UNPKG

7.92 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 } 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 ProtobufTypeDefinition,
47 Serialize,
48 ServiceClientConstructor,
49 ServiceDefinition,
50} from './make-client';
51import { Metadata, MetadataOptions, MetadataValue } from './metadata';
52import {
53 Server,
54 UntypedHandleCall,
55 UntypedServiceImplementation,
56} from './server';
57import { KeyCertPair, ServerCredentials } from './server-credentials';
58import { StatusBuilder } from './status-builder';
59import {
60 handleBidiStreamingCall,
61 handleServerStreamingCall,
62 handleClientStreamingCall,
63 handleUnaryCall,
64 sendUnaryData,
65 ServerUnaryCall,
66 ServerReadableStream,
67 ServerWritableStream,
68 ServerDuplexStream,
69 ServerErrorResponse,
70} from './server-call';
71
72export { OAuth2Client };
73
74/**** Client Credentials ****/
75
76// Using assign only copies enumerable properties, which is what we want
77export const credentials = {
78 /**
79 * Combine a ChannelCredentials with any number of CallCredentials into a
80 * single ChannelCredentials object.
81 * @param channelCredentials The ChannelCredentials object.
82 * @param callCredentials Any number of CallCredentials objects.
83 * @return The resulting ChannelCredentials object.
84 */
85 combineChannelCredentials: (
86 channelCredentials: ChannelCredentials,
87 ...callCredentials: CallCredentials[]
88 ): ChannelCredentials => {
89 return callCredentials.reduce(
90 (acc, other) => acc.compose(other),
91 channelCredentials
92 );
93 },
94
95 /**
96 * Combine any number of CallCredentials into a single CallCredentials
97 * object.
98 * @param first The first CallCredentials object.
99 * @param additional Any number of additional CallCredentials objects.
100 * @return The resulting CallCredentials object.
101 */
102 combineCallCredentials: (
103 first: CallCredentials,
104 ...additional: CallCredentials[]
105 ): CallCredentials => {
106 return additional.reduce((acc, other) => acc.compose(other), first);
107 },
108
109 // from channel-credentials.ts
110 createInsecure: ChannelCredentials.createInsecure,
111 createSsl: ChannelCredentials.createSsl,
112 createFromSecureContext: ChannelCredentials.createFromSecureContext,
113
114 // from call-credentials.ts
115 createFromMetadataGenerator: CallCredentials.createFromMetadataGenerator,
116 createFromGoogleCredential: CallCredentials.createFromGoogleCredential,
117 createEmpty: CallCredentials.createEmpty,
118};
119
120/**** Metadata ****/
121
122export { Metadata, MetadataOptions, MetadataValue };
123
124/**** Constants ****/
125
126export {
127 LogVerbosity as logVerbosity,
128 Status as status,
129 ConnectivityState as connectivityState,
130 Propagate as propagate,
131 CompressionAlgorithms as compressionAlgorithms
132 // TODO: Other constants as well
133};
134
135/**** Client ****/
136
137export {
138 Client,
139 ClientOptions,
140 loadPackageDefinition,
141 makeClientConstructor,
142 makeClientConstructor as makeGenericClientConstructor,
143 CallProperties,
144 CallInvocationTransformer,
145 ChannelImplementation as Channel,
146 Channel as ChannelInterface,
147 UnaryCallback as requestCallback,
148};
149
150/**
151 * Close a Client object.
152 * @param client The client to close.
153 */
154export const closeClient = (client: Client) => client.close();
155
156export const waitForClientReady = (
157 client: Client,
158 deadline: Date | number,
159 callback: (error?: Error) => void
160) => client.waitForReady(deadline, callback);
161
162/* Interfaces */
163
164export {
165 sendUnaryData,
166 ChannelCredentials,
167 CallCredentials,
168 Deadline,
169 Serialize as serialize,
170 Deserialize as deserialize,
171 ClientUnaryCall,
172 ClientReadableStream,
173 ClientWritableStream,
174 ClientDuplexStream,
175 CallOptions,
176 MethodDefinition,
177 StatusObject,
178 ServiceError,
179 ServerUnaryCall,
180 ServerReadableStream,
181 ServerWritableStream,
182 ServerDuplexStream,
183 ServerErrorResponse,
184 ServiceDefinition,
185 UntypedHandleCall,
186 UntypedServiceImplementation,
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 };
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 {
263 getChannelzServiceDefinition,
264 getChannelzHandlers
265} from './channelz';
266
267export { addAdminServicesToServer } from './admin';
268
269import * as experimental from './experimental';
270export { experimental };
271
272import * as resolver_dns from './resolver-dns';
273import * as resolver_uds from './resolver-uds';
274import * as resolver_ip from './resolver-ip';
275import * as load_balancer_pick_first from './load-balancer-pick-first';
276import * as load_balancer_round_robin from './load-balancer-round-robin';
277import * as load_balancer_outlier_detection from './load-balancer-outlier-detection';
278import * as channelz from './channelz';
279import { Deadline } from './deadline';
280
281const clientVersion = require('../../package.json').version;
282
283(() => {
284 logging.trace(LogVerbosity.DEBUG, 'index', 'Loading @grpc/grpc-js version ' + clientVersion);
285 resolver_dns.setup();
286 resolver_uds.setup();
287 resolver_ip.setup();
288 load_balancer_pick_first.setup();
289 load_balancer_round_robin.setup();
290 load_balancer_outlier_detection.setup();
291 channelz.setup();
292})();