@lunora/db 1.0.0-alpha.70 → 1.0.0-alpha.71
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 +1 -0
- package/dist/packem_shared/{DIRECT_TRANSACTION_METADATA_KEY-D2l1cFzz.mjs → DIRECT_TRANSACTION_METADATA_KEY-C-CHKj3n.mjs} +1 -1
- package/dist/packem_shared/{collection-options.d-DWNFnQ70.d.mts → collection-options.d-BDL5mz7T.d.mts} +1 -3
- package/dist/packem_shared/{collection-options.d-DWNFnQ70.d.ts → collection-options.d-BDL5mz7T.d.ts} +1 -3
- package/dist/packem_shared/{defineCollections-DBxlxj4t.mjs → defineCollections-DLPLAvjt.mjs} +1 -1
- package/dist/packem_shared/{index.d-C4dXRxV5.d.ts → index.d-CbsFrP5r.d.ts} +1 -1
- package/dist/packem_shared/{index.d-DreeESSV.d.mts → index.d-DJ2mA1Ci.d.mts} +1 -1
- package/dist/packem_shared/{index.d-5tpy1rI6.d.ts → index.d-seIZK_RO.d.ts} +1 -1
- package/dist/packem_shared/{index.d-DgB3nvmL.d.mts → index.d-xovzQ7rA.d.mts} +1 -1
- package/package.json +2 -2
- package/dist/packem_shared/CHECKPOINT_FALLBACK_MS-DEhlJ5je.mjs +0 -1
|
@@ -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-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";
|
|
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-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";
|
|
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-DAWfz0yD.mjs";import{defineCollections as n}from"../packem_shared/defineCollections-DLPLAvjt.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,
|
|
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-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";
|
|
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,
|
|
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-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";
|
|
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
|
|
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,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-xovzQ7rA.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-BDL5mz7T.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-CbsFrP5r.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-BDL5mz7T.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-C-CHKj3n.mjs";export{r as bindMutators,i as defineMutator,a as initMutators};
|
|
@@ -0,0 +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 b=!1;const K=e=>{b||(b=!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,w=new WeakMap,C=new WeakSet,N=new WeakMap,F=3e3,R=(e={})=>{const a=e.fallbackMs??F,r=e.onFallback??K,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)},f={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(f,()=>{f.dispose(),n.reset(),c.reset()}),f},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)&&w.get(e)!==a)for(const r of y.get(e)?.values()??[])N.get(r)?.();w.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,f;const t=(s,m)=>{const k=u=>{d?.(E(u,a)),m?.(),e.shape===void 0&&(r().resolve({mutationId:f??e.client.confirmedMutationWatermark(e.shardKey)}),f=void 0)},v=u=>h?.(u),g=u=>{u.mutationId!==void 0&&(f=u.mutationId),r().resolve(u)};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{F 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-DAWfz0yD.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};
|
|
@@ -264,8 +264,6 @@ declare const releaseShardCheckpoints: (client: LunoraClient) => void;
|
|
|
264
264
|
* `lunoraCollectionOptions` and `bindMutators` call for that shard.
|
|
265
265
|
*/
|
|
266
266
|
declare const getShardCheckpoints: (client: LunoraClient, shardKey?: string, options?: CheckpointRegistryOptions) => CheckpointRegistry;
|
|
267
|
-
/** Every live registry for `client`, keyed by shard (`""` = unsharded) — for a debug surface. */
|
|
268
|
-
declare const shardCheckpointStats: (client: LunoraClient) => Record<string, CheckpointRegistryStats>;
|
|
269
267
|
/**
|
|
270
268
|
* A replication-shape sync source (the local-first partial-replication path).
|
|
271
269
|
* Mutually exclusive with {@link LunoraCollectionConfig.list}: the collection
|
|
@@ -344,4 +342,4 @@ interface LunoraCollectionOptions<TRow extends Row> {
|
|
|
344
342
|
* overlays against confirmed server watermarks (see {@link CheckpointRegistry}).
|
|
345
343
|
*/
|
|
346
344
|
declare const lunoraCollectionOptions: <TRow extends Row>(options: LunoraCollectionConfig<TRow>) => LunoraCollectionOptions<TRow>;
|
|
347
|
-
export { CHECKPOINT_FALLBACK_MS as C, ExecutorOutboxSinkOptions as E, LunoraCollectionConfig as L, OUTBOX_MUTATION_FN_NAME as O, Row as R, SyncWriter as S, CheckpointFallbackEvent as a, CheckpointRegistry as b, CheckpointRegistryOptions as c, CheckpointRegistryStats as d, CheckpointWatermark as e, LunoraCollectionOptions as f, OutboxExecutor as g, OutboxMutationMetadata as h, createCheckpointRegistry as i, createExecutorOutboxSink as j, createOptimisticOnlineDetector as k, getShardCheckpoints as l, lunoraCollectionOptions as m, makeDiffEmit as n, runOutboxMutation as o, releaseShardCheckpoints as r,
|
|
345
|
+
export { CHECKPOINT_FALLBACK_MS as C, ExecutorOutboxSinkOptions as E, LunoraCollectionConfig as L, OUTBOX_MUTATION_FN_NAME as O, Row as R, SyncWriter as S, CheckpointFallbackEvent as a, CheckpointRegistry as b, CheckpointRegistryOptions as c, CheckpointRegistryStats as d, CheckpointWatermark as e, LunoraCollectionOptions as f, OutboxExecutor as g, OutboxMutationMetadata as h, createCheckpointRegistry as i, createExecutorOutboxSink as j, createOptimisticOnlineDetector as k, getShardCheckpoints as l, lunoraCollectionOptions as m, makeDiffEmit as n, runOutboxMutation as o, releaseShardCheckpoints as r, toMap as t };
|
package/dist/packem_shared/{collection-options.d-DWNFnQ70.d.ts → collection-options.d-BDL5mz7T.d.ts}
RENAMED
|
@@ -264,8 +264,6 @@ declare const releaseShardCheckpoints: (client: LunoraClient) => void;
|
|
|
264
264
|
* `lunoraCollectionOptions` and `bindMutators` call for that shard.
|
|
265
265
|
*/
|
|
266
266
|
declare const getShardCheckpoints: (client: LunoraClient, shardKey?: string, options?: CheckpointRegistryOptions) => CheckpointRegistry;
|
|
267
|
-
/** Every live registry for `client`, keyed by shard (`""` = unsharded) — for a debug surface. */
|
|
268
|
-
declare const shardCheckpointStats: (client: LunoraClient) => Record<string, CheckpointRegistryStats>;
|
|
269
267
|
/**
|
|
270
268
|
* A replication-shape sync source (the local-first partial-replication path).
|
|
271
269
|
* Mutually exclusive with {@link LunoraCollectionConfig.list}: the collection
|
|
@@ -344,4 +342,4 @@ interface LunoraCollectionOptions<TRow extends Row> {
|
|
|
344
342
|
* overlays against confirmed server watermarks (see {@link CheckpointRegistry}).
|
|
345
343
|
*/
|
|
346
344
|
declare const lunoraCollectionOptions: <TRow extends Row>(options: LunoraCollectionConfig<TRow>) => LunoraCollectionOptions<TRow>;
|
|
347
|
-
export { CHECKPOINT_FALLBACK_MS as C, ExecutorOutboxSinkOptions as E, LunoraCollectionConfig as L, OUTBOX_MUTATION_FN_NAME as O, Row as R, SyncWriter as S, CheckpointFallbackEvent as a, CheckpointRegistry as b, CheckpointRegistryOptions as c, CheckpointRegistryStats as d, CheckpointWatermark as e, LunoraCollectionOptions as f, OutboxExecutor as g, OutboxMutationMetadata as h, createCheckpointRegistry as i, createExecutorOutboxSink as j, createOptimisticOnlineDetector as k, getShardCheckpoints as l, lunoraCollectionOptions as m, makeDiffEmit as n, runOutboxMutation as o, releaseShardCheckpoints as r,
|
|
345
|
+
export { CHECKPOINT_FALLBACK_MS as C, ExecutorOutboxSinkOptions as E, LunoraCollectionConfig as L, OUTBOX_MUTATION_FN_NAME as O, Row as R, SyncWriter as S, CheckpointFallbackEvent as a, CheckpointRegistry as b, CheckpointRegistryOptions as c, CheckpointRegistryStats as d, CheckpointWatermark as e, LunoraCollectionOptions as f, OutboxExecutor as g, OutboxMutationMetadata as h, createCheckpointRegistry as i, createExecutorOutboxSink as j, createOptimisticOnlineDetector as k, getShardCheckpoints as l, lunoraCollectionOptions as m, makeDiffEmit as n, runOutboxMutation as o, releaseShardCheckpoints as r, toMap as t };
|
package/dist/packem_shared/{defineCollections-DBxlxj4t.mjs → defineCollections-DLPLAvjt.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{lunoraCollectionOptions as M}from"./CHECKPOINT_FALLBACK_MS-
|
|
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};
|
|
@@ -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-BDL5mz7T.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-BDL5mz7T.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,4 +1,4 @@
|
|
|
1
|
-
import { R as Row } from "./collection-options.d-
|
|
1
|
+
import { R as Row } from "./collection-options.d-BDL5mz7T.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-BDL5mz7T.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.71",
|
|
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.
|
|
57
|
+
"@lunora/client": "1.0.0-alpha.67",
|
|
58
58
|
"@lunora/errors": "1.0.0-alpha.26"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as S}from"@lunora/errors";import{BTreeIndex as M}from"@tanstack/db";import{toMap as T,makeDiffEmit as E}from"./OUTBOX_MUTATION_FN_NAME-BfFCughR.mjs";const I=()=>{let e=Number.NEGATIVE_INFINITY;const r=[];return{advance:t=>{if(!(t<=e)){e=t;for(let s=r.length-1;s>=0;s-=1){const i=r[s];i&&i.threshold<=e&&(i.resolve(),r.splice(s,1))}}},await:t=>t<=e?Promise.resolve():new Promise(s=>{r.push({resolve:s,threshold:t})}),passed:t=>t<=e,reset:()=>{for(const t of r.splice(0))t.resolve();e=Number.NEGATIVE_INFINITY},waiting:()=>r.length}};let b=!1;const K=e=>{b||(b=!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.)`))},u=new WeakMap,w=new WeakMap,C=new WeakSet,N=new WeakMap,F=3e3,R=(e={})=>{const r=e.fallbackMs??F,t=e.onFallback??K,s=I(),i=I();let d=0;const o=new Set,p=(a,c)=>{for(const l of o)l.kind===a&&l.threshold<=c&&(clearTimeout(l.handle),o.delete(l))},y=(a,c)=>{if(r<=0)return;const l=a==="checkpoint"?s:i;if(l.passed(c))return;for(const m of o)if(m.kind===a&&m.threshold>=c)return;const n={handle:setTimeout(()=>{if(o.delete(n),!l.passed(c)){d+=1,l.advance(c);try{t({kind:a,waitedMs:r,watermark:c})}catch{}}},r),kind:a,threshold:c};o.add(n)},f={acknowledge:({checkpoint:a,mutationId:c})=>{a!==void 0&&y("checkpoint",a),c!==void 0&&y("mutationId",c)},awaitCheckpoint:a=>s.await(a),awaitMutationId:a=>i.await(a),dispose:()=>{for(const a of o)clearTimeout(a.handle);o.clear()},resolve:({checkpoint:a,mutationId:c})=>{a!==void 0&&(s.advance(a),p("checkpoint",a)),c!==void 0&&(i.advance(c),p("mutationId",c))},stats:()=>({fallbacks:d,pendingCheckpointWaiters:s.waiting(),pendingMutationWaiters:i.waiting()})};return N.set(f,()=>{f.dispose(),s.reset(),i.reset()}),f},G=e=>{const r=u.get(e);if(r){for(const t of r.values())t.resolve({checkpoint:Number.POSITIVE_INFINITY,mutationId:Number.POSITIVE_INFINITY}),t.dispose();u.delete(e)}},A=e=>{const r=e.currentIdentity();if(u.has(e)&&w.get(e)!==r)for(const t of u.get(e)?.values()??[])N.get(t)?.();w.set(e,r)},_=(e,r,t)=>{A(e);let s=u.get(e);s||(s=new Map,u.set(e,s));const i=r??"",d=s.get(i);if(d)return d;const o=R(t);return s.set(i,o),o},W=e=>{C.add(e)},P=e=>C.has(e),L=e=>{const r=u.get(e),t={};if(r)for(const[s,i]of r)t[s]=i.stats();return t},V=e=>{if(e.list===void 0==(e.shape===void 0))throw new S("INTERNAL","lunoraCollectionOptions: pass exactly one of `list` or `shape`");const r=e.getKey??(n=>n._id),t=()=>{const n=e.checkpoints??_(e.client,e.shape?.shardKey??e.shardKey);return W(n),n},s=t(),i=new Map;let d,o,p,y,f;const a=(n,m)=>{const k=h=>{d?.(T(h,r)),m?.(),e.shape===void 0&&(t().resolve({mutationId:f??e.client.confirmedMutationWatermark(e.shardKey)}),f=void 0)},g=h=>p?.(h),v=h=>{h.mutationId!==void 0&&(f=h.mutationId),t().resolve(h)};return e.shape!==void 0?e.client.subscribeShape({args:n,name:e.shape.name},k,{onCheckpoint:v,onError:g,shardKey:e.shape.shardKey}):e.client.subscribe(e.list,n,k,{onCheckpoint:v,onError:g,shardKey:e.shardKey})},c={autoIndex:"eager",defaultIndexType:M,getKey:r,id:e.id??e.list?.__lunoraRef??`shape:${e.shape?.name??""}`,...e.load==="eager"?{startSync:!0}:{},sync:{sync:n=>(d=E(i,n),p=k=>{n.markReady(),e.onError?.(k)},e.scopeBy===void 0?o=a(e.shape?.args??{},()=>{n.markReady()}):(n.markReady(),y!==void 0&&(o=a(y,void 0))),()=>{d=void 0,p=void 0,o?.(),o=void 0,i.clear()})}};return{checkpoints:s,config:c,scope:n=>{e.scopeBy!==void 0&&(y=n,o?.(),o=void 0,d?.(new Map),n!==void 0&&d!==void 0&&(o=a(n,void 0)))}}};export{F as CHECKPOINT_FALLBACK_MS,R as createCheckpointRegistry,_ as getShardCheckpoints,P as hasCheckpointsAttached,V as lunoraCollectionOptions,W as markCheckpointsAttached,G as releaseShardCheckpoints,L as shardCheckpointStats,A as syncShardCheckpointIdentity};
|