@powerhousedao/reactor-browser 5.1.0 → 5.2.0-dev.1
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.
- package/README.md +296 -482
- package/dist/src/actions/dispatch.d.ts +16 -2
- package/dist/src/actions/dispatch.d.ts.map +1 -1
- package/dist/src/actions/dispatch.js +20 -2
- package/dist/src/actions/dispatch.js.map +1 -1
- package/dist/src/actions/document.d.ts +7 -4
- package/dist/src/actions/document.d.ts.map +1 -1
- package/dist/src/actions/document.js +302 -131
- package/dist/src/actions/document.js.map +1 -1
- package/dist/src/actions/drive.d.ts +2 -2
- package/dist/src/actions/drive.d.ts.map +1 -1
- package/dist/src/actions/drive.js +153 -50
- package/dist/src/actions/drive.js.map +1 -1
- package/dist/src/actions/queue.d.ts.map +1 -1
- package/dist/src/actions/queue.js +48 -24
- package/dist/src/actions/queue.js.map +1 -1
- package/dist/src/actions/sign.js +1 -1
- package/dist/src/actions/sign.js.map +1 -1
- package/dist/src/document-cache.d.ts +17 -0
- package/dist/src/document-cache.d.ts.map +1 -0
- package/dist/src/document-cache.js +143 -0
- package/dist/src/document-cache.js.map +1 -0
- package/dist/src/errors.js +1 -1
- package/dist/src/errors.js.map +1 -1
- package/dist/src/hooks/add-ph-event-handlers.d.ts.map +1 -1
- package/dist/src/hooks/add-ph-event-handlers.js +11 -2
- package/dist/src/hooks/add-ph-event-handlers.js.map +1 -1
- package/dist/src/hooks/config/connect.d.ts +2 -2
- package/dist/src/hooks/connect.d.ts +1 -1
- package/dist/src/hooks/connect.d.ts.map +1 -1
- package/dist/src/hooks/connect.js +1 -1
- package/dist/src/hooks/connect.js.map +1 -1
- package/dist/src/hooks/crypto.d.ts +7 -1
- package/dist/src/hooks/crypto.d.ts.map +1 -1
- package/dist/src/hooks/crypto.js +7 -1
- package/dist/src/hooks/crypto.js.map +1 -1
- package/dist/src/hooks/dispatch.d.ts +7 -2
- package/dist/src/hooks/dispatch.d.ts.map +1 -1
- package/dist/src/hooks/dispatch.js +13 -3
- package/dist/src/hooks/dispatch.js.map +1 -1
- package/dist/src/hooks/document-by-id.d.ts +1 -1
- package/dist/src/hooks/document-by-id.d.ts.map +1 -1
- package/dist/src/hooks/document-by-id.js +3 -3
- package/dist/src/hooks/document-by-id.js.map +1 -1
- package/dist/src/hooks/document-cache.d.ts +19 -3
- package/dist/src/hooks/document-cache.d.ts.map +1 -1
- package/dist/src/hooks/document-cache.js +41 -14
- package/dist/src/hooks/document-cache.js.map +1 -1
- package/dist/src/hooks/features.d.ts +5 -0
- package/dist/src/hooks/features.d.ts.map +1 -0
- package/dist/src/hooks/features.js +6 -0
- package/dist/src/hooks/features.js.map +1 -0
- package/dist/src/hooks/index.d.ts +6 -3
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +6 -3
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/reactor.d.ts +39 -6
- package/dist/src/hooks/reactor.d.ts.map +1 -1
- package/dist/src/hooks/reactor.js +41 -6
- package/dist/src/hooks/reactor.js.map +1 -1
- package/dist/src/hooks/renown.d.ts +3 -2
- package/dist/src/hooks/renown.d.ts.map +1 -1
- package/dist/src/hooks/renown.js.map +1 -1
- package/dist/src/hooks/selected-document.d.ts +3 -1
- package/dist/src/hooks/selected-document.d.ts.map +1 -1
- package/dist/src/hooks/selected-document.js +9 -0
- package/dist/src/hooks/selected-document.js.map +1 -1
- package/dist/src/hooks/selected-drive.d.ts.map +1 -1
- package/dist/src/hooks/selected-drive.js +3 -3
- package/dist/src/hooks/selected-drive.js.map +1 -1
- package/dist/src/hooks/selected-node.d.ts.map +1 -1
- package/dist/src/hooks/selected-node.js +3 -3
- package/dist/src/hooks/selected-node.js.map +1 -1
- package/dist/src/hooks/toast.d.ts +7 -0
- package/dist/src/hooks/toast.d.ts.map +1 -0
- package/dist/src/hooks/toast.js +9 -0
- package/dist/src/hooks/toast.js.map +1 -0
- package/dist/src/hooks/use-feature-flags.d.ts +44 -0
- package/dist/src/hooks/use-feature-flags.d.ts.map +1 -0
- package/dist/src/hooks/use-feature-flags.js +65 -0
- package/dist/src/hooks/use-feature-flags.js.map +1 -0
- package/dist/src/hooks/user.d.ts +7 -1
- package/dist/src/hooks/user.d.ts.map +1 -1
- package/dist/src/hooks/user.js +7 -1
- package/dist/src/hooks/user.js.map +1 -1
- package/dist/src/hooks/vetra-packages.d.ts.map +1 -1
- package/dist/src/hooks/vetra-packages.js +3 -1
- package/dist/src/hooks/vetra-packages.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/pglite/drop.d.ts +3 -0
- package/dist/src/pglite/drop.d.ts.map +1 -0
- package/dist/src/pglite/drop.js +19 -0
- package/dist/src/pglite/drop.js.map +1 -0
- package/dist/src/pglite/index.d.ts +1 -0
- package/dist/src/pglite/index.d.ts.map +1 -1
- package/dist/src/pglite/index.js +1 -0
- package/dist/src/pglite/index.js.map +1 -1
- package/dist/src/reactor-client-document-cache.d.ts +31 -0
- package/dist/src/reactor-client-document-cache.d.ts.map +1 -0
- package/dist/src/reactor-client-document-cache.js +142 -0
- package/dist/src/reactor-client-document-cache.js.map +1 -0
- package/dist/src/reactor.d.ts +5 -6
- package/dist/src/reactor.d.ts.map +1 -1
- package/dist/src/reactor.js +36 -61
- package/dist/src/reactor.js.map +1 -1
- package/dist/src/renown/constants.d.ts +1 -1
- package/dist/src/renown/constants.d.ts.map +1 -1
- package/dist/src/renown/constants.js +1 -1
- package/dist/src/renown/constants.js.map +1 -1
- package/dist/src/renown/utils.d.ts +2 -2
- package/dist/src/renown/utils.d.ts.map +1 -1
- package/dist/src/renown/utils.js +2 -2
- package/dist/src/renown/utils.js.map +1 -1
- package/dist/src/types/documents.d.ts +10 -5
- package/dist/src/types/documents.d.ts.map +1 -1
- package/dist/src/types/global.d.ts +15 -1
- package/dist/src/types/global.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +1 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/modals.d.ts +2 -0
- package/dist/src/types/modals.d.ts.map +1 -1
- package/dist/src/types/toast.d.ts +9 -0
- package/dist/src/types/toast.d.ts.map +1 -0
- package/dist/src/types/toast.js +2 -0
- package/dist/src/types/toast.js.map +1 -0
- package/dist/src/utils/drives.d.ts.map +1 -1
- package/dist/src/utils/drives.js +41 -24
- package/dist/src/utils/drives.js.map +1 -1
- package/dist/src/utils/url.d.ts +4 -0
- package/dist/src/utils/url.d.ts.map +1 -1
- package/dist/src/utils/url.js +7 -0
- package/dist/src/utils/url.js.map +1 -1
- package/dist/test/document-cache.test.d.ts +2 -0
- package/dist/test/document-cache.test.d.ts.map +1 -0
- package/dist/test/document-cache.test.js +457 -0
- package/dist/test/document-cache.test.js.map +1 -0
- package/dist/test/drop.test.d.ts +2 -0
- package/dist/test/drop.test.d.ts.map +1 -0
- package/dist/test/drop.test.js +86 -0
- package/dist/test/drop.test.js.map +1 -0
- package/dist/test/getSwitchboardUrl.test.js +3 -1
- package/dist/test/getSwitchboardUrl.test.js.map +1 -1
- package/dist/test/hooks/document-cache.test.d.ts +2 -0
- package/dist/test/hooks/document-cache.test.d.ts.map +1 -0
- package/dist/test/hooks/document-cache.test.js +642 -0
- package/dist/test/hooks/document-cache.test.js.map +1 -0
- package/dist/test/switchboard.test.js +4 -2
- package/dist/test/switchboard.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -7
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import type { Action, PHDocument } from "document-model";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Dispatches actions to a document.
|
|
4
|
+
* @param actionOrActions - The action or actions to dispatch.
|
|
5
|
+
* @param document - The document to dispatch actions to.
|
|
6
|
+
* @param onErrors - Callback invoked with any errors that occurred during action execution.
|
|
7
|
+
* @returns The updated document, or undefined if the dispatch failed.
|
|
8
|
+
*/
|
|
9
|
+
export declare function dispatchActions<TDocument = PHDocument, TAction = Action>(actionOrActions: TAction[] | TAction | undefined, document: TDocument | undefined, onErrors?: (errors: Error[]) => void, onSuccess?: (result: PHDocument) => void): Promise<PHDocument | undefined>;
|
|
10
|
+
/**
|
|
11
|
+
* Dispatches actions to a document.
|
|
12
|
+
* @param actionOrActions - The action or actions to dispatch.
|
|
13
|
+
* @param documentId - The ID of the document to dispatch actions to.
|
|
14
|
+
* @param onErrors - Callback invoked with any errors that occurred during action execution.
|
|
15
|
+
* @returns The updated document, or undefined if the dispatch failed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function dispatchActions(actionOrActions: Action[] | Action | undefined, documentId: string, onErrors?: (errors: Error[]) => void, onSuccess?: (result: PHDocument) => void): Promise<PHDocument | undefined>;
|
|
4
18
|
//# sourceMappingURL=dispatch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../src/actions/dispatch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../src/actions/dispatch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA4BzD;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,SAAS,GAAG,UAAU,EAAE,OAAO,GAAG,MAAM,EAC5E,eAAe,EAAE,OAAO,EAAE,GAAG,OAAO,GAAG,SAAS,EAChD,QAAQ,EAAE,SAAS,GAAG,SAAS,EAC/B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,IAAI,EACpC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,GACvC,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;AACnC;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,eAAe,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,EAC9C,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,IAAI,EACpC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,GACvC,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC"}
|
|
@@ -3,14 +3,23 @@ import { queueActions } from "./queue.js";
|
|
|
3
3
|
import { makeSignedActionsWithContext } from "./sign.js";
|
|
4
4
|
async function getDocument(documentId) {
|
|
5
5
|
try {
|
|
6
|
-
return await window.ph?.
|
|
6
|
+
return await window.ph?.legacyReactor?.getDocument(documentId);
|
|
7
7
|
}
|
|
8
8
|
catch (error) {
|
|
9
9
|
logger.debug(`Failed to get document with id ${documentId}:`, error);
|
|
10
10
|
return undefined;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
function getActionErrors(result, actions) {
|
|
14
|
+
return actions.reduce((errors, a) => {
|
|
15
|
+
const op = result.operations[a.scope].findLast((op) => op.action.id === a.id);
|
|
16
|
+
if (op?.error) {
|
|
17
|
+
errors.push(new Error(op.error));
|
|
18
|
+
}
|
|
19
|
+
return errors;
|
|
20
|
+
}, new Array());
|
|
21
|
+
}
|
|
22
|
+
export async function dispatchActions(actionOrActions, documentOrDocumentId, onErrors, onSuccess) {
|
|
14
23
|
const document = typeof documentOrDocumentId === "string"
|
|
15
24
|
? await getDocument(documentOrDocumentId)
|
|
16
25
|
: documentOrDocumentId;
|
|
@@ -24,6 +33,15 @@ export async function dispatchActions(actionOrActions, documentOrDocumentId) {
|
|
|
24
33
|
return;
|
|
25
34
|
}
|
|
26
35
|
const result = await queueActions(document, signedActionsWithContext);
|
|
36
|
+
if (onErrors && result) {
|
|
37
|
+
const errors = getActionErrors(result, signedActionsWithContext);
|
|
38
|
+
if (errors.length) {
|
|
39
|
+
onErrors(errors);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (onSuccess && result) {
|
|
43
|
+
onSuccess(result);
|
|
44
|
+
}
|
|
27
45
|
return result;
|
|
28
46
|
}
|
|
29
47
|
//# sourceMappingURL=dispatch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../../src/actions/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAC;AAEzD,KAAK,UAAU,WAAW,CACxB,UAAkB;IAElB,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,CAAC,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../../src/actions/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAC;AAEzD,KAAK,UAAU,WAAW,CACxB,UAAkB;IAElB,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,CAAC,EAAE,EAAE,aAAa,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,kCAAkC,UAAU,GAAG,EAAE,KAAK,CAAC,CAAC;QACrE,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,MAAkB,EAAE,OAAiB;IAC5D,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAClC,MAAM,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,CAC5C,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAC9B,CAAC;QAEF,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC;YACd,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,IAAI,KAAK,EAAS,CAAC,CAAC;AACzB,CAAC;AA4BD,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,eAA8C,EAC9C,oBAAqD,EACrD,QAAoC,EACpC,SAAwC;IAExC,MAAM,QAAQ,GACZ,OAAO,oBAAoB,KAAK,QAAQ;QACtC,CAAC,CAAC,MAAM,WAAW,CAAC,oBAAoB,CAAC;QACzC,CAAC,CAAC,oBAAoB,CAAC;IAE3B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,CAAC,KAAK,CACV,oBAAoB,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,YAAY,CACrE,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,wBAAwB,GAAG,MAAM,4BAA4B,CACjE,eAAe,EACf,QAAQ,CACT,CAAC;IACF,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9B,MAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;QACrD,OAAO;IACT,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;IAEtE,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;QACvB,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;QACjE,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IAED,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;QACxB,SAAS,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -3,14 +3,17 @@ import type { Node } from "document-drive";
|
|
|
3
3
|
import type { PHDocument } from "document-model";
|
|
4
4
|
export declare function downloadFile(document: PHDocument, fileName: string): void;
|
|
5
5
|
export declare function exportFile(document: PHDocument, suggestedName?: string): Promise<void | FileSystemFileHandle>;
|
|
6
|
-
export declare function loadFile(path: string | File): Promise<PHDocument<import("document-model").PHBaseState
|
|
7
|
-
export declare function addDocument(driveId: string, name: string, documentType: string, parentFolder?: string, document?: PHDocument, id?: string, preferredEditor?: string): Promise<import("document-drive").FileNode
|
|
6
|
+
export declare function loadFile(path: string | File): Promise<PHDocument<import("document-model").PHBaseState>>;
|
|
7
|
+
export declare function addDocument(driveId: string, name: string, documentType: string, parentFolder?: string, document?: PHDocument, id?: string, preferredEditor?: string): Promise<import("document-drive").FileNode>;
|
|
8
8
|
export declare function addFile(file: string | File, driveId: string, name?: string, parentFolder?: string): Promise<void>;
|
|
9
9
|
export declare function addFileWithProgress(file: string | File, driveId: string, name?: string, parentFolder?: string, onProgress?: FileUploadProgressCallback, documentTypes?: string[], resolveConflict?: ConflictResolution): Promise<import("document-drive").FileNode | undefined>;
|
|
10
10
|
export declare function updateFile(driveId: string, nodeId: string, documentType?: string, name?: string, parentFolder?: string): Promise<import("document-drive").FileNode | undefined>;
|
|
11
|
-
export declare function addFolder(driveId: string, name: string, parentFolder?: string): Promise<
|
|
11
|
+
export declare function addFolder(driveId: string, name: string, parentFolder?: string): Promise<Node>;
|
|
12
12
|
export declare function deleteNode(driveId: string, nodeId: string): Promise<void>;
|
|
13
13
|
export declare function renameNode(driveId: string, nodeId: string, name: string): Promise<Node | undefined>;
|
|
14
|
-
export declare function moveNode(driveId: string, src: Node, target: Node | undefined): Promise<PHDocument |
|
|
14
|
+
export declare function moveNode(driveId: string, src: Node, target: Node | undefined): Promise<PHDocument | {
|
|
15
|
+
source: PHDocument;
|
|
16
|
+
target: PHDocument;
|
|
17
|
+
} | undefined>;
|
|
15
18
|
export declare function copyNode(driveId: string, src: Node, target: Node | undefined): Promise<PHDocument | undefined>;
|
|
16
19
|
//# sourceMappingURL=document.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../../src/actions/document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAElB,0BAA0B,EAC3B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAGV,IAAI,EACL,MAAM,gBAAgB,CAAC;AAexB,OAAO,KAAK,EAGV,UAAU,EACX,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../../src/actions/document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAElB,0BAA0B,EAC3B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAGV,IAAI,EACL,MAAM,gBAAgB,CAAC;AAexB,OAAO,KAAK,EAGV,UAAU,EACX,MAAM,gBAAgB,CAAC;AAuJxB,wBAAgB,YAAY,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,QAgBlE;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,UAAU,EAAE,aAAa,CAAC,EAAE,MAAM,wCAyC5E;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,6DA2CjD;AAED,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,MAAM,EACrB,QAAQ,CAAC,EAAE,UAAU,EACrB,EAAE,CAAC,EAAE,MAAM,EACX,eAAe,CAAC,EAAE,MAAM,8CA2FzB;AAED,wBAAsB,OAAO,CAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,iBA2FtB;AAED,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,EACrB,UAAU,CAAC,EAAE,0BAA0B,EACvC,aAAa,CAAC,EAAE,MAAM,EAAE,EACxB,eAAe,CAAC,EAAE,kBAAkB,0DAuKrC;AAED,wBAAsB,UAAU,CAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,MAAM,EACrB,IAAI,CAAC,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,0DA6BtB;AAED,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,MAAM,iBA8DtB;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAgC/D;AAED,wBAAsB,UAAU,CAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CA2C3B;AAED,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,IAAI,EACT,MAAM,EAAE,IAAI,GAAG,SAAS;;;eAmCzB;AA2BD,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,IAAI,EACT,MAAM,EAAE,IAAI,GAAG,SAAS,mCA2EzB"}
|
|
@@ -2,39 +2,73 @@ import { addFile as baseAddFile, addFolder as baseAddFolder, copyNode as baseCop
|
|
|
2
2
|
import { documentModelDocumentType } from "document-model";
|
|
3
3
|
import { baseLoadFromInput, baseSaveToFileHandle, createPresignedHeader, createZip, generateId, replayDocument, } from "document-model/core";
|
|
4
4
|
import { UnsupportedDocumentTypeError } from "../errors.js";
|
|
5
|
+
import { isLegacyReadEnabledSync, isLegacyWriteEnabledSync, } from "../hooks/use-feature-flags.js";
|
|
5
6
|
import { isDocumentTypeSupported } from "../utils/documents.js";
|
|
6
7
|
import { getUserPermissions } from "../utils/user.js";
|
|
7
8
|
import { queueActions, queueOperations, uploadOperations } from "./queue.js";
|
|
8
9
|
async function isDocumentInLocation(document, driveId, parentFolder) {
|
|
9
|
-
const
|
|
10
|
-
if (!reactor) {
|
|
11
|
-
return { isDuplicate: false };
|
|
12
|
-
}
|
|
10
|
+
const useLegacy = isLegacyReadEnabledSync();
|
|
13
11
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
if (useLegacy) {
|
|
13
|
+
const reactor = window.ph?.legacyReactor;
|
|
14
|
+
if (!reactor) {
|
|
15
|
+
throw new Error("Legacy reactor not initialized");
|
|
16
|
+
}
|
|
17
|
+
// Get the drive and check its nodes
|
|
18
|
+
const drive = await reactor.getDrive(driveId);
|
|
19
|
+
// Case 1: Check for duplicate by ID
|
|
20
|
+
const nodeById = drive.state.global.nodes.find((node) => node.id === document.header.id);
|
|
21
|
+
if (nodeById && nodeById.parentFolder === (parentFolder ?? null)) {
|
|
22
|
+
return {
|
|
23
|
+
isDuplicate: true,
|
|
24
|
+
duplicateType: "id",
|
|
25
|
+
nodeId: nodeById.id,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// Case 2: Check for duplicate by name + type in same parent folder
|
|
29
|
+
const nodeByNameAndType = drive.state.global.nodes.find((node) => isFileNode(node) &&
|
|
30
|
+
node.name === document.header.name &&
|
|
31
|
+
node.documentType === document.header.documentType &&
|
|
32
|
+
node.parentFolder === (parentFolder ?? null));
|
|
33
|
+
if (nodeByNameAndType) {
|
|
34
|
+
return {
|
|
35
|
+
isDuplicate: true,
|
|
36
|
+
duplicateType: "name",
|
|
37
|
+
nodeId: nodeByNameAndType.id,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return { isDuplicate: false };
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const reactorClient = window.ph?.reactorClient;
|
|
44
|
+
if (!reactorClient) {
|
|
45
|
+
throw new Error("ReactorClient not initialized");
|
|
46
|
+
}
|
|
47
|
+
// Get the drive and check its nodes
|
|
48
|
+
const { document: drive } = await reactorClient.get(driveId);
|
|
49
|
+
// Case 1: Check for duplicate by ID
|
|
50
|
+
const nodeById = drive.state.global.nodes.find((node) => node.id === document.header.id);
|
|
51
|
+
if (nodeById && nodeById.parentFolder === (parentFolder ?? null)) {
|
|
52
|
+
return {
|
|
53
|
+
isDuplicate: true,
|
|
54
|
+
duplicateType: "id",
|
|
55
|
+
nodeId: nodeById.id,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// Case 2: Check for duplicate by name + type in same parent folder
|
|
59
|
+
const nodeByNameAndType = drive.state.global.nodes.find((node) => isFileNode(node) &&
|
|
60
|
+
node.name === document.header.name &&
|
|
61
|
+
node.documentType === document.header.documentType &&
|
|
62
|
+
node.parentFolder === (parentFolder ?? null));
|
|
63
|
+
if (nodeByNameAndType) {
|
|
64
|
+
return {
|
|
65
|
+
isDuplicate: true,
|
|
66
|
+
duplicateType: "name",
|
|
67
|
+
nodeId: nodeByNameAndType.id,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return { isDuplicate: false };
|
|
36
71
|
}
|
|
37
|
-
return { isDuplicate: false };
|
|
38
72
|
}
|
|
39
73
|
catch {
|
|
40
74
|
// Drive doesn't exist or other error
|
|
@@ -87,9 +121,17 @@ export function downloadFile(document, fileName) {
|
|
|
87
121
|
.catch(logger.error);
|
|
88
122
|
}
|
|
89
123
|
export async function exportFile(document, suggestedName) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
124
|
+
// Ensure we have either reactor available for consistency
|
|
125
|
+
const useLegacy = isLegacyReadEnabledSync();
|
|
126
|
+
if (useLegacy) {
|
|
127
|
+
if (!window.ph?.legacyReactor) {
|
|
128
|
+
throw new Error("Legacy reactor not initialized");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
if (!window.ph?.reactorClient) {
|
|
133
|
+
throw new Error("ReactorClient not initialized");
|
|
134
|
+
}
|
|
93
135
|
}
|
|
94
136
|
let extension = "";
|
|
95
137
|
if (document.header.documentType === documentModelDocumentType) {
|
|
@@ -118,81 +160,140 @@ export async function exportFile(document, suggestedName) {
|
|
|
118
160
|
}
|
|
119
161
|
}
|
|
120
162
|
export async function loadFile(path) {
|
|
121
|
-
const
|
|
122
|
-
if (!reactor) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const documentModelModules = reactor.getDocumentModelModules();
|
|
163
|
+
const useLegacy = isLegacyReadEnabledSync();
|
|
126
164
|
const baseDocument = await baseLoadFromInput(path, (state) => state, { checkHashes: true });
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
165
|
+
if (useLegacy) {
|
|
166
|
+
const reactor = window.ph?.legacyReactor;
|
|
167
|
+
if (!reactor) {
|
|
168
|
+
throw new Error("Legacy reactor not initialized");
|
|
169
|
+
}
|
|
170
|
+
const documentModelModules = reactor.getDocumentModelModules();
|
|
171
|
+
const documentModelModule = documentModelModules.find((module) => module.documentModel.global.id === baseDocument.header.documentType);
|
|
172
|
+
if (!documentModelModule) {
|
|
173
|
+
throw new Error(`Document "${baseDocument.header.documentType}" is not supported`);
|
|
174
|
+
}
|
|
175
|
+
return documentModelModule.utils.loadFromInput(path);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const reactorClient = window.ph?.reactorClient;
|
|
179
|
+
if (!reactorClient) {
|
|
180
|
+
throw new Error("ReactorClient not initialized");
|
|
181
|
+
}
|
|
182
|
+
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
183
|
+
const documentModelModule = documentModelModules.find((module) => module.documentModel.global.id === baseDocument.header.documentType);
|
|
184
|
+
if (!documentModelModule) {
|
|
185
|
+
throw new Error(`Document "${baseDocument.header.documentType}" is not supported`);
|
|
186
|
+
}
|
|
187
|
+
return documentModelModule.utils.loadFromInput(path);
|
|
130
188
|
}
|
|
131
|
-
return documentModelModule.utils.loadFromInput(path);
|
|
132
189
|
}
|
|
133
190
|
export async function addDocument(driveId, name, documentType, parentFolder, document, id, preferredEditor) {
|
|
134
|
-
const reactor = window.ph?.reactor;
|
|
135
|
-
if (!reactor) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
191
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
139
192
|
if (!isAllowedToCreateDocuments) {
|
|
140
193
|
throw new Error("User is not allowed to create documents");
|
|
141
194
|
}
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
195
|
+
const useLegacy = isLegacyWriteEnabledSync();
|
|
196
|
+
if (useLegacy) {
|
|
197
|
+
const reactor = window.ph?.legacyReactor;
|
|
198
|
+
if (!reactor) {
|
|
199
|
+
throw new Error("Legacy reactor not initialized");
|
|
200
|
+
}
|
|
201
|
+
const drive = await reactor.getDrive(driveId);
|
|
202
|
+
const documentId = id ?? generateId();
|
|
203
|
+
const reactorDocumentModelModules = reactor.getDocumentModelModules();
|
|
204
|
+
const documentModelModuleFromReactor = reactorDocumentModelModules.find((module) => module.documentModel.global.id === documentType);
|
|
205
|
+
if (!documentModelModuleFromReactor) {
|
|
206
|
+
throw new Error(`Document model module for type ${documentType} not found`);
|
|
207
|
+
}
|
|
208
|
+
const newDocument = documentModelModuleFromReactor.utils.createDocument({
|
|
209
|
+
...document?.state,
|
|
210
|
+
});
|
|
211
|
+
newDocument.header = createPresignedHeader(documentId, documentType);
|
|
212
|
+
newDocument.header.name = name;
|
|
213
|
+
const documentMeta = preferredEditor ? { preferredEditor } : undefined;
|
|
214
|
+
await reactor.addDocument(newDocument, documentMeta);
|
|
215
|
+
const action = baseAddFile({
|
|
216
|
+
id: documentId,
|
|
217
|
+
name,
|
|
218
|
+
documentType,
|
|
219
|
+
parentFolder: parentFolder ?? null,
|
|
220
|
+
});
|
|
221
|
+
const unsafeCastAsDrive = (await queueActions(drive, action));
|
|
222
|
+
const node = unsafeCastAsDrive.state.global.nodes.find((node) => node.id === documentId);
|
|
223
|
+
if (!node || !isFileNode(node)) {
|
|
224
|
+
throw new Error("There was an error adding document");
|
|
225
|
+
}
|
|
226
|
+
return node;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
const reactorClient = window.ph?.reactorClient;
|
|
230
|
+
if (!reactorClient) {
|
|
231
|
+
throw new Error("ReactorClient not initialized");
|
|
232
|
+
}
|
|
233
|
+
// get the module
|
|
234
|
+
const documentModelModule = await reactorClient.getDocumentModelModule(documentType);
|
|
235
|
+
// create
|
|
236
|
+
const document = documentModelModule.utils.createDocument();
|
|
237
|
+
document.header.name = name;
|
|
238
|
+
// Create document using ReactorClient
|
|
239
|
+
let newDoc;
|
|
240
|
+
try {
|
|
241
|
+
newDoc = await reactorClient.createDocumentInDrive(driveId, document, parentFolder);
|
|
242
|
+
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
logger.error("Error adding document", e);
|
|
245
|
+
throw new Error("There was an error adding document");
|
|
246
|
+
}
|
|
247
|
+
// Return a file node structure for compatibility
|
|
248
|
+
return {
|
|
249
|
+
id: newDoc.header.id,
|
|
250
|
+
name: newDoc.header.name,
|
|
251
|
+
documentType,
|
|
252
|
+
parentFolder: parentFolder ?? null,
|
|
253
|
+
kind: "file",
|
|
254
|
+
};
|
|
166
255
|
}
|
|
167
|
-
return node;
|
|
168
256
|
}
|
|
169
257
|
export async function addFile(file, driveId, name, parentFolder) {
|
|
170
258
|
logger.verbose(`addFile(drive: ${driveId}, name: ${name}, folder: ${parentFolder})`);
|
|
171
|
-
const reactor = window.ph?.reactor;
|
|
172
|
-
if (!reactor) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
259
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
176
260
|
if (!isAllowedToCreateDocuments) {
|
|
177
261
|
throw new Error("User is not allowed to create files");
|
|
178
262
|
}
|
|
263
|
+
const useLegacy = isLegacyWriteEnabledSync();
|
|
179
264
|
const document = await loadFile(file);
|
|
180
|
-
if (!document) {
|
|
181
|
-
throw new Error("No document loaded");
|
|
182
|
-
}
|
|
183
|
-
const documentModule = reactor
|
|
184
|
-
.getDocumentModelModules()
|
|
185
|
-
.find((module) => module.documentModel.global.id === document.header.documentType);
|
|
186
|
-
if (!documentModule) {
|
|
187
|
-
throw new Error(`Document model module for type ${document.header.documentType} not found`);
|
|
188
|
-
}
|
|
189
265
|
let duplicateId = false;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
266
|
+
if (useLegacy) {
|
|
267
|
+
const reactor = window.ph?.legacyReactor;
|
|
268
|
+
if (!reactor) {
|
|
269
|
+
throw new Error("Legacy reactor not initialized");
|
|
270
|
+
}
|
|
271
|
+
const documentModule = reactor
|
|
272
|
+
.getDocumentModelModules()
|
|
273
|
+
.find((module) => module.documentModel.global.id === document.header.documentType);
|
|
274
|
+
if (!documentModule) {
|
|
275
|
+
throw new Error(`Document model module for type ${document.header.documentType} not found`);
|
|
276
|
+
}
|
|
277
|
+
try {
|
|
278
|
+
await reactor.getDocument(document.header.id);
|
|
279
|
+
duplicateId = true;
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
// document id not found
|
|
283
|
+
}
|
|
193
284
|
}
|
|
194
|
-
|
|
195
|
-
|
|
285
|
+
else {
|
|
286
|
+
const reactorClient = window.ph?.reactorClient;
|
|
287
|
+
if (!reactorClient) {
|
|
288
|
+
throw new Error("ReactorClient not initialized");
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
await reactorClient.get(document.header.id);
|
|
292
|
+
duplicateId = true;
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
// document id not found
|
|
296
|
+
}
|
|
196
297
|
}
|
|
197
298
|
const documentId = duplicateId ? generateId() : document.header.id;
|
|
198
299
|
const header = createPresignedHeader(documentId, document.header.documentType);
|
|
@@ -209,10 +310,7 @@ export async function addFile(file, driveId, name, parentFolder) {
|
|
|
209
310
|
return acc;
|
|
210
311
|
}, {}),
|
|
211
312
|
};
|
|
212
|
-
|
|
213
|
-
if (!fileNode) {
|
|
214
|
-
throw new Error("There was an error adding file");
|
|
215
|
-
}
|
|
313
|
+
await addDocument(driveId, name || document.header.name, document.header.documentType, parentFolder, initialDocument, documentId, document.header.meta?.preferredEditor);
|
|
216
314
|
// then add all the operations in chunks
|
|
217
315
|
uploadOperations(documentId, document.operations, queueOperations).catch((error) => {
|
|
218
316
|
throw error;
|
|
@@ -220,7 +318,7 @@ export async function addFile(file, driveId, name, parentFolder) {
|
|
|
220
318
|
}
|
|
221
319
|
export async function addFileWithProgress(file, driveId, name, parentFolder, onProgress, documentTypes, resolveConflict) {
|
|
222
320
|
logger.verbose(`addFileWithProgress(drive: ${driveId}, name: ${name}, folder: ${parentFolder})`);
|
|
223
|
-
const reactor = window.ph?.
|
|
321
|
+
const reactor = window.ph?.legacyReactor;
|
|
224
322
|
if (!reactor) {
|
|
225
323
|
return;
|
|
226
324
|
}
|
|
@@ -342,7 +440,7 @@ export async function addFileWithProgress(file, driveId, name, parentFolder, onP
|
|
|
342
440
|
}
|
|
343
441
|
}
|
|
344
442
|
export async function updateFile(driveId, nodeId, documentType, name, parentFolder) {
|
|
345
|
-
const reactor = window.ph?.
|
|
443
|
+
const reactor = window.ph?.legacyReactor;
|
|
346
444
|
if (!reactor) {
|
|
347
445
|
return;
|
|
348
446
|
}
|
|
@@ -364,67 +462,140 @@ export async function updateFile(driveId, nodeId, documentType, name, parentFold
|
|
|
364
462
|
return node;
|
|
365
463
|
}
|
|
366
464
|
export async function addFolder(driveId, name, parentFolder) {
|
|
367
|
-
const reactor = window.ph?.reactor;
|
|
368
|
-
if (!reactor) {
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
465
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
372
466
|
if (!isAllowedToCreateDocuments) {
|
|
373
467
|
throw new Error("User is not allowed to create folders");
|
|
374
468
|
}
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
469
|
+
const useLegacy = isLegacyWriteEnabledSync();
|
|
470
|
+
if (useLegacy) {
|
|
471
|
+
const reactor = window.ph?.legacyReactor;
|
|
472
|
+
if (!reactor) {
|
|
473
|
+
throw new Error("Legacy reactor not initialized");
|
|
474
|
+
}
|
|
475
|
+
const folderId = generateId();
|
|
476
|
+
const drive = await reactor.getDrive(driveId);
|
|
477
|
+
const unsafeCastAsDrive = (await queueActions(drive, baseAddFolder({
|
|
478
|
+
id: folderId,
|
|
479
|
+
name,
|
|
480
|
+
parentFolder,
|
|
481
|
+
})));
|
|
482
|
+
const node = unsafeCastAsDrive.state.global.nodes.find((node) => node.id === folderId);
|
|
483
|
+
if (!node || !isFolderNode(node)) {
|
|
484
|
+
throw new Error("There was an error adding folder");
|
|
485
|
+
}
|
|
486
|
+
return node;
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
const reactorClient = window.ph?.reactorClient;
|
|
490
|
+
if (!reactorClient) {
|
|
491
|
+
throw new Error("ReactorClient not initialized");
|
|
492
|
+
}
|
|
493
|
+
// Get the drive document and add folder action
|
|
494
|
+
const { document: drive } = await reactorClient.get(driveId);
|
|
495
|
+
const folderId = generateId();
|
|
496
|
+
const updatedDrive = await reactorClient.execute(driveId, "main", [
|
|
497
|
+
baseAddFolder({
|
|
498
|
+
id: folderId,
|
|
499
|
+
name,
|
|
500
|
+
parentFolder,
|
|
501
|
+
}),
|
|
502
|
+
]);
|
|
503
|
+
const node = updatedDrive.state.global.nodes.find((node) => node.id === folderId);
|
|
504
|
+
if (!node || !isFolderNode(node)) {
|
|
505
|
+
throw new Error("There was an error adding folder");
|
|
506
|
+
}
|
|
507
|
+
return node;
|
|
385
508
|
}
|
|
386
|
-
return node;
|
|
387
509
|
}
|
|
388
510
|
export async function deleteNode(driveId, nodeId) {
|
|
389
|
-
const reactor = window.ph?.reactor;
|
|
390
|
-
if (!reactor) {
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
511
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
394
512
|
if (!isAllowedToCreateDocuments) {
|
|
395
513
|
throw new Error("User is not allowed to delete documents");
|
|
396
514
|
}
|
|
397
|
-
const
|
|
398
|
-
|
|
515
|
+
const useLegacy = isLegacyWriteEnabledSync();
|
|
516
|
+
if (useLegacy) {
|
|
517
|
+
const reactor = window.ph?.legacyReactor;
|
|
518
|
+
if (!reactor) {
|
|
519
|
+
throw new Error("Legacy reactor not initialized");
|
|
520
|
+
}
|
|
521
|
+
const drive = await reactor.getDrive(driveId);
|
|
522
|
+
await queueActions(drive, baseDeleteNode({ id: nodeId }));
|
|
523
|
+
// now delete the document
|
|
524
|
+
await reactor.deleteDocument(nodeId);
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
const reactorClient = window.ph?.reactorClient;
|
|
528
|
+
if (!reactorClient) {
|
|
529
|
+
throw new Error("ReactorClient not initialized");
|
|
530
|
+
}
|
|
531
|
+
// delete the node in the drive document
|
|
532
|
+
await reactorClient.execute(driveId, "main", [
|
|
533
|
+
baseDeleteNode({ id: nodeId }),
|
|
534
|
+
]);
|
|
535
|
+
// now delete the document
|
|
536
|
+
await reactorClient.deleteDocument(nodeId);
|
|
537
|
+
}
|
|
399
538
|
}
|
|
400
539
|
export async function renameNode(driveId, nodeId, name) {
|
|
401
|
-
const reactor = window.ph?.reactor;
|
|
402
|
-
if (!reactor) {
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
540
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
406
541
|
if (!isAllowedToCreateDocuments) {
|
|
407
542
|
throw new Error("User is not allowed to rename documents");
|
|
408
543
|
}
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
544
|
+
const useLegacy = isLegacyWriteEnabledSync();
|
|
545
|
+
if (useLegacy) {
|
|
546
|
+
const reactor = window.ph?.legacyReactor;
|
|
547
|
+
if (!reactor) {
|
|
548
|
+
throw new Error("Legacy reactor not initialized");
|
|
549
|
+
}
|
|
550
|
+
const drive = await reactor.getDrive(driveId);
|
|
551
|
+
const unsafeCastAsDrive = (await queueActions(drive, updateNode({ id: nodeId, name })));
|
|
552
|
+
const node = unsafeCastAsDrive.state.global.nodes.find((node) => node.id === nodeId);
|
|
553
|
+
if (!node) {
|
|
554
|
+
throw new Error("There was an error renaming node");
|
|
555
|
+
}
|
|
556
|
+
return node;
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
const reactorClient = window.ph?.reactorClient;
|
|
560
|
+
if (!reactorClient) {
|
|
561
|
+
throw new Error("ReactorClient not initialized");
|
|
562
|
+
}
|
|
563
|
+
await reactorClient.rename(nodeId, name);
|
|
564
|
+
// Fetch the updated drive to return the node
|
|
565
|
+
const { document: drive } = await reactorClient.get(driveId);
|
|
566
|
+
const node = drive.state.global.nodes.find((n) => n.id === nodeId);
|
|
567
|
+
if (!node) {
|
|
568
|
+
throw new Error("There was an error renaming node");
|
|
569
|
+
}
|
|
570
|
+
return node;
|
|
414
571
|
}
|
|
415
|
-
return node;
|
|
416
572
|
}
|
|
417
573
|
export async function moveNode(driveId, src, target) {
|
|
418
|
-
const reactor = window.ph?.reactor;
|
|
419
|
-
if (!reactor) {
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
574
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
423
575
|
if (!isAllowedToCreateDocuments) {
|
|
424
576
|
throw new Error("User is not allowed to move documents");
|
|
425
577
|
}
|
|
426
|
-
const
|
|
427
|
-
|
|
578
|
+
const useLegacy = isLegacyWriteEnabledSync();
|
|
579
|
+
if (useLegacy) {
|
|
580
|
+
const reactor = window.ph?.legacyReactor;
|
|
581
|
+
if (!reactor) {
|
|
582
|
+
throw new Error("Legacy reactor not initialized");
|
|
583
|
+
}
|
|
584
|
+
const drive = await reactor.getDrive(driveId);
|
|
585
|
+
return await queueActions(drive, baseMoveNode({ srcFolder: src.id, targetParentFolder: target?.id }));
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
const reactorClient = window.ph?.reactorClient;
|
|
589
|
+
if (!reactorClient) {
|
|
590
|
+
throw new Error("ReactorClient not initialized");
|
|
591
|
+
}
|
|
592
|
+
// Get current parent folder from source node
|
|
593
|
+
const sourceParent = src.parentFolder ?? driveId;
|
|
594
|
+
const targetParent = target?.id ?? driveId;
|
|
595
|
+
return await reactorClient.moveChildren(sourceParent, targetParent, [
|
|
596
|
+
src.id,
|
|
597
|
+
]);
|
|
598
|
+
}
|
|
428
599
|
}
|
|
429
600
|
function _duplicateDocument(reactor, document, newId = generateId()) {
|
|
430
601
|
const documentModule = reactor
|
|
@@ -433,10 +604,10 @@ function _duplicateDocument(reactor, document, newId = generateId()) {
|
|
|
433
604
|
if (!documentModule) {
|
|
434
605
|
throw new Error(`Document model module for type ${document.header.documentType} not found`);
|
|
435
606
|
}
|
|
436
|
-
return replayDocument(document.initialState, document.operations, documentModule.reducer,
|
|
607
|
+
return replayDocument(document.initialState, document.operations, documentModule.reducer, createPresignedHeader(newId, document.header.documentType));
|
|
437
608
|
}
|
|
438
609
|
export async function copyNode(driveId, src, target) {
|
|
439
|
-
const reactor = window.ph?.
|
|
610
|
+
const reactor = window.ph?.legacyReactor;
|
|
440
611
|
if (!reactor) {
|
|
441
612
|
return;
|
|
442
613
|
}
|