-
Notifications
You must be signed in to change notification settings - Fork 910
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
Clean up SolanaRpcApi: no longer extend RpcApiMethods #3213
Conversation
🦋 Changeset detectedLatest commit: 728d517 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
b48b241
to
c483d1e
Compare
// @ts-expect-error - Mocking RPC methods | ||
target[p as keyof GraphQLCompliantRpc] = jest |
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.
@buffalojoec I'm not sure why this throws an error with this change, but it seems very test-specific so I'm not too worried about it. LMK if this is pointing at a problem I've overlooked though!
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.
Much better 👌
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @mcintyre94 and the rest of your teammates on Graphite |
740d46b
to
1f94447
Compare
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.
Looks great! I dug up the original reason why I added this.
The change to the API methods went in here, and it was really only to tee up this change which added the createJsonRpcApi
generic helper.
It seems like somewhere along the way the helper was updated and it will no longer throw a type error, cool! Seems like it might be the change from this:
const params = config?.parametersTransformer
? config?.parametersTransformer(rawParams, methodName)
: rawParams;
const responseTransformer = config?.responseTransformer
? config?.responseTransformer<ReturnType<TRpcMethods[TMethodName]>>
: (rawResponse: unknown) => rawResponse as ReturnType<TRpcMethods[TMethodName]>;
return {
methodName,
params,
responseTransformer,
};
... to this:
const rawRequest = { methodName, params: rawParams };
const request = config?.requestTransformer
? config?.requestTransformer(Object.freeze(rawRequest))
: rawRequest;
return Object.freeze({
...request,
...(config?.responseTransformer
? {
responseTransformer: config.responseTransformer as RpcResponseTransformer<
ReturnType<TRpcMethods[TMethodName]>
>,
}
: {}),
});
Note: This is mirrored in rpc-subscriptions-api
, so that API should also get the same treatment.
1f94447
to
728d517
Compare
Thanks! Added a new PR to the stack: #3218 |
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.
Yep, still seems ~instant for me! |
Merge activity
|
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |
Extending
RpcApiMethods
removes the ability to access typed keys onSolanaRpcApi
etc, because it's typed as[method: string]: RpcApiMethod
.In this PR we change from:
To:
(Thanks @lorisleiva!)
This allows
createRpcApi
to maintain its typing, meaning that it still constrains any API methods we attempt to build an RPC for. But we now have typesafekeyof SolanaRpcApi
etc.I've also removed the export of
RpcApiMethods
, since this should now be used only as a constraint internally and not a type externally.I've added a typetest with a bit more detail, but this basically makes this work:
Previously
someMadeUpMethod
would satisfy it, becausekeyof SolanaRpcApi
was just string.