@lunora/db 1.0.0-alpha.80 → 1.0.0-alpha.82
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/collections/index.d.mts +2 -2
- package/dist/collections/index.d.ts +2 -2
- package/dist/collections/index.mjs +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/mutators/index.d.mts +2 -2
- package/dist/mutators/index.d.ts +2 -2
- package/dist/mutators/index.mjs +1 -1
- package/dist/packem_shared/{CHECKPOINT_FALLBACK_MS-DAWfz0yD.mjs → CHECKPOINT_FALLBACK_MS-DVkxHO2j.mjs} +1 -1
- package/dist/packem_shared/{DIRECT_TRANSACTION_METADATA_KEY-C-CHKj3n.mjs → DIRECT_TRANSACTION_METADATA_KEY-O-hmqO42.mjs} +1 -1
- package/dist/packem_shared/{collection-options.d-BA8jp3ji.d.mts → collection-options.d-bmH3BTGq.d.mts} +12 -5
- package/dist/packem_shared/{collection-options.d-BA8jp3ji.d.ts → collection-options.d-bmH3BTGq.d.ts} +12 -5
- package/dist/packem_shared/{defineCollections-Czhhf-A8.mjs → defineCollections-Cz4-m1Mp.mjs} +1 -1
- package/dist/packem_shared/{index.d-Depww9_D.d.mts → index.d-BzXEOiP5.d.mts} +1 -1
- package/dist/packem_shared/{index.d-BZ00iQoq.d.ts → index.d-DQsjGcjP.d.ts} +1 -1
- package/dist/packem_shared/{index.d-C3aBVnK7.d.ts → index.d-DlfHbDas.d.ts} +1 -1
- package/dist/packem_shared/{index.d-BCKTZhCD.d.mts → index.d-DrpzHIoj.d.mts} +1 -1
- package/package.json +3 -3
|
@@ -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-
|
|
2
|
-
export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/index.d-
|
|
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-bmH3BTGq.mjs";
|
|
2
|
+
export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/index.d-BzXEOiP5.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-
|
|
2
|
-
export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/index.d-
|
|
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-bmH3BTGq.js";
|
|
2
|
+
export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/index.d-DlfHbDas.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-
|
|
1
|
+
import{createCheckpointRegistry as t,lunoraCollectionOptions as r}from"../packem_shared/CHECKPOINT_FALLBACK_MS-DVkxHO2j.mjs";import{defineCollections as n}from"../packem_shared/defineCollections-Cz4-m1Mp.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-
|
|
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-
|
|
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-
|
|
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-
|
|
2
|
+
import { R as Row } from "./packem_shared/collection-options.d-bmH3BTGq.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-bmH3BTGq.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-BzXEOiP5.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-DrpzHIoj.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-
|
|
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-
|
|
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-
|
|
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-
|
|
2
|
+
import { R as Row } from "./packem_shared/collection-options.d-bmH3BTGq.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-bmH3BTGq.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-DlfHbDas.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-DQsjGcjP.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-
|
|
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-DVkxHO2j.mjs";import{defineCollections as O}from"./packem_shared/defineCollections-Cz4-m1Mp.mjs";import{DIRECT_TRANSACTION_METADATA_KEY as f,bindMutators as u,defineMutator as x,initMutators as A}from"./packem_shared/DIRECT_TRANSACTION_METADATA_KEY-O-hmqO42.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-
|
|
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-DrpzHIoj.mjs";
|
|
2
2
|
import '@lunora/client';
|
|
3
3
|
import '@tanstack/db';
|
|
4
|
-
import "../packem_shared/collection-options.d-
|
|
4
|
+
import "../packem_shared/collection-options.d-bmH3BTGq.mjs";
|
|
5
5
|
import '@tanstack/offline-transactions';
|
package/dist/mutators/index.d.ts
CHANGED
|
@@ -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-
|
|
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-DQsjGcjP.js";
|
|
2
2
|
import '@lunora/client';
|
|
3
3
|
import '@tanstack/db';
|
|
4
|
-
import "../packem_shared/collection-options.d-
|
|
4
|
+
import "../packem_shared/collection-options.d-bmH3BTGq.js";
|
|
5
5
|
import '@tanstack/offline-transactions';
|
package/dist/mutators/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{bindMutators as r,defineMutator as i,initMutators as a}from"../packem_shared/DIRECT_TRANSACTION_METADATA_KEY-
|
|
1
|
+
import{bindMutators as r,defineMutator as i,initMutators as a}from"../packem_shared/DIRECT_TRANSACTION_METADATA_KEY-O-hmqO42.mjs";export{r as bindMutators,i as defineMutator,a as initMutators};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as M}from"@lunora/errors";import{BTreeIndex as T}from"@tanstack/db";import{toMap as E,makeDiffEmit as S}from"./OUTBOX_MUTATION_FN_NAME-BfFCughR.mjs";const I=()=>{let e=Number.NEGATIVE_INFINITY;const a=[];return{advance:r=>{if(!(r<=e)){e=r;for(let n=a.length-1;n>=0;n-=1){const c=a[n];c&&c.threshold<=e&&(c.resolve(),a.splice(n,1))}}},await:r=>r<=e?Promise.resolve():new Promise(n=>{a.push({resolve:n,threshold:r})}),passed:r=>r<=e,reset:()=>{for(const r of a.splice(0))r.resolve();e=Number.NEGATIVE_INFINITY},waiting:()=>a.length}};let
|
|
1
|
+
import{LunoraError as M}from"@lunora/errors";import{BTreeIndex as T}from"@tanstack/db";import{toMap as E,makeDiffEmit as S}from"./OUTBOX_MUTATION_FN_NAME-BfFCughR.mjs";const I=()=>{let e=Number.NEGATIVE_INFINITY;const a=[];return{advance:r=>{if(!(r<=e)){e=r;for(let n=a.length-1;n>=0;n-=1){const c=a[n];c&&c.threshold<=e&&(c.resolve(),a.splice(n,1))}}},await:r=>r<=e?Promise.resolve():new Promise(n=>{a.push({resolve:n,threshold:r})}),passed:r=>r<=e,reset:()=>{for(const r of a.splice(0))r.resolve();e=Number.NEGATIVE_INFINITY},waiting:()=>a.length}};let w=!1;const F=e=>{w||(w=!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.)`))},y=new WeakMap,b=new WeakMap,C=new WeakSet,N=new WeakMap,K=3e3,R=(e={})=>{const a=e.fallbackMs??K,r=e.onFallback??F,n=I(),c=I();let d=0;const o=new Set,h=(t,i)=>{for(const l of o)l.kind===t&&l.threshold<=i&&(clearTimeout(l.handle),o.delete(l))},p=(t,i)=>{if(a<=0)return;const l=t==="checkpoint"?n:c;if(l.passed(i))return;for(const m of o)if(m.kind===t&&m.threshold>=i)return;const s={handle:setTimeout(()=>{if(o.delete(s),!l.passed(i)){d+=1,l.advance(i);try{r({kind:t,waitedMs:a,watermark:i})}catch{}}},a),kind:t,threshold:i};o.add(s)},u={acknowledge:({checkpoint:t,mutationId:i})=>{t!==void 0&&p("checkpoint",t),i!==void 0&&p("mutationId",i)},awaitCheckpoint:t=>n.await(t),awaitMutationId:t=>c.await(t),dispose:()=>{for(const t of o)clearTimeout(t.handle);o.clear()},resolve:({checkpoint:t,mutationId:i})=>{t!==void 0&&(n.advance(t),h("checkpoint",t)),i!==void 0&&(c.advance(i),h("mutationId",i))},stats:()=>({fallbacks:d,pendingCheckpointWaiters:n.waiting(),pendingMutationWaiters:c.waiting()})};return N.set(u,()=>{u.dispose(),n.reset(),c.reset()}),u},G=e=>{const a=y.get(e);if(a){for(const r of a.values())r.resolve({checkpoint:Number.POSITIVE_INFINITY,mutationId:Number.POSITIVE_INFINITY}),r.dispose();y.delete(e)}},A=e=>{const a=e.currentIdentity();if(y.has(e)&&b.get(e)!==a)for(const r of y.get(e)?.values()??[])N.get(r)?.();b.set(e,a)},_=(e,a,r)=>{A(e);let n=y.get(e);n||(n=new Map,y.set(e,n));const c=a??"",d=n.get(c);if(d)return d;const o=R(r);return n.set(c,o),o},W=e=>{C.add(e)},P=e=>C.has(e),L=e=>{if(e.list===void 0==(e.shape===void 0))throw new M("INTERNAL","lunoraCollectionOptions: pass exactly one of `list` or `shape`");const a=e.getKey??(s=>s._id),r=()=>{const s=e.checkpoints??_(e.client,e.shape?.shardKey??e.shardKey);return W(s),s},n=r(),c=new Map;let d,o,h,p,u;const t=(s,m)=>{const k=f=>{d?.(E(f,a)),m?.(),e.shape===void 0&&(r().resolve({mutationId:u??e.client.confirmedMutationWatermark(e.shardKey)}),u=void 0)},v=f=>h?.(f),g=f=>{f.rowsFollow===!0&&f.mutationId!==void 0&&(u=f.mutationId),r().resolve(f)};return e.shape!==void 0?e.client.subscribeShape({args:s,name:e.shape.name},k,{onCheckpoint:g,onError:v,shardKey:e.shape.shardKey}):e.client.subscribe(e.list,s,k,{onCheckpoint:g,onError:v,shardKey:e.shardKey})},i={autoIndex:"eager",defaultIndexType:T,getKey:a,id:e.id??e.list?.__lunoraRef??`shape:${e.shape?.name??""}`,...e.load==="eager"?{startSync:!0}:{},sync:{sync:s=>(d=S(c,s),h=k=>{s.markReady(),e.onError?.(k)},e.scopeBy===void 0?o=t(e.shape?.args??{},()=>{s.markReady()}):(s.markReady(),p!==void 0&&(o=t(p,void 0))),()=>{d=void 0,h=void 0,o?.(),o=void 0,c.clear()})}};return{checkpoints:n,config:i,scope:s=>{e.scopeBy!==void 0&&(p=s,o?.(),o=void 0,d?.(new Map),s!==void 0&&d!==void 0&&(o=t(s,void 0)))}}};export{K as CHECKPOINT_FALLBACK_MS,R as createCheckpointRegistry,_ as getShardCheckpoints,P as hasCheckpointsAttached,L as lunoraCollectionOptions,W as markCheckpointsAttached,G as releaseShardCheckpoints,A as syncShardCheckpointIdentity};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as f}from"@lunora/errors";import{createTransaction as k}from"@tanstack/db";import{getShardCheckpoints as v,hasCheckpointsAttached as w,syncShardCheckpointIdentity as C}from"./CHECKPOINT_FALLBACK_MS-
|
|
1
|
+
import{LunoraError as f}from"@lunora/errors";import{createTransaction as k}from"@tanstack/db";import{getShardCheckpoints as v,hasCheckpointsAttached as w,syncShardCheckpointIdentity as C}from"./CHECKPOINT_FALLBACK_MS-DVkxHO2j.mjs";import{runOutboxMutation as I}from"./OUTBOX_MUTATION_FN_NAME-BfFCughR.mjs";const E="__tanstack_db_direct",T="defineMutator: `serverRef` must be a generated mutator reference (api.mutators.*) or a 'namespace:fn' string",A=t=>{const e=typeof t=="string"?t:t?.__lunoraRef;if(typeof e!="string"||e.length===0)throw new f("INTERNAL",T);return e},S=t=>({__lunoraClientMutator:!0,apply:t.apply,serverRef:A(t.serverRef)}),g=(t,e,l)=>{let c=0,u=t.currentIdentity();const d=()=>{C(t);const r=t.currentIdentity();r!==u&&(c=0,u=r)},y=()=>(d(),c=Math.max(c,t.confirmedMutationWatermark(e.shardKey))+1,c);let m=Promise.resolve();const R=(r,a)=>{const s=m.then(async()=>{for(let i=0;;i+=1){const n=y();try{const{applied:o}=await t.callMutator(r,a,{clientSeq:n,shardKey:e.shardKey});if(o)return n}catch(o){throw d(),c=t.confirmedMutationWatermark(e.shardKey),o}if(i>=32)throw new f("INTERNAL",`lunora: custom mutator "${r}" could not claim a fresh client sequence after ${String(32)} attempts`)}});return m=s.then(()=>{},()=>{}),s},M=()=>{if(e.checkpoints===!1)return;if(e.checkpoints)return e.checkpoints;const r=v(t,e.shardKey);return w(r)?r:void 0},_=(r,a,s,i)=>{const{onWriteRejected:n}=e;n&&r.isPersisted.promise.catch(o=>{const h=o instanceof Error?o:new Error(String(o));try{n({args:i,code:h.code,error:h,mutator:a,serverRef:s})}catch{}})},p={};for(const[r,a]of Object.entries(l))p[r]=s=>{const i=k({autoCommit:!0,metadata:{[E]:!0,serverRef:a.serverRef},mutationFn:async()=>{let n=0;await I(async()=>{n=await R(a.serverRef,s)});const o=M();o&&(o.acknowledge({mutationId:n}),await o.awaitMutationId(n))}});return i.mutate(()=>{a.apply({collections:e.collections},s)}),_(i,r,a.serverRef,s),i};return p},q=()=>({bindMutators:g,defineMutator:S});export{E as DIRECT_TRANSACTION_METADATA_KEY,g as bindMutators,S as defineMutator,q as initMutators};
|
|
@@ -108,11 +108,18 @@ declare const toMap: <T extends object>(rows: ReadonlyArray<T>, getKey: (row: T)
|
|
|
108
108
|
* is kept. Each incoming value is serialized exactly once per tick (for both
|
|
109
109
|
* comparison and cache update), so the previous value is never re-serialized.
|
|
110
110
|
*
|
|
111
|
-
* Lifecycle: `syncedJson`
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
111
|
+
* Lifecycle: `syncedJson` is owned by the caller at the same scope as any other
|
|
112
|
+
* per-collection state (outside the `sync.sync` callback), so one map serves
|
|
113
|
+
* every `makeDiffEmit` closure the collection creates and a *within-session*
|
|
114
|
+
* re-delivery of an unchanged snapshot writes nothing.
|
|
115
|
+
*
|
|
116
|
+
* It does NOT survive a sync **restart**, and must not: TanStack drops its
|
|
117
|
+
* synced store on gc cleanup, so the sole caller
|
|
118
|
+
* ({@link file://./collection-options.ts}'s `sync.sync` teardown) clears the map
|
|
119
|
+
* on the way out. A restart that kept the map would diff the server's
|
|
120
|
+
* re-delivered snapshot against rows the store no longer holds, emit zero
|
|
121
|
+
* writes, and leave the restarted collection permanently empty. The map's job is
|
|
122
|
+
* incremental-diff state for one live session, not a durable cache.
|
|
116
123
|
*/
|
|
117
124
|
declare const makeDiffEmit: <T extends object>(syncedJson: Map<string, string>, writer: SyncWriter<T>) => (next: Map<string, T>) => void;
|
|
118
125
|
/**
|
package/dist/packem_shared/{collection-options.d-BA8jp3ji.d.ts → collection-options.d-bmH3BTGq.d.ts}
RENAMED
|
@@ -108,11 +108,18 @@ declare const toMap: <T extends object>(rows: ReadonlyArray<T>, getKey: (row: T)
|
|
|
108
108
|
* is kept. Each incoming value is serialized exactly once per tick (for both
|
|
109
109
|
* comparison and cache update), so the previous value is never re-serialized.
|
|
110
110
|
*
|
|
111
|
-
* Lifecycle: `syncedJson`
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
111
|
+
* Lifecycle: `syncedJson` is owned by the caller at the same scope as any other
|
|
112
|
+
* per-collection state (outside the `sync.sync` callback), so one map serves
|
|
113
|
+
* every `makeDiffEmit` closure the collection creates and a *within-session*
|
|
114
|
+
* re-delivery of an unchanged snapshot writes nothing.
|
|
115
|
+
*
|
|
116
|
+
* It does NOT survive a sync **restart**, and must not: TanStack drops its
|
|
117
|
+
* synced store on gc cleanup, so the sole caller
|
|
118
|
+
* ({@link file://./collection-options.ts}'s `sync.sync` teardown) clears the map
|
|
119
|
+
* on the way out. A restart that kept the map would diff the server's
|
|
120
|
+
* re-delivered snapshot against rows the store no longer holds, emit zero
|
|
121
|
+
* writes, and leave the restarted collection permanently empty. The map's job is
|
|
122
|
+
* incremental-diff state for one live session, not a durable cache.
|
|
116
123
|
*/
|
|
117
124
|
declare const makeDiffEmit: <T extends object>(syncedJson: Map<string, string>, writer: SyncWriter<T>) => (next: Map<string, T>) => void;
|
|
118
125
|
/**
|
package/dist/packem_shared/{defineCollections-Czhhf-A8.mjs → defineCollections-Cz4-m1Mp.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{lunoraCollectionOptions as T}from"./CHECKPOINT_FALLBACK_MS-
|
|
1
|
+
import{lunoraCollectionOptions as T}from"./CHECKPOINT_FALLBACK_MS-DVkxHO2j.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,4 +1,4 @@
|
|
|
1
|
-
import { R as Row } from "./collection-options.d-
|
|
1
|
+
import { R as Row } from "./collection-options.d-bmH3BTGq.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';
|
|
@@ -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-
|
|
3
|
+
import { b as CheckpointRegistry } from "./collection-options.d-bmH3BTGq.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-
|
|
1
|
+
import { R as Row } from "./collection-options.d-bmH3BTGq.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';
|
|
@@ -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-
|
|
3
|
+
import { b as CheckpointRegistry } from "./collection-options.d-bmH3BTGq.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* TanStack DB's "direct transaction" marker.
|
|
6
6
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/db",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.82",
|
|
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.
|
|
58
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
57
|
+
"@lunora/client": "1.0.0-alpha.79",
|
|
58
|
+
"@lunora/errors": "1.0.0-alpha.32"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@tanstack/db": "^0.6.0",
|