import { IConfigurationOptions, IMidwayApplication, IMidwayContext, NextFunction as BaseNextFunction, } from '@midwayjs/core'; import { Server, ServerCredentials, Metadata, ClientWritableStream, ClientDuplexStream, ClientReadableStream, ClientUnaryCall, ChannelOptions, ClientOptions, ServerUnaryCall, ServerReadableStream, ServerWritableStream, ServerDuplexStream, } from '@grpc/grpc-js'; type GrpcHandleCall = Partial< ServerUnaryCall & ServerReadableStream & ServerWritableStream & ServerDuplexStream >; export interface Context< RequestType = unknown, ResponseType = unknown, > extends IMidwayContext> { method: string; } export type IMidwayGRPCApplication = IMidwayApplication; export type Application = IMidwayGRPCApplication; export type NextFunction = BaseNextFunction; export interface IGRPCServiceOptions { /** * proto path */ protoPath?: string; /** * protobuf package name */ package?: string; } export interface IGRPCClientServiceOptions extends IGRPCServiceOptions { /** * application gRPC connection string */ url: string; /** * proto file loader options. Optional */ loaderOptions?: object; /** * Server credentials. Optional. */ credentials?: ServerCredentials; /** * Client options. Optional. */ clientOptions?: ClientOptions; /** * Service name. Optional. */ service?: string; } export interface IMidwayGRPFrameworkOptions extends IConfigurationOptions { /** * gRPC Server connection url, like 'localhost:6565' */ url?: string; services?: IGRPCServiceOptions[]; /** * proto file loader options. Optional */ loaderOptions?: object; /** * Server credentials. Optional. */ credentials?: ServerCredentials; /** * grpc server options */ serverOptions?: ChannelOptions; } export interface DefaultConfig extends IConfigurationOptions { services: IGRPCClientServiceOptions[]; } export interface IClientUnaryService { sendMessage( reqData: reqType, handler?: (call: ClientUnaryCall) => void ): Promise; sendMessageWithCallback(content: reqType, callback): ClientUnaryCall; } export interface IClientReadableStreamService { sendMessage(reqData: reqType): Promise; getCall(): ClientReadableStream; } export interface IClientWritableStreamService { sendMessage(reqData: reqType): IClientWritableStreamService; end(): Promise; getCall(): ClientWritableStream; } export interface IClientDuplexStreamService { sendMessage(reqData: reqType): Promise; getCall(): ClientDuplexStream; end(): void; } export interface IClientOptions { metadata?: Metadata; timeout?: number; timeoutMessage?: number; messageKey?: string; }