@rdlabo/ionic-angular-kit 21.4.7 → 21.4.8

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.
@@ -1399,6 +1399,11 @@ class OfflineSessionService {
1399
1399
  this.#localAccessThisRun = false;
1400
1400
  this.#remoteActivatedThisRun = false;
1401
1401
  }
1402
+ /** Immediately revoke local and remote runtime access while durable cleanup is pending. */
1403
+ revokeAccess() {
1404
+ this.#localAccessThisRun = false;
1405
+ this.#remoteActivatedThisRun = false;
1406
+ }
1402
1407
  /** Disable remote pull/replay eligibility while retaining the verified local manifest. */
1403
1408
  async suspendRemoteSession() {
1404
1409
  await this.initialize();
@@ -1488,6 +1493,7 @@ class OfflineSyncService {
1488
1493
  #knownScopes;
1489
1494
  #activeUserId;
1490
1495
  #flushPromise;
1496
+ #flushTransitions;
1491
1497
  #generation;
1492
1498
  #sendingTransitions;
1493
1499
  #enqueueTail;
@@ -1507,6 +1513,7 @@ class OfflineSyncService {
1507
1513
  this.#knownScopes = new Map();
1508
1514
  this.#activeUserId = null;
1509
1515
  this.#flushPromise = null;
1516
+ this.#flushTransitions = new Set();
1510
1517
  this.#generation = 0;
1511
1518
  this.#sendingTransitions = new Set();
1512
1519
  this.#enqueueTail = Promise.resolve();
@@ -1566,7 +1573,8 @@ class OfflineSyncService {
1566
1573
  await this.#refreshState();
1567
1574
  }
1568
1575
  async resetSession() {
1569
- this.#invalidateFlush();
1576
+ this.revokeSession();
1577
+ await Promise.allSettled([this.#enqueueTail, ...this.#flushTransitions]);
1570
1578
  await this.#waitForSendingTransitions();
1571
1579
  await this.#restoreInterruptedCommands();
1572
1580
  this.#activeUserId = null;
@@ -1574,12 +1582,17 @@ class OfflineSyncService {
1574
1582
  this.#commands.set([]);
1575
1583
  this.#scheduleRetry(null);
1576
1584
  }
1585
+ /** Synchronously invalidate in-flight enqueue and transport work owned by the current session. */
1586
+ revokeSession() {
1587
+ this.#invalidateFlush();
1588
+ }
1577
1589
  enqueue(request, options = {}) {
1578
- const enqueue = this.#enqueueTail.then(() => this.#enqueue(request, options));
1590
+ const generation = this.#generation;
1591
+ const enqueue = this.#enqueueTail.then(() => this.#enqueue(request, options, generation));
1579
1592
  this.#enqueueTail = enqueue.then(() => undefined, () => undefined);
1580
1593
  return enqueue;
1581
1594
  }
1582
- async #enqueue(request, options) {
1595
+ async #enqueue(request, options, generation) {
1583
1596
  await this.initialize();
1584
1597
  const session = await this.#getLocalSession();
1585
1598
  if (!session)
@@ -1628,6 +1641,9 @@ class OfflineSyncService {
1628
1641
  fetchedAt: Date.now(),
1629
1642
  syncState: 'pending',
1630
1643
  };
1644
+ if (generation !== this.#generation) {
1645
+ throw new Error('Offline session changed before the command could be persisted');
1646
+ }
1631
1647
  await this.#repository.transactReplica({ putRows: [optimisticRow], putCommands: [command] });
1632
1648
  await this.#refreshState();
1633
1649
  if (options.flush !== false && this.#network.connected())
@@ -1665,10 +1681,12 @@ class OfflineSyncService {
1665
1681
  return this.#flushPromise;
1666
1682
  const generation = this.#generation;
1667
1683
  const promise = this.#runFlush(generation).finally(() => {
1684
+ this.#flushTransitions.delete(promise);
1668
1685
  if (this.#flushPromise === promise)
1669
1686
  this.#flushPromise = null;
1670
1687
  });
1671
1688
  this.#flushPromise = promise;
1689
+ this.#flushTransitions.add(promise);
1672
1690
  return promise;
1673
1691
  }
1674
1692
  async #runFlush(generation) {
@@ -2109,6 +2127,8 @@ class OfflineCoordinatorService {
2109
2127
  });
2110
2128
  }
2111
2129
  clearActiveSession() {
2130
+ this.#sync.revokeSession();
2131
+ this.#session.revokeAccess();
2112
2132
  ++this.#transitionRevision;
2113
2133
  return this.#enqueueTransition(async () => {
2114
2134
  await this.#sync.resetSession();