@adep/cli 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/index.js +5081 -2694
- package/dist/vite.js +149 -88
- package/dist/worker-entry.js +19 -12
- package/package.json +5 -5
package/dist/vite.js
CHANGED
|
@@ -4,8 +4,8 @@ import { adepPlugin } from "@adep/vite-plugin";
|
|
|
4
4
|
// packages/cli/src/dev.ts
|
|
5
5
|
import { createServer } from "node:http";
|
|
6
6
|
import { watch } from "node:fs";
|
|
7
|
-
import { mkdir as mkdir3,
|
|
8
|
-
import { basename, join as
|
|
7
|
+
import { mkdir as mkdir3, readFile as readFile6, writeFile as writeFile3 } from "node:fs/promises";
|
|
8
|
+
import { basename, join as join9, resolve as resolve2 } from "node:path";
|
|
9
9
|
|
|
10
10
|
// packages/runtime/src/shared/capability-keys.ts
|
|
11
11
|
var RPC_CAPABILITY_KEY = "__adepRpc";
|
|
@@ -1106,7 +1106,7 @@ function createDbCapability(driver, options = {}) {
|
|
|
1106
1106
|
};
|
|
1107
1107
|
}
|
|
1108
1108
|
|
|
1109
|
-
// packages/
|
|
1109
|
+
// packages/runtime/src/sim/sql-engine.ts
|
|
1110
1110
|
var SimDbError = class extends Error {
|
|
1111
1111
|
constructor(code, message) {
|
|
1112
1112
|
super(message);
|
|
@@ -1146,7 +1146,7 @@ function parseCreateTable(ddl) {
|
|
|
1146
1146
|
);
|
|
1147
1147
|
if (m === null) return null;
|
|
1148
1148
|
const name = ident(m[1]);
|
|
1149
|
-
const body = m[
|
|
1149
|
+
const body = m[3];
|
|
1150
1150
|
const columns = [];
|
|
1151
1151
|
for (const part of body.split(",")) {
|
|
1152
1152
|
const tokens = part.trim().split(/\s+/);
|
|
@@ -1236,9 +1236,9 @@ function matchValue(value, clause) {
|
|
|
1236
1236
|
const right = clause.value;
|
|
1237
1237
|
switch (op) {
|
|
1238
1238
|
case "=":
|
|
1239
|
-
return left === right;
|
|
1239
|
+
return left !== null && right !== null && left === right;
|
|
1240
1240
|
case "!=":
|
|
1241
|
-
return left !== right;
|
|
1241
|
+
return left !== null && right !== null && left !== right;
|
|
1242
1242
|
case ">":
|
|
1243
1243
|
return left !== null && right !== null && left > right;
|
|
1244
1244
|
case ">=":
|
|
@@ -1348,6 +1348,17 @@ var SimSqlEngine = class {
|
|
|
1348
1348
|
}
|
|
1349
1349
|
return { changes: 0 };
|
|
1350
1350
|
}
|
|
1351
|
+
if (/^CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?/i.test(stmt)) {
|
|
1352
|
+
const idx = /^CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?((?:"[^"]+")|([A-Za-z_][A-Za-z0-9_]*))\s+ON\s+((?:"[^"]+")|([A-Za-z_][A-Za-z0-9_]*))/i.exec(
|
|
1353
|
+
stmt
|
|
1354
|
+
);
|
|
1355
|
+
if (idx === null) throw new SimDbError("DB_UNSAFE_OP", `\u65E0\u6CD5\u89E3\u6790 CREATE INDEX \u8BED\u53E5`);
|
|
1356
|
+
const tableName = ident(idx[3]);
|
|
1357
|
+
if (this.tables[tableName] === void 0) {
|
|
1358
|
+
throw new SimDbError("DB_UNSAFE_OP", `CREATE INDEX \u76EE\u6807\u8868\u4E0D\u5B58\u5728\uFF1A${tableName}`);
|
|
1359
|
+
}
|
|
1360
|
+
return { changes: 0 };
|
|
1361
|
+
}
|
|
1351
1362
|
if (/^INSERT\s+INTO/i.test(stmt)) return this.execInsert(stmt, params);
|
|
1352
1363
|
if (/^UPDATE\s+/i.test(stmt)) return this.execUpdate(stmt, params);
|
|
1353
1364
|
if (/^DELETE\s+FROM/i.test(stmt)) return this.execDelete(stmt, params);
|
|
@@ -1687,6 +1698,19 @@ function assertSafeStoragePath(path) {
|
|
|
1687
1698
|
}
|
|
1688
1699
|
return path;
|
|
1689
1700
|
}
|
|
1701
|
+
function assertStoragePrefix(prefix) {
|
|
1702
|
+
if (prefix !== void 0 && prefix !== "") {
|
|
1703
|
+
const segments = prefix.split("/");
|
|
1704
|
+
if (prefix.startsWith("/") || /[\\]/.test(prefix) || segments.some((segment) => segment === "..")) {
|
|
1705
|
+
throw new StorageError(
|
|
1706
|
+
400,
|
|
1707
|
+
STORAGE_CODES.invalidPath,
|
|
1708
|
+
`\u975E\u6CD5\u524D\u7F00 "${prefix}"\uFF08\u7981\u6B62 / \u5F00\u5934\u3001\u53CD\u659C\u6760\u6216 .. \u7A7F\u8D8A\uFF09`
|
|
1709
|
+
);
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
return prefix ?? "";
|
|
1713
|
+
}
|
|
1690
1714
|
|
|
1691
1715
|
// packages/runtime/src/storage/hmac-sha256.ts
|
|
1692
1716
|
var K = new Uint32Array([
|
|
@@ -2070,16 +2094,7 @@ function createLocalStorageDriver(options) {
|
|
|
2070
2094
|
await unlink(metaPath(projectId, path)).catch(() => void 0);
|
|
2071
2095
|
},
|
|
2072
2096
|
async list(projectId, prefix) {
|
|
2073
|
-
|
|
2074
|
-
const segments = prefix.split("/");
|
|
2075
|
-
if (prefix.startsWith("/") || /[\\]/.test(prefix) || segments.some((segment) => segment === "..")) {
|
|
2076
|
-
throw new StorageError(
|
|
2077
|
-
400,
|
|
2078
|
-
STORAGE_CODES.invalidPath,
|
|
2079
|
-
`\u975E\u6CD5\u524D\u7F00 "${prefix}"\uFF08\u7981\u6B62 / \u5F00\u5934\u3001\u53CD\u659C\u6760\u6216 .. \u7A7F\u8D8A\uFF09`
|
|
2080
|
-
);
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2097
|
+
assertStoragePrefix(prefix);
|
|
2083
2098
|
const root = bucketDir(projectId);
|
|
2084
2099
|
const metas = [];
|
|
2085
2100
|
const walk = async (dir, relative) => {
|
|
@@ -2145,7 +2160,7 @@ function createSimStorageCapability(options) {
|
|
|
2145
2160
|
return { bundle, driver };
|
|
2146
2161
|
}
|
|
2147
2162
|
|
|
2148
|
-
// packages/
|
|
2163
|
+
// packages/runtime/src/sim/realtime.ts
|
|
2149
2164
|
var SimRealtime = class {
|
|
2150
2165
|
seq = 0;
|
|
2151
2166
|
subscribers = /* @__PURE__ */ new Map();
|
|
@@ -2267,10 +2282,7 @@ function createSimRealtimeCapability() {
|
|
|
2267
2282
|
};
|
|
2268
2283
|
}
|
|
2269
2284
|
|
|
2270
|
-
// packages/
|
|
2271
|
-
function simDir(cwd) {
|
|
2272
|
-
return join4(cwd, ".adep", "sim");
|
|
2273
|
-
}
|
|
2285
|
+
// packages/runtime/src/sim/merge.ts
|
|
2274
2286
|
function mergeBundles(bundles) {
|
|
2275
2287
|
const capabilities = [];
|
|
2276
2288
|
const byName = /* @__PURE__ */ new Map();
|
|
@@ -2290,6 +2302,11 @@ function mergeBundles(bundles) {
|
|
|
2290
2302
|
}
|
|
2291
2303
|
return { capabilities, rpcHandlers };
|
|
2292
2304
|
}
|
|
2305
|
+
|
|
2306
|
+
// packages/cli/src/sim/runtime.ts
|
|
2307
|
+
function simDir(cwd) {
|
|
2308
|
+
return join4(cwd, ".adep", "sim");
|
|
2309
|
+
}
|
|
2293
2310
|
function jsonStorage(cwd) {
|
|
2294
2311
|
const file = join4(simDir(cwd), "db.json");
|
|
2295
2312
|
return {
|
|
@@ -2405,12 +2422,21 @@ function createSimInvokeHandler(options) {
|
|
|
2405
2422
|
};
|
|
2406
2423
|
}
|
|
2407
2424
|
|
|
2408
|
-
//
|
|
2409
|
-
var
|
|
2410
|
-
var
|
|
2411
|
-
|
|
2412
|
-
|
|
2425
|
+
// shared/builtin-deps.ts
|
|
2426
|
+
var CF_COMPAT_SPECIFIER = "@adep/cf-compat";
|
|
2427
|
+
var STATE_OBJECTS_SPECIFIER = "@adep/runtime/state-objects";
|
|
2428
|
+
var BUILTIN_DEPS = [
|
|
2429
|
+
CF_COMPAT_SPECIFIER,
|
|
2430
|
+
STATE_OBJECTS_SPECIFIER,
|
|
2431
|
+
"axios",
|
|
2432
|
+
"lodash",
|
|
2433
|
+
"dayjs",
|
|
2434
|
+
"zod"
|
|
2413
2435
|
];
|
|
2436
|
+
var BUILTIN_DEPS_CSV = BUILTIN_DEPS.join(",");
|
|
2437
|
+
|
|
2438
|
+
// packages/cli/src/builtin-deps.ts
|
|
2439
|
+
var LOCAL_BUILTIN_DEPS = [CF_COMPAT_SPECIFIER, STATE_OBJECTS_SPECIFIER];
|
|
2414
2440
|
|
|
2415
2441
|
// packages/cli/src/sim/boundary.ts
|
|
2416
2442
|
var SIM_BOUNDARIES = [
|
|
@@ -3046,9 +3072,9 @@ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare) {
|
|
|
3046
3072
|
|
|
3047
3073
|
// packages/runtime/src/state-objects/loader.ts
|
|
3048
3074
|
var STATE_OBJECTS_ENTRY = "state-objects.ts";
|
|
3049
|
-
var
|
|
3075
|
+
var STATE_OBJECTS_SPECIFIER2 = "@adep/runtime/state-objects";
|
|
3050
3076
|
function resolveStateObjectSpecifier(request) {
|
|
3051
|
-
if (request ===
|
|
3077
|
+
if (request === STATE_OBJECTS_SPECIFIER2) return { StateObject };
|
|
3052
3078
|
return void 0;
|
|
3053
3079
|
}
|
|
3054
3080
|
function defaultStateSandboxGlobals() {
|
|
@@ -3370,6 +3396,19 @@ function createSandboxFetch(options) {
|
|
|
3370
3396
|
};
|
|
3371
3397
|
}
|
|
3372
3398
|
|
|
3399
|
+
// packages/runtime/src/functions/runtime/rpc-wire.ts
|
|
3400
|
+
function wireRpcResponses(port, pending) {
|
|
3401
|
+
port.on?.((message) => {
|
|
3402
|
+
const reply = message;
|
|
3403
|
+
if (reply?.type !== "rpc-response" || typeof reply.id !== "number") return;
|
|
3404
|
+
const entry = pending.get(reply.id);
|
|
3405
|
+
if (entry === void 0) return;
|
|
3406
|
+
pending.delete(reply.id);
|
|
3407
|
+
if (reply.ok === true) entry.resolve(reply.result);
|
|
3408
|
+
else entry.reject(new Error(reply.error ?? "RPC \u80FD\u529B\u8C03\u7528\u5931\u8D25"));
|
|
3409
|
+
});
|
|
3410
|
+
}
|
|
3411
|
+
|
|
3373
3412
|
// packages/runtime/src/functions/runtime/chain.ts
|
|
3374
3413
|
function isChainCapability(value) {
|
|
3375
3414
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -3441,6 +3480,11 @@ function createChainClient(capability, port, pending, nextId, spec) {
|
|
|
3441
3480
|
return makeRoot(void 0);
|
|
3442
3481
|
}
|
|
3443
3482
|
|
|
3483
|
+
// packages/runtime/src/shared/regexp.ts
|
|
3484
|
+
function escapeRegExp(text) {
|
|
3485
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3486
|
+
}
|
|
3487
|
+
|
|
3444
3488
|
// packages/runtime/src/functions/runtime/worker-entry.ts
|
|
3445
3489
|
function isRpcCapability(value) {
|
|
3446
3490
|
return typeof value === "object" && value !== null && value[RPC_CAPABILITY_KEY] === true;
|
|
@@ -3470,9 +3514,6 @@ function errorMessageOf2(error) {
|
|
|
3470
3514
|
}
|
|
3471
3515
|
return String(error);
|
|
3472
3516
|
}
|
|
3473
|
-
function escapeRegExp(text) {
|
|
3474
|
-
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3475
|
-
}
|
|
3476
3517
|
function firstUserFrame(stack, files) {
|
|
3477
3518
|
for (const key of Object.keys(files)) {
|
|
3478
3519
|
const match = new RegExp(
|
|
@@ -3531,15 +3572,7 @@ function runWorker(input, port) {
|
|
|
3531
3572
|
const container = createCloudContainer();
|
|
3532
3573
|
const pending = /* @__PURE__ */ new Map();
|
|
3533
3574
|
let rpcId = 0;
|
|
3534
|
-
port
|
|
3535
|
-
const reply = message;
|
|
3536
|
-
if (reply?.type !== "rpc-response" || typeof reply.id !== "number") return;
|
|
3537
|
-
const entry = pending.get(reply.id);
|
|
3538
|
-
if (entry === void 0) return;
|
|
3539
|
-
pending.delete(reply.id);
|
|
3540
|
-
if (reply.ok === true) entry.resolve(reply.result);
|
|
3541
|
-
else entry.reject(new Error(reply.error ?? "RPC \u80FD\u529B\u8C03\u7528\u5931\u8D25"));
|
|
3542
|
-
});
|
|
3575
|
+
wireRpcResponses(port, pending);
|
|
3543
3576
|
for (const capability of input.capabilities ?? []) {
|
|
3544
3577
|
container.register(
|
|
3545
3578
|
capability.name,
|
|
@@ -3645,30 +3678,36 @@ if (workerPort !== null && workerData !== void 0) {
|
|
|
3645
3678
|
runWorker(workerData, port);
|
|
3646
3679
|
}
|
|
3647
3680
|
|
|
3648
|
-
// packages/cli/src/dev.ts
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3681
|
+
// packages/cli/src/dev-shared.ts
|
|
3682
|
+
import { readdir as readdir2, readFile as readFile5 } from "node:fs/promises";
|
|
3683
|
+
import { join as join8 } from "node:path";
|
|
3684
|
+
var BEARER_TOKEN_RE = /^Bearer\s+(.+)$/i;
|
|
3685
|
+
function bearerUserResolverFromEnv() {
|
|
3686
|
+
const raw = process.env.ADEP_AUTH_ISSUER;
|
|
3687
|
+
if (raw === void 0 || raw.trim() === "") return void 0;
|
|
3688
|
+
return createBearerUserResolver(raw.trim());
|
|
3689
|
+
}
|
|
3690
|
+
function createBearerUserResolver(issuer) {
|
|
3691
|
+
const userinfoUrl = `${issuer.replace(/\/+$/, "")}/oauth/userinfo`;
|
|
3692
|
+
return async (headers) => {
|
|
3693
|
+
const match = BEARER_TOKEN_RE.exec((headers["authorization"] ?? "").trim());
|
|
3694
|
+
const token = match?.[1]?.trim();
|
|
3695
|
+
if (token === void 0 || token === "") return null;
|
|
3696
|
+
try {
|
|
3697
|
+
const res = await fetch(userinfoUrl, { headers: { authorization: `Bearer ${token}` } });
|
|
3698
|
+
if (!res.ok) return null;
|
|
3699
|
+
const claims = await res.json();
|
|
3700
|
+
if (typeof claims.sub !== "string" || claims.sub.length === 0) return null;
|
|
3701
|
+
return {
|
|
3702
|
+
id: claims.sub,
|
|
3703
|
+
...typeof claims.name === "string" ? { name: claims.name } : {},
|
|
3704
|
+
...typeof claims.email === "string" ? { email: claims.email } : {}
|
|
3705
|
+
};
|
|
3706
|
+
} catch {
|
|
3707
|
+
return null;
|
|
3708
|
+
}
|
|
3657
3709
|
};
|
|
3658
3710
|
}
|
|
3659
|
-
function parseEnvFile(content) {
|
|
3660
|
-
const env = {};
|
|
3661
|
-
for (const raw of content.split(/\r?\n/)) {
|
|
3662
|
-
const line = raw.trim();
|
|
3663
|
-
if (line.length === 0 || line.startsWith("#")) continue;
|
|
3664
|
-
const eq = line.indexOf("=");
|
|
3665
|
-
if (eq === -1) continue;
|
|
3666
|
-
const key = line.slice(0, eq).trim();
|
|
3667
|
-
if (key.length === 0) continue;
|
|
3668
|
-
env[key] = line.slice(eq + 1).trim();
|
|
3669
|
-
}
|
|
3670
|
-
return env;
|
|
3671
|
-
}
|
|
3672
3711
|
async function collectFunctions(dir) {
|
|
3673
3712
|
const files = {};
|
|
3674
3713
|
const walk = async (sub, prefix) => {
|
|
@@ -3710,6 +3749,42 @@ function bodyOf(req) {
|
|
|
3710
3749
|
req.on("error", rejectBody);
|
|
3711
3750
|
});
|
|
3712
3751
|
}
|
|
3752
|
+
function writeJson(res, status, payload) {
|
|
3753
|
+
res.writeHead(status, { "content-type": "application/json" });
|
|
3754
|
+
res.end(JSON.stringify(payload));
|
|
3755
|
+
}
|
|
3756
|
+
async function requestInput(url, req, readBody) {
|
|
3757
|
+
const query = {};
|
|
3758
|
+
for (const key of new Set(url.searchParams.keys())) {
|
|
3759
|
+
const values = url.searchParams.getAll(key);
|
|
3760
|
+
query[key] = values.length > 1 ? values.join(",") : values[0] ?? "";
|
|
3761
|
+
}
|
|
3762
|
+
const headers = {};
|
|
3763
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
3764
|
+
if (typeof value === "string") headers[key] = value;
|
|
3765
|
+
}
|
|
3766
|
+
const body = req.method === "GET" || req.method === "HEAD" ? void 0 : await readBody(req);
|
|
3767
|
+
return {
|
|
3768
|
+
method: req.method ?? "GET",
|
|
3769
|
+
path: url.pathname,
|
|
3770
|
+
query,
|
|
3771
|
+
headers,
|
|
3772
|
+
...body === void 0 ? {} : { body }
|
|
3773
|
+
};
|
|
3774
|
+
}
|
|
3775
|
+
|
|
3776
|
+
// packages/cli/src/dev.ts
|
|
3777
|
+
async function loadConfig(cwd) {
|
|
3778
|
+
const name = basename(resolve2(cwd));
|
|
3779
|
+
const config = await loadAdepConfigModule(cwd);
|
|
3780
|
+
return {
|
|
3781
|
+
name: config?.name ?? name,
|
|
3782
|
+
functionsDir: config?.functionsDir ?? "functions",
|
|
3783
|
+
functionsPrefix: config?.functions_prefix ?? "",
|
|
3784
|
+
...config?.environment === void 0 ? {} : { environment: config.environment }
|
|
3785
|
+
};
|
|
3786
|
+
}
|
|
3787
|
+
var parseEnvFile = parseEnv;
|
|
3713
3788
|
function resolveRouteFnName(pathname, prefix) {
|
|
3714
3789
|
const segments = pathname.split("/").filter((segment) => segment.length > 0);
|
|
3715
3790
|
const normalizedPrefix = prefix.replace(/^\/+|\/+$/g, "");
|
|
@@ -3736,10 +3811,6 @@ function resolveRouteFnName(pathname, prefix) {
|
|
|
3736
3811
|
}
|
|
3737
3812
|
return { fnName: second };
|
|
3738
3813
|
}
|
|
3739
|
-
function writeJson(res, status, payload) {
|
|
3740
|
-
res.writeHead(status, { "content-type": "application/json" });
|
|
3741
|
-
res.end(JSON.stringify(payload));
|
|
3742
|
-
}
|
|
3743
3814
|
function printBoundaries(log) {
|
|
3744
3815
|
log("[adep] \u80FD\u529B\u8FB9\u754C\uFF08\u6A21\u62DF\u8FD0\u884C\u65F6\u53EA\u66FF\u6362\u4F20\u8F93/\u6301\u4E45\u5316\uFF0C\u4E0D\u6539\u5199\u8BED\u4E49\uFF09\uFF1A");
|
|
3745
3816
|
for (const b of SIM_BOUNDARIES) {
|
|
@@ -3747,8 +3818,8 @@ function printBoundaries(log) {
|
|
|
3747
3818
|
}
|
|
3748
3819
|
}
|
|
3749
3820
|
async function ensureGitignore(cwd) {
|
|
3750
|
-
const gitignorePath =
|
|
3751
|
-
const existing = await
|
|
3821
|
+
const gitignorePath = join9(cwd, ".gitignore");
|
|
3822
|
+
const existing = await readFile6(gitignorePath, "utf8").catch(() => "");
|
|
3752
3823
|
if (existing.split(/\r?\n/).includes(".adep/")) return;
|
|
3753
3824
|
await writeFile3(gitignorePath, `${existing.replace(/\n+$/, "")}
|
|
3754
3825
|
.adep/
|
|
@@ -3762,8 +3833,9 @@ async function startDevServer(options) {
|
|
|
3762
3833
|
if (options.prefix !== void 0) {
|
|
3763
3834
|
config.functionsPrefix = options.prefix.replace(/^\/+|\/+$/g, "");
|
|
3764
3835
|
}
|
|
3765
|
-
const functionsDir =
|
|
3836
|
+
const functionsDir = join9(cwd, config.functionsDir);
|
|
3766
3837
|
const coldStartAt = Date.now();
|
|
3838
|
+
const bearerUser = bearerUserResolverFromEnv();
|
|
3767
3839
|
const executor = new WorkerFunctionExecutor({
|
|
3768
3840
|
deps: { rootDir: cwd, builtin: LOCAL_BUILTIN_DEPS }
|
|
3769
3841
|
});
|
|
@@ -3854,12 +3926,12 @@ async function startDevServer(options) {
|
|
|
3854
3926
|
const reload = async () => {
|
|
3855
3927
|
const [nextFiles, envText2] = await Promise.all([
|
|
3856
3928
|
collectFunctions(functionsDir),
|
|
3857
|
-
|
|
3929
|
+
readFile6(join9(cwd, ".env.local"), "utf8").catch(() => "")
|
|
3858
3930
|
]);
|
|
3859
3931
|
files = nextFiles;
|
|
3860
3932
|
env = { ...config.environment, ...parseEnvFile(envText2) };
|
|
3861
3933
|
};
|
|
3862
|
-
const envText = await
|
|
3934
|
+
const envText = await readFile6(join9(cwd, ".env.local"), "utf8").catch(() => "");
|
|
3863
3935
|
env = { ...config.environment, ...parseEnvFile(envText) };
|
|
3864
3936
|
let debounceTimer;
|
|
3865
3937
|
let watcher;
|
|
@@ -3874,29 +3946,15 @@ async function startDevServer(options) {
|
|
|
3874
3946
|
watcher = void 0;
|
|
3875
3947
|
}
|
|
3876
3948
|
const buildInput = async (fnName, entry, url, req) => {
|
|
3877
|
-
const query = {};
|
|
3878
|
-
for (const key of new Set(url.searchParams.keys())) {
|
|
3879
|
-
const values = url.searchParams.getAll(key);
|
|
3880
|
-
query[key] = values.length > 1 ? values.join(",") : values[0] ?? "";
|
|
3881
|
-
}
|
|
3882
|
-
const headers = {};
|
|
3883
|
-
for (const [key, value] of Object.entries(req.headers)) {
|
|
3884
|
-
if (typeof value === "string") headers[key] = value;
|
|
3885
|
-
}
|
|
3886
|
-
const body = req.method === "GET" || req.method === "HEAD" ? void 0 : await bodyOf(req);
|
|
3887
3949
|
const hasEnv = Object.keys(env).length > 0;
|
|
3950
|
+
const request = await requestInput(url, req, bodyOf);
|
|
3951
|
+
if (bearerUser !== void 0) request.user = await bearerUser(request.headers);
|
|
3888
3952
|
return {
|
|
3889
3953
|
project: { id: "local", slug: config.name },
|
|
3890
3954
|
fn: { id: fnName, name: fnName },
|
|
3891
3955
|
files,
|
|
3892
3956
|
entry,
|
|
3893
|
-
request
|
|
3894
|
-
method: req.method ?? "GET",
|
|
3895
|
-
path: url.pathname,
|
|
3896
|
-
query,
|
|
3897
|
-
headers,
|
|
3898
|
-
...body === void 0 ? {} : { body }
|
|
3899
|
-
},
|
|
3957
|
+
request,
|
|
3900
3958
|
// 模拟运行时能力:db / storage / realtime 各自只读复用线上装配,语义一致。
|
|
3901
3959
|
capabilities: dbBundle.capabilities,
|
|
3902
3960
|
rpcHandlers: {
|
|
@@ -4033,6 +4091,9 @@ async function startDevServer(options) {
|
|
|
4033
4091
|
log(`[adep] dev server listening on ${baseUrl}\uFF08\u6A21\u62DF\u8FD0\u884C\u65F6\uFF0C\u51B7\u542F\u52A8 ${coldStartMs}ms\uFF09`);
|
|
4034
4092
|
log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
|
|
4035
4093
|
printBoundaries(log);
|
|
4094
|
+
if (bearerUser !== void 0) {
|
|
4095
|
+
log(`[adep] \u767B\u5F55\u5373\u670D\u52A1\uFF1AADEP_AUTH_ISSUER \u5DF2\u914D\u7F6E\uFF0CBearer token \u5C06\u89E3\u6790\u4E3A\u7528\u6237\u8EAB\u4EFD\uFF08userinfo \u7AEF\u70B9\uFF09`);
|
|
4096
|
+
}
|
|
4036
4097
|
log(`[adep] \u6A21\u62DF\u6570\u636E\u76EE\u5F55\uFF1A${simDir(cwd)}`);
|
|
4037
4098
|
startStateAlarmScheduler();
|
|
4038
4099
|
return {
|
package/dist/worker-entry.js
CHANGED
|
@@ -434,6 +434,19 @@ var DB_RPC = {
|
|
|
434
434
|
chain: "chain"
|
|
435
435
|
};
|
|
436
436
|
|
|
437
|
+
// packages/runtime/src/functions/runtime/rpc-wire.ts
|
|
438
|
+
function wireRpcResponses(port, pending) {
|
|
439
|
+
port.on?.((message) => {
|
|
440
|
+
const reply = message;
|
|
441
|
+
if (reply?.type !== "rpc-response" || typeof reply.id !== "number") return;
|
|
442
|
+
const entry = pending.get(reply.id);
|
|
443
|
+
if (entry === void 0) return;
|
|
444
|
+
pending.delete(reply.id);
|
|
445
|
+
if (reply.ok === true) entry.resolve(reply.result);
|
|
446
|
+
else entry.reject(new Error(reply.error ?? "RPC \u80FD\u529B\u8C03\u7528\u5931\u8D25"));
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
|
|
437
450
|
// packages/runtime/src/functions/runtime/chain.ts
|
|
438
451
|
function isChainCapability(value) {
|
|
439
452
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -514,6 +527,11 @@ function splitBareSpecifier(request) {
|
|
|
514
527
|
return request.split("/")[0];
|
|
515
528
|
}
|
|
516
529
|
|
|
530
|
+
// packages/runtime/src/shared/regexp.ts
|
|
531
|
+
function escapeRegExp(text) {
|
|
532
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
533
|
+
}
|
|
534
|
+
|
|
517
535
|
// packages/runtime/src/functions/runtime/worker-entry.ts
|
|
518
536
|
function isRpcCapability(value) {
|
|
519
537
|
return typeof value === "object" && value !== null && value[RPC_CAPABILITY_KEY] === true;
|
|
@@ -543,9 +561,6 @@ function errorMessageOf2(error) {
|
|
|
543
561
|
}
|
|
544
562
|
return String(error);
|
|
545
563
|
}
|
|
546
|
-
function escapeRegExp(text) {
|
|
547
|
-
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
548
|
-
}
|
|
549
564
|
function firstUserFrame(stack, files) {
|
|
550
565
|
for (const key of Object.keys(files)) {
|
|
551
566
|
const match = new RegExp(
|
|
@@ -604,15 +619,7 @@ function runWorker(input, port) {
|
|
|
604
619
|
const container = createCloudContainer();
|
|
605
620
|
const pending = /* @__PURE__ */ new Map();
|
|
606
621
|
let rpcId = 0;
|
|
607
|
-
port
|
|
608
|
-
const reply = message;
|
|
609
|
-
if (reply?.type !== "rpc-response" || typeof reply.id !== "number") return;
|
|
610
|
-
const entry = pending.get(reply.id);
|
|
611
|
-
if (entry === void 0) return;
|
|
612
|
-
pending.delete(reply.id);
|
|
613
|
-
if (reply.ok === true) entry.resolve(reply.result);
|
|
614
|
-
else entry.reject(new Error(reply.error ?? "RPC \u80FD\u529B\u8C03\u7528\u5931\u8D25"));
|
|
615
|
-
});
|
|
622
|
+
wireRpcResponses(port, pending);
|
|
616
623
|
for (const capability of input.capabilities ?? []) {
|
|
617
624
|
container.register(
|
|
618
625
|
capability.name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adep/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "`adep` 命令行工具包位:登录 / 初始化 / 本地调试 / 部署 / 数据库维护 / 云存储 / 静态托管 / 微前端组件(widget),实现见任务单 CLI-001 ~ CLI-003 与 FE-002;子路径 `@adep/cli/vite` 提供云函数 vite 插件(CLI-014)",
|
|
6
6
|
"bin": {
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"commander": "14.0.2",
|
|
22
22
|
"esbuild": "0.25.12",
|
|
23
|
-
"@adep/
|
|
24
|
-
"@adep/
|
|
23
|
+
"@adep/cf-compat": "0.1.1",
|
|
24
|
+
"@adep/vite-plugin": "0.1.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@adep/runtime": "0.2.
|
|
28
|
-
"@adep/types": "0.2.
|
|
27
|
+
"@adep/runtime": "0.2.3",
|
|
28
|
+
"@adep/types": "0.2.3"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"test": "vitest run",
|