@powerhousedao/reactor-browser 6.2.2-dev.5 → 6.2.2-dev.50

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 (66) hide show
  1. package/README.md +283 -0
  2. package/dist/attachment-service-CghxHYta.d.ts +970 -0
  3. package/dist/attachment-service-CghxHYta.d.ts.map +1 -0
  4. package/dist/client-BaHKLGy5.d.ts +14 -0
  5. package/dist/client-BaHKLGy5.d.ts.map +1 -0
  6. package/dist/{client-u13cr-Vg.js → client-Zz_l9QzI.js} +30 -3
  7. package/dist/client-Zz_l9QzI.js.map +1 -0
  8. package/dist/{client-_Gh2Uf0E.js → client-s_ISz_Zs.js} +30 -4
  9. package/dist/client-s_ISz_Zs.js.map +1 -0
  10. package/dist/{document-by-id-dLYFX-xz.js → document-by-id-DWEQI7wn.js} +48 -43
  11. package/dist/document-by-id-DWEQI7wn.js.map +1 -0
  12. package/dist/document-operations-D0ePGjbp.js +2778 -0
  13. package/dist/document-operations-D0ePGjbp.js.map +1 -0
  14. package/dist/global-CbyAMlZd.d.ts +400 -0
  15. package/dist/global-CbyAMlZd.d.ts.map +1 -0
  16. package/dist/index-CxxxP14A.d.ts +144 -0
  17. package/dist/index-CxxxP14A.d.ts.map +1 -0
  18. package/dist/index-DPq1VjpB.d.ts +345 -0
  19. package/dist/index-DPq1VjpB.d.ts.map +1 -0
  20. package/dist/index.d.ts +177 -695
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +256 -1627
  23. package/dist/index.js.map +1 -1
  24. package/dist/{inspector-proxy-CvQDDxmT.d.ts → inspector-proxy-CaCFdEG4.d.ts} +4 -2
  25. package/dist/inspector-proxy-CaCFdEG4.d.ts.map +1 -0
  26. package/dist/{make-ph-event-functions-BHoLPif5.js → make-ph-event-functions-DBq3iWYn.js} +1 -1
  27. package/dist/{make-ph-event-functions-BHoLPif5.js.map → make-ph-event-functions-DBq3iWYn.js.map} +1 -1
  28. package/dist/{index-DS4W07Y8.d.ts → pglite-CntadC_p-BtEalg1H.d.ts} +2 -142
  29. package/dist/pglite-CntadC_p-BtEalg1H.d.ts.map +1 -0
  30. package/dist/{relational-Dj06-YkI.js → relational-C_0GdGVN.js} +2 -2
  31. package/dist/{relational-Dj06-YkI.js.map → relational-C_0GdGVN.js.map} +1 -1
  32. package/dist/renown-BZabzj4l.js +68 -0
  33. package/dist/renown-BZabzj4l.js.map +1 -0
  34. package/dist/{renown-D-1c_Bvx.js → renown-C7a1ygsj.js} +471 -57
  35. package/dist/renown-C7a1ygsj.js.map +1 -0
  36. package/dist/src/analytics/index.d.ts +1 -1
  37. package/dist/src/analytics/index.js +2 -1
  38. package/dist/src/analytics/index.js.map +1 -1
  39. package/dist/src/graphql/client.d.ts +3 -2
  40. package/dist/src/graphql/client.js +1 -1
  41. package/dist/src/graphql-client/entry.d.ts +4 -0
  42. package/dist/src/graphql-client/entry.js +3 -0
  43. package/dist/src/relational/index.d.ts +1 -1
  44. package/dist/src/relational/index.js +1 -1
  45. package/dist/src/renown/index.d.ts +2 -2
  46. package/dist/src/renown/index.js +3 -2
  47. package/dist/src/rpc/index.d.ts +5 -3
  48. package/dist/src/rpc/index.d.ts.map +1 -1
  49. package/dist/src/rpc/index.js +37 -10
  50. package/dist/src/rpc/index.js.map +1 -1
  51. package/dist/store-DAJq6vSs.js +37 -0
  52. package/dist/store-DAJq6vSs.js.map +1 -0
  53. package/dist/{client-09xv0Dq6.d.ts → types-Bitg5Z5j.d.ts} +25 -13
  54. package/dist/types-Bitg5Z5j.d.ts.map +1 -0
  55. package/dist/{types-CPV0Cnsy.d.ts → types-wGaiXwjh.d.ts} +1 -1
  56. package/dist/{types-CPV0Cnsy.d.ts.map → types-wGaiXwjh.d.ts.map} +1 -1
  57. package/package.json +15 -9
  58. package/dist/client-09xv0Dq6.d.ts.map +0 -1
  59. package/dist/client-_Gh2Uf0E.js.map +0 -1
  60. package/dist/client-u13cr-Vg.js.map +0 -1
  61. package/dist/document-by-id-dLYFX-xz.js.map +0 -1
  62. package/dist/index-D3bV5rcl.d.ts +0 -216
  63. package/dist/index-D3bV5rcl.d.ts.map +0 -1
  64. package/dist/index-DS4W07Y8.d.ts.map +0 -1
  65. package/dist/inspector-proxy-CvQDDxmT.d.ts.map +0 -1
  66. package/dist/renown-D-1c_Bvx.js.map +0 -1
@@ -0,0 +1,970 @@
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-CbyAMlZd.js";
2
+ import { t as PGlite } from "./pglite-CntadC_p-BtEalg1H.js";
3
+ import { D as Scalars, E as PropagationMode$1, O as SdkFunctionWrapper, S as GetDocumentQuery, T as PhDocumentFieldsFragment, c as ReactorGraphQLClient, k as ViewFilterInput, x as GetDocumentOperationsQuery, y as DocumentChangesSubscription } from "./types-Bitg5Z5j.js";
4
+ import { Action, DocumentModelLib, DocumentModelModule, Operation, PHDocument } from "document-model";
5
+ import { Action as Action$1, DocumentOperations, ISigner, Operation as Operation$1, PHBaseState, PHDocument as PHDocument$1, PHDocumentHeader } from "@powerhousedao/shared/document-model";
6
+ import { ReactNode } from "react";
7
+ import * as _powerhousedao_reactor0 from "@powerhousedao/reactor";
8
+ import { Database, DocumentChangeEvent, DocumentModelSource, IDocumentModelRegistry, ISyncManager, OperationFilter, PagedResults, PagingOptions, PropagationMode, SearchFilter, ViewFilter } from "@powerhousedao/reactor";
9
+ import { GraphQLClient, Variables } from "graphql-request";
10
+ import * as graphql from "graphql";
11
+ import { DocumentNode } from "graphql";
12
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
13
+ import { IAttachmentService } from "@powerhousedao/reactor-attachments/client";
14
+ import { Kysely } from "kysely";
15
+ import { AddPHGlobalEventHandler, BrowserReactorClientModule, IReactorBrowserClient, SetPHGlobalValue, UsePHGlobalValue, WorkerReactorClientModule } from "@powerhousedao/reactor-browser";
16
+ import { RegistryPackageSource } from "@powerhousedao/shared";
17
+
18
+ //#region src/document-cache.d.ts
19
+ declare function addPromiseState<T>(promise: Promise<T>): PromiseWithState<T>;
20
+ declare function readPromiseState<T>(promise: Promise<T> | PromiseWithState<T>): PromiseState<T>;
21
+ /**
22
+ * Document cache implementation that uses the new ReactorClient API.
23
+ *
24
+ * This cache subscribes to document change events via IReactorBrowserClient.subscribe()
25
+ * and automatically updates the cache when documents are created, updated, or deleted.
26
+ */
27
+ declare class DocumentCache implements IDocumentCache {
28
+ private client;
29
+ private documents;
30
+ private batchPromises;
31
+ private listeners;
32
+ private unsubscribe;
33
+ constructor(client: IReactorBrowserClient$1);
34
+ private handleDocumentChange;
35
+ private handleDocumentDeleted;
36
+ private handleDocumentUpdated;
37
+ private invalidateBatchesContaining;
38
+ get(id: string, refetch?: boolean): Promise<PHDocument$1>;
39
+ getBatch(ids: string[]): Promise<PHDocument$1[]>;
40
+ subscribe(id: string | string[], callback: () => void): () => void;
41
+ /**
42
+ * Disposes of the cache and unsubscribes from document change events.
43
+ */
44
+ dispose(): void;
45
+ }
46
+ //#endregion
47
+ //#region src/remote-controller/types.d.ts
48
+ type RemoteControllerGraphQLClient = Pick<ReactorGraphQLClient, "GetDocument" | "GetDocumentWithOperations" | "GetDocumentOperations" | "MutateDocument" | "CreateDocument" | "CreateEmptyDocument" | "DeleteDocument" | "BatchGetDocumentOperations" | "BatchGetDocumentWithOperations">;
49
+ type RemoteDocumentData = PhDocumentFieldsFragment;
50
+ type RemoteOperation = GetDocumentOperationsQuery["documentOperations"]["items"][number];
51
+ type RemoteOperationResultPage = GetDocumentOperationsQuery["documentOperations"];
52
+ /**
53
+ * Options for creating a RemoteDocumentController.
54
+ */
55
+ type RemoteControllerOptions = {
56
+ client: RemoteControllerGraphQLClient; /** Remote document id. Omit for new documents. */
57
+ documentId?: string; /** "batch" requires explicit push(), "streaming" auto-pushes after actions. Defaults to "batch" */
58
+ mode?: "batch" | "streaming"; /** Optional signer for action signing. */
59
+ signer?: ISigner; /** Branch name, defaults to "main". */
60
+ branch?: string; /** Parent document identifier for creating new documents. */
61
+ parentIdentifier?: string; /** Conflict resolution strategy when remote has new operations. Default: no check (current behavior). */
62
+ onConflict?: ConflictStrategy; /** Called when a streaming-mode push fails. If not provided, errors are silently swallowed. */
63
+ onPushError?: (error: unknown) => void; /** Number of operations to fetch per page. Defaults to 100. */
64
+ operationsPageSize?: number;
65
+ };
66
+ /**
67
+ * Result of a push operation.
68
+ */
69
+ type PushResult = {
70
+ remoteDocument: RemoteDocumentData;
71
+ actionCount: number; /** The actions that were sent to the server (after signing, if applicable). */
72
+ operations: ReadonlyArray<Action$1>;
73
+ };
74
+ /**
75
+ * Sync status of the controller.
76
+ */
77
+ type SyncStatus$1 = {
78
+ pendingActionCount: number;
79
+ connected: boolean;
80
+ documentId: string;
81
+ remoteRevision: Record<string, number>;
82
+ };
83
+ /**
84
+ * A tracked action with operation context for signing.
85
+ */
86
+ type TrackedAction = {
87
+ action: Action$1;
88
+ prevOpHash: string;
89
+ prevOpIndex: number;
90
+ };
91
+ /** Information about a detected conflict. */
92
+ type ConflictInfo = {
93
+ /** Remote operations added since the last pull, grouped by scope. */remoteOperations: Record<string, RemoteOperation[]>; /** Local actions pending push. */
94
+ localActions: TrackedAction[]; /** Remote revision at last pull. */
95
+ knownRevision: Record<string, number>; /** Current remote revision. */
96
+ currentRevision: Record<string, number>;
97
+ };
98
+ /** Custom merge handler receives conflict info and returns actions to push (or throws to abort). */
99
+ type MergeHandler = (conflict: ConflictInfo) => Action$1[] | Promise<Action$1[]>;
100
+ /** Conflict resolution strategy. */
101
+ type ConflictStrategy = "reject" | "rebase" | MergeHandler;
102
+ /** Event emitted when the document changes. */
103
+ type RemoteDocumentChangeEvent = {
104
+ source: "action" | "pull";
105
+ document: PHDocument$1<PHBaseState>;
106
+ };
107
+ /** Listener for document change events. */
108
+ type DocumentChangeListener = (event: RemoteDocumentChangeEvent) => void;
109
+ /** Result of fetching operations. */
110
+ type GetOperationsResult = {
111
+ operationsByScope: Record<string, RemoteOperation[]>;
112
+ };
113
+ /** Result of fetching a document together with its operations. */
114
+ type GetDocumentWithOperationsResult = {
115
+ document: RemoteDocumentData;
116
+ childIds: ReadonlyArray<string>;
117
+ operations: GetOperationsResult;
118
+ };
119
+ interface IRemoteClient {
120
+ getDocument(identifier: string, branch?: string): Promise<GetDocumentResult | null>;
121
+ /** Fetch document metadata and operations in a single call. */
122
+ getDocumentWithOperations(identifier: string, branch?: string, sinceRevision?: Record<string, number>, scopes?: string[]): Promise<GetDocumentWithOperationsResult | null>;
123
+ getAllOperations(documentId: string, branch?: string, sinceRevision?: Record<string, number>, scopes?: string[]): Promise<GetOperationsResult>;
124
+ pushActions(documentIdentifier: string, actions: ReadonlyArray<NonNullable<unknown>>, branch?: string): Promise<RemoteDocumentData>;
125
+ createDocument(document: NonNullable<unknown>, parentIdentifier?: string): Promise<RemoteDocumentData>;
126
+ createEmptyDocument(documentType: string, parentIdentifier?: string): Promise<RemoteDocumentData>;
127
+ deleteDocument(identifier: string, propagate?: PropagationMode$1): Promise<boolean>;
128
+ }
129
+ type GetDocumentResult = {
130
+ document: RemoteDocumentData;
131
+ childIds: ReadonlyArray<string>;
132
+ };
133
+ interface IRemoteController<TState extends PHBaseState = PHBaseState> {
134
+ readonly header: PHDocumentHeader;
135
+ readonly state: TState;
136
+ readonly operations: DocumentOperations;
137
+ readonly document: PHDocument$1<TState>;
138
+ readonly status: SyncStatus$1;
139
+ onChange(listener: DocumentChangeListener): () => void;
140
+ push(): Promise<PushResult>;
141
+ pull(): Promise<RemoteDocumentData>;
142
+ delete(propagate?: PropagationMode$1): Promise<boolean>;
143
+ }
144
+ //#endregion
145
+ //#region src/graphql-client/adapter.d.ts
146
+ /** The `document` payload of a `GetDocument` query, once the null case is handled. */
147
+ type GetDocumentQueryResult = NonNullable<GetDocumentQuery["document"]>;
148
+ /** The `PHDocumentFields` fragment as returned by `GetDocument`. */
149
+ type GetDocumentQueryFields = GetDocumentQueryResult["document"];
150
+ /** The `revisionsList` selection of the `PHDocumentFields` fragment. */
151
+ type RevisionsListSelection = GetDocumentQueryFields["revisionsList"];
152
+ /**
153
+ * Converts a `GetDocument` result into a `PHDocument`.
154
+ *
155
+ * Unlike the legacy `src/graphql/adapters.ts` this preserves the per-scope
156
+ * revision map, which the write path needs to compute the `prevOpIndex` of a
157
+ * signed action. `sig` is filled with the empty shape used by
158
+ * `createPresignedHeader`: the creation signature is not fetchable over
159
+ * GraphQL and is not part of the operation signing payload.
160
+ *
161
+ * The read path never fetches operation history, so `operations` is a map of
162
+ * the document's known scopes to empty arrays.
163
+ *
164
+ * `branch` is the branch the document was read from. The GraphQL type does not
165
+ * carry it, so it has to be passed back in by the caller; it defaults to the
166
+ * server's own default branch.
167
+ */
168
+ declare function phDocumentFromGetDocument<TDocument extends PHDocument = PHDocument>(document: GetDocumentQueryFields, branch?: string): TDocument;
169
+ /**
170
+ * Converts a mutation result into a `PHDocument`, carrying the operations the
171
+ * mutation produced.
172
+ *
173
+ * `dispatchActions` reads per-action failures out of `operations[scope]`, so
174
+ * unlike the read path this one must not return empty operation lists.
175
+ */
176
+ declare function phDocumentFromMutation<TDocument extends PHDocument = PHDocument>(document: GetDocumentQueryFields, operations: readonly RemoteOperation[], branch?: string): TDocument;
177
+ /** Turns a `revisionsList` selection into the header's per-scope revision map. */
178
+ declare function revisionMapFromRevisionsList(revisionsList: RevisionsListSelection): Record<string, number>;
179
+ //#endregion
180
+ //#region src/graphql-client/auth.d.ts
181
+ /**
182
+ * Resolves the bearer token to send with a request.
183
+ *
184
+ * Returning `undefined` (or an empty string) means "send this request
185
+ * anonymously": open Switchboards must keep serving reads to logged-out users.
186
+ */
187
+ type BearerTokenProvider = () => Promise<string | undefined>;
188
+ /**
189
+ * The default token provider: the token of the currently logged-in Renown user.
190
+ *
191
+ * It is deliberately resolved from `window.ph` on every call rather than
192
+ * captured at construction time, so a client built before login starts sending
193
+ * the token as soon as there is one.
194
+ *
195
+ * The token is requested WITHOUT an `aud` claim - the Switchboard verifier
196
+ * rejects tokens that carry an audience.
197
+ */
198
+ declare function ambientRenownTokenProvider(): Promise<string | undefined>;
199
+ /**
200
+ * Builds the SDK middleware that authenticates every request.
201
+ *
202
+ * The token is resolved per request and never cached, so a login, a logout or
203
+ * an expiry between two calls is picked up by the next one. When no token is
204
+ * available the request goes out unauthenticated.
205
+ */
206
+ declare function makeAuthMiddleware(tokenProvider: BearerTokenProvider): SdkFunctionWrapper;
207
+ //#endregion
208
+ //#region src/graphql-client/subgraph.d.ts
209
+ /**
210
+ * The factory a GraphQL code generator produces for a schema.
211
+ *
212
+ * It is the signature of `getSdk` emitted by the `typescript-graphql-request`
213
+ * plugin - the generated `getSdk` in `src/graphql/gen/schema.ts` is the
214
+ * canonical example - so a project can hand its own generated function straight
215
+ * to {@link SubgraphSdkRegistry.get} and keep every operation typed.
216
+ */
217
+ type SubgraphSdkFactory<TSdk> = (client: GraphQLClient, withWrapper?: SdkFunctionWrapper) => TSdk;
218
+ /**
219
+ * A GraphQL document that carries its result and variable types.
220
+ *
221
+ * This is the shape a code generator gives a document (`TypedDocumentNode`),
222
+ * declared structurally so that reactor-browser needs no dependency on
223
+ * `@graphql-typed-document-node/core`. A plain `DocumentNode` satisfies it too,
224
+ * with the result type falling back to whatever the caller passes explicitly.
225
+ */
226
+ type TypedGraphQLDocument<TResult, TVariables> = DocumentNode & {
227
+ __apiType?: (variables: TVariables) => TResult;
228
+ };
229
+ /** Extras for a one-off request. */
230
+ type GraphQLRequestOptions = {
231
+ /**
232
+ * The operation name reported to the auth and logging middleware. Read off
233
+ * the document when it is not given.
234
+ */
235
+ operationName?: string;
236
+ /**
237
+ * The operation type reported to the middleware, e.g. `"mutation"`. Read off
238
+ * the document when it is not given.
239
+ */
240
+ operationType?: string;
241
+ signal?: AbortSignal;
242
+ };
243
+ /**
244
+ * Derives a subgraph's endpoint from the Switchboard's GraphQL endpoint.
245
+ *
246
+ * Subgraphs are served next to the supergraph, at `<graphql base>/<name>`, so
247
+ * `http://localhost:4001/graphql` plus `statements` is
248
+ * `http://localhost:4001/graphql/statements`.
249
+ */
250
+ declare function subgraphUrlFromGraphqlUrl(url: string, name: string): string;
251
+ /**
252
+ * Reads the operation name and type off a document, for the middleware.
253
+ *
254
+ * Nothing depends on getting this right - it is reported to the middleware, not
255
+ * sent to the server - so an unreadable document falls back to an anonymous
256
+ * query rather than throwing.
257
+ */
258
+ declare function describeGraphQLDocument(document: string | DocumentNode): {
259
+ operationName: string;
260
+ operationType: string;
261
+ };
262
+ /**
263
+ * Binds typed subgraph SDKs to one Switchboard's transport and auth.
264
+ *
265
+ * Every capability a Switchboard exposes lives behind the same base URL, so an
266
+ * app should not have to build a second client - with a second copy of the auth
267
+ * configuration - to reach a project's own subgraph. The registry derives the
268
+ * endpoint, reuses one transport per subgraph and hands the code generator's
269
+ * `getSdk` the very middleware the reactor operations already go through.
270
+ *
271
+ * Transport and typing only: subgraph results are not cached and produce no
272
+ * change events.
273
+ */
274
+ declare class SubgraphSdkRegistry {
275
+ private readonly url;
276
+ private readonly middleware;
277
+ private readonly bindings;
278
+ constructor(url: string, middleware?: SdkFunctionWrapper);
279
+ /**
280
+ * Returns the subgraph's SDK, building it on first use.
281
+ *
282
+ * The transport is kept per subgraph name, so repeated calls do not rebuild
283
+ * it. The SDK itself is only reused when the same factory is passed again -
284
+ * two different generated SDKs over one subgraph each get their own, rather
285
+ * than the second call being handed the first one's methods.
286
+ */
287
+ get<TSdk>(name: string, getSdk: SubgraphSdkFactory<TSdk>): TSdk;
288
+ /** Returns the subgraph's endpoint, for diagnostics and tests. */
289
+ urlFor(name: string): string;
290
+ private binding;
291
+ }
292
+ //#endregion
293
+ //#region src/graphql-client/graphql-reactor-client.d.ts
294
+ type GraphQLReactorClientOptions = {
295
+ /** The Switchboard GraphQL endpoint, e.g. `http://localhost:4001/graphql`. */url: string;
296
+ /**
297
+ * A pre-built SDK to use instead of the transport derived from `url`.
298
+ * Mainly a test seam.
299
+ *
300
+ * A client built this way carries no auth middleware: the injected SDK owns
301
+ * its own transport, and therefore its own headers.
302
+ */
303
+ graphqlClient?: ReactorGraphQLClient;
304
+ /**
305
+ * Resolves the bearer token sent with every request, per request.
306
+ *
307
+ * Defaults to {@link ambientRenownTokenProvider}, i.e. the token of the
308
+ * logged-in Renown user, or none when nobody is logged in.
309
+ */
310
+ tokenProvider?: BearerTokenProvider;
311
+ /**
312
+ * The Switchboard GraphQL subscriptions endpoint, e.g.
313
+ * `ws://localhost:4001/graphql/subscriptions`.
314
+ *
315
+ * Defaults to the endpoint derived from `url` by
316
+ * {@link subscriptionsUrlFromGraphqlUrl}.
317
+ */
318
+ subscriptionsUrl?: string;
319
+ /**
320
+ * Whether server-pushed changes are delivered to subscribers.
321
+ *
322
+ * On by default: the first `subscribe` call opens a websocket and every
323
+ * change the Switchboard reports is emitted to matching subscribers, so
324
+ * documents another user, tab or processor writes invalidate the cache.
325
+ *
326
+ * Set it to `false` where there is no websocket to talk to. The client then
327
+ * only emits the changes it made itself.
328
+ */
329
+ realtime?: boolean;
330
+ };
331
+ /**
332
+ * The marker {@link isGraphQLReactorClient} looks for.
333
+ *
334
+ * A page can end up with two copies of this module - an app that bundles a
335
+ * package carrying its own copy, or a dev server that hot-replaced it - and
336
+ * then `instanceof` compares an instance against the other copy's class object
337
+ * and answers `false`. A branded property survives both.
338
+ */
339
+ declare const graphQLReactorClientBrand: "__powerhouseGraphQLReactorClient";
340
+ /**
341
+ * A light implementation of {@link IReactorBrowserClient} that talks plain
342
+ * GraphQL to a Switchboard, with no reactor in the bundle.
343
+ *
344
+ * It fills the same `window.ph` slots the full in-browser reactor client fills,
345
+ * so the reactor-browser hooks cannot tell the two apart.
346
+ */
347
+ declare class GraphQLReactorClient implements IReactorBrowserClient$1 {
348
+ /** See {@link isGraphQLReactorClient}. */
349
+ readonly [graphQLReactorClientBrand] = true;
350
+ private readonly sdk;
351
+ private readonly subgraphs;
352
+ private readonly listeners;
353
+ private readonly tokenProvider;
354
+ private readonly subscriptionsUrl;
355
+ private stopRealtime;
356
+ private realtimeStarted;
357
+ private realtimeGeneration;
358
+ private realtimeErrorLogged;
359
+ constructor(options: GraphQLReactorClientOptions);
360
+ get<TDocument extends PHDocument>(identifier: string, view?: ViewFilter, signal?: AbortSignal): Promise<TDocument>;
361
+ getOperations(documentIdentifier: string, view?: ViewFilter, filter?: OperationFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<Operation>>;
362
+ create<TDocument extends PHDocument = PHDocument>(document: PHDocument, parentIdentifier?: string, signal?: AbortSignal): Promise<TDocument>;
363
+ /**
364
+ * Pushes actions to the Switchboard and returns the updated document.
365
+ *
366
+ * The document is fetched first: the response is the baseline for the
367
+ * `sinceRevision` filter that narrows the returned operations to the ones
368
+ * this call appended, and it carries the state hash a signed action is
369
+ * stamped with.
370
+ *
371
+ * The emitted `Updated` event carries the document's id, never the
372
+ * identifier this was called with: subscribers - including `DocumentCache` -
373
+ * work in id space.
374
+ */
375
+ execute<TDocument extends PHDocument>(documentIdentifier: string, branch: string, actions: Action[], signal?: AbortSignal): Promise<TDocument>;
376
+ /**
377
+ * Deletes a document and announces it as a `Deleted` event.
378
+ *
379
+ * Pass a document id. The server resolves a slug just as happily, but
380
+ * `deleteDocument` returns a boolean - there is no document left to read an
381
+ * id off - so the identifier is announced verbatim on `context.childId`. A
382
+ * subscriber keyed by id, `DocumentCache` included, therefore only reacts to
383
+ * a delete by id.
384
+ */
385
+ deleteDocument(identifier: string, propagate?: PropagationMode, signal?: AbortSignal): Promise<void>;
386
+ /**
387
+ * Registers a change subscriber and returns its unsubscribe function.
388
+ *
389
+ * Two things produce the events delivered here. Every successful `create`,
390
+ * `execute` and `deleteDocument` emits one, which is what makes a
391
+ * `DocumentCache` built on this client invalidate after a dispatch. And,
392
+ * unless realtime is switched off, the first call to this method opens a
393
+ * websocket to the Switchboard and every change it reports - from another
394
+ * user, another tab or a server-side processor - is emitted too. A write of
395
+ * this client's own is therefore announced twice, once locally and once by
396
+ * the server; the cache refetches twice, which is harmless.
397
+ *
398
+ * A websocket that cannot be opened or is refused is logged once and then
399
+ * ignored: realtime is an enhancement, never a dependency. The failed socket
400
+ * is closed, so the next subscriber to arrive tries again.
401
+ *
402
+ * `view` is accepted for interface compatibility and ignored: the emitted
403
+ * documents are whatever the write returned, so there is nothing to re-scope.
404
+ *
405
+ * Events live in id space: `search.ids` is matched against the resolved
406
+ * document id, never against the identifier the write was issued with. The
407
+ * one exception is `deleteDocument`, which has no document to resolve an id
408
+ * from - see its own note. A `DocumentCache` on this client must therefore
409
+ * be read by id: a slug-keyed entry is never invalidated.
410
+ */
411
+ subscribe(search: SearchFilter, callback: (event: DocumentChangeEvent) => void, view?: ViewFilter): () => void;
412
+ /**
413
+ * Closes the realtime socket, if one was opened.
414
+ *
415
+ * Registered subscribers are left in place: they still receive the events
416
+ * this client produces itself.
417
+ *
418
+ * Disposing is NOT final - a later `subscribe` opens a new socket. React
419
+ * remounts a tree by running an effect's cleanup and then the effect again,
420
+ * on the same client, and `StrictMode` does exactly that on every mount; a
421
+ * terminal flag here would leave those pages without realtime for good, with
422
+ * nothing logged.
423
+ */
424
+ dispose(): void;
425
+ /**
426
+ * Binds a project's generated SDK to this client's transport and auth.
427
+ *
428
+ * Subgraphs are served next to the reactor's own supergraph, so the endpoint
429
+ * is derived from the client's `url` by appending the name, and the SDK is
430
+ * handed the same auth middleware every reactor call goes through. An app
431
+ * therefore configures one URL and one token provider, and reaches every
432
+ * capability of its Switchboard through this one client.
433
+ *
434
+ * `getSdk` is the function a GraphQL code generator emits for the subgraph's
435
+ * schema - see the README in this folder for the codegen recipe.
436
+ *
437
+ * Transport and typing only. Subgraph results are not cached, produce no
438
+ * change events and never reach `useDocument`.
439
+ */
440
+ subgraph<TSdk>(name: string, getSdk: SubgraphSdkFactory<TSdk>): TSdk;
441
+ /**
442
+ * Runs a one-off GraphQL document against the Switchboard's own endpoint,
443
+ * through the same transport and auth as everything else.
444
+ *
445
+ * The escape hatch for an operation not worth generating an SDK for. Pass a
446
+ * document a code generator typed and the result type follows; pass a plain
447
+ * `gql` document or a string and name the result type at the call site.
448
+ */
449
+ request<TResult = unknown, TVariables extends Variables = Variables>(document: TypedGraphQLDocument<TResult, TVariables> | string, variables?: TVariables, options?: GraphQLRequestOptions): Promise<TResult>;
450
+ /**
451
+ * Opens the realtime socket on the first subscriber.
452
+ *
453
+ * The subscription is a firehose - no `search` argument - and this client
454
+ * applies each subscriber's own filter on the way out, exactly as it does for
455
+ * its own emissions.
456
+ */
457
+ private startRealtime;
458
+ /**
459
+ * Gives up on a failed socket so that a later subscriber can try again.
460
+ *
461
+ * `graphql-ws` retries on its own and only reports here once it has given up,
462
+ * or once the server refused the subscription outright - which is what an
463
+ * auth-enabled Switchboard does to an anonymous subscriber. Keeping the dead
464
+ * stop function would make every later `subscribe` a no-op, so realtime would
465
+ * stay off for the life of the page even after the user signs in.
466
+ *
467
+ * The generation stamp discards a report from a socket that has already been
468
+ * replaced or disposed.
469
+ */
470
+ private handleRealtimeFailure;
471
+ /** Closes the socket and lets a later subscriber open a new one. */
472
+ private teardownRealtime;
473
+ /** Maps a server event onto the client-side event and emits it. */
474
+ private emitServerEvent;
475
+ /**
476
+ * Reports a broken realtime socket once per client, however many sockets it
477
+ * goes through.
478
+ *
479
+ * `graphql-ws` retries on its own, and a Switchboard without a websocket
480
+ * endpoint would otherwise fill the console for as long as the page is open.
481
+ */
482
+ private logRealtimeError;
483
+ /**
484
+ * Delivers an event to every matching subscriber.
485
+ *
486
+ * A subscriber that throws is logged and skipped so one bad listener cannot
487
+ * stop the others from being notified.
488
+ */
489
+ private emitChange;
490
+ }
491
+ /**
492
+ * Whether a value is a {@link GraphQLReactorClient}, including one built by
493
+ * another copy of this module.
494
+ *
495
+ * Use this rather than `instanceof`: the brand it tests for is shared by every
496
+ * copy of the class, so a client built by a hot-replaced module or by a package
497
+ * that bundled its own copy is still recognised.
498
+ */
499
+ declare function isGraphQLReactorClient(client: unknown): client is GraphQLReactorClient;
500
+ /**
501
+ * Maps a reactor `ViewFilter` onto the GraphQL `ViewFilterInput`.
502
+ *
503
+ * Point-in-time reads are rejected: the Switchboard read API has no revision
504
+ * argument, so silently returning the head state would be wrong.
505
+ */
506
+ declare function viewFilterInputFromViewFilter(view?: ViewFilter): ViewFilterInput | undefined;
507
+ //#endregion
508
+ //#region src/graphql-client/graphql-reactor-provider.d.ts
509
+ declare global {
510
+ interface Window {
511
+ /** Set by {@link ensurePHEventHandlers}; see its doc comment. */
512
+ __phEventHandlersRegistered?: boolean;
513
+ }
514
+ }
515
+ /**
516
+ * Registers the `window.ph` event handlers once per page.
517
+ *
518
+ * The `set*` helpers only dispatch CustomEvents - nothing writes `window.ph`
519
+ * until `addPHEventHandlers` has registered the listeners that do. Registration
520
+ * is guarded by a marker on `window` rather than a module-level flag so that a
521
+ * hot module replacement, or two copies of this module, still register once.
522
+ */
523
+ declare function ensurePHEventHandlers(): void;
524
+ type GraphQLReactorProviderProps = {
525
+ /** The Switchboard GraphQL endpoint, e.g. `http://localhost:4001/graphql`. */url: string;
526
+ /**
527
+ * Resolves the bearer token sent with every request, per request. Defaults to
528
+ * the token of the logged-in Renown user, or none when nobody is logged in.
529
+ */
530
+ tokenProvider?: GraphQLReactorClientOptions["tokenProvider"];
531
+ /**
532
+ * The Switchboard GraphQL subscriptions endpoint, e.g.
533
+ * `ws://localhost:4001/graphql/subscriptions`. Defaults to the endpoint
534
+ * derived from `url`.
535
+ */
536
+ subscriptionsUrl?: GraphQLReactorClientOptions["subscriptionsUrl"];
537
+ /**
538
+ * Whether server-pushed changes are delivered. On by default; set it to
539
+ * `false` where there is no websocket to talk to.
540
+ */
541
+ realtime?: GraphQLReactorClientOptions["realtime"];
542
+ /**
543
+ * The attachment service the editors below this provider read attachments
544
+ * through, published into the same `window.ph` slot Connect publishes it in.
545
+ *
546
+ * The app constructs it: attachments are a separate package, and which
547
+ * storage an app talks to is the app's business. Leave it out and the slot
548
+ * stays empty, exactly as it is without this provider.
549
+ */
550
+ attachmentService?: PHGlobal$1["attachmentService"];
551
+ /**
552
+ * The document model modules the app works with, imported from its generated
553
+ * package's `document-models` SUBPATH:
554
+ *
555
+ * ```tsx
556
+ * import { TodoV1, TodoV2 } from "my-models/document-models";
557
+ * <GraphQLReactorProvider url={url} documentModels={[TodoV1, TodoV2]}>
558
+ * ```
559
+ *
560
+ * Wrapped via {@link packageFromDocumentModels} and published through a
561
+ * {@link StaticPackageManager} into the same `window.ph.vetraPackageManager`
562
+ * slot Connect fills, so `useDocumentModelModules` and
563
+ * `useDocumentModelModuleById` work below this provider.
564
+ *
565
+ * Modules only, deliberately - not whole packages. Editors are not portable
566
+ * outside Connect yet (they read the selected document from Connect's
567
+ * drive/node selection) and would inflate the bundle; a light app that needs
568
+ * an editor imports the React component directly.
569
+ *
570
+ * Import from the `document-models` subpath, never from the package ROOT:
571
+ * the root entry also exports the package's `processorFactory`, and module
572
+ * resolution happens before tree-shaking, so a root import drags processor
573
+ * (server-side) code into the browser bundle and can break the build.
574
+ *
575
+ * Optional on purpose: a light app may equally ship NO modules and let the
576
+ * Switchboard own the model entirely - both modes are supported.
577
+ */
578
+ documentModels?: readonly DocumentModelModule<any>[];
579
+ children: ReactNode;
580
+ };
581
+ /**
582
+ * Mounts a {@link GraphQLReactorClient} into the `window.ph` slots the
583
+ * reactor-browser hooks read, so `useDocument`, `useDispatch` and
584
+ * `useReactorClient` work below it against a Switchboard, with no reactor in
585
+ * the bundle.
586
+ *
587
+ * It fills the document slots, plus `window.ph.vetraPackageManager` when
588
+ * `documentModels` is given (a fixed {@link StaticPackageManager}, which makes
589
+ * the document-model hooks work). `window.ph.reactorClientModule` always stays
590
+ * empty, so full-reactor surfaces (drives, jobs, editor auto-discovery) find
591
+ * nothing - an app below this provider renders components it imports itself.
592
+ *
593
+ * The client is built on the client only: on the server the slots stay empty
594
+ * and the hooks report their normal loading states. The props are read once,
595
+ * when the client is built - changing `url` afterwards does not rebuild it.
596
+ *
597
+ * The effect's cleanup disposes the cache and the client's socket, and the
598
+ * effect rebuilds both if it runs again on the same client - which is what a
599
+ * `StrictMode` mount does.
600
+ */
601
+ declare function GraphQLReactorProvider({
602
+ url,
603
+ tokenProvider,
604
+ subscriptionsUrl,
605
+ realtime,
606
+ attachmentService,
607
+ documentModels,
608
+ children
609
+ }: GraphQLReactorProviderProps): react_jsx_runtime0.JSX.Element;
610
+ /**
611
+ * Returns the {@link GraphQLReactorClient} mounted by
612
+ * {@link GraphQLReactorProvider}, or `undefined` when the slot holds something
613
+ * else - the full in-browser reactor client, or nothing yet.
614
+ *
615
+ * `useReactorClient` is typed as the narrow `IReactorBrowserClient` subset both
616
+ * implementations share. This is how a component reaches the light client's own
617
+ * surface, i.e. `subgraph` and `request`.
618
+ *
619
+ * The narrowing is by brand, not by `instanceof`: a page can carry two copies
620
+ * of this module - a bundled package with its own copy, or a hot-replaced one -
621
+ * and `instanceof` would then answer `false` for a perfectly good client and
622
+ * leave the component silently without one.
623
+ */
624
+ declare function useSwitchboardClient(): GraphQLReactorClient | undefined;
625
+ //#endregion
626
+ //#region src/graphql-client/operations.d.ts
627
+ /**
628
+ * The operation selection of `GetDocumentOperations`, lifted into a fragment so
629
+ * the write path can reuse `remoteOperationToLocal` on the items it selects.
630
+ */
631
+ declare const ReactorOperationFieldsFragmentDoc: graphql.DocumentNode;
632
+ /**
633
+ * `mutateDocument` plus the operations the mutation produced.
634
+ *
635
+ * The generated `MutateDocument` only selects the document fields, but
636
+ * `dispatchActions` reads per-action failures out of `result.operations[scope]`
637
+ * (`src/actions/dispatch.ts`), so the reducer-level errors would be lost.
638
+ *
639
+ * The operations filter keeps the extra selection to the operations this call
640
+ * could have appended rather than the whole history. All three of its fields
641
+ * matter:
642
+ * - `sinceRevision` is the lowest head revision across the targeted scopes, so
643
+ * it is only a safe window when the selection is scope-limited as well;
644
+ * - `scopes` limits the response to the scopes the pushed actions target,
645
+ * without it the server walks every scope of the document
646
+ * (`packages/reactor/src/core/reactor.ts` `getOperations`);
647
+ * - `branch` must match the branch the mutation writes to, otherwise the
648
+ * operations come from `main` (the server's default) while the actions were
649
+ * applied elsewhere.
650
+ */
651
+ declare const MutateDocumentWithOperationsDocument: graphql.DocumentNode;
652
+ type MutateDocumentWithOperationsVariables = {
653
+ documentIdentifier: Scalars["String"]["input"];
654
+ actions: ReadonlyArray<Scalars["JSONObject"]["input"]>;
655
+ view?: ViewFilterInput;
656
+ sinceRevision?: Scalars["Int"]["input"];
657
+ scopes?: ReadonlyArray<Scalars["String"]["input"]>;
658
+ branch?: Scalars["String"]["input"];
659
+ };
660
+ type MutateDocumentWithOperationsResult = {
661
+ readonly mutateDocument: PhDocumentFieldsFragment & {
662
+ readonly operations?: {
663
+ readonly items: ReadonlyArray<RemoteOperation>;
664
+ } | null;
665
+ };
666
+ };
667
+ //#endregion
668
+ //#region src/graphql-client/signing.d.ts
669
+ /**
670
+ * Stamps an action with the head of the scope it targets.
671
+ *
672
+ * `prevOpHash` is the hash of the scope state the action is meant to apply to;
673
+ * for a document at head that is the hash of the last operation in the scope,
674
+ * which the read path cannot fetch, so it is recomputed from the state.
675
+ * `prevOpIndex` is the index of that last operation: revisions count
676
+ * operations and indices are zero based, so an empty scope stamps `-1`, which
677
+ * matches what the remote controller records.
678
+ */
679
+ declare function stampAction(action: Action$1, document: PHDocument$1): Action$1;
680
+ /**
681
+ * Signs a stamped action, preserving any signatures it already carries.
682
+ *
683
+ * The signer reads `context.prevOpHash` off the action, so this must run after
684
+ * {@link stampAction}.
685
+ */
686
+ declare function signStampedAction(action: Action$1, signer: ISigner): Promise<Action$1>;
687
+ //#endregion
688
+ //#region src/graphql-client/static-package-manager.d.ts
689
+ /**
690
+ * A fixed set of packages presented through the `IPackageManager` interface,
691
+ * so the package-derived hooks - `useDocumentModelModules`,
692
+ * `useDocumentModelModuleById`, `useEditorModules`, `useVetraPackages` - work
693
+ * below `GraphQLReactorProvider` exactly as they do below Connect.
694
+ *
695
+ * Connect's package manager installs, updates and removes packages at runtime.
696
+ * A light app instead declares its packages once, as code it imports itself
697
+ * (every generated package root exports `manifest`, `documentModels`, `editors`
698
+ * and `upgradeManifests` by name), so every mutating member throws and
699
+ * `subscribe` never emits. For hand-picked modules without package artifacts,
700
+ * {@link packageFromDocumentModels} wraps them in one synthetic package.
701
+ */
702
+ declare class StaticPackageManager implements IPackageManager {
703
+ readonly registryUrl: null;
704
+ readonly packages: DocumentModelLib[];
705
+ constructor(packages: readonly DocumentModelLib<any>[]);
706
+ /**
707
+ * Resolves a module by document type across all packages. Mirrors the
708
+ * registry's semantics (`IDocumentModelRegistry.getModule`): the LATEST
709
+ * version wins, with `version ?? 1` as each module's default.
710
+ */
711
+ load(documentType: string): Promise<DocumentModelSource>;
712
+ subscribe(_handler: IPackagesListener): IPackageListerUnsubscribe;
713
+ getPackageSource(_packageName: string): RegistryPackageSource | null;
714
+ getPackageVersion(_packageName: string): string | undefined;
715
+ getRegistryPackages(): {
716
+ name: string;
717
+ version: string | undefined;
718
+ }[];
719
+ addPackage(_packageName: string): PackageManagerInstallResult;
720
+ addPackages(_packageNames: string[]): PackageManagerInstallResult[];
721
+ removePackage(_name: string): void;
722
+ updateLocalPackage(_pkg: DocumentModelLib, _version?: string): void;
723
+ addLocalPackage(_name: string, _loadedPackage: DocumentModelLib, _version?: string): void;
724
+ }
725
+ /**
726
+ * Wraps hand-picked modules in one synthetic `DocumentModelLib`, for apps that
727
+ * assemble their model list from mixed sources instead of passing whole
728
+ * packages. The manifest is fabricated - loose modules carry none - so prefer
729
+ * the `packages` prop with the real package exports when you have them: a real
730
+ * package also carries `editors`, which makes the editor hooks work.
731
+ */
732
+ declare function packageFromDocumentModels(documentModels: readonly DocumentModelModule<any>[]): DocumentModelLib;
733
+ //#endregion
734
+ //#region src/graphql-client/subscriptions.d.ts
735
+ /** The `documentChanges` payload, exactly as the Switchboard sends it. */
736
+ type DocumentChangesEventPayload = DocumentChangesSubscription["documentChanges"];
737
+ /** The connection payload sent with the `ConnectionInit` message. */
738
+ type ConnectionParams = Record<string, string>;
739
+ type DocumentChangesSubscriptionOptions = {
740
+ /** The websocket endpoint, e.g. `ws://localhost:4001/graphql/subscriptions`. */wsUrl: string;
741
+ /**
742
+ * Resolves the `ConnectionInit` payload. Called again on every reconnect, so
743
+ * a token that expired while the socket was down is refreshed on the way back
744
+ * up.
745
+ */
746
+ connectionParams?: () => Promise<ConnectionParams>; /** Called once per server event. */
747
+ onEvent: (event: DocumentChangesEventPayload) => void;
748
+ /**
749
+ * Called when the socket gives up: the retries built into `graphql-ws` are
750
+ * exhausted, or the server rejected the subscription. Realtime is an
751
+ * enhancement, so callers are expected to log and carry on.
752
+ */
753
+ onError: (error: unknown) => void;
754
+ };
755
+ /**
756
+ * Opens one `documentChanges` subscription and feeds every event to `onEvent`.
757
+ *
758
+ * The subscription is a firehose: no `search` argument, so the server sends
759
+ * every change the connection is allowed to see and the caller filters. This is
760
+ * the only module that knows about `graphql-ws`.
761
+ *
762
+ * Returns the stop function, which cancels the subscription and closes the
763
+ * socket. It is safe to call more than once.
764
+ */
765
+ declare function startDocumentChangesSubscription(options: DocumentChangesSubscriptionOptions): () => void;
766
+ /**
767
+ * Derives the websocket endpoint from the GraphQL http endpoint.
768
+ *
769
+ * `http://host/graphql` becomes `ws://host/graphql/subscriptions`, which is
770
+ * where the Switchboard mounts its websocket server (`packages/reactor-api`
771
+ * `startServer`). A URL that already speaks `ws`/`wss` only gets the path.
772
+ */
773
+ declare function subscriptionsUrlFromGraphqlUrl(url: string): string;
774
+ /**
775
+ * Turns a bearer token provider into `connectionParams`.
776
+ *
777
+ * The header key is the lowercase `authorization` the Switchboard's websocket
778
+ * context factory reads. Without a token the payload is empty: an open
779
+ * Switchboard serves anonymous subscribers.
780
+ */
781
+ declare function makeAuthConnectionParams(tokenProvider: BearerTokenProvider): () => Promise<ConnectionParams>;
782
+ //#endregion
783
+ //#region src/hooks/document-cache.d.ts
784
+ /** Returns all documents in the reactor. */
785
+ declare const useDocumentCache: UsePHGlobalValue$1<IDocumentCache>;
786
+ /** Sets all of the documents in the reactor. */
787
+ declare const setDocumentCache: SetPHGlobalValue$1<IDocumentCache>;
788
+ /** Adds an event handler for all of the documents in the reactor. */
789
+ declare const addDocumentCacheEventHandler: () => void;
790
+ /**
791
+ * Retrieves a document from the reactor and subscribes to changes using React Suspense.
792
+ * This hook will suspend rendering while the document is loading.
793
+ * @param id - The document ID to retrieve, or null/undefined to skip retrieval
794
+ * @returns The document if found, or undefined if id is null/undefined
795
+ */
796
+ declare function useDocument(id: string | null | undefined): PHDocument$1 | undefined;
797
+ /**
798
+ * Retrieves a document from the reactor and subscribes to changes without
799
+ * suspending or throwing. Use this when the ID might be stale (e.g., a
800
+ * previously selected node that has since been deleted) and the consumer
801
+ * wants to render a placeholder instead of crashing.
802
+ *
803
+ * Unlike {@link useGetDocumentAsync}, this hook subscribes to cache
804
+ * updates, so the returned state stays in sync with reactor changes.
805
+ *
806
+ * @param id - The document ID to retrieve, or null/undefined to skip retrieval
807
+ * @returns An object containing:
808
+ * - status: "initial" | "pending" | "success" | "error"
809
+ * - data: The document if successfully loaded
810
+ * - isPending: Whether the document is currently loading
811
+ * - error: Any error that occurred during loading (e.g., document not found)
812
+ * - reload: Function to force a refetch, or undefined when no id is supplied
813
+ */
814
+ declare function useDocumentSafe(id: string | null | undefined): {
815
+ readonly status: "initial";
816
+ readonly isPending: false;
817
+ readonly error: undefined;
818
+ readonly data: undefined;
819
+ readonly reload: undefined;
820
+ } | {
821
+ readonly reload: () => Promise<PHDocument$1>;
822
+ readonly status: "pending";
823
+ readonly isPending: true;
824
+ readonly error: undefined;
825
+ readonly data: undefined;
826
+ } | {
827
+ readonly reload: () => Promise<PHDocument$1>;
828
+ readonly status: "success";
829
+ readonly isPending: false;
830
+ readonly error: undefined;
831
+ readonly data: PHDocument$1;
832
+ } | {
833
+ readonly reload: () => Promise<PHDocument$1>;
834
+ readonly status: "error";
835
+ readonly isPending: false;
836
+ readonly error: unknown;
837
+ readonly data: undefined;
838
+ };
839
+ /**
840
+ * Retrieves multiple documents from the reactor using React Suspense.
841
+ * This hook will suspend rendering while any of the documents are loading.
842
+ *
843
+ * Uses getBatch from the document cache which handles promise caching internally,
844
+ * ensuring stable references for useSyncExternalStore.
845
+ *
846
+ * @param ids - Array of document IDs to retrieve, or null/undefined to skip retrieval
847
+ * @returns An array of documents if found, or empty array if ids is null/undefined
848
+ */
849
+ declare function useDocuments(ids: string[] | null | undefined): PHDocument$1[];
850
+ /**
851
+ * Returns a function to retrieve a document from the cache.
852
+ * The returned function fetches and returns a document by ID.
853
+ * @returns A function that takes a document ID and returns a Promise of the document
854
+ */
855
+ declare function useGetDocument(): (id: string) => Promise<PHDocument$1>;
856
+ /**
857
+ * Returns a function to retrieve multiple documents from the cache.
858
+ * The returned function fetches and returns documents by their IDs.
859
+ * @returns A function that takes an array of document IDs and returns a Promise of the documents
860
+ */
861
+ declare function useGetDocuments(): (ids: string[]) => Promise<PHDocument$1[]>;
862
+ /**
863
+ * Retrieves a document from the reactor without suspending rendering.
864
+ * Returns the current state of the document loading operation.
865
+ * @param id - The document ID to retrieve, or null/undefined to skip retrieval
866
+ * @returns An object containing:
867
+ * - status: "initial" | "pending" | "success" | "error"
868
+ * - data: The document if successfully loaded
869
+ * - isPending: Boolean indicating if the document is currently loading
870
+ * - error: Any error that occurred during loading
871
+ * - reload: Function to force reload the document from cache
872
+ */
873
+ declare function useGetDocumentAsync(id: string | null | undefined): {
874
+ readonly status: "initial";
875
+ readonly data: undefined;
876
+ readonly isPending: false;
877
+ readonly error: undefined;
878
+ readonly reload: undefined;
879
+ } | {
880
+ readonly reload: () => Promise<PHDocument$1>;
881
+ readonly status: "pending";
882
+ readonly isPending: true;
883
+ readonly error: undefined;
884
+ readonly data: undefined;
885
+ } | {
886
+ readonly reload: () => Promise<PHDocument$1>;
887
+ readonly status: "success";
888
+ readonly isPending: false;
889
+ readonly error: undefined;
890
+ readonly data: PHDocument$1;
891
+ } | {
892
+ readonly reload: () => Promise<PHDocument$1>;
893
+ readonly status: "error";
894
+ readonly isPending: false;
895
+ readonly error: unknown;
896
+ readonly data: undefined;
897
+ };
898
+ //#endregion
899
+ //#region src/hooks/reactor.d.ts
900
+ /** Returns the reactor client module (in-process or worker-backed) */
901
+ declare const useReactorClientModule: UsePHGlobalValue<BrowserReactorClientModule | WorkerReactorClientModule>;
902
+ /** Sets the reactor client module */
903
+ declare const setReactorClientModule: SetPHGlobalValue<BrowserReactorClientModule | WorkerReactorClientModule>;
904
+ /** Adds an event handler for the reactor client module */
905
+ declare const addReactorClientModuleEventHandler: AddPHGlobalEventHandler;
906
+ /** Returns the reactor client */
907
+ declare const useReactorClient: UsePHGlobalValue<IReactorBrowserClient>;
908
+ /** Sets the reactor client */
909
+ declare const setReactorClient: SetPHGlobalValue<IReactorBrowserClient>;
910
+ /** Adds an event handler for the reactor client */
911
+ declare const addReactorClientEventHandler: AddPHGlobalEventHandler;
912
+ declare const useSync: () => ISyncManager | undefined;
913
+ declare const useSyncList: () => _powerhousedao_reactor0.Remote[];
914
+ declare const useModelRegistry: () => IDocumentModelRegistry | undefined;
915
+ declare const useDatabase: () => Kysely<Database> | undefined;
916
+ declare const usePGlite: () => PGlite | undefined;
917
+ //#endregion
918
+ //#region src/hooks/dispatch.d.ts
919
+ /**
920
+ * Returns a dispatch function for dispatching actions to a document.
921
+ * Used internally by other hooks to provide action dispatching capabilities.
922
+ * @param document - The document to dispatch actions to.
923
+ * @returns A tuple containing the document and a dispatch function.
924
+ */
925
+ type DispatchFn<TAction> = (actionOrActions: TAction[] | TAction | undefined, onErrors?: (errors: Error[]) => void, onSuccess?: (result: PHDocument$1) => void) => void;
926
+ type UseDispatchResult<TDocument, TAction> = readonly [TDocument | undefined, DispatchFn<TAction>];
927
+ declare function useDispatch<TDocument = PHDocument$1, TAction = Action$1>(document: TDocument | undefined): UseDispatchResult<TDocument, TAction>;
928
+ //#endregion
929
+ //#region src/hooks/document-model-modules.d.ts
930
+ declare function useDocumentModelModules(): DocumentModelModule[] | undefined;
931
+ /**
932
+ * Resolves a document model module by document type, mirroring the registry's
933
+ * semantics (`IDocumentModelRegistry.getModule`): with `version` omitted the
934
+ * LATEST version of the type wins (`version ?? 1` as each module's default),
935
+ * with `version` given only an exact match is returned. The reactor resolves
936
+ * modules the same way when a document is created, so metadata read through
937
+ * this hook and the version a creation actually uses cannot disagree.
938
+ */
939
+ declare function useDocumentModelModuleById(id: string | null | undefined, version?: number): DocumentModelModule | undefined;
940
+ //#endregion
941
+ //#region src/hooks/document-operations.d.ts
942
+ type InternalState = {
943
+ globalOperations: Operation$1[];
944
+ localOperations: Operation$1[];
945
+ isLoading: boolean;
946
+ error: Error | undefined;
947
+ };
948
+ /** What `useDocumentOperations` returns; exported so consumers can name it. */
949
+ type DocumentOperationsState = InternalState & {
950
+ refetch: () => void;
951
+ };
952
+ /**
953
+ * Hook to fetch document operations via the reactor client.
954
+ * Operations are no longer auto-populated on documents and must be fetched explicitly.
955
+ *
956
+ * @param documentId - The document ID to fetch operations for
957
+ * @returns Object containing globalOperations, localOperations, isLoading, and error
958
+ */
959
+ declare function useDocumentOperations(documentId: string | null | undefined): DocumentOperationsState;
960
+ //#endregion
961
+ //#region src/hooks/attachment-service.d.ts
962
+ /** Returns the attachment service from window.ph */
963
+ declare const useAttachmentService: UsePHGlobalValue<IAttachmentService>;
964
+ /** Sets the attachment service on window.ph */
965
+ declare const setAttachmentService: SetPHGlobalValue<IAttachmentService>;
966
+ /** Registers the attachmentService window event handler */
967
+ declare const addAttachmentServiceEventHandler: AddPHGlobalEventHandler;
968
+ //#endregion
969
+ export { GraphQLRequestOptions as $, useGetDocuments as A, SyncStatus$1 as At, stampAction as B, setDocumentCache as C, PushResult as Ct, useDocuments as D, RemoteDocumentData as Dt, useDocumentSafe as E, RemoteDocumentChangeEvent as Et, startDocumentChangesSubscription as F, GraphQLReactorProvider as G, MutateDocumentWithOperationsResult as H, subscriptionsUrlFromGraphqlUrl as I, useSwitchboardClient as J, GraphQLReactorProviderProps as K, StaticPackageManager as L, DocumentChangesEventPayload as M, DocumentCache as Mt, DocumentChangesSubscriptionOptions as N, addPromiseState as Nt, useGetDocument as O, RemoteOperation as Ot, makeAuthConnectionParams as P, readPromiseState as Pt, viewFilterInputFromViewFilter as Q, packageFromDocumentModels as R, addDocumentCacheEventHandler as S, MergeHandler as St, useDocumentCache as T, RemoteControllerOptions as Tt, MutateDocumentWithOperationsVariables as U, MutateDocumentWithOperationsDocument as V, ReactorOperationFieldsFragmentDoc as W, GraphQLReactorClientOptions as X, GraphQLReactorClient as Y, isGraphQLReactorClient as Z, usePGlite as _, GetDocumentResult as _t, useDocumentOperations as a, BearerTokenProvider as at, useSync as b, IRemoteClient as bt, DispatchFn as c, GetDocumentQueryFields as ct, addReactorClientEventHandler as d, phDocumentFromGetDocument as dt, SubgraphSdkFactory as et, addReactorClientModuleEventHandler as f, phDocumentFromMutation as ft, useModelRegistry as g, DocumentChangeListener as gt, useDatabase as h, ConflictStrategy as ht, DocumentOperationsState as i, subgraphUrlFromGraphqlUrl as it, ConnectionParams as j, TrackedAction as jt, useGetDocumentAsync as k, RemoteOperationResultPage as kt, UseDispatchResult as l, GetDocumentQueryResult as lt, setReactorClientModule as m, ConflictInfo as mt, setAttachmentService as n, TypedGraphQLDocument as nt, useDocumentModelModuleById as o, ambientRenownTokenProvider as ot, setReactorClient as p, revisionMapFromRevisionsList as pt, ensurePHEventHandlers as q, useAttachmentService as r, describeGraphQLDocument as rt, useDocumentModelModules as s, makeAuthMiddleware as st, addAttachmentServiceEventHandler as t, SubgraphSdkRegistry as tt, useDispatch as u, RevisionsListSelection as ut, useReactorClient as v, GetDocumentWithOperationsResult as vt, useDocument as w, RemoteControllerGraphQLClient as wt, useSyncList as x, IRemoteController as xt, useReactorClientModule as y, GetOperationsResult as yt, signStampedAction as z };
970
+ //# sourceMappingURL=attachment-service-CghxHYta.d.ts.map