@fuzdev/fuz_app 0.178.0 → 0.180.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/actions/CLAUDE.md +106 -0
- package/dist/actions/connection_registry.d.ts +18 -0
- package/dist/actions/connection_registry.d.ts.map +1 -1
- package/dist/actions/connection_registry.js +23 -0
- package/dist/actions/room_action_specs.d.ts +733 -0
- package/dist/actions/room_action_specs.d.ts.map +1 -0
- package/dist/actions/room_action_specs.js +506 -0
- package/dist/actions/room_actions.d.ts +276 -0
- package/dist/actions/room_actions.d.ts.map +1 -0
- package/dist/actions/room_actions.js +394 -0
- package/dist/actions/room_client.svelte.d.ts +399 -0
- package/dist/actions/room_client.svelte.d.ts.map +1 -0
- package/dist/actions/room_client.svelte.js +942 -0
- package/dist/actions/room_registry.d.ts +454 -0
- package/dist/actions/room_registry.d.ts.map +1 -0
- package/dist/actions/room_registry.js +927 -0
- package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
- package/dist/auth/role_grant_queries.d.ts +17 -0
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +30 -0
- package/dist/rtc/rtc_mesh.svelte.d.ts +102 -0
- package/dist/rtc/rtc_mesh.svelte.d.ts.map +1 -0
- package/dist/rtc/rtc_mesh.svelte.js +232 -0
- package/dist/rtc/rtc_peer.svelte.d.ts +180 -0
- package/dist/rtc/rtc_peer.svelte.d.ts.map +1 -0
- package/dist/rtc/rtc_peer.svelte.js +397 -0
- package/dist/rtc/rtc_signal.d.ts +74 -0
- package/dist/rtc/rtc_signal.d.ts.map +1 -0
- package/dist/rtc/rtc_signal.js +87 -0
- package/dist/testing/CLAUDE.md +67 -13
- package/dist/testing/cross_backend/action_manifest.d.ts +34 -2
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +33 -6
- package/dist/testing/cross_backend/capabilities.d.ts +22 -4
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +4 -1
- package/dist/testing/cross_backend/full_spine_mount.d.ts +31 -6
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +45 -13
- package/dist/testing/cross_backend/rooms_ws.d.ts +20 -0
- package/dist/testing/cross_backend/rooms_ws.d.ts.map +1 -0
- package/dist/testing/cross_backend/rooms_ws.js +534 -0
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +4 -1
- package/dist/testing/cross_backend/spine_suites.d.ts +5 -2
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +24 -5
- package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.js +2 -1
- package/dist/testing/cross_backend/test_room_authorize.d.ts +47 -0
- package/dist/testing/cross_backend/test_room_authorize.d.ts.map +1 -0
- package/dist/testing/cross_backend/test_room_authorize.js +58 -0
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +10 -4
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +85 -1
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +57 -3
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/ts_spine_backend_config.js +5 -2
- package/dist/ui/AccountSessions.svelte.d.ts.map +1 -1
- package/dist/ui/AdminAccounts.svelte.d.ts.map +1 -1
- package/dist/ui/AdminAuditLog.svelte.d.ts.map +1 -1
- package/dist/ui/AdminInvites.svelte.d.ts.map +1 -1
- package/dist/ui/AdminOverview.svelte.d.ts.map +1 -1
- package/dist/ui/AdminRoleGrantHistory.svelte.d.ts.map +1 -1
- package/dist/ui/AdminSessions.svelte.d.ts.map +1 -1
- package/dist/ui/AdminSettings.svelte.d.ts.map +1 -1
- package/dist/ui/AdminSurface.svelte.d.ts.map +1 -1
- package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
- package/dist/ui/ConfirmButton.svelte.d.ts.map +1 -1
- package/dist/ui/Datatable.svelte.d.ts.map +1 -1
- package/dist/ui/LoginForm.svelte.d.ts.map +1 -1
- package/dist/ui/LogoutButton.svelte.d.ts.map +1 -1
- package/dist/ui/OpenSignupToggle.svelte.d.ts.map +1 -1
- package/dist/ui/PopoverButton.svelte.d.ts.map +1 -1
- package/dist/ui/RoleGrantOfferForm.svelte.d.ts.map +1 -1
- package/dist/ui/RoleGrantOfferHistory.svelte.d.ts.map +1 -1
- package/dist/ui/RoleGrantOfferInbox.svelte.d.ts.map +1 -1
- package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
- package/dist/ui/SurfaceExplorer.svelte.d.ts.map +1 -1
- package/package.json +19 -19
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rooms over the WebSocket connection registry: members seated in a room by
|
|
3
|
+
* key, relayed messages, per-member state, and occupancy watches. The TS twin
|
|
4
|
+
* of the Rust spine's `fuz_realtime::RoomRegistry`.
|
|
5
|
+
*
|
|
6
|
+
* A room is a key (`RoomId`) the consumer chooses — e.g. a voice room keyed
|
|
7
|
+
* by a space id — holding **seats** and **watches**. A seat is one actor's
|
|
8
|
+
* membership on one connection, with a random `MemberId` that clients address
|
|
9
|
+
* each other by (a connection id never reaches the wire) and a small
|
|
10
|
+
* client-encoded state string. Seats are keyed by connection and actor: a
|
|
11
|
+
* connection whose requests act as different actors of one account (the
|
|
12
|
+
* dispatcher's `acting` selector) holds a seat per actor, and a leave, send,
|
|
13
|
+
* or state set touches only the acting actor's own seat; an event skips the
|
|
14
|
+
* seat that caused it, not its connection. A watch sees the members without
|
|
15
|
+
* joining; it is one per connection and room, whichever actor last asked for
|
|
16
|
+
* it. The registry relays opaque payloads between members and knows nothing of
|
|
17
|
+
* what they carry. Rooms live in memory and die with the process: a restart
|
|
18
|
+
* drops every room and clients rejoin.
|
|
19
|
+
*
|
|
20
|
+
* The verbs over it — the specs, the authorizer hook, the per-connection
|
|
21
|
+
* limiter — are `actions/room_action_specs.ts` and `actions/room_actions.ts`;
|
|
22
|
+
* this module holds the state and the fan-out.
|
|
23
|
+
*
|
|
24
|
+
* ## One step, one order
|
|
25
|
+
*
|
|
26
|
+
* The Rust registry holds rooms, seats, watches, joins in flight, and the
|
|
27
|
+
* per-connection and per-actor indexes under one lock, since exclusivity and
|
|
28
|
+
* eviction span rooms. Here every method runs to completion without an
|
|
29
|
+
* `await`, so JavaScript's single thread gives the same guarantee: no check is
|
|
30
|
+
* ever separated from the mutation it guards. Every notification is queued
|
|
31
|
+
* inside that step through `ConnectionRegistry.send_to`, which never waits, so
|
|
32
|
+
* each room's events carry a `seq` that orders them: one counter per room,
|
|
33
|
+
* bumped by every event in the room. A room with no seats and no watches is
|
|
34
|
+
* deleted; a new one starts its `seq` again at zero.
|
|
35
|
+
*
|
|
36
|
+
* `seq` orders a room's events, and lets a client drop the events at or below
|
|
37
|
+
* the snapshot a join or watch answered; it is not contiguous per client (an
|
|
38
|
+
* addressed message bumps it, and only the addressee sees that one), and it
|
|
39
|
+
* restarts when a room is deleted and created again. Event order across rooms
|
|
40
|
+
* is unspecified; within a room it is the `seq`.
|
|
41
|
+
*
|
|
42
|
+
* Nothing here waits: a recipient that cannot take a frame is closed for the
|
|
43
|
+
* overflow (`WS_CLOSE_OUTBOUND_OVERFLOW`) by the connection registry, and its
|
|
44
|
+
* seats are then released like any other disconnect.
|
|
45
|
+
*
|
|
46
|
+
* ## Two-phase join
|
|
47
|
+
*
|
|
48
|
+
* A join is `reserve_seat`, the consumer's authorizer, then `admit_seat`. The
|
|
49
|
+
* reserve puts the join **in flight** before the authorizer reads anything,
|
|
50
|
+
* refused when the socket has already closed, and returns a `PendingSeat`;
|
|
51
|
+
* `admit_seat` always consumes it, and a caller that never reaches the admit
|
|
52
|
+
* calls `withdraw` (in a `finally` — the Rust guard's drop). While in flight
|
|
53
|
+
* the join is reachable: an eviction that names its actor or room refuses it,
|
|
54
|
+
* one that names a scope marks it, so the admit refuses when the verdict's
|
|
55
|
+
* scope is that one, and the connection's own `leave` of the room refuses it
|
|
56
|
+
* as superseded. That closes the race of an eviction against an authorizer: a
|
|
57
|
+
* consumer evicts after its write commits, and its authorizer reads under READ
|
|
58
|
+
* COMMITTED, so the eviction either precedes the reserve — then its commit
|
|
59
|
+
* precedes the authorizer's read, which denies — or follows it and reaches the
|
|
60
|
+
* join in flight.
|
|
61
|
+
*
|
|
62
|
+
* The argument holds only for authority the authorizer **reads inside that
|
|
63
|
+
* window**, after the reserve, from the database. Anything loaded before the
|
|
64
|
+
* reserve — the request's own role grants, which the dispatcher reads before
|
|
65
|
+
* the handler runs — may predate an eviction that also precedes the reserve
|
|
66
|
+
* and so found nothing in flight to reach: the stale read would admit an
|
|
67
|
+
* evicted actor. The authorizer hook (`RoomAuthorize`) therefore gets the
|
|
68
|
+
* caller's ids and the database, never the request's grants. Watches run the
|
|
69
|
+
* same two phases (`reserve_watch`, `admit_watch`).
|
|
70
|
+
*
|
|
71
|
+
* Unlike the Rust join, whose request future is dropped when its socket
|
|
72
|
+
* closes, a TS join keeps running after the close: the admit refuses it, since
|
|
73
|
+
* the close marks every join in flight on the connection and the admit reads
|
|
74
|
+
* the socket's signal.
|
|
75
|
+
*
|
|
76
|
+
* The admit seats the member unless it was refused meanwhile, its socket
|
|
77
|
+
* closed, or the room is full. A refused join displaces nothing.
|
|
78
|
+
*
|
|
79
|
+
* ## Exclusivity and the rejoin guard
|
|
80
|
+
*
|
|
81
|
+
* With `exclusive` an actor holds one seat across the registry: the newest
|
|
82
|
+
* **admitted** join wins (two sockets racing settle by which admits last, not
|
|
83
|
+
* which sent first), and the seat it displaces hears `room_seat_lost` with
|
|
84
|
+
* reason `moved` and `moved_to`, the new seat's room. Either way a connection
|
|
85
|
+
* holds one seat per room for each actor; joining again as that actor moves its
|
|
86
|
+
* old seat the same way.
|
|
87
|
+
*
|
|
88
|
+
* A seat whose socket died never hears that it moved. Its client, on
|
|
89
|
+
* reconnecting, rejoins naming the seat it held (`rejoin_of`), and must not
|
|
90
|
+
* take back the seat its actor holds now. So an exclusive registry keeps a
|
|
91
|
+
* short per-actor **tombstone** of seats that ended without a leave: each seat
|
|
92
|
+
* moved away, and each released by its disconnect, which counts as moved once
|
|
93
|
+
* the actor is seated again by any other join. A rejoin naming a moved seat is
|
|
94
|
+
* refused (`seat_moved`) instead of seated; one naming a seat released by its
|
|
95
|
+
* disconnect and not moved since is seated, as is any other. Tombstones last
|
|
96
|
+
* `ROOM_REJOIN_TOMBSTONE_TTL_MS`, at most `ROOM_REJOIN_TOMBSTONES_PER_ACTOR`
|
|
97
|
+
* per actor; past either bound a rejoin is seated like a fresh join.
|
|
98
|
+
*
|
|
99
|
+
* ## Disconnect
|
|
100
|
+
*
|
|
101
|
+
* The first seat or watch a connection reserves adds **one** listener to the
|
|
102
|
+
* connection's socket signal (`ConnectionRegistry.socket_signal` — the signal
|
|
103
|
+
* every close path aborts), and the connection keeps it for its life, however
|
|
104
|
+
* many joins and leaves it makes. When the signal aborts, the registry
|
|
105
|
+
* releases every seat (`room_member_left` with reason `disconnected`), watch,
|
|
106
|
+
* and join in flight the connection holds — on the next microtask, as the Rust
|
|
107
|
+
* waiter runs as its own task, so a close made inside a fan-out (an overflow)
|
|
108
|
+
* never re-enters the registry mid-step.
|
|
109
|
+
*
|
|
110
|
+
* ## Eviction
|
|
111
|
+
*
|
|
112
|
+
* `evict` is the consumer's call when its own authority changes, made after
|
|
113
|
+
* the change commits: by actor, by actor within a scope, by room, or by scope
|
|
114
|
+
* (`RoomEvictTarget`), covering seats, watches, and joins in flight alike, so
|
|
115
|
+
* an evicted actor keeps neither a seat nor a watch. Its socket still hears the
|
|
116
|
+
* room while another actor of the same account is seated there or holds the
|
|
117
|
+
* watch, on that actor's own authority.
|
|
118
|
+
*
|
|
119
|
+
* ## Bounds
|
|
120
|
+
*
|
|
121
|
+
* Seats are bounded by the rooms' cap (and by one per actor when exclusive),
|
|
122
|
+
* watches per connection, joins in flight by the connection's in-flight
|
|
123
|
+
* request cap, listeners at one per connection, and tombstones as above.
|
|
124
|
+
*
|
|
125
|
+
* @module
|
|
126
|
+
*/
|
|
127
|
+
import type { Result } from '@fuzdev/fuz_util/result.ts';
|
|
128
|
+
import { type Uuid } from '../primitive_schemas.js';
|
|
129
|
+
import type { ConnectionRegistry } from './connection_registry.js';
|
|
130
|
+
import { type MemberId, type RoomEvictReason, type RoomId, type RoomMember, type RoomOccupancy, type RoomTopology } from './room_action_specs.js';
|
|
131
|
+
/**
|
|
132
|
+
* How long an exclusive registry remembers a seat that ended without a leave,
|
|
133
|
+
* for the rejoin guard (module doc). Twin of the Rust
|
|
134
|
+
* `ROOM_REJOIN_TOMBSTONE_TTL` (15 minutes).
|
|
135
|
+
*/
|
|
136
|
+
export declare const ROOM_REJOIN_TOMBSTONE_TTL_MS: number;
|
|
137
|
+
/** The most tombstones an exclusive registry keeps per actor; past it the oldest goes. */
|
|
138
|
+
export declare const ROOM_REJOIN_TOMBSTONES_PER_ACTOR = 8;
|
|
139
|
+
/**
|
|
140
|
+
* The most scope evictions one join or watch in flight records; past it the
|
|
141
|
+
* join or watch is refused outright, whatever its verdict's scope.
|
|
142
|
+
*
|
|
143
|
+
* A client sees what any eviction of its request in flight answers: the join
|
|
144
|
+
* or watch is refused as if the room were missing (`room_not_found` from the
|
|
145
|
+
* verbs). It trips only when more distinct scopes than this are evicted during
|
|
146
|
+
* one authorizer read. Both twins hold the same bound.
|
|
147
|
+
*/
|
|
148
|
+
export declare const MAX_POISONED_SCOPES = 16;
|
|
149
|
+
/**
|
|
150
|
+
* A consumer's tag for the authority a seat or watch was admitted under, from
|
|
151
|
+
* the authorizer's verdict — e.g. the group whose membership let the actor in.
|
|
152
|
+
* Eviction targets it: when that authority changes, the consumer evicts the
|
|
153
|
+
* scope, or an actor within it.
|
|
154
|
+
*/
|
|
155
|
+
export type RoomScope = string;
|
|
156
|
+
/**
|
|
157
|
+
* A room operation's refusal — the twin of the Rust `RoomError`:
|
|
158
|
+
*
|
|
159
|
+
* - `connection_closed` — the connection is gone or closing, so nothing is seated on it
|
|
160
|
+
* - `evicted` — an eviction reached the join or watch while it was in flight
|
|
161
|
+
* - `join_superseded` — the connection left the room while its join was in flight
|
|
162
|
+
* - `seat_moved` — the seat a rejoin names moved elsewhere since
|
|
163
|
+
* - `full` — the room seats its maximum already
|
|
164
|
+
* - `not_joined` — the connection holds no seat in the room
|
|
165
|
+
* - `member_not_found` — the addressee is not a member of the room
|
|
166
|
+
* - `payload_too_large` — the payload is over `max_payload_bytes`
|
|
167
|
+
* - `state_too_large` — the state is over `max_state_bytes`
|
|
168
|
+
* - `watch_limit` — the connection watches `max_watches_per_connection` rooms already
|
|
169
|
+
*/
|
|
170
|
+
export type RoomError = 'connection_closed' | 'evicted' | 'join_superseded' | 'seat_moved' | 'full' | 'not_joined' | 'member_not_found' | 'payload_too_large' | 'state_too_large' | 'watch_limit';
|
|
171
|
+
/** A room operation's outcome: its value, or its refusal. */
|
|
172
|
+
export type RoomResult<T> = Result<{
|
|
173
|
+
value: T;
|
|
174
|
+
}, {
|
|
175
|
+
error: RoomError;
|
|
176
|
+
}>;
|
|
177
|
+
/** A `RoomRegistry`'s bounds and rules; each omitted field takes its default. */
|
|
178
|
+
export interface RoomRegistryOptions {
|
|
179
|
+
/**
|
|
180
|
+
* One seat per actor across the whole registry: an admitted join moves the
|
|
181
|
+
* actor's other seat, wherever it is, and the newest admitted seat wins
|
|
182
|
+
* (`room_seat_lost` with reason `moved` to the seat it displaced). Default
|
|
183
|
+
* `false`.
|
|
184
|
+
*/
|
|
185
|
+
readonly exclusive?: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* The most members a room seats, a positive integer; an authorizer's
|
|
188
|
+
* verdict may lower it for one join, never raise it. Default
|
|
189
|
+
* `DEFAULT_ROOM_MAX_MEMBERS`.
|
|
190
|
+
*/
|
|
191
|
+
readonly max_members_per_room?: number;
|
|
192
|
+
/** The longest message payload, in UTF-8 bytes. Default `DEFAULT_ROOM_MAX_PAYLOAD_BYTES`. */
|
|
193
|
+
readonly max_payload_bytes?: number;
|
|
194
|
+
/** The longest member state, in UTF-8 bytes. Default `DEFAULT_ROOM_MAX_STATE_BYTES`. */
|
|
195
|
+
readonly max_state_bytes?: number;
|
|
196
|
+
/**
|
|
197
|
+
* The most rooms one connection watches at once. Default
|
|
198
|
+
* `DEFAULT_ROOM_MAX_WATCHES_PER_CONNECTION`.
|
|
199
|
+
*/
|
|
200
|
+
readonly max_watches_per_connection?: number;
|
|
201
|
+
/** What the join answers as the room's topology. Default `'mesh'`. */
|
|
202
|
+
readonly topology?: RoomTopology;
|
|
203
|
+
/**
|
|
204
|
+
* The monotonic clock the tombstones age by, in ms. Default
|
|
205
|
+
* `performance.now`; a test passes its own to drive the expiry.
|
|
206
|
+
*/
|
|
207
|
+
readonly now?: () => number;
|
|
208
|
+
}
|
|
209
|
+
/** A registry's resolved options — every bound set. */
|
|
210
|
+
export interface RoomRegistryLimits {
|
|
211
|
+
readonly exclusive: boolean;
|
|
212
|
+
readonly max_members_per_room: number;
|
|
213
|
+
readonly max_payload_bytes: number;
|
|
214
|
+
readonly max_state_bytes: number;
|
|
215
|
+
readonly max_watches_per_connection: number;
|
|
216
|
+
readonly topology: RoomTopology;
|
|
217
|
+
}
|
|
218
|
+
/** A join to seat: who, on which connection, into which room. */
|
|
219
|
+
export interface RoomSeatRequest {
|
|
220
|
+
readonly connection_id: Uuid;
|
|
221
|
+
readonly actor_id: Uuid;
|
|
222
|
+
readonly room_id: RoomId;
|
|
223
|
+
/**
|
|
224
|
+
* The seat this join takes up again after a reconnect — refused as
|
|
225
|
+
* `seat_moved` on an exclusive registry when that seat has moved since
|
|
226
|
+
* (module doc); ignored otherwise.
|
|
227
|
+
*/
|
|
228
|
+
readonly rejoin_of?: MemberId | null;
|
|
229
|
+
}
|
|
230
|
+
/** What the authorizer's verdict and the request add at admission. */
|
|
231
|
+
export interface RoomSeatAdmit {
|
|
232
|
+
/** The authority the seat is admitted under, for eviction. */
|
|
233
|
+
readonly scope?: RoomScope | null;
|
|
234
|
+
/**
|
|
235
|
+
* This join's member cap, a non-negative integer, below the registry's;
|
|
236
|
+
* omitted keeps the registry's.
|
|
237
|
+
*/
|
|
238
|
+
readonly max_members?: number | null;
|
|
239
|
+
/** The member's initial state. */
|
|
240
|
+
readonly state?: string | null;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* What an admitted join answers: the seat, and the room as of `seq` — the seq
|
|
244
|
+
* of the joiner's own `room_member_joined`, so a client drops every buffered
|
|
245
|
+
* event at or below it. `members` holds every member, the joiner included, in
|
|
246
|
+
* seating order.
|
|
247
|
+
*/
|
|
248
|
+
export interface RoomJoined {
|
|
249
|
+
readonly room_id: RoomId;
|
|
250
|
+
readonly member_id: MemberId;
|
|
251
|
+
readonly seq: number;
|
|
252
|
+
readonly members: Array<RoomMember>;
|
|
253
|
+
readonly topology: RoomTopology;
|
|
254
|
+
}
|
|
255
|
+
/** What `RoomRegistry.evict` removes. */
|
|
256
|
+
export type RoomEvictTarget =
|
|
257
|
+
/** Every seat and watch of an actor. */
|
|
258
|
+
{
|
|
259
|
+
readonly kind: 'actor';
|
|
260
|
+
readonly actor_id: Uuid;
|
|
261
|
+
}
|
|
262
|
+
/** An actor's seats and watches admitted under one scope. */
|
|
263
|
+
| {
|
|
264
|
+
readonly kind: 'actor_in_scope';
|
|
265
|
+
readonly actor_id: Uuid;
|
|
266
|
+
readonly scope: RoomScope;
|
|
267
|
+
}
|
|
268
|
+
/** Every seat and watch of a room. */
|
|
269
|
+
| {
|
|
270
|
+
readonly kind: 'room';
|
|
271
|
+
readonly room_id: RoomId;
|
|
272
|
+
}
|
|
273
|
+
/** Every seat and watch admitted under a scope. */
|
|
274
|
+
| {
|
|
275
|
+
readonly kind: 'scope';
|
|
276
|
+
readonly scope: RoomScope;
|
|
277
|
+
};
|
|
278
|
+
/** What one `RoomRegistry.evict` removed. */
|
|
279
|
+
export interface RoomEvicted {
|
|
280
|
+
/** Seated members removed. */
|
|
281
|
+
seats: number;
|
|
282
|
+
/** Watches removed. */
|
|
283
|
+
watches: number;
|
|
284
|
+
/**
|
|
285
|
+
* Joins and watches in flight it reached: refused outright by an actor or
|
|
286
|
+
* room target, marked by a scope target (refused at admission only if
|
|
287
|
+
* their verdict names the scope).
|
|
288
|
+
*/
|
|
289
|
+
pending: number;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* A join in flight, between `RoomRegistry.reserve_seat` and
|
|
293
|
+
* `RoomRegistry.admit_seat`. The admit consumes it; a caller that never
|
|
294
|
+
* reaches the admit — a refusal, a cancelled request, a throwing authorizer —
|
|
295
|
+
* calls `withdraw`, which removes it (in a `finally`, as the Rust guard's drop
|
|
296
|
+
* does). Withdrawing an admitted or withdrawn seat does nothing.
|
|
297
|
+
*/
|
|
298
|
+
export declare class PendingSeat {
|
|
299
|
+
/** The member id the seat will have once admitted. */
|
|
300
|
+
readonly member_id: MemberId;
|
|
301
|
+
/** The room the join is for. */
|
|
302
|
+
readonly room_id: RoomId;
|
|
303
|
+
constructor(member_id: MemberId, room_id: RoomId);
|
|
304
|
+
/** Withdraw the join, if it is still in flight. */
|
|
305
|
+
withdraw(): void;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* A watch in flight, between `RoomRegistry.reserve_watch` and
|
|
309
|
+
* `RoomRegistry.admit_watch` — the watch half of `PendingSeat`.
|
|
310
|
+
*/
|
|
311
|
+
export declare class PendingWatch {
|
|
312
|
+
/** The room the watch is for. */
|
|
313
|
+
readonly room_id: RoomId;
|
|
314
|
+
constructor(room_id: RoomId);
|
|
315
|
+
/** Withdraw the watch, if it is still in flight. */
|
|
316
|
+
withdraw(): void;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* The room registry: see the module doc.
|
|
320
|
+
*
|
|
321
|
+
* Build one over the connection registry its WebSocket endpoint uses
|
|
322
|
+
* (`new RoomRegistry(connections, options)`); a connection id from any other
|
|
323
|
+
* registry names no socket here, so its reserves refuse as
|
|
324
|
+
* `connection_closed`. Two WS endpoints sharing one connection registry share
|
|
325
|
+
* one room registry.
|
|
326
|
+
*/
|
|
327
|
+
export declare class RoomRegistry {
|
|
328
|
+
#private;
|
|
329
|
+
/** The registry's resolved bounds and rules. */
|
|
330
|
+
readonly options: RoomRegistryLimits;
|
|
331
|
+
/**
|
|
332
|
+
* @throws Error when a bound is not an integer in range (`max_members_per_room`
|
|
333
|
+
* at least 1, the byte and watch bounds at least 0)
|
|
334
|
+
*/
|
|
335
|
+
constructor(connections: ConnectionRegistry, options?: RoomRegistryOptions);
|
|
336
|
+
/**
|
|
337
|
+
* Phase one of a join: put it in flight before the authorizer runs (module
|
|
338
|
+
* doc, "Two-phase join").
|
|
339
|
+
*
|
|
340
|
+
* @returns the join in flight, or `connection_closed` when the connection
|
|
341
|
+
* is gone or closing, or `seat_moved` when the request is a rejoin of a
|
|
342
|
+
* seat that has moved (exclusive registries)
|
|
343
|
+
* @mutates this - records the join in flight, and on the connection's first
|
|
344
|
+
* reserve adds its one disconnect listener
|
|
345
|
+
*/
|
|
346
|
+
reserve_seat(request: RoomSeatRequest): RoomResult<PendingSeat>;
|
|
347
|
+
/**
|
|
348
|
+
* Phase two of a join: seat the member (module doc). Consumes `pending`,
|
|
349
|
+
* whatever it answers.
|
|
350
|
+
*
|
|
351
|
+
* Moves the actor's own seat in the room on this connection, and on an
|
|
352
|
+
* exclusive registry the actor's seat anywhere, to this one: each hears
|
|
353
|
+
* `room_seat_lost` with reason `moved`, its room `room_member_left` with
|
|
354
|
+
* reason `moved`. Then the room hears `room_member_joined`.
|
|
355
|
+
*
|
|
356
|
+
* @returns the seat and the room, or `state_too_large`; `evicted`,
|
|
357
|
+
* `join_superseded`, or `connection_closed` when the join was refused in
|
|
358
|
+
* flight or its socket closed; `seat_moved` for a rejoin of a moved seat;
|
|
359
|
+
* `full` when the room seats its cap (the lower of the registry's and
|
|
360
|
+
* `admit.max_members`) after the moves this join makes
|
|
361
|
+
* @throws Error when `admit.max_members` is not a non-negative integer (a
|
|
362
|
+
* consumer's authorizer bug), checked once the join passes its other
|
|
363
|
+
* refusals; `pending` is consumed all the same
|
|
364
|
+
* @mutates this - seats the member, moving what the join displaces
|
|
365
|
+
*/
|
|
366
|
+
admit_seat(pending: PendingSeat, admit?: RoomSeatAdmit): RoomResult<RoomJoined>;
|
|
367
|
+
/**
|
|
368
|
+
* End `actor_id`'s seat in the room on the connection (`room_member_left`
|
|
369
|
+
* with reason `left`), and refuse that actor's joins of the room still in
|
|
370
|
+
* flight on it (`join_superseded`). Another actor's seat on the same
|
|
371
|
+
* connection is untouched. Idempotent.
|
|
372
|
+
*
|
|
373
|
+
* @returns `true` when it ended or refused anything
|
|
374
|
+
* @mutates this - removes the seat, marks the joins in flight
|
|
375
|
+
*/
|
|
376
|
+
leave(connection_id: Uuid, actor_id: Uuid, room_id: RoomId): boolean;
|
|
377
|
+
/**
|
|
378
|
+
* Relay `payload` from `actor_id`'s seat in the room on the connection to
|
|
379
|
+
* the member `to`, or with `null` to every other member (`room_message`).
|
|
380
|
+
* Watchers get no messages.
|
|
381
|
+
*
|
|
382
|
+
* @returns the message's `seq`, or `payload_too_large`, `not_joined`, or
|
|
383
|
+
* `member_not_found` when `to` names no member of the room — or names the
|
|
384
|
+
* sender's own seat: a seat never addresses itself
|
|
385
|
+
*/
|
|
386
|
+
send(connection_id: Uuid, actor_id: Uuid, room_id: RoomId, to: MemberId | null, payload: string): RoomResult<number>;
|
|
387
|
+
/**
|
|
388
|
+
* Set `actor_id`'s member state in the room on the connection, telling the
|
|
389
|
+
* other members and the watchers (`room_member_state`).
|
|
390
|
+
*
|
|
391
|
+
* @returns its `seq`, or `state_too_large` or `not_joined`
|
|
392
|
+
*/
|
|
393
|
+
set_state(connection_id: Uuid, actor_id: Uuid, room_id: RoomId, member_state: string): RoomResult<number>;
|
|
394
|
+
/**
|
|
395
|
+
* Phase one of a watch, as `reserve_seat` is of a join.
|
|
396
|
+
*
|
|
397
|
+
* @returns the watch in flight, or `connection_closed`, or `watch_limit`
|
|
398
|
+
* when the connection watches its maximum of other rooms
|
|
399
|
+
* @mutates this - records the watch in flight, and on the connection's
|
|
400
|
+
* first reserve adds its one disconnect listener
|
|
401
|
+
*/
|
|
402
|
+
reserve_watch(connection_id: Uuid, actor_id: Uuid, room_id: RoomId): RoomResult<PendingWatch>;
|
|
403
|
+
/**
|
|
404
|
+
* Phase two of a watch: from now on the connection hears the room's member
|
|
405
|
+
* events. Watching a room already watched answers its occupancy again and
|
|
406
|
+
* takes the new scope and actor. Consumes `pending`, whatever it answers.
|
|
407
|
+
*
|
|
408
|
+
* @returns the room's occupancy, or `evicted` or `connection_closed` when
|
|
409
|
+
* the watch was refused in flight or its socket closed, or `watch_limit`
|
|
410
|
+
* @mutates this - records the watch
|
|
411
|
+
*/
|
|
412
|
+
admit_watch(pending: PendingWatch, scope?: RoomScope | null): RoomResult<RoomOccupancy>;
|
|
413
|
+
/**
|
|
414
|
+
* Stop the connection's watch of the room. Idempotent. A watch still in
|
|
415
|
+
* flight is untouched — a client stops one by cancelling its request.
|
|
416
|
+
*
|
|
417
|
+
* @returns `true` when it was watching
|
|
418
|
+
*/
|
|
419
|
+
unwatch(connection_id: Uuid, room_id: RoomId): boolean;
|
|
420
|
+
/**
|
|
421
|
+
* Remove the seats and watches `target` names, and refuse its joins and
|
|
422
|
+
* watches in flight (module doc, "Eviction"). Each removed seat hears
|
|
423
|
+
* `room_seat_lost`, its room `room_member_left`, each removed watch
|
|
424
|
+
* `room_watch_ended`, all with `reason`.
|
|
425
|
+
*
|
|
426
|
+
* A join in flight has no scope until its verdict, so a scope target marks
|
|
427
|
+
* it instead, and its admit refuses when its verdict's scope is that one; a
|
|
428
|
+
* join marked by more scopes than `MAX_POISONED_SCOPES` is refused outright.
|
|
429
|
+
*
|
|
430
|
+
* @returns what it removed and reached
|
|
431
|
+
*/
|
|
432
|
+
evict(target: RoomEvictTarget, reason: RoomEvictReason): RoomEvicted;
|
|
433
|
+
/**
|
|
434
|
+
* The room's members as of its current `seq`.
|
|
435
|
+
*
|
|
436
|
+
* @returns the occupancy, or `null` when no room by that id exists (no seats and no watches)
|
|
437
|
+
*/
|
|
438
|
+
occupancy(room_id: RoomId): RoomOccupancy | null;
|
|
439
|
+
/**
|
|
440
|
+
* Drop every room, seat, watch, and tombstone, telling no one, and refuse
|
|
441
|
+
* every join and watch in flight (`evicted`). For a test server's reset
|
|
442
|
+
* between cases; the connections' disconnect listeners stay.
|
|
443
|
+
*
|
|
444
|
+
* @mutates this - empties the registry
|
|
445
|
+
*/
|
|
446
|
+
clear(): void;
|
|
447
|
+
/**
|
|
448
|
+
* Connections the registry tracks — each that reserved a seat or watch and
|
|
449
|
+
* has not closed — each holding the one disconnect listener. For tests and
|
|
450
|
+
* telemetry.
|
|
451
|
+
*/
|
|
452
|
+
connection_count(): number;
|
|
453
|
+
}
|
|
454
|
+
//# sourceMappingURL=room_registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room_registry.d.ts","sourceRoot":"","sources":["../../src/lib/actions/room_registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6HG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEzD,OAAO,EAAe,KAAK,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,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