@adep/cli 0.5.6 → 0.5.8

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/index.js CHANGED
@@ -26,6 +26,9 @@ function resolvePaths(env = process.env) {
26
26
  function resolveServer(env = process.env) {
27
27
  return (env["ADEP_SERVER"] ?? "https://adep.top").replace(/\/+$/, "");
28
28
  }
29
+ function normalizeFunctionsPrefix(prefix) {
30
+ return prefix.replace(/^\/+|\/+$/g, "");
31
+ }
29
32
  function resolveElectronMirror(env = process.env) {
30
33
  return env["ELECTRON_MIRROR"] ?? DEFAULT_ELECTRON_MIRROR;
31
34
  }
@@ -1298,7 +1301,9 @@ var init_worker_executor = __esm({
1298
1301
  ...input2.env === void 0 ? {} : { env: input2.env },
1299
1302
  ...deps === void 0 ? {} : { deps },
1300
1303
  ...this.parity ? { parity: true } : {},
1301
- ...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig }
1304
+ ...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig },
1305
+ // W2:预编译提示随 workerData 下发(结构化克隆可跨线程;缺省不传 = 全量编译路径)。
1306
+ ...input2.compileHints === void 0 ? {} : { compileHints: input2.compileHints }
1302
1307
  },
1303
1308
  resourceLimits: { maxOldGenerationSizeMb: memoryLimitMb }
1304
1309
  });
@@ -1397,14 +1402,14 @@ var init_dialect = __esm({
1397
1402
  placeholder: () => "?",
1398
1403
  quote: (identifier) => `"${identifier.replace(/"/g, '""')}"`,
1399
1404
  lastInsertIdClause: () => "",
1400
- upsertConflictClause: (columns) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")}) DO NOTHING`
1405
+ upsertConflictClause: (columns, doUpdateSet) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")})` + (doUpdateSet ? ` DO UPDATE SET ${doUpdateSet}` : " DO NOTHING")
1401
1406
  };
1402
1407
  postgresDialect = {
1403
1408
  name: "postgres",
1404
1409
  placeholder: (index) => `$${index + 1}`,
1405
1410
  quote: (identifier) => `"${identifier.replace(/"/g, '""')}"`,
1406
1411
  lastInsertIdClause: () => " RETURNING id",
1407
- upsertConflictClause: (columns) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")}) DO NOTHING`
1412
+ upsertConflictClause: (columns, doUpdateSet) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")})` + (doUpdateSet ? ` DO UPDATE SET ${doUpdateSet}` : " DO NOTHING")
1408
1413
  };
1409
1414
  }
1410
1415
  });
@@ -1544,6 +1549,17 @@ async function appendChange(driver, table, op, id, ownerKey, before, after) {
1544
1549
  );
1545
1550
  }
1546
1551
  async function runOwnedWrite(driver, fn) {
1552
+ if (driver.engine === "pg") {
1553
+ await driver.run("BEGIN");
1554
+ try {
1555
+ await fn(driver);
1556
+ await driver.run("COMMIT");
1557
+ } catch (error62) {
1558
+ await driver.run("ROLLBACK");
1559
+ throw error62;
1560
+ }
1561
+ return;
1562
+ }
1547
1563
  await driver.run("SAVEPOINT _adep_change");
1548
1564
  try {
1549
1565
  await fn(driver);
@@ -1734,6 +1750,9 @@ function compileWhere(wheres, dialect, params) {
1734
1750
  if (value === null) {
1735
1751
  if (where.operator === "=") return `${quoted} IS NULL`;
1736
1752
  if (where.operator === "!=") return `${quoted} IS NOT NULL`;
1753
+ throw unsafeOperation(
1754
+ `NULL \u53EA\u80FD\u4E0E = / != \u6BD4\u8F83\uFF08${where.operator} NULL \u6052\u4E3A UNKNOWN\uFF0C\u4F1A\u9759\u9ED8\u8FD4\u56DE\u7A7A\u96C6\uFF09\uFF1A\u5217 ${where.column}`
1755
+ );
1737
1756
  }
1738
1757
  const mark = pushParam(params, dialect, value);
1739
1758
  return `${quoted} ${where.operator} ${mark}`;
@@ -1808,6 +1827,44 @@ function compileInsertMany(table, rows, dialect) {
1808
1827
  params
1809
1828
  };
1810
1829
  }
1830
+ function resolveUpsertPlan(row, options) {
1831
+ const target = [...options.target];
1832
+ if (target.length === 0) {
1833
+ throw unsafeOperation("upsert \u7684 target \u5FC5\u987B\u81F3\u5C11\u4E00\u5217\uFF08\u51B2\u7A81\u5224\u5B9A\u65E0\u5217\u5219\u65E0\u4ECE\u8C08\u8D77\uFF09");
1834
+ }
1835
+ target.forEach(assertUserColumn);
1836
+ const targetSet = new Set(target);
1837
+ const rowColumns = new Set(Object.keys(row));
1838
+ if (rowColumns.size === 0) {
1839
+ throw unsafeOperation("upsert \u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u5B57\u6BB5");
1840
+ }
1841
+ const update = options.update === void 0 ? [...rowColumns].filter((name) => !targetSet.has(name)) : [...options.update];
1842
+ update.forEach(assertUserColumn);
1843
+ const overlapping = update.filter((name) => targetSet.has(name));
1844
+ if (overlapping.length > 0) {
1845
+ throw unsafeOperation(`upsert \u7684 update \u5217\u4E0D\u80FD\u4E0E target \u91CD\u53E0\uFF08\u51B2\u7A81\u884C\u4E3B\u952E\u4E0D\u6539\uFF09\uFF1A${overlapping.join(", ")}`);
1846
+ }
1847
+ const missing = update.filter((name) => !rowColumns.has(name));
1848
+ if (missing.length > 0) {
1849
+ throw unsafeOperation(`upsert \u7684 update \u5217\u5FC5\u987B\u51FA\u73B0\u5728 row \u4E2D\uFF08\u503C\u53D6\u81EA row\uFF09\uFF1A${missing.join(", ")}`);
1850
+ }
1851
+ return { target, update };
1852
+ }
1853
+ function compileUpsert(table, row, options, dialect) {
1854
+ const { target, update } = resolveUpsertPlan(row, options);
1855
+ const params = [];
1856
+ const entries = Object.entries(row);
1857
+ const columns = entries.map(([name]) => {
1858
+ assertUserColumn(name);
1859
+ return dialect.quote(name);
1860
+ }).join(", ");
1861
+ const marks = entries.map(([, value]) => pushParam(params, dialect, value));
1862
+ const doUpdateSet = update.length === 0 ? null : update.map((name) => `${dialect.quote(name)} = ${pushParam(params, dialect, row[name])}`).join(", ");
1863
+ return {
1864
+ sql: `INSERT INTO ${dialect.quote(table)} (${columns}) VALUES (${marks.join(", ")})${dialect.upsertConflictClause(target, doUpdateSet)}`,
1865
+ params
1866
+ };
1867
+ }
1811
1868
  function compileUpdate(table, wheres, values, dialect) {
1812
1869
  const entries = Object.entries(values);
1813
1870
  if (entries.length === 0) {
@@ -1948,6 +2005,17 @@ function createTableBuilder(table, driver, dialect, options = {}) {
1948
2005
  const compiled = compileInsertMany(state.table, rows, dialect);
1949
2006
  await driver.run(compiled.sql, compiled.params);
1950
2007
  },
2008
+ async upsert(row, conflict) {
2009
+ guardWrite();
2010
+ Object.keys(row).forEach(assertUserColumn);
2011
+ if (await resolveOwned(state, driver)) {
2012
+ throw unsafeOperation(
2013
+ "upsert \u4E0D\u652F\u6301 owned \u8868\uFF1A\u53D8\u66F4\u6D41\u65E0\u6CD5\u8868\u8FBE\u300C\u63D2\u5165\u8FD8\u662F\u66F4\u65B0\u300D\u7684\u4E8C\u4E49\uFF08before/after \u987B\u786E\u5B9A\uFF09\uFF0C\u8BF7\u6539\u7528 insert / update"
2014
+ );
2015
+ }
2016
+ const compiled = compileUpsert(state.table, row, conflict, dialect);
2017
+ await driver.run(compiled.sql, compiled.params);
2018
+ },
1951
2019
  async update(values) {
1952
2020
  guardWrite();
1953
2021
  assertHasWhere(state);
@@ -2240,13 +2308,23 @@ var init_cloud = __esm({
2240
2308
  CLOUD_DB_SPEC = {
2241
2309
  kind: "cloud-db",
2242
2310
  rootMethod: "table",
2243
- stepMethods: ["select", "where", "orderBy", "limit", "offset"],
2244
- terminalMethods: ["get", "first", "count", "insert", "insertMany", "update", "delete"],
2311
+ // 规格清单必须与构建器公开方法面一致(防漂移门 spec-drift.test.ts 双向咬合):
2312
+ // - owned:DB-006 的 owned 声明(step);
2313
+ // - execute:BUG-4 统一执行入口(direct,宿主侧 DB_RPC.execute 分支早已在);
2314
+ // - upsert:DB-010 终端(漏登记过一次,真机 500,见 spec-drift.test.ts 头注释)。
2315
+ stepMethods: ["select", "where", "orderBy", "limit", "offset", "owned"],
2316
+ terminalMethods: ["get", "first", "count", "insert", "insertMany", "update", "delete", "upsert"],
2245
2317
  // CF-013:writeQuery 是 D1 shim 的写路径(INSERT/UPDATE/DELETE),与 query 并列直通方法。
2246
- directMethods: ["query", "writeQuery", "changes"],
2318
+ directMethods: ["query", "writeQuery", "execute", "changes"],
2247
2319
  transactionMethod: "transaction"
2248
2320
  };
2249
- WRITE_TERMINALS = /* @__PURE__ */ new Set(["insert", "insertMany", "update", "delete"]);
2321
+ WRITE_TERMINALS = /* @__PURE__ */ new Set([
2322
+ "insert",
2323
+ "insertMany",
2324
+ "update",
2325
+ "delete",
2326
+ "upsert"
2327
+ ]);
2250
2328
  }
2251
2329
  });
2252
2330
 
@@ -5273,9 +5351,14 @@ function runLsof(port) {
5273
5351
  );
5274
5352
  });
5275
5353
  }
5354
+ function defaultOccupierExecutor(port) {
5355
+ if (process.platform === "win32") {
5356
+ return Promise.reject(new Error("lsof unavailable on win32"));
5357
+ }
5358
+ return runLsof(port);
5359
+ }
5276
5360
  async function lookupPortOccupier(port, options = {}) {
5277
- if (process.platform === "win32") return null;
5278
- const execute = options.execute ?? runLsof;
5361
+ const execute = options.execute ?? defaultOccupierExecutor;
5279
5362
  try {
5280
5363
  return parsePortOccupier(await execute(port));
5281
5364
  } catch {
@@ -5703,13 +5786,32 @@ var init_runtime2 = __esm({
5703
5786
  }
5704
5787
  /**
5705
5788
  * alarm 轮询:把到期对象唤醒并调 onAlarm(CF-037)。
5789
+ * - 到期集合 = 后端落库到期记录 ∪ **驻留实例的内存 alarmAt(驻留时以内存值为准)**:
5790
+ * `setAlarm`/`clearAlarm` 只写内存、`alarmAt` 随 `flush()` 落库——若 pump 只读后端,
5791
+ * 「setAlarm 后没 flush」会静默丢调度(rift-brawl 实锤:先 flush 再 setAlarm,闹钟永不触发),
5792
+ * 反向「clearAlarm 后没 flush」会因 DB 残留到期值误触发。重启续接仍以落库值为准
5793
+ * (实例不驻留时后端值是唯一事实;要重启不丢 alarm,方法内仍须 flush——见 features/state-objects.md)。
5706
5794
  * - onAlarm 后统一持久化(flush):onAlarm 内改的 state 与 setAlarm 重调度 / clearAlarm
5707
5795
  * 的新 alarmAt 都落库;
5708
5796
  * - 单对象 onAlarm 抛错**不阻塞**同 tick 其余对象:失败对象不落库、alarmAt 保留
5709
5797
  * → 下轮 dueAlarms 仍命中重试;错误折叠进 failed(不泄漏内部栈)。
5710
5798
  */
5711
5799
  async pump(now) {
5712
- const due = await this.backend.dueAlarms(now);
5800
+ const dueMap = /* @__PURE__ */ new Map();
5801
+ for (const d of await this.backend.dueAlarms(now)) {
5802
+ dueMap.set(this.key(d.type, d.id), d);
5803
+ }
5804
+ for (const [k, inst] of this.instances) {
5805
+ const typeName = inst.constructor.typeName;
5806
+ if (typeName === void 0) continue;
5807
+ const raw = inst;
5808
+ if (raw.alarmAt === null || raw.alarmAt > now) {
5809
+ dueMap.delete(k);
5810
+ continue;
5811
+ }
5812
+ dueMap.set(k, { type: typeName, id: inst.id, alarmAt: raw.alarmAt });
5813
+ }
5814
+ const due = [...dueMap.values()].toSorted((a, b) => a.alarmAt - b.alarmAt);
5713
5815
  const fired = [];
5714
5816
  const failed = [];
5715
5817
  for (const d of due) {
@@ -5752,8 +5854,9 @@ function createProjectDriverStateBackend(driver) {
5752
5854
  let ensured = false;
5753
5855
  const ensureTable = async () => {
5754
5856
  if (ensured) return;
5857
+ const tsType = driver.engine === "pg" ? "BIGINT" : "INTEGER";
5755
5858
  await driver.run(
5756
- `CREATE TABLE IF NOT EXISTS ${STATE_OBJECTS_TABLE} ("type" TEXT NOT NULL, "id" TEXT NOT NULL, "state" TEXT NOT NULL, "alarm_at" INTEGER, "updated_at" INTEGER NOT NULL, PRIMARY KEY ("type", "id"))`
5859
+ `CREATE TABLE IF NOT EXISTS ${STATE_OBJECTS_TABLE} ("type" TEXT NOT NULL, "id" TEXT NOT NULL, "state" TEXT NOT NULL, "alarm_at" ${tsType}, "updated_at" ${tsType} NOT NULL, PRIMARY KEY ("type", "id"))`
5757
5860
  );
5758
5861
  ensured = true;
5759
5862
  };
@@ -6298,7 +6401,7 @@ ${DYNAMIC_IMPORT_HINT}` : "";
6298
6401
  if (typeof code === "string") wrapped.code = code;
6299
6402
  return wrapped;
6300
6403
  }
6301
- function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false) {
6404
+ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false, hints) {
6302
6405
  const cached2 = cache.get(path);
6303
6406
  if (cached2 !== void 0) return cached2;
6304
6407
  const source = files[path];
@@ -6319,7 +6422,7 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
6319
6422
  }
6320
6423
  const resolved = resolveModulePath(dir, request, files);
6321
6424
  if (resolved !== null) {
6322
- return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths);
6425
+ return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths, hints);
6323
6426
  }
6324
6427
  if (resolveBare !== void 0 && !request.startsWith("./") && !request.startsWith("../")) {
6325
6428
  const cachedModule = bareCache?.get(request);
@@ -6334,21 +6437,33 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
6334
6437
  error62.code = SANDBOX_BUILTIN_REJECTED;
6335
6438
  throw error62;
6336
6439
  };
6337
- let transformed;
6440
+ const hint = hints?.[path];
6441
+ let scriptSource;
6338
6442
  try {
6339
- transformed = transformExports(transpile(source));
6443
+ scriptSource = hint !== void 0 ? hint.js : `${WRAPPER_PREFIX}${transformExports(transpile(source))}${WRAPPER_SUFFIX}`;
6340
6444
  } catch (error62) {
6341
6445
  throw syntaxErrorWithLocation(error62, path, source);
6342
6446
  }
6343
6447
  const context = createSandboxContext(sandboxGlobals);
6344
6448
  let wrapper;
6345
6449
  try {
6346
- wrapper = vm.runInContext(
6347
- `(function (module, exports, require) { ${transformed}
6348
- })`,
6349
- context,
6350
- { filename: path }
6351
- );
6450
+ if (hint !== void 0 && hint.cachedData !== void 0) {
6451
+ const script = new vm.Script(scriptSource, {
6452
+ filename: path,
6453
+ cachedData: Buffer.from(
6454
+ hint.cachedData.buffer,
6455
+ hint.cachedData.byteOffset,
6456
+ hint.cachedData.byteLength
6457
+ )
6458
+ });
6459
+ if (script.cachedDataRejected !== true) {
6460
+ wrapper = script.runInContext(context);
6461
+ } else {
6462
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
6463
+ }
6464
+ } else {
6465
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
6466
+ }
6352
6467
  } catch (error62) {
6353
6468
  throw syntaxErrorWithLocation(error62, path, source);
6354
6469
  }
@@ -6358,7 +6473,7 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
6358
6473
  }
6359
6474
  return exports;
6360
6475
  }
6361
- function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false) {
6476
+ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false, hints) {
6362
6477
  const cache = /* @__PURE__ */ new Map();
6363
6478
  const bareCache = /* @__PURE__ */ new Map();
6364
6479
  const entryExports = loadModule(
@@ -6368,15 +6483,18 @@ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPat
6368
6483
  cache,
6369
6484
  resolveBare,
6370
6485
  bareCache,
6371
- strictPaths
6486
+ strictPaths,
6487
+ hints
6372
6488
  );
6373
6489
  const handler = entryExports["default"];
6374
6490
  if (typeof handler !== "function") {
6375
- throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570`);
6491
+ const base = entry.replace(/^.*\//, "");
6492
+ const hint = base === "state-objects.ts" || entry.startsWith("durable-objects/") ? '\u3002\u8BE5\u6587\u4EF6\u662F\u72B6\u6001\u5BF9\u8C61\u58F0\u660E\u6587\u4EF6\uFF0C\u653E\u5728 functions/ \u76EE\u5F55\u5185\u4F1A\u540C\u65F6\u88AB\u5F53\u4F5C\u4E91\u51FD\u6570\u5165\u53E3\uFF1A\u8865\u4E00\u4E2A default \u5BFC\u51FA\u7684\u5360\u4F4D handler\uFF0C\u4F8B\u5982 `export default async () => ({ error: "state objects \u8BF7\u8D70 /api/state/<type>/<id>/<method>" })`' : "";
6493
+ throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570${hint}`);
6376
6494
  }
6377
6495
  return { handler };
6378
6496
  }
6379
- var bunTranspiler, SANDBOX_BUILTIN_REJECTED, REALM_VALUE_KEY, DYNAMIC_IMPORT_HINT;
6497
+ var bunTranspiler, SANDBOX_BUILTIN_REJECTED, REALM_VALUE_KEY, DYNAMIC_IMPORT_HINT, WRAPPER_PREFIX, WRAPPER_SUFFIX;
6380
6498
  var init_sandbox = __esm({
6381
6499
  "packages/runtime/src/functions/runtime/sandbox.ts"() {
6382
6500
  "use strict";
@@ -6385,6 +6503,8 @@ var init_sandbox = __esm({
6385
6503
  SANDBOX_BUILTIN_REJECTED = "FN_SANDBOX_BUILTIN_BLOCKED";
6386
6504
  REALM_VALUE_KEY = "__adepRealmValue";
6387
6505
  DYNAMIC_IMPORT_HINT = "\u63D0\u793A\uFF1AM1 \u6C99\u7BB1\u4E0D\u652F\u6301\u52A8\u6001 import\uFF0C\u6539\u9759\u6001 import";
6506
+ WRAPPER_PREFIX = "(function (module, exports, require) { ";
6507
+ WRAPPER_SUFFIX = " \n})";
6388
6508
  }
6389
6509
  });
6390
6510
 
@@ -7188,7 +7308,9 @@ function runWorker(input2, port) {
7188
7308
  sandboxGlobals,
7189
7309
  input2.deps === void 0 ? void 0 : createBareResolver(input2.deps),
7190
7310
  // CORE-154:--parity 严格模式连带 `../` 越根引用报错(与容器形态真实 fs 同形)。
7191
- input2.parity === true
7311
+ input2.parity === true,
7312
+ // W2:预编译提示透传(缺省 undefined = 全量编译路径,零回归)。
7313
+ input2.compileHints
7192
7314
  );
7193
7315
  const result = Promise.resolve(handler(ctx));
7194
7316
  void result.then(
@@ -7607,14 +7729,14 @@ async function loadConfig(cwd) {
7607
7729
  return {
7608
7730
  name: config2?.name ?? name,
7609
7731
  functionsDir: config2?.functionsDir ?? "functions",
7610
- functionsPrefix: config2?.functions_prefix ?? "",
7732
+ functionsPrefix: normalizeFunctionsPrefix(config2?.functions_prefix ?? ""),
7611
7733
  ...config2?.environment === void 0 ? {} : { environment: config2.environment },
7612
7734
  ...config2?.db_environment === void 0 ? {} : { dbEnvironment: config2.db_environment }
7613
7735
  };
7614
7736
  }
7615
7737
  function resolveRouteFnName(pathname, prefix) {
7616
7738
  const segments = pathname.split("/").filter((segment) => segment.length > 0);
7617
- const normalizedPrefix = prefix.replace(/^\/+|\/+$/g, "");
7739
+ const normalizedPrefix = normalizeFunctionsPrefix(prefix);
7618
7740
  if (normalizedPrefix.length === 0) {
7619
7741
  const first = segments[0];
7620
7742
  return first === void 0 ? {} : { fnName: first };
@@ -7658,7 +7780,7 @@ async function startDevServer(options) {
7658
7780
  `));
7659
7781
  const config2 = await loadConfig(cwd);
7660
7782
  if (options.prefix !== void 0) {
7661
- config2.functionsPrefix = options.prefix.replace(/^\/+|\/+$/g, "");
7783
+ config2.functionsPrefix = normalizeFunctionsPrefix(options.prefix);
7662
7784
  }
7663
7785
  const functionsDir = join13(cwd, config2.functionsDir);
7664
7786
  const coldStartAt = Date.now();
@@ -7836,7 +7958,7 @@ async function startDevServer(options) {
7836
7958
  return;
7837
7959
  }
7838
7960
  if (fnName === "state") {
7839
- const normalizedPrefix = config2.functionsPrefix.replace(/^\/+|\/+$/g, "");
7961
+ const normalizedPrefix = normalizeFunctionsPrefix(config2.functionsPrefix);
7840
7962
  const rest = normalizedPrefix.length === 0 ? url2.pathname : url2.pathname.replace(new RegExp(`^/${normalizedPrefix}`), "");
7841
7963
  const parsed = parseStatePath(rest);
7842
7964
  if (parsed === null) {
@@ -7947,13 +8069,19 @@ async function startDevServer(options) {
7947
8069
  const baseUrl = `http://127.0.0.1:${actualPort}`;
7948
8070
  runtime.storage.signer.baseUrl = baseUrl;
7949
8071
  const coldStartMs = Date.now() - coldStartAt;
7950
- const curlPath = config2.functionsPrefix.length === 0 ? "/hello" : `/${config2.functionsPrefix}/hello`;
8072
+ const functionNames = listFunctionNames(files);
8073
+ const firstFunction = functionNames[0];
8074
+ const curlPath = firstFunction === void 0 ? null : config2.functionsPrefix.length === 0 ? `/${firstFunction}` : `/${config2.functionsPrefix}/${firstFunction}`;
7951
8075
  const dbLabel = db.mode === "sqlite" ? `SQLite \u771F\u5B9E\u5E93${db.module === null ? "" : `\uFF08${db.module}\uFF09`}` : "sim \u5F15\u64CE\uFF08\u5185\u7F6E\u6A21\u62DF\uFF09";
7952
8076
  const dbTargetText = db.file === null ? simDbTarget(cwd) : displayPath(cwd, db.file);
7953
8077
  log(
7954
8078
  `[adep] dev server listening on ${baseUrl}\uFF08\u672C\u5730\u8FD0\u884C\u65F6 / ${dbLabel}\uFF0C\u51B7\u542F\u52A8 ${coldStartMs}ms\uFF09`
7955
8079
  );
7956
- log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
8080
+ if (curlPath === null) {
8081
+ log("[adep] functions/ \u76EE\u5F55\u4E3A\u7A7A\uFF1A\u6682\u65E0\u51FD\u6570\u53EF\u8C03\u7528\u3002\u65B0\u5EFA functions/<name>.ts \u540E\u81EA\u52A8\u70ED\u91CD\u8F7D\u3002");
8082
+ } else {
8083
+ log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
8084
+ }
7957
8085
  printBoundaries(log);
7958
8086
  if (simUser.resolver !== void 0) {
7959
8087
  log(
@@ -7991,6 +8119,7 @@ var init_dev = __esm({
7991
8119
  init_fetch_safe_port();
7992
8120
  init_port_in_use();
7993
8121
  init_env();
8122
+ init_config();
7994
8123
  init_fetch_config();
7995
8124
  init_invoke();
7996
8125
  init_builtin_deps2();
@@ -8480,7 +8609,7 @@ function renderBanner(options) {
8480
8609
  lines.push("");
8481
8610
  lines.push(" \u80FD\u529B:");
8482
8611
  if (functions.length > 0) {
8483
- const route = options.functionsPrefix === void 0 || options.functionsPrefix.length === 0 ? `${baseUrl}/api/{fn}` : `${baseUrl}/${options.functionsPrefix.replace(/^\/+|\/+$/g, "")}/{fn}`;
8612
+ const route = options.functionsPrefix === void 0 || options.functionsPrefix.length === 0 ? `${baseUrl}/api/{fn}` : `${baseUrl}/${normalizeFunctionsPrefix(options.functionsPrefix)}/{fn}`;
8484
8613
  lines.push(` - \u51FD\u6570\u8DEF\u7531: ${route}\uFF08${functions.length} \u4E2A\u51FD\u6570: ${functions.join(", ")}\uFF09`);
8485
8614
  } else {
8486
8615
  lines.push(" - \u51FD\u6570\u8DEF\u7531: \u65E0\uFF08functions/ \u76EE\u5F55\u4E3A\u7A7A\uFF09");
@@ -8563,6 +8692,7 @@ var init_banner = __esm({
8563
8692
  "packages/cli/src/serve/banner.ts"() {
8564
8693
  "use strict";
8565
8694
  init_dev_shared();
8695
+ init_config();
8566
8696
  }
8567
8697
  });
8568
8698
 
@@ -9133,7 +9263,7 @@ async function startServeServer(options) {
9133
9263
  );
9134
9264
  return;
9135
9265
  }
9136
- const normalizedPrefix = config2.functionsPrefix.replace(/^\/+|\/+$/g, "");
9266
+ const normalizedPrefix = normalizeFunctionsPrefix(config2.functionsPrefix);
9137
9267
  const fnRest = normalizedPrefix.length > 0 ? pathname === `/${normalizedPrefix}` || pathname.startsWith(`/${normalizedPrefix}/`) ? pathname.slice(normalizedPrefix.length + 1) : null : pathname === "/api" ? "" : pathname.startsWith("/api/") ? pathname.slice("/api/".length) : null;
9138
9268
  if (fnRest !== null) {
9139
9269
  const { fnName, error: routeError } = resolveRouteFnName(fnRest, "");
@@ -9332,6 +9462,7 @@ var init_server = __esm({
9332
9462
  init_worker_executor();
9333
9463
  init_signature();
9334
9464
  init_driver();
9465
+ init_config();
9335
9466
  init_builtin_deps2();
9336
9467
  init_runtime();
9337
9468
  init_storage();
@@ -10981,7 +11112,7 @@ var init_version = __esm({
10981
11112
  manifest = requireJson("../package.json");
10982
11113
  CLI_VERSION = typeof manifest.version === "string" && manifest.version.length > 0 ? manifest.version : "0.0.0";
10983
11114
  RELEASE_TASKS = Array.isArray(manifest.adep?.releaseTasks) ? manifest.adep.releaseTasks.filter((item) => typeof item === "string") : [];
10984
- BUILD_COMMIT = "f4161f88".trim() !== "" ? "f4161f88".trim() : null;
11115
+ BUILD_COMMIT = "08ca68b9".trim() !== "" ? "08ca68b9".trim() : null;
10985
11116
  }
10986
11117
  });
10987
11118
 
@@ -11902,8 +12033,8 @@ var GENERATED_TEMPLATES = {
11902
12033
  },
11903
12034
  "files": [
11904
12035
  {
11905
- "path": "README-EMPTY.md",
11906
- "content": "// AgentDeploy \u9879\u76EE\u5165\u53E3\u3002\u6A21\u677F\u6682\u65E0\u66F4\u591A\u5185\u5BB9\u2014\u2014\u51FD\u6570\u653E functions/\uFF0C\u524D\u7AEF\u653E web/src/\uFF0C\u914D\u7F6E\u89C1 adep.config.ts\u3002\n"
12036
+ "path": "README.md",
12037
+ "content": '# {{name}}\n\nAgentDeploy **\u7A7A\u6A21\u677F**\u9879\u76EE\u2014\u2014\u8FD9\u91CC\u53EA\u6709\u6700\u5C0F\u5DE5\u7A0B\u9AA8\u67B6\uFF1A\u6CA1\u6709 `functions/`\uFF08\u6CA1\u6709\u4E91\u51FD\u6570\uFF09\uFF0C\n\u4E5F\u6CA1\u6709\u524D\u7AEF\u5DE5\u7A0B\u3002\n\n## \u8FD9\u4E2A\u6A21\u677F\u91CC\u6709\u4EC0\u4E48\n\n- `package.json`\uFF1A\u5E94\u7528\u5B9A\u4E49\uFF08\u4EC5 `@adep/cli` \u4F9D\u8D56\uFF1B\u65E0\u524D\u7AEF\u4F9D\u8D56\uFF09\n- `adep.config.ts`\uFF1A\u9879\u76EE\u914D\u7F6E\uFF08name / template / functionsDir / functions_prefix\uFF0C\u9ED8\u8BA4 `/api`\uFF09\n- `tsconfig.json`\uFF1ATypeScript \u7F16\u8F91\u5668\u914D\u7F6E\uFF08strict + noEmit\uFF09\n- `adep.d.ts`\uFF1A\u4E91\u51FD\u6570\u4E0A\u4E0B\u6587\u73AF\u5883\u7C7B\u578B\u58F0\u660E\uFF08`ctx: AdepContext` \u8865\u5168\uFF0C\u65E0\u9700\u88C5\u4F9D\u8D56\uFF09\n\n## \u600E\u4E48\u7528\n\n\u8FD9\u662F**\u8D77\u70B9**\uFF0C\u4E0D\u662F\u6210\u54C1\u3002\u6309\u9700\u8981\u4E8C\u9009\u4E00\uFF1A\n\n- **\u53EA\u8981\u4E91\u51FD\u6570**\uFF1A`adep init <name> -t function` \u2014\u2014 \u5E26\u4E00\u4E2A\u793A\u4F8B\u51FD\u6570\uFF08`functions/hello.ts`\uFF09\u3002\n- **\u8981\u524D\u7AEF\uFF08Vue 3 + Vite\uFF09**\uFF1A`adep init <name> -t fullstack` \u2014\u2014 \u5E26 `web/src/` \u6E90\u7801\u3001\n `vite.config.ts`\u3001`index.html` \u4E0E `database/schema.sql`\u3002\n\n\u5728\u672C\u76EE\u5F55\u91CC\u624B\u5199\u4E5F\u53EF\u4EE5\uFF1A\u65B0\u5EFA `functions/<name>.ts`\uFF0C\u5BFC\u51FA\n`export default async (ctx: AdepContext) => Response`\u3002\n\n## \u5E38\u7528\u547D\u4EE4\n\n- `pnpm dev`\uFF08= `adep dev`\uFF09\uFF1A\u51FD\u6570\u4FA7\u6A21\u62DF\u8FD0\u884C\u65F6\u2014\u2014\u8FDB\u7A0B\u5185\u6267\u884C\u4E91\u51FD\u6570\uFF0C\u4E0D\u8FDE\u4E91\u7AEF\u3001\u4E0D\u88C5 Docker\uFF0C\n \u65AD\u7F51\u4E5F\u80FD\u5F00\u53D1\uFF1B\u81EA\u52A8\u88C5\u914D `cloud.db` / `cloud.storage` / `cloud.realtime`\uFF0C\u6587\u4EF6\u53D8\u66F4\u81EA\u52A8\u70ED\u91CD\u8F7D\u3002\n- `pnpm serve`\uFF08= `adep serve`\uFF09\uFF1A\u5F00\u53D1\u6001\u670D\u52A1\u5668\uFF08\u51FD\u6570 `/api/{prefix}/{fn}` + `/healthz` + \u9759\u6001\u6258\u7BA1\uFF09\n- `pnpm deploy`\uFF08= `adep publish --only functions`\uFF09\uFF1A\u589E\u91CF\u90E8\u7F72\u4E91\u51FD\u6570\uFF08\u5BF9\u6BD4\u8FDC\u7AEF\u54C8\u5E0C \u2192 \u4EC5\u4E0A\u4F20\u53D8\u66F4 \u2192 \u53D1\u5E03 \u2192 \u8F93\u51FA\u8BBF\u95EE\u57DF\u540D\uFF09\n- `pnpm doctor`\uFF08= `adep doctor`\uFF09\uFF1A\u672C\u5730\u73AF\u5883\u79BB\u7EBF\u8BCA\u65AD\n\n> \u672C\u6A21\u677F**\u6CA1\u6709** `build` / `site:deploy` \u811A\u672C\uFF1A\u6CA1\u6709\u524D\u7AEF\u5DE5\u7A0B\u5C31\u6CA1\u6709\u524D\u7AEF\u4EA7\u7269\u53EF\u6784\u5EFA\u3002\n\n## pnpm \u4E0E\u4F9D\u8D56\u6784\u5EFA\u811A\u672C\uFF08pnpm 10 \u8D77\u9ED8\u8BA4\u4E0D\u8DD1\uFF09\n\n\u9879\u76EE\u6839\u7684 `pnpm-workspace.yaml` \u5DF2\u653E\u884C `esbuild` \u7684\u6784\u5EFA\u811A\u672C\uFF08`onlyBuiltDependencies` \u4E0E\n`allowBuilds` \u53CC\u5199\uFF1Apnpm 10 \u8BFB\u524D\u8005\uFF0Cpnpm 11+ \u8BFB\u540E\u8005\uFF09\u3002pnpm 10 \u8D77**\u9ED8\u8BA4\u4E0D\u6267\u884C\u4F9D\u8D56\u7684\n\u6784\u5EFA\u811A\u672C**\uFF0C\u5220\u6389\u8FD9\u4EFD\u914D\u7F6E\u540E `pnpm install` \u4F1A\u4EE5 `ERR_PNPM_IGNORED_BUILDS` \u62A5\u9519\n\uFF08`@adep/cli` \u4F9D\u8D56 esbuild\uFF0C\u5176\u539F\u751F\u4E8C\u8FDB\u5236\u6CA1\u51C6\u5907\u597D\uFF0C\u6784\u5EFA\u53EF\u80FD\u5931\u8D25\uFF09\u3002\u4ECD\u7528 pnpm 9 \u65F6\u7B49\u4EF7\u5199\u6CD5\u662F\u5728\n`package.json` \u91CC\u5199 `"pnpm": { "onlyBuiltDependencies": ["esbuild"] }`\u3002\n'
11907
12038
  }
11908
12039
  ]
11909
12040
  },
@@ -12023,7 +12154,7 @@ var GENERATED_TEMPLATES = {
12023
12154
  },
12024
12155
  {
12025
12156
  "path": "functions/_shared/date.test.ts",
12026
- "content": "/**\n * \u670D\u52A1\u7AEF\u65E5\u671F/\u6392\u5E8F\u5355\u5143\u6D4B\u8BD5\uFF08\u79FB\u690D\u903B\u8F91\u7684\u56DE\u5F52\u4FDD\u62A4\uFF09\u3002\n * \u54CD\u5E94\u4FE1\u5C01\u7684\u6D4B\u8BD5\u5728\u5B98\u65B9\u5305 `@adep/runtime` \u4FA7\uFF08FN-029 \u8D77 ok/fail \u6536\u7F16\u8FDB\u5E73\u53F0\uFF09\u3002\n * \u8FD0\u884C\uFF1Anpm run test\n */\nimport { describe, it, expect } from 'vitest'\nimport { isValidDate, calcDays, toDTO, sortEvents } from './date'\nimport type { EventRow } from './store'\n\ndescribe('isValidDate', () => {\n it('\u63A5\u53D7\u5408\u6CD5 YYYY-MM-DD', () => {\n expect(isValidDate('2026-09-20')).toBe(true)\n expect(isValidDate('2024-02-29')).toBe(true)\n })\n it('\u62D2\u7EDD\u975E\u6CD5\u65E5\u671F\u4E0E\u683C\u5F0F', () => {\n expect(isValidDate('2026-13-01')).toBe(false)\n expect(isValidDate('2026-02-30')).toBe(false)\n expect(isValidDate('2026/09/20')).toBe(false)\n expect(isValidDate('')).toBe(false)\n expect(isValidDate(null)).toBe(false)\n })\n})\n\ndescribe('calcDays\uFF08\u5317\u4EAC\u65F6\u95F4\u81EA\u7136\u65E5\uFF09', () => {\n it('\u5012\u8BA1\u65F6\uFF1A\u672A\u6765\u4E3A\u6B63\uFF0C\u5F53\u5929\u4E3A 0', () => {\n const today = new Date()\n const beijing = new Date(today.getTime() + 8 * 3600_000)\n const todayStr = `${beijing.getUTCFullYear()}-${String(beijing.getUTCMonth() + 1).padStart(2, '0')}-${String(\n beijing.getUTCDate()\n ).padStart(2, '0')}`\n expect(calcDays(todayStr)).toBe(0)\n })\n it('\u8FC7\u53BB\u65E5\u671F\u4E3A\u8D1F\uFF1Bcountup \u53D6\u7EDD\u5BF9\u503C', () => {\n expect(calcDays('2020-01-01')).toBeLessThan(0)\n expect(calcDays('2020-01-01', 'countup')).toBeGreaterThan(0)\n })\n it('\u975E\u6CD5\u65E5\u671F\u8FD4\u56DE 0', () => {\n expect(calcDays('bad-date')).toBe(0)\n })\n})\n\ndescribe('toDTO + sortEvents', () => {\n const base = {\n id: '1',\n user_id: 'u1',\n title: '\u4E8B\u4EF6',\n target_date: '2030-01-01',\n note: null,\n category: null,\n direction: 'countdown',\n is_pinned: 0,\n sort_order: 0,\n created_at: '2026-01-01T00:00:00.000Z',\n updated_at: '2026-01-01T00:00:00.000Z',\n } as EventRow\n\n it('toDTO \u8865\u9ED8\u8BA4\u503C\u5E76\u7B97 days', () => {\n const dto = toDTO(base)\n expect(dto.note).toBe('')\n expect(dto.category).toBe('other')\n expect(dto.is_pinned).toBe(false)\n expect(dto.days).toBeGreaterThan(0)\n })\n\n it('\u6392\u5E8F\uFF1A\u7F6E\u9876\u4F18\u5148\uFF0C\u5176\u4F59\u6309\u5269\u4F59\u5929\u6570\u5347\u5E8F\uFF08\u8FC7\u53BB\u6392\u6700\u540E\uFF09', () => {\n const far = { ...base, id: 'far', target_date: '2031-01-01' } as EventRow\n const near = { ...base, id: 'near', target_date: '2026-10-01' } as EventRow\n const past = { ...base, id: 'past', target_date: '2020-01-01' } as EventRow\n const pinnedFar = { ...far, id: 'pinnedFar', is_pinned: 1 } as EventRow\n const sorted = sortEvents([far, near, past, pinnedFar].map((r) => toDTO(r)))\n expect(sorted.map((e) => e.id)).toEqual(['pinnedFar', 'near', 'far', 'past'])\n })\n})\n"
12157
+ "content": "/**\n * \u670D\u52A1\u7AEF\u65E5\u671F/\u6392\u5E8F\u5355\u5143\u6D4B\u8BD5\uFF08\u79FB\u690D\u903B\u8F91\u7684\u56DE\u5F52\u4FDD\u62A4\uFF09\u3002\n * \u54CD\u5E94\u4FE1\u5C01\u7684\u6D4B\u8BD5\u5728\u5B98\u65B9\u5305 `@adep/runtime` \u4FA7\uFF08FN-029 \u8D77 ok/fail \u6536\u7F16\u8FDB\u5E73\u53F0\uFF09\u3002\n * \u8FD0\u884C\uFF1Anpm run test\n */\nimport { describe, it, expect } from 'vitest'\nimport { isValidDate, calcDays, toDTO, sortEvents } from './date'\nimport type { EventRow } from './store'\n\n/** \u76F8\u5BF9\u951A\u9020 YYYY-MM-DD\uFF08+8h \u5BF9\u9F50\u672C\u6587\u4EF6\u300C\u5317\u4EAC\u81EA\u7136\u65E5\u300D\u53E3\u5F84\uFF09\uFF1A\u5199\u6B7B\u65E5\u5386\u65E5\u671F\u7684\u5939\u5177\u662F\u5B9A\u65F6\u70B8\u5F39\uFF082026-10-01 \u8FC7\u671F\u5373\u7EA2\u5B9E\u8BC1\uFF09\u3002 */\nfunction dateOffset(days: number): string {\n const d = new Date(Date.now() + days * 86_400_000 + 8 * 3600_000)\n return d.toISOString().slice(0, 10)\n}\n\ndescribe('isValidDate', () => {\n it('\u63A5\u53D7\u5408\u6CD5 YYYY-MM-DD', () => {\n expect(isValidDate('2026-09-20')).toBe(true)\n expect(isValidDate('2024-02-29')).toBe(true)\n })\n it('\u62D2\u7EDD\u975E\u6CD5\u65E5\u671F\u4E0E\u683C\u5F0F', () => {\n expect(isValidDate('2026-13-01')).toBe(false)\n expect(isValidDate('2026-02-30')).toBe(false)\n expect(isValidDate('2026/09/20')).toBe(false)\n expect(isValidDate('')).toBe(false)\n expect(isValidDate(null)).toBe(false)\n })\n})\n\ndescribe('calcDays\uFF08\u5317\u4EAC\u65F6\u95F4\u81EA\u7136\u65E5\uFF09', () => {\n it('\u5012\u8BA1\u65F6\uFF1A\u672A\u6765\u4E3A\u6B63\uFF0C\u5F53\u5929\u4E3A 0', () => {\n const today = new Date()\n const beijing = new Date(today.getTime() + 8 * 3600_000)\n const todayStr = `${beijing.getUTCFullYear()}-${String(beijing.getUTCMonth() + 1).padStart(2, '0')}-${String(\n beijing.getUTCDate()\n ).padStart(2, '0')}`\n expect(calcDays(todayStr)).toBe(0)\n })\n it('\u8FC7\u53BB\u65E5\u671F\u4E3A\u8D1F\uFF1Bcountup \u53D6\u7EDD\u5BF9\u503C', () => {\n expect(calcDays('2020-01-01')).toBeLessThan(0)\n expect(calcDays('2020-01-01', 'countup')).toBeGreaterThan(0)\n })\n it('\u975E\u6CD5\u65E5\u671F\u8FD4\u56DE 0', () => {\n expect(calcDays('bad-date')).toBe(0)\n })\n})\n\ndescribe('toDTO + sortEvents', () => {\n const base = {\n id: '1',\n user_id: 'u1',\n title: '\u4E8B\u4EF6',\n target_date: dateOffset(30),\n note: null,\n category: null,\n direction: 'countdown',\n is_pinned: 0,\n sort_order: 0,\n created_at: '2026-01-01T00:00:00.000Z',\n updated_at: '2026-01-01T00:00:00.000Z',\n } as EventRow\n\n it('toDTO \u8865\u9ED8\u8BA4\u503C\u5E76\u7B97 days', () => {\n const dto = toDTO(base)\n expect(dto.note).toBe('')\n expect(dto.category).toBe('other')\n expect(dto.is_pinned).toBe(false)\n expect(dto.days).toBeGreaterThan(0)\n })\n\n it('\u6392\u5E8F\uFF1A\u7F6E\u9876\u4F18\u5148\uFF0C\u5176\u4F59\u6309\u5269\u4F59\u5929\u6570\u5347\u5E8F\uFF08\u8FC7\u53BB\u6392\u6700\u540E\uFF09', () => {\n // \u5939\u5177\u65E5\u671F\u5FC5\u987B\u76F8\u5BF9\u951A\uFF1A\u5199\u6B7B\u65E5\u5386\u65E5\u671F\u662F\u5B9A\u65F6\u70B8\u5F39\uFF082026-10-01 \u8FC7\u671F\u5373\u7EA2\u5B9E\u8BC1\uFF0C398 \u6279\u540C\u6B3E\uFF09\u3002\n const far = { ...base, id: 'far', target_date: dateOffset(1460) } as EventRow\n const near = { ...base, id: 'near', target_date: dateOffset(7) } as EventRow\n const past = { ...base, id: 'past', target_date: dateOffset(-7) } as EventRow\n const pinnedFar = { ...far, id: 'pinnedFar', is_pinned: 1 } as EventRow\n const sorted = sortEvents([far, near, past, pinnedFar].map((r) => toDTO(r)))\n expect(sorted.map((e) => e.id)).toEqual(['pinnedFar', 'near', 'far', 'past'])\n })\n})\n"
12027
12158
  },
12028
12159
  {
12029
12160
  "path": "functions/_shared/date.ts",
@@ -14583,6 +14714,18 @@ interface AdepCloudDbTable {
14583
14714
  insert(row: Record<string, AdepSqlValue>): Promise<void>
14584
14715
  /** \u6279\u91CF\u63D2\u5165\u3002 */
14585
14716
  insertMany(rows: ReadonlyArray<Record<string, AdepSqlValue>>): Promise<void>
14717
+ /**
14718
+ * \u63D2\u5165\u6216\u66F4\u65B0\uFF08INSERT ... ON CONFLICT (target) DO UPDATE SET ...\uFF09\u3002
14719
+ * \u66FF\u4EE3\u300C\u5148\u67E5\u4E00\u904D\u3001\u6CA1\u6709\u5C31 insert\u3001\u6709\u5C31 update\u300D\u6A21\u677F\u2014\u2014\u90A3\u6761\u8DEF\u5728\u5E76\u53D1\u4E0B\u4E24\u4E2A\u8BF7\u6C42
14720
+ * \u90FD\u4F1A\u67E5\u5230\u300C\u6CA1\u6709\u300D\uFF0C\u7136\u540E\u53CC\u53CC insert\uFF0C\u649E\u552F\u4E00\u7EA6\u675F\u76F4\u63A5 500\uFF08\u590D\u5408\u4E3B\u952E\u8868\u5C24\u5176\u5E38\u89C1\uFF09\u3002
14721
+ *
14722
+ * target \u5FC5\u987B\u547D\u4E2D\u8868\u4E0A\u7684\u552F\u4E00\u7EA6\u675F\uFF08\u4E3B\u952E\u6216 UNIQUE \u7D22\u5F15\uFF09\uFF0C\u5426\u5219\u9A71\u52A8\u5C42\u62A5\u9519\u3002
14723
+ * \u51B2\u7A81\u65F6\u7684\u66F4\u65B0\u5217\u7531 options.update \u6307\u5B9A\uFF08\u503C\u53D6\u81EA row\uFF09\uFF0C\u7F3A\u7701 = row \u4E2D\u9664 target
14724
+ * \u5916\u7684\u5168\u90E8\u5217\uFF1B\u663E\u5F0F update: [] \u8868\u793A\u51B2\u7A81\u65F6\u4FDD\u6301\u65E7\u884C\u4E0D\u53D8\uFF08DO NOTHING\uFF09\u3002
14725
+ *
14726
+ * owned \u8868\u4E0D\u652F\u6301\uFF08\u53D8\u66F4\u6D41\u65E0\u6CD5\u8868\u8FBE insert/update \u4E8C\u4E49\uFF09\uFF0C\u629B DB_UNSAFE_OP\u3002
14727
+ */
14728
+ upsert(row: Record<string, AdepSqlValue>, options: UpsertOptions): Promise<void>
14586
14729
  /** \u66F4\u65B0\uFF08\u5FC5\u987B\u5148 where\uFF0C\u5426\u5219 DB_UNSAFE_OP\uFF09\uFF1B\u8FD4\u56DE\u53D7\u5F71\u54CD\u884C\u6570\u3002 */
14587
14730
  update(values: Record<string, AdepSqlValue>): Promise<number>
14588
14731
  /** \u5220\u9664\uFF08\u5FC5\u987B\u5148 where\uFF0C\u5426\u5219 DB_UNSAFE_OP\uFF09\uFF1B\u8FD4\u56DE\u53D7\u5F71\u54CD\u884C\u6570\u3002 */
@@ -14984,30 +15127,41 @@ var ADEP_CONFIG_HEADER = `// adep \u9879\u76EE\u914D\u7F6E\uFF1ACLI\uFF08dev / s
14984
15127
  // dev / serve / \u5E73\u53F0\u8BBF\u95EE\u8DEF\u5F84\u4E00\u81F4\u4E3A /{prefix}/{fnName}\uFF08\u5982 /api/hello\uFF09\u3002
14985
15128
  // vite \u63D2\u4EF6\uFF08vite.config.ts \u7684 adepPlugin()\uFF09\u6309\u6B64\u524D\u7F00\u628A\u524D\u7AEF /{prefix}/* \u8BF7\u6C42\u4EE3\u7406\u5230\u4E91\u51FD\u6570\u3002
14986
15129
  // \u8FB9\u754C\uFF1A\u53EA\u5F71\u54CD\u672C\u5730 HTTP \u5165\u53E3\u8DEF\u7531\uFF1B\u51FD\u6570\u4E92\u8C03\uFF08ctx.cloud.invoke\uFF09\u4E0E\u7EBF\u4E0A\u90E8\u7F72\u8DEF\u5F84\u6309\u51FD\u6570\u540D\uFF0C\u4E0D\u53D7\u5F71\u54CD\u3002`;
14987
- var PACKAGE_JSON = (name, template, cliVersion) => {
15130
+ var PACKAGE_JSON = (ctx) => {
15131
+ const { name, template, cliVersion, hasFrontend } = ctx;
15132
+ const scripts = hasFrontend ? {
15133
+ dev: "vite",
15134
+ build: "vite build",
15135
+ "site:deploy": "adep hosting deploy site --spa",
15136
+ serve: "adep serve",
15137
+ // 容器内启动入口(Dockerfile 的 CMD 只有 `bun run start`):静态目录 / 端口口径
15138
+ // 只在这一个地方定档——Dockerfile 与 package.json 各写一套必然漂移(2026-10-08 收敛)。
15139
+ // fullstack 的前端产物在 site/(vite build);function / empty 无前端产物,故不指目录。
15140
+ start: template === "fullstack" ? "adep serve --host 0.0.0.0 --static site" : "adep serve --host 0.0.0.0",
15141
+ deploy: "adep publish --only functions",
15142
+ doctor: "adep doctor"
15143
+ } : {
15144
+ // 无前端模板:dev 走**函数侧**模拟运行时(进程内、不连云端、不装 Docker)。
15145
+ // 不能写 vite——没有 vite 工程根,启动后只会白屏一个空页。
15146
+ dev: "adep dev",
15147
+ serve: "adep serve",
15148
+ start: "adep serve --host 0.0.0.0",
15149
+ deploy: "adep publish --only functions",
15150
+ doctor: "adep doctor"
15151
+ };
14988
15152
  const pkg = {
14989
15153
  name,
14990
15154
  version: "0.1.0",
14991
15155
  private: true,
14992
15156
  type: "module",
14993
- description: `AgentDeploy \u5168\u6808\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u2014\u2014functions/ \u4E91\u51FD\u6570 + web/src/ \u524D\u7AEF\u6E90\u7801 + site/ \u524D\u7AEF\u6784\u5EFA\u4EA7\u7269`,
14994
- scripts: {
14995
- dev: "vite",
14996
- build: "vite build",
14997
- "site:deploy": "adep hosting deploy site --spa",
14998
- serve: "adep serve",
14999
- // 容器内启动入口(Dockerfile 的 CMD 只有 `bun run start`):静态目录 / 端口口径
15000
- // 只在这一个地方定档——Dockerfile 与 package.json 各写一套必然漂移(2026-10-08 收敛)。
15001
- // fullstack 的前端产物在 site/(vite build);function / empty 无前端产物,故不指目录。
15002
- start: template === "fullstack" ? "adep serve --host 0.0.0.0 --static site" : "adep serve --host 0.0.0.0",
15003
- deploy: "adep publish --only functions",
15004
- doctor: "adep doctor"
15005
- },
15157
+ description: hasFrontend ? `AgentDeploy \u5168\u6808\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u2014\u2014functions/ \u4E91\u51FD\u6570 + web/src/ \u524D\u7AEF\u6E90\u7801 + site/ \u524D\u7AEF\u6784\u5EFA\u4EA7\u7269` : template === "empty" ? "AgentDeploy \u7A7A\u6A21\u677F\u9879\u76EE\u2014\u2014\u4EC5\u9879\u76EE\u9AA8\u67B6\uFF08\u65E0 functions/\u3001\u65E0\u524D\u7AEF\u5DE5\u7A0B\uFF09" : `AgentDeploy \u4E91\u51FD\u6570\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u2014\u2014functions/ \u4E91\u51FD\u6570\uFF08\u65E0\u524D\u7AEF\u5DE5\u7A0B\uFF09`,
15158
+ scripts,
15006
15159
  dependencies: {
15007
15160
  "@adep/cli": cliVersion,
15008
- ...WEB_DEPENDENCIES
15161
+ // 前端依赖只在有前端工程时才声明(vue / @adep/client 运行时不需要)。
15162
+ ...hasFrontend ? WEB_DEPENDENCIES : {}
15009
15163
  },
15010
- devDependencies: WEB_DEV_DEPENDENCIES,
15164
+ devDependencies: hasFrontend ? WEB_DEV_DEPENDENCIES : {},
15011
15165
  engines: {
15012
15166
  node: ">=18",
15013
15167
  bun: ">=1.0"
@@ -15049,7 +15203,7 @@ var COUNTDOWN_PACKAGE_JSON = (name, cliVersion) => {
15049
15203
  "@adep/runtime": "^0.3.0",
15050
15204
  "@vitejs/plugin-vue": "^6.0.0",
15051
15205
  "esbuild-wasm": "^0.25.12",
15052
- typescript: "5.9.3",
15206
+ typescript: "6.0.3",
15053
15207
  vite: "^7.0.0",
15054
15208
  // vitest 用 ^3.2.4:vitest 4.x 的 packument 触发 npm 10.9 arborist edgesOut 崩溃(官方源同样),
15055
15209
  // 与 countdown 模板保持一致。
@@ -15178,7 +15332,7 @@ var DOCKER_ASSETS = (name) => [
15178
15332
  { path: ".dockerignore", content: DOCKERIGNORE },
15179
15333
  { path: ".env.example", content: ENV_EXAMPLE }
15180
15334
  ];
15181
- var README = (name, template) => `# ${name}
15335
+ var README_FULLSTACK = (name, template) => `# ${name}
15182
15336
 
15183
15337
  AgentDeploy \u5168\u6808\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u3002
15184
15338
 
@@ -15289,6 +15443,66 @@ console.log(result.message)
15289
15443
  \`web/src/\` \u5B58\u653E\u524D\u7AEF\u6E90\u7801\uFF08\`main.ts\` / \`App.vue\`\uFF09\uFF0C\u4E0E Web IDE \u5185 \`web/\` \u5DE5\u7A0B\u7684 \`src/\`
15290
15444
  \u5B8C\u5168\u540C\u6784\uFF1Bvite \u5DE5\u7A0B\u6839\u5728\u9879\u76EE\u6839\u76EE\u5F55\uFF08\`vite.config.ts\` / \`index.html\` / \`package.json\`\uFF09\u3002
15291
15445
  `;
15446
+ var README_FUNCTION_ONLY = (name, template) => `# ${name}
15447
+
15448
+ ${template === "empty" ? "AgentDeploy \u7A7A\u6A21\u677F\u9879\u76EE\u2014\u2014**\u4EC5\u9879\u76EE\u9AA8\u67B6**\uFF1A\u6CA1\u6709 functions/ \u76EE\u5F55\uFF0C\u4E5F\u6CA1\u6709\u524D\u7AEF\u5DE5\u7A0B\u3002" : "AgentDeploy \u4E91\u51FD\u6570\u9879\u76EE\uFF08\u6A21\u677F\uFF1A" + template + "\uFF09\u2014\u2014**\u53EA\u6709 functions/ \u4E91\u51FD\u6570\uFF0C\u6CA1\u6709\u524D\u7AEF\u5DE5\u7A0B**\u3002"}
15449
+
15450
+ ## \u5E38\u7528\u547D\u4EE4
15451
+
15452
+ - \`pnpm dev\`\uFF08= \`adep dev\`\uFF09\uFF1A**\u51FD\u6570\u4FA7**\u6A21\u62DF\u8FD0\u884C\u65F6\u2014\u2014\u8FDB\u7A0B\u5185\u6267\u884C\u4E91\u51FD\u6570\uFF0C\u4E0D\u8FDE\u4E91\u7AEF\u3001\u4E0D\u88C5 Docker\uFF0C
15453
+ \u65AD\u7F51\u4E5F\u80FD\u5F00\u53D1\uFF1B\u81EA\u52A8\u88C5\u914D \`cloud.db\` / \`cloud.storage\` / \`cloud.realtime\`\uFF0C\u6587\u4EF6\u53D8\u66F4\u81EA\u52A8\u70ED\u91CD\u8F7D\u3002
15454
+ \u542F\u52A8\u6A2A\u5E45\u4F1A\u6253\u5370\u4E00\u6761**\u53EF\u76F4\u63A5\u590D\u5236**\u7684 curl \u547D\u4EE4\uFF08\u5F62\u5982 \`curl http://127.0.0.1:8787/api/hello\`\uFF09\uFF0C
15455
+ \u7AEF\u53E3\u88AB\u5360\u7528\u4F1A\u81EA\u52A8\u987A\u5EF6\uFF0C\u4EE5\u6A2A\u5E45\u5B9E\u9645\u6253\u5370\u7684\u4E3A\u51C6\u3002
15456
+ - \`pnpm serve\`\uFF08= \`adep serve\`\uFF09\uFF1A\u5F00\u53D1\u6001\u670D\u52A1\u5668\uFF08\u51FD\u6570 \`/api/{prefix}/{fn}\` + \`/healthz\` + \u9759\u6001\u6258\u7BA1\uFF09
15457
+ - \`pnpm deploy\`\uFF08= \`adep publish --only functions\`\uFF09\uFF1A\u589E\u91CF\u90E8\u7F72\u4E91\u51FD\u6570\uFF08\u5BF9\u6BD4\u8FDC\u7AEF\u54C8\u5E0C \u2192 \u4EC5\u4E0A\u4F20\u53D8\u66F4 \u2192 \u53D1\u5E03 \u2192 \u8F93\u51FA\u8BBF\u95EE\u57DF\u540D\uFF09
15458
+ - \`pnpm doctor\`\uFF08= \`adep doctor\`\uFF09\uFF1A\u672C\u5730\u73AF\u5883\u79BB\u7EBF\u8BCA\u65AD
15459
+
15460
+ > \u672C\u6A21\u677F**\u6CA1\u6709** \`build\` / \`site:deploy\` \u811A\u672C\uFF1A\u6CA1\u6709\u524D\u7AEF\u5DE5\u7A0B\u5C31\u6CA1\u6709\u524D\u7AEF\u4EA7\u7269\u53EF\u6784\u5EFA\u3002
15461
+ > \u9700\u8981\u524D\u7AEF\uFF08Vue 3 + Vite\uFF09\u8BF7\u6539\u7528 \`adep init <name> -t fullstack\`\u3002
15462
+
15463
+ ## pnpm \u4E0E\u4F9D\u8D56\u6784\u5EFA\u811A\u672C\uFF08pnpm 10 \u8D77\u9ED8\u8BA4\u4E0D\u8DD1\uFF09
15464
+
15465
+ \u9879\u76EE\u6839\u7684 \`pnpm-workspace.yaml\` \u5DF2\u653E\u884C \`esbuild\` \u7684\u6784\u5EFA\u811A\u672C\uFF08\`onlyBuiltDependencies\` \u4E0E
15466
+ \`allowBuilds\` \u53CC\u5199\uFF1Apnpm 10 \u8BFB\u524D\u8005\uFF0Cpnpm 11+ \u8BFB\u540E\u8005\uFF09\u3002pnpm 10 \u8D77**\u9ED8\u8BA4\u4E0D\u6267\u884C\u4F9D\u8D56\u7684
15467
+ \u6784\u5EFA\u811A\u672C**\uFF0C\u5220\u6389\u8FD9\u4EFD\u914D\u7F6E\u540E \`pnpm install\` \u4F1A\u4EE5 \`ERR_PNPM_IGNORED_BUILDS\` \u62A5\u9519
15468
+ \uFF08\`@adep/cli\` \u4F9D\u8D56 esbuild\uFF0C\u5176\u539F\u751F\u4E8C\u8FDB\u5236\u6CA1\u51C6\u5907\u597D\uFF0C\u6784\u5EFA\u53EF\u80FD\u5931\u8D25\uFF09\u3002\u4ECD\u7528 pnpm 9 \u65F6\u7B49\u4EF7\u5199\u6CD5\u662F\u5728
15469
+ \`package.json\` \u91CC\u5199 \`"pnpm": { "onlyBuiltDependencies": ["esbuild"] }\`\u3002
15470
+
15471
+ ${DOCKER_README_SECTION()}
15472
+
15473
+ ## \u76EE\u5F55\u7ED3\u6784
15474
+
15475
+ - \`package.json\`\uFF1A\u5E94\u7528\u5B9A\u4E49\uFF08\u4EC5 \`@adep/cli\` \u4F9D\u8D56\uFF1B**\u65E0\u524D\u7AEF\u4F9D\u8D56**\uFF09
15476
+ - \`adep.config.ts\`\uFF1A\u9879\u76EE\u914D\u7F6E\uFF08name / template / functionsDir / functions_prefix\uFF0C\u9ED8\u8BA4 /api\uFF09
15477
+ - \`functions/\`\uFF1A\u4E91\u51FD\u6570\u76EE\u5F55\u2014\u2014\`functions/<name>.ts\` \u4E0E \`functions/<name>/index.ts\`
15478
+ \u662F\u540C\u4E00\u4E2A\u51FD\u6570\u7684\u4E24\u79CD**\u7B49\u4EF7**\u5199\u6CD5\uFF08\u540E\u8005\u4E3A\u76EE\u5F55\u5F62\u6001\uFF0C\u5165\u53E3\u56FA\u5B9A \`index.ts\`\uFF0C\u76EE\u5F55\u5185\u5176\u4F59\u6587\u4EF6\u662F\u8BE5
15479
+ \u51FD\u6570\u7684\u79C1\u6709\u6587\u4EF6\uFF09\uFF1B\u9ED8\u8BA4\u5BFC\u51FA \`(ctx: AdepContext) => Response\`\u3002\`functions/_shared/**\` \u662F
15480
+ \u9879\u76EE\u7EA7\u5171\u4EAB\u6E90\u7801\uFF08\u4FDD\u7559\u5B57\uFF0C\u5168\u9879\u76EE\u5355\u4EFD\uFF0C\u4E0D\u5C5E\u4E8E\u4EFB\u4F55\u51FD\u6570\uFF09\u3002\u8BE6\u89C1 \`functions/README.md\`
15481
+ - \`tsconfig.json\`\uFF1ATypeScript \u7F16\u8F91\u5668\u914D\u7F6E\uFF08strict + noEmit\uFF09
15482
+ - \`adep.d.ts\`\uFF1A\u4E91\u51FD\u6570\u4E0A\u4E0B\u6587\u73AF\u5883\u7C7B\u578B\u58F0\u660E\uFF08\`ctx: AdepContext\` \u8865\u5168\uFF0C\u65E0\u9700\u88C5\u4F9D\u8D56\uFF09
15483
+
15484
+ ## \u4E91\u51FD\u6570\u8DEF\u7531\u524D\u7F00\uFF08functions_prefix\uFF09
15485
+
15486
+ \`adep.config.ts\` \u7684 \`functions_prefix\`\uFF08\u9ED8\u8BA4 \`/api\`\uFF09\uFF1A
15487
+ - \`adep dev\`\uFF1A\`/{prefix}/{fn}\`\uFF0C\u5982 \`/api/hello\`\u3002
15488
+ - \`adep serve\`\uFF1A\`/api/{prefix}/{fn}\`\uFF08\u524D\u7F00\u62FC\u63A5\uFF09\u3002
15489
+ - **\u8FB9\u754C**\uFF1A\u53EA\u5F71\u54CD\u672C\u5730 HTTP \u5165\u53E3\uFF1B\u51FD\u6570\u4E92\u8C03 \`ctx.cloud.invoke('name')\` \u4E0E\u7EBF\u4E0A\u90E8\u7F72\u8DEF\u5F84\u6309\u51FD\u6570\u540D\uFF0C
15490
+ \u4E0D\u968F\u524D\u7F00\u53D8\u5316\uFF08\u4E0E\u7EBF\u4E0A\u540C\u6784\uFF09\u3002
15491
+
15492
+ ## \u4E91\u51FD\u6570\u7C7B\u578B\u63D0\u793A
15493
+
15494
+ \u7528 VSCode \u6253\u5F00\u672C\u76EE\u5F55\uFF0C\u4EFB\u610F \`functions/**\` \u4E0B\u7684 TS \u6587\u4EF6\u5373\u53EF\u83B7\u5F97 \`AdepContext\` / \`ctx.cloud.*\` \u8865\u5168\uFF1A
15495
+ \`tsconfig.json\` \u4F1A\u628A \`adep.d.ts\` \u7EB3\u5165 include\uFF0C\u51FD\u6570\u53C2\u6570\u5199 \`ctx: AdepContext\` \u5373\u53EF\u3002
15496
+ \`ctx\` \u4E0E \`AdepContext\` \u662F\u5168\u5C40\u5F00\u53D1\u671F\u58F0\u660E\uFF0C\u51FD\u6570\u8FD0\u884C\u671F\u7ECF\u53C2\u6570\u6CE8\u5165\uFF08\u4E0D\u8BFB\u53D6\u5168\u5C40\uFF09\u3002
15497
+
15498
+ ## \u6A21\u677F\u8BF4\u660E\uFF08adep init\uFF09
15499
+
15500
+ - \`adep init <name>\`\uFF1A\u9ED8\u8BA4 \`fullstack\` \u6A21\u677F\uFF08functions/ + web/src/ \u524D\u7AEF\u6E90\u7801 + database/\uFF09
15501
+ - \`adep init <name> -t function\`\uFF1A\u4EC5\u4E91\u51FD\u6570\uFF08\u5355\u4E2A\u793A\u4F8B\u51FD\u6570\uFF09\u2014\u2014**\u672C\u6A21\u677F**
15502
+ - \`adep init <name> -t empty\`\uFF1A\u7A7A\u6A21\u677F\uFF08\u4EC5\u9879\u76EE\u9AA8\u67B6\uFF09
15503
+ - \`adep init --list\`\uFF1A\u4ECE\u5E73\u53F0 /api/v1/templates \u5217\u51FA\u53EF\u7528\u6A21\u677F
15504
+ - \`adep init --list -s <server>\`\uFF1A\u6307\u5B9A\u5E73\u53F0\u5730\u5740
15505
+ `;
15292
15506
  var FUNCTION_INDEX = `// \u51FD\u6570\u6A21\u5757\u5165\u53E3\uFF1A\u9879\u76EE\u91CC\u7684\u6BCF\u4E2A\u51FD\u6570\u662F functions/ \u4E0B\u7684\u72EC\u7ACB\u6A21\u5757\uFF0C
15293
15507
  // \u9ED8\u8BA4\u5BFC\u51FA (ctx: AdepContext) => Response \u5F62\u72B6\u7684\u5904\u7406\u5668\uFF08\u5951\u7EA6\u89C1 adep.d.ts\uFF09\u3002
15294
15508
  //
@@ -15360,10 +15574,17 @@ var SHARED_ASSETS = {
15360
15574
  packageJson: (ctx) => [
15361
15575
  {
15362
15576
  path: "package.json",
15363
- content: ctx.template === "countdown" ? COUNTDOWN_PACKAGE_JSON(ctx.name, ctx.cliVersion) : PACKAGE_JSON(ctx.name, ctx.template, ctx.cliVersion)
15577
+ content: ctx.template === "countdown" ? COUNTDOWN_PACKAGE_JSON(ctx.name, ctx.cliVersion) : PACKAGE_JSON(ctx)
15578
+ }
15579
+ ],
15580
+ readme: (ctx) => [
15581
+ {
15582
+ path: "README.md",
15583
+ // README 的口径必须与 package.json 的 scripts 一致(两份不许各说一套):
15584
+ // 无前端模板给函数侧版本,否则会写出跑不通的 vite 命令与不存在的目录。
15585
+ content: ctx.hasFrontend ? README_FULLSTACK(ctx.name, ctx.template) : README_FUNCTION_ONLY(ctx.name, ctx.template)
15364
15586
  }
15365
15587
  ],
15366
- readme: (ctx) => [{ path: "README.md", content: README(ctx.name, ctx.template) }],
15367
15588
  adepConfig: (ctx) => [
15368
15589
  {
15369
15590
  path: "adep.config.ts",
@@ -15488,6 +15709,10 @@ function cliPackageRoot() {
15488
15709
  function localTemplateDir(code) {
15489
15710
  return join2(cliPackageRoot(), "src", "templates", code);
15490
15711
  }
15712
+ var FRONTEND_ASSETS = /* @__PURE__ */ new Set(["webSrc", "viteConfig", "indexHtml"]);
15713
+ function hasFrontendAssets(sharedAssets) {
15714
+ return (sharedAssets ?? []).some((asset) => FRONTEND_ASSETS.has(asset));
15715
+ }
15491
15716
  function templateFiles(code, name) {
15492
15717
  const generated = GENERATED_TEMPLATES[code];
15493
15718
  if (generated === void 0) {
@@ -15501,7 +15726,12 @@ function renderTemplatePackage(pkg, name) {
15501
15726
  const vars = { name, template: pkg.code };
15502
15727
  const dirFiles = renderTemplateFiles(pkg.files, vars, manifest2);
15503
15728
  const code = pkg.code;
15504
- const ctx = { name, template: code, cliVersion: cliVersionOf() };
15729
+ const ctx = {
15730
+ name,
15731
+ template: code,
15732
+ cliVersion: cliVersionOf(),
15733
+ hasFrontend: hasFrontendAssets(manifest2.sharedAssets)
15734
+ };
15505
15735
  const sharedFiles = (manifest2.sharedAssets ?? []).flatMap((assetName) => {
15506
15736
  const asset = SHARED_ASSETS[assetName];
15507
15737
  if (asset === void 0) {
package/dist/vite.js CHANGED
@@ -375,7 +375,9 @@ var WorkerFunctionExecutor = class {
375
375
  ...input.env === void 0 ? {} : { env: input.env },
376
376
  ...deps === void 0 ? {} : { deps },
377
377
  ...this.parity ? { parity: true } : {},
378
- ...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig }
378
+ ...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig },
379
+ // W2:预编译提示随 workerData 下发(结构化克隆可跨线程;缺省不传 = 全量编译路径)。
380
+ ...input.compileHints === void 0 ? {} : { compileHints: input.compileHints }
379
381
  },
380
382
  resourceLimits: { maxOldGenerationSizeMb: memoryLimitMb }
381
383
  });
@@ -469,14 +471,14 @@ var sqliteDialect = {
469
471
  placeholder: () => "?",
470
472
  quote: (identifier) => `"${identifier.replace(/"/g, '""')}"`,
471
473
  lastInsertIdClause: () => "",
472
- upsertConflictClause: (columns) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")}) DO NOTHING`
474
+ upsertConflictClause: (columns, doUpdateSet) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")})` + (doUpdateSet ? ` DO UPDATE SET ${doUpdateSet}` : " DO NOTHING")
473
475
  };
474
476
  var postgresDialect = {
475
477
  name: "postgres",
476
478
  placeholder: (index) => `$${index + 1}`,
477
479
  quote: (identifier) => `"${identifier.replace(/"/g, '""')}"`,
478
480
  lastInsertIdClause: () => " RETURNING id",
479
- upsertConflictClause: (columns) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")}) DO NOTHING`
481
+ upsertConflictClause: (columns, doUpdateSet) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")})` + (doUpdateSet ? ` DO UPDATE SET ${doUpdateSet}` : " DO NOTHING")
480
482
  };
481
483
  function dialectFor(driver) {
482
484
  return driver.engine === "pg" ? postgresDialect : sqliteDialect;
@@ -608,6 +610,17 @@ async function appendChange(driver, table, op, id, ownerKey, before, after) {
608
610
  );
609
611
  }
610
612
  async function runOwnedWrite(driver, fn) {
613
+ if (driver.engine === "pg") {
614
+ await driver.run("BEGIN");
615
+ try {
616
+ await fn(driver);
617
+ await driver.run("COMMIT");
618
+ } catch (error) {
619
+ await driver.run("ROLLBACK");
620
+ throw error;
621
+ }
622
+ return;
623
+ }
611
624
  await driver.run("SAVEPOINT _adep_change");
612
625
  try {
613
626
  await fn(driver);
@@ -792,6 +805,9 @@ function compileWhere(wheres, dialect, params) {
792
805
  if (value === null) {
793
806
  if (where.operator === "=") return `${quoted} IS NULL`;
794
807
  if (where.operator === "!=") return `${quoted} IS NOT NULL`;
808
+ throw unsafeOperation(
809
+ `NULL \u53EA\u80FD\u4E0E = / != \u6BD4\u8F83\uFF08${where.operator} NULL \u6052\u4E3A UNKNOWN\uFF0C\u4F1A\u9759\u9ED8\u8FD4\u56DE\u7A7A\u96C6\uFF09\uFF1A\u5217 ${where.column}`
810
+ );
795
811
  }
796
812
  const mark = pushParam(params, dialect, value);
797
813
  return `${quoted} ${where.operator} ${mark}`;
@@ -866,6 +882,44 @@ function compileInsertMany(table, rows, dialect) {
866
882
  params
867
883
  };
868
884
  }
885
+ function resolveUpsertPlan(row, options) {
886
+ const target = [...options.target];
887
+ if (target.length === 0) {
888
+ throw unsafeOperation("upsert \u7684 target \u5FC5\u987B\u81F3\u5C11\u4E00\u5217\uFF08\u51B2\u7A81\u5224\u5B9A\u65E0\u5217\u5219\u65E0\u4ECE\u8C08\u8D77\uFF09");
889
+ }
890
+ target.forEach(assertUserColumn);
891
+ const targetSet = new Set(target);
892
+ const rowColumns = new Set(Object.keys(row));
893
+ if (rowColumns.size === 0) {
894
+ throw unsafeOperation("upsert \u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u5B57\u6BB5");
895
+ }
896
+ const update = options.update === void 0 ? [...rowColumns].filter((name) => !targetSet.has(name)) : [...options.update];
897
+ update.forEach(assertUserColumn);
898
+ const overlapping = update.filter((name) => targetSet.has(name));
899
+ if (overlapping.length > 0) {
900
+ throw unsafeOperation(`upsert \u7684 update \u5217\u4E0D\u80FD\u4E0E target \u91CD\u53E0\uFF08\u51B2\u7A81\u884C\u4E3B\u952E\u4E0D\u6539\uFF09\uFF1A${overlapping.join(", ")}`);
901
+ }
902
+ const missing = update.filter((name) => !rowColumns.has(name));
903
+ if (missing.length > 0) {
904
+ throw unsafeOperation(`upsert \u7684 update \u5217\u5FC5\u987B\u51FA\u73B0\u5728 row \u4E2D\uFF08\u503C\u53D6\u81EA row\uFF09\uFF1A${missing.join(", ")}`);
905
+ }
906
+ return { target, update };
907
+ }
908
+ function compileUpsert(table, row, options, dialect) {
909
+ const { target, update } = resolveUpsertPlan(row, options);
910
+ const params = [];
911
+ const entries = Object.entries(row);
912
+ const columns = entries.map(([name]) => {
913
+ assertUserColumn(name);
914
+ return dialect.quote(name);
915
+ }).join(", ");
916
+ const marks = entries.map(([, value]) => pushParam(params, dialect, value));
917
+ const doUpdateSet = update.length === 0 ? null : update.map((name) => `${dialect.quote(name)} = ${pushParam(params, dialect, row[name])}`).join(", ");
918
+ return {
919
+ sql: `INSERT INTO ${dialect.quote(table)} (${columns}) VALUES (${marks.join(", ")})${dialect.upsertConflictClause(target, doUpdateSet)}`,
920
+ params
921
+ };
922
+ }
869
923
  function compileUpdate(table, wheres, values, dialect) {
870
924
  const entries = Object.entries(values);
871
925
  if (entries.length === 0) {
@@ -1006,6 +1060,17 @@ function createTableBuilder(table, driver, dialect, options = {}) {
1006
1060
  const compiled = compileInsertMany(state.table, rows, dialect);
1007
1061
  await driver.run(compiled.sql, compiled.params);
1008
1062
  },
1063
+ async upsert(row, conflict) {
1064
+ guardWrite();
1065
+ Object.keys(row).forEach(assertUserColumn);
1066
+ if (await resolveOwned(state, driver)) {
1067
+ throw unsafeOperation(
1068
+ "upsert \u4E0D\u652F\u6301 owned \u8868\uFF1A\u53D8\u66F4\u6D41\u65E0\u6CD5\u8868\u8FBE\u300C\u63D2\u5165\u8FD8\u662F\u66F4\u65B0\u300D\u7684\u4E8C\u4E49\uFF08before/after \u987B\u786E\u5B9A\uFF09\uFF0C\u8BF7\u6539\u7528 insert / update"
1069
+ );
1070
+ }
1071
+ const compiled = compileUpsert(state.table, row, conflict, dialect);
1072
+ await driver.run(compiled.sql, compiled.params);
1073
+ },
1009
1074
  async update(values) {
1010
1075
  guardWrite();
1011
1076
  assertHasWhere(state);
@@ -1144,13 +1209,23 @@ function createCloudDb(driver, options = {}) {
1144
1209
  var CLOUD_DB_SPEC = {
1145
1210
  kind: "cloud-db",
1146
1211
  rootMethod: "table",
1147
- stepMethods: ["select", "where", "orderBy", "limit", "offset"],
1148
- terminalMethods: ["get", "first", "count", "insert", "insertMany", "update", "delete"],
1212
+ // 规格清单必须与构建器公开方法面一致(防漂移门 spec-drift.test.ts 双向咬合):
1213
+ // - owned:DB-006 的 owned 声明(step);
1214
+ // - execute:BUG-4 统一执行入口(direct,宿主侧 DB_RPC.execute 分支早已在);
1215
+ // - upsert:DB-010 终端(漏登记过一次,真机 500,见 spec-drift.test.ts 头注释)。
1216
+ stepMethods: ["select", "where", "orderBy", "limit", "offset", "owned"],
1217
+ terminalMethods: ["get", "first", "count", "insert", "insertMany", "update", "delete", "upsert"],
1149
1218
  // CF-013:writeQuery 是 D1 shim 的写路径(INSERT/UPDATE/DELETE),与 query 并列直通方法。
1150
- directMethods: ["query", "writeQuery", "changes"],
1219
+ directMethods: ["query", "writeQuery", "execute", "changes"],
1151
1220
  transactionMethod: "transaction"
1152
1221
  };
1153
- var WRITE_TERMINALS = /* @__PURE__ */ new Set(["insert", "insertMany", "update", "delete"]);
1222
+ var WRITE_TERMINALS = /* @__PURE__ */ new Set([
1223
+ "insert",
1224
+ "insertMany",
1225
+ "update",
1226
+ "delete",
1227
+ "upsert"
1228
+ ]);
1154
1229
  function errorWithCode(error) {
1155
1230
  if (error instanceof Error) {
1156
1231
  const sqlite = /no such table: (\S+)/.exec(error.message);
@@ -3745,9 +3820,14 @@ function runLsof(port) {
3745
3820
  );
3746
3821
  });
3747
3822
  }
3823
+ function defaultOccupierExecutor(port) {
3824
+ if (process.platform === "win32") {
3825
+ return Promise.reject(new Error("lsof unavailable on win32"));
3826
+ }
3827
+ return runLsof(port);
3828
+ }
3748
3829
  async function lookupPortOccupier(port, options = {}) {
3749
- if (process.platform === "win32") return null;
3750
- const execute = options.execute ?? runLsof;
3830
+ const execute = options.execute ?? defaultOccupierExecutor;
3751
3831
  try {
3752
3832
  return parsePortOccupier(await execute(port));
3753
3833
  } catch {
@@ -3823,6 +3903,11 @@ async function loadSimEnv(cwd, config = {}) {
3823
3903
  return merged;
3824
3904
  }
3825
3905
 
3906
+ // packages/cli/src/config.ts
3907
+ function normalizeFunctionsPrefix(prefix) {
3908
+ return prefix.replace(/^\/+|\/+$/g, "");
3909
+ }
3910
+
3826
3911
  // packages/cli/src/sim/fetch-config.ts
3827
3912
  var LOCAL_FETCH_TIMEOUT_MS_DEFAULT = 1e4;
3828
3913
  function resolveLocalFetchConfig(simEnv) {
@@ -4320,13 +4405,32 @@ var StateObjectRuntime = class {
4320
4405
  }
4321
4406
  /**
4322
4407
  * alarm 轮询:把到期对象唤醒并调 onAlarm(CF-037)。
4408
+ * - 到期集合 = 后端落库到期记录 ∪ **驻留实例的内存 alarmAt(驻留时以内存值为准)**:
4409
+ * `setAlarm`/`clearAlarm` 只写内存、`alarmAt` 随 `flush()` 落库——若 pump 只读后端,
4410
+ * 「setAlarm 后没 flush」会静默丢调度(rift-brawl 实锤:先 flush 再 setAlarm,闹钟永不触发),
4411
+ * 反向「clearAlarm 后没 flush」会因 DB 残留到期值误触发。重启续接仍以落库值为准
4412
+ * (实例不驻留时后端值是唯一事实;要重启不丢 alarm,方法内仍须 flush——见 features/state-objects.md)。
4323
4413
  * - onAlarm 后统一持久化(flush):onAlarm 内改的 state 与 setAlarm 重调度 / clearAlarm
4324
4414
  * 的新 alarmAt 都落库;
4325
4415
  * - 单对象 onAlarm 抛错**不阻塞**同 tick 其余对象:失败对象不落库、alarmAt 保留
4326
4416
  * → 下轮 dueAlarms 仍命中重试;错误折叠进 failed(不泄漏内部栈)。
4327
4417
  */
4328
4418
  async pump(now) {
4329
- const due = await this.backend.dueAlarms(now);
4419
+ const dueMap = /* @__PURE__ */ new Map();
4420
+ for (const d of await this.backend.dueAlarms(now)) {
4421
+ dueMap.set(this.key(d.type, d.id), d);
4422
+ }
4423
+ for (const [k, inst] of this.instances) {
4424
+ const typeName = inst.constructor.typeName;
4425
+ if (typeName === void 0) continue;
4426
+ const raw = inst;
4427
+ if (raw.alarmAt === null || raw.alarmAt > now) {
4428
+ dueMap.delete(k);
4429
+ continue;
4430
+ }
4431
+ dueMap.set(k, { type: typeName, id: inst.id, alarmAt: raw.alarmAt });
4432
+ }
4433
+ const due = [...dueMap.values()].toSorted((a, b) => a.alarmAt - b.alarmAt);
4330
4434
  const fired = [];
4331
4435
  const failed = [];
4332
4436
  for (const d of due) {
@@ -4368,8 +4472,9 @@ function createProjectDriverStateBackend(driver) {
4368
4472
  let ensured = false;
4369
4473
  const ensureTable = async () => {
4370
4474
  if (ensured) return;
4475
+ const tsType = driver.engine === "pg" ? "BIGINT" : "INTEGER";
4371
4476
  await driver.run(
4372
- `CREATE TABLE IF NOT EXISTS ${STATE_OBJECTS_TABLE} ("type" TEXT NOT NULL, "id" TEXT NOT NULL, "state" TEXT NOT NULL, "alarm_at" INTEGER, "updated_at" INTEGER NOT NULL, PRIMARY KEY ("type", "id"))`
4477
+ `CREATE TABLE IF NOT EXISTS ${STATE_OBJECTS_TABLE} ("type" TEXT NOT NULL, "id" TEXT NOT NULL, "state" TEXT NOT NULL, "alarm_at" ${tsType}, "updated_at" ${tsType} NOT NULL, PRIMARY KEY ("type", "id"))`
4373
4478
  );
4374
4479
  ensured = true;
4375
4480
  };
@@ -4889,7 +4994,7 @@ ${DYNAMIC_IMPORT_HINT}` : "";
4889
4994
  if (typeof code === "string") wrapped.code = code;
4890
4995
  return wrapped;
4891
4996
  }
4892
- function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false) {
4997
+ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false, hints) {
4893
4998
  const cached = cache.get(path);
4894
4999
  if (cached !== void 0) return cached;
4895
5000
  const source = files[path];
@@ -4910,7 +5015,7 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
4910
5015
  }
4911
5016
  const resolved = resolveModulePath(dir, request, files);
4912
5017
  if (resolved !== null) {
4913
- return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths);
5018
+ return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths, hints);
4914
5019
  }
4915
5020
  if (resolveBare !== void 0 && !request.startsWith("./") && !request.startsWith("../")) {
4916
5021
  const cachedModule = bareCache?.get(request);
@@ -4925,21 +5030,33 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
4925
5030
  error.code = SANDBOX_BUILTIN_REJECTED;
4926
5031
  throw error;
4927
5032
  };
4928
- let transformed;
5033
+ const hint = hints?.[path];
5034
+ let scriptSource;
4929
5035
  try {
4930
- transformed = transformExports(transpile(source));
5036
+ scriptSource = hint !== void 0 ? hint.js : `${WRAPPER_PREFIX}${transformExports(transpile(source))}${WRAPPER_SUFFIX}`;
4931
5037
  } catch (error) {
4932
5038
  throw syntaxErrorWithLocation(error, path, source);
4933
5039
  }
4934
5040
  const context = createSandboxContext(sandboxGlobals);
4935
5041
  let wrapper;
4936
5042
  try {
4937
- wrapper = vm.runInContext(
4938
- `(function (module, exports, require) { ${transformed}
4939
- })`,
4940
- context,
4941
- { filename: path }
4942
- );
5043
+ if (hint !== void 0 && hint.cachedData !== void 0) {
5044
+ const script = new vm.Script(scriptSource, {
5045
+ filename: path,
5046
+ cachedData: Buffer.from(
5047
+ hint.cachedData.buffer,
5048
+ hint.cachedData.byteOffset,
5049
+ hint.cachedData.byteLength
5050
+ )
5051
+ });
5052
+ if (script.cachedDataRejected !== true) {
5053
+ wrapper = script.runInContext(context);
5054
+ } else {
5055
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
5056
+ }
5057
+ } else {
5058
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
5059
+ }
4943
5060
  } catch (error) {
4944
5061
  throw syntaxErrorWithLocation(error, path, source);
4945
5062
  }
@@ -4949,7 +5066,9 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
4949
5066
  }
4950
5067
  return exports;
4951
5068
  }
4952
- function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false) {
5069
+ var WRAPPER_PREFIX = "(function (module, exports, require) { ";
5070
+ var WRAPPER_SUFFIX = " \n})";
5071
+ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false, hints) {
4953
5072
  const cache = /* @__PURE__ */ new Map();
4954
5073
  const bareCache = /* @__PURE__ */ new Map();
4955
5074
  const entryExports = loadModule(
@@ -4959,11 +5078,14 @@ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPat
4959
5078
  cache,
4960
5079
  resolveBare,
4961
5080
  bareCache,
4962
- strictPaths
5081
+ strictPaths,
5082
+ hints
4963
5083
  );
4964
5084
  const handler = entryExports["default"];
4965
5085
  if (typeof handler !== "function") {
4966
- throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570`);
5086
+ const base = entry.replace(/^.*\//, "");
5087
+ const hint = base === "state-objects.ts" || entry.startsWith("durable-objects/") ? '\u3002\u8BE5\u6587\u4EF6\u662F\u72B6\u6001\u5BF9\u8C61\u58F0\u660E\u6587\u4EF6\uFF0C\u653E\u5728 functions/ \u76EE\u5F55\u5185\u4F1A\u540C\u65F6\u88AB\u5F53\u4F5C\u4E91\u51FD\u6570\u5165\u53E3\uFF1A\u8865\u4E00\u4E2A default \u5BFC\u51FA\u7684\u5360\u4F4D handler\uFF0C\u4F8B\u5982 `export default async () => ({ error: "state objects \u8BF7\u8D70 /api/state/<type>/<id>/<method>" })`' : "";
5088
+ throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570${hint}`);
4967
5089
  }
4968
5090
  return { handler };
4969
5091
  }
@@ -5706,7 +5828,9 @@ function runWorker(input, port) {
5706
5828
  sandboxGlobals,
5707
5829
  input.deps === void 0 ? void 0 : createBareResolver(input.deps),
5708
5830
  // CORE-154:--parity 严格模式连带 `../` 越根引用报错(与容器形态真实 fs 同形)。
5709
- input.parity === true
5831
+ input.parity === true,
5832
+ // W2:预编译提示透传(缺省 undefined = 全量编译路径,零回归)。
5833
+ input.compileHints
5710
5834
  );
5711
5835
  const result = Promise.resolve(handler(ctx));
5712
5836
  void result.then(
@@ -6070,7 +6194,7 @@ async function loadConfig(cwd) {
6070
6194
  return {
6071
6195
  name: config?.name ?? name,
6072
6196
  functionsDir: config?.functionsDir ?? "functions",
6073
- functionsPrefix: config?.functions_prefix ?? "",
6197
+ functionsPrefix: normalizeFunctionsPrefix(config?.functions_prefix ?? ""),
6074
6198
  ...config?.environment === void 0 ? {} : { environment: config.environment },
6075
6199
  ...config?.db_environment === void 0 ? {} : { dbEnvironment: config.db_environment }
6076
6200
  };
@@ -6078,7 +6202,7 @@ async function loadConfig(cwd) {
6078
6202
  var parseEnvFile = parseEnv;
6079
6203
  function resolveRouteFnName(pathname, prefix) {
6080
6204
  const segments = pathname.split("/").filter((segment) => segment.length > 0);
6081
- const normalizedPrefix = prefix.replace(/^\/+|\/+$/g, "");
6205
+ const normalizedPrefix = normalizeFunctionsPrefix(prefix);
6082
6206
  if (normalizedPrefix.length === 0) {
6083
6207
  const first = segments[0];
6084
6208
  return first === void 0 ? {} : { fnName: first };
@@ -6122,7 +6246,7 @@ async function startDevServer(options) {
6122
6246
  `));
6123
6247
  const config = await loadConfig(cwd);
6124
6248
  if (options.prefix !== void 0) {
6125
- config.functionsPrefix = options.prefix.replace(/^\/+|\/+$/g, "");
6249
+ config.functionsPrefix = normalizeFunctionsPrefix(options.prefix);
6126
6250
  }
6127
6251
  const functionsDir = join10(cwd, config.functionsDir);
6128
6252
  const coldStartAt = Date.now();
@@ -6300,7 +6424,7 @@ async function startDevServer(options) {
6300
6424
  return;
6301
6425
  }
6302
6426
  if (fnName === "state") {
6303
- const normalizedPrefix = config.functionsPrefix.replace(/^\/+|\/+$/g, "");
6427
+ const normalizedPrefix = normalizeFunctionsPrefix(config.functionsPrefix);
6304
6428
  const rest = normalizedPrefix.length === 0 ? url.pathname : url.pathname.replace(new RegExp(`^/${normalizedPrefix}`), "");
6305
6429
  const parsed = parseStatePath(rest);
6306
6430
  if (parsed === null) {
@@ -6411,13 +6535,19 @@ async function startDevServer(options) {
6411
6535
  const baseUrl = `http://127.0.0.1:${actualPort}`;
6412
6536
  runtime.storage.signer.baseUrl = baseUrl;
6413
6537
  const coldStartMs = Date.now() - coldStartAt;
6414
- const curlPath = config.functionsPrefix.length === 0 ? "/hello" : `/${config.functionsPrefix}/hello`;
6538
+ const functionNames = listFunctionNames(files);
6539
+ const firstFunction = functionNames[0];
6540
+ const curlPath = firstFunction === void 0 ? null : config.functionsPrefix.length === 0 ? `/${firstFunction}` : `/${config.functionsPrefix}/${firstFunction}`;
6415
6541
  const dbLabel = db.mode === "sqlite" ? `SQLite \u771F\u5B9E\u5E93${db.module === null ? "" : `\uFF08${db.module}\uFF09`}` : "sim \u5F15\u64CE\uFF08\u5185\u7F6E\u6A21\u62DF\uFF09";
6416
6542
  const dbTargetText = db.file === null ? simDbTarget(cwd) : displayPath(cwd, db.file);
6417
6543
  log(
6418
6544
  `[adep] dev server listening on ${baseUrl}\uFF08\u672C\u5730\u8FD0\u884C\u65F6 / ${dbLabel}\uFF0C\u51B7\u542F\u52A8 ${coldStartMs}ms\uFF09`
6419
6545
  );
6420
- log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
6546
+ if (curlPath === null) {
6547
+ log("[adep] functions/ \u76EE\u5F55\u4E3A\u7A7A\uFF1A\u6682\u65E0\u51FD\u6570\u53EF\u8C03\u7528\u3002\u65B0\u5EFA functions/<name>.ts \u540E\u81EA\u52A8\u70ED\u91CD\u8F7D\u3002");
6548
+ } else {
6549
+ log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
6550
+ }
6421
6551
  printBoundaries(log);
6422
6552
  if (simUser.resolver !== void 0) {
6423
6553
  log(
@@ -489,7 +489,7 @@ ${DYNAMIC_IMPORT_HINT}` : "";
489
489
  if (typeof code === "string") wrapped.code = code;
490
490
  return wrapped;
491
491
  }
492
- function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false) {
492
+ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false, hints) {
493
493
  const cached = cache.get(path);
494
494
  if (cached !== void 0) return cached;
495
495
  const source = files[path];
@@ -510,7 +510,7 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
510
510
  }
511
511
  const resolved = resolveModulePath(dir, request, files);
512
512
  if (resolved !== null) {
513
- return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths);
513
+ return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths, hints);
514
514
  }
515
515
  if (resolveBare !== void 0 && !request.startsWith("./") && !request.startsWith("../")) {
516
516
  const cachedModule = bareCache?.get(request);
@@ -525,21 +525,33 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
525
525
  error.code = SANDBOX_BUILTIN_REJECTED;
526
526
  throw error;
527
527
  };
528
- let transformed;
528
+ const hint = hints?.[path];
529
+ let scriptSource;
529
530
  try {
530
- transformed = transformExports(transpile(source));
531
+ scriptSource = hint !== void 0 ? hint.js : `${WRAPPER_PREFIX}${transformExports(transpile(source))}${WRAPPER_SUFFIX}`;
531
532
  } catch (error) {
532
533
  throw syntaxErrorWithLocation(error, path, source);
533
534
  }
534
535
  const context = createSandboxContext(sandboxGlobals);
535
536
  let wrapper;
536
537
  try {
537
- wrapper = vm.runInContext(
538
- `(function (module, exports, require) { ${transformed}
539
- })`,
540
- context,
541
- { filename: path }
542
- );
538
+ if (hint !== void 0 && hint.cachedData !== void 0) {
539
+ const script = new vm.Script(scriptSource, {
540
+ filename: path,
541
+ cachedData: Buffer.from(
542
+ hint.cachedData.buffer,
543
+ hint.cachedData.byteOffset,
544
+ hint.cachedData.byteLength
545
+ )
546
+ });
547
+ if (script.cachedDataRejected !== true) {
548
+ wrapper = script.runInContext(context);
549
+ } else {
550
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
551
+ }
552
+ } else {
553
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
554
+ }
543
555
  } catch (error) {
544
556
  throw syntaxErrorWithLocation(error, path, source);
545
557
  }
@@ -549,7 +561,9 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
549
561
  }
550
562
  return exports;
551
563
  }
552
- function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false) {
564
+ var WRAPPER_PREFIX = "(function (module, exports, require) { ";
565
+ var WRAPPER_SUFFIX = " \n})";
566
+ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false, hints) {
553
567
  const cache = /* @__PURE__ */ new Map();
554
568
  const bareCache = /* @__PURE__ */ new Map();
555
569
  const entryExports = loadModule(
@@ -559,11 +573,14 @@ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPat
559
573
  cache,
560
574
  resolveBare,
561
575
  bareCache,
562
- strictPaths
576
+ strictPaths,
577
+ hints
563
578
  );
564
579
  const handler = entryExports["default"];
565
580
  if (typeof handler !== "function") {
566
- throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570`);
581
+ const base = entry.replace(/^.*\//, "");
582
+ const hint = base === "state-objects.ts" || entry.startsWith("durable-objects/") ? '\u3002\u8BE5\u6587\u4EF6\u662F\u72B6\u6001\u5BF9\u8C61\u58F0\u660E\u6587\u4EF6\uFF0C\u653E\u5728 functions/ \u76EE\u5F55\u5185\u4F1A\u540C\u65F6\u88AB\u5F53\u4F5C\u4E91\u51FD\u6570\u5165\u53E3\uFF1A\u8865\u4E00\u4E2A default \u5BFC\u51FA\u7684\u5360\u4F4D handler\uFF0C\u4F8B\u5982 `export default async () => ({ error: "state objects \u8BF7\u8D70 /api/state/<type>/<id>/<method>" })`' : "";
583
+ throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570${hint}`);
567
584
  }
568
585
  return { handler };
569
586
  }
@@ -1254,7 +1271,9 @@ function runWorker(input, port) {
1254
1271
  sandboxGlobals,
1255
1272
  input.deps === void 0 ? void 0 : createBareResolver(input.deps),
1256
1273
  // CORE-154:--parity 严格模式连带 `../` 越根引用报错(与容器形态真实 fs 同形)。
1257
- input.parity === true
1274
+ input.parity === true,
1275
+ // W2:预编译提示透传(缺省 undefined = 全量编译路径,零回归)。
1276
+ input.compileHints
1258
1277
  );
1259
1278
  const result = Promise.resolve(handler(ctx));
1260
1279
  void result.then(
package/package.json CHANGED
@@ -7,10 +7,10 @@
7
7
  },
8
8
  "homepage": "https://adep.top",
9
9
  "bugs": "https://gitcode.com/yunqiang_wu/ai-yunke/issues",
10
- "version": "0.5.6",
10
+ "version": "0.5.8",
11
11
  "adep": {
12
12
  "releaseTasks": [
13
- "CORE-193"
13
+ "CORE-485"
14
14
  ]
15
15
  },
16
16
  "type": "module",
@@ -36,13 +36,13 @@
36
36
  "yaml": "2.9.1",
37
37
  "zod": "^4.6.6",
38
38
  "@adep/app-runtime": "0.1.1",
39
- "@adep/cf-compat": "0.1.4",
40
39
  "@adep/crypto": "0.1.1",
40
+ "@adep/cf-compat": "0.1.4",
41
41
  "@adep/vite-plugin": "0.1.13",
42
- "@adep/runtime": "0.3.11"
42
+ "@adep/runtime": "0.3.16"
43
43
  },
44
44
  "devDependencies": {
45
- "@adep/types": "0.4.3"
45
+ "@adep/types": "0.4.5"
46
46
  },
47
47
  "scripts": {
48
48
  "test": "vitest run",
@@ -20,6 +20,6 @@
20
20
  "@capacitor/cli": "^7.0.0",
21
21
  "@capacitor/ios": "^7.0.0",
22
22
  "@capacitor/android": "^7.0.0",
23
- "typescript": "5.9.3"
23
+ "typescript": "6.0.3"
24
24
  }
25
25
  }