@metamask/utils 8.4.0 → 8.5.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 +14 -1
- package/dist/assert.cjs +127 -0
- package/dist/assert.cjs.map +1 -0
- package/dist/{types/assert.d.ts → assert.d.cts} +3 -3
- package/dist/assert.d.cts.map +1 -0
- package/dist/assert.d.mts +61 -0
- package/dist/assert.d.mts.map +1 -0
- package/dist/assert.mjs +119 -15
- package/dist/assert.mjs.map +1 -1
- package/dist/base64.cjs +34 -0
- package/dist/base64.cjs.map +1 -0
- package/dist/{types/base64.d.ts → base64.d.cts} +3 -3
- package/dist/base64.d.cts.map +1 -0
- package/dist/base64.d.mts +25 -0
- package/dist/base64.d.mts.map +1 -0
- package/dist/base64.mjs +28 -9
- package/dist/base64.mjs.map +1 -1
- package/dist/bytes.cjs +400 -0
- package/dist/{chunk-QEPVHEP7.js.map → bytes.cjs.map} +1 -1
- package/dist/{types/bytes.d.ts → bytes.d.cts} +3 -3
- package/dist/bytes.d.cts.map +1 -0
- package/dist/bytes.d.mts +183 -0
- package/dist/bytes.d.mts.map +1 -0
- package/dist/bytes.mjs +379 -42
- package/dist/bytes.mjs.map +1 -1
- package/dist/caip-types.cjs +151 -0
- package/dist/caip-types.cjs.map +1 -0
- package/dist/{types/caip-types.d.ts → caip-types.d.cts} +12 -12
- package/dist/caip-types.d.cts.map +1 -0
- package/dist/caip-types.d.mts +114 -0
- package/dist/caip-types.d.mts.map +1 -0
- package/dist/caip-types.mjs +139 -43
- package/dist/caip-types.mjs.map +1 -1
- package/dist/checksum.cjs +7 -0
- package/dist/checksum.cjs.map +1 -0
- package/dist/checksum.d.cts +2 -0
- package/dist/checksum.d.cts.map +1 -0
- package/dist/checksum.d.mts +2 -0
- package/dist/checksum.d.mts.map +1 -0
- package/dist/checksum.mjs +3 -11
- package/dist/checksum.mjs.map +1 -1
- package/dist/coercers.cjs +162 -0
- package/dist/coercers.cjs.map +1 -0
- package/dist/{types/coercers.d.ts → coercers.d.cts} +7 -7
- package/dist/coercers.d.cts.map +1 -0
- package/dist/coercers.d.mts +97 -0
- package/dist/coercers.d.mts.map +1 -0
- package/dist/coercers.mjs +154 -17
- package/dist/coercers.mjs.map +1 -1
- package/dist/collections.cjs +109 -0
- package/dist/collections.cjs.map +1 -0
- package/dist/{types/collections.d.ts → collections.d.cts} +1 -1
- package/dist/collections.d.cts.map +1 -0
- package/dist/collections.d.mts +39 -0
- package/dist/collections.d.mts.map +1 -0
- package/dist/collections.mjs +103 -8
- package/dist/collections.mjs.map +1 -1
- package/dist/encryption-types.cjs +3 -0
- package/dist/encryption-types.cjs.map +1 -0
- package/dist/{types/encryption-types.d.ts → encryption-types.d.cts} +2 -2
- package/dist/encryption-types.d.cts.map +1 -0
- package/dist/encryption-types.d.mts +7 -0
- package/dist/encryption-types.d.mts.map +1 -0
- package/dist/encryption-types.mjs +1 -1
- package/dist/encryption-types.mjs.map +1 -1
- package/dist/errors.cjs +111 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/{types/errors.d.ts → errors.d.cts} +1 -1
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +58 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +102 -16
- package/dist/errors.mjs.map +1 -1
- package/dist/fs.cjs +248 -0
- package/dist/fs.cjs.map +1 -0
- package/dist/{types/fs.d.ts → fs.d.cts} +3 -3
- package/dist/fs.d.cts.map +1 -0
- package/dist/fs.d.mts +133 -0
- package/dist/fs.d.mts.map +1 -0
- package/dist/fs.mjs +209 -25
- package/dist/fs.mjs.map +1 -1
- package/dist/hex.cjs +134 -0
- package/dist/hex.cjs.map +1 -0
- package/dist/{types/hex.d.ts → hex.d.cts} +3 -3
- package/dist/hex.d.cts.map +1 -0
- package/dist/hex.d.mts +77 -0
- package/dist/hex.d.mts.map +1 -0
- package/dist/hex.mjs +121 -34
- package/dist/hex.mjs.map +1 -1
- package/dist/index.cjs +37 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +20 -296
- package/dist/index.mjs.map +1 -1
- package/dist/json.cjs +413 -0
- package/dist/json.cjs.map +1 -0
- package/dist/{types/json.d.ts → json.d.cts} +21 -22
- package/dist/json.d.cts.map +1 -0
- package/dist/json.d.mts +383 -0
- package/dist/json.d.mts.map +1 -0
- package/dist/json.mjs +389 -74
- package/dist/json.mjs.map +1 -1
- package/dist/keyring.cjs +3 -0
- package/dist/keyring.cjs.map +1 -0
- package/dist/{types/keyring.d.ts → keyring.d.cts} +7 -7
- package/dist/keyring.d.cts.map +1 -0
- package/dist/keyring.d.mts +224 -0
- package/dist/keyring.d.mts.map +1 -0
- package/dist/keyring.mjs +1 -1
- package/dist/keyring.mjs.map +1 -1
- package/dist/logging.cjs +43 -0
- package/dist/logging.cjs.map +1 -0
- package/dist/{types/logging.d.ts → logging.d.cts} +2 -2
- package/dist/logging.d.cts.map +1 -0
- package/dist/logging.d.mts +30 -0
- package/dist/logging.d.mts.map +1 -0
- package/dist/logging.mjs +34 -9
- package/dist/logging.mjs.map +1 -1
- package/dist/misc.cjs +149 -0
- package/dist/misc.cjs.map +1 -0
- package/dist/{types/misc.d.ts → misc.d.cts} +6 -6
- package/dist/misc.d.cts.map +1 -0
- package/dist/misc.d.mts +119 -0
- package/dist/misc.d.mts.map +1 -0
- package/dist/misc.mjs +136 -27
- package/dist/misc.mjs.map +1 -1
- package/dist/node.cjs +19 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +3 -0
- package/dist/node.d.cts.map +1 -0
- package/dist/node.d.mts +3 -0
- package/dist/node.d.mts.map +1 -0
- package/dist/node.mjs +2 -316
- package/dist/node.mjs.map +1 -1
- package/dist/number.cjs +102 -0
- package/dist/number.cjs.map +1 -0
- package/dist/{types/number.d.ts → number.d.cts} +1 -1
- package/dist/number.d.cts.map +1 -0
- package/dist/number.d.mts +73 -0
- package/dist/number.d.mts.map +1 -0
- package/dist/number.mjs +93 -16
- package/dist/number.mjs.map +1 -1
- package/dist/opaque.cjs +3 -0
- package/dist/opaque.cjs.map +1 -0
- package/dist/opaque.d.cts +6 -0
- package/dist/opaque.d.cts.map +1 -0
- package/dist/opaque.d.mts +6 -0
- package/dist/opaque.d.mts.map +1 -0
- package/dist/opaque.mjs +1 -1
- package/dist/opaque.mjs.map +1 -1
- package/dist/promise.cjs +40 -0
- package/dist/promise.cjs.map +1 -0
- package/dist/{types/promise.d.ts → promise.d.cts} +2 -2
- package/dist/promise.d.cts.map +1 -0
- package/dist/promise.d.mts +45 -0
- package/dist/promise.d.mts.map +1 -0
- package/dist/promise.mjs +35 -7
- package/dist/promise.mjs.map +1 -1
- package/dist/time.cjs +67 -0
- package/dist/time.cjs.map +1 -0
- package/dist/{types/time.d.ts → time.d.cts} +1 -1
- package/dist/time.d.cts.map +1 -0
- package/dist/time.d.mts +49 -0
- package/dist/time.d.mts.map +1 -0
- package/dist/time.mjs +60 -10
- package/dist/time.mjs.map +1 -1
- package/dist/transaction-types.cjs +3 -0
- package/dist/transaction-types.cjs.map +1 -0
- package/dist/{types/transaction-types.d.ts → transaction-types.d.cts} +11 -11
- package/dist/transaction-types.d.cts.map +1 -0
- package/dist/transaction-types.d.mts +117 -0
- package/dist/transaction-types.d.mts.map +1 -0
- package/dist/transaction-types.mjs +1 -1
- package/dist/transaction-types.mjs.map +1 -1
- package/dist/versions.cjs +95 -0
- package/dist/versions.cjs.map +1 -0
- package/dist/{types/versions.d.ts → versions.d.cts} +5 -5
- package/dist/versions.d.cts.map +1 -0
- package/dist/versions.d.mts +101 -0
- package/dist/versions.d.mts.map +1 -0
- package/dist/versions.mjs +85 -26
- package/dist/versions.mjs.map +1 -1
- package/package.json +26 -17
- package/dist/assert.js +0 -16
- package/dist/assert.js.map +0 -1
- package/dist/base64.js +0 -11
- package/dist/base64.js.map +0 -1
- package/dist/bytes.js +0 -43
- package/dist/bytes.js.map +0 -1
- package/dist/caip-types.js +0 -44
- package/dist/caip-types.js.map +0 -1
- package/dist/checksum.js +0 -12
- package/dist/checksum.js.map +0 -1
- package/dist/chunk-2LBGT4GH.js +0 -15
- package/dist/chunk-2LBGT4GH.js.map +0 -1
- package/dist/chunk-3W5G4CYI.js +0 -25
- package/dist/chunk-3W5G4CYI.js.map +0 -1
- package/dist/chunk-4D6XQBHA.js +0 -69
- package/dist/chunk-4D6XQBHA.js.map +0 -1
- package/dist/chunk-4RMX5YWE.js +0 -34
- package/dist/chunk-4RMX5YWE.js.map +0 -1
- package/dist/chunk-5AVWINSB.js +0 -1
- package/dist/chunk-5AVWINSB.js.map +0 -1
- package/dist/chunk-622IOGVI.mjs +0 -1
- package/dist/chunk-622IOGVI.mjs.map +0 -1
- package/dist/chunk-6C35XQOF.mjs +0 -257
- package/dist/chunk-6C35XQOF.mjs.map +0 -1
- package/dist/chunk-6NZW4WK4.js +0 -35
- package/dist/chunk-6NZW4WK4.js.map +0 -1
- package/dist/chunk-6ZDHSOUV.js +0 -59
- package/dist/chunk-6ZDHSOUV.js.map +0 -1
- package/dist/chunk-74DGVJVE.mjs +0 -59
- package/dist/chunk-74DGVJVE.mjs.map +0 -1
- package/dist/chunk-AY6FDCBT.mjs +0 -1
- package/dist/chunk-AY6FDCBT.mjs.map +0 -1
- package/dist/chunk-C6HGFEYL.js +0 -23
- package/dist/chunk-C6HGFEYL.js.map +0 -1
- package/dist/chunk-DHVKFDHQ.js +0 -95
- package/dist/chunk-DHVKFDHQ.js.map +0 -1
- package/dist/chunk-DYRKZQMK.mjs +0 -122
- package/dist/chunk-DYRKZQMK.mjs.map +0 -1
- package/dist/chunk-E4C7EW4R.js +0 -16
- package/dist/chunk-E4C7EW4R.js.map +0 -1
- package/dist/chunk-EQMZL4XU.js +0 -1
- package/dist/chunk-EQMZL4XU.js.map +0 -1
- package/dist/chunk-GZS3IQBZ.mjs +0 -16
- package/dist/chunk-GZS3IQBZ.mjs.map +0 -1
- package/dist/chunk-H4YFDLB7.mjs +0 -70
- package/dist/chunk-H4YFDLB7.mjs.map +0 -1
- package/dist/chunk-I575FZFH.mjs +0 -1
- package/dist/chunk-I575FZFH.mjs.map +0 -1
- package/dist/chunk-IZC266HS.js +0 -55
- package/dist/chunk-IZC266HS.js.map +0 -1
- package/dist/chunk-JPAL7Q5S.mjs +0 -90
- package/dist/chunk-JPAL7Q5S.mjs.map +0 -1
- package/dist/chunk-LC2CRSWD.js +0 -1
- package/dist/chunk-LC2CRSWD.js.map +0 -1
- package/dist/chunk-NQMRFZHB.mjs +0 -35
- package/dist/chunk-NQMRFZHB.mjs.map +0 -1
- package/dist/chunk-O3EIM33O.mjs +0 -95
- package/dist/chunk-O3EIM33O.mjs.map +0 -1
- package/dist/chunk-OLLG4H35.js +0 -257
- package/dist/chunk-OLLG4H35.js.map +0 -1
- package/dist/chunk-OUZ3LSLX.mjs +0 -94
- package/dist/chunk-OUZ3LSLX.mjs.map +0 -1
- package/dist/chunk-QEPVHEP7.js +0 -273
- package/dist/chunk-QVEKZRZ2.js +0 -70
- package/dist/chunk-QVEKZRZ2.js.map +0 -1
- package/dist/chunk-RIRDOQPX.mjs +0 -15
- package/dist/chunk-RIRDOQPX.mjs.map +0 -1
- package/dist/chunk-RKRGAFXY.js +0 -1
- package/dist/chunk-RKRGAFXY.js.map +0 -1
- package/dist/chunk-RNEXSCNP.js +0 -122
- package/dist/chunk-RNEXSCNP.js.map +0 -1
- package/dist/chunk-ROQSKDP5.mjs +0 -69
- package/dist/chunk-ROQSKDP5.mjs.map +0 -1
- package/dist/chunk-RRYOWRCV.mjs +0 -1
- package/dist/chunk-RRYOWRCV.mjs.map +0 -1
- package/dist/chunk-S3UHBN2Z.mjs +0 -44
- package/dist/chunk-S3UHBN2Z.mjs.map +0 -1
- package/dist/chunk-THNLGEXV.mjs +0 -34
- package/dist/chunk-THNLGEXV.mjs.map +0 -1
- package/dist/chunk-UOTVU7OQ.js +0 -1
- package/dist/chunk-UOTVU7OQ.js.map +0 -1
- package/dist/chunk-VA2DRBDE.mjs +0 -273
- package/dist/chunk-VA2DRBDE.mjs.map +0 -1
- package/dist/chunk-VFXTVNXN.js +0 -44
- package/dist/chunk-VFXTVNXN.js.map +0 -1
- package/dist/chunk-W5XI7ERF.mjs +0 -23
- package/dist/chunk-W5XI7ERF.mjs.map +0 -1
- package/dist/chunk-WA4DHIND.mjs +0 -1
- package/dist/chunk-WA4DHIND.mjs.map +0 -1
- package/dist/chunk-X66SUIEF.mjs +0 -25
- package/dist/chunk-X66SUIEF.mjs.map +0 -1
- package/dist/chunk-XYGUOY6N.mjs +0 -55
- package/dist/chunk-XYGUOY6N.mjs.map +0 -1
- package/dist/chunk-YWAID473.js +0 -94
- package/dist/chunk-YWAID473.js.map +0 -1
- package/dist/chunk-Z2RGWDD7.js +0 -90
- package/dist/chunk-Z2RGWDD7.js.map +0 -1
- package/dist/coercers.js +0 -18
- package/dist/coercers.js.map +0 -1
- package/dist/collections.js +0 -10
- package/dist/collections.js.map +0 -1
- package/dist/encryption-types.js +0 -2
- package/dist/encryption-types.js.map +0 -1
- package/dist/errors.js +0 -17
- package/dist/errors.js.map +0 -1
- package/dist/fs.js +0 -26
- package/dist/fs.js.map +0 -1
- package/dist/hex.js +0 -35
- package/dist/hex.js.map +0 -1
- package/dist/index.js +0 -297
- package/dist/index.js.map +0 -1
- package/dist/json.js +0 -75
- package/dist/json.js.map +0 -1
- package/dist/keyring.js +0 -2
- package/dist/keyring.js.map +0 -1
- package/dist/logging.js +0 -10
- package/dist/logging.js.map +0 -1
- package/dist/misc.js +0 -28
- package/dist/misc.js.map +0 -1
- package/dist/node.js +0 -317
- package/dist/node.js.map +0 -1
- package/dist/number.js +0 -18
- package/dist/number.js.map +0 -1
- package/dist/opaque.js +0 -2
- package/dist/opaque.js.map +0 -1
- package/dist/promise.js +0 -8
- package/dist/promise.js.map +0 -1
- package/dist/time.js +0 -12
- package/dist/time.js.map +0 -1
- package/dist/transaction-types.js +0 -2
- package/dist/transaction-types.js.map +0 -1
- package/dist/types/assert.d.ts.map +0 -1
- package/dist/types/base64.d.ts.map +0 -1
- package/dist/types/bytes.d.ts.map +0 -1
- package/dist/types/caip-types.d.ts.map +0 -1
- package/dist/types/checksum.d.ts +0 -2
- package/dist/types/checksum.d.ts.map +0 -1
- package/dist/types/coercers.d.ts.map +0 -1
- package/dist/types/collections.d.ts.map +0 -1
- package/dist/types/encryption-types.d.ts.map +0 -1
- package/dist/types/errors.d.ts.map +0 -1
- package/dist/types/fs.d.ts.map +0 -1
- package/dist/types/hex.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -21
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/json.d.ts.map +0 -1
- package/dist/types/keyring.d.ts.map +0 -1
- package/dist/types/logging.d.ts.map +0 -1
- package/dist/types/misc.d.ts.map +0 -1
- package/dist/types/node.d.ts +0 -3
- package/dist/types/node.d.ts.map +0 -1
- package/dist/types/number.d.ts.map +0 -1
- package/dist/types/opaque.d.ts +0 -6
- package/dist/types/opaque.d.ts.map +0 -1
- package/dist/types/promise.d.ts.map +0 -1
- package/dist/types/time.d.ts.map +0 -1
- package/dist/types/transaction-types.d.ts.map +0 -1
- package/dist/types/versions.d.ts.map +0 -1
- package/dist/versions.js +0 -27
- package/dist/versions.js.map +0 -1
package/dist/json.cjs
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getJsonRpcIdValidator = exports.assertIsJsonRpcError = exports.isJsonRpcError = exports.assertIsJsonRpcFailure = exports.isJsonRpcFailure = exports.assertIsJsonRpcSuccess = exports.isJsonRpcSuccess = exports.assertIsJsonRpcResponse = exports.isJsonRpcResponse = exports.assertIsPendingJsonRpcResponse = exports.isPendingJsonRpcResponse = exports.JsonRpcResponseStruct = exports.JsonRpcFailureStruct = exports.JsonRpcSuccessStruct = exports.PendingJsonRpcResponseStruct = exports.assertIsJsonRpcRequest = exports.isJsonRpcRequest = exports.assertIsJsonRpcNotification = exports.isJsonRpcNotification = exports.JsonRpcNotificationStruct = exports.JsonRpcRequestStruct = exports.JsonRpcParamsStruct = exports.JsonRpcErrorStruct = exports.JsonRpcIdStruct = exports.JsonRpcVersionStruct = exports.jsonrpc2 = exports.getJsonSize = exports.getSafeJson = exports.isValidJson = exports.JsonStruct = exports.UnsafeJsonStruct = exports.exactOptional = exports.object = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
const assert_1 = require("./assert.cjs");
|
|
6
|
+
const misc_1 = require("./misc.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* A struct to check if the given value is a valid object, with support for
|
|
9
|
+
* {@link exactOptional} types.
|
|
10
|
+
*
|
|
11
|
+
* @param schema - The schema of the object.
|
|
12
|
+
* @returns A struct to check if the given value is an object.
|
|
13
|
+
*/
|
|
14
|
+
const object = (schema) =>
|
|
15
|
+
// The type is slightly different from a regular object struct, because we
|
|
16
|
+
// want to make properties with `undefined` in their type optional, but not
|
|
17
|
+
// `undefined` itself. This means that we need a type cast.
|
|
18
|
+
(0, superstruct_1.object)(schema);
|
|
19
|
+
exports.object = object;
|
|
20
|
+
/**
|
|
21
|
+
* Check the last field of a path is present.
|
|
22
|
+
*
|
|
23
|
+
* @param context - The context to check.
|
|
24
|
+
* @param context.path - The path to check.
|
|
25
|
+
* @param context.branch - The branch to check.
|
|
26
|
+
* @returns Whether the last field of a path is present.
|
|
27
|
+
*/
|
|
28
|
+
function hasOptional({ path, branch }) {
|
|
29
|
+
const field = path[path.length - 1];
|
|
30
|
+
return (0, misc_1.hasProperty)(branch[branch.length - 2], field);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A struct which allows the property of an object to be absent, or to be present
|
|
34
|
+
* as long as it's valid and not set to `undefined`.
|
|
35
|
+
*
|
|
36
|
+
* This struct should be used in conjunction with the {@link object} from this
|
|
37
|
+
* library, to get proper type inference.
|
|
38
|
+
*
|
|
39
|
+
* @param struct - The struct to check the value against, if present.
|
|
40
|
+
* @returns A struct to check if the given value is valid, or not present.
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const struct = object({
|
|
44
|
+
* foo: exactOptional(string()),
|
|
45
|
+
* bar: exactOptional(number()),
|
|
46
|
+
* baz: optional(boolean()),
|
|
47
|
+
* qux: unknown(),
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* type Type = Infer<typeof struct>;
|
|
51
|
+
* // Type is equivalent to:
|
|
52
|
+
* // {
|
|
53
|
+
* // foo?: string;
|
|
54
|
+
* // bar?: number;
|
|
55
|
+
* // baz?: boolean | undefined;
|
|
56
|
+
* // qux: unknown;
|
|
57
|
+
* // }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
function exactOptional(struct) {
|
|
61
|
+
return new superstruct_1.Struct({
|
|
62
|
+
...struct,
|
|
63
|
+
type: `optional ${struct.type}`,
|
|
64
|
+
validator: (value, context) => !hasOptional(context) || struct.validator(value, context),
|
|
65
|
+
refiner: (value, context) => !hasOptional(context) || struct.refiner(value, context),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
exports.exactOptional = exactOptional;
|
|
69
|
+
/**
|
|
70
|
+
* A struct to check if the given value is finite number. Superstruct's
|
|
71
|
+
* `number()` struct does not check if the value is finite.
|
|
72
|
+
*
|
|
73
|
+
* @returns A struct to check if the given value is finite number.
|
|
74
|
+
*/
|
|
75
|
+
const finiteNumber = () => (0, superstruct_1.define)('finite number', (value) => {
|
|
76
|
+
return (0, superstruct_1.is)(value, (0, superstruct_1.number)()) && Number.isFinite(value);
|
|
77
|
+
});
|
|
78
|
+
/**
|
|
79
|
+
* A struct to check if the given value is a valid JSON-serializable value.
|
|
80
|
+
*
|
|
81
|
+
* Note that this struct is unsafe. For safe validation, use {@link JsonStruct}.
|
|
82
|
+
*/
|
|
83
|
+
// We cannot infer the type of the struct, because it is recursive.
|
|
84
|
+
exports.UnsafeJsonStruct = (0, superstruct_1.union)([
|
|
85
|
+
(0, superstruct_1.literal)(null),
|
|
86
|
+
(0, superstruct_1.boolean)(),
|
|
87
|
+
finiteNumber(),
|
|
88
|
+
(0, superstruct_1.string)(),
|
|
89
|
+
(0, superstruct_1.array)((0, superstruct_1.lazy)(() => exports.UnsafeJsonStruct)),
|
|
90
|
+
(0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.lazy)(() => exports.UnsafeJsonStruct)),
|
|
91
|
+
]);
|
|
92
|
+
/**
|
|
93
|
+
* A struct to check if the given value is a valid JSON-serializable value.
|
|
94
|
+
*
|
|
95
|
+
* This struct sanitizes the value before validating it, so that it is safe to
|
|
96
|
+
* use with untrusted input.
|
|
97
|
+
*/
|
|
98
|
+
exports.JsonStruct = (0, superstruct_1.coerce)(exports.UnsafeJsonStruct, (0, superstruct_1.any)(), (value) => {
|
|
99
|
+
(0, assert_1.assertStruct)(value, exports.UnsafeJsonStruct);
|
|
100
|
+
return JSON.parse(JSON.stringify(value, (propKey, propValue) => {
|
|
101
|
+
// Strip __proto__ and constructor properties to prevent prototype pollution.
|
|
102
|
+
if (propKey === '__proto__' || propKey === 'constructor') {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
return propValue;
|
|
106
|
+
}));
|
|
107
|
+
});
|
|
108
|
+
/**
|
|
109
|
+
* Check if the given value is a valid {@link Json} value, i.e., a value that is
|
|
110
|
+
* serializable to JSON.
|
|
111
|
+
*
|
|
112
|
+
* @param value - The value to check.
|
|
113
|
+
* @returns Whether the value is a valid {@link Json} value.
|
|
114
|
+
*/
|
|
115
|
+
function isValidJson(value) {
|
|
116
|
+
try {
|
|
117
|
+
getSafeJson(value);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.isValidJson = isValidJson;
|
|
125
|
+
/**
|
|
126
|
+
* Validate and return sanitized JSON.
|
|
127
|
+
*
|
|
128
|
+
* Note:
|
|
129
|
+
* This function uses sanitized JsonStruct for validation
|
|
130
|
+
* that applies stringify and then parse of a value provided
|
|
131
|
+
* to ensure that there are no getters which can have side effects
|
|
132
|
+
* that can cause security issues.
|
|
133
|
+
*
|
|
134
|
+
* @param value - JSON structure to be processed.
|
|
135
|
+
* @returns Sanitized JSON structure.
|
|
136
|
+
*/
|
|
137
|
+
function getSafeJson(value) {
|
|
138
|
+
return (0, superstruct_1.create)(value, exports.JsonStruct);
|
|
139
|
+
}
|
|
140
|
+
exports.getSafeJson = getSafeJson;
|
|
141
|
+
/**
|
|
142
|
+
* Get the size of a JSON value in bytes. This also validates the value.
|
|
143
|
+
*
|
|
144
|
+
* @param value - The JSON value to get the size of.
|
|
145
|
+
* @returns The size of the JSON value in bytes.
|
|
146
|
+
*/
|
|
147
|
+
function getJsonSize(value) {
|
|
148
|
+
(0, assert_1.assertStruct)(value, exports.JsonStruct, 'Invalid JSON value');
|
|
149
|
+
const json = JSON.stringify(value);
|
|
150
|
+
return new TextEncoder().encode(json).byteLength;
|
|
151
|
+
}
|
|
152
|
+
exports.getJsonSize = getJsonSize;
|
|
153
|
+
/**
|
|
154
|
+
* The string '2.0'.
|
|
155
|
+
*/
|
|
156
|
+
exports.jsonrpc2 = '2.0';
|
|
157
|
+
exports.JsonRpcVersionStruct = (0, superstruct_1.literal)(exports.jsonrpc2);
|
|
158
|
+
exports.JsonRpcIdStruct = (0, superstruct_1.nullable)((0, superstruct_1.union)([(0, superstruct_1.number)(), (0, superstruct_1.string)()]));
|
|
159
|
+
exports.JsonRpcErrorStruct = (0, exports.object)({
|
|
160
|
+
code: (0, superstruct_1.integer)(),
|
|
161
|
+
message: (0, superstruct_1.string)(),
|
|
162
|
+
data: exactOptional(exports.JsonStruct),
|
|
163
|
+
stack: exactOptional((0, superstruct_1.string)()),
|
|
164
|
+
});
|
|
165
|
+
exports.JsonRpcParamsStruct = (0, superstruct_1.union)([(0, superstruct_1.record)((0, superstruct_1.string)(), exports.JsonStruct), (0, superstruct_1.array)(exports.JsonStruct)]);
|
|
166
|
+
exports.JsonRpcRequestStruct = (0, exports.object)({
|
|
167
|
+
id: exports.JsonRpcIdStruct,
|
|
168
|
+
jsonrpc: exports.JsonRpcVersionStruct,
|
|
169
|
+
method: (0, superstruct_1.string)(),
|
|
170
|
+
params: exactOptional(exports.JsonRpcParamsStruct),
|
|
171
|
+
});
|
|
172
|
+
exports.JsonRpcNotificationStruct = (0, exports.object)({
|
|
173
|
+
jsonrpc: exports.JsonRpcVersionStruct,
|
|
174
|
+
method: (0, superstruct_1.string)(),
|
|
175
|
+
params: exactOptional(exports.JsonRpcParamsStruct),
|
|
176
|
+
});
|
|
177
|
+
/**
|
|
178
|
+
* Check if the given value is a valid {@link JsonRpcNotification} object.
|
|
179
|
+
*
|
|
180
|
+
* @param value - The value to check.
|
|
181
|
+
* @returns Whether the given value is a valid {@link JsonRpcNotification}
|
|
182
|
+
* object.
|
|
183
|
+
*/
|
|
184
|
+
function isJsonRpcNotification(value) {
|
|
185
|
+
return (0, superstruct_1.is)(value, exports.JsonRpcNotificationStruct);
|
|
186
|
+
}
|
|
187
|
+
exports.isJsonRpcNotification = isJsonRpcNotification;
|
|
188
|
+
/**
|
|
189
|
+
* Assert that the given value is a valid {@link JsonRpcNotification} object.
|
|
190
|
+
*
|
|
191
|
+
* @param value - The value to check.
|
|
192
|
+
* @param ErrorWrapper - The error class to throw if the assertion fails.
|
|
193
|
+
* Defaults to {@link AssertionError}.
|
|
194
|
+
* @throws If the given value is not a valid {@link JsonRpcNotification} object.
|
|
195
|
+
*/
|
|
196
|
+
function assertIsJsonRpcNotification(value,
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
198
|
+
ErrorWrapper) {
|
|
199
|
+
(0, assert_1.assertStruct)(value, exports.JsonRpcNotificationStruct, 'Invalid JSON-RPC notification', ErrorWrapper);
|
|
200
|
+
}
|
|
201
|
+
exports.assertIsJsonRpcNotification = assertIsJsonRpcNotification;
|
|
202
|
+
/**
|
|
203
|
+
* Check if the given value is a valid {@link JsonRpcRequest} object.
|
|
204
|
+
*
|
|
205
|
+
* @param value - The value to check.
|
|
206
|
+
* @returns Whether the given value is a valid {@link JsonRpcRequest} object.
|
|
207
|
+
*/
|
|
208
|
+
function isJsonRpcRequest(value) {
|
|
209
|
+
return (0, superstruct_1.is)(value, exports.JsonRpcRequestStruct);
|
|
210
|
+
}
|
|
211
|
+
exports.isJsonRpcRequest = isJsonRpcRequest;
|
|
212
|
+
/**
|
|
213
|
+
* Assert that the given value is a valid {@link JsonRpcRequest} object.
|
|
214
|
+
*
|
|
215
|
+
* @param value - The JSON-RPC request or notification to check.
|
|
216
|
+
* @param ErrorWrapper - The error class to throw if the assertion fails.
|
|
217
|
+
* Defaults to {@link AssertionError}.
|
|
218
|
+
* @throws If the given value is not a valid {@link JsonRpcRequest} object.
|
|
219
|
+
*/
|
|
220
|
+
function assertIsJsonRpcRequest(value,
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
222
|
+
ErrorWrapper) {
|
|
223
|
+
(0, assert_1.assertStruct)(value, exports.JsonRpcRequestStruct, 'Invalid JSON-RPC request', ErrorWrapper);
|
|
224
|
+
}
|
|
225
|
+
exports.assertIsJsonRpcRequest = assertIsJsonRpcRequest;
|
|
226
|
+
exports.PendingJsonRpcResponseStruct = (0, superstruct_1.object)({
|
|
227
|
+
id: exports.JsonRpcIdStruct,
|
|
228
|
+
jsonrpc: exports.JsonRpcVersionStruct,
|
|
229
|
+
result: (0, superstruct_1.optional)((0, superstruct_1.unknown)()),
|
|
230
|
+
error: (0, superstruct_1.optional)(exports.JsonRpcErrorStruct),
|
|
231
|
+
});
|
|
232
|
+
exports.JsonRpcSuccessStruct = (0, exports.object)({
|
|
233
|
+
id: exports.JsonRpcIdStruct,
|
|
234
|
+
jsonrpc: exports.JsonRpcVersionStruct,
|
|
235
|
+
result: exports.JsonStruct,
|
|
236
|
+
});
|
|
237
|
+
exports.JsonRpcFailureStruct = (0, exports.object)({
|
|
238
|
+
id: exports.JsonRpcIdStruct,
|
|
239
|
+
jsonrpc: exports.JsonRpcVersionStruct,
|
|
240
|
+
error: exports.JsonRpcErrorStruct,
|
|
241
|
+
});
|
|
242
|
+
exports.JsonRpcResponseStruct = (0, superstruct_1.union)([
|
|
243
|
+
exports.JsonRpcSuccessStruct,
|
|
244
|
+
exports.JsonRpcFailureStruct,
|
|
245
|
+
]);
|
|
246
|
+
/**
|
|
247
|
+
* Type guard to check whether specified JSON-RPC response is a
|
|
248
|
+
* {@link PendingJsonRpcResponse}.
|
|
249
|
+
*
|
|
250
|
+
* @param response - The JSON-RPC response to check.
|
|
251
|
+
* @returns Whether the specified JSON-RPC response is pending.
|
|
252
|
+
*/
|
|
253
|
+
function isPendingJsonRpcResponse(response) {
|
|
254
|
+
return (0, superstruct_1.is)(response, exports.PendingJsonRpcResponseStruct);
|
|
255
|
+
}
|
|
256
|
+
exports.isPendingJsonRpcResponse = isPendingJsonRpcResponse;
|
|
257
|
+
/**
|
|
258
|
+
* Assert that the given value is a valid {@link PendingJsonRpcResponse} object.
|
|
259
|
+
*
|
|
260
|
+
* @param response - The JSON-RPC response to check.
|
|
261
|
+
* @param ErrorWrapper - The error class to throw if the assertion fails.
|
|
262
|
+
* Defaults to {@link AssertionError}.
|
|
263
|
+
* @throws If the given value is not a valid {@link PendingJsonRpcResponse}
|
|
264
|
+
* object.
|
|
265
|
+
*/
|
|
266
|
+
function assertIsPendingJsonRpcResponse(response,
|
|
267
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
268
|
+
ErrorWrapper) {
|
|
269
|
+
(0, assert_1.assertStruct)(response, exports.PendingJsonRpcResponseStruct, 'Invalid pending JSON-RPC response', ErrorWrapper);
|
|
270
|
+
}
|
|
271
|
+
exports.assertIsPendingJsonRpcResponse = assertIsPendingJsonRpcResponse;
|
|
272
|
+
/**
|
|
273
|
+
* Type guard to check if a value is a {@link JsonRpcResponse}.
|
|
274
|
+
*
|
|
275
|
+
* @param response - The object to check.
|
|
276
|
+
* @returns Whether the object is a JsonRpcResponse.
|
|
277
|
+
*/
|
|
278
|
+
function isJsonRpcResponse(response) {
|
|
279
|
+
return (0, superstruct_1.is)(response, exports.JsonRpcResponseStruct);
|
|
280
|
+
}
|
|
281
|
+
exports.isJsonRpcResponse = isJsonRpcResponse;
|
|
282
|
+
/**
|
|
283
|
+
* Assert that the given value is a valid {@link JsonRpcResponse} object.
|
|
284
|
+
*
|
|
285
|
+
* @param value - The value to check.
|
|
286
|
+
* @param ErrorWrapper - The error class to throw if the assertion fails.
|
|
287
|
+
* Defaults to {@link AssertionError}.
|
|
288
|
+
* @throws If the given value is not a valid {@link JsonRpcResponse} object.
|
|
289
|
+
*/
|
|
290
|
+
function assertIsJsonRpcResponse(value,
|
|
291
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
292
|
+
ErrorWrapper) {
|
|
293
|
+
(0, assert_1.assertStruct)(value, exports.JsonRpcResponseStruct, 'Invalid JSON-RPC response', ErrorWrapper);
|
|
294
|
+
}
|
|
295
|
+
exports.assertIsJsonRpcResponse = assertIsJsonRpcResponse;
|
|
296
|
+
/**
|
|
297
|
+
* Check if the given value is a valid {@link JsonRpcSuccess} object.
|
|
298
|
+
*
|
|
299
|
+
* @param value - The value to check.
|
|
300
|
+
* @returns Whether the given value is a valid {@link JsonRpcSuccess} object.
|
|
301
|
+
*/
|
|
302
|
+
function isJsonRpcSuccess(value) {
|
|
303
|
+
return (0, superstruct_1.is)(value, exports.JsonRpcSuccessStruct);
|
|
304
|
+
}
|
|
305
|
+
exports.isJsonRpcSuccess = isJsonRpcSuccess;
|
|
306
|
+
/**
|
|
307
|
+
* Assert that the given value is a valid {@link JsonRpcSuccess} object.
|
|
308
|
+
*
|
|
309
|
+
* @param value - The value to check.
|
|
310
|
+
* @param ErrorWrapper - The error class to throw if the assertion fails.
|
|
311
|
+
* Defaults to {@link AssertionError}.
|
|
312
|
+
* @throws If the given value is not a valid {@link JsonRpcSuccess} object.
|
|
313
|
+
*/
|
|
314
|
+
function assertIsJsonRpcSuccess(value,
|
|
315
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
316
|
+
ErrorWrapper) {
|
|
317
|
+
(0, assert_1.assertStruct)(value, exports.JsonRpcSuccessStruct, 'Invalid JSON-RPC success response', ErrorWrapper);
|
|
318
|
+
}
|
|
319
|
+
exports.assertIsJsonRpcSuccess = assertIsJsonRpcSuccess;
|
|
320
|
+
/**
|
|
321
|
+
* Check if the given value is a valid {@link JsonRpcFailure} object.
|
|
322
|
+
*
|
|
323
|
+
* @param value - The value to check.
|
|
324
|
+
* @returns Whether the given value is a valid {@link JsonRpcFailure} object.
|
|
325
|
+
*/
|
|
326
|
+
function isJsonRpcFailure(value) {
|
|
327
|
+
return (0, superstruct_1.is)(value, exports.JsonRpcFailureStruct);
|
|
328
|
+
}
|
|
329
|
+
exports.isJsonRpcFailure = isJsonRpcFailure;
|
|
330
|
+
/**
|
|
331
|
+
* Assert that the given value is a valid {@link JsonRpcFailure} object.
|
|
332
|
+
*
|
|
333
|
+
* @param value - The value to check.
|
|
334
|
+
* @param ErrorWrapper - The error class to throw if the assertion fails.
|
|
335
|
+
* Defaults to {@link AssertionError}.
|
|
336
|
+
* @throws If the given value is not a valid {@link JsonRpcFailure} object.
|
|
337
|
+
*/
|
|
338
|
+
function assertIsJsonRpcFailure(value,
|
|
339
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
340
|
+
ErrorWrapper) {
|
|
341
|
+
(0, assert_1.assertStruct)(value, exports.JsonRpcFailureStruct, 'Invalid JSON-RPC failure response', ErrorWrapper);
|
|
342
|
+
}
|
|
343
|
+
exports.assertIsJsonRpcFailure = assertIsJsonRpcFailure;
|
|
344
|
+
/**
|
|
345
|
+
* Check if the given value is a valid {@link JsonRpcError} object.
|
|
346
|
+
*
|
|
347
|
+
* @param value - The value to check.
|
|
348
|
+
* @returns Whether the given value is a valid {@link JsonRpcError} object.
|
|
349
|
+
*/
|
|
350
|
+
function isJsonRpcError(value) {
|
|
351
|
+
return (0, superstruct_1.is)(value, exports.JsonRpcErrorStruct);
|
|
352
|
+
}
|
|
353
|
+
exports.isJsonRpcError = isJsonRpcError;
|
|
354
|
+
/**
|
|
355
|
+
* Assert that the given value is a valid {@link JsonRpcError} object.
|
|
356
|
+
*
|
|
357
|
+
* @param value - The value to check.
|
|
358
|
+
* @param ErrorWrapper - The error class to throw if the assertion fails.
|
|
359
|
+
* Defaults to {@link AssertionError}.
|
|
360
|
+
* @throws If the given value is not a valid {@link JsonRpcError} object.
|
|
361
|
+
*/
|
|
362
|
+
function assertIsJsonRpcError(value,
|
|
363
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
364
|
+
ErrorWrapper) {
|
|
365
|
+
(0, assert_1.assertStruct)(value, exports.JsonRpcErrorStruct, 'Invalid JSON-RPC error', ErrorWrapper);
|
|
366
|
+
}
|
|
367
|
+
exports.assertIsJsonRpcError = assertIsJsonRpcError;
|
|
368
|
+
/**
|
|
369
|
+
* Gets a function for validating JSON-RPC request / response `id` values.
|
|
370
|
+
*
|
|
371
|
+
* By manipulating the options of this factory, you can control the behavior
|
|
372
|
+
* of the resulting validator for some edge cases. This is useful because e.g.
|
|
373
|
+
* `null` should sometimes but not always be permitted.
|
|
374
|
+
*
|
|
375
|
+
* Note that the empty string (`''`) is always permitted by the JSON-RPC
|
|
376
|
+
* specification, but that kind of sucks and you may want to forbid it in some
|
|
377
|
+
* instances anyway.
|
|
378
|
+
*
|
|
379
|
+
* For more details, see the
|
|
380
|
+
* [JSON-RPC Specification](https://www.jsonrpc.org/specification).
|
|
381
|
+
*
|
|
382
|
+
* @param options - An options object.
|
|
383
|
+
* @param options.permitEmptyString - Whether the empty string (i.e. `''`)
|
|
384
|
+
* should be treated as a valid ID. Default: `true`
|
|
385
|
+
* @param options.permitFractions - Whether fractional numbers (e.g. `1.2`)
|
|
386
|
+
* should be treated as valid IDs. Default: `false`
|
|
387
|
+
* @param options.permitNull - Whether `null` should be treated as a valid ID.
|
|
388
|
+
* Default: `true`
|
|
389
|
+
* @returns The JSON-RPC ID validator function.
|
|
390
|
+
*/
|
|
391
|
+
function getJsonRpcIdValidator(options) {
|
|
392
|
+
const { permitEmptyString, permitFractions, permitNull } = {
|
|
393
|
+
permitEmptyString: true,
|
|
394
|
+
permitFractions: false,
|
|
395
|
+
permitNull: true,
|
|
396
|
+
...options,
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Type guard for {@link JsonRpcId}.
|
|
400
|
+
*
|
|
401
|
+
* @param id - The JSON-RPC ID value to check.
|
|
402
|
+
* @returns Whether the given ID is valid per the options given to the
|
|
403
|
+
* factory.
|
|
404
|
+
*/
|
|
405
|
+
const isValidJsonRpcId = (id) => {
|
|
406
|
+
return Boolean((typeof id === 'number' && (permitFractions || Number.isInteger(id))) ||
|
|
407
|
+
(typeof id === 'string' && (permitEmptyString || id.length > 0)) ||
|
|
408
|
+
(permitNull && id === null));
|
|
409
|
+
};
|
|
410
|
+
return isValidJsonRpcId;
|
|
411
|
+
}
|
|
412
|
+
exports.getJsonRpcIdValidator = getJsonRpcIdValidator;
|
|
413
|
+
//# sourceMappingURL=json.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.cjs","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":";;;AAAA,uDAoB+B;AAU/B,yCAAwC;AACxC,qCAAqC;AAgDrC;;;;;;GAMG;AACI,MAAM,MAAM,GAAG,CACpB,MAAc,EACc,EAAE;AAC9B,0EAA0E;AAC1E,2EAA2E;AAC3E,2DAA2D;AAC3D,IAAA,oBAAiB,EAAC,MAAM,CAA0C,CAAC;AANxD,QAAA,MAAM,UAMkD;AAOrE;;;;;;;GAOG;AACH,SAAS,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,EAAW;IAC5C,MA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;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAClC,KAAc;AACd,gEAAgE;AAChE,YAAwC;IAExC,IAAA,qBAAY,EACV,KAAK,EACL,0BAAkB,EAClB,wBAAwB,EACxB,YAAY,CACb,CAAC;AACJ,CAAC;AAXD,oDAWC;AAQD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,qBAAqB,CAAC,OAAiC;IACrE,MAAM,EAAE,iBAAiB,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG;QACzD,iBAAiB,EAAE,IAAI;QACvB,eAAe,EAAE,KAAK;QACtB,UAAU,EAAE,IAAI;QAChB,GAAG,OAAO;KACX,CAAC;IAEF;;;;;;OAMG;IACH,MAAM,gBAAgB,GAAG,CAAC,EAAW,EAAmB,EAAE;QACxD,OAAO,OAAO,CACZ,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,eAAe,IAAI,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;YACnE,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,iBAAiB,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAChE,CAAC,UAAU,IAAI,EAAE,KAAK,IAAI,CAAC,CAC9B,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAxBD,sDAwBC","sourcesContent":["import {\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 '@metamask/superstruct';\nimport type {\n Context,\n Infer,\n ObjectSchema,\n Simplify,\n Optionalize,\n} from '@metamask/superstruct';\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"]}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import type { AssertionErrorConstructor } from './assert';
|
|
1
|
+
import { Struct } from "@metamask/superstruct";
|
|
2
|
+
import type { Infer, ObjectSchema, Simplify, Optionalize } from "@metamask/superstruct";
|
|
3
|
+
import type { AssertionErrorConstructor } from "./assert.cjs";
|
|
5
4
|
/**
|
|
6
5
|
* Any JSON-compatible value.
|
|
7
6
|
*/
|
|
8
|
-
export
|
|
7
|
+
export type Json = null | boolean | number | string | Json[] | {
|
|
9
8
|
[prop: string]: Json;
|
|
10
9
|
};
|
|
11
10
|
/**
|
|
@@ -18,7 +17,7 @@ export declare type Json = null | boolean | number | string | Json[] | {
|
|
|
18
17
|
* // Foo is equivalent to { foo?: string }
|
|
19
18
|
* ```
|
|
20
19
|
*/
|
|
21
|
-
export
|
|
20
|
+
export type ObjectOptional<Schema extends Record<string, unknown>> = {
|
|
22
21
|
[Key in keyof Schema as Schema[Key] extends ExactOptionalGuard ? Key : never]?: Schema[Key] extends ExactOptionalGuard & infer Original ? Original : never;
|
|
23
22
|
} & {
|
|
24
23
|
[Key in keyof Schema as Schema[Key] extends ExactOptionalGuard ? never : Key]: Schema[Key];
|
|
@@ -28,7 +27,7 @@ export declare type ObjectOptional<Schema extends Record<string, unknown>> = {
|
|
|
28
27
|
* struct. This uses the {@link ObjectOptional} helper to make properties with
|
|
29
28
|
* `undefined` in their type optional, but not `undefined` itself.
|
|
30
29
|
*/
|
|
31
|
-
export
|
|
30
|
+
export type ObjectType<Schema extends ObjectSchema> = Simplify<ObjectOptional<Optionalize<{
|
|
32
31
|
[Key in keyof Schema]: Infer<Schema[Key]>;
|
|
33
32
|
}>>>;
|
|
34
33
|
/**
|
|
@@ -40,7 +39,7 @@ export declare type ObjectType<Schema extends ObjectSchema> = Simplify<ObjectOpt
|
|
|
40
39
|
*/
|
|
41
40
|
export declare const object: <Schema extends ObjectSchema>(schema: Schema) => Struct<Simplify<ObjectOptional<Optionalize<{ [Key in keyof Schema]: Infer<Schema[Key]>; }>>>, unknown>;
|
|
42
41
|
declare const exactOptionalSymbol: unique symbol;
|
|
43
|
-
|
|
42
|
+
type ExactOptionalGuard = {
|
|
44
43
|
_exactOptionalGuard?: typeof exactOptionalSymbol;
|
|
45
44
|
};
|
|
46
45
|
/**
|
|
@@ -122,7 +121,7 @@ export declare const JsonRpcVersionStruct: Struct<"2.0", "2.0">;
|
|
|
122
121
|
* A String specifying the version of the JSON-RPC protocol.
|
|
123
122
|
* MUST be exactly "2.0".
|
|
124
123
|
*/
|
|
125
|
-
export
|
|
124
|
+
export type JsonRpcVersion2 = typeof jsonrpc2;
|
|
126
125
|
export declare const JsonRpcIdStruct: Struct<string | number | null, null>;
|
|
127
126
|
/**
|
|
128
127
|
* An identifier established by the Client that MUST contain a String, Number,
|
|
@@ -130,7 +129,7 @@ export declare const JsonRpcIdStruct: Struct<string | number | null, null>;
|
|
|
130
129
|
* notification. The value SHOULD normally not be Null and Numbers SHOULD
|
|
131
130
|
* NOT contain fractional parts.
|
|
132
131
|
*/
|
|
133
|
-
export
|
|
132
|
+
export type JsonRpcId = Infer<typeof JsonRpcIdStruct>;
|
|
134
133
|
export declare const JsonRpcErrorStruct: Struct<{
|
|
135
134
|
data?: Json & ExactOptionalGuard;
|
|
136
135
|
stack?: string;
|
|
@@ -140,7 +139,7 @@ export declare const JsonRpcErrorStruct: Struct<{
|
|
|
140
139
|
/**
|
|
141
140
|
* Mark a certain key of a type as optional.
|
|
142
141
|
*/
|
|
143
|
-
export
|
|
142
|
+
export type OptionalField<Type extends Record<string, unknown>, Key extends keyof Type> = Omit<Type, Key> & Partial<Pick<Type, Key>>;
|
|
144
143
|
/**
|
|
145
144
|
* A JSON-RPC error object.
|
|
146
145
|
*
|
|
@@ -148,22 +147,22 @@ export declare type OptionalField<Type extends Record<string, unknown>, Key exte
|
|
|
148
147
|
* the `data` field is not optional. To make it optional, we use the
|
|
149
148
|
* `OptionalField` helper, to explicitly make it optional.
|
|
150
149
|
*/
|
|
151
|
-
export
|
|
150
|
+
export type JsonRpcError = OptionalField<Infer<typeof JsonRpcErrorStruct>, 'data'>;
|
|
152
151
|
export declare const JsonRpcParamsStruct: Struct<Json[] | Record<string, Json>, null>;
|
|
153
|
-
export
|
|
152
|
+
export type JsonRpcParams = Json[] | Record<string, Json>;
|
|
154
153
|
export declare const JsonRpcRequestStruct: Struct<{
|
|
155
154
|
params?: (Json[] | Record<string, Json>) & ExactOptionalGuard;
|
|
156
155
|
id: string | number | null;
|
|
157
156
|
method: string;
|
|
158
157
|
jsonrpc: "2.0";
|
|
159
158
|
}, unknown>;
|
|
160
|
-
export
|
|
159
|
+
export type InferWithParams<Type extends Struct<any>, Params extends JsonRpcParams> = Infer<Type> & {
|
|
161
160
|
params?: Params;
|
|
162
161
|
};
|
|
163
162
|
/**
|
|
164
163
|
* A JSON-RPC request object.
|
|
165
164
|
*/
|
|
166
|
-
export
|
|
165
|
+
export type JsonRpcRequest<Params extends JsonRpcParams = JsonRpcParams> = InferWithParams<typeof JsonRpcRequestStruct, Params>;
|
|
167
166
|
export declare const JsonRpcNotificationStruct: Struct<{
|
|
168
167
|
params?: (Json[] | Record<string, Json>) & ExactOptionalGuard;
|
|
169
168
|
method: string;
|
|
@@ -172,7 +171,7 @@ export declare const JsonRpcNotificationStruct: Struct<{
|
|
|
172
171
|
/**
|
|
173
172
|
* A JSON-RPC notification object.
|
|
174
173
|
*/
|
|
175
|
-
export
|
|
174
|
+
export type JsonRpcNotification<Params extends JsonRpcParams = JsonRpcParams> = InferWithParams<typeof JsonRpcNotificationStruct, Params>;
|
|
176
175
|
/**
|
|
177
176
|
* Check if the given value is a valid {@link JsonRpcNotification} object.
|
|
178
177
|
*
|
|
@@ -230,7 +229,7 @@ export declare const PendingJsonRpcResponseStruct: Struct<{
|
|
|
230
229
|
/**
|
|
231
230
|
* A JSON-RPC response object that has not yet been resolved.
|
|
232
231
|
*/
|
|
233
|
-
export
|
|
232
|
+
export type PendingJsonRpcResponse<Result extends Json> = Omit<Infer<typeof PendingJsonRpcResponseStruct>, 'result'> & {
|
|
234
233
|
result?: Result;
|
|
235
234
|
};
|
|
236
235
|
export declare const JsonRpcSuccessStruct: Struct<{
|
|
@@ -241,7 +240,7 @@ export declare const JsonRpcSuccessStruct: Struct<{
|
|
|
241
240
|
/**
|
|
242
241
|
* A successful JSON-RPC response object.
|
|
243
242
|
*/
|
|
244
|
-
export
|
|
243
|
+
export type JsonRpcSuccess<Result extends Json> = Omit<Infer<typeof JsonRpcSuccessStruct>, 'result'> & {
|
|
245
244
|
result: Result;
|
|
246
245
|
};
|
|
247
246
|
export declare const JsonRpcFailureStruct: Struct<{
|
|
@@ -252,7 +251,7 @@ export declare const JsonRpcFailureStruct: Struct<{
|
|
|
252
251
|
/**
|
|
253
252
|
* A failed JSON-RPC response object.
|
|
254
253
|
*/
|
|
255
|
-
export
|
|
254
|
+
export type JsonRpcFailure = Infer<typeof JsonRpcFailureStruct>;
|
|
256
255
|
export declare const JsonRpcResponseStruct: Struct<{
|
|
257
256
|
id: string | number | null;
|
|
258
257
|
jsonrpc: "2.0";
|
|
@@ -268,7 +267,7 @@ export declare const JsonRpcResponseStruct: Struct<{
|
|
|
268
267
|
*
|
|
269
268
|
* @template Result - The type of the result.
|
|
270
269
|
*/
|
|
271
|
-
export
|
|
270
|
+
export type JsonRpcResponse<Result extends Json> = JsonRpcSuccess<Result> | JsonRpcFailure;
|
|
272
271
|
/**
|
|
273
272
|
* Type guard to check whether specified JSON-RPC response is a
|
|
274
273
|
* {@link PendingJsonRpcResponse}.
|
|
@@ -351,7 +350,7 @@ export declare function isJsonRpcError(value: unknown): value is JsonRpcError;
|
|
|
351
350
|
* @throws If the given value is not a valid {@link JsonRpcError} object.
|
|
352
351
|
*/
|
|
353
352
|
export declare function assertIsJsonRpcError(value: unknown, ErrorWrapper?: AssertionErrorConstructor): asserts value is JsonRpcError;
|
|
354
|
-
|
|
353
|
+
type JsonRpcValidatorOptions = {
|
|
355
354
|
permitEmptyString?: boolean;
|
|
356
355
|
permitFractions?: boolean;
|
|
357
356
|
permitNull?: boolean;
|
|
@@ -381,4 +380,4 @@ declare type JsonRpcValidatorOptions = {
|
|
|
381
380
|
*/
|
|
382
381
|
export declare function getJsonRpcIdValidator(options?: JsonRpcValidatorOptions): (id: unknown) => id is string | number | null;
|
|
383
382
|
export {};
|
|
384
|
-
//# sourceMappingURL=json.d.
|
|
383
|
+
//# sourceMappingURL=json.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.cts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAmBL,MAAM,EACP,8BAA8B;AAC/B,OAAO,KAAK,EAEV,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,WAAW,EACZ,8BAA8B;AAE/B,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAiB;AAI1D;;GAEG;AACH,MAAM,MAAM,IAAI,GACZ,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,IAAI,EAAE,GACN;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAE7B;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KAClE,GAAG,IAAI,MAAM,MAAM,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,kBAAkB,GAC1D,GAAG,GACH,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,kBAAkB,GAAG,MAAM,QAAQ,GAChE,QAAQ,GACR,KAAK;CACV,GAAG;KACD,GAAG,IAAI,MAAM,MAAM,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,kBAAkB,GAC1D,KAAK,GACL,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;CACtB,CAAC;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