@absolutejs/sync 1.21.0 → 1.22.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.
@@ -3059,6 +3059,43 @@ var createSyncEngine = (options = {}) => {
3059
3059
  version
3060
3060
  }),
3061
3061
  importChangeLog,
3062
+ replayTo: async ({ at, tables }) => {
3063
+ const filterTables = tables !== undefined ? new Set(tables) : undefined;
3064
+ const state = new Map;
3065
+ let asOfVersion = 0;
3066
+ let asOfAt = 0;
3067
+ const oldest = changeLog[0];
3068
+ const truncated = oldest !== undefined && oldest.version > 1 && oldest.at > at;
3069
+ for (const entry of changeLog) {
3070
+ if (entry.at > at)
3071
+ break;
3072
+ if (filterTables !== undefined && !filterTables.has(entry.table)) {
3073
+ continue;
3074
+ }
3075
+ let tableState = state.get(entry.table);
3076
+ if (tableState === undefined) {
3077
+ tableState = new Map;
3078
+ state.set(entry.table, tableState);
3079
+ }
3080
+ const reader = readers.get(entry.table);
3081
+ const key = reader?.key?.(entry.change.row) ?? entry.change.row?.id;
3082
+ if (key === undefined) {
3083
+ continue;
3084
+ }
3085
+ if (entry.change.op === "delete") {
3086
+ tableState.delete(key);
3087
+ } else {
3088
+ tableState.set(key, entry.change.row);
3089
+ }
3090
+ asOfVersion = entry.version;
3091
+ asOfAt = entry.at;
3092
+ }
3093
+ const rows = {};
3094
+ for (const [table, map] of state) {
3095
+ rows[table] = [...map.values()];
3096
+ }
3097
+ return { asOfAt, asOfVersion, rows, truncated };
3098
+ },
3062
3099
  metrics: () => {
3063
3100
  const now = Date.now();
3064
3101
  const byCollection = {};
@@ -3633,5 +3670,5 @@ export {
3633
3670
  CdcConsumerSlowError
3634
3671
  };
3635
3672
 
3636
- //# debugId=774BCA75D2571A6764756E2164756E21
3673
+ //# debugId=04E0C6606054D14564756E2164756E21
3637
3674
  //# sourceMappingURL=index.js.map