@voltro/cli 0.5.0 → 0.7.0
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/CHANGELOG.md +68 -1
- package/bin/voltro.mjs +63 -2
- package/dist/apiBuild-CSM74oEZ.js +2 -0
- package/dist/{apiBuild-CZugTK46.js → apiBuild-deIjJKJm.js} +2 -1
- package/dist/bin.js +2 -2
- package/dist/{commands-CJheDVOr.js → commands-BHdc71DG.js} +2671 -2960
- package/dist/dev-BYfrYwrT.js +2 -0
- package/dist/dev-Bqyq62Ak.js +6492 -0
- package/dist/devActivity-1WtIVyHc.js +153 -0
- package/dist/devActivity.d.ts +46 -0
- package/dist/devActivity.js +2 -0
- package/dist/index.js +1 -1
- package/dist/inspectMetrics-BLUBAWLb.js +3711 -0
- package/dist/serveCommand-Dn6--0Bv.js +1111 -0
- package/dist/serveEntry.js +3 -2
- package/dist/start-CWZW_4Et.js +941 -0
- package/dist/startEntry.d.ts +5 -0
- package/dist/startEntry.js +3 -0
- package/package.json +22 -17
- package/templates/AGENTS.core.md +36 -1
- package/templates/AGENTS.md +36 -1
- package/templates/agent-docs/_manifest.json +3 -3
- package/templates/agent-docs/ai.md +35 -3
- package/templates/agent-docs/authentication.md +264 -0
- package/templates/agent-docs/cli.md +126 -3
- package/templates/agent-docs/configuration.md +38 -0
- package/templates/agent-docs/data.md +616 -40
- package/templates/agent-docs/database/querying.md +151 -3
- package/templates/agent-docs/database/schema.md +1 -0
- package/templates/agent-docs/deployment.md +171 -0
- package/templates/agent-docs/internationalization.md +2 -0
- package/templates/agent-docs/plugins.md +4 -4
- package/templates/agent-docs/reference.md +56 -2
- package/templates/agent-docs/templates/apibackends.md +13 -2
- package/templates/agent-docs/testing.md +215 -3
- package/templates/apps/api-ai/package.json +7 -7
- package/templates/apps/api-auth/app.config.ts +20 -13
- package/templates/apps/api-auth/package.json +8 -8
- package/templates/apps/api-backend/package.json +7 -7
- package/templates/apps/api-backend-deactivation/package.json +7 -7
- package/templates/apps/api-backend-mail/package.json +8 -8
- package/templates/apps/api-backend-mariadb/.env.example +10 -4
- package/templates/apps/api-backend-mariadb/package.json +9 -9
- package/templates/apps/api-backend-storage/package.json +8 -8
- package/templates/apps/api-data-advanced/app.config.ts +21 -8
- package/templates/apps/api-data-advanced/package.json +8 -8
- package/templates/apps/api-durable/package.json +8 -8
- package/templates/apps/api-feature-flags/package.json +9 -9
- package/templates/apps/api-governance/app.config.ts +15 -2
- package/templates/apps/api-governance/package.json +8 -8
- package/templates/apps/api-kv/package.json +8 -8
- package/templates/apps/api-moderation/package.json +8 -8
- package/templates/apps/api-observability/package.json +8 -8
- package/templates/apps/api-ratelimit/package.json +8 -8
- package/templates/apps/api-rbac/package.json +8 -8
- package/templates/apps/api-rest/package.json +7 -7
- package/templates/apps/api-saas/package.json +11 -11
- package/templates/apps/api-search/package.json +8 -8
- package/templates/apps/api-versioning/package.json +8 -8
- package/templates/apps/api-webhooks/app.config.ts +20 -1
- package/templates/apps/api-webhooks/package.json +8 -8
- package/templates/apps/changelog/package.json +6 -6
- package/templates/apps/edge-functions/package.json +2 -2
- package/templates/apps/frontend-admin/package.json +8 -8
- package/templates/apps/frontend-app/package.json +8 -8
- package/templates/apps/frontend-blank/package.json +7 -7
- package/templates/apps/frontend-contact/package.json +7 -7
- package/templates/apps/frontend-dashboard/package.json +7 -7
- package/templates/apps/frontend-docs/package.json +7 -7
- package/templates/apps/frontend-i18n/package.json +6 -6
- package/templates/apps/frontend-landing/package.json +7 -7
- package/templates/apps/frontend-spa/package.json +7 -7
- package/templates/apps/frontend-ssr/package.json +7 -7
- package/templates/apps/frontend-ssr-api/package.json +8 -8
- package/templates/apps/frontend-static-blog/package.json +6 -6
- package/templates/baselines/bare/.env.example +10 -3
- package/templates/baselines/compose/.env.example +10 -2
- package/templates/baselines/compose-mariadb/.env.example +10 -2
- package/templates/baselines/helm/.env.example +10 -3
- package/dist/apiBuild-D-iBYKa3.js +0 -2
- package/dist/dev-B71ICpXJ.js +0 -9896
- package/dist/dev-DNUetyG2.js +0 -2
- package/dist/serveCommand-C0WFA396.js +0 -1084
- package/templates/apps/api-auth/.env +0 -17
- package/templates/apps/api-data-advanced/.env +0 -17
- package/templates/apps/api-governance/.env +0 -4
- package/templates/apps/api-webhooks/.env +0 -6
|
@@ -0,0 +1,3711 @@
|
|
|
1
|
+
import { basename as e, dirname as t, isAbsolute as n, join as r, relative as i, resolve as a } from "node:path";
|
|
2
|
+
import { fileURLToPath as o, pathToFileURL as s } from "node:url";
|
|
3
|
+
import { FileSystem as c } from "@effect/platform";
|
|
4
|
+
import { NodeContext as l, NodeRuntime as u } from "@effect/platform-node";
|
|
5
|
+
import { Cause as d, Effect as f, Layer as p } from "effect";
|
|
6
|
+
import { LoggerLayer as m, addSink as h, createLogger as g, printReadyBlock as _ } from "@voltro/logger";
|
|
7
|
+
import { closeSync as v, existsSync as y, mkdirSync as b, openSync as x, promises as S, readFileSync as C, readdirSync as w, statSync as T, unlinkSync as E, unwatchFile as ee, watchFile as D, writeSync as te } from "node:fs";
|
|
8
|
+
import { currentTraceContext as O, lastWriteProvenance as ne, recordSample as re, resolveSecret as k } from "@voltro/runtime";
|
|
9
|
+
import { mkdir as A, writeFile as j } from "node:fs/promises";
|
|
10
|
+
import { FRAMEWORK_ENV_CATALOG as M, appEnvEntries as N, checkEnvNaming as ie, formatEnvErrors as ae, installEnvSnapshot as oe, isEnvContract as se, pluginEnvEntries as ce, renderDotEnvExample as P, resolveEnv as le } from "@voltro/env";
|
|
11
|
+
import { __installPublicEnv as ue } from "@voltro/env/public";
|
|
12
|
+
import { createHash as de } from "node:crypto";
|
|
13
|
+
import { spawn as fe } from "node:child_process";
|
|
14
|
+
import { timingSafeStringEqual as pe } from "@voltro/protocol/session";
|
|
15
|
+
import { homedir as F } from "node:os";
|
|
16
|
+
import { createConnection as me } from "node:net";
|
|
17
|
+
import { createRequire as he } from "node:module";
|
|
18
|
+
//#region src/cliRuntime.ts
|
|
19
|
+
var ge = [
|
|
20
|
+
"severity",
|
|
21
|
+
"code",
|
|
22
|
+
"detail",
|
|
23
|
+
"hint",
|
|
24
|
+
"position",
|
|
25
|
+
"internalPosition",
|
|
26
|
+
"internalQuery",
|
|
27
|
+
"where",
|
|
28
|
+
"schema",
|
|
29
|
+
"table",
|
|
30
|
+
"column",
|
|
31
|
+
"dataType",
|
|
32
|
+
"constraint",
|
|
33
|
+
"file",
|
|
34
|
+
"line",
|
|
35
|
+
"routine"
|
|
36
|
+
], I = (e, t = 0, n = /* @__PURE__ */ new WeakSet()) => {
|
|
37
|
+
if (t > 10 || typeof e != "object" || !e || n.has(e)) return null;
|
|
38
|
+
n.add(e);
|
|
39
|
+
let r = e, i = r.message;
|
|
40
|
+
if (typeof i == "string" && i.length > 0 && i !== "Failed to execute statement") {
|
|
41
|
+
let e = { message: i };
|
|
42
|
+
typeof r.stack == "string" && (e.stack = r.stack);
|
|
43
|
+
for (let t of ge) r[t] !== void 0 && (e[t] = r[t]);
|
|
44
|
+
return e;
|
|
45
|
+
}
|
|
46
|
+
for (let e of [
|
|
47
|
+
"cause",
|
|
48
|
+
"defect",
|
|
49
|
+
"left",
|
|
50
|
+
"right",
|
|
51
|
+
"failure",
|
|
52
|
+
"failures"
|
|
53
|
+
]) {
|
|
54
|
+
let i = r[e];
|
|
55
|
+
if (i !== void 0) {
|
|
56
|
+
let e = I(i, t + 1, n);
|
|
57
|
+
if (e) return e;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(r.failures)) for (let e of r.failures) {
|
|
61
|
+
let r = I(e, t + 1, n);
|
|
62
|
+
if (r) return r;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}, _e = (e = {}) => p.merge(l.layer, m({
|
|
66
|
+
...e.scope ? { defaultScope: e.scope } : {},
|
|
67
|
+
...e.logger
|
|
68
|
+
})), ve = async (e, t = {}) => {
|
|
69
|
+
let n = e.pipe(f.provide(_e(t)));
|
|
70
|
+
return await f.runPromise(f.matchCauseEffect(n, {
|
|
71
|
+
onSuccess: (e) => f.succeed(e),
|
|
72
|
+
onFailure: (e) => {
|
|
73
|
+
let t = [...d.defects(e)];
|
|
74
|
+
if (process.env.VOLTRO_CAUSE_DEBUG === "1") for (let [e, n] of t.entries()) {
|
|
75
|
+
let t = Object.getOwnPropertyNames(n);
|
|
76
|
+
process.stderr.write(`[VOLTRO_CAUSE_DEBUG] defect[${e}] ctor=${n?.constructor?.name} props=${JSON.stringify(t)}\n`);
|
|
77
|
+
let r = n;
|
|
78
|
+
if (r.message && process.stderr.write(` message: ${String(r.message)}\n`), r.cause) {
|
|
79
|
+
let e = r.cause;
|
|
80
|
+
process.stderr.write(` cause.ctor=${e.constructor?.name} cause.message=${String(e.message)} cause.code=${String(e.code)}\n`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
let n = null;
|
|
84
|
+
for (let e of t) {
|
|
85
|
+
let t = I(e);
|
|
86
|
+
if (t) {
|
|
87
|
+
n = t;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
let r = n ? {
|
|
92
|
+
pgMessage: n.message,
|
|
93
|
+
...n.code ? { pgCode: n.code } : {},
|
|
94
|
+
...n.detail ? { pgDetail: n.detail } : {},
|
|
95
|
+
...n.hint ? { pgHint: n.hint } : {},
|
|
96
|
+
...n.table ? { pgTable: n.table } : {},
|
|
97
|
+
...n.column ? { pgColumn: n.column } : {},
|
|
98
|
+
...n.constraint ? { pgConstraint: n.constraint } : {},
|
|
99
|
+
...n.routine ? { pgRoutine: n.routine } : {},
|
|
100
|
+
causePretty: d.pretty(e)
|
|
101
|
+
} : { causePretty: d.pretty(e) };
|
|
102
|
+
return f.zipRight(f.logError("cli command failed", r), f.succeed(1));
|
|
103
|
+
}
|
|
104
|
+
}).pipe(f.provide(m(t.logger ?? {}))));
|
|
105
|
+
}, ye = (e, t = {}) => {
|
|
106
|
+
let n = e.pipe(f.provide(_e(t)));
|
|
107
|
+
u.runMain(n, { disableErrorReporting: !1 });
|
|
108
|
+
}, L = t(o(import.meta.url)), be = [a(L, "..", "templates"), a(L, "..", "..", "templates")], xe = (e) => ({
|
|
109
|
+
_tag: "TemplateNotFoundError",
|
|
110
|
+
searched: e
|
|
111
|
+
}), Se = ["AGENTS.md", "CLAUDE.md"], Ce = "voltro:agents-md:keep", we = 2048, Te = "<!-- VOLTRO:INDEX -->", R = (e, t) => e.exists(t).pipe(f.orElseSucceed(() => !1)), z = (e, t) => e.readFileString(t).pipe(f.orElseSucceed(() => "")), Ee = (e, t) => e.readFileString(t).pipe(f.map((e) => {
|
|
112
|
+
try {
|
|
113
|
+
return JSON.parse(e).workspaces !== void 0;
|
|
114
|
+
} catch {
|
|
115
|
+
return !1;
|
|
116
|
+
}
|
|
117
|
+
}), f.orElseSucceed(() => !1)), De = (e) => f.gen(function* () {
|
|
118
|
+
let n = yield* c.FileSystem, i = a(e);
|
|
119
|
+
for (;;) {
|
|
120
|
+
if ((yield* R(n, r(i, ".git"))) || (yield* R(n, r(i, "pnpm-workspace.yaml"))) || (yield* Ee(n, r(i, "package.json")))) return i;
|
|
121
|
+
let o = t(i);
|
|
122
|
+
if (o === i) return a(e);
|
|
123
|
+
i = o;
|
|
124
|
+
}
|
|
125
|
+
}), Oe = (e, t, n) => f.gen(function* () {
|
|
126
|
+
yield* e.makeDirectory(n, { recursive: !0 }).pipe(f.orElseSucceed(() => void 0));
|
|
127
|
+
let i = yield* e.readDirectory(t).pipe(f.orElseSucceed(() => []));
|
|
128
|
+
for (let a of i) {
|
|
129
|
+
let i = r(t, a), o = r(n, a);
|
|
130
|
+
(yield* e.stat(i).pipe(f.orElseSucceed(() => null)))?.type === "Directory" ? yield* Oe(e, i, o) : yield* e.copyFile(i, o).pipe(f.orElseSucceed(() => void 0));
|
|
131
|
+
}
|
|
132
|
+
}), ke = (e) => typeof e?.name == "string" && e.name.length > 0 ? e.name.split("#")[0] : null, Ae = (e, t) => f.gen(function* () {
|
|
133
|
+
let n = r(t, "app.config.ts");
|
|
134
|
+
if (!(yield* R(e, n))) return null;
|
|
135
|
+
let i = (yield* f.tryPromise(() => import(s(n).href)).pipe(f.orElseSucceed(() => null)))?.default;
|
|
136
|
+
return !i || i.type && i.type !== "api" ? i?.type === "web" ? [] : null : (i.plugins ?? []).map(ke).filter((e) => e !== null);
|
|
137
|
+
}), je = (e, t) => f.gen(function* () {
|
|
138
|
+
let n = [], i = [], a = r(t, "apps");
|
|
139
|
+
if (!(yield* R(e, a))) return {
|
|
140
|
+
apis: n,
|
|
141
|
+
webs: i
|
|
142
|
+
};
|
|
143
|
+
for (let t of yield* e.readDirectory(a).pipe(f.orElseSucceed(() => []))) {
|
|
144
|
+
let o = r(a, t);
|
|
145
|
+
if ((yield* e.stat(o).pipe(f.orElseSucceed(() => null)))?.type === "Directory") for (let t of yield* e.readDirectory(o).pipe(f.orElseSucceed(() => []))) {
|
|
146
|
+
let a = r(o, t), s = r(a, "app.config.ts");
|
|
147
|
+
if (!(yield* R(e, s))) continue;
|
|
148
|
+
let c = yield* z(e, s);
|
|
149
|
+
/type:\s*['"]web['"]/.test(c) ? i.push(a) : n.push(a);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
apis: n,
|
|
154
|
+
webs: i
|
|
155
|
+
};
|
|
156
|
+
}), Me = (e) => e.replace(/\|/g, "\\|").replace(/\n/g, " ").trim(), Ne = (e, t, n) => {
|
|
157
|
+
let r = [
|
|
158
|
+
"<!-- voltro agent-docs index — regenerated at seed time -->",
|
|
159
|
+
"## Deep reference (read on demand)",
|
|
160
|
+
"",
|
|
161
|
+
"Each row is a file to OPEN when you work on that topic — not loaded into",
|
|
162
|
+
"context by default. Paths are from the repo root.",
|
|
163
|
+
"",
|
|
164
|
+
"### Topics",
|
|
165
|
+
"",
|
|
166
|
+
"| Topic | Open | Summary |",
|
|
167
|
+
"|---|---|---|",
|
|
168
|
+
...e.modules.map((e) => `| ${e.title} | \`${n}${e.path}\` | ${Me(e.description)} |`),
|
|
169
|
+
""
|
|
170
|
+
], i = new Map(e.plugins.map((e) => [e.pkg, e])), a = t === null ? e.plugins.map((e) => `| ${e.slug} | \`node_modules/${e.pkg}/README.md\` | ${Me(e.description)} |`) : t.map((e) => {
|
|
171
|
+
let t = i.get(e);
|
|
172
|
+
return t ? `| ${t.slug} | \`node_modules/${e}/README.md\` | ${Me(t.description)} |` : `| ${e.replace(/^@[^/]+\//, "")} | \`node_modules/${e}/README.md\` | (see plugin README) |`;
|
|
173
|
+
});
|
|
174
|
+
return r.push(`### Plugins${t === null ? "" : " (installed)"}`, "", "| Plugin | Open | Summary |", "|---|---|---|"), r.push(a.length ? a.join("\n") : "| _(none installed)_ | | |", ""), r.join("\n");
|
|
175
|
+
}, Pe = (e, t, n) => {
|
|
176
|
+
let r = t.templates?.[e] ?? t.templates?.[e.replace(/^frontend-/, "")];
|
|
177
|
+
return `\nScaffolded from the \`${e}\` template — see \`${r ? `${n}${r}` : `${n}agent-docs/templates/overview.md`}\`.\n`;
|
|
178
|
+
}, Fe = {
|
|
179
|
+
api: (e, t, n = "") => `# api — agent notes
|
|
180
|
+
|
|
181
|
+
You are in a Voltro **api** app. Server primitives live here: \`queries/\`,
|
|
182
|
+
\`mutations/\`, \`actions/\`, \`workflows/\`, \`database/\`, \`schedules/\`.
|
|
183
|
+
|
|
184
|
+
- Every RPC primitive is a descriptor + \`*.server.ts\` executor pair. Descriptors
|
|
185
|
+
are **browser-loaded** — keep them free of \`node:*\` / \`@voltro/database\` /
|
|
186
|
+
server-only imports (transitively too).
|
|
187
|
+
- Pick the primitive with the rubric in the repo-root \`AGENTS.md\`.
|
|
188
|
+
|
|
189
|
+
Deep reference (paths from the repo root):
|
|
190
|
+
- Data primitives → \`${e}agent-docs/data.md\`
|
|
191
|
+
- Schema / queries → \`${e}agent-docs/database/schema.md\`, \`${e}agent-docs/database/querying.md\`
|
|
192
|
+
- Workflows → \`${e}agent-docs/workflows.md\`
|
|
193
|
+
${t && t.length ? `\nThis api's plugins: ${t.join(", ")} (API in each \`node_modules/<pkg>/README.md\`).` : ""}
|
|
194
|
+
${n}`,
|
|
195
|
+
database: (e) => `# database — agent notes
|
|
196
|
+
|
|
197
|
+
Schema lives here: one table per \`*.entity.ts\`; \`index.ts\` builds the handle.
|
|
198
|
+
|
|
199
|
+
- Mixins compose via \`.with(...)\` and auto-stamp columns; declare \`.index([...])\`
|
|
200
|
+
AFTER \`.with(...)\`. Indexes are table-level (no column-level \`.index()\`).
|
|
201
|
+
- Don't add tenant filters on \`tenant()\` tables — the runtime does it.
|
|
202
|
+
|
|
203
|
+
Deep reference (paths from the repo root): \`${e}agent-docs/database/schema.md\`,
|
|
204
|
+
\`${e}agent-docs/database/columntypes.md\`, \`${e}agent-docs/database/querying.md\`,
|
|
205
|
+
\`${e}agent-docs/database/migrations.md\`.
|
|
206
|
+
`,
|
|
207
|
+
web: (e, t = "") => `# web — agent notes
|
|
208
|
+
|
|
209
|
+
You are in a Voltro **web** app. File-based routing under \`src/pages/**\`.
|
|
210
|
+
|
|
211
|
+
- Use \`useSubscription\` / \`useMutation\` / \`useAction\` from \`@voltro/client\`.
|
|
212
|
+
- Never read \`window.location\` (use \`useLocation()\`); never toggle \`dark\` from
|
|
213
|
+
\`useEffect\` (set \`theme\` in \`app.config.ts\`).
|
|
214
|
+
|
|
215
|
+
Deep reference (paths from the repo root): \`${e}agent-docs/routing.md\`,
|
|
216
|
+
\`${e}agent-docs/schema-driven-ui.md\`, \`${e}agent-docs/internationalization.md\`.
|
|
217
|
+
${t}`
|
|
218
|
+
}, Ie = [
|
|
219
|
+
{
|
|
220
|
+
name: "voltro-schema",
|
|
221
|
+
description: "Define or change a Voltro database table/schema (columns, mixins, indexes, relations).",
|
|
222
|
+
module: "database/schema.md"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: "voltro-data",
|
|
226
|
+
description: "Write a Voltro query, mutation, action, or stream (the descriptor + server executor pair).",
|
|
227
|
+
module: "data.md"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
name: "voltro-workflows",
|
|
231
|
+
description: "Write or debug a durable Voltro workflow (steps, signals, retries).",
|
|
232
|
+
module: "workflows.md"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
name: "voltro-routing",
|
|
236
|
+
description: "Add or change a Voltro web page, layout, loader, or render mode.",
|
|
237
|
+
module: "routing.md"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: "voltro-plugins",
|
|
241
|
+
description: "Wire a Voltro plugin (storage, mail, billing, auth, rbac, …) into an app.",
|
|
242
|
+
module: "plugins.md"
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: "voltro-data-transfer",
|
|
246
|
+
description: "Export/import + backup/restore Voltro data & assets, and copy prod→dev/stage SAFELY with fail-closed masking/anonymization (.sensitive()/.safe()) + referential subsetting. Use for data takeout, seeding lower envs, backups, or cross-dialect moves.",
|
|
247
|
+
module: "cli.md"
|
|
248
|
+
}
|
|
249
|
+
], Le = (e, t) => `---
|
|
250
|
+
name: ${e.name}
|
|
251
|
+
description: ${e.description}
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
Open the full reference and follow the patterns there:
|
|
255
|
+
|
|
256
|
+
\`${t}agent-docs/${e.module}\`
|
|
257
|
+
|
|
258
|
+
Also read the repo-root \`AGENTS.md\` for the always-true rules (browser/server
|
|
259
|
+
boundary, naming, anti-patterns) before editing.
|
|
260
|
+
`, Re = (e, n, r, i) => f.gen(function* () {
|
|
261
|
+
let a = yield* R(e, n);
|
|
262
|
+
if (a) {
|
|
263
|
+
if ((yield* z(e, n)).slice(0, we).includes("voltro:agents-md:keep")) return {
|
|
264
|
+
path: n,
|
|
265
|
+
action: "protected"
|
|
266
|
+
};
|
|
267
|
+
if (!i) return {
|
|
268
|
+
path: n,
|
|
269
|
+
action: "present"
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
return yield* e.makeDirectory(t(n), { recursive: !0 }).pipe(f.orElseSucceed(() => void 0)), yield* e.writeFileString(n, r).pipe(f.orDie), {
|
|
273
|
+
path: n,
|
|
274
|
+
action: a ? "overwritten" : "created"
|
|
275
|
+
};
|
|
276
|
+
}), ze = (e, t = {}) => f.gen(function* () {
|
|
277
|
+
let n = yield* c.FileSystem, i = yield* De(e), o = null;
|
|
278
|
+
for (let e of be) if (yield* R(n, r(e, "AGENTS.core.md"))) {
|
|
279
|
+
o = e;
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
if (o === null) {
|
|
283
|
+
for (let e of be) if (yield* R(n, r(e, "AGENTS.md"))) {
|
|
284
|
+
let a = yield* z(n, r(e, "AGENTS.md")), o = [];
|
|
285
|
+
for (let e of Se) o.push(yield* Re(n, r(i, e), a, t.force ?? !1));
|
|
286
|
+
return { files: o };
|
|
287
|
+
}
|
|
288
|
+
return yield* f.fail(xe(be.map((e) => r(e, "AGENTS.core.md"))));
|
|
289
|
+
}
|
|
290
|
+
let s = yield* z(n, r(o, "AGENTS.core.md")), l = yield* z(n, r(o, "agent-docs", "_manifest.json")), u = l ? JSON.parse(l) : {
|
|
291
|
+
modules: [],
|
|
292
|
+
plugins: []
|
|
293
|
+
}, d = (t.preferPointer ?? !1) || (yield* R(n, r(i, "node_modules/@voltro/cli/templates/agent-docs", "_manifest.json"))), p = d ? "node_modules/@voltro/cli/templates/" : "", m = t.force ?? !1, h = Se.map((e) => r(i, e));
|
|
294
|
+
if ((yield* f.forEach(h, (e) => z(n, e).pipe(f.map((e) => e.slice(0, we))))).every((e) => e.includes("voltro:agents-md:keep"))) return { files: h.map((e) => ({
|
|
295
|
+
path: e,
|
|
296
|
+
action: "protected"
|
|
297
|
+
})) };
|
|
298
|
+
let { apis: g, webs: _ } = yield* je(n, i), v = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Set(), b = !1;
|
|
299
|
+
for (let e of g) {
|
|
300
|
+
let t = yield* Ae(n, e);
|
|
301
|
+
if (v.set(e, t), t !== null) {
|
|
302
|
+
b = !0;
|
|
303
|
+
for (let e of t) y.add(e);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
let x = t.plugins ? t.plugins.map(ke).filter((e) => e !== null) : b ? [...y] : null, S = s.includes(Te) ? s.replace(Te, Ne(u, x, p)) : s, C = [];
|
|
307
|
+
for (let e of h) C.push(yield* Re(n, e, S, m));
|
|
308
|
+
d || (yield* Oe(n, r(o, "agent-docs"), r(i, "agent-docs")));
|
|
309
|
+
let w = new Map((t.appTemplates ?? []).map((e) => [a(e.dir), e.template])), T = (e) => {
|
|
310
|
+
let t = w.get(a(e));
|
|
311
|
+
return t ? Pe(t, u, p) : "";
|
|
312
|
+
}, E = (e, t) => f.forEach(Se, (i) => Re(n, r(e, i), t, m));
|
|
313
|
+
for (let e of g) C.push(...yield* E(e, Fe.api(p, v.get(e) ?? null, T(e)))), (yield* R(n, r(e, "database"))) && C.push(...yield* E(r(e, "database"), Fe.database(p)));
|
|
314
|
+
for (let e of _) C.push(...yield* E(e, Fe.web(p, T(e))));
|
|
315
|
+
for (let e of Ie) C.push(yield* Re(n, r(i, ".claude", "skills", e.name, "SKILL.md"), Le(e, p), m));
|
|
316
|
+
return { files: C };
|
|
317
|
+
}), Be = (e, t = {}) => f.runPromise(ze(e, t).pipe(f.provide(l.layer))), Ve = async (e) => {
|
|
318
|
+
let t = e.includes("--force"), n = e.find((e) => !e.startsWith("-")) ?? process.cwd();
|
|
319
|
+
return ve(f.gen(function* () {
|
|
320
|
+
let e = yield* ze(n, { force: t });
|
|
321
|
+
for (let t of e.files) {
|
|
322
|
+
let e = t.action === "created" ? "wrote" : t.action === "overwritten" ? "overwrote" : t.action === "protected" ? `protected (hand-maintained — has "${Ce}")` : "present (use --force to overwrite)";
|
|
323
|
+
yield* f.logInfo(`${t.path.split("/").slice(-2).join("/")} ${e}`, { action: t.action });
|
|
324
|
+
}
|
|
325
|
+
return 0;
|
|
326
|
+
}).pipe(f.catchTag("TemplateNotFoundError", (e) => f.gen(function* () {
|
|
327
|
+
return yield* f.logError("AGENTS.md template not found", { searched: e.searched }), 1;
|
|
328
|
+
}))), { scope: "voltro:agents-md" });
|
|
329
|
+
}, He = (e) => e.replace(/\\"|"(?:[^"\\]|\\.)*"|(\/\/[^\n]*|\/\*[\s\S]*?\*\/)/g, (e, t) => t ? "" : e), Ue = (e) => {
|
|
330
|
+
try {
|
|
331
|
+
let t = r(e, "tsconfig.json");
|
|
332
|
+
if (!y(t)) return [];
|
|
333
|
+
let n = JSON.parse(He(C(t, "utf8"))).compilerOptions ?? {}, i = n.paths ?? {}, o = a(e, n.baseUrl ?? "."), s = [];
|
|
334
|
+
for (let [e, t] of Object.entries(i)) {
|
|
335
|
+
let n = t[0];
|
|
336
|
+
if (!n) continue;
|
|
337
|
+
let i = n.replace(/\\/g, "/");
|
|
338
|
+
if (!(i.includes("/@types/") || i.endsWith(".d.ts"))) if (e.endsWith("/*") && n.endsWith("/*")) {
|
|
339
|
+
let t = e.slice(0, -2).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
340
|
+
s.push({
|
|
341
|
+
find: RegExp(`^${t}/(.*)$`),
|
|
342
|
+
replacement: `${r(o, n.slice(0, -2))}/$1`
|
|
343
|
+
});
|
|
344
|
+
} else s.push({
|
|
345
|
+
find: e,
|
|
346
|
+
replacement: r(o, n)
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
return s;
|
|
350
|
+
} catch {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
}, We = (e) => {
|
|
354
|
+
let t = e;
|
|
355
|
+
return t?.code === "ERR_MODULE_NOT_FOUND" || /Cannot find (package|module)/.test(String(t?.message ?? ""));
|
|
356
|
+
}, Ge = async (e, t) => {
|
|
357
|
+
try {
|
|
358
|
+
return await t();
|
|
359
|
+
} catch (t) {
|
|
360
|
+
throw We(t) ? Error(`voltro: the build tool '${e}' is not installed.\n\nIt's an OPTIONAL dependency of @voltro/cli — needed by 'voltro dev' and 'voltro build', but excluded from a serve-only production install (that's how prod images stay lean). If you are building, reinstall WITHOUT '--no-optional' (e.g. 'pnpm install'). A production SERVE container does not need '${e}' — it boots from the precompiled bundle.`) : t;
|
|
361
|
+
}
|
|
362
|
+
}, Ke = "// AUTO-GENERATED by Voltro — DO NOT EDIT.\n// Source: app.config.ts `env` (defineEnv). Regenerated on every `voltro dev` boot.\n", qe = (e, t) => t ? `${e} | undefined` : e, Je = (e, t) => Object.entries(e.vars).filter(([, e]) => t(e.access)).map(([e, t]) => `${t.description ? ` /** ${t.description} */\n` : ""} readonly ${e}: ${qe(t.tsType, t.optional)}`).join("\n"), Ye = async (e, t) => {
|
|
363
|
+
let n = Je(t, () => !0), i = `${Ke}
|
|
364
|
+
import '@voltro/env/server'
|
|
365
|
+
|
|
366
|
+
declare module '@voltro/env/server' {
|
|
367
|
+
interface ServerEnv {
|
|
368
|
+
${n.length > 0 ? n : " // (no variables declared)"}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
`;
|
|
372
|
+
await j(r(e, "env.generated.d.ts"), i, "utf8");
|
|
373
|
+
}, Xe = async (e, t) => {
|
|
374
|
+
let n = Je(t, (e) => e === "public"), i = `${Ke}
|
|
375
|
+
import '@voltro/env/public'
|
|
376
|
+
|
|
377
|
+
declare module '@voltro/env/public' {
|
|
378
|
+
interface PublicEnv {
|
|
379
|
+
${n.length > 0 ? n : " // (no public variables declared)"}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
`, a = r(e, "src");
|
|
383
|
+
await A(a, { recursive: !0 }), await j(r(a, "voltro-env.d.ts"), i, "utf8");
|
|
384
|
+
}, Ze = async (e, t) => {
|
|
385
|
+
let n = `${Ke}
|
|
386
|
+
import { __installPublicEnv } from '@voltro/env/public'
|
|
387
|
+
|
|
388
|
+
export const publicEnvValues = ${JSON.stringify(t, null, 2)} as const
|
|
389
|
+
|
|
390
|
+
// Set the browser/SSR-shared global the \`publicEnv\` accessor reads.
|
|
391
|
+
__installPublicEnv(publicEnvValues)
|
|
392
|
+
`;
|
|
393
|
+
await A(e, { recursive: !0 }), await j(r(e, "env.public.ts"), n, "utf8");
|
|
394
|
+
}, Qe = async (e) => {
|
|
395
|
+
let t = se(e.rawEnv) ? e.rawEnv : void 0, n = await le({
|
|
396
|
+
contract: t,
|
|
397
|
+
resolveSecret: k
|
|
398
|
+
}), r = [...n.errors, ...ie(t, e.appType)];
|
|
399
|
+
if (r.length > 0) throw Error(ae(r));
|
|
400
|
+
oe(n.values), e.appType === "web" && ue(n.publicValues);
|
|
401
|
+
let i = t ? Object.keys(t.vars).length : 0;
|
|
402
|
+
if (i > 0) {
|
|
403
|
+
let r = Object.keys(n.publicValues).length;
|
|
404
|
+
if (e.log.info(`env: ${i} declared var(s) validated`, {
|
|
405
|
+
public: r,
|
|
406
|
+
secret: i - r
|
|
407
|
+
}), e.appType === "web" && t) {
|
|
408
|
+
let n = Object.entries(t.vars).filter(([, e]) => e.access === "secret").map(([e]) => e);
|
|
409
|
+
n.length > 0 && e.log.warn(`env: ${n.length} secret var(s) declared on a web app — secrets are reachable only from server-side render code and are NEVER bundled. Prefer declaring secrets on the api.`, { keys: n });
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return e.generateTypes && t && (e.appType === "api" ? await Ye(e.root, t) : await Xe(e.root, t)), {
|
|
413
|
+
resolved: n,
|
|
414
|
+
contract: t
|
|
415
|
+
};
|
|
416
|
+
}, B = g({ scope: "vite" }), $e = /\x1b\[[0-9;]*m/g, et = /^\s*\[?vite\]?\s*(\([a-z-]+\)\s*)?/, tt = (e) => e.replace($e, "").replace(et, "").trim(), nt = /proxy error/i, rt = [
|
|
417
|
+
"ECONNREFUSED",
|
|
418
|
+
"ECONNRESET",
|
|
419
|
+
"ECONNABORTED",
|
|
420
|
+
"EPIPE",
|
|
421
|
+
"ETIMEDOUT"
|
|
422
|
+
], it = (e, t = 0) => {
|
|
423
|
+
if (e == null || t > 5) return !1;
|
|
424
|
+
let n = e;
|
|
425
|
+
return typeof n.code == "string" && rt.includes(n.code) || typeof n.message == "string" && rt.some((e) => n.message.includes(e)) || Array.isArray(n.errors) && n.errors.some((e) => it(e, t + 1)) ? !0 : it(n.cause, t + 1);
|
|
426
|
+
}, at = 4e3, ot = () => {
|
|
427
|
+
let e = /* @__PURE__ */ new Set(), t = 0, n = {
|
|
428
|
+
hasWarned: !1,
|
|
429
|
+
info: (e) => {
|
|
430
|
+
let t = tt(e);
|
|
431
|
+
t.length !== 0 && B.info(t);
|
|
432
|
+
},
|
|
433
|
+
warn: (e) => {
|
|
434
|
+
n.hasWarned = !0;
|
|
435
|
+
let t = tt(e);
|
|
436
|
+
t.length !== 0 && B.warn(t);
|
|
437
|
+
},
|
|
438
|
+
warnOnce: (t) => {
|
|
439
|
+
let r = tt(t);
|
|
440
|
+
e.has(r) || (e.add(r), n.hasWarned = !0, r.length !== 0 && B.warn(r));
|
|
441
|
+
},
|
|
442
|
+
error: (e, n) => {
|
|
443
|
+
let r = tt(e), i = n?.error;
|
|
444
|
+
if (r.length !== 0) {
|
|
445
|
+
if (nt.test(r) && it(i)) {
|
|
446
|
+
let e = Date.now();
|
|
447
|
+
e - t > at && (t = e, B.info("waiting for api — proxy upstream not accepting connections yet (still starting?)"));
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
B.error(r, {}, i);
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
clearScreen: () => {},
|
|
454
|
+
hasErrorLogged: (e) => !1
|
|
455
|
+
};
|
|
456
|
+
return n;
|
|
457
|
+
}, st = (e) => {
|
|
458
|
+
let t = [];
|
|
459
|
+
for (let n of e.split("/").filter(Boolean)) n.startsWith("[[...") && n.endsWith("]]") ? t.push({
|
|
460
|
+
name: n.slice(5, -2),
|
|
461
|
+
catchAll: !0,
|
|
462
|
+
optional: !0
|
|
463
|
+
}) : n.startsWith("[...") && n.endsWith("]") ? t.push({
|
|
464
|
+
name: n.slice(4, -1),
|
|
465
|
+
catchAll: !0,
|
|
466
|
+
optional: !1
|
|
467
|
+
}) : n.startsWith("[") && n.endsWith("]") && t.push({
|
|
468
|
+
name: n.slice(1, -1),
|
|
469
|
+
catchAll: !1,
|
|
470
|
+
optional: !1
|
|
471
|
+
});
|
|
472
|
+
return t;
|
|
473
|
+
}, ct = (e) => e.replace(/-([a-z0-9])/g, (e, t) => t.toUpperCase()), lt = async (e) => {
|
|
474
|
+
let n = a(e);
|
|
475
|
+
for (let e = 0; e < 4; e++) {
|
|
476
|
+
let e = r(n, "project.json");
|
|
477
|
+
if (y(e)) try {
|
|
478
|
+
let t = await S.readFile(e, "utf8");
|
|
479
|
+
return {
|
|
480
|
+
projectDir: n,
|
|
481
|
+
manifest: JSON.parse(t)
|
|
482
|
+
};
|
|
483
|
+
} catch {
|
|
484
|
+
return null;
|
|
485
|
+
}
|
|
486
|
+
let i = t(n);
|
|
487
|
+
if (i === n) break;
|
|
488
|
+
n = i;
|
|
489
|
+
}
|
|
490
|
+
return null;
|
|
491
|
+
}, ut = async (t) => {
|
|
492
|
+
let n = await lt(t);
|
|
493
|
+
if (!n) return [];
|
|
494
|
+
let { projectDir: i, manifest: a } = n, o = e(t), s = a.apps ?? {}, c = [];
|
|
495
|
+
for (let [e, t] of Object.entries(s)) {
|
|
496
|
+
if (e === o || t.kind !== "web" || typeof t.port != "number") continue;
|
|
497
|
+
let n = r(r(i, t.path ?? e), "src", "pages");
|
|
498
|
+
if (!y(n)) continue;
|
|
499
|
+
let a;
|
|
500
|
+
try {
|
|
501
|
+
let { pages: e } = await $(n);
|
|
502
|
+
a = e.map((e) => ({
|
|
503
|
+
pattern: e.pattern,
|
|
504
|
+
params: st(e.pattern)
|
|
505
|
+
}));
|
|
506
|
+
} catch {
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
c.push({
|
|
510
|
+
key: ct(e),
|
|
511
|
+
origin: `http://localhost:${t.port}`,
|
|
512
|
+
...typeof t.origin == "string" && t.origin.length > 0 ? { prodOrigin: t.origin } : {},
|
|
513
|
+
routes: a
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
return c;
|
|
517
|
+
}, dt = (e) => {
|
|
518
|
+
if (e.params.length === 0) return `'${e.pattern}'`;
|
|
519
|
+
let t = e.pattern;
|
|
520
|
+
for (let n of e.params) {
|
|
521
|
+
let e = n.optional ? `[[...${n.name}]]` : n.catchAll ? `[...${n.name}]` : `[${n.name}]`, r = n.optional ? "${" + n.name + " === undefined ? \"\" : encodeURI(" + n.name + ")}" : n.catchAll ? "${encodeURI(" + n.name + ")}" : "${encodeURIComponent(" + n.name + ")}";
|
|
522
|
+
t = t.replace(e, r);
|
|
523
|
+
}
|
|
524
|
+
return "`" + t + "`";
|
|
525
|
+
}, ft = (e) => e.params.length === 0 ? "EmptyParams" : `{ ${e.params.map((e) => {
|
|
526
|
+
let t = "string";
|
|
527
|
+
return e.optional ? `readonly ${e.name}?: ${t}` : `readonly ${e.name}: ${t}`;
|
|
528
|
+
}).join("; ")} }`, pt = (e, t, n) => {
|
|
529
|
+
let r = ft(e), i = dt(e), a = t ? "VoltroExternalUrl" : "VoltroRouteUrl", o = t && n ? `${n} + ` : "";
|
|
530
|
+
return e.params.length === 0 ? `() => (${o}${i}) as ${a}` : `({ ${e.params.map((e) => e.name).join(", ")} }: ${r}) => (${o}${i}) as ${a}`;
|
|
531
|
+
}, mt = (e) => `{\n${[...e].sort((e, t) => e.pattern.localeCompare(t.pattern)).map((e) => ` ${JSON.stringify(e.pattern)}: ${pt(e, !1)},`).join("\n")}\n}`, ht = (e, t) => {
|
|
532
|
+
if (e.routes.length === 0) return ` ${e.key}: {} as Record<string, never>,`;
|
|
533
|
+
let n = [...e.routes].sort((e, t) => e.pattern.localeCompare(t.pattern)), r = t === "prod" && e.prodOrigin ? e.prodOrigin : e.origin, i = JSON.stringify(r), a = n.map((e) => ` ${JSON.stringify(e.pattern)}: ${pt(e, !0, i)},`);
|
|
534
|
+
return ` ${e.key}: {\n${a.join("\n")}\n },`;
|
|
535
|
+
}, gt = async (e) => {
|
|
536
|
+
let n = e.pages.map((e) => ({
|
|
537
|
+
pattern: e.pattern,
|
|
538
|
+
params: st(e.pattern)
|
|
539
|
+
})), i = await ut(e.appRoot), a = [
|
|
540
|
+
"// THIS FILE IS GENERATED — DO NOT EDIT BY HAND.",
|
|
541
|
+
"// Re-emitted by `voltro dev` whenever `src/pages/**` changes.",
|
|
542
|
+
"// Type-safe route builders consumed by <Link to={...}>.",
|
|
543
|
+
"",
|
|
544
|
+
"import type { VoltroRouteUrl, VoltroExternalUrl } from '@voltro/web'",
|
|
545
|
+
"",
|
|
546
|
+
"type EmptyParams = Record<string, never>",
|
|
547
|
+
""
|
|
548
|
+
].join("\n"), o = e.mode ?? "dev", s = `${a}\n${`export const routes = ${mt(n)} as const\n`}\n${i.length === 0 ? "export const siblingApps = {} as Record<string, never>\n" : `export const siblingApps = {\n${i.map((e) => ht(e, o)).join("\n")}\n} as const\n`}`, c = r(e.appRoot, ".framework", "routes.generated.ts");
|
|
549
|
+
await S.mkdir(t(c), { recursive: !0 });
|
|
550
|
+
let l = null;
|
|
551
|
+
try {
|
|
552
|
+
l = await S.readFile(c, "utf8");
|
|
553
|
+
} catch {}
|
|
554
|
+
return l === s ? {
|
|
555
|
+
path: c,
|
|
556
|
+
wrote: !1
|
|
557
|
+
} : (await S.writeFile(c, s, "utf8"), {
|
|
558
|
+
path: c,
|
|
559
|
+
wrote: !0
|
|
560
|
+
});
|
|
561
|
+
}, _t = (e) => {
|
|
562
|
+
let t = N(e.contract), n = (e.plugins ?? []).flatMap((e) => ce(e.name, e.declaredEnv)), r = e.includeFramework === !1 ? [] : M, i = /* @__PURE__ */ new Set(), a = [];
|
|
563
|
+
for (let e of [
|
|
564
|
+
...t,
|
|
565
|
+
...n,
|
|
566
|
+
...r
|
|
567
|
+
]) i.has(e.key) || (i.add(e.key), a.push(e));
|
|
568
|
+
return a;
|
|
569
|
+
}, vt = (e, t, n = (e) => process.env[e]) => {
|
|
570
|
+
let r = _t(t).map((e) => {
|
|
571
|
+
let t = n(e.key) !== void 0;
|
|
572
|
+
return {
|
|
573
|
+
...e,
|
|
574
|
+
isSet: t,
|
|
575
|
+
satisfied: t || e.default !== void 0 || !e.required
|
|
576
|
+
};
|
|
577
|
+
});
|
|
578
|
+
return {
|
|
579
|
+
app: e,
|
|
580
|
+
entries: r,
|
|
581
|
+
summary: {
|
|
582
|
+
total: r.length,
|
|
583
|
+
set: r.filter((e) => e.isSet).length,
|
|
584
|
+
missingRequired: r.filter((e) => e.required && !e.isSet && e.default === void 0).length
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
}, yt = (e, t) => P(_t({
|
|
588
|
+
...e,
|
|
589
|
+
includeFramework: !1
|
|
590
|
+
}), {
|
|
591
|
+
includeFramework: e.includeFramework !== !1,
|
|
592
|
+
...t ? { header: t } : {}
|
|
593
|
+
}), V = "/_voltro/inspect", H = () => process.env.VOLTRO_INSPECT === "off", U = (e) => {
|
|
594
|
+
let t = process.env.VOLTRO_INSPECT_TOKEN;
|
|
595
|
+
if (!t || t.length === 0) return { ok: !0 };
|
|
596
|
+
let n = e.authorization ?? e.Authorization;
|
|
597
|
+
return n ? n.startsWith("Bearer ") ? pe(n.slice(7).trim(), t) ? { ok: !0 } : {
|
|
598
|
+
ok: !1,
|
|
599
|
+
reason: "token mismatch"
|
|
600
|
+
} : {
|
|
601
|
+
ok: !1,
|
|
602
|
+
reason: "expected \"Bearer <token>\" auth scheme"
|
|
603
|
+
} : {
|
|
604
|
+
ok: !1,
|
|
605
|
+
reason: "missing Authorization header"
|
|
606
|
+
};
|
|
607
|
+
}, bt = (e) => {
|
|
608
|
+
if (!Array.isArray(e) || e.length === 0) return;
|
|
609
|
+
let t = [];
|
|
610
|
+
for (let n of e) {
|
|
611
|
+
if (typeof n != "object" || !n) continue;
|
|
612
|
+
if (typeof n.action == "string" && typeof n.resourceType == "string") {
|
|
613
|
+
t.push({
|
|
614
|
+
kind: "policy",
|
|
615
|
+
action: n.action,
|
|
616
|
+
resourceType: n.resourceType
|
|
617
|
+
});
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
let e = n.scope;
|
|
621
|
+
typeof e != "string" && !Array.isArray(e) || t.push({
|
|
622
|
+
kind: "scope",
|
|
623
|
+
scope: typeof e == "string" ? [e] : e.filter((e) => typeof e == "string"),
|
|
624
|
+
mode: n.mode === "any" ? "any" : "all",
|
|
625
|
+
resourceScoped: typeof n.resource == "function"
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
return t.length > 0 ? t : void 0;
|
|
629
|
+
}, W = (e, t, n = {}) => ({
|
|
630
|
+
status: e,
|
|
631
|
+
contentType: "application/json; charset=utf-8",
|
|
632
|
+
body: JSON.stringify(t),
|
|
633
|
+
headers: n
|
|
634
|
+
}), G = (e) => !e || e.length === 0 ? {} : {
|
|
635
|
+
"access-control-allow-origin": e,
|
|
636
|
+
"access-control-allow-credentials": "true",
|
|
637
|
+
"access-control-allow-methods": "GET, POST, OPTIONS",
|
|
638
|
+
"access-control-allow-headers": "authorization, content-type, accept",
|
|
639
|
+
"access-control-expose-headers": "content-type, content-length",
|
|
640
|
+
vary: "Origin"
|
|
641
|
+
}, K = (e) => {
|
|
642
|
+
let t = e.indexOf("?");
|
|
643
|
+
return t === -1 ? e : e.slice(0, t);
|
|
644
|
+
}, xt = (e) => {
|
|
645
|
+
let t = e.indexOf("?");
|
|
646
|
+
return t === -1 ? new URLSearchParams() : new URLSearchParams(e.slice(t + 1));
|
|
647
|
+
}, St = (e) => e === "/_voltro/inspect" || e.startsWith("/_voltro/inspect/"), Ct = [
|
|
648
|
+
"text",
|
|
649
|
+
"textarea",
|
|
650
|
+
"number",
|
|
651
|
+
"checkbox",
|
|
652
|
+
"switch",
|
|
653
|
+
"select",
|
|
654
|
+
"radio",
|
|
655
|
+
"async-select",
|
|
656
|
+
"multi-select",
|
|
657
|
+
"date",
|
|
658
|
+
"datetime",
|
|
659
|
+
"daterange",
|
|
660
|
+
"file",
|
|
661
|
+
"hidden",
|
|
662
|
+
"custom"
|
|
663
|
+
], wt = (e, t, n = []) => ({
|
|
664
|
+
version: 2,
|
|
665
|
+
procedures: [...e].sort((e, t) => e.tag.localeCompare(t.tag)).map((e) => ({
|
|
666
|
+
tag: e.tag,
|
|
667
|
+
kind: e.kind,
|
|
668
|
+
...e.inputSchema === void 0 ? {} : { input: e.inputSchema },
|
|
669
|
+
...e.outputSchema === void 0 ? {} : { output: e.outputSchema },
|
|
670
|
+
...e.source === void 0 ? {} : { source: e.source },
|
|
671
|
+
...e.targets === void 0 ? {} : { targets: e.targets },
|
|
672
|
+
...e.guards === void 0 ? {} : { guards: e.guards },
|
|
673
|
+
...e.publicApi === void 0 ? {} : { publicApi: e.publicApi },
|
|
674
|
+
...e.exposeAsTool === void 0 ? {} : { exposeAsTool: e.exposeAsTool }
|
|
675
|
+
})),
|
|
676
|
+
workflows: [...t].sort((e, t) => e.tag.localeCompare(t.tag)).map((e) => ({ name: e.tag })),
|
|
677
|
+
widgets: Ct,
|
|
678
|
+
tables: [...n].filter((e) => !e.isFrameworkTable).sort((e, t) => e.name.localeCompare(t.name)).map((e) => ({
|
|
679
|
+
name: e.name,
|
|
680
|
+
reactive: e.isReactive,
|
|
681
|
+
framework: e.isFrameworkTable,
|
|
682
|
+
columns: e.columns.map((e) => ({
|
|
683
|
+
name: e.name,
|
|
684
|
+
type: String(e.type),
|
|
685
|
+
nullable: e.nullable,
|
|
686
|
+
...e.referencesTable === void 0 ? {} : { refersTo: e.referencesTable },
|
|
687
|
+
...e.oneOf === void 0 ? {} : { enum: e.oneOf }
|
|
688
|
+
}))
|
|
689
|
+
}))
|
|
690
|
+
}), Tt = (e, t, n = {}, r = {}) => {
|
|
691
|
+
let i = K(e);
|
|
692
|
+
if (!St(i)) return null;
|
|
693
|
+
let a = G(n.origin ?? n.Origin);
|
|
694
|
+
if ((r.method ?? "GET").toUpperCase() === "OPTIONS") return {
|
|
695
|
+
status: 204,
|
|
696
|
+
contentType: "text/plain",
|
|
697
|
+
body: "",
|
|
698
|
+
headers: a
|
|
699
|
+
};
|
|
700
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, a);
|
|
701
|
+
let o = (r.authResolver ?? U)(n);
|
|
702
|
+
if (!o.ok) return W(401, {
|
|
703
|
+
error: "unauthorized",
|
|
704
|
+
reason: o.reason
|
|
705
|
+
}, a);
|
|
706
|
+
if (i === "/_voltro/inspect" || i === "/_voltro/inspect/" || i === "/_voltro/inspect/app") return W(200, {
|
|
707
|
+
kind: t.kind,
|
|
708
|
+
...t.meta
|
|
709
|
+
}, a);
|
|
710
|
+
if (i === "/_voltro/inspect/routes") return t.kind === "web" ? W(200, {
|
|
711
|
+
pages: t.routes,
|
|
712
|
+
dirs: t.dirs
|
|
713
|
+
}, a) : W(404, { error: "routes endpoint is web-only" }, a);
|
|
714
|
+
if (i === "/_voltro/inspect/cache") return t.kind === "web" ? W(200, t.cache(), a) : W(404, { error: "cache endpoint is web-only" }, a);
|
|
715
|
+
if (i === "/_voltro/inspect/rpc") return t.kind === "api" ? W(200, {
|
|
716
|
+
procedures: t.rpc,
|
|
717
|
+
workflows: t.workflows
|
|
718
|
+
}, a) : W(404, { error: "rpc endpoint is api-only" }, a);
|
|
719
|
+
if (i === "/_voltro/inspect/manifest") {
|
|
720
|
+
if (t.kind !== "api") return W(404, { error: "manifest endpoint is api-only" }, a);
|
|
721
|
+
let e = t.inspectTables?.().tables ?? [];
|
|
722
|
+
return W(200, wt(t.rpc, t.workflows, e), a);
|
|
723
|
+
}
|
|
724
|
+
return i === "/_voltro/inspect/metrics" ? t.metrics === void 0 ? W(200, [], a) : W(200, t.metrics(), a) : i === "/_voltro/inspect/subscriptions" ? t.kind === "api" ? t.subscriptions === void 0 ? W(200, {
|
|
725
|
+
subscriptions: [],
|
|
726
|
+
matcherStats: [],
|
|
727
|
+
capturedAt: Date.now()
|
|
728
|
+
}, a) : W(200, t.subscriptions(), a) : W(404, { error: "subscriptions endpoint is api-only" }, a) : i === "/_voltro/inspect/data-cache" ? t.kind === "api" ? t.dataCache === void 0 ? W(200, {
|
|
729
|
+
backend: "memory",
|
|
730
|
+
engine: "memory",
|
|
731
|
+
driver: "resp",
|
|
732
|
+
hits: 0,
|
|
733
|
+
misses: 0,
|
|
734
|
+
hitRate: 0
|
|
735
|
+
}, a) : W(200, t.dataCache(), a) : W(404, { error: "data-cache endpoint is api-only" }, a) : i === "/_voltro/inspect/database" ? t.kind === "api" ? t.database === void 0 ? W(200, {
|
|
736
|
+
migrations: [],
|
|
737
|
+
seeds: []
|
|
738
|
+
}, a) : W(200, t.database(), a) : W(404, { error: "database endpoint is api-only" }, a) : i === "/_voltro/inspect/plugins" ? t.kind === "api" ? t.plugins === void 0 ? W(200, {
|
|
739
|
+
plugins: [],
|
|
740
|
+
capturedAt: Date.now()
|
|
741
|
+
}, a) : W(200, t.plugins(), a) : W(404, { error: "plugins endpoint is api-only" }, a) : i === "/_voltro/inspect/env" ? t.env === void 0 ? W(200, {
|
|
742
|
+
app: t.meta.name ?? "app",
|
|
743
|
+
entries: [],
|
|
744
|
+
summary: {
|
|
745
|
+
total: 0,
|
|
746
|
+
set: 0,
|
|
747
|
+
missingRequired: 0
|
|
748
|
+
}
|
|
749
|
+
}, a) : W(200, t.env(), a) : i === "/_voltro/inspect/data/tables" ? t.kind === "api" ? t.inspectTables === void 0 ? W(200, { tables: [] }, a) : W(200, t.inspectTables(), a) : W(404, { error: "data viewer is api-only" }, a) : i === "/_voltro/inspect/invoke" ? W(404, { error: "invoke not enabled here — use POST handler" }, a) : W(404, {
|
|
750
|
+
error: "unknown inspect endpoint",
|
|
751
|
+
path: i
|
|
752
|
+
}, a);
|
|
753
|
+
}, Et = async (e, t, n, r = {}) => {
|
|
754
|
+
let i = G(t.origin ?? t.Origin);
|
|
755
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, i);
|
|
756
|
+
if ((r.method ?? "POST").toUpperCase() !== "POST") return W(405, {
|
|
757
|
+
error: "method not allowed",
|
|
758
|
+
expected: "POST"
|
|
759
|
+
}, i);
|
|
760
|
+
let a = (r.authResolver ?? U)(t);
|
|
761
|
+
if (!a.ok) return W(401, {
|
|
762
|
+
error: "unauthorized",
|
|
763
|
+
reason: a.reason
|
|
764
|
+
}, i);
|
|
765
|
+
if (e.kind !== "api") return W(404, { error: "invoke endpoint is api-only" }, i);
|
|
766
|
+
if (!e.invokers || e.invokers.size === 0) return W(404, { error: "invoke not configured" }, i);
|
|
767
|
+
let o;
|
|
768
|
+
try {
|
|
769
|
+
o = JSON.parse(n || "{}");
|
|
770
|
+
} catch {
|
|
771
|
+
return W(400, { error: "body must be JSON" }, i);
|
|
772
|
+
}
|
|
773
|
+
let s = o;
|
|
774
|
+
if (typeof s.tag != "string") return W(400, { error: "body.tag must be a string" }, i);
|
|
775
|
+
let c = e.invokers.get(s.tag);
|
|
776
|
+
if (!c) return W(404, {
|
|
777
|
+
error: "unknown tag",
|
|
778
|
+
tag: s.tag
|
|
779
|
+
}, i);
|
|
780
|
+
let l = typeof s.headers == "object" && s.headers !== null ? s.headers : {}, u = {};
|
|
781
|
+
for (let [e, n] of Object.entries(t)) u[e.toLowerCase()] = n;
|
|
782
|
+
for (let [e, t] of Object.entries(l)) {
|
|
783
|
+
let n = e.toLowerCase();
|
|
784
|
+
n !== "cookie" && (u[n] = t);
|
|
785
|
+
}
|
|
786
|
+
return W(200, await c(s.input, u), i);
|
|
787
|
+
}, Dt = async (e, t, n, r, i = {}) => {
|
|
788
|
+
let a = K(e);
|
|
789
|
+
if (!St(a) || !a.startsWith("/_voltro/inspect/webhooks/")) return null;
|
|
790
|
+
let o = G(n.origin ?? n.Origin);
|
|
791
|
+
if ((i.method ?? "POST").toUpperCase() !== "POST") return null;
|
|
792
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, o);
|
|
793
|
+
let s = (i.authResolver ?? U)(n);
|
|
794
|
+
if (!s.ok) return W(401, {
|
|
795
|
+
error: "unauthorized",
|
|
796
|
+
reason: s.reason
|
|
797
|
+
}, o);
|
|
798
|
+
if (t.kind !== "api") return W(404, { error: "webhook actions are api-only" }, o);
|
|
799
|
+
if (!t.webhookActions) return W(404, { error: "webhook actions not configured — is @voltro/plugin-webhooks active?" }, o);
|
|
800
|
+
let c;
|
|
801
|
+
try {
|
|
802
|
+
c = JSON.parse(r || "{}");
|
|
803
|
+
} catch {
|
|
804
|
+
return W(400, { error: "body must be JSON" }, o);
|
|
805
|
+
}
|
|
806
|
+
let l = a.slice(`${V}/webhooks/`.length);
|
|
807
|
+
try {
|
|
808
|
+
switch (l) {
|
|
809
|
+
case "subscribe": {
|
|
810
|
+
let e = c;
|
|
811
|
+
return typeof e.event != "string" || e.event.length === 0 ? W(400, { error: "event required" }, o) : typeof e.url != "string" || e.url.length === 0 ? W(400, { error: "url required" }, o) : W(200, await t.webhookActions.subscribe(e), o);
|
|
812
|
+
}
|
|
813
|
+
case "pause": {
|
|
814
|
+
let e = c.targetId;
|
|
815
|
+
return typeof e != "string" || e.length === 0 ? W(400, { error: "targetId required" }, o) : (await t.webhookActions.pause(e), W(200, { ok: !0 }, o));
|
|
816
|
+
}
|
|
817
|
+
case "resume": {
|
|
818
|
+
let e = c.targetId;
|
|
819
|
+
return typeof e != "string" || e.length === 0 ? W(400, { error: "targetId required" }, o) : (await t.webhookActions.resume(e), W(200, { ok: !0 }, o));
|
|
820
|
+
}
|
|
821
|
+
case "delete": {
|
|
822
|
+
let e = c.targetId;
|
|
823
|
+
return typeof e != "string" || e.length === 0 ? W(400, { error: "targetId required" }, o) : (await t.webhookActions.delete(e), W(200, { ok: !0 }, o));
|
|
824
|
+
}
|
|
825
|
+
case "rotateSecret": {
|
|
826
|
+
let e = c.targetId;
|
|
827
|
+
return typeof e != "string" || e.length === 0 ? W(400, { error: "targetId required" }, o) : W(200, await t.webhookActions.rotateSecret(e), o);
|
|
828
|
+
}
|
|
829
|
+
case "replay": {
|
|
830
|
+
let e = c.deliveryId;
|
|
831
|
+
return typeof e != "string" || e.length === 0 ? W(400, { error: "deliveryId required" }, o) : (await t.webhookActions.replay(e), W(200, { ok: !0 }, o));
|
|
832
|
+
}
|
|
833
|
+
case "repinVersion": {
|
|
834
|
+
let e = c.targetId, n = c.version;
|
|
835
|
+
return typeof e != "string" || e.length === 0 ? W(400, { error: "targetId required" }, o) : typeof n != "number" || !Number.isInteger(n) || n < 1 ? W(400, { error: "version must be a positive integer" }, o) : (await t.webhookActions.updateTargetPayloadVersion(e, n), W(200, { ok: !0 }, o));
|
|
836
|
+
}
|
|
837
|
+
default: return W(404, { error: `unknown webhook action: ${l}` }, o);
|
|
838
|
+
}
|
|
839
|
+
} catch (e) {
|
|
840
|
+
return W(500, {
|
|
841
|
+
error: "webhook action failed",
|
|
842
|
+
message: e?.message ?? String(e)
|
|
843
|
+
}, o);
|
|
844
|
+
}
|
|
845
|
+
}, Ot = async (e, t, n, r, i = {}) => {
|
|
846
|
+
let a = K(e);
|
|
847
|
+
if (!St(a)) return null;
|
|
848
|
+
let o = G(n.origin ?? n.Origin);
|
|
849
|
+
if ((i.method ?? "POST").toUpperCase() !== "POST") return null;
|
|
850
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, o);
|
|
851
|
+
let s = (i.authResolver ?? U)(n);
|
|
852
|
+
if (!s.ok) return W(401, {
|
|
853
|
+
error: "unauthorized",
|
|
854
|
+
reason: s.reason
|
|
855
|
+
}, o);
|
|
856
|
+
if (t.kind !== "api") return W(404, { error: "framework-action endpoints are api-only" }, o);
|
|
857
|
+
let c = `${V}/seeds/run`, l = `${V}/migrations/rollback`, u = `${V}/migrations/squash`, d = `${V}/migrations/restore-snapshot`;
|
|
858
|
+
if (a !== c && a !== l && a !== u && a !== d && a !== "/_voltro/inspect/migrations/compare-env") return null;
|
|
859
|
+
let f;
|
|
860
|
+
try {
|
|
861
|
+
f = JSON.parse(r || "{}");
|
|
862
|
+
} catch {
|
|
863
|
+
return W(400, { error: "body must be JSON" }, o);
|
|
864
|
+
}
|
|
865
|
+
try {
|
|
866
|
+
if (a === c) return typeof f.id != "string" || f.id.length === 0 ? W(400, { error: "body.id must be a non-empty string" }, o) : t.runSeed ? W(200, await t.runSeed(f.id), o) : W(404, { error: "runSeed not configured" }, o);
|
|
867
|
+
if (a === l) return typeof f.id != "string" || f.id.length === 0 ? W(400, { error: "body.id must be a non-empty string" }, o) : t.rollbackMigration ? W(200, await t.rollbackMigration(f.id), o) : W(404, { error: "rollbackMigration not configured" }, o);
|
|
868
|
+
if (a === u) {
|
|
869
|
+
if (typeof f.before != "string" || f.before.length === 0) return W(400, { error: "body.before must be a non-empty ISO date string" }, o);
|
|
870
|
+
if (!t.squashMigrationHistory) return W(404, { error: "squashMigrationHistory not configured" }, o);
|
|
871
|
+
let e = typeof f.note == "string" ? f.note : void 0;
|
|
872
|
+
return W(200, await t.squashMigrationHistory({
|
|
873
|
+
before: f.before,
|
|
874
|
+
note: e
|
|
875
|
+
}), o);
|
|
876
|
+
}
|
|
877
|
+
return a === d ? typeof f.planId != "string" || f.planId.length === 0 ? W(400, { error: "body.planId must be a non-empty string" }, o) : t.restoreSnapshot ? W(200, await t.restoreSnapshot({ planId: f.planId }), o) : W(404, { error: "restoreSnapshot not configured" }, o) : typeof f.url != "string" || f.url.length === 0 ? W(400, { error: "body.url must be a non-empty URL string" }, o) : t.compareCrossEnv ? (await t.compareCrossEnv({
|
|
878
|
+
url: f.url,
|
|
879
|
+
label: typeof f.label == "string" ? f.label : void 0,
|
|
880
|
+
token: typeof f.token == "string" ? f.token : void 0
|
|
881
|
+
}), W(200, { ok: !0 }, o)) : W(404, { error: "compareCrossEnv not configured" }, o);
|
|
882
|
+
} catch (e) {
|
|
883
|
+
return W(500, {
|
|
884
|
+
error: "framework action failed",
|
|
885
|
+
message: e?.message ?? String(e)
|
|
886
|
+
}, o);
|
|
887
|
+
}
|
|
888
|
+
}, kt = async (e, t, n, r = {}) => {
|
|
889
|
+
if (K(e) !== "/_voltro/inspect/data/rows") return null;
|
|
890
|
+
let i = G(n.origin ?? n.Origin);
|
|
891
|
+
if ((r.method ?? "GET").toUpperCase() !== "GET") return W(405, {
|
|
892
|
+
error: "method not allowed",
|
|
893
|
+
expected: "GET"
|
|
894
|
+
}, i);
|
|
895
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, i);
|
|
896
|
+
let a = (r.authResolver ?? U)(n);
|
|
897
|
+
if (!a.ok) return W(401, {
|
|
898
|
+
error: "unauthorized",
|
|
899
|
+
reason: a.reason
|
|
900
|
+
}, i);
|
|
901
|
+
if (t.kind !== "api") return W(404, { error: "data viewer is api-only" }, i);
|
|
902
|
+
if (t.inspectRows === void 0) return W(404, { error: "inspectRows not configured" }, i);
|
|
903
|
+
let o = q(e), s = o.get("table");
|
|
904
|
+
if (!s) return W(400, { error: "query.table is required" }, i);
|
|
905
|
+
let c = J(o.get("offset")) ?? 0, l = J(o.get("limit")) ?? 50, u = {}, d = o.get("q");
|
|
906
|
+
if (d) {
|
|
907
|
+
if (d.length > 8192) return W(400, { error: "query.q too large" }, i);
|
|
908
|
+
try {
|
|
909
|
+
u = JSON.parse(Buffer.from(d, "base64url").toString("utf8"));
|
|
910
|
+
} catch {
|
|
911
|
+
return W(400, { error: "query.q is not valid base64url JSON" }, i);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
try {
|
|
915
|
+
return W(200, await t.inspectRows({
|
|
916
|
+
table: s,
|
|
917
|
+
offset: c,
|
|
918
|
+
limit: l,
|
|
919
|
+
...u
|
|
920
|
+
}), i);
|
|
921
|
+
} catch (e) {
|
|
922
|
+
return e?.name === "InspectQueryError" ? W(400, {
|
|
923
|
+
error: "invalid query",
|
|
924
|
+
message: e.message
|
|
925
|
+
}, i) : W(500, {
|
|
926
|
+
error: "data-rows query failed",
|
|
927
|
+
message: e?.message ?? String(e)
|
|
928
|
+
}, i);
|
|
929
|
+
}
|
|
930
|
+
}, At = async (e, t, n, r = {}) => {
|
|
931
|
+
if (K(e) !== "/_voltro/inspect/provenance") return null;
|
|
932
|
+
let i = G(n.origin ?? n.Origin);
|
|
933
|
+
if ((r.method ?? "GET").toUpperCase() !== "GET") return W(405, {
|
|
934
|
+
error: "method not allowed",
|
|
935
|
+
expected: "GET"
|
|
936
|
+
}, i);
|
|
937
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, i);
|
|
938
|
+
let a = (r.authResolver ?? U)(n);
|
|
939
|
+
if (!a.ok) return W(401, {
|
|
940
|
+
error: "unauthorized",
|
|
941
|
+
reason: a.reason
|
|
942
|
+
}, i);
|
|
943
|
+
if (t.kind !== "api") return W(404, { error: "provenance is api-only" }, i);
|
|
944
|
+
if (t.inspectRows === void 0) return W(404, { error: "inspectRows not configured" }, i);
|
|
945
|
+
let o = q(e), s = o.get("table"), c = o.get("id"), l = o.get("column") ?? void 0;
|
|
946
|
+
if (!s || !c) return W(400, { error: "query.table and query.id are required" }, i);
|
|
947
|
+
try {
|
|
948
|
+
let e = (await t.inspectRows({
|
|
949
|
+
table: s,
|
|
950
|
+
limit: 1,
|
|
951
|
+
filter: {
|
|
952
|
+
kind: "leaf",
|
|
953
|
+
column: "id",
|
|
954
|
+
op: "eq",
|
|
955
|
+
value: c
|
|
956
|
+
}
|
|
957
|
+
})).rows[0];
|
|
958
|
+
return W(200, ne(e, {
|
|
959
|
+
table: s,
|
|
960
|
+
id: c,
|
|
961
|
+
...l === void 0 ? {} : { column: l }
|
|
962
|
+
}), i);
|
|
963
|
+
} catch (e) {
|
|
964
|
+
return e?.name === "InspectQueryError" ? W(400, {
|
|
965
|
+
error: "invalid query",
|
|
966
|
+
message: e.message
|
|
967
|
+
}, i) : W(500, {
|
|
968
|
+
error: "provenance query failed",
|
|
969
|
+
message: e?.message ?? String(e)
|
|
970
|
+
}, i);
|
|
971
|
+
}
|
|
972
|
+
}, q = (e) => {
|
|
973
|
+
let t = e.indexOf("?");
|
|
974
|
+
return t < 0 ? new URLSearchParams() : new URLSearchParams(e.slice(t + 1));
|
|
975
|
+
}, J = (e) => {
|
|
976
|
+
if (e === null || e === "") return;
|
|
977
|
+
let t = Number(e);
|
|
978
|
+
return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
|
|
979
|
+
}, jt = async (e, t, n, r = {}) => {
|
|
980
|
+
if (K(e) !== "/_voltro/inspect/workflows/runs") return null;
|
|
981
|
+
let i = G(n.origin ?? n.Origin);
|
|
982
|
+
if ((r.method ?? "GET").toUpperCase() !== "GET") return W(405, {
|
|
983
|
+
error: "method not allowed",
|
|
984
|
+
expected: "GET"
|
|
985
|
+
}, i);
|
|
986
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, i);
|
|
987
|
+
let a = (r.authResolver ?? U)(n);
|
|
988
|
+
if (!a.ok) return W(401, {
|
|
989
|
+
error: "unauthorized",
|
|
990
|
+
reason: a.reason
|
|
991
|
+
}, i);
|
|
992
|
+
if (t.kind !== "api") return W(404, { error: "workflows endpoint is api-only" }, i);
|
|
993
|
+
if (t.inspectWorkflowRuns === void 0) return W(200, {
|
|
994
|
+
runs: [],
|
|
995
|
+
total: 0,
|
|
996
|
+
offset: 0,
|
|
997
|
+
limit: 50
|
|
998
|
+
}, i);
|
|
999
|
+
let o = q(e);
|
|
1000
|
+
try {
|
|
1001
|
+
return W(200, await t.inspectWorkflowRuns({
|
|
1002
|
+
...o.get("tag") === null ? {} : { tag: o.get("tag") },
|
|
1003
|
+
...o.get("status") === null ? {} : { status: o.get("status") },
|
|
1004
|
+
offset: J(o.get("offset")) ?? 0,
|
|
1005
|
+
limit: J(o.get("limit")) ?? 50
|
|
1006
|
+
}), i);
|
|
1007
|
+
} catch (e) {
|
|
1008
|
+
return W(500, {
|
|
1009
|
+
error: "workflow-runs query failed",
|
|
1010
|
+
message: e?.message ?? String(e)
|
|
1011
|
+
}, i);
|
|
1012
|
+
}
|
|
1013
|
+
}, Mt = async (e, t, n, r, i = {}) => {
|
|
1014
|
+
let a = K(e).match(/^\/_voltro\/inspect\/workflows\/start\/([^/]+)$/);
|
|
1015
|
+
if (!a) return null;
|
|
1016
|
+
let o = decodeURIComponent(a[1] ?? ""), s = G(n.origin ?? n.Origin);
|
|
1017
|
+
if ((i.method ?? "POST").toUpperCase() !== "POST") return W(405, {
|
|
1018
|
+
error: "method not allowed",
|
|
1019
|
+
expected: "POST"
|
|
1020
|
+
}, s);
|
|
1021
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, s);
|
|
1022
|
+
let c = (i.authResolver ?? U)(n);
|
|
1023
|
+
if (!c.ok) return W(401, {
|
|
1024
|
+
error: "unauthorized",
|
|
1025
|
+
reason: c.reason
|
|
1026
|
+
}, s);
|
|
1027
|
+
if (t.kind !== "api") return W(404, { error: "workflow start is api-only" }, s);
|
|
1028
|
+
if (t.inspectStartWorkflow === void 0) return W(404, { error: "inspectStartWorkflow not configured" }, s);
|
|
1029
|
+
let l = {};
|
|
1030
|
+
if (r.length > 0) try {
|
|
1031
|
+
l = JSON.parse(r).payload ?? {};
|
|
1032
|
+
} catch {
|
|
1033
|
+
return W(400, { error: "start requires JSON body `{ payload?: unknown }`" }, s);
|
|
1034
|
+
}
|
|
1035
|
+
try {
|
|
1036
|
+
return W(200, await t.inspectStartWorkflow({
|
|
1037
|
+
name: o,
|
|
1038
|
+
payload: l
|
|
1039
|
+
}), s);
|
|
1040
|
+
} catch (e) {
|
|
1041
|
+
return W(500, {
|
|
1042
|
+
error: "workflow start failed",
|
|
1043
|
+
message: e?.message ?? String(e)
|
|
1044
|
+
}, s);
|
|
1045
|
+
}
|
|
1046
|
+
}, Nt = async (e, t, n, r = {}) => {
|
|
1047
|
+
let i = K(e);
|
|
1048
|
+
if (!i.startsWith("/_voltro/inspect/schedules")) return null;
|
|
1049
|
+
let a = G(n.origin ?? n.Origin);
|
|
1050
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, a);
|
|
1051
|
+
let o = (r.authResolver ?? U)(n);
|
|
1052
|
+
if (!o.ok) return W(401, {
|
|
1053
|
+
error: "unauthorized",
|
|
1054
|
+
reason: o.reason
|
|
1055
|
+
}, a);
|
|
1056
|
+
if (t.kind !== "api") return W(404, { error: "schedules are api-only" }, a);
|
|
1057
|
+
let s = (r.method ?? "GET").toUpperCase(), c = i.match(/^\/_voltro\/inspect\/schedules\/([^/]+)\/fire$/);
|
|
1058
|
+
if (c) {
|
|
1059
|
+
if (s !== "POST") return W(405, {
|
|
1060
|
+
error: "method not allowed",
|
|
1061
|
+
expected: "POST"
|
|
1062
|
+
}, a);
|
|
1063
|
+
if (!t.inspectFireSchedule) return W(404, { error: "inspectFireSchedule not configured" }, a);
|
|
1064
|
+
let n = decodeURIComponent(c[1] ?? ""), r = q(e).get("trigger") === "external" ? "external" : "manual";
|
|
1065
|
+
try {
|
|
1066
|
+
return W(200, await t.inspectFireSchedule({
|
|
1067
|
+
name: n,
|
|
1068
|
+
trigger: r
|
|
1069
|
+
}), a);
|
|
1070
|
+
} catch (e) {
|
|
1071
|
+
return W(500, {
|
|
1072
|
+
error: "fire failed",
|
|
1073
|
+
message: e?.message ?? String(e)
|
|
1074
|
+
}, a);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
if (i === "/_voltro/inspect/schedules/runs") {
|
|
1078
|
+
if (s !== "GET") return W(405, {
|
|
1079
|
+
error: "method not allowed",
|
|
1080
|
+
expected: "GET"
|
|
1081
|
+
}, a);
|
|
1082
|
+
if (!t.inspectScheduleRuns) return W(200, {
|
|
1083
|
+
runs: [],
|
|
1084
|
+
total: 0,
|
|
1085
|
+
offset: 0,
|
|
1086
|
+
limit: 50
|
|
1087
|
+
}, a);
|
|
1088
|
+
let n = q(e);
|
|
1089
|
+
try {
|
|
1090
|
+
return W(200, await t.inspectScheduleRuns({
|
|
1091
|
+
...n.get("name") === null ? {} : { name: n.get("name") },
|
|
1092
|
+
offset: J(n.get("offset")) ?? 0,
|
|
1093
|
+
limit: J(n.get("limit")) ?? 50
|
|
1094
|
+
}), a);
|
|
1095
|
+
} catch (e) {
|
|
1096
|
+
return W(500, {
|
|
1097
|
+
error: "schedule-runs query failed",
|
|
1098
|
+
message: e?.message ?? String(e)
|
|
1099
|
+
}, a);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
return i === "/_voltro/inspect/schedules" ? s === "GET" ? t.inspectSchedules ? W(200, t.inspectSchedules(), a) : W(200, {
|
|
1103
|
+
schedules: [],
|
|
1104
|
+
coordination: "single"
|
|
1105
|
+
}, a) : W(405, {
|
|
1106
|
+
error: "method not allowed",
|
|
1107
|
+
expected: "GET"
|
|
1108
|
+
}, a) : W(404, {
|
|
1109
|
+
error: "unknown schedules endpoint",
|
|
1110
|
+
path: i
|
|
1111
|
+
}, a);
|
|
1112
|
+
}, Pt = async (e, t, n, r = {}) => {
|
|
1113
|
+
if (K(e) !== "/_voltro/inspect/cluster") return null;
|
|
1114
|
+
let i = G(n.origin ?? n.Origin);
|
|
1115
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, i);
|
|
1116
|
+
let a = (r.authResolver ?? U)(n);
|
|
1117
|
+
if (!a.ok) return W(401, {
|
|
1118
|
+
error: "unauthorized",
|
|
1119
|
+
reason: a.reason
|
|
1120
|
+
}, i);
|
|
1121
|
+
if (t.kind !== "api") return W(404, { error: "cluster is api-only" }, i);
|
|
1122
|
+
if ((r.method ?? "GET").toUpperCase() !== "GET") return W(405, {
|
|
1123
|
+
error: "method not allowed",
|
|
1124
|
+
expected: "GET"
|
|
1125
|
+
}, i);
|
|
1126
|
+
if (!t.cluster) return W(200, {
|
|
1127
|
+
instance: {
|
|
1128
|
+
replicaId: process.env.POD_NAME ?? process.env.HOSTNAME ?? `dev-${process.pid}`,
|
|
1129
|
+
dialect: "memory",
|
|
1130
|
+
runnerHost: "localhost",
|
|
1131
|
+
runnerPort: 0,
|
|
1132
|
+
runnerStorage: "none",
|
|
1133
|
+
shardLock: "none",
|
|
1134
|
+
coordination: "single",
|
|
1135
|
+
cdc: {
|
|
1136
|
+
enabled: !1,
|
|
1137
|
+
flavor: "none (single-process)"
|
|
1138
|
+
},
|
|
1139
|
+
tier: "none",
|
|
1140
|
+
localhostRisk: !1
|
|
1141
|
+
},
|
|
1142
|
+
coordinationState: {
|
|
1143
|
+
recentReplicaIds: [],
|
|
1144
|
+
scheduleClaims: [],
|
|
1145
|
+
runningScheduleRuns: 0,
|
|
1146
|
+
runningWorkflowRuns: 0
|
|
1147
|
+
},
|
|
1148
|
+
capturedAt: Date.now()
|
|
1149
|
+
}, i);
|
|
1150
|
+
try {
|
|
1151
|
+
return W(200, await t.cluster(), i);
|
|
1152
|
+
} catch (e) {
|
|
1153
|
+
return W(500, {
|
|
1154
|
+
error: "cluster snapshot failed",
|
|
1155
|
+
message: e?.message ?? String(e)
|
|
1156
|
+
}, i);
|
|
1157
|
+
}
|
|
1158
|
+
}, Ft = async (e, t, n, r = {}) => {
|
|
1159
|
+
let i = K(e).match(/^\/_voltro\/inspect\/workflows\/runs\/([^/]+)\/steps$/);
|
|
1160
|
+
if (!i) return null;
|
|
1161
|
+
let a = decodeURIComponent(i[1] ?? ""), o = G(n.origin ?? n.Origin);
|
|
1162
|
+
if ((r.method ?? "GET").toUpperCase() !== "GET") return W(405, {
|
|
1163
|
+
error: "method not allowed",
|
|
1164
|
+
expected: "GET"
|
|
1165
|
+
}, o);
|
|
1166
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, o);
|
|
1167
|
+
let s = (r.authResolver ?? U)(n);
|
|
1168
|
+
if (!s.ok) return W(401, {
|
|
1169
|
+
error: "unauthorized",
|
|
1170
|
+
reason: s.reason
|
|
1171
|
+
}, o);
|
|
1172
|
+
if (t.kind !== "api") return W(404, { error: "workflow steps are api-only" }, o);
|
|
1173
|
+
if (t.inspectWorkflowRunSteps === void 0) return W(200, { steps: [] }, o);
|
|
1174
|
+
try {
|
|
1175
|
+
return W(200, await t.inspectWorkflowRunSteps({ runId: a }), o);
|
|
1176
|
+
} catch (e) {
|
|
1177
|
+
return W(500, {
|
|
1178
|
+
error: "steps query failed",
|
|
1179
|
+
message: e?.message ?? String(e)
|
|
1180
|
+
}, o);
|
|
1181
|
+
}
|
|
1182
|
+
}, It = async (e, t, n, r = {}) => {
|
|
1183
|
+
let i = K(e).match(/^\/_voltro\/inspect\/workflows\/runs\/([^/]+)\/events$/);
|
|
1184
|
+
if (!i) return null;
|
|
1185
|
+
let a = decodeURIComponent(i[1] ?? ""), o = G(n.origin ?? n.Origin);
|
|
1186
|
+
if ((r.method ?? "GET").toUpperCase() !== "GET") return W(405, {
|
|
1187
|
+
error: "method not allowed",
|
|
1188
|
+
expected: "GET"
|
|
1189
|
+
}, o);
|
|
1190
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, o);
|
|
1191
|
+
let s = (r.authResolver ?? U)(n);
|
|
1192
|
+
if (!s.ok) return W(401, {
|
|
1193
|
+
error: "unauthorized",
|
|
1194
|
+
reason: s.reason
|
|
1195
|
+
}, o);
|
|
1196
|
+
if (t.kind !== "api") return W(404, { error: "workflow events are api-only" }, o);
|
|
1197
|
+
if (t.inspectWorkflowRunEvents === void 0) return W(200, { events: [] }, o);
|
|
1198
|
+
try {
|
|
1199
|
+
return W(200, await t.inspectWorkflowRunEvents({ runId: a }), o);
|
|
1200
|
+
} catch (e) {
|
|
1201
|
+
return W(500, {
|
|
1202
|
+
error: "events query failed",
|
|
1203
|
+
message: e?.message ?? String(e)
|
|
1204
|
+
}, o);
|
|
1205
|
+
}
|
|
1206
|
+
}, Lt = async (e, t, n, r = {}) => {
|
|
1207
|
+
if (K(t) !== "/_voltro/inspect/workflows/events") return null;
|
|
1208
|
+
let i = G(n.origin ?? n.Origin);
|
|
1209
|
+
if ((r.method ?? "GET").toUpperCase() !== "GET") return W(405, {
|
|
1210
|
+
error: "method not allowed",
|
|
1211
|
+
expected: "GET"
|
|
1212
|
+
}, i);
|
|
1213
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, i);
|
|
1214
|
+
let a = (r.authResolver ?? U)(n);
|
|
1215
|
+
if (!a.ok) return W(401, {
|
|
1216
|
+
error: "unauthorized",
|
|
1217
|
+
reason: a.reason
|
|
1218
|
+
}, i);
|
|
1219
|
+
if (e.kind !== "api") return W(404, { error: "workflow domain events are api-only" }, i);
|
|
1220
|
+
if (e.inspectWorkflowDomainEvents === void 0) return W(200, {
|
|
1221
|
+
events: [],
|
|
1222
|
+
total: 0,
|
|
1223
|
+
offset: 0,
|
|
1224
|
+
limit: 100
|
|
1225
|
+
}, i);
|
|
1226
|
+
let o = xt(t), s = o.get("name") ?? void 0, c = Number(o.get("offset") ?? "0"), l = Number(o.get("limit") ?? "100");
|
|
1227
|
+
try {
|
|
1228
|
+
return W(200, await e.inspectWorkflowDomainEvents({
|
|
1229
|
+
...s !== void 0 && s !== "" ? { name: s } : {},
|
|
1230
|
+
offset: Number.isFinite(c) ? c : 0,
|
|
1231
|
+
limit: Number.isFinite(l) ? l : 100
|
|
1232
|
+
}), i);
|
|
1233
|
+
} catch (e) {
|
|
1234
|
+
return W(500, {
|
|
1235
|
+
error: "workflow domain events query failed",
|
|
1236
|
+
message: e?.message ?? String(e)
|
|
1237
|
+
}, i);
|
|
1238
|
+
}
|
|
1239
|
+
}, Rt = async (e, t, n, r = {}) => {
|
|
1240
|
+
let i = K(t).match(/^\/_voltro\/inspect\/workflows\/events\/([^/]+)\/deliveries$/);
|
|
1241
|
+
if (!i) return null;
|
|
1242
|
+
let a = decodeURIComponent(i[1] ?? ""), o = G(n.origin ?? n.Origin);
|
|
1243
|
+
if ((r.method ?? "GET").toUpperCase() !== "GET") return W(405, {
|
|
1244
|
+
error: "method not allowed",
|
|
1245
|
+
expected: "GET"
|
|
1246
|
+
}, o);
|
|
1247
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, o);
|
|
1248
|
+
let s = (r.authResolver ?? U)(n);
|
|
1249
|
+
if (!s.ok) return W(401, {
|
|
1250
|
+
error: "unauthorized",
|
|
1251
|
+
reason: s.reason
|
|
1252
|
+
}, o);
|
|
1253
|
+
if (e.kind !== "api") return W(404, { error: "workflow event deliveries are api-only" }, o);
|
|
1254
|
+
if (e.inspectWorkflowEventDeliveries === void 0) return W(200, { deliveries: [] }, o);
|
|
1255
|
+
try {
|
|
1256
|
+
return W(200, await e.inspectWorkflowEventDeliveries({ eventId: a }), o);
|
|
1257
|
+
} catch (e) {
|
|
1258
|
+
return W(500, {
|
|
1259
|
+
error: "workflow event deliveries query failed",
|
|
1260
|
+
message: e?.message ?? String(e)
|
|
1261
|
+
}, o);
|
|
1262
|
+
}
|
|
1263
|
+
}, zt = async (e, t, n, r = {}) => {
|
|
1264
|
+
if (K(e) !== "/_voltro/inspect/workflows/children") return null;
|
|
1265
|
+
let i = G(n.origin ?? n.Origin);
|
|
1266
|
+
if ((r.method ?? "GET").toUpperCase() !== "GET") return W(405, {
|
|
1267
|
+
error: "method not allowed",
|
|
1268
|
+
expected: "GET"
|
|
1269
|
+
}, i);
|
|
1270
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, i);
|
|
1271
|
+
let a = (r.authResolver ?? U)(n);
|
|
1272
|
+
if (!a.ok) return W(401, {
|
|
1273
|
+
error: "unauthorized",
|
|
1274
|
+
reason: a.reason
|
|
1275
|
+
}, i);
|
|
1276
|
+
if (t.kind !== "api") return W(404, { error: "workflow children are api-only" }, i);
|
|
1277
|
+
let o = q(e).get("parentExecutionId");
|
|
1278
|
+
if (o === null || o === "") return W(400, { error: "parentExecutionId query param required" }, i);
|
|
1279
|
+
if (t.inspectWorkflowChildren === void 0) return W(200, {
|
|
1280
|
+
runs: [],
|
|
1281
|
+
total: 0,
|
|
1282
|
+
offset: 0,
|
|
1283
|
+
limit: 200
|
|
1284
|
+
}, i);
|
|
1285
|
+
try {
|
|
1286
|
+
return W(200, await t.inspectWorkflowChildren({ parentExecutionId: o }), i);
|
|
1287
|
+
} catch (e) {
|
|
1288
|
+
return W(500, {
|
|
1289
|
+
error: "children query failed",
|
|
1290
|
+
message: e?.message ?? String(e)
|
|
1291
|
+
}, i);
|
|
1292
|
+
}
|
|
1293
|
+
}, Bt = async (e, t, n, r, i = {}) => {
|
|
1294
|
+
let a = K(e).match(/^\/_voltro\/inspect\/workflows\/runs\/([^/]+)\/(cancel|retry|suspend|resume|signal|update)$/);
|
|
1295
|
+
if (!a) return null;
|
|
1296
|
+
let o = decodeURIComponent(a[1] ?? ""), s = a[2], c = G(n.origin ?? n.Origin);
|
|
1297
|
+
if ((i.method ?? "POST").toUpperCase() !== "POST") return W(405, {
|
|
1298
|
+
error: "method not allowed",
|
|
1299
|
+
expected: "POST"
|
|
1300
|
+
}, c);
|
|
1301
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, c);
|
|
1302
|
+
let l = (i.authResolver ?? U)(n);
|
|
1303
|
+
if (!l.ok) return W(401, {
|
|
1304
|
+
error: "unauthorized",
|
|
1305
|
+
reason: l.reason
|
|
1306
|
+
}, c);
|
|
1307
|
+
if (t.kind !== "api") return W(404, { error: "workflow actions are api-only" }, c);
|
|
1308
|
+
let u = {
|
|
1309
|
+
cancel: t.inspectCancelWorkflowRun,
|
|
1310
|
+
retry: t.inspectRetryWorkflowRun,
|
|
1311
|
+
suspend: t.inspectSuspendWorkflowRun,
|
|
1312
|
+
resume: t.inspectResumeWorkflowRun,
|
|
1313
|
+
signal: t.inspectSignalWorkflowRun,
|
|
1314
|
+
update: t.inspectUpdateWorkflowRun
|
|
1315
|
+
}[s];
|
|
1316
|
+
if (!u) return W(404, { error: `inspect${s[0]?.toUpperCase() ?? ""}${s.slice(1)}WorkflowRun not configured` }, c);
|
|
1317
|
+
let d, f, p, m, h, g;
|
|
1318
|
+
if (r.length > 0) try {
|
|
1319
|
+
let e = JSON.parse(r);
|
|
1320
|
+
s === "retry" && (d = e.payloadOverride), s === "signal" && (typeof e.signalName == "string" && e.signalName.length > 0 && (f = e.signalName), p = e.payload), s === "update" && (typeof e.updateName == "string" && e.updateName.length > 0 && (m = e.updateName), h = e.payload, typeof e.timeoutMs == "number" && Number.isFinite(e.timeoutMs) && (g = e.timeoutMs));
|
|
1321
|
+
} catch {}
|
|
1322
|
+
if (s === "signal" && f === void 0) return W(400, { error: "signal requires JSON body `{ signalName: string, payload?: unknown }`" }, c);
|
|
1323
|
+
if (s === "update" && m === void 0) return W(400, { error: "update requires JSON body `{ updateName: string, payload?: unknown, timeoutMs?: number }`" }, c);
|
|
1324
|
+
try {
|
|
1325
|
+
return W(200, s === "retry" && d !== void 0 ? await u({
|
|
1326
|
+
runId: o,
|
|
1327
|
+
payloadOverride: d
|
|
1328
|
+
}) : s === "signal" ? await u({
|
|
1329
|
+
runId: o,
|
|
1330
|
+
signalName: f,
|
|
1331
|
+
payload: p
|
|
1332
|
+
}) : s === "update" ? await u({
|
|
1333
|
+
runId: o,
|
|
1334
|
+
updateName: m,
|
|
1335
|
+
payload: h,
|
|
1336
|
+
...g === void 0 ? {} : { timeoutMs: g }
|
|
1337
|
+
}) : await u({ runId: o }), c);
|
|
1338
|
+
} catch (e) {
|
|
1339
|
+
return W(500, {
|
|
1340
|
+
error: `${s} failed`,
|
|
1341
|
+
message: e?.message ?? String(e)
|
|
1342
|
+
}, c);
|
|
1343
|
+
}
|
|
1344
|
+
}, Vt = async (e, t, n, r, i = {}) => {
|
|
1345
|
+
if (K(e) !== "/_voltro/inspect/data/import" || (i.method ?? "POST").toUpperCase() !== "POST") return null;
|
|
1346
|
+
let a = G(n.origin ?? n.Origin);
|
|
1347
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, a);
|
|
1348
|
+
let o = (i.authResolver ?? U)(n);
|
|
1349
|
+
if (!o.ok) return W(401, {
|
|
1350
|
+
error: "unauthorized",
|
|
1351
|
+
reason: o.reason
|
|
1352
|
+
}, a);
|
|
1353
|
+
if (t.kind !== "api") return W(404, { error: "data import is api-only" }, a);
|
|
1354
|
+
if (!t.inspectImport) return W(404, { error: "inspectImport not configured" }, a);
|
|
1355
|
+
let s;
|
|
1356
|
+
try {
|
|
1357
|
+
s = JSON.parse(r || "{}");
|
|
1358
|
+
} catch {
|
|
1359
|
+
return W(400, { error: "body must be JSON" }, a);
|
|
1360
|
+
}
|
|
1361
|
+
if (typeof s.bundleDir != "string" || !s.bundleDir) return W(400, { error: "body.bundleDir (string) is required" }, a);
|
|
1362
|
+
try {
|
|
1363
|
+
return W(200, await t.inspectImport({
|
|
1364
|
+
bundleDir: s.bundleDir,
|
|
1365
|
+
...s.mode === "upsert" || s.mode === "append" || s.mode === "replace" ? { mode: s.mode } : {},
|
|
1366
|
+
...s.onConflict === "skip" || s.onConflict === "fail" ? { onConflict: s.onConflict } : {},
|
|
1367
|
+
...typeof s.atomic == "boolean" ? { atomic: s.atomic } : {}
|
|
1368
|
+
}), a);
|
|
1369
|
+
} catch (e) {
|
|
1370
|
+
return W(500, {
|
|
1371
|
+
error: "import failed",
|
|
1372
|
+
message: e?.message ?? String(e)
|
|
1373
|
+
}, a);
|
|
1374
|
+
}
|
|
1375
|
+
}, Ht = async (e, t, n, r, i = {}) => {
|
|
1376
|
+
let a = K(e);
|
|
1377
|
+
if (!a.startsWith("/_voltro/inspect/data/rows")) return null;
|
|
1378
|
+
let o = (i.method ?? "POST").toUpperCase();
|
|
1379
|
+
if (o === "GET" && a === "/_voltro/inspect/data/rows") return null;
|
|
1380
|
+
let s = G(n.origin ?? n.Origin);
|
|
1381
|
+
if (H()) return W(503, { error: "inspect disabled (VOLTRO_INSPECT=off)" }, s);
|
|
1382
|
+
let c = (i.authResolver ?? U)(n);
|
|
1383
|
+
if (!c.ok) return W(401, {
|
|
1384
|
+
error: "unauthorized",
|
|
1385
|
+
reason: c.reason
|
|
1386
|
+
}, s);
|
|
1387
|
+
if (t.kind !== "api") return W(404, { error: "data viewer is api-only" }, s);
|
|
1388
|
+
if (o === "POST" && a === "/_voltro/inspect/data/rows") {
|
|
1389
|
+
if (!t.inspectInsertRow) return W(404, { error: "inspectInsertRow not configured" }, s);
|
|
1390
|
+
let e;
|
|
1391
|
+
try {
|
|
1392
|
+
e = JSON.parse(r || "{}");
|
|
1393
|
+
} catch {
|
|
1394
|
+
return W(400, { error: "body must be JSON" }, s);
|
|
1395
|
+
}
|
|
1396
|
+
if (typeof e.table != "string" || !e.row || typeof e.row != "object") return W(400, { error: "body must be { table: string, row: object }" }, s);
|
|
1397
|
+
try {
|
|
1398
|
+
return W(200, await t.inspectInsertRow({
|
|
1399
|
+
table: e.table,
|
|
1400
|
+
row: e.row
|
|
1401
|
+
}), s);
|
|
1402
|
+
} catch (e) {
|
|
1403
|
+
return W(500, {
|
|
1404
|
+
error: "insert failed",
|
|
1405
|
+
message: e?.message ?? String(e)
|
|
1406
|
+
}, s);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
let l = a.match(/^\/_voltro\/inspect\/data\/rows\/([^/]+)$/);
|
|
1410
|
+
if (!l) return null;
|
|
1411
|
+
let u = decodeURIComponent(l[1] ?? "");
|
|
1412
|
+
if (!u) return W(400, { error: "row id is required in URL" }, s);
|
|
1413
|
+
let d = q(e).get("table") ?? "";
|
|
1414
|
+
if (!d) return W(400, { error: "query.table is required" }, s);
|
|
1415
|
+
if (o === "PATCH") {
|
|
1416
|
+
if (!t.inspectUpdateRow) return W(404, { error: "inspectUpdateRow not configured" }, s);
|
|
1417
|
+
let e;
|
|
1418
|
+
try {
|
|
1419
|
+
e = JSON.parse(r || "{}");
|
|
1420
|
+
} catch {
|
|
1421
|
+
return W(400, { error: "body must be JSON" }, s);
|
|
1422
|
+
}
|
|
1423
|
+
if (!e.patch || typeof e.patch != "object") return W(400, { error: "body.patch must be an object" }, s);
|
|
1424
|
+
try {
|
|
1425
|
+
return W(200, await t.inspectUpdateRow({
|
|
1426
|
+
table: d,
|
|
1427
|
+
id: u,
|
|
1428
|
+
patch: e.patch
|
|
1429
|
+
}), s);
|
|
1430
|
+
} catch (e) {
|
|
1431
|
+
return W(500, {
|
|
1432
|
+
error: "update failed",
|
|
1433
|
+
message: e?.message ?? String(e)
|
|
1434
|
+
}, s);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
if (o === "DELETE") {
|
|
1438
|
+
if (!t.inspectDeleteRow) return W(404, { error: "inspectDeleteRow not configured" }, s);
|
|
1439
|
+
try {
|
|
1440
|
+
return W(200, await t.inspectDeleteRow({
|
|
1441
|
+
table: d,
|
|
1442
|
+
id: u
|
|
1443
|
+
}), s);
|
|
1444
|
+
} catch (e) {
|
|
1445
|
+
return W(500, {
|
|
1446
|
+
error: "delete failed",
|
|
1447
|
+
message: e?.message ?? String(e)
|
|
1448
|
+
}, s);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
return W(405, {
|
|
1452
|
+
error: "method not allowed",
|
|
1453
|
+
expected: "POST | PATCH | DELETE"
|
|
1454
|
+
}, s);
|
|
1455
|
+
}, Ut = 256, Wt = (e = Ut) => {
|
|
1456
|
+
let t = [], n = /* @__PURE__ */ new Set();
|
|
1457
|
+
return {
|
|
1458
|
+
emit(r, i) {
|
|
1459
|
+
let a = {
|
|
1460
|
+
ts: Date.now(),
|
|
1461
|
+
channel: r,
|
|
1462
|
+
payload: i
|
|
1463
|
+
};
|
|
1464
|
+
t.push(a), t.length > e && t.shift();
|
|
1465
|
+
for (let e of n) try {
|
|
1466
|
+
e(a);
|
|
1467
|
+
} catch {}
|
|
1468
|
+
},
|
|
1469
|
+
subscribe(e) {
|
|
1470
|
+
return n.add(e), () => {
|
|
1471
|
+
n.delete(e);
|
|
1472
|
+
};
|
|
1473
|
+
},
|
|
1474
|
+
buffered() {
|
|
1475
|
+
return t.slice();
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1478
|
+
}, Gt = (e) => `event: ${e.channel}\ndata: ${JSON.stringify(e)}\n\n`, Kt = () => `: keep-alive ${Date.now()}\n\n`, qt = {
|
|
1479
|
+
trace: 0,
|
|
1480
|
+
debug: 1,
|
|
1481
|
+
info: 2,
|
|
1482
|
+
warn: 3,
|
|
1483
|
+
error: 4,
|
|
1484
|
+
fatal: 5
|
|
1485
|
+
}, Jt = 2e3, Yt = 200, Xt = class {
|
|
1486
|
+
capacity;
|
|
1487
|
+
buffer = [];
|
|
1488
|
+
constructor(e = Jt) {
|
|
1489
|
+
this.capacity = e;
|
|
1490
|
+
}
|
|
1491
|
+
append(e) {
|
|
1492
|
+
this.buffer.push(e), this.buffer.length > this.capacity && this.buffer.shift();
|
|
1493
|
+
}
|
|
1494
|
+
query(e = {}) {
|
|
1495
|
+
let t = e.since ?? 0, n = e.until ?? Date.now(), r = Math.min(e.max ?? Yt, this.capacity), i = e.minLevel === void 0 ? qt.trace : qt[e.minLevel], a = e.scope?.toLowerCase(), o = e.source, s = e.filter?.toLowerCase(), c = e.traceId, l = [];
|
|
1496
|
+
for (let e = this.buffer.length - 1; e >= 0 && l.length < r; e--) {
|
|
1497
|
+
let r = this.buffer[e];
|
|
1498
|
+
r.ts < t || r.ts > n || qt[r.level] < i || o !== void 0 && r.source !== o || a !== void 0 && (r.scope === void 0 || !r.scope.toLowerCase().includes(a)) || s !== void 0 && !r.message.toLowerCase().includes(s) || c !== void 0 && r.fields.traceId !== c || l.push(r);
|
|
1499
|
+
}
|
|
1500
|
+
return l.reverse();
|
|
1501
|
+
}
|
|
1502
|
+
size() {
|
|
1503
|
+
return this.buffer.length;
|
|
1504
|
+
}
|
|
1505
|
+
capacityHint() {
|
|
1506
|
+
return this.capacity;
|
|
1507
|
+
}
|
|
1508
|
+
clear() {
|
|
1509
|
+
this.buffer = [];
|
|
1510
|
+
}
|
|
1511
|
+
}, Zt = null, Qt = () => (Zt === null && (Zt = new Xt()), Zt), $t = (e) => {
|
|
1512
|
+
if (typeof e == "string") return e;
|
|
1513
|
+
if (e instanceof Error) return e.message;
|
|
1514
|
+
try {
|
|
1515
|
+
return JSON.stringify(e);
|
|
1516
|
+
} catch {
|
|
1517
|
+
return String(e);
|
|
1518
|
+
}
|
|
1519
|
+
}, en = (e) => {
|
|
1520
|
+
let t = {
|
|
1521
|
+
log: console.log.bind(console),
|
|
1522
|
+
info: console.info.bind(console),
|
|
1523
|
+
warn: console.warn.bind(console),
|
|
1524
|
+
error: console.error.bind(console),
|
|
1525
|
+
debug: console.debug.bind(console)
|
|
1526
|
+
}, n = Qt(), r = !1, i = (i) => (...a) => {
|
|
1527
|
+
if (t[i](...a), !r) {
|
|
1528
|
+
r = !0;
|
|
1529
|
+
try {
|
|
1530
|
+
let t = a.length > 0 ? $t(a[0]) : "", r = t.length > 500 ? t.slice(0, 500) + "…" : t, o = O();
|
|
1531
|
+
e.emit("log", {
|
|
1532
|
+
level: i,
|
|
1533
|
+
message: r,
|
|
1534
|
+
argsCount: a.length,
|
|
1535
|
+
...o ? { traceId: o.traceId } : {}
|
|
1536
|
+
});
|
|
1537
|
+
let s = i === "log" ? "info" : i;
|
|
1538
|
+
n.append({
|
|
1539
|
+
ts: Date.now(),
|
|
1540
|
+
level: s,
|
|
1541
|
+
source: "server",
|
|
1542
|
+
message: r,
|
|
1543
|
+
fields: {
|
|
1544
|
+
...a.length > 1 ? { argsCount: a.length } : {},
|
|
1545
|
+
...o ? {
|
|
1546
|
+
traceId: o.traceId,
|
|
1547
|
+
...o.spanId === void 0 ? {} : { spanId: o.spanId }
|
|
1548
|
+
} : {}
|
|
1549
|
+
}
|
|
1550
|
+
});
|
|
1551
|
+
} finally {
|
|
1552
|
+
r = !1;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
console.log = i("log"), console.info = i("info"), console.warn = i("warn"), console.error = i("error"), console.debug = i("debug");
|
|
1557
|
+
let a = h((t) => {
|
|
1558
|
+
if (!r) {
|
|
1559
|
+
r = !0;
|
|
1560
|
+
try {
|
|
1561
|
+
let r = t.level === "trace" || t.level === "debug" ? "debug" : t.level === "info" ? "info" : t.level === "warn" ? "warn" : "error", i = `${t.scope ? `[${t.scope}] ` : ""}${t.message}`;
|
|
1562
|
+
e.emit("log", {
|
|
1563
|
+
level: r,
|
|
1564
|
+
message: i.length > 500 ? i.slice(0, 500) + "…" : i,
|
|
1565
|
+
argsCount: 1,
|
|
1566
|
+
...t.scope === void 0 ? {} : { scope: t.scope }
|
|
1567
|
+
});
|
|
1568
|
+
let a = O(), o = a !== void 0 && t.fields.traceId === void 0 ? {
|
|
1569
|
+
...t.fields,
|
|
1570
|
+
traceId: a.traceId
|
|
1571
|
+
} : t.fields;
|
|
1572
|
+
n.append({
|
|
1573
|
+
ts: t.ts.getTime(),
|
|
1574
|
+
level: t.level,
|
|
1575
|
+
source: t.scope === "client" ? "client" : "server",
|
|
1576
|
+
...t.scope === void 0 ? {} : { scope: t.scope },
|
|
1577
|
+
message: t.message,
|
|
1578
|
+
fields: o
|
|
1579
|
+
});
|
|
1580
|
+
} finally {
|
|
1581
|
+
r = !1;
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
});
|
|
1585
|
+
return () => {
|
|
1586
|
+
console.log = t.log, console.info = t.info, console.warn = t.warn, console.error = t.error, console.debug = t.debug, a();
|
|
1587
|
+
};
|
|
1588
|
+
}, tn = 2e3, nn = 8, rn = 1e3, an = 200, Y = (e, t) => e.length > t ? `${e.slice(0, t)}…` : e, on = (e) => {
|
|
1589
|
+
switch (e) {
|
|
1590
|
+
case "error": return "error";
|
|
1591
|
+
case "warn": return "warn";
|
|
1592
|
+
case "debug": return "debug";
|
|
1593
|
+
default: return "info";
|
|
1594
|
+
}
|
|
1595
|
+
}, sn = g({ scope: "client" }), cn = (e, t) => {
|
|
1596
|
+
let n;
|
|
1597
|
+
try {
|
|
1598
|
+
n = JSON.parse(e);
|
|
1599
|
+
} catch {
|
|
1600
|
+
return ln(400, { error: "invalid JSON body" });
|
|
1601
|
+
}
|
|
1602
|
+
if (typeof n != "object" || !n) return ln(400, { error: "body must be a JSON object" });
|
|
1603
|
+
let r = n;
|
|
1604
|
+
if (!Array.isArray(r.entries)) return ln(400, { error: "entries must be an array" });
|
|
1605
|
+
let i = typeof r.app == "string" ? Y(r.app, 120) : void 0, a = typeof r.page == "string" ? Y(r.page, 200) : void 0, o = typeof r.ua == "string" ? Y(r.ua, 200) : void 0, s = r.entries.slice(0, an), c = 0;
|
|
1606
|
+
for (let e of s) {
|
|
1607
|
+
if (typeof e != "object" || !e) continue;
|
|
1608
|
+
let n = e;
|
|
1609
|
+
if (typeof n.message != "string") continue;
|
|
1610
|
+
let r = typeof n.level == "string" && [
|
|
1611
|
+
"log",
|
|
1612
|
+
"info",
|
|
1613
|
+
"warn",
|
|
1614
|
+
"error",
|
|
1615
|
+
"debug"
|
|
1616
|
+
].includes(n.level) ? n.level : "log", s = typeof n.ts == "number" && Number.isFinite(n.ts) ? n.ts : Date.now(), l = Y(n.message, tn), u = Array.isArray(n.args) ? n.args.slice(0, nn).filter((e) => typeof e == "string").map((e) => Y(e, rn)) : void 0, d = typeof n.stack == "string" ? Y(n.stack, tn) : void 0;
|
|
1617
|
+
t.emit("clientLog", {
|
|
1618
|
+
ts: s,
|
|
1619
|
+
level: r,
|
|
1620
|
+
message: l,
|
|
1621
|
+
...u === void 0 ? {} : { args: u },
|
|
1622
|
+
...d === void 0 ? {} : { stack: d },
|
|
1623
|
+
...i === void 0 ? {} : { app: i },
|
|
1624
|
+
...a === void 0 ? {} : { page: a },
|
|
1625
|
+
...o === void 0 ? {} : { ua: o }
|
|
1626
|
+
});
|
|
1627
|
+
let f = {
|
|
1628
|
+
...i === void 0 ? {} : { app: i },
|
|
1629
|
+
...a === void 0 ? {} : { page: a },
|
|
1630
|
+
...u !== void 0 && u.length > 0 ? { args: u } : {}
|
|
1631
|
+
}, p = on(r);
|
|
1632
|
+
(p === "error" || p === "warn") && d !== void 0 ? sn[p](l, f, { stack: d }) : sn[p](l, {
|
|
1633
|
+
...f,
|
|
1634
|
+
...d === void 0 ? {} : { stack: d }
|
|
1635
|
+
}), c++;
|
|
1636
|
+
}
|
|
1637
|
+
return ln(202, {
|
|
1638
|
+
accepted: c,
|
|
1639
|
+
dropped: r.entries.length - c
|
|
1640
|
+
});
|
|
1641
|
+
}, ln = (e, t) => ({
|
|
1642
|
+
status: e,
|
|
1643
|
+
contentType: "application/json; charset=utf-8",
|
|
1644
|
+
body: JSON.stringify(t)
|
|
1645
|
+
}), un = "/_voltro/inspect/clientLog", dn = [
|
|
1646
|
+
"trace",
|
|
1647
|
+
"debug",
|
|
1648
|
+
"info",
|
|
1649
|
+
"warn",
|
|
1650
|
+
"error",
|
|
1651
|
+
"fatal"
|
|
1652
|
+
], fn = {
|
|
1653
|
+
trace: "TRACE",
|
|
1654
|
+
debug: "DEBUG",
|
|
1655
|
+
info: "INFO ",
|
|
1656
|
+
warn: "WARN ",
|
|
1657
|
+
error: "ERROR",
|
|
1658
|
+
fatal: "FATAL"
|
|
1659
|
+
}, pn = (e) => dn.includes(e), mn = (e, t) => {
|
|
1660
|
+
let n = e.indexOf("?"), r = n === -1 ? new URLSearchParams() : new URLSearchParams(e.slice(n + 1)), i = {}, a = r.get("since");
|
|
1661
|
+
if (a !== null) {
|
|
1662
|
+
let e = Number(a);
|
|
1663
|
+
Number.isFinite(e) && (i.since = e);
|
|
1664
|
+
}
|
|
1665
|
+
let o = r.get("until");
|
|
1666
|
+
if (o !== null) {
|
|
1667
|
+
let e = Number(o);
|
|
1668
|
+
Number.isFinite(e) && (i.until = e);
|
|
1669
|
+
}
|
|
1670
|
+
let s = r.get("max");
|
|
1671
|
+
if (s !== null) {
|
|
1672
|
+
let e = Number(s);
|
|
1673
|
+
Number.isFinite(e) && e > 0 && (i.max = Math.floor(e));
|
|
1674
|
+
}
|
|
1675
|
+
let c = r.get("level");
|
|
1676
|
+
c !== null && pn(c) && (i.minLevel = c);
|
|
1677
|
+
let l = r.get("source");
|
|
1678
|
+
(l === "server" || l === "client") && (i.source = l);
|
|
1679
|
+
let u = r.get("scope");
|
|
1680
|
+
u !== null && u.length > 0 && (i.scope = u);
|
|
1681
|
+
let d = r.get("filter");
|
|
1682
|
+
d !== null && d.length > 0 && (i.filter = d);
|
|
1683
|
+
let f = r.get("trace");
|
|
1684
|
+
f !== null && f.length > 0 && (i.traceId = f);
|
|
1685
|
+
let p = t.query(i);
|
|
1686
|
+
if ((r.get("format") ?? "json") === "text") return {
|
|
1687
|
+
status: 200,
|
|
1688
|
+
contentType: "text/plain; charset=utf-8",
|
|
1689
|
+
body: p.map(hn).join("\n") + (p.length > 0 ? "\n" : "")
|
|
1690
|
+
};
|
|
1691
|
+
let m = {
|
|
1692
|
+
capturedAt: Date.now(),
|
|
1693
|
+
bufferCapacity: t.capacityHint(),
|
|
1694
|
+
bufferSize: t.size(),
|
|
1695
|
+
returned: p.length,
|
|
1696
|
+
records: p
|
|
1697
|
+
};
|
|
1698
|
+
return {
|
|
1699
|
+
status: 200,
|
|
1700
|
+
contentType: "application/json; charset=utf-8",
|
|
1701
|
+
body: JSON.stringify(m)
|
|
1702
|
+
};
|
|
1703
|
+
}, hn = (e) => {
|
|
1704
|
+
let t = new Date(e.ts), n = String(t.getHours()).padStart(2, "0"), r = String(t.getMinutes()).padStart(2, "0"), i = String(t.getSeconds()).padStart(2, "0"), a = String(t.getMilliseconds()).padStart(3, "0"), o = `[${e.scope ?? "?"}/${e.source}]`, s = _n(e.fields);
|
|
1705
|
+
return `${n}:${r}:${i}.${a} ${fn[e.level]} ${o} ${e.message}${s}`;
|
|
1706
|
+
}, gn = 80, _n = (e) => {
|
|
1707
|
+
let t = Object.entries(e);
|
|
1708
|
+
if (t.length === 0) return "";
|
|
1709
|
+
let n = [];
|
|
1710
|
+
for (let [e, r] of t) {
|
|
1711
|
+
if (r === void 0) continue;
|
|
1712
|
+
let t = vn(r);
|
|
1713
|
+
n.push(`${e}=${t}`);
|
|
1714
|
+
}
|
|
1715
|
+
return n.length > 0 ? " " + n.join(" ") : "";
|
|
1716
|
+
}, vn = (e) => {
|
|
1717
|
+
if (typeof e == "string") {
|
|
1718
|
+
let t = e.length > gn ? e.slice(0, gn) + "…" : e;
|
|
1719
|
+
return /[\s=]/.test(t) ? `"${t.replace(/"/g, "\\\"")}"` : t;
|
|
1720
|
+
}
|
|
1721
|
+
if (e === null) return "null";
|
|
1722
|
+
if (typeof e == "number" || typeof e == "boolean") return String(e);
|
|
1723
|
+
try {
|
|
1724
|
+
let t = JSON.stringify(e);
|
|
1725
|
+
return t.length > gn ? t.slice(0, gn) + "…" : t;
|
|
1726
|
+
} catch {
|
|
1727
|
+
return "[unserialisable]";
|
|
1728
|
+
}
|
|
1729
|
+
}, yn = "/_voltro/inspect/logs", bn = g({ scope: "voltro:cli" }), xn = [], Sn = (e) => {
|
|
1730
|
+
xn.length = 0;
|
|
1731
|
+
let r = e[1] && !e[1].startsWith("-") ? e[1] : void 0, i = r ? n(r) ? r : a(process.cwd(), r) : process.cwd(), o = [], s = i;
|
|
1732
|
+
for (;;) {
|
|
1733
|
+
o.push(s);
|
|
1734
|
+
let e = t(s);
|
|
1735
|
+
if (e === s) break;
|
|
1736
|
+
s = e;
|
|
1737
|
+
}
|
|
1738
|
+
for (let e of o) for (let t of [".env.local", ".env"]) {
|
|
1739
|
+
let n = a(e, t);
|
|
1740
|
+
if (y(n)) {
|
|
1741
|
+
xn.push(n);
|
|
1742
|
+
try {
|
|
1743
|
+
let e = C(n, "utf8");
|
|
1744
|
+
for (let t of e.split(/\r?\n/)) {
|
|
1745
|
+
let e = t.trim();
|
|
1746
|
+
if (e === "" || e.startsWith("#")) continue;
|
|
1747
|
+
let n = e.indexOf("=");
|
|
1748
|
+
if (n < 1) continue;
|
|
1749
|
+
let r = e.slice(0, n).trim(), i = e.slice(n + 1).trim();
|
|
1750
|
+
(i.startsWith("\"") && i.endsWith("\"") || i.startsWith("'") && i.endsWith("'")) && (i = i.slice(1, -1)), process.env[r] === void 0 && (process.env[r] = i);
|
|
1751
|
+
}
|
|
1752
|
+
} catch (e) {
|
|
1753
|
+
bn.warn("failed to load env file (continuing)", { path: n }, e);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
}, Cn = 500, wn = (e, t, n = {}) => {
|
|
1758
|
+
if (e.length === 0) return () => {};
|
|
1759
|
+
let r = (e) => n.root ? i(n.root, e) : e, a = !1, o = (e) => {
|
|
1760
|
+
a || (a = !0, t.warn(`.env changed (${r(e)}) — hard-restarting: process.env is read once at boot, a reload would keep stale values`, { file: r(e) }), Promise.resolve().then(() => n.onBeforeRestart?.()).catch((e) => t.warn(".env restart: onBeforeRestart failed (continuing)", {}, e)).finally(() => {
|
|
1761
|
+
let e = fe(process.execPath, [...process.execArgv, ...process.argv.slice(1)], {
|
|
1762
|
+
stdio: "inherit",
|
|
1763
|
+
env: process.env,
|
|
1764
|
+
cwd: n.cwd ?? process.cwd()
|
|
1765
|
+
}), r = (t) => {
|
|
1766
|
+
e.kill(t);
|
|
1767
|
+
}, i = () => r("SIGINT"), a = () => r("SIGTERM");
|
|
1768
|
+
process.on("SIGINT", i), process.on("SIGTERM", a), e.on("exit", (e, t) => {
|
|
1769
|
+
process.off("SIGINT", i), process.off("SIGTERM", a), t ? process.kill(process.pid, t) : process.exit(e ?? 0);
|
|
1770
|
+
}), e.on("error", (e) => {
|
|
1771
|
+
t.error(".env restart: spawn failed", {}, e), process.exit(1);
|
|
1772
|
+
});
|
|
1773
|
+
}));
|
|
1774
|
+
};
|
|
1775
|
+
for (let t of e) D(t, { interval: Cn }, (e, n) => {
|
|
1776
|
+
e.mtimeMs !== n.mtimeMs && o(t);
|
|
1777
|
+
});
|
|
1778
|
+
return t.info("watching .env files for changes", {
|
|
1779
|
+
files: e.map(r),
|
|
1780
|
+
intervalMs: Cn
|
|
1781
|
+
}), () => {
|
|
1782
|
+
for (let t of e) ee(t);
|
|
1783
|
+
};
|
|
1784
|
+
}, Tn = [{
|
|
1785
|
+
match: (e) => typeof e == "string" && e.startsWith("[BABEL] Note: The code generator has deoptimised"),
|
|
1786
|
+
handle: (e, t) => {
|
|
1787
|
+
let n = e[0], r = n.match(/deoptimised the styling of (.+?) as it exceeds the max of (\d+\w*B)\.?/);
|
|
1788
|
+
if (r) {
|
|
1789
|
+
let [, e, n] = r;
|
|
1790
|
+
t.info(`code generator deoptimised (${n}+)`, {
|
|
1791
|
+
path: e,
|
|
1792
|
+
threshold: n
|
|
1793
|
+
});
|
|
1794
|
+
} else t.info(n);
|
|
1795
|
+
}
|
|
1796
|
+
}], En = () => {
|
|
1797
|
+
let e = {
|
|
1798
|
+
warn: console.warn.bind(console),
|
|
1799
|
+
error: console.error.bind(console)
|
|
1800
|
+
}, t = g({ scope: "babel" }), n = !1, r = (r) => (...i) => {
|
|
1801
|
+
if (!n) {
|
|
1802
|
+
for (let e of Tn) if (e.match(i[0])) {
|
|
1803
|
+
n = !0;
|
|
1804
|
+
try {
|
|
1805
|
+
e.handle(i, t);
|
|
1806
|
+
} finally {
|
|
1807
|
+
n = !1;
|
|
1808
|
+
}
|
|
1809
|
+
return;
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
e[r](...i);
|
|
1813
|
+
};
|
|
1814
|
+
return console.warn = r("warn"), console.error = r("error"), () => {
|
|
1815
|
+
console.warn = e.warn, console.error = e.error;
|
|
1816
|
+
};
|
|
1817
|
+
}, Dn = () => {
|
|
1818
|
+
let e = /* @__PURE__ */ new Map();
|
|
1819
|
+
return {
|
|
1820
|
+
get(t) {
|
|
1821
|
+
return e.get(t);
|
|
1822
|
+
},
|
|
1823
|
+
set(t, n) {
|
|
1824
|
+
e.set(t, n);
|
|
1825
|
+
},
|
|
1826
|
+
invalidate(t) {
|
|
1827
|
+
e.delete(t);
|
|
1828
|
+
},
|
|
1829
|
+
invalidateBy(t) {
|
|
1830
|
+
let n = 0;
|
|
1831
|
+
for (let r of e.keys()) t(r) && (e.delete(r), n++);
|
|
1832
|
+
return n;
|
|
1833
|
+
},
|
|
1834
|
+
clear() {
|
|
1835
|
+
e.clear();
|
|
1836
|
+
},
|
|
1837
|
+
size() {
|
|
1838
|
+
return e.size;
|
|
1839
|
+
},
|
|
1840
|
+
snapshot() {
|
|
1841
|
+
return Array.from(e.entries());
|
|
1842
|
+
}
|
|
1843
|
+
};
|
|
1844
|
+
}, On = (e) => {
|
|
1845
|
+
if (typeof e == "number" && Number.isFinite(e) && e > 0) return e * 1e3;
|
|
1846
|
+
if (typeof e != "string") return null;
|
|
1847
|
+
let t = /^\s*(\d+)\s*(s|seconds?|m|minutes?|h|hours?|d|days?)\s*$/i.exec(e);
|
|
1848
|
+
if (!t) return null;
|
|
1849
|
+
let n = parseInt(t[1], 10);
|
|
1850
|
+
if (!Number.isFinite(n) || n <= 0) return null;
|
|
1851
|
+
let r = t[2].toLowerCase();
|
|
1852
|
+
return r === "s" || r.startsWith("second") ? n * 1e3 : r === "m" || r.startsWith("minute") ? n * 6e4 : r === "h" || r.startsWith("hour") ? n * 36e5 : r === "d" || r.startsWith("day") ? n * 864e5 : null;
|
|
1853
|
+
}, kn = (e, t = {}) => {
|
|
1854
|
+
let n = [e];
|
|
1855
|
+
return t.tenant !== void 0 && t.tenant !== "" && n.push(`tenant=${t.tenant}`), t.locale !== void 0 && t.locale !== "" && n.push(`lang=${t.locale}`), n.join("|");
|
|
1856
|
+
}, An = (e, t) => e.expiresAt > t, jn = (e, t) => e.expiresAt <= t && e.servableUntil > t, Mn = r(F(), ".voltro"), Nn = r(Mn, "runtime-registry.json"), Pn = 3e4, Fn = () => {
|
|
1857
|
+
let e = Math.random().toString(36).slice(2, 10);
|
|
1858
|
+
return `${Nn}.${process.pid}.${Date.now()}.${e}.tmp`;
|
|
1859
|
+
}, In = async () => {
|
|
1860
|
+
await S.mkdir(Mn, { recursive: !0 });
|
|
1861
|
+
}, Ln = async () => {
|
|
1862
|
+
try {
|
|
1863
|
+
let e = await S.readFile(Nn, "utf8"), t = JSON.parse(e);
|
|
1864
|
+
return t.version !== 1 || !Array.isArray(t.apps) ? {
|
|
1865
|
+
version: 1,
|
|
1866
|
+
apps: []
|
|
1867
|
+
} : t;
|
|
1868
|
+
} catch {
|
|
1869
|
+
return {
|
|
1870
|
+
version: 1,
|
|
1871
|
+
apps: []
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
}, Rn = async (e) => {
|
|
1875
|
+
await In();
|
|
1876
|
+
let t = Fn();
|
|
1877
|
+
try {
|
|
1878
|
+
await S.writeFile(t, JSON.stringify(e, null, 2), "utf8"), await S.rename(t, Nn);
|
|
1879
|
+
} catch (e) {
|
|
1880
|
+
try {
|
|
1881
|
+
await S.unlink(t);
|
|
1882
|
+
} catch {}
|
|
1883
|
+
throw e;
|
|
1884
|
+
}
|
|
1885
|
+
}, zn = (e) => {
|
|
1886
|
+
try {
|
|
1887
|
+
return process.kill(e, 0), !0;
|
|
1888
|
+
} catch {
|
|
1889
|
+
return !1;
|
|
1890
|
+
}
|
|
1891
|
+
}, Bn = (e) => {
|
|
1892
|
+
let t = Date.now();
|
|
1893
|
+
return e.filter((e) => zn(e.pid) ? t - new Date(e.heartbeatAt).getTime() < Pn : !1);
|
|
1894
|
+
}, Vn = async () => {
|
|
1895
|
+
let e = await Ln(), t = Bn(e.apps);
|
|
1896
|
+
if (t.length === e.apps.length) return e;
|
|
1897
|
+
try {
|
|
1898
|
+
await Rn({
|
|
1899
|
+
version: 1,
|
|
1900
|
+
apps: t
|
|
1901
|
+
});
|
|
1902
|
+
} catch {}
|
|
1903
|
+
return {
|
|
1904
|
+
version: 1,
|
|
1905
|
+
apps: t
|
|
1906
|
+
};
|
|
1907
|
+
}, Hn = async (e) => {
|
|
1908
|
+
let t = await Ln(), n = (/* @__PURE__ */ new Date()).toISOString(), r = t.apps.findIndex((t) => t.id === e.id), i = {
|
|
1909
|
+
...e,
|
|
1910
|
+
registeredAt: r >= 0 ? t.apps[r].registeredAt : n,
|
|
1911
|
+
heartbeatAt: n
|
|
1912
|
+
};
|
|
1913
|
+
await Rn({
|
|
1914
|
+
version: 1,
|
|
1915
|
+
apps: r >= 0 ? t.apps.map((e, t) => t === r ? i : e) : [...t.apps, i]
|
|
1916
|
+
});
|
|
1917
|
+
}, Un = async (e) => {
|
|
1918
|
+
try {
|
|
1919
|
+
let t = await Ln(), n = t.apps.filter((t) => t.id !== e);
|
|
1920
|
+
if (n.length === t.apps.length) return;
|
|
1921
|
+
await Rn({
|
|
1922
|
+
version: 1,
|
|
1923
|
+
apps: n
|
|
1924
|
+
});
|
|
1925
|
+
} catch {}
|
|
1926
|
+
}, Wn = (e, t, n) => `${e}:${t}:${n}`, X = r(F(), ".voltro", "logs"), Gn = () => {
|
|
1927
|
+
let e = Number(process.env.VOLTRO_LOG_FILE_TTL_MS);
|
|
1928
|
+
return Number.isFinite(e) && e > 0 ? e : 3600 * 1e3;
|
|
1929
|
+
}, Kn = !1, qn = () => {
|
|
1930
|
+
if (Kn) return;
|
|
1931
|
+
Kn = !0;
|
|
1932
|
+
let e = Date.now() - Gn(), t = [];
|
|
1933
|
+
try {
|
|
1934
|
+
t = w(X);
|
|
1935
|
+
} catch {
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
for (let n of t) {
|
|
1939
|
+
if (!n.endsWith(".log")) continue;
|
|
1940
|
+
let t = r(X, n);
|
|
1941
|
+
try {
|
|
1942
|
+
T(t).mtimeMs < e && E(t);
|
|
1943
|
+
} catch {}
|
|
1944
|
+
}
|
|
1945
|
+
}, Jn = (e) => e.replace(/[^a-zA-Z0-9._-]/g, "_").slice(0, 80), Yn = (e, t) => r(X, `${Jn(e)}-${t}.log`), Xn = (e) => {
|
|
1946
|
+
let t = Jn(e), n = [];
|
|
1947
|
+
try {
|
|
1948
|
+
n = w(X);
|
|
1949
|
+
} catch {
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1952
|
+
let i = n.filter((e) => e.startsWith(`${t}-`) && e.endsWith(".log"));
|
|
1953
|
+
if (i.length === 0) return;
|
|
1954
|
+
let a, o = -1;
|
|
1955
|
+
for (let e of i) {
|
|
1956
|
+
let t = r(X, e);
|
|
1957
|
+
try {
|
|
1958
|
+
let e = T(t);
|
|
1959
|
+
e.mtimeMs > o && (o = e.mtimeMs, a = t);
|
|
1960
|
+
} catch {}
|
|
1961
|
+
}
|
|
1962
|
+
return a;
|
|
1963
|
+
}, Zn = (e) => {
|
|
1964
|
+
try {
|
|
1965
|
+
b(X, { recursive: !0 });
|
|
1966
|
+
} catch {}
|
|
1967
|
+
qn();
|
|
1968
|
+
let t = Yn(e, process.pid), n = x(t, "w"), r = (e) => {
|
|
1969
|
+
let t = {
|
|
1970
|
+
ts: e.ts.getTime(),
|
|
1971
|
+
level: e.level,
|
|
1972
|
+
source: e.scope === "client" ? "client" : "server",
|
|
1973
|
+
message: e.message,
|
|
1974
|
+
fields: e.fields
|
|
1975
|
+
};
|
|
1976
|
+
e.scope !== void 0 && (t.scope = e.scope);
|
|
1977
|
+
try {
|
|
1978
|
+
return JSON.stringify(t) + "\n";
|
|
1979
|
+
} catch {
|
|
1980
|
+
return JSON.stringify({
|
|
1981
|
+
ts: e.ts.getTime(),
|
|
1982
|
+
level: e.level,
|
|
1983
|
+
source: t.source,
|
|
1984
|
+
message: e.message,
|
|
1985
|
+
fields: {},
|
|
1986
|
+
...e.scope === void 0 ? {} : { scope: e.scope }
|
|
1987
|
+
}) + "\n";
|
|
1988
|
+
}
|
|
1989
|
+
}, i = !1, a = h((e) => {
|
|
1990
|
+
if (!i) try {
|
|
1991
|
+
te(n, r(e));
|
|
1992
|
+
} catch {}
|
|
1993
|
+
}), o = () => {
|
|
1994
|
+
if (!i) {
|
|
1995
|
+
i = !0;
|
|
1996
|
+
try {
|
|
1997
|
+
v(n);
|
|
1998
|
+
} catch {}
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
2001
|
+
process.once("exit", o);
|
|
2002
|
+
let s = () => o();
|
|
2003
|
+
return process.on("uncaughtException", s), process.on("unhandledRejection", s), {
|
|
2004
|
+
path: t,
|
|
2005
|
+
dispose: async () => {
|
|
2006
|
+
a(), o(), process.off("exit", o), process.off("uncaughtException", s), process.off("unhandledRejection", s);
|
|
2007
|
+
}
|
|
2008
|
+
};
|
|
2009
|
+
}, Qn = async (e, t) => {
|
|
2010
|
+
let n;
|
|
2011
|
+
try {
|
|
2012
|
+
n = await S.readFile(e, "utf8");
|
|
2013
|
+
} catch {
|
|
2014
|
+
return [];
|
|
2015
|
+
}
|
|
2016
|
+
let r = n.split("\n"), i = [], a = t?.since ?? 0;
|
|
2017
|
+
for (let e of r) if (e.length !== 0) try {
|
|
2018
|
+
let t = JSON.parse(e);
|
|
2019
|
+
if (typeof t.ts != "number" || t.ts < a) continue;
|
|
2020
|
+
i.push(t);
|
|
2021
|
+
} catch {}
|
|
2022
|
+
return t?.max !== void 0 && i.length > t.max ? i.slice(i.length - t.max) : i;
|
|
2023
|
+
}, $n = g({ scope: "voltro:dashboard" }), er = he(import.meta.url), tr = 5179, nr = (e) => {
|
|
2024
|
+
let n = process.env.VOLTRO_DASHBOARD_PATH;
|
|
2025
|
+
if (n && y(r(a(n), "app.config.ts"))) return a(n);
|
|
2026
|
+
try {
|
|
2027
|
+
let e = t(er.resolve("@voltro/dashboard/package.json"));
|
|
2028
|
+
if (y(r(e, "app.config.ts"))) return e;
|
|
2029
|
+
} catch {}
|
|
2030
|
+
let i = r("voltro-devtools", "apps", "dashboard"), o = a(e);
|
|
2031
|
+
for (let e = 0; e < 10; e++) {
|
|
2032
|
+
let e = r(o, i);
|
|
2033
|
+
if (y(r(e, "app.config.ts"))) return e;
|
|
2034
|
+
let n = t(o);
|
|
2035
|
+
if (n === o) break;
|
|
2036
|
+
o = n;
|
|
2037
|
+
}
|
|
2038
|
+
return null;
|
|
2039
|
+
}, rr = "VOLTRO_IS_DASHBOARD", ir = (e, t = "127.0.0.1", n = 250) => new Promise((r) => {
|
|
2040
|
+
let i = me({
|
|
2041
|
+
port: e,
|
|
2042
|
+
host: t
|
|
2043
|
+
}), a = !1, o = (e) => {
|
|
2044
|
+
a || (a = !0, i.destroy(), r(e));
|
|
2045
|
+
};
|
|
2046
|
+
i.once("connect", () => o(!0)), i.once("error", () => o(!1)), setTimeout(() => o(!1), n);
|
|
2047
|
+
}), ar = () => !!(process.env.VOLTRO_DASHBOARD === "off" || process.argv.includes("--disable-dashboard")), or = () => process.env[rr] === "1", sr = () => process.stdout.isTTY === !0, cr = r(F(), ".voltro", "dashboard-launch.lock"), lr = 1e4, ur = async () => {
|
|
2048
|
+
try {
|
|
2049
|
+
await S.mkdir(t(cr), { recursive: !0 });
|
|
2050
|
+
let e = await S.open(cr, "wx");
|
|
2051
|
+
return await e.write(`${process.pid}\n${Date.now()}\n`), await e.close(), !0;
|
|
2052
|
+
} catch {
|
|
2053
|
+
try {
|
|
2054
|
+
let e = await S.stat(cr);
|
|
2055
|
+
if (Date.now() - e.mtimeMs > lr) return await S.unlink(cr).catch(() => void 0), ur();
|
|
2056
|
+
} catch {}
|
|
2057
|
+
return !1;
|
|
2058
|
+
}
|
|
2059
|
+
}, dr = async () => {
|
|
2060
|
+
try {
|
|
2061
|
+
await S.unlink(cr);
|
|
2062
|
+
} catch {}
|
|
2063
|
+
}, fr = async (e) => {
|
|
2064
|
+
let n = e.port ?? 5179;
|
|
2065
|
+
if (ar()) return {
|
|
2066
|
+
status: "skipped",
|
|
2067
|
+
reason: "disabled by flag/env",
|
|
2068
|
+
port: n
|
|
2069
|
+
};
|
|
2070
|
+
if (or()) return {
|
|
2071
|
+
status: "skipped",
|
|
2072
|
+
reason: "this process IS the dashboard",
|
|
2073
|
+
port: n
|
|
2074
|
+
};
|
|
2075
|
+
if (!sr()) return {
|
|
2076
|
+
status: "skipped",
|
|
2077
|
+
reason: "stdout is not a TTY (CI/smoke)",
|
|
2078
|
+
port: n
|
|
2079
|
+
};
|
|
2080
|
+
if (!await ur()) return {
|
|
2081
|
+
status: "skipped",
|
|
2082
|
+
reason: "another voltro process is currently launching the dashboard",
|
|
2083
|
+
port: n
|
|
2084
|
+
};
|
|
2085
|
+
if (await ir(n)) return await dr(), {
|
|
2086
|
+
status: "already-running",
|
|
2087
|
+
port: n
|
|
2088
|
+
};
|
|
2089
|
+
let i = e.voltroBin;
|
|
2090
|
+
if (!i) {
|
|
2091
|
+
let e = process.argv[1];
|
|
2092
|
+
i = e && e.endsWith("/src/bin.ts") ? r(t(e), "..", "bin", "voltro.mjs") : e ?? "voltro";
|
|
2093
|
+
}
|
|
2094
|
+
let a = y(r(e.dashboardAppPath, ".framework", "dist", "index.html")), o = a ? "start" : "dev", s = fe(process.execPath, [
|
|
2095
|
+
i,
|
|
2096
|
+
o,
|
|
2097
|
+
e.dashboardAppPath
|
|
2098
|
+
], {
|
|
2099
|
+
stdio: "ignore",
|
|
2100
|
+
env: {
|
|
2101
|
+
...process.env,
|
|
2102
|
+
[rr]: "1",
|
|
2103
|
+
VOLTRO_DASHBOARD_PORT: String(n)
|
|
2104
|
+
}
|
|
2105
|
+
});
|
|
2106
|
+
return process.on("exit", () => {
|
|
2107
|
+
if (s.exitCode === null && s.signalCode === null) try {
|
|
2108
|
+
s.kill("SIGTERM");
|
|
2109
|
+
} catch {}
|
|
2110
|
+
}), $n.info(`auto-launching dashboard at http://localhost:${n}`, {
|
|
2111
|
+
port: n,
|
|
2112
|
+
mode: o,
|
|
2113
|
+
prebuilt: a
|
|
2114
|
+
}), a || $n.debug("no pre-built dashboard — running `voltro dev`. Build with `cd voltro-devtools && pnpm build` for a fast prod boot."), $n.debug("disable via --disable-dashboard or VOLTRO_DASHBOARD=off"), setTimeout(() => {
|
|
2115
|
+
dr();
|
|
2116
|
+
}, 4e3).unref(), {
|
|
2117
|
+
status: "launched",
|
|
2118
|
+
port: n
|
|
2119
|
+
};
|
|
2120
|
+
}, Z = g({ scope: "voltro:dev:web" }), pr = g({ scope: "vite" }), mr = await (async () => {
|
|
2121
|
+
try {
|
|
2122
|
+
let e = r(t(o(import.meta.url)), "..", "package.json"), n = await S.readFile(e, "utf8");
|
|
2123
|
+
return JSON.parse(n).version ?? "0.0.0";
|
|
2124
|
+
} catch {
|
|
2125
|
+
return "0.0.0";
|
|
2126
|
+
}
|
|
2127
|
+
})(), hr = async () => {
|
|
2128
|
+
try {
|
|
2129
|
+
let e = t(o(import.meta.url)), n = a(e, "..", "..", "devtools");
|
|
2130
|
+
if (y(r(n, "package.json"))) return n;
|
|
2131
|
+
let i = a(e, "..", "..", "..", "devtools");
|
|
2132
|
+
return y(r(i, "package.json")) ? i : null;
|
|
2133
|
+
} catch {
|
|
2134
|
+
return null;
|
|
2135
|
+
}
|
|
2136
|
+
}, gr = (e, t) => e.disableDevtools || !t ? [] : [
|
|
2137
|
+
"",
|
|
2138
|
+
"// Dev-only in-page devtools overlay. The `import.meta.env.DEV` guard is a",
|
|
2139
|
+
"// compile-time constant, so prod builds strip this whole `if` block — the",
|
|
2140
|
+
"// dynamic `@voltro/devtools` import (+ its CSS) never reaches Rollup.",
|
|
2141
|
+
"let Devtools",
|
|
2142
|
+
"if (import.meta.env.DEV) {",
|
|
2143
|
+
" await import('@voltro/devtools/styles.css')",
|
|
2144
|
+
" Devtools = (await import('@voltro/devtools')).VoltroDevtools",
|
|
2145
|
+
"}"
|
|
2146
|
+
], _r = (e, t) => e.disableDevtools || !t ? [] : [" ...(Devtools ? { Devtools } : {}),"], vr = (e) => e.sentry ? ["import { initSentryBrowser } from '@voltro/plugin-sentry/web'"] : [], yr = (e) => e.sentry ? [
|
|
2147
|
+
"",
|
|
2148
|
+
"// Browser-side Sentry (frontend half of the deep integration). Errors +",
|
|
2149
|
+
"// browser rpc spans flow to Sentry, sharing the server transactions' trace.",
|
|
2150
|
+
`await initSentryBrowser(${JSON.stringify(e.sentry)})`
|
|
2151
|
+
] : [], br = (e) => e.env ? ["import './env.public'"] : [], xr = (e) => {
|
|
2152
|
+
let n = [], i = a(e);
|
|
2153
|
+
for (;;) {
|
|
2154
|
+
y(r(i, "pnpm-workspace.yaml")) && n.push(i);
|
|
2155
|
+
let e = t(i);
|
|
2156
|
+
if (e === i) break;
|
|
2157
|
+
i = e;
|
|
2158
|
+
}
|
|
2159
|
+
return n;
|
|
2160
|
+
}, Sr = /* @__PURE__ */ new Set([
|
|
2161
|
+
"layout.tsx",
|
|
2162
|
+
"error.tsx",
|
|
2163
|
+
"loading.tsx",
|
|
2164
|
+
"not-found.tsx"
|
|
2165
|
+
]), Cr = (e) => /\.(test|spec)\.tsx$/.test(e), wr = (e) => {
|
|
2166
|
+
if (/\/node_modules\/(?:\.pnpm\/[^/]+\/node_modules\/)?(?:react|react-dom|scheduler)\//.test(e)) return "react";
|
|
2167
|
+
let t = /\/([^/]+)\.island\.tsx?$/.exec(e);
|
|
2168
|
+
if (t) return `island-${t[1]}`;
|
|
2169
|
+
}, Tr = /export\s+(?:async\s+)?(?:const|function|let|var)\s+loader\b/, Er = (e) => e.startsWith("(") && e.endsWith(")"), Dr = (e) => e.filter((e) => !Er(e)), Or = (e) => {
|
|
2170
|
+
let t = e.replace(/\.tsx$/, "").split("/").filter(Boolean).filter((e) => !Er(e)), n = t.length > 0 && t[t.length - 1] === "index" ? t.slice(0, -1) : t;
|
|
2171
|
+
return n.length === 0 ? "/" : "/" + n.join("/");
|
|
2172
|
+
}, kr = (e) => `${e.replace(/\.tsx$/, "").split("/").filter(Boolean).map((e) => e.replace(/[()]/g, "").replace(/\[\.\.\./g, "_rest_").replace(/[[\]]/g, "_")).map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join("").replace(/[^A-Za-z0-9_]/g, "_") || "Index"}Page`, Q = (e, t) => e === "" ? `Root${t}` : `${e.split("/").filter(Boolean).map((e) => e.replace(/[()]/g, "").replace(/\[\.\.\./g, "_rest_").replace(/[[\]]/g, "_")).map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join("").replace(/[^A-Za-z0-9_]/g, "_") || "Root"}${t}`, $ = async (e) => {
|
|
2173
|
+
let t = [], n = [], i = async (e, a) => {
|
|
2174
|
+
let o = [];
|
|
2175
|
+
try {
|
|
2176
|
+
o = await S.readdir(e, { withFileTypes: !0 });
|
|
2177
|
+
} catch {
|
|
2178
|
+
return;
|
|
2179
|
+
}
|
|
2180
|
+
let s = o.filter((e) => e.isDirectory()).map((e) => e.name).sort(), c = o.filter((e) => e.isFile() && e.name.endsWith(".tsx") && !Cr(e.name)).map((e) => e.name).sort(), l = new Set(c), u = a.join("/");
|
|
2181
|
+
if (c.some((e) => Sr.has(e))) {
|
|
2182
|
+
let t = l.has("layout.tsx"), i = !1;
|
|
2183
|
+
if (t) try {
|
|
2184
|
+
let t = await S.readFile(r(e, "layout.tsx"), "utf8");
|
|
2185
|
+
i = Tr.test(t);
|
|
2186
|
+
} catch {}
|
|
2187
|
+
n.push({
|
|
2188
|
+
dir: u,
|
|
2189
|
+
chain: a,
|
|
2190
|
+
contributesToUrl: a.length === 0 || !Er(a[a.length - 1]),
|
|
2191
|
+
hasLayout: t,
|
|
2192
|
+
hasLayoutLoader: i,
|
|
2193
|
+
hasError: l.has("error.tsx"),
|
|
2194
|
+
hasPending: l.has("loading.tsx"),
|
|
2195
|
+
hasNotFound: l.has("not-found.tsx")
|
|
2196
|
+
});
|
|
2197
|
+
}
|
|
2198
|
+
for (let e of c) {
|
|
2199
|
+
if (Sr.has(e)) continue;
|
|
2200
|
+
let n = u ? `${u}/${e}` : e;
|
|
2201
|
+
t.push({
|
|
2202
|
+
file: n,
|
|
2203
|
+
pattern: Or(n),
|
|
2204
|
+
ident: kr(n),
|
|
2205
|
+
dirChain: a
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
for (let t of s) await i(r(e, t), [...a, t]);
|
|
2209
|
+
};
|
|
2210
|
+
return await i(e, []), t.sort((e, t) => e.file < t.file ? -1 : 1), {
|
|
2211
|
+
pages: t,
|
|
2212
|
+
dirs: n
|
|
2213
|
+
};
|
|
2214
|
+
}, Ar = (e, t) => {
|
|
2215
|
+
let n = [];
|
|
2216
|
+
for (let r = 0; r <= t.length; r++) {
|
|
2217
|
+
let i = t.slice(0, r).join("/"), a = e.find((e) => e.dir === i);
|
|
2218
|
+
a && n.push(a);
|
|
2219
|
+
}
|
|
2220
|
+
return n;
|
|
2221
|
+
}, jr = (e) => {
|
|
2222
|
+
let t = Dr(e);
|
|
2223
|
+
return t.length === 0 ? "" : "/" + t.join("/");
|
|
2224
|
+
}, Mr = [
|
|
2225
|
+
"// Hot-reload bridge: keep SSR-injected <link rel=\"stylesheet\"> tags",
|
|
2226
|
+
"// in sync with Vite's CSS HMR. Without this, edits to .css files",
|
|
2227
|
+
"// only update the JS-injected <style> overlay; the underlying <link>",
|
|
2228
|
+
"// stays pinned to the old CSS until a full page reload.",
|
|
2229
|
+
"//",
|
|
2230
|
+
"// Also publishes a \"Compiling…\" status to @voltro/web's statusBus so",
|
|
2231
|
+
"// the devtools floating button morphs into a Next.js-style pill while",
|
|
2232
|
+
"// vite is rebuilding. The dispose handle returned by pushStatus()",
|
|
2233
|
+
"// pops the status on vite:afterUpdate. Plain JS, no React in this",
|
|
2234
|
+
"// file — the bus is React-free.",
|
|
2235
|
+
"if (import.meta.hot) {",
|
|
2236
|
+
" let _vdtCompilingDispose = null",
|
|
2237
|
+
" let _vdtCompilingTimer = null",
|
|
2238
|
+
" const _vdtCompilingStart = (label) => {",
|
|
2239
|
+
" if (_vdtCompilingDispose) return // dedupe overlapping events",
|
|
2240
|
+
" import('@voltro/web').then((m) => {",
|
|
2241
|
+
" if (_vdtCompilingDispose) return",
|
|
2242
|
+
" _vdtCompilingDispose = m.pushStatus({",
|
|
2243
|
+
" id: 'voltro:hmr:compiling',",
|
|
2244
|
+
" kind: 'compiling',",
|
|
2245
|
+
" label,",
|
|
2246
|
+
" })",
|
|
2247
|
+
" }).catch(() => {})",
|
|
2248
|
+
" }",
|
|
2249
|
+
" const _vdtCompilingStop = () => {",
|
|
2250
|
+
" if (_vdtCompilingTimer) { clearTimeout(_vdtCompilingTimer); _vdtCompilingTimer = null }",
|
|
2251
|
+
" if (_vdtCompilingDispose) {",
|
|
2252
|
+
" // Hold the indicator briefly so single-frame compiles are still",
|
|
2253
|
+
" // visible — otherwise the morph happens too fast to register.",
|
|
2254
|
+
" _vdtCompilingTimer = setTimeout(() => {",
|
|
2255
|
+
" const dispose = _vdtCompilingDispose",
|
|
2256
|
+
" _vdtCompilingDispose = null",
|
|
2257
|
+
" _vdtCompilingTimer = null",
|
|
2258
|
+
" if (dispose) dispose()",
|
|
2259
|
+
" }, 220)",
|
|
2260
|
+
" }",
|
|
2261
|
+
" }",
|
|
2262
|
+
" import.meta.hot.on('vite:beforeUpdate', (payload) => {",
|
|
2263
|
+
" _vdtCompilingStart('Compiling…')",
|
|
2264
|
+
" for (const u of payload.updates ?? []) {",
|
|
2265
|
+
" if (u.type !== 'css-update' || !u.path) continue",
|
|
2266
|
+
" const targetPath = u.path.split('?')[0]",
|
|
2267
|
+
" const links = document.querySelectorAll('link[rel=\"stylesheet\"]')",
|
|
2268
|
+
" for (const link of links) {",
|
|
2269
|
+
" const href = link.getAttribute('href') ?? ''",
|
|
2270
|
+
" const linkPath = href.split('?')[0]",
|
|
2271
|
+
" if (linkPath === targetPath || linkPath.endsWith(targetPath)) {",
|
|
2272
|
+
" const url = new URL(href, window.location.origin)",
|
|
2273
|
+
" url.searchParams.set('t', String(Date.now()))",
|
|
2274
|
+
" link.setAttribute('href', url.toString())",
|
|
2275
|
+
" }",
|
|
2276
|
+
" }",
|
|
2277
|
+
" }",
|
|
2278
|
+
" })",
|
|
2279
|
+
" // Sticky \"Build error\" status on vite:error — held until the",
|
|
2280
|
+
" // next successful update clears it (vite:afterUpdate). Different",
|
|
2281
|
+
" // kind from compiling so the devtools FAB can re-colour to",
|
|
2282
|
+
" // danger red. The compile status (if any) is also cleared so we",
|
|
2283
|
+
" // don't show two pills at once.",
|
|
2284
|
+
" let _vdtErrorDispose = null",
|
|
2285
|
+
" const _vdtErrorStart = (label) => {",
|
|
2286
|
+
" if (_vdtErrorDispose) return",
|
|
2287
|
+
" import('@voltro/web').then((m) => {",
|
|
2288
|
+
" if (_vdtErrorDispose) return",
|
|
2289
|
+
" _vdtErrorDispose = m.pushStatus({",
|
|
2290
|
+
" id: 'voltro:hmr:error',",
|
|
2291
|
+
" kind: 'error',",
|
|
2292
|
+
" label,",
|
|
2293
|
+
" })",
|
|
2294
|
+
" }).catch(() => {})",
|
|
2295
|
+
" }",
|
|
2296
|
+
" const _vdtErrorStop = () => {",
|
|
2297
|
+
" if (_vdtErrorDispose) { _vdtErrorDispose(); _vdtErrorDispose = null }",
|
|
2298
|
+
" }",
|
|
2299
|
+
" import.meta.hot.on('vite:afterUpdate', () => {",
|
|
2300
|
+
" _vdtCompilingStop()",
|
|
2301
|
+
" _vdtErrorStop() // successful update clears any sticky build-error",
|
|
2302
|
+
" })",
|
|
2303
|
+
" import.meta.hot.on('vite:beforeFullReload', () => _vdtCompilingStart('Reloading…'))",
|
|
2304
|
+
" import.meta.hot.on('vite:error', (payload) => {",
|
|
2305
|
+
" _vdtCompilingStop()",
|
|
2306
|
+
" // Pill label stays short (\"Build error\") — the actual message",
|
|
2307
|
+
" // is way too long for a ~180px pill (e.g. \"Failed to resolve",
|
|
2308
|
+
" // import '../foo' from 'bar.tsx'\"). Detail goes to the console",
|
|
2309
|
+
" // (vite already logs it) and to the devtools error panel later.",
|
|
2310
|
+
" const err = payload?.err",
|
|
2311
|
+
" if (err && typeof err.message === 'string') {",
|
|
2312
|
+
" console.error('[voltro:hmr] build error:', err.message)",
|
|
2313
|
+
" }",
|
|
2314
|
+
" _vdtErrorStart('Build error')",
|
|
2315
|
+
" })",
|
|
2316
|
+
"}"
|
|
2317
|
+
].join("\n"), Nr = (e) => {
|
|
2318
|
+
let t = [], n = 0, r = e.split("/").filter(Boolean), i = [];
|
|
2319
|
+
for (let e of r) e.startsWith("[[...") && e.endsWith("]]") ? (i.push("(.*)"), t.push(e.slice(5, -2)), n += 2) : e.startsWith("[...") && e.endsWith("]") ? (i.push("(.+)"), t.push(e.slice(4, -1)), n += 3) : e.startsWith("[") && e.endsWith("]") ? (i.push("([^/]+)"), t.push(e.slice(1, -1)), n += 1) : i.push(e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
2320
|
+
let a = i.join("/");
|
|
2321
|
+
return {
|
|
2322
|
+
regex: a.length === 0 ? /^\/?$/ : RegExp(`^/${a}/?$`),
|
|
2323
|
+
paramNames: t,
|
|
2324
|
+
priority: n
|
|
2325
|
+
};
|
|
2326
|
+
}, Pr = (e) => e.map((e) => {
|
|
2327
|
+
let { regex: t, paramNames: n, priority: r } = Nr(e.pattern);
|
|
2328
|
+
return {
|
|
2329
|
+
pattern: e.pattern,
|
|
2330
|
+
file: e.file,
|
|
2331
|
+
dirChain: e.dirChain,
|
|
2332
|
+
regex: t,
|
|
2333
|
+
paramNames: n,
|
|
2334
|
+
priority: r
|
|
2335
|
+
};
|
|
2336
|
+
}).slice().sort((e, t) => e.priority - t.priority), Fr = (e, t) => {
|
|
2337
|
+
for (let n of t) {
|
|
2338
|
+
let t = n.regex.exec(e);
|
|
2339
|
+
if (!t) continue;
|
|
2340
|
+
let r = {};
|
|
2341
|
+
for (let e = 0; e < n.paramNames.length; e++) r[n.paramNames[e]] = t[e + 1] ?? "";
|
|
2342
|
+
return {
|
|
2343
|
+
route: n,
|
|
2344
|
+
params: r
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
return null;
|
|
2348
|
+
}, Ir = async (e, n) => {
|
|
2349
|
+
let i = e;
|
|
2350
|
+
for (;;) {
|
|
2351
|
+
let e = r(i, "node_modules", n);
|
|
2352
|
+
try {
|
|
2353
|
+
if ((await S.stat(e)).isDirectory()) {
|
|
2354
|
+
let t = await S.realpath(e);
|
|
2355
|
+
return t.includes("/node_modules/") ? null : t;
|
|
2356
|
+
}
|
|
2357
|
+
} catch {}
|
|
2358
|
+
let a = t(i);
|
|
2359
|
+
if (a === i) return null;
|
|
2360
|
+
i = a;
|
|
2361
|
+
}
|
|
2362
|
+
}, Lr = async (e) => {
|
|
2363
|
+
try {
|
|
2364
|
+
let t = await import(s(r(e, "app.config.ts")).href), n = t.default?.port, i = typeof n == "number" ? n : 4e3, a = t.default?.transport?.wsPath, o = typeof a == "string" && a.startsWith("/") ? a : void 0;
|
|
2365
|
+
return o ? {
|
|
2366
|
+
port: i,
|
|
2367
|
+
wsPath: o
|
|
2368
|
+
} : { port: i };
|
|
2369
|
+
} catch {}
|
|
2370
|
+
return { port: 4e3 };
|
|
2371
|
+
}, Rr = (e, t) => ({
|
|
2372
|
+
name: e,
|
|
2373
|
+
pkg: t.package,
|
|
2374
|
+
browserWsUrl: t.url,
|
|
2375
|
+
proxyTarget: void 0,
|
|
2376
|
+
...t.headers ? { headers: t.headers } : {}
|
|
2377
|
+
}), zr = (e, t, n) => {
|
|
2378
|
+
let r = t.transport?.wsPath ?? n.wsPath;
|
|
2379
|
+
return {
|
|
2380
|
+
name: e,
|
|
2381
|
+
pkg: t.package,
|
|
2382
|
+
browserWsUrl: r ?? `/ws/${e}`,
|
|
2383
|
+
proxyTarget: `ws://localhost:${n.port}`,
|
|
2384
|
+
...r ? { wsPath: r } : {},
|
|
2385
|
+
...t.headers ? { headers: t.headers } : {}
|
|
2386
|
+
};
|
|
2387
|
+
}, Br = (e) => {
|
|
2388
|
+
let t = /* @__PURE__ */ new Map();
|
|
2389
|
+
for (let n of e) {
|
|
2390
|
+
if (n.proxyTarget === void 0) continue;
|
|
2391
|
+
let e = t.get(n.browserWsUrl);
|
|
2392
|
+
if (e) throw Error(`[voltro] api ${JSON.stringify(n.name)} and ${JSON.stringify(e)} both resolve the same-origin WS path ${JSON.stringify(n.browserWsUrl)}. A custom transport.wsPath must be unique per origin (one api per origin may use a fixed path). Give each a distinct wsPath, or drop the override to use the default /ws/<name>.`);
|
|
2393
|
+
t.set(n.browserWsUrl, n.name);
|
|
2394
|
+
}
|
|
2395
|
+
}, Vr = async (e, t) => {
|
|
2396
|
+
let n = Object.entries(t.apis ?? {}), r = [];
|
|
2397
|
+
for (let [t, i] of n) {
|
|
2398
|
+
if (i.url) {
|
|
2399
|
+
r.push(Rr(t, i));
|
|
2400
|
+
continue;
|
|
2401
|
+
}
|
|
2402
|
+
let n = await Ir(e, i.package);
|
|
2403
|
+
if (!n) throw Error(`[voltro dev] api ${JSON.stringify(t)} (package ${JSON.stringify(i.package)}) is not a workspace dep and has no \`url\` set in app.config.ts. External apis need an explicit \`url\` because the framework can't discover their dev port.`);
|
|
2404
|
+
r.push(zr(t, i, await Lr(n)));
|
|
2405
|
+
}
|
|
2406
|
+
return Br(r), r;
|
|
2407
|
+
}, Hr = (e) => {
|
|
2408
|
+
if (!e) return;
|
|
2409
|
+
let t = e.proxyTarget ?? e.browserWsUrl;
|
|
2410
|
+
if (t && !(!/^wss?:\/\//.test(t) && !/^https?:\/\//.test(t))) try {
|
|
2411
|
+
let e = new URL(t);
|
|
2412
|
+
return e.protocol = e.protocol === "wss:" || e.protocol === "https:" ? "https:" : "http:", `${e.protocol}//${e.host}`;
|
|
2413
|
+
} catch {
|
|
2414
|
+
return;
|
|
2415
|
+
}
|
|
2416
|
+
}, Ur = (e, t) => {
|
|
2417
|
+
if (e) return async (n, r) => {
|
|
2418
|
+
let i = {
|
|
2419
|
+
_tag: "Request",
|
|
2420
|
+
id: "0",
|
|
2421
|
+
tag: n,
|
|
2422
|
+
payload: r ?? {},
|
|
2423
|
+
headers: []
|
|
2424
|
+
}, a = await fetch(`${e}/rpc`, {
|
|
2425
|
+
method: "POST",
|
|
2426
|
+
headers: {
|
|
2427
|
+
"content-type": "application/json",
|
|
2428
|
+
...t ? { cookie: t } : {}
|
|
2429
|
+
},
|
|
2430
|
+
body: JSON.stringify(i)
|
|
2431
|
+
});
|
|
2432
|
+
if (!a.ok) throw Error(`[loader.query] ${n}: HTTP ${a.status} ${await a.text()}`);
|
|
2433
|
+
let o = await a.json();
|
|
2434
|
+
if (!Array.isArray(o)) throw Error(`[loader.query] ${n}: unexpected non-array rpc response`);
|
|
2435
|
+
let s = (e) => e && typeof e == "object" && "_tag" in e && "data" in e && e._tag === "snapshot" ? e.data : e, c, l = !1;
|
|
2436
|
+
for (let e of o) {
|
|
2437
|
+
if (e._tag === "ClientProtocolError") throw Error(`[loader.query] ${n}: protocol error ${JSON.stringify(e.error)}`);
|
|
2438
|
+
if (!(e.requestId !== void 0 && String(e.requestId) !== "0")) {
|
|
2439
|
+
if (e._tag === "Chunk" && e.values && e.values.length > 0 && !l && (c = s(e.values[0]), l = !0), e._tag === "Defect") throw Error(`[loader.query] ${n}: defect ${JSON.stringify(e)}`);
|
|
2440
|
+
if (e._tag === "Exit" && e.exit) {
|
|
2441
|
+
if (e.exit._tag === "Failure") throw Error(`[loader.query] ${n}: rpc failed ${JSON.stringify(e.exit.cause ?? e.exit)}`);
|
|
2442
|
+
!l && e.exit._tag === "Success" && e.exit.value !== void 0 && (c = s(e.exit.value), l = !0);
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
if (l) return c;
|
|
2447
|
+
};
|
|
2448
|
+
}, Wr = async (e, t, n, i = {}) => {
|
|
2449
|
+
let a = t.title ?? t.name ?? "app", o = t.theme === "dark" ? " class=\"dark\"" : t.theme === "light" ? " class=\"light\"" : "", s = y(r(e, "node_modules", "@voltro", "devtools", "package.json")) || await hr() !== null, c = t.theme === "system" ? [
|
|
2450
|
+
" <script>",
|
|
2451
|
+
" (function () {",
|
|
2452
|
+
" var root = document.documentElement",
|
|
2453
|
+
" var readCookie = function () {",
|
|
2454
|
+
" try {",
|
|
2455
|
+
" var m = document.cookie.match(/(?:^|;\\s*)voltro:theme=([^;]*)/)",
|
|
2456
|
+
" return m ? decodeURIComponent(m[1]) : ''",
|
|
2457
|
+
" } catch (e) { return '' }",
|
|
2458
|
+
" }",
|
|
2459
|
+
" var apply = function () {",
|
|
2460
|
+
" var stored = readCookie()",
|
|
2461
|
+
" var dark = stored === 'dark' || (stored !== 'light' && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)",
|
|
2462
|
+
" root.classList.toggle('dark', dark)",
|
|
2463
|
+
" }",
|
|
2464
|
+
" apply()",
|
|
2465
|
+
" if (window.matchMedia) {",
|
|
2466
|
+
" try { window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', apply) } catch (e) {}",
|
|
2467
|
+
" }",
|
|
2468
|
+
" })()",
|
|
2469
|
+
" <\/script>"
|
|
2470
|
+
].join("\n") : "", l = [
|
|
2471
|
+
"<!doctype html>",
|
|
2472
|
+
"<!-- GENERATED BY `voltro dev` — do not edit; will be overwritten on next boot. -->",
|
|
2473
|
+
`<html lang="en"${o}>`,
|
|
2474
|
+
" <head>",
|
|
2475
|
+
" <meta charset=\"UTF-8\" />",
|
|
2476
|
+
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />",
|
|
2477
|
+
` <title>${a}</title>`,
|
|
2478
|
+
" <link rel=\"icon\" type=\"image/svg+xml\" href=\"/favicon.svg\" />",
|
|
2479
|
+
...c ? [c] : [],
|
|
2480
|
+
" </head>",
|
|
2481
|
+
" <body>",
|
|
2482
|
+
" <div id=\"root\"></div>",
|
|
2483
|
+
" <script type=\"module\" src=\"/main.tsx\"><\/script>",
|
|
2484
|
+
" </body>",
|
|
2485
|
+
"</html>",
|
|
2486
|
+
""
|
|
2487
|
+
].join("\n"), { pages: u, dirs: d } = await $(r(e, "src", "pages")), f = (e) => `${e.replace(/[^a-zA-Z0-9]/g, "_")}AppGroup`, p = (e) => `${e.replace(/[^a-zA-Z0-9]/g, "_")}AppDescriptors`, m = n.map((e) => `import { appGroup as ${f(e.name)}, appDescriptors as ${p(e.name)} } from '${e.pkg}/rpcGroup'`), h = n.map((e) => {
|
|
2488
|
+
let t = [`group: ${f(e.name)}`];
|
|
2489
|
+
return t.push(`descriptors: ${p(e.name)}`), t.push(`wsUrl: ${JSON.stringify(e.browserWsUrl)}`), e.headers && t.push(`headers: ${JSON.stringify(e.headers)}`), ` ${JSON.stringify(e.name)}: { ${t.join(", ")} },`;
|
|
2490
|
+
}), g, _;
|
|
2491
|
+
if (u.length > 0) {
|
|
2492
|
+
let e = u.map((e) => ` ${JSON.stringify(e.pattern)}: () => import('../src/pages/${e.file}'),`), n = [];
|
|
2493
|
+
for (let e of d) {
|
|
2494
|
+
let t = e.dir === "" ? "../src/pages" : `../src/pages/${e.dir}`;
|
|
2495
|
+
e.hasLayout && e.hasLayoutLoader ? n.push(`import * as ${Q(e.dir, "Layout")}Mod from '${t}/layout.tsx'`) : e.hasLayout && n.push(`import ${Q(e.dir, "Layout")} from '${t}/layout.tsx'`), e.hasError && n.push(`import ${Q(e.dir, "Error")} from '${t}/error.tsx'`), e.hasPending && n.push(`import ${Q(e.dir, "Pending")} from '${t}/loading.tsx'`), e.hasNotFound && n.push(`import ${Q(e.dir, "NotFound")} from '${t}/not-found.tsx'`);
|
|
2496
|
+
}
|
|
2497
|
+
let r = u.map((e) => {
|
|
2498
|
+
let t = Ar(d, e.dirChain).map((e) => {
|
|
2499
|
+
let t = [`id: ${JSON.stringify(e.dir || "/")}`], n = JSON.stringify(e.dir);
|
|
2500
|
+
return e.hasLayout && t.push(`Layout: refs.layouts[${n}]`), e.hasLayoutLoader && t.push(`loader: refs.layoutLoaders[${n}]`), e.hasError && t.push(`Error: refs.errors[${n}]`), e.hasPending && t.push(`Pending: refs.pendings[${n}]`), ` { ${t.join(", ")} }`;
|
|
2501
|
+
}).join(",\n");
|
|
2502
|
+
return ` makePageRoute(${JSON.stringify(e.pattern)}, ${t.length > 0 ? `[\n${t},\n ]` : "undefined"}),`;
|
|
2503
|
+
}), i = d.filter((e) => e.hasNotFound).map((e) => {
|
|
2504
|
+
let t = jr(e.chain), n = Ar(d, e.chain).map((e) => {
|
|
2505
|
+
let t = [`id: ${JSON.stringify(e.dir || "/")}`], n = JSON.stringify(e.dir);
|
|
2506
|
+
return e.hasLayout && t.push(`Layout: refs.layouts[${n}]`), e.hasError && t.push(`Error: refs.errors[${n}]`), ` { ${t.join(", ")} }`;
|
|
2507
|
+
}).join(",\n"), r = n.length > 0 ? `\n chain: [\n${n},\n ],` : "";
|
|
2508
|
+
return ` {\n prefix: ${JSON.stringify(t)},\n Component: refs.notFounds[${JSON.stringify(e.dir)}],${r}\n },`;
|
|
2509
|
+
}), a = [], o = [], c = [], l = [], f = [], p = [];
|
|
2510
|
+
for (let e of d) {
|
|
2511
|
+
let t = e.dir === "" ? "../src/pages/layout.tsx" : `../src/pages/${e.dir}/layout.tsx`, n = e.dir === "" ? "../src/pages/error.tsx" : `../src/pages/${e.dir}/error.tsx`, r = e.dir === "" ? "../src/pages/loading.tsx" : `../src/pages/${e.dir}/loading.tsx`, i = e.dir === "" ? "../src/pages/not-found.tsx" : `../src/pages/${e.dir}/not-found.tsx`, s = JSON.stringify(e.dir);
|
|
2512
|
+
e.hasLayout && e.hasLayoutLoader ? (o.push(` ${s}: ${Q(e.dir, "Layout")}Mod.default,`), c.push(` ${s}: ${Q(e.dir, "Layout")}Mod.loader,`), a.push({
|
|
2513
|
+
relPath: t,
|
|
2514
|
+
kind: "layout",
|
|
2515
|
+
slotKey: e.dir
|
|
2516
|
+
})) : e.hasLayout && (o.push(` ${s}: ${Q(e.dir, "Layout")},`), a.push({
|
|
2517
|
+
relPath: t,
|
|
2518
|
+
kind: "layout",
|
|
2519
|
+
slotKey: e.dir
|
|
2520
|
+
})), e.hasError && (l.push(` ${s}: ${Q(e.dir, "Error")},`), a.push({
|
|
2521
|
+
relPath: n,
|
|
2522
|
+
kind: "error",
|
|
2523
|
+
slotKey: e.dir
|
|
2524
|
+
})), e.hasPending && (f.push(` ${s}: ${Q(e.dir, "Pending")},`), a.push({
|
|
2525
|
+
relPath: r,
|
|
2526
|
+
kind: "pending",
|
|
2527
|
+
slotKey: e.dir
|
|
2528
|
+
})), e.hasNotFound && (p.push(` ${s}: ${Q(e.dir, "NotFound")},`), a.push({
|
|
2529
|
+
relPath: i,
|
|
2530
|
+
kind: "notFound",
|
|
2531
|
+
slotKey: e.dir
|
|
2532
|
+
}));
|
|
2533
|
+
}
|
|
2534
|
+
for (let e of u) a.push({
|
|
2535
|
+
relPath: `../src/pages/${e.file}`,
|
|
2536
|
+
kind: "page",
|
|
2537
|
+
slotKey: e.pattern
|
|
2538
|
+
});
|
|
2539
|
+
let v = a.map((e) => ` ${JSON.stringify(e.relPath)},`), y = a.map((e, t) => {
|
|
2540
|
+
let n = JSON.stringify(e.slotKey);
|
|
2541
|
+
return e.kind === "page" ? ` if (newMods[${t}] && refs.pages[${n}] !== undefined) { refs.pages[${n}] = newMods[${t}]; changed = true }` : ` if (newMods[${t}]?.default) { refs.${e.kind === "layout" ? "layouts" : e.kind === "error" ? "errors" : e.kind === "pending" ? "pendings" : "notFounds"}[${n}] = newMods[${t}].default;${e.kind === "layout" ? ` refs.layoutLoaders[${n}] = newMods[${t}].loader;` : ""} changed = true }`;
|
|
2542
|
+
}), b = t.locales ?? [], x = b.length > 0, S = t.defaultLocale ?? b[0] ?? "en";
|
|
2543
|
+
if (x && !b.includes(S)) throw Error(`[voltro dev] app.config.ts: defaultLocale '${S}' must be one of locales [${b.join(", ")}]`);
|
|
2544
|
+
g = [
|
|
2545
|
+
"// GENERATED BY `voltro dev` — do not edit; will be overwritten on next boot.",
|
|
2546
|
+
"// Routes + per-page chain + not-found scopes assembled from src/pages/.",
|
|
2547
|
+
"// Exported as a single React component so vite-plugin-react treats this file",
|
|
2548
|
+
"// as a clean HMR boundary.",
|
|
2549
|
+
"//",
|
|
2550
|
+
"// HMR architecture (option C — server-pushed re-render with living React tree):",
|
|
2551
|
+
"// Page + layout module references live in the `refs` registry below. The",
|
|
2552
|
+
"// generated route array reads from `refs` on every `buildRoutes()` call",
|
|
2553
|
+
"// — never from the static imports directly. On HMR Vite delivers the new",
|
|
2554
|
+
"// module to the multi-dep `accept` callback below, which patches the",
|
|
2555
|
+
"// matching slot in `refs` and bumps the version counter. The `App`'s",
|
|
2556
|
+
"// `useSyncExternalStore` subscription picks up the bump → `useMemo`",
|
|
2557
|
+
"// rebuilds the routes array → Router rebuilds its compiled match → React",
|
|
2558
|
+
"// renders with the new module without unmounting the surrounding tree.",
|
|
2559
|
+
"",
|
|
2560
|
+
"import { useMemo, useSyncExternalStore } from 'react'",
|
|
2561
|
+
"import { Router, pageRoute, lazyPageRoute, preloadRouteModule, type PageDescriptor, type NotFoundDescriptor } from '@voltro/web'",
|
|
2562
|
+
...x ? [
|
|
2563
|
+
"import { I18nProvider } from '@voltro/i18n'",
|
|
2564
|
+
"import { resolveLocale } from '@voltro/i18n/server'",
|
|
2565
|
+
"import { useServerRequest } from '@voltro/web'",
|
|
2566
|
+
...b.map((e) => `import i18nCatalog_${e} from '../src/locales/${e}'`)
|
|
2567
|
+
] : [],
|
|
2568
|
+
...n,
|
|
2569
|
+
"",
|
|
2570
|
+
"// Mutable module registry. Initial values come from the static",
|
|
2571
|
+
"// imports above; HMR patches the slot, never the import.",
|
|
2572
|
+
"const refs: {",
|
|
2573
|
+
" layouts: Record<string, unknown>",
|
|
2574
|
+
" layoutLoaders: Record<string, unknown>",
|
|
2575
|
+
" errors: Record<string, unknown>",
|
|
2576
|
+
" pendings: Record<string, unknown>",
|
|
2577
|
+
" notFounds: Record<string, unknown>",
|
|
2578
|
+
" pages: Record<string, unknown>",
|
|
2579
|
+
"} = {",
|
|
2580
|
+
" layouts: {",
|
|
2581
|
+
...o,
|
|
2582
|
+
" },",
|
|
2583
|
+
" layoutLoaders: {",
|
|
2584
|
+
...c,
|
|
2585
|
+
" },",
|
|
2586
|
+
" errors: {",
|
|
2587
|
+
...l,
|
|
2588
|
+
" },",
|
|
2589
|
+
" pendings: {",
|
|
2590
|
+
...f,
|
|
2591
|
+
" },",
|
|
2592
|
+
" notFounds: {",
|
|
2593
|
+
...p,
|
|
2594
|
+
" },",
|
|
2595
|
+
" pages: {},",
|
|
2596
|
+
"}",
|
|
2597
|
+
"",
|
|
2598
|
+
"// Per-pattern dynamic-import thunks. Each is a literal `import()` so vite",
|
|
2599
|
+
"// code-splits the page into its own chunk and only fetches it on match.",
|
|
2600
|
+
"const pageLoaders: Record<string, () => Promise<Record<string, unknown>>> = {",
|
|
2601
|
+
...e,
|
|
2602
|
+
"}",
|
|
2603
|
+
"",
|
|
2604
|
+
"let version = 0",
|
|
2605
|
+
"const listeners = new Set<() => void>()",
|
|
2606
|
+
"const subscribe = (cb: () => void): (() => void) => {",
|
|
2607
|
+
" listeners.add(cb)",
|
|
2608
|
+
" return () => { listeners.delete(cb) }",
|
|
2609
|
+
"}",
|
|
2610
|
+
"const getVersion = (): number => version",
|
|
2611
|
+
"const bump = (): void => {",
|
|
2612
|
+
" version++",
|
|
2613
|
+
" for (const cb of listeners) cb()",
|
|
2614
|
+
"}",
|
|
2615
|
+
"",
|
|
2616
|
+
"// Returns an EAGER route once the page module is in `refs.pages` (already",
|
|
2617
|
+
"// loaded, or just HMR-patched), otherwise a LAZY route whose load thunk",
|
|
2618
|
+
"// fetches the chunk, stores it in `refs.pages`, and bumps the version so",
|
|
2619
|
+
"// the next buildRoutes() upgrades it to eager. `buildRoutes` re-runs on",
|
|
2620
|
+
"// every bump, so layout HMR (the rebuilt `chain`) stays live too.",
|
|
2621
|
+
"const makePageRoute = (",
|
|
2622
|
+
" pattern: string,",
|
|
2623
|
+
" chain?: PageDescriptor['chain'],",
|
|
2624
|
+
"): PageDescriptor =>",
|
|
2625
|
+
" refs.pages[pattern] !== undefined",
|
|
2626
|
+
" ? pageRoute(pattern, refs.pages[pattern] as Record<string, unknown>, { chain })",
|
|
2627
|
+
" : lazyPageRoute(pattern, async () => {",
|
|
2628
|
+
" const mod = await pageLoaders[pattern]()",
|
|
2629
|
+
" refs.pages[pattern] = mod",
|
|
2630
|
+
" bump()",
|
|
2631
|
+
" return mod",
|
|
2632
|
+
" }, { chain })",
|
|
2633
|
+
"",
|
|
2634
|
+
"const buildRoutes = (): PageDescriptor[] => [",
|
|
2635
|
+
...r,
|
|
2636
|
+
"]",
|
|
2637
|
+
"",
|
|
2638
|
+
"// Preload the CURRENT url's page chunk before hydration. main.tsx awaits",
|
|
2639
|
+
"// this pre-mount so the lazy page module is in `refs.pages` (→ an EAGER",
|
|
2640
|
+
"// route) for the first client render — matching the SSG/SSR-prerendered",
|
|
2641
|
+
"// HTML instead of a null leaf that would trip a hydration mismatch.",
|
|
2642
|
+
"export const preloadCurrentRoute = async (): Promise<void> => {",
|
|
2643
|
+
" if (typeof window === 'undefined') return",
|
|
2644
|
+
" await preloadRouteModule(buildRoutes(), window.location.pathname)",
|
|
2645
|
+
"}",
|
|
2646
|
+
"",
|
|
2647
|
+
"const buildNotFounds = (): NotFoundDescriptor[] => [",
|
|
2648
|
+
...i,
|
|
2649
|
+
"]",
|
|
2650
|
+
"",
|
|
2651
|
+
...x ? [
|
|
2652
|
+
`// i18n auto-wiring (config.locales = [${b.map((e) => JSON.stringify(e)).join(", ")}]).`,
|
|
2653
|
+
"const I18N_CATALOGS: Record<string, import('@voltro/i18n').MessageCatalog> = {",
|
|
2654
|
+
...b.map((e) => ` ${JSON.stringify(e)}: i18nCatalog_${e},`),
|
|
2655
|
+
"}",
|
|
2656
|
+
`const I18N_SUPPORTED: ReadonlyArray<string> = [${b.map((e) => JSON.stringify(e)).join(", ")}]`,
|
|
2657
|
+
`const I18N_DEFAULT = ${JSON.stringify(S)}`,
|
|
2658
|
+
"",
|
|
2659
|
+
"const pickI18nLocale = (ssr: ReturnType<typeof useServerRequest>): string => {",
|
|
2660
|
+
" if (ssr) {",
|
|
2661
|
+
" return resolveLocale({",
|
|
2662
|
+
" cookieHeader: ssr.headers['cookie'] ?? null,",
|
|
2663
|
+
" acceptLanguageHeader: ssr.headers['accept-language'] ?? null,",
|
|
2664
|
+
" supported: I18N_SUPPORTED,",
|
|
2665
|
+
" defaultLocale: I18N_DEFAULT,",
|
|
2666
|
+
" })",
|
|
2667
|
+
" }",
|
|
2668
|
+
" // Client-side: cookie only. Accept-Language sniffing is",
|
|
2669
|
+
" // server-exclusive — navigator.languages can diverge from",
|
|
2670
|
+
" // what the server saw and would produce a hydration",
|
|
2671
|
+
" // mismatch on first paint.",
|
|
2672
|
+
" if (typeof document === 'undefined') return I18N_DEFAULT",
|
|
2673
|
+
" return resolveLocale({",
|
|
2674
|
+
" cookieHeader: document.cookie,",
|
|
2675
|
+
" acceptLanguageHeader: null,",
|
|
2676
|
+
" supported: I18N_SUPPORTED,",
|
|
2677
|
+
" defaultLocale: I18N_DEFAULT,",
|
|
2678
|
+
" })",
|
|
2679
|
+
"}",
|
|
2680
|
+
""
|
|
2681
|
+
] : [],
|
|
2682
|
+
"export const App = (): React.ReactNode => {",
|
|
2683
|
+
" // `useSyncExternalStore` keeps the React tree alive across HMR-driven",
|
|
2684
|
+
" // module swaps. When version bumps, the snapshot changes, the component",
|
|
2685
|
+
" // re-renders, `buildRoutes()` reads the freshest refs slot, and React",
|
|
2686
|
+
" // sees a new Component identity → renders the patched module's output",
|
|
2687
|
+
" // without unmounting the Router or any ancestors.",
|
|
2688
|
+
" const v = useSyncExternalStore(subscribe, getVersion, getVersion)",
|
|
2689
|
+
" const routes = useMemo(() => buildRoutes(), [v])",
|
|
2690
|
+
" const notFounds = useMemo(() => buildNotFounds(), [v])",
|
|
2691
|
+
...x ? [
|
|
2692
|
+
" const ssr = useServerRequest()",
|
|
2693
|
+
" const locale = pickI18nLocale(ssr)",
|
|
2694
|
+
" const messages = I18N_CATALOGS[locale] ?? I18N_CATALOGS[I18N_DEFAULT]!",
|
|
2695
|
+
" return (",
|
|
2696
|
+
" <I18nProvider locale={locale} messages={messages} defaultLocale={I18N_DEFAULT}>",
|
|
2697
|
+
" <Router routes={routes} notFounds={notFounds} />",
|
|
2698
|
+
" </I18nProvider>",
|
|
2699
|
+
" )"
|
|
2700
|
+
] : [" return <Router routes={routes} notFounds={notFounds} />"],
|
|
2701
|
+
"}",
|
|
2702
|
+
"",
|
|
2703
|
+
"if (import.meta.hot) {",
|
|
2704
|
+
" import.meta.hot.accept(",
|
|
2705
|
+
" [",
|
|
2706
|
+
...v,
|
|
2707
|
+
" ],",
|
|
2708
|
+
" (newMods: Array<Record<string, unknown> | undefined>) => {",
|
|
2709
|
+
" let changed = false",
|
|
2710
|
+
...y,
|
|
2711
|
+
" if (changed) bump()",
|
|
2712
|
+
" },",
|
|
2713
|
+
" )",
|
|
2714
|
+
"}",
|
|
2715
|
+
""
|
|
2716
|
+
].join("\n"), _ = [
|
|
2717
|
+
"// GENERATED BY `voltro dev` — do not edit; will be overwritten on next boot.",
|
|
2718
|
+
"// Entry: imports the generated App component and calls mount() with the",
|
|
2719
|
+
"// resolved apis map. Side-effect only — no local component definitions —",
|
|
2720
|
+
"// so downstream invalidations (user page edits) terminate at app.tsx.",
|
|
2721
|
+
"",
|
|
2722
|
+
...br(t),
|
|
2723
|
+
"import { mount } from '@voltro/web'",
|
|
2724
|
+
...m,
|
|
2725
|
+
"import { App, preloadCurrentRoute } from './app'",
|
|
2726
|
+
...vr(t),
|
|
2727
|
+
...gr(t, s),
|
|
2728
|
+
...yr(t),
|
|
2729
|
+
"",
|
|
2730
|
+
"// Preload the current route's page chunk BEFORE hydration so the first",
|
|
2731
|
+
"// client render matches the SSG/SSR-prerendered HTML. Without it, a lazy",
|
|
2732
|
+
"// page resolves to a null leaf on the first render (its chunk hasn't",
|
|
2733
|
+
"// loaded), diverging from the server's full <main> → React #418. Only",
|
|
2734
|
+
"// when hydrating pre-rendered markup (a fresh SPA mount has nothing to",
|
|
2735
|
+
"// match); the load-error path is swallowed inside preloadRouteModule.",
|
|
2736
|
+
"const __voltroRoot = document.getElementById('root')",
|
|
2737
|
+
"if (document.getElementById('__voltro_state__') && __voltroRoot && __voltroRoot.children.length > 0) {",
|
|
2738
|
+
" await preloadCurrentRoute()",
|
|
2739
|
+
"}",
|
|
2740
|
+
"",
|
|
2741
|
+
"mount(App, {",
|
|
2742
|
+
" apis: {",
|
|
2743
|
+
...h,
|
|
2744
|
+
" },",
|
|
2745
|
+
..._r(t, s),
|
|
2746
|
+
"})",
|
|
2747
|
+
"",
|
|
2748
|
+
Mr
|
|
2749
|
+
].join("\n");
|
|
2750
|
+
} else g = "", _ = [
|
|
2751
|
+
"// GENERATED BY `voltro dev` — do not edit; will be overwritten on next boot.",
|
|
2752
|
+
"// The user's root component lives at ../src/App.tsx; this file imports it",
|
|
2753
|
+
"// and calls mount(). Side-effect only, no component definitions, so the",
|
|
2754
|
+
"// user's component file remains the Fast Refresh boundary.",
|
|
2755
|
+
"",
|
|
2756
|
+
...br(t),
|
|
2757
|
+
"import { mount } from '@voltro/web'",
|
|
2758
|
+
...m,
|
|
2759
|
+
"import App from '../src/App'",
|
|
2760
|
+
...vr(t),
|
|
2761
|
+
...gr(t, s),
|
|
2762
|
+
...yr(t),
|
|
2763
|
+
"",
|
|
2764
|
+
"mount(App, {",
|
|
2765
|
+
" apis: {",
|
|
2766
|
+
...h,
|
|
2767
|
+
" },",
|
|
2768
|
+
..._r(t, s),
|
|
2769
|
+
"})",
|
|
2770
|
+
"",
|
|
2771
|
+
Mr
|
|
2772
|
+
].join("\n");
|
|
2773
|
+
let v = r(e, ".framework");
|
|
2774
|
+
await S.mkdir(v, { recursive: !0 }), t.env ? await Ze(v, i) : await S.rm(r(v, "env.public.ts"), { force: !0 }), await S.writeFile(r(v, "index.html"), l, "utf8"), await S.writeFile(r(v, "main.tsx"), _, "utf8"), g ? await S.writeFile(r(v, "app.tsx"), g, "utf8") : await S.rm(r(v, "app.tsx"), { force: !0 });
|
|
2775
|
+
let b = r(e, ".gitignore"), x = "";
|
|
2776
|
+
try {
|
|
2777
|
+
x = await S.readFile(b, "utf8");
|
|
2778
|
+
} catch {}
|
|
2779
|
+
let C = ["/.framework/"], w = x.split("\n").filter((e) => e.trim() !== "");
|
|
2780
|
+
for (let e of C) w.includes(e) || w.push(e);
|
|
2781
|
+
await S.writeFile(b, w.join("\n") + "\n", "utf8");
|
|
2782
|
+
}, Gr = async (e, n) => {
|
|
2783
|
+
try {
|
|
2784
|
+
let i = r(t(e), "project.json");
|
|
2785
|
+
if (!y(i)) return;
|
|
2786
|
+
let a = await S.readFile(i, "utf8"), o = JSON.parse(a).apps ?? {}, s = e.split("/").filter(Boolean).pop() ?? "", c = [];
|
|
2787
|
+
for (let [e, t] of Object.entries(o)) e !== s && t.port === n && c.push(e);
|
|
2788
|
+
if (c.length === 0) return;
|
|
2789
|
+
Z.warn("sibling app(s) claim the same port — only one boots", {
|
|
2790
|
+
port: n,
|
|
2791
|
+
conflicts: c,
|
|
2792
|
+
projectJson: i
|
|
2793
|
+
});
|
|
2794
|
+
} catch {}
|
|
2795
|
+
}, Kr = (e) => r(e, ".framework", "dist", "server", "appConfig.js"), qr = async (e) => {
|
|
2796
|
+
let t = Kr(e), n = y(t) ? t : r(e, "app.config.ts");
|
|
2797
|
+
try {
|
|
2798
|
+
let e = (await import(s(n).href)).default;
|
|
2799
|
+
return typeof e == "object" && e && "type" in e && e.type === "web" ? e : null;
|
|
2800
|
+
} catch {
|
|
2801
|
+
return null;
|
|
2802
|
+
}
|
|
2803
|
+
}, Jr = async (t) => {
|
|
2804
|
+
let n = await qr(t);
|
|
2805
|
+
if (!n) return {
|
|
2806
|
+
ran: !1,
|
|
2807
|
+
exitCode: 0
|
|
2808
|
+
};
|
|
2809
|
+
En();
|
|
2810
|
+
let o = Wt();
|
|
2811
|
+
en(o), Z.info("booting voltro dev (web)", { app: n.name ?? "(unnamed)" });
|
|
2812
|
+
let s = await Vr(t, n);
|
|
2813
|
+
for (let e of s) Z.info("api wired", {
|
|
2814
|
+
name: e.name,
|
|
2815
|
+
pkg: e.pkg,
|
|
2816
|
+
...e.proxyTarget ? { proxyTo: e.proxyTarget } : { directWs: e.browserWsUrl }
|
|
2817
|
+
});
|
|
2818
|
+
Be(t).then((e) => {
|
|
2819
|
+
for (let t of e.files) if (t.action === "created") {
|
|
2820
|
+
let e = t.path.split("/").pop() ?? t.path;
|
|
2821
|
+
Z.info(`${e} seeded`, { path: t.path });
|
|
2822
|
+
}
|
|
2823
|
+
}).catch(() => {});
|
|
2824
|
+
let { resolved: c } = await Qe({
|
|
2825
|
+
rawEnv: n.env,
|
|
2826
|
+
appType: "web",
|
|
2827
|
+
root: t,
|
|
2828
|
+
log: Z,
|
|
2829
|
+
generateTypes: !0
|
|
2830
|
+
}), l = c.publicValues;
|
|
2831
|
+
await Wr(t, n, s, l), Z.debug("generated framework entry files", { files: [
|
|
2832
|
+
"index.html",
|
|
2833
|
+
".framework/main.tsx",
|
|
2834
|
+
...n.env ? [".framework/env.public.ts"] : []
|
|
2835
|
+
] });
|
|
2836
|
+
let u = process.env.VOLTRO_IS_DASHBOARD === "1" && process.env.VOLTRO_DASHBOARD_PORT ? Number(process.env.VOLTRO_DASHBOARD_PORT) : n.port ?? 5173, d = n.name ?? "unnamed", f = Wn("web", d, u), p = Zn(d);
|
|
2837
|
+
await Hn({
|
|
2838
|
+
id: f,
|
|
2839
|
+
name: d,
|
|
2840
|
+
kind: "web",
|
|
2841
|
+
url: `http://localhost:${u}`,
|
|
2842
|
+
pid: process.pid,
|
|
2843
|
+
status: "booting",
|
|
2844
|
+
logFile: p.path
|
|
2845
|
+
}).catch(() => {}), await Gr(t, u);
|
|
2846
|
+
let { pages: m, dirs: h } = await $(r(t, "src", "pages")), g = h.map((e) => ({
|
|
2847
|
+
dir: e.dir,
|
|
2848
|
+
hasLayout: e.hasLayout,
|
|
2849
|
+
hasError: e.hasError,
|
|
2850
|
+
hasPending: e.hasPending,
|
|
2851
|
+
hasNotFound: e.hasNotFound
|
|
2852
|
+
})), v = await gt({
|
|
2853
|
+
appRoot: t,
|
|
2854
|
+
pages: m
|
|
2855
|
+
});
|
|
2856
|
+
v.wrote && Z.debug("routes codegen wrote", { path: i(t, v.path) });
|
|
2857
|
+
let b = await Ge("vite", () => import("vite")), x = (await import("@vitejs/plugin-react")).default, C = (await import("@tailwindcss/vite")).default, w = r(t, ".framework"), T = r(t, "src"), E = /* @__PURE__ */ new Set([
|
|
2858
|
+
".framework",
|
|
2859
|
+
"node_modules",
|
|
2860
|
+
"dist",
|
|
2861
|
+
".git",
|
|
2862
|
+
".vite",
|
|
2863
|
+
".turbo",
|
|
2864
|
+
".cache"
|
|
2865
|
+
]), ee = {
|
|
2866
|
+
name: "framework:watch-app-sources",
|
|
2867
|
+
async configureServer(e) {
|
|
2868
|
+
try {
|
|
2869
|
+
let n = (await S.readdir(t, { withFileTypes: !0 })).filter((e) => e.isDirectory() && !E.has(e.name));
|
|
2870
|
+
for (let i of n) e.watcher.add(r(t, i.name));
|
|
2871
|
+
n.length === 0 && e.watcher.add(T);
|
|
2872
|
+
} catch {
|
|
2873
|
+
e.watcher.add(T);
|
|
2874
|
+
}
|
|
2875
|
+
try {
|
|
2876
|
+
let n = await S.readFile(r(t, "package.json"), "utf8"), i = JSON.parse(n), a = Object.keys({
|
|
2877
|
+
...i.dependencies,
|
|
2878
|
+
...i.devDependencies
|
|
2879
|
+
});
|
|
2880
|
+
await Promise.all(a.map(async (n) => {
|
|
2881
|
+
let i = await Ir(t, n);
|
|
2882
|
+
if (!i) return;
|
|
2883
|
+
let a = r(i, "src");
|
|
2884
|
+
try {
|
|
2885
|
+
(await S.stat(a)).isDirectory() && e.watcher.add(a);
|
|
2886
|
+
} catch {}
|
|
2887
|
+
}));
|
|
2888
|
+
} catch {}
|
|
2889
|
+
}
|
|
2890
|
+
}, D = r(t, "src", "pages"), te = (e) => e.endsWith(".tsx") && (e === D || e.startsWith(D + "/")), O = (e) => e === D || e.startsWith(D + "/"), ne = async (e) => {
|
|
2891
|
+
try {
|
|
2892
|
+
let r = Date.now();
|
|
2893
|
+
await Wr(t, n, s, l);
|
|
2894
|
+
let { pages: i } = await $(D);
|
|
2895
|
+
await gt({
|
|
2896
|
+
appRoot: t,
|
|
2897
|
+
pages: i
|
|
2898
|
+
}), Z.info("page tree regenerated", {
|
|
2899
|
+
reason: e,
|
|
2900
|
+
ms: Date.now() - r
|
|
2901
|
+
});
|
|
2902
|
+
} catch (t) {
|
|
2903
|
+
Z.error("page tree regen failed", { reason: e }, t);
|
|
2904
|
+
}
|
|
2905
|
+
}, re = {
|
|
2906
|
+
name: "framework:regenerate-on-page-tree-change",
|
|
2907
|
+
configureServer(e) {
|
|
2908
|
+
let n = null, r = [], a = (e) => {
|
|
2909
|
+
r.push(e), n && clearTimeout(n), n = setTimeout(() => {
|
|
2910
|
+
n = null;
|
|
2911
|
+
let e = r.length === 1 ? r[0] : `${r.length} events (${r[0]}, …)`;
|
|
2912
|
+
r.length = 0, ne(e);
|
|
2913
|
+
}, 50);
|
|
2914
|
+
};
|
|
2915
|
+
e.watcher.on("add", (e) => {
|
|
2916
|
+
te(e) && a(`add ${i(t, e)}`);
|
|
2917
|
+
}), e.watcher.on("unlink", (e) => {
|
|
2918
|
+
te(e) && a(`unlink ${i(t, e)}`);
|
|
2919
|
+
}), e.watcher.on("addDir", (e) => {
|
|
2920
|
+
O(e) && a(`addDir ${i(t, e)}`);
|
|
2921
|
+
}), e.watcher.on("unlinkDir", (e) => {
|
|
2922
|
+
O(e) && a(`unlinkDir ${i(t, e)}`);
|
|
2923
|
+
});
|
|
2924
|
+
}
|
|
2925
|
+
}, k = r(t, "app.config.ts"), A = (e) => {
|
|
2926
|
+
if (!se(e.env)) return "";
|
|
2927
|
+
let t = Object.entries(e.env.vars).map(([e, t]) => `${e}:${t.access}`).sort();
|
|
2928
|
+
return `${String(e.env.publicPrefix)}|${t.join(",")}`;
|
|
2929
|
+
}, j = (e, t) => {
|
|
2930
|
+
let n = [];
|
|
2931
|
+
return e.port !== t.port && n.push(`port ${e.port ?? "(default)"} → ${t.port ?? "(default)"}`), JSON.stringify(e.proxies) !== JSON.stringify(t.proxies) && n.push("proxies"), JSON.stringify(e.allowedHosts) !== JSON.stringify(t.allowedHosts) && n.push("allowedHosts"), JSON.stringify(e.apis) !== JSON.stringify(t.apis) && n.push("apis"), A(e) !== A(t) && n.push("env"), n;
|
|
2932
|
+
}, M = n, N = a(k), ie = {
|
|
2933
|
+
name: "framework:watch-app-config",
|
|
2934
|
+
async configureServer(n) {
|
|
2935
|
+
n.watcher.add(k), Z.info("watching app.config.ts for changes", { path: i(t, k) });
|
|
2936
|
+
let r = async () => {
|
|
2937
|
+
try {
|
|
2938
|
+
try {
|
|
2939
|
+
let e = n.moduleGraph.getModuleById(k);
|
|
2940
|
+
e && n.moduleGraph.invalidateModule(e);
|
|
2941
|
+
} catch {}
|
|
2942
|
+
let e = (await n.ssrLoadModule(k, { fixStacktrace: !0 })).default;
|
|
2943
|
+
return typeof e == "object" && e && "type" in e && e.type === "web" ? e : (Z.warn("app.config.ts re-load returned wrong shape", { hasDefault: e !== void 0 }), null);
|
|
2944
|
+
} catch (e) {
|
|
2945
|
+
return Z.warn("app.config.ts re-load failed — ignoring this change", {}, e), null;
|
|
2946
|
+
}
|
|
2947
|
+
}, o = null, s = () => {
|
|
2948
|
+
o && clearTimeout(o), o = setTimeout(() => {
|
|
2949
|
+
o = null, c();
|
|
2950
|
+
}, 100);
|
|
2951
|
+
}, c = async () => {
|
|
2952
|
+
let e = await r();
|
|
2953
|
+
if (!e) {
|
|
2954
|
+
Z.info("app.config.ts onConfigChange: load returned null — skipping");
|
|
2955
|
+
return;
|
|
2956
|
+
}
|
|
2957
|
+
if (Z.info("app.config.ts onConfigChange: loaded", {
|
|
2958
|
+
theme: e.theme,
|
|
2959
|
+
port: e.port,
|
|
2960
|
+
name: e.name
|
|
2961
|
+
}), JSON.stringify(e) === JSON.stringify(M)) {
|
|
2962
|
+
Z.info("app.config.ts onConfigChange: parsed config unchanged — skipping (no-op edit?)");
|
|
2963
|
+
return;
|
|
2964
|
+
}
|
|
2965
|
+
let i = j(M, e);
|
|
2966
|
+
if (i.length > 0) {
|
|
2967
|
+
Z.warn("app.config.ts changed — hard restart required", { fields: i });
|
|
2968
|
+
try {
|
|
2969
|
+
await n.close();
|
|
2970
|
+
} catch {}
|
|
2971
|
+
let e = fe(process.execPath, [...process.execArgv, ...process.argv.slice(1)], {
|
|
2972
|
+
stdio: "inherit",
|
|
2973
|
+
env: process.env,
|
|
2974
|
+
cwd: process.cwd()
|
|
2975
|
+
}), t = (t) => {
|
|
2976
|
+
e.kill(t);
|
|
2977
|
+
}, r = () => t("SIGINT"), a = () => t("SIGTERM");
|
|
2978
|
+
process.on("SIGINT", r), process.on("SIGTERM", a), e.on("exit", (e, t) => {
|
|
2979
|
+
process.off("SIGINT", r), process.off("SIGTERM", a), t ? process.kill(process.pid, t) : process.exit(e ?? 0);
|
|
2980
|
+
}), e.on("error", (e) => {
|
|
2981
|
+
Z.error("restart spawn failed", {}, e), process.exit(1);
|
|
2982
|
+
});
|
|
2983
|
+
return;
|
|
2984
|
+
}
|
|
2985
|
+
try {
|
|
2986
|
+
let r = Date.now();
|
|
2987
|
+
await Wr(t, e, await Vr(t, e)), M = e, n.ws && n.ws.send({
|
|
2988
|
+
type: "full-reload",
|
|
2989
|
+
path: "*"
|
|
2990
|
+
}), Z.info("app.config.ts soft-regen", {
|
|
2991
|
+
ms: Date.now() - r,
|
|
2992
|
+
reload: "full"
|
|
2993
|
+
});
|
|
2994
|
+
} catch (e) {
|
|
2995
|
+
Z.error("app.config.ts soft-regen failed", {}, e);
|
|
2996
|
+
}
|
|
2997
|
+
}, l = (t) => e(t) === "app.config.ts" ? t === k || a(t) === N : !1;
|
|
2998
|
+
n.watcher.on("change", (e) => {
|
|
2999
|
+
l(e) && (Z.info("app.config.ts change event (chokidar)", { file: e }), s());
|
|
3000
|
+
}), n.watcher.on("add", (e) => {
|
|
3001
|
+
l(e) && (Z.info("app.config.ts add event (chokidar)", { file: e }), s());
|
|
3002
|
+
});
|
|
3003
|
+
try {
|
|
3004
|
+
let { watchFile: e } = await import("node:fs");
|
|
3005
|
+
e(k, { interval: 500 }, (e, t) => {
|
|
3006
|
+
e.mtimeMs !== t.mtimeMs && (Z.info("app.config.ts change event (poll)", { mtime: e.mtimeMs }), s());
|
|
3007
|
+
}), Z.info("app.config.ts polling watcher attached", { intervalMs: 500 });
|
|
3008
|
+
} catch (e) {
|
|
3009
|
+
Z.warn("app.config.ts polling watcher could not attach", {}, e);
|
|
3010
|
+
}
|
|
3011
|
+
wn(xn, Z, {
|
|
3012
|
+
root: t,
|
|
3013
|
+
onBeforeRestart: () => n.close()
|
|
3014
|
+
});
|
|
3015
|
+
}
|
|
3016
|
+
}, ae = /\/apps\/[^/]+\/.*\.(route|mutation|workflow|schema)\.tsx?$/, oe = {
|
|
3017
|
+
name: "framework:suppress-api-hmr",
|
|
3018
|
+
handleHotUpdate(e) {
|
|
3019
|
+
if (ae.test(e.file)) return [];
|
|
3020
|
+
}
|
|
3021
|
+
}, ce = {
|
|
3022
|
+
name: "framework:reoptimize-on-rpcgroup-change",
|
|
3023
|
+
async configureServer(e) {
|
|
3024
|
+
let n = /* @__PURE__ */ new Map();
|
|
3025
|
+
for (let i of s) {
|
|
3026
|
+
if (!i.proxyTarget) continue;
|
|
3027
|
+
let a = await Ir(t, i.pkg);
|
|
3028
|
+
if (!a) continue;
|
|
3029
|
+
let o = r(a, "rpcGroup.generated.ts");
|
|
3030
|
+
try {
|
|
3031
|
+
n.set(o, await S.readFile(o, "utf8"));
|
|
3032
|
+
} catch {
|
|
3033
|
+
n.set(o, "");
|
|
3034
|
+
}
|
|
3035
|
+
try {
|
|
3036
|
+
e.watcher.add(o);
|
|
3037
|
+
} catch {}
|
|
3038
|
+
}
|
|
3039
|
+
if (n.size === 0) return;
|
|
3040
|
+
let o = null, c = !1, l = async () => {
|
|
3041
|
+
if (c) return;
|
|
3042
|
+
let a = null;
|
|
3043
|
+
for (let [e, t] of n) {
|
|
3044
|
+
let r;
|
|
3045
|
+
try {
|
|
3046
|
+
r = await S.readFile(e, "utf8");
|
|
3047
|
+
} catch {
|
|
3048
|
+
continue;
|
|
3049
|
+
}
|
|
3050
|
+
r !== t && (n.set(e, r), a = e);
|
|
3051
|
+
}
|
|
3052
|
+
if (a !== null) {
|
|
3053
|
+
c = !0, Z.info(`rpcGroup changed (${i(t, a)}) — re-bundling the api client + reloading (descriptor edits propagate automatically; no manual restart needed)`);
|
|
3054
|
+
try {
|
|
3055
|
+
await S.rm(r(w, ".vite", "deps"), {
|
|
3056
|
+
recursive: !0,
|
|
3057
|
+
force: !0
|
|
3058
|
+
}), await e.restart(!0);
|
|
3059
|
+
} catch (e) {
|
|
3060
|
+
c = !1, Z.error("rpcGroup re-optimize failed", {}, e);
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
}, u = (e) => {
|
|
3064
|
+
n.has(a(e)) && (o && clearTimeout(o), o = setTimeout(() => {
|
|
3065
|
+
l();
|
|
3066
|
+
}, 120));
|
|
3067
|
+
};
|
|
3068
|
+
e.watcher.on("change", u), e.watcher.on("add", u);
|
|
3069
|
+
}
|
|
3070
|
+
}, P = {};
|
|
3071
|
+
for (let e of s) {
|
|
3072
|
+
if (!e.proxyTarget) continue;
|
|
3073
|
+
P[e.browserWsUrl] = {
|
|
3074
|
+
target: e.proxyTarget,
|
|
3075
|
+
ws: !0,
|
|
3076
|
+
changeOrigin: !0,
|
|
3077
|
+
...e.wsPath ? {} : { rewrite: () => "/ws" }
|
|
3078
|
+
};
|
|
3079
|
+
let t = e.proxyTarget.replace(/^ws/, "http");
|
|
3080
|
+
P[`/_voltro/api/${e.name}`] = {
|
|
3081
|
+
target: t,
|
|
3082
|
+
changeOrigin: !0,
|
|
3083
|
+
rewrite: (t) => t.replace(RegExp(`^/_voltro/api/${e.name}`), "")
|
|
3084
|
+
};
|
|
3085
|
+
}
|
|
3086
|
+
for (let [e, t] of Object.entries(n.proxies ?? {})) {
|
|
3087
|
+
if (P[e]) {
|
|
3088
|
+
Z.warn("user proxy ignored — prefix already claimed by an api ws proxy", { prefix: e });
|
|
3089
|
+
continue;
|
|
3090
|
+
}
|
|
3091
|
+
P[e] = {
|
|
3092
|
+
target: t.target,
|
|
3093
|
+
changeOrigin: t.changeOrigin ?? !0,
|
|
3094
|
+
...t.rewrite === void 0 ? {} : { rewrite: (n) => n.replace(RegExp(`^${e}`), t.rewrite) }
|
|
3095
|
+
}, Z.info(`proxy ${e} → ${t.target}`, {
|
|
3096
|
+
prefix: e,
|
|
3097
|
+
target: t.target,
|
|
3098
|
+
...t.rewrite === void 0 ? {} : { rewrite: t.rewrite }
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3101
|
+
let le = {
|
|
3102
|
+
name: "framework:inspect",
|
|
3103
|
+
configureServer(e) {
|
|
3104
|
+
let i = null, a = async () => {
|
|
3105
|
+
if (i !== null) return i;
|
|
3106
|
+
let n = [];
|
|
3107
|
+
for (let i of m) try {
|
|
3108
|
+
let a = await e.ssrLoadModule(r(t, "src", "pages", i.file));
|
|
3109
|
+
n.push({
|
|
3110
|
+
pattern: i.pattern,
|
|
3111
|
+
file: i.file,
|
|
3112
|
+
dirChain: i.dirChain,
|
|
3113
|
+
renderMode: a.renderMode ?? "static",
|
|
3114
|
+
interactive: a.interactive ?? "full",
|
|
3115
|
+
tenantAware: a.tenantAware === !0,
|
|
3116
|
+
revalidateMs: On(a.revalidate),
|
|
3117
|
+
staleWhileRevalidateMs: On(a.staleWhileRevalidate) ?? 0,
|
|
3118
|
+
cacheInvalidatesOn: Array.isArray(a.cacheInvalidatesOn) ? a.cacheInvalidatesOn : [],
|
|
3119
|
+
hasLoader: typeof a.loader == "function",
|
|
3120
|
+
hasMeta: a.meta != null,
|
|
3121
|
+
hasGetStaticPaths: typeof a.getStaticPaths == "function"
|
|
3122
|
+
});
|
|
3123
|
+
} catch (e) {
|
|
3124
|
+
Z.warn("inspect: failed to load page metadata", { pattern: i.pattern }, e);
|
|
3125
|
+
}
|
|
3126
|
+
return i = n, n;
|
|
3127
|
+
};
|
|
3128
|
+
e.middlewares.use((e, t, n) => {
|
|
3129
|
+
let r = e.url ?? "/";
|
|
3130
|
+
if (r.startsWith("/_voltro/inspect") || r.startsWith("/api/dashboard/proxy")) return n();
|
|
3131
|
+
let i = Date.now(), a = t.end.bind(t);
|
|
3132
|
+
t.end = ((...e) => {
|
|
3133
|
+
try {
|
|
3134
|
+
o.emit("request", {
|
|
3135
|
+
url: r.split("?")[0],
|
|
3136
|
+
status: t.statusCode ?? 0,
|
|
3137
|
+
durationMs: Date.now() - i
|
|
3138
|
+
});
|
|
3139
|
+
} catch {}
|
|
3140
|
+
return a(...e);
|
|
3141
|
+
}), n();
|
|
3142
|
+
}), n.name === "voltroDashboard" && e.middlewares.use(async (e, t, n) => {
|
|
3143
|
+
let r = e.url ?? "", i = r.split("?")[0];
|
|
3144
|
+
if (i === "/api/dashboard/proxy") {
|
|
3145
|
+
let n = new URL(r, "http://x").searchParams.get("target");
|
|
3146
|
+
if (!n) {
|
|
3147
|
+
t.statusCode = 400, t.end("missing ?target=");
|
|
3148
|
+
return;
|
|
3149
|
+
}
|
|
3150
|
+
try {
|
|
3151
|
+
let r = { accept: String(e.headers.accept ?? "application/json") };
|
|
3152
|
+
e.headers.authorization && (r.authorization = String(e.headers.authorization));
|
|
3153
|
+
let i;
|
|
3154
|
+
if (e.method && e.method !== "GET" && e.method !== "HEAD") {
|
|
3155
|
+
let t = [];
|
|
3156
|
+
for await (let n of e) t.push(n);
|
|
3157
|
+
i = Buffer.concat(t);
|
|
3158
|
+
let n = e.headers["content-type"];
|
|
3159
|
+
n && (r["content-type"] = Array.isArray(n) ? n[0] : String(n));
|
|
3160
|
+
}
|
|
3161
|
+
let a = await fetch(n, {
|
|
3162
|
+
...e.method ? { method: e.method } : {},
|
|
3163
|
+
headers: r,
|
|
3164
|
+
...i && i.length ? { body: new Uint8Array(i.buffer, i.byteOffset, i.byteLength) } : {}
|
|
3165
|
+
}), o = Buffer.from(await a.arrayBuffer());
|
|
3166
|
+
t.statusCode = a.status, t.setHeader("content-type", a.headers.get("content-type") ?? "application/octet-stream"), t.setHeader("content-length", String(o.length)), t.end(o);
|
|
3167
|
+
} catch (e) {
|
|
3168
|
+
t.statusCode = 502, t.end(`proxy error: ${e.message}`);
|
|
3169
|
+
}
|
|
3170
|
+
return;
|
|
3171
|
+
}
|
|
3172
|
+
if (i === "/api/dashboard/proxy/stream") {
|
|
3173
|
+
let n = new URL(r, "http://x").searchParams.get("target");
|
|
3174
|
+
if (!n) {
|
|
3175
|
+
t.statusCode = 400, t.end("missing ?target=");
|
|
3176
|
+
return;
|
|
3177
|
+
}
|
|
3178
|
+
let i = new AbortController();
|
|
3179
|
+
e.on("close", () => i.abort()), t.on("close", () => i.abort());
|
|
3180
|
+
try {
|
|
3181
|
+
let r = await fetch(n, {
|
|
3182
|
+
method: "GET",
|
|
3183
|
+
headers: {
|
|
3184
|
+
accept: "text/event-stream",
|
|
3185
|
+
...e.headers.authorization ? { authorization: String(e.headers.authorization) } : {}
|
|
3186
|
+
},
|
|
3187
|
+
signal: i.signal
|
|
3188
|
+
});
|
|
3189
|
+
if (!r.ok || !r.body) {
|
|
3190
|
+
t.statusCode = r.status, t.end(`upstream ${r.status}`);
|
|
3191
|
+
return;
|
|
3192
|
+
}
|
|
3193
|
+
t.writeHead(200, {
|
|
3194
|
+
"content-type": "text/event-stream; charset=utf-8",
|
|
3195
|
+
"cache-control": "no-cache, no-transform",
|
|
3196
|
+
connection: "keep-alive",
|
|
3197
|
+
"x-accel-buffering": "no"
|
|
3198
|
+
});
|
|
3199
|
+
let a = r.body.getReader();
|
|
3200
|
+
try {
|
|
3201
|
+
for (;;) {
|
|
3202
|
+
let { done: e, value: n } = await a.read();
|
|
3203
|
+
if (e) break;
|
|
3204
|
+
n && t.write(Buffer.from(n));
|
|
3205
|
+
}
|
|
3206
|
+
} finally {
|
|
3207
|
+
a.releaseLock(), t.end();
|
|
3208
|
+
}
|
|
3209
|
+
} catch (e) {
|
|
3210
|
+
e.name !== "AbortError" && (t.statusCode = 502, t.end(`proxy stream error: ${e.message}`));
|
|
3211
|
+
}
|
|
3212
|
+
return;
|
|
3213
|
+
}
|
|
3214
|
+
n();
|
|
3215
|
+
}), e.middlewares.use(async (e, t, r) => {
|
|
3216
|
+
let i = e.url ?? "";
|
|
3217
|
+
if (!i.startsWith("/_voltro/inspect")) return r();
|
|
3218
|
+
let s = {};
|
|
3219
|
+
for (let [t, n] of Object.entries(e.headers ?? {})) n !== void 0 && (s[String(t).toLowerCase()] = Array.isArray(n) ? n.join(", ") : String(n));
|
|
3220
|
+
let c = i.split("?")[0];
|
|
3221
|
+
if (e.method === "GET" && (c === "/_voltro/inspect/logs" || i.startsWith("/_voltro/inspect/logs?"))) {
|
|
3222
|
+
let e = G(s.origin);
|
|
3223
|
+
if (H()) {
|
|
3224
|
+
t.statusCode = 503, t.setHeader("content-type", "application/json");
|
|
3225
|
+
for (let [n, r] of Object.entries(e)) t.setHeader(n, r);
|
|
3226
|
+
t.end(JSON.stringify({ error: "inspect disabled (VOLTRO_INSPECT=off)" }));
|
|
3227
|
+
return;
|
|
3228
|
+
}
|
|
3229
|
+
let n = mn(i, Qt());
|
|
3230
|
+
t.statusCode = n.status, t.setHeader("content-type", n.contentType);
|
|
3231
|
+
for (let [n, r] of Object.entries(e)) t.setHeader(n, r);
|
|
3232
|
+
t.end(n.body);
|
|
3233
|
+
return;
|
|
3234
|
+
}
|
|
3235
|
+
if (e.method === "POST" && c === "/_voltro/inspect/clientLog") {
|
|
3236
|
+
let n = G(s.origin);
|
|
3237
|
+
if (H()) {
|
|
3238
|
+
t.statusCode = 503, t.setHeader("content-type", "application/json");
|
|
3239
|
+
for (let [e, r] of Object.entries(n)) t.setHeader(e, r);
|
|
3240
|
+
t.end(JSON.stringify({ error: "inspect disabled (VOLTRO_INSPECT=off)" }));
|
|
3241
|
+
return;
|
|
3242
|
+
}
|
|
3243
|
+
let r = "";
|
|
3244
|
+
e.setEncoding("utf-8"), e.on("data", (e) => {
|
|
3245
|
+
r += e;
|
|
3246
|
+
}), e.on("end", () => {
|
|
3247
|
+
let e = cn(r, o);
|
|
3248
|
+
t.statusCode = e.status, t.setHeader("content-type", e.contentType);
|
|
3249
|
+
for (let [e, r] of Object.entries(n)) t.setHeader(e, r);
|
|
3250
|
+
t.end(e.body);
|
|
3251
|
+
}), e.on("error", () => {
|
|
3252
|
+
t.statusCode = 400, t.setHeader("content-type", "application/json"), t.end(JSON.stringify({ error: "read failed" }));
|
|
3253
|
+
});
|
|
3254
|
+
return;
|
|
3255
|
+
}
|
|
3256
|
+
if (c === "/_voltro/inspect/stream") {
|
|
3257
|
+
let n = G(s.origin);
|
|
3258
|
+
if (H()) {
|
|
3259
|
+
t.statusCode = 503, t.setHeader("content-type", "application/json");
|
|
3260
|
+
for (let [e, r] of Object.entries(n)) t.setHeader(e, r);
|
|
3261
|
+
t.end(JSON.stringify({ error: "inspect disabled (VOLTRO_INSPECT=off)" }));
|
|
3262
|
+
return;
|
|
3263
|
+
}
|
|
3264
|
+
let r = U(s);
|
|
3265
|
+
if (!r.ok) {
|
|
3266
|
+
t.statusCode = 401, t.setHeader("content-type", "application/json");
|
|
3267
|
+
for (let [e, r] of Object.entries(n)) t.setHeader(e, r);
|
|
3268
|
+
t.end(JSON.stringify({
|
|
3269
|
+
error: "unauthorized",
|
|
3270
|
+
reason: r.reason
|
|
3271
|
+
}));
|
|
3272
|
+
return;
|
|
3273
|
+
}
|
|
3274
|
+
t.statusCode = 200, t.setHeader("content-type", "text/event-stream; charset=utf-8"), t.setHeader("cache-control", "no-cache, no-transform"), t.setHeader("connection", "keep-alive"), t.setHeader("x-accel-buffering", "no");
|
|
3275
|
+
for (let [e, r] of Object.entries(n)) t.setHeader(e, r);
|
|
3276
|
+
t.flushHeaders?.(), t.write("retry: 5000\n\n");
|
|
3277
|
+
let a = i.indexOf("?");
|
|
3278
|
+
if (!(a !== -1 && new URLSearchParams(i.slice(a + 1)).get("live") === "1")) for (let e of o.buffered()) t.write(Gt(e));
|
|
3279
|
+
let c = o.subscribe((e) => {
|
|
3280
|
+
try {
|
|
3281
|
+
t.write(Gt(e));
|
|
3282
|
+
} catch {}
|
|
3283
|
+
}), l = setInterval(() => {
|
|
3284
|
+
try {
|
|
3285
|
+
t.write(Kt());
|
|
3286
|
+
} catch {}
|
|
3287
|
+
}, 15e3), u = () => {
|
|
3288
|
+
clearInterval(l), c();
|
|
3289
|
+
};
|
|
3290
|
+
e.on("close", u), t.on("close", u);
|
|
3291
|
+
return;
|
|
3292
|
+
}
|
|
3293
|
+
try {
|
|
3294
|
+
let o = Tt(i, {
|
|
3295
|
+
kind: "web",
|
|
3296
|
+
meta: {
|
|
3297
|
+
name: n.name ?? "(unnamed)",
|
|
3298
|
+
voltroVersion: mr,
|
|
3299
|
+
port: u,
|
|
3300
|
+
mode: "dev",
|
|
3301
|
+
apis: Object.entries(n.apis ?? {}).map(([e, t]) => {
|
|
3302
|
+
let n = {
|
|
3303
|
+
name: e,
|
|
3304
|
+
package: t.package
|
|
3305
|
+
};
|
|
3306
|
+
return t.url !== void 0 && (n.url = t.url), n;
|
|
3307
|
+
})
|
|
3308
|
+
},
|
|
3309
|
+
routes: await a(),
|
|
3310
|
+
dirs: g,
|
|
3311
|
+
cache: () => ({
|
|
3312
|
+
backend: "memory",
|
|
3313
|
+
size: 0,
|
|
3314
|
+
entries: []
|
|
3315
|
+
}),
|
|
3316
|
+
env: () => vt(n.name ?? "app", { contract: se(n.env) ? n.env : void 0 })
|
|
3317
|
+
}, s, { method: e.method ?? "GET" });
|
|
3318
|
+
if (o === null) return r();
|
|
3319
|
+
t.statusCode = o.status, t.setHeader("content-type", o.contentType);
|
|
3320
|
+
for (let [e, n] of Object.entries(o.headers ?? {})) t.setHeader(e, n);
|
|
3321
|
+
t.end(o.body);
|
|
3322
|
+
} catch (e) {
|
|
3323
|
+
t.statusCode = 500, t.setHeader("content-type", "text/plain"), t.end(`inspect handler error: ${e.message}`);
|
|
3324
|
+
}
|
|
3325
|
+
});
|
|
3326
|
+
}
|
|
3327
|
+
}, ue = n.name === "voltroDashboard" ? {
|
|
3328
|
+
name: "framework:dashboard-registry",
|
|
3329
|
+
configureServer(e) {
|
|
3330
|
+
e.middlewares.use(async (e, t, n) => {
|
|
3331
|
+
if (!(e.url ?? "").startsWith("/api/dashboard/registry")) return n();
|
|
3332
|
+
try {
|
|
3333
|
+
let e = await Vn();
|
|
3334
|
+
t.statusCode = 200, t.setHeader("content-type", "application/json; charset=utf-8"), t.end(JSON.stringify(e));
|
|
3335
|
+
} catch (e) {
|
|
3336
|
+
t.statusCode = 500, t.setHeader("content-type", "text/plain"), t.end(`registry read error: ${e.message}`);
|
|
3337
|
+
}
|
|
3338
|
+
});
|
|
3339
|
+
}
|
|
3340
|
+
} : null, pe = Pr(m), F = /* @__PURE__ */ new Set(), me = null, he = async () => (me === null && (me = await S.readFile(r(t, ".framework", "index.html"), "utf8")), me), ge = {
|
|
3341
|
+
name: "framework:ssr",
|
|
3342
|
+
configureServer(e) {
|
|
3343
|
+
e.middlewares.use(async (n, i, a) => {
|
|
3344
|
+
if (n.method !== "GET" && n.method !== "HEAD") return a();
|
|
3345
|
+
let o = n.url ?? "/", c = o.indexOf("?"), l = (c === -1 ? o : o.slice(0, c)) || "/";
|
|
3346
|
+
if (l.startsWith("/@") || l.startsWith("/node_modules/") || l.startsWith("/.framework/") || l.startsWith("/_voltro/") || l === "/main.tsx" || l === "/index.html" || l === "/sw.js" || l === "/favicon.ico" || l === "/robots.txt" || /\.[a-z0-9]+$/i.test(l)) return a();
|
|
3347
|
+
let u = Fr(l, pe);
|
|
3348
|
+
if (!u) return a();
|
|
3349
|
+
let d = !F.has(u.route.pattern), f = Date.now();
|
|
3350
|
+
d && Z.info(`ssr compiling ${u.route.pattern}`, {
|
|
3351
|
+
pattern: u.route.pattern,
|
|
3352
|
+
pathname: l
|
|
3353
|
+
});
|
|
3354
|
+
let p = {}, m = async (e, t) => {
|
|
3355
|
+
let n = Date.now(), r = await t();
|
|
3356
|
+
return p[e] = (p[e] ?? 0) + (Date.now() - n), r;
|
|
3357
|
+
}, g = async (t, n, r) => {
|
|
3358
|
+
let i = await e.moduleGraph.getModuleById(t);
|
|
3359
|
+
if (!(!i || n.has(t))) {
|
|
3360
|
+
if (n.add(t), i.id && /\.(css|sass|scss|less|stylus|pcss|postcss)(\?|$)/.test(i.id)) {
|
|
3361
|
+
let e = i.url.replace(/\?.*$/, "");
|
|
3362
|
+
r.includes(e) || r.push(e);
|
|
3363
|
+
return;
|
|
3364
|
+
}
|
|
3365
|
+
for (let e of i.importedModules ?? []) e.id && await g(e.id, n, r);
|
|
3366
|
+
}
|
|
3367
|
+
};
|
|
3368
|
+
try {
|
|
3369
|
+
let c = await m("loadPage", async () => await e.ssrLoadModule(r(t, "src", "pages", u.route.file))), _ = c.renderMode ?? "static";
|
|
3370
|
+
if (_ !== "ssr" && _ !== "isr") return a();
|
|
3371
|
+
let v = Ar(h, u.route.dirChain), y = await m("loadChain", () => Promise.all(v.map(async (n) => {
|
|
3372
|
+
let i = {};
|
|
3373
|
+
return n.hasLayout && (i.Layout = (await e.ssrLoadModule(r(t, "src", "pages", n.dir, "layout.tsx"))).default), n.hasError && (i.Error = (await e.ssrLoadModule(r(t, "src", "pages", n.dir, "error.tsx"))).default), n.hasPending && (i.Pending = (await e.ssrLoadModule(r(t, "src", "pages", n.dir, "loading.tsx"))).default), {
|
|
3374
|
+
id: n.dir || "/",
|
|
3375
|
+
...i
|
|
3376
|
+
};
|
|
3377
|
+
}))), b = {};
|
|
3378
|
+
for (let [e, t] of Object.entries(n.headers ?? {})) typeof t == "string" ? b[e] = t : Array.isArray(t) && (b[e] = t.join(", "));
|
|
3379
|
+
let x = Ur(Hr(s[0]), b.cookie), S = null, C = c.loader;
|
|
3380
|
+
if (typeof C == "function") {
|
|
3381
|
+
let e = new AbortController(), t = () => e.abort();
|
|
3382
|
+
i.once("close", t);
|
|
3383
|
+
try {
|
|
3384
|
+
S = await m("loader", () => C({
|
|
3385
|
+
params: u.params,
|
|
3386
|
+
pathname: l,
|
|
3387
|
+
signal: e.signal,
|
|
3388
|
+
headers: b,
|
|
3389
|
+
query: x
|
|
3390
|
+
}));
|
|
3391
|
+
} finally {
|
|
3392
|
+
i.off("close", t);
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
let w = await m("loadSsrHelpers", async () => await e.ssrLoadModule("@voltro/web/ssr")), T = {
|
|
3396
|
+
pattern: u.route.pattern,
|
|
3397
|
+
Component: c.default,
|
|
3398
|
+
meta: c.meta,
|
|
3399
|
+
loader: c.loader,
|
|
3400
|
+
ErrorBoundary: c.ErrorBoundary,
|
|
3401
|
+
Pending: c.Pending,
|
|
3402
|
+
renderMode: _,
|
|
3403
|
+
chain: y
|
|
3404
|
+
}, E = {
|
|
3405
|
+
cookies: w.parseCookieHeader(b.cookie),
|
|
3406
|
+
headers: b,
|
|
3407
|
+
url: o
|
|
3408
|
+
}, ee = Date.now(), { html: D, meta: te } = w.renderPageToHtml({
|
|
3409
|
+
descriptor: T,
|
|
3410
|
+
params: u.params,
|
|
3411
|
+
pathname: l,
|
|
3412
|
+
loaderData: S,
|
|
3413
|
+
requestContext: E
|
|
3414
|
+
});
|
|
3415
|
+
p.render = Date.now() - ee;
|
|
3416
|
+
let O = c.interactive ?? "full", ne = [];
|
|
3417
|
+
await m("collectCss", async () => {
|
|
3418
|
+
let e = /* @__PURE__ */ new Set(), n = [
|
|
3419
|
+
r(t, "src", "pages", u.route.file),
|
|
3420
|
+
...v.flatMap((e) => [
|
|
3421
|
+
...e.hasLayout ? [r(t, "src", "pages", e.dir, "layout.tsx")] : [],
|
|
3422
|
+
...e.hasError ? [r(t, "src", "pages", e.dir, "error.tsx")] : [],
|
|
3423
|
+
...e.hasPending ? [r(t, "src", "pages", e.dir, "loading.tsx")] : []
|
|
3424
|
+
]),
|
|
3425
|
+
r(t, ".framework", "main.tsx")
|
|
3426
|
+
];
|
|
3427
|
+
for (let t of n) await g(t, e, ne);
|
|
3428
|
+
});
|
|
3429
|
+
let re = await m("readShell", he), k = await m("transformShell", () => e.transformIndexHtml(o, re)), A = [
|
|
3430
|
+
ne.map((e) => `<link rel="stylesheet" href="${e}?direct" />`).join("\n "),
|
|
3431
|
+
w.renderMetaToHtml(te),
|
|
3432
|
+
`<meta name="voltro-interactive" content="${O}" />`,
|
|
3433
|
+
`<script type="application/json" id="__voltro_state__">${w.serialiseStateForInlining(S)}<\/script>`
|
|
3434
|
+
].filter((e) => e.length > 0).join("\n "), j = E.cookies["voltro:locale"], M = k.replace("<div id=\"root\"></div>", `<div id="root">${D}</div>`).replace("</head>", ` ${A}\n </head>`).replace(/<html(\s+lang="[^"]*")?/i, j ? `<html lang="${j}"` : "<html lang=\"en\"");
|
|
3435
|
+
i.statusCode = 200, i.setHeader("content-type", "text/html; charset=utf-8"), i.setHeader("x-voltro-rendered-by", "ssr-dev"), i.end(M);
|
|
3436
|
+
let N = Date.now() - f;
|
|
3437
|
+
d ? (F.add(u.route.pattern), Z.info(`ssr compiled ${u.route.pattern} in ${N}ms`, {
|
|
3438
|
+
pattern: u.route.pattern,
|
|
3439
|
+
pathname: l,
|
|
3440
|
+
elapsedMs: N,
|
|
3441
|
+
cold: !0,
|
|
3442
|
+
phases: p
|
|
3443
|
+
})) : N > 200 && Z.info(`ssr rendered ${l} in ${N}ms`, {
|
|
3444
|
+
pattern: u.route.pattern,
|
|
3445
|
+
pathname: l,
|
|
3446
|
+
elapsedMs: N,
|
|
3447
|
+
cold: !1,
|
|
3448
|
+
phases: p
|
|
3449
|
+
});
|
|
3450
|
+
} catch (e) {
|
|
3451
|
+
Z.warn("ssr-dev render failed; falling back to SPA shell", {
|
|
3452
|
+
pathname: l,
|
|
3453
|
+
pattern: u.route.pattern
|
|
3454
|
+
}, e), a();
|
|
3455
|
+
}
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
}, I = Date.now(), _e = b.version ?? "?", ve = await hr(), ye = r(t, "node_modules", "@voltro", "ui-shadcn"), L = y(r(ye, "package.json")) ? ye : null, be = [], xe = await (async () => {
|
|
3459
|
+
let e = [];
|
|
3460
|
+
for (let n of s) {
|
|
3461
|
+
if (!n.proxyTarget) continue;
|
|
3462
|
+
let i = await Ir(t, n.pkg);
|
|
3463
|
+
if (i) try {
|
|
3464
|
+
e.push(await S.readFile(r(i, "rpcGroup.generated.ts"), "utf8"));
|
|
3465
|
+
} catch {}
|
|
3466
|
+
}
|
|
3467
|
+
if (e.length === 0) return !1;
|
|
3468
|
+
let n = de("sha1").update(e.join("\0")).digest("hex"), i = r(w, ".voltro-rpcgroup-optimize"), a = "";
|
|
3469
|
+
try {
|
|
3470
|
+
a = (await S.readFile(i, "utf8")).trim();
|
|
3471
|
+
} catch {}
|
|
3472
|
+
if (a === n) return !1;
|
|
3473
|
+
try {
|
|
3474
|
+
await S.writeFile(i, n);
|
|
3475
|
+
} catch {}
|
|
3476
|
+
return !0;
|
|
3477
|
+
})();
|
|
3478
|
+
xe && Z.info("rpcGroup changed since last boot — forcing a dep re-optimize so the browser loads the current api client"), await (await b.createServer({
|
|
3479
|
+
root: w,
|
|
3480
|
+
envPrefix: "__VOLTRO_VITE_ENV_DISABLED__",
|
|
3481
|
+
ssr: { noExternal: ["react-intl"] },
|
|
3482
|
+
resolve: {
|
|
3483
|
+
dedupe: ["react", "react-dom"],
|
|
3484
|
+
alias: [
|
|
3485
|
+
...ve ? [{
|
|
3486
|
+
find: "@voltro/devtools/styles.css",
|
|
3487
|
+
replacement: r(ve, "src/styles.css")
|
|
3488
|
+
}, {
|
|
3489
|
+
find: "@voltro/devtools",
|
|
3490
|
+
replacement: r(ve, "src/index.ts")
|
|
3491
|
+
}] : [],
|
|
3492
|
+
...L ? [
|
|
3493
|
+
{
|
|
3494
|
+
find: "@voltro/ui-shadcn/tokens.css",
|
|
3495
|
+
replacement: r(L, "src/tokens.css")
|
|
3496
|
+
},
|
|
3497
|
+
{
|
|
3498
|
+
find: "@voltro/ui-shadcn/cn",
|
|
3499
|
+
replacement: r(L, "src/cn.ts")
|
|
3500
|
+
},
|
|
3501
|
+
{
|
|
3502
|
+
find: "@voltro/ui-shadcn/brand",
|
|
3503
|
+
replacement: r(L, "src/brand/voltroLogo.tsx")
|
|
3504
|
+
},
|
|
3505
|
+
{
|
|
3506
|
+
find: "@voltro/ui-shadcn",
|
|
3507
|
+
replacement: r(L, "src/index.ts")
|
|
3508
|
+
}
|
|
3509
|
+
] : [],
|
|
3510
|
+
...Ue(t)
|
|
3511
|
+
]
|
|
3512
|
+
},
|
|
3513
|
+
optimizeDeps: {
|
|
3514
|
+
include: [...s.map((e) => `${e.pkg}/rpcGroup`), ...be],
|
|
3515
|
+
force: xe
|
|
3516
|
+
},
|
|
3517
|
+
customLogger: ot(),
|
|
3518
|
+
plugins: [
|
|
3519
|
+
x(),
|
|
3520
|
+
C(),
|
|
3521
|
+
ee,
|
|
3522
|
+
re,
|
|
3523
|
+
ie,
|
|
3524
|
+
oe,
|
|
3525
|
+
ce,
|
|
3526
|
+
le,
|
|
3527
|
+
ge,
|
|
3528
|
+
...ue ? [ue] : []
|
|
3529
|
+
],
|
|
3530
|
+
server: {
|
|
3531
|
+
port: u,
|
|
3532
|
+
strictPort: !0,
|
|
3533
|
+
host: !0,
|
|
3534
|
+
allowedHosts: n.allowedHosts === !0 || [...n.allowedHosts ?? []],
|
|
3535
|
+
proxy: P,
|
|
3536
|
+
fs: { allow: [t, ...xr(t)] }
|
|
3537
|
+
},
|
|
3538
|
+
appType: "spa",
|
|
3539
|
+
cacheDir: r(w, ".vite"),
|
|
3540
|
+
publicDir: r(t, "public")
|
|
3541
|
+
})).listen(), pr.info(`v${_e} ready in ${Date.now() - I}ms`, {
|
|
3542
|
+
version: _e,
|
|
3543
|
+
bootMs: Date.now() - I
|
|
3544
|
+
}), Z.info(`listening on http://localhost:${u}`, {
|
|
3545
|
+
port: u,
|
|
3546
|
+
app: n.name ?? "(unnamed)"
|
|
3547
|
+
});
|
|
3548
|
+
for (let e of s) e.proxyTarget && (Z.info(`proxy /ws/${e.name} → ${e.proxyTarget}`, {
|
|
3549
|
+
api: e.name,
|
|
3550
|
+
target: e.proxyTarget
|
|
3551
|
+
}), Z.info(`proxy /_voltro/api/${e.name} → ${e.proxyTarget.replace(/^ws/, "http")}/_voltro/inspect`, { api: e.name }));
|
|
3552
|
+
try {
|
|
3553
|
+
await Hn({
|
|
3554
|
+
id: f,
|
|
3555
|
+
name: d,
|
|
3556
|
+
kind: "web",
|
|
3557
|
+
url: `http://localhost:${u}`,
|
|
3558
|
+
pid: process.pid,
|
|
3559
|
+
status: "live",
|
|
3560
|
+
logFile: p.path
|
|
3561
|
+
});
|
|
3562
|
+
let e = nr(t);
|
|
3563
|
+
if (e) {
|
|
3564
|
+
let t = await fr({ dashboardAppPath: e });
|
|
3565
|
+
t.status === "launched" ? Z.info(`dashboard launched at http://localhost:${t.port}`, { port: t.port }) : t.status === "already-running" && Z.debug(`dashboard already running on :${t.port}`, { port: t.port });
|
|
3566
|
+
}
|
|
3567
|
+
setInterval(() => {
|
|
3568
|
+
Hn({
|
|
3569
|
+
id: f,
|
|
3570
|
+
name: d,
|
|
3571
|
+
kind: "web",
|
|
3572
|
+
url: `http://localhost:${u}`,
|
|
3573
|
+
pid: process.pid,
|
|
3574
|
+
status: "live",
|
|
3575
|
+
logFile: p.path
|
|
3576
|
+
}).catch(() => {});
|
|
3577
|
+
}, 1e4).unref();
|
|
3578
|
+
let n = () => {
|
|
3579
|
+
Un(f), p.dispose();
|
|
3580
|
+
};
|
|
3581
|
+
process.on("SIGINT", n), process.on("SIGTERM", n);
|
|
3582
|
+
} catch (e) {
|
|
3583
|
+
Z.warn("runtime-registry write failed", {}, e);
|
|
3584
|
+
}
|
|
3585
|
+
return _({
|
|
3586
|
+
app: n.name ?? "unnamed",
|
|
3587
|
+
kind: "web",
|
|
3588
|
+
url: `http://localhost:${u}`,
|
|
3589
|
+
bootMs: Date.now() - I
|
|
3590
|
+
}), new Promise(() => {});
|
|
3591
|
+
}, Yr = async (e) => {
|
|
3592
|
+
process.env.NODE_ENV || (process.env.NODE_ENV = "production");
|
|
3593
|
+
let t = await qr(e);
|
|
3594
|
+
if (!t) return {
|
|
3595
|
+
ran: !1,
|
|
3596
|
+
exitCode: 0
|
|
3597
|
+
};
|
|
3598
|
+
let n = Date.now(), i = Z.child("serve");
|
|
3599
|
+
i.info("booting voltro serve (preview)", { app: t.name ?? "(unnamed)" });
|
|
3600
|
+
let a = await Vr(e, t);
|
|
3601
|
+
for (let e of a) i.info("api wired", {
|
|
3602
|
+
name: e.name,
|
|
3603
|
+
pkg: e.pkg
|
|
3604
|
+
});
|
|
3605
|
+
await Wr(e, t, a);
|
|
3606
|
+
{
|
|
3607
|
+
let { pages: t } = await $(r(e, "src", "pages"));
|
|
3608
|
+
await gt({
|
|
3609
|
+
appRoot: e,
|
|
3610
|
+
pages: t
|
|
3611
|
+
});
|
|
3612
|
+
}
|
|
3613
|
+
let o = t.port ?? 5173, s = await Ge("vite", () => import("vite")), c = (await import("@vitejs/plugin-react")).default, l = r(e, ".framework");
|
|
3614
|
+
Z.info("running production build"), await s.build({
|
|
3615
|
+
root: l,
|
|
3616
|
+
envPrefix: "__VOLTRO_VITE_ENV_DISABLED__",
|
|
3617
|
+
plugins: [c()],
|
|
3618
|
+
customLogger: ot(),
|
|
3619
|
+
resolve: { dedupe: ["react", "react-dom"] },
|
|
3620
|
+
build: {
|
|
3621
|
+
outDir: "dist",
|
|
3622
|
+
rollupOptions: { output: { manualChunks: wr } }
|
|
3623
|
+
},
|
|
3624
|
+
publicDir: r(e, "public")
|
|
3625
|
+
});
|
|
3626
|
+
let u = (await s.preview({
|
|
3627
|
+
root: l,
|
|
3628
|
+
envPrefix: "__VOLTRO_VITE_ENV_DISABLED__",
|
|
3629
|
+
preview: { port: o },
|
|
3630
|
+
build: { outDir: "dist" }
|
|
3631
|
+
})).resolvedUrls, d = u?.local[0] ?? `http://localhost:${o}`, f = u?.local.slice(1).map((e) => ({
|
|
3632
|
+
label: "Local",
|
|
3633
|
+
url: e
|
|
3634
|
+
})) ?? [];
|
|
3635
|
+
return _({
|
|
3636
|
+
app: t.name ?? "unnamed",
|
|
3637
|
+
kind: "preview",
|
|
3638
|
+
url: d,
|
|
3639
|
+
extras: f,
|
|
3640
|
+
bootMs: Date.now() - n
|
|
3641
|
+
}), new Promise(() => {});
|
|
3642
|
+
}, Xr = 5e3, Zr = 6e4, Qr = (e, t) => {
|
|
3643
|
+
if (e.length === 0) return 0;
|
|
3644
|
+
if (e.length === 1) return e[0];
|
|
3645
|
+
let n = t * (e.length - 1), r = Math.floor(n), i = Math.ceil(n);
|
|
3646
|
+
if (r === i) return e[r];
|
|
3647
|
+
let a = n - r;
|
|
3648
|
+
return e[r] * (1 - a) + e[i] * a;
|
|
3649
|
+
}, $r = (e) => {
|
|
3650
|
+
if (e.length === 0) return {
|
|
3651
|
+
p50: 0,
|
|
3652
|
+
p95: 0,
|
|
3653
|
+
p99: 0,
|
|
3654
|
+
mean: 0,
|
|
3655
|
+
min: 0,
|
|
3656
|
+
max: 0
|
|
3657
|
+
};
|
|
3658
|
+
let t = e.slice().sort((e, t) => e - t), n = 0;
|
|
3659
|
+
for (let e of t) n += e;
|
|
3660
|
+
return {
|
|
3661
|
+
p50: Qr(t, .5),
|
|
3662
|
+
p95: Qr(t, .95),
|
|
3663
|
+
p99: Qr(t, .99),
|
|
3664
|
+
mean: n / t.length,
|
|
3665
|
+
min: t[0],
|
|
3666
|
+
max: t[t.length - 1]
|
|
3667
|
+
};
|
|
3668
|
+
}, ei = (e = {}) => {
|
|
3669
|
+
let t = e.maxSamples ?? Xr, n = e.defaultWindowMs ?? Zr, r = [];
|
|
3670
|
+
return {
|
|
3671
|
+
record(e) {
|
|
3672
|
+
re(e), r.push({
|
|
3673
|
+
...e,
|
|
3674
|
+
ts: Date.now()
|
|
3675
|
+
}), r.length > t && r.shift();
|
|
3676
|
+
},
|
|
3677
|
+
snapshot(e) {
|
|
3678
|
+
let t = e ?? n, i = Date.now(), a = i - t, o = /* @__PURE__ */ new Map(), s = 0;
|
|
3679
|
+
for (let e of r) {
|
|
3680
|
+
if (e.ts < a) continue;
|
|
3681
|
+
s++;
|
|
3682
|
+
let t = `${e.kind}\u0000${e.tag}`, n = o.get(t);
|
|
3683
|
+
n || (n = {
|
|
3684
|
+
kind: e.kind,
|
|
3685
|
+
tag: e.tag,
|
|
3686
|
+
samples: []
|
|
3687
|
+
}, o.set(t, n)), n.samples.push(e);
|
|
3688
|
+
}
|
|
3689
|
+
let c = [];
|
|
3690
|
+
for (let e of o.values()) {
|
|
3691
|
+
let t = e.samples.map((e) => e.durationMs), n = 0;
|
|
3692
|
+
for (let t of e.samples) t.status === "error" && n++;
|
|
3693
|
+
c.push({
|
|
3694
|
+
kind: e.kind,
|
|
3695
|
+
tag: e.tag,
|
|
3696
|
+
count: e.samples.length,
|
|
3697
|
+
errorCount: n,
|
|
3698
|
+
latencyMs: $r(t)
|
|
3699
|
+
});
|
|
3700
|
+
}
|
|
3701
|
+
return c.sort((e, t) => t.count - e.count), {
|
|
3702
|
+
windowMs: t,
|
|
3703
|
+
capturedAt: i,
|
|
3704
|
+
totalSamples: s,
|
|
3705
|
+
buckets: c
|
|
3706
|
+
};
|
|
3707
|
+
}
|
|
3708
|
+
};
|
|
3709
|
+
};
|
|
3710
|
+
//#endregion
|
|
3711
|
+
export { Bt as $, xn as A, V as B, kn as C, On as D, Dn as E, en as F, kt as G, U as H, Qt as I, Et as J, Ht as K, Gt as L, mn as M, un as N, wn as O, cn as P, Dt as Q, Wt as R, Hn as S, jn as T, Pt as U, wt as V, Vt as W, Tt as X, At as Y, Nt as Z, Zn as _, Ue as _t, qr as a, jt as at, Vn as b, ve as bt, Yr as c, H as ct, Wr as d, yt as dt, zt as et, rr as f, gt as ft, Xn as g, Ge as gt, nr as h, Ye as ht, Ar as i, Ft as it, yn as j, Sn as k, wr as l, bt as lt, fr as m, Xe as mt, Hr as n, Rt as nt, Vr as o, Mt as ot, tr as p, Qe as pt, Ot as q, Ur as r, It as rt, Jr as s, G as st, ei as t, Lt as tt, $ as u, vt as ut, Qn as v, Be as vt, An as w, Un as x, ye as xt, Wn as y, Ve as yt, Kt as z };
|