statewire 0.21.0 → 0.22.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/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 +144 -145
- package/dist/host/socket.d.ts.map +1 -1
- package/dist/host/socket.js +19 -9
- 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 +99 -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 +47 -3
- package/src/host-internal.ts +10 -0
package/dist/host/socket.d.ts
CHANGED
|
@@ -1,174 +1,174 @@
|
|
|
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
|
+
lanes: Map<string, Lane>;
|
|
67
|
+
contexts: Map<string, Statewire.Context>;
|
|
68
|
+
documents: Map<string, StatewireHost.Document>;
|
|
69
|
+
included: Set<string>;
|
|
70
|
+
onIncludedChange: ((included: readonly StatewireHostInternal.IncludedDocument[]) => void) | undefined;
|
|
71
|
+
view: Map<string, {
|
|
72
|
+
doc: number;
|
|
73
|
+
value: unknown;
|
|
74
|
+
}>;
|
|
75
|
+
nextDoc: number;
|
|
76
|
+
pendingApplied: Cmd[];
|
|
77
|
+
pendingCmds: Cmd[];
|
|
78
|
+
attach: StatewireHost.Attach;
|
|
79
79
|
};
|
|
80
80
|
type PendingConn = {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
socket: StatewireHostInternal.Socket;
|
|
82
|
+
open: boolean;
|
|
83
|
+
authorizing: boolean;
|
|
84
|
+
queued: string[];
|
|
85
|
+
timer: ReturnType<typeof setTimeout> | null;
|
|
86
|
+
connection: StatewireHostInternal.SocketConnection | null;
|
|
87
87
|
};
|
|
88
88
|
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
89
|
protocol: string;
|
|
99
|
-
|
|
100
|
-
|
|
90
|
+
seq: number;
|
|
91
|
+
method: string;
|
|
92
|
+
params: unknown;
|
|
93
|
+
meta?: unknown;
|
|
94
|
+
};
|
|
95
|
+
export type ParsedFrame = {
|
|
96
|
+
cmd: CmdStatement[];
|
|
97
|
+
ctx?: {
|
|
98
|
+
protocol: string;
|
|
99
|
+
value: Statewire.Context;
|
|
100
|
+
}[];
|
|
101
101
|
};
|
|
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
|
-
|
|
102
|
+
export declare const parseFrameValue: (frame: unknown) => ParsedFrame;
|
|
103
|
+
export declare const parseFrame: (raw: string) => ParsedFrame;
|
|
104
|
+
export type SocketHostState = {
|
|
105
|
+
protocol: StatewireProtocol.Definition;
|
|
106
|
+
key: readonly string[] | undefined;
|
|
107
|
+
wireVersion: StatewireProtocol.Range;
|
|
108
|
+
heartbeatMs: number;
|
|
109
|
+
maxLeaseLifetimeMs: number | null;
|
|
110
|
+
wsInitTimeoutMs: number;
|
|
111
|
+
maxSubscribers: number;
|
|
112
|
+
maxInflightCommands: number;
|
|
113
|
+
streamQueueSize: number;
|
|
114
|
+
clientRecordLimit: number;
|
|
115
|
+
finOnIdle: boolean;
|
|
116
|
+
pushback: (() => number | null) | undefined;
|
|
117
|
+
authorize: StatewireHostInternal.SocketHostOptions["authorize"];
|
|
118
|
+
clients: Map<string, ClientRec>;
|
|
119
|
+
conns: Set<Conn>;
|
|
120
|
+
pendingConns: Set<PendingConn>;
|
|
121
|
+
pendingOps: WireOp[];
|
|
122
|
+
pendingApplied: Map<string, Cmd[]>;
|
|
123
|
+
pendingCmds: Map<string, Cmd[]>;
|
|
124
|
+
viewsDirty: boolean;
|
|
125
|
+
idleWire: boolean;
|
|
126
|
+
finished: StatewireHost.Fin | null;
|
|
127
|
+
disposed: boolean;
|
|
128
|
+
flushScheduled: boolean;
|
|
129
|
+
heartbeatTimer: ReturnType<typeof setInterval> | null;
|
|
130
|
+
stateHost: StatewireHost.StateHost | null;
|
|
131
|
+
commandsHost: CommandsHost | null;
|
|
132
|
+
current: Statewire<unknown> | null;
|
|
133
|
+
persistence: StatewireHostInternal.SocketHostPersistence | undefined;
|
|
134
|
+
post: () => void;
|
|
135
|
+
connect: (clientId: string, socket: StatewireHostInternal.Socket, options?: StatewireHostInternal.SocketConnectOptions) => StatewireHostInternal.SocketConnection | null;
|
|
136
|
+
finish: (fin: StatewireHost.Fin) => void;
|
|
137
|
+
stream: (request: Request) => Promise<Response>;
|
|
138
|
+
frames: (request: Request) => Promise<Response>;
|
|
139
139
|
};
|
|
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
|
-
|
|
140
|
+
export declare const closeConn: (h: SocketHostState, conn: Conn, code?: number, reason?: string) => void;
|
|
141
|
+
export declare const sendTo: (h: SocketHostState, conn: Conn, data: string) => void;
|
|
142
|
+
export declare const expireLease: (h: SocketHostState, conn: Conn) => boolean;
|
|
143
|
+
export declare const atSubscriberLimit: (h: SocketHostState) => boolean;
|
|
144
|
+
export declare const flush: (h: SocketHostState, fin?: StatewireHost.Fin) => void;
|
|
145
|
+
export type FrameAdmission = {
|
|
146
|
+
type: "ok";
|
|
147
147
|
} | {
|
|
148
|
-
|
|
148
|
+
type: "expired";
|
|
149
149
|
} | {
|
|
150
|
-
|
|
151
|
-
syn: {
|
|
150
|
+
type: "refused";
|
|
152
151
|
syn: {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
syn: {
|
|
153
|
+
protocols: {
|
|
154
|
+
name: string;
|
|
155
|
+
seq: number;
|
|
156
|
+
}[];
|
|
157
|
+
retry?: number;
|
|
158
|
+
};
|
|
158
159
|
};
|
|
159
|
-
};
|
|
160
160
|
};
|
|
161
|
-
declare const admitFrame: (h: SocketHostState, conn: Conn, frame: ParsedFrame) => FrameAdmission;
|
|
162
|
-
type Registration = {
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
export declare const admitFrame: (h: SocketHostState, conn: Conn, frame: ParsedFrame) => FrameAdmission;
|
|
162
|
+
export type Registration = {
|
|
163
|
+
conn: Conn;
|
|
164
|
+
connection: StatewireHostInternal.SocketConnection;
|
|
165
165
|
};
|
|
166
166
|
/**
|
|
167
167
|
* Attach a socket: ephemeral-lane statements of the attach frame are admitted
|
|
168
168
|
* before the snapshot (their documents and answers ride the hello), durable
|
|
169
169
|
* ones after it. A violation in the attach frame closes the attach and throws.
|
|
170
170
|
*/
|
|
171
|
-
declare const register: (h: SocketHostState, clientId: string, socket: StatewireHostInternal.Socket, sawFrame?: boolean, auth?: unknown, selection?: StatewireProtocol.Selection, frame?: ParsedFrame, authorizedAt?: number) => Registration | null;
|
|
171
|
+
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">) => Registration | null;
|
|
172
172
|
/**
|
|
173
173
|
* Transport-agnostic WS binding over a statewire/host transport:
|
|
174
174
|
* feed it sockets (anything with `send`/`close`) and raw text frames, and it
|
|
@@ -178,7 +178,6 @@ declare const register: (h: SocketHostState, clientId: string, socket: Statewire
|
|
|
178
178
|
* admitting attach (ephemeral lanes), per-attach document views, idle edges,
|
|
179
179
|
* and `fin` on finish.
|
|
180
180
|
*/
|
|
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 };
|
|
181
|
+
export declare const StatewireSocketHost: (transport: ResourceElement<Statewire>, options?: StatewireHostInternal.SocketHostOptions, persistence?: StatewireHostInternal.SocketHostPersistence) => StatewireHostInternal.SocketHost;
|
|
182
|
+
export {};
|
|
184
183
|
//# 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,EAAE,qBAAqB,EAAE,4BAAyB;AAY9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAoB;AACrD,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AAC,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,CAC3B,KACL,YAAY,GAAG,IAoKjB,CAAC;AAkMF;;;;;;;;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
|
|
@@ -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
|
};
|
|
@@ -802,7 +811,7 @@ 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)?.connection ?? null;
|
|
814
|
+
return register(h, clientId, socket, options.authorized === true, options.auth, options.selection, void 0, options.authorizedAt, options)?.connection ?? null;
|
|
806
815
|
}
|
|
807
816
|
const refuse = (code, reason) => {
|
|
808
817
|
try {
|
|
@@ -907,7 +916,7 @@ const connectAuthorized = (h, clientId, socket, options) => {
|
|
|
907
916
|
if (pending.timer !== null) clearTimeout(pending.timer);
|
|
908
917
|
let registration;
|
|
909
918
|
try {
|
|
910
|
-
registration = register(h, clientId, socket, true, auth, selection, frame, authorizedAt);
|
|
919
|
+
registration = register(h, clientId, socket, true, auth, selection, frame, authorizedAt, options.onIncludedChange === void 0 ? {} : { onIncludedChange: options.onIncludedChange });
|
|
911
920
|
} catch (error) {
|
|
912
921
|
if (violationReason(error) === null) throw error;
|
|
913
922
|
return;
|
|
@@ -951,7 +960,8 @@ const register = (h, clientId, socket, sawFrame = false, auth = void 0, selectio
|
|
|
951
960
|
name: h.protocol.name,
|
|
952
961
|
version: h.protocol.version
|
|
953
962
|
}]
|
|
954
|
-
}, frame = { cmd: [] }, authorizedAt) => {
|
|
963
|
+
}, frame = { cmd: [] }, authorizedAt, included = {}) => {
|
|
964
|
+
const restored = restoredIncluded(included.included ?? []);
|
|
955
965
|
const refuse = (code, reason) => {
|
|
956
966
|
try {
|
|
957
967
|
socket.close(code, reason);
|
|
@@ -1012,7 +1022,8 @@ const register = (h, clientId, socket, sawFrame = false, auth = void 0, selectio
|
|
|
1012
1022
|
lanes: /* @__PURE__ */ new Map(),
|
|
1013
1023
|
contexts: /* @__PURE__ */ new Map(),
|
|
1014
1024
|
documents: /* @__PURE__ */ new Map(),
|
|
1015
|
-
included:
|
|
1025
|
+
included: restored,
|
|
1026
|
+
onIncludedChange: included.onIncludedChange,
|
|
1016
1027
|
view: /* @__PURE__ */ new Map(),
|
|
1017
1028
|
nextDoc: 1,
|
|
1018
1029
|
pendingApplied: [],
|
|
@@ -1258,7 +1269,6 @@ const StatewireSocketHost = (transport, options, persistence) => {
|
|
|
1258
1269
|
}
|
|
1259
1270
|
};
|
|
1260
1271
|
};
|
|
1261
|
-
//#endregion
|
|
1262
1272
|
export { CLIENT_ID_RE, PRINCIPAL_MISMATCH_MESSAGE, SUBSCRIBER_LIMIT_MESSAGE, StatewireSocketHost, admitFrame, atSubscriberLimit, authEquals, closeConn, expireLease, flush, parseFrame, parseFrameValue, register, sendTo };
|
|
1263
1273
|
|
|
1264
1274
|
//# sourceMappingURL=socket.js.map
|