cry-synced-db-client 0.1.212 → 0.1.214

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/index.js CHANGED
@@ -3192,8 +3192,9 @@ function stripServerManagedFromChanges(changes) {
3192
3192
 
3193
3193
  // src/db/sync/SyncEngine.ts
3194
3194
  var SUPRESS_DB_WARNINGS = true;
3195
- var _SyncEngine = class _SyncEngine {
3195
+ var SyncEngine = class {
3196
3196
  constructor(config) {
3197
+ var _a;
3197
3198
  this.tenant = config.tenant;
3198
3199
  this.collections = config.collections;
3199
3200
  this.dexieDb = config.dexieDb;
@@ -3201,6 +3202,7 @@ var _SyncEngine = class _SyncEngine {
3201
3202
  this.callbacks = config.callbacks;
3202
3203
  this.deps = config.deps;
3203
3204
  this.preprocessDirtyItem = config.preprocessDirtyItem;
3205
+ this.syncBatchSize = (_a = config.syncBatchSize) != null ? _a : 5e3;
3204
3206
  }
3205
3207
  /**
3206
3208
  * Execute full sync cycle.
@@ -3219,6 +3221,7 @@ var _SyncEngine = class _SyncEngine {
3219
3221
  let conflictsResolved = 0;
3220
3222
  const collectionStats = {};
3221
3223
  this.callOnSyncStart({ calledFrom, initialSync: false });
3224
+ const _perCollectionItems = /* @__PURE__ */ new Map();
3222
3225
  try {
3223
3226
  this.deps.cancelRestUploadTimer();
3224
3227
  await this.deps.awaitRestUpload();
@@ -3297,12 +3300,14 @@ var _SyncEngine = class _SyncEngine {
3297
3300
  if (!config) return;
3298
3301
  const state = collectionState.get(collection);
3299
3302
  state.receivedCount += items.length;
3303
+ const _tProcess = performance.now();
3300
3304
  const stats = await this.processIncomingServerData(
3301
3305
  collection,
3302
3306
  config,
3303
3307
  items,
3304
3308
  state.source
3305
3309
  );
3310
+ const _processingMs = performance.now() - _tProcess;
3306
3311
  state.conflicts += stats.conflictsResolved;
3307
3312
  if (stats.maxTs) {
3308
3313
  if (!state.maxTs || this.compareTimestamps(stats.maxTs, state.maxTs) > 0) {
@@ -3312,16 +3317,24 @@ var _SyncEngine = class _SyncEngine {
3312
3317
  if (stats.updatedIds.length > 0) {
3313
3318
  this.deps.broadcastUpdates({ [collection]: stats.updatedIds });
3314
3319
  }
3315
- if (!completedCollections.has(collection)) {
3320
+ const isNewColl = !completedCollections.has(collection);
3321
+ if (isNewColl) {
3316
3322
  completedCollections.add(collection);
3317
- this.callbackSafe(this.callbacks.onSyncProgress, {
3318
- phase: "server",
3319
- collection,
3320
- loaded: completedCollections.size,
3321
- total: syncSpecs.length,
3322
- items: items.length
3323
- });
3324
3323
  }
3324
+ _perCollectionItems.set(
3325
+ collection,
3326
+ (_perCollectionItems.get(collection) || 0) + items.length
3327
+ );
3328
+ this.callbackSafe(this.callbacks.onSyncProgress, {
3329
+ phase: "server",
3330
+ collection,
3331
+ loaded: completedCollections.size,
3332
+ total: syncSpecs.length,
3333
+ items: items.length,
3334
+ itemsCumulative: _perCollectionItems.get(collection),
3335
+ isNewCollection: isNewColl,
3336
+ processingMs: Math.round(_processingMs)
3337
+ });
3325
3338
  },
3326
3339
  {
3327
3340
  onRequestBytes: (bytes) => {
@@ -4141,12 +4154,14 @@ var _SyncEngine = class _SyncEngine {
4141
4154
  }
4142
4155
  async processIncomingServerData(collectionName, config, serverData, source = "incremental") {
4143
4156
  if (serverData.length === 0) {
4144
- return { conflictsResolved: 0, maxTs: void 0, updatedIds: [] };
4157
+ return { conflictsResolved: 0, maxTs: void 0, updatedIds: [], dexieMs: 0, inMemMs: 0 };
4145
4158
  }
4146
4159
  let maxTs;
4147
4160
  let conflictsResolved = 0;
4161
+ let totalDexieMs = 0;
4162
+ let totalInMemMs = 0;
4148
4163
  const allUpdatedIds = [];
4149
- const BATCH = _SyncEngine.SYNC_BATCH_SIZE;
4164
+ const BATCH = this.syncBatchSize;
4150
4165
  for (let offset = 0; offset < serverData.length; offset += BATCH) {
4151
4166
  const chunk = serverData.slice(offset, offset + BATCH);
4152
4167
  const chunkIds = [];
@@ -4203,13 +4218,22 @@ var _SyncEngine = class _SyncEngine {
4203
4218
  }
4204
4219
  }
4205
4220
  }
4221
+ let _timingDexieMs = 0;
4222
+ let _timingInMemMs = 0;
4206
4223
  if (dexieBatch.length > 0) {
4224
+ const _t0 = performance.now();
4207
4225
  await this.dexieDb.saveMany(collectionName, dexieBatch);
4226
+ _timingDexieMs = performance.now() - _t0;
4227
+ totalDexieMs += _timingDexieMs;
4208
4228
  }
4209
4229
  if (inMemSaveBatch.length > 0) {
4230
+ const _t1 = performance.now();
4210
4231
  this.deps.writeToInMemBatch(collectionName, inMemSaveBatch, "upsert", {
4211
4232
  source
4212
4233
  });
4234
+ const _inMemMs = performance.now() - _t1;
4235
+ _timingInMemMs += _inMemMs;
4236
+ totalInMemMs += _inMemMs;
4213
4237
  }
4214
4238
  if (inMemDeleteIds.length > 0) {
4215
4239
  this.deps.writeToInMemBatch(
@@ -4228,7 +4252,7 @@ var _SyncEngine = class _SyncEngine {
4228
4252
  lastSyncTs: maxTs
4229
4253
  });
4230
4254
  }
4231
- return { conflictsResolved, maxTs, updatedIds: allUpdatedIds };
4255
+ return { conflictsResolved, maxTs, updatedIds: allUpdatedIds, dexieMs: totalDexieMs, inMemMs: totalInMemMs };
4232
4256
  }
4233
4257
  // ============================================================
4234
4258
  // Private Helpers
@@ -4414,12 +4438,6 @@ var _SyncEngine = class _SyncEngine {
4414
4438
  }
4415
4439
  }
4416
4440
  };
4417
- // ============================================================
4418
- // Private: Process Incoming Data
4419
- // ============================================================
4420
- /** Max items to process per batch in processIncomingServerData */
4421
- _SyncEngine.SYNC_BATCH_SIZE = 2e3;
4422
- var SyncEngine = _SyncEngine;
4423
4441
 
4424
4442
  // src/db/sync/ServerUpdateHandler.ts
4425
4443
  var ServerUpdateHandler = class {
@@ -5057,6 +5075,7 @@ var _SyncedDb = class _SyncedDb {
5057
5075
  }
5058
5076
  });
5059
5077
  this.syncEngine = new SyncEngine({
5078
+ syncBatchSize: config.syncBatchSize,
5060
5079
  tenant: this.tenant,
5061
5080
  updaterId: this.updaterId,
5062
5081
  collections: this.collections,
@@ -75,8 +75,7 @@ export declare class SyncEngine implements I_SyncEngine {
75
75
  }): Promise<{
76
76
  updatedIds: string[];
77
77
  }>;
78
- /** Max items to process per batch in processIncomingServerData */
79
- private static readonly SYNC_BATCH_SIZE;
78
+ private readonly syncBatchSize;
80
79
  private processIncomingServerData;
81
80
  private compareTimestamps;
82
81
  private resolveCollectionConflict;
@@ -248,6 +248,9 @@ export interface SyncEngineCallbacks {
248
248
  loaded: number;
249
249
  total: number;
250
250
  items: number;
251
+ itemsCumulative?: number;
252
+ isNewCollection?: boolean;
253
+ processingMs?: number;
251
254
  }) => void;
252
255
  onServerSyncStart?: (info: {
253
256
  calledFrom?: string;
@@ -300,6 +303,8 @@ export interface SyncEngineConfig {
300
303
  collections: Map<string, CollectionConfig>;
301
304
  dexieDb: I_DexieDb;
302
305
  restInterface: I_RestInterface;
306
+ /** Items per batch in processIncomingServerData. Default 10000. */
307
+ syncBatchSize?: number;
303
308
  /**
304
309
  * Optional per-item filter / transform applied before upload. See
305
310
  * `SyncedDbConfig.preprocessDirtyItem` for full semantics.
@@ -592,6 +592,8 @@ export interface SyncedDbConfig {
592
592
  restTimeoutMs?: number;
593
593
  /** Timeout za sync REST klice v ms (default: 120000) - daljši ker sync prenaša več podatkov */
594
594
  syncTimeoutMs?: number;
595
+ /** Število itemov na batch v processIncomingServerData. Default 10000. */
596
+ syncBatchSize?: number;
595
597
  /**
596
598
  * Activity timeout za streaming odgovore (default: 30000).
597
599
  *
@@ -674,6 +676,12 @@ export interface SyncedDbConfig {
674
676
  loaded: number;
675
677
  total: number;
676
678
  items: number;
679
+ /** Cumulative items for this collection across all chunks so far */
680
+ itemsCumulative?: number;
681
+ /** True only for the first chunk of a new collection */
682
+ isNewCollection?: boolean;
683
+ /** Processing time for this chunk: Dexie save + InMem write (ms) */
684
+ processingMs?: number;
677
685
  }) => void;
678
686
  /**
679
687
  * Callback when per-collection hydration status changes (hydration end,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.212",
3
+ "version": "0.1.214",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",