UNPKG

2.98 kBTypeScriptView Raw
1/// <reference types="node" />
2import { ChannelCredentials } from './channel-credentials';
3import { ChannelOptions } from './channel-options';
4import { Client } from './client';
5import { UntypedServiceImplementation } from './server';
6export interface Serialize<T> {
7 (value: T): Buffer;
8}
9export interface Deserialize<T> {
10 (bytes: Buffer): T;
11}
12export interface ClientMethodDefinition<RequestType, ResponseType> {
13 path: string;
14 requestStream: boolean;
15 responseStream: boolean;
16 requestSerialize: Serialize<RequestType>;
17 responseDeserialize: Deserialize<ResponseType>;
18 originalName?: string;
19}
20export interface ServerMethodDefinition<RequestType, ResponseType> {
21 path: string;
22 requestStream: boolean;
23 responseStream: boolean;
24 responseSerialize: Serialize<ResponseType>;
25 requestDeserialize: Deserialize<RequestType>;
26 originalName?: string;
27}
28export interface MethodDefinition<RequestType, ResponseType> extends ClientMethodDefinition<RequestType, ResponseType>, ServerMethodDefinition<RequestType, ResponseType> {
29}
30export declare type ServiceDefinition<ImplementationType = UntypedServiceImplementation> = {
31 readonly [index in keyof ImplementationType]: MethodDefinition<any, any>;
32};
33export interface ProtobufTypeDefinition {
34 format: string;
35 type: object;
36 fileDescriptorProtos: Buffer[];
37}
38export interface PackageDefinition {
39 [index: string]: ServiceDefinition | ProtobufTypeDefinition;
40}
41export interface ServiceClient extends Client {
42 [methodName: string]: Function;
43}
44export interface ServiceClientConstructor {
45 new (address: string, credentials: ChannelCredentials, options?: Partial<ChannelOptions>): ServiceClient;
46 service: ServiceDefinition;
47}
48/**
49 * Creates a constructor for a client with the given methods, as specified in
50 * the methods argument. The resulting class will have an instance method for
51 * each method in the service, which is a partial application of one of the
52 * [Client]{@link grpc.Client} request methods, depending on `requestSerialize`
53 * and `responseSerialize`, with the `method`, `serialize`, and `deserialize`
54 * arguments predefined.
55 * @param methods An object mapping method names to
56 * method attributes
57 * @param serviceName The fully qualified name of the service
58 * @param classOptions An options object.
59 * @return New client constructor, which is a subclass of
60 * {@link grpc.Client}, and has the same arguments as that constructor.
61 */
62export declare function makeClientConstructor(methods: ServiceDefinition, serviceName: string, classOptions?: {}): ServiceClientConstructor;
63export interface GrpcObject {
64 [index: string]: GrpcObject | ServiceClientConstructor | ProtobufTypeDefinition;
65}
66/**
67 * Load a gRPC package definition as a gRPC object hierarchy.
68 * @param packageDef The package definition object.
69 * @return The resulting gRPC object.
70 */
71export declare function loadPackageDefinition(packageDef: PackageDefinition): GrpcObject;