@powerhousedao/reactor-browser 6.2.3-dev.23 → 6.2.3-dev.25
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/dist/{attachment-service-C14mVTk_.d.ts → attachment-service-ZjvRT9u7.d.ts} +97 -56
- package/dist/attachment-service-ZjvRT9u7.d.ts.map +1 -0
- package/dist/{client-CxJD0Ck2.d.ts → client-BAb4EAbM.d.ts} +3 -3
- package/dist/client-BAb4EAbM.d.ts.map +1 -0
- package/dist/{client-DjK30EQ-.js → client-BiJAJ9dW.js} +1 -1
- package/dist/{client-DjK30EQ-.js.map → client-BiJAJ9dW.js.map} +1 -1
- package/dist/{client-D4bkR4pH.js → client-C-y8-2iK.js} +15 -12
- package/dist/{client-D4bkR4pH.js.map → client-C-y8-2iK.js.map} +1 -1
- package/dist/{document-by-id-iXB59Ge-.js → dispatch-DDynSeBk.js} +168 -48
- package/dist/dispatch-DDynSeBk.js.map +1 -0
- package/dist/document-by-id-DFdjM023.js +16 -0
- package/dist/document-by-id-DFdjM023.js.map +1 -0
- package/dist/{document-model-modules-BSwKnUR_.js → document-model-modules-gE3Yh6Na.js} +32 -65
- package/dist/document-model-modules-gE3Yh6Na.js.map +1 -0
- package/dist/{document-operations-BjZmu1JC.js → document-operations-CwA7L3ef.js} +61 -42
- package/dist/document-operations-CwA7L3ef.js.map +1 -0
- package/dist/{global-D4e836Hk.d.ts → global-B8m-7kiK.d.ts} +31 -17
- package/dist/global-B8m-7kiK.d.ts.map +1 -0
- package/dist/{index-BvJaeywJ.d.ts → index-ERZ7o77d.d.ts} +19 -98
- package/dist/index-ERZ7o77d.d.ts.map +1 -0
- package/dist/{index-BIVDXw3K.d.ts → index-rtDmzViP.d.ts} +3 -3
- package/dist/index-rtDmzViP.d.ts.map +1 -0
- package/dist/index.d.ts +376 -362
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +103 -39
- package/dist/index.js.map +1 -1
- package/dist/{inspector-proxy-6h5VKAwt.d.ts → inspector-proxy-B2qjCMEv.d.ts} +9 -4
- package/dist/inspector-proxy-B2qjCMEv.d.ts.map +1 -0
- package/dist/{make-ph-event-functions-DBq3iWYn.js → make-ph-event-functions-FzpvQtj6.js} +1 -1
- package/dist/{make-ph-event-functions-DBq3iWYn.js.map → make-ph-event-functions-FzpvQtj6.js.map} +1 -1
- package/dist/{pglite-CntadC_p-9NDG14dS.d.ts → pglite-CntadC_p-DTkdF8sr.d.ts} +11 -33
- package/dist/pglite-CntadC_p-DTkdF8sr.d.ts.map +1 -0
- package/dist/{relational-D1RB45sA.js → relational-ChC_AWAK.js} +3 -2
- package/dist/{relational-D1RB45sA.js.map → relational-ChC_AWAK.js.map} +1 -1
- package/dist/{renown-rqK8sokh.js → renown-C9pYZRqf.js} +7 -8
- package/dist/{renown-rqK8sokh.js.map → renown-C9pYZRqf.js.map} +1 -1
- package/dist/{renown-BHxwP7xU.js → renown-Def5iO8k.js} +2 -2
- package/dist/{renown-BHxwP7xU.js.map → renown-Def5iO8k.js.map} +1 -1
- package/dist/src/ai/index.d.ts +51 -62
- package/dist/src/ai/index.d.ts.map +1 -1
- package/dist/src/ai/index.js +5 -8
- package/dist/src/ai/index.js.map +1 -1
- package/dist/src/analytics/index.d.ts +36 -44
- package/dist/src/analytics/index.d.ts.map +1 -1
- package/dist/src/analytics/index.js +2 -2
- package/dist/src/analytics/index.js.map +1 -1
- package/dist/src/document-model.d.ts +3 -4
- package/dist/src/document-model.d.ts.map +1 -1
- package/dist/src/document-model.js.map +1 -1
- package/dist/src/graphql/client.d.ts +4 -3
- package/dist/src/graphql/client.js +1 -1
- package/dist/src/graphql-client/entry.d.ts +5 -4
- package/dist/src/graphql-client/entry.js +3 -3
- package/dist/src/relational/index.d.ts +8 -9
- package/dist/src/relational/index.d.ts.map +1 -1
- package/dist/src/relational/index.js +1 -1
- package/dist/src/renown/index.d.ts +3 -2
- package/dist/src/renown/index.js +2 -2
- package/dist/src/rpc/index.d.ts +32 -31
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/rpc/index.js +6 -4
- package/dist/src/rpc/index.js.map +1 -1
- package/dist/{store-BJYcr_FL.js → store-DInXcjal.js} +1 -1
- package/dist/{store-BJYcr_FL.js.map → store-DInXcjal.js.map} +1 -1
- package/dist/{switchboard-Yt6ASJRx.js → switchboard-CXYzj-et.js} +58 -6
- package/dist/switchboard-CXYzj-et.js.map +1 -0
- package/dist/{types-6vDzbRRS.d.ts → types-520nWrB3.d.ts} +2 -2
- package/dist/types-520nWrB3.d.ts.map +1 -0
- package/dist/{types-N3Jy6Nry.d.ts → types-BCB-z7MN.d.ts} +17 -9
- package/dist/types-BCB-z7MN.d.ts.map +1 -0
- package/package.json +12 -12
- package/dist/attachment-service-C14mVTk_.d.ts.map +0 -1
- package/dist/client-CxJD0Ck2.d.ts.map +0 -1
- package/dist/document-by-id-iXB59Ge-.js.map +0 -1
- package/dist/document-model-modules-BSwKnUR_.js.map +0 -1
- package/dist/document-operations-BjZmu1JC.js.map +0 -1
- package/dist/global-D4e836Hk.d.ts.map +0 -1
- package/dist/index-BIVDXw3K.d.ts.map +0 -1
- package/dist/index-BvJaeywJ.d.ts.map +0 -1
- package/dist/inspector-proxy-6h5VKAwt.d.ts.map +0 -1
- package/dist/pglite-CntadC_p-9NDG14dS.d.ts.map +0 -1
- package/dist/switchboard-Yt6ASJRx.js.map +0 -1
- package/dist/types-6vDzbRRS.d.ts.map +0 -1
- package/dist/types-N3Jy6Nry.d.ts.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as makePHEventFunctions } from "./make-ph-event-functions-
|
|
1
|
+
import { _ as isDuplicateManifestError, t as useDispatch, v as isDuplicateModuleError } from "./dispatch-DDynSeBk.js";
|
|
2
|
+
import { t as makePHEventFunctions } from "./make-ph-event-functions-FzpvQtj6.js";
|
|
3
|
+
import { isDerivedDocumentId } from "@powerhousedao/shared/document-model";
|
|
3
4
|
import { useSyncExternalStore } from "react";
|
|
4
5
|
import slug from "slug";
|
|
5
6
|
//#region src/graphql-client/auth.ts
|
|
@@ -69,6 +70,7 @@ var NoSelectedDocumentError = class extends Error {
|
|
|
69
70
|
};
|
|
70
71
|
//#endregion
|
|
71
72
|
//#region src/utils/url.ts
|
|
73
|
+
const DERIVED_ID_LENGTH = 43;
|
|
72
74
|
function resolveUrlPathname(path) {
|
|
73
75
|
return new URL(path.replace(/^\/+/, ""), window.location.origin + (window.ph?.basePath ?? "/")).pathname;
|
|
74
76
|
}
|
|
@@ -82,12 +84,14 @@ function makeDriveUrlComponent(drive) {
|
|
|
82
84
|
if (!drive) return "";
|
|
83
85
|
return `/d/${slug(drive.header.slug)}`;
|
|
84
86
|
}
|
|
85
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Makes a URL component for a node: `<slugged name>-<id>`. The id is kept
|
|
89
|
+
* verbatim, since a v2-required id is case-sensitive base64url.
|
|
90
|
+
*/
|
|
86
91
|
function makeNodeSlug(node) {
|
|
87
92
|
if (!node) return "";
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
return slug(`${nodeName}-${node.id}`);
|
|
93
|
+
const nameSlug = node.name ? slug(node.name) : "";
|
|
94
|
+
return nameSlug ? `${nameSlug}-${node.id}` : node.id;
|
|
91
95
|
}
|
|
92
96
|
/** Extracts the node slug from a path.
|
|
93
97
|
*
|
|
@@ -102,8 +106,16 @@ function findUuid(input) {
|
|
|
102
106
|
if (!input) return void 0;
|
|
103
107
|
return /\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/.exec(input)?.[0];
|
|
104
108
|
}
|
|
109
|
+
/** The v2-required document id a slug ends with, if any. */
|
|
110
|
+
function findDerivedId(input) {
|
|
111
|
+
if (!input || input.length < DERIVED_ID_LENGTH) return void 0;
|
|
112
|
+
const start = input.length - DERIVED_ID_LENGTH;
|
|
113
|
+
if (start > 0 && input[start - 1] !== "-") return void 0;
|
|
114
|
+
const candidate = input.slice(start);
|
|
115
|
+
return isDerivedDocumentId(candidate) ? candidate : void 0;
|
|
116
|
+
}
|
|
105
117
|
function extractNodeIdFromSlug(nodeSlug) {
|
|
106
|
-
return findUuid(nodeSlug);
|
|
118
|
+
return findUuid(nodeSlug) ?? findDerivedId(nodeSlug);
|
|
107
119
|
}
|
|
108
120
|
function extractNodeIdFromPath(path) {
|
|
109
121
|
return extractNodeIdFromSlug(extractNodeSlugFromPath(path));
|
|
@@ -117,7 +129,7 @@ function extractDriveSlugFromPath(path) {
|
|
|
117
129
|
return /^\/d\/([^/]+)/.exec(currentPath)?.[1] ?? "";
|
|
118
130
|
}
|
|
119
131
|
function extractDriveIdFromSlug(driveSlug) {
|
|
120
|
-
return findUuid(driveSlug);
|
|
132
|
+
return findUuid(driveSlug) ?? findDerivedId(driveSlug);
|
|
121
133
|
}
|
|
122
134
|
function extractDriveIdFromPath(path) {
|
|
123
135
|
return extractDriveIdFromSlug(extractDriveSlugFromPath(path));
|
|
@@ -147,7 +159,8 @@ const addSelectedNodeIdEventHandler = selectedNodeIdEventFunctions.addEventHandl
|
|
|
147
159
|
/** Sets the selected node (file or folder). */
|
|
148
160
|
function setSelectedNode(nodeOrNodeSlug) {
|
|
149
161
|
const nodeSlug = typeof nodeOrNodeSlug === "string" ? nodeOrNodeSlug : makeNodeSlug(nodeOrNodeSlug);
|
|
150
|
-
|
|
162
|
+
const nodeId = extractNodeIdFromSlug(nodeSlug);
|
|
163
|
+
setSelectedNodeId(nodeId);
|
|
151
164
|
const driveSlugFromPath = extractDriveSlugFromPath(window.location.pathname);
|
|
152
165
|
if (!driveSlugFromPath) return;
|
|
153
166
|
if (!nodeSlug) {
|
|
@@ -276,56 +289,6 @@ function addSetSelectedDriveOnPopStateEventHandler() {
|
|
|
276
289
|
});
|
|
277
290
|
}
|
|
278
291
|
//#endregion
|
|
279
|
-
//#region src/utils/nodes.ts
|
|
280
|
-
/** Sorts nodes by name. */
|
|
281
|
-
function sortNodesByName(nodes) {
|
|
282
|
-
return nodes.toSorted((a, b) => a.name.localeCompare(b.name));
|
|
283
|
-
}
|
|
284
|
-
/** Returns whether a node is a file. */
|
|
285
|
-
function isFileNodeKind(node) {
|
|
286
|
-
if (!node) return false;
|
|
287
|
-
return node.kind.toUpperCase() === "FILE";
|
|
288
|
-
}
|
|
289
|
-
/** Returns whether a node is a folder. */
|
|
290
|
-
function isFolderNodeKind(node) {
|
|
291
|
-
if (!node) return false;
|
|
292
|
-
return node.kind.toUpperCase() === "FOLDER";
|
|
293
|
-
}
|
|
294
|
-
//#endregion
|
|
295
|
-
//#region src/hooks/items-in-selected-drive.ts
|
|
296
|
-
/** Returns the nodes in the selected drive. */
|
|
297
|
-
function useNodesInSelectedDrive() {
|
|
298
|
-
const [selectedDrive] = useSelectedDriveSafe();
|
|
299
|
-
return selectedDrive?.state.global.nodes;
|
|
300
|
-
}
|
|
301
|
-
/** Returns the file nodes in the selected drive. */
|
|
302
|
-
function useFileNodesInSelectedDrive() {
|
|
303
|
-
return useNodesInSelectedDrive()?.filter((n) => isFileNodeKind(n));
|
|
304
|
-
}
|
|
305
|
-
/** Returns the folder nodes in the selected drive. */
|
|
306
|
-
function useFolderNodesInSelectedDrive() {
|
|
307
|
-
return useNodesInSelectedDrive()?.filter((n) => isFolderNodeKind(n));
|
|
308
|
-
}
|
|
309
|
-
/** Returns the documents in the selected drive. */
|
|
310
|
-
function useDocumentsInSelectedDrive() {
|
|
311
|
-
const fileNodeIds = useFileNodesInSelectedDrive()?.map((node) => node.id);
|
|
312
|
-
return useDocumentsByIds(fileNodeIds);
|
|
313
|
-
}
|
|
314
|
-
/** Returns the document types supported by the selected drive, as defined by the document model documents present in the drive */
|
|
315
|
-
function useDocumentTypesInSelectedDrive() {
|
|
316
|
-
return (useDocumentsInSelectedDrive()?.filter(isDocumentModelDocument))?.map((doc) => doc.state.global.id);
|
|
317
|
-
}
|
|
318
|
-
function isDocumentModelDocument(document) {
|
|
319
|
-
return document.header.documentType === "powerhouse/document-model";
|
|
320
|
-
}
|
|
321
|
-
//#endregion
|
|
322
|
-
//#region src/hooks/selected-node.ts
|
|
323
|
-
/** Returns the selected node. */
|
|
324
|
-
function useSelectedNode() {
|
|
325
|
-
const selectedNodeId = useSelectedNodeId();
|
|
326
|
-
return useNodesInSelectedDrive()?.find((n) => n.id === selectedNodeId);
|
|
327
|
-
}
|
|
328
|
-
//#endregion
|
|
329
292
|
//#region src/hooks/vetra-packages.ts
|
|
330
293
|
const vetraPackageManagerFunctions = makePHEventFunctions("vetraPackageManager");
|
|
331
294
|
const useVetraPackageManager = vetraPackageManagerFunctions.useValue;
|
|
@@ -360,8 +323,10 @@ function updateReactorClientDocumentModels(packages) {
|
|
|
360
323
|
if (!registry || documentModelModules.length === 0) return;
|
|
361
324
|
const results = registry.registerModules(...documentModelModules);
|
|
362
325
|
const duplicateTypes = /* @__PURE__ */ new Set();
|
|
363
|
-
for (const result of results) if (result.status === "error")
|
|
364
|
-
|
|
326
|
+
for (const result of results) if (result.status === "error") {
|
|
327
|
+
if (isDuplicateModuleError(result.error)) duplicateTypes.add(result.item.documentModel.global.id);
|
|
328
|
+
else console.error("Failed to register document model module:", result.error);
|
|
329
|
+
}
|
|
365
330
|
if (duplicateTypes.size > 0) {
|
|
366
331
|
registry.unregisterModules(...duplicateTypes);
|
|
367
332
|
registry.registerModules(...documentModelModules.filter((module) => duplicateTypes.has(module.documentModel.global.id)));
|
|
@@ -373,8 +338,10 @@ function updateReactorClientUpgradeManifests(packages) {
|
|
|
373
338
|
if (!registry || upgradeManifests.length === 0) return;
|
|
374
339
|
const results = registry.registerUpgradeManifests(...upgradeManifests);
|
|
375
340
|
const duplicates = [];
|
|
376
|
-
for (const result of results) if (result.status === "error")
|
|
377
|
-
|
|
341
|
+
for (const result of results) if (result.status === "error") {
|
|
342
|
+
if (isDuplicateManifestError(result.error)) duplicates.push(result);
|
|
343
|
+
else console.error("Failed to register upgrade manifest:", result.error);
|
|
344
|
+
}
|
|
378
345
|
if (duplicates.length > 0) {
|
|
379
346
|
const duplicateTypes = duplicates.map((r) => r.item.documentType).filter((t) => !!t);
|
|
380
347
|
registry.unregisterUpgradeManifests(...duplicateTypes);
|
|
@@ -414,6 +381,6 @@ function useDocumentModelModuleById(id, version) {
|
|
|
414
381
|
return latestModule;
|
|
415
382
|
}
|
|
416
383
|
//#endregion
|
|
417
|
-
export {
|
|
384
|
+
export { findUuid as A, makeAuthMiddleware as B, extractDriveIdFromPath as C, extractNodeIdFromSlug as D, extractNodeIdFromPath as E, DocumentModelNotFoundError as F, DocumentTypeMismatchError as I, NoSelectedDocumentError as L, makeDriveUrlComponent as M, makeNodeSlug as N, extractNodeSlugFromPath as O, resolveUrlPathname as P, UnsupportedDocumentTypeError as R, createUrlWithPreservedParams as S, extractDriveSlugFromPath as T, setSelectedNode as _, useVetraPackageManager as a, setDrives as b, addSetSelectedDriveOnPopStateEventHandler as c, useSelectedDrive as d, useSelectedDriveId as f, addSetSelectedNodeOnPopStateEventHandler as g, addSelectedNodeIdEventHandler as h, setVetraPackageManager as i, getPathWithoutBase as j, findDerivedId as k, setSelectedDrive as l, addResetSelectedNodeEventHandler as m, useDocumentModelModules as n, useVetraPackages as o, useSelectedDriveSafe as p, addVetraPackageManagerEventHandler as r, addSelectedDriveIdEventHandler as s, useDocumentModelModuleById as t, setSelectedDriveId as u, useSelectedNodeId as v, extractDriveIdFromSlug as w, useDrives as x, addDrivesEventHandler as y, ambientRenownTokenProvider as z };
|
|
418
385
|
|
|
419
|
-
//# sourceMappingURL=document-model-modules-
|
|
386
|
+
//# sourceMappingURL=document-model-modules-gE3Yh6Na.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-model-modules-gE3Yh6Na.js","names":[],"sources":["../src/graphql-client/auth.ts","../src/errors.ts","../src/utils/url.ts","../src/hooks/drives.ts","../src/hooks/set-selected-node.ts","../src/hooks/selected-drive.ts","../src/hooks/vetra-packages.ts","../src/hooks/document-model-modules.ts"],"sourcesContent":["import type { SdkFunctionWrapper } from \"../graphql/gen/schema.js\";\n\n/**\n * Resolves the bearer token to send with a request.\n *\n * Returning `undefined` (or an empty string) means \"send this request\n * anonymously\": open Switchboards must keep serving reads to logged-out users.\n */\nexport type BearerTokenProvider = () => Promise<string | undefined>;\n\n/** Lifetime requested for an ambient Renown token, in seconds. */\nconst ambientTokenExpiresInSeconds = 600;\n\n/**\n * The default token provider: the token of the currently logged-in Renown user.\n *\n * It is deliberately resolved from `window.ph` on every call rather than\n * captured at construction time, so a client built before login starts sending\n * the token as soon as there is one.\n *\n * The token is requested WITHOUT an `aud` claim - the Switchboard verifier\n * rejects tokens that carry an audience.\n */\nexport async function ambientRenownTokenProvider(): Promise<\n string | undefined\n> {\n if (typeof window === \"undefined\") {\n return undefined;\n }\n\n const renown = window.ph?.renown;\n if (!renown?.user) {\n return undefined;\n }\n\n return renown.getBearerToken({ expiresIn: ambientTokenExpiresInSeconds });\n}\n\n/**\n * Builds the SDK middleware that authenticates every request.\n *\n * The token is resolved per request and never cached, so a login, a logout or\n * an expiry between two calls is picked up by the next one. When no token is\n * available the request goes out unauthenticated.\n */\nexport function makeAuthMiddleware(\n tokenProvider: BearerTokenProvider,\n): SdkFunctionWrapper {\n return async (action) => {\n const token = await tokenProvider();\n if (!token) {\n return action();\n }\n\n return action({ authorization: `Bearer ${token}` });\n };\n}\n","export class UnsupportedDocumentTypeError extends Error {\n constructor(documentType: string) {\n super(`Document type ${documentType} is not supported`);\n this.name = \"UnsupportedDocumentTypeError\";\n }\n\n static isError(error: unknown): error is UnsupportedDocumentTypeError {\n return (\n Error.isError(error) && error.name === \"UnsupportedDocumentTypeError\"\n );\n }\n}\n\nexport class DocumentModelNotFoundError extends Error {\n readonly documentType: string;\n readonly name = \"DocumentModelNotFoundError\";\n\n constructor(documentType: string) {\n super(`Document model module for type ${documentType} not found`);\n this.documentType = documentType;\n }\n\n static isError(error: unknown): error is DocumentModelNotFoundError {\n return Error.isError(error) && error.name === \"DocumentModelNotFoundError\";\n }\n}\n\nexport class DocumentTypeMismatchError extends Error {\n constructor(documentId: string, expectedType: string, actualType: string) {\n super(\n `Document ${documentId} is not of type ${expectedType}. Actual type: ${actualType}`,\n );\n }\n}\n\nexport class NoSelectedDocumentError extends Error {\n constructor() {\n super(\n \"There is no selected document. Did you mean to call 'useSelectedDocumentSafe' instead?\",\n );\n }\n}\n","import type {\n DocumentDriveDocument,\n Node,\n} from \"@powerhousedao/shared/document-drive\";\nimport { isDerivedDocumentId } from \"@powerhousedao/shared/document-model\";\nimport slug from \"slug\";\n\n// Length of the base64url id a v2-required document gets.\nconst DERIVED_ID_LENGTH = 43;\n\n// Returns url with base path plus provided path\nexport function resolveUrlPathname(path: string) {\n return new URL(\n path.replace(/^\\/+/, \"\"),\n window.location.origin + (window.ph?.basePath ?? \"/\"),\n ).pathname;\n}\n\n/** Returns the current path without the base path */\nexport function getPathWithoutBase(path: string) {\n const basePath = window.ph?.basePath ?? \"/\";\n return path.replace(basePath, basePath.endsWith(\"/\") ? \"/\" : \"\");\n}\n\n/** Makes a URL component for a drive. */\nexport function makeDriveUrlComponent(\n drive: DocumentDriveDocument | undefined,\n) {\n if (!drive) return \"\";\n return `/d/${slug(drive.header.slug)}`;\n}\n\n/**\n * Makes a URL component for a node: `<slugged name>-<id>`. The id is kept\n * verbatim, since a v2-required id is case-sensitive base64url.\n */\nexport function makeNodeSlug(node: Node | undefined) {\n if (!node) return \"\";\n const nameSlug = node.name ? slug(node.name) : \"\";\n return nameSlug ? `${nameSlug}-${node.id}` : node.id;\n}\n\n/** Extracts the node slug from a path.\n *\n * The path is expected to be in the format `/d/<drive-slug>/<node-slug>`.\n */\nexport function extractNodeSlugFromPath(path: string) {\n const currentPath = getPathWithoutBase(path);\n const match = /^\\/d\\/[^/]+\\/([^/]+)$/.exec(currentPath);\n return match?.[1];\n}\n\n/** Finds a UUID in a string, used for extracting node ids from node slugs in the URL. */\nexport function findUuid(input: string | undefined) {\n if (!input) return undefined;\n const uuidRegex =\n /\\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\\b/;\n const match = uuidRegex.exec(input);\n return match?.[0];\n}\n\n/** The v2-required document id a slug ends with, if any. */\nexport function findDerivedId(input: string | undefined) {\n if (!input || input.length < DERIVED_ID_LENGTH) return undefined;\n const start = input.length - DERIVED_ID_LENGTH;\n if (start > 0 && input[start - 1] !== \"-\") return undefined;\n const candidate = input.slice(start);\n return isDerivedDocumentId(candidate) ? candidate : undefined;\n}\n\nexport function extractNodeIdFromSlug(nodeSlug: string | undefined) {\n return findUuid(nodeSlug) ?? findDerivedId(nodeSlug);\n}\n\nexport function extractNodeIdFromPath(path: string) {\n const nodeSlug = extractNodeSlugFromPath(path);\n const nodeId = extractNodeIdFromSlug(nodeSlug);\n return nodeId;\n}\n\n/** Extracts the drive slug from a path.\n * Used for extracting drive ids from drive slugs in the URL.\n * Expects the path to be in the format `/d/<drive-slug>`.\n */\nexport function extractDriveSlugFromPath(path: string) {\n const currentPath = getPathWithoutBase(path);\n const match = /^\\/d\\/([^/]+)/.exec(currentPath);\n return match?.[1] ?? \"\";\n}\n\nexport function extractDriveIdFromSlug(driveSlug: string | undefined) {\n return findUuid(driveSlug) ?? findDerivedId(driveSlug);\n}\n\nexport function extractDriveIdFromPath(path: string) {\n const driveSlug = extractDriveSlugFromPath(path);\n const driveId = extractDriveIdFromSlug(driveSlug);\n return driveId;\n}\n\n/**\n * Creates a URL string with the given pathname while preserving existing query parameters.\n */\nexport function createUrlWithPreservedParams(pathname: string): string {\n const search = window.location.search;\n return search ? `${pathname}${search}` : pathname;\n}\n","import type { DocumentDriveDocument } from \"@powerhousedao/shared/document-drive\";\nimport type { SetPHGlobalValue, UsePHGlobalValue } from \"../types/global.js\";\nimport { makePHEventFunctions } from \"./make-ph-event-functions.js\";\n\nconst drivesEventFunctions = makePHEventFunctions(\"drives\");\n\n/** Returns all of the drives in the reactor */\nexport const useDrives: UsePHGlobalValue<DocumentDriveDocument[]> =\n drivesEventFunctions.useValue;\n\n/** Sets the drives in the reactor */\nexport const setDrives: SetPHGlobalValue<DocumentDriveDocument[]> =\n drivesEventFunctions.setValue;\n\n/** Adds an event handler for the drives */\nexport const addDrivesEventHandler = drivesEventFunctions.addEventHandler;\n","import type { Node } from \"@powerhousedao/shared/document-drive\";\nimport {\n createUrlWithPreservedParams,\n extractDriveSlugFromPath,\n extractNodeIdFromSlug,\n extractNodeSlugFromPath,\n makeNodeSlug,\n resolveUrlPathname,\n} from \"../utils/url.js\";\nimport { makePHEventFunctions } from \"./make-ph-event-functions.js\";\n\nconst selectedNodeIdEventFunctions = makePHEventFunctions(\"selectedNodeId\");\nexport const useSelectedNodeId = selectedNodeIdEventFunctions.useValue;\nconst setSelectedNodeId = selectedNodeIdEventFunctions.setValue;\nexport const addSelectedNodeIdEventHandler =\n selectedNodeIdEventFunctions.addEventHandler;\n\n/** Sets the selected node (file or folder). */\nexport function setSelectedNode(nodeOrNodeSlug: Node | string | undefined) {\n const nodeSlug =\n typeof nodeOrNodeSlug === \"string\"\n ? nodeOrNodeSlug\n : makeNodeSlug(nodeOrNodeSlug);\n const nodeId = extractNodeIdFromSlug(nodeSlug);\n setSelectedNodeId(nodeId);\n const driveSlugFromPath = extractDriveSlugFromPath(window.location.pathname);\n if (!driveSlugFromPath) {\n return;\n }\n if (!nodeSlug) {\n const pathname = resolveUrlPathname(`/d/${driveSlugFromPath}`);\n if (pathname === window.location.pathname) {\n return;\n }\n window.history.pushState(null, \"\", createUrlWithPreservedParams(pathname));\n return;\n }\n const pathname = resolveUrlPathname(`/d/${driveSlugFromPath}/${nodeSlug}`);\n if (pathname === window.location.pathname) {\n return;\n }\n window.history.pushState(null, \"\", createUrlWithPreservedParams(pathname));\n}\n\nexport function addResetSelectedNodeEventHandler() {\n window.addEventListener(\"ph:selectedDriveIdUpdated\", () => {\n setSelectedNodeId(undefined);\n });\n}\n\nexport function addSetSelectedNodeOnPopStateEventHandler() {\n window.addEventListener(\"popstate\", () => {\n const pathname = window.location.pathname;\n const nodeSlug = extractNodeSlugFromPath(pathname);\n // The slug embeds the id (`<name>-<uuid>`); compare ids, not slug vs id.\n const nodeId = extractNodeIdFromSlug(nodeSlug);\n const selectedNodeId = window.ph?.selectedNodeId;\n if (nodeId !== selectedNodeId) {\n setSelectedNode(nodeSlug);\n }\n });\n}\n","import type { DocumentDispatch } from \"@powerhousedao/reactor-browser\";\nimport type {\n DocumentDriveAction,\n DocumentDriveDocument,\n} from \"@powerhousedao/shared/document-drive\";\nimport {\n createUrlWithPreservedParams,\n extractDriveIdFromPath,\n extractDriveSlugFromPath,\n extractNodeSlugFromPath,\n resolveUrlPathname,\n} from \"../utils/url.js\";\nimport { useDispatch } from \"./dispatch.js\";\nimport { useDrives } from \"./drives.js\";\nimport { makePHEventFunctions } from \"./make-ph-event-functions.js\";\nimport { setSelectedNode } from \"./set-selected-node.js\";\n\nconst selectedDriveIdEventFunctions = makePHEventFunctions(\"selectedDriveId\");\n\n/** Returns the selected drive id */\nexport const useSelectedDriveId = selectedDriveIdEventFunctions.useValue;\n\n/** Sets the selected drive id */\nexport const setSelectedDriveId = selectedDriveIdEventFunctions.setValue;\n\n/** Adds an event handler for the selected drive id */\nexport const addSelectedDriveIdEventHandler =\n selectedDriveIdEventFunctions.addEventHandler;\n\n/** Returns the selected drive */\nexport function useSelectedDrive() {\n const drive = useSelectedDriveSafe();\n if (!drive[0]) {\n throw new Error(\n \"There is no drive selected. Did you mean to call 'useSelectedDriveSafe'?\",\n );\n }\n\n return drive;\n}\n\n/** Returns the selected drive, or undefined if no drive is selected */\nexport function useSelectedDriveSafe() {\n const selectedDriveId = useSelectedDriveId();\n const drives = useDrives();\n const selectedDrive = drives?.find(\n (drive) => drive.header.id === selectedDriveId,\n );\n\n const [drive, dispatch] = useDispatch(selectedDrive);\n if (!selectedDrive) {\n return [undefined, undefined] as const;\n }\n return [drive, dispatch] as [\n DocumentDriveDocument,\n DocumentDispatch<DocumentDriveAction>,\n ];\n}\n\nexport function setSelectedDrive(\n driveOrDriveSlug: string | DocumentDriveDocument | undefined,\n) {\n const driveSlug =\n typeof driveOrDriveSlug === \"string\"\n ? driveOrDriveSlug\n : driveOrDriveSlug?.header.slug;\n\n // A full drive document is selected directly — a just-created drive\n // navigates before the collection refresh. Slugs go through the lookup.\n const drives = window.ph?.drives;\n const drive =\n typeof driveOrDriveSlug === \"object\" && driveOrDriveSlug !== null\n ? driveOrDriveSlug\n : drives?.find((d) => d.header.slug === driveSlug);\n const driveId = drive?.header.id;\n\n // A URL-pinned slug with no matching drive: the deep link may predate\n // remote drive registration, so defer instead of rewriting the URL.\n if (\n !driveId &&\n driveSlug &&\n extractDriveSlugFromPath(window.location.pathname) === driveSlug\n ) {\n // Clear the previous selection so a stale drive doesn't render against\n // the new URL; the selected node resets with it, the URL is untouched.\n if (window.ph?.selectedDriveId) {\n setSelectedDriveId(undefined);\n }\n deferDriveSelection(driveSlug);\n return;\n }\n\n // Any resolved selection supersedes a pending deferred lookup.\n cancelPendingDriveSelection();\n\n setSelectedDriveId(driveId);\n\n if (!driveId) {\n const pathname = resolveUrlPathname(\"/\");\n if (pathname === window.location.pathname) {\n return;\n }\n window.history.pushState(null, \"\", createUrlWithPreservedParams(pathname));\n return;\n }\n const pathname = resolveUrlPathname(`/d/${driveSlug}`);\n if (pathname === window.location.pathname) {\n return;\n }\n window.history.pushState(null, \"\", createUrlWithPreservedParams(pathname));\n}\n\n// Tick between unresolved-slug checks; re-armed while a sync is in flight.\nconst DEFERRED_DRIVE_TICK_MS = 2_000;\n// Hard cap so a wedged remote can't pin the deep link forever.\nconst DEFERRED_DRIVE_MAX_WAIT_MS = 15_000;\n\n// True while any sync remote has not completed its first successful pull —\n// a drive may still be on its way in, so the deferred lookup keeps waiting.\nfunction isInitialSyncInFlight(): boolean {\n const remotes =\n window.ph?.reactorClientModule?.reactorModule?.syncModule?.syncManager?.list();\n if (!remotes?.length) {\n return false;\n }\n return remotes.some((remote) => {\n try {\n const snapshot = remote.channel.getConnectionState();\n return (\n snapshot.receivingPages ||\n (!snapshot.lastSuccessUtcMs && snapshot.state !== \"error\")\n );\n } catch {\n return false;\n }\n });\n}\n\nlet pendingHandler: (() => void) | undefined;\nlet pendingTimeout: ReturnType<typeof setTimeout> | undefined;\n\nfunction cancelPendingDriveSelection() {\n if (pendingHandler) {\n window.removeEventListener(\"ph:drivesUpdated\", pendingHandler);\n pendingHandler = undefined;\n }\n if (pendingTimeout) {\n clearTimeout(pendingTimeout);\n pendingTimeout = undefined;\n }\n}\n\n// Re-runs the slug lookup on each drives update until it resolves, then\n// restores the URL-pinned node. Unresolved slugs redirect once syncs settle.\nfunction deferDriveSelection(driveSlug: string) {\n cancelPendingDriveSelection();\n\n // Capture the node pinned in the deep link before setSelectedDrive\n // rewrites the URL to /d/<driveSlug>, dropping the node segment.\n const nodeSlug = extractNodeSlugFromPath(window.location.pathname);\n const handler = () => {\n const drive = window.ph?.drives?.find((d) => d.header.slug === driveSlug);\n if (!drive) {\n return;\n }\n cancelPendingDriveSelection();\n setSelectedDrive(driveSlug);\n setSelectedNode(nodeSlug);\n };\n pendingHandler = handler;\n window.addEventListener(\"ph:drivesUpdated\", handler);\n\n const deadline = Date.now() + DEFERRED_DRIVE_MAX_WAIT_MS;\n const scheduleTick = () => {\n pendingTimeout = setTimeout(() => {\n if (Date.now() < deadline && isInitialSyncInFlight()) {\n scheduleTick();\n return;\n }\n cancelPendingDriveSelection();\n const pathname = resolveUrlPathname(\"/\");\n if (pathname === window.location.pathname) {\n return;\n }\n window.history.pushState(\n null,\n \"\",\n createUrlWithPreservedParams(pathname),\n );\n }, DEFERRED_DRIVE_TICK_MS);\n };\n scheduleTick();\n}\n\nexport function addSetSelectedDriveOnPopStateEventHandler() {\n window.addEventListener(\"popstate\", () => {\n const pathname = window.location.pathname;\n const driveId = extractDriveIdFromPath(pathname);\n const selectedDriveId = window.ph?.selectedDriveId;\n if (driveId !== selectedDriveId) {\n setSelectedDrive(driveId);\n }\n });\n}\n","import type { DocumentModelLib } from \"document-model\";\nimport { useSyncExternalStore } from \"react\";\nimport {\n isDuplicateManifestError,\n isDuplicateModuleError,\n} from \"../reactor-interop.js\";\nimport type { IPackageManager } from \"../types/vetra.js\";\nimport { makePHEventFunctions } from \"./make-ph-event-functions.js\";\n\nconst vetraPackageManagerFunctions = makePHEventFunctions(\n \"vetraPackageManager\",\n);\n\nexport const useVetraPackageManager = vetraPackageManagerFunctions.useValue;\n\nconst EMPTY_VETRA_PACKAGES: DocumentModelLib[] = [];\nconst noPackageManagerUnsubscribe = () => {};\n\n/**\n * Returns all of the Vetra packages loaded by the Connect instance.\n *\n * The snapshot and subscription must keep stable identity while no package\n * manager is registered: `useSyncExternalStore` loops when the snapshot\n * changes on every read, which a fresh `[]` does.\n */\nexport const useVetraPackages = () => {\n const packageManager = useVetraPackageManager();\n\n return useSyncExternalStore(\n (cb) =>\n packageManager\n ? packageManager.subscribe(cb)\n : noPackageManagerUnsubscribe,\n () => packageManager?.packages ?? EMPTY_VETRA_PACKAGES,\n );\n};\n\n/** Adds the Vetra package manager event handler */\nexport const addVetraPackageManagerEventHandler =\n vetraPackageManagerFunctions.addEventHandler;\n\n/** Sets the Vetra package manager and registers its packages */\nexport function setVetraPackageManager(packageManager: IPackageManager) {\n vetraPackageManagerFunctions.setValue(packageManager);\n updateReactorClientDocumentModels(packageManager.packages);\n updateReactorClientUpgradeManifests(packageManager.packages);\n packageManager.subscribe(({ packages }) => {\n updateReactorClientDocumentModels(packages);\n updateReactorClientUpgradeManifests(packages);\n });\n}\n\nfunction updateReactorClientDocumentModels(packages: DocumentModelLib[]) {\n const documentModelModules = packages\n .flatMap((pkg) => pkg.documentModels)\n .filter(\n (module, index, modules) =>\n // dedupe by documentType and version\n modules.findIndex(\n (m) =>\n m.documentModel.global.id === module.documentModel.global.id &&\n (m.version ?? 1) === (module.version ?? 1),\n ) === index,\n );\n\n const registry =\n window.ph?.reactorClientModule?.reactorModule?.documentModelRegistry;\n if (!registry || documentModelModules.length === 0) return;\n\n const results = registry.registerModules(...documentModelModules);\n const duplicateTypes = new Set<string>();\n for (const result of results) {\n if (result.status === \"error\") {\n if (isDuplicateModuleError(result.error)) {\n duplicateTypes.add(result.item.documentModel.global.id);\n } else {\n console.error(\n \"Failed to register document model module:\",\n result.error,\n );\n }\n }\n }\n if (duplicateTypes.size > 0) {\n // unregisterModules is type-scoped, so replace the whole version family\n // with the incoming package's modules: re-registering only the duplicated\n // items would purge any new version that registered successfully above.\n registry.unregisterModules(...duplicateTypes);\n registry.registerModules(\n ...documentModelModules.filter((module) =>\n duplicateTypes.has(module.documentModel.global.id),\n ),\n );\n }\n}\n\nfunction updateReactorClientUpgradeManifests(packages: DocumentModelLib[]) {\n const upgradeManifests = packages\n .flatMap((pkg) => pkg.upgradeManifests)\n .filter((u) => u !== undefined);\n\n const registry =\n window.ph?.reactorClientModule?.reactorModule?.documentModelRegistry;\n if (!registry || upgradeManifests.length === 0) return;\n\n const results = registry.registerUpgradeManifests(...upgradeManifests);\n const duplicates = [];\n for (const result of results) {\n if (result.status === \"error\") {\n if (isDuplicateManifestError(result.error)) {\n duplicates.push(result);\n } else {\n console.error(\"Failed to register upgrade manifest:\", result.error);\n }\n }\n }\n if (duplicates.length > 0) {\n const duplicateTypes = duplicates\n .map((r) => r.item.documentType)\n .filter((t): t is string => !!t);\n registry.unregisterUpgradeManifests(...duplicateTypes);\n registry.registerUpgradeManifests(...duplicates.map((r) => r.item));\n }\n}\n","import type { DocumentModelModule } from \"document-model\";\nimport { useVetraPackages } from \"./vetra-packages.js\";\n\nexport function useDocumentModelModules(): DocumentModelModule[] | undefined {\n const vetraPackages = useVetraPackages();\n return vetraPackages\n .flatMap((pkg) => pkg.documentModels)\n .filter(\n (module, index, modules) =>\n // deduplicate by documentType and version\n modules.findIndex(\n (m) =>\n m.documentModel.global.id === module.documentModel.global.id &&\n m.version === module.version,\n ) === index,\n );\n}\n\n/**\n * Resolves a document model module by document type, mirroring the registry's\n * semantics (`IDocumentModelRegistry.getModule`): with `version` omitted the\n * LATEST version of the type wins (`version ?? 1` as each module's default),\n * with `version` given only an exact match is returned. The reactor resolves\n * modules the same way when a document is created, so metadata read through\n * this hook and the version a creation actually uses cannot disagree.\n */\nexport function useDocumentModelModuleById(\n id: string | null | undefined,\n version?: number,\n): DocumentModelModule | undefined {\n const documentModelModules = useDocumentModelModules();\n if (!id || !documentModelModules) return undefined;\n\n let latestModule: DocumentModelModule | undefined;\n let latestVersion = -1;\n for (const module of documentModelModules) {\n if (module.documentModel.global.id !== id) continue;\n const moduleVersion = module.version ?? 1;\n if (version !== undefined) {\n if (moduleVersion === version) return module;\n continue;\n }\n if (moduleVersion > latestVersion) {\n latestVersion = moduleVersion;\n latestModule = module;\n }\n }\n return latestModule;\n}\n"],"mappings":";;;;;;;AAWA,MAAM,+BAA+B;;;;;;;;;;;AAYrC,eAAsB,6BAEpB;CACA,IAAI,OAAO,WAAW,aACpB;CAGF,MAAM,SAAS,OAAO,IAAI;CAC1B,IAAI,CAAC,QAAQ,MACX;CAGF,OAAO,OAAO,eAAe,EAAE,WAAW,6BAA6B,CAAC;AAC1E;;;;;;;;AASA,SAAgB,mBACd,eACoB;CACpB,OAAO,OAAO,WAAW;EACvB,MAAM,QAAQ,MAAM,cAAc;EAClC,IAAI,CAAC,OACH,OAAO,OAAO;EAGhB,OAAO,OAAO,EAAE,eAAe,UAAU,QAAQ,CAAC;CACpD;AACF;;;ACxDA,IAAa,+BAAb,cAAkD,MAAM;CACtD,YAAY,cAAsB;EAChC,MAAM,iBAAiB,aAAa,kBAAkB;EACtD,KAAK,OAAO;CACd;CAEA,OAAO,QAAQ,OAAuD;EACpE,OACE,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS;CAE3C;AACF;AAEA,IAAa,6BAAb,cAAgD,MAAM;CACpD;CACA,OAAgB;CAEhB,YAAY,cAAsB;EAChC,MAAM,kCAAkC,aAAa,WAAW;EA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AK,MAAM,EAAE,KAAK,YAAY,CAAC,CAC/B,QAAQ,MAAmB,CAAC,CAAC,CAAC;EACjC,SAAS,2BAA2B,GAAG,cAAc;EACrD,SAAS,yBAAyB,GAAG,WAAW,KAAK,MAAM,EAAE,IAAI,CAAC;CACpE;AACF;;;ACxHA,SAAgB,0BAA6D;CAE3E,OADsB,iBACH,CAAC,CACjB,SAAS,QAAQ,IAAI,cAAc,CAAC,CACpC,QACE,QAAQ,OAAO,YAEd,QAAQ,WACL,MACC,EAAE,cAAc,OAAO,OAAO,OAAO,cAAc,OAAO,MAC1D,EAAE,YAAY,OAAO,OACzB,MAAM,KACV;AACJ;;;;;;;;;AAUA,SAAgB,2BACd,IACA,SACiC;CACjC,MAAM,uBAAuB,wBAAwB;CACrD,IAAI,CAAC,MAAM,CAAC,sBAAsB,OAAO,KAAA;CAEzC,IAAI;CACJ,IAAI,gBAAgB;CACpB,KAAK,MAAM,UAAU,sBAAsB;EACzC,IAAI,OAAO,cAAc,OAAO,OAAO,IAAI;EAC3C,MAAM,gBAAgB,OAAO,WAAW;EACxC,IAAI,YAAY,KAAA,GAAW;GACzB,IAAI,kBAAkB,SAAS,OAAO;GACtC;EACF;EACA,IAAI,gBAAgB,eAAe;GACjC,gBAAgB;GAChB,eAAe;EACjB;CACF;CACA,OAAO;AACT"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { C as queueOperations, S as queueActions, a as
|
|
2
|
-
import {
|
|
3
|
-
import { t as makePHEventFunctions } from "./make-ph-event-functions-
|
|
4
|
-
import {
|
|
5
|
-
import { f as addLoadingEventHandler, t as addRenownEventHandler } from "./renown-
|
|
1
|
+
import { C as queueOperations, S as queueActions, a as useDocumentCache, d as DocumentCache, f as IDLE_OPERATIONS_ENTRY, g as DOCUMENT_CHANGE_TYPE, m as isOperationCache, n as addDocumentCacheEventHandler, r as setDocumentCache, w as uploadOperations } from "./dispatch-DDynSeBk.js";
|
|
2
|
+
import { B as makeAuthMiddleware, F as DocumentModelNotFoundError, R as UnsupportedDocumentTypeError, c as addSetSelectedDriveOnPopStateEventHandler, f as useSelectedDriveId, g as addSetSelectedNodeOnPopStateEventHandler, h as addSelectedNodeIdEventHandler, i as setVetraPackageManager, m as addResetSelectedNodeEventHandler, r as addVetraPackageManagerEventHandler, s as addSelectedDriveIdEventHandler, y as addDrivesEventHandler, z as ambientRenownTokenProvider } from "./document-model-modules-gE3Yh6Na.js";
|
|
3
|
+
import { t as makePHEventFunctions } from "./make-ph-event-functions-FzpvQtj6.js";
|
|
4
|
+
import { i as PhDocumentFieldsFragmentDoc, n as DocumentChangesDocument, t as createClient$1 } from "./client-C-y8-2iK.js";
|
|
5
|
+
import { f as addLoadingEventHandler, t as addRenownEventHandler } from "./renown-Def5iO8k.js";
|
|
6
6
|
import { logger } from "document-model";
|
|
7
|
-
import { UnsupportedDocumentModelVersionError, assertAuthPreservedOnDuplicate, baseLoadFromInput, baseLoadFromInputVersioned, baseSaveToFileHandle, createPresignedHeader, createZip, deserializeSignature, documentModelDocumentType, generateId, hashDocumentStateForScope, normalizeDocumentModelVersion, replayDocumentVersioned, setName, setPreferredEditor, toTransportAction } from "@powerhousedao/shared/document-model";
|
|
8
7
|
import { addFolder, copyNode, generateNodesCopy, handleTargetNameCollisions, isFileNode, isFolderNode, moveNode, updateNode } from "@powerhousedao/shared/document-drive";
|
|
8
|
+
import { UnsupportedDocumentModelVersionError, actionSignerIdentity, actionSigningTarget, assertAuthPreservedOnDuplicate, baseLoadFromInput, baseLoadFromInputVersioned, baseSaveToFileHandle, createCopyHeader, createPresignedHeader, createZip, deserializeSignature, documentModelDocumentType, generateId, hasDerivedDocumentId, hashDocumentStateForScope, normalizeDocumentModelVersion, replayDocumentVersioned, setName, setPreferredEditor, signaturePolicyOf, toTransportAction, withSignaturePolicy } from "@powerhousedao/shared/document-model";
|
|
9
9
|
import { allPass, conditional, constant, forEachObj, funnel, isDefined, isNot, isStrictEqual, isString, isTruthy, once } from "remeda";
|
|
10
10
|
import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
11
11
|
import { GraphQLClient } from "graphql-request";
|
|
@@ -39,9 +39,10 @@ function showCreateDocumentModal(documentType, documentModelVersion) {
|
|
|
39
39
|
}
|
|
40
40
|
/** Shows the delete node modal */
|
|
41
41
|
function showDeleteNodeModal(nodeOrId) {
|
|
42
|
+
const id = typeof nodeOrId === "string" ? nodeOrId : nodeOrId.id;
|
|
42
43
|
setPHModal({
|
|
43
44
|
type: "deleteItem",
|
|
44
|
-
id
|
|
45
|
+
id
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
//#endregion
|
|
@@ -76,7 +77,7 @@ function getUserPermissions() {
|
|
|
76
77
|
}
|
|
77
78
|
//#endregion
|
|
78
79
|
//#region src/actions/document.ts
|
|
79
|
-
const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
|
|
80
|
+
const NON_DOMAIN_SCOPES = /* @__PURE__ */ new Set(["auth", "document"]);
|
|
80
81
|
/** An unreadable drive cannot be shown to hold no duplicate, so reads throw. */
|
|
81
82
|
async function isDocumentInLocation(reactorClient, document, driveId, parentFolder) {
|
|
82
83
|
const drive = await reactorClient.get(driveId);
|
|
@@ -293,7 +294,7 @@ async function addDocument(driveId, name, documentType, parentFolder, document,
|
|
|
293
294
|
if (!module) throw new Error(`Document model not found for type: ${documentType} with version: ${documentModelVersion}`);
|
|
294
295
|
documentModelModule = module;
|
|
295
296
|
} else documentModelModule = await reactorClient.getDocumentModelModule(documentType);
|
|
296
|
-
const newDocument = document ?? documentModelModule.utils.createDocument();
|
|
297
|
+
const newDocument = document ?? withSignaturePolicy(documentModelModule.utils.createDocument(), await reactorClient.getCreateSignaturePolicy());
|
|
297
298
|
if (!document) newDocument.state.document.version = documentModelModule.version ?? 1;
|
|
298
299
|
newDocument.header.name = name;
|
|
299
300
|
if (preferredEditor) newDocument.header.meta = {
|
|
@@ -341,9 +342,24 @@ function isDocumentAlreadyExists(error) {
|
|
|
341
342
|
* fails leaves the drive untouched, so a retry has nothing to clean up.
|
|
342
343
|
*/
|
|
343
344
|
async function createImportedDocument(reactor, document, driveId, name, parentFolder) {
|
|
344
|
-
|
|
345
|
+
const v2Required = signaturePolicyOf(document.header) === "v2-required";
|
|
346
|
+
const keepsId = (!v2Required || hasDerivedDocumentId(document.header)) && !await reactor.isDocumentIdTaken(document.header.id);
|
|
347
|
+
let documentId = keepsId ? document.header.id : generateId();
|
|
345
348
|
for (let attempt = 1;; attempt++) {
|
|
346
|
-
|
|
349
|
+
let header;
|
|
350
|
+
if (!v2Required) header = createPresignedHeader(documentId, document.header.documentType);
|
|
351
|
+
else if (keepsId && attempt === 1) {
|
|
352
|
+
header = createPresignedHeader(documentId, document.header.documentType);
|
|
353
|
+
header.createdAtUtcIso = document.header.createdAtUtcIso;
|
|
354
|
+
header.sig = {
|
|
355
|
+
...header.sig,
|
|
356
|
+
nonce: document.header.sig.nonce
|
|
357
|
+
};
|
|
358
|
+
header.protocolVersions = { ...document.header.protocolVersions };
|
|
359
|
+
} else {
|
|
360
|
+
header = createCopyHeader(document.header);
|
|
361
|
+
documentId = header.id;
|
|
362
|
+
}
|
|
347
363
|
header.lastModifiedAtUtcIso = document.header.createdAtUtcIso;
|
|
348
364
|
header.meta = document.header.meta;
|
|
349
365
|
header.name = name || document.header.name;
|
|
@@ -609,7 +625,7 @@ async function _duplicateDocument(reactor, document, newId = generateId()) {
|
|
|
609
625
|
reducers,
|
|
610
626
|
upgradeManifest
|
|
611
627
|
};
|
|
612
|
-
const header =
|
|
628
|
+
const header = createCopyHeader(document.header, newId, await reactor.getCreateSignaturePolicy());
|
|
613
629
|
const duplicated = replayDocumentVersioned(document.initialState, document.operations, config, header);
|
|
614
630
|
assertAuthPreservedOnDuplicate(document.header.id, document.state.auth, duplicated.state.auth);
|
|
615
631
|
return duplicated;
|
|
@@ -646,11 +662,13 @@ async function copyNode$1(driveId, src, target) {
|
|
|
646
662
|
const duplicatedDocument = await _duplicateDocument(reactor, await reactor.get(fileNodeToCopy.srcId), fileNodeToCopy.targetId);
|
|
647
663
|
const resolvedName = resolvedNamesMap.get(fileNodeToCopy.targetId);
|
|
648
664
|
if (resolvedName) duplicatedDocument.header.name = resolvedName;
|
|
665
|
+
fileNodeToCopy.targetId = duplicatedDocument.header.id;
|
|
649
666
|
await reactor.drives.addFile(driveId, duplicatedDocument, target?.id);
|
|
650
667
|
} catch (e) {
|
|
651
668
|
logger.error(`Error copying document ${fileNodeToCopy.srcId}: ${String(e)}`);
|
|
652
669
|
}
|
|
653
|
-
|
|
670
|
+
const copyActions = copyNodesInput.map((copyNodeInput) => copyNode(copyNodeInput));
|
|
671
|
+
return await queueActions(drive, copyActions);
|
|
654
672
|
}
|
|
655
673
|
/**
|
|
656
674
|
* Upgrades a document to a newer document model version. Defaults to the
|
|
@@ -669,6 +687,7 @@ function screamingSnakeToCamel(s) {
|
|
|
669
687
|
}
|
|
670
688
|
/** Error thrown when a push conflict is detected with the "reject" strategy. */
|
|
671
689
|
var ConflictError = class extends Error {
|
|
690
|
+
conflict;
|
|
672
691
|
constructor(conflict) {
|
|
673
692
|
super("Push conflict: remote has new operations since last pull");
|
|
674
693
|
this.conflict = conflict;
|
|
@@ -941,43 +960,42 @@ function stampAction(action, document, revision = document.header.revision[actio
|
|
|
941
960
|
};
|
|
942
961
|
}
|
|
943
962
|
/**
|
|
944
|
-
* Signs a stamped action
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
*
|
|
963
|
+
* Signs a stamped action for `target`, keeping any signatures it already
|
|
964
|
+
* carries. The signer reads `context.prevOpHash`, so this runs after
|
|
965
|
+
* {@link stampAction}. A v2 tuple covers the signer's identity, so the context
|
|
966
|
+
* takes the signer's user and app even when the action named others.
|
|
948
967
|
*/
|
|
949
|
-
async function signStampedAction(action, signer, signal) {
|
|
950
|
-
|
|
951
|
-
const
|
|
952
|
-
const app = actionSigner?.app ?? signer.app;
|
|
953
|
-
if (!user || !app) throw new Error("cannot sign an action: the signer has no user or app identity");
|
|
954
|
-
const signature = await signer.signAction(action, signal);
|
|
968
|
+
async function signStampedAction(action, signer, target, signal) {
|
|
969
|
+
if (!signer.user || !signer.app) throw new Error("cannot sign an action: the signer has no user or app identity");
|
|
970
|
+
const signature = await signer.signAction(action, target, signal);
|
|
955
971
|
return {
|
|
956
972
|
...action,
|
|
957
973
|
context: {
|
|
958
974
|
...action.context,
|
|
959
975
|
signer: {
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
signatures: [...actionSigner?.signatures ?? [], signature]
|
|
976
|
+
...actionSignerIdentity(signer),
|
|
977
|
+
signatures: [...action.context?.signer?.signatures ?? [], signature]
|
|
963
978
|
}
|
|
964
979
|
}
|
|
965
980
|
};
|
|
966
981
|
}
|
|
982
|
+
/** The log a snapshot's action is written to; the snapshot names the branch read. */
|
|
983
|
+
function snapshotTarget(action, snapshot) {
|
|
984
|
+
return actionSigningTarget(action, snapshot.header.id, snapshot.header.branch || "main");
|
|
985
|
+
}
|
|
967
986
|
/**
|
|
968
987
|
* Actions a snapshot batch cannot predict the next state for.
|
|
969
988
|
*
|
|
970
|
-
* `UNDO
|
|
971
|
-
*
|
|
989
|
+
* `UNDO` and `REDO` rewrite history the light read path never fetched (and
|
|
990
|
+
* the reducer appends no operation for them); `NOOP` is only ever produced
|
|
972
991
|
* by an undo chain; the document-scope actions run through the reactor's
|
|
973
992
|
* document-action handler rather than a document-model reducer
|
|
974
993
|
* (`DOCUMENT_SCOPE_ACTIONS` in packages/reactor/src/executor/util.ts) and
|
|
975
994
|
* `UPGRADE_DOCUMENT` changes which reducer applies mid-batch.
|
|
976
995
|
*/
|
|
977
|
-
const unsupportedBatchActions = new Set([
|
|
996
|
+
const unsupportedBatchActions = /* @__PURE__ */ new Set([
|
|
978
997
|
"UNDO",
|
|
979
998
|
"REDO",
|
|
980
|
-
"PRUNE",
|
|
981
999
|
"NOOP",
|
|
982
1000
|
"CREATE_DOCUMENT",
|
|
983
1001
|
"DELETE_DOCUMENT",
|
|
@@ -1020,7 +1038,7 @@ const predictionProtocolVersion = 2;
|
|
|
1020
1038
|
*/
|
|
1021
1039
|
async function prepareSignedActions(actions, snapshot, signer, module, signal) {
|
|
1022
1040
|
if (actions.length === 0) return [];
|
|
1023
|
-
if (actions.length === 1) return [await signStampedAction(stampAction(actions[0], snapshot), signer, signal)];
|
|
1041
|
+
if (actions.length === 1) return [await signStampedAction(stampAction(actions[0], snapshot), signer, snapshotTarget(actions[0], snapshot), signal)];
|
|
1024
1042
|
const scope = sharedScope(actions);
|
|
1025
1043
|
assertSupportedBatch(actions);
|
|
1026
1044
|
if (!module) throw new Error(`cannot sign ${actions.length} actions: no document model module for ${snapshot.header.documentType} was supplied, so the batch state cannot be predicted`);
|
|
@@ -1035,7 +1053,8 @@ async function prepareSignedActions(actions, snapshot, signer, module, signal) {
|
|
|
1035
1053
|
const signed = [];
|
|
1036
1054
|
for (const [index, action] of actions.entries()) {
|
|
1037
1055
|
throwIfAborted(signal, index);
|
|
1038
|
-
const
|
|
1056
|
+
const stamped = stampAction(action, working, revision);
|
|
1057
|
+
const signedAction = await signStampedAction(stamped, signer, snapshotTarget(stamped, snapshot), signal);
|
|
1039
1058
|
signed.push(signedAction);
|
|
1040
1059
|
const before = scopeOperationCount(working, scope);
|
|
1041
1060
|
let next;
|
|
@@ -1743,13 +1762,13 @@ function isGraphQLReactorClient(client) {
|
|
|
1743
1762
|
}
|
|
1744
1763
|
/** The schema's change types, mapped onto the reactor's. */
|
|
1745
1764
|
const documentChangeTypes = {
|
|
1746
|
-
[
|
|
1747
|
-
[
|
|
1748
|
-
[
|
|
1749
|
-
[
|
|
1750
|
-
[
|
|
1751
|
-
[
|
|
1752
|
-
[
|
|
1765
|
+
["CREATED"]: DOCUMENT_CHANGE_TYPE.Created,
|
|
1766
|
+
["DELETED"]: DOCUMENT_CHANGE_TYPE.Deleted,
|
|
1767
|
+
["UPDATED"]: DOCUMENT_CHANGE_TYPE.Updated,
|
|
1768
|
+
["PARENT_ADDED"]: DOCUMENT_CHANGE_TYPE.ParentAdded,
|
|
1769
|
+
["PARENT_REMOVED"]: DOCUMENT_CHANGE_TYPE.ParentRemoved,
|
|
1770
|
+
["CHILD_ADDED"]: DOCUMENT_CHANGE_TYPE.ChildAdded,
|
|
1771
|
+
["CHILD_REMOVED"]: DOCUMENT_CHANGE_TYPE.ChildRemoved
|
|
1753
1772
|
};
|
|
1754
1773
|
/**
|
|
1755
1774
|
* Decides whether an event reaches a subscriber.
|
|
@@ -1804,8 +1823,8 @@ function pagingInputFromPaging(paging) {
|
|
|
1804
1823
|
* `toReactorPropagationMode`.
|
|
1805
1824
|
*/
|
|
1806
1825
|
const propagationModeInputs = {
|
|
1807
|
-
cascade:
|
|
1808
|
-
none:
|
|
1826
|
+
cascade: "CASCADE",
|
|
1827
|
+
none: "ORPHAN"
|
|
1809
1828
|
};
|
|
1810
1829
|
function propagationModeInput(propagate) {
|
|
1811
1830
|
return propagate === void 0 ? void 0 : propagationModeInputs[propagate];
|
|
@@ -2603,4 +2622,4 @@ function useDocumentOperations(documentId, scope, options = {}) {
|
|
|
2603
2622
|
//#endregion
|
|
2604
2623
|
export { addDefaultDrivesUrlEventHandler as $, useIsAddLocalDrivesEnabled as $n, isAuthRefusalClose as $r, setEnabledEditors as $t, useReactorClientModule as A, fetchDocumentOperations as Ai, setRenownUrl as An, useSentryRelease as Ar, addRenownAdaptersEventHandler as At, useDragNode as B, addModalEventHandler as Bi, setWarnOutdatedApp as Bn, phAppConfigHooks as Br, addSwitchboardUrlEventHandler as Bt, addReactorClientModuleEventHandler as C, addDocument as Ci, setIsRelationalProcessorsEnabled as Cn, useRenownChainId as Cr, addIsExternalRelationalProcessorsEnabledEventHandler as Ct, useModelRegistry as D, deleteNode as Di, setRenownAdapters as Dn, useRouterBasename as Dr, addIsSentryTracingEnabledEventHandler as Dt, useDatabase as E, copyNode$1 as Ei, setLogLevel as En, useRequiresHardRefresh as Er, addIsRelationalProcessorsEnabledEventHandler as Et, usePackageDiscoveryService as F, renameNode as Fi, setSentryRelease as Fn, useWarnOutdatedApp as Fr, addRouterBasenameEventHandler as Ft, useFeatures as G, showPHModal as Gi, useDefaultDrivesUrl as Gn, setIsDragAndDropEnabled as Gr, phGlobalConfigSetters as Gt, useDropTarget as H, setPHModal as Hi, useAnalyticsDatabaseName as Hn, phDocumentEditorConfigHooks as Hr, addVersionEventHandler as Ht, addGraphQLReactorClientEventHandler as I, setPreferredEditorOnNode as Ii, setStudioMode as In, addAllowedDocumentTypesEventHandler as Ir, addSentryDsnEventHandler as It, useAttachmentService as J, useEnabledEditors as Jn, useIsDragAndDropEnabled as Jr, setBasePath as Jt, addAttachmentServiceEventHandler as K, usePHModal as Ki, useDisabledEditors as Kn, setIsExternalControlsEnabled as Kr, setAllowList as Kt, setGraphQLReactorClient as L, upgradeDocument as Li, setSwitchboardUrl as Ln, addIsDragAndDropEnabledEventHandler as Lr, addSentryEnvEventHandler as Lt, useSyncList as M, loadFile as Mi, setRouterBasename as Mn, useSwitchboardUrl as Mr, addRenownNetworkIdEventHandler as Mt, addPackageDiscoveryServiceEventHandler as N, moveNode$1 as Ni, setSentryDsn as Nn, useVersion as Nr, addRenownUrlEventHandler as Nt, usePGlite as O, exportFile as Oi, setRenownChainId as On, useSentryDsn as Or, addLocalDrivesEnabledEventHandler as Ot, setPackageDiscoveryService as P, renameDriveNode as Pi, setSentryEnv as Pn, useVersionCheckInterval as Pr, addRequiresHardRefreshEventHandler as Pt, addCliVersionEventHandler as Q, useIsAddDriveEnabled as Qn, viewFilterInputFromViewFilter as Qr, setDrivesPreserveStrategy as Qt, useGraphQLReactorClient as R, getUserPermissions as Ri, setVersion as Rn, addIsExternalControlsEnabledEventHandler as Rr, addSentryReleaseEventHandler as Rt, addReactorClientEventHandler as S, screamingSnakeToCamel as Si, setIsPublicDrivesEnabled as Sn, useRenownAdapters as Sr, addIsExternalProcessorsEnabledEventHandler as St, setReactorClientModule as T, addFolder$1 as Ti, setLocalDrivesEnabled as Tn, useRenownUrl as Tr, addIsPublicDrivesEnabledEventHandler as Tt, addFeaturesEventHandler as U, showCreateDocumentModal as Ui, useBasePath as Un, phDocumentEditorConfigSetters as Ur, addWarnOutdatedAppEventHandler as Ut, useDropNode as V, closePHModal as Vi, useAllowList as Vn, phAppConfigSetters as Vr, addVersionCheckIntervalEventHandler as Vt, setFeatures as W, showDeleteNodeModal as Wi, useCliVersion as Wn, setAllowedDocumentTypes as Wr, phGlobalConfigHooks as Wt, addAnalyticsDatabaseNameEventHandler as X, useGaTrackingId as Xn, GraphQLReactorClient as Xr, setDefaultDrivesUrl as Xt, addAllowListEventHandler as Y, useFileUploadOperationsChunkSize as Yn, useIsExternalControlsEnabled as Yr, setCliVersion as Yt, addBasePathEventHandler as Z, useIsAddCloudDrivesEnabled as Zn, isGraphQLReactorClient as Zr, setDisabledEditors as Zt, addRevisionHistoryVisibleEventHandler as _, ConflictError as _i, setIsEditorReadModeEnabled as _n, useIsPublicDrivesEnabled as _r, addIsDocumentModelSelectionSettingsEnabledEventHandler as _t, addPHEventHandlers as a, subgraphUrlFromGraphqlUrl as ai, setIsAddPublicDrivesEnabled as an, useIsDeleteCloudDrivesEnabled as ar, addIsAddCloudDrivesEnabledEventHandler as at, showRevisionHistory as b, extractRevisionMap as bi, setIsExternalRelationalProcessorsEnabled as bn, useLocalDrivesEnabled as br, addIsEditorReadModeEnabledEventHandler as bt, addToastEventHandler as c, resolveDocumentModelModule as ci, setIsAnalyticsExternalProcessorsEnabled as cn, useIsDiffAnalyticsEnabled as cr, addIsAddPublicDrivesEnabledEventHandler as ct, addSelectedTimelineRevisionEventHandler as d, stampAction as di, setIsDeleteLocalDrivesEnabled as dn, useIsEditorDebugModeEnabled as dr, addIsAnalyticsExternalProcessorsEnabledEventHandler as dt, makeAuthConnectionParams as ei, setFileUploadOperationsChunkSize as en, useIsAddPublicDrivesEnabled as er, addDisabledEditorsEventHandler as et, setSelectedTimelineRevision as f, MutateDocumentWithOperationsDocument as fi, setIsDeletePublicDrivesEnabled as fn, useIsEditorReadModeEnabled as fr, addIsCloudDrivesEnabledEventHandler as ft, useSelectedTimelineItem as g, revisionMapFromRevisionsList as gi, setIsEditorDebugModeEnabled as gn, useIsLocalDrivesEnabled as gr, addIsDiffAnalyticsEnabledEventHandler as gt, setSelectedTimelineItem as h, phDocumentFromMutation as hi, setIsDriveAnalyticsEnabled as hn, useIsExternalRelationalProcessorsEnabled as hr, addIsDeletePublicDrivesEnabledEventHandler as ht, useSwitchboardClient as i, describeGraphQLDocument as ii, setIsAddLocalDrivesEnabled as in, useIsCloudDrivesEnabled as ir, addGaTrackingIdEventHandler as it, useSync as j, getDocumentExtension as ji, setRequiresHardRefresh as jn, useStudioMode as jr, addRenownChainIdEventHandler as jt, useReactorClient as k, extractInitialState as ki, setRenownNetworkId as kn, useSentryEnv as kr, addLogLevelEventHandler as kt, setPHToast as l, prepareSignedActions as li, setIsCloudDrivesEnabled as ln, useIsDocumentModelSelectionSettingsEnabled as lr, addIsAnalyticsDatabaseWorkerEnabledEventHandler as lt, addSelectedTimelineItemEventHandler as m, phDocumentFromGetDocument as mi, setIsDocumentModelSelectionSettingsEnabled as mn, useIsExternalProcessorsEnabled as mr, addIsDeleteLocalDrivesEnabledEventHandler as mt, GraphQLReactorProvider as n, subscriptionsUrlFromGraphqlUrl as ni, setIsAddCloudDrivesEnabled as nn, useIsAnalyticsEnabled as nr, addEnabledEditorsEventHandler as nt, callEventHandlerRegisterFunctions as o, StaticPackageManager as oi, setIsAnalyticsDatabaseWorkerEnabled as on, useIsDeleteLocalDrivesEnabled as or, addIsAddDriveEnabledEventHandler as ot, useSelectedTimelineRevision as p, ReactorOperationFieldsFragmentDoc as pi, setIsDiffAnalyticsEnabled as pn, useIsExternalPackagesEnabled as pr, addIsDeleteCloudDrivesEnabledEventHandler as pt, setAttachmentService as q, useDrivesPreserveStrategy as qn, useAllowedDocumentTypes as qr, setAnalyticsDatabaseName as qt, ensurePHEventHandlers as r, SubgraphSdkRegistry as ri, setIsAddDriveEnabled as rn, useIsAnalyticsExternalProcessorsEnabled as rr, addFileUploadOperationsChunkSizeEventHandler as rt, commonGlobalEventHandlerFunctions as s, packageFromDocumentModels as si, setIsAnalyticsEnabled as sn, useIsDeletePublicDrivesEnabled as sr, addIsAddLocalDrivesEnabledEventHandler as st, useDocumentOperations as t, startDocumentChangesSubscription as ti, setGaTrackingId as tn, useIsAnalyticsDatabaseWorkerEnabled as tr, addDrivesPreserveStrategyEventHandler as tt, usePHToast as u, signStampedAction as ui, setIsDeleteCloudDrivesEnabled as un, useIsDriveAnalyticsEnabled as ur, addIsAnalyticsEnabledEventHandler as ut, hideRevisionHistory as v, buildPulledDocument as vi, setIsExternalPackagesEnabled as vn, useIsRelationalProcessorsEnabled as vr, addIsDriveAnalyticsEnabledEventHandler as vt, setReactorClient as w, addFileWithProgress as wi, setIsSentryTracingEnabled as wn, useRenownNetworkId as wr, addIsLocalDrivesEnabledEventHandler as wt, useRevisionHistoryVisible as x, hasRevisionConflict as xi, setIsLocalDrivesEnabled as xn, useLogLevel as xr, addIsExternalPackagesEnabledEventHandler as xt, setRevisionHistoryVisible as y, convertRemoteOperations as yi, setIsExternalProcessorsEnabled as yn, useIsSentryTracingEnabled as yr, addIsEditorDebugModeEnabledEventHandler as yt, addDraggingNodeEventHandler as z, isDocumentTypeSupported as zi, setVersionCheckInterval as zn, isExternalControlsEnabledEventFunctions as zr, addStudioModeEventHandler as zt };
|
|
2605
2624
|
|
|
2606
|
-
//# sourceMappingURL=document-operations-
|
|
2625
|
+
//# sourceMappingURL=document-operations-CwA7L3ef.js.map
|