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.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { pushable } from 'it-pushable';
|
|
2
|
-
import { ChannelCredentials, createChannel, createClientFactory, createServer } from 'nice-grpc';
|
|
2
|
+
import { ChannelCredentials, createChannel, createClientFactory, createServer, Metadata } from 'nice-grpc';
|
|
3
3
|
import { decode, encode } from '@msgpack/msgpack';
|
|
4
4
|
|
|
5
5
|
var __create = Object.create;
|
|
@@ -348,7 +348,7 @@ var require_metadata = __commonJS({
|
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
|
-
var
|
|
351
|
+
var Metadata2 = class _Metadata {
|
|
352
352
|
constructor(options = {}) {
|
|
353
353
|
this.internalRepr = /* @__PURE__ */ new Map();
|
|
354
354
|
this.opaqueData = /* @__PURE__ */ new Map();
|
|
@@ -540,7 +540,7 @@ var require_metadata = __commonJS({
|
|
|
540
540
|
return result;
|
|
541
541
|
}
|
|
542
542
|
};
|
|
543
|
-
exports2.Metadata =
|
|
543
|
+
exports2.Metadata = Metadata2;
|
|
544
544
|
var bufToString = (val) => {
|
|
545
545
|
return Buffer.isBuffer(val) ? val.toString("base64") : val;
|
|
546
546
|
};
|
|
@@ -3923,10 +3923,10 @@ var require_client_interceptors = __commonJS({
|
|
|
3923
3923
|
const host = options.host;
|
|
3924
3924
|
const parent = (_b = options.parent) !== null && _b !== void 0 ? _b : null;
|
|
3925
3925
|
const propagateFlags = options.propagate_flags;
|
|
3926
|
-
const
|
|
3926
|
+
const credentials = options.credentials;
|
|
3927
3927
|
const call = channel.createCall(path, deadline, host, parent, propagateFlags);
|
|
3928
|
-
if (
|
|
3929
|
-
call.setCredentials(
|
|
3928
|
+
if (credentials) {
|
|
3929
|
+
call.setCredentials(credentials);
|
|
3930
3930
|
}
|
|
3931
3931
|
return call;
|
|
3932
3932
|
}
|
|
@@ -4085,7 +4085,7 @@ var require_client = __commonJS({
|
|
|
4085
4085
|
return ((_a = error.stack) === null || _a === void 0 ? void 0 : _a.split("\n").slice(1).join("\n")) || "no stack trace available";
|
|
4086
4086
|
}
|
|
4087
4087
|
var Client = class {
|
|
4088
|
-
constructor(address,
|
|
4088
|
+
constructor(address, credentials, options = {}) {
|
|
4089
4089
|
var _a, _b;
|
|
4090
4090
|
options = Object.assign({}, options);
|
|
4091
4091
|
this[INTERCEPTOR_SYMBOL] = (_a = options.interceptors) !== null && _a !== void 0 ? _a : [];
|
|
@@ -4102,9 +4102,9 @@ var require_client = __commonJS({
|
|
|
4102
4102
|
} else if (options.channelFactoryOverride) {
|
|
4103
4103
|
const channelFactoryOverride = options.channelFactoryOverride;
|
|
4104
4104
|
delete options.channelFactoryOverride;
|
|
4105
|
-
this[CHANNEL_SYMBOL] = channelFactoryOverride(address,
|
|
4105
|
+
this[CHANNEL_SYMBOL] = channelFactoryOverride(address, credentials, options);
|
|
4106
4106
|
} else {
|
|
4107
|
-
this[CHANNEL_SYMBOL] = new channel_1.ChannelImplementation(address,
|
|
4107
|
+
this[CHANNEL_SYMBOL] = new channel_1.ChannelImplementation(address, credentials, options);
|
|
4108
4108
|
}
|
|
4109
4109
|
}
|
|
4110
4110
|
close() {
|
|
@@ -7715,7 +7715,7 @@ var require_root = __commonJS({
|
|
|
7715
7715
|
var util = require_util();
|
|
7716
7716
|
var Type;
|
|
7717
7717
|
var parse2;
|
|
7718
|
-
var
|
|
7718
|
+
var common;
|
|
7719
7719
|
function Root2(options) {
|
|
7720
7720
|
Namespace.call(this, "", options);
|
|
7721
7721
|
this.deferred = [];
|
|
@@ -7762,7 +7762,7 @@ var require_root = __commonJS({
|
|
|
7762
7762
|
var idx = filename2.lastIndexOf("google/protobuf/");
|
|
7763
7763
|
if (idx > -1) {
|
|
7764
7764
|
var altname = filename2.substring(idx);
|
|
7765
|
-
if (altname in
|
|
7765
|
+
if (altname in common) return altname;
|
|
7766
7766
|
}
|
|
7767
7767
|
return null;
|
|
7768
7768
|
}
|
|
@@ -7799,14 +7799,14 @@ var require_root = __commonJS({
|
|
|
7799
7799
|
return;
|
|
7800
7800
|
}
|
|
7801
7801
|
self2.files.push(filename2);
|
|
7802
|
-
if (filename2 in
|
|
7802
|
+
if (filename2 in common) {
|
|
7803
7803
|
if (sync) {
|
|
7804
|
-
process2(filename2,
|
|
7804
|
+
process2(filename2, common[filename2]);
|
|
7805
7805
|
} else {
|
|
7806
7806
|
++queued;
|
|
7807
7807
|
setTimeout(function() {
|
|
7808
7808
|
--queued;
|
|
7809
|
-
process2(filename2,
|
|
7809
|
+
process2(filename2, common[filename2]);
|
|
7810
7810
|
});
|
|
7811
7811
|
}
|
|
7812
7812
|
return;
|
|
@@ -7946,7 +7946,7 @@ var require_root = __commonJS({
|
|
|
7946
7946
|
Root2._configure = function(Type_, parse_, common_) {
|
|
7947
7947
|
Type = Type_;
|
|
7948
7948
|
parse2 = parse_;
|
|
7949
|
-
|
|
7949
|
+
common = common_;
|
|
7950
7950
|
};
|
|
7951
7951
|
}
|
|
7952
7952
|
});
|
|
@@ -9910,16 +9910,16 @@ var require_parse = __commonJS({
|
|
|
9910
9910
|
// node_modules/protobufjs/src/common.js
|
|
9911
9911
|
var require_common = __commonJS({
|
|
9912
9912
|
"node_modules/protobufjs/src/common.js"(exports2, module2) {
|
|
9913
|
-
module2.exports =
|
|
9913
|
+
module2.exports = common;
|
|
9914
9914
|
var commonRe = /\/|\./;
|
|
9915
|
-
function
|
|
9915
|
+
function common(name, json) {
|
|
9916
9916
|
if (!commonRe.test(name)) {
|
|
9917
9917
|
name = "google/protobuf/" + name + ".proto";
|
|
9918
9918
|
json = { nested: { google: { nested: { protobuf: { nested: json } } } } };
|
|
9919
9919
|
}
|
|
9920
|
-
|
|
9920
|
+
common[name] = json;
|
|
9921
9921
|
}
|
|
9922
|
-
|
|
9922
|
+
common("any", {
|
|
9923
9923
|
/**
|
|
9924
9924
|
* Properties of a google.protobuf.Any message.
|
|
9925
9925
|
* @interface IAny
|
|
@@ -9942,7 +9942,7 @@ var require_common = __commonJS({
|
|
|
9942
9942
|
}
|
|
9943
9943
|
});
|
|
9944
9944
|
var timeType;
|
|
9945
|
-
|
|
9945
|
+
common("duration", {
|
|
9946
9946
|
/**
|
|
9947
9947
|
* Properties of a google.protobuf.Duration message.
|
|
9948
9948
|
* @interface IDuration
|
|
@@ -9964,7 +9964,7 @@ var require_common = __commonJS({
|
|
|
9964
9964
|
}
|
|
9965
9965
|
}
|
|
9966
9966
|
});
|
|
9967
|
-
|
|
9967
|
+
common("timestamp", {
|
|
9968
9968
|
/**
|
|
9969
9969
|
* Properties of a google.protobuf.Timestamp message.
|
|
9970
9970
|
* @interface ITimestamp
|
|
@@ -9975,7 +9975,7 @@ var require_common = __commonJS({
|
|
|
9975
9975
|
*/
|
|
9976
9976
|
Timestamp: timeType
|
|
9977
9977
|
});
|
|
9978
|
-
|
|
9978
|
+
common("empty", {
|
|
9979
9979
|
/**
|
|
9980
9980
|
* Properties of a google.protobuf.Empty message.
|
|
9981
9981
|
* @interface IEmpty
|
|
@@ -9985,7 +9985,7 @@ var require_common = __commonJS({
|
|
|
9985
9985
|
fields: {}
|
|
9986
9986
|
}
|
|
9987
9987
|
});
|
|
9988
|
-
|
|
9988
|
+
common("struct", {
|
|
9989
9989
|
/**
|
|
9990
9990
|
* Properties of a google.protobuf.Struct message.
|
|
9991
9991
|
* @interface IStruct
|
|
@@ -10077,7 +10077,7 @@ var require_common = __commonJS({
|
|
|
10077
10077
|
}
|
|
10078
10078
|
}
|
|
10079
10079
|
});
|
|
10080
|
-
|
|
10080
|
+
common("wrappers", {
|
|
10081
10081
|
/**
|
|
10082
10082
|
* Properties of a google.protobuf.DoubleValue message.
|
|
10083
10083
|
* @interface IDoubleValue
|
|
@@ -10214,7 +10214,7 @@ var require_common = __commonJS({
|
|
|
10214
10214
|
}
|
|
10215
10215
|
}
|
|
10216
10216
|
});
|
|
10217
|
-
|
|
10217
|
+
common("field_mask", {
|
|
10218
10218
|
/**
|
|
10219
10219
|
* Properties of a google.protobuf.FieldMask message.
|
|
10220
10220
|
* @interface IDoubleValue
|
|
@@ -10232,8 +10232,8 @@ var require_common = __commonJS({
|
|
|
10232
10232
|
}
|
|
10233
10233
|
}
|
|
10234
10234
|
});
|
|
10235
|
-
|
|
10236
|
-
return
|
|
10235
|
+
common.get = function get(file) {
|
|
10236
|
+
return common[file] || null;
|
|
10237
10237
|
};
|
|
10238
10238
|
}
|
|
10239
10239
|
});
|
|
@@ -15024,7 +15024,7 @@ var require_single_subchannel_channel = __commonJS({
|
|
|
15024
15024
|
getCallNumber() {
|
|
15025
15025
|
return this.callNumber;
|
|
15026
15026
|
}
|
|
15027
|
-
setCredentials(
|
|
15027
|
+
setCredentials(credentials) {
|
|
15028
15028
|
throw new Error("Method not implemented.");
|
|
15029
15029
|
}
|
|
15030
15030
|
getAuthContext() {
|
|
@@ -15114,7 +15114,7 @@ var require_subchannel = __commonJS({
|
|
|
15114
15114
|
* @param credentials The channel credentials used to establish this
|
|
15115
15115
|
* connection
|
|
15116
15116
|
*/
|
|
15117
|
-
constructor(channelTarget, subchannelAddress, options,
|
|
15117
|
+
constructor(channelTarget, subchannelAddress, options, credentials, connector) {
|
|
15118
15118
|
var _a;
|
|
15119
15119
|
this.channelTarget = channelTarget;
|
|
15120
15120
|
this.subchannelAddress = subchannelAddress;
|
|
@@ -15153,7 +15153,7 @@ var require_subchannel = __commonJS({
|
|
|
15153
15153
|
this.channelzRef = (0, channelz_1.registerChannelzSubchannel)(this.subchannelAddressString, () => this.getChannelzInfo(), this.channelzEnabled);
|
|
15154
15154
|
this.channelzTrace.addTrace("CT_INFO", "Subchannel created");
|
|
15155
15155
|
this.trace("Subchannel constructed with options " + JSON.stringify(options, void 0, 2));
|
|
15156
|
-
this.secureConnector =
|
|
15156
|
+
this.secureConnector = credentials._createSecureConnector(channelTarget, options);
|
|
15157
15157
|
}
|
|
15158
15158
|
getChannelzInfo() {
|
|
15159
15159
|
return {
|
|
@@ -17052,13 +17052,13 @@ var require_load_balancing_call = __commonJS({
|
|
|
17052
17052
|
var http2 = __require("http2");
|
|
17053
17053
|
var TRACER_NAME = "load_balancing_call";
|
|
17054
17054
|
var LoadBalancingCall = class {
|
|
17055
|
-
constructor(channel, callConfig, methodName, host,
|
|
17055
|
+
constructor(channel, callConfig, methodName, host, credentials, deadline, callNumber) {
|
|
17056
17056
|
var _a, _b;
|
|
17057
17057
|
this.channel = channel;
|
|
17058
17058
|
this.callConfig = callConfig;
|
|
17059
17059
|
this.methodName = methodName;
|
|
17060
17060
|
this.host = host;
|
|
17061
|
-
this.credentials =
|
|
17061
|
+
this.credentials = credentials;
|
|
17062
17062
|
this.deadline = deadline;
|
|
17063
17063
|
this.callNumber = callNumber;
|
|
17064
17064
|
this.child = null;
|
|
@@ -17260,7 +17260,7 @@ var require_load_balancing_call = __commonJS({
|
|
|
17260
17260
|
this.pendingHalfClose = true;
|
|
17261
17261
|
}
|
|
17262
17262
|
}
|
|
17263
|
-
setCredentials(
|
|
17263
|
+
setCredentials(credentials) {
|
|
17264
17264
|
throw new Error("Method not implemented.");
|
|
17265
17265
|
}
|
|
17266
17266
|
getCallNumber() {
|
|
@@ -17541,8 +17541,8 @@ var require_resolving_call = __commonJS({
|
|
|
17541
17541
|
this.pendingHalfClose = true;
|
|
17542
17542
|
}
|
|
17543
17543
|
}
|
|
17544
|
-
setCredentials(
|
|
17545
|
-
this.credentials =
|
|
17544
|
+
setCredentials(credentials) {
|
|
17545
|
+
this.credentials = credentials;
|
|
17546
17546
|
}
|
|
17547
17547
|
addStatusWatcher(watcher) {
|
|
17548
17548
|
this.statusWatchers.push(watcher);
|
|
@@ -17636,13 +17636,13 @@ var require_retrying_call = __commonJS({
|
|
|
17636
17636
|
var PREVIONS_RPC_ATTEMPTS_METADATA_KEY = "grpc-previous-rpc-attempts";
|
|
17637
17637
|
var DEFAULT_MAX_ATTEMPTS_LIMIT = 5;
|
|
17638
17638
|
var RetryingCall = class {
|
|
17639
|
-
constructor(channel, callConfig, methodName, host,
|
|
17639
|
+
constructor(channel, callConfig, methodName, host, credentials, deadline, callNumber, bufferTracker, retryThrottler) {
|
|
17640
17640
|
var _a;
|
|
17641
17641
|
this.channel = channel;
|
|
17642
17642
|
this.callConfig = callConfig;
|
|
17643
17643
|
this.methodName = methodName;
|
|
17644
17644
|
this.host = host;
|
|
17645
|
-
this.credentials =
|
|
17645
|
+
this.credentials = credentials;
|
|
17646
17646
|
this.deadline = deadline;
|
|
17647
17647
|
this.callNumber = callNumber;
|
|
17648
17648
|
this.bufferTracker = bufferTracker;
|
|
@@ -18367,9 +18367,9 @@ var require_internal_channel = __commonJS({
|
|
|
18367
18367
|
}
|
|
18368
18368
|
};
|
|
18369
18369
|
var InternalChannel = class {
|
|
18370
|
-
constructor(target,
|
|
18370
|
+
constructor(target, credentials, options) {
|
|
18371
18371
|
var _a, _b, _c, _d, _e, _f;
|
|
18372
|
-
this.credentials =
|
|
18372
|
+
this.credentials = credentials;
|
|
18373
18373
|
this.options = options;
|
|
18374
18374
|
this.connectivityState = connectivity_state_1.ConnectivityState.IDLE;
|
|
18375
18375
|
this.currentPicker = new picker_1.UnavailablePicker();
|
|
@@ -18387,7 +18387,7 @@ var require_internal_channel = __commonJS({
|
|
|
18387
18387
|
if (typeof target !== "string") {
|
|
18388
18388
|
throw new TypeError("Channel target must be a string");
|
|
18389
18389
|
}
|
|
18390
|
-
if (!(
|
|
18390
|
+
if (!(credentials instanceof channel_credentials_1.ChannelCredentials)) {
|
|
18391
18391
|
throw new TypeError("Channel credentials must be a ChannelCredentials object");
|
|
18392
18392
|
}
|
|
18393
18393
|
if (options) {
|
|
@@ -18669,15 +18669,15 @@ var require_internal_channel = __commonJS({
|
|
|
18669
18669
|
this.lastActivityTimestamp = /* @__PURE__ */ new Date();
|
|
18670
18670
|
this.maybeStartIdleTimer();
|
|
18671
18671
|
}
|
|
18672
|
-
createLoadBalancingCall(callConfig, method, host,
|
|
18672
|
+
createLoadBalancingCall(callConfig, method, host, credentials, deadline) {
|
|
18673
18673
|
const callNumber = (0, call_number_1.getNextCallNumber)();
|
|
18674
18674
|
this.trace("createLoadBalancingCall [" + callNumber + '] method="' + method + '"');
|
|
18675
|
-
return new load_balancing_call_1.LoadBalancingCall(this, callConfig, method, host,
|
|
18675
|
+
return new load_balancing_call_1.LoadBalancingCall(this, callConfig, method, host, credentials, deadline, callNumber);
|
|
18676
18676
|
}
|
|
18677
|
-
createRetryingCall(callConfig, method, host,
|
|
18677
|
+
createRetryingCall(callConfig, method, host, credentials, deadline) {
|
|
18678
18678
|
const callNumber = (0, call_number_1.getNextCallNumber)();
|
|
18679
18679
|
this.trace("createRetryingCall [" + callNumber + '] method="' + method + '"');
|
|
18680
|
-
return new retrying_call_1.RetryingCall(this, callConfig, method, host,
|
|
18680
|
+
return new retrying_call_1.RetryingCall(this, callConfig, method, host, credentials, deadline, callNumber, this.retryBufferTracker, RETRY_THROTTLER_MAP.get(this.getTarget()));
|
|
18681
18681
|
}
|
|
18682
18682
|
createResolvingCall(method, deadline, host, parentCall, propagateFlags) {
|
|
18683
18683
|
const callNumber = (0, call_number_1.getNextCallNumber)();
|
|
@@ -18793,11 +18793,11 @@ var require_channel = __commonJS({
|
|
|
18793
18793
|
var channel_credentials_1 = require_channel_credentials();
|
|
18794
18794
|
var internal_channel_1 = require_internal_channel();
|
|
18795
18795
|
var ChannelImplementation = class {
|
|
18796
|
-
constructor(target,
|
|
18796
|
+
constructor(target, credentials, options) {
|
|
18797
18797
|
if (typeof target !== "string") {
|
|
18798
18798
|
throw new TypeError("Channel target must be a string");
|
|
18799
18799
|
}
|
|
18800
|
-
if (!(
|
|
18800
|
+
if (!(credentials instanceof channel_credentials_1.ChannelCredentials)) {
|
|
18801
18801
|
throw new TypeError("Channel credentials must be a ChannelCredentials object");
|
|
18802
18802
|
}
|
|
18803
18803
|
if (options) {
|
|
@@ -18805,7 +18805,7 @@ var require_channel = __commonJS({
|
|
|
18805
18805
|
throw new TypeError("Channel options must be an object");
|
|
18806
18806
|
}
|
|
18807
18807
|
}
|
|
18808
|
-
this.internalChannel = new internal_channel_1.InternalChannel(target,
|
|
18808
|
+
this.internalChannel = new internal_channel_1.InternalChannel(target, credentials, options);
|
|
18809
18809
|
}
|
|
18810
18810
|
close() {
|
|
18811
18811
|
this.internalChannel.close();
|
|
@@ -19332,8 +19332,8 @@ var require_server_credentials = __commonJS({
|
|
|
19332
19332
|
return this.childCredentials._getSecureContextOptions();
|
|
19333
19333
|
}
|
|
19334
19334
|
};
|
|
19335
|
-
function createServerCredentialsWithInterceptors(
|
|
19336
|
-
return new InterceptorServerCredentials(
|
|
19335
|
+
function createServerCredentialsWithInterceptors(credentials, interceptors) {
|
|
19336
|
+
return new InterceptorServerCredentials(credentials, interceptors);
|
|
19337
19337
|
}
|
|
19338
19338
|
}
|
|
19339
19339
|
});
|
|
@@ -20729,11 +20729,11 @@ var require_server = __commonJS({
|
|
|
20729
20729
|
experimentalUnregisterListenerFromChannelz(channelzRef) {
|
|
20730
20730
|
(0, channelz_1.unregisterChannelzRef)(channelzRef);
|
|
20731
20731
|
}
|
|
20732
|
-
createHttp2Server(
|
|
20732
|
+
createHttp2Server(credentials) {
|
|
20733
20733
|
let http2Server;
|
|
20734
|
-
if (
|
|
20735
|
-
const constructorOptions =
|
|
20736
|
-
const contextOptions =
|
|
20734
|
+
if (credentials._isSecure()) {
|
|
20735
|
+
const constructorOptions = credentials._getConstructorOptions();
|
|
20736
|
+
const contextOptions = credentials._getSecureContextOptions();
|
|
20737
20737
|
const secureServerOptions = Object.assign(Object.assign(Object.assign(Object.assign({}, this.commonServerOptions), constructorOptions), contextOptions), { enableTrace: this.options["grpc-node.tls_enable_trace"] === 1 });
|
|
20738
20738
|
let areCredentialsValid = contextOptions !== null;
|
|
20739
20739
|
this.trace("Initial credentials valid: " + areCredentialsValid);
|
|
@@ -20762,15 +20762,15 @@ var require_server = __commonJS({
|
|
|
20762
20762
|
areCredentialsValid = options !== null;
|
|
20763
20763
|
this.trace("Post-update credentials valid: " + areCredentialsValid);
|
|
20764
20764
|
};
|
|
20765
|
-
|
|
20765
|
+
credentials._addWatcher(credsWatcher);
|
|
20766
20766
|
http2Server.on("close", () => {
|
|
20767
|
-
|
|
20767
|
+
credentials._removeWatcher(credsWatcher);
|
|
20768
20768
|
});
|
|
20769
20769
|
} else {
|
|
20770
20770
|
http2Server = http2.createServer(this.commonServerOptions);
|
|
20771
20771
|
}
|
|
20772
20772
|
http2Server.setTimeout(0, noop);
|
|
20773
|
-
this._setupHandlers(http2Server,
|
|
20773
|
+
this._setupHandlers(http2Server, credentials._getInterceptors());
|
|
20774
20774
|
return http2Server;
|
|
20775
20775
|
}
|
|
20776
20776
|
bindOneAddress(address, boundPortObject) {
|
|
@@ -21005,14 +21005,14 @@ var require_server = __commonJS({
|
|
|
21005
21005
|
* @param channelzRef
|
|
21006
21006
|
* @returns
|
|
21007
21007
|
*/
|
|
21008
|
-
experimentalCreateConnectionInjectorWithChannelzRef(
|
|
21009
|
-
if (
|
|
21008
|
+
experimentalCreateConnectionInjectorWithChannelzRef(credentials, channelzRef, ownsChannelzRef = false) {
|
|
21009
|
+
if (credentials === null || !(credentials instanceof server_credentials_1.ServerCredentials)) {
|
|
21010
21010
|
throw new TypeError("creds must be a ServerCredentials object");
|
|
21011
21011
|
}
|
|
21012
21012
|
if (this.channelzEnabled) {
|
|
21013
21013
|
this.listenerChildrenTracker.refChild(channelzRef);
|
|
21014
21014
|
}
|
|
21015
|
-
const server2 = this.createHttp2Server(
|
|
21015
|
+
const server2 = this.createHttp2Server(credentials);
|
|
21016
21016
|
const sessionsSet = /* @__PURE__ */ new Set();
|
|
21017
21017
|
this.http2Servers.set(server2, {
|
|
21018
21018
|
channelzRef,
|
|
@@ -21042,12 +21042,12 @@ var require_server = __commonJS({
|
|
|
21042
21042
|
}
|
|
21043
21043
|
};
|
|
21044
21044
|
}
|
|
21045
|
-
createConnectionInjector(
|
|
21046
|
-
if (
|
|
21045
|
+
createConnectionInjector(credentials) {
|
|
21046
|
+
if (credentials === null || !(credentials instanceof server_credentials_1.ServerCredentials)) {
|
|
21047
21047
|
throw new TypeError("creds must be a ServerCredentials object");
|
|
21048
21048
|
}
|
|
21049
21049
|
const channelzRef = this.registerInjectorToChannelz();
|
|
21050
|
-
return this.experimentalCreateConnectionInjectorWithChannelzRef(
|
|
21050
|
+
return this.experimentalCreateConnectionInjectorWithChannelzRef(credentials, channelzRef, true);
|
|
21051
21051
|
}
|
|
21052
21052
|
closeServer(server2, callback) {
|
|
21053
21053
|
this.trace("Closing server with address " + JSON.stringify(server2.address()));
|
|
@@ -24041,10 +24041,19 @@ var require_src3 = __commonJS({
|
|
|
24041
24041
|
|
|
24042
24042
|
// src/core/rpc-signatures.ts
|
|
24043
24043
|
function server() {
|
|
24044
|
-
|
|
24044
|
+
const descriptor = {
|
|
24045
24045
|
serviceType: "server",
|
|
24046
24046
|
methodType: "unary"
|
|
24047
24047
|
};
|
|
24048
|
+
const contextFn = (context) => {
|
|
24049
|
+
descriptor.config = {
|
|
24050
|
+
metadata: context.metadata !== void 0,
|
|
24051
|
+
ack: false
|
|
24052
|
+
};
|
|
24053
|
+
return descriptor;
|
|
24054
|
+
};
|
|
24055
|
+
Object.assign(contextFn, descriptor);
|
|
24056
|
+
return contextFn;
|
|
24048
24057
|
}
|
|
24049
24058
|
function client() {
|
|
24050
24059
|
return {
|
|
@@ -24052,6 +24061,21 @@ function client() {
|
|
|
24052
24061
|
methodType: "unary"
|
|
24053
24062
|
};
|
|
24054
24063
|
}
|
|
24064
|
+
function bidi(..._) {
|
|
24065
|
+
const descriptor = {
|
|
24066
|
+
serviceType: "bidi",
|
|
24067
|
+
methodType: "bidi"
|
|
24068
|
+
};
|
|
24069
|
+
const configFn = (config) => {
|
|
24070
|
+
descriptor.config = {
|
|
24071
|
+
metadata: config.metadata !== void 0,
|
|
24072
|
+
ack: config.ack ?? false
|
|
24073
|
+
};
|
|
24074
|
+
return descriptor;
|
|
24075
|
+
};
|
|
24076
|
+
Object.assign(configFn, descriptor);
|
|
24077
|
+
return configFn;
|
|
24078
|
+
}
|
|
24055
24079
|
|
|
24056
24080
|
// src/core/service.ts
|
|
24057
24081
|
var ServiceImpl = class {
|
|
@@ -24112,18 +24136,18 @@ function loadProtoFromString(source) {
|
|
|
24112
24136
|
function encodeRequestMessage(id, value) {
|
|
24113
24137
|
return {
|
|
24114
24138
|
id,
|
|
24115
|
-
value: encode(value)
|
|
24139
|
+
value: value === void 0 ? void 0 : encode(value)
|
|
24116
24140
|
};
|
|
24117
24141
|
}
|
|
24118
24142
|
function decodeRequestMessage(message) {
|
|
24119
24143
|
const id = message.id;
|
|
24120
|
-
const mapData = message.value === void 0 ?
|
|
24144
|
+
const mapData = message.value === void 0 ? void 0 : decode(message.value);
|
|
24121
24145
|
return [id, mapData];
|
|
24122
24146
|
}
|
|
24123
24147
|
function encodeResponseMessage(id, value) {
|
|
24124
24148
|
return {
|
|
24125
24149
|
id,
|
|
24126
|
-
value: encode(value)
|
|
24150
|
+
value: value === void 0 ? void 0 : encode(value)
|
|
24127
24151
|
};
|
|
24128
24152
|
}
|
|
24129
24153
|
function decodeResponseMessage(message) {
|
|
@@ -24131,6 +24155,18 @@ function decodeResponseMessage(message) {
|
|
|
24131
24155
|
const mapData = message.value === void 0 ? void 0 : decode(message.value);
|
|
24132
24156
|
return [id, mapData];
|
|
24133
24157
|
}
|
|
24158
|
+
function encodeMetadata(raw) {
|
|
24159
|
+
const m = new Metadata();
|
|
24160
|
+
m.set("better-grpc", JSON.stringify(raw));
|
|
24161
|
+
return m;
|
|
24162
|
+
}
|
|
24163
|
+
function decodeMetadata(metadata) {
|
|
24164
|
+
const betterGrpcMetadata = metadata.get("better-grpc");
|
|
24165
|
+
if (!betterGrpcMetadata) {
|
|
24166
|
+
throw new Error("Failed to decode metadata: 'better-grpc' key not found in gRPC metadata");
|
|
24167
|
+
}
|
|
24168
|
+
return JSON.parse(betterGrpcMetadata);
|
|
24169
|
+
}
|
|
24134
24170
|
|
|
24135
24171
|
// src/runtime/proto-builder.ts
|
|
24136
24172
|
function buildProtoString(services) {
|
|
@@ -24179,13 +24215,18 @@ var GrpcClient = class {
|
|
|
24179
24215
|
clientFactory;
|
|
24180
24216
|
proto;
|
|
24181
24217
|
clients = /* @__PURE__ */ new Map();
|
|
24218
|
+
pushableStreams = {};
|
|
24219
|
+
pendingStreams = /* @__PURE__ */ new Map();
|
|
24220
|
+
pendingBidi = /* @__PURE__ */ new Map();
|
|
24221
|
+
// bidi that is waiting for context
|
|
24222
|
+
pendingBidiAck = /* @__PURE__ */ new Map();
|
|
24182
24223
|
constructor(address, serviceImpls) {
|
|
24183
24224
|
this.address = address;
|
|
24184
24225
|
this.serviceImpls = serviceImpls;
|
|
24185
24226
|
this.proto = loadProtoFromString(buildProtoString(serviceImpls));
|
|
24186
24227
|
const useSSL = !address.includes("localhost") && !address.includes("127.0.0.1") && !address.includes("0.0.0.0");
|
|
24187
|
-
const
|
|
24188
|
-
this.channel = createChannel(address,
|
|
24228
|
+
const credentials = useSSL ? ChannelCredentials.createSsl() : ChannelCredentials.createInsecure();
|
|
24229
|
+
this.channel = createChannel(address, credentials, {
|
|
24189
24230
|
"grpc.max_receive_message_length": 10 * 1024 * 1024,
|
|
24190
24231
|
"grpc.max_send_message_length": 10 * 1024 * 1024,
|
|
24191
24232
|
"grpc.keepalive_time_ms": 3e4,
|
|
@@ -24203,27 +24244,90 @@ var GrpcClient = class {
|
|
|
24203
24244
|
this.clients.set(serviceImpl.serviceClass.serviceName, client2);
|
|
24204
24245
|
}
|
|
24205
24246
|
}
|
|
24247
|
+
setStream(serviceName, methodName, stream) {
|
|
24248
|
+
if (!this.pushableStreams[serviceName]) {
|
|
24249
|
+
this.pushableStreams[serviceName] = {};
|
|
24250
|
+
}
|
|
24251
|
+
this.pushableStreams[serviceName][methodName.toUpperCase()] = stream;
|
|
24252
|
+
if (this.pendingStreams.has(`${serviceName}.${methodName.toUpperCase()}`)) {
|
|
24253
|
+
const resolve = this.pendingStreams.get(`${serviceName}.${methodName.toUpperCase()}`);
|
|
24254
|
+
resolve?.(stream);
|
|
24255
|
+
this.pendingStreams.delete(`${serviceName}.${methodName.toUpperCase()}`);
|
|
24256
|
+
}
|
|
24257
|
+
}
|
|
24258
|
+
async getStream(serviceName, methodName) {
|
|
24259
|
+
const stream = this.pushableStreams[serviceName]?.[methodName.toUpperCase()];
|
|
24260
|
+
if (!stream) {
|
|
24261
|
+
return new Promise((resolve) => {
|
|
24262
|
+
this.pendingStreams.set(`${serviceName}.${methodName.toUpperCase()}`, resolve);
|
|
24263
|
+
});
|
|
24264
|
+
}
|
|
24265
|
+
return stream;
|
|
24266
|
+
}
|
|
24206
24267
|
watching() {
|
|
24207
24268
|
for (const serviceImpl of this.serviceImpls) {
|
|
24208
24269
|
const client2 = this.clients.get(serviceImpl.serviceClass.serviceName);
|
|
24209
24270
|
for (const [name, descriptor] of Object.entries(serviceImpl.methods())) {
|
|
24210
|
-
switch (descriptor.serviceType) {
|
|
24211
|
-
case "client":
|
|
24212
|
-
|
|
24213
|
-
|
|
24214
|
-
|
|
24215
|
-
|
|
24216
|
-
(
|
|
24271
|
+
switch (`${descriptor.serviceType}:${descriptor.methodType}`) {
|
|
24272
|
+
case "client:unary": {
|
|
24273
|
+
const incomingStream = pushable({ objectMode: true });
|
|
24274
|
+
const incomingMessages = client2[name.toUpperCase()](incomingStream);
|
|
24275
|
+
(async () => {
|
|
24276
|
+
try {
|
|
24277
|
+
for await (const message of incomingMessages) {
|
|
24278
|
+
const [id, value] = decodeRequestMessage(message);
|
|
24279
|
+
const responseValue = await serviceImpl.implementation[name](...value ?? []);
|
|
24280
|
+
incomingStream.push(encodeResponseMessage(id, responseValue));
|
|
24281
|
+
}
|
|
24282
|
+
} finally {
|
|
24283
|
+
incomingStream.end();
|
|
24284
|
+
}
|
|
24285
|
+
})();
|
|
24286
|
+
break;
|
|
24287
|
+
}
|
|
24288
|
+
case "bidi:bidi": {
|
|
24289
|
+
const setupBidi = (context) => {
|
|
24290
|
+
const outStream = pushable({ objectMode: true });
|
|
24291
|
+
const inStream = pushable({ objectMode: true });
|
|
24292
|
+
this.setStream(
|
|
24293
|
+
`${serviceImpl.serviceClass.serviceName}_OUT`,
|
|
24294
|
+
name.toUpperCase(),
|
|
24295
|
+
outStream
|
|
24296
|
+
);
|
|
24297
|
+
this.setStream(`${serviceImpl.serviceClass.serviceName}_IN`, name.toUpperCase(), inStream);
|
|
24298
|
+
const incomingMessages = context ? client2[name.toUpperCase()](outStream, { metadata: encodeMetadata(context.metadata) }) : client2[name.toUpperCase()](outStream);
|
|
24299
|
+
(async () => {
|
|
24300
|
+
try {
|
|
24217
24301
|
for await (const message of incomingMessages) {
|
|
24218
24302
|
const [id, value] = decodeRequestMessage(message);
|
|
24219
|
-
|
|
24220
|
-
|
|
24303
|
+
if (id && descriptor.config?.ack && value === void 0) {
|
|
24304
|
+
this.pendingBidiAck.get(id)?.();
|
|
24305
|
+
this.pendingBidiAck.delete(id);
|
|
24306
|
+
} else {
|
|
24307
|
+
inStream.push(value ?? []);
|
|
24308
|
+
if (id && descriptor.config?.ack) {
|
|
24309
|
+
outStream.push(encodeRequestMessage(id, void 0));
|
|
24310
|
+
}
|
|
24311
|
+
}
|
|
24221
24312
|
}
|
|
24222
|
-
}
|
|
24223
|
-
|
|
24224
|
-
|
|
24313
|
+
} finally {
|
|
24314
|
+
inStream.end();
|
|
24315
|
+
outStream.end();
|
|
24316
|
+
}
|
|
24317
|
+
})();
|
|
24318
|
+
};
|
|
24319
|
+
if (descriptor.config?.metadata) {
|
|
24320
|
+
(async () => {
|
|
24321
|
+
const context = await new Promise((resolve) => {
|
|
24322
|
+
this.pendingBidi.set(`${serviceImpl.serviceClass.serviceName}.${name}`, resolve);
|
|
24323
|
+
});
|
|
24324
|
+
setupBidi(context);
|
|
24325
|
+
})();
|
|
24326
|
+
} else {
|
|
24327
|
+
setupBidi(void 0);
|
|
24225
24328
|
}
|
|
24226
24329
|
break;
|
|
24330
|
+
}
|
|
24227
24331
|
}
|
|
24228
24332
|
}
|
|
24229
24333
|
}
|
|
@@ -24233,13 +24337,72 @@ var GrpcClient = class {
|
|
|
24233
24337
|
const serviceCallableInstance = {};
|
|
24234
24338
|
for (const [name, descriptor] of Object.entries(serviceImpl.methods())) {
|
|
24235
24339
|
switch (`${descriptor.serviceType}:${descriptor.methodType}`) {
|
|
24236
|
-
case "server:unary":
|
|
24237
|
-
|
|
24238
|
-
|
|
24239
|
-
|
|
24240
|
-
|
|
24340
|
+
case "server:unary": {
|
|
24341
|
+
if (descriptor.config?.metadata) {
|
|
24342
|
+
serviceCallableInstance[name] = (...args) => {
|
|
24343
|
+
return {
|
|
24344
|
+
withMeta: async (metadata) => {
|
|
24345
|
+
const response = await this.clients.get(serviceImpl.serviceClass.serviceName)[name.toUpperCase()](encodeRequestMessage(void 0, args), {
|
|
24346
|
+
metadata: encodeMetadata(metadata)
|
|
24347
|
+
});
|
|
24348
|
+
const [_, value] = decodeResponseMessage(response);
|
|
24349
|
+
return value;
|
|
24350
|
+
}
|
|
24351
|
+
};
|
|
24352
|
+
};
|
|
24353
|
+
} else {
|
|
24354
|
+
serviceCallableInstance[name] = async (...args) => {
|
|
24355
|
+
const response = await this.clients.get(serviceImpl.serviceClass.serviceName)[name.toUpperCase()](encodeRequestMessage(void 0, args));
|
|
24356
|
+
const [_, value] = decodeResponseMessage(response);
|
|
24357
|
+
return value;
|
|
24358
|
+
};
|
|
24359
|
+
}
|
|
24360
|
+
break;
|
|
24361
|
+
}
|
|
24362
|
+
case "bidi:bidi": {
|
|
24363
|
+
async function* generator(client2) {
|
|
24364
|
+
const inStream = await client2.getStream(
|
|
24365
|
+
`${serviceImpl.serviceClass.serviceName}_IN`,
|
|
24366
|
+
name.toUpperCase()
|
|
24367
|
+
);
|
|
24368
|
+
yield* inStream;
|
|
24369
|
+
}
|
|
24370
|
+
const emitFn = async (...args) => {
|
|
24371
|
+
const outStream = await this.getStream(
|
|
24372
|
+
`${serviceImpl.serviceClass.serviceName}_OUT`,
|
|
24373
|
+
name.toUpperCase()
|
|
24374
|
+
);
|
|
24375
|
+
const ackId = descriptor.config?.ack ? crypto.randomUUID() : void 0;
|
|
24376
|
+
outStream.push(encodeRequestMessage(ackId, args));
|
|
24377
|
+
if (ackId) {
|
|
24378
|
+
return new Promise((resolve) => {
|
|
24379
|
+
this.pendingBidiAck.set(ackId, resolve);
|
|
24380
|
+
});
|
|
24381
|
+
}
|
|
24241
24382
|
};
|
|
24383
|
+
const context = {
|
|
24384
|
+
context: async (ctx) => {
|
|
24385
|
+
const resolve = this.pendingBidi.get(`${serviceImpl.serviceClass.serviceName}.${name}`);
|
|
24386
|
+
if (resolve) {
|
|
24387
|
+
resolve(ctx);
|
|
24388
|
+
this.pendingBidi.delete(`${serviceImpl.serviceClass.serviceName}.${name}`);
|
|
24389
|
+
}
|
|
24390
|
+
}
|
|
24391
|
+
};
|
|
24392
|
+
const hybrid = Object.assign(emitFn, {
|
|
24393
|
+
[Symbol.asyncIterator]: () => {
|
|
24394
|
+
const iterator = generator(this);
|
|
24395
|
+
return {
|
|
24396
|
+
next: iterator.next.bind(iterator),
|
|
24397
|
+
return: iterator.return.bind(iterator),
|
|
24398
|
+
throw: iterator.throw.bind(iterator)
|
|
24399
|
+
};
|
|
24400
|
+
}
|
|
24401
|
+
});
|
|
24402
|
+
Object.assign(hybrid, context);
|
|
24403
|
+
serviceCallableInstance[name] = hybrid;
|
|
24242
24404
|
break;
|
|
24405
|
+
}
|
|
24243
24406
|
}
|
|
24244
24407
|
}
|
|
24245
24408
|
Object.defineProperty(this, serviceImpl.serviceClass.serviceName, {
|
|
@@ -24291,9 +24454,10 @@ function createServiceImpl(serviceImpl, grpcServer) {
|
|
|
24291
24454
|
for (const [name, descriptor] of Object.entries(serviceImpl.methods())) {
|
|
24292
24455
|
switch (`${descriptor.serviceType}:${descriptor.methodType}`) {
|
|
24293
24456
|
case "server:unary":
|
|
24294
|
-
grpcImpl[name.toUpperCase()] = async (req) => {
|
|
24457
|
+
grpcImpl[name.toUpperCase()] = async (req, ctx) => {
|
|
24295
24458
|
const [_, value] = decodeRequestMessage(req);
|
|
24296
|
-
const
|
|
24459
|
+
const args = descriptor.config?.metadata ? [{ metadata: decodeMetadata(ctx.metadata) }, ...value ?? []] : value ?? [];
|
|
24460
|
+
const result = await serviceImpl.implementation[name](...args);
|
|
24297
24461
|
return encodeResponseMessage(void 0, result);
|
|
24298
24462
|
};
|
|
24299
24463
|
break;
|
|
@@ -24302,19 +24466,55 @@ function createServiceImpl(serviceImpl, grpcServer) {
|
|
|
24302
24466
|
const stream = pushable({ objectMode: true });
|
|
24303
24467
|
grpcServer.setStream(serviceImpl.serviceClass.serviceName, name, stream);
|
|
24304
24468
|
(async () => {
|
|
24305
|
-
|
|
24306
|
-
const
|
|
24307
|
-
|
|
24308
|
-
|
|
24309
|
-
|
|
24310
|
-
|
|
24469
|
+
try {
|
|
24470
|
+
for await (const message of incomingStream) {
|
|
24471
|
+
const [id, value] = decodeResponseMessage(message);
|
|
24472
|
+
if (id) {
|
|
24473
|
+
grpcServer.resolveResponse(id, value);
|
|
24474
|
+
} else {
|
|
24475
|
+
throw new Error(`Invalid response message: ${message}`);
|
|
24476
|
+
}
|
|
24311
24477
|
}
|
|
24478
|
+
} finally {
|
|
24479
|
+
stream.end();
|
|
24312
24480
|
}
|
|
24313
|
-
stream.end();
|
|
24314
24481
|
})();
|
|
24315
24482
|
yield* stream;
|
|
24316
24483
|
};
|
|
24317
24484
|
break;
|
|
24485
|
+
case "bidi:bidi":
|
|
24486
|
+
grpcImpl[name.toUpperCase()] = async function* (incomingStream, ctx) {
|
|
24487
|
+
if (descriptor.config?.metadata) {
|
|
24488
|
+
grpcServer.setContext(serviceImpl.serviceClass.serviceName, name, {
|
|
24489
|
+
metadata: decodeMetadata(ctx.metadata)
|
|
24490
|
+
});
|
|
24491
|
+
}
|
|
24492
|
+
const outStream = pushable({ objectMode: true });
|
|
24493
|
+
const inStream = pushable({ objectMode: true });
|
|
24494
|
+
grpcServer.setStream(`${serviceImpl.serviceClass.serviceName}_OUT`, name, outStream);
|
|
24495
|
+
grpcServer.setStream(`${serviceImpl.serviceClass.serviceName}_IN`, name, inStream);
|
|
24496
|
+
(async () => {
|
|
24497
|
+
try {
|
|
24498
|
+
for await (const message of incomingStream) {
|
|
24499
|
+
const [id, value] = decodeResponseMessage(message);
|
|
24500
|
+
if (id && descriptor.config?.ack && value === void 0) {
|
|
24501
|
+
grpcServer.pendingBidiAck.get(id)?.();
|
|
24502
|
+
grpcServer.pendingBidiAck.delete(id);
|
|
24503
|
+
} else {
|
|
24504
|
+
inStream.push(value ?? []);
|
|
24505
|
+
if (id && descriptor.config?.ack) {
|
|
24506
|
+
outStream.push(encodeRequestMessage(id, void 0));
|
|
24507
|
+
}
|
|
24508
|
+
}
|
|
24509
|
+
}
|
|
24510
|
+
} finally {
|
|
24511
|
+
inStream.end();
|
|
24512
|
+
outStream.end();
|
|
24513
|
+
}
|
|
24514
|
+
})();
|
|
24515
|
+
yield* outStream;
|
|
24516
|
+
};
|
|
24517
|
+
break;
|
|
24318
24518
|
default:
|
|
24319
24519
|
throw new Error(`Unknown method descriptor: ${descriptor} for ${name}`);
|
|
24320
24520
|
}
|
|
@@ -24331,6 +24531,9 @@ var GrpcServer = class {
|
|
|
24331
24531
|
pushableStreams = {};
|
|
24332
24532
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
24333
24533
|
pendingStreams = /* @__PURE__ */ new Map();
|
|
24534
|
+
contexts = /* @__PURE__ */ new Map();
|
|
24535
|
+
pendingContext = /* @__PURE__ */ new Map();
|
|
24536
|
+
pendingBidiAck = /* @__PURE__ */ new Map();
|
|
24334
24537
|
constructor(address, serviceImpls) {
|
|
24335
24538
|
this.address = address;
|
|
24336
24539
|
this.serviceImpls = serviceImpls;
|
|
@@ -24347,6 +24550,9 @@ var GrpcServer = class {
|
|
|
24347
24550
|
await this.grpcServer.listen(this.address);
|
|
24348
24551
|
}
|
|
24349
24552
|
setStream(serviceName, methodName, stream) {
|
|
24553
|
+
if (!this.pushableStreams[serviceName]) {
|
|
24554
|
+
this.pushableStreams[serviceName] = {};
|
|
24555
|
+
}
|
|
24350
24556
|
this.pushableStreams[serviceName][methodName.toUpperCase()] = stream;
|
|
24351
24557
|
if (this.pendingStreams.has(`${serviceName}.${methodName.toUpperCase()}`)) {
|
|
24352
24558
|
const resolve = this.pendingStreams.get(`${serviceName}.${methodName.toUpperCase()}`);
|
|
@@ -24355,7 +24561,7 @@ var GrpcServer = class {
|
|
|
24355
24561
|
}
|
|
24356
24562
|
}
|
|
24357
24563
|
async getStream(serviceName, methodName) {
|
|
24358
|
-
const stream = this.pushableStreams[serviceName][methodName.toUpperCase()];
|
|
24564
|
+
const stream = this.pushableStreams[serviceName]?.[methodName.toUpperCase()];
|
|
24359
24565
|
if (!stream) {
|
|
24360
24566
|
return new Promise((resolve) => {
|
|
24361
24567
|
this.pendingStreams.set(`${serviceName}.${methodName.toUpperCase()}`, resolve);
|
|
@@ -24363,6 +24569,23 @@ var GrpcServer = class {
|
|
|
24363
24569
|
}
|
|
24364
24570
|
return stream;
|
|
24365
24571
|
}
|
|
24572
|
+
setContext(serviceName, methodName, context) {
|
|
24573
|
+
this.contexts.set(`${serviceName}.${methodName.toUpperCase()}`, context);
|
|
24574
|
+
if (this.pendingContext.has(`${serviceName}.${methodName.toUpperCase()}`)) {
|
|
24575
|
+
const resolve = this.pendingContext.get(`${serviceName}.${methodName.toUpperCase()}`);
|
|
24576
|
+
resolve?.(context);
|
|
24577
|
+
this.pendingContext.delete(`${serviceName}.${methodName.toUpperCase()}`);
|
|
24578
|
+
}
|
|
24579
|
+
}
|
|
24580
|
+
async getContext(serviceName, methodName) {
|
|
24581
|
+
const context = this.contexts.get(`${serviceName}.${methodName.toUpperCase()}`);
|
|
24582
|
+
if (!context) {
|
|
24583
|
+
return new Promise((resolve) => {
|
|
24584
|
+
this.pendingContext.set(`${serviceName}.${methodName.toUpperCase()}`, resolve);
|
|
24585
|
+
});
|
|
24586
|
+
}
|
|
24587
|
+
return context;
|
|
24588
|
+
}
|
|
24366
24589
|
resolveResponse(id, value) {
|
|
24367
24590
|
const resolve = this.pendingRequests.get(id);
|
|
24368
24591
|
if (!resolve) {
|
|
@@ -24386,6 +24609,44 @@ var GrpcServer = class {
|
|
|
24386
24609
|
});
|
|
24387
24610
|
};
|
|
24388
24611
|
break;
|
|
24612
|
+
case "bidi:bidi": {
|
|
24613
|
+
async function* generator(server2) {
|
|
24614
|
+
const inStream = await server2.getStream(
|
|
24615
|
+
`${serviceImpl.serviceClass.serviceName}_IN`,
|
|
24616
|
+
name.toUpperCase()
|
|
24617
|
+
);
|
|
24618
|
+
yield* inStream;
|
|
24619
|
+
}
|
|
24620
|
+
const emitFn = async (...args) => {
|
|
24621
|
+
const outStream = await this.getStream(
|
|
24622
|
+
`${serviceImpl.serviceClass.serviceName}_OUT`,
|
|
24623
|
+
name.toUpperCase()
|
|
24624
|
+
);
|
|
24625
|
+
const ackId = descriptor.config?.ack ? crypto.randomUUID() : void 0;
|
|
24626
|
+
outStream.push(encodeRequestMessage(ackId, args));
|
|
24627
|
+
if (ackId) {
|
|
24628
|
+
return new Promise((resolve) => {
|
|
24629
|
+
this.pendingBidiAck.set(ackId, resolve);
|
|
24630
|
+
});
|
|
24631
|
+
}
|
|
24632
|
+
};
|
|
24633
|
+
const context = {
|
|
24634
|
+
context: this.getContext(serviceImpl.serviceClass.serviceName, name)
|
|
24635
|
+
};
|
|
24636
|
+
const hybrid = Object.assign(emitFn, {
|
|
24637
|
+
[Symbol.asyncIterator]: () => {
|
|
24638
|
+
const iterator = generator(this);
|
|
24639
|
+
return {
|
|
24640
|
+
next: iterator.next.bind(iterator),
|
|
24641
|
+
return: iterator.return.bind(iterator),
|
|
24642
|
+
throw: iterator.throw.bind(iterator)
|
|
24643
|
+
};
|
|
24644
|
+
}
|
|
24645
|
+
});
|
|
24646
|
+
Object.assign(hybrid, context);
|
|
24647
|
+
serviceCallableInstance[name] = hybrid;
|
|
24648
|
+
break;
|
|
24649
|
+
}
|
|
24389
24650
|
}
|
|
24390
24651
|
}
|
|
24391
24652
|
Object.defineProperty(this, serviceImpl.serviceClass.serviceName, {
|
|
@@ -24449,6 +24710,6 @@ long/umd/index.js:
|
|
|
24449
24710
|
*)
|
|
24450
24711
|
*/
|
|
24451
24712
|
|
|
24452
|
-
export { Service, client, createGrpcClient, createGrpcServer, server };
|
|
24713
|
+
export { Service, bidi, client, createGrpcClient, createGrpcServer, server };
|
|
24453
24714
|
//# sourceMappingURL=index.js.map
|
|
24454
24715
|
//# sourceMappingURL=index.js.map
|