@metamask-previews/json-rpc-engine 10.5.0-preview-4f4c98e → 10.5.0-preview-eb263b0ee
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 +0 -1
- package/dist/JsonRpcEngine.cjs +352 -0
- package/dist/JsonRpcEngine.cjs.map +1 -0
- package/dist/{JsonRpcEngine.d.ts → JsonRpcEngine.d.cts} +3 -3
- package/dist/JsonRpcEngine.d.cts.map +1 -0
- package/dist/JsonRpcEngine.d.mts +132 -0
- package/dist/JsonRpcEngine.d.mts.map +1 -0
- package/dist/{JsonRpcEngine.js → JsonRpcEngine.mjs} +5 -5
- package/dist/JsonRpcEngine.mjs.map +1 -0
- package/dist/asV2Middleware.cjs +57 -0
- package/dist/asV2Middleware.cjs.map +1 -0
- package/dist/{asV2Middleware.d.ts → asV2Middleware.d.cts} +6 -6
- package/dist/asV2Middleware.d.cts.map +1 -0
- package/dist/asV2Middleware.d.mts +20 -0
- package/dist/asV2Middleware.d.mts.map +1 -0
- package/dist/{asV2Middleware.js → asV2Middleware.mjs} +5 -5
- package/dist/asV2Middleware.mjs.map +1 -0
- package/dist/createAsyncMiddleware.cjs +71 -0
- package/dist/createAsyncMiddleware.cjs.map +1 -0
- package/dist/{createAsyncMiddleware.d.ts → createAsyncMiddleware.d.cts} +3 -3
- package/dist/createAsyncMiddleware.d.cts.map +1 -0
- package/dist/createAsyncMiddleware.d.mts +28 -0
- package/dist/createAsyncMiddleware.d.mts.map +1 -0
- package/dist/{createAsyncMiddleware.js → createAsyncMiddleware.mjs} +1 -1
- package/dist/createAsyncMiddleware.mjs.map +1 -0
- package/dist/createMethodMiddleware.cjs +56 -0
- package/dist/createMethodMiddleware.cjs.map +1 -0
- package/dist/{createMethodMiddleware.d.ts → createMethodMiddleware.d.cts} +6 -6
- package/dist/createMethodMiddleware.d.cts.map +1 -0
- package/dist/createMethodMiddleware.d.mts +86 -0
- package/dist/createMethodMiddleware.d.mts.map +1 -0
- package/dist/{createMethodMiddleware.js → createMethodMiddleware.mjs} +3 -3
- package/dist/createMethodMiddleware.mjs.map +1 -0
- package/dist/createOriginMiddleware.cjs +18 -0
- package/dist/createOriginMiddleware.cjs.map +1 -0
- package/dist/{createOriginMiddleware.d.ts → createOriginMiddleware.d.cts} +3 -3
- package/dist/createOriginMiddleware.d.cts.map +1 -0
- package/dist/createOriginMiddleware.d.mts +11 -0
- package/dist/createOriginMiddleware.d.mts.map +1 -0
- package/dist/{createOriginMiddleware.js → createOriginMiddleware.mjs} +1 -1
- package/dist/createOriginMiddleware.mjs.map +1 -0
- package/dist/createScaffoldMiddleware.cjs +31 -0
- package/dist/createScaffoldMiddleware.cjs.map +1 -0
- package/dist/{createScaffoldMiddleware.d.ts → createScaffoldMiddleware.d.cts} +3 -3
- package/dist/createScaffoldMiddleware.d.cts.map +1 -0
- package/dist/createScaffoldMiddleware.d.mts +18 -0
- package/dist/createScaffoldMiddleware.d.mts.map +1 -0
- package/dist/{createScaffoldMiddleware.js → createScaffoldMiddleware.mjs} +1 -1
- package/dist/createScaffoldMiddleware.mjs.map +1 -0
- package/dist/getUniqueId.cjs +20 -0
- package/dist/getUniqueId.cjs.map +1 -0
- package/dist/{getUniqueId.d.ts → getUniqueId.d.cts} +1 -1
- package/dist/getUniqueId.d.cts.map +1 -0
- package/dist/getUniqueId.d.mts +9 -0
- package/dist/getUniqueId.d.mts.map +1 -0
- package/dist/{getUniqueId.js → getUniqueId.mjs} +1 -1
- package/dist/getUniqueId.mjs.map +1 -0
- package/dist/idRemapMiddleware.cjs +29 -0
- package/dist/idRemapMiddleware.cjs.map +1 -0
- package/dist/{idRemapMiddleware.d.ts → idRemapMiddleware.d.cts} +3 -3
- package/dist/idRemapMiddleware.d.cts.map +1 -0
- package/dist/idRemapMiddleware.d.mts +14 -0
- package/dist/idRemapMiddleware.d.mts.map +1 -0
- package/dist/{idRemapMiddleware.js → idRemapMiddleware.mjs} +2 -2
- package/dist/idRemapMiddleware.mjs.map +1 -0
- package/dist/index.cjs +22 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +1 -0
- package/dist/mergeMiddleware.cjs +18 -0
- package/dist/mergeMiddleware.cjs.map +1 -0
- package/dist/{mergeMiddleware.d.ts → mergeMiddleware.d.cts} +3 -3
- package/dist/mergeMiddleware.d.cts.map +1 -0
- package/dist/mergeMiddleware.d.mts +11 -0
- package/dist/mergeMiddleware.d.mts.map +1 -0
- package/dist/{mergeMiddleware.js → mergeMiddleware.mjs} +2 -2
- package/dist/mergeMiddleware.mjs.map +1 -0
- package/dist/v2/JsonRpcEngineV2.cjs +220 -0
- package/dist/v2/JsonRpcEngineV2.cjs.map +1 -0
- package/dist/v2/{JsonRpcEngineV2.d.ts → JsonRpcEngineV2.d.cts} +5 -5
- package/dist/v2/JsonRpcEngineV2.d.cts.map +1 -0
- package/dist/v2/JsonRpcEngineV2.d.mts +136 -0
- package/dist/v2/JsonRpcEngineV2.d.mts.map +1 -0
- package/dist/v2/{JsonRpcEngineV2.js → JsonRpcEngineV2.mjs} +13 -9
- package/dist/v2/JsonRpcEngineV2.mjs.map +1 -0
- package/dist/v2/JsonRpcServer.cjs +178 -0
- package/dist/v2/JsonRpcServer.cjs.map +1 -0
- package/dist/v2/{JsonRpcServer.d.ts → JsonRpcServer.d.cts} +4 -4
- package/dist/v2/JsonRpcServer.d.cts.map +1 -0
- package/dist/v2/JsonRpcServer.d.mts +104 -0
- package/dist/v2/JsonRpcServer.d.mts.map +1 -0
- package/dist/v2/{JsonRpcServer.js → JsonRpcServer.mjs} +5 -5
- package/dist/v2/JsonRpcServer.mjs.map +1 -0
- package/dist/v2/MiddlewareContext.cjs +108 -0
- package/dist/v2/MiddlewareContext.cjs.map +1 -0
- package/dist/v2/{MiddlewareContext.d.ts → MiddlewareContext.d.cts} +2 -2
- package/dist/v2/MiddlewareContext.d.cts.map +1 -0
- package/dist/v2/MiddlewareContext.d.mts +108 -0
- package/dist/v2/MiddlewareContext.d.mts.map +1 -0
- package/dist/v2/{MiddlewareContext.js → MiddlewareContext.mjs} +2 -2
- package/dist/v2/MiddlewareContext.mjs.map +1 -0
- package/dist/v2/asLegacyMiddleware.cjs +45 -0
- package/dist/v2/asLegacyMiddleware.cjs.map +1 -0
- package/dist/v2/{asLegacyMiddleware.d.ts → asLegacyMiddleware.d.cts} +5 -5
- package/dist/v2/asLegacyMiddleware.d.cts.map +1 -0
- package/dist/v2/asLegacyMiddleware.d.mts +19 -0
- package/dist/v2/asLegacyMiddleware.d.mts.map +1 -0
- package/dist/v2/{asLegacyMiddleware.js → asLegacyMiddleware.mjs} +4 -4
- package/dist/v2/asLegacyMiddleware.mjs.map +1 -0
- package/dist/v2/compatibility-utils.cjs +167 -0
- package/dist/v2/compatibility-utils.cjs.map +1 -0
- package/dist/v2/{compatibility-utils.d.ts → compatibility-utils.d.cts} +5 -5
- package/dist/v2/compatibility-utils.d.cts.map +1 -0
- package/dist/v2/compatibility-utils.d.mts +75 -0
- package/dist/v2/compatibility-utils.d.mts.map +1 -0
- package/dist/v2/{compatibility-utils.js → compatibility-utils.mjs} +6 -6
- package/dist/v2/compatibility-utils.mjs.map +1 -0
- package/dist/v2/createMethodMiddleware.cjs +44 -0
- package/dist/v2/createMethodMiddleware.cjs.map +1 -0
- package/dist/v2/{createMethodMiddleware.d.ts → createMethodMiddleware.d.cts} +5 -5
- package/dist/v2/createMethodMiddleware.d.cts.map +1 -0
- package/dist/v2/createMethodMiddleware.d.mts +71 -0
- package/dist/v2/createMethodMiddleware.d.mts.map +1 -0
- package/dist/v2/{createMethodMiddleware.js → createMethodMiddleware.mjs} +3 -2
- package/dist/v2/createMethodMiddleware.mjs.map +1 -0
- package/dist/v2/createOriginMiddleware.cjs +18 -0
- package/dist/v2/createOriginMiddleware.cjs.map +1 -0
- package/dist/v2/{createOriginMiddleware.d.ts → createOriginMiddleware.d.cts} +4 -4
- package/dist/v2/createOriginMiddleware.d.cts.map +1 -0
- package/dist/v2/createOriginMiddleware.d.mts +13 -0
- package/dist/v2/createOriginMiddleware.d.mts.map +1 -0
- package/dist/v2/{createOriginMiddleware.js → createOriginMiddleware.mjs} +2 -1
- package/dist/v2/createOriginMiddleware.mjs.map +1 -0
- package/dist/v2/createScaffoldMiddleware.cjs +25 -0
- package/dist/v2/createScaffoldMiddleware.cjs.map +1 -0
- package/dist/v2/{createScaffoldMiddleware.d.ts → createScaffoldMiddleware.d.cts} +4 -4
- package/dist/v2/createScaffoldMiddleware.d.cts.map +1 -0
- package/dist/v2/createScaffoldMiddleware.d.mts +30 -0
- package/dist/v2/createScaffoldMiddleware.d.mts.map +1 -0
- package/dist/v2/{createScaffoldMiddleware.js → createScaffoldMiddleware.mjs} +1 -1
- package/dist/v2/createScaffoldMiddleware.mjs.map +1 -0
- package/dist/v2/index.cjs +26 -0
- package/dist/v2/index.cjs.map +1 -0
- package/dist/v2/index.d.cts +14 -0
- package/dist/v2/index.d.cts.map +1 -0
- package/dist/v2/index.d.mts +14 -0
- package/dist/v2/index.d.mts.map +1 -0
- package/dist/v2/index.mjs +10 -0
- package/dist/v2/index.mjs.map +1 -0
- package/dist/v2/utils.cjs +122 -0
- package/dist/v2/utils.cjs.map +1 -0
- package/dist/v2/{utils.d.ts → utils.d.cts} +5 -5
- package/dist/v2/utils.d.cts.map +1 -0
- package/dist/v2/utils.d.mts +85 -0
- package/dist/v2/utils.d.mts.map +1 -0
- package/dist/v2/{utils.js → utils.mjs} +3 -3
- package/dist/v2/utils.mjs.map +1 -0
- package/package.json +25 -15
- package/dist/JsonRpcEngine.d.ts.map +0 -1
- package/dist/JsonRpcEngine.js.map +0 -1
- package/dist/asV2Middleware.d.ts.map +0 -1
- package/dist/asV2Middleware.js.map +0 -1
- package/dist/createAsyncMiddleware.d.ts.map +0 -1
- package/dist/createAsyncMiddleware.js.map +0 -1
- package/dist/createMethodMiddleware.d.ts.map +0 -1
- package/dist/createMethodMiddleware.js.map +0 -1
- package/dist/createOriginMiddleware.d.ts.map +0 -1
- package/dist/createOriginMiddleware.js.map +0 -1
- package/dist/createScaffoldMiddleware.d.ts.map +0 -1
- package/dist/createScaffoldMiddleware.js.map +0 -1
- package/dist/getUniqueId.d.ts.map +0 -1
- package/dist/getUniqueId.js.map +0 -1
- package/dist/idRemapMiddleware.d.ts.map +0 -1
- package/dist/idRemapMiddleware.js.map +0 -1
- package/dist/index.d.ts +0 -13
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -10
- package/dist/index.js.map +0 -1
- package/dist/mergeMiddleware.d.ts.map +0 -1
- package/dist/mergeMiddleware.js.map +0 -1
- package/dist/v2/JsonRpcEngineV2.d.ts.map +0 -1
- package/dist/v2/JsonRpcEngineV2.js.map +0 -1
- package/dist/v2/JsonRpcServer.d.ts.map +0 -1
- package/dist/v2/JsonRpcServer.js.map +0 -1
- package/dist/v2/MiddlewareContext.d.ts.map +0 -1
- package/dist/v2/MiddlewareContext.js.map +0 -1
- package/dist/v2/asLegacyMiddleware.d.ts.map +0 -1
- package/dist/v2/asLegacyMiddleware.js.map +0 -1
- package/dist/v2/compatibility-utils.d.ts.map +0 -1
- package/dist/v2/compatibility-utils.js.map +0 -1
- package/dist/v2/createMethodMiddleware.d.ts.map +0 -1
- package/dist/v2/createMethodMiddleware.js.map +0 -1
- package/dist/v2/createOriginMiddleware.d.ts.map +0 -1
- package/dist/v2/createOriginMiddleware.js.map +0 -1
- package/dist/v2/createScaffoldMiddleware.d.ts.map +0 -1
- package/dist/v2/createScaffoldMiddleware.js.map +0 -1
- package/dist/v2/index.d.ts +0 -14
- package/dist/v2/index.d.ts.map +0 -1
- package/dist/v2/index.js +0 -10
- package/dist/v2/index.js.map +0 -1
- package/dist/v2/utils.d.ts.map +0 -1
- package/dist/v2/utils.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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IAAI,IAAI,SAAS,MAAM,MAAM,GAC3C;KAAG,GAAG,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC;CAAE,GACtC,KAAK,CAAC;AAEV;;;;;;;;;GASG;AACH,KAAK,YAAY,CAAC,IAAI,SAAS,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,IAAI;KAC5D,GAAG,IAAI,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,KAAK;CACjE,CAAC,MAAM,IAAI,CAAC,SAAS,KAAK,GACvB,IAAI,GACJ,KAAK,CAAC;AAEV;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,CAAC,QAAQ,SAAS,iBAAiB,IAC1D,YAAY,CACV,QAAQ,CAAC,mBAAmB,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CACxD,SAAS,KAAK,GACX,KAAK,GACL,iBAAiB,CACf,YAAY,CAAC,QAAQ,CAAC,mBAAmB,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CACtE,CAAC;AAER;;GAEG;AAGH,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;AAEvD;;GAEG;AAGH,MAAM,MAAM,YAAY,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var _a;
|
|
2
|
-
import { isInstance } from
|
|
2
|
+
import { isInstance } from "./utils.mjs";
|
|
3
3
|
const MiddlewareContextSymbol = Symbol.for('json-rpc-engine#MiddlewareContext');
|
|
4
4
|
/**
|
|
5
5
|
* A context object for middleware that attempts to protect against accidental
|
|
@@ -101,4 +101,4 @@ function entriesFromKeyValues(keyValues) {
|
|
|
101
101
|
keyValues[key],
|
|
102
102
|
]);
|
|
103
103
|
}
|
|
104
|
-
//# sourceMappingURL=MiddlewareContext.
|
|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GAAG,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,0BAA0B,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAC3E,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;KA3DmB,uBAAuB;AA6D3C;;;;;GAKG;AACH,SAAS,UAAU,CACjB,KAAuD;IAEvD,OAAO,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC;AAClC,CAAC;AAED;;;;;;GAMG;AACH,SAAS,oBAAoB,CAC3B,SAAoB;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 { isInstance } from './utils.js';\nimport type { UnionToIntersection } from './utils.js';\n\nconst MiddlewareContextSymbol = Symbol.for('json-rpc-engine#MiddlewareContext');\n\n/**\n * A 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 // This is a computed property name, and it doesn't seem possible to make it\n // hash private using `#`.\n // eslint-disable-next-line no-restricted-syntax\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 isInstance(value, MiddlewareContextSymbol);\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<Key extends keyof KeyValues>(key: Key): KeyValues[Key] | undefined {\n return super.get(key) as KeyValues[Key] | 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<Key extends keyof KeyValues>(key: Key): KeyValues[Key] {\n if (!super.has(key)) {\n throw new Error(`Context key \"${String(key)}\" not found`);\n }\n return super.get(key) as KeyValues[Key];\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<Key extends keyof KeyValues>(key: Key, value: KeyValues[Key]): 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<Type> =\n Type extends MiddlewareContext<infer KeyValues> ? KeyValues : 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<Type> = Type extends infer Object\n ? { [Key in keyof Object]: Object[Key] }\n : 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<Type extends Record<PropertyKey, unknown>> = {\n [Key in keyof Type]-?: [Type[Key]] extends [never] ? Key : never;\n}[keyof Type] extends never\n ? Type\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"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asLegacyMiddleware = void 0;
|
|
4
|
+
const index_js_1 = require("../index.cjs");
|
|
5
|
+
const compatibility_utils_js_1 = require("./compatibility-utils.cjs");
|
|
6
|
+
const JsonRpcEngineV2_js_1 = require("./JsonRpcEngineV2.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* The asLegacyMiddleware implementation.
|
|
9
|
+
*
|
|
10
|
+
* @param engineOrMiddleware - A V2 engine or V2 middleware.
|
|
11
|
+
* @param rest - Any additional V2 middleware when the first argument is a middleware.
|
|
12
|
+
* @returns The legacy middleware.
|
|
13
|
+
*/
|
|
14
|
+
function asLegacyMiddleware(engineOrMiddleware, ...rest) {
|
|
15
|
+
const v2Middleware = typeof engineOrMiddleware === 'function'
|
|
16
|
+
? JsonRpcEngineV2_js_1.JsonRpcEngineV2.create({
|
|
17
|
+
middleware: [engineOrMiddleware, ...rest],
|
|
18
|
+
}).asMiddleware()
|
|
19
|
+
: engineOrMiddleware.asMiddleware();
|
|
20
|
+
return (0, index_js_1.createAsyncMiddleware)(async (req, res, next) => {
|
|
21
|
+
const request = (0, compatibility_utils_js_1.fromLegacyRequest)(req);
|
|
22
|
+
const context = (0, compatibility_utils_js_1.makeContext)(req);
|
|
23
|
+
let modifiedRequest;
|
|
24
|
+
const result = await v2Middleware({
|
|
25
|
+
request,
|
|
26
|
+
context,
|
|
27
|
+
next: (finalRequest) => {
|
|
28
|
+
modifiedRequest = finalRequest;
|
|
29
|
+
return Promise.resolve(undefined);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
if (modifiedRequest !== undefined && modifiedRequest !== request) {
|
|
33
|
+
Object.assign(req, (0, compatibility_utils_js_1.deepClone)(modifiedRequest));
|
|
34
|
+
}
|
|
35
|
+
(0, compatibility_utils_js_1.propagateToRequest)(req, context);
|
|
36
|
+
if (result !== undefined) {
|
|
37
|
+
// Unclear why the `as unknown` is needed here, but the cast is safe.
|
|
38
|
+
res.result = (0, compatibility_utils_js_1.deepClone)(result);
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return next();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.asLegacyMiddleware = asLegacyMiddleware;
|
|
45
|
+
//# sourceMappingURL=asLegacyMiddleware.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asLegacyMiddleware.cjs","sourceRoot":"","sources":["../../src/v2/asLegacyMiddleware.ts"],"names":[],"mappings":";;;AAEA,2CAAoD;AAEpD,sEAKkC;AAElC,8DAAuD;AA4BvD;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAIhC,kBAEyD,EACzD,GAAG,IAA6D;IAEhE,MAAM,YAAY,GAChB,OAAO,kBAAkB,KAAK,UAAU;QACtC,CAAC,CAAC,oCAAe,CAAC,MAAM,CAAC;YACrB,UAAU,EAAE,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC;SAC1C,CAAC,CAAC,YAAY,EAAE;QACnB,CAAC,CAAC,kBAAkB,CAAC,YAAY,EAAE,CAAC;IAExC,OAAO,IAAA,gCAAqB,EAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACpD,MAAM,OAAO,GAAG,IAAA,0CAAiB,EAAC,GAAc,CAAC,CAAC;QAClD,MAAM,OAAO,GAAG,IAAA,oCAAW,EAAC,GAAG,CAAC,CAAC;QACjC,IAAI,eAAoC,CAAC;QAEzC,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC;YAChC,OAAO;YACP,OAAO;YACP,IAAI,EAAE,CAAC,YAAY,EAAE,EAAE;gBACrB,eAAe,GAAG,YAAY,CAAC;gBAC/B,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACpC,CAAC;SACF,CAAC,CAAC;QAEH,IAAI,eAAe,KAAK,SAAS,IAAI,eAAe,KAAK,OAAO,EAAE,CAAC;YACjE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,IAAA,kCAAS,EAAC,eAAe,CAAC,CAAC,CAAC;QACjD,CAAC;QACD,IAAA,2CAAkB,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAEjC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,qEAAqE;YACrE,GAAG,CAAC,MAAM,GAAG,IAAA,kCAAS,EAAC,MAAM,CAAyC,CAAC;YACvE,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC;AA1CD,gDA0CC","sourcesContent":["import type { JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nimport { createAsyncMiddleware } from '../index.js';\nimport type { JsonRpcMiddleware as LegacyMiddleware } from '../index.js';\nimport {\n deepClone,\n fromLegacyRequest,\n makeContext,\n propagateToRequest,\n} from './compatibility-utils.js';\nimport type { JsonRpcMiddleware, ResultConstraint } from './JsonRpcEngineV2.js';\nimport { JsonRpcEngineV2 } from './JsonRpcEngineV2.js';\n\n/**\n * Convert a {@link JsonRpcEngineV2} into a legacy middleware.\n *\n * @param engine - The engine to convert.\n * @returns The legacy middleware.\n */\nexport function asLegacyMiddleware<\n Params extends JsonRpcParams,\n Request extends JsonRpcRequest<Params>,\n>(\n engine: JsonRpcEngineV2<Request>,\n): LegacyMiddleware<Params, ResultConstraint<Request>>;\n\n/**\n * Convert one or more V2 middlewares into a legacy middleware.\n *\n * @param middleware - The V2 middleware(s) to convert.\n * @returns The legacy middleware.\n */\nexport function asLegacyMiddleware<\n Params extends JsonRpcParams,\n Request extends JsonRpcRequest<Params>,\n>(\n ...middleware: JsonRpcMiddleware<Request, ResultConstraint<Request>>[]\n): LegacyMiddleware<Params, ResultConstraint<Request>>;\n\n/**\n * The asLegacyMiddleware implementation.\n *\n * @param engineOrMiddleware - A V2 engine or V2 middleware.\n * @param rest - Any additional V2 middleware when the first argument is a middleware.\n * @returns The legacy middleware.\n */\nexport function asLegacyMiddleware<\n Params extends JsonRpcParams,\n Request extends JsonRpcRequest<Params>,\n>(\n engineOrMiddleware:\n | JsonRpcEngineV2<Request>\n | JsonRpcMiddleware<Request, ResultConstraint<Request>>,\n ...rest: JsonRpcMiddleware<Request, ResultConstraint<Request>>[]\n): LegacyMiddleware<Params, ResultConstraint<Request>> {\n const v2Middleware =\n typeof engineOrMiddleware === 'function'\n ? JsonRpcEngineV2.create({\n middleware: [engineOrMiddleware, ...rest],\n }).asMiddleware()\n : engineOrMiddleware.asMiddleware();\n\n return createAsyncMiddleware(async (req, res, next) => {\n const request = fromLegacyRequest(req as Request);\n const context = makeContext(req);\n let modifiedRequest: Request | undefined;\n\n const result = await v2Middleware({\n request,\n context,\n next: (finalRequest) => {\n modifiedRequest = finalRequest;\n return Promise.resolve(undefined);\n },\n });\n\n if (modifiedRequest !== undefined && modifiedRequest !== request) {\n Object.assign(req, deepClone(modifiedRequest));\n }\n propagateToRequest(req, context);\n\n if (result !== undefined) {\n // Unclear why the `as unknown` is needed here, but the cast is safe.\n res.result = deepClone(result) as unknown as ResultConstraint<Request>;\n return undefined;\n }\n return next();\n });\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { JsonRpcParams, JsonRpcRequest } from
|
|
2
|
-
import type { JsonRpcMiddleware as LegacyMiddleware } from
|
|
3
|
-
import type { JsonRpcMiddleware, ResultConstraint } from
|
|
4
|
-
import { JsonRpcEngineV2 } from
|
|
1
|
+
import type { JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
|
|
2
|
+
import type { JsonRpcMiddleware as LegacyMiddleware } from "../index.cjs";
|
|
3
|
+
import type { JsonRpcMiddleware, ResultConstraint } from "./JsonRpcEngineV2.cjs";
|
|
4
|
+
import { JsonRpcEngineV2 } from "./JsonRpcEngineV2.cjs";
|
|
5
5
|
/**
|
|
6
6
|
* Convert a {@link JsonRpcEngineV2} into a legacy middleware.
|
|
7
7
|
*
|
|
@@ -16,4 +16,4 @@ export declare function asLegacyMiddleware<Params extends JsonRpcParams, Request
|
|
|
16
16
|
* @returns The legacy middleware.
|
|
17
17
|
*/
|
|
18
18
|
export declare function asLegacyMiddleware<Params extends JsonRpcParams, Request extends JsonRpcRequest<Params>>(...middleware: JsonRpcMiddleware<Request, ResultConstraint<Request>>[]): LegacyMiddleware<Params, ResultConstraint<Request>>;
|
|
19
|
-
//# sourceMappingURL=asLegacyMiddleware.d.
|
|
19
|
+
//# sourceMappingURL=asLegacyMiddleware.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asLegacyMiddleware.d.cts","sourceRoot":"","sources":["../../src/v2/asLegacyMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB;AAGrE,OAAO,KAAK,EAAE,iBAAiB,IAAI,gBAAgB,EAAE,qBAAoB;AAOzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,8BAA6B;AAChF,OAAO,EAAE,eAAe,EAAE,8BAA6B;AAEvD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,SAAS,aAAa,EAC5B,OAAO,SAAS,cAAc,CAAC,MAAM,CAAC,EAEtC,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,GAC/B,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AAEvD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,SAAS,aAAa,EAC5B,OAAO,SAAS,cAAc,CAAC,MAAM,CAAC,EAEtC,GAAG,UAAU,EAAE,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,GACrE,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
|
|
2
|
+
import type { JsonRpcMiddleware as LegacyMiddleware } from "../index.mjs";
|
|
3
|
+
import type { JsonRpcMiddleware, ResultConstraint } from "./JsonRpcEngineV2.mjs";
|
|
4
|
+
import { JsonRpcEngineV2 } from "./JsonRpcEngineV2.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Convert a {@link JsonRpcEngineV2} into a legacy middleware.
|
|
7
|
+
*
|
|
8
|
+
* @param engine - The engine to convert.
|
|
9
|
+
* @returns The legacy middleware.
|
|
10
|
+
*/
|
|
11
|
+
export declare function asLegacyMiddleware<Params extends JsonRpcParams, Request extends JsonRpcRequest<Params>>(engine: JsonRpcEngineV2<Request>): LegacyMiddleware<Params, ResultConstraint<Request>>;
|
|
12
|
+
/**
|
|
13
|
+
* Convert one or more V2 middlewares into a legacy middleware.
|
|
14
|
+
*
|
|
15
|
+
* @param middleware - The V2 middleware(s) to convert.
|
|
16
|
+
* @returns The legacy middleware.
|
|
17
|
+
*/
|
|
18
|
+
export declare function asLegacyMiddleware<Params extends JsonRpcParams, Request extends JsonRpcRequest<Params>>(...middleware: JsonRpcMiddleware<Request, ResultConstraint<Request>>[]): LegacyMiddleware<Params, ResultConstraint<Request>>;
|
|
19
|
+
//# sourceMappingURL=asLegacyMiddleware.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asLegacyMiddleware.d.mts","sourceRoot":"","sources":["../../src/v2/asLegacyMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB;AAGrE,OAAO,KAAK,EAAE,iBAAiB,IAAI,gBAAgB,EAAE,qBAAoB;AAOzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,8BAA6B;AAChF,OAAO,EAAE,eAAe,EAAE,8BAA6B;AAEvD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,SAAS,aAAa,EAC5B,OAAO,SAAS,cAAc,CAAC,MAAM,CAAC,EAEtC,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,GAC/B,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AAEvD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,SAAS,aAAa,EAC5B,OAAO,SAAS,cAAc,CAAC,MAAM,CAAC,EAEtC,GAAG,UAAU,EAAE,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,GACrE,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createAsyncMiddleware } from
|
|
2
|
-
import { deepClone, fromLegacyRequest, makeContext, propagateToRequest
|
|
3
|
-
import { JsonRpcEngineV2 } from
|
|
1
|
+
import { createAsyncMiddleware } from "../index.mjs";
|
|
2
|
+
import { deepClone, fromLegacyRequest, makeContext, propagateToRequest } from "./compatibility-utils.mjs";
|
|
3
|
+
import { JsonRpcEngineV2 } from "./JsonRpcEngineV2.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* The asLegacyMiddleware implementation.
|
|
6
6
|
*
|
|
@@ -38,4 +38,4 @@ export function asLegacyMiddleware(engineOrMiddleware, ...rest) {
|
|
|
38
38
|
return next();
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
-
//# sourceMappingURL=asLegacyMiddleware.
|
|
41
|
+
//# sourceMappingURL=asLegacyMiddleware.mjs.map
|
|
@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AEjC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,qEAAqE;YACrE,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,CAAyC,CAAC;YACvE,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nimport { createAsyncMiddleware } from '../index.js';\nimport type { JsonRpcMiddleware as LegacyMiddleware } from '../index.js';\nimport {\n deepClone,\n fromLegacyRequest,\n makeContext,\n propagateToRequest,\n} from './compatibility-utils.js';\nimport type { JsonRpcMiddleware, ResultConstraint } from './JsonRpcEngineV2.js';\nimport { JsonRpcEngineV2 } from './JsonRpcEngineV2.js';\n\n/**\n * Convert a {@link JsonRpcEngineV2} into a legacy middleware.\n *\n * @param engine - The engine to convert.\n * @returns The legacy middleware.\n */\nexport function asLegacyMiddleware<\n Params extends JsonRpcParams,\n Request extends JsonRpcRequest<Params>,\n>(\n engine: JsonRpcEngineV2<Request>,\n): LegacyMiddleware<Params, ResultConstraint<Request>>;\n\n/**\n * Convert one or more V2 middlewares into a legacy middleware.\n *\n * @param middleware - The V2 middleware(s) to convert.\n * @returns The legacy middleware.\n */\nexport function asLegacyMiddleware<\n Params extends JsonRpcParams,\n Request extends JsonRpcRequest<Params>,\n>(\n ...middleware: JsonRpcMiddleware<Request, ResultConstraint<Request>>[]\n): LegacyMiddleware<Params, ResultConstraint<Request>>;\n\n/**\n * The asLegacyMiddleware implementation.\n *\n * @param engineOrMiddleware - A V2 engine or V2 middleware.\n * @param rest - Any additional V2 middleware when the first argument is a middleware.\n * @returns The legacy middleware.\n */\nexport function asLegacyMiddleware<\n Params extends JsonRpcParams,\n Request extends JsonRpcRequest<Params>,\n>(\n engineOrMiddleware:\n | JsonRpcEngineV2<Request>\n | JsonRpcMiddleware<Request, ResultConstraint<Request>>,\n ...rest: JsonRpcMiddleware<Request, ResultConstraint<Request>>[]\n): LegacyMiddleware<Params, ResultConstraint<Request>> {\n const v2Middleware =\n typeof engineOrMiddleware === 'function'\n ? JsonRpcEngineV2.create({\n middleware: [engineOrMiddleware, ...rest],\n }).asMiddleware()\n : engineOrMiddleware.asMiddleware();\n\n return createAsyncMiddleware(async (req, res, next) => {\n const request = fromLegacyRequest(req as Request);\n const context = makeContext(req);\n let modifiedRequest: Request | undefined;\n\n const result = await v2Middleware({\n request,\n context,\n next: (finalRequest) => {\n modifiedRequest = finalRequest;\n return Promise.resolve(undefined);\n },\n });\n\n if (modifiedRequest !== undefined && modifiedRequest !== request) {\n Object.assign(req, deepClone(modifiedRequest));\n }\n propagateToRequest(req, context);\n\n if (result !== undefined) {\n // Unclear why the `as unknown` is needed here, but the cast is safe.\n res.result = deepClone(result) as unknown as ResultConstraint<Request>;\n return undefined;\n }\n return next();\n });\n}\n"]}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeError = exports.propagateToRequest = exports.propagateToContext = exports.makeContext = exports.fromLegacyRequest = exports.requestProps = exports.deepClone = void 0;
|
|
4
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
// ATTN: We must NOT use 'klona/full' here because it freezes properties on the clone.
|
|
7
|
+
const klona_1 = require("klona");
|
|
8
|
+
const MiddlewareContext_js_1 = require("./MiddlewareContext.cjs");
|
|
9
|
+
const utils_js_1 = require("./utils.cjs");
|
|
10
|
+
// Legacy engine compatibility utils
|
|
11
|
+
/**
|
|
12
|
+
* Create a deep clone of a value as follows:
|
|
13
|
+
* - Assumes acyclical objects
|
|
14
|
+
* - Does not copy property descriptors (i.e. uses mutable defaults)
|
|
15
|
+
* - Ignores non-enumerable properties
|
|
16
|
+
* - Ignores getters and setters
|
|
17
|
+
*
|
|
18
|
+
* @throws If the value is an object with a circular reference.
|
|
19
|
+
* @param value - The value to clone.
|
|
20
|
+
* @returns The cloned value.
|
|
21
|
+
*/
|
|
22
|
+
const deepClone = (value) => (0, klona_1.klona)(value);
|
|
23
|
+
exports.deepClone = deepClone;
|
|
24
|
+
/**
|
|
25
|
+
* Standard JSON-RPC request properties.
|
|
26
|
+
*/
|
|
27
|
+
exports.requestProps = ['jsonrpc', 'method', 'params', 'id'];
|
|
28
|
+
/**
|
|
29
|
+
* Make a JSON-RPC request from a legacy request. Clones the params to avoid
|
|
30
|
+
* freezing them, which could cause errors in an involved legacy engine.
|
|
31
|
+
*
|
|
32
|
+
* @param req - The legacy request to make a request from.
|
|
33
|
+
* @returns The JSON-RPC request.
|
|
34
|
+
*/
|
|
35
|
+
function fromLegacyRequest(req) {
|
|
36
|
+
const request = {
|
|
37
|
+
jsonrpc: '2.0',
|
|
38
|
+
method: req.method,
|
|
39
|
+
};
|
|
40
|
+
request.id = req.id;
|
|
41
|
+
if ((0, utils_1.hasProperty)(req, 'params') && req.params !== undefined) {
|
|
42
|
+
request.params = (0, exports.deepClone)(req.params);
|
|
43
|
+
}
|
|
44
|
+
return request;
|
|
45
|
+
}
|
|
46
|
+
exports.fromLegacyRequest = fromLegacyRequest;
|
|
47
|
+
/**
|
|
48
|
+
* Make a middleware context from a legacy request by copying over all non-JSON-RPC
|
|
49
|
+
* properties from the request to the context object.
|
|
50
|
+
*
|
|
51
|
+
* @param req - The legacy request to make a context from.
|
|
52
|
+
* @returns The middleware context.
|
|
53
|
+
*/
|
|
54
|
+
function makeContext(req) {
|
|
55
|
+
const context = new MiddlewareContext_js_1.MiddlewareContext();
|
|
56
|
+
propagateToContext(req, context);
|
|
57
|
+
return context;
|
|
58
|
+
}
|
|
59
|
+
exports.makeContext = makeContext;
|
|
60
|
+
/**
|
|
61
|
+
* Copies non-JSON-RPC string properties from the request to the context.
|
|
62
|
+
*
|
|
63
|
+
* For compatibility with our problematic practice of appending non-standard
|
|
64
|
+
* fields to requests for inter-middleware communication in the legacy engine.
|
|
65
|
+
*
|
|
66
|
+
* **ATTN:** Only string properties that do not already exist in the context
|
|
67
|
+
* are copied.
|
|
68
|
+
*
|
|
69
|
+
* @param req - The request to propagate the context from.
|
|
70
|
+
* @param context - The context to propagate to.
|
|
71
|
+
*/
|
|
72
|
+
function propagateToContext(req, context) {
|
|
73
|
+
Object.keys(req)
|
|
74
|
+
.filter((key) => typeof key === 'string' &&
|
|
75
|
+
!exports.requestProps.includes(key) &&
|
|
76
|
+
!context.has(key))
|
|
77
|
+
.forEach((key) => {
|
|
78
|
+
context.set(key, req[key]);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.propagateToContext = propagateToContext;
|
|
82
|
+
/**
|
|
83
|
+
* Copies non-JSON-RPC string properties from the context to the request.
|
|
84
|
+
*
|
|
85
|
+
* For compatibility with our problematic practice of appending non-standard
|
|
86
|
+
* fields to requests for inter-middleware communication in the legacy engine.
|
|
87
|
+
*
|
|
88
|
+
* **ATTN:** Only string properties are copied.
|
|
89
|
+
*
|
|
90
|
+
* @param req - The request to propagate the context to.
|
|
91
|
+
* @param context - The context to propagate from.
|
|
92
|
+
*/
|
|
93
|
+
function propagateToRequest(req, context) {
|
|
94
|
+
Array.from(context.keys())
|
|
95
|
+
.filter(((key) => typeof key === 'string' && !exports.requestProps.includes(key)))
|
|
96
|
+
.forEach((key) => {
|
|
97
|
+
req[key] = context.get(key);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
exports.propagateToRequest = propagateToRequest;
|
|
101
|
+
/**
|
|
102
|
+
* Deserialize the error property for a thrown error, merging in the cause where possible.
|
|
103
|
+
*
|
|
104
|
+
* @param data - The data from the thrown error.
|
|
105
|
+
* @param cause - The cause from the thrown error.
|
|
106
|
+
* @returns The deserialized data.
|
|
107
|
+
*/
|
|
108
|
+
function deserializeData(data, cause) {
|
|
109
|
+
// If data is an object, merge with cause.
|
|
110
|
+
if ((0, utils_1.isObject)(data)) {
|
|
111
|
+
return { ...data, cause: cause ?? data.cause };
|
|
112
|
+
}
|
|
113
|
+
// If data is a JSON value that's not mergeable.
|
|
114
|
+
if ((0, utils_1.isValidJson)(data)) {
|
|
115
|
+
return data;
|
|
116
|
+
}
|
|
117
|
+
// If data is undefined, only use cause.
|
|
118
|
+
return { cause };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Unserialize an error from a thrown value. Creates a {@link JsonRpcError} if
|
|
122
|
+
* the thrown value is an object with a `code` property. Otherwise, creates a
|
|
123
|
+
* plain {@link Error}.
|
|
124
|
+
*
|
|
125
|
+
* @param thrown - The thrown value to unserialize.
|
|
126
|
+
* @returns The unserialized error.
|
|
127
|
+
*/
|
|
128
|
+
function deserializeError(thrown) {
|
|
129
|
+
// @ts-expect-error - New, but preferred if available.
|
|
130
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError
|
|
131
|
+
if (typeof Error.isError === 'function' && Error.isError(thrown)) {
|
|
132
|
+
return thrown;
|
|
133
|
+
}
|
|
134
|
+
// Unlike Error.isError, instanceof does not work for Errors from other realms.
|
|
135
|
+
if (thrown instanceof Error) {
|
|
136
|
+
return thrown;
|
|
137
|
+
}
|
|
138
|
+
if (typeof thrown === 'string') {
|
|
139
|
+
return new Error(thrown);
|
|
140
|
+
}
|
|
141
|
+
if (!(0, utils_1.isObject)(thrown)) {
|
|
142
|
+
return new Error(`Unknown error: ${(0, utils_js_1.stringify)(thrown)}`);
|
|
143
|
+
}
|
|
144
|
+
const code = typeof thrown.code === 'number' && Number.isInteger(thrown.code)
|
|
145
|
+
? thrown.code
|
|
146
|
+
: undefined;
|
|
147
|
+
let message = 'Unknown error';
|
|
148
|
+
if (typeof thrown.message === 'string') {
|
|
149
|
+
message = thrown.message;
|
|
150
|
+
}
|
|
151
|
+
else if (typeof code === 'number') {
|
|
152
|
+
message = (0, rpc_errors_1.getMessageFromCode)(code, message);
|
|
153
|
+
}
|
|
154
|
+
const { stack, cause, data } = thrown;
|
|
155
|
+
const error = code === undefined
|
|
156
|
+
? // Jest complains if we use the `@ts-expect-error` directive here.
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
158
|
+
// @ts-ignore - Our error type is outdated.
|
|
159
|
+
new Error(message, { cause })
|
|
160
|
+
: new rpc_errors_1.JsonRpcError(code, message, deserializeData(data, cause));
|
|
161
|
+
if (typeof stack === 'string') {
|
|
162
|
+
error.stack = stack;
|
|
163
|
+
}
|
|
164
|
+
return error;
|
|
165
|
+
}
|
|
166
|
+
exports.deserializeError = deserializeError;
|
|
167
|
+
//# sourceMappingURL=compatibility-utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compatibility-utils.cjs","sourceRoot":"","sources":["../../src/v2/compatibility-utils.ts"],"names":[],"mappings":";;;AACA,qDAAwE;AAExE,2CAAqE;AACrE,sFAAsF;AACtF,iCAA8B;AAE9B,kEAA2D;AAC3D,0CAAuC;AAGvC,oCAAoC;AAEpC;;;;;;;;;;GAUG;AACI,MAAM,SAAS,GAAG,CAAO,KAAW,EAAoB,EAAE,CAC/D,IAAA,aAAK,EAAC,KAAK,CAAqB,CAAC;AADtB,QAAA,SAAS,aACa;AAenC;;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,CAAC;QAC3D,OAAO,CAAC,MAAM,GAAG,IAAA,iBAAS,EAAC,GAAG,CAAC,MAAM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AO,CAAC;IAC3B,CAAC;SAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,GAAG,IAAA,+BAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;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,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAEpE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AA5CD,4CA4CC","sourcesContent":["import type { OptionalDataWithOptionalCause } from '@metamask/rpc-errors';\nimport { getMessageFromCode, JsonRpcError } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty, isObject, isValidJson } 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.js';\nimport { stringify } from './utils.js';\nimport type { JsonRpcRequest } from './utils.js';\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 = <Type>(value: Type): DeepCloned<Type> =>\n klona(value) as DeepCloned<Type>;\n\n// Matching the default implementation of klona, this type:\n// - Removes readonly modifiers\n// - Excludes non-enumerable / symbol properties\ntype DeepCloned<Type> = Type extends readonly (infer ArrayType)[]\n ? DeepCloned<ArrayType>[]\n : Type extends object\n ? {\n -readonly [Key in keyof Type & (string | number)]: DeepCloned<\n Type[Key]\n >;\n }\n : Type;\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): void {\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): void {\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 * Deserialize the error property for a thrown error, merging in the cause where possible.\n *\n * @param data - The data from the thrown error.\n * @param cause - The cause from the thrown error.\n * @returns The deserialized data.\n */\nfunction deserializeData(\n data: unknown,\n cause: unknown,\n): OptionalDataWithOptionalCause {\n // If data is an object, merge with cause.\n if (isObject(data)) {\n return { ...data, cause: cause ?? data.cause };\n }\n\n // If data is a JSON value that's not mergeable.\n if (isValidJson(data)) {\n return data;\n }\n\n // If data is undefined, only use cause.\n return { cause };\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, deserializeData(data, cause));\n\n if (typeof stack === 'string') {\n error.stack = stack;\n }\n\n return error;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { JsonRpcError } from
|
|
2
|
-
import type { Json } from
|
|
3
|
-
import { MiddlewareContext } from
|
|
4
|
-
import type { JsonRpcRequest } from
|
|
1
|
+
import { JsonRpcError } from "@metamask/rpc-errors";
|
|
2
|
+
import type { Json } from "@metamask/utils";
|
|
3
|
+
import { MiddlewareContext } from "./MiddlewareContext.cjs";
|
|
4
|
+
import type { JsonRpcRequest } from "./utils.cjs";
|
|
5
5
|
/**
|
|
6
6
|
* Create a deep clone of a value as follows:
|
|
7
7
|
* - Assumes acyclical objects
|
|
@@ -72,4 +72,4 @@ export declare function propagateToRequest(req: Record<string, unknown>, context
|
|
|
72
72
|
*/
|
|
73
73
|
export declare function deserializeError(thrown: unknown): Error | JsonRpcError<Json>;
|
|
74
74
|
export {};
|
|
75
|
-
//# sourceMappingURL=compatibility-utils.d.
|
|
75
|
+
//# sourceMappingURL=compatibility-utils.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compatibility-utils.d.cts","sourceRoot":"","sources":["../../src/v2/compatibility-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,YAAY,EAAE,6BAA6B;AACxE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C,OAAO,EAAE,iBAAiB,EAAE,gCAA+B;AAE3D,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAmB;AAIjD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,yCACY,CAAC;AAKnC,KAAK,UAAU,CAAC,IAAI,IAAI,IAAI,SAAS,SAAS,CAAC,MAAM,SAAS,CAAC,EAAE,GAC7D,UAAU,CAAC,SAAS,CAAC,EAAE,GACvB,IAAI,SAAS,MAAM,GACjB;IACE,CAAC,UAAU,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,UAAU,CAC3D,IAAI,CAAC,GAAG,CAAC,CACV;CACF,GACD,IAAI,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,YAAY,UAAwC,CAAC;AAElE;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,cAAc,EAC9D,GAAG,EAAE,OAAO,GACX,OAAO,CAUT;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAC1E,GAAG,EAAE,OAAO,GACX,iBAAiB,CAInB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,OAAO,EAAE,iBAAiB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAClD,IAAI,CAWN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,OAAO,EAAE,iBAAiB,GACzB,IAAI,CAUN;AA2BD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CA4C5E"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { JsonRpcError } from "@metamask/rpc-errors";
|
|
2
|
+
import type { Json } from "@metamask/utils";
|
|
3
|
+
import { MiddlewareContext } from "./MiddlewareContext.mjs";
|
|
4
|
+
import type { JsonRpcRequest } from "./utils.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Create a deep clone of a value as follows:
|
|
7
|
+
* - Assumes acyclical objects
|
|
8
|
+
* - Does not copy property descriptors (i.e. uses mutable defaults)
|
|
9
|
+
* - Ignores non-enumerable properties
|
|
10
|
+
* - Ignores getters and setters
|
|
11
|
+
*
|
|
12
|
+
* @throws If the value is an object with a circular reference.
|
|
13
|
+
* @param value - The value to clone.
|
|
14
|
+
* @returns The cloned value.
|
|
15
|
+
*/
|
|
16
|
+
export declare const deepClone: <Type>(value: Type) => DeepCloned<Type>;
|
|
17
|
+
type DeepCloned<Type> = Type extends readonly (infer ArrayType)[] ? DeepCloned<ArrayType>[] : Type extends object ? {
|
|
18
|
+
-readonly [Key in keyof Type & (string | number)]: DeepCloned<Type[Key]>;
|
|
19
|
+
} : Type;
|
|
20
|
+
/**
|
|
21
|
+
* Standard JSON-RPC request properties.
|
|
22
|
+
*/
|
|
23
|
+
export declare const requestProps: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Make a JSON-RPC request from a legacy request. Clones the params to avoid
|
|
26
|
+
* freezing them, which could cause errors in an involved legacy engine.
|
|
27
|
+
*
|
|
28
|
+
* @param req - The legacy request to make a request from.
|
|
29
|
+
* @returns The JSON-RPC request.
|
|
30
|
+
*/
|
|
31
|
+
export declare function fromLegacyRequest<Request extends JsonRpcRequest>(req: Request): Request;
|
|
32
|
+
/**
|
|
33
|
+
* Make a middleware context from a legacy request by copying over all non-JSON-RPC
|
|
34
|
+
* properties from the request to the context object.
|
|
35
|
+
*
|
|
36
|
+
* @param req - The legacy request to make a context from.
|
|
37
|
+
* @returns The middleware context.
|
|
38
|
+
*/
|
|
39
|
+
export declare function makeContext<Request extends Record<string | symbol, unknown>>(req: Request): MiddlewareContext;
|
|
40
|
+
/**
|
|
41
|
+
* Copies non-JSON-RPC string properties from the request to the context.
|
|
42
|
+
*
|
|
43
|
+
* For compatibility with our problematic practice of appending non-standard
|
|
44
|
+
* fields to requests for inter-middleware communication in the legacy engine.
|
|
45
|
+
*
|
|
46
|
+
* **ATTN:** Only string properties that do not already exist in the context
|
|
47
|
+
* are copied.
|
|
48
|
+
*
|
|
49
|
+
* @param req - The request to propagate the context from.
|
|
50
|
+
* @param context - The context to propagate to.
|
|
51
|
+
*/
|
|
52
|
+
export declare function propagateToContext(req: Record<string, unknown>, context: MiddlewareContext<Record<string, unknown>>): void;
|
|
53
|
+
/**
|
|
54
|
+
* Copies non-JSON-RPC string properties from the context to the request.
|
|
55
|
+
*
|
|
56
|
+
* For compatibility with our problematic practice of appending non-standard
|
|
57
|
+
* fields to requests for inter-middleware communication in the legacy engine.
|
|
58
|
+
*
|
|
59
|
+
* **ATTN:** Only string properties are copied.
|
|
60
|
+
*
|
|
61
|
+
* @param req - The request to propagate the context to.
|
|
62
|
+
* @param context - The context to propagate from.
|
|
63
|
+
*/
|
|
64
|
+
export declare function propagateToRequest(req: Record<string, unknown>, context: MiddlewareContext): void;
|
|
65
|
+
/**
|
|
66
|
+
* Unserialize an error from a thrown value. Creates a {@link JsonRpcError} if
|
|
67
|
+
* the thrown value is an object with a `code` property. Otherwise, creates a
|
|
68
|
+
* plain {@link Error}.
|
|
69
|
+
*
|
|
70
|
+
* @param thrown - The thrown value to unserialize.
|
|
71
|
+
* @returns The unserialized error.
|
|
72
|
+
*/
|
|
73
|
+
export declare function deserializeError(thrown: unknown): Error | JsonRpcError<Json>;
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=compatibility-utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compatibility-utils.d.mts","sourceRoot":"","sources":["../../src/v2/compatibility-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,YAAY,EAAE,6BAA6B;AACxE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C,OAAO,EAAE,iBAAiB,EAAE,gCAA+B;AAE3D,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAmB;AAIjD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,yCACY,CAAC;AAKnC,KAAK,UAAU,CAAC,IAAI,IAAI,IAAI,SAAS,SAAS,CAAC,MAAM,SAAS,CAAC,EAAE,GAC7D,UAAU,CAAC,SAAS,CAAC,EAAE,GACvB,IAAI,SAAS,MAAM,GACjB;IACE,CAAC,UAAU,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,UAAU,CAC3D,IAAI,CAAC,GAAG,CAAC,CACV;CACF,GACD,IAAI,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,YAAY,UAAwC,CAAC;AAElE;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,cAAc,EAC9D,GAAG,EAAE,OAAO,GACX,OAAO,CAUT;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAC1E,GAAG,EAAE,OAAO,GACX,iBAAiB,CAInB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,OAAO,EAAE,iBAAiB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAClD,IAAI,CAWN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,OAAO,EAAE,iBAAiB,GACzB,IAAI,CAUN;AA2BD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CA4C5E"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { getMessageFromCode, JsonRpcError } from
|
|
2
|
-
import { hasProperty, isObject, isValidJson } from
|
|
1
|
+
import { getMessageFromCode, JsonRpcError } from "@metamask/rpc-errors";
|
|
2
|
+
import { hasProperty, isObject, isValidJson } from "@metamask/utils";
|
|
3
3
|
// ATTN: We must NOT use 'klona/full' here because it freezes properties on the clone.
|
|
4
|
-
import { klona } from
|
|
5
|
-
import { MiddlewareContext } from
|
|
6
|
-
import { stringify } from
|
|
4
|
+
import { klona } from "klona";
|
|
5
|
+
import { MiddlewareContext } from "./MiddlewareContext.mjs";
|
|
6
|
+
import { stringify } from "./utils.mjs";
|
|
7
7
|
// Legacy engine compatibility utils
|
|
8
8
|
/**
|
|
9
9
|
* Create a deep clone of a value as follows:
|
|
@@ -155,4 +155,4 @@ export function deserializeError(thrown) {
|
|
|
155
155
|
}
|
|
156
156
|
return error;
|
|
157
157
|
}
|
|
158
|
-
//# sourceMappingURL=compatibility-utils.
|
|
158
|
+
//# sourceMappingURL=compatibility-utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compatibility-utils.mjs","sourceRoot":"","sources":["../../src/v2/compatibility-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,6BAA6B;AAExE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,wBAAwB;AACrE,sFAAsF;AACtF,OAAO,EAAE,KAAK,EAAE,cAAc;AAE9B,OAAO,EAAE,iBAAiB,EAAE,gCAA+B;AAC3D,OAAO,EAAE,SAAS,EAAE,oBAAmB;AAGvC,oCAAoC;AAEpC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAO,KAAW,EAAoB,EAAE,CAC/D,KAAK,CAAC,KAAK,CAAqB,CAAC;AAenC;;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,OAAO,EAAE,KAAc;QACvB,MAAM,EAAE,GAAG,CAAC,MAAM;KACC,CAAC;IACtB,OAAO,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC;IACpB,IAAI,WA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AO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IAC3B,CAAC;SAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,GAAG,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;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,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAEpE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { OptionalDataWithOptionalCause } from '@metamask/rpc-errors';\nimport { getMessageFromCode, JsonRpcError } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty, isObject, isValidJson } 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.js';\nimport { stringify } from './utils.js';\nimport type { JsonRpcRequest } from './utils.js';\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 = <Type>(value: Type): DeepCloned<Type> =>\n klona(value) as DeepCloned<Type>;\n\n// Matching the default implementation of klona, this type:\n// - Removes readonly modifiers\n// - Excludes non-enumerable / symbol properties\ntype DeepCloned<Type> = Type extends readonly (infer ArrayType)[]\n ? DeepCloned<ArrayType>[]\n : Type extends object\n ? {\n -readonly [Key in keyof Type & (string | number)]: DeepCloned<\n Type[Key]\n >;\n }\n : Type;\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): void {\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): void {\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 * Deserialize the error property for a thrown error, merging in the cause where possible.\n *\n * @param data - The data from the thrown error.\n * @param cause - The cause from the thrown error.\n * @returns The deserialized data.\n */\nfunction deserializeData(\n data: unknown,\n cause: unknown,\n): OptionalDataWithOptionalCause {\n // If data is an object, merge with cause.\n if (isObject(data)) {\n return { ...data, cause: cause ?? data.cause };\n }\n\n // If data is a JSON value that's not mergeable.\n if (isValidJson(data)) {\n return data;\n }\n\n // If data is undefined, only use cause.\n return { cause };\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, deserializeData(data, cause));\n\n if (typeof stack === 'string') {\n error.stack = stack;\n }\n\n return error;\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMethodMiddleware = void 0;
|
|
4
|
+
const messenger_1 = require("@metamask/messenger");
|
|
5
|
+
const utils_js_1 = require("./utils.cjs");
|
|
6
|
+
/**
|
|
7
|
+
* Create a JSON-RPC middleware that handles the passed JSON-RPC method handlers using the messenger and hooks.
|
|
8
|
+
*
|
|
9
|
+
* @param options The options.
|
|
10
|
+
* @param options.handlers - The JSON-RPC method handler implementations.
|
|
11
|
+
* @param options.messenger - The messenger to be used by the handlers.
|
|
12
|
+
* @param options.hooks - The hooks to be used by the handlers.
|
|
13
|
+
* @returns A JsonRpcEngineV2 middleware.
|
|
14
|
+
*/
|
|
15
|
+
function createMethodMiddleware(options) {
|
|
16
|
+
const { messenger: rootMessenger } = options;
|
|
17
|
+
const allHooks = options.hooks;
|
|
18
|
+
const expectedHookNames = new Set(Object.values(options.handlers).flatMap((handler) => handler.hookNames ? Object.getOwnPropertyNames(handler.hookNames) : []));
|
|
19
|
+
(0, utils_js_1.assertExpectedHooks)(allHooks, expectedHookNames);
|
|
20
|
+
const handlers = Object.entries(options.handlers).reduce((accumulator, [handlerName, handler]) => {
|
|
21
|
+
const handlerHooks = (0, utils_js_1.selectHooks)(allHooks, handler.hookNames) ?? {};
|
|
22
|
+
const handlerMessenger = (0, utils_js_1.createHandlerMessenger)({
|
|
23
|
+
namespace: handlerName,
|
|
24
|
+
actionNames: handler.actionNames,
|
|
25
|
+
rootMessenger,
|
|
26
|
+
});
|
|
27
|
+
accumulator[handlerName] = {
|
|
28
|
+
implementation: handler.implementation,
|
|
29
|
+
hooks: handlerHooks,
|
|
30
|
+
messenger: handlerMessenger,
|
|
31
|
+
};
|
|
32
|
+
return accumulator;
|
|
33
|
+
}, {});
|
|
34
|
+
return ({ request, context, next }) => {
|
|
35
|
+
const handler = handlers[request.method];
|
|
36
|
+
if (handler === undefined) {
|
|
37
|
+
return next();
|
|
38
|
+
}
|
|
39
|
+
const { implementation, hooks, messenger } = handler;
|
|
40
|
+
return implementation({ request, context, next, hooks, messenger });
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.createMethodMiddleware = createMethodMiddleware;
|
|
44
|
+
//# sourceMappingURL=createMethodMiddleware.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMethodMiddleware.cjs","sourceRoot":"","sources":["../../src/v2/createMethodMiddleware.ts"],"names":[],"mappings":";;;AAAA,mDAAkE;AAIlE,0CAQoB;AAsFpB;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CAIpC,OAAgD;IAEhD,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAgC,CAAC;IAE1D,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAC/B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAClD,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CACvE,CACF,CAAC;IACF,IAAA,8BAAmB,EAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;IAEjD,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAEtD,CAAC,WAAW,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,EAAE,EAAE;QACxC,MAAM,YAAY,GAAG,IAAA,sBAAW,EAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QACpE,MAAM,gBAAgB,GAAG,IAAA,iCAAsB,EAE7C;YACA,SAAS,EAAE,WAAW;YACtB,WAAW,EAAE,OAAO,CAAC,WAER;YACb,aAAa;SACd,CAAC,CAAC;QAEH,WAAW,CAAC,WAAW,CAAC,GAAG;YACzB,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,KAAK,EAAE,YAAY;YACnB,SAAS,EAAE,gBAAgB;SAC5B,CAAC;QACF,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;QACpC,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAErD,OAAO,cAAc,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IACtE,CAAC,CAAC;AACJ,CAAC;AAhDD,wDAgDC","sourcesContent":["import { ActionConstraint, Messenger } from '@metamask/messenger';\n\nimport { JsonRpcMiddleware, Next } from './JsonRpcEngineV2.js';\nimport { ContextConstraint } from './MiddlewareContext.js';\nimport {\n assertExpectedHooks,\n createHandlerMessenger,\n selectHooks,\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n UnionToIntersection,\n} from './utils.js';\n\ntype HandlerActions<Handler> = Handler extends {\n implementation: (options: infer Options) => unknown;\n}\n ? Options extends { messenger: Messenger<string, infer Actions> }\n ? Actions\n : never\n : never;\n\ntype HandlerHooks<Handler> = Handler extends {\n implementation: (options: infer Options) => unknown;\n}\n ? Options extends { hooks: infer Hooks }\n ? Hooks\n : never\n : never;\n\n/**\n * A `JsonRpcEngineV2` method middleware handler.\n */\nexport type MethodHandler<\n Hooks extends Record<string, unknown> = never,\n MessengerActions extends ActionConstraint = never,\n Parameters extends JsonRpcParams = JsonRpcParams,\n Result extends Json = Json,\n Context extends ContextConstraint = ContextConstraint,\n> = {\n implementation: (options: {\n request: Readonly<JsonRpcRequest<Parameters>>;\n context: Context;\n next: Next<JsonRpcRequest>;\n messenger: Messenger<string, MessengerActions>;\n hooks: Hooks;\n }) => Promise<Result> | Result;\n} & ([Hooks] extends [never]\n ? { hookNames?: undefined }\n : { hookNames: { [Key in keyof Hooks]: true } }) &\n ([MessengerActions] extends [never]\n ? { actionNames?: undefined }\n : { actionNames: MessengerActions['type'][] });\n\ntype AnyMethodHandler = {\n implementation(\n this: void,\n options: {\n request: Readonly<JsonRpcRequest>;\n context: ContextConstraint;\n next: Next<JsonRpcRequest>;\n messenger: unknown;\n hooks: unknown;\n },\n ): Promise<Json> | Json;\n hookNames?: Record<string, true>;\n actionNames?: readonly string[];\n};\n\ntype CreateMethodMiddlewareBaseOptions<\n Handlers extends Record<string, AnyMethodHandler>,\n> = {\n handlers: Handlers;\n hooks: [HandlerHooks<Handlers[keyof Handlers]>] extends [never]\n ? Record<string, never>\n : UnionToIntersection<HandlerHooks<Handlers[keyof Handlers]>>;\n};\n\n/**\n * Options for {@link createMethodMiddleware}.\n */\nexport type CreateMethodMiddlewareOptions<\n Handlers extends Record<string, AnyMethodHandler>,\n> = CreateMethodMiddlewareBaseOptions<Handlers> &\n ([HandlerActions<Handlers[keyof Handlers]>] extends [never]\n ? {\n messenger?: undefined;\n }\n : {\n messenger: Messenger<string, HandlerActions<Handlers[keyof Handlers]>>;\n });\n\ntype ResolvedHandler = {\n implementation: AnyMethodHandler['implementation'];\n hooks: Record<string, unknown>;\n messenger?: Messenger<string, ActionConstraint> | undefined;\n};\n\n/**\n * Create a JSON-RPC middleware that handles the passed JSON-RPC method handlers using the messenger and hooks.\n *\n * @param options The options.\n * @param options.handlers - The JSON-RPC method handler implementations.\n * @param options.messenger - The messenger to be used by the handlers.\n * @param options.hooks - The hooks to be used by the handlers.\n * @returns A JsonRpcEngineV2 middleware.\n */\nexport function createMethodMiddleware<\n Handlers extends Record<string, AnyMethodHandler>,\n Context extends ContextConstraint,\n>(\n options: CreateMethodMiddlewareOptions<Handlers>,\n): JsonRpcMiddleware<JsonRpcRequest, Json, Context> {\n const { messenger: rootMessenger } = options;\n const allHooks = options.hooks as Record<string, unknown>;\n\n const expectedHookNames = new Set(\n Object.values(options.handlers).flatMap((handler) =>\n handler.hookNames ? Object.getOwnPropertyNames(handler.hookNames) : [],\n ),\n );\n assertExpectedHooks(allHooks, expectedHookNames);\n\n const handlers = Object.entries(options.handlers).reduce<\n Record<string, ResolvedHandler>\n >((accumulator, [handlerName, handler]) => {\n const handlerHooks = selectHooks(allHooks, handler.hookNames) ?? {};\n const handlerMessenger = createHandlerMessenger<\n HandlerActions<Handlers[keyof Handlers]>\n >({\n namespace: handlerName,\n actionNames: handler.actionNames as\n | readonly HandlerActions<Handlers[keyof Handlers]>['type'][]\n | undefined,\n rootMessenger,\n });\n\n accumulator[handlerName] = {\n implementation: handler.implementation,\n hooks: handlerHooks,\n messenger: handlerMessenger,\n };\n return accumulator;\n }, {});\n\n return ({ request, context, next }) => {\n const handler = handlers[request.method];\n if (handler === undefined) {\n return next();\n }\n\n const { implementation, hooks, messenger } = handler;\n\n return implementation({ request, context, next, hooks, messenger });\n };\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ActionConstraint, Messenger } from
|
|
2
|
-
import { JsonRpcMiddleware, Next } from
|
|
3
|
-
import { ContextConstraint } from
|
|
4
|
-
import { Json, JsonRpcParams, JsonRpcRequest, UnionToIntersection } from
|
|
1
|
+
import { ActionConstraint, Messenger } from "@metamask/messenger";
|
|
2
|
+
import { JsonRpcMiddleware, Next } from "./JsonRpcEngineV2.cjs";
|
|
3
|
+
import { ContextConstraint } from "./MiddlewareContext.cjs";
|
|
4
|
+
import { Json, JsonRpcParams, JsonRpcRequest, UnionToIntersection } from "./utils.cjs";
|
|
5
5
|
type HandlerActions<Handler> = Handler extends {
|
|
6
6
|
implementation: (options: infer Options) => unknown;
|
|
7
7
|
} ? Options extends {
|
|
@@ -68,4 +68,4 @@ export type CreateMethodMiddlewareOptions<Handlers extends Record<string, AnyMet
|
|
|
68
68
|
*/
|
|
69
69
|
export declare function createMethodMiddleware<Handlers extends Record<string, AnyMethodHandler>, Context extends ContextConstraint>(options: CreateMethodMiddlewareOptions<Handlers>): JsonRpcMiddleware<JsonRpcRequest, Json, Context>;
|
|
70
70
|
export {};
|
|
71
|
-
//# sourceMappingURL=createMethodMiddleware.d.
|
|
71
|
+
//# sourceMappingURL=createMethodMiddleware.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMethodMiddleware.d.cts","sourceRoot":"","sources":["../../src/v2/createMethodMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,4BAA4B;AAElE,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,8BAA6B;AAC/D,OAAO,EAAE,iBAAiB,EAAE,gCAA+B;AAC3D,OAAO,EAIL,IAAI,EACJ,aAAa,EACb,cAAc,EACd,mBAAmB,EACpB,oBAAmB;AAEpB,KAAK,cAAc,CAAC,OAAO,IAAI,OAAO,SAAS;IAC7C,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,OAAO,KAAK,OAAO,CAAC;CACrD,GACG,OAAO,SAAS;IAAE,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,CAAA;CAAE,GAC7D,OAAO,GACP,KAAK,GACP,KAAK,CAAC;AAEV,KAAK,YAAY,CAAC,OAAO,IAAI,OAAO,SAAS;IAC3C,cAAc,EAAE,CAAC,OAAO,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