@metamask-previews/json-rpc-engine 10.2.4-preview-45a82ea8e → 10.2.4-preview-d8ff44d

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +5 -5
  2. package/dist/index.cjs +1 -3
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +0 -2
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +0 -2
  7. package/dist/index.d.mts.map +1 -1
  8. package/dist/index.mjs +0 -1
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/v2/createMethodMiddleware.cjs +31 -8
  11. package/dist/v2/createMethodMiddleware.cjs.map +1 -1
  12. package/dist/v2/createMethodMiddleware.d.cts +15 -12
  13. package/dist/v2/createMethodMiddleware.d.cts.map +1 -1
  14. package/dist/v2/createMethodMiddleware.d.mts +15 -12
  15. package/dist/v2/createMethodMiddleware.d.mts.map +1 -1
  16. package/dist/v2/createMethodMiddleware.mjs +28 -6
  17. package/dist/v2/createMethodMiddleware.mjs.map +1 -1
  18. package/dist/v2/index.cjs +2 -2
  19. package/dist/v2/index.cjs.map +1 -1
  20. package/dist/v2/index.d.cts +2 -2
  21. package/dist/v2/index.d.cts.map +1 -1
  22. package/dist/v2/index.d.mts +2 -2
  23. package/dist/v2/index.d.mts.map +1 -1
  24. package/dist/v2/index.mjs +2 -2
  25. package/dist/v2/index.mjs.map +1 -1
  26. package/dist/v2/utils.cjs +1 -76
  27. package/dist/v2/utils.cjs.map +1 -1
  28. package/dist/v2/utils.d.cts +0 -40
  29. package/dist/v2/utils.d.cts.map +1 -1
  30. package/dist/v2/utils.d.mts +0 -40
  31. package/dist/v2/utils.d.mts.map +1 -1
  32. package/dist/v2/utils.mjs +0 -72
  33. package/dist/v2/utils.mjs.map +1 -1
  34. package/package.json +2 -2
  35. package/dist/createMethodMiddleware.cjs +0 -56
  36. package/dist/createMethodMiddleware.cjs.map +0 -1
  37. package/dist/createMethodMiddleware.d.cts +0 -79
  38. package/dist/createMethodMiddleware.d.cts.map +0 -1
  39. package/dist/createMethodMiddleware.d.mts +0 -79
  40. package/dist/createMethodMiddleware.d.mts.map +0 -1
  41. package/dist/createMethodMiddleware.mjs +0 -52
  42. package/dist/createMethodMiddleware.mjs.map +0 -1
package/dist/v2/utils.cjs CHANGED
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createHandlerMessenger = exports.assertExpectedHooks = exports.selectHooks = exports.JsonRpcEngineError = exports.isInstance = exports.stringify = exports.isNotification = exports.isRequest = void 0;
5
- const messenger_1 = require("@metamask/messenger");
4
+ exports.JsonRpcEngineError = exports.isInstance = exports.stringify = exports.isNotification = exports.isRequest = void 0;
6
5
  const utils_1 = require("@metamask/utils");
7
6
  const isRequest = (message) => (0, utils_1.hasProperty)(message, 'id');
8
7
  exports.isRequest = isRequest;
@@ -50,78 +49,4 @@ class JsonRpcEngineError extends Error {
50
49
  }
51
50
  exports.JsonRpcEngineError = JsonRpcEngineError;
52
51
  _a = JsonRpcEngineErrorSymbol;
53
- // Method middleware utils
54
- /**
55
- * Returns the subset of the specified `hooks` that are included in the
56
- * `hookNames` object. This is a Principle of Least Authority (POLA) measure
57
- * to ensure that each RPC method implementation only has access to the
58
- * API "hooks" it needs to do its job.
59
- *
60
- * @param hooks - The hooks to select from.
61
- * @param hookNames - The names of the hooks to select.
62
- * @returns The selected hooks, or `undefined` if `hookNames` is not provided.
63
- * @template Hooks - The hooks to select from.
64
- * @template HookName - The names of the hooks to select.
65
- */
66
- function selectHooks(hooks, hookNames) {
67
- if (hookNames) {
68
- return Object.keys(hookNames).reduce((subset, name) => {
69
- const hookName = name;
70
- subset[hookName] = hooks[hookName];
71
- return subset;
72
- }, {});
73
- }
74
- return undefined;
75
- }
76
- exports.selectHooks = selectHooks;
77
- /**
78
- * Asserts that `hooks` contains exactly the hook names in `expectedHookNames`.
79
- * Throws on any missing hooks, then on any extraneous hooks.
80
- *
81
- * @param hooks - The hooks object to validate.
82
- * @param expectedHookNames - The expected hook names.
83
- */
84
- function assertExpectedHooks(hooks, expectedHookNames) {
85
- const missingHookNames = [];
86
- expectedHookNames.forEach((hookName) => {
87
- if (!(0, utils_1.hasProperty)(hooks, hookName)) {
88
- missingHookNames.push(hookName);
89
- }
90
- });
91
- if (missingHookNames.length > 0) {
92
- throw new Error(`Missing expected hooks:\n\n${missingHookNames.join('\n')}\n`);
93
- }
94
- const extraneousHookNames = Object.getOwnPropertyNames(hooks).filter((hookName) => !expectedHookNames.has(hookName));
95
- if (extraneousHookNames.length > 0) {
96
- throw new Error(`Received unexpected hooks:\n\n${extraneousHookNames.join('\n')}\n`);
97
- }
98
- }
99
- exports.assertExpectedHooks = assertExpectedHooks;
100
- /**
101
- * Creates a per-handler messenger namespaced to `namespace`, and delegates the
102
- * specified `actionNames` from `rootMessenger` to it. This lets each handler
103
- * call only the actions it declared, per POLA.
104
- *
105
- * @param options - The options.
106
- * @param options.namespace - The namespace for the handler messenger.
107
- * @param options.actionNames - Actions to delegate from the root messenger.
108
- * @param options.rootMessenger - The root messenger to delegate from. Required
109
- * when `actionNames` are provided.
110
- * @returns The per-handler messenger.
111
- */
112
- function createHandlerMessenger({ namespace, actionNames, rootMessenger, }) {
113
- if (!actionNames) {
114
- return undefined;
115
- }
116
- if (!rootMessenger) {
117
- throw new Error('A messenger is required when a handler declares actionNames.');
118
- }
119
- const handlerMessenger = new messenger_1.Messenger({ namespace, parent: rootMessenger });
120
- rootMessenger.delegate({
121
- actions: actionNames,
122
- messenger: handlerMessenger,
123
- });
124
- return handlerMessenger;
125
- }
126
- exports.createHandlerMessenger = createHandlerMessenger;
127
52
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":";;;;AACA,mDAAgD;AAChD,2CAAwD;AAkBjD,MA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AI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;IACJ,CAAC;IAED,MAAM,gBAAgB,GAAG,IAAI,qBAAS,CAKpC,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;IAExC,aAAa,CAAC,QAAQ,CAAC;QACrB,OAAO,EAAE,WAAgC;QACzC,SAAS,EAAE,gBAAgB;KAC5B,CAAC,CAAC;IAEH,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAhCD,wDAgCC","sourcesContent":["import type { ActionConstraint } from '@metamask/messenger';\nimport { Messenger } from '@metamask/messenger';\nimport { hasProperty, isObject } from '@metamask/utils';\nimport type {\n JsonRpcNotification,\n JsonRpcParams,\n 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 message: JsonRpcCall<Params> | Readonly<JsonRpcCall<Params>>,\n): message is JsonRpcRequest<Params> => hasProperty(message, 'id');\n\nexport const isNotification = <Params extends JsonRpcParams>(\n message: JsonRpcCall<Params>,\n): message is JsonRpcNotification<Params> => !isRequest(message);\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<Union> = (\n Union extends never ? never : (k: Union) => void\n) extends (k: infer Args) => void\n ? Args\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\n/**\n * The implementation of static `isInstance` methods for classes that have them.\n *\n * @param value - The value to check.\n * @param symbol - The symbol property to check for.\n * @returns Whether the value has `{ [symbol]: true }` in its prototype chain.\n */\nexport const isInstance = (\n value: unknown,\n symbol: symbol,\n): value is { [key: symbol]: true } =>\n isObject(value) && symbol in value && value[symbol] === true;\n\nconst JsonRpcEngineErrorSymbol = Symbol.for(\n 'json-rpc-engine#JsonRpcEngineError',\n);\n\nexport class JsonRpcEngineError extends Error {\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 [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: unknown): value is JsonRpcEngineError {\n return isInstance(value, JsonRpcEngineErrorSymbol);\n }\n}\n\n// Method middleware utils\n\n/**\n * Returns the subset of the specified `hooks` that are included in the\n * `hookNames` object. This is a Principle of Least Authority (POLA) measure\n * to ensure that each RPC method implementation only has access to the\n * API \"hooks\" it needs to do its job.\n *\n * @param hooks - The hooks to select from.\n * @param hookNames - The names of the hooks to select.\n * @returns The selected hooks, or `undefined` if `hookNames` is not provided.\n * @template Hooks - The hooks to select from.\n * @template HookName - The names of the hooks to select.\n */\nexport function selectHooks<Hooks, HookName extends keyof Hooks>(\n hooks: Hooks,\n hookNames?: Record<HookName, true>,\n): Pick<Hooks, HookName> | undefined {\n if (hookNames) {\n return Object.keys(hookNames).reduce<Partial<Pick<Hooks, HookName>>>(\n (subset, name) => {\n const hookName = name as HookName;\n subset[hookName] = hooks[hookName];\n return subset;\n },\n {},\n ) as Pick<Hooks, HookName>;\n }\n return undefined;\n}\n\n/**\n * Asserts that `hooks` contains exactly the hook names in `expectedHookNames`.\n * Throws on any missing hooks, then on any extraneous hooks.\n *\n * @param hooks - The hooks object to validate.\n * @param expectedHookNames - The expected hook names.\n */\nexport function assertExpectedHooks(\n hooks: Record<string, unknown>,\n expectedHookNames: Set<string>,\n): void {\n const missingHookNames: string[] = [];\n expectedHookNames.forEach((hookName) => {\n if (!hasProperty(hooks, hookName)) {\n missingHookNames.push(hookName);\n }\n });\n if (missingHookNames.length > 0) {\n throw new Error(\n `Missing expected hooks:\\n\\n${missingHookNames.join('\\n')}\\n`,\n );\n }\n\n const extraneousHookNames = Object.getOwnPropertyNames(hooks).filter(\n (hookName) => !expectedHookNames.has(hookName),\n );\n if (extraneousHookNames.length > 0) {\n throw new Error(\n `Received unexpected hooks:\\n\\n${extraneousHookNames.join('\\n')}\\n`,\n );\n }\n}\n\n/**\n * Creates a per-handler messenger namespaced to `namespace`, and delegates the\n * specified `actionNames` from `rootMessenger` to it. This lets each handler\n * call only the actions it declared, per POLA.\n *\n * @param options - The options.\n * @param options.namespace - The namespace for the handler messenger.\n * @param options.actionNames - Actions to delegate from the root messenger.\n * @param options.rootMessenger - The root messenger to delegate from. Required\n * when `actionNames` are provided.\n * @returns The per-handler messenger.\n */\nexport function createHandlerMessenger<Actions extends ActionConstraint>({\n namespace,\n actionNames,\n rootMessenger,\n}: {\n namespace: string;\n actionNames: readonly Actions['type'][] | undefined;\n rootMessenger?: Messenger<string, Actions> | undefined;\n}): Messenger<string, Actions> | undefined {\n if (!actionNames) {\n return undefined;\n }\n\n if (!rootMessenger) {\n throw new Error(\n 'A messenger is required when a handler declares actionNames.',\n );\n }\n\n const handlerMessenger = new Messenger<\n string,\n Actions,\n never,\n typeof rootMessenger\n >({ namespace, parent: rootMessenger });\n\n rootMessenger.delegate({\n actions: actionNames as Actions['type'][],\n messenger: handlerMessenger,\n });\n\n return handlerMessenger;\n}\n"]}
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":";;;;AAAA,2CAAwD;AAkBjD,MAAM,SAAS,GAAG,CACvB,OAA4D,EACzB,EAAE,CAAC,IAAA,mBAAW,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAFtD,QAAA,SAAS,aAE6C;AAE5D,MAAM,cAAc,GAAG,CAC5B,OAA4B,EACY,EAAE,CAAC,CAAC,IAAA,iBAAS,EAAC,OAAO,CAAC,CAAC;AAFpD,QAAA,cAAc,kBAEsC;AAgBjE;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,KAAc;IACtC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC;AAFD,8BAEC;AAED;;;;;;GAMG;AACI,MAAM,UAAU,GAAG,CACxB,KAAc,EACd,MAAc,EACoB,EAAE,CACpC,IAAA,gBAAQ,EAAC,KAAK,CAAC,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;AAJlD,QAAA,UAAU,cAIwC;AAE/D,MAAM,wBAAwB,GAAG,MAAM,CAAC,GAAG,CACzC,oCAAoC,CACrC,CAAC;AAEF,MAAa,kBAAmB,SAAQ,KAAK;IAM3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QANjB,4EAA4E;QAC5E,0BAA0B;QAC1B,gDAAgD;QAC/B,QAA0B,GAAG,IAAI,CAAC;QAIjD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,KAAc;QAC9B,OAAO,IAAA,kBAAU,EAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;IACrD,CAAC;CACF;AArBD,gDAqBC;KAjBmB,wBAAwB","sourcesContent":["import { hasProperty, isObject } from '@metamask/utils';\nimport type {\n JsonRpcNotification,\n JsonRpcParams,\n 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 message: JsonRpcCall<Params> | Readonly<JsonRpcCall<Params>>,\n): message is JsonRpcRequest<Params> => hasProperty(message, 'id');\n\nexport const isNotification = <Params extends JsonRpcParams>(\n message: JsonRpcCall<Params>,\n): message is JsonRpcNotification<Params> => !isRequest(message);\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<Union> = (\n Union extends never ? never : (k: Union) => void\n) extends (k: infer Args) => void\n ? Args\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\n/**\n * The implementation of static `isInstance` methods for classes that have them.\n *\n * @param value - The value to check.\n * @param symbol - The symbol property to check for.\n * @returns Whether the value has `{ [symbol]: true }` in its prototype chain.\n */\nexport const isInstance = (\n value: unknown,\n symbol: symbol,\n): value is { [key: symbol]: true } =>\n isObject(value) && symbol in value && value[symbol] === true;\n\nconst JsonRpcEngineErrorSymbol = Symbol.for(\n 'json-rpc-engine#JsonRpcEngineError',\n);\n\nexport class JsonRpcEngineError extends Error {\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 [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: unknown): value is JsonRpcEngineError {\n return isInstance(value, JsonRpcEngineErrorSymbol);\n }\n}\n"]}
@@ -1,5 +1,3 @@
1
- import type { ActionConstraint } from "@metamask/messenger";
2
- import { Messenger } from "@metamask/messenger";
3
1
  import type { JsonRpcNotification, JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
4
2
  export type { Json, JsonRpcParams, JsonRpcRequest, JsonRpcNotification, } from "@metamask/utils";
5
3
  export type JsonRpcCall<Params extends JsonRpcParams = JsonRpcParams> = JsonRpcNotification<Params> | JsonRpcRequest<Params>;
@@ -44,42 +42,4 @@ export declare class JsonRpcEngineError extends Error {
44
42
  */
45
43
  static isInstance(value: unknown): value is JsonRpcEngineError;
46
44
  }
47
- /**
48
- * Returns the subset of the specified `hooks` that are included in the
49
- * `hookNames` object. This is a Principle of Least Authority (POLA) measure
50
- * to ensure that each RPC method implementation only has access to the
51
- * API "hooks" it needs to do its job.
52
- *
53
- * @param hooks - The hooks to select from.
54
- * @param hookNames - The names of the hooks to select.
55
- * @returns The selected hooks, or `undefined` if `hookNames` is not provided.
56
- * @template Hooks - The hooks to select from.
57
- * @template HookName - The names of the hooks to select.
58
- */
59
- export declare function selectHooks<Hooks, HookName extends keyof Hooks>(hooks: Hooks, hookNames?: Record<HookName, true>): Pick<Hooks, HookName> | undefined;
60
- /**
61
- * Asserts that `hooks` contains exactly the hook names in `expectedHookNames`.
62
- * Throws on any missing hooks, then on any extraneous hooks.
63
- *
64
- * @param hooks - The hooks object to validate.
65
- * @param expectedHookNames - The expected hook names.
66
- */
67
- export declare function assertExpectedHooks(hooks: Record<string, unknown>, expectedHookNames: Set<string>): void;
68
- /**
69
- * Creates a per-handler messenger namespaced to `namespace`, and delegates the
70
- * specified `actionNames` from `rootMessenger` to it. This lets each handler
71
- * call only the actions it declared, per POLA.
72
- *
73
- * @param options - The options.
74
- * @param options.namespace - The namespace for the handler messenger.
75
- * @param options.actionNames - Actions to delegate from the root messenger.
76
- * @param options.rootMessenger - The root messenger to delegate from. Required
77
- * when `actionNames` are provided.
78
- * @returns The per-handler messenger.
79
- */
80
- export declare function createHandlerMessenger<Actions extends ActionConstraint>({ namespace, actionNames, rootMessenger, }: {
81
- namespace: string;
82
- actionNames: readonly Actions['type'][] | undefined;
83
- rootMessenger?: Messenger<string, Actions> | undefined;
84
- }): Messenger<string, Actions> | undefined;
85
45
  //# sourceMappingURL=utils.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,4BAA4B;AAC5D,OAAO,EAAE,SAAS,EAAE,4BAA4B;AAEhD,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EACb,cAAc,EACf,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,mIAE4C,CAAC;AAEnE,eAAO,MAAM,cAAc,wGAEqC,CAAC;AAEjE;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,CAAC,KAAK,IAAI,CACvC,KAAK,SAAS,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CACjD,SAAS,CAAC,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,GAC7B,IAAI,GACJ,KAAK,CAAC;AAEV;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,UACd,OAAO,UACN,MAAM;;CAE8C,CAAC;AAE/D,QAAA,MAAM,wBAAwB,eAE7B,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,KAAK;IAI3C,OAAO,CAAC,QAAQ,CAAC,CAAC,wBAAwB,CAAC,CAAQ;gBA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AAE3B,eAAO,MAAM,SAAS,mIAE4C,CAAC;AAEnE,eAAO,MAAM,cAAc,wGAEqC,CAAC;AAEjE;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,CAAC,KAAK,IAAI,CACvC,KAAK,SAAS,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CACjD,SAAS,CAAC,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,GAC7B,IAAI,GACJ,KAAK,CAAC;AAEV;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,UACd,OAAO,UACN,MAAM;;CAE8C,CAAC;AAE/D,QAAA,MAAM,wBAAwB,eAE7B,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,KAAK;IAI3C,OAAO,CAAC,QAAQ,CAAC,CAAC,wBAAwB,CAAC,CAAQ;gBAEvC,OAAO,EAAE,MAAM;IAK3B;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB;CAG/D"}
@@ -1,5 +1,3 @@
1
- import type { ActionConstraint } from "@metamask/messenger";
2
- import { Messenger } from "@metamask/messenger";
3
1
  import type { JsonRpcNotification, JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
4
2
  export type { Json, JsonRpcParams, JsonRpcRequest, JsonRpcNotification, } from "@metamask/utils";
5
3
  export type JsonRpcCall<Params extends JsonRpcParams = JsonRpcParams> = JsonRpcNotification<Params> | JsonRpcRequest<Params>;
@@ -44,42 +42,4 @@ export declare class JsonRpcEngineError extends Error {
44
42
  */
45
43
  static isInstance(value: unknown): value is JsonRpcEngineError;
46
44
  }
47
- /**
48
- * Returns the subset of the specified `hooks` that are included in the
49
- * `hookNames` object. This is a Principle of Least Authority (POLA) measure
50
- * to ensure that each RPC method implementation only has access to the
51
- * API "hooks" it needs to do its job.
52
- *
53
- * @param hooks - The hooks to select from.
54
- * @param hookNames - The names of the hooks to select.
55
- * @returns The selected hooks, or `undefined` if `hookNames` is not provided.
56
- * @template Hooks - The hooks to select from.
57
- * @template HookName - The names of the hooks to select.
58
- */
59
- export declare function selectHooks<Hooks, HookName extends keyof Hooks>(hooks: Hooks, hookNames?: Record<HookName, true>): Pick<Hooks, HookName> | undefined;
60
- /**
61
- * Asserts that `hooks` contains exactly the hook names in `expectedHookNames`.
62
- * Throws on any missing hooks, then on any extraneous hooks.
63
- *
64
- * @param hooks - The hooks object to validate.
65
- * @param expectedHookNames - The expected hook names.
66
- */
67
- export declare function assertExpectedHooks(hooks: Record<string, unknown>, expectedHookNames: Set<string>): void;
68
- /**
69
- * Creates a per-handler messenger namespaced to `namespace`, and delegates the
70
- * specified `actionNames` from `rootMessenger` to it. This lets each handler
71
- * call only the actions it declared, per POLA.
72
- *
73
- * @param options - The options.
74
- * @param options.namespace - The namespace for the handler messenger.
75
- * @param options.actionNames - Actions to delegate from the root messenger.
76
- * @param options.rootMessenger - The root messenger to delegate from. Required
77
- * when `actionNames` are provided.
78
- * @returns The per-handler messenger.
79
- */
80
- export declare function createHandlerMessenger<Actions extends ActionConstraint>({ namespace, actionNames, rootMessenger, }: {
81
- namespace: string;
82
- actionNames: readonly Actions['type'][] | undefined;
83
- rootMessenger?: Messenger<string, Actions> | undefined;
84
- }): Messenger<string, Actions> | undefined;
85
45
  //# sourceMappingURL=utils.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,4BAA4B;AAC5D,OAAO,EAAE,SAAS,EAAE,4BAA4B;AAEhD,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EACb,cAAc,EACf,wBAAwB;AAEzB,YAAY,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,mBAAmB,GACpB,wBAAwB;AAEzB,M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,qBAAa,kBAAmB,SAAQ,KAAK;IAI3C,OAAO,CAAC,QAAQ,CAAC,CAAC,wBAAwB,CAAC,CAAQ;gBAEvC,OAAO,EAAE,MAAM;IAK3B;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB;CAG/D"}
package/dist/v2/utils.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  var _a;
2
- import { Messenger } from "@metamask/messenger";
3
2
  import { hasProperty, isObject } from "@metamask/utils";
4
3
  export const isRequest = (message) => hasProperty(message, 'id');
5
4
  export const isNotification = (message) => !isRequest(message);
@@ -42,75 +41,4 @@ export class JsonRpcEngineError extends Error {
42
41
  }
43
42
  }
44
43
  _a = JsonRpcEngineErrorSymbol;
45
- // Method middleware utils
46
- /**
47
- * Returns the subset of the specified `hooks` that are included in the
48
- * `hookNames` object. This is a Principle of Least Authority (POLA) measure
49
- * to ensure that each RPC method implementation only has access to the
50
- * API "hooks" it needs to do its job.
51
- *
52
- * @param hooks - The hooks to select from.
53
- * @param hookNames - The names of the hooks to select.
54
- * @returns The selected hooks, or `undefined` if `hookNames` is not provided.
55
- * @template Hooks - The hooks to select from.
56
- * @template HookName - The names of the hooks to select.
57
- */
58
- export function selectHooks(hooks, hookNames) {
59
- if (hookNames) {
60
- return Object.keys(hookNames).reduce((subset, name) => {
61
- const hookName = name;
62
- subset[hookName] = hooks[hookName];
63
- return subset;
64
- }, {});
65
- }
66
- return undefined;
67
- }
68
- /**
69
- * Asserts that `hooks` contains exactly the hook names in `expectedHookNames`.
70
- * Throws on any missing hooks, then on any extraneous hooks.
71
- *
72
- * @param hooks - The hooks object to validate.
73
- * @param expectedHookNames - The expected hook names.
74
- */
75
- export function assertExpectedHooks(hooks, expectedHookNames) {
76
- const missingHookNames = [];
77
- expectedHookNames.forEach((hookName) => {
78
- if (!hasProperty(hooks, hookName)) {
79
- missingHookNames.push(hookName);
80
- }
81
- });
82
- if (missingHookNames.length > 0) {
83
- throw new Error(`Missing expected hooks:\n\n${missingHookNames.join('\n')}\n`);
84
- }
85
- const extraneousHookNames = Object.getOwnPropertyNames(hooks).filter((hookName) => !expectedHookNames.has(hookName));
86
- if (extraneousHookNames.length > 0) {
87
- throw new Error(`Received unexpected hooks:\n\n${extraneousHookNames.join('\n')}\n`);
88
- }
89
- }
90
- /**
91
- * Creates a per-handler messenger namespaced to `namespace`, and delegates the
92
- * specified `actionNames` from `rootMessenger` to it. This lets each handler
93
- * call only the actions it declared, per POLA.
94
- *
95
- * @param options - The options.
96
- * @param options.namespace - The namespace for the handler messenger.
97
- * @param options.actionNames - Actions to delegate from the root messenger.
98
- * @param options.rootMessenger - The root messenger to delegate from. Required
99
- * when `actionNames` are provided.
100
- * @returns The per-handler messenger.
101
- */
102
- export function createHandlerMessenger({ namespace, actionNames, rootMessenger, }) {
103
- if (!actionNames) {
104
- return undefined;
105
- }
106
- if (!rootMessenger) {
107
- throw new Error('A messenger is required when a handler declares actionNames.');
108
- }
109
- const handlerMessenger = new Messenger({ namespace, parent: rootMessenger });
110
- rootMessenger.delegate({
111
- actions: actionNames,
112
- messenger: handlerMessenger,
113
- });
114
- return handlerMessenger;
115
- }
116
44
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,4BAA4B;AAChD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB;AAkBxD,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,OAA4D,EACzB,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,OAA4B,EACY,EAAE,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAgBjE;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,I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AC;AAC1B,CAAC","sourcesContent":["import type { ActionConstraint } from '@metamask/messenger';\nimport { Messenger } from '@metamask/messenger';\nimport { hasProperty, isObject } from '@metamask/utils';\nimport type {\n JsonRpcNotification,\n JsonRpcParams,\n 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 message: JsonRpcCall<Params> | Readonly<JsonRpcCall<Params>>,\n): message is JsonRpcRequest<Params> => hasProperty(message, 'id');\n\nexport const isNotification = <Params extends JsonRpcParams>(\n message: JsonRpcCall<Params>,\n): message is JsonRpcNotification<Params> => !isRequest(message);\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<Union> = (\n Union extends never ? never : (k: Union) => void\n) extends (k: infer Args) => void\n ? Args\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\n/**\n * The implementation of static `isInstance` methods for classes that have them.\n *\n * @param value - The value to check.\n * @param symbol - The symbol property to check for.\n * @returns Whether the value has `{ [symbol]: true }` in its prototype chain.\n */\nexport const isInstance = (\n value: unknown,\n symbol: symbol,\n): value is { [key: symbol]: true } =>\n isObject(value) && symbol in value && value[symbol] === true;\n\nconst JsonRpcEngineErrorSymbol = Symbol.for(\n 'json-rpc-engine#JsonRpcEngineError',\n);\n\nexport class JsonRpcEngineError extends Error {\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 [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: unknown): value is JsonRpcEngineError {\n return isInstance(value, JsonRpcEngineErrorSymbol);\n }\n}\n\n// Method middleware utils\n\n/**\n * Returns the subset of the specified `hooks` that are included in the\n * `hookNames` object. This is a Principle of Least Authority (POLA) measure\n * to ensure that each RPC method implementation only has access to the\n * API \"hooks\" it needs to do its job.\n *\n * @param hooks - The hooks to select from.\n * @param hookNames - The names of the hooks to select.\n * @returns The selected hooks, or `undefined` if `hookNames` is not provided.\n * @template Hooks - The hooks to select from.\n * @template HookName - The names of the hooks to select.\n */\nexport function selectHooks<Hooks, HookName extends keyof Hooks>(\n hooks: Hooks,\n hookNames?: Record<HookName, true>,\n): Pick<Hooks, HookName> | undefined {\n if (hookNames) {\n return Object.keys(hookNames).reduce<Partial<Pick<Hooks, HookName>>>(\n (subset, name) => {\n const hookName = name as HookName;\n subset[hookName] = hooks[hookName];\n return subset;\n },\n {},\n ) as Pick<Hooks, HookName>;\n }\n return undefined;\n}\n\n/**\n * Asserts that `hooks` contains exactly the hook names in `expectedHookNames`.\n * Throws on any missing hooks, then on any extraneous hooks.\n *\n * @param hooks - The hooks object to validate.\n * @param expectedHookNames - The expected hook names.\n */\nexport function assertExpectedHooks(\n hooks: Record<string, unknown>,\n expectedHookNames: Set<string>,\n): void {\n const missingHookNames: string[] = [];\n expectedHookNames.forEach((hookName) => {\n if (!hasProperty(hooks, hookName)) {\n missingHookNames.push(hookName);\n }\n });\n if (missingHookNames.length > 0) {\n throw new Error(\n `Missing expected hooks:\\n\\n${missingHookNames.join('\\n')}\\n`,\n );\n }\n\n const extraneousHookNames = Object.getOwnPropertyNames(hooks).filter(\n (hookName) => !expectedHookNames.has(hookName),\n );\n if (extraneousHookNames.length > 0) {\n throw new Error(\n `Received unexpected hooks:\\n\\n${extraneousHookNames.join('\\n')}\\n`,\n );\n }\n}\n\n/**\n * Creates a per-handler messenger namespaced to `namespace`, and delegates the\n * specified `actionNames` from `rootMessenger` to it. This lets each handler\n * call only the actions it declared, per POLA.\n *\n * @param options - The options.\n * @param options.namespace - The namespace for the handler messenger.\n * @param options.actionNames - Actions to delegate from the root messenger.\n * @param options.rootMessenger - The root messenger to delegate from. Required\n * when `actionNames` are provided.\n * @returns The per-handler messenger.\n */\nexport function createHandlerMessenger<Actions extends ActionConstraint>({\n namespace,\n actionNames,\n rootMessenger,\n}: {\n namespace: string;\n actionNames: readonly Actions['type'][] | undefined;\n rootMessenger?: Messenger<string, Actions> | undefined;\n}): Messenger<string, Actions> | undefined {\n if (!actionNames) {\n return undefined;\n }\n\n if (!rootMessenger) {\n throw new Error(\n 'A messenger is required when a handler declares actionNames.',\n );\n }\n\n const handlerMessenger = new Messenger<\n string,\n Actions,\n never,\n typeof rootMessenger\n >({ namespace, parent: rootMessenger });\n\n rootMessenger.delegate({\n actions: actionNames as Actions['type'][],\n messenger: handlerMessenger,\n });\n\n return handlerMessenger;\n}\n"]}
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB;AAkBxD,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,OAA4D,EACzB,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,OAA4B,EACY,EAAE,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAgBjE;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAAc,EACd,MAAc,EACoB,EAAE,CACpC,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;AAE/D,MAAM,wBAAwB,GAAG,MAAM,CAAC,GAAG,CACzC,oCAAoC,CACrC,CAAC;AAEF,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAM3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QANjB,4EAA4E;QAC5E,0BAA0B;QAC1B,gDAAgD;QAC/B,QAA0B,GAAG,IAAI,CAAC;QAIjD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,KAAc;QAC9B,OAAO,UAAU,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;IACrD,CAAC;CACF;KAjBmB,wBAAwB","sourcesContent":["import { hasProperty, isObject } from '@metamask/utils';\nimport type {\n JsonRpcNotification,\n JsonRpcParams,\n 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 message: JsonRpcCall<Params> | Readonly<JsonRpcCall<Params>>,\n): message is JsonRpcRequest<Params> => hasProperty(message, 'id');\n\nexport const isNotification = <Params extends JsonRpcParams>(\n message: JsonRpcCall<Params>,\n): message is JsonRpcNotification<Params> => !isRequest(message);\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<Union> = (\n Union extends never ? never : (k: Union) => void\n) extends (k: infer Args) => void\n ? Args\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\n/**\n * The implementation of static `isInstance` methods for classes that have them.\n *\n * @param value - The value to check.\n * @param symbol - The symbol property to check for.\n * @returns Whether the value has `{ [symbol]: true }` in its prototype chain.\n */\nexport const isInstance = (\n value: unknown,\n symbol: symbol,\n): value is { [key: symbol]: true } =>\n isObject(value) && symbol in value && value[symbol] === true;\n\nconst JsonRpcEngineErrorSymbol = Symbol.for(\n 'json-rpc-engine#JsonRpcEngineError',\n);\n\nexport class JsonRpcEngineError extends Error {\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 [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: unknown): value is JsonRpcEngineError {\n return isInstance(value, JsonRpcEngineErrorSymbol);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/json-rpc-engine",
3
- "version": "10.2.4-preview-45a82ea8e",
3
+ "version": "10.2.4-preview-d8ff44d",
4
4
  "description": "A tool for processing JSON-RPC messages",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -70,7 +70,7 @@
70
70
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
71
71
  },
72
72
  "dependencies": {
73
- "@metamask/messenger": "^1.1.1",
73
+ "@metamask/messenger": "^1.2.0",
74
74
  "@metamask/rpc-errors": "^7.0.2",
75
75
  "@metamask/safe-event-emitter": "^3.0.0",
76
76
  "@metamask/utils": "^11.9.0",
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMethodMiddleware = void 0;
4
- const rpc_errors_1 = require("@metamask/rpc-errors");
5
- const utils_1 = require("./v2/utils.cjs");
6
- /**
7
- * Create a JSON-RPC middleware that handles the passed JSON-RPC method handlers using the messenger and hooks.
8
- *
9
- * @deprecated Use the v2 `createMethodMiddleware` instead.
10
- * @param options The options.
11
- * @param options.handlers - The JSON-RPC method handler implementations.
12
- * @param options.messenger - The messenger to be used by the handlers.
13
- * @param options.hooks - The hooks to be used by the handlers.
14
- * @returns A JsonRpcEngineV2 middleware.
15
- */
16
- function createMethodMiddleware(options) {
17
- const { messenger: rootMessenger, onError } = options;
18
- const allHooks = options.hooks;
19
- const expectedHookNames = new Set(Object.values(options.handlers).flatMap((handler) => handler.hookNames ? Object.getOwnPropertyNames(handler.hookNames) : []));
20
- (0, utils_1.assertExpectedHooks)(allHooks, expectedHookNames);
21
- const handlers = Object.entries(options.handlers).reduce((accumulator, [handlerName, handler]) => {
22
- const handlerHooks = (0, utils_1.selectHooks)(allHooks, handler.hookNames) ?? {};
23
- const handlerMessenger = (0, utils_1.createHandlerMessenger)({
24
- namespace: handlerName,
25
- actionNames: handler.actionNames,
26
- rootMessenger,
27
- });
28
- accumulator[handlerName] = {
29
- implementation: handler.implementation,
30
- hooks: handlerHooks,
31
- messenger: handlerMessenger,
32
- };
33
- return accumulator;
34
- }, {});
35
- // This should technically use createAsyncMiddleware, but we get around this by catching
36
- // all handler errors.
37
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
38
- return async (req, res, next, end) => {
39
- const handler = handlers[req.method];
40
- if (!handler) {
41
- return next();
42
- }
43
- const { implementation, hooks: handlerHooks, messenger } = handler;
44
- try {
45
- return await implementation(req, res, next, end, handlerHooks, messenger);
46
- }
47
- catch (error) {
48
- onError?.(error, req);
49
- return end(error instanceof Error
50
- ? error
51
- : rpc_errors_1.rpcErrors.internal({ data: error }));
52
- }
53
- };
54
- }
55
- exports.createMethodMiddleware = createMethodMiddleware;
56
- //# sourceMappingURL=createMethodMiddleware.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createMethodMiddleware.cjs","sourceRoot":"","sources":["../src/createMethodMiddleware.ts"],"names":[],"mappings":";;;AAEA,qDAAiD;AAajD,0CAKoB;AA2HpB;;;;;;;;;GASG;AACH,SAAgB,sBAAsB,CAGpC,OAAgD;IAEhD,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACtD,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,2BAAmB,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,mBAAW,EAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QACpE,MAAM,gBAAgB,GAAG,IAAA,8BAAsB,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,wFAAwF;IACxF,sBAAsB;IACtB,kEAAkE;IAClE,OAAO,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;QACnC,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QACnE,IAAI,CAAC;YACH,OAAO,MAAM,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;QAC5E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YACtB,OAAO,GAAG,CACR,KAAK,YAAY,KAAK;gBACpB,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,sBAAS,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAa,EAAE,CAAC,CAChD,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AA1DD,wDA0DC","sourcesContent":["import type { ActionConstraint } from '@metamask/messenger';\nimport type { Messenger } from '@metamask/messenger';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n JsonRpcMiddleware,\n} from './JsonRpcEngine';\nimport {\n assertExpectedHooks,\n createHandlerMessenger,\n selectHooks,\n UnionToIntersection,\n} from './v2/utils';\n\ntype HandlerActions<Handler> = Handler extends {\n implementation: (...args: infer Args) => unknown;\n}\n ? Args extends [\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n infer HandlerMessenger,\n ]\n ? HandlerMessenger extends Messenger<string, infer Actions>\n ? Actions\n : never\n : never\n : never;\n\ntype HandlerHooks<Handler> = Handler extends {\n implementation: (...args: infer Args) => unknown;\n}\n ? Args extends [unknown, unknown, unknown, unknown, infer ArgHooks, unknown]\n ? ArgHooks extends Record<string, unknown>\n ? ArgHooks\n : never\n : never\n : never;\n\n/**\n * A {@link MethodHandler} implementation.\n *\n * @deprecated Use the v2 `createMethodMiddleware` instead.\n */\nexport type MethodHandlerImplementation<\n Hooks extends Record<string, unknown> = never,\n MessengerActions extends ActionConstraint = never,\n Params extends JsonRpcParams = JsonRpcParams,\n Result extends Json = Json,\n RequestExtras extends Record<string, unknown> = Record<string, unknown>,\n> = (\n req: JsonRpcRequest<Params> & RequestExtras,\n res: PendingJsonRpcResponse<Result>,\n next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: Hooks,\n messenger: Messenger<string, MessengerActions>,\n) => Promise<void> | void;\n\n/**\n * A handler for {@link createMethodMiddleware}.\n *\n * @deprecated Use the v2 `createMethodMiddleware` instead.\n */\nexport type MethodHandler<\n Hooks extends Record<string, unknown> = never,\n MessengerActions extends ActionConstraint = never,\n Params extends JsonRpcParams = JsonRpcParams,\n Result extends Json = Json,\n RequestExtras extends Record<string, unknown> = Record<string, unknown>,\n> = {\n implementation: MethodHandlerImplementation<\n Hooks,\n MessengerActions,\n Params,\n Result,\n RequestExtras\n >;\n} & ([Hooks] extends [never]\n ? { hookNames?: undefined }\n : { hookNames: { [Key in keyof Hooks]: true } }) &\n ([MessengerActions] extends [never]\n ? { actionNames?: undefined }\n : { actionNames: readonly MessengerActions['type'][] });\n\ntype AnyMethodHandler = {\n implementation(\n this: void,\n req: JsonRpcRequest,\n res: PendingJsonRpcResponse,\n next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: unknown,\n messenger: unknown,\n ): Promise<void> | void;\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: UnionToIntersection<HandlerHooks<Handlers[keyof Handlers]>>;\n /**\n * Called when a handler throws, before the error is forwarded to `end`.\n * Intended for logging; must not throw.\n */\n onError?: (error: unknown, request: JsonRpcRequest) => void;\n};\n\n/**\n * Options for {@link createMethodMiddleware}.\n *\n * @deprecated Use the v2 `createMethodMiddleware` instead.\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 * @deprecated Use the v2 `createMethodMiddleware` instead.\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>(\n options: CreateMethodMiddlewareOptions<Handlers>,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n const { messenger: rootMessenger, onError } = 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 // This should technically use createAsyncMiddleware, but we get around this by catching\n // all handler errors.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async (req, res, next, end) => {\n const handler = handlers[req.method];\n if (!handler) {\n return next();\n }\n\n const { implementation, hooks: handlerHooks, messenger } = handler;\n try {\n return await implementation(req, res, next, end, handlerHooks, messenger);\n } catch (error) {\n onError?.(error, req);\n return end(\n error instanceof Error\n ? error\n : rpcErrors.internal({ data: error as Json }),\n );\n }\n };\n}\n"]}
@@ -1,79 +0,0 @@
1
- import type { ActionConstraint } from "@metamask/messenger";
2
- import type { Messenger } from "@metamask/messenger";
3
- import type { Json, JsonRpcParams, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
4
- import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback, JsonRpcMiddleware } from "./JsonRpcEngine.cjs";
5
- import { UnionToIntersection } from "./v2/utils.cjs";
6
- type HandlerActions<Handler> = Handler extends {
7
- implementation: (...args: infer Args) => unknown;
8
- } ? Args extends [
9
- unknown,
10
- unknown,
11
- unknown,
12
- unknown,
13
- unknown,
14
- infer HandlerMessenger
15
- ] ? HandlerMessenger extends Messenger<string, infer Actions> ? Actions : never : never : never;
16
- type HandlerHooks<Handler> = Handler extends {
17
- implementation: (...args: infer Args) => unknown;
18
- } ? Args extends [unknown, unknown, unknown, unknown, infer ArgHooks, unknown] ? ArgHooks extends Record<string, unknown> ? ArgHooks : never : never : never;
19
- /**
20
- * A {@link MethodHandler} implementation.
21
- *
22
- * @deprecated Use the v2 `createMethodMiddleware` instead.
23
- */
24
- export type MethodHandlerImplementation<Hooks extends Record<string, unknown> = never, MessengerActions extends ActionConstraint = never, Params extends JsonRpcParams = JsonRpcParams, Result extends Json = Json, RequestExtras extends Record<string, unknown> = Record<string, unknown>> = (req: JsonRpcRequest<Params> & RequestExtras, res: PendingJsonRpcResponse<Result>, next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: Hooks, messenger: Messenger<string, MessengerActions>) => Promise<void> | void;
25
- /**
26
- * A handler for {@link createMethodMiddleware}.
27
- *
28
- * @deprecated Use the v2 `createMethodMiddleware` instead.
29
- */
30
- export type MethodHandler<Hooks extends Record<string, unknown> = never, MessengerActions extends ActionConstraint = never, Params extends JsonRpcParams = JsonRpcParams, Result extends Json = Json, RequestExtras extends Record<string, unknown> = Record<string, unknown>> = {
31
- implementation: MethodHandlerImplementation<Hooks, MessengerActions, Params, Result, RequestExtras>;
32
- } & ([Hooks] extends [never] ? {
33
- hookNames?: undefined;
34
- } : {
35
- hookNames: {
36
- [Key in keyof Hooks]: true;
37
- };
38
- }) & ([MessengerActions] extends [never] ? {
39
- actionNames?: undefined;
40
- } : {
41
- actionNames: readonly MessengerActions['type'][];
42
- });
43
- type AnyMethodHandler = {
44
- implementation(this: void, req: JsonRpcRequest, res: PendingJsonRpcResponse, next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: unknown, messenger: unknown): Promise<void> | void;
45
- hookNames?: Record<string, true>;
46
- actionNames?: readonly string[];
47
- };
48
- type CreateMethodMiddlewareBaseOptions<Handlers extends Record<string, AnyMethodHandler>> = {
49
- handlers: Handlers;
50
- hooks: UnionToIntersection<HandlerHooks<Handlers[keyof Handlers]>>;
51
- /**
52
- * Called when a handler throws, before the error is forwarded to `end`.
53
- * Intended for logging; must not throw.
54
- */
55
- onError?: (error: unknown, request: JsonRpcRequest) => void;
56
- };
57
- /**
58
- * Options for {@link createMethodMiddleware}.
59
- *
60
- * @deprecated Use the v2 `createMethodMiddleware` instead.
61
- */
62
- export type CreateMethodMiddlewareOptions<Handlers extends Record<string, AnyMethodHandler>> = CreateMethodMiddlewareBaseOptions<Handlers> & ([HandlerActions<Handlers[keyof Handlers]>] extends [never] ? {
63
- messenger?: undefined;
64
- } : {
65
- messenger: Messenger<string, HandlerActions<Handlers[keyof Handlers]>>;
66
- });
67
- /**
68
- * Create a JSON-RPC middleware that handles the passed JSON-RPC method handlers using the messenger and hooks.
69
- *
70
- * @deprecated Use the v2 `createMethodMiddleware` instead.
71
- * @param options The options.
72
- * @param options.handlers - The JSON-RPC method handler implementations.
73
- * @param options.messenger - The messenger to be used by the handlers.
74
- * @param options.hooks - The hooks to be used by the handlers.
75
- * @returns A JsonRpcEngineV2 middleware.
76
- */
77
- export declare function createMethodMiddleware<Handlers extends Record<string, AnyMethodHandler>>(options: CreateMethodMiddlewareOptions<Handlers>): JsonRpcMiddleware<JsonRpcParams, Json>;
78
- export {};
79
- //# sourceMappingURL=createMethodMiddleware.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createMethodMiddleware.d.cts","sourceRoot":"","sources":["../src/createMethodMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,4BAA4B;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EACzB,iBAAiB,EAClB,4BAAwB;AACzB,OAAO,EAIL,mBAAmB,EACpB,uBAAmB;AAEpB,KAAK,cAAc,CAAC,OAAO,IAAI,OAAO,SAAS;IAC7C,cAAc,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,IAAI,KAAK,OAAO,CAAC;CAClD,GACG,IAAI,SAAS;IACX,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,MAAM,gBAAgB;CACvB,GACC,gBAAg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nE;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;CAC7D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,6BAA6B,CACvC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,IAC/C,iCAAiC,CAAC,QAAQ,CAAC,GAC7C,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACvD;IACE,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,GACD;IACE,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAC;CACxE,CAAC,CAAC;AAQT;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAEjD,OAAO,EAAE,6BAA6B,CAAC,QAAQ,CAAC,GAC/C,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAsDxC"}
@@ -1,79 +0,0 @@
1
- import type { ActionConstraint } from "@metamask/messenger";
2
- import type { Messenger } from "@metamask/messenger";
3
- import type { Json, JsonRpcParams, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
4
- import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback, JsonRpcMiddleware } from "./JsonRpcEngine.mjs";
5
- import { UnionToIntersection } from "./v2/utils.mjs";
6
- type HandlerActions<Handler> = Handler extends {
7
- implementation: (...args: infer Args) => unknown;
8
- } ? Args extends [
9
- unknown,
10
- unknown,
11
- unknown,
12
- unknown,
13
- unknown,
14
- infer HandlerMessenger
15
- ] ? HandlerMessenger extends Messenger<string, infer Actions> ? Actions : never : never : never;
16
- type HandlerHooks<Handler> = Handler extends {
17
- implementation: (...args: infer Args) => unknown;
18
- } ? Args extends [unknown, unknown, unknown, unknown, infer ArgHooks, unknown] ? ArgHooks extends Record<string, unknown> ? ArgHooks : never : never : never;
19
- /**
20
- * A {@link MethodHandler} implementation.
21
- *
22
- * @deprecated Use the v2 `createMethodMiddleware` instead.
23
- */
24
- export type MethodHandlerImplementation<Hooks extends Record<string, unknown> = never, MessengerActions extends ActionConstraint = never, Params extends JsonRpcParams = JsonRpcParams, Result extends Json = Json, RequestExtras extends Record<string, unknown> = Record<string, unknown>> = (req: JsonRpcRequest<Params> & RequestExtras, res: PendingJsonRpcResponse<Result>, next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: Hooks, messenger: Messenger<string, MessengerActions>) => Promise<void> | void;
25
- /**
26
- * A handler for {@link createMethodMiddleware}.
27
- *
28
- * @deprecated Use the v2 `createMethodMiddleware` instead.
29
- */
30
- export type MethodHandler<Hooks extends Record<string, unknown> = never, MessengerActions extends ActionConstraint = never, Params extends JsonRpcParams = JsonRpcParams, Result extends Json = Json, RequestExtras extends Record<string, unknown> = Record<string, unknown>> = {
31
- implementation: MethodHandlerImplementation<Hooks, MessengerActions, Params, Result, RequestExtras>;
32
- } & ([Hooks] extends [never] ? {
33
- hookNames?: undefined;
34
- } : {
35
- hookNames: {
36
- [Key in keyof Hooks]: true;
37
- };
38
- }) & ([MessengerActions] extends [never] ? {
39
- actionNames?: undefined;
40
- } : {
41
- actionNames: readonly MessengerActions['type'][];
42
- });
43
- type AnyMethodHandler = {
44
- implementation(this: void, req: JsonRpcRequest, res: PendingJsonRpcResponse, next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: unknown, messenger: unknown): Promise<void> | void;
45
- hookNames?: Record<string, true>;
46
- actionNames?: readonly string[];
47
- };
48
- type CreateMethodMiddlewareBaseOptions<Handlers extends Record<string, AnyMethodHandler>> = {
49
- handlers: Handlers;
50
- hooks: UnionToIntersection<HandlerHooks<Handlers[keyof Handlers]>>;
51
- /**
52
- * Called when a handler throws, before the error is forwarded to `end`.
53
- * Intended for logging; must not throw.
54
- */
55
- onError?: (error: unknown, request: JsonRpcRequest) => void;
56
- };
57
- /**
58
- * Options for {@link createMethodMiddleware}.
59
- *
60
- * @deprecated Use the v2 `createMethodMiddleware` instead.
61
- */
62
- export type CreateMethodMiddlewareOptions<Handlers extends Record<string, AnyMethodHandler>> = CreateMethodMiddlewareBaseOptions<Handlers> & ([HandlerActions<Handlers[keyof Handlers]>] extends [never] ? {
63
- messenger?: undefined;
64
- } : {
65
- messenger: Messenger<string, HandlerActions<Handlers[keyof Handlers]>>;
66
- });
67
- /**
68
- * Create a JSON-RPC middleware that handles the passed JSON-RPC method handlers using the messenger and hooks.
69
- *
70
- * @deprecated Use the v2 `createMethodMiddleware` instead.
71
- * @param options The options.
72
- * @param options.handlers - The JSON-RPC method handler implementations.
73
- * @param options.messenger - The messenger to be used by the handlers.
74
- * @param options.hooks - The hooks to be used by the handlers.
75
- * @returns A JsonRpcEngineV2 middleware.
76
- */
77
- export declare function createMethodMiddleware<Handlers extends Record<string, AnyMethodHandler>>(options: CreateMethodMiddlewareOptions<Handlers>): JsonRpcMiddleware<JsonRpcParams, Json>;
78
- export {};
79
- //# sourceMappingURL=createMethodMiddleware.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createMethodMiddleware.d.mts","sourceRoot":"","sources":["../src/createMethodMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,4BAA4B;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EACzB,iBAAiB,EAClB,4BAAwB;AACzB,OAAO,EAIL,mBAAmB,EACpB,uBAAmB;AAEpB,KAAK,cAAc,CAAC,OAAO,IAAI,OAAO,SAAS;IAC7C,cAAc,EAAE,CAAC,GAAG,IAAI,EAAE,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