@powerhousedao/reactor-browser 6.2.2-dev.6 → 6.2.2-dev.60

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