Skip to content

Commit

Permalink
WIP: 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 1e421de
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ export type JsonRpcError = OptionalField<
'data'
>;

export const JsonRpcParamsStruct = optional(
export const JsonRpcParamsStruct: Struct<Json[] | Record<string, Json>, null> = optional(

Check failure on line 180 in src/json.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

Replace `·optional(⏎··union([record(string(),·JsonStruct),·array(JsonStruct)]),⏎` with `⏎··optional(union([record(string(),·JsonStruct),·array(JsonStruct)])`

Check failure on line 180 in src/json.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Replace `·optional(⏎··union([record(string(),·JsonStruct),·array(JsonStruct)]),⏎` with `⏎··optional(union([record(string(),·JsonStruct),·array(JsonStruct)])`

Check failure on line 180 in src/json.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Replace `·optional(⏎··union([record(string(),·JsonStruct),·array(JsonStruct)]),⏎` with `⏎··optional(union([record(string(),·JsonStruct),·array(JsonStruct)])`
union([record(string(), JsonStruct), array(JsonStruct)]),
);
export type JsonRpcParams = Infer<typeof JsonRpcParamsStruct>;
) as any;

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

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

0 comments on commit 1e421de

Please sign in to comment.