@powerhousedao/reactor-browser 6.2.3-dev.8 → 6.2.3-dev.81
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-D3EhiAJ7.d.ts → attachment-service-DPWkKp3y.d.ts} +636 -83
- package/dist/attachment-service-DPWkKp3y.d.ts.map +1 -0
- package/dist/{client-DjK30EQ-.js → client-BFnMV-EO.js} +39 -22
- package/dist/client-BFnMV-EO.js.map +1 -0
- package/dist/{client-D66jVnot.js → client-BUpynoY6.js} +345 -33
- package/dist/client-BUpynoY6.js.map +1 -0
- package/dist/{client-BIHN_UyR.d.ts → client-XPGQrO4a.d.ts} +3 -3
- package/dist/client-XPGQrO4a.d.ts.map +1 -0
- package/dist/dispatch-C8J9jQ-o.js +1171 -0
- package/dist/dispatch-C8J9jQ-o.js.map +1 -0
- package/dist/document-by-id-Dpp76ZNE.js +16 -0
- package/dist/document-by-id-Dpp76ZNE.js.map +1 -0
- package/dist/document-model-modules-XrYfGXt8.js +644 -0
- package/dist/document-model-modules-XrYfGXt8.js.map +1 -0
- package/dist/{document-operations-WeE6wIDt.js → document-operations-CdfiLNQN.js} +1919 -278
- package/dist/document-operations-CdfiLNQN.js.map +1 -0
- package/dist/global-BSyOOTvL.d.ts +647 -0
- package/dist/global-BSyOOTvL.d.ts.map +1 -0
- package/dist/{index-B33TKEqp.d.ts → index-Bjm0bSzf.d.ts} +19 -98
- package/dist/index-Bjm0bSzf.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 +813 -410
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +771 -119
- package/dist/index.js.map +1 -1
- package/dist/inspector-proxy-DODqs15F.d.ts +25 -0
- package/dist/inspector-proxy-DODqs15F.d.ts.map +1 -0
- package/dist/make-ph-event-functions-B5GU5xcR.js +180 -0
- package/dist/make-ph-event-functions-B5GU5xcR.js.map +1 -0
- package/dist/navigation-BqphkrOB.js +302 -0
- package/dist/navigation-BqphkrOB.js.map +1 -0
- 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-DZuyKp2y.js} +66 -5
- package/dist/relational-DZuyKp2y.js.map +1 -0
- package/dist/{renown-rqK8sokh.js → renown-BtjgHBjH.js} +33 -28
- package/dist/{renown-rqK8sokh.js.map → renown-BtjgHBjH.js.map} +1 -1
- package/dist/{renown-BHxwP7xU.js → renown-BxkZYzbQ.js} +2 -2
- package/dist/{renown-BHxwP7xU.js.map → renown-BxkZYzbQ.js.map} +1 -1
- package/dist/src/ai/index.d.ts +53 -70
- package/dist/src/ai/index.d.ts.map +1 -1
- package/dist/src/ai/index.js +12 -28
- 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 +4 -4
- 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 +4 -4
- package/dist/src/relational/index.d.ts +15 -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 +214 -140
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/rpc/index.js +587 -622
- 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-CaXQ4-5Q.js → switchboard-CYTCYt4Z.js} +61 -11
- package/dist/switchboard-CYTCYt4Z.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-Dcv1ZLoW.d.ts → types-BNVqRNli.d.ts} +320 -18
- package/dist/types-BNVqRNli.d.ts.map +1 -0
- package/package.json +23 -23
- package/dist/attachment-service-D3EhiAJ7.d.ts.map +0 -1
- package/dist/client-BIHN_UyR.d.ts.map +0 -1
- package/dist/client-D66jVnot.js.map +0 -1
- package/dist/client-DjK30EQ-.js.map +0 -1
- package/dist/document-by-id-B4FIzG1w.js +0 -519
- package/dist/document-by-id-B4FIzG1w.js.map +0 -1
- package/dist/document-model-modules-bTP87nyr.js +0 -419
- package/dist/document-model-modules-bTP87nyr.js.map +0 -1
- package/dist/document-operations-WeE6wIDt.js.map +0 -1
- package/dist/global-OuINvEGT.d.ts +0 -401
- package/dist/global-OuINvEGT.d.ts.map +0 -1
- package/dist/index-B33TKEqp.d.ts.map +0 -1
- package/dist/index-BIVDXw3K.d.ts.map +0 -1
- package/dist/inspector-proxy-6h5VKAwt.d.ts +0 -257
- package/dist/inspector-proxy-6h5VKAwt.d.ts.map +0 -1
- package/dist/make-ph-event-functions-DBq3iWYn.js +0 -53
- package/dist/make-ph-event-functions-DBq3iWYn.js.map +0 -1
- package/dist/pglite-CntadC_p-9NDG14dS.d.ts.map +0 -1
- package/dist/relational-D1RB45sA.js.map +0 -1
- package/dist/switchboard-CaXQ4-5Q.js.map +0 -1
- package/dist/types-6vDzbRRS.d.ts.map +0 -1
- package/dist/types-Dcv1ZLoW.d.ts.map +0 -1
|
@@ -1,18 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { c as getPHStore, f as usePHStore, t as makePHEventFunctions } from "./make-ph-event-functions-B5GU5xcR.js";
|
|
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-C8J9jQ-o.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-XrYfGXt8.js";
|
|
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 { a as PhDocumentFieldsFragmentDoc, i as JobChangesDocument, n as DocumentChangesDocument, t as createClient$1 } from "./client-BUpynoY6.js";
|
|
6
|
+
import { f as addLoadingEventHandler, t as addRenownEventHandler } from "./renown-BxkZYzbQ.js";
|
|
7
|
+
import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
8
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
6
9
|
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
|
-
import { addFolder, copyNode, generateNodesCopy, handleTargetNameCollisions, isFileNode, isFolderNode, moveNode, updateNode } from "@powerhousedao/shared/document-drive";
|
|
10
|
+
import { PEER_CAPABILITIES, UnsupportedDocumentModelVersionError, actionSignerIdentity, actionSigningTarget, actions, assertAuthPreservedOnDuplicate, baseLoadFromInput, baseLoadFromInputVersioned, baseSaveToFileHandle, capSelection, createCopyHeader, createPresignedHeader, createZip, creationState, deserializeSignature, documentModelDocumentType, generateId, hasDerivedDocumentId, hashDocumentStateForScope, headNewDocument, isSignaturePolicy, localSupports, normalizeDocumentModelVersion, replayDocumentVersioned, selectDocumentModelModule, setName, setPreferredEditor, signaturePolicyOf, toTransportAction, withSignaturePolicy } from "@powerhousedao/shared/document-model";
|
|
11
|
+
import { addFolder, copyNode, driveDocumentModelModule, generateNodesCopy, handleTargetNameCollisions, isFileNode, isFolderNode, moveNode, updateNode } from "@powerhousedao/shared/document-drive";
|
|
9
12
|
import { allPass, conditional, constant, forEachObj, funnel, isDefined, isNot, isStrictEqual, isString, isTruthy, once } from "remeda";
|
|
10
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
11
|
-
import { GraphQLClient } from "graphql-request";
|
|
12
13
|
import { gql } from "graphql-tag";
|
|
13
14
|
import { Kind, print } from "graphql";
|
|
15
|
+
import { GraphQLClient } from "graphql-request";
|
|
14
16
|
import { createClient } from "graphql-ws/client";
|
|
15
|
-
|
|
17
|
+
//#region src/hooks/url-state.ts
|
|
18
|
+
/** The nearest store's navigation, else the bound store's, else the browser's.
|
|
19
|
+
* Hosts set it once, so hook order holds. */
|
|
20
|
+
function usePHNavigation() {
|
|
21
|
+
return usePHStore()?.navigation ?? getPHNavigation();
|
|
22
|
+
}
|
|
23
|
+
/** The current query params. */
|
|
24
|
+
function useSearchParams() {
|
|
25
|
+
return usePHNavigation().useSearchParams();
|
|
26
|
+
}
|
|
27
|
+
/** Sets query params: an object merges into them, a function returns them all. */
|
|
28
|
+
function useSetSearchParams() {
|
|
29
|
+
return usePHNavigation().useSetSearchParams();
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/hooks/link-props.ts
|
|
33
|
+
/** A plain primary click; modified and other-button clicks stay the browser's. */
|
|
34
|
+
function isPlainClick(event) {
|
|
35
|
+
return !event.defaultPrevented && event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
|
|
36
|
+
}
|
|
37
|
+
/** Props for an `<a>` that opens `target` in the app on a plain click, and
|
|
38
|
+
* leaves new tabs and windows to the browser; acts on the store in context. */
|
|
39
|
+
function useLinkProps(target, open) {
|
|
40
|
+
const navigation = usePHNavigation();
|
|
41
|
+
const href = navigation.hrefFor?.(target) ?? targetPathname(target);
|
|
42
|
+
const isCurrent = navigation.useIsCurrent?.(target) ?? false;
|
|
43
|
+
const preload = () => navigation.preload?.(target);
|
|
44
|
+
const openTarget = open ?? (() => openTargetWith(navigation, target));
|
|
45
|
+
return {
|
|
46
|
+
href,
|
|
47
|
+
onClick: (event) => {
|
|
48
|
+
if (!isPlainClick(event)) return;
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
openTarget();
|
|
51
|
+
},
|
|
52
|
+
onMouseEnter: preload,
|
|
53
|
+
onFocus: preload,
|
|
54
|
+
"aria-current": isCurrent ? "page" : void 0
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
16
58
|
//#region src/hooks/modals.ts
|
|
17
59
|
const modalEventFunctions = makePHEventFunctions("modal");
|
|
18
60
|
/** Returns the current modal */
|
|
@@ -21,17 +63,123 @@ const usePHModal = modalEventFunctions.useValue;
|
|
|
21
63
|
const setPHModal = modalEventFunctions.setValue;
|
|
22
64
|
/** Adds an event handler for the modal */
|
|
23
65
|
const addModalEventHandler = modalEventFunctions.addEventHandler;
|
|
24
|
-
/**
|
|
66
|
+
/** The query param that names a routed modal. */
|
|
67
|
+
const MODAL_SEARCH_PARAM = "modal";
|
|
68
|
+
const MODAL_ROUTES = {
|
|
69
|
+
createDocument: {
|
|
70
|
+
id: "create-document",
|
|
71
|
+
toSearch: ({ documentType, documentModelVersion, driveId }) => ({
|
|
72
|
+
documentType,
|
|
73
|
+
...documentModelVersion !== void 0 && { documentModelVersion: String(documentModelVersion) },
|
|
74
|
+
...driveId && { driveId }
|
|
75
|
+
}),
|
|
76
|
+
fromSearch: (search) => ({
|
|
77
|
+
documentType: search.documentType ?? "",
|
|
78
|
+
...search.documentModelVersion && { documentModelVersion: Number(search.documentModelVersion) },
|
|
79
|
+
...search.driveId && { driveId: search.driveId }
|
|
80
|
+
})
|
|
81
|
+
},
|
|
82
|
+
login: { id: "login" },
|
|
83
|
+
addDrive: { id: "add-drive" },
|
|
84
|
+
driveSettings: {
|
|
85
|
+
id: "drive-settings",
|
|
86
|
+
toSearch: ({ driveId }) => ({ driveId }),
|
|
87
|
+
fromSearch: (search) => ({ driveId: search.driveId ?? "" })
|
|
88
|
+
},
|
|
89
|
+
debugSettings: { id: "debug-settings" },
|
|
90
|
+
inspector: { id: "inspector" },
|
|
91
|
+
disclaimer: { id: "disclaimer" },
|
|
92
|
+
cookiesPolicy: { id: "cookies-policy" }
|
|
93
|
+
};
|
|
94
|
+
const routeOf = (type) => MODAL_ROUTES[type];
|
|
95
|
+
/** Whether `modal` lives in the URL rather than the store. */
|
|
96
|
+
function isRoutedModal(modal) {
|
|
97
|
+
return !!modal && !!routeOf(modal.type);
|
|
98
|
+
}
|
|
99
|
+
/** The query params that open `modal`; undefined for one the store holds. */
|
|
100
|
+
function modalSearch(modal) {
|
|
101
|
+
const route = routeOf(modal.type);
|
|
102
|
+
if (!route) return void 0;
|
|
103
|
+
return {
|
|
104
|
+
[MODAL_SEARCH_PARAM]: route.id,
|
|
105
|
+
...route.toSearch?.(modal)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** The routed modal `search` opens, if any. */
|
|
109
|
+
function modalFromSearch(search) {
|
|
110
|
+
const id = search[MODAL_SEARCH_PARAM];
|
|
111
|
+
if (typeof id !== "string") return void 0;
|
|
112
|
+
const strings = Object.fromEntries(Object.entries(search).map(([key, value]) => [key, String(value)]));
|
|
113
|
+
for (const [type, route] of Object.entries(MODAL_ROUTES)) {
|
|
114
|
+
if (route.id !== id) continue;
|
|
115
|
+
return {
|
|
116
|
+
type,
|
|
117
|
+
...route.fromSearch?.(strings)
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** `search` without a routed modal's params. */
|
|
122
|
+
function withoutModalSearch(search) {
|
|
123
|
+
const modal = modalFromSearch(search);
|
|
124
|
+
const own = modal ? Object.keys(modalSearch(modal) ?? {}) : [];
|
|
125
|
+
return Object.fromEntries(Object.entries(search).filter(([key]) => !own.includes(key)));
|
|
126
|
+
}
|
|
127
|
+
/** Shows a modal. With a host navigation, a routed one opens in the URL, in
|
|
128
|
+
* place of the current entry, and "settings" opens the settings page. */
|
|
25
129
|
function showPHModal(modal) {
|
|
130
|
+
if (modal.type === "settings" && hasHostNavigation()) {
|
|
131
|
+
openTarget({ settings: true });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const search = modalSearch(modal);
|
|
135
|
+
if (search && hasHostNavigation()) {
|
|
136
|
+
if (!isRoutedModal(modalEventFunctions.getSnapshot())) setPHModal(void 0);
|
|
137
|
+
getPHNavigation().setSearch((prev) => ({
|
|
138
|
+
...withoutModalSearch(prev),
|
|
139
|
+
...search
|
|
140
|
+
}), { replace: true });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
26
143
|
setPHModal(modal);
|
|
27
144
|
}
|
|
28
|
-
/** Closes the current modal
|
|
145
|
+
/** Closes the current modal; a routed one leaves the URL in place of the entry,
|
|
146
|
+
* and a confirmation opened over it closes with it. */
|
|
29
147
|
function closePHModal() {
|
|
148
|
+
if (hasHostNavigation()) {
|
|
149
|
+
const navigation = getPHNavigation();
|
|
150
|
+
if (modalFromSearch(searchToRecord(navigation.location().search))) {
|
|
151
|
+
navigation.setSearch((prev) => withoutModalSearch(prev), { replace: true });
|
|
152
|
+
if (!isRoutedModal(modalEventFunctions.getSnapshot())) setPHModal(void 0);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
30
156
|
setPHModal(void 0);
|
|
31
157
|
}
|
|
158
|
+
/** The href that opens `modal` over the current page. */
|
|
159
|
+
function modalHref(modal) {
|
|
160
|
+
const { pathname, search } = getPHNavigation().location();
|
|
161
|
+
const next = {
|
|
162
|
+
...withoutModalSearch(searchToRecord(search)),
|
|
163
|
+
...modalSearch(modal)
|
|
164
|
+
};
|
|
165
|
+
return `${pathname}${recordToSearch(next)}`;
|
|
166
|
+
}
|
|
167
|
+
/** Props for an `<a>` that opens a routed `modal` over the current page on a
|
|
168
|
+
* plain click; new tabs and copied links get its URL. */
|
|
169
|
+
function useModalLinkProps(modal) {
|
|
170
|
+
useSearchParams();
|
|
171
|
+
return {
|
|
172
|
+
href: modalHref(modal),
|
|
173
|
+
onClick: (event) => {
|
|
174
|
+
if (!isPlainClick(event)) return;
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
showPHModal(modal);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
32
180
|
/** Shows the create document modal */
|
|
33
181
|
function showCreateDocumentModal(documentType, documentModelVersion) {
|
|
34
|
-
|
|
182
|
+
showPHModal({
|
|
35
183
|
type: "createDocument",
|
|
36
184
|
documentType,
|
|
37
185
|
...documentModelVersion !== void 0 && { documentModelVersion }
|
|
@@ -39,12 +187,70 @@ function showCreateDocumentModal(documentType, documentModelVersion) {
|
|
|
39
187
|
}
|
|
40
188
|
/** Shows the delete node modal */
|
|
41
189
|
function showDeleteNodeModal(nodeOrId) {
|
|
190
|
+
const id = typeof nodeOrId === "string" ? nodeOrId : nodeOrId.id;
|
|
42
191
|
setPHModal({
|
|
43
192
|
type: "deleteItem",
|
|
44
|
-
id
|
|
193
|
+
id
|
|
45
194
|
});
|
|
46
195
|
}
|
|
47
196
|
//#endregion
|
|
197
|
+
//#region src/hooks/reactor.ts
|
|
198
|
+
const reactorClientModuleEventFunctions = makePHEventFunctions("reactorClientModule");
|
|
199
|
+
const reactorClientEventFunctions = makePHEventFunctions("reactorClient");
|
|
200
|
+
const reactorHalvesEventFunctions = makePHEventFunctions("reactor");
|
|
201
|
+
const fullReactorClientEventFunctions = makePHEventFunctions("fullReactorClient");
|
|
202
|
+
/** Returns the reactor client module (in-process or worker-backed) */
|
|
203
|
+
const useReactorClientModule = reactorClientModuleEventFunctions.useValue;
|
|
204
|
+
/** Sets the reactor client module */
|
|
205
|
+
const setReactorClientModule = reactorClientModuleEventFunctions.setValue;
|
|
206
|
+
/** Adds an event handler for the reactor client module */
|
|
207
|
+
const addReactorClientModuleEventHandler = reactorClientModuleEventFunctions.addEventHandler;
|
|
208
|
+
/** Returns the reactor client */
|
|
209
|
+
const useReactorClient = reactorClientEventFunctions.useValue;
|
|
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
|
+
}
|
|
230
|
+
/** Adds an event handler for the reactor client */
|
|
231
|
+
const addReactorClientEventHandler = reactorClientEventFunctions.addEventHandler;
|
|
232
|
+
/** Sets the client full-client actions use instead of the module's */
|
|
233
|
+
const setFullReactorClient = fullReactorClientEventFunctions.setValue;
|
|
234
|
+
/** Adds an event handler for the full reactor client */
|
|
235
|
+
const addFullReactorClientEventHandler = fullReactorClientEventFunctions.addEventHandler;
|
|
236
|
+
/** The client full-client actions use: the one set, else the module's. */
|
|
237
|
+
function getFullReactorClient() {
|
|
238
|
+
return getPHStore()?.fullReactorClient ?? getPHStore()?.reactorClientModule?.client;
|
|
239
|
+
}
|
|
240
|
+
const useSync = () => useReactorClientModule()?.reactorModule?.syncModule?.syncManager;
|
|
241
|
+
const useSyncList = () => {
|
|
242
|
+
return useSync()?.list() ?? [];
|
|
243
|
+
};
|
|
244
|
+
const useModelRegistry = () => useReactorClientModule()?.reactorModule?.documentModelRegistry;
|
|
245
|
+
const useDatabase = () => {
|
|
246
|
+
const module = useReactorClientModule();
|
|
247
|
+
return module?.kind === "browser" ? module.reactorModule?.database : void 0;
|
|
248
|
+
};
|
|
249
|
+
const usePGlite = () => {
|
|
250
|
+
const module = useReactorClientModule();
|
|
251
|
+
return module?.kind === "browser" ? module.reactorModule?.pg : void 0;
|
|
252
|
+
};
|
|
253
|
+
//#endregion
|
|
48
254
|
//#region src/utils/documents.ts
|
|
49
255
|
function isDocumentTypeSupported(documentType, supportedDocuments) {
|
|
50
256
|
if (!supportedDocuments?.length) return true;
|
|
@@ -63,8 +269,8 @@ function isDocumentTypeSupported(documentType, supportedDocuments) {
|
|
|
63
269
|
//#endregion
|
|
64
270
|
//#region src/utils/user.ts
|
|
65
271
|
function getUserPermissions() {
|
|
66
|
-
const user =
|
|
67
|
-
const allowList =
|
|
272
|
+
const user = getPHStore()?.renown?.user;
|
|
273
|
+
const allowList = getPHStore()?.allowList;
|
|
68
274
|
if (!allowList) return {
|
|
69
275
|
isAllowedToCreateDocuments: true,
|
|
70
276
|
isAllowedToEditDocuments: true
|
|
@@ -76,17 +282,27 @@ function getUserPermissions() {
|
|
|
76
282
|
}
|
|
77
283
|
//#endregion
|
|
78
284
|
//#region src/actions/document.ts
|
|
79
|
-
const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
|
|
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
|
+
}
|
|
80
296
|
/** An unreadable drive cannot be shown to hold no duplicate, so reads throw. */
|
|
81
297
|
async function isDocumentInLocation(reactorClient, document, driveId, parentFolder) {
|
|
82
|
-
const
|
|
83
|
-
const nodeById =
|
|
84
|
-
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 {
|
|
85
301
|
isDuplicate: true,
|
|
86
302
|
duplicateType: "id",
|
|
87
303
|
nodeId: nodeById.id
|
|
88
304
|
};
|
|
89
|
-
const nodeByNameAndType =
|
|
305
|
+
const nodeByNameAndType = siblings.find((node) => isFileNode(node) && node.name === document.header.name && node.documentType === document.header.documentType);
|
|
90
306
|
if (nodeByNameAndType) return {
|
|
91
307
|
isDuplicate: true,
|
|
92
308
|
duplicateType: "name",
|
|
@@ -131,9 +347,9 @@ async function getDocumentExtension(document) {
|
|
|
131
347
|
let rawExtension;
|
|
132
348
|
if (documentType === documentModelDocumentType) rawExtension = document.state.global?.extension;
|
|
133
349
|
else {
|
|
134
|
-
const reactorClient =
|
|
350
|
+
const reactorClient = getFullReactorClient();
|
|
135
351
|
if (reactorClient) {
|
|
136
|
-
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
352
|
+
const { results: documentModelModules } = await reactorClient.read.getDocumentModelModules();
|
|
137
353
|
rawExtension = documentModelModules.find((m) => m.documentModel.global.id === documentType)?.utils.fileExtension;
|
|
138
354
|
}
|
|
139
355
|
}
|
|
@@ -163,12 +379,9 @@ async function fetchDocumentOperations(reactorClient, document, pageSize = 100)
|
|
|
163
379
|
return operations;
|
|
164
380
|
}
|
|
165
381
|
function extractInitialState(documentScopeOps) {
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
const initialState = input.initialState ?? input.state;
|
|
170
|
-
if (!initialState) throw new Error("UPGRADE_DOCUMENT operation has no initialState — document is invalid");
|
|
171
|
-
return initialState;
|
|
382
|
+
const initialState = creationState(documentScopeOps);
|
|
383
|
+
if (initialState) return initialState;
|
|
384
|
+
throw new Error(documentScopeOps.some((op) => op.action.type === "UPGRADE_DOCUMENT") ? "UPGRADE_DOCUMENT operation has no initialState — document is invalid" : "No UPGRADE_DOCUMENT operation found — document is invalid");
|
|
172
385
|
}
|
|
173
386
|
function filterDomainOperations(operations) {
|
|
174
387
|
return Object.fromEntries(Object.entries(operations).filter(([scope]) => !NON_DOMAIN_SCOPES.has(scope)));
|
|
@@ -235,9 +448,9 @@ function boundary(upgrade, scope, ops) {
|
|
|
235
448
|
return ops.length;
|
|
236
449
|
}
|
|
237
450
|
async function exportFile(document, suggestedName) {
|
|
238
|
-
const reactorClient =
|
|
451
|
+
const reactorClient = getPHStore()?.reactorClient;
|
|
239
452
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
240
|
-
const operations = await fetchDocumentOperations(reactorClient, document);
|
|
453
|
+
const operations = await fetchDocumentOperations(reactorClient.read, document);
|
|
241
454
|
const initialState = extractInitialState(operations["document"] ?? []);
|
|
242
455
|
const documentWithOps = {
|
|
243
456
|
...document,
|
|
@@ -263,15 +476,15 @@ async function exportFile(document, suggestedName) {
|
|
|
263
476
|
*/
|
|
264
477
|
async function loadFile(path) {
|
|
265
478
|
const baseDocument = await baseLoadFromInput(path, (state) => state, { checkHashes: true });
|
|
266
|
-
const reactorClient =
|
|
479
|
+
const reactorClient = getFullReactorClient();
|
|
267
480
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
268
481
|
const documentType = baseDocument.header.documentType;
|
|
269
|
-
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
482
|
+
const { results: documentModelModules } = await reactorClient.read.getDocumentModelModules();
|
|
270
483
|
const modulesForType = documentModelModules.filter((module) => module.documentModel.global.id === documentType);
|
|
271
484
|
if (modulesForType.length === 0) throw new DocumentModelNotFoundError(documentType);
|
|
272
485
|
const reducers = {};
|
|
273
486
|
for (const module of modulesForType) reducers[module.version ?? 1] = module.reducer;
|
|
274
|
-
const registry =
|
|
487
|
+
const registry = getPHStore()?.reactorClientModule?.reactorModule?.documentModelRegistry;
|
|
275
488
|
let upgradeManifest;
|
|
276
489
|
if (registry) try {
|
|
277
490
|
upgradeManifest = registry.getUpgradeManifest(documentType);
|
|
@@ -284,29 +497,27 @@ async function loadFile(path) {
|
|
|
284
497
|
async function addDocument(driveId, name, documentType, parentFolder, document, id, preferredEditor, documentModelVersion) {
|
|
285
498
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
286
499
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create documents");
|
|
287
|
-
const reactorClient =
|
|
500
|
+
const reactorClient = getFullReactorClient();
|
|
288
501
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (!module) throw new Error(`Document model not found for type: ${documentType} with version: ${documentModelVersion}`);
|
|
294
|
-
documentModelModule = module;
|
|
295
|
-
} else documentModelModule = await reactorClient.getDocumentModelModule(documentType);
|
|
296
|
-
const newDocument = document ?? documentModelModule.utils.createDocument();
|
|
297
|
-
if (!document) newDocument.state.document.version = documentModelModule.version ?? 1;
|
|
502
|
+
const newDocument = document ?? await reactorClient.read.newDocument(documentType, {
|
|
503
|
+
parentIdentifier: driveId,
|
|
504
|
+
documentModelVersion
|
|
505
|
+
});
|
|
298
506
|
newDocument.header.name = name;
|
|
299
507
|
if (preferredEditor) newDocument.header.meta = {
|
|
300
508
|
...newDocument.header.meta,
|
|
301
509
|
preferredEditor
|
|
302
510
|
};
|
|
511
|
+
markLocalDriveWrite(driveId);
|
|
303
512
|
let newDoc;
|
|
304
513
|
try {
|
|
305
|
-
newDoc = await reactorClient.drives.addFile(driveId, newDocument, parentFolder);
|
|
514
|
+
newDoc = await (await reactorClient.write.drives.addFile(driveId, newDocument, parentFolder)).document();
|
|
306
515
|
} catch (e) {
|
|
307
516
|
logger.error("Error adding document: @error", e);
|
|
308
517
|
throw new Error("There was an error adding document", { cause: e });
|
|
309
518
|
}
|
|
519
|
+
await rememberDriveNode(driveId, newDoc.header.id);
|
|
520
|
+
await getDriveNode(driveId, newDoc.header.id, { refresh: true }).catch(() => void 0);
|
|
310
521
|
return {
|
|
311
522
|
id: newDoc.header.id,
|
|
312
523
|
name: newDoc.header.name,
|
|
@@ -340,10 +551,25 @@ function isDocumentAlreadyExists(error) {
|
|
|
340
551
|
* under the same id and is resolved by minting another one. A create that
|
|
341
552
|
* fails leaves the drive untouched, so a retry has nothing to clean up.
|
|
342
553
|
*/
|
|
343
|
-
async function createImportedDocument(
|
|
344
|
-
|
|
554
|
+
async function createImportedDocument(write, document, driveId, name, parentFolder) {
|
|
555
|
+
const v2Required = signaturePolicyOf(document.header) === "v2-required";
|
|
556
|
+
const keepsId = (!v2Required || hasDerivedDocumentId(document.header)) && !await write.isDocumentIdTaken(document.header.id);
|
|
557
|
+
let documentId = keepsId ? document.header.id : generateId();
|
|
345
558
|
for (let attempt = 1;; attempt++) {
|
|
346
|
-
|
|
559
|
+
let header;
|
|
560
|
+
if (!v2Required) header = createPresignedHeader(documentId, document.header.documentType, document.header.protocolVersions);
|
|
561
|
+
else if (keepsId && attempt === 1) {
|
|
562
|
+
header = createPresignedHeader(documentId, document.header.documentType);
|
|
563
|
+
header.createdAtUtcIso = document.header.createdAtUtcIso;
|
|
564
|
+
header.sig = {
|
|
565
|
+
...header.sig,
|
|
566
|
+
nonce: document.header.sig.nonce
|
|
567
|
+
};
|
|
568
|
+
header.protocolVersions = { ...document.header.protocolVersions };
|
|
569
|
+
} else {
|
|
570
|
+
header = createCopyHeader(document.header);
|
|
571
|
+
documentId = header.id;
|
|
572
|
+
}
|
|
347
573
|
header.lastModifiedAtUtcIso = document.header.createdAtUtcIso;
|
|
348
574
|
header.meta = document.header.meta;
|
|
349
575
|
header.name = name || document.header.name;
|
|
@@ -372,7 +598,7 @@ async function createImportedDocument(reactor, document, driveId, name, parentFo
|
|
|
372
598
|
}
|
|
373
599
|
async function addFileWithProgress(file, driveId, name, parentFolder, onProgress, documentTypes, resolveConflict) {
|
|
374
600
|
logger.verbose(`addFileWithProgress(drive: ${driveId}, name: ${name}, folder: ${parentFolder})`);
|
|
375
|
-
const reactor =
|
|
601
|
+
const reactor = getFullReactorClient();
|
|
376
602
|
if (!reactor) {
|
|
377
603
|
onProgress?.({
|
|
378
604
|
stage: "failed",
|
|
@@ -406,7 +632,7 @@ async function addFileWithProgress(file, driveId, name, parentFolder, onProgress
|
|
|
406
632
|
});
|
|
407
633
|
return;
|
|
408
634
|
}
|
|
409
|
-
const discoveryService =
|
|
635
|
+
const discoveryService = getPHStore()?.packageDiscoveryService;
|
|
410
636
|
if (discoveryService && DocumentModelNotFoundError.isError(loadError)) {
|
|
411
637
|
retryAfterDiscovery(discoveryService, loadError.documentType, file, driveId, name, parentFolder, onProgress, documentTypes, resolveConflict).catch((retryError) => {
|
|
412
638
|
logger.error("Import retry after discovery failed: @error", retryError);
|
|
@@ -420,7 +646,7 @@ async function addFileWithProgress(file, driveId, name, parentFolder, onProgress
|
|
|
420
646
|
}
|
|
421
647
|
throw loadError;
|
|
422
648
|
}
|
|
423
|
-
const duplicateCheck = await isDocumentInLocation(reactor, document, driveId, parentFolder);
|
|
649
|
+
const duplicateCheck = await isDocumentInLocation(reactor.read, document, driveId, parentFolder);
|
|
424
650
|
if (duplicateCheck.isDuplicate && !resolveConflict) {
|
|
425
651
|
onProgress?.({
|
|
426
652
|
stage: "conflict",
|
|
@@ -447,19 +673,21 @@ async function addFileWithProgress(file, driveId, name, parentFolder, onProgress
|
|
|
447
673
|
});
|
|
448
674
|
throw new UnsupportedDocumentTypeError(document.header.documentType);
|
|
449
675
|
}
|
|
450
|
-
await reactor.getDocumentModelModule(document.header.documentType);
|
|
676
|
+
await reactor.read.getDocumentModelModule(document.header.documentType);
|
|
451
677
|
onProgress?.({
|
|
452
678
|
stage: "initializing",
|
|
453
679
|
progress: 10
|
|
454
680
|
});
|
|
455
|
-
|
|
681
|
+
markLocalDriveWrite(driveId);
|
|
682
|
+
const created = await createImportedDocument(reactor.write, document, driveId, name, parentFolder);
|
|
456
683
|
const documentId = created.documentId;
|
|
457
684
|
const fileNode = created.fileNode;
|
|
685
|
+
await rememberDriveNode(driveId, documentId);
|
|
458
686
|
onProgress?.({
|
|
459
687
|
stage: "initializing",
|
|
460
688
|
progress: 20
|
|
461
689
|
});
|
|
462
|
-
await reactor.get(documentId);
|
|
690
|
+
await reactor.read.get(documentId);
|
|
463
691
|
console.log("Document created, starting upload of operations");
|
|
464
692
|
const segments = splitAtUpgradeBoundaries(document.operations);
|
|
465
693
|
const totalOperations = segments.reduce((total, segment) => total + countOperations(segment.operations), 0);
|
|
@@ -514,93 +742,106 @@ async function retryAfterDiscovery(discoveryService, documentType, file, driveId
|
|
|
514
742
|
async function addFolder$1(driveId, name, parentFolder) {
|
|
515
743
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
516
744
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create folders");
|
|
517
|
-
const reactorClient =
|
|
745
|
+
const reactorClient = getPHStore()?.reactorClient;
|
|
518
746
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
519
|
-
await reactorClient.get(driveId);
|
|
747
|
+
await reactorClient.read.get(driveId);
|
|
520
748
|
const folderId = generateId();
|
|
521
|
-
|
|
749
|
+
markLocalDriveWrite(driveId);
|
|
750
|
+
await (await reactorClient.write.execute(driveId, "main", [addFolder({
|
|
522
751
|
id: folderId,
|
|
523
752
|
name,
|
|
524
753
|
parentFolder
|
|
525
|
-
})])).
|
|
754
|
+
})])).readable;
|
|
755
|
+
const node = await getDriveNode(driveId, folderId, { refresh: true });
|
|
526
756
|
if (!node || !isFolderNode(node)) throw new Error("There was an error adding folder");
|
|
527
757
|
return node;
|
|
528
758
|
}
|
|
529
759
|
async function deleteNode(driveId, nodeId) {
|
|
530
760
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
531
761
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to delete documents");
|
|
532
|
-
const reactorClient =
|
|
762
|
+
const reactorClient = getFullReactorClient();
|
|
533
763
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
534
|
-
|
|
764
|
+
markLocalDriveWrite(driveId);
|
|
765
|
+
await (await reactorClient.write.drives.removeNode(driveId, nodeId)).readable;
|
|
766
|
+
dropDriveNode(driveId, nodeId);
|
|
535
767
|
}
|
|
536
768
|
async function renameNode(driveId, nodeId, name) {
|
|
537
769
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
538
770
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to rename documents");
|
|
539
|
-
const reactorClient =
|
|
771
|
+
const reactorClient = getPHStore()?.reactorClient;
|
|
540
772
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
541
|
-
if ((await reactorClient.execute(nodeId, "main", [setName({ name })])).header.name !== name) throw new Error("There was an error renaming the node");
|
|
542
|
-
|
|
773
|
+
if ((await (await reactorClient.write.execute(nodeId, "main", [setName({ name })])).document()).header.name !== name) throw new Error("There was an error renaming the node");
|
|
774
|
+
markLocalDriveWrite(driveId);
|
|
775
|
+
await (await reactorClient.write.execute(driveId, "main", [updateNode({
|
|
543
776
|
id: nodeId,
|
|
544
777
|
name
|
|
545
|
-
})])).
|
|
778
|
+
})])).readable;
|
|
779
|
+
const node = await getDriveNode(driveId, nodeId, { refresh: true });
|
|
546
780
|
if (!node) throw new Error("There was an error renaming node in the drive");
|
|
547
781
|
return node;
|
|
548
782
|
}
|
|
549
783
|
async function renameDriveNode(driveId, nodeId, name) {
|
|
550
784
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
551
785
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to rename documents");
|
|
552
|
-
const reactorClient =
|
|
786
|
+
const reactorClient = getPHStore()?.reactorClient;
|
|
553
787
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
554
|
-
if ((await reactorClient.execute(nodeId, "main", [setName({ name })])).header.name !== name) throw new Error("There was an error renaming the node");
|
|
555
|
-
|
|
788
|
+
if ((await (await reactorClient.write.execute(nodeId, "main", [setName({ name })])).document()).header.name !== name) throw new Error("There was an error renaming the node");
|
|
789
|
+
markLocalDriveWrite(driveId);
|
|
790
|
+
await (await reactorClient.write.execute(driveId, "main", [updateNode({
|
|
556
791
|
id: nodeId,
|
|
557
792
|
name
|
|
558
|
-
})]);
|
|
559
|
-
return (
|
|
793
|
+
})])).readable;
|
|
794
|
+
return getDriveNode(driveId, nodeId, { refresh: true });
|
|
560
795
|
}
|
|
561
796
|
async function setPreferredEditorOnNode(nodeId, preferredEditor) {
|
|
562
797
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
563
798
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to modify documents");
|
|
564
|
-
const reactorClient =
|
|
799
|
+
const reactorClient = getPHStore()?.reactorClient;
|
|
565
800
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
566
|
-
return reactorClient.execute(nodeId, "main", [setPreferredEditor(preferredEditor)]);
|
|
801
|
+
return (await reactorClient.write.execute(nodeId, "main", [setPreferredEditor(preferredEditor)])).document();
|
|
567
802
|
}
|
|
568
803
|
async function moveNodeById(args) {
|
|
569
804
|
const { driveId, srcId, targetId } = args;
|
|
570
805
|
if (!driveId || !srcId) return;
|
|
571
806
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
572
807
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to move documents");
|
|
573
|
-
const reactorClient =
|
|
808
|
+
const reactorClient = getPHStore()?.reactorClient;
|
|
574
809
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
575
810
|
const targetParentFolder = conditional(targetId, [isNot(isDefined), constant(void 0)], [isStrictEqual(driveId), constant(void 0)], constant(targetId));
|
|
576
811
|
if (isStrictEqual(targetParentFolder, srcId)) return;
|
|
577
|
-
|
|
812
|
+
markLocalDriveWrite(driveId);
|
|
813
|
+
const moved = await (await reactorClient.write.execute(driveId, "main", [moveNode({
|
|
578
814
|
srcFolder: srcId,
|
|
579
815
|
targetParentFolder
|
|
580
|
-
})]);
|
|
816
|
+
})])).document();
|
|
817
|
+
await rememberDriveNode(driveId, srcId);
|
|
818
|
+
return moved;
|
|
581
819
|
}
|
|
582
820
|
async function moveNode$1(driveId, src, target) {
|
|
583
821
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
584
822
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to move documents");
|
|
585
|
-
const reactorClient =
|
|
823
|
+
const reactorClient = getPHStore()?.reactorClient;
|
|
586
824
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
587
|
-
|
|
825
|
+
markLocalDriveWrite(driveId);
|
|
826
|
+
const moved = await (await reactorClient.write.execute(driveId, "main", [moveNode({
|
|
588
827
|
srcFolder: src.id,
|
|
589
828
|
targetParentFolder: target?.id
|
|
590
|
-
})]);
|
|
829
|
+
})])).document();
|
|
830
|
+
await rememberDriveNode(driveId, src.id);
|
|
831
|
+
return moved;
|
|
591
832
|
}
|
|
592
833
|
/**
|
|
593
834
|
* Duplicates a document under a new id using version-aware replay.
|
|
594
835
|
* Falls back gracefully when no upgrade manifest is registered for the document type.
|
|
595
836
|
*/
|
|
596
|
-
async function _duplicateDocument(reactor, document, newId = generateId()) {
|
|
837
|
+
async function _duplicateDocument(reactor, document, newId = generateId(), driveId) {
|
|
597
838
|
const documentType = document.header.documentType;
|
|
598
839
|
const { results: allModules } = await reactor.getDocumentModelModules();
|
|
599
840
|
const modulesForType = allModules.filter((m) => m.documentModel.global.id === documentType);
|
|
600
841
|
const reducers = {};
|
|
601
842
|
for (const m of modulesForType) reducers[m.version ?? 1] = m.reducer;
|
|
602
843
|
if (Object.keys(reducers).length === 0) throw new Error(`Document model module not found for type: ${documentType}`);
|
|
603
|
-
const registry =
|
|
844
|
+
const registry = getPHStore()?.reactorClientModule?.reactorModule?.documentModelRegistry;
|
|
604
845
|
let upgradeManifest;
|
|
605
846
|
if (registry) try {
|
|
606
847
|
upgradeManifest = registry.getUpgradeManifest(documentType);
|
|
@@ -609,28 +850,39 @@ async function _duplicateDocument(reactor, document, newId = generateId()) {
|
|
|
609
850
|
reducers,
|
|
610
851
|
upgradeManifest
|
|
611
852
|
};
|
|
612
|
-
const
|
|
853
|
+
const selected = await reactor.getCreateProtocolVersions({
|
|
854
|
+
documentType: document.header.documentType,
|
|
855
|
+
parentIdentifier: driveId
|
|
856
|
+
});
|
|
857
|
+
const header = createCopyHeader({
|
|
858
|
+
documentType: document.header.documentType,
|
|
859
|
+
protocolVersions: document.header.protocolVersions ? {
|
|
860
|
+
...selected,
|
|
861
|
+
...document.header.protocolVersions
|
|
862
|
+
} : void 0
|
|
863
|
+
}, newId, await reactor.getCreateSignaturePolicy());
|
|
613
864
|
const duplicated = replayDocumentVersioned(document.initialState, document.operations, config, header);
|
|
614
865
|
assertAuthPreservedOnDuplicate(document.header.id, document.state.auth, duplicated.state.auth);
|
|
615
866
|
return duplicated;
|
|
616
867
|
}
|
|
617
868
|
async function copyNode$1(driveId, src, target) {
|
|
618
|
-
const reactor =
|
|
869
|
+
const reactor = getFullReactorClient();
|
|
619
870
|
if (!reactor) return;
|
|
620
871
|
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
621
872
|
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to copy documents");
|
|
622
|
-
const drive = await reactor.get(driveId);
|
|
873
|
+
const drive = await reactor.read.get(driveId);
|
|
874
|
+
const driveNodes = await listAllDriveNodes(reactor.read.drives, driveId);
|
|
623
875
|
const copyNodesInput = generateNodesCopy({
|
|
624
876
|
srcId: src.id,
|
|
625
877
|
targetParentFolder: target?.id,
|
|
626
878
|
targetName: src.name
|
|
627
|
-
}, () => generateId(),
|
|
879
|
+
}, () => generateId(), driveNodes);
|
|
628
880
|
const resolvedNamesMap = /* @__PURE__ */ new Map();
|
|
629
881
|
for (const copyNodeInput of copyNodesInput) {
|
|
630
|
-
const node =
|
|
882
|
+
const node = driveNodes.find((n) => n.id === copyNodeInput.srcId);
|
|
631
883
|
if (node) {
|
|
632
884
|
const resolvedName = handleTargetNameCollisions({
|
|
633
|
-
nodes:
|
|
885
|
+
nodes: driveNodes,
|
|
634
886
|
srcName: copyNodeInput.targetName || node.name,
|
|
635
887
|
srcKind: isFileNode(node) ? "file" : "folder",
|
|
636
888
|
targetParentFolder: copyNodeInput.targetParentFolder || null
|
|
@@ -639,28 +891,126 @@ async function copyNode$1(driveId, src, target) {
|
|
|
639
891
|
}
|
|
640
892
|
}
|
|
641
893
|
const fileNodesToCopy = copyNodesInput.filter((copyNodeInput) => {
|
|
642
|
-
const node =
|
|
894
|
+
const node = driveNodes.find((node) => node.id === copyNodeInput.srcId);
|
|
643
895
|
return node !== void 0 && isFileNode(node);
|
|
644
896
|
});
|
|
897
|
+
markLocalDriveWrite(driveId);
|
|
645
898
|
for (const fileNodeToCopy of fileNodesToCopy) try {
|
|
646
|
-
const
|
|
899
|
+
const document = await reactor.read.get(fileNodeToCopy.srcId);
|
|
900
|
+
const duplicatedDocument = await _duplicateDocument(reactor.read, document, fileNodeToCopy.targetId, driveId);
|
|
647
901
|
const resolvedName = resolvedNamesMap.get(fileNodeToCopy.targetId);
|
|
648
902
|
if (resolvedName) duplicatedDocument.header.name = resolvedName;
|
|
649
|
-
|
|
903
|
+
fileNodeToCopy.targetId = duplicatedDocument.header.id;
|
|
904
|
+
await (await reactor.write.drives.addFile(driveId, duplicatedDocument, target?.id)).readable;
|
|
650
905
|
} catch (e) {
|
|
651
906
|
logger.error(`Error copying document ${fileNodeToCopy.srcId}: ${String(e)}`);
|
|
652
907
|
}
|
|
653
|
-
|
|
908
|
+
const copyActions = copyNodesInput.map((copyNodeInput) => copyNode(copyNodeInput));
|
|
909
|
+
markLocalDriveWrite(driveId);
|
|
910
|
+
const copied = await queueActions(drive, copyActions);
|
|
911
|
+
invalidateDriveNodes(driveId);
|
|
912
|
+
return copied;
|
|
654
913
|
}
|
|
655
914
|
/**
|
|
656
915
|
* Upgrades a document to a newer document model version. Defaults to the
|
|
657
916
|
* latest registered version for the document's type.
|
|
658
917
|
*/
|
|
659
918
|
async function upgradeDocument(documentId, toVersion) {
|
|
660
|
-
const reactorClient =
|
|
919
|
+
const reactorClient = getFullReactorClient();
|
|
661
920
|
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
662
|
-
return reactorClient.upgradeDocument(documentId, toVersion);
|
|
921
|
+
return (await reactorClient.write.upgradeDocument(documentId, toVersion)).document();
|
|
922
|
+
}
|
|
923
|
+
//#endregion
|
|
924
|
+
//#region src/graphql-client/errors.ts
|
|
925
|
+
/** A call the Switchboard GraphQL surface cannot express. */
|
|
926
|
+
var GraphQLOperationNotSupportedError = class extends Error {
|
|
927
|
+
name = "GraphQLOperationNotSupportedError";
|
|
928
|
+
operation;
|
|
929
|
+
constructor(operation, reason) {
|
|
930
|
+
super(`GraphQLReactorClient.${operation} is not supported: ${reason}`);
|
|
931
|
+
this.operation = operation;
|
|
932
|
+
}
|
|
933
|
+
static isError(error) {
|
|
934
|
+
return Error.isError(error) && error.name === "GraphQLOperationNotSupportedError";
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
/**
|
|
938
|
+
* The Switchboard refused a request with 421 Misdirected Request: the
|
|
939
|
+
* `Drive-Id` it carried names a drive that Switchboard does not own.
|
|
940
|
+
*/
|
|
941
|
+
var GraphQLWrongBackendError = class extends Error {
|
|
942
|
+
name = "GraphQLWrongBackendError";
|
|
943
|
+
status = 421;
|
|
944
|
+
/** The drive the Switchboard refused, or `""` when its answer names none. */
|
|
945
|
+
driveId;
|
|
946
|
+
/** The response body, parsed when it is JSON. */
|
|
947
|
+
payload;
|
|
948
|
+
constructor(driveId, payload, options) {
|
|
949
|
+
super(`The Switchboard does not serve drive ${driveId === "" ? "(unnamed)" : driveId}: 421 Misdirected Request`, options);
|
|
950
|
+
this.driveId = driveId;
|
|
951
|
+
this.payload = payload;
|
|
952
|
+
}
|
|
953
|
+
static isError(error) {
|
|
954
|
+
return Error.isError(error) && error.name === "GraphQLWrongBackendError" && typeof error.driveId === "string";
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
/**
|
|
958
|
+
* The reactor's `BatchJobFailedError`, rebuilt from a batch result; this entry
|
|
959
|
+
* imports the reactor for types only. The shared name lets either `isError`
|
|
960
|
+
* recognise it.
|
|
961
|
+
*/
|
|
962
|
+
var BatchJobFailedError = class extends Error {
|
|
963
|
+
name = "BatchJobFailedError";
|
|
964
|
+
key;
|
|
965
|
+
jobs;
|
|
966
|
+
constructor(key, jobs) {
|
|
967
|
+
const failure = jobs[key].error;
|
|
968
|
+
const cause = new Error(failure?.message ?? "Job failed");
|
|
969
|
+
cause.name = failure?.name ?? "Error";
|
|
970
|
+
super(failure?.message ?? "Job failed", { cause });
|
|
971
|
+
this.key = key;
|
|
972
|
+
this.jobs = jobs;
|
|
973
|
+
}
|
|
974
|
+
static isError(error) {
|
|
975
|
+
return Error.isError(error) && error.name === "BatchJobFailedError" && typeof error.key === "string" && typeof error.jobs === "object";
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
/** A validation error naming root field `field` unknown: a host from before it. */
|
|
979
|
+
function queriesUnknownField(error, field) {
|
|
980
|
+
return hasErrorStarting(error, `Cannot query field "${field}" on type "`);
|
|
981
|
+
}
|
|
982
|
+
/** A validation error naming `argument` unknown: a host from before it. */
|
|
983
|
+
function queriesUnknownArgument(error, argument) {
|
|
984
|
+
return hasErrorStarting(error, `Unknown argument "${argument}" on field "`);
|
|
663
985
|
}
|
|
986
|
+
function hasErrorStarting(error, prefix) {
|
|
987
|
+
const errors = error?.response?.errors;
|
|
988
|
+
if (!Array.isArray(errors)) return false;
|
|
989
|
+
return errors.some((entry) => typeof entry?.message === "string" && entry.message.startsWith(prefix));
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* The reactor's `JobFailedError`, rebuilt from a job the Switchboard reported
|
|
993
|
+
* FAILED; this entry imports the reactor for types only. A write handle's
|
|
994
|
+
* stage rejects with it. The message is the job error's message, as the
|
|
995
|
+
* reactor's is.
|
|
996
|
+
*/
|
|
997
|
+
var JobFailedError = class extends Error {
|
|
998
|
+
name = "JobFailedError";
|
|
999
|
+
job;
|
|
1000
|
+
constructor(job) {
|
|
1001
|
+
super(job.error?.message);
|
|
1002
|
+
this.job = job;
|
|
1003
|
+
}
|
|
1004
|
+
static isError(error) {
|
|
1005
|
+
return Error.isError(error) && error.name === "JobFailedError" && typeof error.job === "object";
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
//#endregion
|
|
1009
|
+
//#region src/constants.ts
|
|
1010
|
+
const DEFAULT_DRIVE_EDITOR_ID = "powerhouse/generic-drive-explorer";
|
|
1011
|
+
const COMMON_PACKAGE_ID = "powerhouse/common";
|
|
1012
|
+
/** Document types that represent a "drive": a container of nodes. */
|
|
1013
|
+
const DRIVE_DOCUMENT_TYPES = ["powerhouse/document-drive", "powerhouse/reactor-drive"];
|
|
664
1014
|
//#endregion
|
|
665
1015
|
//#region src/remote-controller/utils.ts
|
|
666
1016
|
/** Convert SCREAMING_SNAKE_CASE to camelCase (e.g. "SET_MODEL_NAME" → "setModelName"). */
|
|
@@ -669,6 +1019,7 @@ function screamingSnakeToCamel(s) {
|
|
|
669
1019
|
}
|
|
670
1020
|
/** Error thrown when a push conflict is detected with the "reject" strategy. */
|
|
671
1021
|
var ConflictError = class extends Error {
|
|
1022
|
+
conflict;
|
|
672
1023
|
constructor(conflict) {
|
|
673
1024
|
super("Push conflict: remote has new operations since last pull");
|
|
674
1025
|
this.conflict = conflict;
|
|
@@ -712,7 +1063,11 @@ function convertRemoteOperations(operationsByScope) {
|
|
|
712
1063
|
for (const [scope, remoteOps] of Object.entries(operationsByScope)) operations[scope] = remoteOps.map((op) => remoteOperationToLocal(op));
|
|
713
1064
|
return operations;
|
|
714
1065
|
}
|
|
715
|
-
/**
|
|
1066
|
+
/**
|
|
1067
|
+
* Reconstruct a PHDocument from remote document data and operations; the
|
|
1068
|
+
* header carries the remote protocol versions. `initialDoc` supplies the rest
|
|
1069
|
+
* of the header, and the initial state when the operations do not record one.
|
|
1070
|
+
*/
|
|
716
1071
|
function buildPulledDocument(remoteDoc, operations, initialDoc, branch) {
|
|
717
1072
|
return {
|
|
718
1073
|
header: {
|
|
@@ -724,14 +1079,34 @@ function buildPulledDocument(remoteDoc, operations, initialDoc, branch) {
|
|
|
724
1079
|
createdAtUtcIso: typeof remoteDoc.createdAtUtcIso === "string" ? remoteDoc.createdAtUtcIso : remoteDoc.createdAtUtcIso.toISOString(),
|
|
725
1080
|
lastModifiedAtUtcIso: typeof remoteDoc.lastModifiedAtUtcIso === "string" ? remoteDoc.lastModifiedAtUtcIso : remoteDoc.lastModifiedAtUtcIso.toISOString(),
|
|
726
1081
|
revision: Object.fromEntries(remoteDoc.revisionsList.map((r) => [r.scope, r.revision])),
|
|
727
|
-
branch
|
|
1082
|
+
branch,
|
|
1083
|
+
...remoteDoc.protocolVersions != null ? { protocolVersions: remoteDoc.protocolVersions } : {}
|
|
728
1084
|
},
|
|
729
1085
|
state: remoteDoc.state,
|
|
730
|
-
initialState: initialDoc.initialState,
|
|
1086
|
+
initialState: creationState(operations.document ?? []) ?? initialDoc.initialState,
|
|
731
1087
|
operations,
|
|
732
1088
|
clipboard: []
|
|
733
1089
|
};
|
|
734
1090
|
}
|
|
1091
|
+
/** `document` as created: its header and initial state, without scope operations. */
|
|
1092
|
+
function uncreatedDocument(document) {
|
|
1093
|
+
const { header, initialState } = structuredClone({
|
|
1094
|
+
header: document.header,
|
|
1095
|
+
initialState: document.initialState
|
|
1096
|
+
});
|
|
1097
|
+
return {
|
|
1098
|
+
header,
|
|
1099
|
+
state: initialState,
|
|
1100
|
+
initialState,
|
|
1101
|
+
operations: {},
|
|
1102
|
+
clipboard: []
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
/** An uncreated `document` under `policy`; a legacy one keeps its id. */
|
|
1106
|
+
function underSignaturePolicy(document, policy) {
|
|
1107
|
+
if (signaturePolicyOf(document.header) === policy) return document;
|
|
1108
|
+
return withSignaturePolicy(document, policy, { id: document.header.id });
|
|
1109
|
+
}
|
|
735
1110
|
/** Extract revision map from a remote document's revisionsList. */
|
|
736
1111
|
function extractRevisionMap(revisionsList) {
|
|
737
1112
|
return Object.fromEntries(revisionsList.map((r) => [r.scope, r.revision]));
|
|
@@ -758,8 +1133,8 @@ function hasRevisionConflict(currentRevision, knownRevision, scopes) {
|
|
|
758
1133
|
* `createPresignedHeader`: the creation signature is not fetchable over
|
|
759
1134
|
* GraphQL and is not part of the operation signing payload.
|
|
760
1135
|
*
|
|
761
|
-
* The read path never fetches operation history, so `operations`
|
|
762
|
-
* the document's
|
|
1136
|
+
* The read path never fetches operation history, so `operations` maps each
|
|
1137
|
+
* scope of the document's state and revisions to an empty array.
|
|
763
1138
|
*
|
|
764
1139
|
* `branch` is the branch the document was read from. The GraphQL type does not
|
|
765
1140
|
* carry it, so it has to be passed back in by the caller; it defaults to the
|
|
@@ -771,7 +1146,7 @@ function phDocumentFromGetDocument(document, branch) {
|
|
|
771
1146
|
header: phDocumentHeaderFromGetDocument(document, branch),
|
|
772
1147
|
state,
|
|
773
1148
|
initialState: state,
|
|
774
|
-
operations: emptyOperationsForScopes(document.revisionsList),
|
|
1149
|
+
operations: emptyOperationsForScopes(state, document.revisionsList),
|
|
775
1150
|
clipboard: []
|
|
776
1151
|
};
|
|
777
1152
|
}
|
|
@@ -814,17 +1189,199 @@ function phDocumentHeaderFromGetDocument(document, branch) {
|
|
|
814
1189
|
name: document.name,
|
|
815
1190
|
branch: branch ?? defaultBranch,
|
|
816
1191
|
revision: revisionMapFromRevisionsList(document.revisionsList),
|
|
817
|
-
lastModifiedAtUtcIso: isoStringFromDateTime(document.lastModifiedAtUtcIso)
|
|
1192
|
+
lastModifiedAtUtcIso: isoStringFromDateTime(document.lastModifiedAtUtcIso),
|
|
1193
|
+
...document.meta != null ? { meta: document.meta } : {},
|
|
1194
|
+
...document.protocolVersions != null ? { protocolVersions: document.protocolVersions } : {}
|
|
818
1195
|
};
|
|
819
1196
|
}
|
|
820
|
-
function emptyOperationsForScopes(revisionsList) {
|
|
821
|
-
|
|
1197
|
+
function emptyOperationsForScopes(state, revisionsList) {
|
|
1198
|
+
const scopes = /* @__PURE__ */ new Set([...Object.keys(state), ...revisionsList.map((r) => r.scope)]);
|
|
1199
|
+
return Object.fromEntries([...scopes].map((scope) => [scope, []]));
|
|
822
1200
|
}
|
|
823
1201
|
/** The `DateTime` scalar deserializes as either an ISO string or a `Date`. */
|
|
824
1202
|
function isoStringFromDateTime(value) {
|
|
825
1203
|
return value instanceof Date ? value.toISOString() : value;
|
|
826
1204
|
}
|
|
827
1205
|
//#endregion
|
|
1206
|
+
//#region src/graphql-client/drive-nodes.ts
|
|
1207
|
+
/** Page size {@link GraphQLDriveNodeSource.listAll} reads a drive in. */
|
|
1208
|
+
const LIST_ALL_PAGE_LIMIT = 1e3;
|
|
1209
|
+
const DEFAULT_LIMIT$1 = 100;
|
|
1210
|
+
/**
|
|
1211
|
+
* The reactor subgraph's type-neutral node queries (`driveNodes`, `driveNode`,
|
|
1212
|
+
* `driveDescendants`) as an {@link IDriveNodeSource}, so a browser reads a
|
|
1213
|
+
* legacy drive and a reactor-drive alike. The Switchboard serves only the
|
|
1214
|
+
* nodes the caller may read. Drive ids must be canonical ids, not slugs.
|
|
1215
|
+
*/
|
|
1216
|
+
var GraphQLDriveNodeSource = class {
|
|
1217
|
+
queries;
|
|
1218
|
+
headersFor;
|
|
1219
|
+
constructor(queries, headersFor = () => void 0) {
|
|
1220
|
+
this.queries = queries;
|
|
1221
|
+
this.headersFor = headersFor;
|
|
1222
|
+
}
|
|
1223
|
+
async getNode(driveId, nodeId, signal) {
|
|
1224
|
+
const result = await this.queries.GetDriveNode({
|
|
1225
|
+
driveId,
|
|
1226
|
+
id: nodeId
|
|
1227
|
+
}, this.headersFor(driveId), signal);
|
|
1228
|
+
return result.driveNode ? toRecord(result.driveNode) : void 0;
|
|
1229
|
+
}
|
|
1230
|
+
async listChildren(driveId, parentFolder, paging, signal, kind) {
|
|
1231
|
+
const cursor = startCursor(paging?.cursor);
|
|
1232
|
+
const page = (await this.queries.GetDriveNodes({
|
|
1233
|
+
driveId,
|
|
1234
|
+
...parentFolder === void 0 ? {} : { parentFolder },
|
|
1235
|
+
paging: paging ? {
|
|
1236
|
+
cursor,
|
|
1237
|
+
limit: paging.limit
|
|
1238
|
+
} : void 0,
|
|
1239
|
+
kind: kind === void 0 ? void 0 : kind === "file" ? "FILE" : "FOLDER"
|
|
1240
|
+
}, this.headersFor(driveId), signal)).driveNodes;
|
|
1241
|
+
const nextCursor = page.hasMore ? page.nextCursor ?? void 0 : void 0;
|
|
1242
|
+
return {
|
|
1243
|
+
results: page.results.map(toRecord),
|
|
1244
|
+
options: {
|
|
1245
|
+
cursor,
|
|
1246
|
+
limit: paging?.limit ?? DEFAULT_LIMIT$1
|
|
1247
|
+
},
|
|
1248
|
+
...nextCursor !== void 0 ? { nextCursor } : {}
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
async getDescendants(driveId, root, signal) {
|
|
1252
|
+
return (await this.queries.GetDriveDescendants({
|
|
1253
|
+
driveId,
|
|
1254
|
+
root
|
|
1255
|
+
}, this.headersFor(driveId), signal)).driveDescendants.map(toRecord);
|
|
1256
|
+
}
|
|
1257
|
+
async listAll(driveId, signal) {
|
|
1258
|
+
const nodes = [];
|
|
1259
|
+
let cursor = "";
|
|
1260
|
+
for (;;) {
|
|
1261
|
+
const page = await this.listChildren(driveId, void 0, {
|
|
1262
|
+
cursor,
|
|
1263
|
+
limit: LIST_ALL_PAGE_LIMIT
|
|
1264
|
+
}, signal);
|
|
1265
|
+
nodes.push(...page.results);
|
|
1266
|
+
if (page.nextCursor === void 0 || page.nextCursor === cursor) return nodes;
|
|
1267
|
+
cursor = page.nextCursor;
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
/**
|
|
1272
|
+
* `read.drives` over a node source: the reactor's {@link IDriveReadClient},
|
|
1273
|
+
* answering in the legacy `Node` shape for every drive type.
|
|
1274
|
+
*/
|
|
1275
|
+
var GraphQLDriveReadClient = class {
|
|
1276
|
+
nodes;
|
|
1277
|
+
constructor(nodes) {
|
|
1278
|
+
this.nodes = nodes;
|
|
1279
|
+
}
|
|
1280
|
+
async getNode(driveIdentifier, nodeId, signal) {
|
|
1281
|
+
const record = await this.nodes.getNode(driveIdentifier, nodeId, signal);
|
|
1282
|
+
if (!record) throw new Error(`Node ${nodeId} not found in drive ${driveIdentifier}`);
|
|
1283
|
+
return toLegacyNode(record);
|
|
1284
|
+
}
|
|
1285
|
+
async listNodes(driveIdentifier, parentFolder, paging, signal) {
|
|
1286
|
+
const page = await this.nodes.listChildren(driveIdentifier, parentFolder, paging, signal);
|
|
1287
|
+
const nextCursor = page.nextCursor;
|
|
1288
|
+
return {
|
|
1289
|
+
results: page.results.map(toLegacyNode),
|
|
1290
|
+
options: page.options,
|
|
1291
|
+
...nextCursor !== void 0 ? {
|
|
1292
|
+
nextCursor,
|
|
1293
|
+
next: () => this.listNodes(driveIdentifier, parentFolder, {
|
|
1294
|
+
cursor: nextCursor,
|
|
1295
|
+
limit: page.options.limit
|
|
1296
|
+
}, signal)
|
|
1297
|
+
} : {}
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
1301
|
+
/** A node record in the legacy `Node` shape. */
|
|
1302
|
+
function toLegacyNode(node) {
|
|
1303
|
+
if (node.kind === "file") return {
|
|
1304
|
+
id: node.id,
|
|
1305
|
+
kind: "file",
|
|
1306
|
+
name: node.name,
|
|
1307
|
+
parentFolder: node.parentFolder,
|
|
1308
|
+
documentType: node.documentType ?? ""
|
|
1309
|
+
};
|
|
1310
|
+
return {
|
|
1311
|
+
id: node.id,
|
|
1312
|
+
kind: "folder",
|
|
1313
|
+
name: node.name,
|
|
1314
|
+
parentFolder: node.parentFolder
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
function toRecord(node) {
|
|
1318
|
+
const base = {
|
|
1319
|
+
id: node.id,
|
|
1320
|
+
driveId: node.driveId,
|
|
1321
|
+
name: node.name,
|
|
1322
|
+
parentFolder: node.parentFolder ?? null
|
|
1323
|
+
};
|
|
1324
|
+
return "documentType" in node ? {
|
|
1325
|
+
...base,
|
|
1326
|
+
kind: "file",
|
|
1327
|
+
documentType: node.documentType
|
|
1328
|
+
} : {
|
|
1329
|
+
...base,
|
|
1330
|
+
kind: "folder"
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
/** The offset-style "0" other listings start from means the first page here too. */
|
|
1334
|
+
function startCursor(cursor) {
|
|
1335
|
+
return cursor === void 0 || cursor === "0" ? "" : cursor;
|
|
1336
|
+
}
|
|
1337
|
+
//#endregion
|
|
1338
|
+
//#region src/graphql-client/create-defaults.ts
|
|
1339
|
+
/** The host's policy for a new document; a host without `createDefaults` is refused, as a guess could under-sign. */
|
|
1340
|
+
async function readCreateSignaturePolicy(sdk, signal) {
|
|
1341
|
+
const defaults = await readCreateDefaults(sdk, void 0, signal);
|
|
1342
|
+
if (defaults === void 0) throw new GraphQLOperationNotSupportedError("getCreateSignaturePolicy", "the Switchboard predates the createDefaults query");
|
|
1343
|
+
const { signaturePolicy } = defaults;
|
|
1344
|
+
if (!isSignaturePolicy(signaturePolicy)) throw new Error(`The Switchboard answered an unknown create signature policy: ${signaturePolicy}`);
|
|
1345
|
+
return signaturePolicy;
|
|
1346
|
+
}
|
|
1347
|
+
/** The host's per-type selection, capped at what this build runs and fitted to `modules`; baseline from an old host. */
|
|
1348
|
+
async function readCreateProtocolVersions(sdk, { documentType, parentIdentifier }, modules, signal) {
|
|
1349
|
+
const host = await hostCreateProtocolVersions(sdk, documentType, parentIdentifier, signal);
|
|
1350
|
+
return capSelection(host, PEER_CAPABILITIES, localSupports(PEER_CAPABILITIES, {}));
|
|
1351
|
+
}
|
|
1352
|
+
/** The Switchboard's selection; undefined from a host without `createDefaults`. */
|
|
1353
|
+
async function hostCreateProtocolVersions(sdk, documentType, parentIdentifier, signal) {
|
|
1354
|
+
if (documentType !== void 0) try {
|
|
1355
|
+
return protocolVersionsFrom((await sdk.GetCreateProtocolVersions({
|
|
1356
|
+
documentType,
|
|
1357
|
+
parentIdOrSlug: parentIdentifier
|
|
1358
|
+
}, void 0, signal)).createDefaults.protocolVersions);
|
|
1359
|
+
} catch (error) {
|
|
1360
|
+
if (queriesUnknownField(error, "createDefaults")) return void 0;
|
|
1361
|
+
if (!queriesUnknownArgument(error, "documentType")) throw error;
|
|
1362
|
+
}
|
|
1363
|
+
const defaults = await readCreateDefaults(sdk, parentIdentifier, signal);
|
|
1364
|
+
return defaults && protocolVersionsFrom(defaults.protocolVersions);
|
|
1365
|
+
}
|
|
1366
|
+
/** The reactor-wide `createDefaults`; undefined from a host without the query. */
|
|
1367
|
+
async function readCreateDefaults(sdk, parentIdentifier, signal) {
|
|
1368
|
+
try {
|
|
1369
|
+
return (await sdk.GetCreateDefaults({ parentIdOrSlug: parentIdentifier }, void 0, signal)).createDefaults;
|
|
1370
|
+
} catch (error) {
|
|
1371
|
+
if (queriesUnknownField(error, "createDefaults")) return;
|
|
1372
|
+
throw error;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
function protocolVersionsFrom(value) {
|
|
1376
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("The Switchboard answered malformed create protocol versions");
|
|
1377
|
+
const versions = {};
|
|
1378
|
+
for (const [protocol, version] of Object.entries(value)) {
|
|
1379
|
+
if (typeof version !== "number" || !Number.isInteger(version)) throw new Error(`The Switchboard answered a malformed version for protocol ${protocol}`);
|
|
1380
|
+
versions[protocol] = version;
|
|
1381
|
+
}
|
|
1382
|
+
return versions;
|
|
1383
|
+
}
|
|
1384
|
+
//#endregion
|
|
828
1385
|
//#region src/graphql-client/operations.ts
|
|
829
1386
|
/**
|
|
830
1387
|
* The operation selection of `GetDocumentOperations`, lifted into a fragment so
|
|
@@ -913,6 +1470,27 @@ const MutateDocumentWithOperationsDocument = gql`
|
|
|
913
1470
|
${PhDocumentFieldsFragmentDoc}
|
|
914
1471
|
${ReactorOperationFieldsFragmentDoc}
|
|
915
1472
|
`;
|
|
1473
|
+
/**
|
|
1474
|
+
* `document`, bounded by a consistency token: the read waits until the
|
|
1475
|
+
* Switchboard's read models hold every operation the token names. The
|
|
1476
|
+
* `consistency` argument is additive on the Switchboard; one without it refuses
|
|
1477
|
+
* this document, and the client falls back to the plain `GetDocument`.
|
|
1478
|
+
*/
|
|
1479
|
+
const GetDocumentAtConsistencyDocument = gql`
|
|
1480
|
+
query GetDocumentAtConsistency(
|
|
1481
|
+
$identifier: String!
|
|
1482
|
+
$view: ViewFilterInput
|
|
1483
|
+
$consistency: ConsistencyTokenInput
|
|
1484
|
+
) {
|
|
1485
|
+
document(identifier: $identifier, view: $view, consistency: $consistency) {
|
|
1486
|
+
document {
|
|
1487
|
+
...PHDocumentFields
|
|
1488
|
+
}
|
|
1489
|
+
childIds
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
${PhDocumentFieldsFragmentDoc}
|
|
1493
|
+
`;
|
|
916
1494
|
//#endregion
|
|
917
1495
|
//#region src/graphql-client/signing.ts
|
|
918
1496
|
/**
|
|
@@ -941,43 +1519,42 @@ function stampAction(action, document, revision = document.header.revision[actio
|
|
|
941
1519
|
};
|
|
942
1520
|
}
|
|
943
1521
|
/**
|
|
944
|
-
* Signs a stamped action
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
*/
|
|
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);
|
|
1522
|
+
* Signs a stamped action for `target`, keeping any signatures it already
|
|
1523
|
+
* carries. The signer reads `context.prevOpHash`, so this runs after
|
|
1524
|
+
* {@link stampAction}. A v2 tuple covers the signer's identity, so the context
|
|
1525
|
+
* takes the signer's user and app even when the action named others.
|
|
1526
|
+
*/
|
|
1527
|
+
async function signStampedAction(action, signer, target, signal) {
|
|
1528
|
+
if (!signer.user || !signer.app) throw new Error("cannot sign an action: the signer has no user or app identity");
|
|
1529
|
+
const signature = await signer.signAction(action, target, signal);
|
|
955
1530
|
return {
|
|
956
1531
|
...action,
|
|
957
1532
|
context: {
|
|
958
1533
|
...action.context,
|
|
959
1534
|
signer: {
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
signatures: [...actionSigner?.signatures ?? [], signature]
|
|
1535
|
+
...actionSignerIdentity(signer),
|
|
1536
|
+
signatures: [...action.context?.signer?.signatures ?? [], signature]
|
|
963
1537
|
}
|
|
964
1538
|
}
|
|
965
1539
|
};
|
|
966
1540
|
}
|
|
1541
|
+
/** The log a snapshot's action is written to; the snapshot names the branch read. */
|
|
1542
|
+
function snapshotTarget(action, snapshot) {
|
|
1543
|
+
return actionSigningTarget(action, snapshot.header.id, snapshot.header.branch || "main");
|
|
1544
|
+
}
|
|
967
1545
|
/**
|
|
968
1546
|
* Actions a snapshot batch cannot predict the next state for.
|
|
969
1547
|
*
|
|
970
|
-
* `UNDO
|
|
971
|
-
*
|
|
1548
|
+
* `UNDO` and `REDO` rewrite history the light read path never fetched (and
|
|
1549
|
+
* the reducer appends no operation for them); `NOOP` is only ever produced
|
|
972
1550
|
* by an undo chain; the document-scope actions run through the reactor's
|
|
973
1551
|
* document-action handler rather than a document-model reducer
|
|
974
1552
|
* (`DOCUMENT_SCOPE_ACTIONS` in packages/reactor/src/executor/util.ts) and
|
|
975
1553
|
* `UPGRADE_DOCUMENT` changes which reducer applies mid-batch.
|
|
976
1554
|
*/
|
|
977
|
-
const unsupportedBatchActions = new Set([
|
|
1555
|
+
const unsupportedBatchActions = /* @__PURE__ */ new Set([
|
|
978
1556
|
"UNDO",
|
|
979
1557
|
"REDO",
|
|
980
|
-
"PRUNE",
|
|
981
1558
|
"NOOP",
|
|
982
1559
|
"CREATE_DOCUMENT",
|
|
983
1560
|
"DELETE_DOCUMENT",
|
|
@@ -991,9 +1568,9 @@ const unsupportedBatchActions = new Set([
|
|
|
991
1568
|
* carries none.
|
|
992
1569
|
*
|
|
993
1570
|
* `baseReducer` reads `baseReducerVersion(document.header)` for every action and
|
|
994
|
-
* throws when the header has no `protocolVersions
|
|
995
|
-
* {@link phDocumentFromGetDocument}
|
|
996
|
-
*
|
|
1571
|
+
* throws when the header has no `protocolVersions`, which a header built by
|
|
1572
|
+
* {@link phDocumentFromGetDocument} lacks when the server sends none. The
|
|
1573
|
+
* version only selects between the v1
|
|
997
1574
|
* and v2 UNDO/NOOP branches, and every action reaching the prediction loop is an
|
|
998
1575
|
* ordinary append-only one, so it cannot change the predicted state here; it is
|
|
999
1576
|
* passed purely so the lookup does not throw.
|
|
@@ -1020,7 +1597,7 @@ const predictionProtocolVersion = 2;
|
|
|
1020
1597
|
*/
|
|
1021
1598
|
async function prepareSignedActions(actions, snapshot, signer, module, signal) {
|
|
1022
1599
|
if (actions.length === 0) return [];
|
|
1023
|
-
if (actions.length === 1) return [await signStampedAction(stampAction(actions[0], snapshot), signer, signal)];
|
|
1600
|
+
if (actions.length === 1) return [await signStampedAction(stampAction(actions[0], snapshot), signer, snapshotTarget(actions[0], snapshot), signal)];
|
|
1024
1601
|
const scope = sharedScope(actions);
|
|
1025
1602
|
assertSupportedBatch(actions);
|
|
1026
1603
|
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 +1612,8 @@ async function prepareSignedActions(actions, snapshot, signer, module, signal) {
|
|
|
1035
1612
|
const signed = [];
|
|
1036
1613
|
for (const [index, action] of actions.entries()) {
|
|
1037
1614
|
throwIfAborted(signal, index);
|
|
1038
|
-
const
|
|
1615
|
+
const stamped = stampAction(action, working, revision);
|
|
1616
|
+
const signedAction = await signStampedAction(stamped, signer, snapshotTarget(stamped, snapshot), signal);
|
|
1039
1617
|
signed.push(signedAction);
|
|
1040
1618
|
const before = scopeOperationCount(working, scope);
|
|
1041
1619
|
let next;
|
|
@@ -1344,6 +1922,45 @@ function startDocumentChangesSubscription(options) {
|
|
|
1344
1922
|
};
|
|
1345
1923
|
}
|
|
1346
1924
|
/**
|
|
1925
|
+
* Opens the socket write handles wait on. `graphql-ws` multiplexes every
|
|
1926
|
+
* watched job over it and closes it once the last watch stops.
|
|
1927
|
+
*/
|
|
1928
|
+
function createJobChangesSocket(options) {
|
|
1929
|
+
let client;
|
|
1930
|
+
const clientOf = () => client ??= createClient({
|
|
1931
|
+
url: options.wsUrl,
|
|
1932
|
+
connectionParams: options.connectionParams,
|
|
1933
|
+
shouldRetry: (errOrCloseEvent) => isLikeCloseEvent(errOrCloseEvent) && !isAuthRefusalClose(errOrCloseEvent)
|
|
1934
|
+
});
|
|
1935
|
+
return {
|
|
1936
|
+
watch(jobId, onEvent, onError) {
|
|
1937
|
+
const unsubscribe = clientOf().subscribe({
|
|
1938
|
+
operationName: "JobChanges",
|
|
1939
|
+
query: print(JobChangesDocument),
|
|
1940
|
+
variables: { jobId }
|
|
1941
|
+
}, {
|
|
1942
|
+
next: (result) => {
|
|
1943
|
+
const event = result.data?.jobChanges;
|
|
1944
|
+
if (event) onEvent(event);
|
|
1945
|
+
},
|
|
1946
|
+
error: (error) => onError(error),
|
|
1947
|
+
complete: () => void 0
|
|
1948
|
+
});
|
|
1949
|
+
let stopped = false;
|
|
1950
|
+
return () => {
|
|
1951
|
+
if (stopped) return;
|
|
1952
|
+
stopped = true;
|
|
1953
|
+
unsubscribe();
|
|
1954
|
+
};
|
|
1955
|
+
},
|
|
1956
|
+
dispose() {
|
|
1957
|
+
const current = client;
|
|
1958
|
+
client = void 0;
|
|
1959
|
+
current?.dispose();
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
/**
|
|
1347
1964
|
* Derives the websocket endpoint from the GraphQL http endpoint.
|
|
1348
1965
|
*
|
|
1349
1966
|
* `http://host/graphql` becomes `ws://host/graphql/subscriptions`, which is
|
|
@@ -1369,12 +1986,157 @@ function makeAuthConnectionParams(tokenProvider) {
|
|
|
1369
1986
|
};
|
|
1370
1987
|
}
|
|
1371
1988
|
//#endregion
|
|
1989
|
+
//#region src/graphql-client/write-handles.ts
|
|
1990
|
+
/** Whether a job status has reached a stage, FAILED counting as settled. */
|
|
1991
|
+
function settlesGraphQLJobStage(status, stage) {
|
|
1992
|
+
const value = status;
|
|
1993
|
+
if (value === "FAILED" || value === "READ_READY") return true;
|
|
1994
|
+
return stage === "written" && value === "WRITE_READY";
|
|
1995
|
+
}
|
|
1996
|
+
function emptyToken() {
|
|
1997
|
+
return {
|
|
1998
|
+
version: 1,
|
|
1999
|
+
createdAtUtcIso: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2000
|
+
coordinates: []
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
function abortError(signal) {
|
|
2004
|
+
const reason = signal.reason;
|
|
2005
|
+
return reason instanceof Error ? reason : new Error(String(reason));
|
|
2006
|
+
}
|
|
2007
|
+
/** `promise`, rejected early when `signal` aborts. */
|
|
2008
|
+
function bounded(promise, signal) {
|
|
2009
|
+
if (!signal) return promise;
|
|
2010
|
+
if (signal.aborted) return Promise.reject(abortError(signal));
|
|
2011
|
+
return new Promise((resolve, reject) => {
|
|
2012
|
+
const onAbort = () => reject(abortError(signal));
|
|
2013
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2014
|
+
promise.then((value) => {
|
|
2015
|
+
signal.removeEventListener("abort", onAbort);
|
|
2016
|
+
resolve(value);
|
|
2017
|
+
}, (error) => {
|
|
2018
|
+
signal.removeEventListener("abort", onAbort);
|
|
2019
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2020
|
+
});
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
/**
|
|
2024
|
+
* A write handle over a job the Switchboard accepted (`executeAsync`).
|
|
2025
|
+
*
|
|
2026
|
+
* Each stage is the waiter's: `jobStatus`, woken early by the `jobChanges`
|
|
2027
|
+
* subscription when the client has realtime. Stage promises are created on
|
|
2028
|
+
* first access, so a fire-and-forget caller never owns a rejection. A FAILED
|
|
2029
|
+
* job rejects a stage with {@link JobFailedError}.
|
|
2030
|
+
*
|
|
2031
|
+
* `document()` with no view is read once and shared, so the client's own
|
|
2032
|
+
* change announcement and the caller's read-back cost one request.
|
|
2033
|
+
*/
|
|
2034
|
+
var GraphQLJobWriteHandle = class {
|
|
2035
|
+
jobId;
|
|
2036
|
+
documentId;
|
|
2037
|
+
branch;
|
|
2038
|
+
wait;
|
|
2039
|
+
reader;
|
|
2040
|
+
signal;
|
|
2041
|
+
writtenReceipt;
|
|
2042
|
+
readableReceipt;
|
|
2043
|
+
defaultDocument;
|
|
2044
|
+
constructor(job, documentId, branch, wait, reader, signal) {
|
|
2045
|
+
this.jobId = job.id;
|
|
2046
|
+
this.documentId = documentId;
|
|
2047
|
+
this.branch = branch;
|
|
2048
|
+
this.wait = wait;
|
|
2049
|
+
this.reader = reader;
|
|
2050
|
+
this.signal = signal;
|
|
2051
|
+
}
|
|
2052
|
+
get written() {
|
|
2053
|
+
this.writtenReceipt ??= this.receiptAt("written");
|
|
2054
|
+
return this.writtenReceipt;
|
|
2055
|
+
}
|
|
2056
|
+
get readable() {
|
|
2057
|
+
this.readableReceipt ??= this.receiptAt("readable");
|
|
2058
|
+
return this.readableReceipt;
|
|
2059
|
+
}
|
|
2060
|
+
async document(view, signal) {
|
|
2061
|
+
if (view !== void 0) {
|
|
2062
|
+
const receipt = await bounded(this.readable, signal);
|
|
2063
|
+
return this.reader(receipt, view, signal);
|
|
2064
|
+
}
|
|
2065
|
+
this.defaultDocument ??= this.readable.then((receipt) => this.reader(receipt, void 0, void 0));
|
|
2066
|
+
return bounded(this.defaultDocument, signal);
|
|
2067
|
+
}
|
|
2068
|
+
async receiptAt(stage) {
|
|
2069
|
+
const job = await this.wait(this.jobId, stage, this.signal);
|
|
2070
|
+
if (job.status === "FAILED") throw new JobFailedError(job);
|
|
2071
|
+
return {
|
|
2072
|
+
job,
|
|
2073
|
+
token: job.consistencyToken,
|
|
2074
|
+
documentId: this.documentId,
|
|
2075
|
+
branch: this.branch
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
};
|
|
2079
|
+
/**
|
|
2080
|
+
* A write handle for a write the Switchboard applied before answering: the
|
|
2081
|
+
* synchronous `createDocument` and `deleteDocument` mutations name no job. Both
|
|
2082
|
+
* stages are settled; `jobId` is empty and the receipt's job is a READ_READY
|
|
2083
|
+
* placeholder with an empty token, as the reactor's own settled handle has.
|
|
2084
|
+
*/
|
|
2085
|
+
var GraphQLSettledWriteHandle = class {
|
|
2086
|
+
jobId = "";
|
|
2087
|
+
documentId;
|
|
2088
|
+
branch;
|
|
2089
|
+
receipt;
|
|
2090
|
+
reader;
|
|
2091
|
+
constructor(documentId, branch, reader) {
|
|
2092
|
+
this.documentId = documentId;
|
|
2093
|
+
this.branch = branch;
|
|
2094
|
+
this.reader = reader;
|
|
2095
|
+
const token = emptyToken();
|
|
2096
|
+
this.receipt = {
|
|
2097
|
+
job: {
|
|
2098
|
+
id: "",
|
|
2099
|
+
documentId,
|
|
2100
|
+
status: "READ_READY",
|
|
2101
|
+
createdAtUtcIso: token.createdAtUtcIso,
|
|
2102
|
+
consistencyToken: token,
|
|
2103
|
+
meta: {
|
|
2104
|
+
batchId: "",
|
|
2105
|
+
batchJobIds: []
|
|
2106
|
+
}
|
|
2107
|
+
},
|
|
2108
|
+
token,
|
|
2109
|
+
documentId,
|
|
2110
|
+
branch
|
|
2111
|
+
};
|
|
2112
|
+
}
|
|
2113
|
+
get written() {
|
|
2114
|
+
return Promise.resolve(this.receipt);
|
|
2115
|
+
}
|
|
2116
|
+
get readable() {
|
|
2117
|
+
return Promise.resolve(this.receipt);
|
|
2118
|
+
}
|
|
2119
|
+
document(view, signal) {
|
|
2120
|
+
return this.reader(this.receipt, view, signal);
|
|
2121
|
+
}
|
|
2122
|
+
};
|
|
2123
|
+
//#endregion
|
|
1372
2124
|
//#region src/graphql-client/graphql-reactor-client.ts
|
|
2125
|
+
const BUILT_IN_MODELS = [driveDocumentModelModule];
|
|
1373
2126
|
/** Paging defaults, matching the reactor's own client. */
|
|
1374
2127
|
const defaultPaging = {
|
|
1375
2128
|
cursor: "0",
|
|
1376
2129
|
limit: 100
|
|
1377
2130
|
};
|
|
2131
|
+
const JOB_POLL_INTERVAL_MS = 250;
|
|
2132
|
+
/** The first `jobStatus` poll of a write handle's stage wait, doubling from here. */
|
|
2133
|
+
const STAGE_POLL_START_MS = 25;
|
|
2134
|
+
/**
|
|
2135
|
+
* The longest a stage wait sleeps between `jobStatus` polls while the
|
|
2136
|
+
* `jobChanges` subscription is up: the subscription wakes it early, and the
|
|
2137
|
+
* poll is the safety net for an event that raced the subscription.
|
|
2138
|
+
*/
|
|
2139
|
+
const STAGE_POLL_REALTIME_MAX_MS = 1e3;
|
|
1378
2140
|
/**
|
|
1379
2141
|
* The marker {@link isGraphQLReactorClient} looks for.
|
|
1380
2142
|
*
|
|
@@ -1401,30 +2163,153 @@ var GraphQLReactorClient = class {
|
|
|
1401
2163
|
subscriptionsUrl;
|
|
1402
2164
|
documentModels;
|
|
1403
2165
|
signer;
|
|
2166
|
+
driveIdFor;
|
|
1404
2167
|
stopRealtime;
|
|
1405
2168
|
realtimeStarted = false;
|
|
1406
2169
|
realtimeGeneration = 0;
|
|
1407
2170
|
realtimeErrorLogged = false;
|
|
1408
2171
|
/** Whether the last socket died because the Switchboard refused its credentials. */
|
|
1409
2172
|
realtimeRefusedCredentials = false;
|
|
2173
|
+
/** The socket write handles wait on; opened by the first stage wait. */
|
|
2174
|
+
jobSocket;
|
|
2175
|
+
/** Set once the `jobChanges` subscription failed; stage waits then only poll. */
|
|
2176
|
+
jobRealtimeBroken = false;
|
|
2177
|
+
/** Set once the Switchboard refused the `document` query's `consistency` argument. */
|
|
2178
|
+
consistencyUnsupported = false;
|
|
2179
|
+
driveNodes;
|
|
2180
|
+
/**
|
|
2181
|
+
* The read half: the reads the hooks make. Every method is this client's
|
|
2182
|
+
* own; nothing that writes is reachable from it.
|
|
2183
|
+
*/
|
|
2184
|
+
read;
|
|
2185
|
+
/**
|
|
2186
|
+
* The write half. `execute` submits through `executeAsync` and hands back a
|
|
2187
|
+
* handle whose `written` and `readable` resolve from `jobStatus`, woken by
|
|
2188
|
+
* the `jobChanges` subscription when realtime is on, and whose `document()`
|
|
2189
|
+
* runs the `document` query bounded by the receipt's token. `create` and
|
|
2190
|
+
* `deleteDocument` have no asynchronous mutation: they run the synchronous
|
|
2191
|
+
* ones and hand back a settled handle.
|
|
2192
|
+
*/
|
|
2193
|
+
write;
|
|
1410
2194
|
constructor(options) {
|
|
1411
2195
|
this.tokenProvider = options.tokenProvider ?? ambientRenownTokenProvider;
|
|
1412
|
-
|
|
2196
|
+
const models = options.documentModels;
|
|
2197
|
+
if (typeof models === "function") this.documentModels = models;
|
|
2198
|
+
else {
|
|
2199
|
+
const copied = [...models ?? []];
|
|
2200
|
+
this.documentModels = () => copied;
|
|
2201
|
+
}
|
|
1413
2202
|
this.signer = options.signer;
|
|
2203
|
+
this.driveIdFor = options.driveIdFor;
|
|
1414
2204
|
this.subscriptionsUrl = options.realtime === false ? void 0 : options.subscriptionsUrl ?? subscriptionsUrlFromGraphqlUrl(options.url);
|
|
1415
|
-
const middleware = makeAuthMiddleware(this.tokenProvider);
|
|
2205
|
+
const middleware = withWrongBackendErrors(makeAuthMiddleware(this.tokenProvider));
|
|
1416
2206
|
this.sdk = options.graphqlClient ?? createClient$1(options.url, middleware);
|
|
1417
2207
|
this.subgraphs = new SubgraphSdkRegistry(options.url, middleware);
|
|
2208
|
+
this.driveNodes = new GraphQLDriveNodeSource(this.sdk, driveIdHeaders);
|
|
2209
|
+
this.read = new GraphQLReadHalf(this, this.driveNodes);
|
|
2210
|
+
this.write = {
|
|
2211
|
+
execute: (documentIdentifier, branch, actions, signal) => this.submitExecute(documentIdentifier, branch, actions, signal),
|
|
2212
|
+
create: (document, parentIdentifier, signal) => this.submitCreate(document, parentIdentifier, signal),
|
|
2213
|
+
deleteDocument: (identifier, propagate, signal) => this.submitDeleteDocument(identifier, propagate, signal)
|
|
2214
|
+
};
|
|
2215
|
+
}
|
|
2216
|
+
/**
|
|
2217
|
+
* The Switchboard's drive node queries as a node source, for every drive
|
|
2218
|
+
* type. `read.drives` answers from it.
|
|
2219
|
+
*/
|
|
2220
|
+
nodeSource() {
|
|
2221
|
+
return this.driveNodes;
|
|
1418
2222
|
}
|
|
1419
|
-
|
|
2223
|
+
/**
|
|
2224
|
+
* Reads a document. With a consistency token that names any coordinate, the
|
|
2225
|
+
* Switchboard waits until its read models hold them; one without the
|
|
2226
|
+
* `document` query's `consistency` argument is read without it, which after
|
|
2227
|
+
* a write's `readable` stage still sees the write on a single node.
|
|
2228
|
+
*/
|
|
2229
|
+
async get(identifier, view, signal, consistencyToken) {
|
|
1420
2230
|
const viewInput = viewFilterInputFromViewFilter(view);
|
|
1421
|
-
const document = (await this.sdk.GetDocument({
|
|
2231
|
+
const document = (consistencyToken && consistencyToken.coordinates.length > 0 ? await this.getDocumentAtConsistency(identifier, viewInput, consistencyToken, signal) : await this.sdk.GetDocument({
|
|
1422
2232
|
identifier,
|
|
1423
2233
|
view: viewInput
|
|
1424
2234
|
}, void 0, signal)).document;
|
|
1425
2235
|
if (!document) throw new Error(`Document not found: ${identifier}`);
|
|
1426
2236
|
return phDocumentFromGetDocument(document.document, view?.branch);
|
|
1427
2237
|
}
|
|
2238
|
+
/**
|
|
2239
|
+
* Reads documents by id, in the order given; throws if any is missing. Each
|
|
2240
|
+
* chunk of {@link GET_MANY_CHUNK_SIZE} ids is one request holding an aliased
|
|
2241
|
+
* `document` field per id, with the selection and arguments `get` sends.
|
|
2242
|
+
*/
|
|
2243
|
+
async getMany(documentIds, view, signal, consistencyToken) {
|
|
2244
|
+
const viewInput = viewFilterInputFromViewFilter(view);
|
|
2245
|
+
const token = consistencyToken && consistencyToken.coordinates.length > 0 ? consistencyToken : void 0;
|
|
2246
|
+
const chunks = [];
|
|
2247
|
+
for (let i = 0; i < documentIds.length; i += GET_MANY_CHUNK_SIZE) chunks.push(documentIds.slice(i, i + GET_MANY_CHUNK_SIZE));
|
|
2248
|
+
return (await Promise.all(chunks.map((chunk) => this.getDocumentChunk(chunk, viewInput, token, signal)))).flat().map((document) => phDocumentFromGetDocument(document, view?.branch));
|
|
2249
|
+
}
|
|
2250
|
+
/** One chunk of `getMany`, with the `consistency` argument while the Switchboard accepts it. */
|
|
2251
|
+
async getDocumentChunk(identifiers, view, token, signal) {
|
|
2252
|
+
if (token && !this.consistencyUnsupported) try {
|
|
2253
|
+
return await this.runGetDocuments(identifiers, view, consistencyInputFromToken(token), signal);
|
|
2254
|
+
} catch (error) {
|
|
2255
|
+
if (!refusesConsistencyArgument(error)) throw error;
|
|
2256
|
+
this.consistencyUnsupported = true;
|
|
2257
|
+
}
|
|
2258
|
+
return this.runGetDocuments(identifiers, view, void 0, signal);
|
|
2259
|
+
}
|
|
2260
|
+
async runGetDocuments(identifiers, view, consistency, signal) {
|
|
2261
|
+
const variables = { view };
|
|
2262
|
+
const definitions = ["$view: ViewFilterInput"];
|
|
2263
|
+
let consistencyArgument = "";
|
|
2264
|
+
if (consistency) {
|
|
2265
|
+
variables.consistency = consistency;
|
|
2266
|
+
definitions.push("$consistency: ConsistencyTokenInput");
|
|
2267
|
+
consistencyArgument = ", consistency: $consistency";
|
|
2268
|
+
}
|
|
2269
|
+
const fields = identifiers.map((identifier, i) => {
|
|
2270
|
+
variables[`id${i}`] = identifier;
|
|
2271
|
+
definitions.push(`$id${i}: String!`);
|
|
2272
|
+
return `d${i}: document(identifier: $id${i}, view: $view${consistencyArgument}) { document { ...PHDocumentFields } childIds }`;
|
|
2273
|
+
});
|
|
2274
|
+
const query = [
|
|
2275
|
+
`query GetDocuments(${definitions.join(", ")}) {`,
|
|
2276
|
+
...fields,
|
|
2277
|
+
"}",
|
|
2278
|
+
PH_DOCUMENT_FIELDS_SOURCE
|
|
2279
|
+
].join("\n");
|
|
2280
|
+
const data = await this.sdk.RunDocument({
|
|
2281
|
+
operationName: "GetDocuments",
|
|
2282
|
+
operationType: "query",
|
|
2283
|
+
document: query,
|
|
2284
|
+
variables,
|
|
2285
|
+
signal
|
|
2286
|
+
});
|
|
2287
|
+
return identifiers.map((identifier, i) => {
|
|
2288
|
+
const result = data[`d${i}`];
|
|
2289
|
+
if (!result) throw new Error(`Document not found: ${identifier}`);
|
|
2290
|
+
return result.document;
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2293
|
+
/**
|
|
2294
|
+
* Whether the Switchboard would serve the document to this client's caller,
|
|
2295
|
+
* from its `documentServed` query: the same read gate `find` passes. Absent
|
|
2296
|
+
* or withheld is `false`; a failure to decide throws.
|
|
2297
|
+
*
|
|
2298
|
+
* A point-in-time view throws {@link GraphQLOperationNotSupportedError}, as
|
|
2299
|
+
* does a Switchboard without the query.
|
|
2300
|
+
*/
|
|
2301
|
+
async isServed(identifier, view, signal) {
|
|
2302
|
+
const viewInput = viewFilterInputFromViewFilter(view);
|
|
2303
|
+
try {
|
|
2304
|
+
return (await this.sdk.GetDocumentServed({
|
|
2305
|
+
idOrSlug: identifier,
|
|
2306
|
+
view: viewInput
|
|
2307
|
+
}, void 0, signal)).documentServed;
|
|
2308
|
+
} catch (error) {
|
|
2309
|
+
if (queriesUnknownField(error, "documentServed")) throw new GraphQLOperationNotSupportedError("isServed", "the Switchboard predates the documentServed query");
|
|
2310
|
+
throw error;
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
1428
2313
|
async getOperations(documentIdentifier, view, filter, paging, signal) {
|
|
1429
2314
|
const viewInput = viewFilterInputFromViewFilter(view);
|
|
1430
2315
|
const operationsFilter = {
|
|
@@ -1446,26 +2331,113 @@ var GraphQLReactorClient = class {
|
|
|
1446
2331
|
results: page.items.map((item) => remoteOperationToLocal(item)),
|
|
1447
2332
|
options: effectivePaging,
|
|
1448
2333
|
nextCursor,
|
|
1449
|
-
totalCount: page.totalCount,
|
|
1450
2334
|
next: nextCursor ? () => this.getOperations(documentIdentifier, view, filter, {
|
|
1451
2335
|
cursor: nextCursor,
|
|
1452
2336
|
limit: effectivePaging.limit
|
|
1453
2337
|
}, signal) : void 0
|
|
1454
2338
|
};
|
|
1455
2339
|
}
|
|
1456
|
-
async create(document, parentIdentifier, signal) {
|
|
1457
|
-
const created = phDocumentFromGetDocument((await this.sdk.CreateDocument({
|
|
1458
|
-
document,
|
|
1459
|
-
parentIdentifier
|
|
1460
|
-
}, void 0, signal)).createDocument);
|
|
1461
|
-
this.emitChange({
|
|
1462
|
-
type: DOCUMENT_CHANGE_TYPE.Created,
|
|
1463
|
-
documents: [created]
|
|
1464
|
-
});
|
|
1465
|
-
return created;
|
|
1466
|
-
}
|
|
1467
2340
|
/**
|
|
1468
|
-
*
|
|
2341
|
+
* Filters documents by criteria over the Switchboard's `findDocuments` query.
|
|
2342
|
+
*
|
|
2343
|
+
* The query filters by `type` and `parentId` only, at head. A search naming
|
|
2344
|
+
* `ids` or `slugs` (present, whatever its length) and a point-in-time view are
|
|
2345
|
+
* each by-contract limitations the query cannot express -- running it anyway
|
|
2346
|
+
* would return every document instead of the named ones, or head instead of
|
|
2347
|
+
* the asked-for revision, a silently wrong answer. {@link findIsServableOverGraphQL}
|
|
2348
|
+
* is the single predicate that decides this, and an unservable `find` throws
|
|
2349
|
+
* {@link GraphQLOperationNotSupportedError}. Drive enumeration itself filters
|
|
2350
|
+
* by `type` at head, which is served.
|
|
2351
|
+
*/
|
|
2352
|
+
async find(search, view, paging, signal) {
|
|
2353
|
+
if (!findIsServableOverGraphQL(search, view)) throw new GraphQLOperationNotSupportedError("find", searchNamesIdentifiers(search) ? "it cannot filter by ids or slugs: the Switchboard findDocuments query filters only by type and parentId" : "point-in-time views are not supported by GraphQLReactorClient");
|
|
2354
|
+
const viewInput = viewFilterInputFromViewFilter(view);
|
|
2355
|
+
const effectivePaging = paging ?? defaultPaging;
|
|
2356
|
+
const result = await this.sdk.FindDocuments({
|
|
2357
|
+
search: {
|
|
2358
|
+
type: search.type,
|
|
2359
|
+
parentId: search.parentId
|
|
2360
|
+
},
|
|
2361
|
+
view: viewInput,
|
|
2362
|
+
paging: pagingInputFromPaging(effectivePaging)
|
|
2363
|
+
}, search.parentId === void 0 ? void 0 : this.driveIdHeaders({
|
|
2364
|
+
method: "find",
|
|
2365
|
+
parentId: search.parentId
|
|
2366
|
+
}), signal);
|
|
2367
|
+
return this.toDocumentResults(result.findDocuments, effectivePaging, view?.branch, (cursor, limit) => this.find(search, view, {
|
|
2368
|
+
cursor,
|
|
2369
|
+
limit
|
|
2370
|
+
}, signal));
|
|
2371
|
+
}
|
|
2372
|
+
async getOutgoingRelationships(sourceIdentifier, relationshipType, view, paging, signal) {
|
|
2373
|
+
const viewInput = viewFilterInputFromViewFilter(view);
|
|
2374
|
+
const result = await this.sdk.GetDocumentOutgoingRelationships({
|
|
2375
|
+
sourceIdentifier,
|
|
2376
|
+
relationshipType,
|
|
2377
|
+
view: viewInput,
|
|
2378
|
+
paging: pagingInputFromPaging(paging)
|
|
2379
|
+
}, void 0, signal);
|
|
2380
|
+
return this.toDocumentResults(result.documentOutgoingRelationships, paging ?? defaultPaging, view?.branch, (cursor, limit) => this.getOutgoingRelationships(sourceIdentifier, relationshipType, view, {
|
|
2381
|
+
cursor,
|
|
2382
|
+
limit
|
|
2383
|
+
}, signal));
|
|
2384
|
+
}
|
|
2385
|
+
async getIncomingRelationships(targetIdentifier, relationshipType, view, paging, signal) {
|
|
2386
|
+
const viewInput = viewFilterInputFromViewFilter(view);
|
|
2387
|
+
const result = await this.sdk.GetDocumentIncomingRelationships({
|
|
2388
|
+
targetIdentifier,
|
|
2389
|
+
relationshipType,
|
|
2390
|
+
view: viewInput,
|
|
2391
|
+
paging: pagingInputFromPaging(paging)
|
|
2392
|
+
}, void 0, signal);
|
|
2393
|
+
return this.toDocumentResults(result.documentIncomingRelationships, paging ?? defaultPaging, view?.branch, (cursor, limit) => this.getIncomingRelationships(targetIdentifier, relationshipType, view, {
|
|
2394
|
+
cursor,
|
|
2395
|
+
limit
|
|
2396
|
+
}, signal));
|
|
2397
|
+
}
|
|
2398
|
+
async getOutgoingRelationshipEdges(sourceIdentifier, relationshipType, view, paging, signal) {
|
|
2399
|
+
const viewInput = viewFilterInputFromViewFilter(view);
|
|
2400
|
+
const result = await this.sdk.GetDocumentOutgoingRelationshipEdges({
|
|
2401
|
+
sourceIdentifier,
|
|
2402
|
+
relationshipType,
|
|
2403
|
+
view: viewInput,
|
|
2404
|
+
paging: pagingInputFromPaging(paging)
|
|
2405
|
+
}, void 0, signal);
|
|
2406
|
+
return this.toRelationshipResults(result.documentOutgoingRelationshipEdges, paging ?? defaultPaging, (cursor, limit) => this.getOutgoingRelationshipEdges(sourceIdentifier, relationshipType, view, {
|
|
2407
|
+
cursor,
|
|
2408
|
+
limit
|
|
2409
|
+
}, signal));
|
|
2410
|
+
}
|
|
2411
|
+
async getIncomingRelationshipEdges(targetIdentifier, relationshipType, view, paging, signal) {
|
|
2412
|
+
const viewInput = viewFilterInputFromViewFilter(view);
|
|
2413
|
+
const result = await this.sdk.GetDocumentIncomingRelationshipEdges({
|
|
2414
|
+
targetIdentifier,
|
|
2415
|
+
relationshipType,
|
|
2416
|
+
view: viewInput,
|
|
2417
|
+
paging: pagingInputFromPaging(paging)
|
|
2418
|
+
}, void 0, signal);
|
|
2419
|
+
return this.toRelationshipResults(result.documentIncomingRelationshipEdges, paging ?? defaultPaging, (cursor, limit) => this.getIncomingRelationshipEdges(targetIdentifier, relationshipType, view, {
|
|
2420
|
+
cursor,
|
|
2421
|
+
limit
|
|
2422
|
+
}, signal));
|
|
2423
|
+
}
|
|
2424
|
+
async create(document, parentIdentifier, signal) {
|
|
2425
|
+
const created = phDocumentFromGetDocument((await this.sdk.CreateDocument({
|
|
2426
|
+
document,
|
|
2427
|
+
parentIdentifier
|
|
2428
|
+
}, this.driveIdHeaders({
|
|
2429
|
+
method: "create",
|
|
2430
|
+
documentId: document.header.id || void 0,
|
|
2431
|
+
parentId: parentIdentifier
|
|
2432
|
+
}, isDrive(document) && parentIdentifier === void 0 ? document.header.id : void 0), signal)).createDocument);
|
|
2433
|
+
this.emitChange({
|
|
2434
|
+
type: DOCUMENT_CHANGE_TYPE.Created,
|
|
2435
|
+
documents: [created]
|
|
2436
|
+
});
|
|
2437
|
+
return created;
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
* Pushes actions to the Switchboard and returns the updated document.
|
|
1469
2441
|
*
|
|
1470
2442
|
* The document is fetched first: the response is the baseline for the
|
|
1471
2443
|
* `sinceRevision` filter that narrows the returned operations to the ones
|
|
@@ -1485,7 +2457,7 @@ var GraphQLReactorClient = class {
|
|
|
1485
2457
|
const document = await this.get(documentIdentifier, { branch }, signal);
|
|
1486
2458
|
const variables = {
|
|
1487
2459
|
documentIdentifier,
|
|
1488
|
-
actions: (await prepareActionsForPush(actions, document, this.documentModels, this.signer, signal)).map(toTransportAction),
|
|
2460
|
+
actions: (await prepareActionsForPush(actions, document, this.documentModels(), this.signer, signal)).map(toTransportAction),
|
|
1489
2461
|
sinceRevision: sinceRevisionForActions(document, actions),
|
|
1490
2462
|
scopes: scopesForActions(actions),
|
|
1491
2463
|
branch
|
|
@@ -1495,6 +2467,10 @@ var GraphQLReactorClient = class {
|
|
|
1495
2467
|
operationType: "mutation",
|
|
1496
2468
|
document: MutateDocumentWithOperationsDocument,
|
|
1497
2469
|
variables,
|
|
2470
|
+
requestHeaders: this.driveIdHeaders({
|
|
2471
|
+
method: "execute",
|
|
2472
|
+
documentId: documentIdentifier
|
|
2473
|
+
}, isDrive(document) ? document.header.id : void 0),
|
|
1498
2474
|
signal
|
|
1499
2475
|
})).mutateDocument;
|
|
1500
2476
|
const updated = phDocumentFromMutation(mutated, mutated.operations?.items ?? [], branch);
|
|
@@ -1505,6 +2481,199 @@ var GraphQLReactorClient = class {
|
|
|
1505
2481
|
return updated;
|
|
1506
2482
|
}
|
|
1507
2483
|
/**
|
|
2484
|
+
* Runs multiple mutation jobs in dependency order over the Switchboard's
|
|
2485
|
+
* `executeBatch` mutation and waits for all to settle, returning the result
|
|
2486
|
+
* shaped like `IReactor.executeBatch`'s so the reference `DriveClient`
|
|
2487
|
+
* consumes it unchanged.
|
|
2488
|
+
*
|
|
2489
|
+
* Not atomic: each job commits on its own and a failed job still releases
|
|
2490
|
+
* its dependents. A FAILED job throws {@link BatchJobFailedError}, naming the
|
|
2491
|
+
* first failed plan key and carrying every job's final state.
|
|
2492
|
+
*
|
|
2493
|
+
* Each job's actions are signed independently for the job's own
|
|
2494
|
+
* `(documentId, branch)` target -- the per-action signing the reactor's own
|
|
2495
|
+
* `signActions` does, not the batch state-prediction `execute` uses for a
|
|
2496
|
+
* multi-action push. A drive job such as `addFile`'s is `CREATE_DOCUMENT` +
|
|
2497
|
+
* `UPGRADE_DOCUMENT` + `ADD_RELATIONSHIP`, which the prediction path rejects
|
|
2498
|
+
* outright and which has no fetchable baseline to stamp against. The reactor
|
|
2499
|
+
* records but does not verify the stamped previous-state head, so signing
|
|
2500
|
+
* each action bare is exactly what the in-process `DriveClient` relies on.
|
|
2501
|
+
*
|
|
2502
|
+
* The mutation is synchronous server-side: a job it returns is already
|
|
2503
|
+
* settled, so {@link waitForJob} resolves from it without polling.
|
|
2504
|
+
*/
|
|
2505
|
+
async executeBatch(request, signal) {
|
|
2506
|
+
const signer = this.signer ?? resolveAmbientSigner();
|
|
2507
|
+
const jobInputs = await Promise.all(request.jobs.map(async (job, index) => {
|
|
2508
|
+
const documentId = await this.batchWriteTarget(job, request.jobs.slice(0, index), signer, signal);
|
|
2509
|
+
const actions = await this.signBatchJobActions({
|
|
2510
|
+
...job,
|
|
2511
|
+
documentId
|
|
2512
|
+
}, signer, signal);
|
|
2513
|
+
return {
|
|
2514
|
+
key: job.key,
|
|
2515
|
+
documentIdOrSlug: documentId,
|
|
2516
|
+
scope: job.scope,
|
|
2517
|
+
branch: job.branch,
|
|
2518
|
+
actions: actions.map(toTransportAction),
|
|
2519
|
+
dependsOn: job.dependsOn
|
|
2520
|
+
};
|
|
2521
|
+
}));
|
|
2522
|
+
const result = await this.sdk.ExecuteBatch({ jobs: jobInputs }, this.driveIdHeaders({
|
|
2523
|
+
method: "executeBatch",
|
|
2524
|
+
jobs: jobInputs.map((job) => ({ documentId: job.documentIdOrSlug }))
|
|
2525
|
+
}), signal);
|
|
2526
|
+
const jobs = {};
|
|
2527
|
+
for (const entry of result.executeBatch.jobs) jobs[entry.key] = jobInfoFromGql(entry.job);
|
|
2528
|
+
await this.announceBatch(request, jobs, signal);
|
|
2529
|
+
const failed = request.jobs.find((job) => jobs[job.key]?.status === "FAILED");
|
|
2530
|
+
if (failed) throw new BatchJobFailedError(failed.key, jobs);
|
|
2531
|
+
return { jobs };
|
|
2532
|
+
}
|
|
2533
|
+
/** The job as `jobStatus` reports it now; `undefined` when it reports none. */
|
|
2534
|
+
async getJob(jobId, signal) {
|
|
2535
|
+
const result = await this.sdk.GetJobStatus({ jobId }, void 0, signal);
|
|
2536
|
+
return result.jobStatus ? jobInfoFromGql(result.jobStatus) : void 0;
|
|
2537
|
+
}
|
|
2538
|
+
/** The job as `jobStatus` reports it now; throws when it reports none. */
|
|
2539
|
+
async getJobStatus(jobId, signal) {
|
|
2540
|
+
const job = await this.getJob(jobId, signal);
|
|
2541
|
+
if (!job) throw new Error(`Job not found: ${jobId}`);
|
|
2542
|
+
return job;
|
|
2543
|
+
}
|
|
2544
|
+
/** Polls `jobStatus` until the job is READ_READY or FAILED. */
|
|
2545
|
+
async waitForJob(jobOrId, signal) {
|
|
2546
|
+
if (typeof jobOrId !== "string" && isSettled(jobOrId)) return jobOrId;
|
|
2547
|
+
const jobId = typeof jobOrId === "string" ? jobOrId : jobOrId.id;
|
|
2548
|
+
for (;;) {
|
|
2549
|
+
const result = await this.sdk.GetJobStatus({ jobId }, void 0, signal);
|
|
2550
|
+
if (!result.jobStatus) throw new Error(`Job not found: ${jobId}`);
|
|
2551
|
+
const job = jobInfoFromGql(result.jobStatus);
|
|
2552
|
+
if (isSettled(job)) return job;
|
|
2553
|
+
await delay(JOB_POLL_INTERVAL_MS, signal);
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
/** See {@link readCreateSignaturePolicy}. */
|
|
2557
|
+
getCreateSignaturePolicy() {
|
|
2558
|
+
return readCreateSignaturePolicy(this.sdk);
|
|
2559
|
+
}
|
|
2560
|
+
/** See {@link readCreateProtocolVersions}; fitted to `documentModels`. */
|
|
2561
|
+
getCreateProtocolVersions(options, signal) {
|
|
2562
|
+
return readCreateProtocolVersions(this.sdk, options, this.documentModels(), signal);
|
|
2563
|
+
}
|
|
2564
|
+
/** See {@link IReactorClient.newDocument}; the module comes from `documentModels`. */
|
|
2565
|
+
async newDocument(documentType, options, signal) {
|
|
2566
|
+
const module = selectDocumentModelModule([...this.documentModels(), ...BUILT_IN_MODELS], documentType, options?.documentModelVersion);
|
|
2567
|
+
const [policy, versions] = await Promise.all([options?.signaturePolicy ?? this.getCreateSignaturePolicy(), this.getCreateProtocolVersions({
|
|
2568
|
+
documentType,
|
|
2569
|
+
parentIdentifier: options?.parentIdentifier
|
|
2570
|
+
}, signal)]);
|
|
2571
|
+
return headNewDocument(module, options, policy, versions);
|
|
2572
|
+
}
|
|
2573
|
+
/**
|
|
2574
|
+
* Sets or, with `null`, clears the preferred editor as a client-signed
|
|
2575
|
+
* action, as the in-process client does.
|
|
2576
|
+
*/
|
|
2577
|
+
setPreferredEditor(documentIdentifier, preferredEditor, branch = "main", signal) {
|
|
2578
|
+
return this.execute(documentIdentifier, branch, [actions.setPreferredEditor(preferredEditor)], signal);
|
|
2579
|
+
}
|
|
2580
|
+
/** The `Drive-Id` header for a call: the client's own proof, else the hook's. */
|
|
2581
|
+
driveIdHeaders(call, proven) {
|
|
2582
|
+
const hinted = this.driveIdFor?.(call);
|
|
2583
|
+
if (proven) {
|
|
2584
|
+
if (hinted && hinted !== proven) logger.warn("GraphQLReactorClient: driveIdFor named @hinted for @method, which belongs to drive @proven; sending the proven drive", hinted, call.method, proven);
|
|
2585
|
+
return driveIdHeaders(proven);
|
|
2586
|
+
}
|
|
2587
|
+
return hinted ? driveIdHeaders(hinted) : void 0;
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2590
|
+
* Emits the changes the batch's settled jobs made, as `create` and `execute`
|
|
2591
|
+
* do, so a cache is invalidated without a realtime socket. The documents a
|
|
2592
|
+
* job wrote to are its own and those its consistency token names.
|
|
2593
|
+
*/
|
|
2594
|
+
async announceBatch(request, jobs, signal) {
|
|
2595
|
+
if (this.listeners.length === 0) return;
|
|
2596
|
+
const deleted = /* @__PURE__ */ new Set();
|
|
2597
|
+
const created = /* @__PURE__ */ new Map();
|
|
2598
|
+
const touched = /* @__PURE__ */ new Map();
|
|
2599
|
+
const keyOf = (written) => `${written.branch}\u0000${written.documentId}`;
|
|
2600
|
+
for (const job of request.jobs) {
|
|
2601
|
+
const info = jobs[job.key];
|
|
2602
|
+
if (!info || info.status !== "READ_READY") continue;
|
|
2603
|
+
const types = new Set(job.actions.map((action) => action.type));
|
|
2604
|
+
if (types.has("DELETE_DOCUMENT")) {
|
|
2605
|
+
deleted.add(info.documentId);
|
|
2606
|
+
continue;
|
|
2607
|
+
}
|
|
2608
|
+
const own = {
|
|
2609
|
+
documentId: info.documentId,
|
|
2610
|
+
branch: job.branch
|
|
2611
|
+
};
|
|
2612
|
+
if (types.has("CREATE_DOCUMENT")) created.set(keyOf(own), own);
|
|
2613
|
+
touched.set(keyOf(own), own);
|
|
2614
|
+
for (const { documentId, branch } of info.consistencyToken.coordinates) touched.set(keyOf({
|
|
2615
|
+
documentId,
|
|
2616
|
+
branch
|
|
2617
|
+
}), {
|
|
2618
|
+
documentId,
|
|
2619
|
+
branch
|
|
2620
|
+
});
|
|
2621
|
+
}
|
|
2622
|
+
for (const documentId of deleted) this.emitChange({
|
|
2623
|
+
type: DOCUMENT_CHANGE_TYPE.Deleted,
|
|
2624
|
+
documents: [],
|
|
2625
|
+
context: { childId: documentId }
|
|
2626
|
+
});
|
|
2627
|
+
const read = async ({ documentId, branch }) => {
|
|
2628
|
+
try {
|
|
2629
|
+
return await this.get(documentId, { branch }, signal);
|
|
2630
|
+
} catch (error) {
|
|
2631
|
+
logger.warn("GraphQLReactorClient: could not read @documentId on @branch to announce a batch change: @error", documentId, branch, error);
|
|
2632
|
+
return;
|
|
2633
|
+
}
|
|
2634
|
+
};
|
|
2635
|
+
const readAll = async (written) => (await Promise.all(written.map(read))).filter((document) => document !== void 0);
|
|
2636
|
+
const [createdDocuments, updatedDocuments] = await Promise.all([readAll([...created.values()].filter((w) => !deleted.has(w.documentId))), readAll([...touched.entries()].filter(([key, w]) => !deleted.has(w.documentId) && !created.has(key)).map(([, w]) => w))]);
|
|
2637
|
+
if (createdDocuments.length > 0) this.emitChange({
|
|
2638
|
+
type: DOCUMENT_CHANGE_TYPE.Created,
|
|
2639
|
+
documents: createdDocuments
|
|
2640
|
+
});
|
|
2641
|
+
if (updatedDocuments.length > 0) this.emitChange({
|
|
2642
|
+
type: DOCUMENT_CHANGE_TYPE.Updated,
|
|
2643
|
+
documents: updatedDocuments
|
|
2644
|
+
});
|
|
2645
|
+
}
|
|
2646
|
+
/**
|
|
2647
|
+
* The id a job's actions are signed for: a signature covers the document id,
|
|
2648
|
+
* and the server resolves a slug before verifying. A document created by this
|
|
2649
|
+
* job or an earlier one is named by its id. When the server has no such
|
|
2650
|
+
* document the identifier is used as given, and the server decides; any
|
|
2651
|
+
* other failure to read it throws, so nothing is signed for a slug.
|
|
2652
|
+
*/
|
|
2653
|
+
async batchWriteTarget(job, earlier, signer, signal) {
|
|
2654
|
+
const creates = (plan) => plan.documentId === job.documentId && plan.actions.some((action) => action.type === "CREATE_DOCUMENT");
|
|
2655
|
+
if (!signer || job.actions.every(isActionSigned) || creates(job) || earlier.some(creates)) return job.documentId;
|
|
2656
|
+
return (await this.sdk.GetDocument({
|
|
2657
|
+
identifier: job.documentId,
|
|
2658
|
+
view: viewFilterInputFromViewFilter({ branch: job.branch })
|
|
2659
|
+
}, void 0, signal)).document?.document.id ?? job.documentId;
|
|
2660
|
+
}
|
|
2661
|
+
/**
|
|
2662
|
+
* Signs one batch job's actions for the job's own log.
|
|
2663
|
+
*
|
|
2664
|
+
* Each action is signed on its own for `(documentId, branch)`, the same
|
|
2665
|
+
* per-action signing the reactor's `signActions` does: no state prediction
|
|
2666
|
+
* across the job, so a job carrying a `CREATE_DOCUMENT` the push-prediction
|
|
2667
|
+
* path rejects still signs. An action already signed under a key is left
|
|
2668
|
+
* as it is: the reference `DriveClient` signs its jobs before handing them
|
|
2669
|
+
* here. With no signer the actions pass through unsigned, matching
|
|
2670
|
+
* {@link execute}.
|
|
2671
|
+
*/
|
|
2672
|
+
async signBatchJobActions(job, signer, signal) {
|
|
2673
|
+
if (!signer) return job.actions;
|
|
2674
|
+
return Promise.all(job.actions.map((action) => isActionSigned(action) ? Promise.resolve(action) : signStampedAction(action, signer, actionSigningTarget(action, job.documentId, job.branch), signal)));
|
|
2675
|
+
}
|
|
2676
|
+
/**
|
|
1508
2677
|
* Deletes a document and announces it as a `Deleted` event.
|
|
1509
2678
|
*
|
|
1510
2679
|
* Pass a document id. The server resolves a slug just as happily, but
|
|
@@ -1517,7 +2686,10 @@ var GraphQLReactorClient = class {
|
|
|
1517
2686
|
await this.sdk.DeleteDocument({
|
|
1518
2687
|
identifier,
|
|
1519
2688
|
propagate: propagationModeInput(propagate)
|
|
1520
|
-
},
|
|
2689
|
+
}, this.driveIdHeaders({
|
|
2690
|
+
method: "deleteDocument",
|
|
2691
|
+
documentId: identifier
|
|
2692
|
+
}), signal);
|
|
1521
2693
|
this.emitChange({
|
|
1522
2694
|
type: DOCUMENT_CHANGE_TYPE.Deleted,
|
|
1523
2695
|
documents: [],
|
|
@@ -1575,6 +2747,8 @@ var GraphQLReactorClient = class {
|
|
|
1575
2747
|
*/
|
|
1576
2748
|
dispose() {
|
|
1577
2749
|
this.teardownRealtime();
|
|
2750
|
+
this.jobSocket?.dispose();
|
|
2751
|
+
this.jobSocket = void 0;
|
|
1578
2752
|
}
|
|
1579
2753
|
/**
|
|
1580
2754
|
* Binds a project's generated SDK to this client's transport and auth.
|
|
@@ -1613,6 +2787,157 @@ var GraphQLReactorClient = class {
|
|
|
1613
2787
|
});
|
|
1614
2788
|
}
|
|
1615
2789
|
/**
|
|
2790
|
+
* Shapes a document result page into the reactor's {@link PagedResults}.
|
|
2791
|
+
*
|
|
2792
|
+
* The items carry the same `PHDocumentFields` fragment as `get`, so the same
|
|
2793
|
+
* adapter rebuilds each one. `hasNextPage` gates the cursor exactly as
|
|
2794
|
+
* `getOperations` does: no cursor means no `next`.
|
|
2795
|
+
*/
|
|
2796
|
+
toDocumentResults(page, effectivePaging, branch, next) {
|
|
2797
|
+
const nextCursor = page.hasNextPage ? page.cursor ?? void 0 : void 0;
|
|
2798
|
+
return {
|
|
2799
|
+
results: page.items.map((item) => phDocumentFromGetDocument(item, branch)),
|
|
2800
|
+
options: effectivePaging,
|
|
2801
|
+
nextCursor,
|
|
2802
|
+
next: nextCursor ? () => next(nextCursor, effectivePaging.limit) : void 0
|
|
2803
|
+
};
|
|
2804
|
+
}
|
|
2805
|
+
/**
|
|
2806
|
+
* Shapes a relationship-edge result page into the reactor's
|
|
2807
|
+
* {@link PagedResults}, restoring each edge's `Date` fields.
|
|
2808
|
+
*/
|
|
2809
|
+
toRelationshipResults(page, effectivePaging, next) {
|
|
2810
|
+
const nextCursor = page.hasNextPage ? page.cursor ?? void 0 : void 0;
|
|
2811
|
+
return {
|
|
2812
|
+
results: page.items.map((edge) => documentRelationshipFromEdge(edge)),
|
|
2813
|
+
options: effectivePaging,
|
|
2814
|
+
nextCursor,
|
|
2815
|
+
next: nextCursor ? () => next(nextCursor, effectivePaging.limit) : void 0
|
|
2816
|
+
};
|
|
2817
|
+
}
|
|
2818
|
+
/**
|
|
2819
|
+
* The write half's `execute`: signs as the facade's `execute` does, submits
|
|
2820
|
+
* through `executeAsync` and returns once the job is accepted. When anyone
|
|
2821
|
+
* subscribes, the document is read back once the job is readable and
|
|
2822
|
+
* announced as `Updated`, as the facade's `execute` announces it; the handle
|
|
2823
|
+
* shares that read with its own `document()`.
|
|
2824
|
+
*/
|
|
2825
|
+
async submitExecute(documentIdentifier, branch, actions, signal) {
|
|
2826
|
+
const document = await this.get(documentIdentifier, { branch }, signal);
|
|
2827
|
+
const preparedActions = await prepareActionsForPush(actions, document, this.documentModels(), this.signer, signal);
|
|
2828
|
+
const handle = new GraphQLJobWriteHandle(jobInfoFromGql((await this.sdk.MutateDocumentAsync({
|
|
2829
|
+
documentIdentifier,
|
|
2830
|
+
actions: preparedActions.map(toTransportAction),
|
|
2831
|
+
branch
|
|
2832
|
+
}, this.driveIdHeaders({
|
|
2833
|
+
method: "execute",
|
|
2834
|
+
documentId: documentIdentifier
|
|
2835
|
+
}, 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);
|
|
2836
|
+
if (this.listeners.length > 0) this.announceWrite(handle);
|
|
2837
|
+
return handle;
|
|
2838
|
+
}
|
|
2839
|
+
/** The write half's `create`: the synchronous mutation, a settled handle. */
|
|
2840
|
+
async submitCreate(document, parentIdentifier, signal) {
|
|
2841
|
+
const created = await this.create(document, parentIdentifier, signal);
|
|
2842
|
+
return new GraphQLSettledWriteHandle(created.header.id, created.header.branch || "main", this.handleReader(created.header.id));
|
|
2843
|
+
}
|
|
2844
|
+
/** The write half's `deleteDocument`: the synchronous mutation, a settled handle. */
|
|
2845
|
+
async submitDeleteDocument(identifier, propagate, signal) {
|
|
2846
|
+
await this.deleteDocument(identifier, propagate, signal);
|
|
2847
|
+
return new GraphQLSettledWriteHandle(identifier, "main", this.handleReader(identifier));
|
|
2848
|
+
}
|
|
2849
|
+
/** Reads a write's document back, bounded by its receipt's token. */
|
|
2850
|
+
handleReader(documentId) {
|
|
2851
|
+
return (receipt, view, signal) => this.get(documentId, {
|
|
2852
|
+
...view,
|
|
2853
|
+
branch: receipt.branch
|
|
2854
|
+
}, signal, receipt.token);
|
|
2855
|
+
}
|
|
2856
|
+
/** Announces a write's document as `Updated` once it is readable. */
|
|
2857
|
+
async announceWrite(handle) {
|
|
2858
|
+
let document;
|
|
2859
|
+
try {
|
|
2860
|
+
document = await handle.document();
|
|
2861
|
+
} catch (error) {
|
|
2862
|
+
logger.warn("GraphQLReactorClient: could not read @documentId back to announce a write: @error", handle.documentId, error);
|
|
2863
|
+
return;
|
|
2864
|
+
}
|
|
2865
|
+
this.emitChange({
|
|
2866
|
+
type: DOCUMENT_CHANGE_TYPE.Updated,
|
|
2867
|
+
documents: [document]
|
|
2868
|
+
});
|
|
2869
|
+
}
|
|
2870
|
+
/**
|
|
2871
|
+
* Waits for a job to settle a stage, resolving with a FAILED job too. Polls
|
|
2872
|
+
* `jobStatus` with a doubling interval; with realtime on, a `jobChanges`
|
|
2873
|
+
* event for the job wakes the wait early and the interval is only a safety
|
|
2874
|
+
* net. A failed subscription is logged once and the wait keeps polling.
|
|
2875
|
+
*/
|
|
2876
|
+
async waitForStage(jobId, stage, signal) {
|
|
2877
|
+
const wakers = /* @__PURE__ */ new Set();
|
|
2878
|
+
const stopWatching = this.watchJob(jobId, () => {
|
|
2879
|
+
for (const wake of [...wakers]) wake();
|
|
2880
|
+
});
|
|
2881
|
+
try {
|
|
2882
|
+
let interval = STAGE_POLL_START_MS;
|
|
2883
|
+
for (;;) {
|
|
2884
|
+
const job = await this.getJobStatus(jobId, signal);
|
|
2885
|
+
if (settlesGraphQLJobStage(job.status, stage)) return job;
|
|
2886
|
+
await sleepUntilWoken(interval, wakers, signal);
|
|
2887
|
+
const max = stopWatching && !this.jobRealtimeBroken ? STAGE_POLL_REALTIME_MAX_MS : JOB_POLL_INTERVAL_MS;
|
|
2888
|
+
interval = Math.min(interval * 2, max);
|
|
2889
|
+
}
|
|
2890
|
+
} finally {
|
|
2891
|
+
stopWatching?.();
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
/**
|
|
2895
|
+
* Subscribes to one job's `jobChanges` when realtime is on and the
|
|
2896
|
+
* subscription has not failed before. Returns the stop function, or
|
|
2897
|
+
* undefined when nothing was subscribed.
|
|
2898
|
+
*/
|
|
2899
|
+
watchJob(jobId, onChange) {
|
|
2900
|
+
if (!this.subscriptionsUrl || this.jobRealtimeBroken) return;
|
|
2901
|
+
this.jobSocket ??= createJobChangesSocket({
|
|
2902
|
+
wsUrl: this.subscriptionsUrl,
|
|
2903
|
+
connectionParams: makeAuthConnectionParams(this.tokenProvider)
|
|
2904
|
+
});
|
|
2905
|
+
return this.jobSocket.watch(jobId, () => onChange(), (error) => {
|
|
2906
|
+
if (this.jobRealtimeBroken) return;
|
|
2907
|
+
this.jobRealtimeBroken = true;
|
|
2908
|
+
logger.warn("GraphQLReactorClient: realtime job changes are unavailable, write handles fall back to polling jobStatus", error);
|
|
2909
|
+
});
|
|
2910
|
+
}
|
|
2911
|
+
/**
|
|
2912
|
+
* The `document` query with the `consistency` argument, or without it once
|
|
2913
|
+
* the Switchboard has refused the argument.
|
|
2914
|
+
*/
|
|
2915
|
+
async getDocumentAtConsistency(identifier, view, token, signal) {
|
|
2916
|
+
if (!this.consistencyUnsupported) {
|
|
2917
|
+
const variables = {
|
|
2918
|
+
identifier,
|
|
2919
|
+
view,
|
|
2920
|
+
consistency: consistencyInputFromToken(token)
|
|
2921
|
+
};
|
|
2922
|
+
try {
|
|
2923
|
+
return await this.sdk.RunDocument({
|
|
2924
|
+
operationName: "GetDocumentAtConsistency",
|
|
2925
|
+
operationType: "query",
|
|
2926
|
+
document: GetDocumentAtConsistencyDocument,
|
|
2927
|
+
variables,
|
|
2928
|
+
signal
|
|
2929
|
+
});
|
|
2930
|
+
} catch (error) {
|
|
2931
|
+
if (!refusesConsistencyArgument(error)) throw error;
|
|
2932
|
+
this.consistencyUnsupported = true;
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
return this.sdk.GetDocument({
|
|
2936
|
+
identifier,
|
|
2937
|
+
view
|
|
2938
|
+
}, void 0, signal);
|
|
2939
|
+
}
|
|
2940
|
+
/**
|
|
1616
2941
|
* Opens the realtime socket on the first subscriber.
|
|
1617
2942
|
*
|
|
1618
2943
|
* The subscription is a firehose - no `search` argument - and this client
|
|
@@ -1731,6 +3056,98 @@ var GraphQLReactorClient = class {
|
|
|
1731
3056
|
}
|
|
1732
3057
|
};
|
|
1733
3058
|
/**
|
|
3059
|
+
* The read half of {@link GraphQLReactorClient}: every read is the client's
|
|
3060
|
+
* own, and nothing that writes is reachable from it.
|
|
3061
|
+
*/
|
|
3062
|
+
var GraphQLReadHalf = class {
|
|
3063
|
+
client;
|
|
3064
|
+
drives;
|
|
3065
|
+
constructor(client, nodes) {
|
|
3066
|
+
this.client = client;
|
|
3067
|
+
this.drives = new GraphQLDriveReadClient(nodes);
|
|
3068
|
+
}
|
|
3069
|
+
get(identifier, view, signal, consistencyToken) {
|
|
3070
|
+
return this.client.get(identifier, view, signal, consistencyToken);
|
|
3071
|
+
}
|
|
3072
|
+
getMany(documentIds, view, signal, consistencyToken) {
|
|
3073
|
+
return this.client.getMany(documentIds, view, signal, consistencyToken);
|
|
3074
|
+
}
|
|
3075
|
+
find(search, view, paging, signal) {
|
|
3076
|
+
return this.client.find(search, view, paging, signal);
|
|
3077
|
+
}
|
|
3078
|
+
getOperations(documentIdentifier, view, filter, paging, signal) {
|
|
3079
|
+
return this.client.getOperations(documentIdentifier, view, filter, paging, signal);
|
|
3080
|
+
}
|
|
3081
|
+
subscribe(search, callback, view) {
|
|
3082
|
+
return this.client.subscribe(search, callback, view);
|
|
3083
|
+
}
|
|
3084
|
+
waitForJob(jobId, signal) {
|
|
3085
|
+
return this.client.waitForJob(jobId, signal);
|
|
3086
|
+
}
|
|
3087
|
+
getJobStatus(jobId, signal) {
|
|
3088
|
+
return this.client.getJobStatus(jobId, signal);
|
|
3089
|
+
}
|
|
3090
|
+
};
|
|
3091
|
+
/**
|
|
3092
|
+
* Sleeps for `ms`, or less when a waker in `wakers` fires first. Each sleep
|
|
3093
|
+
* adds its own waker and removes it when it ends.
|
|
3094
|
+
*/
|
|
3095
|
+
function sleepUntilWoken(ms, wakers, signal) {
|
|
3096
|
+
return new Promise((resolve, reject) => {
|
|
3097
|
+
if (signal?.aborted) {
|
|
3098
|
+
reject(abortReason(signal));
|
|
3099
|
+
return;
|
|
3100
|
+
}
|
|
3101
|
+
const finish = () => {
|
|
3102
|
+
clearTimeout(timer);
|
|
3103
|
+
wakers.delete(finish);
|
|
3104
|
+
signal?.removeEventListener("abort", onAbort);
|
|
3105
|
+
};
|
|
3106
|
+
const wake = () => {
|
|
3107
|
+
finish();
|
|
3108
|
+
resolve();
|
|
3109
|
+
};
|
|
3110
|
+
const onAbort = () => {
|
|
3111
|
+
finish();
|
|
3112
|
+
if (signal) reject(abortReason(signal));
|
|
3113
|
+
};
|
|
3114
|
+
const timer = setTimeout(wake, ms);
|
|
3115
|
+
wakers.add(wake);
|
|
3116
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
3117
|
+
});
|
|
3118
|
+
}
|
|
3119
|
+
/**
|
|
3120
|
+
* Whether a request failed because the Switchboard's `document` query has no
|
|
3121
|
+
* `consistency` argument, or its schema no `ConsistencyTokenInput`.
|
|
3122
|
+
*/
|
|
3123
|
+
/** The most ids one `getMany` request reads. */
|
|
3124
|
+
const GET_MANY_CHUNK_SIZE = 50;
|
|
3125
|
+
const PH_DOCUMENT_FIELDS_SOURCE = print(PhDocumentFieldsFragmentDoc);
|
|
3126
|
+
function consistencyInputFromToken(token) {
|
|
3127
|
+
return {
|
|
3128
|
+
version: token.version,
|
|
3129
|
+
createdAtUtcIso: token.createdAtUtcIso,
|
|
3130
|
+
coordinates: token.coordinates.map((coordinate) => ({
|
|
3131
|
+
documentId: coordinate.documentId,
|
|
3132
|
+
scope: coordinate.scope,
|
|
3133
|
+
branch: coordinate.branch,
|
|
3134
|
+
operationIndex: coordinate.operationIndex
|
|
3135
|
+
}))
|
|
3136
|
+
};
|
|
3137
|
+
}
|
|
3138
|
+
function refusesConsistencyArgument(error) {
|
|
3139
|
+
const errors = error?.response?.errors;
|
|
3140
|
+
if (!Array.isArray(errors)) return false;
|
|
3141
|
+
return errors.some((entry) => {
|
|
3142
|
+
const message = entry?.message;
|
|
3143
|
+
return typeof message === "string" && (message.includes("\"consistency\"") || message.includes("\"ConsistencyTokenInput\""));
|
|
3144
|
+
});
|
|
3145
|
+
}
|
|
3146
|
+
/** {@link GraphQLReactorClient.nodeSource}, as a function. */
|
|
3147
|
+
function createGraphQLDriveNodeSource(client) {
|
|
3148
|
+
return client.nodeSource();
|
|
3149
|
+
}
|
|
3150
|
+
/**
|
|
1734
3151
|
* Whether a value is a {@link GraphQLReactorClient}, including one built by
|
|
1735
3152
|
* another copy of this module.
|
|
1736
3153
|
*
|
|
@@ -1743,13 +3160,13 @@ function isGraphQLReactorClient(client) {
|
|
|
1743
3160
|
}
|
|
1744
3161
|
/** The schema's change types, mapped onto the reactor's. */
|
|
1745
3162
|
const documentChangeTypes = {
|
|
1746
|
-
[
|
|
1747
|
-
[
|
|
1748
|
-
[
|
|
1749
|
-
[
|
|
1750
|
-
[
|
|
1751
|
-
[
|
|
1752
|
-
[
|
|
3163
|
+
["CREATED"]: DOCUMENT_CHANGE_TYPE.Created,
|
|
3164
|
+
["DELETED"]: DOCUMENT_CHANGE_TYPE.Deleted,
|
|
3165
|
+
["UPDATED"]: DOCUMENT_CHANGE_TYPE.Updated,
|
|
3166
|
+
["PARENT_ADDED"]: DOCUMENT_CHANGE_TYPE.ParentAdded,
|
|
3167
|
+
["PARENT_REMOVED"]: DOCUMENT_CHANGE_TYPE.ParentRemoved,
|
|
3168
|
+
["CHILD_ADDED"]: DOCUMENT_CHANGE_TYPE.ChildAdded,
|
|
3169
|
+
["CHILD_REMOVED"]: DOCUMENT_CHANGE_TYPE.ChildRemoved
|
|
1753
3170
|
};
|
|
1754
3171
|
/**
|
|
1755
3172
|
* Decides whether an event reaches a subscriber.
|
|
@@ -1784,7 +3201,7 @@ function eventMatchesSearch(event, search) {
|
|
|
1784
3201
|
*/
|
|
1785
3202
|
function viewFilterInputFromViewFilter(view) {
|
|
1786
3203
|
if (!view) return;
|
|
1787
|
-
if (view
|
|
3204
|
+
if (viewIsPointInTime(view)) throw new GraphQLOperationNotSupportedError("view", "point-in-time views are not supported by GraphQLReactorClient");
|
|
1788
3205
|
if (view.branch === void 0 && view.scopes === void 0) return;
|
|
1789
3206
|
return {
|
|
1790
3207
|
branch: view.branch,
|
|
@@ -1799,13 +3216,78 @@ function pagingInputFromPaging(paging) {
|
|
|
1799
3216
|
};
|
|
1800
3217
|
}
|
|
1801
3218
|
/**
|
|
3219
|
+
* Whether a search names `ids` or `slugs`, which the Switchboard `findDocuments`
|
|
3220
|
+
* query cannot honour (it filters by `type` and `parentId`).
|
|
3221
|
+
*
|
|
3222
|
+
* The test is PRESENCE, not length: the reactor `find` contract
|
|
3223
|
+
* (`packages/reactor/src/core/reactor.ts`) dispatches on `search.ids` /
|
|
3224
|
+
* `search.slugs` being present, so `find({ ids: [] })` is an identifier search
|
|
3225
|
+
* that must yield the empty set -- not a plain type query over every document.
|
|
3226
|
+
* The GraphQL surface cannot express an identifier search at all, so a present
|
|
3227
|
+
* (even empty) `ids`/`slugs` is refused rather than served as the wrong query.
|
|
3228
|
+
*/
|
|
3229
|
+
function searchNamesIdentifiers(search) {
|
|
3230
|
+
return search.ids !== void 0 || search.slugs !== void 0;
|
|
3231
|
+
}
|
|
3232
|
+
/** Whether a view asks for a point-in-time read the GraphQL surface cannot express. */
|
|
3233
|
+
function viewIsPointInTime(view) {
|
|
3234
|
+
return view?.revision !== void 0;
|
|
3235
|
+
}
|
|
3236
|
+
/**
|
|
3237
|
+
* The single source of truth for whether the Switchboard `findDocuments` query
|
|
3238
|
+
* can serve a `find`. It is servable iff the search names neither `ids` nor
|
|
3239
|
+
* `slugs` (present, regardless of length) AND the view is not point-in-time:
|
|
3240
|
+
* each is a by-contract limitation of a surface that filters only by
|
|
3241
|
+
* `type`/`parentId` at head. Exported so a caller can route around an
|
|
3242
|
+
* unservable search instead of catching the error `find` throws for it.
|
|
3243
|
+
*/
|
|
3244
|
+
function findIsServableOverGraphQL(search, view) {
|
|
3245
|
+
return !searchNamesIdentifiers(search) && !viewIsPointInTime(view);
|
|
3246
|
+
}
|
|
3247
|
+
/** Rebuilds a relationship edge from its GraphQL fields. */
|
|
3248
|
+
function documentRelationshipFromEdge(edge) {
|
|
3249
|
+
const relationship = {
|
|
3250
|
+
sourceId: edge.sourceId,
|
|
3251
|
+
targetId: edge.targetId,
|
|
3252
|
+
relationshipType: edge.relationshipType,
|
|
3253
|
+
createdAt: dateFromDateTime(edge.createdAt),
|
|
3254
|
+
updatedAt: dateFromDateTime(edge.updatedAt)
|
|
3255
|
+
};
|
|
3256
|
+
const metadata = edge.metadata;
|
|
3257
|
+
if (isPlainObject(metadata)) relationship.metadata = metadata;
|
|
3258
|
+
return relationship;
|
|
3259
|
+
}
|
|
3260
|
+
/**
|
|
3261
|
+
* Restores a `Date` from the `DateTime` scalar, which deserializes as either an
|
|
3262
|
+
* ISO string or a `Date`, reusing the get-path's {@link isoStringFromDateTime}.
|
|
3263
|
+
*
|
|
3264
|
+
* A null, absent or unparseable value is a malformed timestamp from the server,
|
|
3265
|
+
* not something to coerce to the epoch or an `Invalid Date`: it throws, so the
|
|
3266
|
+
* malformed edge surfaces as a genuine failure rather than a silently-wrong
|
|
3267
|
+
* `DocumentRelationship`.
|
|
3268
|
+
*/
|
|
3269
|
+
function dateFromDateTime(value) {
|
|
3270
|
+
if (value === null || value === void 0) throw new Error("relationship edge is missing a required DateTime timestamp");
|
|
3271
|
+
const date = new Date(isoStringFromDateTime(value));
|
|
3272
|
+
if (Number.isNaN(date.getTime())) throw new Error(`relationship edge carries an unparseable DateTime timestamp: ${String(value)}`);
|
|
3273
|
+
return date;
|
|
3274
|
+
}
|
|
3275
|
+
/**
|
|
3276
|
+
* Whether a JSON value is a plain object, so relationship `metadata` is assigned
|
|
3277
|
+
* only when it is one. A non-object JSON scalar (string, number, array, null)
|
|
3278
|
+
* is dropped exactly as a null is, rather than cast to `Record` and trusted.
|
|
3279
|
+
*/
|
|
3280
|
+
function isPlainObject(value) {
|
|
3281
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3282
|
+
}
|
|
3283
|
+
/**
|
|
1802
3284
|
* The reactor and the GraphQL schema disagree on the enum: the reactor's
|
|
1803
3285
|
* `None` is the schema's `ORPHAN`. This is the inverse of the server's
|
|
1804
3286
|
* `toReactorPropagationMode`.
|
|
1805
3287
|
*/
|
|
1806
3288
|
const propagationModeInputs = {
|
|
1807
|
-
cascade:
|
|
1808
|
-
none:
|
|
3289
|
+
cascade: "CASCADE",
|
|
3290
|
+
none: "ORPHAN"
|
|
1809
3291
|
};
|
|
1810
3292
|
function propagationModeInput(propagate) {
|
|
1811
3293
|
return propagate === void 0 ? void 0 : propagationModeInputs[propagate];
|
|
@@ -1841,10 +3323,106 @@ function documentModelVersion(document) {
|
|
|
1841
3323
|
const documentScope = document.state.document;
|
|
1842
3324
|
return normalizeDocumentModelVersion(documentScope?.version);
|
|
1843
3325
|
}
|
|
3326
|
+
/**
|
|
3327
|
+
* Rebuilds a reactor {@link JobInfo} from what the server reported. An unknown
|
|
3328
|
+
* job arrives as the reactor's own: FAILED with an empty `documentId`.
|
|
3329
|
+
*/
|
|
3330
|
+
function jobInfoFromGql(job) {
|
|
3331
|
+
const token = job.consistencyToken;
|
|
3332
|
+
if (token.version !== 1) throw new Error(`Job ${job.id} carries consistency token version ${token.version}, which this client cannot read`);
|
|
3333
|
+
const info = {
|
|
3334
|
+
id: job.id,
|
|
3335
|
+
documentId: job.documentId,
|
|
3336
|
+
status: job.status,
|
|
3337
|
+
createdAtUtcIso: isoStringFromDateTime(job.createdAt),
|
|
3338
|
+
consistencyToken: {
|
|
3339
|
+
version: 1,
|
|
3340
|
+
createdAtUtcIso: token.createdAtUtcIso,
|
|
3341
|
+
coordinates: token.coordinates.map((coordinate) => ({ ...coordinate }))
|
|
3342
|
+
},
|
|
3343
|
+
meta: {
|
|
3344
|
+
batchId: job.meta.batchId,
|
|
3345
|
+
batchJobIds: [...job.meta.batchJobIds]
|
|
3346
|
+
}
|
|
3347
|
+
};
|
|
3348
|
+
if (job.completedAt != null) info.completedAtUtcIso = isoStringFromDateTime(job.completedAt);
|
|
3349
|
+
if (job.result != null) info.result = job.result;
|
|
3350
|
+
if (job.error != null) info.error = {
|
|
3351
|
+
name: job.errorName ?? "Error",
|
|
3352
|
+
message: job.error,
|
|
3353
|
+
stack: ""
|
|
3354
|
+
};
|
|
3355
|
+
return info;
|
|
3356
|
+
}
|
|
3357
|
+
/**
|
|
3358
|
+
* The header a Switchboard's drive middleware and load balancer key on. A
|
|
3359
|
+
* request carries it only when it is known to belong to that one drive: the
|
|
3360
|
+
* server answers any drive it does not own with 421.
|
|
3361
|
+
*/
|
|
3362
|
+
const DRIVE_ID_HEADER = "Drive-Id";
|
|
3363
|
+
function driveIdHeaders(driveId) {
|
|
3364
|
+
return driveId === "" ? void 0 : { [DRIVE_ID_HEADER]: driveId };
|
|
3365
|
+
}
|
|
3366
|
+
function isDrive(document) {
|
|
3367
|
+
return DRIVE_DOCUMENT_TYPES.includes(document.header.documentType);
|
|
3368
|
+
}
|
|
3369
|
+
/**
|
|
3370
|
+
* Surfaces a 421 from the Switchboard's drive middleware, which graphql-request
|
|
3371
|
+
* reports as a `ClientError`, as {@link GraphQLWrongBackendError}.
|
|
3372
|
+
*/
|
|
3373
|
+
function withWrongBackendErrors(middleware) {
|
|
3374
|
+
return async (action, ...rest) => {
|
|
3375
|
+
try {
|
|
3376
|
+
return await middleware(action, ...rest);
|
|
3377
|
+
} catch (error) {
|
|
3378
|
+
throw wrongBackendErrorOf(error) ?? error;
|
|
3379
|
+
}
|
|
3380
|
+
};
|
|
3381
|
+
}
|
|
3382
|
+
function wrongBackendErrorOf(error) {
|
|
3383
|
+
const response = error?.response;
|
|
3384
|
+
if (response?.status !== 421) return;
|
|
3385
|
+
let payload = response.body;
|
|
3386
|
+
if (typeof payload === "string") try {
|
|
3387
|
+
payload = JSON.parse(payload);
|
|
3388
|
+
} catch {}
|
|
3389
|
+
const driveId = payload?.driveId;
|
|
3390
|
+
return new GraphQLWrongBackendError(typeof driveId === "string" ? driveId : "", payload, { cause: error });
|
|
3391
|
+
}
|
|
3392
|
+
function isSettled(job) {
|
|
3393
|
+
const status = job.status;
|
|
3394
|
+
return status === "READ_READY" || status === "FAILED";
|
|
3395
|
+
}
|
|
3396
|
+
function abortReason(signal) {
|
|
3397
|
+
const reason = signal.reason;
|
|
3398
|
+
return reason instanceof Error ? reason : new Error(String(reason));
|
|
3399
|
+
}
|
|
3400
|
+
function delay(ms, signal) {
|
|
3401
|
+
return new Promise((resolve, reject) => {
|
|
3402
|
+
if (signal?.aborted) {
|
|
3403
|
+
reject(abortReason(signal));
|
|
3404
|
+
return;
|
|
3405
|
+
}
|
|
3406
|
+
const onAbort = () => {
|
|
3407
|
+
clearTimeout(timer);
|
|
3408
|
+
if (signal) reject(abortReason(signal));
|
|
3409
|
+
};
|
|
3410
|
+
const timer = setTimeout(() => {
|
|
3411
|
+
signal?.removeEventListener("abort", onAbort);
|
|
3412
|
+
resolve();
|
|
3413
|
+
}, ms);
|
|
3414
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
3415
|
+
});
|
|
3416
|
+
}
|
|
3417
|
+
/** As the reactor's `signAction` reads it: the last tuple names a key. */
|
|
3418
|
+
function isActionSigned(action) {
|
|
3419
|
+
const signer = action.context?.signer;
|
|
3420
|
+
return Boolean(signer?.app?.key && signer.signatures.at(-1)?.[1]);
|
|
3421
|
+
}
|
|
1844
3422
|
/** Resolves the signer of the logged-in user, if there is one. */
|
|
1845
3423
|
function resolveAmbientSigner() {
|
|
1846
3424
|
if (typeof window === "undefined") return;
|
|
1847
|
-
const renown =
|
|
3425
|
+
const renown = getPHStore()?.renown;
|
|
1848
3426
|
return renown?.user ? renown.signer : void 0;
|
|
1849
3427
|
}
|
|
1850
3428
|
/**
|
|
@@ -1865,6 +3443,68 @@ function scopesForActions(actions) {
|
|
|
1865
3443
|
return [...new Set(actions.map((action) => action.scope))];
|
|
1866
3444
|
}
|
|
1867
3445
|
//#endregion
|
|
3446
|
+
//#region src/hooks/backend-auth.ts
|
|
3447
|
+
const backendAuthEventFunctions = makePHEventFunctions("backendAuth");
|
|
3448
|
+
/** Whether the app's backend refused this tab's caller, and how. */
|
|
3449
|
+
const useBackendAuth = backendAuthEventFunctions.useValue;
|
|
3450
|
+
/** Records (or clears, with `undefined`) a backend's refusal of the caller. */
|
|
3451
|
+
const setBackendAuth = backendAuthEventFunctions.setValue;
|
|
3452
|
+
const addBackendAuthEventHandler = backendAuthEventFunctions.addEventHandler;
|
|
3453
|
+
const STATUS_IN_MESSAGE = /\(Code: (401|403)\)/;
|
|
3454
|
+
/**
|
|
3455
|
+
* The messages a Switchboard's GraphQL layer refuses with, without an HTTP
|
|
3456
|
+
* status (the sync layer's `DRIVE_AUTH_ERROR_MESSAGES`). Inlined: this file
|
|
3457
|
+
* is reachable from the browser entry, which must not import the reactor
|
|
3458
|
+
* package as a value.
|
|
3459
|
+
*/
|
|
3460
|
+
const GRAPHQL_REFUSALS = [
|
|
3461
|
+
"Forbidden: insufficient permissions",
|
|
3462
|
+
"Forbidden: authentication required",
|
|
3463
|
+
"Authentication required"
|
|
3464
|
+
];
|
|
3465
|
+
/**
|
|
3466
|
+
* The HTTP status with which a backend refused the caller, or null when the
|
|
3467
|
+
* error is something else.
|
|
3468
|
+
*
|
|
3469
|
+
* Covers every shape a refusal reaches the browser in: the sync layer's
|
|
3470
|
+
* errors (`isDriveAuthError`), graphql-request's `ClientError` from the
|
|
3471
|
+
* remote GraphQL client (`response.status`, and "(Code: 401)" in its
|
|
3472
|
+
* message), and the router's partial-failure error that wraps one such
|
|
3473
|
+
* failure per backend.
|
|
3474
|
+
*/
|
|
3475
|
+
function backendAuthStatusOf(error) {
|
|
3476
|
+
if (!error || typeof error !== "object") return null;
|
|
3477
|
+
const e = error;
|
|
3478
|
+
const direct = [e.response?.status, e.statusCode].find((s) => s === 401 || s === 403);
|
|
3479
|
+
if (direct === 401 || direct === 403) return direct;
|
|
3480
|
+
if (typeof e.message === "string") {
|
|
3481
|
+
const m = STATUS_IN_MESSAGE.exec(e.message);
|
|
3482
|
+
if (m) return m[1] === "401" ? 401 : 403;
|
|
3483
|
+
}
|
|
3484
|
+
if (Array.isArray(e.failures)) for (const failure of e.failures) {
|
|
3485
|
+
const status = backendAuthStatusOf(failure.error);
|
|
3486
|
+
if (status) return status;
|
|
3487
|
+
}
|
|
3488
|
+
if (typeof e.message === "string" && GRAPHQL_REFUSALS.some((m) => e.message.includes(m))) return /authentication required/i.test(e.message) ? 401 : 403;
|
|
3489
|
+
return null;
|
|
3490
|
+
}
|
|
3491
|
+
/** True when a backend refused the caller as unauthenticated or unauthorized. */
|
|
3492
|
+
function isBackendAuthError(error) {
|
|
3493
|
+
return backendAuthStatusOf(error) !== null;
|
|
3494
|
+
}
|
|
3495
|
+
/** Records the refusal `error` carries, if it is one; returns whether it was. */
|
|
3496
|
+
function recordBackendAuthError(error, backend) {
|
|
3497
|
+
const status = backendAuthStatusOf(error);
|
|
3498
|
+
if (status === null) return false;
|
|
3499
|
+
setBackendAuth({
|
|
3500
|
+
requiresAuth: true,
|
|
3501
|
+
status,
|
|
3502
|
+
backend,
|
|
3503
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
3504
|
+
});
|
|
3505
|
+
return true;
|
|
3506
|
+
}
|
|
3507
|
+
//#endregion
|
|
1868
3508
|
//#region src/hooks/config/editor.ts
|
|
1869
3509
|
const isExternalControlsEnabledEventFunctions = makePHEventFunctions("isExternalControlsEnabled");
|
|
1870
3510
|
/** Sets whether external controls are enabled for a given editor. */
|
|
@@ -1885,7 +3525,7 @@ const allowedDocumentTypesEventFunctions = makePHEventFunctions("allowedDocument
|
|
|
1885
3525
|
const setAllowedDocumentTypes = allowedDocumentTypesEventFunctions.setValue;
|
|
1886
3526
|
/** Defines the document types a drive supports.
|
|
1887
3527
|
*
|
|
1888
|
-
*
|
|
3528
|
+
* Unset or empty, it means every document type registered in the reactor.
|
|
1889
3529
|
*/
|
|
1890
3530
|
function useAllowedDocumentTypes() {
|
|
1891
3531
|
return allowedDocumentTypesEventFunctions.useValue();
|
|
@@ -2265,51 +3905,46 @@ const usePackageDiscoveryService = packageDiscoveryFunctions.useValue;
|
|
|
2265
3905
|
const setPackageDiscoveryService = packageDiscoveryFunctions.setValue;
|
|
2266
3906
|
const addPackageDiscoveryServiceEventHandler = packageDiscoveryFunctions.addEventHandler;
|
|
2267
3907
|
//#endregion
|
|
2268
|
-
//#region src/hooks/
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
const
|
|
2273
|
-
|
|
2274
|
-
const
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
const
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
const
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
};
|
|
2296
|
-
//#endregion
|
|
2297
|
-
//#region src/hooks/revision-history.ts
|
|
2298
|
-
const revisionHistoryEventFunctions = makePHEventFunctions("revisionHistoryVisible");
|
|
2299
|
-
/** Returns whether revision history is visible */
|
|
2300
|
-
const useRevisionHistoryVisible = revisionHistoryEventFunctions.useValue;
|
|
2301
|
-
/** Sets revision history visibility */
|
|
2302
|
-
const setRevisionHistoryVisible = revisionHistoryEventFunctions.setValue;
|
|
2303
|
-
/** Adds event handler for revision history visibility */
|
|
2304
|
-
const addRevisionHistoryVisibleEventHandler = revisionHistoryEventFunctions.addEventHandler;
|
|
2305
|
-
/** Shows the revision history */
|
|
2306
|
-
function showRevisionHistory() {
|
|
2307
|
-
setRevisionHistoryVisible(true);
|
|
2308
|
-
}
|
|
2309
|
-
/** Hides the revision history */
|
|
2310
|
-
function hideRevisionHistory() {
|
|
2311
|
-
setRevisionHistoryVisible(false);
|
|
3908
|
+
//#region src/hooks/sync-selection.ts
|
|
3909
|
+
/** Applies a path's selection without writing the URL; idempotent.
|
|
3910
|
+
* @deprecated Set the store's `navigation`; its route loaders write the selection. */
|
|
3911
|
+
function syncSelectionFromPath(pathname = getCurrentPathname()) {
|
|
3912
|
+
const drives = getPHStore()?.drives;
|
|
3913
|
+
if (!drives) return;
|
|
3914
|
+
const driveSlug = extractDriveSlugFromPath(pathname);
|
|
3915
|
+
const selectedDriveId = getPHStore()?.selectedDriveId;
|
|
3916
|
+
if (!driveSlug) {
|
|
3917
|
+
if (selectedDriveId) selectDrive(void 0);
|
|
3918
|
+
return;
|
|
3919
|
+
}
|
|
3920
|
+
const drive = findDriveBySlug(drives, driveSlug);
|
|
3921
|
+
const selectedIsUnlisted = !!selectedDriveId && !drives.some((d) => d.header.id === selectedDriveId);
|
|
3922
|
+
if (drive) {
|
|
3923
|
+
if (drive.header.id !== selectedDriveId) setSelectedDriveId(drive.header.id);
|
|
3924
|
+
} else if (!selectedIsUnlisted) {
|
|
3925
|
+
selectDrive(driveSlug);
|
|
3926
|
+
return;
|
|
3927
|
+
}
|
|
3928
|
+
const nodeId = extractNodeIdFromSlug(extractNodeSlugFromPath(pathname));
|
|
3929
|
+
if (nodeId !== getPHStore()?.selectedNodeId) setSelectedNodeId(nodeId);
|
|
3930
|
+
}
|
|
3931
|
+
setBrowserOpenSync(() => syncSelectionFromPath());
|
|
3932
|
+
function syncOnPopState() {
|
|
3933
|
+
if (hasHostNavigation()) return;
|
|
3934
|
+
syncSelectionFromPath(window.location.pathname);
|
|
2312
3935
|
}
|
|
3936
|
+
let popStateHandlerAdded = false;
|
|
3937
|
+
/** Syncs the selection on back/forward when no host navigation is set.
|
|
3938
|
+
* @deprecated Set the store's `navigation`; its router handles back/forward. */
|
|
3939
|
+
function addSyncSelectionOnPopStateEventHandler() {
|
|
3940
|
+
if (popStateHandlerAdded) return;
|
|
3941
|
+
popStateHandlerAdded = true;
|
|
3942
|
+
window.addEventListener("popstate", syncOnPopState);
|
|
3943
|
+
}
|
|
3944
|
+
/** @deprecated Set the store's `navigation`; its router handles back/forward. */
|
|
3945
|
+
const addSetSelectedDriveOnPopStateEventHandler = addSyncSelectionOnPopStateEventHandler;
|
|
3946
|
+
/** @deprecated Set the store's `navigation`; its router handles back/forward. */
|
|
3947
|
+
const addSetSelectedNodeOnPopStateEventHandler = addSyncSelectionOnPopStateEventHandler;
|
|
2313
3948
|
//#endregion
|
|
2314
3949
|
//#region src/hooks/selected-timeline-item.ts
|
|
2315
3950
|
const selectedTimelineItemEventFunctions = makePHEventFunctions("selectedTimelineItem");
|
|
@@ -2342,14 +3977,15 @@ const addToastEventHandler = toastEventFunctions.addEventHandler;
|
|
|
2342
3977
|
const commonGlobalEventHandlerFunctions = {
|
|
2343
3978
|
loading: addLoadingEventHandler,
|
|
2344
3979
|
drives: addDrivesEventHandler,
|
|
3980
|
+
backendAuth: addBackendAuthEventHandler,
|
|
3981
|
+
driveNodes: addDriveNodesEventHandler,
|
|
2345
3982
|
selectedDriveId: () => {
|
|
2346
3983
|
addSelectedDriveIdEventHandler();
|
|
2347
|
-
|
|
3984
|
+
addSyncSelectionOnPopStateEventHandler();
|
|
2348
3985
|
addResetSelectedNodeEventHandler();
|
|
2349
3986
|
},
|
|
2350
3987
|
selectedNodeId: () => {
|
|
2351
3988
|
addSelectedNodeIdEventHandler();
|
|
2352
|
-
addSetSelectedNodeOnPopStateEventHandler();
|
|
2353
3989
|
},
|
|
2354
3990
|
documentCache: addDocumentCacheEventHandler,
|
|
2355
3991
|
reactorGraphQLClient: addGraphQLReactorClientEventHandler,
|
|
@@ -2359,6 +3995,8 @@ const phGlobalEventHandlerRegisterFunctions = {
|
|
|
2359
3995
|
...commonGlobalEventHandlerFunctions,
|
|
2360
3996
|
reactorClientModule: addReactorClientModuleEventHandler,
|
|
2361
3997
|
reactorClient: addReactorClientEventHandler,
|
|
3998
|
+
reactor: addReactorHalvesEventHandler,
|
|
3999
|
+
fullReactorClient: addFullReactorClientEventHandler,
|
|
2362
4000
|
attachmentService: addAttachmentServiceEventHandler,
|
|
2363
4001
|
features: addFeaturesEventHandler,
|
|
2364
4002
|
modal: addModalEventHandler,
|
|
@@ -2366,7 +4004,6 @@ const phGlobalEventHandlerRegisterFunctions = {
|
|
|
2366
4004
|
vetraPackageManager: addVetraPackageManagerEventHandler,
|
|
2367
4005
|
packageDiscoveryService: addPackageDiscoveryServiceEventHandler,
|
|
2368
4006
|
selectedTimelineRevision: addSelectedTimelineRevisionEventHandler,
|
|
2369
|
-
revisionHistoryVisible: addRevisionHistoryVisibleEventHandler,
|
|
2370
4007
|
selectedTimelineItem: addSelectedTimelineItemEventHandler,
|
|
2371
4008
|
routerBasename: addRouterBasenameEventHandler,
|
|
2372
4009
|
version: addVersionEventHandler,
|
|
@@ -2419,7 +4056,8 @@ const phGlobalEventHandlerRegisterFunctions = {
|
|
|
2419
4056
|
isSentryTracingEnabled: addIsSentryTracingEnabledEventHandler,
|
|
2420
4057
|
isExternalProcessorsEnabled: addIsExternalProcessorsEnabledEventHandler,
|
|
2421
4058
|
isExternalPackagesEnabled: addIsExternalPackagesEnabledEventHandler,
|
|
2422
|
-
toast: addToastEventHandler
|
|
4059
|
+
toast: addToastEventHandler,
|
|
4060
|
+
navigation: () => {}
|
|
2423
4061
|
};
|
|
2424
4062
|
function addPHEventHandlers() {
|
|
2425
4063
|
callEventHandlerRegisterFunctions(phGlobalEventHandlerRegisterFunctions);
|
|
@@ -2515,89 +4153,92 @@ function useSwitchboardClient() {
|
|
|
2515
4153
|
}
|
|
2516
4154
|
//#endregion
|
|
2517
4155
|
//#region src/hooks/document-operations.ts
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
const
|
|
2527
|
-
const
|
|
2528
|
-
const
|
|
2529
|
-
|
|
2530
|
-
localOperations: [],
|
|
2531
|
-
isLoading: !!documentId,
|
|
2532
|
-
error: void 0
|
|
2533
|
-
}));
|
|
2534
|
-
const fetchOperations = useCallback(async (retryCount = 0) => {
|
|
2535
|
-
const MAX_RETRIES = 5;
|
|
2536
|
-
const RETRY_DELAY_MS = 500;
|
|
2537
|
-
if (!documentId || !reactorClient) {
|
|
2538
|
-
setState({
|
|
2539
|
-
globalOperations: [],
|
|
2540
|
-
localOperations: [],
|
|
2541
|
-
isLoading: false,
|
|
2542
|
-
error: void 0
|
|
2543
|
-
});
|
|
2544
|
-
return;
|
|
2545
|
-
}
|
|
2546
|
-
setState((prev) => ({
|
|
2547
|
-
...prev,
|
|
2548
|
-
isLoading: true,
|
|
2549
|
-
error: void 0
|
|
2550
|
-
}));
|
|
2551
|
-
let globalOps = [];
|
|
2552
|
-
let localOps = [];
|
|
2553
|
-
let fetchError;
|
|
2554
|
-
try {
|
|
2555
|
-
globalOps = (await reactorClient.getOperations(documentId, { scopes: ["global"] })).results;
|
|
2556
|
-
} catch (err) {
|
|
2557
|
-
fetchError = err instanceof Error ? err : new Error(String(err));
|
|
2558
|
-
}
|
|
2559
|
-
if (!fetchError) try {
|
|
2560
|
-
localOps = (await reactorClient.getOperations(documentId, { scopes: ["local"] })).results;
|
|
2561
|
-
} catch (err) {
|
|
2562
|
-
fetchError = err instanceof Error ? err : new Error(String(err));
|
|
2563
|
-
}
|
|
2564
|
-
if (!fetchError && globalOps.length === 0 && localOps.length === 0 && retryCount < MAX_RETRIES) {
|
|
2565
|
-
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS));
|
|
2566
|
-
return fetchOperations(retryCount + 1);
|
|
2567
|
-
}
|
|
2568
|
-
setState({
|
|
2569
|
-
globalOperations: globalOps,
|
|
2570
|
-
localOperations: localOps,
|
|
2571
|
-
isLoading: false,
|
|
2572
|
-
error: fetchError
|
|
2573
|
-
});
|
|
2574
|
-
hasFetchedRef.current = true;
|
|
2575
|
-
}, [documentId, reactorClient]);
|
|
4156
|
+
const DEFAULT_LIMIT = 100;
|
|
4157
|
+
function toError(reason) {
|
|
4158
|
+
return reason instanceof Error ? reason : new Error(String(reason));
|
|
4159
|
+
}
|
|
4160
|
+
const EMPTY_OPERATIONS = [];
|
|
4161
|
+
function useScopeOperations(documentId, scope, options = {}) {
|
|
4162
|
+
const { limit = DEFAULT_LIMIT, enabled = true } = options;
|
|
4163
|
+
const documentCache = useDocumentCache();
|
|
4164
|
+
const cache = documentCache && isOperationCache(documentCache) ? documentCache : void 0;
|
|
4165
|
+
const activeId = enabled && cache && documentId ? documentId : void 0;
|
|
4166
|
+
const getEntry = () => activeId && cache ? cache.getOperationsState(activeId, scope) : IDLE_OPERATIONS_ENTRY;
|
|
4167
|
+
const entry = useSyncExternalStore((onChange) => activeId && cache ? cache.subscribeOperations(activeId, onChange) : () => {}, getEntry, getEntry);
|
|
2576
4168
|
useEffect(() => {
|
|
2577
|
-
if (
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
4169
|
+
if (activeId && cache && entry.status === "idle") cache.loadOperations(activeId, scope, limit);
|
|
4170
|
+
}, [
|
|
4171
|
+
activeId,
|
|
4172
|
+
cache,
|
|
4173
|
+
scope,
|
|
4174
|
+
limit,
|
|
4175
|
+
entry.status
|
|
4176
|
+
]);
|
|
4177
|
+
const fetchNextPage = useCallback(() => {
|
|
4178
|
+
if (activeId && cache) cache.loadMoreOperations(activeId, scope);
|
|
2587
4179
|
}, [
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
4180
|
+
activeId,
|
|
4181
|
+
cache,
|
|
4182
|
+
scope
|
|
2591
4183
|
]);
|
|
2592
4184
|
const refetch = useCallback(() => {
|
|
2593
|
-
|
|
2594
|
-
}, [
|
|
4185
|
+
if (activeId && cache) cache.invalidateOperations(activeId);
|
|
4186
|
+
}, [activeId, cache]);
|
|
4187
|
+
const error = useMemo(() => entry.status === "error" ? toError(entry.error) : void 0, [entry.status, entry.error]);
|
|
2595
4188
|
return {
|
|
2596
|
-
|
|
4189
|
+
operations: entry.operations,
|
|
4190
|
+
isLoading: entry.status === "pending" || !!activeId && entry.status === "idle",
|
|
4191
|
+
error,
|
|
4192
|
+
hasNextPage: entry.hasNextPage,
|
|
4193
|
+
fetchNextPage,
|
|
2597
4194
|
refetch
|
|
2598
4195
|
};
|
|
2599
4196
|
}
|
|
4197
|
+
/** Keeps paging `result` to completion while `enabled` is true. */
|
|
4198
|
+
function useLoadAllPages(result, enabled) {
|
|
4199
|
+
useEffect(() => {
|
|
4200
|
+
if (!enabled || !result.hasNextPage || result.isLoading) return;
|
|
4201
|
+
const handle = window.setTimeout(result.fetchNextPage, 0);
|
|
4202
|
+
return () => window.clearTimeout(handle);
|
|
4203
|
+
}, [
|
|
4204
|
+
enabled,
|
|
4205
|
+
result.hasNextPage,
|
|
4206
|
+
result.isLoading,
|
|
4207
|
+
result.fetchNextPage
|
|
4208
|
+
]);
|
|
4209
|
+
}
|
|
4210
|
+
function useDocumentOperations(documentId, scope, options = {}) {
|
|
4211
|
+
const legacy = scope === void 0;
|
|
4212
|
+
const primary = useScopeOperations(documentId, legacy ? "global" : scope, legacy ? {} : options);
|
|
4213
|
+
const local = useScopeOperations(documentId, "local", { enabled: legacy });
|
|
4214
|
+
useLoadAllPages(primary, legacy);
|
|
4215
|
+
useLoadAllPages(local, legacy);
|
|
4216
|
+
const globalOperations = useMemo(() => legacy ? [...primary.operations] : EMPTY_OPERATIONS, [legacy, primary.operations]);
|
|
4217
|
+
const localOperations = useMemo(() => legacy ? [...local.operations] : EMPTY_OPERATIONS, [legacy, local.operations]);
|
|
4218
|
+
const refetch = useCallback(() => {
|
|
4219
|
+
primary.refetch();
|
|
4220
|
+
local.refetch();
|
|
4221
|
+
}, [primary.refetch, local.refetch]);
|
|
4222
|
+
const error = primary.error ?? local.error;
|
|
4223
|
+
const legacyResult = useMemo(() => ({
|
|
4224
|
+
globalOperations,
|
|
4225
|
+
localOperations,
|
|
4226
|
+
isLoading: !error && (primary.isLoading || local.isLoading || primary.hasNextPage || local.hasNextPage),
|
|
4227
|
+
error,
|
|
4228
|
+
refetch
|
|
4229
|
+
}), [
|
|
4230
|
+
globalOperations,
|
|
4231
|
+
localOperations,
|
|
4232
|
+
error,
|
|
4233
|
+
primary.isLoading,
|
|
4234
|
+
local.isLoading,
|
|
4235
|
+
primary.hasNextPage,
|
|
4236
|
+
local.hasNextPage,
|
|
4237
|
+
refetch
|
|
4238
|
+
]);
|
|
4239
|
+
return legacy ? legacyResult : primary;
|
|
4240
|
+
}
|
|
2600
4241
|
//#endregion
|
|
2601
|
-
export {
|
|
4242
|
+
export { addIsAnalyticsExternalProcessorsEnabledEventHandler as $, getUserPermissions as $i, useIsEditorDebugModeEnabled as $n, subscriptionsUrlFromGraphqlUrl as $r, setIsDeleteLocalDrivesEnabled as $t, useDropTarget as A, withoutModalSearch as Aa, DEFAULT_DRIVE_EDITOR_ID as Ai, useAnalyticsDatabaseName as An, phDocumentEditorConfigHooks as Ar, addVersionEventHandler as At, addCliVersionEventHandler as B, addFolder$1 as Bi, useIsAddDriveEnabled as Bn, isBackendAuthError as Br, setDrivesPreserveStrategy as Bt, usePackageDiscoveryService as C, modalSearch as Ca, convertRemoteOperations as Ci, setSentryRelease as Cn, useWarnOutdatedApp as Cr, addRouterBasenameEventHandler as Ct, addDraggingNodeEventHandler as D, showPHModal as Da, uncreatedDocument as Di, setVersionCheckInterval as Dn, isExternalControlsEnabledEventFunctions as Dr, addStudioModeEventHandler as Dt, useGraphQLReactorClient as E, showDeleteNodeModal as Ea, screamingSnakeToCamel as Ei, setVersion as En, addIsExternalControlsEnabledEventHandler as Er, addSentryReleaseEventHandler as Et, setAttachmentService as F, useSetSearchParams as Fa, JobFailedError as Fi, useDrivesPreserveStrategy as Fn, useAllowedDocumentTypes as Fr, setAnalyticsDatabaseName as Ft, addFileUploadOperationsChunkSizeEventHandler as G, fetchDocumentOperations as Gi, useIsAnalyticsExternalProcessorsEnabled as Gn, createGraphQLDriveNodeSource as Gr, setIsAddDriveEnabled as Gt, addDisabledEditorsEventHandler as H, deleteNode as Hi, useIsAddPublicDrivesEnabled as Hn, setBackendAuth as Hr, setFileUploadOperationsChunkSize as Ht, useAttachmentService as I, queriesUnknownArgument as Ii, useEnabledEditors as In, useIsDragAndDropEnabled as Ir, setBasePath as It, addIsAddDriveEnabledEventHandler as J, moveNode$1 as Ji, useIsDeleteLocalDrivesEnabled as Jn, viewFilterInputFromViewFilter as Jr, setIsAnalyticsDatabaseWorkerEnabled as Jt, addGaTrackingIdEventHandler as K, getDocumentExtension as Ki, useIsCloudDrivesEnabled as Kn, findIsServableOverGraphQL as Kr, setIsAddLocalDrivesEnabled as Kt, addAllowListEventHandler as L, queriesUnknownField as Li, useFileUploadOperationsChunkSize as Ln, useIsExternalControlsEnabled as Lr, setCliVersion as Lt, setFeatures as M, useLinkProps as Ma, BatchJobFailedError as Mi, useCliVersion as Mn, setAllowedDocumentTypes as Mr, phGlobalConfigHooks as Mt, useFeatures as N, usePHNavigation as Na, GraphQLOperationNotSupportedError as Ni, useDefaultDrivesUrl as Nn, setIsDragAndDropEnabled as Nr, phGlobalConfigSetters as Nt, useDragNode as O, useModalLinkProps as Oa, underSignaturePolicy as Oi, setWarnOutdatedApp as On, phAppConfigHooks as Or, addSwitchboardUrlEventHandler as Ot, addAttachmentServiceEventHandler as P, useSearchParams as Pa, GraphQLWrongBackendError as Pi, useDisabledEditors as Pn, setIsExternalControlsEnabled as Pr, setAllowList as Pt, addIsAnalyticsEnabledEventHandler as Q, upgradeDocument as Qi, useIsDriveAnalyticsEnabled as Qn, startDocumentChangesSubscription as Qr, setIsDeleteCloudDrivesEnabled as Qt, addAnalyticsDatabaseNameEventHandler as R, addDocument as Ri, useGaTrackingId as Rn, addBackendAuthEventHandler as Rr, setDefaultDrivesUrl as Rt, setPackageDiscoveryService as S, modalHref as Sa, buildPulledDocument as Si, setSentryEnv as Sn, useVersionCheckInterval as Sr, addRequiresHardRefreshEventHandler as St, setGraphQLReactorClient as T, showCreateDocumentModal as Ta, hasRevisionConflict as Ti, setSwitchboardUrl as Tn, addIsDragAndDropEnabledEventHandler as Tr, addSentryEnvEventHandler as Tt, addDrivesPreserveStrategyEventHandler as U, exportFile as Ui, useIsAnalyticsDatabaseWorkerEnabled as Un, useBackendAuth as Ur, setGaTrackingId as Ut, addDefaultDrivesUrlEventHandler as V, copyNode$1 as Vi, useIsAddLocalDrivesEnabled as Vn, recordBackendAuthError as Vr, setEnabledEditors as Vt, addEnabledEditorsEventHandler as W, extractInitialState as Wi, useIsAnalyticsEnabled as Wn, GraphQLReactorClient as Wr, setIsAddCloudDrivesEnabled as Wt, addIsAddPublicDrivesEnabledEventHandler as X, renameNode as Xi, useIsDiffAnalyticsEnabled as Xn, isAuthRefusalClose as Xr, setIsAnalyticsExternalProcessorsEnabled as Xt, addIsAddLocalDrivesEnabledEventHandler as Y, renameDriveNode as Yi, useIsDeletePublicDrivesEnabled as Yn, createJobChangesSocket as Yr, setIsAnalyticsEnabled as Yt, addIsAnalyticsDatabaseWorkerEnabledEventHandler as Z, setPreferredEditorOnNode as Zi, useIsDocumentModelSelectionSettingsEnabled as Zn, makeAuthConnectionParams as Zr, setIsCloudDrivesEnabled as Zt, addSetSelectedDriveOnPopStateEventHandler as _, MODAL_SEARCH_PARAM as _a, isoStringFromDateTime as _i, setRenownNetworkId as _n, useSentryEnv as _r, addLogLevelEventHandler as _t, addPHEventHandlers as a, getFullReactorClient as aa, resolveDocumentModelModule as ai, setIsEditorReadModeEnabled as an, useIsPublicDrivesEnabled as ar, addIsDocumentModelSelectionSettingsEnabledEventHandler as at, syncSelectionFromPath as b, isRoutedModal as ba, revisionMapFromRevisionsList as bi, setRouterBasename as bn, useSwitchboardUrl as br, addRenownNetworkIdEventHandler as bt, addToastEventHandler as c, setReactorClientModule as ca, stampAction as ci, setIsExternalRelationalProcessorsEnabled as cn, useLocalDrivesEnabled as cr, addIsEditorReadModeEnabledEventHandler as ct, addSelectedTimelineRevisionEventHandler as d, usePGlite as da, ReactorOperationFieldsFragmentDoc as di, setIsRelationalProcessorsEnabled as dn, useRenownChainId as dr, addIsExternalRelationalProcessorsEnabledEventHandler as dt, isDocumentTypeSupported as ea, SubgraphSdkRegistry as ei, setIsDeletePublicDrivesEnabled as en, useIsEditorReadModeEnabled as er, addIsCloudDrivesEnabledEventHandler as et, setSelectedTimelineRevision as f, useReactorClient as fa, readCreateProtocolVersions as fi, setIsSentryTracingEnabled as fn, useRenownNetworkId as fr, addIsLocalDrivesEnabledEventHandler as ft, useSelectedTimelineItem as g, useSyncList as ga, toLegacyNode as gi, setRenownChainId as gn, useSentryDsn as gr, addLocalDrivesEnabledEventHandler as gt, setSelectedTimelineItem as h, useSync as ha, GraphQLDriveReadClient as hi, setRenownAdapters as hn, useRouterBasename as hr, addIsSentryTracingEnabledEventHandler as ht, useSwitchboardClient as i, addReactorHalvesEventHandler as ia, packageFromDocumentModels as ii, setIsEditorDebugModeEnabled as in, useIsLocalDrivesEnabled as ir, addIsDiffAnalyticsEnabledEventHandler as it, addFeaturesEventHandler as j, isPlainClick as ja, DRIVE_DOCUMENT_TYPES as ji, useBasePath as jn, phDocumentEditorConfigSetters as jr, addWarnOutdatedAppEventHandler as jt, useDropNode as k, usePHModal as ka, COMMON_PACKAGE_ID as ki, useAllowList as kn, phAppConfigSetters as kr, addVersionCheckIntervalEventHandler as kt, setPHToast as l, useDatabase as la, GetDocumentAtConsistencyDocument as li, setIsLocalDrivesEnabled as ln, useLogLevel as lr, addIsExternalPackagesEnabledEventHandler as lt, addSelectedTimelineItemEventHandler as m, useReactorHalves as ma, GraphQLDriveNodeSource as mi, setLogLevel as mn, useRequiresHardRefresh as mr, addIsRelationalProcessorsEnabledEventHandler as mt, GraphQLReactorProvider as n, addReactorClientEventHandler as na, subgraphUrlFromGraphqlUrl as ni, setIsDocumentModelSelectionSettingsEnabled as nn, useIsExternalProcessorsEnabled as nr, addIsDeleteLocalDrivesEnabledEventHandler as nt, callEventHandlerRegisterFunctions as o, setFullReactorClient as oa, prepareSignedActions as oi, setIsExternalPackagesEnabled as on, useIsRelationalProcessorsEnabled as or, addIsDriveAnalyticsEnabledEventHandler as ot, useSelectedTimelineRevision as p, useReactorClientModule as pa, readCreateSignaturePolicy as pi, setLocalDrivesEnabled as pn, useRenownUrl as pr, addIsPublicDrivesEnabledEventHandler as pt, addIsAddCloudDrivesEnabledEventHandler as q, loadFile as qi, useIsDeleteCloudDrivesEnabled as qn, isGraphQLReactorClient as qr, setIsAddPublicDrivesEnabled as qt, ensurePHEventHandlers as r, addReactorClientModuleEventHandler as ra, StaticPackageManager as ri, setIsDriveAnalyticsEnabled as rn, useIsExternalRelationalProcessorsEnabled as rr, addIsDeletePublicDrivesEnabledEventHandler as rt, commonGlobalEventHandlerFunctions as s, setReactorClient as sa, signStampedAction as si, setIsExternalProcessorsEnabled as sn, useIsSentryTracingEnabled as sr, addIsEditorDebugModeEnabledEventHandler as st, useDocumentOperations as t, addFullReactorClientEventHandler as ta, describeGraphQLDocument as ti, setIsDiffAnalyticsEnabled as tn, useIsExternalPackagesEnabled as tr, addIsDeleteCloudDrivesEnabledEventHandler as tt, usePHToast as u, useModelRegistry as ua, MutateDocumentWithOperationsDocument as ui, setIsPublicDrivesEnabled as un, useRenownAdapters as ur, addIsExternalProcessorsEnabledEventHandler as ut, addSetSelectedNodeOnPopStateEventHandler as v, addModalEventHandler as va, phDocumentFromGetDocument as vi, setRenownUrl as vn, useSentryRelease as vr, addRenownAdaptersEventHandler as vt, addGraphQLReactorClientEventHandler as w, setPHModal as wa, extractRevisionMap as wi, setStudioMode as wn, addAllowedDocumentTypesEventHandler as wr, addSentryDsnEventHandler as wt, addPackageDiscoveryServiceEventHandler as x, modalFromSearch as xa, ConflictError as xi, setSentryDsn as xn, useVersion as xr, addRenownUrlEventHandler as xt, addSyncSelectionOnPopStateEventHandler as y, closePHModal as ya, phDocumentFromMutation as yi, setRequiresHardRefresh as yn, useStudioMode as yr, addRenownChainIdEventHandler as yt, addBasePathEventHandler as z, addFileWithProgress as zi, useIsAddCloudDrivesEnabled as zn, backendAuthStatusOf as zr, setDisabledEditors as zt };
|
|
2602
4243
|
|
|
2603
|
-
//# sourceMappingURL=document-operations-
|
|
4244
|
+
//# sourceMappingURL=document-operations-CdfiLNQN.js.map
|