@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
|
@@ -1,6 +1,53 @@
|
|
|
1
|
-
import * as plugins from './
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { NativeByteManager } from './classes.nativebytemanager.js';
|
|
3
|
+
export { toClientWebSocketCloseCode } from './helpers.websocket.js';
|
|
4
|
+
export { TYPEDSOCKET_MAX_RETAINED_CLIENT_TAG_MUTATIONS, TYPEDSOCKET_MAX_RETAINED_CLIENT_TAG_MUTATIONS_PER_NAME, } from './classes.clienttagreconciler.js';
|
|
5
|
+
import type { TTypedSocketDiagnosticEvent } from './interfaces.diagnostics.js';
|
|
6
|
+
import type { INativeByteAuthorizationAdapter, INativeByteCreateVirtualStreamOptions, TNativeByteCapabilityMode } from './interfaces.nativebytes.js';
|
|
7
|
+
import type { ITypedSocketClientTagPolicy } from './classes.typedsockettagpolicymanager.js';
|
|
2
8
|
export type TTypedSocketSide = 'server' | 'client';
|
|
3
9
|
export type TConnectionStatus = 'new' | 'connecting' | 'connected' | 'disconnected' | 'reconnecting';
|
|
10
|
+
export declare const TYPEDSOCKET_MAX_TEXT_FRAME_BYTES: number;
|
|
11
|
+
export declare const TYPEDSOCKET_MAX_QUEUED_TEXT_FRAMES = 64;
|
|
12
|
+
export declare const TYPEDSOCKET_MAX_QUEUED_TEXT_BYTES: number;
|
|
13
|
+
export declare const TYPEDSOCKET_MAX_CONCURRENT_CLIENT_HANDLERS = 16;
|
|
14
|
+
export declare const TYPEDSOCKET_MAX_RETAINED_CLIENT_CALLBACKS = 64;
|
|
15
|
+
export declare const TYPEDSOCKET_MAX_PENDING_CLIENT_REQUESTS = 1024;
|
|
16
|
+
export declare const TYPEDSOCKET_MAX_OUTBOUND_BUFFERED_BYTES: number;
|
|
17
|
+
export declare const TYPEDSOCKET_MAX_METHOD_NAME_BYTES = 256;
|
|
18
|
+
export declare const TYPEDSOCKET_MAX_CORRELATION_ID_BYTES = 256;
|
|
19
|
+
export declare const TYPEDSOCKET_MAX_REQUEST_TIMEOUT_MS: number;
|
|
20
|
+
export declare const TYPEDSOCKET_MAX_CONNECTION_RESTORE_TIMEOUT_MS = 10000;
|
|
21
|
+
export declare const TYPEDSOCKET_MAX_RECONNECT_RETRIES = 100;
|
|
22
|
+
export declare const TYPEDSOCKET_MAX_RECONNECT_BACKOFF_MS = 60000;
|
|
23
|
+
export declare const TYPEDSOCKET_MAX_PENDING_SERVER_REQUESTS_PER_PEER = 64;
|
|
24
|
+
export declare const TYPEDSOCKET_MAX_PENDING_SERVER_REQUESTS = 1024;
|
|
25
|
+
export declare const TYPEDSOCKET_MAX_RETAINED_SERVER_INTERESTS_PER_PEER = 8;
|
|
26
|
+
export declare const TYPEDSOCKET_MAX_RETAINED_SERVER_INTERESTS = 64;
|
|
27
|
+
export interface ITypedSocketClientLimits {
|
|
28
|
+
readonly textFrameBytes: number;
|
|
29
|
+
readonly queuedTextFrames: number;
|
|
30
|
+
readonly queuedTextBytes: number;
|
|
31
|
+
readonly concurrentHandlers: number;
|
|
32
|
+
readonly retainedCallbacks: number;
|
|
33
|
+
readonly pendingRequests: number;
|
|
34
|
+
readonly outboundBufferedBytes: number;
|
|
35
|
+
readonly requestTimeoutMs: number;
|
|
36
|
+
readonly connectionRestoreTimeoutMs: number;
|
|
37
|
+
}
|
|
38
|
+
export interface ITypedSocketConnectionRestoreContext {
|
|
39
|
+
readonly connectionId: string;
|
|
40
|
+
readonly abortSignal: AbortSignal;
|
|
41
|
+
readonly deadline: number;
|
|
42
|
+
readonly createTypedRequest: TTypedSocketRestoreRequestFactory;
|
|
43
|
+
}
|
|
44
|
+
export type TTypedSocketRestoreRequestFactory = <T extends plugins.typedrequestInterfaces.ITypedRequest>(methodNameArg: T['method']) => plugins.typedrequest.TypedRequest<T>;
|
|
45
|
+
export interface ITypedSocketRequestContext {
|
|
46
|
+
readonly localData: Readonly<Record<string, unknown>>;
|
|
47
|
+
}
|
|
48
|
+
export declare class TypedSocketConnectionRestoreDeniedError extends Error {
|
|
49
|
+
constructor(messageArg: string);
|
|
50
|
+
}
|
|
4
51
|
/**
|
|
5
52
|
* Options for creating a TypedSocket client
|
|
6
53
|
*/
|
|
@@ -10,6 +57,16 @@ export interface ITypedSocketClientOptions {
|
|
|
10
57
|
initialBackoffMs?: number;
|
|
11
58
|
maxBackoffMs?: number;
|
|
12
59
|
abortSignal?: AbortSignal;
|
|
60
|
+
nativeByteCapabilityMode?: TNativeByteCapabilityMode;
|
|
61
|
+
/** Limits may lower, but never raise, TypedSocket package ceilings. */
|
|
62
|
+
limits?: Partial<ITypedSocketClientLimits>;
|
|
63
|
+
/** Restores connection-bound authentication before desired tags are reconciled. */
|
|
64
|
+
restoreConnection?: (contextArg: ITypedSocketConnectionRestoreContext) => void | Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
export interface ITypedSocketServerOptions {
|
|
67
|
+
nativeByteCapabilityMode?: TNativeByteCapabilityMode;
|
|
68
|
+
nativeByteAuthorizationAdapter?: INativeByteAuthorizationAdapter;
|
|
69
|
+
clientTagPolicy?: ITypedSocketClientTagPolicy;
|
|
13
70
|
}
|
|
14
71
|
/**
|
|
15
72
|
* Lifecycle controls for one TypedRequest sent over a TypedSocket.
|
|
@@ -20,7 +77,7 @@ export interface ITypedSocketRequestOptions {
|
|
|
20
77
|
}
|
|
21
78
|
export type TTypedSocketServerRouterInput = plugins.typedrequest.TypedRouter | readonly plugins.typedrequest.TypedRouter[];
|
|
22
79
|
/**
|
|
23
|
-
*
|
|
80
|
+
* Typed connection wrapper for one exact SmartServe WebSocket peer.
|
|
24
81
|
*/
|
|
25
82
|
export interface ISmartServeConnectionWrapper {
|
|
26
83
|
peer: plugins.IWebSocketPeer;
|
|
@@ -60,7 +117,7 @@ export declare class TypedSocket {
|
|
|
60
117
|
*
|
|
61
118
|
* Call attachSmartServe() after constructing the SmartServe transport.
|
|
62
119
|
*/
|
|
63
|
-
static createServer(typedRouterOrRoutersArg: TTypedSocketServerRouterInput): TypedSocket;
|
|
120
|
+
static createServer(typedRouterOrRoutersArg: TTypedSocketServerRouterInput, optionsArg?: ITypedSocketServerOptions): TypedSocket;
|
|
64
121
|
/**
|
|
65
122
|
* Creates and attaches a TypedSocket server to an existing SmartServe
|
|
66
123
|
* instance. Prefer createServer() plus attachSmartServe() when transport
|
|
@@ -75,24 +132,36 @@ export declare class TypedSocket {
|
|
|
75
132
|
* const smartServe = new SmartServe({
|
|
76
133
|
* port: 3000,
|
|
77
134
|
* websocket: {
|
|
78
|
-
* typedRouter
|
|
79
|
-
* onConnectionOpen: (peer) => peer.tags.add('client')
|
|
135
|
+
* typedRouter
|
|
80
136
|
* }
|
|
81
137
|
* });
|
|
82
138
|
* await smartServe.start();
|
|
83
139
|
* const typedSocket = TypedSocket.fromSmartServe(smartServe, typedRouter);
|
|
140
|
+
* // Authenticated server handlers assign protected connection metadata with:
|
|
141
|
+
* // typedSocket.setServerTag(peer, 'authenticated', { userId });
|
|
84
142
|
* ```
|
|
85
143
|
*/
|
|
86
|
-
static fromSmartServe(smartServeArg: plugins.SmartServe, typedRouterArg: TTypedSocketServerRouterInput): TypedSocket;
|
|
144
|
+
static fromSmartServe(smartServeArg: plugins.SmartServe, typedRouterArg: TTypedSocketServerRouterInput, optionsArg?: ITypedSocketServerOptions): TypedSocket;
|
|
87
145
|
/**
|
|
88
146
|
* Registers built-in TypedHandlers for tag management
|
|
89
147
|
*/
|
|
90
|
-
private static
|
|
148
|
+
private static registerProtocolHandlers;
|
|
91
149
|
readonly side: TTypedSocketSide;
|
|
92
150
|
readonly typedrouter: plugins.typedrequest.TypedRouter;
|
|
151
|
+
readonly nativeBytes: NativeByteManager;
|
|
152
|
+
readonly webSocketTransportOwner: plugins.IWebSocketTransportOwner;
|
|
93
153
|
statusSubject: plugins.smartrx.rxjs.Subject<TConnectionStatus>;
|
|
154
|
+
/**
|
|
155
|
+
* Structured diagnostics: why a connection was closed, denied, or retried.
|
|
156
|
+
* Never completes, mirroring statusSubject; subscribers own unsubscription.
|
|
157
|
+
*/
|
|
158
|
+
readonly diagnosticsSubject: plugins.smartrx.rxjs.Subject<TTypedSocketDiagnosticEvent>;
|
|
94
159
|
private connectionStatus;
|
|
160
|
+
private reconnectExhaustedReported;
|
|
95
161
|
private websocket;
|
|
162
|
+
private connectionGeneration;
|
|
163
|
+
private clientConnectionState;
|
|
164
|
+
private retainedClientCallbacks;
|
|
96
165
|
private clientOptions;
|
|
97
166
|
private serverUrl;
|
|
98
167
|
private retryCount;
|
|
@@ -101,15 +170,22 @@ export declare class TypedSocket {
|
|
|
101
170
|
private abortSignalListener?;
|
|
102
171
|
private stopListeners;
|
|
103
172
|
private pendingRequests;
|
|
104
|
-
private
|
|
105
|
-
private clientTagMutations;
|
|
173
|
+
private readonly clientTagReconciler;
|
|
106
174
|
private smartServeRef;
|
|
107
175
|
private serverTypedRouters;
|
|
108
176
|
private detachProtocolRouters;
|
|
177
|
+
private detachLegacyVirtualStreamPolicies;
|
|
109
178
|
private serverStopping;
|
|
179
|
+
private serverLifecycleGeneration;
|
|
110
180
|
private unsubscribeSmartServeConnectionClose;
|
|
181
|
+
private detachNativeStreamResolvers;
|
|
182
|
+
private detachResponseAuthorityGuards;
|
|
111
183
|
private pendingServerRequests;
|
|
112
|
-
private
|
|
184
|
+
private pendingServerRequestIdsByPeer;
|
|
185
|
+
private retainedServerInterests;
|
|
186
|
+
private retainedServerInterestsByPeer;
|
|
187
|
+
private readonly nativeByteAuthorizationAdapter;
|
|
188
|
+
private readonly tagPolicyManager;
|
|
113
189
|
private constructor();
|
|
114
190
|
/**
|
|
115
191
|
* Attaches the SmartServe transport after server router composition.
|
|
@@ -119,14 +195,20 @@ export declare class TypedSocket {
|
|
|
119
195
|
* Connects the client to the server using native WebSocket
|
|
120
196
|
*/
|
|
121
197
|
private connect;
|
|
198
|
+
private negotiateClientCapabilities;
|
|
199
|
+
private restoreClientConnection;
|
|
122
200
|
/**
|
|
123
201
|
* Converts an HTTP(S) URL to a WebSocket URL
|
|
124
202
|
*/
|
|
125
203
|
private toWebSocketUrl;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
204
|
+
private toRedactedLogEndpoint;
|
|
205
|
+
private enqueueClientTextFrame;
|
|
206
|
+
private drainClientTextFrames;
|
|
207
|
+
private assertClientEnvelope;
|
|
129
208
|
private handleMessage;
|
|
209
|
+
private sendClientTextEnvelope;
|
|
210
|
+
private isCurrentClientConnection;
|
|
211
|
+
private abortClientConnectionState;
|
|
130
212
|
/**
|
|
131
213
|
* Handles WebSocket disconnection
|
|
132
214
|
*/
|
|
@@ -153,12 +235,24 @@ export declare class TypedSocket {
|
|
|
153
235
|
* Updates connection status and notifies subscribers
|
|
154
236
|
*/
|
|
155
237
|
private updateStatus;
|
|
238
|
+
/**
|
|
239
|
+
* Diagnostics must never disturb transport code paths: subscriber errors
|
|
240
|
+
* are swallowed here.
|
|
241
|
+
*/
|
|
242
|
+
private emitDiagnostic;
|
|
243
|
+
private emitConnectionClosedDiagnostic;
|
|
244
|
+
private emitTagDenialDiagnostic;
|
|
156
245
|
/**
|
|
157
246
|
* Sends a request to the server and waits for response (client-side)
|
|
158
247
|
*/
|
|
159
248
|
private sendRequest;
|
|
160
249
|
private normalizeRequestTimeout;
|
|
250
|
+
private requireClientOptions;
|
|
161
251
|
private cancelPendingServerRequestsForPeer;
|
|
252
|
+
private retainServerInterestRegistration;
|
|
253
|
+
private authorizeIncomingServerResponse;
|
|
254
|
+
private isAttachedServerPeer;
|
|
255
|
+
private findServerPeerFromRequest;
|
|
162
256
|
private sendServerRequest;
|
|
163
257
|
/**
|
|
164
258
|
* Creates a TypedRequest for the specified method.
|
|
@@ -166,6 +260,11 @@ export declare class TypedSocket {
|
|
|
166
260
|
* On servers, sends to the specified target connection.
|
|
167
261
|
*/
|
|
168
262
|
createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(methodName: T['method'], targetConnection?: ISmartServeConnectionWrapper, optionsArg?: ITypedSocketRequestOptions): plugins.typedrequest.TypedRequest<T>;
|
|
263
|
+
/**
|
|
264
|
+
* Creates an exact authorized native-byte receive facade for one server peer.
|
|
265
|
+
* TypedRequest carries its opaque descriptor when the facade enters a DTO.
|
|
266
|
+
*/
|
|
267
|
+
createVirtualStream(optionsArg: INativeByteCreateVirtualStreamOptions): plugins.typedrequestInterfaces.INativeByteVirtualStreamReceiver<Uint8Array>;
|
|
169
268
|
/**
|
|
170
269
|
* Gets the current connection status
|
|
171
270
|
*/
|
|
@@ -174,6 +273,7 @@ export declare class TypedSocket {
|
|
|
174
273
|
* Stops the TypedSocket client or cleans up server state
|
|
175
274
|
*/
|
|
176
275
|
stop(): Promise<void>;
|
|
276
|
+
private releaseServerComposition;
|
|
177
277
|
/**
|
|
178
278
|
* Sets a tag on this client connection.
|
|
179
279
|
* Tags are stored on the server and can be used for filtering.
|
|
@@ -190,6 +290,15 @@ export declare class TypedSocket {
|
|
|
190
290
|
* @client-only
|
|
191
291
|
*/
|
|
192
292
|
removeTag(name: string): Promise<void>;
|
|
293
|
+
/**
|
|
294
|
+
* Resolves the exact SmartServe transport peer for one incoming TypedRequest.
|
|
295
|
+
* Server handlers can pass their TypedTools argument without type assertions.
|
|
296
|
+
*/
|
|
297
|
+
getServerConnectionForRequest(typedToolsArg: ITypedSocketRequestContext | undefined): ISmartServeConnectionWrapper;
|
|
298
|
+
/** Assigns a protected server-owned tag to one connection. */
|
|
299
|
+
setServerTag(connectionArg: ISmartServeConnectionWrapper | plugins.IWebSocketPeer, nameArg: string, payloadArg?: unknown): void;
|
|
300
|
+
/** Removes a server-owned tag while keeping its name protected from clients. */
|
|
301
|
+
removeServerTag(connectionArg: ISmartServeConnectionWrapper | plugins.IWebSocketPeer, nameArg: string): void;
|
|
193
302
|
/**
|
|
194
303
|
* Finds all connections matching the filter function.
|
|
195
304
|
* @server-only
|