-
-
Notifications
You must be signed in to change notification settings - Fork 254
feat: Add context parameter to InternalProvider and JsonRpcServer methods
#7061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3feb558
feat: Permit specifying MiddlewareContext via object
rekmarks 4fb7a6d
feat: Permit specifying context to JsonRpcServer.handle()
rekmarks 6556f16
feat: Permit specifying context to InternalProvider.request()
rekmarks ccbc0d1
refactor: Update network client provider type
rekmarks dba9904
test: Fix bridge-controller tests
rekmarks f96650e
refactor: Add context generic to PollingBlockTracker
rekmarks 48318e2
chore: Lint
rekmarks c0ef5d0
docs: Update changelogs
rekmarks 1deebb8
fix: Include symbol-keyed properties when constructing MiddlewareCont…
rekmarks d30da03
refactor: Make JsonRpcServer.#coerceRequest static
rekmarks 2349423
fix: Resolve more MiddlewareContext bugs
rekmarks 3ef2de7
docs: Fix a docstring
rekmarks b206d87
fix: Walk the prototype chain for JsonRpcEngineError.isInstance
rekmarks 9a50958
refactor: Rationalize class symbol identifier names
rekmarks 1237cd6
docs: Update json-rpc-engine readme
rekmarks 5e87af2
chore: Lint
rekmarks c2632f3
refactor: Rationalize isInstance methods
rekmarks c853283
Merge branch 'main' into rekm/jrpce-internal-provider-context
rekmarks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -444,6 +444,33 @@ const engine = JsonRpcEngineV2.create({ | |
| }); | ||
| ``` | ||
|
|
||
| #### Passing the context to `handle()` | ||
|
|
||
| You can pass a `MiddlewareContext` instance directly to `handle()`: | ||
|
|
||
| ```ts | ||
| const context = new MiddlewareContext(); | ||
| context.set('foo', 'bar'); | ||
| const result = await engine.handle( | ||
| { id: '1', jsonrpc: '2.0', method: 'hello' }, | ||
| { context }, | ||
| ); | ||
| console.log(result); // 'bar' | ||
| ``` | ||
|
|
||
| You can also pass a plain object as a shorthand for a `MiddlewareContext` instance: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice feature :) |
||
|
|
||
| ```ts | ||
| const context = { foo: 'bar' }; | ||
| const result = await engine.handle( | ||
| { id: '1', jsonrpc: '2.0', method: 'hello' }, | ||
| { context }, | ||
| ); | ||
| console.log(result); // 'bar' | ||
| ``` | ||
|
|
||
| This works the same way for `JsonRpcServer.handle()`. | ||
|
|
||
| #### Constraining context keys and values | ||
|
|
||
| The context exposes a generic parameter `KeyValues`, which determines the keys and values | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Indentation?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what Prettier wants (there are no lint warnings or errors in the entire package).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boo. Fine then 😆