@adep/cli 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -5
- package/dist/index.js +1030 -190
- package/dist/vite.js +285 -29
- package/package.json +12 -13
package/dist/index.js
CHANGED
|
@@ -3123,6 +3123,14 @@ var init_kv = __esm({
|
|
|
3123
3123
|
});
|
|
3124
3124
|
|
|
3125
3125
|
// packages/runtime/src/storage/driver.ts
|
|
3126
|
+
function assertFileVisibility(value) {
|
|
3127
|
+
if (value === "public" || value === "private") return value;
|
|
3128
|
+
throw new StorageError(
|
|
3129
|
+
400,
|
|
3130
|
+
STORAGE_CODES.invalidVisibility,
|
|
3131
|
+
`\u975E\u6CD5\u7684\u6587\u4EF6\u53EF\u89C1\u6027 ${JSON.stringify(value)}\uFF08\u53EA\u652F\u6301 'public' / 'private'\uFF09`
|
|
3132
|
+
);
|
|
3133
|
+
}
|
|
3126
3134
|
function assertSafeStoragePath(path) {
|
|
3127
3135
|
if (typeof path !== "string" || path.length === 0) {
|
|
3128
3136
|
throw new StorageError(400, STORAGE_CODES.invalidPath, "\u5B58\u50A8\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A");
|
|
@@ -3183,6 +3191,9 @@ var init_driver = __esm({
|
|
|
3183
3191
|
STORAGE_CODES = {
|
|
3184
3192
|
invalidPath: "STORAGE_INVALID_PATH",
|
|
3185
3193
|
invalidData: "STORAGE_INVALID_DATA",
|
|
3194
|
+
invalidVisibility: "STORAGE_INVALID_VISIBILITY",
|
|
3195
|
+
invalidSignedUrlTtl: "STORAGE_SIGNED_URL_TTL_INVALID",
|
|
3196
|
+
signedUrlTtlExceeded: "STORAGE_SIGNED_URL_TTL_EXCEEDED",
|
|
3186
3197
|
notFound: "STORAGE_NOT_FOUND",
|
|
3187
3198
|
quotaExceeded: "STORAGE_QUOTA_EXCEEDED"
|
|
3188
3199
|
};
|
|
@@ -3366,15 +3377,43 @@ var init_hmac_sha256 = __esm({
|
|
|
3366
3377
|
});
|
|
3367
3378
|
|
|
3368
3379
|
// packages/runtime/src/storage/signature.ts
|
|
3380
|
+
function resolveSignedUrlTtl(ttlSeconds, options) {
|
|
3381
|
+
if (ttlSeconds === void 0) return DEFAULT_SIGN_TTL_SECONDS;
|
|
3382
|
+
if (!Number.isInteger(ttlSeconds) || ttlSeconds <= 0) {
|
|
3383
|
+
throw new StorageError(
|
|
3384
|
+
400,
|
|
3385
|
+
STORAGE_CODES.invalidSignedUrlTtl,
|
|
3386
|
+
`\u7B7E\u540D\u6709\u6548\u671F\u5FC5\u987B\u662F\u6B63\u6574\u6570\u79D2\uFF08\u6536\u5230 ${ttlSeconds}\uFF09`
|
|
3387
|
+
);
|
|
3388
|
+
}
|
|
3389
|
+
if (ttlSeconds > MAX_SIGNED_URL_TTL_SECONDS && options?.force !== true) {
|
|
3390
|
+
throw new StorageError(
|
|
3391
|
+
400,
|
|
3392
|
+
STORAGE_CODES.signedUrlTtlExceeded,
|
|
3393
|
+
`\u7B7E\u540D URL \u6709\u6548\u671F\u6700\u957F ${MAX_SIGNED_URL_TTL_SECONDS / 86400} \u5929\uFF08\u6536\u5230 ${ttlSeconds} \u79D2\uFF09\u3002\u9700\u8981\u957F\u671F\u7A33\u5B9A\u7684\u94FE\u63A5\u8BF7\u628A\u6587\u4EF6\u4E0A\u4F20\u4E3A visibility: 'public' \u5E76\u7528 getUrl() \u53D6\u76F4\u94FE\uFF1B\u786E\u9700\u8D85\u957F\u79C1\u6709\u94FE\u63A5\u8BF7\u663E\u5F0F\u4F20 { force: true }\uFF08\u8FC7\u671F\u524D\u94FE\u63A5\u6CC4\u6F0F\u5373\u957F\u671F\u53EF\u8BFB\uFF09\u3002`
|
|
3394
|
+
);
|
|
3395
|
+
}
|
|
3396
|
+
return ttlSeconds;
|
|
3397
|
+
}
|
|
3369
3398
|
function sign(secret, projectId, path, expires) {
|
|
3370
3399
|
const payload = `${projectId}|${path}|${expires}`;
|
|
3371
3400
|
return hmacSha256Hex(secret, payload);
|
|
3372
3401
|
}
|
|
3373
|
-
function
|
|
3374
|
-
|
|
3375
|
-
|
|
3402
|
+
function publicDownloadUrl(config2, projectId, path) {
|
|
3403
|
+
return `${config2.baseUrl}/api/v1/projects/${encodeURIComponent(projectId)}/files/${encodeURIComponent(path)}`;
|
|
3404
|
+
}
|
|
3405
|
+
function signDownloadUrlWithExpiry(config2, projectId, path, ttlSeconds = DEFAULT_SIGN_TTL_SECONDS, options) {
|
|
3406
|
+
const ttl = resolveSignedUrlTtl(ttlSeconds, options);
|
|
3407
|
+
const expires = Math.floor(Date.now() / 1e3) + ttl;
|
|
3408
|
+
const base = publicDownloadUrl(config2, projectId, path);
|
|
3376
3409
|
const signature = sign(config2.secret, projectId, path, expires);
|
|
3377
|
-
return
|
|
3410
|
+
return {
|
|
3411
|
+
url: `${base}?${SIGN_EXPIRES_KEY}=${expires}&${SIGN_SIGNATURE_KEY}=${signature}`,
|
|
3412
|
+
expires
|
|
3413
|
+
};
|
|
3414
|
+
}
|
|
3415
|
+
function signDownloadUrl(config2, projectId, path, ttlSeconds = DEFAULT_SIGN_TTL_SECONDS, options) {
|
|
3416
|
+
return signDownloadUrlWithExpiry(config2, projectId, path, ttlSeconds, options).url;
|
|
3378
3417
|
}
|
|
3379
3418
|
function verifyDownloadSignature(config2, projectId, path, query, nowSeconds2 = Math.floor(Date.now() / 1e3)) {
|
|
3380
3419
|
const expiresRaw = query.expires;
|
|
@@ -3392,12 +3431,14 @@ function verifyDownloadSignature(config2, projectId, path, query, nowSeconds2 =
|
|
|
3392
3431
|
}
|
|
3393
3432
|
return { ok: true };
|
|
3394
3433
|
}
|
|
3395
|
-
var DEFAULT_SIGN_TTL_SECONDS, SIGN_EXPIRES_KEY, SIGN_SIGNATURE_KEY;
|
|
3434
|
+
var DEFAULT_SIGN_TTL_SECONDS, MAX_SIGNED_URL_TTL_SECONDS, SIGN_EXPIRES_KEY, SIGN_SIGNATURE_KEY;
|
|
3396
3435
|
var init_signature = __esm({
|
|
3397
3436
|
"packages/runtime/src/storage/signature.ts"() {
|
|
3398
3437
|
"use strict";
|
|
3399
3438
|
init_hmac_sha256();
|
|
3439
|
+
init_driver();
|
|
3400
3440
|
DEFAULT_SIGN_TTL_SECONDS = 15 * 60;
|
|
3441
|
+
MAX_SIGNED_URL_TTL_SECONDS = 7 * 24 * 60 * 60;
|
|
3401
3442
|
SIGN_EXPIRES_KEY = "x-expires";
|
|
3402
3443
|
SIGN_SIGNATURE_KEY = "x-signature";
|
|
3403
3444
|
}
|
|
@@ -3448,9 +3489,10 @@ function createStorageCapability(driver, signer, projectId) {
|
|
|
3448
3489
|
switch (method) {
|
|
3449
3490
|
case "upload": {
|
|
3450
3491
|
const [path, data, options] = args;
|
|
3492
|
+
const visibility = assertFileVisibility(options?.visibility ?? DEFAULT_VISIBILITY);
|
|
3451
3493
|
return toStoredFile(
|
|
3452
3494
|
await driver.put(projectId, path, asBytes(data), {
|
|
3453
|
-
visibility
|
|
3495
|
+
visibility,
|
|
3454
3496
|
...options?.contentType === void 0 ? {} : { contentType: options.contentType }
|
|
3455
3497
|
})
|
|
3456
3498
|
);
|
|
@@ -3468,9 +3510,26 @@ function createStorageCapability(driver, signer, projectId) {
|
|
|
3468
3510
|
const [prefix] = args;
|
|
3469
3511
|
return (await driver.list(projectId, prefix)).map(toStoredFile);
|
|
3470
3512
|
}
|
|
3513
|
+
case "getUrl": {
|
|
3514
|
+
const [path] = args;
|
|
3515
|
+
const meta3 = await driver.getMeta(projectId, path);
|
|
3516
|
+
if (meta3.visibility === "public") {
|
|
3517
|
+
const result2 = {
|
|
3518
|
+
url: publicDownloadUrl(signer, projectId, path),
|
|
3519
|
+
expiresAt: null
|
|
3520
|
+
};
|
|
3521
|
+
return result2;
|
|
3522
|
+
}
|
|
3523
|
+
const signed = signDownloadUrlWithExpiry(signer, projectId, path);
|
|
3524
|
+
const result = {
|
|
3525
|
+
url: signed.url,
|
|
3526
|
+
expiresAt: new Date(signed.expires * 1e3).toISOString()
|
|
3527
|
+
};
|
|
3528
|
+
return result;
|
|
3529
|
+
}
|
|
3471
3530
|
case "getSignedUrl": {
|
|
3472
|
-
const [path, ttlSeconds] = args;
|
|
3473
|
-
return signDownloadUrl(signer, projectId, path, ttlSeconds);
|
|
3531
|
+
const [path, ttlSeconds, options] = args;
|
|
3532
|
+
return signDownloadUrl(signer, projectId, path, ttlSeconds, options);
|
|
3474
3533
|
}
|
|
3475
3534
|
default:
|
|
3476
3535
|
throw new StorageError(
|
|
@@ -4011,6 +4070,16 @@ function unquoteIdent(raw) {
|
|
|
4011
4070
|
}
|
|
4012
4071
|
return text;
|
|
4013
4072
|
}
|
|
4073
|
+
function parsePlainIdent(raw) {
|
|
4074
|
+
const text = raw.trim();
|
|
4075
|
+
if (text.length === 0) return null;
|
|
4076
|
+
const first = text[0];
|
|
4077
|
+
if (first === '"' || first === "`" || first === "[" || first === "'") {
|
|
4078
|
+
const unquoted = unquoteIdent(text);
|
|
4079
|
+
return unquoted === text.trim() ? null : unquoted;
|
|
4080
|
+
}
|
|
4081
|
+
return /^[A-Za-z_][A-Za-z0-9_$]*$/.test(text) ? text : null;
|
|
4082
|
+
}
|
|
4014
4083
|
function splitTopLevel2(body) {
|
|
4015
4084
|
const parts = [];
|
|
4016
4085
|
let depth = 0;
|
|
@@ -4089,19 +4158,47 @@ function parseColumn(part) {
|
|
|
4089
4158
|
}
|
|
4090
4159
|
const type = rest.slice(0, typeEnd).trim();
|
|
4091
4160
|
rest = rest.slice(typeEnd).trim();
|
|
4092
|
-
const notNull = /\bNOT\s+NULL\b/i.test(rest);
|
|
4093
|
-
const primaryKey = /\bPRIMARY\s+KEY\b/i.test(rest);
|
|
4094
4161
|
const defaultMatch = /\bDEFAULT\s+(.+?)(?=\s+(?:NOT|PRIMARY|UNIQUE|CHECK|REFERENCES|COLLATE|GENERATED|AS|AUTOINCREMENT|CONSTRAINT)\b|$)/i.exec(
|
|
4095
4162
|
rest
|
|
4096
4163
|
);
|
|
4164
|
+
const constraintText = defaultMatch === null ? rest : rest.replace(defaultMatch[0], " ");
|
|
4165
|
+
const declarationText = stripNonNullabilityClauses(constraintText);
|
|
4166
|
+
const notNull = /\bNOT\s+NULL\b/i.test(declarationText);
|
|
4167
|
+
const explicitNullable = !notNull && /\bNULL\b/i.test(declarationText);
|
|
4168
|
+
const primaryKey = /\bPRIMARY\s+KEY\b/i.test(declarationText);
|
|
4169
|
+
const unique = /\bUNIQUE\b/i.test(declarationText);
|
|
4097
4170
|
return {
|
|
4098
4171
|
name,
|
|
4099
4172
|
type,
|
|
4100
4173
|
notNull,
|
|
4174
|
+
explicitNullable,
|
|
4101
4175
|
primaryKey,
|
|
4176
|
+
unique,
|
|
4102
4177
|
defaultValue: defaultMatch === null ? null : defaultMatch[1].trim()
|
|
4103
4178
|
};
|
|
4104
4179
|
}
|
|
4180
|
+
function stripNonNullabilityClauses(text) {
|
|
4181
|
+
return text.replace(
|
|
4182
|
+
/\bREFERENCES\s+\S+(?:\s*\([^)]*\))?(?:\s+ON\s+(?:DELETE|UPDATE)\s+(?:CASCADE|RESTRICT|SET\s+NULL|SET\s+DEFAULT|NO\s+ACTION))*/gi,
|
|
4183
|
+
" "
|
|
4184
|
+
).replace(/\bCHECK\s*\([^)]*\)/gi, " ").replace(/\bGENERATED\s+ALWAYS\s+AS\s*\([^)]*\)(?:\s+STORED|\s+VIRTUAL)?/gi, " ");
|
|
4185
|
+
}
|
|
4186
|
+
function parseTableUnique(part) {
|
|
4187
|
+
const trimmed = part.trim();
|
|
4188
|
+
const match = /^(?:CONSTRAINT\s+(?:"(?:[^"]|"")*"|`(?:[^`]|``)*`|\[[^\]]*\]|[A-Za-z_][A-Za-z0-9_$]*)\s+)?UNIQUE\s*\(/i.exec(
|
|
4189
|
+
trimmed
|
|
4190
|
+
);
|
|
4191
|
+
if (match === null) return null;
|
|
4192
|
+
const body = findTableBody(trimmed, match[0].lastIndexOf("("));
|
|
4193
|
+
if (body === null) return null;
|
|
4194
|
+
const columns = [];
|
|
4195
|
+
for (const entry of splitTopLevel2(body)) {
|
|
4196
|
+
const column = parsePlainIdent(entry);
|
|
4197
|
+
if (column === null) return null;
|
|
4198
|
+
columns.push(column);
|
|
4199
|
+
}
|
|
4200
|
+
return columns.length === 0 ? null : columns;
|
|
4201
|
+
}
|
|
4105
4202
|
function parseSchemaTables(sql) {
|
|
4106
4203
|
const tables = [];
|
|
4107
4204
|
const pattern = /CREATE\s+(?:TEMP|TEMPORARY\s+)?TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?("(?:[^"]|"")*"|`(?:[^`]|``)*`|\[[^\]]*\]|'[^']*'|[A-Za-z_][A-Za-z0-9_$.]*)\s*\(/gi;
|
|
@@ -4115,11 +4212,14 @@ function parseSchemaTables(sql) {
|
|
|
4115
4212
|
const rawName = match[1];
|
|
4116
4213
|
const name = unquoteIdent(rawName.split(".").pop() ?? rawName);
|
|
4117
4214
|
const columns = [];
|
|
4215
|
+
const uniqueConstraints = [];
|
|
4118
4216
|
for (const part of splitTopLevel2(body)) {
|
|
4217
|
+
const unique = parseTableUnique(part);
|
|
4218
|
+
if (unique !== null) uniqueConstraints.push(unique);
|
|
4119
4219
|
const column = parseColumn(part);
|
|
4120
4220
|
if (column !== null) columns.push(column);
|
|
4121
4221
|
}
|
|
4122
|
-
tables.push({ name, columns, statement: statement.trim() });
|
|
4222
|
+
tables.push({ name, columns, uniqueConstraints, statement: statement.trim() });
|
|
4123
4223
|
}
|
|
4124
4224
|
return tables;
|
|
4125
4225
|
}
|
|
@@ -4412,7 +4512,28 @@ async function dbExecBatch(paths, options) {
|
|
|
4412
4512
|
"SQL_EXEC_FAILED"
|
|
4413
4513
|
);
|
|
4414
4514
|
}
|
|
4515
|
+
function assertProductionMigrateConfirm(project2, files, confirmDb) {
|
|
4516
|
+
const fileArgs = files.join(" ");
|
|
4517
|
+
const runExample = `adep db migrate ${fileArgs} --confirm-db ${project2}`;
|
|
4518
|
+
if (confirmDb === void 0 || confirmDb.trim() === "") {
|
|
4519
|
+
throw new CliError(
|
|
4520
|
+
"MIGRATE_CONFIRM_REQUIRED",
|
|
4521
|
+
`\u751F\u4EA7\u5E93\u8FC1\u79FB\u9700\u8981\u4E8C\u6B21\u786E\u8BA4\uFF1A\u547D\u4EE4\u4F1A\u4F5C\u7528\u5230\u9879\u76EE\u300C${project2}\u300D\u7684\u751F\u4EA7\u5E93\u3002\u5148\u770B\u8BA1\u5212\uFF1Aadep db migrate ${fileArgs} --plan\uFF1B\u786E\u8BA4\u540E\u6267\u884C\uFF1A${runExample}`
|
|
4522
|
+
);
|
|
4523
|
+
}
|
|
4524
|
+
if (confirmDb.trim() !== project2) {
|
|
4525
|
+
throw new CliError(
|
|
4526
|
+
"MIGRATE_CONFIRM_MISMATCH",
|
|
4527
|
+
`--confirm-db \u7684\u503C\u300C${confirmDb}\u300D\u4E0E\u76EE\u6807\u9879\u76EE slug\u300C${project2}\u300D\u4E0D\u4E00\u81F4\u3002\u786E\u8BA4\u503C\u5FC5\u987B\u4E0E\u76EE\u6807\u9879\u76EE slug \u5B8C\u5168\u4E00\u81F4\uFF08\u533A\u5206\u5927\u5C0F\u5199\uFF09\uFF1A${runExample}`
|
|
4528
|
+
);
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4415
4531
|
async function dbMigrate(paths, options) {
|
|
4532
|
+
const environment = options.environment ?? "prod";
|
|
4533
|
+
const project2 = await resolveSlug(resolve3(options.cwd), options.slug);
|
|
4534
|
+
if (options.plan !== true && environment === "prod") {
|
|
4535
|
+
assertProductionMigrateConfirm(project2, options.files, options.confirmDb);
|
|
4536
|
+
}
|
|
4416
4537
|
const queue = [];
|
|
4417
4538
|
for (const file2 of options.files) {
|
|
4418
4539
|
const source = await readFile4(resolve3(file2), "utf8");
|
|
@@ -4422,7 +4543,7 @@ async function dbMigrate(paths, options) {
|
|
|
4422
4543
|
}
|
|
4423
4544
|
queue.push({ file: file2, sql: source });
|
|
4424
4545
|
}
|
|
4425
|
-
|
|
4546
|
+
await open2(paths, { cwd: options.cwd, slug: project2 });
|
|
4426
4547
|
const applied = [];
|
|
4427
4548
|
const changes = [];
|
|
4428
4549
|
let createdTables = 0;
|
|
@@ -4440,10 +4561,15 @@ async function dbMigrate(paths, options) {
|
|
|
4440
4561
|
missingTables: [...drift.missingTables, ...next.missingTables],
|
|
4441
4562
|
missingColumns: [...drift.missingColumns, ...next.missingColumns],
|
|
4442
4563
|
typeMismatches: [...drift.typeMismatches, ...next.typeMismatches],
|
|
4564
|
+
// 兼容旧服务端响应(缺字段按空处理):CLI 与平台版本允许滚动差。
|
|
4565
|
+
missingIndexes: [...drift.missingIndexes ?? [], ...next.missingIndexes ?? []],
|
|
4566
|
+
uniqueDiff: [...drift.uniqueDiff ?? [], ...next.uniqueDiff ?? []],
|
|
4567
|
+
defaultDiff: [...drift.defaultDiff ?? [], ...next.defaultDiff ?? []],
|
|
4568
|
+
nullabilityDiff: [...drift.nullabilityDiff ?? [], ...next.nullabilityDiff ?? []],
|
|
4569
|
+
blocking: drift.blocking === void 0 && next.blocking === void 0 ? void 0 : (drift.blocking ?? false) || (next.blocking ?? false),
|
|
4443
4570
|
extraTables: [.../* @__PURE__ */ new Set([...drift.extraTables, ...next.extraTables])],
|
|
4444
4571
|
extraColumns: [...drift.extraColumns, ...next.extraColumns],
|
|
4445
4572
|
destructiveStatements: [...drift.destructiveStatements, ...next.destructiveStatements],
|
|
4446
|
-
// 兼容旧服务端响应(缺字段按空处理):CLI 与平台版本允许滚动差。
|
|
4447
4573
|
dataStatements: [...drift.dataStatements ?? [], ...next.dataStatements ?? []],
|
|
4448
4574
|
applicable: drift.applicable && next.applicable
|
|
4449
4575
|
};
|
|
@@ -4454,8 +4580,8 @@ async function dbMigrate(paths, options) {
|
|
|
4454
4580
|
const next = await dbSchemaDiff(paths, {
|
|
4455
4581
|
cwd: options.cwd,
|
|
4456
4582
|
sql,
|
|
4457
|
-
|
|
4458
|
-
|
|
4583
|
+
slug: project2,
|
|
4584
|
+
environment
|
|
4459
4585
|
});
|
|
4460
4586
|
mergeDrift(next);
|
|
4461
4587
|
} catch (error62) {
|
|
@@ -4482,12 +4608,21 @@ async function dbMigrate(paths, options) {
|
|
|
4482
4608
|
}
|
|
4483
4609
|
for (const { file: file2, sql } of queue) {
|
|
4484
4610
|
try {
|
|
4611
|
+
if (environment === "prod" && options.onPlan !== void 0) {
|
|
4612
|
+
const planned = await dbSchemaDiff(paths, {
|
|
4613
|
+
cwd: options.cwd,
|
|
4614
|
+
sql,
|
|
4615
|
+
slug: project2,
|
|
4616
|
+
environment
|
|
4617
|
+
});
|
|
4618
|
+
options.onPlan(planned, file2);
|
|
4619
|
+
}
|
|
4485
4620
|
const result = await dbSchemaMigrate(paths, {
|
|
4486
4621
|
cwd: options.cwd,
|
|
4487
4622
|
sql,
|
|
4488
|
-
|
|
4623
|
+
slug: project2,
|
|
4489
4624
|
// 环境必须一路透传:漏掉这一步,`--env dev` 的迁移会落到生产库。
|
|
4490
|
-
|
|
4625
|
+
environment
|
|
4491
4626
|
});
|
|
4492
4627
|
applied.push(...result.applied);
|
|
4493
4628
|
changes.push(...result.applied.map(() => 0));
|
|
@@ -4940,6 +5075,21 @@ function buildExhaustedMessage(input2) {
|
|
|
4940
5075
|
"\u53EF\u80FD\u539F\u56E0\uFF1A\u7CFB\u7EDF\u4E34\u65F6\u7AEF\u53E3\u8D77\u59CB\u503C\u88AB\u8C03\u4F4E\uFF08Windows \u7528 netsh int ipv4 show dynamicport tcp \u6838\u5BF9\uFF0CHyper-V / \u5BB9\u5668\u7F51\u7EDC\u4F1A\u6539\u5B83\uFF09\u3002\u53EF\u7528 --port \u6307\u5B9A\u4E00\u4E2A\u672A\u5360\u7528\u7684\u7AEF\u53E3\u7ED5\u8FC7\u3002"
|
|
4941
5076
|
].join("\n");
|
|
4942
5077
|
}
|
|
5078
|
+
function isAddrInUseCode(error62) {
|
|
5079
|
+
return error62?.code === "EADDRINUSE";
|
|
5080
|
+
}
|
|
5081
|
+
function formatFallbackNotice(info) {
|
|
5082
|
+
return `[adep] \u7AEF\u53E3 ${info.requested} \u5DF2\u88AB\u5360\u7528\uFF0C\u5DF2\u6539\u7528 ${info.actual}\uFF08\u7F3A\u7701\u7AEF\u53E3\u81EA\u52A8\u987A\u5EF6\uFF1B\u663E\u5F0F\u6307\u5B9A\u7684\u7AEF\u53E3\u4E0D\u6362\u53F7\uFF09`;
|
|
5083
|
+
}
|
|
5084
|
+
function buildFallbackExhaustedMessage(input2) {
|
|
5085
|
+
const first = input2.requested + 1;
|
|
5086
|
+
const last = input2.requested + input2.span;
|
|
5087
|
+
return [
|
|
5088
|
+
`[adep] \u7AEF\u53E3 ${input2.requested} \u5DF2\u88AB\u5360\u7528\uFF0C\u5176\u540E ${input2.span} \u4E2A\u5019\u9009\u7AEF\u53E3\uFF08${first}~${last}\uFF09\u4E5F\u4E0D\u53EF\u7528\uFF0C\u5DF2\u653E\u5F03\u542F\u52A8\u3002`,
|
|
5089
|
+
"\u7F3A\u7701\u7AEF\u53E3\u81EA\u52A8\u987A\u5EF6\u53EA\u8986\u76D6\u8FD9\u4E00\u5C0F\u6BB5\uFF1B\u8BF7\u7528 --port \u6307\u5B9A\u4E00\u4E2A\u7A7A\u95F2\u7AEF\u53E3\uFF08\u663E\u5F0F\u7AEF\u53E3\u4E0D\u4F1A\u81EA\u52A8\u6362\u53F7\uFF09\u3002",
|
|
5090
|
+
`\u5360\u7528\u8005\u6392\u67E5\uFF1Alsof -nP -iTCP:${input2.requested} -sTCP:LISTEN\uFF08Windows\uFF1Anetstat -ano | findstr :${input2.requested}\uFF09`
|
|
5091
|
+
].join("\n");
|
|
5092
|
+
}
|
|
4943
5093
|
async function listenOnFetchSafePort(server, options) {
|
|
4944
5094
|
const isBlocked = options.isBlocked ?? isFetchBlockedPort;
|
|
4945
5095
|
const warn = options.warn ?? (() => {
|
|
@@ -4950,12 +5100,46 @@ async function listenOnFetchSafePort(server, options) {
|
|
|
4950
5100
|
} catch {
|
|
4951
5101
|
}
|
|
4952
5102
|
};
|
|
4953
|
-
|
|
5103
|
+
const requestedPort = options.port;
|
|
5104
|
+
if (requestedPort !== 0) {
|
|
4954
5105
|
try {
|
|
4955
|
-
await listenOnce(server,
|
|
5106
|
+
await listenOnce(server, requestedPort, options.host);
|
|
4956
5107
|
} catch (error62) {
|
|
4957
|
-
|
|
4958
|
-
|
|
5108
|
+
const fallback = options.fallbackOnInUse;
|
|
5109
|
+
if (fallback === void 0 || !isAddrInUseCode(error62)) {
|
|
5110
|
+
await notifyListenError(error62);
|
|
5111
|
+
throw error62;
|
|
5112
|
+
}
|
|
5113
|
+
const span = fallback.span ?? DEFAULT_PORT_FALLBACK_SPAN;
|
|
5114
|
+
if (!Number.isInteger(span) || span < 1) {
|
|
5115
|
+
await notifyListenError(error62);
|
|
5116
|
+
throw new Error(`[adep] fallbackOnInUse.span \u5FC5\u987B\u662F\u6B63\u6574\u6570\uFF08\u6536\u5230 ${String(span)}\uFF09\u3002`, {
|
|
5117
|
+
cause: error62
|
|
5118
|
+
});
|
|
5119
|
+
}
|
|
5120
|
+
let lastError = error62;
|
|
5121
|
+
for (let offset = 1; offset <= span; offset += 1) {
|
|
5122
|
+
const candidate = requestedPort + offset;
|
|
5123
|
+
if (candidate > 65535) break;
|
|
5124
|
+
if (isBlocked(candidate)) continue;
|
|
5125
|
+
try {
|
|
5126
|
+
await listenOnce(server, candidate, options.host);
|
|
5127
|
+
} catch (candidateError) {
|
|
5128
|
+
if (isAddrInUseCode(candidateError)) {
|
|
5129
|
+
lastError = candidateError;
|
|
5130
|
+
continue;
|
|
5131
|
+
}
|
|
5132
|
+
await notifyListenError(candidateError);
|
|
5133
|
+
throw candidateError;
|
|
5134
|
+
}
|
|
5135
|
+
const report = options.onFallback ?? ((info) => warn(formatFallbackNotice(info)));
|
|
5136
|
+
report({ requested: requestedPort, actual: candidate });
|
|
5137
|
+
return candidate;
|
|
5138
|
+
}
|
|
5139
|
+
await notifyListenError(lastError);
|
|
5140
|
+
throw new PortFallbackExhaustedError(
|
|
5141
|
+
buildFallbackExhaustedMessage({ requested: requestedPort, span })
|
|
5142
|
+
);
|
|
4959
5143
|
}
|
|
4960
5144
|
const actual = readTcpPort(server, options.host);
|
|
4961
5145
|
if (isBlocked(actual)) {
|
|
@@ -4987,12 +5171,89 @@ async function listenOnFetchSafePort(server, options) {
|
|
|
4987
5171
|
}
|
|
4988
5172
|
throw new Error(buildExhaustedMessage({ host: options.host, hits, maxAttempts }));
|
|
4989
5173
|
}
|
|
4990
|
-
var MAX_FETCH_SAFE_LISTEN_ATTEMPTS;
|
|
5174
|
+
var MAX_FETCH_SAFE_LISTEN_ATTEMPTS, DEFAULT_PORT_FALLBACK_SPAN, PortFallbackExhaustedError;
|
|
4991
5175
|
var init_fetch_safe_port = __esm({
|
|
4992
5176
|
"packages/cli/src/serve/fetch-safe-port.ts"() {
|
|
4993
5177
|
"use strict";
|
|
4994
5178
|
init_fetch_blocked_ports();
|
|
4995
5179
|
MAX_FETCH_SAFE_LISTEN_ATTEMPTS = 8;
|
|
5180
|
+
DEFAULT_PORT_FALLBACK_SPAN = 12;
|
|
5181
|
+
PortFallbackExhaustedError = class extends Error {
|
|
5182
|
+
constructor(message) {
|
|
5183
|
+
super(message);
|
|
5184
|
+
this.name = "PortFallbackExhaustedError";
|
|
5185
|
+
}
|
|
5186
|
+
};
|
|
5187
|
+
}
|
|
5188
|
+
});
|
|
5189
|
+
|
|
5190
|
+
// packages/cli/src/serve/port-in-use.ts
|
|
5191
|
+
import { execFile } from "node:child_process";
|
|
5192
|
+
function parsePortOccupier(stdout) {
|
|
5193
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
5194
|
+
const trimmed = line.trim();
|
|
5195
|
+
if (trimmed.length === 0 || trimmed.startsWith("COMMAND")) continue;
|
|
5196
|
+
const [command, pid] = trimmed.split(/\s+/);
|
|
5197
|
+
if (command === void 0 || pid === void 0 || !/^\d+$/u.test(pid)) return null;
|
|
5198
|
+
return `${command} ${pid}`;
|
|
5199
|
+
}
|
|
5200
|
+
return null;
|
|
5201
|
+
}
|
|
5202
|
+
function runLsof(port) {
|
|
5203
|
+
return new Promise((resolve22, reject) => {
|
|
5204
|
+
execFile(
|
|
5205
|
+
"lsof",
|
|
5206
|
+
["-nP", `-iTCP:${port}`, "-sTCP:LISTEN"],
|
|
5207
|
+
{ timeout: 2e3, windowsHide: true },
|
|
5208
|
+
(error62, stdout) => {
|
|
5209
|
+
if (error62 !== null) {
|
|
5210
|
+
reject(error62);
|
|
5211
|
+
return;
|
|
5212
|
+
}
|
|
5213
|
+
resolve22(stdout);
|
|
5214
|
+
}
|
|
5215
|
+
);
|
|
5216
|
+
});
|
|
5217
|
+
}
|
|
5218
|
+
async function lookupPortOccupier(port, options = {}) {
|
|
5219
|
+
if (process.platform === "win32") return null;
|
|
5220
|
+
const execute = options.execute ?? runLsof;
|
|
5221
|
+
try {
|
|
5222
|
+
return parsePortOccupier(await execute(port));
|
|
5223
|
+
} catch {
|
|
5224
|
+
return null;
|
|
5225
|
+
}
|
|
5226
|
+
}
|
|
5227
|
+
async function describePortInUse(options) {
|
|
5228
|
+
const occupier = await (options.lookup ?? lookupPortOccupier)(options.port);
|
|
5229
|
+
const nextPort = options.port < 65535 ? options.port + 1 : options.port - 1;
|
|
5230
|
+
const command = `adep ${options.scope}`;
|
|
5231
|
+
return [
|
|
5232
|
+
`[adep] \u7AEF\u53E3 ${options.port} \u5DF2\u88AB\u5360\u7528\uFF08EADDRINUSE\uFF09\uFF1B\u8BE5\u7AEF\u53E3\u662F\u663E\u5F0F\u6307\u5B9A\u7684\uFF08--port / PORT\uFF09\uFF0C\u4E0D\u4F1A\u81EA\u52A8\u6539\u7528\u5176\u5B83\u7AEF\u53E3\u3002`,
|
|
5233
|
+
occupier === null ? `\u5360\u7528\u8005\uFF1A\u65E0\u6CD5\u5B9A\u4F4D\u3002\u624B\u52A8\u68C0\u67E5\uFF1Alsof -nP -iTCP:${options.port} -sTCP:LISTEN\uFF08Windows\uFF1Anetstat -ano | findstr :${options.port}\uFF09` : `\u5360\u7528\u8005\uFF1A${occupier}\uFF08\u590D\u6838\u547D\u4EE4\uFF1Alsof -nP -iTCP:${options.port} -sTCP:LISTEN\uFF09`,
|
|
5234
|
+
`\u5904\u7F6E\uFF1A\u6539\u7528\u5176\u5B83\u7AEF\u53E3\uFF08${command} --port ${nextPort}\uFF09\uFF0C\u6216\u5148\u505C\u6B62\u5360\u7528\u8BE5\u7AEF\u53E3\u7684\u8FDB\u7A0B\u3002`
|
|
5235
|
+
].join("\n");
|
|
5236
|
+
}
|
|
5237
|
+
function isAddrInUse(error62) {
|
|
5238
|
+
return error62?.code === "EADDRINUSE";
|
|
5239
|
+
}
|
|
5240
|
+
async function toPortCliError(error62, context) {
|
|
5241
|
+
if (isAddrInUse(error62)) {
|
|
5242
|
+
return new CliError(
|
|
5243
|
+
"PORT_IN_USE",
|
|
5244
|
+
await describePortInUse({ port: context.port, scope: context.scope })
|
|
5245
|
+
);
|
|
5246
|
+
}
|
|
5247
|
+
if (error62 instanceof PortFallbackExhaustedError) {
|
|
5248
|
+
return new CliError("PORT_FALLBACK_EXHAUSTED", error62.message);
|
|
5249
|
+
}
|
|
5250
|
+
return null;
|
|
5251
|
+
}
|
|
5252
|
+
var init_port_in_use = __esm({
|
|
5253
|
+
"packages/cli/src/serve/port-in-use.ts"() {
|
|
5254
|
+
"use strict";
|
|
5255
|
+
init_auth();
|
|
5256
|
+
init_fetch_safe_port();
|
|
4996
5257
|
}
|
|
4997
5258
|
});
|
|
4998
5259
|
|
|
@@ -7550,13 +7811,22 @@ async function startDevServer(options) {
|
|
|
7550
7811
|
} catch {
|
|
7551
7812
|
}
|
|
7552
7813
|
};
|
|
7553
|
-
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
|
|
7557
|
-
|
|
7558
|
-
|
|
7814
|
+
let actualPort;
|
|
7815
|
+
try {
|
|
7816
|
+
actualPort = await listenOnFetchSafePort(server, {
|
|
7817
|
+
port,
|
|
7818
|
+
host: "127.0.0.1",
|
|
7819
|
+
warn: log,
|
|
7820
|
+
...options.port === void 0 ? { fallbackOnInUse: {} } : {},
|
|
7821
|
+
onListenError: disposeAfterListenError
|
|
7822
|
+
});
|
|
7823
|
+
} catch (error62) {
|
|
7824
|
+
const portError = await toPortCliError(error62, { port, scope: "dev" });
|
|
7825
|
+
if (portError !== null) throw portError;
|
|
7826
|
+
throw error62;
|
|
7827
|
+
}
|
|
7559
7828
|
const baseUrl = `http://127.0.0.1:${actualPort}`;
|
|
7829
|
+
runtime.storage.signer.baseUrl = baseUrl;
|
|
7560
7830
|
const coldStartMs = Date.now() - coldStartAt;
|
|
7561
7831
|
const curlPath = config2.functionsPrefix.length === 0 ? "/hello" : `/${config2.functionsPrefix}/hello`;
|
|
7562
7832
|
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";
|
|
@@ -7596,6 +7866,7 @@ var init_dev = __esm({
|
|
|
7596
7866
|
init_runtime();
|
|
7597
7867
|
init_db_mode();
|
|
7598
7868
|
init_fetch_safe_port();
|
|
7869
|
+
init_port_in_use();
|
|
7599
7870
|
init_env();
|
|
7600
7871
|
init_fetch_config();
|
|
7601
7872
|
init_invoke();
|
|
@@ -8472,6 +8743,7 @@ async function startServeServer(options) {
|
|
|
8472
8743
|
`));
|
|
8473
8744
|
const host = options.host ?? envString("HOST") ?? "127.0.0.1";
|
|
8474
8745
|
const port = resolveServePort(options.port);
|
|
8746
|
+
const portFromBuiltinDefault = options.port === void 0 && envNumber("PORT") === void 0;
|
|
8475
8747
|
const publicUrl = resolvePublicUrl(
|
|
8476
8748
|
options.publicUrl !== void 0 ? options.publicUrl : envString("ADEP_PUBLIC_URL")
|
|
8477
8749
|
);
|
|
@@ -8829,7 +9101,31 @@ async function startServeServer(options) {
|
|
|
8829
9101
|
}
|
|
8830
9102
|
});
|
|
8831
9103
|
});
|
|
8832
|
-
const
|
|
9104
|
+
const disposeAfterListenError = async () => {
|
|
9105
|
+
stopWatch?.();
|
|
9106
|
+
try {
|
|
9107
|
+
await executor.dispose();
|
|
9108
|
+
} catch {
|
|
9109
|
+
}
|
|
9110
|
+
try {
|
|
9111
|
+
await runtime.dispose();
|
|
9112
|
+
} catch {
|
|
9113
|
+
}
|
|
9114
|
+
};
|
|
9115
|
+
let actualPort;
|
|
9116
|
+
try {
|
|
9117
|
+
actualPort = await listenOnFetchSafePort(server, {
|
|
9118
|
+
port,
|
|
9119
|
+
host,
|
|
9120
|
+
warn: log,
|
|
9121
|
+
...portFromBuiltinDefault ? { fallbackOnInUse: {} } : {},
|
|
9122
|
+
onListenError: disposeAfterListenError
|
|
9123
|
+
});
|
|
9124
|
+
} catch (error62) {
|
|
9125
|
+
const portError = await toPortCliError(error62, { port, scope: "serve" });
|
|
9126
|
+
if (portError !== null) throw portError;
|
|
9127
|
+
throw error62;
|
|
9128
|
+
}
|
|
8833
9129
|
runtime.storage.signer.baseUrl = publicUrl ?? `http://${host}:${actualPort}`;
|
|
8834
9130
|
const drift = schemaReport?.drift ?? null;
|
|
8835
9131
|
const schemaDrift = drift === null || drift.missing.length === 0 ? void 0 : drift.missing.map((plan) => {
|
|
@@ -8864,7 +9160,9 @@ async function startServeServer(options) {
|
|
|
8864
9160
|
});
|
|
8865
9161
|
log(banner);
|
|
8866
9162
|
if (options.parity === true) {
|
|
8867
|
-
log(
|
|
9163
|
+
log(
|
|
9164
|
+
"[serve] --parity \u4E25\u683C\u6A21\u5F0F\uFF1A\u6C99\u7BB1\u4E0D\u6CE8\u5165 process\uFF08env \u8D70 ctx.env\uFF09\u3001../ \u8D8A\u6839\u5F15\u7528\u62A5\u9519\u2014\u2014\u4E0E\u5E73\u53F0\u6C99\u7BB1\u540C\u5F62"
|
|
9165
|
+
);
|
|
8868
9166
|
}
|
|
8869
9167
|
if (templateEnv !== null) {
|
|
8870
9168
|
const currentKeys = Object.keys(templateEnv.values());
|
|
@@ -8912,6 +9210,7 @@ var init_server = __esm({
|
|
|
8912
9210
|
init_dev();
|
|
8913
9211
|
init_banner();
|
|
8914
9212
|
init_fetch_safe_port();
|
|
9213
|
+
init_port_in_use();
|
|
8915
9214
|
init_staleness();
|
|
8916
9215
|
init_template_params2();
|
|
8917
9216
|
init_adep_env_inject();
|
|
@@ -9369,11 +9668,15 @@ var init_deploy = __esm({
|
|
|
9369
9668
|
});
|
|
9370
9669
|
|
|
9371
9670
|
// shared/frontend-draft.ts
|
|
9372
|
-
|
|
9671
|
+
function hasFrontendEntry(files) {
|
|
9672
|
+
return Object.hasOwn(files, FRONTEND_DRAFT_ENTRY_PATH);
|
|
9673
|
+
}
|
|
9674
|
+
var FRONTEND_DRAFT_FILE_PATH_PATTERN, FRONTEND_DRAFT_ENTRY_PATH, FRONTEND_DRAFT_MAX_TOTAL_SOURCE_BYTES, FRONTEND_DRAFT_MAX_FILES, FRONTEND_TRANSFORM_EXTENSIONS;
|
|
9373
9675
|
var init_frontend_draft = __esm({
|
|
9374
9676
|
"shared/frontend-draft.ts"() {
|
|
9375
9677
|
"use strict";
|
|
9376
9678
|
FRONTEND_DRAFT_FILE_PATH_PATTERN = /^[a-zA-Z0-9._][a-zA-Z0-9._/-]*$/;
|
|
9679
|
+
FRONTEND_DRAFT_ENTRY_PATH = "web/index.html";
|
|
9377
9680
|
FRONTEND_DRAFT_MAX_TOTAL_SOURCE_BYTES = 512 * 1024;
|
|
9378
9681
|
FRONTEND_DRAFT_MAX_FILES = 100;
|
|
9379
9682
|
FRONTEND_TRANSFORM_EXTENSIONS = [
|
|
@@ -9396,8 +9699,10 @@ __export(frontend_exports, {
|
|
|
9396
9699
|
detectCanonicalFrontendLayout: () => detectCanonicalFrontendLayout,
|
|
9397
9700
|
frontendSync: () => frontendSync,
|
|
9398
9701
|
isStaticFrontendDir: () => isStaticFrontendDir,
|
|
9702
|
+
prepareFrontendDraft: () => prepareFrontendDraft,
|
|
9399
9703
|
readPackageDistDir: () => readPackageDistDir,
|
|
9400
|
-
resolveSiteOutputDir: () => resolveSiteOutputDir
|
|
9704
|
+
resolveSiteOutputDir: () => resolveSiteOutputDir,
|
|
9705
|
+
syncPreparedFrontend: () => syncPreparedFrontend
|
|
9401
9706
|
});
|
|
9402
9707
|
import { readdir as readdir10, readFile as readFile23, stat as stat13 } from "node:fs/promises";
|
|
9403
9708
|
import { join as join31, relative as relative6, resolve as resolve14, sep as sep2 } from "node:path";
|
|
@@ -9434,15 +9739,12 @@ async function collectFiles(root, dir) {
|
|
|
9434
9739
|
}
|
|
9435
9740
|
return { files, skipped };
|
|
9436
9741
|
}
|
|
9437
|
-
async function
|
|
9438
|
-
const log = options.silent === true ? () => void 0 : options.log ?? ((line) => process.stdout.write(`${line}
|
|
9439
|
-
`));
|
|
9440
|
-
const webDir = options.dir ?? join31(options.cwd, "web");
|
|
9742
|
+
async function prepareFrontendDraft(webDir) {
|
|
9441
9743
|
const rootStat = await stat13(webDir).catch(() => null);
|
|
9442
9744
|
if (rootStat === null || !rootStat.isDirectory()) {
|
|
9443
9745
|
throw new CliError(
|
|
9444
9746
|
"FRONTEND_DIR_MISSING",
|
|
9445
|
-
`\u672C\u5730\u524D\u7AEF\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${webDir}\
|
|
9747
|
+
`\u672C\u5730\u524D\u7AEF\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${webDir}\uFF08\u671F\u671B ${webDir}/ \u4E0B\u662F Vite \u5DE5\u7A0B\uFF09`
|
|
9446
9748
|
);
|
|
9447
9749
|
}
|
|
9448
9750
|
const { files, skipped } = await collectFiles(webDir, webDir);
|
|
@@ -9471,18 +9773,40 @@ async function frontendSync(paths, options) {
|
|
|
9471
9773
|
`\u6E90\u7801\u603B\u91CF ${totalBytes} \u5B57\u8282\u8D85\u8FC7\u4E0A\u9650\uFF08${MAX_TOTAL_SOURCE_BYTES2} \u5B57\u8282\uFF09`
|
|
9472
9774
|
);
|
|
9473
9775
|
}
|
|
9776
|
+
return { drafts, skipped, totalBytes };
|
|
9777
|
+
}
|
|
9778
|
+
async function syncPreparedFrontend(paths, options) {
|
|
9779
|
+
const log = options.silent === true ? () => void 0 : options.log ?? ((line) => process.stdout.write(`${line}
|
|
9780
|
+
`));
|
|
9781
|
+
const { prepared } = options;
|
|
9782
|
+
const uploaded = Object.keys(prepared.drafts).length;
|
|
9474
9783
|
const client = await createClient(paths);
|
|
9475
9784
|
const project2 = await resolveProjectId(client, options.cwd, options.slug);
|
|
9476
|
-
log(`[adep] \u540C\u6B65\u672C\u5730 web/ \u8349\u7A3F\u5230\u5E73\u53F0\uFF08\u9879\u76EE ${project2.slug}\uFF0C${
|
|
9785
|
+
log(`[adep] \u540C\u6B65\u672C\u5730 web/ \u8349\u7A3F\u5230\u5E73\u53F0\uFF08\u9879\u76EE ${project2.slug}\uFF0C${uploaded} \u4E2A\u6587\u4EF6\uFF09\u2026`);
|
|
9477
9786
|
await client.request(
|
|
9478
9787
|
`/api/v1/projects/${project2.id}/frontend/files`,
|
|
9479
|
-
{ method: "PUT", body: { files: drafts } },
|
|
9788
|
+
{ method: "PUT", body: { files: prepared.drafts } },
|
|
9480
9789
|
"FRONTEND_SYNC_FAILED"
|
|
9481
9790
|
);
|
|
9482
|
-
if (skipped.length > 0) {
|
|
9483
|
-
log(`[adep] \u8DF3\u8FC7\u975E\u6587\u672C\u6587\u4EF6\uFF08\u8349\u7A3F\u901A\u9053\u4E0D\u652F\u6301\u4E8C\u8FDB\u5236\uFF09\uFF1A${skipped.join(", ")}`);
|
|
9791
|
+
if (prepared.skipped.length > 0) {
|
|
9792
|
+
log(`[adep] \u8DF3\u8FC7\u975E\u6587\u672C\u6587\u4EF6\uFF08\u8349\u7A3F\u901A\u9053\u4E0D\u652F\u6301\u4E8C\u8FDB\u5236\uFF09\uFF1A${prepared.skipped.join(", ")}`);
|
|
9484
9793
|
}
|
|
9485
|
-
return {
|
|
9794
|
+
return {
|
|
9795
|
+
projectId: project2.id,
|
|
9796
|
+
uploaded,
|
|
9797
|
+
skipped: prepared.skipped,
|
|
9798
|
+
totalBytes: prepared.totalBytes
|
|
9799
|
+
};
|
|
9800
|
+
}
|
|
9801
|
+
async function frontendSync(paths, options) {
|
|
9802
|
+
const prepared = await prepareFrontendDraft(options.dir ?? join31(options.cwd, "web"));
|
|
9803
|
+
return syncPreparedFrontend(paths, {
|
|
9804
|
+
cwd: options.cwd,
|
|
9805
|
+
...options.slug === void 0 ? {} : { slug: options.slug },
|
|
9806
|
+
...options.silent === void 0 ? {} : { silent: options.silent },
|
|
9807
|
+
...options.log === void 0 ? {} : { log: options.log },
|
|
9808
|
+
prepared
|
|
9809
|
+
});
|
|
9486
9810
|
}
|
|
9487
9811
|
function declaresBuildScript(pkgJson) {
|
|
9488
9812
|
if (pkgJson === void 0) return false;
|
|
@@ -10526,18 +10850,90 @@ var init_version = __esm({
|
|
|
10526
10850
|
manifest = requireJson("../package.json");
|
|
10527
10851
|
CLI_VERSION = typeof manifest.version === "string" && manifest.version.length > 0 ? manifest.version : "0.0.0";
|
|
10528
10852
|
RELEASE_TASKS = Array.isArray(manifest.adep?.releaseTasks) ? manifest.adep.releaseTasks.filter((item) => typeof item === "string") : [];
|
|
10529
|
-
BUILD_COMMIT = "
|
|
10853
|
+
BUILD_COMMIT = "fd927236".trim() !== "" ? "fd927236".trim() : null;
|
|
10530
10854
|
}
|
|
10531
10855
|
});
|
|
10532
10856
|
|
|
10533
10857
|
// packages/cli/src/doctor.ts
|
|
10534
10858
|
var doctor_exports = {};
|
|
10535
10859
|
__export(doctor_exports, {
|
|
10860
|
+
detectSupplyChainPolicy: () => detectSupplyChainPolicy,
|
|
10536
10861
|
formatDoctorReport: () => formatDoctorReport,
|
|
10537
10862
|
runDoctor: () => runDoctor
|
|
10538
10863
|
});
|
|
10539
|
-
import { stat as stat18 } from "node:fs/promises";
|
|
10864
|
+
import { readFile as readFile32, stat as stat18 } from "node:fs/promises";
|
|
10865
|
+
import { homedir } from "node:os";
|
|
10540
10866
|
import { join as join39 } from "node:path";
|
|
10867
|
+
import { parse as parseYaml } from "yaml";
|
|
10868
|
+
function minimumReleaseAgeMinutes(raw) {
|
|
10869
|
+
const text = raw.trim();
|
|
10870
|
+
return /^\d+$/u.test(text) ? Number(text) : null;
|
|
10871
|
+
}
|
|
10872
|
+
function hitFromRaw(raw, source) {
|
|
10873
|
+
const minutes = minimumReleaseAgeMinutes(raw);
|
|
10874
|
+
return {
|
|
10875
|
+
minutes,
|
|
10876
|
+
raw,
|
|
10877
|
+
warning: minutes === null ? `minimumReleaseAge \u7684\u503C\u300C${raw}\u300D\u4E0D\u662F\u975E\u8D1F\u6574\u6570\uFF08\u5206\u949F\uFF09\uFF0Cpnpm \u4F1A\u62D2\u7EDD\u8BE5\u914D\u7F6E` : null,
|
|
10878
|
+
source
|
|
10879
|
+
};
|
|
10880
|
+
}
|
|
10881
|
+
function hitFromEnvironment(env) {
|
|
10882
|
+
for (const [key, value] of Object.entries(env)) {
|
|
10883
|
+
if (value === void 0 || !MINIMUM_RELEASE_AGE_ENV.test(key)) continue;
|
|
10884
|
+
return hitFromRaw(value, `\u73AF\u5883\u53D8\u91CF ${key}`);
|
|
10885
|
+
}
|
|
10886
|
+
return null;
|
|
10887
|
+
}
|
|
10888
|
+
async function readTextOrNull(file2) {
|
|
10889
|
+
try {
|
|
10890
|
+
return await readFile32(file2, "utf8");
|
|
10891
|
+
} catch {
|
|
10892
|
+
return null;
|
|
10893
|
+
}
|
|
10894
|
+
}
|
|
10895
|
+
async function hitFromYamlConfig(file2, label) {
|
|
10896
|
+
const text = await readTextOrNull(file2);
|
|
10897
|
+
if (text === null) return null;
|
|
10898
|
+
let data;
|
|
10899
|
+
try {
|
|
10900
|
+
data = parseYaml(text);
|
|
10901
|
+
} catch (error62) {
|
|
10902
|
+
return {
|
|
10903
|
+
minutes: null,
|
|
10904
|
+
raw: null,
|
|
10905
|
+
warning: `${label} \u65E0\u6CD5\u89E3\u6790\uFF1A${error62 instanceof Error ? error62.message : String(error62)}`,
|
|
10906
|
+
source: label
|
|
10907
|
+
};
|
|
10908
|
+
}
|
|
10909
|
+
if (data === null || typeof data !== "object") return null;
|
|
10910
|
+
const value = data["minimumReleaseAge"];
|
|
10911
|
+
if (value === void 0) return null;
|
|
10912
|
+
return hitFromRaw(String(value), label);
|
|
10913
|
+
}
|
|
10914
|
+
async function hitFromNpmrc(file2, label) {
|
|
10915
|
+
const text = await readTextOrNull(file2);
|
|
10916
|
+
if (text === null) return null;
|
|
10917
|
+
let found = null;
|
|
10918
|
+
for (const line of text.split(/\r?\n/u)) {
|
|
10919
|
+
const trimmed = line.trim();
|
|
10920
|
+
if (trimmed === "" || trimmed.startsWith("#") || trimmed.startsWith(";")) continue;
|
|
10921
|
+
const equal = trimmed.indexOf("=");
|
|
10922
|
+
if (equal < 0) continue;
|
|
10923
|
+
const key = trimmed.slice(0, equal).trim().toLowerCase().replaceAll("-", "").replaceAll("_", "");
|
|
10924
|
+
if (key !== "minimumreleaseage") continue;
|
|
10925
|
+
found = trimmed.slice(equal + 1).trim();
|
|
10926
|
+
}
|
|
10927
|
+
return found === null ? null : hitFromRaw(found, label);
|
|
10928
|
+
}
|
|
10929
|
+
async function detectSupplyChainPolicy(cwd, env = process.env, home = homedir()) {
|
|
10930
|
+
const xdg = env["XDG_CONFIG_HOME"]?.trim();
|
|
10931
|
+
const globalConfig2 = xdg !== void 0 && xdg !== "" ? join39(xdg, "pnpm", "config.yaml") : join39(home, ".config", "pnpm", "config.yaml");
|
|
10932
|
+
const hit = hitFromEnvironment(env) ?? await hitFromYamlConfig(join39(cwd, "pnpm-workspace.yaml"), "pnpm-workspace.yaml") ?? await hitFromNpmrc(join39(cwd, ".npmrc"), ".npmrc") ?? await hitFromYamlConfig(globalConfig2, "~/.config/pnpm/config.yaml") ?? await hitFromNpmrc(join39(home, ".npmrc"), "~/.npmrc");
|
|
10933
|
+
return {
|
|
10934
|
+
minimumReleaseAge: hit === null ? { minutes: null, source: null, raw: null, warning: null } : { minutes: hit.minutes, source: hit.source, raw: hit.raw, warning: hit.warning }
|
|
10935
|
+
};
|
|
10936
|
+
}
|
|
10541
10937
|
function isWildcardBind(host) {
|
|
10542
10938
|
return host === "0.0.0.0" || host === "::" || host === "[::]";
|
|
10543
10939
|
}
|
|
@@ -10575,6 +10971,7 @@ async function runDoctor(paths, cwd = process.cwd()) {
|
|
|
10575
10971
|
const session = credentials === null ? null : await checkSession(credentials);
|
|
10576
10972
|
const sandbox = await scanSandbox(cwd);
|
|
10577
10973
|
const projectEnv = await inspectProjectEnv(cwd);
|
|
10974
|
+
const supplyChain = await detectSupplyChainPolicy(cwd);
|
|
10578
10975
|
const cliRelease = await checkCliRelease(CLI_VERSION, RELEASE_TASKS);
|
|
10579
10976
|
const report = {
|
|
10580
10977
|
server,
|
|
@@ -10594,7 +10991,8 @@ async function runDoctor(paths, cwd = process.cwd()) {
|
|
|
10594
10991
|
env: process.env["ADEP_PUBLIC_URL"]?.trim() || null,
|
|
10595
10992
|
hostEnv: process.env["HOST"]?.trim() || null
|
|
10596
10993
|
},
|
|
10597
|
-
projectEnv
|
|
10994
|
+
projectEnv,
|
|
10995
|
+
supplyChain
|
|
10598
10996
|
};
|
|
10599
10997
|
if (credentials !== null) report.credentials.email = credentials.email;
|
|
10600
10998
|
if (mode !== void 0 && mode !== "600") {
|
|
@@ -10686,10 +11084,34 @@ function cliVersionSection(cli) {
|
|
|
10686
11084
|
lines.push(" \u63D0\u793A\uFF1A\u6309 docs/npm-publishing.md \u53D1\u5305\uFF08pnpm run release:check \u53EF\u67E5\u5F85\u53D1\u6E05\u5355\uFF09");
|
|
10687
11085
|
return lines;
|
|
10688
11086
|
}
|
|
11087
|
+
function supplyChainSection(policy) {
|
|
11088
|
+
const { minutes, source, warning } = policy.minimumReleaseAge;
|
|
11089
|
+
if (source === null) {
|
|
11090
|
+
return [" \xB7 \u672A\u68C0\u6D4B\u5230 minimumReleaseAge \u4F9B\u5E94\u94FE\u7B56\u7565\uFF08pnpm \u4E0D\u9650\u5236\u4F9D\u8D56\u53D1\u5E03\u5E74\u9F84\uFF09"];
|
|
11091
|
+
}
|
|
11092
|
+
if (warning !== null) {
|
|
11093
|
+
return [
|
|
11094
|
+
` ! ${warning}\uFF08\u6765\u6E90 ${source}\uFF09`,
|
|
11095
|
+
" \u63D0\u793A\uFF1A\u5148\u4FEE\u6B63\u8BE5\u914D\u7F6E\uFF0Cpnpm \u7684\u5B89\u88C5\u4E0E exec \u624D\u80FD\u6B63\u5E38\u6267\u884C"
|
|
11096
|
+
];
|
|
11097
|
+
}
|
|
11098
|
+
if (minutes === 0) {
|
|
11099
|
+
return [` \xB7 minimumReleaseAge=0\uFF08\u6765\u6E90 ${source}\uFF09\uFF1A\u7B56\u7565\u5DF2\u663E\u5F0F\u5173\u95ED`];
|
|
11100
|
+
}
|
|
11101
|
+
return [
|
|
11102
|
+
` ! minimumReleaseAge=${minutes} \u5206\u949F\uFF08\u6765\u6E90 ${source}\uFF09\uFF1Apnpm \u4F1A\u62D2\u7EDD\u53D1\u5E03\u65F6\u95F4\u4E0D\u8DB3 ${minutes} \u5206\u949F\u7684\u65B0\u7248\u672C`,
|
|
11103
|
+
" \u4EE5\u4E0B\u8F93\u51FA\u5C5E\u4E8E pnpm \u7684\u524D\u7F6E\u5B89\u88C5\u7B56\u7565\uFF0C\u4E0D\u662F adep \u5931\u8D25\uFF08\u4EE5 adep \u547D\u4EE4\u81EA\u8EAB\u7684\u9000\u51FA\u7801\u4E0E\u7ED3\u679C\u4E3A\u51C6\uFF09\uFF1A",
|
|
11104
|
+
" Lockfile failed supply-chain policy check / ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION",
|
|
11105
|
+
" \u4EC5\u672C\u6B21\u7ED5\u8FC7\uFF08pnpm \u53C2\u6570\uFF0C\u4E0D\u662F adep \u7684\uFF09\uFF1Apnpm --config.minimumReleaseAge=0 exec adep <\u547D\u4EE4>",
|
|
11106
|
+
" \u957F\u671F\u7B56\u7565\uFF08canary/next \u5148\u53D1\u3001latest \u5EF6\u540E\uFF09\u89C1\u6587\u6863\u300C\u4E25\u683C\u4F9B\u5E94\u94FE\u7B56\u7565\u73AF\u5883\u300D"
|
|
11107
|
+
];
|
|
11108
|
+
}
|
|
10689
11109
|
function formatDoctorReport(report) {
|
|
10690
11110
|
const lines = ["adep doctor \xB7 \u73AF\u5883\u81EA\u68C0", ""];
|
|
10691
11111
|
lines.push("CLI \u7248\u672C\u4E0E\u53D1\u7248");
|
|
10692
11112
|
lines.push(...cliVersionSection(report.cli));
|
|
11113
|
+
lines.push("", "\u4F9B\u5E94\u94FE\u7B56\u7565\uFF08\u73AF\u5883\uFF09");
|
|
11114
|
+
lines.push(...supplyChainSection(report.supplyChain));
|
|
10693
11115
|
lines.push("", "\u51ED\u636E\u4E0E\u8EAB\u4EFD");
|
|
10694
11116
|
if (report.credentials.present) {
|
|
10695
11117
|
const email3 = report.credentials.email ?? "(\u672A\u77E5\u90AE\u7BB1)";
|
|
@@ -10797,7 +11219,7 @@ function formatDoctorReport(report) {
|
|
|
10797
11219
|
}
|
|
10798
11220
|
return lines;
|
|
10799
11221
|
}
|
|
10800
|
-
var SERVER_PROBE_TIMEOUT_MS, OFFLINE_COMMANDS;
|
|
11222
|
+
var SERVER_PROBE_TIMEOUT_MS, OFFLINE_COMMANDS, MINIMUM_RELEASE_AGE_ENV;
|
|
10801
11223
|
var init_doctor = __esm({
|
|
10802
11224
|
"packages/cli/src/doctor.ts"() {
|
|
10803
11225
|
"use strict";
|
|
@@ -10821,6 +11243,7 @@ var init_doctor = __esm({
|
|
|
10821
11243
|
"adep db\uFF08\u672C\u5730\u6A21\u62DF\uFF09",
|
|
10822
11244
|
"adep doctor"
|
|
10823
11245
|
];
|
|
11246
|
+
MINIMUM_RELEASE_AGE_ENV = /^(?:npm_config_|pnpm_config_)minimum[_-]release[_-]age$/i;
|
|
10824
11247
|
}
|
|
10825
11248
|
});
|
|
10826
11249
|
|
|
@@ -11275,7 +11698,14 @@ var GENERATED_TEMPLATES = {
|
|
|
11275
11698
|
description: "\u6A21\u677F code"
|
|
11276
11699
|
}
|
|
11277
11700
|
],
|
|
11278
|
-
sharedAssets: [
|
|
11701
|
+
sharedAssets: [
|
|
11702
|
+
"packageJson",
|
|
11703
|
+
"adepConfig",
|
|
11704
|
+
"adepEnv",
|
|
11705
|
+
"gitignore",
|
|
11706
|
+
"dockerAssets",
|
|
11707
|
+
"pnpmWorkspace"
|
|
11708
|
+
]
|
|
11279
11709
|
},
|
|
11280
11710
|
files: [
|
|
11281
11711
|
{
|
|
@@ -11308,7 +11738,8 @@ var GENERATED_TEMPLATES = {
|
|
|
11308
11738
|
"helloFunction",
|
|
11309
11739
|
"functionIndex",
|
|
11310
11740
|
"gitignore",
|
|
11311
|
-
"dockerAssets"
|
|
11741
|
+
"dockerAssets",
|
|
11742
|
+
"pnpmWorkspace"
|
|
11312
11743
|
]
|
|
11313
11744
|
},
|
|
11314
11745
|
files: []
|
|
@@ -11341,7 +11772,8 @@ var GENERATED_TEMPLATES = {
|
|
|
11341
11772
|
"indexHtml",
|
|
11342
11773
|
"webSrc",
|
|
11343
11774
|
"gitignore",
|
|
11344
|
-
"dockerAssets"
|
|
11775
|
+
"dockerAssets",
|
|
11776
|
+
"pnpmWorkspace"
|
|
11345
11777
|
]
|
|
11346
11778
|
},
|
|
11347
11779
|
files: []
|
|
@@ -11370,14 +11802,15 @@ var GENERATED_TEMPLATES = {
|
|
|
11370
11802
|
"indexHtml",
|
|
11371
11803
|
"viteConfig",
|
|
11372
11804
|
"gitignore",
|
|
11373
|
-
"dockerAssets"
|
|
11805
|
+
"dockerAssets",
|
|
11806
|
+
"pnpmWorkspace"
|
|
11374
11807
|
],
|
|
11375
11808
|
source: "\u672C\u76EE\u5F55\u5373\u771F\u76F8\u6E90\uFF08\u539F apps/countdown \u5DF2\u79FB\u51FA\u4ED3\u5E93\uFF0C\u72EC\u7ACB\u7EF4\u62A4\u4E8E git.a.jajabjbj.top:6602/a/countdown-adep.git\uFF09"
|
|
11376
11809
|
},
|
|
11377
11810
|
files: [
|
|
11378
11811
|
{
|
|
11379
11812
|
path: "README.md",
|
|
11380
|
-
content:
|
|
11813
|
+
content: '# {{name}}\n\n\u5012\u6570\u65E5 / \u7EAA\u5FF5\u65E5\uFF08countdown \u6A21\u677F\uFF09\u2014\u2014\u7531\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F\u300C\u5012\u6570\u65E5\u300D\u79FB\u690D\u7684 adep \u5168\u6808\u5E94\u7528\uFF1A\n`functions/` \u4E91\u51FD\u6570\uFF08auth / events + `_shared/` \u5171\u4EAB\u6A21\u5757\uFF09+ `web/src/` \u524D\u7AEF\u6E90\u7801\uFF08Vue 3 + Vite\uFF0C\nHome / Edit / Profile \u4E09\u9875 + OIDC \u56DE\u8C03\u9875\u3001\u81EA\u5B9A\u4E49 TabBar + \u5DE6\u6ED1\u5220\u9664 / \u957F\u6309\u7F6E\u9876 / \u4E0B\u62C9\u5237\u65B0\uFF0C\n\u754C\u9762\u4E0E\u5C0F\u7A0B\u5E8F\u5BF9\u9F50\uFF09\u3002vite \u5DE5\u7A0B\u6839\u5728**\u9879\u76EE\u6839**\uFF08`index.html` + `vite.config.ts` + \u6839 `package.json`\uFF09\u3002\n\n> \u672C\u6A21\u677F\u76EE\u5F55\u662F\u81EA\u5305\u542B\u771F\u76F8\u6E90\uFF08`scripts/build-templates.mjs` \u7531\u6B64\u751F\u6210 `generated.ts` \u5FEB\u7167\uFF0C\n> \u6539\u6A21\u677F\u540E\u91CD\u8DD1\u811A\u672C\uFF09\u3002**\u5B8C\u6574\u7248**\u5012\u6570\u65E5\uFF089 \u51FD\u6570\u57DF + \u4F1A\u5458/\u88C2\u53D8/\u519C\u5386/\u63D0\u9192 + 102 \u9879\u6D4B\u8BD5\uFF09\u89C1\u72EC\u7ACB\u4ED3\u5E93 [a/countdown-adep](https://git.a.jajabjbj.top:6602/a/countdown-adep)\uFF0C\u53EF\u88AB\u5E73\u53F0\u76F4\u63A5 from-git \u5BFC\u5165\u3002\n\n## \u5FEB\u901F\u5F00\u59CB\n\n```bash\nnpm install # \u5355\u4E00\u5DE5\u7A0B\u6839\uFF1A@adep/cli + \u524D\u7AEF\u4F9D\u8D56\uFF08vue / vue-router / @adep/auth-client\uFF09+ \u6784\u5EFA\u94FE\nnpm run dev # \u5168\u6808\u5F00\u53D1\uFF1Avite \u8FDB\u7A0B\u5185\u542F\u52A8 adep dev + /api \u4EE3\u7406\uFF0C\u524D\u7AEF HMR + \u51FD\u6570\u70ED\u91CD\u8F7D\nnpm test # \u51FD\u6570/\u5DE5\u5177\u5171\u4EAB\u903B\u8F91\u5355\u5143\u6D4B\u8BD5\uFF08vitest\uFF09\nnpm run build # \u6784\u5EFA\u524D\u7AEF \u2192 site/\nnpm run start # \u72EC\u7ACB\u8FD0\u884C\uFF08\u672C\u5730\u6A21\u62DF\u8FD0\u884C\u65F6 + \u9759\u6001\u6258\u7BA1 + --schema \u81EA\u52A8\u5EFA\u8868\uFF09\uFF0C\u6D4F\u89C8\u5668\u5F00 http://127.0.0.1:8787\n```\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\uFF08vite \u4F9D\u8D56\u7684\nesbuild \u539F\u751F\u4E8C\u8FDB\u5236\u6CA1\u51C6\u5907\u597D\uFF0C\u6784\u5EFA\u53EF\u80FD\u5931\u8D25\uFF09\uFF1B\u7528 npm \u5B89\u88C5\u4E0D\u53D7\u8FD9\u6761\u7B56\u7565\u5F71\u54CD\u3002\u4ECD\u7528 pnpm 9 \u65F6\n\u7B49\u4EF7\u5199\u6CD5\u662F\u5728 `package.json` \u91CC\u5199 `"pnpm": { "onlyBuiltDependencies": ["esbuild"] }`\u3002\n\n## \u90E8\u7F72\u5230 adep \u5E73\u53F0\n\n```bash\nadep login # \u767B\u5F55\uFF08\u5199 ~/.adep/credentials\uFF09\nnpm run deploy # \u53D1\u5E03\u4E91\u51FD\u6570\uFF08\u542B _shared/ \u5171\u4EAB\u6E90\u7801\uFF09\nadep publish --only frontend # \u672C\u5730\u6784\u5EFA\uFF08npm run build\uFF09\u2192 \u4E0A\u4F20 site/ \u5230\u5E73\u53F0\u9759\u6001\u6258\u7BA1\uFF08\u5F00 SPA \u56DE\u9000\uFF09\n# \u7B49\u4EF7\u7684\u663E\u5F0F\u4E24\u6B65\uFF1Anpm run build && npm run site:deploy\n```\n\n\u53D1\u5E03\u540E\u8BBF\u95EE `https://{project-slug}.adep.localhost:3001`\uFF08\u672C\u5730 dev \u5E73\u53F0\uFF09\u6216\u7EBF\u4E0A\u7AD9\u70B9\u5730\u5740\u3002\n\n> `adep publish --only frontend` \u5BF9 canonical \u5E03\u5C40\uFF08\u6839 `index.html` + \u6839 `scripts.build`\uFF0C\n> `web/` \u53EA\u653E\u6E90\u7801\uFF09\u4F1A\u81EA\u52A8\u6267\u884C\u672C\u5730\u6784\u5EFA\u518D\u76F4\u901A\u9759\u6001\u6258\u7BA1\u2014\u2014\u5E73\u53F0\u300C\u524D\u7AEF\u8349\u7A3F\u6784\u5EFA\u300D\u7684\u5165\u53E3\n> `web/index.html` \u5728\u672C\u5E03\u5C40\u4E0B\u4E0D\u5B58\u5728\uFF0C\u6240\u4EE5\u8D70\u524D\u8005\u800C\u4E0D\u662F\u7F3A\u7701\u5168\u6808\u53D1\u5E03\u3002\n\n## \u72EC\u7ACB\u90E8\u7F72\uFF08\u4E0D\u4F9D\u8D56 adep \u5E73\u53F0\uFF09\n\n`npm run build && npm run start` \u5373\u53EF\u672C\u5730\u72EC\u7ACB\u8DD1\uFF08adep serve \u4E0E\u5E73\u53F0\u540C\u6E90\u6267\u884C\u5668\uFF09\u3002\n\u5BB9\u5668\u5316\u90E8\u7F72\u53C2\u8003\u72EC\u7ACB\u4ED3\u5E93 a/countdown-adep \u7684 `Dockerfile` + `compose.yaml`\uFF08\u5355\u5BB9\u5668 =\nserve \u627F\u8F7D /api/* + \u9759\u6001\u6258\u7BA1 site/ + .adep/sim/ \u6570\u636E\u5377\uFF09\u3002\n\n## \u76EE\u5F55\u7ED3\u6784\n\n- `adep.config.ts`\uFF1A\u9879\u76EE\u914D\u7F6E\uFF08name / template / functionsDir / functions_prefix \u9ED8\u8BA4 /api\uFF09\n- `index.html` / `vite.config.ts`\uFF1Avite \u5165\u53E3\u4E0E\u914D\u7F6E\uFF08\u5DE5\u7A0B\u6839 = \u9879\u76EE\u6839\uFF0C`adep()` \u63D2\u4EF6\u4EE3\u7406 /api/*\uFF0Cbuild \u8F93\u51FA `site/`\uFF09\n- `pnpm-workspace.yaml`\uFF1Apnpm 10+ \u7684\u4F9D\u8D56\u6784\u5EFA\u811A\u672C\u767D\u540D\u5355\uFF08\u653E\u884C esbuild\uFF0C\u89C1\u4E0A\u8282\uFF09\n- `functions/`\uFF1A\u4E91\u51FD\u6570\u76EE\u5F55\u2014\u2014`auth.ts`\uFF08\u767B\u5F55/\u4F1A\u8BDD\uFF1AOIDC \u8EAB\u4EFD\u4F18\u5148\u3001device \u8EAB\u4EFD\u517C\u5BB9\uFF09\u3001`events.ts`\n \uFF08\u4E8B\u4EF6 CRUD + \u7F6E\u9876\u6392\u5E8F\uFF09\u3001`_shared/`\uFF08auth / store / date / response / route \u5171\u4EAB\u6A21\u5757\uFF0C\n \u5BF9\u5E94 vitest \u5355\u6D4B\uFF0C\u5168\u9879\u76EE\u5355\u4EFD\uFF09\n- `database/schema.sql`\uFF1A\u6570\u636E\u5E93\u7ED3\u6784\uFF08users / events \u8868\uFF1B`adep db migrate database/schema.sql` \u5E94\u7528\uFF09\n- `web/src/`\uFF1A\u524D\u7AEF\u6E90\u7801\u2014\u2014`web/src/views/`\uFF08Home / Edit / Profile + `OidcCallbackView.vue`\uFF09\u3001\n `web/src/ui/`\uFF08TabBar / UiHost \u590D\u523B wx.showToast \u7B49\uFF09\u3001`web/src/lib/`\n \uFF08request / auth / config / date / events / oidc\uFF09\n- `web/src/lib/request.ts`\uFF1Afetch \u5C01\u88C5\uFF08\u4E1A\u52A1\u4FE1\u5C01 + 40001 \u81EA\u52A8\u5237\u65B0\u91CD\u8BD5\uFF09\n- `site/`\uFF1A`npm run build` \u7684\u524D\u7AEF\u6784\u5EFA\u4EA7\u7269\uFF08\u7AD9\u70B9\u6258\u7BA1\u76EE\u5F55\uFF0C\u5DF2 gitignore\uFF09\n- `tsconfig.json` / `adep.d.ts`\uFF1ATypeScript \u914D\u7F6E\u4E0E\u4E91\u51FD\u6570\u4E0A\u4E0B\u6587\u7C7B\u578B\u58F0\u660E\n\n## \u7528\u6237\u4F53\u7CFB\u8BF4\u660E\uFF08\u767B\u5F55\u94FE\u8DEF\uFF09\n\n- **OIDC \u767B\u5F55\uFF08\u767B\u5F55\u5373\u670D\u52A1\uFF0C\u4E3B\u94FE\u8DEF\uFF09**\uFF1A`web/src/lib/oidc.ts` \u63A5\u5165\u5E73\u53F0\u4E09\u65B9\u767B\u5F55\uFF08\u6388\u6743\u7801 +\n PKCE S256\uFF0C\u4F1A\u8BDD\u81EA\u7BA1 localStorage\uFF0Caccess token \u8FC7\u671F\u81EA\u52A8\u5237\u65B0\uFF09\uFF0C`OidcCallbackView.vue`\n \u5904\u7406\u6388\u6743\u56DE\u8C03\uFF1B`functions/_shared/auth.ts` \u628A\u7F51\u5173\u89E3\u6790\u7684 `ctx.user`\uFF08\u5E73\u53F0\u7528\u6237\uFF09\u4EE5\n `oidc:<\u5E73\u53F0\u7528\u6237 id>` \u5173\u8054\u672C\u5730 users \u8868\uFF08\u96F6\u8FC1\u79FB\uFF0C\u7F3A\u884C\u5373\u5EFA\uFF09\u3002\u672A\u767B\u5F55\u65F6\u6570\u636E\u5B58 localStorage\n \uFF08`lib/events.ts`\uFF09\uFF0C\u767B\u5F55\u540E\u540C\u6B65\u4E91\u7AEF\u3002\n- **\u8BBE\u5907\u8EAB\u4EFD\uFF08\u517C\u5BB9\u65E7\u5BA2\u6237\u7AEF / API \u8C03\u7528\uFF0C\u515C\u5E95\uFF09**\uFF1A`POST /auth/login` \u6362\u53D6 device_id \u4F5C\n Bearer \u51ED\u636E\uFF08\u7B49\u4EF7 API Key\uFF09\uFF1Bweb \u524D\u7AEF\u5DF2\u8FC1\u79FB OIDC\uFF0C\u4E0D\u518D\u8D70\u8BBE\u5907\u767B\u5F55\u3002\u672A\u767B\u5F55/\u5931\u6548\u8FD4\u56DE\n \u4E1A\u52A1\u7801 40001\uFF0C`request.ts` \u636E\u6B64\u6E05\u4F1A\u8BDD\u3001\u6709 OIDC \u4F1A\u8BDD\u5219\u5F3A\u5236\u5237\u65B0\u91CD\u8BD5\u4E00\u6B21\u3002\n\n## \u66F4\u591A\n\n- \u79FB\u690D\u7ECF\u9A8C\u4E0E\u9010\u9879\u5BF9\u9F50\u8BF4\u660E\uFF1Aadep \u6587\u6863\u7AD9\u300C\u5B9E\u6218\uFF1A\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F\u79FB\u690D\u5012\u6570\u65E5\u300D\uFF08tutorial-countdown.md\uFF09\n- \u72EC\u7ACB\u90E8\u7F72\u5BB9\u5668\u914D\u7F6E\u89C1\u72EC\u7ACB\u4ED3\u5E93 a/countdown-adep\uFF08Dockerfile / compose.yaml\uFF09\n'
|
|
11381
11814
|
},
|
|
11382
11815
|
{
|
|
11383
11816
|
path: "database/schema.sql",
|
|
@@ -13718,14 +14151,18 @@ onMounted(() => {
|
|
|
13718
14151
|
}
|
|
13719
14152
|
};
|
|
13720
14153
|
|
|
13721
|
-
// shared/sdk/adep-env.ts
|
|
14154
|
+
// shared/sdk/adep-env.generated.ts
|
|
13722
14155
|
var ADEP_ENV_DTS = `/**
|
|
13723
14156
|
* AgentDeploy \u4E91\u51FD\u6570\u5F00\u53D1\u73AF\u5883\u7C7B\u578B\u58F0\u660E\uFF08\u90E8\u7F72\u5305 / adep init \u751F\u6210\uFF0C\u8BF7\u52FF\u624B\u6539\uFF09\u3002
|
|
13724
14157
|
*
|
|
13725
|
-
* \u672C\u6587\u4EF6\
|
|
13726
|
-
* headers/body/files/user \u4E0E cloud.db / cloud.
|
|
13727
|
-
* \u5168\u5C40 ctx \u4E0E AdepContext \u662F\u5F00\u53D1\u671F\u4E0A\u4E0B\u6587
|
|
13728
|
-
* \
|
|
14158
|
+
* \u672C\u6587\u4EF6\u7531\u300Cpnpm run generate:contracts\u300D\u4ECE @adep/types \u751F\u6210\uFF1A\u4E3A\u51FD\u6570\u6E90\u7801\u91CC\u7684 ctx \u63D0\u4F9B
|
|
14159
|
+
* method/path/query/headers/body/files/user/env \u4E0E cloud.db / cloud.kv / cloud.storage /
|
|
14160
|
+
* cloud.fetch / cloud.realtime \u7684\u5B8C\u6574\u8865\u5168\u3002\u5168\u5C40 ctx \u4E0E AdepContext \u662F\u5F00\u53D1\u671F\u4E0A\u4E0B\u6587
|
|
14161
|
+
* \uFF08\u7F16\u8F91\u5668\u8865\u5168\u7528\uFF09\uFF1B\u51FD\u6570\u8FD0\u884C\u671F\u7ECF\u53C2\u6570\u6CE8\u5165\uFF0C\u4E0D\u8BFB\u53D6\u5168\u5C40\u3002
|
|
14162
|
+
*
|
|
14163
|
+
* \u5951\u7EA6\u552F\u4E00\u771F\u76F8\u6E90 = packages/types/src/\uFF1B\u540C\u6E90\u4EA7\u7269\u8FD8\u6709 Web IDE \u955C\u50CF
|
|
14164
|
+
* \uFF08app/components/ide/adep.d.ts\uFF0C\u540C\u4E00\u4EFD\u751F\u6210\u5668\u8F93\u51FA + \u6D4F\u89C8\u5668\u6D4B\u8BD5\u5168\u5C40\uFF09\u3002
|
|
14165
|
+
* \u6F02\u79FB\u95E8 = scripts/lib/__tests__/contract-mirrors.test.ts\u3002
|
|
13729
14166
|
*/
|
|
13730
14167
|
|
|
13731
14168
|
/* ---------- HTTP \u89E6\u53D1\u4E0A\u4E0B\u6587\uFF08FunctionContext \u955C\u50CF\uFF09 ---------- */
|
|
@@ -13734,44 +14171,145 @@ type AdepHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OP
|
|
|
13734
14171
|
|
|
13735
14172
|
/* ---------- \u6587\u4EF6\u4E0E\u5B58\u50A8\uFF08CloudStorage \u955C\u50CF\uFF09 ---------- */
|
|
13736
14173
|
|
|
13737
|
-
/**
|
|
14174
|
+
/** \u51FD\u6570 HTTP \u89E6\u53D1\u65F6 ctx.files \u91CC\u7684\u5355\u4E2A\u4E0A\u4F20\u6587\u4EF6\uFF08multipart \u89E3\u6790\u4EA7\u7269\uFF09\u3002 */
|
|
13738
14175
|
interface AdepFunctionFile {
|
|
13739
14176
|
/** \u5BA2\u6237\u7AEF\u63D0\u4F9B\u7684\u6587\u4EF6\u540D\uFF08\u542B\u6269\u5C55\u540D\uFF09\u3002 */
|
|
13740
|
-
name: string
|
|
14177
|
+
readonly name: string
|
|
13741
14178
|
/** MIME \u7C7B\u578B\u3002 */
|
|
13742
|
-
type: string
|
|
14179
|
+
readonly type: string
|
|
13743
14180
|
/** \u5B57\u8282\u6570\u3002 */
|
|
13744
|
-
size: number
|
|
13745
|
-
data: Uint8Array
|
|
14181
|
+
readonly size: number
|
|
14182
|
+
readonly data: Uint8Array
|
|
13746
14183
|
}
|
|
13747
14184
|
|
|
13748
|
-
/** \u4E0A\u4F20\u6570\u636E\uFF1A\u6587\u672C\u3001\u4E8C\u8FDB\u5236\u3001\u6216\u76F4\u63A5\u900F\u4F20\u8BF7\u6C42\u91CC\u7684\u6587\u4EF6\u5BF9\u8C61\u3002 */
|
|
14185
|
+
/** \u4E0A\u4F20\u6570\u636E\uFF1A\u6587\u672C\u3001\u4E8C\u8FDB\u5236\u3001\u6216\u76F4\u63A5\u900F\u4F20\u8BF7\u6C42\u91CC\u7684\u6587\u4EF6\u5BF9\u8C61\uFF08PRD \xA72.1.3 \u793A\u4F8B\u7684\u7528\u6CD5\uFF09\u3002 */
|
|
13749
14186
|
type AdepStorageUploadData = string | Uint8Array | ArrayBuffer | AdepFunctionFile
|
|
13750
14187
|
|
|
13751
14188
|
type AdepFileVisibility = 'public' | 'private'
|
|
13752
14189
|
|
|
14190
|
+
/** \u4E0A\u4F20\u9009\u9879\u3002 */
|
|
14191
|
+
interface AdepStorageUploadOptions {
|
|
14192
|
+
/** \u53EF\u9009 MIME\uFF08R2 \u8FC1\u79FB\u7ECF httpMetadata \u6620\u5C04\uFF1B\u9A71\u52A8\u4FA7\u6301\u4E45\u5316\uFF09\u3002 */
|
|
14193
|
+
contentType?: string
|
|
14194
|
+
/**
|
|
14195
|
+
* \u53EF\u89C1\u6027\uFF0C\u7F3A\u7701 private\u3002
|
|
14196
|
+
*
|
|
14197
|
+
* public \u8868\u793A\u300C\u62FF\u5230 URL \u7684\u4EFB\u4F55\u4EBA\u6C38\u4E45\u53EF\u8BFB\u300D\uFF08\u9879\u76EE\u6587\u4EF6\u76F4\u8FDE\u8DEF\u7531\u8DF3\u8FC7\u7B7E\u540D\uFF09\uFF0C
|
|
14198
|
+
* \u9700\u8981\u957F\u671F\u7A33\u5B9A\u7684\u5916\u94FE\uFF08getUrl\uFF09\u624D\u663E\u5F0F\u4F20\uFF1B\u5176\u4F59\u60C5\u51B5\u4FDD\u6301 private\u3002
|
|
14199
|
+
*/
|
|
14200
|
+
visibility?: AdepFileVisibility
|
|
14201
|
+
}
|
|
14202
|
+
|
|
14203
|
+
/** getUrl \u7684\u8FD4\u56DE\uFF1A\u7A33\u5B9A\u8BBF\u95EE\u5730\u5740 + \u8FC7\u671F\u8BED\u4E49\u3002 */
|
|
14204
|
+
interface AdepStorageFileUrl {
|
|
14205
|
+
/**
|
|
14206
|
+
* \u8BBF\u95EE\u5730\u5740\uFF1A
|
|
14207
|
+
* - public \u6587\u4EF6 \u2192 \u65E0\u7B7E\u540D\u7684\u7A33\u5B9A\u76F4\u94FE\uFF08expiresAt: null\uFF09\uFF1B
|
|
14208
|
+
* - private \u6587\u4EF6 \u2192 \u5E26\u7B7E\u540D URL\uFF08expiresAt \u7ED9\u51FA\u771F\u5B9E\u8FC7\u671F\u65F6\u95F4\uFF0C**\u4E0D\u8981**\u628A\u5B83\u5F53\u6C38\u4E45\u94FE\u63A5\u5B58\u5E93\uFF09\u3002
|
|
14209
|
+
*/
|
|
14210
|
+
readonly url: string
|
|
14211
|
+
/** ISO 8601 \u8FC7\u671F\u65F6\u95F4\uFF1Bnull = \u4E0D\u8FC7\u671F\uFF08public \u76F4\u94FE\uFF09\u3002 */
|
|
14212
|
+
readonly expiresAt: string | null
|
|
14213
|
+
}
|
|
14214
|
+
|
|
14215
|
+
/** getSignedUrl \u9009\u9879\u3002 */
|
|
14216
|
+
interface AdepStorageSignedUrlOptions {
|
|
14217
|
+
/**
|
|
14218
|
+
* \u663E\u5F0F\u5141\u8BB8\u8D85\u8FC7 7 \u5929\u4E0A\u9650\u7684\u79C1\u6709\u7B7E\u540D URL\u3002
|
|
14219
|
+
*
|
|
14220
|
+
* \u79C1\u6709\u7B7E\u540D\u94FE\u63A5\u7684\u8BED\u4E49\u662F\u300C\u4E34\u65F6\u8BBF\u95EE\u300D\uFF1A\u8FC7\u671F\u524D\u6CC4\u6F0F\u5373\u957F\u671F\u53EF\u8BFB\u3002\u8D85\u957F TTL \u5FC5\u987B\u663E\u5F0F\u627F\u62C5\u98CE\u9669\uFF1B
|
|
14221
|
+
* \u957F\u671F\u5C55\u793A\u8BF7\u6539\u7528 visibility: 'public' + getUrl()\u3002
|
|
14222
|
+
*/
|
|
14223
|
+
force?: boolean
|
|
14224
|
+
}
|
|
14225
|
+
|
|
13753
14226
|
/** \u4E0A\u4F20 / \u5217\u4E3E\u8FD4\u56DE\u7684\u6587\u4EF6\u5143\u6570\u636E\uFF08\u4E0D\u542B\u5185\u5BB9\uFF09\u3002 */
|
|
13754
14227
|
interface AdepStoredFile {
|
|
13755
14228
|
/** \u6876\u5185\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u5982 avatars/avatar.png\u3002 */
|
|
13756
|
-
path: string
|
|
13757
|
-
size: number
|
|
13758
|
-
contentType?: string
|
|
13759
|
-
visibility: AdepFileVisibility
|
|
14229
|
+
readonly path: string
|
|
14230
|
+
readonly size: number
|
|
14231
|
+
readonly contentType?: string
|
|
14232
|
+
readonly visibility: AdepFileVisibility
|
|
13760
14233
|
/** ISO 8601 \u65F6\u95F4\u6233\u3002 */
|
|
13761
|
-
updatedAt?: string
|
|
14234
|
+
readonly updatedAt?: string
|
|
13762
14235
|
}
|
|
13763
14236
|
|
|
13764
14237
|
interface AdepCloudStorage {
|
|
13765
|
-
/**
|
|
13766
|
-
|
|
14238
|
+
/**
|
|
14239
|
+
* \u4E0A\u4F20 / \u8986\u76D6\u6587\u4EF6\uFF1B\u8DEF\u5F84\u975E\u6CD5\uFF08\u7A7F\u8D8A\u3001\u8D85\u9650\uFF09\u7531\u5B9E\u73B0\u629B\u9519\u3002
|
|
14240
|
+
* options.contentType\uFF1A\u53EF\u9009 MIME\uFF08R2 \u8FC1\u79FB\u7ECF httpMetadata \u6620\u5C04\uFF1B\u9A71\u52A8\u4FA7\u6301\u4E45\u5316\uFF09\u3002
|
|
14241
|
+
* options.visibility\uFF1A\u7F3A\u7701 private\uFF1Bpublic \u624D\u80FD\u7528 getUrl \u62FF\u4E0D\u8FC7\u671F\u7684\u7A33\u5B9A\u76F4\u94FE\u3002
|
|
14242
|
+
*/
|
|
14243
|
+
upload(
|
|
14244
|
+
path: string,
|
|
14245
|
+
data: AdepStorageUploadData,
|
|
14246
|
+
options?: AdepStorageUploadOptions
|
|
14247
|
+
): Promise<AdepStoredFile>
|
|
13767
14248
|
/** \u8BFB\u53D6\u6587\u4EF6\u5185\u5BB9\uFF1B\u4E0D\u5B58\u5728\u65F6\u629B STORAGE_NOT_FOUND\u3002 */
|
|
13768
14249
|
get(path: string): Promise<Uint8Array>
|
|
13769
14250
|
/** \u5220\u9664\u6587\u4EF6\uFF1B\u4E0D\u5B58\u5728\u65F6\u629B STORAGE_NOT_FOUND\u3002 */
|
|
13770
14251
|
remove(path: string): Promise<void>
|
|
13771
14252
|
/** \u6309\u524D\u7F00\u5217\u4E3E\uFF08\u7F3A\u7701\u5168\u6876\uFF09\u3002 */
|
|
13772
14253
|
list(prefix?: string): Promise<AdepStoredFile[]>
|
|
13773
|
-
/**
|
|
13774
|
-
|
|
14254
|
+
/**
|
|
14255
|
+
* \u7A33\u5B9A\u8BBF\u95EE\u5730\u5740\uFF08\u4E0E SDK \u901A\u9053 getFileUrl \u540C\u8BED\u4E49\uFF09\uFF1A
|
|
14256
|
+
* public \u2192 \u65E0\u7B7E\u540D\u3001\u4E0D\u8FC7\u671F\uFF1Bprivate \u2192 \u5E26\u7B7E\u540D\u5E76\u7ED9\u51FA expiresAt\uFF08\u663E\u5F0F\u533A\u5206\uFF0C\u4E0D\u8FD4\u56DE\u4F1A 403 \u7684\u88F8\u94FE\u63A5\uFF09\u3002
|
|
14257
|
+
*/
|
|
14258
|
+
getUrl(path: string): Promise<AdepStorageFileUrl>
|
|
14259
|
+
/** \u751F\u6210\u7B7E\u540D URL\uFF08private \u6587\u4EF6\u7684\u5916\u53D1\u901A\u9053\uFF09\uFF1B\u7F3A\u7701 TTL \u7531\u5B9E\u73B0\u5B9A\uFF08M1\uFF1A15 \u5206\u949F\uFF09\uFF0C\u4E0A\u9650 7 \u5929\u3002 */
|
|
14260
|
+
getSignedUrl(
|
|
14261
|
+
path: string,
|
|
14262
|
+
ttlSeconds?: number,
|
|
14263
|
+
options?: AdepStorageSignedUrlOptions
|
|
14264
|
+
): Promise<string>
|
|
14265
|
+
}
|
|
14266
|
+
|
|
14267
|
+
/* ---------- KV \u5B58\u50A8\uFF08CloudKv \u955C\u50CF\uFF09 ---------- */
|
|
14268
|
+
|
|
14269
|
+
/**
|
|
14270
|
+
* cloud.kv \u5951\u7EA6\uFF08ADR-0024 / CF-012\uFF09\uFF1A\u9879\u76EE\u7EA7 KV \u5B58\u50A8\u80FD\u529B\u3002
|
|
14271
|
+
*
|
|
14272
|
+
* \u5B9A\u4F4D\uFF1AWorkers KV \u7684 adep \u539F\u751F\u5BF9\u5E94\u7269\u2014\u2014@adep/cf-compat \u7684 KVNamespace shim
|
|
14273
|
+
* \u5728\u5176\u4E0A\u63D0\u4F9B Workers \u98CE\u683C API\uFF08text/json/arrayBuffer\u3001TTL\u3001list\uFF09\u3002\u539F\u751F\u51FD\u6570\u4E5F\u53EF
|
|
14274
|
+
* \u76F4\u63A5 cloud.kv \u4F7F\u7528\u3002
|
|
14275
|
+
*
|
|
14276
|
+
* \u5951\u7EA6\u8981\u70B9\uFF1A
|
|
14277
|
+
* - \u503C\u4E3A string\uFF08\u4E8C\u8FDB\u5236\u7531 shim \u5C42 base64 \u7F16\u89E3\u7801\u540E\u5B58\u53D6\uFF0C\u80FD\u529B\u672C\u4F53\u4FDD\u6301\u7B80\u5355\uFF09\uFF1B
|
|
14278
|
+
* - TTL \u4EE5\u300C\u79D2\u300D\u4E3A\u5355\u4F4D\uFF08Workers expirationTtl \u540C\u8BED\u4E49\uFF09\uFF1B\u672A\u8BBE TTL \u6C38\u4E0D\u8FC7\u671F\uFF1B
|
|
14279
|
+
* - list \u8FD4\u56DE\u952E + \u8FC7\u671F\u65F6\u95F4\uFF08unix \u79D2\uFF09\uFF0Cprefix \u8FC7\u6EE4\u5728\u5B9E\u73B0\u5185\u5B8C\u6210\uFF1B
|
|
14280
|
+
* - \u5B9E\u73B0\u843D\u70B9\uFF1A\u9879\u76EE\u5E93 _adep_kv \u4FDD\u7559\u8868\uFF08_ \u5E73\u53F0\u4FDD\u7559\u6BB5\uFF0C\u63A7\u5236\u53F0/db.list_tables
|
|
14281
|
+
* \u81EA\u52A8\u6392\u9664\uFF09\uFF0CSQL \u4E25\u683C\u4FDD\u6301\u5728 sim \u5F15\u64CE\u5B50\u96C6\u5185\uFF08CF-012\uFF09\u3002
|
|
14282
|
+
*/
|
|
14283
|
+
interface AdepCloudKvEntry {
|
|
14284
|
+
/** \u952E\u540D\u3002 */
|
|
14285
|
+
readonly name: string
|
|
14286
|
+
/** \u8FC7\u671F\u65F6\u95F4\uFF08unix \u79D2\uFF09\uFF1Bnull = \u6C38\u4E0D\u8FC7\u671F\u3002 */
|
|
14287
|
+
readonly expiration: number | null
|
|
14288
|
+
}
|
|
14289
|
+
|
|
14290
|
+
interface AdepCloudKvListOptions {
|
|
14291
|
+
/** \u524D\u7F00\u8FC7\u6EE4\u3002 */
|
|
14292
|
+
readonly prefix?: string
|
|
14293
|
+
/** \u8FD4\u56DE\u6761\u6570\u4E0A\u9650\uFF08\u7F3A\u7701\u5B9E\u73B0\u9ED8\u8BA4\uFF0C\u5982 100\uFF09\u3002 */
|
|
14294
|
+
readonly limit?: number
|
|
14295
|
+
}
|
|
14296
|
+
|
|
14297
|
+
interface AdepCloudKv {
|
|
14298
|
+
/** \u8BFB\u952E\uFF1B\u4E0D\u5B58\u5728\u6216\u5DF2\u8FC7\u671F\u8FD4\u56DE null\u3002 */
|
|
14299
|
+
get(key: string): Promise<string | null>
|
|
14300
|
+
/**
|
|
14301
|
+
* \u5199\u952E\uFF1BexpirationTtlSeconds \u4E3A\u5B58\u6D3B\u79D2\u6570\uFF08\u5230\u671F\u540E\u8BFB\u53D6\u8FD4\u56DE null\uFF09\u3002
|
|
14302
|
+
* \u8986\u76D6\u5199\u4E0D\u62A5\u9519\uFF08Workers KV \u540C\u8BED\u4E49\uFF09\u3002
|
|
14303
|
+
*/
|
|
14304
|
+
put(
|
|
14305
|
+
key: string,
|
|
14306
|
+
value: string,
|
|
14307
|
+
options?: { readonly expirationTtlSeconds?: number }
|
|
14308
|
+
): Promise<void>
|
|
14309
|
+
/** \u5220\u952E\uFF1B\u4E0D\u5B58\u5728\u4E0D\u62A5\u9519\uFF08\u5E42\u7B49\uFF09\u3002 */
|
|
14310
|
+
delete(key: string): Promise<void>
|
|
14311
|
+
/** \u6309\u524D\u7F00\u5217\u4E3E\u952E\uFF08\u672A\u8FC7\u671F\u7684\uFF09\uFF1B\u987A\u5E8F\u4E0E\u5206\u9875\u7531\u5B9E\u73B0\u5B9A\u4E49\u3002 */
|
|
14312
|
+
list(options?: AdepCloudKvListOptions): Promise<AdepCloudKvEntry[]>
|
|
13775
14313
|
}
|
|
13776
14314
|
|
|
13777
14315
|
/* ---------- \u6570\u636E\u5E93\uFF08CloudDb \u955C\u50CF\uFF09 ---------- */
|
|
@@ -13816,14 +14354,16 @@ interface AdepChangeQuery {
|
|
|
13816
14354
|
}
|
|
13817
14355
|
|
|
13818
14356
|
/**
|
|
13819
|
-
* \u5355\u8868\u94FE\u5F0F Builder\u3002\u6240\u6709\u94FE\u5F0F\u65B9\u6CD5\u8FD4\u56DE\u65B0 Builder\uFF08\u4E0D\u53EF\u53D8\uFF09\uFF0C\u7EC8\u503C\u65B9\u6CD5
|
|
13820
|
-
* \
|
|
13821
|
-
* \u5B9E\u4F8B\u6D3E\u751F\u591A\u4E2A\u67E5\u8BE2\u662F\u5B89\u5168\u7684\uFF08\u5B9E\u73B0\u4E0D\u5F97\u6709\u5171\u4EAB\u53EF\u53D8\u72B6\u6001\uFF09\u3002
|
|
14357
|
+
* \u5355\u8868\u94FE\u5F0F Builder\u3002\u6240\u6709\u94FE\u5F0F\u65B9\u6CD5\u8FD4\u56DE\u65B0 Builder\uFF08\u4E0D\u53EF\u53D8\uFF09\uFF0C\u7EC8\u503C\u65B9\u6CD5\uFF08get/first/count/insert/update/delete\uFF09
|
|
14358
|
+
* \u8FD4\u56DE Promise\u3002\u590D\u7528\u540C\u4E00 Builder \u5B9E\u4F8B\u6D3E\u751F\u591A\u4E2A\u67E5\u8BE2\u662F\u5B89\u5168\u7684\uFF08\u5B9E\u73B0\u4E0D\u5F97\u6709\u5171\u4EAB\u53EF\u53D8\u72B6\u6001\uFF09\u3002
|
|
13822
14359
|
*/
|
|
13823
14360
|
interface AdepCloudDbTable {
|
|
13824
14361
|
/** \u9650\u5B9A\u8FD4\u56DE\u5217\uFF1B\u4E0D\u8C03\u5373 select *\u3002 */
|
|
13825
14362
|
select(...columns: string[]): AdepCloudDbTable
|
|
13826
|
-
/**
|
|
14363
|
+
/**
|
|
14364
|
+
* \u58F0\u660E\u4E3A owned \u8868\uFF08DB-006\uFF09\uFF1A\u5199\u5165\u81EA\u52A8\u751F\u6210 ULID \u4E3B\u952E + \u8FFD\u52A0 __changes \u53D8\u66F4\u6D41\u3002
|
|
14365
|
+
* \u8868\u987B\u5DF2\u58F0\u660E owned\uFF08\u5B58\u5728 _adep_changes_<table> \u53D8\u66F4\u6D41\u8868\uFF09\uFF0C\u5426\u5219\u629B DB_UNSAFE_OP\u3002
|
|
14366
|
+
*/
|
|
13827
14367
|
owned(): AdepCloudDbTable
|
|
13828
14368
|
/** \u7B49\u503C\u8FC7\u6EE4\uFF1Awhere('status', 'active')\u3002 */
|
|
13829
14369
|
where(column: string, value: AdepSqlValue): AdepCloudDbTable
|
|
@@ -13842,7 +14382,7 @@ interface AdepCloudDbTable {
|
|
|
13842
14382
|
first(): Promise<AdepRow | null>
|
|
13843
14383
|
/** \u884C\u6570\uFF08\u5FFD\u7565 select/orderBy\uFF09\u3002 */
|
|
13844
14384
|
count(): Promise<number>
|
|
13845
|
-
/** \u63D2\u5165\u4E00\u884C\uFF1Bwhere \u5BF9\u63D2\u5165\u65E0\u610F\u4E49\u3002 */
|
|
14385
|
+
/** \u63D2\u5165\u4E00\u884C\uFF1Bwhere \u5BF9\u63D2\u5165\u65E0\u610F\u4E49\uFF0C\u5B9E\u73B0\u5E94\u5FFD\u7565\u6216\u62D2\u7EDD\u3002 */
|
|
13846
14386
|
insert(row: Record<string, AdepSqlValue>): Promise<void>
|
|
13847
14387
|
/** \u6279\u91CF\u63D2\u5165\u3002 */
|
|
13848
14388
|
insertMany(rows: ReadonlyArray<Record<string, AdepSqlValue>>): Promise<void>
|
|
@@ -13852,15 +14392,38 @@ interface AdepCloudDbTable {
|
|
|
13852
14392
|
delete(): Promise<number>
|
|
13853
14393
|
}
|
|
13854
14394
|
|
|
13855
|
-
/**
|
|
14395
|
+
/**
|
|
14396
|
+
* \u9879\u76EE\u6570\u636E\u5E93\u53E5\u67C4\u3002\u53E5\u67C4\u5FC5\u987B\u95ED\u5305\u5C01\u88C5\uFF1A\u4E0D\u5F97\u66B4\u9732\u8FDE\u63A5\u4E32\u3001schema \u540D\uFF08\xA74.5 \u786C\u89C4\u5219 4\uFF09\u3002
|
|
14397
|
+
*/
|
|
13856
14398
|
interface AdepCloudDb {
|
|
13857
|
-
/** \u6253\u5F00\u5355\u8868 Builder\u3002\u8868\u540D\u7531\u8FD0\u884C\u65F6\u767D\u540D\u5355\u6821\u9A8C\u3002 */
|
|
14399
|
+
/** \u6253\u5F00\u5355\u8868 Builder\u3002\u8868\u540D\u7531\u8FD0\u884C\u65F6\u767D\u540D\u5355\u6821\u9A8C\uFF08^[a-zA-Z_][a-zA-Z0-9_]{0,62}$\uFF09\u3002 */
|
|
13858
14400
|
table(name: string): AdepCloudDbTable
|
|
13859
|
-
/**
|
|
14401
|
+
/**
|
|
14402
|
+
* \u4E8B\u52A1\uFF1Afn \u6536\u5230\u540C\u5F62\u72B6\u7684\u53D7\u63A7\u4E8B\u52A1\u53E5\u67C4\uFF1B\u629B\u9519\u5373\u6574\u4F53\u56DE\u6EDA\u3002
|
|
14403
|
+
* \u4E8B\u52A1\u5185\u7981\u6B62 await \u4E8B\u52A1\u5916\u7684\u672C\u5E93\u64CD\u4F5C\uFF08\u5B9E\u73B0\u53EF\u68C0\u6D4B\u5E76\u62D2\u7EDD\uFF09\u3002
|
|
14404
|
+
*/
|
|
13860
14405
|
transaction<T>(fn: (tx: AdepCloudDb) => Promise<T>): Promise<T>
|
|
13861
14406
|
/** \u53D7\u63A7\u88F8 SQL\uFF1Bparams \u5FC5\u586B\uFF08\u65E0\u53C2\u4F20 []\uFF09\uFF0C\u5355\u8BED\u53E5\uFF0C\u7981\u591A\u8BED\u53E5\u5806\u53E0\u3002 */
|
|
13862
14407
|
query(sql: string, params: readonly AdepSqlValue[]): Promise<AdepRow[]>
|
|
13863
|
-
/**
|
|
14408
|
+
/**
|
|
14409
|
+
* \u53D7\u63A7\u88F8 DML\uFF08ADR-0024 / CF-013\uFF09\uFF1A\u5355\u6761 INSERT / UPDATE / DELETE\uFF0C
|
|
14410
|
+
* \u53C2\u6570\u5316\u7ED1\u5B9A\uFF0C\u8FD4\u56DE\u503C = \u53D7\u5F71\u54CD\u884C\u6570\u3002DDL\uFF08CREATE/DROP/ALTER\uFF09\u62D2\u7EDD\uFF08\u8D70\u63A7\u5236\u53F0\u5BA1\u8BA1\u8DEF\u5F84\uFF09\u3002
|
|
14411
|
+
* \u8FB9\u754C\uFF1A\u672C\u5730\u6A21\u62DF\u5F15\u64CE\u8981\u6C42 UPDATE/DELETE \u5FC5\u987B\u5E26 WHERE\uFF08\u4E0E\u7EBF\u4E0A\u884C\u4E3A\u5206\u53C9\u65F6\u4EE5 sim \u5F15\u64CE
|
|
14412
|
+
* \u7EA6\u675F\u4E3A\u51C6\uFF0CD1 shim \u4E1A\u52A1\u4EE3\u7801\u901A\u5E38\u5929\u7136\u5E26 WHERE\uFF09\u3002
|
|
14413
|
+
*/
|
|
14414
|
+
writeQuery(sql: string, params: readonly AdepSqlValue[]): Promise<{ changes: number }>
|
|
14415
|
+
/**
|
|
14416
|
+
* \u901A\u7528\u6267\u884C\uFF082026-10-14\uFF0CBUG-4\uFF09\uFF1Aquery \u53EA\u8BFB\u3001writeQuery \u4EC5 DML \u7684\u5386\u53F2 split \u8BA9
|
|
14417
|
+
* \u300CDDL \u8BE5\u8D70\u54EA\u300D\u6210\u4E3A\u6A21\u578B\u7684\u5FC5\u9519\u9898\uFF08\u5B9E\u6D4B db.execute \u76F4\u63A5 500\uFF09\u3002execute \u6536\u53E3\u4E3A
|
|
14418
|
+
* \u300Cquery \u222A writeQuery \u222A \u5355\u6761 DDL\u300D\u7684\u7EDF\u4E00\u5165\u53E3\uFF1A\u8BFB\u8BED\u53E5\u8F6C\u53D1 query \u8BED\u4E49\u3001\u5199\u8BED\u53E5\u8F6C\u53D1
|
|
14419
|
+
* writeQuery \u8BED\u4E49\u3001CREATE/ALTER \u7B49\u5355\u6761 DDL \u76F4\u653E\uFF08\u591A\u8BED\u53E5\u4ECD\u7136\u62D2\u7EDD\uFF09\u3002\u8FD4\u56DE\u53D7\u5F71\u54CD\u884C\u6570\uFF1B
|
|
14420
|
+
* SELECT \u7ECF\u5B83\u6267\u884C\u65F6\u8FD4\u56DE 0\uFF08\u8981\u884C\u96C6\u8BF7\u7528 query\uFF09\u3002
|
|
14421
|
+
*/
|
|
14422
|
+
execute(sql: string, params?: readonly AdepSqlValue[]): Promise<{ changes: number }>
|
|
14423
|
+
/**
|
|
14424
|
+
* \u8BFB\u53D6 owned \u8868 __changes \u53D8\u66F4\u6D41\uFF08\u6309 seq \u5347\u5E8F\uFF0C\u53EF\u91CD\u653E\uFF09\u3002\u8868\u975E owned \u2192 DB_UNSAFE_OP\u3002
|
|
14425
|
+
* afterSeq / ownerKey / limit \u8FC7\u6EE4\u6761\u4EF6\u53C2\u6570\u5316\u7ED1\u5B9A\u3002
|
|
14426
|
+
*/
|
|
13864
14427
|
changes(table: string, query?: AdepChangeQuery): Promise<AdepChangeRecord[]>
|
|
13865
14428
|
}
|
|
13866
14429
|
|
|
@@ -13891,9 +14454,12 @@ interface AdepCloudFetchResponse {
|
|
|
13891
14454
|
/** cloud.fetch\uFF1A\u53D7\u63A7\u7684 HTTPS \u8BF7\u6C42\u3002URL \u4E3B\u673A\u4E0D\u5728\u767D\u540D\u5355\u5219\u629B FN_FETCH_FORBIDDEN\u3002 */
|
|
13892
14455
|
type AdepCloudFetch = (url: string, init?: AdepCloudFetchInit) => Promise<AdepCloudFetchResponse>
|
|
13893
14456
|
|
|
13894
|
-
/* ---------- \u5B9E\u65F6\u901A\u9053\uFF08CloudRealtime \u955C\u50CF\uFF09 ---------- */
|
|
14457
|
+
/* ---------- \u5B9E\u65F6\u901A\u9053\uFF08CloudRealtime \u955C\u50CF\uFF0CFN-020\uFF09 ---------- */
|
|
13895
14458
|
|
|
13896
|
-
/**
|
|
14459
|
+
/**
|
|
14460
|
+
* \u4E00\u6761\u5DF2\u6295\u9012\u7684 channel \u6D88\u606F\uFF08RT-003 \u7684\u6D3E\u53D1\u961F\u5217\u8F93\u51FA\uFF09\u3002
|
|
14461
|
+
* seq \u4E3A\u670D\u52A1\u7AEF\u5728\u8BE5 channel \u5185\u7684\u5355\u8C03\u9012\u589E\u5E8F\u53F7\uFF08PRD \xA73.2.9 \u6BCF channel \u4E32\u884C\u4FDD\u5E8F\uFF09\u3002
|
|
14462
|
+
*/
|
|
13897
14463
|
interface AdepRealtimeChannelMessage {
|
|
13898
14464
|
channel: string
|
|
13899
14465
|
seq: number
|
|
@@ -13907,37 +14473,60 @@ interface AdepCloudRealtimeReceipt {
|
|
|
13907
14473
|
delivered: number
|
|
13908
14474
|
}
|
|
13909
14475
|
|
|
13910
|
-
/** subscribe \u56DE\u6267\uFF1Asubscription \u662F\u540E\u7EED receive / unsubscribe \u7684\u53E5\u67C4\u3002 */
|
|
14476
|
+
/** subscribe \u56DE\u6267\uFF1Asubscription \u662F\u540E\u7EED receive / unsubscribe \u7684\u53E5\u67C4\uFF08\u4E0D\u900F\u660E\u5B57\u7B26\u4E32\uFF09\u3002 */
|
|
13911
14477
|
interface AdepCloudRealtimeSubscription {
|
|
13912
14478
|
subscription: string
|
|
13913
14479
|
channel: string
|
|
13914
14480
|
}
|
|
13915
14481
|
|
|
13916
|
-
/**
|
|
13917
|
-
|
|
13918
|
-
|
|
13919
|
-
|
|
14482
|
+
/** \u9000\u8BA2\u56DE\u6267\uFF08\u4E0E\u672C\u5730 sim \u540C\u5F62\uFF1A\u53EA\u62A5\u300C\u5DF2\u79FB\u9664\u300D\uFF0C\u4E0D\u62A5\u5269\u4F59\u7F13\u51B2\u91CF\uFF09\u3002 */
|
|
14483
|
+
interface AdepCloudRealtimeUnsubscribeReceipt {
|
|
14484
|
+
removed: true
|
|
14485
|
+
}
|
|
14486
|
+
|
|
14487
|
+
/** \u51FD\u6570\u5185\u53EF\u7528\u7684\u5B9E\u65F6\u901A\u9053\u80FD\u529B\uFF08PRD \xA72.12 / \xA72.14.2\uFF09\u3002 */
|
|
13920
14488
|
interface AdepCloudRealtime {
|
|
13921
|
-
/**
|
|
14489
|
+
/**
|
|
14490
|
+
* \u5411 channel \u6295\u9012\u4E00\u6761\u6D88\u606F\uFF08\u540C\u6B65\u8BED\u4E49\uFF1A\u4E0D\u7B49\u8BA2\u9605\u8005\u786E\u8BA4\uFF0C\xA72.12.3\uFF09\u3002
|
|
14491
|
+
* except \u4E3A\u300C\u4E0D\u56DE\u53D1\u7ED9\u8BE5\u8FDE\u63A5\u300D\u7684\u8FDE\u63A5\u6807\u8BC6\u2014\u2014**\u7EBF\u4E0A\u652F\u6301\u3001\u672C\u5730 fail loud**
|
|
14492
|
+
* \uFF08\u5355\u8FDB\u7A0B\u5185\u5B58\u5E7F\u64AD\u6CA1\u6709\u8FDE\u63A5\u8EAB\u4EFD\u53EF\u6BD4\u8F83\uFF0C\u89C1 sim/boundary.ts\uFF09\u3002
|
|
14493
|
+
*/
|
|
13922
14494
|
publish(channel: string, data: unknown, except?: string): Promise<AdepCloudRealtimeReceipt>
|
|
14495
|
+
/** \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 */
|
|
13923
14496
|
subscribe(channel: string): Promise<AdepCloudRealtimeSubscription>
|
|
14497
|
+
/** \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 */
|
|
13924
14498
|
receive(subscription: string): Promise<AdepRealtimeChannelMessage[]>
|
|
13925
|
-
|
|
14499
|
+
/** \u9000\u8BA2\u5E76\u4E22\u5F03\u7F13\u51B2\u3002 */
|
|
14500
|
+
unsubscribe(subscription: string): Promise<AdepCloudRealtimeUnsubscribeReceipt>
|
|
13926
14501
|
}
|
|
13927
14502
|
|
|
13928
14503
|
/* ---------- \u80FD\u529B\u6302\u8F7D\u70B9\uFF08Cloud / CapabilityRegistry \u955C\u50CF\uFF09 ---------- */
|
|
13929
14504
|
|
|
13930
|
-
/** \u5DF2\u6CE8\u518C\u80FD\u529B\u540D \u2192 \u5B9E\u73B0\u5951\u7EA6\u7684\u6620\u5C04\
|
|
14505
|
+
/** \u5DF2\u6CE8\u518C\u80FD\u529B\u540D \u2192 \u5B9E\u73B0\u5951\u7EA6\u7684\u6620\u5C04\uFF08\u80FD\u529B\u540D\u7684\u552F\u4E00\u767B\u8BB0\u5904\uFF0C\u89C4\u8303 \xA74.5\uFF09\u3002 */
|
|
13931
14506
|
interface AdepCapabilityRegistry {
|
|
13932
14507
|
db: AdepCloudDb
|
|
13933
14508
|
storage: AdepCloudStorage
|
|
13934
|
-
/**
|
|
13935
|
-
|
|
13936
|
-
|
|
14509
|
+
/**
|
|
14510
|
+
* \u5B9E\u65F6\u901A\u9053\uFF08FN-020\uFF09\uFF1A\u9879\u76EE\u88C5\u914D\u4E86 realtime \u57DF\u5373\u6CE8\u5165\uFF1B\u65B9\u6CD5\u9762\u4E0E\u672C\u5730 sim \u540C\u6E90
|
|
14511
|
+
* \uFF08\u5951\u7EA6\u89C1 cloud-realtime.ts \u7684\u8F6E\u8BE2\u8BED\u4E49\u8B66\u793A\uFF09\u3002
|
|
14512
|
+
*/
|
|
13937
14513
|
realtime: AdepCloudRealtime
|
|
14514
|
+
/**
|
|
14515
|
+
* \u6C99\u7BB1\u53D7\u63A7\u7F51\u7EDC\uFF08GAME-007\uFF09\uFF1A\u672A\u914D\u7F6E FUNCTIONS_FETCH_ALLOWLIST \u65F6\u4E0D\u6CE8\u5165\uFF08\u65E0\u7F51\u7EDC\u5B89\u5168\u9ED8\u8BA4\uFF09\u3002
|
|
14516
|
+
* \u6CE8\u5165\u65F6\u4EC5\u53EF\u8BBF\u95EE\u767D\u540D\u5355\u4E3B\u673A\uFF0C\u53D7\u8D85\u65F6\u4E0E\u54CD\u5E94\u4F53\u4E0A\u9650\u7EA6\u675F\u3002
|
|
14517
|
+
*/
|
|
14518
|
+
fetch: AdepCloudFetch
|
|
14519
|
+
/**
|
|
14520
|
+
* \u9879\u76EE\u7EA7 KV \u5B58\u50A8\uFF08ADR-0024 / CF-012\uFF09\uFF1Abacked by \u9879\u76EE\u5E93 _adep_kv \u4FDD\u7559\u8868\uFF1B
|
|
14521
|
+
* @adep/cf-compat \u7684 KVNamespace shim \u5728\u5176\u4E0A\u63D0\u4F9B Workers \u98CE\u683C API\u3002
|
|
14522
|
+
*/
|
|
14523
|
+
kv: AdepCloudKv
|
|
13938
14524
|
}
|
|
13939
14525
|
|
|
13940
|
-
/**
|
|
14526
|
+
/**
|
|
14527
|
+
* \u7528\u6237\u51FD\u6570\u4FA7\u7684 ctx.cloud\uFF1A\u53EA\u80FD**\u8BBF\u95EE**\u80FD\u529B\uFF0C\u4E0D\u80FD\u6CE8\u518C/\u6CE8\u9500\uFF08\u90A3\u662F Provider/Consumer \u7684\u7279\u6743\uFF09\u3002
|
|
14528
|
+
* \u5DF2\u77E5\u80FD\u529B\u6709\u7CBE\u786E\u7C7B\u578B\u8865\u5168\uFF1B\u81EA\u5B9A\u4E49\u80FD\u529B\u7ECF\u7D22\u5F15\u7B7E\u540D\u8BBF\u95EE\uFF08\u8FD0\u884C\u65F6\u672A\u6CE8\u518C\u5373\u629B\u9519\uFF09\u3002
|
|
14529
|
+
*/
|
|
13941
14530
|
type AdepCloud = {
|
|
13942
14531
|
readonly [K in keyof AdepCapabilityRegistry]: AdepCapabilityRegistry[K]
|
|
13943
14532
|
} & {
|
|
@@ -13947,7 +14536,11 @@ type AdepCloud = {
|
|
|
13947
14536
|
|
|
13948
14537
|
/* ---------- \u8C03\u7528\u8005\u8EAB\u4EFD\uFF08ExecutorUser \u955C\u50CF\uFF09 ---------- */
|
|
13949
14538
|
|
|
13950
|
-
/**
|
|
14539
|
+
/**
|
|
14540
|
+
* \u6267\u884C\u8005\u8EAB\u4EFD\u6295\u5F71\uFF08FN-010 auth-in-function\uFF09\uFF1A\u7F51\u5173\u89E3\u6790\u4F1A\u8BDD\u540E\u6CE8\u5165\u8C03\u7528\u8005\u8EAB\u4EFD\u3002
|
|
14541
|
+
* \u7F3A\u7701 / \u533F\u540D / \u672A\u63A5\u89E3\u6790\u5668\u65F6\uFF0CExecutorRequest.user \u4E3A null\u2014\u2014
|
|
14542
|
+
* \u8EAB\u4EFD\u662F**\u900F\u4F20\u4FE1\u606F**\uFF08\u4F9B\u51FD\u6570\u81EA\u884C\u505A\u6743\u9650\u5224\u65AD\uFF09\uFF0C\u4E0D\u662F\u5F3A\u5236\u95E8\uFF0C\u7F3A\u8EAB\u4EFD\u4E0D\u963B\u585E\u6267\u884C\u3002
|
|
14543
|
+
*/
|
|
13951
14544
|
interface AdepExecutorUser {
|
|
13952
14545
|
/** \u5E73\u53F0\u7528\u6237 id\uFF08= better-auth session.user.id\uFF09\u3002 */
|
|
13953
14546
|
id: string
|
|
@@ -13966,19 +14559,30 @@ interface AdepContext {
|
|
|
13966
14559
|
readonly query: Readonly<Record<string, string | readonly string[]>>
|
|
13967
14560
|
/** \u8BF7\u6C42\u5934\uFF08\u952E\u4E3A\u5C0F\u5199\uFF09\u3002 */
|
|
13968
14561
|
readonly headers: Readonly<Record<string, string>>
|
|
13969
|
-
/** \u8BF7\u6C42\u4F53\uFF1B\u5F62\u72B6\u7531\u7528\u6237\u7528\u7C7B\u578B\u65AD\u8A00\u6536\u7A84\
|
|
14562
|
+
/** \u8BF7\u6C42\u4F53\uFF1B\u5F62\u72B6\u7531\u7528\u6237\u7528\u7C7B\u578B\u65AD\u8A00\u6536\u7A84\uFF08PRD \xA72.1.3 \u793A\u4F8B\u5373 ctx.body as {...}\uFF09\u3002 */
|
|
13970
14563
|
readonly body: unknown
|
|
13971
14564
|
/** multipart \u4E0A\u4F20\u7684\u6587\u4EF6\uFF08\u65E0\u6587\u4EF6\u65F6\u4E3A\u7A7A\u6570\u7EC4\uFF09\u3002 */
|
|
13972
14565
|
readonly files: readonly AdepFunctionFile[]
|
|
13973
|
-
/** \u5E73\u53F0\u80FD\u529B\u6302\u8F7D\u70B9\uFF1Acloud.db / cloud.storage
|
|
14566
|
+
/** \u5E73\u53F0\u80FD\u529B\u6302\u8F7D\u70B9\uFF1Acloud.db / cloud.storage\uFF08M3 \u8D77 cloud.realtime\uFF09\u3002 */
|
|
13974
14567
|
readonly cloud: AdepCloud
|
|
13975
|
-
/**
|
|
14568
|
+
/**
|
|
14569
|
+
* \u51FD\u6570\u73AF\u5883\u53D8\u91CF\uFF08CF-015\uFF09\uFF1A\u90E8\u7F72/\u672C\u5730\u6CE8\u5165\u7684\u9879\u76EE\u73AF\u5883\uFF08wrangler vars \u8FC1\u79FB\u4EA7\u7269\uFF09\u3002
|
|
14570
|
+
* \u4F9B @adep/cf-compat \u7684 cfEnv \u7EC4\u88C5 Workers \u98CE\u683C env\uFF08cf-compat \u7ECF\u771F\u5B9E\u6A21\u5757\u7CFB\u7EDF\u52A0\u8F7D\uFF0C
|
|
14571
|
+
* \u8BFB\u4E0D\u5230 vm \u6C99\u7BB1\u7684 process.env\uFF0C\u6545\u7ECF ctx \u900F\u4F20\uFF09\uFF1B\u7F3A\u7701 undefined\uFF08\u672A\u914D\u7F6E\uFF09\u3002
|
|
14572
|
+
*/
|
|
14573
|
+
readonly env?: Readonly<Record<string, string>>
|
|
14574
|
+
/**
|
|
14575
|
+
* \u8C03\u7528\u8005\u8EAB\u4EFD\u6295\u5F71\uFF08FN-010\uFF09\uFF1A\u7F51\u5173\u89E3\u6790\u4F1A\u8BDD\u540E\u6CE8\u5165\uFF1Bnull = \u533F\u540D / \u672A\u6CE8\u5165\u3002
|
|
14576
|
+
* \u51FD\u6570\u636E\u6B64\u81EA\u884C\u505A\u6210\u5458 / \u6743\u9650\u5224\u65AD\uFF08\u8EAB\u4EFD\u662F\u900F\u4F20\u4FE1\u606F\uFF0C\u4E0D\u662F\u5F3A\u5236\u95E8\uFF09\u3002
|
|
14577
|
+
*/
|
|
13976
14578
|
readonly user: AdepExecutorUser | null
|
|
13977
14579
|
}
|
|
13978
14580
|
|
|
13979
14581
|
/** \u5168\u5C40\u5F00\u53D1\u671F\u4E0A\u4E0B\u6587\uFF08\u7F16\u8F91\u5668\u8865\u5168\u7528\uFF1B\u51FD\u6570\u8FD0\u884C\u671F\u7ECF\u53C2\u6570\u6CE8\u5165\uFF0C\u4E0D\u8BFB\u53D6\u5168\u5C40\uFF09\u3002 */
|
|
13980
14582
|
declare const ctx: AdepContext
|
|
13981
14583
|
`;
|
|
14584
|
+
|
|
14585
|
+
// shared/sdk/adep-env.ts
|
|
13982
14586
|
var ADEP_TSCONFIG_JSON = `{
|
|
13983
14587
|
"compilerOptions": {
|
|
13984
14588
|
"target": "ES2021",
|
|
@@ -14394,6 +14998,14 @@ AgentDeploy \u5168\u6808\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u3
|
|
|
14394
14998
|
- \`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
|
|
14395
14999
|
- \`pnpm doctor\`\uFF08= \`adep doctor\`\uFF09\uFF1A\u672C\u5730\u73AF\u5883\u79BB\u7EBF\u8BCA\u65AD
|
|
14396
15000
|
|
|
15001
|
+
## pnpm \u4E0E\u4F9D\u8D56\u6784\u5EFA\u811A\u672C\uFF08pnpm 10 \u8D77\u9ED8\u8BA4\u4E0D\u8DD1\uFF09
|
|
15002
|
+
|
|
15003
|
+
\u9879\u76EE\u6839\u7684 \`pnpm-workspace.yaml\` \u5DF2\u653E\u884C \`esbuild\` \u7684\u6784\u5EFA\u811A\u672C\uFF08\`onlyBuiltDependencies\` \u4E0E
|
|
15004
|
+
\`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
|
|
15005
|
+
\u6784\u5EFA\u811A\u672C**\uFF0C\u5220\u6389\u8FD9\u4EFD\u914D\u7F6E\u540E \`pnpm install\` \u4F1A\u4EE5 \`ERR_PNPM_IGNORED_BUILDS\` \u62A5\u9519
|
|
15006
|
+
\uFF08vite \u4F9D\u8D56\u7684 esbuild \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
|
|
15007
|
+
\`package.json\` \u91CC\u5199 \`"pnpm": { "onlyBuiltDependencies": ["esbuild"] }\`\u3002
|
|
15008
|
+
|
|
14397
15009
|
${DOCKER_README_SECTION()}
|
|
14398
15010
|
|
|
14399
15011
|
## \u76EE\u5F55\u7ED3\u6784
|
|
@@ -14534,6 +15146,19 @@ export default defineConfig({
|
|
|
14534
15146
|
})
|
|
14535
15147
|
`;
|
|
14536
15148
|
var GITIGNORE = "node_modules/\ndata/\n.adep/\nsite/\n";
|
|
15149
|
+
var PNPM_WORKSPACE_YAML = `# pnpm \u914D\u7F6E\uFF08pnpm 10 \u8D77\u4ECE\u8FD9\u91CC\u8BFB\u53D6\uFF1Bpackage.json \u7684 pnpm \u5B57\u6BB5\u53EA\u5BF9 pnpm 9 \u53CA\u66F4\u65E9\u751F\u6548\uFF09
|
|
15150
|
+
#
|
|
15151
|
+
# pnpm 10+ \u9ED8\u8BA4\u4E0D\u6267\u884C\u4F9D\u8D56\u7684\u6784\u5EFA\u811A\u672C\uFF08\u4F9B\u5E94\u94FE\u5B89\u5168\u9ED8\u8BA4\uFF09\u3002esbuild \u662F vite / @adep/cli \u7684
|
|
15152
|
+
# \u4F20\u9012\u4F9D\u8D56\uFF0C\u9700\u8981\u51C6\u5907\u539F\u751F\u4E8C\u8FDB\u5236\uFF1B\u4E0D\u653E\u884C\u4F1A\u5728 pnpm install \u672B\u5C3E\u62A5
|
|
15153
|
+
# Error: ERR_PNPM_IGNORED_BUILDS ... Ignored build scripts: esbuild
|
|
15154
|
+
# pnpm 10 \u8BFB onlyBuiltDependencies\uFF0Cpnpm 11+ \u6539\u540D\u4E3A allowBuilds\uFF08\u65E7\u952E\u88AB\u9759\u9ED8\u5FFD\u7565\uFF09\uFF0C
|
|
15155
|
+
# \u4E24\u4EFD\u5E76\u5199\u4EE5\u540C\u65F6\u8986\u76D6\u4E24\u4E2A major\u3002
|
|
15156
|
+
onlyBuiltDependencies:
|
|
15157
|
+
- esbuild
|
|
15158
|
+
|
|
15159
|
+
allowBuilds:
|
|
15160
|
+
esbuild: true
|
|
15161
|
+
`;
|
|
14537
15162
|
var SHARED_ASSETS = {
|
|
14538
15163
|
packageJson: (ctx) => [
|
|
14539
15164
|
{
|
|
@@ -14563,7 +15188,8 @@ var SHARED_ASSETS = {
|
|
|
14563
15188
|
viteConfig: () => [{ path: "vite.config.ts", content: VITE_CONFIG }],
|
|
14564
15189
|
indexHtml: () => [{ path: "index.html", content: INDEX_HTML }],
|
|
14565
15190
|
gitignore: () => [{ path: ".gitignore", content: GITIGNORE }],
|
|
14566
|
-
dockerAssets: (ctx) => DOCKER_ASSETS(ctx.name)
|
|
15191
|
+
dockerAssets: (ctx) => DOCKER_ASSETS(ctx.name),
|
|
15192
|
+
pnpmWorkspace: () => [{ path: "pnpm-workspace.yaml", content: PNPM_WORKSPACE_YAML }]
|
|
14567
15193
|
};
|
|
14568
15194
|
|
|
14569
15195
|
// packages/cli/src/templates/template-render.ts
|
|
@@ -38555,7 +39181,7 @@ function registerImport(program2, ctx) {
|
|
|
38555
39181
|
|
|
38556
39182
|
// packages/cli/src/commands/dev.ts
|
|
38557
39183
|
function registerDevServers(program2, ctx) {
|
|
38558
|
-
program2.command("dev").description("\u672C\u5730\u8C03\u8BD5\uFF1A\u76D1\u542C functions/ \u70ED\u91CD\u8F7D\uFF0Chttp://localhost:<port>/<fnName>").option("-p, --port <port>", "\u76D1\u542C\u7AEF\u53E3\uFF08\u7F3A\u7701 8787\uFF09"
|
|
39184
|
+
program2.command("dev").description("\u672C\u5730\u8C03\u8BD5\uFF1A\u76D1\u542C functions/ \u70ED\u91CD\u8F7D\uFF0Chttp://localhost:<port>/<fnName>").option("-p, --port <port>", "\u76D1\u542C\u7AEF\u53E3\uFF08\u7F3A\u7701 8787\uFF1B\u5185\u7F6E\u7F3A\u7701\u88AB\u5360\u7528\u65F6\u81EA\u52A8\u987A\u5EF6\u5230 8788 \u8D77\uFF09").option(
|
|
38559
39185
|
"--db <mode>",
|
|
38560
39186
|
"\u6570\u636E\u5E93\u6A21\u5F0F\uFF1Asqlite\uFF08\u7F3A\u7701\uFF0C\u771F\u5B9E SQLite \u5E93\u6587\u4EF6\uFF0C\u9700 Bun \u6216 Node \u2265 22.5\uFF1B\u8FD0\u884C\u65F6\u4E0D\u652F\u6301\u6216\u6253\u5F00\u5931\u8D25\u65F6\u81EA\u52A8\u964D\u7EA7 sim\uFF09| sim\uFF08\u5185\u7F6E\u6A21\u62DF\u5F15\u64CE + .adep/sim/db.json\uFF09"
|
|
38561
39187
|
).option(
|
|
@@ -38570,7 +39196,8 @@ function registerDevServers(program2, ctx) {
|
|
|
38570
39196
|
const { startDevServer: startDevServer2 } = await Promise.resolve().then(() => (init_dev(), dev_exports));
|
|
38571
39197
|
const started = await startDevServer2({
|
|
38572
39198
|
cwd: ctx.cwd,
|
|
38573
|
-
|
|
39199
|
+
// 不传就交给 startDevServer 定档(内置缺省 8787,被占用时顺延);传了就是显式意图,不换号。
|
|
39200
|
+
...flags.port === void 0 ? {} : { port: Number(flags.port) },
|
|
38574
39201
|
// 缺省值一律交给 startDevServer 定档(旗标 > ADEP_SERVE_DB > 内置缺省),
|
|
38575
39202
|
// 与 `adep serve` 同一条纪律:commander 的缺省值不该盖掉环境变量。
|
|
38576
39203
|
...flags.db === void 0 ? {} : { db: flags.db },
|
|
@@ -38583,7 +39210,10 @@ function registerDevServers(program2, ctx) {
|
|
|
38583
39210
|
});
|
|
38584
39211
|
program2.command("serve").description(
|
|
38585
39212
|
"\u5F00\u53D1\u6001\u670D\u52A1\u5668\uFF1A\u51FD\u6570 /api/{fn} + /healthz + \u9759\u6001\u6258\u7BA1 + \u7EC4\u4EF6\u9884\u89C8\uFF08\u9ED8\u8BA4\u4EC5\u56DE\u73AF\uFF0C\u4E0D\u662F\u751F\u4EA7\u670D\u52A1\u5668\uFF09"
|
|
38586
|
-
).option(
|
|
39213
|
+
).option(
|
|
39214
|
+
"-p, --port <port>",
|
|
39215
|
+
"\u76D1\u542C\u7AEF\u53E3\uFF08\u7F3A\u7701\u53D6 PORT \u73AF\u5883\u53D8\u91CF\uFF0C\u518D\u7F3A\u7701 8787\uFF1B\u4EC5\u5185\u7F6E\u7F3A\u7701 8787 \u88AB\u5360\u7528\u65F6\u81EA\u52A8\u987A\u5EF6\uFF0C\u663E\u5F0F\u7AEF\u53E3/PORT \u4E0D\u6362\u53F7\uFF09"
|
|
39216
|
+
).option(
|
|
38587
39217
|
"-H, --host <host>",
|
|
38588
39218
|
"\u76D1\u542C\u5730\u5740\uFF08\u7F3A\u7701\u53D6 HOST \u73AF\u5883\u53D8\u91CF\uFF0C\u518D\u7F3A\u7701 127.0.0.1\uFF1B\u7ED1\u5B9A\u975E\u56DE\u73AF\u65F6\u7ED9\u51FA\u5BF9\u5916\u66B4\u9732\u8B66\u544A\uFF09"
|
|
38589
39219
|
).option(
|
|
@@ -38643,6 +39273,7 @@ init_auth();
|
|
|
38643
39273
|
init_client();
|
|
38644
39274
|
init_deploy();
|
|
38645
39275
|
init_frontend();
|
|
39276
|
+
init_frontend_draft();
|
|
38646
39277
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
38647
39278
|
import { readFile as readFile26, stat as stat16 } from "node:fs/promises";
|
|
38648
39279
|
import { join as join34, resolve as resolve17 } from "node:path";
|
|
@@ -38683,6 +39314,30 @@ async function frontendNoPageGuidance(cwd, message) {
|
|
|
38683
39314
|
);
|
|
38684
39315
|
return lines.join("\n");
|
|
38685
39316
|
}
|
|
39317
|
+
async function assertDraftPublishable(cwd, prepared) {
|
|
39318
|
+
if (hasFrontendEntry(prepared.drafts)) return;
|
|
39319
|
+
const fileCount = Object.keys(prepared.drafts).length;
|
|
39320
|
+
throw new CliError(
|
|
39321
|
+
"FE_NO_PAGE",
|
|
39322
|
+
await frontendNoPageGuidance(
|
|
39323
|
+
cwd,
|
|
39324
|
+
`\u672C\u5730 web/ \u7F3A\u5C11\u7AD9\u70B9\u5165\u53E3 web/index.html\uFF08\u73B0\u6709 ${fileCount} \u4E2A\u6587\u4EF6\u90FD\u4E0D\u662F\u5165\u53E3\uFF09\uFF1A\u5E73\u53F0\u6784\u7AD9\u95E8\u540C\u6837\u8981\u6C42\u8BE5\u6587\u4EF6\uFF0C\u53D1\u5E03\u5FC5\u7136\u5931\u8D25\u3002
|
|
39325
|
+
\u5DF2\u5728\u540C\u6B65\u4E4B\u524D\u963B\u65AD\u2014\u2014\u672C\u6B21\u672A\u5411\u5E73\u53F0\u5199\u5165\u4EFB\u4F55\u8349\u7A3F\uFF0C\u5E73\u53F0\u8349\u7A3F\u4FDD\u6301\u539F\u6837\u3002
|
|
39326
|
+
\u5728 web/ \u4E0B\u8865 index.html \u540E\u518D\u6267\u884C adep publish --only frontend\u3002`
|
|
39327
|
+
)
|
|
39328
|
+
);
|
|
39329
|
+
}
|
|
39330
|
+
function withDraftReplacedNote(error62, prepared) {
|
|
39331
|
+
if (!(error62 instanceof CliError)) return error62;
|
|
39332
|
+
const fileCount = Object.keys(prepared.drafts).length;
|
|
39333
|
+
return new CliError(
|
|
39334
|
+
error62.code,
|
|
39335
|
+
`${error62.message}
|
|
39336
|
+
|
|
39337
|
+
\u6CE8\u610F\uFF1A\u672C\u6B21\u53D1\u5E03\u524D\u5DF2\u628A\u672C\u5730 web/ \u7684 ${fileCount} \u4E2A\u6587\u4EF6\u6574\u7EC4\u5199\u5165\u5E73\u53F0\u8349\u7A3F\uFF08\u539F\u8349\u7A3F\u5DF2\u88AB\u66FF\u6362\uFF0C\u5F53\u524D\u5E73\u53F0\u8349\u7A3F = \u672C\u5730\u6E90\u7801\uFF09\uFF1B\u4FEE\u590D\u540E\u91CD\u8BD5\u4F1A\u518D\u6B21\u6574\u7EC4\u8986\u76D6\u3002`,
|
|
39338
|
+
error62.exitCode
|
|
39339
|
+
);
|
|
39340
|
+
}
|
|
38686
39341
|
async function publishFrontend(paths, options) {
|
|
38687
39342
|
const log = options.silent === true ? () => void 0 : options.log ?? ((line) => process.stdout.write(`${line}
|
|
38688
39343
|
`));
|
|
@@ -38852,7 +39507,7 @@ async function checkSchemaDrift(paths, options) {
|
|
|
38852
39507
|
const schemaStat = await stat16(schemaFile).catch(() => null);
|
|
38853
39508
|
if (schemaStat === null || !schemaStat.isFile()) {
|
|
38854
39509
|
options.log("[adep] \u672A\u627E\u5230 database/schema.sql\uFF0C\u8DF3\u8FC7 schema \u6F02\u79FB\u68C0\u67E5");
|
|
38855
|
-
return
|
|
39510
|
+
return { status: "skipped", reason: "no-schema" };
|
|
38856
39511
|
}
|
|
38857
39512
|
const sql = await readFile26(schemaFile, "utf8");
|
|
38858
39513
|
const { dbSchemaDiff: dbSchemaDiff2 } = await Promise.resolve().then(() => (init_db2(), db_exports));
|
|
@@ -38867,25 +39522,61 @@ async function checkSchemaDrift(paths, options) {
|
|
|
38867
39522
|
} catch (error62) {
|
|
38868
39523
|
if (error62 instanceof CliError && (error62.code === "DB_NOT_PROVISIONED" || error62.code === "DB_NOT_FOUND")) {
|
|
38869
39524
|
options.log("[adep] \u6570\u636E\u5E93\u5C1A\u672A\u542F\u52A8\uFF0C\u8DF3\u8FC7 schema \u6F02\u79FB\u68C0\u67E5\uFF08\u5148 adep db start \u540E\u53D1\u5E03\u53EF\u542F\u7528\uFF09");
|
|
38870
|
-
return
|
|
39525
|
+
return { status: "skipped", reason: "db-not-provisioned" };
|
|
38871
39526
|
}
|
|
38872
39527
|
throw error62;
|
|
38873
39528
|
}
|
|
38874
|
-
const
|
|
39529
|
+
const missingIndexes = drift.missingIndexes ?? [];
|
|
39530
|
+
const uniqueDiff = drift.uniqueDiff ?? [];
|
|
39531
|
+
const defaultDiff = drift.defaultDiff ?? [];
|
|
39532
|
+
const nullabilityDiff = drift.nullabilityDiff ?? [];
|
|
39533
|
+
const missingPlainIndexes = missingIndexes.filter((index) => !index.unique);
|
|
39534
|
+
const blockingNullability = nullabilityDiff.filter(
|
|
39535
|
+
(item) => item.expected === "not-null" && item.actual === "nullable"
|
|
39536
|
+
);
|
|
39537
|
+
const warningNullability = nullabilityDiff.filter(
|
|
39538
|
+
(item) => item.expected === "nullable" && item.actual === "not-null"
|
|
39539
|
+
);
|
|
39540
|
+
const fallbackBlocking = drift.missingTables.length > 0 || drift.missingColumns.length > 0 || drift.typeMismatches.length > 0 || uniqueDiff.length > 0 || blockingNullability.length > 0;
|
|
39541
|
+
const blocking = drift.blocking ?? fallbackBlocking;
|
|
38875
39542
|
if (drift.destructiveStatements.length > 0) {
|
|
38876
39543
|
options.log(
|
|
38877
39544
|
`[adep] \u26A0 schema.sql \u542B\u7834\u574F\u6027\u8BED\u53E5\uFF08\u4E0D\u4F1A\u88AB\u81EA\u52A8\u6267\u884C\uFF09\uFF1A${drift.destructiveStatements.join(" \xB7 ")}`
|
|
38878
39545
|
);
|
|
38879
39546
|
}
|
|
39547
|
+
const warningCount = missingPlainIndexes.length + defaultDiff.length + warningNullability.length;
|
|
39548
|
+
const hasWarnings = warningCount > 0;
|
|
39549
|
+
if (missingPlainIndexes.length > 0) {
|
|
39550
|
+
options.log(
|
|
39551
|
+
`[adep] \u26A0 \u7EBF\u4E0A\u7F3A\u5C11 ${missingPlainIndexes.length} \u4E2A\u7D22\u5F15\uFF08\u4E0D\u963B\u65AD\u53D1\u5E03\uFF1Badep db migrate \u53EF\u8865\u5EFA\uFF09\uFF1A${missingPlainIndexes.map((index) => index.name).join(" \xB7 ")}`
|
|
39552
|
+
);
|
|
39553
|
+
}
|
|
39554
|
+
if (defaultDiff.length > 0) {
|
|
39555
|
+
options.log(
|
|
39556
|
+
`[adep] \u26A0 \u9ED8\u8BA4\u503C\u6F02\u79FB ${defaultDiff.length} \u5904\uFF08\u4E0D\u963B\u65AD\u53D1\u5E03\uFF1B\u8BF7\u6838\u5BF9 schema \u4E0E\u7EBF\u4E0A\uFF09\uFF1A${defaultDiff.map((item) => `${item.table}.${item.column}`).join(" \xB7 ")}`
|
|
39557
|
+
);
|
|
39558
|
+
}
|
|
39559
|
+
if (warningNullability.length > 0) {
|
|
39560
|
+
options.log(
|
|
39561
|
+
`[adep] \u26A0 \u7EBF\u4E0A\u5217\u6BD4 schema \u66F4\u4E25\u683C\uFF08NOT NULL\uFF09${warningNullability.length} \u5904\uFF08\u4E0D\u963B\u65AD\uFF09\uFF1A${warningNullability.map((item) => `${item.table}.${item.column}`).join(" \xB7 ")}`
|
|
39562
|
+
);
|
|
39563
|
+
}
|
|
38880
39564
|
if (!blocking) {
|
|
38881
|
-
options.log(
|
|
38882
|
-
|
|
39565
|
+
options.log(
|
|
39566
|
+
hasWarnings ? "[adep] \u2713 schema \u65E0\u963B\u65AD\u6F02\u79FB\uFF08\u5B58\u5728\u4E0A\u8FF0\u8B66\u544A\uFF09" : "[adep] \u2713 schema \u65E0\u6F02\u79FB"
|
|
39567
|
+
);
|
|
39568
|
+
return { status: "clean", warnings: warningCount };
|
|
38883
39569
|
}
|
|
39570
|
+
const blockingCount = drift.missingTables.length + drift.missingColumns.length + drift.typeMismatches.length + uniqueDiff.length + blockingNullability.length;
|
|
38884
39571
|
if (options.allowDrift === true) {
|
|
38885
|
-
options.log(
|
|
38886
|
-
|
|
39572
|
+
options.log(
|
|
39573
|
+
"[adep] \u26A0 schema \u6F02\u79FB\u88AB --allow-drift \u653E\u884C\uFF1A\u7EBF\u4E0A\u51FD\u6570\u53EF\u80FD no such column / \u4EA7\u751F\u91CD\u590D\u6570\u636E"
|
|
39574
|
+
);
|
|
39575
|
+
return { status: "allowed", blocking: blockingCount };
|
|
38887
39576
|
}
|
|
38888
|
-
const lines = [
|
|
39577
|
+
const lines = [
|
|
39578
|
+
"\u68C0\u6D4B\u5230 schema \u6F02\u79FB\uFF0C\u53D1\u5E03\u5DF2\u963B\u65AD\uFF08\u4E91\u51FD\u6570\u4F1A\u76F4\u63A5 no such column / \u552F\u4E00\u7EA6\u675F\u7F3A\u5931\u4F1A\u4EA7\u751F\u91CD\u590D\u6570\u636E\uFF09\uFF1A"
|
|
39579
|
+
];
|
|
38889
39580
|
for (const item of drift.missingTables) lines.push(` +table ${item.table}`);
|
|
38890
39581
|
for (const item of drift.missingColumns) {
|
|
38891
39582
|
lines.push(` +column ${item.table}.${item.column.name}`);
|
|
@@ -38895,6 +39586,14 @@ async function checkSchemaDrift(paths, options) {
|
|
|
38895
39586
|
` !type ${item.table}.${item.column}\uFF08\u671F\u671B ${item.expected}\uFF0C\u7EBF\u4E0A ${item.actual}\uFF09`
|
|
38896
39587
|
);
|
|
38897
39588
|
}
|
|
39589
|
+
for (const item of uniqueDiff) {
|
|
39590
|
+
lines.push(
|
|
39591
|
+
` !unique ${item.table}(${item.columns.join(", ")})` + (item.fixable ? "\uFF08adep db migrate \u53EF\u8865\u5EFA\u552F\u4E00\u7D22\u5F15\uFF09" : "\uFF08\u9700\u91CD\u5EFA\u8868\u8865\u552F\u4E00\u7EA6\u675F\uFF09")
|
|
39592
|
+
);
|
|
39593
|
+
}
|
|
39594
|
+
for (const item of blockingNullability) {
|
|
39595
|
+
lines.push(` !null ${item.table}.${item.column}\uFF08schema NOT NULL\uFF0C\u7EBF\u4E0A\u53EF\u7A7A\uFF09`);
|
|
39596
|
+
}
|
|
38898
39597
|
lines.push("\u4E0B\u4E00\u6B65\uFF1Aadep db migrate database/schema.sql");
|
|
38899
39598
|
lines.push(" \u67E5\u770B\u8BA1\u5212\uFF1Aadep db migrate database/schema.sql --plan");
|
|
38900
39599
|
lines.push(" \u5168\u5E93\u6F02\u79FB\u62A5\u544A\uFF1Aadep db doctor");
|
|
@@ -38910,8 +39609,9 @@ async function runPublish(paths, io, cwd, flags) {
|
|
|
38910
39609
|
const wantFrontend = scope === "fullstack" || scope === "frontend";
|
|
38911
39610
|
const environment = flags.environment;
|
|
38912
39611
|
const result = { scope };
|
|
39612
|
+
let schemaGate;
|
|
38913
39613
|
if (wantFunctions) {
|
|
38914
|
-
await checkSchemaDrift(paths, {
|
|
39614
|
+
schemaGate = await checkSchemaDrift(paths, {
|
|
38915
39615
|
cwd,
|
|
38916
39616
|
...flags.project === void 0 ? {} : { slug: flags.project },
|
|
38917
39617
|
log: io.json ? () => void 0 : (line) => io.line(line),
|
|
@@ -38949,19 +39649,26 @@ async function runPublish(paths, io, cwd, flags) {
|
|
|
38949
39649
|
log: (line) => io.line(line)
|
|
38950
39650
|
});
|
|
38951
39651
|
} else {
|
|
38952
|
-
await
|
|
39652
|
+
const prepared = await prepareFrontendDraft(webDir);
|
|
39653
|
+
await assertDraftPublishable(cwd, prepared);
|
|
39654
|
+
await syncPreparedFrontend(paths, {
|
|
38953
39655
|
cwd,
|
|
38954
39656
|
...flags.project === void 0 ? {} : { slug: flags.project },
|
|
38955
39657
|
silent: io.json,
|
|
38956
|
-
log: (line) => io.line(line)
|
|
38957
|
-
|
|
38958
|
-
result.frontend = await publishFrontend(paths, {
|
|
38959
|
-
cwd,
|
|
38960
|
-
...environment === void 0 ? {} : { environment },
|
|
38961
|
-
...flags.project === void 0 ? {} : { slug: flags.project },
|
|
38962
|
-
silent: io.json,
|
|
38963
|
-
log: (line) => io.line(line)
|
|
39658
|
+
log: (line) => io.line(line),
|
|
39659
|
+
prepared
|
|
38964
39660
|
});
|
|
39661
|
+
try {
|
|
39662
|
+
result.frontend = await publishFrontend(paths, {
|
|
39663
|
+
cwd,
|
|
39664
|
+
...environment === void 0 ? {} : { environment },
|
|
39665
|
+
...flags.project === void 0 ? {} : { slug: flags.project },
|
|
39666
|
+
silent: io.json,
|
|
39667
|
+
log: (line) => io.line(line)
|
|
39668
|
+
});
|
|
39669
|
+
} catch (error62) {
|
|
39670
|
+
throw withDraftReplacedNote(error62, prepared);
|
|
39671
|
+
}
|
|
38965
39672
|
}
|
|
38966
39673
|
} else {
|
|
38967
39674
|
result.frontend = await publishFrontend(paths, {
|
|
@@ -38974,9 +39681,60 @@ async function runPublish(paths, io, cwd, flags) {
|
|
|
38974
39681
|
}
|
|
38975
39682
|
}
|
|
38976
39683
|
}
|
|
38977
|
-
return result;
|
|
39684
|
+
return schemaGate === void 0 ? { result } : { result, schemaGate };
|
|
39685
|
+
}
|
|
39686
|
+
function namedList(functions) {
|
|
39687
|
+
return functions.length === 0 ? "" : `\uFF08${functions.map((fn) => fn.name).join("\u3001")}\uFF09`;
|
|
39688
|
+
}
|
|
39689
|
+
function classifyFunctionPublish(functions) {
|
|
39690
|
+
if (functions.length === 0) return "unknown";
|
|
39691
|
+
if (functions.some((fn) => fn.action !== "create")) return "repeat";
|
|
39692
|
+
return functions.every((fn) => fn.version === 1) ? "first" : "unknown";
|
|
39693
|
+
}
|
|
39694
|
+
function describeFrontendPublish(fe) {
|
|
39695
|
+
if (fe.mode === "static") {
|
|
39696
|
+
const via = fe.built === true ? `\u672C\u5730\u6784\u5EFA ${fe.distDir ?? "\u4EA7\u7269"}/ \u2192 \u9759\u6001\u76F4\u901A` : "\u9759\u6001\u76F4\u901A";
|
|
39697
|
+
const files = fe.uploaded === void 0 ? "\u6587\u4EF6\u6570\u672A\u8FD4\u56DE" : `${fe.uploaded} \u4E2A\u6587\u4EF6`;
|
|
39698
|
+
let spa = "\u672A\u8FD4\u56DE";
|
|
39699
|
+
if (fe.spaMode !== void 0) spa = fe.spaMode ? "\u5F00" : "\u5173";
|
|
39700
|
+
return `\u524D\u7AEF\uFF1A${via}\uFF08${files}\uFF0CSPA \u56DE\u9000 ${spa}\uFF09 \xB7 \u7248\u672C/reused \u672A\u8FD4\u56DE\uFF08\u8BE5\u901A\u9053\u4E0D\u4EA7\u751F\u7248\u672C\u53F7\uFF09 \xB7 ${fe.siteUrl}`;
|
|
39701
|
+
}
|
|
39702
|
+
let channel = "\u524D\u7AEF\u53D1\u5E03";
|
|
39703
|
+
if (fe.reused === true) channel = "\u590D\u7528";
|
|
39704
|
+
else if (fe.reused === false) channel = "\u6784\u5EFA\u53D1\u5E03";
|
|
39705
|
+
const version2 = fe.version === void 0 ? "\u7248\u672C\u672A\u8FD4\u56DE" : `v${fe.version}`;
|
|
39706
|
+
const reused = fe.reused === void 0 ? "reused \u672A\u8FD4\u56DE" : `reused=${fe.reused}`;
|
|
39707
|
+
return `\u524D\u7AEF\uFF1A${channel} ${version2}\uFF08${reused}\uFF09 \xB7 ${fe.siteUrl}`;
|
|
38978
39708
|
}
|
|
38979
|
-
function
|
|
39709
|
+
function describeSchemaGate(gate) {
|
|
39710
|
+
switch (gate.status) {
|
|
39711
|
+
case "skipped":
|
|
39712
|
+
return gate.reason === "no-schema" ? "\u6570\u636E\u5E93\uFF1A\u672A\u68C0\u67E5\uFF08\u672A\u627E\u5230 database/schema.sql\uFF09" : "\u6570\u636E\u5E93\uFF1A\u672A\u68C0\u67E5\uFF08\u6570\u636E\u5E93\u5C1A\u672A\u542F\u52A8\uFF09";
|
|
39713
|
+
case "clean":
|
|
39714
|
+
return gate.warnings === 0 ? "\u6570\u636E\u5E93\uFF1A\u65E0\u6F02\u79FB" : `\u6570\u636E\u5E93\uFF1A\u65E0\u963B\u65AD\u6F02\u79FB\uFF08\u8B66\u544A ${gate.warnings} \u5904\uFF09`;
|
|
39715
|
+
case "allowed":
|
|
39716
|
+
return `\u6570\u636E\u5E93\uFF1A\u6F02\u79FB\u5DF2\u7531 --allow-drift \u653E\u884C\uFF08\u963B\u65AD ${gate.blocking} \u5904\uFF09`;
|
|
39717
|
+
}
|
|
39718
|
+
}
|
|
39719
|
+
function renderPublishSummary(result, context) {
|
|
39720
|
+
const lines = [];
|
|
39721
|
+
if (result.functions !== void 0) {
|
|
39722
|
+
const created = result.functions.functions.filter((fn) => fn.action === "create");
|
|
39723
|
+
const updated = result.functions.functions.filter((fn) => fn.action === "publish");
|
|
39724
|
+
const unchanged = result.functions.functions.filter((fn) => fn.action === "none");
|
|
39725
|
+
lines.push(
|
|
39726
|
+
` \u51FD\u6570\uFF1A\u65B0\u589E ${created.length}${namedList(created)} \xB7 \u66F4\u65B0 ${updated.length}${namedList(updated)} \xB7 \u672A\u53D8 ${unchanged.length} \xB7 \u7F51\u5173 ${result.functions.baseUrl}`
|
|
39727
|
+
);
|
|
39728
|
+
}
|
|
39729
|
+
if (result.frontend !== void 0) {
|
|
39730
|
+
lines.push(` ${describeFrontendPublish(result.frontend)}`);
|
|
39731
|
+
}
|
|
39732
|
+
if (context.schemaGate !== void 0) {
|
|
39733
|
+
lines.push(` ${describeSchemaGate(context.schemaGate)}`);
|
|
39734
|
+
}
|
|
39735
|
+
return lines.length === 0 ? [] : ["\u672C\u6B21\u53D1\u5E03\u6458\u8981\uFF1A", ...lines];
|
|
39736
|
+
}
|
|
39737
|
+
function renderPublish(data, context = {}) {
|
|
38980
39738
|
const result = data;
|
|
38981
39739
|
const lines = [];
|
|
38982
39740
|
if (result.functions !== void 0) {
|
|
@@ -39005,14 +39763,26 @@ function renderPublish(data) {
|
|
|
39005
39763
|
lines.push(`\u2713 frontend built ${status} \xB7 ${fe.siteUrl}`);
|
|
39006
39764
|
}
|
|
39007
39765
|
}
|
|
39766
|
+
const summary = renderPublishSummary(result, context);
|
|
39767
|
+
if (summary.length > 0) {
|
|
39768
|
+
lines.push("");
|
|
39769
|
+
lines.push(...summary);
|
|
39770
|
+
}
|
|
39008
39771
|
if (result.functions !== void 0) {
|
|
39772
|
+
const kind = classifyFunctionPublish(result.functions.functions);
|
|
39009
39773
|
lines.push("");
|
|
39010
|
-
|
|
39011
|
-
|
|
39012
|
-
|
|
39013
|
-
|
|
39014
|
-
|
|
39015
|
-
|
|
39774
|
+
if (kind === "first") {
|
|
39775
|
+
lines.push("\u53D1\u5E03\u540E\u4E09\u6B65\uFF08\u9996\u6B21\u53D1\u5E03\u5FC5\u505A\uFF09\uFF1A");
|
|
39776
|
+
lines.push(" 1. adep db start # \u542F\u52A8\u9879\u76EE\u6570\u636E\u5E93\uFF08\u82E5\u5DF2\u542F\u52A8\u8DF3\u8FC7\uFF09");
|
|
39777
|
+
lines.push(
|
|
39778
|
+
" 2. adep db migrate <schema.sql> # \u5EFA\u8868 + \u6267\u884C\u6587\u4EF6\u5185\u5176\u4F59\u8BED\u53E5\uFF08\u7D22\u5F15/\u79CD\u5B50\uFF1B\u91CD\u8DD1\u4F1A\u518D\u6267\u884C\uFF09"
|
|
39779
|
+
);
|
|
39780
|
+
lines.push(" 3. adep db migrate <seed.sql> # \u79CD\u5B50\u5355\u72EC\u6210\u6587\u4EF6\u65F6\uFF08\u53EF\u9009\uFF1B\u79CD\u5B50\u8BF7\u5199\u6210\u5E42\u7B49\u8BED\u53E5\uFF09");
|
|
39781
|
+
} else if (kind === "repeat") {
|
|
39782
|
+
lines.push("\u975E\u9996\u6B21\u53D1\u5E03\uFF08\u670D\u52A1\u7AEF\u8FD4\u56DE\u65E2\u6709\u7248\u672C\uFF09\uFF0C\u8DF3\u8FC7\u300C\u53D1\u5E03\u540E\u4E09\u6B65\u300D\u9996\u6B21\u6E05\u5355\u3002");
|
|
39783
|
+
} else {
|
|
39784
|
+
lines.push("\u65E0\u6CD5\u786E\u8BA4\u662F\u5426\u9996\u6B21\u53D1\u5E03\uFF08\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE\u81EA\u6D3D\u7684\u7248\u672C\u5B57\u6BB5\uFF09\uFF0C\u8DF3\u8FC7\u300C\u53D1\u5E03\u540E\u4E09\u6B65\u300D\u9996\u6B21\u6E05\u5355\u3002");
|
|
39785
|
+
}
|
|
39016
39786
|
}
|
|
39017
39787
|
return lines;
|
|
39018
39788
|
}
|
|
@@ -39031,7 +39801,7 @@ function registerPublish(program2, ctx) {
|
|
|
39031
39801
|
const command = ctx.io("publish");
|
|
39032
39802
|
await command.run(async () => {
|
|
39033
39803
|
const { environment, source } = await ctx.env();
|
|
39034
|
-
const
|
|
39804
|
+
const run = await runPublish(ctx.paths, command, ctx.cwd, {
|
|
39035
39805
|
...flags,
|
|
39036
39806
|
...source === "default" ? {} : { environment }
|
|
39037
39807
|
});
|
|
@@ -39040,7 +39810,10 @@ function registerPublish(program2, ctx) {
|
|
|
39040
39810
|
`\u73AF\u5883\uFF1Adev\uFF08${describeEnvironmentSource(source)}\uFF09\u2014\u2014 \u524D\u7AEF\u53D1\u5230\u5F00\u53D1\u7AD9\u70B9\uFF1B\u4E91\u51FD\u6570\u90E8\u7F72\u4E0D\u53D7\u5F71\u54CD\uFF08\u7EBF\u4E0A\u51FD\u6570\u6052\u8BFB\u751F\u4EA7\u5E93\uFF09`
|
|
39041
39811
|
);
|
|
39042
39812
|
}
|
|
39043
|
-
command.ok(
|
|
39813
|
+
command.ok(
|
|
39814
|
+
run.result,
|
|
39815
|
+
(data) => renderPublish(data, run.schemaGate === void 0 ? {} : { schemaGate: run.schemaGate })
|
|
39816
|
+
);
|
|
39044
39817
|
});
|
|
39045
39818
|
}
|
|
39046
39819
|
);
|
|
@@ -39276,8 +40049,13 @@ function registerExport(program2, ctx) {
|
|
|
39276
40049
|
import { readFile as readFile29 } from "node:fs/promises";
|
|
39277
40050
|
import { resolve as resolve19 } from "node:path";
|
|
39278
40051
|
init_db2();
|
|
39279
|
-
function renderDrift(diff) {
|
|
40052
|
+
function renderDrift(diff, options = {}) {
|
|
39280
40053
|
const lines = [];
|
|
40054
|
+
const missingIndexes = diff.missingIndexes ?? [];
|
|
40055
|
+
const uniqueDiff = diff.uniqueDiff ?? [];
|
|
40056
|
+
const defaultDiff = diff.defaultDiff ?? [];
|
|
40057
|
+
const nullabilityDiff = diff.nullabilityDiff ?? [];
|
|
40058
|
+
const dataStatements = diff.dataStatements ?? [];
|
|
39281
40059
|
for (const table of diff.missingTables) lines.push(`+table ${table.table}`);
|
|
39282
40060
|
for (const column of diff.missingColumns) {
|
|
39283
40061
|
lines.push(
|
|
@@ -39289,6 +40067,30 @@ function renderDrift(diff) {
|
|
|
39289
40067
|
`!type ${mismatch.table}.${mismatch.column} \u7EBF\u4E0A ${mismatch.actual || "(\u65E0\u7C7B\u578B)"} \u2192 schema ${mismatch.expected}`
|
|
39290
40068
|
);
|
|
39291
40069
|
}
|
|
40070
|
+
for (const unique of uniqueDiff) {
|
|
40071
|
+
const columns = unique.columns.length === 0 ? "(\u5217\u672A\u77E5)" : unique.columns.join(", ");
|
|
40072
|
+
const source = unique.source === "index" ? unique.fixable ? "\u552F\u4E00\u7D22\u5F15\u672A\u5EFA\uFF0Cadep db migrate \u53EF\u8865\u5EFA" : "\u540C\u5217\u7D22\u5F15\u5B58\u5728\u4F46\u4E0D\u662F UNIQUE\uFF0C\u9700\u91CD\u5EFA" : "UNIQUE \u7EA6\u675F\u672A\u751F\u6548\uFF0C\u9700\u91CD\u5EFA\u8868\u8865\u7EA6\u675F";
|
|
40073
|
+
lines.push(`!unique ${unique.table}(${columns}) ${source}`);
|
|
40074
|
+
}
|
|
40075
|
+
for (const item of defaultDiff) {
|
|
40076
|
+
lines.push(
|
|
40077
|
+
`!default ${item.table}.${item.column} \u7EBF\u4E0A ${item.actual === null ? "(\u65E0\u9ED8\u8BA4\u503C)" : item.actual} \u2192 schema ${item.expected}\uFF08\u53EA\u8B66\u544A\uFF0C\u4E0D\u963B\u65AD\uFF09`
|
|
40078
|
+
);
|
|
40079
|
+
}
|
|
40080
|
+
for (const item of nullabilityDiff) {
|
|
40081
|
+
const blocking = item.expected === "not-null" && item.actual === "nullable";
|
|
40082
|
+
lines.push(
|
|
40083
|
+
`!null ${item.table}.${item.column} schema ${item.expected === "not-null" ? "NOT NULL" : "\u663E\u5F0F NULL"}\uFF0C\u7EBF\u4E0A ${item.actual === "not-null" ? "NOT NULL" : "\u53EF\u7A7A"}` + (blocking ? "\uFF08\u963B\u65AD\uFF1A\u9700\u91CD\u5EFA\u8868\uFF09" : "\uFF08\u53EA\u8B66\u544A\uFF09")
|
|
40084
|
+
);
|
|
40085
|
+
}
|
|
40086
|
+
for (const index of missingIndexes) {
|
|
40087
|
+
if (index.unique) continue;
|
|
40088
|
+
const columns = index.columns.length === 0 ? "(\u5217\u672A\u77E5)" : index.columns.join(", ");
|
|
40089
|
+
lines.push(`+index ${index.name} ON ${index.table}(${columns})`);
|
|
40090
|
+
if (options.indexStatements === true && index.statement !== void 0) {
|
|
40091
|
+
lines.push(` ${index.statement.replace(/\s+/g, " ").slice(0, 160)}`);
|
|
40092
|
+
}
|
|
40093
|
+
}
|
|
39292
40094
|
for (const table of diff.extraTables)
|
|
39293
40095
|
lines.push(`-table ${table}\uFF08\u7EBF\u4E0A\u6709\u3001schema \u672A\u58F0\u660E\uFF1B\u4E0D\u4F1A\u81EA\u52A8\u5220\u9664\uFF09`);
|
|
39294
40096
|
for (const column of diff.extraColumns) {
|
|
@@ -39297,12 +40099,17 @@ function renderDrift(diff) {
|
|
|
39297
40099
|
for (const statement of diff.destructiveStatements) {
|
|
39298
40100
|
lines.push(`!ddl ${statement.replace(/\s+/g, " ").slice(0, 120)}`);
|
|
39299
40101
|
}
|
|
39300
|
-
const
|
|
39301
|
-
|
|
40102
|
+
const missingIndexStatements = new Set(
|
|
40103
|
+
missingIndexes.map((index) => (index.statement ?? "").trim()).filter((statement) => statement !== "")
|
|
40104
|
+
);
|
|
40105
|
+
const visibleDataStatements = dataStatements.filter(
|
|
40106
|
+
(statement) => !missingIndexStatements.has(statement.trim())
|
|
40107
|
+
);
|
|
40108
|
+
for (const statement of visibleDataStatements) {
|
|
39302
40109
|
lines.push(`!dml ${statement.replace(/\s+/g, " ").slice(0, 120)}`);
|
|
39303
40110
|
}
|
|
39304
40111
|
if (lines.length === 0) return ["\u2713 schema \u4E0E\u7EBF\u4E0A\u4E00\u81F4\uFF0C\u65E0\u6F02\u79FB"];
|
|
39305
|
-
if (
|
|
40112
|
+
if (visibleDataStatements.length > 0) {
|
|
39306
40113
|
lines.push(
|
|
39307
40114
|
"",
|
|
39308
40115
|
"\u63D0\u793A\uFF1A!dml \u8BED\u53E5\uFF08\u7D22\u5F15 / \u79CD\u5B50\u7B49\uFF09\u4F1A\u6309\u58F0\u660E\u987A\u5E8F\u539F\u6837\u6267\u884C\uFF1B\u91CD\u590D\u6267\u884C\u540C\u4E00\u6587\u4EF6\u65F6\u4F1A\u518D\u6B21\u6267\u884C\uFF0C\u79CD\u5B50\u8BF7\u5199\u6210\u5E42\u7B49\u8BED\u53E5\uFF08WHERE NOT EXISTS / INSERT OR IGNORE\uFF09\u3002"
|
|
@@ -39313,6 +40120,25 @@ function renderDrift(diff) {
|
|
|
39313
40120
|
}
|
|
39314
40121
|
return lines;
|
|
39315
40122
|
}
|
|
40123
|
+
function renderTableSchema(schema) {
|
|
40124
|
+
const lines = [`\u8868 ${schema.name}`];
|
|
40125
|
+
for (const col of schema.columns) {
|
|
40126
|
+
lines.push(
|
|
40127
|
+
` ${col.name} ${col.type}${col.primaryKey ? " PRIMARY KEY" : ""}${col.nullable ? "" : " NOT NULL"}`
|
|
40128
|
+
);
|
|
40129
|
+
}
|
|
40130
|
+
if (schema.indexes.length === 0) {
|
|
40131
|
+
lines.push("", "\u7D22\u5F15\uFF1A\uFF08\u65E0\uFF09");
|
|
40132
|
+
} else {
|
|
40133
|
+
lines.push("", "\u7D22\u5F15\uFF1A");
|
|
40134
|
+
for (const index of schema.indexes) {
|
|
40135
|
+
const columns = index.columns.length === 0 ? "(\u5217\u89C1 DDL)" : `(${index.columns.join(", ")})`;
|
|
40136
|
+
lines.push(` ${index.name} ${columns}${index.unique ? " UNIQUE" : ""}`);
|
|
40137
|
+
}
|
|
40138
|
+
}
|
|
40139
|
+
if (schema.ddl !== null) lines.push("", schema.ddl);
|
|
40140
|
+
return lines;
|
|
40141
|
+
}
|
|
39316
40142
|
function registerDb(program2, ctx) {
|
|
39317
40143
|
const db = program2.command("db").description("\u9879\u76EE\u6570\u636E\u5E93\u7EF4\u62A4\uFF1A\u542F\u52A8 / \u72B6\u6001 / \u505C\u6B62 / SQL / \u5FEB\u7167 / \u56DE\u6EDA");
|
|
39318
40144
|
db.command("start").description("\u542F\u52A8\u9879\u76EE\u6570\u636E\u5E93\uFF08\u5DF2\u5B58\u5728\u5219\u91CD\u65B0\u6FC0\u6D3B\uFF0C\u4E0D\u91CD\u5EFA\u6570\u636E\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (flags) => {
|
|
@@ -39438,14 +40264,7 @@ function registerDb(program2, ctx) {
|
|
|
39438
40264
|
command.ok(result, (data) => {
|
|
39439
40265
|
const r = data;
|
|
39440
40266
|
if ("columns" in r) {
|
|
39441
|
-
|
|
39442
|
-
for (const col of r.columns) {
|
|
39443
|
-
lines.push(
|
|
39444
|
-
` ${col.name} ${col.type}${col.primaryKey ? " PRIMARY KEY" : ""}${col.nullable ? "" : " NOT NULL"}`
|
|
39445
|
-
);
|
|
39446
|
-
}
|
|
39447
|
-
if (r.ddl !== null) lines.push("", r.ddl);
|
|
39448
|
-
return lines;
|
|
40267
|
+
return renderTableSchema(r);
|
|
39449
40268
|
}
|
|
39450
40269
|
if (r.tables.length === 0) {
|
|
39451
40270
|
return `\uFF08${environment} \u5E93\u91CC\u6CA1\u6709\u8868\uFF09`;
|
|
@@ -39458,53 +40277,73 @@ function registerDb(program2, ctx) {
|
|
|
39458
40277
|
});
|
|
39459
40278
|
});
|
|
39460
40279
|
db.command("migrate").description(
|
|
39461
|
-
"\u6267\u884C SQL \u8FC1\u79FB\u6587\u4EF6\uFF08\u589E\u91CF\u8BED\u4E49\uFF09\uFF1A\u7F3A\u8868\u5EFA\u8868\u3001\u65E2\u6709\u8868\u7F3A\u5217\u81EA\u52A8 ADD COLUMN\uFF1BINDEX / INSERT / UPDATE \u7B49\u5176\u4F59\u8BED\u53E5\u6309\u58F0\u660E\u987A\u5E8F\u539F\u6837\u6267\u884C\uFF08\u6BCF\u6B21\u90FD\u4F1A\u91CD\u8DD1\uFF0C\u79CD\u5B50\u8BF7\u5199\u6210\u5E42\u7B49\u8BED\u53E5\uFF09\uFF1B\u5220\u5217/\u6539\u7C7B\u578B/\u91CD\u547D\u540D\u62D2\u7EDD\u81EA\u52A8\u6267\u884C\u3002\u53EF\u591A\u4E2A\u6587\u4EF6\uFF0C\u6309\u58F0\u660E\u987A\u5E8F\u6267\u884C\uFF0C\u5931\u8D25\u5373\u505C"
|
|
39462
|
-
).argument("<files...>", "\u8FC1\u79FB SQL \u6587\u4EF6\u8DEF\u5F84\uFF08\u76F8\u5BF9\u5F53\u524D\u76EE\u5F55\u6216\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u6309\u58F0\u660E\u987A\u5E8F\u6267\u884C\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").option(
|
|
39463
|
-
|
|
39464
|
-
|
|
39465
|
-
|
|
39466
|
-
|
|
39467
|
-
|
|
39468
|
-
|
|
39469
|
-
|
|
39470
|
-
|
|
39471
|
-
|
|
39472
|
-
|
|
39473
|
-
|
|
39474
|
-
|
|
39475
|
-
|
|
39476
|
-
);
|
|
39477
|
-
if (result.failed !== void 0) {
|
|
39478
|
-
const f = result.failed;
|
|
39479
|
-
const nextStep = f.code === "DB_NOT_PROVISIONED" ? "\n\u4E0B\u4E00\u6B65\uFF1Aadep db start\uFF08\u542F\u52A8\u9879\u76EE\u6570\u636E\u5E93\uFF1B--env dev \u9700\u5148\u89E6\u53D1\u4E00\u6B21\u51FD\u6570\u8C03\u8BD5\u4EE5\u521D\u59CB\u5316\u5F00\u53D1\u5E93\uFF09" : "";
|
|
39480
|
-
command.fail(f.code, `\u6587\u4EF6 ${f.file} \u8FC1\u79FB\u5931\u8D25\uFF1A${f.message}${nextStep}`);
|
|
39481
|
-
return;
|
|
39482
|
-
}
|
|
39483
|
-
command.ok(result, (data) => {
|
|
39484
|
-
const r = data;
|
|
39485
|
-
const lines = renderDrift(
|
|
39486
|
-
r.drift ?? {
|
|
39487
|
-
missingTables: [],
|
|
39488
|
-
missingColumns: [],
|
|
39489
|
-
typeMismatches: [],
|
|
39490
|
-
extraTables: [],
|
|
39491
|
-
extraColumns: [],
|
|
39492
|
-
destructiveStatements: [],
|
|
39493
|
-
dataStatements: [],
|
|
39494
|
-
applicable: true
|
|
39495
|
-
}
|
|
39496
|
-
);
|
|
39497
|
-
if (flags.plan === true) return lines;
|
|
39498
|
-
lines.push(
|
|
39499
|
-
`\u2713 \u8FC1\u79FB\u5B8C\u6210\uFF1A\u65B0\u5EFA\u8868 ${r.createdTables}\uFF0C\u65B0\u589E\u5217 ${r.addedColumns}\uFF0C\u5DF2\u5B58\u5728\u8DF3\u8FC7 ${r.skippedTables}\uFF08\u5171\u6267\u884C ${r.applied.length} \u6761\u8BED\u53E5\uFF09`
|
|
40280
|
+
"\u6267\u884C SQL \u8FC1\u79FB\u6587\u4EF6\uFF08\u589E\u91CF\u8BED\u4E49\uFF09\uFF1A\u7F3A\u8868\u5EFA\u8868\u3001\u65E2\u6709\u8868\u7F3A\u5217\u81EA\u52A8 ADD COLUMN\uFF1BINDEX / INSERT / UPDATE \u7B49\u5176\u4F59\u8BED\u53E5\u6309\u58F0\u660E\u987A\u5E8F\u539F\u6837\u6267\u884C\uFF08\u6BCF\u6B21\u90FD\u4F1A\u91CD\u8DD1\uFF0C\u79CD\u5B50\u8BF7\u5199\u6210\u5E42\u7B49\u8BED\u53E5\uFF09\uFF1B\u5220\u5217/\u6539\u7C7B\u578B/\u91CD\u547D\u540D\u62D2\u7EDD\u81EA\u52A8\u6267\u884C\u3002\u53EF\u591A\u4E2A\u6587\u4EF6\uFF0C\u6309\u58F0\u660E\u987A\u5E8F\u6267\u884C\uFF0C\u5931\u8D25\u5373\u505C\u3002\u751F\u4EA7\u5E93\uFF08\u542B\u7F3A\u7701\u73AF\u5883\uFF09\u6267\u884C\u9700 --confirm-db <project-slug> \u4E8C\u6B21\u786E\u8BA4\u2014\u2014\u5148 --plan \u770B\u5BF9\u8C61\u6E05\u5355"
|
|
40281
|
+
).argument("<files...>", "\u8FC1\u79FB SQL \u6587\u4EF6\u8DEF\u5F84\uFF08\u76F8\u5BF9\u5F53\u524D\u76EE\u5F55\u6216\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u6309\u58F0\u660E\u987A\u5E8F\u6267\u884C\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").option(
|
|
40282
|
+
"--plan",
|
|
40283
|
+
"\u53EA\u8F93\u51FA\u8BA1\u5212\uFF08+table / +column / !type / +index / !unique / !default / !null / !dml\uFF09\uFF0C\u4E0D\u6267\u884C\u4EFB\u4F55\u8BED\u53E5"
|
|
40284
|
+
).option(
|
|
40285
|
+
"--confirm-db <project-slug>",
|
|
40286
|
+
"\u751F\u4EA7\u8FC1\u79FB\u4E8C\u6B21\u786E\u8BA4\uFF1A\u503C\u5FC5\u987B\u4E0E\u76EE\u6807\u9879\u76EE slug \u5B8C\u5168\u4E00\u81F4\uFF08dev \u4E0E --plan \u4E0D\u9700\u8981\uFF09"
|
|
40287
|
+
).action(
|
|
40288
|
+
async (files, flags) => {
|
|
40289
|
+
const command = ctx.io("db migrate");
|
|
40290
|
+
await command.run(async () => {
|
|
40291
|
+
const { environment, source } = await ctx.env();
|
|
40292
|
+
const { dbMigrate: dbMigrate2 } = await Promise.resolve().then(() => (init_db2(), db_exports));
|
|
40293
|
+
command.line(
|
|
40294
|
+
`\u73AF\u5883\uFF1A${environment}\uFF08${describeEnvironmentSource(source)}\uFF09\u2014\u2014 \u8FC1\u79FB\u5C06\u4F5C\u7528\u5230${environment === "dev" ? "\u5F00\u53D1\u5E93" : "\u751F\u4EA7\u5E93"}`
|
|
39500
40295
|
);
|
|
39501
|
-
|
|
40296
|
+
const printsPreflight = flags.plan !== true && environment === "prod" && !command.json;
|
|
40297
|
+
const result = await dbMigrate2(ctx.paths, {
|
|
40298
|
+
cwd: ctx.cwd,
|
|
40299
|
+
files,
|
|
40300
|
+
environment,
|
|
40301
|
+
...flags.project === void 0 ? {} : { slug: flags.project },
|
|
40302
|
+
...flags.plan === true ? { plan: true } : {},
|
|
40303
|
+
...flags.confirmDb === void 0 ? {} : { confirmDb: flags.confirmDb },
|
|
40304
|
+
...printsPreflight ? {
|
|
40305
|
+
onPlan: (diff, file2) => {
|
|
40306
|
+
command.line(`\u5C06\u8981\u6267\u884C\u7684\u5BF9\u8C61\uFF08${file2}\uFF09\uFF1A`);
|
|
40307
|
+
for (const line of renderDrift(diff, { indexStatements: true }))
|
|
40308
|
+
command.line(line);
|
|
40309
|
+
}
|
|
40310
|
+
} : {}
|
|
40311
|
+
});
|
|
40312
|
+
if (result.failed !== void 0) {
|
|
40313
|
+
const f = result.failed;
|
|
40314
|
+
const nextStep = f.code === "DB_NOT_PROVISIONED" ? "\n\u4E0B\u4E00\u6B65\uFF1Aadep db start\uFF08\u542F\u52A8\u9879\u76EE\u6570\u636E\u5E93\uFF1B--env dev \u9700\u5148\u89E6\u53D1\u4E00\u6B21\u51FD\u6570\u8C03\u8BD5\u4EE5\u521D\u59CB\u5316\u5F00\u53D1\u5E93\uFF09" : "";
|
|
40315
|
+
command.fail(f.code, `\u6587\u4EF6 ${f.file} \u8FC1\u79FB\u5931\u8D25\uFF1A${f.message}${nextStep}`);
|
|
40316
|
+
return;
|
|
40317
|
+
}
|
|
40318
|
+
command.ok(result, (data) => {
|
|
40319
|
+
const r = data;
|
|
40320
|
+
const summary = `\u2713 \u8FC1\u79FB\u5B8C\u6210\uFF1A\u65B0\u5EFA\u8868 ${r.createdTables}\uFF0C\u65B0\u589E\u5217 ${r.addedColumns}\uFF0C\u5DF2\u5B58\u5728\u8DF3\u8FC7 ${r.skippedTables}\uFF08\u5171\u6267\u884C ${r.applied.length} \u6761\u8BED\u53E5\uFF09`;
|
|
40321
|
+
if (printsPreflight) return [summary];
|
|
40322
|
+
const lines = renderDrift(
|
|
40323
|
+
r.drift ?? {
|
|
40324
|
+
dbEnvironment: environment,
|
|
40325
|
+
missingTables: [],
|
|
40326
|
+
missingColumns: [],
|
|
40327
|
+
typeMismatches: [],
|
|
40328
|
+
extraTables: [],
|
|
40329
|
+
extraColumns: [],
|
|
40330
|
+
destructiveStatements: [],
|
|
40331
|
+
dataStatements: [],
|
|
40332
|
+
applicable: true
|
|
40333
|
+
},
|
|
40334
|
+
// 计划必须与「实际会执行的索引语句」对得上:缺失索引逐条列出并附语句原文。
|
|
40335
|
+
{ indexStatements: true }
|
|
40336
|
+
);
|
|
40337
|
+
if (flags.plan === true) return lines;
|
|
40338
|
+
lines.push(summary);
|
|
40339
|
+
return lines;
|
|
40340
|
+
});
|
|
39502
40341
|
});
|
|
39503
|
-
}
|
|
39504
|
-
|
|
40342
|
+
}
|
|
40343
|
+
);
|
|
39505
40344
|
db.command("doctor").description(
|
|
39506
|
-
"\u5168\u5E93 schema \u6F02\u79FB\u62A5\u544A\uFF1A\u5BF9\u6BD4 schema.sql \u4E0E\u7EBF\u4E0A\u76EE\u5F55\uFF08\u7F3A\u8868 / \u7F3A\u5217 / \u7C7B\u578B\
|
|
39507
|
-
).argument("[schema]", "schema.sql \u8DEF\u5F84", "database/schema.sql").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (schema, flags) => {
|
|
40345
|
+
"\u5168\u5E93 schema \u6F02\u79FB\u62A5\u544A\uFF1A\u5BF9\u6BD4 schema.sql \u4E0E\u7EBF\u4E0A\u76EE\u5F55\uFF08\u7F3A\u8868 / \u7F3A\u5217 / \u7C7B\u578B / \u552F\u4E00\u7EA6\u675F / \u9ED8\u8BA4\u503C / \u53EF\u7A7A\u6027 / \u7D22\u5F15\uFF09\u3002\u53D7\u5168\u5C40 --env \u5F71\u54CD\uFF1B\u5B58\u5728\u963B\u65AD\u9879\u65F6\u9000\u51FA\u7801\u975E 0"
|
|
40346
|
+
).argument("[schema]", "schema.sql \u8DEF\u5F84", "database/schema.sql").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").option("--verbose", "\u7D22\u5F15\u5C42\u660E\u7EC6\uFF1A\u7F3A\u5931\u7D22\u5F15\u9644\u5B8C\u6574 CREATE INDEX \u8BED\u53E5").action(async (schema, flags) => {
|
|
39508
40347
|
const command = ctx.io("db doctor");
|
|
39509
40348
|
await command.run(async () => {
|
|
39510
40349
|
const { environment, source } = await ctx.env();
|
|
@@ -39519,15 +40358,16 @@ function registerDb(program2, ctx) {
|
|
|
39519
40358
|
command.line(
|
|
39520
40359
|
`\u73AF\u5883\uFF1A${environment}\uFF08${describeEnvironmentSource(source)}\uFF09\u2014\u2014 \u68C0\u67E5\u7684\u662F${environment === "dev" ? "\u5F00\u53D1\u5E93" : "\u751F\u4EA7\u5E93"}`
|
|
39521
40360
|
);
|
|
39522
|
-
|
|
40361
|
+
const blocking = diff.blocking === true || !diff.applicable;
|
|
40362
|
+
if (blocking) {
|
|
39523
40363
|
command.fail(
|
|
39524
40364
|
"SCHEMA_DRIFT",
|
|
39525
|
-
`\u68C0\u6D4B\u5230\
|
|
39526
|
-
${renderDrift(diff).join("\n")}`
|
|
40365
|
+
`\u68C0\u6D4B\u5230\u963B\u65AD\u53D1\u5E03\u7684\u6F02\u79FB\uFF08${schema}\uFF09\uFF1A
|
|
40366
|
+
${renderDrift(diff, { indexStatements: true }).join("\n")}`
|
|
39527
40367
|
);
|
|
39528
40368
|
return;
|
|
39529
40369
|
}
|
|
39530
|
-
command.ok(diff, () => renderDrift(diff));
|
|
40370
|
+
command.ok(diff, () => renderDrift(diff, { indexStatements: flags.verbose === true }));
|
|
39531
40371
|
});
|
|
39532
40372
|
});
|
|
39533
40373
|
const snapshot = db.command("snapshot").description("\u6570\u636E\u5E93\u5FEB\u7167\uFF08\u4ED8\u8D39\u6863\u4F4D\uFF09\uFF1A\u5217\u51FA\uFF08\u7F3A\u7701\uFF09/ \u521B\u5EFA / \u8FD8\u539F");
|