1 /// <reference types="node" />
2 import * as grpcProtoLoaderTypes from '@grpc/proto-loader';
3 import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';
4 import * as grpcTypes from 'grpc';
5 import { OutgoingHttpHeaders } from 'http';
6 import * as protobuf from 'protobufjs';
7 import * as gax from './gax';
8 export { GrpcObject } from 'grpc';
9 export interface GrpcClientOptions extends GoogleAuthOptions {
11 promise?: PromiseConstructor;
14 export interface MetadataValue {
17 export interface Metadata {
19 set: (key: {}, value?: {} | null) => void;
20 clone: () => Metadata;
24 export declare type GrpcModule = typeof grpcTypes & {
26 [index: string]: number;
30 export interface ClientStubOptions {
33 sslCreds?: grpcTypes.ChannelCredentials;
35 export declare class ClientStub extends grpcTypes.Client {
36 [name: string]: Function;
38 export declare class GrpcClient {
40 promise: PromiseConstructor;
43 grpcProtoLoader: typeof grpcProtoLoaderTypes;
45 * A class which keeps the context of gRPC and auth for the gRPC.
47 * @param {Object=} options - The optional parameters. It will be directly
48 * passed to google-auth-library library, so parameters like keyFile or
49 * credentials will be valid.
50 * @param {Object=} options.auth - An instance of google-auth-library.
51 * When specified, this auth instance will be used instead of creating
53 * @param {Object=} options.grpc - When specified, this will be used
54 * for the 'grpc' module in this context. By default, it will load the grpc
55 * module in the standard way.
56 * @param {Function=} options.promise - A constructor for a promise that
57 * implements the ES6 specification of promise. If not provided, native
58 * promises will be used.
61 constructor(options?: GrpcClientOptions);
63 * Creates a gRPC credentials. It asks the auth data if necessary.
65 * @param {Object} opts - options values for configuring credentials.
66 * @param {Object=} opts.sslCreds - when specified, this is used instead
67 * of default channel credentials.
68 * @return {Promise} The promise which will be resolved to the gRPC credential.
70 _getCredentials(opts: ClientStubOptions): Promise<grpcTypes.ChannelCredentials>;
72 * Loads the gRPC service from the proto file at the given path and with the
74 * @param filename The path to the proto file.
75 * @param options Options for loading the proto file.
77 loadFromProto(filename: string, options: grpcProtoLoaderTypes.Options): grpcTypes.GrpcObject;
79 * Load grpc proto service from a filename hooking in googleapis common protos
80 * when necessary. Uses legacy grpc.loadObject.
81 * @param {String} protoPath - The directory to search for the protofile.
82 * @param {String} filename - The filename of the proto to be loaded.
83 * @return {Object<string, *>} The gRPC loaded result (the toplevel namespace
86 protected loadProtoLegacy(protoPath: string, filename: string): grpcTypes.GrpcObject;
88 * Load grpc proto service from a filename hooking in googleapis common protos
89 * when necessary. Uses the new shiny @grpc/proto-loader.
90 * @param {String} protoPath - The directory to search for the protofile.
91 * @param {String} filename - The filename of the proto to be loaded.
92 * @return {Object<string, *>} The gRPC loaded result (the toplevel namespace
95 protected loadProtoGrpcJs(protoPath: string, filename: string): grpcTypes.GrpcObject;
97 * Load grpc proto service from a filename hooking in googleapis common protos
98 * when necessary. Can use either legacy grpc.loadProto, or new
99 * @grpc/proto-loader, depending on which gRPC backend is used.
100 * @param {String} protoPath - The directory to search for the protofile.
101 * @param {String} filename - The filename of the proto to be loaded.
102 * @return {Object<string, *>} The gRPC loaded result (the toplevel namespace
105 loadProto(protoPath: string, filename: string): grpcTypes.GrpcObject;
106 static _resolveFile(protoPath: string, filename: string): string;
107 metadataBuilder(headers: OutgoingHttpHeaders): (abTests?: {} | undefined, moreHeaders?: OutgoingHttpHeaders | undefined) => grpcTypes.Metadata;
109 * A wrapper of {@link constructSettings} function under the gRPC context.
111 * Most of parameters are common among constructSettings, please take a look.
112 * @param {string} serviceName - The fullly-qualified name of the service.
113 * @param {Object} clientConfig - A dictionary of the client config.
114 * @param {Object} configOverrides - A dictionary of overriding configs.
115 * @param {Object} headers - A dictionary of additional HTTP header name to
117 * @return {Object} A mapping of method names to CallSettings.
119 constructSettings(serviceName: string, clientConfig: gax.ClientConfig, configOverrides: gax.ClientConfig, headers: OutgoingHttpHeaders): any;
121 * Creates a gRPC stub with current gRPC and auth.
122 * @param {function} CreateStub - The constructor function of the stub.
123 * @param {Object} options - The optional arguments to customize
124 * gRPC connection. This options will be passed to the constructor of
126 * @param {string} options.servicePath - The name of the server of the service.
127 * @param {number} options.port - The port of the service.
128 * @param {grpcTypes.ClientCredentials=} options.sslCreds - The credentials to be used
129 * to set up gRPC connection.
130 * @return {Promise} A promse which resolves to a gRPC stub instance.
132 createStub(CreateStub: typeof ClientStub, options: ClientStubOptions): Promise<ClientStub>;
134 * Creates a 'bytelength' function for a given proto message class.
136 * See {@link BundleDescriptor} about the meaning of the return value.
138 * @param {function} message - a constructor function that is generated by
139 * protobuf.js. Assumes 'encoder' field in the message.
140 * @return {function(Object):number} - a function to compute the byte length
143 static createByteLengthFunction(message: {
144 encode: (obj: {}) => {
145 finish: () => Array<{}>;
147 }): (obj: {}) => number;
149 export declare class GoogleProtoFilesRoot extends protobuf.Root {
150 constructor(...args: Array<{}>);
151 resolvePath(originPath: string, includePath: string): string;
152 static _findIncludePath(originPath: string, includePath: string): string;