statewire 0.21.0 → 0.22.1
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/client/changes.d.ts +3 -6
- package/dist/client/changes.d.ts.map +1 -1
- package/dist/client/changes.js +1 -2
- package/dist/client/connection.d.ts +80 -83
- package/dist/client/connection.d.ts.map +1 -1
- package/dist/client/connection.js +2 -3
- package/dist/client/connection.js.map +1 -1
- package/dist/client/core.d.ts +39 -41
- package/dist/client/core.d.ts.map +1 -1
- package/dist/client/core.js +2 -3
- package/dist/client/session.d.ts +93 -95
- package/dist/client/session.d.ts.map +1 -1
- package/dist/client/session.js +6 -7
- package/dist/client/session.js.map +1 -1
- package/dist/client/sessionStore.d.ts +11 -14
- package/dist/client/sessionStore.d.ts.map +1 -1
- package/dist/client/sessionStore.js +1 -2
- package/dist/client/storageError.d.ts +2 -5
- package/dist/client/storageError.d.ts.map +1 -1
- package/dist/client/storageError.js +1 -2
- package/dist/client/timing.d.ts +11 -14
- package/dist/client/timing.d.ts.map +1 -1
- package/dist/client/timing.js +1 -2
- package/dist/document.d.ts +17 -20
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +1 -2
- package/dist/host/adapter.d.ts +4 -7
- package/dist/host/adapter.d.ts.map +1 -1
- package/dist/host/adapter.js +1 -2
- package/dist/host/draft.d.ts +13 -16
- package/dist/host/draft.d.ts.map +1 -1
- package/dist/host/draft.js +1 -2
- package/dist/host/engine.d.ts +7 -10
- package/dist/host/engine.d.ts.map +1 -1
- package/dist/host/engine.js +1 -2
- package/dist/host/host.d.ts +42 -45
- package/dist/host/host.d.ts.map +1 -1
- package/dist/host/host.js +1 -2
- package/dist/host/http.d.ts +4 -7
- package/dist/host/http.d.ts.map +1 -1
- package/dist/host/http.js +2 -3
- package/dist/host/socket.d.ts +148 -145
- package/dist/host/socket.d.ts.map +1 -1
- package/dist/host/socket.js +30 -12
- package/dist/host/socket.js.map +1 -1
- package/dist/host/synced.d.ts +3 -6
- package/dist/host/synced.d.ts.map +1 -1
- package/dist/host/synced.js +1 -2
- package/dist/host/work.d.ts +2 -5
- package/dist/host/work.d.ts.map +1 -1
- package/dist/host/work.js +1 -2
- package/dist/host-internal.d.ts +101 -93
- package/dist/host-internal.d.ts.map +1 -1
- package/dist/host.d.ts +90 -91
- package/dist/host.d.ts.map +1 -1
- package/dist/index.d.ts +11 -8
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/statewire.d.ts +265 -268
- package/dist/statewire.d.ts.map +1 -1
- package/dist/statewire.js +1 -2
- package/dist/storage.d.ts +23 -26
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +1 -2
- package/dist/transports/fake-sse.d.ts +7 -10
- package/dist/transports/fake-sse.d.ts.map +1 -1
- package/dist/transports/fake-sse.js +1 -2
- package/dist/transports/fixtures.d.ts +19 -25
- package/dist/transports/fixtures.d.ts.map +1 -1
- package/dist/transports/fixtures.js +1 -2
- package/dist/transports/remote.d.ts +8 -11
- package/dist/transports/remote.d.ts.map +1 -1
- package/dist/transports/remote.js +1 -2
- package/dist/transports/sse-parser.d.ts +1 -4
- package/dist/transports/sse-parser.d.ts.map +1 -1
- package/dist/transports/sse-parser.js +1 -2
- package/dist/transports/sse.d.ts +50 -53
- package/dist/transports/sse.d.ts.map +1 -1
- package/dist/transports/sse.js +2 -3
- package/dist/transports/testing.d.ts +31 -34
- package/dist/transports/testing.d.ts.map +1 -1
- package/dist/transports/testing.js +1 -2
- package/dist/transports/ws.d.ts +5 -7
- package/dist/transports/ws.d.ts.map +1 -1
- package/dist/transports/ws.js +3 -4
- package/dist/transports/ws.js.map +1 -1
- package/dist/types.d.ts +81 -78
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -2
- package/dist/util/draftTraps.d.ts +2 -4
- package/dist/util/draftTraps.d.ts.map +1 -1
- package/dist/util/draftTraps.js +1 -2
- package/dist/util/macrotask.d.ts +1 -4
- package/dist/util/macrotask.d.ts.map +1 -1
- package/dist/util/macrotask.js +1 -2
- package/dist/util/methodProxy.d.ts +1 -4
- package/dist/util/methodProxy.d.ts.map +1 -1
- package/dist/util/methodProxy.js +1 -2
- package/dist/util/randomId.d.ts +1 -4
- package/dist/util/randomId.d.ts.map +1 -1
- package/dist/util/randomId.js +1 -2
- package/dist/util/recordMutations.d.ts +5 -7
- package/dist/util/recordMutations.d.ts.map +1 -1
- package/dist/util/recordMutations.js +1 -2
- package/dist/util/statePath.d.ts +9 -12
- package/dist/util/statePath.d.ts.map +1 -1
- package/dist/util/statePath.js +1 -2
- package/dist/wire/context.d.ts +7 -12
- package/dist/wire/context.d.ts.map +1 -1
- package/dist/wire/context.js +2 -3
- package/dist/wire/documents.d.ts +36 -39
- package/dist/wire/documents.d.ts.map +1 -1
- package/dist/wire/documents.js +2 -3
- package/dist/wire/documents.js.map +1 -1
- package/dist/wire/limits.d.ts +7 -10
- package/dist/wire/limits.d.ts.map +1 -1
- package/dist/wire/limits.js +1 -2
- package/dist/wire/meta.d.ts +9 -11
- package/dist/wire/meta.d.ts.map +1 -1
- package/dist/wire/meta.js +1 -2
- package/dist/wire/meta.js.map +1 -1
- package/dist/wire/ops.d.ts +9 -12
- package/dist/wire/ops.d.ts.map +1 -1
- package/dist/wire/ops.js +1 -2
- package/dist/wire/protocol.d.ts +53 -56
- package/dist/wire/protocol.d.ts.map +1 -1
- package/dist/wire/protocol.js +1 -2
- package/dist/wire/version.d.ts +1 -4
- package/dist/wire/version.d.ts.map +1 -1
- package/dist/wire/version.js +1 -2
- package/package.json +6 -6
- package/src/client/connection.ts +13 -15
- package/src/host/socket.ts +63 -6
- package/src/host-internal.ts +12 -0
package/dist/host/socket.d.ts
CHANGED
|
@@ -1,174 +1,178 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
declare const
|
|
11
|
-
declare const PRINCIPAL_MISMATCH_MESSAGE = "client id is bound to another principal";
|
|
1
|
+
import type { StatewireProtocol } from "../wire/protocol.js";
|
|
2
|
+
import type { ResourceElement } from "@assistant-ui/tap";
|
|
3
|
+
import type { CommandsHost } from "./host.js";
|
|
4
|
+
import type { Statewire } from "../types.js";
|
|
5
|
+
import type { StatewireHost } from "../host.js";
|
|
6
|
+
import type { StatewireHostInternal } from "../host-internal.js";
|
|
7
|
+
import type { StatewireDocument } from "../document.js";
|
|
8
|
+
import type { StatewirePath } from "../wire/ops.js";
|
|
9
|
+
export declare const CLIENT_ID_RE: RegExp;
|
|
10
|
+
export declare const PRINCIPAL_MISMATCH_MESSAGE = "client id is bound to another principal";
|
|
12
11
|
/** Structural equality over auth values: primitives, Dates, arrays, and plain
|
|
13
12
|
* objects compare by value; anything else by identity. */
|
|
14
|
-
declare const authEquals: (a: unknown, b: unknown) => boolean;
|
|
15
|
-
declare const SUBSCRIBER_LIMIT_MESSAGE = "stream subscriber limit reached";
|
|
13
|
+
export declare const authEquals: (a: unknown, b: unknown) => boolean;
|
|
14
|
+
export declare const SUBSCRIBER_LIMIT_MESSAGE = "stream subscriber limit reached";
|
|
16
15
|
type Cmd = StatewireHostInternal.Cmd;
|
|
17
16
|
type WireOp = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
op: string;
|
|
18
|
+
doc?: number;
|
|
19
|
+
path?: StatewirePath;
|
|
20
|
+
value?: unknown;
|
|
21
|
+
meta?: StatewireDocument.MetaEntry[];
|
|
22
|
+
protocol?: string;
|
|
23
|
+
key?: readonly string[];
|
|
24
|
+
main?: boolean;
|
|
26
25
|
};
|
|
27
26
|
type Admission = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
protocol: string;
|
|
28
|
+
seq: number;
|
|
29
|
+
method: string;
|
|
30
|
+
applied: boolean;
|
|
31
|
+
appliedSent: boolean;
|
|
32
|
+
settled: boolean;
|
|
34
33
|
};
|
|
35
34
|
/** One statement lane: durable lanes live on the client record, ephemeral lanes on the attach. */
|
|
36
35
|
type Lane = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
protocol: string;
|
|
37
|
+
clientId: string;
|
|
38
|
+
conn: Conn | null;
|
|
39
|
+
lastSeq: number;
|
|
40
|
+
results: Map<number, {
|
|
41
|
+
ts: number;
|
|
42
|
+
cmd: Cmd;
|
|
43
|
+
}>;
|
|
44
|
+
inflight: Map<number, Admission>;
|
|
46
45
|
};
|
|
47
|
-
type ClientRec = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
export type ClientRec = {
|
|
47
|
+
id: string;
|
|
48
|
+
touched: number;
|
|
49
|
+
lanes: Map<string, Lane>;
|
|
50
|
+
/** The auth captured at the record's first attach; later attaches must match. */
|
|
51
|
+
principal: unknown;
|
|
53
52
|
};
|
|
54
|
-
type Conn = {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
53
|
+
export type Conn = {
|
|
54
|
+
selection: StatewireProtocol.Selection;
|
|
55
|
+
clientId: string;
|
|
56
|
+
socket: StatewireHostInternal.Socket;
|
|
57
|
+
open: boolean;
|
|
58
|
+
ready: boolean;
|
|
59
|
+
sawFrame: boolean;
|
|
60
|
+
lastSentAt: number;
|
|
61
|
+
lease: string | null;
|
|
62
|
+
/** The awaited `authorize` return captured at this attach's authorization. */
|
|
63
|
+
auth: unknown;
|
|
64
|
+
authorizedAt: number | undefined;
|
|
65
|
+
leaseTimer: ReturnType<typeof setTimeout> | null;
|
|
66
|
+
timedLease: boolean;
|
|
67
|
+
lanes: Map<string, Lane>;
|
|
68
|
+
contexts: Map<string, Statewire.Context>;
|
|
69
|
+
documents: Map<string, StatewireHost.Document>;
|
|
70
|
+
included: Set<string>;
|
|
71
|
+
onIncludedChange: ((included: readonly StatewireHostInternal.IncludedDocument[]) => void) | undefined;
|
|
72
|
+
view: Map<string, {
|
|
73
|
+
doc: number;
|
|
74
|
+
value: unknown;
|
|
75
|
+
}>;
|
|
76
|
+
nextDoc: number;
|
|
77
|
+
pendingApplied: Cmd[];
|
|
78
|
+
pendingCmds: Cmd[];
|
|
79
|
+
attach: StatewireHost.Attach;
|
|
79
80
|
};
|
|
80
81
|
type PendingConn = {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
socket: StatewireHostInternal.Socket;
|
|
83
|
+
open: boolean;
|
|
84
|
+
authorizing: boolean;
|
|
85
|
+
queued: string[];
|
|
86
|
+
timer: ReturnType<typeof setTimeout> | null;
|
|
87
|
+
connection: StatewireHostInternal.SocketConnection | null;
|
|
87
88
|
};
|
|
88
89
|
type CmdStatement = {
|
|
89
|
-
protocol: string;
|
|
90
|
-
seq: number;
|
|
91
|
-
method: string;
|
|
92
|
-
params: unknown;
|
|
93
|
-
meta?: unknown;
|
|
94
|
-
};
|
|
95
|
-
type ParsedFrame = {
|
|
96
|
-
cmd: CmdStatement[];
|
|
97
|
-
ctx?: {
|
|
98
90
|
protocol: string;
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
seq: number;
|
|
92
|
+
method: string;
|
|
93
|
+
params: unknown;
|
|
94
|
+
meta?: unknown;
|
|
95
|
+
};
|
|
96
|
+
export type ParsedFrame = {
|
|
97
|
+
cmd: CmdStatement[];
|
|
98
|
+
ctx?: {
|
|
99
|
+
protocol: string;
|
|
100
|
+
value: Statewire.Context;
|
|
101
|
+
}[];
|
|
101
102
|
};
|
|
102
|
-
declare const parseFrameValue: (frame: unknown) => ParsedFrame;
|
|
103
|
-
declare const parseFrame: (raw: string) => ParsedFrame;
|
|
104
|
-
type SocketHostState = {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
103
|
+
export declare const parseFrameValue: (frame: unknown) => ParsedFrame;
|
|
104
|
+
export declare const parseFrame: (raw: string) => ParsedFrame;
|
|
105
|
+
export type SocketHostState = {
|
|
106
|
+
protocol: StatewireProtocol.Definition;
|
|
107
|
+
key: readonly string[] | undefined;
|
|
108
|
+
wireVersion: StatewireProtocol.Range;
|
|
109
|
+
heartbeatMs: number;
|
|
110
|
+
maxLeaseLifetimeMs: number | null;
|
|
111
|
+
leaseTimers: boolean;
|
|
112
|
+
wsInitTimeoutMs: number;
|
|
113
|
+
maxSubscribers: number;
|
|
114
|
+
maxInflightCommands: number;
|
|
115
|
+
streamQueueSize: number;
|
|
116
|
+
clientRecordLimit: number;
|
|
117
|
+
finOnIdle: boolean;
|
|
118
|
+
pushback: (() => number | null) | undefined;
|
|
119
|
+
authorize: StatewireHostInternal.SocketHostOptions["authorize"];
|
|
120
|
+
clients: Map<string, ClientRec>;
|
|
121
|
+
conns: Set<Conn>;
|
|
122
|
+
pendingConns: Set<PendingConn>;
|
|
123
|
+
pendingOps: WireOp[];
|
|
124
|
+
pendingApplied: Map<string, Cmd[]>;
|
|
125
|
+
pendingCmds: Map<string, Cmd[]>;
|
|
126
|
+
viewsDirty: boolean;
|
|
127
|
+
idleWire: boolean;
|
|
128
|
+
finished: StatewireHost.Fin | null;
|
|
129
|
+
disposed: boolean;
|
|
130
|
+
flushScheduled: boolean;
|
|
131
|
+
heartbeatTimer: ReturnType<typeof setInterval> | null;
|
|
132
|
+
stateHost: StatewireHost.StateHost | null;
|
|
133
|
+
commandsHost: CommandsHost | null;
|
|
134
|
+
current: Statewire<unknown> | null;
|
|
135
|
+
persistence: StatewireHostInternal.SocketHostPersistence | undefined;
|
|
136
|
+
post: () => void;
|
|
137
|
+
connect: (clientId: string, socket: StatewireHostInternal.Socket, options?: StatewireHostInternal.SocketConnectOptions) => StatewireHostInternal.SocketConnection | null;
|
|
138
|
+
finish: (fin: StatewireHost.Fin) => void;
|
|
139
|
+
stream: (request: Request) => Promise<Response>;
|
|
140
|
+
frames: (request: Request) => Promise<Response>;
|
|
139
141
|
};
|
|
140
|
-
declare const closeConn: (h: SocketHostState, conn: Conn, code?: number, reason?: string) => void;
|
|
141
|
-
declare const sendTo: (h: SocketHostState, conn: Conn, data: string) => void;
|
|
142
|
-
declare const expireLease: (h: SocketHostState, conn: Conn) => boolean;
|
|
143
|
-
declare const atSubscriberLimit: (h: SocketHostState) => boolean;
|
|
144
|
-
declare const flush: (h: SocketHostState, fin?: StatewireHost.Fin) => void;
|
|
145
|
-
type FrameAdmission = {
|
|
146
|
-
|
|
142
|
+
export declare const closeConn: (h: SocketHostState, conn: Conn, code?: number, reason?: string) => void;
|
|
143
|
+
export declare const sendTo: (h: SocketHostState, conn: Conn, data: string) => void;
|
|
144
|
+
export declare const expireLease: (h: SocketHostState, conn: Conn) => boolean;
|
|
145
|
+
export declare const atSubscriberLimit: (h: SocketHostState) => boolean;
|
|
146
|
+
export declare const flush: (h: SocketHostState, fin?: StatewireHost.Fin) => void;
|
|
147
|
+
export type FrameAdmission = {
|
|
148
|
+
type: "ok";
|
|
147
149
|
} | {
|
|
148
|
-
|
|
150
|
+
type: "expired";
|
|
149
151
|
} | {
|
|
150
|
-
|
|
151
|
-
syn: {
|
|
152
|
+
type: "refused";
|
|
152
153
|
syn: {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
syn: {
|
|
155
|
+
protocols: {
|
|
156
|
+
name: string;
|
|
157
|
+
seq: number;
|
|
158
|
+
}[];
|
|
159
|
+
retry?: number;
|
|
160
|
+
};
|
|
158
161
|
};
|
|
159
|
-
};
|
|
160
162
|
};
|
|
161
|
-
declare const admitFrame: (h: SocketHostState, conn: Conn, frame: ParsedFrame) => FrameAdmission;
|
|
162
|
-
type Registration = {
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
export declare const admitFrame: (h: SocketHostState, conn: Conn, frame: ParsedFrame) => FrameAdmission;
|
|
164
|
+
export type Registration = {
|
|
165
|
+
conn: Conn;
|
|
166
|
+
connection: StatewireHostInternal.SocketConnection;
|
|
165
167
|
};
|
|
166
168
|
/**
|
|
167
169
|
* Attach a socket: ephemeral-lane statements of the attach frame are admitted
|
|
168
170
|
* before the snapshot (their documents and answers ride the hello), durable
|
|
169
171
|
* ones after it. A violation in the attach frame closes the attach and throws.
|
|
170
172
|
*/
|
|
171
|
-
declare const register: (h: SocketHostState, clientId: string, socket: StatewireHostInternal.Socket, sawFrame?: boolean, auth?: unknown, selection?: StatewireProtocol.Selection, frame?: ParsedFrame, authorizedAt?: number
|
|
173
|
+
export declare const register: (h: SocketHostState, clientId: string, socket: StatewireHostInternal.Socket, sawFrame?: boolean, auth?: unknown, selection?: StatewireProtocol.Selection, frame?: ParsedFrame, authorizedAt?: number, included?: Pick<StatewireHostInternal.SocketConnectOptions, "included" | "onIncludedChange"> & {
|
|
174
|
+
timedLease?: boolean;
|
|
175
|
+
}) => Registration | null;
|
|
172
176
|
/**
|
|
173
177
|
* Transport-agnostic WS binding over a statewire/host transport:
|
|
174
178
|
* feed it sockets (anything with `send`/`close`) and raw text frames, and it
|
|
@@ -178,7 +182,6 @@ declare const register: (h: SocketHostState, clientId: string, socket: Statewire
|
|
|
178
182
|
* admitting attach (ephemeral lanes), per-attach document views, idle edges,
|
|
179
183
|
* and `fin` on finish.
|
|
180
184
|
*/
|
|
181
|
-
declare const StatewireSocketHost: (transport: ResourceElement<Statewire>, options?: StatewireHostInternal.SocketHostOptions, persistence?: StatewireHostInternal.SocketHostPersistence) => StatewireHostInternal.SocketHost;
|
|
182
|
-
|
|
183
|
-
export { CLIENT_ID_RE, ClientRec, Conn, FrameAdmission, PRINCIPAL_MISMATCH_MESSAGE, ParsedFrame, Registration, SUBSCRIBER_LIMIT_MESSAGE, SocketHostState, StatewireSocketHost, admitFrame, atSubscriberLimit, authEquals, closeConn, expireLease, flush, parseFrame, parseFrameValue, register, sendTo };
|
|
185
|
+
export declare const StatewireSocketHost: (transport: ResourceElement<Statewire>, options?: StatewireHostInternal.SocketHostOptions, persistence?: StatewireHostInternal.SocketHostPersistence) => StatewireHostInternal.SocketHost;
|
|
186
|
+
export {};
|
|
184
187
|
//# sourceMappingURL=socket.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket.d.ts","
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../src/host/socket.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,4BAAyB;AAG1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,KAAK,EAAE,YAAY,EAAmB,kBAAe;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAiB;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAgB;AAC7C,OAAO,KAAK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e,EAClB,MAAM,IAAI,EACV,OAAO,WAAW,KACjB,cA8DF,CAAC;AA2WF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,IAAI,CAAC;IACX,UAAU,EAAE,qBAAqB,CAAC,gBAAgB,CAAC;CACpD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GACnB,GAAG,eAAe,EAClB,UAAU,MAAM,EAChB,QAAQ,qBAAqB,CAAC,MAAM,EACpC,kBAAgB,EAChB,OAAM,OAAmB,EACzB,YAAW,iBAAiB,CAAC,SAG5B,EACD,QAAO,WAAyB,EAChC,eAAe,MAAM,EACrB,WAAU,IAAI,CACZ,qBAAqB,CAAC,oBAAoB,EAC1C,UAAU,GAAG,kBAAkB,CAChC,GAAG;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,KAChC,YAAY,GAAG,IAqKjB,CAAC;AAmMF;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAC9B,WAAW,eAAe,CAAC,SAAS,CAAC,EACrC,UAAU,qBAAqB,CAAC,iBAAiB,EACjD,cAAc,qBAAqB,CAAC,qBAAqB,KACxD,qBAAqB,CAAC,UAqBxB,CAAC"}
|
package/dist/host/socket.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { DEFAULT_PROTOCOL, WIRE_VERSION, negotiateProtocols } from "../wire/protocol.js";
|
|
1
2
|
import { encodeDocument, reviveDocumentValue } from "../document.js";
|
|
2
3
|
import { COMMAND_CAPACITY_RETRY_MS, MAX_INFLIGHT_COMMANDS_PER_HOST } from "../wire/limits.js";
|
|
3
|
-
import { DEFAULT_PROTOCOL, WIRE_VERSION, negotiateProtocols } from "../wire/protocol.js";
|
|
4
4
|
import { captureContext, contextValue } from "../wire/context.js";
|
|
5
5
|
import { sanitizeValue } from "../wire/ops.js";
|
|
6
6
|
import { StatewireSendError } from "../types.js";
|
|
@@ -9,7 +9,7 @@ import { createMacrotaskPoster } from "../util/macrotask.js";
|
|
|
9
9
|
import { frames, stream } from "./http.js";
|
|
10
10
|
import { useEffect, useState } from "@assistant-ui/tap/react-shim";
|
|
11
11
|
import { createTapRoot, flushTapSync, useResource } from "@assistant-ui/tap";
|
|
12
|
-
|
|
12
|
+
// src/host/socket.ts
|
|
13
13
|
const CLIENT_ID_RE = /^[A-Za-z0-9._~-]{1,256}$/;
|
|
14
14
|
const PRINCIPAL_MISMATCH_MESSAGE = "client id is bound to another principal";
|
|
15
15
|
/** Structural equality over auth values: primitives, Dates, arrays, and plain
|
|
@@ -256,7 +256,7 @@ const expireLease = (h, conn) => {
|
|
|
256
256
|
const armLeaseTimer = (h, conn) => {
|
|
257
257
|
if (conn.leaseTimer !== null) clearTimeout(conn.leaseTimer);
|
|
258
258
|
conn.leaseTimer = null;
|
|
259
|
-
if (h.disposed || h.maxLeaseLifetimeMs === null || expireLease(h, conn)) return;
|
|
259
|
+
if (h.disposed || h.maxLeaseLifetimeMs === null || expireLease(h, conn) || !conn.timedLease) return;
|
|
260
260
|
const delay = h.maxLeaseLifetimeMs - (Date.now() - conn.authorizedAt);
|
|
261
261
|
conn.leaseTimer = setTimeout(() => {
|
|
262
262
|
conn.leaseTimer = null;
|
|
@@ -276,7 +276,7 @@ const ensureHeartbeat = (h) => {
|
|
|
276
276
|
if (h.heartbeatTimer !== null || h.heartbeatMs <= 0) return;
|
|
277
277
|
h.heartbeatTimer = setInterval(() => {
|
|
278
278
|
const now = Date.now();
|
|
279
|
-
for (const conn of [...h.conns]) if (now - conn.lastSentAt >= h.heartbeatMs) sendTo(h, conn, "{}");
|
|
279
|
+
for (const conn of [...h.conns]) if (now - conn.lastSentAt >= h.heartbeatMs && !expireLease(h, conn)) sendTo(h, conn, "{}");
|
|
280
280
|
}, h.heartbeatMs);
|
|
281
281
|
h.heartbeatTimer.unref?.();
|
|
282
282
|
};
|
|
@@ -354,6 +354,11 @@ const diffView = (h, conn) => {
|
|
|
354
354
|
}
|
|
355
355
|
return ops;
|
|
356
356
|
};
|
|
357
|
+
const notifyIncluded = (conn) => conn.onIncludedChange?.([...conn.included].map((id) => JSON.parse(id)));
|
|
358
|
+
const restoredIncluded = (included) => new Set(included.map((entry) => {
|
|
359
|
+
if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string" || !(entry[1] === null || Array.isArray(entry[1]) && entry[1].every((part) => typeof part === "string"))) throw new TypeError("statewire: invalid restored include");
|
|
360
|
+
return documentIdentity(entry[0], entry[1] ?? void 0);
|
|
361
|
+
}));
|
|
357
362
|
const attachOf = (h, conn) => {
|
|
358
363
|
const requireSelected = (protocol) => {
|
|
359
364
|
const entry = conn.selection.protocols.find((p) => p.name === protocol);
|
|
@@ -396,11 +401,15 @@ const attachOf = (h, conn) => {
|
|
|
396
401
|
},
|
|
397
402
|
include: (protocol, key) => {
|
|
398
403
|
if (requireSelected(protocol).record !== void 0) throw new Error(`statewire: protocol ${protocol} is not durable`);
|
|
399
|
-
|
|
404
|
+
const id = documentIdentity(protocol, key);
|
|
405
|
+
if (conn.included.has(id)) return;
|
|
406
|
+
conn.included.add(id);
|
|
407
|
+
notifyIncluded(conn);
|
|
400
408
|
markViews(h);
|
|
401
409
|
},
|
|
402
410
|
exclude: (protocol, key) => {
|
|
403
|
-
conn.included.delete(documentIdentity(protocol, key));
|
|
411
|
+
if (!conn.included.delete(documentIdentity(protocol, key))) return;
|
|
412
|
+
notifyIncluded(conn);
|
|
404
413
|
markViews(h);
|
|
405
414
|
}
|
|
406
415
|
};
|
|
@@ -425,7 +434,7 @@ const flush = (h, fin) => {
|
|
|
425
434
|
h.pendingApplied = /* @__PURE__ */ new Map();
|
|
426
435
|
h.pendingCmds = /* @__PURE__ */ new Map();
|
|
427
436
|
for (const conn of [...h.conns]) {
|
|
428
|
-
if (!conn.ready) continue;
|
|
437
|
+
if (!conn.ready || expireLease(h, conn)) continue;
|
|
429
438
|
const forConn = (list) => (list ?? []).filter((cmd) => selects(conn, cmd.protocol));
|
|
430
439
|
const ops = [...selects(conn, h.protocol.name) ? mainOps : [], ...diffView(h, conn)];
|
|
431
440
|
const cmd = [
|
|
@@ -802,7 +811,10 @@ const connectAuthorized = (h, clientId, socket, options) => {
|
|
|
802
811
|
} catch {}
|
|
803
812
|
return null;
|
|
804
813
|
}
|
|
805
|
-
return register(h, clientId, socket, options.authorized === true, options.auth, options.selection, void 0, options.authorizedAt
|
|
814
|
+
return register(h, clientId, socket, options.authorized === true, options.auth, options.selection, void 0, options.authorizedAt, {
|
|
815
|
+
...options,
|
|
816
|
+
timedLease: h.leaseTimers
|
|
817
|
+
})?.connection ?? null;
|
|
806
818
|
}
|
|
807
819
|
const refuse = (code, reason) => {
|
|
808
820
|
try {
|
|
@@ -907,7 +919,10 @@ const connectAuthorized = (h, clientId, socket, options) => {
|
|
|
907
919
|
if (pending.timer !== null) clearTimeout(pending.timer);
|
|
908
920
|
let registration;
|
|
909
921
|
try {
|
|
910
|
-
registration = register(h, clientId, socket, true, auth, selection, frame, authorizedAt
|
|
922
|
+
registration = register(h, clientId, socket, true, auth, selection, frame, authorizedAt, {
|
|
923
|
+
timedLease: h.leaseTimers,
|
|
924
|
+
...options.onIncludedChange !== void 0 && { onIncludedChange: options.onIncludedChange }
|
|
925
|
+
});
|
|
911
926
|
} catch (error) {
|
|
912
927
|
if (violationReason(error) === null) throw error;
|
|
913
928
|
return;
|
|
@@ -951,7 +966,8 @@ const register = (h, clientId, socket, sawFrame = false, auth = void 0, selectio
|
|
|
951
966
|
name: h.protocol.name,
|
|
952
967
|
version: h.protocol.version
|
|
953
968
|
}]
|
|
954
|
-
}, frame = { cmd: [] }, authorizedAt) => {
|
|
969
|
+
}, frame = { cmd: [] }, authorizedAt, included = {}) => {
|
|
970
|
+
const restored = restoredIncluded(included.included ?? []);
|
|
955
971
|
const refuse = (code, reason) => {
|
|
956
972
|
try {
|
|
957
973
|
socket.close(code, reason);
|
|
@@ -1009,10 +1025,12 @@ const register = (h, clientId, socket, sawFrame = false, auth = void 0, selectio
|
|
|
1009
1025
|
auth,
|
|
1010
1026
|
authorizedAt,
|
|
1011
1027
|
leaseTimer: null,
|
|
1028
|
+
timedLease: included.timedLease ?? true,
|
|
1012
1029
|
lanes: /* @__PURE__ */ new Map(),
|
|
1013
1030
|
contexts: /* @__PURE__ */ new Map(),
|
|
1014
1031
|
documents: /* @__PURE__ */ new Map(),
|
|
1015
|
-
included:
|
|
1032
|
+
included: restored,
|
|
1033
|
+
onIncludedChange: included.onIncludedChange,
|
|
1016
1034
|
view: /* @__PURE__ */ new Map(),
|
|
1017
1035
|
nextDoc: 1,
|
|
1018
1036
|
pendingApplied: [],
|
|
@@ -1153,6 +1171,7 @@ const useSocketHost = (transport, options, persistence) => {
|
|
|
1153
1171
|
wireVersion: { version: WIRE_VERSION },
|
|
1154
1172
|
heartbeatMs: 15e3,
|
|
1155
1173
|
maxLeaseLifetimeMs: 864e5,
|
|
1174
|
+
leaseTimers: persistence?.hibernatable !== true,
|
|
1156
1175
|
wsInitTimeoutMs: 5e3,
|
|
1157
1176
|
maxSubscribers: MAX_SUBSCRIBERS,
|
|
1158
1177
|
maxInflightCommands: MAX_INFLIGHT_COMMANDS_PER_HOST,
|
|
@@ -1258,7 +1277,6 @@ const StatewireSocketHost = (transport, options, persistence) => {
|
|
|
1258
1277
|
}
|
|
1259
1278
|
};
|
|
1260
1279
|
};
|
|
1261
|
-
//#endregion
|
|
1262
1280
|
export { CLIENT_ID_RE, PRINCIPAL_MISMATCH_MESSAGE, SUBSCRIBER_LIMIT_MESSAGE, StatewireSocketHost, admitFrame, atSubscriberLimit, authEquals, closeConn, expireLease, flush, parseFrame, parseFrameValue, register, sendTo };
|
|
1263
1281
|
|
|
1264
1282
|
//# sourceMappingURL=socket.js.map
|