@absolutejs/sync 1.21.0 → 1.23.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
@@ -2274,6 +2274,43 @@ var createSyncEngine = (options = {}) => {
2274
2274
  version
2275
2275
  }),
2276
2276
  importChangeLog,
2277
+ replayTo: async ({ at, tables }) => {
2278
+ const filterTables = tables !== undefined ? new Set(tables) : undefined;
2279
+ const state = new Map;
2280
+ let asOfVersion = 0;
2281
+ let asOfAt = 0;
2282
+ const oldest = changeLog[0];
2283
+ const truncated = oldest !== undefined && oldest.version > 1 && oldest.at > at;
2284
+ for (const entry of changeLog) {
2285
+ if (entry.at > at)
2286
+ break;
2287
+ if (filterTables !== undefined && !filterTables.has(entry.table)) {
2288
+ continue;
2289
+ }
2290
+ let tableState = state.get(entry.table);
2291
+ if (tableState === undefined) {
2292
+ tableState = new Map;
2293
+ state.set(entry.table, tableState);
2294
+ }
2295
+ const reader = readers.get(entry.table);
2296
+ const key = reader?.key?.(entry.change.row) ?? entry.change.row?.id;
2297
+ if (key === undefined) {
2298
+ continue;
2299
+ }
2300
+ if (entry.change.op === "delete") {
2301
+ tableState.delete(key);
2302
+ } else {
2303
+ tableState.set(key, entry.change.row);
2304
+ }
2305
+ asOfVersion = entry.version;
2306
+ asOfAt = entry.at;
2307
+ }
2308
+ const rows = {};
2309
+ for (const [table, map] of state) {
2310
+ rows[table] = [...map.values()];
2311
+ }
2312
+ return { asOfAt, asOfVersion, rows, truncated };
2313
+ },
2277
2314
  metrics: () => {
2278
2315
  const now = Date.now();
2279
2316
  const byCollection = {};
@@ -2418,5 +2455,5 @@ export {
2418
2455
  createTestEngine
2419
2456
  };
2420
2457
 
2421
- //# debugId=ED4D54755D5C43CD64756E2164756E21
2458
+ //# debugId=19605A03FFBA9EF964756E2164756E21
2422
2459
  //# sourceMappingURL=testing.js.map