@powerhousedao/reactor-browser 6.2.3-dev.10 → 6.2.3-dev.100

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.
Files changed (106) hide show
  1. package/dist/{attachment-service-BW1v0OAT.d.ts → attachment-service-DXfpfp98.d.ts} +767 -108
  2. package/dist/attachment-service-DXfpfp98.d.ts.map +1 -0
  3. package/dist/auth-DzIYxeEJ.d.ts +32 -0
  4. package/dist/auth-DzIYxeEJ.d.ts.map +1 -0
  5. package/dist/client-1n_ZUXeu.js +135 -0
  6. package/dist/client-1n_ZUXeu.js.map +1 -0
  7. package/dist/{client-CxJD0Ck2.d.ts → client-BFk0MY6A.d.ts} +4 -3
  8. package/dist/client-BFk0MY6A.d.ts.map +1 -0
  9. package/dist/{client-DjK30EQ-.js → client-BFnMV-EO.js} +39 -22
  10. package/dist/client-BFnMV-EO.js.map +1 -0
  11. package/dist/dispatch-Cylwl2Dk.js +1173 -0
  12. package/dist/dispatch-Cylwl2Dk.js.map +1 -0
  13. package/dist/document-by-id-DdvqanGR.js +16 -0
  14. package/dist/document-by-id-DdvqanGR.js.map +1 -0
  15. package/dist/document-model-modules-BG-61uke.js +710 -0
  16. package/dist/document-model-modules-BG-61uke.js.map +1 -0
  17. package/dist/document-operations-D5QXcJbV.js +4609 -0
  18. package/dist/document-operations-D5QXcJbV.js.map +1 -0
  19. package/dist/global-DAAmZGCO.d.ts +612 -0
  20. package/dist/global-DAAmZGCO.d.ts.map +1 -0
  21. package/dist/{index-CBjFO54H.d.ts → index-Bj1poVfa.d.ts} +31 -100
  22. package/dist/index-Bj1poVfa.d.ts.map +1 -0
  23. package/dist/{index-BIVDXw3K.d.ts → index-rtDmzViP.d.ts} +3 -3
  24. package/dist/index-rtDmzViP.d.ts.map +1 -0
  25. package/dist/index.d.ts +907 -411
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +851 -306
  28. package/dist/index.js.map +1 -1
  29. package/dist/inspector-proxy-DODqs15F.d.ts +25 -0
  30. package/dist/inspector-proxy-DODqs15F.d.ts.map +1 -0
  31. package/dist/make-ph-event-functions-B5GU5xcR.js +180 -0
  32. package/dist/make-ph-event-functions-B5GU5xcR.js.map +1 -0
  33. package/dist/{pglite-CntadC_p-9NDG14dS.d.ts → pglite-CntadC_p-DTkdF8sr.d.ts} +11 -33
  34. package/dist/pglite-CntadC_p-DTkdF8sr.d.ts.map +1 -0
  35. package/dist/{relational-D1RB45sA.js → relational-DZuyKp2y.js} +66 -5
  36. package/dist/relational-DZuyKp2y.js.map +1 -0
  37. package/dist/{renown-rqK8sokh.js → renown-B3MUaiq7.js} +61 -31
  38. package/dist/renown-B3MUaiq7.js.map +1 -0
  39. package/dist/renown-CBoTdGrg.js +394 -0
  40. package/dist/renown-CBoTdGrg.js.map +1 -0
  41. package/dist/{types-N3Jy6Nry.d.ts → schema-Bn6L3QR1.d.ts} +255 -65
  42. package/dist/schema-Bn6L3QR1.d.ts.map +1 -0
  43. package/dist/{client-D4bkR4pH.js → schema-D0G1oAo9.js} +247 -152
  44. package/dist/schema-D0G1oAo9.js.map +1 -0
  45. package/dist/src/ai/index.d.ts +313 -79
  46. package/dist/src/ai/index.d.ts.map +1 -1
  47. package/dist/src/ai/index.js +1030 -173
  48. package/dist/src/ai/index.js.map +1 -1
  49. package/dist/src/analytics/index.d.ts +36 -44
  50. package/dist/src/analytics/index.d.ts.map +1 -1
  51. package/dist/src/analytics/index.js +4 -4
  52. package/dist/src/analytics/index.js.map +1 -1
  53. package/dist/src/document-model.d.ts +3 -4
  54. package/dist/src/document-model.d.ts.map +1 -1
  55. package/dist/src/document-model.js.map +1 -1
  56. package/dist/src/graphql/client.d.ts +4 -3
  57. package/dist/src/graphql/client.js +1 -1
  58. package/dist/src/graphql-client/entry.d.ts +7 -4
  59. package/dist/src/graphql-client/entry.js +4 -4
  60. package/dist/src/relational/index.d.ts +15 -9
  61. package/dist/src/relational/index.d.ts.map +1 -1
  62. package/dist/src/relational/index.js +1 -1
  63. package/dist/src/renown/index.d.ts +3 -2
  64. package/dist/src/renown/index.js +3 -3
  65. package/dist/src/rpc/index.d.ts +217 -140
  66. package/dist/src/rpc/index.d.ts.map +1 -1
  67. package/dist/src/rpc/index.js +600 -623
  68. package/dist/src/rpc/index.js.map +1 -1
  69. package/dist/{store-BJYcr_FL.js → store-DInXcjal.js} +1 -1
  70. package/dist/{store-BJYcr_FL.js.map → store-DInXcjal.js.map} +1 -1
  71. package/dist/switchboard-directory-CWf5SRo7.js +435 -0
  72. package/dist/switchboard-directory-CWf5SRo7.js.map +1 -0
  73. package/dist/switchboards-D-_JBUbF.d.ts +75 -0
  74. package/dist/switchboards-D-_JBUbF.d.ts.map +1 -0
  75. package/dist/{types-6vDzbRRS.d.ts → types-520nWrB3.d.ts} +2 -2
  76. package/dist/types-520nWrB3.d.ts.map +1 -0
  77. package/dist/types-CyPDurGV.d.ts +63 -0
  78. package/dist/types-CyPDurGV.d.ts.map +1 -0
  79. package/package.json +24 -23
  80. package/dist/attachment-service-BW1v0OAT.d.ts.map +0 -1
  81. package/dist/client-CxJD0Ck2.d.ts.map +0 -1
  82. package/dist/client-D4bkR4pH.js.map +0 -1
  83. package/dist/client-DjK30EQ-.js.map +0 -1
  84. package/dist/document-by-id-B4FIzG1w.js +0 -519
  85. package/dist/document-by-id-B4FIzG1w.js.map +0 -1
  86. package/dist/document-model-modules-bTP87nyr.js +0 -419
  87. package/dist/document-model-modules-bTP87nyr.js.map +0 -1
  88. package/dist/document-operations-Cm4EtaZs.js +0 -2603
  89. package/dist/document-operations-Cm4EtaZs.js.map +0 -1
  90. package/dist/global-CgCouXuH.d.ts +0 -401
  91. package/dist/global-CgCouXuH.d.ts.map +0 -1
  92. package/dist/index-BIVDXw3K.d.ts.map +0 -1
  93. package/dist/index-CBjFO54H.d.ts.map +0 -1
  94. package/dist/inspector-proxy-6h5VKAwt.d.ts +0 -257
  95. package/dist/inspector-proxy-6h5VKAwt.d.ts.map +0 -1
  96. package/dist/make-ph-event-functions-DBq3iWYn.js +0 -53
  97. package/dist/make-ph-event-functions-DBq3iWYn.js.map +0 -1
  98. package/dist/pglite-CntadC_p-9NDG14dS.d.ts.map +0 -1
  99. package/dist/relational-D1RB45sA.js.map +0 -1
  100. package/dist/renown-BHxwP7xU.js +0 -97
  101. package/dist/renown-BHxwP7xU.js.map +0 -1
  102. package/dist/renown-rqK8sokh.js.map +0 -1
  103. package/dist/switchboard-CaXQ4-5Q.js +0 -271
  104. package/dist/switchboard-CaXQ4-5Q.js.map +0 -1
  105. package/dist/types-6vDzbRRS.d.ts.map +0 -1
  106. package/dist/types-N3Jy6Nry.d.ts.map +0 -1
@@ -1,34 +1,84 @@
1
- import { a as PHGlobal$1, b as IPackagesListener, ct as PromiseWithState, d as UsePHGlobalValue$1, ot as IDocumentCache, rt as IReactorBrowserClient$1, st as PromiseState, u as SetPHGlobalValue$1, v as IPackageListerUnsubscribe, x as PackageManagerInstallResult, y as IPackageManager } from "./global-CgCouXuH.js";
2
- import { t as PGlite } from "./pglite-CntadC_p-9NDG14dS.js";
3
- import { A as ViewFilterInput, C as GetDocumentQuery, D as PropagationMode$1, E as PhDocumentFieldsFragment, O as Scalars, S as GetDocumentOperationsQuery, b as DocumentChangesSubscription, c as ReactorGraphQLClient, g as ActionInput, k as SdkFunctionWrapper } from "./types-N3Jy6Nry.js";
4
- import { Action, DocumentModelLib, DocumentModelModule, Operation, PHDocument } from "document-model";
5
- import { Action as Action$1, DocumentModelModule as DocumentModelModule$1, DocumentOperations, ISigner, Operation as Operation$1, PHBaseState, PHDocument as PHDocument$1, PHDocumentHeader } from "@powerhousedao/shared/document-model";
6
- import * as _powerhousedao_reactor0 from "@powerhousedao/reactor";
7
- import { Database, DocumentChangeEvent, DocumentModelSource, IDocumentModelRegistry, ISyncManager, OperationFilter, PagedResults, PagingOptions, PropagationMode, SearchFilter, ViewFilter } from "@powerhousedao/reactor";
1
+ import { _ as Sdk, a as DocumentChangesSubscription, c as GetDocumentQuery, g as Scalars, h as PropagationMode$1, m as PhDocumentFieldsFragment, s as GetDocumentOperationsQuery, t as ActionInput, u as JobChangesSubscription, v as SdkFunctionWrapper, y as ViewFilterInput } from "./schema-Bn6L3QR1.js";
2
+ import { t as BearerTokenProvider } from "./auth-DzIYxeEJ.js";
3
+ import { $ as IPackageManager, Gt as PromiseState, Ht as IDocumentTypeCache, Kt as PromiseWithState, Q as IPackageListerUnsubscribe, Rt as DocumentRefetchState, Ut as IOperationCache, Vt as IDocumentCache, Wt as OperationsCacheEntry, b as UsePHGlobalValue$1, et as IPackagesListener, s as PHGlobal$1, tt as PackageManagerInstallResult, v as SetPHGlobalValue$1, zt as DocumentsOfTypeEntry } from "./global-DAAmZGCO.js";
4
+ import { a as IReactorBrowserReadClient, i as IReactorBrowserClient$1, o as IReactorBrowserWriteClient } from "./switchboards-D-_JBUbF.js";
5
+ import { t as PGlite } from "./pglite-CntadC_p-DTkdF8sr.js";
6
+ import { c as ReactorGraphQLClient } from "./types-CyPDurGV.js";
8
7
  import { ReactNode } from "react";
9
- import { GraphQLClient, Variables } from "graphql-request";
10
- import * as graphql from "graphql";
8
+ import { Action, DocumentModelLib, DocumentModelModule, Operation, PHDocument } from "document-model";
9
+ import { Action as Action$1, ActionSigningTarget, DispatchOutcome, DocumentModelModule as DocumentModelModule$1, DocumentOperations, ISigner, Operation as Operation$1, PHBaseState, PHDocument as PHDocument$1, PHDocumentHeader, ProtocolVersions, SignaturePolicy } from "@powerhousedao/shared/document-model";
10
+ import { BatchExecutionRequest, BatchExecutionResult, ConsistencyToken, CreateProtocolVersionsOptions, Database, DocumentChangeEvent, DocumentModelSource, DocumentRelationship, DriveNodeKind, DriveNodePage, DriveNodeRecord, IDocumentModelRegistry, IDriveNodeSource, IDriveReadClient, IReactorClient, ISyncManager, JobInfo, NewDocumentOptions, OperationFilter, PagedResults, PagingOptions, PropagationMode, SearchFilter, UndoRedoAvailability, UndoRedoTargets, ViewFilter } from "@powerhousedao/reactor";
11
+ import { Node } from "@powerhousedao/shared/document-drive";
11
12
  import { DocumentNode } from "graphql";
12
- import * as react_jsx_runtime0 from "react/jsx-runtime";
13
+ import { GraphQLClient, Variables } from "graphql-request";
13
14
  import { IAttachmentService } from "@powerhousedao/reactor-attachments/client";
14
15
  import { Kysely } from "kysely";
15
- import { AddPHGlobalEventHandler, BrowserReactorClientModule, IReactorBrowserClient, SetPHGlobalValue, UsePHGlobalValue, WorkerReactorClientModule } from "@powerhousedao/reactor-browser";
16
+ import { AddPHGlobalEventHandler, BrowserReactorClientModule, IReactorBrowserClient, ReactorBrowserHalves, SetPHGlobalValue, UsePHGlobalValue, WorkerReactorClientModule } from "@powerhousedao/reactor-browser";
16
17
  import { RegistryPackageSource } from "@powerhousedao/shared";
17
-
18
+ import { ReactorReach, RoutableBackendConfig } from "@powerhousedao/reactor-router";
19
+ //#region src/actions/dispatch.d.ts
20
+ /** Called once the write lands; `outcome.rejected` is empty when every action applied. */
21
+ type DispatchSuccessCallback = (result: PHDocument$1, outcome: DispatchOutcome) => void;
22
+ /**
23
+ * Dispatches actions to a document.
24
+ * @param actionOrActions - The action or actions to dispatch.
25
+ * @param document - The document to dispatch actions to.
26
+ * @param onErrors - Callback invoked with an `OperationRejectedError` for each action the
27
+ * document did not apply, or with why nothing was dispatched. Runs before `onSuccess`.
28
+ * @param onSuccess - Callback invoked with the updated document once the write lands, after
29
+ * `onErrors` and also when an action was rejected; `outcome.rejected` lists the rejections.
30
+ * @returns The updated document, or undefined if the dispatch failed.
31
+ */
32
+ declare function dispatchActions<TDocument = PHDocument$1, TAction = Action$1>(actionOrActions: TAction[] | TAction | undefined, document: TDocument | undefined, onErrors?: (errors: Error[]) => void, onSuccess?: DispatchSuccessCallback): Promise<PHDocument$1 | undefined>;
33
+ /**
34
+ * Dispatches actions to a document.
35
+ * @param actionOrActions - The action or actions to dispatch.
36
+ * @param documentId - The ID of the document to dispatch actions to.
37
+ * @param onErrors - Callback invoked with an `OperationRejectedError` for each action the
38
+ * document did not apply. Runs before `onSuccess`.
39
+ * @param onSuccess - Callback invoked with the updated document once the write lands, after
40
+ * `onErrors` and also when an action was rejected; `outcome.rejected` lists the rejections.
41
+ * @returns The updated document, or undefined if the dispatch failed.
42
+ */
43
+ declare function dispatchActions(actionOrActions: Action$1[] | Action$1 | undefined, documentId: string, onErrors?: (errors: Error[]) => void, onSuccess?: DispatchSuccessCallback): Promise<PHDocument$1 | undefined>;
44
+ //#endregion
45
+ //#region src/document-refetcher.d.ts
46
+ /** The refetch snapshot of a document with nothing in flight and no kept failure. */
47
+ declare const IDLE_REFETCH_STATE: DocumentRefetchState;
48
+ //#endregion
18
49
  //#region src/document-cache.d.ts
50
+ /**
51
+ * The reads a {@link DocumentCache} makes. `getMany` is optional: without it,
52
+ * a batch reads each uncached id with `get`.
53
+ */
54
+ interface IDocumentCacheReader extends Pick<IReactorBrowserReadClient, "get" | "find" | "getOperations" | "subscribe">, Partial<Pick<IReactorBrowserReadClient, "getMany">> {}
55
+ /** The most ids one `getMany` call is asked for. */
56
+ declare const GET_MANY_CHUNK_SIZE = 100;
19
57
  declare function addPromiseState<T>(promise: Promise<T>): PromiseWithState<T>;
20
58
  declare function readPromiseState<T>(promise: Promise<T> | PromiseWithState<T>): PromiseState<T>;
59
+ /** The snapshot every uncached document scope reads as. One frozen object, so `useSyncExternalStore` sees a stable value. */
60
+ declare const IDLE_OPERATIONS_ENTRY: OperationsCacheEntry;
61
+ /** Whether a document cache also serves operation history. `GraphQLClientDocumentCache` does not. */
62
+ declare function isOperationCache(cache: unknown): cache is IOperationCache;
63
+ /** The snapshot every unloaded type reads as, frozen so `useSyncExternalStore` sees one value. */
64
+ declare const IDLE_DOCUMENTS_OF_TYPE_ENTRY: DocumentsOfTypeEntry;
65
+ /** Whether a document cache also lists documents by type. */
66
+ declare function isDocumentTypeCache(cache: unknown): cache is IDocumentTypeCache;
21
67
  /**
22
68
  * Document cache implementation that uses the new ReactorClient API.
23
69
  *
24
- * This cache subscribes to document change events via IReactorBrowserClient.subscribe()
70
+ * This cache subscribes to document change events through the client's read half
25
71
  * and automatically updates the cache when documents are created, updated, or deleted.
72
+ * It is built over a browser client, whose `read` half it uses, or over a read
73
+ * half directly.
74
+ * It also holds paginated operation history per document scope (see `IOperationCache`),
75
+ * which is dropped for a document whenever a change event for it arrives.
26
76
  */
27
- declare class DocumentCache implements IDocumentCache {
28
- private client;
77
+ declare class DocumentCache implements IDocumentCache, IOperationCache, IDocumentTypeCache {
29
78
  private documents;
30
79
  private batchPromises;
31
80
  private listeners;
81
+ private refetcher;
32
82
  /**
33
83
  * Cache keys that fetched a document under a name other than its id --
34
84
  * slugs, which `client.get` resolves. Change events dispatch by `header.id`,
@@ -37,19 +87,84 @@ declare class DocumentCache implements IDocumentCache {
37
87
  * the same document is cached under.
38
88
  */
39
89
  private aliasKeys;
90
+ /** Operations by document id, then scope. Entries are replaced, never mutated. */
91
+ private operationEntries;
92
+ /** In-flight controllers and the next page's cursor/limit, by document id then scope. */
93
+ private operationRequests;
94
+ private operationListeners;
95
+ /** Documents by type and page size, keyed by typeKey. */
96
+ private typeEntries;
97
+ private typeRequests;
98
+ private typeListeners;
40
99
  private unsubscribe;
41
- constructor(client: IReactorBrowserClient$1);
100
+ private readonly client;
101
+ constructor(client: IReactorBrowserClient$1 | IDocumentCacheReader);
42
102
  private handleDocumentChange;
43
103
  private handleDocumentDeleted;
44
104
  private handleDocumentUpdated;
105
+ private notifyListeners;
45
106
  /** The id an event dispatches by, plus every alias the document is cached under. */
46
107
  private cacheKeysFor;
47
108
  /** Records that `key` cached the document change events know as `header.id`. */
48
109
  private recordAlias;
49
110
  private invalidateBatchesContaining;
50
111
  get(id: string, refetch?: boolean): Promise<PHDocument$1>;
112
+ getRefetchState(id: string): DocumentRefetchState;
51
113
  getBatch(ids: string[]): Promise<PHDocument$1[]>;
114
+ /**
115
+ * Reserves an entry for every id not yet cached and fills them from
116
+ * `getMany`, in chunks of {@link GET_MANY_CHUNK_SIZE}. Each id keeps its own
117
+ * entry, settled as `get` would settle it.
118
+ */
119
+ private loadMany;
120
+ /**
121
+ * `getMany` rejects when any id is unavailable, so a failed chunk is split
122
+ * in half and retried; a single id is read with `get`, so it settles exactly
123
+ * as a single read would.
124
+ */
125
+ private settleMany;
126
+ private settleFetched;
52
127
  subscribe(id: string | string[], callback: () => void): () => void;
128
+ getOperationsState(documentId: string, scope: string): OperationsCacheEntry;
129
+ loadOperations(documentId: string, scope: string, limit: number): void;
130
+ loadMoreOperations(documentId: string, scope: string): void;
131
+ /**
132
+ * Bring a document's cached scopes up to date after it changed, without
133
+ * throwing away what is already loaded.
134
+ *
135
+ * The operation stream is append-only: an update adds operations at higher
136
+ * revisions and never rewrites the ones below, so history already paged in
137
+ * is still correct. Dropping it meant a panel showing a fully loaded
138
+ * document re-walked every page on each edit -- the cost of which grows
139
+ * with the document, exactly where it hurts most. Each scope instead asks
140
+ * only for what comes after the newest revision it holds, using the
141
+ * `sinceRevision` filter, and appends the answer.
142
+ *
143
+ * A scope that has not finished paging is dropped as before: it has no
144
+ * meaningful "newest revision" to resume from, since asking for everything
145
+ * past the newest row it happens to hold would skip the pages between that
146
+ * row and the end of the stream.
147
+ */
148
+ private refreshOperations;
149
+ /** Drops one scope of a document, aborting its request if one is in flight. */
150
+ private invalidateOperationsScope;
151
+ invalidateOperations(documentId: string): void;
152
+ subscribeOperations(documentId: string, callback: () => void): () => void;
153
+ private settleOperationsPage;
154
+ private setOperationsEntry;
155
+ private setOperationsRequest;
156
+ private notifyOperationListeners;
157
+ getDocumentsOfTypeState(type: string, limit: number): DocumentsOfTypeEntry;
158
+ loadDocumentsOfType(type: string, limit: number): Promise<void>;
159
+ loadMoreDocumentsOfType(type: string, limit: number): void;
160
+ subscribeDocumentsOfType(type: string, limit: number, callback: () => void): () => void;
161
+ /** Loads one page after `before` and appends it; never rejects, the entry holds the error. */
162
+ private loadTypePage;
163
+ /** Reloads every loaded page of a type a created or deleted document belongs to. */
164
+ private reloadTypesChangedBy;
165
+ private primeDocument;
166
+ private getTypeEntry;
167
+ private setTypeEntry;
53
168
  /**
54
169
  * Disposes of the cache and unsubscribes from document change events.
55
170
  */
@@ -57,7 +172,7 @@ declare class DocumentCache implements IDocumentCache {
57
172
  }
58
173
  //#endregion
59
174
  //#region src/remote-controller/types.d.ts
60
- type RemoteControllerGraphQLClient = Pick<ReactorGraphQLClient, "GetDocument" | "GetDocumentWithOperations" | "GetDocumentOperations" | "MutateDocument" | "CreateDocument" | "CreateEmptyDocument" | "DeleteDocument" | "BatchGetDocumentOperations" | "BatchGetDocumentWithOperations">;
175
+ type RemoteControllerGraphQLClient = Pick<ReactorGraphQLClient, "GetDocument" | "GetDocumentWithOperations" | "GetDocumentOperations" | "MutateDocument" | "CreateDocument" | "CreateEmptyDocument" | "GetCreateDefaults" | "GetCreateProtocolVersions" | "DeleteDocument" | "BatchGetDocumentOperations" | "BatchGetDocumentWithOperations">;
61
176
  type RemoteDocumentData = PhDocumentFieldsFragment;
62
177
  type RemoteOperation = GetDocumentOperationsQuery["documentOperations"]["items"][number];
63
178
  type RemoteOperationResultPage = GetDocumentOperationsQuery["documentOperations"];
@@ -65,14 +180,22 @@ type RemoteOperationResultPage = GetDocumentOperationsQuery["documentOperations"
65
180
  * Options for creating a RemoteDocumentController.
66
181
  */
67
182
  type RemoteControllerOptions = {
68
- client: RemoteControllerGraphQLClient; /** Remote document id. Omit for new documents. */
69
- documentId?: string; /** "batch" requires explicit push(), "streaming" auto-pushes after actions. Defaults to "batch" */
70
- mode?: "batch" | "streaming"; /** Optional signer for action signing. */
71
- signer?: ISigner; /** Branch name, defaults to "main". */
72
- branch?: string; /** Parent document identifier for creating new documents. */
73
- parentIdentifier?: string; /** Conflict resolution strategy when remote has new operations. Default: no check (current behavior). */
74
- onConflict?: ConflictStrategy; /** Called when a streaming-mode push fails. If not provided, errors are silently swallowed. */
75
- onPushError?: (error: unknown) => void; /** Number of operations to fetch per page. Defaults to 100. */
183
+ client: RemoteControllerGraphQLClient;
184
+ /** Remote document id. Omit for new documents. */
185
+ documentId?: string;
186
+ /** "batch" requires explicit push(), "streaming" auto-pushes after actions. Defaults to "batch" */
187
+ mode?: "batch" | "streaming";
188
+ /** Optional signer for action signing. */
189
+ signer?: ISigner;
190
+ /** Branch name, defaults to "main". */
191
+ branch?: string;
192
+ /** Parent document identifier for creating new documents. */
193
+ parentIdentifier?: string;
194
+ /** Conflict resolution strategy when remote has new operations. Default: no check (current behavior). */
195
+ onConflict?: ConflictStrategy;
196
+ /** Called when a streaming-mode push fails. If not provided, errors are silently swallowed. */
197
+ onPushError?: (error: unknown) => void;
198
+ /** Number of operations to fetch per page. Defaults to 100. */
76
199
  operationsPageSize?: number;
77
200
  };
78
201
  /**
@@ -80,7 +203,8 @@ type RemoteControllerOptions = {
80
203
  */
81
204
  type PushResult = {
82
205
  remoteDocument: RemoteDocumentData;
83
- actionCount: number; /** The actions that were sent to the server (after signing, if applicable). */
206
+ actionCount: number;
207
+ /** The actions that were sent to the server (after signing, if applicable). */
84
208
  operations: ReadonlyArray<Action$1>;
85
209
  };
86
210
  /**
@@ -102,9 +226,13 @@ type TrackedAction = {
102
226
  };
103
227
  /** Information about a detected conflict. */
104
228
  type ConflictInfo = {
105
- /** Remote operations added since the last pull, grouped by scope. */remoteOperations: Record<string, RemoteOperation[]>; /** Local actions pending push. */
106
- localActions: TrackedAction[]; /** Remote revision at last pull. */
107
- knownRevision: Record<string, number>; /** Current remote revision. */
229
+ /** Remote operations added since the last pull, grouped by scope. */
230
+ remoteOperations: Record<string, RemoteOperation[]>;
231
+ /** Local actions pending push. */
232
+ localActions: TrackedAction[];
233
+ /** Remote revision at last pull. */
234
+ knownRevision: Record<string, number>;
235
+ /** Current remote revision. */
108
236
  currentRevision: Record<string, number>;
109
237
  };
110
238
  /** Custom merge handler receives conflict info and returns actions to push (or throws to abort). */
@@ -170,8 +298,8 @@ type RevisionsListSelection = GetDocumentQueryFields["revisionsList"];
170
298
  * `createPresignedHeader`: the creation signature is not fetchable over
171
299
  * GraphQL and is not part of the operation signing payload.
172
300
  *
173
- * The read path never fetches operation history, so `operations` is a map of
174
- * the document's known scopes to empty arrays.
301
+ * The read path never fetches operation history, so `operations` maps each
302
+ * scope of the document's state and revisions to an empty array.
175
303
  *
176
304
  * `branch` is the branch the document was read from. The GraphQL type does not
177
305
  * carry it, so it has to be passed back in by the caller; it defaults to the
@@ -188,34 +316,118 @@ declare function phDocumentFromGetDocument<TDocument extends PHDocument = PHDocu
188
316
  declare function phDocumentFromMutation<TDocument extends PHDocument = PHDocument>(document: GetDocumentQueryFields, operations: readonly RemoteOperation[], branch?: string): TDocument;
189
317
  /** Turns a `revisionsList` selection into the header's per-scope revision map. */
190
318
  declare function revisionMapFromRevisionsList(revisionsList: RevisionsListSelection): Record<string, number>;
319
+ /** The `DateTime` scalar deserializes as either an ISO string or a `Date`. */
320
+ declare function isoStringFromDateTime(value: string | Date): string;
191
321
  //#endregion
192
- //#region src/graphql-client/auth.d.ts
322
+ //#region src/graphql-client/drive-nodes.d.ts
323
+ /** The node queries a {@link GraphQLDriveNodeSource} runs. */
324
+ type DriveNodeQueries = Pick<Sdk, "GetDriveNodes" | "GetDriveNode" | "GetDriveDescendants">;
193
325
  /**
194
- * Resolves the bearer token to send with a request.
195
- *
196
- * Returning `undefined` (or an empty string) means "send this request
197
- * anonymously": open Switchboards must keep serving reads to logged-out users.
326
+ * The reactor subgraph's type-neutral node queries (`driveNodes`, `driveNode`,
327
+ * `driveDescendants`) as an {@link IDriveNodeSource}, so a browser reads a
328
+ * legacy drive and a reactor-drive alike. The Switchboard serves only the
329
+ * nodes the caller may read. Drive ids must be canonical ids, not slugs.
198
330
  */
199
- type BearerTokenProvider = () => Promise<string | undefined>;
331
+ declare class GraphQLDriveNodeSource implements IDriveNodeSource {
332
+ private readonly queries;
333
+ private readonly headersFor;
334
+ constructor(queries: DriveNodeQueries, headersFor?: (driveId: string) => Record<string, string> | undefined);
335
+ getNode(driveId: string, nodeId: string, signal?: AbortSignal): Promise<DriveNodeRecord | undefined>;
336
+ listChildren(driveId: string, parentFolder: string | null | undefined, paging?: PagingOptions, signal?: AbortSignal, kind?: DriveNodeKind): Promise<DriveNodePage>;
337
+ getDescendants(driveId: string, root: string, signal?: AbortSignal): Promise<DriveNodeRecord[]>;
338
+ listAll(driveId: string, signal?: AbortSignal): Promise<DriveNodeRecord[]>;
339
+ }
200
340
  /**
201
- * The default token provider: the token of the currently logged-in Renown user.
202
- *
203
- * It is deliberately resolved from `window.ph` on every call rather than
204
- * captured at construction time, so a client built before login starts sending
205
- * the token as soon as there is one.
206
- *
207
- * The token is requested WITHOUT an `aud` claim - the Switchboard verifier
208
- * rejects tokens that carry an audience.
341
+ * `read.drives` over a node source: the reactor's {@link IDriveReadClient},
342
+ * answering in the legacy `Node` shape for every drive type.
209
343
  */
210
- declare function ambientRenownTokenProvider(): Promise<string | undefined>;
344
+ declare class GraphQLDriveReadClient implements IDriveReadClient {
345
+ private readonly nodes;
346
+ constructor(nodes: IDriveNodeSource);
347
+ getNode(driveIdentifier: string, nodeId: string, signal?: AbortSignal): Promise<Node>;
348
+ listNodes(driveIdentifier: string, parentFolder?: string | null, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<Node>>;
349
+ }
350
+ /** A node record in the legacy `Node` shape. */
351
+ declare function toLegacyNode(node: DriveNodeRecord): Node;
352
+ //#endregion
353
+ //#region src/graphql-client/errors.d.ts
354
+ /** A call the Switchboard GraphQL surface cannot express. */
355
+ declare class GraphQLOperationNotSupportedError extends Error {
356
+ readonly name = "GraphQLOperationNotSupportedError";
357
+ readonly operation: string;
358
+ constructor(operation: string, reason: string);
359
+ static isError(error: unknown): error is GraphQLOperationNotSupportedError;
360
+ }
211
361
  /**
212
- * Builds the SDK middleware that authenticates every request.
213
- *
214
- * The token is resolved per request and never cached, so a login, a logout or
215
- * an expiry between two calls is picked up by the next one. When no token is
216
- * available the request goes out unauthenticated.
362
+ * The Switchboard refused a request with 421 Misdirected Request: the
363
+ * `Drive-Id` it carried names a drive that Switchboard does not own.
364
+ */
365
+ declare class GraphQLWrongBackendError extends Error {
366
+ readonly name = "GraphQLWrongBackendError";
367
+ readonly status = 421;
368
+ /** The drive the Switchboard refused, or `""` when its answer names none. */
369
+ readonly driveId: string;
370
+ /** The response body, parsed when it is JSON. */
371
+ readonly payload: unknown;
372
+ constructor(driveId: string, payload: unknown, options?: ErrorOptions);
373
+ static isError(error: unknown): error is GraphQLWrongBackendError;
374
+ }
375
+ /**
376
+ * The reactor's `BatchJobFailedError`, rebuilt from a batch result; this entry
377
+ * imports the reactor for types only. The shared name lets either `isError`
378
+ * recognise it.
379
+ */
380
+ declare class BatchJobFailedError extends Error {
381
+ readonly name = "BatchJobFailedError";
382
+ readonly key: string;
383
+ readonly jobs: Readonly<Record<string, JobInfo>>;
384
+ constructor(key: string, jobs: Record<string, JobInfo>);
385
+ static isError(error: unknown): error is BatchJobFailedError;
386
+ }
387
+ /** A validation error naming root field `field` unknown: a host from before it. */
388
+ declare function queriesUnknownField(error: unknown, field: string): boolean;
389
+ /** A validation error naming `argument` unknown: a host from before it. */
390
+ declare function queriesUnknownArgument(error: unknown, argument: string): boolean;
391
+ /**
392
+ * The reactor's `JobFailedError`, rebuilt from a job the Switchboard reported
393
+ * FAILED; this entry imports the reactor for types only. A write handle's
394
+ * stage rejects with it. The message is the job error's message, as the
395
+ * reactor's is.
396
+ */
397
+ declare class JobFailedError extends Error {
398
+ readonly name = "JobFailedError";
399
+ readonly job: JobInfo;
400
+ constructor(job: JobInfo);
401
+ static isError(error: unknown): error is JobFailedError;
402
+ }
403
+ //#endregion
404
+ //#region src/graphql-client/transport.d.ts
405
+ /** The `fetch` a client's HTTP requests go through. */
406
+ type GraphQLFetch = typeof globalThis.fetch;
407
+ /** The global `fetch`, read per call so a later replacement is honoured. */
408
+ declare const globalFetch: GraphQLFetch;
409
+ /**
410
+ * Whether `fetch` here is Node's (undici), which resends a request answered
411
+ * 421 and can fail the resend of a buffered body. A page, Electron's renderer
412
+ * included, has a `document`.
413
+ */
414
+ declare function isNodeFetch(): boolean;
415
+ /**
416
+ * Sends a string body as a stream, which fetch never resends, so a 421 comes
417
+ * back as itself. Browsers keep buffered bodies: Chrome streams an upload only
418
+ * over HTTP/2.
419
+ */
420
+ declare function withStreamedBodies(inner?: GraphQLFetch): GraphQLFetch;
421
+ /** A Switchboard backend's default transport: streamed bodies under Node only. */
422
+ declare const switchboardFetch: GraphQLFetch;
423
+ /** Bounds each request, headers through body; rejects with a `TimeoutError`. */
424
+ declare function withRequestDeadline(timeoutMs: number, inner?: GraphQLFetch): GraphQLFetch;
425
+ /**
426
+ * Whether a request failed at a deadline rather than by its caller's abort:
427
+ * this transport's own (`TimeoutError`, a DOMException) or the router's probe
428
+ * deadline (`ProbeTimeoutError`, reactor-router's dispatcher.ts).
217
429
  */
218
- declare function makeAuthMiddleware(tokenProvider: BearerTokenProvider): SdkFunctionWrapper;
430
+ declare function isDeadlineError(error: unknown): boolean;
219
431
  //#endregion
220
432
  //#region src/graphql-client/subgraph.d.ts
221
433
  /**
@@ -286,8 +498,9 @@ declare function describeGraphQLDocument(document: string | DocumentNode): {
286
498
  declare class SubgraphSdkRegistry {
287
499
  private readonly url;
288
500
  private readonly middleware;
501
+ private readonly fetch;
289
502
  private readonly bindings;
290
- constructor(url: string, middleware?: SdkFunctionWrapper);
503
+ constructor(url: string, middleware?: SdkFunctionWrapper, fetch?: GraphQLFetch);
291
504
  /**
292
505
  * Returns the subgraph's SDK, building it on first use.
293
506
  *
@@ -303,14 +516,25 @@ declare class SubgraphSdkRegistry {
303
516
  }
304
517
  //#endregion
305
518
  //#region src/graphql-client/graphql-reactor-client.d.ts
519
+ /** A call the client asks {@link GraphQLReactorClientOptions.driveIdFor} about. */
520
+ type DriveIdCall = {
521
+ readonly method: "create" | "execute" | "executeBatch" | "deleteDocument" | "find";
522
+ readonly documentId?: string;
523
+ readonly parentId?: string;
524
+ readonly jobs?: readonly {
525
+ readonly documentId: string;
526
+ }[];
527
+ };
306
528
  type GraphQLReactorClientOptions = {
307
- /** The Switchboard GraphQL endpoint, e.g. `http://localhost:4001/graphql`. */url: string;
529
+ /** The Switchboard GraphQL endpoint, e.g. `http://localhost:4001/graphql`. */
530
+ url: string;
308
531
  /**
309
532
  * A pre-built SDK to use instead of the transport derived from `url`.
310
533
  * Mainly a test seam.
311
534
  *
312
- * A client built this way carries no auth middleware: the injected SDK owns
313
- * its own transport, and therefore its own headers.
535
+ * A client built this way carries no auth middleware and no 421 mapping:
536
+ * the injected SDK owns its own transport, and therefore its own headers
537
+ * and transport errors.
314
538
  */
315
539
  graphqlClient?: ReactorGraphQLClient;
316
540
  /**
@@ -348,19 +572,43 @@ type GraphQLReactorClientOptions = {
348
572
  * `state.document.version` is here. One action needs no prediction and is
349
573
  * signed without any of this.
350
574
  *
351
- * Read once, when the client is built. Below `GraphQLReactorProvider` this
352
- * is its `documentModels` prop; a client constructed directly passes its own.
575
+ * An array is read once, when the client is built; a function is called at
576
+ * every batch, for a registry that gains models later. Below
577
+ * `GraphQLReactorProvider` this is its `documentModels` prop; a client
578
+ * constructed directly passes its own.
353
579
  */
354
- documentModels?: readonly DocumentModelModule<any>[];
580
+ documentModels?: readonly DocumentModelModule<any>[] | (() => readonly DocumentModelModule<any>[]);
355
581
  /**
356
582
  * Signs the actions this client pushes, instead of the logged-in Renown user.
357
583
  *
358
584
  * Left out - the normal case - the signer is resolved per push from
359
585
  * `window.ph.renown`, so a page signs as whoever is logged in and pushes
360
586
  * unsigned when nobody is. Set it where there is no Renown to read: tests,
361
- * scripts, and integration suites that must sign deterministically.
587
+ * scripts, and integration suites that must sign deterministically. A
588
+ * function is called per push, and pushes unsigned when it returns
589
+ * `undefined`.
362
590
  */
363
- signer?: ISigner;
591
+ signer?: ISigner | (() => ISigner | undefined);
592
+ /**
593
+ * Names the drive a call belongs to when the client cannot prove it itself,
594
+ * for its `Drive-Id` header; `undefined` sends none. Return only a drive id
595
+ * the caller knows: a Switchboard that does not own it answers 421. Where
596
+ * the client has proof of its own and the two disagree, the proof is sent.
597
+ */
598
+ driveIdFor?: (call: DriveIdCall) => string | undefined;
599
+ /**
600
+ * Bounds each HTTP request, headers through body, in milliseconds; a request
601
+ * past it rejects with a `TimeoutError`. Unset, requests are unbounded.
602
+ */
603
+ requestTimeoutMs?: number;
604
+ /**
605
+ * Bounds an `executeBatch` request in place of `requestTimeoutMs`. The
606
+ * mutation answers once its jobs are readable, and it has no form that does
607
+ * not wait, so one request lasts as long as the write does.
608
+ */
609
+ batchRequestTimeoutMs?: number;
610
+ /** The `fetch` every HTTP request goes through; the global one by default. */
611
+ fetch?: GraphQLFetch;
364
612
  };
365
613
  /**
366
614
  * The marker {@link isGraphQLReactorClient} looks for.
@@ -371,6 +619,11 @@ type GraphQLReactorClientOptions = {
371
619
  * and answers `false`. A branded property survives both.
372
620
  */
373
621
  declare const graphQLReactorClientBrand: "__powerhouseGraphQLReactorClient";
622
+ /** The read half of {@link GraphQLReactorClient}: the hooks' reads plus `drives`. */
623
+ interface GraphQLReactorReadClient extends IReactorBrowserReadClient {
624
+ /** A drive's nodes from the node queries, for every drive type. */
625
+ readonly drives: IDriveReadClient;
626
+ }
374
627
  /**
375
628
  * A light implementation of {@link IReactorBrowserClient} that talks plain
376
629
  * GraphQL to a Switchboard, with no reactor in the bundle.
@@ -382,21 +635,92 @@ declare class GraphQLReactorClient implements IReactorBrowserClient$1 {
382
635
  /** See {@link isGraphQLReactorClient}. */
383
636
  readonly [graphQLReactorClientBrand] = true;
384
637
  private readonly sdk;
638
+ /** For `executeBatch`, the one write a request waits for: see {@link batchRequestTimeoutMs}. */
639
+ private readonly batchSdk;
385
640
  private readonly subgraphs;
386
641
  private readonly listeners;
387
642
  private readonly tokenProvider;
388
643
  private readonly subscriptionsUrl;
389
644
  private readonly documentModels;
390
- private readonly signer;
645
+ private readonly resolveSigner;
646
+ private readonly driveIdFor;
647
+ private readonly undoRedoChains;
391
648
  private stopRealtime;
392
649
  private realtimeStarted;
393
650
  private realtimeGeneration;
394
651
  private realtimeErrorLogged;
395
652
  /** Whether the last socket died because the Switchboard refused its credentials. */
396
653
  private realtimeRefusedCredentials;
654
+ /** The socket write handles wait on; opened by the first stage wait. */
655
+ private jobSocket;
656
+ /** Set once the `jobChanges` subscription failed; stage waits then only poll. */
657
+ private jobRealtimeBroken;
658
+ /** Set once the Switchboard refused the `document` query's `consistency` argument. */
659
+ private consistencyUnsupported;
660
+ private readonly driveNodes;
661
+ /**
662
+ * The read half: the reads the hooks make. Every method is this client's
663
+ * own; nothing that writes is reachable from it.
664
+ */
665
+ readonly read: GraphQLReactorReadClient;
666
+ /**
667
+ * The write half. `execute` submits through `executeAsync` and hands back a
668
+ * handle whose `written` and `readable` resolve from `jobStatus`, woken by
669
+ * the `jobChanges` subscription when realtime is on, and whose `document()`
670
+ * runs the `document` query bounded by the receipt's token. `create` and
671
+ * `deleteDocument` have no asynchronous mutation: they run the synchronous
672
+ * ones and hand back a settled handle.
673
+ */
674
+ readonly write: IReactorBrowserWriteClient;
397
675
  constructor(options: GraphQLReactorClientOptions);
398
- get<TDocument extends PHDocument>(identifier: string, view?: ViewFilter, signal?: AbortSignal): Promise<TDocument>;
676
+ /**
677
+ * The Switchboard's drive node queries as a node source, for every drive
678
+ * type. `read.drives` answers from it.
679
+ */
680
+ nodeSource(): IDriveNodeSource;
681
+ /**
682
+ * Reads a document. With a consistency token that names any coordinate, the
683
+ * Switchboard waits until its read models hold them; one without the
684
+ * `document` query's `consistency` argument is read without it, which after
685
+ * a write's `readable` stage still sees the write on a single node.
686
+ */
687
+ get<TDocument extends PHDocument>(identifier: string, view?: ViewFilter, signal?: AbortSignal, consistencyToken?: ConsistencyToken): Promise<TDocument>;
688
+ /**
689
+ * Reads documents by id, in the order given; throws if any is missing. Each
690
+ * chunk of {@link GET_MANY_CHUNK_SIZE} ids is one request holding an aliased
691
+ * `document` field per id, with the selection and arguments `get` sends.
692
+ */
693
+ getMany<TDocument extends PHDocument>(documentIds: string[], view?: ViewFilter, signal?: AbortSignal, consistencyToken?: ConsistencyToken): Promise<TDocument[]>;
694
+ /** One chunk of `getMany`, with the `consistency` argument while the Switchboard accepts it. */
695
+ private getDocumentChunk;
696
+ private runGetDocuments;
697
+ /**
698
+ * Whether the Switchboard would serve the document to this client's caller,
699
+ * from its `documentServed` query: the same read gate `find` passes. Absent
700
+ * or withheld is `false`; a failure to decide throws.
701
+ *
702
+ * A point-in-time view throws {@link GraphQLOperationNotSupportedError}, as
703
+ * does a Switchboard without the query.
704
+ */
705
+ isServed(identifier: string, view?: ViewFilter, signal?: AbortSignal): Promise<boolean>;
399
706
  getOperations(documentIdentifier: string, view?: ViewFilter, filter?: OperationFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<Operation>>;
707
+ /**
708
+ * Filters documents by criteria over the Switchboard's `findDocuments` query.
709
+ *
710
+ * The query filters by `type` and `parentId` only, at head. A search naming
711
+ * `ids` or `slugs` (present, whatever its length) and a point-in-time view are
712
+ * each by-contract limitations the query cannot express -- running it anyway
713
+ * would return every document instead of the named ones, or head instead of
714
+ * the asked-for revision, a silently wrong answer. {@link findIsServableOverGraphQL}
715
+ * is the single predicate that decides this, and an unservable `find` throws
716
+ * {@link GraphQLOperationNotSupportedError}. Drive enumeration itself filters
717
+ * by `type` at head, which is served.
718
+ */
719
+ find<TDocument extends PHDocument = PHDocument>(search: SearchFilter, view?: ViewFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<TDocument>>;
720
+ getOutgoingRelationships(sourceIdentifier: string, relationshipType: string, view?: ViewFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<PHDocument>>;
721
+ getIncomingRelationships(targetIdentifier: string, relationshipType: string, view?: ViewFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<PHDocument>>;
722
+ getOutgoingRelationshipEdges(sourceIdentifier: string, relationshipType?: string, view?: ViewFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<DocumentRelationship>>;
723
+ getIncomingRelationshipEdges(targetIdentifier: string, relationshipType?: string, view?: ViewFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<DocumentRelationship>>;
400
724
  create<TDocument extends PHDocument = PHDocument>(document: PHDocument, parentIdentifier?: string, signal?: AbortSignal): Promise<TDocument>;
401
725
  /**
402
726
  * Pushes actions to the Switchboard and returns the updated document.
@@ -416,6 +740,101 @@ declare class GraphQLReactorClient implements IReactorBrowserClient$1 {
416
740
  * request. Declaring it would suggest a per-call choice that does not exist.
417
741
  */
418
742
  execute<TDocument extends PHDocument>(documentIdentifier: string, branch: string, actions: Action[], signal?: AbortSignal): Promise<TDocument>;
743
+ /**
744
+ * What `execute` writes, without waiting: returns the job once the Switchboard
745
+ * holds it, so a write slower than one request's deadline still lands and is
746
+ * reported. It is announced as the write half's `execute` announces it.
747
+ */
748
+ executeAsync(documentIdentifier: string, branch: string, actions: Action[], signal?: AbortSignal): Promise<JobInfo>;
749
+ /**
750
+ * Undoes the last applied operation of `scope` under this client's own
751
+ * signature: UNDO below base-reducer 3; on it, a RETRACT of the target the
752
+ * Switchboard resolves with {@link undoRedoTargets}. One at a time per
753
+ * document, scope and branch. A stale target is refused, not re-resolved.
754
+ */
755
+ undo<TDocument extends PHDocument = PHDocument>(documentIdentifier: string, scope?: string, branch?: string, signal?: AbortSignal): Promise<TDocument>;
756
+ /** Redoes the last undo of `scope`; see {@link undo}. */
757
+ redo<TDocument extends PHDocument = PHDocument>(documentIdentifier: string, scope?: string, branch?: string, signal?: AbortSignal): Promise<TDocument>;
758
+ /** Exact on base-reducer 3, from the targets the Switchboard resolves. */
759
+ undoRedoAvailability(documentIdentifier: string, scope?: string, branch?: string, signal?: AbortSignal): Promise<UndoRedoAvailability>;
760
+ /**
761
+ * The rows a base-reducer 3 undo and redo would retract, resolved by the
762
+ * Switchboard as the caller. A Switchboard without the query is refused
763
+ * with {@link GraphQLOperationNotSupportedError}. `view.subject` is not
764
+ * sent: the Switchboard reads the caller from the bearer.
765
+ */
766
+ undoRedoTargets(documentIdentifier: string, scope?: string, view?: ViewFilter, signal?: AbortSignal): Promise<UndoRedoTargets>;
767
+ private undoOrRedo;
768
+ /** An older Switchboard serves no header versions; then CREATE_DOCUMENT names them, else it is 1. */
769
+ private undoCapabilities;
770
+ /**
771
+ * Runs multiple mutation jobs in dependency order over the Switchboard's
772
+ * `executeBatch` mutation and waits for all to settle, returning the result
773
+ * shaped like `IReactor.executeBatch`'s so the reference `DriveClient`
774
+ * consumes it unchanged.
775
+ *
776
+ * Not atomic: each job commits on its own and a failed job still releases
777
+ * its dependents. A FAILED job throws {@link BatchJobFailedError}, naming the
778
+ * first failed plan key and carrying every job's final state.
779
+ *
780
+ * Each job's actions are signed independently for the job's own
781
+ * `(documentId, branch)` target -- the per-action signing the reactor's own
782
+ * `signActions` does, not the batch state-prediction `execute` uses for a
783
+ * multi-action push. A drive job such as `addFile`'s is `CREATE_DOCUMENT` +
784
+ * `UPGRADE_DOCUMENT` + `ADD_RELATIONSHIP`, which the prediction path rejects
785
+ * outright and which has no fetchable baseline to stamp against. The reactor
786
+ * records but does not verify the stamped previous-state head, so signing
787
+ * each action bare is exactly what the in-process `DriveClient` relies on.
788
+ *
789
+ * The mutation is synchronous server-side: a job it returns is already
790
+ * settled, so {@link waitForJob} resolves from it without polling.
791
+ */
792
+ executeBatch(request: BatchExecutionRequest, signal?: AbortSignal): Promise<BatchExecutionResult>;
793
+ /** The job as `jobStatus` reports it now; `undefined` when it reports none. */
794
+ getJob(jobId: string, signal?: AbortSignal): Promise<JobInfo | undefined>;
795
+ /** The job as `jobStatus` reports it now; throws when it reports none. */
796
+ getJobStatus(jobId: string, signal?: AbortSignal): Promise<JobInfo>;
797
+ /** Polls `jobStatus` until the job is READ_READY or FAILED. */
798
+ waitForJob(jobOrId: string | JobInfo, signal?: AbortSignal): Promise<JobInfo>;
799
+ /** See {@link readCreateSignaturePolicy}. */
800
+ getCreateSignaturePolicy(): Promise<SignaturePolicy>;
801
+ /** See {@link readCreateProtocolVersions}; fitted to `documentModels`. */
802
+ getCreateProtocolVersions(options: CreateProtocolVersionsOptions, signal?: AbortSignal): Promise<ProtocolVersions>;
803
+ /** See {@link IReactorClient.newDocument}; the module comes from `documentModels`. */
804
+ newDocument<TDocument extends PHDocument = PHDocument>(documentType: string, options?: NewDocumentOptions, signal?: AbortSignal): Promise<TDocument>;
805
+ /**
806
+ * Sets or, with `null`, clears the preferred editor as a client-signed
807
+ * action, as the in-process client does.
808
+ */
809
+ setPreferredEditor(documentIdentifier: string, preferredEditor: string | null, branch?: string, signal?: AbortSignal): Promise<PHDocument>;
810
+ /** The `Drive-Id` header for a call: the client's own proof, else the hook's. */
811
+ private driveIdHeaders;
812
+ /**
813
+ * Emits the changes the batch's settled jobs made, as `create` and `execute`
814
+ * do, so a cache is invalidated without a realtime socket. The documents a
815
+ * job wrote to are its own and those its consistency token names.
816
+ */
817
+ private announceBatch;
818
+ /**
819
+ * The id a job's actions are signed for: a signature covers the document id,
820
+ * and the server resolves a slug before verifying. A document created by this
821
+ * job or an earlier one is named by its id. When the server has no such
822
+ * document the identifier is used as given, and the server decides; any
823
+ * other failure to read it throws, so nothing is signed for a slug.
824
+ */
825
+ private batchWriteTarget;
826
+ /**
827
+ * Signs one batch job's actions for the job's own log.
828
+ *
829
+ * Each action is signed on its own for `(documentId, branch)`, the same
830
+ * per-action signing the reactor's `signActions` does: no state prediction
831
+ * across the job, so a job carrying a `CREATE_DOCUMENT` the push-prediction
832
+ * path rejects still signs. An action already signed under a key is left
833
+ * as it is: the reference `DriveClient` signs its jobs before handing them
834
+ * here. With no signer the actions pass through unsigned, matching
835
+ * {@link execute}.
836
+ */
837
+ private signBatchJobActions;
419
838
  /**
420
839
  * Deletes a document and announces it as a `Deleted` event.
421
840
  *
@@ -490,6 +909,53 @@ declare class GraphQLReactorClient implements IReactorBrowserClient$1 {
490
909
  * `gql` document or a string and name the result type at the call site.
491
910
  */
492
911
  request<TResult = unknown, TVariables extends Variables = Variables>(document: TypedGraphQLDocument<TResult, TVariables> | string, variables?: TVariables, options?: GraphQLRequestOptions): Promise<TResult>;
912
+ /**
913
+ * Shapes a document result page into the reactor's {@link PagedResults}.
914
+ *
915
+ * The items carry the same `PHDocumentFields` fragment as `get`, so the same
916
+ * adapter rebuilds each one. `hasNextPage` gates the cursor exactly as
917
+ * `getOperations` does: no cursor means no `next`.
918
+ */
919
+ private toDocumentResults;
920
+ /**
921
+ * Shapes a relationship-edge result page into the reactor's
922
+ * {@link PagedResults}, restoring each edge's `Date` fields.
923
+ */
924
+ private toRelationshipResults;
925
+ /**
926
+ * The write half's `execute`: signs as the facade's `execute` does, submits
927
+ * through `executeAsync` and returns once the job is accepted. When anyone
928
+ * subscribes, the document is read back once the job is readable and
929
+ * announced as `Updated`, as the facade's `execute` announces it; the handle
930
+ * shares that read with its own `document()`.
931
+ */
932
+ private submitExecute;
933
+ /** The write half's `create`: the synchronous mutation, a settled handle. */
934
+ private submitCreate;
935
+ /** The write half's `deleteDocument`: the synchronous mutation, a settled handle. */
936
+ private submitDeleteDocument;
937
+ /** Reads a write's document back, bounded by its receipt's token. */
938
+ private handleReader;
939
+ /** Announces a write's document as `Updated` once it is readable. */
940
+ private announceWrite;
941
+ /**
942
+ * Waits for a job to settle a stage, resolving with a FAILED job too. Polls
943
+ * `jobStatus` with a doubling interval; with realtime on, a `jobChanges`
944
+ * event for the job wakes the wait early and the interval is only a safety
945
+ * net. A failed subscription is logged once and the wait keeps polling.
946
+ */
947
+ private waitForStage;
948
+ /**
949
+ * Subscribes to one job's `jobChanges` when realtime is on and the
950
+ * subscription has not failed before. Returns the stop function, or
951
+ * undefined when nothing was subscribed.
952
+ */
953
+ private watchJob;
954
+ /**
955
+ * The `document` query with the `consistency` argument, or without it once
956
+ * the Switchboard has refused the argument.
957
+ */
958
+ private getDocumentAtConsistency;
493
959
  /**
494
960
  * Opens the realtime socket on the first subscriber.
495
961
  *
@@ -555,6 +1021,8 @@ declare class GraphQLReactorClient implements IReactorBrowserClient$1 {
555
1021
  */
556
1022
  private emitChange;
557
1023
  }
1024
+ /** {@link GraphQLReactorClient.nodeSource}, as a function. */
1025
+ declare function createGraphQLDriveNodeSource(client: GraphQLReactorClient): IDriveNodeSource;
558
1026
  /**
559
1027
  * Whether a value is a {@link GraphQLReactorClient}, including one built by
560
1028
  * another copy of this module.
@@ -571,6 +1039,18 @@ declare function isGraphQLReactorClient(client: unknown): client is GraphQLReact
571
1039
  * argument, so silently returning the head state would be wrong.
572
1040
  */
573
1041
  declare function viewFilterInputFromViewFilter(view?: ViewFilter): ViewFilterInput | undefined;
1042
+ /**
1043
+ * The single source of truth for whether the Switchboard `findDocuments` query
1044
+ * can serve a `find`. It is servable iff the search names neither `ids` nor
1045
+ * `slugs` (present, regardless of length) AND the view is not point-in-time:
1046
+ * each is a by-contract limitation of a surface that filters only by
1047
+ * `type`/`parentId` at head. Exported so a caller can route around an
1048
+ * unservable search instead of catching the error `find` throws for it.
1049
+ */
1050
+ declare function findIsServableOverGraphQL(search: SearchFilter, view?: ViewFilter): boolean;
1051
+ /** Resolves the signer of the logged-in user, if there is one. */
1052
+ /** The logged-in Renown user's signer, read per call; none when nobody is. */
1053
+ declare function ambientRenownSigner(): ISigner | undefined;
574
1054
  //#endregion
575
1055
  //#region src/graphql-client/graphql-reactor-provider.d.ts
576
1056
  declare global {
@@ -589,7 +1069,8 @@ declare global {
589
1069
  */
590
1070
  declare function ensurePHEventHandlers(): void;
591
1071
  type GraphQLReactorProviderProps = {
592
- /** The Switchboard GraphQL endpoint, e.g. `http://localhost:4001/graphql`. */url: string;
1072
+ /** The Switchboard GraphQL endpoint, e.g. `http://localhost:4001/graphql`. */
1073
+ url: string;
593
1074
  /**
594
1075
  * Resolves the bearer token sent with every request, per request. Defaults to
595
1076
  * the token of the logged-in Renown user, or none when nobody is logged in.
@@ -675,15 +1156,7 @@ type GraphQLReactorProviderProps = {
675
1156
  * effect rebuilds both if it runs again on the same client - which is what a
676
1157
  * `StrictMode` mount does.
677
1158
  */
678
- declare function GraphQLReactorProvider({
679
- url,
680
- tokenProvider,
681
- subscriptionsUrl,
682
- realtime,
683
- attachmentService,
684
- documentModels,
685
- children
686
- }: GraphQLReactorProviderProps): react_jsx_runtime0.JSX.Element;
1159
+ declare function GraphQLReactorProvider({ url, tokenProvider, subscriptionsUrl, realtime, attachmentService, documentModels, children }: GraphQLReactorProviderProps): import("react/jsx-runtime").JSX.Element;
687
1160
  /**
688
1161
  * Returns the {@link GraphQLReactorClient} mounted by
689
1162
  * {@link GraphQLReactorProvider}, or `undefined` when the slot holds something
@@ -705,7 +1178,7 @@ declare function useSwitchboardClient(): GraphQLReactorClient | undefined;
705
1178
  * The operation selection of `GetDocumentOperations`, lifted into a fragment so
706
1179
  * the write path can reuse `remoteOperationToLocal` on the items it selects.
707
1180
  */
708
- declare const ReactorOperationFieldsFragmentDoc: graphql.DocumentNode;
1181
+ declare const ReactorOperationFieldsFragmentDoc: import("graphql").DocumentNode;
709
1182
  /**
710
1183
  * `mutateDocument` plus the operations the mutation produced.
711
1184
  *
@@ -727,7 +1200,7 @@ declare const ReactorOperationFieldsFragmentDoc: graphql.DocumentNode;
727
1200
  * by hand or the operations came from `main` while the actions were applied
728
1201
  * elsewhere. One variable cannot disagree with itself.
729
1202
  */
730
- declare const MutateDocumentWithOperationsDocument: graphql.DocumentNode;
1203
+ declare const MutateDocumentWithOperationsDocument: import("graphql").DocumentNode;
731
1204
  type MutateDocumentWithOperationsVariables = {
732
1205
  documentIdentifier: Scalars["String"]["input"];
733
1206
  actions: ReadonlyArray<ActionInput>;
@@ -742,6 +1215,33 @@ type MutateDocumentWithOperationsResult = {
742
1215
  } | null;
743
1216
  };
744
1217
  };
1218
+ /**
1219
+ * `document`, bounded by a consistency token: the read waits until the
1220
+ * Switchboard's read models hold every operation the token names. The
1221
+ * `consistency` argument is additive on the Switchboard; one without it refuses
1222
+ * this document, and the client falls back to the plain `GetDocument`.
1223
+ */
1224
+ declare const GetDocumentAtConsistencyDocument: import("graphql").DocumentNode;
1225
+ type GetDocumentAtConsistencyVariables = {
1226
+ identifier: Scalars["String"]["input"];
1227
+ view?: ViewFilterInput;
1228
+ consistency: {
1229
+ version: number;
1230
+ createdAtUtcIso: string;
1231
+ coordinates: ReadonlyArray<{
1232
+ documentId: string;
1233
+ scope: string;
1234
+ branch: string;
1235
+ operationIndex: number;
1236
+ }>;
1237
+ };
1238
+ };
1239
+ type GetDocumentAtConsistencyResult = {
1240
+ readonly document?: {
1241
+ readonly document: PhDocumentFieldsFragment;
1242
+ readonly childIds: ReadonlyArray<string>;
1243
+ } | null;
1244
+ };
745
1245
  //#endregion
746
1246
  //#region src/graphql-client/signing.d.ts
747
1247
  /**
@@ -761,12 +1261,12 @@ type MutateDocumentWithOperationsResult = {
761
1261
  */
762
1262
  declare function stampAction(action: Action$1, document: PHDocument$1, revision?: number): Action$1;
763
1263
  /**
764
- * Signs a stamped action, preserving any signatures it already carries.
765
- *
766
- * The signer reads `context.prevOpHash` off the action, so this must run after
767
- * {@link stampAction}.
1264
+ * Signs a stamped action for `target`, keeping any signatures it already
1265
+ * carries. The signer reads `context.prevOpHash`, so this runs after
1266
+ * {@link stampAction}. A v2 tuple covers the signer's identity, so the context
1267
+ * takes the signer's user and app even when the action named others.
768
1268
  */
769
- declare function signStampedAction(action: Action$1, signer: ISigner, signal?: AbortSignal): Promise<Action$1>;
1269
+ declare function signStampedAction(action: Action$1, signer: ISigner, target: ActionSigningTarget, signal?: AbortSignal): Promise<Action$1>;
770
1270
  /**
771
1271
  * Stamps and signs a batch of actions against one document snapshot, so every
772
1272
  * action carries the head its predecessor will leave behind.
@@ -856,13 +1356,15 @@ type DocumentChangesEventPayload = DocumentChangesSubscription["documentChanges"
856
1356
  /** The connection payload sent with the `ConnectionInit` message. */
857
1357
  type ConnectionParams = Record<string, string>;
858
1358
  type DocumentChangesSubscriptionOptions = {
859
- /** The websocket endpoint, e.g. `ws://localhost:4001/graphql/subscriptions`. */wsUrl: string;
1359
+ /** The websocket endpoint, e.g. `ws://localhost:4001/graphql/subscriptions`. */
1360
+ wsUrl: string;
860
1361
  /**
861
1362
  * Resolves the `ConnectionInit` payload. Called again on every reconnect, so
862
1363
  * a token that expired while the socket was down is refreshed on the way back
863
1364
  * up.
864
1365
  */
865
- connectionParams?: () => Promise<ConnectionParams>; /** Called once per server event. */
1366
+ connectionParams?: () => Promise<ConnectionParams>;
1367
+ /** Called once per server event. */
866
1368
  onEvent: (event: DocumentChangesEventPayload) => void;
867
1369
  /**
868
1370
  * Called when the socket gives up: the retries built into `graphql-ws` are
@@ -891,6 +1393,33 @@ declare function isAuthRefusalClose(error: unknown): boolean;
891
1393
  * socket. It is safe to call more than once.
892
1394
  */
893
1395
  declare function startDocumentChangesSubscription(options: DocumentChangesSubscriptionOptions): () => void;
1396
+ /** The `jobChanges` payload, exactly as the Switchboard sends it. */
1397
+ type JobChangesEventPayload = JobChangesSubscription["jobChanges"];
1398
+ /**
1399
+ * One socket carrying `jobChanges` subscriptions, one per watched job. The
1400
+ * socket opens on the first watch and closes when nothing is watched.
1401
+ */
1402
+ interface IJobChangesSocket {
1403
+ /**
1404
+ * Watches one job. `onEvent` is called per status change the Switchboard
1405
+ * reports; `onError` once if the subscription fails. Returns the stop
1406
+ * function, safe to call more than once.
1407
+ */
1408
+ watch(jobId: string, onEvent: (event: JobChangesEventPayload) => void, onError: (error: unknown) => void): () => void;
1409
+ /** Closes the socket; a later watch opens a new one. */
1410
+ dispose(): void;
1411
+ }
1412
+ type JobChangesSocketOptions = {
1413
+ /** The websocket endpoint, e.g. `ws://localhost:4001/graphql/subscriptions`. */
1414
+ wsUrl: string;
1415
+ /** Resolves the `ConnectionInit` payload, per connect. */
1416
+ connectionParams?: () => Promise<ConnectionParams>;
1417
+ };
1418
+ /**
1419
+ * Opens the socket write handles wait on. `graphql-ws` multiplexes every
1420
+ * watched job over it and closes it once the last watch stops.
1421
+ */
1422
+ declare function createJobChangesSocket(options: JobChangesSocketOptions): IJobChangesSocket;
894
1423
  /**
895
1424
  * Derives the websocket endpoint from the GraphQL http endpoint.
896
1425
  *
@@ -908,6 +1437,59 @@ declare function subscriptionsUrlFromGraphqlUrl(url: string): string;
908
1437
  */
909
1438
  declare function makeAuthConnectionParams(tokenProvider: BearerTokenProvider): () => Promise<ConnectionParams>;
910
1439
  //#endregion
1440
+ //#region src/graphql-client/switchboard-backend.d.ts
1441
+ type SwitchboardBackendDescriptor = {
1442
+ /** Router backend name; unique and stable for the router's life. */
1443
+ readonly name: string;
1444
+ /** `<origin>[/<prefix>]/graphql`. */
1445
+ readonly url: string;
1446
+ /** Resolves the bearer per request and for the realtime socket. */
1447
+ readonly tokenProvider: BearerTokenProvider;
1448
+ /** Read per push when a function; `undefined` pushes unsigned, never ambient. */
1449
+ readonly signer: ISigner | (() => ISigner | undefined) | undefined;
1450
+ /** Models for signing a batch, read per batch. */
1451
+ readonly documentModels: () => readonly DocumentModelModule$1<any>[];
1452
+ readonly realtime?: boolean;
1453
+ /** Default `"rpc"`. */
1454
+ readonly inspection?: ReactorReach["inspection"];
1455
+ /** Bound on one request, headers through body. Default 30_000. */
1456
+ readonly requestTimeoutMs?: number;
1457
+ /** Bound on a batch, which waits for its jobs. Default 120_000. */
1458
+ readonly batchRequestTimeoutMs?: number;
1459
+ /** Unset fields take {@link DEFAULT_BREAKER}; `false` never opens. */
1460
+ readonly breaker?: SwitchboardBreaker;
1461
+ /** The transport under the deadline and the breaker; {@link switchboardFetch} by default. */
1462
+ readonly fetch?: GraphQLFetch;
1463
+ };
1464
+ declare const DEFAULT_REQUEST_TIMEOUT_MS = 30000;
1465
+ declare const DEFAULT_BATCH_REQUEST_TIMEOUT_MS = 120000;
1466
+ declare const DEFAULT_BREAKER: Readonly<{
1467
+ failures: 3;
1468
+ openMs: 30000;
1469
+ }>;
1470
+ /** After `failures` failed requests in a row, send nothing for `openMs`. */
1471
+ type SwitchboardBreaker = false | {
1472
+ readonly failures?: number;
1473
+ readonly openMs?: number;
1474
+ };
1475
+ type SwitchboardBackend = {
1476
+ /** reach `{hosting: "remote", inspection}`; `refusesMisroutes: false`. */
1477
+ readonly config: RoutableBackendConfig;
1478
+ /** Reopens the realtime socket on the new credentials. */
1479
+ notifyCredentialsChanged(): void;
1480
+ /** Closes the realtime socket. */
1481
+ dispose(): void;
1482
+ };
1483
+ /** The Switchboard's circuit is open: nothing was sent. */
1484
+ declare class SwitchboardUnreachableError extends Error {
1485
+ readonly backend: string;
1486
+ readonly retryAt: number;
1487
+ readonly name = "SwitchboardUnreachableError";
1488
+ constructor(backend: string, retryAt: number);
1489
+ }
1490
+ /** A Switchboard as a router backend; members GraphQL cannot serve are absent. */
1491
+ declare function createSwitchboardBackend(descriptor: SwitchboardBackendDescriptor): SwitchboardBackend;
1492
+ //#endregion
911
1493
  //#region src/hooks/document-cache.d.ts
912
1494
  /** Returns all documents in the reactor. */
913
1495
  declare const useDocumentCache: UsePHGlobalValue$1<IDocumentCache>;
@@ -938,6 +1520,8 @@ declare function useDocument(id: string | null | undefined): PHDocument$1 | unde
938
1520
  * - isPending: Whether the document is currently loading
939
1521
  * - error: Any error that occurred during loading (e.g., document not found)
940
1522
  * - reload: Function to force a refetch, or undefined when no id is supplied
1523
+ * - isRefetching: A loaded document is being refetched; `data` is the loaded one
1524
+ * - refetchError: The last refetch failure that kept the loaded document
941
1525
  */
942
1526
  declare function useDocumentSafe(id: string | null | undefined): {
943
1527
  readonly status: "initial";
@@ -945,24 +1529,32 @@ declare function useDocumentSafe(id: string | null | undefined): {
945
1529
  readonly error: undefined;
946
1530
  readonly data: undefined;
947
1531
  readonly reload: undefined;
1532
+ readonly isRefetching: false;
1533
+ readonly refetchError: undefined;
948
1534
  } | {
949
- readonly reload: () => Promise<PHDocument$1>;
950
1535
  readonly status: "pending";
951
1536
  readonly isPending: true;
952
1537
  readonly error: undefined;
953
1538
  readonly data: undefined;
954
- } | {
955
1539
  readonly reload: () => Promise<PHDocument$1>;
1540
+ readonly isRefetching: boolean;
1541
+ readonly refetchError: unknown;
1542
+ } | {
956
1543
  readonly status: "success";
957
1544
  readonly isPending: false;
958
1545
  readonly error: undefined;
959
1546
  readonly data: PHDocument$1;
960
- } | {
961
1547
  readonly reload: () => Promise<PHDocument$1>;
1548
+ readonly isRefetching: boolean;
1549
+ readonly refetchError: unknown;
1550
+ } | {
962
1551
  readonly status: "error";
963
1552
  readonly isPending: false;
964
1553
  readonly error: unknown;
965
1554
  readonly data: undefined;
1555
+ readonly reload: () => Promise<PHDocument$1>;
1556
+ readonly isRefetching: boolean;
1557
+ readonly refetchError: unknown;
966
1558
  };
967
1559
  /**
968
1560
  * Retrieves multiple documents from the reactor using React Suspense.
@@ -997,6 +1589,8 @@ declare function useGetDocuments(): (ids: string[]) => Promise<PHDocument$1[]>;
997
1589
  * - isPending: Boolean indicating if the document is currently loading
998
1590
  * - error: Any error that occurred during loading
999
1591
  * - reload: Function to force reload the document from cache
1592
+ * - isRefetching: A loaded document is being refetched; `data` is the loaded one
1593
+ * - refetchError: The last refetch failure that kept the loaded document
1000
1594
  */
1001
1595
  declare function useGetDocumentAsync(id: string | null | undefined): {
1002
1596
  readonly status: "initial";
@@ -1004,24 +1598,32 @@ declare function useGetDocumentAsync(id: string | null | undefined): {
1004
1598
  readonly isPending: false;
1005
1599
  readonly error: undefined;
1006
1600
  readonly reload: undefined;
1601
+ readonly isRefetching: false;
1602
+ readonly refetchError: undefined;
1007
1603
  } | {
1008
- readonly reload: () => Promise<PHDocument$1>;
1009
1604
  readonly status: "pending";
1010
1605
  readonly isPending: true;
1011
1606
  readonly error: undefined;
1012
1607
  readonly data: undefined;
1013
- } | {
1014
1608
  readonly reload: () => Promise<PHDocument$1>;
1609
+ readonly isRefetching: boolean;
1610
+ readonly refetchError: unknown;
1611
+ } | {
1015
1612
  readonly status: "success";
1016
1613
  readonly isPending: false;
1017
1614
  readonly error: undefined;
1018
1615
  readonly data: PHDocument$1;
1019
- } | {
1020
1616
  readonly reload: () => Promise<PHDocument$1>;
1617
+ readonly isRefetching: boolean;
1618
+ readonly refetchError: unknown;
1619
+ } | {
1021
1620
  readonly status: "error";
1022
1621
  readonly isPending: false;
1023
1622
  readonly error: unknown;
1024
1623
  readonly data: undefined;
1624
+ readonly reload: () => Promise<PHDocument$1>;
1625
+ readonly isRefetching: boolean;
1626
+ readonly refetchError: unknown;
1025
1627
  };
1026
1628
  //#endregion
1027
1629
  //#region src/hooks/reactor.d.ts
@@ -1033,25 +1635,44 @@ declare const setReactorClientModule: SetPHGlobalValue<BrowserReactorClientModul
1033
1635
  declare const addReactorClientModuleEventHandler: AddPHGlobalEventHandler;
1034
1636
  /** Returns the reactor client */
1035
1637
  declare const useReactorClient: UsePHGlobalValue<IReactorBrowserClient>;
1036
- /** Sets the reactor client */
1638
+ /**
1639
+ * Sets the reactor client, and `window.ph.reactor` to its read and write
1640
+ * halves. A client without halves leaves `reactor` unset.
1641
+ */
1037
1642
  declare const setReactorClient: SetPHGlobalValue<IReactorBrowserClient>;
1643
+ /** Returns the reactor client's read and write halves */
1644
+ declare const useReactorHalves: UsePHGlobalValue<ReactorBrowserHalves>;
1645
+ /** Adds an event handler for the reactor client's halves */
1646
+ declare const addReactorHalvesEventHandler: AddPHGlobalEventHandler;
1038
1647
  /** Adds an event handler for the reactor client */
1039
1648
  declare const addReactorClientEventHandler: AddPHGlobalEventHandler;
1649
+ /** Sets the client full-client actions use instead of the module's */
1650
+ declare const setFullReactorClient: SetPHGlobalValue<IReactorClient>;
1651
+ /** Adds an event handler for the full reactor client */
1652
+ declare const addFullReactorClientEventHandler: AddPHGlobalEventHandler;
1653
+ /** The client full-client actions use: the one set, else the module's. */
1654
+ declare function getFullReactorClient(): IReactorClient | undefined;
1040
1655
  declare const useSync: () => ISyncManager | undefined;
1041
- declare const useSyncList: () => _powerhousedao_reactor0.Remote[];
1656
+ declare const useSyncList: () => import("@powerhousedao/reactor").Remote[];
1042
1657
  declare const useModelRegistry: () => IDocumentModelRegistry | undefined;
1043
1658
  declare const useDatabase: () => Kysely<Database> | undefined;
1044
1659
  declare const usePGlite: () => PGlite | undefined;
1045
1660
  //#endregion
1046
1661
  //#region src/hooks/dispatch.d.ts
1047
- /**
1048
- * Returns a dispatch function for dispatching actions to a document.
1049
- * Used internally by other hooks to provide action dispatching capabilities.
1050
- * @param document - The document to dispatch actions to.
1051
- * @returns A tuple containing the document and a dispatch function.
1052
- */
1053
- type DispatchFn<TAction> = (actionOrActions: TAction[] | TAction | undefined, onErrors?: (errors: Error[]) => void, onSuccess?: (result: PHDocument$1) => void) => void;
1662
+ /** Dispatches actions.
1663
+ *
1664
+ * Once the write lands, `onErrors` runs first, with an `OperationRejectedError` per action
1665
+ * the document did not apply; it is skipped when every action applied. Then `onSuccess`
1666
+ * runs with the document and an outcome, whether or not any action was rejected:
1667
+ * `outcome.rejected` holds the same errors, and is empty only when every action applied.
1668
+ * If `onErrors` throws, `onSuccess` does not run.
1669
+ *
1670
+ * When nothing lands (no document, no reactor, a failed write), only `onErrors` runs, with why. */
1671
+ type DispatchFn<TAction> = (actionOrActions: TAction[] | TAction | undefined, onErrors?: (errors: Error[]) => void, onSuccess?: DispatchSuccessCallback) => void;
1054
1672
  type UseDispatchResult<TDocument, TAction> = readonly [TDocument | undefined, DispatchFn<TAction>];
1673
+ /** A dispatch to the document `getDocument` returns when it runs. */
1674
+ declare function createDispatch<TDocument = PHDocument$1, TAction = Action$1>(getDocument: () => TDocument | undefined): DispatchFn<TAction>;
1675
+ /** Returns the document and a dispatch to it; see `DispatchFn` for the callbacks' order. */
1055
1676
  declare function useDispatch<TDocument = PHDocument$1, TAction = Action$1>(document: TDocument | undefined): UseDispatchResult<TDocument, TAction>;
1056
1677
  //#endregion
1057
1678
  //#region src/hooks/document-model-modules.d.ts
@@ -1067,24 +1688,61 @@ declare function useDocumentModelModules(): DocumentModelModule[] | undefined;
1067
1688
  declare function useDocumentModelModuleById(id: string | null | undefined, version?: number): DocumentModelModule | undefined;
1068
1689
  //#endregion
1069
1690
  //#region src/hooks/document-operations.d.ts
1070
- type InternalState = {
1691
+ type UseDocumentOperationsOptions = {
1692
+ /**
1693
+ * Operations per page. Default 100. Applies to the next first-page load;
1694
+ * changing it while pages are already loaded has no effect until the next
1695
+ * invalidation or `refetch`.
1696
+ */
1697
+ limit?: number;
1698
+ /** Whether to fetch at all. Default true. Pass false until the operations are needed. */
1699
+ enabled?: boolean;
1700
+ };
1701
+ /** What `useDocumentOperations` returns; exported so consumers can name it. */
1702
+ type DocumentOperationsResult = {
1703
+ /** Every operation of the scope loaded so far, oldest first. */
1704
+ operations: readonly Operation$1[];
1705
+ /** A page is in flight. */
1706
+ isLoading: boolean;
1707
+ /** The last page failed. Operations loaded before it stay available. */
1708
+ error: Error | undefined;
1709
+ /** The last page reported a further page. */
1710
+ hasNextPage: boolean;
1711
+ /** Loads the next page and appends it. No-op while loading or when there is none. */
1712
+ fetchNextPage: () => void;
1713
+ /** Drops the document's cached operations and reloads from the first page. */
1714
+ refetch: () => void;
1715
+ };
1716
+ /**
1717
+ * Legacy result of `useDocumentOperations(documentId)`.
1718
+ * @deprecated Call `useDocumentOperations(documentId, scope, options)` and read `operations`. Removed in the next major.
1719
+ */
1720
+ type DocumentOperationsState = {
1071
1721
  globalOperations: Operation$1[];
1072
1722
  localOperations: Operation$1[];
1073
1723
  isLoading: boolean;
1074
1724
  error: Error | undefined;
1075
- };
1076
- /** What `useDocumentOperations` returns; exported so consumers can name it. */
1077
- type DocumentOperationsState = InternalState & {
1078
1725
  refetch: () => void;
1079
1726
  };
1727
+ /** @deprecated Pass a scope: `useDocumentOperations(documentId, "global")`. The legacy form fetches the whole global and local history eagerly. Removed in the next major. */
1728
+ declare function useDocumentOperations(documentId: string | null | undefined): DocumentOperationsState;
1080
1729
  /**
1081
- * Hook to fetch document operations via the reactor client.
1082
- * Operations are no longer auto-populated on documents and must be fetched explicitly.
1730
+ * Operation history of a document, read from the document cache and kept in
1731
+ * step with it: a change event for the document drops the cached pages and
1732
+ * the hook loads the first page again.
1733
+ *
1734
+ * Pages arrive oldest first. A view that wants the whole history calls
1735
+ * `fetchNextPage` while `hasNextPage` is true.
1083
1736
  *
1084
- * @param documentId - The document ID to fetch operations for
1085
- * @returns Object containing globalOperations, localOperations, isLoading, and error
1737
+ * An empty first page is a final result; there is no retry. When the active
1738
+ * document cache does not serve operations, the result is empty and not
1739
+ * loading.
1740
+ *
1741
+ * @param documentId - The document id, or null/undefined to skip fetching
1742
+ * @param scope - The operation scope, for example "global" or "local"
1743
+ * @param options - Page size and whether fetching is enabled
1086
1744
  */
1087
- declare function useDocumentOperations(documentId: string | null | undefined): DocumentOperationsState;
1745
+ declare function useDocumentOperations(documentId: string | null | undefined, scope: string, options?: UseDocumentOperationsOptions): DocumentOperationsResult;
1088
1746
  //#endregion
1089
1747
  //#region src/hooks/attachment-service.d.ts
1090
1748
  /** Returns the attachment service from window.ph */
@@ -1094,5 +1752,6 @@ declare const setAttachmentService: SetPHGlobalValue<IAttachmentService>;
1094
1752
  /** Registers the attachmentService window event handler */
1095
1753
  declare const addAttachmentServiceEventHandler: AddPHGlobalEventHandler;
1096
1754
  //#endregion
1097
- export { GraphQLReactorClientOptions as $, useGetDocuments as A, RemoteDocumentData as At, resolveDocumentModelModule as B, setDocumentCache as C, IRemoteClient as Ct, useDocuments as D, RemoteControllerGraphQLClient as Dt, useDocumentSafe as E, PushResult as Et, makeAuthConnectionParams as F, DocumentCache as Ft, MutateDocumentWithOperationsResult as G, signStampedAction as H, startDocumentChangesSubscription as I, addPromiseState as It, GraphQLReactorProvider as J, MutateDocumentWithOperationsVariables as K, subscriptionsUrlFromGraphqlUrl as L, readPromiseState as Lt, DocumentChangesEventPayload as M, RemoteOperationResultPage as Mt, DocumentChangesSubscriptionOptions as N, SyncStatus$1 as Nt, useGetDocument as O, RemoteControllerOptions as Ot, isAuthRefusalClose as P, TrackedAction as Pt, GraphQLReactorClient as Q, StaticPackageManager as R, addDocumentCacheEventHandler as S, GetOperationsResult as St, useDocumentCache as T, MergeHandler as Tt, stampAction as U, prepareSignedActions as V, MutateDocumentWithOperationsDocument as W, ensurePHEventHandlers as X, GraphQLReactorProviderProps as Y, useSwitchboardClient as Z, usePGlite as _, ConflictInfo as _t, useDocumentOperations as a, TypedGraphQLDocument as at, useSync as b, GetDocumentResult as bt, DispatchFn as c, BearerTokenProvider as ct, addReactorClientEventHandler as d, GetDocumentQueryFields as dt, isGraphQLReactorClient as et, addReactorClientModuleEventHandler as f, GetDocumentQueryResult as ft, useModelRegistry as g, revisionMapFromRevisionsList as gt, useDatabase as h, phDocumentFromMutation as ht, DocumentOperationsState as i, SubgraphSdkRegistry as it, ConnectionParams as j, RemoteOperation as jt, useGetDocumentAsync as k, RemoteDocumentChangeEvent as kt, UseDispatchResult as l, ambientRenownTokenProvider as lt, setReactorClientModule as m, phDocumentFromGetDocument as mt, setAttachmentService as n, GraphQLRequestOptions as nt, useDocumentModelModuleById as o, describeGraphQLDocument as ot, setReactorClient as p, RevisionsListSelection as pt, ReactorOperationFieldsFragmentDoc as q, useAttachmentService as r, SubgraphSdkFactory as rt, useDocumentModelModules as s, subgraphUrlFromGraphqlUrl as st, addAttachmentServiceEventHandler as t, viewFilterInputFromViewFilter as tt, useDispatch as u, makeAuthMiddleware as ut, useReactorClient as v, ConflictStrategy as vt, useDocument as w, IRemoteController as wt, useSyncList as x, GetDocumentWithOperationsResult as xt, useReactorClientModule as y, DocumentChangeListener as yt, packageFromDocumentModels as z };
1098
- //# sourceMappingURL=attachment-service-BW1v0OAT.d.ts.map
1755
+ export { createJobChangesSocket as $, GetDocumentQueryFields as $t, addDocumentCacheEventHandler as A, isDocumentTypeCache as An, GraphQLRequestOptions as At, DEFAULT_BREAKER as B, switchboardFetch as Bt, useModelRegistry as C, TrackedAction as Cn, GraphQLReactorClientOptions as Ct, useReactorHalves as D, IDLE_OPERATIONS_ENTRY as Dn, findIsServableOverGraphQL as Dt, useReactorClientModule as E, IDLE_DOCUMENTS_OF_TYPE_ENTRY as En, createGraphQLDriveNodeSource as Et, useDocuments as F, subgraphUrlFromGraphqlUrl as Ft, SwitchboardUnreachableError as G, GraphQLWrongBackendError as Gt, SwitchboardBackend as H, withStreamedBodies as Ht, useGetDocument as I, GraphQLFetch as It, DocumentChangesEventPayload as J, queriesUnknownField as Jt, createSwitchboardBackend as K, JobFailedError as Kt, useGetDocumentAsync as L, globalFetch as Lt, useDocument as M, readPromiseState as Mn, SubgraphSdkRegistry as Mt, useDocumentCache as N, IDLE_REFETCH_STATE as Nn, TypedGraphQLDocument as Nt, useSync as O, IDocumentCacheReader as On, isGraphQLReactorClient as Ot, useDocumentSafe as P, dispatchActions as Pn, describeGraphQLDocument as Pt, JobChangesSocketOptions as Q, toLegacyNode as Qt, useGetDocuments as R, isDeadlineError as Rt, useDatabase as S, SyncStatus$1 as Sn, GraphQLReactorClient as St, useReactorClient as T, GET_MANY_CHUNK_SIZE as Tn, ambientRenownSigner as Tt, SwitchboardBackendDescriptor as U, BatchJobFailedError as Ut, DEFAULT_REQUEST_TIMEOUT_MS as V, withRequestDeadline as Vt, SwitchboardBreaker as W, GraphQLOperationNotSupportedError as Wt, IJobChangesSocket as X, GraphQLDriveNodeSource as Xt, DocumentChangesSubscriptionOptions as Y, DriveNodeQueries as Yt, JobChangesEventPayload as Z, GraphQLDriveReadClient as Zt, addReactorHalvesEventHandler as _, RemoteControllerOptions as _n, GraphQLReactorProvider as _t, DocumentOperationsState as a, revisionMapFromRevisionsList as an, packageFromDocumentModels as at, setReactorClient as b, RemoteOperation as bn, useSwitchboardClient as bt, useDocumentModelModuleById as c, DocumentChangeListener as cn, signStampedAction as ct, UseDispatchResult as d, GetOperationsResult as dn, GetDocumentAtConsistencyResult as dt, GetDocumentQueryResult as en, isAuthRefusalClose as et, createDispatch as f, IRemoteClient as fn, GetDocumentAtConsistencyVariables as ft, addReactorClientModuleEventHandler as g, RemoteControllerGraphQLClient as gn, ReactorOperationFieldsFragmentDoc as gt, addReactorClientEventHandler as h, PushResult as hn, MutateDocumentWithOperationsVariables as ht, DocumentOperationsResult as i, phDocumentFromMutation as in, StaticPackageManager as it, setDocumentCache as j, isOperationCache as jn, SubgraphSdkFactory as jt, useSyncList as k, addPromiseState as kn, viewFilterInputFromViewFilter as kt, useDocumentModelModules as l, GetDocumentResult as ln, stampAction as lt, addFullReactorClientEventHandler as m, MergeHandler as mn, MutateDocumentWithOperationsResult as mt, setAttachmentService as n, isoStringFromDateTime as nn, startDocumentChangesSubscription as nt, UseDocumentOperationsOptions as o, ConflictInfo as on, resolveDocumentModelModule as ot, useDispatch as p, IRemoteController as pn, MutateDocumentWithOperationsDocument as pt, ConnectionParams as q, queriesUnknownArgument as qt, useAttachmentService as r, phDocumentFromGetDocument as rn, subscriptionsUrlFromGraphqlUrl as rt, useDocumentOperations as s, ConflictStrategy as sn, prepareSignedActions as st, addAttachmentServiceEventHandler as t, RevisionsListSelection as tn, makeAuthConnectionParams as tt, DispatchFn as u, GetDocumentWithOperationsResult as un, GetDocumentAtConsistencyDocument as ut, getFullReactorClient as v, RemoteDocumentChangeEvent as vn, GraphQLReactorProviderProps as vt, usePGlite as w, DocumentCache as wn, GraphQLReactorReadClient as wt, setReactorClientModule as x, RemoteOperationResultPage as xn, DriveIdCall as xt, setFullReactorClient as y, RemoteDocumentData as yn, ensurePHEventHandlers as yt, DEFAULT_BATCH_REQUEST_TIMEOUT_MS as z, isNodeFetch as zt };
1756
+ export {};
1757
+ //# sourceMappingURL=attachment-service-DXfpfp98.d.ts.map