From ea528833dd476ddc3de60125d9a44f10b2dd6860 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Thu, 31 Aug 2023 10:43:19 +0000 Subject: [PATCH] patch @metamask/utils 4bc04f1e61d2589e139fc2dd1b5dfba14dc1324b --- ...@metamask-utils-npm-8.0.0-7a3c3a899a.patch | 392 ++++++++++++++++++ package.json | 3 + yarn.lock | 16 +- 3 files changed, 410 insertions(+), 1 deletion(-) create mode 100644 .yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch diff --git a/.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch b/.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch new file mode 100644 index 0000000..3a48412 --- /dev/null +++ b/.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch @@ -0,0 +1,392 @@ +diff --git a/dist/cjs/json.js b/dist/cjs/json.js +index 17e5663cd237a88fcdb3728a16b5b1219113babe..b4887029d6f7b56e73c54abb40c972d89cf2ce3f 100644 +--- a/dist/cjs/json.js ++++ b/dist/cjs/json.js +@@ -9,6 +9,12 @@ function _export(target, all) { + }); + } + _export(exports, { ++ jsonObject: function() { ++ return jsonObject; ++ }, ++ jsonOptional: function() { ++ return jsonOptional; ++ }, + UnsafeJsonStruct: function() { + return UnsafeJsonStruct; + }, +@@ -105,6 +111,22 @@ _export(exports, { + }); + const _superstruct = require("superstruct"); + const _assert = require("./assert"); ++const _misc = require("./misc"); ++const jsonObject = (schema)=>// The type is slightly different from a regular object struct, because we ++ // want to make properties with `undefined` in their type optional, but not ++ // `undefined` itself. This means that we need a type cast. ++ (0, _superstruct.object)(schema); ++const jsonOptional = (struct)=>(0, _superstruct.define)('optional', (value, context)=>{ ++ const parent = context.branch[context.branch.length - 2]; ++ const key = context.path[context.path.length - 1]; ++ if (!(0, _misc.hasProperty)(parent, key)) { ++ return true; ++ } ++ if (value === undefined) { ++ return 'Expected a value, but received: undefined.'; ++ } ++ return struct.validator(value, context); ++ }); + /** + * A struct to check if the given value is finite number. Superstruct's + * `number()` struct does not check if the value is finite. +@@ -153,25 +175,27 @@ const JsonRpcIdStruct = (0, _superstruct.nullable)((0, _superstruct.union)([ + (0, _superstruct.number)(), + (0, _superstruct.string)() + ])); +-const JsonRpcErrorStruct = (0, _superstruct.object)({ ++const JsonRpcErrorStruct = jsonObject({ + code: (0, _superstruct.integer)(), + message: (0, _superstruct.string)(), +- data: (0, _superstruct.optional)(JsonStruct), +- stack: (0, _superstruct.optional)((0, _superstruct.string)()) ++ data: jsonOptional(JsonStruct), ++ stack: jsonOptional((0, _superstruct.string)()) + }); +-const JsonRpcParamsStruct = (0, _superstruct.optional)((0, _superstruct.union)([ ++const JsonRpcParamsStruct = (0, _superstruct.union)([ + (0, _superstruct.record)((0, _superstruct.string)(), JsonStruct), + (0, _superstruct.array)(JsonStruct) +-])); +-const JsonRpcRequestStruct = (0, _superstruct.object)({ ++]); ++const JsonRpcRequestStruct = jsonObject({ + id: JsonRpcIdStruct, + jsonrpc: JsonRpcVersionStruct, + method: (0, _superstruct.string)(), +- params: JsonRpcParamsStruct ++ params: jsonOptional(JsonRpcParamsStruct) ++}); ++const JsonRpcNotificationStruct = jsonObject({ ++ jsonrpc: JsonRpcVersionStruct, ++ method: (0, _superstruct.string)(), ++ params: jsonOptional(JsonRpcParamsStruct) + }); +-const JsonRpcNotificationStruct = (0, _superstruct.omit)(JsonRpcRequestStruct, [ +- 'id' +-]); + function isJsonRpcNotification(value) { + return (0, _superstruct.is)(value, JsonRpcNotificationStruct); + } +@@ -192,12 +216,12 @@ const PendingJsonRpcResponseStruct = (0, _superstruct.object)({ + result: (0, _superstruct.optional)((0, _superstruct.unknown)()), + error: (0, _superstruct.optional)(JsonRpcErrorStruct) + }); +-const JsonRpcSuccessStruct = (0, _superstruct.object)({ ++const JsonRpcSuccessStruct = jsonObject({ + id: JsonRpcIdStruct, + jsonrpc: JsonRpcVersionStruct, + result: JsonStruct + }); +-const JsonRpcFailureStruct = (0, _superstruct.object)({ ++const JsonRpcFailureStruct = jsonObject({ + id: JsonRpcIdStruct, + jsonrpc: JsonRpcVersionStruct, + error: JsonRpcErrorStruct +diff --git a/dist/cjs/json.js.map b/dist/cjs/json.js.map +index 26bea6e257cc0f2d36ca93f5652254ed85d8720f..189ef8e19cd91b974c4e7d5e00b09308f47644e3 100644 +--- a/dist/cjs/json.js.map ++++ b/dist/cjs/json.js.map +@@ -1 +1 @@ +-{"version":3,"sources":["../../src/json.ts"],"sourcesContent":["import type { Infer, Struct } 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,\n omit,\n optional,\n record,\n string,\n union,\n unknown,\n} from 'superstruct';\n\nimport type { AssertionErrorConstructor } from './assert';\nimport { assertStruct } from './assert';\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 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('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 = 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(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;\n\nexport const JsonRpcErrorStruct = object({\n code: integer(),\n message: string(),\n data: optional(JsonStruct),\n stack: optional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record,\n Key extends keyof Type,\n> = Omit & Partial>;\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,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct: Struct, null> =\n optional(union([record(string(), JsonStruct), array(JsonStruct)])) as any;\n\nexport type JsonRpcParams = Json[] | Record;\n\nexport const JsonRpcRequestStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: JsonRpcParamsStruct,\n});\n\nexport type InferWithParams<\n Type extends Struct,\n Params extends JsonRpcParams,\n> = Omit, 'params'> &\n (keyof Params extends undefined\n ? {\n params?: Params;\n }\n : {\n params: Params;\n });\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest =\n InferWithParams;\n\nexport const JsonRpcNotificationStruct = omit(JsonRpcRequestStruct, ['id']);\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification =\n InferWithParams;\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 = object({\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 = Omit<\n Infer,\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 = Omit<\n Infer,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n error: JsonRpcErrorStruct as Struct,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer;\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 =\n | JsonRpcSuccess\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 {\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 {\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 {\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 {\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 {\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 {\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"],"names":["UnsafeJsonStruct","JsonStruct","isValidJson","getSafeJson","getJsonSize","jsonrpc2","JsonRpcVersionStruct","JsonRpcIdStruct","JsonRpcErrorStruct","JsonRpcParamsStruct","JsonRpcRequestStruct","JsonRpcNotificationStruct","isJsonRpcNotification","assertIsJsonRpcNotification","isJsonRpcRequest","assertIsJsonRpcRequest","PendingJsonRpcResponseStruct","JsonRpcSuccessStruct","JsonRpcFailureStruct","JsonRpcResponseStruct","isPendingJsonRpcResponse","assertIsPendingJsonRpcResponse","isJsonRpcResponse","assertIsJsonRpcResponse","isJsonRpcSuccess","assertIsJsonRpcSuccess","isJsonRpcFailure","assertIsJsonRpcFailure","isJsonRpcError","assertIsJsonRpcError","getJsonRpcIdValidator","finiteNumber","define","value","is","number","Number","isFinite","union","literal","boolean","string","array","lazy","record","coerce","any","assertStruct","JSON","parse","stringify","propKey","propValue","undefined","create","json","TextEncoder","encode","byteLength","nullable","object","code","integer","message","data","optional","stack","id","jsonrpc","method","params","omit","ErrorWrapper","result","unknown","error","response","options","permitEmptyString","permitFractions","permitNull","isValidJsonRpcId","Boolean","isInteger","length"],"mappings":";;;;;;;;;;;IAsDaA,gBAAgB;eAAhBA;;IAkBAC,UAAU;eAAVA;;IAoBGC,WAAW;eAAXA;;IAqBAC,WAAW;eAAXA;;IAUAC,WAAW;eAAXA;;IAUHC,QAAQ;eAARA;;IACAC,oBAAoB;eAApBA;;IAQAC,eAAe;eAAfA;;IAUAC,kBAAkB;eAAlBA;;IA2BAC,mBAAmB;eAAnBA;;IAKAC,oBAAoB;eAApBA;;IAyBAC,yBAAyB;eAAzBA;;IAeGC,qBAAqB;eAArBA;;IAcAC,2BAA2B;eAA3BA;;IAmBAC,gBAAgB;eAAhBA;;IAYAC,sBAAsB;eAAtBA;;IAaHC,4BAA4B;eAA5BA;;IAiBAC,oBAAoB;eAApBA;;IAgBAC,oBAAoB;eAApBA;;IAWAC,qBAAqB;eAArBA;;IAsBGC,wBAAwB;eAAxBA;;IAeAC,8BAA8B;eAA9BA;;IAmBAC,iBAAiB;eAAjBA;;IAcAC,uBAAuB;eAAvBA;;IAmBAC,gBAAgB;eAAhBA;;IAcAC,sBAAsB;eAAtBA;;IAmBAC,gBAAgB;eAAhBA;;IAYAC,sBAAsB;eAAtBA;;IAmBAC,cAAc;eAAdA;;IAYAC,oBA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e,EAAEC,UAAU,EAAE,GAAG;QACzDF,mBAAmB;QACnBC,iBAAiB;QACjBC,YAAY;QACZ,GAAGH,OAAO;IACZ;IAEA;;;;;;GAMC,GACD,MAAMI,mBAAmB,CAACd;QACxB,OAAOe,QACL,AAAC,OAAOf,OAAO,YAAaY,CAAAA,mBAAmB3C,OAAO+C,SAAS,CAAChB,GAAE,KAC/D,OAAOA,OAAO,YAAaW,CAAAA,qBAAqBX,GAAGiB,MAAM,GAAG,CAAA,KAC5DJ,cAAcb,OAAO;IAE5B;IAEA,OAAOc;AACT"} +\ No newline at end of file ++{"version":3,"sources":["../../src/json.ts"],"sourcesContent":["import type { Infer, Struct } 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 object,\n optional,\n record,\n string,\n union,\n unknown,\n} from 'superstruct';\nimport type {\n ObjectSchema,\n OmitBy,\n PickBy,\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 = JsonOptional<{ foo: string | undefined }>;\n * // Foo is equivalent to { foo?: string }\n * ```\n */\nexport type JsonOptional> = {\n [Key in keyof PickBy]?: Exclude;\n} & {\n [Key in keyof OmitBy]: Schema[Key];\n};\n\n/**\n * A JSON object type. This is used by the `json` struct. This uses the\n * {@link JsonOptional} helper to make properties with `undefined` in their type\n * optional, but not `undefined` itself.\n */\nexport type JsonObjectType = Simplify<\n JsonOptional<{\n [Key in keyof Schema]: Infer;\n }>\n>;\n\n/**\n * A struct to check if the given value is a valid JSON object.\n *\n * @param schema - The schema of the JSON object.\n * @returns A struct to check if the given value is a valid JSON object.\n */\nexport const jsonObject = (\n schema: Schema,\n): Struct> =>\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>;\n\n/**\n * A struct to check if the given value is a valid JSON object, or not present.\n * This means that it allows an object which does not have the property, or an\n * object which has the property and is valid, but not an object which has the\n * property set to `undefined`.\n *\n * @param struct - The struct to check the value against, if present.\n * @returns A struct to check if the given value is a valid JSON object, or not\n * present.\n */\nexport const jsonOptional = (\n struct: Struct,\n): Struct =>\n define('optional', (value, context) => {\n const parent = context.branch[context.branch.length - 2];\n const key = context.path[context.path.length - 1];\n\n if (!hasProperty(parent, key)) {\n return true;\n }\n\n if (value === undefined) {\n return 'Expected a value, but received: undefined.';\n }\n\n return struct.validator(value, context);\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('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 = 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(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;\n\nexport const JsonRpcErrorStruct = jsonObject({\n code: integer(),\n message: string(),\n data: jsonOptional(JsonStruct),\n stack: jsonOptional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record,\n Key extends keyof Type,\n> = Omit & Partial>;\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,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct: Struct, null> =\n union([record(string(), JsonStruct), array(JsonStruct)]);\n\nexport type JsonRpcParams = Json[] | Record;\n\nexport const JsonRpcRequestStruct = jsonObject({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: jsonOptional(JsonRpcParamsStruct),\n});\n\nexport type InferWithParams<\n Type extends Struct,\n Params extends JsonRpcParams,\n> = Infer & {\n params?: Params;\n};\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest =\n InferWithParams;\n\nexport const JsonRpcNotificationStruct = jsonObject({\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: jsonOptional(JsonRpcParamsStruct),\n});\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification =\n InferWithParams;\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 = object({\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 = Omit<\n Infer,\n 'result'\n> & {\n result?: Result;\n};\n\nexport const JsonRpcSuccessStruct = jsonObject({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: JsonStruct,\n});\n\n/**\n * A successful JSON-RPC response object.\n */\nexport type JsonRpcSuccess = Omit<\n Infer,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = jsonObject({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n error: JsonRpcErrorStruct as Struct,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer;\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 =\n | JsonRpcSuccess\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 {\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 {\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 {\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 {\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 {\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 {\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"],"names":["jsonObject","jsonOptional","UnsafeJsonStruct","JsonStruct","isValidJson","getSafeJson","getJsonSize","jsonrpc2","JsonRpcVersionStruct","JsonRpcIdStruct","JsonRpcErrorStruct","JsonRpcParamsStruct","JsonRpcRequestStruct","JsonRpcNotificationStruct","isJsonRpcNotification","assertIsJsonRpcNotification","isJsonRpcRequest","assertIsJsonRpcRequest","PendingJsonRpcResponseStruct","JsonRpcSuccessStruct","JsonRpcFailureStruct","JsonRpcResponseStruct","isPendingJsonRpcResponse","assertIsPendingJsonRpcResponse","isJsonRpcResponse","assertIsJsonRpcResponse","isJsonRpcSuccess","assertIsJsonRpcSuccess","isJsonRpcFailure","assertIsJsonRpcFailure","isJsonRpcError","assertIsJsonRpcError","getJsonRpcIdValidator","schema","superstructObject","struct","define","value","context","parent","branch","length","key","path","hasProperty","undefined","validator","finiteNumber","is","number","Number","isFinite","union","literal","boolean","string","array","lazy","record","coerce","any","assertStruct","JSON","parse","stringify","propKey","propValue","create","json","TextEncoder","encode","byteLength","nullable","code","integer","message","data","stack","id","jsonrpc","method","params","ErrorWrapper","object","result","optional","unknown","error","response","options","permitEmptyString","permitFractions","permitNull","isValidJsonRpcId","Boolean","isInteger"],"mappings":";;;;;;;;;;;IA6EaA,UAAU;eAAVA;;IAkBAC,YAAY;eAAZA;;IAmCAC,gBAAgB;eAAhBA;;IAkBAC,UAAU;eAAVA;;IAoBGC,WAAW;eAAXA;;IAqBAC,WAAW;eAAXA;;IAUAC,WAAW;eAAXA;;IAUHC,QAAQ;eAARA;;IACAC,oBAAoB;eAApBA;;IAQAC,eAAe;eAAfA;;IAUAC,kBAAkB;eAAlBA;;IA2BAC,mBAAmB;eAAnBA;;IAKAC,oBAAoB;eAApBA;;IAoBAC,yBAAyB;eAAzBA;;IAmBGC,qBAAqB;eAArBA;;IAcAC,2BAA2B;eAA3BA;;IAmBAC,gBAAgB;eAAhBA;;IAYAC,sBAAsB;eAAtBA;;IAaHC,4BAA4B;eAA5BA;;IAiBAC,oBAAoB;eAApBA;;IAgBAC,oBAAoB;eAApBA;;IAWAC,qBAAqB;eAArBA;;IAsBGC,wBAAwB;eAAxBA;;IAeAC,8BAA8B;eAA9BA;;IAmBAC,iBAAiB;eAAjBA;;IAcAC,uBAAuB;eAAvBA;;IAmBAC,gBAAgB;eAAhBA;;IAcAC,sBAAsB;eAAtBA;;IAmBAC,gBAAgB;eAAhBA;;IAYAC,sBAAsB;e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oBAAY,EACVxB,OACAlB,sBACA,qCACA+D;AAEJ;AAQO,SAAStD,iBAAiBS,KAAc;IAC7C,OAAOW,IAAAA,eAAE,EAACX,OAAOjB;AACnB;AAUO,SAASS,uBACdQ,KAAc,EACd,gEAAgE;AAChE6C,YAAwC;IAExCrB,IAAAA,oBAAY,EACVxB,OACAjB,sBACA,qCACA8D;AAEJ;AAQO,SAASpD,eAAeO,KAAc;IAC3C,OAAOW,IAAAA,eAAE,EAACX,OAAO3B;AACnB;AAUO,SAASqB,qBACdM,KAAc,EACd,gEAAgE;AAChE6C,YAAwC;IAExCrB,IAAAA,oBAAY,EACVxB,OACA3B,oBACA,0BACAwE;AAEJ;AA+BO,SAASlD,sBAAsByD,OAAiC;IACrE,MAAM,EAAEC,iBAAiB,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAG;QACzDF,mBAAmB;QACnBC,iBAAiB;QACjBC,YAAY;QACZ,GAAGH,OAAO;IACZ;IAEA;;;;;;GAMC,GACD,MAAMI,mBAAmB,CAACf;QACxB,OAAOgB,QACL,AAAC,OAAOhB,OAAO,YAAaa,CAAAA,mBAAmBzC,OAAO6C,SAAS,CAACjB,GAAE,KAC/D,OAAOA,OAAO,YAAaY,CAAAA,qBAAqBZ,GAAGrC,MAAM,GAAG,CAAA,KAC5DmD,cAAcd,OAAO;IAE5B;IAEA,OAAOe;AACT"} +\ No newline at end of file +diff --git a/dist/esm/json.js b/dist/esm/json.js +index 2c039cccf11893d2d88fc4fb666e7836c9a42325..79cff5f24af419080633f3be7f8971309ea8bcbb 100644 +--- a/dist/esm/json.js ++++ b/dist/esm/json.js +@@ -1,5 +1,35 @@ +-import { any, array, boolean, coerce, create, define, integer, is, lazy, literal, nullable, number, object, omit, optional, record, string, union, unknown } from 'superstruct'; ++import { any, array, boolean, coerce, create, define, integer, is, lazy, literal, nullable, number, object as superstructObject, object, optional, record, string, union, unknown } from 'superstruct'; + import { assertStruct } from './assert'; ++import { hasProperty } from './misc'; ++/** ++ * A struct to check if the given value is a valid JSON object. ++ * ++ * @param schema - The schema of the JSON object. ++ * @returns A struct to check if the given value is a valid JSON object. ++ */ export const jsonObject = (schema)=>// The type is slightly different from a regular object struct, because we ++ // want to make properties with `undefined` in their type optional, but not ++ // `undefined` itself. This means that we need a type cast. ++ superstructObject(schema); ++/** ++ * A struct to check if the given value is a valid JSON object, or not present. ++ * This means that it allows an object which does not have the property, or an ++ * object which has the property and is valid, but not an object which has the ++ * property set to `undefined`. ++ * ++ * @param struct - The struct to check the value against, if present. ++ * @returns A struct to check if the given value is a valid JSON object, or not ++ * present. ++ */ export const jsonOptional = (struct)=>define('optional', (value, context)=>{ ++ const parent = context.branch[context.branch.length - 2]; ++ const key = context.path[context.path.length - 1]; ++ if (!hasProperty(parent, key)) { ++ return true; ++ } ++ if (value === undefined) { ++ return 'Expected a value, but received: undefined.'; ++ } ++ return struct.validator(value, context); ++ }); + /** + * A struct to check if the given value is finite number. Superstruct's + * `number()` struct does not check if the value is finite. +@@ -82,25 +112,27 @@ export const JsonRpcIdStruct = nullable(union([ + number(), + string() + ])); +-export const JsonRpcErrorStruct = object({ ++export const JsonRpcErrorStruct = jsonObject({ + code: integer(), + message: string(), +- data: optional(JsonStruct), +- stack: optional(string()) ++ data: jsonOptional(JsonStruct), ++ stack: jsonOptional(string()) + }); +-export const JsonRpcParamsStruct = optional(union([ ++export const JsonRpcParamsStruct = union([ + record(string(), JsonStruct), + array(JsonStruct) +-])); +-export const JsonRpcRequestStruct = object({ ++]); ++export const JsonRpcRequestStruct = jsonObject({ + id: JsonRpcIdStruct, + jsonrpc: JsonRpcVersionStruct, + method: string(), +- params: JsonRpcParamsStruct ++ params: jsonOptional(JsonRpcParamsStruct) ++}); ++export const JsonRpcNotificationStruct = jsonObject({ ++ jsonrpc: JsonRpcVersionStruct, ++ method: string(), ++ params: jsonOptional(JsonRpcParamsStruct) + }); +-export const JsonRpcNotificationStruct = omit(JsonRpcRequestStruct, [ +- 'id' +-]); + /** + * Check if the given value is a valid {@link JsonRpcNotification} object. + * +@@ -146,12 +178,12 @@ export const PendingJsonRpcResponseStruct = object({ + result: optional(unknown()), + error: optional(JsonRpcErrorStruct) + }); +-export const JsonRpcSuccessStruct = object({ ++export const JsonRpcSuccessStruct = jsonObject({ + id: JsonRpcIdStruct, + jsonrpc: JsonRpcVersionStruct, + result: JsonStruct + }); +-export const JsonRpcFailureStruct = object({ ++export const JsonRpcFailureStruct = jsonObject({ + id: JsonRpcIdStruct, + jsonrpc: JsonRpcVersionStruct, + error: JsonRpcErrorStruct +diff --git a/dist/esm/json.js.map b/dist/esm/json.js.map +index ae3392c53e52a601e18ce8991dc6e4414a50123f..e1cbb6fabf0a3a36cf3260a3a7d8b37a1f95ac24 100644 +--- a/dist/esm/json.js.map ++++ b/dist/esm/json.js.map +@@ -1 +1 @@ +-{"version":3,"sources":["../../src/json.ts"],"sourcesContent":["import type { Infer, Struct } 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,\n omit,\n optional,\n record,\n string,\n union,\n unknown,\n} from 'superstruct';\n\nimport type { AssertionErrorConstructor } from './assert';\nimport { assertStruct } from './assert';\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 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('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 = 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(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;\n\nexport const JsonRpcErrorStruct = object({\n code: integer(),\n message: string(),\n data: optional(JsonStruct),\n stack: optional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record,\n Key extends keyof Type,\n> = Omit & Partial>;\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,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct: Struct, null> =\n optional(union([record(string(), JsonStruct), array(JsonStruct)])) as any;\n\nexport type JsonRpcParams = Json[] | Record;\n\nexport const JsonRpcRequestStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: JsonRpcParamsStruct,\n});\n\nexport type InferWithParams<\n Type extends Struct,\n Params extends JsonRpcParams,\n> = Omit, 'params'> &\n (keyof Params extends undefined\n ? {\n params?: Params;\n }\n : {\n params: Params;\n });\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest =\n InferWithParams;\n\nexport const JsonRpcNotificationStruct = omit(JsonRpcRequestStruct, ['id']);\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification =\n InferWithParams;\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 = object({\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 = Omit<\n Infer,\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 = Omit<\n Infer,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n error: JsonRpcErrorStruct as Struct,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer;\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 =\n | JsonRpcSuccess\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 {\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 {\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 {\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 {\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 {\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 {\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"],"names":["any","array","boolean","coerce","create","define","integer","is","lazy","literal","nullable","number","object","omit","optional","record","string","union","unknown","assertStruct","finiteNumber","value","Number","isFinite","UnsafeJsonStruct","JsonStruct","JSON","parse","stringify","propKey","propValue","undefined","isValidJson","getSafeJson","getJsonSize","json","TextEncoder","encode","byteLength","jsonrpc2","JsonRpcVersionStruct","JsonRpcIdStruct","JsonRpcErrorStruct","code","message","data","stack","JsonRpcParamsStruct","JsonRpcRequestStruct","id","jsonrpc","method","params","JsonRpcNotificationStruct","isJsonRpcNotification","assertIsJsonRpcNotification","ErrorWrapper","isJsonRpcRequest","assertIsJsonRpcRequest","PendingJsonRpcResponseStruct","result","error","JsonRpcSuccessStruct","JsonRpcFailureStruct","JsonRpcResponseStruct","isPendingJsonRpcResponse","response","assertIsPendingJsonRpcResponse","isJsonRpcResponse","assertIsJsonRpcResponse","isJsonRpcSuccess","assertIsJsonRpcSuccess","isJsonRpcFailure","assertIsJsonRpcFailure","isJsonRpcError","assertIsJsonRpcError","getJsonRpcIdValidator","options","permitEmptyString","permitFractions","permitNull","isValidJsonRpcId","Boolean","isInteger","length"],"mappings":"AACA,SACEA,GAAG,EACHC,KAAK,EACLC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,OAAO,EACPC,EAAE,EACFC,IAAI,EACJC,OAAO,EACPC,QAAQ,EACRC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,QAAQ,EACRC,MAAM,EACNC,MAAM,EACNC,KAAK,EACLC,OAAO,QACF,cAAc;AAGrB,SAASC,YAAY,QAAQ,WAAW;AAaxC;;;;;CAKC,GACD,MAAMC,eAAe,IACnBf,OAAe,iBAAiB,CAACgB;QAC/B,OAAOd,GAAGc,OAAOV,aAAaW,OAAOC,QAAQ,CAACF;IAChD;AAEF;;;;CAIC,GACD,mEAAmE;AACnE,OAAO,MAAMG,mBAAiCP,MAAM;IAClDR,QAAQ;IACRP;IACAkB;IACAJ;IACAf,MAA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;AAEJ;AAEA;;;;;CAKC,GACD,OAAO,SAASc,iBACdjD,KAAc;IAEd,OAAOd,GAAGc,OAAOyC;AACnB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASS,uBACdlD,KAAc,EACd,gEAAgE;AAChEmC,YAAwC;IAExCrC,aACEE,OACAyC,sBACA,qCACAN;AAEJ;AAEA;;;;;CAKC,GACD,OAAO,SAASgB,iBAAiBnD,KAAc;IAC7C,OAAOd,GAAGc,OAAO0C;AACnB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASU,uBACdpD,KAAc,EACd,gEAAgE;AAChEmC,YAAwC;IAExCrC,aACEE,OACA0C,sBACA,qCACAP;AAEJ;AAEA;;;;;CAKC,GACD,OAAO,SAASkB,eAAerD,KAAc;IAC3C,OAAOd,GAAGc,OAAOqB;AACnB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASiC,qBACdtD,KAAc,EACd,gEAAgE;AAChEmC,YAAwC;IAExCrC,aACEE,OACAqB,oBACA,0BACAc;AAEJ;AAQA;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,SAASoB,sBAAsBC,OAAiC;IACrE,MAAM,EAAEC,iBAAiB,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAG;QACzDF,mBAAmB;QACnBC,iBAAiB;QACjBC,YAAY;QACZ,GAAGH,OAAO;IACZ;IAEA;;;;;;GAMC,GACD,MAAMI,mBAAmB,CAAChC;QACxB,OAAOiC,QACL,AAAC,OAAOjC,OAAO,YAAa8B,CAAAA,mBAAmBzD,OAAO6D,SAAS,CAAClC,GAAE,KAC/D,OAAOA,OAAO,YAAa6B,CAAAA,qBAAqB7B,GAAGmC,MAAM,GAAG,CAAA,KAC5DJ,cAAc/B,OAAO;IAE5B;IAEA,OAAOgC;AACT"} +\ No newline at end of file ++{"version":3,"sources":["../../src/json.ts"],"sourcesContent":["import type { Infer, Struct } 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 object,\n optional,\n record,\n string,\n union,\n unknown,\n} from 'superstruct';\nimport type {\n ObjectSchema,\n OmitBy,\n PickBy,\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 = JsonOptional<{ foo: string | undefined }>;\n * // Foo is equivalent to { foo?: string }\n * ```\n */\nexport type JsonOptional> = {\n [Key in keyof PickBy]?: Exclude;\n} & {\n [Key in keyof OmitBy]: Schema[Key];\n};\n\n/**\n * A JSON object type. This is used by the `json` struct. This uses the\n * {@link JsonOptional} helper to make properties with `undefined` in their type\n * optional, but not `undefined` itself.\n */\nexport type JsonObjectType = Simplify<\n JsonOptional<{\n [Key in keyof Schema]: Infer;\n }>\n>;\n\n/**\n * A struct to check if the given value is a valid JSON object.\n *\n * @param schema - The schema of the JSON object.\n * @returns A struct to check if the given value is a valid JSON object.\n */\nexport const jsonObject = (\n schema: Schema,\n): Struct> =>\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>;\n\n/**\n * A struct to check if the given value is a valid JSON object, or not present.\n * This means that it allows an object which does not have the property, or an\n * object which has the property and is valid, but not an object which has the\n * property set to `undefined`.\n *\n * @param struct - The struct to check the value against, if present.\n * @returns A struct to check if the given value is a valid JSON object, or not\n * present.\n */\nexport const jsonOptional = (\n struct: Struct,\n): Struct =>\n define('optional', (value, context) => {\n const parent = context.branch[context.branch.length - 2];\n const key = context.path[context.path.length - 1];\n\n if (!hasProperty(parent, key)) {\n return true;\n }\n\n if (value === undefined) {\n return 'Expected a value, but received: undefined.';\n }\n\n return struct.validator(value, context);\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('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 = 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(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;\n\nexport const JsonRpcErrorStruct = jsonObject({\n code: integer(),\n message: string(),\n data: jsonOptional(JsonStruct),\n stack: jsonOptional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record,\n Key extends keyof Type,\n> = Omit & Partial>;\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,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct: Struct, null> =\n union([record(string(), JsonStruct), array(JsonStruct)]);\n\nexport type JsonRpcParams = Json[] | Record;\n\nexport const JsonRpcRequestStruct = jsonObject({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: jsonOptional(JsonRpcParamsStruct),\n});\n\nexport type InferWithParams<\n Type extends Struct,\n Params extends JsonRpcParams,\n> = Infer & {\n params?: Params;\n};\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest =\n InferWithParams;\n\nexport const JsonRpcNotificationStruct = jsonObject({\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: jsonOptional(JsonRpcParamsStruct),\n});\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification =\n InferWithParams;\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 = object({\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 = Omit<\n Infer,\n 'result'\n> & {\n result?: Result;\n};\n\nexport const JsonRpcSuccessStruct = jsonObject({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: JsonStruct,\n});\n\n/**\n * A successful JSON-RPC response object.\n */\nexport type JsonRpcSuccess = Omit<\n Infer,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = jsonObject({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n error: JsonRpcErrorStruct as Struct,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer;\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 =\n | JsonRpcSuccess\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 {\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 {\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 {\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 {\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 {\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 {\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"],"names":["any","array","boolean","coerce","create","define","integer","is","lazy","literal","nullable","number","object","superstructObject","optional","record","string","union","unknown","assertStruct","hasProperty","jsonObject","schema","jsonOptional","struct","value","context","parent","branch","length","key","path","undefined","validator","finiteNumber","Number","isFinite","UnsafeJsonStruct","JsonStruct","JSON","parse","stringify","propKey","propValue","isValidJson","getSafeJson","getJsonSize","json","TextEncoder","encode","byteLength","jsonrpc2","JsonRpcVersionStruct","JsonRpcIdStruct","JsonRpcErrorStruct","code","message","data","stack","JsonRpcParamsStruct","JsonRpcRequestStruct","id","jsonrpc","method","params","JsonRpcNotificationStruct","isJsonRpcNotification","assertIsJsonRpcNotification","ErrorWrapper","isJsonRpcRequest","assertIsJsonRpcRequest","PendingJsonRpcResponseStruct","result","error","JsonRpcSuccessStruct","JsonRpcFailureStruct","JsonRpcResponseStruct","isPendingJsonRpcResponse","response","assertIsPendingJsonRpcResponse","isJsonRpcResponse","assertIsJsonRpcResponse","isJsonRpcSuccess","assertIsJsonRpcSuccess","isJsonRpcFailure","assertIsJsonRpcFailure","isJsonRpcError","assertIsJsonRpcError","getJsonRpcIdValidator","options","permitEmptyString","permitFractions","permitNull","isValidJsonRpcId","Boolean","isInteger"],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D;AACnB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASS,uBACd1D,KAAc,EACd,gEAAgE;AAChE2C,YAAwC;IAExCjD,aACEM,OACAiD,sBACA,qCACAN;AAEJ;AAEA;;;;;CAKC,GACD,OAAO,SAASgB,iBAAiB3D,KAAc;IAC7C,OAAOlB,GAAGkB,OAAOkD;AACnB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASU,uBACd5D,KAAc,EACd,gEAAgE;AAChE2C,YAAwC;IAExCjD,aACEM,OACAkD,sBACA,qCACAP;AAEJ;AAEA;;;;;CAKC,GACD,OAAO,SAASkB,eAAe7D,KAAc;IAC3C,OAAOlB,GAAGkB,OAAO6B;AACnB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASiC,qBACd9D,KAAc,EACd,gEAAgE;AAChE2C,YAAwC;IAExCjD,aACEM,OACA6B,oBACA,0BACAc;AAEJ;AAQA;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,SAASoB,sBAAsBC,OAAiC;IACrE,MAAM,EAAEC,iBAAiB,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAG;QACzDF,mBAAmB;QACnBC,iBAAiB;QACjBC,YAAY;QACZ,GAAGH,OAAO;IACZ;IAEA;;;;;;GAMC,GACD,MAAMI,mBAAmB,CAAChC;QACxB,OAAOiC,QACL,AAAC,OAAOjC,OAAO,YAAa8B,CAAAA,mBAAmBxD,OAAO4D,SAAS,CAAClC,GAAE,KAC/D,OAAOA,OAAO,YAAa6B,CAAAA,qBAAqB7B,GAAGhC,MAAM,GAAG,CAAA,KAC5D+D,cAAc/B,OAAO;IAE5B;IAEA,OAAOgC;AACT"} +\ No newline at end of file +diff --git a/dist/types/json.d.ts b/dist/types/json.d.ts +index 1533dcbb925903367f6cf082a4a54d5aa306caf9..11d6980ca424799d50f1182e7fb72987f4066a80 100644 +--- a/dist/types/json.d.ts ++++ b/dist/types/json.d.ts +@@ -1,4 +1,5 @@ + import type { Infer, Struct } from 'superstruct'; ++import type { ObjectSchema, OmitBy, PickBy, Simplify } from 'superstruct/dist/utils'; + import type { AssertionErrorConstructor } from './assert'; + /** + * Any JSON-compatible value. +@@ -6,6 +7,47 @@ import type { AssertionErrorConstructor } from './assert'; + export declare type Json = null | boolean | number | string | Json[] | { + [prop: string]: Json; + }; ++/** ++ * A helper type to make properties with `undefined` in their type optional, but ++ * not `undefined` itself. ++ * ++ * @example ++ * ```ts ++ * type Foo = JsonOptional<{ foo: string | undefined }>; ++ * // Foo is equivalent to { foo?: string } ++ * ``` ++ */ ++export declare type JsonOptional> = { ++ [Key in keyof PickBy]?: Exclude; ++} & { ++ [Key in keyof OmitBy]: Schema[Key]; ++}; ++/** ++ * A JSON object type. This is used by the `json` struct. This uses the ++ * {@link JsonOptional} helper to make properties with `undefined` in their type ++ * optional, but not `undefined` itself. ++ */ ++export declare type JsonObjectType = Simplify; ++}>>; ++/** ++ * A struct to check if the given value is a valid JSON object. ++ * ++ * @param schema - The schema of the JSON object. ++ * @returns A struct to check if the given value is a valid JSON object. ++ */ ++export declare const jsonObject: (schema: Schema) => Struct; }>>, unknown>; ++/** ++ * A struct to check if the given value is a valid JSON object, or not present. ++ * This means that it allows an object which does not have the property, or an ++ * object which has the property and is valid, but not an object which has the ++ * property set to `undefined`. ++ * ++ * @param struct - The struct to check the value against, if present. ++ * @returns A struct to check if the given value is a valid JSON object, or not ++ * present. ++ */ ++export declare const jsonOptional: (struct: Struct) => Struct; + /** + * A struct to check if the given value is a valid JSON-serializable value. + * +@@ -66,16 +108,11 @@ export declare const JsonRpcIdStruct: Struct; + */ + export declare type JsonRpcId = Infer; + export declare const JsonRpcErrorStruct: Struct<{ ++ data?: Json; ++ stack?: string; + code: number; + message: string; +- data?: Json | undefined; +- stack?: string | undefined; +-}, { +- code: Struct; +- message: Struct; +- data: Struct; +- stack: Struct; +-}>; ++}, unknown>; + /** + * Mark a certain key of a type as optional. + */ +@@ -91,35 +128,23 @@ export declare type JsonRpcError = OptionalField, null>; + export declare type JsonRpcParams = Json[] | Record; + export declare const JsonRpcRequestStruct: Struct<{ ++ params?: Json[] | Record; + id: string | number | null; + method: string; + jsonrpc: "2.0"; +- params: Json[] | Record; +-}, { +- id: Struct; +- jsonrpc: Struct<"2.0", "2.0">; +- method: Struct; +- params: Struct, null>; +-}>; +-export declare type InferWithParams, Params extends JsonRpcParams> = Omit, 'params'> & (keyof Params extends undefined ? { ++}, unknown>; ++export declare type InferWithParams, Params extends JsonRpcParams> = Infer & { + params?: Params; +-} : { +- params: Params; +-}); ++}; + /** + * A JSON-RPC request object. + */ + export declare type JsonRpcRequest = InferWithParams; + export declare const JsonRpcNotificationStruct: Struct<{ ++ params?: Json[] | Record; + method: string; + jsonrpc: "2.0"; +- params: Json[] | Record; +-}, Omit<{ +- id: Struct; +- jsonrpc: Struct<"2.0", "2.0">; +- method: Struct; +- params: Struct, null>; +-}, "id">>; ++}, unknown>; + /** + * A JSON-RPC notification object. + */ +@@ -162,26 +187,21 @@ export declare const PendingJsonRpcResponseStruct: Struct<{ + jsonrpc: "2.0"; + result: unknown; + error?: { ++ data?: Json; ++ stack?: string; + code: number; + message: string; +- data?: Json | undefined; +- stack?: string | undefined; + } | undefined; + }, { + id: Struct; + jsonrpc: Struct<"2.0", "2.0">; + result: Struct; + error: Struct<{ ++ data?: Json; ++ stack?: string; + code: number; + message: string; +- data?: Json | undefined; +- stack?: string | undefined; +- } | undefined, { +- code: Struct; +- message: Struct; +- data: Struct; +- stack: Struct; +- }>; ++ } | undefined, unknown>; + }>; + /** + * A JSON-RPC response object that has not yet been resolved. +@@ -193,11 +213,7 @@ export declare const JsonRpcSuccessStruct: Struct<{ + id: string | number | null; + jsonrpc: "2.0"; + result: Json; +-}, { +- id: Struct; +- jsonrpc: Struct<"2.0", "2.0">; +- result: Struct; +-}>; ++}, unknown>; + /** + * A successful JSON-RPC response object. + */ +@@ -208,11 +224,7 @@ export declare const JsonRpcFailureStruct: Struct<{ + error: JsonRpcError; + id: string | number | null; + jsonrpc: "2.0"; +-}, { +- id: Struct; +- jsonrpc: Struct<"2.0", "2.0">; +- error: Struct; +-}>; ++}, unknown>; + /** + * A failed JSON-RPC response object. + */ +diff --git a/dist/types/json.d.ts.map b/dist/types/json.d.ts.map +index b8af457fd46d71f4687d6164df970f05e392966e..30b319e8e5c7d10f6b73fafb93b510d7ff6bea5e 100644 +--- a/dist/types/json.d.ts.map ++++ b/dist/types/json.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAuBjD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAG1D;;GAEG;AACH,oBAAY,IAAI,GACZ,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,IAAI,EAAE,GACN;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAa7B;;;;GAIG;AAEH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAUxC,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,UAAU,uBAWrB,CAAC;AAEH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAOzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,IAAI,SAAS,IAAI,GAAG,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAE1E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAKlD;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,OAAiB,CAAC;AACvC,eAAO,MAAM,oBAAoB,sBAAoB,CAAC;AAEtD;;;GAGG;AACH,oBAAY,eAAe,GAAG,OAAO,QAAQ,CAAC;AAE9C,eAAO,MAAM,eAAe,sCAAwC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uB,CACrC,KAAK,EAAE,OAAO,EAEd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,eAAe,CAAC,IAAI,CAAC,CAOxC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,cAAc,CAAC,IAAI,CAAC,CAE/B;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EAEd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,cAAc,CAAC,IAAI,CAAC,CAOvC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAExE;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EAEd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,cAAc,CAOjC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EAEd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,YAAY,CAO/B;AAED,aAAK,uBAAuB,GAAG;IAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,uBAAuB,QAevC,OAAO,kCAStC"} +\ No newline at end of file diff --git a/package.json b/package.json index a39d713..3e3466e 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,9 @@ "test": "jest && jest-it-up", "test:watch": "jest --watch" }, + "resolutions": { + "@metamask/utils@^8.0.0": "patch:@metamask/utils@npm%3A8.0.0#./.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch" + }, "dependencies": { "@metamask/utils": "^8.0.0", "fast-safe-stringify": "^2.0.6" diff --git a/yarn.lock b/yarn.lock index 6358f6f..14384b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1018,7 +1018,7 @@ __metadata: languageName: unknown linkType: soft -"@metamask/utils@npm:^8.0.0": +"@metamask/utils@npm:8.0.0": version: 8.0.0 resolution: "@metamask/utils@npm:8.0.0" dependencies: @@ -1032,6 +1032,20 @@ __metadata: languageName: node linkType: hard +"@metamask/utils@patch:@metamask/utils@npm%3A8.0.0#./.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch::locator=%40metamask%2Frpc-errors%40workspace%3A.": + version: 8.0.0 + resolution: "@metamask/utils@patch:@metamask/utils@npm%3A8.0.0#./.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch::version=8.0.0&hash=345c47&locator=%40metamask%2Frpc-errors%40workspace%3A." + dependencies: + "@ethereumjs/tx": ^4.1.2 + "@noble/hashes": ^1.3.1 + "@types/debug": ^4.1.7 + debug: ^4.3.4 + semver: ^7.5.4 + superstruct: ^1.0.3 + checksum: b63783de2ef654f667d9ae06d9e3b71efd227d8cf7aa99c87717feaed3a0ec686141094f1825effa332f48132ac2dce6c786c9ab33e96ffcb3c89a9e5049bf26 + languageName: node + linkType: hard + "@noble/curves@npm:1.0.0, @noble/curves@npm:~1.0.0": version: 1.0.0 resolution: "@noble/curves@npm:1.0.0"