@powerhousedao/ph-cli 6.2.3-dev.70 → 6.2.3-dev.71
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/{cli-connect-override-Cf7WutqU.mjs → cli-connect-override-CEJhQWRX.mjs} +5 -5
- package/dist/cli-connect-override-CEJhQWRX.mjs.map +1 -0
- package/dist/cli.mjs +4 -4
- package/dist/compound-B6RZMA0Y-Cv3XMQ3Y.mjs +2459 -0
- package/dist/compound-B6RZMA0Y-Cv3XMQ3Y.mjs.map +1 -0
- package/dist/{connect-build-BtKpvcQK.mjs → connect-build-BfhOGbha.mjs} +4 -4
- package/dist/{connect-build-BtKpvcQK.mjs.map → connect-build-BfhOGbha.mjs.map} +1 -1
- package/dist/{connect-config-9EZB_0H_.mjs → connect-config-DblqJgxR.mjs} +4 -4
- package/dist/{connect-config-9EZB_0H_.mjs.map → connect-config-DblqJgxR.mjs.map} +1 -1
- package/dist/connect-plugin-configs-D2fwYpMw.mjs +50 -0
- package/dist/connect-plugin-configs-D2fwYpMw.mjs.map +1 -0
- package/dist/{connect-studio-Bhlc77WI.mjs → connect-studio-DX7r4iyI.mjs} +5 -4
- package/dist/{connect-studio-Bhlc77WI.mjs.map → connect-studio-DX7r4iyI.mjs.map} +1 -1
- package/dist/{connect-studio-BehPZzN7.mjs → connect-studio-DmjcV8I2.mjs} +3 -3
- package/dist/{dist-BqeDFgEy.mjs → dist-CCLkwpTS.mjs} +199 -109
- package/dist/dist-CCLkwpTS.mjs.map +1 -0
- package/dist/explain-DUXbB9jf.mjs +241 -0
- package/dist/explain-DUXbB9jf.mjs.map +1 -0
- package/dist/{generate-all-C_sPGBuk.mjs → generate-all-Dgyy_kT-.mjs} +7 -3
- package/dist/generate-all-Dgyy_kT-.mjs.map +1 -0
- package/dist/{generate-desktop-shell-BBSGpmud.mjs → generate-desktop-shell-Bj_3bJDL.mjs} +112 -7
- package/dist/generate-desktop-shell-Bj_3bJDL.mjs.map +1 -0
- package/dist/generate-hosts-BFmPIW2X.mjs +18 -0
- package/dist/generate-hosts-BFmPIW2X.mjs.map +1 -0
- package/dist/generate-hosts-RWj7WPHZ.mjs +4 -0
- package/dist/{index-CspiP73o.d.mts → index-BIbx17vt.d.mts} +178 -14
- package/dist/index-BIbx17vt.d.mts.map +1 -0
- package/dist/ph-cli-commands-BhzvcuzR.mjs +4 -0
- package/dist/{ph-cli-commands-3ptdQ0NI.mjs → ph-cli-commands-pyxDifSE.mjs} +155 -138
- package/dist/ph-cli-commands-pyxDifSE.mjs.map +1 -0
- package/dist/{run-sugar-BdjKTPGO.mjs → run-sugar-Ns53R6lU.mjs} +4 -4
- package/dist/{run-sugar-BdjKTPGO.mjs.map → run-sugar-Ns53R6lU.mjs.map} +1 -1
- package/dist/runners/connect.d.mts +1054 -26
- package/dist/runners/connect.d.mts.map +1 -1
- package/dist/runners/connect.mjs +121 -49
- package/dist/runners/connect.mjs.map +1 -1
- package/dist/runners/switchboard.d.mts +170 -28
- package/dist/runners/switchboard.d.mts.map +1 -1
- package/dist/runners/switchboard.mjs +171 -49
- package/dist/runners/switchboard.mjs.map +1 -1
- package/dist/{schemas-BQSPev1x.mjs → schemas-D5N5U_Mf.mjs} +205 -4
- package/dist/{schemas-BQSPev1x.mjs.map → schemas-D5N5U_Mf.mjs.map} +1 -1
- package/dist/scripts/emit-runner-schemas.ts +24 -0
- package/dist/start-run-BIaYSpHh.mjs +124 -0
- package/dist/start-run-BIaYSpHh.mjs.map +1 -0
- package/dist/{superseded-config-9D7BdLvd.mjs → superseded-config-CbSTFun2.mjs} +4 -4
- package/dist/superseded-config-CbSTFun2.mjs.map +1 -0
- package/dist/switchboard-h4-XgP1h.mjs +2 -2
- package/dist/switchboard-h4-XgP1h.mjs.map +1 -1
- package/dist/utils-DAux4Ga7.mjs +4 -0
- package/dist/{vetra-BD-34wGs.mjs → vetra-CnrGDPX0.mjs} +10 -10
- package/dist/vetra-CnrGDPX0.mjs.map +1 -0
- package/package.json +15 -20
- package/dist/cli-connect-override-Cf7WutqU.mjs.map +0 -1
- package/dist/dist-BqeDFgEy.mjs.map +0 -1
- package/dist/explain-BDHmXgw3.mjs +0 -27
- package/dist/explain-BDHmXgw3.mjs.map +0 -1
- package/dist/generate-all-C_sPGBuk.mjs.map +0 -1
- package/dist/generate-desktop-shell-BBSGpmud.mjs.map +0 -1
- package/dist/host-schemas-CtPNRr5v-BQyKKFbS.mjs +0 -493
- package/dist/host-schemas-CtPNRr5v-BQyKKFbS.mjs.map +0 -1
- package/dist/index-CspiP73o.d.mts.map +0 -1
- package/dist/ph-cli-commands-3ptdQ0NI.mjs.map +0 -1
- package/dist/ph-cli-commands-Dx8hNj6W.mjs +0 -4
- package/dist/plugins-CHVv4qup.mjs +0 -91
- package/dist/plugins-CHVv4qup.mjs.map +0 -1
- package/dist/reactor-env-BbR86_Li.mjs +0 -29
- package/dist/reactor-env-BbR86_Li.mjs.map +0 -1
- package/dist/reactor-env-D_EvBtLB.mjs +0 -4
- package/dist/runners/compound.d.mts +0 -127
- package/dist/runners/compound.d.mts.map +0 -1
- package/dist/runners/compound.mjs +0 -72
- package/dist/runners/compound.mjs.map +0 -1
- package/dist/start-run-CmDxyMw0.mjs +0 -36
- package/dist/start-run-CmDxyMw0.mjs.map +0 -1
- package/dist/superseded-config-9D7BdLvd.mjs.map +0 -1
- package/dist/utils-TO9lB8Xs.mjs +0 -4
- package/dist/vetra-BD-34wGs.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
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 { c as validateConnectKeyValue, i as wasFlagExplicitlyPassed, l as validateConnectPatch, n as buildConnectFlagPatch, o as normalizeKey, s as parseCliValue } from "./cli-connect-override-
|
|
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]="76f1dd01-ea3d-5516-ac4f-ee1cdfd6a438")}catch(e){}}();
|
|
3
|
+
import { c as validateConnectKeyValue, i as wasFlagExplicitlyPassed, l as validateConnectPatch, n as buildConnectFlagPatch, o as normalizeKey, s as parseCliValue } from "./cli-connect-override-CEJhQWRX.mjs";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { isAbsolute, join, resolve } from "node:path";
|
|
6
6
|
import { ConfigLoader, JsonConfigAdapter, deepMerge, resolveSourceConnect } from "@powerhousedao/shared/connect";
|
|
@@ -192,5 +192,5 @@ async function runConnectConfig(args) {
|
|
|
192
192
|
//#endregion
|
|
193
193
|
export { runConnectConfig };
|
|
194
194
|
|
|
195
|
-
//# sourceMappingURL=connect-config-
|
|
196
|
-
//# debugId=
|
|
195
|
+
//# sourceMappingURL=connect-config-DblqJgxR.mjs.map
|
|
196
|
+
//# debugId=76f1dd01-ea3d-5516-ac4f-ee1cdfd6a438
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect-config-9EZB_0H_.mjs","sources":["../src/utils/get-at-path.ts","../src/services/connect-config.ts"],"sourcesContent":["/**\n * Walk a parsed path (e.g. from remeda's `stringToPath`) through a runtime-\n * typed object, returning the value or `undefined` if any segment is\n * missing.\n *\n * Remeda's `prop` is overload-typed for compile-time literal paths and\n * doesn't accept a runtime path array via spread, so we walk inline for\n * the dynamic-path case used by `ph connect config --get`.\n */\nexport function getAtPath(\n obj: unknown,\n parts: ReadonlyArray<string | number>,\n): unknown {\n let cur: unknown = obj;\n for (const key of parts) {\n if (cur === null || typeof cur !== \"object\") return undefined;\n cur = (cur as Record<string, unknown>)[String(key)];\n }\n return cur;\n}\n","// `ph connect config` — read or update Connect's runtime configuration.\n//\n// Mode dispatch (exactly one mode per invocation; mutex enforced below):\n//\n// ph connect config → list mode (print effective merged config)\n// ph connect config <key> → get mode (positional)\n// ph connect config --get <dotted.path> → get mode (flag form, equivalent)\n// ph connect config <key> <value> → set mode (positional, dual-write source + dist)\n// ph connect config --<field> <value> → set mode (flag form)\n// ph connect config --json '{...}' → bulk-set mode (dual-write)\n//\n// Dual-write semantics for set / bulk-set:\n// - Source `powerhouse.config.json` (project root) gets the connect.* patch\n// deep-merged into `connect.*`. `--packages-registry` lands at the\n// top-level `packageRegistryUrl` field (project-wide setting, also read\n// by `ph install` / `ph publish` / Switchboard).\n// - Dist `powerhouse.config.json` (default `.ph/connect-build/dist/`) gets\n// the same connect.* patch deep-merged in, and the same top-level\n// `packageRegistryUrl` if set. The runtime schema mirrors the source\n// schema, so the field lives at the same path in both files.\n//\n// The dist write is skipped silently if the dist file doesn't exist — that's\n// the \"config-only-before-first-build\" workflow, not an error.\n//\n// Field flags + the 4 commonArgs flags (base, log-level, default-drives-url,\n// drive-preserve-strategy) come from the same source as `ph connect build`'s\n// flags, so the two commands share identical CLI surfaces. The 4 commonArgs\n// flags carry cmd-ts defaults; we gate them through `wasFlagExplicitlyPassed`\n// for the same reason `buildCliConnectOverride` does — to avoid leaking\n// default values into a write the user didn't request.\n\nimport type {\n PHConnectRuntimeConfig,\n PowerhouseConfig,\n} from \"@powerhousedao/shared/clis\";\nimport {\n ConfigLoader,\n JsonConfigAdapter,\n deepMerge,\n resolveSourceConnect,\n} from \"@powerhousedao/shared/connect\";\nimport { existsSync } from \"node:fs\";\nimport { isAbsolute, join, resolve } from \"node:path\";\nimport { stringToPath } from \"remeda\";\nimport type { ConnectConfigArgs } from \"../types.js\";\nimport {\n buildConnectFlagPatch,\n wasFlagExplicitlyPassed,\n type ConnectFlagInput,\n} from \"../utils/cli-connect-override.js\";\nimport {\n normalizeKey,\n parseCliValue,\n validateConnectKeyValue,\n validateConnectPatch,\n} from \"../utils/connect-config-validation.js\";\nimport { getAtPath } from \"../utils/get-at-path.js\";\n\ntype ConnectPartial = Partial<PHConnectRuntimeConfig>;\n\nconst SOURCE_FILE = \"powerhouse.config.json\";\nconst DEFAULT_DIST_SUBPATH = \".ph/connect-build/dist\";\n\nfunction resolveSourcePath(cwd: string): string {\n return join(cwd, SOURCE_FILE);\n}\n\nfunction resolveDistPath(cwd: string, distDirArg: string | undefined): string {\n const fromArg = distDirArg;\n const fromEnv = process.env.PH_CONNECT_OUTDIR;\n const dir = fromArg ?? fromEnv ?? DEFAULT_DIST_SUBPATH;\n const abs = isAbsolute(dir) ? dir : resolve(cwd, dir);\n return join(abs, SOURCE_FILE);\n}\n\n/**\n * Read the source file's raw bytes (no merge with defaults). Returns an empty\n * object stub when the file doesn't exist — the operator can config their way\n * to a complete file before ever running `ph connect build`.\n */\nasync function readSourceRaw(path: string): Promise<Record<string, unknown>> {\n if (!existsSync(path)) return {};\n const adapter = new JsonConfigAdapter({ path });\n const raw = await adapter.read();\n return raw && typeof raw === \"object\" && !Array.isArray(raw)\n ? (raw as Record<string, unknown>)\n : {};\n}\n\nasync function writeSourceRaw(\n path: string,\n next: Record<string, unknown>,\n): Promise<void> {\n const adapter = new JsonConfigAdapter({ path });\n // ConfigShape requires a `connect` key; ensure it's present.\n const shape = {\n ...next,\n connect: (next.connect as PHConnectRuntimeConfig | undefined) ?? {},\n };\n await adapter.write(shape);\n}\n\n/**\n * Build the merged \"effective\" connect block for list/get mode: defaults <\n * source.workflows < source.connect. Doesn't go through env or dist — list\n * mode shows what the source declares + defaults, which is what the next\n * build will produce as a baseline (before env seeds + CLI overrides).\n */\nfunction effectiveConnect(\n source: Record<string, unknown>,\n): PHConnectRuntimeConfig {\n const sourceConnect =\n source.connect &&\n typeof source.connect === \"object\" &&\n !Array.isArray(source.connect)\n ? (source.connect as ConnectPartial)\n : {};\n return resolveSourceConnect({\n connect: sourceConnect,\n workflows: source.workflows as PowerhouseConfig[\"workflows\"],\n });\n}\n\nfunction printJson(value: unknown): void {\n process.stdout.write(`${JSON.stringify(value, null, 2)}\\n`);\n}\n\n/**\n * Translate the parsed `ph connect config` args into the structural\n * `ConnectFlagInput` consumed by `buildConnectFlagPatch`. Common-args flags\n * with cmd-ts defaults are gated through `wasFlagExplicitlyPassed` so the\n * defaults don't leak into a write the user didn't request. `--base` is\n * not translated here — it's rejected up front by `runConnectConfig`.\n */\nfunction argsToFlagInput(args: ConnectConfigArgs): ConnectFlagInput {\n return {\n renownUrl: args.renownUrl,\n renownNetworkId: args.renownNetworkId,\n renownChainId: args.renownChainId,\n renownNamespace: args.renownNamespace,\n renownSwitchboardUrl: args.renownSwitchboardUrl,\n allowAddDrive: args.allowAddDrive,\n externalPackages: args.externalPackages,\n workflows: args.workflows,\n remoteDrivesEnabled: args.remoteDrivesEnabled,\n remoteDrivesAllowAdd: args.remoteDrivesAllowAdd,\n remoteDrivesAllowDelete: args.remoteDrivesAllowDelete,\n localDrivesEnabled: args.localDrivesEnabled,\n localDrivesAllowAdd: args.localDrivesAllowAdd,\n localDrivesAllowDelete: args.localDrivesAllowDelete,\n appName: args.appName,\n homeBackground: args.homeBackground,\n sentryDsn: args.sentryDsn,\n sentryEnv: args.sentryEnv,\n sentryTracingEnabled: args.sentryTracingEnabled,\n logLevel: wasFlagExplicitlyPassed(\"log-level\") ? args.logLevel : undefined,\n defaultDrivesUrl: wasFlagExplicitlyPassed(\"default-drives-url\")\n ? args.defaultDrivesUrl\n : undefined,\n drivesPreserveStrategy: wasFlagExplicitlyPassed(\"drive-preserve-strategy\")\n ? args.drivesPreserveStrategy\n : undefined,\n };\n}\n\n/**\n * Whether any field flag (any of the 20) was passed. Distinguishes the\n * single-field-set mode from list mode when neither `--get` nor `--json` is\n * present.\n */\nfunction hasAnyFieldFlag(input: ConnectFlagInput): boolean {\n // Object.values doesn't include json (which isn't in ConnectFlagInput here).\n // Cast to a generic record so the `!== undefined` predicate is type-aware:\n // ConnectFlagInput's optional properties narrow `v` in a way TS thinks\n // excludes `undefined`, even though at runtime any of them can be unset.\n return Object.values(input as Record<string, unknown>).some(\n (v) => v !== undefined,\n );\n}\n\nexport async function runConnectConfig(args: ConnectConfigArgs): Promise<void> {\n // `--base` is a build-time field (baked into the Vite bundle's asset URLs\n // and the nginx config template), so writing it post-build leaves the\n // layers disagreeing and the SPA's assets 404. The flag stays declared so\n // cmd-ts parses it; we reject explicit use here with an actionable error.\n if (wasFlagExplicitlyPassed(\"base\")) {\n throw new Error(\n \"ph connect config: --base is a build-time field; run `ph connect build --base <value>` and redeploy the container (or restart with PH_CONNECT_BASE_PATH=<value> set in the environment).\",\n );\n }\n\n const cwd = process.cwd();\n const sourcePath = resolveSourcePath(cwd);\n const distPath = resolveDistPath(cwd, args.distDir);\n\n const flagInput = argsToFlagInput(args);\n const hasGet = args.get !== undefined;\n const hasJson = args.json !== undefined;\n const hasFieldFlag = hasAnyFieldFlag(flagInput);\n // `--packages-registry` is a top-level field, not part of the connect-flag\n // patch. Track it separately so the set-mode write puts it in the right\n // place and the mutex counts it as a \"field flag\".\n const explicitRegistry = args.packagesRegistry;\n const hasExplicitRegistry = explicitRegistry !== undefined;\n // Positional pair: 1 positional = get, 2 = set. cmd-ts assigns the first\n // positional to `keyPositional` and the second to `valuePositional`, so a\n // standalone <value> isn't representable here.\n const hasPositionalKey = args.keyPositional !== undefined;\n const hasPositionalValue = args.valuePositional !== undefined;\n const hasPositional = hasPositionalKey;\n\n // Mutex: positional / --get / --json / (any field flag OR\n // --packages-registry) are mutually exclusive. Exactly one mode (or none →\n // list) per call. Counting positional as a single mode regardless of arity:\n // a `<key>` alone is a get, `<key> <value>` is a set, both occupy the same\n // \"positional mode\" slot vs. the other forms.\n const modeCount = [\n hasPositional,\n hasGet,\n hasJson,\n hasFieldFlag || hasExplicitRegistry,\n ].filter(Boolean).length;\n if (modeCount > 1) {\n throw new Error(\n \"ph connect config: positional <key>/<value>, --get, --json, and individual field flags are mutually exclusive. Use one mode per invocation.\",\n );\n }\n\n const source = await readSourceRaw(sourcePath);\n\n // List mode.\n if (modeCount === 0) {\n printJson(effectiveConnect(source));\n return;\n }\n\n // Get mode (either positional `<key>` alone or `--get <key>`).\n if (hasGet || (hasPositional && !hasPositionalValue)) {\n const rawKey = hasGet ? args.get! : args.keyPositional!;\n const sourceLabel = hasGet ? \"--get\" : \"<key>\";\n const normalized = normalizeKey(rawKey);\n if (!normalized) {\n throw new Error(\n `ph connect config ${sourceLabel}: key cannot be empty. Pass a dotted path inside connect.* (e.g. connect.renown.url).`,\n );\n }\n // `packageRegistryUrl` is a top-level field — look it up on the raw\n // source object, not inside `effectiveConnect`.\n if (normalized === \"packageRegistryUrl\") {\n const value = source.packageRegistryUrl;\n if (value === undefined) {\n throw new Error(\n `ph connect config ${sourceLabel}: no value at key \"${normalized}\". Run \\`ph connect config\\` (no args) to see the available paths.`,\n );\n }\n printJson(value);\n return;\n }\n const value = getAtPath(effectiveConnect(source), stringToPath(normalized));\n if (value === undefined) {\n throw new Error(\n `ph connect config ${sourceLabel}: no value at key \"${normalized}\". Run \\`ph connect config\\` (no args) to see the available paths.`,\n );\n }\n printJson(value);\n return;\n }\n\n // Set / bulk-set mode. Build the connect-side patch from positional\n // `<key> <value>` (Ajv-validated against the schema at that path), --json\n // (Ajv-validated as a partial connect.* blob), or individual field flags\n // (shape guaranteed by cmd-ts type coercion). `--packages-registry` is a\n // top-level field; if positional `<key>` is `packageRegistryUrl` or --json\n // carries it, route that to the top-level write.\n let topLevelRegistry: string | undefined = explicitRegistry;\n let patch: ConnectPartial;\n if (hasPositional && hasPositionalValue) {\n const normalized = normalizeKey(args.keyPositional!);\n if (!normalized) {\n throw new Error(\n \"ph connect config <key>: key cannot be empty. Pass a dotted path inside connect.* (e.g. connect.renown.url).\",\n );\n }\n // Top-level: positional `packageRegistryUrl <value>` writes the top-level\n // field instead of a connect.* path.\n if (normalized === \"packageRegistryUrl\") {\n const parsed = parseCliValue(args.valuePositional!);\n if (typeof parsed !== \"string\") {\n throw new Error(\n `ph connect config: packageRegistryUrl must be a string (got ${typeof parsed}).`,\n );\n }\n topLevelRegistry = parsed;\n patch = {};\n } else {\n patch = validateConnectKeyValue(\n normalized,\n args.valuePositional!,\n ) as ConnectPartial;\n }\n } else if (hasJson) {\n const validated = validateConnectPatch(args.json!) as Record<\n string,\n unknown\n >;\n if (typeof validated.packageRegistryUrl === \"string\") {\n topLevelRegistry = topLevelRegistry ?? validated.packageRegistryUrl;\n }\n const connectOnly = { ...validated };\n delete connectOnly.packageRegistryUrl;\n patch = connectOnly as ConnectPartial;\n } else {\n patch = buildConnectFlagPatch(flagInput) as ConnectPartial;\n }\n\n if (Object.keys(patch).length === 0 && topLevelRegistry === undefined) {\n throw new Error(\n \"ph connect config: nothing to set. Pass at least one field flag (e.g. --renown-url <url>) or --json with a non-empty payload.\",\n );\n }\n\n // Build the next source: top-level packageRegistryUrl (if set) +\n // connect.* deep-merge.\n const currentConnect =\n source.connect &&\n typeof source.connect === \"object\" &&\n !Array.isArray(source.connect)\n ? (source.connect as PHConnectRuntimeConfig)\n : ({} as PHConnectRuntimeConfig);\n const nextConnect = deepMerge(\n currentConnect,\n patch as PHConnectRuntimeConfig,\n );\n const nextSource: Record<string, unknown> = {\n ...source,\n connect: nextConnect,\n };\n if (topLevelRegistry !== undefined) {\n nextSource.packageRegistryUrl = topLevelRegistry;\n }\n\n await writeSourceRaw(sourcePath, nextSource);\n\n // Dual-write to dist if it exists. Same shape as source: connect.* block\n // is deep-merged; top-level `packageRegistryUrl` is set in place.\n if (existsSync(distPath)) {\n const distLoader = new ConfigLoader(\n new JsonConfigAdapter({ path: distPath }),\n );\n const distPatch: Record<string, unknown> = { connect: patch };\n if (topLevelRegistry !== undefined) {\n distPatch.packageRegistryUrl = topLevelRegistry;\n }\n await distLoader.write(distPatch);\n }\n\n process.stdout.write(\n `ph connect config: wrote ${sourcePath}${existsSync(distPath) ? ` and ${distPath}` : \"\"}\\n`,\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AASA,SAAgB,UACd,KACA,OACS;CAC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MAAM,cAAc,EAAE,GAAG,UAAU;EACnC,OAAO,YAAY;EACnB,QAAQ;CACV,OACE,QAAQ,sBAAsB,SAAS;CAGzC,IAAI,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,KAAK,qBAAqB,KAAA,GAC1D,MAAM,IAAI,MACR,+HACF;CAKF,MAAM,iBACJ,OAAO,WACP,OAAO,OAAO,YAAY,YAC1B,CAAC,MAAM,QAAQ,OAAO,OAAO,IACxB,OAAO,UACP,CAAC;CACR,MAAM,cAAc,UAClB,gBACA,KACF;CACA,MAAM,aAAsC;EAC1C,GAAG;EACH,SAAS;CACX;CACA,IAAI,qBAAqB,KAAA,GACvB,WAAW,qBAAqB;CAGlC,MAAM,eAAe,YAAY,UAAU;CAI3C,IAAI,WAAW,QAAQ,GAAG;EACxB,MAAM,aAAa,IAAI,aACrB,IAAI,kBAAkB,EAAE,MAAM,SAAS,CAAC,CAC1C;EACA,MAAM,YAAqC,EAAE,SAAS,MAAM;EAC5D,IAAI,qBAAqB,KAAA,GACvB,UAAU,qBAAqB;EAEjC,MAAM,WAAW,MAAM,SAAS;CAClC;CAEA,QAAQ,OAAO,MACb,4BAA4B,aAAa,WAAW,QAAQ,IAAI,QAAQ,aAAa,GAAG,GAC1F;AACF","debug_id":"a7c5c922-bde7-558e-99eb-cb5ff7df3bdb"}
|
|
1
|
+
{"version":3,"file":"connect-config-DblqJgxR.mjs","sources":["../src/utils/get-at-path.ts","../src/services/connect-config.ts"],"sourcesContent":["/**\n * Walk a parsed path (e.g. from remeda's `stringToPath`) through a runtime-\n * typed object, returning the value or `undefined` if any segment is\n * missing.\n *\n * Remeda's `prop` is overload-typed for compile-time literal paths and\n * doesn't accept a runtime path array via spread, so we walk inline for\n * the dynamic-path case used by `ph connect config --get`.\n */\nexport function getAtPath(\n obj: unknown,\n parts: ReadonlyArray<string | number>,\n): unknown {\n let cur: unknown = obj;\n for (const key of parts) {\n if (cur === null || typeof cur !== \"object\") return undefined;\n cur = (cur as Record<string, unknown>)[String(key)];\n }\n return cur;\n}\n","// `ph connect config` — read or update Connect's runtime configuration.\n//\n// Mode dispatch (exactly one mode per invocation; mutex enforced below):\n//\n// ph connect config → list mode (print effective merged config)\n// ph connect config <key> → get mode (positional)\n// ph connect config --get <dotted.path> → get mode (flag form, equivalent)\n// ph connect config <key> <value> → set mode (positional, dual-write source + dist)\n// ph connect config --<field> <value> → set mode (flag form)\n// ph connect config --json '{...}' → bulk-set mode (dual-write)\n//\n// Dual-write semantics for set / bulk-set:\n// - Source `powerhouse.config.json` (project root) gets the connect.* patch\n// deep-merged into `connect.*`. `--packages-registry` lands at the\n// top-level `packageRegistryUrl` field (project-wide setting, also read\n// by `ph install` / `ph publish` / Switchboard).\n// - Dist `powerhouse.config.json` (default `.ph/connect-build/dist/`) gets\n// the same connect.* patch deep-merged in, and the same top-level\n// `packageRegistryUrl` if set. The runtime schema mirrors the source\n// schema, so the field lives at the same path in both files.\n//\n// The dist write is skipped silently if the dist file doesn't exist — that's\n// the \"config-only-before-first-build\" workflow, not an error.\n//\n// Field flags + the 4 commonArgs flags (base, log-level, default-drives-url,\n// drive-preserve-strategy) come from the same source as `ph connect build`'s\n// flags, so the two commands share identical CLI surfaces. The 4 commonArgs\n// flags carry cmd-ts defaults; we gate them through `wasFlagExplicitlyPassed`\n// for the same reason `buildCliConnectOverride` does — to avoid leaking\n// default values into a write the user didn't request.\n\nimport type {\n PHConnectRuntimeConfig,\n PowerhouseConfig,\n} from \"@powerhousedao/shared/clis\";\nimport {\n ConfigLoader,\n JsonConfigAdapter,\n deepMerge,\n resolveSourceConnect,\n} from \"@powerhousedao/shared/connect\";\nimport { existsSync } from \"node:fs\";\nimport { isAbsolute, join, resolve } from \"node:path\";\nimport { stringToPath } from \"remeda\";\nimport type { ConnectConfigArgs } from \"../types.js\";\nimport {\n buildConnectFlagPatch,\n wasFlagExplicitlyPassed,\n type ConnectFlagInput,\n} from \"../utils/cli-connect-override.js\";\nimport {\n normalizeKey,\n parseCliValue,\n validateConnectKeyValue,\n validateConnectPatch,\n} from \"../utils/connect-config-validation.js\";\nimport { getAtPath } from \"../utils/get-at-path.js\";\n\ntype ConnectPartial = Partial<PHConnectRuntimeConfig>;\n\nconst SOURCE_FILE = \"powerhouse.config.json\";\nconst DEFAULT_DIST_SUBPATH = \".ph/connect-build/dist\";\n\nfunction resolveSourcePath(cwd: string): string {\n return join(cwd, SOURCE_FILE);\n}\n\nfunction resolveDistPath(cwd: string, distDirArg: string | undefined): string {\n const fromArg = distDirArg;\n const fromEnv = process.env.PH_CONNECT_OUTDIR;\n const dir = fromArg ?? fromEnv ?? DEFAULT_DIST_SUBPATH;\n const abs = isAbsolute(dir) ? dir : resolve(cwd, dir);\n return join(abs, SOURCE_FILE);\n}\n\n/**\n * Read the source file's raw bytes (no merge with defaults). Returns an empty\n * object stub when the file doesn't exist — the operator can config their way\n * to a complete file before ever running `ph connect build`.\n */\nasync function readSourceRaw(path: string): Promise<Record<string, unknown>> {\n if (!existsSync(path)) return {};\n const adapter = new JsonConfigAdapter({ path });\n const raw = await adapter.read();\n return raw && typeof raw === \"object\" && !Array.isArray(raw)\n ? (raw as Record<string, unknown>)\n : {};\n}\n\nasync function writeSourceRaw(\n path: string,\n next: Record<string, unknown>,\n): Promise<void> {\n const adapter = new JsonConfigAdapter({ path });\n // ConfigShape requires a `connect` key; ensure it's present.\n const shape = {\n ...next,\n connect: (next.connect as PHConnectRuntimeConfig | undefined) ?? {},\n };\n await adapter.write(shape);\n}\n\n/**\n * Build the merged \"effective\" connect block for list/get mode: defaults <\n * source.workflows < source.connect. Doesn't go through env or dist — list\n * mode shows what the source declares + defaults, which is what the next\n * build will produce as a baseline (before env seeds + CLI overrides).\n */\nfunction effectiveConnect(\n source: Record<string, unknown>,\n): PHConnectRuntimeConfig {\n const sourceConnect =\n source.connect &&\n typeof source.connect === \"object\" &&\n !Array.isArray(source.connect)\n ? (source.connect as ConnectPartial)\n : {};\n return resolveSourceConnect({\n connect: sourceConnect,\n workflows: source.workflows as PowerhouseConfig[\"workflows\"],\n });\n}\n\nfunction printJson(value: unknown): void {\n process.stdout.write(`${JSON.stringify(value, null, 2)}\\n`);\n}\n\n/**\n * Translate the parsed `ph connect config` args into the structural\n * `ConnectFlagInput` consumed by `buildConnectFlagPatch`. Common-args flags\n * with cmd-ts defaults are gated through `wasFlagExplicitlyPassed` so the\n * defaults don't leak into a write the user didn't request. `--base` is\n * not translated here — it's rejected up front by `runConnectConfig`.\n */\nfunction argsToFlagInput(args: ConnectConfigArgs): ConnectFlagInput {\n return {\n renownUrl: args.renownUrl,\n renownNetworkId: args.renownNetworkId,\n renownChainId: args.renownChainId,\n renownNamespace: args.renownNamespace,\n renownSwitchboardUrl: args.renownSwitchboardUrl,\n allowAddDrive: args.allowAddDrive,\n externalPackages: args.externalPackages,\n workflows: args.workflows,\n remoteDrivesEnabled: args.remoteDrivesEnabled,\n remoteDrivesAllowAdd: args.remoteDrivesAllowAdd,\n remoteDrivesAllowDelete: args.remoteDrivesAllowDelete,\n localDrivesEnabled: args.localDrivesEnabled,\n localDrivesAllowAdd: args.localDrivesAllowAdd,\n localDrivesAllowDelete: args.localDrivesAllowDelete,\n appName: args.appName,\n homeBackground: args.homeBackground,\n sentryDsn: args.sentryDsn,\n sentryEnv: args.sentryEnv,\n sentryTracingEnabled: args.sentryTracingEnabled,\n logLevel: wasFlagExplicitlyPassed(\"log-level\") ? args.logLevel : undefined,\n defaultDrivesUrl: wasFlagExplicitlyPassed(\"default-drives-url\")\n ? args.defaultDrivesUrl\n : undefined,\n drivesPreserveStrategy: wasFlagExplicitlyPassed(\"drive-preserve-strategy\")\n ? args.drivesPreserveStrategy\n : undefined,\n };\n}\n\n/**\n * Whether any field flag (any of the 20) was passed. Distinguishes the\n * single-field-set mode from list mode when neither `--get` nor `--json` is\n * present.\n */\nfunction hasAnyFieldFlag(input: ConnectFlagInput): boolean {\n // Object.values doesn't include json (which isn't in ConnectFlagInput here).\n // Cast to a generic record so the `!== undefined` predicate is type-aware:\n // ConnectFlagInput's optional properties narrow `v` in a way TS thinks\n // excludes `undefined`, even though at runtime any of them can be unset.\n return Object.values(input as Record<string, unknown>).some(\n (v) => v !== undefined,\n );\n}\n\nexport async function runConnectConfig(args: ConnectConfigArgs): Promise<void> {\n // `--base` is a build-time field (baked into the Vite bundle's asset URLs\n // and the nginx config template), so writing it post-build leaves the\n // layers disagreeing and the SPA's assets 404. The flag stays declared so\n // cmd-ts parses it; we reject explicit use here with an actionable error.\n if (wasFlagExplicitlyPassed(\"base\")) {\n throw new Error(\n \"ph connect config: --base is a build-time field; run `ph connect build --base <value>` and redeploy the container (or restart with PH_CONNECT_BASE_PATH=<value> set in the environment).\",\n );\n }\n\n const cwd = process.cwd();\n const sourcePath = resolveSourcePath(cwd);\n const distPath = resolveDistPath(cwd, args.distDir);\n\n const flagInput = argsToFlagInput(args);\n const hasGet = args.get !== undefined;\n const hasJson = args.json !== undefined;\n const hasFieldFlag = hasAnyFieldFlag(flagInput);\n // `--packages-registry` is a top-level field, not part of the connect-flag\n // patch. Track it separately so the set-mode write puts it in the right\n // place and the mutex counts it as a \"field flag\".\n const explicitRegistry = args.packagesRegistry;\n const hasExplicitRegistry = explicitRegistry !== undefined;\n // Positional pair: 1 positional = get, 2 = set. cmd-ts assigns the first\n // positional to `keyPositional` and the second to `valuePositional`, so a\n // standalone <value> isn't representable here.\n const hasPositionalKey = args.keyPositional !== undefined;\n const hasPositionalValue = args.valuePositional !== undefined;\n const hasPositional = hasPositionalKey;\n\n // Mutex: positional / --get / --json / (any field flag OR\n // --packages-registry) are mutually exclusive. Exactly one mode (or none →\n // list) per call. Counting positional as a single mode regardless of arity:\n // a `<key>` alone is a get, `<key> <value>` is a set, both occupy the same\n // \"positional mode\" slot vs. the other forms.\n const modeCount = [\n hasPositional,\n hasGet,\n hasJson,\n hasFieldFlag || hasExplicitRegistry,\n ].filter(Boolean).length;\n if (modeCount > 1) {\n throw new Error(\n \"ph connect config: positional <key>/<value>, --get, --json, and individual field flags are mutually exclusive. Use one mode per invocation.\",\n );\n }\n\n const source = await readSourceRaw(sourcePath);\n\n // List mode.\n if (modeCount === 0) {\n printJson(effectiveConnect(source));\n return;\n }\n\n // Get mode (either positional `<key>` alone or `--get <key>`).\n if (hasGet || (hasPositional && !hasPositionalValue)) {\n const rawKey = hasGet ? args.get! : args.keyPositional!;\n const sourceLabel = hasGet ? \"--get\" : \"<key>\";\n const normalized = normalizeKey(rawKey);\n if (!normalized) {\n throw new Error(\n `ph connect config ${sourceLabel}: key cannot be empty. Pass a dotted path inside connect.* (e.g. connect.renown.url).`,\n );\n }\n // `packageRegistryUrl` is a top-level field — look it up on the raw\n // source object, not inside `effectiveConnect`.\n if (normalized === \"packageRegistryUrl\") {\n const value = source.packageRegistryUrl;\n if (value === undefined) {\n throw new Error(\n `ph connect config ${sourceLabel}: no value at key \"${normalized}\". Run \\`ph connect config\\` (no args) to see the available paths.`,\n );\n }\n printJson(value);\n return;\n }\n const value = getAtPath(effectiveConnect(source), stringToPath(normalized));\n if (value === undefined) {\n throw new Error(\n `ph connect config ${sourceLabel}: no value at key \"${normalized}\". Run \\`ph connect config\\` (no args) to see the available paths.`,\n );\n }\n printJson(value);\n return;\n }\n\n // Set / bulk-set mode. Build the connect-side patch from positional\n // `<key> <value>` (Ajv-validated against the schema at that path), --json\n // (Ajv-validated as a partial connect.* blob), or individual field flags\n // (shape guaranteed by cmd-ts type coercion). `--packages-registry` is a\n // top-level field; if positional `<key>` is `packageRegistryUrl` or --json\n // carries it, route that to the top-level write.\n let topLevelRegistry: string | undefined = explicitRegistry;\n let patch: ConnectPartial;\n if (hasPositional && hasPositionalValue) {\n const normalized = normalizeKey(args.keyPositional!);\n if (!normalized) {\n throw new Error(\n \"ph connect config <key>: key cannot be empty. Pass a dotted path inside connect.* (e.g. connect.renown.url).\",\n );\n }\n // Top-level: positional `packageRegistryUrl <value>` writes the top-level\n // field instead of a connect.* path.\n if (normalized === \"packageRegistryUrl\") {\n const parsed = parseCliValue(args.valuePositional!);\n if (typeof parsed !== \"string\") {\n throw new Error(\n `ph connect config: packageRegistryUrl must be a string (got ${typeof parsed}).`,\n );\n }\n topLevelRegistry = parsed;\n patch = {};\n } else {\n patch = validateConnectKeyValue(\n normalized,\n args.valuePositional!,\n ) as ConnectPartial;\n }\n } else if (hasJson) {\n const validated = validateConnectPatch(args.json!) as Record<\n string,\n unknown\n >;\n if (typeof validated.packageRegistryUrl === \"string\") {\n topLevelRegistry = topLevelRegistry ?? validated.packageRegistryUrl;\n }\n const connectOnly = { ...validated };\n delete connectOnly.packageRegistryUrl;\n patch = connectOnly as ConnectPartial;\n } else {\n patch = buildConnectFlagPatch(flagInput) as ConnectPartial;\n }\n\n if (Object.keys(patch).length === 0 && topLevelRegistry === undefined) {\n throw new Error(\n \"ph connect config: nothing to set. Pass at least one field flag (e.g. --renown-url <url>) or --json with a non-empty payload.\",\n );\n }\n\n // Build the next source: top-level packageRegistryUrl (if set) +\n // connect.* deep-merge.\n const currentConnect =\n source.connect &&\n typeof source.connect === \"object\" &&\n !Array.isArray(source.connect)\n ? (source.connect as PHConnectRuntimeConfig)\n : ({} as PHConnectRuntimeConfig);\n const nextConnect = deepMerge(\n currentConnect,\n patch as PHConnectRuntimeConfig,\n );\n const nextSource: Record<string, unknown> = {\n ...source,\n connect: nextConnect,\n };\n if (topLevelRegistry !== undefined) {\n nextSource.packageRegistryUrl = topLevelRegistry;\n }\n\n await writeSourceRaw(sourcePath, nextSource);\n\n // Dual-write to dist if it exists. Same shape as source: connect.* block\n // is deep-merged; top-level `packageRegistryUrl` is set in place.\n if (existsSync(distPath)) {\n const distLoader = new ConfigLoader(\n new JsonConfigAdapter({ path: distPath }),\n );\n const distPatch: Record<string, unknown> = { connect: patch };\n if (topLevelRegistry !== undefined) {\n distPatch.packageRegistryUrl = topLevelRegistry;\n }\n await distLoader.write(distPatch);\n }\n\n process.stdout.write(\n `ph connect config: wrote ${sourcePath}${existsSync(distPath) ? ` and ${distPath}` : \"\"}\\n`,\n );\n}\n"],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AI,OAAO,UAAU,uBAAuB,UAC1C,mBAAmB,oBAAoB,UAAU;EAEnD,MAAM,cAAc,EAAE,GAAG,UAAU;EACnC,OAAO,YAAY;EACnB,QAAQ;CACV,OACE,QAAQ,sBAAsB,SAAS;CAGzC,IAAI,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,KAAK,qBAAqB,KAAA,GAC1D,MAAM,IAAI,MACR,+HACF;CAKF,MAAM,iBACJ,OAAO,WACP,OAAO,OAAO,YAAY,YAC1B,CAAC,MAAM,QAAQ,OAAO,OAAO,IACxB,OAAO,UACP,CAAC;CACR,MAAM,cAAc,UAClB,gBACA,KACF;CACA,MAAM,aAAsC;EAC1C,GAAG;EACH,SAAS;CACX;CACA,IAAI,qBAAqB,KAAA,GACvB,WAAW,qBAAqB;CAGlC,MAAM,eAAe,YAAY,UAAU;CAI3C,IAAI,WAAW,QAAQ,GAAG;EACxB,MAAM,aAAa,IAAI,aACrB,IAAI,kBAAkB,EAAE,MAAM,SAAS,CAAC,CAC1C;EACA,MAAM,YAAqC,EAAE,SAAS,MAAM;EAC5D,IAAI,qBAAqB,KAAA,GACvB,UAAU,qBAAqB;EAEjC,MAAM,WAAW,MAAM,SAAS;CAClC;CAEA,QAAQ,OAAO,MACb,4BAA4B,aAAa,WAAW,QAAQ,IAAI,QAAQ,aAAa,GAAG,GAC1F;AACF","debug_id":"76f1dd01-ea3d-5516-ac4f-ee1cdfd6a438"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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]="1230558a-cf85-5b58-bd20-9f79de5e287a")}catch(e){}}();
|
|
3
|
+
import { d as entryActiveForVerb, g as isSchemaLike, r as PluginError, x as normalizePluginEntries } from "./compound-B6RZMA0Y-Cv3XMQ3Y.mjs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
//#region src/runners/connect-plugin-configs.ts
|
|
8
|
+
/** The zod-only entry Connect publishes with every built-in plugin's entry
|
|
9
|
+
* config schema, keyed by plugin specifier. */
|
|
10
|
+
const PLUGIN_CONFIGS_ENTRY = "@powerhousedao/connect/plugin-configs";
|
|
11
|
+
/**
|
|
12
|
+
* Validate the entry configs of the Connect plugins composed for `verb`
|
|
13
|
+
* before Connect boots, so a typo fails at `ph run` naming the plugin and the
|
|
14
|
+
* key instead of at browser boot. The schemas come from the project's own
|
|
15
|
+
* `@powerhousedao/connect/plugin-configs` (resolved from the project tree,
|
|
16
|
+
* like runner and plugin modules); without it, or for a specifier it has no
|
|
17
|
+
* schema for, the browser's own validation stays the only check.
|
|
18
|
+
*/
|
|
19
|
+
async function validateConnectPluginConfigs(projectRoot, entries, verb, where) {
|
|
20
|
+
if (entries === void 0 || entries.length === 0) return;
|
|
21
|
+
const schemas = await loadPluginConfigSchemas(projectRoot);
|
|
22
|
+
if (!schemas) return;
|
|
23
|
+
for (const entry of normalizePluginEntries(entries, where)) {
|
|
24
|
+
if (!entryActiveForVerb(entry, verb)) continue;
|
|
25
|
+
const schema = schemas[entry.module];
|
|
26
|
+
if (!isSchemaLike(schema)) continue;
|
|
27
|
+
const parsed = schema.safeParse(entry.config);
|
|
28
|
+
if (parsed.success) continue;
|
|
29
|
+
const issues = parsed.error.issues.map((issue) => {
|
|
30
|
+
return ` - ${["config", ...issue.path.map(String)].join(".")}: ${issue.message}`;
|
|
31
|
+
});
|
|
32
|
+
throw new PluginError(`${where}: config for plugin "${entry.module}" is invalid:\n${issues.join("\n")}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function loadPluginConfigSchemas(projectRoot) {
|
|
36
|
+
const projectRequire = createRequire(pathToFileURL(path.join(projectRoot, "package.json")).href);
|
|
37
|
+
let file;
|
|
38
|
+
try {
|
|
39
|
+
file = projectRequire.resolve(PLUGIN_CONFIGS_ENTRY);
|
|
40
|
+
} catch {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const schemas = (await import(pathToFileURL(file).href)).connectPluginConfigSchemas;
|
|
44
|
+
return typeof schemas === "object" && schemas !== null ? schemas : void 0;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { validateConnectPluginConfigs };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=connect-plugin-configs-D2fwYpMw.mjs.map
|
|
50
|
+
//# debugId=1230558a-cf85-5b58-bd20-9f79de5e287a
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-plugin-configs-D2fwYpMw.mjs","sources":["../src/runners/connect-plugin-configs.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport {\n entryActiveForVerb,\n isSchemaLike,\n normalizePluginEntries,\n PluginError,\n type PluginEntryData,\n} from \"@powerhousedao/host-core\";\n\n/** The zod-only entry Connect publishes with every built-in plugin's entry\n * config schema, keyed by plugin specifier. */\nconst PLUGIN_CONFIGS_ENTRY = \"@powerhousedao/connect/plugin-configs\";\n\n/**\n * Validate the entry configs of the Connect plugins composed for `verb`\n * before Connect boots, so a typo fails at `ph run` naming the plugin and the\n * key instead of at browser boot. The schemas come from the project's own\n * `@powerhousedao/connect/plugin-configs` (resolved from the project tree,\n * like runner and plugin modules); without it, or for a specifier it has no\n * schema for, the browser's own validation stays the only check.\n */\nexport async function validateConnectPluginConfigs(\n projectRoot: string,\n entries: readonly PluginEntryData[] | undefined,\n verb: string,\n where: string,\n): Promise<void> {\n if (entries === undefined || entries.length === 0) return;\n const schemas = await loadPluginConfigSchemas(projectRoot);\n if (!schemas) return;\n for (const entry of normalizePluginEntries(entries, where)) {\n if (!entryActiveForVerb(entry, verb)) continue;\n const schema = schemas[entry.module];\n if (!isSchemaLike(schema)) continue;\n const parsed = schema.safeParse(entry.config);\n if (parsed.success) continue;\n const issues = parsed.error.issues.map((issue) => {\n const key = [\"config\", ...issue.path.map(String)].join(\".\");\n return ` - ${key}: ${issue.message}`;\n });\n throw new PluginError(\n `${where}: config for plugin \"${entry.module}\" is invalid:\\n${issues.join(\"\\n\")}`,\n );\n }\n}\n\nasync function loadPluginConfigSchemas(\n projectRoot: string,\n): Promise<Record<string, unknown> | undefined> {\n const projectRequire = createRequire(\n pathToFileURL(path.join(projectRoot, \"package.json\")).href,\n );\n let file: string;\n try {\n file = projectRequire.resolve(PLUGIN_CONFIGS_ENTRY);\n } catch {\n return undefined;\n }\n const module = (await import(pathToFileURL(file).href)) as {\n connectPluginConfigSchemas?: unknown;\n };\n const schemas = module.connectPluginConfigSchemas;\n return typeof schemas === \"object\" && schemas !== null\n ? (schemas as Record<string, unknown>)\n : undefined;\n}\n"],"names":[],"mappings":";;;;;;;;;AAaA,MAAM,uBAAuB;;;;;;;;;AAU7B,eAAsB,6BACpB,aACA,SACA,MACA,OACe;CACf,IAAI,YAAY,KAAA,KAAa,QAAQ,WAAW,GAAG;CACnD,MAAM,UAAU,MAAM,wBAAwB,WAAW;CACzD,IAAI,CAAC,SAAS;CACd,KAAK,MAAM,SAAS,uBAAuB,SAAS,KAAK,GAAG;EAC1D,IAAI,CAAC,mBAAmB,OAAO,IAAI,GAAG;EACtC,MAAM,SAAS,QAAQ,MAAM;EAC7B,IAAI,CAAC,aAAa,MAAM,GAAG;EAC3B,MAAM,SAAS,OAAO,UAAU,MAAM,MAAM;EAC5C,IAAI,OAAO,SAAS;EACpB,MAAM,SAAS,OAAO,MAAM,OAAO,KAAK,UAAU;GAEhD,OAAO,OADK,CAAC,UAAU,GAAG,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,GACvC,EAAE,IAAI,MAAM;EAC9B,CAAC;EACD,MAAM,IAAI,YACR,GAAG,MAAM,uBAAuB,MAAM,OAAO,iBAAiB,OAAO,KAAK,IAAI,GAChF;CACF;AACF;AAEA,eAAe,wBACb,aAC8C;CAC9C,MAAM,iBAAiB,cACrB,cAAc,KAAK,KAAK,aAAa,cAAc,CAAC,CAAC,CAAC,IACxD;CACA,IAAI;CACJ,IAAI;EACF,OAAO,eAAe,QAAQ,oBAAoB;CACpD,QAAQ;EACN;CACF;CAIA,MAAM,WAAU,MAHM,OAAO,cAAc,IAAI,CAAC,CAAC,MAAA,CAG1B;CACvB,OAAO,OAAO,YAAY,YAAY,YAAY,OAC7C,UACD,KAAA;AACN","debug_id":"1230558a-cf85-5b58-bd20-9f79de5e287a"}
|
|
@@ -1,6 +1,6 @@
|
|
|
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 { r as buildStudioConnectOverride } from "./cli-connect-override-
|
|
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]="b17d6908-daf0-5322-b9d0-2ac650f7907a")}catch(e){}}();
|
|
3
|
+
import { r as buildStudioConnectOverride } from "./cli-connect-override-CEJhQWRX.mjs";
|
|
4
4
|
import { getConnectBaseViteConfig } from "@powerhousedao/builder-tools";
|
|
5
5
|
import { createServer, mergeConfig } from "vite";
|
|
6
6
|
//#region src/services/connect-studio.ts
|
|
@@ -29,9 +29,10 @@ async function runConnectStudio(args, customLogger, callerOverride, { routes } =
|
|
|
29
29
|
await server.listen();
|
|
30
30
|
if (printUrls) server.printUrls();
|
|
31
31
|
if (bindCLIShortcuts) server.bindCLIShortcuts({ print: true });
|
|
32
|
+
return server;
|
|
32
33
|
}
|
|
33
34
|
//#endregion
|
|
34
35
|
export { runConnectStudio as t };
|
|
35
36
|
|
|
36
|
-
//# sourceMappingURL=connect-studio-
|
|
37
|
-
//# debugId=
|
|
37
|
+
//# sourceMappingURL=connect-studio-DX7r4iyI.mjs.map
|
|
38
|
+
//# debugId=b17d6908-daf0-5322-b9d0-2ac650f7907a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect-studio-
|
|
1
|
+
{"version":3,"file":"connect-studio-DX7r4iyI.mjs","sources":["../src/services/connect-studio.ts"],"sourcesContent":["import { getConnectBaseViteConfig } from \"@powerhousedao/builder-tools\";\nimport type { PHConnectRuntimeConfig } from \"@powerhousedao/shared/clis\";\nimport type { InlineConfig, Logger } from \"vite\";\nimport { createServer, mergeConfig } from \"vite\";\nimport type { ConnectStudioArgs } from \"../types.js\";\nimport { buildStudioConnectOverride } from \"../utils/cli-connect-override.js\";\n\nexport async function runConnectStudio(\n args: ConnectStudioArgs,\n customLogger?: Logger,\n callerOverride?: PHConnectRuntimeConfig,\n { routes }: { routes?: string | false } = {},\n) {\n const { port, host, open, cors, strictPort, printUrls, bindCLIShortcuts } =\n args;\n const mode = \"development\";\n\n const dirname = process.cwd();\n\n const cliConnectOverride = buildStudioConnectOverride(args, callerOverride);\n\n const baseConfig = getConnectBaseViteConfig({\n mode,\n dirname,\n cliConnectOverride,\n routes,\n });\n\n const devServerConfig: InlineConfig = {\n server: { port, host, open, cors, strictPort },\n customLogger,\n };\n\n const config = mergeConfig(baseConfig, devServerConfig);\n\n const server = await createServer(config);\n\n await server.listen();\n\n if (printUrls) server.printUrls();\n if (bindCLIShortcuts) server.bindCLIShortcuts({ print: true });\n return server;\n}\n"],"names":[],"mappings":";;;;;;AAOA,eAAsB,iBACpB,MACA,cACA,gBACA,EAAE,WAAwC,CAAC,GAC3C;CACA,MAAM,EAAE,MAAM,MAAM,MAAM,MAAM,YAAY,WAAW,qBACrD;CACF,MAAM,OAAO;CAEb,MAAM,UAAU,QAAQ,IAAI;CAE5B,MAAM,qBAAqB,2BAA2B,MAAM,cAAc;CAE1E,MAAM,aAAa,yBAAyB;EAC1C;EACA;EACA;EACA;CACF,CAAC;CAOD,MAAM,SAAS,YAAY,YAAY;EAJrC,QAAQ;GAAE;GAAM;GAAM;GAAM;GAAM;EAAW;EAC7C;CAGmD,CAAC;CAEtD,MAAM,SAAS,MAAM,aAAa,MAAM;CAExC,MAAM,OAAO,OAAO;CAEpB,IAAI,WAAW,OAAO,UAAU;CAChC,IAAI,kBAAkB,OAAO,iBAAiB,EAAE,OAAO,KAAK,CAAC;CAC7D,OAAO;AACT","debug_id":"b17d6908-daf0-5322-b9d0-2ac650f7907a"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as runConnectStudio } from "./connect-studio-
|
|
1
|
+
import { t as runConnectStudio } from "./connect-studio-DX7r4iyI.mjs";
|
|
2
2
|
export { runConnectStudio };
|
|
3
|
-
!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]="
|
|
4
|
-
//# debugId=
|
|
3
|
+
!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]="ea6224c0-9ba2-5caa-ae9b-88fea686e754")}catch(e){}}();
|
|
4
|
+
//# debugId=ea6224c0-9ba2-5caa-ae9b-88fea686e754
|
|
@@ -1,72 +1,89 @@
|
|
|
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
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import { pathToFileURL } from "node:url";
|
|
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]="ed6e9a99-bbeb-54b3-986e-46c7a47cc5bc")}catch(e){}}();
|
|
3
|
+
import { k as projectDriveIdWith } from "./compound-B6RZMA0Y-Cv3XMQ3Y.mjs";
|
|
4
|
+
import { DRIVE_ICON_MAX_BYTES, resolveImageRef } from "@powerhousedao/shared/connect/image-ref";
|
|
5
|
+
import crypto from "node:crypto";
|
|
8
6
|
//#region ../../packages/host-core/dist/index.mjs
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
case "memory": return { kind: "memory" };
|
|
13
|
-
case "path":
|
|
14
|
-
if (!storage.dataDir) throw new Error(`Backend "${name}": storage kind "path" requires dataDir.`);
|
|
15
|
-
return {
|
|
16
|
-
kind: "path",
|
|
17
|
-
dataDir: storage.dataDir
|
|
18
|
-
};
|
|
19
|
-
case "postgres": throw new Error(`Backend "${name}": storage kind "postgres" is server-side only — a provisioned (in-process/worker) reactor cannot use it. Point a "remote" backend at the switchboard that owns that database instead.`);
|
|
20
|
-
}
|
|
7
|
+
const sha256Hex = (input) => crypto.createHash("sha256").update(input).digest("hex");
|
|
8
|
+
function projectDriveId(projectRoot, slug) {
|
|
9
|
+
return projectDriveIdWith(sha256Hex, projectRoot, slug);
|
|
21
10
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
11
|
+
function resolveDriveDeclaration(projectRoot, decl) {
|
|
12
|
+
const id = decl.projectHash ? projectDriveId(projectRoot, decl.slug) : decl.id ?? decl.slug;
|
|
13
|
+
const slug = decl.projectHash === true ? id : decl.slug;
|
|
14
|
+
if (decl.remote) return {
|
|
15
|
+
kind: "remote",
|
|
16
|
+
id,
|
|
17
|
+
slug,
|
|
18
|
+
name: decl.name ?? decl.slug,
|
|
19
|
+
remoteUrl: decl.remote.url,
|
|
20
|
+
sharingType: decl.sharingType ?? "public",
|
|
21
|
+
availableOffline: decl.availableOffline ?? true
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
kind: "local",
|
|
25
|
+
id,
|
|
26
|
+
slug,
|
|
27
|
+
name: decl.name ?? decl.slug,
|
|
28
|
+
icon: resolveImageRef(projectRoot, decl.icon, {
|
|
29
|
+
maxBytes: DRIVE_ICON_MAX_BYTES,
|
|
30
|
+
warn: (m) => console.warn(m)
|
|
31
|
+
}),
|
|
32
|
+
preferredEditor: decl.preferredEditor,
|
|
33
|
+
sharingType: decl.sharingType ?? "public",
|
|
34
|
+
availableOffline: decl.availableOffline ?? true
|
|
29
35
|
};
|
|
30
|
-
if (descriptor.kind === "remote") {
|
|
31
|
-
const url = backend.remote?.url;
|
|
32
|
-
if (!url) throw new Error(`Backend "${name}" is kind "remote" but has no remote.url — a remote descriptor attaches to an already-running reactor by URL.`);
|
|
33
|
-
descriptor.remote = { url };
|
|
34
|
-
return descriptor;
|
|
35
|
-
}
|
|
36
|
-
if (backend.storage) descriptor.storage = projectStorage(name, backend.storage);
|
|
37
|
-
if (backend.packages) descriptor.packages = backend.packages;
|
|
38
|
-
if (protocol?.featureFlags) descriptor.featureFlags = protocol.featureFlags;
|
|
39
|
-
return descriptor;
|
|
40
36
|
}
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
function
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
/** Idempotent, slug-keyed: an existing slug is left untouched (never
|
|
38
|
+
* recreated, never mutated — preserveStrategy refinements live here later). */
|
|
39
|
+
async function seedDrives(client, drives) {
|
|
40
|
+
const result = {
|
|
41
|
+
created: [],
|
|
42
|
+
existing: [],
|
|
43
|
+
attached: []
|
|
44
|
+
};
|
|
45
|
+
for (const drive of drives) {
|
|
46
|
+
if (drive.kind === "remote") {
|
|
47
|
+
await client.attachRemoteDrive(drive.remoteUrl);
|
|
48
|
+
result.attached.push(drive.slug);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (await client.findDriveBySlug(drive.slug) !== void 0) {
|
|
52
|
+
result.existing.push(drive.slug);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
await client.createDrive(drive);
|
|
56
|
+
result.created.push(drive.slug);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
49
59
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
/** Merge host-declared drives with plugin contributions, slug-keyed — the
|
|
61
|
+
* host file wins on conflicts (it is the most explicit source). */
|
|
62
|
+
function mergeDrivePlan(projectRoot, hostDeclared, contributed) {
|
|
63
|
+
const plan = /* @__PURE__ */ new Map();
|
|
64
|
+
for (const { declaration, source } of contributed) {
|
|
65
|
+
const drive = resolveDriveDeclaration(projectRoot, declaration);
|
|
66
|
+
plan.set(drive.slug, {
|
|
67
|
+
drive,
|
|
68
|
+
source
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
for (const declaration of hostDeclared) {
|
|
72
|
+
const drive = resolveDriveDeclaration(projectRoot, declaration);
|
|
73
|
+
plan.set(drive.slug, {
|
|
74
|
+
drive,
|
|
75
|
+
source: "host"
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return [...plan.values()];
|
|
66
79
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return
|
|
80
|
+
function explainDrivePlan(plan) {
|
|
81
|
+
if (plan.length === 0) return "(no drives declared)";
|
|
82
|
+
return ["drives:", ...plan.map(({ drive, source }) => {
|
|
83
|
+
const kind = drive.kind === "remote" ? `remote ${drive.remoteUrl}` : "local";
|
|
84
|
+
const editor = drive.preferredEditor ? ` editor=${drive.preferredEditor}` : "";
|
|
85
|
+
return ` ${drive.slug} (${kind}, id=${drive.id}${editor}) [${source}]`;
|
|
86
|
+
})].join("\n");
|
|
70
87
|
}
|
|
71
88
|
/** The single primary backend for phase-2 projection (multi-backend routing is
|
|
72
89
|
* track R). Prefers placement.primary, else "main"/"local", else the first. */
|
|
@@ -114,11 +131,7 @@ function projectReactorToSwitchboard(reactor) {
|
|
|
114
131
|
options
|
|
115
132
|
};
|
|
116
133
|
}
|
|
117
|
-
const LOCAL_BACKEND_KINDS = /* @__PURE__ */ new Set([
|
|
118
|
-
"in-process",
|
|
119
|
-
"worker",
|
|
120
|
-
void 0
|
|
121
|
-
]);
|
|
134
|
+
const LOCAL_BACKEND_KINDS = /* @__PURE__ */ new Set(["in-process", "worker"]);
|
|
122
135
|
/**
|
|
123
136
|
* Which reactor client the backend topology asks for:
|
|
124
137
|
* - local (in-process/worker) AND remote backends -> `router`
|
|
@@ -170,54 +183,131 @@ function assertProtocolConsistency(protocol, env, hostFile = "the host file") {
|
|
|
170
183
|
if (envValue !== void 0 && envValue !== hostValue) throw new Error(`reactor.protocol conflict: ${varName} is "${envValue}" in the environment but "${hostValue}" in ${hostFile}. These are fleet-consensus settings — a mismatch would diverge replay. Remove the env override or align the host.`);
|
|
171
184
|
}
|
|
172
185
|
}
|
|
186
|
+
function projectStorage(name, storage) {
|
|
187
|
+
switch (storage.kind) {
|
|
188
|
+
case "idb": return { kind: "idb" };
|
|
189
|
+
case "memory": return { kind: "memory" };
|
|
190
|
+
case "path":
|
|
191
|
+
if (!storage.dataDir) throw new Error(`Backend "${name}": storage kind "path" requires dataDir.`);
|
|
192
|
+
return {
|
|
193
|
+
kind: "path",
|
|
194
|
+
dataDir: storage.dataDir
|
|
195
|
+
};
|
|
196
|
+
case "postgres": throw new Error(`Backend "${name}": storage kind "postgres" is server-side only — a provisioned (in-process/worker) reactor cannot use it. Point a "remote" backend at the switchboard that owns that database instead.`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** One backend → one descriptor. The protocol's featureFlags ride every
|
|
200
|
+
* descriptor (they are fleet consensus, not per-backend). A remote backend
|
|
201
|
+
* must carry remote.url — provision() requires it. */
|
|
202
|
+
function backendToDescriptor(name, backend, protocol) {
|
|
203
|
+
const descriptor = {
|
|
204
|
+
kind: backend.kind,
|
|
205
|
+
name
|
|
206
|
+
};
|
|
207
|
+
if (descriptor.kind === "remote") {
|
|
208
|
+
const url = backend.remote?.url;
|
|
209
|
+
if (!url) throw new Error(`Backend "${name}" is kind "remote" but has no remote.url — a remote descriptor attaches to an already-running reactor by URL.`);
|
|
210
|
+
descriptor.remote = { url };
|
|
211
|
+
return descriptor;
|
|
212
|
+
}
|
|
213
|
+
if (backend.storage) descriptor.storage = projectStorage(name, backend.storage);
|
|
214
|
+
if (backend.packages) descriptor.packages = backend.packages;
|
|
215
|
+
if (protocol?.featureFlags) descriptor.featureFlags = protocol.featureFlags;
|
|
216
|
+
return descriptor;
|
|
217
|
+
}
|
|
218
|
+
/** All named backends, in placement-primary-first order (the order a
|
|
219
|
+
* createReactorClients step would provision them). */
|
|
220
|
+
function backendsToDescriptors(reactor) {
|
|
221
|
+
const backends = reactor?.backends;
|
|
222
|
+
if (!backends) return [];
|
|
223
|
+
const names = Object.keys(backends);
|
|
224
|
+
const primary = reactor.placement?.primary;
|
|
225
|
+
return (primary && names.includes(primary) ? [primary, ...names.filter((n) => n !== primary)] : names).map((name) => backendToDescriptor(name, backends[name], reactor.protocol));
|
|
226
|
+
}
|
|
227
|
+
const LOCAL_KINDS = /* @__PURE__ */ new Set(["in-process", "worker"]);
|
|
173
228
|
/**
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
229
|
+
* Structural multi-reactor (phase 4): true when the block names BOTH a local
|
|
230
|
+
* backend (in-process/worker — the tab's own reactor) and a remote one. This
|
|
231
|
+
* is the shape Connect's routing client serves; a lone remote backend is an
|
|
232
|
+
* attach-only host (assistant/agent shape), not a routed tab.
|
|
177
233
|
*/
|
|
178
|
-
function
|
|
179
|
-
|
|
234
|
+
function isStructuralMultiReactor(reactor) {
|
|
235
|
+
const backends = reactor?.backends;
|
|
236
|
+
if (!backends) return false;
|
|
237
|
+
const kinds = Object.values(backends).map((b) => b.kind);
|
|
238
|
+
return kinds.some((k) => LOCAL_KINDS.has(k)) && kinds.some((k) => k === "remote");
|
|
239
|
+
}
|
|
240
|
+
/** The remote backends' urls, placement order — what the routing client dials. */
|
|
241
|
+
function remoteBackendUrls(reactor) {
|
|
242
|
+
return backendsToDescriptors(reactor).filter((d) => d.kind === "remote").map((d) => d.remote?.url).filter((u) => typeof u === "string");
|
|
180
243
|
}
|
|
181
244
|
/**
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
245
|
+
* Instance-fact projection for compound hosts: the drives a compound's
|
|
246
|
+
* reactor member created, projected into the Connect member's runtime-config
|
|
247
|
+
* override. Pure functions, moved from ph-cli's vetra service so the generic
|
|
248
|
+
* compound and the classic path share one implementation.
|
|
185
249
|
*/
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (plugin.configSchema) {
|
|
206
|
-
const parsed = plugin.configSchema.safeParse(entry.config);
|
|
207
|
-
if (!parsed.success) throw new PluginError(`${where}: config for plugin "${plugin.name}" is invalid:\n` + prettifyError(parsed.error));
|
|
208
|
-
}
|
|
209
|
-
const appliesTo = plugin.appliesTo ?? "reactor";
|
|
210
|
-
if (!hostTypeSatisfies(hostType, appliesTo)) throw new PluginError(`${where}: plugin "${plugin.name}" applies to "${appliesTo}" hosts, but this host is "${hostType}".`);
|
|
211
|
-
resolved.push({
|
|
212
|
-
entry,
|
|
213
|
-
plugin,
|
|
214
|
-
provenance: "dependency"
|
|
215
|
-
});
|
|
250
|
+
function isLocalDrive(drive) {
|
|
251
|
+
return "local" in drive;
|
|
252
|
+
}
|
|
253
|
+
const driveKey = (drive) => isLocalDrive(drive) ? `local:${drive.id}` : drive.url;
|
|
254
|
+
/**
|
|
255
|
+
* Concatenate groups of `connect.drives.defaultDrives` in the order given,
|
|
256
|
+
* de-duplicating by drive identity (URL for remote entries, id for local
|
|
257
|
+
* ones). The first occurrence of a drive wins, so earlier groups keep their
|
|
258
|
+
* position and metadata — e.g. the Vetra drive `ph vetra` starts stays first
|
|
259
|
+
* even when the project's `powerhouse.config.json` lists the same drive.
|
|
260
|
+
*/
|
|
261
|
+
function mergeDefaultDrives(...groups) {
|
|
262
|
+
const seen = /* @__PURE__ */ new Set();
|
|
263
|
+
const out = [];
|
|
264
|
+
for (const group of groups) for (const drive of group) {
|
|
265
|
+
const key = driveKey(drive);
|
|
266
|
+
if (seen.has(key)) continue;
|
|
267
|
+
seen.add(key);
|
|
268
|
+
out.push(drive);
|
|
216
269
|
}
|
|
217
|
-
return
|
|
270
|
+
return out;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Rebase a local drive URL onto a public base: keeps the /d/<slug> path,
|
|
274
|
+
* swaps the loopback origin for the public base. Browser clients behind a
|
|
275
|
+
* reverse proxy can't reach http://localhost:<port>. Non-loopback URLs
|
|
276
|
+
* (e.g. a remote drive) are already public and pass through unchanged, as do
|
|
277
|
+
* unparseable ones.
|
|
278
|
+
*/
|
|
279
|
+
function rebaseDriveUrl(driveUrl, publicBase) {
|
|
280
|
+
let url;
|
|
281
|
+
try {
|
|
282
|
+
url = new URL(driveUrl);
|
|
283
|
+
} catch {
|
|
284
|
+
return driveUrl;
|
|
285
|
+
}
|
|
286
|
+
if (![
|
|
287
|
+
"localhost",
|
|
288
|
+
"127.0.0.1",
|
|
289
|
+
"[::1]"
|
|
290
|
+
].includes(url.hostname)) return driveUrl;
|
|
291
|
+
return `${publicBase.replace(/\/+$/, "")}${url.pathname}`;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* The compound's drives projection: created drives first (rebased onto the
|
|
295
|
+
* public base when given), then the project's configured drives, de-duplicated
|
|
296
|
+
* — and `preserve-all`, because compound-injected drive lists change per
|
|
297
|
+
* launch context and must never detach drives the user added by hand.
|
|
298
|
+
*/
|
|
299
|
+
function projectDrivesIntoConnect(input) {
|
|
300
|
+
return { drives: {
|
|
301
|
+
defaultDrives: mergeDefaultDrives(input.createdDriveUrls.filter((url) => typeof url === "string" && url.length > 0).map((url) => ({
|
|
302
|
+
url: input.publicBase ? rebaseDriveUrl(url, input.publicBase) : url,
|
|
303
|
+
name: null,
|
|
304
|
+
icon: null
|
|
305
|
+
})), input.configuredDefaultDrives ?? []),
|
|
306
|
+
preserveStrategy: "preserve-all"
|
|
307
|
+
} };
|
|
218
308
|
}
|
|
219
309
|
//#endregion
|
|
220
|
-
export {
|
|
310
|
+
export { mergeDrivePlan as a, projectReactorToConnect as c, remoteBackendUrls as d, resolveDriveDeclaration as f, mergeDefaultDrives as i, projectReactorToSwitchboard as l, explainDrivePlan as n, primaryBackend as o, seedDrives as p, isStructuralMultiReactor as r, projectDrivesIntoConnect as s, assertProtocolConsistency as t, rebaseDriveUrl as u };
|
|
221
311
|
|
|
222
|
-
//# sourceMappingURL=dist-
|
|
223
|
-
//# debugId=
|
|
312
|
+
//# sourceMappingURL=dist-CCLkwpTS.mjs.map
|
|
313
|
+
//# debugId=ed6e9a99-bbeb-54b3-986e-46c7a47cc5bc
|