Skip to content

Commit c101f60

Browse files
committed
Start JSON-RPC messages with 'jsonrpc' and 'id' fields, instead of the other way around
1 parent ecbcb8d commit c101f60

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/types.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,23 @@ export const RequestIdSchema = z.union([z.string(), z.number().int()]);
5959
/**
6060
* A request that expects a response.
6161
*/
62-
export const JSONRPCRequestSchema = RequestSchema.extend({
63-
jsonrpc: z.literal(JSONRPC_VERSION),
64-
id: RequestIdSchema,
65-
}).strict();
62+
export const JSONRPCRequestSchema = z
63+
.object({
64+
jsonrpc: z.literal(JSONRPC_VERSION),
65+
id: RequestIdSchema,
66+
})
67+
.merge(RequestSchema)
68+
.strict();
6669

6770
/**
6871
* A notification which does not expect a response.
6972
*/
70-
export const JSONRPCNotificationSchema = NotificationSchema.extend({
71-
jsonrpc: z.literal(JSONRPC_VERSION),
72-
}).strict();
73+
export const JSONRPCNotificationSchema = z
74+
.object({
75+
jsonrpc: z.literal(JSONRPC_VERSION),
76+
})
77+
.merge(NotificationSchema)
78+
.strict();
7379

7480
/**
7581
* A successful (non-error) response to a request.

0 commit comments

Comments
 (0)