@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
package/LICENSE
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-ALv2
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 ZLink Systems
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ZlinkStreamMetadata } from '../ZlinkStreamMetadata';
|
|
2
|
+
import type { ZlinkStreamEncodedPayload, ZlinkStreamFlow, ZlinkStreamMessage, ZlinkStreamResultOf } from '../ZlinkStreamModels';
|
|
3
|
+
export interface ZlinkStreamSendCall {
|
|
4
|
+
packetName(name: string): ZlinkStreamSendCall;
|
|
5
|
+
metadata(key: string, value: string): ZlinkStreamSendCall;
|
|
6
|
+
metadata(metadata: ZlinkStreamMetadata): ZlinkStreamSendCall;
|
|
7
|
+
compress(): ZlinkStreamSendCall;
|
|
8
|
+
flowFrom(flow: ZlinkStreamFlow): ZlinkStreamSendCall;
|
|
9
|
+
submit(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export interface ZlinkStreamRequestCall {
|
|
12
|
+
packetName(name: string): ZlinkStreamRequestCall;
|
|
13
|
+
metadata(key: string, value: string): ZlinkStreamRequestCall;
|
|
14
|
+
metadata(metadata: ZlinkStreamMetadata): ZlinkStreamRequestCall;
|
|
15
|
+
timeout(timeoutMs: number): ZlinkStreamRequestCall;
|
|
16
|
+
compress(): ZlinkStreamRequestCall;
|
|
17
|
+
flowFrom(flow: ZlinkStreamFlow): ZlinkStreamRequestCall;
|
|
18
|
+
submit<TReply = unknown>(signal?: AbortSignal): Promise<TReply>;
|
|
19
|
+
submitEncoded(signal?: AbortSignal): Promise<ZlinkStreamEncodedPayload>;
|
|
20
|
+
submit(callback: (result: ZlinkStreamResultOf<ZlinkStreamEncodedPayload>) => void): void;
|
|
21
|
+
}
|
|
22
|
+
export interface ZlinkStreamWaitCall<TPayload = ZlinkStreamEncodedPayload> {
|
|
23
|
+
where(predicate: (message: ZlinkStreamMessage<TPayload>) => boolean): ZlinkStreamWaitCall<TPayload>;
|
|
24
|
+
timeout(timeoutMs: number): ZlinkStreamWaitCall<TPayload>;
|
|
25
|
+
submit(signal?: AbortSignal): Promise<ZlinkStreamMessage<TPayload>>;
|
|
26
|
+
}
|
|
27
|
+
export interface ZlinkStreamExpectNoneCall<TPayload = ZlinkStreamEncodedPayload> {
|
|
28
|
+
within(windowMs: number): ZlinkStreamExpectNoneCall<TPayload>;
|
|
29
|
+
run(signal?: AbortSignal): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export interface ZlinkStreamSequenceCall<TPayload = ZlinkStreamEncodedPayload> {
|
|
32
|
+
expect(predicate: (payload: TPayload) => boolean): ZlinkStreamSequenceCall<TPayload>;
|
|
33
|
+
timeout(timeoutMs: number): ZlinkStreamSequenceCall<TPayload>;
|
|
34
|
+
run(signal?: AbortSignal): Promise<readonly TPayload[]>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Disposable } from './ZlinkStreamInterfaces';
|
|
2
|
+
import type { RequiredZlinkStreamConnectorOptions } from './ZlinkStreamConnectorOptions';
|
|
3
|
+
import type { ZlinkStreamRequestCall, ZlinkStreamSendCall, ZlinkStreamExpectNoneCall, ZlinkStreamSequenceCall, ZlinkStreamWaitCall } from './Calls/ZlinkStreamCalls';
|
|
4
|
+
import type { ZlinkStreamConnectionStateChanged, ZlinkStreamEncodedPayload, ZlinkStreamError, ZlinkStreamInboundObservation, ZlinkStreamMessage } from './ZlinkStreamModels';
|
|
5
|
+
import type { ZlinkStreamCloseReason, ZlinkStreamConnectionState, ZlinkStreamDiagnosticsLevel } from './ZlinkStreamEnums';
|
|
6
|
+
export interface ZlinkStreamConnector {
|
|
7
|
+
readonly isConnected: boolean;
|
|
8
|
+
readonly state: ZlinkStreamConnectionState;
|
|
9
|
+
readonly closeReason?: ZlinkStreamCloseReason;
|
|
10
|
+
readonly options: RequiredZlinkStreamConnectorOptions;
|
|
11
|
+
readonly pendingDispatchCount: number;
|
|
12
|
+
/**
|
|
13
|
+
* Current diagnostics level (spec 26 §4.1, spec stream-connector 32 §13).
|
|
14
|
+
* Always equal to `options.diagnosticsLevel`.
|
|
15
|
+
*/
|
|
16
|
+
readonly diagnosticsLevel: ZlinkStreamDiagnosticsLevel;
|
|
17
|
+
/**
|
|
18
|
+
* Changes the diagnostics level at runtime without recreating the
|
|
19
|
+
* connector (spec 26 §4.1, spec stream-connector 32 §13). Applies to
|
|
20
|
+
* processing points that read the level after this call returns; never
|
|
21
|
+
* applied retroactively to frames already built. Rejects unknown values
|
|
22
|
+
* with {@link import('./ZlinkStreamEnums').ZlinkStreamErrorCode.ConfigurationError}.
|
|
23
|
+
*/
|
|
24
|
+
setDiagnosticsLevel(level: ZlinkStreamDiagnosticsLevel): void;
|
|
25
|
+
onErrorReceived(handler: (error: ZlinkStreamError, signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
26
|
+
onDisconnected(handler: (signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
27
|
+
onConnectionStateChanged(handler: (change: ZlinkStreamConnectionStateChanged, signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
28
|
+
connect(signal?: AbortSignal): Promise<void>;
|
|
29
|
+
close(signal?: AbortSignal): Promise<void>;
|
|
30
|
+
dispatch(signal?: AbortSignal): Promise<void>;
|
|
31
|
+
send(payload: unknown, messageType?: Function): ZlinkStreamSendCall;
|
|
32
|
+
request(payload: unknown, messageType?: Function): ZlinkStreamRequestCall;
|
|
33
|
+
observeInbound(observer: (observation: ZlinkStreamInboundObservation, signal?: AbortSignal) => Promise<void> | void): Disposable;
|
|
34
|
+
on<TPayload = ZlinkStreamEncodedPayload>(name: string, handler: (message: ZlinkStreamMessage<TPayload>, signal?: AbortSignal) => Promise<void> | void, messageType?: Function): Disposable;
|
|
35
|
+
waitFor<TPayload = ZlinkStreamEncodedPayload>(name: string): ZlinkStreamWaitCall<TPayload>;
|
|
36
|
+
expectNone<TPayload = ZlinkStreamEncodedPayload>(name: string): ZlinkStreamExpectNoneCall<TPayload>;
|
|
37
|
+
waitForSequence<TPayload = ZlinkStreamEncodedPayload>(name: string): ZlinkStreamSequenceCall<TPayload>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { ZlinkStreamCompression, ZlinkStreamDiagnosticsLevel, ZlinkStreamDispatchMode, ZlinkStreamTransport } from './ZlinkStreamEnums';
|
|
2
|
+
import type { ZlinkStreamEncodedPayload } from './ZlinkStreamModels';
|
|
3
|
+
export interface ZlinkStreamConnectorOptions {
|
|
4
|
+
readonly endpoint: string;
|
|
5
|
+
readonly codec?: ZlinkStreamPayloadCodec;
|
|
6
|
+
readonly transport?: ZlinkStreamTransport;
|
|
7
|
+
readonly transportFactory?: ZlinkStreamTransportFactory;
|
|
8
|
+
readonly connectTimeoutMs?: number;
|
|
9
|
+
readonly requestTimeoutMs?: number;
|
|
10
|
+
readonly waitTimeoutMs?: number;
|
|
11
|
+
readonly heartbeat?: ZlinkStreamHeartbeatOptions;
|
|
12
|
+
readonly reconnect?: ZlinkStreamReconnectOptions;
|
|
13
|
+
readonly maxSendPayloadSize?: number;
|
|
14
|
+
readonly maxReceivePayloadSize?: number;
|
|
15
|
+
readonly maxReceivedMessages?: number;
|
|
16
|
+
readonly maxInboundObserverNotifications?: number;
|
|
17
|
+
readonly maxInboundObserverPayloadPreviewBytes?: number;
|
|
18
|
+
readonly dispatchMode?: ZlinkStreamDispatchMode;
|
|
19
|
+
readonly compression?: ZlinkStreamCompression;
|
|
20
|
+
readonly compressionCodec?: ZlinkStreamCompressionCodec;
|
|
21
|
+
readonly nameResolver?: ZlinkStreamPacketNameResolver;
|
|
22
|
+
readonly meterProvider?: ZlinkStreamMeterProvider;
|
|
23
|
+
/**
|
|
24
|
+
* Initial diagnostics level (spec 26 §4); defaults to
|
|
25
|
+
* {@link ZlinkStreamDiagnosticsLevel.Errors}, which preserves the current
|
|
26
|
+
* wire behavior. `Off` suppresses all observation-only flow handling
|
|
27
|
+
* (spec 27 §4). This is only the level at construction time — spec 26
|
|
28
|
+
* §4.1 / spec stream-connector 32 §13 require runtime read/write, provided
|
|
29
|
+
* by `ZlinkStreamConnector.diagnosticsLevel` / `setDiagnosticsLevel(...)`.
|
|
30
|
+
*/
|
|
31
|
+
readonly diagnosticsLevel?: ZlinkStreamDiagnosticsLevel;
|
|
32
|
+
}
|
|
33
|
+
export interface ZlinkStreamMeterProvider {
|
|
34
|
+
getMeter(name: string): {
|
|
35
|
+
createCounter(name: string, options?: {
|
|
36
|
+
readonly unit?: string;
|
|
37
|
+
}): {
|
|
38
|
+
add(value: number, attributes?: Readonly<Record<string, string | number | boolean>>): void;
|
|
39
|
+
};
|
|
40
|
+
createHistogram(name: string, options?: {
|
|
41
|
+
readonly unit?: string;
|
|
42
|
+
}): {
|
|
43
|
+
record(value: number, attributes?: Readonly<Record<string, string | number | boolean>>): void;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export interface ZlinkStreamHeartbeatOptions {
|
|
48
|
+
readonly enabled?: boolean;
|
|
49
|
+
readonly intervalMs?: number;
|
|
50
|
+
readonly timeoutMs?: number;
|
|
51
|
+
}
|
|
52
|
+
export interface ZlinkStreamReconnectOptions {
|
|
53
|
+
readonly enabled?: boolean;
|
|
54
|
+
readonly initialDelayMs?: number;
|
|
55
|
+
readonly maxDelayMs?: number;
|
|
56
|
+
readonly backoffFactor?: number;
|
|
57
|
+
readonly maxAttempts?: number;
|
|
58
|
+
}
|
|
59
|
+
export interface ZlinkStreamPacketNameResolver {
|
|
60
|
+
resolve(payloadType: Function): string;
|
|
61
|
+
}
|
|
62
|
+
export interface ZlinkStreamPayloadCodec {
|
|
63
|
+
encode(payload: unknown, messageType?: Function): ZlinkStreamEncodedPayload;
|
|
64
|
+
decode<T = unknown>(payload: ZlinkStreamEncodedPayload, messageType?: Function): T;
|
|
65
|
+
}
|
|
66
|
+
export interface ZlinkStreamCompressionCodec {
|
|
67
|
+
compress(payload: Uint8Array): Uint8Array;
|
|
68
|
+
decompress(payload: Uint8Array, maxDecompressedSize: number): Uint8Array;
|
|
69
|
+
}
|
|
70
|
+
export interface ZlinkStreamTransportFactory {
|
|
71
|
+
connect(options: RequiredZlinkStreamConnectorOptions, signal?: AbortSignal): Promise<ZlinkStreamConnection>;
|
|
72
|
+
}
|
|
73
|
+
export interface ZlinkStreamConnection {
|
|
74
|
+
write(frame: Uint8Array, signal?: AbortSignal): Promise<void>;
|
|
75
|
+
read?(signal?: AbortSignal): Promise<Uint8Array | undefined>;
|
|
76
|
+
close(signal?: AbortSignal): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
export interface RequiredZlinkStreamConnectorOptions {
|
|
79
|
+
readonly endpoint: string;
|
|
80
|
+
readonly transport: ZlinkStreamTransport;
|
|
81
|
+
readonly connectTimeoutMs: number;
|
|
82
|
+
readonly requestTimeoutMs: number;
|
|
83
|
+
readonly waitTimeoutMs: number;
|
|
84
|
+
readonly heartbeat: Required<ZlinkStreamHeartbeatOptions>;
|
|
85
|
+
readonly reconnect: Required<ZlinkStreamReconnectOptions>;
|
|
86
|
+
readonly maxSendPayloadSize: number;
|
|
87
|
+
readonly maxReceivePayloadSize: number;
|
|
88
|
+
readonly maxReceivedMessages: number;
|
|
89
|
+
readonly maxInboundObserverNotifications: number;
|
|
90
|
+
readonly maxInboundObserverPayloadPreviewBytes: number;
|
|
91
|
+
readonly dispatchMode: ZlinkStreamDispatchMode;
|
|
92
|
+
readonly compression: ZlinkStreamCompression;
|
|
93
|
+
readonly compressionCodec?: ZlinkStreamCompressionCodec;
|
|
94
|
+
readonly nameResolver: ZlinkStreamPacketNameResolver;
|
|
95
|
+
readonly transportFactory: ZlinkStreamTransportFactory;
|
|
96
|
+
readonly codec?: ZlinkStreamPayloadCodec;
|
|
97
|
+
readonly meterProvider?: ZlinkStreamMeterProvider;
|
|
98
|
+
readonly diagnosticsLevel: ZlinkStreamDiagnosticsLevel;
|
|
99
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export declare enum ZlinkStreamTransport {
|
|
2
|
+
WebSocket = "webSocket",
|
|
3
|
+
WebSocketSecure = "webSocketSecure"
|
|
4
|
+
}
|
|
5
|
+
export { ZlinkStreamCodec } from '@zlink-systems/stream-wire';
|
|
6
|
+
export declare enum ZlinkStreamCompression {
|
|
7
|
+
None = "none",
|
|
8
|
+
Lz4 = "lz4"
|
|
9
|
+
}
|
|
10
|
+
export declare enum ZlinkStreamDispatchMode {
|
|
11
|
+
Manual = "manual",
|
|
12
|
+
Immediate = "immediate"
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Connector diagnostics level (spec 26 §4). `Errors` is the default and
|
|
16
|
+
* preserves the connector's established wire behavior (outbound frames carry
|
|
17
|
+
* the flow pair). `Off` applies spec 27 §4: no flow id is generated or
|
|
18
|
+
* attached to outbound frames (header flag 0x10 stays clear), inbound flow
|
|
19
|
+
* fields are neither validated nor installed into received messages
|
|
20
|
+
* (structural length checks are kept), and no trace-only work runs.
|
|
21
|
+
*/
|
|
22
|
+
export declare enum ZlinkStreamDiagnosticsLevel {
|
|
23
|
+
Off = "off",
|
|
24
|
+
Errors = "errors",
|
|
25
|
+
Normal = "normal",
|
|
26
|
+
Detailed = "detailed"
|
|
27
|
+
}
|
|
28
|
+
export declare enum ZlinkStreamMessageKind {
|
|
29
|
+
Send = 1,
|
|
30
|
+
Request = 2,
|
|
31
|
+
Response = 3,
|
|
32
|
+
Error = 4,
|
|
33
|
+
Control = 5
|
|
34
|
+
}
|
|
35
|
+
export declare enum ZlinkStreamHeaderFlags {
|
|
36
|
+
None = 0,
|
|
37
|
+
HasRequestSeq = 1,
|
|
38
|
+
HasMetadata = 2,
|
|
39
|
+
PayloadCompressed = 4,
|
|
40
|
+
HasCorrelationId = 8,
|
|
41
|
+
HasFlowId = 16
|
|
42
|
+
}
|
|
43
|
+
export type ZlinkFlowOrigin = 'Inbound' | 'Timer' | 'Application' | 'Lifecycle';
|
|
44
|
+
export type ZlinkStreamCloseReason = 'ClientClose' | 'IdleTimeout' | 'HeartbeatTimeout' | 'ServerDrain' | 'ProtocolError' | 'TransportError';
|
|
45
|
+
export declare enum ZlinkStreamErrorCode {
|
|
46
|
+
Disconnected = "disconnected",
|
|
47
|
+
ConfigurationError = "configurationError",
|
|
48
|
+
ValidationFailed = "validationFailed",
|
|
49
|
+
RequestTimeout = "requestTimeout",
|
|
50
|
+
ConnectTimeout = "connectTimeout",
|
|
51
|
+
FrameDecodeFailed = "frameDecodeFailed",
|
|
52
|
+
FrameTooLarge = "frameTooLarge",
|
|
53
|
+
SendFailed = "sendFailed",
|
|
54
|
+
CompressionFailed = "compressionFailed",
|
|
55
|
+
DecompressionFailed = "decompressionFailed",
|
|
56
|
+
UserCallbackFailed = "userCallbackFailed",
|
|
57
|
+
ObserverFailed = "observer-failed",
|
|
58
|
+
ObserverDropped = "observer-dropped",
|
|
59
|
+
ReceivedMessageDropped = "received-message-dropped",
|
|
60
|
+
RemoteError = "remoteError"
|
|
61
|
+
}
|
|
62
|
+
export declare enum ZlinkStreamConnectionState {
|
|
63
|
+
Created = "created",
|
|
64
|
+
Connecting = "connecting",
|
|
65
|
+
Connected = "connected",
|
|
66
|
+
Reconnecting = "reconnecting",
|
|
67
|
+
Disconnected = "disconnected",
|
|
68
|
+
Closed = "closed"
|
|
69
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ZlinkStreamPayloadCodec } from './ZlinkStreamConnectorOptions';
|
|
2
|
+
import type { ZlinkStreamEncodedPayload } from './ZlinkStreamModels';
|
|
3
|
+
export declare const zlinkStreamJsonCodecName = "json";
|
|
4
|
+
export interface ZlinkStreamJsonCodecOptions {
|
|
5
|
+
readonly replacer?: (this: unknown, key: string, value: unknown) => unknown;
|
|
6
|
+
readonly reviver?: (this: unknown, key: string, value: unknown) => unknown;
|
|
7
|
+
}
|
|
8
|
+
export declare const zlinkStreamJsonCodec: ZlinkStreamPayloadCodec & {
|
|
9
|
+
configure(options: ZlinkStreamJsonCodecOptions): void;
|
|
10
|
+
};
|
|
11
|
+
export declare function toJson<T>(value: T, messageType?: Function): ZlinkStreamEncodedPayload;
|
|
12
|
+
export declare function fromJson<T>(payload: ZlinkStreamEncodedPayload): T;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ZlinkStreamMetadata {
|
|
2
|
+
readonly count: number;
|
|
3
|
+
readonly values: ReadonlyMap<string, string>;
|
|
4
|
+
get(key: string): string | undefined;
|
|
5
|
+
with(key: string, value: string): ZlinkStreamMetadata;
|
|
6
|
+
withMany(values: Iterable<readonly [string, string]>): ZlinkStreamMetadata;
|
|
7
|
+
}
|
|
8
|
+
export declare class ZlinkStreamMetadataMap implements ZlinkStreamMetadata {
|
|
9
|
+
readonly values: ReadonlyMap<string, string>;
|
|
10
|
+
static readonly empty: ZlinkStreamMetadata;
|
|
11
|
+
private constructor();
|
|
12
|
+
get count(): number;
|
|
13
|
+
get(key: string): string | undefined;
|
|
14
|
+
with(key: string, value: string): ZlinkStreamMetadata;
|
|
15
|
+
withMany(values: Iterable<readonly [string, string]>): ZlinkStreamMetadata;
|
|
16
|
+
static from(values: Iterable<readonly [string, string]>): ZlinkStreamMetadata;
|
|
17
|
+
}
|
|
18
|
+
export declare function validateMetadataKey(key: string): void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ZlinkStreamCodec, ZlinkStreamConnectionState, ZlinkStreamErrorCode, ZlinkStreamHeaderFlags, ZlinkStreamMessageKind, ZlinkFlowOrigin } from './ZlinkStreamEnums';
|
|
2
|
+
import type { ZlinkStreamMetadata } from './ZlinkStreamMetadata';
|
|
3
|
+
export interface ZlinkStreamEncodedPayload {
|
|
4
|
+
readonly codec: ZlinkStreamCodec;
|
|
5
|
+
readonly payload: Uint8Array;
|
|
6
|
+
readonly messageType?: Function;
|
|
7
|
+
}
|
|
8
|
+
export interface ZlinkStreamFlow {
|
|
9
|
+
readonly flowId: string;
|
|
10
|
+
readonly flowOrigin: ZlinkFlowOrigin;
|
|
11
|
+
}
|
|
12
|
+
export interface ZlinkStreamMessage<TPayload = unknown> {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly metadata: ZlinkStreamMetadata;
|
|
15
|
+
readonly payload: TPayload;
|
|
16
|
+
/**
|
|
17
|
+
* Present while diagnostics are enabled (the default). With
|
|
18
|
+
* `diagnosticsLevel: Off` inbound flow fields are neither read nor
|
|
19
|
+
* installed (spec 27 §4), so delivered messages carry no flow pair.
|
|
20
|
+
*/
|
|
21
|
+
readonly flowId?: string;
|
|
22
|
+
readonly flowOrigin?: ZlinkFlowOrigin;
|
|
23
|
+
}
|
|
24
|
+
export interface ZlinkStreamHeader {
|
|
25
|
+
readonly kind: ZlinkStreamMessageKind;
|
|
26
|
+
readonly codec: ZlinkStreamCodec;
|
|
27
|
+
readonly flags: ZlinkStreamHeaderFlags;
|
|
28
|
+
readonly requestSeq?: bigint;
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly metadata: ZlinkStreamMetadata;
|
|
31
|
+
readonly correlationId?: string;
|
|
32
|
+
readonly flowId?: string;
|
|
33
|
+
readonly flowOrigin?: ZlinkFlowOrigin;
|
|
34
|
+
}
|
|
35
|
+
export interface ZlinkStreamError {
|
|
36
|
+
readonly code: ZlinkStreamErrorCode;
|
|
37
|
+
readonly message: string;
|
|
38
|
+
readonly cause?: unknown;
|
|
39
|
+
}
|
|
40
|
+
export interface ZlinkStreamConnectionStateChanged {
|
|
41
|
+
readonly previous: ZlinkStreamConnectionState;
|
|
42
|
+
readonly current: ZlinkStreamConnectionState;
|
|
43
|
+
readonly error?: ZlinkStreamError;
|
|
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
|
+
export interface ZlinkStreamResult {
|
|
59
|
+
readonly isSuccess: boolean;
|
|
60
|
+
readonly error?: ZlinkStreamError;
|
|
61
|
+
}
|
|
62
|
+
export interface ZlinkStreamResultOf<T> extends ZlinkStreamResult {
|
|
63
|
+
readonly value?: T;
|
|
64
|
+
}
|
|
65
|
+
export declare class ZlinkStreamException extends Error {
|
|
66
|
+
readonly error: ZlinkStreamError;
|
|
67
|
+
constructor(error: ZlinkStreamError);
|
|
68
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { ZlinkStreamTransport, ZlinkStreamCodec, ZlinkStreamCompression, ZlinkStreamDiagnosticsLevel, ZlinkStreamDispatchMode, ZlinkStreamMessageKind, ZlinkStreamHeaderFlags, ZlinkStreamErrorCode, ZlinkStreamConnectionState } from './ZlinkStreamEnums';
|
|
2
|
+
export type { ZlinkFlowOrigin, ZlinkStreamCloseReason } from './ZlinkStreamEnums';
|
|
3
|
+
export * from './ZlinkStreamConnectorOptions';
|
|
4
|
+
export * from './ZlinkStreamInterfaces';
|
|
5
|
+
export * from './ZlinkStreamMetadata';
|
|
6
|
+
export type { ZlinkStreamEncodedPayload, ZlinkStreamFlow, ZlinkStreamMessage, ZlinkStreamError, ZlinkStreamConnectionStateChanged, ZlinkStreamInboundObservation, ZlinkStreamResult, ZlinkStreamResultOf } from './ZlinkStreamModels';
|
|
7
|
+
export { ZlinkStreamException } from './ZlinkStreamModels';
|
|
8
|
+
export * from './ZlinkStreamJsonCodec';
|
|
9
|
+
export * from './IZlinkStreamConnector';
|
|
10
|
+
export * from './Calls/ZlinkStreamCalls';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RequiredZlinkStreamConnectorOptions, ZlinkStreamEncodedPayload, ZlinkStreamFlow, ZlinkStreamMessage, ZlinkStreamMessageKind, ZlinkStreamMetadata, type ZlinkStreamRequestCall, type ZlinkStreamResultOf, type ZlinkStreamSendCall, type ZlinkStreamWaitCall } from '../../Contracts';
|
|
2
|
+
interface ZlinkStreamConnectorSubmitter {
|
|
3
|
+
readonly options: RequiredZlinkStreamConnectorOptions;
|
|
4
|
+
sendEncoded(kind: ZlinkStreamMessageKind, name: string, payload: ZlinkStreamEncodedPayload, metadata: ZlinkStreamMetadata, compress: boolean, requestSeq: bigint | undefined, signal?: AbortSignal, flow?: ZlinkStreamFlow): Promise<void>;
|
|
5
|
+
requestEncoded(name: string, payload: ZlinkStreamEncodedPayload, metadata: ZlinkStreamMetadata, compress: boolean, timeoutMs: number, signal?: AbortSignal, flow?: ZlinkStreamFlow): Promise<ZlinkStreamEncodedPayload>;
|
|
6
|
+
waitForMessage<TPayload>(name: string, timeoutMs: number, predicate: (message: ZlinkStreamMessage<TPayload>) => boolean, signal?: AbortSignal): Promise<ZlinkStreamMessage<TPayload>>;
|
|
7
|
+
}
|
|
8
|
+
export declare class ZlinkStreamSendBuilder implements ZlinkStreamSendCall {
|
|
9
|
+
private readonly connector;
|
|
10
|
+
private readonly payload;
|
|
11
|
+
private readonly state;
|
|
12
|
+
constructor(connector: ZlinkStreamConnectorSubmitter, name: string | undefined, payload: ZlinkStreamEncodedPayload);
|
|
13
|
+
packetName(name: string): this;
|
|
14
|
+
metadata(key: string, value: string): this;
|
|
15
|
+
metadata(metadata: ZlinkStreamMetadata): this;
|
|
16
|
+
compress(): this;
|
|
17
|
+
flowFrom(flow: ZlinkStreamFlow): this;
|
|
18
|
+
submit(signal?: AbortSignal): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare class ZlinkStreamRequestBuilder implements ZlinkStreamRequestCall {
|
|
21
|
+
private readonly connector;
|
|
22
|
+
private readonly payload;
|
|
23
|
+
private readonly state;
|
|
24
|
+
constructor(connector: ZlinkStreamConnectorSubmitter, name: string | undefined, payload: ZlinkStreamEncodedPayload);
|
|
25
|
+
packetName(name: string): this;
|
|
26
|
+
metadata(key: string, value: string): this;
|
|
27
|
+
metadata(metadata: ZlinkStreamMetadata): this;
|
|
28
|
+
timeout(timeoutMs: number): this;
|
|
29
|
+
compress(): this;
|
|
30
|
+
flowFrom(flow: ZlinkStreamFlow): this;
|
|
31
|
+
submit<TReply = unknown>(signal?: AbortSignal): Promise<TReply>;
|
|
32
|
+
submit(callback: (result: ZlinkStreamResultOf<ZlinkStreamEncodedPayload>) => void): void;
|
|
33
|
+
submitEncoded(signal?: AbortSignal): Promise<ZlinkStreamEncodedPayload>;
|
|
34
|
+
}
|
|
35
|
+
export declare class ZlinkStreamWaitBuilder<TPayload = ZlinkStreamEncodedPayload> implements ZlinkStreamWaitCall<TPayload> {
|
|
36
|
+
private readonly connector;
|
|
37
|
+
private readonly name;
|
|
38
|
+
private executed;
|
|
39
|
+
private timeoutMs;
|
|
40
|
+
private predicate;
|
|
41
|
+
constructor(connector: ZlinkStreamConnectorSubmitter, name: string);
|
|
42
|
+
where(predicate: (message: ZlinkStreamMessage<TPayload>) => boolean): this;
|
|
43
|
+
timeout(timeoutMs: number): this;
|
|
44
|
+
submit(signal?: AbortSignal): Promise<ZlinkStreamMessage<TPayload>>;
|
|
45
|
+
private ensureConfigurable;
|
|
46
|
+
private markExecuted;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type RequiredZlinkStreamConnectorOptions, type ZlinkStreamExpectNoneCall, type ZlinkStreamMessage, type ZlinkStreamSequenceCall } from '../../Contracts';
|
|
2
|
+
export interface ZlinkStreamMessageWaiter {
|
|
3
|
+
readonly options: RequiredZlinkStreamConnectorOptions;
|
|
4
|
+
waitForMessage<TPayload>(name: string, timeoutMs: number, predicate: (message: ZlinkStreamMessage<TPayload>) => boolean, signal?: AbortSignal): Promise<ZlinkStreamMessage<TPayload>>;
|
|
5
|
+
}
|
|
6
|
+
export declare class ZlinkStreamExpectNoneBuilder<TPayload> implements ZlinkStreamExpectNoneCall<TPayload> {
|
|
7
|
+
private readonly connector;
|
|
8
|
+
private readonly name;
|
|
9
|
+
private windowMs;
|
|
10
|
+
private executed;
|
|
11
|
+
constructor(connector: ZlinkStreamMessageWaiter, name: string);
|
|
12
|
+
within(windowMs: number): this;
|
|
13
|
+
run(signal?: AbortSignal): Promise<void>;
|
|
14
|
+
private ensureConfigurable;
|
|
15
|
+
private markExecuted;
|
|
16
|
+
}
|
|
17
|
+
export declare class ZlinkStreamSequenceBuilder<TPayload> implements ZlinkStreamSequenceCall<TPayload> {
|
|
18
|
+
private readonly connector;
|
|
19
|
+
private readonly name;
|
|
20
|
+
private readonly predicates;
|
|
21
|
+
private timeoutMs;
|
|
22
|
+
private executed;
|
|
23
|
+
constructor(connector: ZlinkStreamMessageWaiter, name: string);
|
|
24
|
+
expect(predicate: (payload: TPayload) => boolean): this;
|
|
25
|
+
timeout(timeoutMs: number): this;
|
|
26
|
+
run(signal?: AbortSignal): Promise<readonly TPayload[]>;
|
|
27
|
+
private ensureConfigurable;
|
|
28
|
+
private markExecuted;
|
|
29
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ZlinkStreamCompressionCodec, ZlinkStreamCompression } from '../../../Contracts';
|
|
2
|
+
import type { ZlinkStreamHeader } from '../../../Contracts/ZlinkStreamModels';
|
|
3
|
+
export declare const zlinkStreamLz4CompressionCodec: ZlinkStreamCompressionCodec;
|
|
4
|
+
export declare function compressPayload(payload: Uint8Array, compression: ZlinkStreamCompression, compressionCodec: ZlinkStreamCompressionCodec | undefined): Uint8Array;
|
|
5
|
+
export declare function decompressIfNeeded(header: ZlinkStreamHeader, payload: Uint8Array, compression: ZlinkStreamCompression, compressionCodec: ZlinkStreamCompressionCodec | undefined, maxDecompressedSize: number): Uint8Array;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ZlinkStreamCloseReason } from '../../Contracts';
|
|
2
|
+
export declare const ZLINK_SESSION_CLOSING = "session-closing";
|
|
3
|
+
export declare function decodeSessionClosing(payload: Uint8Array): {
|
|
4
|
+
readonly closeReason: ZlinkStreamCloseReason;
|
|
5
|
+
readonly diagnostic?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function encodeSessionClosing(reason: ZlinkStreamCloseReason, diagnostic?: string): Uint8Array;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class ZlinkStreamFrameCodec {
|
|
2
|
+
static encode(header: Uint8Array, payload: Uint8Array, maxPayloadSize?: number): Uint8Array;
|
|
3
|
+
static decode(frame: Uint8Array): {
|
|
4
|
+
header: Uint8Array;
|
|
5
|
+
payload: Uint8Array;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare function splitZlinkStreamFrames(chunk: Uint8Array): readonly Uint8Array[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RequiredZlinkStreamConnectorOptions, ZlinkStreamEncodedPayload, ZlinkStreamMetadata } from '../../Contracts';
|
|
2
|
+
import { ZlinkStreamMessageKind } from '../../Contracts';
|
|
3
|
+
import type { ZlinkStreamHeader } from '../../Contracts/ZlinkStreamModels';
|
|
4
|
+
import type { ZlinkFlowOrigin } from '../../Contracts';
|
|
5
|
+
export declare const ZLINK_STREAM_HEARTBEAT_PING = "$zlink.heartbeat.ping";
|
|
6
|
+
export declare const ZLINK_STREAM_HEARTBEAT_PONG = "$zlink.heartbeat.pong";
|
|
7
|
+
export declare class ZlinkStreamFrameProtocol {
|
|
8
|
+
private readonly options;
|
|
9
|
+
constructor(options: RequiredZlinkStreamConnectorOptions);
|
|
10
|
+
encode(kind: ZlinkStreamMessageKind, name: string, payload: ZlinkStreamEncodedPayload, metadata: ZlinkStreamMetadata, compress: boolean, requestSeq: bigint | undefined, correlationId?: string, flowId?: string, flowOrigin?: ZlinkFlowOrigin): Uint8Array;
|
|
11
|
+
encodeControl(name: string, payload?: Uint8Array<ArrayBuffer>): Uint8Array;
|
|
12
|
+
decode(frameBytes: Uint8Array, flowEnabled?: boolean): {
|
|
13
|
+
readonly header: ZlinkStreamHeader;
|
|
14
|
+
readonly payload: Uint8Array;
|
|
15
|
+
};
|
|
16
|
+
flowEnabled(): boolean;
|
|
17
|
+
decodeFrames(chunk: Uint8Array, flowEnabled?: boolean): readonly {
|
|
18
|
+
readonly header: ZlinkStreamHeader;
|
|
19
|
+
readonly payload: Uint8Array;
|
|
20
|
+
}[];
|
|
21
|
+
decodePayload(header: ZlinkStreamHeader, payload: Uint8Array): Uint8Array;
|
|
22
|
+
private encodeFrame;
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ZlinkStreamCodec, ZlinkStreamMessageKind, ZlinkStreamMetadata } from '../../Contracts';
|
|
2
|
+
import type { ZlinkStreamHeader } from '../../Contracts/ZlinkStreamModels';
|
|
3
|
+
export declare class ZlinkStreamHeaderCodec {
|
|
4
|
+
static encode(header: ZlinkStreamHeader): Uint8Array;
|
|
5
|
+
/**
|
|
6
|
+
* `includeFlow=false` (diagnostics Off, spec 27 §4) skips reading and
|
|
7
|
+
* validating the inbound flow fields while the structural length checks in
|
|
8
|
+
* the wire decoder are preserved.
|
|
9
|
+
*/
|
|
10
|
+
static decode(header: Uint8Array, includeFlow?: boolean): ZlinkStreamHeader;
|
|
11
|
+
}
|
|
12
|
+
export declare function buildHeader(kind: ZlinkStreamMessageKind, name: string, codec: ZlinkStreamCodec, metadata: ZlinkStreamMetadata, compress: boolean, requestSeq: bigint | undefined, correlationId?: string, flowId?: string, flowOrigin?: import('../../Contracts').ZlinkFlowOrigin): ZlinkStreamHeader;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ZlinkStreamMetadata } from '../../Contracts';
|
|
2
|
+
export declare const ZLINK_STREAM_MAX_METADATA_BYTES = 1024;
|
|
3
|
+
export declare class ZlinkStreamMetadataCodec {
|
|
4
|
+
static size(metadata: ZlinkStreamMetadata): number;
|
|
5
|
+
static write(metadata: ZlinkStreamMetadata, destination: Uint8Array): void;
|
|
6
|
+
static decode(metadata: Uint8Array): ZlinkStreamMetadata;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validateName(name: string, allowReserved?: boolean): void;
|