@api.global/typedsocket 6.3.0 → 7.0.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.
Files changed (35) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/classes.typedsocket.d.ts +21 -52
  3. package/dist_ts/classes.typedsocket.js +264 -358
  4. package/dist_ts/classes.typedsockettagpolicymanager.d.ts +1 -0
  5. package/dist_ts/classes.typedsockettagpolicymanager.js +26 -2
  6. package/dist_ts/classes.virtualstreammanager.d.ts +268 -0
  7. package/dist_ts/classes.virtualstreammanager.js +2085 -0
  8. package/dist_ts/constants.virtualstream.d.ts +58 -0
  9. package/dist_ts/constants.virtualstream.js +58 -0
  10. package/dist_ts/helpers.virtualstreamcodec.d.ts +14 -0
  11. package/dist_ts/helpers.virtualstreamcodec.js +349 -0
  12. package/dist_ts/index.d.ts +5 -9
  13. package/dist_ts/index.js +3 -6
  14. package/dist_ts/interfaces.diagnostics.d.ts +6 -18
  15. package/dist_ts/interfaces.virtualstream.d.ts +131 -0
  16. package/dist_ts/interfaces.virtualstream.js +2 -0
  17. package/package.json +5 -5
  18. package/readme.hints.md +11 -59
  19. package/readme.md +295 -840
  20. package/dist_ts/classes.nativebyteerror.d.ts +0 -26
  21. package/dist_ts/classes.nativebyteerror.js +0 -51
  22. package/dist_ts/classes.nativebytemanager.d.ts +0 -505
  23. package/dist_ts/classes.nativebytemanager.js +0 -3691
  24. package/dist_ts/constants.nativebytes.d.ts +0 -59
  25. package/dist_ts/constants.nativebytes.js +0 -58
  26. package/dist_ts/constants.nativemessages.d.ts +0 -45
  27. package/dist_ts/constants.nativemessages.js +0 -44
  28. package/dist_ts/helpers.nativebytecodec.d.ts +0 -8
  29. package/dist_ts/helpers.nativebytecodec.js +0 -328
  30. package/dist_ts/helpers.nativemessagecodec.d.ts +0 -6
  31. package/dist_ts/helpers.nativemessagecodec.js +0 -267
  32. package/dist_ts/interfaces.nativebytes.d.ts +0 -187
  33. package/dist_ts/interfaces.nativebytes.js +0 -2
  34. package/dist_ts/interfaces.nativemessages.d.ts +0 -144
  35. package/dist_ts/interfaces.nativemessages.js +0 -2
@@ -0,0 +1,131 @@
1
+ import type * as plugins from './plugins.js';
2
+ import type { VIRTUAL_STREAM_FRAME_TYPES, VIRTUAL_STREAM_PROTOCOL } from './constants.virtualstream.js';
3
+ export type TVirtualStreamDirection = plugins.typedrequestInterfaces.TVirtualStreamDirection;
4
+ export type TVirtualStreamAuthorityOperation = 'open' | 'chunk' | 'accept' | 'reject';
5
+ export type TVirtualStreamConnectionBinding = {
6
+ readonly side: 'client';
7
+ readonly generation: number;
8
+ readonly webSocket: WebSocket;
9
+ } | {
10
+ readonly side: 'server';
11
+ readonly peer: plugins.IWebSocketPeer;
12
+ };
13
+ export interface IVirtualStreamDescriptorTransport {
14
+ readonly [key: string]: plugins.typedrequestInterfaces.TVirtualStreamTransportDescriptorPayload;
15
+ readonly capability: string;
16
+ readonly expiresAt: number;
17
+ }
18
+ export interface ITypedSocketVirtualStreamDescriptor<TDirection extends TVirtualStreamDirection = TVirtualStreamDirection> extends plugins.typedrequestInterfaces.IVirtualStreamDescriptor<TDirection> {
19
+ readonly protocol: typeof VIRTUAL_STREAM_PROTOCOL;
20
+ readonly transport: IVirtualStreamDescriptorTransport;
21
+ }
22
+ export interface IVirtualStreamAuthorizationContext {
23
+ readonly target: plugins.IWebSocketPeer;
24
+ readonly creatorDirection: TVirtualStreamDirection;
25
+ readonly contentType?: string;
26
+ readonly integrity?: plugins.typedrequestInterfaces.IVirtualStreamIntegrity;
27
+ }
28
+ export interface IVirtualStreamRevalidationContext {
29
+ readonly operation: TVirtualStreamAuthorityOperation;
30
+ readonly descriptor: ITypedSocketVirtualStreamDescriptor;
31
+ readonly connection: TVirtualStreamConnectionBinding;
32
+ readonly abortSignal: AbortSignal;
33
+ readonly deadline: number;
34
+ }
35
+ export type TVirtualStreamRevalidate = (contextArg: Readonly<IVirtualStreamRevalidationContext>) => boolean | Promise<boolean>;
36
+ export interface IVirtualStreamAuthorizationBinding {
37
+ readonly revalidate: TVirtualStreamRevalidate;
38
+ }
39
+ export interface IVirtualStreamAuthorizationAdapter {
40
+ bind(authorizationArg: unknown, contextArg: Readonly<IVirtualStreamAuthorizationContext>): IVirtualStreamAuthorizationBinding;
41
+ }
42
+ export interface ICreateVirtualStreamOptions<TDirection extends TVirtualStreamDirection = TVirtualStreamDirection> {
43
+ readonly target: {
44
+ readonly peer: plugins.IWebSocketPeer;
45
+ } | plugins.IWebSocketPeer;
46
+ readonly creatorDirection: TDirection;
47
+ readonly contentType?: string;
48
+ readonly integrity?: plugins.typedrequestInterfaces.IVirtualStreamIntegrity;
49
+ readonly authorization: unknown;
50
+ }
51
+ export interface IVirtualStreamCreateRegistrationOptions<TDirection extends TVirtualStreamDirection = TVirtualStreamDirection> {
52
+ readonly creatorDirection: TDirection;
53
+ readonly contentType?: string;
54
+ readonly integrity?: plugins.typedrequestInterfaces.IVirtualStreamIntegrity;
55
+ readonly revalidate?: TVirtualStreamRevalidate;
56
+ }
57
+ export interface IVirtualStreamServerCreateRegistrationOptions<TDirection extends TVirtualStreamDirection = TVirtualStreamDirection> {
58
+ readonly creatorDirection: TDirection;
59
+ readonly contentType?: string;
60
+ readonly integrity?: plugins.typedrequestInterfaces.IVirtualStreamIntegrity;
61
+ readonly revalidate: TVirtualStreamRevalidate;
62
+ }
63
+ export interface IVirtualStreamStats {
64
+ readonly connection: 'none' | 'client' | 'server';
65
+ readonly handshakeReady: boolean;
66
+ readonly registeredCapabilities: number;
67
+ readonly activeStreams: number;
68
+ readonly queuedChunks: number;
69
+ readonly queuedBytes: number;
70
+ readonly rawQueueFrames: number;
71
+ readonly rawQueueBytes: number;
72
+ readonly arrivalStamps: number;
73
+ readonly arrivalStampBytes: number;
74
+ readonly outboundFrames: number;
75
+ readonly retainedRevalidations: number;
76
+ readonly tombstones: number;
77
+ readonly serverConnections: number;
78
+ readonly serverStreams: number;
79
+ readonly serverRetainedRevalidations: number;
80
+ readonly serverRetainedBytes: number;
81
+ }
82
+ export interface IVirtualStreamRuntime {
83
+ now(): number;
84
+ randomBytes(lengthArg: number): Uint8Array;
85
+ setTimer(callbackArg: () => void, delayMsArg: number): unknown;
86
+ clearTimer(timerArg: unknown): void;
87
+ scheduleMacrotask(callbackArg: () => void): unknown;
88
+ }
89
+ export type TVirtualStreamOpenFrame = {
90
+ readonly type: typeof VIRTUAL_STREAM_FRAME_TYPES.OPEN;
91
+ readonly streamId: string;
92
+ readonly capability: string;
93
+ readonly descriptorDigest: string;
94
+ };
95
+ export type TVirtualStreamOpenAckFrame = {
96
+ readonly type: typeof VIRTUAL_STREAM_FRAME_TYPES.OPEN_ACK;
97
+ readonly streamId: string;
98
+ };
99
+ export type TVirtualStreamChunkFrame = {
100
+ readonly type: typeof VIRTUAL_STREAM_FRAME_TYPES.CHUNK;
101
+ readonly streamId: string;
102
+ readonly sequence: number;
103
+ readonly totalLength: number;
104
+ readonly fragmentOffset: number;
105
+ readonly payload: Uint8Array;
106
+ };
107
+ export type TVirtualStreamChunkAckFrame = {
108
+ readonly type: typeof VIRTUAL_STREAM_FRAME_TYPES.CHUNK_ACK;
109
+ readonly streamId: string;
110
+ readonly sequence: number;
111
+ };
112
+ export type TVirtualStreamFinFrame = {
113
+ readonly type: typeof VIRTUAL_STREAM_FRAME_TYPES.FIN;
114
+ readonly streamId: string;
115
+ readonly chunkCount: number;
116
+ readonly byteLength: number;
117
+ };
118
+ export type TVirtualStreamAcceptFrame = {
119
+ readonly type: typeof VIRTUAL_STREAM_FRAME_TYPES.ACCEPT;
120
+ readonly streamId: string;
121
+ readonly chunkCount: number;
122
+ readonly byteLength: number;
123
+ readonly integrityVerified: boolean;
124
+ };
125
+ export type TVirtualStreamResetFrame = {
126
+ readonly type: typeof VIRTUAL_STREAM_FRAME_TYPES.RESET;
127
+ readonly streamId: string;
128
+ readonly code: number;
129
+ readonly reason: string;
130
+ };
131
+ export type TVirtualStreamFrame = TVirtualStreamOpenFrame | TVirtualStreamOpenAckFrame | TVirtualStreamChunkFrame | TVirtualStreamChunkAckFrame | TVirtualStreamFinFrame | TVirtualStreamAcceptFrame | TVirtualStreamResetFrame;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50ZXJmYWNlcy52aXJ0dWFsc3RyZWFtLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvaW50ZXJmYWNlcy52aXJ0dWFsc3RyZWFtLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@api.global/typedsocket",
3
- "version": "6.3.0",
3
+ "version": "7.0.0",
4
4
  "private": false,
5
5
  "description": "A library for creating typed WebSocket connections, supporting bi-directional communication with type safety.",
6
6
  "main": "dist_ts/index.js",
@@ -21,12 +21,12 @@
21
21
  "@git.zone/tsrun": "^2.0.6",
22
22
  "@git.zone/tstest": "^4.0.0",
23
23
  "@push.rocks/smartenv": "^6.1.0",
24
- "@push.rocks/smartserve": "^4.2.1",
24
+ "@push.rocks/smartserve": "^5.1.1",
25
25
  "@types/node": "26.1.2"
26
26
  },
27
27
  "dependencies": {
28
- "@api.global/typedrequest": "^5.2.1",
29
- "@api.global/typedrequest-interfaces": "^5.1.1",
28
+ "@api.global/typedrequest": "^7.0.1",
29
+ "@api.global/typedrequest-interfaces": "^7.0.0",
30
30
  "@push.rocks/smartdelay": "^3.1.0",
31
31
  "@push.rocks/smarthash": "^3.3.0",
32
32
  "@push.rocks/smartjson": "^6.0.1",
@@ -36,7 +36,7 @@
36
36
  "@push.rocks/smarturl": "^3.1.0"
37
37
  },
38
38
  "peerDependencies": {
39
- "@push.rocks/smartserve": ">=4.2.1 <5"
39
+ "@push.rocks/smartserve": ">=5.1.1 <6"
40
40
  },
41
41
  "browserslist": [
42
42
  "last 1 chrome versions"
package/readme.hints.md CHANGED
@@ -1,71 +1,23 @@
1
1
  # TypedSocket Hints
2
2
 
3
- ## TypedSocket 6 Integration
3
+ ## TypedSocket 7 integration findings
4
4
 
5
- TypedSocket 6 requires SmartServe 4.2.1 and TypedRequest 5.2.1. Compose the
6
- TypedSocket server before constructing SmartServe so `webSocketTransportOwner`
7
- is selected for the physical peer at upgrade time.
5
+ 1. `TypedSocket.createServer()` creates a transport routing surface for each application router. SmartServe 5.1.1 must receive `typedSocket.getServerRoutingSurface(applicationRouter)` and the exact `typedSocket.webSocketTransportOwner`; passing the application router directly does not establish the v7 peer authority boundary.
8
6
 
9
- ### Authority Rules
7
+ 2. Construction order is fixed: application routers, `createServer()`, SmartServe construction, `attachSmartServe()`, then `smartServe.start()`. Version 7 intentionally has no `fromSmartServe()` path because routing-surface and transport-owner identities are selected during upgrade.
10
8
 
11
- 1. **Peer identity**: Incoming server handlers call
12
- `getServerConnectionForRequest(typedTools)` to obtain the exact typed transport
13
- connection without assertions. Tag validators receive opaque `connectionId`
14
- and `routingSurfaceId` identities instead of mutable peer/router objects.
9
+ 3. Every peer uses one always-on TypedRequest 7 `IVirtualStreamTransport` with protocol `virtual-stream-v1`. There are no native-byte/native-message capability modes or JSON-only fallback. The exact TypedSocket package major must handshake before application RPC or binary stream traffic is authorized.
15
10
 
16
- 2. **Tags**: Client tags are default-deny exact rules. Authentication, roles,
17
- registration, and reserved names are assigned only with `setServerTag()`.
11
+ 4. Server-initiated TypedRequests require an explicit `ISmartServeConnectionWrapper`. Resolve it from handler tools with `getServerConnectionForRequest()` or from the live target lookup APIs. There is no implicit single-peer targeting.
18
12
 
19
- 3. **Bytes**: Generic legacy VirtualStreams are always denied. Exact native-byte
20
- facades require fixed manifests, principal/revision authority, and durable
21
- confirmation.
13
+ 5. Server-created streams go through `TypedSocket.createVirtualStream()`, which requires an exact target and a synchronous `virtualStreamAuthorizationAdapter.bind()` result containing `revalidate()`. Client-created streams use `virtualStreams.createRegistration()` plus TypedRequest's `VirtualStream.fromRegistration()` on the current handshake-ready generation.
22
14
 
23
- 4. **Messages**: `native-message-v1` is separately negotiated after the primary
24
- negotiation. Its ordinary one-use descriptor is explicit application JSON;
25
- grants expose the descriptor, receiver, open state, revocation, and disposal,
26
- while receivers expose only `receive()`, `closed`, and `reject()`. ACK means
27
- application dequeue, not raw-frame receipt.
15
+ 6. Stream direction in shared DTOs is requester-local and TypedHandler reverses it at the handler boundary. Receivers drain until `undefined` and then call `accept()`; senders call `close()`. Direct receive and `ReadableStream` consumption are mutually exclusive.
28
16
 
29
- 5. **Lifecycle**: Client text work, native frames, callbacks, pending requests,
30
- tag mutations, and server request interests have fixed resource ceilings and
31
- generation fencing. SmartServe settlements authorize only the exact frame
32
- object returned by `pullBinaryFrame()`.
17
+ 7. Client tags remain default-deny and exact-rule based. Authentication and roles belong in protected server tags. Connection restoration runs after the major handshake and before desired tags and `connected` readiness.
33
18
 
34
- 6. **Restoration**: `restoreConnection(context)` runs after both capability
35
- negotiations and before desired tags or `connected`. Use
36
- `context.createTypedRequest()` for authenticated restoration RPCs; it inherits
37
- the restoration deadline and abort signal and becomes invalid afterward.
19
+ 8. `stop()` releases TypedSocket-owned guards, resolvers, pending requests, streams, and router composition. Server stop does not stop SmartServe. Diagnostics use `text` and `virtualStream` scopes and never expose caller-controlled unbounded values.
38
20
 
39
- ### Diagnostics and Close Codes
21
+ ## Release artifact
40
22
 
41
- `diagnosticsSubject` (and `onDiagnostic` on a standalone `NativeByteManager`)
42
- publishes structured invariant-close, peer-rejection, reconnect, tag-denial,
43
- and implicit-targeting events. Emission must never disturb transport paths:
44
- every sink call is try/catch-wrapped. Native message invariant closes use
45
- `scope: 'nativeMessage'`.
46
-
47
- The WebSocket JS `close()` API only permits codes 1000 and 3000-4999. All
48
- client-initiated invariant closes therefore go through
49
- `toClientWebSocketCloseCode()` (1009 -> 4009). Calling `close(1008)` on a real
50
- client WebSocket throws `InvalidAccessError` — under Node/undici that escapes
51
- `onmessage` as an uncaught exception and kills the process, and inside
52
- `NativeByteManager`'s try/catch it silently left the socket open. Server-side
53
- `peer.close()` keeps protocol codes; diagnostics always report the semantic
54
- protocol code.
55
-
56
- ### Source Layout
57
-
58
- Files are named after their main class: `classes.typedsocket.ts`,
59
- `classes.typedsockettagpolicymanager.ts`, `classes.clienttagreconciler.ts`
60
- (client desired/acknowledged tag state machine behind a transport adapter),
61
- `classes.nativebytemanager.ts`, `classes.nativebyteerror.ts`, plus
62
- `helpers.*`, `interfaces.*`, `constants.*`, and `plugins.ts`. The native message
63
- codec/types/constants have `nativemessage` module names but intentionally share
64
- the one manager and transport owner.
65
-
66
- ### Release Artifact
67
-
68
- Only compiled `dist_ts` JavaScript/declarations, package metadata, documentation,
69
- and the license are published. `pnpm run verify:package` performs the deterministic
70
- two-pack entry, hash, metadata, and smoke-import gate (exact artifact count is
71
- asserted in `verify.package.ts` — update it when adding source files).
23
+ The package publishes compiled `dist_ts` JavaScript and declarations, package metadata, `readme.md`, `readme.hints.md`, and `license.md`. Keep examples aligned with root exports from `ts/index.ts`; v6 native modules are no longer published.