@api.global/typedsocket 5.1.2 → 6.1.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_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.clienttagreconciler.d.ts +51 -0
- package/dist_ts/classes.clienttagreconciler.js +290 -0
- package/dist_ts/classes.nativebyteerror.d.ts +13 -0
- package/dist_ts/classes.nativebyteerror.js +26 -0
- package/dist_ts/classes.nativebytemanager.d.ts +327 -0
- package/dist_ts/classes.nativebytemanager.js +2343 -0
- package/dist_ts/{typedsocket.classes.typedsocket.d.ts → classes.typedsocket.d.ts} +122 -13
- package/dist_ts/classes.typedsocket.js +1733 -0
- package/dist_ts/classes.typedsockettagpolicymanager.d.ts +112 -0
- package/dist_ts/classes.typedsockettagpolicymanager.js +549 -0
- package/dist_ts/constants.nativebytes.d.ts +59 -0
- package/dist_ts/constants.nativebytes.js +58 -0
- package/dist_ts/helpers.nativebytecodec.d.ts +8 -0
- package/dist_ts/helpers.nativebytecodec.js +328 -0
- package/dist_ts/helpers.websocket.d.ts +8 -0
- package/dist_ts/helpers.websocket.js +13 -0
- package/dist_ts/index.d.ts +9 -1
- package/dist_ts/index.js +6 -2
- package/dist_ts/interfaces.diagnostics.d.ts +73 -0
- package/dist_ts/interfaces.diagnostics.js +2 -0
- package/dist_ts/interfaces.nativebytes.d.ts +187 -0
- package/dist_ts/interfaces.nativebytes.js +2 -0
- package/{ts/typedsocket.plugins.ts → dist_ts/plugins.d.ts} +3 -9
- package/dist_ts/plugins.js +14 -0
- package/{license → license.md} +2 -2
- package/package.json +22 -18
- package/readme.hints.md +60 -19
- package/readme.md +536 -56
- package/dist_ts/typedsocket.classes.typedsocket.js +0 -941
- package/dist_ts/typedsocket.plugins.d.ts +0 -11
- package/dist_ts/typedsocket.plugins.js +0 -13
- package/npmextra.json +0 -35
- package/ts/00_commitinfo_data.ts +0 -8
- package/ts/index.ts +0 -1
- package/ts/typedsocket.classes.typedsocket.ts +0 -1156
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { NativeByteStreamClosedError } from './classes.nativebyteerror.js';
|
|
3
|
+
import type { INativeByteCapabilityStatus, INativeByteCreateReceiveGrantOptions, INativeByteDescriptor, INativeByteOpenSenderOptions, INativeByteReceipt, INativeByteReceiveGrant, INativeByteRuntime, INativeByteStats, TNativeByteCapabilityMode, TNativeByteConnectionBinding, TNativeByteRevalidate } from './interfaces.nativebytes.js';
|
|
4
|
+
import type { TNativeByteDiagnosticEvent } from './interfaces.diagnostics.js';
|
|
5
|
+
type TNativeStreamTransport = plugins.typedrequestInterfaces.INativeStreamTransport;
|
|
6
|
+
type TNativeStreamEndpoint = plugins.typedrequestInterfaces.INativeStreamTransportEndpoint;
|
|
7
|
+
type TSha256Hasher = ReturnType<typeof plugins.smarthash.createSha256Hasher>;
|
|
8
|
+
interface IDeferred<T> {
|
|
9
|
+
readonly promise: Promise<T>;
|
|
10
|
+
readonly settled: boolean;
|
|
11
|
+
resolve(valueArg: T): void;
|
|
12
|
+
reject(errorArg: unknown): void;
|
|
13
|
+
}
|
|
14
|
+
interface IOutboundFrame {
|
|
15
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
16
|
+
readonly streamId: string;
|
|
17
|
+
readonly producer?: IProducerState;
|
|
18
|
+
readonly payloadBytes: number;
|
|
19
|
+
readonly settlement: IDeferred<void>;
|
|
20
|
+
accountingReleased: boolean;
|
|
21
|
+
timer?: unknown;
|
|
22
|
+
}
|
|
23
|
+
interface IProducerAdmission {
|
|
24
|
+
readonly payload: Uint8Array;
|
|
25
|
+
remainingPayloadBytes: number;
|
|
26
|
+
sourceAccountingOwned: boolean;
|
|
27
|
+
pendingOperationOwned: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface ITombstone {
|
|
30
|
+
readonly streamId: string;
|
|
31
|
+
readonly expiresAt: number;
|
|
32
|
+
readonly confirmedFin: boolean;
|
|
33
|
+
readonly byteLength: number;
|
|
34
|
+
readonly sha256: string;
|
|
35
|
+
readonly finAck?: Uint8Array<ArrayBuffer>;
|
|
36
|
+
readonly retainedBytes: number;
|
|
37
|
+
}
|
|
38
|
+
type TConsumerStatus = 'grant' | 'validating-open' | 'open' | 'fin-validated' | 'awaiting-confirmation' | 'closed';
|
|
39
|
+
type TProducerStatus = 'opening' | 'open' | 'finishing' | 'closed';
|
|
40
|
+
type TConsumerTerminalOperation = {
|
|
41
|
+
readonly kind: 'confirm';
|
|
42
|
+
readonly promise: Promise<INativeByteReceipt>;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: 'reject';
|
|
45
|
+
readonly promise: Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
interface IConsumerState {
|
|
48
|
+
readonly role: 'consumer';
|
|
49
|
+
readonly connection: IConnectionState;
|
|
50
|
+
readonly descriptor: INativeByteDescriptor;
|
|
51
|
+
readonly revalidate: TNativeByteRevalidate;
|
|
52
|
+
readonly principalId: string;
|
|
53
|
+
readonly revisions: {
|
|
54
|
+
readonly credentialRevision: string;
|
|
55
|
+
readonly configRevision: string;
|
|
56
|
+
readonly bindingRevision: string;
|
|
57
|
+
};
|
|
58
|
+
readonly endpoint: NativeByteReceiver;
|
|
59
|
+
readonly completion: IDeferred<INativeByteReceipt>;
|
|
60
|
+
readonly opened: IDeferred<NativeByteReceiver>;
|
|
61
|
+
readonly closedSignal: IDeferred<never>;
|
|
62
|
+
readonly revalidationControllers: Set<AbortController>;
|
|
63
|
+
readonly authorityMetadataBytes: number;
|
|
64
|
+
readonly receiveQueue: Array<Uint8Array | undefined>;
|
|
65
|
+
receiveQueueHead: number;
|
|
66
|
+
readonly receiveWaiters: Set<IDeferred<void>>;
|
|
67
|
+
readonly hasher: TSha256Hasher;
|
|
68
|
+
status: TConsumerStatus;
|
|
69
|
+
consumerReadActive: boolean;
|
|
70
|
+
timer?: unknown;
|
|
71
|
+
nextSequence: number;
|
|
72
|
+
receivedOffset: number;
|
|
73
|
+
consumedOffset: number;
|
|
74
|
+
receiveLimitOffset: number;
|
|
75
|
+
windowReservationBytes: number;
|
|
76
|
+
queuedPayloadBytes: number;
|
|
77
|
+
terminalOperation?: TConsumerTerminalOperation;
|
|
78
|
+
finalSha256?: string;
|
|
79
|
+
closeError?: NativeByteStreamClosedError;
|
|
80
|
+
}
|
|
81
|
+
interface IProducerState {
|
|
82
|
+
readonly role: 'producer';
|
|
83
|
+
readonly connection: IConnectionState;
|
|
84
|
+
readonly descriptor: INativeByteDescriptor;
|
|
85
|
+
readonly endpoint: NativeByteSender;
|
|
86
|
+
readonly completion: IDeferred<INativeByteReceipt>;
|
|
87
|
+
readonly opened: IDeferred<NativeByteSender>;
|
|
88
|
+
readonly closedSignal: IDeferred<never>;
|
|
89
|
+
readonly windowWaiters: Set<IDeferred<void>>;
|
|
90
|
+
readonly hasher: TSha256Hasher;
|
|
91
|
+
status: TProducerStatus;
|
|
92
|
+
operationTail: Promise<void>;
|
|
93
|
+
terminalRequested: boolean;
|
|
94
|
+
terminalPromise?: Promise<void>;
|
|
95
|
+
openTimer?: unknown;
|
|
96
|
+
idleTimer?: unknown;
|
|
97
|
+
ackTimer?: unknown;
|
|
98
|
+
finAckTimer?: unknown;
|
|
99
|
+
nextSequence: number;
|
|
100
|
+
sentOffset: number;
|
|
101
|
+
admittedOffset: number;
|
|
102
|
+
acknowledgedOffset: number;
|
|
103
|
+
receiveLimitOffset: number;
|
|
104
|
+
queuedPayloadBytes: number;
|
|
105
|
+
finalSha256?: string;
|
|
106
|
+
closeError?: NativeByteStreamClosedError;
|
|
107
|
+
}
|
|
108
|
+
type TStreamState = IConsumerState | IProducerState;
|
|
109
|
+
interface IConnectionState {
|
|
110
|
+
readonly binding: TNativeByteConnectionBinding;
|
|
111
|
+
readonly transport: NativeByteConnectionTransport;
|
|
112
|
+
readonly grants: Map<string, IConsumerState>;
|
|
113
|
+
readonly streams: Map<string, TStreamState>;
|
|
114
|
+
readonly tombstones: Map<string, ITombstone>;
|
|
115
|
+
readonly rawQueue: Uint8Array[];
|
|
116
|
+
readonly controlQueue: IOutboundFrame[];
|
|
117
|
+
readonly dataQueue: IOutboundFrame[];
|
|
118
|
+
serverInflightFrame?: IOutboundFrame;
|
|
119
|
+
serverInflightTransportFrame?: Extract<plugins.TWebSocketOutboundRawFrame, {
|
|
120
|
+
type: 'binary';
|
|
121
|
+
}>;
|
|
122
|
+
readonly revalidationControllers: Set<AbortController>;
|
|
123
|
+
negotiated: boolean;
|
|
124
|
+
nativeEnabled: boolean;
|
|
125
|
+
closed: boolean;
|
|
126
|
+
processingRaw: boolean;
|
|
127
|
+
rawQueueBytes: number;
|
|
128
|
+
processingRawBytes: number;
|
|
129
|
+
queuedPayloadBytes: number;
|
|
130
|
+
authorityMetadataBytes: number;
|
|
131
|
+
tombstoneBytes: number;
|
|
132
|
+
receiveWindowReservedBytes: number;
|
|
133
|
+
pendingProducerDataOperations: number;
|
|
134
|
+
retainedRevalidations: number;
|
|
135
|
+
serverWakeOutstanding: boolean;
|
|
136
|
+
clientTurnScheduled: boolean;
|
|
137
|
+
clientBackpressureTimer?: unknown;
|
|
138
|
+
negotiationTimer?: unknown;
|
|
139
|
+
}
|
|
140
|
+
export declare class NativeByteReceiver implements TNativeStreamEndpoint {
|
|
141
|
+
private readonly manager;
|
|
142
|
+
private readonly state;
|
|
143
|
+
readonly protocol: "native-byte-v1";
|
|
144
|
+
readonly direction: "receive";
|
|
145
|
+
readonly readable: ReadableStream<Uint8Array>;
|
|
146
|
+
private manifestInternal;
|
|
147
|
+
constructor(manager: NativeByteManager, state: IConsumerState);
|
|
148
|
+
get closed(): Promise<void>;
|
|
149
|
+
get manifest(): plugins.typedrequestInterfaces.INativeByteStreamManifest;
|
|
150
|
+
get completion(): Promise<INativeByteReceipt>;
|
|
151
|
+
sendData(_dataArg: Uint8Array): Promise<void>;
|
|
152
|
+
fetchData(): Promise<Uint8Array>;
|
|
153
|
+
readFromWebstream(_readableStreamArg: ReadableStream<Uint8Array>): Promise<void>;
|
|
154
|
+
writeToWebstream(writableStreamArg: WritableStream<Uint8Array>): Promise<void>;
|
|
155
|
+
close(_sendClosingBitArg?: boolean): Promise<void>;
|
|
156
|
+
abort(reasonArg?: unknown): Promise<void>;
|
|
157
|
+
reject(reasonArg?: unknown): Promise<void>;
|
|
158
|
+
confirmDurable(): Promise<INativeByteReceipt>;
|
|
159
|
+
}
|
|
160
|
+
export declare class NativeByteSender implements TNativeStreamEndpoint {
|
|
161
|
+
private readonly manager;
|
|
162
|
+
private readonly state;
|
|
163
|
+
readonly protocol: "native-byte-v1";
|
|
164
|
+
readonly direction: "send";
|
|
165
|
+
readonly writable: WritableStream<Uint8Array>;
|
|
166
|
+
private manifestInternal;
|
|
167
|
+
constructor(manager: NativeByteManager, state: IProducerState);
|
|
168
|
+
get closed(): Promise<void>;
|
|
169
|
+
get manifest(): plugins.typedrequestInterfaces.INativeByteStreamManifest;
|
|
170
|
+
get completion(): Promise<INativeByteReceipt>;
|
|
171
|
+
sendData(dataArg: Uint8Array): Promise<void>;
|
|
172
|
+
fetchData(): Promise<Uint8Array>;
|
|
173
|
+
readFromWebstream(readableStreamArg: ReadableStream<Uint8Array>, closeAfterReadingArg?: boolean): Promise<void>;
|
|
174
|
+
writeToWebstream(_writableStreamArg: WritableStream<Uint8Array>): Promise<void>;
|
|
175
|
+
close(_sendClosingBitArg?: boolean): Promise<void>;
|
|
176
|
+
abort(reasonArg?: unknown): Promise<void>;
|
|
177
|
+
}
|
|
178
|
+
declare class NativeByteConnectionTransport implements TNativeStreamTransport {
|
|
179
|
+
private readonly manager;
|
|
180
|
+
private readonly connection;
|
|
181
|
+
constructor(manager: NativeByteManager, connection: IConnectionState);
|
|
182
|
+
get capabilities(): readonly ['native-byte-v1'] | readonly [];
|
|
183
|
+
requireCapability(requirementArg: plugins.typedrequestInterfaces.INativeStreamCapabilityRequirement): void;
|
|
184
|
+
registerNativeStream(): plugins.typedrequestInterfaces.INativeStreamTransportRegistration;
|
|
185
|
+
openNativeStream(descriptorArg: plugins.typedrequestInterfaces.TNativeStreamDescriptor): Promise<TNativeStreamEndpoint>;
|
|
186
|
+
}
|
|
187
|
+
export interface INativeByteManagerOptions {
|
|
188
|
+
readonly side: 'client' | 'server';
|
|
189
|
+
readonly capabilityMode?: TNativeByteCapabilityMode;
|
|
190
|
+
readonly runtime?: INativeByteRuntime;
|
|
191
|
+
/** Structured close/rejection diagnostics; must not throw, errors are swallowed. */
|
|
192
|
+
readonly onDiagnostic?: (eventArg: TNativeByteDiagnosticEvent) => void;
|
|
193
|
+
}
|
|
194
|
+
export declare class NativeByteManager {
|
|
195
|
+
readonly webSocketTransportOwner: plugins.IWebSocketTransportOwner;
|
|
196
|
+
private readonly side;
|
|
197
|
+
private readonly capabilityMode;
|
|
198
|
+
private readonly runtime;
|
|
199
|
+
private readonly onDiagnostic?;
|
|
200
|
+
private readonly clientNativeStreamTransport;
|
|
201
|
+
private readonly serverConnections;
|
|
202
|
+
private readonly serverSettlementConnections;
|
|
203
|
+
private readonly serverAccountingConnections;
|
|
204
|
+
private currentClientConnection;
|
|
205
|
+
private serverAttached;
|
|
206
|
+
private retainedRevalidations;
|
|
207
|
+
private readonly retainedRevalidationsByPrincipal;
|
|
208
|
+
constructor(optionsArg: INativeByteManagerOptions);
|
|
209
|
+
attachServer(): void;
|
|
210
|
+
detachServer(): void;
|
|
211
|
+
bindClientConnection(webSocketArg: WebSocket, generationArg: number): void;
|
|
212
|
+
unbindClientConnection(webSocketArg: WebSocket, generationArg: number, reasonArg?: unknown): void;
|
|
213
|
+
enqueueClientRawFrame(webSocketArg: WebSocket, generationArg: number, dataArg: ArrayBuffer | ArrayBufferView): void;
|
|
214
|
+
getClientNegotiationAdvertisement(): {
|
|
215
|
+
protocolMajor: 6;
|
|
216
|
+
capabilities: readonly ['native-byte-v1'] | readonly [];
|
|
217
|
+
};
|
|
218
|
+
completeClientNegotiation(webSocketArg: WebSocket, generationArg: number, responseArg: {
|
|
219
|
+
protocolMajor: number;
|
|
220
|
+
capabilities: readonly string[];
|
|
221
|
+
required?: boolean;
|
|
222
|
+
}): void;
|
|
223
|
+
failOptionalClientNegotiation(webSocketArg: WebSocket, generationArg: number): void;
|
|
224
|
+
negotiateServerPeer(peerArg: plugins.IWebSocketPeer, requestArg: {
|
|
225
|
+
protocolMajor: number;
|
|
226
|
+
capabilities: readonly string[];
|
|
227
|
+
}): {
|
|
228
|
+
protocolMajor: 6;
|
|
229
|
+
capabilities: readonly ['native-byte-v1'] | readonly [];
|
|
230
|
+
required: boolean;
|
|
231
|
+
};
|
|
232
|
+
getClientNativeStreamTransport(): TNativeStreamTransport | undefined;
|
|
233
|
+
getServerNativeStreamTransport(peerArg: plugins.IWebSocketPeer): TNativeStreamTransport | undefined;
|
|
234
|
+
connectionHasCapability(connectionArg: IConnectionState): boolean;
|
|
235
|
+
createReceiveGrant(optionsArg: INativeByteCreateReceiveGrantOptions): INativeByteReceiveGrant;
|
|
236
|
+
normalizeManifest(manifestArg: plugins.typedrequestInterfaces.INativeByteStreamManifest): plugins.typedrequestInterfaces.INativeByteStreamManifest;
|
|
237
|
+
createReceiveRegistration(optionsArg: INativeByteCreateReceiveGrantOptions): plugins.typedrequestInterfaces.INativeByteStreamTransportRegistration;
|
|
238
|
+
openSender(descriptorArg: INativeByteDescriptor, optionsArg?: INativeByteOpenSenderOptions): Promise<NativeByteSender>;
|
|
239
|
+
getCapability(targetArg?: {
|
|
240
|
+
readonly peer: plugins.IWebSocketPeer;
|
|
241
|
+
} | plugins.IWebSocketPeer): INativeByteCapabilityStatus;
|
|
242
|
+
getStats(targetArg?: {
|
|
243
|
+
readonly peer: plugins.IWebSocketPeer;
|
|
244
|
+
} | plugins.IWebSocketPeer): INativeByteStats;
|
|
245
|
+
registerGenericNativeStream(connectionArg: IConnectionState): plugins.typedrequestInterfaces.INativeStreamTransportRegistration;
|
|
246
|
+
openSenderOnConnection(connectionArg: IConnectionState, descriptorArg: plugins.typedrequestInterfaces.TNativeStreamDescriptor): Promise<NativeByteSender>;
|
|
247
|
+
enqueueProducerData(stateArg: IProducerState, dataArg: Uint8Array): Promise<void>;
|
|
248
|
+
closeProducer(stateArg: IProducerState): Promise<void>;
|
|
249
|
+
private admitProducerData;
|
|
250
|
+
private releaseProducerAdmission;
|
|
251
|
+
sendProducerData(stateArg: IProducerState, admissionArg: IProducerAdmission): Promise<void>;
|
|
252
|
+
finishProducer(stateArg: IProducerState): Promise<void>;
|
|
253
|
+
abortProducer(stateArg: IProducerState, reasonArg?: unknown): Promise<void>;
|
|
254
|
+
private getConsumerQueueLength;
|
|
255
|
+
consumeReceiverData(stateArg: IConsumerState): Promise<Uint8Array | undefined>;
|
|
256
|
+
private consumeReceiverDataOnce;
|
|
257
|
+
getConsumerCloseError(stateArg: IConsumerState, messageArg?: string): NativeByteStreamClosedError;
|
|
258
|
+
confirmConsumerDurable(stateArg: IConsumerState): Promise<INativeByteReceipt>;
|
|
259
|
+
private confirmConsumerDurableOnce;
|
|
260
|
+
rejectConsumer(stateArg: IConsumerState, reasonArg?: unknown): Promise<void>;
|
|
261
|
+
private rejectConsumerOnce;
|
|
262
|
+
private createConnection;
|
|
263
|
+
private bindServerPeer;
|
|
264
|
+
private unbindServerPeer;
|
|
265
|
+
private enqueueServerRawFrame;
|
|
266
|
+
private enqueueRawFrame;
|
|
267
|
+
private processRawQueue;
|
|
268
|
+
private handleFrame;
|
|
269
|
+
private handleOpen;
|
|
270
|
+
private handleOpenAck;
|
|
271
|
+
private handleData;
|
|
272
|
+
private handleAck;
|
|
273
|
+
private handleFin;
|
|
274
|
+
private handleFinAck;
|
|
275
|
+
private handleReset;
|
|
276
|
+
private createReceiveGrantOnConnection;
|
|
277
|
+
private validateDescriptor;
|
|
278
|
+
private resolveConnection;
|
|
279
|
+
private resolveConnectionForInspection;
|
|
280
|
+
private requireConnectionCapability;
|
|
281
|
+
private reserveStreamSlot;
|
|
282
|
+
private normalizePrincipalId;
|
|
283
|
+
private normalizeAuthorityRevision;
|
|
284
|
+
private getServerConnectionCount;
|
|
285
|
+
private getServerStreamCount;
|
|
286
|
+
private getServerRetainedBytes;
|
|
287
|
+
private getServerReceiveReservationBytes;
|
|
288
|
+
private assertServerRetainedByteCapacity;
|
|
289
|
+
private assertServerReceiveReservationCapacity;
|
|
290
|
+
private maybeReleaseServerAccountingConnection;
|
|
291
|
+
private revalidateConsumer;
|
|
292
|
+
private getRevalidationResetCode;
|
|
293
|
+
private assertConsumerOwned;
|
|
294
|
+
private assertProducerOpen;
|
|
295
|
+
private waitForProducerWindow;
|
|
296
|
+
private wakeProducerWindowWaiters;
|
|
297
|
+
private wakeConsumerReceiveWaiters;
|
|
298
|
+
private refreshProducerIdleTimer;
|
|
299
|
+
private refreshProducerAckTimer;
|
|
300
|
+
private refreshConsumerIdleTimer;
|
|
301
|
+
private enterAwaitingConfirmation;
|
|
302
|
+
private clearProducerProgressTimers;
|
|
303
|
+
private failStreamProtocol;
|
|
304
|
+
private failProducer;
|
|
305
|
+
private failConsumer;
|
|
306
|
+
private cleanupProducer;
|
|
307
|
+
private cleanupConsumer;
|
|
308
|
+
private tryAddCleanupTombstone;
|
|
309
|
+
private addTombstone;
|
|
310
|
+
private pruneTombstones;
|
|
311
|
+
private deleteTombstone;
|
|
312
|
+
private sendReset;
|
|
313
|
+
private enqueueFrame;
|
|
314
|
+
private enqueueEncodedFrame;
|
|
315
|
+
private wakeOutbound;
|
|
316
|
+
private runClientOutboundTurn;
|
|
317
|
+
private pullServerBinaryFrame;
|
|
318
|
+
private settleServerOutboundFrame;
|
|
319
|
+
private settleOutboundFrame;
|
|
320
|
+
private releaseOutboundQueueBytes;
|
|
321
|
+
private releaseProducerPayloadAccounting;
|
|
322
|
+
private removeQueuedFramesForStream;
|
|
323
|
+
private emitDiagnostic;
|
|
324
|
+
private closeConnection;
|
|
325
|
+
private failConnection;
|
|
326
|
+
}
|
|
327
|
+
export {};
|