@lunora/do 1.0.0-alpha.295 → 1.0.0-alpha.296

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
@@ -1558,7 +1558,14 @@ declare abstract class ShardDO {
1558
1558
  private readonly deliveryRequestPermits;
1559
1559
  private currentDeliveryPermit;
1560
1560
  private transactionRequestScope;
1561
- private readonly deliveryRegistrations;
1561
+ /**
1562
+ * Per socket, the identity of each subscription id's current registration: `subscribe` mints a
1563
+ * new one when it (re)registers an id, `unsubscribe` drops it. A path that awaits between reading
1564
+ * a subscription and acting on it compares identities so it never acts on a replacement. Memory
1565
+ * only, so a subscription restored from hibernation gets one lazily — see
1566
+ * {@link ShardDO.subscriptionRegistration}.
1567
+ */
1568
+ private readonly subscriptionRegistrations;
1562
1569
  /** ctx-db relation knobs from {@link ShardDOOptions}, handed on by {@link ShardDO.ctxDbTuning}. */
1563
1570
  private readonly ctxDbRelationOptions;
1564
1571
  /**
@@ -2099,6 +2106,8 @@ declare abstract class ShardDO {
2099
2106
  private readonly queuedSocketEvents;
2100
2107
  /** Sockets whose close is in progress: their room membership is being torn down, so nothing new may join or leave. */
2101
2108
  private readonly closingSockets;
2109
+ /** Per socket, the subscribe ids waiting on their function's load; see {@link ShardDO.subscribeOutlivedLoad}. */
2110
+ private readonly loadingSubscribes;
2102
2111
  /**
2103
2112
  * Sockets holding at least one live grant, so a publish visits only grant holders. Kept as a
2104
2113
  * superset of the truth: `deliverLiveLocal` re-checks each socket's attachment, and drops an
@@ -3672,6 +3681,15 @@ declare abstract class ShardDO {
3672
3681
  * nothing — and this is the only place left that still knows the call is paid.
3673
3682
  */
3674
3683
  protected isPaidFunction(_functionPath: string): boolean;
3684
+ /**
3685
+ * Whether `functionPath`'s `.use()` chain carries a per-dispatch middleware
3686
+ * (`perDispatch` on the registered function). `subscribe` refuses such a
3687
+ * query: a live query re-runs the chain on every refresh, and the effect —
3688
+ * limiter budget, a single-use token — must happen once per request. The
3689
+ * base class has no function registry, so the default is `false`; the
3690
+ * codegen-generated subclass answers from `LUNORA_FUNCTIONS`.
3691
+ */
3692
+ protected isPerDispatchFunction(_functionPath: string): boolean;
3675
3693
  /**
3676
3694
  * The argument names of `functionPath` whose validators carry a `v.sensitive`
3677
3695
  * marker. The request log replaces them before anything is persisted, logged or
@@ -3725,10 +3743,11 @@ declare abstract class ShardDO {
3725
3743
  * serialize. We never throw out of this path — the WS hibernation API
3726
3744
  * treats a thrown `webSocketMessage` as a fatal-channel error.
3727
3745
  *
3728
- * The `paid` refusal sits here rather than at the envelope so every
3729
- * registration path — not only the `subscribe` frame — goes through it.
3746
+ * The `paid` and `per_dispatch` refusals sit here rather than at the
3747
+ * envelope so every registration path — not only the `subscribe` frame —
3748
+ * goes through them.
3730
3749
  */
3731
- protected subscribe(ws: ShardSocketLike, subId: string, query: SubscriptionQuery): "ok" | "paid" | "serialize_failed" | "too_many";
3750
+ protected subscribe(ws: ShardSocketLike, subId: string, query: SubscriptionQuery): "ok" | "paid" | "per_dispatch" | "serialize_failed" | "too_many";
3732
3751
  protected unsubscribe(ws: ShardSocketLike, subId: string): void;
3733
3752
  /**
3734
3753
  * Register a live shape subscription on a socket — the partial-replication
@@ -4566,6 +4585,35 @@ declare abstract class ShardDO {
4566
4585
  * as this request's. The dispatch path re-pins its own afterwards.
4567
4586
  */
4568
4587
  protected restoreRequestScope(scope: RequestScope): void;
4588
+ /**
4589
+ * Load `functionPath`'s module before a live-query gate reads its registry entry: a lazy
4590
+ * registry's stub carries no `perDispatch` until then, so the gate would wave a cold per-dispatch
4591
+ * query through and run it once. A failed load is left to the run that follows, which reports it.
4592
+ *
4593
+ * The per-request fields are left alone: a socket path pins its identity around each run it
4594
+ * makes, so it holds no scope here, and putting a snapshot back after the wait would overwrite
4595
+ * those of a dispatch that ran meanwhile.
4596
+ */
4597
+ private prepareForLiveQueryGate;
4598
+ /**
4599
+ * Wait out a subscribe's function load, answering whether the subscribe may still register: an
4600
+ * unsubscribe for the same id, or the socket closing, during the wait makes it moot.
4601
+ */
4602
+ private subscribeOutlivedLoad;
4603
+ /** The identity of `subId`'s current registration on `ws`, minted for one restored from hibernation. */
4604
+ private subscriptionRegistration;
4605
+ /** Whether `subId` on `ws` is still the registration a caller read before awaiting. */
4606
+ private holdsRegistration;
4607
+ /**
4608
+ * The refresh sweep's gate: drop `subId` (and tell the client) when its function may not be held
4609
+ * live, once that function is loaded. `undefined` keeps it, decided without a yield; a promise
4610
+ * answers whether the sweep must skip it — dropped, or replaced or unsubscribed during the load,
4611
+ * in which case `functionPath` names a query the id no longer holds — and is only pending while
4612
+ * a cold function loads.
4613
+ */
4614
+ private dropIfNotLive;
4615
+ /** Why `functionPath` may not be held as a live subscription, or `undefined` when it may; shared by `subscribe` and the refresh sweep. */
4616
+ private liveQueryRefusal;
4569
4617
  /**
4570
4618
  * Whether a subscription gets its updates by re-execution, which diffs the
4571
4619
  * query's own result. A broadcast row would bypass that diff baseline (no
@@ -5984,6 +6032,8 @@ declare abstract class ShardDO {
5984
6032
  * persist failure. A subscription hitting one ends rather than latching for backoff.
5985
6033
  */
5986
6034
  private isDeterministicSubscriptionFailure;
6035
+ /** The refresh sweep's answer to a subscription run that threw. */
6036
+ private failRefresh;
5987
6037
  /**
5988
6038
  * A subscription's refresh threw: count and log it, latch it for backoff, and
5989
6039
  * tell the client the first time of a streak. The subscription stays
package/dist/index.d.ts CHANGED
@@ -1558,7 +1558,14 @@ declare abstract class ShardDO {
1558
1558
  private readonly deliveryRequestPermits;
1559
1559
  private currentDeliveryPermit;
1560
1560
  private transactionRequestScope;
1561
- private readonly deliveryRegistrations;
1561
+ /**
1562
+ * Per socket, the identity of each subscription id's current registration: `subscribe` mints a
1563
+ * new one when it (re)registers an id, `unsubscribe` drops it. A path that awaits between reading
1564
+ * a subscription and acting on it compares identities so it never acts on a replacement. Memory
1565
+ * only, so a subscription restored from hibernation gets one lazily — see
1566
+ * {@link ShardDO.subscriptionRegistration}.
1567
+ */
1568
+ private readonly subscriptionRegistrations;
1562
1569
  /** ctx-db relation knobs from {@link ShardDOOptions}, handed on by {@link ShardDO.ctxDbTuning}. */
1563
1570
  private readonly ctxDbRelationOptions;
1564
1571
  /**
@@ -2099,6 +2106,8 @@ declare abstract class ShardDO {
2099
2106
  private readonly queuedSocketEvents;
2100
2107
  /** Sockets whose close is in progress: their room membership is being torn down, so nothing new may join or leave. */
2101
2108
  private readonly closingSockets;
2109
+ /** Per socket, the subscribe ids waiting on their function's load; see {@link ShardDO.subscribeOutlivedLoad}. */
2110
+ private readonly loadingSubscribes;
2102
2111
  /**
2103
2112
  * Sockets holding at least one live grant, so a publish visits only grant holders. Kept as a
2104
2113
  * superset of the truth: `deliverLiveLocal` re-checks each socket's attachment, and drops an
@@ -3672,6 +3681,15 @@ declare abstract class ShardDO {
3672
3681
  * nothing — and this is the only place left that still knows the call is paid.
3673
3682
  */
3674
3683
  protected isPaidFunction(_functionPath: string): boolean;
3684
+ /**
3685
+ * Whether `functionPath`'s `.use()` chain carries a per-dispatch middleware
3686
+ * (`perDispatch` on the registered function). `subscribe` refuses such a
3687
+ * query: a live query re-runs the chain on every refresh, and the effect —
3688
+ * limiter budget, a single-use token — must happen once per request. The
3689
+ * base class has no function registry, so the default is `false`; the
3690
+ * codegen-generated subclass answers from `LUNORA_FUNCTIONS`.
3691
+ */
3692
+ protected isPerDispatchFunction(_functionPath: string): boolean;
3675
3693
  /**
3676
3694
  * The argument names of `functionPath` whose validators carry a `v.sensitive`
3677
3695
  * marker. The request log replaces them before anything is persisted, logged or
@@ -3725,10 +3743,11 @@ declare abstract class ShardDO {
3725
3743
  * serialize. We never throw out of this path — the WS hibernation API
3726
3744
  * treats a thrown `webSocketMessage` as a fatal-channel error.
3727
3745
  *
3728
- * The `paid` refusal sits here rather than at the envelope so every
3729
- * registration path — not only the `subscribe` frame — goes through it.
3746
+ * The `paid` and `per_dispatch` refusals sit here rather than at the
3747
+ * envelope so every registration path — not only the `subscribe` frame —
3748
+ * goes through them.
3730
3749
  */
3731
- protected subscribe(ws: ShardSocketLike, subId: string, query: SubscriptionQuery): "ok" | "paid" | "serialize_failed" | "too_many";
3750
+ protected subscribe(ws: ShardSocketLike, subId: string, query: SubscriptionQuery): "ok" | "paid" | "per_dispatch" | "serialize_failed" | "too_many";
3732
3751
  protected unsubscribe(ws: ShardSocketLike, subId: string): void;
3733
3752
  /**
3734
3753
  * Register a live shape subscription on a socket — the partial-replication
@@ -4566,6 +4585,35 @@ declare abstract class ShardDO {
4566
4585
  * as this request's. The dispatch path re-pins its own afterwards.
4567
4586
  */
4568
4587
  protected restoreRequestScope(scope: RequestScope): void;
4588
+ /**
4589
+ * Load `functionPath`'s module before a live-query gate reads its registry entry: a lazy
4590
+ * registry's stub carries no `perDispatch` until then, so the gate would wave a cold per-dispatch
4591
+ * query through and run it once. A failed load is left to the run that follows, which reports it.
4592
+ *
4593
+ * The per-request fields are left alone: a socket path pins its identity around each run it
4594
+ * makes, so it holds no scope here, and putting a snapshot back after the wait would overwrite
4595
+ * those of a dispatch that ran meanwhile.
4596
+ */
4597
+ private prepareForLiveQueryGate;
4598
+ /**
4599
+ * Wait out a subscribe's function load, answering whether the subscribe may still register: an
4600
+ * unsubscribe for the same id, or the socket closing, during the wait makes it moot.
4601
+ */
4602
+ private subscribeOutlivedLoad;
4603
+ /** The identity of `subId`'s current registration on `ws`, minted for one restored from hibernation. */
4604
+ private subscriptionRegistration;
4605
+ /** Whether `subId` on `ws` is still the registration a caller read before awaiting. */
4606
+ private holdsRegistration;
4607
+ /**
4608
+ * The refresh sweep's gate: drop `subId` (and tell the client) when its function may not be held
4609
+ * live, once that function is loaded. `undefined` keeps it, decided without a yield; a promise
4610
+ * answers whether the sweep must skip it — dropped, or replaced or unsubscribed during the load,
4611
+ * in which case `functionPath` names a query the id no longer holds — and is only pending while
4612
+ * a cold function loads.
4613
+ */
4614
+ private dropIfNotLive;
4615
+ /** Why `functionPath` may not be held as a live subscription, or `undefined` when it may; shared by `subscribe` and the refresh sweep. */
4616
+ private liveQueryRefusal;
4569
4617
  /**
4570
4618
  * Whether a subscription gets its updates by re-execution, which diffs the
4571
4619
  * query's own result. A broadcast row would bypass that diff baseline (no
@@ -5984,6 +6032,8 @@ declare abstract class ShardDO {
5984
6032
  * persist failure. A subscription hitting one ends rather than latching for backoff.
5985
6033
  */
5986
6034
  private isDeterministicSubscriptionFailure;
6035
+ /** The refresh sweep's answer to a subscription run that threw. */
6036
+ private failRefresh;
5987
6037
  /**
5988
6038
  * A subscription's refresh threw: count and log it, latch it for backoff, and
5989
6039
  * tell the client the first time of a streak. The subscription stays
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{AdminRevocationDO as a}from"./packem_shared/AdminRevocationDO-DHjoZWfF.mjs";import{installDeliveryFence as t}from"./packem_shared/installDeliveryFence-B6M9KOnb.mjs";import{MERGED_ROLES as S,mergeDurableObjects as i,roleNamespace as l}from"./packem_shared/MERGED_ROLES-BAMAmIcW.mjs";import{serveRelationFanout as n}from"./packem_shared/serveRelationFanout-Bms_fuoY.mjs";import{SESSION_DO_TTL_DEFAULT as d,SessionDO as p}from"./packem_shared/SESSION_DO_TTL_DEFAULT-DSvTwRjc.mjs";import{ROOT_DO_SIZE_WARN_BYTES as D,ROOT_SHARD_NAME as O,ShardDO as E}from"./packem_shared/ROOT_DO_SIZE_WARN_BYTES-ALVGgqTd.mjs";import{SHARD_REGISTRY_DO_NAME as h,ShardRegistryDO as x,hostedShardRegistry as f}from"./packem_shared/SHARD_REGISTRY_DO_NAME-Dbh8JQJQ.mjs";import{createStableIdFactory as A,createStableRandomFactory as I}from"./packem_shared/createStableIdFactory-DPDT_chw.mjs";import{createShardAlarms as b,createShardDirectory as M,createShardHost as N,createShardKvStore as g,createShardPlatform as y,createSocketHost as k,createWorkerPlatform as F}from"@lunora/platform-cloudflare";import{REPROJECTION_MIGRATION_PREFIX as L,UNVOUCHABLE_DEP as v,applyCdcChanges as H,assertShapeShardable as P,backfillSearchIndexes as j,backfillVectorIndexes as U,buildReprojectionMigration as w,clearMemoryTables as G,countLegacyRows as V,createReadFootprint as B,createShardCtxDb as W,exportShardRows as Y,importShardRows as J,isSourceDue as K,markUnvouchableReads as X,pullExternalSourceIncrementalTick as Z,pullExternalSourceTick as q,reprojectionMigrationId as z,reprojectionTables as Q,runDataMigration as $,runShardMigrations as ee,subscriptionListDeltas as re}from"@lunora/shard-engine";import{A as oe}from"./packem_shared/admin-token-DrufJIZV.mjs";export{oe as ADMIN_REVOCATION_DO_NAME,a as AdminRevocationDO,S as MERGED_ROLES,L as REPROJECTION_MIGRATION_PREFIX,D as ROOT_DO_SIZE_WARN_BYTES,O as ROOT_SHARD_NAME,d as SESSION_DO_TTL_DEFAULT,h as SHARD_REGISTRY_DO_NAME,p as SessionDO,E as ShardDO,x as ShardRegistryDO,v as UNVOUCHABLE_DEP,H as applyCdcChanges,P as assertShapeShardable,j as backfillSearchIndexes,U as backfillVectorIndexes,w as buildReprojectionMigration,G as clearMemoryTables,V as countLegacyRows,B as createReadFootprint,b as createShardAlarms,W as createShardCtxDb,M as createShardDirectory,N as createShardHost,g as createShardKvStore,y as createShardPlatform,k as createSocketHost,A as createStableIdFactory,I as createStableRandomFactory,F as createWorkerPlatform,Y as exportShardRows,f as hostedShardRegistry,J as importShardRows,t as installDeliveryFence,K as isSourceDue,X as markUnvouchableReads,i as mergeDurableObjects,Z as pullExternalSourceIncrementalTick,q as pullExternalSourceTick,z as reprojectionMigrationId,Q as reprojectionTables,l as roleNamespace,$ as runDataMigration,ee as runShardMigrations,n as serveRelationFanout,re as subscriptionListDeltas};
1
+ import{AdminRevocationDO as a}from"./packem_shared/AdminRevocationDO-DHjoZWfF.mjs";import{installDeliveryFence as t}from"./packem_shared/installDeliveryFence-B6M9KOnb.mjs";import{MERGED_ROLES as S,mergeDurableObjects as i,roleNamespace as l}from"./packem_shared/MERGED_ROLES-BAMAmIcW.mjs";import{serveRelationFanout as n}from"./packem_shared/serveRelationFanout-Bms_fuoY.mjs";import{SESSION_DO_TTL_DEFAULT as d,SessionDO as p}from"./packem_shared/SESSION_DO_TTL_DEFAULT-DSvTwRjc.mjs";import{ROOT_DO_SIZE_WARN_BYTES as D,ROOT_SHARD_NAME as O,ShardDO as E}from"./packem_shared/ROOT_DO_SIZE_WARN_BYTES-BO0jZbrG.mjs";import{SHARD_REGISTRY_DO_NAME as h,ShardRegistryDO as x,hostedShardRegistry as f}from"./packem_shared/SHARD_REGISTRY_DO_NAME-Dbh8JQJQ.mjs";import{createStableIdFactory as A,createStableRandomFactory as I}from"./packem_shared/createStableIdFactory-DPDT_chw.mjs";import{createShardAlarms as b,createShardDirectory as M,createShardHost as N,createShardKvStore as g,createShardPlatform as y,createSocketHost as k,createWorkerPlatform as F}from"@lunora/platform-cloudflare";import{REPROJECTION_MIGRATION_PREFIX as L,UNVOUCHABLE_DEP as v,applyCdcChanges as H,assertShapeShardable as P,backfillSearchIndexes as j,backfillVectorIndexes as U,buildReprojectionMigration as w,clearMemoryTables as G,countLegacyRows as V,createReadFootprint as B,createShardCtxDb as W,exportShardRows as Y,importShardRows as J,isSourceDue as K,markUnvouchableReads as X,pullExternalSourceIncrementalTick as Z,pullExternalSourceTick as q,reprojectionMigrationId as z,reprojectionTables as Q,runDataMigration as $,runShardMigrations as ee,subscriptionListDeltas as re}from"@lunora/shard-engine";import{A as oe}from"./packem_shared/admin-token-DrufJIZV.mjs";export{oe as ADMIN_REVOCATION_DO_NAME,a as AdminRevocationDO,S as MERGED_ROLES,L as REPROJECTION_MIGRATION_PREFIX,D as ROOT_DO_SIZE_WARN_BYTES,O as ROOT_SHARD_NAME,d as SESSION_DO_TTL_DEFAULT,h as SHARD_REGISTRY_DO_NAME,p as SessionDO,E as ShardDO,x as ShardRegistryDO,v as UNVOUCHABLE_DEP,H as applyCdcChanges,P as assertShapeShardable,j as backfillSearchIndexes,U as backfillVectorIndexes,w as buildReprojectionMigration,G as clearMemoryTables,V as countLegacyRows,B as createReadFootprint,b as createShardAlarms,W as createShardCtxDb,M as createShardDirectory,N as createShardHost,g as createShardKvStore,y as createShardPlatform,k as createSocketHost,A as createStableIdFactory,I as createStableRandomFactory,F as createWorkerPlatform,Y as exportShardRows,f as hostedShardRegistry,J as importShardRows,t as installDeliveryFence,K as isSourceDue,X as markUnvouchableReads,i as mergeDurableObjects,Z as pullExternalSourceIncrementalTick,q as pullExternalSourceTick,z as reprojectionMigrationId,Q as reprojectionTables,l as roleNamespace,$ as runDataMigration,ee as runShardMigrations,n as serveRelationFanout,re as subscriptionListDeltas};