@absolutejs/sync 2.0.1 → 2.2.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.
package/dist/testing.js CHANGED
@@ -826,6 +826,9 @@ var createSyncEngine = (options = {}) => {
826
826
  let mutationsFailed = 0;
827
827
  let mutationsRetried = 0;
828
828
  let mutationsInFlight = 0;
829
+ let connectedSources = 0;
830
+ let sourceChangesReceived = 0;
831
+ let sourceLastChangeAt = null;
829
832
  const mutationWaiters = [];
830
833
  let mutationsQueued = 0;
831
834
  const activeFences = new Set;
@@ -1011,6 +1014,9 @@ var createSyncEngine = (options = {}) => {
1011
1014
  return subscription.view.reset(await subscription.rehydrate());
1012
1015
  }
1013
1016
  }
1017
+ if (subscription.affects && !subscription.affects(change)) {
1018
+ return EMPTY_DIFF;
1019
+ }
1014
1020
  return subscription.view.reset(await subscription.rehydrate());
1015
1021
  };
1016
1022
  const subscriptionsForTable = function* (table) {
@@ -1803,6 +1809,7 @@ var createSyncEngine = (options = {}) => {
1803
1809
  return readRule ? rows.filter((row) => readRule(ctx, row)) : rows;
1804
1810
  };
1805
1811
  const incremental = match !== undefined && tables.length === 1;
1812
+ const boundAffects = !incremental && definition.affects ? (change) => definition.affects(change, params, ctx) : undefined;
1806
1813
  const boundMatch = incremental ? (row) => match(row, params, ctx) && (readRule ? readRule(ctx, row) : true) : () => true;
1807
1814
  const view = createMaterializedView({
1808
1815
  key,
@@ -1817,6 +1824,7 @@ var createSyncEngine = (options = {}) => {
1817
1824
  view,
1818
1825
  incremental,
1819
1826
  rehydrate,
1827
+ ...boundAffects ? { affects: boundAffects } : {},
1820
1828
  key,
1821
1829
  onDiff: typedOnDiff
1822
1830
  };
@@ -1879,8 +1887,18 @@ var createSyncEngine = (options = {}) => {
1879
1887
  },
1880
1888
  applyChange: (table, change) => applyChange(table, change),
1881
1889
  connectSource: async (source) => {
1882
- await source.start((table, change) => applyChange(table, change));
1890
+ await source.start((table, change) => {
1891
+ sourceChangesReceived += 1;
1892
+ sourceLastChangeAt = Date.now();
1893
+ return applyChange(table, change);
1894
+ });
1895
+ connectedSources += 1;
1896
+ let stopped = false;
1883
1897
  return async () => {
1898
+ if (!stopped) {
1899
+ stopped = true;
1900
+ connectedSources -= 1;
1901
+ }
1884
1902
  await source.stop();
1885
1903
  };
1886
1904
  },
@@ -2441,6 +2459,12 @@ var createSyncEngine = (options = {}) => {
2441
2459
  schedules: {
2442
2460
  registered: schedules.size
2443
2461
  },
2462
+ source: {
2463
+ changesReceived: sourceChangesReceived,
2464
+ connected: connectedSources,
2465
+ lastChangeAgeMs: sourceLastChangeAt === null ? null : now - sourceLastChangeAt,
2466
+ lastChangeAt: sourceLastChangeAt
2467
+ },
2444
2468
  subscriptions: {
2445
2469
  byCollection,
2446
2470
  byTenant: Object.fromEntries(subscriptionsByTenant),
@@ -2553,5 +2577,5 @@ export {
2553
2577
  createTestEngine
2554
2578
  };
2555
2579
 
2556
- //# debugId=2AB81FA5B279855564756E2164756E21
2580
+ //# debugId=F796E6726FCBFF2B64756E2164756E21
2557
2581
  //# sourceMappingURL=testing.js.map