cry-synced-db-client 0.1.113 → 0.1.114

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
@@ -3438,6 +3438,7 @@ var SyncedDb = class _SyncedDb {
3438
3438
  const windowId = (_a = config._testWindowId) != null ? _a : this.getOrCreateWindowId();
3439
3439
  this.defaultReturnDeleted = (_b = config.returnDeleted) != null ? _b : false;
3440
3440
  this.defaultReturnArchived = (_c = config.returnArchived) != null ? _c : false;
3441
+ this.onDatabaseCreated = config.onDatabaseCreated;
3441
3442
  this.onSyncStart = config.onSyncStart;
3442
3443
  this.onSyncEnd = config.onSyncEnd;
3443
3444
  this.onDexieSyncStart = config.onDexieSyncStart;
@@ -3714,6 +3715,13 @@ var SyncedDb = class _SyncedDb {
3714
3715
  }
3715
3716
  await this._loadLastFullSync();
3716
3717
  await this._loadLastInitialSync();
3718
+ if (this.dexieDb.isNewDatabase() && this.onDatabaseCreated) {
3719
+ try {
3720
+ this.onDatabaseCreated();
3721
+ } catch (err) {
3722
+ console.error("onDatabaseCreated callback failed:", err);
3723
+ }
3724
+ }
3717
3725
  await this.pendingChanges.recoverPendingWrites();
3718
3726
  const allowedColls = [...this.collections.keys()].filter((n) => this.isSyncAllowed(n));
3719
3727
  const dexieStart = Date.now();
@@ -4577,7 +4585,7 @@ var SyncedDb = class _SyncedDb {
4577
4585
  }
4578
4586
  assertCollection(name) {
4579
4587
  if (!this.collections.has(name)) {
4580
- throw new Error(`Collection "${name}" not configured`);
4588
+ throw new Error(`SyncedDb: Collection "${(name == null ? void 0 : name.toString()) || "?"}" not configured`);
4581
4589
  }
4582
4590
  }
4583
4591
  /** Stringify an Id parameter (ObjectId → hex string). */
@@ -4658,6 +4666,7 @@ var DexieDb = class extends Dexie {
4658
4666
  constructor(tenant, collectionConfigs) {
4659
4667
  super(`synced-db-${tenant}`);
4660
4668
  this.collections = /* @__PURE__ */ new Map();
4669
+ this._isNewDatabase = false;
4661
4670
  this.tenant = tenant;
4662
4671
  const schema = {};
4663
4672
  schema[SYNC_META_TABLE] = "[tenant+collection]";
@@ -4666,6 +4675,9 @@ var DexieDb = class extends Dexie {
4666
4675
  schema[config.name] = "_id";
4667
4676
  }
4668
4677
  this.version(1).stores(schema);
4678
+ this.on("populate", () => {
4679
+ this._isNewDatabase = true;
4680
+ });
4669
4681
  this.syncMeta = this.table(SYNC_META_TABLE);
4670
4682
  this.dirtyChanges = this.table(DIRTY_CHANGES_TABLE);
4671
4683
  for (const config of collectionConfigs) {
@@ -4675,7 +4687,7 @@ var DexieDb = class extends Dexie {
4675
4687
  getTable(collection) {
4676
4688
  const table = this.collections.get(collection);
4677
4689
  if (!table) {
4678
- throw new Error(`Collection "${collection}" not configured`);
4690
+ throw new Error(`DexieDb: Collection "${(collection == null ? void 0 : collection.toString()) || "?"}" not configured`);
4679
4691
  }
4680
4692
  return table;
4681
4693
  }
@@ -4874,6 +4886,9 @@ var DexieDb = class extends Dexie {
4874
4886
  getTenant() {
4875
4887
  return this.tenant;
4876
4888
  }
4889
+ isNewDatabase() {
4890
+ return this._isNewDatabase;
4891
+ }
4877
4892
  };
4878
4893
 
4879
4894
  // node_modules/msgpackr/unpack.js
@@ -12,6 +12,7 @@ export declare class DexieDb extends Dexie implements I_DexieDb {
12
12
  private collections;
13
13
  private syncMeta;
14
14
  private dirtyChanges;
15
+ private _isNewDatabase;
15
16
  constructor(tenant: string, collectionConfigs: CollectionConfig<any>[]);
16
17
  private getTable;
17
18
  private idToString;
@@ -51,4 +52,5 @@ export declare class DexieDb extends Dexie implements I_DexieDb {
51
52
  setSyncMeta(collection: string, lastSyncTs: any): Promise<void>;
52
53
  deleteSyncMeta(collection: string): Promise<void>;
53
54
  getTenant(): string;
55
+ isNewDatabase(): boolean;
54
56
  }
@@ -37,6 +37,7 @@ export declare class SyncedDb implements I_SyncedDb {
37
37
  private beforeUnloadHandler?;
38
38
  private readonly defaultReturnDeleted;
39
39
  private readonly defaultReturnArchived;
40
+ private readonly onDatabaseCreated?;
40
41
  private readonly onSyncStart?;
41
42
  private readonly onSyncEnd?;
42
43
  private readonly onDexieSyncStart?;
@@ -116,5 +116,7 @@ export interface I_DexieDb {
116
116
  deleteSyncMeta(collection: string): Promise<void>;
117
117
  /** Vrne tenant */
118
118
  getTenant(): string;
119
+ /** Returns true if the IndexedDB database was created fresh during this session (first ever open). */
120
+ isNewDatabase(): boolean;
119
121
  }
120
122
  export {};
@@ -293,6 +293,8 @@ export interface SyncedDbConfig {
293
293
  debounceRestWritesMs?: number;
294
294
  /** Callback ki se pokliče, ko SyncedDb sam preide v offline stanje (npr. ob sync napaki) */
295
295
  onForcedOffline?: (reason: string) => void;
296
+ /** Callback fired once during init() when the IndexedDB database was created fresh (first ever open). */
297
+ onDatabaseCreated?: () => void;
296
298
  /** Callback at the start of each sync cycle. initialSync=true if no full sync has completed yet. */
297
299
  onSyncStart?: (info: {
298
300
  calledFrom?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.113",
3
+ "version": "0.1.114",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",