Skip to content
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

Rename RpcResponse to RpcResponseData #3145

Merged
merged 1 commit into from
Sep 1, 2024
Merged

Conversation

lorisleiva
Copy link
Contributor

@lorisleiva lorisleiva commented Aug 23, 2024

The purpose of this PR stack is to refactor both the RPC and RPC Subscriptions packages such that they have better interfaces with their respective transports. In this first batch of PRs, we will start by focusing on the RPC packages whilst ensuring minimum changes on the RPC Subscriptions packages.

The end goal of this first part is to have the following interfaces for the RPC packages:

RPC Shared Layer

type RpcRequest<TParams = unknown> = {
  readonly methodName: string;
  readonly params: TParams;
}

type RpcResponse<TResponse = unknown> = {
  readonly json: () => Promise<TResponse>;
  readonly text: () => Promise<string>;
}


type RpcRequestTransformer = {
    <TParams>(request: RpcRequest<unknown>): RpcRequest<TParams>;
};

type RpcResponseTransformer = {
    <TResponse>(response: RpcResponse<unknown>, request: RpcRequest<unknown>): RpcResponse<TResponse>;
};

type RpcResponseTransformerFor<TResponse> = {
    (response: RpcResponse<unknown>, request: RpcRequest<unknown>): RpcResponse<TResponse>;
};

RPC Transport Layer

type RpcTransportRequest = {
  readonly payload: unknown;
  readonly signal?: AbortSignal;
}


type RpcTransport = {
  <TResponse>(
    request: RpcTransportRequest
  ): Promise<RpcResponse<TResponse>>;
}

RPC API Layer

type RpcApi<TRpcMethods> = { ... }

type RpcApiConfig = {
  readonly requestTransformer?: RpcRequestTransformer;
  readonly responseTransformer?: RpcResponseTransformer;
}

type PendingRpcApiRequest<TResponse> = RpcRequest & {
    responseTransformer?: RpcResponseTransformerFor<TResponse>;
};

RPC Layer

type PendingRpcRequest<TResponse> = {
  // Nothing changes here but the final send function returns the result of `response.json()`.
  send(options?: RpcSendOptions): Promise<TResponse>;
};

In the first two PRs of the stack, we start by cleaning up the type namespace to allow these new types to exist. First, we rename RpcResponse to RpcResponseData, since RpcResponse will be used to define a proper response interface that aligns all the RPC layers.

Copy link

changeset-bot bot commented Aug 23, 2024

🦋 Changeset detected

Latest commit: f16d5af

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

Copy link
Collaborator

@steveluscher steveluscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added via Giphy

packages/rpc-spec-types/src/rpc-response.ts Outdated Show resolved Hide resolved
@lorisleiva lorisleiva force-pushed the loris/rename-rpc-response branch from cd9b1b2 to f16d5af Compare August 30, 2024 16:37
Copy link
Contributor Author

lorisleiva commented Sep 1, 2024

Merge activity

@lorisleiva lorisleiva merged commit 1c25dd4 into master Sep 1, 2024
9 checks passed
@lorisleiva lorisleiva deleted the loris/rename-rpc-response branch September 1, 2024 18:07
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants