cry-synced-db-client 0.1.59 → 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
@@ -572,7 +572,15 @@ class CrossTabSyncManager {
572
572
  }
573
573
  if (this.callbacks.onCrossTabSync && newItemsCount > 0) {
574
574
  try {
575
- 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);
576
584
  } catch (err) {
577
585
  console.error("onCrossTabSync callback failed:", err);
578
586
  }
@@ -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
  }
@@ -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.59",
3
+ "version": "0.1.60",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",