UNPKG

3.52 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 emit: Function;
14}
15export declare class ServerGrpc extends Server implements CustomTransportStrategy {
16 private readonly options;
17 readonly transportId = Transport.GRPC;
18 private readonly url;
19 private grpcClient;
20 constructor(options: GrpcOptions['options']);
21 listen(callback: () => void): Promise<void>;
22 start(callback?: () => void): Promise<void>;
23 bindEvents(): Promise<void>;
24 /**
25 * Will return all of the services along with their fully namespaced
26 * names as an array of objects.
27 * This method initiates recursive scan of grpcPkg object
28 */
29 getServiceNames(grpcPkg: any): {
30 name: string;
31 service: any;
32 }[];
33 /**
34 * Will create service mapping from gRPC generated Object to handlers
35 * defined with @GrpcMethod or @GrpcStreamMethod annotations
36 *
37 * @param grpcService
38 * @param name
39 */
40 createService(grpcService: any, name: string): Promise<{}>;
41 /**
42 * Will create a string of a JSON serialized format
43 *
44 * @param service name of the service which should be a match to gRPC service definition name
45 * @param methodName name of the method which is coming after rpc keyword
46 * @param streaming GrpcMethodStreamingType parameter which should correspond to
47 * stream keyword in gRPC service request part
48 */
49 createPattern(service: string, methodName: string, streaming: GrpcMethodStreamingType): string;
50 /**
51 * Will return async function which will handle gRPC call
52 * with Rx streams or as a direct call passthrough
53 *
54 * @param methodHandler
55 * @param protoNativeHandler
56 */
57 createServiceMethod(methodHandler: Function, protoNativeHandler: any, streamType: GrpcMethodStreamingType): Function;
58 createUnaryServiceMethod(methodHandler: Function): Function;
59 createStreamServiceMethod(methodHandler: Function): Function;
60 createRequestStreamMethod(methodHandler: Function, isResponseStream: boolean): (call: GrpcCall, callback: (err: unknown, value: unknown) => void) => Promise<void>;
61 createStreamCallMethod(methodHandler: Function, isResponseStream: boolean): (call: GrpcCall, callback: (err: unknown, value: unknown) => void) => Promise<void>;
62 close(): void;
63 deserialize(obj: any): any;
64 addHandler(pattern: any, callback: MessageHandler, isEventHandler?: boolean): void;
65 createClient(): any;
66 lookupPackage(root: any, packageName: string): any;
67 loadProto(): any;
68 /**
69 * Recursively fetch all of the service methods available on loaded
70 * protobuf descriptor object, and collect those as an objects with
71 * dot-syntax full-path names.
72 *
73 * Example:
74 * for proto package Bundle.FirstService with service Events { rpc...
75 * will be resolved to object of (while loaded for Bundle package):
76 * {
77 * name: "FirstService.Events",
78 * service: {Object}
79 * }
80 */
81 private collectDeepServices;
82 private parseDeepServiceName;
83 private createServices;
84}
85export {};