@powerhousedao/reactor-browser 6.2.2-dev.27 → 6.2.2-dev.29

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