@metamask/utils 8.0.0 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/dist/assert.js +16 -0
- package/dist/assert.js.map +1 -0
- package/dist/assert.mjs +16 -0
- package/dist/assert.mjs.map +1 -0
- package/dist/base64.js +11 -0
- package/dist/base64.js.map +1 -0
- package/dist/base64.mjs +11 -0
- package/dist/base64.mjs.map +1 -0
- package/dist/bytes.js +43 -0
- package/dist/bytes.js.map +1 -0
- package/dist/bytes.mjs +43 -0
- package/dist/bytes.mjs.map +1 -0
- package/dist/caip-types.js +40 -0
- package/dist/caip-types.js.map +1 -0
- package/dist/caip-types.mjs +40 -0
- package/dist/caip-types.mjs.map +1 -0
- package/dist/checksum.js +12 -0
- package/dist/checksum.js.map +1 -0
- package/dist/checksum.mjs +12 -0
- package/dist/checksum.mjs.map +1 -0
- package/dist/chunk-2CY4F77D.mjs +95 -0
- package/dist/chunk-2CY4F77D.mjs.map +1 -0
- package/dist/chunk-2LBGT4GH.js +15 -0
- package/dist/chunk-2LBGT4GH.js.map +1 -0
- package/dist/chunk-2TBCL6EF.js +1 -0
- package/dist/chunk-2TBCL6EF.js.map +1 -0
- package/dist/chunk-3W5G4CYI.js +25 -0
- package/dist/chunk-3W5G4CYI.js.map +1 -0
- package/dist/chunk-4JNG5UTO.js +44 -0
- package/dist/chunk-4JNG5UTO.js.map +1 -0
- package/dist/chunk-4RMX5YWE.js +34 -0
- package/dist/chunk-4RMX5YWE.js.map +1 -0
- package/dist/chunk-5WQRFJVQ.js +257 -0
- package/dist/chunk-5WQRFJVQ.js.map +1 -0
- package/dist/chunk-65KBH4FZ.mjs +257 -0
- package/dist/chunk-65KBH4FZ.mjs.map +1 -0
- package/dist/chunk-7S5AWFX7.mjs +61 -0
- package/dist/chunk-7S5AWFX7.mjs.map +1 -0
- package/dist/chunk-AY6FDCBT.mjs +1 -0
- package/dist/chunk-AY6FDCBT.mjs.map +1 -0
- package/dist/chunk-BKR45GQY.mjs +273 -0
- package/dist/chunk-BKR45GQY.mjs.map +1 -0
- package/dist/chunk-CSDMTDND.mjs +59 -0
- package/dist/chunk-CSDMTDND.mjs.map +1 -0
- package/dist/chunk-DMPG3H3G.js +61 -0
- package/dist/chunk-DMPG3H3G.js.map +1 -0
- package/dist/chunk-DYMCEQIV.mjs +1 -0
- package/dist/chunk-DYMCEQIV.mjs.map +1 -0
- package/dist/chunk-EQMZL4XU.js +1 -0
- package/dist/chunk-EQMZL4XU.js.map +1 -0
- package/dist/chunk-G66TREC6.mjs +69 -0
- package/dist/chunk-G66TREC6.mjs.map +1 -0
- package/dist/chunk-H4YFDLB7.mjs +70 -0
- package/dist/chunk-H4YFDLB7.mjs.map +1 -0
- package/dist/chunk-HLDWS2JR.mjs +35 -0
- package/dist/chunk-HLDWS2JR.mjs.map +1 -0
- package/dist/chunk-I575FZFH.mjs +1 -0
- package/dist/chunk-I575FZFH.mjs.map +1 -0
- package/dist/chunk-JCYFTGED.js +95 -0
- package/dist/chunk-JCYFTGED.js.map +1 -0
- package/dist/chunk-JPAL7Q5S.mjs +90 -0
- package/dist/chunk-JPAL7Q5S.mjs.map +1 -0
- package/dist/chunk-LC2CRSWD.js +1 -0
- package/dist/chunk-LC2CRSWD.js.map +1 -0
- package/dist/chunk-N53OILN6.mjs +16 -0
- package/dist/chunk-N53OILN6.mjs.map +1 -0
- package/dist/chunk-QVEKZRZ2.js +70 -0
- package/dist/chunk-QVEKZRZ2.js.map +1 -0
- package/dist/chunk-RIRDOQPX.mjs +15 -0
- package/dist/chunk-RIRDOQPX.mjs.map +1 -0
- package/dist/chunk-RKRGAFXY.js +1 -0
- package/dist/chunk-RKRGAFXY.js.map +1 -0
- package/dist/chunk-RRYOWRCV.mjs +1 -0
- package/dist/chunk-RRYOWRCV.mjs.map +1 -0
- package/dist/chunk-TGOMTREC.mjs +75 -0
- package/dist/chunk-TGOMTREC.mjs.map +1 -0
- package/dist/chunk-THNLGEXV.mjs +34 -0
- package/dist/chunk-THNLGEXV.mjs.map +1 -0
- package/dist/chunk-U7ZUGCE7.js +75 -0
- package/dist/chunk-U7ZUGCE7.js.map +1 -0
- package/dist/chunk-UOTVU7OQ.js +1 -0
- package/dist/chunk-UOTVU7OQ.js.map +1 -0
- package/dist/chunk-VBYRLAP6.js +59 -0
- package/dist/chunk-VBYRLAP6.js.map +1 -0
- package/dist/chunk-VL5DYXC5.mjs +122 -0
- package/dist/chunk-VL5DYXC5.mjs.map +1 -0
- package/dist/chunk-VSEW3V2L.mjs +44 -0
- package/dist/chunk-VSEW3V2L.mjs.map +1 -0
- package/dist/chunk-WA4DHIND.mjs +1 -0
- package/dist/chunk-WA4DHIND.mjs.map +1 -0
- package/dist/chunk-WQDTPIQK.js +122 -0
- package/dist/chunk-WQDTPIQK.js.map +1 -0
- package/dist/chunk-WRBN6DWM.js +35 -0
- package/dist/chunk-WRBN6DWM.js.map +1 -0
- package/dist/chunk-X66SUIEF.mjs +25 -0
- package/dist/chunk-X66SUIEF.mjs.map +1 -0
- package/dist/chunk-XYYGZF5Y.js +16 -0
- package/dist/chunk-XYYGZF5Y.js.map +1 -0
- package/dist/chunk-YQJBIHC7.js +273 -0
- package/dist/chunk-YQJBIHC7.js.map +1 -0
- package/dist/chunk-Z2RGWDD7.js +90 -0
- package/dist/chunk-Z2RGWDD7.js.map +1 -0
- package/dist/chunk-ZRNIY7OW.js +69 -0
- package/dist/chunk-ZRNIY7OW.js.map +1 -0
- package/dist/coercers.js +18 -0
- package/dist/coercers.js.map +1 -0
- package/dist/coercers.mjs +18 -0
- package/dist/coercers.mjs.map +1 -0
- package/dist/collections.js +10 -0
- package/dist/collections.js.map +1 -0
- package/dist/collections.mjs +10 -0
- package/dist/collections.mjs.map +1 -0
- package/dist/encryption-types.js +2 -0
- package/dist/encryption-types.js.map +1 -0
- package/dist/encryption-types.mjs +2 -0
- package/dist/encryption-types.mjs.map +1 -0
- package/dist/errors.js +17 -0
- package/dist/errors.js.map +1 -0
- package/dist/errors.mjs +17 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/fs.js +26 -0
- package/dist/fs.js.map +1 -0
- package/dist/fs.mjs +26 -0
- package/dist/fs.mjs.map +1 -0
- package/dist/hex.js +35 -0
- package/dist/hex.js.map +1 -0
- package/dist/hex.mjs +35 -0
- package/dist/hex.mjs.map +1 -0
- package/dist/index.js +289 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +289 -0
- package/dist/index.mjs.map +1 -0
- package/dist/json.js +75 -0
- package/dist/json.js.map +1 -0
- package/dist/json.mjs +75 -0
- package/dist/json.mjs.map +1 -0
- package/dist/keyring.js +2 -0
- package/dist/keyring.js.map +1 -0
- package/dist/keyring.mjs +2 -0
- package/dist/keyring.mjs.map +1 -0
- package/dist/logging.js +10 -0
- package/dist/logging.js.map +1 -0
- package/dist/logging.mjs +10 -0
- package/dist/logging.mjs.map +1 -0
- package/dist/misc.js +28 -0
- package/dist/misc.js.map +1 -0
- package/dist/misc.mjs +28 -0
- package/dist/misc.mjs.map +1 -0
- package/dist/node.js +309 -0
- package/dist/node.js.map +1 -0
- package/dist/node.mjs +309 -0
- package/dist/node.mjs.map +1 -0
- package/dist/number.js +18 -0
- package/dist/number.js.map +1 -0
- package/dist/number.mjs +18 -0
- package/dist/number.mjs.map +1 -0
- package/dist/opaque.js +2 -0
- package/dist/opaque.js.map +1 -0
- package/dist/opaque.mjs +2 -0
- package/dist/opaque.mjs.map +1 -0
- package/dist/time.js +12 -0
- package/dist/time.js.map +1 -0
- package/dist/time.mjs +12 -0
- package/dist/time.mjs.map +1 -0
- package/dist/transaction-types.js +2 -0
- package/dist/transaction-types.js.map +1 -0
- package/dist/transaction-types.mjs +2 -0
- package/dist/transaction-types.mjs.map +1 -0
- package/dist/types/assert.d.ts.map +1 -1
- package/dist/types/bytes.d.ts +14 -0
- package/dist/types/bytes.d.ts.map +1 -1
- package/dist/types/errors.d.ts +58 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/fs.d.ts +133 -0
- package/dist/types/fs.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/json.d.ts +83 -47
- package/dist/types/json.d.ts.map +1 -1
- package/dist/types/node.d.ts +3 -0
- package/dist/types/node.d.ts.map +1 -0
- package/dist/versions.js +27 -0
- package/dist/versions.js.map +1 -0
- package/dist/versions.mjs +27 -0
- package/dist/versions.mjs.map +1 -0
- package/package.json +21 -20
- package/dist/cjs/assert.js +0 -116
- package/dist/cjs/assert.js.map +0 -1
- package/dist/cjs/base64.js +0 -32
- package/dist/cjs/base64.js.map +0 -1
- package/dist/cjs/bytes.js +0 -255
- package/dist/cjs/bytes.js.map +0 -1
- package/dist/cjs/caip-types.js +0 -115
- package/dist/cjs/caip-types.js.map +0 -1
- package/dist/cjs/checksum.js +0 -17
- package/dist/cjs/checksum.js.map +0 -1
- package/dist/cjs/coercers.js +0 -96
- package/dist/cjs/coercers.js.map +0 -1
- package/dist/cjs/collections.js +0 -157
- package/dist/cjs/collections.js.map +0 -1
- package/dist/cjs/encryption-types.js +0 -6
- package/dist/cjs/encryption-types.js.map +0 -1
- package/dist/cjs/hex.js +0 -107
- package/dist/cjs/hex.js.map +0 -1
- package/dist/cjs/index.js +0 -37
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/json.js +0 -263
- package/dist/cjs/json.js.map +0 -1
- package/dist/cjs/keyring.js +0 -6
- package/dist/cjs/keyring.js.map +0 -1
- package/dist/cjs/logging.js +0 -33
- package/dist/cjs/logging.js.map +0 -1
- package/dist/cjs/misc.js +0 -111
- package/dist/cjs/misc.js.map +0 -1
- package/dist/cjs/number.js +0 -52
- package/dist/cjs/number.js.map +0 -1
- package/dist/cjs/opaque.js +0 -8
- package/dist/cjs/opaque.js.map +0 -1
- package/dist/cjs/time.js +0 -63
- package/dist/cjs/time.js.map +0 -1
- package/dist/cjs/transaction-types.js +0 -6
- package/dist/cjs/transaction-types.js.map +0 -1
- package/dist/cjs/versions.js +0 -79
- package/dist/cjs/versions.js.map +0 -1
- package/dist/esm/assert.js +0 -133
- package/dist/esm/assert.js.map +0 -1
- package/dist/esm/base64.js +0 -28
- package/dist/esm/base64.js.map +0 -1
- package/dist/esm/bytes.js +0 -334
- package/dist/esm/bytes.js.map +0 -1
- package/dist/esm/caip-types.js +0 -99
- package/dist/esm/caip-types.js.map +0 -1
- package/dist/esm/checksum.js +0 -7
- package/dist/esm/checksum.js.map +0 -1
- package/dist/esm/coercers.js +0 -153
- package/dist/esm/coercers.js.map +0 -1
- package/dist/esm/collections.js +0 -140
- package/dist/esm/collections.js.map +0 -1
- package/dist/esm/encryption-types.js +0 -3
- package/dist/esm/encryption-types.js.map +0 -1
- package/dist/esm/hex.js +0 -108
- package/dist/esm/hex.js.map +0 -1
- package/dist/esm/index.js +0 -20
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/json.js +0 -301
- package/dist/esm/json.js.map +0 -1
- package/dist/esm/keyring.js +0 -3
- package/dist/esm/keyring.js.map +0 -1
- package/dist/esm/logging.js +0 -34
- package/dist/esm/logging.js.map +0 -1
- package/dist/esm/misc.js +0 -129
- package/dist/esm/misc.js.map +0 -1
- package/dist/esm/number.js +0 -92
- package/dist/esm/number.js.map +0 -1
- package/dist/esm/opaque.js +0 -5
- package/dist/esm/opaque.js.map +0 -1
- package/dist/esm/package.json +0 -1
- package/dist/esm/time.js +0 -53
- package/dist/esm/time.js.map +0 -1
- package/dist/esm/transaction-types.js +0 -3
- package/dist/esm/transaction-types.js.map +0 -1
- package/dist/esm/versions.js +0 -78
- package/dist/esm/versions.js.map +0 -1
- package/dist/types/caip-types.test-d.d.ts +0 -2
- package/dist/types/caip-types.test-d.d.ts.map +0 -1
- package/dist/types/hex.test-d.d.ts +0 -2
- package/dist/types/hex.test-d.d.ts.map +0 -1
- package/dist/types/json.test-d.d.ts +0 -2
- package/dist/types/json.test-d.d.ts.map +0 -1
- package/dist/types/misc.test-d.d.ts +0 -2
- package/dist/types/misc.test-d.d.ts.map +0 -1
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkVBYRLAP6js = require('./chunk-VBYRLAP6.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkQVEKZRZ2js = require('./chunk-QVEKZRZ2.js');
|
|
7
|
+
|
|
8
|
+
// src/json.ts
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
var _superstruct = require('superstruct');
|
|
30
|
+
var object = (schema) => (
|
|
31
|
+
// The type is slightly different from a regular object struct, because we
|
|
32
|
+
// want to make properties with `undefined` in their type optional, but not
|
|
33
|
+
// `undefined` itself. This means that we need a type cast.
|
|
34
|
+
_superstruct.object.call(void 0, schema)
|
|
35
|
+
);
|
|
36
|
+
function hasOptional({ path, branch }) {
|
|
37
|
+
const field = path[path.length - 1];
|
|
38
|
+
return _chunkQVEKZRZ2js.hasProperty.call(void 0, branch[branch.length - 2], field);
|
|
39
|
+
}
|
|
40
|
+
function exactOptional(struct) {
|
|
41
|
+
return new (0, _superstruct.Struct)({
|
|
42
|
+
...struct,
|
|
43
|
+
type: `optional ${struct.type}`,
|
|
44
|
+
validator: (value, context) => !hasOptional(context) || struct.validator(value, context),
|
|
45
|
+
refiner: (value, context) => !hasOptional(context) || struct.refiner(value, context)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
var finiteNumber = () => _superstruct.define.call(void 0, "finite number", (value) => {
|
|
49
|
+
return _superstruct.is.call(void 0, value, _superstruct.number.call(void 0, )) && Number.isFinite(value);
|
|
50
|
+
});
|
|
51
|
+
var UnsafeJsonStruct = _superstruct.union.call(void 0, [
|
|
52
|
+
_superstruct.literal.call(void 0, null),
|
|
53
|
+
_superstruct.boolean.call(void 0, ),
|
|
54
|
+
finiteNumber(),
|
|
55
|
+
_superstruct.string.call(void 0, ),
|
|
56
|
+
_superstruct.array.call(void 0, _superstruct.lazy.call(void 0, () => UnsafeJsonStruct)),
|
|
57
|
+
_superstruct.record.call(void 0,
|
|
58
|
+
_superstruct.string.call(void 0, ),
|
|
59
|
+
_superstruct.lazy.call(void 0, () => UnsafeJsonStruct)
|
|
60
|
+
)
|
|
61
|
+
]);
|
|
62
|
+
var JsonStruct = _superstruct.coerce.call(void 0, UnsafeJsonStruct, _superstruct.any.call(void 0, ), (value) => {
|
|
63
|
+
_chunkVBYRLAP6js.assertStruct.call(void 0, value, UnsafeJsonStruct);
|
|
64
|
+
return JSON.parse(
|
|
65
|
+
JSON.stringify(value, (propKey, propValue) => {
|
|
66
|
+
if (propKey === "__proto__" || propKey === "constructor") {
|
|
67
|
+
return void 0;
|
|
68
|
+
}
|
|
69
|
+
return propValue;
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
function isValidJson(value) {
|
|
74
|
+
try {
|
|
75
|
+
getSafeJson(value);
|
|
76
|
+
return true;
|
|
77
|
+
} catch (e) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function getSafeJson(value) {
|
|
82
|
+
return _superstruct.create.call(void 0, value, JsonStruct);
|
|
83
|
+
}
|
|
84
|
+
function getJsonSize(value) {
|
|
85
|
+
_chunkVBYRLAP6js.assertStruct.call(void 0, value, JsonStruct, "Invalid JSON value");
|
|
86
|
+
const json = JSON.stringify(value);
|
|
87
|
+
return new TextEncoder().encode(json).byteLength;
|
|
88
|
+
}
|
|
89
|
+
var jsonrpc2 = "2.0";
|
|
90
|
+
var JsonRpcVersionStruct = _superstruct.literal.call(void 0, jsonrpc2);
|
|
91
|
+
var JsonRpcIdStruct = _superstruct.nullable.call(void 0, _superstruct.union.call(void 0, [_superstruct.number.call(void 0, ), _superstruct.string.call(void 0, )]));
|
|
92
|
+
var JsonRpcErrorStruct = object({
|
|
93
|
+
code: _superstruct.integer.call(void 0, ),
|
|
94
|
+
message: _superstruct.string.call(void 0, ),
|
|
95
|
+
data: exactOptional(JsonStruct),
|
|
96
|
+
stack: exactOptional(_superstruct.string.call(void 0, ))
|
|
97
|
+
});
|
|
98
|
+
var JsonRpcParamsStruct = _superstruct.union.call(void 0, [_superstruct.record.call(void 0, _superstruct.string.call(void 0, ), JsonStruct), _superstruct.array.call(void 0, JsonStruct)]);
|
|
99
|
+
var JsonRpcRequestStruct = object({
|
|
100
|
+
id: JsonRpcIdStruct,
|
|
101
|
+
jsonrpc: JsonRpcVersionStruct,
|
|
102
|
+
method: _superstruct.string.call(void 0, ),
|
|
103
|
+
params: exactOptional(JsonRpcParamsStruct)
|
|
104
|
+
});
|
|
105
|
+
var JsonRpcNotificationStruct = object({
|
|
106
|
+
jsonrpc: JsonRpcVersionStruct,
|
|
107
|
+
method: _superstruct.string.call(void 0, ),
|
|
108
|
+
params: exactOptional(JsonRpcParamsStruct)
|
|
109
|
+
});
|
|
110
|
+
function isJsonRpcNotification(value) {
|
|
111
|
+
return _superstruct.is.call(void 0, value, JsonRpcNotificationStruct);
|
|
112
|
+
}
|
|
113
|
+
function assertIsJsonRpcNotification(value, ErrorWrapper) {
|
|
114
|
+
_chunkVBYRLAP6js.assertStruct.call(void 0,
|
|
115
|
+
value,
|
|
116
|
+
JsonRpcNotificationStruct,
|
|
117
|
+
"Invalid JSON-RPC notification",
|
|
118
|
+
ErrorWrapper
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
function isJsonRpcRequest(value) {
|
|
122
|
+
return _superstruct.is.call(void 0, value, JsonRpcRequestStruct);
|
|
123
|
+
}
|
|
124
|
+
function assertIsJsonRpcRequest(value, ErrorWrapper) {
|
|
125
|
+
_chunkVBYRLAP6js.assertStruct.call(void 0,
|
|
126
|
+
value,
|
|
127
|
+
JsonRpcRequestStruct,
|
|
128
|
+
"Invalid JSON-RPC request",
|
|
129
|
+
ErrorWrapper
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
var PendingJsonRpcResponseStruct = _superstruct.object.call(void 0, {
|
|
133
|
+
id: JsonRpcIdStruct,
|
|
134
|
+
jsonrpc: JsonRpcVersionStruct,
|
|
135
|
+
result: _superstruct.optional.call(void 0, _superstruct.unknown.call(void 0, )),
|
|
136
|
+
error: _superstruct.optional.call(void 0, JsonRpcErrorStruct)
|
|
137
|
+
});
|
|
138
|
+
var JsonRpcSuccessStruct = object({
|
|
139
|
+
id: JsonRpcIdStruct,
|
|
140
|
+
jsonrpc: JsonRpcVersionStruct,
|
|
141
|
+
result: JsonStruct
|
|
142
|
+
});
|
|
143
|
+
var JsonRpcFailureStruct = object({
|
|
144
|
+
id: JsonRpcIdStruct,
|
|
145
|
+
jsonrpc: JsonRpcVersionStruct,
|
|
146
|
+
error: JsonRpcErrorStruct
|
|
147
|
+
});
|
|
148
|
+
var JsonRpcResponseStruct = _superstruct.union.call(void 0, [
|
|
149
|
+
JsonRpcSuccessStruct,
|
|
150
|
+
JsonRpcFailureStruct
|
|
151
|
+
]);
|
|
152
|
+
function isPendingJsonRpcResponse(response) {
|
|
153
|
+
return _superstruct.is.call(void 0, response, PendingJsonRpcResponseStruct);
|
|
154
|
+
}
|
|
155
|
+
function assertIsPendingJsonRpcResponse(response, ErrorWrapper) {
|
|
156
|
+
_chunkVBYRLAP6js.assertStruct.call(void 0,
|
|
157
|
+
response,
|
|
158
|
+
PendingJsonRpcResponseStruct,
|
|
159
|
+
"Invalid pending JSON-RPC response",
|
|
160
|
+
ErrorWrapper
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
function isJsonRpcResponse(response) {
|
|
164
|
+
return _superstruct.is.call(void 0, response, JsonRpcResponseStruct);
|
|
165
|
+
}
|
|
166
|
+
function assertIsJsonRpcResponse(value, ErrorWrapper) {
|
|
167
|
+
_chunkVBYRLAP6js.assertStruct.call(void 0,
|
|
168
|
+
value,
|
|
169
|
+
JsonRpcResponseStruct,
|
|
170
|
+
"Invalid JSON-RPC response",
|
|
171
|
+
ErrorWrapper
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
function isJsonRpcSuccess(value) {
|
|
175
|
+
return _superstruct.is.call(void 0, value, JsonRpcSuccessStruct);
|
|
176
|
+
}
|
|
177
|
+
function assertIsJsonRpcSuccess(value, ErrorWrapper) {
|
|
178
|
+
_chunkVBYRLAP6js.assertStruct.call(void 0,
|
|
179
|
+
value,
|
|
180
|
+
JsonRpcSuccessStruct,
|
|
181
|
+
"Invalid JSON-RPC success response",
|
|
182
|
+
ErrorWrapper
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
function isJsonRpcFailure(value) {
|
|
186
|
+
return _superstruct.is.call(void 0, value, JsonRpcFailureStruct);
|
|
187
|
+
}
|
|
188
|
+
function assertIsJsonRpcFailure(value, ErrorWrapper) {
|
|
189
|
+
_chunkVBYRLAP6js.assertStruct.call(void 0,
|
|
190
|
+
value,
|
|
191
|
+
JsonRpcFailureStruct,
|
|
192
|
+
"Invalid JSON-RPC failure response",
|
|
193
|
+
ErrorWrapper
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
function isJsonRpcError(value) {
|
|
197
|
+
return _superstruct.is.call(void 0, value, JsonRpcErrorStruct);
|
|
198
|
+
}
|
|
199
|
+
function assertIsJsonRpcError(value, ErrorWrapper) {
|
|
200
|
+
_chunkVBYRLAP6js.assertStruct.call(void 0,
|
|
201
|
+
value,
|
|
202
|
+
JsonRpcErrorStruct,
|
|
203
|
+
"Invalid JSON-RPC error",
|
|
204
|
+
ErrorWrapper
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
function getJsonRpcIdValidator(options) {
|
|
208
|
+
const { permitEmptyString, permitFractions, permitNull } = {
|
|
209
|
+
permitEmptyString: true,
|
|
210
|
+
permitFractions: false,
|
|
211
|
+
permitNull: true,
|
|
212
|
+
...options
|
|
213
|
+
};
|
|
214
|
+
const isValidJsonRpcId = (id) => {
|
|
215
|
+
return Boolean(
|
|
216
|
+
typeof id === "number" && (permitFractions || Number.isInteger(id)) || typeof id === "string" && (permitEmptyString || id.length > 0) || permitNull && id === null
|
|
217
|
+
);
|
|
218
|
+
};
|
|
219
|
+
return isValidJsonRpcId;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
exports.object = object; exports.exactOptional = exactOptional; exports.UnsafeJsonStruct = UnsafeJsonStruct; exports.JsonStruct = JsonStruct; exports.isValidJson = isValidJson; exports.getSafeJson = getSafeJson; exports.getJsonSize = getJsonSize; exports.jsonrpc2 = jsonrpc2; exports.JsonRpcVersionStruct = JsonRpcVersionStruct; exports.JsonRpcIdStruct = JsonRpcIdStruct; exports.JsonRpcErrorStruct = JsonRpcErrorStruct; exports.JsonRpcParamsStruct = JsonRpcParamsStruct; exports.JsonRpcRequestStruct = JsonRpcRequestStruct; exports.JsonRpcNotificationStruct = JsonRpcNotificationStruct; exports.isJsonRpcNotification = isJsonRpcNotification; exports.assertIsJsonRpcNotification = assertIsJsonRpcNotification; exports.isJsonRpcRequest = isJsonRpcRequest; exports.assertIsJsonRpcRequest = assertIsJsonRpcRequest; exports.PendingJsonRpcResponseStruct = PendingJsonRpcResponseStruct; exports.JsonRpcSuccessStruct = JsonRpcSuccessStruct; exports.JsonRpcFailureStruct = JsonRpcFailureStruct; exports.JsonRpcResponseStruct = JsonRpcResponseStruct; exports.isPendingJsonRpcResponse = isPendingJsonRpcResponse; exports.assertIsPendingJsonRpcResponse = assertIsPendingJsonRpcResponse; exports.isJsonRpcResponse = isJsonRpcResponse; exports.assertIsJsonRpcResponse = assertIsJsonRpcResponse; exports.isJsonRpcSuccess = isJsonRpcSuccess; exports.assertIsJsonRpcSuccess = assertIsJsonRpcSuccess; exports.isJsonRpcFailure = isJsonRpcFailure; exports.assertIsJsonRpcFailure = assertIsJsonRpcFailure; exports.isJsonRpcError = isJsonRpcError; exports.assertIsJsonRpcError = assertIsJsonRpcError; exports.getJsonRpcIdValidator = getJsonRpcIdValidator;
|
|
257
|
+
//# sourceMappingURL=chunk-5WQRFJVQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/json.ts"],"names":[],"mappings":";;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAgEA,IAAM,SAAS,CACpB;AAAA;AAAA;AAAA;AAAA,EAKA,kBAAkB,MAAM;AAAA;AAe1B,SAAS,YAAY,EAAE,MAAM,OAAO,GAAqB;AACvD,QAAM,QAAQ,KAAK,KAAK,SAAS,CAAC;AAClC,SAAO,YAAY,OAAO,OAAO,SAAS,CAAC,GAAG,KAAK;AACrD;AA8BO,SAAS,cACd,QAC2C;AAC3C,SAAO,IAAI,OAA0C;AAAA,IACnD,GAAG;AAAA,IAEH,MAAM,YAAY,OAAO,IAAI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;AAmBM,SAAS,yBACd,UAC0C;AAC1C,SAAO,GAAG,UAAU,4BAA4B;AAClD;AAWO,SAAS,+BACd,UAEA,cACkD;AAClD;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAQO,SAAS,kBACd,UACmC;AACnC,SAAO,GAAG,UAAU,qBAAqB;AAC3C;AAUO,SAAS,wBACd,OAEA,cACwC;AACxC;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAQO,SAAS,iBACd,OAC+B;AAC/B,SAAO,GAAG,OAAO,oBAAoB;AACvC;AAUO,SAAS,uBACd,OAEA,cACuC;AACvC;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAQO,SAAS,iBAAiB,OAAyC;AACxE,SAAO,GAAG,OAAO,oBAAoB;AACvC;AAUO,SAAS,uBACd,OAEA,cACiC;AACjC;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAQO,SAAS,eAAe,OAAuC;AACpE,SAAO,GAAG,OAAO,kBAAkB;AACrC;AAUO,SAAS,qBACd,OAEA,cAC+B;AAC/B;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AA+BO,SAAS,sBAAsB,SAAmC;AACvE,QAAM,EAAE,mBAAmB,iBAAiB,WAAW,IAAI;AAAA,IACzD,mBAAmB;AAAA,IACnB,iBAAiB;AAAA,IACjB,YAAY;AAAA,IACZ,GAAG;AAAA,EACL;AASA,QAAM,mBAAmB,CAAC,OAAiC;AACzD,WAAO;AAAA,MACJ,OAAO,OAAO,aAAa,mBAAmB,OAAO,UAAU,EAAE,MAC/D,OAAO,OAAO,aAAa,qBAAqB,GAAG,SAAS,MAC5D,cAAc,OAAO;AAAA,IAC1B;AAAA,EACF;AAEA,SAAO;AACT","sourcesContent":["import type { Context, Infer } from 'superstruct';\nimport {\n any,\n array,\n boolean,\n coerce,\n create,\n define,\n integer,\n is,\n lazy,\n literal,\n nullable,\n number,\n object as superstructObject,\n optional,\n record,\n string,\n union,\n unknown,\n Struct,\n} from 'superstruct';\nimport type {\n ObjectSchema,\n Optionalize,\n Simplify,\n} from 'superstruct/dist/utils';\n\nimport type { AssertionErrorConstructor } from './assert';\nimport { assertStruct } from './assert';\nimport { hasProperty } from './misc';\n\n/**\n * Any JSON-compatible value.\n */\nexport type Json =\n | null\n | boolean\n | number\n | string\n | Json[]\n | { [prop: string]: Json };\n\n/**\n * A helper type to make properties with `undefined` in their type optional, but\n * not `undefined` itself.\n *\n * @example\n * ```ts\n * type Foo = ObjectOptional<{ foo: string | undefined }>;\n * // Foo is equivalent to { foo?: string }\n * ```\n */\nexport type ObjectOptional<Schema extends Record<string, unknown>> = {\n [Key in keyof Schema as Schema[Key] extends ExactOptionalGuard\n ? Key\n : never]?: Schema[Key] extends ExactOptionalGuard & infer Original\n ? Original\n : never;\n} & {\n [Key in keyof Schema as Schema[Key] extends ExactOptionalGuard\n ? never\n : Key]: Schema[Key];\n};\n\n/**\n * An object type with support for exact optionals. This is used by the `object`\n * struct. This uses the {@link ObjectOptional} helper to make properties with\n * `undefined` in their type optional, but not `undefined` itself.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ObjectOptional<\n Optionalize<{\n [Key in keyof Schema]: Infer<Schema[Key]>;\n }>\n >\n>;\n\n/**\n * A struct to check if the given value is a valid object, with support for\n * {@link exactOptional} types.\n *\n * @param schema - The schema of the object.\n * @returns A struct to check if the given value is an object.\n */\nexport const object = <Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>> =>\n // The type is slightly different from a regular object struct, because we\n // want to make properties with `undefined` in their type optional, but not\n // `undefined` itself. This means that we need a type cast.\n superstructObject(schema) as unknown as Struct<ObjectType<Schema>>;\n\ndeclare const exactOptionalSymbol: unique symbol;\ntype ExactOptionalGuard = {\n _exactOptionalGuard?: typeof exactOptionalSymbol;\n};\n\n/**\n * Check the last field of a path is present.\n *\n * @param context - The context to check.\n * @param context.path - The path to check.\n * @param context.branch - The branch to check.\n * @returns Whether the last field of a path is present.\n */\nfunction hasOptional({ path, branch }: Context): boolean {\n const field = path[path.length - 1];\n return hasProperty(branch[branch.length - 2], field);\n}\n\n/**\n * A struct which allows the property of an object to be absent, or to be present\n * as long as it's valid and not set to `undefined`.\n *\n * This struct should be used in conjunction with the {@link object} from this\n * library, to get proper type inference.\n *\n * @param struct - The struct to check the value against, if present.\n * @returns A struct to check if the given value is valid, or not present.\n * @example\n * ```ts\n * const struct = object({\n * foo: exactOptional(string()),\n * bar: exactOptional(number()),\n * baz: optional(boolean()),\n * qux: unknown(),\n * });\n *\n * type Type = Infer<typeof struct>;\n * // Type is equivalent to:\n * // {\n * // foo?: string;\n * // bar?: number;\n * // baz?: boolean | undefined;\n * // qux: unknown;\n * // }\n * ```\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type & ExactOptionalGuard, Schema> {\n return new Struct<Type & ExactOptionalGuard, Schema>({\n ...struct,\n\n type: `optional ${struct.type}`,\n validator: (value, context) =>\n !hasOptional(context) || struct.validator(value, context),\n\n refiner: (value, context) =>\n !hasOptional(context) || struct.refiner(value as Type, context),\n });\n}\n\n/**\n * A struct to check if the given value is finite number. Superstruct's\n * `number()` struct does not check if the value is finite.\n *\n * @returns A struct to check if the given value is finite number.\n */\nconst finiteNumber = () =>\n define<number>('finite number', (value) => {\n return is(value, number()) && Number.isFinite(value);\n });\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * Note that this struct is unsafe. For safe validation, use {@link JsonStruct}.\n */\n// We cannot infer the type of the struct, because it is recursive.\nexport const UnsafeJsonStruct: Struct<Json> = union([\n literal(null),\n boolean(),\n finiteNumber(),\n string(),\n array(lazy(() => UnsafeJsonStruct)),\n record(\n string(),\n lazy(() => UnsafeJsonStruct),\n ),\n]);\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * This struct sanitizes the value before validating it, so that it is safe to\n * use with untrusted input.\n */\nexport const JsonStruct = coerce(UnsafeJsonStruct, any(), (value) => {\n assertStruct(value, UnsafeJsonStruct);\n return JSON.parse(\n JSON.stringify(value, (propKey, propValue) => {\n // Strip __proto__ and constructor properties to prevent prototype pollution.\n if (propKey === '__proto__' || propKey === 'constructor') {\n return undefined;\n }\n return propValue;\n }),\n );\n});\n\n/**\n * Check if the given value is a valid {@link Json} value, i.e., a value that is\n * serializable to JSON.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link Json} value.\n */\nexport function isValidJson(value: unknown): value is Json {\n try {\n getSafeJson(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validate and return sanitized JSON.\n *\n * Note:\n * This function uses sanitized JsonStruct for validation\n * that applies stringify and then parse of a value provided\n * to ensure that there are no getters which can have side effects\n * that can cause security issues.\n *\n * @param value - JSON structure to be processed.\n * @returns Sanitized JSON structure.\n */\nexport function getSafeJson<Type extends Json = Json>(value: unknown): Type {\n return create(value, JsonStruct) as Type;\n}\n\n/**\n * Get the size of a JSON value in bytes. This also validates the value.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSize(value: unknown): number {\n assertStruct(value, JsonStruct, 'Invalid JSON value');\n\n const json = JSON.stringify(value);\n return new TextEncoder().encode(json).byteLength;\n}\n\n/**\n * The string '2.0'.\n */\nexport const jsonrpc2 = '2.0' as const;\nexport const JsonRpcVersionStruct = literal(jsonrpc2);\n\n/**\n * A String specifying the version of the JSON-RPC protocol.\n * MUST be exactly \"2.0\".\n */\nexport type JsonRpcVersion2 = typeof jsonrpc2;\n\nexport const JsonRpcIdStruct = nullable(union([number(), string()]));\n\n/**\n * An identifier established by the Client that MUST contain a String, Number,\n * or NULL value if included. If it is not included it is assumed to be a\n * notification. The value SHOULD normally not be Null and Numbers SHOULD\n * NOT contain fractional parts.\n */\nexport type JsonRpcId = Infer<typeof JsonRpcIdStruct>;\n\nexport const JsonRpcErrorStruct = object({\n code: integer(),\n message: string(),\n data: exactOptional(JsonStruct),\n stack: exactOptional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record<string, unknown>,\n Key extends keyof Type,\n> = Omit<Type, Key> & Partial<Pick<Type, Key>>;\n\n/**\n * A JSON-RPC error object.\n *\n * Note that TypeScript infers `unknown | undefined` as `unknown`, meaning that\n * the `data` field is not optional. To make it optional, we use the\n * `OptionalField` helper, to explicitly make it optional.\n */\nexport type JsonRpcError = OptionalField<\n Infer<typeof JsonRpcErrorStruct>,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct: Struct<Json[] | Record<string, Json>, null> =\n union([record(string(), JsonStruct), array(JsonStruct)]);\n\nexport type JsonRpcParams = Json[] | Record<string, Json>;\n\nexport const JsonRpcRequestStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: exactOptional(JsonRpcParamsStruct),\n});\n\nexport type InferWithParams<\n Type extends Struct<any>,\n Params extends JsonRpcParams,\n> = Infer<Type> & {\n params?: Params;\n};\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest<Params extends JsonRpcParams = JsonRpcParams> =\n InferWithParams<typeof JsonRpcRequestStruct, Params>;\n\nexport const JsonRpcNotificationStruct = object({\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: exactOptional(JsonRpcParamsStruct),\n});\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification<Params extends JsonRpcParams = JsonRpcParams> =\n InferWithParams<typeof JsonRpcNotificationStruct, Params>;\n\n/**\n * Check if the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcNotification}\n * object.\n */\nexport function isJsonRpcNotification(\n value: unknown,\n): value is JsonRpcNotification {\n return is(value, JsonRpcNotificationStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcNotification} object.\n */\nexport function assertIsJsonRpcNotification(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcNotification {\n assertStruct(\n value,\n JsonRpcNotificationStruct,\n 'Invalid JSON-RPC notification',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcRequest} object.\n */\nexport function isJsonRpcRequest(value: unknown): value is JsonRpcRequest {\n return is(value, JsonRpcRequestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The JSON-RPC request or notification to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcRequest} object.\n */\nexport function assertIsJsonRpcRequest(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcRequest {\n assertStruct(\n value,\n JsonRpcRequestStruct,\n 'Invalid JSON-RPC request',\n ErrorWrapper,\n );\n}\n\nexport const PendingJsonRpcResponseStruct = superstructObject({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: optional(unknown()),\n error: optional(JsonRpcErrorStruct),\n});\n\n/**\n * A JSON-RPC response object that has not yet been resolved.\n */\nexport type PendingJsonRpcResponse<Result extends Json> = Omit<\n Infer<typeof PendingJsonRpcResponseStruct>,\n 'result'\n> & {\n result?: Result;\n};\n\nexport const JsonRpcSuccessStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: JsonStruct,\n});\n\n/**\n * A successful JSON-RPC response object.\n */\nexport type JsonRpcSuccess<Result extends Json> = Omit<\n Infer<typeof JsonRpcSuccessStruct>,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n error: JsonRpcErrorStruct as Struct<JsonRpcError>,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer<typeof JsonRpcFailureStruct>;\n\nexport const JsonRpcResponseStruct = union([\n JsonRpcSuccessStruct,\n JsonRpcFailureStruct,\n]);\n\n/**\n * A JSON-RPC response object. Must be checked to determine whether it's a\n * success or failure.\n *\n * @template Result - The type of the result.\n */\nexport type JsonRpcResponse<Result extends Json> =\n | JsonRpcSuccess<Result>\n | JsonRpcFailure;\n\n/**\n * Type guard to check whether specified JSON-RPC response is a\n * {@link PendingJsonRpcResponse}.\n *\n * @param response - The JSON-RPC response to check.\n * @returns Whether the specified JSON-RPC response is pending.\n */\nexport function isPendingJsonRpcResponse(\n response: unknown,\n): response is PendingJsonRpcResponse<Json> {\n return is(response, PendingJsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link PendingJsonRpcResponse} object.\n *\n * @param response - The JSON-RPC response to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link PendingJsonRpcResponse}\n * object.\n */\nexport function assertIsPendingJsonRpcResponse(\n response: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts response is PendingJsonRpcResponse<Json> {\n assertStruct(\n response,\n PendingJsonRpcResponseStruct,\n 'Invalid pending JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Type guard to check if a value is a {@link JsonRpcResponse}.\n *\n * @param response - The object to check.\n * @returns Whether the object is a JsonRpcResponse.\n */\nexport function isJsonRpcResponse(\n response: unknown,\n): response is JsonRpcResponse<Json> {\n return is(response, JsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcResponse} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcResponse} object.\n */\nexport function assertIsJsonRpcResponse(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcResponse<Json> {\n assertStruct(\n value,\n JsonRpcResponseStruct,\n 'Invalid JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcSuccess} object.\n */\nexport function isJsonRpcSuccess(\n value: unknown,\n): value is JsonRpcSuccess<Json> {\n return is(value, JsonRpcSuccessStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcSuccess} object.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcSuccess<Json> {\n assertStruct(\n value,\n JsonRpcSuccessStruct,\n 'Invalid JSON-RPC success response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcFailure} object.\n */\nexport function isJsonRpcFailure(value: unknown): value is JsonRpcFailure {\n return is(value, JsonRpcFailureStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcFailure} object.\n */\nexport function assertIsJsonRpcFailure(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcFailure {\n assertStruct(\n value,\n JsonRpcFailureStruct,\n 'Invalid JSON-RPC failure response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcError} object.\n */\nexport function isJsonRpcError(value: unknown): value is JsonRpcError {\n return is(value, JsonRpcErrorStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcError} object.\n */\nexport function assertIsJsonRpcError(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcError {\n assertStruct(\n value,\n JsonRpcErrorStruct,\n 'Invalid JSON-RPC error',\n ErrorWrapper,\n );\n}\n\ntype JsonRpcValidatorOptions = {\n permitEmptyString?: boolean;\n permitFractions?: boolean;\n permitNull?: boolean;\n};\n\n/**\n * Gets a function for validating JSON-RPC request / response `id` values.\n *\n * By manipulating the options of this factory, you can control the behavior\n * of the resulting validator for some edge cases. This is useful because e.g.\n * `null` should sometimes but not always be permitted.\n *\n * Note that the empty string (`''`) is always permitted by the JSON-RPC\n * specification, but that kind of sucks and you may want to forbid it in some\n * instances anyway.\n *\n * For more details, see the\n * [JSON-RPC Specification](https://www.jsonrpc.org/specification).\n *\n * @param options - An options object.\n * @param options.permitEmptyString - Whether the empty string (i.e. `''`)\n * should be treated as a valid ID. Default: `true`\n * @param options.permitFractions - Whether fractional numbers (e.g. `1.2`)\n * should be treated as valid IDs. Default: `false`\n * @param options.permitNull - Whether `null` should be treated as a valid ID.\n * Default: `true`\n * @returns The JSON-RPC ID validator function.\n */\nexport function getJsonRpcIdValidator(options?: JsonRpcValidatorOptions) {\n const { permitEmptyString, permitFractions, permitNull } = {\n permitEmptyString: true,\n permitFractions: false,\n permitNull: true,\n ...options,\n };\n\n /**\n * Type guard for {@link JsonRpcId}.\n *\n * @param id - The JSON-RPC ID value to check.\n * @returns Whether the given ID is valid per the options given to the\n * factory.\n */\n const isValidJsonRpcId = (id: unknown): id is JsonRpcId => {\n return Boolean(\n (typeof id === 'number' && (permitFractions || Number.isInteger(id))) ||\n (typeof id === 'string' && (permitEmptyString || id.length > 0)) ||\n (permitNull && id === null),\n );\n };\n\n return isValidJsonRpcId;\n}\n"]}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertStruct
|
|
3
|
+
} from "./chunk-CSDMTDND.mjs";
|
|
4
|
+
import {
|
|
5
|
+
hasProperty
|
|
6
|
+
} from "./chunk-H4YFDLB7.mjs";
|
|
7
|
+
|
|
8
|
+
// src/json.ts
|
|
9
|
+
import {
|
|
10
|
+
any,
|
|
11
|
+
array,
|
|
12
|
+
boolean,
|
|
13
|
+
coerce,
|
|
14
|
+
create,
|
|
15
|
+
define,
|
|
16
|
+
integer,
|
|
17
|
+
is,
|
|
18
|
+
lazy,
|
|
19
|
+
literal,
|
|
20
|
+
nullable,
|
|
21
|
+
number,
|
|
22
|
+
object as superstructObject,
|
|
23
|
+
optional,
|
|
24
|
+
record,
|
|
25
|
+
string,
|
|
26
|
+
union,
|
|
27
|
+
unknown,
|
|
28
|
+
Struct
|
|
29
|
+
} from "superstruct";
|
|
30
|
+
var object = (schema) => (
|
|
31
|
+
// The type is slightly different from a regular object struct, because we
|
|
32
|
+
// want to make properties with `undefined` in their type optional, but not
|
|
33
|
+
// `undefined` itself. This means that we need a type cast.
|
|
34
|
+
superstructObject(schema)
|
|
35
|
+
);
|
|
36
|
+
function hasOptional({ path, branch }) {
|
|
37
|
+
const field = path[path.length - 1];
|
|
38
|
+
return hasProperty(branch[branch.length - 2], field);
|
|
39
|
+
}
|
|
40
|
+
function exactOptional(struct) {
|
|
41
|
+
return new Struct({
|
|
42
|
+
...struct,
|
|
43
|
+
type: `optional ${struct.type}`,
|
|
44
|
+
validator: (value, context) => !hasOptional(context) || struct.validator(value, context),
|
|
45
|
+
refiner: (value, context) => !hasOptional(context) || struct.refiner(value, context)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
var finiteNumber = () => define("finite number", (value) => {
|
|
49
|
+
return is(value, number()) && Number.isFinite(value);
|
|
50
|
+
});
|
|
51
|
+
var UnsafeJsonStruct = union([
|
|
52
|
+
literal(null),
|
|
53
|
+
boolean(),
|
|
54
|
+
finiteNumber(),
|
|
55
|
+
string(),
|
|
56
|
+
array(lazy(() => UnsafeJsonStruct)),
|
|
57
|
+
record(
|
|
58
|
+
string(),
|
|
59
|
+
lazy(() => UnsafeJsonStruct)
|
|
60
|
+
)
|
|
61
|
+
]);
|
|
62
|
+
var JsonStruct = coerce(UnsafeJsonStruct, any(), (value) => {
|
|
63
|
+
assertStruct(value, UnsafeJsonStruct);
|
|
64
|
+
return JSON.parse(
|
|
65
|
+
JSON.stringify(value, (propKey, propValue) => {
|
|
66
|
+
if (propKey === "__proto__" || propKey === "constructor") {
|
|
67
|
+
return void 0;
|
|
68
|
+
}
|
|
69
|
+
return propValue;
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
function isValidJson(value) {
|
|
74
|
+
try {
|
|
75
|
+
getSafeJson(value);
|
|
76
|
+
return true;
|
|
77
|
+
} catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function getSafeJson(value) {
|
|
82
|
+
return create(value, JsonStruct);
|
|
83
|
+
}
|
|
84
|
+
function getJsonSize(value) {
|
|
85
|
+
assertStruct(value, JsonStruct, "Invalid JSON value");
|
|
86
|
+
const json = JSON.stringify(value);
|
|
87
|
+
return new TextEncoder().encode(json).byteLength;
|
|
88
|
+
}
|
|
89
|
+
var jsonrpc2 = "2.0";
|
|
90
|
+
var JsonRpcVersionStruct = literal(jsonrpc2);
|
|
91
|
+
var JsonRpcIdStruct = nullable(union([number(), string()]));
|
|
92
|
+
var JsonRpcErrorStruct = object({
|
|
93
|
+
code: integer(),
|
|
94
|
+
message: string(),
|
|
95
|
+
data: exactOptional(JsonStruct),
|
|
96
|
+
stack: exactOptional(string())
|
|
97
|
+
});
|
|
98
|
+
var JsonRpcParamsStruct = union([record(string(), JsonStruct), array(JsonStruct)]);
|
|
99
|
+
var JsonRpcRequestStruct = object({
|
|
100
|
+
id: JsonRpcIdStruct,
|
|
101
|
+
jsonrpc: JsonRpcVersionStruct,
|
|
102
|
+
method: string(),
|
|
103
|
+
params: exactOptional(JsonRpcParamsStruct)
|
|
104
|
+
});
|
|
105
|
+
var JsonRpcNotificationStruct = object({
|
|
106
|
+
jsonrpc: JsonRpcVersionStruct,
|
|
107
|
+
method: string(),
|
|
108
|
+
params: exactOptional(JsonRpcParamsStruct)
|
|
109
|
+
});
|
|
110
|
+
function isJsonRpcNotification(value) {
|
|
111
|
+
return is(value, JsonRpcNotificationStruct);
|
|
112
|
+
}
|
|
113
|
+
function assertIsJsonRpcNotification(value, ErrorWrapper) {
|
|
114
|
+
assertStruct(
|
|
115
|
+
value,
|
|
116
|
+
JsonRpcNotificationStruct,
|
|
117
|
+
"Invalid JSON-RPC notification",
|
|
118
|
+
ErrorWrapper
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
function isJsonRpcRequest(value) {
|
|
122
|
+
return is(value, JsonRpcRequestStruct);
|
|
123
|
+
}
|
|
124
|
+
function assertIsJsonRpcRequest(value, ErrorWrapper) {
|
|
125
|
+
assertStruct(
|
|
126
|
+
value,
|
|
127
|
+
JsonRpcRequestStruct,
|
|
128
|
+
"Invalid JSON-RPC request",
|
|
129
|
+
ErrorWrapper
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
var PendingJsonRpcResponseStruct = superstructObject({
|
|
133
|
+
id: JsonRpcIdStruct,
|
|
134
|
+
jsonrpc: JsonRpcVersionStruct,
|
|
135
|
+
result: optional(unknown()),
|
|
136
|
+
error: optional(JsonRpcErrorStruct)
|
|
137
|
+
});
|
|
138
|
+
var JsonRpcSuccessStruct = object({
|
|
139
|
+
id: JsonRpcIdStruct,
|
|
140
|
+
jsonrpc: JsonRpcVersionStruct,
|
|
141
|
+
result: JsonStruct
|
|
142
|
+
});
|
|
143
|
+
var JsonRpcFailureStruct = object({
|
|
144
|
+
id: JsonRpcIdStruct,
|
|
145
|
+
jsonrpc: JsonRpcVersionStruct,
|
|
146
|
+
error: JsonRpcErrorStruct
|
|
147
|
+
});
|
|
148
|
+
var JsonRpcResponseStruct = union([
|
|
149
|
+
JsonRpcSuccessStruct,
|
|
150
|
+
JsonRpcFailureStruct
|
|
151
|
+
]);
|
|
152
|
+
function isPendingJsonRpcResponse(response) {
|
|
153
|
+
return is(response, PendingJsonRpcResponseStruct);
|
|
154
|
+
}
|
|
155
|
+
function assertIsPendingJsonRpcResponse(response, ErrorWrapper) {
|
|
156
|
+
assertStruct(
|
|
157
|
+
response,
|
|
158
|
+
PendingJsonRpcResponseStruct,
|
|
159
|
+
"Invalid pending JSON-RPC response",
|
|
160
|
+
ErrorWrapper
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
function isJsonRpcResponse(response) {
|
|
164
|
+
return is(response, JsonRpcResponseStruct);
|
|
165
|
+
}
|
|
166
|
+
function assertIsJsonRpcResponse(value, ErrorWrapper) {
|
|
167
|
+
assertStruct(
|
|
168
|
+
value,
|
|
169
|
+
JsonRpcResponseStruct,
|
|
170
|
+
"Invalid JSON-RPC response",
|
|
171
|
+
ErrorWrapper
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
function isJsonRpcSuccess(value) {
|
|
175
|
+
return is(value, JsonRpcSuccessStruct);
|
|
176
|
+
}
|
|
177
|
+
function assertIsJsonRpcSuccess(value, ErrorWrapper) {
|
|
178
|
+
assertStruct(
|
|
179
|
+
value,
|
|
180
|
+
JsonRpcSuccessStruct,
|
|
181
|
+
"Invalid JSON-RPC success response",
|
|
182
|
+
ErrorWrapper
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
function isJsonRpcFailure(value) {
|
|
186
|
+
return is(value, JsonRpcFailureStruct);
|
|
187
|
+
}
|
|
188
|
+
function assertIsJsonRpcFailure(value, ErrorWrapper) {
|
|
189
|
+
assertStruct(
|
|
190
|
+
value,
|
|
191
|
+
JsonRpcFailureStruct,
|
|
192
|
+
"Invalid JSON-RPC failure response",
|
|
193
|
+
ErrorWrapper
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
function isJsonRpcError(value) {
|
|
197
|
+
return is(value, JsonRpcErrorStruct);
|
|
198
|
+
}
|
|
199
|
+
function assertIsJsonRpcError(value, ErrorWrapper) {
|
|
200
|
+
assertStruct(
|
|
201
|
+
value,
|
|
202
|
+
JsonRpcErrorStruct,
|
|
203
|
+
"Invalid JSON-RPC error",
|
|
204
|
+
ErrorWrapper
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
function getJsonRpcIdValidator(options) {
|
|
208
|
+
const { permitEmptyString, permitFractions, permitNull } = {
|
|
209
|
+
permitEmptyString: true,
|
|
210
|
+
permitFractions: false,
|
|
211
|
+
permitNull: true,
|
|
212
|
+
...options
|
|
213
|
+
};
|
|
214
|
+
const isValidJsonRpcId = (id) => {
|
|
215
|
+
return Boolean(
|
|
216
|
+
typeof id === "number" && (permitFractions || Number.isInteger(id)) || typeof id === "string" && (permitEmptyString || id.length > 0) || permitNull && id === null
|
|
217
|
+
);
|
|
218
|
+
};
|
|
219
|
+
return isValidJsonRpcId;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export {
|
|
223
|
+
object,
|
|
224
|
+
exactOptional,
|
|
225
|
+
UnsafeJsonStruct,
|
|
226
|
+
JsonStruct,
|
|
227
|
+
isValidJson,
|
|
228
|
+
getSafeJson,
|
|
229
|
+
getJsonSize,
|
|
230
|
+
jsonrpc2,
|
|
231
|
+
JsonRpcVersionStruct,
|
|
232
|
+
JsonRpcIdStruct,
|
|
233
|
+
JsonRpcErrorStruct,
|
|
234
|
+
JsonRpcParamsStruct,
|
|
235
|
+
JsonRpcRequestStruct,
|
|
236
|
+
JsonRpcNotificationStruct,
|
|
237
|
+
isJsonRpcNotification,
|
|
238
|
+
assertIsJsonRpcNotification,
|
|
239
|
+
isJsonRpcRequest,
|
|
240
|
+
assertIsJsonRpcRequest,
|
|
241
|
+
PendingJsonRpcResponseStruct,
|
|
242
|
+
JsonRpcSuccessStruct,
|
|
243
|
+
JsonRpcFailureStruct,
|
|
244
|
+
JsonRpcResponseStruct,
|
|
245
|
+
isPendingJsonRpcResponse,
|
|
246
|
+
assertIsPendingJsonRpcResponse,
|
|
247
|
+
isJsonRpcResponse,
|
|
248
|
+
assertIsJsonRpcResponse,
|
|
249
|
+
isJsonRpcSuccess,
|
|
250
|
+
assertIsJsonRpcSuccess,
|
|
251
|
+
isJsonRpcFailure,
|
|
252
|
+
assertIsJsonRpcFailure,
|
|
253
|
+
isJsonRpcError,
|
|
254
|
+
assertIsJsonRpcError,
|
|
255
|
+
getJsonRpcIdValidator
|
|
256
|
+
};
|
|
257
|
+
//# sourceMappingURL=chunk-65KBH4FZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/json.ts"],"sourcesContent":["import type { Context, Infer } from 'superstruct';\nimport {\n any,\n array,\n boolean,\n coerce,\n create,\n define,\n integer,\n is,\n lazy,\n literal,\n nullable,\n number,\n object as superstructObject,\n optional,\n record,\n string,\n union,\n unknown,\n Struct,\n} from 'superstruct';\nimport type {\n ObjectSchema,\n Optionalize,\n Simplify,\n} from 'superstruct/dist/utils';\n\nimport type { AssertionErrorConstructor } from './assert';\nimport { assertStruct } from './assert';\nimport { hasProperty } from './misc';\n\n/**\n * Any JSON-compatible value.\n */\nexport type Json =\n | null\n | boolean\n | number\n | string\n | Json[]\n | { [prop: string]: Json };\n\n/**\n * A helper type to make properties with `undefined` in their type optional, but\n * not `undefined` itself.\n *\n * @example\n * ```ts\n * type Foo = ObjectOptional<{ foo: string | undefined }>;\n * // Foo is equivalent to { foo?: string }\n * ```\n */\nexport type ObjectOptional<Schema extends Record<string, unknown>> = {\n [Key in keyof Schema as Schema[Key] extends ExactOptionalGuard\n ? Key\n : never]?: Schema[Key] extends ExactOptionalGuard & infer Original\n ? Original\n : never;\n} & {\n [Key in keyof Schema as Schema[Key] extends ExactOptionalGuard\n ? never\n : Key]: Schema[Key];\n};\n\n/**\n * An object type with support for exact optionals. This is used by the `object`\n * struct. This uses the {@link ObjectOptional} helper to make properties with\n * `undefined` in their type optional, but not `undefined` itself.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ObjectOptional<\n Optionalize<{\n [Key in keyof Schema]: Infer<Schema[Key]>;\n }>\n >\n>;\n\n/**\n * A struct to check if the given value is a valid object, with support for\n * {@link exactOptional} types.\n *\n * @param schema - The schema of the object.\n * @returns A struct to check if the given value is an object.\n */\nexport const object = <Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>> =>\n // The type is slightly different from a regular object struct, because we\n // want to make properties with `undefined` in their type optional, but not\n // `undefined` itself. This means that we need a type cast.\n superstructObject(schema) as unknown as Struct<ObjectType<Schema>>;\n\ndeclare const exactOptionalSymbol: unique symbol;\ntype ExactOptionalGuard = {\n _exactOptionalGuard?: typeof exactOptionalSymbol;\n};\n\n/**\n * Check the last field of a path is present.\n *\n * @param context - The context to check.\n * @param context.path - The path to check.\n * @param context.branch - The branch to check.\n * @returns Whether the last field of a path is present.\n */\nfunction hasOptional({ path, branch }: Context): boolean {\n const field = path[path.length - 1];\n return hasProperty(branch[branch.length - 2], field);\n}\n\n/**\n * A struct which allows the property of an object to be absent, or to be present\n * as long as it's valid and not set to `undefined`.\n *\n * This struct should be used in conjunction with the {@link object} from this\n * library, to get proper type inference.\n *\n * @param struct - The struct to check the value against, if present.\n * @returns A struct to check if the given value is valid, or not present.\n * @example\n * ```ts\n * const struct = object({\n * foo: exactOptional(string()),\n * bar: exactOptional(number()),\n * baz: optional(boolean()),\n * qux: unknown(),\n * });\n *\n * type Type = Infer<typeof struct>;\n * // Type is equivalent to:\n * // {\n * // foo?: string;\n * // bar?: number;\n * // baz?: boolean | undefined;\n * // qux: unknown;\n * // }\n * ```\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type & ExactOptionalGuard, Schema> {\n return new Struct<Type & ExactOptionalGuard, Schema>({\n ...struct,\n\n type: `optional ${struct.type}`,\n validator: (value, context) =>\n !hasOptional(context) || struct.validator(value, context),\n\n refiner: (value, context) =>\n !hasOptional(context) || struct.refiner(value as Type, context),\n });\n}\n\n/**\n * A struct to check if the given value is finite number. Superstruct's\n * `number()` struct does not check if the value is finite.\n *\n * @returns A struct to check if the given value is finite number.\n */\nconst finiteNumber = () =>\n define<number>('finite number', (value) => {\n return is(value, number()) && Number.isFinite(value);\n });\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * Note that this struct is unsafe. For safe validation, use {@link JsonStruct}.\n */\n// We cannot infer the type of the struct, because it is recursive.\nexport const UnsafeJsonStruct: Struct<Json> = union([\n literal(null),\n boolean(),\n finiteNumber(),\n string(),\n array(lazy(() => UnsafeJsonStruct)),\n record(\n string(),\n lazy(() => UnsafeJsonStruct),\n ),\n]);\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * This struct sanitizes the value before validating it, so that it is safe to\n * use with untrusted input.\n */\nexport const JsonStruct = coerce(UnsafeJsonStruct, any(), (value) => {\n assertStruct(value, UnsafeJsonStruct);\n return JSON.parse(\n JSON.stringify(value, (propKey, propValue) => {\n // Strip __proto__ and constructor properties to prevent prototype pollution.\n if (propKey === '__proto__' || propKey === 'constructor') {\n return undefined;\n }\n return propValue;\n }),\n );\n});\n\n/**\n * Check if the given value is a valid {@link Json} value, i.e., a value that is\n * serializable to JSON.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link Json} value.\n */\nexport function isValidJson(value: unknown): value is Json {\n try {\n getSafeJson(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validate and return sanitized JSON.\n *\n * Note:\n * This function uses sanitized JsonStruct for validation\n * that applies stringify and then parse of a value provided\n * to ensure that there are no getters which can have side effects\n * that can cause security issues.\n *\n * @param value - JSON structure to be processed.\n * @returns Sanitized JSON structure.\n */\nexport function getSafeJson<Type extends Json = Json>(value: unknown): Type {\n return create(value, JsonStruct) as Type;\n}\n\n/**\n * Get the size of a JSON value in bytes. This also validates the value.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSize(value: unknown): number {\n assertStruct(value, JsonStruct, 'Invalid JSON value');\n\n const json = JSON.stringify(value);\n return new TextEncoder().encode(json).byteLength;\n}\n\n/**\n * The string '2.0'.\n */\nexport const jsonrpc2 = '2.0' as const;\nexport const JsonRpcVersionStruct = literal(jsonrpc2);\n\n/**\n * A String specifying the version of the JSON-RPC protocol.\n * MUST be exactly \"2.0\".\n */\nexport type JsonRpcVersion2 = typeof jsonrpc2;\n\nexport const JsonRpcIdStruct = nullable(union([number(), string()]));\n\n/**\n * An identifier established by the Client that MUST contain a String, Number,\n * or NULL value if included. If it is not included it is assumed to be a\n * notification. The value SHOULD normally not be Null and Numbers SHOULD\n * NOT contain fractional parts.\n */\nexport type JsonRpcId = Infer<typeof JsonRpcIdStruct>;\n\nexport const JsonRpcErrorStruct = object({\n code: integer(),\n message: string(),\n data: exactOptional(JsonStruct),\n stack: exactOptional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record<string, unknown>,\n Key extends keyof Type,\n> = Omit<Type, Key> & Partial<Pick<Type, Key>>;\n\n/**\n * A JSON-RPC error object.\n *\n * Note that TypeScript infers `unknown | undefined` as `unknown`, meaning that\n * the `data` field is not optional. To make it optional, we use the\n * `OptionalField` helper, to explicitly make it optional.\n */\nexport type JsonRpcError = OptionalField<\n Infer<typeof JsonRpcErrorStruct>,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct: Struct<Json[] | Record<string, Json>, null> =\n union([record(string(), JsonStruct), array(JsonStruct)]);\n\nexport type JsonRpcParams = Json[] | Record<string, Json>;\n\nexport const JsonRpcRequestStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: exactOptional(JsonRpcParamsStruct),\n});\n\nexport type InferWithParams<\n Type extends Struct<any>,\n Params extends JsonRpcParams,\n> = Infer<Type> & {\n params?: Params;\n};\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest<Params extends JsonRpcParams = JsonRpcParams> =\n InferWithParams<typeof JsonRpcRequestStruct, Params>;\n\nexport const JsonRpcNotificationStruct = object({\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: exactOptional(JsonRpcParamsStruct),\n});\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification<Params extends JsonRpcParams = JsonRpcParams> =\n InferWithParams<typeof JsonRpcNotificationStruct, Params>;\n\n/**\n * Check if the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcNotification}\n * object.\n */\nexport function isJsonRpcNotification(\n value: unknown,\n): value is JsonRpcNotification {\n return is(value, JsonRpcNotificationStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcNotification} object.\n */\nexport function assertIsJsonRpcNotification(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcNotification {\n assertStruct(\n value,\n JsonRpcNotificationStruct,\n 'Invalid JSON-RPC notification',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcRequest} object.\n */\nexport function isJsonRpcRequest(value: unknown): value is JsonRpcRequest {\n return is(value, JsonRpcRequestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The JSON-RPC request or notification to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcRequest} object.\n */\nexport function assertIsJsonRpcRequest(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcRequest {\n assertStruct(\n value,\n JsonRpcRequestStruct,\n 'Invalid JSON-RPC request',\n ErrorWrapper,\n );\n}\n\nexport const PendingJsonRpcResponseStruct = superstructObject({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: optional(unknown()),\n error: optional(JsonRpcErrorStruct),\n});\n\n/**\n * A JSON-RPC response object that has not yet been resolved.\n */\nexport type PendingJsonRpcResponse<Result extends Json> = Omit<\n Infer<typeof PendingJsonRpcResponseStruct>,\n 'result'\n> & {\n result?: Result;\n};\n\nexport const JsonRpcSuccessStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: JsonStruct,\n});\n\n/**\n * A successful JSON-RPC response object.\n */\nexport type JsonRpcSuccess<Result extends Json> = Omit<\n Infer<typeof JsonRpcSuccessStruct>,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n error: JsonRpcErrorStruct as Struct<JsonRpcError>,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer<typeof JsonRpcFailureStruct>;\n\nexport const JsonRpcResponseStruct = union([\n JsonRpcSuccessStruct,\n JsonRpcFailureStruct,\n]);\n\n/**\n * A JSON-RPC response object. Must be checked to determine whether it's a\n * success or failure.\n *\n * @template Result - The type of the result.\n */\nexport type JsonRpcResponse<Result extends Json> =\n | JsonRpcSuccess<Result>\n | JsonRpcFailure;\n\n/**\n * Type guard to check whether specified JSON-RPC response is a\n * {@link PendingJsonRpcResponse}.\n *\n * @param response - The JSON-RPC response to check.\n * @returns Whether the specified JSON-RPC response is pending.\n */\nexport function isPendingJsonRpcResponse(\n response: unknown,\n): response is PendingJsonRpcResponse<Json> {\n return is(response, PendingJsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link PendingJsonRpcResponse} object.\n *\n * @param response - The JSON-RPC response to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link PendingJsonRpcResponse}\n * object.\n */\nexport function assertIsPendingJsonRpcResponse(\n response: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts response is PendingJsonRpcResponse<Json> {\n assertStruct(\n response,\n PendingJsonRpcResponseStruct,\n 'Invalid pending JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Type guard to check if a value is a {@link JsonRpcResponse}.\n *\n * @param response - The object to check.\n * @returns Whether the object is a JsonRpcResponse.\n */\nexport function isJsonRpcResponse(\n response: unknown,\n): response is JsonRpcResponse<Json> {\n return is(response, JsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcResponse} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcResponse} object.\n */\nexport function assertIsJsonRpcResponse(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcResponse<Json> {\n assertStruct(\n value,\n JsonRpcResponseStruct,\n 'Invalid JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcSuccess} object.\n */\nexport function isJsonRpcSuccess(\n value: unknown,\n): value is JsonRpcSuccess<Json> {\n return is(value, JsonRpcSuccessStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcSuccess} object.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcSuccess<Json> {\n assertStruct(\n value,\n JsonRpcSuccessStruct,\n 'Invalid JSON-RPC success response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcFailure} object.\n */\nexport function isJsonRpcFailure(value: unknown): value is JsonRpcFailure {\n return is(value, JsonRpcFailureStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcFailure} object.\n */\nexport function assertIsJsonRpcFailure(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcFailure {\n assertStruct(\n value,\n JsonRpcFailureStruct,\n 'Invalid JSON-RPC failure response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcError} object.\n */\nexport function isJsonRpcError(value: unknown): value is JsonRpcError {\n return is(value, JsonRpcErrorStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcError} object.\n */\nexport function assertIsJsonRpcError(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcError {\n assertStruct(\n value,\n JsonRpcErrorStruct,\n 'Invalid JSON-RPC error',\n ErrorWrapper,\n );\n}\n\ntype JsonRpcValidatorOptions = {\n permitEmptyString?: boolean;\n permitFractions?: boolean;\n permitNull?: boolean;\n};\n\n/**\n * Gets a function for validating JSON-RPC request / response `id` values.\n *\n * By manipulating the options of this factory, you can control the behavior\n * of the resulting validator for some edge cases. This is useful because e.g.\n * `null` should sometimes but not always be permitted.\n *\n * Note that the empty string (`''`) is always permitted by the JSON-RPC\n * specification, but that kind of sucks and you may want to forbid it in some\n * instances anyway.\n *\n * For more details, see the\n * [JSON-RPC Specification](https://www.jsonrpc.org/specification).\n *\n * @param options - An options object.\n * @param options.permitEmptyString - Whether the empty string (i.e. `''`)\n * should be treated as a valid ID. Default: `true`\n * @param options.permitFractions - Whether fractional numbers (e.g. `1.2`)\n * should be treated as valid IDs. Default: `false`\n * @param options.permitNull - Whether `null` should be treated as a valid ID.\n * Default: `true`\n * @returns The JSON-RPC ID validator function.\n */\nexport function getJsonRpcIdValidator(options?: JsonRpcValidatorOptions) {\n const { permitEmptyString, permitFractions, permitNull } = {\n permitEmptyString: true,\n permitFractions: false,\n permitNull: true,\n ...options,\n };\n\n /**\n * Type guard for {@link JsonRpcId}.\n *\n * @param id - The JSON-RPC ID value to check.\n * @returns Whether the given ID is valid per the options given to the\n * factory.\n */\n const isValidJsonRpcId = (id: unknown): id is JsonRpcId => {\n return Boolean(\n (typeof id === 'number' && (permitFractions || Number.isInteger(id))) ||\n (typeof id === 'string' && (permitEmptyString || id.length > 0)) ||\n (permitNull && id === null),\n );\n };\n\n return isValidJson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