UNPKG

8.12 kBPlain TextView Raw
1/*
2 * Copyright 2019 gRPC authors.
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 */
17
18import {
19 ClientDuplexStream,
20 ClientReadableStream,
21 ClientUnaryCall,
22 ClientWritableStream,
23 ServiceError,
24} from './call';
25import { CallCredentials, OAuth2Client } from './call-credentials';
26import { StatusObject } from './call-interface';
27import { Channel, ChannelImplementation } from './channel';
28import { CompressionAlgorithms } from './compression-algorithms';
29import { ConnectivityState } from './connectivity-state';
30import { ChannelCredentials, VerifyOptions } from './channel-credentials';
31import {
32 CallOptions,
33 Client,
34 ClientOptions,
35 CallInvocationTransformer,
36 CallProperties,
37 UnaryCallback,
38} from './client';
39import { LogVerbosity, Status, Propagate } from './constants';
40import * as logging from './logging';
41import {
42 Deserialize,
43 loadPackageDefinition,
44 makeClientConstructor,
45 MethodDefinition,
46 Serialize,
47 ServiceDefinition,
48} from './make-client';
49import { Metadata, MetadataOptions, MetadataValue } from './metadata';
50import {
51 Server,
52 ServerOptions,
53 UntypedHandleCall,
54 UntypedServiceImplementation,
55} from './server';
56import { KeyCertPair, ServerCredentials } from './server-credentials';
57import { StatusBuilder } from './status-builder';
58import {
59 handleBidiStreamingCall,
60 handleServerStreamingCall,
61 handleClientStreamingCall,
62 handleUnaryCall,
63 sendUnaryData,
64 ServerUnaryCall,
65 ServerReadableStream,
66 ServerWritableStream,
67 ServerDuplexStream,
68 ServerErrorResponse,
69} from './server-call';
70
71export { OAuth2Client };
72
73/**** Client Credentials ****/
74
75// Using assign only copies enumerable properties, which is what we want
76export const credentials = {
77 /**
78 * Combine a ChannelCredentials with any number of CallCredentials into a
79 * single ChannelCredentials object.
80 * @param channelCredentials The ChannelCredentials object.
81 * @param callCredentials Any number of CallCredentials objects.
82 * @return The resulting ChannelCredentials object.
83 */
84 combineChannelCredentials: (
85 channelCredentials: ChannelCredentials,
86 ...callCredentials: CallCredentials[]
87 ): ChannelCredentials => {
88 return callCredentials.reduce(
89 (acc, other) => acc.compose(other),
90 channelCredentials
91 );
92 },
93
94 /**
95 * Combine any number of CallCredentials into a single CallCredentials
96 * object.
97 * @param first The first CallCredentials object.
98 * @param additional Any number of additional CallCredentials objects.
99 * @return The resulting CallCredentials object.
100 */
101 combineCallCredentials: (
102 first: CallCredentials,
103 ...additional: CallCredentials[]
104 ): CallCredentials => {
105 return additional.reduce((acc, other) => acc.compose(other), first);
106 },
107
108 // from channel-credentials.ts
109 createInsecure: ChannelCredentials.createInsecure,
110 createSsl: ChannelCredentials.createSsl,
111 createFromSecureContext: ChannelCredentials.createFromSecureContext,
112
113 // from call-credentials.ts
114 createFromMetadataGenerator: CallCredentials.createFromMetadataGenerator,
115 createFromGoogleCredential: CallCredentials.createFromGoogleCredential,
116 createEmpty: CallCredentials.createEmpty,
117};
118
119/**** Metadata ****/
120
121export { Metadata, MetadataOptions, MetadataValue };
122
123/**** Constants ****/
124
125export {
126 LogVerbosity as logVerbosity,
127 Status as status,
128 ConnectivityState as connectivityState,
129 Propagate as propagate,
130 CompressionAlgorithms as compressionAlgorithms,
131 // TODO: Other constants as well
132};
133
134/**** Client ****/
135
136export {
137 Client,
138 ClientOptions,
139 loadPackageDefinition,
140 makeClientConstructor,
141 makeClientConstructor as makeGenericClientConstructor,
142 CallProperties,
143 CallInvocationTransformer,
144 ChannelImplementation as Channel,
145 Channel as ChannelInterface,
146 UnaryCallback as requestCallback,
147};
148
149/**
150 * Close a Client object.
151 * @param client The client to close.
152 */
153export const closeClient = (client: Client) => client.close();
154
155export const waitForClientReady = (
156 client: Client,
157 deadline: Date | number,
158 callback: (error?: Error) => void
159) => client.waitForReady(deadline, callback);
160
161/* Interfaces */
162
163export {
164 sendUnaryData,
165 ChannelCredentials,
166 CallCredentials,
167 Deadline,
168 Serialize as serialize,
169 Deserialize as deserialize,
170 ClientUnaryCall,
171 ClientReadableStream,
172 ClientWritableStream,
173 ClientDuplexStream,
174 CallOptions,
175 MethodDefinition,
176 StatusObject,
177 ServiceError,
178 ServerUnaryCall,
179 ServerReadableStream,
180 ServerWritableStream,
181 ServerDuplexStream,
182 ServerErrorResponse,
183 ServiceDefinition,
184 UntypedHandleCall,
185 UntypedServiceImplementation,
186 VerifyOptions,
187};
188
189/**** Server ****/
190
191export {
192 handleBidiStreamingCall,
193 handleServerStreamingCall,
194 handleUnaryCall,
195 handleClientStreamingCall,
196};
197
198/* eslint-disable @typescript-eslint/no-explicit-any */
199export type Call =
200 | ClientUnaryCall
201 | ClientReadableStream<any>
202 | ClientWritableStream<any>
203 | ClientDuplexStream<any, any>;
204/* eslint-enable @typescript-eslint/no-explicit-any */
205
206/**** Unimplemented function stubs ****/
207
208/* eslint-disable @typescript-eslint/no-explicit-any */
209
210export const loadObject = (value: any, options: any): never => {
211 throw new Error(
212 'Not available in this library. Use @grpc/proto-loader and loadPackageDefinition instead'
213 );
214};
215
216export const load = (filename: any, format: any, options: any): never => {
217 throw new Error(
218 'Not available in this library. Use @grpc/proto-loader and loadPackageDefinition instead'
219 );
220};
221
222export const setLogger = (logger: Partial<Console>): void => {
223 logging.setLogger(logger);
224};
225
226export const setLogVerbosity = (verbosity: LogVerbosity): void => {
227 logging.setLoggerVerbosity(verbosity);
228};
229
230export { Server, ServerOptions };
231export { ServerCredentials };
232export { KeyCertPair };
233
234export const getClientChannel = (client: Client) => {
235 return Client.prototype.getChannel.call(client);
236};
237
238export { StatusBuilder };
239
240export { Listener, InterceptingListener } from './call-interface';
241
242export {
243 Requester,
244 ListenerBuilder,
245 RequesterBuilder,
246 Interceptor,
247 InterceptorOptions,
248 InterceptorProvider,
249 InterceptingCall,
250 InterceptorConfigurationError,
251 NextCall,
252} from './client-interceptors';
253
254export {
255 GrpcObject,
256 ServiceClientConstructor,
257 ProtobufTypeDefinition,
258} from './make-client';
259
260export { ChannelOptions } from './channel-options';
261
262export { getChannelzServiceDefinition, getChannelzHandlers } from './channelz';
263
264export { addAdminServicesToServer } from './admin';
265
266export {
267 ServiceConfig,
268 LoadBalancingConfig,
269 MethodConfig,
270 RetryPolicy,
271} from './service-config';
272
273export {
274 ServerListener,
275 FullServerListener,
276 ServerListenerBuilder,
277 Responder,
278 FullResponder,
279 ResponderBuilder,
280 ServerInterceptingCallInterface,
281 ServerInterceptingCall,
282 ServerInterceptor,
283} from './server-interceptors';
284
285import * as experimental from './experimental';
286export { experimental };
287
288import * as resolver_dns from './resolver-dns';
289import * as resolver_uds from './resolver-uds';
290import * as resolver_ip from './resolver-ip';
291import * as load_balancer_pick_first from './load-balancer-pick-first';
292import * as load_balancer_round_robin from './load-balancer-round-robin';
293import * as load_balancer_outlier_detection from './load-balancer-outlier-detection';
294import * as channelz from './channelz';
295import { Deadline } from './deadline';
296
297(() => {
298 resolver_dns.setup();
299 resolver_uds.setup();
300 resolver_ip.setup();
301 load_balancer_pick_first.setup();
302 load_balancer_round_robin.setup();
303 load_balancer_outlier_detection.setup();
304 channelz.setup();
305})();