cry-synced-db-client 0.1.144 → 0.1.145

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/CHANGELOG.md CHANGED
@@ -108,6 +108,37 @@ Signature is identical. No other callback changes.
108
108
  - Noop when offline or on writeOnly collections.
109
109
  - Ignored on `find` / `findOne` (use `referToServer` there).
110
110
 
111
+ ## 0.1.145 (2026-04-25)
112
+
113
+ ### Fix: `onSyncProgress` back-track during initial sync
114
+
115
+ `onSyncProgress` is fired from two distinct phases that can run **concurrently**
116
+ during initial sync — Dexie → in-mem hydration (`SyncedDb.loadCollectionsToInMem`)
117
+ and server → Dexie download (`SyncEngine.findNewerManyStream`). Each phase
118
+ carries its own `loaded`/`total`, so consumers wiring the callback into a single
119
+ progress bar saw the percentage back-track every time a tick from the other
120
+ phase arrived (e.g. dexie 9/58 → server 1/62 → dexie 10/58 → server 2/62 …).
121
+
122
+ The payload now carries a `phase: 'dexie' | 'server'` discriminator so consumers
123
+ can attribute each tick to its source and either filter or render the two
124
+ streams separately. **Non-breaking**: consumers that destructure
125
+ `{ collection, loaded, total }` and ignore `phase` keep working unchanged.
126
+
127
+ Type change in `I_SyncedDb.SyncedDbConfig` and internal `SyncEngineCallbacks`:
128
+ ```ts
129
+ onSyncProgress?: (info: {
130
+ phase: 'dexie' | 'server';
131
+ collection: string;
132
+ loaded: number;
133
+ total: number;
134
+ items: number;
135
+ }) => void;
136
+ ```
137
+
138
+ The JSDoc on `onSyncProgress` previously claimed "Fires only during
139
+ init/setSyncOnlyTheseCollections" — that was wrong; it also fires during server
140
+ sync. Doc corrected.
141
+
111
142
  ## 0.1.136 (2026-04-20)
112
143
 
113
144
  - `DexieDb.saveMany` is now fail-safe:
package/dist/index.js CHANGED
@@ -2502,6 +2502,7 @@ var _SyncEngine = class _SyncEngine {
2502
2502
  if (!completedCollections.has(collection)) {
2503
2503
  completedCollections.add(collection);
2504
2504
  this.callbackSafe(this.callbacks.onSyncProgress, {
2505
+ phase: "server",
2505
2506
  collection,
2506
2507
  loaded: completedCollections.size,
2507
2508
  total: syncSpecs.length,
@@ -4983,6 +4984,7 @@ var _SyncedDb = class _SyncedDb {
4983
4984
  totalItems += items;
4984
4985
  loaded++;
4985
4986
  this.safeCallback(this.onSyncProgress, {
4987
+ phase: "dexie",
4986
4988
  collection: name,
4987
4989
  loaded,
4988
4990
  total: names.length,
@@ -235,6 +235,7 @@ export interface SyncEngineCallbacks {
235
235
  }) => void;
236
236
  onSyncEnd?: (info: SyncInfo) => void;
237
237
  onSyncProgress?: (info: {
238
+ phase: 'dexie' | 'server';
238
239
  collection: string;
239
240
  loaded: number;
240
241
  total: number;
@@ -345,8 +345,15 @@ export interface SyncedDbConfig {
345
345
  totalItems: number;
346
346
  durationMs: number;
347
347
  }) => void;
348
- /** Callback after each collection is loaded during full sync (Dexie→inMem). Fires only during init/setSyncOnlyTheseCollections. */
348
+ /**
349
+ * Callback after each collection completes loading. Fires from two distinct phases that can run
350
+ * concurrently — `phase` discriminates the source so consumers can render progress coherently:
351
+ * - `'dexie'` — Dexie → in-memory hydration during init/setSyncOnlyTheseCollections
352
+ * - `'server'` — server → Dexie download during full/initial sync (findNewerManyStream)
353
+ * `loaded`/`total` are scoped to the phase that emitted the event.
354
+ */
349
355
  onSyncProgress?: (info: {
356
+ phase: 'dexie' | 'server';
350
357
  collection: string;
351
358
  loaded: number;
352
359
  total: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.144",
3
+ "version": "0.1.145",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",