Skip to content

Commit

Permalink
[web] add flow types for grpc-web unary interceptor
Browse files Browse the repository at this point in the history
Summary:
added the relevant types using this file as reference: https://github.com/grpc/grpc-web/blob/master/packages/grpc-web/index.d.ts

Depends on D9670

Test Plan: ran `flow`

Reviewers: ashoat

Reviewed By: ashoat

Subscribers: tomek, wyilio

Differential Revision: https://phab.comm.dev/D9671
  • Loading branch information
vdhanan committed Nov 8, 2023
1 parent 62a3781 commit d62b1f9
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion web/flow-typed/npm/grpc-web_v1.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

declare module 'grpc-web' {

declare export type Metadata = { +[s: string]: string };
declare export type Metadata = { [s: string]: string };

declare export type StatusCode =
| 0 // OK
Expand All @@ -30,6 +30,43 @@ declare module 'grpc-web' {
+metadata?: Metadata,
};

declare export class UnaryInterceptor<REQ, RESP> {
intercept(
request: Request<REQ, RESP>,
invoker: (request: Request<REQ, RESP>) => Promise<UnaryResponse<REQ, RESP>>
): Promise<UnaryResponse<REQ, RESP>>;
}

declare export class Request<REQ, RESP> {
getRequestMessage(): REQ;
getMethodDescriptor(): MethodDescriptor<REQ, RESP>;
getMetadata(): Metadata;
getCallOptions(): CallOptions;
}

declare export class UnaryResponse<REQ, RESP> {
getResponseMessage(): RESP;
getMetadata(): Metadata;
getMethodDescriptor(): MethodDescriptor<REQ, RESP>;
getStatus(): Status;
}

declare export class CallOptions {
constructor(options: { [index: string]: mixed; }): void;
}

declare export class MethodDescriptor<REQ, RESP> {
constructor(
name: string,
methodType: string,
requestType: (...args: mixed[]) => REQ,
responseType: (...args: mixed[]) => RESP,
requestSerializeFn: any,
responseDeserializeFn: any,
): void;
getName(): string;
}

declare export class RpcError extends Error {
constructor(code: StatusCode, message: string, metadata: Metadata): void;
code: StatusCode;
Expand Down

0 comments on commit d62b1f9

Please sign in to comment.