Skip to content

Commit

Permalink
Fix JsonRpcRequest to be valid json
Browse files Browse the repository at this point in the history
fix/types: JsonRpcParams should be valid JSON values

`undefined` is not valid JSON.

https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf
(Section 5):

    A JSON value can be an object, array, number, string, true, false, or null.
  • Loading branch information
legobeat committed Aug 24, 2023
1 parent 20bb059 commit 4e5c07f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ export type JsonRpcError = OptionalField<
'data'
>;

export const JsonRpcParamsStruct = optional(
union([record(string(), JsonStruct), array(JsonStruct)]),
);
export type JsonRpcParams = Infer<typeof JsonRpcParamsStruct>;
export const JsonRpcParamsStruct: Struct<Json[] | Record<string, Json>, null> =
optional(union([record(string(), JsonStruct), array(JsonStruct)])) as any;

export type JsonRpcParams = Json[] | Record<string, Json>;

export const JsonRpcRequestStruct = object({
id: JsonRpcIdStruct,
Expand Down

0 comments on commit 4e5c07f

Please sign in to comment.