@lunora/db 1.0.0-alpha.44 → 1.0.0-alpha.46

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.
Files changed (22) hide show
  1. package/dist/collections/index.d.mts +2 -2
  2. package/dist/collections/index.d.ts +2 -2
  3. package/dist/collections/index.mjs +1 -1
  4. package/dist/index.d.mts +4 -4
  5. package/dist/index.d.ts +4 -4
  6. package/dist/index.mjs +1 -1
  7. package/dist/mutators/index.d.mts +2 -2
  8. package/dist/mutators/index.d.ts +2 -2
  9. package/dist/mutators/index.mjs +1 -1
  10. package/dist/packem_shared/CHECKPOINT_FALLBACK_MS-Dxy7C_Up.mjs +1 -0
  11. package/dist/packem_shared/{DIRECT_TRANSACTION_METADATA_KEY-B9s9Zmty.mjs → DIRECT_TRANSACTION_METADATA_KEY-BxbJYIRz.mjs} +1 -1
  12. package/dist/packem_shared/applyPlanToCollections-CPB4eTOM.mjs +1 -0
  13. package/dist/packem_shared/{collection-options.d-B_2IXvdU.d.ts → collection-options.d-CmsXU1wV.d.mts} +11 -11
  14. package/dist/packem_shared/{collection-options.d-B_2IXvdU.d.mts → collection-options.d-CmsXU1wV.d.ts} +11 -11
  15. package/dist/packem_shared/{define-collections.d-Ciaqcod6.d.mts → define-collections.d-CTOC6vMT.d.mts} +1 -1
  16. package/dist/packem_shared/{define-collections.d-B7pL91T8.d.ts → define-collections.d-u87f9B-o.d.ts} +1 -1
  17. package/dist/packem_shared/{define-mutators.d-D51n_r1n.d.mts → define-mutators.d-C6MkAEpe.d.ts} +2 -2
  18. package/dist/packem_shared/{define-mutators.d-DuAmdkYR.d.ts → define-mutators.d-cBFz2vjk.d.mts} +2 -2
  19. package/dist/packem_shared/{defineCollections-BbmvoISF.mjs → defineCollections-qbfQ6xN1.mjs} +1 -1
  20. package/package.json +2 -2
  21. package/dist/packem_shared/CHECKPOINT_FALLBACK_MS-B0XZscWq.mjs +0 -1
  22. package/dist/packem_shared/applyPlanToCollections-C29s6OoX.mjs +0 -1
@@ -1,5 +1,5 @@
1
- export { type C as CheckpointRegistry, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, c as createCheckpointRegistry, l as lunoraCollectionOptions } from "../packem_shared/collection-options.d-B_2IXvdU.mjs";
2
- export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/define-collections.d-Ciaqcod6.mjs";
1
+ export { type C as CheckpointRegistry, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, c as createCheckpointRegistry, l as lunoraCollectionOptions } from "../packem_shared/collection-options.d-CmsXU1wV.mjs";
2
+ export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/define-collections.d-CTOC6vMT.mjs";
3
3
  import '@lunora/client';
4
4
  import '@tanstack/db';
5
5
  import '@tanstack/offline-transactions';
@@ -1,5 +1,5 @@
1
- export { type C as CheckpointRegistry, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, c as createCheckpointRegistry, l as lunoraCollectionOptions } from "../packem_shared/collection-options.d-B_2IXvdU.js";
2
- export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/define-collections.d-B7pL91T8.js";
1
+ export { type C as CheckpointRegistry, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, c as createCheckpointRegistry, l as lunoraCollectionOptions } from "../packem_shared/collection-options.d-CmsXU1wV.js";
2
+ export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/define-collections.d-u87f9B-o.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-B0XZscWq.mjs";import{defineCollections as n}from"../packem_shared/defineCollections-BbmvoISF.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-Dxy7C_Up.mjs";import{defineCollections as n}from"../packem_shared/defineCollections-qbfQ6xN1.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-B_2IXvdU.mjs";
3
- export { b as CHECKPOINT_FALLBACK_MS, type d as CheckpointFallbackEvent, type C as CheckpointRegistry, type e as CheckpointRegistryOptions, type f as CheckpointRegistryStats, type g as CheckpointWatermark, type E as ExecutorOutboxSinkOptions, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, O as OUTBOX_MUTATION_FN_NAME, type h as OutboxExecutor, type i as OutboxMutationMetadata, type S as SyncWriter, c as createCheckpointRegistry, j as createExecutorOutboxSink, k as createOptimisticOnlineDetector, m as getShardCheckpoints, l as lunoraCollectionOptions, n as makeDiffEmit, r as releaseShardCheckpoints, o as runOutboxMutation, s as shardCheckpointStats, t as toMap } from "./packem_shared/collection-options.d-B_2IXvdU.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/define-collections.d-Ciaqcod6.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 g as MutatorReference, type M as MutatorRejectedEvent, e as bindMutators, f as defineMutator, i as initMutators } from "./packem_shared/define-mutators.d-D51n_r1n.mjs";
2
+ import { R as Row } from "./packem_shared/collection-options.d-CmsXU1wV.mjs";
3
+ export { b as CHECKPOINT_FALLBACK_MS, type d as CheckpointFallbackEvent, type C as CheckpointRegistry, type e as CheckpointRegistryOptions, type f as CheckpointRegistryStats, type g as CheckpointWatermark, type E as ExecutorOutboxSinkOptions, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, O as OUTBOX_MUTATION_FN_NAME, type h as OutboxExecutor, type i as OutboxMutationMetadata, type S as SyncWriter, c as createCheckpointRegistry, j as createExecutorOutboxSink, k as createOptimisticOnlineDetector, m as getShardCheckpoints, l as lunoraCollectionOptions, n as makeDiffEmit, r as releaseShardCheckpoints, o as runOutboxMutation, s as shardCheckpointStats, t as toMap } from "./packem_shared/collection-options.d-CmsXU1wV.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/define-collections.d-CTOC6vMT.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 g as MutatorReference, type M as MutatorRejectedEvent, e as bindMutators, f as defineMutator, i as initMutators } from "./packem_shared/define-mutators.d-cBFz2vjk.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-B_2IXvdU.js";
3
- export { b as CHECKPOINT_FALLBACK_MS, type d as CheckpointFallbackEvent, type C as CheckpointRegistry, type e as CheckpointRegistryOptions, type f as CheckpointRegistryStats, type g as CheckpointWatermark, type E as ExecutorOutboxSinkOptions, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, O as OUTBOX_MUTATION_FN_NAME, type h as OutboxExecutor, type i as OutboxMutationMetadata, type S as SyncWriter, c as createCheckpointRegistry, j as createExecutorOutboxSink, k as createOptimisticOnlineDetector, m as getShardCheckpoints, l as lunoraCollectionOptions, n as makeDiffEmit, r as releaseShardCheckpoints, o as runOutboxMutation, s as shardCheckpointStats, t as toMap } from "./packem_shared/collection-options.d-B_2IXvdU.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/define-collections.d-B7pL91T8.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 g as MutatorReference, type M as MutatorRejectedEvent, e as bindMutators, f as defineMutator, i as initMutators } from "./packem_shared/define-mutators.d-DuAmdkYR.js";
2
+ import { R as Row } from "./packem_shared/collection-options.d-CmsXU1wV.js";
3
+ export { b as CHECKPOINT_FALLBACK_MS, type d as CheckpointFallbackEvent, type C as CheckpointRegistry, type e as CheckpointRegistryOptions, type f as CheckpointRegistryStats, type g as CheckpointWatermark, type E as ExecutorOutboxSinkOptions, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, O as OUTBOX_MUTATION_FN_NAME, type h as OutboxExecutor, type i as OutboxMutationMetadata, type S as SyncWriter, c as createCheckpointRegistry, j as createExecutorOutboxSink, k as createOptimisticOnlineDetector, m as getShardCheckpoints, l as lunoraCollectionOptions, n as makeDiffEmit, r as releaseShardCheckpoints, o as runOutboxMutation, s as shardCheckpointStats, t as toMap } from "./packem_shared/collection-options.d-CmsXU1wV.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/define-collections.d-u87f9B-o.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 g as MutatorReference, type M as MutatorRejectedEvent, e as bindMutators, f as defineMutator, i as initMutators } from "./packem_shared/define-mutators.d-C6MkAEpe.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-C29s6OoX.mjs";import{CHECKPOINT_FALLBACK_MS as a,createCheckpointRegistry as p,getShardCheckpoints as c,lunoraCollectionOptions as l,releaseShardCheckpoints as s,shardCheckpointStats as C}from"./packem_shared/CHECKPOINT_FALLBACK_MS-B0XZscWq.mjs";import{defineCollections as T}from"./packem_shared/defineCollections-BbmvoISF.mjs";import{DIRECT_TRANSACTION_METADATA_KEY as u,bindMutators as x,defineMutator as A,initMutators as M}from"./packem_shared/DIRECT_TRANSACTION_METADATA_KEY-B9s9Zmty.mjs";import{OUTBOX_MUTATION_FN_NAME as E,createExecutorOutboxSink as _,createOptimisticOnlineDetector as h,makeDiffEmit as N,runOutboxMutation as S,toMap as d}from"./packem_shared/OUTBOX_MUTATION_FN_NAME-BznV-kE1.mjs";const t="0.0.0";export{a as CHECKPOINT_FALLBACK_MS,u as DIRECT_TRANSACTION_METADATA_KEY,E as OUTBOX_MUTATION_FN_NAME,t as VERSION,r as applyPlanToCollections,i as applyPlanToDb,x as bindMutators,p as createCheckpointRegistry,_ as createExecutorOutboxSink,h as createOptimisticOnlineDetector,T as defineCollections,A as defineMutator,c as getShardCheckpoints,M as initMutators,l as lunoraCollectionOptions,N as makeDiffEmit,s as releaseShardCheckpoints,S as runOutboxMutation,C as shardCheckpointStats,d as toMap};
1
+ import{applyPlanToCollections as r,applyPlanToDb as i}from"./packem_shared/applyPlanToCollections-CPB4eTOM.mjs";import{CHECKPOINT_FALLBACK_MS as a,createCheckpointRegistry as p,getShardCheckpoints as c,lunoraCollectionOptions as l,releaseShardCheckpoints as s,shardCheckpointStats as C}from"./packem_shared/CHECKPOINT_FALLBACK_MS-Dxy7C_Up.mjs";import{defineCollections as T}from"./packem_shared/defineCollections-qbfQ6xN1.mjs";import{DIRECT_TRANSACTION_METADATA_KEY as u,bindMutators as x,defineMutator as A,initMutators as M}from"./packem_shared/DIRECT_TRANSACTION_METADATA_KEY-BxbJYIRz.mjs";import{OUTBOX_MUTATION_FN_NAME as E,createExecutorOutboxSink as _,createOptimisticOnlineDetector as h,makeDiffEmit as N,runOutboxMutation as S,toMap as d}from"./packem_shared/OUTBOX_MUTATION_FN_NAME-BznV-kE1.mjs";const t="0.0.0";export{a as CHECKPOINT_FALLBACK_MS,u as DIRECT_TRANSACTION_METADATA_KEY,E as OUTBOX_MUTATION_FN_NAME,t as VERSION,r as applyPlanToCollections,i as applyPlanToDb,x as bindMutators,p as createCheckpointRegistry,_ as createExecutorOutboxSink,h as createOptimisticOnlineDetector,T as defineCollections,A as defineMutator,c as getShardCheckpoints,M as initMutators,l as lunoraCollectionOptions,N as makeDiffEmit,s as releaseShardCheckpoints,S as runOutboxMutation,C as shardCheckpointStats,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 M as MutatorRejectedEvent, e as bindMutators, f as defineMutator, i as initMutators } from "../packem_shared/define-mutators.d-D51n_r1n.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 M as MutatorRejectedEvent, e as bindMutators, f as defineMutator, i as initMutators } from "../packem_shared/define-mutators.d-cBFz2vjk.mjs";
2
2
  import '@lunora/client';
3
3
  import '@tanstack/db';
4
- import "../packem_shared/collection-options.d-B_2IXvdU.mjs";
4
+ import "../packem_shared/collection-options.d-CmsXU1wV.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 M as MutatorRejectedEvent, e as bindMutators, f as defineMutator, i as initMutators } from "../packem_shared/define-mutators.d-DuAmdkYR.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 M as MutatorRejectedEvent, e as bindMutators, f as defineMutator, i as initMutators } from "../packem_shared/define-mutators.d-C6MkAEpe.js";
2
2
  import '@lunora/client';
3
3
  import '@tanstack/db';
4
- import "../packem_shared/collection-options.d-B_2IXvdU.js";
4
+ import "../packem_shared/collection-options.d-CmsXU1wV.js";
5
5
  import '@tanstack/offline-transactions';
@@ -1 +1 @@
1
- import{bindMutators as r,defineMutator as i,initMutators as a}from"../packem_shared/DIRECT_TRANSACTION_METADATA_KEY-B9s9Zmty.mjs";export{r as bindMutators,i as defineMutator,a as initMutators};
1
+ import{bindMutators as r,defineMutator as i,initMutators as a}from"../packem_shared/DIRECT_TRANSACTION_METADATA_KEY-BxbJYIRz.mjs";export{r as bindMutators,i as defineMutator,a as initMutators};
@@ -0,0 +1 @@
1
+ import{LunoraError as y}from"@lunora/errors";import{BTreeIndex as b}from"@tanstack/db";import{toMap as C,makeDiffEmit as T}from"./OUTBOX_MUTATION_FN_NAME-BznV-kE1.mjs";const I=()=>{let e=Number.NEGATIVE_INFINITY;const i=[];return{advance:o=>{if(!(o<=e)){e=o;for(let a=i.length-1;a>=0;a-=1){const n=i[a];n&&n.threshold<=e&&(n.resolve(),i.splice(a,1))}}},await:o=>o<=e?Promise.resolve():new Promise(a=>{i.push({resolve:a,threshold:o})}),passed:o=>o<=e,waiting:()=>i.length}};let g=!1;const M=e=>{g||(g=!0,console.warn(`[@lunora/db] released an optimistic overlay via the ${String(e.waitedMs)}ms checkpoint fallback: the server confirmed ${e.kind} ${String(e.watermark)} but no sync frame ever echoed it. A dropped shape poke or \`settled\` frame is the usual cause — inspect the subscription rather than raising \`fallbackMs\`. (Reported once per process.)`))},m=new WeakMap,w=new WeakSet,N=3e3,S=(e={})=>{const i=e.fallbackMs??N,o=e.onFallback??M,a=I(),n=I();let d=0;const c=new Set,l=(t,s)=>{for(const r of c)r.kind===t&&r.threshold<=s&&(clearTimeout(r.handle),c.delete(r))},p=(t,s)=>{if(i<=0)return;const r=t==="checkpoint"?a:n;if(r.passed(s))return;for(const k of c)if(k.kind===t&&k.threshold>=s)return;const u={handle:setTimeout(()=>{if(c.delete(u),!r.passed(s)){d+=1,r.advance(s);try{o({kind:t,waitedMs:i,watermark:s})}catch{}}},i),kind:t,threshold:s};c.add(u)};return{acknowledge:({checkpoint:t,mutationId:s})=>{t!==void 0&&p("checkpoint",t),s!==void 0&&p("mutationId",s)},awaitCheckpoint:t=>a.await(t),awaitMutationId:t=>n.await(t),dispose:()=>{for(const t of c)clearTimeout(t.handle);c.clear()},resolve:({checkpoint:t,mutationId:s})=>{t!==void 0&&(a.advance(t),l("checkpoint",t)),s!==void 0&&(n.advance(s),l("mutationId",s))},stats:()=>({fallbacks:d,pendingCheckpointWaiters:a.waiting(),pendingMutationWaiters:n.waiting()})}},E=(e,i,o)=>{let a=m.get(e);a||(a=new Map,m.set(e,a));const n=i??"",d=a.get(n);if(d)return d;const c=S(o);return a.set(n,c),c},K=e=>{w.add(e)},x=e=>w.has(e),F=e=>{const i=m.get(e);if(i){for(const o of i.values())o.resolve({checkpoint:Number.POSITIVE_INFINITY,mutationId:Number.POSITIVE_INFINITY}),o.dispose();m.delete(e)}},O=e=>{const i=m.get(e),o={};if(i)for(const[a,n]of i)o[a]=n.stats();return o},P=e=>{if(e.list===void 0==(e.shape===void 0))throw new y("INTERNAL","lunoraCollectionOptions: pass exactly one of `list` or `shape`");const i=e.getKey??(r=>r._id),o=e.checkpoints??E(e.client,e.shape?.shardKey??e.shardKey);K(o);const a=new Map;let n,d,c,l,p;const t=(r,u)=>{const k=h=>{n?.(C(h,i)),u?.(),e.shape===void 0&&(o.resolve({mutationId:p??e.client.confirmedMutationWatermark(e.shardKey)}),p=void 0)},f=h=>c?.(h),v=h=>{h.mutationId!==void 0&&(p=h.mutationId),o.resolve(h)};return e.shape!==void 0?e.client.subscribeShape({args:r,name:e.shape.name},k,{onCheckpoint:v,onError:f,shardKey:e.shape.shardKey}):e.client.subscribe(e.list,r,k,{onCheckpoint:v,onError:f,shardKey:e.shardKey})},s={autoIndex:"eager",defaultIndexType:b,getKey:i,id:e.id??e.list?.__lunoraRef??`shape:${e.shape?.name??""}`,...e.load==="eager"?{startSync:!0}:{},sync:{sync:r=>(n=T(a,r),c=u=>{r.markReady(),e.onError?.(u)},e.scopeBy===void 0?d=t(e.shape?.args??{},()=>{r.markReady()}):(r.markReady(),l!==void 0&&(d=t(l,void 0))),()=>{n=void 0,c=void 0,d?.(),d=void 0,a.clear()})}};return{checkpoints:o,config:s,scope:r=>{e.scopeBy!==void 0&&(l=r,d?.(),d=void 0,n?.(new Map),r!==void 0&&n!==void 0&&(d=t(r,void 0)))}}};export{N as CHECKPOINT_FALLBACK_MS,S as createCheckpointRegistry,E as getShardCheckpoints,x as hasCheckpointsAttached,P as lunoraCollectionOptions,K as markCheckpointsAttached,F as releaseShardCheckpoints,O as shardCheckpointStats};
@@ -1 +1 @@
1
- import{LunoraError as d}from"@lunora/errors";import{createTransaction as w}from"@tanstack/db";import{getShardCheckpoints as M,hasCheckpointsAttached as g}from"./CHECKPOINT_FALLBACK_MS-B0XZscWq.mjs";import{runOutboxMutation as _}from"./OUTBOX_MUTATION_FN_NAME-BznV-kE1.mjs";const v="__tanstack_db_direct",k="defineMutator: `serverRef` must be a generated mutator reference (api.mutators.*) or a 'namespace:fn' string",T=r=>{const t=typeof r=="string"?r:r?.__lunoraRef;if(typeof t!="string"||t.length===0)throw new d("INTERNAL",k);return t},A=r=>({__lunoraClientMutator:!0,apply:r.apply,serverRef:T(r.serverRef)}),E=(r,t,l)=>{let i=0;const h=()=>(i=Math.max(i,r.confirmedMutationWatermark(t.shardKey))+1,i);let u=Promise.resolve();const p=(o,a)=>{const s=u.then(async()=>{for(let c=0;;c+=1){const n=h();try{const{applied:e}=await r.callMutator(o,a,{clientSeq:n,shardKey:t.shardKey});if(e)return n}catch(e){throw i=r.confirmedMutationWatermark(t.shardKey),e}if(c>=32)throw new d("INTERNAL",`lunora: custom mutator "${o}" could not claim a fresh client sequence after ${String(32)} attempts`)}});return u=s.then(()=>{},()=>{}),s},y=()=>{if(t.checkpoints===!1)return;if(t.checkpoints)return t.checkpoints;const o=M(r,t.shardKey);return g(o)?o:void 0},R=(o,a,s,c)=>{const{onWriteRejected:n}=t;n&&o.isPersisted.promise.catch(e=>{const m=e instanceof Error?e:new Error(String(e));try{n({args:c,code:m.code,error:m,mutator:a,serverRef:s})}catch{}})},f={};for(const[o,a]of Object.entries(l))f[o]=s=>{const c=w({autoCommit:!0,metadata:{[v]:!0,serverRef:a.serverRef},mutationFn:async()=>{let n=0;await _(async()=>{n=await p(a.serverRef,s)});const e=y();e&&(e.acknowledge({mutationId:n}),await e.awaitMutationId(n))}});return c.mutate(()=>{a.apply({collections:t.collections},s)}),R(c,o,a.serverRef,s),c};return f},b=()=>({bindMutators:E,defineMutator:A});export{v as DIRECT_TRANSACTION_METADATA_KEY,E as bindMutators,A as defineMutator,b as initMutators};
1
+ import{LunoraError as d}from"@lunora/errors";import{createTransaction as w}from"@tanstack/db";import{getShardCheckpoints as M,hasCheckpointsAttached as g}from"./CHECKPOINT_FALLBACK_MS-Dxy7C_Up.mjs";import{runOutboxMutation as _}from"./OUTBOX_MUTATION_FN_NAME-BznV-kE1.mjs";const v="__tanstack_db_direct",k="defineMutator: `serverRef` must be a generated mutator reference (api.mutators.*) or a 'namespace:fn' string",T=r=>{const t=typeof r=="string"?r:r?.__lunoraRef;if(typeof t!="string"||t.length===0)throw new d("INTERNAL",k);return t},A=r=>({__lunoraClientMutator:!0,apply:r.apply,serverRef:T(r.serverRef)}),E=(r,t,l)=>{let i=0;const h=()=>(i=Math.max(i,r.confirmedMutationWatermark(t.shardKey))+1,i);let u=Promise.resolve();const p=(o,a)=>{const s=u.then(async()=>{for(let c=0;;c+=1){const n=h();try{const{applied:e}=await r.callMutator(o,a,{clientSeq:n,shardKey:t.shardKey});if(e)return n}catch(e){throw i=r.confirmedMutationWatermark(t.shardKey),e}if(c>=32)throw new d("INTERNAL",`lunora: custom mutator "${o}" could not claim a fresh client sequence after ${String(32)} attempts`)}});return u=s.then(()=>{},()=>{}),s},y=()=>{if(t.checkpoints===!1)return;if(t.checkpoints)return t.checkpoints;const o=M(r,t.shardKey);return g(o)?o:void 0},R=(o,a,s,c)=>{const{onWriteRejected:n}=t;n&&o.isPersisted.promise.catch(e=>{const m=e instanceof Error?e:new Error(String(e));try{n({args:c,code:m.code,error:m,mutator:a,serverRef:s})}catch{}})},f={};for(const[o,a]of Object.entries(l))f[o]=s=>{const c=w({autoCommit:!0,metadata:{[v]:!0,serverRef:a.serverRef},mutationFn:async()=>{let n=0;await _(async()=>{n=await p(a.serverRef,s)});const e=y();e&&(e.acknowledge({mutationId:n}),await e.awaitMutationId(n))}});return c.mutate(()=>{a.apply({collections:t.collections},s)}),R(c,o,a.serverRef,s),c};return f},b=()=>({bindMutators:E,defineMutator:A});export{v as DIRECT_TRANSACTION_METADATA_KEY,E as bindMutators,A as defineMutator,b as initMutators};
@@ -0,0 +1 @@
1
+ const n=(o,s)=>{for(const t of s.deletes??[])o[t.table]?.delete(t.id);for(const t of s.patches??[]){const e=o[t.table];e&&e.update(t.id,i=>{Object.assign(i,t.fields)})}for(const t of s.inserts??[]){const e=o[t.table];if(e){if(typeof t.row._id!="string")throw new TypeError(`applyPlanToCollections: insert into "${t.table}" needs an "_id" — mint it client-side so the optimistic row keys match the persisted one`);e.insert(t.row)}}},a=async(o,s)=>{for(const t of s.deletes??[])await o.delete(t.id);for(const t of s.patches??[])await o.patch(t.id,t.fields);for(const t of s.inserts??[]){const{_id:e,...i}=t.row;await o.insert(t.table,i,...typeof e=="string"?[{clientId:e}]:[])}};export{n as applyPlanToCollections,a as applyPlanToDb};
@@ -181,16 +181,16 @@ interface CheckpointRegistryOptions {
181
181
  *
182
182
  * Two inputs, deliberately distinct:
183
183
  *
184
- * - {@link resolve} is the **authoritative** advance, called by whoever owns the
185
- * watermark stream — a `data`/`delta` frame's `lastMutationId`, or a shape poke's
186
- * `checkpoint`. The synced rows have landed, so gates open immediately.
187
- * - {@link acknowledge} is the **provisional** advance, called when the server has
188
- * accepted the write (the mutator RPC ack) but the matching rows have not
189
- * necessarily been delivered yet. Releasing here would drop the overlay before
190
- * the synced row exists — a visible flicker — so instead it arms a bounded
191
- * fallback. If the authoritative frame lands first the fallback is cancelled;
192
- * if it never lands, the overlay is released after `fallbackMs` and the event is
193
- * reported rather than hanging forever.
184
+ * - {@link CheckpointRegistry.resolve} is the **authoritative** advance, called by whoever owns
185
+ * the watermark stream — a `data`/`delta` frame's `lastMutationId`, or a shape poke's
186
+ * `checkpoint`. The synced rows have landed, so gates open immediately.
187
+ * - {@link CheckpointRegistry.acknowledge} is the **provisional** advance, called when the server
188
+ * has accepted the write (the mutator RPC ack) but the matching rows have not
189
+ * necessarily been delivered yet. Releasing here would drop the overlay before
190
+ * the synced row exists — a visible flicker — so instead it arms a bounded
191
+ * fallback. If the authoritative frame lands first the fallback is cancelled;
192
+ * if it never lands, the overlay is released after `fallbackMs` and the event is
193
+ * reported rather than hanging forever.
194
194
  *
195
195
  * That pairing is why a lost poke degrades to a late overlay drop instead of a
196
196
  * permanently stuck `isPersisted` promise.
@@ -211,7 +211,7 @@ interface CheckpointRegistry {
211
211
  * the armed set. Idempotent. A discarded registry (Vite HMR dispose, sign-out)
212
212
  * can otherwise hold up to `fallbackMs` of pending `setTimeout`s alive through
213
213
  * their closures — keeping a Node/SSR event loop from draining. Distinct from
214
- * {@link resolve}: `resolve` settles parked *waiters* (and disarms the timers it
214
+ * {@link CheckpointRegistry.resolve}: `resolve` settles parked *waiters* (and disarms the timers it
215
215
  * subsumes as a side effect); `dispose` guarantees no armed timer survives,
216
216
  * independent of any watermark.
217
217
  */
@@ -181,16 +181,16 @@ interface CheckpointRegistryOptions {
181
181
  *
182
182
  * Two inputs, deliberately distinct:
183
183
  *
184
- * - {@link resolve} is the **authoritative** advance, called by whoever owns the
185
- * watermark stream — a `data`/`delta` frame's `lastMutationId`, or a shape poke's
186
- * `checkpoint`. The synced rows have landed, so gates open immediately.
187
- * - {@link acknowledge} is the **provisional** advance, called when the server has
188
- * accepted the write (the mutator RPC ack) but the matching rows have not
189
- * necessarily been delivered yet. Releasing here would drop the overlay before
190
- * the synced row exists — a visible flicker — so instead it arms a bounded
191
- * fallback. If the authoritative frame lands first the fallback is cancelled;
192
- * if it never lands, the overlay is released after `fallbackMs` and the event is
193
- * reported rather than hanging forever.
184
+ * - {@link CheckpointRegistry.resolve} is the **authoritative** advance, called by whoever owns
185
+ * the watermark stream — a `data`/`delta` frame's `lastMutationId`, or a shape poke's
186
+ * `checkpoint`. The synced rows have landed, so gates open immediately.
187
+ * - {@link CheckpointRegistry.acknowledge} is the **provisional** advance, called when the server
188
+ * has accepted the write (the mutator RPC ack) but the matching rows have not
189
+ * necessarily been delivered yet. Releasing here would drop the overlay before
190
+ * the synced row exists — a visible flicker — so instead it arms a bounded
191
+ * fallback. If the authoritative frame lands first the fallback is cancelled;
192
+ * if it never lands, the overlay is released after `fallbackMs` and the event is
193
+ * reported rather than hanging forever.
194
194
  *
195
195
  * That pairing is why a lost poke degrades to a late overlay drop instead of a
196
196
  * permanently stuck `isPersisted` promise.
@@ -211,7 +211,7 @@ interface CheckpointRegistry {
211
211
  * the armed set. Idempotent. A discarded registry (Vite HMR dispose, sign-out)
212
212
  * can otherwise hold up to `fallbackMs` of pending `setTimeout`s alive through
213
213
  * their closures — keeping a Node/SSR event loop from draining. Distinct from
214
- * {@link resolve}: `resolve` settles parked *waiters* (and disarms the timers it
214
+ * {@link CheckpointRegistry.resolve}: `resolve` settles parked *waiters* (and disarms the timers it
215
215
  * subsumes as a side effect); `dispose` guarantees no armed timer survives,
216
216
  * independent of any watermark.
217
217
  */
@@ -1,7 +1,7 @@
1
1
  import { FunctionReference, SubscriptionError, LunoraClient } from '@lunora/client';
2
2
  import { Transaction, Collection } from '@tanstack/db';
3
3
  import { OfflineExecutor, StorageDiagnostic } from '@tanstack/offline-transactions';
4
- import { R as Row } from "./collection-options.d-B_2IXvdU.mjs";
4
+ import { R as Row } from "./collection-options.d-CmsXU1wV.mjs";
5
5
  /** Element type of an array (the row type a `list` query returns). */
6
6
  type Element<T> = T extends ReadonlyArray<infer E> ? E : never;
7
7
  /** `true` for the `any` type, `false` otherwise. */
@@ -1,7 +1,7 @@
1
1
  import { FunctionReference, SubscriptionError, LunoraClient } from '@lunora/client';
2
2
  import { Transaction, Collection } from '@tanstack/db';
3
3
  import { OfflineExecutor, StorageDiagnostic } from '@tanstack/offline-transactions';
4
- import { R as Row } from "./collection-options.d-B_2IXvdU.js";
4
+ import { R as Row } from "./collection-options.d-CmsXU1wV.js";
5
5
  /** Element type of an array (the row type a `list` query returns). */
6
6
  type Element<T> = T extends ReadonlyArray<infer E> ? E : never;
7
7
  /** `true` for the `any` type, `false` otherwise. */
@@ -1,6 +1,6 @@
1
1
  import { LunoraClient } from '@lunora/client';
2
2
  import { Collection, Transaction } from '@tanstack/db';
3
- import { C as CheckpointRegistry } from "./collection-options.d-B_2IXvdU.mjs";
3
+ import { C as CheckpointRegistry } from "./collection-options.d-CmsXU1wV.js";
4
4
  /**
5
5
  * TanStack DB's "direct transaction" marker.
6
6
  *
@@ -133,7 +133,7 @@ interface BindMutatorsContext<TCollections extends CollectionMap = CollectionMap
133
133
  * `lastMutationId >= clientSeq` (via {@link CheckpointRegistry.resolve}), so the
134
134
  * row never flashes out and back.
135
135
  *
136
- * Defaults to the shared per-shard registry for `client` + {@link shardKey}
136
+ * Defaults to the shared per-shard registry for `client` + {@link BindMutatorsContext.shardKey}
137
137
  * ({@link getShardCheckpoints}) — the same one
138
138
  * {@link import("./collection-options").lunoraCollectionOptions} defaults to, so
139
139
  * a shard's collections and its mutators gate on one watermark line without the
@@ -1,6 +1,6 @@
1
1
  import { LunoraClient } from '@lunora/client';
2
2
  import { Collection, Transaction } from '@tanstack/db';
3
- import { C as CheckpointRegistry } from "./collection-options.d-B_2IXvdU.js";
3
+ import { C as CheckpointRegistry } from "./collection-options.d-CmsXU1wV.mjs";
4
4
  /**
5
5
  * TanStack DB's "direct transaction" marker.
6
6
  *
@@ -133,7 +133,7 @@ interface BindMutatorsContext<TCollections extends CollectionMap = CollectionMap
133
133
  * `lastMutationId >= clientSeq` (via {@link CheckpointRegistry.resolve}), so the
134
134
  * row never flashes out and back.
135
135
  *
136
- * Defaults to the shared per-shard registry for `client` + {@link shardKey}
136
+ * Defaults to the shared per-shard registry for `client` + {@link BindMutatorsContext.shardKey}
137
137
  * ({@link getShardCheckpoints}) — the same one
138
138
  * {@link import("./collection-options").lunoraCollectionOptions} defaults to, so
139
139
  * a shard's collections and its mutators gate on one watermark line without the
@@ -1 +1 @@
1
- import{createCollection as M,safeRandomUUID as v}from"@tanstack/db";import{startOfflineExecutor as E,NonRetriableError as O}from"@tanstack/offline-transactions";import{lunoraCollectionOptions as R}from"./CHECKPOINT_FALLBACK_MS-B0XZscWq.mjs";import{createOutboxCarrier as U,createOptimisticOnlineDetector as _,OUTBOX_MUTATION_FN_NAME as C,registerOutboxCarrier as A,runOutboxMutation as x}from"./OUTBOX_MUTATION_FN_NAME-BznV-kE1.mjs";const N=new WeakMap,I=(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={},y={},f={},h=Object.entries(c);for(const[t,e]of h){const r=e.insert;I(n,t);const{config:l,scope:m}=R({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]=M(l),e.scopeBy!==void 0&&(y[t]=m),r&&(f[t]=async({idempotencyKey:s,transaction:a})=>{for(const[p,K]of a.mutations.entries()){const b=K.modified,F=`${s}:${String(p)}`;try{await x(()=>n.mutation(r.mutation,r.toArgs(b),{mutationId:F}))}catch(u){if(u instanceof O&&o.onWriteRejected)try{o.onWriteRejected({code:u.code,collection:t,error:u,row:b})}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 g=U(),d=E({collections:{...i,[C]:g},mutationFns:f,onlineDetector:_(),...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{}}});A(d,g);const w={};for(const[t,e]of h){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))}});w[t]=s=>{const a=v(),p=m({id:a,input:s});return{id:a,transaction:p}}}return{actions:w,collections:i,executor:d,pendingCount:()=>d.getPendingCount(),scope:y}};export{D as defineCollections};
1
+ import{createCollection as M,safeRandomUUID as v}from"@tanstack/db";import{startOfflineExecutor as E,NonRetriableError as O}from"@tanstack/offline-transactions";import{lunoraCollectionOptions as R}from"./CHECKPOINT_FALLBACK_MS-Dxy7C_Up.mjs";import{createOutboxCarrier as U,createOptimisticOnlineDetector as _,OUTBOX_MUTATION_FN_NAME as C,registerOutboxCarrier as A,runOutboxMutation as x}from"./OUTBOX_MUTATION_FN_NAME-BznV-kE1.mjs";const N=new WeakMap,I=(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={},y={},f={},h=Object.entries(c);for(const[t,e]of h){const r=e.insert;I(n,t);const{config:l,scope:m}=R({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]=M(l),e.scopeBy!==void 0&&(y[t]=m),r&&(f[t]=async({idempotencyKey:s,transaction:a})=>{for(const[p,K]of a.mutations.entries()){const b=K.modified,F=`${s}:${String(p)}`;try{await x(()=>n.mutation(r.mutation,r.toArgs(b),{mutationId:F}))}catch(u){if(u instanceof O&&o.onWriteRejected)try{o.onWriteRejected({code:u.code,collection:t,error:u,row:b})}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 g=U(),d=E({collections:{...i,[C]:g},mutationFns:f,onlineDetector:_(),...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{}}});A(d,g);const w={};for(const[t,e]of h){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))}});w[t]=s=>{const a=v(),p=m({id:a,input:s});return{id:a,transaction:p}}}return{actions:w,collections:i,executor:d,pendingCount:()=>d.getPendingCount(),scope:y}};export{D as defineCollections};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/db",
3
- "version": "1.0.0-alpha.44",
3
+ "version": "1.0.0-alpha.46",
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,7 +54,7 @@
54
54
  "access": "public"
55
55
  },
56
56
  "dependencies": {
57
- "@lunora/client": "1.0.0-alpha.42",
57
+ "@lunora/client": "1.0.0-alpha.43",
58
58
  "@lunora/errors": "1.0.0-alpha.16"
59
59
  },
60
60
  "peerDependencies": {
@@ -1 +0,0 @@
1
- import{LunoraError as y}from"@lunora/errors";import{BTreeIndex as b}from"@tanstack/db";import{toMap as C,makeDiffEmit as T}from"./OUTBOX_MUTATION_FN_NAME-BznV-kE1.mjs";const I=()=>{let e=Number.NEGATIVE_INFINITY;const r=[];return{advance:o=>{if(!(o<=e)){e=o;for(let a=r.length-1;a>=0;a-=1){const i=r[a];i&&i.threshold<=e&&(i.resolve(),r.splice(a,1))}}},await:o=>o<=e?Promise.resolve():new Promise(a=>{r.push({resolve:a,threshold:o})}),passed:o=>o<=e,waiting:()=>r.length}},M=3e3;let g=!1;const N=e=>{g||(g=!0,console.warn(`[@lunora/db] released an optimistic overlay via the ${String(e.waitedMs)}ms checkpoint fallback: the server confirmed ${e.kind} ${String(e.watermark)} but no sync frame ever echoed it. A dropped shape poke or \`settled\` frame is the usual cause — inspect the subscription rather than raising \`fallbackMs\`. (Reported once per process.)`))},S=(e={})=>{const r=e.fallbackMs??M,o=e.onFallback??N,a=I(),i=I();let d=0;const c=new Set,l=(t,s)=>{for(const n of c)n.kind===t&&n.threshold<=s&&(clearTimeout(n.handle),c.delete(n))},p=(t,s)=>{if(r<=0)return;const n=t==="checkpoint"?a:i;if(n.passed(s))return;for(const k of c)if(k.kind===t&&k.threshold>=s)return;const u={handle:setTimeout(()=>{if(c.delete(u),!n.passed(s)){d+=1,n.advance(s);try{o({kind:t,waitedMs:r,watermark:s})}catch{}}},r),kind:t,threshold:s};c.add(u)};return{acknowledge:({checkpoint:t,mutationId:s})=>{t!==void 0&&p("checkpoint",t),s!==void 0&&p("mutationId",s)},awaitCheckpoint:t=>a.await(t),awaitMutationId:t=>i.await(t),dispose:()=>{for(const t of c)clearTimeout(t.handle);c.clear()},resolve:({checkpoint:t,mutationId:s})=>{t!==void 0&&(a.advance(t),l("checkpoint",t)),s!==void 0&&(i.advance(s),l("mutationId",s))},stats:()=>({fallbacks:d,pendingCheckpointWaiters:a.waiting(),pendingMutationWaiters:i.waiting()})}},m=new WeakMap,E=(e,r,o)=>{let a=m.get(e);a||(a=new Map,m.set(e,a));const i=r??"",d=a.get(i);if(d)return d;const c=S(o);return a.set(i,c),c},w=new WeakSet,K=e=>{w.add(e)},x=e=>w.has(e),F=e=>{const r=m.get(e);if(r){for(const o of r.values())o.resolve({checkpoint:Number.POSITIVE_INFINITY,mutationId:Number.POSITIVE_INFINITY}),o.dispose();m.delete(e)}},O=e=>{const r=m.get(e),o={};if(r)for(const[a,i]of r)o[a]=i.stats();return o},P=e=>{if(e.list===void 0==(e.shape===void 0))throw new y("INTERNAL","lunoraCollectionOptions: pass exactly one of `list` or `shape`");const r=e.getKey??(n=>n._id),o=e.checkpoints??E(e.client,e.shape?.shardKey??e.shardKey);K(o);const a=new Map;let i,d,c,l,p;const t=(n,u)=>{const k=h=>{i?.(C(h,r)),u?.(),e.shape===void 0&&(o.resolve({mutationId:p??e.client.confirmedMutationWatermark(e.shardKey)}),p=void 0)},f=h=>c?.(h),v=h=>{h.mutationId!==void 0&&(p=h.mutationId),o.resolve(h)};return e.shape!==void 0?e.client.subscribeShape({args:n,name:e.shape.name},k,{onCheckpoint:v,onError:f,shardKey:e.shape.shardKey}):e.client.subscribe(e.list,n,k,{onCheckpoint:v,onError:f,shardKey:e.shardKey})},s={autoIndex:"eager",defaultIndexType:b,getKey:r,id:e.id??e.list?.__lunoraRef??`shape:${e.shape?.name??""}`,...e.load==="eager"?{startSync:!0}:{},sync:{sync:n=>(i=T(a,n),c=u=>{n.markReady(),e.onError?.(u)},e.scopeBy===void 0?d=t(e.shape?.args??{},()=>{n.markReady()}):(n.markReady(),l!==void 0&&(d=t(l,void 0))),()=>{i=void 0,c=void 0,d?.(),d=void 0,a.clear()})}};return{checkpoints:o,config:s,scope:n=>{e.scopeBy!==void 0&&(l=n,d?.(),d=void 0,i?.(new Map),n!==void 0&&i!==void 0&&(d=t(n,void 0)))}}};export{M as CHECKPOINT_FALLBACK_MS,S as createCheckpointRegistry,E as getShardCheckpoints,x as hasCheckpointsAttached,P as lunoraCollectionOptions,K as markCheckpointsAttached,F as releaseShardCheckpoints,O as shardCheckpointStats};
@@ -1 +0,0 @@
1
- const l=t=>({deletes:t.deletes??[],inserts:t.inserts??[],patches:t.patches??[]}),r=(t,o)=>{const{deletes:n,inserts:i,patches:a}=l(o);for(const e of n)t[e.table]?.delete(e.id);for(const e of a){const s=t[e.table];s&&s.update(e.id,c=>{Object.assign(c,e.fields)})}for(const e of i){const s=t[e.table];if(s){if(typeof e.row._id!="string")throw new TypeError(`applyPlanToCollections: insert into "${e.table}" needs an "_id" — mint it client-side so the optimistic row keys match the persisted one`);s.insert(e.row)}}},d=async(t,o)=>{const{deletes:n,inserts:i,patches:a}=l(o);for(const e of n)await t.delete(e.id);for(const e of a)await t.patch(e.id,e.fields);for(const e of i){const{_id:s,...c}=e.row;await t.insert(e.table,c,...typeof s=="string"?[{clientId:s}]:[])}};export{r as applyPlanToCollections,d as applyPlanToDb};