@adep/cli 0.1.16 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vite.js CHANGED
@@ -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, readFile as readFile6, writeFile as writeFile3 } from "node:fs/promises";
8
- import { basename, join as join9, resolve as resolve2 } from "node:path";
7
+ import { mkdir as mkdir4, readFile as readFile7, writeFile as writeFile3 } from "node:fs/promises";
8
+ import { basename, join as join10, resolve as resolve4 } from "node:path";
9
9
 
10
10
  // packages/runtime/src/shared/capability-keys.ts
11
11
  var RPC_CAPABILITY_KEY = "__adepRpc";
@@ -269,7 +269,7 @@ var WorkerFunctionExecutor = class {
269
269
  const entry = input.entry ?? resolveDraftEntry(input.fn.name, input.files) ?? "index.ts";
270
270
  const deps = this.depsConfig === void 0 ? void 0 : resolveExecutionDeps(this.depsConfig, input.project.id, input.files["package.json"]);
271
271
  const logs = [];
272
- return new Promise((resolve3, reject) => {
272
+ return new Promise((resolve5, reject) => {
273
273
  let worker;
274
274
  try {
275
275
  worker = new Worker(resolveWorkerEntry(), {
@@ -331,7 +331,7 @@ var WorkerFunctionExecutor = class {
331
331
  if (message.type === "result") {
332
332
  clearTimeout(timer);
333
333
  void worker.terminate();
334
- resolve3({ body: message.body, logs });
334
+ resolve5({ body: message.body, logs });
335
335
  return;
336
336
  }
337
337
  if (message.type === "error") {
@@ -2386,7 +2386,7 @@ function createLocalStorageDriver(options) {
2386
2386
  assertStoragePrefix(prefix);
2387
2387
  const root = bucketDir(projectId);
2388
2388
  const metas = [];
2389
- const walk = async (dir, relative) => {
2389
+ const walk = async (dir, relative2) => {
2390
2390
  let entries;
2391
2391
  try {
2392
2392
  entries = await readdir(dir, { withFileTypes: true });
@@ -2397,7 +2397,7 @@ function createLocalStorageDriver(options) {
2397
2397
  for (const entry of entries) {
2398
2398
  if (entry.name.endsWith(META_SUFFIX)) continue;
2399
2399
  const full = join2(dir, entry.name);
2400
- const rel = relative === "" ? entry.name : `${relative}/${entry.name}`;
2400
+ const rel = relative2 === "" ? entry.name : `${relative2}/${entry.name}`;
2401
2401
  if (entry.isFile()) {
2402
2402
  if (prefix !== void 0 && !rel.startsWith(prefix)) continue;
2403
2403
  tasks.push(
@@ -2640,9 +2640,253 @@ async function createSimRuntime(options) {
2640
2640
  };
2641
2641
  }
2642
2642
 
2643
- // packages/cli/src/sim/env.ts
2643
+ // packages/cli/src/serve/db-mode.ts
2644
2644
  import { readFile as readFile3 } from "node:fs/promises";
2645
- import { join as join5 } from "node:path";
2645
+ import { join as join5, relative, resolve as resolve3 } from "node:path";
2646
+
2647
+ // packages/cli/src/db.ts
2648
+ function splitSqlStatements(source) {
2649
+ const statements = [];
2650
+ let buffer = "";
2651
+ let inQuote = false;
2652
+ const lines = source.split("\n");
2653
+ for (const rawLine of lines) {
2654
+ const trimmed = rawLine.trim();
2655
+ if (!inQuote && (trimmed.length === 0 || trimmed.startsWith("--"))) continue;
2656
+ for (let i = 0; i < rawLine.length; i++) {
2657
+ const ch = rawLine[i];
2658
+ if (inQuote) {
2659
+ if (ch === "'") {
2660
+ if (rawLine[i + 1] === "'") {
2661
+ buffer += ch + rawLine[i + 1];
2662
+ i++;
2663
+ continue;
2664
+ }
2665
+ inQuote = false;
2666
+ }
2667
+ buffer += ch;
2668
+ continue;
2669
+ }
2670
+ if (ch === "'") {
2671
+ inQuote = true;
2672
+ buffer += ch;
2673
+ continue;
2674
+ }
2675
+ if (ch === "-" && rawLine[i + 1] === "-") break;
2676
+ if (ch === ";") {
2677
+ const statement = buffer.trim();
2678
+ if (statement.length > 0) statements.push(statement);
2679
+ buffer = "";
2680
+ continue;
2681
+ }
2682
+ buffer += ch;
2683
+ }
2684
+ buffer += inQuote ? "\n" : " ";
2685
+ }
2686
+ if (inQuote) {
2687
+ throw new Error(`SQL \u8FC1\u79FB\u6587\u4EF6\u5F15\u53F7\u672A\u95ED\u5408\uFF1A${buffer.trim().slice(0, 80)}\u2026`);
2688
+ }
2689
+ const tail = buffer.trim();
2690
+ if (tail.length > 0) statements.push(tail);
2691
+ return statements;
2692
+ }
2693
+
2694
+ // packages/cli/src/serve/sqlite-driver.ts
2695
+ import { mkdir as mkdir3 } from "node:fs/promises";
2696
+ import { dirname as dirname4, resolve as resolve2 } from "node:path";
2697
+ var NODE_SQLITE_MIN = { major: 22, minor: 5 };
2698
+ function isBun(versions) {
2699
+ return versions["bun"] !== void 0 && versions["bun"] !== "";
2700
+ }
2701
+ function detectSqliteRuntime(versions = process.versions) {
2702
+ if (isBun(versions)) return "bun";
2703
+ const raw = versions["node"];
2704
+ if (raw === void 0) return null;
2705
+ const [majorText, minorText] = raw.split(".");
2706
+ const major = Number(majorText);
2707
+ const minor = Number(minorText ?? "0");
2708
+ if (!Number.isInteger(major) || !Number.isInteger(minor)) return null;
2709
+ if (major > NODE_SQLITE_MIN.major) return "node";
2710
+ if (major === NODE_SQLITE_MIN.major && minor >= NODE_SQLITE_MIN.minor) return "node";
2711
+ return null;
2712
+ }
2713
+ function sqliteModuleName(runtime) {
2714
+ return runtime === "bun" ? "bun:sqlite" : "node:sqlite";
2715
+ }
2716
+ function sqliteUnavailableReason(versions = process.versions) {
2717
+ const current = isBun(versions) ? `Bun ${versions["bun"] ?? ""}`.trim() : `Node ${versions["node"] ?? "\u672A\u77E5"}`;
2718
+ return `\u5F53\u524D\u8FD0\u884C\u65F6 ${current} \u4E0D\u63D0\u4F9B SQLite \u5185\u5EFA\u6A21\u5757\uFF08\u9700\u8981 Bun \u6216 Node \u2265 ${NODE_SQLITE_MIN.major}.${NODE_SQLITE_MIN.minor}\uFF09`;
2719
+ }
2720
+ function sqliteRuntimeRequirementMessage(versions = process.versions) {
2721
+ return `--db sqlite \u9700\u8981 Bun\uFF08\u5185\u7F6E bun:sqlite\uFF09\u6216 Node \u2265 ${NODE_SQLITE_MIN.major}.${NODE_SQLITE_MIN.minor}\uFF08\u5185\u7F6E node:sqlite\uFF09\uFF1B${sqliteUnavailableReason(versions)}\u3002\u8BF7\u6539\u7528 \`--db sim\`\uFF08\u5185\u7F6E\u6A21\u62DF\u5F15\u64CE\uFF0C\u65E0\u9700\u989D\u5916\u8FD0\u884C\u65F6\uFF09\uFF0C\u6216\u5347\u7EA7 Node / \u7528 Bun \u8FD0\u884C\u3002`;
2722
+ }
2723
+ async function openSqliteProjectDriver(file, options = {}) {
2724
+ const runtime = options.runtime ?? detectSqliteRuntime();
2725
+ if (runtime === null) throw new Error(sqliteRuntimeRequirementMessage());
2726
+ const moduleName = sqliteModuleName(runtime);
2727
+ const ctorName = runtime === "bun" ? "Database" : "DatabaseSync";
2728
+ let mod;
2729
+ try {
2730
+ const specifier = moduleName;
2731
+ mod = await import(
2732
+ /* @vite-ignore */
2733
+ specifier
2734
+ );
2735
+ } catch (error) {
2736
+ throw new Error(
2737
+ `${sqliteRuntimeRequirementMessage()}
2738
+ \uFF08\u8F7D\u5165 ${moduleName} \u5931\u8D25\uFF1A${error instanceof Error ? error.message : String(error)}\uFF09`,
2739
+ { cause: error }
2740
+ );
2741
+ }
2742
+ const Ctor = mod[ctorName];
2743
+ if (Ctor === void 0) {
2744
+ throw new Error(`${moduleName} \u672A\u5BFC\u51FA ${ctorName}\uFF1A\u5F53\u524D\u8FD0\u884C\u65F6\u7684 SQLite \u5185\u5EFA\u6A21\u5757\u4E0D\u53EF\u7528`);
2745
+ }
2746
+ const target = file === ":memory:" ? file : resolve2(file);
2747
+ if (target !== ":memory:") await mkdir3(dirname4(target), { recursive: true });
2748
+ const database = new Ctor(target);
2749
+ database.exec("PRAGMA journal_mode = WAL; PRAGMA foreign_keys = ON;");
2750
+ return {
2751
+ engine: "sqlite",
2752
+ async run(sql, params = []) {
2753
+ if (params.length === 0) {
2754
+ database.exec(sql);
2755
+ return { changes: 0 };
2756
+ }
2757
+ const result = database.prepare(sql).run(...params);
2758
+ return { changes: Number(result.changes) };
2759
+ },
2760
+ async all(sql, params = []) {
2761
+ const statement = database.prepare(sql);
2762
+ statement.setReturnArrays?.(false);
2763
+ return statement.all(...params);
2764
+ },
2765
+ async get(sql, params = []) {
2766
+ const statement = database.prepare(sql);
2767
+ statement.setReturnArrays?.(false);
2768
+ const row = statement.get(...params);
2769
+ return row ?? null;
2770
+ },
2771
+ async close() {
2772
+ database.close();
2773
+ }
2774
+ };
2775
+ }
2776
+
2777
+ // packages/cli/src/serve/db-mode.ts
2778
+ var SERVE_DB_MODES = ["sim", "sqlite"];
2779
+ var DEFAULT_SERVE_DB_MODE = "sqlite";
2780
+ var DEFAULT_SQLITE_DB_FILE = ".adep/data/project.sqlite";
2781
+ function isServeDbMode(value) {
2782
+ return SERVE_DB_MODES.includes(value.trim().toLowerCase());
2783
+ }
2784
+ function parseServeDbMode(raw, source) {
2785
+ const value = raw.trim().toLowerCase();
2786
+ if (!isServeDbMode(value)) {
2787
+ throw new Error(
2788
+ `${source} \u7684\u6570\u636E\u5E93\u6A21\u5F0F "${raw}" \u65E0\u6548\uFF1A\u53EA\u652F\u6301 ${SERVE_DB_MODES.join(" | ")}\uFF08sim = \u5185\u7F6E\u6A21\u62DF\u5F15\u64CE\u4E0E .adep/sim/db.json\uFF1Bsqlite = \u771F\u5B9E SQLite \u5E93\u6587\u4EF6\uFF09`
2789
+ );
2790
+ }
2791
+ return value;
2792
+ }
2793
+ function resolveServeDbMode(explicit) {
2794
+ if (explicit !== void 0) return parseServeDbMode(explicit, "--db");
2795
+ const fromEnv = process.env["ADEP_SERVE_DB"];
2796
+ if (fromEnv !== void 0 && fromEnv.trim() !== "") {
2797
+ return parseServeDbMode(fromEnv, "ADEP_SERVE_DB");
2798
+ }
2799
+ return DEFAULT_SERVE_DB_MODE;
2800
+ }
2801
+ function resolveServeDbFile(cwd, explicit) {
2802
+ const raw = explicit ?? envDbFile() ?? DEFAULT_SQLITE_DB_FILE;
2803
+ return raw === ":memory:" ? raw : resolve3(cwd, raw);
2804
+ }
2805
+ function envDbFile() {
2806
+ const raw = process.env["ADEP_SERVE_DB_FILE"];
2807
+ return raw === void 0 || raw.trim() === "" ? void 0 : raw.trim();
2808
+ }
2809
+ function displayPath(cwd, target) {
2810
+ if (target === ":memory:") return target;
2811
+ const rel = relative(cwd, target);
2812
+ return rel.startsWith("..") ? target : rel;
2813
+ }
2814
+ function simDbTarget(cwd) {
2815
+ return displayPath(cwd, join5(simDir(cwd), "db.json"));
2816
+ }
2817
+ function resolveLocalDbTarget(cwd, options) {
2818
+ const mode = resolveServeDbMode(options.db);
2819
+ return {
2820
+ mode,
2821
+ file: mode === "sqlite" ? resolveServeDbFile(cwd, options.dbFile) : null
2822
+ };
2823
+ }
2824
+ async function openLocalDbDriver(target, options) {
2825
+ if (target.mode === "sim" || target.file === null) {
2826
+ return { mode: "sim", file: null, module: null, driver: null };
2827
+ }
2828
+ const simTarget = simDbTarget(options.cwd);
2829
+ const runtimeName = detectSqliteRuntime();
2830
+ if (runtimeName === null) {
2831
+ options.log(
2832
+ `[${options.tag}] \u8B66\u544A\uFF1A${sqliteUnavailableReason()}\uFF0C\u5DF2\u81EA\u52A8\u964D\u7EA7\u4E3A sim \u6A21\u5F0F\uFF08\u5185\u7F6E\u6A21\u62DF\u5F15\u64CE\uFF0C\u5E93 ${simTarget}\uFF09\u3002\u5982\u9700\u771F\u5B9E SQLite\uFF0C\u8BF7\u7528 Bun \u6216\u5347\u7EA7 Node \u540E\u91CD\u8BD5\u3002`
2833
+ );
2834
+ return { mode: "sim", file: null, module: null, driver: null };
2835
+ }
2836
+ try {
2837
+ const driver = await openSqliteProjectDriver(target.file, { runtime: runtimeName });
2838
+ return {
2839
+ mode: "sqlite",
2840
+ file: target.file,
2841
+ module: sqliteModuleName(runtimeName),
2842
+ driver
2843
+ };
2844
+ } catch (error) {
2845
+ const detail = error instanceof Error ? error.message : String(error);
2846
+ options.log(
2847
+ `[${options.tag}] \u8B66\u544A\uFF1A\u6253\u5F00 SQLite \u5E93\u5931\u8D25\uFF08${detail}\uFF09\uFF0C\u5DF2\u81EA\u52A8\u964D\u7EA7\u4E3A sim \u6A21\u5F0F\uFF08\u5185\u7F6E\u6A21\u62DF\u5F15\u64CE\uFF0C\u5E93 ${simTarget}\uFF09\u3002`
2848
+ );
2849
+ return { mode: "sim", file: null, module: null, driver: null };
2850
+ }
2851
+ }
2852
+ async function applyLocalSchema(driver, options) {
2853
+ const { schemaFile, mode, tag, cwd, log } = options;
2854
+ const schemaPath = resolve3(cwd, schemaFile);
2855
+ const schemaSource = await readFile3(schemaPath, "utf8").catch((error) => {
2856
+ if (error.code === "ENOENT") {
2857
+ throw new Error(`schema \u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${schemaPath}`);
2858
+ }
2859
+ throw error;
2860
+ });
2861
+ const statements = splitSqlStatements(schemaSource);
2862
+ let applied = 0;
2863
+ let skipped = 0;
2864
+ for (const [index, statement] of statements.entries()) {
2865
+ try {
2866
+ await driver.run(statement);
2867
+ applied += 1;
2868
+ } catch (error) {
2869
+ const isUnsupported = error instanceof Error && "code" in error && error.code === "DB_UNSAFE_OP";
2870
+ if (mode === "sim" && isUnsupported) {
2871
+ skipped += 1;
2872
+ log(`[${tag}] \u8DF3\u8FC7 schema \u8BED\u53E5\uFF08sim \u5F15\u64CE\u4E0D\u652F\u6301\uFF09\uFF1A${statement.slice(0, 60)}\u2026`);
2873
+ continue;
2874
+ }
2875
+ const detail = error instanceof Error ? error.message : String(error);
2876
+ throw new Error(
2877
+ `schema \u8BED\u53E5\u6267\u884C\u5931\u8D25\uFF08--schema ${schemaFile}\uFF0C\u7B2C ${index + 1} \u6761\uFF0Cdb \u6A21\u5F0F ${mode}\uFF09\uFF1A${detail}
2878
+ \u8BED\u53E5\uFF1A${statement.slice(0, 200)}` + (mode === "sqlite" ? "\n\uFF08sqlite \u6A21\u5F0F\u4E0D\u505A\u8BED\u53E5\u8DF3\u8FC7\uFF1B\u5982\u9700\u8DF3\u8FC7\u8BED\u4E49\u8BF7\u6539\u7528 --db sim\uFF09" : ""),
2879
+ { cause: error }
2880
+ );
2881
+ }
2882
+ }
2883
+ const skipNote = skipped > 0 ? `\uFF0C\u8DF3\u8FC7 ${skipped} \u6761` : "";
2884
+ log(`[${tag}] \u5DF2\u5E94\u7528\u6570\u636E\u5E93\u7ED3\u6784\uFF08--schema ${schemaFile}\uFF09\uFF1A${applied} \u6761\u8BED\u53E5${skipNote}`);
2885
+ }
2886
+
2887
+ // packages/cli/src/sim/env.ts
2888
+ import { readFile as readFile4 } from "node:fs/promises";
2889
+ import { join as join6 } from "node:path";
2646
2890
  function parseEnv(content) {
2647
2891
  const env = {};
2648
2892
  for (const raw of content.split(/\r?\n/)) {
@@ -2657,8 +2901,8 @@ function parseEnv(content) {
2657
2901
  return env;
2658
2902
  }
2659
2903
  async function loadSimEnv(cwd, config = {}) {
2660
- const envRoot = await readFile3(join5(cwd, ".env"), "utf8").catch(() => "");
2661
- const envLocal = await readFile3(join5(cwd, ".env.local"), "utf8").catch(() => "");
2904
+ const envRoot = await readFile4(join6(cwd, ".env"), "utf8").catch(() => "");
2905
+ const envLocal = await readFile4(join6(cwd, ".env.local"), "utf8").catch(() => "");
2662
2906
  const merged = { ...parseEnv(envRoot), ...parseEnv(envLocal) };
2663
2907
  for (const secret of config.secrets ?? []) {
2664
2908
  if (merged[secret] !== void 0) continue;
@@ -2781,8 +3025,8 @@ var SIM_BOUNDARIES = [
2781
3025
  ];
2782
3026
 
2783
3027
  // packages/cli/src/ts-config.ts
2784
- import { stat as stat2, readFile as readFile4 } from "node:fs/promises";
2785
- import { join as join6 } from "node:path";
3028
+ import { stat as stat2, readFile as readFile5 } from "node:fs/promises";
3029
+ import { join as join7 } from "node:path";
2786
3030
 
2787
3031
  // shared/sdk/adep-config.ts
2788
3032
  var DEFAULT_ADEP_CONFIG = {
@@ -2921,7 +3165,7 @@ function parseAdepConfig(raw) {
2921
3165
 
2922
3166
  // packages/cli/src/ts-config.ts
2923
3167
  async function loadAdepConfigModule(cwd) {
2924
- const configPath = join6(cwd, "adep.config.ts");
3168
+ const configPath = join7(cwd, "adep.config.ts");
2925
3169
  try {
2926
3170
  await stat2(configPath);
2927
3171
  } catch {
@@ -2935,7 +3179,7 @@ async function loadAdepConfigModule(cwd) {
2935
3179
  rawDefault = mod.default;
2936
3180
  } else {
2937
3181
  const { transform } = await import("esbuild");
2938
- const source = await readFile4(configPath, "utf8");
3182
+ const source = await readFile5(configPath, "utf8");
2939
3183
  const { code } = await transform(source, {
2940
3184
  loader: "ts",
2941
3185
  format: "esm",
@@ -3448,7 +3692,7 @@ function loadStateObjectClasses(files, entry = STATE_OBJECTS_ENTRY, options = {}
3448
3692
  // packages/runtime/src/functions/runtime/worker-entry.ts
3449
3693
  import { parentPort, workerData } from "node:worker_threads";
3450
3694
  import { createRequire } from "node:module";
3451
- import { join as join7 } from "node:path";
3695
+ import { join as join8 } from "node:path";
3452
3696
 
3453
3697
  // packages/runtime/src/functions/runtime/cloud-container.ts
3454
3698
  var KNOWN_CAPABILITY_HINTS = {
@@ -3729,9 +3973,9 @@ function isChainCapability(value) {
3729
3973
  return typeof spec === "object" && spec !== null && Array.isArray(spec.stepMethods) && Array.isArray(spec.terminalMethods);
3730
3974
  }
3731
3975
  function createChainClient(capability, port, pending, nextId, spec) {
3732
- const call = (method, args) => new Promise((resolve3, reject) => {
3976
+ const call = (method, args) => new Promise((resolve5, reject) => {
3733
3977
  const id = nextId();
3734
- pending.set(id, { resolve: resolve3, reject });
3978
+ pending.set(id, { resolve: resolve5, reject });
3735
3979
  port.postMessage({ type: "rpc", id, capability, method, args });
3736
3980
  });
3737
3981
  const makeChainable = (rootArgs, steps, txId) => new Proxy(
@@ -3810,8 +4054,8 @@ function createRpcClient(capability, port, pending, nextId) {
3810
4054
  if (typeof method !== "string") return void 0;
3811
4055
  return (...args) => {
3812
4056
  const id = nextId();
3813
- return new Promise((resolve3, reject) => {
3814
- pending.set(id, { resolve: resolve3, reject });
4057
+ return new Promise((resolve5, reject) => {
4058
+ pending.set(id, { resolve: resolve5, reject });
3815
4059
  port.postMessage({ type: "rpc", id, capability, method, args });
3816
4060
  });
3817
4061
  };
@@ -3847,7 +4091,7 @@ function errorMessageWithLocation(error, files) {
3847
4091
  }
3848
4092
  function createBareResolver(deps) {
3849
4093
  const platformRequire = createRequire(import.meta.url);
3850
- const depsRequire = deps.dir === null ? null : createRequire(join7(deps.dir, "__deps__.js"));
4094
+ const depsRequire = deps.dir === null ? null : createRequire(join8(deps.dir, "__deps__.js"));
3851
4095
  return (request) => {
3852
4096
  if (deps.builtin.includes(request)) return platformRequire(request);
3853
4097
  const root = splitBareSpecifier(request);
@@ -3992,8 +4236,8 @@ if (workerPort !== null && workerData !== void 0) {
3992
4236
  }
3993
4237
 
3994
4238
  // packages/cli/src/dev-shared.ts
3995
- import { readdir as readdir2, readFile as readFile5 } from "node:fs/promises";
3996
- import { join as join8 } from "node:path";
4239
+ import { readdir as readdir2, readFile as readFile6 } from "node:fs/promises";
4240
+ import { join as join9 } from "node:path";
3997
4241
 
3998
4242
  // packages/runtime/src/shared/function-source.ts
3999
4243
  var SHARED_SOURCE_ROOT = "functions/_shared/";
@@ -4056,11 +4300,11 @@ async function collectFunctions(dir) {
4056
4300
  }
4057
4301
  for (const entry of entries) {
4058
4302
  const rel = prefix.length === 0 ? entry.name : `${prefix}/${entry.name}`;
4059
- const full = join8(sub, entry.name);
4303
+ const full = join9(sub, entry.name);
4060
4304
  if (entry.isDirectory()) {
4061
4305
  await walk(full, rel);
4062
4306
  } else if (entry.isFile() && isRuntimeSource(entry.name)) {
4063
- files[rel] = await readFile5(full, "utf8");
4307
+ files[rel] = await readFile6(full, "utf8");
4064
4308
  }
4065
4309
  }
4066
4310
  };
@@ -4130,7 +4374,7 @@ async function requestInput(url, req, readBody) {
4130
4374
 
4131
4375
  // packages/cli/src/dev.ts
4132
4376
  async function loadConfig(cwd) {
4133
- const name = basename(resolve2(cwd));
4377
+ const name = basename(resolve4(cwd));
4134
4378
  const config = await loadAdepConfigModule(cwd);
4135
4379
  return {
4136
4380
  name: config?.name ?? name,
@@ -4173,34 +4417,49 @@ function printBoundaries(log) {
4173
4417
  }
4174
4418
  }
4175
4419
  async function ensureGitignore(cwd) {
4176
- const gitignorePath = join9(cwd, ".gitignore");
4177
- const existing = await readFile6(gitignorePath, "utf8").catch(() => "");
4420
+ const gitignorePath = join10(cwd, ".gitignore");
4421
+ const existing = await readFile7(gitignorePath, "utf8").catch(() => "");
4178
4422
  if (existing.split(/\r?\n/).includes(".adep/")) return;
4179
4423
  await writeFile3(gitignorePath, `${existing.replace(/\n+$/, "")}
4180
4424
  .adep/
4181
4425
  `, "utf8");
4182
4426
  }
4183
4427
  async function startDevServer(options) {
4184
- const cwd = resolve2(options.cwd);
4428
+ const cwd = resolve4(options.cwd);
4185
4429
  const log = options.log ?? ((line) => process.stdout.write(`${line}
4186
4430
  `));
4187
4431
  const config = await loadConfig(cwd);
4188
4432
  if (options.prefix !== void 0) {
4189
4433
  config.functionsPrefix = options.prefix.replace(/^\/+|\/+$/g, "");
4190
4434
  }
4191
- const functionsDir = join9(cwd, config.functionsDir);
4435
+ const functionsDir = join10(cwd, config.functionsDir);
4192
4436
  const coldStartAt = Date.now();
4437
+ const dbTarget = resolveLocalDbTarget(cwd, {
4438
+ ...options.db === void 0 ? {} : { db: options.db },
4439
+ ...options.dbFile === void 0 ? {} : { dbFile: options.dbFile }
4440
+ });
4193
4441
  const bearerUser = bearerUserResolverFromEnv();
4194
4442
  const executor = new WorkerFunctionExecutor({
4195
4443
  deps: { rootDir: cwd, builtin: LOCAL_BUILTIN_DEPS }
4196
4444
  });
4197
- await mkdir3(functionsDir, { recursive: true });
4445
+ await mkdir4(functionsDir, { recursive: true });
4446
+ const db = await openLocalDbDriver(dbTarget, { cwd, tag: "adep", log });
4198
4447
  const runtime = await createSimRuntime({
4199
4448
  cwd,
4200
4449
  projectId: "local",
4201
4450
  baseUrl: `http://127.0.0.1:${options.port ?? 8787}`,
4202
- log
4451
+ log,
4452
+ ...db.driver === null ? {} : { driver: db.driver }
4203
4453
  });
4454
+ if (options.schemaFile !== void 0) {
4455
+ await applyLocalSchema(runtime.db.driver, {
4456
+ cwd,
4457
+ schemaFile: options.schemaFile,
4458
+ mode: db.mode,
4459
+ tag: "adep",
4460
+ log
4461
+ });
4462
+ }
4204
4463
  await ensureGitignore(cwd);
4205
4464
  let files = mergeSharedIntoFunctions(await collectFunctions(functionsDir));
4206
4465
  let env = {
@@ -4281,12 +4540,12 @@ async function startDevServer(options) {
4281
4540
  const reload = async () => {
4282
4541
  const [nextFiles, envText2] = await Promise.all([
4283
4542
  collectFunctions(functionsDir).then(mergeSharedIntoFunctions),
4284
- readFile6(join9(cwd, ".env.local"), "utf8").catch(() => "")
4543
+ readFile7(join10(cwd, ".env.local"), "utf8").catch(() => "")
4285
4544
  ]);
4286
4545
  files = nextFiles;
4287
4546
  env = { ...config.environment, ...parseEnvFile(envText2) };
4288
4547
  };
4289
- const envText = await readFile6(join9(cwd, ".env.local"), "utf8").catch(() => "");
4548
+ const envText = await readFile7(join10(cwd, ".env.local"), "utf8").catch(() => "");
4290
4549
  env = { ...config.environment, ...parseEnvFile(envText) };
4291
4550
  let debounceTimer;
4292
4551
  let watcher;
@@ -4443,13 +4702,17 @@ async function startDevServer(options) {
4443
4702
  const baseUrl = `http://127.0.0.1:${actualPort}`;
4444
4703
  const coldStartMs = Date.now() - coldStartAt;
4445
4704
  const curlPath = config.functionsPrefix.length === 0 ? "/hello" : `/${config.functionsPrefix}/hello`;
4446
- log(`[adep] dev server listening on ${baseUrl}\uFF08\u6A21\u62DF\u8FD0\u884C\u65F6\uFF0C\u51B7\u542F\u52A8 ${coldStartMs}ms\uFF09`);
4705
+ 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";
4706
+ const dbTargetText = db.file === null ? simDbTarget(cwd) : displayPath(cwd, db.file);
4707
+ log(
4708
+ `[adep] dev server listening on ${baseUrl}\uFF08\u672C\u5730\u8FD0\u884C\u65F6 / ${dbLabel}\uFF0C\u51B7\u542F\u52A8 ${coldStartMs}ms\uFF09`
4709
+ );
4447
4710
  log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
4448
4711
  printBoundaries(log);
4449
4712
  if (bearerUser !== void 0) {
4450
4713
  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`);
4451
4714
  }
4452
- log(`[adep] \u6A21\u62DF\u6570\u636E\u76EE\u5F55\uFF1A${simDir(cwd)}`);
4715
+ log(`[adep] \u6570\u636E\u5E93\uFF1A${dbLabel} \u2192 ${dbTargetText}`);
4453
4716
  startStateAlarmScheduler();
4454
4717
  return {
4455
4718
  port: actualPort,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adep/cli",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "type": "module",
5
5
  "description": "`adep` 命令行工具包位:登录 / 初始化 / 本地调试 / 部署 / 数据库维护 / 云存储 / 静态托管 / 微前端组件(widget),实现见任务单 CLI-001 ~ CLI-003 与 FE-002;子路径 `@adep/cli/vite` 提供云函数 vite 插件(CLI-014)",
6
6
  "bin": {
@@ -21,9 +21,9 @@
21
21
  "commander": "14.0.2",
22
22
  "esbuild": "0.25.12",
23
23
  "@adep/cf-compat": "0.1.1",
24
- "@adep/runtime": "0.2.7",
25
24
  "@adep/crypto": "0.1.0",
26
- "@adep/vite-plugin": "0.1.7"
25
+ "@adep/vite-plugin": "0.1.7",
26
+ "@adep/runtime": "0.2.7"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@adep/types": "0.2.3"