@rdlabo/ionic-angular-kit 21.5.31 → 21.5.32

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.
@@ -1660,6 +1660,13 @@ class OfflineReplicaPullService {
1660
1660
  const scopeCommands = await this.#repository.getCommands(scope);
1661
1661
  const userCommands = this.#repository.getCommandsForUser ? await this.#repository.getCommandsForUser(scope.userId) : scopeCommands;
1662
1662
  const changes = this.#collapseChanges(page.changes);
1663
+ const projection = await this.#projector?.project({
1664
+ scope,
1665
+ changes,
1666
+ commands: scopeCommands,
1667
+ repository: this.#repository,
1668
+ });
1669
+ this.#assertProjection(scope, projection);
1663
1670
  const putRows = [];
1664
1671
  const removeRows = [];
1665
1672
  const rebasedPutRows = [];
@@ -1755,7 +1762,7 @@ class OfflineReplicaPullService {
1755
1762
  const revisionChanged = related.some((command) => command.baseRevision !== change.serverRevision);
1756
1763
  const rebaseEligible = related.every((command) => (command.state === 'pending' || command.state === 'retry_wait') && command.serverCommitUnknown !== true);
1757
1764
  const rebase = revisionChanged && rebaseEligible
1758
- ? ((await this.#executor.rebasePendingCommands?.(related, confirmedValues, change.serverRevision, await this.#currentCompanionRows(related))) ?? null)
1765
+ ? ((await this.#executor.rebasePendingCommands?.(related, confirmedValues, change.serverRevision, await this.#projectedCompanionRows(related, projection))) ?? null)
1759
1766
  : null;
1760
1767
  this.#assertRebasedSteps(related, rebase?.steps ?? null);
1761
1768
  const conflicted = revisionChanged && rebase === null;
@@ -1791,13 +1798,6 @@ class OfflineReplicaPullService {
1791
1798
  }
1792
1799
  }
1793
1800
  }
1794
- const projection = await this.#projector?.project({
1795
- scope,
1796
- changes,
1797
- commands: scopeCommands,
1798
- repository: this.#repository,
1799
- });
1800
- this.#assertProjection(scope, projection);
1801
1801
  const finalRows = this.#mergeRowMutations([
1802
1802
  { putRows, removeRows },
1803
1803
  { putRows: projection?.putRows ?? [], removeRows: projection?.removeRows ?? [] },
@@ -1916,6 +1916,21 @@ class OfflineReplicaPullService {
1916
1916
  }));
1917
1917
  return rows.filter((row) => row !== null);
1918
1918
  }
1919
+ async #projectedCompanionRows(commands, projection) {
1920
+ const footprint = new Set(commands.flatMap((command) => (command.optimisticCompanions ?? []).map((companion) => this.#rowKey(companion.key))));
1921
+ const rows = new Map((await this.#currentCompanionRows(commands)).map((row) => [this.#rowKey(row), row]));
1922
+ for (const row of projection?.removeRows ?? []) {
1923
+ const key = this.#rowKey(row);
1924
+ if (footprint.has(key))
1925
+ rows.delete(key);
1926
+ }
1927
+ for (const row of projection?.putRows ?? []) {
1928
+ const key = this.#rowKey(row);
1929
+ if (footprint.has(key))
1930
+ rows.set(key, row);
1931
+ }
1932
+ return [...rows.values()];
1933
+ }
1919
1934
  #assertPullChange(change, index) {
1920
1935
  const label = `Offline replica pull page changes[${index}]`;
1921
1936
  if (!isPlainObject(change)) {