@powerhousedao/reactor-browser 6.2.3-dev.76 → 6.2.3-dev.78
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-BsOmg2-v.d.ts → attachment-service-C_8_poEv.d.ts} +223 -12
- package/dist/attachment-service-C_8_poEv.d.ts.map +1 -0
- package/dist/{client-BnGewICj.d.ts → client-Cx43uuSO.d.ts} +2 -2
- package/dist/client-Cx43uuSO.d.ts.map +1 -0
- package/dist/{client-CXDpILj6.js → client-D_cBN8L-.js} +91 -3
- package/dist/client-D_cBN8L-.js.map +1 -0
- package/dist/{dispatch-BEI1Ai2b.js → dispatch-DLD1E-9L.js} +80 -8
- package/dist/dispatch-DLD1E-9L.js.map +1 -0
- package/dist/{document-by-id-bHT2FDHM.js → document-by-id-BGTnMWiG.js} +2 -2
- package/dist/{document-by-id-bHT2FDHM.js.map → document-by-id-BGTnMWiG.js.map} +1 -1
- package/dist/{document-model-modules-DAx3VAm3.js → document-model-modules-D_kT09sv.js} +254 -9
- package/dist/document-model-modules-D_kT09sv.js.map +1 -0
- package/dist/{document-operations-zQKFs_xu.js → document-operations-BdCl99y6.js} +777 -52
- package/dist/document-operations-BdCl99y6.js.map +1 -0
- package/dist/{global-DY0jZmcO.d.ts → global-C4kaLEPb.d.ts} +165 -53
- package/dist/global-C4kaLEPb.d.ts.map +1 -0
- package/dist/{index-DlZsXHpT.d.ts → index-CROGY3XV.d.ts} +2 -2
- package/dist/{index-DlZsXHpT.d.ts.map → index-CROGY3XV.d.ts.map} +1 -1
- package/dist/index.d.ts +55 -41
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +215 -53
- package/dist/index.js.map +1 -1
- package/dist/src/ai/index.js +2 -2
- package/dist/src/analytics/index.js +1 -1
- package/dist/src/graphql/client.d.ts +2 -2
- package/dist/src/graphql/client.js +1 -1
- package/dist/src/graphql-client/entry.d.ts +4 -4
- package/dist/src/graphql-client/entry.js +4 -4
- package/dist/src/renown/index.d.ts +1 -1
- package/dist/{switchboard-G3aKXjNx.js → switchboard-CqUq5pIZ.js} +10 -48
- package/dist/switchboard-CqUq5pIZ.js.map +1 -0
- package/dist/{types-0Fh1tNjy.d.ts → types-Vb8q55oM.d.ts} +69 -2
- package/dist/types-Vb8q55oM.d.ts.map +1 -0
- package/package.json +9 -9
- package/dist/attachment-service-BsOmg2-v.d.ts.map +0 -1
- package/dist/client-BnGewICj.d.ts.map +0 -1
- package/dist/client-CXDpILj6.js.map +0 -1
- package/dist/dispatch-BEI1Ai2b.js.map +0 -1
- package/dist/document-model-modules-DAx3VAm3.js.map +0 -1
- package/dist/document-operations-zQKFs_xu.js.map +0 -1
- package/dist/global-DY0jZmcO.d.ts.map +0 -1
- package/dist/switchboard-G3aKXjNx.js.map +0 -1
- package/dist/types-0Fh1tNjy.d.ts.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { c as getPHStore, f as usePHStore, t as makePHEventFunctions } from "./make-ph-event-functions-B5GU5xcR.js";
|
|
2
|
-
import { D as
|
|
3
|
-
import { A as addDrivesEventHandler, L as ambientRenownTokenProvider, R as
|
|
2
|
+
import { D as queueOperations, E as queueActions, N as UnsupportedDocumentTypeError, O as uploadOperations, b as DOCUMENT_CHANGE_TYPE, f as DocumentCache, h as IDLE_OPERATIONS_ENTRY, i as setDocumentCache, k as DocumentModelNotFoundError, o as useDocumentCache, r as addDocumentCacheEventHandler, v as isOperationCache } from "./dispatch-DLD1E-9L.js";
|
|
3
|
+
import { $ as makeAuthMiddleware, A as addDrivesEventHandler, B as invalidateDriveNodes, H as markLocalDriveWrite, L as addDriveNodesEventHandler, Q as ambientRenownTokenProvider, R as dropDriveNode, X as listAllDriveNodes, a as setVetraPackageManager, c as addSelectedDriveIdEventHandler, f as setSelectedDriveId, h as useSelectedDriveId, r as addVetraPackageManagerEventHandler, u as selectDrive, v as addResetSelectedNodeEventHandler, w as setSelectedNodeId, y as addSelectedNodeIdEventHandler, z as getDriveNode } from "./document-model-modules-D_kT09sv.js";
|
|
4
4
|
import { A as extractNodeIdFromSlug, N as findDriveBySlug, O as extractDriveSlugFromPath, S as setBrowserOpenSync, c as getCurrentPathname, d as hasHostNavigation, h as openTargetWith, j as extractNodeSlugFromPath, l as getPHNavigation, m as openTarget, v as recordToSearch, w as targetPathname, x as searchToRecord } from "./navigation-BqphkrOB.js";
|
|
5
|
-
import {
|
|
5
|
+
import { a as PhDocumentFieldsFragmentDoc, i as JobChangesDocument, n as DocumentChangesDocument, t as createClient$1 } from "./client-D_cBN8L-.js";
|
|
6
6
|
import { f as addLoadingEventHandler, t as addRenownEventHandler } from "./renown-BxkZYzbQ.js";
|
|
7
7
|
import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
8
8
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
@@ -10,9 +10,9 @@ import { logger } from "document-model";
|
|
|
10
10
|
import { UnsupportedDocumentModelVersionError, actionSignerIdentity, actionSigningTarget, actions, assertAuthPreservedOnDuplicate, baseLoadFromInput, baseLoadFromInputVersioned, baseSaveToFileHandle, createCopyHeader, createPresignedHeader, createZip, deserializeSignature, documentModelDocumentType, generateId, hasDerivedDocumentId, hashDocumentStateForScope, isSignaturePolicy, normalizeDocumentModelVersion, replayDocumentVersioned, setName, setPreferredEditor, signaturePolicyOf, toTransportAction, withSignaturePolicy } from "@powerhousedao/shared/document-model";
|
|
11
11
|
import { addFolder, copyNode, generateNodesCopy, handleTargetNameCollisions, isFileNode, isFolderNode, moveNode, updateNode } from "@powerhousedao/shared/document-drive";
|
|
12
12
|
import { allPass, conditional, constant, forEachObj, funnel, isDefined, isNot, isStrictEqual, isString, isTruthy, once } from "remeda";
|
|
13
|
-
import { GraphQLClient } from "graphql-request";
|
|
14
13
|
import { gql } from "graphql-tag";
|
|
15
14
|
import { Kind, print } from "graphql";
|
|
15
|
+
import { GraphQLClient } from "graphql-request";
|
|
16
16
|
import { createClient } from "graphql-ws/client";
|
|
17
17
|
//#region src/hooks/url-state.ts
|
|
18
18
|
/** The nearest store's navigation, else the bound store's, else the browser's.
|
|
@@ -197,6 +197,7 @@ function showDeleteNodeModal(nodeOrId) {
|
|
|
197
197
|
//#region src/hooks/reactor.ts
|
|
198
198
|
const reactorClientModuleEventFunctions = makePHEventFunctions("reactorClientModule");
|
|
199
199
|
const reactorClientEventFunctions = makePHEventFunctions("reactorClient");
|
|
200
|
+
const reactorHalvesEventFunctions = makePHEventFunctions("reactor");
|
|
200
201
|
const fullReactorClientEventFunctions = makePHEventFunctions("fullReactorClient");
|
|
201
202
|
/** Returns the reactor client module (in-process or worker-backed) */
|
|
202
203
|
const useReactorClientModule = reactorClientModuleEventFunctions.useValue;
|
|
@@ -206,8 +207,26 @@ const setReactorClientModule = reactorClientModuleEventFunctions.setValue;
|
|
|
206
207
|
const addReactorClientModuleEventHandler = reactorClientModuleEventFunctions.addEventHandler;
|
|
207
208
|
/** Returns the reactor client */
|
|
208
209
|
const useReactorClient = reactorClientEventFunctions.useValue;
|
|
209
|
-
/**
|
|
210
|
-
|
|
210
|
+
/**
|
|
211
|
+
* Sets the reactor client, and `window.ph.reactor` to its read and write
|
|
212
|
+
* halves. A client without halves leaves `reactor` unset.
|
|
213
|
+
*/
|
|
214
|
+
const setReactorClient = (client) => {
|
|
215
|
+
reactorClientEventFunctions.setValue(client);
|
|
216
|
+
reactorHalvesEventFunctions.setValue(halvesOf(client));
|
|
217
|
+
};
|
|
218
|
+
/** Returns the reactor client's read and write halves */
|
|
219
|
+
const useReactorHalves = reactorHalvesEventFunctions.useValue;
|
|
220
|
+
/** Adds an event handler for the reactor client's halves */
|
|
221
|
+
const addReactorHalvesEventHandler = reactorHalvesEventFunctions.addEventHandler;
|
|
222
|
+
function halvesOf(client) {
|
|
223
|
+
const read = client?.read;
|
|
224
|
+
const write = client?.write;
|
|
225
|
+
return read && write ? {
|
|
226
|
+
read,
|
|
227
|
+
write
|
|
228
|
+
} : void 0;
|
|
229
|
+
}
|
|
211
230
|
/** Adds an event handler for the reactor client */
|
|
212
231
|
const addReactorClientEventHandler = reactorClientEventFunctions.addEventHandler;
|
|
213
232
|
/** Sets the client full-client actions use instead of the module's */
|
|
@@ -264,16 +283,26 @@ function getUserPermissions() {
|
|
|
264
283
|
//#endregion
|
|
265
284
|
//#region src/actions/document.ts
|
|
266
285
|
const NON_DOMAIN_SCOPES = /* @__PURE__ */ new Set(["auth", "document"]);
|
|
286
|
+
/** Puts a node this tab just wrote into its drive's cache, so hooks show it
|
|
287
|
+
* before the drive change that follows the write is processed. Best effort:
|
|
288
|
+
* a client without a node reader is left to that change. */
|
|
289
|
+
async function rememberDriveNode(driveId, nodeId) {
|
|
290
|
+
try {
|
|
291
|
+
await getDriveNode(driveId, nodeId, { refresh: true });
|
|
292
|
+
} catch (error) {
|
|
293
|
+
logger.verbose("Caching the written node @id failed: @error", nodeId, error);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
267
296
|
/** An unreadable drive cannot be shown to hold no duplicate, so reads throw. */
|
|
268
297
|
async function isDocumentInLocation(reactorClient, document, driveId, parentFolder) {
|
|
269
|
-
const
|
|
270
|
-
const nodeById =
|
|
271
|
-
if (nodeById
|
|
298
|
+
const siblings = await listAllDriveNodes(reactorClient.drives, driveId, { parentFolder: parentFolder ?? null });
|
|
299
|
+
const nodeById = siblings.find((node) => node.id === document.header.id);
|
|
300
|
+
if (nodeById) return {
|
|
272
301
|
isDuplicate: true,
|
|
273
302
|
duplicateType: "id",
|
|
274
303
|
nodeId: nodeById.id
|
|
275
304
|
};
|
|
276
|
-
const nodeByNameAndType =
|
|
305
|
+
const nodeByNameAndType = siblings.find((node) => isFileNode(node) && node.name === document.header.name && node.documentType === document.header.documentType);
|
|
277
306
|
if (nodeByNameAndType) return {
|
|
278
307
|
isDuplicate: true,
|
|
279
308
|
duplicateType: "name",
|
|
@@ -320,7 +349,7 @@ async function getDocumentExtension(document) {
|
|
|
320
349
|
else {
|
|
321
350
|
const reactorClient = getFullReactorClient();
|
|
322
351
|
if (reactorClient) {
|
|
323
|
-
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
352
|
+
const { results: documentModelModules } = await reactorClient.read.getDocumentModelModules();
|
|
324
353
|
rawExtension = documentModelModules.find((m) => m.documentModel.global.id === documentType)?.utils.fileExtension;
|
|
325
354
|
}
|
|
326
355
|
}
|
|
@@ -424,7 +453,7 @@ function boundary(upgrade, scope, ops) {
|
|
|
424
453
|
async function exportFile(document, suggestedName) {
|
|
425
454
|
const reactorClient = getPHStore()?.reactorClient;
|
|
426
455
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
427
|
-
const operations = await fetchDocumentOperations(reactorClient, document);
|
|
456
|
+
const operations = await fetchDocumentOperations(reactorClient.read, document);
|
|
428
457
|
const initialState = extractInitialState(operations["document"] ?? []);
|
|
429
458
|
const documentWithOps = {
|
|
430
459
|
...document,
|
|
@@ -453,7 +482,7 @@ async function loadFile(path) {
|
|
|
453
482
|
const reactorClient = getFullReactorClient();
|
|
454
483
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
455
484
|
const documentType = baseDocument.header.documentType;
|
|
456
|
-
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
485
|
+
const { results: documentModelModules } = await reactorClient.read.getDocumentModelModules();
|
|
457
486
|
const modulesForType = documentModelModules.filter((module) => module.documentModel.global.id === documentType);
|
|
458
487
|
if (modulesForType.length === 0) throw new DocumentModelNotFoundError(documentType);
|
|
459
488
|
const reducers = {};
|
|
@@ -475,25 +504,28 @@ async function addDocument(driveId, name, documentType, parentFolder, document,
|
|
|
475
504
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
476
505
|
let documentModelModule;
|
|
477
506
|
if (documentModelVersion !== void 0) {
|
|
478
|
-
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
507
|
+
const { results: documentModelModules } = await reactorClient.read.getDocumentModelModules();
|
|
479
508
|
const module = documentModelModules.find((m) => m.documentModel.global.id === documentType && (m.version ?? 1) === documentModelVersion);
|
|
480
509
|
if (!module) throw new Error(`Document model not found for type: ${documentType} with version: ${documentModelVersion}`);
|
|
481
510
|
documentModelModule = module;
|
|
482
|
-
} else documentModelModule = await reactorClient.getDocumentModelModule(documentType);
|
|
483
|
-
const newDocument = document ?? withSignaturePolicy(documentModelModule.utils.createDocument(), await reactorClient.getCreateSignaturePolicy());
|
|
511
|
+
} else documentModelModule = await reactorClient.read.getDocumentModelModule(documentType);
|
|
512
|
+
const newDocument = document ?? withSignaturePolicy(documentModelModule.utils.createDocument(), await reactorClient.read.getCreateSignaturePolicy());
|
|
484
513
|
if (!document) newDocument.state.document.version = documentModelModule.version ?? 1;
|
|
485
514
|
newDocument.header.name = name;
|
|
486
515
|
if (preferredEditor) newDocument.header.meta = {
|
|
487
516
|
...newDocument.header.meta,
|
|
488
517
|
preferredEditor
|
|
489
518
|
};
|
|
519
|
+
markLocalDriveWrite(driveId);
|
|
490
520
|
let newDoc;
|
|
491
521
|
try {
|
|
492
|
-
newDoc = await reactorClient.drives.addFile(driveId, newDocument, parentFolder);
|
|
522
|
+
newDoc = await (await reactorClient.write.drives.addFile(driveId, newDocument, parentFolder)).document();
|
|
493
523
|
} catch (e) {
|
|
494
524
|
logger.error("Error adding document: @error", e);
|
|
495
525
|
throw new Error("There was an error adding document", { cause: e });
|
|
496
526
|
}
|
|
527
|
+
await rememberDriveNode(driveId, newDoc.header.id);
|
|
528
|
+
await getDriveNode(driveId, newDoc.header.id, { refresh: true }).catch(() => void 0);
|
|
497
529
|
return {
|
|
498
530
|
id: newDoc.header.id,
|
|
499
531
|
name: newDoc.header.name,
|
|
@@ -527,9 +559,9 @@ function isDocumentAlreadyExists(error) {
|
|
|
527
559
|
* under the same id and is resolved by minting another one. A create that
|
|
528
560
|
* fails leaves the drive untouched, so a retry has nothing to clean up.
|
|
529
561
|
*/
|
|
530
|
-
async function createImportedDocument(
|
|
562
|
+
async function createImportedDocument(write, document, driveId, name, parentFolder) {
|
|
531
563
|
const v2Required = signaturePolicyOf(document.header) === "v2-required";
|
|
532
|
-
const keepsId = (!v2Required || hasDerivedDocumentId(document.header)) && !await
|
|
564
|
+
const keepsId = (!v2Required || hasDerivedDocumentId(document.header)) && !await write.isDocumentIdTaken(document.header.id);
|
|
533
565
|
let documentId = keepsId ? document.header.id : generateId();
|
|
534
566
|
for (let attempt = 1;; attempt++) {
|
|
535
567
|
let header;
|
|
@@ -622,7 +654,7 @@ async function addFileWithProgress(file, driveId, name, parentFolder, onProgress
|
|
|
622
654
|
}
|
|
623
655
|
throw loadError;
|
|
624
656
|
}
|
|
625
|
-
const duplicateCheck = await isDocumentInLocation(reactor, document, driveId, parentFolder);
|
|
657
|
+
const duplicateCheck = await isDocumentInLocation(reactor.read, document, driveId, parentFolder);
|
|
626
658
|
if (duplicateCheck.isDuplicate && !resolveConflict) {
|
|
627
659
|
onProgress?.({
|
|
628
660
|
stage: "conflict",
|
|
@@ -649,19 +681,21 @@ async function addFileWithProgress(file, driveId, name, parentFolder, onProgress
|
|
|
649
681
|
});
|
|
650
682
|
throw new UnsupportedDocumentTypeError(document.header.documentType);
|
|
651
683
|
}
|
|
652
|
-
await reactor.getDocumentModelModule(document.header.documentType);
|
|
684
|
+
await reactor.read.getDocumentModelModule(document.header.documentType);
|
|
653
685
|
onProgress?.({
|
|
654
686
|
stage: "initializing",
|
|
655
687
|
progress: 10
|
|
656
688
|
});
|
|
657
|
-
|
|
689
|
+
markLocalDriveWrite(driveId);
|
|
690
|
+
const created = await createImportedDocument(reactor.write, document, driveId, name, parentFolder);
|
|
658
691
|
const documentId = created.documentId;
|
|
659
692
|
const fileNode = created.fileNode;
|
|
693
|
+
await rememberDriveNode(driveId, documentId);
|
|
660
694
|
onProgress?.({
|
|
661
695
|
stage: "initializing",
|
|
662
696
|
progress: 20
|
|
663
697
|
});
|
|
664
|
-
await reactor.get(documentId);
|
|
698
|
+
await reactor.read.get(documentId);
|
|
665
699
|
console.log("Document created, starting upload of operations");
|
|
666
700
|
const segments = splitAtUpgradeBoundaries(document.operations);
|
|
667
701
|
const totalOperations = segments.reduce((total, segment) => total + countOperations(segment.operations), 0);
|
|
@@ -718,13 +752,15 @@ async function addFolder$1(driveId, name, parentFolder) {
|
|
|
718
752
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create folders");
|
|
719
753
|
const reactorClient = getPHStore()?.reactorClient;
|
|
720
754
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
721
|
-
await reactorClient.get(driveId);
|
|
755
|
+
await reactorClient.read.get(driveId);
|
|
722
756
|
const folderId = generateId();
|
|
723
|
-
|
|
757
|
+
markLocalDriveWrite(driveId);
|
|
758
|
+
await (await reactorClient.write.execute(driveId, "main", [addFolder({
|
|
724
759
|
id: folderId,
|
|
725
760
|
name,
|
|
726
761
|
parentFolder
|
|
727
|
-
})])).
|
|
762
|
+
})])).readable;
|
|
763
|
+
const node = await getDriveNode(driveId, folderId, { refresh: true });
|
|
728
764
|
if (!node || !isFolderNode(node)) throw new Error("There was an error adding folder");
|
|
729
765
|
return node;
|
|
730
766
|
}
|
|
@@ -733,18 +769,22 @@ async function deleteNode(driveId, nodeId) {
|
|
|
733
769
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to delete documents");
|
|
734
770
|
const reactorClient = getFullReactorClient();
|
|
735
771
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
736
|
-
|
|
772
|
+
markLocalDriveWrite(driveId);
|
|
773
|
+
await (await reactorClient.write.drives.removeNode(driveId, nodeId)).readable;
|
|
774
|
+
dropDriveNode(driveId, nodeId);
|
|
737
775
|
}
|
|
738
776
|
async function renameNode(driveId, nodeId, name) {
|
|
739
777
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
740
778
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to rename documents");
|
|
741
779
|
const reactorClient = getPHStore()?.reactorClient;
|
|
742
780
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
743
|
-
if ((await reactorClient.execute(nodeId, "main", [setName({ name })])).header.name !== name) throw new Error("There was an error renaming the node");
|
|
744
|
-
|
|
781
|
+
if ((await (await reactorClient.write.execute(nodeId, "main", [setName({ name })])).document()).header.name !== name) throw new Error("There was an error renaming the node");
|
|
782
|
+
markLocalDriveWrite(driveId);
|
|
783
|
+
await (await reactorClient.write.execute(driveId, "main", [updateNode({
|
|
745
784
|
id: nodeId,
|
|
746
785
|
name
|
|
747
|
-
})])).
|
|
786
|
+
})])).readable;
|
|
787
|
+
const node = await getDriveNode(driveId, nodeId, { refresh: true });
|
|
748
788
|
if (!node) throw new Error("There was an error renaming node in the drive");
|
|
749
789
|
return node;
|
|
750
790
|
}
|
|
@@ -753,19 +793,20 @@ async function renameDriveNode(driveId, nodeId, name) {
|
|
|
753
793
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to rename documents");
|
|
754
794
|
const reactorClient = getPHStore()?.reactorClient;
|
|
755
795
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
756
|
-
if ((await reactorClient.execute(nodeId, "main", [setName({ name })])).header.name !== name) throw new Error("There was an error renaming the node");
|
|
757
|
-
|
|
796
|
+
if ((await (await reactorClient.write.execute(nodeId, "main", [setName({ name })])).document()).header.name !== name) throw new Error("There was an error renaming the node");
|
|
797
|
+
markLocalDriveWrite(driveId);
|
|
798
|
+
await (await reactorClient.write.execute(driveId, "main", [updateNode({
|
|
758
799
|
id: nodeId,
|
|
759
800
|
name
|
|
760
|
-
})]);
|
|
761
|
-
return (
|
|
801
|
+
})])).readable;
|
|
802
|
+
return getDriveNode(driveId, nodeId, { refresh: true });
|
|
762
803
|
}
|
|
763
804
|
async function setPreferredEditorOnNode(nodeId, preferredEditor) {
|
|
764
805
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
765
806
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to modify documents");
|
|
766
807
|
const reactorClient = getPHStore()?.reactorClient;
|
|
767
808
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
768
|
-
return reactorClient.execute(nodeId, "main", [setPreferredEditor(preferredEditor)]);
|
|
809
|
+
return (await reactorClient.write.execute(nodeId, "main", [setPreferredEditor(preferredEditor)])).document();
|
|
769
810
|
}
|
|
770
811
|
async function moveNodeById(args) {
|
|
771
812
|
const { driveId, srcId, targetId } = args;
|
|
@@ -776,20 +817,26 @@ async function moveNodeById(args) {
|
|
|
776
817
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
777
818
|
const targetParentFolder = conditional(targetId, [isNot(isDefined), constant(void 0)], [isStrictEqual(driveId), constant(void 0)], constant(targetId));
|
|
778
819
|
if (isStrictEqual(targetParentFolder, srcId)) return;
|
|
779
|
-
|
|
820
|
+
markLocalDriveWrite(driveId);
|
|
821
|
+
const moved = await (await reactorClient.write.execute(driveId, "main", [moveNode({
|
|
780
822
|
srcFolder: srcId,
|
|
781
823
|
targetParentFolder
|
|
782
|
-
})]);
|
|
824
|
+
})])).document();
|
|
825
|
+
await rememberDriveNode(driveId, srcId);
|
|
826
|
+
return moved;
|
|
783
827
|
}
|
|
784
828
|
async function moveNode$1(driveId, src, target) {
|
|
785
829
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
786
830
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to move documents");
|
|
787
831
|
const reactorClient = getPHStore()?.reactorClient;
|
|
788
832
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
789
|
-
|
|
833
|
+
markLocalDriveWrite(driveId);
|
|
834
|
+
const moved = await (await reactorClient.write.execute(driveId, "main", [moveNode({
|
|
790
835
|
srcFolder: src.id,
|
|
791
836
|
targetParentFolder: target?.id
|
|
792
|
-
})]);
|
|
837
|
+
})])).document();
|
|
838
|
+
await rememberDriveNode(driveId, src.id);
|
|
839
|
+
return moved;
|
|
793
840
|
}
|
|
794
841
|
/**
|
|
795
842
|
* Duplicates a document under a new id using version-aware replay.
|
|
@@ -828,18 +875,19 @@ async function copyNode$1(driveId, src, target) {
|
|
|
828
875
|
if (!reactor) return;
|
|
829
876
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
830
877
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to copy documents");
|
|
831
|
-
const drive = await reactor.get(driveId);
|
|
878
|
+
const drive = await reactor.read.get(driveId);
|
|
879
|
+
const driveNodes = await listAllDriveNodes(reactor.read.drives, driveId);
|
|
832
880
|
const copyNodesInput = generateNodesCopy({
|
|
833
881
|
srcId: src.id,
|
|
834
882
|
targetParentFolder: target?.id,
|
|
835
883
|
targetName: src.name
|
|
836
|
-
}, () => generateId(),
|
|
884
|
+
}, () => generateId(), driveNodes);
|
|
837
885
|
const resolvedNamesMap = /* @__PURE__ */ new Map();
|
|
838
886
|
for (const copyNodeInput of copyNodesInput) {
|
|
839
|
-
const node =
|
|
887
|
+
const node = driveNodes.find((n) => n.id === copyNodeInput.srcId);
|
|
840
888
|
if (node) {
|
|
841
889
|
const resolvedName = handleTargetNameCollisions({
|
|
842
|
-
nodes:
|
|
890
|
+
nodes: driveNodes,
|
|
843
891
|
srcName: copyNodeInput.targetName || node.name,
|
|
844
892
|
srcKind: isFileNode(node) ? "file" : "folder",
|
|
845
893
|
targetParentFolder: copyNodeInput.targetParentFolder || null
|
|
@@ -848,20 +896,25 @@ async function copyNode$1(driveId, src, target) {
|
|
|
848
896
|
}
|
|
849
897
|
}
|
|
850
898
|
const fileNodesToCopy = copyNodesInput.filter((copyNodeInput) => {
|
|
851
|
-
const node =
|
|
899
|
+
const node = driveNodes.find((node) => node.id === copyNodeInput.srcId);
|
|
852
900
|
return node !== void 0 && isFileNode(node);
|
|
853
901
|
});
|
|
902
|
+
markLocalDriveWrite(driveId);
|
|
854
903
|
for (const fileNodeToCopy of fileNodesToCopy) try {
|
|
855
|
-
const
|
|
904
|
+
const document = await reactor.read.get(fileNodeToCopy.srcId);
|
|
905
|
+
const duplicatedDocument = await _duplicateDocument(reactor.read, document, fileNodeToCopy.targetId, driveId);
|
|
856
906
|
const resolvedName = resolvedNamesMap.get(fileNodeToCopy.targetId);
|
|
857
907
|
if (resolvedName) duplicatedDocument.header.name = resolvedName;
|
|
858
908
|
fileNodeToCopy.targetId = duplicatedDocument.header.id;
|
|
859
|
-
await reactor.drives.addFile(driveId, duplicatedDocument, target?.id);
|
|
909
|
+
await (await reactor.write.drives.addFile(driveId, duplicatedDocument, target?.id)).readable;
|
|
860
910
|
} catch (e) {
|
|
861
911
|
logger.error(`Error copying document ${fileNodeToCopy.srcId}: ${String(e)}`);
|
|
862
912
|
}
|
|
863
913
|
const copyActions = copyNodesInput.map((copyNodeInput) => copyNode(copyNodeInput));
|
|
864
|
-
|
|
914
|
+
markLocalDriveWrite(driveId);
|
|
915
|
+
const copied = await queueActions(drive, copyActions);
|
|
916
|
+
invalidateDriveNodes(driveId);
|
|
917
|
+
return copied;
|
|
865
918
|
}
|
|
866
919
|
/**
|
|
867
920
|
* Upgrades a document to a newer document model version. Defaults to the
|
|
@@ -870,7 +923,7 @@ async function copyNode$1(driveId, src, target) {
|
|
|
870
923
|
async function upgradeDocument(documentId, toVersion) {
|
|
871
924
|
const reactorClient = getFullReactorClient();
|
|
872
925
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
873
|
-
return reactorClient.upgradeDocument(documentId, toVersion);
|
|
926
|
+
return (await reactorClient.write.upgradeDocument(documentId, toVersion)).document();
|
|
874
927
|
}
|
|
875
928
|
//#endregion
|
|
876
929
|
//#region src/constants.ts
|
|
@@ -1046,6 +1099,138 @@ function isoStringFromDateTime(value) {
|
|
|
1046
1099
|
return value instanceof Date ? value.toISOString() : value;
|
|
1047
1100
|
}
|
|
1048
1101
|
//#endregion
|
|
1102
|
+
//#region src/graphql-client/drive-nodes.ts
|
|
1103
|
+
/** Page size {@link GraphQLDriveNodeSource.listAll} reads a drive in. */
|
|
1104
|
+
const LIST_ALL_PAGE_LIMIT = 1e3;
|
|
1105
|
+
const DEFAULT_LIMIT$1 = 100;
|
|
1106
|
+
/**
|
|
1107
|
+
* The reactor subgraph's type-neutral node queries (`driveNodes`, `driveNode`,
|
|
1108
|
+
* `driveDescendants`) as an {@link IDriveNodeSource}, so a browser reads a
|
|
1109
|
+
* legacy drive and a reactor-drive alike. The Switchboard serves only the
|
|
1110
|
+
* nodes the caller may read. Drive ids must be canonical ids, not slugs.
|
|
1111
|
+
*/
|
|
1112
|
+
var GraphQLDriveNodeSource = class {
|
|
1113
|
+
queries;
|
|
1114
|
+
headersFor;
|
|
1115
|
+
constructor(queries, headersFor = () => void 0) {
|
|
1116
|
+
this.queries = queries;
|
|
1117
|
+
this.headersFor = headersFor;
|
|
1118
|
+
}
|
|
1119
|
+
async getNode(driveId, nodeId, signal) {
|
|
1120
|
+
const result = await this.queries.GetDriveNode({
|
|
1121
|
+
driveId,
|
|
1122
|
+
id: nodeId
|
|
1123
|
+
}, this.headersFor(driveId), signal);
|
|
1124
|
+
return result.driveNode ? toRecord(result.driveNode) : void 0;
|
|
1125
|
+
}
|
|
1126
|
+
async listChildren(driveId, parentFolder, paging, signal, kind) {
|
|
1127
|
+
const cursor = startCursor(paging?.cursor);
|
|
1128
|
+
const page = (await this.queries.GetDriveNodes({
|
|
1129
|
+
driveId,
|
|
1130
|
+
...parentFolder === void 0 ? {} : { parentFolder },
|
|
1131
|
+
paging: paging ? {
|
|
1132
|
+
cursor,
|
|
1133
|
+
limit: paging.limit
|
|
1134
|
+
} : void 0,
|
|
1135
|
+
kind: kind === void 0 ? void 0 : kind === "file" ? "FILE" : "FOLDER"
|
|
1136
|
+
}, this.headersFor(driveId), signal)).driveNodes;
|
|
1137
|
+
const nextCursor = page.hasMore ? page.nextCursor ?? void 0 : void 0;
|
|
1138
|
+
return {
|
|
1139
|
+
results: page.results.map(toRecord),
|
|
1140
|
+
options: {
|
|
1141
|
+
cursor,
|
|
1142
|
+
limit: paging?.limit ?? DEFAULT_LIMIT$1
|
|
1143
|
+
},
|
|
1144
|
+
...nextCursor !== void 0 ? { nextCursor } : {}
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
async getDescendants(driveId, root, signal) {
|
|
1148
|
+
return (await this.queries.GetDriveDescendants({
|
|
1149
|
+
driveId,
|
|
1150
|
+
root
|
|
1151
|
+
}, this.headersFor(driveId), signal)).driveDescendants.map(toRecord);
|
|
1152
|
+
}
|
|
1153
|
+
async listAll(driveId, signal) {
|
|
1154
|
+
const nodes = [];
|
|
1155
|
+
let cursor = "";
|
|
1156
|
+
for (;;) {
|
|
1157
|
+
const page = await this.listChildren(driveId, void 0, {
|
|
1158
|
+
cursor,
|
|
1159
|
+
limit: LIST_ALL_PAGE_LIMIT
|
|
1160
|
+
}, signal);
|
|
1161
|
+
nodes.push(...page.results);
|
|
1162
|
+
if (page.nextCursor === void 0 || page.nextCursor === cursor) return nodes;
|
|
1163
|
+
cursor = page.nextCursor;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
/**
|
|
1168
|
+
* `read.drives` over a node source: the reactor's {@link IDriveReadClient},
|
|
1169
|
+
* answering in the legacy `Node` shape for every drive type.
|
|
1170
|
+
*/
|
|
1171
|
+
var GraphQLDriveReadClient = class {
|
|
1172
|
+
nodes;
|
|
1173
|
+
constructor(nodes) {
|
|
1174
|
+
this.nodes = nodes;
|
|
1175
|
+
}
|
|
1176
|
+
async getNode(driveIdentifier, nodeId, signal) {
|
|
1177
|
+
const record = await this.nodes.getNode(driveIdentifier, nodeId, signal);
|
|
1178
|
+
if (!record) throw new Error(`Node ${nodeId} not found in drive ${driveIdentifier}`);
|
|
1179
|
+
return toLegacyNode(record);
|
|
1180
|
+
}
|
|
1181
|
+
async listNodes(driveIdentifier, parentFolder, paging, signal) {
|
|
1182
|
+
const page = await this.nodes.listChildren(driveIdentifier, parentFolder, paging, signal);
|
|
1183
|
+
const nextCursor = page.nextCursor;
|
|
1184
|
+
return {
|
|
1185
|
+
results: page.results.map(toLegacyNode),
|
|
1186
|
+
options: page.options,
|
|
1187
|
+
...nextCursor !== void 0 ? {
|
|
1188
|
+
nextCursor,
|
|
1189
|
+
next: () => this.listNodes(driveIdentifier, parentFolder, {
|
|
1190
|
+
cursor: nextCursor,
|
|
1191
|
+
limit: page.options.limit
|
|
1192
|
+
}, signal)
|
|
1193
|
+
} : {}
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
1197
|
+
/** A node record in the legacy `Node` shape. */
|
|
1198
|
+
function toLegacyNode(node) {
|
|
1199
|
+
if (node.kind === "file") return {
|
|
1200
|
+
id: node.id,
|
|
1201
|
+
kind: "file",
|
|
1202
|
+
name: node.name,
|
|
1203
|
+
parentFolder: node.parentFolder,
|
|
1204
|
+
documentType: node.documentType ?? ""
|
|
1205
|
+
};
|
|
1206
|
+
return {
|
|
1207
|
+
id: node.id,
|
|
1208
|
+
kind: "folder",
|
|
1209
|
+
name: node.name,
|
|
1210
|
+
parentFolder: node.parentFolder
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
function toRecord(node) {
|
|
1214
|
+
const base = {
|
|
1215
|
+
id: node.id,
|
|
1216
|
+
driveId: node.driveId,
|
|
1217
|
+
name: node.name,
|
|
1218
|
+
parentFolder: node.parentFolder ?? null
|
|
1219
|
+
};
|
|
1220
|
+
return "documentType" in node ? {
|
|
1221
|
+
...base,
|
|
1222
|
+
kind: "file",
|
|
1223
|
+
documentType: node.documentType
|
|
1224
|
+
} : {
|
|
1225
|
+
...base,
|
|
1226
|
+
kind: "folder"
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
/** The offset-style "0" other listings start from means the first page here too. */
|
|
1230
|
+
function startCursor(cursor) {
|
|
1231
|
+
return cursor === void 0 || cursor === "0" ? "" : cursor;
|
|
1232
|
+
}
|
|
1233
|
+
//#endregion
|
|
1049
1234
|
//#region src/graphql-client/errors.ts
|
|
1050
1235
|
/** A call the Switchboard GraphQL surface cannot express. */
|
|
1051
1236
|
var GraphQLOperationNotSupportedError = class extends Error {
|
|
@@ -1100,6 +1285,23 @@ var BatchJobFailedError = class extends Error {
|
|
|
1100
1285
|
return Error.isError(error) && error.name === "BatchJobFailedError" && typeof error.key === "string" && typeof error.jobs === "object";
|
|
1101
1286
|
}
|
|
1102
1287
|
};
|
|
1288
|
+
/**
|
|
1289
|
+
* The reactor's `JobFailedError`, rebuilt from a job the Switchboard reported
|
|
1290
|
+
* FAILED; this entry imports the reactor for types only. A write handle's
|
|
1291
|
+
* stage rejects with it. The message is the job error's message, as the
|
|
1292
|
+
* reactor's is.
|
|
1293
|
+
*/
|
|
1294
|
+
var JobFailedError = class extends Error {
|
|
1295
|
+
name = "JobFailedError";
|
|
1296
|
+
job;
|
|
1297
|
+
constructor(job) {
|
|
1298
|
+
super(job.error?.message);
|
|
1299
|
+
this.job = job;
|
|
1300
|
+
}
|
|
1301
|
+
static isError(error) {
|
|
1302
|
+
return Error.isError(error) && error.name === "JobFailedError" && typeof error.job === "object";
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1103
1305
|
//#endregion
|
|
1104
1306
|
//#region src/graphql-client/operations.ts
|
|
1105
1307
|
/**
|
|
@@ -1189,6 +1391,27 @@ const MutateDocumentWithOperationsDocument = gql`
|
|
|
1189
1391
|
${PhDocumentFieldsFragmentDoc}
|
|
1190
1392
|
${ReactorOperationFieldsFragmentDoc}
|
|
1191
1393
|
`;
|
|
1394
|
+
/**
|
|
1395
|
+
* `document`, bounded by a consistency token: the read waits until the
|
|
1396
|
+
* Switchboard's read models hold every operation the token names. The
|
|
1397
|
+
* `consistency` argument is additive on the Switchboard; one without it refuses
|
|
1398
|
+
* this document, and the client falls back to the plain `GetDocument`.
|
|
1399
|
+
*/
|
|
1400
|
+
const GetDocumentAtConsistencyDocument = gql`
|
|
1401
|
+
query GetDocumentAtConsistency(
|
|
1402
|
+
$identifier: String!
|
|
1403
|
+
$view: ViewFilterInput
|
|
1404
|
+
$consistency: ConsistencyTokenInput
|
|
1405
|
+
) {
|
|
1406
|
+
document(identifier: $identifier, view: $view, consistency: $consistency) {
|
|
1407
|
+
document {
|
|
1408
|
+
...PHDocumentFields
|
|
1409
|
+
}
|
|
1410
|
+
childIds
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
${PhDocumentFieldsFragmentDoc}
|
|
1414
|
+
`;
|
|
1192
1415
|
//#endregion
|
|
1193
1416
|
//#region src/graphql-client/signing.ts
|
|
1194
1417
|
/**
|
|
@@ -1620,6 +1843,45 @@ function startDocumentChangesSubscription(options) {
|
|
|
1620
1843
|
};
|
|
1621
1844
|
}
|
|
1622
1845
|
/**
|
|
1846
|
+
* Opens the socket write handles wait on. `graphql-ws` multiplexes every
|
|
1847
|
+
* watched job over it and closes it once the last watch stops.
|
|
1848
|
+
*/
|
|
1849
|
+
function createJobChangesSocket(options) {
|
|
1850
|
+
let client;
|
|
1851
|
+
const clientOf = () => client ??= createClient({
|
|
1852
|
+
url: options.wsUrl,
|
|
1853
|
+
connectionParams: options.connectionParams,
|
|
1854
|
+
shouldRetry: (errOrCloseEvent) => isLikeCloseEvent(errOrCloseEvent) && !isAuthRefusalClose(errOrCloseEvent)
|
|
1855
|
+
});
|
|
1856
|
+
return {
|
|
1857
|
+
watch(jobId, onEvent, onError) {
|
|
1858
|
+
const unsubscribe = clientOf().subscribe({
|
|
1859
|
+
operationName: "JobChanges",
|
|
1860
|
+
query: print(JobChangesDocument),
|
|
1861
|
+
variables: { jobId }
|
|
1862
|
+
}, {
|
|
1863
|
+
next: (result) => {
|
|
1864
|
+
const event = result.data?.jobChanges;
|
|
1865
|
+
if (event) onEvent(event);
|
|
1866
|
+
},
|
|
1867
|
+
error: (error) => onError(error),
|
|
1868
|
+
complete: () => void 0
|
|
1869
|
+
});
|
|
1870
|
+
let stopped = false;
|
|
1871
|
+
return () => {
|
|
1872
|
+
if (stopped) return;
|
|
1873
|
+
stopped = true;
|
|
1874
|
+
unsubscribe();
|
|
1875
|
+
};
|
|
1876
|
+
},
|
|
1877
|
+
dispose() {
|
|
1878
|
+
const current = client;
|
|
1879
|
+
client = void 0;
|
|
1880
|
+
current?.dispose();
|
|
1881
|
+
}
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
/**
|
|
1623
1885
|
* Derives the websocket endpoint from the GraphQL http endpoint.
|
|
1624
1886
|
*
|
|
1625
1887
|
* `http://host/graphql` becomes `ws://host/graphql/subscriptions`, which is
|
|
@@ -1645,6 +1907,141 @@ function makeAuthConnectionParams(tokenProvider) {
|
|
|
1645
1907
|
};
|
|
1646
1908
|
}
|
|
1647
1909
|
//#endregion
|
|
1910
|
+
//#region src/graphql-client/write-handles.ts
|
|
1911
|
+
/** Whether a job status has reached a stage, FAILED counting as settled. */
|
|
1912
|
+
function settlesGraphQLJobStage(status, stage) {
|
|
1913
|
+
const value = status;
|
|
1914
|
+
if (value === "FAILED" || value === "READ_READY") return true;
|
|
1915
|
+
return stage === "written" && value === "WRITE_READY";
|
|
1916
|
+
}
|
|
1917
|
+
function emptyToken() {
|
|
1918
|
+
return {
|
|
1919
|
+
version: 1,
|
|
1920
|
+
createdAtUtcIso: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1921
|
+
coordinates: []
|
|
1922
|
+
};
|
|
1923
|
+
}
|
|
1924
|
+
function abortError(signal) {
|
|
1925
|
+
const reason = signal.reason;
|
|
1926
|
+
return reason instanceof Error ? reason : new Error(String(reason));
|
|
1927
|
+
}
|
|
1928
|
+
/** `promise`, rejected early when `signal` aborts. */
|
|
1929
|
+
function bounded(promise, signal) {
|
|
1930
|
+
if (!signal) return promise;
|
|
1931
|
+
if (signal.aborted) return Promise.reject(abortError(signal));
|
|
1932
|
+
return new Promise((resolve, reject) => {
|
|
1933
|
+
const onAbort = () => reject(abortError(signal));
|
|
1934
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1935
|
+
promise.then((value) => {
|
|
1936
|
+
signal.removeEventListener("abort", onAbort);
|
|
1937
|
+
resolve(value);
|
|
1938
|
+
}, (error) => {
|
|
1939
|
+
signal.removeEventListener("abort", onAbort);
|
|
1940
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
1941
|
+
});
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
/**
|
|
1945
|
+
* A write handle over a job the Switchboard accepted (`executeAsync`).
|
|
1946
|
+
*
|
|
1947
|
+
* Each stage is the waiter's: `jobStatus`, woken early by the `jobChanges`
|
|
1948
|
+
* subscription when the client has realtime. Stage promises are created on
|
|
1949
|
+
* first access, so a fire-and-forget caller never owns a rejection. A FAILED
|
|
1950
|
+
* job rejects a stage with {@link JobFailedError}.
|
|
1951
|
+
*
|
|
1952
|
+
* `document()` with no view is read once and shared, so the client's own
|
|
1953
|
+
* change announcement and the caller's read-back cost one request.
|
|
1954
|
+
*/
|
|
1955
|
+
var GraphQLJobWriteHandle = class {
|
|
1956
|
+
jobId;
|
|
1957
|
+
documentId;
|
|
1958
|
+
branch;
|
|
1959
|
+
wait;
|
|
1960
|
+
reader;
|
|
1961
|
+
signal;
|
|
1962
|
+
writtenReceipt;
|
|
1963
|
+
readableReceipt;
|
|
1964
|
+
defaultDocument;
|
|
1965
|
+
constructor(job, documentId, branch, wait, reader, signal) {
|
|
1966
|
+
this.jobId = job.id;
|
|
1967
|
+
this.documentId = documentId;
|
|
1968
|
+
this.branch = branch;
|
|
1969
|
+
this.wait = wait;
|
|
1970
|
+
this.reader = reader;
|
|
1971
|
+
this.signal = signal;
|
|
1972
|
+
}
|
|
1973
|
+
get written() {
|
|
1974
|
+
this.writtenReceipt ??= this.receiptAt("written");
|
|
1975
|
+
return this.writtenReceipt;
|
|
1976
|
+
}
|
|
1977
|
+
get readable() {
|
|
1978
|
+
this.readableReceipt ??= this.receiptAt("readable");
|
|
1979
|
+
return this.readableReceipt;
|
|
1980
|
+
}
|
|
1981
|
+
async document(view, signal) {
|
|
1982
|
+
if (view !== void 0) {
|
|
1983
|
+
const receipt = await bounded(this.readable, signal);
|
|
1984
|
+
return this.reader(receipt, view, signal);
|
|
1985
|
+
}
|
|
1986
|
+
this.defaultDocument ??= this.readable.then((receipt) => this.reader(receipt, void 0, void 0));
|
|
1987
|
+
return bounded(this.defaultDocument, signal);
|
|
1988
|
+
}
|
|
1989
|
+
async receiptAt(stage) {
|
|
1990
|
+
const job = await this.wait(this.jobId, stage, this.signal);
|
|
1991
|
+
if (job.status === "FAILED") throw new JobFailedError(job);
|
|
1992
|
+
return {
|
|
1993
|
+
job,
|
|
1994
|
+
token: job.consistencyToken,
|
|
1995
|
+
documentId: this.documentId,
|
|
1996
|
+
branch: this.branch
|
|
1997
|
+
};
|
|
1998
|
+
}
|
|
1999
|
+
};
|
|
2000
|
+
/**
|
|
2001
|
+
* A write handle for a write the Switchboard applied before answering: the
|
|
2002
|
+
* synchronous `createDocument` and `deleteDocument` mutations name no job. Both
|
|
2003
|
+
* stages are settled; `jobId` is empty and the receipt's job is a READ_READY
|
|
2004
|
+
* placeholder with an empty token, as the reactor's own settled handle has.
|
|
2005
|
+
*/
|
|
2006
|
+
var GraphQLSettledWriteHandle = class {
|
|
2007
|
+
jobId = "";
|
|
2008
|
+
documentId;
|
|
2009
|
+
branch;
|
|
2010
|
+
receipt;
|
|
2011
|
+
reader;
|
|
2012
|
+
constructor(documentId, branch, reader) {
|
|
2013
|
+
this.documentId = documentId;
|
|
2014
|
+
this.branch = branch;
|
|
2015
|
+
this.reader = reader;
|
|
2016
|
+
const token = emptyToken();
|
|
2017
|
+
this.receipt = {
|
|
2018
|
+
job: {
|
|
2019
|
+
id: "",
|
|
2020
|
+
documentId,
|
|
2021
|
+
status: "READ_READY",
|
|
2022
|
+
createdAtUtcIso: token.createdAtUtcIso,
|
|
2023
|
+
consistencyToken: token,
|
|
2024
|
+
meta: {
|
|
2025
|
+
batchId: "",
|
|
2026
|
+
batchJobIds: []
|
|
2027
|
+
}
|
|
2028
|
+
},
|
|
2029
|
+
token,
|
|
2030
|
+
documentId,
|
|
2031
|
+
branch
|
|
2032
|
+
};
|
|
2033
|
+
}
|
|
2034
|
+
get written() {
|
|
2035
|
+
return Promise.resolve(this.receipt);
|
|
2036
|
+
}
|
|
2037
|
+
get readable() {
|
|
2038
|
+
return Promise.resolve(this.receipt);
|
|
2039
|
+
}
|
|
2040
|
+
document(view, signal) {
|
|
2041
|
+
return this.reader(this.receipt, view, signal);
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
//#endregion
|
|
1648
2045
|
//#region src/graphql-client/graphql-reactor-client.ts
|
|
1649
2046
|
/** Paging defaults, matching the reactor's own client. */
|
|
1650
2047
|
const defaultPaging = {
|
|
@@ -1652,6 +2049,14 @@ const defaultPaging = {
|
|
|
1652
2049
|
limit: 100
|
|
1653
2050
|
};
|
|
1654
2051
|
const JOB_POLL_INTERVAL_MS = 250;
|
|
2052
|
+
/** The first `jobStatus` poll of a write handle's stage wait, doubling from here. */
|
|
2053
|
+
const STAGE_POLL_START_MS = 25;
|
|
2054
|
+
/**
|
|
2055
|
+
* The longest a stage wait sleeps between `jobStatus` polls while the
|
|
2056
|
+
* `jobChanges` subscription is up: the subscription wakes it early, and the
|
|
2057
|
+
* poll is the safety net for an event that raced the subscription.
|
|
2058
|
+
*/
|
|
2059
|
+
const STAGE_POLL_REALTIME_MAX_MS = 1e3;
|
|
1655
2060
|
/**
|
|
1656
2061
|
* The marker {@link isGraphQLReactorClient} looks for.
|
|
1657
2062
|
*
|
|
@@ -1685,6 +2090,27 @@ var GraphQLReactorClient = class {
|
|
|
1685
2090
|
realtimeErrorLogged = false;
|
|
1686
2091
|
/** Whether the last socket died because the Switchboard refused its credentials. */
|
|
1687
2092
|
realtimeRefusedCredentials = false;
|
|
2093
|
+
/** The socket write handles wait on; opened by the first stage wait. */
|
|
2094
|
+
jobSocket;
|
|
2095
|
+
/** Set once the `jobChanges` subscription failed; stage waits then only poll. */
|
|
2096
|
+
jobRealtimeBroken = false;
|
|
2097
|
+
/** Set once the Switchboard refused the `document` query's `consistency` argument. */
|
|
2098
|
+
consistencyUnsupported = false;
|
|
2099
|
+
driveNodes;
|
|
2100
|
+
/**
|
|
2101
|
+
* The read half: the reads the hooks make. Every method is this client's
|
|
2102
|
+
* own; nothing that writes is reachable from it.
|
|
2103
|
+
*/
|
|
2104
|
+
read;
|
|
2105
|
+
/**
|
|
2106
|
+
* The write half. `execute` submits through `executeAsync` and hands back a
|
|
2107
|
+
* handle whose `written` and `readable` resolve from `jobStatus`, woken by
|
|
2108
|
+
* the `jobChanges` subscription when realtime is on, and whose `document()`
|
|
2109
|
+
* runs the `document` query bounded by the receipt's token. `create` and
|
|
2110
|
+
* `deleteDocument` have no asynchronous mutation: they run the synchronous
|
|
2111
|
+
* ones and hand back a settled handle.
|
|
2112
|
+
*/
|
|
2113
|
+
write;
|
|
1688
2114
|
constructor(options) {
|
|
1689
2115
|
this.tokenProvider = options.tokenProvider ?? ambientRenownTokenProvider;
|
|
1690
2116
|
const models = options.documentModels;
|
|
@@ -1699,10 +2125,30 @@ var GraphQLReactorClient = class {
|
|
|
1699
2125
|
const middleware = withWrongBackendErrors(makeAuthMiddleware(this.tokenProvider));
|
|
1700
2126
|
this.sdk = options.graphqlClient ?? createClient$1(options.url, middleware);
|
|
1701
2127
|
this.subgraphs = new SubgraphSdkRegistry(options.url, middleware);
|
|
2128
|
+
this.driveNodes = new GraphQLDriveNodeSource(this.sdk, driveIdHeaders);
|
|
2129
|
+
this.read = new GraphQLReadHalf(this, this.driveNodes);
|
|
2130
|
+
this.write = {
|
|
2131
|
+
execute: (documentIdentifier, branch, actions, signal) => this.submitExecute(documentIdentifier, branch, actions, signal),
|
|
2132
|
+
create: (document, parentIdentifier, signal) => this.submitCreate(document, parentIdentifier, signal),
|
|
2133
|
+
deleteDocument: (identifier, propagate, signal) => this.submitDeleteDocument(identifier, propagate, signal)
|
|
2134
|
+
};
|
|
2135
|
+
}
|
|
2136
|
+
/**
|
|
2137
|
+
* The Switchboard's drive node queries as a node source, for every drive
|
|
2138
|
+
* type. `read.drives` answers from it.
|
|
2139
|
+
*/
|
|
2140
|
+
nodeSource() {
|
|
2141
|
+
return this.driveNodes;
|
|
1702
2142
|
}
|
|
1703
|
-
|
|
2143
|
+
/**
|
|
2144
|
+
* Reads a document. With a consistency token that names any coordinate, the
|
|
2145
|
+
* Switchboard waits until its read models hold them; one without the
|
|
2146
|
+
* `document` query's `consistency` argument is read without it, which after
|
|
2147
|
+
* a write's `readable` stage still sees the write on a single node.
|
|
2148
|
+
*/
|
|
2149
|
+
async get(identifier, view, signal, consistencyToken) {
|
|
1704
2150
|
const viewInput = viewFilterInputFromViewFilter(view);
|
|
1705
|
-
const document = (await this.sdk.GetDocument({
|
|
2151
|
+
const document = (consistencyToken && consistencyToken.coordinates.length > 0 ? await this.getDocumentAtConsistency(identifier, viewInput, consistencyToken, signal) : await this.sdk.GetDocument({
|
|
1706
2152
|
identifier,
|
|
1707
2153
|
view: viewInput
|
|
1708
2154
|
}, void 0, signal)).document;
|
|
@@ -1710,6 +2156,61 @@ var GraphQLReactorClient = class {
|
|
|
1710
2156
|
return phDocumentFromGetDocument(document.document, view?.branch);
|
|
1711
2157
|
}
|
|
1712
2158
|
/**
|
|
2159
|
+
* Reads documents by id, in the order given; throws if any is missing. Each
|
|
2160
|
+
* chunk of {@link GET_MANY_CHUNK_SIZE} ids is one request holding an aliased
|
|
2161
|
+
* `document` field per id, with the selection and arguments `get` sends.
|
|
2162
|
+
*/
|
|
2163
|
+
async getMany(documentIds, view, signal, consistencyToken) {
|
|
2164
|
+
const viewInput = viewFilterInputFromViewFilter(view);
|
|
2165
|
+
const token = consistencyToken && consistencyToken.coordinates.length > 0 ? consistencyToken : void 0;
|
|
2166
|
+
const chunks = [];
|
|
2167
|
+
for (let i = 0; i < documentIds.length; i += GET_MANY_CHUNK_SIZE) chunks.push(documentIds.slice(i, i + GET_MANY_CHUNK_SIZE));
|
|
2168
|
+
return (await Promise.all(chunks.map((chunk) => this.getDocumentChunk(chunk, viewInput, token, signal)))).flat().map((document) => phDocumentFromGetDocument(document, view?.branch));
|
|
2169
|
+
}
|
|
2170
|
+
/** One chunk of `getMany`, with the `consistency` argument while the Switchboard accepts it. */
|
|
2171
|
+
async getDocumentChunk(identifiers, view, token, signal) {
|
|
2172
|
+
if (token && !this.consistencyUnsupported) try {
|
|
2173
|
+
return await this.runGetDocuments(identifiers, view, consistencyInputFromToken(token), signal);
|
|
2174
|
+
} catch (error) {
|
|
2175
|
+
if (!refusesConsistencyArgument(error)) throw error;
|
|
2176
|
+
this.consistencyUnsupported = true;
|
|
2177
|
+
}
|
|
2178
|
+
return this.runGetDocuments(identifiers, view, void 0, signal);
|
|
2179
|
+
}
|
|
2180
|
+
async runGetDocuments(identifiers, view, consistency, signal) {
|
|
2181
|
+
const variables = { view };
|
|
2182
|
+
const definitions = ["$view: ViewFilterInput"];
|
|
2183
|
+
let consistencyArgument = "";
|
|
2184
|
+
if (consistency) {
|
|
2185
|
+
variables.consistency = consistency;
|
|
2186
|
+
definitions.push("$consistency: ConsistencyTokenInput");
|
|
2187
|
+
consistencyArgument = ", consistency: $consistency";
|
|
2188
|
+
}
|
|
2189
|
+
const fields = identifiers.map((identifier, i) => {
|
|
2190
|
+
variables[`id${i}`] = identifier;
|
|
2191
|
+
definitions.push(`$id${i}: String!`);
|
|
2192
|
+
return `d${i}: document(identifier: $id${i}, view: $view${consistencyArgument}) { document { ...PHDocumentFields } childIds }`;
|
|
2193
|
+
});
|
|
2194
|
+
const query = [
|
|
2195
|
+
`query GetDocuments(${definitions.join(", ")}) {`,
|
|
2196
|
+
...fields,
|
|
2197
|
+
"}",
|
|
2198
|
+
PH_DOCUMENT_FIELDS_SOURCE
|
|
2199
|
+
].join("\n");
|
|
2200
|
+
const data = await this.sdk.RunDocument({
|
|
2201
|
+
operationName: "GetDocuments",
|
|
2202
|
+
operationType: "query",
|
|
2203
|
+
document: query,
|
|
2204
|
+
variables,
|
|
2205
|
+
signal
|
|
2206
|
+
});
|
|
2207
|
+
return identifiers.map((identifier, i) => {
|
|
2208
|
+
const result = data[`d${i}`];
|
|
2209
|
+
if (!result) throw new Error(`Document not found: ${identifier}`);
|
|
2210
|
+
return result.document;
|
|
2211
|
+
});
|
|
2212
|
+
}
|
|
2213
|
+
/**
|
|
1713
2214
|
* Whether the Switchboard would serve the document to this client's caller,
|
|
1714
2215
|
* from its `documentServed` query: the same read gate `find` passes. Absent
|
|
1715
2216
|
* or withheld is `false`; a failure to decide throws.
|
|
@@ -1954,6 +2455,12 @@ var GraphQLReactorClient = class {
|
|
|
1954
2455
|
const result = await this.sdk.GetJobStatus({ jobId }, void 0, signal);
|
|
1955
2456
|
return result.jobStatus ? jobInfoFromGql(result.jobStatus) : void 0;
|
|
1956
2457
|
}
|
|
2458
|
+
/** The job as `jobStatus` reports it now; throws when it reports none. */
|
|
2459
|
+
async getJobStatus(jobId, signal) {
|
|
2460
|
+
const job = await this.getJob(jobId, signal);
|
|
2461
|
+
if (!job) throw new Error(`Job not found: ${jobId}`);
|
|
2462
|
+
return job;
|
|
2463
|
+
}
|
|
1957
2464
|
/** Polls `jobStatus` until the job is READ_READY or FAILED. */
|
|
1958
2465
|
async waitForJob(jobOrId, signal) {
|
|
1959
2466
|
if (typeof jobOrId !== "string" && isSettled(jobOrId)) return jobOrId;
|
|
@@ -2177,6 +2684,8 @@ var GraphQLReactorClient = class {
|
|
|
2177
2684
|
*/
|
|
2178
2685
|
dispose() {
|
|
2179
2686
|
this.teardownRealtime();
|
|
2687
|
+
this.jobSocket?.dispose();
|
|
2688
|
+
this.jobSocket = void 0;
|
|
2180
2689
|
}
|
|
2181
2690
|
/**
|
|
2182
2691
|
* Binds a project's generated SDK to this client's transport and auth.
|
|
@@ -2244,6 +2753,128 @@ var GraphQLReactorClient = class {
|
|
|
2244
2753
|
};
|
|
2245
2754
|
}
|
|
2246
2755
|
/**
|
|
2756
|
+
* The write half's `execute`: signs as the facade's `execute` does, submits
|
|
2757
|
+
* through `executeAsync` and returns once the job is accepted. When anyone
|
|
2758
|
+
* subscribes, the document is read back once the job is readable and
|
|
2759
|
+
* announced as `Updated`, as the facade's `execute` announces it; the handle
|
|
2760
|
+
* shares that read with its own `document()`.
|
|
2761
|
+
*/
|
|
2762
|
+
async submitExecute(documentIdentifier, branch, actions, signal) {
|
|
2763
|
+
const document = await this.get(documentIdentifier, { branch }, signal);
|
|
2764
|
+
const preparedActions = await prepareActionsForPush(actions, document, this.documentModels(), this.signer, signal);
|
|
2765
|
+
const handle = new GraphQLJobWriteHandle(jobInfoFromGql((await this.sdk.MutateDocumentAsync({
|
|
2766
|
+
documentIdentifier,
|
|
2767
|
+
actions: preparedActions.map(toTransportAction),
|
|
2768
|
+
branch
|
|
2769
|
+
}, this.driveIdHeaders({
|
|
2770
|
+
method: "execute",
|
|
2771
|
+
documentId: documentIdentifier
|
|
2772
|
+
}, isDrive(document) ? document.header.id : void 0), signal)).mutateDocumentAsync), document.header.id, branch, (jobId, stage, stageSignal) => this.waitForStage(jobId, stage, stageSignal), this.handleReader(document.header.id), signal);
|
|
2773
|
+
if (this.listeners.length > 0) this.announceWrite(handle);
|
|
2774
|
+
return handle;
|
|
2775
|
+
}
|
|
2776
|
+
/** The write half's `create`: the synchronous mutation, a settled handle. */
|
|
2777
|
+
async submitCreate(document, parentIdentifier, signal) {
|
|
2778
|
+
const created = await this.create(document, parentIdentifier, signal);
|
|
2779
|
+
return new GraphQLSettledWriteHandle(created.header.id, created.header.branch || "main", this.handleReader(created.header.id));
|
|
2780
|
+
}
|
|
2781
|
+
/** The write half's `deleteDocument`: the synchronous mutation, a settled handle. */
|
|
2782
|
+
async submitDeleteDocument(identifier, propagate, signal) {
|
|
2783
|
+
await this.deleteDocument(identifier, propagate, signal);
|
|
2784
|
+
return new GraphQLSettledWriteHandle(identifier, "main", this.handleReader(identifier));
|
|
2785
|
+
}
|
|
2786
|
+
/** Reads a write's document back, bounded by its receipt's token. */
|
|
2787
|
+
handleReader(documentId) {
|
|
2788
|
+
return (receipt, view, signal) => this.get(documentId, {
|
|
2789
|
+
...view,
|
|
2790
|
+
branch: receipt.branch
|
|
2791
|
+
}, signal, receipt.token);
|
|
2792
|
+
}
|
|
2793
|
+
/** Announces a write's document as `Updated` once it is readable. */
|
|
2794
|
+
async announceWrite(handle) {
|
|
2795
|
+
let document;
|
|
2796
|
+
try {
|
|
2797
|
+
document = await handle.document();
|
|
2798
|
+
} catch (error) {
|
|
2799
|
+
logger.warn("GraphQLReactorClient: could not read @documentId back to announce a write: @error", handle.documentId, error);
|
|
2800
|
+
return;
|
|
2801
|
+
}
|
|
2802
|
+
this.emitChange({
|
|
2803
|
+
type: DOCUMENT_CHANGE_TYPE.Updated,
|
|
2804
|
+
documents: [document]
|
|
2805
|
+
});
|
|
2806
|
+
}
|
|
2807
|
+
/**
|
|
2808
|
+
* Waits for a job to settle a stage, resolving with a FAILED job too. Polls
|
|
2809
|
+
* `jobStatus` with a doubling interval; with realtime on, a `jobChanges`
|
|
2810
|
+
* event for the job wakes the wait early and the interval is only a safety
|
|
2811
|
+
* net. A failed subscription is logged once and the wait keeps polling.
|
|
2812
|
+
*/
|
|
2813
|
+
async waitForStage(jobId, stage, signal) {
|
|
2814
|
+
const wakers = /* @__PURE__ */ new Set();
|
|
2815
|
+
const stopWatching = this.watchJob(jobId, () => {
|
|
2816
|
+
for (const wake of [...wakers]) wake();
|
|
2817
|
+
});
|
|
2818
|
+
try {
|
|
2819
|
+
let interval = STAGE_POLL_START_MS;
|
|
2820
|
+
for (;;) {
|
|
2821
|
+
const job = await this.getJobStatus(jobId, signal);
|
|
2822
|
+
if (settlesGraphQLJobStage(job.status, stage)) return job;
|
|
2823
|
+
await sleepUntilWoken(interval, wakers, signal);
|
|
2824
|
+
const max = stopWatching && !this.jobRealtimeBroken ? STAGE_POLL_REALTIME_MAX_MS : JOB_POLL_INTERVAL_MS;
|
|
2825
|
+
interval = Math.min(interval * 2, max);
|
|
2826
|
+
}
|
|
2827
|
+
} finally {
|
|
2828
|
+
stopWatching?.();
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
/**
|
|
2832
|
+
* Subscribes to one job's `jobChanges` when realtime is on and the
|
|
2833
|
+
* subscription has not failed before. Returns the stop function, or
|
|
2834
|
+
* undefined when nothing was subscribed.
|
|
2835
|
+
*/
|
|
2836
|
+
watchJob(jobId, onChange) {
|
|
2837
|
+
if (!this.subscriptionsUrl || this.jobRealtimeBroken) return;
|
|
2838
|
+
this.jobSocket ??= createJobChangesSocket({
|
|
2839
|
+
wsUrl: this.subscriptionsUrl,
|
|
2840
|
+
connectionParams: makeAuthConnectionParams(this.tokenProvider)
|
|
2841
|
+
});
|
|
2842
|
+
return this.jobSocket.watch(jobId, () => onChange(), (error) => {
|
|
2843
|
+
if (this.jobRealtimeBroken) return;
|
|
2844
|
+
this.jobRealtimeBroken = true;
|
|
2845
|
+
logger.warn("GraphQLReactorClient: realtime job changes are unavailable, write handles fall back to polling jobStatus", error);
|
|
2846
|
+
});
|
|
2847
|
+
}
|
|
2848
|
+
/**
|
|
2849
|
+
* The `document` query with the `consistency` argument, or without it once
|
|
2850
|
+
* the Switchboard has refused the argument.
|
|
2851
|
+
*/
|
|
2852
|
+
async getDocumentAtConsistency(identifier, view, token, signal) {
|
|
2853
|
+
if (!this.consistencyUnsupported) {
|
|
2854
|
+
const variables = {
|
|
2855
|
+
identifier,
|
|
2856
|
+
view,
|
|
2857
|
+
consistency: consistencyInputFromToken(token)
|
|
2858
|
+
};
|
|
2859
|
+
try {
|
|
2860
|
+
return await this.sdk.RunDocument({
|
|
2861
|
+
operationName: "GetDocumentAtConsistency",
|
|
2862
|
+
operationType: "query",
|
|
2863
|
+
document: GetDocumentAtConsistencyDocument,
|
|
2864
|
+
variables,
|
|
2865
|
+
signal
|
|
2866
|
+
});
|
|
2867
|
+
} catch (error) {
|
|
2868
|
+
if (!refusesConsistencyArgument(error)) throw error;
|
|
2869
|
+
this.consistencyUnsupported = true;
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
return this.sdk.GetDocument({
|
|
2873
|
+
identifier,
|
|
2874
|
+
view
|
|
2875
|
+
}, void 0, signal);
|
|
2876
|
+
}
|
|
2877
|
+
/**
|
|
2247
2878
|
* Opens the realtime socket on the first subscriber.
|
|
2248
2879
|
*
|
|
2249
2880
|
* The subscription is a firehose - no `search` argument - and this client
|
|
@@ -2362,6 +2993,98 @@ var GraphQLReactorClient = class {
|
|
|
2362
2993
|
}
|
|
2363
2994
|
};
|
|
2364
2995
|
/**
|
|
2996
|
+
* The read half of {@link GraphQLReactorClient}: every read is the client's
|
|
2997
|
+
* own, and nothing that writes is reachable from it.
|
|
2998
|
+
*/
|
|
2999
|
+
var GraphQLReadHalf = class {
|
|
3000
|
+
client;
|
|
3001
|
+
drives;
|
|
3002
|
+
constructor(client, nodes) {
|
|
3003
|
+
this.client = client;
|
|
3004
|
+
this.drives = new GraphQLDriveReadClient(nodes);
|
|
3005
|
+
}
|
|
3006
|
+
get(identifier, view, signal, consistencyToken) {
|
|
3007
|
+
return this.client.get(identifier, view, signal, consistencyToken);
|
|
3008
|
+
}
|
|
3009
|
+
getMany(documentIds, view, signal, consistencyToken) {
|
|
3010
|
+
return this.client.getMany(documentIds, view, signal, consistencyToken);
|
|
3011
|
+
}
|
|
3012
|
+
find(search, view, paging, signal) {
|
|
3013
|
+
return this.client.find(search, view, paging, signal);
|
|
3014
|
+
}
|
|
3015
|
+
getOperations(documentIdentifier, view, filter, paging, signal) {
|
|
3016
|
+
return this.client.getOperations(documentIdentifier, view, filter, paging, signal);
|
|
3017
|
+
}
|
|
3018
|
+
subscribe(search, callback, view) {
|
|
3019
|
+
return this.client.subscribe(search, callback, view);
|
|
3020
|
+
}
|
|
3021
|
+
waitForJob(jobId, signal) {
|
|
3022
|
+
return this.client.waitForJob(jobId, signal);
|
|
3023
|
+
}
|
|
3024
|
+
getJobStatus(jobId, signal) {
|
|
3025
|
+
return this.client.getJobStatus(jobId, signal);
|
|
3026
|
+
}
|
|
3027
|
+
};
|
|
3028
|
+
/**
|
|
3029
|
+
* Sleeps for `ms`, or less when a waker in `wakers` fires first. Each sleep
|
|
3030
|
+
* adds its own waker and removes it when it ends.
|
|
3031
|
+
*/
|
|
3032
|
+
function sleepUntilWoken(ms, wakers, signal) {
|
|
3033
|
+
return new Promise((resolve, reject) => {
|
|
3034
|
+
if (signal?.aborted) {
|
|
3035
|
+
reject(abortReason(signal));
|
|
3036
|
+
return;
|
|
3037
|
+
}
|
|
3038
|
+
const finish = () => {
|
|
3039
|
+
clearTimeout(timer);
|
|
3040
|
+
wakers.delete(finish);
|
|
3041
|
+
signal?.removeEventListener("abort", onAbort);
|
|
3042
|
+
};
|
|
3043
|
+
const wake = () => {
|
|
3044
|
+
finish();
|
|
3045
|
+
resolve();
|
|
3046
|
+
};
|
|
3047
|
+
const onAbort = () => {
|
|
3048
|
+
finish();
|
|
3049
|
+
if (signal) reject(abortReason(signal));
|
|
3050
|
+
};
|
|
3051
|
+
const timer = setTimeout(wake, ms);
|
|
3052
|
+
wakers.add(wake);
|
|
3053
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
3054
|
+
});
|
|
3055
|
+
}
|
|
3056
|
+
/**
|
|
3057
|
+
* Whether a request failed because the Switchboard's `document` query has no
|
|
3058
|
+
* `consistency` argument, or its schema no `ConsistencyTokenInput`.
|
|
3059
|
+
*/
|
|
3060
|
+
/** The most ids one `getMany` request reads. */
|
|
3061
|
+
const GET_MANY_CHUNK_SIZE = 50;
|
|
3062
|
+
const PH_DOCUMENT_FIELDS_SOURCE = print(PhDocumentFieldsFragmentDoc);
|
|
3063
|
+
function consistencyInputFromToken(token) {
|
|
3064
|
+
return {
|
|
3065
|
+
version: token.version,
|
|
3066
|
+
createdAtUtcIso: token.createdAtUtcIso,
|
|
3067
|
+
coordinates: token.coordinates.map((coordinate) => ({
|
|
3068
|
+
documentId: coordinate.documentId,
|
|
3069
|
+
scope: coordinate.scope,
|
|
3070
|
+
branch: coordinate.branch,
|
|
3071
|
+
operationIndex: coordinate.operationIndex
|
|
3072
|
+
}))
|
|
3073
|
+
};
|
|
3074
|
+
}
|
|
3075
|
+
function refusesConsistencyArgument(error) {
|
|
3076
|
+
const errors = error?.response?.errors;
|
|
3077
|
+
if (!Array.isArray(errors)) return false;
|
|
3078
|
+
return errors.some((entry) => {
|
|
3079
|
+
const message = entry?.message;
|
|
3080
|
+
return typeof message === "string" && (message.includes("\"consistency\"") || message.includes("\"ConsistencyTokenInput\""));
|
|
3081
|
+
});
|
|
3082
|
+
}
|
|
3083
|
+
/** {@link GraphQLReactorClient.nodeSource}, as a function. */
|
|
3084
|
+
function createGraphQLDriveNodeSource(client) {
|
|
3085
|
+
return client.nodeSource();
|
|
3086
|
+
}
|
|
3087
|
+
/**
|
|
2365
3088
|
* Whether a value is a {@link GraphQLReactorClient}, including one built by
|
|
2366
3089
|
* another copy of this module.
|
|
2367
3090
|
*
|
|
@@ -3150,6 +3873,7 @@ const addToastEventHandler = toastEventFunctions.addEventHandler;
|
|
|
3150
3873
|
const commonGlobalEventHandlerFunctions = {
|
|
3151
3874
|
loading: addLoadingEventHandler,
|
|
3152
3875
|
drives: addDrivesEventHandler,
|
|
3876
|
+
driveNodes: addDriveNodesEventHandler,
|
|
3153
3877
|
selectedDriveId: () => {
|
|
3154
3878
|
addSelectedDriveIdEventHandler();
|
|
3155
3879
|
addSyncSelectionOnPopStateEventHandler();
|
|
@@ -3166,6 +3890,7 @@ const phGlobalEventHandlerRegisterFunctions = {
|
|
|
3166
3890
|
...commonGlobalEventHandlerFunctions,
|
|
3167
3891
|
reactorClientModule: addReactorClientModuleEventHandler,
|
|
3168
3892
|
reactorClient: addReactorClientEventHandler,
|
|
3893
|
+
reactor: addReactorHalvesEventHandler,
|
|
3169
3894
|
fullReactorClient: addFullReactorClientEventHandler,
|
|
3170
3895
|
attachmentService: addAttachmentServiceEventHandler,
|
|
3171
3896
|
features: addFeaturesEventHandler,
|
|
@@ -3409,6 +4134,6 @@ function useDocumentOperations(documentId, scope, options = {}) {
|
|
|
3409
4134
|
return legacy ? legacyResult : primary;
|
|
3410
4135
|
}
|
|
3411
4136
|
//#endregion
|
|
3412
|
-
export { addIsAnalyticsExternalProcessorsEnabledEventHandler as $,
|
|
4137
|
+
export { addIsAnalyticsExternalProcessorsEnabledEventHandler as $, usePGlite as $i, useIsEditorDebugModeEnabled as $n, resolveDocumentModelModule as $r, setIsDeleteLocalDrivesEnabled as $t, useDropTarget as A, deleteNode as Ai, useAnalyticsDatabaseName as An, phDocumentEditorConfigHooks as Ar, addVersionEventHandler as At, addCliVersionEventHandler as B, upgradeDocument as Bi, useIsAddDriveEnabled as Bn, findIsServableOverGraphQL as Br, setDrivesPreserveStrategy as Bt, usePackageDiscoveryService as C, useSetSearchParams as Ca, COMMON_PACKAGE_ID as Ci, setSentryRelease as Cn, useWarnOutdatedApp as Cr, addRouterBasenameEventHandler as Ct, addDraggingNodeEventHandler as D, addFileWithProgress as Di, setVersionCheckInterval as Dn, isExternalControlsEnabledEventFunctions as Dr, addStudioModeEventHandler as Dt, useGraphQLReactorClient as E, addDocument as Ei, setVersion as En, addIsExternalControlsEnabledEventHandler as Er, addSentryReleaseEventHandler as Et, setAttachmentService as F, loadFile as Fi, useDrivesPreserveStrategy as Fn, useAllowedDocumentTypes as Fr, setAnalyticsDatabaseName as Ft, addFileUploadOperationsChunkSizeEventHandler as G, addReactorClientModuleEventHandler as Gi, useIsAnalyticsExternalProcessorsEnabled as Gn, makeAuthConnectionParams as Gr, setIsAddDriveEnabled as Gt, addDisabledEditorsEventHandler as H, isDocumentTypeSupported as Hi, useIsAddPublicDrivesEnabled as Hn, viewFilterInputFromViewFilter as Hr, setFileUploadOperationsChunkSize as Ht, useAttachmentService as I, moveNode$1 as Ii, useEnabledEditors as In, useIsDragAndDropEnabled as Ir, setBasePath as It, addIsAddDriveEnabledEventHandler as J, setFullReactorClient as Ji, useIsDeleteLocalDrivesEnabled as Jn, SubgraphSdkRegistry as Jr, setIsAnalyticsDatabaseWorkerEnabled as Jt, addGaTrackingIdEventHandler as K, addReactorHalvesEventHandler as Ki, useIsCloudDrivesEnabled as Kn, startDocumentChangesSubscription as Kr, setIsAddLocalDrivesEnabled as Kt, addAllowListEventHandler as L, renameDriveNode as Li, useFileUploadOperationsChunkSize as Ln, useIsExternalControlsEnabled as Lr, setCliVersion as Lt, setFeatures as M, extractInitialState as Mi, useCliVersion as Mn, setAllowedDocumentTypes as Mr, phGlobalConfigHooks as Mt, useFeatures as N, fetchDocumentOperations as Ni, useDefaultDrivesUrl as Nn, setIsDragAndDropEnabled as Nr, phGlobalConfigSetters as Nt, useDragNode as O, addFolder$1 as Oi, setWarnOutdatedApp as On, phAppConfigHooks as Or, addSwitchboardUrlEventHandler as Ot, addAttachmentServiceEventHandler as P, getDocumentExtension as Pi, useDisabledEditors as Pn, setIsExternalControlsEnabled as Pr, setAllowList as Pt, addIsAnalyticsEnabledEventHandler as Q, useModelRegistry as Qi, useIsDriveAnalyticsEnabled as Qn, packageFromDocumentModels as Qr, setIsDeleteCloudDrivesEnabled as Qt, addAnalyticsDatabaseNameEventHandler as R, renameNode as Ri, useGaTrackingId as Rn, GraphQLReactorClient as Rr, setDefaultDrivesUrl as Rt, setPackageDiscoveryService as S, useSearchParams as Sa, screamingSnakeToCamel as Si, setSentryEnv as Sn, useVersionCheckInterval as Sr, addRequiresHardRefreshEventHandler as St, setGraphQLReactorClient as T, DRIVE_DOCUMENT_TYPES as Ti, setSwitchboardUrl as Tn, addIsDragAndDropEnabledEventHandler as Tr, addSentryEnvEventHandler as Tt, addDrivesPreserveStrategyEventHandler as U, addFullReactorClientEventHandler as Ui, useIsAnalyticsDatabaseWorkerEnabled as Un, createJobChangesSocket as Ur, setGaTrackingId as Ut, addDefaultDrivesUrlEventHandler as V, getUserPermissions as Vi, useIsAddLocalDrivesEnabled as Vn, isGraphQLReactorClient as Vr, setEnabledEditors as Vt, addEnabledEditorsEventHandler as W, addReactorClientEventHandler as Wi, useIsAnalyticsEnabled as Wn, isAuthRefusalClose as Wr, setIsAddCloudDrivesEnabled as Wt, addIsAddPublicDrivesEnabledEventHandler as X, setReactorClientModule as Xi, useIsDiffAnalyticsEnabled as Xn, subgraphUrlFromGraphqlUrl as Xr, setIsAnalyticsExternalProcessorsEnabled as Xt, addIsAddLocalDrivesEnabledEventHandler as Y, setReactorClient as Yi, useIsDeletePublicDrivesEnabled as Yn, describeGraphQLDocument as Yr, setIsAnalyticsEnabled as Yt, addIsAnalyticsDatabaseWorkerEnabledEventHandler as Z, useDatabase as Zi, useIsDocumentModelSelectionSettingsEnabled as Zn, StaticPackageManager as Zr, setIsCloudDrivesEnabled as Zt, addSetSelectedDriveOnPopStateEventHandler as _, usePHModal as _a, ConflictError as _i, setRenownNetworkId as _n, useSentryEnv as _r, addLogLevelEventHandler as _t, addPHEventHandlers as a, MODAL_SEARCH_PARAM as aa, ReactorOperationFieldsFragmentDoc as ai, setIsEditorReadModeEnabled as an, useIsPublicDrivesEnabled as ar, addIsDocumentModelSelectionSettingsEnabledEventHandler as at, syncSelectionFromPath as b, useLinkProps as ba, extractRevisionMap as bi, setRouterBasename as bn, useSwitchboardUrl as br, addRenownNetworkIdEventHandler as bt, addToastEventHandler as c, isRoutedModal as ca, GraphQLWrongBackendError as ci, setIsExternalRelationalProcessorsEnabled as cn, useLocalDrivesEnabled as cr, addIsEditorReadModeEnabledEventHandler as ct, addSelectedTimelineRevisionEventHandler as d, modalSearch as da, GraphQLDriveReadClient as di, setIsRelationalProcessorsEnabled as dn, useRenownChainId as dr, addIsExternalRelationalProcessorsEnabledEventHandler as dt, useReactorClient as ea, prepareSignedActions as ei, setIsDeletePublicDrivesEnabled as en, useIsEditorReadModeEnabled as er, addIsCloudDrivesEnabledEventHandler as et, setSelectedTimelineRevision as f, setPHModal as fa, toLegacyNode as fi, setIsSentryTracingEnabled as fn, useRenownNetworkId as fr, addIsLocalDrivesEnabledEventHandler as ft, useSelectedTimelineItem as g, useModalLinkProps as ga, revisionMapFromRevisionsList as gi, setRenownChainId as gn, useSentryDsn as gr, addLocalDrivesEnabledEventHandler as gt, setSelectedTimelineItem as h, showPHModal as ha, phDocumentFromMutation as hi, setRenownAdapters as hn, useRouterBasename as hr, addIsSentryTracingEnabledEventHandler as ht, useSwitchboardClient as i, useSyncList as ia, MutateDocumentWithOperationsDocument as ii, setIsEditorDebugModeEnabled as in, useIsLocalDrivesEnabled as ir, addIsDiffAnalyticsEnabledEventHandler as it, addFeaturesEventHandler as j, exportFile as ji, useBasePath as jn, phDocumentEditorConfigSetters as jr, addWarnOutdatedAppEventHandler as jt, useDropNode as k, copyNode$1 as ki, useAllowList as kn, phAppConfigSetters as kr, addVersionCheckIntervalEventHandler as kt, setPHToast as l, modalFromSearch as la, JobFailedError as li, setIsLocalDrivesEnabled as ln, useLogLevel as lr, addIsExternalPackagesEnabledEventHandler as lt, addSelectedTimelineItemEventHandler as m, showDeleteNodeModal as ma, phDocumentFromGetDocument as mi, setLogLevel as mn, useRequiresHardRefresh as mr, addIsRelationalProcessorsEnabledEventHandler as mt, GraphQLReactorProvider as n, useReactorHalves as na, stampAction as ni, setIsDocumentModelSelectionSettingsEnabled as nn, useIsExternalProcessorsEnabled as nr, addIsDeleteLocalDrivesEnabledEventHandler as nt, callEventHandlerRegisterFunctions as o, addModalEventHandler as oa, BatchJobFailedError as oi, setIsExternalPackagesEnabled as on, useIsRelationalProcessorsEnabled as or, addIsDriveAnalyticsEnabledEventHandler as ot, useSelectedTimelineRevision as p, showCreateDocumentModal as pa, isoStringFromDateTime as pi, setLocalDrivesEnabled as pn, useRenownUrl as pr, addIsPublicDrivesEnabledEventHandler as pt, addIsAddCloudDrivesEnabledEventHandler as q, getFullReactorClient as qi, useIsDeleteCloudDrivesEnabled as qn, subscriptionsUrlFromGraphqlUrl as qr, setIsAddPublicDrivesEnabled as qt, ensurePHEventHandlers as r, useSync as ra, GetDocumentAtConsistencyDocument as ri, setIsDriveAnalyticsEnabled as rn, useIsExternalRelationalProcessorsEnabled as rr, addIsDeletePublicDrivesEnabledEventHandler as rt, commonGlobalEventHandlerFunctions as s, closePHModal as sa, GraphQLOperationNotSupportedError as si, setIsExternalProcessorsEnabled as sn, useIsSentryTracingEnabled as sr, addIsEditorDebugModeEnabledEventHandler as st, useDocumentOperations as t, useReactorClientModule as ta, signStampedAction as ti, setIsDiffAnalyticsEnabled as tn, useIsExternalPackagesEnabled as tr, addIsDeleteCloudDrivesEnabledEventHandler as tt, usePHToast as u, modalHref as ua, GraphQLDriveNodeSource as ui, setIsPublicDrivesEnabled as un, useRenownAdapters as ur, addIsExternalProcessorsEnabledEventHandler as ut, addSetSelectedNodeOnPopStateEventHandler as v, withoutModalSearch as va, buildPulledDocument as vi, setRenownUrl as vn, useSentryRelease as vr, addRenownAdaptersEventHandler as vt, addGraphQLReactorClientEventHandler as w, DEFAULT_DRIVE_EDITOR_ID as wi, setStudioMode as wn, addAllowedDocumentTypesEventHandler as wr, addSentryDsnEventHandler as wt, addPackageDiscoveryServiceEventHandler as x, usePHNavigation as xa, hasRevisionConflict as xi, setSentryDsn as xn, useVersion as xr, addRenownUrlEventHandler as xt, addSyncSelectionOnPopStateEventHandler as y, isPlainClick as ya, convertRemoteOperations as yi, setRequiresHardRefresh as yn, useStudioMode as yr, addRenownChainIdEventHandler as yt, addBasePathEventHandler as z, setPreferredEditorOnNode as zi, useIsAddCloudDrivesEnabled as zn, createGraphQLDriveNodeSource as zr, setDisabledEditors as zt };
|
|
3413
4138
|
|
|
3414
|
-
//# sourceMappingURL=document-operations-
|
|
4139
|
+
//# sourceMappingURL=document-operations-BdCl99y6.js.map
|