@powerhousedao/switchboard 6.2.3-dev.78 → 6.2.3-dev.79
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/.tsbuild/test/boot-auth-config.test.d.ts +2 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-helpers.d.ts +5 -0
- package/.tsbuild/test/boot-helpers.d.ts.map +1 -0
- package/.tsbuild/test/config-from-env.test.d.ts +2 -0
- package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
- package/.tsbuild/test/config-merge.test.d.ts +2 -0
- package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
- package/.tsbuild/test/config-schema.test.d.ts +2 -0
- package/.tsbuild/test/config-schema.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
- package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
- package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +35 -0
- package/README.md +9 -5
- package/dist/boot.d.mts +8 -0
- package/dist/boot.d.mts.map +1 -1
- package/dist/boot.mjs +22 -16
- package/dist/boot.mjs.map +1 -1
- package/dist/config/from-env.d.mts +15 -0
- package/dist/config/from-env.d.mts.map +1 -0
- package/dist/config/from-env.mjs +4 -0
- package/dist/config/schema.d.mts +3 -0
- package/dist/config/schema.mjs +4 -0
- package/dist/from-env-BO0n9R02.mjs +401 -0
- package/dist/from-env-BO0n9R02.mjs.map +1 -0
- package/dist/index.mjs +34 -38
- package/dist/index.mjs.map +1 -1
- package/dist/migrate.mjs +2 -2
- package/dist/{plugin-host-BBqojyyY.d.mts → plugin-host-C1sYEm8g.d.mts} +4 -1
- package/dist/plugin-host-C1sYEm8g.d.mts.map +1 -0
- package/dist/plugins/attachments.d.mts +3 -3
- package/dist/plugins/attachments.mjs +3 -3
- package/dist/plugins/mcp.d.mts +1 -1
- package/dist/plugins/privacy.d.mts +1 -1
- package/dist/plugins/privacy.mjs +3 -3
- package/dist/plugins/workflows.d.mts +1 -1
- package/dist/plugins/workflows.mjs +3 -3
- package/dist/privacy-BO8Q25xI.mjs +44 -0
- package/dist/privacy-BO8Q25xI.mjs.map +1 -0
- package/dist/{privacy-BsFl7GzK.mjs → privacy-DxIJGH4P.mjs} +14 -41
- package/dist/privacy-DxIJGH4P.mjs.map +1 -0
- package/dist/renown-layers-COZsrGQT.mjs +40 -0
- package/dist/renown-layers-COZsrGQT.mjs.map +1 -0
- package/dist/schema-0g_QdOWn.mjs +267 -0
- package/dist/schema-0g_QdOWn.mjs.map +1 -0
- package/dist/schema-ivUWPQOn.d.mts +202 -0
- package/dist/schema-ivUWPQOn.d.mts.map +1 -0
- package/dist/{server-Bdq8xquD.mjs → server-CtGBZlTg.mjs} +230 -382
- package/dist/server-CtGBZlTg.mjs.map +1 -0
- package/dist/server.d.mts +46 -11
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +5 -4
- package/dist/{utils-CTtD7Oti.mjs → utils-BbV_nodR.mjs} +23 -20
- package/dist/utils-BbV_nodR.mjs.map +1 -0
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +3 -3
- package/dist/{reactor-feature-flags-BtWVQDt6.mjs → worker-pool-BWHBLBJd.mjs} +12 -32
- package/dist/worker-pool-BWHBLBJd.mjs.map +1 -0
- package/dist/workflow-runtime-7GaJ13c9.d.mts.map +1 -1
- package/dist/{workflows-fsBcElEi.mjs → workflows-QY9Y2eoD.mjs} +5 -16
- package/dist/workflows-QY9Y2eoD.mjs.map +1 -0
- package/package.json +29 -19
- package/test/attachment-reference-read-model.test.ts +22 -19
- package/test/attachments/download-target.test.ts +29 -19
- package/test/attachments/service-config.test.ts +28 -16
- package/test/boot-auth-config.test.ts +109 -0
- package/test/boot-create-signature-policy.test.ts +15 -13
- package/test/boot-env-isolation.test.ts +2 -2
- package/test/boot-helpers.ts +18 -0
- package/test/boot-inspection-enabled.test.ts +16 -13
- package/test/boot-mcp-enabled.test.ts +15 -13
- package/test/boot-port-zero.test.ts +15 -13
- package/test/boot-preconditions.test.ts +51 -0
- package/test/boot-privacy.test.ts +12 -10
- package/test/boot-unsupported-stored-documents.test.ts +10 -9
- package/test/boot-without-renown.test.ts +11 -9
- package/test/boot-without-require-signatures.test.ts +12 -10
- package/test/boot-worker-trust-policy.test.ts +11 -10
- package/test/boot-workflow-singleton-conflict.test.ts +11 -9
- package/test/boot-workflow-singleton-retry.test.ts +12 -10
- package/test/config-from-env.test.ts +758 -0
- package/test/config-merge.test.ts +215 -0
- package/test/config-schema.test.ts +128 -0
- package/test/default-drive-protocol-versions.test.ts +78 -0
- package/test/pglite-storage-dirs.test.ts +24 -14
- package/test/pglite-store.test.ts +1 -62
- package/test/plugin-presence.test.ts +27 -21
- package/test/renown-storage-path.test.ts +9 -8
- package/test/shutdown.test.ts +22 -21
- package/test/two-switchboards.test.ts +146 -0
- package/test/workflow-runtime.test.ts +12 -69
- package/tsdown.config.ts +2 -0
- package/vitest.config.ts +2 -0
- package/.tsbuild/test/inspection-flag.test.d.ts +0 -2
- package/.tsbuild/test/inspection-flag.test.d.ts.map +0 -1
- package/.tsbuild/test/mcp-flag.test.d.ts +0 -2
- package/.tsbuild/test/mcp-flag.test.d.ts.map +0 -1
- package/dist/plugin-host-BBqojyyY.d.mts.map +0 -1
- package/dist/privacy-BsFl7GzK.mjs.map +0 -1
- package/dist/reactor-feature-flags-BtWVQDt6.mjs.map +0 -1
- package/dist/server-Bdq8xquD.mjs.map +0 -1
- package/dist/utils-CTtD7Oti.mjs.map +0 -1
- package/dist/workflows-fsBcElEi.mjs.map +0 -1
- package/test/inspection-flag.test.ts +0 -62
- package/test/mcp-flag.test.ts +0 -56
package/dist/server.d.mts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { a as SwitchboardConfigInput } from "./schema-ivUWPQOn.mjs";
|
|
1
2
|
import { n as WorkflowTriggersCapability } from "./workflow-runtime-7GaJ13c9.mjs";
|
|
2
3
|
import { ILogger } from "document-model";
|
|
3
4
|
import { ChannelScheme, Database, IDocumentModelLoader, IInspector, IReactorClient, InProcessReactorClientModule, JwtHandler, ModelManifestEntry, PoolInstrumentation, ReactorBuilder, ReactorClientBuilder, ReactorFeatureFlags, ReactorStorageFacts, SignerConfig, UnsupportedStoredDocuments, UnsupportedStoredProtocolError } from "@powerhousedao/reactor";
|
|
4
5
|
import { AttachmentReferenceProjectionCapability } from "@powerhousedao/reactor-api";
|
|
5
|
-
import "@powerhousedao/reactor-api/pglite-node";
|
|
6
|
+
import { PgliteMaintenanceSettings, resolvePgliteMaintenance } from "@powerhousedao/reactor-api/pglite-node";
|
|
7
|
+
import { DocumentModelModule, ISigner, SignaturePolicy, UpgradeManifest } from "@powerhousedao/shared/document-model";
|
|
8
|
+
import { IErasureService } from "@powerhousedao/reactor-privacy";
|
|
6
9
|
import { IAttachmentService } from "@powerhousedao/reactor-attachments";
|
|
7
10
|
import { IRenown } from "@renown/sdk/node";
|
|
8
11
|
import { Kysely } from "kysely";
|
|
9
|
-
import { IErasureService } from "@powerhousedao/reactor-privacy";
|
|
10
12
|
import { ResolvedPlugin } from "@powerhousedao/host-core";
|
|
11
|
-
import { DocumentModelModule, ISigner, SignaturePolicy, UpgradeManifest } from "@powerhousedao/shared/document-model";
|
|
12
13
|
import { DriveInput } from "@powerhousedao/shared/document-drive";
|
|
13
14
|
import "@electric-sql/pglite";
|
|
14
15
|
import { IRenown as IRenown$1 } from "@renown/sdk";
|
|
@@ -16,6 +17,14 @@ import { IRenown as IRenown$1 } from "@renown/sdk";
|
|
|
16
17
|
declare const SUPPORTED_PG_MAJORS: readonly [16, 17];
|
|
17
18
|
type SupportedPgMajor = (typeof SUPPORTED_PG_MAJORS)[number];
|
|
18
19
|
//#endregion
|
|
20
|
+
//#region src/pglite-store.d.mts
|
|
21
|
+
/** How each PGlite store runs; unset fields take the defaults. */
|
|
22
|
+
interface PgliteStoreSettings {
|
|
23
|
+
fsync?: boolean;
|
|
24
|
+
maintenance?: PgliteMaintenanceSettings;
|
|
25
|
+
workerMemoryMb?: number;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
19
28
|
//#region src/privacy.d.mts
|
|
20
29
|
type PrivacyOptions = {
|
|
21
30
|
/** Wins over PH_PRIVACY_ENABLED. */
|
|
@@ -24,6 +33,11 @@ type PrivacyOptions = {
|
|
|
24
33
|
deploymentSecret?: string;
|
|
25
34
|
/** The reactor's signer, for a caller-provided reactor. */
|
|
26
35
|
signer?: ISigner;
|
|
36
|
+
/** Each wins over its PH_PRIVACY_* env var. */
|
|
37
|
+
intervalMs?: number;
|
|
38
|
+
deadlineMs?: number;
|
|
39
|
+
markerGraceMs?: number;
|
|
40
|
+
purgeTimeoutMs?: number;
|
|
27
41
|
};
|
|
28
42
|
//#endregion
|
|
29
43
|
//#region src/types.d.ts
|
|
@@ -54,6 +68,11 @@ export type IdentityOptions = {
|
|
|
54
68
|
/** Base url of the Renown instance to use */
|
|
55
69
|
baseUrl?: string;
|
|
56
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* The options view of a switchboard's config and deps: what plugins'
|
|
73
|
+
* `transformServerOptions` hook receives. `startSwitchboard` takes the
|
|
74
|
+
* config (`@powerhousedao/switchboard/config`) and {@link SwitchboardDeps}.
|
|
75
|
+
*/
|
|
57
76
|
export type StartServerOptions = {
|
|
58
77
|
/**
|
|
59
78
|
* Pre-built ReactorClientModule (typically from
|
|
@@ -217,6 +236,22 @@ export type StartServerOptions = {
|
|
|
217
236
|
*/
|
|
218
237
|
unsupportedStoredDocuments?: UnsupportedStoredDocuments;
|
|
219
238
|
};
|
|
239
|
+
/** What a switchboard is started with that is not a setting. */
|
|
240
|
+
export type SwitchboardDeps = {
|
|
241
|
+
logger?: ILogger;
|
|
242
|
+
/** See {@link StartServerOptions.reactor}. */
|
|
243
|
+
reactor?: InProcessReactorClientModule;
|
|
244
|
+
/** See {@link StartServerOptions.pluginComposition}. */
|
|
245
|
+
pluginComposition?: ResolvedPlugin[];
|
|
246
|
+
/** Receives failures in background work; Sentry by default. */
|
|
247
|
+
reportError?: (error: unknown) => void;
|
|
248
|
+
/** See {@link StartServerOptions.fatalErrorShutdown}. */
|
|
249
|
+
fatalErrorShutdown?: boolean;
|
|
250
|
+
/** See {@link StartServerOptions.signalHandlers}. */
|
|
251
|
+
signalHandlers?: boolean;
|
|
252
|
+
/** The privacy add-on's signer, for a caller-provided reactor. */
|
|
253
|
+
privacySigner?: ISigner;
|
|
254
|
+
};
|
|
220
255
|
export type SwitchboardReactor = {
|
|
221
256
|
defaultDriveUrl: string | undefined;
|
|
222
257
|
reactor: IReactorClient;
|
|
@@ -315,6 +350,8 @@ export declare class StoredDocumentsRefusedError extends Error {
|
|
|
315
350
|
}
|
|
316
351
|
//#endregion
|
|
317
352
|
//#region src/server.d.mts
|
|
353
|
+
/** Process-wide settings an edge applies once, before its first `startSwitchboard`. */
|
|
354
|
+
export declare function initSwitchboardProcess(options?: Pick<SwitchboardConfigInput, "logLevel">): void;
|
|
318
355
|
/**
|
|
319
356
|
* Attempt to bind a throwaway TCP server to the given port. Resolves true if
|
|
320
357
|
* the port is free, false if the OS reports it in use. Any other error is
|
|
@@ -336,15 +373,11 @@ export declare function createReactorKysely(opts: {
|
|
|
336
373
|
reactorPgliteDir: string | null;
|
|
337
374
|
reactorPgliteMajor: SupportedPgMajor | null;
|
|
338
375
|
inMemory: boolean;
|
|
339
|
-
/**
|
|
340
|
-
* Resolved lazily: only the Postgres branch has a host pool, and
|
|
341
|
-
* {@link resolveHostPoolSize} throws on a bad REACTOR_DB_POOL_SIZE_HOST.
|
|
342
|
-
* Called eagerly it would fail a PGlite-backed server over a value that
|
|
343
|
-
* path never reads.
|
|
344
|
-
*/
|
|
376
|
+
/** Called only on the Postgres branch, the one with a host pool. */
|
|
345
377
|
hostPoolSize: () => number;
|
|
346
378
|
/** Open the PGlite store in its own worker thread. */
|
|
347
379
|
pgliteWorkers: boolean;
|
|
380
|
+
pgliteSettings?: PgliteStoreSettings;
|
|
348
381
|
logger: ILogger;
|
|
349
382
|
}): Promise<ReactorStorage>;
|
|
350
383
|
export interface PgliteStorageDirs {
|
|
@@ -377,9 +410,11 @@ export declare function resolvePgliteStorageDirs(opts: {
|
|
|
377
410
|
reactorDbUrl: string | undefined;
|
|
378
411
|
/** The caller passed its own reactor — the reactor-side dir is unused. */
|
|
379
412
|
callerReactor: boolean;
|
|
413
|
+
/** The relocated `.ph` root (PH_USER_DATA_DIR at the edge). */
|
|
414
|
+
userDataDir?: string;
|
|
380
415
|
phDir?: string;
|
|
381
416
|
}): PgliteStorageDirs;
|
|
382
|
-
/**
|
|
417
|
+
/** The remote attachment service config for switchboard's own `/attachments/*` API; `attachments.serviceUrl` carries PH_SWITCHBOARD_PUBLIC_URL. */
|
|
383
418
|
export declare function deriveAttachmentServiceConfig(options: Pick<StartServerOptions, "attachmentServiceUrl" | "https">, serverPort: number, renown: IRenown | null): {
|
|
384
419
|
remoteUrl: string;
|
|
385
420
|
jwtHandler: JwtHandler | undefined;
|
|
@@ -402,7 +437,7 @@ export declare function deriveAttachmentServiceConfig(options: Pick<StartServerO
|
|
|
402
437
|
* teardown the SIGINT/SIGTERM handlers (`withSignalHandlers`) run, so calling
|
|
403
438
|
* it twice, or receiving a signal around it, tears down once.
|
|
404
439
|
*/
|
|
405
|
-
export declare const startSwitchboard: (
|
|
440
|
+
export declare const startSwitchboard: (input?: SwitchboardConfigInput, deps?: SwitchboardDeps) => Promise<SwitchboardReactor>;
|
|
406
441
|
//#endregion
|
|
407
442
|
export type { SwitchboardReactorDefaultsOptions, WorkflowTriggersCapability };
|
|
408
443
|
export {};
|
package/dist/server.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/privacy.mts","../src/types.ts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/pglite-store.mts","../src/privacy.mts","../src/types.ts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;;;;;;cAYa;KACD,2BAA2B;;;;UCoHtB;EACf;EACA,cAAc;EACd;;;;KC3GU;;EAEV;;EAEA;;EAEA,SAAS;;EAET;EACA;EACA;EACA;;;;;;;;;;YCXU;;YAKA,wBAAwB;EAClC,eAAe;;YAGL;EACV;EACA;EACA;;YAGU;;EAEV;;;;;EAKA;;EAGA;;;;;;;YAQU;;;;;;;;;;;;;;;;;;;;;EAqBV,UAAU;;;;;;;;EAQV;;;;;;;EAOA;;;;;;;EAOA;EACA;;;;;;;EAOA;;;;;;EAMA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;IAEM;IACA;;;;;;;EASN,WAAW;;EAEX;;;EAGA;;;;;;EAMA,oBAAoB;;;EAGpB;;;;EAIA;;;EAGA;IACE;;;EAGF,UAAU;EACV,kBAAkB;EAClB;EACA;;;;;;EAMA;EACA,SAAS;;;;;;;;;;EAUT;;;;;;;;;;EAUA;;;;;;;;;EASA;IACE;IACA;IACA;;;;;;;;;;;EAWF;IACE;IACA;;;;;;;;;EASF,6BAA6B;;;YAInB;EACV,SAAS;;EAET,UAAU;;EAEV,oBAAoB;;EAEpB,eAAe;;EAEf;;EAEA;;EAEA,gBAAgB;;YAGN;EACV;EACA,SAAS;;;;EAIT,mBAAmB;;EAEnB,+BAA+B;;;EAG/B,mBAAmB;;EAEnB;;EAEA,iBAAiB;;EAEjB;IAAY,SAAS;;;EAErB;;EAEA;;EAEA,WAAW;;EAEX,QAAQ;;;;;EAKR;;;;;;;;EAQA,gBAAgB;;;;KCnQN;EAIV,iBAAiB;;EAEjB,mBAAmB;;EAEnB;;;;;;;EAOA,gBAAgB;;EAEhB;;EAEA;IACE;IACA,eAAe,QAAQ;;;EAGzB,sBAAsB;EACtB,SAAS;;;;;;EAMT,SAAS;;;;;EAKT,cAAc,KAAK;;EAEnB,wBAAwB;;wBAiBV,gCACd,gBAAgB,gBAChB,eAAe,sBACf,UAAS;;;;wBCvEK,kCACd,OAAO,wCACP,KAAK,OAAO,aACX;;qBAaU,oCAAoC;WACtC;IAAqB;IAAkB;;WACvC;EAET,YAAY,OAAO;SAcZ,QAAQ,iBAAiB,SAAS;;;;;wBC6I3B,uBACd,UAAS,KAAK;;;;;;wBAgCM,gBAAgB,eAAe;;;;;;KAsFhD;EACH,QAAQ,OAAO;EACf,qBAAqB;EACrB,cAAc;;wBAGM,oBAAoB;EACxC;EACA;EACA,oBAAoB;EACpB;;EAEA;;EAEA;EACA,iBAAiB;EACjB,QAAQ;IACN,QAAQ;iBA2DK;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;wBAcc,yBAAyB;EACvC;EACA;;EAEA;;EAEA;EACA;IACE;;wBAmCY,8BACd,SAAS,KAAK,uDACd,oBACA,QAAQ;EACL;EAAmB,YAAY;;;;;;;;;;;;;;;;;;;;qBA8sCvB,mBAAgB,QACpB,wBAAsB,OACvB,oBACL,QAAQ"}
|
package/dist/server.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { n as StoredDocumentsRefusedError, r as resolveUnsupportedStoredDocuments } from "./from-env-BO0n9R02.mjs";
|
|
3
|
+
import { a as resolvePgliteStorageDirs, i as isPortAvailable, l as applySwitchboardReactorDefaults, n as deriveAttachmentServiceConfig, o as startSwitchboard, r as initSwitchboardProcess, t as createReactorKysely } from "./server-CtGBZlTg.mjs";
|
|
4
|
+
export { StoredDocumentsRefusedError, applySwitchboardReactorDefaults, createReactorKysely, deriveAttachmentServiceConfig, initSwitchboardProcess, isPortAvailable, resolvePgliteStorageDirs, resolveUnsupportedStoredDocuments, startSwitchboard };
|
|
5
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d1ddb4e9-52c7-59a9-bc55-4e6b13c67470")}catch(e){}}();
|
|
6
|
+
//# debugId=d1ddb4e9-52c7-59a9-bc55-4e6b13c67470
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { driveCreateDocument, driveCreateState } from "@powerhousedao/shared/document-drive";
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="43c4397d-8c51-5a5f-a076-14afbdb56cac")}catch(e){}}();
|
|
3
|
+
import { REACTOR_DRIVE_DOCUMENT_TYPE, reactorDriveCreateState } from "@powerhousedao/reactor-drive";
|
|
4
|
+
import { driveCreateState, driveDocumentType } from "@powerhousedao/shared/document-drive";
|
|
6
5
|
//#region src/utils.mts
|
|
7
6
|
/**
|
|
8
7
|
* A configured id pins the drive, and only a legacy drive can take a chosen
|
|
9
8
|
* id; otherwise the client's creation default applies.
|
|
10
9
|
*/
|
|
11
|
-
|
|
12
|
-
return
|
|
10
|
+
function newDrive(client, documentType, initialState, id) {
|
|
11
|
+
return client.newDocument(documentType, {
|
|
12
|
+
initialState,
|
|
13
|
+
...id ? {
|
|
14
|
+
signaturePolicy: "legacy",
|
|
15
|
+
id
|
|
16
|
+
} : {}
|
|
17
|
+
});
|
|
13
18
|
}
|
|
14
19
|
/** The document that already holds `slug`; null when two do (an id and a slug). */
|
|
15
20
|
async function slugHolder(client, slug) {
|
|
@@ -47,7 +52,9 @@ async function addDefaultDrive(client, drive, serverPort, logger = console) {
|
|
|
47
52
|
} catch {}
|
|
48
53
|
if (existingDrive) return `http://localhost:${serverPort}/d/${driveId}`;
|
|
49
54
|
const { global } = driveCreateState();
|
|
50
|
-
const
|
|
55
|
+
const taken = await slugTakenBy(client, drive, driveDocumentType, serverPort, logger);
|
|
56
|
+
if (taken !== void 0) return taken ?? void 0;
|
|
57
|
+
const document = await newDrive(client, driveDocumentType, {
|
|
51
58
|
global: {
|
|
52
59
|
...global,
|
|
53
60
|
name: drive.global.name,
|
|
@@ -59,15 +66,12 @@ async function addDefaultDrive(client, drive, serverPort, logger = console) {
|
|
|
59
66
|
listeners: drive.local?.listeners ?? [],
|
|
60
67
|
triggers: drive.local?.triggers ?? []
|
|
61
68
|
}
|
|
62
|
-
});
|
|
63
|
-
const taken = await slugTakenBy(client, drive, created.header.documentType, serverPort, logger);
|
|
64
|
-
if (taken !== void 0) return taken ?? void 0;
|
|
65
|
-
const document = await underCreatePolicy(client, created, drive.id);
|
|
69
|
+
}, drive.id);
|
|
66
70
|
if (drive.slug && drive.slug.length > 0) document.header.slug = drive.slug;
|
|
67
71
|
if (drive.global.name) document.header.name = drive.global.name;
|
|
68
72
|
if (drive.preferredEditor) document.header.meta = { preferredEditor: drive.preferredEditor };
|
|
69
73
|
try {
|
|
70
|
-
await client.create(document);
|
|
74
|
+
await (await client.write.create(document)).readable;
|
|
71
75
|
} catch (e) {
|
|
72
76
|
if (!(e instanceof Error ? e.message : String(e)).includes("already exists")) throw e;
|
|
73
77
|
}
|
|
@@ -84,7 +88,9 @@ async function addDefaultReactorDrive(client, drive, serverPort, logger = consol
|
|
|
84
88
|
} catch {}
|
|
85
89
|
if (existingDrive) return `http://localhost:${serverPort}/d/${driveId}`;
|
|
86
90
|
const { global, local } = reactorDriveCreateState();
|
|
87
|
-
const
|
|
91
|
+
const taken = await slugTakenBy(client, drive, REACTOR_DRIVE_DOCUMENT_TYPE, serverPort, logger);
|
|
92
|
+
if (taken !== void 0) return taken ?? void 0;
|
|
93
|
+
const document = await newDrive(client, REACTOR_DRIVE_DOCUMENT_TYPE, {
|
|
88
94
|
global: {
|
|
89
95
|
...global,
|
|
90
96
|
name: drive.global.name,
|
|
@@ -95,15 +101,12 @@ async function addDefaultReactorDrive(client, drive, serverPort, logger = consol
|
|
|
95
101
|
availableOffline: drive.local?.availableOffline ?? local.availableOffline,
|
|
96
102
|
sharingType: drive.local?.sharingType ?? local.sharingType
|
|
97
103
|
}
|
|
98
|
-
});
|
|
99
|
-
const taken = await slugTakenBy(client, drive, created.header.documentType, serverPort, logger);
|
|
100
|
-
if (taken !== void 0) return taken ?? void 0;
|
|
101
|
-
const document = await underCreatePolicy(client, created, drive.id);
|
|
104
|
+
}, drive.id);
|
|
102
105
|
if (drive.slug && drive.slug.length > 0) document.header.slug = drive.slug;
|
|
103
106
|
if (drive.global.name) document.header.name = drive.global.name;
|
|
104
107
|
if (drive.preferredEditor) document.header.meta = { preferredEditor: drive.preferredEditor };
|
|
105
108
|
try {
|
|
106
|
-
await client.create(document);
|
|
109
|
+
await (await client.write.create(document)).readable;
|
|
107
110
|
} catch (e) {
|
|
108
111
|
if (!(e instanceof Error ? e.message : String(e)).includes("already exists")) throw e;
|
|
109
112
|
}
|
|
@@ -112,5 +115,5 @@ async function addDefaultReactorDrive(client, drive, serverPort, logger = consol
|
|
|
112
115
|
//#endregion
|
|
113
116
|
export { addDefaultReactorDrive as n, addDefaultDrive as t };
|
|
114
117
|
|
|
115
|
-
//# sourceMappingURL=utils-
|
|
116
|
-
//# debugId=
|
|
118
|
+
//# sourceMappingURL=utils-BbV_nodR.mjs.map
|
|
119
|
+
//# debugId=43c4397d-8c51-5a5f-a076-14afbdb56cac
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-BbV_nodR.mjs","sources":["../src/utils.mts"],"sourcesContent":["import type { IReactorClient } from \"@powerhousedao/reactor\";\nimport {\n REACTOR_DRIVE_DOCUMENT_TYPE,\n reactorDriveCreateState,\n} from \"@powerhousedao/reactor-drive\";\nimport {\n driveCreateState,\n driveDocumentType,\n} from \"@powerhousedao/shared/document-drive\";\nimport type { DriveInput } from \"@powerhousedao/shared/document-drive\";\nimport type {\n PHBaseState,\n PHDocument,\n} from \"@powerhousedao/shared/document-model\";\n\n/**\n * A configured id pins the drive, and only a legacy drive can take a chosen\n * id; otherwise the client's creation default applies.\n */\nfunction newDrive<TDocument extends PHDocument>(\n client: IReactorClient,\n documentType: string,\n initialState: Partial<PHBaseState>,\n id: string | undefined,\n): Promise<TDocument> {\n return client.newDocument<TDocument>(documentType, {\n initialState,\n ...(id ? { signaturePolicy: \"legacy\" as const, id } : {}),\n });\n}\n\ntype DefaultDriveLogger = { error: (message: string) => void };\n\n/** The document that already holds `slug`; null when two do (an id and a slug). */\nasync function slugHolder(\n client: IReactorClient,\n slug: string,\n): Promise<PHDocument | null | undefined> {\n let id: string;\n try {\n id = await client.resolveIdOrSlug(slug);\n } catch (error) {\n const notFound =\n error instanceof Error && error.name === \"DocumentNotFoundError\";\n return notFound ? undefined : null;\n }\n return client.get(id);\n}\n\n/**\n * A default drive whose slug another document holds: a drive of the same type\n * stands in for it (its URL); anything else keeps it uncreated (null), with an\n * error logged so the server still starts. Undefined when the slug is free.\n */\nasync function slugTakenBy(\n client: IReactorClient,\n drive: DriveInput,\n documentType: string,\n serverPort: number,\n logger: DefaultDriveLogger,\n): Promise<string | null | undefined> {\n if (!drive.slug) return undefined;\n const holder = await slugHolder(client, drive.slug);\n if (holder === undefined) return undefined;\n if (holder?.header.documentType === documentType) {\n return `http://localhost:${serverPort}/d/${holder.header.id}`;\n }\n const owner = holder\n ? `${holder.header.documentType} document ${holder.header.id}`\n : \"two documents\";\n logger.error(\n `The default drive \"${drive.slug}\" was not created: the slug belongs to ${owner}.`,\n );\n return null;\n}\n\n/** Creates a configured drive unless one with its id or slug exists; the\n * URL it is served at, or undefined when another document holds the slug. */\nexport async function addDefaultDrive(\n client: IReactorClient,\n drive: DriveInput,\n serverPort: number,\n logger: DefaultDriveLogger = console,\n): Promise<string | undefined> {\n let driveId = drive.id;\n if (!driveId || driveId.length === 0) {\n driveId = drive.slug;\n }\n\n if (!driveId || driveId.length === 0) {\n throw new Error(\"Invalid Drive Id\");\n }\n\n // check if the drive already exists\n let existingDrive;\n try {\n existingDrive = await client.get(driveId);\n } catch {\n //\n }\n\n // already exists, return the existing drive url\n if (existingDrive) {\n return `http://localhost:${serverPort}/d/${driveId}`;\n }\n\n const { global } = driveCreateState();\n const taken = await slugTakenBy(\n client,\n drive,\n driveDocumentType,\n serverPort,\n logger,\n );\n if (taken !== undefined) return taken ?? undefined;\n\n const document = await newDrive(\n client,\n driveDocumentType,\n {\n global: {\n ...global,\n name: drive.global.name,\n icon: drive.global.icon ?? global.icon,\n },\n local: {\n availableOffline: drive.local?.availableOffline ?? false,\n sharingType: drive.local?.sharingType ?? \"public\",\n listeners: drive.local?.listeners ?? [],\n triggers: drive.local?.triggers ?? [],\n },\n } as Partial<PHBaseState>,\n drive.id,\n );\n if (drive.slug && drive.slug.length > 0) {\n document.header.slug = drive.slug;\n }\n if (drive.global.name) {\n document.header.name = drive.global.name;\n }\n if (drive.preferredEditor) {\n document.header.meta = { preferredEditor: drive.preferredEditor };\n }\n\n try {\n await (\n await client.write.create(document)\n ).readable;\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : String(e);\n if (!errorMessage.includes(\"already exists\")) {\n throw e;\n }\n }\n\n return `http://localhost:${serverPort}/d/${driveId}`;\n}\n\n/** addDefaultDrive for a reactor drive. */\nexport async function addDefaultReactorDrive(\n client: IReactorClient,\n drive: DriveInput,\n serverPort: number,\n logger: DefaultDriveLogger = console,\n): Promise<string | undefined> {\n let driveId = drive.id;\n if (!driveId || driveId.length === 0) {\n driveId = drive.slug;\n }\n\n if (!driveId || driveId.length === 0) {\n throw new Error(\"Invalid Drive Id\");\n }\n\n let existingDrive;\n try {\n existingDrive = await client.get(driveId);\n } catch {\n //\n }\n\n if (existingDrive) {\n return `http://localhost:${serverPort}/d/${driveId}`;\n }\n\n const { global, local } = reactorDriveCreateState();\n const taken = await slugTakenBy(\n client,\n drive,\n REACTOR_DRIVE_DOCUMENT_TYPE,\n serverPort,\n logger,\n );\n if (taken !== undefined) return taken ?? undefined;\n\n const document = await newDrive(\n client,\n REACTOR_DRIVE_DOCUMENT_TYPE,\n {\n global: {\n ...global,\n name: drive.global.name,\n icon: drive.global.icon ?? global.icon,\n },\n local: {\n ...local,\n availableOffline:\n drive.local?.availableOffline ?? local.availableOffline,\n sharingType: drive.local?.sharingType ?? local.sharingType,\n },\n } as Partial<PHBaseState>,\n drive.id,\n );\n if (drive.slug && drive.slug.length > 0) {\n document.header.slug = drive.slug;\n }\n if (drive.global.name) {\n document.header.name = drive.global.name;\n }\n if (drive.preferredEditor) {\n document.header.meta = { preferredEditor: drive.preferredEditor };\n }\n\n try {\n await (\n await client.write.create(document)\n ).readable;\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : String(e);\n if (!errorMessage.includes(\"already exists\")) {\n throw e;\n }\n }\n\n return `http://localhost:${serverPort}/d/${driveId}`;\n}\n\nexport { isPostgresUrl } from \"./postgres-url.mjs\";\n"],"names":[],"mappings":";;;;;;;;;AAmBA,SAAS,SACP,QACA,cACA,cACA,IACoB;CACpB,OAAO,OAAO,YAAuB,cAAc;EACjD;EACA,GAAI,KAAK;GAAE,iBAAiB;GAAmB;EAAG,IAAI,CAAC;CACzD,CAAC;AACH;;AAKA,eAAe,WACb,QACA,MACwC;CACxC,IAAI;CACJ,IAAI;EACF,KAAK,MAAM,OAAO,gBAAgB,IAAI;CACxC,SAAS,OAAO;EAGd,OADE,iBAAiB,SAAS,MAAM,SAAS,0BACzB,KAAA,IAA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O,MACf,SAAS,OAAO,OAAO,MAAM,OAAO;CAEtC,IAAI,MAAM,iBACR,SAAS,OAAO,OAAO,EAAE,iBAAiB,MAAM,gBAAgB;CAGlE,IAAI;EACF,OACE,MAAM,OAAO,MAAM,OAAO,QAAQ,EAAA,CAClC;CACJ,SAAS,GAAG;EAEV,IAAI,EADiB,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,EAAA,CAC5C,SAAS,gBAAgB,GACzC,MAAM;CAEV;CAEA,OAAO,oBAAoB,WAAW,KAAK;AAC7C","debug_id":"43c4397d-8c51-5a5f-a076-14afbdb56cac"}
|
package/dist/utils.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","names":[],"sources":["../src/postgres-url.mts","../src/utils.mts"],"mappings":";;;wBAAgB,cAAc;;;
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"sources":["../src/postgres-url.mts","../src/utils.mts"],"mappings":";;;wBAAgB,cAAc;;;KC+BzB;EAAuB,QAAQ;;;;wBA+Cd,gBACpB,QAAQ,gBACR,OAAO,YACP,oBACA,SAAQ,qBACP;;wBA4EmB,uBACpB,QAAQ,gBACR,OAAO,YACP,oBACA,SAAQ,qBACP"}
|
package/dist/utils.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as isPostgresUrl } from "./postgres-url-DTDhBjXX.mjs";
|
|
2
|
-
import { n as addDefaultReactorDrive, t as addDefaultDrive } from "./utils-
|
|
2
|
+
import { n as addDefaultReactorDrive, t as addDefaultDrive } from "./utils-BbV_nodR.mjs";
|
|
3
3
|
export { addDefaultDrive, addDefaultReactorDrive, isPostgresUrl };
|
|
4
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
5
|
-
//# debugId=
|
|
4
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="135bae10-d500-567c-9048-68df0a6da261")}catch(e){}}();
|
|
5
|
+
//# debugId=135bae10-d500-567c-9048-68df0a6da261
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="eca2a0ad-1b80-50e5-a2e3-272987fbba5e")}catch(e){}}();
|
|
3
3
|
import { t as isPostgresUrl } from "./postgres-url-DTDhBjXX.mjs";
|
|
4
4
|
import { existsSync, realpathSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
import { readFile } from "node:fs/promises";
|
|
8
8
|
import os from "node:os";
|
|
9
|
+
//#region src/env.mts
|
|
10
|
+
function parseNonNegativeInt(raw, name) {
|
|
11
|
+
if (raw === void 0 || raw.trim() === "") return;
|
|
12
|
+
const value = Number.parseInt(raw, 10);
|
|
13
|
+
if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) throw new Error(`${name} must be a non-negative integer, got "${raw}"`);
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
9
17
|
//#region src/boot-preconditions.mts
|
|
10
18
|
/** The reactor database the server boots with: its `dbPath` option, then the env. */
|
|
11
19
|
function reactorDbUrlOf(dbPath, env) {
|
|
@@ -35,14 +43,6 @@ function switchboardBootIssues(facts) {
|
|
|
35
43
|
return [...workerPoolIssues(facts), ...facts.projectionWorker ? projectionWorkerIssues(facts) : []];
|
|
36
44
|
}
|
|
37
45
|
//#endregion
|
|
38
|
-
//#region src/env.mts
|
|
39
|
-
function parseNonNegativeInt(raw, name) {
|
|
40
|
-
if (raw === void 0 || raw.trim() === "") return;
|
|
41
|
-
const value = Number.parseInt(raw, 10);
|
|
42
|
-
if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) throw new Error(`${name} must be a non-negative integer, got "${raw}"`);
|
|
43
|
-
return value;
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
46
|
//#region src/projection-worker.mts
|
|
47
47
|
const DEFAULT_DB_POOL_SIZE_PROJECTION = 8;
|
|
48
48
|
const ON_TOKENS = [
|
|
@@ -298,27 +298,7 @@ function parseWorkerCount(raw) {
|
|
|
298
298
|
return value;
|
|
299
299
|
}
|
|
300
300
|
//#endregion
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Enforcement flags from the REACTOR_* env vars. Each flag requires the ones
|
|
304
|
-
* before it; the reactor rejects an inconsistent set rather than enforcing less
|
|
305
|
-
* than the operator asked for, so this reports what was asked without
|
|
306
|
-
* correcting it.
|
|
307
|
-
*/
|
|
308
|
-
function resolveReactorFeatureFlags(env) {
|
|
309
|
-
const flags = {
|
|
310
|
-
documentDecisions: env.REACTOR_DOCUMENT_DECISIONS === "true",
|
|
311
|
-
authEnforcement: env.REACTOR_AUTH_ENFORCEMENT === "true",
|
|
312
|
-
authGroups: env.REACTOR_AUTH_GROUPS === "true",
|
|
313
|
-
authConditions: env.REACTOR_AUTH_CONDITIONS === "true"
|
|
314
|
-
};
|
|
315
|
-
return {
|
|
316
|
-
flags,
|
|
317
|
-
enabled: Object.entries(flags).filter(([, isEnabled]) => isEnabled).map(([name]) => name)
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
//#endregion
|
|
321
|
-
export { resolveWorkerModelSources as a, resolveProjectionWorkerOptions as c, reactorDbUrlOf as d, switchboardBootIssues as f, resolveHostPoolSize as i, parseNonNegativeInt as l, workerTrustPolicyIssue as m, buildWorkerDbConfig as n, resolveWorkerPoolOptions as o, workerPoolIssues as p, keepImportableSources as r, assertProjectionWorkerSupported as s, resolveReactorFeatureFlags as t, projectionWorkerIssues as u };
|
|
301
|
+
export { resolveWorkerModelSources as a, parseOnOff as c, reactorDbUrlOf as d, switchboardBootIssues as f, parseNonNegativeInt as h, resolveHostPoolSize as i, resolveProjectionWorkerOptions as l, workerTrustPolicyIssue as m, keepImportableSources as n, resolveWorkerPoolOptions as o, workerPoolIssues as p, parseWorkerCount as r, assertProjectionWorkerSupported as s, buildWorkerDbConfig as t, projectionWorkerIssues as u };
|
|
322
302
|
|
|
323
|
-
//# sourceMappingURL=
|
|
324
|
-
//# debugId=
|
|
303
|
+
//# sourceMappingURL=worker-pool-BWHBLBJd.mjs.map
|
|
304
|
+
//# debugId=eca2a0ad-1b80-50e5-a2e3-272987fbba5e
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-pool-BWHBLBJd.mjs","sources":["../src/env.mts","../src/boot-preconditions.mts","../src/projection-worker.mts","../src/worker-pool.mts"],"sourcesContent":["export function parseNonNegativeInt(\n raw: string | undefined,\n name: string,\n): number | undefined {\n if (raw === undefined || raw.trim() === \"\") {\n return undefined;\n }\n const value = Number.parseInt(raw, 10);\n if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) {\n throw new Error(`${name} must be a non-negative integer, got \"${raw}\"`);\n }\n return value;\n}\n","import { isPostgresUrl } from \"./postgres-url.mjs\";\n\n/** What the server refuses to boot with; it throws the first, `ph host check` reports all. */\nexport interface SwitchboardBootFacts {\n dev: boolean;\n /** Executor pool size; 0 when the pool is off. */\n workers: number;\n projectionWorker: boolean;\n reactorDbUrl: string | undefined;\n authEnforcement: boolean;\n renownSource: \"self\" | \"remote\";\n}\n\n/** The reactor database the server boots with: its `dbPath` option, then the env. */\nexport function reactorDbUrlOf(\n dbPath: string | undefined,\n env: Readonly<Record<string, string | undefined>>,\n): string | undefined {\n return (\n dbPath ?? env.PH_REACTOR_DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL\n );\n}\n\nexport function workerTrustPolicyIssue(\n facts: Pick<\n SwitchboardBootFacts,\n \"workers\" | \"authEnforcement\" | \"renownSource\"\n >,\n): string | undefined {\n if (\n facts.workers > 0 &&\n facts.authEnforcement &&\n facts.renownSource === \"self\"\n ) {\n return (\n \"The executor worker pool (REACTOR_WORKERS) cannot verify signers when \" +\n \"REACTOR_AUTH_ENFORCEMENT is on and Renown credentials are read from \" +\n 'this switchboard (\"self\" via auth.renown.source or RENOWN_SOURCE): ' +\n \"pooled workers have no trust policy and would refuse every signed \" +\n \"write. Set RENOWN_SOURCE=remote, or disable the worker pool \" +\n \"(REACTOR_WORKERS=0).\"\n );\n }\n return undefined;\n}\n\n/** In the order the server checks them; empty when the pool is off. */\nexport function workerPoolIssues(facts: SwitchboardBootFacts): string[] {\n if (facts.workers <= 0) return [];\n const issues: string[] = [];\n if (facts.dev) {\n issues.push(\n \"The executor worker pool (REACTOR_WORKERS) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary\",\n );\n }\n const trust = workerTrustPolicyIssue(facts);\n if (trust) issues.push(trust);\n if (!facts.reactorDbUrl || !isPostgresUrl(facts.reactorDbUrl)) {\n issues.push(\n \"The executor worker pool (REACTOR_WORKERS) requires a Postgres reactor database — set PH_REACTOR_DATABASE_URL or PH_SWITCHBOARD_DATABASE_URL. PGlite cannot be shared across worker threads.\",\n );\n }\n return issues;\n}\n\n/** The projection worker's preconditions, assuming it is enabled. */\nexport function projectionWorkerIssues(\n facts: Pick<SwitchboardBootFacts, \"dev\" | \"reactorDbUrl\">,\n): string[] {\n const issues: string[] = [];\n if (facts.dev) {\n issues.push(\n \"The projection worker (REACTOR_PROJECTION_WORKER) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary\",\n );\n }\n if (!facts.reactorDbUrl || !isPostgresUrl(facts.reactorDbUrl)) {\n issues.push(\n \"The projection worker (REACTOR_PROJECTION_WORKER) requires a Postgres reactor database — set PH_REACTOR_DATABASE_URL or PH_SWITCHBOARD_DATABASE_URL. PGlite cannot be shared across worker threads.\",\n );\n }\n return issues;\n}\n\nexport function switchboardBootIssues(facts: SwitchboardBootFacts): string[] {\n return [\n ...workerPoolIssues(facts),\n ...(facts.projectionWorker ? projectionWorkerIssues(facts) : []),\n ];\n}\n","import { projectionWorkerIssues } from \"./boot-preconditions.mjs\";\nimport { parseNonNegativeInt } from \"./env.mjs\";\n\nexport type SwitchboardProjectionWorkerOptions = {\n dbPoolSize: number;\n};\n\nexport type SwitchboardProjectionWorkerInput = {\n enabled?: boolean;\n dbPoolSize?: number;\n};\n\n// Run 11 of the bench sweep saw chain.depth ~6.5 at one shard, so 8 covers the\n// working set; behind a 25-slot transaction pooler a larger pool is not spendable.\nconst DEFAULT_DB_POOL_SIZE_PROJECTION = 8;\n\nconst ON_TOKENS = [\"1\", \"true\", \"on\", \"yes\"];\nconst OFF_TOKENS = [\"0\", \"false\", \"off\", \"no\"];\n\n/**\n * Enabled by REACTOR_PROJECTION_WORKER (1/true/on/yes, case-insensitive) or\n * `input.enabled`, which wins when defined; null when off (the default).\n */\nexport function resolveProjectionWorkerOptions(\n input: SwitchboardProjectionWorkerInput | undefined,\n env: NodeJS.ProcessEnv,\n): SwitchboardProjectionWorkerOptions | null {\n const enabled =\n input?.enabled ?? parseOnOff(env.REACTOR_PROJECTION_WORKER) ?? false;\n if (!enabled) {\n return null;\n }\n const dbPoolSize =\n input?.dbPoolSize ??\n parseNonNegativeInt(\n env.REACTOR_DB_POOL_SIZE_PROJECTION,\n \"REACTOR_DB_POOL_SIZE_PROJECTION\",\n ) ??\n DEFAULT_DB_POOL_SIZE_PROJECTION;\n if (dbPoolSize < 1) {\n throw new Error(\n \"REACTOR_DB_POOL_SIZE_PROJECTION must be at least 1; the projection worker cannot run without a pool\",\n );\n }\n return { dbPoolSize };\n}\n\n/** Same preconditions as the executor worker pool; message shape mirrors server.mts. */\nexport function assertProjectionWorkerSupported(args: {\n dev: boolean;\n reactorDbUrl: string | undefined;\n}): void {\n const issue = projectionWorkerIssues(args).at(0);\n if (issue) throw new Error(issue);\n}\n\nexport function parseOnOff(raw: string | undefined): boolean | undefined {\n if (raw === undefined || raw.trim() === \"\") {\n return undefined;\n }\n const token = raw.trim().toLowerCase();\n if (ON_TOKENS.includes(token)) {\n return true;\n }\n if (OFF_TOKENS.includes(token)) {\n return false;\n }\n throw new Error(\n `REACTOR_PROJECTION_WORKER must be one of 1, true, on, yes, 0, false, off, no, got \"${raw}\"`,\n );\n}\n","import type { DbConfig, FileModelSource } from \"@powerhousedao/reactor\";\nimport type { ILogger } from \"document-model\";\nimport { existsSync, realpathSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { parseNonNegativeInt } from \"./env.mjs\";\n\nexport type WorkerCountInput = number | \"auto\";\n\nexport type SwitchboardWorkerPoolOptions = {\n numWorkers: number;\n /** Whether numWorkers was given explicitly or sized from the core count. */\n mode: \"explicit\" | \"auto\";\n dbPoolSizePerWorker: number;\n acquireTimeoutMs: number;\n};\n\nexport type SwitchboardWorkerPoolInput = {\n numWorkers?: WorkerCountInput;\n dbPoolSizePerWorker?: number;\n acquireTimeoutMs?: number;\n};\n\nconst DEFAULT_DB_POOL_SIZE_PER_WORKER = 2;\nconst DEFAULT_ACQUIRE_TIMEOUT_MS = 5000;\n\n// Host reactor pool. pg-pool's own default is 10, below the bench harness's\n// floor of 16 (bench/host/src/main.ts, REACTOR_DB_POOL_SIZE_HOST). Run 8 of\n// the sweep found throughput flat from 16 to 96 but per-op index p50\n// collapsing 262ms -> 43ms, so this buys latency, not throughput — and only\n// up to whatever the connection budget in front of Postgres allows.\nconst DEFAULT_DB_POOL_SIZE_HOST = 16;\n\n// Auto-sizing: reserve cores for the host event loop (queue, read models,\n// HTTP) and cap at the top of the bench sweep envelope, which also bounds\n// the worker Postgres-connection budget.\nconst AUTO_RESERVED_CORES = 2;\nconst AUTO_WORKER_CAP = 8;\n\n/** Worker count for \"auto\": always at least 1 — auto sizes the pool, it does not turn worker mode off. */\nexport function autoWorkerCount(availableCores: number): number {\n return Math.max(\n 1,\n Math.min(AUTO_WORKER_CAP, availableCores - AUTO_RESERVED_CORES),\n );\n}\n\n/**\n * Effective worker-pool config from programmatic options (which win) and the\n * REACTOR_* env vars; null when disabled (numWorkers 0, the default).\n * `\"auto\"` sizes the pool from the machine's available cores.\n */\nexport function resolveWorkerPoolOptions(\n input: SwitchboardWorkerPoolInput | undefined,\n env: NodeJS.ProcessEnv,\n availableCores: number = os.availableParallelism(),\n): SwitchboardWorkerPoolOptions | null {\n const requested =\n input?.numWorkers ?? parseWorkerCount(env.REACTOR_WORKERS) ?? 0;\n const mode = requested === \"auto\" ? \"auto\" : \"explicit\";\n const numWorkers =\n requested === \"auto\" ? autoWorkerCount(availableCores) : requested;\n if (!Number.isInteger(numWorkers) || numWorkers < 0) {\n throw new Error(\n `workerPool.numWorkers must be \"auto\" or a non-negative integer, got ${numWorkers}`,\n );\n }\n if (numWorkers === 0) {\n return null;\n }\n return {\n numWorkers,\n mode,\n dbPoolSizePerWorker:\n input?.dbPoolSizePerWorker ??\n parseNonNegativeInt(\n env.REACTOR_DB_POOL_SIZE_WORKER,\n \"REACTOR_DB_POOL_SIZE_WORKER\",\n ) ??\n DEFAULT_DB_POOL_SIZE_PER_WORKER,\n acquireTimeoutMs:\n input?.acquireTimeoutMs ??\n parseNonNegativeInt(\n env.REACTOR_DB_ACQUIRE_TIMEOUT_MS,\n \"REACTOR_DB_ACQUIRE_TIMEOUT_MS\",\n ) ??\n DEFAULT_ACQUIRE_TIMEOUT_MS,\n };\n}\n\n/**\n * Size of the reactor's own (host) Postgres pool. Unlike the worker pool there\n * is no \"disabled\" state — the host pool is the only Postgres pool in the\n * server path, backing both reactor storage and the read models that reach it\n * via `withSchema` — so 0 is rejected rather than read as \"off\".\n *\n * The acquire timeout is deliberately not configurable here: the host pool\n * waits indefinitely today, and making it finite converts saturation from a\n * latency problem into a thrown error on the read-model path. That is a\n * behavior change worth making separately, once the retry semantics of a\n * rejected `pool.connect()` inside the read-model coordinator are settled.\n */\nexport function resolveHostPoolSize(env: NodeJS.ProcessEnv): number {\n const poolSize =\n parseNonNegativeInt(\n env.REACTOR_DB_POOL_SIZE_HOST,\n \"REACTOR_DB_POOL_SIZE_HOST\",\n ) ?? DEFAULT_DB_POOL_SIZE_HOST;\n if (poolSize < 1) {\n throw new Error(\n \"REACTOR_DB_POOL_SIZE_HOST must be at least 1; the host pool cannot be disabled\",\n );\n }\n return poolSize;\n}\n\n/**\n * DbConfig for each worker's own pool, parsed from a postgres:// URL.\n * Explicit host, database, and user are required — no pg-side defaults.\n */\nexport function buildWorkerDbConfig(\n postgresUrl: string,\n options: Pick<\n SwitchboardWorkerPoolOptions,\n \"dbPoolSizePerWorker\" | \"acquireTimeoutMs\"\n >,\n): DbConfig {\n let parsed: URL;\n try {\n parsed = new URL(postgresUrl);\n } catch {\n throw new Error(\n `Worker pool requires a valid postgres:// URL for the reactor database, got \"${postgresUrl}\"`,\n );\n }\n const database = decodeURIComponent(parsed.pathname.replace(/^\\//, \"\"));\n if (!parsed.hostname || !database) {\n throw new Error(\n `Worker pool requires a postgres URL with a host and database name, got \"${postgresUrl}\"`,\n );\n }\n if (!parsed.username) {\n throw new Error(\n `Worker pool requires explicit credentials in the postgres URL (workers open their own connections), got \"${postgresUrl}\"`,\n );\n }\n const sslmode = parsed.searchParams.get(\"sslmode\");\n const ssl =\n parsed.searchParams.get(\"ssl\") === \"true\" ||\n (sslmode !== null && sslmode !== \"disable\");\n return {\n host: parsed.hostname,\n port: parsed.port ? Number(parsed.port) : 5432,\n database,\n user: decodeURIComponent(parsed.username),\n password: decodeURIComponent(parsed.password),\n ssl,\n applicationName: \"switchboard-worker\",\n poolSize: options.dbPoolSizePerWorker,\n connectionTimeoutMillis: options.acquireTimeoutMs,\n };\n}\n\n/** Specifiers of the base models switchboard always registers. */\nconst BASE_MODEL_SPECIFIERS = [\n \"document-model\",\n \"@powerhousedao/shared/document-drive\",\n \"@powerhousedao/reactor-drive\",\n \"@powerhousedao/reactor-group/document-models\",\n];\n\n// As the reactor builder tells a module from the rest of a source's exports.\nfunction isModelModule(value: unknown): boolean {\n const candidate = value as {\n reducer?: unknown;\n documentModel?: { global?: { id?: unknown } };\n } | null;\n return (\n typeof candidate?.reducer === \"function\" &&\n typeof candidate.documentModel?.global?.id === \"string\"\n );\n}\n\n// Drops sources that fail to import or export no model. For workflow pieces\n// only: a missing model means \"unavailable to pieces\", not a failed boot.\nexport async function keepImportableSources(\n sources: FileModelSource[],\n logger: ILogger,\n): Promise<FileModelSource[]> {\n const kept: FileModelSource[] = [];\n for (const source of sources) {\n try {\n const exports = (await import(\n pathToFileURL(source.filePath).href\n )) as Record<string, unknown>;\n if (Object.values(exports).some(isModelModule)) kept.push(source);\n } catch (error) {\n logger.warn(\n `Worker model sources: \"${source.filePath}\" does not import, so workflow pieces will not see its models: ${String(error)}`,\n );\n }\n }\n return kept;\n}\n\n/**\n * Resolves base models and configured package identifiers to `{ filePath }`\n * sources for the reactor builder. Resolution to absolute paths happens here\n * because workers (and the builder) resolve bare specifiers from the reactor\n * package's own dependency context, which cannot see switchboard or project\n * packages. Unresolvable identifiers are skipped with a warning; the builder\n * fails the boot if a registered model ends up without an importable source.\n */\nexport async function resolveWorkerModelSources(\n packages: string[],\n logger: ILogger,\n options: {\n /** Cached file for a package not installed locally, e.g. from a registry. */\n resolveRemote?: (identifier: string) => Promise<string | null>;\n } = {},\n): Promise<FileModelSource[]> {\n const sources: FileModelSource[] = [];\n for (const identifier of [...BASE_MODEL_SPECIFIERS, ...packages]) {\n const filePath =\n (await resolveModelModuleFile(identifier)) ??\n (await resolveRemoteSafely(identifier, options.resolveRemote, logger));\n if (!filePath) {\n logger.warn(\n `Worker model sources: no importable document-models entry for \"${identifier}\", skipping`,\n );\n continue;\n }\n sources.push({ filePath });\n }\n return sources;\n}\n\nasync function resolveRemoteSafely(\n identifier: string,\n resolveRemote: ((identifier: string) => Promise<string | null>) | undefined,\n logger: ILogger,\n): Promise<string | null> {\n if (!resolveRemote) return null;\n try {\n return await resolveRemote(identifier);\n } catch (error) {\n logger.warn(\n `Worker model sources: could not cache \"${identifier}\" from the registry: ${String(error)}`,\n );\n return null;\n }\n}\n\n/**\n * Absolute file path of a source's models barrel. Mirrors reactor-api's\n * import-resolver: import.meta.resolve, then the project's node_modules via\n * the package.json exports map / dist layout.\n */\nasync function resolveModelModuleFile(source: string): Promise<string | null> {\n if (isFsPath(source)) {\n return resolveFromPackageDir(source, \"./document-models\");\n }\n\n const specifier = BASE_MODEL_SPECIFIERS.includes(source)\n ? source\n : `${source}/document-models`;\n\n try {\n const resolved = import.meta.resolve(specifier);\n if (resolved.startsWith(\"file:\")) {\n return fileURLToPath(resolved);\n }\n } catch {\n // fall through to node_modules resolution from the project dir\n }\n\n const { packageName, subpath } = splitSpecifier(specifier);\n const packageDir = path.join(process.cwd(), \"node_modules\", packageName);\n if (!existsSync(packageDir)) {\n return null;\n }\n let realDir: string;\n try {\n realDir = realpathSync(packageDir);\n } catch {\n return null;\n }\n return resolveFromPackageDir(realDir, subpath);\n}\n\nfunction splitSpecifier(specifier: string): {\n packageName: string;\n subpath: string;\n} {\n const parts = specifier.split(\"/\");\n const packageSegments = specifier.startsWith(\"@\") ? 2 : 1;\n const packageName = parts.slice(0, packageSegments).join(\"/\");\n const rest = parts.slice(packageSegments).join(\"/\");\n return { packageName, subpath: rest ? `./${rest}` : \".\" };\n}\n\n/** Exports-map lookup (import condition), then conventional dist paths. */\nasync function resolveFromPackageDir(\n packageDir: string,\n subpath: string,\n): Promise<string | null> {\n const fromManifest = await resolveViaManifest(packageDir, subpath);\n if (fromManifest) {\n return fromManifest;\n }\n const candidates =\n subpath === \".\"\n ? [path.join(packageDir, \"dist\", \"index.js\")]\n : [\n path.join(packageDir, \"dist\", subpath.slice(2), \"index.js\"),\n path.join(packageDir, \"dist\", `${subpath.slice(2)}.js`),\n path.join(packageDir, subpath.slice(2), \"index.js\"),\n ];\n for (const candidate of candidates) {\n if (existsSync(candidate)) {\n return candidate;\n }\n }\n return null;\n}\n\nasync function resolveViaManifest(\n packageDir: string,\n subpath: string,\n): Promise<string | null> {\n let raw: string;\n try {\n raw = await readFile(path.join(packageDir, \"package.json\"), \"utf8\");\n } catch {\n return null;\n }\n let manifest: { exports?: unknown; main?: unknown };\n try {\n manifest = JSON.parse(raw) as { exports?: unknown; main?: unknown };\n } catch {\n return null;\n }\n\n let entry: unknown;\n const exportsField = manifest.exports;\n if (\n exportsField !== null &&\n typeof exportsField === \"object\" &&\n !Array.isArray(exportsField)\n ) {\n const map = exportsField as Record<string, unknown>;\n const hasSubpathKeys = Object.keys(map).some((key) => key.startsWith(\".\"));\n entry = hasSubpathKeys ? map[subpath] : subpath === \".\" ? map : undefined;\n } else if (typeof exportsField === \"string\" && subpath === \".\") {\n entry = exportsField;\n }\n\n let target = pickImportTarget(entry);\n if (!target && subpath === \".\" && typeof manifest.main === \"string\") {\n target = manifest.main;\n }\n if (!target) {\n return null;\n }\n const resolved = path.join(packageDir, target);\n return existsSync(resolved) ? resolved : null;\n}\n\nfunction pickImportTarget(entry: unknown): string | null {\n if (typeof entry === \"string\") {\n return entry;\n }\n if (typeof entry !== \"object\" || entry === null) {\n return null;\n }\n const conditions = entry as Record<string, unknown>;\n for (const condition of [\"import\", \"node\", \"default\"]) {\n const value = conditions[condition];\n if (typeof value === \"string\") {\n return value;\n }\n }\n return null;\n}\n\nfunction isFsPath(identifier: string): boolean {\n return (\n path.isAbsolute(identifier) ||\n identifier.startsWith(\"./\") ||\n identifier.startsWith(\"../\")\n );\n}\n\nexport function parseWorkerCount(\n raw: string | undefined,\n): WorkerCountInput | undefined {\n if (raw === undefined || raw.trim() === \"\") {\n return undefined;\n }\n if (raw.trim().toLowerCase() === \"auto\") {\n return \"auto\";\n }\n const value = Number.parseInt(raw, 10);\n if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) {\n throw new Error(\n `REACTOR_WORKERS must be \"auto\" or a non-negative integer, got \"${raw}\"`,\n );\n }\n return value;\n}\n"],"names":[],"mappings":";;;;;;;;;AAAA,SAAgB,oBACd,KACA,MACoB;CACpB,IAAI,QAAQ,KAAA,KAAa,IAAI,KAAK,MAAM,IACtC;CAEF,MAAM,QAAQ,OAAO,SAAS,KAAK,EAAE;CACrC,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,KAAK,OAAO,KAAK,MAAM,IAAI,KAAK,GACtE,MAAM,IAAI,MAAM,GAAG,KAAK,wCAAwC,IAAI,EAAE;CAExE,OAAO;AACT;;;;ACEA,SAAgB,eACd,QACA,KACoB;CACpB,OACE,UAAU,IAAI,2BAA2B,IAAI;AAEjD;AAEA,SAAgB,uBACd,OAIoB;CACpB,IACE,MAAM,UAAU,KAChB,MAAM,mBACN,MAAM,iBAAiB,QAEvB,OACE;AASN;;AAGA,SAAgB,iBAAiB,OAAuC;CACtE,IAAI,MAAM,WAAW,GAAG,OAAO,CAAC;CAChC,MAAM,SAAmB,CAAC;CAC1B,IAAI,MAAM,KACR,OAAO,KACL,4IACF;CAEF,MAAM,QAAQ,uBAAuB,KAAK;CAC1C,IAAI,OAAO,OAAO,KAAK,KAAK;CAC5B,IAAI,CAAC,MAAM,gBAAgB,CAAC,cAAc,MAAM,YAAY,GAC1D,OAAO,KACL,8LACF;CAEF,OAAO;AACT;;AAGA,SAAgB,uBACd,OACU;CACV,MAAM,SAAmB,CAAC;CAC1B,IAAI,MAAM,KACR,OAAO,KACL,mJACF;CAEF,IAAI,CAAC,MAAM,gBAAgB,CAAC,cAAc,MAAM,YAAY,GAC1D,OAAO,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,KAAK,KAAK,QAAQ,KAAK,OAAO,KAAK,MAAM,IAAI,KAAK,GACtE,MAAM,IAAI,MACR,kEAAkE,IAAI,EACxE;CAEF,OAAO;AACT","debug_id":"eca2a0ad-1b80-50e5-a2e3-272987fbba5e"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-runtime-7GaJ13c9.d.mts","names":[],"sources":["../src/workflow-runtime.mts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"workflow-runtime-7GaJ13c9.d.mts","names":[],"sources":["../src/workflow-runtime.mts"],"mappings":";;;;;;;;;KA8DY;EACN;;EAEA;EACA;;UAqPW;EACf,UAAU;;;WAGD,UAAU;;;EAGnB;EACA,SAAS;EACT,QAAQ"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="14c2a5a9-4d66-5303-8503-d50a9ebe5779")}catch(e){}}();
|
|
3
3
|
import { REACTOR_SCHEMA, supportsLiveReadModelRegistration } from "@powerhousedao/reactor";
|
|
4
4
|
import { AuthorizationPolicy, BaseSubgraph, ForbiddenError, callerSubject, createCanonicalDocumentIdResolver } from "@powerhousedao/reactor-api";
|
|
5
|
-
import { parseRef } from "@powerhousedao/reactor-attachments";
|
|
6
5
|
import { z } from "zod";
|
|
6
|
+
import { parseRef } from "@powerhousedao/reactor-attachments";
|
|
7
7
|
import { GraphQLError, Kind } from "graphql";
|
|
8
8
|
import { gql } from "graphql-tag";
|
|
9
9
|
//#region src/fatal-shutdown.mts
|
|
@@ -922,21 +922,10 @@ function createWorkflowRuntimeSubgraph(runtime, oauth, access) {
|
|
|
922
922
|
/** The npm name the workflow package owns: its HTTP namespace and its models. */
|
|
923
923
|
const WORKFLOW_PACKAGE_NAME = "@powerhousedao/workflow";
|
|
924
924
|
const WORKFLOW_TELEMETRY_SCOPE = "@powerhousedao/reactor-workflow";
|
|
925
|
-
/** The env var and OpenFeature flag key that turns workflows on. */
|
|
926
|
-
const PH_WORKFLOWS_ENABLED = "PH_WORKFLOWS_ENABLED";
|
|
927
925
|
const SINGLETON_LOST = {
|
|
928
926
|
status: "unavailable",
|
|
929
927
|
reason: "workflow-singleton-lost"
|
|
930
928
|
};
|
|
931
|
-
/** Precedence, unchanged from the reactor-api resolver this replaces: the
|
|
932
|
-
* host's option, then PH_WORKFLOWS_ENABLED, then the config file, then off. */
|
|
933
|
-
async function resolveWorkflowsEnabled({ featureFlags, override, configEnabled = false, env = process.env }) {
|
|
934
|
-
if (override !== void 0) return override;
|
|
935
|
-
const raw = env[PH_WORKFLOWS_ENABLED]?.trim();
|
|
936
|
-
if (raw === "1") return true;
|
|
937
|
-
if (raw === "0") return false;
|
|
938
|
-
return featureFlags.getBooleanValue(PH_WORKFLOWS_ENABLED, configEnabled);
|
|
939
|
-
}
|
|
940
929
|
async function assertWorkflowPackageLoadable(load = () => import("@powerhousedao/workflow/document-models")) {
|
|
941
930
|
try {
|
|
942
931
|
await load();
|
|
@@ -1376,7 +1365,7 @@ function createWorkflowsPlugin(rawConfig = {}) {
|
|
|
1376
1365
|
/** The default-config instance: the built-in composition's entry. */
|
|
1377
1366
|
const workflowsPlugin = createWorkflowsPlugin({});
|
|
1378
1367
|
//#endregion
|
|
1379
|
-
export {
|
|
1368
|
+
export { workflowsPlugin as a, WORKFLOW_TELEMETRY_SCOPE as c, isWorkflowSingletonConflict as d, modelManifestSource as f, triggerFatalShutdown as g, installFatalErrorShutdown as h, workflowsDriveDeclaration as i, assertWorkflowPackageLoadable as l, workflowSingletonLossHandler as m, WORKFLOW_STUDIO_EDITOR_ID as n, workflowsPluginConfigSchema as o, retryWorkflowSingleton as p, createWorkflowsPlugin as r, WORKFLOW_PACKAGE_NAME as s, DEFAULT_WORKFLOWS_DRIVE as t, composeWorkflowRuntime as u };
|
|
1380
1369
|
|
|
1381
|
-
//# sourceMappingURL=workflows-
|
|
1382
|
-
//# debugId=
|
|
1370
|
+
//# sourceMappingURL=workflows-QY9Y2eoD.mjs.map
|
|
1371
|
+
//# debugId=14c2a5a9-4d66-5303-8503-d50a9ebe5779
|