@metamask-previews/json-rpc-engine 10.1.1-preview-2e88eaea → 10.1.1-preview-c96ff8f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -3
- package/README.md +27 -0
- package/dist/asV2Middleware.cjs +8 -3
- package/dist/asV2Middleware.cjs.map +1 -1
- package/dist/asV2Middleware.d.cts +1 -1
- package/dist/asV2Middleware.d.cts.map +1 -1
- package/dist/asV2Middleware.d.mts +1 -1
- package/dist/asV2Middleware.d.mts.map +1 -1
- package/dist/asV2Middleware.mjs +9 -4
- package/dist/asV2Middleware.mjs.map +1 -1
- package/dist/v2/JsonRpcEngineV2.cjs +5 -2
- package/dist/v2/JsonRpcEngineV2.cjs.map +1 -1
- package/dist/v2/JsonRpcEngineV2.d.cts +18 -5
- package/dist/v2/JsonRpcEngineV2.d.cts.map +1 -1
- package/dist/v2/JsonRpcEngineV2.d.mts +18 -5
- package/dist/v2/JsonRpcEngineV2.d.mts.map +1 -1
- package/dist/v2/JsonRpcEngineV2.mjs +5 -2
- package/dist/v2/JsonRpcEngineV2.mjs.map +1 -1
- package/dist/v2/JsonRpcServer.cjs +5 -6
- package/dist/v2/JsonRpcServer.cjs.map +1 -1
- package/dist/v2/JsonRpcServer.d.cts +12 -6
- package/dist/v2/JsonRpcServer.d.cts.map +1 -1
- package/dist/v2/JsonRpcServer.d.mts +12 -6
- package/dist/v2/JsonRpcServer.d.mts.map +1 -1
- package/dist/v2/JsonRpcServer.mjs +5 -6
- package/dist/v2/JsonRpcServer.mjs.map +1 -1
- package/dist/v2/MiddlewareContext.cjs +42 -1
- package/dist/v2/MiddlewareContext.cjs.map +1 -1
- package/dist/v2/MiddlewareContext.d.cts +15 -2
- package/dist/v2/MiddlewareContext.d.cts.map +1 -1
- package/dist/v2/MiddlewareContext.d.mts +15 -2
- package/dist/v2/MiddlewareContext.d.mts.map +1 -1
- package/dist/v2/MiddlewareContext.mjs +42 -1
- package/dist/v2/MiddlewareContext.mjs.map +1 -1
- package/dist/v2/compatibility-utils.cjs +3 -3
- package/dist/v2/compatibility-utils.cjs.map +1 -1
- package/dist/v2/compatibility-utils.d.cts +1 -1
- package/dist/v2/compatibility-utils.d.mts +1 -1
- package/dist/v2/compatibility-utils.mjs +1 -1
- package/dist/v2/compatibility-utils.mjs.map +1 -1
- package/dist/v2/createScaffoldMiddleware.cjs.map +1 -1
- package/dist/v2/createScaffoldMiddleware.d.cts +12 -3
- package/dist/v2/createScaffoldMiddleware.d.cts.map +1 -1
- package/dist/v2/createScaffoldMiddleware.d.mts +12 -3
- package/dist/v2/createScaffoldMiddleware.d.mts.map +1 -1
- package/dist/v2/createScaffoldMiddleware.mjs.map +1 -1
- package/dist/v2/index.cjs.map +1 -1
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.cts.map +1 -1
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.d.mts.map +1 -1
- package/dist/v2/index.mjs.map +1 -1
- package/dist/v2/utils.cjs +2 -2
- package/dist/v2/utils.cjs.map +1 -1
- package/dist/v2/utils.d.cts.map +1 -1
- package/dist/v2/utils.d.mts.map +1 -1
- package/dist/v2/utils.mjs +2 -2
- package/dist/v2/utils.mjs.map +1 -1
- package/package.json +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MiddlewareContext.mjs","sourceRoot":"","sources":["../../src/v2/MiddlewareContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MiddlewareContext.mjs","sourceRoot":"","sources":["../../src/v2/MiddlewareContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAI3C,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,iBAEX,SAAQ,GAAgD;IAGxD;;;;;;OAMG;IACH,MAAM,CAAC,U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oB;IAEpB,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,GAAoB,EAAE,EAAE,CAAC;QAC9D,GAAG;QACH,SAAS,CAAC,GAAG,CAAC;KACf,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { isObject } from '@metamask/utils';\n\nimport type { UnionToIntersection } from './utils';\n\nconst MiddlewareContextSymbol = Symbol.for('json-rpc-engine#MiddlewareContext');\n\n/**\n * An context object for middleware that attempts to protect against accidental\n * modifications. Its interface is frozen.\n *\n * Map keys may not be directly overridden with {@link set}. Instead, use\n * {@link delete} to remove a key and then {@link set} to add a new value.\n *\n * The override protections are circumvented when using e.g. `Reflect.set`, so\n * don't do that.\n *\n * @template KeyValues - The type of the keys and values in the context.\n * @example\n * // By default, the context permits any PropertyKey as a key.\n * const context = new MiddlewareContext();\n * context.set('foo', 'bar');\n * context.get('foo'); // 'bar'\n * context.get('fizz'); // undefined\n * @example\n * // By specifying an object type, the context permits only the keys of the object.\n * type Context = MiddlewareContext<{ foo: string }>;\n * const context = new Context([['foo', 'bar']]);\n * context.get('foo'); // 'bar'\n * context.get('fizz'); // Type error\n */\nexport class MiddlewareContext<\n KeyValues extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>,\n> extends Map<keyof KeyValues, KeyValues[keyof KeyValues]> {\n private readonly [MiddlewareContextSymbol] = true;\n\n /**\n * Check if a value is a {@link MiddlewareContext} instance.\n * Works across different package versions in the same realm.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link MiddlewareContext} instance.\n */\n static isInstance(value: unknown): value is MiddlewareContext {\n return (\n isObject(value) &&\n MiddlewareContextSymbol in value &&\n value[MiddlewareContextSymbol] === true\n );\n }\n\n constructor(\n entries?:\n | Iterable<readonly [keyof KeyValues, KeyValues[keyof KeyValues]]>\n | KeyValues,\n ) {\n super(\n entries && isIterable(entries)\n ? entries\n : entriesFromKeyValues(entries ?? {}),\n );\n Object.freeze(this);\n }\n\n get<K extends keyof KeyValues>(key: K): KeyValues[K] | undefined {\n return super.get(key) as KeyValues[K] | undefined;\n }\n\n /**\n * Get a value from the context. Throws if the key is not found.\n *\n * @param key - The key to get the value for.\n * @returns The value.\n */\n assertGet<K extends keyof KeyValues>(key: K): KeyValues[K] {\n if (!super.has(key)) {\n throw new Error(`Context key \"${String(key)}\" not found`);\n }\n return super.get(key) as KeyValues[K];\n }\n\n /**\n * Set a value in the context. Throws if the key already exists.\n * {@link delete} an existing key before setting it to a new value.\n *\n * @throws If the key already exists.\n * @param key - The key to set the value for.\n * @param value - The value to set.\n * @returns The context.\n */\n set<K extends keyof KeyValues>(key: K, value: KeyValues[K]): this {\n if (super.has(key)) {\n throw new Error(`MiddlewareContext key \"${String(key)}\" already exists`);\n }\n super.set(key, value);\n return this;\n }\n}\n\n/**\n * {@link Iterable} type guard.\n *\n * @param value - The value to check.\n * @returns Whether the value is an {@link Iterable}.\n */\nfunction isIterable(\n value: Iterable<unknown> | Record<PropertyKey, unknown>,\n): value is Iterable<unknown> {\n return Symbol.iterator in value;\n}\n\n/**\n * Like Object.entries(), but includes symbol-keyed properties.\n *\n * @template KeyValues - The type of the keys and values in the object.\n * @param keyValues - The object to convert.\n * @returns The array of entries, including symbol-keyed properties.\n */\nfunction entriesFromKeyValues<KeyValues extends Record<PropertyKey, unknown>>(\n keyValues: KeyValues,\n): [keyof KeyValues, KeyValues[keyof KeyValues]][] {\n return Reflect.ownKeys(keyValues).map((key: keyof KeyValues) => [\n key,\n keyValues[key],\n ]);\n}\n\n/**\n * Infer the KeyValues type from a {@link MiddlewareContext}.\n */\nexport type InferKeyValues<T> =\n T extends MiddlewareContext<infer U> ? U : never;\n\n/**\n * Simplifies an object type by \"merging\" its properties.\n *\n * - Expands intersections into a single object type.\n * - Forces mapped/conditional results to resolve into a readable shape.\n * - No runtime effect; purely a type-level normalization.\n *\n * @example\n * type A = { a: string } & { b: number };\n * type B = Simplify<A>; // { a: string; b: number }\n */\ntype Simplify<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;\n\n/**\n * Rejects record types that contain any `never`-valued property.\n *\n * If any property of `T` resolves to `never`, the result is `never`; otherwise it returns `T` unchanged.\n * Useful as a guard to ensure computed/merged record types didn't collapse any fields to `never`.\n *\n * @example\n * type A = ExcludeNever<{ a: string; b: never }>; // never\n * type B = ExcludeNever<{ a: string; b: number }>; // { a: string; b: number }\n */\ntype ExcludeNever<T extends Record<PropertyKey, unknown>> = {\n [K in keyof T]-?: [T[K]] extends [never] ? K : never;\n}[keyof T] extends never\n ? T\n : never;\n\n/**\n * Merge a union of {@link MiddlewareContext}s into a single {@link MiddlewareContext}\n * supertype.\n *\n * @param Contexts - The union of {@link MiddlewareContext}s to merge.\n * @returns The merged {@link MiddlewareContext} supertype.\n * @example\n * type A = MiddlewareContext<{ a: string }> | MiddlewareContext<{ b: number }>;\n * type B = MergeContexts<A>; // MiddlewareContext<{ a: string, b: number }>\n */\nexport type MergeContexts<Contexts extends ContextConstraint> =\n ExcludeNever<\n Simplify<UnionToIntersection<InferKeyValues<Contexts>>>\n > extends never\n ? never\n : MiddlewareContext<\n ExcludeNever<Simplify<UnionToIntersection<InferKeyValues<Contexts>>>>\n >;\n\n/**\n * A constraint for {@link MiddlewareContext} generic parameters.\n */\n// Non-polluting `any` constraint.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ContextConstraint = MiddlewareContext<any>;\n\n/**\n * The empty context type, i.e. `MiddlewareContext<{}>`.\n */\n// The empty object type is literally an empty object in this context.\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport type EmptyContext = MiddlewareContext<{}>;\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.deserializeError = exports.propagateToRequest = exports.propagateToContext = exports.makeContext = exports.fromLegacyRequest = exports.requestProps = exports.deepClone = void 0;
|
|
4
4
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
5
|
const utils_1 = require("@metamask/utils");
|
|
6
6
|
// ATTN: We must NOT use 'klona/full' here because it freezes properties on the clone.
|
|
@@ -106,7 +106,7 @@ exports.propagateToRequest = propagateToRequest;
|
|
|
106
106
|
* @param thrown - The thrown value to unserialize.
|
|
107
107
|
* @returns The unserialized error.
|
|
108
108
|
*/
|
|
109
|
-
function
|
|
109
|
+
function deserializeError(thrown) {
|
|
110
110
|
// @ts-expect-error - New, but preferred if available.
|
|
111
111
|
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError
|
|
112
112
|
if (typeof Error.isError === 'function' && Error.isError(thrown)) {
|
|
@@ -147,5 +147,5 @@ function unserializeError(thrown) {
|
|
|
147
147
|
}
|
|
148
148
|
return error;
|
|
149
149
|
}
|
|
150
|
-
exports.
|
|
150
|
+
exports.deserializeError = deserializeError;
|
|
151
151
|
//# sourceMappingURL=compatibility-utils.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compatibility-utils.cjs","sourceRoot":"","sources":["../../src/v2/compatibility-utils.ts"],"names":[],"mappings":";;;AAAA,qDAAwE;AAExE,2CAAwD;AACxD,sFAAsF;AACtF,iCAA8B;AAE9B,+DAAwD;AACxD,uCAAyD;AAEzD,oCAAoC;AAEpC;;;;;;;;;;GAUG;AACI,MAAM,SAAS,GAAG,CAAI,KAAQ,EAAiB,EAAE,CACtD,IAAA,aAAK,EAAC,KAAK,CAAkB,CAAC;AADnB,QAAA,SAAS,aACU;AAWhC;;GAEG;AACU,QAAA,YAAY,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AAElE;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,GAAY;IAEZ,MAAM,OAAO,GAAG;QACd,OAAO,EAAE,KAAc;QACvB,MAAM,EAAE,GAAG,CAAC,MAAM;KACC,CAAC;IACtB,OAAO,CAAC,EAAE,GAAG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kEAAkE;YAClE,6DAA6D;YAC7D,2CAA2C;YAC3C,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC,IAAI,yBAAY,CAAC,IAAI,EAAE,OAAO,EAAE;YAC9B,GAAG,CAAC,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;YACtC,KAAK;SACN,CAAC,CAAC;IAET,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;KACrB;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AA/CD,4CA+CC","sourcesContent":["import { getMessageFromCode, JsonRpcError } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n// ATTN: We must NOT use 'klona/full' here because it freezes properties on the clone.\nimport { klona } from 'klona';\n\nimport { MiddlewareContext } from './MiddlewareContext';\nimport { stringify, type JsonRpcRequest } from './utils';\n\n// Legacy engine compatibility utils\n\n/**\n * Create a deep clone of a value as follows:\n * - Assumes acyclical objects\n * - Does not copy property descriptors (i.e. uses mutable defaults)\n * - Ignores non-enumerable properties\n * - Ignores getters and setters\n *\n * @throws If the value is an object with a circular reference.\n * @param value - The value to clone.\n * @returns The cloned value.\n */\nexport const deepClone = <T>(value: T): DeepCloned<T> =>\n klona(value) as DeepCloned<T>;\n\n// Matching the default implementation of klona, this type:\n// - Removes readonly modifiers\n// - Excludes non-enumerable / symbol properties\ntype DeepCloned<T> = T extends readonly (infer U)[]\n ? DeepCloned<U>[]\n : T extends object\n ? { -readonly [K in keyof T & (string | number)]: DeepCloned<T[K]> }\n : T;\n\n/**\n * Standard JSON-RPC request properties.\n */\nexport const requestProps = ['jsonrpc', 'method', 'params', 'id'];\n\n/**\n * Make a JSON-RPC request from a legacy request. Clones the params to avoid\n * freezing them, which could cause errors in an involved legacy engine.\n *\n * @param req - The legacy request to make a request from.\n * @returns The JSON-RPC request.\n */\nexport function fromLegacyRequest<Request extends JsonRpcRequest>(\n req: Request,\n): Request {\n const request = {\n jsonrpc: '2.0' as const,\n method: req.method,\n } as Partial<Request>;\n request.id = req.id;\n if (hasProperty(req, 'params') && req.params !== undefined) {\n request.params = deepClone(req.params);\n }\n return request as Request;\n}\n\n/**\n * Make a middleware context from a legacy request by copying over all non-JSON-RPC\n * properties from the request to the context object.\n *\n * @param req - The legacy request to make a context from.\n * @returns The middleware context.\n */\nexport function makeContext<Request extends Record<string | symbol, unknown>>(\n req: Request,\n): MiddlewareContext {\n const context = new MiddlewareContext();\n propagateToContext(req, context);\n return context;\n}\n\n/**\n * Copies non-JSON-RPC string properties from the request to the context.\n *\n * For compatibility with our problematic practice of appending non-standard\n * fields to requests for inter-middleware communication in the legacy engine.\n *\n * **ATTN:** Only string properties that do not already exist in the context\n * are copied.\n *\n * @param req - The request to propagate the context from.\n * @param context - The context to propagate to.\n */\nexport function propagateToContext(\n req: Record<string, unknown>,\n context: MiddlewareContext<Record<string, unknown>>,\n) {\n Object.keys(req)\n .filter(\n (key) =>\n typeof key === 'string' &&\n !requestProps.includes(key) &&\n !context.has(key),\n )\n .forEach((key) => {\n context.set(key, req[key]);\n });\n}\n\n/**\n * Copies non-JSON-RPC string properties from the context to the request.\n *\n * For compatibility with our problematic practice of appending non-standard\n * fields to requests for inter-middleware communication in the legacy engine.\n *\n * **ATTN:** Only string properties are copied.\n *\n * @param req - The request to propagate the context to.\n * @param context - The context to propagate from.\n */\nexport function propagateToRequest(\n req: Record<string, unknown>,\n context: MiddlewareContext,\n) {\n Array.from(context.keys())\n .filter(\n ((key) => typeof key === 'string' && !requestProps.includes(key)) as (\n value: unknown,\n ) => value is string,\n )\n .forEach((key) => {\n req[key] = context.get(key);\n });\n}\n\n/**\n * Unserialize an error from a thrown value. Creates a {@link JsonRpcError} if\n * the thrown value is an object with a `code` property. Otherwise, creates a\n * plain {@link Error}.\n *\n * @param thrown - The thrown value to unserialize.\n * @returns The unserialized error.\n */\nexport function
|
|
1
|
+
{"version":3,"file":"compatibility-utils.cjs","sourceRoot":"","sources":["../../src/v2/compatibility-utils.ts"],"names":[],"mappings":";;;AAAA,qDAAwE;AAExE,2CAAwD;AACxD,sFAAsF;AACtF,iCAA8B;AAE9B,+DAAwD;AACxD,uCAAyD;AAEzD,oCAAoC;AAEpC;;;;;;;;;;GAUG;AACI,MAAM,SAAS,GAAG,CAAI,KAAQ,EAAiB,EAAE,CACtD,IAAA,aAAK,EAAC,KAAK,CAAkB,CAAC;AADnB,QAAA,SAAS,aACU;AAWhC;;GAEG;AACU,QAAA,YAAY,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AAElE;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,GAAY;IAEZ,MAAM,OAAO,GAAG;QACd,OAAO,EAAE,KAAc;QACvB,MAAM,EAAE,GAAG,CAAC,MAAM;KACC,CAAC;IACtB,OAAO,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC;IACpB,IAAI,IAAA,mBAAW,EAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE;QAC1D,OAAO,CAAC,MAAM,GAAG,IAAA,iBAAS,EAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KACxC;IACD,OAAO,OAAkB,CAAC;AAC5B,CAAC;AAZD,8CAYC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CACzB,GAAY;IAEZ,MAAM,OAAO,GAAG,IAAI,qCAAiB,EAAE,CAAC;IACxC,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,OAAO,CAAC;AACjB,CAAC;AAND,kCAMC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,kBAAkB,CAChC,GAA4B,EAC5B,OAAmD;IAEnD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;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AAO,IAAI,KAAK,CAAC,kBAAkB,IAAA,iBAAS,EAAC,MAAM,CAAC,EAAE,CAAC,CAAC;KACzD;IAED,MAAM,IAAI,GACR,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;QAC9D,CAAC,CAAC,MAAM,CAAC,IAAI;QACb,CAAC,CAAC,SAAS,CAAC;IAEhB,IAAI,OAAO,GAAG,eAAe,CAAC;IAC9B,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE;QACtC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;KAC1B;SAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QACnC,OAAO,GAAG,IAAA,+BAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;KAC7C;IAED,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAEtC,MAAM,KAAK,GACT,IAAI,KAAK,SAAS;QAChB,CAAC,CAAC,kEAAkE;YAClE,6DAA6D;YAC7D,2CAA2C;YAC3C,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC,IAAI,yBAAY,CAAC,IAAI,EAAE,OAAO,EAAE;YAC9B,GAAG,CAAC,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;YACtC,KAAK;SACN,CAAC,CAAC;IAET,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;KACrB;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AA/CD,4CA+CC","sourcesContent":["import { getMessageFromCode, JsonRpcError } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n// ATTN: We must NOT use 'klona/full' here because it freezes properties on the clone.\nimport { klona } from 'klona';\n\nimport { MiddlewareContext } from './MiddlewareContext';\nimport { stringify, type JsonRpcRequest } from './utils';\n\n// Legacy engine compatibility utils\n\n/**\n * Create a deep clone of a value as follows:\n * - Assumes acyclical objects\n * - Does not copy property descriptors (i.e. uses mutable defaults)\n * - Ignores non-enumerable properties\n * - Ignores getters and setters\n *\n * @throws If the value is an object with a circular reference.\n * @param value - The value to clone.\n * @returns The cloned value.\n */\nexport const deepClone = <T>(value: T): DeepCloned<T> =>\n klona(value) as DeepCloned<T>;\n\n// Matching the default implementation of klona, this type:\n// - Removes readonly modifiers\n// - Excludes non-enumerable / symbol properties\ntype DeepCloned<T> = T extends readonly (infer U)[]\n ? DeepCloned<U>[]\n : T extends object\n ? { -readonly [K in keyof T & (string | number)]: DeepCloned<T[K]> }\n : T;\n\n/**\n * Standard JSON-RPC request properties.\n */\nexport const requestProps = ['jsonrpc', 'method', 'params', 'id'];\n\n/**\n * Make a JSON-RPC request from a legacy request. Clones the params to avoid\n * freezing them, which could cause errors in an involved legacy engine.\n *\n * @param req - The legacy request to make a request from.\n * @returns The JSON-RPC request.\n */\nexport function fromLegacyRequest<Request extends JsonRpcRequest>(\n req: Request,\n): Request {\n const request = {\n jsonrpc: '2.0' as const,\n method: req.method,\n } as Partial<Request>;\n request.id = req.id;\n if (hasProperty(req, 'params') && req.params !== undefined) {\n request.params = deepClone(req.params);\n }\n return request as Request;\n}\n\n/**\n * Make a middleware context from a legacy request by copying over all non-JSON-RPC\n * properties from the request to the context object.\n *\n * @param req - The legacy request to make a context from.\n * @returns The middleware context.\n */\nexport function makeContext<Request extends Record<string | symbol, unknown>>(\n req: Request,\n): MiddlewareContext {\n const context = new MiddlewareContext();\n propagateToContext(req, context);\n return context;\n}\n\n/**\n * Copies non-JSON-RPC string properties from the request to the context.\n *\n * For compatibility with our problematic practice of appending non-standard\n * fields to requests for inter-middleware communication in the legacy engine.\n *\n * **ATTN:** Only string properties that do not already exist in the context\n * are copied.\n *\n * @param req - The request to propagate the context from.\n * @param context - The context to propagate to.\n */\nexport function propagateToContext(\n req: Record<string, unknown>,\n context: MiddlewareContext<Record<string, unknown>>,\n) {\n Object.keys(req)\n .filter(\n (key) =>\n typeof key === 'string' &&\n !requestProps.includes(key) &&\n !context.has(key),\n )\n .forEach((key) => {\n context.set(key, req[key]);\n });\n}\n\n/**\n * Copies non-JSON-RPC string properties from the context to the request.\n *\n * For compatibility with our problematic practice of appending non-standard\n * fields to requests for inter-middleware communication in the legacy engine.\n *\n * **ATTN:** Only string properties are copied.\n *\n * @param req - The request to propagate the context to.\n * @param context - The context to propagate from.\n */\nexport function propagateToRequest(\n req: Record<string, unknown>,\n context: MiddlewareContext,\n) {\n Array.from(context.keys())\n .filter(\n ((key) => typeof key === 'string' && !requestProps.includes(key)) as (\n value: unknown,\n ) => value is string,\n )\n .forEach((key) => {\n req[key] = context.get(key);\n });\n}\n\n/**\n * Unserialize an error from a thrown value. Creates a {@link JsonRpcError} if\n * the thrown value is an object with a `code` property. Otherwise, creates a\n * plain {@link Error}.\n *\n * @param thrown - The thrown value to unserialize.\n * @returns The unserialized error.\n */\nexport function deserializeError(thrown: unknown): Error | JsonRpcError<Json> {\n // @ts-expect-error - New, but preferred if available.\n // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError\n if (typeof Error.isError === 'function' && Error.isError(thrown)) {\n return thrown as Error;\n }\n // Unlike Error.isError, instanceof does not work for Errors from other realms.\n if (thrown instanceof Error) {\n return thrown;\n }\n if (typeof thrown === 'string') {\n return new Error(thrown);\n }\n if (!isObject(thrown)) {\n return new Error(`Unknown error: ${stringify(thrown)}`);\n }\n\n const code =\n typeof thrown.code === 'number' && Number.isInteger(thrown.code)\n ? thrown.code\n : undefined;\n\n let message = 'Unknown error';\n if (typeof thrown.message === 'string') {\n message = thrown.message;\n } else if (typeof code === 'number') {\n message = getMessageFromCode(code, message);\n }\n\n const { stack, cause, data } = thrown;\n\n const error =\n code === undefined\n ? // Jest complains if we use the `@ts-expect-error` directive here.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Our error type is outdated.\n new Error(message, { cause })\n : new JsonRpcError(code, message, {\n ...(isObject(data) ? data : undefined),\n cause,\n });\n\n if (typeof stack === 'string') {\n error.stack = stack;\n }\n\n return error;\n}\n"]}
|
|
@@ -70,6 +70,6 @@ export declare function propagateToRequest(req: Record<string, unknown>, context
|
|
|
70
70
|
* @param thrown - The thrown value to unserialize.
|
|
71
71
|
* @returns The unserialized error.
|
|
72
72
|
*/
|
|
73
|
-
export declare function
|
|
73
|
+
export declare function deserializeError(thrown: unknown): Error | JsonRpcError<Json>;
|
|
74
74
|
export {};
|
|
75
75
|
//# sourceMappingURL=compatibility-utils.d.cts.map
|
|
@@ -70,6 +70,6 @@ export declare function propagateToRequest(req: Record<string, unknown>, context
|
|
|
70
70
|
* @param thrown - The thrown value to unserialize.
|
|
71
71
|
* @returns The unserialized error.
|
|
72
72
|
*/
|
|
73
|
-
export declare function
|
|
73
|
+
export declare function deserializeError(thrown: unknown): Error | JsonRpcError<Json>;
|
|
74
74
|
export {};
|
|
75
75
|
//# sourceMappingURL=compatibility-utils.d.mts.map
|
|
@@ -98,7 +98,7 @@ export function propagateToRequest(req, context) {
|
|
|
98
98
|
* @param thrown - The thrown value to unserialize.
|
|
99
99
|
* @returns The unserialized error.
|
|
100
100
|
*/
|
|
101
|
-
export function
|
|
101
|
+
export function deserializeError(thrown) {
|
|
102
102
|
// @ts-expect-error - New, but preferred if available.
|
|
103
103
|
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError
|
|
104
104
|
if (typeof Error.isError === 'function' && Error.isError(thrown)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compatibility-utils.mjs","sourceRoot":"","sources":["../../src/v2/compatibility-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,6BAA6B;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OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;QAC9D,CAAC,CAAC,MAAM,CAAC,IAAI;QACb,CAAC,CAAC,SAAS,CAAC;IAEhB,IAAI,OAAO,GAAG,eAAe,CAAC;IAC9B,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE;QACtC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;KAC1B;SAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QACnC,OAAO,GAAG,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;KAC7C;IAED,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAEtC,MAAM,KAAK,GACT,IAAI,KAAK,SAAS;QAChB,CAAC,CAAC,kEAAkE;YAClE,6DAA6D;YAC7D,2CAA2C;YAC3C,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC,IAAI,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE;YAC9B,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;YACtC,KAAK;SACN,CAAC,CAAC;IAET,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;KACrB;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { getMessageFromCode, JsonRpcError } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n// ATTN: We must NOT use 'klona/full' here because it freezes properties on the clone.\nimport { klona } from 'klona';\n\nimport { MiddlewareContext } from './MiddlewareContext';\nimport { stringify, type JsonRpcRequest } from './utils';\n\n// Legacy engine compatibility utils\n\n/**\n * Create a deep clone of a value as follows:\n * - Assumes acyclical objects\n * - Does not copy property descriptors (i.e. uses mutable defaults)\n * - Ignores non-enumerable properties\n * - Ignores getters and setters\n *\n * @throws If the value is an object with a circular reference.\n * @param value - The value to clone.\n * @returns The cloned value.\n */\nexport const deepClone = <T>(value: T): DeepCloned<T> =>\n klona(value) as DeepCloned<T>;\n\n// Matching the default implementation of klona, this type:\n// - Removes readonly modifiers\n// - Excludes non-enumerable / symbol properties\ntype DeepCloned<T> = T extends readonly (infer U)[]\n ? DeepCloned<U>[]\n : T extends object\n ? { -readonly [K in keyof T & (string | number)]: DeepCloned<T[K]> }\n : T;\n\n/**\n * Standard JSON-RPC request properties.\n */\nexport const requestProps = ['jsonrpc', 'method', 'params', 'id'];\n\n/**\n * Make a JSON-RPC request from a legacy request. Clones the params to avoid\n * freezing them, which could cause errors in an involved legacy engine.\n *\n * @param req - The legacy request to make a request from.\n * @returns The JSON-RPC request.\n */\nexport function fromLegacyRequest<Request extends JsonRpcRequest>(\n req: Request,\n): Request {\n const request = {\n jsonrpc: '2.0' as const,\n method: req.method,\n } as Partial<Request>;\n request.id = req.id;\n if (hasProperty(req, 'params') && req.params !== undefined) {\n request.params = deepClone(req.params);\n }\n return request as Request;\n}\n\n/**\n * Make a middleware context from a legacy request by copying over all non-JSON-RPC\n * properties from the request to the context object.\n *\n * @param req - The legacy request to make a context from.\n * @returns The middleware context.\n */\nexport function makeContext<Request extends Record<string | symbol, unknown>>(\n req: Request,\n): MiddlewareContext {\n const context = new MiddlewareContext();\n propagateToContext(req, context);\n return context;\n}\n\n/**\n * Copies non-JSON-RPC string properties from the request to the context.\n *\n * For compatibility with our problematic practice of appending non-standard\n * fields to requests for inter-middleware communication in the legacy engine.\n *\n * **ATTN:** Only string properties that do not already exist in the context\n * are copied.\n *\n * @param req - The request to propagate the context from.\n * @param context - The context to propagate to.\n */\nexport function propagateToContext(\n req: Record<string, unknown>,\n context: MiddlewareContext<Record<string, unknown>>,\n) {\n Object.keys(req)\n .filter(\n (key) =>\n typeof key === 'string' &&\n !requestProps.includes(key) &&\n !context.has(key),\n )\n .forEach((key) => {\n context.set(key, req[key]);\n });\n}\n\n/**\n * Copies non-JSON-RPC string properties from the context to the request.\n *\n * For compatibility with our problematic practice of appending non-standard\n * fields to requests for inter-middleware communication in the legacy engine.\n *\n * **ATTN:** Only string properties are copied.\n *\n * @param req - The request to propagate the context to.\n * @param context - The context to propagate from.\n */\nexport function propagateToRequest(\n req: Record<string, unknown>,\n context: MiddlewareContext,\n) {\n Array.from(context.keys())\n .filter(\n ((key) => typeof key === 'string' && !requestProps.includes(key)) as (\n value: unknown,\n ) => value is string,\n )\n .forEach((key) => {\n req[key] = context.get(key);\n });\n}\n\n/**\n * Unserialize an error from a thrown value. Creates a {@link JsonRpcError} if\n * the thrown value is an object with a `code` property. Otherwise, creates a\n * plain {@link Error}.\n *\n * @param thrown - The thrown value to unserialize.\n * @returns The unserialized error.\n */\nexport function
|
|
1
|
+
{"version":3,"file":"compatibility-utils.mjs","sourceRoot":"","sources":["../../src/v2/compatibility-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,6BAA6B;AAExE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB;AACxD,sFAAsF;AACtF,OAAO,EAAE,KAAK,EAAE,cAAc;AAE9B,OAAO,EAAE,iBAAiB,EAAE,gCAA4B;AACxD,OAAO,EAAE,SAAS,EAAuB,oBAAgB;AAEzD,oCAAoC;AAEpC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAI,KAAQ,EAAiB,EAAE,CACtD,KAAK,CAAC,KAAK,CAAkB,CAAC;AAWhC;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AAElE;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,GAAY;IAEZ,MAAM,OAAO,GAAG;QACd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,SAAS;QAChB,CAAC,CAAC,kEAAkE;YAClE,6DAA6D;YAC7D,2CAA2C;YAC3C,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC,IAAI,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE;YAC9B,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;YACtC,KAAK;SACN,CAAC,CAAC;IAET,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;KACrB;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { getMessageFromCode, JsonRpcError } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n// ATTN: We must NOT use 'klona/full' here because it freezes properties on the clone.\nimport { klona } from 'klona';\n\nimport { MiddlewareContext } from './MiddlewareContext';\nimport { stringify, type JsonRpcRequest } from './utils';\n\n// Legacy engine compatibility utils\n\n/**\n * Create a deep clone of a value as follows:\n * - Assumes acyclical objects\n * - Does not copy property descriptors (i.e. uses mutable defaults)\n * - Ignores non-enumerable properties\n * - Ignores getters and setters\n *\n * @throws If the value is an object with a circular reference.\n * @param value - The value to clone.\n * @returns The cloned value.\n */\nexport const deepClone = <T>(value: T): DeepCloned<T> =>\n klona(value) as DeepCloned<T>;\n\n// Matching the default implementation of klona, this type:\n// - Removes readonly modifiers\n// - Excludes non-enumerable / symbol properties\ntype DeepCloned<T> = T extends readonly (infer U)[]\n ? DeepCloned<U>[]\n : T extends object\n ? { -readonly [K in keyof T & (string | number)]: DeepCloned<T[K]> }\n : T;\n\n/**\n * Standard JSON-RPC request properties.\n */\nexport const requestProps = ['jsonrpc', 'method', 'params', 'id'];\n\n/**\n * Make a JSON-RPC request from a legacy request. Clones the params to avoid\n * freezing them, which could cause errors in an involved legacy engine.\n *\n * @param req - The legacy request to make a request from.\n * @returns The JSON-RPC request.\n */\nexport function fromLegacyRequest<Request extends JsonRpcRequest>(\n req: Request,\n): Request {\n const request = {\n jsonrpc: '2.0' as const,\n method: req.method,\n } as Partial<Request>;\n request.id = req.id;\n if (hasProperty(req, 'params') && req.params !== undefined) {\n request.params = deepClone(req.params);\n }\n return request as Request;\n}\n\n/**\n * Make a middleware context from a legacy request by copying over all non-JSON-RPC\n * properties from the request to the context object.\n *\n * @param req - The legacy request to make a context from.\n * @returns The middleware context.\n */\nexport function makeContext<Request extends Record<string | symbol, unknown>>(\n req: Request,\n): MiddlewareContext {\n const context = new MiddlewareContext();\n propagateToContext(req, context);\n return context;\n}\n\n/**\n * Copies non-JSON-RPC string properties from the request to the context.\n *\n * For compatibility with our problematic practice of appending non-standard\n * fields to requests for inter-middleware communication in the legacy engine.\n *\n * **ATTN:** Only string properties that do not already exist in the context\n * are copied.\n *\n * @param req - The request to propagate the context from.\n * @param context - The context to propagate to.\n */\nexport function propagateToContext(\n req: Record<string, unknown>,\n context: MiddlewareContext<Record<string, unknown>>,\n) {\n Object.keys(req)\n .filter(\n (key) =>\n typeof key === 'string' &&\n !requestProps.includes(key) &&\n !context.has(key),\n )\n .forEach((key) => {\n context.set(key, req[key]);\n });\n}\n\n/**\n * Copies non-JSON-RPC string properties from the context to the request.\n *\n * For compatibility with our problematic practice of appending non-standard\n * fields to requests for inter-middleware communication in the legacy engine.\n *\n * **ATTN:** Only string properties are copied.\n *\n * @param req - The request to propagate the context to.\n * @param context - The context to propagate from.\n */\nexport function propagateToRequest(\n req: Record<string, unknown>,\n context: MiddlewareContext,\n) {\n Array.from(context.keys())\n .filter(\n ((key) => typeof key === 'string' && !requestProps.includes(key)) as (\n value: unknown,\n ) => value is string,\n )\n .forEach((key) => {\n req[key] = context.get(key);\n });\n}\n\n/**\n * Unserialize an error from a thrown value. Creates a {@link JsonRpcError} if\n * the thrown value is an object with a `code` property. Otherwise, creates a\n * plain {@link Error}.\n *\n * @param thrown - The thrown value to unserialize.\n * @returns The unserialized error.\n */\nexport function deserializeError(thrown: unknown): Error | JsonRpcError<Json> {\n // @ts-expect-error - New, but preferred if available.\n // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError\n if (typeof Error.isError === 'function' && Error.isError(thrown)) {\n return thrown as Error;\n }\n // Unlike Error.isError, instanceof does not work for Errors from other realms.\n if (thrown instanceof Error) {\n return thrown;\n }\n if (typeof thrown === 'string') {\n return new Error(thrown);\n }\n if (!isObject(thrown)) {\n return new Error(`Unknown error: ${stringify(thrown)}`);\n }\n\n const code =\n typeof thrown.code === 'number' && Number.isInteger(thrown.code)\n ? thrown.code\n : undefined;\n\n let message = 'Unknown error';\n if (typeof thrown.message === 'string') {\n message = thrown.message;\n } else if (typeof code === 'number') {\n message = getMessageFromCode(code, message);\n }\n\n const { stack, cause, data } = thrown;\n\n const error =\n code === undefined\n ? // Jest complains if we use the `@ts-expect-error` directive here.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Our error type is outdated.\n new Error(message, { cause })\n : new JsonRpcError(code, message, {\n ...(isObject(data) ? data : undefined),\n cause,\n });\n\n if (typeof stack === 'string') {\n error.stack = stack;\n }\n\n return error;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createScaffoldMiddleware.cjs","sourceRoot":"","sources":["../../src/v2/createScaffoldMiddleware.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"createScaffoldMiddleware.cjs","sourceRoot":"","sources":["../../src/v2/createScaffoldMiddleware.ts"],"names":[],"mappings":";;;AA+BA;;;;;;;;GAQG;AACH,SAAgB,wBAAwB,CACtC,QAAqC;IAErC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;QACpC,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACjD,IAAI,eAAe,KAAK,SAAS,EAAE;YACjC,OAAO,IAAI,EAAE,CAAC;SACf;QAED,OAAO,OAAO,eAAe,KAAK,UAAU;YAC1C,CAAC,CAAC,eAAe,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YAC7C,CAAC,CAAC,eAAe,CAAC;IACtB,CAAC,CAAC;AACJ,CAAC;AAbD,4DAaC","sourcesContent":["import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nimport type { JsonRpcMiddleware } from './JsonRpcEngineV2';\nimport type { ContextConstraint } from './MiddlewareContext';\n\n// Only permit primitive values as hard-coded scaffold middleware results.\ntype JsonPrimitive = string | number | boolean | null;\n\n/**\n * A handler for a scaffold middleware function.\n *\n * @template Params - The parameters of the request.\n * @template Result - The result of the request.\n * @template Context - The context of the request.\n * @returns A JSON-RPC middleware function or a primitive JSON value.\n */\nexport type ScaffoldMiddlewareHandler<\n Params extends JsonRpcParams,\n Result extends Json,\n Context extends ContextConstraint,\n> = JsonRpcMiddleware<JsonRpcRequest<Params>, Result, Context> | JsonPrimitive;\n\n/**\n * A record of RPC method handler functions or hard-coded results, keyed to particular method names.\n * Only primitive JSON values are permitted as hard-coded results.\n */\nexport type MiddlewareScaffold<Context extends ContextConstraint> = Record<\n string,\n ScaffoldMiddlewareHandler<JsonRpcParams, Json, Context>\n>;\n\n/**\n * Creates a middleware function from an object of RPC method handler functions,\n * keyed to particular method names. If a method corresponding to a key of this\n * object is requested, this middleware will pass it to the corresponding\n * handler and return the result.\n *\n * @param handlers - The RPC method handler functions.\n * @returns The scaffold middleware function.\n */\nexport function createScaffoldMiddleware<Context extends ContextConstraint>(\n handlers: MiddlewareScaffold<Context>,\n): JsonRpcMiddleware<JsonRpcRequest, Json, Context> {\n return ({ request, context, next }) => {\n const handlerOrResult = handlers[request.method];\n if (handlerOrResult === undefined) {\n return next();\n }\n\n return typeof handlerOrResult === 'function'\n ? handlerOrResult({ request, context, next })\n : handlerOrResult;\n };\n}\n"]}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import type { Json, JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
|
|
2
2
|
import type { JsonRpcMiddleware } from "./JsonRpcEngineV2.cjs";
|
|
3
|
+
import type { ContextConstraint } from "./MiddlewareContext.cjs";
|
|
3
4
|
type JsonPrimitive = string | number | boolean | null;
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* A handler for a scaffold middleware function.
|
|
7
|
+
*
|
|
8
|
+
* @template Params - The parameters of the request.
|
|
9
|
+
* @template Result - The result of the request.
|
|
10
|
+
* @template Context - The context of the request.
|
|
11
|
+
* @returns A JSON-RPC middleware function or a primitive JSON value.
|
|
12
|
+
*/
|
|
13
|
+
export type ScaffoldMiddlewareHandler<Params extends JsonRpcParams, Result extends Json, Context extends ContextConstraint> = JsonRpcMiddleware<JsonRpcRequest<Params>, Result, Context> | JsonPrimitive;
|
|
5
14
|
/**
|
|
6
15
|
* A record of RPC method handler functions or hard-coded results, keyed to particular method names.
|
|
7
16
|
* Only primitive JSON values are permitted as hard-coded results.
|
|
8
17
|
*/
|
|
9
|
-
export type MiddlewareScaffold = Record<string, ScaffoldMiddlewareHandler<JsonRpcParams, Json>>;
|
|
18
|
+
export type MiddlewareScaffold<Context extends ContextConstraint> = Record<string, ScaffoldMiddlewareHandler<JsonRpcParams, Json, Context>>;
|
|
10
19
|
/**
|
|
11
20
|
* Creates a middleware function from an object of RPC method handler functions,
|
|
12
21
|
* keyed to particular method names. If a method corresponding to a key of this
|
|
@@ -16,6 +25,6 @@ export type MiddlewareScaffold = Record<string, ScaffoldMiddlewareHandler<JsonRp
|
|
|
16
25
|
* @param handlers - The RPC method handler functions.
|
|
17
26
|
* @returns The scaffold middleware function.
|
|
18
27
|
*/
|
|
19
|
-
export declare function createScaffoldMiddleware(handlers: MiddlewareScaffold): JsonRpcMiddleware<JsonRpcRequest, Json>;
|
|
28
|
+
export declare function createScaffoldMiddleware<Context extends ContextConstraint>(handlers: MiddlewareScaffold<Context>): JsonRpcMiddleware<JsonRpcRequest, Json, Context>;
|
|
20
29
|
export {};
|
|
21
30
|
//# sourceMappingURL=createScaffoldMiddleware.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createScaffoldMiddleware.d.cts","sourceRoot":"","sources":["../../src/v2/createScaffoldMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB;AAE3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,8BAA0B;
|
|
1
|
+
{"version":3,"file":"createScaffoldMiddleware.d.cts","sourceRoot":"","sources":["../../src/v2/createScaffoldMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB;AAE3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,8BAA0B;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAG7D,KAAK,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,MAAM,yBAAyB,CACnC,MAAM,SAAS,aAAa,EAC5B,MAAM,SAAS,IAAI,EACnB,OAAO,SAAS,iBAAiB,IAC/B,iBAAiB,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC;AAE/E;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,OAAO,SAAS,iBAAiB,IAAI,MAAM,CACxE,MAAM,EACN,yBAAyB,CAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CACxD,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,SAAS,iBAAiB,EACxE,QAAQ,EAAE,kBAAkB,CAAC,OAAO,CAAC,GACpC,iBAAiB,CAAC,cAAc,EAAE,IAAI,EAAE,OAAO,CAAC,CAWlD"}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import type { Json, JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
|
|
2
2
|
import type { JsonRpcMiddleware } from "./JsonRpcEngineV2.mjs";
|
|
3
|
+
import type { ContextConstraint } from "./MiddlewareContext.mjs";
|
|
3
4
|
type JsonPrimitive = string | number | boolean | null;
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* A handler for a scaffold middleware function.
|
|
7
|
+
*
|
|
8
|
+
* @template Params - The parameters of the request.
|
|
9
|
+
* @template Result - The result of the request.
|
|
10
|
+
* @template Context - The context of the request.
|
|
11
|
+
* @returns A JSON-RPC middleware function or a primitive JSON value.
|
|
12
|
+
*/
|
|
13
|
+
export type ScaffoldMiddlewareHandler<Params extends JsonRpcParams, Result extends Json, Context extends ContextConstraint> = JsonRpcMiddleware<JsonRpcRequest<Params>, Result, Context> | JsonPrimitive;
|
|
5
14
|
/**
|
|
6
15
|
* A record of RPC method handler functions or hard-coded results, keyed to particular method names.
|
|
7
16
|
* Only primitive JSON values are permitted as hard-coded results.
|
|
8
17
|
*/
|
|
9
|
-
export type MiddlewareScaffold = Record<string, ScaffoldMiddlewareHandler<JsonRpcParams, Json>>;
|
|
18
|
+
export type MiddlewareScaffold<Context extends ContextConstraint> = Record<string, ScaffoldMiddlewareHandler<JsonRpcParams, Json, Context>>;
|
|
10
19
|
/**
|
|
11
20
|
* Creates a middleware function from an object of RPC method handler functions,
|
|
12
21
|
* keyed to particular method names. If a method corresponding to a key of this
|
|
@@ -16,6 +25,6 @@ export type MiddlewareScaffold = Record<string, ScaffoldMiddlewareHandler<JsonRp
|
|
|
16
25
|
* @param handlers - The RPC method handler functions.
|
|
17
26
|
* @returns The scaffold middleware function.
|
|
18
27
|
*/
|
|
19
|
-
export declare function createScaffoldMiddleware(handlers: MiddlewareScaffold): JsonRpcMiddleware<JsonRpcRequest, Json>;
|
|
28
|
+
export declare function createScaffoldMiddleware<Context extends ContextConstraint>(handlers: MiddlewareScaffold<Context>): JsonRpcMiddleware<JsonRpcRequest, Json, Context>;
|
|
20
29
|
export {};
|
|
21
30
|
//# sourceMappingURL=createScaffoldMiddleware.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createScaffoldMiddleware.d.mts","sourceRoot":"","sources":["../../src/v2/createScaffoldMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB;AAE3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,8BAA0B;
|
|
1
|
+
{"version":3,"file":"createScaffoldMiddleware.d.mts","sourceRoot":"","sources":["../../src/v2/createScaffoldMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB;AAE3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,8BAA0B;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAG7D,KAAK,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,MAAM,yBAAyB,CACnC,MAAM,SAAS,aAAa,EAC5B,MAAM,SAAS,IAAI,EACnB,OAAO,SAAS,iBAAiB,IAC/B,iBAAiB,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC;AAE/E;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,OAAO,SAAS,iBAAiB,IAAI,MAAM,CACxE,MAAM,EACN,yBAAyB,CAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CACxD,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,SAAS,iBAAiB,EACxE,QAAQ,EAAE,kBAAkB,CAAC,OAAO,CAAC,GACpC,iBAAiB,CAAC,cAAc,EAAE,IAAI,EAAE,OAAO,CAAC,CAWlD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createScaffoldMiddleware.mjs","sourceRoot":"","sources":["../../src/v2/createScaffoldMiddleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createScaffoldMiddleware.mjs","sourceRoot":"","sources":["../../src/v2/createScaffoldMiddleware.ts"],"names":[],"mappings":"AA+BA;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAAqC;IAErC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;QACpC,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACjD,IAAI,eAAe,KAAK,SAAS,EAAE;YACjC,OAAO,IAAI,EAAE,CAAC;SACf;QAED,OAAO,OAAO,eAAe,KAAK,UAAU;YAC1C,CAAC,CAAC,eAAe,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YAC7C,CAAC,CAAC,eAAe,CAAC;IACtB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nimport type { JsonRpcMiddleware } from './JsonRpcEngineV2';\nimport type { ContextConstraint } from './MiddlewareContext';\n\n// Only permit primitive values as hard-coded scaffold middleware results.\ntype JsonPrimitive = string | number | boolean | null;\n\n/**\n * A handler for a scaffold middleware function.\n *\n * @template Params - The parameters of the request.\n * @template Result - The result of the request.\n * @template Context - The context of the request.\n * @returns A JSON-RPC middleware function or a primitive JSON value.\n */\nexport type ScaffoldMiddlewareHandler<\n Params extends JsonRpcParams,\n Result extends Json,\n Context extends ContextConstraint,\n> = JsonRpcMiddleware<JsonRpcRequest<Params>, Result, Context> | JsonPrimitive;\n\n/**\n * A record of RPC method handler functions or hard-coded results, keyed to particular method names.\n * Only primitive JSON values are permitted as hard-coded results.\n */\nexport type MiddlewareScaffold<Context extends ContextConstraint> = Record<\n string,\n ScaffoldMiddlewareHandler<JsonRpcParams, Json, Context>\n>;\n\n/**\n * Creates a middleware function from an object of RPC method handler functions,\n * keyed to particular method names. If a method corresponding to a key of this\n * object is requested, this middleware will pass it to the corresponding\n * handler and return the result.\n *\n * @param handlers - The RPC method handler functions.\n * @returns The scaffold middleware function.\n */\nexport function createScaffoldMiddleware<Context extends ContextConstraint>(\n handlers: MiddlewareScaffold<Context>,\n): JsonRpcMiddleware<JsonRpcRequest, Json, Context> {\n return ({ request, context, next }) => {\n const handlerOrResult = handlers[request.method];\n if (handlerOrResult === undefined) {\n return next();\n }\n\n return typeof handlerOrResult === 'function'\n ? handlerOrResult({ request, context, next })\n : handlerOrResult;\n };\n}\n"]}
|
package/dist/v2/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,kDAA6C;AAApC,0GAAA,WAAW,OAAA;AACpB,2EAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AACjC,yDAAoD;AAA3C,kHAAA,eAAe,OAAA;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,kDAA6C;AAApC,0GAAA,WAAW,OAAA;AACpB,2EAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AACjC,yDAAoD;AAA3C,kHAAA,eAAe,OAAA;AAWxB,qDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,6DAAwD;AAA/C,sHAAA,iBAAiB,OAAA;AAE1B,qCAAwE;AAA/D,uGAAA,cAAc,OAAA;AAAE,kGAAA,SAAS,OAAA;AAAE,2GAAA,kBAAkB,OAAA","sourcesContent":["export { asLegacyMiddleware } from './asLegacyMiddleware';\nexport { getUniqueId } from '../getUniqueId';\nexport { createScaffoldMiddleware } from './createScaffoldMiddleware';\nexport { JsonRpcEngineV2 } from './JsonRpcEngineV2';\nexport type {\n JsonRpcMiddleware,\n HandleOptions,\n MergedContextOf,\n MiddlewareParams,\n MiddlewareConstraint,\n Next,\n RequestOf,\n ResultConstraint,\n} from './JsonRpcEngineV2';\nexport { JsonRpcServer } from './JsonRpcServer';\nexport { MiddlewareContext } from './MiddlewareContext';\nexport type { EmptyContext, ContextConstraint } from './MiddlewareContext';\nexport { isNotification, isRequest, JsonRpcEngineError } from './utils';\nexport type {\n Json,\n JsonRpcCall,\n JsonRpcNotification,\n JsonRpcParams,\n JsonRpcRequest,\n} from './utils';\n"]}
|
package/dist/v2/index.d.cts
CHANGED
|
@@ -2,10 +2,10 @@ export { asLegacyMiddleware } from "./asLegacyMiddleware.cjs";
|
|
|
2
2
|
export { getUniqueId } from "../getUniqueId.cjs";
|
|
3
3
|
export { createScaffoldMiddleware } from "./createScaffoldMiddleware.cjs";
|
|
4
4
|
export { JsonRpcEngineV2 } from "./JsonRpcEngineV2.cjs";
|
|
5
|
-
export type { JsonRpcMiddleware, MiddlewareParams, Next, ResultConstraint, } from "./JsonRpcEngineV2.cjs";
|
|
5
|
+
export type { JsonRpcMiddleware, HandleOptions, MergedContextOf, MiddlewareParams, MiddlewareConstraint, Next, RequestOf, ResultConstraint, } from "./JsonRpcEngineV2.cjs";
|
|
6
6
|
export { JsonRpcServer } from "./JsonRpcServer.cjs";
|
|
7
7
|
export { MiddlewareContext } from "./MiddlewareContext.cjs";
|
|
8
|
-
export type { EmptyContext } from "./MiddlewareContext.cjs";
|
|
8
|
+
export type { EmptyContext, ContextConstraint } from "./MiddlewareContext.cjs";
|
|
9
9
|
export { isNotification, isRequest, JsonRpcEngineError } from "./utils.cjs";
|
|
10
10
|
export type { Json, JsonRpcCall, JsonRpcNotification, JsonRpcParams, JsonRpcRequest, } from "./utils.cjs";
|
|
11
11
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/v2/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B;AAC1D,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAC7C,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AACtE,OAAO,EAAE,eAAe,EAAE,8BAA0B;AACpD,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,IAAI,EACJ,gBAAgB,GACjB,8BAA0B;AAC3B,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAChD,OAAO,EAAE,iBAAiB,EAAE,gCAA4B;AACxD,YAAY,EAAE,YAAY,EAAE,gCAA4B;
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B;AAC1D,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAC7C,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AACtE,OAAO,EAAE,eAAe,EAAE,8BAA0B;AACpD,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,IAAI,EACJ,SAAS,EACT,gBAAgB,GACjB,8BAA0B;AAC3B,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAChD,OAAO,EAAE,iBAAiB,EAAE,gCAA4B;AACxD,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,gCAA4B;AAC3E,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,kBAAkB,EAAE,oBAAgB;AACxE,YAAY,EACV,IAAI,EACJ,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,cAAc,GACf,oBAAgB"}
|
package/dist/v2/index.d.mts
CHANGED
|
@@ -2,10 +2,10 @@ export { asLegacyMiddleware } from "./asLegacyMiddleware.mjs";
|
|
|
2
2
|
export { getUniqueId } from "../getUniqueId.mjs";
|
|
3
3
|
export { createScaffoldMiddleware } from "./createScaffoldMiddleware.mjs";
|
|
4
4
|
export { JsonRpcEngineV2 } from "./JsonRpcEngineV2.mjs";
|
|
5
|
-
export type { JsonRpcMiddleware, MiddlewareParams, Next, ResultConstraint, } from "./JsonRpcEngineV2.mjs";
|
|
5
|
+
export type { JsonRpcMiddleware, HandleOptions, MergedContextOf, MiddlewareParams, MiddlewareConstraint, Next, RequestOf, ResultConstraint, } from "./JsonRpcEngineV2.mjs";
|
|
6
6
|
export { JsonRpcServer } from "./JsonRpcServer.mjs";
|
|
7
7
|
export { MiddlewareContext } from "./MiddlewareContext.mjs";
|
|
8
|
-
export type { EmptyContext } from "./MiddlewareContext.mjs";
|
|
8
|
+
export type { EmptyContext, ContextConstraint } from "./MiddlewareContext.mjs";
|
|
9
9
|
export { isNotification, isRequest, JsonRpcEngineError } from "./utils.mjs";
|
|
10
10
|
export type { Json, JsonRpcCall, JsonRpcNotification, JsonRpcParams, JsonRpcRequest, } from "./utils.mjs";
|
|
11
11
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/v2/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B;AAC1D,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAC7C,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AACtE,OAAO,EAAE,eAAe,EAAE,8BAA0B;AACpD,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,IAAI,EACJ,gBAAgB,GACjB,8BAA0B;AAC3B,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAChD,OAAO,EAAE,iBAAiB,EAAE,gCAA4B;AACxD,YAAY,EAAE,YAAY,EAAE,gCAA4B;
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B;AAC1D,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAC7C,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AACtE,OAAO,EAAE,eAAe,EAAE,8BAA0B;AACpD,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,IAAI,EACJ,SAAS,EACT,gBAAgB,GACjB,8BAA0B;AAC3B,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAChD,OAAO,EAAE,iBAAiB,EAAE,gCAA4B;AACxD,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,gCAA4B;AAC3E,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,kBAAkB,EAAE,oBAAgB;AACxE,YAAY,EACV,IAAI,EACJ,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,cAAc,GACf,oBAAgB"}
|
package/dist/v2/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B;AAC1D,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAC7C,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AACtE,OAAO,EAAE,eAAe,EAAE,8BAA0B;
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B;AAC1D,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAC7C,OAAO,EAAE,wBAAwB,EAAE,uCAAmC;AACtE,OAAO,EAAE,eAAe,EAAE,8BAA0B;AAWpD,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAChD,OAAO,EAAE,iBAAiB,EAAE,gCAA4B;AAExD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,kBAAkB,EAAE,oBAAgB","sourcesContent":["export { asLegacyMiddleware } from './asLegacyMiddleware';\nexport { getUniqueId } from '../getUniqueId';\nexport { createScaffoldMiddleware } from './createScaffoldMiddleware';\nexport { JsonRpcEngineV2 } from './JsonRpcEngineV2';\nexport type {\n JsonRpcMiddleware,\n HandleOptions,\n MergedContextOf,\n MiddlewareParams,\n MiddlewareConstraint,\n Next,\n RequestOf,\n ResultConstraint,\n} from './JsonRpcEngineV2';\nexport { JsonRpcServer } from './JsonRpcServer';\nexport { MiddlewareContext } from './MiddlewareContext';\nexport type { EmptyContext, ContextConstraint } from './MiddlewareContext';\nexport { isNotification, isRequest, JsonRpcEngineError } from './utils';\nexport type {\n Json,\n JsonRpcCall,\n JsonRpcNotification,\n JsonRpcParams,\n JsonRpcRequest,\n} from './utils';\n"]}
|
package/dist/v2/utils.cjs
CHANGED
|
@@ -17,7 +17,7 @@ function stringify(value) {
|
|
|
17
17
|
return JSON.stringify(value, null, 2);
|
|
18
18
|
}
|
|
19
19
|
exports.stringify = stringify;
|
|
20
|
-
const JsonRpcEngineErrorSymbol = Symbol.for('JsonRpcEngineError');
|
|
20
|
+
const JsonRpcEngineErrorSymbol = Symbol.for('json-rpc-engine#JsonRpcEngineError');
|
|
21
21
|
class JsonRpcEngineError extends Error {
|
|
22
22
|
constructor(message) {
|
|
23
23
|
super(message);
|
|
@@ -32,7 +32,7 @@ class JsonRpcEngineError extends Error {
|
|
|
32
32
|
* @returns Whether the value is a {@link JsonRpcEngineError} instance.
|
|
33
33
|
*/
|
|
34
34
|
static isInstance(value) {
|
|
35
|
-
return (
|
|
35
|
+
return (JsonRpcEngineErrorSymbol in value &&
|
|
36
36
|
value[JsonRpcEngineErrorSymbol] === true);
|
|
37
37
|
}
|
|
38
38
|
}
|
package/dist/v2/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../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oBAAoB,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CACf,KAAY;QAEZ,OAAO,CACL,wBAAwB,IAAI,KAAK;YACjC,KAAK,CAAC,wBAAwB,CAAC,KAAK,IAAI,CACzC,CAAC;IACJ,CAAC;CACF;AAvBD,gDAuBC;KAtBmB,wBAAwB","sourcesContent":["import {\n hasProperty,\n type JsonRpcNotification,\n type JsonRpcParams,\n type JsonRpcRequest,\n} from '@metamask/utils';\n\nexport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcNotification,\n} from '@metamask/utils';\n\nexport type JsonRpcCall<Params extends JsonRpcParams = JsonRpcParams> =\n | JsonRpcNotification<Params>\n | JsonRpcRequest<Params>;\n\nexport const isRequest = <Params extends JsonRpcParams>(\n msg: JsonRpcCall<Params> | Readonly<JsonRpcCall<Params>>,\n): msg is JsonRpcRequest<Params> => hasProperty(msg, 'id');\n\nexport const isNotification = <Params extends JsonRpcParams>(\n msg: JsonRpcCall<Params>,\n): msg is JsonRpcNotification<Params> => !isRequest(msg);\n\n/**\n * An unholy incantation that converts a union of object types into an\n * intersection of object types.\n *\n * @example\n * type A = { a: string } | { b: number };\n * type B = UnionToIntersection<A>; // { a: string } & { b: number }\n */\nexport type UnionToIntersection<U> = (\n U extends never ? never : (k: U) => void\n) extends (k: infer I) => void\n ? I\n : never;\n\n/**\n * JSON-stringifies a value.\n *\n * @param value - The value to stringify.\n * @returns The stringified value.\n */\nexport function stringify(value: unknown): string {\n return JSON.stringify(value, null, 2);\n}\n\nconst JsonRpcEngineErrorSymbol = Symbol.for(\n 'json-rpc-engine#JsonRpcEngineError',\n);\n\nexport class JsonRpcEngineError extends Error {\n private readonly [JsonRpcEngineErrorSymbol] = true;\n\n constructor(message: string) {\n super(message);\n this.name = 'JsonRpcEngineError';\n }\n\n /**\n * Check if a value is a {@link JsonRpcEngineError} instance.\n * Works across different package versions in the same realm.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link JsonRpcEngineError} instance.\n */\n static isInstance<Value extends Error>(\n value: Value,\n ): value is Value & JsonRpcEngineError {\n return (\n JsonRpcEngineErrorSymbol in value &&\n value[JsonRpcEngineErrorSymbol] === true\n );\n }\n}\n"]}
|
package/dist/v2/utils.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,wBAAwB;AAEzB,YAAY,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,mBAAmB,GACpB,wBAAwB;AAEzB,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa,IAChE,mBAAmB,CAAC,MAAM,CAAC,GAC3B,cAAc,CAAC,MAAM,CAAC,CAAC;AAE3B,eAAO,MAAM,SAAS,2HAEoC,CAAC;AAE3D,eAAO,MAAM,cAAc,gGAE6B,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CACnC,CAAC,SAAS,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CACzC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,GAC1B,CAAC,GACD,KAAK,CAAC;AAEV;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED,QAAA,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,wBAAwB;AAEzB,YAAY,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,mBAAmB,GACpB,wBAAwB;AAEzB,MAAM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,OAAO,CAAC,QAAQ,CAAC,CAAC,wBAAwB,CAAC,CAAQ;gBAEvC,OAAO,EAAE,MAAM;IAK3B;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,SAAS,KAAK,EACnC,KAAK,EAAE,KAAK,GACX,KAAK,IAAI,KAAK,GAAG,kBAAkB;CAMvC"}
|
package/dist/v2/utils.mjs
CHANGED
|
@@ -11,7 +11,7 @@ export const isNotification = (msg) => !isRequest(msg);
|
|
|
11
11
|
export function stringify(value) {
|
|
12
12
|
return JSON.stringify(value, null, 2);
|
|
13
13
|
}
|
|
14
|
-
const JsonRpcEngineErrorSymbol = Symbol.for('JsonRpcEngineError');
|
|
14
|
+
const JsonRpcEngineErrorSymbol = Symbol.for('json-rpc-engine#JsonRpcEngineError');
|
|
15
15
|
export class JsonRpcEngineError extends Error {
|
|
16
16
|
constructor(message) {
|
|
17
17
|
super(message);
|
|
@@ -26,7 +26,7 @@ export class JsonRpcEngineError extends Error {
|
|
|
26
26
|
* @returns Whether the value is a {@link JsonRpcEngineError} instance.
|
|
27
27
|
*/
|
|
28
28
|
static isInstance(value) {
|
|
29
|
-
return (
|
|
29
|
+
return (JsonRpcEngineErrorSymbol in value &&
|
|
30
30
|
value[JsonRpcEngineErrorSymbol] === true);
|
|
31
31
|
}
|
|
32
32
|
}
|
package/dist/v2/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,WAAW,EAIZ,wBAAwB;AAazB,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,GAAwD,EACzB,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAE3D,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,GAAwB,EACY,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AAgBzD;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,wBAAwB,GAAG,MAAM,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,WAAW,EAIZ,wBAAwB;AAazB,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,GAAwD,EACzB,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAE3D,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,GAAwB,EACY,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AAgBzD;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,wBAAwB,GAAG,MAAM,CAAC,GAAG,CACzC,oCAAoC,CACrC,CAAC;AAEF,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAG3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHA,QAA0B,GAAG,IAAI,CAAC;QAIjD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CACf,KAAY;QAEZ,OAAO,CACL,wBAAwB,IAAI,KAAK;YACjC,KAAK,CAAC,wBAAwB,CAAC,KAAK,IAAI,CACzC,CAAC;IACJ,CAAC;CACF;KAtBmB,wBAAwB","sourcesContent":["import {\n hasProperty,\n type JsonRpcNotification,\n type JsonRpcParams,\n type JsonRpcRequest,\n} from '@metamask/utils';\n\nexport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcNotification,\n} from '@metamask/utils';\n\nexport type JsonRpcCall<Params extends JsonRpcParams = JsonRpcParams> =\n | JsonRpcNotification<Params>\n | JsonRpcRequest<Params>;\n\nexport const isRequest = <Params extends JsonRpcParams>(\n msg: JsonRpcCall<Params> | Readonly<JsonRpcCall<Params>>,\n): msg is JsonRpcRequest<Params> => hasProperty(msg, 'id');\n\nexport const isNotification = <Params extends JsonRpcParams>(\n msg: JsonRpcCall<Params>,\n): msg is JsonRpcNotification<Params> => !isRequest(msg);\n\n/**\n * An unholy incantation that converts a union of object types into an\n * intersection of object types.\n *\n * @example\n * type A = { a: string } | { b: number };\n * type B = UnionToIntersection<A>; // { a: string } & { b: number }\n */\nexport type UnionToIntersection<U> = (\n U extends never ? never : (k: U) => void\n) extends (k: infer I) => void\n ? I\n : never;\n\n/**\n * JSON-stringifies a value.\n *\n * @param value - The value to stringify.\n * @returns The stringified value.\n */\nexport function stringify(value: unknown): string {\n return JSON.stringify(value, null, 2);\n}\n\nconst JsonRpcEngineErrorSymbol = Symbol.for(\n 'json-rpc-engine#JsonRpcEngineError',\n);\n\nexport class JsonRpcEngineError extends Error {\n private readonly [JsonRpcEngineErrorSymbol] = true;\n\n constructor(message: string) {\n super(message);\n this.name = 'JsonRpcEngineError';\n }\n\n /**\n * Check if a value is a {@link JsonRpcEngineError} instance.\n * Works across different package versions in the same realm.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link JsonRpcEngineError} instance.\n */\n static isInstance<Value extends Error>(\n value: Value,\n ): value is Value & JsonRpcEngineError {\n return (\n JsonRpcEngineErrorSymbol in value &&\n value[JsonRpcEngineErrorSymbol] === true\n );\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/json-rpc-engine",
|
|
3
|
-
"version": "10.1.1-preview-
|
|
3
|
+
"version": "10.1.1-preview-c96ff8f",
|
|
4
4
|
"description": "A tool for processing JSON-RPC messages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
],
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
53
|
+
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
|
|
53
54
|
"build:docs": "typedoc",
|
|
54
55
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/json-rpc-engine --tag-prefix-before-package-rename json-rpc-engine@ --version-before-package-rename 6.1.0",
|
|
55
56
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/json-rpc-engine --tag-prefix-before-package-rename json-rpc-engine@ --version-before-package-rename 6.1.0",
|
|
@@ -78,6 +79,7 @@
|
|
|
78
79
|
"@lavamoat/allow-scripts": "^3.0.4",
|
|
79
80
|
"@lavamoat/preinstall-always-fail": "^2.1.0",
|
|
80
81
|
"@metamask/auto-changelog": "^3.4.4",
|
|
82
|
+
"@ts-bridge/cli": "^0.6.4",
|
|
81
83
|
"@types/jest": "^27.4.1",
|
|
82
84
|
"deepmerge": "^4.2.2",
|
|
83
85
|
"jest": "^27.5.1",
|