UNPKG

7.85 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 { Deadline, StatusObject } from './call-stream';
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 } from './call-stream';
241
242export {
243 Requester,
244 ListenerBuilder,
245 RequesterBuilder,
246 Interceptor,
247 InterceptorOptions,
248 InterceptorProvider,
249 InterceptingCall,
250 InterceptorConfigurationError,
251} from './client-interceptors';
252
253export {
254 GrpcObject,
255 ServiceClientConstructor,
256 ProtobufTypeDefinition
257} from './make-client';
258
259export { ChannelOptions } from './channel-options';
260
261export {
262 getChannelzServiceDefinition,
263 getChannelzHandlers
264} from './channelz';
265
266export { addAdminServicesToServer } from './admin';
267
268import * as experimental from './experimental';
269export { experimental };
270
271import * as resolver_dns from './resolver-dns';
272import * as resolver_uds from './resolver-uds';
273import * as resolver_ip from './resolver-ip';
274import * as load_balancer_pick_first from './load-balancer-pick-first';
275import * as load_balancer_round_robin from './load-balancer-round-robin';
276import * as load_balancer_outlier_detection from './load-balancer-outlier-detection';
277import * as channelz from './channelz';
278
279const clientVersion = require('../../package.json').version;
280
281(() => {
282 logging.trace(LogVerbosity.DEBUG, 'index', 'Loading @grpc/grpc-js version ' + clientVersion);
283 resolver_dns.setup();
284 resolver_uds.setup();
285 resolver_ip.setup();
286 load_balancer_pick_first.setup();
287 load_balancer_round_robin.setup();
288 load_balancer_outlier_detection.setup();
289 channelz.setup();
290})();