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
5 changed files with 35 additions and 23 deletions

20
dist/types.d.ts generated vendored
View file

@ -158,6 +158,9 @@ export declare const RequestIdSchema: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
* A request that expects a response.
*/
export declare const JSONRPCRequestSchema: z.ZodObject<z.objectUtil.extendShape<{
jsonrpc: z.ZodLiteral<"2.0">;
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
}, {
method: z.ZodString;
params: z.ZodOptional<z.ZodObject<{
_meta: z.ZodOptional<z.ZodObject<{
@ -211,9 +214,6 @@ export declare const JSONRPCRequestSchema: z.ZodObject<z.objectUtil.extendShape<
progressToken: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
}, z.ZodTypeAny, "passthrough">>>;
}, z.ZodTypeAny, "passthrough">>>;
}, {
jsonrpc: z.ZodLiteral<"2.0">;
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
}>, "strict", z.ZodTypeAny, {
method: string;
jsonrpc: "2.0";
@ -263,6 +263,8 @@ export declare const JSONRPCRequestSchema: z.ZodObject<z.objectUtil.extendShape<
* A notification which does not expect a response.
*/
export declare const JSONRPCNotificationSchema: z.ZodObject<z.objectUtil.extendShape<{
jsonrpc: z.ZodLiteral<"2.0">;
}, {
method: z.ZodString;
params: z.ZodOptional<z.ZodObject<{
/**
@ -280,8 +282,6 @@ export declare const JSONRPCNotificationSchema: z.ZodObject<z.objectUtil.extendS
*/
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
}, z.ZodTypeAny, "passthrough">>>;
}, {
jsonrpc: z.ZodLiteral<"2.0">;
}>, "strict", z.ZodTypeAny, {
method: string;
jsonrpc: "2.0";
@ -397,6 +397,9 @@ export declare const JSONRPCErrorSchema: z.ZodObject<{
};
}>;
export declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
jsonrpc: z.ZodLiteral<"2.0">;
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
}, {
method: z.ZodString;
params: z.ZodOptional<z.ZodObject<{
_meta: z.ZodOptional<z.ZodObject<{
@ -450,9 +453,6 @@ export declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.
progressToken: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
}, z.ZodTypeAny, "passthrough">>>;
}, z.ZodTypeAny, "passthrough">>>;
}, {
jsonrpc: z.ZodLiteral<"2.0">;
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
}>, "strict", z.ZodTypeAny, {
method: string;
jsonrpc: "2.0";
@ -498,6 +498,8 @@ export declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.
}, z.ZodTypeAny, "passthrough">>>;
}, z.ZodTypeAny, "passthrough"> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
jsonrpc: z.ZodLiteral<"2.0">;
}, {
method: z.ZodString;
params: z.ZodOptional<z.ZodObject<{
/**
@ -515,8 +517,6 @@ export declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.
*/
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
}, z.ZodTypeAny, "passthrough">>>;
}, {
jsonrpc: z.ZodLiteral<"2.0">;
}>, "strict", z.ZodTypeAny, {
method: string;
jsonrpc: "2.0";

2
dist/types.d.ts.map generated vendored

File diff suppressed because one or more lines are too long

14
dist/types.js generated vendored
View file

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

2
dist/types.js.map generated vendored

File diff suppressed because one or more lines are too long

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.