@powerhousedao/connect 1.0.0-dev.245 → 1.0.0-dev.247

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-Bjaniq_f.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-CnDRDKWw.js} +500 -369
  5. package/dist/assets/{ccip-DzlgrM-Q.js → ccip-BIN6bp0k.js} +3 -3
  6. package/dist/assets/{content-CGSfY9bJ.js → content-CT8IEBqv.js} +3 -3
  7. package/dist/assets/{index-Boh2tg26.js → index-BaBnabbX.js} +4 -4
  8. package/dist/assets/{index-BR7pEetO.js → index-BeBd0Q5I.js} +3 -3
  9. package/dist/assets/{index-Ck0OHqQ0.js → index-CWxXMTAJ.js} +3 -3
  10. package/dist/assets/{main.PwF6jbJu.js → main.DonDJ7tf.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-K62SYQYI.js → chunk-6MBHOHAA.js} +53 -5
  15. package/dist/modules/@powerhousedao/reactor-browser/{chunk-UIXXJKR2.js → chunk-IC6B3767.js} +1 -1
  16. package/dist/modules/@powerhousedao/reactor-browser/{chunk-4AV4NYOH.js → chunk-N5UNGAA6.js} +310 -223
  17. package/dist/modules/@powerhousedao/reactor-browser/{chunk-GZM7UEXF.js → chunk-OYYVE7RP.js} +1 -1
  18. package/dist/modules/@powerhousedao/reactor-browser/{chunk-QVHWUIBE.js → chunk-UDKYG6I4.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 +7 -7
@@ -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-Bjaniq_f.js","assets/main.DonDJ7tf.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.DonDJ7tf.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];
176
- }
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());
140
+ return this.idToDrive.delete(driveId);
202
141
  }
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;
226
- }
227
- async getDocument(drive, id) {
228
- var _a2;
229
- return (_a2 = this.cache.get(drive)) == null ? void 0 : _a2.get(id);
152
+ return this.getDrive(driveId);
230
153
  }
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 });
@@ -22754,22 +22786,203 @@ __publicField(_PullResponderTransmitter, "staticLogger", childLogger([
22754
22786
  "static"
22755
22787
  ]));
22756
22788
  let PullResponderTransmitter = _PullResponderTransmitter;
22757
- var TransmitterType;
22758
- (function(TransmitterType2) {
22759
- TransmitterType2[TransmitterType2["Internal"] = 0] = "Internal";
22760
- TransmitterType2[TransmitterType2["SwitchboardPush"] = 1] = "SwitchboardPush";
22761
- TransmitterType2[TransmitterType2["PullResponder"] = 2] = "PullResponder";
22762
- TransmitterType2[TransmitterType2["SecureConnect"] = 3] = "SecureConnect";
22763
- TransmitterType2[TransmitterType2["MatrixConnect"] = 4] = "MatrixConnect";
22764
- TransmitterType2[TransmitterType2["RESTWebhook"] = 5] = "RESTWebhook";
22765
- })(TransmitterType || (TransmitterType = {}));
22766
- const DefaultListenerManagerOptions = {
22767
- sequentialUpdates: true
22768
- };
22769
- function filterOperationsByRevision(operations, revisions) {
22770
- if (!revisions) {
22771
- return operations;
22772
- }
22789
+ var defaults;
22790
+ var hasRequiredDefaults;
22791
+ function requireDefaults() {
22792
+ if (hasRequiredDefaults) return defaults;
22793
+ hasRequiredDefaults = 1;
22794
+ defaults = {
22795
+ space: "",
22796
+ cycles: false,
22797
+ replacer: (k, v) => v,
22798
+ stringify: JSON.stringify
22799
+ };
22800
+ return defaults;
22801
+ }
22802
+ var util;
22803
+ var hasRequiredUtil;
22804
+ function requireUtil() {
22805
+ if (hasRequiredUtil) return util;
22806
+ hasRequiredUtil = 1;
22807
+ util = {
22808
+ isArray: Array.isArray,
22809
+ assign: Object.assign,
22810
+ isObject: (v) => typeof v === "object",
22811
+ isFunction: (v) => typeof v === "function",
22812
+ isBoolean: (v) => typeof v === "boolean",
22813
+ isRegex: (v) => v instanceof RegExp,
22814
+ keys: Object.keys
22815
+ };
22816
+ return util;
22817
+ }
22818
+ var lib;
22819
+ var hasRequiredLib;
22820
+ function requireLib() {
22821
+ if (hasRequiredLib) return lib;
22822
+ hasRequiredLib = 1;
22823
+ const DEFAULTS = requireDefaults();
22824
+ const isFunction = requireUtil().isFunction;
22825
+ const isBoolean = requireUtil().isBoolean;
22826
+ const isObject = requireUtil().isObject;
22827
+ const isArray = requireUtil().isArray;
22828
+ const isRegex = requireUtil().isRegex;
22829
+ const assign = requireUtil().assign;
22830
+ const keys = requireUtil().keys;
22831
+ function serialize(obj) {
22832
+ if (obj === null || obj === void 0) return obj;
22833
+ if (isRegex(obj)) return obj.toString();
22834
+ return obj.toJSON ? obj.toJSON() : obj;
22835
+ }
22836
+ function stringifyDeterministic(obj, opts) {
22837
+ opts = opts || assign({}, DEFAULTS);
22838
+ if (isFunction(opts)) opts = { compare: opts };
22839
+ const space = opts.space || DEFAULTS.space;
22840
+ const cycles = isBoolean(opts.cycles) ? opts.cycles : DEFAULTS.cycles;
22841
+ const replacer = opts.replacer || DEFAULTS.replacer;
22842
+ const stringify2 = opts.stringify || DEFAULTS.stringify;
22843
+ const compare = opts.compare && /* @__PURE__ */ function(f) {
22844
+ return function(node) {
22845
+ return function(a, b) {
22846
+ const aobj = { key: a, value: node[a] };
22847
+ const bobj = { key: b, value: node[b] };
22848
+ return f(aobj, bobj);
22849
+ };
22850
+ };
22851
+ }(opts.compare);
22852
+ if (!cycles) stringify2(obj);
22853
+ const seen = [];
22854
+ return function _deterministic(parent, key, node, level) {
22855
+ const indent2 = space ? "\n" + new Array(level + 1).join(space) : "";
22856
+ const colonSeparator = space ? ": " : ":";
22857
+ node = serialize(node);
22858
+ node = replacer.call(parent, key, node);
22859
+ if (node === void 0) return;
22860
+ if (!isObject(node) || node === null) return stringify2(node);
22861
+ if (isArray(node)) {
22862
+ const out = [];
22863
+ for (let i = 0; i < node.length; i++) {
22864
+ const item = _deterministic(node, i, node[i], level + 1) || stringify2(null);
22865
+ out.push(indent2 + space + item);
22866
+ }
22867
+ return "[" + out.join(",") + indent2 + "]";
22868
+ } else {
22869
+ if (cycles) {
22870
+ if (seen.indexOf(node) !== -1) {
22871
+ return stringify2("[Circular]");
22872
+ } else {
22873
+ seen.push(node);
22874
+ }
22875
+ }
22876
+ const nodeKeys = keys(node).sort(compare && compare(node));
22877
+ const out = [];
22878
+ for (let i = 0; i < nodeKeys.length; i++) {
22879
+ const key2 = nodeKeys[i];
22880
+ const value = _deterministic(node, key2, node[key2], level + 1);
22881
+ if (!value) continue;
22882
+ const keyValue = stringify2(key2) + colonSeparator + value;
22883
+ out.push(indent2 + space + keyValue);
22884
+ }
22885
+ seen.splice(seen.indexOf(node), 1);
22886
+ return "{" + out.join(",") + indent2 + "}";
22887
+ }
22888
+ }({ "": obj }, "", obj, 0);
22889
+ }
22890
+ lib = stringifyDeterministic;
22891
+ return lib;
22892
+ }
22893
+ var libExports = requireLib();
22894
+ const stringify = /* @__PURE__ */ getDefaultExportFromCjs(libExports);
22895
+ const SYNC_OPS_BATCH_LIMIT = 10;
22896
+ class SwitchboardPushTransmitter {
22897
+ constructor(targetURL) {
22898
+ __publicField(this, "targetURL");
22899
+ __publicField(this, "logger", childLogger([
22900
+ "SwitchboardPushTransmitter",
22901
+ Math.floor(Math.random() * 999).toString()
22902
+ ]));
22903
+ this.targetURL = targetURL;
22904
+ }
22905
+ async transmit(strands, source) {
22906
+ var _a2;
22907
+ if (source.type === "trigger" && ((_a2 = source.trigger.data) == null ? void 0 : _a2.url) === this.targetURL) {
22908
+ this.logger.verbose(`Cutting trigger loop from ${this.targetURL}.`);
22909
+ return strands.map((strand) => {
22910
+ var _a3;
22911
+ return {
22912
+ driveId: strand.driveId,
22913
+ documentId: strand.documentId,
22914
+ scope: strand.scope,
22915
+ branch: strand.branch,
22916
+ status: "SUCCESS",
22917
+ revision: ((_a3 = strand.operations.at(-1)) == null ? void 0 : _a3.index) ?? -1
22918
+ };
22919
+ });
22920
+ }
22921
+ const culledStrands = [];
22922
+ let opsCounter = 0;
22923
+ for (let s = 0; opsCounter <= SYNC_OPS_BATCH_LIMIT && s < strands.length; s++) {
22924
+ const currentStrand = strands.at(s);
22925
+ if (!currentStrand) {
22926
+ break;
22927
+ }
22928
+ const newOps = Math.min(SYNC_OPS_BATCH_LIMIT - opsCounter, currentStrand.operations.length);
22929
+ culledStrands.push({
22930
+ ...currentStrand,
22931
+ operations: currentStrand.operations.slice(0, newOps)
22932
+ });
22933
+ opsCounter += newOps;
22934
+ }
22935
+ this.logger.verbose(` Total update: [${strands.map((s) => s.operations.length).join(", ")}] operations`);
22936
+ this.logger.verbose(`Culled update: [${culledStrands.map((s) => s.operations.length).join(", ")}] operations`);
22937
+ try {
22938
+ const { pushUpdates } = await requestGraphql(this.targetURL, gql`
22939
+ mutation pushUpdates($strands: [InputStrandUpdate!]) {
22940
+ pushUpdates(strands: $strands) {
22941
+ driveId
22942
+ documentId
22943
+ scope
22944
+ branch
22945
+ status
22946
+ revision
22947
+ error
22948
+ }
22949
+ }
22950
+ `, {
22951
+ strands: culledStrands.map((strand) => ({
22952
+ ...strand,
22953
+ operations: strand.operations.map((op) => ({
22954
+ ...op,
22955
+ input: stringify(op.input)
22956
+ }))
22957
+ }))
22958
+ });
22959
+ if (!pushUpdates) {
22960
+ throw new Error("Couldn't update listener revision");
22961
+ }
22962
+ return pushUpdates;
22963
+ } catch (e) {
22964
+ this.logger.error(e);
22965
+ throw e;
22966
+ }
22967
+ return [];
22968
+ }
22969
+ }
22970
+ var TransmitterType;
22971
+ (function(TransmitterType2) {
22972
+ TransmitterType2[TransmitterType2["Internal"] = 0] = "Internal";
22973
+ TransmitterType2[TransmitterType2["SwitchboardPush"] = 1] = "SwitchboardPush";
22974
+ TransmitterType2[TransmitterType2["PullResponder"] = 2] = "PullResponder";
22975
+ TransmitterType2[TransmitterType2["SecureConnect"] = 3] = "SecureConnect";
22976
+ TransmitterType2[TransmitterType2["MatrixConnect"] = 4] = "MatrixConnect";
22977
+ TransmitterType2[TransmitterType2["RESTWebhook"] = 5] = "RESTWebhook";
22978
+ })(TransmitterType || (TransmitterType = {}));
22979
+ const DefaultListenerManagerOptions = {
22980
+ sequentialUpdates: true
22981
+ };
22982
+ function filterOperationsByRevision(operations, revisions) {
22983
+ if (!revisions) {
22984
+ return operations;
22985
+ }
22773
22986
  return Object.keys(operations).reduce((acc, scope) => {
22774
22987
  const revision = revisions[scope];
22775
22988
  if (revision !== void 0) {
@@ -22987,11 +23200,32 @@ class BaseDocumentDriveServer {
22987
23200
  return this.triggerMap.delete(driveId);
22988
23201
  }
22989
23202
  async _initializeDrive(driveId) {
23203
+ var _a2, _b, _c, _d, _e, _f;
22990
23204
  const drive = await this.getDrive(driveId);
22991
23205
  await this.synchronizationManager.initializeDriveSyncStatus(driveId, drive);
22992
23206
  if (this.shouldSyncRemoteDrive(drive)) {
22993
23207
  await this.startSyncRemoteDrive(driveId);
22994
23208
  }
23209
+ for (const zodListener of drive.state.local.listeners) {
23210
+ if (((_a2 = zodListener.callInfo) == null ? void 0 : _a2.transmitterType) === "SwitchboardPush") {
23211
+ const transmitter = new SwitchboardPushTransmitter(((_b = zodListener.callInfo) == null ? void 0 : _b.data) ?? "");
23212
+ this.listenerManager.setListener(driveId, {
23213
+ block: zodListener.block,
23214
+ driveId: drive.state.global.id,
23215
+ filter: {
23216
+ branch: ((_c = zodListener.filter) == null ? void 0 : _c.branch) ?? [],
23217
+ documentId: ((_d = zodListener.filter) == null ? void 0 : _d.documentId) ?? [],
23218
+ documentType: ((_e = zodListener.filter) == null ? void 0 : _e.documentType) ?? [],
23219
+ scope: ((_f = zodListener.filter) == null ? void 0 : _f.scope) ?? []
23220
+ },
23221
+ listenerId: zodListener.listenerId,
23222
+ callInfo: zodListener.callInfo,
23223
+ system: zodListener.system,
23224
+ label: zodListener.label ?? "",
23225
+ transmitter
23226
+ });
23227
+ }
23228
+ }
22995
23229
  }
22996
23230
  // Delegate synchronization methods to synchronizationManager
22997
23231
  getSynchronizationUnits(driveId, documentId, scope, branch, documentType2) {
@@ -23033,7 +23267,7 @@ class BaseDocumentDriveServer {
23033
23267
  };
23034
23268
  await this.storage.createDrive(id, document);
23035
23269
  if (input.global.slug) {
23036
- await this.cache.deleteDocument("drives-slug", input.global.slug);
23270
+ await this.cache.deleteDriveBySlug(input.global.slug);
23037
23271
  }
23038
23272
  await this._initializeDrive(id);
23039
23273
  this.eventEmitter.emit("driveAdded", document);
@@ -23065,7 +23299,7 @@ class BaseDocumentDriveServer {
23065
23299
  const result = await Promise.allSettled([
23066
23300
  this.stopSyncRemoteDrive(driveId),
23067
23301
  this.listenerManager.removeDrive(driveId),
23068
- this.cache.deleteDocument("drives", driveId),
23302
+ this.cache.deleteDrive(driveId),
23069
23303
  this.storage.deleteDrive(driveId)
23070
23304
  ]);
23071
23305
  result.forEach((r) => {
@@ -23080,7 +23314,7 @@ class BaseDocumentDriveServer {
23080
23314
  async getDrive(driveId, options) {
23081
23315
  let document;
23082
23316
  try {
23083
- const cachedDocument = await this.cache.getDocument("drives", driveId);
23317
+ const cachedDocument = await this.cache.getDrive(driveId);
23084
23318
  if (cachedDocument && isDocumentDrive(cachedDocument)) {
23085
23319
  document = cachedDocument;
23086
23320
  if (isAtRevision(document, options == null ? void 0 : options.revisions)) {
@@ -23096,16 +23330,16 @@ class BaseDocumentDriveServer {
23096
23330
  throw new Error(`Document with id ${driveId} is not a Document Drive`);
23097
23331
  } else {
23098
23332
  if (!(options == null ? void 0 : options.revisions)) {
23099
- this.cache.setDocument("drives", driveId, result).catch(logger$1.error);
23333
+ this.cache.setDrive(driveId, result).catch(logger$1.error);
23100
23334
  }
23101
23335
  return result;
23102
23336
  }
23103
23337
  }
23104
23338
  async getDriveBySlug(slug, options) {
23105
23339
  try {
23106
- const document2 = await this.cache.getDocument("drives-slug", slug);
23107
- if (document2 && isDocumentDrive(document2)) {
23108
- return document2;
23340
+ const drive = await this.cache.getDriveBySlug(slug);
23341
+ if (drive) {
23342
+ return drive;
23109
23343
  }
23110
23344
  } catch (e) {
23111
23345
  logger$1.error("Error getting drive from cache", e);
@@ -23115,14 +23349,14 @@ class BaseDocumentDriveServer {
23115
23349
  if (!isDocumentDrive(document)) {
23116
23350
  throw new Error(`Document with slug ${slug} is not a Document Drive`);
23117
23351
  } else {
23118
- this.cache.setDocument("drives-slug", slug, document).catch(logger$1.error);
23352
+ this.cache.setDriveBySlug(slug, document).catch(logger$1.error);
23119
23353
  return document;
23120
23354
  }
23121
23355
  }
23122
23356
  async getDocument(driveId, documentId, options) {
23123
23357
  let cachedDocument;
23124
23358
  try {
23125
- cachedDocument = await this.cache.getDocument(driveId, documentId);
23359
+ cachedDocument = await this.cache.getDocument(documentId);
23126
23360
  if (cachedDocument && isAtRevision(cachedDocument, options == null ? void 0 : options.revisions)) {
23127
23361
  return cachedDocument;
23128
23362
  }
@@ -23132,7 +23366,7 @@ class BaseDocumentDriveServer {
23132
23366
  const documentStorage = cachedDocument ?? await this.storage.getDocument(driveId, documentId);
23133
23367
  const document = this._buildDocument(documentStorage, options);
23134
23368
  if (!(options == null ? void 0 : options.revisions)) {
23135
- this.cache.setDocument(driveId, documentId, document).catch(logger$1.error);
23369
+ this.cache.setDocument(documentId, document).catch(logger$1.error);
23136
23370
  }
23137
23371
  return document;
23138
23372
  }
@@ -23189,7 +23423,7 @@ class BaseDocumentDriveServer {
23189
23423
  } catch (error) {
23190
23424
  logger$1.warn("Error deleting document", error);
23191
23425
  }
23192
- await this.cache.deleteDocument(driveId, documentId);
23426
+ await this.cache.deleteDocument(documentId);
23193
23427
  return this.storage.deleteDocument(driveId, documentId);
23194
23428
  }
23195
23429
  async _processOperations(driveId, documentId, documentStorage, operations) {
@@ -23479,7 +23713,7 @@ class BaseDocumentDriveServer {
23479
23713
  };
23480
23714
  });
23481
23715
  if (document) {
23482
- this.cache.setDocument(driveId, documentId, document).catch(logger$1.error);
23716
+ this.cache.setDocument(documentId, document).catch(logger$1.error);
23483
23717
  }
23484
23718
  const { scopes, branches } = operationsApplied.reduce((acc, operation) => {
23485
23719
  if (!acc.scopes.includes(operation.scope)) {
@@ -23642,7 +23876,7 @@ class BaseDocumentDriveServer {
23642
23876
  if (!document || !isDocumentDrive(document)) {
23643
23877
  throw error ?? new Error("Invalid Document Drive document");
23644
23878
  }
23645
- this.cache.setDocument("drives", driveId, document).catch(logger$1.error);
23879
+ this.cache.setDrive(driveId, document).catch(logger$1.error);
23646
23880
  const lastOperation = operationsApplied.filter((op) => op.scope === "global").slice().pop();
23647
23881
  if (lastOperation) {
23648
23882
  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 +24048,44 @@ class MemoryStorage {
23814
24048
  }
23815
24049
  return Promise.resolve(document);
23816
24050
  }
24051
+ async delete(documentId) {
24052
+ const drives = await this.getDrives();
24053
+ for (const driveId of drives) {
24054
+ if (driveId === documentId)
24055
+ continue;
24056
+ await this.removeChild(driveId, documentId);
24057
+ }
24058
+ delete this.driveManifests[documentId];
24059
+ if (this.documents[documentId]) {
24060
+ delete this.documents[documentId];
24061
+ return Promise.resolve(true);
24062
+ }
24063
+ return Promise.resolve(false);
24064
+ }
24065
+ async addChild(parentId, childId) {
24066
+ if (parentId === childId) {
24067
+ throw new Error("Cannot associate a document with itself");
24068
+ }
24069
+ const children = await this.getChildren(childId);
24070
+ if (children.includes(parentId)) {
24071
+ throw new Error("Cannot associate a document with its child");
24072
+ }
24073
+ const manifest = this.getManifest(parentId);
24074
+ manifest.documentIds.add(childId);
24075
+ this.updateDriveManifest(parentId, manifest);
24076
+ }
24077
+ async removeChild(parentId, childId) {
24078
+ const manifest = this.getManifest(parentId);
24079
+ if (manifest.documentIds.delete(childId)) {
24080
+ this.updateDriveManifest(parentId, manifest);
24081
+ return true;
24082
+ }
24083
+ return false;
24084
+ }
24085
+ async getChildren(parentId) {
24086
+ const manifest = this.getManifest(parentId);
24087
+ return [...manifest.documentIds];
24088
+ }
23817
24089
  ////////////////////////////////
23818
24090
  // IDriveStorage
23819
24091
  ////////////////////////////////
@@ -23821,7 +24093,7 @@ class MemoryStorage {
23821
24093
  return this.exists(id);
23822
24094
  }
23823
24095
  getDocuments(drive) {
23824
- const manifest = this.getDriveManifest(drive);
24096
+ const manifest = this.getManifest(drive);
23825
24097
  return Promise.resolve([...manifest.documentIds]);
23826
24098
  }
23827
24099
  getDocument(driveId, id) {
@@ -23833,7 +24105,7 @@ class MemoryStorage {
23833
24105
  }
23834
24106
  async createDocument(drive, id, document) {
23835
24107
  await this.create(id, document);
23836
- const manifest = this.getDriveManifest(drive);
24108
+ const manifest = this.getManifest(drive);
23837
24109
  manifest.documentIds.add(id);
23838
24110
  this.updateDriveManifest(drive, manifest);
23839
24111
  }
@@ -23850,15 +24122,7 @@ class MemoryStorage {
23850
24122
  };
23851
24123
  }
23852
24124
  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];
24125
+ this.delete(id);
23862
24126
  }
23863
24127
  async getDrives() {
23864
24128
  return Object.keys(this.driveManifests);
@@ -23904,14 +24168,14 @@ class MemoryStorage {
23904
24168
  };
23905
24169
  }
23906
24170
  async deleteDrive(id) {
23907
- const manifest = this.getDriveManifest(id);
24171
+ const manifest = this.getManifest(id);
23908
24172
  const drives = await this.getDrives();
23909
24173
  await Promise.all([...manifest.documentIds].map((docId) => {
23910
24174
  for (const driveId of drives) {
23911
24175
  if (driveId === id) {
23912
24176
  continue;
23913
24177
  }
23914
- const manifest2 = this.getDriveManifest(driveId);
24178
+ const manifest2 = this.getManifest(driveId);
23915
24179
  if (manifest2.documentIds.has(docId)) {
23916
24180
  return;
23917
24181
  }
@@ -23952,7 +24216,7 @@ class MemoryStorage {
23952
24216
  ////////////////////////////////
23953
24217
  // Private
23954
24218
  ////////////////////////////////
23955
- getDriveManifest(driveId) {
24219
+ getManifest(driveId) {
23956
24220
  if (!this.driveManifests[driveId]) {
23957
24221
  this.driveManifests[driveId] = { documentIds: /* @__PURE__ */ new Set() };
23958
24222
  }
@@ -24351,187 +24615,6 @@ const _ListenerManager = class _ListenerManager {
24351
24615
  };
24352
24616
  __publicField(_ListenerManager, "LISTENER_UPDATE_DELAY", 250);
24353
24617
  let ListenerManager = _ListenerManager;
24354
- var defaults;
24355
- var hasRequiredDefaults;
24356
- function requireDefaults() {
24357
- if (hasRequiredDefaults) return defaults;
24358
- hasRequiredDefaults = 1;
24359
- defaults = {
24360
- space: "",
24361
- cycles: false,
24362
- replacer: (k, v) => v,
24363
- stringify: JSON.stringify
24364
- };
24365
- return defaults;
24366
- }
24367
- var util;
24368
- var hasRequiredUtil;
24369
- function requireUtil() {
24370
- if (hasRequiredUtil) return util;
24371
- hasRequiredUtil = 1;
24372
- util = {
24373
- isArray: Array.isArray,
24374
- assign: Object.assign,
24375
- isObject: (v) => typeof v === "object",
24376
- isFunction: (v) => typeof v === "function",
24377
- isBoolean: (v) => typeof v === "boolean",
24378
- isRegex: (v) => v instanceof RegExp,
24379
- keys: Object.keys
24380
- };
24381
- return util;
24382
- }
24383
- var lib;
24384
- var hasRequiredLib;
24385
- function requireLib() {
24386
- if (hasRequiredLib) return lib;
24387
- hasRequiredLib = 1;
24388
- const DEFAULTS = requireDefaults();
24389
- const isFunction = requireUtil().isFunction;
24390
- const isBoolean = requireUtil().isBoolean;
24391
- const isObject = requireUtil().isObject;
24392
- const isArray = requireUtil().isArray;
24393
- const isRegex = requireUtil().isRegex;
24394
- const assign = requireUtil().assign;
24395
- const keys = requireUtil().keys;
24396
- function serialize(obj) {
24397
- if (obj === null || obj === void 0) return obj;
24398
- if (isRegex(obj)) return obj.toString();
24399
- return obj.toJSON ? obj.toJSON() : obj;
24400
- }
24401
- function stringifyDeterministic(obj, opts) {
24402
- opts = opts || assign({}, DEFAULTS);
24403
- if (isFunction(opts)) opts = { compare: opts };
24404
- const space = opts.space || DEFAULTS.space;
24405
- const cycles = isBoolean(opts.cycles) ? opts.cycles : DEFAULTS.cycles;
24406
- const replacer = opts.replacer || DEFAULTS.replacer;
24407
- const stringify2 = opts.stringify || DEFAULTS.stringify;
24408
- const compare = opts.compare && /* @__PURE__ */ function(f) {
24409
- return function(node) {
24410
- return function(a, b) {
24411
- const aobj = { key: a, value: node[a] };
24412
- const bobj = { key: b, value: node[b] };
24413
- return f(aobj, bobj);
24414
- };
24415
- };
24416
- }(opts.compare);
24417
- if (!cycles) stringify2(obj);
24418
- const seen = [];
24419
- return function _deterministic(parent, key, node, level) {
24420
- const indent2 = space ? "\n" + new Array(level + 1).join(space) : "";
24421
- const colonSeparator = space ? ": " : ":";
24422
- node = serialize(node);
24423
- node = replacer.call(parent, key, node);
24424
- if (node === void 0) return;
24425
- if (!isObject(node) || node === null) return stringify2(node);
24426
- if (isArray(node)) {
24427
- const out = [];
24428
- for (let i = 0; i < node.length; i++) {
24429
- const item = _deterministic(node, i, node[i], level + 1) || stringify2(null);
24430
- out.push(indent2 + space + item);
24431
- }
24432
- return "[" + out.join(",") + indent2 + "]";
24433
- } else {
24434
- if (cycles) {
24435
- if (seen.indexOf(node) !== -1) {
24436
- return stringify2("[Circular]");
24437
- } else {
24438
- seen.push(node);
24439
- }
24440
- }
24441
- const nodeKeys = keys(node).sort(compare && compare(node));
24442
- const out = [];
24443
- for (let i = 0; i < nodeKeys.length; i++) {
24444
- const key2 = nodeKeys[i];
24445
- const value = _deterministic(node, key2, node[key2], level + 1);
24446
- if (!value) continue;
24447
- const keyValue = stringify2(key2) + colonSeparator + value;
24448
- out.push(indent2 + space + keyValue);
24449
- }
24450
- seen.splice(seen.indexOf(node), 1);
24451
- return "{" + out.join(",") + indent2 + "}";
24452
- }
24453
- }({ "": obj }, "", obj, 0);
24454
- }
24455
- lib = stringifyDeterministic;
24456
- return lib;
24457
- }
24458
- var libExports = requireLib();
24459
- const stringify = /* @__PURE__ */ getDefaultExportFromCjs(libExports);
24460
- const SYNC_OPS_BATCH_LIMIT = 10;
24461
- class SwitchboardPushTransmitter {
24462
- constructor(targetURL) {
24463
- __publicField(this, "targetURL");
24464
- __publicField(this, "logger", childLogger([
24465
- "SwitchboardPushTransmitter",
24466
- Math.floor(Math.random() * 999).toString()
24467
- ]));
24468
- this.targetURL = targetURL;
24469
- }
24470
- async transmit(strands, source) {
24471
- var _a2;
24472
- if (source.type === "trigger" && ((_a2 = source.trigger.data) == null ? void 0 : _a2.url) === this.targetURL) {
24473
- this.logger.verbose(`Cutting trigger loop from ${this.targetURL}.`);
24474
- return strands.map((strand) => {
24475
- var _a3;
24476
- return {
24477
- driveId: strand.driveId,
24478
- documentId: strand.documentId,
24479
- scope: strand.scope,
24480
- branch: strand.branch,
24481
- status: "SUCCESS",
24482
- revision: ((_a3 = strand.operations.at(-1)) == null ? void 0 : _a3.index) ?? -1
24483
- };
24484
- });
24485
- }
24486
- const culledStrands = [];
24487
- let opsCounter = 0;
24488
- for (let s = 0; opsCounter <= SYNC_OPS_BATCH_LIMIT && s < strands.length; s++) {
24489
- const currentStrand = strands.at(s);
24490
- if (!currentStrand) {
24491
- break;
24492
- }
24493
- const newOps = Math.min(SYNC_OPS_BATCH_LIMIT - opsCounter, currentStrand.operations.length);
24494
- culledStrands.push({
24495
- ...currentStrand,
24496
- operations: currentStrand.operations.slice(0, newOps)
24497
- });
24498
- opsCounter += newOps;
24499
- }
24500
- this.logger.verbose(` Total update: [${strands.map((s) => s.operations.length).join(", ")}] operations`);
24501
- this.logger.verbose(`Culled update: [${culledStrands.map((s) => s.operations.length).join(", ")}] operations`);
24502
- try {
24503
- const { pushUpdates } = await requestGraphql(this.targetURL, gql`
24504
- mutation pushUpdates($strands: [InputStrandUpdate!]) {
24505
- pushUpdates(strands: $strands) {
24506
- driveId
24507
- documentId
24508
- scope
24509
- branch
24510
- status
24511
- revision
24512
- error
24513
- }
24514
- }
24515
- `, {
24516
- strands: culledStrands.map((strand) => ({
24517
- ...strand,
24518
- operations: strand.operations.map((op) => ({
24519
- ...op,
24520
- input: stringify(op.input)
24521
- }))
24522
- }))
24523
- });
24524
- if (!pushUpdates) {
24525
- throw new Error("Couldn't update listener revision");
24526
- }
24527
- return pushUpdates;
24528
- } catch (e) {
24529
- this.logger.error(e);
24530
- throw e;
24531
- }
24532
- return [];
24533
- }
24534
- }
24535
24618
  class TransmitterFactory {
24536
24619
  constructor(listenerManager) {
24537
24620
  __publicField(this, "listenerManager");
@@ -24676,7 +24759,7 @@ class SynchronizationManager {
24676
24759
  }
24677
24760
  async getDrive(driveId) {
24678
24761
  try {
24679
- const cachedDocument = await this.cache.getDocument("drives", driveId);
24762
+ const cachedDocument = await this.cache.getDrive(driveId);
24680
24763
  if (cachedDocument && isDocumentDrive(cachedDocument)) {
24681
24764
  return cachedDocument;
24682
24765
  }
@@ -24692,7 +24775,7 @@ class SynchronizationManager {
24692
24775
  }
24693
24776
  async getDocument(driveId, documentId) {
24694
24777
  try {
24695
- const cachedDocument = await this.cache.getDocument(driveId, documentId);
24778
+ const cachedDocument = await this.cache.getDocument(documentId);
24696
24779
  if (cachedDocument) {
24697
24780
  return cachedDocument;
24698
24781
  }
@@ -25533,7 +25616,7 @@ const nodeOptionsMap = {
25533
25616
  };
25534
25617
  const name = "@powerhousedao/connect";
25535
25618
  const productName = "Powerhouse-Connect";
25536
- const version$1 = "1.0.0-dev.245";
25619
+ const version$1 = "1.0.0-dev.247";
25537
25620
  const description = "Powerhouse Connect";
25538
25621
  const main = "./dist/index.html";
25539
25622
  const type = "module";
@@ -28326,6 +28409,10 @@ const _BrowserStorage = class _BrowserStorage {
28326
28409
  name: namespace ? `${namespace}:${_BrowserStorage.DBName}` : _BrowserStorage.DBName
28327
28410
  }));
28328
28411
  }
28412
+ async clear() {
28413
+ const db = await this.db;
28414
+ await db.clear();
28415
+ }
28329
28416
  ////////////////////////////////
28330
28417
  // IDocumentStorage
28331
28418
  ////////////////////////////////
@@ -28346,13 +28433,57 @@ const _BrowserStorage = class _BrowserStorage {
28346
28433
  }
28347
28434
  return document;
28348
28435
  }
28436
+ async delete(documentId) {
28437
+ const db = await this.db;
28438
+ const document = await db.getItem(this.buildDocumentKey(documentId));
28439
+ if (!document) {
28440
+ return false;
28441
+ }
28442
+ const drives = await this.getDrives();
28443
+ for (const driveId of drives) {
28444
+ if (driveId === documentId)
28445
+ continue;
28446
+ await this.removeChild(driveId, documentId);
28447
+ }
28448
+ await db.removeItem(this.buildManifestKey(documentId));
28449
+ await db.removeItem(this.buildDocumentKey(documentId));
28450
+ return true;
28451
+ }
28452
+ async removeChild(parentId, childId) {
28453
+ const manifest = await this.getManifest(parentId);
28454
+ const docIndex = manifest.documentIds.indexOf(childId);
28455
+ if (docIndex !== -1) {
28456
+ manifest.documentIds.splice(docIndex, 1);
28457
+ await this.updateDriveManifest(parentId, manifest);
28458
+ return true;
28459
+ }
28460
+ return false;
28461
+ }
28462
+ async addChild(parentId, childId) {
28463
+ if (parentId === childId) {
28464
+ throw new Error("Cannot associate a document with itself");
28465
+ }
28466
+ const children = await this.getChildren(childId);
28467
+ if (children.includes(parentId)) {
28468
+ throw new Error("Cannot associate a document with its child");
28469
+ }
28470
+ const manifest = await this.getManifest(parentId);
28471
+ if (!manifest.documentIds.includes(childId)) {
28472
+ manifest.documentIds.push(childId);
28473
+ await this.updateDriveManifest(parentId, manifest);
28474
+ }
28475
+ }
28476
+ async getChildren(parentId) {
28477
+ const manifest = await this.getManifest(parentId);
28478
+ return manifest.documentIds;
28479
+ }
28349
28480
  ////////////////////////////////
28350
28481
  // IDriveStorage
28351
28482
  ////////////////////////////////
28352
28483
  checkDocumentExists(drive, documentId) {
28353
28484
  return this.exists(documentId);
28354
28485
  }
28355
- async getDriveManifest(driveId) {
28486
+ async getManifest(driveId) {
28356
28487
  const db = await this.db;
28357
28488
  const manifest = await db.getItem(this.buildManifestKey(driveId));
28358
28489
  return manifest || { documentIds: [] };
@@ -28362,7 +28493,7 @@ const _BrowserStorage = class _BrowserStorage {
28362
28493
  await db.setItem(this.buildManifestKey(driveId), manifest);
28363
28494
  }
28364
28495
  async getDocuments(drive) {
28365
- const manifest = await this.getDriveManifest(drive);
28496
+ const manifest = await this.getManifest(drive);
28366
28497
  return manifest.documentIds;
28367
28498
  }
28368
28499
  async getDocument(driveId, id) {
@@ -28370,7 +28501,7 @@ const _BrowserStorage = class _BrowserStorage {
28370
28501
  }
28371
28502
  async createDocument(drive, id, document) {
28372
28503
  await this.create(id, document);
28373
- const manifest = await this.getDriveManifest(drive);
28504
+ const manifest = await this.getManifest(drive);
28374
28505
  if (!manifest.documentIds.includes(id)) {
28375
28506
  manifest.documentIds.push(id);
28376
28507
  await this.updateDriveManifest(drive, manifest);
@@ -28378,7 +28509,7 @@ const _BrowserStorage = class _BrowserStorage {
28378
28509
  }
28379
28510
  async deleteDocument(drive, id) {
28380
28511
  await (await this.db).removeItem(this.buildDocumentKey(id));
28381
- const manifest = await this.getDriveManifest(drive);
28512
+ const manifest = await this.getManifest(drive);
28382
28513
  const docIndex = manifest.documentIds.indexOf(id);
28383
28514
  if (docIndex !== -1) {
28384
28515
  manifest.documentIds.splice(docIndex, 1);
@@ -31125,7 +31256,7 @@ if (window.__VITE_ENVS.MODE === "development") {
31125
31256
  } else {
31126
31257
  serviceWorkerManager.registerServiceWorker(false);
31127
31258
  }
31128
- const App = lazy(() => __vitePreload(() => import("./app-BH-6rUAk.js").then((n) => n.aN), true ? __vite__mapDeps([0,1,2]) : void 0));
31259
+ const App = lazy(() => __vitePreload(() => import("./app-Bjaniq_f.js").then((n) => n.aN), true ? __vite__mapDeps([0,1,2]) : void 0));
31129
31260
  const AppLoader = /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(App, {}) });
31130
31261
  const appLoader = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
31131
31262
  __proto__: null,