@zlink-systems/stream-connector 0.10.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/LICENSE +105 -0
- package/dist/browser/Contracts/Calls/ZlinkStreamCalls.d.ts +35 -0
- package/dist/browser/Contracts/IZlinkStreamConnector.d.ts +38 -0
- package/dist/browser/Contracts/ZlinkStreamConnectorOptions.d.ts +99 -0
- package/dist/browser/Contracts/ZlinkStreamEnums.d.ts +69 -0
- package/dist/browser/Contracts/ZlinkStreamInterfaces.d.ts +3 -0
- package/dist/browser/Contracts/ZlinkStreamJsonCodec.d.ts +12 -0
- package/dist/browser/Contracts/ZlinkStreamMetadata.d.ts +18 -0
- package/dist/browser/Contracts/ZlinkStreamModels.d.ts +68 -0
- package/dist/browser/Contracts/index.d.ts +10 -0
- package/dist/browser/Runtime/Calls/ZlinkStreamCallBuilders.d.ts +48 -0
- package/dist/browser/Runtime/Calls/ZlinkStreamObservationBuilders.d.ts +29 -0
- package/dist/browser/Runtime/Protocol/Compression/ZlinkStreamCompressionCodec.d.ts +5 -0
- package/dist/browser/Runtime/Protocol/ZlinkSessionClosing.d.ts +7 -0
- package/dist/browser/Runtime/Protocol/ZlinkStreamFrameCodec.d.ts +8 -0
- package/dist/browser/Runtime/Protocol/ZlinkStreamFrameProtocol.d.ts +23 -0
- package/dist/browser/Runtime/Protocol/ZlinkStreamHeaderCodec.d.ts +12 -0
- package/dist/browser/Runtime/Protocol/ZlinkStreamMetadataCodec.d.ts +7 -0
- package/dist/browser/Runtime/Protocol/ZlinkStreamPacketNameValidator.d.ts +1 -0
- package/dist/browser/Runtime/Transport/BrowserWebSocketConnection.d.ts +44 -0
- package/dist/browser/Runtime/Transport/ZlinkStreamEndpoint.d.ts +3 -0
- package/dist/browser/Runtime/ZlinkFlowContext.d.ts +15 -0
- package/dist/browser/Runtime/ZlinkStreamAssertions.d.ts +7 -0
- package/dist/browser/Runtime/ZlinkStreamConnector.d.ts +63 -0
- package/dist/browser/Runtime/ZlinkStreamConnectorEvents.d.ts +13 -0
- package/dist/browser/Runtime/ZlinkStreamConnectorLifecycle.d.ts +55 -0
- package/dist/browser/Runtime/ZlinkStreamConnectorOptions.d.ts +3 -0
- package/dist/browser/Runtime/ZlinkStreamDiagnosticsLevelCell.d.ts +16 -0
- package/dist/browser/Runtime/ZlinkStreamFrameSender.d.ts +15 -0
- package/dist/browser/Runtime/ZlinkStreamInboundObservers.d.ts +25 -0
- package/dist/browser/Runtime/ZlinkStreamPendingRequests.d.ts +15 -0
- package/dist/browser/Runtime/ZlinkStreamReceiveDispatcher.d.ts +29 -0
- package/dist/browser/Runtime/ZlinkStreamReceivedMessages.d.ts +24 -0
- package/dist/browser/Runtime/ZlinkStreamRuntimeMetrics.d.ts +17 -0
- package/dist/browser/Runtime/ZlinkStreamSupport.d.ts +16 -0
- package/dist/browser/index.d.ts +8 -0
- package/dist/browser/index.mjs +2893 -0
- package/package.json +20 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ZlinkStreamConnection, ZlinkStreamTransportFactory } from '../../Contracts';
|
|
2
|
+
import type { RequiredZlinkStreamConnectorOptions } from '../../Contracts';
|
|
3
|
+
interface BrowserWebSocketEventMap {
|
|
4
|
+
open: unknown;
|
|
5
|
+
close: unknown;
|
|
6
|
+
error: unknown;
|
|
7
|
+
message: {
|
|
8
|
+
readonly data: unknown;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface BrowserWebSocket {
|
|
12
|
+
binaryType: string;
|
|
13
|
+
readonly readyState: number;
|
|
14
|
+
send(data: Uint8Array): void;
|
|
15
|
+
close(): void;
|
|
16
|
+
addEventListener<TKey extends keyof BrowserWebSocketEventMap>(type: TKey, listener: (event: BrowserWebSocketEventMap[TKey]) => void, options?: {
|
|
17
|
+
readonly once?: boolean;
|
|
18
|
+
}): void;
|
|
19
|
+
removeEventListener<TKey extends keyof BrowserWebSocketEventMap>(type: TKey, listener: (event: BrowserWebSocketEventMap[TKey]) => void): void;
|
|
20
|
+
}
|
|
21
|
+
export declare class BrowserStreamTransportFactory implements ZlinkStreamTransportFactory {
|
|
22
|
+
connect(options: RequiredZlinkStreamConnectorOptions, signal?: AbortSignal): Promise<ZlinkStreamConnection>;
|
|
23
|
+
}
|
|
24
|
+
export declare class BrowserWebSocketConnection implements ZlinkStreamConnection {
|
|
25
|
+
private readonly socket;
|
|
26
|
+
private readonly messages;
|
|
27
|
+
private messageHead;
|
|
28
|
+
private closed;
|
|
29
|
+
private error;
|
|
30
|
+
private readWaiter;
|
|
31
|
+
constructor(socket: BrowserWebSocket);
|
|
32
|
+
write(frame: Uint8Array, signal?: AbortSignal): Promise<void>;
|
|
33
|
+
read(signal?: AbortSignal): Promise<Uint8Array | undefined>;
|
|
34
|
+
close(signal?: AbortSignal): Promise<void>;
|
|
35
|
+
private readonly onMessage;
|
|
36
|
+
private readonly onClose;
|
|
37
|
+
private readonly onError;
|
|
38
|
+
private waitForMessage;
|
|
39
|
+
private wakeReader;
|
|
40
|
+
private removeListeners;
|
|
41
|
+
private hasQueuedMessage;
|
|
42
|
+
private takeMessage;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ZlinkFlowOrigin } from '../Contracts';
|
|
2
|
+
export interface ZlinkFlowContextValue {
|
|
3
|
+
readonly flowId: string;
|
|
4
|
+
readonly flowOrigin: ZlinkFlowOrigin;
|
|
5
|
+
}
|
|
6
|
+
export interface ZlinkFlowContext {
|
|
7
|
+
currentOrCreate(explicit?: ZlinkFlowContextValue): ZlinkFlowContextValue;
|
|
8
|
+
createInbound(flowId?: string, flowOrigin?: ZlinkFlowOrigin): ZlinkFlowContextValue;
|
|
9
|
+
}
|
|
10
|
+
export declare class BrowserZlinkFlowContext implements ZlinkFlowContext {
|
|
11
|
+
currentOrCreate(explicit?: ZlinkFlowContextValue): ZlinkFlowContextValue;
|
|
12
|
+
createInbound(flowId?: string, flowOrigin?: ZlinkFlowOrigin): ZlinkFlowContextValue;
|
|
13
|
+
private createUuidV7;
|
|
14
|
+
}
|
|
15
|
+
export declare function formatUuidV7(bytes: Uint8Array): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ZlinkStreamError } from '../Contracts';
|
|
2
|
+
export interface ZlinkStreamAssertions {
|
|
3
|
+
ensure(condition: boolean, message: string): asserts condition;
|
|
4
|
+
expectFailure(action: (signal?: AbortSignal) => Promise<void>, errorKind?: string): Promise<ZlinkStreamError>;
|
|
5
|
+
expectTimeout(action: (signal?: AbortSignal) => Promise<void>): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export declare const zlinkStreamAssert: ZlinkStreamAssertions;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Disposable, RequiredZlinkStreamConnectorOptions, ZlinkStreamConnectionState, ZlinkStreamConnectionStateChanged, ZlinkStreamConnector, ZlinkStreamConnectorOptions, ZlinkStreamDiagnosticsLevel, ZlinkStreamEncodedPayload, ZlinkStreamError, ZlinkStreamExpectNoneCall, ZlinkStreamFlow, ZlinkStreamInboundObservation, ZlinkStreamMessage, ZlinkStreamMessageKind, ZlinkStreamMetadata, ZlinkStreamRequestCall, ZlinkStreamSendCall, ZlinkStreamSequenceCall, ZlinkStreamWaitCall } from '../Contracts';
|
|
2
|
+
export declare class DefaultZlinkStreamConnector implements ZlinkStreamConnector {
|
|
3
|
+
static readonly heartbeatPingName = "$zlink.heartbeat.ping";
|
|
4
|
+
static readonly heartbeatPongName = "$zlink.heartbeat.pong";
|
|
5
|
+
private readonly receivedMessages;
|
|
6
|
+
private readonly lifecycle;
|
|
7
|
+
private readonly events;
|
|
8
|
+
private correlationCounter;
|
|
9
|
+
private readonly pendingRequests;
|
|
10
|
+
private readonly frameSender;
|
|
11
|
+
private readonly receiveDispatcher;
|
|
12
|
+
private readonly inboundObservers;
|
|
13
|
+
private readonly diagnosticsLevelCell;
|
|
14
|
+
readonly options: RequiredZlinkStreamConnectorOptions;
|
|
15
|
+
constructor(options: ZlinkStreamConnectorOptions);
|
|
16
|
+
get isConnected(): boolean;
|
|
17
|
+
get closeReason(): import("..").ZlinkStreamCloseReason | undefined;
|
|
18
|
+
get state(): ZlinkStreamConnectionState;
|
|
19
|
+
get pendingDispatchCount(): number;
|
|
20
|
+
/**
|
|
21
|
+
* Current diagnostics level (spec 26 §4.1, spec stream-connector 32 §13).
|
|
22
|
+
* Reflects the level set by the most recent {@link setDiagnosticsLevel}
|
|
23
|
+
* call, or the construction-time option (default
|
|
24
|
+
* {@link ZlinkStreamDiagnosticsLevel.Errors}) if it was never changed.
|
|
25
|
+
*/
|
|
26
|
+
get diagnosticsLevel(): ZlinkStreamDiagnosticsLevel;
|
|
27
|
+
/**
|
|
28
|
+
* Changes the diagnostics level in place without recreating the connector
|
|
29
|
+
* (spec 26 §4.1, spec stream-connector 32 §13). The change is an atomic
|
|
30
|
+
* state update: it applies to processing points that read the level after
|
|
31
|
+
* this call returns and is never applied retroactively to frames already
|
|
32
|
+
* built. Rejects unknown values with {@link ZlinkStreamErrorCode.ConfigurationError}.
|
|
33
|
+
* Do not call this synchronous bridge from a framework execution context such
|
|
34
|
+
* as a handler or callback; use setDiagnosticsLevelAsync there.
|
|
35
|
+
*/
|
|
36
|
+
setDiagnosticsLevel(level: ZlinkStreamDiagnosticsLevel): void;
|
|
37
|
+
setDiagnosticsLevelAsync(level: ZlinkStreamDiagnosticsLevel): Promise<void>;
|
|
38
|
+
onErrorReceived(handler: (error: ZlinkStreamError, signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
39
|
+
onDisconnected(handler: (signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
40
|
+
onConnectionStateChanged(handler: (change: ZlinkStreamConnectionStateChanged, signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
41
|
+
connect(signal?: AbortSignal): Promise<void>;
|
|
42
|
+
close(signal?: AbortSignal): Promise<void>;
|
|
43
|
+
dispatch(signal?: AbortSignal): Promise<void>;
|
|
44
|
+
send(payload: unknown, messageType?: Function): ZlinkStreamSendCall;
|
|
45
|
+
request(payload: unknown, messageType?: Function): ZlinkStreamRequestCall;
|
|
46
|
+
observeInbound(observer: (observation: ZlinkStreamInboundObservation, signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
47
|
+
on<TPayload = ZlinkStreamEncodedPayload>(name: string, handler: (message: ZlinkStreamMessage<TPayload>, signal?: AbortSignal) => Promise<void> | void, messageType?: Function): Disposable;
|
|
48
|
+
waitFor<TPayload = ZlinkStreamEncodedPayload>(name: string): ZlinkStreamWaitCall<TPayload>;
|
|
49
|
+
expectNone<TPayload = ZlinkStreamEncodedPayload>(name: string): ZlinkStreamExpectNoneCall<TPayload>;
|
|
50
|
+
waitForSequence<TPayload = ZlinkStreamEncodedPayload>(name: string): ZlinkStreamSequenceCall<TPayload>;
|
|
51
|
+
waitForMessage<TPayload>(name: string, timeoutMs: number, predicate: (message: ZlinkStreamMessage<TPayload>) => boolean, signal?: AbortSignal): Promise<ZlinkStreamMessage<TPayload>>;
|
|
52
|
+
private encodePayload;
|
|
53
|
+
private decodePayload;
|
|
54
|
+
private decodeWaitPayload;
|
|
55
|
+
sendEncoded(kind: ZlinkStreamMessageKind, name: string, payload: ZlinkStreamEncodedPayload, metadata: ZlinkStreamMetadata, compress: boolean, requestSeq: bigint | undefined, signal?: AbortSignal, flow?: ZlinkStreamFlow, correlationId?: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Per-connector monotonic correlation id (hex). The client generates it on each request
|
|
58
|
+
* and the server echoes it back on the reply, so flows can be joined across the wire.
|
|
59
|
+
*/
|
|
60
|
+
private nextCorrelationId;
|
|
61
|
+
requestEncoded(name: string, payload: ZlinkStreamEncodedPayload, metadata: ZlinkStreamMetadata, compress: boolean, timeoutMs: number, signal?: AbortSignal, flow?: ZlinkStreamFlow): Promise<ZlinkStreamEncodedPayload>;
|
|
62
|
+
private resolveNameOrDefault;
|
|
63
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Disposable, ZlinkStreamConnectionStateChanged, ZlinkStreamError } from '../Contracts';
|
|
2
|
+
export declare class ZlinkStreamConnectorEvents {
|
|
3
|
+
private readonly errorHandlers;
|
|
4
|
+
private readonly disconnectedHandlers;
|
|
5
|
+
private readonly stateHandlers;
|
|
6
|
+
onError(handler: (error: ZlinkStreamError, signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
7
|
+
onDisconnected(handler: (signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
8
|
+
onStateChanged(handler: (change: ZlinkStreamConnectionStateChanged, signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
9
|
+
publishError(error: ZlinkStreamError, signal?: AbortSignal): Promise<void>;
|
|
10
|
+
publishDisconnected(signal?: AbortSignal): Promise<void>;
|
|
11
|
+
publishStateChanged(change: ZlinkStreamConnectionStateChanged, signal?: AbortSignal): Promise<void>;
|
|
12
|
+
private publish;
|
|
13
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { RequiredZlinkStreamConnectorOptions, ZlinkStreamConnection } from '../Contracts';
|
|
2
|
+
import { ZlinkStreamConnectionState } from '../Contracts';
|
|
3
|
+
import type { ZlinkStreamCloseReason } from '../Contracts';
|
|
4
|
+
import type { ZlinkStreamConnectorEvents } from './ZlinkStreamConnectorEvents';
|
|
5
|
+
import type { ZlinkStreamFrameSender } from './ZlinkStreamFrameSender';
|
|
6
|
+
import type { ZlinkStreamPendingRequests } from './ZlinkStreamPendingRequests';
|
|
7
|
+
import type { ZlinkStreamReceiveDispatcher } from './ZlinkStreamReceiveDispatcher';
|
|
8
|
+
import type { ZlinkStreamRuntimeMetrics } from './ZlinkStreamRuntimeMetrics';
|
|
9
|
+
export declare class ZlinkStreamConnectorLifecycle {
|
|
10
|
+
private readonly options;
|
|
11
|
+
private readonly pendingRequests;
|
|
12
|
+
private readonly frameSender;
|
|
13
|
+
private readonly receiveDispatcher;
|
|
14
|
+
private readonly events;
|
|
15
|
+
private readonly metrics;
|
|
16
|
+
private receiveLoopAbort;
|
|
17
|
+
private currentConnection;
|
|
18
|
+
private connectionGeneration;
|
|
19
|
+
private currentState;
|
|
20
|
+
private heartbeatTimer;
|
|
21
|
+
private lastInboundAt;
|
|
22
|
+
private closeTask;
|
|
23
|
+
private connectTask;
|
|
24
|
+
private disconnectTask;
|
|
25
|
+
private closeRequested;
|
|
26
|
+
private disconnectedPublished;
|
|
27
|
+
private closeReasonValue?;
|
|
28
|
+
private lateConnectCleanupError;
|
|
29
|
+
constructor(options: RequiredZlinkStreamConnectorOptions, pendingRequests: ZlinkStreamPendingRequests, frameSender: ZlinkStreamFrameSender, receiveDispatcher: ZlinkStreamReceiveDispatcher, events: ZlinkStreamConnectorEvents, metrics: ZlinkStreamRuntimeMetrics);
|
|
30
|
+
get isConnected(): boolean;
|
|
31
|
+
get state(): ZlinkStreamConnectionState;
|
|
32
|
+
get closeReason(): ZlinkStreamCloseReason | undefined;
|
|
33
|
+
connect(signal?: AbortSignal): Promise<void>;
|
|
34
|
+
private connectOnce;
|
|
35
|
+
close(signal?: AbortSignal): Promise<void>;
|
|
36
|
+
serverClosing(reason: ZlinkStreamCloseReason): Promise<void>;
|
|
37
|
+
private closeOnce;
|
|
38
|
+
dispatch(signal?: AbortSignal): Promise<void>;
|
|
39
|
+
connectionForSend(): ZlinkStreamConnection;
|
|
40
|
+
private dispatchAvailable;
|
|
41
|
+
private connectWithReconnect;
|
|
42
|
+
private startHeartbeat;
|
|
43
|
+
private stopHeartbeat;
|
|
44
|
+
private startReceiveLoop;
|
|
45
|
+
private stopReceiveLoop;
|
|
46
|
+
private runReceiveLoop;
|
|
47
|
+
private shouldContinueReceiveLoop;
|
|
48
|
+
private runHeartbeatTick;
|
|
49
|
+
private disconnectForTransportFailure;
|
|
50
|
+
private isCurrentConnection;
|
|
51
|
+
private disconnectOnce;
|
|
52
|
+
private shouldReconnect;
|
|
53
|
+
private publishDisconnectedOnce;
|
|
54
|
+
private setState;
|
|
55
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { RequiredZlinkStreamConnectorOptions, ZlinkStreamConnectorOptions, ZlinkStreamDiagnosticsLevel } from '../Contracts';
|
|
2
|
+
export declare function normalizeOptions(options: ZlinkStreamConnectorOptions, defaultTransportFactory: RequiredZlinkStreamConnectorOptions['transportFactory']): RequiredZlinkStreamConnectorOptions;
|
|
3
|
+
export declare function validateDiagnosticsLevel(level: ZlinkStreamDiagnosticsLevel | undefined): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ZlinkStreamDiagnosticsLevel } from '../Contracts';
|
|
2
|
+
/**
|
|
3
|
+
* Mutable holder for the connector's current diagnostics level (spec 26 §4.1,
|
|
4
|
+
* spec stream-connector 32 §13). The application can read and change the
|
|
5
|
+
* level at runtime without recreating the connector. Each processing point
|
|
6
|
+
* reads {@link level} exactly once and uses that value for the whole
|
|
7
|
+
* operation; the change takes effect for processing points that read the
|
|
8
|
+
* cell after the change and is never applied retroactively to frames already
|
|
9
|
+
* built.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ZlinkStreamDiagnosticsLevelCell {
|
|
12
|
+
private current;
|
|
13
|
+
constructor(initial: ZlinkStreamDiagnosticsLevel);
|
|
14
|
+
get level(): ZlinkStreamDiagnosticsLevel;
|
|
15
|
+
set(level: ZlinkStreamDiagnosticsLevel): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ZlinkStreamConnection, ZlinkStreamEncodedPayload, ZlinkStreamFlow, ZlinkStreamMetadata, ZlinkStreamMessageKind } from '../Contracts';
|
|
2
|
+
import type { ZlinkStreamFrameProtocol } from './Protocol/ZlinkStreamFrameProtocol';
|
|
3
|
+
import type { ZlinkFlowContext } from './ZlinkFlowContext';
|
|
4
|
+
import type { ZlinkStreamRuntimeMetrics } from './ZlinkStreamRuntimeMetrics';
|
|
5
|
+
export declare class ZlinkStreamFrameSender {
|
|
6
|
+
private readonly protocol;
|
|
7
|
+
private readonly flowContext;
|
|
8
|
+
private readonly metrics;
|
|
9
|
+
private readonly pendingWrites;
|
|
10
|
+
constructor(protocol: ZlinkStreamFrameProtocol, flowContext: ZlinkFlowContext, metrics: ZlinkStreamRuntimeMetrics);
|
|
11
|
+
send(connection: ZlinkStreamConnection, kind: ZlinkStreamMessageKind, name: string, payload: ZlinkStreamEncodedPayload, metadata: ZlinkStreamMetadata, compress: boolean, requestSeq: bigint | undefined, signal?: AbortSignal, correlationId?: string, explicitFlow?: ZlinkStreamFlow): Promise<void>;
|
|
12
|
+
sendControl(connection: ZlinkStreamConnection, name: string, signal?: AbortSignal): Promise<void>;
|
|
13
|
+
drain(signal?: AbortSignal): Promise<void>;
|
|
14
|
+
private write;
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ZlinkStreamEncodedPayload, ZlinkStreamError } from '../Contracts';
|
|
2
|
+
export interface PendingZlinkStreamRequest {
|
|
3
|
+
readonly requestSeq: bigint;
|
|
4
|
+
readonly promise: Promise<ZlinkStreamEncodedPayload>;
|
|
5
|
+
}
|
|
6
|
+
export declare class ZlinkStreamPendingRequests {
|
|
7
|
+
private nextRequestSeq;
|
|
8
|
+
private readonly active;
|
|
9
|
+
get count(): number;
|
|
10
|
+
create(packetName: string, timeoutMs: number): PendingZlinkStreamRequest;
|
|
11
|
+
resolve(requestSeq: bigint, value: ZlinkStreamEncodedPayload): boolean;
|
|
12
|
+
reject(requestSeq: bigint, error: ZlinkStreamError): boolean;
|
|
13
|
+
cancel(requestSeq: bigint): void;
|
|
14
|
+
failAll(error: ZlinkStreamError): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ZlinkStreamConnection } from '../Contracts';
|
|
2
|
+
import type { ZlinkStreamFrameProtocol } from './Protocol/ZlinkStreamFrameProtocol';
|
|
3
|
+
import type { ZlinkStreamConnectorEvents } from './ZlinkStreamConnectorEvents';
|
|
4
|
+
import type { ZlinkStreamFrameSender } from './ZlinkStreamFrameSender';
|
|
5
|
+
import type { ZlinkStreamInboundObservers } from './ZlinkStreamInboundObservers';
|
|
6
|
+
import type { ZlinkStreamPendingRequests } from './ZlinkStreamPendingRequests';
|
|
7
|
+
import type { ZlinkStreamReceivedMessages } from './ZlinkStreamReceivedMessages';
|
|
8
|
+
import type { ZlinkFlowContext } from './ZlinkFlowContext';
|
|
9
|
+
import type { ZlinkStreamCloseReason } from '../Contracts';
|
|
10
|
+
import type { ZlinkStreamRuntimeMetrics } from './ZlinkStreamRuntimeMetrics';
|
|
11
|
+
export interface ZlinkStreamReceiveResult {
|
|
12
|
+
readonly available: boolean;
|
|
13
|
+
readonly inbound: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare class ZlinkStreamReceiveDispatcher {
|
|
16
|
+
private readonly protocol;
|
|
17
|
+
private readonly pendingRequests;
|
|
18
|
+
private readonly inboundObservers;
|
|
19
|
+
private readonly receivedMessages;
|
|
20
|
+
private readonly frameSender;
|
|
21
|
+
private readonly events;
|
|
22
|
+
private readonly flowContext;
|
|
23
|
+
private readonly metrics;
|
|
24
|
+
private readonly serverClosing?;
|
|
25
|
+
constructor(protocol: ZlinkStreamFrameProtocol, pendingRequests: ZlinkStreamPendingRequests, inboundObservers: ZlinkStreamInboundObservers, receivedMessages: ZlinkStreamReceivedMessages, frameSender: ZlinkStreamFrameSender, events: ZlinkStreamConnectorEvents, flowContext: ZlinkFlowContext, metrics: ZlinkStreamRuntimeMetrics, serverClosing?: ((reason: ZlinkStreamCloseReason) => Promise<void>) | undefined);
|
|
26
|
+
readAndDispatch(connection: ZlinkStreamConnection | undefined, signal?: AbortSignal, isCurrent?: () => boolean): Promise<ZlinkStreamReceiveResult>;
|
|
27
|
+
private dispatch;
|
|
28
|
+
private dispatchControl;
|
|
29
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Disposable, ZlinkStreamEncodedPayload, ZlinkStreamMessage } from '../Contracts';
|
|
2
|
+
import type { ZlinkStreamConnectorEvents } from './ZlinkStreamConnectorEvents';
|
|
3
|
+
type EncodedMessageHandler = (message: ZlinkStreamMessage<ZlinkStreamEncodedPayload>, signal?: AbortSignal) => Promise<void> | void;
|
|
4
|
+
export declare class ZlinkStreamReceivedMessages {
|
|
5
|
+
private readonly capacity;
|
|
6
|
+
private readonly events;
|
|
7
|
+
private readonly handlers;
|
|
8
|
+
private readonly queue;
|
|
9
|
+
private queueHead;
|
|
10
|
+
private queuedCount;
|
|
11
|
+
private drainTask;
|
|
12
|
+
private dropReportPending;
|
|
13
|
+
constructor(capacity: number, events: ZlinkStreamConnectorEvents);
|
|
14
|
+
on(name: string, handler: EncodedMessageHandler): Disposable;
|
|
15
|
+
enqueue(message: ZlinkStreamMessage<ZlinkStreamEncodedPayload>, signal?: AbortSignal): void;
|
|
16
|
+
private scheduleDrain;
|
|
17
|
+
private drain;
|
|
18
|
+
private findDeliverableIndex;
|
|
19
|
+
private hasQueuedMessage;
|
|
20
|
+
private advanceHead;
|
|
21
|
+
private compactQueue;
|
|
22
|
+
private reportDropped;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RequiredZlinkStreamConnectorOptions } from '../Contracts';
|
|
2
|
+
export declare class ZlinkStreamRuntimeMetrics {
|
|
3
|
+
private readonly options;
|
|
4
|
+
private readonly reconnects;
|
|
5
|
+
private readonly handshakeDuration;
|
|
6
|
+
private readonly handshakeFailures;
|
|
7
|
+
private readonly inboundBytes;
|
|
8
|
+
private readonly outboundBytes;
|
|
9
|
+
constructor(options: RequiredZlinkStreamConnectorOptions);
|
|
10
|
+
reconnect(): void;
|
|
11
|
+
handshakeCompleted(startedAt: number): void;
|
|
12
|
+
handshakeFailed(error: unknown): void;
|
|
13
|
+
inbound(byteCount: number): void;
|
|
14
|
+
outbound(byteCount: number): void;
|
|
15
|
+
private transportLabel;
|
|
16
|
+
private safe;
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Disposable, ZlinkStreamError, ZlinkStreamErrorCode, ZlinkStreamException } from '../Contracts';
|
|
2
|
+
export declare function connectorError(code: ZlinkStreamErrorCode, message: string, cause?: unknown): ZlinkStreamException;
|
|
3
|
+
export declare function toStreamError(cause: unknown, code: ZlinkStreamErrorCode, message: string): ZlinkStreamError;
|
|
4
|
+
export declare function unwrapStreamError(error: unknown): ZlinkStreamError;
|
|
5
|
+
export declare function subscription(dispose: () => void): Disposable;
|
|
6
|
+
export declare function throwIfAborted(signal: AbortSignal | undefined): void;
|
|
7
|
+
export declare function delay(delayMs: number, signal: AbortSignal | undefined): Promise<void>;
|
|
8
|
+
export declare function readLength(source: Uint8Array, offset: number, bytes: 1 | 2, label: string): number;
|
|
9
|
+
export declare function writeUInt16BE(destination: Uint8Array, offset: number, value: number): void;
|
|
10
|
+
export declare function writeUInt32BE(destination: Uint8Array, offset: number, value: number): void;
|
|
11
|
+
export declare function readUInt16BE(source: Uint8Array, offset: number): number;
|
|
12
|
+
export declare function readUInt32BE(source: Uint8Array, offset: number): number;
|
|
13
|
+
export declare function writeBigUInt64BE(destination: Uint8Array, offset: number, value: bigint): void;
|
|
14
|
+
export declare function readBigUInt64BE(source: Uint8Array, offset: number): bigint;
|
|
15
|
+
export declare function utf8Encode(value: string): Uint8Array;
|
|
16
|
+
export declare function utf8Decode(value: Uint8Array): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './Contracts';
|
|
2
|
+
export { DefaultZlinkStreamConnector, } from './Runtime/ZlinkStreamConnector';
|
|
3
|
+
export { zlinkStreamAssert } from './Runtime/ZlinkStreamAssertions';
|
|
4
|
+
import { DefaultZlinkStreamConnector } from './Runtime/ZlinkStreamConnector';
|
|
5
|
+
import type { ZlinkStreamConnectorOptions } from './Contracts';
|
|
6
|
+
export declare const zlinkStreamConnectorFactory: {
|
|
7
|
+
create(options: ZlinkStreamConnectorOptions): DefaultZlinkStreamConnector;
|
|
8
|
+
};
|