Skip to content

Commit 61a03af

Browse files
authored
Label dictionary keys in community-cli-plugin dev server (#59986)
Summary: Add key labels to the indexer types in the dev server `/message` and `/events` socket handlers and their tests (`{[string]: T}` becomes `{[key: string]: T}`). This matches the stricter Flow configuration used to type-check these files downstream, which requires dictionary key labels. Changelog: [Internal] Differential Revision: D131543175
1 parent 728d49e commit 61a03af

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎packages/community-cli-plugin/src/dev-server/__tests__/createEventsSocket-test.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {startTestServer, waitUntil} from './SocketTestUtils';
1616
jest.useRealTimers();
1717

1818
const logger = {warn: jest.fn(), error: jest.fn()};
19-
const broadcast = jest.fn<[string, ?{[string]: unknown}], void>();
19+
const broadcast = jest.fn<[string, ?{[key: string]: unknown}], void>();
2020

2121
let testServer: TestServer;
2222
let eventsSocket: ReturnType<typeof createEventsSocket>;
@@ -64,7 +64,7 @@ describe('/events', () => {
6464

6565
test('logs an event that cannot be serialized', async () => {
6666
const client = await testServer.connect('/events');
67-
const circular: {[string]: unknown} = {};
67+
const circular: {[key: string]: unknown} = {};
6868
circular.self = circular;
6969

7070
eventsSocket.reportEvent(circular);

‎packages/community-cli-plugin/src/dev-server/createDevServerMiddleware.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type DevServerMiddleware = Readonly<{
3232
middleware: Server,
3333
websocketEndpoints: {[path: string]: ws$WebSocketServer},
3434
messageSocket: Readonly<{
35-
broadcast: (method: string, params?: ?{[string]: unknown}) => void,
35+
broadcast: (method: string, params?: ?{[key: string]: unknown}) => void,
3636
}>,
3737
eventsSocket: Readonly<{
3838
reportEvent: (event: unknown) => void,

‎packages/community-cli-plugin/src/dev-server/createEventsSocket.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const PROTOCOL_VERSION = 2;
1919
type Options = Readonly<{
2020
logger: Logger,
2121
serverBaseUrl: URL,
22-
broadcast: (method: string, params?: ?{[string]: unknown}) => void,
22+
broadcast: (method: string, params?: ?{[key: string]: unknown}) => void,
2323
}>;
2424

2525
/**
@@ -97,7 +97,7 @@ export default function createEventsSocket({
9797
function parseCommand(
9898
data: unknown,
9999
logger: Logger,
100-
): ?Readonly<{command: string, params: ?{[string]: unknown}}> {
100+
): ?Readonly<{command: string, params: ?{[key: string]: unknown}}> {
101101
let message;
102102
try {
103103
message = JSON.parse(String(data));

‎packages/community-cli-plugin/src/dev-server/createMessageSocket.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type Logger = Readonly<{
2424
...
2525
}>;
2626

27-
type Params = Readonly<{[string]: unknown}>;
27+
type Params = Readonly<{[key: string]: unknown}>;
2828

2929
type ClientMessage =
3030
| Readonly<{kind: 'broadcast', method: string, params: unknown}>
@@ -45,7 +45,7 @@ type ClientMessage =
4545

4646
type Client = Readonly<{
4747
socket: ws$WebSocket,
48-
query: Readonly<{[string]: string}>,
48+
query: Readonly<{[key: string]: string}>,
4949
}>;
5050

5151
type Options = Readonly<{
@@ -130,7 +130,7 @@ export default function createMessageSocket({logger, serverBaseUrl}: Options): {
130130
result = clientId;
131131
break;
132132
case 'getpeers': {
133-
const peers: {[string]: Readonly<{[string]: string}>} = {};
133+
const peers: {[key: string]: Readonly<{[key: string]: string}>} = {};
134134
for (const [otherId, {query}] of clients) {
135135
if (otherId !== clientId) {
136136
peers[otherId] = query;

0 commit comments

Comments
 (0)