@absolutejs/sync 2.0.1 → 2.1.0

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.
@@ -113,6 +113,21 @@ export type EngineMetrics = {
113
113
  schedules: {
114
114
  registered: number;
115
115
  };
116
+ /**
117
+ * Change-source liveness, aggregated across every `connectSource` (e.g. a
118
+ * CDC adapter). Lets a health check distinguish a healthy-but-quiet feed
119
+ * from a wired-but-silent or disconnected one. Added in 2.1.0.
120
+ */
121
+ source: {
122
+ /** Currently-connected change sources (0 once all have disconnected). */
123
+ connected: number;
124
+ /** Total changes delivered by connected sources since engine start. */
125
+ changesReceived: number;
126
+ /** `Date.now()` of the most recent source change, or `null` if none yet. */
127
+ lastChangeAt: number | null;
128
+ /** Wall-clock age of the most recent source change in ms, or `null`. */
129
+ lastChangeAgeMs: number | null;
130
+ };
116
131
  };
117
132
  /**
118
133
  * A live engine event (see {@link SyncEngine.onActivity}): a committed change or
@@ -1611,6 +1611,9 @@ var createSyncEngine = (options = {}) => {
1611
1611
  let mutationsFailed = 0;
1612
1612
  let mutationsRetried = 0;
1613
1613
  let mutationsInFlight = 0;
1614
+ let connectedSources = 0;
1615
+ let sourceChangesReceived = 0;
1616
+ let sourceLastChangeAt = null;
1614
1617
  const mutationWaiters = [];
1615
1618
  let mutationsQueued = 0;
1616
1619
  const activeFences = new Set;
@@ -2664,8 +2667,18 @@ var createSyncEngine = (options = {}) => {
2664
2667
  },
2665
2668
  applyChange: (table, change) => applyChange(table, change),
2666
2669
  connectSource: async (source) => {
2667
- await source.start((table, change) => applyChange(table, change));
2670
+ await source.start((table, change) => {
2671
+ sourceChangesReceived += 1;
2672
+ sourceLastChangeAt = Date.now();
2673
+ return applyChange(table, change);
2674
+ });
2675
+ connectedSources += 1;
2676
+ let stopped = false;
2668
2677
  return async () => {
2678
+ if (!stopped) {
2679
+ stopped = true;
2680
+ connectedSources -= 1;
2681
+ }
2669
2682
  await source.stop();
2670
2683
  };
2671
2684
  },
@@ -3226,6 +3239,12 @@ var createSyncEngine = (options = {}) => {
3226
3239
  schedules: {
3227
3240
  registered: schedules.size
3228
3241
  },
3242
+ source: {
3243
+ changesReceived: sourceChangesReceived,
3244
+ connected: connectedSources,
3245
+ lastChangeAgeMs: sourceLastChangeAt === null ? null : now - sourceLastChangeAt,
3246
+ lastChangeAt: sourceLastChangeAt
3247
+ },
3229
3248
  subscriptions: {
3230
3249
  byCollection,
3231
3250
  byTenant: Object.fromEntries(subscriptionsByTenant),
@@ -3769,5 +3788,5 @@ export {
3769
3788
  CdcConsumerSlowError
3770
3789
  };
3771
3790
 
3772
- //# debugId=6D23BAC246E5201264756E2164756E21
3791
+ //# debugId=34D5A585C92FDCCE64756E2164756E21
3773
3792
  //# sourceMappingURL=index.js.map