@lunora/db 1.0.0-alpha.150 → 1.0.0-alpha.151
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-BV_RSNwO.mjs → CHECKPOINT_FALLBACK_MS-DgrLzaWr.mjs} +1 -1
- package/dist/packem_shared/DIRECT_TRANSACTION_METADATA_KEY-C8-I3T2D.mjs +1 -0
- package/dist/packem_shared/OUTBOX_MUTATION_FN_NAME-rGyegnLw.mjs +1 -0
- package/dist/packem_shared/{collection-options.d-DsGUMF3w.d.ts → collection-options.d-QNwn1hBH.d.mts} +5 -1
- package/dist/packem_shared/{collection-options.d-DsGUMF3w.d.mts → collection-options.d-QNwn1hBH.d.ts} +5 -1
- package/dist/packem_shared/defineCollections-BU_uBD8S.mjs +1 -0
- package/dist/packem_shared/{index.d-3_VPwmxL.d.ts → index.d-BlRQftDD.d.ts} +1 -1
- package/dist/packem_shared/{index.d-Bf_MIEGd.d.mts → index.d-Bpi6cYCP.d.mts} +1 -1
- package/dist/packem_shared/{index.d-DIgugGcM.d.ts → index.d-D326yMXQ.d.ts} +1 -1
- package/dist/packem_shared/{index.d-B2iWmWam.d.mts → index.d-IIvTftRH.d.mts} +1 -1
- package/package.json +2 -2
- package/dist/packem_shared/DIRECT_TRANSACTION_METADATA_KEY-BlgfwSy3.mjs +0 -1
- package/dist/packem_shared/OUTBOX_MUTATION_FN_NAME-5Ig_tf_V.mjs +0 -1
- package/dist/packem_shared/defineCollections-CcZOHYUm.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-QNwn1hBH.mjs";
|
|
2
|
+
export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/index.d-Bpi6cYCP.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-QNwn1hBH.js";
|
|
2
|
+
export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/index.d-BlRQftDD.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-DgrLzaWr.mjs";import{defineCollections as n}from"../packem_shared/defineCollections-BU_uBD8S.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-QNwn1hBH.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-QNwn1hBH.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-Bpi6cYCP.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-IIvTftRH.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-QNwn1hBH.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-QNwn1hBH.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-BlRQftDD.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-D326yMXQ.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-DgrLzaWr.mjs";import{defineCollections as O}from"./packem_shared/defineCollections-BU_uBD8S.mjs";import{DIRECT_TRANSACTION_METADATA_KEY as f,bindMutators as u,defineMutator as x,initMutators as A}from"./packem_shared/DIRECT_TRANSACTION_METADATA_KEY-C8-I3T2D.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-rGyegnLw.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-IIvTftRH.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-QNwn1hBH.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-D326yMXQ.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-QNwn1hBH.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-C8-I3T2D.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-
|
|
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-rGyegnLw.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isAuthReplayFailure as k}from"@lunora/client";import{LunoraError as l}from"@lunora/errors";import{createTransaction as v}from"@tanstack/db";import{getShardCheckpoints as C,hasCheckpointsAttached as I,syncShardCheckpointIdentity as A}from"./CHECKPOINT_FALLBACK_MS-DgrLzaWr.mjs";import{assertSecureRandom as E,runOutboxMutation as S,toNonRetriable as T}from"./OUTBOX_MUTATION_FN_NAME-rGyegnLw.mjs";const b="__tanstack_db_direct",g="defineMutator: `serverRef` must be a generated mutator reference (api.mutators.*) or a 'namespace:fn' string",N=t=>{const e=typeof t=="string"?t:t?.__lunoraRef;if(typeof e!="string"||e.length===0)throw new l("INTERNAL",g);return e},K=t=>({__lunoraClientMutator:!0,apply:t.apply,serverRef:N(t.serverRef)}),O=(t,e,y)=>{E("bindMutators");const d=32;let u=0,m=t.currentIdentity();const h=()=>{A(t);const r=t.currentIdentity();r!==m&&(u=0,m=r)},R=()=>(h(),u=Math.max(u,t.confirmedMutationWatermark(e.shardKey))+1,u);let p=Promise.resolve();const M=(r,a)=>{const s=p.then(async()=>{for(let i=0;;i+=1){const n=R();try{const{applied:o}=await t.callMutator(r,a,{clientSeq:n,shardKey:e.shardKey});if(o)return n}catch(o){throw h(),u=t.confirmedMutationWatermark(e.shardKey),o}if(i>=d)throw new l("INTERNAL",`lunora: custom mutator "${r}" could not claim a fresh client sequence after ${String(d)} attempts`)}});return p=s.then(()=>{},()=>{}),s},w=()=>{if(e.checkpoints===!1)return;if(e.checkpoints)return e.checkpoints;const r=C(t,e.shardKey);return I(r)?r:void 0},_=(r,a,s,i)=>{const{onWriteRejected:n}=e;n&&r.isPersisted.promise.catch(o=>{const c=o instanceof Error?o:new Error(String(o));try{n({args:i,code:c.code,error:c,mutator:a,serverRef:s})}catch{}})},f={};for(const[r,a]of Object.entries(y))f[r]=s=>{const i=v({autoCommit:!0,metadata:{[b]:!0,serverRef:a.serverRef},mutationFn:async()=>{let n=0;try{await S(async()=>{n=await M(a.serverRef,s)})}catch(c){throw k(c)?T(c):c}const o=w();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 f},W=()=>({bindMutators:O,defineMutator:K});export{b as DIRECT_TRANSACTION_METADATA_KEY,O as bindMutators,K as defineMutator,W as initMutators};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isAuthReplayFailure as p}from"@lunora/client";import{createCollection as b,safeRandomUUID as h}from"@tanstack/db";import{NonRetriableError as s}from"@tanstack/offline-transactions";const g=1e3,I=e=>{const t=globalThis.crypto;if(!(typeof t?.randomUUID=="function"||typeof t?.getRandomValues=="function"))throw new Error(`${e}: this runtime has no WebCrypto (\`crypto.randomUUID\` / \`crypto.getRandomValues\`), which every optimistic write needs to mint its client-side id. On React Native / Expo, install \`expo-crypto\` (or \`react-native-get-random-values\`) and import it ONCE at the top of your entry file, before anything that reaches \`@lunora/db\` or \`@tanstack/db\`.`)},u="__lunora_outbox__",m=new WeakMap,R=()=>b({getKey:e=>e._id,id:`${u}:${h()}`,startSync:!0,sync:{sync:e=>(e.markReady(),()=>{})}}),_=(e,t)=>{m.set(e,t)};let f=!1;const c=new Map,O=e=>{e.onRejected&&c.set(e.idempotencyKey,e.onRejected)},v=e=>{const t=c.get(e);return c.delete(e),t},N=(e,t={})=>{const o=t.maxItems??1e3,a=t.mutationFnName??u;return{pending:()=>e.getPendingCount()>0,enqueue(n){if(e.getPendingCount()>=o){const d=new Error("offline outbox is full");return d.code="OFFLINE_QUEUE_OVERFLOW",Promise.reject(d)}O(n);const r={args:n.args,baselineSeq:n.baselineSeq,clientId:n.clientId,functionPath:n.functionPath,idempotencyKey:n.idempotencyKey,identity:n.identity,mutationId:n.mutationId,shardKey:n.shardKey},i=m.get(e);!i&&!f&&(f=!0,console.warn("[@lunora/db] createExecutorOutboxSink: no outbox carrier is registered for this executor. On a TanStack OfflineExecutor a zero-mutation transaction is silently dropped, so offline writes may be lost — wire the sink to the executor returned by defineCollections()."));const l=e.createOfflineTransaction({autoCommit:!1,idempotencyKey:n.idempotencyKey,metadata:r,mutationFnName:a});return l.mutate(()=>{i?.insert({_id:n.idempotencyKey})}),l.commit?.().catch(()=>{}),Promise.resolve()}}},k=(e,t)=>new Map(e.map(o=>[t(o),o])),C=(e,t)=>o=>{t.begin();const a=new Map;for(const[n,r]of o){const i=JSON.stringify(r);a.set(n,i),e.has(n)?e.get(n)!==i&&t.write({type:"update",value:r}):t.write({type:"insert",value:r})}for(const n of e.keys())o.has(n)||t.write({key:n,type:"delete"});t.commit(),e.clear();for(const[n,r]of a)e.set(n,r)},y=e=>{if(e instanceof s)return e;const t=new s(e instanceof Error?e.message:String(e)),{code:o}=e;return typeof o=="string"&&(t.code=o),t},S=async e=>{try{await e()}catch(t){throw t.code==="IDENTITY_MISMATCH"||p(t)?t:typeof t.code=="string"?y(t):t}},M=e=>{if(e instanceof s)return e;const t=e instanceof Error?e:new Error(String(e));if(t.name==="AbortError"||["400","401","403","422"].some(o=>t.message.includes(o)))return y(e)},T=()=>{const e=new Set;return{dispose:()=>{for(const t of e)clearInterval(t);e.clear()},isOnline:()=>!0,notifyOnline:()=>{},subscribe:t=>{const o=setInterval(t,g);return e.add(o),()=>{clearInterval(o),e.delete(o)}}}};export{u as OUTBOX_MUTATION_FN_NAME,I as assertSecureRandom,N as createExecutorOutboxSink,T as createOptimisticOnlineDetector,R as createOutboxCarrier,C as makeDiffEmit,_ as registerOutboxCarrier,S as runOutboxMutation,v as takeOutboxRejection,M as terminalVerdict,k as toMap,y as toNonRetriable};
|
|
@@ -148,7 +148,11 @@ declare const makeDiffEmit: <T extends object>(syncedJson: Map<string, string>,
|
|
|
148
148
|
* code is transient — a `fetch` network failure (`TypeError`) or an HTTP/infra
|
|
149
149
|
* blip the rpc surfaces as a code-less `Error` (a 5xx gateway page, a non-JSON
|
|
150
150
|
* body) — so it's rethrown as-is and the durable outbox replays it. Keying on
|
|
151
|
-
* `error instanceof TypeError` alone would wrongly drop the latter.
|
|
151
|
+
* `error instanceof TypeError` alone would wrongly drop the latter. Two coded
|
|
152
|
+
* failures are not verdicts on the write and are rethrown as-is too: the worker's
|
|
153
|
+
* `IDENTITY_MISMATCH`, and a refused credential ({@link isAuthReplayFailure}).
|
|
154
|
+
* The caller decides what those mean: `defineCollections` holds the write for a
|
|
155
|
+
* fresh credential, and a bound mutator (never retried) settles it.
|
|
152
156
|
*/
|
|
153
157
|
declare const runOutboxMutation: (mutate: () => Promise<unknown>) => Promise<void>;
|
|
154
158
|
/**
|
|
@@ -148,7 +148,11 @@ declare const makeDiffEmit: <T extends object>(syncedJson: Map<string, string>,
|
|
|
148
148
|
* code is transient — a `fetch` network failure (`TypeError`) or an HTTP/infra
|
|
149
149
|
* blip the rpc surfaces as a code-less `Error` (a 5xx gateway page, a non-JSON
|
|
150
150
|
* body) — so it's rethrown as-is and the durable outbox replays it. Keying on
|
|
151
|
-
* `error instanceof TypeError` alone would wrongly drop the latter.
|
|
151
|
+
* `error instanceof TypeError` alone would wrongly drop the latter. Two coded
|
|
152
|
+
* failures are not verdicts on the write and are rethrown as-is too: the worker's
|
|
153
|
+
* `IDENTITY_MISMATCH`, and a refused credential ({@link isAuthReplayFailure}).
|
|
154
|
+
* The caller decides what those mean: `defineCollections` holds the write for a
|
|
155
|
+
* fresh credential, and a bound mutator (never retried) settles it.
|
|
152
156
|
*/
|
|
153
157
|
declare const runOutboxMutation: (mutate: () => Promise<unknown>) => Promise<void>;
|
|
154
158
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{lunoraCollectionOptions as M}from"./CHECKPOINT_FALLBACK_MS-DgrLzaWr.mjs";import{isAuthReplayFailure as S}from"@lunora/client";import{createCollection as _,safeRandomUUID as A}from"@tanstack/db";import{startOfflineExecutor as D,NonRetriableError as U}from"@tanstack/offline-transactions";import{assertSecureRandom as j,createOutboxCarrier as L,createOptimisticOnlineDetector as q,OUTBOX_MUTATION_FN_NAME as N,registerOutboxCarrier as W,takeOutboxRejection as T,toNonRetriable as R,runOutboxMutation as $,terminalVerdict as k}from"./OUTBOX_MUTATION_FN_NAME-rGyegnLw.mjs";const B=new WeakMap,H=(n,s)=>{let o=B.get(n);o===void 0&&(o=new Map,B.set(n,o));const c=o.get(s)??0;o.set(s,c+1),c===1&&console.warn(`[@lunora/db] table "${s}" 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).`)},b=(n,s)=>{try{n.onWriteRejected?.(s)}catch{}},P=(n,s)=>{const o=n.replayIdentityVerdict(s?.identity);if(o.verdict==="mismatch")throw new U("outbox write dropped: identity changed since it was queued");if(o.verdict==="unknown")throw new Error("outbox write deferred: no identity established yet");return o.credential},V=6e4,Y=(n,s,o={})=>{j("defineCollections");const c={},d=new Map,C=async(t,e,r)=>{const i=d.get(t);if(n.getAuthToken()===i?.refused)throw Date.now()-i.since<V?new Error("outbox write deferred: waiting for a fresh credential"):(d.delete(t),R(i.error));const m=n.getAuthToken(),l=P(n,e);try{await $(async()=>r(l))}catch(a){throw S(a)?i!==void 0?(d.delete(t),R(a)):(d.set(t,{error:a,refused:m,since:Date.now()}),new Error("outbox write deferred: its credential was refused",{cause:a})):a}d.delete(t)},K=(t,e)=>{const r=k(e);return r!==void 0&&d.delete(t),r},O={},y={},x=Object.entries(s);for(const[t,e]of x){const r=e.insert;H(n,t);const{config:i,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});c[t]=_(i),e.scopeBy!==void 0&&(O[t]=m),r&&(y[t]=async({idempotencyKey:l,transaction:a})=>{const u=a.metadata;for(const[w,I]of a.mutations.entries()){const F=I.modified,p=`${l}:${String(w)}`;try{await C(p,u,async f=>n.mutation(r.mutation,r.toArgs(F),{mutationId:p,replayBaseline:u?.baselineSeq??null,replayCredential:f,shardKey:u?.shardKey}))}catch(g){const f=K(p,g);throw f!==void 0?(b(o,{code:f.code,collection:t,error:f,row:F}),f):g}}})}y[N]=async({transaction:t})=>{const e=t.metadata;if(e)try{const r=async i=>n.mutation({__lunoraRef:e.functionPath},e.args,{mutationId:e.idempotencyKey,replayBaseline:e.baselineSeq??null,replayCredential:i,shardKey:e.shardKey});await C(e.idempotencyKey,e,r),T(e.idempotencyKey)}catch(r){const i=K(e.idempotencyKey,r);throw i!==void 0?(T(e.idempotencyKey)?.(),b(o,{code:i.code,collection:e.functionPath,error:i}),i):r}};const v=L(),h=D({collections:{...c,[N]:v},mutationFns:y,onlineDetector:q(),...o.onLeadershipChange?{onLeadershipChange:o.onLeadershipChange}:{},...o.onStorageFailure?{onStorageFailure:o.onStorageFailure}:{},onUnknownMutationFn:(t,e)=>{b(o,{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})}});W(h,v);const E={};for(const[t,e]of x){const r=e.insert,i=c[t];!r||!i||(E[t]=m=>{const l=A(),a={baselineSeq:n.currentBaseline(e.shardKey),identity:n.currentIdentity(),shardKey:e.shardKey},u=h.createOfflineTransaction({autoCommit:!1,metadata:a,mutationFnName:t}),w=u.mutate(()=>{i.insert(r.optimistic(m,l))});return u.commit().catch(()=>{}),{id:l,transaction:w}})}return{actions:E,collections:c,executor:h,pendingCount:()=>h.getPendingCount(),scope:O}};export{Y as defineCollections};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as Row } from "./collection-options.d-
|
|
1
|
+
import { R as Row } from "./collection-options.d-QNwn1hBH.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,4 +1,4 @@
|
|
|
1
|
-
import { R as Row } from "./collection-options.d-
|
|
1
|
+
import { R as Row } from "./collection-options.d-QNwn1hBH.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-QNwn1hBH.js";
|
|
4
4
|
/**
|
|
5
5
|
* TanStack DB's "direct transaction" marker.
|
|
6
6
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LunoraClient } from '@lunora/client';
|
|
2
2
|
import { Collection, Transaction } from '@tanstack/db';
|
|
3
|
-
import { b as CheckpointRegistry } from "./collection-options.d-
|
|
3
|
+
import { b as CheckpointRegistry } from "./collection-options.d-QNwn1hBH.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.151",
|
|
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.149",
|
|
58
58
|
"@lunora/errors": "1.0.0-alpha.44"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as l}from"@lunora/errors";import{createTransaction as v}from"@tanstack/db";import{getShardCheckpoints as w,hasCheckpointsAttached as C,syncShardCheckpointIdentity as I}from"./CHECKPOINT_FALLBACK_MS-BV_RSNwO.mjs";import{assertSecureRandom as E,runOutboxMutation as S}from"./OUTBOX_MUTATION_FN_NAME-5Ig_tf_V.mjs";const T="__tanstack_db_direct",A="defineMutator: `serverRef` must be a generated mutator reference (api.mutators.*) or a 'namespace:fn' string",b=t=>{const e=typeof t=="string"?t:t?.__lunoraRef;if(typeof e!="string"||e.length===0)throw new l("INTERNAL",A);return e},g=t=>({__lunoraClientMutator:!0,apply:t.apply,serverRef:b(t.serverRef)}),K=(t,e,y)=>{E("bindMutators");const u=32;let c=0,d=t.currentIdentity();const m=()=>{I(t);const r=t.currentIdentity();r!==d&&(c=0,d=r)},R=()=>(m(),c=Math.max(c,t.confirmedMutationWatermark(e.shardKey))+1,c);let p=Promise.resolve();const M=(r,a)=>{const s=p.then(async()=>{for(let i=0;;i+=1){const n=R();try{const{applied:o}=await t.callMutator(r,a,{clientSeq:n,shardKey:e.shardKey});if(o)return n}catch(o){throw m(),c=t.confirmedMutationWatermark(e.shardKey),o}if(i>=u)throw new l("INTERNAL",`lunora: custom mutator "${r}" could not claim a fresh client sequence after ${String(u)} attempts`)}});return p=s.then(()=>{},()=>{}),s},_=()=>{if(e.checkpoints===!1)return;if(e.checkpoints)return e.checkpoints;const r=w(t,e.shardKey);return C(r)?r:void 0},k=(r,a,s,i)=>{const{onWriteRejected:n}=e;n&&r.isPersisted.promise.catch(o=>{const f=o instanceof Error?o:new Error(String(o));try{n({args:i,code:f.code,error:f,mutator:a,serverRef:s})}catch{}})},h={};for(const[r,a]of Object.entries(y))h[r]=s=>{const i=v({autoCommit:!0,metadata:{[T]:!0,serverRef:a.serverRef},mutationFn:async()=>{let n=0;await S(async()=>{n=await M(a.serverRef,s)});const o=_();o&&(o.acknowledge({mutationId:n}),await o.awaitMutationId(n))}});return i.mutate(()=>{a.apply({collections:e.collections},s)}),k(i,r,a.serverRef,s),i};return h},F=()=>({bindMutators:K,defineMutator:g});export{T as DIRECT_TRANSACTION_METADATA_KEY,K as bindMutators,g as defineMutator,F as initMutators};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createCollection as y,safeRandomUUID as m}from"@tanstack/db";import{NonRetriableError as p}from"@tanstack/offline-transactions";const b=1e3,x=e=>{const t=globalThis.crypto;if(!(typeof t?.randomUUID=="function"||typeof t?.getRandomValues=="function"))throw new Error(`${e}: this runtime has no WebCrypto (\`crypto.randomUUID\` / \`crypto.getRandomValues\`), which every optimistic write needs to mint its client-side id. On React Native / Expo, install \`expo-crypto\` (or \`react-native-get-random-values\`) and import it ONCE at the top of your entry file, before anything that reaches \`@lunora/db\` or \`@tanstack/db\`.`)},f="__lunora_outbox__",u=new WeakMap,I=()=>y({getKey:e=>e._id,id:`${f}:${m()}`,startSync:!0,sync:{sync:e=>(e.markReady(),()=>{})}}),w=(e,t)=>{u.set(e,t)};let l=!1;const s=new Map,h=e=>{e.onRejected&&s.set(e.idempotencyKey,e.onRejected)},E=e=>{const t=s.get(e);return s.delete(e),t},R=(e,t={})=>{const n=t.maxItems??1e3,a=t.mutationFnName??f;return{pending:()=>e.getPendingCount()>0,enqueue(o){if(e.getPendingCount()>=n){const d=new Error("offline outbox is full");return d.code="OFFLINE_QUEUE_OVERFLOW",Promise.reject(d)}h(o);const r={args:o.args,baselineSeq:o.baselineSeq,clientId:o.clientId,functionPath:o.functionPath,idempotencyKey:o.idempotencyKey,identity:o.identity,mutationId:o.mutationId,shardKey:o.shardKey},i=u.get(e);!i&&!l&&(l=!0,console.warn("[@lunora/db] createExecutorOutboxSink: no outbox carrier is registered for this executor. On a TanStack OfflineExecutor a zero-mutation transaction is silently dropped, so offline writes may be lost — wire the sink to the executor returned by defineCollections()."));const c=e.createOfflineTransaction({autoCommit:!1,idempotencyKey:o.idempotencyKey,metadata:r,mutationFnName:a});return c.mutate(()=>{i?.insert({_id:o.idempotencyKey})}),c.commit?.().catch(()=>{}),Promise.resolve()}}},_=(e,t)=>new Map(e.map(n=>[t(n),n])),v=(e,t)=>n=>{t.begin();const a=new Map;for(const[o,r]of n){const i=JSON.stringify(r);a.set(o,i),e.has(o)?e.get(o)!==i&&t.write({type:"update",value:r}):t.write({type:"insert",value:r})}for(const o of e.keys())n.has(o)||t.write({key:o,type:"delete"});t.commit(),e.clear();for(const[o,r]of a)e.set(o,r)},N=async e=>{try{await e()}catch(t){if(t.code==="IDENTITY_MISMATCH")throw t;if(typeof t.code=="string"){const n=new p(t instanceof Error?t.message:String(t));throw n.code=t.code,n}throw t}},k=()=>{const e=new Set;return{dispose:()=>{for(const t of e)clearInterval(t);e.clear()},isOnline:()=>!0,notifyOnline:()=>{},subscribe:t=>{const n=setInterval(t,b);return e.add(n),()=>{clearInterval(n),e.delete(n)}}}};export{f as OUTBOX_MUTATION_FN_NAME,x as assertSecureRandom,R as createExecutorOutboxSink,k as createOptimisticOnlineDetector,I as createOutboxCarrier,v as makeDiffEmit,w as registerOutboxCarrier,N as runOutboxMutation,E as takeOutboxRejection,_ as toMap};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{lunoraCollectionOptions as S}from"./CHECKPOINT_FALLBACK_MS-BV_RSNwO.mjs";import{createCollection as T,safeRandomUUID as M}from"@tanstack/db";import{startOfflineExecutor as R,NonRetriableError as b}from"@tanstack/offline-transactions";import{assertSecureRandom as U,createOutboxCarrier as _,createOptimisticOnlineDetector as j,OUTBOX_MUTATION_FN_NAME as x,registerOutboxCarrier as k,runOutboxMutation as I,takeOutboxRejection as N}from"./OUTBOX_MUTATION_FN_NAME-5Ig_tf_V.mjs";const v=new WeakMap,q=(o,r)=>{let t=v.get(o);t===void 0&&(t=new Map,v.set(o,t));const a=t.get(r)??0;t.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=(o,r)=>{try{o.onWriteRejected?.(r)}catch{}},B=(o,r)=>{const t=o.replayIdentityVerdict(r?.identity);if(t==="mismatch")throw new b("outbox write dropped: identity changed since it was queued");if(t==="unknown")throw new Error("outbox write deferred: no identity established yet")},L=(o,r,t={})=>{U("defineCollections");const a={},g={},y={},w=Object.entries(r);for(const[n,e]of w){const i=e.insert;q(o,n);const{config:d,scope:m}=S({client:o,getKey:e.getKey,id:n,list:e.list,...e.load===void 0?{}:{load:e.load},onError:e.onError,scopeBy:e.scopeBy,shardKey:e.shardKey});a[n]=T(d),e.scopeBy!==void 0&&(g[n]=m),i&&(y[n]=async({idempotencyKey:l,transaction:u})=>{const s=u.metadata;for(const[h,F]of u.mutations.entries()){const K=F.modified,E=`${l}:${String(h)}`;try{B(o,s),await I(()=>o.mutation(i.mutation,i.toArgs(K),{mutationId:E,replayBaseline:s.baselineSeq??null,replayIdentity:s.identity,shardKey:s.shardKey}))}catch(f){throw f instanceof b&&p(t,{code:f.code,collection:n,error:f,row:K}),f}}})}y[x]=async({transaction:n})=>{const e=n.metadata;if(e)try{B(o,e),await I(()=>o.mutation({__lunoraRef:e.functionPath},e.args,{mutationId:e.idempotencyKey,replayBaseline:e.baselineSeq??null,replayIdentity:e.identity,shardKey:e.shardKey})),N(e.idempotencyKey)}catch(i){throw i instanceof b&&(N(e.idempotencyKey)?.(),p(t,{code:i.code,collection:e.functionPath,error:i})),i}};const O=_(),c=R({collections:{...a,[x]:O},mutationFns:y,onlineDetector:j(),...t.onLeadershipChange?{onLeadershipChange:t.onLeadershipChange}:{},...t.onStorageFailure?{onStorageFailure:t.onStorageFailure}:{},onUnknownMutationFn:(n,e)=>{p(t,{code:"UNKNOWN_MUTATION_FN",collection:n,error:new Error(`offline write dropped: mutation "${n}" no longer exists (removed or renamed in a deploy?)`),row:e.mutations[0]?.modified})}});k(c,O);const C={};for(const[n,e]of w){const i=e.insert,d=a[n];!i||!d||(C[n]=m=>{const l=M(),u={baselineSeq:o.currentBaseline(e.shardKey),identity:o.currentIdentity(),shardKey:e.shardKey},s=c.createOfflineTransaction({autoCommit:!1,metadata:u,mutationFnName:n}),h=s.mutate(()=>{d.insert(i.optimistic(m,l))});return s.commit().catch(()=>{}),{id:l,transaction:h}})}return{actions:C,collections:a,executor:c,pendingCount:()=>c.getPendingCount(),scope:g}};export{L as defineCollections};
|