@metamask-previews/json-rpc-engine 10.1.1-preview-63ea58af → 10.1.1-preview-0458fe94

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 (116) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +647 -124
  3. package/dist/JsonRpcEngine.cjs +11 -13
  4. package/dist/JsonRpcEngine.cjs.map +1 -1
  5. package/dist/JsonRpcEngine.d.cts +18 -0
  6. package/dist/JsonRpcEngine.d.cts.map +1 -1
  7. package/dist/JsonRpcEngine.d.mts +18 -0
  8. package/dist/JsonRpcEngine.d.mts.map +1 -1
  9. package/dist/JsonRpcEngine.mjs +11 -13
  10. package/dist/JsonRpcEngine.mjs.map +1 -1
  11. package/dist/asV2Middleware.cjs +48 -0
  12. package/dist/asV2Middleware.cjs.map +1 -0
  13. package/dist/asV2Middleware.d.cts +11 -0
  14. package/dist/asV2Middleware.d.cts.map +1 -0
  15. package/dist/asV2Middleware.d.mts +11 -0
  16. package/dist/asV2Middleware.d.mts.map +1 -0
  17. package/dist/asV2Middleware.mjs +44 -0
  18. package/dist/asV2Middleware.mjs.map +1 -0
  19. package/dist/createAsyncMiddleware.cjs +1 -0
  20. package/dist/createAsyncMiddleware.cjs.map +1 -1
  21. package/dist/createAsyncMiddleware.d.cts +1 -0
  22. package/dist/createAsyncMiddleware.d.cts.map +1 -1
  23. package/dist/createAsyncMiddleware.d.mts +1 -0
  24. package/dist/createAsyncMiddleware.d.mts.map +1 -1
  25. package/dist/createAsyncMiddleware.mjs +1 -0
  26. package/dist/createAsyncMiddleware.mjs.map +1 -1
  27. package/dist/createScaffoldMiddleware.cjs +1 -0
  28. package/dist/createScaffoldMiddleware.cjs.map +1 -1
  29. package/dist/createScaffoldMiddleware.d.cts +1 -0
  30. package/dist/createScaffoldMiddleware.d.cts.map +1 -1
  31. package/dist/createScaffoldMiddleware.d.mts +1 -0
  32. package/dist/createScaffoldMiddleware.d.mts.map +1 -1
  33. package/dist/createScaffoldMiddleware.mjs +1 -0
  34. package/dist/createScaffoldMiddleware.mjs.map +1 -1
  35. package/dist/idRemapMiddleware.cjs +1 -0
  36. package/dist/idRemapMiddleware.cjs.map +1 -1
  37. package/dist/idRemapMiddleware.d.cts +1 -0
  38. package/dist/idRemapMiddleware.d.cts.map +1 -1
  39. package/dist/idRemapMiddleware.d.mts +1 -0
  40. package/dist/idRemapMiddleware.d.mts.map +1 -1
  41. package/dist/idRemapMiddleware.mjs +1 -0
  42. package/dist/idRemapMiddleware.mjs.map +1 -1
  43. package/dist/index.cjs +3 -1
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/index.d.cts +1 -0
  46. package/dist/index.d.cts.map +1 -1
  47. package/dist/index.d.mts +1 -0
  48. package/dist/index.d.mts.map +1 -1
  49. package/dist/index.mjs +1 -0
  50. package/dist/index.mjs.map +1 -1
  51. package/dist/mergeMiddleware.cjs +1 -0
  52. package/dist/mergeMiddleware.cjs.map +1 -1
  53. package/dist/mergeMiddleware.d.cts +1 -0
  54. package/dist/mergeMiddleware.d.cts.map +1 -1
  55. package/dist/mergeMiddleware.d.mts +1 -0
  56. package/dist/mergeMiddleware.d.mts.map +1 -1
  57. package/dist/mergeMiddleware.mjs +1 -0
  58. package/dist/mergeMiddleware.mjs.map +1 -1
  59. package/dist/v2/JsonRpcEngineV2.cjs +213 -0
  60. package/dist/v2/JsonRpcEngineV2.cjs.map +1 -0
  61. package/dist/v2/JsonRpcEngineV2.d.cts +122 -0
  62. package/dist/v2/JsonRpcEngineV2.d.cts.map +1 -0
  63. package/dist/v2/JsonRpcEngineV2.d.mts +122 -0
  64. package/dist/v2/JsonRpcEngineV2.d.mts.map +1 -0
  65. package/dist/v2/JsonRpcEngineV2.mjs +213 -0
  66. package/dist/v2/JsonRpcEngineV2.mjs.map +1 -0
  67. package/dist/v2/JsonRpcServer.cjs +162 -0
  68. package/dist/v2/JsonRpcServer.cjs.map +1 -0
  69. package/dist/v2/JsonRpcServer.d.cts +85 -0
  70. package/dist/v2/JsonRpcServer.d.cts.map +1 -0
  71. package/dist/v2/JsonRpcServer.d.mts +85 -0
  72. package/dist/v2/JsonRpcServer.d.mts.map +1 -0
  73. package/dist/v2/JsonRpcServer.mjs +158 -0
  74. package/dist/v2/JsonRpcServer.mjs.map +1 -0
  75. package/dist/v2/MiddlewareContext.cjs +66 -0
  76. package/dist/v2/MiddlewareContext.cjs.map +1 -0
  77. package/dist/v2/MiddlewareContext.d.cts +95 -0
  78. package/dist/v2/MiddlewareContext.d.cts.map +1 -0
  79. package/dist/v2/MiddlewareContext.d.mts +95 -0
  80. package/dist/v2/MiddlewareContext.d.mts.map +1 -0
  81. package/dist/v2/MiddlewareContext.mjs +62 -0
  82. package/dist/v2/MiddlewareContext.mjs.map +1 -0
  83. package/dist/v2/asLegacyMiddleware.cjs +39 -0
  84. package/dist/v2/asLegacyMiddleware.cjs.map +1 -0
  85. package/dist/v2/asLegacyMiddleware.d.cts +11 -0
  86. package/dist/v2/asLegacyMiddleware.d.cts.map +1 -0
  87. package/dist/v2/asLegacyMiddleware.d.mts +11 -0
  88. package/dist/v2/asLegacyMiddleware.d.mts.map +1 -0
  89. package/dist/v2/asLegacyMiddleware.mjs +35 -0
  90. package/dist/v2/asLegacyMiddleware.mjs.map +1 -0
  91. package/dist/v2/compatibility-utils.cjs +151 -0
  92. package/dist/v2/compatibility-utils.cjs.map +1 -0
  93. package/dist/v2/compatibility-utils.d.cts +75 -0
  94. package/dist/v2/compatibility-utils.d.cts.map +1 -0
  95. package/dist/v2/compatibility-utils.d.mts +75 -0
  96. package/dist/v2/compatibility-utils.d.mts.map +1 -0
  97. package/dist/v2/compatibility-utils.mjs +142 -0
  98. package/dist/v2/compatibility-utils.mjs.map +1 -0
  99. package/dist/v2/index.cjs +29 -0
  100. package/dist/v2/index.cjs.map +1 -0
  101. package/dist/v2/index.d.cts +8 -0
  102. package/dist/v2/index.d.cts.map +1 -0
  103. package/dist/v2/index.d.mts +8 -0
  104. package/dist/v2/index.d.mts.map +1 -0
  105. package/dist/v2/index.mjs +6 -0
  106. package/dist/v2/index.mjs.map +1 -0
  107. package/dist/v2/utils.cjs +41 -0
  108. package/dist/v2/utils.cjs.map +1 -0
  109. package/dist/v2/utils.d.cts +35 -0
  110. package/dist/v2/utils.d.cts.map +1 -0
  111. package/dist/v2/utils.d.mts +35 -0
  112. package/dist/v2/utils.d.mts.map +1 -0
  113. package/dist/v2/utils.mjs +34 -0
  114. package/dist/v2/utils.mjs.map +1 -0
  115. package/package.json +17 -3
  116. package/v2.js +3 -0
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.JsonRpcEngineError = exports.stringify = exports.isNotification = exports.isRequest = void 0;
5
+ const utils_1 = require("@metamask/utils");
6
+ const isRequest = (msg) => (0, utils_1.hasProperty)(msg, 'id');
7
+ exports.isRequest = isRequest;
8
+ const isNotification = (msg) => !(0, exports.isRequest)(msg);
9
+ exports.isNotification = isNotification;
10
+ /**
11
+ * JSON-stringifies a value.
12
+ *
13
+ * @param value - The value to stringify.
14
+ * @returns The stringified value.
15
+ */
16
+ function stringify(value) {
17
+ return JSON.stringify(value, null, 2);
18
+ }
19
+ exports.stringify = stringify;
20
+ const JsonRpcEngineErrorSymbol = Symbol.for('JsonRpcEngineError');
21
+ class JsonRpcEngineError extends Error {
22
+ constructor(message) {
23
+ super(message);
24
+ this[_a] = true;
25
+ this.name = 'JsonRpcEngineError';
26
+ }
27
+ /**
28
+ * Check if a value is a {@link JsonRpcEngineError} instance.
29
+ * Works across different package versions in the same realm.
30
+ *
31
+ * @param value - The value to check.
32
+ * @returns Whether the value is a {@link JsonRpcEngineError} instance.
33
+ */
34
+ static isInstance(value) {
35
+ return ((0, utils_1.hasProperty)(value, JsonRpcEngineErrorSymbol) &&
36
+ value[JsonRpcEngineErrorSymbol] === true);
37
+ }
38
+ }
39
+ exports.JsonRpcEngineError = JsonRpcEngineError;
40
+ _a = JsonRpcEngineErrorSymbol;
41
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":";;;;AAAA,2CAKyB;AAalB,MAAM,SAAS,GAAG,CACvB,GAAwD,EACzB,EAAE,CAAC,IAAA,mBAAW,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAF9C,QAAA,SAAS,aAEqC;AAEpD,MAAM,cAAc,GAAG,CAC5B,GAAwB,EACY,EAAE,CAAC,CAAC,IAAA,iBAAS,EAAC,GAAG,CAAC,CAAC;AAF5C,QAAA,cAAc,kBAE8B;AAgBzD;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,KAAc;IACtC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC;AAFD,8BAEC;AAED,MAAM,wBAAwB,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAa,kBAAmB,SAAQ,KAAK;IAG3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHA,QAA0B,GAAG,IAAI,CAAC;QAIjD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CACf,KAAY;QAEZ,OAAO,CACL,IAAA,mBAAW,EAAC,KAAK,EAAE,wBAAwB,CAAC;YAC5C,KAAK,CAAC,wBAAwB,CAAC,KAAK,IAAI,CACzC,CAAC;IACJ,CAAC;CACF;AAvBD,gDAuBC;KAtBmB,wBAAwB","sourcesContent":["import {\n hasProperty,\n type JsonRpcNotification,\n type JsonRpcParams,\n type JsonRpcRequest,\n} from '@metamask/utils';\n\nexport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcNotification,\n} from '@metamask/utils';\n\nexport type JsonRpcCall<Params extends JsonRpcParams = JsonRpcParams> =\n | JsonRpcNotification<Params>\n | JsonRpcRequest<Params>;\n\nexport const isRequest = <Params extends JsonRpcParams>(\n msg: JsonRpcCall<Params> | Readonly<JsonRpcCall<Params>>,\n): msg is JsonRpcRequest<Params> => hasProperty(msg, 'id');\n\nexport const isNotification = <Params extends JsonRpcParams>(\n msg: JsonRpcCall<Params>,\n): msg is JsonRpcNotification<Params> => !isRequest(msg);\n\n/**\n * An unholy incantation that converts a union of object types into an\n * intersection of object types.\n *\n * @example\n * type A = { a: string } | { b: number };\n * type B = UnionToIntersection<A>; // { a: string } & { b: number }\n */\nexport type UnionToIntersection<U> = (\n U extends never ? never : (k: U) => void\n) extends (k: infer I) => void\n ? I\n : never;\n\n/**\n * JSON-stringifies a value.\n *\n * @param value - The value to stringify.\n * @returns The stringified value.\n */\nexport function stringify(value: unknown): string {\n return JSON.stringify(value, null, 2);\n}\n\nconst JsonRpcEngineErrorSymbol = Symbol.for('JsonRpcEngineError');\n\nexport class JsonRpcEngineError extends Error {\n private readonly [JsonRpcEngineErrorSymbol] = true;\n\n constructor(message: string) {\n super(message);\n this.name = 'JsonRpcEngineError';\n }\n\n /**\n * Check if a value is a {@link JsonRpcEngineError} instance.\n * Works across different package versions in the same realm.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link JsonRpcEngineError} instance.\n */\n static isInstance<Value extends Error>(\n value: Value,\n ): value is Value & JsonRpcEngineError {\n return (\n hasProperty(value, JsonRpcEngineErrorSymbol) &&\n value[JsonRpcEngineErrorSymbol] === true\n );\n }\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { type JsonRpcNotification, type JsonRpcParams, type JsonRpcRequest } from "@metamask/utils";
2
+ export type { Json, JsonRpcParams, JsonRpcRequest, JsonRpcNotification, } from "@metamask/utils";
3
+ export type JsonRpcCall<Params extends JsonRpcParams = JsonRpcParams> = JsonRpcNotification<Params> | JsonRpcRequest<Params>;
4
+ export declare const isRequest: <Params extends JsonRpcParams>(msg: JsonRpcCall<Params> | Readonly<JsonRpcCall<Params>>) => msg is JsonRpcRequest<Params>;
5
+ export declare const isNotification: <Params extends JsonRpcParams>(msg: JsonRpcCall<Params>) => msg is JsonRpcNotification<Params>;
6
+ /**
7
+ * An unholy incantation that converts a union of object types into an
8
+ * intersection of object types.
9
+ *
10
+ * @example
11
+ * type A = { a: string } | { b: number };
12
+ * type B = UnionToIntersection<A>; // { a: string } & { b: number }
13
+ */
14
+ export type UnionToIntersection<U> = (U extends never ? never : (k: U) => void) extends (k: infer I) => void ? I : never;
15
+ /**
16
+ * JSON-stringifies a value.
17
+ *
18
+ * @param value - The value to stringify.
19
+ * @returns The stringified value.
20
+ */
21
+ export declare function stringify(value: unknown): string;
22
+ declare const JsonRpcEngineErrorSymbol: unique symbol;
23
+ export declare class JsonRpcEngineError extends Error {
24
+ private readonly [JsonRpcEngineErrorSymbol];
25
+ constructor(message: string);
26
+ /**
27
+ * Check if a value is a {@link JsonRpcEngineError} instance.
28
+ * Works across different package versions in the same realm.
29
+ *
30
+ * @param value - The value to check.
31
+ * @returns Whether the value is a {@link JsonRpcEngineError} instance.
32
+ */
33
+ static isInstance<Value extends Error>(value: Value): value is Value & JsonRpcEngineError;
34
+ }
35
+ //# sourceMappingURL=utils.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,wBAAwB;AAEzB,YAAY,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,mBAAmB,GACpB,wBAAwB;AAEzB,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa,IAChE,mBAAmB,CAAC,MAAM,CAAC,GAC3B,cAAc,CAAC,MAAM,CAAC,CAAC;AAE3B,eAAO,MAAM,SAAS,2HAEoC,CAAC;AAE3D,eAAO,MAAM,cAAc,gGAE6B,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CACnC,CAAC,SAAS,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CACzC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,GAC1B,CAAC,GACD,KAAK,CAAC;AAEV;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED,QAAA,MAAM,wBAAwB,eAAmC,CAAC;AAElE,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,OAAO,CAAC,QAAQ,CAAC,CAAC,wBAAwB,CAAC,CAAQ;gBAEvC,OAAO,EAAE,MAAM;IAK3B;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,SAAS,KAAK,EACnC,KAAK,EAAE,KAAK,GACX,KAAK,IAAI,KAAK,GAAG,kBAAkB;CAMvC"}
@@ -0,0 +1,35 @@
1
+ import { type JsonRpcNotification, type JsonRpcParams, type JsonRpcRequest } from "@metamask/utils";
2
+ export type { Json, JsonRpcParams, JsonRpcRequest, JsonRpcNotification, } from "@metamask/utils";
3
+ export type JsonRpcCall<Params extends JsonRpcParams = JsonRpcParams> = JsonRpcNotification<Params> | JsonRpcRequest<Params>;
4
+ export declare const isRequest: <Params extends JsonRpcParams>(msg: JsonRpcCall<Params> | Readonly<JsonRpcCall<Params>>) => msg is JsonRpcRequest<Params>;
5
+ export declare const isNotification: <Params extends JsonRpcParams>(msg: JsonRpcCall<Params>) => msg is JsonRpcNotification<Params>;
6
+ /**
7
+ * An unholy incantation that converts a union of object types into an
8
+ * intersection of object types.
9
+ *
10
+ * @example
11
+ * type A = { a: string } | { b: number };
12
+ * type B = UnionToIntersection<A>; // { a: string } & { b: number }
13
+ */
14
+ export type UnionToIntersection<U> = (U extends never ? never : (k: U) => void) extends (k: infer I) => void ? I : never;
15
+ /**
16
+ * JSON-stringifies a value.
17
+ *
18
+ * @param value - The value to stringify.
19
+ * @returns The stringified value.
20
+ */
21
+ export declare function stringify(value: unknown): string;
22
+ declare const JsonRpcEngineErrorSymbol: unique symbol;
23
+ export declare class JsonRpcEngineError extends Error {
24
+ private readonly [JsonRpcEngineErrorSymbol];
25
+ constructor(message: string);
26
+ /**
27
+ * Check if a value is a {@link JsonRpcEngineError} instance.
28
+ * Works across different package versions in the same realm.
29
+ *
30
+ * @param value - The value to check.
31
+ * @returns Whether the value is a {@link JsonRpcEngineError} instance.
32
+ */
33
+ static isInstance<Value extends Error>(value: Value): value is Value & JsonRpcEngineError;
34
+ }
35
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,wBAAwB;AAEzB,YAAY,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,mBAAmB,GACpB,wBAAwB;AAEzB,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa,IAChE,mBAAmB,CAAC,MAAM,CAAC,GAC3B,cAAc,CAAC,MAAM,CAAC,CAAC;AAE3B,eAAO,MAAM,SAAS,2HAEoC,CAAC;AAE3D,eAAO,MAAM,cAAc,gGAE6B,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CACnC,CAAC,SAAS,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CACzC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,GAC1B,CAAC,GACD,KAAK,CAAC;AAEV;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED,QAAA,MAAM,wBAAwB,eAAmC,CAAC;AAElE,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,OAAO,CAAC,QAAQ,CAAC,CAAC,wBAAwB,CAAC,CAAQ;gBAEvC,OAAO,EAAE,MAAM;IAK3B;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,SAAS,KAAK,EACnC,KAAK,EAAE,KAAK,GACX,KAAK,IAAI,KAAK,GAAG,kBAAkB;CAMvC"}
@@ -0,0 +1,34 @@
1
+ var _a;
2
+ import { hasProperty } from "@metamask/utils";
3
+ export const isRequest = (msg) => hasProperty(msg, 'id');
4
+ export const isNotification = (msg) => !isRequest(msg);
5
+ /**
6
+ * JSON-stringifies a value.
7
+ *
8
+ * @param value - The value to stringify.
9
+ * @returns The stringified value.
10
+ */
11
+ export function stringify(value) {
12
+ return JSON.stringify(value, null, 2);
13
+ }
14
+ const JsonRpcEngineErrorSymbol = Symbol.for('JsonRpcEngineError');
15
+ export class JsonRpcEngineError extends Error {
16
+ constructor(message) {
17
+ super(message);
18
+ this[_a] = true;
19
+ this.name = 'JsonRpcEngineError';
20
+ }
21
+ /**
22
+ * Check if a value is a {@link JsonRpcEngineError} instance.
23
+ * Works across different package versions in the same realm.
24
+ *
25
+ * @param value - The value to check.
26
+ * @returns Whether the value is a {@link JsonRpcEngineError} instance.
27
+ */
28
+ static isInstance(value) {
29
+ return (hasProperty(value, JsonRpcEngineErrorSymbol) &&
30
+ value[JsonRpcEngineErrorSymbol] === true);
31
+ }
32
+ }
33
+ _a = JsonRpcEngineErrorSymbol;
34
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/v2/utils.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,WAAW,EAIZ,wBAAwB;AAazB,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,GAAwD,EACzB,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAE3D,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,GAAwB,EACY,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AAgBzD;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,wBAAwB,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAG3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHA,QAA0B,GAAG,IAAI,CAAC;QAIjD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CACf,KAAY;QAEZ,OAAO,CACL,WAAW,CAAC,KAAK,EAAE,wBAAwB,CAAC;YAC5C,KAAK,CAAC,wBAAwB,CAAC,KAAK,IAAI,CACzC,CAAC;IACJ,CAAC;CACF;KAtBmB,wBAAwB","sourcesContent":["import {\n hasProperty,\n type JsonRpcNotification,\n type JsonRpcParams,\n type JsonRpcRequest,\n} from '@metamask/utils';\n\nexport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcNotification,\n} from '@metamask/utils';\n\nexport type JsonRpcCall<Params extends JsonRpcParams = JsonRpcParams> =\n | JsonRpcNotification<Params>\n | JsonRpcRequest<Params>;\n\nexport const isRequest = <Params extends JsonRpcParams>(\n msg: JsonRpcCall<Params> | Readonly<JsonRpcCall<Params>>,\n): msg is JsonRpcRequest<Params> => hasProperty(msg, 'id');\n\nexport const isNotification = <Params extends JsonRpcParams>(\n msg: JsonRpcCall<Params>,\n): msg is JsonRpcNotification<Params> => !isRequest(msg);\n\n/**\n * An unholy incantation that converts a union of object types into an\n * intersection of object types.\n *\n * @example\n * type A = { a: string } | { b: number };\n * type B = UnionToIntersection<A>; // { a: string } & { b: number }\n */\nexport type UnionToIntersection<U> = (\n U extends never ? never : (k: U) => void\n) extends (k: infer I) => void\n ? I\n : never;\n\n/**\n * JSON-stringifies a value.\n *\n * @param value - The value to stringify.\n * @returns The stringified value.\n */\nexport function stringify(value: unknown): string {\n return JSON.stringify(value, null, 2);\n}\n\nconst JsonRpcEngineErrorSymbol = Symbol.for('JsonRpcEngineError');\n\nexport class JsonRpcEngineError extends Error {\n private readonly [JsonRpcEngineErrorSymbol] = true;\n\n constructor(message: string) {\n super(message);\n this.name = 'JsonRpcEngineError';\n }\n\n /**\n * Check if a value is a {@link JsonRpcEngineError} instance.\n * Works across different package versions in the same realm.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link JsonRpcEngineError} instance.\n */\n static isInstance<Value extends Error>(\n value: Value,\n ): value is Value & JsonRpcEngineError {\n return (\n hasProperty(value, JsonRpcEngineErrorSymbol) &&\n value[JsonRpcEngineErrorSymbol] === true\n );\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/json-rpc-engine",
3
- "version": "10.1.1-preview-63ea58af",
3
+ "version": "10.1.1-preview-0458fe94",
4
4
  "description": "A tool for processing JSON-RPC messages",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -27,6 +27,16 @@
27
27
  "default": "./dist/index.cjs"
28
28
  }
29
29
  },
30
+ "./v2": {
31
+ "import": {
32
+ "types": "./dist/v2/index.d.mts",
33
+ "default": "./dist/v2/index.mjs"
34
+ },
35
+ "require": {
36
+ "types": "./dist/v2/index.d.cts",
37
+ "default": "./dist/v2/index.cjs"
38
+ }
39
+ },
30
40
  "./package.json": "./package.json"
31
41
  },
32
42
  "main": "./dist/index.cjs",
@@ -35,7 +45,8 @@
35
45
  "test": "test"
36
46
  },
37
47
  "files": [
38
- "dist/"
48
+ "dist/",
49
+ "v2.js"
39
50
  ],
40
51
  "scripts": {
41
52
  "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
@@ -58,7 +69,10 @@
58
69
  "dependencies": {
59
70
  "@metamask/rpc-errors": "^7.0.2",
60
71
  "@metamask/safe-event-emitter": "^3.0.0",
61
- "@metamask/utils": "^11.8.1"
72
+ "@metamask/utils": "^11.8.1",
73
+ "@types/deep-freeze-strict": "^1.1.0",
74
+ "deep-freeze-strict": "^1.1.1",
75
+ "klona": "^2.0.6"
62
76
  },
63
77
  "devDependencies": {
64
78
  "@lavamoat/allow-scripts": "^3.0.4",
package/v2.js ADDED
@@ -0,0 +1,3 @@
1
+ // Re-exported for compatibility with Browserify.
2
+ // eslint-disable-next-line
3
+ module.exports = require('./dist/v2/index.cjs');