@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
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/app-DR3WlBLu.js","assets/main.CwbMf_Nf.js","assets/app-D3TxLTK-.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/app-BT03qzg4.js","assets/main.Hm4UID1Z.js","assets/app-D9QJBr8i.css"])))=>i.map(i=>d[i]);
2
2
  var __defProp = Object.defineProperty;
3
3
  var __typeError = (msg) => {
4
4
  throw TypeError(msg);
@@ -11,7 +11,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11
11
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
12
12
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
13
13
  var _tags, _levelString, _errorHandler, _ConsoleLogger_instances, levelValue_get, _getDocumentModelModule, _drives, _ReadModeService_instances, parseGraphQLErrors_fn, fetchDrive_fn, _a, _ServiceWorkerManager_instances, handleServiceWorkerMessage_fn, handleServiceWorker_fn;
14
- import { _ as __vitePreload } from "./main.CwbMf_Nf.js";
14
+ import { _ as __vitePreload } from "./main.Hm4UID1Z.js";
15
15
  import { jsx, jsxs } from "react/jsx-runtime";
16
16
  import { useState, useEffect, Suspense, lazy } from "react";
17
17
  function _mergeNamespaces(n, m) {
@@ -86,34 +86,78 @@ class DocumentEditorDebugTools {
86
86
  this.document = void 0;
87
87
  }
88
88
  }
89
+ const trimResultingState = (document) => {
90
+ const global2 = document.operations.global.map((e) => {
91
+ delete e.resultingState;
92
+ return e;
93
+ });
94
+ const local = document.operations.local.map((e) => {
95
+ delete e.resultingState;
96
+ return e;
97
+ });
98
+ return { ...document, operations: { global: global2, local } };
99
+ };
89
100
  class InMemoryCache {
90
101
  constructor() {
91
- __publicField(this, "cache", /* @__PURE__ */ new Map());
102
+ __publicField(this, "idTodocument", /* @__PURE__ */ new Map());
103
+ __publicField(this, "idToDrive", /* @__PURE__ */ new Map());
104
+ __publicField(this, "slugToDriveId", /* @__PURE__ */ new Map());
92
105
  }
93
- async setDocument(drive, id, document) {
94
- var _a2;
95
- const global2 = document.operations.global.map((e) => {
96
- delete e.resultingState;
97
- return e;
98
- });
99
- const local = document.operations.local.map((e) => {
100
- delete e.resultingState;
101
- return e;
102
- });
103
- const doc = { ...document, operations: { global: global2, local } };
104
- if (!this.cache.has(drive)) {
105
- this.cache.set(drive, /* @__PURE__ */ new Map());
106
+ clear() {
107
+ this.idTodocument.clear();
108
+ this.idToDrive.clear();
109
+ this.slugToDriveId.clear();
110
+ }
111
+ /////////////////////////////////////////////////////////////////////////////
112
+ // ICache
113
+ /////////////////////////////////////////////////////////////////////////////
114
+ async setDocument(documentId, document) {
115
+ const doc = trimResultingState(document);
116
+ this.idTodocument.set(documentId, doc);
117
+ }
118
+ async getDocument(documentId) {
119
+ return this.idTodocument.get(documentId);
120
+ }
121
+ async deleteDocument(documentId) {
122
+ return this.idTodocument.delete(documentId);
123
+ }
124
+ async setDrive(driveId, drive) {
125
+ const doc = trimResultingState(drive);
126
+ this.idToDrive.set(driveId, doc);
127
+ }
128
+ async getDrive(driveId) {
129
+ return this.idToDrive.get(driveId);
130
+ }
131
+ async deleteDrive(driveId) {
132
+ const drive = this.idToDrive.get(driveId);
133
+ if (!drive) {
134
+ return false;
106
135
  }
107
- (_a2 = this.cache.get(drive)) == null ? void 0 : _a2.set(id, doc);
108
- return true;
136
+ const slug = drive.state.global.slug;
137
+ if (slug) {
138
+ this.slugToDriveId.delete(slug);
139
+ }
140
+ return this.idToDrive.delete(driveId);
109
141
  }
110
- async deleteDocument(drive, id) {
111
- var _a2;
112
- return ((_a2 = this.cache.get(drive)) == null ? void 0 : _a2.delete(id)) ?? false;
142
+ async setDriveBySlug(slug, drive) {
143
+ const driveId = drive.state.global.id;
144
+ this.slugToDriveId.set(slug, driveId);
145
+ this.setDrive(driveId, drive);
113
146
  }
114
- async getDocument(drive, id) {
115
- var _a2;
116
- return (_a2 = this.cache.get(drive)) == null ? void 0 : _a2.get(id);
147
+ async getDriveBySlug(slug) {
148
+ const driveId = this.slugToDriveId.get(slug);
149
+ if (!driveId) {
150
+ return void 0;
151
+ }
152
+ return this.getDrive(driveId);
153
+ }
154
+ async deleteDriveBySlug(slug) {
155
+ const driveId = this.slugToDriveId.get(slug);
156
+ if (!driveId) {
157
+ return false;
158
+ }
159
+ this.slugToDriveId.delete(slug);
160
+ return this.deleteDrive(driveId);
117
161
  }
118
162
  }
119
163
  const K = [
@@ -22497,7 +22541,7 @@ const _PullResponderTransmitter = class _PullResponderTransmitter {
22497
22541
  const syncUnits = await this.manager.getListenerSyncUnitIds(driveId, listenerId);
22498
22542
  let success = true;
22499
22543
  for (const revision of revisions) {
22500
- const syncUnit = syncUnits.find((s) => s.scope === revision.scope && s.branch === revision.branch && s.driveId === revision.driveId && s.documentId == revision.documentId);
22544
+ const syncUnit = syncUnits.find((s) => s.scope === revision.scope && s.branch === revision.branch && s.documentId == revision.documentId);
22501
22545
  if (!syncUnit) {
22502
22546
  this.logger.warn("Unknown sync unit was acknowledged", revision);
22503
22547
  success = false;
@@ -22814,7 +22858,6 @@ class BaseDocumentDriveServer {
22814
22858
  // internal state
22815
22859
  __publicField(this, "triggerMap", /* @__PURE__ */ new Map());
22816
22860
  __publicField(this, "initializePromise");
22817
- var _a2, _b;
22818
22861
  this.documentModelModules = documentModelModules;
22819
22862
  this.storage = storage;
22820
22863
  this.documentStorage = documentStorage;
@@ -22835,17 +22878,6 @@ class BaseDocumentDriveServer {
22835
22878
  taskQueueMethod: (options == null ? void 0 : options.taskQueueMethod) === void 0 ? RunAsap.runAsap : options.taskQueueMethod
22836
22879
  };
22837
22880
  this.defaultDrivesManager = new DefaultDrivesManager(this, this.defaultDrivesManagerDelegate, options);
22838
- (_b = (_a2 = this.storage).setStorageDelegate) == null ? void 0 : _b.call(_a2, {
22839
- getCachedOperations: async (drive, id) => {
22840
- try {
22841
- const document = await this.cache.getDocument(drive, id);
22842
- return document == null ? void 0 : document.operations;
22843
- } catch (error) {
22844
- logger$1.error(error);
22845
- return void 0;
22846
- }
22847
- }
22848
- });
22849
22881
  this.initializePromise = this._initialize();
22850
22882
  }
22851
22883
  // workaround for testing the ephemeral listeners -- we don't have DI in place yet
@@ -23033,7 +23065,7 @@ class BaseDocumentDriveServer {
23033
23065
  };
23034
23066
  await this.storage.createDrive(id, document);
23035
23067
  if (input.global.slug) {
23036
- await this.cache.deleteDocument("drives-slug", input.global.slug);
23068
+ await this.cache.deleteDriveBySlug(input.global.slug);
23037
23069
  }
23038
23070
  await this._initializeDrive(id);
23039
23071
  this.eventEmitter.emit("driveAdded", document);
@@ -23065,7 +23097,7 @@ class BaseDocumentDriveServer {
23065
23097
  const result = await Promise.allSettled([
23066
23098
  this.stopSyncRemoteDrive(driveId),
23067
23099
  this.listenerManager.removeDrive(driveId),
23068
- this.cache.deleteDocument("drives", driveId),
23100
+ this.cache.deleteDrive(driveId),
23069
23101
  this.storage.deleteDrive(driveId)
23070
23102
  ]);
23071
23103
  result.forEach((r) => {
@@ -23080,7 +23112,7 @@ class BaseDocumentDriveServer {
23080
23112
  async getDrive(driveId, options) {
23081
23113
  let document;
23082
23114
  try {
23083
- const cachedDocument = await this.cache.getDocument("drives", driveId);
23115
+ const cachedDocument = await this.cache.getDrive(driveId);
23084
23116
  if (cachedDocument && isDocumentDrive(cachedDocument)) {
23085
23117
  document = cachedDocument;
23086
23118
  if (isAtRevision(document, options == null ? void 0 : options.revisions)) {
@@ -23096,16 +23128,16 @@ class BaseDocumentDriveServer {
23096
23128
  throw new Error(`Document with id ${driveId} is not a Document Drive`);
23097
23129
  } else {
23098
23130
  if (!(options == null ? void 0 : options.revisions)) {
23099
- this.cache.setDocument("drives", driveId, result).catch(logger$1.error);
23131
+ this.cache.setDrive(driveId, result).catch(logger$1.error);
23100
23132
  }
23101
23133
  return result;
23102
23134
  }
23103
23135
  }
23104
23136
  async getDriveBySlug(slug, options) {
23105
23137
  try {
23106
- const document2 = await this.cache.getDocument("drives-slug", slug);
23107
- if (document2 && isDocumentDrive(document2)) {
23108
- return document2;
23138
+ const drive = await this.cache.getDriveBySlug(slug);
23139
+ if (drive) {
23140
+ return drive;
23109
23141
  }
23110
23142
  } catch (e) {
23111
23143
  logger$1.error("Error getting drive from cache", e);
@@ -23115,14 +23147,14 @@ class BaseDocumentDriveServer {
23115
23147
  if (!isDocumentDrive(document)) {
23116
23148
  throw new Error(`Document with slug ${slug} is not a Document Drive`);
23117
23149
  } else {
23118
- this.cache.setDocument("drives-slug", slug, document).catch(logger$1.error);
23150
+ this.cache.setDriveBySlug(slug, document).catch(logger$1.error);
23119
23151
  return document;
23120
23152
  }
23121
23153
  }
23122
23154
  async getDocument(driveId, documentId, options) {
23123
23155
  let cachedDocument;
23124
23156
  try {
23125
- cachedDocument = await this.cache.getDocument(driveId, documentId);
23157
+ cachedDocument = await this.cache.getDocument(documentId);
23126
23158
  if (cachedDocument && isAtRevision(cachedDocument, options == null ? void 0 : options.revisions)) {
23127
23159
  return cachedDocument;
23128
23160
  }
@@ -23132,7 +23164,7 @@ class BaseDocumentDriveServer {
23132
23164
  const documentStorage = cachedDocument ?? await this.storage.getDocument(driveId, documentId);
23133
23165
  const document = this._buildDocument(documentStorage, options);
23134
23166
  if (!(options == null ? void 0 : options.revisions)) {
23135
- this.cache.setDocument(driveId, documentId, document).catch(logger$1.error);
23167
+ this.cache.setDocument(documentId, document).catch(logger$1.error);
23136
23168
  }
23137
23169
  return document;
23138
23170
  }
@@ -23189,7 +23221,7 @@ class BaseDocumentDriveServer {
23189
23221
  } catch (error) {
23190
23222
  logger$1.warn("Error deleting document", error);
23191
23223
  }
23192
- await this.cache.deleteDocument(driveId, documentId);
23224
+ await this.cache.deleteDocument(documentId);
23193
23225
  return this.storage.deleteDocument(driveId, documentId);
23194
23226
  }
23195
23227
  async _processOperations(driveId, documentId, documentStorage, operations) {
@@ -23479,7 +23511,7 @@ class BaseDocumentDriveServer {
23479
23511
  };
23480
23512
  });
23481
23513
  if (document) {
23482
- this.cache.setDocument(driveId, documentId, document).catch(logger$1.error);
23514
+ this.cache.setDocument(documentId, document).catch(logger$1.error);
23483
23515
  }
23484
23516
  const { scopes, branches } = operationsApplied.reduce((acc, operation) => {
23485
23517
  if (!acc.scopes.includes(operation.scope)) {
@@ -23642,7 +23674,7 @@ class BaseDocumentDriveServer {
23642
23674
  if (!document || !isDocumentDrive(document)) {
23643
23675
  throw error ?? new Error("Invalid Document Drive document");
23644
23676
  }
23645
- this.cache.setDocument("drives", driveId, document).catch(logger$1.error);
23677
+ this.cache.setDrive(driveId, document).catch(logger$1.error);
23646
23678
  const lastOperation = operationsApplied.filter((op) => op.scope === "global").slice().pop();
23647
23679
  if (lastOperation) {
23648
23680
  const newOp = operationsApplied.find((appliedOp) => !operations.find((o) => o.id === appliedOp.id && o.index === appliedOp.index && o.skip === appliedOp.skip && o.hash === appliedOp.hash));
@@ -23651,7 +23683,6 @@ class BaseDocumentDriveServer {
23651
23683
  this.listenerManager.updateSynchronizationRevisions(driveId, [
23652
23684
  {
23653
23685
  syncId: "0",
23654
- driveId,
23655
23686
  documentId: "",
23656
23687
  scope: "global",
23657
23688
  branch: "main",
@@ -23790,18 +23821,15 @@ const DocumentDriveServer = ReadModeServer(BaseDocumentDriveServer);
23790
23821
  class MemoryStorage {
23791
23822
  constructor() {
23792
23823
  __publicField(this, "documents");
23793
- __publicField(this, "drives");
23794
23824
  __publicField(this, "driveManifests");
23795
- __publicField(this, "slugToDriveId", {});
23796
23825
  this.documents = {};
23797
- this.drives = {};
23798
23826
  this.driveManifests = {};
23799
23827
  }
23800
23828
  ////////////////////////////////
23801
23829
  // IDocumentStorage
23802
23830
  ////////////////////////////////
23803
23831
  exists(documentId) {
23804
- return Promise.resolve(!!this.documents[documentId]);
23832
+ return Promise.resolve(!!this.documents[documentId] || !!this.documents[`drive/${documentId}`]);
23805
23833
  }
23806
23834
  create(documentId, document) {
23807
23835
  this.documents[documentId] = document;
@@ -23810,10 +23838,52 @@ class MemoryStorage {
23810
23838
  get(documentId) {
23811
23839
  const document = this.documents[documentId];
23812
23840
  if (!document) {
23841
+ const drive = this.documents[`drive/${documentId}`];
23842
+ if (drive) {
23843
+ return Promise.resolve(drive);
23844
+ }
23813
23845
  throw new Error(`Document with id ${documentId} not found`);
23814
23846
  }
23815
23847
  return Promise.resolve(document);
23816
23848
  }
23849
+ async delete(documentId) {
23850
+ const drives = await this.getDrives();
23851
+ for (const driveId of drives) {
23852
+ if (driveId === documentId)
23853
+ continue;
23854
+ await this.removeChild(driveId, documentId);
23855
+ }
23856
+ delete this.driveManifests[documentId];
23857
+ if (this.documents[documentId]) {
23858
+ delete this.documents[documentId];
23859
+ return Promise.resolve(true);
23860
+ }
23861
+ return Promise.resolve(false);
23862
+ }
23863
+ async addChild(parentId, childId) {
23864
+ if (parentId === childId) {
23865
+ throw new Error("Cannot associate a document with itself");
23866
+ }
23867
+ const children = await this.getChildren(childId);
23868
+ if (children.includes(parentId)) {
23869
+ throw new Error("Cannot associate a document with its child");
23870
+ }
23871
+ const manifest = this.getManifest(parentId);
23872
+ manifest.documentIds.add(childId);
23873
+ this.updateDriveManifest(parentId, manifest);
23874
+ }
23875
+ async removeChild(parentId, childId) {
23876
+ const manifest = this.getManifest(parentId);
23877
+ if (manifest.documentIds.delete(childId)) {
23878
+ this.updateDriveManifest(parentId, manifest);
23879
+ return true;
23880
+ }
23881
+ return false;
23882
+ }
23883
+ async getChildren(parentId) {
23884
+ const manifest = this.getManifest(parentId);
23885
+ return [...manifest.documentIds];
23886
+ }
23817
23887
  ////////////////////////////////
23818
23888
  // IDriveStorage
23819
23889
  ////////////////////////////////
@@ -23821,27 +23891,19 @@ class MemoryStorage {
23821
23891
  return this.exists(id);
23822
23892
  }
23823
23893
  getDocuments(drive) {
23824
- const manifest = this.getDriveManifest(drive);
23894
+ const manifest = this.getManifest(drive);
23825
23895
  return Promise.resolve([...manifest.documentIds]);
23826
23896
  }
23827
23897
  getDocument(driveId, id) {
23828
23898
  return this.get(id);
23829
23899
  }
23830
- async saveDocument(drive, id, document) {
23831
- this.documents[id] = document;
23832
- const manifest = this.getDriveManifest(drive);
23833
- manifest.documentIds.add(id);
23834
- this.updateDriveManifest(drive, manifest);
23835
- }
23836
23900
  async clearStorage() {
23837
23901
  this.documents = {};
23838
- this.drives = {};
23839
23902
  this.driveManifests = {};
23840
- this.slugToDriveId = {};
23841
23903
  }
23842
23904
  async createDocument(drive, id, document) {
23843
23905
  await this.create(id, document);
23844
- const manifest = this.getDriveManifest(drive);
23906
+ const manifest = this.getManifest(drive);
23845
23907
  manifest.documentIds.add(id);
23846
23908
  this.updateDriveManifest(drive, manifest);
23847
23909
  }
@@ -23858,59 +23920,60 @@ class MemoryStorage {
23858
23920
  };
23859
23921
  }
23860
23922
  async deleteDocument(drive, id) {
23861
- const drives = await this.getDrives();
23862
- for (const driveId of drives) {
23863
- const manifest = this.getDriveManifest(driveId);
23864
- if (manifest.documentIds.has(id)) {
23865
- manifest.documentIds.delete(id);
23866
- this.updateDriveManifest(driveId, manifest);
23867
- }
23868
- }
23869
- delete this.documents[id];
23923
+ this.delete(id);
23870
23924
  }
23871
23925
  async getDrives() {
23872
- return Object.keys(this.drives);
23926
+ return Object.keys(this.driveManifests);
23873
23927
  }
23874
23928
  async getDrive(id) {
23875
- const drive = this.drives[id];
23929
+ const drive = this.documents[`drive/${id}`];
23876
23930
  if (!drive) {
23877
23931
  throw new DriveNotFoundError(id);
23878
23932
  }
23879
23933
  return drive;
23880
23934
  }
23881
23935
  async getDriveBySlug(slug) {
23882
- const driveId = this.slugToDriveId[slug];
23883
- if (!driveId) {
23884
- throw new Error(`Drive with slug ${slug} not found`);
23936
+ for (const driveId of Object.keys(this.driveManifests)) {
23937
+ const drive = this.documents[`drive/${driveId}`];
23938
+ if (drive.initialState.state.global.slug === slug) {
23939
+ return drive;
23940
+ }
23885
23941
  }
23886
- return this.getDrive(driveId);
23942
+ throw new Error(`Drive with slug ${slug} not found`);
23887
23943
  }
23888
23944
  async createDrive(id, drive) {
23889
- this.drives[id] = drive;
23890
- this.updateDriveManifest(id, { documentIds: /* @__PURE__ */ new Set() });
23891
- const { slug } = drive.initialState.state.global;
23945
+ const slug = drive.initialState.state.global.slug;
23892
23946
  if (slug) {
23893
- this.slugToDriveId[slug] = id;
23947
+ let existingDrive;
23948
+ try {
23949
+ existingDrive = await this.getDriveBySlug(slug);
23950
+ } catch {
23951
+ }
23952
+ if (existingDrive) {
23953
+ throw new Error(`Drive with slug ${slug} already exists`);
23954
+ }
23894
23955
  }
23956
+ await this.create(`drive/${id}`, drive);
23957
+ this.updateDriveManifest(id, { documentIds: /* @__PURE__ */ new Set() });
23895
23958
  }
23896
23959
  async addDriveOperations(id, operations, header) {
23897
23960
  const drive = await this.getDrive(id);
23898
23961
  const mergedOperations = mergeOperations(drive.operations, operations);
23899
- this.drives[id] = {
23962
+ this.documents[`drive/${id}`] = {
23900
23963
  ...drive,
23901
23964
  ...header,
23902
23965
  operations: mergedOperations
23903
23966
  };
23904
23967
  }
23905
23968
  async deleteDrive(id) {
23906
- const manifest = this.getDriveManifest(id);
23969
+ const manifest = this.getManifest(id);
23907
23970
  const drives = await this.getDrives();
23908
23971
  await Promise.all([...manifest.documentIds].map((docId) => {
23909
23972
  for (const driveId of drives) {
23910
23973
  if (driveId === id) {
23911
23974
  continue;
23912
23975
  }
23913
- const manifest2 = this.getDriveManifest(driveId);
23976
+ const manifest2 = this.getManifest(driveId);
23914
23977
  if (manifest2.documentIds.has(docId)) {
23915
23978
  return;
23916
23979
  }
@@ -23918,24 +23981,18 @@ class MemoryStorage {
23918
23981
  delete this.documents[docId];
23919
23982
  }));
23920
23983
  delete this.driveManifests[id];
23921
- delete this.drives[id];
23922
- for (const [slug, driveId] of Object.entries(this.slugToDriveId)) {
23923
- if (driveId === id) {
23924
- delete this.slugToDriveId[slug];
23925
- }
23926
- }
23984
+ delete this.documents[id];
23927
23985
  }
23928
23986
  async getSynchronizationUnitsRevision(units) {
23929
23987
  const results = await Promise.allSettled(units.map(async (unit) => {
23930
23988
  try {
23931
- const document = await (unit.documentId ? this.getDocument(unit.driveId, unit.documentId) : this.getDrive(unit.driveId));
23989
+ const document = await this.get(unit.documentId);
23932
23990
  if (!document) {
23933
23991
  return void 0;
23934
23992
  }
23935
23993
  const operation = document.operations[unit.scope].at(-1);
23936
23994
  if (operation) {
23937
23995
  return {
23938
- driveId: unit.driveId,
23939
23996
  documentId: unit.documentId,
23940
23997
  scope: unit.scope,
23941
23998
  branch: unit.branch,
@@ -23957,7 +24014,7 @@ class MemoryStorage {
23957
24014
  ////////////////////////////////
23958
24015
  // Private
23959
24016
  ////////////////////////////////
23960
- getDriveManifest(driveId) {
24017
+ getManifest(driveId) {
23961
24018
  if (!this.driveManifests[driveId]) {
23962
24019
  this.driveManifests[driveId] = { documentIds: /* @__PURE__ */ new Set() };
23963
24020
  }
@@ -24138,7 +24195,7 @@ const _ListenerManager = class _ListenerManager {
24138
24195
  this.logger.verbose(`Abandoning push for sync unit ${syncUnit.syncId}: already up-to-date (${unitState.listenerRev} >= ${syncUnit.revision})`);
24139
24196
  return;
24140
24197
  } else {
24141
- this.logger.verbose(`Listener out-of-date for sync unit (${syncUnit.driveId}, ${syncUnit.scope}, ${syncUnit.documentId}): ${unitState == null ? void 0 : unitState.listenerRev} < ${syncUnit.revision}`);
24198
+ this.logger.verbose(`Listener out-of-date for sync unit (${syncUnit.scope}, ${syncUnit.documentId}): ${unitState == null ? void 0 : unitState.listenerRev} < ${syncUnit.revision}`);
24142
24199
  }
24143
24200
  const opData = [];
24144
24201
  try {
@@ -24296,11 +24353,11 @@ const _ListenerManager = class _ListenerManager {
24296
24353
  if (entry && entry.listenerRev >= syncUnit.revision) {
24297
24354
  return;
24298
24355
  }
24299
- const { documentId, driveId: driveId2, scope, branch } = syncUnit;
24356
+ const { documentId, scope, branch } = syncUnit;
24300
24357
  try {
24301
24358
  const operations = await this.syncManager.getOperationData(
24302
24359
  // DEAL WITH INVALID SYNC ID ERROR
24303
- driveId2,
24360
+ driveId,
24304
24361
  syncUnit.syncId,
24305
24362
  {
24306
24363
  since: options == null ? void 0 : options.since,
@@ -24313,7 +24370,7 @@ const _ListenerManager = class _ListenerManager {
24313
24370
  }
24314
24371
  operationsCount += operations.length;
24315
24372
  strands.push({
24316
- driveId: driveId2,
24373
+ driveId,
24317
24374
  documentId,
24318
24375
  scope,
24319
24376
  branch,
@@ -24580,26 +24637,21 @@ class SynchronizationManager {
24580
24637
  async getSynchronizationUnitsRevision(driveId, syncUnitsQuery) {
24581
24638
  const drive = await this.getDrive(driveId);
24582
24639
  const revisions = await this.storage.getSynchronizationUnitsRevision(syncUnitsQuery);
24583
- const synchronizationUnits = syncUnitsQuery.map((s) => ({
24584
- ...s,
24585
- lastUpdated: drive.created,
24586
- revision: -1
24587
- }));
24588
- for (const revision of revisions) {
24589
- const syncUnit = synchronizationUnits.find((s) => revision.driveId === s.driveId && revision.documentId === s.documentId && revision.scope === s.scope && revision.branch === s.branch);
24590
- if (syncUnit) {
24591
- syncUnit.revision = revision.revision;
24592
- syncUnit.lastUpdated = revision.lastUpdated;
24593
- }
24594
- }
24595
- return synchronizationUnits;
24640
+ return syncUnitsQuery.map((s) => {
24641
+ var _a2;
24642
+ return {
24643
+ ...s,
24644
+ lastUpdated: drive.created,
24645
+ revision: ((_a2 = revisions.find((r) => r.documentId === s.documentId && r.scope === s.scope && r.branch === s.branch)) == null ? void 0 : _a2.revision) ?? -1
24646
+ };
24647
+ });
24596
24648
  }
24597
24649
  async getSynchronizationUnitsIds(driveId, documentId, scope, branch, documentType2) {
24598
24650
  const drive = await this.getDrive(driveId);
24599
24651
  const nodes = drive.state.global.nodes.filter((node) => isFileNode(node) && (!(documentId == null ? void 0 : documentId.length) || documentId.includes(node.id) || documentId.includes("*")) && (!(documentType2 == null ? void 0 : documentType2.length) || documentType2.includes(node.documentType) || documentType2.includes("*")));
24600
24652
  if ((!documentId || documentId.includes("*") || documentId.includes("")) && (!(documentType2 == null ? void 0 : documentType2.length) || documentType2.includes("powerhouse/document-drive") || documentType2.includes("*"))) {
24601
24653
  nodes.unshift({
24602
- id: "",
24654
+ id: drive.state.global.id,
24603
24655
  documentType: "powerhouse/document-drive",
24604
24656
  synchronizationUnits: [
24605
24657
  {
@@ -24641,7 +24693,6 @@ class SynchronizationManager {
24641
24693
  syncId,
24642
24694
  scope: syncUnit.scope,
24643
24695
  branch: syncUnit.branch,
24644
- driveId,
24645
24696
  documentId: node.id,
24646
24697
  documentType: node.documentType
24647
24698
  };
@@ -24659,7 +24710,6 @@ class SynchronizationManager {
24659
24710
  syncId,
24660
24711
  scope,
24661
24712
  branch,
24662
- driveId,
24663
24713
  documentId,
24664
24714
  documentType: documentType2,
24665
24715
  lastUpdated: lastOperation.timestamp ?? document.lastModified,
@@ -24688,7 +24738,7 @@ class SynchronizationManager {
24688
24738
  }
24689
24739
  async getDrive(driveId) {
24690
24740
  try {
24691
- const cachedDocument = await this.cache.getDocument("drives", driveId);
24741
+ const cachedDocument = await this.cache.getDrive(driveId);
24692
24742
  if (cachedDocument && isDocumentDrive(cachedDocument)) {
24693
24743
  return cachedDocument;
24694
24744
  }
@@ -24704,7 +24754,7 @@ class SynchronizationManager {
24704
24754
  }
24705
24755
  async getDocument(driveId, documentId) {
24706
24756
  try {
24707
- const cachedDocument = await this.cache.getDocument(driveId, documentId);
24757
+ const cachedDocument = await this.cache.getDocument(documentId);
24708
24758
  if (cachedDocument) {
24709
24759
  return cachedDocument;
24710
24760
  }
@@ -25545,7 +25595,7 @@ const nodeOptionsMap = {
25545
25595
  };
25546
25596
  const name = "@powerhousedao/connect";
25547
25597
  const productName = "Powerhouse-Connect";
25548
- const version$1 = "1.0.0-dev.244";
25598
+ const version$1 = "1.0.0-dev.246";
25549
25599
  const description = "Powerhouse Connect";
25550
25600
  const main = "./dist/index.html";
25551
25601
  const type = "module";
@@ -28338,6 +28388,10 @@ const _BrowserStorage = class _BrowserStorage {
28338
28388
  name: namespace ? `${namespace}:${_BrowserStorage.DBName}` : _BrowserStorage.DBName
28339
28389
  }));
28340
28390
  }
28391
+ async clear() {
28392
+ const db = await this.db;
28393
+ await db.clear();
28394
+ }
28341
28395
  ////////////////////////////////
28342
28396
  // IDocumentStorage
28343
28397
  ////////////////////////////////
@@ -28358,13 +28412,57 @@ const _BrowserStorage = class _BrowserStorage {
28358
28412
  }
28359
28413
  return document;
28360
28414
  }
28415
+ async delete(documentId) {
28416
+ const db = await this.db;
28417
+ const document = await db.getItem(this.buildDocumentKey(documentId));
28418
+ if (!document) {
28419
+ return false;
28420
+ }
28421
+ const drives = await this.getDrives();
28422
+ for (const driveId of drives) {
28423
+ if (driveId === documentId)
28424
+ continue;
28425
+ await this.removeChild(driveId, documentId);
28426
+ }
28427
+ await db.removeItem(this.buildManifestKey(documentId));
28428
+ await db.removeItem(this.buildDocumentKey(documentId));
28429
+ return true;
28430
+ }
28431
+ async removeChild(parentId, childId) {
28432
+ const manifest = await this.getManifest(parentId);
28433
+ const docIndex = manifest.documentIds.indexOf(childId);
28434
+ if (docIndex !== -1) {
28435
+ manifest.documentIds.splice(docIndex, 1);
28436
+ await this.updateDriveManifest(parentId, manifest);
28437
+ return true;
28438
+ }
28439
+ return false;
28440
+ }
28441
+ async addChild(parentId, childId) {
28442
+ if (parentId === childId) {
28443
+ throw new Error("Cannot associate a document with itself");
28444
+ }
28445
+ const children = await this.getChildren(childId);
28446
+ if (children.includes(parentId)) {
28447
+ throw new Error("Cannot associate a document with its child");
28448
+ }
28449
+ const manifest = await this.getManifest(parentId);
28450
+ if (!manifest.documentIds.includes(childId)) {
28451
+ manifest.documentIds.push(childId);
28452
+ await this.updateDriveManifest(parentId, manifest);
28453
+ }
28454
+ }
28455
+ async getChildren(parentId) {
28456
+ const manifest = await this.getManifest(parentId);
28457
+ return manifest.documentIds;
28458
+ }
28361
28459
  ////////////////////////////////
28362
28460
  // IDriveStorage
28363
28461
  ////////////////////////////////
28364
28462
  checkDocumentExists(drive, documentId) {
28365
28463
  return this.exists(documentId);
28366
28464
  }
28367
- async getDriveManifest(driveId) {
28465
+ async getManifest(driveId) {
28368
28466
  const db = await this.db;
28369
28467
  const manifest = await db.getItem(this.buildManifestKey(driveId));
28370
28468
  return manifest || { documentIds: [] };
@@ -28374,7 +28472,7 @@ const _BrowserStorage = class _BrowserStorage {
28374
28472
  await db.setItem(this.buildManifestKey(driveId), manifest);
28375
28473
  }
28376
28474
  async getDocuments(drive) {
28377
- const manifest = await this.getDriveManifest(drive);
28475
+ const manifest = await this.getManifest(drive);
28378
28476
  return manifest.documentIds;
28379
28477
  }
28380
28478
  async getDocument(driveId, id) {
@@ -28382,7 +28480,7 @@ const _BrowserStorage = class _BrowserStorage {
28382
28480
  }
28383
28481
  async createDocument(drive, id, document) {
28384
28482
  await this.create(id, document);
28385
- const manifest = await this.getDriveManifest(drive);
28483
+ const manifest = await this.getManifest(drive);
28386
28484
  if (!manifest.documentIds.includes(id)) {
28387
28485
  manifest.documentIds.push(id);
28388
28486
  await this.updateDriveManifest(drive, manifest);
@@ -28390,7 +28488,7 @@ const _BrowserStorage = class _BrowserStorage {
28390
28488
  }
28391
28489
  async deleteDocument(drive, id) {
28392
28490
  await (await this.db).removeItem(this.buildDocumentKey(id));
28393
- const manifest = await this.getDriveManifest(drive);
28491
+ const manifest = await this.getManifest(drive);
28394
28492
  const docIndex = manifest.documentIds.indexOf(id);
28395
28493
  if (docIndex !== -1) {
28396
28494
  manifest.documentIds.splice(docIndex, 1);
@@ -28416,12 +28514,13 @@ const _BrowserStorage = class _BrowserStorage {
28416
28514
  async getDrives() {
28417
28515
  const db = await this.db;
28418
28516
  const keys = await db.keys();
28419
- return keys.filter((key) => key.startsWith(_BrowserStorage.DRIVES_KEY)).map((key) => key.slice(_BrowserStorage.DRIVES_KEY.length + _BrowserStorage.SEP.length));
28517
+ return keys.filter((key) => key.startsWith(_BrowserStorage.MANIFEST_KEY)).map((key) => key.slice(_BrowserStorage.MANIFEST_KEY.length + _BrowserStorage.SEP.length));
28420
28518
  }
28421
28519
  async getDrive(id) {
28422
- const db = await this.db;
28423
- const drive = await db.getItem(this.buildDriveKey(id));
28424
- if (!drive) {
28520
+ let drive;
28521
+ try {
28522
+ drive = await this.get(id);
28523
+ } catch {
28425
28524
  throw new DriveNotFoundError(id);
28426
28525
  }
28427
28526
  return drive;
@@ -28437,8 +28536,18 @@ const _BrowserStorage = class _BrowserStorage {
28437
28536
  throw new Error(`Drive with slug ${slug} not found`);
28438
28537
  }
28439
28538
  async createDrive(id, drive) {
28440
- const db = await this.db;
28441
- await db.setItem(this.buildDriveKey(id), drive);
28539
+ const slug = drive.initialState.state.global.slug;
28540
+ if (slug) {
28541
+ let existingDrive;
28542
+ try {
28543
+ existingDrive = await this.getDriveBySlug(slug);
28544
+ } catch {
28545
+ }
28546
+ if (existingDrive) {
28547
+ throw new Error(`Drive with slug ${slug} already exists`);
28548
+ }
28549
+ }
28550
+ await this.create(id, drive);
28442
28551
  await this.updateDriveManifest(id, { documentIds: [] });
28443
28552
  }
28444
28553
  async deleteDrive(id) {
@@ -28446,13 +28555,13 @@ const _BrowserStorage = class _BrowserStorage {
28446
28555
  await Promise.all(documents.map((doc) => this.deleteDocument(id, doc)));
28447
28556
  const db = await this.db;
28448
28557
  await db.removeItem(this.buildManifestKey(id));
28449
- return db.removeItem(this.buildDriveKey(id));
28558
+ return db.removeItem(this.buildDocumentKey(id));
28450
28559
  }
28451
28560
  async addDriveOperations(id, operations, header) {
28452
28561
  const drive = await this.getDrive(id);
28453
28562
  const mergedOperations = mergeOperations(drive.operations, operations);
28454
28563
  const db = await this.db;
28455
- await db.setItem(this.buildDriveKey(id), {
28564
+ await db.setItem(this.buildDocumentKey(id), {
28456
28565
  ...drive,
28457
28566
  ...header,
28458
28567
  operations: mergedOperations
@@ -28461,14 +28570,13 @@ const _BrowserStorage = class _BrowserStorage {
28461
28570
  async getSynchronizationUnitsRevision(units) {
28462
28571
  const results = await Promise.allSettled(units.map(async (unit) => {
28463
28572
  try {
28464
- const document = await (unit.documentId ? this.getDocument(unit.driveId, unit.documentId) : this.getDrive(unit.driveId));
28573
+ const document = await this.get(unit.documentId);
28465
28574
  if (!document) {
28466
28575
  return void 0;
28467
28576
  }
28468
28577
  const operation = document.operations[unit.scope].at(-1);
28469
28578
  if (operation) {
28470
28579
  return {
28471
- driveId: unit.driveId,
28472
28580
  documentId: unit.documentId,
28473
28581
  scope: unit.scope,
28474
28582
  branch: unit.branch,
@@ -28500,7 +28608,7 @@ const _BrowserStorage = class _BrowserStorage {
28500
28608
  const drive = await this.getDrive(driveId);
28501
28609
  const migratedDrive = migrateDocumentOperationSignatures(drive);
28502
28610
  if (migratedDrive !== drive) {
28503
- return (await this.db).setItem(this.buildDriveKey(driveId), migratedDrive);
28611
+ return (await this.db).setItem(this.buildDocumentKey(driveId), migratedDrive);
28504
28612
  }
28505
28613
  }
28506
28614
  async migrateDocument(drive, id) {
@@ -28513,9 +28621,6 @@ const _BrowserStorage = class _BrowserStorage {
28513
28621
  ////////////////////////////////
28514
28622
  // Private methods
28515
28623
  ////////////////////////////////
28516
- buildDriveKey(driveId) {
28517
- return `${_BrowserStorage.DRIVES_KEY}${_BrowserStorage.SEP}${driveId}`;
28518
- }
28519
28624
  buildDocumentKey(documentId) {
28520
28625
  return `${_BrowserStorage.DOCUMENT_KEY}${_BrowserStorage.SEP}${documentId}`;
28521
28626
  }
@@ -28525,7 +28630,6 @@ const _BrowserStorage = class _BrowserStorage {
28525
28630
  };
28526
28631
  __publicField(_BrowserStorage, "DBName", "DOCUMENT_DRIVES");
28527
28632
  __publicField(_BrowserStorage, "SEP", ":");
28528
- __publicField(_BrowserStorage, "DRIVES_KEY", "DRIVES");
28529
28633
  __publicField(_BrowserStorage, "DOCUMENT_KEY", "DOCUMENT");
28530
28634
  __publicField(_BrowserStorage, "MANIFEST_KEY", "MANIFEST");
28531
28635
  let BrowserStorage = _BrowserStorage;
@@ -31131,7 +31235,7 @@ if (window.__VITE_ENVS.MODE === "development") {
31131
31235
  } else {
31132
31236
  serviceWorkerManager.registerServiceWorker(false);
31133
31237
  }
31134
- const App = lazy(() => __vitePreload(() => import("./app-DR3WlBLu.js").then((n) => n.aN), true ? __vite__mapDeps([0,1,2]) : void 0));
31238
+ const App = lazy(() => __vitePreload(() => import("./app-BT03qzg4.js").then((n) => n.aN), true ? __vite__mapDeps([0,1,2]) : void 0));
31135
31239
  const AppLoader = /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(App, {}) });
31136
31240
  const appLoader = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
31137
31241
  __proto__: null,