Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -2373,6 +2403,12 @@ export type JSONRPCRequest = Infer<typeof JSONRPCRequestSchema>;
export type JSONRPCNotification = Infer<typeof JSONRPCNotificationSchema>;
export type JSONRPCResponse = Infer<typeof JSONRPCResponseSchema>;
export type JSONRPCErrorResponse = Infer<typeof JSONRPCErrorResponseSchema>;
/**
* @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<typeof JSONRPCResultResponseSchema>;

export type JSONRPCMessage = Infer<typeof JSONRPCMessageSchema>;
Expand Down
Loading