@powerhousedao/reactor-browser 6.2.2-dev.70 → 6.2.2-dev.71
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/{document-operations-DQfMZpj8.js → document-operations-B2lxu6qg.js} +78 -70
- package/dist/document-operations-B2lxu6qg.js.map +1 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/src/graphql-client/entry.js +1 -1
- package/package.json +9 -9
- package/dist/document-operations-DQfMZpj8.js.map +0 -1
|
@@ -23,11 +23,6 @@ var UnsupportedDocumentTypeError = class extends Error {
|
|
|
23
23
|
return Error.isError(error) && error.name === "UnsupportedDocumentTypeError";
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
var DocumentNotFoundError = class extends Error {
|
|
27
|
-
constructor(documentId) {
|
|
28
|
-
super(`Document with id ${documentId} not found`);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
26
|
var DocumentModelNotFoundError = class extends Error {
|
|
32
27
|
documentType;
|
|
33
28
|
name = "DocumentModelNotFoundError";
|
|
@@ -114,15 +109,9 @@ function getUserPermissions() {
|
|
|
114
109
|
//#endregion
|
|
115
110
|
//#region src/actions/document.ts
|
|
116
111
|
const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
let drive;
|
|
121
|
-
try {
|
|
122
|
-
drive = await reactorClient.get(driveId);
|
|
123
|
-
} catch {
|
|
124
|
-
return { isDuplicate: false };
|
|
125
|
-
}
|
|
112
|
+
/** An unreadable drive cannot be shown to hold no duplicate, so reads throw. */
|
|
113
|
+
async function isDocumentInLocation(reactorClient, document, driveId, parentFolder) {
|
|
114
|
+
const drive = await reactorClient.get(driveId);
|
|
126
115
|
const nodeById = drive.state.global.nodes.find((node) => node.id === document.header.id);
|
|
127
116
|
if (nodeById && nodeById.parentFolder === (parentFolder ?? null)) return {
|
|
128
117
|
isDuplicate: true,
|
|
@@ -358,42 +347,72 @@ async function addDocument(driveId, name, documentType, parentFolder, document,
|
|
|
358
347
|
kind: "file"
|
|
359
348
|
};
|
|
360
349
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
for (
|
|
389
|
-
|
|
390
|
-
|
|
350
|
+
/**
|
|
351
|
+
* How many ids an import will try before giving up. The check before the create
|
|
352
|
+
* catches an id that is already taken; this bound covers the window between the
|
|
353
|
+
* two, where a create can still lose to a claim made in the meantime.
|
|
354
|
+
*/
|
|
355
|
+
const IMPORT_ID_ATTEMPTS = 3;
|
|
356
|
+
/** True when this error, or anything it wraps, is a taken document id. */
|
|
357
|
+
function isDocumentAlreadyExists(error) {
|
|
358
|
+
let current = error;
|
|
359
|
+
while (current instanceof Error) {
|
|
360
|
+
if (current.name === "DocumentAlreadyExistsError") return true;
|
|
361
|
+
current = current.cause;
|
|
362
|
+
}
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Creates the imported document under an id that is free, retrying on a
|
|
367
|
+
* collision.
|
|
368
|
+
*
|
|
369
|
+
* The check cannot stand on its own: it answers for the moment it ran, and the
|
|
370
|
+
* create that follows can still land on an id claimed in between. The store
|
|
371
|
+
* rejects that create as DocumentAlreadyExistsError, which is not retryable
|
|
372
|
+
* under the same id and is resolved by minting another one. A create that
|
|
373
|
+
* fails leaves the drive untouched, so a retry has nothing to clean up.
|
|
374
|
+
*/
|
|
375
|
+
async function createImportedDocument(reactor, document, driveId, name, parentFolder) {
|
|
376
|
+
let documentId = await reactor.isDocumentIdTaken(document.header.id) ? generateId() : document.header.id;
|
|
377
|
+
for (let attempt = 1;; attempt++) {
|
|
378
|
+
const header = createPresignedHeader(documentId, document.header.documentType);
|
|
379
|
+
header.lastModifiedAtUtcIso = document.header.createdAtUtcIso;
|
|
380
|
+
header.meta = document.header.meta;
|
|
381
|
+
header.name = name || document.header.name;
|
|
382
|
+
const initialDocument = {
|
|
383
|
+
...document,
|
|
384
|
+
header,
|
|
385
|
+
state: document.initialState,
|
|
386
|
+
operations: Object.keys(document.operations).reduce((acc, key) => {
|
|
387
|
+
acc[key] = [];
|
|
388
|
+
return acc;
|
|
389
|
+
}, {})
|
|
390
|
+
};
|
|
391
|
+
try {
|
|
392
|
+
const fileNode = await addDocument(driveId, name || document.header.name, document.header.documentType, parentFolder, initialDocument, documentId, document.header.meta?.preferredEditor);
|
|
393
|
+
if (!fileNode) throw new Error("There was an error adding file");
|
|
394
|
+
return {
|
|
395
|
+
documentId,
|
|
396
|
+
fileNode
|
|
397
|
+
};
|
|
398
|
+
} catch (error) {
|
|
399
|
+
if (!isDocumentAlreadyExists(error) || attempt === IMPORT_ID_ATTEMPTS) throw error;
|
|
400
|
+
logger.warn(`Document id ${documentId} was taken between the check and the create; importing under a new id`);
|
|
401
|
+
documentId = generateId();
|
|
402
|
+
}
|
|
391
403
|
}
|
|
392
404
|
}
|
|
393
405
|
async function addFileWithProgress(file, driveId, name, parentFolder, onProgress, documentTypes, resolveConflict) {
|
|
394
406
|
logger.verbose(`addFileWithProgress(drive: ${driveId}, name: ${name}, folder: ${parentFolder})`);
|
|
395
407
|
const reactor = window.ph?.reactorClientModule?.client;
|
|
396
|
-
if (!reactor)
|
|
408
|
+
if (!reactor) {
|
|
409
|
+
onProgress?.({
|
|
410
|
+
stage: "failed",
|
|
411
|
+
progress: 100,
|
|
412
|
+
error: "ReactorClient not initialized"
|
|
413
|
+
});
|
|
414
|
+
throw new Error("ReactorClient not initialized");
|
|
415
|
+
}
|
|
397
416
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
398
417
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create files");
|
|
399
418
|
try {
|
|
@@ -421,12 +440,19 @@ async function addFileWithProgress(file, driveId, name, parentFolder, onProgress
|
|
|
421
440
|
}
|
|
422
441
|
const discoveryService = window.ph?.packageDiscoveryService;
|
|
423
442
|
if (discoveryService && DocumentModelNotFoundError.isError(loadError)) {
|
|
424
|
-
retryAfterDiscovery(discoveryService, loadError.documentType, file, driveId, name, parentFolder, onProgress, documentTypes, resolveConflict)
|
|
443
|
+
retryAfterDiscovery(discoveryService, loadError.documentType, file, driveId, name, parentFolder, onProgress, documentTypes, resolveConflict).catch((retryError) => {
|
|
444
|
+
logger.error("Import retry after discovery failed: @error", retryError);
|
|
445
|
+
onProgress?.({
|
|
446
|
+
stage: "failed",
|
|
447
|
+
progress: 100,
|
|
448
|
+
error: retryError instanceof Error ? retryError.message : String(retryError)
|
|
449
|
+
});
|
|
450
|
+
});
|
|
425
451
|
return;
|
|
426
452
|
}
|
|
427
453
|
throw loadError;
|
|
428
454
|
}
|
|
429
|
-
const duplicateCheck = await isDocumentInLocation(document, driveId, parentFolder);
|
|
455
|
+
const duplicateCheck = await isDocumentInLocation(reactor, document, driveId, parentFolder);
|
|
430
456
|
if (duplicateCheck.isDuplicate && !resolveConflict) {
|
|
431
457
|
onProgress?.({
|
|
432
458
|
stage: "conflict",
|
|
@@ -458,27 +484,9 @@ async function addFileWithProgress(file, driveId, name, parentFolder, onProgress
|
|
|
458
484
|
stage: "initializing",
|
|
459
485
|
progress: 10
|
|
460
486
|
});
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
duplicateId = true;
|
|
465
|
-
} catch {}
|
|
466
|
-
const documentId = duplicateId ? generateId() : document.header.id;
|
|
467
|
-
const header = createPresignedHeader(documentId, document.header.documentType);
|
|
468
|
-
header.lastModifiedAtUtcIso = document.header.createdAtUtcIso;
|
|
469
|
-
header.meta = document.header.meta;
|
|
470
|
-
header.name = name || document.header.name;
|
|
471
|
-
const initialDocument = {
|
|
472
|
-
...document,
|
|
473
|
-
header,
|
|
474
|
-
state: document.initialState,
|
|
475
|
-
operations: Object.keys(document.operations).reduce((acc, key) => {
|
|
476
|
-
acc[key] = [];
|
|
477
|
-
return acc;
|
|
478
|
-
}, {})
|
|
479
|
-
};
|
|
480
|
-
const fileNode = await addDocument(driveId, name || document.header.name, document.header.documentType, parentFolder, initialDocument, documentId, document.header.meta?.preferredEditor);
|
|
481
|
-
if (!fileNode) throw new Error("There was an error adding file");
|
|
487
|
+
const created = await createImportedDocument(reactor, document, driveId, name, parentFolder);
|
|
488
|
+
const documentId = created.documentId;
|
|
489
|
+
const fileNode = created.fileNode;
|
|
482
490
|
onProgress?.({
|
|
483
491
|
stage: "initializing",
|
|
484
492
|
progress: 20
|
|
@@ -2923,6 +2931,6 @@ function useDocumentOperations(documentId) {
|
|
|
2923
2931
|
};
|
|
2924
2932
|
}
|
|
2925
2933
|
//#endregion
|
|
2926
|
-
export { useGraphQLReactorClient as $, ReactorOperationFieldsFragmentDoc as $i, setIsDeletePublicDrivesEnabled as $n, useIsEditorReadModeEnabled as $r, addIsCloudDrivesEnabledEventHandler as $t, isFolderNodeKind as A,
|
|
2934
|
+
export { useGraphQLReactorClient as $, ReactorOperationFieldsFragmentDoc as $i, setIsDeletePublicDrivesEnabled as $n, useIsEditorReadModeEnabled as $r, addIsCloudDrivesEnabledEventHandler as $t, isFolderNodeKind as A, usePHModal as Aa, phDocumentEditorConfigSetters as Ai, addWarnOutdatedAppEventHandler as An, useBasePath as Ar, addFeaturesEventHandler as At, setReactorClientModule as B, makeAuthConnectionParams as Bi, setEnabledEditors as Bn, useIsAddLocalDrivesEnabled as Br, addDefaultDrivesUrlEventHandler as Bt, useSelectedNode as C, isDocumentTypeSupported as Ca, addAllowedDocumentTypesEventHandler as Ci, addSentryDsnEventHandler as Cn, setStudioMode as Cr, extractNodeIdFromSlug as Ct, useFolderNodesInSelectedDrive as D, showCreateDocumentModal as Da, phAppConfigHooks as Di, addSwitchboardUrlEventHandler as Dn, setWarnOutdatedApp as Dr, makeDriveUrlComponent as Dt, useFileNodesInSelectedDrive as E, setPHModal as Ea, isExternalControlsEnabledEventFunctions as Ei, addStudioModeEventHandler as En, setVersionCheckInterval as Er, getPathWithoutBase as Et, showRevisionHistory as F, useIsDragAndDropEnabled as Fi, setBasePath as Fn, useEnabledEditors as Fr, useAttachmentService as Ft, useReactorClientModule as G, subgraphUrlFromGraphqlUrl as Gi, setIsAddLocalDrivesEnabled as Gn, useIsCloudDrivesEnabled as Gr, addGaTrackingIdEventHandler as Gt, useModelRegistry as H, subscriptionsUrlFromGraphqlUrl as Hi, setGaTrackingId as Hn, useIsAnalyticsDatabaseWorkerEnabled as Hr, addDrivesPreserveStrategyEventHandler as Ht, useRevisionHistoryVisible as I, useIsExternalControlsEnabled as Ii, setCliVersion as In, useFileUploadOperationsChunkSize as Ir, addAllowListEventHandler as It, addPackageDiscoveryServiceEventHandler as J, resolveDocumentModelModule as Ji, setIsAnalyticsEnabled as Jn, useIsDeletePublicDrivesEnabled as Jr, addIsAddLocalDrivesEnabledEventHandler as Jt, useSync as K, StaticPackageManager as Ki, setIsAddPublicDrivesEnabled as Kn, useIsDeleteCloudDrivesEnabled as Kr, addIsAddCloudDrivesEnabledEventHandler as Kt, addReactorClientEventHandler as L, GraphQLReactorClient as Li, setDefaultDrivesUrl as Ln, useGaTrackingId as Lr, addAnalyticsDatabaseNameEventHandler as Lt, addRevisionHistoryVisibleEventHandler as M, DocumentTypeMismatchError as Ma, setIsDragAndDropEnabled as Mi, phGlobalConfigSetters as Mn, useDefaultDrivesUrl as Mr, useFeatures as Mt, hideRevisionHistory as N, NoSelectedDocumentError as Na, setIsExternalControlsEnabled as Ni, setAllowList as Nn, useDisabledEditors as Nr, addAttachmentServiceEventHandler as Nt, useNodesInSelectedDrive as O, showDeleteNodeModal as Oa, phAppConfigSetters as Oi, addVersionCheckIntervalEventHandler as On, useAllowList as Or, makeNodeSlug as Ot, setRevisionHistoryVisible as P, UnsupportedDocumentTypeError as Pa, useAllowedDocumentTypes as Pi, setAnalyticsDatabaseName as Pn, useDrivesPreserveStrategy as Pr, setAttachmentService as Pt, setGraphQLReactorClient as Q, MutateDocumentWithOperationsDocument as Qi, setIsDeleteLocalDrivesEnabled as Qn, useIsEditorDebugModeEnabled as Qr, addIsAnalyticsExternalProcessorsEnabledEventHandler as Qt, addReactorClientModuleEventHandler as R, isGraphQLReactorClient as Ri, setDisabledEditors as Rn, useIsAddCloudDrivesEnabled as Rr, addBasePathEventHandler as Rt, useSelectedTimelineItem as S, getUserPermissions as Sa, useWarnOutdatedApp as Si, addRouterBasenameEventHandler as Sn, setSentryRelease as Sr, extractNodeIdFromPath as St, useDocumentsInSelectedDrive as T, closePHModal as Ta, addIsExternalControlsEnabledEventHandler as Ti, addSentryReleaseEventHandler as Tn, setVersion as Tr, findUuid as Tt, usePGlite as U, SubgraphSdkRegistry as Ui, setIsAddCloudDrivesEnabled as Un, useIsAnalyticsEnabled as Ur, addEnabledEditorsEventHandler as Ut, useDatabase as V, startDocumentChangesSubscription as Vi, setFileUploadOperationsChunkSize as Vn, useIsAddPublicDrivesEnabled as Vr, addDisabledEditorsEventHandler as Vt, useReactorClient as W, describeGraphQLDocument as Wi, setIsAddDriveEnabled as Wn, useIsAnalyticsExternalProcessorsEnabled as Wr, addFileUploadOperationsChunkSizeEventHandler as Wt, usePackageDiscoveryService as X, signStampedAction as Xi, setIsCloudDrivesEnabled as Xn, useIsDocumentModelSelectionSettingsEnabled as Xr, addIsAnalyticsDatabaseWorkerEnabledEventHandler as Xt, setPackageDiscoveryService as Y, prepareSignedActions as Yi, setIsAnalyticsExternalProcessorsEnabled as Yn, useIsDiffAnalyticsEnabled as Yr, addIsAddPublicDrivesEnabledEventHandler as Yt, addGraphQLReactorClientEventHandler as Z, stampAction as Zi, setIsDeleteCloudDrivesEnabled as Zn, useIsDriveAnalyticsEnabled as Zr, addIsAnalyticsEnabledEventHandler as Zt, addSelectedTimelineRevisionEventHandler as _, loadFile as _a, useSentryRelease as _i, addRenownAdaptersEventHandler as _n, setRenownUrl as _r, useDrives as _t, ensurePHEventHandlers as a, ConflictError as aa, useIsRelationalProcessorsEnabled as ai, addIsDriveAnalyticsEnabledEventHandler as an, setIsExternalPackagesEnabled as ar, addSetSelectedDriveOnPopStateEventHandler as at, addSelectedTimelineItemEventHandler as b, renameNode as ba, useVersion as bi, addRenownUrlEventHandler as bn, setSentryDsn as br, extractDriveIdFromSlug as bt, callEventHandlerRegisterFunctions as c, extractRevisionMap as ca, useLogLevel as ci, addIsExternalPackagesEnabledEventHandler as cn, setIsLocalDrivesEnabled as cr, useSelectedDrive as ct, setVetraPackageManager as d, addDocument as da, useRenownNetworkId as di, addIsLocalDrivesEnabledEventHandler as dn, setIsSentryTracingEnabled as dr, addResetSelectedNodeEventHandler as dt, ambientRenownTokenProvider as ea, useIsExternalPackagesEnabled as ei, addIsDeleteCloudDrivesEnabledEventHandler as en, setIsDiffAnalyticsEnabled as er, addDraggingNodeEventHandler as et, useVetraPackageManager as f, addFileWithProgress as fa, useRenownUrl as fi, addIsPublicDrivesEnabledEventHandler as fn, setLocalDrivesEnabled as fr, addSelectedNodeIdEventHandler as ft, usePHToast as g, exportFile as ga, useSentryEnv as gi, addLogLevelEventHandler as gn, setRenownNetworkId as gr, setDrives as gt, setPHToast as h, deleteNode as ha, useSentryDsn as hi, addLocalDrivesEnabledEventHandler as hn, setRenownChainId as hr, addDrivesEventHandler as ht, GraphQLReactorProvider as i, revisionMapFromRevisionsList as ia, useIsPublicDrivesEnabled as ii, addIsDocumentModelSelectionSettingsEnabledEventHandler as in, setIsEditorReadModeEnabled as ir, addSelectedDriveIdEventHandler as it, sortNodesByName as j, DocumentModelNotFoundError as ja, setAllowedDocumentTypes as ji, phGlobalConfigHooks as jn, useCliVersion as jr, setFeatures as jt, isFileNodeKind as k, showPHModal as ka, phDocumentEditorConfigHooks as ki, addVersionEventHandler as kn, useAnalyticsDatabaseName as kr, resolveUrlPathname as kt, commonGlobalEventHandlerFunctions as l, hasRevisionConflict as la, useRenownAdapters as li, addIsExternalProcessorsEnabledEventHandler as ln, setIsPublicDrivesEnabled as lr, useSelectedDriveId as lt, addToastEventHandler as m, copyNode$1 as ma, useRouterBasename as mi, addIsSentryTracingEnabledEventHandler as mn, setRenownAdapters as mr, setSelectedNode as mt, useDocumentModelModuleById as n, phDocumentFromGetDocument as na, useIsExternalRelationalProcessorsEnabled as ni, addIsDeletePublicDrivesEnabledEventHandler as nn, setIsDriveAnalyticsEnabled as nr, useDropNode as nt, useSwitchboardClient as o, buildPulledDocument as oa, useIsSentryTracingEnabled as oi, addIsEditorDebugModeEnabledEventHandler as on, setIsExternalProcessorsEnabled as or, setSelectedDrive as ot, useVetraPackages as p, addFolder$1 as pa, useRequiresHardRefresh as pi, addIsRelationalProcessorsEnabledEventHandler as pn, setLogLevel as pr, addSetSelectedNodeOnPopStateEventHandler as pt, useSyncList as q, packageFromDocumentModels as qi, setIsAnalyticsDatabaseWorkerEnabled as qn, useIsDeleteLocalDrivesEnabled as qr, addIsAddDriveEnabledEventHandler as qt, useDocumentModelModules as r, phDocumentFromMutation as ra, useIsLocalDrivesEnabled as ri, addIsDiffAnalyticsEnabledEventHandler as rn, setIsEditorDebugModeEnabled as rr, useDropTarget as rt, addPHEventHandlers as s, convertRemoteOperations as sa, useLocalDrivesEnabled as si, addIsEditorReadModeEnabledEventHandler as sn, setIsExternalRelationalProcessorsEnabled as sr, setSelectedDriveId as st, useDocumentOperations as t, makeAuthMiddleware as ta, useIsExternalProcessorsEnabled as ti, addIsDeleteLocalDrivesEnabledEventHandler as tn, setIsDocumentModelSelectionSettingsEnabled as tr, useDragNode as tt, addVetraPackageManagerEventHandler as u, screamingSnakeToCamel as ua, useRenownChainId as ui, addIsExternalRelationalProcessorsEnabledEventHandler as un, setIsRelationalProcessorsEnabled as ur, useSelectedDriveSafe as ut, setSelectedTimelineRevision as v, moveNode$1 as va, useStudioMode as vi, addRenownChainIdEventHandler as vn, setRequiresHardRefresh as vr, createUrlWithPreservedParams as vt, useDocumentTypesInSelectedDrive as w, addModalEventHandler as wa, addIsDragAndDropEnabledEventHandler as wi, addSentryEnvEventHandler as wn, setSwitchboardUrl as wr, extractNodeSlugFromPath as wt, setSelectedTimelineItem as x, upgradeDocument as xa, useVersionCheckInterval as xi, addRequiresHardRefreshEventHandler as xn, setSentryEnv as xr, extractDriveSlugFromPath as xt, useSelectedTimelineRevision as y, renameDriveNode as ya, useSwitchboardUrl as yi, addRenownNetworkIdEventHandler as yn, setRouterBasename as yr, extractDriveIdFromPath as yt, setReactorClient as z, viewFilterInputFromViewFilter as zi, setDrivesPreserveStrategy as zn, useIsAddDriveEnabled as zr, addCliVersionEventHandler as zt };
|
|
2927
2935
|
|
|
2928
|
-
//# sourceMappingURL=document-operations-
|
|
2936
|
+
//# sourceMappingURL=document-operations-B2lxu6qg.js.map
|