UNPKG

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