@api.global/typedsocket 6.2.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.
@@ -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.2.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",
@@ -19,14 +19,14 @@
19
19
  "@git.zone/tsbuild": "^4.4.2",
20
20
  "@git.zone/tsbundle": "^2.11.3",
21
21
  "@git.zone/tsrun": "^2.0.6",
22
- "@git.zone/tstest": "^3.6.7",
22
+ "@git.zone/tstest": "^4.0.0",
23
23
  "@push.rocks/smartenv": "^6.1.0",
24
- "@push.rocks/smartserve": "^4.2.1",
25
- "@types/node": "26.1.1"
24
+ "@push.rocks/smartserve": "^5.1.1",
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,62 +1,23 @@
1
1
  # TypedSocket Hints
2
2
 
3
- ## TypedSocket 6 Integration
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.
8
-
9
- ### Authority Rules
10
-
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.
15
-
16
- 2. **Tags**: Client tags are default-deny exact rules. Authentication, roles,
17
- registration, and reserved names are assigned only with `setServerTag()`.
18
-
19
- 3. **Bytes**: Generic legacy VirtualStreams are always denied. Exact native-byte
20
- facades require fixed manifests, principal/revision authority, and durable
21
- confirmation.
22
-
23
- 4. **Lifecycle**: Client text work, native frames, callbacks, pending requests,
24
- tag mutations, and server request interests have fixed resource ceilings and
25
- generation fencing. SmartServe settlements authorize only the exact frame
26
- object returned by `pullBinaryFrame()`.
27
-
28
- 5. **Restoration**: `restoreConnection(context)` runs after capability
29
- negotiation and before desired tags or `connected`. Use
30
- `context.createTypedRequest()` for authenticated restoration RPCs; it inherits
31
- the restoration deadline and abort signal and becomes invalid afterward.
32
-
33
- ### Diagnostics and Close Codes
34
-
35
- `diagnosticsSubject` (and `onDiagnostic` on a standalone `NativeByteManager`)
36
- publishes structured invariant-close, peer-rejection, reconnect, tag-denial,
37
- and implicit-targeting events. Emission must never disturb transport paths:
38
- every sink call is try/catch-wrapped.
39
-
40
- The WebSocket JS `close()` API only permits codes 1000 and 3000-4999. All
41
- client-initiated invariant closes therefore go through
42
- `toClientWebSocketCloseCode()` (1009 -> 4009). Calling `close(1008)` on a real
43
- client WebSocket throws `InvalidAccessError` — under Node/undici that escapes
44
- `onmessage` as an uncaught exception and kills the process, and inside
45
- `NativeByteManager`'s try/catch it silently left the socket open. Server-side
46
- `peer.close()` keeps protocol codes; diagnostics always report the semantic
47
- protocol code.
48
-
49
- ### Source Layout
50
-
51
- Files are named after their main class: `classes.typedsocket.ts`,
52
- `classes.typedsockettagpolicymanager.ts`, `classes.clienttagreconciler.ts`
53
- (client desired/acknowledged tag state machine behind a transport adapter),
54
- `classes.nativebytemanager.ts`, `classes.nativebyteerror.ts`, plus
55
- `helpers.*`, `interfaces.*`, `constants.*`, and `plugins.ts`.
56
-
57
- ### Release Artifact
58
-
59
- Only compiled `dist_ts` JavaScript/declarations, package metadata, documentation,
60
- and the license are published. `pnpm run verify:package` performs the deterministic
61
- two-pack entry, hash, metadata, and smoke-import gate (exact artifact count is
62
- asserted in `verify.package.ts` — update it when adding source files).
3
+ ## TypedSocket 7 integration findings
4
+
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.
6
+
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.
8
+
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.
10
+
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.
12
+
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.
14
+
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.
16
+
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.
18
+
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.
20
+
21
+ ## Release artifact
22
+
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.