cry-synced-db-client 0.1.98 → 0.1.100

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
@@ -7211,7 +7211,7 @@ var Ebus2ProxyServerUpdateNotifier = class {
7211
7211
  this.reconnectAttempt = 0;
7212
7212
  this.forcedOffline = false;
7213
7213
  this.subscribedChannels = /* @__PURE__ */ new Set();
7214
- var _a, _b, _c, _d;
7214
+ var _a, _b, _c, _d, _e;
7215
7215
  this.wsUrl = config.wsUrl;
7216
7216
  this.dbName = config.dbName;
7217
7217
  this.collections = config.collections;
@@ -7225,6 +7225,8 @@ var Ebus2ProxyServerUpdateNotifier = class {
7225
7225
  if (config.onWsDisconnect) this.onWsDisconnectCallbacks.push(config.onWsDisconnect);
7226
7226
  if (config.onWsReconnect) this.onWsReconnectCallbacks.push(config.onWsReconnect);
7227
7227
  this.onWsNotification = config.onWsNotification;
7228
+ this.subscribeServices = (_e = config.subscribeServices) != null ? _e : false;
7229
+ this.onServicesChange = config.onServicesChange;
7228
7230
  }
7229
7231
  subscribe(callback) {
7230
7232
  this.callbacks.add(callback);
@@ -7357,9 +7359,9 @@ var Ebus2ProxyServerUpdateNotifier = class {
7357
7359
  this.connected = true;
7358
7360
  this.reconnectAttempt = 0;
7359
7361
  this.currentReconnectDelay = this.reconnectDelayMs;
7360
- for (const collection of this.collections) {
7361
- const channel = `db/${this.dbName}/${collection}`;
7362
- this.sendSubscribe(channel);
7362
+ this.sendSubscribe(`db/${this.dbName}`);
7363
+ if (this.subscribeServices) {
7364
+ this.sendSubscribe("ebus/services");
7363
7365
  }
7364
7366
  this.startPingInterval();
7365
7367
  for (const callback of this.onWsConnectCallbacks) {
@@ -7420,7 +7422,20 @@ var Ebus2ProxyServerUpdateNotifier = class {
7420
7422
  }
7421
7423
  }
7422
7424
  handleChannelMessage(message) {
7423
- if (!message.channel.startsWith("db/")) {
7425
+ if (message.channel === "ebus/services" && this.onServicesChange) {
7426
+ try {
7427
+ this.onServicesChange(message.data);
7428
+ } catch (err) {
7429
+ console.error("onServicesChange callback failed:", err);
7430
+ }
7431
+ return;
7432
+ }
7433
+ const prefix = `db/${this.dbName}/`;
7434
+ if (!message.channel.startsWith(prefix)) {
7435
+ return;
7436
+ }
7437
+ const collection = message.channel.slice(prefix.length);
7438
+ if (!this.collections.includes(collection)) {
7424
7439
  return;
7425
7440
  }
7426
7441
  const payload = message.data;
@@ -25,6 +25,15 @@ export interface Ebus2ProxyServerUpdateNotifierConfig {
25
25
  onWsReconnect?: (attempt: number) => void;
26
26
  /** Called when a notification is received */
27
27
  onWsNotification?: (payload: PublishDataPayload) => void;
28
+ /** Subscribe to ebus/services channel for worker presence */
29
+ subscribeServices?: boolean;
30
+ /** Called when ebus/services data changes (worker presence) */
31
+ onServicesChange?: (services: EbusService[]) => void;
32
+ }
33
+ export interface EbusService {
34
+ name: string;
35
+ workers: number;
36
+ requests: number;
28
37
  }
29
38
  export declare class Ebus2ProxyServerUpdateNotifier implements I_ServerUpdateNotifier {
30
39
  private wsUrl;
@@ -39,6 +48,8 @@ export declare class Ebus2ProxyServerUpdateNotifier implements I_ServerUpdateNot
39
48
  private onWsDisconnectCallbacks;
40
49
  private onWsReconnectCallbacks;
41
50
  private onWsNotification?;
51
+ private subscribeServices;
52
+ private onServicesChange?;
42
53
  private ws;
43
54
  private callbacks;
44
55
  private connected;
@@ -6,6 +6,6 @@ export { DexieDb } from "./db/DexieDb";
6
6
  export { RestProxy } from "./db/RestProxy";
7
7
  export type { RestProxyConfig } from "./db/RestProxy";
8
8
  export { Ebus2ProxyServerUpdateNotifier } from "./db/Ebus2ProxyServerUpdateNotifier";
9
- export type { Ebus2ProxyServerUpdateNotifierConfig } from "./db/Ebus2ProxyServerUpdateNotifier";
9
+ export type { Ebus2ProxyServerUpdateNotifierConfig, EbusService } from "./db/Ebus2ProxyServerUpdateNotifier";
10
10
  export { resolveConflict } from "./utils/conflictResolution";
11
11
  export { filterByQuery, matchesQuery, sortItems, applySkipLimit, projectItem, applyQueryOpts } from "./utils/localQuery";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.98",
3
+ "version": "0.1.100",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",