@powerhousedao/connect 1.0.0-dev.244 → 1.0.0-dev.246

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.
Files changed (29) hide show
  1. package/dist/.env +0 -5
  2. package/dist/assets/{app-DR3WlBLu.js → app-BT03qzg4.js} +342 -384
  3. package/dist/assets/{app-D3TxLTK-.css → app-D9QJBr8i.css} +19 -1
  4. package/dist/assets/{app-loader-CjrEwupY.css → app-loader-Bnp0H-wa.css} +16 -0
  5. package/dist/assets/{app-loader-CXe8k3Z6.js → app-loader-Cp_C_kSQ.js} +243 -139
  6. package/dist/assets/{ccip-DqQzZGts.js → ccip-rCu2dOKk.js} +3 -3
  7. package/dist/assets/{content-C4uS9aKJ.js → content-B1RXkSXz.js} +3 -3
  8. package/dist/assets/{index-DXnKAS5B.js → index-CJbQZ7hP.js} +3 -3
  9. package/dist/assets/{index-Ka_SdIs9.js → index-DX2bXpNe.js} +3 -3
  10. package/dist/assets/{index-BSwHlrXw.js → index-a5VEmfQw.js} +4 -4
  11. package/dist/assets/{main.CwbMf_Nf.js → main.Hm4UID1Z.js} +1 -1
  12. package/dist/external-packages.js +5 -0
  13. package/dist/hmr.js +4 -1
  14. package/dist/index.html +1 -4
  15. package/dist/modules/@powerhousedao/reactor-browser/{chunk-YOX3ZAET.js → chunk-A4GIWVYS.js} +162 -109
  16. package/dist/modules/@powerhousedao/reactor-browser/{chunk-6AXML2S3.js → chunk-PQ4UODLR.js} +1 -1
  17. package/dist/modules/@powerhousedao/reactor-browser/{chunk-P46ZMPJ3.js → chunk-UP4DC4D2.js} +1 -1
  18. package/dist/modules/@powerhousedao/reactor-browser/{chunk-POMUCSTC.js → chunk-XXFOSD4A.js} +74 -20
  19. package/dist/modules/@powerhousedao/reactor-browser/{chunk-4LZZ55AN.js → chunk-YDERCA5J.js} +1 -1
  20. package/dist/modules/@powerhousedao/reactor-browser/context/index.js +2 -2
  21. package/dist/modules/@powerhousedao/reactor-browser/context/read-mode.js +2 -2
  22. package/dist/modules/@powerhousedao/reactor-browser/hooks/index.js +3 -3
  23. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActions.js +2 -2
  24. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActionsWithUiNodes.js +3 -3
  25. package/dist/modules/@powerhousedao/reactor-browser/index.js +5 -5
  26. package/dist/modules/@powerhousedao/reactor-browser/reactor.js +2 -2
  27. package/dist/swEnv.js +0 -3
  28. package/dist/vite-envs.sh +1 -28
  29. package/package.json +9 -9
@@ -688,30 +688,79 @@ var require_lib = __commonJS({
688
688
  }
689
689
  });
690
690
 
691
+ // ../../packages/document-drive/dist/src/cache/util.js
692
+ var trimResultingState = (document) => {
693
+ const global2 = document.operations.global.map((e) => {
694
+ delete e.resultingState;
695
+ return e;
696
+ });
697
+ const local = document.operations.local.map((e) => {
698
+ delete e.resultingState;
699
+ return e;
700
+ });
701
+ return { ...document, operations: { global: global2, local } };
702
+ };
703
+
691
704
  // ../../packages/document-drive/dist/src/cache/memory.js
692
705
  var InMemoryCache = class {
693
- cache = /* @__PURE__ */ new Map();
694
- async setDocument(drive, id, document) {
695
- const global2 = document.operations.global.map((e) => {
696
- delete e.resultingState;
697
- return e;
698
- });
699
- const local = document.operations.local.map((e) => {
700
- delete e.resultingState;
701
- return e;
702
- });
703
- const doc = { ...document, operations: { global: global2, local } };
704
- if (!this.cache.has(drive)) {
705
- this.cache.set(drive, /* @__PURE__ */ new Map());
706
+ idTodocument = /* @__PURE__ */ new Map();
707
+ idToDrive = /* @__PURE__ */ new Map();
708
+ slugToDriveId = /* @__PURE__ */ new Map();
709
+ clear() {
710
+ this.idTodocument.clear();
711
+ this.idToDrive.clear();
712
+ this.slugToDriveId.clear();
713
+ }
714
+ /////////////////////////////////////////////////////////////////////////////
715
+ // ICache
716
+ /////////////////////////////////////////////////////////////////////////////
717
+ async setDocument(documentId, document) {
718
+ const doc = trimResultingState(document);
719
+ this.idTodocument.set(documentId, doc);
720
+ }
721
+ async getDocument(documentId) {
722
+ return this.idTodocument.get(documentId);
723
+ }
724
+ async deleteDocument(documentId) {
725
+ return this.idTodocument.delete(documentId);
726
+ }
727
+ async setDrive(driveId, drive) {
728
+ const doc = trimResultingState(drive);
729
+ this.idToDrive.set(driveId, doc);
730
+ }
731
+ async getDrive(driveId) {
732
+ return this.idToDrive.get(driveId);
733
+ }
734
+ async deleteDrive(driveId) {
735
+ const drive = this.idToDrive.get(driveId);
736
+ if (!drive) {
737
+ return false;
706
738
  }
707
- this.cache.get(drive)?.set(id, doc);
708
- return true;
739
+ const slug = drive.state.global.slug;
740
+ if (slug) {
741
+ this.slugToDriveId.delete(slug);
742
+ }
743
+ return this.idToDrive.delete(driveId);
709
744
  }
710
- async deleteDocument(drive, id) {
711
- return this.cache.get(drive)?.delete(id) ?? false;
745
+ async setDriveBySlug(slug, drive) {
746
+ const driveId = drive.state.global.id;
747
+ this.slugToDriveId.set(slug, driveId);
748
+ this.setDrive(driveId, drive);
712
749
  }
713
- async getDocument(drive, id) {
714
- return this.cache.get(drive)?.get(id);
750
+ async getDriveBySlug(slug) {
751
+ const driveId = this.slugToDriveId.get(slug);
752
+ if (!driveId) {
753
+ return void 0;
754
+ }
755
+ return this.getDrive(driveId);
756
+ }
757
+ async deleteDriveBySlug(slug) {
758
+ const driveId = this.slugToDriveId.get(slug);
759
+ if (!driveId) {
760
+ return false;
761
+ }
762
+ this.slugToDriveId.delete(slug);
763
+ return this.deleteDrive(driveId);
715
764
  }
716
765
  };
717
766
  var memory_default = InMemoryCache;
@@ -1652,19 +1701,16 @@ var ReadDocumentNotFoundError = class extends ReadDriveError {
1652
1701
  // ../../packages/document-drive/dist/src/storage/memory.js
1653
1702
  var MemoryStorage = class {
1654
1703
  documents;
1655
- drives;
1656
1704
  driveManifests;
1657
- slugToDriveId = {};
1658
1705
  constructor() {
1659
1706
  this.documents = {};
1660
- this.drives = {};
1661
1707
  this.driveManifests = {};
1662
1708
  }
1663
1709
  ////////////////////////////////
1664
1710
  // IDocumentStorage
1665
1711
  ////////////////////////////////
1666
1712
  exists(documentId) {
1667
- return Promise.resolve(!!this.documents[documentId]);
1713
+ return Promise.resolve(!!this.documents[documentId] || !!this.documents[`drive/${documentId}`]);
1668
1714
  }
1669
1715
  create(documentId, document) {
1670
1716
  this.documents[documentId] = document;
@@ -1673,10 +1719,52 @@ var MemoryStorage = class {
1673
1719
  get(documentId) {
1674
1720
  const document = this.documents[documentId];
1675
1721
  if (!document) {
1722
+ const drive = this.documents[`drive/${documentId}`];
1723
+ if (drive) {
1724
+ return Promise.resolve(drive);
1725
+ }
1676
1726
  throw new Error(`Document with id ${documentId} not found`);
1677
1727
  }
1678
1728
  return Promise.resolve(document);
1679
1729
  }
1730
+ async delete(documentId) {
1731
+ const drives = await this.getDrives();
1732
+ for (const driveId of drives) {
1733
+ if (driveId === documentId)
1734
+ continue;
1735
+ await this.removeChild(driveId, documentId);
1736
+ }
1737
+ delete this.driveManifests[documentId];
1738
+ if (this.documents[documentId]) {
1739
+ delete this.documents[documentId];
1740
+ return Promise.resolve(true);
1741
+ }
1742
+ return Promise.resolve(false);
1743
+ }
1744
+ async addChild(parentId, childId) {
1745
+ if (parentId === childId) {
1746
+ throw new Error("Cannot associate a document with itself");
1747
+ }
1748
+ const children = await this.getChildren(childId);
1749
+ if (children.includes(parentId)) {
1750
+ throw new Error("Cannot associate a document with its child");
1751
+ }
1752
+ const manifest = this.getManifest(parentId);
1753
+ manifest.documentIds.add(childId);
1754
+ this.updateDriveManifest(parentId, manifest);
1755
+ }
1756
+ async removeChild(parentId, childId) {
1757
+ const manifest = this.getManifest(parentId);
1758
+ if (manifest.documentIds.delete(childId)) {
1759
+ this.updateDriveManifest(parentId, manifest);
1760
+ return true;
1761
+ }
1762
+ return false;
1763
+ }
1764
+ async getChildren(parentId) {
1765
+ const manifest = this.getManifest(parentId);
1766
+ return [...manifest.documentIds];
1767
+ }
1680
1768
  ////////////////////////////////
1681
1769
  // IDriveStorage
1682
1770
  ////////////////////////////////
@@ -1684,27 +1772,19 @@ var MemoryStorage = class {
1684
1772
  return this.exists(id);
1685
1773
  }
1686
1774
  getDocuments(drive) {
1687
- const manifest = this.getDriveManifest(drive);
1775
+ const manifest = this.getManifest(drive);
1688
1776
  return Promise.resolve([...manifest.documentIds]);
1689
1777
  }
1690
1778
  getDocument(driveId, id) {
1691
1779
  return this.get(id);
1692
1780
  }
1693
- async saveDocument(drive, id, document) {
1694
- this.documents[id] = document;
1695
- const manifest = this.getDriveManifest(drive);
1696
- manifest.documentIds.add(id);
1697
- this.updateDriveManifest(drive, manifest);
1698
- }
1699
1781
  async clearStorage() {
1700
1782
  this.documents = {};
1701
- this.drives = {};
1702
1783
  this.driveManifests = {};
1703
- this.slugToDriveId = {};
1704
1784
  }
1705
1785
  async createDocument(drive, id, document) {
1706
1786
  await this.create(id, document);
1707
- const manifest = this.getDriveManifest(drive);
1787
+ const manifest = this.getManifest(drive);
1708
1788
  manifest.documentIds.add(id);
1709
1789
  this.updateDriveManifest(drive, manifest);
1710
1790
  }
@@ -1721,59 +1801,60 @@ var MemoryStorage = class {
1721
1801
  };
1722
1802
  }
1723
1803
  async deleteDocument(drive, id) {
1724
- const drives = await this.getDrives();
1725
- for (const driveId of drives) {
1726
- const manifest = this.getDriveManifest(driveId);
1727
- if (manifest.documentIds.has(id)) {
1728
- manifest.documentIds.delete(id);
1729
- this.updateDriveManifest(driveId, manifest);
1730
- }
1731
- }
1732
- delete this.documents[id];
1804
+ this.delete(id);
1733
1805
  }
1734
1806
  async getDrives() {
1735
- return Object.keys(this.drives);
1807
+ return Object.keys(this.driveManifests);
1736
1808
  }
1737
1809
  async getDrive(id) {
1738
- const drive = this.drives[id];
1810
+ const drive = this.documents[`drive/${id}`];
1739
1811
  if (!drive) {
1740
1812
  throw new DriveNotFoundError(id);
1741
1813
  }
1742
1814
  return drive;
1743
1815
  }
1744
1816
  async getDriveBySlug(slug) {
1745
- const driveId = this.slugToDriveId[slug];
1746
- if (!driveId) {
1747
- throw new Error(`Drive with slug ${slug} not found`);
1817
+ for (const driveId of Object.keys(this.driveManifests)) {
1818
+ const drive = this.documents[`drive/${driveId}`];
1819
+ if (drive.initialState.state.global.slug === slug) {
1820
+ return drive;
1821
+ }
1748
1822
  }
1749
- return this.getDrive(driveId);
1823
+ throw new Error(`Drive with slug ${slug} not found`);
1750
1824
  }
1751
1825
  async createDrive(id, drive) {
1752
- this.drives[id] = drive;
1753
- this.updateDriveManifest(id, { documentIds: /* @__PURE__ */ new Set() });
1754
- const { slug } = drive.initialState.state.global;
1826
+ const slug = drive.initialState.state.global.slug;
1755
1827
  if (slug) {
1756
- this.slugToDriveId[slug] = id;
1828
+ let existingDrive;
1829
+ try {
1830
+ existingDrive = await this.getDriveBySlug(slug);
1831
+ } catch {
1832
+ }
1833
+ if (existingDrive) {
1834
+ throw new Error(`Drive with slug ${slug} already exists`);
1835
+ }
1757
1836
  }
1837
+ await this.create(`drive/${id}`, drive);
1838
+ this.updateDriveManifest(id, { documentIds: /* @__PURE__ */ new Set() });
1758
1839
  }
1759
1840
  async addDriveOperations(id, operations, header) {
1760
1841
  const drive = await this.getDrive(id);
1761
1842
  const mergedOperations = mergeOperations(drive.operations, operations);
1762
- this.drives[id] = {
1843
+ this.documents[`drive/${id}`] = {
1763
1844
  ...drive,
1764
1845
  ...header,
1765
1846
  operations: mergedOperations
1766
1847
  };
1767
1848
  }
1768
1849
  async deleteDrive(id) {
1769
- const manifest = this.getDriveManifest(id);
1850
+ const manifest = this.getManifest(id);
1770
1851
  const drives = await this.getDrives();
1771
1852
  await Promise.all([...manifest.documentIds].map((docId) => {
1772
1853
  for (const driveId of drives) {
1773
1854
  if (driveId === id) {
1774
1855
  continue;
1775
1856
  }
1776
- const manifest2 = this.getDriveManifest(driveId);
1857
+ const manifest2 = this.getManifest(driveId);
1777
1858
  if (manifest2.documentIds.has(docId)) {
1778
1859
  return;
1779
1860
  }
@@ -1781,24 +1862,18 @@ var MemoryStorage = class {
1781
1862
  delete this.documents[docId];
1782
1863
  }));
1783
1864
  delete this.driveManifests[id];
1784
- delete this.drives[id];
1785
- for (const [slug, driveId] of Object.entries(this.slugToDriveId)) {
1786
- if (driveId === id) {
1787
- delete this.slugToDriveId[slug];
1788
- }
1789
- }
1865
+ delete this.documents[id];
1790
1866
  }
1791
1867
  async getSynchronizationUnitsRevision(units) {
1792
1868
  const results = await Promise.allSettled(units.map(async (unit) => {
1793
1869
  try {
1794
- const document = await (unit.documentId ? this.getDocument(unit.driveId, unit.documentId) : this.getDrive(unit.driveId));
1870
+ const document = await this.get(unit.documentId);
1795
1871
  if (!document) {
1796
1872
  return void 0;
1797
1873
  }
1798
1874
  const operation = document.operations[unit.scope].at(-1);
1799
1875
  if (operation) {
1800
1876
  return {
1801
- driveId: unit.driveId,
1802
1877
  documentId: unit.documentId,
1803
1878
  scope: unit.scope,
1804
1879
  branch: unit.branch,
@@ -1820,7 +1895,7 @@ var MemoryStorage = class {
1820
1895
  ////////////////////////////////
1821
1896
  // Private
1822
1897
  ////////////////////////////////
1823
- getDriveManifest(driveId) {
1898
+ getManifest(driveId) {
1824
1899
  if (!this.driveManifests[driveId]) {
1825
1900
  this.driveManifests[driveId] = { documentIds: /* @__PURE__ */ new Set() };
1826
1901
  }
@@ -11851,7 +11926,7 @@ var PullResponderTransmitter = class _PullResponderTransmitter {
11851
11926
  const syncUnits = await this.manager.getListenerSyncUnitIds(driveId, listenerId);
11852
11927
  let success = true;
11853
11928
  for (const revision of revisions) {
11854
- const syncUnit = syncUnits.find((s) => s.scope === revision.scope && s.branch === revision.branch && s.driveId === revision.driveId && s.documentId == revision.documentId);
11929
+ const syncUnit = syncUnits.find((s) => s.scope === revision.scope && s.branch === revision.branch && s.documentId == revision.documentId);
11855
11930
  if (!syncUnit) {
11856
11931
  this.logger.warn("Unknown sync unit was acknowledged", revision);
11857
11932
  success = false;
@@ -12185,17 +12260,6 @@ var BaseDocumentDriveServer = class {
12185
12260
  taskQueueMethod: options?.taskQueueMethod === void 0 ? RunAsap.runAsap : options.taskQueueMethod
12186
12261
  };
12187
12262
  this.defaultDrivesManager = new DefaultDrivesManager(this, this.defaultDrivesManagerDelegate, options);
12188
- this.storage.setStorageDelegate?.({
12189
- getCachedOperations: async (drive, id) => {
12190
- try {
12191
- const document = await this.cache.getDocument(drive, id);
12192
- return document?.operations;
12193
- } catch (error) {
12194
- logger.error(error);
12195
- return void 0;
12196
- }
12197
- }
12198
- });
12199
12263
  this.initializePromise = this._initialize();
12200
12264
  }
12201
12265
  // workaround for testing the ephemeral listeners -- we don't have DI in place yet
@@ -12380,7 +12444,7 @@ var BaseDocumentDriveServer = class {
12380
12444
  };
12381
12445
  await this.storage.createDrive(id, document);
12382
12446
  if (input.global.slug) {
12383
- await this.cache.deleteDocument("drives-slug", input.global.slug);
12447
+ await this.cache.deleteDriveBySlug(input.global.slug);
12384
12448
  }
12385
12449
  await this._initializeDrive(id);
12386
12450
  this.eventEmitter.emit("driveAdded", document);
@@ -12412,7 +12476,7 @@ var BaseDocumentDriveServer = class {
12412
12476
  const result = await Promise.allSettled([
12413
12477
  this.stopSyncRemoteDrive(driveId),
12414
12478
  this.listenerManager.removeDrive(driveId),
12415
- this.cache.deleteDocument("drives", driveId),
12479
+ this.cache.deleteDrive(driveId),
12416
12480
  this.storage.deleteDrive(driveId)
12417
12481
  ]);
12418
12482
  result.forEach((r) => {
@@ -12427,7 +12491,7 @@ var BaseDocumentDriveServer = class {
12427
12491
  async getDrive(driveId, options) {
12428
12492
  let document;
12429
12493
  try {
12430
- const cachedDocument = await this.cache.getDocument("drives", driveId);
12494
+ const cachedDocument = await this.cache.getDrive(driveId);
12431
12495
  if (cachedDocument && isDocumentDrive(cachedDocument)) {
12432
12496
  document = cachedDocument;
12433
12497
  if (isAtRevision(document, options?.revisions)) {
@@ -12443,16 +12507,16 @@ var BaseDocumentDriveServer = class {
12443
12507
  throw new Error(`Document with id ${driveId} is not a Document Drive`);
12444
12508
  } else {
12445
12509
  if (!options?.revisions) {
12446
- this.cache.setDocument("drives", driveId, result).catch(logger.error);
12510
+ this.cache.setDrive(driveId, result).catch(logger.error);
12447
12511
  }
12448
12512
  return result;
12449
12513
  }
12450
12514
  }
12451
12515
  async getDriveBySlug(slug, options) {
12452
12516
  try {
12453
- const document2 = await this.cache.getDocument("drives-slug", slug);
12454
- if (document2 && isDocumentDrive(document2)) {
12455
- return document2;
12517
+ const drive = await this.cache.getDriveBySlug(slug);
12518
+ if (drive) {
12519
+ return drive;
12456
12520
  }
12457
12521
  } catch (e) {
12458
12522
  logger.error("Error getting drive from cache", e);
@@ -12462,14 +12526,14 @@ var BaseDocumentDriveServer = class {
12462
12526
  if (!isDocumentDrive(document)) {
12463
12527
  throw new Error(`Document with slug ${slug} is not a Document Drive`);
12464
12528
  } else {
12465
- this.cache.setDocument("drives-slug", slug, document).catch(logger.error);
12529
+ this.cache.setDriveBySlug(slug, document).catch(logger.error);
12466
12530
  return document;
12467
12531
  }
12468
12532
  }
12469
12533
  async getDocument(driveId, documentId, options) {
12470
12534
  let cachedDocument;
12471
12535
  try {
12472
- cachedDocument = await this.cache.getDocument(driveId, documentId);
12536
+ cachedDocument = await this.cache.getDocument(documentId);
12473
12537
  if (cachedDocument && isAtRevision(cachedDocument, options?.revisions)) {
12474
12538
  return cachedDocument;
12475
12539
  }
@@ -12479,7 +12543,7 @@ var BaseDocumentDriveServer = class {
12479
12543
  const documentStorage = cachedDocument ?? await this.storage.getDocument(driveId, documentId);
12480
12544
  const document = this._buildDocument(documentStorage, options);
12481
12545
  if (!options?.revisions) {
12482
- this.cache.setDocument(driveId, documentId, document).catch(logger.error);
12546
+ this.cache.setDocument(documentId, document).catch(logger.error);
12483
12547
  }
12484
12548
  return document;
12485
12549
  }
@@ -12536,7 +12600,7 @@ var BaseDocumentDriveServer = class {
12536
12600
  } catch (error) {
12537
12601
  logger.warn("Error deleting document", error);
12538
12602
  }
12539
- await this.cache.deleteDocument(driveId, documentId);
12603
+ await this.cache.deleteDocument(documentId);
12540
12604
  return this.storage.deleteDocument(driveId, documentId);
12541
12605
  }
12542
12606
  async _processOperations(driveId, documentId, documentStorage, operations) {
@@ -12824,7 +12888,7 @@ var BaseDocumentDriveServer = class {
12824
12888
  };
12825
12889
  });
12826
12890
  if (document) {
12827
- this.cache.setDocument(driveId, documentId, document).catch(logger.error);
12891
+ this.cache.setDocument(documentId, document).catch(logger.error);
12828
12892
  }
12829
12893
  const { scopes, branches } = operationsApplied.reduce((acc, operation) => {
12830
12894
  if (!acc.scopes.includes(operation.scope)) {
@@ -12986,7 +13050,7 @@ var BaseDocumentDriveServer = class {
12986
13050
  if (!document || !isDocumentDrive(document)) {
12987
13051
  throw error ?? new Error("Invalid Document Drive document");
12988
13052
  }
12989
- this.cache.setDocument("drives", driveId, document).catch(logger.error);
13053
+ this.cache.setDrive(driveId, document).catch(logger.error);
12990
13054
  const lastOperation = operationsApplied.filter((op) => op.scope === "global").slice().pop();
12991
13055
  if (lastOperation) {
12992
13056
  const newOp = operationsApplied.find((appliedOp) => !operations.find((o) => o.id === appliedOp.id && o.index === appliedOp.index && o.skip === appliedOp.skip && o.hash === appliedOp.hash));
@@ -12995,7 +13059,6 @@ var BaseDocumentDriveServer = class {
12995
13059
  this.listenerManager.updateSynchronizationRevisions(driveId, [
12996
13060
  {
12997
13061
  syncId: "0",
12998
- driveId,
12999
13062
  documentId: "",
13000
13063
  scope: "global",
13001
13064
  branch: "main",
@@ -13306,7 +13369,7 @@ var ListenerManager = class _ListenerManager {
13306
13369
  this.logger.verbose(`Abandoning push for sync unit ${syncUnit.syncId}: already up-to-date (${unitState.listenerRev} >= ${syncUnit.revision})`);
13307
13370
  return;
13308
13371
  } else {
13309
- this.logger.verbose(`Listener out-of-date for sync unit (${syncUnit.driveId}, ${syncUnit.scope}, ${syncUnit.documentId}): ${unitState?.listenerRev} < ${syncUnit.revision}`);
13372
+ this.logger.verbose(`Listener out-of-date for sync unit (${syncUnit.scope}, ${syncUnit.documentId}): ${unitState?.listenerRev} < ${syncUnit.revision}`);
13310
13373
  }
13311
13374
  const opData = [];
13312
13375
  try {
@@ -13461,11 +13524,11 @@ var ListenerManager = class _ListenerManager {
13461
13524
  if (entry && entry.listenerRev >= syncUnit.revision) {
13462
13525
  return;
13463
13526
  }
13464
- const { documentId, driveId: driveId2, scope, branch } = syncUnit;
13527
+ const { documentId, scope, branch } = syncUnit;
13465
13528
  try {
13466
13529
  const operations = await this.syncManager.getOperationData(
13467
13530
  // DEAL WITH INVALID SYNC ID ERROR
13468
- driveId2,
13531
+ driveId,
13469
13532
  syncUnit.syncId,
13470
13533
  {
13471
13534
  since: options?.since,
@@ -13478,7 +13541,7 @@ var ListenerManager = class _ListenerManager {
13478
13541
  }
13479
13542
  operationsCount += operations.length;
13480
13543
  strands.push({
13481
- driveId: driveId2,
13544
+ driveId,
13482
13545
  documentId,
13483
13546
  scope,
13484
13547
  branch,
@@ -13639,26 +13702,18 @@ var SynchronizationManager = class {
13639
13702
  async getSynchronizationUnitsRevision(driveId, syncUnitsQuery) {
13640
13703
  const drive = await this.getDrive(driveId);
13641
13704
  const revisions = await this.storage.getSynchronizationUnitsRevision(syncUnitsQuery);
13642
- const synchronizationUnits = syncUnitsQuery.map((s) => ({
13705
+ return syncUnitsQuery.map((s) => ({
13643
13706
  ...s,
13644
13707
  lastUpdated: drive.created,
13645
- revision: -1
13708
+ revision: revisions.find((r) => r.documentId === s.documentId && r.scope === s.scope && r.branch === s.branch)?.revision ?? -1
13646
13709
  }));
13647
- for (const revision of revisions) {
13648
- const syncUnit = synchronizationUnits.find((s) => revision.driveId === s.driveId && revision.documentId === s.documentId && revision.scope === s.scope && revision.branch === s.branch);
13649
- if (syncUnit) {
13650
- syncUnit.revision = revision.revision;
13651
- syncUnit.lastUpdated = revision.lastUpdated;
13652
- }
13653
- }
13654
- return synchronizationUnits;
13655
13710
  }
13656
13711
  async getSynchronizationUnitsIds(driveId, documentId, scope, branch, documentType2) {
13657
13712
  const drive = await this.getDrive(driveId);
13658
13713
  const nodes = drive.state.global.nodes.filter((node) => isFileNode(node) && (!documentId?.length || documentId.includes(node.id) || documentId.includes("*")) && (!documentType2?.length || documentType2.includes(node.documentType) || documentType2.includes("*")));
13659
13714
  if ((!documentId || documentId.includes("*") || documentId.includes("")) && (!documentType2?.length || documentType2.includes("powerhouse/document-drive") || documentType2.includes("*"))) {
13660
13715
  nodes.unshift({
13661
- id: "",
13716
+ id: drive.state.global.id,
13662
13717
  documentType: "powerhouse/document-drive",
13663
13718
  synchronizationUnits: [
13664
13719
  {
@@ -13700,7 +13755,6 @@ var SynchronizationManager = class {
13700
13755
  syncId,
13701
13756
  scope: syncUnit.scope,
13702
13757
  branch: syncUnit.branch,
13703
- driveId,
13704
13758
  documentId: node.id,
13705
13759
  documentType: node.documentType
13706
13760
  };
@@ -13718,7 +13772,6 @@ var SynchronizationManager = class {
13718
13772
  syncId,
13719
13773
  scope,
13720
13774
  branch,
13721
- driveId,
13722
13775
  documentId,
13723
13776
  documentType: documentType2,
13724
13777
  lastUpdated: lastOperation.timestamp ?? document.lastModified,
@@ -13747,7 +13800,7 @@ var SynchronizationManager = class {
13747
13800
  }
13748
13801
  async getDrive(driveId) {
13749
13802
  try {
13750
- const cachedDocument = await this.cache.getDocument("drives", driveId);
13803
+ const cachedDocument = await this.cache.getDrive(driveId);
13751
13804
  if (cachedDocument && isDocumentDrive(cachedDocument)) {
13752
13805
  return cachedDocument;
13753
13806
  }
@@ -13763,7 +13816,7 @@ var SynchronizationManager = class {
13763
13816
  }
13764
13817
  async getDocument(driveId, documentId) {
13765
13818
  try {
13766
- const cachedDocument = await this.cache.getDocument(driveId, documentId);
13819
+ const cachedDocument = await this.cache.getDocument(documentId);
13767
13820
  if (cachedDocument) {
13768
13821
  return cachedDocument;
13769
13822
  }
@@ -8,7 +8,7 @@ import {
8
8
  isFolderNode,
9
9
  moveNode,
10
10
  updateNode
11
- } from "./chunk-YOX3ZAET.js";
11
+ } from "./chunk-A4GIWVYS.js";
12
12
  import {
13
13
  generateId
14
14
  } from "./chunk-FQF4YAVC.js";
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-P6NJ6IAQ.js";
7
7
  import {
8
8
  ReadDriveNotFoundError
9
- } from "./chunk-YOX3ZAET.js";
9
+ } from "./chunk-A4GIWVYS.js";
10
10
 
11
11
  // ../../packages/reactor-browser/dist/src/context/read-mode.js
12
12
  import { jsx as _jsx } from "react/jsx-runtime";