Start JSON-RPC messages with 'jsonrpc' and 'id' fields, instead of the other way around

This commit is contained in:
Justin Spahr-Summers 2024-10-02 22:21:19 +01:00
commit 8b476ddc85
No known key found for this signature in database
GPG key ID: E78498BF3C053CA7

View file

@ -59,17 +59,23 @@ export const RequestIdSchema = z.union([z.string(), z.number().int()]);
/**
* A request that expects a response.
*/
export const JSONRPCRequestSchema = RequestSchema.extend({
jsonrpc: z.literal(JSONRPC_VERSION),
id: RequestIdSchema,
}).strict();
export const JSONRPCRequestSchema = z
.object({
jsonrpc: z.literal(JSONRPC_VERSION),
id: RequestIdSchema,
})
.merge(RequestSchema)
.strict();
/**
* A notification which does not expect a response.
*/
export const JSONRPCNotificationSchema = NotificationSchema.extend({
jsonrpc: z.literal(JSONRPC_VERSION),
}).strict();
export const JSONRPCNotificationSchema = z
.object({
jsonrpc: z.literal(JSONRPC_VERSION),
})
.merge(NotificationSchema)
.strict();
/**
* A successful (non-error) response to a request.