cry-synced-db-client 0.1.58 → 0.1.60

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
@@ -438,6 +438,7 @@ class LeaderElectionManager {
438
438
  class CrossTabSyncManager {
439
439
  tenant;
440
440
  instanceId;
441
+ windowId;
441
442
  debounceMs;
442
443
  callbacks;
443
444
  deps;
@@ -447,6 +448,7 @@ class CrossTabSyncManager {
447
448
  constructor(config) {
448
449
  this.tenant = config.tenant;
449
450
  this.instanceId = config.instanceId;
451
+ this.windowId = config.windowId;
450
452
  this.debounceMs = config.debounceMs;
451
453
  this.callbacks = config.callbacks;
452
454
  this.deps = config.deps;
@@ -500,7 +502,9 @@ class CrossTabSyncManager {
500
502
  if (Object.keys(updates).length > 0) {
501
503
  const payload = {
502
504
  updates,
503
- instanceId: this.instanceId
505
+ instanceId: this.instanceId,
506
+ isLeader: this.deps.isLeader(),
507
+ windowId: this.windowId
504
508
  };
505
509
  try {
506
510
  this.metaUpdateChannel.postMessage(payload);
@@ -568,7 +572,15 @@ class CrossTabSyncManager {
568
572
  }
569
573
  if (this.callbacks.onCrossTabSync && newItemsCount > 0) {
570
574
  try {
571
- this.callbacks.onCrossTabSync(collection, newItemsCount);
575
+ const info = {
576
+ collection,
577
+ itemsCount: newItemsCount,
578
+ senderInstanceId: payload.instanceId,
579
+ senderWindowId: payload.windowId,
580
+ senderWasLeader: payload.isLeader,
581
+ timestamp: new Date
582
+ };
583
+ this.callbacks.onCrossTabSync(info);
572
584
  } catch (err) {
573
585
  console.error("onCrossTabSync callback failed:", err);
574
586
  }
@@ -2730,6 +2742,7 @@ class SyncedDb {
2730
2742
  this.crossTabSync = new CrossTabSyncManager({
2731
2743
  tenant: this.tenant,
2732
2744
  instanceId: this.syncedDbInstanceId,
2745
+ windowId,
2733
2746
  debounceMs: config.crossTabSyncDebounceMs ?? 100,
2734
2747
  callbacks: {
2735
2748
  onCrossTabSync: config.onCrossTabSync,
@@ -9,6 +9,7 @@ import type { I_CrossTabSyncManager, CrossTabSyncConfig } from "../types/manager
9
9
  export declare class CrossTabSyncManager implements I_CrossTabSyncManager {
10
10
  private readonly tenant;
11
11
  private readonly instanceId;
12
+ private readonly windowId;
12
13
  private readonly debounceMs;
13
14
  private readonly callbacks;
14
15
  private readonly deps;
@@ -7,7 +7,7 @@ import type { I_DexieDb, SyncMeta, MetaUpdateBroadcast } from "../../types/I_Dex
7
7
  import type { I_InMemDb } from "../../types/I_InMemDb";
8
8
  import type { I_RestInterface } from "../../types/I_RestInterface";
9
9
  import type { PublishDataPayload } from "../../types/PublishRevsPayload";
10
- import type { CollectionConfig, SyncInfo, ConflictResolutionReport, ServerWriteRequestInfo, ServerWriteResultInfo, FindNewerManyCallInfo, FindNewerManyResultInfo, DexieWriteRequestInfo, DexieWriteResultInfo, LocalstorageWriteResultInfo, WsNotificationInfo } from "../../types/I_SyncedDb";
10
+ import type { CollectionConfig, SyncInfo, ConflictResolutionReport, ServerWriteRequestInfo, ServerWriteResultInfo, FindNewerManyCallInfo, FindNewerManyResultInfo, DexieWriteRequestInfo, DexieWriteResultInfo, LocalstorageWriteResultInfo, WsNotificationInfo, CrossTabSyncInfo } from "../../types/I_SyncedDb";
11
11
  import type { PendingChange, UploadResult } from "./internal";
12
12
  export interface LeaderElectionCallbacks {
13
13
  onBecameLeader?: () => void;
@@ -35,7 +35,7 @@ export interface I_LeaderElectionManager {
35
35
  }
36
36
  export interface CrossTabSyncCallbacks {
37
37
  /** Called after cross-tab sync completes. */
38
- onCrossTabSync?: (collection: string, newItemsCount: number) => void;
38
+ onCrossTabSync?: (info: CrossTabSyncInfo) => void;
39
39
  /** Called when BroadcastChannel is unavailable. */
40
40
  onInfrastructureError?: (type: string, message: string, error?: Error) => void;
41
41
  }
@@ -54,6 +54,7 @@ export interface CrossTabSyncDeps {
54
54
  export interface CrossTabSyncConfig {
55
55
  tenant: string;
56
56
  instanceId: string;
57
+ windowId: string;
57
58
  debounceMs: number;
58
59
  callbacks: CrossTabSyncCallbacks;
59
60
  deps: CrossTabSyncDeps;
@@ -34,7 +34,12 @@ export interface DirtyChange {
34
34
  export interface MetaUpdateBroadcast {
35
35
  /** Map of collection name -> array of _id strings that were updated */
36
36
  updates: Record<string, string[]>;
37
+ /** Unique ID of the SyncedDb instance that sent this broadcast */
37
38
  instanceId: string;
39
+ /** Whether the sender is the leader tab */
40
+ isLeader: boolean;
41
+ /** Window ID of the sender (for debugging) */
42
+ windowId: string;
38
43
  }
39
44
  /**
40
45
  * Interface za Dexie (IndexedDB) bazo podatkov
@@ -158,6 +158,24 @@ export type ConflictSource =
158
158
  | "serverUpdate_pendingChanges"
159
159
  /** Conflict when processing server update with dirty local item in Dexie */
160
160
  | "serverUpdate_dirtyLocal";
161
+ /**
162
+ * Callback payload for cross-tab synchronization events.
163
+ * Contains information about the source tab that triggered the sync.
164
+ */
165
+ export interface CrossTabSyncInfo {
166
+ /** Collection that was synchronized */
167
+ collection: string;
168
+ /** Number of items that were updated in local in-memory cache */
169
+ itemsCount: number;
170
+ /** Unique ID of the SyncedDb instance that sent the broadcast */
171
+ senderInstanceId: string;
172
+ /** Window ID of the sender tab (for debugging multi-window scenarios) */
173
+ senderWindowId: string;
174
+ /** Whether the sender was the leader tab when broadcasting */
175
+ senderWasLeader: boolean;
176
+ /** Timestamp when the sync was processed locally */
177
+ timestamp: Date;
178
+ }
161
179
  /**
162
180
  * Callback payload for conflict resolution
163
181
  */
@@ -279,7 +297,7 @@ export interface SyncedDbConfig {
279
297
  /** Debounce interval for cross-tab sync broadcasts in ms (default: 100) */
280
298
  crossTabSyncDebounceMs?: number;
281
299
  /** Callback when another tab synced data and local in-memory cache was updated */
282
- onCrossTabSync?: (collection: string, newItemsCount: number) => void;
300
+ onCrossTabSync?: (info: CrossTabSyncInfo) => void;
283
301
  /** Callback when this instance becomes the leader tab */
284
302
  onBecameLeader?: () => void;
285
303
  /** Callback when this instance loses leadership (e.g., another tab took over) */
@@ -4,5 +4,5 @@ export type { Obj, QuerySpec, Projection, QueryOpts, KeyOf, InsertKeyOf, InsertS
4
4
  export type { I_InMemDb as InMemDb } from "./I_InMemDb";
5
5
  export type { I_DexieDb as DexieDb, SyncMeta } from "./I_DexieDb";
6
6
  export type { I_ServerUpdateNotifier as ServerUpdateNotifier, ServerUpdateCallback, ServerUpdateNotifierCallbacks } from "./I_ServerUpdateNotifier";
7
- export type { I_SyncedDb as SyncedDb, SyncedDbConfig, CollectionConfig, SyncInfo, ServerWriteRequestInfo, ServerWriteResultInfo, FindNewerManyCallInfo, FindNewerManyResultInfo, DexieWriteRequestInfo, DexieWriteResultInfo, LocalstorageWriteResultInfo, WsNotificationInfo, InfrastructureErrorType, InfrastructureErrorInfo, ConflictSource, ConflictResolutionReport, } from "./I_SyncedDb";
7
+ export type { I_SyncedDb as SyncedDb, SyncedDbConfig, CollectionConfig, SyncInfo, ServerWriteRequestInfo, ServerWriteResultInfo, FindNewerManyCallInfo, FindNewerManyResultInfo, DexieWriteRequestInfo, DexieWriteResultInfo, LocalstorageWriteResultInfo, WsNotificationInfo, InfrastructureErrorType, InfrastructureErrorInfo, ConflictSource, ConflictResolutionReport, CrossTabSyncInfo, } from "./I_SyncedDb";
8
8
  export type { CollectionConfig as CollectionConfigFull } from "./CollectionConfig";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.58",
3
+ "version": "0.1.60",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",