@lunora/do 1.0.0-alpha.224 → 1.0.0-alpha.225

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/index.d.mts CHANGED
@@ -1338,6 +1338,50 @@ declare abstract class ShardDO {
1338
1338
  protected static readonly MAX_WHISPER_BYTES = 4096;
1339
1339
  /** Room events one socket may have queued at once; past it the next event is refused. */
1340
1340
  protected static readonly MAX_QUEUED_ROOM_EVENTS = 64;
1341
+ /**
1342
+ * Per-connection cap on live SSE topics. A live connection is one SSE stream
1343
+ * multiplexing many topics, so this bounds how many a single browser can
1344
+ * follow before the connection is refused a further join. Like the whisper
1345
+ * membership cap, an over-cap join is refused rather than evicting an earlier
1346
+ * one.
1347
+ */
1348
+ protected static readonly MAX_LIVE_TOPICS_PER_CONNECTION = 64;
1349
+ /**
1350
+ * Per-WebSocket cap on live grants. A grant is a `liveGrants` entry in the 16 KiB
1351
+ * hibernation attachment (subscription id and stream-scoped topic key), so this sits far
1352
+ * below {@link ShardDO.MAX_LIVE_TOPICS_PER_CONNECTION}. A grant past it is refused.
1353
+ */
1354
+ protected static readonly MAX_LIVE_TOPICS_PER_SOCKET = 8;
1355
+ /**
1356
+ * Ceiling on live SSE connections one shard DO holds. Each open connection is
1357
+ * a pinned stream the publish scan visits, and the connect route is reachable
1358
+ * before any topic is authorized, so an unbounded count is a memory and CPU
1359
+ * denial of service.
1360
+ */
1361
+ protected static readonly MAX_LIVE_CONNECTIONS = 1024;
1362
+ /**
1363
+ * How often an open live stream is sent a comment frame. A proxy or load balancer that idles out a
1364
+ * silent connection would otherwise close a quiet stream, and the client would reconnect and
1365
+ * resubscribe for no reason.
1366
+ */
1367
+ protected static readonly LIVE_KEEPALIVE_MS = 25e3;
1368
+ /**
1369
+ * Live SSE connections one caller may hold on a shard: one user id, or, for an anonymous
1370
+ * caller with an IP (the `x-lunora-client-ip` the runtime mints), one client IP. A signed-in
1371
+ * caller is never capped by its IP, so a shared IP cannot lock out its users.
1372
+ */
1373
+ protected static readonly MAX_LIVE_CONNECTIONS_PER_CALLER = 32;
1374
+ /**
1375
+ * Live SSE connections all anonymous callers with no IP share. Without an IP there is no per-client
1376
+ * bucket, so this is the only bound: a single no-IP client can take this many slots, and no more.
1377
+ * Set `trustedClientIpHeader` so anonymous clients get their own bucket.
1378
+ */
1379
+ protected static readonly MAX_LIVE_CONNECTIONS_ANONYMOUS_SHARED = 256;
1380
+ /**
1381
+ * Bytes a live SSE connection may hold queued unread. A reader that falls this far behind
1382
+ * is dropped rather than letting its response queue grow with every publish.
1383
+ */
1384
+ protected static readonly MAX_LIVE_QUEUED_BYTES: number;
1341
1385
  /**
1342
1386
  * Whisper-rate token bucket: each socket may burst {@link ShardDO.WHISPER_RATE_BURST}
1343
1387
  * whispers, refilling at {@link ShardDO.WHISPER_RATE_PER_SEC}/s. Without this a single
@@ -1897,6 +1941,16 @@ declare abstract class ShardDO {
1897
1941
  private readonly queuedRoomEvents;
1898
1942
  /** Sockets whose close is in progress: their room membership is being torn down, so nothing new may join or leave. */
1899
1943
  private readonly closingSockets;
1944
+ /**
1945
+ * Sockets holding at least one live grant, so a publish visits only grant holders. Kept as a
1946
+ * superset of the truth: `deliverLiveLocal` re-checks each socket's attachment, and drops an
1947
+ * entry whose grants are gone. In-memory, so a hibernation wake empties it;
1948
+ * {@link ShardDO.ensureLiveSocketIndex} rebuilds it with one scan the first time it is needed.
1949
+ */
1950
+ private readonly liveGrantSockets;
1951
+ /** Sockets by the `connectionId` stamped at accept, so a control call finds its socket without a scan. Maintained like {@link ShardDO.liveGrantSockets}. */
1952
+ private readonly liveSocketsByConnection;
1953
+ private liveSocketIndexBuilt;
1900
1954
  /** Tail of each socket's queued room-handler events; see `dispatchRoomEvent`. */
1901
1955
  private readonly roomChains;
1902
1956
  /**
@@ -1914,6 +1968,22 @@ declare abstract class ShardDO {
1914
1968
  * the pair as taken rather than all passing an unchanged size check.
1915
1969
  */
1916
1970
  private readonly whisperVerdicts;
1971
+ /**
1972
+ * Live-topic SSE subscribers, keyed by the server-minted connection id
1973
+ * returned on the connect response (`LIVE_CONNECTION_HEADER`). Each entry
1974
+ * holds the topic set the connection is subscribed to and the stream
1975
+ * controller frames are written into.
1976
+ *
1977
+ * In-memory on purpose and unlike whisper membership this is NOT on a
1978
+ * hibernation attachment: an SSE response is an in-flight DO request, so the
1979
+ * subscriber cannot outlive the instance that owns the stream — losing the
1980
+ * map means the stream is gone too. That is also the hot-shard ceiling: the
1981
+ * registry is a single shard object per shard key, so a very busy topic is a
1982
+ * hot object; shard by `?shard=<key>` when throughput matters.
1983
+ */
1984
+ private readonly liveSubscribers;
1985
+ /** The keepalive timer for open live streams. Runs only while at least one is open. */
1986
+ private liveKeepalive;
1917
1987
  /**
1918
1988
  * Per-socket {@link AbortController} map keyed by stream id, used to
1919
1989
  * propagate a client unsubscribe (or a socket close) into the user
@@ -3570,6 +3640,32 @@ declare abstract class ShardDO {
3570
3640
  protected pollScheduleOutbox(trace?: TraceRefLike): Promise<number | undefined>;
3571
3641
  /** This DO's shard key (its DO name), or `__root__` for the single-DO default. The `tenantBy` mapper binds it into the source query. */
3572
3642
  protected currentShardKey(): string;
3643
+ /**
3644
+ * The one validated publish path for a server-side live event. The HTTP route
3645
+ * (`ctx.live.publish` from an HTTP action, forwarded by the Worker) and an
3646
+ * in-shard action (see publishLiveFromAction) both land here, so
3647
+ * the room refusal and the byte cap cannot drift between them. `wireData` is
3648
+ * already wire-encoded.
3649
+ * @throws LunoraError `FORBIDDEN_TOPIC` (403) for a room topic, `BAD_REQUEST` (400) for a topic over the control bound,
3650
+ * `PAYLOAD_TOO_LARGE` (413) past the cap
3651
+ * @returns the number of LOCAL SSE connections the frame was written to
3652
+ */
3653
+ protected publishLiveEvent(stream: string, topic: string, wireData: unknown): number;
3654
+ /**
3655
+ * `ctx.live.publish` from an action that runs on THIS shard — a scheduled job's
3656
+ * action, or any action the shard executes. It is a local call, not an RPC hop:
3657
+ * the action already runs inside the Durable Object that owns the subscribers.
3658
+ *
3659
+ * An absent `shardKey` means this shard. Unlike the HTTP route, which defaults to
3660
+ * the root shard, an action has no request to route from, so it publishes where
3661
+ * it runs. A `shardKey` naming another shard is refused rather than delivered to
3662
+ * zero subscribers: there is no cross-shard live fan-out to forward it through.
3663
+ * @returns the number of LOCAL SSE connections the frame was written to
3664
+ */
3665
+ protected publishLiveFromAction(topic: string, payload: unknown, options: {
3666
+ shardKey?: string;
3667
+ stream: string;
3668
+ }): Promise<number>;
3573
3669
  /**
3574
3670
  * The `ShardRegistryDO` namespace this shard reports to, and which of its
3575
3671
  * tables are `.shardBy()`. The generated subclass overrides it for a schema
@@ -6053,6 +6149,8 @@ declare abstract class ShardDO {
6053
6149
  * `fetch` then dispatches.
6054
6150
  * @returns the routed response, or `undefined` when this is an RPC request
6055
6151
  */
6152
+ /** The three live-stream endpoints, or `undefined` when the request is not one of them. */
6153
+ private routeLive;
6056
6154
  private routeNonRpc;
6057
6155
  private handleWebSocketUpgrade;
6058
6156
  /**
@@ -6195,6 +6293,13 @@ declare abstract class ShardDO {
6195
6293
  * they were dispatched: a leave queued behind a join never overtakes it.
6196
6294
  */
6197
6295
  private dispatchRoomEvent;
6296
+ /**
6297
+ * Acknowledge a processed `whisper_subscribe` to a live (non-room) topic, whatever its outcome,
6298
+ * so the ack carries no authorization signal (see protocol/README.md). A room join is never
6299
+ * acknowledged: its own history frame answers it, and its `onJoin` can outlast the client's grant
6300
+ * timer, which would make the ack reveal admit against deny.
6301
+ */
6302
+ private acknowledgeLiveJoin;
6198
6303
  /**
6199
6304
  * Dispatch one membership change's room handler. A join stays pending (see
6200
6305
  * `pendingRoomJoins`) until its `onJoin` settles, so broadcasts skip the socket meanwhile.
@@ -6258,6 +6363,90 @@ declare abstract class ShardDO {
6258
6363
  * takes. The relay has already checked rate and size, and it undoes a join the owner refuses.
6259
6364
  */
6260
6365
  private relayRoomEvent;
6366
+ /** Start the keepalive when the first live stream opens. The timer stops itself once none remain. */
6367
+ private startLiveKeepalive;
6368
+ /**
6369
+ * End and deregister a live connection whose credential has lapsed, so the client reconnects and
6370
+ * re-authenticates. Run by the keepalive tick and by each publish.
6371
+ * @returns whether the connection was ended
6372
+ */
6373
+ private endExpiredLiveSubscriber;
6374
+ /**
6375
+ * Open a live SSE connection. The stream is registered in
6376
+ * {@link ShardDO.liveSubscribers} under a fresh connection id, which is
6377
+ * returned in the `LIVE_CONNECTION_HEADER` response header so the client can
6378
+ * scope later control calls to THIS connection.
6379
+ *
6380
+ * Opening a connection grants nothing: each topic is authorized on its own
6381
+ * subscribe through the worker's `defineLiveStream`.
6382
+ */
6383
+ private handleLiveConnect;
6384
+ /**
6385
+ * Subscribe or unsubscribe on a live connection. Both are scoped to the
6386
+ * connection named in the body, and the worker's `defineLiveStream` has
6387
+ * already authorized the topic (see {@link ShardDO.handleLiveConnect}). The
6388
+ * subscription is keyed by the stream that granted it, so a topic authorized
6389
+ * by one stream is never delivered to a subscriber of another.
6390
+ */
6391
+ private handleLiveControl;
6392
+ /**
6393
+ * Subscribe or unsubscribe a live grant on a WebSocket. The control route reaches this only
6394
+ * when no SSE connection holds `connectionId`, and the worker has already run `onSubscribe`
6395
+ * for the call. The grant is written to the socket's hibernation attachment so it survives
6396
+ * a hibernation; an in-memory grant would be silently lost on wake.
6397
+ *
6398
+ * A socket is held by one DO. On the shard owner, a socket this DO does not hold is forwarded
6399
+ * to the relays (the owner gets the control call, the relay holds the connection). A relay
6400
+ * never forwards, so the owner is the only hop.
6401
+ *
6402
+ * The socket is found through {@link ShardDO.liveSocketsByConnection}, so a control call does not
6403
+ * read every socket's attachment.
6404
+ */
6405
+ private handleLiveSocketControl;
6406
+ /**
6407
+ * Server-side publish: the worker's `ctx.live.publish` lands here, on an
6408
+ * endpoint no browser can reach through `defineLiveStream`'s control route.
6409
+ * Fans the event out via {@link ShardDO.broadcastLiveTopic}.
6410
+ */
6411
+ private handleLivePublish;
6412
+ /**
6413
+ * Fan a server-published event out to every live subscriber of `topic` on `stream` on
6414
+ * THIS DO (see {@link liveSubscriptionKey}): the SSE connections that subscribed through
6415
+ * that stream, and the WebSocket whisper members that were granted it (see
6416
+ * {@link ShardDO.deliverLiveLocal}). A grant only exists because the worker's
6417
+ * `onSubscribe` admitted the caller for this stream and topic, so the bare-topic whisper
6418
+ * channel carries no event a member was not admitted for. SSE connections are local to the
6419
+ * DO they connected to. A WebSocket can sit on a relay, so the owner also forwards the frame
6420
+ * and the grant control calls through the relay hub (see {@link OwnerRelay.forwardLiveFrame}
6421
+ * and {@link OwnerRelay.forwardLiveControl}); each relay delivers only to its own grant holders.
6422
+ *
6423
+ * `dataJson` is the already-serialized, wire-encoded payload (the producer
6424
+ * encodes once so a `bigint`/`Uint8Array` survives the hop). The caller has
6425
+ * checked the size bound.
6426
+ * @returns the number of LOCAL SSE connections and WebSocket members the frame was written to
6427
+ */
6428
+ private broadcastLiveTopic;
6429
+ /**
6430
+ * Deliver a live publish to the WebSocket whisper members of `topic` on this DO that hold the
6431
+ * live grant `key`. Both must hold: membership alone does not admit a stream's event, and a
6432
+ * grant alone does not join the socket to the topic's whisper channel. Expiry and the pending
6433
+ * room-join skip match {@link ShardDO.deliverWhisperLocal}.
6434
+ * @returns the number of sockets the frame was sent to
6435
+ */
6436
+ private deliverLiveLocal;
6437
+ /**
6438
+ * Build the live-socket indexes from the hibernated sockets, once per instance. Sockets accepted
6439
+ * or grant-changed since the build are already in the index, and the scan is idempotent, so the
6440
+ * build order does not matter.
6441
+ */
6442
+ private ensureLiveSocketIndex;
6443
+ /** The socket this DO holds for `connectionId`, or `undefined`. Builds the index on first use after a wake. */
6444
+ private findLiveSocket;
6445
+ /**
6446
+ * Write a socket's live grants to its attachment and keep the grant-holder index in step. The
6447
+ * index moves only when the write persisted, so it never claims a grant the attachment lacks.
6448
+ */
6449
+ private persistSocketGrants;
6261
6450
  private readAttachment;
6262
6451
  }
6263
6452
  /** Conventional DO instance name, passed to `idFromName` to address the single registry instance. */
package/dist/index.d.ts CHANGED
@@ -1338,6 +1338,50 @@ declare abstract class ShardDO {
1338
1338
  protected static readonly MAX_WHISPER_BYTES = 4096;
1339
1339
  /** Room events one socket may have queued at once; past it the next event is refused. */
1340
1340
  protected static readonly MAX_QUEUED_ROOM_EVENTS = 64;
1341
+ /**
1342
+ * Per-connection cap on live SSE topics. A live connection is one SSE stream
1343
+ * multiplexing many topics, so this bounds how many a single browser can
1344
+ * follow before the connection is refused a further join. Like the whisper
1345
+ * membership cap, an over-cap join is refused rather than evicting an earlier
1346
+ * one.
1347
+ */
1348
+ protected static readonly MAX_LIVE_TOPICS_PER_CONNECTION = 64;
1349
+ /**
1350
+ * Per-WebSocket cap on live grants. A grant is a `liveGrants` entry in the 16 KiB
1351
+ * hibernation attachment (subscription id and stream-scoped topic key), so this sits far
1352
+ * below {@link ShardDO.MAX_LIVE_TOPICS_PER_CONNECTION}. A grant past it is refused.
1353
+ */
1354
+ protected static readonly MAX_LIVE_TOPICS_PER_SOCKET = 8;
1355
+ /**
1356
+ * Ceiling on live SSE connections one shard DO holds. Each open connection is
1357
+ * a pinned stream the publish scan visits, and the connect route is reachable
1358
+ * before any topic is authorized, so an unbounded count is a memory and CPU
1359
+ * denial of service.
1360
+ */
1361
+ protected static readonly MAX_LIVE_CONNECTIONS = 1024;
1362
+ /**
1363
+ * How often an open live stream is sent a comment frame. A proxy or load balancer that idles out a
1364
+ * silent connection would otherwise close a quiet stream, and the client would reconnect and
1365
+ * resubscribe for no reason.
1366
+ */
1367
+ protected static readonly LIVE_KEEPALIVE_MS = 25e3;
1368
+ /**
1369
+ * Live SSE connections one caller may hold on a shard: one user id, or, for an anonymous
1370
+ * caller with an IP (the `x-lunora-client-ip` the runtime mints), one client IP. A signed-in
1371
+ * caller is never capped by its IP, so a shared IP cannot lock out its users.
1372
+ */
1373
+ protected static readonly MAX_LIVE_CONNECTIONS_PER_CALLER = 32;
1374
+ /**
1375
+ * Live SSE connections all anonymous callers with no IP share. Without an IP there is no per-client
1376
+ * bucket, so this is the only bound: a single no-IP client can take this many slots, and no more.
1377
+ * Set `trustedClientIpHeader` so anonymous clients get their own bucket.
1378
+ */
1379
+ protected static readonly MAX_LIVE_CONNECTIONS_ANONYMOUS_SHARED = 256;
1380
+ /**
1381
+ * Bytes a live SSE connection may hold queued unread. A reader that falls this far behind
1382
+ * is dropped rather than letting its response queue grow with every publish.
1383
+ */
1384
+ protected static readonly MAX_LIVE_QUEUED_BYTES: number;
1341
1385
  /**
1342
1386
  * Whisper-rate token bucket: each socket may burst {@link ShardDO.WHISPER_RATE_BURST}
1343
1387
  * whispers, refilling at {@link ShardDO.WHISPER_RATE_PER_SEC}/s. Without this a single
@@ -1897,6 +1941,16 @@ declare abstract class ShardDO {
1897
1941
  private readonly queuedRoomEvents;
1898
1942
  /** Sockets whose close is in progress: their room membership is being torn down, so nothing new may join or leave. */
1899
1943
  private readonly closingSockets;
1944
+ /**
1945
+ * Sockets holding at least one live grant, so a publish visits only grant holders. Kept as a
1946
+ * superset of the truth: `deliverLiveLocal` re-checks each socket's attachment, and drops an
1947
+ * entry whose grants are gone. In-memory, so a hibernation wake empties it;
1948
+ * {@link ShardDO.ensureLiveSocketIndex} rebuilds it with one scan the first time it is needed.
1949
+ */
1950
+ private readonly liveGrantSockets;
1951
+ /** Sockets by the `connectionId` stamped at accept, so a control call finds its socket without a scan. Maintained like {@link ShardDO.liveGrantSockets}. */
1952
+ private readonly liveSocketsByConnection;
1953
+ private liveSocketIndexBuilt;
1900
1954
  /** Tail of each socket's queued room-handler events; see `dispatchRoomEvent`. */
1901
1955
  private readonly roomChains;
1902
1956
  /**
@@ -1914,6 +1968,22 @@ declare abstract class ShardDO {
1914
1968
  * the pair as taken rather than all passing an unchanged size check.
1915
1969
  */
1916
1970
  private readonly whisperVerdicts;
1971
+ /**
1972
+ * Live-topic SSE subscribers, keyed by the server-minted connection id
1973
+ * returned on the connect response (`LIVE_CONNECTION_HEADER`). Each entry
1974
+ * holds the topic set the connection is subscribed to and the stream
1975
+ * controller frames are written into.
1976
+ *
1977
+ * In-memory on purpose and unlike whisper membership this is NOT on a
1978
+ * hibernation attachment: an SSE response is an in-flight DO request, so the
1979
+ * subscriber cannot outlive the instance that owns the stream — losing the
1980
+ * map means the stream is gone too. That is also the hot-shard ceiling: the
1981
+ * registry is a single shard object per shard key, so a very busy topic is a
1982
+ * hot object; shard by `?shard=<key>` when throughput matters.
1983
+ */
1984
+ private readonly liveSubscribers;
1985
+ /** The keepalive timer for open live streams. Runs only while at least one is open. */
1986
+ private liveKeepalive;
1917
1987
  /**
1918
1988
  * Per-socket {@link AbortController} map keyed by stream id, used to
1919
1989
  * propagate a client unsubscribe (or a socket close) into the user
@@ -3570,6 +3640,32 @@ declare abstract class ShardDO {
3570
3640
  protected pollScheduleOutbox(trace?: TraceRefLike): Promise<number | undefined>;
3571
3641
  /** This DO's shard key (its DO name), or `__root__` for the single-DO default. The `tenantBy` mapper binds it into the source query. */
3572
3642
  protected currentShardKey(): string;
3643
+ /**
3644
+ * The one validated publish path for a server-side live event. The HTTP route
3645
+ * (`ctx.live.publish` from an HTTP action, forwarded by the Worker) and an
3646
+ * in-shard action (see publishLiveFromAction) both land here, so
3647
+ * the room refusal and the byte cap cannot drift between them. `wireData` is
3648
+ * already wire-encoded.
3649
+ * @throws LunoraError `FORBIDDEN_TOPIC` (403) for a room topic, `BAD_REQUEST` (400) for a topic over the control bound,
3650
+ * `PAYLOAD_TOO_LARGE` (413) past the cap
3651
+ * @returns the number of LOCAL SSE connections the frame was written to
3652
+ */
3653
+ protected publishLiveEvent(stream: string, topic: string, wireData: unknown): number;
3654
+ /**
3655
+ * `ctx.live.publish` from an action that runs on THIS shard — a scheduled job's
3656
+ * action, or any action the shard executes. It is a local call, not an RPC hop:
3657
+ * the action already runs inside the Durable Object that owns the subscribers.
3658
+ *
3659
+ * An absent `shardKey` means this shard. Unlike the HTTP route, which defaults to
3660
+ * the root shard, an action has no request to route from, so it publishes where
3661
+ * it runs. A `shardKey` naming another shard is refused rather than delivered to
3662
+ * zero subscribers: there is no cross-shard live fan-out to forward it through.
3663
+ * @returns the number of LOCAL SSE connections the frame was written to
3664
+ */
3665
+ protected publishLiveFromAction(topic: string, payload: unknown, options: {
3666
+ shardKey?: string;
3667
+ stream: string;
3668
+ }): Promise<number>;
3573
3669
  /**
3574
3670
  * The `ShardRegistryDO` namespace this shard reports to, and which of its
3575
3671
  * tables are `.shardBy()`. The generated subclass overrides it for a schema
@@ -6053,6 +6149,8 @@ declare abstract class ShardDO {
6053
6149
  * `fetch` then dispatches.
6054
6150
  * @returns the routed response, or `undefined` when this is an RPC request
6055
6151
  */
6152
+ /** The three live-stream endpoints, or `undefined` when the request is not one of them. */
6153
+ private routeLive;
6056
6154
  private routeNonRpc;
6057
6155
  private handleWebSocketUpgrade;
6058
6156
  /**
@@ -6195,6 +6293,13 @@ declare abstract class ShardDO {
6195
6293
  * they were dispatched: a leave queued behind a join never overtakes it.
6196
6294
  */
6197
6295
  private dispatchRoomEvent;
6296
+ /**
6297
+ * Acknowledge a processed `whisper_subscribe` to a live (non-room) topic, whatever its outcome,
6298
+ * so the ack carries no authorization signal (see protocol/README.md). A room join is never
6299
+ * acknowledged: its own history frame answers it, and its `onJoin` can outlast the client's grant
6300
+ * timer, which would make the ack reveal admit against deny.
6301
+ */
6302
+ private acknowledgeLiveJoin;
6198
6303
  /**
6199
6304
  * Dispatch one membership change's room handler. A join stays pending (see
6200
6305
  * `pendingRoomJoins`) until its `onJoin` settles, so broadcasts skip the socket meanwhile.
@@ -6258,6 +6363,90 @@ declare abstract class ShardDO {
6258
6363
  * takes. The relay has already checked rate and size, and it undoes a join the owner refuses.
6259
6364
  */
6260
6365
  private relayRoomEvent;
6366
+ /** Start the keepalive when the first live stream opens. The timer stops itself once none remain. */
6367
+ private startLiveKeepalive;
6368
+ /**
6369
+ * End and deregister a live connection whose credential has lapsed, so the client reconnects and
6370
+ * re-authenticates. Run by the keepalive tick and by each publish.
6371
+ * @returns whether the connection was ended
6372
+ */
6373
+ private endExpiredLiveSubscriber;
6374
+ /**
6375
+ * Open a live SSE connection. The stream is registered in
6376
+ * {@link ShardDO.liveSubscribers} under a fresh connection id, which is
6377
+ * returned in the `LIVE_CONNECTION_HEADER` response header so the client can
6378
+ * scope later control calls to THIS connection.
6379
+ *
6380
+ * Opening a connection grants nothing: each topic is authorized on its own
6381
+ * subscribe through the worker's `defineLiveStream`.
6382
+ */
6383
+ private handleLiveConnect;
6384
+ /**
6385
+ * Subscribe or unsubscribe on a live connection. Both are scoped to the
6386
+ * connection named in the body, and the worker's `defineLiveStream` has
6387
+ * already authorized the topic (see {@link ShardDO.handleLiveConnect}). The
6388
+ * subscription is keyed by the stream that granted it, so a topic authorized
6389
+ * by one stream is never delivered to a subscriber of another.
6390
+ */
6391
+ private handleLiveControl;
6392
+ /**
6393
+ * Subscribe or unsubscribe a live grant on a WebSocket. The control route reaches this only
6394
+ * when no SSE connection holds `connectionId`, and the worker has already run `onSubscribe`
6395
+ * for the call. The grant is written to the socket's hibernation attachment so it survives
6396
+ * a hibernation; an in-memory grant would be silently lost on wake.
6397
+ *
6398
+ * A socket is held by one DO. On the shard owner, a socket this DO does not hold is forwarded
6399
+ * to the relays (the owner gets the control call, the relay holds the connection). A relay
6400
+ * never forwards, so the owner is the only hop.
6401
+ *
6402
+ * The socket is found through {@link ShardDO.liveSocketsByConnection}, so a control call does not
6403
+ * read every socket's attachment.
6404
+ */
6405
+ private handleLiveSocketControl;
6406
+ /**
6407
+ * Server-side publish: the worker's `ctx.live.publish` lands here, on an
6408
+ * endpoint no browser can reach through `defineLiveStream`'s control route.
6409
+ * Fans the event out via {@link ShardDO.broadcastLiveTopic}.
6410
+ */
6411
+ private handleLivePublish;
6412
+ /**
6413
+ * Fan a server-published event out to every live subscriber of `topic` on `stream` on
6414
+ * THIS DO (see {@link liveSubscriptionKey}): the SSE connections that subscribed through
6415
+ * that stream, and the WebSocket whisper members that were granted it (see
6416
+ * {@link ShardDO.deliverLiveLocal}). A grant only exists because the worker's
6417
+ * `onSubscribe` admitted the caller for this stream and topic, so the bare-topic whisper
6418
+ * channel carries no event a member was not admitted for. SSE connections are local to the
6419
+ * DO they connected to. A WebSocket can sit on a relay, so the owner also forwards the frame
6420
+ * and the grant control calls through the relay hub (see {@link OwnerRelay.forwardLiveFrame}
6421
+ * and {@link OwnerRelay.forwardLiveControl}); each relay delivers only to its own grant holders.
6422
+ *
6423
+ * `dataJson` is the already-serialized, wire-encoded payload (the producer
6424
+ * encodes once so a `bigint`/`Uint8Array` survives the hop). The caller has
6425
+ * checked the size bound.
6426
+ * @returns the number of LOCAL SSE connections and WebSocket members the frame was written to
6427
+ */
6428
+ private broadcastLiveTopic;
6429
+ /**
6430
+ * Deliver a live publish to the WebSocket whisper members of `topic` on this DO that hold the
6431
+ * live grant `key`. Both must hold: membership alone does not admit a stream's event, and a
6432
+ * grant alone does not join the socket to the topic's whisper channel. Expiry and the pending
6433
+ * room-join skip match {@link ShardDO.deliverWhisperLocal}.
6434
+ * @returns the number of sockets the frame was sent to
6435
+ */
6436
+ private deliverLiveLocal;
6437
+ /**
6438
+ * Build the live-socket indexes from the hibernated sockets, once per instance. Sockets accepted
6439
+ * or grant-changed since the build are already in the index, and the scan is idempotent, so the
6440
+ * build order does not matter.
6441
+ */
6442
+ private ensureLiveSocketIndex;
6443
+ /** The socket this DO holds for `connectionId`, or `undefined`. Builds the index on first use after a wake. */
6444
+ private findLiveSocket;
6445
+ /**
6446
+ * Write a socket's live grants to its attachment and keep the grant-holder index in step. The
6447
+ * index moves only when the write persisted, so it never claims a grant the attachment lacks.
6448
+ */
6449
+ private persistSocketGrants;
6261
6450
  private readAttachment;
6262
6451
  }
6263
6452
  /** Conventional DO instance name, passed to `idFromName` to address the single registry instance. */
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{installDeliveryFence as a}from"./packem_shared/installDeliveryFence-B6M9KOnb.mjs";import{MERGED_ROLES as t,mergeDurableObjects as c,roleNamespace as S}from"./packem_shared/MERGED_ROLES-C4RToZ16.mjs";import{serveRelationFanout as i}from"./packem_shared/serveRelationFanout-DcSjzAZv.mjs";import{SESSION_DO_TTL_DEFAULT as n,SessionDO as p}from"./packem_shared/SESSION_DO_TTL_DEFAULT-DSvTwRjc.mjs";import{ROOT_DO_SIZE_WARN_BYTES as d,ROOT_SHARD_NAME as m,ShardDO as D}from"./packem_shared/ROOT_DO_SIZE_WARN_BYTES-DPBXQLDj.mjs";import{SHARD_REGISTRY_DO_NAME as O,ShardRegistryDO as h}from"./packem_shared/SHARD_REGISTRY_DO_NAME-DRIFt2FK.mjs";import{createStableIdFactory as x}from"./packem_shared/createStableIdFactory-CAEDEee5.mjs";import{createShardAlarms as f,createShardDirectory as T,createShardHost as b,createShardKvStore as I,createShardPlatform as A,createSocketHost as M,createWorkerPlatform as g}from"@lunora/platform-cloudflare";import{REPROJECTION_MIGRATION_PREFIX as k,UNVOUCHABLE_DEP as y,applyCdcChanges as F,assertShapeShardable as L,backfillSearchIndexes as C,backfillVectorIndexes as H,buildReprojectionMigration as P,clearMemoryTables as j,countLegacyRows as v,createReadFootprint as U,createShardCtxDb as w,exportShardRows as G,importShardRows as B,isSourceDue as V,markUnvouchableReads as W,pullExternalSourceIncrementalTick as Y,pullExternalSourceTick as J,reprojectionMigrationId as K,reprojectionTables as X,runDataMigration as Z,runShardMigrations as q,subscriptionListDeltas as z}from"@lunora/shard-engine";export{t as MERGED_ROLES,k as REPROJECTION_MIGRATION_PREFIX,d as ROOT_DO_SIZE_WARN_BYTES,m as ROOT_SHARD_NAME,n as SESSION_DO_TTL_DEFAULT,O as SHARD_REGISTRY_DO_NAME,p as SessionDO,D as ShardDO,h as ShardRegistryDO,y as UNVOUCHABLE_DEP,F as applyCdcChanges,L as assertShapeShardable,C as backfillSearchIndexes,H as backfillVectorIndexes,P as buildReprojectionMigration,j as clearMemoryTables,v as countLegacyRows,U as createReadFootprint,f as createShardAlarms,w as createShardCtxDb,T as createShardDirectory,b as createShardHost,I as createShardKvStore,A as createShardPlatform,M as createSocketHost,x as createStableIdFactory,g as createWorkerPlatform,G as exportShardRows,B as importShardRows,a as installDeliveryFence,V as isSourceDue,W as markUnvouchableReads,c as mergeDurableObjects,Y as pullExternalSourceIncrementalTick,J as pullExternalSourceTick,K as reprojectionMigrationId,X as reprojectionTables,S as roleNamespace,Z as runDataMigration,q as runShardMigrations,i as serveRelationFanout,z as subscriptionListDeltas};
1
+ import{installDeliveryFence as a}from"./packem_shared/installDeliveryFence-B6M9KOnb.mjs";import{MERGED_ROLES as t,mergeDurableObjects as c,roleNamespace as S}from"./packem_shared/MERGED_ROLES-C4RToZ16.mjs";import{serveRelationFanout as i}from"./packem_shared/serveRelationFanout-DcSjzAZv.mjs";import{SESSION_DO_TTL_DEFAULT as n,SessionDO as p}from"./packem_shared/SESSION_DO_TTL_DEFAULT-DSvTwRjc.mjs";import{ROOT_DO_SIZE_WARN_BYTES as d,ROOT_SHARD_NAME as m,ShardDO as D}from"./packem_shared/ROOT_DO_SIZE_WARN_BYTES-fQcCGI_Z.mjs";import{SHARD_REGISTRY_DO_NAME as O,ShardRegistryDO as h}from"./packem_shared/SHARD_REGISTRY_DO_NAME-DRIFt2FK.mjs";import{createStableIdFactory as x}from"./packem_shared/createStableIdFactory-CAEDEee5.mjs";import{createShardAlarms as f,createShardDirectory as T,createShardHost as b,createShardKvStore as I,createShardPlatform as A,createSocketHost as M,createWorkerPlatform as g}from"@lunora/platform-cloudflare";import{REPROJECTION_MIGRATION_PREFIX as k,UNVOUCHABLE_DEP as y,applyCdcChanges as F,assertShapeShardable as L,backfillSearchIndexes as C,backfillVectorIndexes as H,buildReprojectionMigration as P,clearMemoryTables as j,countLegacyRows as v,createReadFootprint as U,createShardCtxDb as w,exportShardRows as G,importShardRows as B,isSourceDue as V,markUnvouchableReads as W,pullExternalSourceIncrementalTick as Y,pullExternalSourceTick as J,reprojectionMigrationId as K,reprojectionTables as X,runDataMigration as Z,runShardMigrations as q,subscriptionListDeltas as z}from"@lunora/shard-engine";export{t as MERGED_ROLES,k as REPROJECTION_MIGRATION_PREFIX,d as ROOT_DO_SIZE_WARN_BYTES,m as ROOT_SHARD_NAME,n as SESSION_DO_TTL_DEFAULT,O as SHARD_REGISTRY_DO_NAME,p as SessionDO,D as ShardDO,h as ShardRegistryDO,y as UNVOUCHABLE_DEP,F as applyCdcChanges,L as assertShapeShardable,C as backfillSearchIndexes,H as backfillVectorIndexes,P as buildReprojectionMigration,j as clearMemoryTables,v as countLegacyRows,U as createReadFootprint,f as createShardAlarms,w as createShardCtxDb,T as createShardDirectory,b as createShardHost,I as createShardKvStore,A as createShardPlatform,M as createSocketHost,x as createStableIdFactory,g as createWorkerPlatform,G as exportShardRows,B as importShardRows,a as installDeliveryFence,V as isSourceDue,W as markUnvouchableReads,c as mergeDurableObjects,Y as pullExternalSourceIncrementalTick,J as pullExternalSourceTick,K as reprojectionMigrationId,X as reprojectionTables,S as roleNamespace,Z as runDataMigration,q as runShardMigrations,i as serveRelationFanout,z as subscriptionListDeltas};