@powerhousedao/reactor-browser 6.2.2-dev.9 → 6.2.2-staging.0

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 (74) hide show
  1. package/README.md +341 -0
  2. package/dist/attachment-service-KFFLBEuD.d.ts +1062 -0
  3. package/dist/attachment-service-KFFLBEuD.d.ts.map +1 -0
  4. package/dist/{client-u13cr-Vg.js → client-B8ezRmBB.js} +30 -3
  5. package/dist/client-B8ezRmBB.js.map +1 -0
  6. package/dist/client-BIHN_UyR.d.ts +14 -0
  7. package/dist/client-BIHN_UyR.d.ts.map +1 -0
  8. package/dist/{client-_Gh2Uf0E.js → client-D66jVnot.js} +79 -13
  9. package/dist/client-D66jVnot.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-model-modules-DfQBNGc-.js +419 -0
  13. package/dist/document-model-modules-DfQBNGc-.js.map +1 -0
  14. package/dist/document-operations-CBExT76y.js +2544 -0
  15. package/dist/document-operations-CBExT76y.js.map +1 -0
  16. package/dist/global-1rvI8VdA.d.ts +400 -0
  17. package/dist/global-1rvI8VdA.d.ts.map +1 -0
  18. package/dist/index-BE3wBHLP.d.ts +349 -0
  19. package/dist/index-BE3wBHLP.d.ts.map +1 -0
  20. package/dist/index-BIVDXw3K.d.ts +144 -0
  21. package/dist/index-BIVDXw3K.d.ts.map +1 -0
  22. package/dist/index.d.ts +385 -718
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +957 -1712
  25. package/dist/index.js.map +1 -1
  26. package/dist/{inspector-proxy-CvQDDxmT.d.ts → inspector-proxy-6h5VKAwt.d.ts} +4 -2
  27. package/dist/inspector-proxy-6h5VKAwt.d.ts.map +1 -0
  28. package/dist/{make-ph-event-functions-BHoLPif5.js → make-ph-event-functions-DBq3iWYn.js} +1 -1
  29. package/dist/{make-ph-event-functions-BHoLPif5.js.map → make-ph-event-functions-DBq3iWYn.js.map} +1 -1
  30. package/dist/{index-DS4W07Y8.d.ts → pglite-CntadC_p-9NDG14dS.d.ts} +2 -142
  31. package/dist/pglite-CntadC_p-9NDG14dS.d.ts.map +1 -0
  32. package/dist/{relational-Dj06-YkI.js → relational-D4sxGPz7.js} +2 -2
  33. package/dist/{relational-Dj06-YkI.js.map → relational-D4sxGPz7.js.map} +1 -1
  34. package/dist/renown-BHxwP7xU.js +97 -0
  35. package/dist/renown-BHxwP7xU.js.map +1 -0
  36. package/dist/{renown-D-1c_Bvx.js → renown-BIEv6bSI.js} +523 -57
  37. package/dist/renown-BIEv6bSI.js.map +1 -0
  38. package/dist/src/ai/index.d.ts +371 -0
  39. package/dist/src/ai/index.d.ts.map +1 -0
  40. package/dist/src/ai/index.js +1067 -0
  41. package/dist/src/ai/index.js.map +1 -0
  42. package/dist/src/analytics/index.d.ts +1 -1
  43. package/dist/src/analytics/index.js +2 -1
  44. package/dist/src/analytics/index.js.map +1 -1
  45. package/dist/src/graphql/client.d.ts +3 -2
  46. package/dist/src/graphql/client.js +1 -1
  47. package/dist/src/graphql-client/entry.d.ts +4 -0
  48. package/dist/src/graphql-client/entry.js +4 -0
  49. package/dist/src/relational/index.d.ts +1 -1
  50. package/dist/src/relational/index.js +1 -1
  51. package/dist/src/renown/index.d.ts +2 -2
  52. package/dist/src/renown/index.js +3 -2
  53. package/dist/src/rpc/index.d.ts +6 -3
  54. package/dist/src/rpc/index.d.ts.map +1 -1
  55. package/dist/src/rpc/index.js +41 -10
  56. package/dist/src/rpc/index.js.map +1 -1
  57. package/dist/store-BJYcr_FL.js +37 -0
  58. package/dist/store-BJYcr_FL.js.map +1 -0
  59. package/dist/switchboard-D4-_jwk-.js +271 -0
  60. package/dist/switchboard-D4-_jwk-.js.map +1 -0
  61. package/dist/{types-CPV0Cnsy.d.ts → types-6vDzbRRS.d.ts} +1 -1
  62. package/dist/{types-CPV0Cnsy.d.ts.map → types-6vDzbRRS.d.ts.map} +1 -1
  63. package/dist/{client-09xv0Dq6.d.ts → types-Dcv1ZLoW.d.ts} +87 -19
  64. package/dist/types-Dcv1ZLoW.d.ts.map +1 -0
  65. package/package.json +27 -10
  66. package/dist/client-09xv0Dq6.d.ts.map +0 -1
  67. package/dist/client-_Gh2Uf0E.js.map +0 -1
  68. package/dist/client-u13cr-Vg.js.map +0 -1
  69. package/dist/document-by-id-dLYFX-xz.js.map +0 -1
  70. package/dist/index-D3bV5rcl.d.ts +0 -216
  71. package/dist/index-D3bV5rcl.d.ts.map +0 -1
  72. package/dist/index-DS4W07Y8.d.ts.map +0 -1
  73. package/dist/inspector-proxy-CvQDDxmT.d.ts.map +0 -1
  74. package/dist/renown-D-1c_Bvx.js.map +0 -1
@@ -0,0 +1,1062 @@
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-1rvI8VdA.js";
2
+ import { t as PGlite } from "./pglite-CntadC_p-9NDG14dS.js";
3
+ import { A as ViewFilterInput, C as GetDocumentQuery, D as PropagationMode$1, E as PhDocumentFieldsFragment, O as Scalars, S as GetDocumentOperationsQuery, b as DocumentChangesSubscription, c as ReactorGraphQLClient, g as ActionInput, k as SdkFunctionWrapper } from "./types-Dcv1ZLoW.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
+ * `IReactorClient.execute`'s trailing `subject` is deliberately not accepted
412
+ * here. It names the subject a local read gate answers as, and this client
413
+ * runs no gate: the Switchboard decides what to serve from the bearer on the
414
+ * request. Declaring it would suggest a per-call choice that does not exist.
415
+ */
416
+ execute<TDocument extends PHDocument>(documentIdentifier: string, branch: string, actions: Action[], signal?: AbortSignal): Promise<TDocument>;
417
+ /**
418
+ * Deletes a document and announces it as a `Deleted` event.
419
+ *
420
+ * Pass a document id. The server resolves a slug just as happily, but
421
+ * `deleteDocument` returns a boolean - there is no document left to read an
422
+ * id off - so the identifier is announced verbatim on `context.childId`. A
423
+ * subscriber keyed by id, `DocumentCache` included, therefore only reacts to
424
+ * a delete by id.
425
+ */
426
+ deleteDocument(identifier: string, propagate?: PropagationMode, signal?: AbortSignal): Promise<void>;
427
+ /**
428
+ * Registers a change subscriber and returns its unsubscribe function.
429
+ *
430
+ * Two things produce the events delivered here. Every successful `create`,
431
+ * `execute` and `deleteDocument` emits one, which is what makes a
432
+ * `DocumentCache` built on this client invalidate after a dispatch. And,
433
+ * unless realtime is switched off, the first call to this method opens a
434
+ * websocket to the Switchboard and every change it reports - from another
435
+ * user, another tab or a server-side processor - is emitted too. A write of
436
+ * this client's own is therefore announced twice, once locally and once by
437
+ * the server; the cache refetches twice, which is harmless.
438
+ *
439
+ * A websocket that cannot be opened or is refused is logged once and then
440
+ * ignored: realtime is an enhancement, never a dependency. The failed socket
441
+ * is closed, so the next subscriber to arrive tries again.
442
+ *
443
+ * `view` is accepted for interface compatibility and ignored: the emitted
444
+ * documents are whatever the write returned, so there is nothing to re-scope.
445
+ *
446
+ * Events live in id space: `search.ids` is matched against the resolved
447
+ * document id, never against the identifier the write was issued with. The
448
+ * one exception is `deleteDocument`, which has no document to resolve an id
449
+ * from - see its own note. A `DocumentCache` on this client must therefore
450
+ * be read by id: a slug-keyed entry is never invalidated.
451
+ */
452
+ subscribe(search: SearchFilter, callback: (event: DocumentChangeEvent) => void, view?: ViewFilter): () => void;
453
+ /**
454
+ * Closes the realtime socket, if one was opened.
455
+ *
456
+ * Registered subscribers are left in place: they still receive the events
457
+ * this client produces itself.
458
+ *
459
+ * Disposing is NOT final - a later `subscribe` opens a new socket. React
460
+ * remounts a tree by running an effect's cleanup and then the effect again,
461
+ * on the same client, and `StrictMode` does exactly that on every mount; a
462
+ * terminal flag here would leave those pages without realtime for good, with
463
+ * nothing logged.
464
+ */
465
+ dispose(): void;
466
+ /**
467
+ * Binds a project's generated SDK to this client's transport and auth.
468
+ *
469
+ * Subgraphs are served next to the reactor's own supergraph, so the endpoint
470
+ * is derived from the client's `url` by appending the name, and the SDK is
471
+ * handed the same auth middleware every reactor call goes through. An app
472
+ * therefore configures one URL and one token provider, and reaches every
473
+ * capability of its Switchboard through this one client.
474
+ *
475
+ * `getSdk` is the function a GraphQL code generator emits for the subgraph's
476
+ * schema - see the README in this folder for the codegen recipe.
477
+ *
478
+ * Transport and typing only. Subgraph results are not cached, produce no
479
+ * change events and never reach `useDocument`.
480
+ */
481
+ subgraph<TSdk>(name: string, getSdk: SubgraphSdkFactory<TSdk>): TSdk;
482
+ /**
483
+ * Runs a one-off GraphQL document against the Switchboard's own endpoint,
484
+ * through the same transport and auth as everything else.
485
+ *
486
+ * The escape hatch for an operation not worth generating an SDK for. Pass a
487
+ * document a code generator typed and the result type follows; pass a plain
488
+ * `gql` document or a string and name the result type at the call site.
489
+ */
490
+ request<TResult = unknown, TVariables extends Variables = Variables>(document: TypedGraphQLDocument<TResult, TVariables> | string, variables?: TVariables, options?: GraphQLRequestOptions): Promise<TResult>;
491
+ /**
492
+ * Opens the realtime socket on the first subscriber.
493
+ *
494
+ * The subscription is a firehose - no `search` argument - and this client
495
+ * applies each subscriber's own filter on the way out, exactly as it does for
496
+ * its own emissions.
497
+ */
498
+ private startRealtime;
499
+ /**
500
+ * Gives up on a failed socket so that a later subscriber can try again.
501
+ *
502
+ * `graphql-ws` retries on its own and only reports here once it has given up,
503
+ * or once the server refused the subscription outright - which is what an
504
+ * auth-enabled Switchboard does to an anonymous subscriber. Keeping the dead
505
+ * stop function would make every later `subscribe` a no-op, so realtime would
506
+ * stay off for the life of the page even after the user signs in.
507
+ *
508
+ * The generation stamp discards a report from a socket that has already been
509
+ * replaced or disposed.
510
+ */
511
+ private handleRealtimeFailure;
512
+ /** Closes the socket and lets a later subscriber open a new one. */
513
+ private teardownRealtime;
514
+ /** Maps a server event onto the client-side event and emits it. */
515
+ private emitServerEvent;
516
+ /**
517
+ * Reports a broken realtime socket once per client, however many sockets it
518
+ * goes through.
519
+ *
520
+ * `graphql-ws` retries on its own, and a Switchboard without a websocket
521
+ * endpoint would otherwise fill the console for as long as the page is open.
522
+ */
523
+ private logRealtimeError;
524
+ /**
525
+ * Delivers an event to every matching subscriber.
526
+ *
527
+ * A subscriber that throws is logged and skipped so one bad listener cannot
528
+ * stop the others from being notified.
529
+ */
530
+ private emitChange;
531
+ }
532
+ /**
533
+ * Whether a value is a {@link GraphQLReactorClient}, including one built by
534
+ * another copy of this module.
535
+ *
536
+ * Use this rather than `instanceof`: the brand it tests for is shared by every
537
+ * copy of the class, so a client built by a hot-replaced module or by a package
538
+ * that bundled its own copy is still recognised.
539
+ */
540
+ declare function isGraphQLReactorClient(client: unknown): client is GraphQLReactorClient;
541
+ /**
542
+ * Maps a reactor `ViewFilter` onto the GraphQL `ViewFilterInput`.
543
+ *
544
+ * Point-in-time reads are rejected: the Switchboard read API has no revision
545
+ * argument, so silently returning the head state would be wrong.
546
+ */
547
+ declare function viewFilterInputFromViewFilter(view?: ViewFilter): ViewFilterInput | undefined;
548
+ //#endregion
549
+ //#region src/graphql-client/graphql-reactor-provider.d.ts
550
+ declare global {
551
+ interface Window {
552
+ /** Set by {@link ensurePHEventHandlers}; see its doc comment. */
553
+ __phEventHandlersRegistered?: boolean;
554
+ }
555
+ }
556
+ /**
557
+ * Registers the `window.ph` event handlers once per page.
558
+ *
559
+ * The `set*` helpers only dispatch CustomEvents - nothing writes `window.ph`
560
+ * until `addPHEventHandlers` has registered the listeners that do. Registration
561
+ * is guarded by a marker on `window` rather than a module-level flag so that a
562
+ * hot module replacement, or two copies of this module, still register once.
563
+ */
564
+ declare function ensurePHEventHandlers(): void;
565
+ type GraphQLReactorProviderProps = {
566
+ /** The Switchboard GraphQL endpoint, e.g. `http://localhost:4001/graphql`. */url: string;
567
+ /**
568
+ * Resolves the bearer token sent with every request, per request. Defaults to
569
+ * the token of the logged-in Renown user, or none when nobody is logged in.
570
+ */
571
+ tokenProvider?: GraphQLReactorClientOptions["tokenProvider"];
572
+ /**
573
+ * The Switchboard GraphQL subscriptions endpoint, e.g.
574
+ * `ws://localhost:4001/graphql/subscriptions`. Defaults to the endpoint
575
+ * derived from `url`.
576
+ */
577
+ subscriptionsUrl?: GraphQLReactorClientOptions["subscriptionsUrl"];
578
+ /**
579
+ * Whether server-pushed changes are delivered. On by default; set it to
580
+ * `false` where there is no websocket to talk to.
581
+ */
582
+ realtime?: GraphQLReactorClientOptions["realtime"];
583
+ /**
584
+ * The attachment service the editors below this provider read attachments
585
+ * through, published into the same `window.ph` slot Connect publishes it in.
586
+ *
587
+ * The app constructs it: attachments are a separate package, and which
588
+ * storage an app talks to is the app's business. Leave it out and the slot
589
+ * stays empty, exactly as it is without this provider.
590
+ */
591
+ attachmentService?: PHGlobal$1["attachmentService"];
592
+ /**
593
+ * The document model modules the app works with, imported from its generated
594
+ * package's `document-models` SUBPATH:
595
+ *
596
+ * ```tsx
597
+ * import { TodoV1, TodoV2 } from "my-models/document-models";
598
+ * <GraphQLReactorProvider url={url} documentModels={[TodoV1, TodoV2]}>
599
+ * ```
600
+ *
601
+ * Wrapped via {@link packageFromDocumentModels} and published through a
602
+ * {@link StaticPackageManager} into the same `window.ph.vetraPackageManager`
603
+ * slot Connect fills, so `useDocumentModelModules` and
604
+ * `useDocumentModelModuleById` work below this provider.
605
+ *
606
+ * Modules only, deliberately - not whole packages. Editors are not portable
607
+ * outside Connect yet (they read the selected document from Connect's
608
+ * drive/node selection) and would inflate the bundle; a light app that needs
609
+ * an editor imports the React component directly.
610
+ *
611
+ * Import from the `document-models` subpath, never from the package ROOT:
612
+ * the root entry also exports the package's `processorFactory`, and module
613
+ * resolution happens before tree-shaking, so a root import drags processor
614
+ * (server-side) code into the browser bundle and can break the build.
615
+ *
616
+ * They are also what lets the client SIGN a batch of two or more actions:
617
+ * signing the second action needs the state the first one leaves behind, and
618
+ * only the document's own reducer can predict it, so a batch is signable only
619
+ * while the module matching the document's type and exact version is here.
620
+ * Single actions are signed without any of this.
621
+ *
622
+ * Optional on purpose: a light app may equally ship NO modules and let the
623
+ * Switchboard own the model entirely - both modes are supported.
624
+ *
625
+ * Like `url`, this is read once, when the client is built.
626
+ */
627
+ documentModels?: readonly DocumentModelModule<any>[];
628
+ children: ReactNode;
629
+ };
630
+ /**
631
+ * Mounts a {@link GraphQLReactorClient} into the `window.ph` slots the
632
+ * reactor-browser hooks read, so `useDocument`, `useDispatch` and
633
+ * `useReactorClient` work below it against a Switchboard, with no reactor in
634
+ * the bundle.
635
+ *
636
+ * It fills the document slots, plus `window.ph.vetraPackageManager` when
637
+ * `documentModels` is given (a fixed {@link StaticPackageManager}, which makes
638
+ * the document-model hooks work). The same modules go to the client itself, so
639
+ * a dispatch of two or more actions is signed rather than refused.
640
+ * `window.ph.reactorClientModule` always stays empty, so full-reactor surfaces
641
+ * (drives, jobs, editor auto-discovery) find nothing - an app below this
642
+ * provider renders components it imports itself.
643
+ *
644
+ * The client is built on the client only: on the server the slots stay empty
645
+ * and the hooks report their normal loading states. The props are read once,
646
+ * when the client is built - changing `url` afterwards does not rebuild it.
647
+ *
648
+ * The effect's cleanup disposes the cache and the client's socket, and the
649
+ * effect rebuilds both if it runs again on the same client - which is what a
650
+ * `StrictMode` mount does.
651
+ */
652
+ declare function GraphQLReactorProvider({
653
+ url,
654
+ tokenProvider,
655
+ subscriptionsUrl,
656
+ realtime,
657
+ attachmentService,
658
+ documentModels,
659
+ children
660
+ }: GraphQLReactorProviderProps): react_jsx_runtime0.JSX.Element;
661
+ /**
662
+ * Returns the {@link GraphQLReactorClient} mounted by
663
+ * {@link GraphQLReactorProvider}, or `undefined` when the slot holds something
664
+ * else - the full in-browser reactor client, or nothing yet.
665
+ *
666
+ * `useReactorClient` is typed as the narrow `IReactorBrowserClient` subset both
667
+ * implementations share. This is how a component reaches the light client's own
668
+ * surface, i.e. `subgraph` and `request`.
669
+ *
670
+ * The narrowing is by brand, not by `instanceof`: a page can carry two copies
671
+ * of this module - a bundled package with its own copy, or a hot-replaced one -
672
+ * and `instanceof` would then answer `false` for a perfectly good client and
673
+ * leave the component silently without one.
674
+ */
675
+ declare function useSwitchboardClient(): GraphQLReactorClient | undefined;
676
+ //#endregion
677
+ //#region src/graphql-client/operations.d.ts
678
+ /**
679
+ * The operation selection of `GetDocumentOperations`, lifted into a fragment so
680
+ * the write path can reuse `remoteOperationToLocal` on the items it selects.
681
+ */
682
+ declare const ReactorOperationFieldsFragmentDoc: graphql.DocumentNode;
683
+ /**
684
+ * `mutateDocument` plus the operations the mutation produced.
685
+ *
686
+ * The generated `MutateDocument` only selects the document fields, but
687
+ * `dispatchActions` reads per-action failures out of `result.operations[scope]`
688
+ * (`src/actions/dispatch.ts`), so the reducer-level errors would be lost.
689
+ *
690
+ * The operations filter keeps the extra selection to the operations this call
691
+ * could have appended rather than the whole history. All three of its fields
692
+ * matter:
693
+ * - `sinceRevision` is the lowest head revision across the targeted scopes, so
694
+ * it is only a safe window when the selection is scope-limited as well;
695
+ * - `scopes` limits the response to the scopes the pushed actions target,
696
+ * without it the server walks every scope of the document
697
+ * (`packages/reactor/src/core/reactor.ts` `getOperations`);
698
+ * - `branch` selects the branch the operations are read from, and is the same
699
+ * variable the mutation writes to. It used to be two - the write went through
700
+ * a `view`, the filter took its own `branch` - and they had to be kept equal
701
+ * by hand or the operations came from `main` while the actions were applied
702
+ * elsewhere. One variable cannot disagree with itself.
703
+ */
704
+ declare const MutateDocumentWithOperationsDocument: graphql.DocumentNode;
705
+ type MutateDocumentWithOperationsVariables = {
706
+ documentIdentifier: Scalars["String"]["input"];
707
+ actions: ReadonlyArray<ActionInput>;
708
+ sinceRevision?: Scalars["Int"]["input"];
709
+ scopes?: ReadonlyArray<Scalars["String"]["input"]>;
710
+ branch?: Scalars["String"]["input"];
711
+ };
712
+ type MutateDocumentWithOperationsResult = {
713
+ readonly mutateDocument: PhDocumentFieldsFragment & {
714
+ readonly operations?: {
715
+ readonly items: ReadonlyArray<RemoteOperation>;
716
+ } | null;
717
+ };
718
+ };
719
+ //#endregion
720
+ //#region src/graphql-client/signing.d.ts
721
+ /**
722
+ * Stamps an action with the head of the scope it targets.
723
+ *
724
+ * `prevOpHash` is the hash of the scope state the action is meant to apply to;
725
+ * for a document at head that is the hash of the last operation in the scope,
726
+ * which the read path cannot fetch, so it is recomputed from the state.
727
+ * `prevOpIndex` is the index of that last operation: revisions count
728
+ * operations and indices are zero based, so an empty scope stamps `-1`, which
729
+ * matches what the remote controller records.
730
+ *
731
+ * `revision` overrides the scope revision the index is derived from. Only a
732
+ * batch needs it - {@link prepareSignedActions} stamps action N at the revision
733
+ * the N actions before it will have produced, which the document itself does
734
+ * not know yet. `prevOpHash` always comes from the supplied document's state.
735
+ */
736
+ declare function stampAction(action: Action$1, document: PHDocument$1, revision?: number): Action$1;
737
+ /**
738
+ * Signs a stamped action, preserving any signatures it already carries.
739
+ *
740
+ * The signer reads `context.prevOpHash` off the action, so this must run after
741
+ * {@link stampAction}.
742
+ */
743
+ declare function signStampedAction(action: Action$1, signer: ISigner, signal?: AbortSignal): Promise<Action$1>;
744
+ /**
745
+ * Stamps and signs a batch of actions against one document snapshot, so every
746
+ * action carries the head its predecessor will leave behind.
747
+ *
748
+ * The server executes the array in order, each action against the state the one
749
+ * before it produced. The snapshot the light client reads has correct state and
750
+ * per-scope revisions but NO operation history (see `adapter.ts`), so the chain
751
+ * is predicted here: reduce action N over the working document to get the state
752
+ * action N+1 hashes, and carry a virtual revision alongside it. The revision has
753
+ * to be tracked separately because the reducer derives operation indices from
754
+ * the last stored operation, and with an empty history that counts from zero
755
+ * rather than from the document's real revision.
756
+ *
757
+ * A single action needs no prediction and therefore no `module`, which keeps
758
+ * today's callers working unchanged. Two or more require the document's exact
759
+ * reducer, one shared scope (the reactor rejects mixed-scope jobs) and only
760
+ * append-only actions. Anything else rejects: a batch that cannot be predicted
761
+ * must fail before the mutation, never be downgraded to unsigned.
762
+ */
763
+ declare function prepareSignedActions(actions: readonly Action$1[], snapshot: PHDocument$1, signer: ISigner, module?: DocumentModelModule$1<any>, signal?: AbortSignal): Promise<Action$1[]>;
764
+ //#endregion
765
+ //#region src/graphql-client/static-package-manager.d.ts
766
+ /**
767
+ * A fixed set of packages presented through the `IPackageManager` interface,
768
+ * so the package-derived hooks - `useDocumentModelModules`,
769
+ * `useDocumentModelModuleById`, `useEditorModules`, `useVetraPackages` - work
770
+ * below `GraphQLReactorProvider` exactly as they do below Connect.
771
+ *
772
+ * Connect's package manager installs, updates and removes packages at runtime.
773
+ * A light app instead declares its packages once, as code it imports itself
774
+ * (every generated package root exports `manifest`, `documentModels`, `editors`
775
+ * and `upgradeManifests` by name), so every mutating member throws and
776
+ * `subscribe` never emits. For hand-picked modules without package artifacts,
777
+ * {@link packageFromDocumentModels} wraps them in one synthetic package.
778
+ */
779
+ declare class StaticPackageManager implements IPackageManager {
780
+ readonly registryUrl: null;
781
+ readonly packages: DocumentModelLib[];
782
+ constructor(packages: readonly DocumentModelLib<any>[]);
783
+ /**
784
+ * Resolves a module by document type across all packages. Mirrors the
785
+ * registry's semantics (`IDocumentModelRegistry.getModule`): the LATEST
786
+ * version wins, with `version ?? 1` as each module's default.
787
+ */
788
+ load(documentType: string): Promise<DocumentModelSource>;
789
+ subscribe(_handler: IPackagesListener): IPackageListerUnsubscribe;
790
+ getPackageSource(_packageName: string): RegistryPackageSource | null;
791
+ getPackageVersion(_packageName: string): string | undefined;
792
+ getRegistryPackages(): {
793
+ name: string;
794
+ version: string | undefined;
795
+ }[];
796
+ addPackage(_packageName: string): PackageManagerInstallResult;
797
+ addPackages(_packageNames: string[]): PackageManagerInstallResult[];
798
+ removePackage(_name: string): void;
799
+ updateLocalPackage(_pkg: DocumentModelLib, _version?: string): void;
800
+ addLocalPackage(_name: string, _loadedPackage: DocumentModelLib, _version?: string): void;
801
+ }
802
+ /**
803
+ * Resolves one document-model module out of a flat module list, with the same
804
+ * rule the reactor registry uses (`IDocumentModelRegistry.getModule`, at
805
+ * packages/reactor/src/registry/implementation.ts): with a `version`, only an
806
+ * EXACT `version ?? 1` match resolves; without one, the LATEST version wins.
807
+ *
808
+ * Signing an existing document needs the exact rule. A document carries the
809
+ * model version it was written with in `state.document.version`, and its
810
+ * reducer is the only one whose operations that document's history can accept -
811
+ * so "latest" is correct only when no version is asked for.
812
+ *
813
+ * Pure and dependency-free on purpose: this is reachable from the browser
814
+ * entry, so it must not pull the reactor registry in as a value.
815
+ */
816
+ declare function resolveDocumentModelModule(modules: readonly DocumentModelModule<any>[], documentType: string, version?: number): DocumentModelModule<any>;
817
+ /**
818
+ * Wraps hand-picked modules in one synthetic `DocumentModelLib`, for apps that
819
+ * assemble their model list from mixed sources instead of passing whole
820
+ * packages. The manifest is fabricated - loose modules carry none - so prefer
821
+ * the `packages` prop with the real package exports when you have them: a real
822
+ * package also carries `editors`, which makes the editor hooks work.
823
+ */
824
+ declare function packageFromDocumentModels(documentModels: readonly DocumentModelModule<any>[]): DocumentModelLib;
825
+ //#endregion
826
+ //#region src/graphql-client/subscriptions.d.ts
827
+ /** The `documentChanges` payload, exactly as the Switchboard sends it. */
828
+ type DocumentChangesEventPayload = DocumentChangesSubscription["documentChanges"];
829
+ /** The connection payload sent with the `ConnectionInit` message. */
830
+ type ConnectionParams = Record<string, string>;
831
+ type DocumentChangesSubscriptionOptions = {
832
+ /** The websocket endpoint, e.g. `ws://localhost:4001/graphql/subscriptions`. */wsUrl: string;
833
+ /**
834
+ * Resolves the `ConnectionInit` payload. Called again on every reconnect, so
835
+ * a token that expired while the socket was down is refreshed on the way back
836
+ * up.
837
+ */
838
+ connectionParams?: () => Promise<ConnectionParams>; /** Called once per server event. */
839
+ onEvent: (event: DocumentChangesEventPayload) => void;
840
+ /**
841
+ * Called when the socket gives up: the retries built into `graphql-ws` are
842
+ * exhausted, or the server rejected the subscription. Realtime is an
843
+ * enhancement, so callers are expected to log and carry on.
844
+ */
845
+ onError: (error: unknown) => void;
846
+ };
847
+ /**
848
+ * Opens one `documentChanges` subscription and feeds every event to `onEvent`.
849
+ *
850
+ * The subscription is a firehose: no `search` argument, so the server sends
851
+ * every change the connection is allowed to see and the caller filters. This is
852
+ * the only module that knows about `graphql-ws`.
853
+ *
854
+ * Returns the stop function, which cancels the subscription and closes the
855
+ * socket. It is safe to call more than once.
856
+ */
857
+ declare function startDocumentChangesSubscription(options: DocumentChangesSubscriptionOptions): () => void;
858
+ /**
859
+ * Derives the websocket endpoint from the GraphQL http endpoint.
860
+ *
861
+ * `http://host/graphql` becomes `ws://host/graphql/subscriptions`, which is
862
+ * where the Switchboard mounts its websocket server (`packages/reactor-api`
863
+ * `startServer`). A URL that already speaks `ws`/`wss` only gets the path.
864
+ */
865
+ declare function subscriptionsUrlFromGraphqlUrl(url: string): string;
866
+ /**
867
+ * Turns a bearer token provider into `connectionParams`.
868
+ *
869
+ * The header key is the lowercase `authorization` the Switchboard's websocket
870
+ * context factory reads. Without a token the payload is empty: an open
871
+ * Switchboard serves anonymous subscribers.
872
+ */
873
+ declare function makeAuthConnectionParams(tokenProvider: BearerTokenProvider): () => Promise<ConnectionParams>;
874
+ //#endregion
875
+ //#region src/hooks/document-cache.d.ts
876
+ /** Returns all documents in the reactor. */
877
+ declare const useDocumentCache: UsePHGlobalValue$1<IDocumentCache>;
878
+ /** Sets all of the documents in the reactor. */
879
+ declare const setDocumentCache: SetPHGlobalValue$1<IDocumentCache>;
880
+ /** Adds an event handler for all of the documents in the reactor. */
881
+ declare const addDocumentCacheEventHandler: () => void;
882
+ /**
883
+ * Retrieves a document from the reactor and subscribes to changes using React Suspense.
884
+ * This hook will suspend rendering while the document is loading.
885
+ * @param id - The document ID to retrieve, or null/undefined to skip retrieval
886
+ * @returns The document if found, or undefined if id is null/undefined
887
+ */
888
+ declare function useDocument(id: string | null | undefined): PHDocument$1 | undefined;
889
+ /**
890
+ * Retrieves a document from the reactor and subscribes to changes without
891
+ * suspending or throwing. Use this when the ID might be stale (e.g., a
892
+ * previously selected node that has since been deleted) and the consumer
893
+ * wants to render a placeholder instead of crashing.
894
+ *
895
+ * Unlike {@link useGetDocumentAsync}, this hook subscribes to cache
896
+ * updates, so the returned state stays in sync with reactor changes.
897
+ *
898
+ * @param id - The document ID to retrieve, or null/undefined to skip retrieval
899
+ * @returns An object containing:
900
+ * - status: "initial" | "pending" | "success" | "error"
901
+ * - data: The document if successfully loaded
902
+ * - isPending: Whether the document is currently loading
903
+ * - error: Any error that occurred during loading (e.g., document not found)
904
+ * - reload: Function to force a refetch, or undefined when no id is supplied
905
+ */
906
+ declare function useDocumentSafe(id: string | null | undefined): {
907
+ readonly status: "initial";
908
+ readonly isPending: false;
909
+ readonly error: undefined;
910
+ readonly data: undefined;
911
+ readonly reload: undefined;
912
+ } | {
913
+ readonly reload: () => Promise<PHDocument$1>;
914
+ readonly status: "pending";
915
+ readonly isPending: true;
916
+ readonly error: undefined;
917
+ readonly data: undefined;
918
+ } | {
919
+ readonly reload: () => Promise<PHDocument$1>;
920
+ readonly status: "success";
921
+ readonly isPending: false;
922
+ readonly error: undefined;
923
+ readonly data: PHDocument$1;
924
+ } | {
925
+ readonly reload: () => Promise<PHDocument$1>;
926
+ readonly status: "error";
927
+ readonly isPending: false;
928
+ readonly error: unknown;
929
+ readonly data: undefined;
930
+ };
931
+ /**
932
+ * Retrieves multiple documents from the reactor using React Suspense.
933
+ * This hook will suspend rendering while any of the documents are loading.
934
+ *
935
+ * Uses getBatch from the document cache which handles promise caching internally,
936
+ * ensuring stable references for useSyncExternalStore.
937
+ *
938
+ * @param ids - Array of document IDs to retrieve, or null/undefined to skip retrieval
939
+ * @returns An array of documents if found, or empty array if ids is null/undefined
940
+ */
941
+ declare function useDocuments(ids: string[] | null | undefined): PHDocument$1[];
942
+ /**
943
+ * Returns a function to retrieve a document from the cache.
944
+ * The returned function fetches and returns a document by ID.
945
+ * @returns A function that takes a document ID and returns a Promise of the document
946
+ */
947
+ declare function useGetDocument(): (id: string) => Promise<PHDocument$1>;
948
+ /**
949
+ * Returns a function to retrieve multiple documents from the cache.
950
+ * The returned function fetches and returns documents by their IDs.
951
+ * @returns A function that takes an array of document IDs and returns a Promise of the documents
952
+ */
953
+ declare function useGetDocuments(): (ids: string[]) => Promise<PHDocument$1[]>;
954
+ /**
955
+ * Retrieves a document from the reactor without suspending rendering.
956
+ * Returns the current state of the document loading operation.
957
+ * @param id - The document ID to retrieve, or null/undefined to skip retrieval
958
+ * @returns An object containing:
959
+ * - status: "initial" | "pending" | "success" | "error"
960
+ * - data: The document if successfully loaded
961
+ * - isPending: Boolean indicating if the document is currently loading
962
+ * - error: Any error that occurred during loading
963
+ * - reload: Function to force reload the document from cache
964
+ */
965
+ declare function useGetDocumentAsync(id: string | null | undefined): {
966
+ readonly status: "initial";
967
+ readonly data: undefined;
968
+ readonly isPending: false;
969
+ readonly error: undefined;
970
+ readonly reload: undefined;
971
+ } | {
972
+ readonly reload: () => Promise<PHDocument$1>;
973
+ readonly status: "pending";
974
+ readonly isPending: true;
975
+ readonly error: undefined;
976
+ readonly data: undefined;
977
+ } | {
978
+ readonly reload: () => Promise<PHDocument$1>;
979
+ readonly status: "success";
980
+ readonly isPending: false;
981
+ readonly error: undefined;
982
+ readonly data: PHDocument$1;
983
+ } | {
984
+ readonly reload: () => Promise<PHDocument$1>;
985
+ readonly status: "error";
986
+ readonly isPending: false;
987
+ readonly error: unknown;
988
+ readonly data: undefined;
989
+ };
990
+ //#endregion
991
+ //#region src/hooks/reactor.d.ts
992
+ /** Returns the reactor client module (in-process or worker-backed) */
993
+ declare const useReactorClientModule: UsePHGlobalValue<BrowserReactorClientModule | WorkerReactorClientModule>;
994
+ /** Sets the reactor client module */
995
+ declare const setReactorClientModule: SetPHGlobalValue<BrowserReactorClientModule | WorkerReactorClientModule>;
996
+ /** Adds an event handler for the reactor client module */
997
+ declare const addReactorClientModuleEventHandler: AddPHGlobalEventHandler;
998
+ /** Returns the reactor client */
999
+ declare const useReactorClient: UsePHGlobalValue<IReactorBrowserClient>;
1000
+ /** Sets the reactor client */
1001
+ declare const setReactorClient: SetPHGlobalValue<IReactorBrowserClient>;
1002
+ /** Adds an event handler for the reactor client */
1003
+ declare const addReactorClientEventHandler: AddPHGlobalEventHandler;
1004
+ declare const useSync: () => ISyncManager | undefined;
1005
+ declare const useSyncList: () => _powerhousedao_reactor0.Remote[];
1006
+ declare const useModelRegistry: () => IDocumentModelRegistry | undefined;
1007
+ declare const useDatabase: () => Kysely<Database> | undefined;
1008
+ declare const usePGlite: () => PGlite | undefined;
1009
+ //#endregion
1010
+ //#region src/hooks/dispatch.d.ts
1011
+ /**
1012
+ * Returns a dispatch function for dispatching actions to a document.
1013
+ * Used internally by other hooks to provide action dispatching capabilities.
1014
+ * @param document - The document to dispatch actions to.
1015
+ * @returns A tuple containing the document and a dispatch function.
1016
+ */
1017
+ type DispatchFn<TAction> = (actionOrActions: TAction[] | TAction | undefined, onErrors?: (errors: Error[]) => void, onSuccess?: (result: PHDocument$1) => void) => void;
1018
+ type UseDispatchResult<TDocument, TAction> = readonly [TDocument | undefined, DispatchFn<TAction>];
1019
+ declare function useDispatch<TDocument = PHDocument$1, TAction = Action$1>(document: TDocument | undefined): UseDispatchResult<TDocument, TAction>;
1020
+ //#endregion
1021
+ //#region src/hooks/document-model-modules.d.ts
1022
+ declare function useDocumentModelModules(): DocumentModelModule[] | undefined;
1023
+ /**
1024
+ * Resolves a document model module by document type, mirroring the registry's
1025
+ * semantics (`IDocumentModelRegistry.getModule`): with `version` omitted the
1026
+ * LATEST version of the type wins (`version ?? 1` as each module's default),
1027
+ * with `version` given only an exact match is returned. The reactor resolves
1028
+ * modules the same way when a document is created, so metadata read through
1029
+ * this hook and the version a creation actually uses cannot disagree.
1030
+ */
1031
+ declare function useDocumentModelModuleById(id: string | null | undefined, version?: number): DocumentModelModule | undefined;
1032
+ //#endregion
1033
+ //#region src/hooks/document-operations.d.ts
1034
+ type InternalState = {
1035
+ globalOperations: Operation$1[];
1036
+ localOperations: Operation$1[];
1037
+ isLoading: boolean;
1038
+ error: Error | undefined;
1039
+ };
1040
+ /** What `useDocumentOperations` returns; exported so consumers can name it. */
1041
+ type DocumentOperationsState = InternalState & {
1042
+ refetch: () => void;
1043
+ };
1044
+ /**
1045
+ * Hook to fetch document operations via the reactor client.
1046
+ * Operations are no longer auto-populated on documents and must be fetched explicitly.
1047
+ *
1048
+ * @param documentId - The document ID to fetch operations for
1049
+ * @returns Object containing globalOperations, localOperations, isLoading, and error
1050
+ */
1051
+ declare function useDocumentOperations(documentId: string | null | undefined): DocumentOperationsState;
1052
+ //#endregion
1053
+ //#region src/hooks/attachment-service.d.ts
1054
+ /** Returns the attachment service from window.ph */
1055
+ declare const useAttachmentService: UsePHGlobalValue<IAttachmentService>;
1056
+ /** Sets the attachment service on window.ph */
1057
+ declare const setAttachmentService: SetPHGlobalValue<IAttachmentService>;
1058
+ /** Registers the attachmentService window event handler */
1059
+ declare const addAttachmentServiceEventHandler: AddPHGlobalEventHandler;
1060
+ //#endregion
1061
+ 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 };
1062
+ //# sourceMappingURL=attachment-service-KFFLBEuD.d.ts.map