@metamask-previews/json-rpc-engine 7.2.0-preview.80566a6
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 +95 -0
- package/LICENSE +15 -0
- package/README.md +204 -0
- package/dist/JsonRpcEngine.d.ts +114 -0
- package/dist/JsonRpcEngine.d.ts.map +1 -0
- package/dist/JsonRpcEngine.js +357 -0
- package/dist/JsonRpcEngine.js.map +1 -0
- package/dist/createAsyncMiddleware.d.ts +27 -0
- package/dist/createAsyncMiddleware.d.ts.map +1 -0
- package/dist/createAsyncMiddleware.js +79 -0
- package/dist/createAsyncMiddleware.js.map +1 -0
- package/dist/createScaffoldMiddleware.d.ts +17 -0
- package/dist/createScaffoldMiddleware.d.ts.map +1 -0
- package/dist/createScaffoldMiddleware.js +30 -0
- package/dist/createScaffoldMiddleware.js.map +1 -0
- package/dist/getUniqueId.d.ts +9 -0
- package/dist/getUniqueId.d.ts.map +1 -0
- package/dist/getUniqueId.js +20 -0
- package/dist/getUniqueId.js.map +1 -0
- package/dist/idRemapMiddleware.d.ts +13 -0
- package/dist/idRemapMiddleware.d.ts.map +1 -0
- package/dist/idRemapMiddleware.js +28 -0
- package/dist/idRemapMiddleware.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/mergeMiddleware.d.ts +10 -0
- package/dist/mergeMiddleware.d.ts.map +1 -0
- package/dist/mergeMiddleware.js +17 -0
- package/dist/mergeMiddleware.js.map +1 -0
- package/package.json +73 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [7.2.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Applied eslint rules from core monorepo ([#172](https://github.com/MetaMask/json-rpc-engine/pull/172))
|
|
12
|
+
|
|
13
|
+
## [7.1.1]
|
|
14
|
+
### Changed
|
|
15
|
+
- Bumped `@metamask/utils` from `^5.0.2` to `^8.1.0` [#158](https://github.com/MetaMask/json-rpc-engine/pull/158) ([#162](https://github.com/MetaMask/json-rpc-engine/pull/162))
|
|
16
|
+
- Bumped `@metamask/rpc-errors` from `^5.0.0` to `^6.0.0` ([#162](https://github.com/MetaMask/json-rpc-engine/pull/162))
|
|
17
|
+
|
|
18
|
+
## [7.1.0]
|
|
19
|
+
### Changed
|
|
20
|
+
- Bumped `@metamask/safe-event-emitter` from `^2.0.0` to `^3.0.0` ([#148](https://github.com/MetaMask/json-rpc-engine/pull/148))
|
|
21
|
+
- Bumped `@metamask/utils` from `^5.0.1` to `^5.0.2` ([#151](https://github.com/MetaMask/json-rpc-engine/pull/151))
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
- Fixed handling of empty batch array in requests ([#153](https://github.com/MetaMask/json-rpc-engine/pull/153))
|
|
25
|
+
|
|
26
|
+
## [7.0.0]
|
|
27
|
+
### Added
|
|
28
|
+
- Added JSON-RPC notification handling ([#104](https://github.com/MetaMask/json-rpc-engine/pull/104))
|
|
29
|
+
- Added `destroy` method ([#106](https://github.com/MetaMask/json-rpc-engine/pull/106))
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
- **BREAKING:** Require a minimum Node version of 16 ([#139](https://github.com/MetaMask/json-rpc-engine/pull/139))
|
|
33
|
+
- **BREAKING:** Use `@metamask/utils` types ([#105](https://github.com/MetaMask/json-rpc-engine/pull/105))
|
|
34
|
+
- The JSON-RPC engine and all middleware now use `@metamask/utils` JSON-RPC types
|
|
35
|
+
- **(BREAKING)** Return a `null` instead of `undefined` response `id` for malformed request objects ([#91](https://github.com/MetaMask/json-rpc-engine/pull/91))
|
|
36
|
+
- This is very unlikely to be breaking in practice, but the behavior could have been relied on.
|
|
37
|
+
- Change package name to `@metamask/json-rpc-engine` ([#139](https://github.com/MetaMask/json-rpc-engine/pull/139))
|
|
38
|
+
- Use `@metamask/rpc-errors` ([#138](https://github.com/MetaMask/json-rpc-engine/pull/138))
|
|
39
|
+
|
|
40
|
+
## [6.1.0] - 2020-11-20
|
|
41
|
+
### Added
|
|
42
|
+
- Add `PendingJsonRpcResponse` interface for use in middleware ([#75](https://github.com/MetaMask/json-rpc-engine/pull/75))
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
- Use `async`/`await` and `try`/`catch` instead of Promise methods everywhere ([#74](https://github.com/MetaMask/json-rpc-engine/pull/74))
|
|
46
|
+
- Consumers may notice improved stack traces on certain platforms.
|
|
47
|
+
|
|
48
|
+
## [6.0.0] - 2020-11-19
|
|
49
|
+
### Added
|
|
50
|
+
- Add docstrings for public `JsonRpcEngine` methods ([#70](https://github.com/MetaMask/json-rpc-engine/pull/70))
|
|
51
|
+
|
|
52
|
+
### Changed
|
|
53
|
+
- **(BREAKING)** Refactor exports ([#69](https://github.com/MetaMask/json-rpc-engine/pull/69))
|
|
54
|
+
- All exports are now named, and available via the package entry point.
|
|
55
|
+
- All default exports have been removed.
|
|
56
|
+
- **(BREAKING)** Convert `asMiddleware` to instance method ([#69](https://github.com/MetaMask/json-rpc-engine/pull/69))
|
|
57
|
+
- The `asMiddleware` export has been removed.
|
|
58
|
+
- **(BREAKING)** Add runtime typechecks to `JsonRpcEngine.handle()`, and error responses if they fail ([#70](https://github.com/MetaMask/json-rpc-engine/pull/70))
|
|
59
|
+
- Requests will now error if:
|
|
60
|
+
- The request is not a plain object, or if the `method` property is not a `string`. Empty strings are allowed.
|
|
61
|
+
- A `next` middleware callback is called with a truthy, non-function parameter.
|
|
62
|
+
- Migrate to TypeScript ([#69](https://github.com/MetaMask/json-rpc-engine/pull/69))
|
|
63
|
+
- Hopefully improve stack traces by removing uses of `Promise.then` and `.catch` internally ([#70](https://github.com/MetaMask/json-rpc-engine/pull/70))
|
|
64
|
+
- Make some internal `JsonRpcEngine` methods `static` ([#71](https://github.com/MetaMask/json-rpc-engine/pull/71))
|
|
65
|
+
|
|
66
|
+
## [5.4.0] - 2020-11-07
|
|
67
|
+
### Changed
|
|
68
|
+
- Make the TypeScript types not terrible ([#66](https://github.com/MetaMask/json-rpc-engine/pull/66), [#67](https://github.com/MetaMask/json-rpc-engine/pull/67))
|
|
69
|
+
|
|
70
|
+
## [5.3.0] - 2020-07-30
|
|
71
|
+
### Changed
|
|
72
|
+
- Response object errors no longer include a `stack` property
|
|
73
|
+
|
|
74
|
+
## [5.2.0] - 2020-07-24
|
|
75
|
+
### Added
|
|
76
|
+
- Promise signatures for `engine.handle` ([#55](https://github.com/MetaMask/json-rpc-engine/pull/55))
|
|
77
|
+
- So, in addition to `engine.handle(request, callback)`, you can do e.g. `await engine.handle(request)`.
|
|
78
|
+
|
|
79
|
+
### Changed
|
|
80
|
+
- Remove `async` and `promise-to-callback` dependencies
|
|
81
|
+
- These dependencies were used internally for middleware flow control.
|
|
82
|
+
They have been replaced with Promises and native `async`/`await`, which means that some operations are _no longer_ eagerly executed.
|
|
83
|
+
This change may affect consumers that depend on the eager execution of middleware _during_ request processing, _outside of_ middleware functions and request handlers.
|
|
84
|
+
- In general, it is a bad practice to work with state that depends on middleware execution, while the middleware are executing.
|
|
85
|
+
|
|
86
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/json-rpc-engine@7.2.0...HEAD
|
|
87
|
+
[7.2.0]: https://github.com/MetaMask/core/compare/@metamask/json-rpc-engine@7.1.1...@metamask/json-rpc-engine@7.2.0
|
|
88
|
+
[7.1.1]: https://github.com/MetaMask/core/compare/@metamask/json-rpc-engine@7.1.0...@metamask/json-rpc-engine@7.1.1
|
|
89
|
+
[7.1.0]: https://github.com/MetaMask/core/compare/@metamask/json-rpc-engine@7.0.0...@metamask/json-rpc-engine@7.1.0
|
|
90
|
+
[7.0.0]: https://github.com/MetaMask/core/compare/json-rpc-engine@6.1.0...@metamask/json-rpc-engine@7.0.0
|
|
91
|
+
[6.1.0]: https://github.com/MetaMask/core/compare/json-rpc-engine@6.0.0...json-rpc-engine@6.1.0
|
|
92
|
+
[6.0.0]: https://github.com/MetaMask/core/compare/json-rpc-engine@5.4.0...json-rpc-engine@6.0.0
|
|
93
|
+
[5.4.0]: https://github.com/MetaMask/core/compare/json-rpc-engine@5.3.0...json-rpc-engine@5.4.0
|
|
94
|
+
[5.3.0]: https://github.com/MetaMask/core/compare/json-rpc-engine@5.2.0...json-rpc-engine@5.3.0
|
|
95
|
+
[5.2.0]: https://github.com/MetaMask/core/releases/tag/json-rpc-engine@5.2.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 MetaMask
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# `@metamask/json-rpc-engine`
|
|
2
|
+
|
|
3
|
+
A tool for processing JSON-RPC requests and responses.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
const { JsonRpcEngine } = require('@metamask/json-rpc-engine');
|
|
9
|
+
|
|
10
|
+
const engine = new JsonRpcEngine();
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Build a stack of JSON-RPC processors by pushing middleware to the engine.
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
engine.push(function (req, res, next, end) {
|
|
17
|
+
res.result = 42;
|
|
18
|
+
end();
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Requests are handled asynchronously, stepping down the stack until complete.
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
const request = { id: 1, jsonrpc: '2.0', method: 'hello' };
|
|
26
|
+
|
|
27
|
+
engine.handle(request, function (err, response) {
|
|
28
|
+
// Do something with response.result, or handle response.error
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// There is also a Promise signature
|
|
32
|
+
const response = await engine.handle(request);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Middleware have direct access to the request and response objects.
|
|
36
|
+
They can let processing continue down the stack with `next()`, or complete the request with `end()`.
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
engine.push(function (req, res, next, end) {
|
|
40
|
+
if (req.skipCache) return next();
|
|
41
|
+
res.result = getResultFromCache(req);
|
|
42
|
+
end();
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
By passing a _return handler_ to the `next` function, you can get a peek at the result before it returns.
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
engine.push(function (req, res, next, end) {
|
|
50
|
+
next(function (cb) {
|
|
51
|
+
insertIntoCache(res, cb);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
If you specify a `notificationHandler` when constructing the engine, JSON-RPC notifications passed to `handle()` will be handed off directly to this function without touching the middleware stack:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
const engine = new JsonRpcEngine({ notificationHandler });
|
|
60
|
+
|
|
61
|
+
// A notification is defined as a JSON-RPC request without an `id` property.
|
|
62
|
+
const notification = { jsonrpc: '2.0', method: 'hello' };
|
|
63
|
+
|
|
64
|
+
const response = await engine.handle(notification);
|
|
65
|
+
console.log(typeof response); // 'undefined'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Engines can be nested by converting them to middleware using `JsonRpcEngine.asMiddleware()`:
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
const engine = new JsonRpcEngine();
|
|
72
|
+
const subengine = new JsonRpcEngine();
|
|
73
|
+
engine.push(subengine.asMiddleware());
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### `async` Middleware
|
|
77
|
+
|
|
78
|
+
If you require your middleware function to be `async`, use `createAsyncMiddleware`:
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
const { createAsyncMiddleware } = require('@metamask/json-rpc-engine');
|
|
82
|
+
|
|
83
|
+
let engine = new RpcEngine();
|
|
84
|
+
engine.push(
|
|
85
|
+
createAsyncMiddleware(async (req, res, next) => {
|
|
86
|
+
res.result = 42;
|
|
87
|
+
next();
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`async` middleware do not take an `end` callback.
|
|
93
|
+
Instead, the request ends if the middleware returns without calling `next()`:
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
engine.push(
|
|
97
|
+
createAsyncMiddleware(async (req, res, next) => {
|
|
98
|
+
res.result = 42;
|
|
99
|
+
/* The request will end when this returns */
|
|
100
|
+
}),
|
|
101
|
+
);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The `next` callback of `async` middleware also don't take return handlers.
|
|
105
|
+
Instead, you can `await next()`.
|
|
106
|
+
When the execution of the middleware resumes, you can work with the response again.
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
engine.push(
|
|
110
|
+
createAsyncMiddleware(async (req, res, next) => {
|
|
111
|
+
res.result = 42;
|
|
112
|
+
await next();
|
|
113
|
+
/* Your return handler logic goes here */
|
|
114
|
+
addToMetrics(res);
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
You can freely mix callback-based and `async` middleware:
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
engine.push(function (req, res, next, end) {
|
|
123
|
+
if (!isCached(req)) {
|
|
124
|
+
return next((cb) => {
|
|
125
|
+
insertIntoCache(res, cb);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
res.result = getResultFromCache(req);
|
|
129
|
+
end();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
engine.push(
|
|
133
|
+
createAsyncMiddleware(async (req, res, next) => {
|
|
134
|
+
res.result = 42;
|
|
135
|
+
await next();
|
|
136
|
+
addToMetrics(res);
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Teardown
|
|
142
|
+
|
|
143
|
+
If your middleware has teardown to perform, you can assign a method `destroy()` to your middleware function(s),
|
|
144
|
+
and calling `JsonRpcEngine.destroy()` will call this method on each middleware that has it.
|
|
145
|
+
A destroyed engine can no longer be used.
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
const middleware = (req, res, next, end) => {
|
|
149
|
+
/* do something */
|
|
150
|
+
};
|
|
151
|
+
middleware.destroy = () => {
|
|
152
|
+
/* perform teardown */
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const engine = new JsonRpcEngine();
|
|
156
|
+
engine.push(middleware);
|
|
157
|
+
|
|
158
|
+
/* perform work */
|
|
159
|
+
|
|
160
|
+
// This will call middleware.destroy() and destroy the engine itself.
|
|
161
|
+
engine.destroy();
|
|
162
|
+
|
|
163
|
+
// Calling any public method on the middleware other than `destroy()` itself
|
|
164
|
+
// will throw an error.
|
|
165
|
+
engine.handle(req);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Gotchas
|
|
169
|
+
|
|
170
|
+
Handle errors via `end(err)`, _NOT_ `next(err)`.
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
/* INCORRECT */
|
|
174
|
+
engine.push(function (req, res, next, end) {
|
|
175
|
+
next(new Error());
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
/* CORRECT */
|
|
179
|
+
engine.push(function (req, res, next, end) {
|
|
180
|
+
end(new Error());
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
However, `next()` will detect errors on the response object, and cause
|
|
185
|
+
`end(res.error)` to be called.
|
|
186
|
+
|
|
187
|
+
```js
|
|
188
|
+
engine.push(function (req, res, next, end) {
|
|
189
|
+
res.error = new Error();
|
|
190
|
+
next(); /* This will cause end(res.error) to be called. */
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Running tests
|
|
195
|
+
|
|
196
|
+
Build the project if not already built:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
yarn build
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
yarn test
|
|
204
|
+
```
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import SafeEventEmitter from '@metamask/safe-event-emitter';
|
|
2
|
+
import type { JsonRpcError as SerializedJsonRpcError, JsonRpcRequest, JsonRpcResponse, JsonRpcNotification, Json, JsonRpcParams, PendingJsonRpcResponse } from '@metamask/utils';
|
|
3
|
+
export declare type JsonRpcEngineCallbackError = Error | SerializedJsonRpcError | null;
|
|
4
|
+
export declare type JsonRpcEngineReturnHandler = (done: (error?: JsonRpcEngineCallbackError) => void) => void;
|
|
5
|
+
export declare type JsonRpcEngineNextCallback = (returnHandlerCallback?: JsonRpcEngineReturnHandler) => void;
|
|
6
|
+
export declare type JsonRpcEngineEndCallback = (error?: JsonRpcEngineCallbackError) => void;
|
|
7
|
+
export declare type JsonRpcMiddleware<Params extends JsonRpcParams, Result extends Json> = {
|
|
8
|
+
(req: JsonRpcRequest<Params>, res: PendingJsonRpcResponse<Result>, next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback): void;
|
|
9
|
+
destroy?: () => void | Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
export declare type JsonRpcNotificationHandler<Params extends JsonRpcParams> = (notification: JsonRpcNotification<Params>) => void | Promise<void>;
|
|
12
|
+
declare type JsonRpcEngineArgs = {
|
|
13
|
+
/**
|
|
14
|
+
* A function for handling JSON-RPC notifications. A JSON-RPC notification is
|
|
15
|
+
* defined as a JSON-RPC request without an `id` property. If this option is
|
|
16
|
+
* _not_ provided, notifications will be treated the same as requests. If this
|
|
17
|
+
* option _is_ provided, notifications will be passed to the handler
|
|
18
|
+
* function without touching the engine's middleware stack.
|
|
19
|
+
*
|
|
20
|
+
* This function should not throw or reject.
|
|
21
|
+
*/
|
|
22
|
+
notificationHandler?: JsonRpcNotificationHandler<JsonRpcParams>;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* A JSON-RPC request and response processor.
|
|
26
|
+
* Give it a stack of middleware, pass it requests, and get back responses.
|
|
27
|
+
*/
|
|
28
|
+
export declare class JsonRpcEngine extends SafeEventEmitter {
|
|
29
|
+
#private;
|
|
30
|
+
/**
|
|
31
|
+
* Constructs a {@link JsonRpcEngine} instance.
|
|
32
|
+
*
|
|
33
|
+
* @param options - Options bag.
|
|
34
|
+
* @param options.notificationHandler - A function for handling JSON-RPC
|
|
35
|
+
* notifications. A JSON-RPC notification is defined as a JSON-RPC request
|
|
36
|
+
* without an `id` property. If this option is _not_ provided, notifications
|
|
37
|
+
* will be treated the same as requests. If this option _is_ provided,
|
|
38
|
+
* notifications will be passed to the handler function without touching
|
|
39
|
+
* the engine's middleware stack. This function should not throw or reject.
|
|
40
|
+
*/
|
|
41
|
+
constructor({ notificationHandler }?: JsonRpcEngineArgs);
|
|
42
|
+
/**
|
|
43
|
+
* Calls the `destroy()` function of any middleware with that property, clears
|
|
44
|
+
* the middleware array, and marks this engine as destroyed. A destroyed
|
|
45
|
+
* engine cannot be used.
|
|
46
|
+
*/
|
|
47
|
+
destroy(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Add a middleware function to the engine's middleware stack.
|
|
50
|
+
*
|
|
51
|
+
* @param middleware - The middleware function to add.
|
|
52
|
+
*/
|
|
53
|
+
push<Params extends JsonRpcParams, Result extends Json>(middleware: JsonRpcMiddleware<Params, Result>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Handle a JSON-RPC request, and return a response.
|
|
56
|
+
*
|
|
57
|
+
* @param request - The request to handle.
|
|
58
|
+
* @param callback - An error-first callback that will receive the response.
|
|
59
|
+
*/
|
|
60
|
+
handle<Params extends JsonRpcParams, Result extends Json>(request: JsonRpcRequest<Params>, callback: (error: unknown, response: JsonRpcResponse<Result>) => void): void;
|
|
61
|
+
/**
|
|
62
|
+
* Handle a JSON-RPC notification.
|
|
63
|
+
*
|
|
64
|
+
* @param notification - The notification to handle.
|
|
65
|
+
* @param callback - An error-first callback that will receive a `void` response.
|
|
66
|
+
*/
|
|
67
|
+
handle<Params extends JsonRpcParams>(notification: JsonRpcNotification<Params>, callback: (error: unknown, response: void) => void): void;
|
|
68
|
+
/**
|
|
69
|
+
* Handle an array of JSON-RPC requests and/or notifications, and return an
|
|
70
|
+
* array of responses to any included requests.
|
|
71
|
+
*
|
|
72
|
+
* @param request - The requests to handle.
|
|
73
|
+
* @param callback - An error-first callback that will receive the array of
|
|
74
|
+
* responses.
|
|
75
|
+
*/
|
|
76
|
+
handle<Params extends JsonRpcParams, Result extends Json>(requests: (JsonRpcRequest<Params> | JsonRpcNotification<Params>)[], callback: (error: unknown, responses: JsonRpcResponse<Result>[]) => void): void;
|
|
77
|
+
/**
|
|
78
|
+
* Handle a JSON-RPC request, and return a response.
|
|
79
|
+
*
|
|
80
|
+
* @param request - The JSON-RPC request to handle.
|
|
81
|
+
* @returns The JSON-RPC response.
|
|
82
|
+
*/
|
|
83
|
+
handle<Params extends JsonRpcParams, Result extends Json>(request: JsonRpcRequest<Params>): Promise<JsonRpcResponse<Result>>;
|
|
84
|
+
/**
|
|
85
|
+
* Handle a JSON-RPC notification.
|
|
86
|
+
*
|
|
87
|
+
* @param notification - The notification to handle.
|
|
88
|
+
*/
|
|
89
|
+
handle<Params extends JsonRpcParams>(notification: JsonRpcNotification<Params>): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Handle an array of JSON-RPC requests and/or notifications, and return an
|
|
92
|
+
* array of responses to any included requests.
|
|
93
|
+
*
|
|
94
|
+
* @param request - The JSON-RPC requests to handle.
|
|
95
|
+
* @returns An array of JSON-RPC responses.
|
|
96
|
+
*/
|
|
97
|
+
handle<Params extends JsonRpcParams, Result extends Json>(requests: (JsonRpcRequest<Params> | JsonRpcNotification<Params>)[]): Promise<JsonRpcResponse<Result>[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Returns this engine as a middleware function that can be pushed to other
|
|
100
|
+
* engines.
|
|
101
|
+
*
|
|
102
|
+
* @returns This engine as a middleware function.
|
|
103
|
+
*/
|
|
104
|
+
asMiddleware(): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
105
|
+
/**
|
|
106
|
+
* A promise-wrapped _handle.
|
|
107
|
+
*
|
|
108
|
+
* @param request - The JSON-RPC request.
|
|
109
|
+
* @returns The JSON-RPC response.
|
|
110
|
+
*/
|
|
111
|
+
private _promiseHandle;
|
|
112
|
+
}
|
|
113
|
+
export {};
|
|
114
|
+
//# sourceMappingURL=JsonRpcEngine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonRpcEngine.d.ts","sourceRoot":"","sources":["../src/JsonRpcEngine.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;A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