@lunora/db 1.0.0-alpha.5 → 1.0.0-alpha.6

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.
@@ -1,5 +1,5 @@
1
- export { type C as CheckpointRegistry, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, c as createCheckpointRegistry, l as lunoraCollectionOptions } from "../packem_shared/collection-options.d-B3YaP49K.mjs";
2
- export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/define-collections.d-L5DVcLnj.mjs";
1
+ export { type C as CheckpointRegistry, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, c as createCheckpointRegistry, l as lunoraCollectionOptions } from "../packem_shared/collection-options.d-CbS3J_Fm.mjs";
2
+ export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/define-collections.d-DTS0ANuU.mjs";
3
3
  import '@lunora/client';
4
4
  import '@tanstack/db';
5
5
  import '@tanstack/offline-transactions';
@@ -1,5 +1,5 @@
1
- export { type C as CheckpointRegistry, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, c as createCheckpointRegistry, l as lunoraCollectionOptions } from "../packem_shared/collection-options.d-B3YaP49K.js";
2
- export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/define-collections.d-DKc3vPUv.js";
1
+ export { type C as CheckpointRegistry, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, c as createCheckpointRegistry, l as lunoraCollectionOptions } from "../packem_shared/collection-options.d-CbS3J_Fm.js";
2
+ export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "../packem_shared/define-collections.d-Po97lX6i.js";
3
3
  import '@lunora/client';
4
4
  import '@tanstack/db';
5
5
  import '@tanstack/offline-transactions';
@@ -1,2 +1,2 @@
1
- export { createCheckpointRegistry, lunoraCollectionOptions } from '../packem_shared/createCheckpointRegistry-CR_q270X.mjs';
2
- export { defineCollections } from '../packem_shared/defineCollections-it3wN-49.mjs';
1
+ export { createCheckpointRegistry, lunoraCollectionOptions } from '../packem_shared/createCheckpointRegistry-DztP2nI8.mjs';
2
+ export { defineCollections } from '../packem_shared/defineCollections-oL1qzsWE.mjs';
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- export { type C as CheckpointRegistry, type E as ExecutorOutboxSinkOptions, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, O as OUTBOX_MUTATION_FN_NAME, type b as OutboxExecutor, type d as OutboxMutationMetadata, type R as Row, type S as SyncWriter, c as createCheckpointRegistry, e as createExecutorOutboxSink, f as createOptimisticOnlineDetector, l as lunoraCollectionOptions, m as makeDiffEmit, r as runOutboxMutation, t as toMap } from "./packem_shared/collection-options.d-B3YaP49K.mjs";
2
- export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "./packem_shared/define-collections.d-L5DVcLnj.mjs";
3
- export { type B as BindMutatorsContext, type a as BoundMutators, type C as ClientMutatorContext, type b as ClientMutatorDef, c as bindMutators, d as defineMutator } from "./packem_shared/define-mutators.d-Bqd-o1Zp.mjs";
1
+ export { type C as CheckpointRegistry, type E as ExecutorOutboxSinkOptions, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, O as OUTBOX_MUTATION_FN_NAME, type b as OutboxExecutor, type d as OutboxMutationMetadata, type R as Row, type S as SyncWriter, c as createCheckpointRegistry, e as createExecutorOutboxSink, f as createOptimisticOnlineDetector, l as lunoraCollectionOptions, m as makeDiffEmit, r as runOutboxMutation, t as toMap } from "./packem_shared/collection-options.d-CbS3J_Fm.mjs";
2
+ export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "./packem_shared/define-collections.d-DTS0ANuU.mjs";
3
+ export { type B as BindMutatorsContext, type a as BoundMutators, type C as ClientMutatorContext, type b as ClientMutatorDef, c as bindMutators, d as defineMutator } from "./packem_shared/define-mutators.d-DNVJIpW8.mjs";
4
4
  import '@lunora/client';
5
5
  import '@tanstack/db';
6
6
  import '@tanstack/offline-transactions';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { type C as CheckpointRegistry, type E as ExecutorOutboxSinkOptions, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, O as OUTBOX_MUTATION_FN_NAME, type b as OutboxExecutor, type d as OutboxMutationMetadata, type R as Row, type S as SyncWriter, c as createCheckpointRegistry, e as createExecutorOutboxSink, f as createOptimisticOnlineDetector, l as lunoraCollectionOptions, m as makeDiffEmit, r as runOutboxMutation, t as toMap } from "./packem_shared/collection-options.d-B3YaP49K.js";
2
- export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "./packem_shared/define-collections.d-DKc3vPUv.js";
3
- export { type B as BindMutatorsContext, type a as BoundMutators, type C as ClientMutatorContext, type b as ClientMutatorDef, c as bindMutators, d as defineMutator } from "./packem_shared/define-mutators.d-BqsA6_pd.js";
1
+ export { type C as CheckpointRegistry, type E as ExecutorOutboxSinkOptions, type L as LunoraCollectionConfig, type a as LunoraCollectionOptions, O as OUTBOX_MUTATION_FN_NAME, type b as OutboxExecutor, type d as OutboxMutationMetadata, type R as Row, type S as SyncWriter, c as createCheckpointRegistry, e as createExecutorOutboxSink, f as createOptimisticOnlineDetector, l as lunoraCollectionOptions, m as makeDiffEmit, r as runOutboxMutation, t as toMap } from "./packem_shared/collection-options.d-CbS3J_Fm.js";
2
+ export { type C as CollectionDef, type I as InsertBinding, type L as LunoraDb, d as defineCollections } from "./packem_shared/define-collections.d-Po97lX6i.js";
3
+ export { type B as BindMutatorsContext, type a as BoundMutators, type C as ClientMutatorContext, type b as ClientMutatorDef, c as bindMutators, d as defineMutator } from "./packem_shared/define-mutators.d-C3DO284A.js";
4
4
  import '@lunora/client';
5
5
  import '@tanstack/db';
6
6
  import '@tanstack/offline-transactions';
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- export { createCheckpointRegistry, lunoraCollectionOptions } from './packem_shared/createCheckpointRegistry-CR_q270X.mjs';
2
- export { defineCollections } from './packem_shared/defineCollections-it3wN-49.mjs';
3
- export { bindMutators, defineMutator } from './packem_shared/bindMutators-DWGJhyt3.mjs';
4
- export { OUTBOX_MUTATION_FN_NAME, createExecutorOutboxSink, createOptimisticOnlineDetector, makeDiffEmit, runOutboxMutation, toMap } from './packem_shared/OUTBOX_MUTATION_FN_NAME-3cxtwP39.mjs';
1
+ export { createCheckpointRegistry, lunoraCollectionOptions } from './packem_shared/createCheckpointRegistry-DztP2nI8.mjs';
2
+ export { defineCollections } from './packem_shared/defineCollections-oL1qzsWE.mjs';
3
+ export { bindMutators, defineMutator } from './packem_shared/bindMutators-Bh6giR9x.mjs';
4
+ export { OUTBOX_MUTATION_FN_NAME, createExecutorOutboxSink, createOptimisticOnlineDetector, makeDiffEmit, runOutboxMutation, toMap } from './packem_shared/OUTBOX_MUTATION_FN_NAME-DZrP1gna.mjs';
5
5
 
6
6
  const VERSION = "0.0.0";
7
7
 
@@ -1,5 +1,5 @@
1
- export { type B as BindMutatorsContext, type a as BoundMutators, type C as ClientMutatorContext, type b as ClientMutatorDef, c as bindMutators, d as defineMutator } from "../packem_shared/define-mutators.d-Bqd-o1Zp.mjs";
1
+ export { type B as BindMutatorsContext, type a as BoundMutators, type C as ClientMutatorContext, type b as ClientMutatorDef, c as bindMutators, d as defineMutator } from "../packem_shared/define-mutators.d-DNVJIpW8.mjs";
2
2
  import '@lunora/client';
3
3
  import '@tanstack/db';
4
- import "../packem_shared/collection-options.d-B3YaP49K.mjs";
4
+ import "../packem_shared/collection-options.d-CbS3J_Fm.mjs";
5
5
  import '@tanstack/offline-transactions';
@@ -1,5 +1,5 @@
1
- export { type B as BindMutatorsContext, type a as BoundMutators, type C as ClientMutatorContext, type b as ClientMutatorDef, c as bindMutators, d as defineMutator } from "../packem_shared/define-mutators.d-BqsA6_pd.js";
1
+ export { type B as BindMutatorsContext, type a as BoundMutators, type C as ClientMutatorContext, type b as ClientMutatorDef, c as bindMutators, d as defineMutator } from "../packem_shared/define-mutators.d-C3DO284A.js";
2
2
  import '@lunora/client';
3
3
  import '@tanstack/db';
4
- import "../packem_shared/collection-options.d-B3YaP49K.js";
4
+ import "../packem_shared/collection-options.d-CbS3J_Fm.js";
5
5
  import '@tanstack/offline-transactions';
@@ -1 +1 @@
1
- export { bindMutators, defineMutator } from '../packem_shared/bindMutators-DWGJhyt3.mjs';
1
+ export { bindMutators, defineMutator } from '../packem_shared/bindMutators-Bh6giR9x.mjs';
@@ -41,25 +41,27 @@ const toMap = (rows, getKey) => {
41
41
  }
42
42
  return map;
43
43
  };
44
- const makeDiffEmit = (synced, writer) => (next) => {
44
+ const makeDiffEmit = (syncedJson, writer) => (next) => {
45
45
  writer.begin();
46
+ const nextJson = /* @__PURE__ */ new Map();
46
47
  for (const [key, value] of next) {
47
- const previous = synced.get(key);
48
- if (previous === void 0) {
48
+ const valueJson = JSON.stringify(value);
49
+ nextJson.set(key, valueJson);
50
+ if (!syncedJson.has(key)) {
49
51
  writer.write({ type: "insert", value });
50
- } else if (JSON.stringify(previous) !== JSON.stringify(value)) {
52
+ } else if (syncedJson.get(key) !== valueJson) {
51
53
  writer.write({ type: "update", value });
52
54
  }
53
55
  }
54
- for (const key of synced.keys()) {
56
+ for (const key of syncedJson.keys()) {
55
57
  if (!next.has(key)) {
56
58
  writer.write({ key, type: "delete" });
57
59
  }
58
60
  }
59
61
  writer.commit();
60
- synced.clear();
61
- for (const [key, value] of next) {
62
- synced.set(key, value);
62
+ syncedJson.clear();
63
+ for (const [key, valueJson] of nextJson) {
64
+ syncedJson.set(key, valueJson);
63
65
  }
64
66
  };
65
67
  const runOutboxMutation = async (mutate) => {
@@ -1,5 +1,5 @@
1
1
  import { createTransaction } from '@tanstack/db';
2
- import { runOutboxMutation } from './OUTBOX_MUTATION_FN_NAME-3cxtwP39.mjs';
2
+ import { runOutboxMutation } from './OUTBOX_MUTATION_FN_NAME-DZrP1gna.mjs';
3
3
 
4
4
  const defineMutator = (definition) => {
5
5
  return {
@@ -83,14 +83,25 @@ declare const toMap: <T extends object>(rows: ReadonlyArray<T>, getKey: (row: T)
83
83
  * Build an `emit(next)` that diffs a desired keyed snapshot into a collection's
84
84
  * sync channel — only changed rows are written, so a reconnect snapshot or a
85
85
  * scope change never churns the synced view out from under a pending optimistic
86
- * row. The last-synced base is tracked in `synced`.
86
+ * row. The last-synced base is tracked in `syncedJson`.
87
87
  *
88
88
  * Change detection compares rows by `JSON.stringify`, which is key-order
89
- * sensitive — safe here because `synced` only ever holds server snapshots, whose
90
- * column order is stable across reconnects (same query projection). A sync source
91
- * with unstable key ordering would need a structural compare instead.
89
+ * sensitive — safe here because server snapshots have stable column order
90
+ * across reconnects (same query projection). A sync source with unstable key
91
+ * ordering would need a structural compare instead.
92
+ *
93
+ * `syncedJson` holds the JSON-serialized form of each last-synced row, keyed
94
+ * by row id. It is the **sole** synced-state map — no parallel row-object map
95
+ * is kept. Each incoming value is serialized exactly once per tick (for both
96
+ * comparison and cache update), so the previous value is never re-serialized.
97
+ *
98
+ * Lifecycle: `syncedJson` must be owned by the caller at the same scope as any
99
+ * other per-collection state (e.g. outside the `sync.sync` callback), so the
100
+ * cache persists correctly across sync restarts. A new `makeDiffEmit` closure
101
+ * created on restart receives the same map reference and starts from the
102
+ * committed synced state — no spurious diffs on reconnect.
92
103
  */
93
- declare const makeDiffEmit: <T extends object>(synced: Map<string, T>, writer: SyncWriter<T>) => (next: Map<string, T>) => void;
104
+ declare const makeDiffEmit: <T extends object>(syncedJson: Map<string, string>, writer: SyncWriter<T>) => (next: Map<string, T>) => void;
94
105
  /**
95
106
  * Run a Lunora mutation under the outbox's retry policy.
96
107
  *
@@ -83,14 +83,25 @@ declare const toMap: <T extends object>(rows: ReadonlyArray<T>, getKey: (row: T)
83
83
  * Build an `emit(next)` that diffs a desired keyed snapshot into a collection's
84
84
  * sync channel — only changed rows are written, so a reconnect snapshot or a
85
85
  * scope change never churns the synced view out from under a pending optimistic
86
- * row. The last-synced base is tracked in `synced`.
86
+ * row. The last-synced base is tracked in `syncedJson`.
87
87
  *
88
88
  * Change detection compares rows by `JSON.stringify`, which is key-order
89
- * sensitive — safe here because `synced` only ever holds server snapshots, whose
90
- * column order is stable across reconnects (same query projection). A sync source
91
- * with unstable key ordering would need a structural compare instead.
89
+ * sensitive — safe here because server snapshots have stable column order
90
+ * across reconnects (same query projection). A sync source with unstable key
91
+ * ordering would need a structural compare instead.
92
+ *
93
+ * `syncedJson` holds the JSON-serialized form of each last-synced row, keyed
94
+ * by row id. It is the **sole** synced-state map — no parallel row-object map
95
+ * is kept. Each incoming value is serialized exactly once per tick (for both
96
+ * comparison and cache update), so the previous value is never re-serialized.
97
+ *
98
+ * Lifecycle: `syncedJson` must be owned by the caller at the same scope as any
99
+ * other per-collection state (e.g. outside the `sync.sync` callback), so the
100
+ * cache persists correctly across sync restarts. A new `makeDiffEmit` closure
101
+ * created on restart receives the same map reference and starts from the
102
+ * committed synced state — no spurious diffs on reconnect.
92
103
  */
93
- declare const makeDiffEmit: <T extends object>(synced: Map<string, T>, writer: SyncWriter<T>) => (next: Map<string, T>) => void;
104
+ declare const makeDiffEmit: <T extends object>(syncedJson: Map<string, string>, writer: SyncWriter<T>) => (next: Map<string, T>) => void;
94
105
  /**
95
106
  * Run a Lunora mutation under the outbox's retry policy.
96
107
  *
@@ -1,5 +1,5 @@
1
1
  import { BTreeIndex } from '@tanstack/db';
2
- import { toMap, makeDiffEmit } from './OUTBOX_MUTATION_FN_NAME-3cxtwP39.mjs';
2
+ import { toMap, makeDiffEmit } from './OUTBOX_MUTATION_FN_NAME-DZrP1gna.mjs';
3
3
 
4
4
  const createGate = () => {
5
5
  let highest = Number.NEGATIVE_INFINITY;
@@ -50,7 +50,7 @@ const lunoraCollectionOptions = (options) => {
50
50
  }
51
51
  const getKey = options.getKey ?? ((row) => row._id);
52
52
  const checkpoints = createCheckpointRegistry();
53
- const synced = /* @__PURE__ */ new Map();
53
+ const syncedJson = /* @__PURE__ */ new Map();
54
54
  let emit;
55
55
  let unsubscribe;
56
56
  let onErrorHandler;
@@ -85,7 +85,7 @@ const lunoraCollectionOptions = (options) => {
85
85
  id: options.id ?? options.list?.__lunoraRef ?? `shape:${options.shape?.name ?? ""}`,
86
86
  sync: {
87
87
  sync: (writer) => {
88
- emit = makeDiffEmit(synced, writer);
88
+ emit = makeDiffEmit(syncedJson, writer);
89
89
  const onError = (error) => {
90
90
  writer.markReady();
91
91
  options.onError?.(error);
@@ -1,7 +1,7 @@
1
1
  import { FunctionReference, SubscriptionError, LunoraClient } from '@lunora/client';
2
2
  import { Transaction, Collection } from '@tanstack/db';
3
3
  import { OfflineExecutor } from '@tanstack/offline-transactions';
4
- import { R as Row } from "./collection-options.d-B3YaP49K.mjs";
4
+ import { R as Row } from "./collection-options.d-CbS3J_Fm.mjs";
5
5
  /** Element type of an array (the row type a `list` query returns). */
6
6
  type Element<T> = T extends ReadonlyArray<infer E> ? E : never;
7
7
  /** `true` for the `any` type, `false` otherwise. */
@@ -1,7 +1,7 @@
1
1
  import { FunctionReference, SubscriptionError, LunoraClient } from '@lunora/client';
2
2
  import { Transaction, Collection } from '@tanstack/db';
3
3
  import { OfflineExecutor } from '@tanstack/offline-transactions';
4
- import { R as Row } from "./collection-options.d-B3YaP49K.js";
4
+ import { R as Row } from "./collection-options.d-CbS3J_Fm.js";
5
5
  /** Element type of an array (the row type a `list` query returns). */
6
6
  type Element<T> = T extends ReadonlyArray<infer E> ? E : never;
7
7
  /** `true` for the `any` type, `false` otherwise. */
@@ -1,6 +1,6 @@
1
1
  import { LunoraClient } from '@lunora/client';
2
2
  import { Collection, Transaction } from '@tanstack/db';
3
- import { C as CheckpointRegistry, R as Row } from "./collection-options.d-B3YaP49K.js";
3
+ import { C as CheckpointRegistry, R as Row } from "./collection-options.d-CbS3J_Fm.js";
4
4
  /** The local store a client mutator's optimistic body writes against. */
5
5
  interface ClientMutatorContext {
6
6
  /** The wired collections, keyed by name — apply optimistic inserts/updates/deletes here. */
@@ -1,6 +1,6 @@
1
1
  import { LunoraClient } from '@lunora/client';
2
2
  import { Collection, Transaction } from '@tanstack/db';
3
- import { C as CheckpointRegistry, R as Row } from "./collection-options.d-B3YaP49K.mjs";
3
+ import { C as CheckpointRegistry, R as Row } from "./collection-options.d-CbS3J_Fm.mjs";
4
4
  /** The local store a client mutator's optimistic body writes against. */
5
5
  interface ClientMutatorContext {
6
6
  /** The wired collections, keyed by name — apply optimistic inserts/updates/deletes here. */
@@ -1,7 +1,7 @@
1
1
  import { createCollection } from '@tanstack/db';
2
2
  import { startOfflineExecutor, NonRetriableError } from '@tanstack/offline-transactions';
3
- import { lunoraCollectionOptions } from './createCheckpointRegistry-CR_q270X.mjs';
4
- import { createOptimisticOnlineDetector, runOutboxMutation, OUTBOX_MUTATION_FN_NAME } from './OUTBOX_MUTATION_FN_NAME-3cxtwP39.mjs';
3
+ import { lunoraCollectionOptions } from './createCheckpointRegistry-DztP2nI8.mjs';
4
+ import { createOptimisticOnlineDetector, runOutboxMutation, OUTBOX_MUTATION_FN_NAME } from './OUTBOX_MUTATION_FN_NAME-DZrP1gna.mjs';
5
5
 
6
6
  const defineCollections = (client, defs) => {
7
7
  const collections = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/db",
3
- "version": "1.0.0-alpha.5",
3
+ "version": "1.0.0-alpha.6",
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.5"
57
+ "@lunora/client": "1.0.0-alpha.6"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@tanstack/db": "^0.6.0",