Skip to content

Commit fb07af8

Browse files
spec types - backwards compatibility changes (#1306)
1 parent 2b20ca9 commit fb07af8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/types.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,22 @@ export const JSONRPCResultResponseSchema = z
170170
})
171171
.strict();
172172

173+
/**
174+
* Checks if a value is a valid JSONRPCResultResponse.
175+
* @param value - The value to check.
176+
*
177+
* @returns True if the value is a valid JSONRPCResultResponse, false otherwise.
178+
*/
173179
export const isJSONRPCResultResponse = (value: unknown): value is JSONRPCResultResponse =>
174180
JSONRPCResultResponseSchema.safeParse(value).success;
175181

182+
/**
183+
* @deprecated Use {@link isJSONRPCResultResponse} instead.
184+
*
185+
* Please note that {@link JSONRPCResponse} is a union of {@link JSONRPCResultResponse} and {@link JSONRPCErrorResponse} as per the updated JSON-RPC specification. (was previously just {@link JSONRPCResultResponse})
186+
*/
187+
export const isJSONRPCResponse = isJSONRPCResultResponse;
188+
176189
/**
177190
* Error codes defined by the JSON-RPC specification.
178191
*/
@@ -216,15 +229,32 @@ export const JSONRPCErrorResponseSchema = z
216229
})
217230
.strict();
218231

232+
/**
233+
* @deprecated Use {@link JSONRPCErrorResponseSchema} instead.
234+
*/
235+
export const JSONRPCErrorSchema = JSONRPCErrorResponseSchema;
236+
237+
/**
238+
* Checks if a value is a valid JSONRPCErrorResponse.
239+
* @param value - The value to check.
240+
*
241+
* @returns True if the value is a valid JSONRPCErrorResponse, false otherwise.
242+
*/
219243
export const isJSONRPCErrorResponse = (value: unknown): value is JSONRPCErrorResponse =>
220244
JSONRPCErrorResponseSchema.safeParse(value).success;
221245

246+
/**
247+
* @deprecated Use {@link isJSONRPCErrorResponse} instead.
248+
*/
249+
export const isJSONRPCError = isJSONRPCErrorResponse;
250+
222251
export const JSONRPCMessageSchema = z.union([
223252
JSONRPCRequestSchema,
224253
JSONRPCNotificationSchema,
225254
JSONRPCResultResponseSchema,
226255
JSONRPCErrorResponseSchema
227256
]);
257+
228258
export const JSONRPCResponseSchema = z.union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
229259

230260
/* Empty result */
@@ -2373,6 +2403,12 @@ export type JSONRPCRequest = Infer<typeof JSONRPCRequestSchema>;
23732403
export type JSONRPCNotification = Infer<typeof JSONRPCNotificationSchema>;
23742404
export type JSONRPCResponse = Infer<typeof JSONRPCResponseSchema>;
23752405
export type JSONRPCErrorResponse = Infer<typeof JSONRPCErrorResponseSchema>;
2406+
/**
2407+
* @deprecated Use {@link JSONRPCErrorResponse} instead.
2408+
*
2409+
* Please note that spec types have renamed {@link JSONRPCError} to {@link JSONRPCErrorResponse} as per the updated JSON-RPC specification. (was previously just {@link JSONRPCError}) and future versions will remove {@link JSONRPCError}.
2410+
*/
2411+
export type JSONRPCError = JSONRPCErrorResponse;
23762412
export type JSONRPCResultResponse = Infer<typeof JSONRPCResultResponseSchema>;
23772413

23782414
export type JSONRPCMessage = Infer<typeof JSONRPCMessageSchema>;

0 commit comments

Comments
 (0)