@adep/cli 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vite.js CHANGED
@@ -1,4 +1,6 @@
1
1
  // packages/cli/src/vite.ts
2
+ import { existsSync } from "node:fs";
3
+ import { resolve as resolve5 } from "node:path";
2
4
  import { adepPlugin } from "@adep/vite-plugin";
3
5
 
4
6
  // packages/cli/src/dev.ts
@@ -256,6 +258,42 @@ function resolveExecutionDeps(config, projectId, manifestContent) {
256
258
  };
257
259
  }
258
260
 
261
+ // packages/runtime/src/shared/function-timeout.ts
262
+ var TIMEOUT_DECL_RE = /^export const timeoutMs = (\d+)$/;
263
+ function parseDeclaredTimeoutMs(entrySource) {
264
+ for (const rawLine of entrySource.split(/\r?\n/)) {
265
+ const line = rawLine.trim();
266
+ if (line.length === 0 || line.startsWith("//") || line.startsWith("*")) continue;
267
+ if (!line.startsWith("export const timeoutMs")) continue;
268
+ const match = TIMEOUT_DECL_RE.exec(line);
269
+ if (match === null) {
270
+ return {
271
+ value: void 0,
272
+ 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"`
273
+ };
274
+ }
275
+ const value = Number(match[1]);
276
+ if (!Number.isInteger(value) || value <= 0) {
277
+ return {
278
+ value: void 0,
279
+ error: `timeoutMs \u58F0\u660E\u975E\u6CD5\uFF1A"${line}"\uFF08\u987B\u4E3A\u6B63\u6574\u6570\u6BEB\u79D2\uFF09`
280
+ };
281
+ }
282
+ return { value, error: null };
283
+ }
284
+ return { value: void 0, error: null };
285
+ }
286
+ function resolveExecutionBudget(params) {
287
+ const declared = params.declaredMs;
288
+ const declaredField = declared === void 0 ? {} : { declaredMs: declared };
289
+ const base = params.inputTimeoutMs ?? declared ?? DEFAULT_TIMEOUT_MS;
290
+ const ceiling = params.ceilingMs;
291
+ if (ceiling === void 0 || base <= ceiling) {
292
+ return { timeoutMs: base, clamped: false, ...declaredField };
293
+ }
294
+ return { timeoutMs: ceiling, clamped: true, ...declaredField };
295
+ }
296
+
259
297
  // packages/runtime/src/functions/runtime/worker-executor.ts
260
298
  function resolveWorkerEntry(baseDir = fileURLToPath(new URL(".", import.meta.url))) {
261
299
  const candidates = [
@@ -296,17 +334,36 @@ function rpcReply(worker, id, ok, payload) {
296
334
  var WorkerFunctionExecutor = class {
297
335
  depsConfig;
298
336
  fetchConfig;
337
+ parity;
338
+ timeoutMaxMs;
299
339
  constructor(options = {}) {
300
340
  this.depsConfig = options.deps;
301
341
  this.fetchConfig = options.fetch;
342
+ this.parity = options.parity === true;
343
+ this.timeoutMaxMs = options.timeoutMaxMs;
302
344
  }
303
345
  async execute(input) {
304
- const timeoutMs = input.timeoutMs ?? DEFAULT_TIMEOUT_MS;
305
- const memoryLimitMb = input.memoryLimitMb ?? DEFAULT_MEMORY_LIMIT_MB;
306
346
  const entry = input.entry ?? resolveDraftEntry(input.fn.name, input.files) ?? "index.ts";
347
+ const declared = parseDeclaredTimeoutMs(input.files[entry] ?? "");
348
+ if (declared.error !== null) {
349
+ throw new ExecutorError(400, "FN_EXEC_TIMEOUT_DECL_INVALID", declared.error);
350
+ }
351
+ const budget = resolveExecutionBudget({
352
+ inputTimeoutMs: input.timeoutMs,
353
+ declaredMs: declared.value,
354
+ ceilingMs: this.timeoutMaxMs
355
+ });
356
+ const timeoutMs = budget.timeoutMs;
357
+ const memoryLimitMb = input.memoryLimitMb ?? DEFAULT_MEMORY_LIMIT_MB;
307
358
  const deps = this.depsConfig === void 0 ? void 0 : resolveExecutionDeps(this.depsConfig, input.project.id, input.files["package.json"]);
359
+ const effectiveFetchConfig = this.fetchConfig === void 0 ? void 0 : input.fetchAllowlist === void 0 ? this.fetchConfig : { ...this.fetchConfig, allowlist: input.fetchAllowlist };
308
360
  const logs = [];
309
- return new Promise((resolve5, reject) => {
361
+ if (budget.clamped) {
362
+ logs.push(
363
+ `[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`
364
+ );
365
+ }
366
+ return new Promise((resolve6, reject) => {
310
367
  let worker;
311
368
  try {
312
369
  worker = new Worker(resolveWorkerEntry(), {
@@ -317,7 +374,8 @@ var WorkerFunctionExecutor = class {
317
374
  capabilities: input.capabilities ?? [],
318
375
  ...input.env === void 0 ? {} : { env: input.env },
319
376
  ...deps === void 0 ? {} : { deps },
320
- ...this.fetchConfig === void 0 ? {} : { fetch: this.fetchConfig }
377
+ ...this.parity ? { parity: true } : {},
378
+ ...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig }
321
379
  },
322
380
  resourceLimits: { maxOldGenerationSizeMb: memoryLimitMb }
323
381
  });
@@ -368,7 +426,7 @@ var WorkerFunctionExecutor = class {
368
426
  if (message.type === "result") {
369
427
  clearTimeout(timer);
370
428
  void worker.terminate();
371
- resolve5({ body: message.body, logs });
429
+ resolve6({ body: message.body, logs });
372
430
  return;
373
431
  }
374
432
  if (message.type === "error") {
@@ -465,10 +523,10 @@ function assertSafeStatement(sql) {
465
523
  if (stripped.includes(";")) {
466
524
  throw unsafeOperation("\u4EC5\u5141\u8BB8\u5355\u6761\u8BED\u53E5\uFF0C\u7981\u6B62\u591A\u8BED\u53E5\u5806\u53E0");
467
525
  }
468
- if (/ATTACH|DETACH/.test(stripped.toUpperCase())) {
526
+ if (/\b(ATTACH|DETACH)\b/.test(stripped.toUpperCase())) {
469
527
  throw unsafeOperation("\u7981\u6B62\u8DE8\u5E93\u64CD\u4F5C\uFF08ATTACH / DETACH\uFF09");
470
528
  }
471
- if (/SQLITE_\w+/i.test(stripped)) {
529
+ if (/\bSQLITE_\w+/i.test(stripped)) {
472
530
  throw unsafeOperation("\u7981\u6B62\u8BBF\u95EE\u7CFB\u7EDF\u8868\uFF08sqlite_*\uFF09");
473
531
  }
474
532
  return sqlHead(stripped);
@@ -1601,10 +1659,10 @@ function assertReadOnly(sql) {
1601
1659
  if (!head.startsWith("SELECT") && !head.startsWith("WITH")) {
1602
1660
  throw new SimDbError("DB_UNSAFE_OP", "cloud.db.query \u4EC5\u5141\u8BB8\u53EA\u8BFB\u67E5\u8BE2\uFF08SELECT / WITH\uFF09");
1603
1661
  }
1604
- if (/ATTACH|DETACH/.test(stripped.toUpperCase())) {
1662
+ if (/\b(ATTACH|DETACH)\b/.test(stripped.toUpperCase())) {
1605
1663
  throw new SimDbError("DB_UNSAFE_OP", "\u7981\u6B62\u8DE8\u5E93\u64CD\u4F5C\uFF08ATTACH / DETACH\uFF09");
1606
1664
  }
1607
- if (/SQLITE_\w+/i.test(stripped) && !/SQLITE_MASTER\b/i.test(stripped)) {
1665
+ if (/\bSQLITE_\w+/i.test(stripped) && !/SQLITE_MASTER\b/i.test(stripped)) {
1608
1666
  throw new SimDbError("DB_UNSAFE_OP", "\u7981\u6B62\u8BBF\u95EE\u7CFB\u7EDF\u8868\uFF08sqlite_*\uFF09");
1609
1667
  }
1610
1668
  }
@@ -2593,7 +2651,7 @@ function createSimStorageCapability(options) {
2593
2651
  baseUrl: options.baseUrl ?? "http://127.0.0.1:8787"
2594
2652
  };
2595
2653
  const bundle = createStorageCapability(driver, signer, options.projectId ?? "sim-project");
2596
- return { bundle, driver };
2654
+ return { bundle, driver, signer };
2597
2655
  }
2598
2656
 
2599
2657
  // packages/runtime/src/sim/realtime.ts
@@ -2842,6 +2900,169 @@ function splitSqlStatements(source) {
2842
2900
  return statements;
2843
2901
  }
2844
2902
 
2903
+ // packages/runtime/src/shared/schema-diff.ts
2904
+ function quoteIdent(name) {
2905
+ return `"${name.replaceAll('"', '""')}"`;
2906
+ }
2907
+ function unquoteIdent(raw) {
2908
+ const text = raw.trim();
2909
+ if (text.length >= 2) {
2910
+ const first = text[0];
2911
+ const last = text[text.length - 1];
2912
+ if (first === '"' && last === '"' || first === "`" && last === "`") {
2913
+ return text.slice(1, -1).replaceAll(first + first, first);
2914
+ }
2915
+ if (first === "[" && last === "]") return text.slice(1, -1);
2916
+ if (first === "'" && last === "'") return text.slice(1, -1).replaceAll("''", "'");
2917
+ }
2918
+ return text;
2919
+ }
2920
+ function splitTopLevel2(body) {
2921
+ const parts = [];
2922
+ let depth = 0;
2923
+ let quote = null;
2924
+ let start = 0;
2925
+ for (let index = 0; index < body.length; index += 1) {
2926
+ const char = body[index];
2927
+ if (quote !== null) {
2928
+ if (char === quote) {
2929
+ if (body[index + 1] === quote) index += 1;
2930
+ else quote = null;
2931
+ }
2932
+ continue;
2933
+ }
2934
+ if (char === '"' || char === "`" || char === "'") {
2935
+ quote = char;
2936
+ continue;
2937
+ }
2938
+ if (char === "[") {
2939
+ quote = "]";
2940
+ continue;
2941
+ }
2942
+ if (char === "(") depth += 1;
2943
+ else if (char === ")") depth -= 1;
2944
+ else if (char === "," && depth === 0) {
2945
+ parts.push(body.slice(start, index));
2946
+ start = index + 1;
2947
+ }
2948
+ }
2949
+ parts.push(body.slice(start));
2950
+ return parts.map((part) => part.trim()).filter((part) => part.length > 0);
2951
+ }
2952
+ function findTableBody(statement, openIndex) {
2953
+ let depth = 0;
2954
+ let quote = null;
2955
+ for (let index = openIndex; index < statement.length; index += 1) {
2956
+ const char = statement[index];
2957
+ if (quote !== null) {
2958
+ if (char === quote) {
2959
+ if (statement[index + 1] === quote) index += 1;
2960
+ else quote = null;
2961
+ }
2962
+ continue;
2963
+ }
2964
+ if (char === '"' || char === "`" || char === "'") {
2965
+ quote = char;
2966
+ continue;
2967
+ }
2968
+ if (char === "[") {
2969
+ quote = "]";
2970
+ continue;
2971
+ }
2972
+ if (char === "(") depth += 1;
2973
+ else if (char === ")") {
2974
+ depth -= 1;
2975
+ if (depth === 0) return statement.slice(openIndex + 1, index);
2976
+ }
2977
+ }
2978
+ return null;
2979
+ }
2980
+ var TABLE_CONSTRAINTS = /* @__PURE__ */ new Set(["CONSTRAINT", "PRIMARY", "UNIQUE", "FOREIGN", "CHECK", "KEY", "EXCLUDE"]);
2981
+ var COLUMN_CONSTRAINTS = [
2982
+ "NOT",
2983
+ "NULL",
2984
+ "DEFAULT",
2985
+ "PRIMARY",
2986
+ "UNIQUE",
2987
+ "CHECK",
2988
+ "REFERENCES",
2989
+ "COLLATE",
2990
+ "GENERATED",
2991
+ "AS",
2992
+ "AUTOINCREMENT",
2993
+ "CONSTRAINT"
2994
+ ];
2995
+ function parseColumn(part) {
2996
+ const nameMatch = /^("(?:[^"]|"")*"|`(?:[^`]|``)*`|\[[^\]]*\]|'[^']*'|[A-Za-z_][A-Za-z0-9_$]*)/.exec(
2997
+ part.trim()
2998
+ );
2999
+ if (nameMatch === null) return null;
3000
+ const name = unquoteIdent(nameMatch[1]);
3001
+ const head = nameMatch[1].toUpperCase();
3002
+ if (TABLE_CONSTRAINTS.has(head)) return null;
3003
+ let rest = part.trim().slice(nameMatch[1].length).trim();
3004
+ if (TABLE_CONSTRAINTS.has(name.toUpperCase()) && rest.startsWith("(")) return null;
3005
+ const upperRest = rest.toUpperCase();
3006
+ let typeEnd = rest.length;
3007
+ for (const keyword of COLUMN_CONSTRAINTS) {
3008
+ const match = new RegExp(`\\b${keyword}\\b`).exec(upperRest);
3009
+ if (match !== null && match.index < typeEnd) typeEnd = match.index;
3010
+ }
3011
+ const type = rest.slice(0, typeEnd).trim();
3012
+ rest = rest.slice(typeEnd).trim();
3013
+ const notNull = /\bNOT\s+NULL\b/i.test(rest);
3014
+ const primaryKey = /\bPRIMARY\s+KEY\b/i.test(rest);
3015
+ const defaultMatch = /\bDEFAULT\s+(.+?)(?=\s+(?:NOT|PRIMARY|UNIQUE|CHECK|REFERENCES|COLLATE|GENERATED|AS|AUTOINCREMENT|CONSTRAINT)\b|$)/i.exec(
3016
+ rest
3017
+ );
3018
+ return {
3019
+ name,
3020
+ type,
3021
+ notNull,
3022
+ primaryKey,
3023
+ defaultValue: defaultMatch === null ? null : defaultMatch[1].trim()
3024
+ };
3025
+ }
3026
+ function parseSchemaTables(sql) {
3027
+ const tables = [];
3028
+ const pattern = /CREATE\s+(?:TEMP|TEMPORARY\s+)?TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?("(?:[^"]|"")*"|`(?:[^`]|``)*`|\[[^\]]*\]|'[^']*'|[A-Za-z_][A-Za-z0-9_$.]*)\s*\(/gi;
3029
+ for (const statement of splitSqlStatements(sql)) {
3030
+ const match = pattern.exec(statement);
3031
+ pattern.lastIndex = 0;
3032
+ if (match === null) continue;
3033
+ const openIndex = match.index + match[0].length - 1;
3034
+ const body = findTableBody(statement, openIndex);
3035
+ if (body === null) continue;
3036
+ const rawName = match[1];
3037
+ const name = unquoteIdent(rawName.split(".").pop() ?? rawName);
3038
+ const columns = [];
3039
+ for (const part of splitTopLevel2(body)) {
3040
+ const column = parseColumn(part);
3041
+ if (column !== null) columns.push(column);
3042
+ }
3043
+ tables.push({ name, columns, statement: statement.trim() });
3044
+ }
3045
+ return tables;
3046
+ }
3047
+ function planMissingColumn(table, column) {
3048
+ const base = `ALTER TABLE ${quoteIdent(table)} ADD COLUMN ${quoteIdent(column.name)}`;
3049
+ let blocked = null;
3050
+ if (column.primaryKey) {
3051
+ 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`;
3052
+ } else if (column.notNull && column.defaultValue === null) {
3053
+ 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`;
3054
+ }
3055
+ const type = column.type.length === 0 ? "" : ` ${column.type}`;
3056
+ const notNull = column.notNull && column.defaultValue !== null ? " NOT NULL" : "";
3057
+ const fallback = column.defaultValue === null ? "" : ` DEFAULT ${column.defaultValue}`;
3058
+ return {
3059
+ table,
3060
+ column,
3061
+ sql: `${base}${type}${notNull}${fallback}`,
3062
+ blocked
3063
+ };
3064
+ }
3065
+
2845
3066
  // packages/cli/src/serve/sqlite-driver.ts
2846
3067
  import { mkdir as mkdir3 } from "node:fs/promises";
2847
3068
  import { dirname as dirname4, resolve as resolve2 } from "node:path";
@@ -3000,6 +3221,51 @@ async function openLocalDbDriver(target, options) {
3000
3221
  return { mode: "sim", file: null, module: null, driver: null };
3001
3222
  }
3002
3223
  }
3224
+ async function detectMissingColumns(driver, schemaSource, options) {
3225
+ const { mode, tag, log } = options;
3226
+ if (mode !== "sqlite") {
3227
+ log(
3228
+ `[${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`
3229
+ );
3230
+ return null;
3231
+ }
3232
+ const declared = parseSchemaTables(schemaSource);
3233
+ const missing = [];
3234
+ for (const table of declared) {
3235
+ const rows = await driver.all(`SELECT name FROM pragma_table_info(?)`, [table.name]);
3236
+ if (rows.length === 0) continue;
3237
+ const liveNames = new Set(rows.map((row) => String(row["name"] ?? "")));
3238
+ for (const column of table.columns) {
3239
+ if (!liveNames.has(column.name)) missing.push(planMissingColumn(table.name, column));
3240
+ }
3241
+ }
3242
+ if (missing.length === 0) return { missing: [], fixed: [] };
3243
+ const fixable = missing.filter((plan) => plan.blocked === null);
3244
+ const blocked = missing.filter((plan) => plan.blocked !== null);
3245
+ for (const plan of fixable) {
3246
+ log(
3247
+ `[${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`
3248
+ );
3249
+ }
3250
+ for (const plan of blocked) {
3251
+ log(`[${tag}] \u8B66\u544A\uFF1A\u5B58\u91CF\u8868 "${plan.table}" \u7F3A\u5C11\u5217 "${plan.column.name}"\u2014\u2014${plan.blocked}`);
3252
+ }
3253
+ const fixed = [];
3254
+ if (options.fix) {
3255
+ for (const plan of fixable) {
3256
+ await driver.run(plan.sql);
3257
+ fixed.push(`${plan.table}.${plan.column.name}`);
3258
+ log(`[${tag}] \u5DF2\u81EA\u52A8\u8865\u5217\uFF1A${plan.table}.${plan.column.name}\uFF08--schema-fix\uFF09`);
3259
+ }
3260
+ }
3261
+ const unresolved = options.fix ? blocked.length : missing.length;
3262
+ if (unresolved > 0) {
3263
+ log(
3264
+ `[${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`
3265
+ );
3266
+ }
3267
+ return { missing, fixed };
3268
+ }
3003
3269
  async function applyLocalSchema(driver, options) {
3004
3270
  const { schemaFile, mode, tag, cwd, log } = options;
3005
3271
  const schemaPath = resolve3(cwd, schemaFile);
@@ -3033,6 +3299,14 @@ async function applyLocalSchema(driver, options) {
3033
3299
  }
3034
3300
  const skipNote = skipped > 0 ? `\uFF0C\u8DF3\u8FC7 ${skipped} \u6761` : "";
3035
3301
  log(`[${tag}] \u5DF2\u5E94\u7528\u6570\u636E\u5E93\u7ED3\u6784\uFF08--schema ${schemaFile}\uFF09\uFF1A${applied} \u6761\u8BED\u53E5${skipNote}`);
3302
+ const drift = await detectMissingColumns(driver, schemaSource, {
3303
+ cwd,
3304
+ tag,
3305
+ log,
3306
+ mode,
3307
+ fix: options.schemaFix === true
3308
+ });
3309
+ return { applied, skipped, drift };
3036
3310
  }
3037
3311
 
3038
3312
  // packages/runtime/src/shared/fetch-blocked-ports.ts
@@ -3130,7 +3404,7 @@ function isFetchBlockedPort(port) {
3130
3404
  // packages/cli/src/serve/fetch-safe-port.ts
3131
3405
  var MAX_FETCH_SAFE_LISTEN_ATTEMPTS = 8;
3132
3406
  function listenOnce(server, port, host) {
3133
- return new Promise((resolve5, reject) => {
3407
+ return new Promise((resolve6, reject) => {
3134
3408
  const onError = (error) => {
3135
3409
  server.off("error", onError);
3136
3410
  reject(error);
@@ -3138,13 +3412,13 @@ function listenOnce(server, port, host) {
3138
3412
  server.once("error", onError);
3139
3413
  server.listen(port, host, () => {
3140
3414
  server.off("error", onError);
3141
- resolve5();
3415
+ resolve6();
3142
3416
  });
3143
3417
  });
3144
3418
  }
3145
3419
  function closeServer(server) {
3146
- return new Promise((resolve5, reject) => {
3147
- server.close((error) => error === void 0 ? resolve5() : reject(error));
3420
+ return new Promise((resolve6, reject) => {
3421
+ server.close((error) => error === void 0 ? resolve6() : reject(error));
3148
3422
  });
3149
3423
  }
3150
3424
  async function closeQuietly(server) {
@@ -4269,6 +4543,14 @@ function resolveModulePath(fromDir, request, files) {
4269
4543
  }
4270
4544
  return null;
4271
4545
  }
4546
+ function escapesFunctionRoot(fromDir, request) {
4547
+ const depth = fromDir.split("/").filter((part) => part.length > 0).length;
4548
+ let ups = 0;
4549
+ for (const part of request.split("/")) {
4550
+ if (part === "..") ups += 1;
4551
+ }
4552
+ return ups > depth;
4553
+ }
4272
4554
  function joinPosix(dir, request) {
4273
4555
  const parts = [...dir.split("/"), ...request.split("/")];
4274
4556
  const stack = [];
@@ -4297,7 +4579,7 @@ function syntaxErrorWithLocation(error, path) {
4297
4579
  if (typeof code === "string") wrapped.code = code;
4298
4580
  return wrapped;
4299
4581
  }
4300
- function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache) {
4582
+ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false) {
4301
4583
  const cached = cache.get(path);
4302
4584
  if (cached !== void 0) return cached;
4303
4585
  const source = files[path];
@@ -4309,9 +4591,16 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache)
4309
4591
  const dir = path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "";
4310
4592
  const module = { exports, default: void 0 };
4311
4593
  const require2 = (request) => {
4594
+ if (strictPaths && request.startsWith("../") && escapesFunctionRoot(dir, request)) {
4595
+ const error2 = new Error(
4596
+ `\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`
4597
+ );
4598
+ error2.code = "FN_SANDBOX_ESCAPE_BLOCKED";
4599
+ throw error2;
4600
+ }
4312
4601
  const resolved = resolveModulePath(dir, request, files);
4313
4602
  if (resolved !== null) {
4314
- return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache);
4603
+ return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths);
4315
4604
  }
4316
4605
  if (resolveBare !== void 0 && !request.startsWith("./") && !request.startsWith("../")) {
4317
4606
  const cachedModule = bareCache?.get(request);
@@ -4350,10 +4639,18 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache)
4350
4639
  }
4351
4640
  return exports;
4352
4641
  }
4353
- function loadFunctionModule(files, entry, sandboxGlobals, resolveBare) {
4642
+ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false) {
4354
4643
  const cache = /* @__PURE__ */ new Map();
4355
4644
  const bareCache = /* @__PURE__ */ new Map();
4356
- const entryExports = loadModule(entry, files, sandboxGlobals, cache, resolveBare, bareCache);
4645
+ const entryExports = loadModule(
4646
+ entry,
4647
+ files,
4648
+ sandboxGlobals,
4649
+ cache,
4650
+ resolveBare,
4651
+ bareCache,
4652
+ strictPaths
4653
+ );
4357
4654
  const handler = entryExports["default"];
4358
4655
  if (typeof handler !== "function") {
4359
4656
  throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570`);
@@ -4758,8 +5055,8 @@ function isRpcCapability(value) {
4758
5055
  function createRpcClient(capability, port, pending, nextId) {
4759
5056
  return createFlatRpcProxy((method, args) => {
4760
5057
  const id = nextId();
4761
- return new Promise((resolve5, reject) => {
4762
- pending.set(id, { resolve: resolve5, reject });
5058
+ return new Promise((resolve6, reject) => {
5059
+ pending.set(id, { resolve: resolve6, reject });
4763
5060
  port.postMessage({ type: "rpc", id, capability, method, args });
4764
5061
  });
4765
5062
  });
@@ -4869,9 +5166,9 @@ function isChainCapability(value) {
4869
5166
  return typeof spec === "object" && spec !== null && Array.isArray(spec.stepMethods) && Array.isArray(spec.terminalMethods);
4870
5167
  }
4871
5168
  function createChainClient(capability, port, pending, nextId, spec) {
4872
- const call = (method, args) => new Promise((resolve5, reject) => {
5169
+ const call = (method, args) => new Promise((resolve6, reject) => {
4873
5170
  const id = nextId();
4874
- pending.set(id, { resolve: resolve5, reject });
5171
+ pending.set(id, { resolve: resolve6, reject });
4875
5172
  port.postMessage({ type: "rpc", id, capability, method, args });
4876
5173
  });
4877
5174
  const makeChainable = (rootArgs, steps, txId) => new Proxy(
@@ -5062,9 +5359,14 @@ function runWorker(input, port) {
5062
5359
  performance,
5063
5360
  atob,
5064
5361
  btoa,
5065
- structuredClone
5362
+ structuredClone,
5363
+ // CORE-154:定时器家族(纯本地定时,无出网/句柄面;清单见 SANDBOX_GLOBAL_KEYS 钉测面)。
5364
+ setTimeout,
5365
+ clearTimeout,
5366
+ setInterval,
5367
+ clearInterval
5066
5368
  };
5067
- if (input.env !== void 0) {
5369
+ if (input.env !== void 0 && input.parity !== true) {
5068
5370
  sandboxGlobals["process"] = realmValue({ env: input.env });
5069
5371
  }
5070
5372
  if (input.fetch !== void 0) {
@@ -5092,7 +5394,9 @@ function runWorker(input, port) {
5092
5394
  input.files,
5093
5395
  input.entry,
5094
5396
  sandboxGlobals,
5095
- input.deps === void 0 ? void 0 : createBareResolver(input.deps)
5397
+ input.deps === void 0 ? void 0 : createBareResolver(input.deps),
5398
+ // CORE-154:--parity 严格模式连带 `../` 越根引用报错(与容器形态真实 fs 同形)。
5399
+ input.parity === true
5096
5400
  );
5097
5401
  const result = Promise.resolve(handler(ctx));
5098
5402
  void result.then(
@@ -5267,9 +5571,12 @@ function parseMultipart(contentType, raw) {
5267
5571
  // packages/cli/src/dev-shared.ts
5268
5572
  var BEARER_TOKEN_RE = /^Bearer\s+(.+)$/i;
5269
5573
  function bearerUserResolverFromEnv(fileEnv = {}) {
5270
- const raw = firstNonEmpty(process.env.ADEP_AUTH_ISSUER, fileEnv.ADEP_AUTH_ISSUER);
5574
+ const raw = resolveEffectiveIssuer(fileEnv);
5271
5575
  return raw === void 0 ? void 0 : createBearerUserResolver(raw);
5272
5576
  }
5577
+ function resolveEffectiveIssuer(fileEnv = {}) {
5578
+ return firstNonEmpty(process.env.ADEP_AUTH_ISSUER, fileEnv.ADEP_AUTH_ISSUER);
5579
+ }
5273
5580
  function firstNonEmpty(...values) {
5274
5581
  for (const value of values) {
5275
5582
  const trimmed = value?.trim();
@@ -5777,10 +6084,28 @@ import {
5777
6084
  normalizeFunctionPrefix,
5778
6085
  PREVIEW_AUTOMATION_SCRIPT
5779
6086
  } from "@adep/vite-plugin";
5780
- var createDevServer = (opts) => startDevServer({ cwd: opts.cwd, port: opts.port, prefix: opts.prefix, log: opts.log });
6087
+ var createDevServer = (opts) => startDevServer({
6088
+ cwd: opts.cwd,
6089
+ port: opts.port,
6090
+ prefix: opts.prefix,
6091
+ log: opts.log,
6092
+ ...opts.schemaFile === void 0 ? {} : { schemaFile: opts.schemaFile }
6093
+ });
5781
6094
  var loadConfig2 = (cwd) => loadAdepConfigModule(cwd);
6095
+ function resolveLocalSchemaFile(cwd, configured) {
6096
+ if (configured === false) return void 0;
6097
+ if (typeof configured === "string") return configured;
6098
+ return existsSync(resolve5(cwd, "database/schema.sql")) ? "database/schema.sql" : void 0;
6099
+ }
5782
6100
  function adepVitePlugin(options = {}) {
5783
- return adepPlugin({ ...options, createDevServer, loadConfig: loadConfig2 });
6101
+ const cwd = options.cwd ?? process.cwd();
6102
+ const schemaFile = resolveLocalSchemaFile(cwd, options.schemaFile);
6103
+ return adepPlugin({
6104
+ ...options,
6105
+ ...schemaFile === void 0 ? {} : { schemaFile },
6106
+ createDevServer,
6107
+ loadConfig: loadConfig2
6108
+ });
5784
6109
  }
5785
6110
  var vite_default = adepVitePlugin;
5786
6111
  export {
@@ -5794,5 +6119,6 @@ export {
5794
6119
  injectAutomationScriptTag,
5795
6120
  injectFnProxyScriptTag,
5796
6121
  isAddrInUse,
5797
- normalizeFunctionPrefix
6122
+ normalizeFunctionPrefix,
6123
+ resolveLocalSchemaFile
5798
6124
  };