@powerhousedao/switchboard 6.2.3-dev.72 → 6.2.3-dev.74
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-env-isolation.test.d.ts +2 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +32 -0
- package/dist/boot.d.mts +38 -0
- package/dist/boot.d.mts.map +1 -0
- package/dist/boot.mjs +61 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/index.mjs +5 -4
- package/dist/index.mjs.map +1 -1
- package/dist/migrate.mjs +4 -3
- package/dist/migrate.mjs.map +1 -1
- package/dist/plugins/attachments.mjs +3 -3
- package/dist/postgres-url-DTDhBjXX.mjs +11 -0
- package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
- package/dist/reactor-feature-flags-BVu9wggF.mjs +324 -0
- package/dist/reactor-feature-flags-BVu9wggF.mjs.map +1 -0
- package/dist/{server-CrWPtMG6.mjs → server-nRWFjnu3.mjs} +23 -309
- package/dist/server-nRWFjnu3.mjs.map +1 -0
- package/dist/server.d.mts +1 -1
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +3 -3
- package/dist/{utils-Dh845exv.mjs → utils-CTtD7Oti.mjs} +5 -8
- package/dist/{utils-Dh845exv.mjs.map → utils-CTtD7Oti.mjs.map} +1 -1
- package/dist/utils.d.mts +3 -1
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +4 -3
- package/package.json +21 -16
- package/test/boot-env-isolation.test.ts +26 -0
- package/test/boot-preconditions.test.ts +149 -0
- package/test/renown-storage-path.test.ts +39 -0
- package/test/renown-trust-policy.test.ts +7 -9
- package/tsdown.config.ts +1 -0
- package/dist/server-CrWPtMG6.mjs.map +0 -1
|
@@ -1,18 +1,21 @@
|
|
|
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]="21f643cb-36c9-5be5-b3f0-cd0b3b534ccd")}catch(e){}}();
|
|
3
3
|
import { _ as triggerFatalShutdown, a as workflowsPlugin, c as WORKFLOW_TELEMETRY_SCOPE, d as isWorkflowSingletonConflict, f as modelManifestSource, g as installFatalErrorShutdown, h as workflowSingletonLossHandler, l as assertWorkflowPackageLoadable, m as retryWorkflowSingleton, p as resolveWorkflowsEnabled, s as WORKFLOW_PACKAGE_NAME, u as composeWorkflowRuntime } from "./workflows-fsBcElEi.mjs";
|
|
4
4
|
import { i as startPrivacy, r as resolvePrivacy, t as privacyPlugin } from "./privacy-BsFl7GzK.mjs";
|
|
5
5
|
import { t as mcpPlugin } from "./mcp-SsBK14Jm.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { t as isPostgresUrl } from "./postgres-url-DTDhBjXX.mjs";
|
|
7
|
+
import { a as resolveWorkerModelSources, c as resolveProjectionWorkerOptions, d as reactorDbUrlOf, i as resolveHostPoolSize, l as parseNonNegativeInt, n as buildWorkerDbConfig, o as resolveWorkerPoolOptions, p as workerPoolIssues, r as keepImportableSources, s as assertProjectionWorkerSupported, t as resolveReactorFeatureFlags } from "./reactor-feature-flags-BVu9wggF.mjs";
|
|
8
|
+
import { n as addDefaultReactorDrive, t as addDefaultDrive } from "./utils-CTtD7Oti.mjs";
|
|
7
9
|
import { createRequire, register } from "node:module";
|
|
8
10
|
import { metrics, trace } from "@opentelemetry/api";
|
|
9
11
|
import { ReactorInstrumentation } from "@powerhousedao/opentelemetry-instrumentation-reactor";
|
|
10
12
|
import * as Sentry from "@sentry/node";
|
|
11
13
|
import { childLogger, setLogLevel } from "document-model";
|
|
12
14
|
import dotenv from "dotenv";
|
|
15
|
+
import { isDotenvDisabled } from "@powerhousedao/shared/clis/project-env";
|
|
13
16
|
import { getConfig } from "@powerhousedao/config/node";
|
|
14
|
-
import fs, {
|
|
15
|
-
import path, { resolve } from "node:path";
|
|
17
|
+
import fs, { promises } from "node:fs";
|
|
18
|
+
import path, { join, resolve } from "node:path";
|
|
16
19
|
import { createDurableNodeFs, preparePgliteDataDir, removeStalePgliteFiles, resolvePgliteFsync, syncTree } from "@powerhousedao/reactor-api/pglite-node";
|
|
17
20
|
import { ChannelScheme, DriveCollectionId, EventBus, HardenedPGliteDialect, IN_MEMORY_PGLITE_STORAGE_FACTS, PGLITE_PATH_STORAGE_FACTS, POSTGRES_STORAGE_FACTS, REACTOR_SCHEMA, ReactorBuilder, ReactorClientBuilder, UnsupportedStoredProtocolError, createHybridProjectionCoordinatorFactory, instrumentPgPool, parseDriveUrl, supportsLiveReadModelRegistration } from "@powerhousedao/reactor";
|
|
18
21
|
import { HttpPackageLoader, ImportPackageLoader, PGLITE_UTC_PARSERS, PackageManagementService, PackagesSubgraph, baseDocumentModels, getUniqueDocumentModels, initializeAndStartAPI, reportFailure, resolveRenownConfig, runDetached } from "@powerhousedao/reactor-api";
|
|
@@ -30,12 +33,9 @@ import { Readable } from "node:stream";
|
|
|
30
33
|
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
31
34
|
import { z } from "zod";
|
|
32
35
|
import { mergeContributions, resolveOrder, runObserveHook, runObserveHookSequential, runTransformHook } from "@powerhousedao/host-core";
|
|
33
|
-
import { DEFAULT_SIGNATURE_POLICY, isSignaturePolicy } from "@powerhousedao/shared/document-model";
|
|
34
|
-
import { readFile } from "node:fs/promises";
|
|
35
|
-
import os from "node:os";
|
|
36
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
37
36
|
import { EnvVarProvider } from "@openfeature/env-var-provider";
|
|
38
37
|
import { OpenFeature } from "@openfeature/server-sdk";
|
|
38
|
+
import { DEFAULT_SIGNATURE_POLICY, isSignaturePolicy } from "@powerhousedao/shared/document-model";
|
|
39
39
|
import { defaultStoreDirs, resolvePhDir } from "@powerhousedao/shared/clis/ph-dir";
|
|
40
40
|
//#region src/pglite-version.ts
|
|
41
41
|
const SUPPORTED_PG_MAJORS = [16, 17];
|
|
@@ -1033,269 +1033,6 @@ function createSwitchboardPluginHost(ctx, resolved) {
|
|
|
1033
1033
|
};
|
|
1034
1034
|
}
|
|
1035
1035
|
//#endregion
|
|
1036
|
-
//#region src/env.mts
|
|
1037
|
-
function parseNonNegativeInt(raw, name) {
|
|
1038
|
-
if (raw === void 0 || raw.trim() === "") return;
|
|
1039
|
-
const value = Number.parseInt(raw, 10);
|
|
1040
|
-
if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) throw new Error(`${name} must be a non-negative integer, got "${raw}"`);
|
|
1041
|
-
return value;
|
|
1042
|
-
}
|
|
1043
|
-
//#endregion
|
|
1044
|
-
//#region src/projection-worker.mts
|
|
1045
|
-
const DEFAULT_DB_POOL_SIZE_PROJECTION = 8;
|
|
1046
|
-
const ON_TOKENS = [
|
|
1047
|
-
"1",
|
|
1048
|
-
"true",
|
|
1049
|
-
"on",
|
|
1050
|
-
"yes"
|
|
1051
|
-
];
|
|
1052
|
-
const OFF_TOKENS = [
|
|
1053
|
-
"0",
|
|
1054
|
-
"false",
|
|
1055
|
-
"off",
|
|
1056
|
-
"no"
|
|
1057
|
-
];
|
|
1058
|
-
/**
|
|
1059
|
-
* Enabled by REACTOR_PROJECTION_WORKER (1/true/on/yes, case-insensitive) or
|
|
1060
|
-
* `input.enabled`, which wins when defined; null when off (the default).
|
|
1061
|
-
*/
|
|
1062
|
-
function resolveProjectionWorkerOptions(input, env) {
|
|
1063
|
-
if (!(input?.enabled ?? parseOnOff(env.REACTOR_PROJECTION_WORKER) ?? false)) return null;
|
|
1064
|
-
const dbPoolSize = input?.dbPoolSize ?? parseNonNegativeInt(env.REACTOR_DB_POOL_SIZE_PROJECTION, "REACTOR_DB_POOL_SIZE_PROJECTION") ?? DEFAULT_DB_POOL_SIZE_PROJECTION;
|
|
1065
|
-
if (dbPoolSize < 1) throw new Error("REACTOR_DB_POOL_SIZE_PROJECTION must be at least 1; the projection worker cannot run without a pool");
|
|
1066
|
-
return { dbPoolSize };
|
|
1067
|
-
}
|
|
1068
|
-
/** Same preconditions as the executor worker pool; message shape mirrors server.mts. */
|
|
1069
|
-
function assertProjectionWorkerSupported(args) {
|
|
1070
|
-
if (args.dev) throw new Error("The projection worker (REACTOR_PROJECTION_WORKER) is not supported in dev mode: Vite-loaded document models cannot cross a worker-thread boundary");
|
|
1071
|
-
if (!args.reactorDbUrl || !isPostgresUrl(args.reactorDbUrl)) throw new Error("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.");
|
|
1072
|
-
}
|
|
1073
|
-
function parseOnOff(raw) {
|
|
1074
|
-
if (raw === void 0 || raw.trim() === "") return;
|
|
1075
|
-
const token = raw.trim().toLowerCase();
|
|
1076
|
-
if (ON_TOKENS.includes(token)) return true;
|
|
1077
|
-
if (OFF_TOKENS.includes(token)) return false;
|
|
1078
|
-
throw new Error(`REACTOR_PROJECTION_WORKER must be one of 1, true, on, yes, 0, false, off, no, got "${raw}"`);
|
|
1079
|
-
}
|
|
1080
|
-
//#endregion
|
|
1081
|
-
//#region src/worker-pool.mts
|
|
1082
|
-
const DEFAULT_DB_POOL_SIZE_PER_WORKER = 2;
|
|
1083
|
-
const DEFAULT_ACQUIRE_TIMEOUT_MS = 5e3;
|
|
1084
|
-
const DEFAULT_DB_POOL_SIZE_HOST = 16;
|
|
1085
|
-
const AUTO_RESERVED_CORES = 2;
|
|
1086
|
-
const AUTO_WORKER_CAP = 8;
|
|
1087
|
-
/** Worker count for "auto": always at least 1 — auto sizes the pool, it does not turn worker mode off. */
|
|
1088
|
-
function autoWorkerCount(availableCores) {
|
|
1089
|
-
return Math.max(1, Math.min(AUTO_WORKER_CAP, availableCores - AUTO_RESERVED_CORES));
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
1092
|
-
* Effective worker-pool config from programmatic options (which win) and the
|
|
1093
|
-
* REACTOR_* env vars; null when disabled (numWorkers 0, the default).
|
|
1094
|
-
* `"auto"` sizes the pool from the machine's available cores.
|
|
1095
|
-
*/
|
|
1096
|
-
function resolveWorkerPoolOptions(input, env, availableCores = os.availableParallelism()) {
|
|
1097
|
-
const requested = input?.numWorkers ?? parseWorkerCount(env.REACTOR_WORKERS) ?? 0;
|
|
1098
|
-
const mode = requested === "auto" ? "auto" : "explicit";
|
|
1099
|
-
const numWorkers = requested === "auto" ? autoWorkerCount(availableCores) : requested;
|
|
1100
|
-
if (!Number.isInteger(numWorkers) || numWorkers < 0) throw new Error(`workerPool.numWorkers must be "auto" or a non-negative integer, got ${numWorkers}`);
|
|
1101
|
-
if (numWorkers === 0) return null;
|
|
1102
|
-
return {
|
|
1103
|
-
numWorkers,
|
|
1104
|
-
mode,
|
|
1105
|
-
dbPoolSizePerWorker: input?.dbPoolSizePerWorker ?? parseNonNegativeInt(env.REACTOR_DB_POOL_SIZE_WORKER, "REACTOR_DB_POOL_SIZE_WORKER") ?? DEFAULT_DB_POOL_SIZE_PER_WORKER,
|
|
1106
|
-
acquireTimeoutMs: input?.acquireTimeoutMs ?? parseNonNegativeInt(env.REACTOR_DB_ACQUIRE_TIMEOUT_MS, "REACTOR_DB_ACQUIRE_TIMEOUT_MS") ?? DEFAULT_ACQUIRE_TIMEOUT_MS
|
|
1107
|
-
};
|
|
1108
|
-
}
|
|
1109
|
-
/**
|
|
1110
|
-
* Size of the reactor's own (host) Postgres pool. Unlike the worker pool there
|
|
1111
|
-
* is no "disabled" state — the host pool is the only Postgres pool in the
|
|
1112
|
-
* server path, backing both reactor storage and the read models that reach it
|
|
1113
|
-
* via `withSchema` — so 0 is rejected rather than read as "off".
|
|
1114
|
-
*
|
|
1115
|
-
* The acquire timeout is deliberately not configurable here: the host pool
|
|
1116
|
-
* waits indefinitely today, and making it finite converts saturation from a
|
|
1117
|
-
* latency problem into a thrown error on the read-model path. That is a
|
|
1118
|
-
* behavior change worth making separately, once the retry semantics of a
|
|
1119
|
-
* rejected `pool.connect()` inside the read-model coordinator are settled.
|
|
1120
|
-
*/
|
|
1121
|
-
function resolveHostPoolSize(env) {
|
|
1122
|
-
const poolSize = parseNonNegativeInt(env.REACTOR_DB_POOL_SIZE_HOST, "REACTOR_DB_POOL_SIZE_HOST") ?? DEFAULT_DB_POOL_SIZE_HOST;
|
|
1123
|
-
if (poolSize < 1) throw new Error("REACTOR_DB_POOL_SIZE_HOST must be at least 1; the host pool cannot be disabled");
|
|
1124
|
-
return poolSize;
|
|
1125
|
-
}
|
|
1126
|
-
/**
|
|
1127
|
-
* DbConfig for each worker's own pool, parsed from a postgres:// URL.
|
|
1128
|
-
* Explicit host, database, and user are required — no pg-side defaults.
|
|
1129
|
-
*/
|
|
1130
|
-
function buildWorkerDbConfig(postgresUrl, options) {
|
|
1131
|
-
let parsed;
|
|
1132
|
-
try {
|
|
1133
|
-
parsed = new URL(postgresUrl);
|
|
1134
|
-
} catch {
|
|
1135
|
-
throw new Error(`Worker pool requires a valid postgres:// URL for the reactor database, got "${postgresUrl}"`);
|
|
1136
|
-
}
|
|
1137
|
-
const database = decodeURIComponent(parsed.pathname.replace(/^\//, ""));
|
|
1138
|
-
if (!parsed.hostname || !database) throw new Error(`Worker pool requires a postgres URL with a host and database name, got "${postgresUrl}"`);
|
|
1139
|
-
if (!parsed.username) throw new Error(`Worker pool requires explicit credentials in the postgres URL (workers open their own connections), got "${postgresUrl}"`);
|
|
1140
|
-
const sslmode = parsed.searchParams.get("sslmode");
|
|
1141
|
-
const ssl = parsed.searchParams.get("ssl") === "true" || sslmode !== null && sslmode !== "disable";
|
|
1142
|
-
return {
|
|
1143
|
-
host: parsed.hostname,
|
|
1144
|
-
port: parsed.port ? Number(parsed.port) : 5432,
|
|
1145
|
-
database,
|
|
1146
|
-
user: decodeURIComponent(parsed.username),
|
|
1147
|
-
password: decodeURIComponent(parsed.password),
|
|
1148
|
-
ssl,
|
|
1149
|
-
applicationName: "switchboard-worker",
|
|
1150
|
-
poolSize: options.dbPoolSizePerWorker,
|
|
1151
|
-
connectionTimeoutMillis: options.acquireTimeoutMs
|
|
1152
|
-
};
|
|
1153
|
-
}
|
|
1154
|
-
/** Specifiers of the base models switchboard always registers. */
|
|
1155
|
-
const BASE_MODEL_SPECIFIERS = [
|
|
1156
|
-
"document-model",
|
|
1157
|
-
"@powerhousedao/shared/document-drive",
|
|
1158
|
-
"@powerhousedao/reactor-drive",
|
|
1159
|
-
"@powerhousedao/reactor-group/document-models"
|
|
1160
|
-
];
|
|
1161
|
-
function isModelModule(value) {
|
|
1162
|
-
const candidate = value;
|
|
1163
|
-
return typeof candidate?.reducer === "function" && typeof candidate.documentModel?.global?.id === "string";
|
|
1164
|
-
}
|
|
1165
|
-
async function keepImportableSources(sources, logger) {
|
|
1166
|
-
const kept = [];
|
|
1167
|
-
for (const source of sources) try {
|
|
1168
|
-
const exports = await import(pathToFileURL(source.filePath).href);
|
|
1169
|
-
if (Object.values(exports).some(isModelModule)) kept.push(source);
|
|
1170
|
-
} catch (error) {
|
|
1171
|
-
logger.warn(`Worker model sources: "${source.filePath}" does not import, so workflow pieces will not see its models: ${String(error)}`);
|
|
1172
|
-
}
|
|
1173
|
-
return kept;
|
|
1174
|
-
}
|
|
1175
|
-
/**
|
|
1176
|
-
* Resolves base models and configured package identifiers to `{ filePath }`
|
|
1177
|
-
* sources for the reactor builder. Resolution to absolute paths happens here
|
|
1178
|
-
* because workers (and the builder) resolve bare specifiers from the reactor
|
|
1179
|
-
* package's own dependency context, which cannot see switchboard or project
|
|
1180
|
-
* packages. Unresolvable identifiers are skipped with a warning; the builder
|
|
1181
|
-
* fails the boot if a registered model ends up without an importable source.
|
|
1182
|
-
*/
|
|
1183
|
-
async function resolveWorkerModelSources(packages, logger, options = {}) {
|
|
1184
|
-
const sources = [];
|
|
1185
|
-
for (const identifier of [...BASE_MODEL_SPECIFIERS, ...packages]) {
|
|
1186
|
-
const filePath = await resolveModelModuleFile(identifier) ?? await resolveRemoteSafely(identifier, options.resolveRemote, logger);
|
|
1187
|
-
if (!filePath) {
|
|
1188
|
-
logger.warn(`Worker model sources: no importable document-models entry for "${identifier}", skipping`);
|
|
1189
|
-
continue;
|
|
1190
|
-
}
|
|
1191
|
-
sources.push({ filePath });
|
|
1192
|
-
}
|
|
1193
|
-
return sources;
|
|
1194
|
-
}
|
|
1195
|
-
async function resolveRemoteSafely(identifier, resolveRemote, logger) {
|
|
1196
|
-
if (!resolveRemote) return null;
|
|
1197
|
-
try {
|
|
1198
|
-
return await resolveRemote(identifier);
|
|
1199
|
-
} catch (error) {
|
|
1200
|
-
logger.warn(`Worker model sources: could not cache "${identifier}" from the registry: ${String(error)}`);
|
|
1201
|
-
return null;
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
/**
|
|
1205
|
-
* Absolute file path of a source's models barrel. Mirrors reactor-api's
|
|
1206
|
-
* import-resolver: import.meta.resolve, then the project's node_modules via
|
|
1207
|
-
* the package.json exports map / dist layout.
|
|
1208
|
-
*/
|
|
1209
|
-
async function resolveModelModuleFile(source) {
|
|
1210
|
-
if (isFsPath(source)) return resolveFromPackageDir(source, "./document-models");
|
|
1211
|
-
const specifier = BASE_MODEL_SPECIFIERS.includes(source) ? source : `${source}/document-models`;
|
|
1212
|
-
try {
|
|
1213
|
-
const resolved = import.meta.resolve(specifier);
|
|
1214
|
-
if (resolved.startsWith("file:")) return fileURLToPath(resolved);
|
|
1215
|
-
} catch {}
|
|
1216
|
-
const { packageName, subpath } = splitSpecifier(specifier);
|
|
1217
|
-
const packageDir = path.join(process.cwd(), "node_modules", packageName);
|
|
1218
|
-
if (!existsSync(packageDir)) return null;
|
|
1219
|
-
let realDir;
|
|
1220
|
-
try {
|
|
1221
|
-
realDir = realpathSync(packageDir);
|
|
1222
|
-
} catch {
|
|
1223
|
-
return null;
|
|
1224
|
-
}
|
|
1225
|
-
return resolveFromPackageDir(realDir, subpath);
|
|
1226
|
-
}
|
|
1227
|
-
function splitSpecifier(specifier) {
|
|
1228
|
-
const parts = specifier.split("/");
|
|
1229
|
-
const packageSegments = specifier.startsWith("@") ? 2 : 1;
|
|
1230
|
-
const packageName = parts.slice(0, packageSegments).join("/");
|
|
1231
|
-
const rest = parts.slice(packageSegments).join("/");
|
|
1232
|
-
return {
|
|
1233
|
-
packageName,
|
|
1234
|
-
subpath: rest ? `./${rest}` : "."
|
|
1235
|
-
};
|
|
1236
|
-
}
|
|
1237
|
-
/** Exports-map lookup (import condition), then conventional dist paths. */
|
|
1238
|
-
async function resolveFromPackageDir(packageDir, subpath) {
|
|
1239
|
-
const fromManifest = await resolveViaManifest(packageDir, subpath);
|
|
1240
|
-
if (fromManifest) return fromManifest;
|
|
1241
|
-
const candidates = subpath === "." ? [path.join(packageDir, "dist", "index.js")] : [
|
|
1242
|
-
path.join(packageDir, "dist", subpath.slice(2), "index.js"),
|
|
1243
|
-
path.join(packageDir, "dist", `${subpath.slice(2)}.js`),
|
|
1244
|
-
path.join(packageDir, subpath.slice(2), "index.js")
|
|
1245
|
-
];
|
|
1246
|
-
for (const candidate of candidates) if (existsSync(candidate)) return candidate;
|
|
1247
|
-
return null;
|
|
1248
|
-
}
|
|
1249
|
-
async function resolveViaManifest(packageDir, subpath) {
|
|
1250
|
-
let raw;
|
|
1251
|
-
try {
|
|
1252
|
-
raw = await readFile(path.join(packageDir, "package.json"), "utf8");
|
|
1253
|
-
} catch {
|
|
1254
|
-
return null;
|
|
1255
|
-
}
|
|
1256
|
-
let manifest;
|
|
1257
|
-
try {
|
|
1258
|
-
manifest = JSON.parse(raw);
|
|
1259
|
-
} catch {
|
|
1260
|
-
return null;
|
|
1261
|
-
}
|
|
1262
|
-
let entry;
|
|
1263
|
-
const exportsField = manifest.exports;
|
|
1264
|
-
if (exportsField !== null && typeof exportsField === "object" && !Array.isArray(exportsField)) {
|
|
1265
|
-
const map = exportsField;
|
|
1266
|
-
entry = Object.keys(map).some((key) => key.startsWith(".")) ? map[subpath] : subpath === "." ? map : void 0;
|
|
1267
|
-
} else if (typeof exportsField === "string" && subpath === ".") entry = exportsField;
|
|
1268
|
-
let target = pickImportTarget(entry);
|
|
1269
|
-
if (!target && subpath === "." && typeof manifest.main === "string") target = manifest.main;
|
|
1270
|
-
if (!target) return null;
|
|
1271
|
-
const resolved = path.join(packageDir, target);
|
|
1272
|
-
return existsSync(resolved) ? resolved : null;
|
|
1273
|
-
}
|
|
1274
|
-
function pickImportTarget(entry) {
|
|
1275
|
-
if (typeof entry === "string") return entry;
|
|
1276
|
-
if (typeof entry !== "object" || entry === null) return null;
|
|
1277
|
-
const conditions = entry;
|
|
1278
|
-
for (const condition of [
|
|
1279
|
-
"import",
|
|
1280
|
-
"node",
|
|
1281
|
-
"default"
|
|
1282
|
-
]) {
|
|
1283
|
-
const value = conditions[condition];
|
|
1284
|
-
if (typeof value === "string") return value;
|
|
1285
|
-
}
|
|
1286
|
-
return null;
|
|
1287
|
-
}
|
|
1288
|
-
function isFsPath(identifier) {
|
|
1289
|
-
return path.isAbsolute(identifier) || identifier.startsWith("./") || identifier.startsWith("../");
|
|
1290
|
-
}
|
|
1291
|
-
function parseWorkerCount(raw) {
|
|
1292
|
-
if (raw === void 0 || raw.trim() === "") return;
|
|
1293
|
-
if (raw.trim().toLowerCase() === "auto") return "auto";
|
|
1294
|
-
const value = Number.parseInt(raw, 10);
|
|
1295
|
-
if (!Number.isInteger(value) || value < 0 || String(value) !== raw.trim()) throw new Error(`REACTOR_WORKERS must be "auto" or a non-negative integer, got "${raw}"`);
|
|
1296
|
-
return value;
|
|
1297
|
-
}
|
|
1298
|
-
//#endregion
|
|
1299
1036
|
//#region src/inspection-throttle.mts
|
|
1300
1037
|
const NAME = "PH_INSPECTION_CALLS_PER_MINUTE";
|
|
1301
1038
|
/** Unset keeps reactor-api's default; an invalid value fails boot. */
|
|
@@ -1540,26 +1277,6 @@ async function runPglitePreflight(options) {
|
|
|
1540
1277
|
return detectedMajors;
|
|
1541
1278
|
}
|
|
1542
1279
|
//#endregion
|
|
1543
|
-
//#region src/reactor-feature-flags.mts
|
|
1544
|
-
/**
|
|
1545
|
-
* Enforcement flags from the REACTOR_* env vars. Each flag requires the ones
|
|
1546
|
-
* before it; the reactor rejects an inconsistent set rather than enforcing less
|
|
1547
|
-
* than the operator asked for, so this reports what was asked without
|
|
1548
|
-
* correcting it.
|
|
1549
|
-
*/
|
|
1550
|
-
function resolveReactorFeatureFlags(env) {
|
|
1551
|
-
const flags = {
|
|
1552
|
-
documentDecisions: env.REACTOR_DOCUMENT_DECISIONS === "true",
|
|
1553
|
-
authEnforcement: env.REACTOR_AUTH_ENFORCEMENT === "true",
|
|
1554
|
-
authGroups: env.REACTOR_AUTH_GROUPS === "true",
|
|
1555
|
-
authConditions: env.REACTOR_AUTH_CONDITIONS === "true"
|
|
1556
|
-
};
|
|
1557
|
-
return {
|
|
1558
|
-
flags,
|
|
1559
|
-
enabled: Object.entries(flags).filter(([, isEnabled]) => isEnabled).map(([name]) => name)
|
|
1560
|
-
};
|
|
1561
|
-
}
|
|
1562
|
-
//#endregion
|
|
1563
1280
|
//#region src/create-signature-policy.mts
|
|
1564
1281
|
/**
|
|
1565
1282
|
* What new documents are created as, from CREATE_SIGNATURE_POLICY. Without a
|
|
@@ -1588,13 +1305,16 @@ const logger = childLogger(["switchboard", "renown"]);
|
|
|
1588
1305
|
* using the same identity established during `ph login`.
|
|
1589
1306
|
*/
|
|
1590
1307
|
async function initRenown(options = {}) {
|
|
1591
|
-
const { keypairPath, requireExisting = false, baseUrl = DEFAULT_RENOWN_URL } = options;
|
|
1308
|
+
const { keypairPath, requireExisting = false, baseUrl = DEFAULT_RENOWN_URL, storagePath = process.env.PH_USER_DATA_DIR ? join(resolvePhDir(), ".renown.json") : void 0 } = options;
|
|
1592
1309
|
const keyStorage = new NodeKeyStorage(keypairPath, { logger });
|
|
1593
1310
|
const existingKeyPair = await keyStorage.loadKeyPair();
|
|
1594
1311
|
if (!existingKeyPair && requireExisting) throw new Error("No existing keypair found and requireExisting is true. Run \"ph login\" to create one.");
|
|
1595
1312
|
if (!existingKeyPair) logger.info("No existing keypair found. A new one will be generated.");
|
|
1596
1313
|
const renownCrypto = await new RenownCryptoBuilder().withKeyPairStorage(keyStorage).build();
|
|
1597
|
-
const renown = await new RenownBuilder("switchboard", {
|
|
1314
|
+
const renown = await new RenownBuilder("switchboard", {
|
|
1315
|
+
...storagePath ? { storagePath } : {},
|
|
1316
|
+
...keypairPath ? { keyPath: keypairPath } : {}
|
|
1317
|
+
}).withCrypto(renownCrypto).withBaseUrl(baseUrl).build();
|
|
1598
1318
|
logger.info("Switchboard identity initialized: @did", renownCrypto.did);
|
|
1599
1319
|
return renown;
|
|
1600
1320
|
}
|
|
@@ -1671,14 +1391,6 @@ async function getRenownTrustPolicyConfig(trustSource, renown) {
|
|
|
1671
1391
|
}
|
|
1672
1392
|
};
|
|
1673
1393
|
}
|
|
1674
|
-
/**
|
|
1675
|
-
* Fails the boot when pooled workers would refuse every signed write the
|
|
1676
|
-
* in-process executor accepts: a `self` Renown source gives workers no trust
|
|
1677
|
-
* policy spec, so under authEnforcement they apply the default.
|
|
1678
|
-
*/
|
|
1679
|
-
function assertWorkerTrustPolicy(config) {
|
|
1680
|
-
if (config.workers > 0 && config.authEnforcement && config.renownSource === "self") throw new Error("The executor worker pool (REACTOR_WORKERS) cannot verify signers when REACTOR_AUTH_ENFORCEMENT is on and Renown credentials are read from this switchboard (\"self\" via auth.renown.source or RENOWN_SOURCE): pooled workers have no trust policy and would refuse every signed write. Set RENOWN_SOURCE=remote, or disable the worker pool (REACTOR_WORKERS=0).");
|
|
1681
|
-
}
|
|
1682
1394
|
function ownIdentity(renown) {
|
|
1683
1395
|
const key = renown?.signer.app?.key;
|
|
1684
1396
|
if (!key) return;
|
|
@@ -1780,7 +1492,7 @@ function acquireStoreLocks(dirs, isPidAlive = isAlive) {
|
|
|
1780
1492
|
const defaultLogger = childLogger(["switchboard"]);
|
|
1781
1493
|
const LogLevel = process.env.LOG_LEVEL || "info";
|
|
1782
1494
|
setLogLevel(LogLevel);
|
|
1783
|
-
dotenv.config();
|
|
1495
|
+
if (!isDotenvDisabled()) dotenv.config();
|
|
1784
1496
|
const DOCUMENT_MODEL_SUBGRAPHS_ENABLED = "DOCUMENT_MODEL_SUBGRAPHS_ENABLED";
|
|
1785
1497
|
const DOCUMENT_MODEL_SUBGRAPHS_ENABLED_DEFAULT = true;
|
|
1786
1498
|
const DEFAULT_PORT = process.env.PORT ? Number(process.env.PORT) : 4001;
|
|
@@ -1947,7 +1659,7 @@ async function initServer(serverPort, options, renown, renownConfig) {
|
|
|
1947
1659
|
}
|
|
1948
1660
|
logger.level = LogLevel;
|
|
1949
1661
|
const dbPath = options.dbPath ?? process.env.DATABASE_URL ?? process.env.PH_SWITCHBOARD_DATABASE_URL;
|
|
1950
|
-
const reactorDbUrl = options.dbPath
|
|
1662
|
+
const reactorDbUrl = reactorDbUrlOf(options.dbPath, process.env);
|
|
1951
1663
|
const { readModelPath, reactorPgliteDir, readModelPgliteDir, pgliteDirs, sharedPgliteDir } = resolvePgliteStorageDirs({
|
|
1952
1664
|
dbPath,
|
|
1953
1665
|
reactorDbUrl,
|
|
@@ -1979,13 +1691,15 @@ async function initServer(serverPort, options, renown, renownConfig) {
|
|
|
1979
1691
|
workerPool = null;
|
|
1980
1692
|
}
|
|
1981
1693
|
if (workerPool) {
|
|
1982
|
-
|
|
1983
|
-
|
|
1694
|
+
const issue = workerPoolIssues({
|
|
1695
|
+
dev: dev === true,
|
|
1984
1696
|
workers: workerPool.numWorkers,
|
|
1697
|
+
projectionWorker: false,
|
|
1698
|
+
reactorDbUrl,
|
|
1985
1699
|
authEnforcement: resolveReactorFeatureFlags(process.env).flags.authEnforcement === true,
|
|
1986
1700
|
renownSource: renownConfig.source
|
|
1987
|
-
});
|
|
1988
|
-
if (
|
|
1701
|
+
}).at(0);
|
|
1702
|
+
if (issue) throw new Error(issue);
|
|
1989
1703
|
}
|
|
1990
1704
|
const unsupportedStoredDocuments = resolveUnsupportedStoredDocuments(options.unsupportedStoredDocuments, process.env);
|
|
1991
1705
|
let projectionWorker = resolveProjectionWorkerOptions(options.projectionWorker, process.env);
|
|
@@ -2578,5 +2292,5 @@ if (import.meta.main) await startSwitchboard({ fatalErrorShutdown: true });
|
|
|
2578
2292
|
//#endregion
|
|
2579
2293
|
export { startSwitchboard as a, attachmentsPlugin as c, initProfilerFromEnv as d, parseForcePgVersion as f, resolvePgliteStorageDirs as i, attachmentsPluginConfigSchema as l, deriveAttachmentServiceConfig as n, StoredDocumentsRefusedError as o, isPortAvailable as r, resolveUnsupportedStoredDocuments as s, createReactorKysely as t, applySwitchboardReactorDefaults as u };
|
|
2580
2294
|
|
|
2581
|
-
//# sourceMappingURL=server-
|
|
2582
|
-
//# debugId=
|
|
2295
|
+
//# sourceMappingURL=server-nRWFjnu3.mjs.map
|
|
2296
|
+
//# debugId=21f643cb-36c9-5be5-b3f0-cd0b3b534ccd
|