@metamask-previews/json-rpc-middleware-stream 8.0.8-preview-8bfa290fb → 9.0.0-preview-0a30e47
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 +11 -3
- package/dist/{createEngineStream.d.mts → createEngineStream.d.ts} +3 -3
- package/dist/createEngineStream.d.ts.map +1 -0
- package/dist/{createEngineStream.mjs → createEngineStream.js} +2 -2
- package/dist/createEngineStream.js.map +1 -0
- package/dist/{createStreamMiddleware.d.cts → createStreamMiddleware.d.ts} +4 -5
- package/dist/createStreamMiddleware.d.ts.map +1 -0
- package/dist/{createStreamMiddleware.mjs → createStreamMiddleware.js} +4 -4
- package/dist/createStreamMiddleware.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/package.json +14 -18
- package/dist/createEngineStream.cjs +0 -43
- package/dist/createEngineStream.cjs.map +0 -1
- package/dist/createEngineStream.d.cts +0 -15
- package/dist/createEngineStream.d.cts.map +0 -1
- package/dist/createEngineStream.d.mts.map +0 -1
- package/dist/createEngineStream.mjs.map +0 -1
- package/dist/createStreamMiddleware.cjs +0 -121
- package/dist/createStreamMiddleware.cjs.map +0 -1
- package/dist/createStreamMiddleware.d.cts.map +0 -1
- package/dist/createStreamMiddleware.d.mts +0 -23
- package/dist/createStreamMiddleware.d.mts.map +0 -1
- package/dist/createStreamMiddleware.mjs.map +0 -1
- package/dist/index.cjs +0 -11
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -4
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -4
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -4
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,10 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [9.0.0]
|
|
11
|
+
|
|
10
12
|
### Changed
|
|
11
13
|
|
|
14
|
+
- **BREAKING:** Drop CommonJS support ([#9536](https://github.com/MetaMask/core/pull/9536))
|
|
15
|
+
- This package is now ESM-only, but can still be used in CommonJS projects via `require(esm)` in modern Node.js versions (22+), or dynamic imports in older Node.js versions.
|
|
16
|
+
- **BREAKING:** Bump minimum Node.js version to 22 ([#9976](https://github.com/MetaMask/core/pull/9976))
|
|
17
|
+
- **BREAKING:** Bump TypeScript target to ES2022 ([#10019](https://github.com/MetaMask/core/pull/10019))
|
|
18
|
+
- This package now ships ES2022 code, requiring a compatible modern environment or bundler configuration to consume.
|
|
12
19
|
- Bump `@metamask/utils` from `^11.8.1` to `^11.12.0` ([#7511](https://github.com/MetaMask/core/pull/7511), [#9074](https://github.com/MetaMask/core/pull/9074), [#10076](https://github.com/MetaMask/core/pull/10076))
|
|
13
|
-
- Bump `@metamask/json-rpc-engine` from `^10.1.1` to `^
|
|
20
|
+
- Bump `@metamask/json-rpc-engine` from `^10.1.1` to `^11.0.0` ([#7202](https://github.com/MetaMask/core/pull/7202), [#7642](https://github.com/MetaMask/core/pull/7642), [#7856](https://github.com/MetaMask/core/pull/7856), [#8078](https://github.com/MetaMask/core/pull/8078), [#8317](https://github.com/MetaMask/core/pull/8317), [#8661](https://github.com/MetaMask/core/pull/8661), [#8746](https://github.com/MetaMask/core/pull/8746), [#8753](https://github.com/MetaMask/core/pull/8753), [#10160](https://github.com/MetaMask/core/pull/10160))
|
|
14
21
|
|
|
15
22
|
## [8.0.8]
|
|
16
23
|
|
|
@@ -61,7 +68,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
61
68
|
["Are the Types Wrong?"](https://arethetypeswrong.github.io/) tool as
|
|
62
69
|
["masquerading as CJS"](https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md).
|
|
63
70
|
All of the ATTW checks now pass.
|
|
64
|
-
- Remove chunk files ([#4648](https://github.com/MetaMask/core/pull/4648))
|
|
71
|
+
- Remove chunk files. ([#4648](https://github.com/MetaMask/core/pull/4648))
|
|
65
72
|
- Previously, the build tool we used to generate JavaScript files extracted
|
|
66
73
|
common code to "chunk" files. While this was intended to make this package
|
|
67
74
|
more tree-shakeable, it also made debugging more difficult for our
|
|
@@ -209,7 +216,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
209
216
|
|
|
210
217
|
- TypeScript typings ([#11](https://github.com/MetaMask/json-rpc-middleware-stream/pull/11))
|
|
211
218
|
|
|
212
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/json-rpc-middleware-stream@
|
|
219
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/json-rpc-middleware-stream@9.0.0...HEAD
|
|
220
|
+
[9.0.0]: https://github.com/MetaMask/core/compare/@metamask/json-rpc-middleware-stream@8.0.8...@metamask/json-rpc-middleware-stream@9.0.0
|
|
213
221
|
[8.0.8]: https://github.com/MetaMask/core/compare/@metamask/json-rpc-middleware-stream@8.0.7...@metamask/json-rpc-middleware-stream@8.0.8
|
|
214
222
|
[8.0.7]: https://github.com/MetaMask/core/compare/@metamask/json-rpc-middleware-stream@8.0.6...@metamask/json-rpc-middleware-stream@8.0.7
|
|
215
223
|
[8.0.6]: https://github.com/MetaMask/core/compare/@metamask/json-rpc-middleware-stream@8.0.5...@metamask/json-rpc-middleware-stream@8.0.6
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { JsonRpcEngine } from
|
|
2
|
-
import { Duplex } from
|
|
1
|
+
import type { JsonRpcEngine } from '@metamask/json-rpc-engine';
|
|
2
|
+
import { Duplex } from 'readable-stream';
|
|
3
3
|
type EngineStreamOptions = {
|
|
4
4
|
engine: JsonRpcEngine;
|
|
5
5
|
};
|
|
@@ -12,4 +12,4 @@ type EngineStreamOptions = {
|
|
|
12
12
|
*/
|
|
13
13
|
export default function createEngineStream(opts: EngineStreamOptions): Duplex;
|
|
14
14
|
export {};
|
|
15
|
-
//# sourceMappingURL=createEngineStream.d.
|
|
15
|
+
//# sourceMappingURL=createEngineStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createEngineStream.d.ts","sourceRoot":"","sources":["../src/createEngineStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CAoC5E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Duplex } from
|
|
1
|
+
import { Duplex } from 'readable-stream';
|
|
2
2
|
/**
|
|
3
3
|
* Takes a JsonRpcEngine and returns a Duplex stream wrapping it.
|
|
4
4
|
*
|
|
@@ -37,4 +37,4 @@ export default function createEngineStream(opts) {
|
|
|
37
37
|
streamWriteCallback();
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
//# sourceMappingURL=createEngineStream.
|
|
40
|
+
//# sourceMappingURL=createEngineStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createEngineStream.js","sourceRoot":"","sources":["../src/createEngineStream.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAMzC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,IAAyB;IAClE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACxB,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;QACxB,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,GAAc,EAAE,CAAC,SAAS;QAChC,KAAK;KACN,CAAC,CAAC;IACH,wBAAwB;IACxB,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE;YACpC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,SAAS,KAAK,CACZ,GAAmB,EACnB,SAAkB,EAClB,mBAAmD;QAEnD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YAC/B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;QACH,mBAAmB,EAAE,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport type { JsonRpcRequest } from '@metamask/utils';\nimport { Duplex } from 'readable-stream';\n\ntype EngineStreamOptions = {\n engine: JsonRpcEngine;\n};\n\n/**\n * Takes a JsonRpcEngine and returns a Duplex stream wrapping it.\n *\n * @param opts - Options bag.\n * @param opts.engine - The JsonRpcEngine to wrap in a stream.\n * @returns The stream wrapping the engine.\n */\nexport default function createEngineStream(opts: EngineStreamOptions): Duplex {\n if (!opts?.engine) {\n throw new Error('Missing engine parameter!');\n }\n\n const { engine } = opts;\n const stream = new Duplex({\n objectMode: true,\n read: (): undefined => undefined,\n write,\n });\n // forward notifications\n if (engine.on) {\n engine.on('notification', (message) => {\n stream.push(message);\n });\n }\n return stream;\n\n /**\n * Write a JSON-RPC request to the stream.\n *\n * @param req - The JSON-rpc request.\n * @param _encoding - The stream encoding, not used.\n * @param streamWriteCallback - The stream write callback.\n */\n function write(\n req: JsonRpcRequest,\n _encoding: unknown,\n streamWriteCallback: (error?: Error | null) => void,\n ): void {\n engine.handle(req, (_err, res) => {\n stream.push(res);\n });\n streamWriteCallback();\n }\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import type { JsonRpcParams } from "@metamask/utils";
|
|
1
|
+
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';
|
|
2
|
+
import SafeEventEmitter from '@metamask/safe-event-emitter';
|
|
3
|
+
import type { JsonRpcParams } from '@metamask/utils';
|
|
5
4
|
type Options = {
|
|
6
5
|
retryOnMessage?: string;
|
|
7
6
|
};
|
|
@@ -20,4 +19,4 @@ export default function createStreamMiddleware(options?: Options): {
|
|
|
20
19
|
stream: _Readable.Duplex;
|
|
21
20
|
};
|
|
22
21
|
export {};
|
|
23
|
-
//# sourceMappingURL=createStreamMiddleware.d.
|
|
22
|
+
//# sourceMappingURL=createStreamMiddleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createStreamMiddleware.d.ts","sourceRoot":"","sources":["../src/createStreamMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAE5D,OAAO,KAAK,EAEV,aAAa,EAGd,MAAM,iBAAiB,CAAC;AAezB,KAAK,OAAO,GAAG;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,OAAO,GAAE,OAAY,GAAG;IACrE,MAAM,EAAE,gBAAgB,CAAC;IACzB,UAAU,EAAE,iBAAiB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IAC5D,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC;CAC1B,CAyHA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import SafeEventEmitter from
|
|
2
|
-
import { hasProperty } from
|
|
3
|
-
import { Duplex } from
|
|
1
|
+
import SafeEventEmitter from '@metamask/safe-event-emitter';
|
|
2
|
+
import { hasProperty } from '@metamask/utils';
|
|
3
|
+
import { Duplex } from 'readable-stream';
|
|
4
4
|
/**
|
|
5
5
|
* Creates a JsonRpcEngine middleware with an associated Duplex stream and
|
|
6
6
|
* EventEmitter. The middleware, and by extension stream, assume that middleware
|
|
@@ -112,4 +112,4 @@ export default function createStreamMiddleware(options = {}) {
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
//# sourceMappingURL=createStreamMiddleware.
|
|
115
|
+
//# sourceMappingURL=createStreamMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createStreamMiddleware.js","sourceRoot":"","sources":["../src/createStreamMiddleware.ts"],"names":[],"mappings":"AAKA,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAO9C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAkBzC;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,OAAO,GAAY,EAAE;IAKlE,MAAM,KAAK,GAAU,EAAE,CAAC,CAAC,gCAAgC;IACzD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;QACxB,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,GAAc,EAAE,CAAC,SAAS;QAChC,KAAK,EAAE,cAAc;KACtB,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAEtC,MAAM,UAAU,GAAoD,CAClE,GAAG,EACH,GAAG,EACH,IAAI,EACJ,GAAG,EACH,EAAE;QACF,qFAAqF;QACrF,KAAK,CAAC,GAAG,CAAC,EAAuB,CAAC,GAAG,EAAE,GAAG,EAA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,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAChC,+BAA+B;QAC/B,uDAAuD;QACvD,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,SAAS,mBAAmB,CAAC,KAA0B;QACrD,IAAI,OAAO,EAAE,cAAc,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC;YACvE,kBAAkB,EAAE,CAAC;QACvB,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,SAAS,kBAAkB;QACzB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,GAAG,CAAC,EAAE,EAAE,EAAE;YACvD,2GAA2G;YAC3G,qFAAqF;YACrF,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACZ,OAAO;YACT,CAAC;YAED,IAAI,UAAU,IAAI,CAAC,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CACb,2DAA2D,GAAG,CAAC,EAAE,GAAG,CACrE,CAAC;YACJ,CAAC;YACD,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAClC,IAAI,WAAW,EAAE,CAAC;gBAChB,WAAW,CAAC,UAAU,GAAG,UAAU,GAAG,CAAC,CAAC;YAC1C,CAAC;YACD,YAAY,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n JsonRpcEngineNextCallback,\n JsonRpcEngineEndCallback,\n JsonRpcMiddleware,\n} from '@metamask/json-rpc-engine';\nimport SafeEventEmitter from '@metamask/safe-event-emitter';\nimport { hasProperty } from '@metamask/utils';\nimport type {\n JsonRpcNotification,\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\nimport { Duplex } from 'readable-stream';\n\ntype IdMapValue = {\n req: JsonRpcRequest;\n res: PendingJsonRpcResponse<JsonRpcParams>;\n next: JsonRpcEngineNextCallback;\n end: JsonRpcEngineEndCallback;\n retryCount?: number;\n};\n\ntype IdMap = {\n [requestId: string]: IdMapValue;\n};\n\ntype Options = {\n retryOnMessage?: string;\n};\n\n/**\n * Creates a JsonRpcEngine middleware with an associated Duplex stream and\n * EventEmitter. The middleware, and by extension stream, assume that middleware\n * parameters are properly formatted. No runtime type checking or validation is\n * performed.\n *\n * @param options - Configuration options for middleware.\n * @returns The event emitter, middleware, and stream.\n */\nexport default function createStreamMiddleware(options: Options = {}): {\n events: SafeEventEmitter;\n middleware: JsonRpcMiddleware<JsonRpcParams, JsonRpcParams>;\n stream: _Readable.Duplex;\n} {\n const idMap: IdMap = {}; // TODO: replace with actual Map\n const stream = new Duplex({\n objectMode: true,\n read: (): undefined => undefined,\n write: processMessage,\n });\n\n const events = new SafeEventEmitter();\n\n const middleware: JsonRpcMiddleware<JsonRpcParams, JsonRpcParams> = (\n req,\n res,\n next,\n end,\n ) => {\n // register request on id map *before* sending it to the stream, to avoid race issues\n idMap[req.id as unknown as string] = { req, res, next, end };\n // write req to stream\n sendToStream(req);\n };\n\n return { events, middleware, stream };\n\n /**\n * Forwards JSON-RPC request to the stream.\n *\n * @param req - The JSON-RPC request object.\n */\n function sendToStream(req: JsonRpcRequest): void {\n // TODO: limiting retries could be implemented here\n stream.push(req);\n }\n\n /**\n * Writes a JSON-RPC object to the stream.\n *\n * @param res - The JSON-RPC response object.\n * @param _encoding - The stream encoding, not used.\n * @param streamWriteCallback - The stream write callback.\n */\n function processMessage(\n res: PendingJsonRpcResponse<JsonRpcParams>,\n _encoding: unknown,\n streamWriteCallback: (error?: Error | null) => void,\n ): void {\n let errorObj: Error | null = null;\n try {\n const isNotification = !hasProperty(res, 'id');\n if (isNotification) {\n processNotification(res as unknown as JsonRpcNotification);\n } else {\n processResponse(res);\n }\n } catch (_err) {\n errorObj = _err as Error;\n }\n // continue processing stream\n streamWriteCallback(errorObj);\n }\n\n /**\n * Processes a JSON-RPC response.\n *\n * @param res - The response to process.\n */\n function processResponse(res: PendingJsonRpcResponse<JsonRpcParams>): void {\n const { id: responseId } = res;\n if (responseId === null) {\n return;\n }\n\n const context = idMap[responseId];\n if (!context) {\n console.warn(`StreamMiddleware - Unknown response id \"${responseId}\"`);\n return;\n }\n\n delete idMap[responseId];\n // copy whole res onto original res\n Object.assign(context.res, res);\n // run callback on empty stack,\n // prevent internal stream-handler from catching errors\n setTimeout(context.end);\n }\n\n /**\n * Processes a JSON-RPC notification.\n *\n * @param notif - The notification to process.\n */\n function processNotification(notif: JsonRpcNotification): void {\n if (options?.retryOnMessage && notif.method === options.retryOnMessage) {\n retryStuckRequests();\n }\n events.emit('notification', notif);\n }\n\n /**\n * Retry pending requests.\n */\n function retryStuckRequests(): void {\n Object.values(idMap).forEach(({ req, retryCount = 0 }) => {\n // Avoid retrying requests without an id - they cannot have matching responses so retry logic doesn't apply\n // Check for retry count below ensure that a request is not retried more than 3 times\n if (!req.id) {\n return;\n }\n\n if (retryCount >= 3) {\n throw new Error(\n `StreamMiddleware - Retry limit exceeded for request id \"${req.id}\"`,\n );\n }\n const idMapObject = idMap[req.id];\n if (idMapObject) {\n idMapObject.retryCount = retryCount + 1;\n }\n sendToStream(req);\n });\n }\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,sBAAsB,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,sBAAsB,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,CAAC","sourcesContent":["import createEngineStream from './createEngineStream.js';\nimport createStreamMiddleware from './createStreamMiddleware.js';\n\nexport { createEngineStream, createStreamMiddleware };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/json-rpc-middleware-stream",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-preview-0a30e47",
|
|
4
4
|
"description": "A small toolset for streaming JSON-RPC data and matching requests and responses",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -18,19 +18,12 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/"
|
|
20
20
|
],
|
|
21
|
+
"type": "module",
|
|
21
22
|
"sideEffects": false,
|
|
22
|
-
"main": "./dist/index.cjs",
|
|
23
|
-
"types": "./dist/index.d.cts",
|
|
24
23
|
"exports": {
|
|
25
24
|
".": {
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
"default": "./dist/index.mjs"
|
|
29
|
-
},
|
|
30
|
-
"require": {
|
|
31
|
-
"types": "./dist/index.d.cts",
|
|
32
|
-
"default": "./dist/index.cjs"
|
|
33
|
-
}
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
34
27
|
},
|
|
35
28
|
"./package.json": "./package.json"
|
|
36
29
|
},
|
|
@@ -39,9 +32,11 @@
|
|
|
39
32
|
"registry": "https://registry.npmjs.org/"
|
|
40
33
|
},
|
|
41
34
|
"scripts": {
|
|
42
|
-
"build": "
|
|
43
|
-
"build:all": "
|
|
35
|
+
"build": "tsc --project tsconfig.build.json",
|
|
36
|
+
"build:all": "tsc --build tsconfig.build.json --verbose",
|
|
37
|
+
"build:clean": "yarn build:only-clean && yarn build",
|
|
44
38
|
"build:docs": "typedoc",
|
|
39
|
+
"build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
|
|
45
40
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/json-rpc-middleware-stream --tag-prefix-before-package-rename json-rpc-middleware-stream@ --version-before-package-rename 5.0.1",
|
|
46
41
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/json-rpc-middleware-stream --tag-prefix-before-package-rename json-rpc-middleware-stream@ --version-before-package-rename 5.0.1",
|
|
47
42
|
"lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
|
|
@@ -53,27 +48,28 @@
|
|
|
53
48
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
54
49
|
},
|
|
55
50
|
"dependencies": {
|
|
56
|
-
"@metamask/json-rpc-engine": "^
|
|
57
|
-
"@metamask/safe-event-emitter": "^3.
|
|
51
|
+
"@metamask/json-rpc-engine": "^11.0.0",
|
|
52
|
+
"@metamask/safe-event-emitter": "^3.1.3",
|
|
58
53
|
"@metamask/utils": "^11.12.0",
|
|
59
54
|
"readable-stream": "^3.6.2"
|
|
60
55
|
},
|
|
61
56
|
"devDependencies": {
|
|
62
57
|
"@metamask/auto-changelog": "^6.1.0",
|
|
63
|
-
"@ts-bridge/cli": "^0.6.4",
|
|
64
58
|
"@types/jest": "^30.0.0",
|
|
65
59
|
"@types/readable-stream": "^2.3.0",
|
|
60
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
66
61
|
"deepmerge": "^4.2.2",
|
|
67
62
|
"extension-port-stream": "^3.0.0",
|
|
68
63
|
"jest": "^30.4.2",
|
|
64
|
+
"rimraf": "^5.0.5",
|
|
69
65
|
"ts-jest": "^29.4.11",
|
|
70
66
|
"tsx": "^4.20.5",
|
|
71
67
|
"typedoc": "^0.25.13",
|
|
72
68
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
73
|
-
"typescript": "
|
|
69
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
74
70
|
"webextension-polyfill-ts": "^0.26.0"
|
|
75
71
|
},
|
|
76
72
|
"engines": {
|
|
77
|
-
"node": "^
|
|
73
|
+
"node": "^22.14.0 || ^24"
|
|
78
74
|
}
|
|
79
75
|
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const readable_stream_1 = require("readable-stream");
|
|
4
|
-
/**
|
|
5
|
-
* Takes a JsonRpcEngine and returns a Duplex stream wrapping it.
|
|
6
|
-
*
|
|
7
|
-
* @param opts - Options bag.
|
|
8
|
-
* @param opts.engine - The JsonRpcEngine to wrap in a stream.
|
|
9
|
-
* @returns The stream wrapping the engine.
|
|
10
|
-
*/
|
|
11
|
-
function createEngineStream(opts) {
|
|
12
|
-
if (!opts?.engine) {
|
|
13
|
-
throw new Error('Missing engine parameter!');
|
|
14
|
-
}
|
|
15
|
-
const { engine } = opts;
|
|
16
|
-
const stream = new readable_stream_1.Duplex({
|
|
17
|
-
objectMode: true,
|
|
18
|
-
read: () => undefined,
|
|
19
|
-
write,
|
|
20
|
-
});
|
|
21
|
-
// forward notifications
|
|
22
|
-
if (engine.on) {
|
|
23
|
-
engine.on('notification', (message) => {
|
|
24
|
-
stream.push(message);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return stream;
|
|
28
|
-
/**
|
|
29
|
-
* Write a JSON-RPC request to the stream.
|
|
30
|
-
*
|
|
31
|
-
* @param req - The JSON-rpc request.
|
|
32
|
-
* @param _encoding - The stream encoding, not used.
|
|
33
|
-
* @param streamWriteCallback - The stream write callback.
|
|
34
|
-
*/
|
|
35
|
-
function write(req, _encoding, streamWriteCallback) {
|
|
36
|
-
engine.handle(req, (_err, res) => {
|
|
37
|
-
stream.push(res);
|
|
38
|
-
});
|
|
39
|
-
streamWriteCallback();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.default = createEngineStream;
|
|
43
|
-
//# sourceMappingURL=createEngineStream.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createEngineStream.cjs","sourceRoot":"","sources":["../src/createEngineStream.ts"],"names":[],"mappings":";;AAEA,qDAAyC;AAMzC;;;;;;GAMG;AACH,SAAwB,kBAAkB,CAAC,IAAyB;IAClE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACxB,MAAM,MAAM,GAAG,IAAI,wBAAM,CAAC;QACxB,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,GAAc,EAAE,CAAC,SAAS;QAChC,KAAK;KACN,CAAC,CAAC;IACH,wBAAwB;IACxB,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE;YACpC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,SAAS,KAAK,CACZ,GAAmB,EACnB,SAAkB,EAClB,mBAAmD;QAEnD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YAC/B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;QACH,mBAAmB,EAAE,CAAC;IACxB,CAAC;AACH,CAAC;AApCD,qCAoCC","sourcesContent":["import type { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport type { JsonRpcRequest } from '@metamask/utils';\nimport { Duplex } from 'readable-stream';\n\ntype EngineStreamOptions = {\n engine: JsonRpcEngine;\n};\n\n/**\n * Takes a JsonRpcEngine and returns a Duplex stream wrapping it.\n *\n * @param opts - Options bag.\n * @param opts.engine - The JsonRpcEngine to wrap in a stream.\n * @returns The stream wrapping the engine.\n */\nexport default function createEngineStream(opts: EngineStreamOptions): Duplex {\n if (!opts?.engine) {\n throw new Error('Missing engine parameter!');\n }\n\n const { engine } = opts;\n const stream = new Duplex({\n objectMode: true,\n read: (): undefined => undefined,\n write,\n });\n // forward notifications\n if (engine.on) {\n engine.on('notification', (message) => {\n stream.push(message);\n });\n }\n return stream;\n\n /**\n * Write a JSON-RPC request to the stream.\n *\n * @param req - The JSON-rpc request.\n * @param _encoding - The stream encoding, not used.\n * @param streamWriteCallback - The stream write callback.\n */\n function write(\n req: JsonRpcRequest,\n _encoding: unknown,\n streamWriteCallback: (error?: Error | null) => void,\n ): void {\n engine.handle(req, (_err, res) => {\n stream.push(res);\n });\n streamWriteCallback();\n }\n}\n"]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
2
|
-
import { Duplex } from "readable-stream";
|
|
3
|
-
type EngineStreamOptions = {
|
|
4
|
-
engine: JsonRpcEngine;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Takes a JsonRpcEngine and returns a Duplex stream wrapping it.
|
|
8
|
-
*
|
|
9
|
-
* @param opts - Options bag.
|
|
10
|
-
* @param opts.engine - The JsonRpcEngine to wrap in a stream.
|
|
11
|
-
* @returns The stream wrapping the engine.
|
|
12
|
-
*/
|
|
13
|
-
export default function createEngineStream(opts: EngineStreamOptions): Duplex;
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=createEngineStream.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createEngineStream.d.cts","sourceRoot":"","sources":["../src/createEngineStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kCAAkC;AAE/D,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAEzC,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CAoC5E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createEngineStream.d.mts","sourceRoot":"","sources":["../src/createEngineStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kCAAkC;AAE/D,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAEzC,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CAoC5E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createEngineStream.mjs","sourceRoot":"","sources":["../src/createEngineStream.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAMzC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,IAAyB;IAClE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACxB,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;QACxB,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,GAAc,EAAE,CAAC,SAAS;QAChC,KAAK;KACN,CAAC,CAAC;IACH,wBAAwB;IACxB,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE;YACpC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,SAAS,KAAK,CACZ,GAAmB,EACnB,SAAkB,EAClB,mBAAmD;QAEnD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YAC/B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;QACH,mBAAmB,EAAE,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport type { JsonRpcRequest } from '@metamask/utils';\nimport { Duplex } from 'readable-stream';\n\ntype EngineStreamOptions = {\n engine: JsonRpcEngine;\n};\n\n/**\n * Takes a JsonRpcEngine and returns a Duplex stream wrapping it.\n *\n * @param opts - Options bag.\n * @param opts.engine - The JsonRpcEngine to wrap in a stream.\n * @returns The stream wrapping the engine.\n */\nexport default function createEngineStream(opts: EngineStreamOptions): Duplex {\n if (!opts?.engine) {\n throw new Error('Missing engine parameter!');\n }\n\n const { engine } = opts;\n const stream = new Duplex({\n objectMode: true,\n read: (): undefined => undefined,\n write,\n });\n // forward notifications\n if (engine.on) {\n engine.on('notification', (message) => {\n stream.push(message);\n });\n }\n return stream;\n\n /**\n * Write a JSON-RPC request to the stream.\n *\n * @param req - The JSON-rpc request.\n * @param _encoding - The stream encoding, not used.\n * @param streamWriteCallback - The stream write callback.\n */\n function write(\n req: JsonRpcRequest,\n _encoding: unknown,\n streamWriteCallback: (error?: Error | null) => void,\n ): void {\n engine.handle(req, (_err, res) => {\n stream.push(res);\n });\n streamWriteCallback();\n }\n}\n"]}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const safe_event_emitter_1 = __importDefault(require("@metamask/safe-event-emitter"));
|
|
7
|
-
const utils_1 = require("@metamask/utils");
|
|
8
|
-
const readable_stream_1 = require("readable-stream");
|
|
9
|
-
/**
|
|
10
|
-
* Creates a JsonRpcEngine middleware with an associated Duplex stream and
|
|
11
|
-
* EventEmitter. The middleware, and by extension stream, assume that middleware
|
|
12
|
-
* parameters are properly formatted. No runtime type checking or validation is
|
|
13
|
-
* performed.
|
|
14
|
-
*
|
|
15
|
-
* @param options - Configuration options for middleware.
|
|
16
|
-
* @returns The event emitter, middleware, and stream.
|
|
17
|
-
*/
|
|
18
|
-
function createStreamMiddleware(options = {}) {
|
|
19
|
-
const idMap = {}; // TODO: replace with actual Map
|
|
20
|
-
const stream = new readable_stream_1.Duplex({
|
|
21
|
-
objectMode: true,
|
|
22
|
-
read: () => undefined,
|
|
23
|
-
write: processMessage,
|
|
24
|
-
});
|
|
25
|
-
const events = new safe_event_emitter_1.default();
|
|
26
|
-
const middleware = (req, res, next, end) => {
|
|
27
|
-
// register request on id map *before* sending it to the stream, to avoid race issues
|
|
28
|
-
idMap[req.id] = { req, res, next, end };
|
|
29
|
-
// write req to stream
|
|
30
|
-
sendToStream(req);
|
|
31
|
-
};
|
|
32
|
-
return { events, middleware, stream };
|
|
33
|
-
/**
|
|
34
|
-
* Forwards JSON-RPC request to the stream.
|
|
35
|
-
*
|
|
36
|
-
* @param req - The JSON-RPC request object.
|
|
37
|
-
*/
|
|
38
|
-
function sendToStream(req) {
|
|
39
|
-
// TODO: limiting retries could be implemented here
|
|
40
|
-
stream.push(req);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Writes a JSON-RPC object to the stream.
|
|
44
|
-
*
|
|
45
|
-
* @param res - The JSON-RPC response object.
|
|
46
|
-
* @param _encoding - The stream encoding, not used.
|
|
47
|
-
* @param streamWriteCallback - The stream write callback.
|
|
48
|
-
*/
|
|
49
|
-
function processMessage(res, _encoding, streamWriteCallback) {
|
|
50
|
-
let errorObj = null;
|
|
51
|
-
try {
|
|
52
|
-
const isNotification = !(0, utils_1.hasProperty)(res, 'id');
|
|
53
|
-
if (isNotification) {
|
|
54
|
-
processNotification(res);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
processResponse(res);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch (_err) {
|
|
61
|
-
errorObj = _err;
|
|
62
|
-
}
|
|
63
|
-
// continue processing stream
|
|
64
|
-
streamWriteCallback(errorObj);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Processes a JSON-RPC response.
|
|
68
|
-
*
|
|
69
|
-
* @param res - The response to process.
|
|
70
|
-
*/
|
|
71
|
-
function processResponse(res) {
|
|
72
|
-
const { id: responseId } = res;
|
|
73
|
-
if (responseId === null) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const context = idMap[responseId];
|
|
77
|
-
if (!context) {
|
|
78
|
-
console.warn(`StreamMiddleware - Unknown response id "${responseId}"`);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
delete idMap[responseId];
|
|
82
|
-
// copy whole res onto original res
|
|
83
|
-
Object.assign(context.res, res);
|
|
84
|
-
// run callback on empty stack,
|
|
85
|
-
// prevent internal stream-handler from catching errors
|
|
86
|
-
setTimeout(context.end);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Processes a JSON-RPC notification.
|
|
90
|
-
*
|
|
91
|
-
* @param notif - The notification to process.
|
|
92
|
-
*/
|
|
93
|
-
function processNotification(notif) {
|
|
94
|
-
if (options?.retryOnMessage && notif.method === options.retryOnMessage) {
|
|
95
|
-
retryStuckRequests();
|
|
96
|
-
}
|
|
97
|
-
events.emit('notification', notif);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Retry pending requests.
|
|
101
|
-
*/
|
|
102
|
-
function retryStuckRequests() {
|
|
103
|
-
Object.values(idMap).forEach(({ req, retryCount = 0 }) => {
|
|
104
|
-
// Avoid retrying requests without an id - they cannot have matching responses so retry logic doesn't apply
|
|
105
|
-
// Check for retry count below ensure that a request is not retried more than 3 times
|
|
106
|
-
if (!req.id) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
if (retryCount >= 3) {
|
|
110
|
-
throw new Error(`StreamMiddleware - Retry limit exceeded for request id "${req.id}"`);
|
|
111
|
-
}
|
|
112
|
-
const idMapObject = idMap[req.id];
|
|
113
|
-
if (idMapObject) {
|
|
114
|
-
idMapObject.retryCount = retryCount + 1;
|
|
115
|
-
}
|
|
116
|
-
sendToStream(req);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.default = createStreamMiddleware;
|
|
121
|
-
//# sourceMappingURL=createStreamMiddleware.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createStreamMiddleware.cjs","sourceRoot":"","sources":["../src/createStreamMiddleware.ts"],"names":[],"mappings":";;;;;AAKA,sFAA4D;AAC5D,2CAA8C;AAO9C,qDAAyC;AAkBzC;;;;;;;;GAQG;AACH,SAAwB,sBAAsB,CAAC,UAAmB,EAAE;IAKlE,MAAM,KAAK,GAAU,EAAE,CAAC,CAAC,gCAAgC;IACzD,MAAM,MAAM,GAAG,IAAI,wBAAM,CAAC;QACxB,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,GAAc,EAAE,CAAC,SAAS;QAChC,KAAK,EAAE,cAAc;KACtB,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,IAAI,4BAAgB,EAAE,CAAC;IAEtC,MAAM,UAAU,GAAoD,CAClE,GAAG,EACH,GAAG,EACH,IAAI,EACJ,GAAG,EACH,EAAE;QACF,qFAAqF;QACrF,KAAK,CAAC,GAAG,CAAC,EAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;QAC7D,sBAAsB;QACtB,YAAY,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,CAAC;IAEF,OAAO,EA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,CAAC;IAED;;;;OAIG;IACH,SAAS,mBAAmB,CAAC,KAA0B;QACrD,IAAI,OAAO,EAAE,cAAc,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC;YACvE,kBAAkB,EAAE,CAAC;QACvB,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,SAAS,kBAAkB;QACzB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,GAAG,CAAC,EAAE,EAAE,EAAE;YACvD,2GAA2G;YAC3G,qFAAqF;YACrF,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACZ,OAAO;YACT,CAAC;YAED,IAAI,UAAU,IAAI,CAAC,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CACb,2DAA2D,GAAG,CAAC,EAAE,GAAG,CACrE,CAAC;YACJ,CAAC;YACD,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAClC,IAAI,WAAW,EAAE,CAAC;gBAChB,WAAW,CAAC,UAAU,GAAG,UAAU,GAAG,CAAC,CAAC;YAC1C,CAAC;YACD,YAAY,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AA7HD,yCA6HC","sourcesContent":["import type {\n JsonRpcEngineNextCallback,\n JsonRpcEngineEndCallback,\n JsonRpcMiddleware,\n} from '@metamask/json-rpc-engine';\nimport SafeEventEmitter from '@metamask/safe-event-emitter';\nimport { hasProperty } from '@metamask/utils';\nimport type {\n JsonRpcNotification,\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\nimport { Duplex } from 'readable-stream';\n\ntype IdMapValue = {\n req: JsonRpcRequest;\n res: PendingJsonRpcResponse<JsonRpcParams>;\n next: JsonRpcEngineNextCallback;\n end: JsonRpcEngineEndCallback;\n retryCount?: number;\n};\n\ntype IdMap = {\n [requestId: string]: IdMapValue;\n};\n\ntype Options = {\n retryOnMessage?: string;\n};\n\n/**\n * Creates a JsonRpcEngine middleware with an associated Duplex stream and\n * EventEmitter. The middleware, and by extension stream, assume that middleware\n * parameters are properly formatted. No runtime type checking or validation is\n * performed.\n *\n * @param options - Configuration options for middleware.\n * @returns The event emitter, middleware, and stream.\n */\nexport default function createStreamMiddleware(options: Options = {}): {\n events: SafeEventEmitter;\n middleware: JsonRpcMiddleware<JsonRpcParams, JsonRpcParams>;\n stream: _Readable.Duplex;\n} {\n const idMap: IdMap = {}; // TODO: replace with actual Map\n const stream = new Duplex({\n objectMode: true,\n read: (): undefined => undefined,\n write: processMessage,\n });\n\n const events = new SafeEventEmitter();\n\n const middleware: JsonRpcMiddleware<JsonRpcParams, JsonRpcParams> = (\n req,\n res,\n next,\n end,\n ) => {\n // register request on id map *before* sending it to the stream, to avoid race issues\n idMap[req.id as unknown as string] = { req, res, next, end };\n // write req to stream\n sendToStream(req);\n };\n\n return { events, middleware, stream };\n\n /**\n * Forwards JSON-RPC request to the stream.\n *\n * @param req - The JSON-RPC request object.\n */\n function sendToStream(req: JsonRpcRequest): void {\n // TODO: limiting retries could be implemented here\n stream.push(req);\n }\n\n /**\n * Writes a JSON-RPC object to the stream.\n *\n * @param res - The JSON-RPC response object.\n * @param _encoding - The stream encoding, not used.\n * @param streamWriteCallback - The stream write callback.\n */\n function processMessage(\n res: PendingJsonRpcResponse<JsonRpcParams>,\n _encoding: unknown,\n streamWriteCallback: (error?: Error | null) => void,\n ): void {\n let errorObj: Error | null = null;\n try {\n const isNotification = !hasProperty(res, 'id');\n if (isNotification) {\n processNotification(res as unknown as JsonRpcNotification);\n } else {\n processResponse(res);\n }\n } catch (_err) {\n errorObj = _err as Error;\n }\n // continue processing stream\n streamWriteCallback(errorObj);\n }\n\n /**\n * Processes a JSON-RPC response.\n *\n * @param res - The response to process.\n */\n function processResponse(res: PendingJsonRpcResponse<JsonRpcParams>): void {\n const { id: responseId } = res;\n if (responseId === null) {\n return;\n }\n\n const context = idMap[responseId];\n if (!context) {\n console.warn(`StreamMiddleware - Unknown response id \"${responseId}\"`);\n return;\n }\n\n delete idMap[responseId];\n // copy whole res onto original res\n Object.assign(context.res, res);\n // run callback on empty stack,\n // prevent internal stream-handler from catching errors\n setTimeout(context.end);\n }\n\n /**\n * Processes a JSON-RPC notification.\n *\n * @param notif - The notification to process.\n */\n function processNotification(notif: JsonRpcNotification): void {\n if (options?.retryOnMessage && notif.method === options.retryOnMessage) {\n retryStuckRequests();\n }\n events.emit('notification', notif);\n }\n\n /**\n * Retry pending requests.\n */\n function retryStuckRequests(): void {\n Object.values(idMap).forEach(({ req, retryCount = 0 }) => {\n // Avoid retrying requests without an id - they cannot have matching responses so retry logic doesn't apply\n // Check for retry count below ensure that a request is not retried more than 3 times\n if (!req.id) {\n return;\n }\n\n if (retryCount >= 3) {\n throw new Error(\n `StreamMiddleware - Retry limit exceeded for request id \"${req.id}\"`,\n );\n }\n const idMapObject = idMap[req.id];\n if (idMapObject) {\n idMapObject.retryCount = retryCount + 1;\n }\n sendToStream(req);\n });\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createStreamMiddleware.d.cts","sourceRoot":"","sources":["../src/createStreamMiddleware.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAGV,iBAAiB,EAClB,kCAAkC;AACnC,OAAO,gBAAgB,qCAAqC;AAE5D,OAAO,KAAK,EAEV,aAAa,EAGd,wBAAwB;AAezB,KAAK,OAAO,GAAG;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,OAAO,GAAE,OAAY,GAAG;IACrE,MAAM,EAAE,gBAAgB,CAAC;IACzB,UAAU,EAAE,iBAAiB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IAC5D,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC;CAC1B,CAyHA"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/// <reference types="readable-stream" />
|
|
2
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
3
|
-
import SafeEventEmitter from "@metamask/safe-event-emitter";
|
|
4
|
-
import type { JsonRpcParams } from "@metamask/utils";
|
|
5
|
-
type Options = {
|
|
6
|
-
retryOnMessage?: string;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Creates a JsonRpcEngine middleware with an associated Duplex stream and
|
|
10
|
-
* EventEmitter. The middleware, and by extension stream, assume that middleware
|
|
11
|
-
* parameters are properly formatted. No runtime type checking or validation is
|
|
12
|
-
* performed.
|
|
13
|
-
*
|
|
14
|
-
* @param options - Configuration options for middleware.
|
|
15
|
-
* @returns The event emitter, middleware, and stream.
|
|
16
|
-
*/
|
|
17
|
-
export default function createStreamMiddleware(options?: Options): {
|
|
18
|
-
events: SafeEventEmitter;
|
|
19
|
-
middleware: JsonRpcMiddleware<JsonRpcParams, JsonRpcParams>;
|
|
20
|
-
stream: _Readable.Duplex;
|
|
21
|
-
};
|
|
22
|
-
export {};
|
|
23
|
-
//# sourceMappingURL=createStreamMiddleware.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createStreamMiddleware.d.mts","sourceRoot":"","sources":["../src/createStreamMiddleware.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAGV,iBAAiB,EAClB,kCAAkC;AACnC,OAAO,gBAAgB,qCAAqC;AAE5D,OAAO,KAAK,EAEV,aAAa,EAGd,wBAAwB;AAezB,KAAK,OAAO,GAAG;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,OAAO,GAAE,OAAY,GAAG;IACrE,MAAM,EAAE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ED;;OAEG;IACH,SAAS,kBAAkB;QACzB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,GAAG,CAAC,EAAE,EAAE,EAAE;YACvD,2GAA2G;YAC3G,qFAAqF;YACrF,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACZ,OAAO;YACT,CAAC;YAED,IAAI,UAAU,IAAI,CAAC,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CACb,2DAA2D,GAAG,CAAC,EAAE,GAAG,CACrE,CAAC;YACJ,CAAC;YACD,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAClC,IAAI,WAAW,EAAE,CAAC;gBAChB,WAAW,CAAC,UAAU,GAAG,UAAU,GAAG,CAAC,CAAC;YAC1C,CAAC;YACD,YAAY,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n JsonRpcEngineNextCallback,\n JsonRpcEngineEndCallback,\n JsonRpcMiddleware,\n} from '@metamask/json-rpc-engine';\nimport SafeEventEmitter from '@metamask/safe-event-emitter';\nimport { hasProperty } from '@metamask/utils';\nimport type {\n JsonRpcNotification,\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\nimport { Duplex } from 'readable-stream';\n\ntype IdMapValue = {\n req: JsonRpcRequest;\n res: PendingJsonRpcResponse<JsonRpcParams>;\n next: JsonRpcEngineNextCallback;\n end: JsonRpcEngineEndCallback;\n retryCount?: number;\n};\n\ntype IdMap = {\n [requestId: string]: IdMapValue;\n};\n\ntype Options = {\n retryOnMessage?: string;\n};\n\n/**\n * Creates a JsonRpcEngine middleware with an associated Duplex stream and\n * EventEmitter. The middleware, and by extension stream, assume that middleware\n * parameters are properly formatted. No runtime type checking or validation is\n * performed.\n *\n * @param options - Configuration options for middleware.\n * @returns The event emitter, middleware, and stream.\n */\nexport default function createStreamMiddleware(options: Options = {}): {\n events: SafeEventEmitter;\n middleware: JsonRpcMiddleware<JsonRpcParams, JsonRpcParams>;\n stream: _Readable.Duplex;\n} {\n const idMap: IdMap = {}; // TODO: replace with actual Map\n const stream = new Duplex({\n objectMode: true,\n read: (): undefined => undefined,\n write: processMessage,\n });\n\n const events = new SafeEventEmitter();\n\n const middleware: JsonRpcMiddleware<JsonRpcParams, JsonRpcParams> = (\n req,\n res,\n next,\n end,\n ) => {\n // register request on id map *before* sending it to the stream, to avoid race issues\n idMap[req.id as unknown as string] = { req, res, next, end };\n // write req to stream\n sendToStream(req);\n };\n\n return { events, middleware, stream };\n\n /**\n * Forwards JSON-RPC request to the stream.\n *\n * @param req - The JSON-RPC request object.\n */\n function sendToStream(req: JsonRpcRequest): void {\n // TODO: limiting retries could be implemented here\n stream.push(req);\n }\n\n /**\n * Writes a JSON-RPC object to the stream.\n *\n * @param res - The JSON-RPC response object.\n * @param _encoding - The stream encoding, not used.\n * @param streamWriteCallback - The stream write callback.\n */\n function processMessage(\n res: PendingJsonRpcResponse<JsonRpcParams>,\n _encoding: unknown,\n streamWriteCallback: (error?: Error | null) => void,\n ): void {\n let errorObj: Error | null = null;\n try {\n const isNotification = !hasProperty(res, 'id');\n if (isNotification) {\n processNotification(res as unknown as JsonRpcNotification);\n } else {\n processResponse(res);\n }\n } catch (_err) {\n errorObj = _err as Error;\n }\n // continue processing stream\n streamWriteCallback(errorObj);\n }\n\n /**\n * Processes a JSON-RPC response.\n *\n * @param res - The response to process.\n */\n function processResponse(res: PendingJsonRpcResponse<JsonRpcParams>): void {\n const { id: responseId } = res;\n if (responseId === null) {\n return;\n }\n\n const context = idMap[responseId];\n if (!context) {\n console.warn(`StreamMiddleware - Unknown response id \"${responseId}\"`);\n return;\n }\n\n delete idMap[responseId];\n // copy whole res onto original res\n Object.assign(context.res, res);\n // run callback on empty stack,\n // prevent internal stream-handler from catching errors\n setTimeout(context.end);\n }\n\n /**\n * Processes a JSON-RPC notification.\n *\n * @param notif - The notification to process.\n */\n function processNotification(notif: JsonRpcNotification): void {\n if (options?.retryOnMessage && notif.method === options.retryOnMessage) {\n retryStuckRequests();\n }\n events.emit('notification', notif);\n }\n\n /**\n * Retry pending requests.\n */\n function retryStuckRequests(): void {\n Object.values(idMap).forEach(({ req, retryCount = 0 }) => {\n // Avoid retrying requests without an id - they cannot have matching responses so retry logic doesn't apply\n // Check for retry count below ensure that a request is not retried more than 3 times\n if (!req.id) {\n return;\n }\n\n if (retryCount >= 3) {\n throw new Error(\n `StreamMiddleware - Retry limit exceeded for request id \"${req.id}\"`,\n );\n }\n const idMapObject = idMap[req.id];\n if (idMapObject) {\n idMapObject.retryCount = retryCount + 1;\n }\n sendToStream(req);\n });\n }\n}\n"]}
|
package/dist/index.cjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createStreamMiddleware = exports.createEngineStream = void 0;
|
|
7
|
-
const createEngineStream_js_1 = __importDefault(require("./createEngineStream.cjs"));
|
|
8
|
-
exports.createEngineStream = createEngineStream_js_1.default;
|
|
9
|
-
const createStreamMiddleware_js_1 = __importDefault(require("./createStreamMiddleware.cjs"));
|
|
10
|
-
exports.createStreamMiddleware = createStreamMiddleware_js_1.default;
|
|
11
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,qFAAyD;AAGhD,6BAHF,+BAAkB,CAGE;AAF3B,6FAAiE;AAEpC,iCAFtB,mCAAsB,CAEsB","sourcesContent":["import createEngineStream from './createEngineStream.js';\nimport createStreamMiddleware from './createStreamMiddleware.js';\n\nexport { createEngineStream, createStreamMiddleware };\n"]}
|
package/dist/index.d.cts
DELETED
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,iCAAgC;AACzD,OAAO,sBAAsB,qCAAoC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,CAAC"}
|
package/dist/index.d.mts
DELETED
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,iCAAgC;AACzD,OAAO,sBAAsB,qCAAoC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,CAAC"}
|
package/dist/index.mjs
DELETED
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,iCAAgC;AACzD,OAAO,sBAAsB,qCAAoC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,CAAC","sourcesContent":["import createEngineStream from './createEngineStream.js';\nimport createStreamMiddleware from './createStreamMiddleware.js';\n\nexport { createEngineStream, createStreamMiddleware };\n"]}
|