@lunora/db 1.0.0-alpha.77 → 1.0.0-alpha.79

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.
@@ -1,5 +1,5 @@
1
- export { type b as CheckpointRegistry, type L as LunoraCollectionConfig, type f as LunoraCollectionOptions, i as createCheckpointRegistry, m as lunoraCollectionOptions } from "../packem_shared/collection-options.d-BDL5mz7T.mjs";
2
- export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/index.d-DJ2mA1Ci.mjs";
1
+ export { type b as CheckpointRegistry, type L as LunoraCollectionConfig, type f as LunoraCollectionOptions, i as createCheckpointRegistry, m as lunoraCollectionOptions } from "../packem_shared/collection-options.d-BA8jp3ji.mjs";
2
+ export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/index.d-Depww9_D.mjs";
3
3
  import '@lunora/client';
4
4
  import '@tanstack/db';
5
5
  import '@tanstack/offline-transactions';
@@ -1,5 +1,5 @@
1
- export { type b as CheckpointRegistry, type L as LunoraCollectionConfig, type f as LunoraCollectionOptions, i as createCheckpointRegistry, m as lunoraCollectionOptions } from "../packem_shared/collection-options.d-BDL5mz7T.js";
2
- export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/index.d-seIZK_RO.js";
1
+ export { type b as CheckpointRegistry, type L as LunoraCollectionConfig, type f as LunoraCollectionOptions, i as createCheckpointRegistry, m as lunoraCollectionOptions } from "../packem_shared/collection-options.d-BA8jp3ji.js";
2
+ export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/index.d-C3aBVnK7.js";
3
3
  import '@lunora/client';
4
4
  import '@tanstack/db';
5
5
  import '@tanstack/offline-transactions';
@@ -1 +1 @@
1
- import{createCheckpointRegistry as t,lunoraCollectionOptions as r}from"../packem_shared/CHECKPOINT_FALLBACK_MS-DAWfz0yD.mjs";import{defineCollections as n}from"../packem_shared/defineCollections-DLPLAvjt.mjs";export{t as createCheckpointRegistry,n as defineCollections,r as lunoraCollectionOptions};
1
+ import{createCheckpointRegistry as t,lunoraCollectionOptions as r}from"../packem_shared/CHECKPOINT_FALLBACK_MS-DAWfz0yD.mjs";import{defineCollections as n}from"../packem_shared/defineCollections-Czhhf-A8.mjs";export{t as createCheckpointRegistry,n as defineCollections,r as lunoraCollectionOptions};
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Collection } from '@tanstack/db';
2
- import { R as Row } from "./packem_shared/collection-options.d-BDL5mz7T.mjs";
3
- export { C as CHECKPOINT_FALLBACK_MS, type a as CheckpointFallbackEvent, type b as CheckpointRegistry, type c as CheckpointRegistryOptions, type d as CheckpointRegistryStats, type e as CheckpointWatermark, type E as ExecutorOutboxSinkOptions, type L as LunoraCollectionConfig, type f as LunoraCollectionOptions, O as OUTBOX_MUTATION_FN_NAME, type g as OutboxExecutor, type h as OutboxMutationMetadata, type S as SyncWriter, i as createCheckpointRegistry, j as createExecutorOutboxSink, k as createOptimisticOnlineDetector, l as getShardCheckpoints, m as lunoraCollectionOptions, n as makeDiffEmit, r as releaseShardCheckpoints, o as runOutboxMutation, t as toMap } from "./packem_shared/collection-options.d-BDL5mz7T.mjs";
4
- export { type C as CollectionDef, type D as DefineCollectionsOptions, type I as InsertBinding, type L as LunoraDb, type W as WriteRejectedEvent, d as defineCollections } from "./packem_shared/index.d-DJ2mA1Ci.mjs";
5
- export { type B as BindMutatorsContext, type a as BoundMutatorApi, type b as BoundMutators, type C as ClientMutatorContext, type c as ClientMutatorDef, type d as CollectionMap, D as DIRECT_TRANSACTION_METADATA_KEY, type M as MutatorReference, type e as MutatorRejectedEvent, f as bindMutators, g as defineMutator, i as initMutators } from "./packem_shared/index.d-xovzQ7rA.mjs";
2
+ import { R as Row } from "./packem_shared/collection-options.d-BA8jp3ji.mjs";
3
+ export { C as CHECKPOINT_FALLBACK_MS, type a as CheckpointFallbackEvent, type b as CheckpointRegistry, type c as CheckpointRegistryOptions, type d as CheckpointRegistryStats, type e as CheckpointWatermark, type E as ExecutorOutboxSinkOptions, type L as LunoraCollectionConfig, type f as LunoraCollectionOptions, O as OUTBOX_MUTATION_FN_NAME, type g as OutboxExecutor, type h as OutboxMutationMetadata, type S as SyncWriter, i as createCheckpointRegistry, j as createExecutorOutboxSink, k as createOptimisticOnlineDetector, l as getShardCheckpoints, m as lunoraCollectionOptions, n as makeDiffEmit, r as releaseShardCheckpoints, o as runOutboxMutation, t as toMap } from "./packem_shared/collection-options.d-BA8jp3ji.mjs";
4
+ export { type C as CollectionDef, type D as DefineCollectionsOptions, type I as InsertBinding, type L as LunoraDb, type W as WriteRejectedEvent, d as defineCollections } from "./packem_shared/index.d-Depww9_D.mjs";
5
+ export { type B as BindMutatorsContext, type a as BoundMutatorApi, type b as BoundMutators, type C as ClientMutatorContext, type c as ClientMutatorDef, type d as CollectionMap, D as DIRECT_TRANSACTION_METADATA_KEY, type M as MutatorReference, type e as MutatorRejectedEvent, f as bindMutators, g as defineMutator, i as initMutators } from "./packem_shared/index.d-BCKTZhCD.mjs";
6
6
  import '@lunora/client';
7
7
  import '@tanstack/offline-transactions';
8
8
  /** One row to insert. `_id` may be pre-minted client-side so the optimistic row keys match the persisted one. */
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Collection } from '@tanstack/db';
2
- import { R as Row } from "./packem_shared/collection-options.d-BDL5mz7T.js";
3
- export { C as CHECKPOINT_FALLBACK_MS, type a as CheckpointFallbackEvent, type b as CheckpointRegistry, type c as CheckpointRegistryOptions, type d as CheckpointRegistryStats, type e as CheckpointWatermark, type E as ExecutorOutboxSinkOptions, type L as LunoraCollectionConfig, type f as LunoraCollectionOptions, O as OUTBOX_MUTATION_FN_NAME, type g as OutboxExecutor, type h as OutboxMutationMetadata, type S as SyncWriter, i as createCheckpointRegistry, j as createExecutorOutboxSink, k as createOptimisticOnlineDetector, l as getShardCheckpoints, m as lunoraCollectionOptions, n as makeDiffEmit, r as releaseShardCheckpoints, o as runOutboxMutation, t as toMap } from "./packem_shared/collection-options.d-BDL5mz7T.js";
4
- export { type C as CollectionDef, type D as DefineCollectionsOptions, type I as InsertBinding, type L as LunoraDb, type W as WriteRejectedEvent, d as defineCollections } from "./packem_shared/index.d-seIZK_RO.js";
5
- export { type B as BindMutatorsContext, type a as BoundMutatorApi, type b as BoundMutators, type C as ClientMutatorContext, type c as ClientMutatorDef, type d as CollectionMap, D as DIRECT_TRANSACTION_METADATA_KEY, type M as MutatorReference, type e as MutatorRejectedEvent, f as bindMutators, g as defineMutator, i as initMutators } from "./packem_shared/index.d-CbsFrP5r.js";
2
+ import { R as Row } from "./packem_shared/collection-options.d-BA8jp3ji.js";
3
+ export { C as CHECKPOINT_FALLBACK_MS, type a as CheckpointFallbackEvent, type b as CheckpointRegistry, type c as CheckpointRegistryOptions, type d as CheckpointRegistryStats, type e as CheckpointWatermark, type E as ExecutorOutboxSinkOptions, type L as LunoraCollectionConfig, type f as LunoraCollectionOptions, O as OUTBOX_MUTATION_FN_NAME, type g as OutboxExecutor, type h as OutboxMutationMetadata, type S as SyncWriter, i as createCheckpointRegistry, j as createExecutorOutboxSink, k as createOptimisticOnlineDetector, l as getShardCheckpoints, m as lunoraCollectionOptions, n as makeDiffEmit, r as releaseShardCheckpoints, o as runOutboxMutation, t as toMap } from "./packem_shared/collection-options.d-BA8jp3ji.js";
4
+ export { type C as CollectionDef, type D as DefineCollectionsOptions, type I as InsertBinding, type L as LunoraDb, type W as WriteRejectedEvent, d as defineCollections } from "./packem_shared/index.d-C3aBVnK7.js";
5
+ export { type B as BindMutatorsContext, type a as BoundMutatorApi, type b as BoundMutators, type C as ClientMutatorContext, type c as ClientMutatorDef, type d as CollectionMap, D as DIRECT_TRANSACTION_METADATA_KEY, type M as MutatorReference, type e as MutatorRejectedEvent, f as bindMutators, g as defineMutator, i as initMutators } from "./packem_shared/index.d-BZ00iQoq.js";
6
6
  import '@lunora/client';
7
7
  import '@tanstack/offline-transactions';
8
8
  /** One row to insert. `_id` may be pre-minted client-side so the optimistic row keys match the persisted one. */
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{applyPlanToCollections as r,applyPlanToDb as i}from"./packem_shared/applyPlanToCollections-C_eyqNF9.mjs";import{CHECKPOINT_FALLBACK_MS as a,createCheckpointRegistry as p,getShardCheckpoints as c,lunoraCollectionOptions as l,releaseShardCheckpoints as s}from"./packem_shared/CHECKPOINT_FALLBACK_MS-DAWfz0yD.mjs";import{defineCollections as O}from"./packem_shared/defineCollections-DLPLAvjt.mjs";import{DIRECT_TRANSACTION_METADATA_KEY as f,bindMutators as u,defineMutator as x,initMutators as A}from"./packem_shared/DIRECT_TRANSACTION_METADATA_KEY-C-CHKj3n.mjs";import{OUTBOX_MUTATION_FN_NAME as m,createExecutorOutboxSink as E,createOptimisticOnlineDetector as _,makeDiffEmit as N,runOutboxMutation as S,toMap as d}from"./packem_shared/OUTBOX_MUTATION_FN_NAME-BfFCughR.mjs";const t="0.0.0";export{a as CHECKPOINT_FALLBACK_MS,f as DIRECT_TRANSACTION_METADATA_KEY,m as OUTBOX_MUTATION_FN_NAME,t as VERSION,r as applyPlanToCollections,i as applyPlanToDb,u as bindMutators,p as createCheckpointRegistry,E as createExecutorOutboxSink,_ as createOptimisticOnlineDetector,O as defineCollections,x as defineMutator,c as getShardCheckpoints,A as initMutators,l as lunoraCollectionOptions,N as makeDiffEmit,s as releaseShardCheckpoints,S as runOutboxMutation,d as toMap};
1
+ import{applyPlanToCollections as r,applyPlanToDb as i}from"./packem_shared/applyPlanToCollections-C_eyqNF9.mjs";import{CHECKPOINT_FALLBACK_MS as a,createCheckpointRegistry as p,getShardCheckpoints as c,lunoraCollectionOptions as l,releaseShardCheckpoints as s}from"./packem_shared/CHECKPOINT_FALLBACK_MS-DAWfz0yD.mjs";import{defineCollections as O}from"./packem_shared/defineCollections-Czhhf-A8.mjs";import{DIRECT_TRANSACTION_METADATA_KEY as f,bindMutators as u,defineMutator as x,initMutators as A}from"./packem_shared/DIRECT_TRANSACTION_METADATA_KEY-C-CHKj3n.mjs";import{OUTBOX_MUTATION_FN_NAME as m,createExecutorOutboxSink as E,createOptimisticOnlineDetector as _,makeDiffEmit as N,runOutboxMutation as S,toMap as d}from"./packem_shared/OUTBOX_MUTATION_FN_NAME-BfFCughR.mjs";const t="0.0.0";export{a as CHECKPOINT_FALLBACK_MS,f as DIRECT_TRANSACTION_METADATA_KEY,m as OUTBOX_MUTATION_FN_NAME,t as VERSION,r as applyPlanToCollections,i as applyPlanToDb,u as bindMutators,p as createCheckpointRegistry,E as createExecutorOutboxSink,_ as createOptimisticOnlineDetector,O as defineCollections,x as defineMutator,c as getShardCheckpoints,A as initMutators,l as lunoraCollectionOptions,N as makeDiffEmit,s as releaseShardCheckpoints,S as runOutboxMutation,d as toMap};
@@ -1,5 +1,5 @@
1
- export { type B as BindMutatorsContext, type a as BoundMutatorApi, type b as BoundMutators, type C as ClientMutatorContext, type c as ClientMutatorDef, type d as CollectionMap, type e as MutatorRejectedEvent, f as bindMutators, g as defineMutator, i as initMutators } from "../packem_shared/index.d-xovzQ7rA.mjs";
1
+ export { type B as BindMutatorsContext, type a as BoundMutatorApi, type b as BoundMutators, type C as ClientMutatorContext, type c as ClientMutatorDef, type d as CollectionMap, type e as MutatorRejectedEvent, f as bindMutators, g as defineMutator, i as initMutators } from "../packem_shared/index.d-BCKTZhCD.mjs";
2
2
  import '@lunora/client';
3
3
  import '@tanstack/db';
4
- import "../packem_shared/collection-options.d-BDL5mz7T.mjs";
4
+ import "../packem_shared/collection-options.d-BA8jp3ji.mjs";
5
5
  import '@tanstack/offline-transactions';
@@ -1,5 +1,5 @@
1
- export { type B as BindMutatorsContext, type a as BoundMutatorApi, type b as BoundMutators, type C as ClientMutatorContext, type c as ClientMutatorDef, type d as CollectionMap, type e as MutatorRejectedEvent, f as bindMutators, g as defineMutator, i as initMutators } from "../packem_shared/index.d-CbsFrP5r.js";
1
+ export { type B as BindMutatorsContext, type a as BoundMutatorApi, type b as BoundMutators, type C as ClientMutatorContext, type c as ClientMutatorDef, type d as CollectionMap, type e as MutatorRejectedEvent, f as bindMutators, g as defineMutator, i as initMutators } from "../packem_shared/index.d-BZ00iQoq.js";
2
2
  import '@lunora/client';
3
3
  import '@tanstack/db';
4
- import "../packem_shared/collection-options.d-BDL5mz7T.js";
4
+ import "../packem_shared/collection-options.d-BA8jp3ji.js";
5
5
  import '@tanstack/offline-transactions';
@@ -9,17 +9,29 @@ import { OnlineDetector } from '@tanstack/offline-transactions';
9
9
  * collection inserts instead of the standalone {@link OutboxSink} fallback.
10
10
  */
11
11
  declare const OUTBOX_MUTATION_FN_NAME = "__lunora_outbox__";
12
+ /**
13
+ * Provenance stamped on a durable write at enqueue time: the two questions a
14
+ * replay cannot answer from the persisted row once the write outlives the
15
+ * session that made it — WHO queued it, and WHICH shard it belongs to.
16
+ *
17
+ * Shared so both replay paths (`db.actions.*` and the reserved
18
+ * `__lunora_outbox__` handler) check the same fields; they drifted apart once
19
+ * already, and only one of them had the identity guard.
20
+ */
21
+ interface WriteProvenance extends Record<string, unknown> {
22
+ /** Issuing identity fingerprint; a replay drops the write when it no longer matches. */
23
+ identity: string | null;
24
+ /** Captured, not re-read at replay: a queued write follows the shard it was made against even if the app reboots pointed at another. */
25
+ shardKey?: string;
26
+ }
12
27
  /** The metadata an outbox-routed transaction carries so its replay can call `client.mutation`. */
13
- interface OutboxMutationMetadata extends Record<string, unknown> {
28
+ interface OutboxMutationMetadata extends WriteProvenance {
14
29
  args: Record<string, unknown>;
15
30
  clientId: string;
16
31
  functionPath: string;
17
32
  /** Stable `${clientId}:${mutationId}` replay key; passed back as the mutation id so a committed-but-unacked replay is server-idempotent. */
18
33
  idempotencyKey: string;
19
- /** Issuing identity fingerprint; the replay handler drops the write when it no longer matches. */
20
- identity: string | null;
21
34
  mutationId: number;
22
- shardKey?: string;
23
35
  }
24
36
  /** A committable outbox transaction handle (the `OfflineTransaction` the executor mints). */
25
37
  interface OutboxTransaction {
@@ -9,17 +9,29 @@ import { OnlineDetector } from '@tanstack/offline-transactions';
9
9
  * collection inserts instead of the standalone {@link OutboxSink} fallback.
10
10
  */
11
11
  declare const OUTBOX_MUTATION_FN_NAME = "__lunora_outbox__";
12
+ /**
13
+ * Provenance stamped on a durable write at enqueue time: the two questions a
14
+ * replay cannot answer from the persisted row once the write outlives the
15
+ * session that made it — WHO queued it, and WHICH shard it belongs to.
16
+ *
17
+ * Shared so both replay paths (`db.actions.*` and the reserved
18
+ * `__lunora_outbox__` handler) check the same fields; they drifted apart once
19
+ * already, and only one of them had the identity guard.
20
+ */
21
+ interface WriteProvenance extends Record<string, unknown> {
22
+ /** Issuing identity fingerprint; a replay drops the write when it no longer matches. */
23
+ identity: string | null;
24
+ /** Captured, not re-read at replay: a queued write follows the shard it was made against even if the app reboots pointed at another. */
25
+ shardKey?: string;
26
+ }
12
27
  /** The metadata an outbox-routed transaction carries so its replay can call `client.mutation`. */
13
- interface OutboxMutationMetadata extends Record<string, unknown> {
28
+ interface OutboxMutationMetadata extends WriteProvenance {
14
29
  args: Record<string, unknown>;
15
30
  clientId: string;
16
31
  functionPath: string;
17
32
  /** Stable `${clientId}:${mutationId}` replay key; passed back as the mutation id so a committed-but-unacked replay is server-idempotent. */
18
33
  idempotencyKey: string;
19
- /** Issuing identity fingerprint; the replay handler drops the write when it no longer matches. */
20
- identity: string | null;
21
34
  mutationId: number;
22
- shardKey?: string;
23
35
  }
24
36
  /** A committable outbox transaction handle (the `OfflineTransaction` the executor mints). */
25
37
  interface OutboxTransaction {
@@ -0,0 +1 @@
1
+ import{lunoraCollectionOptions as T}from"./CHECKPOINT_FALLBACK_MS-DAWfz0yD.mjs";import{createCollection as M,safeRandomUUID as U}from"@tanstack/db";import{startOfflineExecutor as _,NonRetriableError as g}from"@tanstack/offline-transactions";import{createOutboxCarrier as B,createOptimisticOnlineDetector as R,OUTBOX_MUTATION_FN_NAME as K,registerOutboxCarrier as A,runOutboxMutation as I}from"./OUTBOX_MUTATION_FN_NAME-BfFCughR.mjs";const N=new WeakMap,D=(n,r)=>{let e=N.get(n);e===void 0&&(e=new Map,N.set(n,e));const a=e.get(r)??0;e.set(r,a+1),a===1&&console.warn(`[@lunora/db] table "${r}" is bound by more than one defineCollections call on this client. Each call creates its own live collection and outbox for the table, so the two can drift and derived indexes built from one can silently read stale rows. Bind every table in a single defineCollections call (see the "One source of truth per table" docs section).`)},p=(n,r)=>{try{n.onWriteRejected?.(r)}catch{}},v=(n,r)=>{const e=n.replayIdentityVerdict(r?.identity);if(e==="mismatch")throw new g("outbox write dropped: identity changed since it was queued");if(e==="unknown")throw new Error("outbox write deferred: no identity established yet")},k=(n,r,e={})=>{const a={},w={},m={},b=Object.entries(r);for(const[o,t]of b){const i=t.insert;D(n,o);const{config:d,scope:h}=T({client:n,getKey:t.getKey,id:o,list:t.list,...t.load===void 0?{}:{load:t.load},onError:t.onError,scopeBy:t.scopeBy,shardKey:t.shardKey});a[o]=M(d),t.scopeBy!==void 0&&(w[o]=h),i&&(m[o]=async({idempotencyKey:l,transaction:u})=>{const c=u.metadata;for(const[y,F]of u.mutations.entries()){const x=F.modified,E=`${l}:${String(y)}`;try{v(n,c),await I(()=>n.mutation(i.mutation,i.toArgs(x),{mutationId:E,shardKey:c.shardKey}))}catch(f){throw f instanceof g&&p(e,{code:f.code,collection:o,error:f,row:x}),f}}})}m[K]=async({transaction:o})=>{const t=o.metadata;if(t)try{v(n,t),await I(()=>n.mutation({__lunoraRef:t.functionPath},t.args,{mutationId:t.idempotencyKey,shardKey:t.shardKey}))}catch(i){throw i instanceof g&&p(e,{code:i.code,collection:t.functionPath,error:i}),i}};const O=B(),s=_({collections:{...a,[K]:O},mutationFns:m,onlineDetector:R(),...e.onLeadershipChange?{onLeadershipChange:e.onLeadershipChange}:{},...e.onStorageFailure?{onStorageFailure:e.onStorageFailure}:{},onUnknownMutationFn:(o,t)=>{p(e,{code:"UNKNOWN_MUTATION_FN",collection:o,error:new Error(`offline write dropped: mutation "${o}" no longer exists (removed or renamed in a deploy?)`),row:t.mutations[0]?.modified})}});A(s,O);const C={};for(const[o,t]of b){const i=t.insert,d=a[o];!i||!d||(C[o]=h=>{const l=U(),u={identity:n.currentIdentity(),shardKey:t.shardKey},c=s.createOfflineTransaction({autoCommit:!1,metadata:u,mutationFnName:o}),y=c.mutate(()=>{d.insert(i.optimistic(h,l))});return c.commit().catch(()=>{}),{id:l,transaction:y}})}return{actions:C,collections:a,executor:s,pendingCount:()=>s.getPendingCount(),scope:w}};export{k as defineCollections};
@@ -1,6 +1,6 @@
1
1
  import { LunoraClient } from '@lunora/client';
2
2
  import { Collection, Transaction } from '@tanstack/db';
3
- import { b as CheckpointRegistry } from "./collection-options.d-BDL5mz7T.mjs";
3
+ import { b as CheckpointRegistry } from "./collection-options.d-BA8jp3ji.mjs";
4
4
  /**
5
5
  * TanStack DB's "direct transaction" marker.
6
6
  *
@@ -1,6 +1,6 @@
1
1
  import { LunoraClient } from '@lunora/client';
2
2
  import { Collection, Transaction } from '@tanstack/db';
3
- import { b as CheckpointRegistry } from "./collection-options.d-BDL5mz7T.js";
3
+ import { b as CheckpointRegistry } from "./collection-options.d-BA8jp3ji.js";
4
4
  /**
5
5
  * TanStack DB's "direct transaction" marker.
6
6
  *
@@ -1,4 +1,4 @@
1
- import { R as Row } from "./collection-options.d-BDL5mz7T.mjs";
1
+ import { R as Row } from "./collection-options.d-BA8jp3ji.js";
2
2
  import { FunctionReference, SubscriptionError, LunoraClient } from '@lunora/client';
3
3
  import { Transaction, Collection } from '@tanstack/db';
4
4
  import { OfflineExecutor, StorageDiagnostic } from '@tanstack/offline-transactions';
@@ -52,7 +52,10 @@ interface CollectionDef<TList extends FunctionReference, TInput = never> {
52
52
  * Routes the `list` subscription (and the confirmed-mutation watermark its
53
53
  * frames advance the checkpoint gate from) to a specific shard's DO — so a
54
54
  * sharded collection's overlay gate compares against that shard's mutator
55
- * sequence line, not the default ("") watermark bucket.
55
+ * sequence line, not the default ("") watermark bucket. `insert` writes are
56
+ * routed with it too, and to the shard that was set when the write was
57
+ * queued: subscriptions and the writes they observe have to land on the same
58
+ * Durable Object, and the server derives no shard from a mutation's args.
56
59
  */
57
60
  shardKey?: string;
58
61
  }
@@ -1,4 +1,4 @@
1
- import { R as Row } from "./collection-options.d-BDL5mz7T.js";
1
+ import { R as Row } from "./collection-options.d-BA8jp3ji.mjs";
2
2
  import { FunctionReference, SubscriptionError, LunoraClient } from '@lunora/client';
3
3
  import { Transaction, Collection } from '@tanstack/db';
4
4
  import { OfflineExecutor, StorageDiagnostic } from '@tanstack/offline-transactions';
@@ -52,7 +52,10 @@ interface CollectionDef<TList extends FunctionReference, TInput = never> {
52
52
  * Routes the `list` subscription (and the confirmed-mutation watermark its
53
53
  * frames advance the checkpoint gate from) to a specific shard's DO — so a
54
54
  * sharded collection's overlay gate compares against that shard's mutator
55
- * sequence line, not the default ("") watermark bucket.
55
+ * sequence line, not the default ("") watermark bucket. `insert` writes are
56
+ * routed with it too, and to the shard that was set when the write was
57
+ * queued: subscriptions and the writes they observe have to land on the same
58
+ * Durable Object, and the server derives no shard from a mutation's args.
56
59
  */
57
60
  shardKey?: string;
58
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/db",
3
- "version": "1.0.0-alpha.77",
3
+ "version": "1.0.0-alpha.79",
4
4
  "description": "TanStack DB binding: typed, live-synced collections and a durable offline outbox over the Lunora client",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -54,8 +54,8 @@
54
54
  "access": "public"
55
55
  },
56
56
  "dependencies": {
57
- "@lunora/client": "1.0.0-alpha.73",
58
- "@lunora/errors": "1.0.0-alpha.30"
57
+ "@lunora/client": "1.0.0-alpha.75",
58
+ "@lunora/errors": "1.0.0-alpha.31"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@tanstack/db": "^0.6.0",
@@ -1 +0,0 @@
1
- import{lunoraCollectionOptions as M}from"./CHECKPOINT_FALLBACK_MS-DAWfz0yD.mjs";import{createCollection as v,safeRandomUUID as E}from"@tanstack/db";import{startOfflineExecutor as I,NonRetriableError as O}from"@tanstack/offline-transactions";import{createOutboxCarrier as T,createOptimisticOnlineDetector as U,OUTBOX_MUTATION_FN_NAME as C,registerOutboxCarrier as _,runOutboxMutation as x}from"./OUTBOX_MUTATION_FN_NAME-BfFCughR.mjs";const N=new WeakMap,B=(n,c)=>{let o=N.get(n);o===void 0&&(o=new Map,N.set(n,o));const i=o.get(c)??0;o.set(c,i+1),i===1&&console.warn(`[@lunora/db] table "${c}" is bound by more than one defineCollections call on this client. Each call creates its own live collection and outbox for the table, so the two can drift and derived indexes built from one can silently read stale rows. Bind every table in a single defineCollections call (see the "One source of truth per table" docs section).`)},D=(n,c,o={})=>{const i={},g={},f={},p=Object.entries(c);for(const[t,e]of p){const r=e.insert;B(n,t);const{config:l,scope:m}=M({client:n,getKey:e.getKey,id:t,list:e.list,...e.load===void 0?{}:{load:e.load},onError:e.onError,scopeBy:e.scopeBy,shardKey:e.shardKey});i[t]=v(l),e.scopeBy!==void 0&&(g[t]=m),r&&(f[t]=async({idempotencyKey:s,transaction:a})=>{for(const[h,F]of a.mutations.entries()){const w=F.modified,K=`${s}:${String(h)}`;try{await x(()=>n.mutation(r.mutation,r.toArgs(w),{mutationId:K}))}catch(u){if(u instanceof O&&o.onWriteRejected)try{o.onWriteRejected({code:u.code,collection:t,error:u,row:w})}catch{}throw u}}})}f[C]=async({transaction:t})=>{const e=t.metadata;if(e){if(e.identity!==n.currentIdentity())throw new O("outbox write dropped: identity changed since it was queued");await x(()=>n.mutation({__lunoraRef:e.functionPath},e.args,{mutationId:e.idempotencyKey,shardKey:e.shardKey}))}};const y=T(),d=I({collections:{...i,[C]:y},mutationFns:f,onlineDetector:U(),...o.onLeadershipChange?{onLeadershipChange:o.onLeadershipChange}:{},...o.onStorageFailure?{onStorageFailure:o.onStorageFailure}:{},onUnknownMutationFn:(t,e)=>{try{o.onWriteRejected?.({code:"UNKNOWN_MUTATION_FN",collection:t,error:new Error(`offline write dropped: mutation "${t}" no longer exists (removed or renamed in a deploy?)`),row:e.mutations[0]?.modified})}catch{}}});_(d,y);const b={};for(const[t,e]of p){const r=e.insert,l=i[t];if(!r||!l)continue;const m=d.createOfflineAction({mutationFnName:t,onMutate:({id:s,input:a})=>{l.insert(r.optimistic(a,s))}});b[t]=s=>{const a=E(),h=m({id:a,input:s});return{id:a,transaction:h}}}return{actions:b,collections:i,executor:d,pendingCount:()=>d.getPendingCount(),scope:g}};export{D as defineCollections};