better-grpc 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.cjs +43 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -43
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
[](./LICENSE)
|
|
13
13
|
[](https://discord.gg/bZd4CMd2H5)
|
|
14
14
|
|
|
15
|
-
**`better-grpc`** is a library that
|
|
15
|
+
**`better-grpc`** is a TypeScript-first gRPC library that focuses on developer experience and type safety. It eliminates the need for `.proto` files and code generation, allowing you to define your services entirely in TypeScript.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
It enables seamless, **bidirectional** communication between a client and a server, allowing developers to call server-side functions from the client and client-side functions from the server, as if they were local.
|
|
18
18
|
|
|
19
19
|
## Features
|
|
20
20
|
|
package/dist/index.cjs
CHANGED
|
@@ -3925,10 +3925,10 @@ var require_client_interceptors = __commonJS({
|
|
|
3925
3925
|
const host = options.host;
|
|
3926
3926
|
const parent = (_b = options.parent) !== null && _b !== void 0 ? _b : null;
|
|
3927
3927
|
const propagateFlags = options.propagate_flags;
|
|
3928
|
-
const
|
|
3928
|
+
const credentials = options.credentials;
|
|
3929
3929
|
const call = channel.createCall(path, deadline, host, parent, propagateFlags);
|
|
3930
|
-
if (
|
|
3931
|
-
call.setCredentials(
|
|
3930
|
+
if (credentials) {
|
|
3931
|
+
call.setCredentials(credentials);
|
|
3932
3932
|
}
|
|
3933
3933
|
return call;
|
|
3934
3934
|
}
|
|
@@ -4087,7 +4087,7 @@ var require_client = __commonJS({
|
|
|
4087
4087
|
return ((_a = error.stack) === null || _a === void 0 ? void 0 : _a.split("\n").slice(1).join("\n")) || "no stack trace available";
|
|
4088
4088
|
}
|
|
4089
4089
|
var Client = class {
|
|
4090
|
-
constructor(address,
|
|
4090
|
+
constructor(address, credentials, options = {}) {
|
|
4091
4091
|
var _a, _b;
|
|
4092
4092
|
options = Object.assign({}, options);
|
|
4093
4093
|
this[INTERCEPTOR_SYMBOL] = (_a = options.interceptors) !== null && _a !== void 0 ? _a : [];
|
|
@@ -4104,9 +4104,9 @@ var require_client = __commonJS({
|
|
|
4104
4104
|
} else if (options.channelFactoryOverride) {
|
|
4105
4105
|
const channelFactoryOverride = options.channelFactoryOverride;
|
|
4106
4106
|
delete options.channelFactoryOverride;
|
|
4107
|
-
this[CHANNEL_SYMBOL] = channelFactoryOverride(address,
|
|
4107
|
+
this[CHANNEL_SYMBOL] = channelFactoryOverride(address, credentials, options);
|
|
4108
4108
|
} else {
|
|
4109
|
-
this[CHANNEL_SYMBOL] = new channel_1.ChannelImplementation(address,
|
|
4109
|
+
this[CHANNEL_SYMBOL] = new channel_1.ChannelImplementation(address, credentials, options);
|
|
4110
4110
|
}
|
|
4111
4111
|
}
|
|
4112
4112
|
close() {
|
|
@@ -15026,7 +15026,7 @@ var require_single_subchannel_channel = __commonJS({
|
|
|
15026
15026
|
getCallNumber() {
|
|
15027
15027
|
return this.callNumber;
|
|
15028
15028
|
}
|
|
15029
|
-
setCredentials(
|
|
15029
|
+
setCredentials(credentials) {
|
|
15030
15030
|
throw new Error("Method not implemented.");
|
|
15031
15031
|
}
|
|
15032
15032
|
getAuthContext() {
|
|
@@ -15116,7 +15116,7 @@ var require_subchannel = __commonJS({
|
|
|
15116
15116
|
* @param credentials The channel credentials used to establish this
|
|
15117
15117
|
* connection
|
|
15118
15118
|
*/
|
|
15119
|
-
constructor(channelTarget, subchannelAddress, options,
|
|
15119
|
+
constructor(channelTarget, subchannelAddress, options, credentials, connector) {
|
|
15120
15120
|
var _a;
|
|
15121
15121
|
this.channelTarget = channelTarget;
|
|
15122
15122
|
this.subchannelAddress = subchannelAddress;
|
|
@@ -15155,7 +15155,7 @@ var require_subchannel = __commonJS({
|
|
|
15155
15155
|
this.channelzRef = (0, channelz_1.registerChannelzSubchannel)(this.subchannelAddressString, () => this.getChannelzInfo(), this.channelzEnabled);
|
|
15156
15156
|
this.channelzTrace.addTrace("CT_INFO", "Subchannel created");
|
|
15157
15157
|
this.trace("Subchannel constructed with options " + JSON.stringify(options, void 0, 2));
|
|
15158
|
-
this.secureConnector =
|
|
15158
|
+
this.secureConnector = credentials._createSecureConnector(channelTarget, options);
|
|
15159
15159
|
}
|
|
15160
15160
|
getChannelzInfo() {
|
|
15161
15161
|
return {
|
|
@@ -17054,13 +17054,13 @@ var require_load_balancing_call = __commonJS({
|
|
|
17054
17054
|
var http2 = __require("http2");
|
|
17055
17055
|
var TRACER_NAME = "load_balancing_call";
|
|
17056
17056
|
var LoadBalancingCall = class {
|
|
17057
|
-
constructor(channel, callConfig, methodName, host,
|
|
17057
|
+
constructor(channel, callConfig, methodName, host, credentials, deadline, callNumber) {
|
|
17058
17058
|
var _a, _b;
|
|
17059
17059
|
this.channel = channel;
|
|
17060
17060
|
this.callConfig = callConfig;
|
|
17061
17061
|
this.methodName = methodName;
|
|
17062
17062
|
this.host = host;
|
|
17063
|
-
this.credentials =
|
|
17063
|
+
this.credentials = credentials;
|
|
17064
17064
|
this.deadline = deadline;
|
|
17065
17065
|
this.callNumber = callNumber;
|
|
17066
17066
|
this.child = null;
|
|
@@ -17262,7 +17262,7 @@ var require_load_balancing_call = __commonJS({
|
|
|
17262
17262
|
this.pendingHalfClose = true;
|
|
17263
17263
|
}
|
|
17264
17264
|
}
|
|
17265
|
-
setCredentials(
|
|
17265
|
+
setCredentials(credentials) {
|
|
17266
17266
|
throw new Error("Method not implemented.");
|
|
17267
17267
|
}
|
|
17268
17268
|
getCallNumber() {
|
|
@@ -17543,8 +17543,8 @@ var require_resolving_call = __commonJS({
|
|
|
17543
17543
|
this.pendingHalfClose = true;
|
|
17544
17544
|
}
|
|
17545
17545
|
}
|
|
17546
|
-
setCredentials(
|
|
17547
|
-
this.credentials =
|
|
17546
|
+
setCredentials(credentials) {
|
|
17547
|
+
this.credentials = credentials;
|
|
17548
17548
|
}
|
|
17549
17549
|
addStatusWatcher(watcher) {
|
|
17550
17550
|
this.statusWatchers.push(watcher);
|
|
@@ -17638,13 +17638,13 @@ var require_retrying_call = __commonJS({
|
|
|
17638
17638
|
var PREVIONS_RPC_ATTEMPTS_METADATA_KEY = "grpc-previous-rpc-attempts";
|
|
17639
17639
|
var DEFAULT_MAX_ATTEMPTS_LIMIT = 5;
|
|
17640
17640
|
var RetryingCall = class {
|
|
17641
|
-
constructor(channel, callConfig, methodName, host,
|
|
17641
|
+
constructor(channel, callConfig, methodName, host, credentials, deadline, callNumber, bufferTracker, retryThrottler) {
|
|
17642
17642
|
var _a;
|
|
17643
17643
|
this.channel = channel;
|
|
17644
17644
|
this.callConfig = callConfig;
|
|
17645
17645
|
this.methodName = methodName;
|
|
17646
17646
|
this.host = host;
|
|
17647
|
-
this.credentials =
|
|
17647
|
+
this.credentials = credentials;
|
|
17648
17648
|
this.deadline = deadline;
|
|
17649
17649
|
this.callNumber = callNumber;
|
|
17650
17650
|
this.bufferTracker = bufferTracker;
|
|
@@ -18369,9 +18369,9 @@ var require_internal_channel = __commonJS({
|
|
|
18369
18369
|
}
|
|
18370
18370
|
};
|
|
18371
18371
|
var InternalChannel = class {
|
|
18372
|
-
constructor(target,
|
|
18372
|
+
constructor(target, credentials, options) {
|
|
18373
18373
|
var _a, _b, _c, _d, _e, _f;
|
|
18374
|
-
this.credentials =
|
|
18374
|
+
this.credentials = credentials;
|
|
18375
18375
|
this.options = options;
|
|
18376
18376
|
this.connectivityState = connectivity_state_1.ConnectivityState.IDLE;
|
|
18377
18377
|
this.currentPicker = new picker_1.UnavailablePicker();
|
|
@@ -18389,7 +18389,7 @@ var require_internal_channel = __commonJS({
|
|
|
18389
18389
|
if (typeof target !== "string") {
|
|
18390
18390
|
throw new TypeError("Channel target must be a string");
|
|
18391
18391
|
}
|
|
18392
|
-
if (!(
|
|
18392
|
+
if (!(credentials instanceof channel_credentials_1.ChannelCredentials)) {
|
|
18393
18393
|
throw new TypeError("Channel credentials must be a ChannelCredentials object");
|
|
18394
18394
|
}
|
|
18395
18395
|
if (options) {
|
|
@@ -18671,15 +18671,15 @@ var require_internal_channel = __commonJS({
|
|
|
18671
18671
|
this.lastActivityTimestamp = /* @__PURE__ */ new Date();
|
|
18672
18672
|
this.maybeStartIdleTimer();
|
|
18673
18673
|
}
|
|
18674
|
-
createLoadBalancingCall(callConfig, method, host,
|
|
18674
|
+
createLoadBalancingCall(callConfig, method, host, credentials, deadline) {
|
|
18675
18675
|
const callNumber = (0, call_number_1.getNextCallNumber)();
|
|
18676
18676
|
this.trace("createLoadBalancingCall [" + callNumber + '] method="' + method + '"');
|
|
18677
|
-
return new load_balancing_call_1.LoadBalancingCall(this, callConfig, method, host,
|
|
18677
|
+
return new load_balancing_call_1.LoadBalancingCall(this, callConfig, method, host, credentials, deadline, callNumber);
|
|
18678
18678
|
}
|
|
18679
|
-
createRetryingCall(callConfig, method, host,
|
|
18679
|
+
createRetryingCall(callConfig, method, host, credentials, deadline) {
|
|
18680
18680
|
const callNumber = (0, call_number_1.getNextCallNumber)();
|
|
18681
18681
|
this.trace("createRetryingCall [" + callNumber + '] method="' + method + '"');
|
|
18682
|
-
return new retrying_call_1.RetryingCall(this, callConfig, method, host,
|
|
18682
|
+
return new retrying_call_1.RetryingCall(this, callConfig, method, host, credentials, deadline, callNumber, this.retryBufferTracker, RETRY_THROTTLER_MAP.get(this.getTarget()));
|
|
18683
18683
|
}
|
|
18684
18684
|
createResolvingCall(method, deadline, host, parentCall, propagateFlags) {
|
|
18685
18685
|
const callNumber = (0, call_number_1.getNextCallNumber)();
|
|
@@ -18795,11 +18795,11 @@ var require_channel = __commonJS({
|
|
|
18795
18795
|
var channel_credentials_1 = require_channel_credentials();
|
|
18796
18796
|
var internal_channel_1 = require_internal_channel();
|
|
18797
18797
|
var ChannelImplementation = class {
|
|
18798
|
-
constructor(target,
|
|
18798
|
+
constructor(target, credentials, options) {
|
|
18799
18799
|
if (typeof target !== "string") {
|
|
18800
18800
|
throw new TypeError("Channel target must be a string");
|
|
18801
18801
|
}
|
|
18802
|
-
if (!(
|
|
18802
|
+
if (!(credentials instanceof channel_credentials_1.ChannelCredentials)) {
|
|
18803
18803
|
throw new TypeError("Channel credentials must be a ChannelCredentials object");
|
|
18804
18804
|
}
|
|
18805
18805
|
if (options) {
|
|
@@ -18807,7 +18807,7 @@ var require_channel = __commonJS({
|
|
|
18807
18807
|
throw new TypeError("Channel options must be an object");
|
|
18808
18808
|
}
|
|
18809
18809
|
}
|
|
18810
|
-
this.internalChannel = new internal_channel_1.InternalChannel(target,
|
|
18810
|
+
this.internalChannel = new internal_channel_1.InternalChannel(target, credentials, options);
|
|
18811
18811
|
}
|
|
18812
18812
|
close() {
|
|
18813
18813
|
this.internalChannel.close();
|
|
@@ -19334,8 +19334,8 @@ var require_server_credentials = __commonJS({
|
|
|
19334
19334
|
return this.childCredentials._getSecureContextOptions();
|
|
19335
19335
|
}
|
|
19336
19336
|
};
|
|
19337
|
-
function createServerCredentialsWithInterceptors(
|
|
19338
|
-
return new InterceptorServerCredentials(
|
|
19337
|
+
function createServerCredentialsWithInterceptors(credentials, interceptors) {
|
|
19338
|
+
return new InterceptorServerCredentials(credentials, interceptors);
|
|
19339
19339
|
}
|
|
19340
19340
|
}
|
|
19341
19341
|
});
|
|
@@ -20731,11 +20731,11 @@ var require_server = __commonJS({
|
|
|
20731
20731
|
experimentalUnregisterListenerFromChannelz(channelzRef) {
|
|
20732
20732
|
(0, channelz_1.unregisterChannelzRef)(channelzRef);
|
|
20733
20733
|
}
|
|
20734
|
-
createHttp2Server(
|
|
20734
|
+
createHttp2Server(credentials) {
|
|
20735
20735
|
let http2Server;
|
|
20736
|
-
if (
|
|
20737
|
-
const constructorOptions =
|
|
20738
|
-
const contextOptions =
|
|
20736
|
+
if (credentials._isSecure()) {
|
|
20737
|
+
const constructorOptions = credentials._getConstructorOptions();
|
|
20738
|
+
const contextOptions = credentials._getSecureContextOptions();
|
|
20739
20739
|
const secureServerOptions = Object.assign(Object.assign(Object.assign(Object.assign({}, this.commonServerOptions), constructorOptions), contextOptions), { enableTrace: this.options["grpc-node.tls_enable_trace"] === 1 });
|
|
20740
20740
|
let areCredentialsValid = contextOptions !== null;
|
|
20741
20741
|
this.trace("Initial credentials valid: " + areCredentialsValid);
|
|
@@ -20764,15 +20764,15 @@ var require_server = __commonJS({
|
|
|
20764
20764
|
areCredentialsValid = options !== null;
|
|
20765
20765
|
this.trace("Post-update credentials valid: " + areCredentialsValid);
|
|
20766
20766
|
};
|
|
20767
|
-
|
|
20767
|
+
credentials._addWatcher(credsWatcher);
|
|
20768
20768
|
http2Server.on("close", () => {
|
|
20769
|
-
|
|
20769
|
+
credentials._removeWatcher(credsWatcher);
|
|
20770
20770
|
});
|
|
20771
20771
|
} else {
|
|
20772
20772
|
http2Server = http2.createServer(this.commonServerOptions);
|
|
20773
20773
|
}
|
|
20774
20774
|
http2Server.setTimeout(0, noop);
|
|
20775
|
-
this._setupHandlers(http2Server,
|
|
20775
|
+
this._setupHandlers(http2Server, credentials._getInterceptors());
|
|
20776
20776
|
return http2Server;
|
|
20777
20777
|
}
|
|
20778
20778
|
bindOneAddress(address, boundPortObject) {
|
|
@@ -21007,14 +21007,14 @@ var require_server = __commonJS({
|
|
|
21007
21007
|
* @param channelzRef
|
|
21008
21008
|
* @returns
|
|
21009
21009
|
*/
|
|
21010
|
-
experimentalCreateConnectionInjectorWithChannelzRef(
|
|
21011
|
-
if (
|
|
21010
|
+
experimentalCreateConnectionInjectorWithChannelzRef(credentials, channelzRef, ownsChannelzRef = false) {
|
|
21011
|
+
if (credentials === null || !(credentials instanceof server_credentials_1.ServerCredentials)) {
|
|
21012
21012
|
throw new TypeError("creds must be a ServerCredentials object");
|
|
21013
21013
|
}
|
|
21014
21014
|
if (this.channelzEnabled) {
|
|
21015
21015
|
this.listenerChildrenTracker.refChild(channelzRef);
|
|
21016
21016
|
}
|
|
21017
|
-
const server2 = this.createHttp2Server(
|
|
21017
|
+
const server2 = this.createHttp2Server(credentials);
|
|
21018
21018
|
const sessionsSet = /* @__PURE__ */ new Set();
|
|
21019
21019
|
this.http2Servers.set(server2, {
|
|
21020
21020
|
channelzRef,
|
|
@@ -21044,12 +21044,12 @@ var require_server = __commonJS({
|
|
|
21044
21044
|
}
|
|
21045
21045
|
};
|
|
21046
21046
|
}
|
|
21047
|
-
createConnectionInjector(
|
|
21048
|
-
if (
|
|
21047
|
+
createConnectionInjector(credentials) {
|
|
21048
|
+
if (credentials === null || !(credentials instanceof server_credentials_1.ServerCredentials)) {
|
|
21049
21049
|
throw new TypeError("creds must be a ServerCredentials object");
|
|
21050
21050
|
}
|
|
21051
21051
|
const channelzRef = this.registerInjectorToChannelz();
|
|
21052
|
-
return this.experimentalCreateConnectionInjectorWithChannelzRef(
|
|
21052
|
+
return this.experimentalCreateConnectionInjectorWithChannelzRef(credentials, channelzRef, true);
|
|
21053
21053
|
}
|
|
21054
21054
|
closeServer(server2, callback) {
|
|
21055
21055
|
this.trace("Closing server with address " + JSON.stringify(server2.address()));
|
|
@@ -24227,8 +24227,8 @@ var GrpcClient = class {
|
|
|
24227
24227
|
this.serviceImpls = serviceImpls;
|
|
24228
24228
|
this.proto = loadProtoFromString(buildProtoString(serviceImpls));
|
|
24229
24229
|
const useSSL = !address.includes("localhost") && !address.includes("127.0.0.1") && !address.includes("0.0.0.0");
|
|
24230
|
-
const
|
|
24231
|
-
this.channel = niceGrpc.createChannel(address,
|
|
24230
|
+
const credentials = useSSL ? niceGrpc.ChannelCredentials.createSsl() : niceGrpc.ChannelCredentials.createInsecure();
|
|
24231
|
+
this.channel = niceGrpc.createChannel(address, credentials, {
|
|
24232
24232
|
"grpc.max_receive_message_length": 10 * 1024 * 1024,
|
|
24233
24233
|
"grpc.max_send_message_length": 10 * 1024 * 1024,
|
|
24234
24234
|
"grpc.keepalive_time_ms": 3e4,
|