-
-
Notifications
You must be signed in to change notification settings - Fork 267
feat(json-rpc-engine): Type-safe context inference #6902
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
feat(json-rpc-engine): Type-safe context inference #6902
Conversation
83ab221 to
a45a3c5
Compare
mcmire
left a comment
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.
Had one question about representing an invalid engine better, as well as some other comments. None of this is blocking though. I think this works really well.
|
|
||
| it('type errors and returns undefined when getting unknown keys', () => { | ||
| const context = new MiddlewareContext<{ test: string }>(); | ||
| // @ts-expect-error - foo is not a valid key |
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: Would it be worth adding tsd or tstyche tests at some point for some of these classes? This would allow us to write assertions at the type level.
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.
I think we're squeaking by with @ts-expect-error for now, although I'm not opposed to the idea if we think it becomes warranted.
471ff5e
into
rekm/json-rpc-engine-rewrite-next
Explanation
References
Checklist
Note
Introduce generic, type-safe MiddlewareContext and JsonRpcEngineV2.create() factory with improved type inference; update server, utils/exports, tests, and docs accordingly.
JsonRpcEngineV2.create()static factory; make constructor private and enforce non-empty middleware.Context,ResultConstraint; improved request/notification typing and composition.handle()/asMiddleware(); validate incompatible contexts at type level; new internal invalid-engine typing.MiddlewareContextgeneric with strict key/value typing; addassertGet/settypings,EmptyContext, andMergeContextsutil.Json,JsonRpcParams; addUnionToIntersectiontype.JsonRpcEngineErrorwith cross-versionisInstance().create()when passed middleware; clarify/adjust param validation and id handling.propagateToContextto accept typed context; minor param-handling tweaks.create()and new helper middlewares; add coverage for context typing, invalid compositions, and new behaviors.create(), typed middleware/context, composition patterns, and error semantics.Written by Cursor Bugbot for commit 75f61e7. This will update automatically on new commits. Configure here.