@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/index.js +556 -94
- package/dist/vite.js +174 -29
- package/dist/worker-entry.js +33 -14
- package/package.json +9 -6
- package/templates/app-mobile/package.json +1 -1
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
|
}
|
|
@@ -903,10 +906,15 @@ var init_capability_keys = __esm({
|
|
|
903
906
|
subscriptionNotFound: "REALTIME_SUBSCRIPTION_NOT_FOUND",
|
|
904
907
|
tooManySubscriptions: "REALTIME_TOO_MANY_SUBSCRIPTIONS",
|
|
905
908
|
/** 线上独有:订阅授权策略(RT-002 `SubscriptionPolicy`)拒绝该 channel。 */
|
|
906
|
-
channelDenied: "REALTIME_CHANNEL_DENIED"
|
|
909
|
+
channelDenied: "REALTIME_CHANNEL_DENIED",
|
|
910
|
+
/** 线上独有(RT-008):签票入参不合法(subject 缺失 / channels 非字符串数组 / TTL 越界)。 */
|
|
911
|
+
invalidArg: "REALTIME_INVALID_ARG",
|
|
912
|
+
/** 线上独有(RT-008):函数级签票超频(按项目固定窗口限流)。 */
|
|
913
|
+
ticketRateLimited: "REALTIME_TICKET_RATE_LIMITED"
|
|
907
914
|
};
|
|
908
915
|
REALTIME_CAPABILITY_METHODS = [
|
|
909
916
|
"publish",
|
|
917
|
+
"issueTicket",
|
|
910
918
|
"subscribe",
|
|
911
919
|
"receive",
|
|
912
920
|
"unsubscribe"
|
|
@@ -1298,7 +1306,9 @@ var init_worker_executor = __esm({
|
|
|
1298
1306
|
...input2.env === void 0 ? {} : { env: input2.env },
|
|
1299
1307
|
...deps === void 0 ? {} : { deps },
|
|
1300
1308
|
...this.parity ? { parity: true } : {},
|
|
1301
|
-
...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig }
|
|
1309
|
+
...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig },
|
|
1310
|
+
// W2:预编译提示随 workerData 下发(结构化克隆可跨线程;缺省不传 = 全量编译路径)。
|
|
1311
|
+
...input2.compileHints === void 0 ? {} : { compileHints: input2.compileHints }
|
|
1302
1312
|
},
|
|
1303
1313
|
resourceLimits: { maxOldGenerationSizeMb: memoryLimitMb }
|
|
1304
1314
|
});
|
|
@@ -1397,14 +1407,14 @@ var init_dialect = __esm({
|
|
|
1397
1407
|
placeholder: () => "?",
|
|
1398
1408
|
quote: (identifier) => `"${identifier.replace(/"/g, '""')}"`,
|
|
1399
1409
|
lastInsertIdClause: () => "",
|
|
1400
|
-
upsertConflictClause: (columns) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")}) DO NOTHING
|
|
1410
|
+
upsertConflictClause: (columns, doUpdateSet) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")})` + (doUpdateSet ? ` DO UPDATE SET ${doUpdateSet}` : " DO NOTHING")
|
|
1401
1411
|
};
|
|
1402
1412
|
postgresDialect = {
|
|
1403
1413
|
name: "postgres",
|
|
1404
1414
|
placeholder: (index) => `$${index + 1}`,
|
|
1405
1415
|
quote: (identifier) => `"${identifier.replace(/"/g, '""')}"`,
|
|
1406
1416
|
lastInsertIdClause: () => " RETURNING id",
|
|
1407
|
-
upsertConflictClause: (columns) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")}) DO NOTHING
|
|
1417
|
+
upsertConflictClause: (columns, doUpdateSet) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")})` + (doUpdateSet ? ` DO UPDATE SET ${doUpdateSet}` : " DO NOTHING")
|
|
1408
1418
|
};
|
|
1409
1419
|
}
|
|
1410
1420
|
});
|
|
@@ -1745,6 +1755,9 @@ function compileWhere(wheres, dialect, params) {
|
|
|
1745
1755
|
if (value === null) {
|
|
1746
1756
|
if (where.operator === "=") return `${quoted} IS NULL`;
|
|
1747
1757
|
if (where.operator === "!=") return `${quoted} IS NOT NULL`;
|
|
1758
|
+
throw unsafeOperation(
|
|
1759
|
+
`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}`
|
|
1760
|
+
);
|
|
1748
1761
|
}
|
|
1749
1762
|
const mark = pushParam(params, dialect, value);
|
|
1750
1763
|
return `${quoted} ${where.operator} ${mark}`;
|
|
@@ -1819,6 +1832,44 @@ function compileInsertMany(table, rows, dialect) {
|
|
|
1819
1832
|
params
|
|
1820
1833
|
};
|
|
1821
1834
|
}
|
|
1835
|
+
function resolveUpsertPlan(row, options) {
|
|
1836
|
+
const target = [...options.target];
|
|
1837
|
+
if (target.length === 0) {
|
|
1838
|
+
throw unsafeOperation("upsert \u7684 target \u5FC5\u987B\u81F3\u5C11\u4E00\u5217\uFF08\u51B2\u7A81\u5224\u5B9A\u65E0\u5217\u5219\u65E0\u4ECE\u8C08\u8D77\uFF09");
|
|
1839
|
+
}
|
|
1840
|
+
target.forEach(assertUserColumn);
|
|
1841
|
+
const targetSet = new Set(target);
|
|
1842
|
+
const rowColumns = new Set(Object.keys(row));
|
|
1843
|
+
if (rowColumns.size === 0) {
|
|
1844
|
+
throw unsafeOperation("upsert \u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u5B57\u6BB5");
|
|
1845
|
+
}
|
|
1846
|
+
const update = options.update === void 0 ? [...rowColumns].filter((name) => !targetSet.has(name)) : [...options.update];
|
|
1847
|
+
update.forEach(assertUserColumn);
|
|
1848
|
+
const overlapping = update.filter((name) => targetSet.has(name));
|
|
1849
|
+
if (overlapping.length > 0) {
|
|
1850
|
+
throw unsafeOperation(`upsert \u7684 update \u5217\u4E0D\u80FD\u4E0E target \u91CD\u53E0\uFF08\u51B2\u7A81\u884C\u4E3B\u952E\u4E0D\u6539\uFF09\uFF1A${overlapping.join(", ")}`);
|
|
1851
|
+
}
|
|
1852
|
+
const missing = update.filter((name) => !rowColumns.has(name));
|
|
1853
|
+
if (missing.length > 0) {
|
|
1854
|
+
throw unsafeOperation(`upsert \u7684 update \u5217\u5FC5\u987B\u51FA\u73B0\u5728 row \u4E2D\uFF08\u503C\u53D6\u81EA row\uFF09\uFF1A${missing.join(", ")}`);
|
|
1855
|
+
}
|
|
1856
|
+
return { target, update };
|
|
1857
|
+
}
|
|
1858
|
+
function compileUpsert(table, row, options, dialect) {
|
|
1859
|
+
const { target, update } = resolveUpsertPlan(row, options);
|
|
1860
|
+
const params = [];
|
|
1861
|
+
const entries = Object.entries(row);
|
|
1862
|
+
const columns = entries.map(([name]) => {
|
|
1863
|
+
assertUserColumn(name);
|
|
1864
|
+
return dialect.quote(name);
|
|
1865
|
+
}).join(", ");
|
|
1866
|
+
const marks = entries.map(([, value]) => pushParam(params, dialect, value));
|
|
1867
|
+
const doUpdateSet = update.length === 0 ? null : update.map((name) => `${dialect.quote(name)} = ${pushParam(params, dialect, row[name])}`).join(", ");
|
|
1868
|
+
return {
|
|
1869
|
+
sql: `INSERT INTO ${dialect.quote(table)} (${columns}) VALUES (${marks.join(", ")})${dialect.upsertConflictClause(target, doUpdateSet)}`,
|
|
1870
|
+
params
|
|
1871
|
+
};
|
|
1872
|
+
}
|
|
1822
1873
|
function compileUpdate(table, wheres, values, dialect) {
|
|
1823
1874
|
const entries = Object.entries(values);
|
|
1824
1875
|
if (entries.length === 0) {
|
|
@@ -1959,6 +2010,17 @@ function createTableBuilder(table, driver, dialect, options = {}) {
|
|
|
1959
2010
|
const compiled = compileInsertMany(state.table, rows, dialect);
|
|
1960
2011
|
await driver.run(compiled.sql, compiled.params);
|
|
1961
2012
|
},
|
|
2013
|
+
async upsert(row, conflict) {
|
|
2014
|
+
guardWrite();
|
|
2015
|
+
Object.keys(row).forEach(assertUserColumn);
|
|
2016
|
+
if (await resolveOwned(state, driver)) {
|
|
2017
|
+
throw unsafeOperation(
|
|
2018
|
+
"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"
|
|
2019
|
+
);
|
|
2020
|
+
}
|
|
2021
|
+
const compiled = compileUpsert(state.table, row, conflict, dialect);
|
|
2022
|
+
await driver.run(compiled.sql, compiled.params);
|
|
2023
|
+
},
|
|
1962
2024
|
async update(values) {
|
|
1963
2025
|
guardWrite();
|
|
1964
2026
|
assertHasWhere(state);
|
|
@@ -2251,13 +2313,23 @@ var init_cloud = __esm({
|
|
|
2251
2313
|
CLOUD_DB_SPEC = {
|
|
2252
2314
|
kind: "cloud-db",
|
|
2253
2315
|
rootMethod: "table",
|
|
2254
|
-
|
|
2255
|
-
|
|
2316
|
+
// 规格清单必须与构建器公开方法面一致(防漂移门 spec-drift.test.ts 双向咬合):
|
|
2317
|
+
// - owned:DB-006 的 owned 声明(step);
|
|
2318
|
+
// - execute:BUG-4 统一执行入口(direct,宿主侧 DB_RPC.execute 分支早已在);
|
|
2319
|
+
// - upsert:DB-010 终端(漏登记过一次,真机 500,见 spec-drift.test.ts 头注释)。
|
|
2320
|
+
stepMethods: ["select", "where", "orderBy", "limit", "offset", "owned"],
|
|
2321
|
+
terminalMethods: ["get", "first", "count", "insert", "insertMany", "update", "delete", "upsert"],
|
|
2256
2322
|
// CF-013:writeQuery 是 D1 shim 的写路径(INSERT/UPDATE/DELETE),与 query 并列直通方法。
|
|
2257
|
-
directMethods: ["query", "writeQuery", "changes"],
|
|
2323
|
+
directMethods: ["query", "writeQuery", "execute", "changes"],
|
|
2258
2324
|
transactionMethod: "transaction"
|
|
2259
2325
|
};
|
|
2260
|
-
WRITE_TERMINALS = /* @__PURE__ */ new Set([
|
|
2326
|
+
WRITE_TERMINALS = /* @__PURE__ */ new Set([
|
|
2327
|
+
"insert",
|
|
2328
|
+
"insertMany",
|
|
2329
|
+
"update",
|
|
2330
|
+
"delete",
|
|
2331
|
+
"upsert"
|
|
2332
|
+
]);
|
|
2261
2333
|
}
|
|
2262
2334
|
});
|
|
2263
2335
|
|
|
@@ -3818,6 +3890,33 @@ function createSimRealtimeCapability() {
|
|
|
3818
3890
|
const [channel, data] = args;
|
|
3819
3891
|
return sim.publish(channel, data);
|
|
3820
3892
|
}
|
|
3893
|
+
case "issueTicket": {
|
|
3894
|
+
const [input2] = args;
|
|
3895
|
+
if (typeof input2 !== "object" || input2 === null) {
|
|
3896
|
+
throw realtimeError(
|
|
3897
|
+
REALTIME_CODES.invalidArg,
|
|
3898
|
+
"\u7B7E\u53D1\u7968\u636E\u9700\u8981\u4E00\u4E2A\u8F93\u5165\u5BF9\u8C61 { subject, channels, ttlSeconds? }"
|
|
3899
|
+
);
|
|
3900
|
+
}
|
|
3901
|
+
const subject = input2.subject;
|
|
3902
|
+
const channels = input2.channels;
|
|
3903
|
+
if (typeof subject !== "string" || subject.length === 0) {
|
|
3904
|
+
throw realtimeError(
|
|
3905
|
+
REALTIME_CODES.invalidArg,
|
|
3906
|
+
"\u7B7E\u53D1\u7968\u636E\u5FC5\u987B\u5E26 subject\uFF08\u5E94\u7528\u4FA7\u7528\u6237\u6807\u8BC6\uFF09"
|
|
3907
|
+
);
|
|
3908
|
+
}
|
|
3909
|
+
if (!Array.isArray(channels) || channels.length === 0 || channels.some((c) => typeof c !== "string")) {
|
|
3910
|
+
throw realtimeError(
|
|
3911
|
+
REALTIME_CODES.invalidArg,
|
|
3912
|
+
"\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"
|
|
3913
|
+
);
|
|
3914
|
+
}
|
|
3915
|
+
throw realtimeError(
|
|
3916
|
+
REALTIME_CODES.unsupportedArg,
|
|
3917
|
+
"\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"
|
|
3918
|
+
);
|
|
3919
|
+
}
|
|
3821
3920
|
case "subscribe": {
|
|
3822
3921
|
if (buffers.size >= MAX_SUBSCRIPTIONS) {
|
|
3823
3922
|
throw realtimeError(
|
|
@@ -5719,13 +5818,32 @@ var init_runtime2 = __esm({
|
|
|
5719
5818
|
}
|
|
5720
5819
|
/**
|
|
5721
5820
|
* alarm 轮询:把到期对象唤醒并调 onAlarm(CF-037)。
|
|
5821
|
+
* - 到期集合 = 后端落库到期记录 ∪ **驻留实例的内存 alarmAt(驻留时以内存值为准)**:
|
|
5822
|
+
* `setAlarm`/`clearAlarm` 只写内存、`alarmAt` 随 `flush()` 落库——若 pump 只读后端,
|
|
5823
|
+
* 「setAlarm 后没 flush」会静默丢调度(rift-brawl 实锤:先 flush 再 setAlarm,闹钟永不触发),
|
|
5824
|
+
* 反向「clearAlarm 后没 flush」会因 DB 残留到期值误触发。重启续接仍以落库值为准
|
|
5825
|
+
* (实例不驻留时后端值是唯一事实;要重启不丢 alarm,方法内仍须 flush——见 features/state-objects.md)。
|
|
5722
5826
|
* - onAlarm 后统一持久化(flush):onAlarm 内改的 state 与 setAlarm 重调度 / clearAlarm
|
|
5723
5827
|
* 的新 alarmAt 都落库;
|
|
5724
5828
|
* - 单对象 onAlarm 抛错**不阻塞**同 tick 其余对象:失败对象不落库、alarmAt 保留
|
|
5725
5829
|
* → 下轮 dueAlarms 仍命中重试;错误折叠进 failed(不泄漏内部栈)。
|
|
5726
5830
|
*/
|
|
5727
5831
|
async pump(now) {
|
|
5728
|
-
const
|
|
5832
|
+
const dueMap = /* @__PURE__ */ new Map();
|
|
5833
|
+
for (const d of await this.backend.dueAlarms(now)) {
|
|
5834
|
+
dueMap.set(this.key(d.type, d.id), d);
|
|
5835
|
+
}
|
|
5836
|
+
for (const [k, inst] of this.instances) {
|
|
5837
|
+
const typeName = inst.constructor.typeName;
|
|
5838
|
+
if (typeName === void 0) continue;
|
|
5839
|
+
const raw = inst;
|
|
5840
|
+
if (raw.alarmAt === null || raw.alarmAt > now) {
|
|
5841
|
+
dueMap.delete(k);
|
|
5842
|
+
continue;
|
|
5843
|
+
}
|
|
5844
|
+
dueMap.set(k, { type: typeName, id: inst.id, alarmAt: raw.alarmAt });
|
|
5845
|
+
}
|
|
5846
|
+
const due = [...dueMap.values()].toSorted((a, b) => a.alarmAt - b.alarmAt);
|
|
5729
5847
|
const fired = [];
|
|
5730
5848
|
const failed = [];
|
|
5731
5849
|
for (const d of due) {
|
|
@@ -6315,7 +6433,7 @@ ${DYNAMIC_IMPORT_HINT}` : "";
|
|
|
6315
6433
|
if (typeof code === "string") wrapped.code = code;
|
|
6316
6434
|
return wrapped;
|
|
6317
6435
|
}
|
|
6318
|
-
function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false) {
|
|
6436
|
+
function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false, hints) {
|
|
6319
6437
|
const cached2 = cache.get(path);
|
|
6320
6438
|
if (cached2 !== void 0) return cached2;
|
|
6321
6439
|
const source = files[path];
|
|
@@ -6336,7 +6454,7 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
|
|
|
6336
6454
|
}
|
|
6337
6455
|
const resolved = resolveModulePath(dir, request, files);
|
|
6338
6456
|
if (resolved !== null) {
|
|
6339
|
-
return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths);
|
|
6457
|
+
return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths, hints);
|
|
6340
6458
|
}
|
|
6341
6459
|
if (resolveBare !== void 0 && !request.startsWith("./") && !request.startsWith("../")) {
|
|
6342
6460
|
const cachedModule = bareCache?.get(request);
|
|
@@ -6351,21 +6469,33 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
|
|
|
6351
6469
|
error62.code = SANDBOX_BUILTIN_REJECTED;
|
|
6352
6470
|
throw error62;
|
|
6353
6471
|
};
|
|
6354
|
-
|
|
6472
|
+
const hint = hints?.[path];
|
|
6473
|
+
let scriptSource;
|
|
6355
6474
|
try {
|
|
6356
|
-
|
|
6475
|
+
scriptSource = hint !== void 0 ? hint.js : `${WRAPPER_PREFIX}${transformExports(transpile(source))}${WRAPPER_SUFFIX}`;
|
|
6357
6476
|
} catch (error62) {
|
|
6358
6477
|
throw syntaxErrorWithLocation(error62, path, source);
|
|
6359
6478
|
}
|
|
6360
6479
|
const context = createSandboxContext(sandboxGlobals);
|
|
6361
6480
|
let wrapper;
|
|
6362
6481
|
try {
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6482
|
+
if (hint !== void 0 && hint.cachedData !== void 0) {
|
|
6483
|
+
const script = new vm.Script(scriptSource, {
|
|
6484
|
+
filename: path,
|
|
6485
|
+
cachedData: Buffer.from(
|
|
6486
|
+
hint.cachedData.buffer,
|
|
6487
|
+
hint.cachedData.byteOffset,
|
|
6488
|
+
hint.cachedData.byteLength
|
|
6489
|
+
)
|
|
6490
|
+
});
|
|
6491
|
+
if (script.cachedDataRejected !== true) {
|
|
6492
|
+
wrapper = script.runInContext(context);
|
|
6493
|
+
} else {
|
|
6494
|
+
wrapper = vm.runInContext(scriptSource, context, { filename: path });
|
|
6495
|
+
}
|
|
6496
|
+
} else {
|
|
6497
|
+
wrapper = vm.runInContext(scriptSource, context, { filename: path });
|
|
6498
|
+
}
|
|
6369
6499
|
} catch (error62) {
|
|
6370
6500
|
throw syntaxErrorWithLocation(error62, path, source);
|
|
6371
6501
|
}
|
|
@@ -6375,7 +6505,7 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
|
|
|
6375
6505
|
}
|
|
6376
6506
|
return exports;
|
|
6377
6507
|
}
|
|
6378
|
-
function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false) {
|
|
6508
|
+
function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false, hints) {
|
|
6379
6509
|
const cache = /* @__PURE__ */ new Map();
|
|
6380
6510
|
const bareCache = /* @__PURE__ */ new Map();
|
|
6381
6511
|
const entryExports = loadModule(
|
|
@@ -6385,15 +6515,18 @@ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPat
|
|
|
6385
6515
|
cache,
|
|
6386
6516
|
resolveBare,
|
|
6387
6517
|
bareCache,
|
|
6388
|
-
strictPaths
|
|
6518
|
+
strictPaths,
|
|
6519
|
+
hints
|
|
6389
6520
|
);
|
|
6390
6521
|
const handler = entryExports["default"];
|
|
6391
6522
|
if (typeof handler !== "function") {
|
|
6392
|
-
|
|
6523
|
+
const base = entry.replace(/^.*\//, "");
|
|
6524
|
+
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>" })`' : "";
|
|
6525
|
+
throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570${hint}`);
|
|
6393
6526
|
}
|
|
6394
6527
|
return { handler };
|
|
6395
6528
|
}
|
|
6396
|
-
var bunTranspiler, SANDBOX_BUILTIN_REJECTED, REALM_VALUE_KEY, DYNAMIC_IMPORT_HINT;
|
|
6529
|
+
var bunTranspiler, SANDBOX_BUILTIN_REJECTED, REALM_VALUE_KEY, DYNAMIC_IMPORT_HINT, WRAPPER_PREFIX, WRAPPER_SUFFIX;
|
|
6397
6530
|
var init_sandbox = __esm({
|
|
6398
6531
|
"packages/runtime/src/functions/runtime/sandbox.ts"() {
|
|
6399
6532
|
"use strict";
|
|
@@ -6402,6 +6535,8 @@ var init_sandbox = __esm({
|
|
|
6402
6535
|
SANDBOX_BUILTIN_REJECTED = "FN_SANDBOX_BUILTIN_BLOCKED";
|
|
6403
6536
|
REALM_VALUE_KEY = "__adepRealmValue";
|
|
6404
6537
|
DYNAMIC_IMPORT_HINT = "\u63D0\u793A\uFF1AM1 \u6C99\u7BB1\u4E0D\u652F\u6301\u52A8\u6001 import\uFF0C\u6539\u9759\u6001 import";
|
|
6538
|
+
WRAPPER_PREFIX = "(function (module, exports, require) { ";
|
|
6539
|
+
WRAPPER_SUFFIX = " \n})";
|
|
6405
6540
|
}
|
|
6406
6541
|
});
|
|
6407
6542
|
|
|
@@ -7205,7 +7340,9 @@ function runWorker(input2, port) {
|
|
|
7205
7340
|
sandboxGlobals,
|
|
7206
7341
|
input2.deps === void 0 ? void 0 : createBareResolver(input2.deps),
|
|
7207
7342
|
// CORE-154:--parity 严格模式连带 `../` 越根引用报错(与容器形态真实 fs 同形)。
|
|
7208
|
-
input2.parity === true
|
|
7343
|
+
input2.parity === true,
|
|
7344
|
+
// W2:预编译提示透传(缺省 undefined = 全量编译路径,零回归)。
|
|
7345
|
+
input2.compileHints
|
|
7209
7346
|
);
|
|
7210
7347
|
const result = Promise.resolve(handler(ctx));
|
|
7211
7348
|
void result.then(
|
|
@@ -7624,14 +7761,14 @@ async function loadConfig(cwd) {
|
|
|
7624
7761
|
return {
|
|
7625
7762
|
name: config2?.name ?? name,
|
|
7626
7763
|
functionsDir: config2?.functionsDir ?? "functions",
|
|
7627
|
-
functionsPrefix: config2?.functions_prefix ?? "",
|
|
7764
|
+
functionsPrefix: normalizeFunctionsPrefix(config2?.functions_prefix ?? ""),
|
|
7628
7765
|
...config2?.environment === void 0 ? {} : { environment: config2.environment },
|
|
7629
7766
|
...config2?.db_environment === void 0 ? {} : { dbEnvironment: config2.db_environment }
|
|
7630
7767
|
};
|
|
7631
7768
|
}
|
|
7632
7769
|
function resolveRouteFnName(pathname, prefix) {
|
|
7633
7770
|
const segments = pathname.split("/").filter((segment) => segment.length > 0);
|
|
7634
|
-
const normalizedPrefix = prefix
|
|
7771
|
+
const normalizedPrefix = normalizeFunctionsPrefix(prefix);
|
|
7635
7772
|
if (normalizedPrefix.length === 0) {
|
|
7636
7773
|
const first = segments[0];
|
|
7637
7774
|
return first === void 0 ? {} : { fnName: first };
|
|
@@ -7675,7 +7812,7 @@ async function startDevServer(options) {
|
|
|
7675
7812
|
`));
|
|
7676
7813
|
const config2 = await loadConfig(cwd);
|
|
7677
7814
|
if (options.prefix !== void 0) {
|
|
7678
|
-
config2.functionsPrefix = options.prefix
|
|
7815
|
+
config2.functionsPrefix = normalizeFunctionsPrefix(options.prefix);
|
|
7679
7816
|
}
|
|
7680
7817
|
const functionsDir = join13(cwd, config2.functionsDir);
|
|
7681
7818
|
const coldStartAt = Date.now();
|
|
@@ -7853,7 +7990,7 @@ async function startDevServer(options) {
|
|
|
7853
7990
|
return;
|
|
7854
7991
|
}
|
|
7855
7992
|
if (fnName === "state") {
|
|
7856
|
-
const normalizedPrefix = config2.functionsPrefix
|
|
7993
|
+
const normalizedPrefix = normalizeFunctionsPrefix(config2.functionsPrefix);
|
|
7857
7994
|
const rest = normalizedPrefix.length === 0 ? url2.pathname : url2.pathname.replace(new RegExp(`^/${normalizedPrefix}`), "");
|
|
7858
7995
|
const parsed = parseStatePath(rest);
|
|
7859
7996
|
if (parsed === null) {
|
|
@@ -7964,13 +8101,19 @@ async function startDevServer(options) {
|
|
|
7964
8101
|
const baseUrl = `http://127.0.0.1:${actualPort}`;
|
|
7965
8102
|
runtime.storage.signer.baseUrl = baseUrl;
|
|
7966
8103
|
const coldStartMs = Date.now() - coldStartAt;
|
|
7967
|
-
const
|
|
8104
|
+
const functionNames = listFunctionNames(files);
|
|
8105
|
+
const firstFunction = functionNames[0];
|
|
8106
|
+
const curlPath = firstFunction === void 0 ? null : config2.functionsPrefix.length === 0 ? `/${firstFunction}` : `/${config2.functionsPrefix}/${firstFunction}`;
|
|
7968
8107
|
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";
|
|
7969
8108
|
const dbTargetText = db.file === null ? simDbTarget(cwd) : displayPath(cwd, db.file);
|
|
7970
8109
|
log(
|
|
7971
8110
|
`[adep] dev server listening on ${baseUrl}\uFF08\u672C\u5730\u8FD0\u884C\u65F6 / ${dbLabel}\uFF0C\u51B7\u542F\u52A8 ${coldStartMs}ms\uFF09`
|
|
7972
8111
|
);
|
|
7973
|
-
|
|
8112
|
+
if (curlPath === null) {
|
|
8113
|
+
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");
|
|
8114
|
+
} else {
|
|
8115
|
+
log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
|
|
8116
|
+
}
|
|
7974
8117
|
printBoundaries(log);
|
|
7975
8118
|
if (simUser.resolver !== void 0) {
|
|
7976
8119
|
log(
|
|
@@ -8008,6 +8151,7 @@ var init_dev = __esm({
|
|
|
8008
8151
|
init_fetch_safe_port();
|
|
8009
8152
|
init_port_in_use();
|
|
8010
8153
|
init_env();
|
|
8154
|
+
init_config();
|
|
8011
8155
|
init_fetch_config();
|
|
8012
8156
|
init_invoke();
|
|
8013
8157
|
init_builtin_deps2();
|
|
@@ -8497,7 +8641,7 @@ function renderBanner(options) {
|
|
|
8497
8641
|
lines.push("");
|
|
8498
8642
|
lines.push(" \u80FD\u529B:");
|
|
8499
8643
|
if (functions.length > 0) {
|
|
8500
|
-
const route = options.functionsPrefix === void 0 || options.functionsPrefix.length === 0 ? `${baseUrl}/api/{fn}` : `${baseUrl}/${options.functionsPrefix
|
|
8644
|
+
const route = options.functionsPrefix === void 0 || options.functionsPrefix.length === 0 ? `${baseUrl}/api/{fn}` : `${baseUrl}/${normalizeFunctionsPrefix(options.functionsPrefix)}/{fn}`;
|
|
8501
8645
|
lines.push(` - \u51FD\u6570\u8DEF\u7531: ${route}\uFF08${functions.length} \u4E2A\u51FD\u6570: ${functions.join(", ")}\uFF09`);
|
|
8502
8646
|
} else {
|
|
8503
8647
|
lines.push(" - \u51FD\u6570\u8DEF\u7531: \u65E0\uFF08functions/ \u76EE\u5F55\u4E3A\u7A7A\uFF09");
|
|
@@ -8580,6 +8724,7 @@ var init_banner = __esm({
|
|
|
8580
8724
|
"packages/cli/src/serve/banner.ts"() {
|
|
8581
8725
|
"use strict";
|
|
8582
8726
|
init_dev_shared();
|
|
8727
|
+
init_config();
|
|
8583
8728
|
}
|
|
8584
8729
|
});
|
|
8585
8730
|
|
|
@@ -9150,7 +9295,7 @@ async function startServeServer(options) {
|
|
|
9150
9295
|
);
|
|
9151
9296
|
return;
|
|
9152
9297
|
}
|
|
9153
|
-
const normalizedPrefix = config2.functionsPrefix
|
|
9298
|
+
const normalizedPrefix = normalizeFunctionsPrefix(config2.functionsPrefix);
|
|
9154
9299
|
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;
|
|
9155
9300
|
if (fnRest !== null) {
|
|
9156
9301
|
const { fnName, error: routeError } = resolveRouteFnName(fnRest, "");
|
|
@@ -9349,6 +9494,7 @@ var init_server = __esm({
|
|
|
9349
9494
|
init_worker_executor();
|
|
9350
9495
|
init_signature();
|
|
9351
9496
|
init_driver();
|
|
9497
|
+
init_config();
|
|
9352
9498
|
init_builtin_deps2();
|
|
9353
9499
|
init_runtime();
|
|
9354
9500
|
init_storage();
|
|
@@ -10086,7 +10232,7 @@ import { basename as basename5, dirname as dirname12, extname as extname2, join
|
|
|
10086
10232
|
function envQuery2(options) {
|
|
10087
10233
|
return options.environment === void 0 ? "" : `?environment=${options.environment}`;
|
|
10088
10234
|
}
|
|
10089
|
-
async function
|
|
10235
|
+
async function open5(paths, options) {
|
|
10090
10236
|
const client = await createClient(paths);
|
|
10091
10237
|
const project2 = await resolveSlug(resolve15(options.cwd), options.slug);
|
|
10092
10238
|
return { client, project: project2 };
|
|
@@ -10120,7 +10266,7 @@ function contentTypeOf(path) {
|
|
|
10120
10266
|
return map2[extname2(path).toLowerCase()] ?? "application/octet-stream";
|
|
10121
10267
|
}
|
|
10122
10268
|
async function storageUpload(paths, options) {
|
|
10123
|
-
const { client, project: project2 } = await
|
|
10269
|
+
const { client, project: project2 } = await open5(paths, options);
|
|
10124
10270
|
const local = resolve15(options.file);
|
|
10125
10271
|
const info = await stat14(local).catch(() => null);
|
|
10126
10272
|
if (info === null || !info.isFile()) {
|
|
@@ -10146,7 +10292,7 @@ async function storageUpload(paths, options) {
|
|
|
10146
10292
|
return { ...body.file, ...body.signedUrl === void 0 ? {} : { signedUrl: body.signedUrl } };
|
|
10147
10293
|
}
|
|
10148
10294
|
async function storageList(paths, options) {
|
|
10149
|
-
const { client, project: project2 } = await
|
|
10295
|
+
const { client, project: project2 } = await open5(paths, options);
|
|
10150
10296
|
const search = new URLSearchParams();
|
|
10151
10297
|
if (options.prefix !== void 0) search.set("prefix", options.prefix);
|
|
10152
10298
|
if (options.environment !== void 0) search.set("environment", options.environment);
|
|
@@ -10170,7 +10316,7 @@ async function resolveDownloadUrl(client, project2, path, environment) {
|
|
|
10170
10316
|
return url2;
|
|
10171
10317
|
}
|
|
10172
10318
|
async function storageDownload(paths, options) {
|
|
10173
|
-
const { client, project: project2 } = await
|
|
10319
|
+
const { client, project: project2 } = await open5(paths, options);
|
|
10174
10320
|
const url2 = await resolveDownloadUrl(client, project2, options.path, options.environment);
|
|
10175
10321
|
const response = await client.download(url2, "STORAGE_DOWNLOAD_FAILED");
|
|
10176
10322
|
const bytes = Buffer.from(await response.arrayBuffer());
|
|
@@ -10180,7 +10326,7 @@ async function storageDownload(paths, options) {
|
|
|
10180
10326
|
return { path: options.path, output: output2, size: bytes.length };
|
|
10181
10327
|
}
|
|
10182
10328
|
async function storageRemove(paths, options) {
|
|
10183
|
-
const { client, project: project2 } = await
|
|
10329
|
+
const { client, project: project2 } = await open5(paths, options);
|
|
10184
10330
|
return client.request(
|
|
10185
10331
|
`/api/v1/projects/${project2}/files/${encodeURIComponent(options.path)}${envQuery2(options)}`,
|
|
10186
10332
|
{ method: "DELETE" }
|
|
@@ -10205,13 +10351,13 @@ __export(hosting_exports, {
|
|
|
10205
10351
|
import { readdir as readdir11, readFile as readFile25, stat as stat15 } from "node:fs/promises";
|
|
10206
10352
|
import { spawnSync } from "node:child_process";
|
|
10207
10353
|
import { dirname as dirname13, join as join33, relative as relative7, resolve as resolve16, sep as sep3 } from "node:path";
|
|
10208
|
-
async function
|
|
10354
|
+
async function open6(paths, options) {
|
|
10209
10355
|
const client = await createClient(paths);
|
|
10210
10356
|
const project2 = await resolveSlug(resolve16(options.cwd), options.slug);
|
|
10211
10357
|
return { client, project: project2 };
|
|
10212
10358
|
}
|
|
10213
10359
|
async function hostingInfo(paths, options) {
|
|
10214
|
-
const { client, project: project2 } = await
|
|
10360
|
+
const { client, project: project2 } = await open6(paths, options);
|
|
10215
10361
|
const body = await client.request(`/api/v1/projects/${project2}/hosting`);
|
|
10216
10362
|
return {
|
|
10217
10363
|
config: body.config,
|
|
@@ -10243,7 +10389,7 @@ async function collectSiteFiles(dir) {
|
|
|
10243
10389
|
return files;
|
|
10244
10390
|
}
|
|
10245
10391
|
async function hostingDeploy(paths, options) {
|
|
10246
|
-
const { client, project: project2 } = await
|
|
10392
|
+
const { client, project: project2 } = await open6(paths, options);
|
|
10247
10393
|
const log = options.log ?? ((line) => process.stdout.write(`${line}
|
|
10248
10394
|
`));
|
|
10249
10395
|
if (options.build !== void 0) {
|
|
@@ -10322,7 +10468,7 @@ async function hostingDeploy(paths, options) {
|
|
|
10322
10468
|
return { config: config2.config, siteUrl: info.siteUrl, uploaded, reused, identical, builtAt };
|
|
10323
10469
|
}
|
|
10324
10470
|
async function hostingPull(paths, options) {
|
|
10325
|
-
const { client } = await
|
|
10471
|
+
const { client } = await open6(paths, options);
|
|
10326
10472
|
const log = options.log ?? ((line) => process.stdout.write(`${line}
|
|
10327
10473
|
`));
|
|
10328
10474
|
const info = await hostingInfo(paths, options);
|
|
@@ -10345,7 +10491,7 @@ async function hostingPull(paths, options) {
|
|
|
10345
10491
|
return { siteUrl: info.siteUrl, outputDir, files };
|
|
10346
10492
|
}
|
|
10347
10493
|
async function hostingConfig(paths, options) {
|
|
10348
|
-
const { client, project: project2 } = await
|
|
10494
|
+
const { client, project: project2 } = await open6(paths, options);
|
|
10349
10495
|
const body = {};
|
|
10350
10496
|
if (options.enabled !== void 0) body["enabled"] = options.enabled;
|
|
10351
10497
|
if (options.spa !== void 0) body["spaMode"] = options.spa;
|
|
@@ -10803,8 +10949,8 @@ var init_release_check = __esm({
|
|
|
10803
10949
|
});
|
|
10804
10950
|
|
|
10805
10951
|
// packages/cli/src/sandbox-scan.ts
|
|
10806
|
-
import { readdir as readdir13, readFile as
|
|
10807
|
-
import { join as
|
|
10952
|
+
import { readdir as readdir13, readFile as readFile32 } from "node:fs/promises";
|
|
10953
|
+
import { join as join39, relative as relative9, sep as sep5 } from "node:path";
|
|
10808
10954
|
function extractSpecifiers(line) {
|
|
10809
10955
|
const out = [];
|
|
10810
10956
|
const patterns = [
|
|
@@ -10848,7 +10994,7 @@ function classify(specifier) {
|
|
|
10848
10994
|
return null;
|
|
10849
10995
|
}
|
|
10850
10996
|
async function scanFunctionSources(rootDir, functionsDir) {
|
|
10851
|
-
const base =
|
|
10997
|
+
const base = join39(rootDir, functionsDir);
|
|
10852
10998
|
const findings = [];
|
|
10853
10999
|
async function walk(current) {
|
|
10854
11000
|
let entries;
|
|
@@ -10858,7 +11004,7 @@ async function scanFunctionSources(rootDir, functionsDir) {
|
|
|
10858
11004
|
return;
|
|
10859
11005
|
}
|
|
10860
11006
|
for (const entry of entries) {
|
|
10861
|
-
const abs =
|
|
11007
|
+
const abs = join39(current, entry.name);
|
|
10862
11008
|
if (entry.isDirectory()) {
|
|
10863
11009
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
10864
11010
|
await walk(abs);
|
|
@@ -10869,7 +11015,7 @@ async function scanFunctionSources(rootDir, functionsDir) {
|
|
|
10869
11015
|
if (entry.name.endsWith(".d.ts")) continue;
|
|
10870
11016
|
let content;
|
|
10871
11017
|
try {
|
|
10872
|
-
content = await
|
|
11018
|
+
content = await readFile32(abs, "utf8");
|
|
10873
11019
|
} catch {
|
|
10874
11020
|
continue;
|
|
10875
11021
|
}
|
|
@@ -10998,7 +11144,7 @@ var init_version = __esm({
|
|
|
10998
11144
|
manifest = requireJson("../package.json");
|
|
10999
11145
|
CLI_VERSION = typeof manifest.version === "string" && manifest.version.length > 0 ? manifest.version : "0.0.0";
|
|
11000
11146
|
RELEASE_TASKS = Array.isArray(manifest.adep?.releaseTasks) ? manifest.adep.releaseTasks.filter((item) => typeof item === "string") : [];
|
|
11001
|
-
BUILD_COMMIT = "
|
|
11147
|
+
BUILD_COMMIT = "89404b79".trim() !== "" ? "89404b79".trim() : null;
|
|
11002
11148
|
}
|
|
11003
11149
|
});
|
|
11004
11150
|
|
|
@@ -11012,9 +11158,9 @@ __export(doctor_exports, {
|
|
|
11012
11158
|
runDoctor: () => runDoctor
|
|
11013
11159
|
});
|
|
11014
11160
|
import { createRequire as createRequire3 } from "node:module";
|
|
11015
|
-
import { readFile as
|
|
11161
|
+
import { readFile as readFile33, stat as stat18 } from "node:fs/promises";
|
|
11016
11162
|
import { homedir } from "node:os";
|
|
11017
|
-
import { join as
|
|
11163
|
+
import { join as join40 } from "node:path";
|
|
11018
11164
|
import { parse as parseYaml } from "yaml";
|
|
11019
11165
|
function minimumReleaseAgeMinutes(raw) {
|
|
11020
11166
|
const text = raw.trim();
|
|
@@ -11038,7 +11184,7 @@ function hitFromEnvironment(env) {
|
|
|
11038
11184
|
}
|
|
11039
11185
|
async function readTextOrNull(file2) {
|
|
11040
11186
|
try {
|
|
11041
|
-
return await
|
|
11187
|
+
return await readFile33(file2, "utf8");
|
|
11042
11188
|
} catch {
|
|
11043
11189
|
return null;
|
|
11044
11190
|
}
|
|
@@ -11079,8 +11225,8 @@ async function hitFromNpmrc(file2, label) {
|
|
|
11079
11225
|
}
|
|
11080
11226
|
async function detectSupplyChainPolicy(cwd, env = process.env, home = homedir()) {
|
|
11081
11227
|
const xdg = env["XDG_CONFIG_HOME"]?.trim();
|
|
11082
|
-
const globalConfig2 = xdg !== void 0 && xdg !== "" ?
|
|
11083
|
-
const hit = hitFromEnvironment(env) ?? await hitFromYamlConfig(
|
|
11228
|
+
const globalConfig2 = xdg !== void 0 && xdg !== "" ? join40(xdg, "pnpm", "config.yaml") : join40(home, ".config", "pnpm", "config.yaml");
|
|
11229
|
+
const hit = hitFromEnvironment(env) ?? await hitFromYamlConfig(join40(cwd, "pnpm-workspace.yaml"), "pnpm-workspace.yaml") ?? await hitFromNpmrc(join40(cwd, ".npmrc"), ".npmrc") ?? await hitFromYamlConfig(globalConfig2, "~/.config/pnpm/config.yaml") ?? await hitFromNpmrc(join40(home, ".npmrc"), "~/.npmrc");
|
|
11084
11230
|
return {
|
|
11085
11231
|
minimumReleaseAge: hit === null ? { minutes: null, source: null, raw: null, warning: null } : { minutes: hit.minutes, source: hit.source, raw: hit.raw, warning: hit.warning }
|
|
11086
11232
|
};
|
|
@@ -11115,7 +11261,7 @@ async function credentialMode(file2) {
|
|
|
11115
11261
|
async function runDoctor(paths, cwd = process.cwd()) {
|
|
11116
11262
|
const credentials = await loadCredentials(paths);
|
|
11117
11263
|
const server = credentials?.server ?? resolveServer();
|
|
11118
|
-
const credentialsFile = credentials !== null ?
|
|
11264
|
+
const credentialsFile = credentials !== null ? join40(paths.credentialsDir, `${slotNameFor(credentials.server)}.json`) : paths.credentialsFile;
|
|
11119
11265
|
const mode = await credentialMode(credentialsFile);
|
|
11120
11266
|
const offline = await isOffline();
|
|
11121
11267
|
const health = await probeServer(server);
|
|
@@ -11247,7 +11393,7 @@ function pickBreakingNotices(parsed, status, version2, newerVersions) {
|
|
|
11247
11393
|
}
|
|
11248
11394
|
async function readOwnChangelog() {
|
|
11249
11395
|
try {
|
|
11250
|
-
return await
|
|
11396
|
+
return await readFile33(createRequire3(import.meta.url).resolve("../CHANGELOG.md"), "utf8");
|
|
11251
11397
|
} catch {
|
|
11252
11398
|
return null;
|
|
11253
11399
|
}
|
|
@@ -11919,8 +12065,8 @@ var GENERATED_TEMPLATES = {
|
|
|
11919
12065
|
},
|
|
11920
12066
|
"files": [
|
|
11921
12067
|
{
|
|
11922
|
-
"path": "README
|
|
11923
|
-
"content":
|
|
12068
|
+
"path": "README.md",
|
|
12069
|
+
"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'
|
|
11924
12070
|
}
|
|
11925
12071
|
]
|
|
11926
12072
|
},
|
|
@@ -12040,7 +12186,7 @@ var GENERATED_TEMPLATES = {
|
|
|
12040
12186
|
},
|
|
12041
12187
|
{
|
|
12042
12188
|
"path": "functions/_shared/date.test.ts",
|
|
12043
|
-
"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:
|
|
12189
|
+
"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"
|
|
12044
12190
|
},
|
|
12045
12191
|
{
|
|
12046
12192
|
"path": "functions/_shared/date.ts",
|
|
@@ -14377,6 +14523,7 @@ var ADEP_ENV_DTS = `/**
|
|
|
14377
14523
|
* \u5951\u7EA6\u552F\u4E00\u771F\u76F8\u6E90 = packages/types/src/\uFF1B\u540C\u6E90\u4EA7\u7269\u8FD8\u6709 Web IDE \u955C\u50CF
|
|
14378
14524
|
* \uFF08app/components/ide/adep.d.ts\uFF0C\u540C\u4E00\u4EFD\u751F\u6210\u5668\u8F93\u51FA + \u6D4F\u89C8\u5668\u6D4B\u8BD5\u5168\u5C40\uFF09\u3002
|
|
14379
14525
|
* \u6F02\u79FB\u95E8 = scripts/lib/__tests__/contract-mirrors.test.ts\u3002
|
|
14526
|
+
* \u955C\u50CF\u7248\u672C = @adep/types@0.4.6\uFF08generate:contracts \u751F\u6210\u65F6\u6233\uFF09
|
|
14380
14527
|
*/
|
|
14381
14528
|
|
|
14382
14529
|
/* ---------- HTTP \u89E6\u53D1\u4E0A\u4E0B\u6587\uFF08FunctionContext \u955C\u50CF\uFF09 ---------- */
|
|
@@ -14600,6 +14747,18 @@ interface AdepCloudDbTable {
|
|
|
14600
14747
|
insert(row: Record<string, AdepSqlValue>): Promise<void>
|
|
14601
14748
|
/** \u6279\u91CF\u63D2\u5165\u3002 */
|
|
14602
14749
|
insertMany(rows: ReadonlyArray<Record<string, AdepSqlValue>>): Promise<void>
|
|
14750
|
+
/**
|
|
14751
|
+
* \u63D2\u5165\u6216\u66F4\u65B0\uFF08INSERT ... ON CONFLICT (target) DO UPDATE SET ...\uFF09\u3002
|
|
14752
|
+
* \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
|
|
14753
|
+
* \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
|
|
14754
|
+
*
|
|
14755
|
+
* 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
|
|
14756
|
+
* \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
|
|
14757
|
+
* \u5916\u7684\u5168\u90E8\u5217\uFF1B\u663E\u5F0F update: [] \u8868\u793A\u51B2\u7A81\u65F6\u4FDD\u6301\u65E7\u884C\u4E0D\u53D8\uFF08DO NOTHING\uFF09\u3002
|
|
14758
|
+
*
|
|
14759
|
+
* owned \u8868\u4E0D\u652F\u6301\uFF08\u53D8\u66F4\u6D41\u65E0\u6CD5\u8868\u8FBE insert/update \u4E8C\u4E49\uFF09\uFF0C\u629B DB_UNSAFE_OP\u3002
|
|
14760
|
+
*/
|
|
14761
|
+
upsert(row: Record<string, AdepSqlValue>, options: UpsertOptions): Promise<void>
|
|
14603
14762
|
/** \u66F4\u65B0\uFF08\u5FC5\u987B\u5148 where\uFF0C\u5426\u5219 DB_UNSAFE_OP\uFF09\uFF1B\u8FD4\u56DE\u53D7\u5F71\u54CD\u884C\u6570\u3002 */
|
|
14604
14763
|
update(values: Record<string, AdepSqlValue>): Promise<number>
|
|
14605
14764
|
/** \u5220\u9664\uFF08\u5FC5\u987B\u5148 where\uFF0C\u5426\u5219 DB_UNSAFE_OP\uFF09\uFF1B\u8FD4\u56DE\u53D7\u5F71\u54CD\u884C\u6570\u3002 */
|
|
@@ -14687,6 +14846,29 @@ interface AdepCloudRealtimeReceipt {
|
|
|
14687
14846
|
delivered: number
|
|
14688
14847
|
}
|
|
14689
14848
|
|
|
14849
|
+
/**
|
|
14850
|
+
* \u5E94\u7528\u4E91\u51FD\u6570\u7B7E\u53D1\u5B9E\u65F6\u7968\u636E\u7684\u5165\u53C2\uFF08RT-008\uFF09\u3002
|
|
14851
|
+
* - subject\uFF1A**\u5E94\u7528\u4FA7\u7528\u6237\u6807\u8BC6**\uFF08\u975E\u5E73\u53F0\u7528\u6237 id\uFF0C\u672C\u5730 sim \u4E0E\u7EBF\u4E0A\u90FD\u4E0D\u505A\u89E3\u6790\uFF0C\u53EA\u5F53\u4E0D\u900F\u660E\u4E32
|
|
14852
|
+
* \u7ED1\u5B9A\u8FDB\u7968\u636E claims\uFF0C\u9632\u7968\u636E\u8DE8\u4E3B\u4F53\u590D\u7528\uFF09\u3002
|
|
14853
|
+
* - channels\uFF1A\u8BE5\u7968\u636E\u53EF\u8BA2\u9605\u7684**\u7CBE\u786E channel \u767D\u540D\u5355**\u3002\u670D\u52A1\u7AEF\u4E0E\u300C\u8BA2\u9605\u6388\u6743\u7B56\u7565\u300D\u6C42\u503C\u53D6 AND
|
|
14854
|
+
* \uFF08\u51FD\u6570\u53EA\u80FD\u7B7E\u53D1\u5B83\u81EA\u5DF1 publish \u9762\u5185\u7684\u901A\u9053\uFF0C\u4E0D\u8DE8\u9879\u76EE\u6269\u6743\uFF09\uFF1Brole='app' \u7968\u7F3A\u7701\u65E0\u8BE5\u540D\u5355
|
|
14855
|
+
* \u21D2 \u65E0\u4EFB\u4F55\u8BA2\u9605\u6388\u6743\uFF08fail closed\uFF09\u3002
|
|
14856
|
+
* - ttlSeconds\uFF1A\u8FC7\u671F\u79D2\u6570\u3002\u7EBF\u4E0A\u5E73\u53F0\u4FA7\u6709\u786C\u6027\u4E0A\u9650\uFF08\u8D85\u4E0A\u9650\u629B REALTIME_INVALID_ARG\uFF09\uFF1B
|
|
14857
|
+
* \u672C\u5730 sim \u4E0D\u4E0E\u7EBF\u4E0A\u540C\u53C2\u503C\u65F6 fail loud\u3002
|
|
14858
|
+
*/
|
|
14859
|
+
interface AdepCloudRealtimeTicketInput {
|
|
14860
|
+
subject: string
|
|
14861
|
+
channels: string[]
|
|
14862
|
+
ttlSeconds?: number
|
|
14863
|
+
}
|
|
14864
|
+
|
|
14865
|
+
/** \u7B7E\u7968\u56DE\u6267\uFF1Aticket \u660E\u6587\u53EA\u5728\u6B64\u51FA\u73B0\u4E00\u6B21\uFF0C\u6B64\u540E\u4E00\u5F8B\u8D70\u6253\u7801\uFF08\u89C4\u8303 \xA77\uFF1Bmasked \u4F9B\u65E5\u5FD7\u4E0E\u5C55\u793A\uFF09\u3002 */
|
|
14866
|
+
interface AdepCloudRealtimeTicketReceipt {
|
|
14867
|
+
ticket: string
|
|
14868
|
+
expiresIn: number
|
|
14869
|
+
masked: string
|
|
14870
|
+
}
|
|
14871
|
+
|
|
14690
14872
|
/** subscribe \u56DE\u6267\uFF1Asubscription \u662F\u540E\u7EED receive / unsubscribe \u7684\u53E5\u67C4\uFF08\u4E0D\u900F\u660E\u5B57\u7B26\u4E32\uFF09\u3002 */
|
|
14691
14873
|
interface AdepCloudRealtimeSubscription {
|
|
14692
14874
|
subscription: string
|
|
@@ -14706,6 +14888,12 @@ interface AdepCloudRealtime {
|
|
|
14706
14888
|
* \uFF08\u5355\u8FDB\u7A0B\u5185\u5B58\u5E7F\u64AD\u6CA1\u6709\u8FDE\u63A5\u8EAB\u4EFD\u53EF\u6BD4\u8F83\uFF0C\u89C1 sim/boundary.ts\uFF09\u3002
|
|
14707
14889
|
*/
|
|
14708
14890
|
publish(channel: string, data: unknown, except?: string): Promise<AdepCloudRealtimeReceipt>
|
|
14891
|
+
/**
|
|
14892
|
+
* \u4EE5**\u51FD\u6570\u8EAB\u4EFD**\u4E3A\u5E94\u7528\u7528\u6237\u7B7E\u53D1\u4E00\u6B21\u6027\u63E1\u624B\u7968\u636E\uFF08RT-008\uFF09\uFF1A\u5E94\u7528\u81EA\u6709\u8D26\u53F7\u4F53\u7CFB\u5728
|
|
14893
|
+
* \u4E91\u51FD\u6570\u5185\u9274\u6743\u540E\uFF0C\u5230\u8FD9\u91CC\u6362\u53D6\u77ED\u65F6\u6548\u7968\u636E\uFF0C\u524D\u7AEF\u51ED\u7968\u5B8C\u6210 WS \u63E1\u624B\u3002
|
|
14894
|
+
* \u4E0D\u4F9D\u8D56\u5E73\u53F0 better-auth \u4F1A\u8BDD\uFF08\u5E94\u7528\u7528\u6237\u4E0D\u662F\u5E73\u53F0\u7528\u6237\uFF09\u3002
|
|
14895
|
+
*/
|
|
14896
|
+
issueTicket(input: AdepCloudRealtimeTicketInput): Promise<AdepCloudRealtimeTicketReceipt>
|
|
14709
14897
|
/** \u8BA2\u9605 channel\uFF0C\u53D6\u5F97\u4E00\u4E2A\u8F6E\u8BE2\u53E5\u67C4\uFF1B\u547D\u4E2D\u672C\u8BA2\u9605\u7684\u6D88\u606F\u7559\u5728\u5BBF\u4E3B\u7F13\u51B2\u3002 */
|
|
14710
14898
|
subscribe(channel: string): Promise<AdepCloudRealtimeSubscription>
|
|
14711
14899
|
/** \u53D6\u56DE\u5E76\u6E05\u7A7A\u8BE5\u53E5\u67C4\u7684\u7F13\u51B2\uFF08\u975E\u963B\u585E\uFF1B\u65E0\u6D88\u606F\u8FD4\u56DE\u7A7A\u6570\u7EC4\uFF09\u3002 */
|
|
@@ -15001,30 +15189,41 @@ var ADEP_CONFIG_HEADER = `// adep \u9879\u76EE\u914D\u7F6E\uFF1ACLI\uFF08dev / s
|
|
|
15001
15189
|
// dev / serve / \u5E73\u53F0\u8BBF\u95EE\u8DEF\u5F84\u4E00\u81F4\u4E3A /{prefix}/{fnName}\uFF08\u5982 /api/hello\uFF09\u3002
|
|
15002
15190
|
// 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
|
|
15003
15191
|
// \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`;
|
|
15004
|
-
var PACKAGE_JSON = (
|
|
15192
|
+
var PACKAGE_JSON = (ctx) => {
|
|
15193
|
+
const { name, template, cliVersion, hasFrontend } = ctx;
|
|
15194
|
+
const scripts = hasFrontend ? {
|
|
15195
|
+
dev: "vite",
|
|
15196
|
+
build: "vite build",
|
|
15197
|
+
"site:deploy": "adep hosting deploy site --spa",
|
|
15198
|
+
serve: "adep serve",
|
|
15199
|
+
// 容器内启动入口(Dockerfile 的 CMD 只有 `bun run start`):静态目录 / 端口口径
|
|
15200
|
+
// 只在这一个地方定档——Dockerfile 与 package.json 各写一套必然漂移(2026-10-08 收敛)。
|
|
15201
|
+
// fullstack 的前端产物在 site/(vite build);function / empty 无前端产物,故不指目录。
|
|
15202
|
+
start: template === "fullstack" ? "adep serve --host 0.0.0.0 --static site" : "adep serve --host 0.0.0.0",
|
|
15203
|
+
deploy: "adep publish --only functions",
|
|
15204
|
+
doctor: "adep doctor"
|
|
15205
|
+
} : {
|
|
15206
|
+
// 无前端模板:dev 走**函数侧**模拟运行时(进程内、不连云端、不装 Docker)。
|
|
15207
|
+
// 不能写 vite——没有 vite 工程根,启动后只会白屏一个空页。
|
|
15208
|
+
dev: "adep dev",
|
|
15209
|
+
serve: "adep serve",
|
|
15210
|
+
start: "adep serve --host 0.0.0.0",
|
|
15211
|
+
deploy: "adep publish --only functions",
|
|
15212
|
+
doctor: "adep doctor"
|
|
15213
|
+
};
|
|
15005
15214
|
const pkg = {
|
|
15006
15215
|
name,
|
|
15007
15216
|
version: "0.1.0",
|
|
15008
15217
|
private: true,
|
|
15009
15218
|
type: "module",
|
|
15010
|
-
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`,
|
|
15011
|
-
scripts
|
|
15012
|
-
dev: "vite",
|
|
15013
|
-
build: "vite build",
|
|
15014
|
-
"site:deploy": "adep hosting deploy site --spa",
|
|
15015
|
-
serve: "adep serve",
|
|
15016
|
-
// 容器内启动入口(Dockerfile 的 CMD 只有 `bun run start`):静态目录 / 端口口径
|
|
15017
|
-
// 只在这一个地方定档——Dockerfile 与 package.json 各写一套必然漂移(2026-10-08 收敛)。
|
|
15018
|
-
// fullstack 的前端产物在 site/(vite build);function / empty 无前端产物,故不指目录。
|
|
15019
|
-
start: template === "fullstack" ? "adep serve --host 0.0.0.0 --static site" : "adep serve --host 0.0.0.0",
|
|
15020
|
-
deploy: "adep publish --only functions",
|
|
15021
|
-
doctor: "adep doctor"
|
|
15022
|
-
},
|
|
15219
|
+
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`,
|
|
15220
|
+
scripts,
|
|
15023
15221
|
dependencies: {
|
|
15024
15222
|
"@adep/cli": cliVersion,
|
|
15025
|
-
|
|
15223
|
+
// 前端依赖只在有前端工程时才声明(vue / @adep/client 运行时不需要)。
|
|
15224
|
+
...hasFrontend ? WEB_DEPENDENCIES : {}
|
|
15026
15225
|
},
|
|
15027
|
-
devDependencies: WEB_DEV_DEPENDENCIES,
|
|
15226
|
+
devDependencies: hasFrontend ? WEB_DEV_DEPENDENCIES : {},
|
|
15028
15227
|
engines: {
|
|
15029
15228
|
node: ">=18",
|
|
15030
15229
|
bun: ">=1.0"
|
|
@@ -15066,7 +15265,7 @@ var COUNTDOWN_PACKAGE_JSON = (name, cliVersion) => {
|
|
|
15066
15265
|
"@adep/runtime": "^0.3.0",
|
|
15067
15266
|
"@vitejs/plugin-vue": "^6.0.0",
|
|
15068
15267
|
"esbuild-wasm": "^0.25.12",
|
|
15069
|
-
typescript: "
|
|
15268
|
+
typescript: "6.0.3",
|
|
15070
15269
|
vite: "^7.0.0",
|
|
15071
15270
|
// vitest 用 ^3.2.4:vitest 4.x 的 packument 触发 npm 10.9 arborist edgesOut 崩溃(官方源同样),
|
|
15072
15271
|
// 与 countdown 模板保持一致。
|
|
@@ -15195,7 +15394,7 @@ var DOCKER_ASSETS = (name) => [
|
|
|
15195
15394
|
{ path: ".dockerignore", content: DOCKERIGNORE },
|
|
15196
15395
|
{ path: ".env.example", content: ENV_EXAMPLE }
|
|
15197
15396
|
];
|
|
15198
|
-
var
|
|
15397
|
+
var README_FULLSTACK = (name, template) => `# ${name}
|
|
15199
15398
|
|
|
15200
15399
|
AgentDeploy \u5168\u6808\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u3002
|
|
15201
15400
|
|
|
@@ -15306,6 +15505,66 @@ console.log(result.message)
|
|
|
15306
15505
|
\`web/src/\` \u5B58\u653E\u524D\u7AEF\u6E90\u7801\uFF08\`main.ts\` / \`App.vue\`\uFF09\uFF0C\u4E0E Web IDE \u5185 \`web/\` \u5DE5\u7A0B\u7684 \`src/\`
|
|
15307
15506
|
\u5B8C\u5168\u540C\u6784\uFF1Bvite \u5DE5\u7A0B\u6839\u5728\u9879\u76EE\u6839\u76EE\u5F55\uFF08\`vite.config.ts\` / \`index.html\` / \`package.json\`\uFF09\u3002
|
|
15308
15507
|
`;
|
|
15508
|
+
var README_FUNCTION_ONLY = (name, template) => `# ${name}
|
|
15509
|
+
|
|
15510
|
+
${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"}
|
|
15511
|
+
|
|
15512
|
+
## \u5E38\u7528\u547D\u4EE4
|
|
15513
|
+
|
|
15514
|
+
- \`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
|
|
15515
|
+
\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
|
|
15516
|
+
\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
|
|
15517
|
+
\u7AEF\u53E3\u88AB\u5360\u7528\u4F1A\u81EA\u52A8\u987A\u5EF6\uFF0C\u4EE5\u6A2A\u5E45\u5B9E\u9645\u6253\u5370\u7684\u4E3A\u51C6\u3002
|
|
15518
|
+
- \`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
|
|
15519
|
+
- \`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
|
|
15520
|
+
- \`pnpm doctor\`\uFF08= \`adep doctor\`\uFF09\uFF1A\u672C\u5730\u73AF\u5883\u79BB\u7EBF\u8BCA\u65AD
|
|
15521
|
+
|
|
15522
|
+
> \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
|
|
15523
|
+
> \u9700\u8981\u524D\u7AEF\uFF08Vue 3 + Vite\uFF09\u8BF7\u6539\u7528 \`adep init <name> -t fullstack\`\u3002
|
|
15524
|
+
|
|
15525
|
+
## pnpm \u4E0E\u4F9D\u8D56\u6784\u5EFA\u811A\u672C\uFF08pnpm 10 \u8D77\u9ED8\u8BA4\u4E0D\u8DD1\uFF09
|
|
15526
|
+
|
|
15527
|
+
\u9879\u76EE\u6839\u7684 \`pnpm-workspace.yaml\` \u5DF2\u653E\u884C \`esbuild\` \u7684\u6784\u5EFA\u811A\u672C\uFF08\`onlyBuiltDependencies\` \u4E0E
|
|
15528
|
+
\`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
|
|
15529
|
+
\u6784\u5EFA\u811A\u672C**\uFF0C\u5220\u6389\u8FD9\u4EFD\u914D\u7F6E\u540E \`pnpm install\` \u4F1A\u4EE5 \`ERR_PNPM_IGNORED_BUILDS\` \u62A5\u9519
|
|
15530
|
+
\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
|
|
15531
|
+
\`package.json\` \u91CC\u5199 \`"pnpm": { "onlyBuiltDependencies": ["esbuild"] }\`\u3002
|
|
15532
|
+
|
|
15533
|
+
${DOCKER_README_SECTION()}
|
|
15534
|
+
|
|
15535
|
+
## \u76EE\u5F55\u7ED3\u6784
|
|
15536
|
+
|
|
15537
|
+
- \`package.json\`\uFF1A\u5E94\u7528\u5B9A\u4E49\uFF08\u4EC5 \`@adep/cli\` \u4F9D\u8D56\uFF1B**\u65E0\u524D\u7AEF\u4F9D\u8D56**\uFF09
|
|
15538
|
+
- \`adep.config.ts\`\uFF1A\u9879\u76EE\u914D\u7F6E\uFF08name / template / functionsDir / functions_prefix\uFF0C\u9ED8\u8BA4 /api\uFF09
|
|
15539
|
+
- \`functions/\`\uFF1A\u4E91\u51FD\u6570\u76EE\u5F55\u2014\u2014\`functions/<name>.ts\` \u4E0E \`functions/<name>/index.ts\`
|
|
15540
|
+
\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
|
|
15541
|
+
\u51FD\u6570\u7684\u79C1\u6709\u6587\u4EF6\uFF09\uFF1B\u9ED8\u8BA4\u5BFC\u51FA \`(ctx: AdepContext) => Response\`\u3002\`functions/_shared/**\` \u662F
|
|
15542
|
+
\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\`
|
|
15543
|
+
- \`tsconfig.json\`\uFF1ATypeScript \u7F16\u8F91\u5668\u914D\u7F6E\uFF08strict + noEmit\uFF09
|
|
15544
|
+
- \`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
|
|
15545
|
+
|
|
15546
|
+
## \u4E91\u51FD\u6570\u8DEF\u7531\u524D\u7F00\uFF08functions_prefix\uFF09
|
|
15547
|
+
|
|
15548
|
+
\`adep.config.ts\` \u7684 \`functions_prefix\`\uFF08\u9ED8\u8BA4 \`/api\`\uFF09\uFF1A
|
|
15549
|
+
- \`adep dev\`\uFF1A\`/{prefix}/{fn}\`\uFF0C\u5982 \`/api/hello\`\u3002
|
|
15550
|
+
- \`adep serve\`\uFF1A\`/api/{prefix}/{fn}\`\uFF08\u524D\u7F00\u62FC\u63A5\uFF09\u3002
|
|
15551
|
+
- **\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
|
|
15552
|
+
\u4E0D\u968F\u524D\u7F00\u53D8\u5316\uFF08\u4E0E\u7EBF\u4E0A\u540C\u6784\uFF09\u3002
|
|
15553
|
+
|
|
15554
|
+
## \u4E91\u51FD\u6570\u7C7B\u578B\u63D0\u793A
|
|
15555
|
+
|
|
15556
|
+
\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
|
|
15557
|
+
\`tsconfig.json\` \u4F1A\u628A \`adep.d.ts\` \u7EB3\u5165 include\uFF0C\u51FD\u6570\u53C2\u6570\u5199 \`ctx: AdepContext\` \u5373\u53EF\u3002
|
|
15558
|
+
\`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
|
|
15559
|
+
|
|
15560
|
+
## \u6A21\u677F\u8BF4\u660E\uFF08adep init\uFF09
|
|
15561
|
+
|
|
15562
|
+
- \`adep init <name>\`\uFF1A\u9ED8\u8BA4 \`fullstack\` \u6A21\u677F\uFF08functions/ + web/src/ \u524D\u7AEF\u6E90\u7801 + database/\uFF09
|
|
15563
|
+
- \`adep init <name> -t function\`\uFF1A\u4EC5\u4E91\u51FD\u6570\uFF08\u5355\u4E2A\u793A\u4F8B\u51FD\u6570\uFF09\u2014\u2014**\u672C\u6A21\u677F**
|
|
15564
|
+
- \`adep init <name> -t empty\`\uFF1A\u7A7A\u6A21\u677F\uFF08\u4EC5\u9879\u76EE\u9AA8\u67B6\uFF09
|
|
15565
|
+
- \`adep init --list\`\uFF1A\u4ECE\u5E73\u53F0 /api/v1/templates \u5217\u51FA\u53EF\u7528\u6A21\u677F
|
|
15566
|
+
- \`adep init --list -s <server>\`\uFF1A\u6307\u5B9A\u5E73\u53F0\u5730\u5740
|
|
15567
|
+
`;
|
|
15309
15568
|
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
|
|
15310
15569
|
// \u9ED8\u8BA4\u5BFC\u51FA (ctx: AdepContext) => Response \u5F62\u72B6\u7684\u5904\u7406\u5668\uFF08\u5951\u7EA6\u89C1 adep.d.ts\uFF09\u3002
|
|
15311
15570
|
//
|
|
@@ -15377,10 +15636,17 @@ var SHARED_ASSETS = {
|
|
|
15377
15636
|
packageJson: (ctx) => [
|
|
15378
15637
|
{
|
|
15379
15638
|
path: "package.json",
|
|
15380
|
-
content: ctx.template === "countdown" ? COUNTDOWN_PACKAGE_JSON(ctx.name, ctx.cliVersion) : PACKAGE_JSON(ctx
|
|
15639
|
+
content: ctx.template === "countdown" ? COUNTDOWN_PACKAGE_JSON(ctx.name, ctx.cliVersion) : PACKAGE_JSON(ctx)
|
|
15640
|
+
}
|
|
15641
|
+
],
|
|
15642
|
+
readme: (ctx) => [
|
|
15643
|
+
{
|
|
15644
|
+
path: "README.md",
|
|
15645
|
+
// README 的口径必须与 package.json 的 scripts 一致(两份不许各说一套):
|
|
15646
|
+
// 无前端模板给函数侧版本,否则会写出跑不通的 vite 命令与不存在的目录。
|
|
15647
|
+
content: ctx.hasFrontend ? README_FULLSTACK(ctx.name, ctx.template) : README_FUNCTION_ONLY(ctx.name, ctx.template)
|
|
15381
15648
|
}
|
|
15382
15649
|
],
|
|
15383
|
-
readme: (ctx) => [{ path: "README.md", content: README(ctx.name, ctx.template) }],
|
|
15384
15650
|
adepConfig: (ctx) => [
|
|
15385
15651
|
{
|
|
15386
15652
|
path: "adep.config.ts",
|
|
@@ -15505,6 +15771,10 @@ function cliPackageRoot() {
|
|
|
15505
15771
|
function localTemplateDir(code) {
|
|
15506
15772
|
return join2(cliPackageRoot(), "src", "templates", code);
|
|
15507
15773
|
}
|
|
15774
|
+
var FRONTEND_ASSETS = /* @__PURE__ */ new Set(["webSrc", "viteConfig", "indexHtml"]);
|
|
15775
|
+
function hasFrontendAssets(sharedAssets) {
|
|
15776
|
+
return (sharedAssets ?? []).some((asset) => FRONTEND_ASSETS.has(asset));
|
|
15777
|
+
}
|
|
15508
15778
|
function templateFiles(code, name) {
|
|
15509
15779
|
const generated = GENERATED_TEMPLATES[code];
|
|
15510
15780
|
if (generated === void 0) {
|
|
@@ -15518,7 +15788,12 @@ function renderTemplatePackage(pkg, name) {
|
|
|
15518
15788
|
const vars = { name, template: pkg.code };
|
|
15519
15789
|
const dirFiles = renderTemplateFiles(pkg.files, vars, manifest2);
|
|
15520
15790
|
const code = pkg.code;
|
|
15521
|
-
const ctx = {
|
|
15791
|
+
const ctx = {
|
|
15792
|
+
name,
|
|
15793
|
+
template: code,
|
|
15794
|
+
cliVersion: cliVersionOf(),
|
|
15795
|
+
hasFrontend: hasFrontendAssets(manifest2.sharedAssets)
|
|
15796
|
+
};
|
|
15522
15797
|
const sharedFiles = (manifest2.sharedAssets ?? []).flatMap((assetName) => {
|
|
15523
15798
|
const asset = SHARED_ASSETS[assetName];
|
|
15524
15799
|
if (asset === void 0) {
|
|
@@ -38635,7 +38910,7 @@ function registerApp(program2, ctx) {
|
|
|
38635
38910
|
// packages/cli/src/import-cf.ts
|
|
38636
38911
|
init_adep_config();
|
|
38637
38912
|
init_regexp();
|
|
38638
|
-
import { copyFile as copyFile4, mkdir as mkdir13, readFile as readFile19, readdir as readdir8, stat as stat11, writeFile as writeFile14 } from "node:fs/promises";
|
|
38913
|
+
import { copyFile as copyFile4, mkdir as mkdir13, open as open4, readFile as readFile19, readdir as readdir8, stat as stat11, writeFile as writeFile14 } from "node:fs/promises";
|
|
38639
38914
|
import { basename as basename3, dirname as dirname11, join as join27, relative as relative3, resolve as resolve11 } from "node:path";
|
|
38640
38915
|
var TomlSyntaxError = class extends Error {
|
|
38641
38916
|
constructor(message) {
|
|
@@ -39136,7 +39411,7 @@ function renderMigrationReport(config2, result) {
|
|
|
39136
39411
|
"",
|
|
39137
39412
|
`- worker\uFF1A\`${config2.main ?? "(\u65E0 main)"}\` \u2192 \`functions/${result.workerName}/\``,
|
|
39138
39413
|
`- vars\uFF1A${result.mapping.vars} \u4E2A \u2192 adep.config.ts environment`,
|
|
39139
|
-
result.mapping.secretsFromDevVars ?
|
|
39414
|
+
result.mapping.secretsFromDevVars ? `- secrets\uFF08.dev.vars\uFF09\u2192 .env.local\uFF080600\uFF0C\u5DF2\u5217\u5165\u751F\u6210\u7684 .gitignore\uFF1B\u672C\u5730 dev/serve \u81EA\u52A8\u88C5\u8F7D\uFF0C\u4E0A\u7EBF\u7528 \`adep env push\` \u63A8\u5E73\u53F0 env\uFF09` : "",
|
|
39140
39415
|
`- KV \u7ED1\u5B9A\uFF1A${result.mapping.kv} \u4E2A`,
|
|
39141
39416
|
`- D1 \u7ED1\u5B9A\uFF1A${result.mapping.d1} \u4E2A`,
|
|
39142
39417
|
`- R2 \u7ED1\u5B9A\uFF1A${result.mapping.r2} \u4E2A`,
|
|
@@ -39220,14 +39495,13 @@ async function importCfProject(cwd, sourceDir, options = {}) {
|
|
|
39220
39495
|
}
|
|
39221
39496
|
const { cfBindings, environment } = bindingsFromWrangler(config2);
|
|
39222
39497
|
const devVars = await readDevVars(sourceDir);
|
|
39223
|
-
const mergedEnv = environment === void 0 && Object.keys(devVars).length === 0 ? void 0 : { ...environment, ...devVars };
|
|
39224
39498
|
const files = [];
|
|
39225
39499
|
const warnings = [];
|
|
39226
39500
|
const adepConfig = {
|
|
39227
39501
|
name: workerName,
|
|
39228
39502
|
functionsDir: "functions",
|
|
39229
39503
|
functions_prefix: "/api",
|
|
39230
|
-
...
|
|
39504
|
+
...environment === void 0 ? {} : { environment },
|
|
39231
39505
|
...cfBindings === void 0 ? {} : { cfBindings }
|
|
39232
39506
|
};
|
|
39233
39507
|
const configText = renderAdepConfig(adepConfig, {
|
|
@@ -39236,6 +39510,29 @@ async function importCfProject(cwd, sourceDir, options = {}) {
|
|
|
39236
39510
|
await mkdir13(outDir, { recursive: true });
|
|
39237
39511
|
await writeFile14(join27(outDir, "adep.config.ts"), configText, "utf8");
|
|
39238
39512
|
files.push("adep.config.ts");
|
|
39513
|
+
const secretCount = Object.keys(devVars).length;
|
|
39514
|
+
if (secretCount > 0) {
|
|
39515
|
+
const envLocalText = `# \u7531 adep import cf \u751F\u6210\uFF1A.dev.vars\uFF08\u672C\u5730\u5F00\u53D1\u5BC6\u94A5\uFF09\u8FC1\u5230\u8FD9\u91CC\u3002
|
|
39516
|
+
# \u672C\u5730 dev/serve \u81EA\u52A8\u88C5\u8F7D\u5E76\u8986\u76D6 adep.config.ts \u7684 environment\uFF1B
|
|
39517
|
+
# \u4E0A\u7EBF\u7528 adep env push \u63A8\u5230\u5E73\u53F0 env\uFF08isSecret \u52A0\u5BC6\u843D\u5E93\uFF09\u3002\u672C\u6587\u4EF6\u7EDD\u4E0D\u5165\u5E93\u3002
|
|
39518
|
+
` + Object.entries(devVars).map(([key, value]) => `${key}=${value}`).join("\n") + "\n";
|
|
39519
|
+
const handle = await open4(join27(outDir, ".env.local"), "w", 384);
|
|
39520
|
+
try {
|
|
39521
|
+
await handle.writeFile(envLocalText, "utf8");
|
|
39522
|
+
} finally {
|
|
39523
|
+
await handle.close();
|
|
39524
|
+
}
|
|
39525
|
+
files.push(".env.local");
|
|
39526
|
+
warnings.push(
|
|
39527
|
+
`.dev.vars \u7684 ${secretCount} \u4E2A\u5BC6\u94A5\u5DF2\u5199\u5165 .env.local\uFF080600\uFF0C\u4E0D\u8FDB adep.config.ts\uFF09\uFF1B\u672C\u5730 dev/serve \u76F4\u63A5\u751F\u6548\uFF0C\u4E0A\u7EBF\u7528 adep env push \u63A8\u5E73\u53F0 env`
|
|
39528
|
+
);
|
|
39529
|
+
await writeFile14(
|
|
39530
|
+
join27(outDir, ".gitignore"),
|
|
39531
|
+
"# adep import cf \u751F\u6210\uFF1A.env.local \u662F\u672C\u5730\u5BC6\u94A5\u8986\u76D6\u5C42\uFF08dev/serve \u81EA\u52A8\u88C5\u8F7D\uFF09\uFF0C\u7EDD\u4E0D\u5165\u5E93\n.env.local\n",
|
|
39532
|
+
"utf8"
|
|
39533
|
+
);
|
|
39534
|
+
files.push(".gitignore");
|
|
39535
|
+
}
|
|
39239
39536
|
await writeFile14(join27(outDir, "package.json"), renderImportPackageJson(workerName), "utf8");
|
|
39240
39537
|
files.push("package.json");
|
|
39241
39538
|
let mainCopied = false;
|
|
@@ -39333,14 +39630,15 @@ async function importCfProject(cwd, sourceDir, options = {}) {
|
|
|
39333
39630
|
}
|
|
39334
39631
|
}
|
|
39335
39632
|
const mapping = {
|
|
39336
|
-
vars: Object.keys(
|
|
39633
|
+
vars: Object.keys(environment ?? {}).length,
|
|
39337
39634
|
kv: config2.kv_namespaces?.length ?? 0,
|
|
39338
39635
|
d1: config2.d1_databases?.length ?? 0,
|
|
39339
39636
|
r2: config2.r2_buckets?.length ?? 0,
|
|
39340
39637
|
dos: dosMigrated,
|
|
39341
39638
|
crons: config2.triggers?.crons ?? [],
|
|
39342
39639
|
assets: assetsCopied,
|
|
39343
|
-
secretsFromDevVars:
|
|
39640
|
+
secretsFromDevVars: secretCount > 0,
|
|
39641
|
+
secretsCount: secretCount
|
|
39344
39642
|
};
|
|
39345
39643
|
const unsupported = unsupportedFromWrangler(config2);
|
|
39346
39644
|
const migration = renderMigrationReport(config2, {
|
|
@@ -40647,9 +40945,98 @@ ${renderDrift(diff, { indexStatements: true }).join("\n")}`
|
|
|
40647
40945
|
|
|
40648
40946
|
// packages/cli/src/commands/env.ts
|
|
40649
40947
|
init_auth();
|
|
40650
|
-
|
|
40651
|
-
import {
|
|
40948
|
+
import { readFile as readFile31, writeFile as writeFile17 } from "node:fs/promises";
|
|
40949
|
+
import { join as join38 } from "node:path";
|
|
40950
|
+
|
|
40951
|
+
// packages/cli/src/env-push.ts
|
|
40952
|
+
init_auth();
|
|
40953
|
+
init_client();
|
|
40954
|
+
import { readFile as readFile30 } from "node:fs/promises";
|
|
40652
40955
|
import { join as join37 } from "node:path";
|
|
40956
|
+
var SECRET_KEY_RE = /SECRET|TOKEN|APPKEY|API_KEY|(^|_)KEY|PASSWORD|PASSWD|PRIVATE/i;
|
|
40957
|
+
function looksSecret(key, forcedSecret, forcedPublic) {
|
|
40958
|
+
if (forcedPublic.has(key)) return false;
|
|
40959
|
+
if (forcedSecret.has(key)) return true;
|
|
40960
|
+
return SECRET_KEY_RE.test(key);
|
|
40961
|
+
}
|
|
40962
|
+
function parseKeyList(raw) {
|
|
40963
|
+
if (raw === void 0 || raw.trim() === "") return /* @__PURE__ */ new Set();
|
|
40964
|
+
return new Set(
|
|
40965
|
+
raw.split(",").map((part) => part.trim()).filter((part) => part.length > 0)
|
|
40966
|
+
);
|
|
40967
|
+
}
|
|
40968
|
+
function parseEnvText(text) {
|
|
40969
|
+
const out = {};
|
|
40970
|
+
for (const line of text.split(/\r?\n/)) {
|
|
40971
|
+
const trimmed = line.trim();
|
|
40972
|
+
if (trimmed === "" || trimmed.startsWith("#")) continue;
|
|
40973
|
+
const eq = trimmed.indexOf("=");
|
|
40974
|
+
if (eq <= 0) continue;
|
|
40975
|
+
const key = trimmed.slice(0, eq).trim();
|
|
40976
|
+
out[key] = trimmed.slice(eq + 1).trim().replace(/^['"]|['"]$/g, "");
|
|
40977
|
+
}
|
|
40978
|
+
return out;
|
|
40979
|
+
}
|
|
40980
|
+
async function envPush(paths, cwd, options = {}) {
|
|
40981
|
+
const environment = options.environment ?? "dev";
|
|
40982
|
+
const forcedSecret = parseKeyList(options.secretKeys);
|
|
40983
|
+
const forcedPublic = parseKeyList(options.publicKeys);
|
|
40984
|
+
const file2 = options.file ?? ".env.local";
|
|
40985
|
+
const text = await readFile30(join37(cwd, file2), "utf8").catch(() => {
|
|
40986
|
+
throw new CliError(
|
|
40987
|
+
"ENV_FILE_MISSING",
|
|
40988
|
+
`\u627E\u4E0D\u5230 ${join37(cwd, file2)}\uFF1A\u5148 adep env set \u6216 adep env push --file <path>`
|
|
40989
|
+
);
|
|
40990
|
+
});
|
|
40991
|
+
const vars = parseEnvText(text);
|
|
40992
|
+
const keys = Object.keys(vars);
|
|
40993
|
+
if (keys.length === 0) {
|
|
40994
|
+
throw new CliError("ENV_FILE_EMPTY", `${file2} \u91CC\u6CA1\u6709\u53EF\u63A8\u9001\u7684\u952E\uFF08\u7A7A\u6587\u4EF6\u6216\u53EA\u6709\u6CE8\u91CA\uFF09`);
|
|
40995
|
+
}
|
|
40996
|
+
const skipped = keys.filter((key) => (vars[key] ?? "") === "");
|
|
40997
|
+
if (options.dryRun === true) {
|
|
40998
|
+
return {
|
|
40999
|
+
projectId: "",
|
|
41000
|
+
environment,
|
|
41001
|
+
pushed: keys.filter((key) => !skipped.includes(key)).map((key) => ({ key, isSecret: looksSecret(key, forcedSecret, forcedPublic), ok: false })),
|
|
41002
|
+
skipped
|
|
41003
|
+
};
|
|
41004
|
+
}
|
|
41005
|
+
const client = await createClient(paths);
|
|
41006
|
+
const project2 = await resolveProjectId(client, cwd, options.slug);
|
|
41007
|
+
const pushed = [];
|
|
41008
|
+
for (const key of keys) {
|
|
41009
|
+
if (skipped.includes(key)) continue;
|
|
41010
|
+
const isSecret = looksSecret(key, forcedSecret, forcedPublic);
|
|
41011
|
+
try {
|
|
41012
|
+
await client.request(`/api/v1/projects/${project2.id}/env`, {
|
|
41013
|
+
method: "POST",
|
|
41014
|
+
body: { environment, key, value: vars[key], isSecret }
|
|
41015
|
+
});
|
|
41016
|
+
pushed.push({ key, isSecret, ok: true });
|
|
41017
|
+
} catch (error62) {
|
|
41018
|
+
pushed.push({
|
|
41019
|
+
key,
|
|
41020
|
+
isSecret,
|
|
41021
|
+
ok: false,
|
|
41022
|
+
error: error62 instanceof Error ? error62.message : String(error62)
|
|
41023
|
+
});
|
|
41024
|
+
}
|
|
41025
|
+
}
|
|
41026
|
+
return { projectId: project2.id, environment, pushed, skipped };
|
|
41027
|
+
}
|
|
41028
|
+
async function envRemote(paths, cwd, options = {}) {
|
|
41029
|
+
const environment = options.environment ?? "dev";
|
|
41030
|
+
const client = await createClient(paths);
|
|
41031
|
+
const project2 = await resolveProjectId(client, cwd, options.slug);
|
|
41032
|
+
const listed = await client.request(
|
|
41033
|
+
`/api/v1/projects/${project2.id}/env?environment=${environment}`
|
|
41034
|
+
);
|
|
41035
|
+
return { projectId: project2.id, environment, vars: listed.vars ?? [] };
|
|
41036
|
+
}
|
|
41037
|
+
|
|
41038
|
+
// packages/cli/src/commands/env.ts
|
|
41039
|
+
init_env();
|
|
40653
41040
|
var ENV_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
40654
41041
|
function upsertEnvLine(content, key, value) {
|
|
40655
41042
|
const lines = content.split(/\r?\n/);
|
|
@@ -40689,7 +41076,7 @@ function mergeEnvKeyEntries(env, local) {
|
|
|
40689
41076
|
return entries;
|
|
40690
41077
|
}
|
|
40691
41078
|
function registerEnv(program2, ctx) {
|
|
40692
|
-
const envCommand = program2.command("env").description("\u9879\u76EE env
|
|
41079
|
+
const envCommand = program2.command("env").description("\u9879\u76EE env\uFF1A\u672C\u5730\u53EF\u89C6\u5316\u4E0E\u5199\u5165\uFF08.env.local \u8986\u76D6 .env\uFF09+ \u5E73\u53F0 env \u63A8\u9001/\u67E5\u770B");
|
|
40693
41080
|
envCommand.command("list").description("\u5217\u51FA\u751F\u6548 env \u952E\u4E0E\u6765\u6E90\u6587\u4EF6\uFF08\u4E0D\u56DE\u663E\u503C\uFF1B\u8FDC\u7AEF\u4E0D\u53EF\u8FBE\u65F6\u6807\u6CE8\u539F\u56E0\uFF09").action(async () => {
|
|
40694
41081
|
const command = ctx.io("env list");
|
|
40695
41082
|
await command.run(async () => {
|
|
@@ -40700,10 +41087,11 @@ function registerEnv(program2, ctx) {
|
|
|
40700
41087
|
envKeyCount: views.env === null ? 0 : Object.keys(views.env).length,
|
|
40701
41088
|
localKeyCount: views.local === null ? 0 : Object.keys(views.local).length,
|
|
40702
41089
|
keys,
|
|
40703
|
-
//
|
|
41090
|
+
// 远端对照面(显式分开,不静默混排):本地视图只认 .env / .env.local;
|
|
41091
|
+
// 平台侧是另一份 env(线上函数读的是它)——用 `adep env remote` 对照。
|
|
40704
41092
|
remote: {
|
|
40705
41093
|
available: false,
|
|
40706
|
-
reason: "
|
|
41094
|
+
reason: "\u5E73\u53F0 env \u662F\u72EC\u7ACB\u7684\u4E00\u4EFD\uFF08\u7EBF\u4E0A\u51FD\u6570\u8BFB\u7684\u662F\u5B83\uFF09\uFF1Aadep env remote \u67E5\u770B\u3001adep env push \u63A8\u9001"
|
|
40707
41095
|
}
|
|
40708
41096
|
};
|
|
40709
41097
|
command.ok(data, () => {
|
|
@@ -40744,10 +41132,14 @@ function registerEnv(program2, ctx) {
|
|
|
40744
41132
|
source,
|
|
40745
41133
|
overridden: source === ".env.local" && inEnv !== void 0
|
|
40746
41134
|
};
|
|
40747
|
-
command.ok(data, () => [
|
|
41135
|
+
command.ok(data, () => [
|
|
41136
|
+
`${key}=${value}\uFF08\u6765\u6E90 ${source}${data.overridden ? "\uFF0C\u8986\u76D6 .env" : ""}\uFF09`
|
|
41137
|
+
]);
|
|
40748
41138
|
});
|
|
40749
41139
|
});
|
|
40750
|
-
envCommand.command("set <key> <value...>").description(
|
|
41140
|
+
envCommand.command("set <key> <value...>").description(
|
|
41141
|
+
"\u5199\u5165 .env.local\uFF08\u8986\u76D6\u5C42\uFF1B\u503C\u53EF\u5F15\u53F7\u5305\u88F9\u4FDD\u5F62\uFF0C\u672A\u5F15\u53F7\u7684\u591A\u8BCD\u4EE5\u5355\u7A7A\u683C\u62FC\u63A5\uFF1B\u4E0B\u6B21 dev/serve \u88C5\u8F7D\u5373\u751F\u6548\uFF09"
|
|
41142
|
+
).action(async (key, valueParts) => {
|
|
40751
41143
|
const command = ctx.io("env set");
|
|
40752
41144
|
await command.run(async () => {
|
|
40753
41145
|
if (!ENV_KEY_RE.test(key)) {
|
|
@@ -40757,7 +41149,7 @@ function registerEnv(program2, ctx) {
|
|
|
40757
41149
|
);
|
|
40758
41150
|
}
|
|
40759
41151
|
const value = valueParts.join(" ");
|
|
40760
|
-
const localPath =
|
|
41152
|
+
const localPath = join38(ctx.cwd, ".env.local");
|
|
40761
41153
|
const existing = await readFileText(localPath);
|
|
40762
41154
|
const replaced = findEnvLine(existing, key) !== void 0;
|
|
40763
41155
|
await writeFile17(localPath, upsertEnvLine(existing, key, value), "utf8");
|
|
@@ -40768,9 +41160,79 @@ function registerEnv(program2, ctx) {
|
|
|
40768
41160
|
]);
|
|
40769
41161
|
});
|
|
40770
41162
|
});
|
|
41163
|
+
envCommand.command("push").description(
|
|
41164
|
+
"\u628A\u672C\u5730 env \u6587\u4EF6\u63A8\u5230\u5E73\u53F0\u9879\u76EE env\uFF08\u7F3A\u7701 dev\uFF1B\u503C\u4E0D\u56DE\u663E\uFF1B--dry \u53EA\u5217\u952E\u3002isSecret \u6309\u952E\u540D\u542F\u53D1\u5F0F\u5224\u5B9A\uFF0C\u53EF\u7528 --secret/--public \u663E\u5F0F\u6307\u5B9A\uFF09"
|
|
41165
|
+
).option("--environment <env>", "\u76EE\u6807\u73AF\u5883\u69FD dev/staging/prod\uFF08\u7F3A\u7701 dev\uFF09").option("--file <path>", "\u6E90 env \u6587\u4EF6\uFF08\u76F8\u5BF9 cwd\uFF0C\u7F3A\u7701 .env.local\uFF09").option("--secret <keys>", "\u5F3A\u5236\u6309 secret \u63A8\u9001\u7684\u952E\uFF08\u9017\u53F7\u5206\u9694\uFF09").option("--public <keys>", "\u5F3A\u5236\u6309\u516C\u5F00\u63A8\u9001\u7684\u952E\uFF08\u9017\u53F7\u5206\u9694\uFF09").option("--project <slug>", "\u76EE\u6807\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").option("--dry-run", "\u53EA\u5217\u5C06\u63A8\u9001\u7684\u952E\u4E0E secret \u5224\u5B9A\uFF0C\u4E0D\u53D1\u8BF7\u6C42").action(async (flags) => {
|
|
41166
|
+
const command = ctx.io("env push");
|
|
41167
|
+
await command.run(async () => {
|
|
41168
|
+
const environment = flags["environment"];
|
|
41169
|
+
if (environment !== void 0 && !["dev", "staging", "prod"].includes(environment)) {
|
|
41170
|
+
throw new CliError(
|
|
41171
|
+
"INVALID_ENVIRONMENT",
|
|
41172
|
+
`\u73AF\u5883\u69FD "${environment}" \u975E\u6CD5\uFF1A\u53EF\u9009 dev / staging / prod`
|
|
41173
|
+
);
|
|
41174
|
+
}
|
|
41175
|
+
const file2 = flags["file"];
|
|
41176
|
+
const secretKeys = flags["secret"];
|
|
41177
|
+
const publicKeys = flags["public"];
|
|
41178
|
+
const projectSlug = flags["project"];
|
|
41179
|
+
const result = await envPush(ctx.paths, ctx.cwd, {
|
|
41180
|
+
...environment === void 0 ? {} : { environment },
|
|
41181
|
+
...file2 === void 0 ? {} : { file: file2 },
|
|
41182
|
+
dryRun: flags["dryRun"] === true,
|
|
41183
|
+
...secretKeys === void 0 ? {} : { secretKeys },
|
|
41184
|
+
...publicKeys === void 0 ? {} : { publicKeys },
|
|
41185
|
+
...projectSlug === void 0 ? {} : { slug: projectSlug }
|
|
41186
|
+
});
|
|
41187
|
+
const dry = flags["dryRun"] === true;
|
|
41188
|
+
command.ok(
|
|
41189
|
+
{
|
|
41190
|
+
dryRun: dry,
|
|
41191
|
+
projectId: result.projectId,
|
|
41192
|
+
environment: result.environment,
|
|
41193
|
+
keys: result.pushed.map((item) => ({
|
|
41194
|
+
key: item.key,
|
|
41195
|
+
isSecret: item.isSecret,
|
|
41196
|
+
ok: item.ok
|
|
41197
|
+
})),
|
|
41198
|
+
skipped: result.skipped
|
|
41199
|
+
},
|
|
41200
|
+
() => [
|
|
41201
|
+
`${dry ? "\u5C06\u63A8\u9001\uFF08dry-run\uFF0C\u672A\u53D1\u8BF7\u6C42\uFF09" : "\u63A8\u9001"}\u5230\u5E73\u53F0 ${result.environment}\uFF08\u9879\u76EE ${result.projectId}\uFF09\uFF1A`,
|
|
41202
|
+
...result.pushed.map((item) => {
|
|
41203
|
+
const tag = item.isSecret ? "secret" : "public";
|
|
41204
|
+
if (dry) return ` ${item.key}\uFF08${tag}\uFF09`;
|
|
41205
|
+
return item.ok ? ` \u2713 ${item.key}\uFF08${tag}\uFF09` : ` \u2717 ${item.key} \u2192 ${item.error ?? "\u5931\u8D25"}`;
|
|
41206
|
+
}),
|
|
41207
|
+
...result.skipped.length > 0 ? [`\u8DF3\u8FC7\u7A7A\u503C\u952E\uFF1A${result.skipped.join(", ")}`] : [],
|
|
41208
|
+
"\u503C\u4E0D\u56DE\u663E\uFF1Bsecret \u5728\u5E73\u53F0\u4FA7\u52A0\u5BC6\u843D\u5E93\uFF0Cenv remote \u53EA\u56DE\u63A9\u7801\u3002"
|
|
41209
|
+
]
|
|
41210
|
+
);
|
|
41211
|
+
});
|
|
41212
|
+
});
|
|
41213
|
+
envCommand.command("remote").description("\u5217\u5E73\u53F0\u9879\u76EE env\uFF08secret \u53EA\u56DE\u63A9\u7801\u2014\u2014\u63A9\u7801\u7531\u670D\u52A1\u7AEF\u751F\u6210\uFF0CCLI \u4E0D\u78B0\u660E\u6587\uFF09").option("--environment <env>", "\u73AF\u5883\u69FD dev/staging/prod\uFF08\u7F3A\u7701 dev\uFF09").option("--project <slug>", "\u76EE\u6807\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (flags) => {
|
|
41214
|
+
const command = ctx.io("env remote");
|
|
41215
|
+
await command.run(async () => {
|
|
41216
|
+
const environment = flags["environment"];
|
|
41217
|
+
if (environment !== void 0 && !["dev", "staging", "prod"].includes(environment)) {
|
|
41218
|
+
throw new CliError(
|
|
41219
|
+
"INVALID_ENVIRONMENT",
|
|
41220
|
+
`\u73AF\u5883\u69FD "${environment}" \u975E\u6CD5\uFF1A\u53EF\u9009 dev / staging / prod`
|
|
41221
|
+
);
|
|
41222
|
+
}
|
|
41223
|
+
const result = await envRemote(ctx.paths, ctx.cwd, {
|
|
41224
|
+
...environment === void 0 ? {} : { environment },
|
|
41225
|
+
...flags["project"] === void 0 ? {} : { slug: flags["project"] }
|
|
41226
|
+
});
|
|
41227
|
+
command.ok(result, () => [
|
|
41228
|
+
`\u5E73\u53F0 ${result.environment}\uFF08\u9879\u76EE ${result.projectId}\uFF09\u5171 ${result.vars.length} \u952E\uFF1A`,
|
|
41229
|
+
...result.vars.length === 0 ? [" \uFF08\u8BE5\u73AF\u5883\u69FD\u6CA1\u6709\u952E\u2014\u2014adep env push --environment " + result.environment + " \u63A8\u9001\uFF09"] : result.vars.map((v) => ` ${v.key}=${v.value}${v.isSecret ? "\uFF08secret\uFF09" : ""}`)
|
|
41230
|
+
]);
|
|
41231
|
+
});
|
|
41232
|
+
});
|
|
40771
41233
|
}
|
|
40772
41234
|
async function readFileText(path) {
|
|
40773
|
-
return
|
|
41235
|
+
return readFile31(path, "utf8").catch(() => "");
|
|
40774
41236
|
}
|
|
40775
41237
|
function findEnvLine(content, key) {
|
|
40776
41238
|
for (const line of content.split(/\r?\n/)) {
|