cry-synced-db-client 0.1.115 → 0.1.117

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
@@ -3881,6 +3881,13 @@ var SyncedDb = class _SyncedDb {
3881
3881
  const memItem = this.inMemDb.getById(collection, id);
3882
3882
  if (memItem) return memItem;
3883
3883
  }
3884
+ if ((opts == null ? void 0 : opts.referToServer) !== false && this.isOnline()) {
3885
+ await this.ensureItemsAreLoaded(
3886
+ collection,
3887
+ [id],
3888
+ opts == null ? void 0 : opts.returnDeleted
3889
+ );
3890
+ }
3884
3891
  if (((opts == null ? void 0 : opts.returnDeleted) || (opts == null ? void 0 : opts.returnArchived)) && this.isOnline()) {
3885
3892
  try {
3886
3893
  const serverItem = await this.connectionManager.withRestTimeout(
@@ -3905,9 +3912,6 @@ var SyncedDb = class _SyncedDb {
3905
3912
  const [projected] = applyQueryOpts([result], { project: opts.project });
3906
3913
  result = projected;
3907
3914
  }
3908
- if ((opts == null ? void 0 : opts.referToServer) && this.isOnline()) {
3909
- this.referToServerSync(collection);
3910
- }
3911
3915
  return result;
3912
3916
  }
3913
3917
  async findByIds(collection, ids, opts) {
@@ -3919,6 +3923,13 @@ var SyncedDb = class _SyncedDb {
3919
3923
  return this.writeOnlyFindByIds(collection, ids);
3920
3924
  }
3921
3925
  if (ids.length === 0) return [];
3926
+ if ((opts == null ? void 0 : opts.referToServer) !== false && this.isOnline()) {
3927
+ await this.ensureItemsAreLoaded(
3928
+ collection,
3929
+ ids,
3930
+ opts == null ? void 0 : opts.returnDeleted
3931
+ );
3932
+ }
3922
3933
  if (((opts == null ? void 0 : opts.returnDeleted) || (opts == null ? void 0 : opts.returnArchived)) && this.isOnline()) {
3923
3934
  try {
3924
3935
  const serverItems = await this.connectionManager.withRestTimeout(
@@ -3943,11 +3954,7 @@ var SyncedDb = class _SyncedDb {
3943
3954
  if (!(opts == null ? void 0 : opts.returnArchived) && item._archived) continue;
3944
3955
  results.push(item);
3945
3956
  }
3946
- const final = applyQueryOpts(results, opts);
3947
- if ((opts == null ? void 0 : opts.referToServer) && this.isOnline()) {
3948
- this.referToServerSync(collection);
3949
- }
3950
- return final;
3957
+ return applyQueryOpts(results, opts);
3951
3958
  }
3952
3959
  async findOne(collection, query, opts) {
3953
3960
  var _a, _b;
@@ -4056,21 +4063,22 @@ var SyncedDb = class _SyncedDb {
4056
4063
  }
4057
4064
  }
4058
4065
  /**
4059
- * Fire-and-forget background sync for a single collection.
4060
- * Calls findNewer with the last sync timestamp and processes results.
4066
+ * Fire-and-forget background query to server.
4067
+ * Uses timestamp 0 to fetch all matching items (not just newer than
4068
+ * last sync), so it also covers items outside the normal sync scope.
4069
+ * Results are processed through conflict resolution before updating
4070
+ * Dexie + in-mem.
4061
4071
  */
4062
4072
  referToServerSync(collection, query) {
4063
- const meta = this.syncMetaCache.get(collection);
4064
- const timestamp = (meta == null ? void 0 : meta.lastSyncTs) || 0;
4065
4073
  this.connectionManager.withRestTimeout(
4066
- this.restInterface.findNewer(collection, timestamp, query, { returnDeleted: true }),
4074
+ this.restInterface.findNewer(collection, 0, query, { returnDeleted: true }),
4067
4075
  "referToServer"
4068
4076
  ).then(async (serverData) => {
4069
4077
  if (serverData.length > 0) {
4070
4078
  await this.syncEngine.processCollectionServerData(collection, serverData);
4071
4079
  }
4072
4080
  }).catch((err) => {
4073
- console.error(`referToServer sync failed for ${collection}:`, err);
4081
+ console.error(`referToServer failed for ${collection}:`, err);
4074
4082
  });
4075
4083
  }
4076
4084
  async ensureItemsAreLoaded(collection, ids, withDeleted) {
@@ -121,8 +121,11 @@ export declare class SyncedDb implements I_SyncedDb {
121
121
  */
122
122
  private syncCollectionForFind;
123
123
  /**
124
- * Fire-and-forget background sync for a single collection.
125
- * Calls findNewer with the last sync timestamp and processes results.
124
+ * Fire-and-forget background query to server.
125
+ * Uses timestamp 0 to fetch all matching items (not just newer than
126
+ * last sync), so it also covers items outside the normal sync scope.
127
+ * Results are processed through conflict resolution before updating
128
+ * Dexie + in-mem.
126
129
  */
127
130
  private referToServerSync;
128
131
  ensureItemsAreLoaded(collection: string, ids: string[], withDeleted?: boolean): Promise<void>;
@@ -19,7 +19,12 @@ export type QueryOpts = Partial<{
19
19
  returnDeleted: boolean;
20
20
  /** Če je true, vrne tudi archived objekte (z _archived poljem) */
21
21
  returnArchived: boolean;
22
- /** Če je true, vrne lokalne rezultate in nato v ozadju sinhronizira s serverjem */
22
+ /**
23
+ * findById/findByIds (privzeto true): če zapis ne obstaja lokalno
24
+ * in smo online, ga prebere s serverja ter shrani v Dexie + in-mem.
25
+ * find (privzeto false): takoj vrne lokalne rezultate, nato v ozadju
26
+ * pošlje query na server in posodobi in-mem z rezultati.
27
+ */
23
28
  referToServer: boolean;
24
29
  }>;
25
30
  export type KeyOf<T> = keyof T | "$bit" | "$set" | "$inc" | "$currentDate" | "$min" | "$max" | "$mul" | "$rename" | "$setOnInsert" | "$unset" | "$pull" | "$push" | "$pop" | "$addToSet" | "$pushAll" | "_rev" | "_ts" | "_csq" | "_deleted";
@@ -518,13 +518,27 @@ export interface I_SyncedDb {
518
518
  * @returns true if forceOffline(true) was called, false otherwise
519
519
  */
520
520
  isForcedOffline(): boolean;
521
- /** Poišče objekt po ID-ju */
521
+ /**
522
+ * Poišče objekt po ID-ju.
523
+ * referToServer (privzeto true): če ne obstaja lokalno, prebere s serverja.
524
+ */
522
525
  findById<T extends DbEntity>(collection: string, id: Id, opts?: QueryOpts): Promise<T | null>;
523
- /** Poišče objekte po ID-jih */
526
+ /**
527
+ * Poišče objekte po ID-jih.
528
+ * referToServer (privzeto true): manjkajoče prebere s serverja.
529
+ */
524
530
  findByIds<T extends DbEntity>(collection: string, ids: Id[], opts?: QueryOpts): Promise<T[]>;
525
- /** Poišče prvi objekt, ki ustreza poizvedbi */
531
+ /**
532
+ * Poišče prvi objekt, ki ustreza poizvedbi.
533
+ * referToServer (privzeto false): vrne lokalni rezultat, nato v ozadju
534
+ * pošlje query na server in posodobi in-mem.
535
+ */
526
536
  findOne<T extends DbEntity>(collection: string, query: QuerySpec<T>, opts?: QueryOpts): Promise<T | null>;
527
- /** Poišče vse objekte, ki ustrezajo poizvedbi */
537
+ /**
538
+ * Poišče vse objekte, ki ustrezajo poizvedbi.
539
+ * referToServer (privzeto false): vrne lokalne rezultate, nato v ozadju
540
+ * pošlje query na server in posodobi in-mem.
541
+ */
528
542
  find<T extends DbEntity>(collection: string, query?: QuerySpec<T>, opts?: QueryOpts): Promise<T[]>;
529
543
  /**
530
544
  * Preveri prisotnost podanih ID-jev v lokalni bazi.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.115",
3
+ "version": "0.1.117",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -35,7 +35,7 @@
35
35
  "vitest": "^4.1.2"
36
36
  },
37
37
  "dependencies": {
38
- "cry-db": "^2.4.24",
38
+ "cry-db": "^2.4.27",
39
39
  "cry-helpers": "^2.1.193",
40
40
  "cry-synced-db-client": "^0.1.111",
41
41
  "msgpackr": "^1.11.9",