cry-synced-db-client 0.1.10 → 0.1.13

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.
@@ -24,6 +24,7 @@ export declare class SyncedDb implements I_SyncedDb {
24
24
  private onFindNewerCall?;
25
25
  private onDexieWriteRequest?;
26
26
  private onDexieWriteResult?;
27
+ private onLocalstorageWriteResult?;
27
28
  private autoSyncIntervalMs?;
28
29
  private online;
29
30
  private syncing;
package/dist/index.js CHANGED
@@ -251,10 +251,10 @@ function getPendingWrites(tenant) {
251
251
  }
252
252
 
253
253
  // src/db/SyncedDb.ts
254
- var DEFAULT_DEXIE_DEBOUNCE_MS = 1000;
255
- var DEFAULT_REST_DEBOUNCE_MS = 2000;
256
- var DEFAULT_REST_TIMEOUT_MS = 1e4;
257
- var DEFAULT_SYNC_TIMEOUT_MS = 30000;
254
+ var DEFAULT_DEXIE_DEBOUNCE_MS = 500;
255
+ var DEFAULT_REST_DEBOUNCE_MS = 100;
256
+ var DEFAULT_REST_TIMEOUT_MS = 90000;
257
+ var DEFAULT_SYNC_TIMEOUT_MS = 120000;
258
258
  var MAX_RETRY_COUNT = 3;
259
259
 
260
260
  class SyncedDb {
@@ -276,6 +276,7 @@ class SyncedDb {
276
276
  onFindNewerCall;
277
277
  onDexieWriteRequest;
278
278
  onDexieWriteResult;
279
+ onLocalstorageWriteResult;
279
280
  autoSyncIntervalMs;
280
281
  online = false;
281
282
  syncing = false;
@@ -307,6 +308,7 @@ class SyncedDb {
307
308
  this.onFindNewerCall = config.onFindNewerCall;
308
309
  this.onDexieWriteRequest = config.onDexieWriteRequest;
309
310
  this.onDexieWriteResult = config.onDexieWriteResult;
311
+ this.onLocalstorageWriteResult = config.onLocalstorageWriteResult;
310
312
  this.autoSyncIntervalMs = config.autoSyncIntervalMs;
311
313
  this.updaterId = Math.random().toString(36).substring(2, 15);
312
314
  for (const col of config.collections) {
@@ -893,6 +895,19 @@ class SyncedDb {
893
895
  }
894
896
  }
895
897
  clearPendingWrite(this.tenant, pending.collection, pending.id);
898
+ if (this.onLocalstorageWriteResult) {
899
+ try {
900
+ this.onLocalstorageWriteResult({
901
+ collection: pending.collection,
902
+ id: pending.id,
903
+ durationMs: Date.now() - startTime,
904
+ success: true,
905
+ calledFrom: pending.calledFrom
906
+ });
907
+ } catch (err) {
908
+ console.error("onLocalstorageWriteResult callback failed:", err);
909
+ }
910
+ }
896
911
  this.scheduleRestUpload();
897
912
  } catch (err) {
898
913
  console.error("Failed to write to Dexie:", err);
@@ -88,6 +88,23 @@ export interface DexieWriteResultInfo {
88
88
  /** Where the write was called from (for debugging) */
89
89
  calledFrom?: string;
90
90
  }
91
+ /**
92
+ * Callback payload for localStorage write results (crash recovery cleared after successful Dexie write)
93
+ */
94
+ export interface LocalstorageWriteResultInfo {
95
+ /** Collection that was written to */
96
+ collection: string;
97
+ /** ID of the item that was written */
98
+ id: Id;
99
+ /** Duration in ms */
100
+ durationMs: number;
101
+ /** Whether the write succeeded */
102
+ success: boolean;
103
+ /** Error if failed */
104
+ error?: Error;
105
+ /** Where the write was called from (for debugging) */
106
+ calledFrom?: string;
107
+ }
91
108
  /**
92
109
  * Informacije o sinhronizaciji za debugging/logging
93
110
  */
@@ -136,13 +153,13 @@ export interface SyncedDbConfig {
136
153
  restInterface: I_RestInterface;
137
154
  /** Server update notifier - dependency injection (opcijsko) */
138
155
  serverUpdateNotifier?: I_ServerUpdateNotifier;
139
- /** Timeout za splošne REST klice v ms (default: 10000) */
156
+ /** Timeout za splošne REST klice v ms (default: 90000) */
140
157
  restTimeoutMs?: number;
141
- /** Timeout za sync REST klice v ms (default: 30000) - daljši ker sync prenaša več podatkov */
158
+ /** Timeout za sync REST klice v ms (default: 120000) - daljši ker sync prenaša več podatkov */
142
159
  syncTimeoutMs?: number;
143
- /** Debounce čas za zapis v Dexie v ms (default: 1000) */
160
+ /** Debounce čas za zapis v Dexie v ms (default: 500) */
144
161
  debounceDexieWritesMs?: number;
145
- /** Debounce čas za pošiljanje na REST v ms (default: 2000) - po uspešnem zapisu v Dexie */
162
+ /** Debounce čas za pošiljanje na REST v ms (default: 100) - po uspešnem zapisu v Dexie */
146
163
  debounceRestWritesMs?: number;
147
164
  /** Callback ki se pokliče, ko SyncedDb sam preide v offline stanje (npr. ob sync napaki) */
148
165
  onForcedOffline?: (reason: string) => void;
@@ -160,6 +177,8 @@ export interface SyncedDbConfig {
160
177
  onDexieWriteRequest?: (info: DexieWriteRequestInfo) => void;
161
178
  /** Callback after writing to Dexie */
162
179
  onDexieWriteResult?: (info: DexieWriteResultInfo) => void;
180
+ /** Callback after localStorage crash recovery is cleared (after successful Dexie write) */
181
+ onLocalstorageWriteResult?: (info: LocalstorageWriteResultInfo) => void;
163
182
  /**
164
183
  * Interval za avtomatsko sinhronizacijo v ms (opcijsko).
165
184
  * Če je podano, se sync() kliče avtomatsko na ta interval, ko je online.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.10",
3
+ "version": "0.1.13",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",