@zlink-systems/stream-connector 0.28.0 → 0.29.0
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.
|
@@ -14,8 +14,10 @@ export interface ZlinkStreamRequestCall {
|
|
|
14
14
|
timeout(timeoutMs: number): ZlinkStreamRequestCall;
|
|
15
15
|
compress(): ZlinkStreamRequestCall;
|
|
16
16
|
submit<TReply = unknown>(signal?: AbortSignal): Promise<TReply>;
|
|
17
|
+
submit<TReply>(replyType: abstract new (...args: never[]) => TReply, signal?: AbortSignal): Promise<TReply>;
|
|
17
18
|
submitEncoded(signal?: AbortSignal): Promise<ZlinkStreamEncodedPayload>;
|
|
18
|
-
|
|
19
|
+
submitCallback(callback: (result: ZlinkStreamResultOf<ZlinkStreamEncodedPayload>) => void): void;
|
|
20
|
+
submitCallback<TReply>(replyType: abstract new (...args: never[]) => TReply, callback: (result: ZlinkStreamResultOf<TReply>) => void): void;
|
|
19
21
|
}
|
|
20
22
|
export interface ZlinkStreamWaitCall<TPayload = ZlinkStreamEncodedPayload> {
|
|
21
23
|
where(predicate: (message: ZlinkStreamMessage<TPayload>) => boolean): ZlinkStreamWaitCall<TPayload>;
|
|
@@ -28,7 +28,9 @@ export declare class ZlinkStreamRequestBuilder implements ZlinkStreamRequestCall
|
|
|
28
28
|
timeout(timeoutMs: number): this;
|
|
29
29
|
compress(): this;
|
|
30
30
|
submit<TReply = unknown>(signal?: AbortSignal): Promise<TReply>;
|
|
31
|
-
submit(
|
|
31
|
+
submit<TReply>(replyType: abstract new (...args: never[]) => TReply, signal?: AbortSignal): Promise<TReply>;
|
|
32
|
+
submitCallback(callback: (result: ZlinkStreamResultOf<ZlinkStreamEncodedPayload>) => void): void;
|
|
33
|
+
submitCallback<TReply>(replyType: abstract new (...args: never[]) => TReply, callback: (result: ZlinkStreamResultOf<TReply>) => void): void;
|
|
32
34
|
submitEncoded(signal?: AbortSignal): Promise<ZlinkStreamEncodedPayload>;
|
|
33
35
|
}
|
|
34
36
|
export declare class ZlinkStreamWaitBuilder<TPayload = ZlinkStreamEncodedPayload> implements ZlinkStreamWaitCall<TPayload> {
|
|
@@ -210,6 +210,17 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
210
210
|
function isStreamWireCodec(value) {
|
|
211
211
|
return validCodecs.has(value);
|
|
212
212
|
}
|
|
213
|
+
function validateHeaderKindAndControl(kind, codec, flags) {
|
|
214
|
+
if (!isStreamWireMessageKind(kind)) {
|
|
215
|
+
throw new Error("Unknown stream message kind.");
|
|
216
|
+
}
|
|
217
|
+
if (!isStreamWireCodec(codec)) {
|
|
218
|
+
throw new Error("Unknown stream codec.");
|
|
219
|
+
}
|
|
220
|
+
if (kind === 5 /* Control */ && (codec !== 0 /* Raw */ || flags !== 0 /* None */)) {
|
|
221
|
+
throw new Error("Control packet must use raw codec and must not contain flags.");
|
|
222
|
+
}
|
|
223
|
+
}
|
|
213
224
|
var UTF8_TWO_BYTE_MIN = 128;
|
|
214
225
|
var UTF8_THREE_BYTE_MIN = 2048;
|
|
215
226
|
var UTF16_HIGH_SURROGATE_MIN = 55296;
|
|
@@ -385,6 +396,7 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
385
396
|
headerFlags = hasCorrelation ? headerFlags | flags.hasCorrelationId : headerFlags & ~flags.hasCorrelationId;
|
|
386
397
|
headerFlags = hasFlow ? headerFlags | flags.hasFlowId : headerFlags & ~flags.hasFlowId;
|
|
387
398
|
headerFlags = hasActorSlot ? headerFlags | flags.hasActorSlot : headerFlags & ~flags.hasActorSlot;
|
|
399
|
+
validateHeaderKindAndControl(header.kind, header.codec, header.flags | headerFlags);
|
|
388
400
|
const metadataBytes = hasMetadata ? encodeStreamWireMetadata(header.metadata) : new Uint8Array();
|
|
389
401
|
const size = 4 + (hasRequestSeq ? UINT64_BYTES : 0) + 1 + nameBytes.length + (hasMetadata ? UINT16_BYTES + metadataBytes.length : 0) + (hasCorrelation ? 1 + correlationBytes.length : 0) + (hasFlow ? FLOW_FIELDS_BYTES : 0) + (hasActorSlot ? UINT16_BYTES : 0);
|
|
390
402
|
const buffer = new Uint8Array(size);
|
|
@@ -436,6 +448,7 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
436
448
|
const kind = header[offset++];
|
|
437
449
|
const codec = header[offset++];
|
|
438
450
|
const headerFlags = header[offset++];
|
|
451
|
+
validateHeaderKindAndControl(kind, codec, headerFlags);
|
|
439
452
|
const hasRequestSeq = (headerFlags & flags.hasRequestSeq) !== 0;
|
|
440
453
|
const hasMetadata = (headerFlags & flags.hasMetadata) !== 0;
|
|
441
454
|
const hasCorrelation = (headerFlags & flags.hasCorrelationId) !== 0;
|
|
@@ -1033,34 +1046,25 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
1033
1046
|
this.state.compress = true;
|
|
1034
1047
|
return this;
|
|
1035
1048
|
}
|
|
1036
|
-
submit(
|
|
1037
|
-
|
|
1038
|
-
this.
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
this.payload,
|
|
1042
|
-
this.state.metadata,
|
|
1043
|
-
this.state.compress,
|
|
1044
|
-
(_a = this.state.timeoutMs) != null ? _a : this.connector.options.requestTimeoutMs,
|
|
1045
|
-
typeof signalOrCallback === "function" ? void 0 : signalOrCallback,
|
|
1046
|
-
this.state.actorSlot
|
|
1047
|
-
);
|
|
1048
|
-
if (typeof signalOrCallback === "function") {
|
|
1049
|
-
operation.then(
|
|
1050
|
-
(value) => this.enqueueCallback(() => signalOrCallback({ isSuccess: true, value })),
|
|
1051
|
-
(error) => this.enqueueCallback(
|
|
1052
|
-
() => signalOrCallback({ isSuccess: false, error: unwrapStreamError(error) })
|
|
1053
|
-
)
|
|
1054
|
-
);
|
|
1055
|
-
return;
|
|
1056
|
-
}
|
|
1057
|
-
return operation.then(
|
|
1049
|
+
submit(replyTypeOrSignal, signal) {
|
|
1050
|
+
const replyType = typeof replyTypeOrSignal === "function" ? replyTypeOrSignal : void 0;
|
|
1051
|
+
return this.submitEncoded(
|
|
1052
|
+
replyType !== void 0 ? signal : replyTypeOrSignal
|
|
1053
|
+
).then(
|
|
1058
1054
|
(value) => {
|
|
1059
|
-
var
|
|
1060
|
-
return ((
|
|
1055
|
+
var _a;
|
|
1056
|
+
return ((_a = this.connector.options.codec) != null ? _a : zlinkStreamJsonCodec).decode(value, replyType);
|
|
1061
1057
|
}
|
|
1062
1058
|
);
|
|
1063
1059
|
}
|
|
1060
|
+
submitCallback(replyTypeOrCallback, callback) {
|
|
1061
|
+
const operation = callback !== void 0 ? this.submit(replyTypeOrCallback) : this.submitEncoded();
|
|
1062
|
+
const handler = callback != null ? callback : replyTypeOrCallback;
|
|
1063
|
+
operation.then(
|
|
1064
|
+
(value) => this.enqueueCallback(() => handler({ isSuccess: true, value })),
|
|
1065
|
+
(error) => this.enqueueCallback(() => handler({ isSuccess: false, error: unwrapStreamError(error) }))
|
|
1066
|
+
);
|
|
1067
|
+
}
|
|
1064
1068
|
submitEncoded(signal) {
|
|
1065
1069
|
var _a;
|
|
1066
1070
|
this.state.ensureNotExecuted();
|
|
@@ -1344,6 +1348,15 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
1344
1348
|
}
|
|
1345
1349
|
|
|
1346
1350
|
// packages/stream-connector/src/Runtime/ZlinkStreamConnectorOptions.ts
|
|
1351
|
+
var DEFAULT_CONNECT_TIMEOUT_MS = 5e3;
|
|
1352
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
1353
|
+
var DEFAULT_WAIT_TIMEOUT_MS = 5e3;
|
|
1354
|
+
var DEFAULT_HEARTBEAT_INTERVAL_MS = 1e3;
|
|
1355
|
+
var DEFAULT_HEARTBEAT_TIMEOUT_MS = 5e3;
|
|
1356
|
+
var DEFAULT_RECONNECT_INITIAL_DELAY_MS = 250;
|
|
1357
|
+
var DEFAULT_RECONNECT_MAX_DELAY_MS = 5e3;
|
|
1358
|
+
var DEFAULT_RECONNECT_BACKOFF_FACTOR = 2;
|
|
1359
|
+
var DEFAULT_RECONNECT_MAX_ATTEMPTS = 3;
|
|
1347
1360
|
function normalizeOptions(options, defaultTransportFactory) {
|
|
1348
1361
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
1349
1362
|
const endpoint = options.endpoint;
|
|
@@ -1360,20 +1373,20 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
1360
1373
|
const normalized = {
|
|
1361
1374
|
endpoint,
|
|
1362
1375
|
transport: inferredTransport,
|
|
1363
|
-
connectTimeoutMs: (_a = options.connectTimeoutMs) != null ? _a :
|
|
1364
|
-
requestTimeoutMs: (_b = options.requestTimeoutMs) != null ? _b :
|
|
1365
|
-
waitTimeoutMs: (_c = options.waitTimeoutMs) != null ? _c :
|
|
1376
|
+
connectTimeoutMs: (_a = options.connectTimeoutMs) != null ? _a : DEFAULT_CONNECT_TIMEOUT_MS,
|
|
1377
|
+
requestTimeoutMs: (_b = options.requestTimeoutMs) != null ? _b : DEFAULT_REQUEST_TIMEOUT_MS,
|
|
1378
|
+
waitTimeoutMs: (_c = options.waitTimeoutMs) != null ? _c : DEFAULT_WAIT_TIMEOUT_MS,
|
|
1366
1379
|
heartbeat: {
|
|
1367
1380
|
enabled: (_e = (_d = options.heartbeat) == null ? void 0 : _d.enabled) != null ? _e : true,
|
|
1368
|
-
intervalMs: (_g = (_f = options.heartbeat) == null ? void 0 : _f.intervalMs) != null ? _g :
|
|
1369
|
-
timeoutMs: (_i = (_h = options.heartbeat) == null ? void 0 : _h.timeoutMs) != null ? _i :
|
|
1381
|
+
intervalMs: (_g = (_f = options.heartbeat) == null ? void 0 : _f.intervalMs) != null ? _g : DEFAULT_HEARTBEAT_INTERVAL_MS,
|
|
1382
|
+
timeoutMs: (_i = (_h = options.heartbeat) == null ? void 0 : _h.timeoutMs) != null ? _i : DEFAULT_HEARTBEAT_TIMEOUT_MS
|
|
1370
1383
|
},
|
|
1371
1384
|
reconnect: {
|
|
1372
1385
|
enabled: (_k = (_j = options.reconnect) == null ? void 0 : _j.enabled) != null ? _k : true,
|
|
1373
|
-
initialDelayMs: (_m = (_l = options.reconnect) == null ? void 0 : _l.initialDelayMs) != null ? _m :
|
|
1374
|
-
maxDelayMs: (_o = (_n = options.reconnect) == null ? void 0 : _n.maxDelayMs) != null ? _o :
|
|
1375
|
-
backoffFactor: (_q = (_p = options.reconnect) == null ? void 0 : _p.backoffFactor) != null ? _q :
|
|
1376
|
-
maxAttempts: ((_r = options.reconnect) == null ? void 0 : _r.maxAttempts) === void 0 ?
|
|
1386
|
+
initialDelayMs: (_m = (_l = options.reconnect) == null ? void 0 : _l.initialDelayMs) != null ? _m : DEFAULT_RECONNECT_INITIAL_DELAY_MS,
|
|
1387
|
+
maxDelayMs: (_o = (_n = options.reconnect) == null ? void 0 : _n.maxDelayMs) != null ? _o : DEFAULT_RECONNECT_MAX_DELAY_MS,
|
|
1388
|
+
backoffFactor: (_q = (_p = options.reconnect) == null ? void 0 : _p.backoffFactor) != null ? _q : DEFAULT_RECONNECT_BACKOFF_FACTOR,
|
|
1389
|
+
maxAttempts: ((_r = options.reconnect) == null ? void 0 : _r.maxAttempts) === void 0 ? DEFAULT_RECONNECT_MAX_ATTEMPTS : options.reconnect.maxAttempts
|
|
1377
1390
|
},
|
|
1378
1391
|
maxSendPayloadSize: (_s = options.maxSendPayloadSize) != null ? _s : ZLINK_STREAM_DEFAULT_PAYLOAD_BYTES,
|
|
1379
1392
|
maxReceivePayloadSize: (_t = options.maxReceivePayloadSize) != null ? _t : ZLINK_STREAM_DEFAULT_PAYLOAD_BYTES,
|
|
@@ -1475,8 +1488,8 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
1475
1488
|
|
|
1476
1489
|
// packages/stream-connector/src/Runtime/Protocol/ZlinkStreamFrameCodec.ts
|
|
1477
1490
|
var ZlinkStreamFrameCodec = class {
|
|
1478
|
-
static encode(header, payload, maxPayloadSize
|
|
1479
|
-
validatePayload(payload.length, maxPayloadSize);
|
|
1491
|
+
static encode(header, payload, maxPayloadSize) {
|
|
1492
|
+
validatePayload(payload.length, maxPayloadSize != null ? maxPayloadSize : ZLINK_STREAM_DEFAULT_PAYLOAD_BYTES);
|
|
1480
1493
|
try {
|
|
1481
1494
|
return encodeStreamWireFrame(header, payload);
|
|
1482
1495
|
} catch (cause) {
|
|
@@ -1626,9 +1639,7 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
1626
1639
|
};
|
|
1627
1640
|
}
|
|
1628
1641
|
function validateHeaderSemantics(header) {
|
|
1629
|
-
validateEnum(header.kind, header.codec);
|
|
1630
1642
|
const hasRequestSeq = header.requestSeq !== void 0 || (header.flags & 1 /* HasRequestSeq */) !== 0;
|
|
1631
|
-
const hasMetadata = header.metadata.count > 0 || (header.flags & 2 /* HasMetadata */) !== 0;
|
|
1632
1643
|
if (header.kind === 1 /* Send */ && hasRequestSeq) {
|
|
1633
1644
|
throw connectorError(
|
|
1634
1645
|
"frameDecodeFailed" /* FrameDecodeFailed */,
|
|
@@ -1647,25 +1658,6 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
1647
1658
|
"Error packet must use the JSON codec."
|
|
1648
1659
|
);
|
|
1649
1660
|
}
|
|
1650
|
-
if (header.kind === 5 /* Control */) {
|
|
1651
|
-
const hasCorrelation = header.correlationId !== void 0 && header.correlationId.length > 0 || (header.flags & 8 /* HasCorrelationId */) !== 0;
|
|
1652
|
-
const hasFlow = (header.flags & 16 /* HasFlowId */) !== 0;
|
|
1653
|
-
const hasActorSlot = header.actorSlot !== void 0 || (header.flags & 32 /* HasActorSlot */) !== 0;
|
|
1654
|
-
if (header.flags !== 0 /* None */ || hasRequestSeq || hasMetadata || hasCorrelation || hasFlow || hasActorSlot || header.codec !== 0 /* Raw */) {
|
|
1655
|
-
throw connectorError(
|
|
1656
|
-
"frameDecodeFailed" /* FrameDecodeFailed */,
|
|
1657
|
-
"Control packet must use raw codec and must not contain flags."
|
|
1658
|
-
);
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
function validateEnum(kind, codec) {
|
|
1663
|
-
if (!isStreamWireMessageKind(kind)) {
|
|
1664
|
-
throw connectorError("frameDecodeFailed" /* FrameDecodeFailed */, "Unknown stream message kind.");
|
|
1665
|
-
}
|
|
1666
|
-
if (!isStreamWireCodec(codec)) {
|
|
1667
|
-
throw connectorError("frameDecodeFailed" /* FrameDecodeFailed */, "Unknown stream codec.");
|
|
1668
|
-
}
|
|
1669
1661
|
}
|
|
1670
1662
|
function validateEncodeFlags(flags) {
|
|
1671
1663
|
const known = 1 /* HasRequestSeq */ | 2 /* HasMetadata */ | 4 /* PayloadCompressed */ | 8 /* HasCorrelationId */ | 16 /* HasFlowId */ | 32 /* HasActorSlot */;
|
|
@@ -1933,7 +1925,8 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
1933
1925
|
cause instanceof Error ? cause.cause : void 0
|
|
1934
1926
|
);
|
|
1935
1927
|
}
|
|
1936
|
-
const
|
|
1928
|
+
const slot = binding.slot;
|
|
1929
|
+
const actorId = binding.actorId;
|
|
1937
1930
|
if (actorId.length === 0 || this.bySlot.has(slot) || this.byId.has(actorId)) {
|
|
1938
1931
|
throw invalidControl("Actor bound identity is already in use.");
|
|
1939
1932
|
}
|
|
@@ -2189,7 +2182,8 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
2189
2182
|
this.events.runUserCallback(queued.callback, "Connector callback failed.");
|
|
2190
2183
|
continue;
|
|
2191
2184
|
}
|
|
2192
|
-
const
|
|
2185
|
+
const message = queued.message;
|
|
2186
|
+
const signal = queued.signal;
|
|
2193
2187
|
const handlers = this.receiversOf(message);
|
|
2194
2188
|
for (const handler of currentRegistrations(this.handlers.get(message.name), handlers)) {
|
|
2195
2189
|
if (!receives(handler, message)) continue;
|
|
@@ -3056,14 +3050,14 @@ var ZlinkStreamConnectorBundle = (() => {
|
|
|
3056
3050
|
* server `session-closing` and the heartbeat timeout. Every other ending
|
|
3057
3051
|
* takes it from {@link closeReasonFor}.
|
|
3058
3052
|
*/
|
|
3059
|
-
async disconnectForTransportFailure(error, origin, generation, reason
|
|
3053
|
+
async disconnectForTransportFailure(error, origin, generation, reason) {
|
|
3060
3054
|
if (this.closeRequested || this.currentState === "closed" /* Closed */) {
|
|
3061
3055
|
return;
|
|
3062
3056
|
}
|
|
3063
3057
|
if (origin !== void 0 && !this.isCurrentConnection(origin, generation)) {
|
|
3064
3058
|
return;
|
|
3065
3059
|
}
|
|
3066
|
-
this.closeReasonValue = reason;
|
|
3060
|
+
this.closeReasonValue = reason != null ? reason : closeReasonFor(error);
|
|
3067
3061
|
if (this.disconnectTask !== void 0) {
|
|
3068
3062
|
return await this.disconnectTask;
|
|
3069
3063
|
}
|
package/dist/browser/index.mjs
CHANGED
|
@@ -166,6 +166,17 @@ function isStreamWireMessageKind(value) {
|
|
|
166
166
|
function isStreamWireCodec(value) {
|
|
167
167
|
return validCodecs.has(value);
|
|
168
168
|
}
|
|
169
|
+
function validateHeaderKindAndControl(kind, codec, flags) {
|
|
170
|
+
if (!isStreamWireMessageKind(kind)) {
|
|
171
|
+
throw new Error("Unknown stream message kind.");
|
|
172
|
+
}
|
|
173
|
+
if (!isStreamWireCodec(codec)) {
|
|
174
|
+
throw new Error("Unknown stream codec.");
|
|
175
|
+
}
|
|
176
|
+
if (kind === 5 /* Control */ && (codec !== 0 /* Raw */ || flags !== 0 /* None */)) {
|
|
177
|
+
throw new Error("Control packet must use raw codec and must not contain flags.");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
169
180
|
var UTF8_TWO_BYTE_MIN = 128;
|
|
170
181
|
var UTF8_THREE_BYTE_MIN = 2048;
|
|
171
182
|
var UTF16_HIGH_SURROGATE_MIN = 55296;
|
|
@@ -341,6 +352,7 @@ function encodeStreamWireHeader(header, flagOverrides) {
|
|
|
341
352
|
headerFlags = hasCorrelation ? headerFlags | flags.hasCorrelationId : headerFlags & ~flags.hasCorrelationId;
|
|
342
353
|
headerFlags = hasFlow ? headerFlags | flags.hasFlowId : headerFlags & ~flags.hasFlowId;
|
|
343
354
|
headerFlags = hasActorSlot ? headerFlags | flags.hasActorSlot : headerFlags & ~flags.hasActorSlot;
|
|
355
|
+
validateHeaderKindAndControl(header.kind, header.codec, header.flags | headerFlags);
|
|
344
356
|
const metadataBytes = hasMetadata ? encodeStreamWireMetadata(header.metadata) : new Uint8Array();
|
|
345
357
|
const size = 4 + (hasRequestSeq ? UINT64_BYTES : 0) + 1 + nameBytes.length + (hasMetadata ? UINT16_BYTES + metadataBytes.length : 0) + (hasCorrelation ? 1 + correlationBytes.length : 0) + (hasFlow ? FLOW_FIELDS_BYTES : 0) + (hasActorSlot ? UINT16_BYTES : 0);
|
|
346
358
|
const buffer = new Uint8Array(size);
|
|
@@ -392,6 +404,7 @@ function decodeStreamWireHeader(header, flagOverrides, includeFlow = true) {
|
|
|
392
404
|
const kind = header[offset++];
|
|
393
405
|
const codec = header[offset++];
|
|
394
406
|
const headerFlags = header[offset++];
|
|
407
|
+
validateHeaderKindAndControl(kind, codec, headerFlags);
|
|
395
408
|
const hasRequestSeq = (headerFlags & flags.hasRequestSeq) !== 0;
|
|
396
409
|
const hasMetadata = (headerFlags & flags.hasMetadata) !== 0;
|
|
397
410
|
const hasCorrelation = (headerFlags & flags.hasCorrelationId) !== 0;
|
|
@@ -986,28 +999,20 @@ var ZlinkStreamRequestBuilder = class {
|
|
|
986
999
|
this.state.compress = true;
|
|
987
1000
|
return this;
|
|
988
1001
|
}
|
|
989
|
-
submit(
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
this.
|
|
995
|
-
this.state.compress,
|
|
996
|
-
this.state.timeoutMs ?? this.connector.options.requestTimeoutMs,
|
|
997
|
-
typeof signalOrCallback === "function" ? void 0 : signalOrCallback,
|
|
998
|
-
this.state.actorSlot
|
|
1002
|
+
submit(replyTypeOrSignal, signal) {
|
|
1003
|
+
const replyType = typeof replyTypeOrSignal === "function" ? replyTypeOrSignal : void 0;
|
|
1004
|
+
return this.submitEncoded(
|
|
1005
|
+
replyType !== void 0 ? signal : replyTypeOrSignal
|
|
1006
|
+
).then(
|
|
1007
|
+
(value) => (this.connector.options.codec ?? zlinkStreamJsonCodec).decode(value, replyType)
|
|
999
1008
|
);
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
)
|
|
1007
|
-
return;
|
|
1008
|
-
}
|
|
1009
|
-
return operation.then(
|
|
1010
|
-
(value) => (this.connector.options.codec ?? zlinkStreamJsonCodec).decode(value)
|
|
1009
|
+
}
|
|
1010
|
+
submitCallback(replyTypeOrCallback, callback) {
|
|
1011
|
+
const operation = callback !== void 0 ? this.submit(replyTypeOrCallback) : this.submitEncoded();
|
|
1012
|
+
const handler = callback ?? replyTypeOrCallback;
|
|
1013
|
+
operation.then(
|
|
1014
|
+
(value) => this.enqueueCallback(() => handler({ isSuccess: true, value })),
|
|
1015
|
+
(error) => this.enqueueCallback(() => handler({ isSuccess: false, error: unwrapStreamError(error) }))
|
|
1011
1016
|
);
|
|
1012
1017
|
}
|
|
1013
1018
|
submitEncoded(signal) {
|
|
@@ -1290,6 +1295,15 @@ function parseEndpoint(endpoint) {
|
|
|
1290
1295
|
}
|
|
1291
1296
|
|
|
1292
1297
|
// packages/stream-connector/src/Runtime/ZlinkStreamConnectorOptions.ts
|
|
1298
|
+
var DEFAULT_CONNECT_TIMEOUT_MS = 5e3;
|
|
1299
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
1300
|
+
var DEFAULT_WAIT_TIMEOUT_MS = 5e3;
|
|
1301
|
+
var DEFAULT_HEARTBEAT_INTERVAL_MS = 1e3;
|
|
1302
|
+
var DEFAULT_HEARTBEAT_TIMEOUT_MS = 5e3;
|
|
1303
|
+
var DEFAULT_RECONNECT_INITIAL_DELAY_MS = 250;
|
|
1304
|
+
var DEFAULT_RECONNECT_MAX_DELAY_MS = 5e3;
|
|
1305
|
+
var DEFAULT_RECONNECT_BACKOFF_FACTOR = 2;
|
|
1306
|
+
var DEFAULT_RECONNECT_MAX_ATTEMPTS = 3;
|
|
1293
1307
|
function normalizeOptions(options, defaultTransportFactory) {
|
|
1294
1308
|
const endpoint = options.endpoint;
|
|
1295
1309
|
if (endpoint.trim().length === 0) {
|
|
@@ -1305,20 +1319,20 @@ function normalizeOptions(options, defaultTransportFactory) {
|
|
|
1305
1319
|
const normalized = {
|
|
1306
1320
|
endpoint,
|
|
1307
1321
|
transport: inferredTransport,
|
|
1308
|
-
connectTimeoutMs: options.connectTimeoutMs ??
|
|
1309
|
-
requestTimeoutMs: options.requestTimeoutMs ??
|
|
1310
|
-
waitTimeoutMs: options.waitTimeoutMs ??
|
|
1322
|
+
connectTimeoutMs: options.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS,
|
|
1323
|
+
requestTimeoutMs: options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,
|
|
1324
|
+
waitTimeoutMs: options.waitTimeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS,
|
|
1311
1325
|
heartbeat: {
|
|
1312
1326
|
enabled: options.heartbeat?.enabled ?? true,
|
|
1313
|
-
intervalMs: options.heartbeat?.intervalMs ??
|
|
1314
|
-
timeoutMs: options.heartbeat?.timeoutMs ??
|
|
1327
|
+
intervalMs: options.heartbeat?.intervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS,
|
|
1328
|
+
timeoutMs: options.heartbeat?.timeoutMs ?? DEFAULT_HEARTBEAT_TIMEOUT_MS
|
|
1315
1329
|
},
|
|
1316
1330
|
reconnect: {
|
|
1317
1331
|
enabled: options.reconnect?.enabled ?? true,
|
|
1318
|
-
initialDelayMs: options.reconnect?.initialDelayMs ??
|
|
1319
|
-
maxDelayMs: options.reconnect?.maxDelayMs ??
|
|
1320
|
-
backoffFactor: options.reconnect?.backoffFactor ??
|
|
1321
|
-
maxAttempts: options.reconnect?.maxAttempts === void 0 ?
|
|
1332
|
+
initialDelayMs: options.reconnect?.initialDelayMs ?? DEFAULT_RECONNECT_INITIAL_DELAY_MS,
|
|
1333
|
+
maxDelayMs: options.reconnect?.maxDelayMs ?? DEFAULT_RECONNECT_MAX_DELAY_MS,
|
|
1334
|
+
backoffFactor: options.reconnect?.backoffFactor ?? DEFAULT_RECONNECT_BACKOFF_FACTOR,
|
|
1335
|
+
maxAttempts: options.reconnect?.maxAttempts === void 0 ? DEFAULT_RECONNECT_MAX_ATTEMPTS : options.reconnect.maxAttempts
|
|
1322
1336
|
},
|
|
1323
1337
|
maxSendPayloadSize: options.maxSendPayloadSize ?? ZLINK_STREAM_DEFAULT_PAYLOAD_BYTES,
|
|
1324
1338
|
maxReceivePayloadSize: options.maxReceivePayloadSize ?? ZLINK_STREAM_DEFAULT_PAYLOAD_BYTES,
|
|
@@ -1420,8 +1434,8 @@ function validateReconnect(options) {
|
|
|
1420
1434
|
|
|
1421
1435
|
// packages/stream-connector/src/Runtime/Protocol/ZlinkStreamFrameCodec.ts
|
|
1422
1436
|
var ZlinkStreamFrameCodec = class {
|
|
1423
|
-
static encode(header, payload, maxPayloadSize
|
|
1424
|
-
validatePayload(payload.length, maxPayloadSize);
|
|
1437
|
+
static encode(header, payload, maxPayloadSize) {
|
|
1438
|
+
validatePayload(payload.length, maxPayloadSize ?? ZLINK_STREAM_DEFAULT_PAYLOAD_BYTES);
|
|
1425
1439
|
try {
|
|
1426
1440
|
return encodeStreamWireFrame(header, payload);
|
|
1427
1441
|
} catch (cause) {
|
|
@@ -1571,9 +1585,7 @@ function buildHeader(kind, name, codec, metadata, compress, requestSeq, correlat
|
|
|
1571
1585
|
};
|
|
1572
1586
|
}
|
|
1573
1587
|
function validateHeaderSemantics(header) {
|
|
1574
|
-
validateEnum(header.kind, header.codec);
|
|
1575
1588
|
const hasRequestSeq = header.requestSeq !== void 0 || (header.flags & 1 /* HasRequestSeq */) !== 0;
|
|
1576
|
-
const hasMetadata = header.metadata.count > 0 || (header.flags & 2 /* HasMetadata */) !== 0;
|
|
1577
1589
|
if (header.kind === 1 /* Send */ && hasRequestSeq) {
|
|
1578
1590
|
throw connectorError(
|
|
1579
1591
|
"frameDecodeFailed" /* FrameDecodeFailed */,
|
|
@@ -1592,25 +1604,6 @@ function validateHeaderSemantics(header) {
|
|
|
1592
1604
|
"Error packet must use the JSON codec."
|
|
1593
1605
|
);
|
|
1594
1606
|
}
|
|
1595
|
-
if (header.kind === 5 /* Control */) {
|
|
1596
|
-
const hasCorrelation = header.correlationId !== void 0 && header.correlationId.length > 0 || (header.flags & 8 /* HasCorrelationId */) !== 0;
|
|
1597
|
-
const hasFlow = (header.flags & 16 /* HasFlowId */) !== 0;
|
|
1598
|
-
const hasActorSlot = header.actorSlot !== void 0 || (header.flags & 32 /* HasActorSlot */) !== 0;
|
|
1599
|
-
if (header.flags !== 0 /* None */ || hasRequestSeq || hasMetadata || hasCorrelation || hasFlow || hasActorSlot || header.codec !== 0 /* Raw */) {
|
|
1600
|
-
throw connectorError(
|
|
1601
|
-
"frameDecodeFailed" /* FrameDecodeFailed */,
|
|
1602
|
-
"Control packet must use raw codec and must not contain flags."
|
|
1603
|
-
);
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
function validateEnum(kind, codec) {
|
|
1608
|
-
if (!isStreamWireMessageKind(kind)) {
|
|
1609
|
-
throw connectorError("frameDecodeFailed" /* FrameDecodeFailed */, "Unknown stream message kind.");
|
|
1610
|
-
}
|
|
1611
|
-
if (!isStreamWireCodec(codec)) {
|
|
1612
|
-
throw connectorError("frameDecodeFailed" /* FrameDecodeFailed */, "Unknown stream codec.");
|
|
1613
|
-
}
|
|
1614
1607
|
}
|
|
1615
1608
|
function validateEncodeFlags(flags) {
|
|
1616
1609
|
const known = 1 /* HasRequestSeq */ | 2 /* HasMetadata */ | 4 /* PayloadCompressed */ | 8 /* HasCorrelationId */ | 16 /* HasFlowId */ | 32 /* HasActorSlot */;
|
|
@@ -1876,7 +1869,8 @@ var ZlinkStreamActors = class {
|
|
|
1876
1869
|
cause instanceof Error ? cause.cause : void 0
|
|
1877
1870
|
);
|
|
1878
1871
|
}
|
|
1879
|
-
const
|
|
1872
|
+
const slot = binding.slot;
|
|
1873
|
+
const actorId = binding.actorId;
|
|
1880
1874
|
if (actorId.length === 0 || this.bySlot.has(slot) || this.byId.has(actorId)) {
|
|
1881
1875
|
throw invalidControl("Actor bound identity is already in use.");
|
|
1882
1876
|
}
|
|
@@ -2129,7 +2123,8 @@ var ZlinkStreamReceivedMessages = class {
|
|
|
2129
2123
|
this.events.runUserCallback(queued.callback, "Connector callback failed.");
|
|
2130
2124
|
continue;
|
|
2131
2125
|
}
|
|
2132
|
-
const
|
|
2126
|
+
const message = queued.message;
|
|
2127
|
+
const signal = queued.signal;
|
|
2133
2128
|
const handlers = this.receiversOf(message);
|
|
2134
2129
|
for (const handler of currentRegistrations(this.handlers.get(message.name), handlers)) {
|
|
2135
2130
|
if (!receives(handler, message)) continue;
|
|
@@ -2989,14 +2984,14 @@ var ZlinkStreamConnectorLifecycle = class {
|
|
|
2989
2984
|
* server `session-closing` and the heartbeat timeout. Every other ending
|
|
2990
2985
|
* takes it from {@link closeReasonFor}.
|
|
2991
2986
|
*/
|
|
2992
|
-
async disconnectForTransportFailure(error, origin, generation, reason
|
|
2987
|
+
async disconnectForTransportFailure(error, origin, generation, reason) {
|
|
2993
2988
|
if (this.closeRequested || this.currentState === "closed" /* Closed */) {
|
|
2994
2989
|
return;
|
|
2995
2990
|
}
|
|
2996
2991
|
if (origin !== void 0 && !this.isCurrentConnection(origin, generation)) {
|
|
2997
2992
|
return;
|
|
2998
2993
|
}
|
|
2999
|
-
this.closeReasonValue = reason;
|
|
2994
|
+
this.closeReasonValue = reason ?? closeReasonFor(error);
|
|
3000
2995
|
if (this.disconnectTask !== void 0) {
|
|
3001
2996
|
return await this.disconnectTask;
|
|
3002
2997
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zlink-systems/stream-connector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@zlink-systems/stream-wire": "0.
|
|
25
|
+
"@zlink-systems/stream-wire": "0.29.0"
|
|
26
26
|
}
|
|
27
27
|
}
|