@powerhousedao/connect 1.0.10-dev.0 → 1.0.12-dev.0

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 (24) hide show
  1. package/dist/assets/{app-BIIVKAZr.css → app-B2wIHlkp.css} +1 -1
  2. package/dist/assets/{app-CsiwsM42.js → app-Dff9FF8i.js} +9 -9
  3. package/dist/assets/{app-loader-C7A2YjX4.js → app-loader-Cq4mceES.js} +75 -128
  4. package/dist/assets/{ccip-BG1d6viz.js → ccip-CHzBVJ_W.js} +3 -3
  5. package/dist/assets/{content-0UFgs2d1.js → content-DFdCvBBv.js} +3 -3
  6. package/dist/assets/{index-CTEGX1We.js → index-BLJi1OAo.js} +3 -3
  7. package/dist/assets/{index-yr0-SqYf.js → index-CTn3AlO1.js} +4 -4
  8. package/dist/assets/{index-BMDqhr-9.js → index-DHZwo9f0.js} +3 -3
  9. package/dist/assets/{main.BmcV9296.js → main.BzO0W8Ha.js} +1 -1
  10. package/dist/index.html +1 -1
  11. package/dist/modules/@powerhousedao/reactor-browser/{chunk-SQ5HIKYV.js → chunk-2GQV5NL6.js} +60 -79
  12. package/dist/modules/@powerhousedao/reactor-browser/{chunk-ISDEPHKP.js → chunk-JBIHRE7L.js} +11 -47
  13. package/dist/modules/@powerhousedao/reactor-browser/{chunk-5QJXNK35.js → chunk-JCLMFPZP.js} +1 -1
  14. package/dist/modules/@powerhousedao/reactor-browser/{chunk-3C54663M.js → chunk-SJYGEYNL.js} +1 -1
  15. package/dist/modules/@powerhousedao/reactor-browser/{chunk-XV42KZK3.js → chunk-T5LUZMLP.js} +1 -1
  16. package/dist/modules/@powerhousedao/reactor-browser/context/index.js +2 -2
  17. package/dist/modules/@powerhousedao/reactor-browser/context/read-mode.js +2 -2
  18. package/dist/modules/@powerhousedao/reactor-browser/hooks/index.js +3 -3
  19. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActions.js +2 -2
  20. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActionsWithUiNodes.js +3 -3
  21. package/dist/modules/@powerhousedao/reactor-browser/index.js +5 -5
  22. package/dist/modules/@powerhousedao/reactor-browser/reactor.js +2 -2
  23. package/dist/vite-envs.sh +1 -1
  24. package/package.json +9 -7
@@ -1,8 +1,8 @@
1
1
  import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
2
- import { t as twMerge, B as Button, m as mergeClassNameProps, E as ERROR, M as MISSING, C as CONFLICT, S as SUCCESS, h as SYNCING, I as INITIAL_SYNC, i as ConnectDropdownMenu, u as useOnClickOutside, j as useEventListener, k as useCopyToClipboard, l as Select, n as ENSAvatar, P as Provider, o as Root3, T as Trigger, p as Portal, q as Content2, v as validateInitialState, w as validateStateSchemaName, x as validateModules, y as useUnwrappedReactor, z as useConnectDid, A as useConnectCrypto, D as useTranslation, F as useModal, G as useAtomValue, H as themeAtom, J as useUser, K as useUserPermissions, L as useUiNodes, N as exportFile, O as useGetDocumentModelModule, Q as addActionContext, U as signOperation, V as useDocumentDriveServer, W as useHotkeys, X as useGetEditor, Y as isSameDocument, Z as useNavigate, _ as ErrorBoundary, $ as DriveLayout, a0 as SearchBar, a1 as useAsyncReactor, a2 as useFilteredDocumentModels, a3 as useDriveEditor, a4 as useDocumentDriveById } from "./app-CsiwsM42.js";
2
+ import { t as twMerge, B as Button, m as mergeClassNameProps, E as ERROR, M as MISSING, C as CONFLICT, S as SUCCESS, h as SYNCING, I as INITIAL_SYNC, i as ConnectDropdownMenu, u as useOnClickOutside, j as useEventListener, k as useCopyToClipboard, l as Select, n as ENSAvatar, P as Provider, o as Root3, T as Trigger, p as Portal, q as Content2, v as validateInitialState, w as validateStateSchemaName, x as validateModules, y as useUnwrappedReactor, z as useConnectDid, A as useConnectCrypto, D as useTranslation, F as useModal, G as useAtomValue, H as themeAtom, J as useUser, K as useUserPermissions, L as useUiNodes, N as exportFile, O as useGetDocumentModelModule, Q as addActionContext, U as signOperation, V as useDocumentDriveServer, W as useHotkeys, X as useGetEditor, Y as isSameDocument, Z as useNavigate, _ as ErrorBoundary, $ as DriveLayout, a0 as SearchBar, a1 as useAsyncReactor, a2 as useFilteredDocumentModels, a3 as useDriveEditor, a4 as useDocumentDriveById } from "./app-Dff9FF8i.js";
3
3
  import * as React from "react";
4
4
  import React__default, { useState, useCallback, useMemo, useEffect, Fragment, useRef, useLayoutEffect, memo as memo$1, createElement, useSyncExternalStore, Suspense } from "react";
5
- import { _ as Icon, aX as getDimensions, aY as READ, aZ as nodeOptionsMap, a_ as defaultFileOptions, a$ as DELETE, b0 as RENAME, b1 as WRITE, b2 as DUPLICATE, b3 as defaultFolderOptions, b4 as garbageCollect, b5 as sortOperations, b6 as UI_NODE, aO as DRIVE, ay as FILE, b7 as undo, b8 as redo, ac as logger, b9 as useDocumentDispatch, aP as FOLDER, ak as driveDocumentModelModule } from "./app-loader-C7A2YjX4.js";
5
+ import { _ as Icon, aX as getDimensions, aY as READ, aZ as nodeOptionsMap, a_ as defaultFileOptions, a$ as DELETE, b0 as RENAME, b1 as WRITE, b2 as DUPLICATE, b3 as defaultFolderOptions, b4 as garbageCollect, b5 as sortOperations, b6 as UI_NODE, aO as DRIVE, ay as FILE, b7 as undo, b8 as redo, ac as logger, b9 as useDocumentDispatch, aP as FOLDER, ak as driveDocumentModelModule } from "./app-loader-Cq4mceES.js";
6
6
  import { useDocument, useDocumentEditorProps } from "@powerhousedao/reactor-browser";
7
7
  import { useUiNodesContext, FILE as FILE$1 } from "@powerhousedao/reactor-browser/hooks/useUiNodesContext";
8
8
  import { useDriveActionsWithUiNodes } from "@powerhousedao/reactor-browser/hooks/useDriveActionsWithUiNodes";
@@ -10,7 +10,7 @@ import { useDriveContext, DriveContextProvider } from "@powerhousedao/reactor-br
10
10
  import "@powerhousedao/reactor-browser/uiNodes/constants";
11
11
  import { makeDriveDocumentStateHook } from "@powerhousedao/reactor-browser/hooks/document-state";
12
12
  import { flushSync } from "react-dom";
13
- import "./main.BmcV9296.js";
13
+ import "./main.BzO0W8Ha.js";
14
14
  const PaginationButton = ({ active = false, ...props }) => {
15
15
  const className = twMerge("h-8 min-w-8 border border-solid border-gray-300 bg-white px-3 py-1 text-xs text-gray-900 hover:bg-gray-100", !active && "border-0");
16
16
  return jsx(Button, { color: "light", size: "small", ...mergeClassNameProps(props, className), children: props.children });
@@ -1,9 +1,9 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { t as twMerge, a5 as clsx, a6 as get, a7 as set, a8 as appendErrors, a9 as useFormContext, aa as Primitive, ab as cva, ac as FormProvider, ad as Controller, ae as Slot, af as useForm, ag as Root2, ah as List, ai as Trigger, aj as Content, ak as setModelName, al as setModelId, am as setModelDescription, an as setModelExtension, ao as setAuthorName, ap as setAuthorWebsite, aq as setStateSchema, ar as setInitialState, as as addModule, at as setModuleName, au as deleteModule, av as addOperation, aw as setOperationName, ax as setOperationSchema, ay as setOperationDescription, az as deleteOperation, aA as addOperationError, aB as deleteOperationError, aC as setOperationErrorName } from "./app-CsiwsM42.js";
3
- import { ba as inspect$1, bb as GraphQLError$1, bc as getNamedType, bd as invariant$2, be as isInputObjectType, bf as isScalarType, bg as isObjectType, bh as isInterfaceType, bi as isUnionType, bj as isEnumType, bk as print, bl as isPrintableAsBlockString, bm as Kind, bn as astFromValue$1, bo as DEFAULT_DEPRECATION_REASON, bp as isSpecifiedDirective, bq as isSpecifiedScalarType, br as isIntrospectionType, bs as z, bt as GraphQLScalarType, Z as pascalCase, bu as parse, bv as visit, bw as buildASTSchema, bx as extendSchema, by as getNullableType, bz as isListType, $ as getDefaultExportFromCjs, bA as snakeCase, bB as constantCase, bC as isAbstractType, bD as BREAK, bE as GraphQLInputObjectType, bF as GraphQLList, bG as GraphQLEnumType, bH as GraphQLObjectType, bI as GraphQLInterfaceType, bJ as SchemaMetaFieldDef, bK as TypeMetaFieldDef, bL as TypeNameMetaFieldDef, bM as isCompositeType, bN as isOutputType, bO as isInputType, bP as GraphQLBoolean, bQ as assertAbstractType, bR as doTypesOverlap, bS as DirectiveLocation, bT as specifiedRules$1, bU as NoUnusedFragmentsRule$1, bV as ExecutableDefinitionsRule$1, bW as validate$2, bX as validateSchema, bY as GraphQLID, bZ as GraphQLString, b_ as GraphQLFloat, b$ as GraphQLInt, c0 as GraphQLDirective, c1 as GraphQLUnionType, c2 as isNonNullType, c3 as GraphQLNonNull, c4 as isNamedType, c5 as isLeafType, c6 as GraphQLSchema, c7 as buildSchema, c8 as sentenceCase, am as hashKey } from "./app-loader-C7A2YjX4.js";
2
+ import { t as twMerge, a5 as clsx, a6 as get, a7 as set, a8 as appendErrors, a9 as useFormContext, aa as Primitive, ab as cva, ac as FormProvider, ad as Controller, ae as Slot, af as useForm, ag as Root2, ah as List, ai as Trigger, aj as Content, ak as setModelName, al as setModelId, am as setModelDescription, an as setModelExtension, ao as setAuthorName, ap as setAuthorWebsite, aq as setStateSchema, ar as setInitialState, as as addModule, at as setModuleName, au as deleteModule, av as addOperation, aw as setOperationName, ax as setOperationSchema, ay as setOperationDescription, az as deleteOperation, aA as addOperationError, aB as deleteOperationError, aC as setOperationErrorName } from "./app-Dff9FF8i.js";
3
+ import { ba as inspect$1, bb as GraphQLError$1, bc as getNamedType, bd as invariant$2, be as isInputObjectType, bf as isScalarType, bg as isObjectType, bh as isInterfaceType, bi as isUnionType, bj as isEnumType, bk as print, bl as isPrintableAsBlockString, bm as Kind, bn as astFromValue$1, bo as DEFAULT_DEPRECATION_REASON, bp as isSpecifiedDirective, bq as isSpecifiedScalarType, br as isIntrospectionType, bs as z, bt as GraphQLScalarType, Z as pascalCase, bu as parse, bv as visit, bw as buildASTSchema, bx as extendSchema, by as getNullableType, bz as isListType, $ as getDefaultExportFromCjs, bA as snakeCase, bB as constantCase, bC as isAbstractType, bD as BREAK, bE as GraphQLInputObjectType, bF as GraphQLList, bG as GraphQLEnumType, bH as GraphQLObjectType, bI as GraphQLInterfaceType, bJ as SchemaMetaFieldDef, bK as TypeMetaFieldDef, bL as TypeNameMetaFieldDef, bM as isCompositeType, bN as isOutputType, bO as isInputType, bP as GraphQLBoolean, bQ as assertAbstractType, bR as doTypesOverlap, bS as DirectiveLocation, bT as specifiedRules$1, bU as NoUnusedFragmentsRule$1, bV as ExecutableDefinitionsRule$1, bW as validate$2, bX as validateSchema, bY as GraphQLID, bZ as GraphQLString, b_ as GraphQLFloat, b$ as GraphQLInt, c0 as GraphQLDirective, c1 as GraphQLUnionType, c2 as isNonNullType, c3 as GraphQLNonNull, c4 as isNamedType, c5 as isLeafType, c6 as GraphQLSchema, c7 as buildSchema, c8 as sentenceCase, am as hashKey } from "./app-loader-Cq4mceES.js";
4
4
  import * as React from "react";
5
5
  import React__default, { forwardRef, useRef, useCallback, useImperativeHandle, useEffect, useState, createContext, useContext, memo, useId, useMemo } from "react";
6
- import "./main.BmcV9296.js";
6
+ import "./main.BzO0W8Ha.js";
7
7
  import "@powerhousedao/reactor-browser";
8
8
  import "react-dom";
9
9
  import "@powerhousedao/reactor-browser/hooks/useUiNodesContext";
@@ -10,10 +10,10 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
11
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
12
  var _DB_NAME, _STORE_NAME, _KEY, _db, _BrowserKeyStorage_instances, useStore_fn, _subtleCrypto, _keyPair, _keyPairStorage, _did, _ConnectCrypto_instances, initCrypto_fn, initialize_fn, parseDid_fn, generateECDSAKeyPair_fn, exportKeyPair_fn, importKeyPair_fn, _sign, _verify, _store, _namespace, _BaseStorage_instances, buildKey_fn, _baseUrl, _store2, _connectId, _eventEmitter, _Renown_instances, updateUser_fn, getCredential_fn;
13
- import { _ as __vitePreload } from "./main.BmcV9296.js";
14
- import { aW as getAugmentedNamespace, $ as getDefaultExportFromCjs, ah as connectConfig, ac as logger } from "./app-loader-C7A2YjX4.js";
15
- import { e as eventsExports, R as RENOWN_URL, g as getEnsInfo } from "./app-CsiwsM42.js";
16
- import { d, c, b, f, a, r, s } from "./app-CsiwsM42.js";
13
+ import { _ as __vitePreload } from "./main.BzO0W8Ha.js";
14
+ import { aW as getAugmentedNamespace, $ as getDefaultExportFromCjs, ah as connectConfig, ac as logger } from "./app-loader-Cq4mceES.js";
15
+ import { e as eventsExports, R as RENOWN_URL, g as getEnsInfo } from "./app-Dff9FF8i.js";
16
+ import { d, c, b, f, a, r, s } from "./app-Dff9FF8i.js";
17
17
  import "react/jsx-runtime";
18
18
  import "react";
19
19
  import "@powerhousedao/reactor-browser";
@@ -1,8 +1,8 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/app-loader-C7A2YjX4.js","assets/main.BmcV9296.js","assets/app-loader-pcztQTL4.css"])))=>i.map(i=>d[i]);
2
- import { _ as __vitePreload } from "./main.BmcV9296.js";
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/app-loader-Cq4mceES.js","assets/main.BzO0W8Ha.js","assets/app-loader-pcztQTL4.css"])))=>i.map(i=>d[i]);
2
+ import { _ as __vitePreload } from "./main.BzO0W8Ha.js";
3
3
  import { createRoot } from "react-dom/client";
4
4
  async function renderApp(element) {
5
- const AppLoader = await __vitePreload(() => import("./app-loader-C7A2YjX4.js").then((n) => n.c9), true ? __vite__mapDeps([0,1,2]) : void 0);
5
+ const AppLoader = await __vitePreload(() => import("./app-loader-Cq4mceES.js").then((n) => n.c9), true ? __vite__mapDeps([0,1,2]) : void 0);
6
6
  createRoot(element).render(AppLoader.default);
7
7
  }
8
8
  const AppElement = document.getElementById("app");
@@ -99,7 +99,7 @@ const __vitePreload = function preload(baseModule, deps, importerUrl) {
99
99
  return baseModule().catch(handlePreloadError);
100
100
  });
101
101
  };
102
- __vitePreload(() => import("./index-BMDqhr-9.js"), true ? [] : void 0);
102
+ __vitePreload(() => import("./index-DHZwo9f0.js"), true ? [] : void 0);
103
103
  export {
104
104
  __vitePreload as _
105
105
  };
package/dist/index.html CHANGED
@@ -94,4 +94,4 @@
94
94
  "@powerhousedao/reactor-browser/utils/index": "/modules/@powerhousedao/reactor-browser/utils/index.js",
95
95
  "@powerhousedao/reactor-browser/utils/signature": "/modules/@powerhousedao/reactor-browser/utils/signature.js"
96
96
  }
97
- }</script><script type="module" crossorigin="" src="/assets/main.BmcV9296.js"></script></head><body><div id="app"></div></body></html>
97
+ }</script><script type="module" crossorigin="" src="/assets/main.BzO0W8Ha.js"></script></head><body><div id="app"></div></body></html>
@@ -1271,13 +1271,6 @@ var DriveAlreadyExistsError = class extends Error {
1271
1271
  this.driveId = driveId;
1272
1272
  }
1273
1273
  };
1274
- var DriveNotFoundError = class extends Error {
1275
- driveId;
1276
- constructor(driveId) {
1277
- super(`Drive with id ${driveId} not found`);
1278
- this.driveId = driveId;
1279
- }
1280
- };
1281
1274
  var SynchronizationUnitNotFoundError = class extends Error {
1282
1275
  syncUnitId;
1283
1276
  constructor(message, syncUnitId) {
@@ -1540,7 +1533,7 @@ var BaseQueueManager = class {
1540
1533
  if (await queue.isDeleted()) {
1541
1534
  throw new Error("Queue is deleted");
1542
1535
  }
1543
- const newDocument = job.documentId && !await this.delegate.checkDocumentExists(job.documentId);
1536
+ const newDocument = job.documentId && !await this.delegate.exists(job.documentId);
1544
1537
  if (newDocument && !await queue.isBlocked()) {
1545
1538
  await queue.setBlocked(true);
1546
1539
  const driveQueue = this.getQueue(job.driveId);
@@ -1710,8 +1703,9 @@ var MemoryStorage = class {
1710
1703
  // IDocumentStorage
1711
1704
  ////////////////////////////////
1712
1705
  exists(documentId) {
1713
- return Promise.resolve(!!this.documents[documentId] || !!this.documents[`drive/${documentId}`]);
1706
+ return Promise.resolve(!!this.documents[documentId]);
1714
1707
  }
1708
+ // TODO: this should throw an error if the document already exists.
1715
1709
  create(documentId, document) {
1716
1710
  this.documents[documentId] = document;
1717
1711
  return Promise.resolve();
@@ -1719,10 +1713,6 @@ var MemoryStorage = class {
1719
1713
  get(documentId) {
1720
1714
  const document = this.documents[documentId];
1721
1715
  if (!document) {
1722
- const drive = this.documents[`drive/${documentId}`];
1723
- if (drive) {
1724
- return Promise.resolve(drive);
1725
- }
1726
1716
  throw new Error(`Document with id ${documentId} not found`);
1727
1717
  }
1728
1718
  return Promise.resolve(document);
@@ -1768,28 +1758,12 @@ var MemoryStorage = class {
1768
1758
  ////////////////////////////////
1769
1759
  // IDriveStorage
1770
1760
  ////////////////////////////////
1771
- checkDocumentExists(drive, id) {
1772
- return this.exists(id);
1773
- }
1774
- getDocuments(drive) {
1775
- const manifest = this.getManifest(drive);
1776
- return Promise.resolve([...manifest.documentIds]);
1777
- }
1778
- getDocument(driveId, id) {
1779
- return this.get(id);
1780
- }
1781
1761
  async clearStorage() {
1782
1762
  this.documents = {};
1783
1763
  this.driveManifests = {};
1784
1764
  }
1785
- async createDocument(drive, id, document) {
1786
- await this.create(id, document);
1787
- const manifest = this.getManifest(drive);
1788
- manifest.documentIds.add(id);
1789
- this.updateDriveManifest(drive, manifest);
1790
- }
1791
1765
  async addDocumentOperations(drive, id, operations, header) {
1792
- const document = await this.getDocument(drive, id);
1766
+ const document = await this.get(id);
1793
1767
  if (!document) {
1794
1768
  throw new Error(`Document with id ${id} not found`);
1795
1769
  }
@@ -1800,22 +1774,12 @@ var MemoryStorage = class {
1800
1774
  operations: mergedOperations
1801
1775
  };
1802
1776
  }
1803
- async deleteDocument(drive, id) {
1804
- this.delete(id);
1805
- }
1806
1777
  async getDrives() {
1807
1778
  return Object.keys(this.driveManifests);
1808
1779
  }
1809
- async getDrive(id) {
1810
- const drive = this.documents[`drive/${id}`];
1811
- if (!drive) {
1812
- throw new DriveNotFoundError(id);
1813
- }
1814
- return drive;
1815
- }
1816
1780
  async getDriveBySlug(slug) {
1817
1781
  for (const driveId of Object.keys(this.driveManifests)) {
1818
- const drive = this.documents[`drive/${driveId}`];
1782
+ const drive = this.documents[driveId];
1819
1783
  if (drive.initialState.state.global.slug === slug) {
1820
1784
  return drive;
1821
1785
  }
@@ -1834,13 +1798,13 @@ var MemoryStorage = class {
1834
1798
  throw new Error(`Drive with slug ${slug} already exists`);
1835
1799
  }
1836
1800
  }
1837
- await this.create(`drive/${id}`, drive);
1801
+ await this.create(id, drive);
1838
1802
  this.updateDriveManifest(id, { documentIds: /* @__PURE__ */ new Set() });
1839
1803
  }
1840
1804
  async addDriveOperations(id, operations, header) {
1841
- const drive = await this.getDrive(id);
1805
+ const drive = await this.get(id);
1842
1806
  const mergedOperations = mergeOperations(drive.operations, operations);
1843
- this.documents[`drive/${id}`] = {
1807
+ this.documents[id] = {
1844
1808
  ...drive,
1845
1809
  ...header,
1846
1810
  operations: mergedOperations
@@ -11745,9 +11709,7 @@ var DefaultDrivesManager = class {
11745
11709
  try {
11746
11710
  await this.server.deleteDrive(driveId);
11747
11711
  } catch (error) {
11748
- if (!(error instanceof DriveNotFoundError)) {
11749
- logger.error(error);
11750
- }
11712
+ logger.error(error);
11751
11713
  }
11752
11714
  }
11753
11715
  async preserveDrivesById(driveIdsToPreserve, drives, removeStrategy = "detach") {
@@ -12363,7 +12325,7 @@ var BaseDocumentDriveServer = class {
12363
12325
  logger = childLogger(["BaseDocumentDriveServer"]);
12364
12326
  // external dependencies
12365
12327
  documentModelModules;
12366
- storage;
12328
+ legacyStorage;
12367
12329
  documentStorage;
12368
12330
  cache;
12369
12331
  queueManager;
@@ -12378,9 +12340,9 @@ var BaseDocumentDriveServer = class {
12378
12340
  emit: (...args) => this.eventEmitter.emit("defaultRemoteDrive", ...args)
12379
12341
  };
12380
12342
  queueDelegate = {
12381
- checkDocumentExists: (documentId) => this.documentStorage.exists(documentId),
12343
+ exists: (documentId) => this.documentStorage.exists(documentId),
12382
12344
  processOperationJob: async ({ driveId, documentId, operations, options }) => {
12383
- return documentId ? this.addOperations(driveId, documentId, operations, options) : this.addDriveOperations(driveId, operations, options);
12345
+ return !documentId || driveId === documentId ? this.addDriveOperations(driveId, operations, options) : this.addOperations(driveId, documentId, operations, options);
12384
12346
  },
12385
12347
  processActionJob: async ({ driveId, documentId, actions, options }) => {
12386
12348
  return documentId ? this.addActions(driveId, documentId, actions, options) : this.addDriveActions(driveId, actions, options);
@@ -12400,7 +12362,7 @@ var BaseDocumentDriveServer = class {
12400
12362
  initializePromise;
12401
12363
  constructor(documentModelModules, storage, documentStorage, cache, queueManager, eventEmitter, synchronizationManager, listenerManager, options) {
12402
12364
  this.documentModelModules = documentModelModules;
12403
- this.storage = storage;
12365
+ this.legacyStorage = storage;
12404
12366
  this.documentStorage = documentStorage;
12405
12367
  this.cache = cache;
12406
12368
  this.queueManager = queueManager;
@@ -12638,7 +12600,7 @@ var BaseDocumentDriveServer = class {
12638
12600
  if (!id) {
12639
12601
  throw new Error("Invalid Drive Id");
12640
12602
  }
12641
- const drives = await this.storage.getDrives();
12603
+ const drives = await this.legacyStorage.getDrives();
12642
12604
  if (drives.includes(id)) {
12643
12605
  throw new DriveAlreadyExistsError(id);
12644
12606
  }
@@ -12648,7 +12610,7 @@ var BaseDocumentDriveServer = class {
12648
12610
  document.meta = {
12649
12611
  preferredEditor
12650
12612
  };
12651
- await this.storage.createDrive(id, document);
12613
+ await this.legacyStorage.createDrive(id, document);
12652
12614
  if (input.global.slug) {
12653
12615
  await this.cache.deleteDriveBySlug(input.global.slug);
12654
12616
  }
@@ -12683,7 +12645,7 @@ var BaseDocumentDriveServer = class {
12683
12645
  this.stopSyncRemoteDrive(driveId),
12684
12646
  this.listenerManager.removeDrive(driveId),
12685
12647
  this.cache.deleteDrive(driveId),
12686
- this.storage.deleteDrive(driveId)
12648
+ this.legacyStorage.deleteDrive(driveId)
12687
12649
  ]);
12688
12650
  result.forEach((r) => {
12689
12651
  if (r.status === "rejected") {
@@ -12692,7 +12654,7 @@ var BaseDocumentDriveServer = class {
12692
12654
  });
12693
12655
  }
12694
12656
  getDrives() {
12695
- return this.storage.getDrives();
12657
+ return this.legacyStorage.getDrives();
12696
12658
  }
12697
12659
  async getDrive(driveId, options) {
12698
12660
  let document;
@@ -12707,7 +12669,7 @@ var BaseDocumentDriveServer = class {
12707
12669
  } catch (e) {
12708
12670
  this.logger.error("Error getting drive from cache", e);
12709
12671
  }
12710
- const driveStorage = document ?? await this.storage.getDrive(driveId);
12672
+ const driveStorage = document ?? await this.documentStorage.get(driveId);
12711
12673
  const result = this._buildDocument(driveStorage, options);
12712
12674
  if (!isDocumentDrive(result)) {
12713
12675
  throw new Error(`Document with id ${driveId} is not a Document Drive`);
@@ -12727,7 +12689,7 @@ var BaseDocumentDriveServer = class {
12727
12689
  } catch (e) {
12728
12690
  this.logger.error("Error getting drive from cache", e);
12729
12691
  }
12730
- const driveStorage = await this.storage.getDriveBySlug(slug);
12692
+ const driveStorage = await this.legacyStorage.getDriveBySlug(slug);
12731
12693
  const document = this._buildDocument(driveStorage, options);
12732
12694
  if (!isDocumentDrive(document)) {
12733
12695
  throw new Error(`Document with slug ${slug} is not a Document Drive`);
@@ -12746,7 +12708,7 @@ var BaseDocumentDriveServer = class {
12746
12708
  } catch (e) {
12747
12709
  this.logger.error("Error getting document from cache", e);
12748
12710
  }
12749
- const documentStorage = cachedDocument ?? await this.storage.getDocument(driveId, documentId);
12711
+ const documentStorage = cachedDocument ?? await this.documentStorage.get(documentId);
12750
12712
  const document = this._buildDocument(documentStorage, options);
12751
12713
  if (!options?.revisions) {
12752
12714
  this.cache.setDocument(documentId, document).catch(this.logger.error);
@@ -12754,7 +12716,7 @@ var BaseDocumentDriveServer = class {
12754
12716
  return document;
12755
12717
  }
12756
12718
  getDocuments(driveId) {
12757
- return this.storage.getDocuments(driveId);
12719
+ return this.documentStorage.getChildren(driveId);
12758
12720
  }
12759
12721
  async createDocument(driveId, input) {
12760
12722
  let state = void 0;
@@ -12777,7 +12739,18 @@ var BaseDocumentDriveServer = class {
12777
12739
  clipboard: [],
12778
12740
  state: state ?? document.state
12779
12741
  };
12780
- await this.storage.createDocument(driveId, input.id, documentStorage);
12742
+ await this.documentStorage.create(input.id, documentStorage);
12743
+ try {
12744
+ await this.documentStorage.addChild(driveId, input.id);
12745
+ } catch (e) {
12746
+ this.logger.error("Error adding child document", e);
12747
+ try {
12748
+ await this.documentStorage.delete(input.id);
12749
+ } catch (e2) {
12750
+ this.logger.error("FATAL: Could not revert document creation. This means that we created a document but failed to add it to the drive..", e2);
12751
+ }
12752
+ throw e;
12753
+ }
12781
12754
  for (const syncUnit of input.synchronizationUnits) {
12782
12755
  this.synchronizationManager.updateSyncStatus(syncUnit.syncId, {
12783
12756
  pull: this.triggerMap.get(driveId) ? "INITIAL_SYNC" : void 0,
@@ -12787,9 +12760,9 @@ var BaseDocumentDriveServer = class {
12787
12760
  const operations = Object.values(document.operations).flat();
12788
12761
  if (operations.length) {
12789
12762
  if (isDocumentDrive(document)) {
12790
- await this.storage.addDriveOperations(driveId, operations, document);
12763
+ await this.legacyStorage.addDriveOperations(driveId, operations, document);
12791
12764
  } else {
12792
- await this.storage.addDocumentOperations(driveId, input.id, operations, document);
12765
+ await this.legacyStorage.addDocumentOperations(driveId, input.id, operations, document);
12793
12766
  }
12794
12767
  }
12795
12768
  return document;
@@ -12807,7 +12780,7 @@ var BaseDocumentDriveServer = class {
12807
12780
  this.logger.warn("Error deleting document", error);
12808
12781
  }
12809
12782
  await this.cache.deleteDocument(documentId);
12810
- return this.storage.deleteDocument(driveId, documentId);
12783
+ return this.documentStorage.delete(documentId);
12811
12784
  }
12812
12785
  async _processOperations(driveId, documentId, documentStorage, operations) {
12813
12786
  const operationsApplied = [];
@@ -12858,7 +12831,7 @@ var BaseDocumentDriveServer = class {
12858
12831
  for (const scope of Object.keys(documentOperations)) {
12859
12832
  const lastRemainingOperation = documentOperations[scope].at(-1);
12860
12833
  if (lastRemainingOperation && !lastRemainingOperation.resultingState) {
12861
- lastRemainingOperation.resultingState = await (documentId ? this.storage.getOperationResultingState?.(driveId, documentId, lastRemainingOperation.index, lastRemainingOperation.scope, "main") : this.storage.getDriveOperationResultingState?.(driveId, lastRemainingOperation.index, lastRemainingOperation.scope, "main"));
12834
+ lastRemainingOperation.resultingState = await (documentId ? this.legacyStorage.getOperationResultingState?.(driveId, documentId, lastRemainingOperation.index, lastRemainingOperation.scope, "main") : this.legacyStorage.getDriveOperationResultingState?.(driveId, lastRemainingOperation.index, lastRemainingOperation.scope, "main"));
12862
12835
  }
12863
12836
  }
12864
12837
  return {
@@ -12890,7 +12863,7 @@ var BaseDocumentDriveServer = class {
12890
12863
  });
12891
12864
  const lastRemainingOperation = documentOperations[scope].at(-1);
12892
12865
  if (lastRemainingOperation && !lastRemainingOperation.resultingState) {
12893
- lastRemainingOperation.resultingState = await (documentId ? this.storage.getOperationResultingState?.(driveId, documentId, lastRemainingOperation.index, lastRemainingOperation.scope, "main") : this.storage.getDriveOperationResultingState?.(driveId, lastRemainingOperation.index, lastRemainingOperation.scope, "main"));
12866
+ lastRemainingOperation.resultingState = await (documentId ? this.legacyStorage.getOperationResultingState?.(driveId, documentId, lastRemainingOperation.index, lastRemainingOperation.scope, "main") : this.legacyStorage.getDriveOperationResultingState?.(driveId, lastRemainingOperation.index, lastRemainingOperation.scope, "main"));
12894
12867
  }
12895
12868
  const operationSignals = [];
12896
12869
  newDocument = documentModelModule.reducer(newDocument, operation, (signal) => {
@@ -12937,14 +12910,14 @@ var BaseDocumentDriveServer = class {
12937
12910
  return this.addOperations(driveId, documentId, [operation], options);
12938
12911
  }
12939
12912
  async _addOperations(driveId, documentId, callback) {
12940
- if (!this.storage.addDocumentOperationsWithTransaction) {
12941
- const documentStorage = await this.storage.getDocument(driveId, documentId);
12913
+ if (!this.legacyStorage.addDocumentOperationsWithTransaction) {
12914
+ const documentStorage = await this.documentStorage.get(documentId);
12942
12915
  const result = await callback(documentStorage);
12943
12916
  if (result.operations.length > 0) {
12944
- await this.storage.addDocumentOperations(driveId, documentId, result.operations, result.header);
12917
+ await this.legacyStorage.addDocumentOperations(driveId, documentId, result.operations, result.header);
12945
12918
  }
12946
12919
  } else {
12947
- await this.storage.addDocumentOperationsWithTransaction(driveId, documentId, callback);
12920
+ await this.legacyStorage.addDocumentOperationsWithTransaction(driveId, documentId, callback);
12948
12921
  }
12949
12922
  }
12950
12923
  queueOperation(driveId, documentId, operation, options) {
@@ -13166,18 +13139,18 @@ var BaseDocumentDriveServer = class {
13166
13139
  for (const drive of await this.getDrives()) {
13167
13140
  await this.deleteDrive(drive);
13168
13141
  }
13169
- await this.storage.clearStorage?.();
13142
+ await this.legacyStorage.clearStorage?.();
13170
13143
  }
13171
13144
  async _addDriveOperations(driveId, callback) {
13172
- if (!this.storage.addDriveOperationsWithTransaction) {
13173
- const documentStorage = await this.storage.getDrive(driveId);
13145
+ if (!this.legacyStorage.addDriveOperationsWithTransaction) {
13146
+ const documentStorage = await this.documentStorage.get(driveId);
13174
13147
  const result = await callback(documentStorage);
13175
13148
  if (result.operations.length > 0) {
13176
- await this.storage.addDriveOperations(driveId, result.operations, result.header);
13149
+ await this.legacyStorage.addDriveOperations(driveId, result.operations, result.header);
13177
13150
  }
13178
13151
  return result;
13179
13152
  } else {
13180
- return this.storage.addDriveOperationsWithTransaction(driveId, callback);
13153
+ return this.legacyStorage.addDriveOperationsWithTransaction(driveId, callback);
13181
13154
  }
13182
13155
  }
13183
13156
  queueDriveOperation(driveId, operation, options) {
@@ -13855,13 +13828,15 @@ var TransmitterFactory = class {
13855
13828
  // ../../packages/document-drive/dist/src/server/sync-manager.js
13856
13829
  var SynchronizationManager = class {
13857
13830
  storage;
13831
+ documentStorage;
13858
13832
  cache;
13859
13833
  documentModelModules;
13860
13834
  eventEmitter;
13861
13835
  syncStatus = /* @__PURE__ */ new Map();
13862
13836
  logger = childLogger(["SynchronizationManager"]);
13863
- constructor(storage, cache, documentModelModules, eventEmitter) {
13837
+ constructor(storage, documentStorage, cache, documentModelModules, eventEmitter) {
13864
13838
  this.storage = storage;
13839
+ this.documentStorage = documentStorage;
13865
13840
  this.cache = cache;
13866
13841
  this.documentModelModules = documentModelModules;
13867
13842
  this.eventEmitter = eventEmitter;
@@ -14001,7 +13976,7 @@ var SynchronizationManager = class {
14001
13976
  } catch (e) {
14002
13977
  this.logger.error("Error getting drive from cache", e);
14003
13978
  }
14004
- const driveStorage = await this.storage.getDrive(driveId);
13979
+ const driveStorage = await this.documentStorage.get(driveId);
14005
13980
  const result = this._buildDocument(driveStorage);
14006
13981
  if (!isDocumentDrive(result)) {
14007
13982
  throw new Error(`Document with id ${driveId} is not a Document Drive`);
@@ -14017,7 +13992,7 @@ var SynchronizationManager = class {
14017
13992
  } catch (e) {
14018
13993
  this.logger.error("Error getting document from cache", e);
14019
13994
  }
14020
- const documentStorage = await this.storage.getDocument(driveId, documentId);
13995
+ const documentStorage = await this.documentStorage.get(documentId);
14021
13996
  return this._buildDocument(documentStorage);
14022
13997
  }
14023
13998
  _buildDocument(documentStorage) {
@@ -14179,7 +14154,14 @@ var ReactorBuilder = class {
14179
14154
  this.eventEmitter = new DefaultEventEmitter();
14180
14155
  }
14181
14156
  if (!this.synchronizationManager) {
14182
- this.synchronizationManager = new SynchronizationManager(this.storage, this.cache, this.documentModelModules, this.eventEmitter);
14157
+ this.synchronizationManager = new SynchronizationManager(
14158
+ this.storage,
14159
+ // as we refactor, we're secretly making all the IStorage implementations also implement IDocumentStorage
14160
+ this.storage,
14161
+ this.cache,
14162
+ this.documentModelModules,
14163
+ this.eventEmitter
14164
+ );
14183
14165
  }
14184
14166
  if (!this.listenerManager) {
14185
14167
  const config = {
@@ -14217,7 +14199,6 @@ export {
14217
14199
  isFolderNode,
14218
14200
  generateNodesCopy,
14219
14201
  generateAddNodeAction,
14220
- DriveNotFoundError,
14221
14202
  mergeOperations,
14222
14203
  BaseQueueManager,
14223
14204
  ReadDriveNotFoundError,
@@ -1,10 +1,9 @@
1
1
  import {
2
2
  BaseQueueManager,
3
- DriveNotFoundError,
4
3
  ReactorBuilder,
5
4
  memory_default,
6
5
  mergeOperations
7
- } from "./chunk-SQ5HIKYV.js";
6
+ } from "./chunk-2GQV5NL6.js";
8
7
  import {
9
8
  __commonJS,
10
9
  __require,
@@ -2220,6 +2219,7 @@ var BrowserStorage = class _BrowserStorage {
2220
2219
  const document = await db.getItem(this.buildDocumentKey(documentId));
2221
2220
  return !!document;
2222
2221
  }
2222
+ // TODO: this should throw an error if the document already exists.
2223
2223
  async create(documentId, document) {
2224
2224
  const db = await this.db;
2225
2225
  await db.setItem(this.buildDocumentKey(documentId), document);
@@ -2279,9 +2279,6 @@ var BrowserStorage = class _BrowserStorage {
2279
2279
  ////////////////////////////////
2280
2280
  // IDriveStorage
2281
2281
  ////////////////////////////////
2282
- checkDocumentExists(drive, documentId) {
2283
- return this.exists(documentId);
2284
- }
2285
2282
  async getManifest(driveId) {
2286
2283
  const db = await this.db;
2287
2284
  const manifest = await db.getItem(this.buildManifestKey(driveId));
@@ -2291,35 +2288,11 @@ var BrowserStorage = class _BrowserStorage {
2291
2288
  const db = await this.db;
2292
2289
  await db.setItem(this.buildManifestKey(driveId), manifest);
2293
2290
  }
2294
- async getDocuments(drive) {
2295
- const manifest = await this.getManifest(drive);
2296
- return manifest.documentIds;
2297
- }
2298
- async getDocument(driveId, id) {
2299
- return this.get(id);
2300
- }
2301
- async createDocument(drive, id, document) {
2302
- await this.create(id, document);
2303
- const manifest = await this.getManifest(drive);
2304
- if (!manifest.documentIds.includes(id)) {
2305
- manifest.documentIds.push(id);
2306
- await this.updateDriveManifest(drive, manifest);
2307
- }
2308
- }
2309
- async deleteDocument(drive, id) {
2310
- await (await this.db).removeItem(this.buildDocumentKey(id));
2311
- const manifest = await this.getManifest(drive);
2312
- const docIndex = manifest.documentIds.indexOf(id);
2313
- if (docIndex !== -1) {
2314
- manifest.documentIds.splice(docIndex, 1);
2315
- await this.updateDriveManifest(drive, manifest);
2316
- }
2317
- }
2318
2291
  async clearStorage() {
2319
2292
  return (await this.db).clear();
2320
2293
  }
2321
2294
  async addDocumentOperations(drive, id, operations, header) {
2322
- const document = await this.getDocument(drive, id);
2295
+ const document = await this.get(id);
2323
2296
  if (!document) {
2324
2297
  throw new Error(`Document with id ${id} not found`);
2325
2298
  }
@@ -2336,21 +2309,12 @@ var BrowserStorage = class _BrowserStorage {
2336
2309
  const keys = await db.keys();
2337
2310
  return keys.filter((key) => key.startsWith(_BrowserStorage.MANIFEST_KEY)).map((key) => key.slice(_BrowserStorage.MANIFEST_KEY.length + _BrowserStorage.SEP.length));
2338
2311
  }
2339
- async getDrive(id) {
2340
- let drive;
2341
- try {
2342
- drive = await this.get(id);
2343
- } catch {
2344
- throw new DriveNotFoundError(id);
2345
- }
2346
- return drive;
2347
- }
2348
2312
  async getDriveBySlug(slug) {
2349
2313
  const drives = (await this.getDrives()).reverse();
2350
2314
  for (const drive of drives) {
2351
- const driveData = await this.getDrive(drive);
2315
+ const driveData = await this.get(drive);
2352
2316
  if (driveData.initialState.state.global.slug === slug) {
2353
- return this.getDrive(drive);
2317
+ return driveData;
2354
2318
  }
2355
2319
  }
2356
2320
  throw new Error(`Drive with slug ${slug} not found`);
@@ -2371,14 +2335,14 @@ var BrowserStorage = class _BrowserStorage {
2371
2335
  await this.updateDriveManifest(id, { documentIds: [] });
2372
2336
  }
2373
2337
  async deleteDrive(id) {
2374
- const documents = await this.getDocuments(id);
2375
- await Promise.all(documents.map((doc) => this.deleteDocument(id, doc)));
2338
+ const documents = await this.getChildren(id);
2339
+ await Promise.all(documents.map((doc) => this.delete(doc)));
2376
2340
  const db = await this.db;
2377
2341
  await db.removeItem(this.buildManifestKey(id));
2378
2342
  return db.removeItem(this.buildDocumentKey(id));
2379
2343
  }
2380
2344
  async addDriveOperations(id, operations, header) {
2381
- const drive = await this.getDrive(id);
2345
+ const drive = await this.get(id);
2382
2346
  const mergedOperations = mergeOperations(drive.operations, operations);
2383
2347
  const db = await this.db;
2384
2348
  await db.setItem(this.buildDocumentKey(id), {
@@ -2420,19 +2384,19 @@ var BrowserStorage = class _BrowserStorage {
2420
2384
  const drives = await this.getDrives();
2421
2385
  for (const drive of drives) {
2422
2386
  await this.migrateDrive(drive);
2423
- const documents = await this.getDocuments(drive);
2387
+ const documents = await this.getChildren(drive);
2424
2388
  await Promise.all(documents.map(async (docId) => this.migrateDocument(drive, docId)));
2425
2389
  }
2426
2390
  }
2427
2391
  async migrateDrive(driveId) {
2428
- const drive = await this.getDrive(driveId);
2392
+ const drive = await this.get(driveId);
2429
2393
  const migratedDrive = migrateDocumentOperationSignatures(drive);
2430
2394
  if (migratedDrive !== drive) {
2431
2395
  return (await this.db).setItem(this.buildDocumentKey(driveId), migratedDrive);
2432
2396
  }
2433
2397
  }
2434
2398
  async migrateDocument(drive, id) {
2435
- const document = await this.getDocument(drive, id);
2399
+ const document = await this.get(id);
2436
2400
  const migratedDocument = migrateDocumentOperationSignatures(document);
2437
2401
  if (migratedDocument !== document) {
2438
2402
  return (await this.db).setItem(this.buildDocumentKey(id), migratedDocument);
@@ -8,7 +8,7 @@ import {
8
8
  isFolderNode,
9
9
  moveNode,
10
10
  updateNode
11
- } from "./chunk-SQ5HIKYV.js";
11
+ } from "./chunk-2GQV5NL6.js";
12
12
  import {
13
13
  generateId
14
14
  } from "./chunk-FQF4YAVC.js";
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-P6NJ6IAQ.js";
7
7
  import {
8
8
  ReadDriveNotFoundError
9
- } from "./chunk-SQ5HIKYV.js";
9
+ } from "./chunk-2GQV5NL6.js";
10
10
 
11
11
  // ../../packages/reactor-browser/dist/src/context/read-mode.js
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useDriveActions
3
- } from "./chunk-5QJXNK35.js";
3
+ } from "./chunk-JCLMFPZP.js";
4
4
  import {
5
5
  useDriveContext
6
6
  } from "./chunk-XBTEGV5M.js";
@@ -3,10 +3,10 @@ import {
3
3
  ReadModeContext,
4
4
  ReadModeContextProvider,
5
5
  useReadModeContext
6
- } from "../chunk-3C54663M.js";
6
+ } from "../chunk-SJYGEYNL.js";
7
7
  import "../chunk-OVGOA2P5.js";
8
8
  import "../chunk-P6NJ6IAQ.js";
9
- import "../chunk-SQ5HIKYV.js";
9
+ import "../chunk-2GQV5NL6.js";
10
10
  import "../chunk-FQF4YAVC.js";
11
11
  import "../chunk-2ESYSVXG.js";
12
12
  export {