@powerhousedao/connect-core 6.2.3-dev.82 → 6.2.3-dev.84
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.
- package/dist/index-ZFFeYX4A.d.ts +365 -0
- package/dist/index-ZFFeYX4A.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{multi-reactor-CVwr_LdS.js → multi-reactor-Dvwv69u1.js} +45 -28
- package/dist/multi-reactor-Dvwv69u1.js.map +1 -0
- package/dist/runtime-LvAkxbdf.js +609 -0
- package/dist/runtime-LvAkxbdf.js.map +1 -0
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +2 -2
- package/package.json +8 -8
- package/src/runtime/app-reactor-client.ts +71 -29
- package/src/runtime/drive-placement.ts +210 -0
- package/src/runtime/drive-placements.ts +361 -0
- package/src/runtime/index.ts +30 -0
- package/src/runtime/multi-reactor.ts +74 -33
- package/dist/index-CCs6HTQV.d.ts +0 -187
- package/dist/index-CCs6HTQV.d.ts.map +0 -1
- package/dist/multi-reactor-CVwr_LdS.js.map +0 -1
- package/dist/runtime-Cb3HQhKo.js +0 -239
- package/dist/runtime-Cb3HQhKo.js.map +0 -1
package/dist/index-CCs6HTQV.d.ts
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import "./runtime-config-D3YPhYyj.js";
|
|
2
|
-
import { BrowserReactorClientModule, PHStore, SwitchboardBackend, WorkerReactorClientModule } from "@powerhousedao/reactor-browser";
|
|
3
|
-
import { PHReactorClientMode } from "@powerhousedao/shared/clis";
|
|
4
|
-
import { DocumentDriveDocument } from "@powerhousedao/shared/document-drive";
|
|
5
|
-
import { DocumentModelModule, ISigner } from "@powerhousedao/shared/document-model";
|
|
6
|
-
import { IReactorClient, ReactorInfo } from "@powerhousedao/reactor";
|
|
7
|
-
import { CollectionRequirementsInput, ReactorReach, RoutableBackendConfig, RouterDiagnostic, RoutingClientOptions, RoutingReactorClient } from "@powerhousedao/reactor-router";
|
|
8
|
-
import { DocumentModelLib } from "document-model";
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/runtime/runtime-flag.d.ts
|
|
11
|
-
type RuntimeFlagInput = {
|
|
12
|
-
configFlag: boolean;
|
|
13
|
-
queryParam?: string | null;
|
|
14
|
-
storedValue?: string | null;
|
|
15
|
-
};
|
|
16
|
-
declare function resolveRuntimeFlag(input: RuntimeFlagInput): boolean;
|
|
17
|
-
type RuntimeFlagKeys = {
|
|
18
|
-
queryKey: string;
|
|
19
|
-
storageKey: string;
|
|
20
|
-
readConfigFlag: () => boolean;
|
|
21
|
-
};
|
|
22
|
-
declare function isRuntimeFlagEnabled(keys: RuntimeFlagKeys): boolean;
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/runtime/multi-reactor-flag.d.ts
|
|
25
|
-
declare function isMultiReactorEnabled(): boolean;
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/runtime/reactor-worker-flag.d.ts
|
|
28
|
-
declare const REACTOR_WORKER_QUERY_KEY = "reactorWorker";
|
|
29
|
-
declare const REACTOR_WORKER_STORAGE_KEY = "ph:reactorWorker";
|
|
30
|
-
type ReactorWorkerFlagInput = RuntimeFlagInput;
|
|
31
|
-
declare function resolveReactorWorkerEnabled(input: ReactorWorkerFlagInput): boolean;
|
|
32
|
-
declare function isReactorWorkerEnabled(): boolean;
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/runtime/reactor-client-mode.d.ts
|
|
35
|
-
/**
|
|
36
|
-
* Which of the four reactor clients Connect boots. Standardized by the
|
|
37
|
-
* multi-reactor work; this resolves the single selector Connect acts on:
|
|
38
|
-
*
|
|
39
|
-
* in-process | worker | remote | router
|
|
40
|
-
*
|
|
41
|
-
* Precedence: an explicit `?reactorClient=` query override (kept in
|
|
42
|
-
* localStorage so it survives a reload), then a stored override, then the
|
|
43
|
-
* served `connect.instance.reactorClient` (projected from the host's reactor
|
|
44
|
-
* backends), then the LEGACY booleans — so a config that only sets
|
|
45
|
-
* reactorWorker/multiReactor behaves exactly as before.
|
|
46
|
-
*
|
|
47
|
-
* `remote` is the only mode that builds NO local reactor (no PGlite): it is a
|
|
48
|
-
* pure client to a remote Switchboard. `router` keeps the local reactor and
|
|
49
|
-
* adds remote backends; `worker`/`in-process` are the local reactor alone.
|
|
50
|
-
*/
|
|
51
|
-
type ReactorClientMode = PHReactorClientMode;
|
|
52
|
-
declare const REACTOR_CLIENT_QUERY_KEY = "reactorClient";
|
|
53
|
-
declare const REACTOR_CLIENT_STORAGE_KEY = "ph:reactorClient";
|
|
54
|
-
declare function resolveReactorClientMode(): ReactorClientMode;
|
|
55
|
-
declare namespace multi_reactor_d_exports {
|
|
56
|
-
export { ConnectRoutingClient, LOCAL_BACKEND_NAME, LoadedDocumentModels, LocalReactorModule, MultiReactorParams, PLACE_ON_LOCAL, PLACE_ON_REMOTE, REMOTE_BACKEND_NAME, buildMultiReactorClient, deriveSwitchboardGraphqlUrl, localFacts, localReach };
|
|
57
|
-
}
|
|
58
|
-
declare const LOCAL_BACKEND_NAME = "connect-local";
|
|
59
|
-
declare const REMOTE_BACKEND_NAME = "switchboard-remote";
|
|
60
|
-
type LocalReactorModule = BrowserReactorClientModule | WorkerReactorClientModule;
|
|
61
|
-
/** Only the tab's reactor is inspectable here, so new collections land on it. */
|
|
62
|
-
declare const PLACE_ON_LOCAL: CollectionRequirementsInput;
|
|
63
|
-
declare function localReach(kind: LocalReactorModule["kind"]): ReactorReach;
|
|
64
|
-
/** Read at every refresh, never kept: a rebuilt reactor reports its own. */
|
|
65
|
-
declare function localFacts(module: LocalReactorModule): () => Promise<ReactorInfo>;
|
|
66
|
-
/** `<origin>[/<prefix>]/d/<slug>` -> `<origin>[/<prefix>]/graphql`. */
|
|
67
|
-
declare function deriveSwitchboardGraphqlUrl(remoteDriveUrl: string): string | undefined;
|
|
68
|
-
/** The loaded document models, or a getter that reads the current ones. */
|
|
69
|
-
type LoadedDocumentModels = readonly DocumentModelModule[] | (() => readonly DocumentModelModule[]);
|
|
70
|
-
type MultiReactorParams = {
|
|
71
|
-
/** The local module, built and ready. Undefined builds a REMOTE-ONLY router
|
|
72
|
-
* (no local backend → no local reactor, no PGlite): the `remote` client. */
|
|
73
|
-
module: LocalReactorModule | undefined;
|
|
74
|
-
remoteGraphqlUrl: string;
|
|
75
|
-
/** Signs routed writes; unsigned (anonymous) without one. */
|
|
76
|
-
signer?: ISigner;
|
|
77
|
-
/** Signing models when the local module exposes no registry; the router asks the local reactor (or, remote-only, the loaded set). */
|
|
78
|
-
documentModelModules: LoadedDocumentModels;
|
|
79
|
-
onDiagnostic?: RouterDiagnostic;
|
|
80
|
-
};
|
|
81
|
-
/** Remote-only placement: the Switchboard serves every collection. (It offers
|
|
82
|
-
* no inspection surface over GraphQL, so PLACE_ON_LOCAL's `inspectable`
|
|
83
|
-
* requirement must NOT apply, or no backend would be eligible.) */
|
|
84
|
-
declare const PLACE_ON_REMOTE: CollectionRequirementsInput;
|
|
85
|
-
/** The router Connect installs, with Connect's handling of credentials and id checks. */
|
|
86
|
-
declare class ConnectRoutingClient extends RoutingReactorClient {
|
|
87
|
-
private readonly remote;
|
|
88
|
-
constructor(backends: readonly RoutableBackendConfig[], options: RoutingClientOptions, remote: SwitchboardBackend, hasLocal: boolean);
|
|
89
|
-
/** Renown's sign-in and sign-out call this on whatever client is installed. */
|
|
90
|
-
notifyCredentialsChanged(): void;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Build the Connect routing client. With a local `module` it is the router
|
|
94
|
-
* over the tab's reactor (primary) and the Switchboard; WITHOUT one it is the
|
|
95
|
-
* `remote` client — a remote-only router whose single backend is the
|
|
96
|
-
* Switchboard, so no local reactor (and no PGlite) is built. Either way the
|
|
97
|
-
* result is a full IReactorClient the app graph consumes unchanged.
|
|
98
|
-
*/
|
|
99
|
-
declare function buildMultiReactorClient(params: MultiReactorParams): Promise<ConnectRoutingClient>;
|
|
100
|
-
//#endregion
|
|
101
|
-
//#region src/runtime/app-reactor-client.d.ts
|
|
102
|
-
type MultiReactorModule = typeof multi_reactor_d_exports;
|
|
103
|
-
type AppReactorClientParams = {
|
|
104
|
-
mode: ReactorClientMode;
|
|
105
|
-
/** Built, and ready (the worker has started up). Undefined in `remote`
|
|
106
|
-
* mode, where no local reactor is built. */
|
|
107
|
-
module: LocalReactorModule | undefined;
|
|
108
|
-
remoteDriveUrl: string | undefined;
|
|
109
|
-
/** Signs routed writes; unsigned (anonymous) without one. */
|
|
110
|
-
signer?: ISigner;
|
|
111
|
-
documentModelModules: LoadedDocumentModels;
|
|
112
|
-
loadRouter?: () => Promise<MultiReactorModule>;
|
|
113
|
-
};
|
|
114
|
-
/** What a mode builds in the tab; `remote` builds no local reactor (no PGlite). */
|
|
115
|
-
type ReactorClientPlan = {
|
|
116
|
-
mode: ReactorClientMode;
|
|
117
|
-
/** `router`: the local reactor plus remote backends. */
|
|
118
|
-
multiReactor: boolean;
|
|
119
|
-
needsLocalReactor: boolean;
|
|
120
|
-
/** The local reactor runs in the shared worker. */
|
|
121
|
-
localAsWorker: boolean;
|
|
122
|
-
};
|
|
123
|
-
declare function planReactorClient(mode?: ReactorClientMode): ReactorClientPlan;
|
|
124
|
-
/** Builds the tab's reactor, e.g. Connect's PGlite or worker reactor. */
|
|
125
|
-
type LocalReactorFactory = (plan: ReactorClientPlan) => Promise<LocalReactorModule>;
|
|
126
|
-
type CreateAppReactorClientOptions = Omit<AppReactorClientParams, "mode" | "module"> & {
|
|
127
|
-
plan?: ReactorClientPlan;
|
|
128
|
-
/** Called only when the plan needs a local reactor. */
|
|
129
|
-
localReactor?: LocalReactorFactory;
|
|
130
|
-
};
|
|
131
|
-
/** Builds the local reactor the plan needs, then selects the app's client. */
|
|
132
|
-
declare function createAppReactorClient(options: CreateAppReactorClientOptions): Promise<{
|
|
133
|
-
plan: ReactorClientPlan;
|
|
134
|
-
module: LocalReactorModule | undefined;
|
|
135
|
-
client: IReactorClient;
|
|
136
|
-
}>;
|
|
137
|
-
/**
|
|
138
|
-
* Pick the client for the resolved mode:
|
|
139
|
-
* - `in-process` / `worker`: the local client, router module never loaded.
|
|
140
|
-
* - `router`: the local reactor plus remote backends.
|
|
141
|
-
* - `remote`: a remote-only router — a full IReactorClient that proxies to
|
|
142
|
-
* the Switchboard over GraphQL with NO local reactor (no PGlite).
|
|
143
|
-
*/
|
|
144
|
-
declare function selectAppReactorClient(params: AppReactorClientParams): Promise<IReactorClient>;
|
|
145
|
-
/**
|
|
146
|
-
* A Switchboard that cannot answer must not fail boot: list the tab's drives.
|
|
147
|
-
*
|
|
148
|
-
* A Switchboard that REFUSES the caller (401/403) must not fail boot either:
|
|
149
|
-
* the refusal is recorded (`backendAuth`) so the root view shows the sign-in
|
|
150
|
-
* gate, and the drive list is empty until the user is someone the backend
|
|
151
|
-
* accepts. A remote-only client has no local drives to fall back on.
|
|
152
|
-
*/
|
|
153
|
-
declare function getAppDrives(client: IReactorClient, local: IReactorClient): Promise<DocumentDriveDocument[]>;
|
|
154
|
-
/**
|
|
155
|
-
* The boot refresh of the drives store. It lists through `getAppDrives`
|
|
156
|
-
* whichever client is in use, so a Switchboard that refuses the caller is
|
|
157
|
-
* recorded for the sign-in gate here too: the remote-only client is its own
|
|
158
|
-
* `local`, and a bare `refreshReactorDataClient` would let the 401 escape
|
|
159
|
-
* and fail the boot before the gate can render.
|
|
160
|
-
*/
|
|
161
|
-
declare function refreshAppDrives(client: IReactorClient, local: IReactorClient): Promise<void>;
|
|
162
|
-
/**
|
|
163
|
-
* Lists the drives again as the caller the tab now is, through the clients
|
|
164
|
-
* boot left in the store: after a sign-in landing or a sign-out that followed
|
|
165
|
-
* a backend's refusal. Nothing to do before boot has set a client.
|
|
166
|
-
*/
|
|
167
|
-
declare function relistAppDrives(): Promise<void>;
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region src/runtime/ph-store.d.ts
|
|
170
|
-
/** The app's PH store: the active one, else a new one bound to `window.ph`.
|
|
171
|
-
* Values set on `window.ph` before carry over. */
|
|
172
|
-
declare function getConnectPHStore(): PHStore;
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region src/runtime/local-package.d.ts
|
|
175
|
-
/** A module namespace, as `import * as pkg` or Vite HMR hands it over. */
|
|
176
|
-
type ModuleNamespace = Record<string, any> & {
|
|
177
|
-
[Symbol.toStringTag]: "Module";
|
|
178
|
-
};
|
|
179
|
-
type LocalPackage = DocumentModelLib<any> | ModuleNamespace;
|
|
180
|
-
/** The package itself, or a loader (`() => import("./index.js")`) that keeps it off the boot path. */
|
|
181
|
-
type LocalPackageSource = LocalPackage | (() => Promise<LocalPackage>);
|
|
182
|
-
/** Starts loading the project's package; a loader runs once, here. */
|
|
183
|
-
declare function loadLocalPackage(source: LocalPackageSource | undefined): DocumentModelLib | Promise<DocumentModelLib> | undefined;
|
|
184
|
-
//#endregion
|
|
185
|
-
export { isRuntimeFlagEnabled as A, REACTOR_WORKER_STORAGE_KEY as C, isMultiReactorEnabled as D, resolveReactorWorkerEnabled as E, RuntimeFlagInput as O, REACTOR_WORKER_QUERY_KEY as S, isReactorWorkerEnabled as T, LocalReactorModule as _, getConnectPHStore as a, ReactorClientMode as b, LocalReactorFactory as c, getAppDrives as d, planReactorClient as f, LoadedDocumentModels as g, selectAppReactorClient as h, loadLocalPackage as i, resolveRuntimeFlag as j, RuntimeFlagKeys as k, ReactorClientPlan as l, relistAppDrives as m, LocalPackageSource as n, AppReactorClientParams as o, refreshAppDrives as p, ModuleNamespace as r, CreateAppReactorClientOptions as s, LocalPackage as t, createAppReactorClient as u, REACTOR_CLIENT_QUERY_KEY as v, ReactorWorkerFlagInput as w, resolveReactorClientMode as x, REACTOR_CLIENT_STORAGE_KEY as y };
|
|
186
|
-
export {};
|
|
187
|
-
//# sourceMappingURL=index-CCs6HTQV.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-CCs6HTQV.d.ts","names":[],"sources":["../src/runtime/runtime-flag.ts","../src/runtime/multi-reactor-flag.ts","../src/runtime/reactor-worker-flag.ts","../src/runtime/reactor-client-mode.ts","../src/runtime/multi-reactor.ts","../src/runtime/app-reactor-client.ts","../src/runtime/ph-store.ts","../src/runtime/local-package.ts"],"mappings":";;;;;;;;;;KAAY;EACV;EACA;EACA;;iBAIc,mBAAmB,OAAO;KAY9B;EACV;EACA;EACA;;iBAKc,qBAAqB,MAAM;;;iBCxB3B;;;cCIH;cACA;KAED,yBAAyB;iBAErB,4BACd,OAAO;iBAKO;;;;;;;;;;;;;;;;;;;KCGJ,oBAAoB;cASnB;cACA;iBA2BG,4BAA4B;;;;cC9B/B;cACA;KAED,qBACR,6BACA;;cAGS,gBAAgB;iBAIb,WAAW,MAAM,6BAA6B;;iBAO9C,WACd,QAAQ,2BACD,QAAQ;;iBAcD,4BACd;;KAaU,gCACC,wCACO;KAER;;;EAGV,QAAQ;EACR;;EAEA,SAAS;;EAET,sBAAsB;EACtB,eAAe;;;;;cAMJ,iBAAiB;;cAwBjB,6BAA6B;mBACvB;EAEjB,YACE,mBAAmB,yBACnB,SAAS,sBACT,QAAQ,oBACR;;EAYF;;;;;;;;;iBAmBoB,wBACpB,QAAQ,qBACP,QAAQ;;;KCzIN,4BAA4B;KAErB;EACV,MAAM;;;EAGN,QAAQ;EACR;;EAEA,SAAS;EACT,sBAAsB;EACtB,mBAAmB,QAAQ;;;KAOjB;EACV,MAAM;;EAEN;EACA;;EAEA;;iBAGc,kBACd,OAAM,oBACL;;KAaS,uBACV,MAAM,sBACH,QAAQ;KAED,gCAAgC,KAC1C;EAGA,OAAO;;EAEP,eAAe;;;iBAIK,uBACpB,SAAS,gCAA6B;;;;;;;;;;;;iBA4BlB,uBACpB,QAAQ,yBACP,QAAQ;;;;;;;;;iBAoCW,aACpB,QAAQ,gBACR,OAAO,iBACN,QAAQ;;;;;;;;iBA4CW,iBACpB,QAAQ,gBACR,OAAO,iBACN;;;;;;iBASmB,mBAAmB;;;;;iBCpMzB,qBAAqB;;;;KCNzB,kBAAkB;GAC3B,OAAO;;KAGE,eAAe,wBAAwB;;KAGvC,qBAAqB,sBAAsB,QAAQ;;iBAG/C,iBACd,QAAQ,iCACP,mBAAmB,QAAQ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multi-reactor-CVwr_LdS.js","names":[],"sources":["../src/runtime/multi-reactor.ts"],"sourcesContent":["import {\n createReactorInspector,\n type ReactorInfo,\n} from \"@powerhousedao/reactor\";\nimport {\n ambientRenownSigner,\n ambientRenownTokenProvider,\n createSwitchboardBackend,\n type BrowserReactorClientModule,\n type SwitchboardBackend,\n type WorkerReactorClientModule,\n} from \"@powerhousedao/reactor-browser\";\nimport {\n FanInPartialFailureError,\n fromReactorClient,\n RoutingReactorClient,\n type CollectionRequirementsInput,\n type ReactorReach,\n type RoutableBackendConfig,\n type RouterDiagnostic,\n type RoutingClientOptions,\n} from \"@powerhousedao/reactor-router\";\nimport type {\n DocumentModelModule,\n ISigner,\n} from \"@powerhousedao/shared/document-model\";\nimport { logger } from \"document-model\";\n\nexport const LOCAL_BACKEND_NAME = \"connect-local\";\nexport const REMOTE_BACKEND_NAME = \"switchboard-remote\";\n\nexport type LocalReactorModule =\n | BrowserReactorClientModule\n | WorkerReactorClientModule;\n\n/** Only the tab's reactor is inspectable here, so new collections land on it. */\nexport const PLACE_ON_LOCAL: CollectionRequirementsInput = Object.freeze({\n inspectable: true,\n});\n\nexport function localReach(kind: LocalReactorModule[\"kind\"]): ReactorReach {\n return kind === \"worker\"\n ? { hosting: \"worker\", inspection: \"rpc\" }\n : { hosting: \"in-process\", inspection: \"direct\" };\n}\n\n/** Read at every refresh, never kept: a rebuilt reactor reports its own. */\nexport function localFacts(\n module: LocalReactorModule,\n): () => Promise<ReactorInfo> {\n if (module.kind === \"worker\") {\n return () => module.inspector.info();\n }\n return async () => {\n const reactorModule = module.reactorModule;\n if (!reactorModule) {\n throw new Error(\"The in-tab reactor exposes no module to inspect\");\n }\n return createReactorInspector(reactorModule).info();\n };\n}\n\n/** `<origin>[/<prefix>]/d/<slug>` -> `<origin>[/<prefix>]/graphql`. */\nexport function deriveSwitchboardGraphqlUrl(\n remoteDriveUrl: string,\n): string | undefined {\n let parsed: URL;\n try {\n parsed = new URL(remoteDriveUrl);\n } catch {\n return undefined;\n }\n const prefix = /^(.*)\\/d\\/[^/]+\\/?$/.exec(parsed.pathname)?.[1];\n return prefix === undefined ? undefined : `${parsed.origin}${prefix}/graphql`;\n}\n\n/** The loaded document models, or a getter that reads the current ones. */\nexport type LoadedDocumentModels =\n | readonly DocumentModelModule[]\n | (() => readonly DocumentModelModule[]);\n\nexport type MultiReactorParams = {\n /** The local module, built and ready. Undefined builds a REMOTE-ONLY router\n * (no local backend → no local reactor, no PGlite): the `remote` client. */\n module: LocalReactorModule | undefined;\n remoteGraphqlUrl: string;\n /** Signs routed writes; unsigned (anonymous) without one. */\n signer?: ISigner;\n /** Signing models when the local module exposes no registry; the router asks the local reactor (or, remote-only, the loaded set). */\n documentModelModules: LoadedDocumentModels;\n onDiagnostic?: RouterDiagnostic;\n};\n\n/** Remote-only placement: the Switchboard serves every collection. (It offers\n * no inspection surface over GraphQL, so PLACE_ON_LOCAL's `inspectable`\n * requirement must NOT apply, or no backend would be eligible.) */\nexport const PLACE_ON_REMOTE: CollectionRequirementsInput = Object.freeze({});\n\n/**\n * The local answer stands when only the Switchboard could not answer -- but\n * only when there IS a local backend. Remote-only has nothing to fall back to,\n * so its errors surface. Installed as the router's `answerFailedIdCheck`, so\n * the facade and `write.isDocumentIdTaken` both apply it.\n */\nfunction localIdCheckAnswer(\n documentId: string,\n error: unknown,\n): boolean | undefined {\n if (!failedOnlyOnRemote(error)) {\n return undefined;\n }\n logger.warn(\n \"The Switchboard could not say whether @id is taken; using the local reactor's answer: @error\",\n documentId,\n error,\n );\n return false;\n}\n\n/** The router Connect installs, with Connect's handling of credentials and id checks. */\nexport class ConnectRoutingClient extends RoutingReactorClient {\n private readonly remote: SwitchboardBackend;\n\n constructor(\n backends: readonly RoutableBackendConfig[],\n options: RoutingClientOptions,\n remote: SwitchboardBackend,\n hasLocal: boolean,\n ) {\n super(backends, {\n ...options,\n answerFailedIdCheck: hasLocal\n ? localIdCheckAnswer\n : options.answerFailedIdCheck,\n });\n this.remote = remote;\n }\n\n /** Renown's sign-in and sign-out call this on whatever client is installed. */\n notifyCredentialsChanged(): void {\n this.remote.notifyCredentialsChanged();\n }\n}\n\nfunction failedOnlyOnRemote(error: unknown): boolean {\n return (\n error instanceof FanInPartialFailureError &&\n error.failures.every((failure) => failure.backend === REMOTE_BACKEND_NAME)\n );\n}\n\n/**\n * Build the Connect routing client. With a local `module` it is the router\n * over the tab's reactor (primary) and the Switchboard; WITHOUT one it is the\n * `remote` client — a remote-only router whose single backend is the\n * Switchboard, so no local reactor (and no PGlite) is built. Either way the\n * result is a full IReactorClient the app graph consumes unchanged.\n */\nexport async function buildMultiReactorClient(\n params: MultiReactorParams,\n): Promise<ConnectRoutingClient> {\n const module = params.module;\n const registry = module?.reactorModule?.documentModelRegistry;\n const loaded = params.documentModelModules;\n const loadedModules = typeof loaded === \"function\" ? loaded : () => loaded;\n // The logged-in Renown user's token and signer, read per request as before.\n const remote = createSwitchboardBackend({\n name: REMOTE_BACKEND_NAME,\n url: params.remoteGraphqlUrl,\n tokenProvider: ambientRenownTokenProvider,\n signer: ambientRenownSigner,\n documentModels: () => registry?.getAllModules() ?? loadedModules(),\n inspection: \"none\",\n });\n const remoteBackend = remote.config;\n const backends: RoutableBackendConfig[] = module\n ? [\n {\n name: LOCAL_BACKEND_NAME,\n backend: fromReactorClient(module.client),\n facts: localFacts(module),\n reach: localReach(module.kind),\n refusesMisroutes: false,\n },\n remoteBackend,\n ]\n : [remoteBackend];\n const router = new ConnectRoutingClient(\n backends,\n {\n // Remote-only: the Switchboard is primary and serves every collection;\n // with a local reactor, new collections land on it (inspectable).\n primaryBackend: module ? LOCAL_BACKEND_NAME : REMOTE_BACKEND_NAME,\n defaultRequirements: module ? PLACE_ON_LOCAL : PLACE_ON_REMOTE,\n signer: params.signer,\n onDiagnostic: params.onDiagnostic,\n // The Switchboard serves no models over GraphQL; remote-only uses the loaded set.\n documentModelModules: module ? undefined : loadedModules,\n },\n remote,\n Boolean(module),\n );\n await router.refreshFacts();\n return router;\n}\n"],"mappings":";;;;;AA4BA,MAAa,qBAAqB;AAClC,MAAa,sBAAsB;;AAOnC,MAAa,iBAA8C,OAAO,OAAO,EACvE,aAAa,KACf,CAAC;AAED,SAAgB,WAAW,MAAgD;CACzE,OAAO,SAAS,WACZ;EAAE,SAAS;EAAU,YAAY;CAAM,IACvC;EAAE,SAAS;EAAc,YAAY;CAAS;AACpD;;AAGA,SAAgB,WACd,QAC4B;CAC5B,IAAI,OAAO,SAAS,UAClB,aAAa,OAAO,UAAU,KAAK;CAErC,OAAO,YAAY;EACjB,MAAM,gBAAgB,OAAO;EAC7B,IAAI,CAAC,eACH,MAAM,IAAI,MAAM,iDAAiD;EAEnE,OAAO,uBAAuB,aAAa,CAAC,CAAC,KAAK;CACpD;AACF;;AAGA,SAAgB,4BACd,gBACoB;CACpB,IAAI;CACJ,IAAI;EACF,SAAS,IAAI,IAAI,cAAc;CACjC,QAAQ;EACN;CACF;CACA,MAAM,SAAS,sBAAsB,KAAK,OAAO,QAAQ,CAAC,GAAG;CAC7D,OAAO,WAAW,KAAA,IAAY,KAAA,IAAY,GAAG,OAAO,SAAS,OAAO;AACtE;;;;AAsBA,MAAa,kBAA+C,OAAO,OAAO,CAAC,CAAC;;;;;;;AAQ5E,SAAS,mBACP,YACA,OACqB;CACrB,IAAI,CAAC,mBAAmB,KAAK,GAC3B;CAEF,OAAO,KACL,gGACA,YACA,KACF;CACA,OAAO;AACT;;AAGA,IAAa,uBAAb,cAA0C,qBAAqB;CAC7D;CAEA,YACE,UACA,SACA,QACA,UACA;EACA,MAAM,UAAU;GACd,GAAG;GACH,qBAAqB,WACjB,qBACA,QAAQ;EACd,CAAC;EACD,KAAK,SAAS;CAChB;;CAGA,2BAAiC;EAC/B,KAAK,OAAO,yBAAyB;CACvC;AACF;AAEA,SAAS,mBAAmB,OAAyB;CACnD,OACE,iBAAiB,4BACjB,MAAM,SAAS,OAAO,YAAY,QAAQ,YAAA,oBAA+B;AAE7E;;;;;;;;AASA,eAAsB,wBACpB,QAC+B;CAC/B,MAAM,SAAS,OAAO;CACtB,MAAM,WAAW,QAAQ,eAAe;CACxC,MAAM,SAAS,OAAO;CACtB,MAAM,gBAAgB,OAAO,WAAW,aAAa,eAAe;CAEpE,MAAM,SAAS,yBAAyB;EACtC,MAAM;EACN,KAAK,OAAO;EACZ,eAAe;EACf,QAAQ;EACR,sBAAsB,UAAU,cAAc,KAAK,cAAc;EACjE,YAAY;CACd,CAAC;CACD,MAAM,gBAAgB,OAAO;CAa7B,MAAM,SAAS,IAAI,qBAZuB,SACtC,CACE;EACE,MAAM;EACN,SAAS,kBAAkB,OAAO,MAAM;EACxC,OAAO,WAAW,MAAM;EACxB,OAAO,WAAW,OAAO,IAAI;EAC7B,kBAAkB;CACpB,GACA,aACF,IACA,CAAC,aAAa,GAGhB;EAGE,gBAAgB,SAAS,qBAAqB;EAC9C,qBAAqB,SAAS,iBAAiB;EAC/C,QAAQ,OAAO;EACf,cAAc,OAAO;EAErB,sBAAsB,SAAS,KAAA,IAAY;CAC7C,GACA,QACA,QAAQ,MAAM,CAChB;CACA,MAAM,OAAO,aAAa;CAC1B,OAAO;AACT"}
|
package/dist/runtime-Cb3HQhKo.js
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { getRuntimeConfig } from "./runtime-config.js";
|
|
2
|
-
import { n as resolveRuntimeFlag, t as isRuntimeFlagEnabled } from "./runtime-flag-DvxW_SD4.js";
|
|
3
|
-
import { n as setDriveRelister } from "./backend-auth-gate-DNKg_v4Y.js";
|
|
4
|
-
import { bindPHStoreToWindow, createPHStore, getActivePHStore, getDrives, getFullReactorClient, getPHStore, recordBackendAuthError, setBackendAuth, setDrives, setFullReactorClient } from "@powerhousedao/reactor-browser";
|
|
5
|
-
import { logger } from "document-model";
|
|
6
|
-
//#region src/runtime/multi-reactor-flag.ts
|
|
7
|
-
function isMultiReactorEnabled() {
|
|
8
|
-
return getRuntimeConfig().connect.instance?.multiReactor ?? false;
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
//#region src/runtime/reactor-worker-flag.ts
|
|
12
|
-
const REACTOR_WORKER_QUERY_KEY = "reactorWorker";
|
|
13
|
-
const REACTOR_WORKER_STORAGE_KEY = "ph:reactorWorker";
|
|
14
|
-
function resolveReactorWorkerEnabled(input) {
|
|
15
|
-
return resolveRuntimeFlag(input);
|
|
16
|
-
}
|
|
17
|
-
function isReactorWorkerEnabled() {
|
|
18
|
-
return isRuntimeFlagEnabled({
|
|
19
|
-
queryKey: REACTOR_WORKER_QUERY_KEY,
|
|
20
|
-
storageKey: REACTOR_WORKER_STORAGE_KEY,
|
|
21
|
-
readConfigFlag: () => getRuntimeConfig().connect.instance?.reactorWorker ?? false
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/runtime/reactor-client-mode.ts
|
|
26
|
-
const MODES = /* @__PURE__ */ new Set([
|
|
27
|
-
"in-process",
|
|
28
|
-
"worker",
|
|
29
|
-
"remote",
|
|
30
|
-
"router"
|
|
31
|
-
]);
|
|
32
|
-
const REACTOR_CLIENT_QUERY_KEY = "reactorClient";
|
|
33
|
-
const REACTOR_CLIENT_STORAGE_KEY = "ph:reactorClient";
|
|
34
|
-
const asMode = (value) => value && MODES.has(value) ? value : void 0;
|
|
35
|
-
function fromTab() {
|
|
36
|
-
if (typeof window === "undefined") return void 0;
|
|
37
|
-
let query;
|
|
38
|
-
try {
|
|
39
|
-
query = asMode(new URLSearchParams(window.location.search).get(REACTOR_CLIENT_QUERY_KEY));
|
|
40
|
-
} catch {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
if (query) {
|
|
45
|
-
window.localStorage.setItem(REACTOR_CLIENT_STORAGE_KEY, query);
|
|
46
|
-
return query;
|
|
47
|
-
}
|
|
48
|
-
return asMode(window.localStorage.getItem(REACTOR_CLIENT_STORAGE_KEY));
|
|
49
|
-
} catch {
|
|
50
|
-
return query;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function resolveReactorClientMode() {
|
|
54
|
-
const override = fromTab();
|
|
55
|
-
if (override) return override;
|
|
56
|
-
const configured = getRuntimeConfig().connect.instance?.reactorClient;
|
|
57
|
-
if (configured && MODES.has(configured)) return configured;
|
|
58
|
-
if (isMultiReactorEnabled()) return "router";
|
|
59
|
-
if (isReactorWorkerEnabled()) return "worker";
|
|
60
|
-
return "in-process";
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/runtime/app-reactor-client.ts
|
|
64
|
-
const loadMultiReactor = () => import("./multi-reactor-CVwr_LdS.js");
|
|
65
|
-
function planReactorClient(mode = resolveReactorClientMode()) {
|
|
66
|
-
const needsLocalReactor = mode !== "remote";
|
|
67
|
-
return {
|
|
68
|
-
mode,
|
|
69
|
-
multiReactor: mode === "router",
|
|
70
|
-
needsLocalReactor,
|
|
71
|
-
localAsWorker: needsLocalReactor && (mode === "worker" || mode === "router" && isReactorWorkerEnabled())
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
/** Builds the local reactor the plan needs, then selects the app's client. */
|
|
75
|
-
async function createAppReactorClient(options) {
|
|
76
|
-
const { localReactor, ...params } = options;
|
|
77
|
-
const plan = options.plan ?? planReactorClient();
|
|
78
|
-
let module;
|
|
79
|
-
if (plan.needsLocalReactor) {
|
|
80
|
-
if (!localReactor) throw new Error(`reactorClient mode "${plan.mode}" needs a local reactor; pass localReactor`);
|
|
81
|
-
module = await localReactor(plan);
|
|
82
|
-
}
|
|
83
|
-
const client = await selectAppReactorClient({
|
|
84
|
-
...params,
|
|
85
|
-
mode: plan.mode,
|
|
86
|
-
module
|
|
87
|
-
});
|
|
88
|
-
return {
|
|
89
|
-
plan,
|
|
90
|
-
module,
|
|
91
|
-
client
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Pick the client for the resolved mode:
|
|
96
|
-
* - `in-process` / `worker`: the local client, router module never loaded.
|
|
97
|
-
* - `router`: the local reactor plus remote backends.
|
|
98
|
-
* - `remote`: a remote-only router — a full IReactorClient that proxies to
|
|
99
|
-
* the Switchboard over GraphQL with NO local reactor (no PGlite).
|
|
100
|
-
*/
|
|
101
|
-
async function selectAppReactorClient(params) {
|
|
102
|
-
if (params.mode === "remote") {
|
|
103
|
-
setFullReactorClient(void 0);
|
|
104
|
-
const remote = await buildRemoteOnly(params);
|
|
105
|
-
setFullReactorClient(remote);
|
|
106
|
-
return remote;
|
|
107
|
-
}
|
|
108
|
-
if (params.mode !== "router") {
|
|
109
|
-
if (getPHStore()?.fullReactorClient) setFullReactorClient(void 0);
|
|
110
|
-
return requireModule(params).client;
|
|
111
|
-
}
|
|
112
|
-
setFullReactorClient(void 0);
|
|
113
|
-
const routed = await buildRouter(params);
|
|
114
|
-
setFullReactorClient(routed);
|
|
115
|
-
return routed ?? requireModule(params).client;
|
|
116
|
-
}
|
|
117
|
-
function requireModule(params) {
|
|
118
|
-
if (!params.module) throw new Error(`reactorClient mode "${params.mode}" needs a local reactor, but none was built`);
|
|
119
|
-
return params.module;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* A Switchboard that cannot answer must not fail boot: list the tab's drives.
|
|
123
|
-
*
|
|
124
|
-
* A Switchboard that REFUSES the caller (401/403) must not fail boot either:
|
|
125
|
-
* the refusal is recorded (`backendAuth`) so the root view shows the sign-in
|
|
126
|
-
* gate, and the drive list is empty until the user is someone the backend
|
|
127
|
-
* accepts. A remote-only client has no local drives to fall back on.
|
|
128
|
-
*/
|
|
129
|
-
async function getAppDrives(client, local) {
|
|
130
|
-
if (client === local) try {
|
|
131
|
-
const drives = await getDrives(local);
|
|
132
|
-
setBackendAuth(void 0);
|
|
133
|
-
return drives;
|
|
134
|
-
} catch (error) {
|
|
135
|
-
if (recordBackendAuthError(error, "switchboard")) {
|
|
136
|
-
logger.warn("The Switchboard refused this caller; showing the sign-in gate: @error", error);
|
|
137
|
-
return [];
|
|
138
|
-
}
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
try {
|
|
142
|
-
const drives = await getDrives(client);
|
|
143
|
-
setBackendAuth(void 0);
|
|
144
|
-
return drives;
|
|
145
|
-
} catch (error) {
|
|
146
|
-
if (recordBackendAuthError(error, "switchboard")) logger.warn("A remote backend refused this caller; listing the local reactor's drives: @error", error);
|
|
147
|
-
else logger.warn("Could not list drives through the router; listing the local reactor's: @error", error);
|
|
148
|
-
return getDrives(local);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* The boot refresh of the drives store. It lists through `getAppDrives`
|
|
153
|
-
* whichever client is in use, so a Switchboard that refuses the caller is
|
|
154
|
-
* recorded for the sign-in gate here too: the remote-only client is its own
|
|
155
|
-
* `local`, and a bare `refreshReactorDataClient` would let the 401 escape
|
|
156
|
-
* and fail the boot before the gate can render.
|
|
157
|
-
*/
|
|
158
|
-
async function refreshAppDrives(client, local) {
|
|
159
|
-
setDrives(await getAppDrives(client, local));
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Lists the drives again as the caller the tab now is, through the clients
|
|
163
|
-
* boot left in the store: after a sign-in landing or a sign-out that followed
|
|
164
|
-
* a backend's refusal. Nothing to do before boot has set a client.
|
|
165
|
-
*/
|
|
166
|
-
async function relistAppDrives() {
|
|
167
|
-
const client = getFullReactorClient();
|
|
168
|
-
if (!client) return;
|
|
169
|
-
await refreshAppDrives(client, getPHStore()?.reactorClientModule?.client ?? client);
|
|
170
|
-
}
|
|
171
|
-
setDriveRelister(relistAppDrives);
|
|
172
|
-
async function buildRouter(params) {
|
|
173
|
-
if (!params.remoteDriveUrl) {
|
|
174
|
-
logger.warn("multiReactor is on but no remote drive URL is configured; using the local reactor only");
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
let multiReactor;
|
|
178
|
-
try {
|
|
179
|
-
multiReactor = await (params.loadRouter ?? loadMultiReactor)();
|
|
180
|
-
} catch (error) {
|
|
181
|
-
logger.error("Could not load the multi-reactor router: @error", error);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
const remoteGraphqlUrl = multiReactor.deriveSwitchboardGraphqlUrl(params.remoteDriveUrl);
|
|
185
|
-
if (!remoteGraphqlUrl) {
|
|
186
|
-
logger.warn("multiReactor is on but the remote drive URL @url does not parse; using the local reactor only", params.remoteDriveUrl);
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
logger.info("Multi-reactor routing to @url", remoteGraphqlUrl);
|
|
190
|
-
return multiReactor.buildMultiReactorClient({
|
|
191
|
-
module: requireModule(params),
|
|
192
|
-
remoteGraphqlUrl,
|
|
193
|
-
signer: params.signer,
|
|
194
|
-
documentModelModules: params.documentModelModules
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* The `remote` mode: a remote-only router — a full IReactorClient that proxies
|
|
199
|
-
* to the Switchboard over GraphQL with NO local backend, so no local reactor
|
|
200
|
-
* and no PGlite are ever built. A missing/unparseable remote URL is a hard
|
|
201
|
-
* config error here (unlike `router`, there is no local reactor to fall back
|
|
202
|
-
* to).
|
|
203
|
-
*/
|
|
204
|
-
async function buildRemoteOnly(params) {
|
|
205
|
-
if (!params.remoteDriveUrl) throw new Error("reactorClient \"remote\" needs a remote drive URL — declare a remote backend / default drive the client can proxy to");
|
|
206
|
-
const multiReactor = await (params.loadRouter ?? loadMultiReactor)();
|
|
207
|
-
const remoteGraphqlUrl = multiReactor.deriveSwitchboardGraphqlUrl(params.remoteDriveUrl);
|
|
208
|
-
if (!remoteGraphqlUrl) throw new Error(`reactorClient "remote": the remote drive URL "${params.remoteDriveUrl}" does not resolve to a Switchboard GraphQL endpoint`);
|
|
209
|
-
logger.info("Remote reactor client → @url", remoteGraphqlUrl);
|
|
210
|
-
return multiReactor.buildMultiReactorClient({
|
|
211
|
-
module: void 0,
|
|
212
|
-
remoteGraphqlUrl,
|
|
213
|
-
signer: params.signer,
|
|
214
|
-
documentModelModules: params.documentModelModules
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
//#endregion
|
|
218
|
-
//#region src/runtime/ph-store.ts
|
|
219
|
-
/** The app's PH store: the active one, else a new one bound to `window.ph`.
|
|
220
|
-
* Values set on `window.ph` before carry over. */
|
|
221
|
-
function getConnectPHStore() {
|
|
222
|
-
const active = getActivePHStore();
|
|
223
|
-
if (active) return active;
|
|
224
|
-
const store = createPHStore();
|
|
225
|
-
bindPHStoreToWindow(store);
|
|
226
|
-
return store;
|
|
227
|
-
}
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region src/runtime/local-package.ts
|
|
230
|
-
/** Starts loading the project's package; a loader runs once, here. */
|
|
231
|
-
function loadLocalPackage(source) {
|
|
232
|
-
const pkg = typeof source === "function" ? source() : source;
|
|
233
|
-
if (pkg instanceof Promise) pkg.catch(() => void 0);
|
|
234
|
-
return pkg;
|
|
235
|
-
}
|
|
236
|
-
//#endregion
|
|
237
|
-
export { planReactorClient as a, selectAppReactorClient as c, resolveReactorClientMode as d, REACTOR_WORKER_QUERY_KEY as f, isMultiReactorEnabled as g, resolveReactorWorkerEnabled as h, getAppDrives as i, REACTOR_CLIENT_QUERY_KEY as l, isReactorWorkerEnabled as m, getConnectPHStore as n, refreshAppDrives as o, REACTOR_WORKER_STORAGE_KEY as p, createAppReactorClient as r, relistAppDrives as s, loadLocalPackage as t, REACTOR_CLIENT_STORAGE_KEY as u };
|
|
238
|
-
|
|
239
|
-
//# sourceMappingURL=runtime-Cb3HQhKo.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-Cb3HQhKo.js","names":[],"sources":["../src/runtime/multi-reactor-flag.ts","../src/runtime/reactor-worker-flag.ts","../src/runtime/reactor-client-mode.ts","../src/runtime/app-reactor-client.ts","../src/runtime/ph-store.ts","../src/runtime/local-package.ts"],"sourcesContent":["import { getRuntimeConfig } from \"./runtime-config.js\";\n\n// Config only: the flag is in the worker fingerprint, so a per-tab value would split tabs.\nexport function isMultiReactorEnabled(): boolean {\n return getRuntimeConfig().connect.instance?.multiReactor ?? false;\n}\n","import { getRuntimeConfig } from \"./runtime-config.js\";\nimport {\n isRuntimeFlagEnabled,\n resolveRuntimeFlag,\n type RuntimeFlagInput,\n} from \"./runtime-flag.js\";\n\nexport const REACTOR_WORKER_QUERY_KEY = \"reactorWorker\";\nexport const REACTOR_WORKER_STORAGE_KEY = \"ph:reactorWorker\";\n\nexport type ReactorWorkerFlagInput = RuntimeFlagInput;\n\nexport function resolveReactorWorkerEnabled(\n input: ReactorWorkerFlagInput,\n): boolean {\n return resolveRuntimeFlag(input);\n}\n\nexport function isReactorWorkerEnabled(): boolean {\n return isRuntimeFlagEnabled({\n queryKey: REACTOR_WORKER_QUERY_KEY,\n storageKey: REACTOR_WORKER_STORAGE_KEY,\n readConfigFlag: () =>\n getRuntimeConfig().connect.instance?.reactorWorker ?? false,\n });\n}\n","import type { PHReactorClientMode } from \"@powerhousedao/shared/clis\";\nimport { getRuntimeConfig } from \"./runtime-config.js\";\nimport { isMultiReactorEnabled } from \"./multi-reactor-flag.js\";\nimport { isReactorWorkerEnabled } from \"./reactor-worker-flag.js\";\n\n/**\n * Which of the four reactor clients Connect boots. Standardized by the\n * multi-reactor work; this resolves the single selector Connect acts on:\n *\n * in-process | worker | remote | router\n *\n * Precedence: an explicit `?reactorClient=` query override (kept in\n * localStorage so it survives a reload), then a stored override, then the\n * served `connect.instance.reactorClient` (projected from the host's reactor\n * backends), then the LEGACY booleans — so a config that only sets\n * reactorWorker/multiReactor behaves exactly as before.\n *\n * `remote` is the only mode that builds NO local reactor (no PGlite): it is a\n * pure client to a remote Switchboard. `router` keeps the local reactor and\n * adds remote backends; `worker`/`in-process` are the local reactor alone.\n */\nexport type ReactorClientMode = PHReactorClientMode;\n\nconst MODES: ReadonlySet<string> = new Set([\n \"in-process\",\n \"worker\",\n \"remote\",\n \"router\",\n]);\n\nexport const REACTOR_CLIENT_QUERY_KEY = \"reactorClient\";\nexport const REACTOR_CLIENT_STORAGE_KEY = \"ph:reactorClient\";\n\nconst asMode = (value: string | null | undefined) =>\n value && MODES.has(value) ? (value as ReactorClientMode) : undefined;\n\nfunction fromTab(): ReactorClientMode | undefined {\n if (typeof window === \"undefined\") return undefined;\n let query: ReactorClientMode | undefined;\n try {\n query = asMode(\n new URLSearchParams(window.location.search).get(REACTOR_CLIENT_QUERY_KEY),\n );\n } catch {\n return undefined;\n }\n try {\n if (query) {\n window.localStorage.setItem(REACTOR_CLIENT_STORAGE_KEY, query);\n return query;\n }\n return asMode(window.localStorage.getItem(REACTOR_CLIENT_STORAGE_KEY));\n } catch {\n // Blocked storage: the query still applies for this page load.\n return query;\n }\n}\n\nexport function resolveReactorClientMode(): ReactorClientMode {\n const override = fromTab();\n if (override) return override;\n const configured = getRuntimeConfig().connect.instance?.reactorClient;\n if (configured && MODES.has(configured)) return configured;\n // Legacy fallback — unchanged behaviour for configs without reactorClient.\n if (isMultiReactorEnabled()) return \"router\";\n if (isReactorWorkerEnabled()) return \"worker\";\n return \"in-process\";\n}\n","import type { IReactorClient } from \"@powerhousedao/reactor\";\nimport {\n getDrives,\n getFullReactorClient,\n getPHStore,\n recordBackendAuthError,\n setBackendAuth,\n setDrives,\n setFullReactorClient,\n} from \"@powerhousedao/reactor-browser\";\nimport type { DocumentDriveDocument } from \"@powerhousedao/shared/document-drive\";\nimport type { ISigner } from \"@powerhousedao/shared/document-model\";\nimport { logger } from \"document-model\";\nimport type * as MultiReactor from \"./multi-reactor.js\";\nimport type {\n LoadedDocumentModels,\n LocalReactorModule,\n} from \"./multi-reactor.js\";\nimport type { ReactorClientMode } from \"./reactor-client-mode.js\";\nimport { resolveReactorClientMode } from \"./reactor-client-mode.js\";\nimport { isReactorWorkerEnabled } from \"./reactor-worker-flag.js\";\nimport { setDriveRelister } from \"./drive-relist.js\";\n\ntype MultiReactorModule = typeof MultiReactor;\n\nexport type AppReactorClientParams = {\n mode: ReactorClientMode;\n /** Built, and ready (the worker has started up). Undefined in `remote`\n * mode, where no local reactor is built. */\n module: LocalReactorModule | undefined;\n remoteDriveUrl: string | undefined;\n /** Signs routed writes; unsigned (anonymous) without one. */\n signer?: ISigner;\n documentModelModules: LoadedDocumentModels;\n loadRouter?: () => Promise<MultiReactorModule>;\n};\n\nconst loadMultiReactor = (): Promise<MultiReactorModule> =>\n import(\"./multi-reactor.js\");\n\n/** What a mode builds in the tab; `remote` builds no local reactor (no PGlite). */\nexport type ReactorClientPlan = {\n mode: ReactorClientMode;\n /** `router`: the local reactor plus remote backends. */\n multiReactor: boolean;\n needsLocalReactor: boolean;\n /** The local reactor runs in the shared worker. */\n localAsWorker: boolean;\n};\n\nexport function planReactorClient(\n mode: ReactorClientMode = resolveReactorClientMode(),\n): ReactorClientPlan {\n const needsLocalReactor = mode !== \"remote\";\n return {\n mode,\n multiReactor: mode === \"router\",\n needsLocalReactor,\n localAsWorker:\n needsLocalReactor &&\n (mode === \"worker\" || (mode === \"router\" && isReactorWorkerEnabled())),\n };\n}\n\n/** Builds the tab's reactor, e.g. Connect's PGlite or worker reactor. */\nexport type LocalReactorFactory = (\n plan: ReactorClientPlan,\n) => Promise<LocalReactorModule>;\n\nexport type CreateAppReactorClientOptions = Omit<\n AppReactorClientParams,\n \"mode\" | \"module\"\n> & {\n plan?: ReactorClientPlan;\n /** Called only when the plan needs a local reactor. */\n localReactor?: LocalReactorFactory;\n};\n\n/** Builds the local reactor the plan needs, then selects the app's client. */\nexport async function createAppReactorClient(\n options: CreateAppReactorClientOptions,\n) {\n const { localReactor, ...params } = options;\n const plan = options.plan ?? planReactorClient();\n let module: LocalReactorModule | undefined;\n if (plan.needsLocalReactor) {\n if (!localReactor) {\n throw new Error(\n `reactorClient mode \"${plan.mode}\" needs a local reactor; pass localReactor`,\n );\n }\n module = await localReactor(plan);\n }\n const client = await selectAppReactorClient({\n ...params,\n mode: plan.mode,\n module,\n });\n return { plan, module, client };\n}\n\n/**\n * Pick the client for the resolved mode:\n * - `in-process` / `worker`: the local client, router module never loaded.\n * - `router`: the local reactor plus remote backends.\n * - `remote`: a remote-only router — a full IReactorClient that proxies to\n * the Switchboard over GraphQL with NO local reactor (no PGlite).\n */\nexport async function selectAppReactorClient(\n params: AppReactorClientParams,\n): Promise<IReactorClient> {\n if (params.mode === \"remote\") {\n setFullReactorClient(undefined);\n const remote = await buildRemoteOnly(params);\n setFullReactorClient(remote);\n return remote;\n }\n if (params.mode !== \"router\") {\n if (getPHStore()?.fullReactorClient) {\n setFullReactorClient(undefined);\n }\n return requireModule(params).client;\n }\n setFullReactorClient(undefined);\n const routed = await buildRouter(params);\n setFullReactorClient(routed);\n return routed ?? requireModule(params).client;\n}\n\nfunction requireModule(params: AppReactorClientParams): LocalReactorModule {\n if (!params.module) {\n throw new Error(\n `reactorClient mode \"${params.mode}\" needs a local reactor, but none was built`,\n );\n }\n return params.module;\n}\n\n/**\n * A Switchboard that cannot answer must not fail boot: list the tab's drives.\n *\n * A Switchboard that REFUSES the caller (401/403) must not fail boot either:\n * the refusal is recorded (`backendAuth`) so the root view shows the sign-in\n * gate, and the drive list is empty until the user is someone the backend\n * accepts. A remote-only client has no local drives to fall back on.\n */\nexport async function getAppDrives(\n client: IReactorClient,\n local: IReactorClient,\n): Promise<DocumentDriveDocument[]> {\n if (client === local) {\n try {\n const drives = await getDrives(local);\n setBackendAuth(undefined);\n return drives;\n } catch (error) {\n if (recordBackendAuthError(error, \"switchboard\")) {\n logger.warn(\n \"The Switchboard refused this caller; showing the sign-in gate: @error\",\n error,\n );\n return [];\n }\n throw error;\n }\n }\n try {\n const drives = await getDrives(client);\n setBackendAuth(undefined);\n return drives;\n } catch (error) {\n if (recordBackendAuthError(error, \"switchboard\")) {\n logger.warn(\n \"A remote backend refused this caller; listing the local reactor's drives: @error\",\n error,\n );\n } else {\n logger.warn(\n \"Could not list drives through the router; listing the local reactor's: @error\",\n error,\n );\n }\n return getDrives(local);\n }\n}\n\n/**\n * The boot refresh of the drives store. It lists through `getAppDrives`\n * whichever client is in use, so a Switchboard that refuses the caller is\n * recorded for the sign-in gate here too: the remote-only client is its own\n * `local`, and a bare `refreshReactorDataClient` would let the 401 escape\n * and fail the boot before the gate can render.\n */\nexport async function refreshAppDrives(\n client: IReactorClient,\n local: IReactorClient,\n): Promise<void> {\n setDrives(await getAppDrives(client, local));\n}\n\n/**\n * Lists the drives again as the caller the tab now is, through the clients\n * boot left in the store: after a sign-in landing or a sign-out that followed\n * a backend's refusal. Nothing to do before boot has set a client.\n */\nexport async function relistAppDrives(): Promise<void> {\n const client = getFullReactorClient();\n if (!client) return;\n const local = getPHStore()?.reactorClientModule?.client ?? client;\n await refreshAppDrives(client, local);\n}\n\n// The backend auth gate relists through drive-relist (see there)\nsetDriveRelister(relistAppDrives);\n\nasync function buildRouter(\n params: AppReactorClientParams,\n): Promise<IReactorClient | undefined> {\n if (!params.remoteDriveUrl) {\n logger.warn(\n \"multiReactor is on but no remote drive URL is configured; using the local reactor only\",\n );\n return undefined;\n }\n let multiReactor: MultiReactorModule;\n try {\n multiReactor = await (params.loadRouter ?? loadMultiReactor)();\n } catch (error) {\n logger.error(\"Could not load the multi-reactor router: @error\", error);\n return undefined;\n }\n const remoteGraphqlUrl = multiReactor.deriveSwitchboardGraphqlUrl(\n params.remoteDriveUrl,\n );\n if (!remoteGraphqlUrl) {\n logger.warn(\n \"multiReactor is on but the remote drive URL @url does not parse; using the local reactor only\",\n params.remoteDriveUrl,\n );\n return undefined;\n }\n logger.info(\"Multi-reactor routing to @url\", remoteGraphqlUrl);\n return multiReactor.buildMultiReactorClient({\n module: requireModule(params),\n remoteGraphqlUrl,\n signer: params.signer,\n documentModelModules: params.documentModelModules,\n });\n}\n\n/**\n * The `remote` mode: a remote-only router — a full IReactorClient that proxies\n * to the Switchboard over GraphQL with NO local backend, so no local reactor\n * and no PGlite are ever built. A missing/unparseable remote URL is a hard\n * config error here (unlike `router`, there is no local reactor to fall back\n * to).\n */\nasync function buildRemoteOnly(\n params: AppReactorClientParams,\n): Promise<IReactorClient> {\n if (!params.remoteDriveUrl) {\n throw new Error(\n 'reactorClient \"remote\" needs a remote drive URL — declare a remote backend / default drive the client can proxy to',\n );\n }\n const multiReactor = await (params.loadRouter ?? loadMultiReactor)();\n const remoteGraphqlUrl = multiReactor.deriveSwitchboardGraphqlUrl(\n params.remoteDriveUrl,\n );\n if (!remoteGraphqlUrl) {\n throw new Error(\n `reactorClient \"remote\": the remote drive URL \"${params.remoteDriveUrl}\" does not resolve to a Switchboard GraphQL endpoint`,\n );\n }\n logger.info(\"Remote reactor client → @url\", remoteGraphqlUrl);\n return multiReactor.buildMultiReactorClient({\n module: undefined,\n remoteGraphqlUrl,\n signer: params.signer,\n documentModelModules: params.documentModelModules,\n });\n}\n","import type { PHStore } from \"@powerhousedao/reactor-browser\";\nimport {\n bindPHStoreToWindow,\n createPHStore,\n getActivePHStore,\n} from \"@powerhousedao/reactor-browser\";\n\n/** The app's PH store: the active one, else a new one bound to `window.ph`.\n * Values set on `window.ph` before carry over. */\nexport function getConnectPHStore(): PHStore {\n const active = getActivePHStore();\n if (active) return active;\n const store = createPHStore();\n bindPHStoreToWindow(store);\n return store;\n}\n","import type { DocumentModelLib } from \"document-model\";\n\n/** A module namespace, as `import * as pkg` or Vite HMR hands it over. */\nexport type ModuleNamespace = Record<string, any> & {\n [Symbol.toStringTag]: \"Module\";\n};\n\nexport type LocalPackage = DocumentModelLib<any> | ModuleNamespace;\n\n/** The package itself, or a loader (`() => import(\"./index.js\")`) that keeps it off the boot path. */\nexport type LocalPackageSource = LocalPackage | (() => Promise<LocalPackage>);\n\n/** Starts loading the project's package; a loader runs once, here. */\nexport function loadLocalPackage(\n source: LocalPackageSource | undefined,\n): DocumentModelLib | Promise<DocumentModelLib> | undefined {\n const pkg = (typeof source === \"function\" ? source() : source) as\n | DocumentModelLib\n | Promise<DocumentModelLib>\n | undefined;\n // Consumers await it; this only stops an early rejection being reported as unhandled.\n if (pkg instanceof Promise) pkg.catch(() => undefined);\n return pkg;\n}\n"],"mappings":"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"}
|