@zlink-systems/stream-connector 0.13.0 → 0.14.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.
- package/dist/browser/Contracts/IZlinkStreamConnector.d.ts +1 -2
- package/dist/browser/Contracts/ZlinkStreamConnectorOptions.d.ts +0 -6
- package/dist/browser/Contracts/ZlinkStreamEnums.d.ts +0 -3
- package/dist/browser/Contracts/ZlinkStreamModels.d.ts +0 -13
- package/dist/browser/Contracts/index.d.ts +1 -1
- package/dist/browser/Runtime/ZlinkStreamConnector.d.ts +1 -3
- package/dist/browser/Runtime/ZlinkStreamReceiveDispatcher.d.ts +1 -3
- package/dist/browser/Runtime/ZlinkStreamReceivedMessages.d.ts +1 -4
- package/dist/browser/index.mjs +11 -184
- package/package.json +2 -2
- package/dist/browser/Runtime/ZlinkStreamInboundObservers.d.ts +0 -25
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Disposable } from './ZlinkStreamInterfaces';
|
|
2
2
|
import type { RequiredZlinkStreamConnectorOptions } from './ZlinkStreamConnectorOptions';
|
|
3
3
|
import type { ZlinkStreamRequestCall, ZlinkStreamSendCall, ZlinkStreamExpectNoneCall, ZlinkStreamSequenceCall, ZlinkStreamWaitCall } from './Calls/ZlinkStreamCalls';
|
|
4
|
-
import type { ZlinkStreamConnectionStateChanged, ZlinkStreamEncodedPayload, ZlinkStreamError,
|
|
4
|
+
import type { ZlinkStreamConnectionStateChanged, ZlinkStreamEncodedPayload, ZlinkStreamError, ZlinkStreamMessage } from './ZlinkStreamModels';
|
|
5
5
|
import type { ZlinkStreamCloseReason, ZlinkStreamConnectionState, ZlinkStreamDiagnosticsLevel } from './ZlinkStreamEnums';
|
|
6
6
|
export interface ZlinkStreamConnector {
|
|
7
7
|
readonly isConnected: boolean;
|
|
@@ -30,7 +30,6 @@ export interface ZlinkStreamConnector {
|
|
|
30
30
|
dispatch(signal?: AbortSignal): Promise<void>;
|
|
31
31
|
send(payload: unknown, messageType?: Function): ZlinkStreamSendCall;
|
|
32
32
|
request(payload: unknown, messageType?: Function): ZlinkStreamRequestCall;
|
|
33
|
-
observeInbound(observer: (observation: ZlinkStreamInboundObservation, signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
34
33
|
on<TPayload = ZlinkStreamEncodedPayload>(name: string, handler: (message: ZlinkStreamMessage<TPayload>, signal?: AbortSignal) => Promise<void> | void, messageType?: Function): Disposable;
|
|
35
34
|
waitFor<TPayload = ZlinkStreamEncodedPayload>(name: string): ZlinkStreamWaitCall<TPayload>;
|
|
36
35
|
expectNone<TPayload = ZlinkStreamEncodedPayload>(name: string): ZlinkStreamExpectNoneCall<TPayload>;
|
|
@@ -12,9 +12,6 @@ export interface ZlinkStreamConnectorOptions {
|
|
|
12
12
|
readonly reconnect?: ZlinkStreamReconnectOptions;
|
|
13
13
|
readonly maxSendPayloadSize?: number;
|
|
14
14
|
readonly maxReceivePayloadSize?: number;
|
|
15
|
-
readonly maxReceivedMessages?: number;
|
|
16
|
-
readonly maxInboundObserverNotifications?: number;
|
|
17
|
-
readonly maxInboundObserverPayloadPreviewBytes?: number;
|
|
18
15
|
readonly dispatchMode?: ZlinkStreamDispatchMode;
|
|
19
16
|
readonly compression?: ZlinkStreamCompression;
|
|
20
17
|
readonly compressionCodec?: ZlinkStreamCompressionCodec;
|
|
@@ -85,9 +82,6 @@ export interface RequiredZlinkStreamConnectorOptions {
|
|
|
85
82
|
readonly reconnect: Required<ZlinkStreamReconnectOptions>;
|
|
86
83
|
readonly maxSendPayloadSize: number;
|
|
87
84
|
readonly maxReceivePayloadSize: number;
|
|
88
|
-
readonly maxReceivedMessages: number;
|
|
89
|
-
readonly maxInboundObserverNotifications: number;
|
|
90
|
-
readonly maxInboundObserverPayloadPreviewBytes: number;
|
|
91
85
|
readonly dispatchMode: ZlinkStreamDispatchMode;
|
|
92
86
|
readonly compression: ZlinkStreamCompression;
|
|
93
87
|
readonly compressionCodec?: ZlinkStreamCompressionCodec;
|
|
@@ -54,9 +54,6 @@ export declare enum ZlinkStreamErrorCode {
|
|
|
54
54
|
CompressionFailed = "compressionFailed",
|
|
55
55
|
DecompressionFailed = "decompressionFailed",
|
|
56
56
|
UserCallbackFailed = "userCallbackFailed",
|
|
57
|
-
ObserverFailed = "observer-failed",
|
|
58
|
-
ObserverDropped = "observer-dropped",
|
|
59
|
-
ReceivedMessageDropped = "received-message-dropped",
|
|
60
57
|
RemoteError = "remoteError"
|
|
61
58
|
}
|
|
62
59
|
export declare enum ZlinkStreamConnectionState {
|
|
@@ -42,19 +42,6 @@ export interface ZlinkStreamConnectionStateChanged {
|
|
|
42
42
|
readonly current: ZlinkStreamConnectionState;
|
|
43
43
|
readonly error?: ZlinkStreamError;
|
|
44
44
|
}
|
|
45
|
-
export interface ZlinkStreamInboundObservation {
|
|
46
|
-
readonly kind: ZlinkStreamMessageKind;
|
|
47
|
-
readonly name: string;
|
|
48
|
-
readonly codec: ZlinkStreamCodec;
|
|
49
|
-
readonly requestSeq?: bigint;
|
|
50
|
-
readonly flowId?: string;
|
|
51
|
-
readonly flowOrigin?: ZlinkFlowOrigin;
|
|
52
|
-
readonly metadata: ZlinkStreamMetadata;
|
|
53
|
-
readonly payloadLength: number;
|
|
54
|
-
readonly isCompressed: boolean;
|
|
55
|
-
readonly receivedAt: Date;
|
|
56
|
-
readonly payloadPreview: Uint8Array;
|
|
57
|
-
}
|
|
58
45
|
export interface ZlinkStreamResult {
|
|
59
46
|
readonly isSuccess: boolean;
|
|
60
47
|
readonly error?: ZlinkStreamError;
|
|
@@ -3,7 +3,7 @@ export type { ZlinkFlowOrigin, ZlinkStreamCloseReason } from './ZlinkStreamEnums
|
|
|
3
3
|
export * from './ZlinkStreamConnectorOptions';
|
|
4
4
|
export * from './ZlinkStreamInterfaces';
|
|
5
5
|
export * from './ZlinkStreamMetadata';
|
|
6
|
-
export type { ZlinkStreamEncodedPayload, ZlinkStreamFlow, ZlinkStreamMessage, ZlinkStreamError, ZlinkStreamConnectionStateChanged,
|
|
6
|
+
export type { ZlinkStreamEncodedPayload, ZlinkStreamFlow, ZlinkStreamMessage, ZlinkStreamError, ZlinkStreamConnectionStateChanged, ZlinkStreamResult, ZlinkStreamResultOf } from './ZlinkStreamModels';
|
|
7
7
|
export { ZlinkStreamException } from './ZlinkStreamModels';
|
|
8
8
|
export * from './ZlinkStreamJsonCodec';
|
|
9
9
|
export * from './IZlinkStreamConnector';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Disposable, RequiredZlinkStreamConnectorOptions, ZlinkStreamConnectionState, ZlinkStreamConnectionStateChanged, ZlinkStreamConnector, ZlinkStreamConnectorOptions, ZlinkStreamDiagnosticsLevel, ZlinkStreamEncodedPayload, ZlinkStreamError, ZlinkStreamExpectNoneCall, ZlinkStreamFlow,
|
|
1
|
+
import { Disposable, RequiredZlinkStreamConnectorOptions, ZlinkStreamConnectionState, ZlinkStreamConnectionStateChanged, ZlinkStreamConnector, ZlinkStreamConnectorOptions, ZlinkStreamDiagnosticsLevel, ZlinkStreamEncodedPayload, ZlinkStreamError, ZlinkStreamExpectNoneCall, ZlinkStreamFlow, ZlinkStreamMessage, ZlinkStreamMessageKind, ZlinkStreamMetadata, ZlinkStreamRequestCall, ZlinkStreamSendCall, ZlinkStreamSequenceCall, ZlinkStreamWaitCall } from '../Contracts';
|
|
2
2
|
export declare class DefaultZlinkStreamConnector implements ZlinkStreamConnector {
|
|
3
3
|
static readonly heartbeatPingName = "$zlink.heartbeat.ping";
|
|
4
4
|
static readonly heartbeatPongName = "$zlink.heartbeat.pong";
|
|
@@ -9,7 +9,6 @@ export declare class DefaultZlinkStreamConnector implements ZlinkStreamConnector
|
|
|
9
9
|
private readonly pendingRequests;
|
|
10
10
|
private readonly frameSender;
|
|
11
11
|
private readonly receiveDispatcher;
|
|
12
|
-
private readonly inboundObservers;
|
|
13
12
|
private readonly diagnosticsLevelCell;
|
|
14
13
|
readonly options: RequiredZlinkStreamConnectorOptions;
|
|
15
14
|
constructor(options: ZlinkStreamConnectorOptions);
|
|
@@ -43,7 +42,6 @@ export declare class DefaultZlinkStreamConnector implements ZlinkStreamConnector
|
|
|
43
42
|
dispatch(signal?: AbortSignal): Promise<void>;
|
|
44
43
|
send(payload: unknown, messageType?: Function): ZlinkStreamSendCall;
|
|
45
44
|
request(payload: unknown, messageType?: Function): ZlinkStreamRequestCall;
|
|
46
|
-
observeInbound(observer: (observation: ZlinkStreamInboundObservation, signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
47
45
|
on<TPayload = ZlinkStreamEncodedPayload>(name: string, handler: (message: ZlinkStreamMessage<TPayload>, signal?: AbortSignal) => Promise<void> | void, messageType?: Function): Disposable;
|
|
48
46
|
waitFor<TPayload = ZlinkStreamEncodedPayload>(name: string): ZlinkStreamWaitCall<TPayload>;
|
|
49
47
|
expectNone<TPayload = ZlinkStreamEncodedPayload>(name: string): ZlinkStreamExpectNoneCall<TPayload>;
|
|
@@ -2,7 +2,6 @@ import type { ZlinkStreamConnection } from '../Contracts';
|
|
|
2
2
|
import type { ZlinkStreamFrameProtocol } from './Protocol/ZlinkStreamFrameProtocol';
|
|
3
3
|
import type { ZlinkStreamConnectorEvents } from './ZlinkStreamConnectorEvents';
|
|
4
4
|
import type { ZlinkStreamFrameSender } from './ZlinkStreamFrameSender';
|
|
5
|
-
import type { ZlinkStreamInboundObservers } from './ZlinkStreamInboundObservers';
|
|
6
5
|
import type { ZlinkStreamPendingRequests } from './ZlinkStreamPendingRequests';
|
|
7
6
|
import type { ZlinkStreamReceivedMessages } from './ZlinkStreamReceivedMessages';
|
|
8
7
|
import type { ZlinkFlowContext } from './ZlinkFlowContext';
|
|
@@ -15,14 +14,13 @@ export interface ZlinkStreamReceiveResult {
|
|
|
15
14
|
export declare class ZlinkStreamReceiveDispatcher {
|
|
16
15
|
private readonly protocol;
|
|
17
16
|
private readonly pendingRequests;
|
|
18
|
-
private readonly inboundObservers;
|
|
19
17
|
private readonly receivedMessages;
|
|
20
18
|
private readonly frameSender;
|
|
21
19
|
private readonly events;
|
|
22
20
|
private readonly flowContext;
|
|
23
21
|
private readonly metrics;
|
|
24
22
|
private readonly serverClosing?;
|
|
25
|
-
constructor(protocol: ZlinkStreamFrameProtocol, pendingRequests: ZlinkStreamPendingRequests,
|
|
23
|
+
constructor(protocol: ZlinkStreamFrameProtocol, pendingRequests: ZlinkStreamPendingRequests, receivedMessages: ZlinkStreamReceivedMessages, frameSender: ZlinkStreamFrameSender, events: ZlinkStreamConnectorEvents, flowContext: ZlinkFlowContext, metrics: ZlinkStreamRuntimeMetrics, serverClosing?: ((reason: ZlinkStreamCloseReason) => Promise<void>) | undefined);
|
|
26
24
|
readAndDispatch(connection: ZlinkStreamConnection | undefined, signal?: AbortSignal, isCurrent?: () => boolean): Promise<ZlinkStreamReceiveResult>;
|
|
27
25
|
private dispatch;
|
|
28
26
|
private dispatchControl;
|
|
@@ -2,15 +2,13 @@ import { Disposable, ZlinkStreamEncodedPayload, ZlinkStreamMessage } from '../Co
|
|
|
2
2
|
import type { ZlinkStreamConnectorEvents } from './ZlinkStreamConnectorEvents';
|
|
3
3
|
type EncodedMessageHandler = (message: ZlinkStreamMessage<ZlinkStreamEncodedPayload>, signal?: AbortSignal) => Promise<void> | void;
|
|
4
4
|
export declare class ZlinkStreamReceivedMessages {
|
|
5
|
-
private readonly capacity;
|
|
6
5
|
private readonly events;
|
|
7
6
|
private readonly handlers;
|
|
8
7
|
private readonly queue;
|
|
9
8
|
private queueHead;
|
|
10
9
|
private queuedCount;
|
|
11
10
|
private drainTask;
|
|
12
|
-
|
|
13
|
-
constructor(capacity: number, events: ZlinkStreamConnectorEvents);
|
|
11
|
+
constructor(events: ZlinkStreamConnectorEvents);
|
|
14
12
|
on(name: string, handler: EncodedMessageHandler): Disposable;
|
|
15
13
|
enqueue(message: ZlinkStreamMessage<ZlinkStreamEncodedPayload>, signal?: AbortSignal): void;
|
|
16
14
|
private scheduleDrain;
|
|
@@ -19,6 +17,5 @@ export declare class ZlinkStreamReceivedMessages {
|
|
|
19
17
|
private hasQueuedMessage;
|
|
20
18
|
private advanceHead;
|
|
21
19
|
private compactQueue;
|
|
22
|
-
private reportDropped;
|
|
23
20
|
}
|
|
24
21
|
export {};
|
package/dist/browser/index.mjs
CHANGED
|
@@ -497,20 +497,17 @@ var ZlinkStreamErrorCode = /* @__PURE__ */ ((ZlinkStreamErrorCode2) => {
|
|
|
497
497
|
ZlinkStreamErrorCode2["CompressionFailed"] = "compressionFailed";
|
|
498
498
|
ZlinkStreamErrorCode2["DecompressionFailed"] = "decompressionFailed";
|
|
499
499
|
ZlinkStreamErrorCode2["UserCallbackFailed"] = "userCallbackFailed";
|
|
500
|
-
ZlinkStreamErrorCode2["ObserverFailed"] = "observer-failed";
|
|
501
|
-
ZlinkStreamErrorCode2["ObserverDropped"] = "observer-dropped";
|
|
502
|
-
ZlinkStreamErrorCode2["ReceivedMessageDropped"] = "received-message-dropped";
|
|
503
500
|
ZlinkStreamErrorCode2["RemoteError"] = "remoteError";
|
|
504
501
|
return ZlinkStreamErrorCode2;
|
|
505
502
|
})(ZlinkStreamErrorCode || {});
|
|
506
|
-
var ZlinkStreamConnectionState = /* @__PURE__ */ ((
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
return
|
|
503
|
+
var ZlinkStreamConnectionState = /* @__PURE__ */ ((ZlinkStreamConnectionState3) => {
|
|
504
|
+
ZlinkStreamConnectionState3["Created"] = "created";
|
|
505
|
+
ZlinkStreamConnectionState3["Connecting"] = "connecting";
|
|
506
|
+
ZlinkStreamConnectionState3["Connected"] = "connected";
|
|
507
|
+
ZlinkStreamConnectionState3["Reconnecting"] = "reconnecting";
|
|
508
|
+
ZlinkStreamConnectionState3["Disconnected"] = "disconnected";
|
|
509
|
+
ZlinkStreamConnectionState3["Closed"] = "closed";
|
|
510
|
+
return ZlinkStreamConnectionState3;
|
|
514
511
|
})(ZlinkStreamConnectionState || {});
|
|
515
512
|
|
|
516
513
|
// packages/stream-connector/src/Contracts/ZlinkStreamMetadata.ts
|
|
@@ -1284,11 +1281,6 @@ function normalizeOptions(options, defaultTransportFactory) {
|
|
|
1284
1281
|
validatePositive(options.waitTimeoutMs ?? 5e3, "WaitTimeout");
|
|
1285
1282
|
validatePositive(options.maxSendPayloadSize ?? 64 * 1024, "MaxSendPayloadSize");
|
|
1286
1283
|
validatePositive(options.maxReceivePayloadSize ?? 64 * 1024, "MaxReceivePayloadSize");
|
|
1287
|
-
validatePositive(options.maxReceivedMessages ?? 1024, "MaxReceivedMessages");
|
|
1288
|
-
validatePositive(options.maxInboundObserverNotifications ?? 1024, "MaxInboundObserverNotifications");
|
|
1289
|
-
if ((options.maxInboundObserverPayloadPreviewBytes ?? 0) < 0) {
|
|
1290
|
-
throw connectorError("validationFailed" /* ValidationFailed */, "MaxInboundObserverPayloadPreviewBytes must not be negative.");
|
|
1291
|
-
}
|
|
1292
1284
|
validateHeartbeat(options.heartbeat);
|
|
1293
1285
|
validateReconnect(options.reconnect);
|
|
1294
1286
|
validateDiagnosticsLevel(options.diagnosticsLevel);
|
|
@@ -1312,9 +1304,6 @@ function normalizeOptions(options, defaultTransportFactory) {
|
|
|
1312
1304
|
},
|
|
1313
1305
|
maxSendPayloadSize: options.maxSendPayloadSize ?? 64 * 1024,
|
|
1314
1306
|
maxReceivePayloadSize: options.maxReceivePayloadSize ?? 64 * 1024,
|
|
1315
|
-
maxReceivedMessages: options.maxReceivedMessages ?? 1024,
|
|
1316
|
-
maxInboundObserverNotifications: options.maxInboundObserverNotifications ?? 1024,
|
|
1317
|
-
maxInboundObserverPayloadPreviewBytes: options.maxInboundObserverPayloadPreviewBytes ?? 0,
|
|
1318
1307
|
dispatchMode: options.dispatchMode ?? "manual" /* Manual */,
|
|
1319
1308
|
compression: options.compression ?? "lz4" /* Lz4 */,
|
|
1320
1309
|
compressionCodec: resolveCompressionCodec2(options),
|
|
@@ -1475,8 +1464,7 @@ var ZlinkStreamPendingRequests = class {
|
|
|
1475
1464
|
|
|
1476
1465
|
// packages/stream-connector/src/Runtime/ZlinkStreamReceivedMessages.ts
|
|
1477
1466
|
var ZlinkStreamReceivedMessages = class {
|
|
1478
|
-
constructor(
|
|
1479
|
-
this.capacity = capacity;
|
|
1467
|
+
constructor(events) {
|
|
1480
1468
|
this.events = events;
|
|
1481
1469
|
}
|
|
1482
1470
|
handlers = /* @__PURE__ */ new Map();
|
|
@@ -1487,7 +1475,6 @@ var ZlinkStreamReceivedMessages = class {
|
|
|
1487
1475
|
queueHead = 0;
|
|
1488
1476
|
queuedCount = 0;
|
|
1489
1477
|
drainTask;
|
|
1490
|
-
dropReportPending = false;
|
|
1491
1478
|
on(name, handler) {
|
|
1492
1479
|
validateName(name);
|
|
1493
1480
|
let set = this.handlers.get(name);
|
|
@@ -1507,10 +1494,6 @@ var ZlinkStreamReceivedMessages = class {
|
|
|
1507
1494
|
});
|
|
1508
1495
|
}
|
|
1509
1496
|
enqueue(message, signal) {
|
|
1510
|
-
if (this.queuedCount >= this.capacity) {
|
|
1511
|
-
this.reportDropped(signal);
|
|
1512
|
-
return;
|
|
1513
|
-
}
|
|
1514
1497
|
this.queue.push({ message, signal });
|
|
1515
1498
|
this.queuedCount += 1;
|
|
1516
1499
|
this.scheduleDrain();
|
|
@@ -1580,144 +1563,6 @@ var ZlinkStreamReceivedMessages = class {
|
|
|
1580
1563
|
this.queueHead = 0;
|
|
1581
1564
|
}
|
|
1582
1565
|
}
|
|
1583
|
-
reportDropped(signal) {
|
|
1584
|
-
if (this.dropReportPending) {
|
|
1585
|
-
return;
|
|
1586
|
-
}
|
|
1587
|
-
this.dropReportPending = true;
|
|
1588
|
-
queueMicrotask(() => {
|
|
1589
|
-
void this.events.publishError({
|
|
1590
|
-
code: "received-message-dropped" /* ReceivedMessageDropped */,
|
|
1591
|
-
message: "Received stream message was dropped because the received-message queue is full."
|
|
1592
|
-
}, signal).finally(() => {
|
|
1593
|
-
this.dropReportPending = false;
|
|
1594
|
-
}).catch(() => {
|
|
1595
|
-
});
|
|
1596
|
-
});
|
|
1597
|
-
}
|
|
1598
|
-
};
|
|
1599
|
-
|
|
1600
|
-
// packages/stream-connector/src/Runtime/ZlinkStreamInboundObservers.ts
|
|
1601
|
-
var ZlinkStreamInboundObservers = class {
|
|
1602
|
-
constructor(maxNotifications, maxPayloadPreviewBytes, events) {
|
|
1603
|
-
this.maxNotifications = maxNotifications;
|
|
1604
|
-
this.maxPayloadPreviewBytes = maxPayloadPreviewBytes;
|
|
1605
|
-
this.events = events;
|
|
1606
|
-
}
|
|
1607
|
-
observers = /* @__PURE__ */ new Set();
|
|
1608
|
-
queue = [];
|
|
1609
|
-
queueHead = 0;
|
|
1610
|
-
queuedCount = 0;
|
|
1611
|
-
draining = false;
|
|
1612
|
-
dropReportPending = false;
|
|
1613
|
-
add(observer) {
|
|
1614
|
-
this.observers.add(observer);
|
|
1615
|
-
return subscription(() => this.observers.delete(observer));
|
|
1616
|
-
}
|
|
1617
|
-
enqueue(header, payload, signal) {
|
|
1618
|
-
if (this.observers.size === 0) {
|
|
1619
|
-
return;
|
|
1620
|
-
}
|
|
1621
|
-
if (this.queuedCount >= this.maxNotifications) {
|
|
1622
|
-
this.reportDropped(signal);
|
|
1623
|
-
return;
|
|
1624
|
-
}
|
|
1625
|
-
this.queue.push(this.createObservation(header, payload));
|
|
1626
|
-
this.queuedCount += 1;
|
|
1627
|
-
this.scheduleDrain(signal);
|
|
1628
|
-
}
|
|
1629
|
-
createObservation(header, payload) {
|
|
1630
|
-
const previewLength = Math.min(this.maxPayloadPreviewBytes, payload.length);
|
|
1631
|
-
return Object.freeze({
|
|
1632
|
-
kind: header.kind,
|
|
1633
|
-
name: header.name,
|
|
1634
|
-
codec: header.codec,
|
|
1635
|
-
requestSeq: header.requestSeq,
|
|
1636
|
-
flowId: header.flowId,
|
|
1637
|
-
flowOrigin: header.flowOrigin,
|
|
1638
|
-
metadata: ZlinkStreamMetadataMap.from(header.metadata.values),
|
|
1639
|
-
payloadLength: payload.length,
|
|
1640
|
-
isCompressed: (header.flags & 4 /* PayloadCompressed */) !== 0,
|
|
1641
|
-
receivedAt: /* @__PURE__ */ new Date(),
|
|
1642
|
-
payloadPreview: previewLength === 0 ? new Uint8Array() : payload.slice(0, previewLength)
|
|
1643
|
-
});
|
|
1644
|
-
}
|
|
1645
|
-
scheduleDrain(signal) {
|
|
1646
|
-
if (this.draining) {
|
|
1647
|
-
return;
|
|
1648
|
-
}
|
|
1649
|
-
this.draining = true;
|
|
1650
|
-
queueMicrotask(() => {
|
|
1651
|
-
void this.drain(signal);
|
|
1652
|
-
});
|
|
1653
|
-
}
|
|
1654
|
-
async drain(signal) {
|
|
1655
|
-
try {
|
|
1656
|
-
while (this.queuedCount > 0) {
|
|
1657
|
-
const observation = this.takeObservation();
|
|
1658
|
-
if (observation === void 0) continue;
|
|
1659
|
-
const observers = [...this.observers];
|
|
1660
|
-
for (const observer of observers) {
|
|
1661
|
-
if (!this.observers.has(observer)) {
|
|
1662
|
-
continue;
|
|
1663
|
-
}
|
|
1664
|
-
try {
|
|
1665
|
-
await observer(observation, signal);
|
|
1666
|
-
} catch (cause) {
|
|
1667
|
-
await this.reportObserverFailed(cause, signal);
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
} finally {
|
|
1672
|
-
this.draining = false;
|
|
1673
|
-
if (this.queuedCount > 0) {
|
|
1674
|
-
this.scheduleDrain(signal);
|
|
1675
|
-
}
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
reportDropped(signal) {
|
|
1679
|
-
if (this.dropReportPending) {
|
|
1680
|
-
return;
|
|
1681
|
-
}
|
|
1682
|
-
this.dropReportPending = true;
|
|
1683
|
-
queueMicrotask(() => {
|
|
1684
|
-
void this.events.publishError({
|
|
1685
|
-
code: "observer-dropped" /* ObserverDropped */,
|
|
1686
|
-
message: "Inbound observer notification was dropped because the observer queue is full."
|
|
1687
|
-
}, signal).finally(() => {
|
|
1688
|
-
this.dropReportPending = false;
|
|
1689
|
-
}).catch(() => {
|
|
1690
|
-
});
|
|
1691
|
-
});
|
|
1692
|
-
}
|
|
1693
|
-
async reportObserverFailed(cause, signal) {
|
|
1694
|
-
try {
|
|
1695
|
-
await this.events.publishError({
|
|
1696
|
-
code: "observer-failed" /* ObserverFailed */,
|
|
1697
|
-
message: "Inbound observer callback failed.",
|
|
1698
|
-
cause
|
|
1699
|
-
}, signal);
|
|
1700
|
-
} catch {
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
takeObservation() {
|
|
1704
|
-
while (this.queueHead < this.queue.length && this.queue[this.queueHead] === void 0) {
|
|
1705
|
-
this.queueHead += 1;
|
|
1706
|
-
}
|
|
1707
|
-
const observation = this.queue[this.queueHead];
|
|
1708
|
-
if (observation === void 0) return void 0;
|
|
1709
|
-
this.queue[this.queueHead] = void 0;
|
|
1710
|
-
this.queueHead += 1;
|
|
1711
|
-
this.queuedCount -= 1;
|
|
1712
|
-
if (this.queuedCount === 0) {
|
|
1713
|
-
this.queue.length = 0;
|
|
1714
|
-
this.queueHead = 0;
|
|
1715
|
-
} else if (this.queueHead >= 1024 && this.queueHead * 2 >= this.queue.length) {
|
|
1716
|
-
this.queue.splice(0, this.queueHead);
|
|
1717
|
-
this.queueHead = 0;
|
|
1718
|
-
}
|
|
1719
|
-
return observation;
|
|
1720
|
-
}
|
|
1721
1566
|
};
|
|
1722
1567
|
|
|
1723
1568
|
// packages/stream-connector/src/Runtime/ZlinkStreamFrameSender.ts
|
|
@@ -1780,10 +1625,9 @@ function decodeSessionClosing(payload) {
|
|
|
1780
1625
|
|
|
1781
1626
|
// packages/stream-connector/src/Runtime/ZlinkStreamReceiveDispatcher.ts
|
|
1782
1627
|
var ZlinkStreamReceiveDispatcher = class {
|
|
1783
|
-
constructor(protocol, pendingRequests,
|
|
1628
|
+
constructor(protocol, pendingRequests, receivedMessages, frameSender, events, flowContext, metrics, serverClosing) {
|
|
1784
1629
|
this.protocol = protocol;
|
|
1785
1630
|
this.pendingRequests = pendingRequests;
|
|
1786
|
-
this.inboundObservers = inboundObservers;
|
|
1787
1631
|
this.receivedMessages = receivedMessages;
|
|
1788
1632
|
this.frameSender = frameSender;
|
|
1789
1633
|
this.events = events;
|
|
@@ -1830,7 +1674,6 @@ var ZlinkStreamReceiveDispatcher = class {
|
|
|
1830
1674
|
return { available: true, inbound: true };
|
|
1831
1675
|
}
|
|
1832
1676
|
async dispatch(connection, header, payload, signal, flowEnabled) {
|
|
1833
|
-
this.inboundObservers.enqueue(header, payload, signal);
|
|
1834
1677
|
if (header.kind === 3 /* Response */ && header.requestSeq !== void 0) {
|
|
1835
1678
|
try {
|
|
1836
1679
|
if (!this.pendingRequests.resolve(header.requestSeq, {
|
|
@@ -2560,7 +2403,6 @@ var DefaultZlinkStreamConnector = class {
|
|
|
2560
2403
|
pendingRequests = new ZlinkStreamPendingRequests();
|
|
2561
2404
|
frameSender;
|
|
2562
2405
|
receiveDispatcher;
|
|
2563
|
-
inboundObservers;
|
|
2564
2406
|
diagnosticsLevelCell;
|
|
2565
2407
|
options;
|
|
2566
2408
|
constructor(options) {
|
|
@@ -2575,19 +2417,10 @@ var DefaultZlinkStreamConnector = class {
|
|
|
2575
2417
|
const metrics = new ZlinkStreamRuntimeMetrics(this.options);
|
|
2576
2418
|
const protocol = new ZlinkStreamFrameProtocol(this.options);
|
|
2577
2419
|
this.frameSender = new ZlinkStreamFrameSender(protocol, flowContext, metrics);
|
|
2578
|
-
this.
|
|
2579
|
-
this.options.maxInboundObserverNotifications,
|
|
2580
|
-
this.options.maxInboundObserverPayloadPreviewBytes,
|
|
2581
|
-
this.events
|
|
2582
|
-
);
|
|
2583
|
-
this.receivedMessages = new ZlinkStreamReceivedMessages(
|
|
2584
|
-
this.options.maxReceivedMessages,
|
|
2585
|
-
this.events
|
|
2586
|
-
);
|
|
2420
|
+
this.receivedMessages = new ZlinkStreamReceivedMessages(this.events);
|
|
2587
2421
|
this.receiveDispatcher = new ZlinkStreamReceiveDispatcher(
|
|
2588
2422
|
protocol,
|
|
2589
2423
|
this.pendingRequests,
|
|
2590
|
-
this.inboundObservers,
|
|
2591
2424
|
this.receivedMessages,
|
|
2592
2425
|
this.frameSender,
|
|
2593
2426
|
this.events,
|
|
@@ -2667,12 +2500,6 @@ var DefaultZlinkStreamConnector = class {
|
|
|
2667
2500
|
const encoded = this.encodePayload(payload, messageType);
|
|
2668
2501
|
return new ZlinkStreamRequestBuilder(this, this.resolveNameOrDefault(encoded), encoded);
|
|
2669
2502
|
}
|
|
2670
|
-
observeInbound(observer) {
|
|
2671
|
-
if (this.lifecycle.state !== "created" /* Created */) {
|
|
2672
|
-
throw connectorError("validationFailed" /* ValidationFailed */, "Inbound observers must be registered before connecting.");
|
|
2673
|
-
}
|
|
2674
|
-
return this.inboundObservers.add(observer);
|
|
2675
|
-
}
|
|
2676
2503
|
on(name, handler, messageType) {
|
|
2677
2504
|
const encodedHandler = (message, signal) => handler({
|
|
2678
2505
|
name: message.name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zlink-systems/stream-connector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@zlink-systems/stream-wire": "0.
|
|
24
|
+
"@zlink-systems/stream-wire": "0.14.0"
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Disposable, ZlinkStreamInboundObservation } from '../Contracts';
|
|
2
|
-
import type { ZlinkStreamHeader } from '../Contracts/ZlinkStreamModels';
|
|
3
|
-
import type { ZlinkStreamConnectorEvents } from './ZlinkStreamConnectorEvents';
|
|
4
|
-
type InboundObserver = (observation: ZlinkStreamInboundObservation, signal?: AbortSignal) => Promise<void> | void;
|
|
5
|
-
export declare class ZlinkStreamInboundObservers {
|
|
6
|
-
private readonly maxNotifications;
|
|
7
|
-
private readonly maxPayloadPreviewBytes;
|
|
8
|
-
private readonly events;
|
|
9
|
-
private readonly observers;
|
|
10
|
-
private readonly queue;
|
|
11
|
-
private queueHead;
|
|
12
|
-
private queuedCount;
|
|
13
|
-
private draining;
|
|
14
|
-
private dropReportPending;
|
|
15
|
-
constructor(maxNotifications: number, maxPayloadPreviewBytes: number, events: ZlinkStreamConnectorEvents);
|
|
16
|
-
add(observer: InboundObserver): Disposable;
|
|
17
|
-
enqueue(header: ZlinkStreamHeader, payload: Uint8Array, signal?: AbortSignal): void;
|
|
18
|
-
private createObservation;
|
|
19
|
-
private scheduleDrain;
|
|
20
|
-
private drain;
|
|
21
|
-
private reportDropped;
|
|
22
|
-
private reportObserverFailed;
|
|
23
|
-
private takeObservation;
|
|
24
|
-
}
|
|
25
|
-
export {};
|