@lunora/db 1.0.0-alpha.52 → 1.0.0-alpha.54
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 +70 -5
- package/dist/index.d.ts +70 -5
- 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-CX7idSTz.mjs +1 -0
- package/dist/packem_shared/DIRECT_TRANSACTION_METADATA_KEY-Ca-snw_0.mjs +1 -0
- package/dist/packem_shared/OUTBOX_MUTATION_FN_NAME-BfFCughR.mjs +1 -0
- package/dist/packem_shared/applyPlanToCollections-C_eyqNF9.mjs +1 -0
- package/dist/packem_shared/{collection-options.d-CmsXU1wV.d.mts → collection-options.d-CspA2N8I.d.mts} +1 -1
- package/dist/packem_shared/{collection-options.d-CmsXU1wV.d.ts → collection-options.d-CspA2N8I.d.ts} +1 -1
- package/dist/packem_shared/defineCollections-DtTv50Sr.mjs +1 -0
- package/dist/packem_shared/{define-collections.d-u87f9B-o.d.ts → index.d-B5epwy7P.d.ts} +1 -1
- package/dist/packem_shared/{define-collections.d-CTOC6vMT.d.mts → index.d-BepAls8u.d.mts} +1 -1
- package/dist/packem_shared/{define-mutators.d-C6MkAEpe.d.ts → index.d-Cq7dDe62.d.ts} +2 -2
- package/dist/packem_shared/{define-mutators.d-cBFz2vjk.d.mts → index.d-Ye1uUYB0.d.mts} +2 -2
- package/package.json +3 -3
- package/dist/packem_shared/CHECKPOINT_FALLBACK_MS-Dxy7C_Up.mjs +0 -1
- package/dist/packem_shared/DIRECT_TRANSACTION_METADATA_KEY-RVemC9vI.mjs +0 -1
- package/dist/packem_shared/OUTBOX_MUTATION_FN_NAME-BznV-kE1.mjs +0 -1
- package/dist/packem_shared/applyPlanToCollections-CPB4eTOM.mjs +0 -1
- package/dist/packem_shared/defineCollections-qbfQ6xN1.mjs +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { type
|
|
2
|
-
export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/
|
|
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-CspA2N8I.mjs";
|
|
2
|
+
export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/index.d-BepAls8u.mjs";
|
|
3
3
|
import '@lunora/client';
|
|
4
4
|
import '@tanstack/db';
|
|
5
5
|
import '@tanstack/offline-transactions';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { type
|
|
2
|
-
export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/
|
|
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-CspA2N8I.js";
|
|
2
|
+
export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/index.d-B5epwy7P.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-CX7idSTz.mjs";import{defineCollections as n}from"../packem_shared/defineCollections-DtTv50Sr.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 {
|
|
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/
|
|
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
|
|
2
|
+
import { R as Row } from "./packem_shared/collection-options.d-CspA2N8I.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, s as shardCheckpointStats, t as toMap } from "./packem_shared/collection-options.d-CspA2N8I.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-BepAls8u.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-Ye1uUYB0.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. */
|
|
@@ -79,4 +79,69 @@ declare const applyPlanToCollections: (collections: Record<string, Collection<Ro
|
|
|
79
79
|
*/
|
|
80
80
|
declare const applyPlanToDb: (db: PlanWriter, plan: ChangePlan) => Promise<void>;
|
|
81
81
|
declare const VERSION = "0.0.0";
|
|
82
|
-
export {
|
|
82
|
+
export {
|
|
83
|
+
/**
|
|
84
|
+
* `@lunora/db` — a TanStack DB binding for the Lunora client.
|
|
85
|
+
*
|
|
86
|
+
* `defineCollections(client, { … })` wires a set of Lunora tables into live,
|
|
87
|
+
* auto-indexed TanStack DB collections (reads) plus a durable, retried
|
|
88
|
+
* offline-transactions outbox (writes) in one declaration. The lower-level
|
|
89
|
+
* helpers are exported for testing and advanced composition.
|
|
90
|
+
*
|
|
91
|
+
* Peer-depends on `@tanstack/db` and `@tanstack/offline-transactions`; the
|
|
92
|
+
* consuming app pins their versions and supplies React bindings
|
|
93
|
+
* (`@tanstack/react-db`) itself.
|
|
94
|
+
*/
|
|
95
|
+
type ChangePlan,
|
|
96
|
+
/**
|
|
97
|
+
* `@lunora/db` — a TanStack DB binding for the Lunora client.
|
|
98
|
+
*
|
|
99
|
+
* `defineCollections(client, { … })` wires a set of Lunora tables into live,
|
|
100
|
+
* auto-indexed TanStack DB collections (reads) plus a durable, retried
|
|
101
|
+
* offline-transactions outbox (writes) in one declaration. The lower-level
|
|
102
|
+
* helpers are exported for testing and advanced composition.
|
|
103
|
+
*
|
|
104
|
+
* Peer-depends on `@tanstack/db` and `@tanstack/offline-transactions`; the
|
|
105
|
+
* consuming app pins their versions and supplies React bindings
|
|
106
|
+
* (`@tanstack/react-db`) itself.
|
|
107
|
+
*/
|
|
108
|
+
type PlanDelete,
|
|
109
|
+
/**
|
|
110
|
+
* `@lunora/db` — a TanStack DB binding for the Lunora client.
|
|
111
|
+
*
|
|
112
|
+
* `defineCollections(client, { … })` wires a set of Lunora tables into live,
|
|
113
|
+
* auto-indexed TanStack DB collections (reads) plus a durable, retried
|
|
114
|
+
* offline-transactions outbox (writes) in one declaration. The lower-level
|
|
115
|
+
* helpers are exported for testing and advanced composition.
|
|
116
|
+
*
|
|
117
|
+
* Peer-depends on `@tanstack/db` and `@tanstack/offline-transactions`; the
|
|
118
|
+
* consuming app pins their versions and supplies React bindings
|
|
119
|
+
* (`@tanstack/react-db`) itself.
|
|
120
|
+
*/
|
|
121
|
+
type PlanInsert,
|
|
122
|
+
/**
|
|
123
|
+
* `@lunora/db` — a TanStack DB binding for the Lunora client.
|
|
124
|
+
*
|
|
125
|
+
* `defineCollections(client, { … })` wires a set of Lunora tables into live,
|
|
126
|
+
* auto-indexed TanStack DB collections (reads) plus a durable, retried
|
|
127
|
+
* offline-transactions outbox (writes) in one declaration. The lower-level
|
|
128
|
+
* helpers are exported for testing and advanced composition.
|
|
129
|
+
*
|
|
130
|
+
* Peer-depends on `@tanstack/db` and `@tanstack/offline-transactions`; the
|
|
131
|
+
* consuming app pins their versions and supplies React bindings
|
|
132
|
+
* (`@tanstack/react-db`) itself.
|
|
133
|
+
*/
|
|
134
|
+
type PlanPatch,
|
|
135
|
+
/**
|
|
136
|
+
* `@lunora/db` — a TanStack DB binding for the Lunora client.
|
|
137
|
+
*
|
|
138
|
+
* `defineCollections(client, { … })` wires a set of Lunora tables into live,
|
|
139
|
+
* auto-indexed TanStack DB collections (reads) plus a durable, retried
|
|
140
|
+
* offline-transactions outbox (writes) in one declaration. The lower-level
|
|
141
|
+
* helpers are exported for testing and advanced composition.
|
|
142
|
+
*
|
|
143
|
+
* Peer-depends on `@tanstack/db` and `@tanstack/offline-transactions`; the
|
|
144
|
+
* consuming app pins their versions and supplies React bindings
|
|
145
|
+
* (`@tanstack/react-db`) itself.
|
|
146
|
+
*/
|
|
147
|
+
type PlanWriter, type Row, VERSION, applyPlanToCollections, applyPlanToDb };
|
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 {
|
|
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/
|
|
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
|
|
2
|
+
import { R as Row } from "./packem_shared/collection-options.d-CspA2N8I.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, s as shardCheckpointStats, t as toMap } from "./packem_shared/collection-options.d-CspA2N8I.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-B5epwy7P.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-Cq7dDe62.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. */
|
|
@@ -79,4 +79,69 @@ declare const applyPlanToCollections: (collections: Record<string, Collection<Ro
|
|
|
79
79
|
*/
|
|
80
80
|
declare const applyPlanToDb: (db: PlanWriter, plan: ChangePlan) => Promise<void>;
|
|
81
81
|
declare const VERSION = "0.0.0";
|
|
82
|
-
export {
|
|
82
|
+
export {
|
|
83
|
+
/**
|
|
84
|
+
* `@lunora/db` — a TanStack DB binding for the Lunora client.
|
|
85
|
+
*
|
|
86
|
+
* `defineCollections(client, { … })` wires a set of Lunora tables into live,
|
|
87
|
+
* auto-indexed TanStack DB collections (reads) plus a durable, retried
|
|
88
|
+
* offline-transactions outbox (writes) in one declaration. The lower-level
|
|
89
|
+
* helpers are exported for testing and advanced composition.
|
|
90
|
+
*
|
|
91
|
+
* Peer-depends on `@tanstack/db` and `@tanstack/offline-transactions`; the
|
|
92
|
+
* consuming app pins their versions and supplies React bindings
|
|
93
|
+
* (`@tanstack/react-db`) itself.
|
|
94
|
+
*/
|
|
95
|
+
type ChangePlan,
|
|
96
|
+
/**
|
|
97
|
+
* `@lunora/db` — a TanStack DB binding for the Lunora client.
|
|
98
|
+
*
|
|
99
|
+
* `defineCollections(client, { … })` wires a set of Lunora tables into live,
|
|
100
|
+
* auto-indexed TanStack DB collections (reads) plus a durable, retried
|
|
101
|
+
* offline-transactions outbox (writes) in one declaration. The lower-level
|
|
102
|
+
* helpers are exported for testing and advanced composition.
|
|
103
|
+
*
|
|
104
|
+
* Peer-depends on `@tanstack/db` and `@tanstack/offline-transactions`; the
|
|
105
|
+
* consuming app pins their versions and supplies React bindings
|
|
106
|
+
* (`@tanstack/react-db`) itself.
|
|
107
|
+
*/
|
|
108
|
+
type PlanDelete,
|
|
109
|
+
/**
|
|
110
|
+
* `@lunora/db` — a TanStack DB binding for the Lunora client.
|
|
111
|
+
*
|
|
112
|
+
* `defineCollections(client, { … })` wires a set of Lunora tables into live,
|
|
113
|
+
* auto-indexed TanStack DB collections (reads) plus a durable, retried
|
|
114
|
+
* offline-transactions outbox (writes) in one declaration. The lower-level
|
|
115
|
+
* helpers are exported for testing and advanced composition.
|
|
116
|
+
*
|
|
117
|
+
* Peer-depends on `@tanstack/db` and `@tanstack/offline-transactions`; the
|
|
118
|
+
* consuming app pins their versions and supplies React bindings
|
|
119
|
+
* (`@tanstack/react-db`) itself.
|
|
120
|
+
*/
|
|
121
|
+
type PlanInsert,
|
|
122
|
+
/**
|
|
123
|
+
* `@lunora/db` — a TanStack DB binding for the Lunora client.
|
|
124
|
+
*
|
|
125
|
+
* `defineCollections(client, { … })` wires a set of Lunora tables into live,
|
|
126
|
+
* auto-indexed TanStack DB collections (reads) plus a durable, retried
|
|
127
|
+
* offline-transactions outbox (writes) in one declaration. The lower-level
|
|
128
|
+
* helpers are exported for testing and advanced composition.
|
|
129
|
+
*
|
|
130
|
+
* Peer-depends on `@tanstack/db` and `@tanstack/offline-transactions`; the
|
|
131
|
+
* consuming app pins their versions and supplies React bindings
|
|
132
|
+
* (`@tanstack/react-db`) itself.
|
|
133
|
+
*/
|
|
134
|
+
type PlanPatch,
|
|
135
|
+
/**
|
|
136
|
+
* `@lunora/db` — a TanStack DB binding for the Lunora client.
|
|
137
|
+
*
|
|
138
|
+
* `defineCollections(client, { … })` wires a set of Lunora tables into live,
|
|
139
|
+
* auto-indexed TanStack DB collections (reads) plus a durable, retried
|
|
140
|
+
* offline-transactions outbox (writes) in one declaration. The lower-level
|
|
141
|
+
* helpers are exported for testing and advanced composition.
|
|
142
|
+
*
|
|
143
|
+
* Peer-depends on `@tanstack/db` and `@tanstack/offline-transactions`; the
|
|
144
|
+
* consuming app pins their versions and supplies React bindings
|
|
145
|
+
* (`@tanstack/react-db`) itself.
|
|
146
|
+
*/
|
|
147
|
+
type PlanWriter, type Row, VERSION, applyPlanToCollections, applyPlanToDb };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{applyPlanToCollections as r,applyPlanToDb as i}from"./packem_shared/applyPlanToCollections-
|
|
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,shardCheckpointStats as C}from"./packem_shared/CHECKPOINT_FALLBACK_MS-CX7idSTz.mjs";import{defineCollections as T}from"./packem_shared/defineCollections-DtTv50Sr.mjs";import{DIRECT_TRANSACTION_METADATA_KEY as u,bindMutators as x,defineMutator as A,initMutators as M}from"./packem_shared/DIRECT_TRANSACTION_METADATA_KEY-Ca-snw_0.mjs";import{OUTBOX_MUTATION_FN_NAME as E,createExecutorOutboxSink as _,createOptimisticOnlineDetector as h,makeDiffEmit as N,runOutboxMutation as S,toMap as d}from"./packem_shared/OUTBOX_MUTATION_FN_NAME-BfFCughR.mjs";const t="0.0.0";export{a as CHECKPOINT_FALLBACK_MS,u as DIRECT_TRANSACTION_METADATA_KEY,E as OUTBOX_MUTATION_FN_NAME,t as VERSION,r as applyPlanToCollections,i as applyPlanToDb,x as bindMutators,p as createCheckpointRegistry,_ as createExecutorOutboxSink,h as createOptimisticOnlineDetector,T as defineCollections,A as defineMutator,c as getShardCheckpoints,M as initMutators,l as lunoraCollectionOptions,N as makeDiffEmit,s as releaseShardCheckpoints,S as runOutboxMutation,C as shardCheckpointStats,d as toMap};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { type B as BindMutatorsContext, type a as BoundMutatorApi, type b as BoundMutators, type C as ClientMutatorContext, type c as ClientMutatorDef, type d as CollectionMap, type
|
|
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-Ye1uUYB0.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-CspA2N8I.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
|
|
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-Cq7dDe62.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-CspA2N8I.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-Ca-snw_0.mjs";export{r as bindMutators,i as defineMutator,a as initMutators};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as w}from"@lunora/errors";import{BTreeIndex as C}from"@tanstack/db";import{toMap as S,makeDiffEmit as M}from"./OUTBOX_MUTATION_FN_NAME-BfFCughR.mjs";const g=()=>{let e=Number.NEGATIVE_INFINITY;const n=[];return{advance:r=>{if(!(r<=e)){e=r;for(let a=n.length-1;a>=0;a-=1){const s=n[a];s&&s.threshold<=e&&(s.resolve(),n.splice(a,1))}}},await:r=>r<=e?Promise.resolve():new Promise(a=>{n.push({resolve:a,threshold:r})}),passed:r=>r<=e,waiting:()=>n.length}};let b=!1;const T=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.)`))},m=new WeakMap,I=new WeakSet,E=3e3,N=(e={})=>{const n=e.fallbackMs??E,r=e.onFallback??T,a=g(),s=g();let d=0;const c=new Set,h=(t,o)=>{for(const l of c)l.kind===t&&l.threshold<=o&&(clearTimeout(l.handle),c.delete(l))},u=(t,o)=>{if(n<=0)return;const l=t==="checkpoint"?a:s;if(l.passed(o))return;for(const p of c)if(p.kind===t&&p.threshold>=o)return;const i={handle:setTimeout(()=>{if(c.delete(i),!l.passed(o)){d+=1,l.advance(o);try{r({kind:t,waitedMs:n,watermark:o})}catch{}}},n),kind:t,threshold:o};c.add(i)};return{acknowledge:({checkpoint:t,mutationId:o})=>{t!==void 0&&u("checkpoint",t),o!==void 0&&u("mutationId",o)},awaitCheckpoint:t=>a.await(t),awaitMutationId:t=>s.await(t),dispose:()=>{for(const t of c)clearTimeout(t.handle);c.clear()},resolve:({checkpoint:t,mutationId:o})=>{t!==void 0&&(a.advance(t),h("checkpoint",t)),o!==void 0&&(s.advance(o),h("mutationId",o))},stats:()=>({fallbacks:d,pendingCheckpointWaiters:a.waiting(),pendingMutationWaiters:s.waiting()})}},K=(e,n,r)=>{let a=m.get(e);a||(a=new Map,m.set(e,a));const s=n??"",d=a.get(s);if(d)return d;const c=N(r);return a.set(s,c),c},F=e=>{I.add(e)},x=e=>I.has(e),O=e=>{const n=m.get(e);if(n){for(const r of n.values())r.resolve({checkpoint:Number.POSITIVE_INFINITY,mutationId:Number.POSITIVE_INFINITY}),r.dispose();m.delete(e)}},W=e=>{const n=m.get(e),r={};if(n)for(const[a,s]of n)r[a]=s.stats();return r},B=e=>{if(e.list===void 0==(e.shape===void 0))throw new w("INTERNAL","lunoraCollectionOptions: pass exactly one of `list` or `shape`");const n=e.getKey??(i=>i._id),r=e.checkpoints??K(e.client,e.shape?.shardKey??e.shardKey);F(r);const a=new Map;let s,d,c,h,u;const t=(i,p)=>{const y=f=>{s?.(S(f,n)),p?.(),e.shape===void 0&&(r.resolve({mutationId:u??e.client.confirmedMutationWatermark(e.shardKey)}),u=void 0)},k=f=>c?.(f),v=f=>{f.mutationId!==void 0&&(u=f.mutationId),r.resolve(f)};return e.shape!==void 0?e.client.subscribeShape({args:i,name:e.shape.name},y,{onCheckpoint:v,onError:k,shardKey:e.shape.shardKey}):e.client.subscribe(e.list,i,y,{onCheckpoint:v,onError:k,shardKey:e.shardKey})},o={autoIndex:"eager",defaultIndexType:C,getKey:n,id:e.id??e.list?.__lunoraRef??`shape:${e.shape?.name??""}`,...e.load==="eager"?{startSync:!0}:{},sync:{sync:i=>(s=M(a,i),c=y=>{i.markReady(),e.onError?.(y)},e.scopeBy===void 0?d=t(e.shape?.args??{},()=>{i.markReady()}):(i.markReady(),h!==void 0&&(d=t(h,void 0))),()=>{s=void 0,c=void 0,d?.(),d=void 0,a.clear()})}};return{checkpoints:r,config:o,scope:i=>{e.scopeBy!==void 0&&(h=i,d?.(),d=void 0,s?.(new Map),i!==void 0&&s!==void 0&&(d=t(i,void 0)))}}};export{E as CHECKPOINT_FALLBACK_MS,N as createCheckpointRegistry,K as getShardCheckpoints,x as hasCheckpointsAttached,B as lunoraCollectionOptions,F as markCheckpointsAttached,O as releaseShardCheckpoints,W as shardCheckpointStats};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as h}from"@lunora/errors";import{createTransaction as v}from"@tanstack/db";import{getShardCheckpoints as w,hasCheckpointsAttached as k}from"./CHECKPOINT_FALLBACK_MS-CX7idSTz.mjs";import{runOutboxMutation as C}from"./OUTBOX_MUTATION_FN_NAME-BfFCughR.mjs";const E="__tanstack_db_direct",I="defineMutator: `serverRef` must be a generated mutator reference (api.mutators.*) or a 'namespace:fn' string",T=t=>{const e=typeof t=="string"?t:t?.__lunoraRef;if(typeof e!="string"||e.length===0)throw new h("INTERNAL",I);return e},A=t=>({__lunoraClientMutator:!0,apply:t.apply,serverRef:T(t.serverRef)}),S=(t,e,l)=>{let c=0,u=t.currentIdentity();const d=()=>{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 h("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=w(t,e.shardKey);return k(r)?r:void 0},_=(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{}})},p={};for(const[r,a]of Object.entries(l))p[r]=s=>{const i=v({autoCommit:!0,metadata:{[E]:!0,serverRef:a.serverRef},mutationFn:async()=>{let n=0;await C(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},j=()=>({bindMutators:S,defineMutator:A});export{E as DIRECT_TRANSACTION_METADATA_KEY,S as bindMutators,A as defineMutator,j as initMutators};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createCollection as d,safeRandomUUID as m}from"@tanstack/db";import{NonRetriableError as y}from"@tanstack/offline-transactions";const p=1e3,f="__lunora_outbox__",u=new WeakMap,g=()=>d({getKey:e=>e._id,id:`${f}:${m()}`,startSync:!0,sync:{sync:e=>(e.markReady(),()=>{})}}),h=(e,t)=>{u.set(e,t)};let l=!1;const x=(e,t={})=>{const n=t.maxItems??1e3,a=t.mutationFnName??f;return{enqueue(r){if(e.getPendingCount()>=n){const c=new Error("offline outbox is full");return c.code="OFFLINE_QUEUE_OVERFLOW",Promise.reject(c)}const o={args:r.args,clientId:r.clientId,functionPath:r.functionPath,idempotencyKey:r.idempotencyKey,identity:r.identity,mutationId:r.mutationId,shardKey:r.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 s=e.createOfflineTransaction({autoCommit:!1,idempotencyKey:r.idempotencyKey,metadata:o,mutationFnName:a});return s.mutate(()=>{i?.insert({_id:r.idempotencyKey})}),s.commit?.().catch(()=>{}),Promise.resolve()}}},_=(e,t)=>new Map(e.map(n=>[t(n),n])),I=(e,t)=>n=>{t.begin();const a=new Map;for(const[r,o]of n){const i=JSON.stringify(o);a.set(r,i),e.has(r)?e.get(r)!==i&&t.write({type:"update",value:o}):t.write({type:"insert",value:o})}for(const r of e.keys())n.has(r)||t.write({key:r,type:"delete"});t.commit(),e.clear();for(const[r,o]of a)e.set(r,o)},E=async e=>{try{await e()}catch(t){if(typeof t.code=="string"){const n=new y(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,p);return e.add(n),()=>{clearInterval(n),e.delete(n)}}}};export{f as OUTBOX_MUTATION_FN_NAME,x as createExecutorOutboxSink,k as createOptimisticOnlineDetector,g as createOutboxCarrier,I as makeDiffEmit,h as registerOutboxCarrier,E as runOutboxMutation,_ as toMap};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const s=(o,n)=>{for(const t of n.deletes??[])o[t.table]?.delete(t.id);for(const t of n.patches??[]){const e=o[t.table];e&&e.update(t.id,i=>{Object.assign(i,t.fields)})}for(const t of n.inserts??[]){const e=o[t.table];if(e){if(typeof t.row._id!="string")throw new TypeError(`applyPlanToCollections: insert into "${t.table}" needs an "_id" — mint it client-side so the optimistic row keys match the persisted one`);e.insert(t.row)}}},r=async(o,n)=>{for(const t of n.deletes??[])await o.delete(t.id);for(const t of n.patches??[])await o.patch(t.id,t.fields);for(const t of n.inserts??[]){const{_id:e,...i}=t.row;await o.insert(t.table,i,...typeof e=="string"?[{clientId:e}]:[])}};export{s as applyPlanToCollections,r as applyPlanToDb};
|
|
@@ -344,4 +344,4 @@ interface LunoraCollectionOptions<TRow extends Row> {
|
|
|
344
344
|
* overlays against confirmed server watermarks (see {@link CheckpointRegistry}).
|
|
345
345
|
*/
|
|
346
346
|
declare const lunoraCollectionOptions: <TRow extends Row>(options: LunoraCollectionConfig<TRow>) => LunoraCollectionOptions<TRow>;
|
|
347
|
-
export {
|
|
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, shardCheckpointStats as s, toMap as t };
|
package/dist/packem_shared/{collection-options.d-CmsXU1wV.d.ts → collection-options.d-CspA2N8I.d.ts}
RENAMED
|
@@ -344,4 +344,4 @@ interface LunoraCollectionOptions<TRow extends Row> {
|
|
|
344
344
|
* overlays against confirmed server watermarks (see {@link CheckpointRegistry}).
|
|
345
345
|
*/
|
|
346
346
|
declare const lunoraCollectionOptions: <TRow extends Row>(options: LunoraCollectionConfig<TRow>) => LunoraCollectionOptions<TRow>;
|
|
347
|
-
export {
|
|
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, shardCheckpointStats as s, toMap as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{lunoraCollectionOptions as M}from"./CHECKPOINT_FALLBACK_MS-CX7idSTz.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,7 +1,7 @@
|
|
|
1
|
+
import { R as Row } from "./collection-options.d-CspA2N8I.js";
|
|
1
2
|
import { FunctionReference, SubscriptionError, LunoraClient } from '@lunora/client';
|
|
2
3
|
import { Transaction, Collection } from '@tanstack/db';
|
|
3
4
|
import { OfflineExecutor, StorageDiagnostic } from '@tanstack/offline-transactions';
|
|
4
|
-
import { R as Row } from "./collection-options.d-CmsXU1wV.js";
|
|
5
5
|
/** Element type of an array (the row type a `list` query returns). */
|
|
6
6
|
type Element<T> = T extends ReadonlyArray<infer E> ? E : never;
|
|
7
7
|
/** `true` for the `any` type, `false` otherwise. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { R as Row } from "./collection-options.d-CspA2N8I.mjs";
|
|
1
2
|
import { FunctionReference, SubscriptionError, LunoraClient } from '@lunora/client';
|
|
2
3
|
import { Transaction, Collection } from '@tanstack/db';
|
|
3
4
|
import { OfflineExecutor, StorageDiagnostic } from '@tanstack/offline-transactions';
|
|
4
|
-
import { R as Row } from "./collection-options.d-CmsXU1wV.mjs";
|
|
5
5
|
/** Element type of an array (the row type a `list` query returns). */
|
|
6
6
|
type Element<T> = T extends ReadonlyArray<infer E> ? E : never;
|
|
7
7
|
/** `true` for the `any` type, `false` otherwise. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LunoraClient } from '@lunora/client';
|
|
2
2
|
import { Collection, Transaction } from '@tanstack/db';
|
|
3
|
-
import {
|
|
3
|
+
import { b as CheckpointRegistry } from "./collection-options.d-CspA2N8I.js";
|
|
4
4
|
/**
|
|
5
5
|
* TanStack DB's "direct transaction" marker.
|
|
6
6
|
*
|
|
@@ -232,4 +232,4 @@ interface BoundMutatorApi<TCollections extends CollectionMap> {
|
|
|
232
232
|
* const setText = defineMutator({ apply: ({ collections }, args) => collections.nodes.update(args.id, setter), serverRef: api.mutators.setText });
|
|
233
233
|
*/
|
|
234
234
|
declare const initMutators: <TCollections extends CollectionMap>() => BoundMutatorApi<TCollections>;
|
|
235
|
-
export { BindMutatorsContext as B, ClientMutatorContext as C, DIRECT_TRANSACTION_METADATA_KEY as D,
|
|
235
|
+
export { BindMutatorsContext as B, ClientMutatorContext as C, DIRECT_TRANSACTION_METADATA_KEY as D, MutatorReference as M, BoundMutatorApi as a, BoundMutators as b, ClientMutatorDef as c, CollectionMap as d, MutatorRejectedEvent as e, bindMutators as f, defineMutator as g, initMutators as i };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LunoraClient } from '@lunora/client';
|
|
2
2
|
import { Collection, Transaction } from '@tanstack/db';
|
|
3
|
-
import {
|
|
3
|
+
import { b as CheckpointRegistry } from "./collection-options.d-CspA2N8I.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* TanStack DB's "direct transaction" marker.
|
|
6
6
|
*
|
|
@@ -232,4 +232,4 @@ interface BoundMutatorApi<TCollections extends CollectionMap> {
|
|
|
232
232
|
* const setText = defineMutator({ apply: ({ collections }, args) => collections.nodes.update(args.id, setter), serverRef: api.mutators.setText });
|
|
233
233
|
*/
|
|
234
234
|
declare const initMutators: <TCollections extends CollectionMap>() => BoundMutatorApi<TCollections>;
|
|
235
|
-
export { BindMutatorsContext as B, ClientMutatorContext as C, DIRECT_TRANSACTION_METADATA_KEY as D,
|
|
235
|
+
export { BindMutatorsContext as B, ClientMutatorContext as C, DIRECT_TRANSACTION_METADATA_KEY as D, MutatorReference as M, BoundMutatorApi as a, BoundMutators as b, ClientMutatorDef as c, CollectionMap as d, MutatorRejectedEvent as e, bindMutators as f, defineMutator as g, initMutators as i };
|
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.54",
|
|
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.51",
|
|
58
|
+
"@lunora/errors": "1.0.0-alpha.22"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@tanstack/db": "^0.6.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as y}from"@lunora/errors";import{BTreeIndex as b}from"@tanstack/db";import{toMap as C,makeDiffEmit as T}from"./OUTBOX_MUTATION_FN_NAME-BznV-kE1.mjs";const I=()=>{let e=Number.NEGATIVE_INFINITY;const i=[];return{advance:o=>{if(!(o<=e)){e=o;for(let a=i.length-1;a>=0;a-=1){const n=i[a];n&&n.threshold<=e&&(n.resolve(),i.splice(a,1))}}},await:o=>o<=e?Promise.resolve():new Promise(a=>{i.push({resolve:a,threshold:o})}),passed:o=>o<=e,waiting:()=>i.length}};let g=!1;const M=e=>{g||(g=!0,console.warn(`[@lunora/db] released an optimistic overlay via the ${String(e.waitedMs)}ms checkpoint fallback: the server confirmed ${e.kind} ${String(e.watermark)} but no sync frame ever echoed it. A dropped shape poke or \`settled\` frame is the usual cause — inspect the subscription rather than raising \`fallbackMs\`. (Reported once per process.)`))},m=new WeakMap,w=new WeakSet,N=3e3,S=(e={})=>{const i=e.fallbackMs??N,o=e.onFallback??M,a=I(),n=I();let d=0;const c=new Set,l=(t,s)=>{for(const r of c)r.kind===t&&r.threshold<=s&&(clearTimeout(r.handle),c.delete(r))},p=(t,s)=>{if(i<=0)return;const r=t==="checkpoint"?a:n;if(r.passed(s))return;for(const k of c)if(k.kind===t&&k.threshold>=s)return;const u={handle:setTimeout(()=>{if(c.delete(u),!r.passed(s)){d+=1,r.advance(s);try{o({kind:t,waitedMs:i,watermark:s})}catch{}}},i),kind:t,threshold:s};c.add(u)};return{acknowledge:({checkpoint:t,mutationId:s})=>{t!==void 0&&p("checkpoint",t),s!==void 0&&p("mutationId",s)},awaitCheckpoint:t=>a.await(t),awaitMutationId:t=>n.await(t),dispose:()=>{for(const t of c)clearTimeout(t.handle);c.clear()},resolve:({checkpoint:t,mutationId:s})=>{t!==void 0&&(a.advance(t),l("checkpoint",t)),s!==void 0&&(n.advance(s),l("mutationId",s))},stats:()=>({fallbacks:d,pendingCheckpointWaiters:a.waiting(),pendingMutationWaiters:n.waiting()})}},E=(e,i,o)=>{let a=m.get(e);a||(a=new Map,m.set(e,a));const n=i??"",d=a.get(n);if(d)return d;const c=S(o);return a.set(n,c),c},K=e=>{w.add(e)},x=e=>w.has(e),F=e=>{const i=m.get(e);if(i){for(const o of i.values())o.resolve({checkpoint:Number.POSITIVE_INFINITY,mutationId:Number.POSITIVE_INFINITY}),o.dispose();m.delete(e)}},O=e=>{const i=m.get(e),o={};if(i)for(const[a,n]of i)o[a]=n.stats();return o},P=e=>{if(e.list===void 0==(e.shape===void 0))throw new y("INTERNAL","lunoraCollectionOptions: pass exactly one of `list` or `shape`");const i=e.getKey??(r=>r._id),o=e.checkpoints??E(e.client,e.shape?.shardKey??e.shardKey);K(o);const a=new Map;let n,d,c,l,p;const t=(r,u)=>{const k=h=>{n?.(C(h,i)),u?.(),e.shape===void 0&&(o.resolve({mutationId:p??e.client.confirmedMutationWatermark(e.shardKey)}),p=void 0)},f=h=>c?.(h),v=h=>{h.mutationId!==void 0&&(p=h.mutationId),o.resolve(h)};return e.shape!==void 0?e.client.subscribeShape({args:r,name:e.shape.name},k,{onCheckpoint:v,onError:f,shardKey:e.shape.shardKey}):e.client.subscribe(e.list,r,k,{onCheckpoint:v,onError:f,shardKey:e.shardKey})},s={autoIndex:"eager",defaultIndexType:b,getKey:i,id:e.id??e.list?.__lunoraRef??`shape:${e.shape?.name??""}`,...e.load==="eager"?{startSync:!0}:{},sync:{sync:r=>(n=T(a,r),c=u=>{r.markReady(),e.onError?.(u)},e.scopeBy===void 0?d=t(e.shape?.args??{},()=>{r.markReady()}):(r.markReady(),l!==void 0&&(d=t(l,void 0))),()=>{n=void 0,c=void 0,d?.(),d=void 0,a.clear()})}};return{checkpoints:o,config:s,scope:r=>{e.scopeBy!==void 0&&(l=r,d?.(),d=void 0,n?.(new Map),r!==void 0&&n!==void 0&&(d=t(r,void 0)))}}};export{N as CHECKPOINT_FALLBACK_MS,S as createCheckpointRegistry,E as getShardCheckpoints,x as hasCheckpointsAttached,P as lunoraCollectionOptions,K as markCheckpointsAttached,F as releaseShardCheckpoints,O as shardCheckpointStats};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as p}from"@lunora/errors";import{createTransaction as g}from"@tanstack/db";import{getShardCheckpoints as v,hasCheckpointsAttached as _}from"./CHECKPOINT_FALLBACK_MS-Dxy7C_Up.mjs";import{runOutboxMutation as k}from"./OUTBOX_MUTATION_FN_NAME-BznV-kE1.mjs";const T="__tanstack_db_direct",A="defineMutator: `serverRef` must be a generated mutator reference (api.mutators.*) or a 'namespace:fn' string",E=t=>{const r=typeof t=="string"?t:t?.__lunoraRef;if(typeof r!="string"||r.length===0)throw new p("INTERNAL",A);return r},I=t=>({__lunoraClientMutator:!0,apply:t.apply,serverRef:E(t.serverRef)}),C=(t,r,h)=>{let i=0,u=t.currentIdentity();const f=()=>{const e=t.currentIdentity();e!==u&&(i=0,u=e)},y=()=>(f(),i=Math.max(i,t.confirmedMutationWatermark(r.shardKey))+1,i);let m=Promise.resolve();const R=(e,a)=>{const s=m.then(async()=>{for(let c=0;;c+=1){const o=y();try{const{applied:n}=await t.callMutator(e,a,{clientSeq:o,shardKey:r.shardKey});if(n)return o}catch(n){throw f(),i=t.confirmedMutationWatermark(r.shardKey),n}if(c>=32)throw new p("INTERNAL",`lunora: custom mutator "${e}" could not claim a fresh client sequence after ${String(32)} attempts`)}});return m=s.then(()=>{},()=>{}),s},M=()=>{if(r.checkpoints===!1)return;if(r.checkpoints)return r.checkpoints;const e=v(t,r.shardKey);return _(e)?e:void 0},w=(e,a,s,c)=>{const{onWriteRejected:o}=r;o&&e.isPersisted.promise.catch(n=>{const l=n instanceof Error?n:new Error(String(n));try{o({args:c,code:l.code,error:l,mutator:a,serverRef:s})}catch{}})},d={};for(const[e,a]of Object.entries(h))d[e]=s=>{const c=g({autoCommit:!0,metadata:{[T]:!0,serverRef:a.serverRef},mutationFn:async()=>{let o=0;await k(async()=>{o=await R(a.serverRef,s)});const n=M();n&&(n.acknowledge({mutationId:o}),await n.awaitMutationId(o))}});return c.mutate(()=>{a.apply({collections:r.collections},s)}),w(c,e,a.serverRef,s),c};return d},x=()=>({bindMutators:C,defineMutator:I});export{T as DIRECT_TRANSACTION_METADATA_KEY,C as bindMutators,I as defineMutator,x as initMutators};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createCollection as m,safeRandomUUID as f}from"@tanstack/db";import{NonRetriableError as y}from"@tanstack/offline-transactions";const p=1e3,d="__lunora_outbox__",l=new WeakMap,w=()=>m({getKey:e=>e._id,id:`${d}:${f()}`,startSync:!0,sync:{sync:e=>(e.markReady(),()=>{})}}),x=(e,t)=>{l.set(e,t)};let u=!1;const g=(e,t={})=>{const r=t.maxItems??1e3,a=t.mutationFnName??d;return{enqueue(o){if(e.getPendingCount()>=r){const s=new Error("offline outbox is full");return s.code="OFFLINE_QUEUE_OVERFLOW",Promise.reject(s)}const n={args:o.args,clientId:o.clientId,functionPath:o.functionPath,idempotencyKey:o.idempotencyKey,identity:o.identity,mutationId:o.mutationId,shardKey:o.shardKey},i=l.get(e);!i&&!u&&(u=!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:n,mutationFnName:a});return c.mutate(()=>{i?.insert({_id:o.idempotencyKey})}),c.commit?.().catch(()=>{}),Promise.resolve()}}},h=(e,t)=>new Map(e.map(r=>[t(r),r])),E=(e,t)=>r=>{t.begin();const a=new Map;for(const[o,n]of r){const i=JSON.stringify(n);a.set(o,i),e.has(o)?e.get(o)!==i&&t.write({type:"update",value:n}):t.write({type:"insert",value:n})}for(const o of e.keys())r.has(o)||t.write({key:o,type:"delete"});t.commit(),e.clear();for(const[o,n]of a)e.set(o,n)},_=async e=>{try{await e()}catch(t){if(typeof t.code=="string"){const r=new y(t instanceof Error?t.message:String(t));throw r.code=t.code,r}throw t}},I=()=>{const e=new Set;return{dispose:()=>{for(const t of e)clearInterval(t);e.clear()},isOnline:()=>!0,notifyOnline:()=>{},subscribe:t=>{const r=setInterval(t,p);return e.add(r),()=>{clearInterval(r),e.delete(r)}}}};export{d as OUTBOX_MUTATION_FN_NAME,g as createExecutorOutboxSink,I as createOptimisticOnlineDetector,w as createOutboxCarrier,E as makeDiffEmit,x as registerOutboxCarrier,_ as runOutboxMutation,h as toMap};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const n=(o,s)=>{for(const t of s.deletes??[])o[t.table]?.delete(t.id);for(const t of s.patches??[]){const e=o[t.table];e&&e.update(t.id,i=>{Object.assign(i,t.fields)})}for(const t of s.inserts??[]){const e=o[t.table];if(e){if(typeof t.row._id!="string")throw new TypeError(`applyPlanToCollections: insert into "${t.table}" needs an "_id" — mint it client-side so the optimistic row keys match the persisted one`);e.insert(t.row)}}},a=async(o,s)=>{for(const t of s.deletes??[])await o.delete(t.id);for(const t of s.patches??[])await o.patch(t.id,t.fields);for(const t of s.inserts??[]){const{_id:e,...i}=t.row;await o.insert(t.table,i,...typeof e=="string"?[{clientId:e}]:[])}};export{n as applyPlanToCollections,a as applyPlanToDb};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createCollection as M,safeRandomUUID as v}from"@tanstack/db";import{startOfflineExecutor as E,NonRetriableError as O}from"@tanstack/offline-transactions";import{lunoraCollectionOptions as R}from"./CHECKPOINT_FALLBACK_MS-Dxy7C_Up.mjs";import{createOutboxCarrier as U,createOptimisticOnlineDetector as _,OUTBOX_MUTATION_FN_NAME as C,registerOutboxCarrier as A,runOutboxMutation as x}from"./OUTBOX_MUTATION_FN_NAME-BznV-kE1.mjs";const N=new WeakMap,I=(n,c)=>{let o=N.get(n);o===void 0&&(o=new Map,N.set(n,o));const i=o.get(c)??0;o.set(c,i+1),i===1&&console.warn(`[@lunora/db] table "${c}" is bound by more than one defineCollections call on this client. Each call creates its own live collection and outbox for the table, so the two can drift and derived indexes built from one can silently read stale rows. Bind every table in a single defineCollections call (see the "One source of truth per table" docs section).`)},D=(n,c,o={})=>{const i={},y={},f={},h=Object.entries(c);for(const[t,e]of h){const r=e.insert;I(n,t);const{config:l,scope:m}=R({client:n,getKey:e.getKey,id:t,list:e.list,...e.load===void 0?{}:{load:e.load},onError:e.onError,scopeBy:e.scopeBy,shardKey:e.shardKey});i[t]=M(l),e.scopeBy!==void 0&&(y[t]=m),r&&(f[t]=async({idempotencyKey:s,transaction:a})=>{for(const[p,K]of a.mutations.entries()){const b=K.modified,F=`${s}:${String(p)}`;try{await x(()=>n.mutation(r.mutation,r.toArgs(b),{mutationId:F}))}catch(u){if(u instanceof O&&o.onWriteRejected)try{o.onWriteRejected({code:u.code,collection:t,error:u,row:b})}catch{}throw u}}})}f[C]=async({transaction:t})=>{const e=t.metadata;if(e){if(e.identity!==n.currentIdentity())throw new O("outbox write dropped: identity changed since it was queued");await x(()=>n.mutation({__lunoraRef:e.functionPath},e.args,{mutationId:e.idempotencyKey,shardKey:e.shardKey}))}};const g=U(),d=E({collections:{...i,[C]:g},mutationFns:f,onlineDetector:_(),...o.onLeadershipChange?{onLeadershipChange:o.onLeadershipChange}:{},...o.onStorageFailure?{onStorageFailure:o.onStorageFailure}:{},onUnknownMutationFn:(t,e)=>{try{o.onWriteRejected?.({code:"UNKNOWN_MUTATION_FN",collection:t,error:new Error(`offline write dropped: mutation "${t}" no longer exists (removed or renamed in a deploy?)`),row:e.mutations[0]?.modified})}catch{}}});A(d,g);const w={};for(const[t,e]of h){const r=e.insert,l=i[t];if(!r||!l)continue;const m=d.createOfflineAction({mutationFnName:t,onMutate:({id:s,input:a})=>{l.insert(r.optimistic(a,s))}});w[t]=s=>{const a=v(),p=m({id:a,input:s});return{id:a,transaction:p}}}return{actions:w,collections:i,executor:d,pendingCount:()=>d.getPendingCount(),scope:y}};export{D as defineCollections};
|