@adep/runtime 0.3.4 → 0.3.6

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.
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 支持子集:
5
5
  * `export default`
6
- * `export const | let | var | function | class`
6
+ * `export const | let | var | function | class` (含顶层逗号分隔的多声明符)
7
7
  * `export { a, b as c }` 裸再导出(引用本模块已有绑定)
8
8
  * `export { a, b as c } from './x'` 再导出(FN-035)
9
9
  * `export * from './x'` / `export * as ns from './x'` 星号再导出(FN-035)
@@ -21,6 +21,10 @@
21
21
  * ⇒ 整个函数 500。FN-035 之前裸再导出正是这样漏的(详见与它配套的
22
22
  * `syntaxErrorWithLocation`:连报位都会指到别的文件上,极难定位)。
23
23
  *
24
+ * ⚠️ **静默漏登记比 SyntaxError 更贵**:少导出一个名字不会炸,消费侧只拿到 `undefined`,
25
+ * 无栈可查。故多声明符(`export const a = 1, b = 2`)必须逐个数出来;形态判不准就明确报错
26
+ * (解构导出 `export const { a } = x` 同此,见 `scanDeclaration` 与 `declaratorName`)。
27
+ *
24
28
  * 行数守恒:每次替换都保持**已有内容的行号不变**——`transpile` 用 strip 模式擦类型,
25
29
  * 前提就是行号可信(错误行号、调试面板行号都靠它),吃掉几行就用等量换行补回。
26
30
  * 唯一的例外是**末尾追加**的汇总赋值(在最后一行之后),它不移任何已有行。
package/dist/index.js CHANGED
@@ -679,10 +679,21 @@ function compileSelect(state, dialect) {
679
679
  if (state.orderBys.length > 0) {
680
680
  sql += ` ORDER BY ${state.orderBys.map((order) => `${dialect.quote(order.column)} ${order.direction.toUpperCase()}`).join(", ")}`;
681
681
  }
682
- if (state.limit !== void 0) sql += ` LIMIT ${pushParam(params, dialect, state.limit)}`;
683
- if (state.offset !== void 0) sql += ` OFFSET ${pushParam(params, dialect, state.offset)}`;
682
+ if (state.limit !== void 0) {
683
+ assertInlineableInt(state.limit, "limit");
684
+ sql += ` LIMIT ${state.limit}`;
685
+ }
686
+ if (state.offset !== void 0) {
687
+ assertInlineableInt(state.offset, "offset");
688
+ sql += ` OFFSET ${state.offset}`;
689
+ }
684
690
  return { sql, params };
685
691
  }
692
+ function assertInlineableInt(value, name) {
693
+ if (!Number.isInteger(value) || value < 0) {
694
+ throw unsafeOperation(`${name} \u5FC5\u987B\u662F\u975E\u8D1F\u6574\u6570`);
695
+ }
696
+ }
686
697
  function compileCount(state, dialect) {
687
698
  const params = [];
688
699
  let sql = `SELECT count(*) AS n FROM ${dialect.quote(state.table)}`;
@@ -1013,6 +1024,20 @@ var CLOUD_DB_SPEC = {
1013
1024
  };
1014
1025
  var WRITE_TERMINALS = /* @__PURE__ */ new Set(["insert", "insertMany", "update", "delete"]);
1015
1026
  function errorWithCode(error) {
1027
+ if (error instanceof Error) {
1028
+ const sqlite = /no such table: (\S+)/.exec(error.message);
1029
+ if (sqlite !== null) {
1030
+ return new Error(
1031
+ `[DB_TABLE_MISSING] \u9879\u76EE\u5E93\u5DF2\u542F\u52A8\u4F46\u7F3A\u8868 "${sqlite[1]}"\uFF1A\u8BF7\u6267\u884C adep db migrate <schema.sql> \u5EFA\u8868\uFF08\u53D1\u5E03\u4E0D\u542B\u5EFA\u8868\uFF09\u3002\u539F\u59CB\u9519\u8BEF\uFF1A${error.message}`
1032
+ );
1033
+ }
1034
+ const pg = /relation "([^"]+)" does not exist/.exec(error.message);
1035
+ if (pg !== null) {
1036
+ return new Error(
1037
+ `[DB_TABLE_MISSING] \u9879\u76EE\u5E93\u5DF2\u542F\u52A8\u4F46\u7F3A\u8868\uFF08\u6216\u5173\u7CFB\uFF09"${pg[1]}"\uFF1A\u8BF7\u6267\u884C adep db migrate <schema.sql> \u5EFA\u8868\uFF08\u53D1\u5E03\u4E0D\u542B\u5EFA\u8868\uFF09\u3002\u539F\u59CB\u9519\u8BEF\uFF1A${error.message}`
1038
+ );
1039
+ }
1040
+ }
1016
1041
  const code = typeof error === "object" && error !== null && typeof error.code === "string" ? error.code : void 0;
1017
1042
  if (code !== void 0 && error instanceof Error) {
1018
1043
  return new Error(`[${code}] ${error.message}`);
@@ -2159,11 +2184,21 @@ function parseWhereClauses(whereRaw, cursor) {
2159
2184
  const t = part.trim();
2160
2185
  if (t.length === 0) continue;
2161
2186
  if (/\bIS\s+NULL\b/i.test(t)) {
2162
- clauses.push({ column: unqualifyColumn(ident(t.split(/\s+IS\s+NULL\b/i)[0] ?? "")), operator: "IS NULL", value: null, list: false });
2187
+ clauses.push({
2188
+ column: unqualifyColumn(ident(t.split(/\s+IS\s+NULL\b/i)[0] ?? "")),
2189
+ operator: "IS NULL",
2190
+ value: null,
2191
+ list: false
2192
+ });
2163
2193
  continue;
2164
2194
  }
2165
2195
  if (/\bIS\s+NOT\s+NULL\b/i.test(t)) {
2166
- clauses.push({ column: unqualifyColumn(ident(t.split(/\s+IS\s+NOT\s+NULL\b/i)[0] ?? "")), operator: "IS NOT NULL", value: null, list: false });
2196
+ clauses.push({
2197
+ column: unqualifyColumn(ident(t.split(/\s+IS\s+NOT\s+NULL\b/i)[0] ?? "")),
2198
+ operator: "IS NOT NULL",
2199
+ value: null,
2200
+ list: false
2201
+ });
2167
2202
  continue;
2168
2203
  }
2169
2204
  const opMatch = /^\s*((?:"[^"]+")|([A-Za-z_][A-Za-z0-9_.]*))\s*(=|!=|>=|<=|>|<|like|in|not\s+in)\s*(.+)$/i.exec(
@@ -2340,7 +2375,10 @@ function parseConflictClause(clause, cursor, fallbackCols) {
2340
2375
  clause.trim()
2341
2376
  );
2342
2377
  if (m === null) {
2343
- throw new SimDbError("DB_UNSAFE_OP", `\u65E0\u6CD5\u89E3\u6790 ON CONFLICT \u5B50\u53E5\uFF1A${clause.trim().slice(0, 60)}\u2026`);
2378
+ throw new SimDbError(
2379
+ "DB_UNSAFE_OP",
2380
+ `\u65E0\u6CD5\u89E3\u6790 ON CONFLICT \u5B50\u53E5\uFF1A${clause.trim().slice(0, 60)}\u2026`
2381
+ );
2344
2382
  }
2345
2383
  const colsRaw = m[1];
2346
2384
  const cols = colsRaw === void 0 ? fallbackCols : colsRaw.split(",").map(ident);
@@ -2544,16 +2582,16 @@ var SimSqlEngine = class {
2544
2582
  row[col] = values[i] ?? null;
2545
2583
  });
2546
2584
  if (conflictSpec !== null) {
2547
- const existing = table.rows.find(
2548
- (r) => conflictSpec.cols.every((c) => r[c] === row[c])
2549
- );
2585
+ const existing = table.rows.find((r) => conflictSpec.cols.every((c) => r[c] === row[c]));
2550
2586
  if (existing !== void 0) {
2551
2587
  const oldRow = { ...existing };
2552
2588
  for (const set of conflictSpec.sets) {
2553
2589
  existing[set.col] = resolveSetValue(set.value, oldRow, row);
2554
2590
  }
2555
2591
  inserted += 1;
2556
- void this.persist();
2592
+ this.persist().catch((error) => {
2593
+ console.warn("[sim] \u6301\u4E45\u5316\u5931\u8D25\uFF1A", error);
2594
+ });
2557
2595
  continue;
2558
2596
  }
2559
2597
  }
@@ -2561,7 +2599,9 @@ var SimSqlEngine = class {
2561
2599
  table.rows.push(row);
2562
2600
  inserted += 1;
2563
2601
  }
2564
- void this.persist();
2602
+ this.persist().catch((error) => {
2603
+ console.warn("[sim] \u6301\u4E45\u5316\u5931\u8D25\uFF1A", error);
2604
+ });
2565
2605
  return { changes: inserted };
2566
2606
  }
2567
2607
  execUpdate(sql, params) {
@@ -2591,7 +2631,9 @@ var SimSqlEngine = class {
2591
2631
  }
2592
2632
  changes += 1;
2593
2633
  }
2594
- void this.persist();
2634
+ this.persist().catch((error) => {
2635
+ console.warn("[sim] \u6301\u4E45\u5316\u5931\u8D25\uFF1A", error);
2636
+ });
2595
2637
  return { changes };
2596
2638
  }
2597
2639
  execDelete(sql, params) {
@@ -2609,7 +2651,9 @@ var SimSqlEngine = class {
2609
2651
  else changes += 1;
2610
2652
  }
2611
2653
  table.rows = keep;
2612
- void this.persist();
2654
+ this.persist().catch((error) => {
2655
+ console.warn("[sim] \u6301\u4E45\u5316\u5931\u8D25\uFF1A", error);
2656
+ });
2613
2657
  return { changes };
2614
2658
  }
2615
2659
  select(sql, params) {
@@ -2631,7 +2675,9 @@ var SimSqlEngine = class {
2631
2675
  rows = table.rows.map((row) => {
2632
2676
  const merged = { ...row };
2633
2677
  for (const j of joins) {
2634
- const joined = this.tables[j.table]?.rows.find((jr) => jr[j.leftCol] === merged[j.rightCol]);
2678
+ const joined = this.tables[j.table]?.rows.find(
2679
+ (jr) => jr[j.leftCol] === merged[j.rightCol]
2680
+ );
2635
2681
  if (joined !== void 0) {
2636
2682
  for (const [k, v] of Object.entries(joined)) merged[`${j.alias}.${k}`] = v;
2637
2683
  }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "homepage": "https://adep.top",
9
9
  "bugs": "https://gitcode.com/yunqiang_wu/ai-yunke/issues",
10
- "version": "0.3.4",
10
+ "version": "0.3.6",
11
11
  "private": false,
12
12
  "type": "module",
13
13
  "sideEffects": false,