@powerhousedao/connect 1.0.0-dev.245 → 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 (28) hide show
  1. package/dist/.env +0 -5
  2. package/dist/assets/{app-BH-6rUAk.js → app-BT03qzg4.js} +14 -56
  3. package/dist/assets/{app-76Vr3j5e.css → app-D9QJBr8i.css} +1 -1
  4. package/dist/assets/{app-loader-CQdXsdrs.js → app-loader-Cp_C_kSQ.js} +282 -172
  5. package/dist/assets/{ccip-DzlgrM-Q.js → ccip-rCu2dOKk.js} +3 -3
  6. package/dist/assets/{content-CGSfY9bJ.js → content-B1RXkSXz.js} +3 -3
  7. package/dist/assets/{index-Ck0OHqQ0.js → index-CJbQZ7hP.js} +3 -3
  8. package/dist/assets/{index-BR7pEetO.js → index-DX2bXpNe.js} +3 -3
  9. package/dist/assets/{index-Boh2tg26.js → index-a5VEmfQw.js} +4 -4
  10. package/dist/assets/{main.PwF6jbJu.js → main.Hm4UID1Z.js} +1 -1
  11. package/dist/external-packages.js +5 -0
  12. package/dist/hmr.js +4 -1
  13. package/dist/index.html +1 -4
  14. package/dist/modules/@powerhousedao/reactor-browser/{chunk-4AV4NYOH.js → chunk-A4GIWVYS.js} +216 -149
  15. package/dist/modules/@powerhousedao/reactor-browser/{chunk-QVHWUIBE.js → chunk-PQ4UODLR.js} +1 -1
  16. package/dist/modules/@powerhousedao/reactor-browser/{chunk-GZM7UEXF.js → chunk-UP4DC4D2.js} +1 -1
  17. package/dist/modules/@powerhousedao/reactor-browser/{chunk-K62SYQYI.js → chunk-XXFOSD4A.js} +53 -5
  18. package/dist/modules/@powerhousedao/reactor-browser/{chunk-UIXXJKR2.js → chunk-YDERCA5J.js} +1 -1
  19. package/dist/modules/@powerhousedao/reactor-browser/context/index.js +2 -2
  20. package/dist/modules/@powerhousedao/reactor-browser/context/read-mode.js +2 -2
  21. package/dist/modules/@powerhousedao/reactor-browser/hooks/index.js +3 -3
  22. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActions.js +2 -2
  23. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActionsWithUiNodes.js +3 -3
  24. package/dist/modules/@powerhousedao/reactor-browser/index.js +5 -5
  25. package/dist/modules/@powerhousedao/reactor-browser/reactor.js +2 -2
  26. package/dist/swEnv.js +0 -3
  27. package/dist/vite-envs.sh +1 -28
  28. package/package.json +6 -6
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/app-BH-6rUAk.js","assets/main.PwF6jbJu.js","assets/app-76Vr3j5e.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.PwF6jbJu.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,156 +86,78 @@ class DocumentEditorDebugTools {
86
86
  this.document = void 0;
87
87
  }
88
88
  }
89
- var define_process_env_default = {};
90
- const LEVELS = {
91
- verbose: 1,
92
- debug: 2,
93
- info: 3,
94
- warn: 4,
95
- error: 5,
96
- silent: 6
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 } };
97
99
  };
98
- class ConsoleLogger {
99
- constructor(tags, errorHandler2) {
100
- __privateAdd(this, _ConsoleLogger_instances);
101
- __privateAdd(this, _tags);
102
- __privateAdd(this, _levelString, "env");
103
- __privateAdd(this, _errorHandler);
104
- __privateSet(this, _tags, (tags || []).map((tag) => `[${tag}]`));
105
- __privateSet(this, _errorHandler, errorHandler2);
106
- this.log = this.log.bind(this);
107
- this.info = this.info.bind(this);
108
- this.warn = this.warn.bind(this);
109
- this.error = this.error.bind(this);
110
- this.debug = this.debug.bind(this);
111
- this.verbose = this.verbose.bind(this);
112
- }
113
- get level() {
114
- return __privateGet(this, _levelString);
115
- }
116
- set level(level) {
117
- __privateSet(this, _levelString, level);
118
- }
119
- get errorHandler() {
120
- return __privateGet(this, _errorHandler);
121
- }
122
- set errorHandler(handler) {
123
- __privateSet(this, _errorHandler, handler);
100
+ class InMemoryCache {
101
+ constructor() {
102
+ __publicField(this, "idTodocument", /* @__PURE__ */ new Map());
103
+ __publicField(this, "idToDrive", /* @__PURE__ */ new Map());
104
+ __publicField(this, "slugToDriveId", /* @__PURE__ */ new Map());
124
105
  }
125
- log(...data) {
126
- return this.debug(...data);
106
+ clear() {
107
+ this.idTodocument.clear();
108
+ this.idToDrive.clear();
109
+ this.slugToDriveId.clear();
127
110
  }
128
- verbose(...data) {
129
- if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.verbose) {
130
- return;
131
- }
132
- return this.debug(...data);
111
+ /////////////////////////////////////////////////////////////////////////////
112
+ // ICache
113
+ /////////////////////////////////////////////////////////////////////////////
114
+ async setDocument(documentId, document) {
115
+ const doc = trimResultingState(document);
116
+ this.idTodocument.set(documentId, doc);
133
117
  }
134
- debug(...data) {
135
- if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.debug) {
136
- return;
137
- }
138
- return console.debug(...[...__privateGet(this, _tags), ...data]);
118
+ async getDocument(documentId) {
119
+ return this.idTodocument.get(documentId);
139
120
  }
140
- info(...data) {
141
- if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.info) {
142
- return;
143
- }
144
- return console.info(...[...__privateGet(this, _tags), ...data]);
121
+ async deleteDocument(documentId) {
122
+ return this.idTodocument.delete(documentId);
145
123
  }
146
- warn(...data) {
147
- if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.warn) {
148
- return;
149
- }
150
- return console.warn(...[...__privateGet(this, _tags), ...data]);
124
+ async setDrive(driveId, drive) {
125
+ const doc = trimResultingState(drive);
126
+ this.idToDrive.set(driveId, doc);
151
127
  }
152
- error(...data) {
153
- if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.error) {
154
- return;
155
- }
156
- if (__privateGet(this, _errorHandler)) {
157
- __privateGet(this, _errorHandler).call(this, ...data);
158
- }
159
- return console.error(...[...__privateGet(this, _tags), ...data]);
128
+ async getDrive(driveId) {
129
+ return this.idToDrive.get(driveId);
160
130
  }
161
- }
162
- _tags = new WeakMap();
163
- _levelString = new WeakMap();
164
- _errorHandler = new WeakMap();
165
- _ConsoleLogger_instances = new WeakSet();
166
- levelValue_get = function() {
167
- if (__privateGet(this, _levelString) === "env") {
168
- const envLevel = typeof process !== "undefined" ? define_process_env_default.LOG_LEVEL : void 0;
169
- if (!envLevel) {
170
- return LEVELS.debug;
131
+ async deleteDrive(driveId) {
132
+ const drive = this.idToDrive.get(driveId);
133
+ if (!drive) {
134
+ return false;
171
135
  }
172
- if (!(envLevel in LEVELS)) {
173
- return LEVELS.debug;
136
+ const slug = drive.state.global.slug;
137
+ if (slug) {
138
+ this.slugToDriveId.delete(slug);
174
139
  }
175
- return LEVELS[envLevel];
140
+ return this.idToDrive.delete(driveId);
176
141
  }
177
- return LEVELS[__privateGet(this, _levelString)];
178
- };
179
- const loggerInstance = new ConsoleLogger();
180
- let logLevel = "env";
181
- let errorHandler;
182
- loggerInstance.level = logLevel;
183
- loggerInstance.errorHandler = errorHandler;
184
- const logger$1 = loggerInstance;
185
- const setErrorHandler = (handler) => {
186
- errorHandler = handler;
187
- loggerInstance.errorHandler = handler;
188
- };
189
- const setLogLevel = (level) => {
190
- logLevel = level;
191
- loggerInstance.level = level;
192
- };
193
- const childLogger = (tags) => {
194
- const logger2 = new ConsoleLogger(tags);
195
- logger2.level = logLevel;
196
- logger2.errorHandler = errorHandler;
197
- return logger2;
198
- };
199
- class InMemoryCache {
200
- constructor() {
201
- __publicField(this, "cache", /* @__PURE__ */ new Map());
202
- }
203
- clear() {
204
- this.cache.clear();
142
+ async setDriveBySlug(slug, drive) {
143
+ const driveId = drive.state.global.id;
144
+ this.slugToDriveId.set(slug, driveId);
145
+ this.setDrive(driveId, drive);
205
146
  }
206
- async setDocument(drive, id, document) {
207
- var _a2;
208
- const global2 = document.operations.global.map((e) => {
209
- delete e.resultingState;
210
- return e;
211
- });
212
- const local = document.operations.local.map((e) => {
213
- delete e.resultingState;
214
- return e;
215
- });
216
- const doc = { ...document, operations: { global: global2, local } };
217
- if (!this.cache.has(drive)) {
218
- this.cache.set(drive, /* @__PURE__ */ new Map());
147
+ async getDriveBySlug(slug) {
148
+ const driveId = this.slugToDriveId.get(slug);
149
+ if (!driveId) {
150
+ return void 0;
219
151
  }
220
- (_a2 = this.cache.get(drive)) == null ? void 0 : _a2.set(id, doc);
221
- return true;
222
- }
223
- async deleteDocument(drive, id) {
224
- var _a2;
225
- return ((_a2 = this.cache.get(drive)) == null ? void 0 : _a2.delete(id)) ?? false;
152
+ return this.getDrive(driveId);
226
153
  }
227
- async getDocument(drive, id) {
228
- var _a2;
229
- return (_a2 = this.cache.get(drive)) == null ? void 0 : _a2.get(id);
230
- }
231
- async getCachedOperations(drive, id) {
232
- try {
233
- const document = await this.getDocument(drive, id);
234
- return document == null ? void 0 : document.operations;
235
- } catch (error) {
236
- logger$1.error(error);
237
- return void 0;
154
+ async deleteDriveBySlug(slug) {
155
+ const driveId = this.slugToDriveId.get(slug);
156
+ if (!driveId) {
157
+ return false;
238
158
  }
159
+ this.slugToDriveId.delete(slug);
160
+ return this.deleteDrive(driveId);
239
161
  }
240
162
  }
241
163
  const K = [
@@ -11494,6 +11416,116 @@ const driveDocumentModelModule = {
11494
11416
  actions: { ...creators, ...actions },
11495
11417
  utils: { ...documentModelUtils, ...customUtils }
11496
11418
  };
11419
+ var define_process_env_default = {};
11420
+ const LEVELS = {
11421
+ verbose: 1,
11422
+ debug: 2,
11423
+ info: 3,
11424
+ warn: 4,
11425
+ error: 5,
11426
+ silent: 6
11427
+ };
11428
+ class ConsoleLogger {
11429
+ constructor(tags, errorHandler2) {
11430
+ __privateAdd(this, _ConsoleLogger_instances);
11431
+ __privateAdd(this, _tags);
11432
+ __privateAdd(this, _levelString, "env");
11433
+ __privateAdd(this, _errorHandler);
11434
+ __privateSet(this, _tags, (tags || []).map((tag) => `[${tag}]`));
11435
+ __privateSet(this, _errorHandler, errorHandler2);
11436
+ this.log = this.log.bind(this);
11437
+ this.info = this.info.bind(this);
11438
+ this.warn = this.warn.bind(this);
11439
+ this.error = this.error.bind(this);
11440
+ this.debug = this.debug.bind(this);
11441
+ this.verbose = this.verbose.bind(this);
11442
+ }
11443
+ get level() {
11444
+ return __privateGet(this, _levelString);
11445
+ }
11446
+ set level(level) {
11447
+ __privateSet(this, _levelString, level);
11448
+ }
11449
+ get errorHandler() {
11450
+ return __privateGet(this, _errorHandler);
11451
+ }
11452
+ set errorHandler(handler) {
11453
+ __privateSet(this, _errorHandler, handler);
11454
+ }
11455
+ log(...data) {
11456
+ return this.debug(...data);
11457
+ }
11458
+ verbose(...data) {
11459
+ if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.verbose) {
11460
+ return;
11461
+ }
11462
+ return this.debug(...data);
11463
+ }
11464
+ debug(...data) {
11465
+ if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.debug) {
11466
+ return;
11467
+ }
11468
+ return console.debug(...[...__privateGet(this, _tags), ...data]);
11469
+ }
11470
+ info(...data) {
11471
+ if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.info) {
11472
+ return;
11473
+ }
11474
+ return console.info(...[...__privateGet(this, _tags), ...data]);
11475
+ }
11476
+ warn(...data) {
11477
+ if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.warn) {
11478
+ return;
11479
+ }
11480
+ return console.warn(...[...__privateGet(this, _tags), ...data]);
11481
+ }
11482
+ error(...data) {
11483
+ if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.error) {
11484
+ return;
11485
+ }
11486
+ if (__privateGet(this, _errorHandler)) {
11487
+ __privateGet(this, _errorHandler).call(this, ...data);
11488
+ }
11489
+ return console.error(...[...__privateGet(this, _tags), ...data]);
11490
+ }
11491
+ }
11492
+ _tags = new WeakMap();
11493
+ _levelString = new WeakMap();
11494
+ _errorHandler = new WeakMap();
11495
+ _ConsoleLogger_instances = new WeakSet();
11496
+ levelValue_get = function() {
11497
+ if (__privateGet(this, _levelString) === "env") {
11498
+ const envLevel = typeof process !== "undefined" ? define_process_env_default.LOG_LEVEL : void 0;
11499
+ if (!envLevel) {
11500
+ return LEVELS.debug;
11501
+ }
11502
+ if (!(envLevel in LEVELS)) {
11503
+ return LEVELS.debug;
11504
+ }
11505
+ return LEVELS[envLevel];
11506
+ }
11507
+ return LEVELS[__privateGet(this, _levelString)];
11508
+ };
11509
+ const loggerInstance = new ConsoleLogger();
11510
+ let logLevel = "env";
11511
+ let errorHandler;
11512
+ loggerInstance.level = logLevel;
11513
+ loggerInstance.errorHandler = errorHandler;
11514
+ const logger$1 = loggerInstance;
11515
+ const setErrorHandler = (handler) => {
11516
+ errorHandler = handler;
11517
+ loggerInstance.errorHandler = handler;
11518
+ };
11519
+ const setLogLevel = (level) => {
11520
+ logLevel = level;
11521
+ loggerInstance.level = level;
11522
+ };
11523
+ const childLogger = (tags) => {
11524
+ const logger2 = new ConsoleLogger(tags);
11525
+ logger2.level = logLevel;
11526
+ logger2.errorHandler = errorHandler;
11527
+ return logger2;
11528
+ };
11497
11529
  class DocumentModelNotFoundError extends Error {
11498
11530
  constructor(id, cause) {
11499
11531
  super(`Document model "${id}" not found`, { cause });
@@ -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));
@@ -23814,6 +23846,44 @@ class MemoryStorage {
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,7 +23891,7 @@ 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) {
@@ -23833,7 +23903,7 @@ class MemoryStorage {
23833
23903
  }
23834
23904
  async createDocument(drive, id, document) {
23835
23905
  await this.create(id, document);
23836
- const manifest = this.getDriveManifest(drive);
23906
+ const manifest = this.getManifest(drive);
23837
23907
  manifest.documentIds.add(id);
23838
23908
  this.updateDriveManifest(drive, manifest);
23839
23909
  }
@@ -23850,15 +23920,7 @@ class MemoryStorage {
23850
23920
  };
23851
23921
  }
23852
23922
  async deleteDocument(drive, id) {
23853
- const drives = await this.getDrives();
23854
- for (const driveId of drives) {
23855
- const manifest = this.getDriveManifest(driveId);
23856
- if (manifest.documentIds.has(id)) {
23857
- manifest.documentIds.delete(id);
23858
- this.updateDriveManifest(driveId, manifest);
23859
- }
23860
- }
23861
- delete this.documents[id];
23923
+ this.delete(id);
23862
23924
  }
23863
23925
  async getDrives() {
23864
23926
  return Object.keys(this.driveManifests);
@@ -23904,14 +23966,14 @@ class MemoryStorage {
23904
23966
  };
23905
23967
  }
23906
23968
  async deleteDrive(id) {
23907
- const manifest = this.getDriveManifest(id);
23969
+ const manifest = this.getManifest(id);
23908
23970
  const drives = await this.getDrives();
23909
23971
  await Promise.all([...manifest.documentIds].map((docId) => {
23910
23972
  for (const driveId of drives) {
23911
23973
  if (driveId === id) {
23912
23974
  continue;
23913
23975
  }
23914
- const manifest2 = this.getDriveManifest(driveId);
23976
+ const manifest2 = this.getManifest(driveId);
23915
23977
  if (manifest2.documentIds.has(docId)) {
23916
23978
  return;
23917
23979
  }
@@ -23952,7 +24014,7 @@ class MemoryStorage {
23952
24014
  ////////////////////////////////
23953
24015
  // Private
23954
24016
  ////////////////////////////////
23955
- getDriveManifest(driveId) {
24017
+ getManifest(driveId) {
23956
24018
  if (!this.driveManifests[driveId]) {
23957
24019
  this.driveManifests[driveId] = { documentIds: /* @__PURE__ */ new Set() };
23958
24020
  }
@@ -24676,7 +24738,7 @@ class SynchronizationManager {
24676
24738
  }
24677
24739
  async getDrive(driveId) {
24678
24740
  try {
24679
- const cachedDocument = await this.cache.getDocument("drives", driveId);
24741
+ const cachedDocument = await this.cache.getDrive(driveId);
24680
24742
  if (cachedDocument && isDocumentDrive(cachedDocument)) {
24681
24743
  return cachedDocument;
24682
24744
  }
@@ -24692,7 +24754,7 @@ class SynchronizationManager {
24692
24754
  }
24693
24755
  async getDocument(driveId, documentId) {
24694
24756
  try {
24695
- const cachedDocument = await this.cache.getDocument(driveId, documentId);
24757
+ const cachedDocument = await this.cache.getDocument(documentId);
24696
24758
  if (cachedDocument) {
24697
24759
  return cachedDocument;
24698
24760
  }
@@ -25533,7 +25595,7 @@ const nodeOptionsMap = {
25533
25595
  };
25534
25596
  const name = "@powerhousedao/connect";
25535
25597
  const productName = "Powerhouse-Connect";
25536
- const version$1 = "1.0.0-dev.245";
25598
+ const version$1 = "1.0.0-dev.246";
25537
25599
  const description = "Powerhouse Connect";
25538
25600
  const main = "./dist/index.html";
25539
25601
  const type = "module";
@@ -28326,6 +28388,10 @@ const _BrowserStorage = class _BrowserStorage {
28326
28388
  name: namespace ? `${namespace}:${_BrowserStorage.DBName}` : _BrowserStorage.DBName
28327
28389
  }));
28328
28390
  }
28391
+ async clear() {
28392
+ const db = await this.db;
28393
+ await db.clear();
28394
+ }
28329
28395
  ////////////////////////////////
28330
28396
  // IDocumentStorage
28331
28397
  ////////////////////////////////
@@ -28346,13 +28412,57 @@ const _BrowserStorage = class _BrowserStorage {
28346
28412
  }
28347
28413
  return document;
28348
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
+ }
28349
28459
  ////////////////////////////////
28350
28460
  // IDriveStorage
28351
28461
  ////////////////////////////////
28352
28462
  checkDocumentExists(drive, documentId) {
28353
28463
  return this.exists(documentId);
28354
28464
  }
28355
- async getDriveManifest(driveId) {
28465
+ async getManifest(driveId) {
28356
28466
  const db = await this.db;
28357
28467
  const manifest = await db.getItem(this.buildManifestKey(driveId));
28358
28468
  return manifest || { documentIds: [] };
@@ -28362,7 +28472,7 @@ const _BrowserStorage = class _BrowserStorage {
28362
28472
  await db.setItem(this.buildManifestKey(driveId), manifest);
28363
28473
  }
28364
28474
  async getDocuments(drive) {
28365
- const manifest = await this.getDriveManifest(drive);
28475
+ const manifest = await this.getManifest(drive);
28366
28476
  return manifest.documentIds;
28367
28477
  }
28368
28478
  async getDocument(driveId, id) {
@@ -28370,7 +28480,7 @@ const _BrowserStorage = class _BrowserStorage {
28370
28480
  }
28371
28481
  async createDocument(drive, id, document) {
28372
28482
  await this.create(id, document);
28373
- const manifest = await this.getDriveManifest(drive);
28483
+ const manifest = await this.getManifest(drive);
28374
28484
  if (!manifest.documentIds.includes(id)) {
28375
28485
  manifest.documentIds.push(id);
28376
28486
  await this.updateDriveManifest(drive, manifest);
@@ -28378,7 +28488,7 @@ const _BrowserStorage = class _BrowserStorage {
28378
28488
  }
28379
28489
  async deleteDocument(drive, id) {
28380
28490
  await (await this.db).removeItem(this.buildDocumentKey(id));
28381
- const manifest = await this.getDriveManifest(drive);
28491
+ const manifest = await this.getManifest(drive);
28382
28492
  const docIndex = manifest.documentIds.indexOf(id);
28383
28493
  if (docIndex !== -1) {
28384
28494
  manifest.documentIds.splice(docIndex, 1);
@@ -31125,7 +31235,7 @@ if (window.__VITE_ENVS.MODE === "development") {
31125
31235
  } else {
31126
31236
  serviceWorkerManager.registerServiceWorker(false);
31127
31237
  }
31128
- const App = lazy(() => __vitePreload(() => import("./app-BH-6rUAk.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));
31129
31239
  const AppLoader = /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(App, {}) });
31130
31240
  const appLoader = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
31131
31241
  __proto__: null,