Skip to content

Commit

Permalink
feat(rpc-adapter): adds rpc request and response types
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Oct 25, 2019
1 parent ea24ddf commit e0fdf38
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/rpc-adapter/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './rpc';
54 changes: 54 additions & 0 deletions packages/rpc-adapter/src/types/rpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Request
export type RPCRequest<D = any> = RPCUnaryRequest<D> | RPCStreamRequest<D>;

export interface RPCUnaryRequest<D = any> {
id: string;
route: string;
action: 'query' | 'mutate';
data: D;
}

export type RPCStreamRequest<D = any> =
| RPCSubscribeRequest<D>
| RPCUnsubscribeRequest;

export interface RPCSubscribeRequest<D = any> {
id: string;
route: string;
action: 'subscribe';
data: D;
}

export interface RPCUnsubscribeRequest {
id: string;
action: 'unsubscribe';
}

// Response
export type RPCResponse<D = any> =
| RPCSuccessResponse<D>
| RPCErrorResponse
| RPCStreamFinalResponse;

export interface RPCSuccessResponse<D = any> {
id: string;
status: 'success';
data: D;
}

export interface RPCErrorResponse {
id: string;
status: 'error';
data: RPCError;
}

export interface RPCStreamFinalResponse {
id: string;
status: 'complete' | 'unsubscribe';
}

export interface RPCError {
id: string;
code: string;
message?: string;
}

0 comments on commit e0fdf38

Please sign in to comment.