Skip to content

Commit 0018d5b

Browse files
committed
WIP: fix JsonRpcRequest to be valid json
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.
1 parent 20bb059 commit 0018d5b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/json.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,28 @@ export type JsonRpcError = OptionalField<
180180
export const JsonRpcParamsStruct = optional(
181181
union([record(string(), JsonStruct), array(JsonStruct)]),
182182
);
183-
export type JsonRpcParams = Infer<typeof JsonRpcParamsStruct>;
184183

185-
export const JsonRpcRequestStruct = object({
184+
export type JsonRpcParams = Json[] | Record<string, Json>;
185+
186+
export const JsonRpcRequestStruct: Struct<
187+
{
188+
id: number | null | string;
189+
method: string;
190+
jsonrpc: '2.0';
191+
params?: Json[] | Record<string, Json>;
192+
},
193+
{
194+
id: Struct<string | number | null, null>;
195+
jsonrpc: Struct<'2.0', '2.0'>;
196+
method: Struct<string, null>;
197+
params?: any;
198+
}
199+
> = object({
186200
id: JsonRpcIdStruct,
187201
jsonrpc: JsonRpcVersionStruct,
188202
method: string(),
189203
params: JsonRpcParamsStruct,
190-
});
204+
}) as any;
191205

192206
export type InferWithParams<
193207
Type extends Struct<any>,

0 commit comments

Comments
 (0)