diff --git a/src/types.ts b/src/types.ts index a5a324e02..6bec5190c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -170,9 +170,22 @@ export const JSONRPCResultResponseSchema = z }) .strict(); +/** + * Checks if a value is a valid JSONRPCResultResponse. + * @param value - The value to check. + * + * @returns True if the value is a valid JSONRPCResultResponse, false otherwise. + */ export const isJSONRPCResultResponse = (value: unknown): value is JSONRPCResultResponse => JSONRPCResultResponseSchema.safeParse(value).success; +/** + * @deprecated Use {@link isJSONRPCResultResponse} instead. + * + * 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}) + */ +export const isJSONRPCResponse = isJSONRPCResultResponse; + /** * Error codes defined by the JSON-RPC specification. */ @@ -216,15 +229,32 @@ export const JSONRPCErrorResponseSchema = z }) .strict(); +/** + * @deprecated Use {@link JSONRPCErrorResponseSchema} instead. + */ +export const JSONRPCErrorSchema = JSONRPCErrorResponseSchema; + +/** + * Checks if a value is a valid JSONRPCErrorResponse. + * @param value - The value to check. + * + * @returns True if the value is a valid JSONRPCErrorResponse, false otherwise. + */ export const isJSONRPCErrorResponse = (value: unknown): value is JSONRPCErrorResponse => JSONRPCErrorResponseSchema.safeParse(value).success; +/** + * @deprecated Use {@link isJSONRPCErrorResponse} instead. + */ +export const isJSONRPCError = isJSONRPCErrorResponse; + export const JSONRPCMessageSchema = z.union([ JSONRPCRequestSchema, JSONRPCNotificationSchema, JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema ]); + export const JSONRPCResponseSchema = z.union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]); /* Empty result */ @@ -2373,6 +2403,12 @@ export type JSONRPCRequest = Infer; export type JSONRPCNotification = Infer; export type JSONRPCResponse = Infer; export type JSONRPCErrorResponse = Infer; +/** + * @deprecated Use {@link JSONRPCErrorResponse} instead. + * + * 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}. + */ +export type JSONRPCError = JSONRPCErrorResponse; export type JSONRPCResultResponse = Infer; export type JSONRPCMessage = Infer;