@adep/cli 0.5.0 → 0.5.2
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/README.md +40 -1
- package/dist/index.js +1113 -113
- package/dist/vite.js +321 -16
- package/dist/worker-entry.js +69 -7
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -228,27 +228,51 @@ __export(net_exports, {
|
|
|
228
228
|
requireReachable: () => requireReachable,
|
|
229
229
|
resetProbeCache: () => resetProbeCache
|
|
230
230
|
});
|
|
231
|
-
|
|
231
|
+
function resolveProbeTimeoutMs() {
|
|
232
|
+
const raw = process.env["ADEP_PROBE_TIMEOUT_MS"];
|
|
233
|
+
if (raw === void 0 || raw.trim() === "") return PROBE_TIMEOUT_MS;
|
|
234
|
+
const value = Number(raw.trim());
|
|
235
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
236
|
+
throw new Error(`ADEP_PROBE_TIMEOUT_MS "${raw}" \u975E\u6CD5\uFF1A\u9700\u8981\u6B63\u6574\u6570\u6BEB\u79D2\uFF08\u5982 20000\uFF09`);
|
|
237
|
+
}
|
|
238
|
+
return value;
|
|
239
|
+
}
|
|
240
|
+
function sleep(ms) {
|
|
241
|
+
return new Promise((resolveSleep) => setTimeout(resolveSleep, ms));
|
|
242
|
+
}
|
|
243
|
+
async function probeReachable(url2, timeoutMs) {
|
|
232
244
|
const now = Date.now();
|
|
233
245
|
const cached2 = probeCache.get(url2);
|
|
234
246
|
if (cached2 !== void 0 && now - cached2.timestamp < PROBE_TTL_MS) {
|
|
235
247
|
return cached2.reachable;
|
|
236
248
|
}
|
|
249
|
+
const timeout = timeoutMs ?? resolveProbeTimeoutMs();
|
|
237
250
|
let reachable = false;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
251
|
+
for (let attempt = 1; attempt <= PROBE_RETRY_DELAYS_MS.length + 1; attempt += 1) {
|
|
252
|
+
if (attempt > 1) {
|
|
253
|
+
const delay = PROBE_RETRY_DELAYS_MS[attempt - 2] ?? 1e3;
|
|
254
|
+
process.stderr.write(
|
|
255
|
+
`[probe] ${url2} \u7B2C ${attempt - 1}/${PROBE_RETRY_DELAYS_MS.length} \u6B21\u63A2\u6D4B\u4E0D\u53EF\u8FBE\uFF0C${delay}ms \u540E\u91CD\u8BD5\uFF08\u8D85\u65F6 ${timeout}ms\uFF09
|
|
256
|
+
`
|
|
257
|
+
);
|
|
258
|
+
await sleep(delay);
|
|
259
|
+
}
|
|
241
260
|
try {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
261
|
+
const controller = new AbortController();
|
|
262
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
263
|
+
try {
|
|
264
|
+
await fetch(url2, {
|
|
265
|
+
method: "HEAD",
|
|
266
|
+
signal: controller.signal
|
|
267
|
+
});
|
|
268
|
+
reachable = true;
|
|
269
|
+
} finally {
|
|
270
|
+
clearTimeout(timer);
|
|
271
|
+
}
|
|
272
|
+
} catch {
|
|
273
|
+
reachable = false;
|
|
249
274
|
}
|
|
250
|
-
|
|
251
|
-
reachable = false;
|
|
275
|
+
if (reachable) break;
|
|
252
276
|
}
|
|
253
277
|
probeCache.set(url2, { reachable, timestamp: now });
|
|
254
278
|
return reachable;
|
|
@@ -262,16 +286,20 @@ async function isOffline() {
|
|
|
262
286
|
async function requireReachable(command, url2) {
|
|
263
287
|
const reachable = await probeReachable(url2);
|
|
264
288
|
if (!reachable) {
|
|
265
|
-
throw new NetworkRequiredError(
|
|
289
|
+
throw new NetworkRequiredError(
|
|
290
|
+
command,
|
|
291
|
+
`\u65E0\u6CD5\u8FDE\u63A5 ${url2}\uFF08\u63A2\u6D4B\u4E0D\u53EF\u8FBE\uFF0C\u5DF2\u91CD\u8BD5 ${PROBE_RETRY_DELAYS_MS.length} \u6B21\uFF09\u3002\u82E5\u76EE\u6807\u662F\u672C\u5730 dev / \u5E73\u53F0\u51B7\u7F16\u8BD1\uFF08Nuxt \u9996\u9875\u51B7\u7F16\u8BD1\u53EF\u8FBE 50-190s\uFF09\uFF0C\u5148 GET / \u9884\u70ED\uFF0C\u6216\u8C03\u5927 ADEP_PROBE_TIMEOUT_MS\uFF08\u5F53\u524D ${resolveProbeTimeoutMs()}ms\uFF09`
|
|
292
|
+
);
|
|
266
293
|
}
|
|
267
294
|
}
|
|
268
|
-
var PROBE_TTL_MS, PROBE_TIMEOUT_MS, PUBLIC_PROBE_URL, probeCache;
|
|
295
|
+
var PROBE_TTL_MS, PROBE_TIMEOUT_MS, PROBE_RETRY_DELAYS_MS, PUBLIC_PROBE_URL, probeCache;
|
|
269
296
|
var init_net = __esm({
|
|
270
297
|
"packages/cli/src/offline/net.ts"() {
|
|
271
298
|
"use strict";
|
|
272
299
|
init_errors();
|
|
273
300
|
PROBE_TTL_MS = 3e4;
|
|
274
301
|
PROBE_TIMEOUT_MS = 5e3;
|
|
302
|
+
PROBE_RETRY_DELAYS_MS = [500, 1e3];
|
|
275
303
|
PUBLIC_PROBE_URL = "https://registry.npmjs.org/";
|
|
276
304
|
probeCache = /* @__PURE__ */ new Map();
|
|
277
305
|
}
|
|
@@ -460,14 +488,14 @@ async function loginWithDevice(paths, input2) {
|
|
|
460
488
|
expiresInSeconds: code.expires_in,
|
|
461
489
|
browserOpened
|
|
462
490
|
});
|
|
463
|
-
const
|
|
491
|
+
const sleep2 = input2.sleep ?? ((ms) => new Promise((resolve21) => setTimeout(resolve21, ms)));
|
|
464
492
|
const token = await pollDeviceToken({
|
|
465
493
|
server,
|
|
466
494
|
deviceCode: code.device_code,
|
|
467
495
|
clientId: CLI_DEVICE_CLIENT_ID,
|
|
468
496
|
intervalMs: input2.intervalMs ?? Math.round(code.interval * 1e3),
|
|
469
497
|
timeoutMs: input2.timeoutMs ?? Math.round(code.expires_in * 1e3),
|
|
470
|
-
sleep,
|
|
498
|
+
sleep: sleep2,
|
|
471
499
|
now: input2.now ?? Date.now
|
|
472
500
|
});
|
|
473
501
|
const email3 = await fetchIdentityWithToken(server, token);
|
|
@@ -1120,6 +1148,49 @@ var init_resolve = __esm({
|
|
|
1120
1148
|
}
|
|
1121
1149
|
});
|
|
1122
1150
|
|
|
1151
|
+
// packages/runtime/src/shared/function-timeout.ts
|
|
1152
|
+
function parseDeclaredTimeoutMs(entrySource) {
|
|
1153
|
+
for (const rawLine of entrySource.split(/\r?\n/)) {
|
|
1154
|
+
const line = rawLine.trim();
|
|
1155
|
+
if (line.length === 0 || line.startsWith("//") || line.startsWith("*")) continue;
|
|
1156
|
+
if (!line.startsWith("export const timeoutMs")) continue;
|
|
1157
|
+
const match = TIMEOUT_DECL_RE.exec(line);
|
|
1158
|
+
if (match === null) {
|
|
1159
|
+
return {
|
|
1160
|
+
value: void 0,
|
|
1161
|
+
error: `timeoutMs \u58F0\u660E\u975E\u6CD5\uFF1A"${line}"\u3002\u552F\u4E00\u5408\u6CD5\u5F62\u6001\u662F\u5355\u884C "export const timeoutMs = <\u6B63\u6574\u6570\u6BEB\u79D2>"\uFF08\u65E0\u5F15\u53F7 / \u65E0\u4E0B\u5212\u7EBF\u5206\u9694 / \u65E0\u5355\u4F4D / \u65E0\u5C3E\u968F\u6CE8\u91CA\uFF09\uFF0C\u4F8B\u5982 "export const timeoutMs = 30000"`
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
const value = Number(match[1]);
|
|
1165
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
1166
|
+
return {
|
|
1167
|
+
value: void 0,
|
|
1168
|
+
error: `timeoutMs \u58F0\u660E\u975E\u6CD5\uFF1A"${line}"\uFF08\u987B\u4E3A\u6B63\u6574\u6570\u6BEB\u79D2\uFF09`
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
return { value, error: null };
|
|
1172
|
+
}
|
|
1173
|
+
return { value: void 0, error: null };
|
|
1174
|
+
}
|
|
1175
|
+
function resolveExecutionBudget(params) {
|
|
1176
|
+
const declared = params.declaredMs;
|
|
1177
|
+
const declaredField = declared === void 0 ? {} : { declaredMs: declared };
|
|
1178
|
+
const base = params.inputTimeoutMs ?? declared ?? DEFAULT_TIMEOUT_MS;
|
|
1179
|
+
const ceiling = params.ceilingMs;
|
|
1180
|
+
if (ceiling === void 0 || base <= ceiling) {
|
|
1181
|
+
return { timeoutMs: base, clamped: false, ...declaredField };
|
|
1182
|
+
}
|
|
1183
|
+
return { timeoutMs: ceiling, clamped: true, ...declaredField };
|
|
1184
|
+
}
|
|
1185
|
+
var TIMEOUT_DECL_RE;
|
|
1186
|
+
var init_function_timeout = __esm({
|
|
1187
|
+
"packages/runtime/src/shared/function-timeout.ts"() {
|
|
1188
|
+
"use strict";
|
|
1189
|
+
init_executor_runtime();
|
|
1190
|
+
TIMEOUT_DECL_RE = /^export const timeoutMs = (\d+)$/;
|
|
1191
|
+
}
|
|
1192
|
+
});
|
|
1193
|
+
|
|
1123
1194
|
// packages/runtime/src/functions/runtime/worker-executor.ts
|
|
1124
1195
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
1125
1196
|
import { fileURLToPath as fileURLToPath2, pathToFileURL } from "node:url";
|
|
@@ -1168,19 +1239,39 @@ var init_worker_executor = __esm({
|
|
|
1168
1239
|
init_executor();
|
|
1169
1240
|
init_resolve();
|
|
1170
1241
|
init_domain();
|
|
1242
|
+
init_function_timeout();
|
|
1171
1243
|
WorkerFunctionExecutor = class {
|
|
1172
1244
|
depsConfig;
|
|
1173
1245
|
fetchConfig;
|
|
1246
|
+
parity;
|
|
1247
|
+
timeoutMaxMs;
|
|
1174
1248
|
constructor(options = {}) {
|
|
1175
1249
|
this.depsConfig = options.deps;
|
|
1176
1250
|
this.fetchConfig = options.fetch;
|
|
1251
|
+
this.parity = options.parity === true;
|
|
1252
|
+
this.timeoutMaxMs = options.timeoutMaxMs;
|
|
1177
1253
|
}
|
|
1178
1254
|
async execute(input2) {
|
|
1179
|
-
const timeoutMs = input2.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
1180
|
-
const memoryLimitMb = input2.memoryLimitMb ?? DEFAULT_MEMORY_LIMIT_MB;
|
|
1181
1255
|
const entry = input2.entry ?? resolveDraftEntry(input2.fn.name, input2.files) ?? "index.ts";
|
|
1256
|
+
const declared = parseDeclaredTimeoutMs(input2.files[entry] ?? "");
|
|
1257
|
+
if (declared.error !== null) {
|
|
1258
|
+
throw new ExecutorError(400, "FN_EXEC_TIMEOUT_DECL_INVALID", declared.error);
|
|
1259
|
+
}
|
|
1260
|
+
const budget = resolveExecutionBudget({
|
|
1261
|
+
inputTimeoutMs: input2.timeoutMs,
|
|
1262
|
+
declaredMs: declared.value,
|
|
1263
|
+
ceilingMs: this.timeoutMaxMs
|
|
1264
|
+
});
|
|
1265
|
+
const timeoutMs = budget.timeoutMs;
|
|
1266
|
+
const memoryLimitMb = input2.memoryLimitMb ?? DEFAULT_MEMORY_LIMIT_MB;
|
|
1182
1267
|
const deps = this.depsConfig === void 0 ? void 0 : resolveExecutionDeps(this.depsConfig, input2.project.id, input2.files["package.json"]);
|
|
1268
|
+
const effectiveFetchConfig = this.fetchConfig === void 0 ? void 0 : input2.fetchAllowlist === void 0 ? this.fetchConfig : { ...this.fetchConfig, allowlist: input2.fetchAllowlist };
|
|
1183
1269
|
const logs = [];
|
|
1270
|
+
if (budget.clamped) {
|
|
1271
|
+
logs.push(
|
|
1272
|
+
`[adep] timeoutMs \u58F0\u660E ${budget.declaredMs}ms \u8D85\u8FC7\u6267\u884C\u9884\u7B97\u4E0A\u9650 ${this.timeoutMaxMs}ms\uFF0C\u5DF2\u6309\u4E0A\u9650\u94B3\u5236\uFF08FN_EXEC_TIMEOUT_CLAMPED\uFF09`
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1184
1275
|
return new Promise((resolve21, reject) => {
|
|
1185
1276
|
let worker;
|
|
1186
1277
|
try {
|
|
@@ -1192,7 +1283,8 @@ var init_worker_executor = __esm({
|
|
|
1192
1283
|
capabilities: input2.capabilities ?? [],
|
|
1193
1284
|
...input2.env === void 0 ? {} : { env: input2.env },
|
|
1194
1285
|
...deps === void 0 ? {} : { deps },
|
|
1195
|
-
...this.
|
|
1286
|
+
...this.parity ? { parity: true } : {},
|
|
1287
|
+
...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig }
|
|
1196
1288
|
},
|
|
1197
1289
|
resourceLimits: { maxOldGenerationSizeMb: memoryLimitMb }
|
|
1198
1290
|
});
|
|
@@ -1350,10 +1442,10 @@ function assertSafeStatement(sql) {
|
|
|
1350
1442
|
if (stripped.includes(";")) {
|
|
1351
1443
|
throw unsafeOperation("\u4EC5\u5141\u8BB8\u5355\u6761\u8BED\u53E5\uFF0C\u7981\u6B62\u591A\u8BED\u53E5\u5806\u53E0");
|
|
1352
1444
|
}
|
|
1353
|
-
if (
|
|
1445
|
+
if (/\b(ATTACH|DETACH)\b/.test(stripped.toUpperCase())) {
|
|
1354
1446
|
throw unsafeOperation("\u7981\u6B62\u8DE8\u5E93\u64CD\u4F5C\uFF08ATTACH / DETACH\uFF09");
|
|
1355
1447
|
}
|
|
1356
|
-
if (
|
|
1448
|
+
if (/\bSQLITE_\w+/i.test(stripped)) {
|
|
1357
1449
|
throw unsafeOperation("\u7981\u6B62\u8BBF\u95EE\u7CFB\u7EDF\u8868\uFF08sqlite_*\uFF09");
|
|
1358
1450
|
}
|
|
1359
1451
|
return sqlHead(stripped);
|
|
@@ -2498,10 +2590,10 @@ function assertReadOnly(sql) {
|
|
|
2498
2590
|
if (!head.startsWith("SELECT") && !head.startsWith("WITH")) {
|
|
2499
2591
|
throw new SimDbError("DB_UNSAFE_OP", "cloud.db.query \u4EC5\u5141\u8BB8\u53EA\u8BFB\u67E5\u8BE2\uFF08SELECT / WITH\uFF09");
|
|
2500
2592
|
}
|
|
2501
|
-
if (
|
|
2593
|
+
if (/\b(ATTACH|DETACH)\b/.test(stripped.toUpperCase())) {
|
|
2502
2594
|
throw new SimDbError("DB_UNSAFE_OP", "\u7981\u6B62\u8DE8\u5E93\u64CD\u4F5C\uFF08ATTACH / DETACH\uFF09");
|
|
2503
2595
|
}
|
|
2504
|
-
if (
|
|
2596
|
+
if (/\bSQLITE_\w+/i.test(stripped) && !/SQLITE_MASTER\b/i.test(stripped)) {
|
|
2505
2597
|
throw new SimDbError("DB_UNSAFE_OP", "\u7981\u6B62\u8BBF\u95EE\u7CFB\u7EDF\u8868\uFF08sqlite_*\uFF09");
|
|
2506
2598
|
}
|
|
2507
2599
|
}
|
|
@@ -3604,7 +3696,7 @@ function createSimStorageCapability(options) {
|
|
|
3604
3696
|
baseUrl: options.baseUrl ?? "http://127.0.0.1:8787"
|
|
3605
3697
|
};
|
|
3606
3698
|
const bundle = createStorageCapability(driver, signer, options.projectId ?? "sim-project");
|
|
3607
|
-
return { bundle, driver };
|
|
3699
|
+
return { bundle, driver, signer };
|
|
3608
3700
|
}
|
|
3609
3701
|
var SIM_SIGN_SECRET;
|
|
3610
3702
|
var init_storage = __esm({
|
|
@@ -3831,6 +3923,233 @@ var init_runtime = __esm({
|
|
|
3831
3923
|
}
|
|
3832
3924
|
});
|
|
3833
3925
|
|
|
3926
|
+
// packages/runtime/src/shared/sql-split.ts
|
|
3927
|
+
function splitSqlStatements(source) {
|
|
3928
|
+
const statements = [];
|
|
3929
|
+
let buffer = "";
|
|
3930
|
+
let inQuote = false;
|
|
3931
|
+
const lines = source.split("\n");
|
|
3932
|
+
for (const rawLine of lines) {
|
|
3933
|
+
const trimmed = rawLine.trim();
|
|
3934
|
+
if (!inQuote && (trimmed.length === 0 || trimmed.startsWith("--"))) continue;
|
|
3935
|
+
const scanLine = inQuote ? rawLine : trimmed;
|
|
3936
|
+
for (let i = 0; i < scanLine.length; i++) {
|
|
3937
|
+
const ch = scanLine[i];
|
|
3938
|
+
if (inQuote) {
|
|
3939
|
+
if (ch === "'") {
|
|
3940
|
+
if (scanLine[i + 1] === "'") {
|
|
3941
|
+
buffer += ch + scanLine[i + 1];
|
|
3942
|
+
i++;
|
|
3943
|
+
continue;
|
|
3944
|
+
}
|
|
3945
|
+
inQuote = false;
|
|
3946
|
+
}
|
|
3947
|
+
buffer += ch;
|
|
3948
|
+
continue;
|
|
3949
|
+
}
|
|
3950
|
+
if (ch === "'") {
|
|
3951
|
+
inQuote = true;
|
|
3952
|
+
buffer += ch;
|
|
3953
|
+
continue;
|
|
3954
|
+
}
|
|
3955
|
+
if (ch === "-" && scanLine[i + 1] === "-") break;
|
|
3956
|
+
if (ch === ";") {
|
|
3957
|
+
const statement = buffer.trim();
|
|
3958
|
+
if (statement.length > 0) statements.push(statement);
|
|
3959
|
+
buffer = "";
|
|
3960
|
+
continue;
|
|
3961
|
+
}
|
|
3962
|
+
buffer += ch;
|
|
3963
|
+
}
|
|
3964
|
+
if (inQuote) {
|
|
3965
|
+
buffer += "\n";
|
|
3966
|
+
} else if (buffer.length > 0 && !/\s$/.test(buffer)) {
|
|
3967
|
+
buffer += " ";
|
|
3968
|
+
}
|
|
3969
|
+
}
|
|
3970
|
+
if (inQuote) {
|
|
3971
|
+
throw new Error(`SQL \u811A\u672C\u5F15\u53F7\u672A\u95ED\u5408\uFF1A${buffer.trim().slice(0, 80)}\u2026`);
|
|
3972
|
+
}
|
|
3973
|
+
const tail = buffer.trim();
|
|
3974
|
+
if (tail.length > 0) statements.push(tail);
|
|
3975
|
+
return statements;
|
|
3976
|
+
}
|
|
3977
|
+
var init_sql_split = __esm({
|
|
3978
|
+
"packages/runtime/src/shared/sql-split.ts"() {
|
|
3979
|
+
"use strict";
|
|
3980
|
+
}
|
|
3981
|
+
});
|
|
3982
|
+
|
|
3983
|
+
// packages/runtime/src/shared/schema-diff.ts
|
|
3984
|
+
function quoteIdent(name) {
|
|
3985
|
+
return `"${name.replaceAll('"', '""')}"`;
|
|
3986
|
+
}
|
|
3987
|
+
function unquoteIdent(raw) {
|
|
3988
|
+
const text = raw.trim();
|
|
3989
|
+
if (text.length >= 2) {
|
|
3990
|
+
const first = text[0];
|
|
3991
|
+
const last = text[text.length - 1];
|
|
3992
|
+
if (first === '"' && last === '"' || first === "`" && last === "`") {
|
|
3993
|
+
return text.slice(1, -1).replaceAll(first + first, first);
|
|
3994
|
+
}
|
|
3995
|
+
if (first === "[" && last === "]") return text.slice(1, -1);
|
|
3996
|
+
if (first === "'" && last === "'") return text.slice(1, -1).replaceAll("''", "'");
|
|
3997
|
+
}
|
|
3998
|
+
return text;
|
|
3999
|
+
}
|
|
4000
|
+
function splitTopLevel2(body) {
|
|
4001
|
+
const parts = [];
|
|
4002
|
+
let depth = 0;
|
|
4003
|
+
let quote3 = null;
|
|
4004
|
+
let start = 0;
|
|
4005
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
4006
|
+
const char = body[index];
|
|
4007
|
+
if (quote3 !== null) {
|
|
4008
|
+
if (char === quote3) {
|
|
4009
|
+
if (body[index + 1] === quote3) index += 1;
|
|
4010
|
+
else quote3 = null;
|
|
4011
|
+
}
|
|
4012
|
+
continue;
|
|
4013
|
+
}
|
|
4014
|
+
if (char === '"' || char === "`" || char === "'") {
|
|
4015
|
+
quote3 = char;
|
|
4016
|
+
continue;
|
|
4017
|
+
}
|
|
4018
|
+
if (char === "[") {
|
|
4019
|
+
quote3 = "]";
|
|
4020
|
+
continue;
|
|
4021
|
+
}
|
|
4022
|
+
if (char === "(") depth += 1;
|
|
4023
|
+
else if (char === ")") depth -= 1;
|
|
4024
|
+
else if (char === "," && depth === 0) {
|
|
4025
|
+
parts.push(body.slice(start, index));
|
|
4026
|
+
start = index + 1;
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
parts.push(body.slice(start));
|
|
4030
|
+
return parts.map((part) => part.trim()).filter((part) => part.length > 0);
|
|
4031
|
+
}
|
|
4032
|
+
function findTableBody(statement, openIndex) {
|
|
4033
|
+
let depth = 0;
|
|
4034
|
+
let quote3 = null;
|
|
4035
|
+
for (let index = openIndex; index < statement.length; index += 1) {
|
|
4036
|
+
const char = statement[index];
|
|
4037
|
+
if (quote3 !== null) {
|
|
4038
|
+
if (char === quote3) {
|
|
4039
|
+
if (statement[index + 1] === quote3) index += 1;
|
|
4040
|
+
else quote3 = null;
|
|
4041
|
+
}
|
|
4042
|
+
continue;
|
|
4043
|
+
}
|
|
4044
|
+
if (char === '"' || char === "`" || char === "'") {
|
|
4045
|
+
quote3 = char;
|
|
4046
|
+
continue;
|
|
4047
|
+
}
|
|
4048
|
+
if (char === "[") {
|
|
4049
|
+
quote3 = "]";
|
|
4050
|
+
continue;
|
|
4051
|
+
}
|
|
4052
|
+
if (char === "(") depth += 1;
|
|
4053
|
+
else if (char === ")") {
|
|
4054
|
+
depth -= 1;
|
|
4055
|
+
if (depth === 0) return statement.slice(openIndex + 1, index);
|
|
4056
|
+
}
|
|
4057
|
+
}
|
|
4058
|
+
return null;
|
|
4059
|
+
}
|
|
4060
|
+
function parseColumn(part) {
|
|
4061
|
+
const nameMatch = /^("(?:[^"]|"")*"|`(?:[^`]|``)*`|\[[^\]]*\]|'[^']*'|[A-Za-z_][A-Za-z0-9_$]*)/.exec(
|
|
4062
|
+
part.trim()
|
|
4063
|
+
);
|
|
4064
|
+
if (nameMatch === null) return null;
|
|
4065
|
+
const name = unquoteIdent(nameMatch[1]);
|
|
4066
|
+
const head = nameMatch[1].toUpperCase();
|
|
4067
|
+
if (TABLE_CONSTRAINTS.has(head)) return null;
|
|
4068
|
+
let rest = part.trim().slice(nameMatch[1].length).trim();
|
|
4069
|
+
if (TABLE_CONSTRAINTS.has(name.toUpperCase()) && rest.startsWith("(")) return null;
|
|
4070
|
+
const upperRest = rest.toUpperCase();
|
|
4071
|
+
let typeEnd = rest.length;
|
|
4072
|
+
for (const keyword of COLUMN_CONSTRAINTS) {
|
|
4073
|
+
const match = new RegExp(`\\b${keyword}\\b`).exec(upperRest);
|
|
4074
|
+
if (match !== null && match.index < typeEnd) typeEnd = match.index;
|
|
4075
|
+
}
|
|
4076
|
+
const type = rest.slice(0, typeEnd).trim();
|
|
4077
|
+
rest = rest.slice(typeEnd).trim();
|
|
4078
|
+
const notNull = /\bNOT\s+NULL\b/i.test(rest);
|
|
4079
|
+
const primaryKey = /\bPRIMARY\s+KEY\b/i.test(rest);
|
|
4080
|
+
const defaultMatch = /\bDEFAULT\s+(.+?)(?=\s+(?:NOT|PRIMARY|UNIQUE|CHECK|REFERENCES|COLLATE|GENERATED|AS|AUTOINCREMENT|CONSTRAINT)\b|$)/i.exec(
|
|
4081
|
+
rest
|
|
4082
|
+
);
|
|
4083
|
+
return {
|
|
4084
|
+
name,
|
|
4085
|
+
type,
|
|
4086
|
+
notNull,
|
|
4087
|
+
primaryKey,
|
|
4088
|
+
defaultValue: defaultMatch === null ? null : defaultMatch[1].trim()
|
|
4089
|
+
};
|
|
4090
|
+
}
|
|
4091
|
+
function parseSchemaTables(sql) {
|
|
4092
|
+
const tables = [];
|
|
4093
|
+
const pattern = /CREATE\s+(?:TEMP|TEMPORARY\s+)?TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?("(?:[^"]|"")*"|`(?:[^`]|``)*`|\[[^\]]*\]|'[^']*'|[A-Za-z_][A-Za-z0-9_$.]*)\s*\(/gi;
|
|
4094
|
+
for (const statement of splitSqlStatements(sql)) {
|
|
4095
|
+
const match = pattern.exec(statement);
|
|
4096
|
+
pattern.lastIndex = 0;
|
|
4097
|
+
if (match === null) continue;
|
|
4098
|
+
const openIndex = match.index + match[0].length - 1;
|
|
4099
|
+
const body = findTableBody(statement, openIndex);
|
|
4100
|
+
if (body === null) continue;
|
|
4101
|
+
const rawName = match[1];
|
|
4102
|
+
const name = unquoteIdent(rawName.split(".").pop() ?? rawName);
|
|
4103
|
+
const columns = [];
|
|
4104
|
+
for (const part of splitTopLevel2(body)) {
|
|
4105
|
+
const column = parseColumn(part);
|
|
4106
|
+
if (column !== null) columns.push(column);
|
|
4107
|
+
}
|
|
4108
|
+
tables.push({ name, columns, statement: statement.trim() });
|
|
4109
|
+
}
|
|
4110
|
+
return tables;
|
|
4111
|
+
}
|
|
4112
|
+
function planMissingColumn(table, column) {
|
|
4113
|
+
const base = `ALTER TABLE ${quoteIdent(table)} ADD COLUMN ${quoteIdent(column.name)}`;
|
|
4114
|
+
let blocked = null;
|
|
4115
|
+
if (column.primaryKey) {
|
|
4116
|
+
blocked = `\u5217 ${table}.${column.name} \u662F PRIMARY KEY\uFF1ASQLite / PG \u7684 ADD COLUMN \u4E0D\u80FD\u65B0\u589E\u4E3B\u952E\u5217\uFF0C\u9700\u8981\u91CD\u5EFA\u8868\uFF08\u5BFC\u51FA \u2192 \u5EFA\u65B0\u8868 \u2192 \u8FC1\u6570\u636E\uFF09\u3002`;
|
|
4117
|
+
} else if (column.notNull && column.defaultValue === null) {
|
|
4118
|
+
blocked = `\u5217 ${table}.${column.name} \u4E3A NOT NULL \u4E14\u65E0 DEFAULT\uFF1A\u65E2\u6709\u884C\u65E0\u6CD5\u81EA\u52A8\u586B\u5145\uFF0C\u8BF7\u5148 \`adep db exec --sql "ALTER TABLE ${table} ADD COLUMN ${column.name} <type> DEFAULT <value>"\` \u56DE\u586B\u540E\u518D\u52A0\u7EA6\u675F\u3002`;
|
|
4119
|
+
}
|
|
4120
|
+
const type = column.type.length === 0 ? "" : ` ${column.type}`;
|
|
4121
|
+
const notNull = column.notNull && column.defaultValue !== null ? " NOT NULL" : "";
|
|
4122
|
+
const fallback = column.defaultValue === null ? "" : ` DEFAULT ${column.defaultValue}`;
|
|
4123
|
+
return {
|
|
4124
|
+
table,
|
|
4125
|
+
column,
|
|
4126
|
+
sql: `${base}${type}${notNull}${fallback}`,
|
|
4127
|
+
blocked
|
|
4128
|
+
};
|
|
4129
|
+
}
|
|
4130
|
+
var TABLE_CONSTRAINTS, COLUMN_CONSTRAINTS;
|
|
4131
|
+
var init_schema_diff = __esm({
|
|
4132
|
+
"packages/runtime/src/shared/schema-diff.ts"() {
|
|
4133
|
+
"use strict";
|
|
4134
|
+
init_sql_split();
|
|
4135
|
+
TABLE_CONSTRAINTS = /* @__PURE__ */ new Set(["CONSTRAINT", "PRIMARY", "UNIQUE", "FOREIGN", "CHECK", "KEY", "EXCLUDE"]);
|
|
4136
|
+
COLUMN_CONSTRAINTS = [
|
|
4137
|
+
"NOT",
|
|
4138
|
+
"NULL",
|
|
4139
|
+
"DEFAULT",
|
|
4140
|
+
"PRIMARY",
|
|
4141
|
+
"UNIQUE",
|
|
4142
|
+
"CHECK",
|
|
4143
|
+
"REFERENCES",
|
|
4144
|
+
"COLLATE",
|
|
4145
|
+
"GENERATED",
|
|
4146
|
+
"AS",
|
|
4147
|
+
"AUTOINCREMENT",
|
|
4148
|
+
"CONSTRAINT"
|
|
4149
|
+
];
|
|
4150
|
+
}
|
|
4151
|
+
});
|
|
4152
|
+
|
|
3834
4153
|
// packages/cli/src/client.ts
|
|
3835
4154
|
var client_exports = {};
|
|
3836
4155
|
__export(client_exports, {
|
|
@@ -3945,63 +4264,6 @@ var init_client = __esm({
|
|
|
3945
4264
|
}
|
|
3946
4265
|
});
|
|
3947
4266
|
|
|
3948
|
-
// packages/runtime/src/shared/sql-split.ts
|
|
3949
|
-
function splitSqlStatements(source) {
|
|
3950
|
-
const statements = [];
|
|
3951
|
-
let buffer = "";
|
|
3952
|
-
let inQuote = false;
|
|
3953
|
-
const lines = source.split("\n");
|
|
3954
|
-
for (const rawLine of lines) {
|
|
3955
|
-
const trimmed = rawLine.trim();
|
|
3956
|
-
if (!inQuote && (trimmed.length === 0 || trimmed.startsWith("--"))) continue;
|
|
3957
|
-
const scanLine = inQuote ? rawLine : trimmed;
|
|
3958
|
-
for (let i = 0; i < scanLine.length; i++) {
|
|
3959
|
-
const ch = scanLine[i];
|
|
3960
|
-
if (inQuote) {
|
|
3961
|
-
if (ch === "'") {
|
|
3962
|
-
if (scanLine[i + 1] === "'") {
|
|
3963
|
-
buffer += ch + scanLine[i + 1];
|
|
3964
|
-
i++;
|
|
3965
|
-
continue;
|
|
3966
|
-
}
|
|
3967
|
-
inQuote = false;
|
|
3968
|
-
}
|
|
3969
|
-
buffer += ch;
|
|
3970
|
-
continue;
|
|
3971
|
-
}
|
|
3972
|
-
if (ch === "'") {
|
|
3973
|
-
inQuote = true;
|
|
3974
|
-
buffer += ch;
|
|
3975
|
-
continue;
|
|
3976
|
-
}
|
|
3977
|
-
if (ch === "-" && scanLine[i + 1] === "-") break;
|
|
3978
|
-
if (ch === ";") {
|
|
3979
|
-
const statement = buffer.trim();
|
|
3980
|
-
if (statement.length > 0) statements.push(statement);
|
|
3981
|
-
buffer = "";
|
|
3982
|
-
continue;
|
|
3983
|
-
}
|
|
3984
|
-
buffer += ch;
|
|
3985
|
-
}
|
|
3986
|
-
if (inQuote) {
|
|
3987
|
-
buffer += "\n";
|
|
3988
|
-
} else if (buffer.length > 0 && !/\s$/.test(buffer)) {
|
|
3989
|
-
buffer += " ";
|
|
3990
|
-
}
|
|
3991
|
-
}
|
|
3992
|
-
if (inQuote) {
|
|
3993
|
-
throw new Error(`SQL \u811A\u672C\u5F15\u53F7\u672A\u95ED\u5408\uFF1A${buffer.trim().slice(0, 80)}\u2026`);
|
|
3994
|
-
}
|
|
3995
|
-
const tail = buffer.trim();
|
|
3996
|
-
if (tail.length > 0) statements.push(tail);
|
|
3997
|
-
return statements;
|
|
3998
|
-
}
|
|
3999
|
-
var init_sql_split = __esm({
|
|
4000
|
-
"packages/runtime/src/shared/sql-split.ts"() {
|
|
4001
|
-
"use strict";
|
|
4002
|
-
}
|
|
4003
|
-
});
|
|
4004
|
-
|
|
4005
4267
|
// packages/cli/src/db.ts
|
|
4006
4268
|
var db_exports = {};
|
|
4007
4269
|
__export(db_exports, {
|
|
@@ -4413,6 +4675,51 @@ async function openLocalDbDriver(target, options) {
|
|
|
4413
4675
|
return { mode: "sim", file: null, module: null, driver: null };
|
|
4414
4676
|
}
|
|
4415
4677
|
}
|
|
4678
|
+
async function detectMissingColumns(driver, schemaSource, options) {
|
|
4679
|
+
const { mode, tag, log } = options;
|
|
4680
|
+
if (mode !== "sqlite") {
|
|
4681
|
+
log(
|
|
4682
|
+
`[${tag}] sim \u6A21\u5F0F\u4E0D\u505A\u7F3A\u5217\u68C0\u6D4B\uFF08\u5F15\u64CE\u65E0\u5217\u76EE\u5F55\u67E5\u8BE2\uFF09\uFF1B\u7F3A\u5217\u5B88\u536B\u53EA\u5728 sqlite \u6A21\u5F0F\u751F\u6548\u3002`
|
|
4683
|
+
);
|
|
4684
|
+
return null;
|
|
4685
|
+
}
|
|
4686
|
+
const declared = parseSchemaTables(schemaSource);
|
|
4687
|
+
const missing = [];
|
|
4688
|
+
for (const table of declared) {
|
|
4689
|
+
const rows = await driver.all(`SELECT name FROM pragma_table_info(?)`, [table.name]);
|
|
4690
|
+
if (rows.length === 0) continue;
|
|
4691
|
+
const liveNames = new Set(rows.map((row) => String(row["name"] ?? "")));
|
|
4692
|
+
for (const column of table.columns) {
|
|
4693
|
+
if (!liveNames.has(column.name)) missing.push(planMissingColumn(table.name, column));
|
|
4694
|
+
}
|
|
4695
|
+
}
|
|
4696
|
+
if (missing.length === 0) return { missing: [], fixed: [] };
|
|
4697
|
+
const fixable = missing.filter((plan) => plan.blocked === null);
|
|
4698
|
+
const blocked = missing.filter((plan) => plan.blocked !== null);
|
|
4699
|
+
for (const plan of fixable) {
|
|
4700
|
+
log(
|
|
4701
|
+
`[${tag}] \u8B66\u544A\uFF1A\u5B58\u91CF\u8868 "${plan.table}" \u7F3A\u5C11 schema.sql \u58F0\u660E\u7684\u5217 "${plan.column.name}"\uFF08--schema-fix \u53EF\u81EA\u52A8\u8865\u5217\uFF09`
|
|
4702
|
+
);
|
|
4703
|
+
}
|
|
4704
|
+
for (const plan of blocked) {
|
|
4705
|
+
log(`[${tag}] \u8B66\u544A\uFF1A\u5B58\u91CF\u8868 "${plan.table}" \u7F3A\u5C11\u5217 "${plan.column.name}"\u2014\u2014${plan.blocked}`);
|
|
4706
|
+
}
|
|
4707
|
+
const fixed = [];
|
|
4708
|
+
if (options.fix) {
|
|
4709
|
+
for (const plan of fixable) {
|
|
4710
|
+
await driver.run(plan.sql);
|
|
4711
|
+
fixed.push(`${plan.table}.${plan.column.name}`);
|
|
4712
|
+
log(`[${tag}] \u5DF2\u81EA\u52A8\u8865\u5217\uFF1A${plan.table}.${plan.column.name}\uFF08--schema-fix\uFF09`);
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4715
|
+
const unresolved = options.fix ? blocked.length : missing.length;
|
|
4716
|
+
if (unresolved > 0) {
|
|
4717
|
+
log(
|
|
4718
|
+
`[${tag}] \u8B66\u544A\uFF1Aschema \u7F3A\u5217\u672A\u89E3\u51B3 ${unresolved} \u5904\u3002RENAME / \u5220\u5217 / \u6539\u7C7B\u578B\u7EF4\u6301\u624B\u5DE5\u8FC1\u79FB\u53E3\u5F84\uFF0C\u672C\u5DE5\u5177\u4E0D\u4F1A\u81EA\u52A8\u6267\u884C\u3002`
|
|
4719
|
+
);
|
|
4720
|
+
}
|
|
4721
|
+
return { missing, fixed };
|
|
4722
|
+
}
|
|
4416
4723
|
async function applyLocalSchema(driver, options) {
|
|
4417
4724
|
const { schemaFile, mode, tag, cwd, log } = options;
|
|
4418
4725
|
const schemaPath = resolve5(cwd, schemaFile);
|
|
@@ -4446,11 +4753,20 @@ async function applyLocalSchema(driver, options) {
|
|
|
4446
4753
|
}
|
|
4447
4754
|
const skipNote = skipped > 0 ? `\uFF0C\u8DF3\u8FC7 ${skipped} \u6761` : "";
|
|
4448
4755
|
log(`[${tag}] \u5DF2\u5E94\u7528\u6570\u636E\u5E93\u7ED3\u6784\uFF08--schema ${schemaFile}\uFF09\uFF1A${applied} \u6761\u8BED\u53E5${skipNote}`);
|
|
4756
|
+
const drift = await detectMissingColumns(driver, schemaSource, {
|
|
4757
|
+
cwd,
|
|
4758
|
+
tag,
|
|
4759
|
+
log,
|
|
4760
|
+
mode,
|
|
4761
|
+
fix: options.schemaFix === true
|
|
4762
|
+
});
|
|
4763
|
+
return { applied, skipped, drift };
|
|
4449
4764
|
}
|
|
4450
4765
|
var SERVE_DB_MODES, DEFAULT_SERVE_DB_MODE, DEFAULT_SQLITE_DB_FILE;
|
|
4451
4766
|
var init_db_mode = __esm({
|
|
4452
4767
|
"packages/cli/src/serve/db-mode.ts"() {
|
|
4453
4768
|
"use strict";
|
|
4769
|
+
init_schema_diff();
|
|
4454
4770
|
init_db2();
|
|
4455
4771
|
init_runtime();
|
|
4456
4772
|
init_sqlite_driver();
|
|
@@ -4672,6 +4988,15 @@ function parseEnv(content) {
|
|
|
4672
4988
|
}
|
|
4673
4989
|
return env;
|
|
4674
4990
|
}
|
|
4991
|
+
async function loadSimEnvViews(cwd) {
|
|
4992
|
+
const envRoot = await readFile6(join9(cwd, ".env"), "utf8").catch(() => null);
|
|
4993
|
+
const envLocal = await readFile6(join9(cwd, ".env.local"), "utf8").catch(() => null);
|
|
4994
|
+
return {
|
|
4995
|
+
env: envRoot === null ? null : parseEnv(envRoot),
|
|
4996
|
+
local: envLocal === null ? null : parseEnv(envLocal),
|
|
4997
|
+
merged: { ...envRoot === null ? {} : parseEnv(envRoot), ...envLocal === null ? {} : parseEnv(envLocal) }
|
|
4998
|
+
};
|
|
4999
|
+
}
|
|
4675
5000
|
async function loadSimEnv(cwd, config2 = {}) {
|
|
4676
5001
|
const envRoot = await readFile6(join9(cwd, ".env"), "utf8").catch(() => "");
|
|
4677
5002
|
const envLocal = await readFile6(join9(cwd, ".env.local"), "utf8").catch(() => "");
|
|
@@ -5579,6 +5904,14 @@ function resolveModulePath(fromDir, request, files) {
|
|
|
5579
5904
|
}
|
|
5580
5905
|
return null;
|
|
5581
5906
|
}
|
|
5907
|
+
function escapesFunctionRoot(fromDir, request) {
|
|
5908
|
+
const depth = fromDir.split("/").filter((part) => part.length > 0).length;
|
|
5909
|
+
let ups = 0;
|
|
5910
|
+
for (const part of request.split("/")) {
|
|
5911
|
+
if (part === "..") ups += 1;
|
|
5912
|
+
}
|
|
5913
|
+
return ups > depth;
|
|
5914
|
+
}
|
|
5582
5915
|
function joinPosix(dir, request) {
|
|
5583
5916
|
const parts = [...dir.split("/"), ...request.split("/")];
|
|
5584
5917
|
const stack = [];
|
|
@@ -5607,7 +5940,7 @@ function syntaxErrorWithLocation(error62, path) {
|
|
|
5607
5940
|
if (typeof code === "string") wrapped.code = code;
|
|
5608
5941
|
return wrapped;
|
|
5609
5942
|
}
|
|
5610
|
-
function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache) {
|
|
5943
|
+
function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false) {
|
|
5611
5944
|
const cached2 = cache.get(path);
|
|
5612
5945
|
if (cached2 !== void 0) return cached2;
|
|
5613
5946
|
const source = files[path];
|
|
@@ -5619,9 +5952,16 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache)
|
|
|
5619
5952
|
const dir = path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "";
|
|
5620
5953
|
const module = { exports, default: void 0 };
|
|
5621
5954
|
const require2 = (request) => {
|
|
5955
|
+
if (strictPaths && request.startsWith("../") && escapesFunctionRoot(dir, request)) {
|
|
5956
|
+
const error63 = new Error(
|
|
5957
|
+
`\u6C99\u7BB1\u62D2\u7EDD\u8D8A\u6839\u5F15\u7528\uFF1A"${request}"\uFF08\u51FD\u6570\u76EE\u5F55\u4E4B\u5916\u4E0D\u53EF\u5F15\u7528\uFF1B\u5E73\u53F0\u6C99\u7BB1\u540C\u6B64\u7EA6\u675F\uFF0CFN_SANDBOX_ESCAPE_BLOCKED\uFF09`
|
|
5958
|
+
);
|
|
5959
|
+
error63.code = "FN_SANDBOX_ESCAPE_BLOCKED";
|
|
5960
|
+
throw error63;
|
|
5961
|
+
}
|
|
5622
5962
|
const resolved = resolveModulePath(dir, request, files);
|
|
5623
5963
|
if (resolved !== null) {
|
|
5624
|
-
return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache);
|
|
5964
|
+
return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths);
|
|
5625
5965
|
}
|
|
5626
5966
|
if (resolveBare !== void 0 && !request.startsWith("./") && !request.startsWith("../")) {
|
|
5627
5967
|
const cachedModule = bareCache?.get(request);
|
|
@@ -5660,10 +6000,18 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache)
|
|
|
5660
6000
|
}
|
|
5661
6001
|
return exports;
|
|
5662
6002
|
}
|
|
5663
|
-
function loadFunctionModule(files, entry, sandboxGlobals, resolveBare) {
|
|
6003
|
+
function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false) {
|
|
5664
6004
|
const cache = /* @__PURE__ */ new Map();
|
|
5665
6005
|
const bareCache = /* @__PURE__ */ new Map();
|
|
5666
|
-
const entryExports = loadModule(
|
|
6006
|
+
const entryExports = loadModule(
|
|
6007
|
+
entry,
|
|
6008
|
+
files,
|
|
6009
|
+
sandboxGlobals,
|
|
6010
|
+
cache,
|
|
6011
|
+
resolveBare,
|
|
6012
|
+
bareCache,
|
|
6013
|
+
strictPaths
|
|
6014
|
+
);
|
|
5667
6015
|
const handler = entryExports["default"];
|
|
5668
6016
|
if (typeof handler !== "function") {
|
|
5669
6017
|
throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570`);
|
|
@@ -6444,9 +6792,14 @@ function runWorker(input2, port) {
|
|
|
6444
6792
|
performance,
|
|
6445
6793
|
atob,
|
|
6446
6794
|
btoa,
|
|
6447
|
-
structuredClone
|
|
6448
|
-
|
|
6449
|
-
|
|
6795
|
+
structuredClone,
|
|
6796
|
+
// CORE-154:定时器家族(纯本地定时,无出网/句柄面;清单见 SANDBOX_GLOBAL_KEYS 钉测面)。
|
|
6797
|
+
setTimeout,
|
|
6798
|
+
clearTimeout,
|
|
6799
|
+
setInterval,
|
|
6800
|
+
clearInterval
|
|
6801
|
+
};
|
|
6802
|
+
if (input2.env !== void 0 && input2.parity !== true) {
|
|
6450
6803
|
sandboxGlobals["process"] = realmValue({ env: input2.env });
|
|
6451
6804
|
}
|
|
6452
6805
|
if (input2.fetch !== void 0) {
|
|
@@ -6474,7 +6827,9 @@ function runWorker(input2, port) {
|
|
|
6474
6827
|
input2.files,
|
|
6475
6828
|
input2.entry,
|
|
6476
6829
|
sandboxGlobals,
|
|
6477
|
-
input2.deps === void 0 ? void 0 : createBareResolver(input2.deps)
|
|
6830
|
+
input2.deps === void 0 ? void 0 : createBareResolver(input2.deps),
|
|
6831
|
+
// CORE-154:--parity 严格模式连带 `../` 越根引用报错(与容器形态真实 fs 同形)。
|
|
6832
|
+
input2.parity === true
|
|
6478
6833
|
);
|
|
6479
6834
|
const result = Promise.resolve(handler(ctx));
|
|
6480
6835
|
void result.then(
|
|
@@ -6675,9 +7030,17 @@ var init_multipart = __esm({
|
|
|
6675
7030
|
import { readdir as readdir2, readFile as readFile8 } from "node:fs/promises";
|
|
6676
7031
|
import { join as join12 } from "node:path";
|
|
6677
7032
|
function bearerUserResolverFromEnv(fileEnv = {}) {
|
|
6678
|
-
const raw =
|
|
7033
|
+
const raw = resolveEffectiveIssuer(fileEnv);
|
|
6679
7034
|
return raw === void 0 ? void 0 : createBearerUserResolver(raw);
|
|
6680
7035
|
}
|
|
7036
|
+
function resolveEffectiveIssuer(fileEnv = {}) {
|
|
7037
|
+
return firstNonEmpty(process.env.ADEP_AUTH_ISSUER, fileEnv.ADEP_AUTH_ISSUER);
|
|
7038
|
+
}
|
|
7039
|
+
function issuerSuffixWarning(issuer) {
|
|
7040
|
+
const normalized = issuer.trim().replace(/\/+$/, "");
|
|
7041
|
+
if (normalized.toLowerCase().endsWith(ISSUER_PATH_SUFFIX)) return null;
|
|
7042
|
+
return `ADEP_AUTH_ISSUER=${issuer} \u7F3A ${ISSUER_PATH_SUFFIX} \u540E\u7F00\uFF1A\u5E73\u53F0 issuer \u5F62\u5982 <origin>${ISSUER_PATH_SUFFIX}\uFF0C\u6F0F\u540E\u7F00\u4F1A\u4F7F userinfo / OAuth \u7AEF\u70B9\u843D\u5230\u9519\u8BEF\u8DEF\u5F84\uFF08issuer \u4FA7 404 \u2192 \u8C03\u7528\u5168\u91CF 40001\uFF09\u3002\u5E94\u4E3A ${normalized}${ISSUER_PATH_SUFFIX}`;
|
|
7043
|
+
}
|
|
6681
7044
|
function firstNonEmpty(...values) {
|
|
6682
7045
|
for (const value of values) {
|
|
6683
7046
|
const trimmed = value?.trim();
|
|
@@ -6809,7 +7172,7 @@ async function requestInput(url2, req, readBody) {
|
|
|
6809
7172
|
...parsed?.files === void 0 ? {} : { files: parsed.files }
|
|
6810
7173
|
};
|
|
6811
7174
|
}
|
|
6812
|
-
var BEARER_TOKEN_RE;
|
|
7175
|
+
var BEARER_TOKEN_RE, ISSUER_PATH_SUFFIX;
|
|
6813
7176
|
var init_dev_shared = __esm({
|
|
6814
7177
|
"packages/cli/src/dev-shared.ts"() {
|
|
6815
7178
|
"use strict";
|
|
@@ -6819,6 +7182,7 @@ var init_dev_shared = __esm({
|
|
|
6819
7182
|
init_executor_runtime();
|
|
6820
7183
|
init_invoke();
|
|
6821
7184
|
BEARER_TOKEN_RE = /^Bearer\s+(.+)$/i;
|
|
7185
|
+
ISSUER_PATH_SUFFIX = "/api";
|
|
6822
7186
|
}
|
|
6823
7187
|
});
|
|
6824
7188
|
|
|
@@ -7678,7 +8042,8 @@ function isLoopback(host) {
|
|
|
7678
8042
|
}
|
|
7679
8043
|
function renderBanner(options) {
|
|
7680
8044
|
const { host, port, projectName, functions, hasStatic, staticDir = "public/" } = options;
|
|
7681
|
-
const baseUrl = `http://${host}:${port}`;
|
|
8045
|
+
const baseUrl = options.publicUrl ?? `http://${host}:${port}`;
|
|
8046
|
+
const listenNote = options.publicUrl === void 0 ? "" : `\uFF08\u76D1\u542C ${host}:${port}\uFF09`;
|
|
7682
8047
|
const loopback = isLoopback(host);
|
|
7683
8048
|
const lines = [];
|
|
7684
8049
|
lines.push("");
|
|
@@ -7688,7 +8053,7 @@ function renderBanner(options) {
|
|
|
7688
8053
|
lines.push("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D");
|
|
7689
8054
|
lines.push("");
|
|
7690
8055
|
lines.push(` \u9879\u76EE: ${projectName}`);
|
|
7691
|
-
lines.push(` \u5730\u5740: ${baseUrl}`);
|
|
8056
|
+
lines.push(` \u5730\u5740: ${baseUrl}${listenNote}`);
|
|
7692
8057
|
lines.push(` \u7ED1\u5B9A: ${host}${loopback ? "\uFF08\u4EC5\u672C\u673A\u53EF\u8BBF\u95EE\uFF09" : "\uFF08\u26A0 \u5BF9\u5916\u66B4\u9732\uFF09"}`);
|
|
7693
8058
|
lines.push("");
|
|
7694
8059
|
lines.push(" \u80FD\u529B:");
|
|
@@ -7710,6 +8075,44 @@ function renderBanner(options) {
|
|
|
7710
8075
|
}
|
|
7711
8076
|
lines.push(` - \u5065\u5EB7\u68C0\u67E5: ${baseUrl}/healthz`);
|
|
7712
8077
|
lines.push("");
|
|
8078
|
+
if (options.effectiveConfig !== void 0) {
|
|
8079
|
+
const cfg = options.effectiveConfig;
|
|
8080
|
+
const { env: hasEnv, local: hasLocal } = cfg.envFiles;
|
|
8081
|
+
let envLine;
|
|
8082
|
+
if (hasEnv && hasLocal) envLine = ".env \u2713 + .env.local \u2713\uFF08.env.local \u8986\u76D6 .env\uFF09";
|
|
8083
|
+
else if (hasLocal) envLine = ".env.local \u2713\uFF08.env \u4E0D\u5B58\u5728\uFF09";
|
|
8084
|
+
else if (hasEnv) envLine = ".env \u2713\uFF08.env.local \u4E0D\u5B58\u5728\uFF09";
|
|
8085
|
+
else envLine = "\u65E0\uFF08\u9879\u76EE\u6839\u6CA1\u6709 .env / .env.local\uFF0C\u6C99\u7BB1 env \u4E3A\u7A7A\u8868\uFF09";
|
|
8086
|
+
lines.push(" \u751F\u6548\u914D\u7F6E:");
|
|
8087
|
+
lines.push(` - env \u6765\u6E90: ${envLine}\uFF08\u6C99\u7BB1 env \u53EA\u6765\u81EA\u6587\u4EF6\uFF0C\u4E0D\u542B\u8FDB\u7A0B\u73AF\u5883\u53D8\u91CF\uFF09`);
|
|
8088
|
+
if (cfg.issuer === void 0) {
|
|
8089
|
+
lines.push(" - \u767B\u5F55\u5373\u670D\u52A1: \u672A\u914D\u7F6E\uFF08ADEP_AUTH_ISSUER \u7F3A\u7701\uFF0CBearer \u4E0D\u89E3\u6790\u8EAB\u4EFD\uFF09");
|
|
8090
|
+
} else {
|
|
8091
|
+
lines.push(` - \u767B\u5F55\u5373\u670D\u52A1: ${cfg.issuer}\uFF08ADEP_AUTH_ISSUER\uFF09`);
|
|
8092
|
+
}
|
|
8093
|
+
if (cfg.fetchAllowlist === void 0) {
|
|
8094
|
+
lines.push(" - \u53D7\u63A7 fetch \u767D\u540D\u5355: \u672A\u914D\u7F6E\uFF08\u6C99\u7BB1\u65E0\u7F51\u7EDC\uFF0CFN-002 \u7F3A\u7701\uFF09");
|
|
8095
|
+
} else {
|
|
8096
|
+
const timeout = cfg.fetchTimeoutMs === void 0 ? "" : `\uFF08\u8D85\u65F6 ${cfg.fetchTimeoutMs}ms\uFF09`;
|
|
8097
|
+
lines.push(` - \u53D7\u63A7 fetch \u767D\u540D\u5355: ${cfg.fetchAllowlist.join(", ")}${timeout}`);
|
|
8098
|
+
}
|
|
8099
|
+
lines.push("");
|
|
8100
|
+
const configWarnings = [];
|
|
8101
|
+
if (cfg.issuer !== void 0) {
|
|
8102
|
+
const suffixWarning = issuerSuffixWarning(cfg.issuer);
|
|
8103
|
+
if (suffixWarning !== null) configWarnings.push(suffixWarning);
|
|
8104
|
+
}
|
|
8105
|
+
if (configWarnings.length > 0) {
|
|
8106
|
+
lines.push(" \u26A0 \u751F\u6548\u914D\u7F6E\u8B66\u544A:");
|
|
8107
|
+
for (const warning of configWarnings) lines.push(` - ${warning}`);
|
|
8108
|
+
lines.push("");
|
|
8109
|
+
}
|
|
8110
|
+
}
|
|
8111
|
+
if (options.schemaDrift !== void 0 && options.schemaDrift.length > 0) {
|
|
8112
|
+
lines.push(" \u26A0 schema \u7F3A\u5217\uFF08\u5B58\u91CF\u5E93\u843D\u540E\u4E8E schema.sql\uFF0C\u51FD\u6570\u53EF\u80FD\u62A5 no such column\uFF09:");
|
|
8113
|
+
for (const item of options.schemaDrift) lines.push(` - ${item}`);
|
|
8114
|
+
lines.push("");
|
|
8115
|
+
}
|
|
7713
8116
|
lines.push(" \u8FB9\u754C\uFF08\u5F00\u53D1\u6001\u9ED8\u8BA4\u503C\uFF0C\u4E0D\u53EF\u5728\u6B64\u6A21\u5F0F\u4E0B\u5F00\u542F\uFF09:");
|
|
7714
8117
|
lines.push(" - \u65E0\u9274\u6743\uFF1A\u4EFB\u4F55\u4EBA\u53EF\u8C03\u7528\u6240\u6709\u51FD\u6570");
|
|
7715
8118
|
lines.push(" - \u65E0\u9650\u6D41\uFF1A\u65E0 QPS / \u5E76\u53D1\u9650\u5236");
|
|
@@ -7737,6 +8140,7 @@ function renderBanner(options) {
|
|
|
7737
8140
|
var init_banner = __esm({
|
|
7738
8141
|
"packages/cli/src/serve/banner.ts"() {
|
|
7739
8142
|
"use strict";
|
|
8143
|
+
init_dev_shared();
|
|
7740
8144
|
}
|
|
7741
8145
|
});
|
|
7742
8146
|
|
|
@@ -7993,6 +8397,7 @@ var init_adep_env_inject = __esm({
|
|
|
7993
8397
|
var server_exports = {};
|
|
7994
8398
|
__export(server_exports, {
|
|
7995
8399
|
isLoopback: () => isLoopback,
|
|
8400
|
+
resolvePublicUrl: () => resolvePublicUrl,
|
|
7996
8401
|
resolveServePort: () => resolveServePort,
|
|
7997
8402
|
startServeServer: () => startServeServer
|
|
7998
8403
|
});
|
|
@@ -8013,6 +8418,22 @@ function envString(name) {
|
|
|
8013
8418
|
function resolveServePort(explicitPort) {
|
|
8014
8419
|
return explicitPort ?? envNumber("PORT") ?? 8787;
|
|
8015
8420
|
}
|
|
8421
|
+
function resolvePublicUrl(raw) {
|
|
8422
|
+
if (raw === void 0 || raw.trim() === "") return void 0;
|
|
8423
|
+
const value = raw.trim().replace(/\/+$/, "");
|
|
8424
|
+
let parsed;
|
|
8425
|
+
try {
|
|
8426
|
+
parsed = new URL(value);
|
|
8427
|
+
} catch {
|
|
8428
|
+
throw new Error(
|
|
8429
|
+
`--public-url / ADEP_PUBLIC_URL "${raw}" \u4E0D\u662F\u5408\u6CD5 URL\uFF08\u9700\u5E26\u534F\u8BAE\uFF0C\u5982 https://app.example.com\uFF09`
|
|
8430
|
+
);
|
|
8431
|
+
}
|
|
8432
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
8433
|
+
throw new Error(`--public-url / ADEP_PUBLIC_URL "${raw}" \u53EA\u652F\u6301 http / https \u534F\u8BAE`);
|
|
8434
|
+
}
|
|
8435
|
+
return value;
|
|
8436
|
+
}
|
|
8016
8437
|
function contentTypeFor(path) {
|
|
8017
8438
|
const ext = path.slice(path.lastIndexOf(".")).toLowerCase();
|
|
8018
8439
|
return MIME_TYPES[ext] ?? "application/octet-stream";
|
|
@@ -8023,6 +8444,9 @@ async function startServeServer(options) {
|
|
|
8023
8444
|
`));
|
|
8024
8445
|
const host = options.host ?? envString("HOST") ?? "127.0.0.1";
|
|
8025
8446
|
const port = resolveServePort(options.port);
|
|
8447
|
+
const publicUrl = resolvePublicUrl(
|
|
8448
|
+
options.publicUrl !== void 0 ? options.publicUrl : envString("ADEP_PUBLIC_URL")
|
|
8449
|
+
);
|
|
8026
8450
|
const staticDir = resolve12(
|
|
8027
8451
|
cwd,
|
|
8028
8452
|
options.staticDir ?? envString("ADEP_SERVE_STATIC_DIR") ?? "public"
|
|
@@ -8045,7 +8469,8 @@ async function startServeServer(options) {
|
|
|
8045
8469
|
let functionNames = listFunctionNames(files);
|
|
8046
8470
|
const envText = await readFile21(join29(cwd, ".env.local"), "utf8").catch(() => "");
|
|
8047
8471
|
let env = parseEnvFile(envText);
|
|
8048
|
-
let
|
|
8472
|
+
let envViews = await loadSimEnvViews(cwd);
|
|
8473
|
+
let simEnv = envViews.merged;
|
|
8049
8474
|
let bearerUser = bearerUserResolverFromEnv(simEnv);
|
|
8050
8475
|
const dotenvFile = await readDotenvFile(cwd, ".env");
|
|
8051
8476
|
let templateEnv;
|
|
@@ -8072,22 +8497,28 @@ async function startServeServer(options) {
|
|
|
8072
8497
|
const runtime = await createSimRuntime({
|
|
8073
8498
|
cwd,
|
|
8074
8499
|
projectId: "local",
|
|
8075
|
-
|
|
8500
|
+
// CLI-048:对外地址显式设置时,存储签名 URL 的基址统一取该值(绑 0.0.0.0 / 容器内
|
|
8501
|
+
// 产出不可达 URL 的缺口);缺省维持监听地址推导,与现版本逐字节一致。
|
|
8502
|
+
baseUrl: publicUrl ?? `http://${host}:${port}`,
|
|
8076
8503
|
log,
|
|
8077
8504
|
...db.driver === null ? {} : { driver: db.driver }
|
|
8078
8505
|
});
|
|
8506
|
+
let schemaReport = null;
|
|
8079
8507
|
if (options.schemaFile !== void 0) {
|
|
8080
|
-
await applyLocalSchema(runtime.db.driver, {
|
|
8508
|
+
schemaReport = await applyLocalSchema(runtime.db.driver, {
|
|
8081
8509
|
cwd,
|
|
8082
8510
|
schemaFile: options.schemaFile,
|
|
8083
8511
|
mode: dbMode,
|
|
8084
8512
|
tag: "serve",
|
|
8513
|
+
...options.schemaFix === true ? { schemaFix: true } : {},
|
|
8085
8514
|
log
|
|
8086
8515
|
});
|
|
8087
8516
|
}
|
|
8088
8517
|
const fetchConfig = resolveLocalFetchConfig(simEnv);
|
|
8089
8518
|
const executor = new WorkerFunctionExecutor({
|
|
8090
8519
|
deps: { rootDir: cwd, builtin: LOCAL_BUILTIN_DEPS },
|
|
8520
|
+
// CORE-154:--parity 严格模式(构造期定死)——process 一律不注入、越根引用报错。
|
|
8521
|
+
...options.parity === true ? { parity: true } : {},
|
|
8091
8522
|
...fetchConfig === void 0 ? {} : { fetch: fetchConfig }
|
|
8092
8523
|
});
|
|
8093
8524
|
if (fetchConfig !== void 0) {
|
|
@@ -8112,7 +8543,8 @@ async function startServeServer(options) {
|
|
|
8112
8543
|
]);
|
|
8113
8544
|
files = nextFiles;
|
|
8114
8545
|
env = parseEnvFile(envLocalText);
|
|
8115
|
-
|
|
8546
|
+
envViews = await loadSimEnvViews(cwd);
|
|
8547
|
+
simEnv = envViews.merged;
|
|
8116
8548
|
bearerUser = bearerUserResolverFromEnv(simEnv);
|
|
8117
8549
|
invokeHandler = createSimInvokeHandler({ executor, files });
|
|
8118
8550
|
functionNames = listFunctionNames(files);
|
|
@@ -8370,6 +8802,16 @@ async function startServeServer(options) {
|
|
|
8370
8802
|
});
|
|
8371
8803
|
});
|
|
8372
8804
|
const actualPort = await listenOnFetchSafePort(server, { port, host, warn: log });
|
|
8805
|
+
runtime.storage.signer.baseUrl = publicUrl ?? `http://${host}:${actualPort}`;
|
|
8806
|
+
const drift = schemaReport?.drift ?? null;
|
|
8807
|
+
const schemaDrift = drift === null || drift.missing.length === 0 ? void 0 : drift.missing.map((plan) => {
|
|
8808
|
+
const where = `"${plan.table}" \u7F3A\u5217 "${plan.column.name}"`;
|
|
8809
|
+
if (drift.fixed.includes(`${plan.table}.${plan.column.name}`)) {
|
|
8810
|
+
return `${where}\uFF08\u5DF2\u81EA\u52A8\u8865\u5217\uFF09`;
|
|
8811
|
+
}
|
|
8812
|
+
return plan.blocked === null ? `${where}\uFF08\u672A\u8865\uFF0C--schema-fix \u53EF\u81EA\u52A8\uFF09` : `${where}\uFF08\u9700\u624B\u5DE5\u8FC1\u79FB\uFF09`;
|
|
8813
|
+
});
|
|
8814
|
+
const effectiveIssuer = resolveEffectiveIssuer(simEnv);
|
|
8373
8815
|
const banner = renderBanner({
|
|
8374
8816
|
host,
|
|
8375
8817
|
port: actualPort,
|
|
@@ -8380,9 +8822,22 @@ async function startServeServer(options) {
|
|
|
8380
8822
|
staticDir: relative4(cwd, staticDir).length > 0 ? relative4(cwd, staticDir) : staticDir,
|
|
8381
8823
|
dbMode,
|
|
8382
8824
|
dbTarget: sqliteFile === null ? simDbTarget(cwd) : displayPath(cwd, sqliteFile),
|
|
8383
|
-
...sqliteModule === null ? {} : { dbDriver: sqliteModule }
|
|
8825
|
+
...sqliteModule === null ? {} : { dbDriver: sqliteModule },
|
|
8826
|
+
...schemaDrift === void 0 ? {} : { schemaDrift },
|
|
8827
|
+
...publicUrl === void 0 ? {} : { publicUrl },
|
|
8828
|
+
effectiveConfig: {
|
|
8829
|
+
envFiles: { env: envViews.env !== null, local: envViews.local !== null },
|
|
8830
|
+
...effectiveIssuer === void 0 ? {} : { issuer: effectiveIssuer },
|
|
8831
|
+
...fetchConfig === void 0 ? {} : {
|
|
8832
|
+
fetchAllowlist: fetchConfig.allowlist,
|
|
8833
|
+
fetchTimeoutMs: fetchConfig.timeoutMs
|
|
8834
|
+
}
|
|
8835
|
+
}
|
|
8384
8836
|
});
|
|
8385
8837
|
log(banner);
|
|
8838
|
+
if (options.parity === true) {
|
|
8839
|
+
log("[serve] --parity \u4E25\u683C\u6A21\u5F0F\uFF1A\u6C99\u7BB1\u4E0D\u6CE8\u5165 process\uFF08env \u8D70 ctx.env\uFF09\u3001../ \u8D8A\u6839\u5F15\u7528\u62A5\u9519\u2014\u2014\u4E0E\u5E73\u53F0\u6C99\u7BB1\u540C\u5F62");
|
|
8840
|
+
}
|
|
8386
8841
|
if (templateEnv !== null) {
|
|
8387
8842
|
const currentKeys = Object.keys(templateEnv.values());
|
|
8388
8843
|
log(
|
|
@@ -8401,6 +8856,7 @@ async function startServeServer(options) {
|
|
|
8401
8856
|
port: actualPort,
|
|
8402
8857
|
host,
|
|
8403
8858
|
baseUrl: `http://${host}:${actualPort}`,
|
|
8859
|
+
publicUrl: publicUrl ?? null,
|
|
8404
8860
|
close: async () => {
|
|
8405
8861
|
stopWatch?.();
|
|
8406
8862
|
await new Promise((resolveClose) => {
|
|
@@ -8472,6 +8928,163 @@ var init_hash = __esm({
|
|
|
8472
8928
|
}
|
|
8473
8929
|
});
|
|
8474
8930
|
|
|
8931
|
+
// packages/cli/src/publish-checks.ts
|
|
8932
|
+
import { posix as posix3 } from "node:path";
|
|
8933
|
+
function formatFindings(findings) {
|
|
8934
|
+
const lines = findings.map(
|
|
8935
|
+
(finding) => `${finding.file}:${finding.line} [${finding.rule}] ${finding.severity === "error" ? "\u5371\u9669" : "\u8B66\u544A"}\uFF1A${finding.message}`
|
|
8936
|
+
);
|
|
8937
|
+
return [`\u53D1\u5E03\u524D\u9759\u6001\u6821\u9A8C\u53D1\u73B0 ${findings.length} \u4E2A\u95EE\u9898\uFF1A`, ...lines, "\u4FEE\u590D\u540E\u91CD\u8BD5\uFF1Bwarn \u7EA7\u53EF\u7528 --force \u653E\u884C\uFF0Cerror \u7EA7\u4E0D\u53EF\u653E\u884C\u3002"].join(
|
|
8938
|
+
"\n"
|
|
8939
|
+
);
|
|
8940
|
+
}
|
|
8941
|
+
function locate(content, index) {
|
|
8942
|
+
const before = content.slice(0, index);
|
|
8943
|
+
const line = before.split("\n").length;
|
|
8944
|
+
const start = before.lastIndexOf("\n") + 1;
|
|
8945
|
+
const end = content.indexOf("\n", index);
|
|
8946
|
+
return { line, text: content.slice(start, end === -1 ? content.length : end) };
|
|
8947
|
+
}
|
|
8948
|
+
function checkFilePath(functionName, file2) {
|
|
8949
|
+
const normalized = file2.split("\\").join("/");
|
|
8950
|
+
const segments = normalized.split("/");
|
|
8951
|
+
const escapes = normalized.startsWith("/") || segments.some((s) => ESCAPE_KEY_SEGMENTS.has(s));
|
|
8952
|
+
if (!escapes) return [];
|
|
8953
|
+
return [
|
|
8954
|
+
{
|
|
8955
|
+
rule: "PATH_ESCAPE",
|
|
8956
|
+
severity: "error",
|
|
8957
|
+
functionName,
|
|
8958
|
+
file: file2,
|
|
8959
|
+
line: 1,
|
|
8960
|
+
message: `bundle \u952E\u4E0D\u80FD\u662F\u7EDD\u5BF9\u8DEF\u5F84\u6216\u5305\u542B ".."\uFF08\u6536\u5230 "${file2}"\uFF09`
|
|
8961
|
+
}
|
|
8962
|
+
];
|
|
8963
|
+
}
|
|
8964
|
+
function checkImportSpecifiers(functionName, file2, content) {
|
|
8965
|
+
const findings = [];
|
|
8966
|
+
for (const matched of content.matchAll(IMPORT_SPECIFIER)) {
|
|
8967
|
+
const specifier = matched[1] ?? "";
|
|
8968
|
+
if (!specifier.startsWith(".")) continue;
|
|
8969
|
+
const resolved = posix3.normalize(posix3.join(posix3.dirname(file2.split("\\").join("/")), specifier));
|
|
8970
|
+
if (!resolved.startsWith("..") && !posix3.isAbsolute(resolved)) continue;
|
|
8971
|
+
const { line } = locate(content, matched.index ?? 0);
|
|
8972
|
+
findings.push({
|
|
8973
|
+
rule: "PATH_ESCAPE",
|
|
8974
|
+
severity: "error",
|
|
8975
|
+
functionName,
|
|
8976
|
+
file: file2,
|
|
8977
|
+
line,
|
|
8978
|
+
message: `import "${specifier}" \u89E3\u6790\u5230 "${resolved}"\uFF0C\u9003\u51FA\u51FD\u6570 bundle \u6839`
|
|
8979
|
+
});
|
|
8980
|
+
}
|
|
8981
|
+
return findings;
|
|
8982
|
+
}
|
|
8983
|
+
function checkSqlConcat(functionName, file2, content) {
|
|
8984
|
+
const findings = [];
|
|
8985
|
+
for (const matched of content.matchAll(SQL_CALL)) {
|
|
8986
|
+
const arg = matched.groups?.["arg"] ?? "";
|
|
8987
|
+
if (!SQL_KEYWORD.test(arg) || !CONCAT_OR_TEMPLATE.test(arg)) continue;
|
|
8988
|
+
const { line } = locate(content, matched.index ?? 0);
|
|
8989
|
+
findings.push({
|
|
8990
|
+
rule: "SQL_CONCAT",
|
|
8991
|
+
severity: "error",
|
|
8992
|
+
functionName,
|
|
8993
|
+
file: file2,
|
|
8994
|
+
line,
|
|
8995
|
+
message: "SQL \u8BED\u53E5\u542B\u5B57\u7B26\u4E32\u62FC\u63A5 / \u6A21\u677F\u63D2\u503C\uFF1B\u6539\u7528\u53C2\u6570\u5316\u5360\u4F4D\u7B26\uFF08? / $1\uFF09"
|
|
8996
|
+
});
|
|
8997
|
+
}
|
|
8998
|
+
return findings;
|
|
8999
|
+
}
|
|
9000
|
+
function checkSecrets(functionName, file2, content) {
|
|
9001
|
+
const findings = [];
|
|
9002
|
+
const lines = content.split("\n");
|
|
9003
|
+
lines.forEach((text, index) => {
|
|
9004
|
+
for (const rule of SECRET_RULES) {
|
|
9005
|
+
if (!rule.pattern.test(text)) continue;
|
|
9006
|
+
findings.push({
|
|
9007
|
+
rule: "SECRET_LITERAL",
|
|
9008
|
+
severity: rule.severity,
|
|
9009
|
+
functionName,
|
|
9010
|
+
file: file2,
|
|
9011
|
+
line: index + 1,
|
|
9012
|
+
message: rule.message
|
|
9013
|
+
});
|
|
9014
|
+
}
|
|
9015
|
+
});
|
|
9016
|
+
return findings;
|
|
9017
|
+
}
|
|
9018
|
+
function collectPrecheckFindings(functions) {
|
|
9019
|
+
const findings = [];
|
|
9020
|
+
for (const [functionName, files] of Object.entries(functions).toSorted(
|
|
9021
|
+
([a], [b]) => a.localeCompare(b)
|
|
9022
|
+
)) {
|
|
9023
|
+
const sortedFiles = Object.entries(files).toSorted(([a], [b]) => a.localeCompare(b));
|
|
9024
|
+
for (const [file2, content] of sortedFiles) {
|
|
9025
|
+
findings.push(...checkFilePath(functionName, file2));
|
|
9026
|
+
findings.push(...checkImportSpecifiers(functionName, file2, content));
|
|
9027
|
+
findings.push(...checkSqlConcat(functionName, file2, content));
|
|
9028
|
+
findings.push(...checkSecrets(functionName, file2, content));
|
|
9029
|
+
}
|
|
9030
|
+
}
|
|
9031
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9032
|
+
return findings.filter((finding) => {
|
|
9033
|
+
const key = `${finding.rule}|${finding.functionName}|${finding.file}|${finding.line}|${finding.message}`;
|
|
9034
|
+
if (seen.has(key)) return false;
|
|
9035
|
+
seen.add(key);
|
|
9036
|
+
return true;
|
|
9037
|
+
}).toSorted(
|
|
9038
|
+
(a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.rule.localeCompare(b.rule)
|
|
9039
|
+
);
|
|
9040
|
+
}
|
|
9041
|
+
function assertPrechecks(functions, options = {}) {
|
|
9042
|
+
const findings = collectPrecheckFindings(functions);
|
|
9043
|
+
const errors = findings.filter((finding) => finding.severity === "error");
|
|
9044
|
+
const warnings = findings.filter((finding) => finding.severity === "warn");
|
|
9045
|
+
if (errors.length > 0) throw new PrecheckError(findings);
|
|
9046
|
+
if (warnings.length > 0 && options.force !== true) throw new PrecheckError(warnings);
|
|
9047
|
+
return warnings;
|
|
9048
|
+
}
|
|
9049
|
+
var PrecheckError, ESCAPE_KEY_SEGMENTS, IMPORT_SPECIFIER, SQL_CALL, SQL_KEYWORD, CONCAT_OR_TEMPLATE, SECRET_RULES;
|
|
9050
|
+
var init_publish_checks = __esm({
|
|
9051
|
+
"packages/cli/src/publish-checks.ts"() {
|
|
9052
|
+
"use strict";
|
|
9053
|
+
init_auth();
|
|
9054
|
+
PrecheckError = class extends CliError {
|
|
9055
|
+
findings;
|
|
9056
|
+
constructor(findings) {
|
|
9057
|
+
super("PRECHECK_FAILED", formatFindings(findings));
|
|
9058
|
+
this.name = "PrecheckError";
|
|
9059
|
+
this.findings = findings;
|
|
9060
|
+
}
|
|
9061
|
+
};
|
|
9062
|
+
ESCAPE_KEY_SEGMENTS = /* @__PURE__ */ new Set([".."]);
|
|
9063
|
+
IMPORT_SPECIFIER = /(?:from\s*|import\s*|require\s*\(\s*)['"]([^'"]+)['"]/g;
|
|
9064
|
+
SQL_CALL = /\.(?:query|execute|run|all|get|prepare)\s*\(\s*(?<arg>[^\n]*)/g;
|
|
9065
|
+
SQL_KEYWORD = /\b(?:SELECT|INSERT|UPDATE|DELETE|REPLACE|WITH|WHERE|FROM)\b/i;
|
|
9066
|
+
CONCAT_OR_TEMPLATE = /(?:\$\{|`\s*\+|\+\s*['"`]|['"`]\s*\+)/;
|
|
9067
|
+
SECRET_RULES = [
|
|
9068
|
+
{
|
|
9069
|
+
pattern: /-----BEGIN (?:RSA |EC |OPENSSH |DSA )?PRIVATE KEY-----/,
|
|
9070
|
+
message: "\u6E90\u7801\u542B PEM \u79C1\u94A5\u660E\u6587",
|
|
9071
|
+
severity: "error"
|
|
9072
|
+
},
|
|
9073
|
+
{ pattern: /AKIA[0-9A-Z]{16}/, message: "\u6E90\u7801\u542B AWS Access Key \u660E\u6587", severity: "error" },
|
|
9074
|
+
{
|
|
9075
|
+
pattern: /(?:sk|pk)_(?:live|test)_[0-9A-Za-z]{16,}/,
|
|
9076
|
+
message: "\u6E90\u7801\u542B\u652F\u4ED8\u6E20\u9053\u5BC6\u94A5\u660E\u6587",
|
|
9077
|
+
severity: "error"
|
|
9078
|
+
},
|
|
9079
|
+
{
|
|
9080
|
+
pattern: /(?:password|passwd|secret|api[_-]?key|access[_-]?token)\s*[:=]\s*['"][^'"]{8,}['"]/i,
|
|
9081
|
+
message: "\u7591\u4F3C\u5BC6\u94A5 / \u53E3\u4EE4\u786C\u7F16\u7801\uFF1B\u6539\u4ECE ctx.env / \u5E73\u53F0\u73AF\u5883\u53D8\u91CF\u8BFB\u53D6",
|
|
9082
|
+
severity: "warn"
|
|
9083
|
+
}
|
|
9084
|
+
];
|
|
9085
|
+
}
|
|
9086
|
+
});
|
|
9087
|
+
|
|
8475
9088
|
// packages/cli/src/deploy.ts
|
|
8476
9089
|
var deploy_exports = {};
|
|
8477
9090
|
__export(deploy_exports, {
|
|
@@ -8577,6 +9190,10 @@ async function deploy(paths, options) {
|
|
|
8577
9190
|
}
|
|
8578
9191
|
const shared = await collectShared(functionsDir);
|
|
8579
9192
|
const filesFor = (name) => local[name] ?? {};
|
|
9193
|
+
const precheckWarnings = assertPrechecks(local, { force: options.force === true });
|
|
9194
|
+
for (const finding of precheckWarnings) {
|
|
9195
|
+
log(`[adep] \u6821\u9A8C\u8B66\u544A ${finding.file}:${finding.line} [${finding.rule}] ${finding.message}`);
|
|
9196
|
+
}
|
|
8580
9197
|
const sharedRows = Object.entries(shared).map(([path, content]) => ({ path, content }));
|
|
8581
9198
|
const hashFiles = (name) => {
|
|
8582
9199
|
const filesAsRuntimeSees = mergeSharedSource(filesFor(name), sharedRows);
|
|
@@ -8677,6 +9294,7 @@ var init_deploy = __esm({
|
|
|
8677
9294
|
init_hash();
|
|
8678
9295
|
init_dev();
|
|
8679
9296
|
init_net();
|
|
9297
|
+
init_publish_checks();
|
|
8680
9298
|
init_shared_source();
|
|
8681
9299
|
init_shared_source();
|
|
8682
9300
|
AmbiguousFunctionError = class extends CliError {
|
|
@@ -8949,7 +9567,7 @@ async function hostingPull(paths, options) {
|
|
|
8949
9567
|
`));
|
|
8950
9568
|
const info = await hostingInfo(paths, options);
|
|
8951
9569
|
const outputDir = resolve15(options.output ?? resolve15(options.cwd));
|
|
8952
|
-
const { mkdir: mkdir17, writeFile:
|
|
9570
|
+
const { mkdir: mkdir17, writeFile: writeFile18 } = await import("node:fs/promises");
|
|
8953
9571
|
const files = [];
|
|
8954
9572
|
for (const entry of info.files) {
|
|
8955
9573
|
if (entry.visibility !== "public" || entry.path === HOSTING_CONFIG_PATH) continue;
|
|
@@ -8961,7 +9579,7 @@ async function hostingPull(paths, options) {
|
|
|
8961
9579
|
const rel = entry.path.replace(/^site\//, "");
|
|
8962
9580
|
const target = join32(outputDir, ...rel.split("/"));
|
|
8963
9581
|
await mkdir17(dirname13(target), { recursive: true });
|
|
8964
|
-
await
|
|
9582
|
+
await writeFile18(target, bytes);
|
|
8965
9583
|
files.push({ path: entry.path, size: bytes.length });
|
|
8966
9584
|
}
|
|
8967
9585
|
return { siteUrl: info.siteUrl, outputDir, files };
|
|
@@ -9431,8 +10049,8 @@ ${detail}`);
|
|
|
9431
10049
|
});
|
|
9432
10050
|
|
|
9433
10051
|
// packages/cli/src/sandbox-scan.ts
|
|
9434
|
-
import { readdir as readdir13, readFile as
|
|
9435
|
-
import { join as
|
|
10052
|
+
import { readdir as readdir13, readFile as readFile31 } from "node:fs/promises";
|
|
10053
|
+
import { join as join38, relative as relative9, sep as sep5 } from "node:path";
|
|
9436
10054
|
function extractSpecifiers(line) {
|
|
9437
10055
|
const out = [];
|
|
9438
10056
|
const patterns = [
|
|
@@ -9476,7 +10094,7 @@ function classify(specifier) {
|
|
|
9476
10094
|
return null;
|
|
9477
10095
|
}
|
|
9478
10096
|
async function scanFunctionSources(rootDir, functionsDir) {
|
|
9479
|
-
const base =
|
|
10097
|
+
const base = join38(rootDir, functionsDir);
|
|
9480
10098
|
const findings = [];
|
|
9481
10099
|
async function walk(current) {
|
|
9482
10100
|
let entries;
|
|
@@ -9486,7 +10104,7 @@ async function scanFunctionSources(rootDir, functionsDir) {
|
|
|
9486
10104
|
return;
|
|
9487
10105
|
}
|
|
9488
10106
|
for (const entry of entries) {
|
|
9489
|
-
const abs =
|
|
10107
|
+
const abs = join38(current, entry.name);
|
|
9490
10108
|
if (entry.isDirectory()) {
|
|
9491
10109
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
9492
10110
|
await walk(abs);
|
|
@@ -9497,7 +10115,7 @@ async function scanFunctionSources(rootDir, functionsDir) {
|
|
|
9497
10115
|
if (entry.name.endsWith(".d.ts")) continue;
|
|
9498
10116
|
let content;
|
|
9499
10117
|
try {
|
|
9500
|
-
content = await
|
|
10118
|
+
content = await readFile31(abs, "utf8");
|
|
9501
10119
|
} catch {
|
|
9502
10120
|
continue;
|
|
9503
10121
|
}
|
|
@@ -9620,7 +10238,10 @@ __export(doctor_exports, {
|
|
|
9620
10238
|
runDoctor: () => runDoctor
|
|
9621
10239
|
});
|
|
9622
10240
|
import { stat as stat18 } from "node:fs/promises";
|
|
9623
|
-
import { join as
|
|
10241
|
+
import { join as join39 } from "node:path";
|
|
10242
|
+
function isWildcardBind(host) {
|
|
10243
|
+
return host === "0.0.0.0" || host === "::" || host === "[::]";
|
|
10244
|
+
}
|
|
9624
10245
|
async function probeServer(server) {
|
|
9625
10246
|
const controller = new AbortController();
|
|
9626
10247
|
const timer = setTimeout(() => controller.abort(), SERVER_PROBE_TIMEOUT_MS);
|
|
@@ -9648,11 +10269,12 @@ async function credentialMode(file2) {
|
|
|
9648
10269
|
async function runDoctor(paths, cwd = process.cwd()) {
|
|
9649
10270
|
const credentials = await loadCredentials(paths);
|
|
9650
10271
|
const server = credentials?.server ?? resolveServer();
|
|
9651
|
-
const credentialsFile = credentials !== null ?
|
|
10272
|
+
const credentialsFile = credentials !== null ? join39(paths.credentialsDir, `${slotNameFor(credentials.server)}.json`) : paths.credentialsFile;
|
|
9652
10273
|
const mode = await credentialMode(credentialsFile);
|
|
9653
10274
|
const offline = await isOffline();
|
|
9654
10275
|
const health = await probeServer(server);
|
|
9655
10276
|
const sandbox = await scanSandbox(cwd);
|
|
10277
|
+
const projectEnv = await inspectProjectEnv(cwd);
|
|
9656
10278
|
const report = {
|
|
9657
10279
|
server,
|
|
9658
10280
|
credentials: {
|
|
@@ -9664,7 +10286,12 @@ async function runDoctor(paths, cwd = process.cwd()) {
|
|
|
9664
10286
|
serverHealth: health,
|
|
9665
10287
|
offlineCommands: [...OFFLINE_COMMANDS],
|
|
9666
10288
|
boundaries: SIM_BOUNDARIES.map((b) => ({ kind: b.kind, title: b.title, detail: b.detail })),
|
|
9667
|
-
sandbox
|
|
10289
|
+
sandbox,
|
|
10290
|
+
servePublicUrl: {
|
|
10291
|
+
env: process.env["ADEP_PUBLIC_URL"]?.trim() || null,
|
|
10292
|
+
hostEnv: process.env["HOST"]?.trim() || null
|
|
10293
|
+
},
|
|
10294
|
+
projectEnv
|
|
9668
10295
|
};
|
|
9669
10296
|
if (credentials !== null) report.credentials.email = credentials.email;
|
|
9670
10297
|
if (mode !== void 0 && mode !== "600") {
|
|
@@ -9688,6 +10315,47 @@ async function scanSandbox(cwd) {
|
|
|
9688
10315
|
return { functionsDir: null, findings: [] };
|
|
9689
10316
|
}
|
|
9690
10317
|
}
|
|
10318
|
+
async function inspectProjectEnv(cwd) {
|
|
10319
|
+
const views = await loadSimEnvViews(cwd).catch(() => ({ env: null, local: null, merged: {} }));
|
|
10320
|
+
const issuer = resolveEffectiveIssuer(views.merged);
|
|
10321
|
+
let fetch2 = {
|
|
10322
|
+
configured: false,
|
|
10323
|
+
hostCount: null,
|
|
10324
|
+
timeoutMs: null,
|
|
10325
|
+
warning: null
|
|
10326
|
+
};
|
|
10327
|
+
try {
|
|
10328
|
+
const local = resolveLocalFetchConfig(views.merged);
|
|
10329
|
+
if (local !== void 0) {
|
|
10330
|
+
fetch2 = {
|
|
10331
|
+
configured: true,
|
|
10332
|
+
hostCount: local.allowlist.length,
|
|
10333
|
+
timeoutMs: local.timeoutMs,
|
|
10334
|
+
warning: null
|
|
10335
|
+
};
|
|
10336
|
+
}
|
|
10337
|
+
} catch (error62) {
|
|
10338
|
+
fetch2 = {
|
|
10339
|
+
configured: false,
|
|
10340
|
+
hostCount: null,
|
|
10341
|
+
timeoutMs: null,
|
|
10342
|
+
warning: error62 instanceof Error ? error62.message : String(error62)
|
|
10343
|
+
};
|
|
10344
|
+
}
|
|
10345
|
+
return {
|
|
10346
|
+
envFiles: {
|
|
10347
|
+
env: views.env !== null,
|
|
10348
|
+
local: views.local !== null,
|
|
10349
|
+
envKeys: views.env === null ? 0 : Object.keys(views.env).length,
|
|
10350
|
+
localKeys: views.local === null ? 0 : Object.keys(views.local).length
|
|
10351
|
+
},
|
|
10352
|
+
authIssuer: {
|
|
10353
|
+
value: issuer ?? null,
|
|
10354
|
+
warning: issuer === void 0 ? null : issuerSuffixWarning(issuer)
|
|
10355
|
+
},
|
|
10356
|
+
fetchAllowlist: fetch2
|
|
10357
|
+
};
|
|
10358
|
+
}
|
|
9691
10359
|
function formatDoctorReport(report) {
|
|
9692
10360
|
const lines = ["adep doctor \xB7 \u73AF\u5883\u81EA\u68C0", ""];
|
|
9693
10361
|
lines.push("\u51ED\u636E\u4E0E\u8EAB\u4EFD");
|
|
@@ -9715,6 +10383,52 @@ function formatDoctorReport(report) {
|
|
|
9715
10383
|
}
|
|
9716
10384
|
lines.push("", "\u79BB\u7EBF\u53EF\u7528\u8303\u56F4\uFF08\u65AD\u7F51\u65F6\u4ECD\u53EF\u6267\u884C\uFF09");
|
|
9717
10385
|
for (const command of report.offlineCommands) lines.push(` \xB7 ${command}`);
|
|
10386
|
+
lines.push("", "serve \u5BF9\u5916\u5730\u5740\uFF08--public-url / ADEP_PUBLIC_URL\uFF0C\u7B7E\u540D URL \u57FA\u5740\uFF09");
|
|
10387
|
+
if (report.servePublicUrl.env !== null) {
|
|
10388
|
+
lines.push(` \u2713 ADEP_PUBLIC_URL=${report.servePublicUrl.env}\uFF08serve \u6A2A\u5E45\u4E0E\u7B7E\u540D URL \u7EDF\u4E00\u53D6\u8BE5\u503C\uFF09`);
|
|
10389
|
+
} else if (report.servePublicUrl.hostEnv !== null && isWildcardBind(report.servePublicUrl.hostEnv)) {
|
|
10390
|
+
lines.push(
|
|
10391
|
+
` ! HOST=${report.servePublicUrl.hostEnv} \u4E14\u672A\u8BBE ADEP_PUBLIC_URL\uFF1Aserve \u4EA7\u51FA\u7684\u7B7E\u540D URL \u4E0E\u6A2A\u5E45\u5730\u5740\u4E0D\u53EF\u8FBE\uFF08http://0.0.0.0:<port>/... \u5F62\u6001\uFF09\uFF0C\u516C\u7F51 HTTPS \u4E0B\u8FD8\u5C5E\u6DF7\u5408\u5185\u5BB9\uFF1B`,
|
|
10392
|
+
" \u63D0\u793A\uFF1A\u8BBE ADEP_PUBLIC_URL\uFF08\u6216 serve \u52A0 --public-url\uFF09\u7EDF\u4E00\u5BF9\u5916\u5730\u5740"
|
|
10393
|
+
);
|
|
10394
|
+
} else {
|
|
10395
|
+
lines.push(
|
|
10396
|
+
" \xB7 \u672A\u8BBE ADEP_PUBLIC_URL\uFF1A\u7B7E\u540D URL \u6309\u76D1\u542C\u5730\u5740\u63A8\u5BFC\uFF08\u7F3A\u7701 127.0.0.1\uFF0C\u672C\u673A\u53EF\u7528\uFF09\uFF1B\u5BB9\u5668 / \u5C40\u57DF\u7F51\u5BF9\u5916\u90E8\u7F72\u65F6\u5EFA\u8BAE\u663E\u5F0F\u8BBE\u7F6E"
|
|
10397
|
+
);
|
|
10398
|
+
}
|
|
10399
|
+
lines.push("", "\u9879\u76EE env \u4E0E\u751F\u6548\u914D\u7F6E\uFF08.env.local \u8986\u76D6 .env\uFF1B\u6C99\u7BB1 env \u53EA\u8BA4\u8FD9\u4E24\u4EFD\u6587\u4EF6\uFF09");
|
|
10400
|
+
{
|
|
10401
|
+
const { env, local, envKeys, localKeys } = report.projectEnv.envFiles;
|
|
10402
|
+
if (env && local) {
|
|
10403
|
+
lines.push(` \u2713 .env\uFF08${envKeys} \u952E\uFF09+ .env.local\uFF08${localKeys} \u952E\uFF0C\u8986\u76D6 .env\uFF09`);
|
|
10404
|
+
} else if (local) {
|
|
10405
|
+
lines.push(` \u2713 .env.local\uFF08${localKeys} \u952E\uFF09\u2014\u2014.env \u4E0D\u5B58\u5728`);
|
|
10406
|
+
} else if (env) {
|
|
10407
|
+
lines.push(` \u2713 .env\uFF08${envKeys} \u952E\uFF09\u2014\u2014.env.local \u4E0D\u5B58\u5728`);
|
|
10408
|
+
} else {
|
|
10409
|
+
lines.push(" \xB7 \u65E0 .env / .env.local\uFF08\u6C99\u7BB1 env \u4E3A\u7A7A\u8868\uFF1B\u952E\u53EA\u5728\u8FDB\u7A0B\u91CC export \u7684\u4E0D\u8FDB\u6C99\u7BB1\uFF09");
|
|
10410
|
+
}
|
|
10411
|
+
const issuer = report.projectEnv.authIssuer;
|
|
10412
|
+
if (issuer.value === null) {
|
|
10413
|
+
lines.push(" \xB7 ADEP_AUTH_ISSUER \u672A\u914D\u7F6E\uFF08\u767B\u5F55\u5373\u670D\u52A1\u5173\u95ED\uFF0CBearer \u4E0D\u89E3\u6790\u8EAB\u4EFD\uFF09");
|
|
10414
|
+
} else if (issuer.warning !== null) {
|
|
10415
|
+
lines.push(` ! ${issuer.warning}`);
|
|
10416
|
+
} else {
|
|
10417
|
+
lines.push(` \u2713 \u767B\u5F55\u5373\u670D\u52A1 issuer ${issuer.value}\uFF08\u540E\u7F00\u6821\u9A8C\u901A\u8FC7\uFF09`);
|
|
10418
|
+
}
|
|
10419
|
+
const fetch2 = report.projectEnv.fetchAllowlist;
|
|
10420
|
+
if (fetch2.warning !== null) {
|
|
10421
|
+
lines.push(` ! ${fetch2.warning}`);
|
|
10422
|
+
} else if (fetch2.configured) {
|
|
10423
|
+
lines.push(
|
|
10424
|
+
` \u2713 \u53D7\u63A7 fetch \u767D\u540D\u5355\uFF1A${fetch2.hostCount} \u53F0\u4E3B\u673A\uFF08\u8D85\u65F6 ${fetch2.timeoutMs}ms\uFF09`
|
|
10425
|
+
);
|
|
10426
|
+
} else {
|
|
10427
|
+
lines.push(
|
|
10428
|
+
" \xB7 \u53D7\u63A7 fetch \u767D\u540D\u5355\u672A\u914D\u7F6E\uFF08\u6C99\u7BB1\u65E0\u7F51\u7EDC\uFF0CFN-002 \u7F3A\u7701\uFF1BFUNCTIONS_FETCH_ALLOWLIST \u53EF\u5F00\u542F\uFF09"
|
|
10429
|
+
);
|
|
10430
|
+
}
|
|
10431
|
+
}
|
|
9718
10432
|
lines.push("", "\u4E91\u51FD\u6570\u6C99\u7BB1\u517C\u5BB9\u6027\uFF08\u53D1\u5E03\u524D\u5C31\u80FD\u6539\uFF0C\u522B\u7B49\u8FD0\u884C\u65F6\u70B8\uFF09");
|
|
9719
10433
|
if (report.sandbox.functionsDir === null) {
|
|
9720
10434
|
lines.push(" \xB7 \u672A\u627E\u5230\u51FD\u6570\u76EE\u5F55\uFF0C\u8DF3\u8FC7\u626B\u63CF");
|
|
@@ -9750,6 +10464,9 @@ var init_doctor = __esm({
|
|
|
9750
10464
|
init_credentials();
|
|
9751
10465
|
init_config();
|
|
9752
10466
|
init_boundary();
|
|
10467
|
+
init_env();
|
|
10468
|
+
init_fetch_config();
|
|
10469
|
+
init_dev_shared();
|
|
9753
10470
|
init_net();
|
|
9754
10471
|
init_sandbox_scan();
|
|
9755
10472
|
init_ts_config();
|
|
@@ -10037,7 +10754,9 @@ var init_git = __esm({
|
|
|
10037
10754
|
var functions_exports = {};
|
|
10038
10755
|
__export(functions_exports, {
|
|
10039
10756
|
functionsList: () => functionsList,
|
|
10040
|
-
functionsLogs: () => functionsLogs
|
|
10757
|
+
functionsLogs: () => functionsLogs,
|
|
10758
|
+
logsByTrace: () => logsByTrace,
|
|
10759
|
+
resolveProject: () => resolveProject2
|
|
10041
10760
|
});
|
|
10042
10761
|
import { resolve as resolve20 } from "node:path";
|
|
10043
10762
|
async function functionsList(paths, options) {
|
|
@@ -10080,6 +10799,22 @@ async function functionsLogs(paths, options) {
|
|
|
10080
10799
|
);
|
|
10081
10800
|
return { functionId: target.id, name: target.name, logs: result.logs };
|
|
10082
10801
|
}
|
|
10802
|
+
async function logsByTrace(paths, options) {
|
|
10803
|
+
const trace = options.trace.trim();
|
|
10804
|
+
if (trace.length === 0) {
|
|
10805
|
+
throw new CliError("INVALID_ARGUMENT", "\u7F3A\u5C11 traceId\uFF1Aadep logs --trace <traceId>");
|
|
10806
|
+
}
|
|
10807
|
+
const client = await createClient(paths);
|
|
10808
|
+
const project2 = await resolveProject2(client, options);
|
|
10809
|
+
const params = new URLSearchParams({ trace });
|
|
10810
|
+
if (options.tail !== void 0) params.set("tail", String(options.tail));
|
|
10811
|
+
const result = await client.request(
|
|
10812
|
+
`/api/v1/projects/${project2.id}/logs?${params.toString()}`,
|
|
10813
|
+
{},
|
|
10814
|
+
"FUNCTION_LOGS_FAILED"
|
|
10815
|
+
);
|
|
10816
|
+
return { projectId: project2.id, slug: project2.slug, traceId: result.traceId, logs: result.logs };
|
|
10817
|
+
}
|
|
10083
10818
|
async function resolveProject2(client, options) {
|
|
10084
10819
|
const slug = await resolveSlug(resolve20(options.cwd), options.slug);
|
|
10085
10820
|
const projects = await projectsListFrom(client);
|
|
@@ -10104,6 +10839,65 @@ var init_functions = __esm({
|
|
|
10104
10839
|
}
|
|
10105
10840
|
});
|
|
10106
10841
|
|
|
10842
|
+
// packages/cli/src/rollback.ts
|
|
10843
|
+
var rollback_exports = {};
|
|
10844
|
+
__export(rollback_exports, {
|
|
10845
|
+
parseVersionFlag: () => parseVersionFlag,
|
|
10846
|
+
rollbackFunctionTo: () => rollbackFunctionTo
|
|
10847
|
+
});
|
|
10848
|
+
function parseVersionFlag(raw) {
|
|
10849
|
+
const text = (raw ?? "").trim();
|
|
10850
|
+
const matched = /^v?(\d+)$/.exec(text);
|
|
10851
|
+
const version2 = matched === null ? Number.NaN : Number(matched[1]);
|
|
10852
|
+
if (!Number.isInteger(version2) || version2 <= 0) {
|
|
10853
|
+
throw new CliError("INVALID_ARGUMENT", `--to \u987B\u4E3A\u7248\u672C\u53F7\uFF08\u5982 v2 \u6216 2\uFF09\uFF0C\u6536\u5230 "${raw ?? ""}"`);
|
|
10854
|
+
}
|
|
10855
|
+
return version2;
|
|
10856
|
+
}
|
|
10857
|
+
async function rollbackFunctionTo(paths, options) {
|
|
10858
|
+
if (!Number.isInteger(options.to) || options.to <= 0) {
|
|
10859
|
+
throw new CliError("INVALID_ARGUMENT", `--to \u987B\u4E3A\u6B63\u6574\u6570\uFF0C\u6536\u5230 ${options.to}`);
|
|
10860
|
+
}
|
|
10861
|
+
const client = await createClient(paths);
|
|
10862
|
+
const project2 = await resolveProject2(client, options);
|
|
10863
|
+
const listed = await client.request(
|
|
10864
|
+
`/api/v1/projects/${project2.id}/functions`,
|
|
10865
|
+
{},
|
|
10866
|
+
"FUNCTION_LIST_FAILED"
|
|
10867
|
+
);
|
|
10868
|
+
const target = listed.functions.find((fn) => fn.name === options.name);
|
|
10869
|
+
if (target === void 0) {
|
|
10870
|
+
throw new CliError("FN_NOT_FOUND", `\u51FD\u6570 "${options.name}" \u4E0D\u5B58\u5728\u4E8E\u9879\u76EE "${project2.slug}"`);
|
|
10871
|
+
}
|
|
10872
|
+
const versions = await client.request(`/api/v1/functions/${target.id}/versions`, {}, "FUNCTION_VERSIONS_FAILED");
|
|
10873
|
+
if (!versions.versions.some((version2) => version2.version === options.to)) {
|
|
10874
|
+
const available = versions.versions.map((version2) => `v${version2.version}`).join(", ");
|
|
10875
|
+
throw new CliError(
|
|
10876
|
+
"VERSION_NOT_FOUND",
|
|
10877
|
+
`\u7248\u672C v${options.to} \u4E0D\u5728\u4FDD\u7559\u7A97\u53E3\u5185\uFF08\u5F53\u524D v${versions.current ?? "\u2014"}\uFF1B\u53EF\u7528\uFF1A${available === "" ? "\u65E0" : available}\uFF09`
|
|
10878
|
+
);
|
|
10879
|
+
}
|
|
10880
|
+
const result = await client.request(
|
|
10881
|
+
`/api/v1/functions/${target.id}/rollback`,
|
|
10882
|
+
{ method: "POST", body: { version: options.to } },
|
|
10883
|
+
"ROLLBACK_FAILED"
|
|
10884
|
+
);
|
|
10885
|
+
return {
|
|
10886
|
+
functionId: target.id,
|
|
10887
|
+
name: target.name,
|
|
10888
|
+
from: versions.current,
|
|
10889
|
+
to: result.version
|
|
10890
|
+
};
|
|
10891
|
+
}
|
|
10892
|
+
var init_rollback = __esm({
|
|
10893
|
+
"packages/cli/src/rollback.ts"() {
|
|
10894
|
+
"use strict";
|
|
10895
|
+
init_auth();
|
|
10896
|
+
init_client();
|
|
10897
|
+
init_functions();
|
|
10898
|
+
}
|
|
10899
|
+
});
|
|
10900
|
+
|
|
10107
10901
|
// packages/cli/src/cli.ts
|
|
10108
10902
|
init_config();
|
|
10109
10903
|
import { Command } from "commander";
|
|
@@ -36673,13 +37467,13 @@ function parseTomlValue(raw) {
|
|
|
36673
37467
|
if (text.startsWith("[") && text.endsWith("]")) {
|
|
36674
37468
|
const inner = text.slice(1, -1).trim();
|
|
36675
37469
|
if (inner === "") return [];
|
|
36676
|
-
return
|
|
37470
|
+
return splitTopLevel3(inner).map((part) => parseTomlValue(part));
|
|
36677
37471
|
}
|
|
36678
37472
|
if (text.startsWith("{") && text.endsWith("}")) {
|
|
36679
37473
|
const inner = text.slice(1, -1).trim();
|
|
36680
37474
|
const table = {};
|
|
36681
37475
|
if (inner !== "") {
|
|
36682
|
-
for (const pair of
|
|
37476
|
+
for (const pair of splitTopLevel3(inner)) {
|
|
36683
37477
|
const eq = pair.indexOf("=");
|
|
36684
37478
|
if (eq <= 0) throw new TomlSyntaxError(`\u5185\u8054\u8868\u6761\u76EE\u975E\u6CD5\uFF1A${pair}`);
|
|
36685
37479
|
const key = pair.slice(0, eq).trim().replace(/^"|"$/g, "");
|
|
@@ -36697,7 +37491,7 @@ function parseTomlValue(raw) {
|
|
|
36697
37491
|
if (text !== "" && !Number.isNaN(number4) && /^-?\d+(\.\d+)?$/.test(text)) return number4;
|
|
36698
37492
|
return text;
|
|
36699
37493
|
}
|
|
36700
|
-
function
|
|
37494
|
+
function splitTopLevel3(text) {
|
|
36701
37495
|
const parts = [];
|
|
36702
37496
|
let depth = 0;
|
|
36703
37497
|
let quote3 = null;
|
|
@@ -37459,6 +38253,15 @@ function registerDevServers(program2, ctx) {
|
|
|
37459
38253
|
).option(
|
|
37460
38254
|
"--schema <file>",
|
|
37461
38255
|
"\u6570\u636E\u5E93\u7ED3\u6784\u6587\u4EF6\uFF1A\u542F\u52A8\u65F6\u5BF9\u672C\u5730\u5E93\u9010\u6761\u5E94\u7528\uFF08\u5EFA\u8868\u8BED\u53E5\u5EFA\u8BAE IF NOT EXISTS\uFF0C\u5E42\u7B49\u53EF\u91CD\u590D\u542F\u52A8\uFF09"
|
|
38256
|
+
).option(
|
|
38257
|
+
"--schema-fix",
|
|
38258
|
+
"\u7F3A\u5217\u81EA\u52A8\u8865\u5217\uFF08CLI-047\uFF0C\u914D\u5408 --schema\uFF09\uFF1A\u5B58\u91CF\u8868\u7F3A\u5217\u65F6\u6267\u884C ADD COLUMN\uFF08\u4EC5\u52A0\u5217\uFF0CRENAME / \u5220\u5217 / \u6539\u7C7B\u578B\u4ECD\u624B\u5DE5\uFF09\uFF1B\u7F3A\u7701\u53EA\u54CD\u4EAE\u8B66\u544A"
|
|
38259
|
+
).option(
|
|
38260
|
+
"--public-url <url>",
|
|
38261
|
+
"\u5BF9\u5916\u5730\u5740\uFF08\u7F3A\u7701\u53D6 ADEP_PUBLIC_URL\uFF09\uFF1Aserve \u6A2A\u5E45\u4E0E\u5B58\u50A8\u7B7E\u540D URL \u7684\u57FA\u5740\u7EDF\u4E00\u53D6\u8BE5\u503C\uFF1B\u7ED1\u5B9A 0.0.0.0 / \u5BB9\u5668\u5185 / \u516C\u7F51 HTTPS \u65F6\u5FC5\u8BBE\uFF08\u5426\u5219\u7B7E\u540D URL \u4E0D\u53EF\u8FBE\uFF09"
|
|
38262
|
+
).option(
|
|
38263
|
+
"--parity",
|
|
38264
|
+
"\u5E73\u53F0\u6C99\u7BB1\u4E25\u683C\u540C\u5F62\uFF08CORE-154\uFF09\uFF1A\u6C99\u7BB1\u4E0D\u6CE8\u5165 process\uFF08env \u8D70 ctx.env\uFF09\u3001../ \u8D8A\u6839\u5F15\u7528\u62A5\u9519\u2014\u2014\u672C\u5730\u4E0D\u518D\u63A9\u76D6\u5E73\u53F0\u7EA6\u675F\uFF1B\u7F3A\u7701\u5173\u95ED\uFF0C\u73B0\u884C\u4E3A\u4E0D\u53D8"
|
|
37462
38265
|
).option(
|
|
37463
38266
|
"--db <mode>",
|
|
37464
38267
|
"\u6570\u636E\u5E93\u6A21\u5F0F\uFF1Asqlite\uFF08\u7F3A\u7701\uFF0C\u771F\u5B9E SQLite \u5E93\u6587\u4EF6\uFF0C\u9700 Bun \u6216 Node \u2265 22.5\uFF1B\u8FD0\u884C\u65F6\u4E0D\u652F\u6301\u6216\u6253\u5F00\u5931\u8D25\u65F6\u81EA\u52A8\u964D\u7EA7 sim\uFF09| sim\uFF08\u5185\u7F6E\u6A21\u62DF\u5F15\u64CE + .adep/sim/db.json\uFF09"
|
|
@@ -37480,6 +38283,9 @@ function registerDevServers(program2, ctx) {
|
|
|
37480
38283
|
...flags.static === void 0 ? {} : { staticDir: flags.static },
|
|
37481
38284
|
...flags.watch === void 0 ? {} : { watch: true },
|
|
37482
38285
|
...flags.schema === void 0 ? {} : { schemaFile: flags.schema },
|
|
38286
|
+
...flags.schemaFix === true ? { schemaFix: true } : {},
|
|
38287
|
+
...flags.publicUrl === void 0 ? {} : { publicUrl: flags.publicUrl },
|
|
38288
|
+
...flags.parity === true ? { parity: true } : {},
|
|
37483
38289
|
...flags.db === void 0 ? {} : { db: flags.db },
|
|
37484
38290
|
...flags.dbFile === void 0 ? {} : { dbFile: flags.dbFile },
|
|
37485
38291
|
...flags.spa === void 0 ? {} : { spaFallback: true }
|
|
@@ -38292,6 +39098,144 @@ ${renderDrift(diff).join("\n")}`
|
|
|
38292
39098
|
});
|
|
38293
39099
|
}
|
|
38294
39100
|
|
|
39101
|
+
// packages/cli/src/commands/env.ts
|
|
39102
|
+
init_auth();
|
|
39103
|
+
init_env();
|
|
39104
|
+
import { readFile as readFile30, writeFile as writeFile17 } from "node:fs/promises";
|
|
39105
|
+
import { join as join37 } from "node:path";
|
|
39106
|
+
var ENV_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
39107
|
+
function upsertEnvLine(content, key, value) {
|
|
39108
|
+
const lines = content.split(/\r?\n/);
|
|
39109
|
+
let replaced = false;
|
|
39110
|
+
const out = lines.map((line) => {
|
|
39111
|
+
if (replaced) return line;
|
|
39112
|
+
const trimmed = line.trim();
|
|
39113
|
+
if (trimmed.length === 0 || trimmed.startsWith("#")) return line;
|
|
39114
|
+
const eq = trimmed.indexOf("=");
|
|
39115
|
+
if (eq === -1) return line;
|
|
39116
|
+
if (trimmed.slice(0, eq).trim() !== key) return line;
|
|
39117
|
+
replaced = true;
|
|
39118
|
+
return `${key}=${value}`;
|
|
39119
|
+
});
|
|
39120
|
+
if (!replaced) {
|
|
39121
|
+
const lastIdx = out.length - 1;
|
|
39122
|
+
if (lastIdx >= 0 && out[lastIdx] === "") out.splice(lastIdx, 0, `${key}=${value}`);
|
|
39123
|
+
else out.push(`${key}=${value}`);
|
|
39124
|
+
}
|
|
39125
|
+
return out.join("\n");
|
|
39126
|
+
}
|
|
39127
|
+
function mergeEnvKeyEntries(env, local) {
|
|
39128
|
+
const entries = [];
|
|
39129
|
+
const seen = /* @__PURE__ */ new Set();
|
|
39130
|
+
if (local !== null) {
|
|
39131
|
+
for (const key of Object.keys(local)) {
|
|
39132
|
+
seen.add(key);
|
|
39133
|
+
entries.push({ key, source: ".env.local", overridden: env?.[key] !== void 0 });
|
|
39134
|
+
}
|
|
39135
|
+
}
|
|
39136
|
+
if (env !== null) {
|
|
39137
|
+
for (const key of Object.keys(env)) {
|
|
39138
|
+
if (seen.has(key)) continue;
|
|
39139
|
+
entries.push({ key, source: ".env", overridden: false });
|
|
39140
|
+
}
|
|
39141
|
+
}
|
|
39142
|
+
return entries;
|
|
39143
|
+
}
|
|
39144
|
+
function registerEnv(program2, ctx) {
|
|
39145
|
+
const envCommand = program2.command("env").description("\u9879\u76EE env \u53EF\u89C6\u5316\u4E0E\u672C\u5730\u5199\u5165\uFF08.env.local \u8986\u76D6 .env\uFF1B\u8FDC\u7AEF\u9879\u76EE env \u8D70\u5E73\u53F0\u63A7\u5236\u53F0\uFF09");
|
|
39146
|
+
envCommand.command("list").description("\u5217\u51FA\u751F\u6548 env \u952E\u4E0E\u6765\u6E90\u6587\u4EF6\uFF08\u4E0D\u56DE\u663E\u503C\uFF1B\u8FDC\u7AEF\u4E0D\u53EF\u8FBE\u65F6\u6807\u6CE8\u539F\u56E0\uFF09").action(async () => {
|
|
39147
|
+
const command = ctx.io("env list");
|
|
39148
|
+
await command.run(async () => {
|
|
39149
|
+
const views = await loadSimEnvViews(ctx.cwd);
|
|
39150
|
+
const keys = mergeEnvKeyEntries(views.env, views.local);
|
|
39151
|
+
const data = {
|
|
39152
|
+
files: { env: views.env !== null, local: views.local !== null },
|
|
39153
|
+
envKeyCount: views.env === null ? 0 : Object.keys(views.env).length,
|
|
39154
|
+
localKeyCount: views.local === null ? 0 : Object.keys(views.local).length,
|
|
39155
|
+
keys,
|
|
39156
|
+
// 远端对照面(显式不可达,不静默):CLI 暂无项目 env 读取端点,端点与推送面另立 FN 线单。
|
|
39157
|
+
remote: {
|
|
39158
|
+
available: false,
|
|
39159
|
+
reason: "CLI \u6682\u65E0\u9879\u76EE env \u8BFB\u53D6\u7AEF\u70B9\uFF08\u8FDC\u7AEF\u5728\u5E73\u53F0\u63A7\u5236\u53F0\u7EF4\u62A4\uFF1BCLI \u8BFB\u5199\u8FDC\u7AEF\u53E6\u7ACB FN \u7EBF\u5355\uFF09"
|
|
39160
|
+
}
|
|
39161
|
+
};
|
|
39162
|
+
command.ok(data, () => {
|
|
39163
|
+
const lines = ["\u672C\u5730 env\uFF08.env.local \u8986\u76D6 .env\uFF1B\u6C99\u7BB1\u53EA\u8BA4\u8FD9\u4E24\u4EFD\u6587\u4EF6\uFF09:"];
|
|
39164
|
+
if (keys.length === 0) {
|
|
39165
|
+
lines.push(" \uFF08\u65E0\u952E\u2014\u2014\u9879\u76EE\u6839\u6CA1\u6709 .env / .env.local\uFF0C\u6216\u6587\u4EF6\u4E3A\u7A7A\uFF09");
|
|
39166
|
+
} else {
|
|
39167
|
+
for (const entry of keys) {
|
|
39168
|
+
const source = entry.overridden ? `${entry.source}\uFF08\u8986\u76D6 .env\uFF09` : entry.source;
|
|
39169
|
+
lines.push(` ${entry.key} \u2190 ${source}`);
|
|
39170
|
+
}
|
|
39171
|
+
}
|
|
39172
|
+
lines.push(
|
|
39173
|
+
`\uFF08\u5171 ${keys.length} \u952E\uFF1A.env ${data.envKeyCount} \u952E / .env.local ${data.localKeyCount} \u952E\uFF09`
|
|
39174
|
+
);
|
|
39175
|
+
lines.push(`\u8FDC\u7AEF\u9879\u76EE env \u5BF9\u7167: \u4E0D\u53EF\u8FBE\u2014\u2014${data.remote.reason}`);
|
|
39176
|
+
return lines;
|
|
39177
|
+
});
|
|
39178
|
+
});
|
|
39179
|
+
});
|
|
39180
|
+
envCommand.command("get <key>").description("\u8BFB\u4E00\u4E2A\u952E\u7684\u751F\u6548\u503C\uFF08.env.local \u8986\u76D6 .env\uFF1B\u4E0D\u8BFB\u8FDB\u7A0B\u73AF\u5883\u53D8\u91CF\uFF09").action(async (key) => {
|
|
39181
|
+
const command = ctx.io("env get");
|
|
39182
|
+
await command.run(async () => {
|
|
39183
|
+
const views = await loadSimEnvViews(ctx.cwd);
|
|
39184
|
+
const inLocal = views.local?.[key];
|
|
39185
|
+
const inEnv = views.env?.[key];
|
|
39186
|
+
if (inLocal === void 0 && inEnv === void 0) {
|
|
39187
|
+
throw new CliError(
|
|
39188
|
+
"ENV_KEY_NOT_FOUND",
|
|
39189
|
+
`\u952E "${key}" \u672A\u5728 .env / .env.local \u4E2D\u914D\u7F6E\uFF08\u6C99\u7BB1 env \u53EA\u6765\u81EA\u8FD9\u4E24\u4EFD\u6587\u4EF6\uFF1B\u8FDB\u7A0B export \u7684\u952E\u4E0D\u6CE8\u5165\u6C99\u7BB1\u2014\u2014\u5982\u9700\u751F\u6548\u8BF7 adep env set ${key} <value>\uFF09`
|
|
39190
|
+
);
|
|
39191
|
+
}
|
|
39192
|
+
const value = inLocal ?? inEnv;
|
|
39193
|
+
const source = inLocal !== void 0 ? ".env.local" : ".env";
|
|
39194
|
+
const data = {
|
|
39195
|
+
key,
|
|
39196
|
+
value,
|
|
39197
|
+
source,
|
|
39198
|
+
overridden: source === ".env.local" && inEnv !== void 0
|
|
39199
|
+
};
|
|
39200
|
+
command.ok(data, () => [`${key}=${value}\uFF08\u6765\u6E90 ${source}${data.overridden ? "\uFF0C\u8986\u76D6 .env" : ""}\uFF09`]);
|
|
39201
|
+
});
|
|
39202
|
+
});
|
|
39203
|
+
envCommand.command("set <key> <value...>").description("\u5199\u5165 .env.local\uFF08\u8986\u76D6\u5C42\uFF1B\u503C\u53EF\u5F15\u53F7\u5305\u88F9\u4FDD\u5F62\uFF0C\u672A\u5F15\u53F7\u7684\u591A\u8BCD\u4EE5\u5355\u7A7A\u683C\u62FC\u63A5\uFF1B\u4E0B\u6B21 dev/serve \u88C5\u8F7D\u5373\u751F\u6548\uFF09").action(async (key, valueParts) => {
|
|
39204
|
+
const command = ctx.io("env set");
|
|
39205
|
+
await command.run(async () => {
|
|
39206
|
+
if (!ENV_KEY_RE.test(key)) {
|
|
39207
|
+
throw new CliError(
|
|
39208
|
+
"INVALID_ENV_KEY",
|
|
39209
|
+
`\u952E\u540D "${key}" \u975E\u6CD5\uFF1A\u987B\u5339\u914D /^[A-Za-z_][A-Za-z0-9_]*$/\uFF08parseEnv \u53D6\u7B49\u53F7\u524D\u6574\u6BB5\uFF0C\u5199\u975E\u6CD5\u952E\u8BFB\u4E0D\u56DE\u6765\uFF09`
|
|
39210
|
+
);
|
|
39211
|
+
}
|
|
39212
|
+
const value = valueParts.join(" ");
|
|
39213
|
+
const localPath = join37(ctx.cwd, ".env.local");
|
|
39214
|
+
const existing = await readFileText(localPath);
|
|
39215
|
+
const replaced = findEnvLine(existing, key) !== void 0;
|
|
39216
|
+
await writeFile17(localPath, upsertEnvLine(existing, key, value), "utf8");
|
|
39217
|
+
const data = { key, file: ".env.local", replaced };
|
|
39218
|
+
command.ok(data, () => [
|
|
39219
|
+
`\u5DF2\u5199\u5165 .env.local\uFF1A${key}\uFF08${replaced ? "\u539F\u503C\u5DF2\u8986\u76D6" : "\u65B0\u589E\u952E"}\uFF1B\u503C\u4E0D\u56DE\u663E\u2014\u2014\u5982\u9700\u786E\u8BA4\u7528 adep env get ${key}\uFF09`,
|
|
39220
|
+
".env.local \u8986\u76D6 .env\uFF1B\u6B63\u5728\u8FD0\u884C\u7684 dev/serve \u9700\u70ED\u91CD\u8F7D\u6216\u91CD\u542F\u540E\u751F\u6548\u3002"
|
|
39221
|
+
]);
|
|
39222
|
+
});
|
|
39223
|
+
});
|
|
39224
|
+
}
|
|
39225
|
+
async function readFileText(path) {
|
|
39226
|
+
return readFile30(path, "utf8").catch(() => "");
|
|
39227
|
+
}
|
|
39228
|
+
function findEnvLine(content, key) {
|
|
39229
|
+
for (const line of content.split(/\r?\n/)) {
|
|
39230
|
+
const trimmed = line.trim();
|
|
39231
|
+
if (trimmed.length === 0 || trimmed.startsWith("#")) continue;
|
|
39232
|
+
const eq = trimmed.indexOf("=");
|
|
39233
|
+
if (eq === -1) continue;
|
|
39234
|
+
if (trimmed.slice(0, eq).trim() === key) return line;
|
|
39235
|
+
}
|
|
39236
|
+
return void 0;
|
|
39237
|
+
}
|
|
39238
|
+
|
|
38295
39239
|
// packages/cli/src/commands/frontend.ts
|
|
38296
39240
|
function registerFrontend(program2, ctx) {
|
|
38297
39241
|
const frontend = program2.command("frontend").description("\u524D\u7AEF\u8349\u7A3F\u7EF4\u62A4\uFF1Async\uFF08\u672C\u5730 web/ \u2192 \u5E73\u53F0\u8349\u7A3F\uFF09");
|
|
@@ -38765,6 +39709,59 @@ function registerHosting(program2, ctx) {
|
|
|
38765
39709
|
});
|
|
38766
39710
|
}
|
|
38767
39711
|
|
|
39712
|
+
// packages/cli/src/commands/logs.ts
|
|
39713
|
+
init_auth();
|
|
39714
|
+
function registerLogs(program2, ctx) {
|
|
39715
|
+
program2.command("logs").description("\u6309 traceId \u67E5\u8BE2\u4E00\u6B21\u8C03\u7528\u94FE\u7684\u65E5\u5FD7\uFF08traceId \u89C1\u9519\u8BEF\u4FE1\u5C01\u6216\u54CD\u5E94\u5934\uFF09").option("--trace <traceId>", "W3C traceId\uFF0832 \u4F4D hex\uFF09").option("--tail <count>", "\u53D6\u6700\u8FD1\u591A\u5C11\u6761\uFF08\u7F3A\u7701 100\uFF0C\u670D\u52A1\u7AEF\u6709\u4E0A\u9650\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (flags) => {
|
|
39716
|
+
const command = ctx.io("logs");
|
|
39717
|
+
await command.run(async () => {
|
|
39718
|
+
const trace = flags.trace?.trim() ?? "";
|
|
39719
|
+
if (trace.length === 0) {
|
|
39720
|
+
throw new CliError("INVALID_ARGUMENT", "\u7F3A\u5C11 --trace\uFF1Aadep logs --trace <traceId>");
|
|
39721
|
+
}
|
|
39722
|
+
const tail = flags.tail === void 0 ? void 0 : Number(flags.tail);
|
|
39723
|
+
if (tail !== void 0 && (!Number.isFinite(tail) || tail <= 0)) {
|
|
39724
|
+
throw new CliError("INVALID_TAIL", `--tail \u987B\u4E3A\u6B63\u6574\u6570\uFF0C\u6536\u5230 "${flags.tail}"`);
|
|
39725
|
+
}
|
|
39726
|
+
const { logsByTrace: logsByTrace2 } = await Promise.resolve().then(() => (init_functions(), functions_exports));
|
|
39727
|
+
const result = await logsByTrace2(ctx.paths, {
|
|
39728
|
+
cwd: ctx.cwd,
|
|
39729
|
+
trace,
|
|
39730
|
+
...tail === void 0 ? {} : { tail },
|
|
39731
|
+
...flags.project === void 0 ? {} : { slug: flags.project }
|
|
39732
|
+
});
|
|
39733
|
+
command.ok(result, (data) => {
|
|
39734
|
+
const r = data;
|
|
39735
|
+
if (r.logs.length === 0) {
|
|
39736
|
+
return `\uFF08trace ${r.traceId} \u6682\u65E0\u65E5\u5FD7\uFF1A\u786E\u8BA4 traceId \u6B63\u786E\uFF0C\u4E14\u8BE5\u8C03\u7528\u53D1\u751F\u5728\u65E5\u5FD7\u7F13\u51B2\u4FDD\u7559\u7A97\u53E3\u5185\uFF09`;
|
|
39737
|
+
}
|
|
39738
|
+
return r.logs.map((log) => `${log.at} [${log.level}] ${log.message}`);
|
|
39739
|
+
});
|
|
39740
|
+
});
|
|
39741
|
+
});
|
|
39742
|
+
}
|
|
39743
|
+
|
|
39744
|
+
// packages/cli/src/commands/rollback.ts
|
|
39745
|
+
function registerRollback(program2, ctx) {
|
|
39746
|
+
program2.command("rollback <fn>").description("\u628A\u5DF2\u53D1\u5E03\u51FD\u6570\u5207\u56DE\u5386\u53F2\u7248\u672C\uFF08\u7248\u672C\u6765\u81EA adep publish \u751F\u6210\u7684\u81EA\u589E\u53F7\uFF09").option("--to <version>", "\u76EE\u6807\u7248\u672C\u53F7\uFF0C\u5982 v2 \u6216 2").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (name, flags) => {
|
|
39747
|
+
const command = ctx.io("rollback");
|
|
39748
|
+
await command.run(async () => {
|
|
39749
|
+
const { parseVersionFlag: parseVersionFlag2, rollbackFunctionTo: rollbackFunctionTo2 } = await Promise.resolve().then(() => (init_rollback(), rollback_exports));
|
|
39750
|
+
const to = parseVersionFlag2(flags.to);
|
|
39751
|
+
const result = await rollbackFunctionTo2(ctx.paths, {
|
|
39752
|
+
cwd: ctx.cwd,
|
|
39753
|
+
name,
|
|
39754
|
+
to,
|
|
39755
|
+
...flags.project === void 0 ? {} : { slug: flags.project }
|
|
39756
|
+
});
|
|
39757
|
+
command.ok(result, (data) => {
|
|
39758
|
+
const r = data;
|
|
39759
|
+
return `\u5DF2\u56DE\u6EDA ${r.name}\uFF1Av${r.from ?? "\u2014"} \u2192 v${r.to}`;
|
|
39760
|
+
});
|
|
39761
|
+
});
|
|
39762
|
+
});
|
|
39763
|
+
}
|
|
39764
|
+
|
|
38768
39765
|
// packages/cli/src/cli.ts
|
|
38769
39766
|
var requireJson = createRequire2(import.meta.url);
|
|
38770
39767
|
var APP_VERSION = requireJson("../package.json").version;
|
|
@@ -38796,10 +39793,13 @@ function buildProgram(options = {}) {
|
|
|
38796
39793
|
registerDb(program2, ctx);
|
|
38797
39794
|
registerFrontend(program2, ctx);
|
|
38798
39795
|
registerStorage(program2, ctx);
|
|
39796
|
+
registerEnv(program2, ctx);
|
|
38799
39797
|
registerDoctor(program2, ctx);
|
|
38800
39798
|
registerAuth(program2, ctx);
|
|
38801
39799
|
registerMcp(program2, ctx);
|
|
38802
39800
|
registerGit(program2, ctx);
|
|
39801
|
+
registerLogs(program2, ctx);
|
|
39802
|
+
registerRollback(program2, ctx);
|
|
38803
39803
|
registerDeploy(program2, ctx);
|
|
38804
39804
|
registerProjects(program2, ctx);
|
|
38805
39805
|
registerFunctions(program2, ctx);
|