UNPKG

4.31 kBTypeScriptView Raw
1import { GrpcMethodStreamingType } from '../decorators';
2import { Transport } from '../enums';
3import { CustomTransportStrategy, MessageHandler } from '../interfaces';
4import { GrpcOptions } from '../interfaces/microservice-configuration.interface';
5import { Server } from './server';
6interface GrpcCall<TRequest = any, TMetadata = any> {
7 request: TRequest;
8 metadata: TMetadata;
9 sendMetadata: Function;
10 end: Function;
11 write: Function;
12 on: Function;
13 off: Function;
14 emit: Function;
15}
16/**
17 * @publicApi
18 */
19export declare class ServerGrpc extends Server implements CustomTransportStrategy {
20 private readonly options;
21 readonly transportId = Transport.GRPC;
22 private readonly url;
23 private grpcClient;
24 constructor(options: GrpcOptions['options']);
25 listen(callback: (err?: unknown, ...optionalParams: unknown[]) => void): Promise<void>;
26 start(callback?: () => void): Promise<void>;
27 bindEvents(): Promise<void>;
28 /**
29 * Will return all of the services along with their fully namespaced
30 * names as an array of objects.
31 * This method initiates recursive scan of grpcPkg object
32 */
33 getServiceNames(grpcPkg: any): {
34 name: string;
35 service: any;
36 }[];
37 /**
38 * Will create service mapping from gRPC generated Object to handlers
39 * defined with @GrpcMethod or @GrpcStreamMethod annotations
40 *
41 * @param grpcService
42 * @param name
43 */
44 createService(grpcService: any, name: string): Promise<{}>;
45 getMessageHandler(serviceName: string, methodName: string, streaming: GrpcMethodStreamingType, grpcMethod: {
46 path?: string;
47 }): MessageHandler<any, any, any>;
48 /**
49 * Will create a string of a JSON serialized format
50 *
51 * @param service name of the service which should be a match to gRPC service definition name
52 * @param methodName name of the method which is coming after rpc keyword
53 * @param streaming GrpcMethodStreamingType parameter which should correspond to
54 * stream keyword in gRPC service request part
55 */
56 createPattern(service: string, methodName: string, streaming: GrpcMethodStreamingType): string;
57 /**
58 * Will return async function which will handle gRPC call
59 * with Rx streams or as a direct call passthrough
60 *
61 * @param methodHandler
62 * @param protoNativeHandler
63 * @param streamType
64 */
65 createServiceMethod(methodHandler: Function, protoNativeHandler: any, streamType: GrpcMethodStreamingType): Function;
66 createUnaryServiceMethod(methodHandler: Function): Function;
67 createStreamServiceMethod(methodHandler: Function): Function;
68 /**
69 * Writes an observable to a GRPC call.
70 *
71 * This function will ensure that backpressure is managed while writing values
72 * that come from an observable to a GRPC call.
73 *
74 * @param source The observable we want to write out to the GRPC call.
75 * @param call The GRPC call we want to write to.
76 * @returns A promise that resolves when we're done writing to the call.
77 */
78 private writeObservableToGrpc;
79 createRequestStreamMethod(methodHandler: Function, isResponseStream: boolean): (call: GrpcCall, callback: (err: unknown, value: unknown) => void) => Promise<void>;
80 createStreamCallMethod(methodHandler: Function, isResponseStream: boolean): (call: GrpcCall, callback: (err: unknown, value: unknown) => void) => Promise<void>;
81 close(): Promise<void>;
82 deserialize(obj: any): any;
83 addHandler(pattern: unknown, callback: MessageHandler, isEventHandler?: boolean): void;
84 createClient(): Promise<any>;
85 lookupPackage(root: any, packageName: string): any;
86 loadProto(): any;
87 /**
88 * Recursively fetch all of the service methods available on loaded
89 * protobuf descriptor object, and collect those as an objects with
90 * dot-syntax full-path names.
91 *
92 * Example:
93 * for proto package Bundle.FirstService with service Events { rpc...
94 * will be resolved to object of (while loaded for Bundle package):
95 * {
96 * name: "FirstService.Events",
97 * service: {Object}
98 * }
99 */
100 private collectDeepServices;
101 private parseDeepServiceName;
102 private createServices;
103 private bufferUntilDrained;
104}
105export {};