UNPKG

6.54 kBTypeScriptView Raw
1/**
2 * Copyright 2020 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16/// <reference types="node" />
17import * as protobuf from 'protobufjs';
18import * as gax from './gax';
19import * as routingHeader from './routingHeader';
20import { OutgoingHttpHeaders } from 'http';
21import { GoogleAuth, OAuth2Client, Compute, JWT, UserRefreshClient, BaseExternalAccountClient } from 'google-auth-library';
22import { OperationsClientBuilder } from './operationsClient';
23import { GrpcClientOptions, ClientStubOptions } from './grpc';
24import { GaxCall, GRPCCall } from './apitypes';
25import { Descriptor } from './descriptor';
26import { FallbackServiceError } from './googleError';
27export { FallbackServiceError };
28export { PathTemplate } from './pathTemplate';
29export { routingHeader };
30export { CallSettings, constructSettings, RetryOptions } from './gax';
31export declare const version: string;
32export { BundleDescriptor, LongrunningDescriptor, PageDescriptor, StreamDescriptor, } from './descriptor';
33export { StreamType } from './streamingCalls/streaming';
34export declare const defaultToObjectOptions: {
35 keepCase: boolean;
36 longs: StringConstructor;
37 enums: StringConstructor;
38 defaults: boolean;
39 oneofs: boolean;
40};
41export interface ServiceMethods {
42 [name: string]: protobuf.Method;
43}
44export declare type AuthClient = OAuth2Client | Compute | JWT | UserRefreshClient | BaseExternalAccountClient;
45export declare class GrpcClient {
46 auth?: OAuth2Client | GoogleAuth;
47 authClient?: AuthClient;
48 fallback: boolean | 'rest' | 'proto';
49 grpcVersion: string;
50 private static protoCache;
51 /**
52 * In rare cases users might need to deallocate all memory consumed by loaded protos.
53 * This method will delete the proto cache content.
54 */
55 static clearProtoCache(): void;
56 /**
57 * gRPC-fallback version of GrpcClient
58 * Implements GrpcClient API for a browser using grpc-fallback protocol (sends serialized protobuf to HTTP/1 $rpc endpoint).
59 *
60 * @param {Object=} options.auth - An instance of OAuth2Client to use in browser, or an instance of GoogleAuth from google-auth-library
61 * to use in Node.js. Required for browser, optional for Node.js.
62 * @constructor
63 */
64 constructor(options?: (GrpcClientOptions | {
65 auth: OAuth2Client;
66 }) & {
67 fallback?: boolean | 'rest' | 'proto';
68 });
69 /**
70 * gRPC-fallback version of loadProto
71 * Loads the protobuf root object from a JSON object created from a proto file
72 * @param {Object} jsonObject - A JSON version of a protofile created usin protobuf.js
73 * @returns {Object} Root namespace of proto JSON
74 */
75 loadProto(jsonObject: {}): protobuf.Root;
76 loadProtoJSON(json: protobuf.INamespace, ignoreCache?: boolean): protobuf.Root;
77 private static getServiceMethods;
78 /**
79 * gRPC-fallback version of constructSettings
80 * A wrapper of {@link constructSettings} function under the gRPC context.
81 *
82 * Most of parameters are common among constructSettings, please take a look.
83 * @param {string} serviceName - The fullly-qualified name of the service.
84 * @param {Object} clientConfig - A dictionary of the client config.
85 * @param {Object} configOverrides - A dictionary of overriding configs.
86 * @param {Object} headers - A dictionary of additional HTTP header name to
87 * its value.
88 * @return {Object} A mapping of method names to CallSettings.
89 */
90 constructSettings(serviceName: string, clientConfig: gax.ClientConfig, configOverrides: gax.ClientConfig, headers: OutgoingHttpHeaders): any;
91 /**
92 * gRPC-fallback version of createStub
93 * Creates a gRPC-fallback stub with authentication headers built from supplied OAuth2Client instance
94 *
95 * @param {function} CreateStub - The constructor function of the stub.
96 * @param {Object} service - A protobufjs Service object (as returned by lookupService)
97 * @param {Object} opts - Connection options, as described below.
98 * @param {string} opts.servicePath - The hostname of the API endpoint service.
99 * @param {number} opts.port - The port of the service.
100 * @return {Promise} A promise which resolves to a gRPC-fallback service stub, which is a protobuf.js service stub instance modified to match the gRPC stub API
101 */
102 createStub(service: protobuf.Service, opts: ClientStubOptions, customServicePath?: boolean): Promise<import("./fallbackServiceStub").FallbackServiceStub>;
103}
104/**
105 * gRPC-fallback version of lro
106 *
107 * @param {Object=} options.auth - An instance of google-auth-library.
108 * @return {Object} A OperationsClientBuilder that will return a OperationsClient
109 */
110export declare function lro(options: GrpcClientOptions): OperationsClientBuilder;
111/**
112 * gRPC-fallback version of createApiCall
113 *
114 * Converts an rpc call into an API call governed by the settings.
115 *
116 * In typical usage, `func` will be a promise to a callable used to make an rpc
117 * request. This will mostly likely be a bound method from a request stub used
118 * to make an rpc call. It is not a direct function but a Promise instance,
119 * because of its asynchronism (typically, obtaining the auth information).
120 *
121 * The result is a function which manages the API call with the given settings
122 * and the options on the invocation.
123 *
124 * Throws exception on unsupported streaming calls
125 *
126 * @param {Promise<GRPCCall>|GRPCCall} func - is either a promise to be used to make
127 * a bare RPC call, or just a bare RPC call.
128 * @param {CallSettings} settings - provides the settings for this call
129 * @param {Descriptor} descriptor - optionally specify the descriptor for
130 * the method call.
131 * @return {GaxCall} func - a bound method on a request stub used
132 * to make an rpc call.
133 */
134export declare function createApiCall(func: Promise<GRPCCall> | GRPCCall, settings: gax.CallSettings, descriptor?: Descriptor): GaxCall;
135export { protobuf };
136export * as protobufMinimal from 'protobufjs/minimal';
137declare const fallback: any;
138export { fallback };