cry-synced-db-client 0.1.208 → 0.1.210

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
@@ -1,5 +1,23 @@
1
1
  # Versions
2
2
 
3
+ ## 0.1.209 (2026-06-25)
4
+
5
+ ### Removed hardcoded `{ returnDeleted: true }` from sync specs
6
+
7
+ `CollectionSyncConfig.opts` now carries `returnDeleted`, `returnArchived`, and
8
+ `project` per-collection instead of being hardcoded in `SyncEngine`. Each
9
+ sync spec passes its own opts directly to `findNewer`.
10
+
11
+ ### Added `onEviction` callback
12
+
13
+ New optional `onEviction` callback on `SyncEngineCallbacks` — fires with
14
+ `{ collection, totalEvicted, totalServerEvicted }` after each eviction pass.
15
+
16
+ ### Test script fixes
17
+
18
+ - Added `test/preload-bun.cjs` — polyfill for Bun's missing `process.getBuiltinModule('v8')`
19
+ - Fixed `test:real-mongo` script to use `npx vitest run` (not `bun test`)
20
+
3
21
  ## 0.1.204 (2026-06-17)
4
22
 
5
23
  ### Per-collection error isolation in `uploadDirtyItems`
package/dist/index.js CHANGED
@@ -3212,7 +3212,7 @@ var _SyncEngine = class _SyncEngine {
3212
3212
  * never enter the positive-sync processing path.
3213
3213
  */
3214
3214
  async sync(calledFrom, extras) {
3215
- var _a, _b;
3215
+ var _a, _b, _c;
3216
3216
  const startTime = Date.now();
3217
3217
  let receivedCount = 0;
3218
3218
  let sentCount = 0;
@@ -3239,7 +3239,7 @@ var _SyncEngine = class _SyncEngine {
3239
3239
  collection: collectionName,
3240
3240
  timestamp: (meta == null ? void 0 : meta.lastSyncTs) || 0,
3241
3241
  query,
3242
- opts: { returnDeleted: true }
3242
+ opts: (_c = config.syncConfig) == null ? void 0 : _c.opts
3243
3243
  });
3244
3244
  configMap.set(collectionName, config);
3245
3245
  }
@@ -3271,7 +3271,26 @@ var _SyncEngine = class _SyncEngine {
3271
3271
  allSpecs,
3272
3272
  async (collection, items, specId) => {
3273
3273
  if (specId !== void 0) {
3274
- if (extras) extras.onChunk(specId, items);
3274
+ if (specId.endsWith(":exit")) {
3275
+ const exitItems = items.filter((it) => it._evictIds);
3276
+ if (exitItems.length > 0) {
3277
+ const exitIds = exitItems.map((it) => String(it._id));
3278
+ await this.dexieDb.deleteMany(collection, exitIds);
3279
+ this.deps.writeToInMemBatch(
3280
+ collection,
3281
+ exitIds.map((id) => ({ _id: id })),
3282
+ "delete",
3283
+ { source: "incremental" }
3284
+ );
3285
+ this.callbackSafe(this.callbacks.onEviction, {
3286
+ collection,
3287
+ totalEvicted: exitIds.length,
3288
+ totalServerEvicted: exitIds.length
3289
+ });
3290
+ }
3291
+ } else if (extras) {
3292
+ extras.onChunk(specId, items);
3293
+ }
3275
3294
  return;
3276
3295
  }
3277
3296
  const config = configMap.get(collection);
@@ -6443,30 +6462,12 @@ var _SyncedDb = class _SyncedDb {
6443
6462
  }
6444
6463
  this.syncing = true;
6445
6464
  this.crossTabSync.startServerSync();
6446
- let evictionPlan;
6447
- let evictionServerFailed = false;
6448
- if (await this._isAutoEvictionDue(calledFrom)) {
6449
- try {
6450
- evictionPlan = await this._collectScopeExitPlan("auto");
6451
- } catch (err) {
6452
- console.error(
6453
- "[SyncedDb] [evict] phase 1 failed (skipping bundled eviction):",
6454
- err
6455
- );
6456
- }
6457
- }
6458
- const evictionExtras = evictionPlan && evictionPlan.specs.length > 0 ? {
6459
- specs: evictionPlan.specs,
6460
- onChunk: (specId, items) => {
6461
- this._applyScopeExitChunkToPlan(evictionPlan, specId, items);
6462
- }
6463
- } : void 0;
6464
6465
  const consumingPendingFullResync = this._pendingFullResync;
6465
6466
  if (consumingPendingFullResync) {
6466
6467
  await this._resetSyncCursors();
6467
6468
  }
6468
6469
  try {
6469
- await this.syncEngine.sync(calledFrom, evictionExtras);
6470
+ await this.syncEngine.sync(calledFrom);
6470
6471
  if (!this.syncOnlyCollections) {
6471
6472
  const now = /* @__PURE__ */ new Date();
6472
6473
  if (!this._lastFullSyncDate) {
@@ -6486,24 +6487,11 @@ var _SyncedDb = class _SyncedDb {
6486
6487
  if (consumingPendingFullResync) this._pendingFullResync = false;
6487
6488
  }
6488
6489
  } catch (err) {
6489
- if (evictionExtras) evictionServerFailed = true;
6490
6490
  throw err;
6491
6491
  } finally {
6492
6492
  this.syncing = false;
6493
6493
  this.crossTabSync.endServerSync();
6494
6494
  await this.processQueuedWsUpdates();
6495
- if (evictionPlan) {
6496
- try {
6497
- await this._applyScopeExitPlan(
6498
- evictionPlan,
6499
- evictionServerFailed,
6500
- evictionExtras ? 1 : 0
6501
- );
6502
- await this._persistEvictionTimestamp();
6503
- } catch (err) {
6504
- console.error(`[SyncedDb] [evict] phase 3 failed: ${err}`, err);
6505
- }
6506
- }
6507
6495
  }
6508
6496
  } finally {
6509
6497
  this.syncLock = false;
@@ -268,6 +268,11 @@ export interface SyncEngineCallbacks {
268
268
  onFindNewerManyResult?: (info: FindNewerManyResultInfo) => void;
269
269
  onUploadSkip?: (info: import("../../types/I_SyncedDb").UploadSkipInfo) => void;
270
270
  onDirtyItemStuck?: (info: import("../../types/I_SyncedDb").DirtyItemStuckInfo) => void;
271
+ onEviction?: (info: {
272
+ collection: string;
273
+ totalEvicted: number;
274
+ totalServerEvicted: number;
275
+ }) => void;
271
276
  }
272
277
  export interface SyncEngineDeps {
273
278
  getSyncMetaCache: () => Map<string, SyncMeta>;
@@ -10,6 +10,15 @@ export interface CollectionSyncConfig<T = any> {
10
10
  enabled?: boolean | (() => boolean);
11
11
  /** Query filter for sync. If a function, called at each sync to get the query. */
12
12
  query?: QuerySpec<T> | (() => QuerySpec<T>);
13
+ /**
14
+ * Options passed to findNewerManyStream during sync.
15
+ * e.g. `{ returnDeleted: true }` to include soft-deleted records.
16
+ * When omitted, cry-db applies its own defaults.
17
+ */
18
+ opts?: {
19
+ returnDeleted?: boolean;
20
+ returnArchived?: boolean;
21
+ };
13
22
  }
14
23
  export interface CollectionConfig<T = any> {
15
24
  name: string;
@@ -531,6 +531,12 @@ export interface CollectionSyncConfig {
531
531
  enabled?: boolean | (() => boolean);
532
532
  /** Query filter for sync. If a function, called at each sync to get the query. */
533
533
  query?: QuerySpec<any> | (() => QuerySpec<any>);
534
+ /** Options passed through to findNewer (returnDeleted, returnArchived, project, ...) */
535
+ opts?: {
536
+ returnDeleted?: boolean;
537
+ returnArchived?: boolean;
538
+ project?: Record<string, any>;
539
+ };
534
540
  }
535
541
  /**
536
542
  * Konfiguracija za posamezno kolekcijo
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.208",
3
+ "version": "0.1.210",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -20,25 +20,25 @@
20
20
  "build": "bun run clean && bun run build:js && bun run build:types",
21
21
  "build:js": "esbuild ./src/index.ts --bundle --outdir=./dist --target=es2017 --format=esm --platform=browser --external:dexie --external:bson --external:cry-helpers",
22
22
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
23
- "test": "bun test test/*.test.ts test/restProxy/*.test.ts && vitest run",
23
+ "test": "bun test --preload ./test/preload-bun.cjs test/*.test.ts test/restProxy/*.test.ts; vitest run",
24
24
  "test:bun": "bun test test/*.test.ts test/restProxy/*.test.ts",
25
25
  "test:node-only": "vitest run",
26
- "test:real-mongo": "USE_REAL_MONGO=1 bun test test/bracketArrayPathsAcrossWriters.test.ts test/restProxy/*.test.ts",
26
+ "test:real-mongo": "USE_REAL_MONGO=1 npx vitest run test/node-only/",
27
27
  "prepublishOnly": "bun run build"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/bun": "latest",
31
- "bson": "^7.2.0",
31
+ "bson": "^7.3.1",
32
32
  "cry-ebus-proxy": "^2.0.0",
33
- "dexie": "^4.4.3",
33
+ "dexie": "^4.4.4",
34
34
  "esbuild": "^0.28.1",
35
35
  "fake-indexeddb": "^6.2.5",
36
36
  "typescript": "^6",
37
- "vitest": "^4.1.8"
37
+ "vitest": "^4.1.9"
38
38
  },
39
39
  "dependencies": {
40
- "cry-db": "^2.5.5",
41
- "cry-helpers": "^2.1.205",
40
+ "cry-db": "^2.5.6",
41
+ "cry-helpers": "^2.1.206",
42
42
  "msgpackr": "^2.0.4",
43
43
  "superjson": "^2.2.6"
44
44
  },