@lunora/do 1.0.0-alpha.304 → 1.0.0-alpha.306

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.
@@ -1795,6 +1795,14 @@ declare abstract class ShardDO {
1795
1795
  * reader never mutates one; a writer edits {@link ShardDO.readAttachmentCopy}.
1796
1796
  */
1797
1797
  private readonly attachmentCache;
1798
+ /**
1799
+ * The refresh visit running on a socket, so a write that changes several of its subscriptions
1800
+ * costs two attachment writes (digests out before the first send, in after the last), not two
1801
+ * per subscription. Present only while the visit runs.
1802
+ */
1803
+ private readonly resultDigestVisits;
1804
+ /** A socket's digest salt from the moment a digest is taken under it until the attachment holds it. */
1805
+ private readonly pendingResultSalts;
1798
1806
  /** Sockets whose `serializeAttachment` already reports into {@link ShardDO.attachmentCache}. */
1799
1807
  private readonly cacheWiredSockets;
1800
1808
  /**
@@ -5500,6 +5508,17 @@ declare abstract class ShardDO {
5500
5508
  * only for work in its own async chain.
5501
5509
  */
5502
5510
  private runShared;
5511
+ /**
5512
+ * A live query's run (a seed or a refresh) under the host's read gate: it only ever runs a query (see
5513
+ * {@link ShardDO.isQueryFunction}), and ungated it would be refused while another mutation holds the transaction.
5514
+ *
5515
+ * The module load goes first and outside the gate: a load takes the write gate, and a read asking for that has to
5516
+ * wait until it is the only reader, so two cold runs would each wait for the other. A refresh can be a path's first
5517
+ * run in this instance, after a restart restored its socket. A joiner waits on the leader's run outside the gate
5518
+ * for the same reason: holding a read slot while the leader waits to be the only reader would leave both waiting
5519
+ * forever.
5520
+ */
5521
+ private runGatedReactiveOutcome;
5503
5522
  /**
5504
5523
  * Single-flight for subscription seeds: identical seeds (same key as the
5505
5524
  * refresh dedup) that start while one is in flight join it, so a reconnect
@@ -6455,6 +6474,11 @@ declare abstract class ShardDO {
6455
6474
  * after the next wake.
6456
6475
  */
6457
6476
  private persistSubscriptionTables;
6477
+ /**
6478
+ * Retry a refused widening without the result digests and their salt: a missing table set makes a
6479
+ * write after a wake re-run a query, a missing digest only makes that re-run send in full.
6480
+ */
6481
+ private widenWithoutResultDigests;
6458
6482
  /**
6459
6483
  * Memoise `outcome` for `(ws, subId)` and push it to the socket, unless an
6460
6484
  * identical result was already sent. Always refreshes the memo's table set
@@ -6482,6 +6506,48 @@ declare abstract class ShardDO {
6482
6506
  * `pageDeltas` a redundant attachment read.
6483
6507
  */
6484
6508
  private pushSubscriptionData;
6509
+ /**
6510
+ * Whether `json` is the result `subId`'s client already holds: its memo's baseline, or, for a memo
6511
+ * without one (restored after a wake, or dropped for size), the socket's stored digest. A digest
6512
+ * match makes `json` the memo's baseline, so later changes diff against it.
6513
+ *
6514
+ * A false match suppresses a real change until the next one. The digest is 64 bits of FNV-1a,
6515
+ * keyed by a random per-socket salt: the salt stops a user who controls part of a shared result
6516
+ * from crafting a collision, since FNV-1a over a known prefix is easy to invert; it does not make
6517
+ * the digest cryptographic, so it guards against chance and steering, not against someone who has
6518
+ * read the socket's attachment. Chance alone is about one in 2^64 per comparison.
6519
+ *
6520
+ * A stored digest never describes a value the client may have replaced: a refresh visit removes
6521
+ * the digests of the subscriptions it may send to before its first frame leaves, and writes the
6522
+ * new ones after its last, so a restart between the two leaves no digest rather than a stale one.
6523
+ */
6524
+ private clientHoldsResult;
6525
+ /** The digest of the result `subId`'s client holds, counting what a running visit has not written yet. */
6526
+ private resultDigest;
6527
+ /** The salt a digest taken now is taken under, without minting one. */
6528
+ private currentResultSalt;
6529
+ /** A (re)subscribe, unsubscribe or permit change: whatever a running visit holds for `subId` no longer applies. */
6530
+ private forgetResultDigest;
6531
+ /**
6532
+ * Before a `data`/`delta` frame for `subId` leaves: take every digest the running visit may make
6533
+ * stale out of storage in one write, the first time it sends; outside a visit (a seed), just this
6534
+ * subscription's. A subscription the prediction left out costs one more write when it sends anyway.
6535
+ */
6536
+ private clearResultDigestsBeforeSend;
6537
+ /** Whether this flush may send `subId` a new value; the restored-memo view of a cold subscription comes from its persisted tables. */
6538
+ private maySendOnFlush;
6539
+ /** Record what `subId`'s client holds after a send of `json`: at the end of a running refresh visit, else at once. */
6540
+ private stageResultDigest;
6541
+ /** `json`'s digest under the socket's salt, minting the salt on the socket's first digest. */
6542
+ private digestResult;
6543
+ /** Run one socket's refresh visit with its result digests written back once, when it ends. */
6544
+ private withResultDigestVisit;
6545
+ /**
6546
+ * Fold `digests` into the attachment in one write, reporting whether it landed. Never throws. A
6547
+ * write the runtime refuses would leave the digests of the values these frames replaced, so it is
6548
+ * retried as a copy without any entry for those subscriptions, smaller than the stored attachment.
6549
+ */
6550
+ private writeResultDigests;
6485
6551
  private sendSubscriptionSettlement;
6486
6552
  private allowsSubscriptionOutcome;
6487
6553
  /**
@@ -6986,13 +7052,14 @@ declare abstract class ShardDO {
6986
7052
  * Persist `value` as the socket's attachment and cache it; `undefined` clears
6987
7053
  * both. The caller must not mutate `value` afterwards.
6988
7054
  *
6989
- * The table sets in `subTables` are optional and share the size limit with
6990
- * everything a socket must hold, so a write the runtime refuses is retried
6991
- * once as a copy without them: a registration never fails for
6992
- * their sake, and their subscriptions re-run after a wake until a run records
6993
- * them again. `shedTableSets: false` refuses that retry, for the write that
6994
- * only widens one set. A write that still fails drops the cache entry and
6995
- * rethrows, so the next read decodes what storage actually holds.
7055
+ * The table sets in `subTables` and the result digests in `subResults` are
7056
+ * optional and share the size limit with everything a socket must hold, so a
7057
+ * write the runtime refuses is retried once as a copy without them: a
7058
+ * registration never fails for their sake, and their subscriptions re-run (and
7059
+ * resend in full) after a wake until a run records them again.
7060
+ * `shedTableSets: false` refuses that retry, for the writes that only add to
7061
+ * them. A write that still fails drops the cache entry and rethrows, so the
7062
+ * next read decodes what storage actually holds.
6996
7063
  */
6997
7064
  private writeAttachment;
6998
7065
  }
@@ -1795,6 +1795,14 @@ declare abstract class ShardDO {
1795
1795
  * reader never mutates one; a writer edits {@link ShardDO.readAttachmentCopy}.
1796
1796
  */
1797
1797
  private readonly attachmentCache;
1798
+ /**
1799
+ * The refresh visit running on a socket, so a write that changes several of its subscriptions
1800
+ * costs two attachment writes (digests out before the first send, in after the last), not two
1801
+ * per subscription. Present only while the visit runs.
1802
+ */
1803
+ private readonly resultDigestVisits;
1804
+ /** A socket's digest salt from the moment a digest is taken under it until the attachment holds it. */
1805
+ private readonly pendingResultSalts;
1798
1806
  /** Sockets whose `serializeAttachment` already reports into {@link ShardDO.attachmentCache}. */
1799
1807
  private readonly cacheWiredSockets;
1800
1808
  /**
@@ -5500,6 +5508,17 @@ declare abstract class ShardDO {
5500
5508
  * only for work in its own async chain.
5501
5509
  */
5502
5510
  private runShared;
5511
+ /**
5512
+ * A live query's run (a seed or a refresh) under the host's read gate: it only ever runs a query (see
5513
+ * {@link ShardDO.isQueryFunction}), and ungated it would be refused while another mutation holds the transaction.
5514
+ *
5515
+ * The module load goes first and outside the gate: a load takes the write gate, and a read asking for that has to
5516
+ * wait until it is the only reader, so two cold runs would each wait for the other. A refresh can be a path's first
5517
+ * run in this instance, after a restart restored its socket. A joiner waits on the leader's run outside the gate
5518
+ * for the same reason: holding a read slot while the leader waits to be the only reader would leave both waiting
5519
+ * forever.
5520
+ */
5521
+ private runGatedReactiveOutcome;
5503
5522
  /**
5504
5523
  * Single-flight for subscription seeds: identical seeds (same key as the
5505
5524
  * refresh dedup) that start while one is in flight join it, so a reconnect
@@ -6455,6 +6474,11 @@ declare abstract class ShardDO {
6455
6474
  * after the next wake.
6456
6475
  */
6457
6476
  private persistSubscriptionTables;
6477
+ /**
6478
+ * Retry a refused widening without the result digests and their salt: a missing table set makes a
6479
+ * write after a wake re-run a query, a missing digest only makes that re-run send in full.
6480
+ */
6481
+ private widenWithoutResultDigests;
6458
6482
  /**
6459
6483
  * Memoise `outcome` for `(ws, subId)` and push it to the socket, unless an
6460
6484
  * identical result was already sent. Always refreshes the memo's table set
@@ -6482,6 +6506,48 @@ declare abstract class ShardDO {
6482
6506
  * `pageDeltas` a redundant attachment read.
6483
6507
  */
6484
6508
  private pushSubscriptionData;
6509
+ /**
6510
+ * Whether `json` is the result `subId`'s client already holds: its memo's baseline, or, for a memo
6511
+ * without one (restored after a wake, or dropped for size), the socket's stored digest. A digest
6512
+ * match makes `json` the memo's baseline, so later changes diff against it.
6513
+ *
6514
+ * A false match suppresses a real change until the next one. The digest is 64 bits of FNV-1a,
6515
+ * keyed by a random per-socket salt: the salt stops a user who controls part of a shared result
6516
+ * from crafting a collision, since FNV-1a over a known prefix is easy to invert; it does not make
6517
+ * the digest cryptographic, so it guards against chance and steering, not against someone who has
6518
+ * read the socket's attachment. Chance alone is about one in 2^64 per comparison.
6519
+ *
6520
+ * A stored digest never describes a value the client may have replaced: a refresh visit removes
6521
+ * the digests of the subscriptions it may send to before its first frame leaves, and writes the
6522
+ * new ones after its last, so a restart between the two leaves no digest rather than a stale one.
6523
+ */
6524
+ private clientHoldsResult;
6525
+ /** The digest of the result `subId`'s client holds, counting what a running visit has not written yet. */
6526
+ private resultDigest;
6527
+ /** The salt a digest taken now is taken under, without minting one. */
6528
+ private currentResultSalt;
6529
+ /** A (re)subscribe, unsubscribe or permit change: whatever a running visit holds for `subId` no longer applies. */
6530
+ private forgetResultDigest;
6531
+ /**
6532
+ * Before a `data`/`delta` frame for `subId` leaves: take every digest the running visit may make
6533
+ * stale out of storage in one write, the first time it sends; outside a visit (a seed), just this
6534
+ * subscription's. A subscription the prediction left out costs one more write when it sends anyway.
6535
+ */
6536
+ private clearResultDigestsBeforeSend;
6537
+ /** Whether this flush may send `subId` a new value; the restored-memo view of a cold subscription comes from its persisted tables. */
6538
+ private maySendOnFlush;
6539
+ /** Record what `subId`'s client holds after a send of `json`: at the end of a running refresh visit, else at once. */
6540
+ private stageResultDigest;
6541
+ /** `json`'s digest under the socket's salt, minting the salt on the socket's first digest. */
6542
+ private digestResult;
6543
+ /** Run one socket's refresh visit with its result digests written back once, when it ends. */
6544
+ private withResultDigestVisit;
6545
+ /**
6546
+ * Fold `digests` into the attachment in one write, reporting whether it landed. Never throws. A
6547
+ * write the runtime refuses would leave the digests of the values these frames replaced, so it is
6548
+ * retried as a copy without any entry for those subscriptions, smaller than the stored attachment.
6549
+ */
6550
+ private writeResultDigests;
6485
6551
  private sendSubscriptionSettlement;
6486
6552
  private allowsSubscriptionOutcome;
6487
6553
  /**
@@ -6986,13 +7052,14 @@ declare abstract class ShardDO {
6986
7052
  * Persist `value` as the socket's attachment and cache it; `undefined` clears
6987
7053
  * both. The caller must not mutate `value` afterwards.
6988
7054
  *
6989
- * The table sets in `subTables` are optional and share the size limit with
6990
- * everything a socket must hold, so a write the runtime refuses is retried
6991
- * once as a copy without them: a registration never fails for
6992
- * their sake, and their subscriptions re-run after a wake until a run records
6993
- * them again. `shedTableSets: false` refuses that retry, for the write that
6994
- * only widens one set. A write that still fails drops the cache entry and
6995
- * rethrows, so the next read decodes what storage actually holds.
7055
+ * The table sets in `subTables` and the result digests in `subResults` are
7056
+ * optional and share the size limit with everything a socket must hold, so a
7057
+ * write the runtime refuses is retried once as a copy without them: a
7058
+ * registration never fails for their sake, and their subscriptions re-run (and
7059
+ * resend in full) after a wake until a run records them again.
7060
+ * `shedTableSets: false` refuses that retry, for the writes that only add to
7061
+ * them. A write that still fails drops the cache entry and rethrows, so the
7062
+ * next read decodes what storage actually holds.
6996
7063
  */
6997
7064
  private writeAttachment;
6998
7065
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/do",
3
- "version": "1.0.0-alpha.304",
3
+ "version": "1.0.0-alpha.306",
4
4
  "description": "Lunora Durable Objects: ShardDO (SQLite, OCC, hibernated WebSocket subscriptions) and SessionDO",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -54,7 +54,7 @@
54
54
  "@lunora/observability": "^1.0.0-alpha.207",
55
55
  "@lunora/platform": "^1.0.0-alpha.85",
56
56
  "@lunora/platform-cloudflare": "^1.0.0-alpha.126",
57
- "@lunora/shard-engine": "^1.0.0-alpha.214",
57
+ "@lunora/shard-engine": "^1.0.0-alpha.216",
58
58
  "@lunora/values": "^1.0.0-alpha.95",
59
59
  "@lunora/wire": "1.0.0-alpha.6",
60
60
  "drizzle-orm": "1.0.0-rc.5"