Skip to content
This repository was archived by the owner on Nov 9, 2023. It is now read-only.

Commit f46e70e

Browse files
committed
Fix default options assignment in getJsonRpcIdValidator
1 parent 4e707d8 commit f46e70e

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/utils.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ export function isJsonRpcFailure(
3232
}
3333

3434
interface JsonRpcValidatorOptions {
35-
permitEmptyString: boolean;
36-
permitFractions: boolean;
37-
permitNull: boolean;
35+
permitEmptyString?: boolean;
36+
permitFractions?: boolean;
37+
permitNull?: boolean;
3838
}
3939

40+
const DEFAULT_VALIDATOR_OPTIONS: JsonRpcValidatorOptions = {
41+
permitEmptyString: true,
42+
permitFractions: false,
43+
permitNull: true,
44+
};
45+
4046
/**
4147
* Gets a function for validating JSON-RPC request / response `id` values.
4248
*
@@ -60,14 +66,11 @@ interface JsonRpcValidatorOptions {
6066
* Default: `true`
6167
* @returns The JSON-RPC ID validator function.
6268
*/
63-
export function getJsonRpcIdValidator(
64-
options: JsonRpcValidatorOptions = {
65-
permitEmptyString: true,
66-
permitFractions: false,
67-
permitNull: true,
68-
},
69-
) {
70-
const { permitEmptyString, permitFractions, permitNull } = options;
69+
export function getJsonRpcIdValidator(options?: JsonRpcValidatorOptions) {
70+
const { permitEmptyString, permitFractions, permitNull } = {
71+
...DEFAULT_VALIDATOR_OPTIONS,
72+
...options,
73+
};
7174

7275
/**
7376
* @param id - The JSON-RPC ID value to check.

test/utils.test.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ describe('getJsonRpcIdValidator', function () {
7171
validateAll(
7272
getJsonRpcIdValidator({
7373
permitEmptyString: false,
74-
permitFractions: false,
75-
permitNull: true,
7674
}),
7775
inputs,
7876
);
@@ -84,9 +82,7 @@ describe('getJsonRpcIdValidator', function () {
8482

8583
validateAll(
8684
getJsonRpcIdValidator({
87-
permitEmptyString: true,
8885
permitFractions: true,
89-
permitNull: true,
9086
}),
9187
inputs,
9288
);
@@ -98,8 +94,6 @@ describe('getJsonRpcIdValidator', function () {
9894

9995
validateAll(
10096
getJsonRpcIdValidator({
101-
permitEmptyString: true,
102-
permitFractions: false,
10397
permitNull: false,
10498
}),
10599
inputs,

0 commit comments

Comments
 (0)