better-grpc 0.1.0 → 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 +87 -6
- package/dist/index.cjs +356 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -12
- package/dist/index.d.ts +41 -12
- package/dist/index.js +357 -96
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -350,7 +350,7 @@ var require_metadata = __commonJS({
|
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
|
-
var
|
|
353
|
+
var Metadata2 = class _Metadata {
|
|
354
354
|
constructor(options = {}) {
|
|
355
355
|
this.internalRepr = /* @__PURE__ */ new Map();
|
|
356
356
|
this.opaqueData = /* @__PURE__ */ new Map();
|
|
@@ -542,7 +542,7 @@ var require_metadata = __commonJS({
|
|
|
542
542
|
return result;
|
|
543
543
|
}
|
|
544
544
|
};
|
|
545
|
-
exports2.Metadata =
|
|
545
|
+
exports2.Metadata = Metadata2;
|
|
546
546
|
var bufToString = (val) => {
|
|
547
547
|
return Buffer.isBuffer(val) ? val.toString("base64") : val;
|
|
548
548
|
};
|
|
@@ -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() {
|
|
@@ -7717,7 +7717,7 @@ var require_root = __commonJS({
|
|
|
7717
7717
|
var util = require_util();
|
|
7718
7718
|
var Type;
|
|
7719
7719
|
var parse2;
|
|
7720
|
-
var
|
|
7720
|
+
var common;
|
|
7721
7721
|
function Root2(options) {
|
|
7722
7722
|
Namespace.call(this, "", options);
|
|
7723
7723
|
this.deferred = [];
|
|
@@ -7764,7 +7764,7 @@ var require_root = __commonJS({
|
|
|
7764
7764
|
var idx = filename2.lastIndexOf("google/protobuf/");
|
|
7765
7765
|
if (idx > -1) {
|
|
7766
7766
|
var altname = filename2.substring(idx);
|
|
7767
|
-
if (altname in
|
|
7767
|
+
if (altname in common) return altname;
|
|
7768
7768
|
}
|
|
7769
7769
|
return null;
|
|
7770
7770
|
}
|
|
@@ -7801,14 +7801,14 @@ var require_root = __commonJS({
|
|
|
7801
7801
|
return;
|
|
7802
7802
|
}
|
|
7803
7803
|
self2.files.push(filename2);
|
|
7804
|
-
if (filename2 in
|
|
7804
|
+
if (filename2 in common) {
|
|
7805
7805
|
if (sync) {
|
|
7806
|
-
process2(filename2,
|
|
7806
|
+
process2(filename2, common[filename2]);
|
|
7807
7807
|
} else {
|
|
7808
7808
|
++queued;
|
|
7809
7809
|
setTimeout(function() {
|
|
7810
7810
|
--queued;
|
|
7811
|
-
process2(filename2,
|
|
7811
|
+
process2(filename2, common[filename2]);
|
|
7812
7812
|
});
|
|
7813
7813
|
}
|
|
7814
7814
|
return;
|
|
@@ -7948,7 +7948,7 @@ var require_root = __commonJS({
|
|
|
7948
7948
|
Root2._configure = function(Type_, parse_, common_) {
|
|
7949
7949
|
Type = Type_;
|
|
7950
7950
|
parse2 = parse_;
|
|
7951
|
-
|
|
7951
|
+
common = common_;
|
|
7952
7952
|
};
|
|
7953
7953
|
}
|
|
7954
7954
|
});
|
|
@@ -9912,16 +9912,16 @@ var require_parse = __commonJS({
|
|
|
9912
9912
|
// node_modules/protobufjs/src/common.js
|
|
9913
9913
|
var require_common = __commonJS({
|
|
9914
9914
|
"node_modules/protobufjs/src/common.js"(exports2, module2) {
|
|
9915
|
-
module2.exports =
|
|
9915
|
+
module2.exports = common;
|
|
9916
9916
|
var commonRe = /\/|\./;
|
|
9917
|
-
function
|
|
9917
|
+
function common(name, json) {
|
|
9918
9918
|
if (!commonRe.test(name)) {
|
|
9919
9919
|
name = "google/protobuf/" + name + ".proto";
|
|
9920
9920
|
json = { nested: { google: { nested: { protobuf: { nested: json } } } } };
|
|
9921
9921
|
}
|
|
9922
|
-
|
|
9922
|
+
common[name] = json;
|
|
9923
9923
|
}
|
|
9924
|
-
|
|
9924
|
+
common("any", {
|
|
9925
9925
|
/**
|
|
9926
9926
|
* Properties of a google.protobuf.Any message.
|
|
9927
9927
|
* @interface IAny
|
|
@@ -9944,7 +9944,7 @@ var require_common = __commonJS({
|
|
|
9944
9944
|
}
|
|
9945
9945
|
});
|
|
9946
9946
|
var timeType;
|
|
9947
|
-
|
|
9947
|
+
common("duration", {
|
|
9948
9948
|
/**
|
|
9949
9949
|
* Properties of a google.protobuf.Duration message.
|
|
9950
9950
|
* @interface IDuration
|
|
@@ -9966,7 +9966,7 @@ var require_common = __commonJS({
|
|
|
9966
9966
|
}
|
|
9967
9967
|
}
|
|
9968
9968
|
});
|
|
9969
|
-
|
|
9969
|
+
common("timestamp", {
|
|
9970
9970
|
/**
|
|
9971
9971
|
* Properties of a google.protobuf.Timestamp message.
|
|
9972
9972
|
* @interface ITimestamp
|
|
@@ -9977,7 +9977,7 @@ var require_common = __commonJS({
|
|
|
9977
9977
|
*/
|
|
9978
9978
|
Timestamp: timeType
|
|
9979
9979
|
});
|
|
9980
|
-
|
|
9980
|
+
common("empty", {
|
|
9981
9981
|
/**
|
|
9982
9982
|
* Properties of a google.protobuf.Empty message.
|
|
9983
9983
|
* @interface IEmpty
|
|
@@ -9987,7 +9987,7 @@ var require_common = __commonJS({
|
|
|
9987
9987
|
fields: {}
|
|
9988
9988
|
}
|
|
9989
9989
|
});
|
|
9990
|
-
|
|
9990
|
+
common("struct", {
|
|
9991
9991
|
/**
|
|
9992
9992
|
* Properties of a google.protobuf.Struct message.
|
|
9993
9993
|
* @interface IStruct
|
|
@@ -10079,7 +10079,7 @@ var require_common = __commonJS({
|
|
|
10079
10079
|
}
|
|
10080
10080
|
}
|
|
10081
10081
|
});
|
|
10082
|
-
|
|
10082
|
+
common("wrappers", {
|
|
10083
10083
|
/**
|
|
10084
10084
|
* Properties of a google.protobuf.DoubleValue message.
|
|
10085
10085
|
* @interface IDoubleValue
|
|
@@ -10216,7 +10216,7 @@ var require_common = __commonJS({
|
|
|
10216
10216
|
}
|
|
10217
10217
|
}
|
|
10218
10218
|
});
|
|
10219
|
-
|
|
10219
|
+
common("field_mask", {
|
|
10220
10220
|
/**
|
|
10221
10221
|
* Properties of a google.protobuf.FieldMask message.
|
|
10222
10222
|
* @interface IDoubleValue
|
|
@@ -10234,8 +10234,8 @@ var require_common = __commonJS({
|
|
|
10234
10234
|
}
|
|
10235
10235
|
}
|
|
10236
10236
|
});
|
|
10237
|
-
|
|
10238
|
-
return
|
|
10237
|
+
common.get = function get(file) {
|
|
10238
|
+
return common[file] || null;
|
|
10239
10239
|
};
|
|
10240
10240
|
}
|
|
10241
10241
|
});
|
|
@@ -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()));
|
|
@@ -24043,10 +24043,19 @@ var require_src3 = __commonJS({
|
|
|
24043
24043
|
|
|
24044
24044
|
// src/core/rpc-signatures.ts
|
|
24045
24045
|
function server() {
|
|
24046
|
-
|
|
24046
|
+
const descriptor = {
|
|
24047
24047
|
serviceType: "server",
|
|
24048
24048
|
methodType: "unary"
|
|
24049
24049
|
};
|
|
24050
|
+
const contextFn = (context) => {
|
|
24051
|
+
descriptor.config = {
|
|
24052
|
+
metadata: context.metadata !== void 0,
|
|
24053
|
+
ack: false
|
|
24054
|
+
};
|
|
24055
|
+
return descriptor;
|
|
24056
|
+
};
|
|
24057
|
+
Object.assign(contextFn, descriptor);
|
|
24058
|
+
return contextFn;
|
|
24050
24059
|
}
|
|
24051
24060
|
function client() {
|
|
24052
24061
|
return {
|
|
@@ -24054,6 +24063,21 @@ function client() {
|
|
|
24054
24063
|
methodType: "unary"
|
|
24055
24064
|
};
|
|
24056
24065
|
}
|
|
24066
|
+
function bidi(..._) {
|
|
24067
|
+
const descriptor = {
|
|
24068
|
+
serviceType: "bidi",
|
|
24069
|
+
methodType: "bidi"
|
|
24070
|
+
};
|
|
24071
|
+
const configFn = (config) => {
|
|
24072
|
+
descriptor.config = {
|
|
24073
|
+
metadata: config.metadata !== void 0,
|
|
24074
|
+
ack: config.ack ?? false
|
|
24075
|
+
};
|
|
24076
|
+
return descriptor;
|
|
24077
|
+
};
|
|
24078
|
+
Object.assign(configFn, descriptor);
|
|
24079
|
+
return configFn;
|
|
24080
|
+
}
|
|
24057
24081
|
|
|
24058
24082
|
// src/core/service.ts
|
|
24059
24083
|
var ServiceImpl = class {
|
|
@@ -24114,18 +24138,18 @@ function loadProtoFromString(source) {
|
|
|
24114
24138
|
function encodeRequestMessage(id, value) {
|
|
24115
24139
|
return {
|
|
24116
24140
|
id,
|
|
24117
|
-
value: msgpack.encode(value)
|
|
24141
|
+
value: value === void 0 ? void 0 : msgpack.encode(value)
|
|
24118
24142
|
};
|
|
24119
24143
|
}
|
|
24120
24144
|
function decodeRequestMessage(message) {
|
|
24121
24145
|
const id = message.id;
|
|
24122
|
-
const mapData = message.value === void 0 ?
|
|
24146
|
+
const mapData = message.value === void 0 ? void 0 : msgpack.decode(message.value);
|
|
24123
24147
|
return [id, mapData];
|
|
24124
24148
|
}
|
|
24125
24149
|
function encodeResponseMessage(id, value) {
|
|
24126
24150
|
return {
|
|
24127
24151
|
id,
|
|
24128
|
-
value: msgpack.encode(value)
|
|
24152
|
+
value: value === void 0 ? void 0 : msgpack.encode(value)
|
|
24129
24153
|
};
|
|
24130
24154
|
}
|
|
24131
24155
|
function decodeResponseMessage(message) {
|
|
@@ -24133,6 +24157,18 @@ function decodeResponseMessage(message) {
|
|
|
24133
24157
|
const mapData = message.value === void 0 ? void 0 : msgpack.decode(message.value);
|
|
24134
24158
|
return [id, mapData];
|
|
24135
24159
|
}
|
|
24160
|
+
function encodeMetadata(raw) {
|
|
24161
|
+
const m = new niceGrpc.Metadata();
|
|
24162
|
+
m.set("better-grpc", JSON.stringify(raw));
|
|
24163
|
+
return m;
|
|
24164
|
+
}
|
|
24165
|
+
function decodeMetadata(metadata) {
|
|
24166
|
+
const betterGrpcMetadata = metadata.get("better-grpc");
|
|
24167
|
+
if (!betterGrpcMetadata) {
|
|
24168
|
+
throw new Error("Failed to decode metadata: 'better-grpc' key not found in gRPC metadata");
|
|
24169
|
+
}
|
|
24170
|
+
return JSON.parse(betterGrpcMetadata);
|
|
24171
|
+
}
|
|
24136
24172
|
|
|
24137
24173
|
// src/runtime/proto-builder.ts
|
|
24138
24174
|
function buildProtoString(services) {
|
|
@@ -24181,13 +24217,18 @@ var GrpcClient = class {
|
|
|
24181
24217
|
clientFactory;
|
|
24182
24218
|
proto;
|
|
24183
24219
|
clients = /* @__PURE__ */ new Map();
|
|
24220
|
+
pushableStreams = {};
|
|
24221
|
+
pendingStreams = /* @__PURE__ */ new Map();
|
|
24222
|
+
pendingBidi = /* @__PURE__ */ new Map();
|
|
24223
|
+
// bidi that is waiting for context
|
|
24224
|
+
pendingBidiAck = /* @__PURE__ */ new Map();
|
|
24184
24225
|
constructor(address, serviceImpls) {
|
|
24185
24226
|
this.address = address;
|
|
24186
24227
|
this.serviceImpls = serviceImpls;
|
|
24187
24228
|
this.proto = loadProtoFromString(buildProtoString(serviceImpls));
|
|
24188
24229
|
const useSSL = !address.includes("localhost") && !address.includes("127.0.0.1") && !address.includes("0.0.0.0");
|
|
24189
|
-
const
|
|
24190
|
-
this.channel = niceGrpc.createChannel(address,
|
|
24230
|
+
const credentials = useSSL ? niceGrpc.ChannelCredentials.createSsl() : niceGrpc.ChannelCredentials.createInsecure();
|
|
24231
|
+
this.channel = niceGrpc.createChannel(address, credentials, {
|
|
24191
24232
|
"grpc.max_receive_message_length": 10 * 1024 * 1024,
|
|
24192
24233
|
"grpc.max_send_message_length": 10 * 1024 * 1024,
|
|
24193
24234
|
"grpc.keepalive_time_ms": 3e4,
|
|
@@ -24205,27 +24246,90 @@ var GrpcClient = class {
|
|
|
24205
24246
|
this.clients.set(serviceImpl.serviceClass.serviceName, client2);
|
|
24206
24247
|
}
|
|
24207
24248
|
}
|
|
24249
|
+
setStream(serviceName, methodName, stream) {
|
|
24250
|
+
if (!this.pushableStreams[serviceName]) {
|
|
24251
|
+
this.pushableStreams[serviceName] = {};
|
|
24252
|
+
}
|
|
24253
|
+
this.pushableStreams[serviceName][methodName.toUpperCase()] = stream;
|
|
24254
|
+
if (this.pendingStreams.has(`${serviceName}.${methodName.toUpperCase()}`)) {
|
|
24255
|
+
const resolve = this.pendingStreams.get(`${serviceName}.${methodName.toUpperCase()}`);
|
|
24256
|
+
resolve?.(stream);
|
|
24257
|
+
this.pendingStreams.delete(`${serviceName}.${methodName.toUpperCase()}`);
|
|
24258
|
+
}
|
|
24259
|
+
}
|
|
24260
|
+
async getStream(serviceName, methodName) {
|
|
24261
|
+
const stream = this.pushableStreams[serviceName]?.[methodName.toUpperCase()];
|
|
24262
|
+
if (!stream) {
|
|
24263
|
+
return new Promise((resolve) => {
|
|
24264
|
+
this.pendingStreams.set(`${serviceName}.${methodName.toUpperCase()}`, resolve);
|
|
24265
|
+
});
|
|
24266
|
+
}
|
|
24267
|
+
return stream;
|
|
24268
|
+
}
|
|
24208
24269
|
watching() {
|
|
24209
24270
|
for (const serviceImpl of this.serviceImpls) {
|
|
24210
24271
|
const client2 = this.clients.get(serviceImpl.serviceClass.serviceName);
|
|
24211
24272
|
for (const [name, descriptor] of Object.entries(serviceImpl.methods())) {
|
|
24212
|
-
switch (descriptor.serviceType) {
|
|
24213
|
-
case "client":
|
|
24214
|
-
|
|
24215
|
-
|
|
24216
|
-
|
|
24217
|
-
|
|
24218
|
-
(
|
|
24273
|
+
switch (`${descriptor.serviceType}:${descriptor.methodType}`) {
|
|
24274
|
+
case "client:unary": {
|
|
24275
|
+
const incomingStream = itPushable.pushable({ objectMode: true });
|
|
24276
|
+
const incomingMessages = client2[name.toUpperCase()](incomingStream);
|
|
24277
|
+
(async () => {
|
|
24278
|
+
try {
|
|
24279
|
+
for await (const message of incomingMessages) {
|
|
24280
|
+
const [id, value] = decodeRequestMessage(message);
|
|
24281
|
+
const responseValue = await serviceImpl.implementation[name](...value ?? []);
|
|
24282
|
+
incomingStream.push(encodeResponseMessage(id, responseValue));
|
|
24283
|
+
}
|
|
24284
|
+
} finally {
|
|
24285
|
+
incomingStream.end();
|
|
24286
|
+
}
|
|
24287
|
+
})();
|
|
24288
|
+
break;
|
|
24289
|
+
}
|
|
24290
|
+
case "bidi:bidi": {
|
|
24291
|
+
const setupBidi = (context) => {
|
|
24292
|
+
const outStream = itPushable.pushable({ objectMode: true });
|
|
24293
|
+
const inStream = itPushable.pushable({ objectMode: true });
|
|
24294
|
+
this.setStream(
|
|
24295
|
+
`${serviceImpl.serviceClass.serviceName}_OUT`,
|
|
24296
|
+
name.toUpperCase(),
|
|
24297
|
+
outStream
|
|
24298
|
+
);
|
|
24299
|
+
this.setStream(`${serviceImpl.serviceClass.serviceName}_IN`, name.toUpperCase(), inStream);
|
|
24300
|
+
const incomingMessages = context ? client2[name.toUpperCase()](outStream, { metadata: encodeMetadata(context.metadata) }) : client2[name.toUpperCase()](outStream);
|
|
24301
|
+
(async () => {
|
|
24302
|
+
try {
|
|
24219
24303
|
for await (const message of incomingMessages) {
|
|
24220
24304
|
const [id, value] = decodeRequestMessage(message);
|
|
24221
|
-
|
|
24222
|
-
|
|
24305
|
+
if (id && descriptor.config?.ack && value === void 0) {
|
|
24306
|
+
this.pendingBidiAck.get(id)?.();
|
|
24307
|
+
this.pendingBidiAck.delete(id);
|
|
24308
|
+
} else {
|
|
24309
|
+
inStream.push(value ?? []);
|
|
24310
|
+
if (id && descriptor.config?.ack) {
|
|
24311
|
+
outStream.push(encodeRequestMessage(id, void 0));
|
|
24312
|
+
}
|
|
24313
|
+
}
|
|
24223
24314
|
}
|
|
24224
|
-
}
|
|
24225
|
-
|
|
24226
|
-
|
|
24315
|
+
} finally {
|
|
24316
|
+
inStream.end();
|
|
24317
|
+
outStream.end();
|
|
24318
|
+
}
|
|
24319
|
+
})();
|
|
24320
|
+
};
|
|
24321
|
+
if (descriptor.config?.metadata) {
|
|
24322
|
+
(async () => {
|
|
24323
|
+
const context = await new Promise((resolve) => {
|
|
24324
|
+
this.pendingBidi.set(`${serviceImpl.serviceClass.serviceName}.${name}`, resolve);
|
|
24325
|
+
});
|
|
24326
|
+
setupBidi(context);
|
|
24327
|
+
})();
|
|
24328
|
+
} else {
|
|
24329
|
+
setupBidi(void 0);
|
|
24227
24330
|
}
|
|
24228
24331
|
break;
|
|
24332
|
+
}
|
|
24229
24333
|
}
|
|
24230
24334
|
}
|
|
24231
24335
|
}
|
|
@@ -24235,13 +24339,72 @@ var GrpcClient = class {
|
|
|
24235
24339
|
const serviceCallableInstance = {};
|
|
24236
24340
|
for (const [name, descriptor] of Object.entries(serviceImpl.methods())) {
|
|
24237
24341
|
switch (`${descriptor.serviceType}:${descriptor.methodType}`) {
|
|
24238
|
-
case "server:unary":
|
|
24239
|
-
|
|
24240
|
-
|
|
24241
|
-
|
|
24242
|
-
|
|
24342
|
+
case "server:unary": {
|
|
24343
|
+
if (descriptor.config?.metadata) {
|
|
24344
|
+
serviceCallableInstance[name] = (...args) => {
|
|
24345
|
+
return {
|
|
24346
|
+
withMeta: async (metadata) => {
|
|
24347
|
+
const response = await this.clients.get(serviceImpl.serviceClass.serviceName)[name.toUpperCase()](encodeRequestMessage(void 0, args), {
|
|
24348
|
+
metadata: encodeMetadata(metadata)
|
|
24349
|
+
});
|
|
24350
|
+
const [_, value] = decodeResponseMessage(response);
|
|
24351
|
+
return value;
|
|
24352
|
+
}
|
|
24353
|
+
};
|
|
24354
|
+
};
|
|
24355
|
+
} else {
|
|
24356
|
+
serviceCallableInstance[name] = async (...args) => {
|
|
24357
|
+
const response = await this.clients.get(serviceImpl.serviceClass.serviceName)[name.toUpperCase()](encodeRequestMessage(void 0, args));
|
|
24358
|
+
const [_, value] = decodeResponseMessage(response);
|
|
24359
|
+
return value;
|
|
24360
|
+
};
|
|
24361
|
+
}
|
|
24362
|
+
break;
|
|
24363
|
+
}
|
|
24364
|
+
case "bidi:bidi": {
|
|
24365
|
+
async function* generator(client2) {
|
|
24366
|
+
const inStream = await client2.getStream(
|
|
24367
|
+
`${serviceImpl.serviceClass.serviceName}_IN`,
|
|
24368
|
+
name.toUpperCase()
|
|
24369
|
+
);
|
|
24370
|
+
yield* inStream;
|
|
24371
|
+
}
|
|
24372
|
+
const emitFn = async (...args) => {
|
|
24373
|
+
const outStream = await this.getStream(
|
|
24374
|
+
`${serviceImpl.serviceClass.serviceName}_OUT`,
|
|
24375
|
+
name.toUpperCase()
|
|
24376
|
+
);
|
|
24377
|
+
const ackId = descriptor.config?.ack ? crypto.randomUUID() : void 0;
|
|
24378
|
+
outStream.push(encodeRequestMessage(ackId, args));
|
|
24379
|
+
if (ackId) {
|
|
24380
|
+
return new Promise((resolve) => {
|
|
24381
|
+
this.pendingBidiAck.set(ackId, resolve);
|
|
24382
|
+
});
|
|
24383
|
+
}
|
|
24243
24384
|
};
|
|
24385
|
+
const context = {
|
|
24386
|
+
context: async (ctx) => {
|
|
24387
|
+
const resolve = this.pendingBidi.get(`${serviceImpl.serviceClass.serviceName}.${name}`);
|
|
24388
|
+
if (resolve) {
|
|
24389
|
+
resolve(ctx);
|
|
24390
|
+
this.pendingBidi.delete(`${serviceImpl.serviceClass.serviceName}.${name}`);
|
|
24391
|
+
}
|
|
24392
|
+
}
|
|
24393
|
+
};
|
|
24394
|
+
const hybrid = Object.assign(emitFn, {
|
|
24395
|
+
[Symbol.asyncIterator]: () => {
|
|
24396
|
+
const iterator = generator(this);
|
|
24397
|
+
return {
|
|
24398
|
+
next: iterator.next.bind(iterator),
|
|
24399
|
+
return: iterator.return.bind(iterator),
|
|
24400
|
+
throw: iterator.throw.bind(iterator)
|
|
24401
|
+
};
|
|
24402
|
+
}
|
|
24403
|
+
});
|
|
24404
|
+
Object.assign(hybrid, context);
|
|
24405
|
+
serviceCallableInstance[name] = hybrid;
|
|
24244
24406
|
break;
|
|
24407
|
+
}
|
|
24245
24408
|
}
|
|
24246
24409
|
}
|
|
24247
24410
|
Object.defineProperty(this, serviceImpl.serviceClass.serviceName, {
|
|
@@ -24293,9 +24456,10 @@ function createServiceImpl(serviceImpl, grpcServer) {
|
|
|
24293
24456
|
for (const [name, descriptor] of Object.entries(serviceImpl.methods())) {
|
|
24294
24457
|
switch (`${descriptor.serviceType}:${descriptor.methodType}`) {
|
|
24295
24458
|
case "server:unary":
|
|
24296
|
-
grpcImpl[name.toUpperCase()] = async (req) => {
|
|
24459
|
+
grpcImpl[name.toUpperCase()] = async (req, ctx) => {
|
|
24297
24460
|
const [_, value] = decodeRequestMessage(req);
|
|
24298
|
-
const
|
|
24461
|
+
const args = descriptor.config?.metadata ? [{ metadata: decodeMetadata(ctx.metadata) }, ...value ?? []] : value ?? [];
|
|
24462
|
+
const result = await serviceImpl.implementation[name](...args);
|
|
24299
24463
|
return encodeResponseMessage(void 0, result);
|
|
24300
24464
|
};
|
|
24301
24465
|
break;
|
|
@@ -24304,19 +24468,55 @@ function createServiceImpl(serviceImpl, grpcServer) {
|
|
|
24304
24468
|
const stream = itPushable.pushable({ objectMode: true });
|
|
24305
24469
|
grpcServer.setStream(serviceImpl.serviceClass.serviceName, name, stream);
|
|
24306
24470
|
(async () => {
|
|
24307
|
-
|
|
24308
|
-
const
|
|
24309
|
-
|
|
24310
|
-
|
|
24311
|
-
|
|
24312
|
-
|
|
24471
|
+
try {
|
|
24472
|
+
for await (const message of incomingStream) {
|
|
24473
|
+
const [id, value] = decodeResponseMessage(message);
|
|
24474
|
+
if (id) {
|
|
24475
|
+
grpcServer.resolveResponse(id, value);
|
|
24476
|
+
} else {
|
|
24477
|
+
throw new Error(`Invalid response message: ${message}`);
|
|
24478
|
+
}
|
|
24313
24479
|
}
|
|
24480
|
+
} finally {
|
|
24481
|
+
stream.end();
|
|
24314
24482
|
}
|
|
24315
|
-
stream.end();
|
|
24316
24483
|
})();
|
|
24317
24484
|
yield* stream;
|
|
24318
24485
|
};
|
|
24319
24486
|
break;
|
|
24487
|
+
case "bidi:bidi":
|
|
24488
|
+
grpcImpl[name.toUpperCase()] = async function* (incomingStream, ctx) {
|
|
24489
|
+
if (descriptor.config?.metadata) {
|
|
24490
|
+
grpcServer.setContext(serviceImpl.serviceClass.serviceName, name, {
|
|
24491
|
+
metadata: decodeMetadata(ctx.metadata)
|
|
24492
|
+
});
|
|
24493
|
+
}
|
|
24494
|
+
const outStream = itPushable.pushable({ objectMode: true });
|
|
24495
|
+
const inStream = itPushable.pushable({ objectMode: true });
|
|
24496
|
+
grpcServer.setStream(`${serviceImpl.serviceClass.serviceName}_OUT`, name, outStream);
|
|
24497
|
+
grpcServer.setStream(`${serviceImpl.serviceClass.serviceName}_IN`, name, inStream);
|
|
24498
|
+
(async () => {
|
|
24499
|
+
try {
|
|
24500
|
+
for await (const message of incomingStream) {
|
|
24501
|
+
const [id, value] = decodeResponseMessage(message);
|
|
24502
|
+
if (id && descriptor.config?.ack && value === void 0) {
|
|
24503
|
+
grpcServer.pendingBidiAck.get(id)?.();
|
|
24504
|
+
grpcServer.pendingBidiAck.delete(id);
|
|
24505
|
+
} else {
|
|
24506
|
+
inStream.push(value ?? []);
|
|
24507
|
+
if (id && descriptor.config?.ack) {
|
|
24508
|
+
outStream.push(encodeRequestMessage(id, void 0));
|
|
24509
|
+
}
|
|
24510
|
+
}
|
|
24511
|
+
}
|
|
24512
|
+
} finally {
|
|
24513
|
+
inStream.end();
|
|
24514
|
+
outStream.end();
|
|
24515
|
+
}
|
|
24516
|
+
})();
|
|
24517
|
+
yield* outStream;
|
|
24518
|
+
};
|
|
24519
|
+
break;
|
|
24320
24520
|
default:
|
|
24321
24521
|
throw new Error(`Unknown method descriptor: ${descriptor} for ${name}`);
|
|
24322
24522
|
}
|
|
@@ -24333,6 +24533,9 @@ var GrpcServer = class {
|
|
|
24333
24533
|
pushableStreams = {};
|
|
24334
24534
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
24335
24535
|
pendingStreams = /* @__PURE__ */ new Map();
|
|
24536
|
+
contexts = /* @__PURE__ */ new Map();
|
|
24537
|
+
pendingContext = /* @__PURE__ */ new Map();
|
|
24538
|
+
pendingBidiAck = /* @__PURE__ */ new Map();
|
|
24336
24539
|
constructor(address, serviceImpls) {
|
|
24337
24540
|
this.address = address;
|
|
24338
24541
|
this.serviceImpls = serviceImpls;
|
|
@@ -24349,6 +24552,9 @@ var GrpcServer = class {
|
|
|
24349
24552
|
await this.grpcServer.listen(this.address);
|
|
24350
24553
|
}
|
|
24351
24554
|
setStream(serviceName, methodName, stream) {
|
|
24555
|
+
if (!this.pushableStreams[serviceName]) {
|
|
24556
|
+
this.pushableStreams[serviceName] = {};
|
|
24557
|
+
}
|
|
24352
24558
|
this.pushableStreams[serviceName][methodName.toUpperCase()] = stream;
|
|
24353
24559
|
if (this.pendingStreams.has(`${serviceName}.${methodName.toUpperCase()}`)) {
|
|
24354
24560
|
const resolve = this.pendingStreams.get(`${serviceName}.${methodName.toUpperCase()}`);
|
|
@@ -24357,7 +24563,7 @@ var GrpcServer = class {
|
|
|
24357
24563
|
}
|
|
24358
24564
|
}
|
|
24359
24565
|
async getStream(serviceName, methodName) {
|
|
24360
|
-
const stream = this.pushableStreams[serviceName][methodName.toUpperCase()];
|
|
24566
|
+
const stream = this.pushableStreams[serviceName]?.[methodName.toUpperCase()];
|
|
24361
24567
|
if (!stream) {
|
|
24362
24568
|
return new Promise((resolve) => {
|
|
24363
24569
|
this.pendingStreams.set(`${serviceName}.${methodName.toUpperCase()}`, resolve);
|
|
@@ -24365,6 +24571,23 @@ var GrpcServer = class {
|
|
|
24365
24571
|
}
|
|
24366
24572
|
return stream;
|
|
24367
24573
|
}
|
|
24574
|
+
setContext(serviceName, methodName, context) {
|
|
24575
|
+
this.contexts.set(`${serviceName}.${methodName.toUpperCase()}`, context);
|
|
24576
|
+
if (this.pendingContext.has(`${serviceName}.${methodName.toUpperCase()}`)) {
|
|
24577
|
+
const resolve = this.pendingContext.get(`${serviceName}.${methodName.toUpperCase()}`);
|
|
24578
|
+
resolve?.(context);
|
|
24579
|
+
this.pendingContext.delete(`${serviceName}.${methodName.toUpperCase()}`);
|
|
24580
|
+
}
|
|
24581
|
+
}
|
|
24582
|
+
async getContext(serviceName, methodName) {
|
|
24583
|
+
const context = this.contexts.get(`${serviceName}.${methodName.toUpperCase()}`);
|
|
24584
|
+
if (!context) {
|
|
24585
|
+
return new Promise((resolve) => {
|
|
24586
|
+
this.pendingContext.set(`${serviceName}.${methodName.toUpperCase()}`, resolve);
|
|
24587
|
+
});
|
|
24588
|
+
}
|
|
24589
|
+
return context;
|
|
24590
|
+
}
|
|
24368
24591
|
resolveResponse(id, value) {
|
|
24369
24592
|
const resolve = this.pendingRequests.get(id);
|
|
24370
24593
|
if (!resolve) {
|
|
@@ -24388,6 +24611,44 @@ var GrpcServer = class {
|
|
|
24388
24611
|
});
|
|
24389
24612
|
};
|
|
24390
24613
|
break;
|
|
24614
|
+
case "bidi:bidi": {
|
|
24615
|
+
async function* generator(server2) {
|
|
24616
|
+
const inStream = await server2.getStream(
|
|
24617
|
+
`${serviceImpl.serviceClass.serviceName}_IN`,
|
|
24618
|
+
name.toUpperCase()
|
|
24619
|
+
);
|
|
24620
|
+
yield* inStream;
|
|
24621
|
+
}
|
|
24622
|
+
const emitFn = async (...args) => {
|
|
24623
|
+
const outStream = await this.getStream(
|
|
24624
|
+
`${serviceImpl.serviceClass.serviceName}_OUT`,
|
|
24625
|
+
name.toUpperCase()
|
|
24626
|
+
);
|
|
24627
|
+
const ackId = descriptor.config?.ack ? crypto.randomUUID() : void 0;
|
|
24628
|
+
outStream.push(encodeRequestMessage(ackId, args));
|
|
24629
|
+
if (ackId) {
|
|
24630
|
+
return new Promise((resolve) => {
|
|
24631
|
+
this.pendingBidiAck.set(ackId, resolve);
|
|
24632
|
+
});
|
|
24633
|
+
}
|
|
24634
|
+
};
|
|
24635
|
+
const context = {
|
|
24636
|
+
context: this.getContext(serviceImpl.serviceClass.serviceName, name)
|
|
24637
|
+
};
|
|
24638
|
+
const hybrid = Object.assign(emitFn, {
|
|
24639
|
+
[Symbol.asyncIterator]: () => {
|
|
24640
|
+
const iterator = generator(this);
|
|
24641
|
+
return {
|
|
24642
|
+
next: iterator.next.bind(iterator),
|
|
24643
|
+
return: iterator.return.bind(iterator),
|
|
24644
|
+
throw: iterator.throw.bind(iterator)
|
|
24645
|
+
};
|
|
24646
|
+
}
|
|
24647
|
+
});
|
|
24648
|
+
Object.assign(hybrid, context);
|
|
24649
|
+
serviceCallableInstance[name] = hybrid;
|
|
24650
|
+
break;
|
|
24651
|
+
}
|
|
24391
24652
|
}
|
|
24392
24653
|
}
|
|
24393
24654
|
Object.defineProperty(this, serviceImpl.serviceClass.serviceName, {
|
|
@@ -24452,6 +24713,7 @@ long/umd/index.js:
|
|
|
24452
24713
|
*/
|
|
24453
24714
|
|
|
24454
24715
|
exports.Service = Service;
|
|
24716
|
+
exports.bidi = bidi;
|
|
24455
24717
|
exports.client = client;
|
|
24456
24718
|
exports.createGrpcClient = createGrpcClient;
|
|
24457
24719
|
exports.createGrpcServer = createGrpcServer;
|