@adep/runtime 0.3.4 → 0.3.5

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)}`;
@@ -2159,11 +2170,21 @@ function parseWhereClauses(whereRaw, cursor) {
2159
2170
  const t = part.trim();
2160
2171
  if (t.length === 0) continue;
2161
2172
  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 });
2173
+ clauses.push({
2174
+ column: unqualifyColumn(ident(t.split(/\s+IS\s+NULL\b/i)[0] ?? "")),
2175
+ operator: "IS NULL",
2176
+ value: null,
2177
+ list: false
2178
+ });
2163
2179
  continue;
2164
2180
  }
2165
2181
  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 });
2182
+ clauses.push({
2183
+ column: unqualifyColumn(ident(t.split(/\s+IS\s+NOT\s+NULL\b/i)[0] ?? "")),
2184
+ operator: "IS NOT NULL",
2185
+ value: null,
2186
+ list: false
2187
+ });
2167
2188
  continue;
2168
2189
  }
2169
2190
  const opMatch = /^\s*((?:"[^"]+")|([A-Za-z_][A-Za-z0-9_.]*))\s*(=|!=|>=|<=|>|<|like|in|not\s+in)\s*(.+)$/i.exec(
@@ -2340,7 +2361,10 @@ function parseConflictClause(clause, cursor, fallbackCols) {
2340
2361
  clause.trim()
2341
2362
  );
2342
2363
  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`);
2364
+ throw new SimDbError(
2365
+ "DB_UNSAFE_OP",
2366
+ `\u65E0\u6CD5\u89E3\u6790 ON CONFLICT \u5B50\u53E5\uFF1A${clause.trim().slice(0, 60)}\u2026`
2367
+ );
2344
2368
  }
2345
2369
  const colsRaw = m[1];
2346
2370
  const cols = colsRaw === void 0 ? fallbackCols : colsRaw.split(",").map(ident);
@@ -2544,16 +2568,16 @@ var SimSqlEngine = class {
2544
2568
  row[col] = values[i] ?? null;
2545
2569
  });
2546
2570
  if (conflictSpec !== null) {
2547
- const existing = table.rows.find(
2548
- (r) => conflictSpec.cols.every((c) => r[c] === row[c])
2549
- );
2571
+ const existing = table.rows.find((r) => conflictSpec.cols.every((c) => r[c] === row[c]));
2550
2572
  if (existing !== void 0) {
2551
2573
  const oldRow = { ...existing };
2552
2574
  for (const set of conflictSpec.sets) {
2553
2575
  existing[set.col] = resolveSetValue(set.value, oldRow, row);
2554
2576
  }
2555
2577
  inserted += 1;
2556
- void this.persist();
2578
+ this.persist().catch((error) => {
2579
+ console.warn("[sim] \u6301\u4E45\u5316\u5931\u8D25\uFF1A", error);
2580
+ });
2557
2581
  continue;
2558
2582
  }
2559
2583
  }
@@ -2561,7 +2585,9 @@ var SimSqlEngine = class {
2561
2585
  table.rows.push(row);
2562
2586
  inserted += 1;
2563
2587
  }
2564
- void this.persist();
2588
+ this.persist().catch((error) => {
2589
+ console.warn("[sim] \u6301\u4E45\u5316\u5931\u8D25\uFF1A", error);
2590
+ });
2565
2591
  return { changes: inserted };
2566
2592
  }
2567
2593
  execUpdate(sql, params) {
@@ -2591,7 +2617,9 @@ var SimSqlEngine = class {
2591
2617
  }
2592
2618
  changes += 1;
2593
2619
  }
2594
- void this.persist();
2620
+ this.persist().catch((error) => {
2621
+ console.warn("[sim] \u6301\u4E45\u5316\u5931\u8D25\uFF1A", error);
2622
+ });
2595
2623
  return { changes };
2596
2624
  }
2597
2625
  execDelete(sql, params) {
@@ -2609,7 +2637,9 @@ var SimSqlEngine = class {
2609
2637
  else changes += 1;
2610
2638
  }
2611
2639
  table.rows = keep;
2612
- void this.persist();
2640
+ this.persist().catch((error) => {
2641
+ console.warn("[sim] \u6301\u4E45\u5316\u5931\u8D25\uFF1A", error);
2642
+ });
2613
2643
  return { changes };
2614
2644
  }
2615
2645
  select(sql, params) {
@@ -2631,7 +2661,9 @@ var SimSqlEngine = class {
2631
2661
  rows = table.rows.map((row) => {
2632
2662
  const merged = { ...row };
2633
2663
  for (const j of joins) {
2634
- const joined = this.tables[j.table]?.rows.find((jr) => jr[j.leftCol] === merged[j.rightCol]);
2664
+ const joined = this.tables[j.table]?.rows.find(
2665
+ (jr) => jr[j.leftCol] === merged[j.rightCol]
2666
+ );
2635
2667
  if (joined !== void 0) {
2636
2668
  for (const [k, v] of Object.entries(joined)) merged[`${j.alias}.${k}`] = v;
2637
2669
  }
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.5",
11
11
  "private": false,
12
12
  "type": "module",
13
13
  "sideEffects": false,