@adep/cli 0.5.7 → 0.5.9

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
@@ -36,10 +36,15 @@ var REALTIME_CAPABILITY_CODES = {
36
36
  subscriptionNotFound: "REALTIME_SUBSCRIPTION_NOT_FOUND",
37
37
  tooManySubscriptions: "REALTIME_TOO_MANY_SUBSCRIPTIONS",
38
38
  /** 线上独有:订阅授权策略(RT-002 `SubscriptionPolicy`)拒绝该 channel。 */
39
- channelDenied: "REALTIME_CHANNEL_DENIED"
39
+ channelDenied: "REALTIME_CHANNEL_DENIED",
40
+ /** 线上独有(RT-008):签票入参不合法(subject 缺失 / channels 非字符串数组 / TTL 越界)。 */
41
+ invalidArg: "REALTIME_INVALID_ARG",
42
+ /** 线上独有(RT-008):函数级签票超频(按项目固定窗口限流)。 */
43
+ ticketRateLimited: "REALTIME_TICKET_RATE_LIMITED"
40
44
  };
41
45
  var REALTIME_CAPABILITY_METHODS = [
42
46
  "publish",
47
+ "issueTicket",
43
48
  "subscribe",
44
49
  "receive",
45
50
  "unsubscribe"
@@ -375,7 +380,9 @@ var WorkerFunctionExecutor = class {
375
380
  ...input.env === void 0 ? {} : { env: input.env },
376
381
  ...deps === void 0 ? {} : { deps },
377
382
  ...this.parity ? { parity: true } : {},
378
- ...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig }
383
+ ...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig },
384
+ // W2:预编译提示随 workerData 下发(结构化克隆可跨线程;缺省不传 = 全量编译路径)。
385
+ ...input.compileHints === void 0 ? {} : { compileHints: input.compileHints }
379
386
  },
380
387
  resourceLimits: { maxOldGenerationSizeMb: memoryLimitMb }
381
388
  });
@@ -469,14 +476,14 @@ var sqliteDialect = {
469
476
  placeholder: () => "?",
470
477
  quote: (identifier) => `"${identifier.replace(/"/g, '""')}"`,
471
478
  lastInsertIdClause: () => "",
472
- upsertConflictClause: (columns) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")}) DO NOTHING`
479
+ upsertConflictClause: (columns, doUpdateSet) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")})` + (doUpdateSet ? ` DO UPDATE SET ${doUpdateSet}` : " DO NOTHING")
473
480
  };
474
481
  var postgresDialect = {
475
482
  name: "postgres",
476
483
  placeholder: (index) => `$${index + 1}`,
477
484
  quote: (identifier) => `"${identifier.replace(/"/g, '""')}"`,
478
485
  lastInsertIdClause: () => " RETURNING id",
479
- upsertConflictClause: (columns) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")}) DO NOTHING`
486
+ upsertConflictClause: (columns, doUpdateSet) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")})` + (doUpdateSet ? ` DO UPDATE SET ${doUpdateSet}` : " DO NOTHING")
480
487
  };
481
488
  function dialectFor(driver) {
482
489
  return driver.engine === "pg" ? postgresDialect : sqliteDialect;
@@ -803,6 +810,9 @@ function compileWhere(wheres, dialect, params) {
803
810
  if (value === null) {
804
811
  if (where.operator === "=") return `${quoted} IS NULL`;
805
812
  if (where.operator === "!=") return `${quoted} IS NOT NULL`;
813
+ throw unsafeOperation(
814
+ `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}`
815
+ );
806
816
  }
807
817
  const mark = pushParam(params, dialect, value);
808
818
  return `${quoted} ${where.operator} ${mark}`;
@@ -877,6 +887,44 @@ function compileInsertMany(table, rows, dialect) {
877
887
  params
878
888
  };
879
889
  }
890
+ function resolveUpsertPlan(row, options) {
891
+ const target = [...options.target];
892
+ if (target.length === 0) {
893
+ throw unsafeOperation("upsert \u7684 target \u5FC5\u987B\u81F3\u5C11\u4E00\u5217\uFF08\u51B2\u7A81\u5224\u5B9A\u65E0\u5217\u5219\u65E0\u4ECE\u8C08\u8D77\uFF09");
894
+ }
895
+ target.forEach(assertUserColumn);
896
+ const targetSet = new Set(target);
897
+ const rowColumns = new Set(Object.keys(row));
898
+ if (rowColumns.size === 0) {
899
+ throw unsafeOperation("upsert \u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u5B57\u6BB5");
900
+ }
901
+ const update = options.update === void 0 ? [...rowColumns].filter((name) => !targetSet.has(name)) : [...options.update];
902
+ update.forEach(assertUserColumn);
903
+ const overlapping = update.filter((name) => targetSet.has(name));
904
+ if (overlapping.length > 0) {
905
+ throw unsafeOperation(`upsert \u7684 update \u5217\u4E0D\u80FD\u4E0E target \u91CD\u53E0\uFF08\u51B2\u7A81\u884C\u4E3B\u952E\u4E0D\u6539\uFF09\uFF1A${overlapping.join(", ")}`);
906
+ }
907
+ const missing = update.filter((name) => !rowColumns.has(name));
908
+ if (missing.length > 0) {
909
+ throw unsafeOperation(`upsert \u7684 update \u5217\u5FC5\u987B\u51FA\u73B0\u5728 row \u4E2D\uFF08\u503C\u53D6\u81EA row\uFF09\uFF1A${missing.join(", ")}`);
910
+ }
911
+ return { target, update };
912
+ }
913
+ function compileUpsert(table, row, options, dialect) {
914
+ const { target, update } = resolveUpsertPlan(row, options);
915
+ const params = [];
916
+ const entries = Object.entries(row);
917
+ const columns = entries.map(([name]) => {
918
+ assertUserColumn(name);
919
+ return dialect.quote(name);
920
+ }).join(", ");
921
+ const marks = entries.map(([, value]) => pushParam(params, dialect, value));
922
+ const doUpdateSet = update.length === 0 ? null : update.map((name) => `${dialect.quote(name)} = ${pushParam(params, dialect, row[name])}`).join(", ");
923
+ return {
924
+ sql: `INSERT INTO ${dialect.quote(table)} (${columns}) VALUES (${marks.join(", ")})${dialect.upsertConflictClause(target, doUpdateSet)}`,
925
+ params
926
+ };
927
+ }
880
928
  function compileUpdate(table, wheres, values, dialect) {
881
929
  const entries = Object.entries(values);
882
930
  if (entries.length === 0) {
@@ -1017,6 +1065,17 @@ function createTableBuilder(table, driver, dialect, options = {}) {
1017
1065
  const compiled = compileInsertMany(state.table, rows, dialect);
1018
1066
  await driver.run(compiled.sql, compiled.params);
1019
1067
  },
1068
+ async upsert(row, conflict) {
1069
+ guardWrite();
1070
+ Object.keys(row).forEach(assertUserColumn);
1071
+ if (await resolveOwned(state, driver)) {
1072
+ throw unsafeOperation(
1073
+ "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"
1074
+ );
1075
+ }
1076
+ const compiled = compileUpsert(state.table, row, conflict, dialect);
1077
+ await driver.run(compiled.sql, compiled.params);
1078
+ },
1020
1079
  async update(values) {
1021
1080
  guardWrite();
1022
1081
  assertHasWhere(state);
@@ -1155,13 +1214,23 @@ function createCloudDb(driver, options = {}) {
1155
1214
  var CLOUD_DB_SPEC = {
1156
1215
  kind: "cloud-db",
1157
1216
  rootMethod: "table",
1158
- stepMethods: ["select", "where", "orderBy", "limit", "offset"],
1159
- terminalMethods: ["get", "first", "count", "insert", "insertMany", "update", "delete"],
1217
+ // 规格清单必须与构建器公开方法面一致(防漂移门 spec-drift.test.ts 双向咬合):
1218
+ // - owned:DB-006 的 owned 声明(step);
1219
+ // - execute:BUG-4 统一执行入口(direct,宿主侧 DB_RPC.execute 分支早已在);
1220
+ // - upsert:DB-010 终端(漏登记过一次,真机 500,见 spec-drift.test.ts 头注释)。
1221
+ stepMethods: ["select", "where", "orderBy", "limit", "offset", "owned"],
1222
+ terminalMethods: ["get", "first", "count", "insert", "insertMany", "update", "delete", "upsert"],
1160
1223
  // CF-013:writeQuery 是 D1 shim 的写路径(INSERT/UPDATE/DELETE),与 query 并列直通方法。
1161
- directMethods: ["query", "writeQuery", "changes"],
1224
+ directMethods: ["query", "writeQuery", "execute", "changes"],
1162
1225
  transactionMethod: "transaction"
1163
1226
  };
1164
- var WRITE_TERMINALS = /* @__PURE__ */ new Set(["insert", "insertMany", "update", "delete"]);
1227
+ var WRITE_TERMINALS = /* @__PURE__ */ new Set([
1228
+ "insert",
1229
+ "insertMany",
1230
+ "update",
1231
+ "delete",
1232
+ "upsert"
1233
+ ]);
1165
1234
  function errorWithCode(error) {
1166
1235
  if (error instanceof Error) {
1167
1236
  const sqlite = /no such table: (\S+)/.exec(error.message);
@@ -2791,6 +2860,33 @@ function createSimRealtimeCapability() {
2791
2860
  const [channel, data] = args;
2792
2861
  return sim.publish(channel, data);
2793
2862
  }
2863
+ case "issueTicket": {
2864
+ const [input] = args;
2865
+ if (typeof input !== "object" || input === null) {
2866
+ throw realtimeError(
2867
+ REALTIME_CODES.invalidArg,
2868
+ "\u7B7E\u53D1\u7968\u636E\u9700\u8981\u4E00\u4E2A\u8F93\u5165\u5BF9\u8C61 { subject, channels, ttlSeconds? }"
2869
+ );
2870
+ }
2871
+ const subject = input.subject;
2872
+ const channels = input.channels;
2873
+ if (typeof subject !== "string" || subject.length === 0) {
2874
+ throw realtimeError(
2875
+ REALTIME_CODES.invalidArg,
2876
+ "\u7B7E\u53D1\u7968\u636E\u5FC5\u987B\u5E26 subject\uFF08\u5E94\u7528\u4FA7\u7528\u6237\u6807\u8BC6\uFF09"
2877
+ );
2878
+ }
2879
+ if (!Array.isArray(channels) || channels.length === 0 || channels.some((c) => typeof c !== "string")) {
2880
+ throw realtimeError(
2881
+ REALTIME_CODES.invalidArg,
2882
+ "\u7B7E\u53D1\u7968\u636E\u5FC5\u987B\u5E26\u975E\u7A7A channels \u5B57\u7B26\u4E32\u6570\u7EC4\uFF08\u5E94\u7528\u7528\u6237\u7684\u7CBE\u786E\u8BA2\u9605\u767D\u540D\u5355\uFF09"
2883
+ );
2884
+ }
2885
+ throw realtimeError(
2886
+ REALTIME_CODES.unsupportedArg,
2887
+ "\u672C\u5730 sim \u4E0D\u7B7E\u53D1\u5B9E\u65F6\u7968\u636E\uFF08\u65E0 WS \u63E1\u624B\u9762\uFF0C\u7968\u636E\u65E0\u5904\u53EF\u7528\uFF09\uFF1B\u8BF7\u5728\u7EBF\u4E0A\u7684\u51FD\u6570\u6267\u884C\u9762\u4F7F\u7528 cloud.realtime.issueTicket"
2888
+ );
2889
+ }
2794
2890
  case "subscribe": {
2795
2891
  if (buffers.size >= MAX_SUBSCRIPTIONS) {
2796
2892
  throw realtimeError(
@@ -3839,6 +3935,11 @@ async function loadSimEnv(cwd, config = {}) {
3839
3935
  return merged;
3840
3936
  }
3841
3937
 
3938
+ // packages/cli/src/config.ts
3939
+ function normalizeFunctionsPrefix(prefix) {
3940
+ return prefix.replace(/^\/+|\/+$/g, "");
3941
+ }
3942
+
3842
3943
  // packages/cli/src/sim/fetch-config.ts
3843
3944
  var LOCAL_FETCH_TIMEOUT_MS_DEFAULT = 1e4;
3844
3945
  function resolveLocalFetchConfig(simEnv) {
@@ -4336,13 +4437,32 @@ var StateObjectRuntime = class {
4336
4437
  }
4337
4438
  /**
4338
4439
  * alarm 轮询:把到期对象唤醒并调 onAlarm(CF-037)。
4440
+ * - 到期集合 = 后端落库到期记录 ∪ **驻留实例的内存 alarmAt(驻留时以内存值为准)**:
4441
+ * `setAlarm`/`clearAlarm` 只写内存、`alarmAt` 随 `flush()` 落库——若 pump 只读后端,
4442
+ * 「setAlarm 后没 flush」会静默丢调度(rift-brawl 实锤:先 flush 再 setAlarm,闹钟永不触发),
4443
+ * 反向「clearAlarm 后没 flush」会因 DB 残留到期值误触发。重启续接仍以落库值为准
4444
+ * (实例不驻留时后端值是唯一事实;要重启不丢 alarm,方法内仍须 flush——见 features/state-objects.md)。
4339
4445
  * - onAlarm 后统一持久化(flush):onAlarm 内改的 state 与 setAlarm 重调度 / clearAlarm
4340
4446
  * 的新 alarmAt 都落库;
4341
4447
  * - 单对象 onAlarm 抛错**不阻塞**同 tick 其余对象:失败对象不落库、alarmAt 保留
4342
4448
  * → 下轮 dueAlarms 仍命中重试;错误折叠进 failed(不泄漏内部栈)。
4343
4449
  */
4344
4450
  async pump(now) {
4345
- const due = await this.backend.dueAlarms(now);
4451
+ const dueMap = /* @__PURE__ */ new Map();
4452
+ for (const d of await this.backend.dueAlarms(now)) {
4453
+ dueMap.set(this.key(d.type, d.id), d);
4454
+ }
4455
+ for (const [k, inst] of this.instances) {
4456
+ const typeName = inst.constructor.typeName;
4457
+ if (typeName === void 0) continue;
4458
+ const raw = inst;
4459
+ if (raw.alarmAt === null || raw.alarmAt > now) {
4460
+ dueMap.delete(k);
4461
+ continue;
4462
+ }
4463
+ dueMap.set(k, { type: typeName, id: inst.id, alarmAt: raw.alarmAt });
4464
+ }
4465
+ const due = [...dueMap.values()].toSorted((a, b) => a.alarmAt - b.alarmAt);
4346
4466
  const fired = [];
4347
4467
  const failed = [];
4348
4468
  for (const d of due) {
@@ -4906,7 +5026,7 @@ ${DYNAMIC_IMPORT_HINT}` : "";
4906
5026
  if (typeof code === "string") wrapped.code = code;
4907
5027
  return wrapped;
4908
5028
  }
4909
- function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false) {
5029
+ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false, hints) {
4910
5030
  const cached = cache.get(path);
4911
5031
  if (cached !== void 0) return cached;
4912
5032
  const source = files[path];
@@ -4927,7 +5047,7 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
4927
5047
  }
4928
5048
  const resolved = resolveModulePath(dir, request, files);
4929
5049
  if (resolved !== null) {
4930
- return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths);
5050
+ return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths, hints);
4931
5051
  }
4932
5052
  if (resolveBare !== void 0 && !request.startsWith("./") && !request.startsWith("../")) {
4933
5053
  const cachedModule = bareCache?.get(request);
@@ -4942,21 +5062,33 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
4942
5062
  error.code = SANDBOX_BUILTIN_REJECTED;
4943
5063
  throw error;
4944
5064
  };
4945
- let transformed;
5065
+ const hint = hints?.[path];
5066
+ let scriptSource;
4946
5067
  try {
4947
- transformed = transformExports(transpile(source));
5068
+ scriptSource = hint !== void 0 ? hint.js : `${WRAPPER_PREFIX}${transformExports(transpile(source))}${WRAPPER_SUFFIX}`;
4948
5069
  } catch (error) {
4949
5070
  throw syntaxErrorWithLocation(error, path, source);
4950
5071
  }
4951
5072
  const context = createSandboxContext(sandboxGlobals);
4952
5073
  let wrapper;
4953
5074
  try {
4954
- wrapper = vm.runInContext(
4955
- `(function (module, exports, require) { ${transformed}
4956
- })`,
4957
- context,
4958
- { filename: path }
4959
- );
5075
+ if (hint !== void 0 && hint.cachedData !== void 0) {
5076
+ const script = new vm.Script(scriptSource, {
5077
+ filename: path,
5078
+ cachedData: Buffer.from(
5079
+ hint.cachedData.buffer,
5080
+ hint.cachedData.byteOffset,
5081
+ hint.cachedData.byteLength
5082
+ )
5083
+ });
5084
+ if (script.cachedDataRejected !== true) {
5085
+ wrapper = script.runInContext(context);
5086
+ } else {
5087
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
5088
+ }
5089
+ } else {
5090
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
5091
+ }
4960
5092
  } catch (error) {
4961
5093
  throw syntaxErrorWithLocation(error, path, source);
4962
5094
  }
@@ -4966,7 +5098,9 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
4966
5098
  }
4967
5099
  return exports;
4968
5100
  }
4969
- function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false) {
5101
+ var WRAPPER_PREFIX = "(function (module, exports, require) { ";
5102
+ var WRAPPER_SUFFIX = " \n})";
5103
+ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false, hints) {
4970
5104
  const cache = /* @__PURE__ */ new Map();
4971
5105
  const bareCache = /* @__PURE__ */ new Map();
4972
5106
  const entryExports = loadModule(
@@ -4976,11 +5110,14 @@ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPat
4976
5110
  cache,
4977
5111
  resolveBare,
4978
5112
  bareCache,
4979
- strictPaths
5113
+ strictPaths,
5114
+ hints
4980
5115
  );
4981
5116
  const handler = entryExports["default"];
4982
5117
  if (typeof handler !== "function") {
4983
- throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570`);
5118
+ const base = entry.replace(/^.*\//, "");
5119
+ 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>" })`' : "";
5120
+ throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570${hint}`);
4984
5121
  }
4985
5122
  return { handler };
4986
5123
  }
@@ -5723,7 +5860,9 @@ function runWorker(input, port) {
5723
5860
  sandboxGlobals,
5724
5861
  input.deps === void 0 ? void 0 : createBareResolver(input.deps),
5725
5862
  // CORE-154:--parity 严格模式连带 `../` 越根引用报错(与容器形态真实 fs 同形)。
5726
- input.parity === true
5863
+ input.parity === true,
5864
+ // W2:预编译提示透传(缺省 undefined = 全量编译路径,零回归)。
5865
+ input.compileHints
5727
5866
  );
5728
5867
  const result = Promise.resolve(handler(ctx));
5729
5868
  void result.then(
@@ -6087,7 +6226,7 @@ async function loadConfig(cwd) {
6087
6226
  return {
6088
6227
  name: config?.name ?? name,
6089
6228
  functionsDir: config?.functionsDir ?? "functions",
6090
- functionsPrefix: config?.functions_prefix ?? "",
6229
+ functionsPrefix: normalizeFunctionsPrefix(config?.functions_prefix ?? ""),
6091
6230
  ...config?.environment === void 0 ? {} : { environment: config.environment },
6092
6231
  ...config?.db_environment === void 0 ? {} : { dbEnvironment: config.db_environment }
6093
6232
  };
@@ -6095,7 +6234,7 @@ async function loadConfig(cwd) {
6095
6234
  var parseEnvFile = parseEnv;
6096
6235
  function resolveRouteFnName(pathname, prefix) {
6097
6236
  const segments = pathname.split("/").filter((segment) => segment.length > 0);
6098
- const normalizedPrefix = prefix.replace(/^\/+|\/+$/g, "");
6237
+ const normalizedPrefix = normalizeFunctionsPrefix(prefix);
6099
6238
  if (normalizedPrefix.length === 0) {
6100
6239
  const first = segments[0];
6101
6240
  return first === void 0 ? {} : { fnName: first };
@@ -6139,7 +6278,7 @@ async function startDevServer(options) {
6139
6278
  `));
6140
6279
  const config = await loadConfig(cwd);
6141
6280
  if (options.prefix !== void 0) {
6142
- config.functionsPrefix = options.prefix.replace(/^\/+|\/+$/g, "");
6281
+ config.functionsPrefix = normalizeFunctionsPrefix(options.prefix);
6143
6282
  }
6144
6283
  const functionsDir = join10(cwd, config.functionsDir);
6145
6284
  const coldStartAt = Date.now();
@@ -6317,7 +6456,7 @@ async function startDevServer(options) {
6317
6456
  return;
6318
6457
  }
6319
6458
  if (fnName === "state") {
6320
- const normalizedPrefix = config.functionsPrefix.replace(/^\/+|\/+$/g, "");
6459
+ const normalizedPrefix = normalizeFunctionsPrefix(config.functionsPrefix);
6321
6460
  const rest = normalizedPrefix.length === 0 ? url.pathname : url.pathname.replace(new RegExp(`^/${normalizedPrefix}`), "");
6322
6461
  const parsed = parseStatePath(rest);
6323
6462
  if (parsed === null) {
@@ -6428,13 +6567,19 @@ async function startDevServer(options) {
6428
6567
  const baseUrl = `http://127.0.0.1:${actualPort}`;
6429
6568
  runtime.storage.signer.baseUrl = baseUrl;
6430
6569
  const coldStartMs = Date.now() - coldStartAt;
6431
- const curlPath = config.functionsPrefix.length === 0 ? "/hello" : `/${config.functionsPrefix}/hello`;
6570
+ const functionNames = listFunctionNames(files);
6571
+ const firstFunction = functionNames[0];
6572
+ const curlPath = firstFunction === void 0 ? null : config.functionsPrefix.length === 0 ? `/${firstFunction}` : `/${config.functionsPrefix}/${firstFunction}`;
6432
6573
  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";
6433
6574
  const dbTargetText = db.file === null ? simDbTarget(cwd) : displayPath(cwd, db.file);
6434
6575
  log(
6435
6576
  `[adep] dev server listening on ${baseUrl}\uFF08\u672C\u5730\u8FD0\u884C\u65F6 / ${dbLabel}\uFF0C\u51B7\u542F\u52A8 ${coldStartMs}ms\uFF09`
6436
6577
  );
6437
- log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
6578
+ if (curlPath === null) {
6579
+ 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");
6580
+ } else {
6581
+ log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
6582
+ }
6438
6583
  printBoundaries(log);
6439
6584
  if (simUser.resolver !== void 0) {
6440
6585
  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,13 @@
7
7
  },
8
8
  "homepage": "https://adep.top",
9
9
  "bugs": "https://gitcode.com/yunqiang_wu/ai-yunke/issues",
10
- "version": "0.5.7",
10
+ "version": "0.5.9",
11
11
  "adep": {
12
12
  "releaseTasks": [
13
- "CORE-485"
13
+ "FN-062",
14
+ "RT-008",
15
+ "SEC-IMPORT-01",
16
+ "CLI-109"
14
17
  ]
15
18
  },
16
19
  "type": "module",
@@ -36,13 +39,13 @@
36
39
  "yaml": "2.9.1",
37
40
  "zod": "^4.6.6",
38
41
  "@adep/app-runtime": "0.1.1",
39
- "@adep/runtime": "0.3.12",
40
42
  "@adep/cf-compat": "0.1.4",
41
- "@adep/crypto": "0.1.1",
42
- "@adep/vite-plugin": "0.1.13"
43
+ "@adep/runtime": "0.3.17",
44
+ "@adep/vite-plugin": "0.1.13",
45
+ "@adep/crypto": "0.1.1"
43
46
  },
44
47
  "devDependencies": {
45
- "@adep/types": "0.4.3"
48
+ "@adep/types": "0.4.6"
46
49
  },
47
50
  "scripts": {
48
51
  "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
  }