jsql-neo 6.7.1 → 6.7.3
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 +13 -2
- package/index.js +1 -1
- package/lib/sql.js +140 -11
- package/package.json +3 -3
- package/postinstall.js +16 -15
- package/test/convert-subquery.test.js +88 -0
- package/test/mysql-utility-functions.test.js +48 -0
- package/test/network-policy.test.js +19 -0
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> **One engine to rule them all** — a Rust-powered embedded database that speaks your language:
|
|
4
4
|
> MySQL, PostgreSQL, MongoDB, Redis, SQL, TypeScript, **and the browser**.
|
|
5
5
|
|
|
6
|
-
> **v6.7.
|
|
6
|
+
> **v6.7.3** — stable release · [github.com/vexify-org/JSQL-neo](https://github.com/vexify-org/JSQL-neo) · [jsql.vexify.top](https://jsql.vexify.top)
|
|
7
7
|
|
|
8
8
|

|
|
9
9
|

|
|
@@ -266,7 +266,18 @@ source stating why it cannot be done locally:
|
|
|
266
266
|
| `jsql star --token-check` | `api.github.com` | star status only exists on the GitHub account | `JSQL_OFFLINE=1` |
|
|
267
267
|
| `jsql update` | `registry.npmjs.org` | "is there a newer version" only exists in the registry | `JSQL_OFFLINE=1` |
|
|
268
268
|
| `jsql plugin list\|search\|info\|install` | `registry-beta.vexify.top` | the plugin catalogue only exists remotely | `JSQL_OFFLINE=1` |
|
|
269
|
-
| `npm install` (postinstall) | GitHub releases | the precompiled Rust `.node` is not in the npm tarball | `JSQL_NO_NATIVE_DOWNLOAD=1` or `JSQL_OFFLINE=1` |
|
|
269
|
+
| `npm install` (postinstall) | GitHub releases (`github.com`) | the precompiled Rust `.node` is not in the npm tarball | `JSQL_NO_NATIVE_DOWNLOAD=1` or `JSQL_OFFLINE=1` |
|
|
270
|
+
|
|
271
|
+
`npm install` downloads the prebuilt addon from the official GitHub release host
|
|
272
|
+
and verifies it against the published `SHA256SUMS`; a mismatch (or a missing
|
|
273
|
+
manifest) aborts the download. **No third-party mirror is used by default.** If
|
|
274
|
+
`github.com` is unreachable you can opt into a proxy explicitly:
|
|
275
|
+
|
|
276
|
+
| Variable | Meaning |
|
|
277
|
+
| --- | --- |
|
|
278
|
+
| `JSQL_GHPROXY` | Comma-separated proxy prefixes, tried in order (e.g. `https://gh-proxy.com/`). Empty/unset = direct only. |
|
|
279
|
+
| `JSQL_GHPROXY_TOKEN` | Optional bearer token, sent as `Authorization: Bearer …` **only** to the proxy origins listed in `JSQL_GHPROXY` (never to `github.com`, never on cross-origin redirects). |
|
|
280
|
+
| `JSQL_NATIVE_SHA256` | Pin the expected digest instead of reading `SHA256SUMS`. |
|
|
270
281
|
|
|
271
282
|
`JSQL_OFFLINE=1` disables every external request at once; affected commands
|
|
272
283
|
report the reason instead of failing silently. Loopback traffic (the
|
package/index.js
CHANGED
package/lib/sql.js
CHANGED
|
@@ -2705,6 +2705,32 @@ class Parser {
|
|
|
2705
2705
|
this.expect('op', ')');
|
|
2706
2706
|
return { type: 'cast', expr, dataType };
|
|
2707
2707
|
}
|
|
2708
|
+
// CONVERT(expr, type) —— MySQL 的另一种 CAST 写法,语义与 CAST 完全一致,
|
|
2709
|
+
// 直接复用 cast 节点。此前完全没解析,SIGNED / CHAR 被当成列名,
|
|
2710
|
+
// 报 "no such column: SIGNED"。
|
|
2711
|
+
// `CONVERT(expr USING charset)` 是另一套语法,这里不支持(会报语法错,
|
|
2712
|
+
// 比静默当成列引用好)。
|
|
2713
|
+
if (String(t.value).toUpperCase() === 'CONVERT' && this.peek().type === 'op' && this.peek().value === '(') {
|
|
2714
|
+
this.next();
|
|
2715
|
+
const expr = this.parseScalar();
|
|
2716
|
+
this.expect('op', ',');
|
|
2717
|
+
const typeTok = this.next();
|
|
2718
|
+
let dataType = String(typeTok.value).toUpperCase();
|
|
2719
|
+
if (this.peek().type === 'op' && this.peek().value === '(') {
|
|
2720
|
+
this.next();
|
|
2721
|
+
let depth = 1;
|
|
2722
|
+
let spec = '';
|
|
2723
|
+
while (depth > 0 && this.peek().type !== 'eof') {
|
|
2724
|
+
const tk = this.next();
|
|
2725
|
+
if (tk.type === 'op' && tk.value === '(') depth++;
|
|
2726
|
+
else if (tk.type === 'op' && tk.value === ')') { depth--; if (depth === 0) break; }
|
|
2727
|
+
spec += tk.value;
|
|
2728
|
+
}
|
|
2729
|
+
dataType += '(' + spec + ')';
|
|
2730
|
+
}
|
|
2731
|
+
this.expect('op', ')');
|
|
2732
|
+
return { type: 'cast', expr, dataType };
|
|
2733
|
+
}
|
|
2708
2734
|
// 零参时间函数:CURRENT_DATE / CURRENT_TIME / CURRENT_TIMESTAMP(可省略括号)。
|
|
2709
2735
|
// 此前不在 KEYWORDS 里,被当成列名解析 → "no such column: CURRENT_DATE"
|
|
2710
2736
|
if (['CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP'].includes(String(t.value).toUpperCase())) {
|
|
@@ -3378,9 +3404,90 @@ function mysqlNum(v) {
|
|
|
3378
3404
|
const n = Number(m[0]);
|
|
3379
3405
|
return Number.isFinite(n) ? n : 0;
|
|
3380
3406
|
}
|
|
3407
|
+
// Issue #108:二进制值按 latin1 文本参与数字上下文(MySQL 的隐式转换)
|
|
3408
|
+
if (isBinaryValue(v)) return mysqlNum(v.toString());
|
|
3381
3409
|
return 0;
|
|
3382
3410
|
}
|
|
3383
3411
|
|
|
3412
|
+
// ---------------------------------------------------------------------------
|
|
3413
|
+
// 二进制字符串(Issue #108)
|
|
3414
|
+
//
|
|
3415
|
+
// 问题:UNHEX() 曾用 `Buffer.from(h, 'hex').toString('latin1')` 把字节塞进
|
|
3416
|
+
// JS 字符串,HEX()/LENGTH()/BIT_LENGTH() 再用 UTF-8 解释该字符串 —— 于是
|
|
3417
|
+
// 码点 0x80-0xFF 被二次编码成两个字节(UNHEX('DEADBEEF') 的 4 字节变成 8 字节,
|
|
3418
|
+
// HEX(UNHEX('DEADBEEF')) 变成 'C39EC2ADC2BEC3AF')。数据被静默放大,无法往返。
|
|
3419
|
+
//
|
|
3420
|
+
// 方案:UNHEX() 返回 BinaryValue(内部持有 Buffer),字节层面无损;HEX /
|
|
3421
|
+
// LENGTH / BIT_LENGTH / CHAR_LENGTH 识别该类型并直接按字节数/字节内容处理。
|
|
3422
|
+
// BinaryValue 不是字符串,但在需要文本的地方(比较、CONCAT、输出)通过
|
|
3423
|
+
// toString() 降级为 latin1 文本,与 MySQL「binary string 也当字符串用」一致。
|
|
3424
|
+
// 结果信封(rows)里仍会降级成普通字符串(见 finalizeResultBigInts),
|
|
3425
|
+
// 所以对外 API 与旧行为保持兼容。
|
|
3426
|
+
// ---------------------------------------------------------------------------
|
|
3427
|
+
class BinaryValue {
|
|
3428
|
+
constructor(buf) {
|
|
3429
|
+
this.bytes = Buffer.isBuffer(buf) ? Buffer.from(buf) : Buffer.from(String(buf), 'latin1');
|
|
3430
|
+
}
|
|
3431
|
+
/** 字节数(MySQL 的 LENGTH / CHAR_LENGTH 对二进制串都按字节计) */
|
|
3432
|
+
get length() { return this.bytes.length; }
|
|
3433
|
+
toString() { return this.bytes.toString('latin1'); }
|
|
3434
|
+
valueOf() { return this.bytes.toString('latin1'); }
|
|
3435
|
+
toJSON() { return this.bytes.toString('latin1'); }
|
|
3436
|
+
[Symbol.toPrimitive]() { return this.bytes.toString('latin1'); }
|
|
3437
|
+
}
|
|
3438
|
+
|
|
3439
|
+
function isBinaryValue(v) { return v instanceof BinaryValue; }
|
|
3440
|
+
|
|
3441
|
+
/** 去重 / GROUP BY / 窗口分组用的键:二进制值按文本,其余保持原逻辑 */
|
|
3442
|
+
function valueKey(v) {
|
|
3443
|
+
if (isBinaryValue(v)) return v.toString();
|
|
3444
|
+
return typeof v === 'object' ? JSON.stringify(v) : String(v);
|
|
3445
|
+
}
|
|
3446
|
+
|
|
3447
|
+
// ---------------------------------------------------------------------------
|
|
3448
|
+
// 位运算(Issue #109)
|
|
3449
|
+
//
|
|
3450
|
+
// MySQL 的 `<<` / `>>`:操作数先按 64 位无符号整数处理(小数部分被丢),
|
|
3451
|
+
// 移位量取整数部分(`1 << 1.9` = `1 << 1` = 2)。此前用的是
|
|
3452
|
+
// `l * Math.pow(2, r)`,既没截断小数(1 << 1.9 = 3.73),又在大移位量下
|
|
3453
|
+
// 丢浮点精度(1 << 63 = 9223372036854776000)。这里全程用 BigInt 精确计算,
|
|
3454
|
+
// 结果超过 2^53 时保留 BigInt(由 finalizeResultBigInts 转成字符串输出)。
|
|
3455
|
+
// 边界与 MySQL 一致:移位量 < 0 或 >= 64 → 0;64 位溢出按无符号回绕。
|
|
3456
|
+
// ---------------------------------------------------------------------------
|
|
3457
|
+
const U64_MASK = (1n << 64n) - 1n;
|
|
3458
|
+
const MAX_SAFE_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
3459
|
+
|
|
3460
|
+
/** MySQL 整数转换:小数四舍五入(远离零),负数按补码转到 64 位无符号 */
|
|
3461
|
+
function toUint64(v) {
|
|
3462
|
+
let n;
|
|
3463
|
+
if (typeof v === 'bigint') n = v;
|
|
3464
|
+
else if (typeof v === 'boolean') n = v ? 1n : 0n;
|
|
3465
|
+
else if (isBinaryValue(v)) n = BigInt(Math.round(mysqlNum(v.toString())));
|
|
3466
|
+
else {
|
|
3467
|
+
const x = mysqlNum(v);
|
|
3468
|
+
// 四舍五入且远离零:-1.5 → -2(Math.round 会得到 -1)
|
|
3469
|
+
n = BigInt(x >= 0 ? Math.floor(x + 0.5) : Math.ceil(x - 0.5));
|
|
3470
|
+
}
|
|
3471
|
+
return n & U64_MASK;
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
/** BigInt 结果 → 对外值:安全整数范围内给 number,否则保留 BigInt(输出为字符串) */
|
|
3475
|
+
function fromUint64(n) {
|
|
3476
|
+
return n <= MAX_SAFE_BIGINT ? Number(n) : n;
|
|
3477
|
+
}
|
|
3478
|
+
|
|
3479
|
+
function sqlBitShift(l, r, op) {
|
|
3480
|
+
const a = toUint64(l);
|
|
3481
|
+
// 移位量只取整数部分(trunc,不是 round)—— MySQL 丢弃小数位
|
|
3482
|
+
const rawShift = mysqlNum(r);
|
|
3483
|
+
if (!Number.isFinite(rawShift)) return 0;
|
|
3484
|
+
const s = Math.trunc(rawShift);
|
|
3485
|
+
if (s < 0 || s >= 64) return 0;
|
|
3486
|
+
const shift = BigInt(s);
|
|
3487
|
+
if (op === '<<') return fromUint64((a << shift) & U64_MASK);
|
|
3488
|
+
return fromUint64(a >> shift);
|
|
3489
|
+
}
|
|
3490
|
+
|
|
3384
3491
|
// ---------------------------------------------------------------------------
|
|
3385
3492
|
// CHECK 约束(Issue #70)
|
|
3386
3493
|
//
|
|
@@ -3612,8 +3719,8 @@ function resolveOperand(operand, row, ctx) {
|
|
|
3612
3719
|
case '^': return (mysqlNum(l) | 0) ^ (mysqlNum(r) | 0);
|
|
3613
3720
|
// P1-22: JavaScript 位运算只使用 32 位整数,移位量对 32 取模
|
|
3614
3721
|
// 1 << 32 = 1 << 0 = 1,但 SQL 中 1 << 32 = 4294967296
|
|
3615
|
-
|
|
3616
|
-
case '>>': return
|
|
3722
|
+
// Issue #109:移位量截断为整数并用 BigInt 精确计算(见 sqlBitShift)
|
|
3723
|
+
case '<<': case '>>': return sqlBitShift(l, r, operand.op);
|
|
3617
3724
|
}
|
|
3618
3725
|
return null;
|
|
3619
3726
|
}
|
|
@@ -3653,8 +3760,8 @@ function resolveOperand(operand, row, ctx) {
|
|
|
3653
3760
|
case '&': return (mysqlNum(l) | 0) & (mysqlNum(r) | 0);
|
|
3654
3761
|
case '|': return (mysqlNum(l) | 0) | (mysqlNum(r) | 0);
|
|
3655
3762
|
case '^': return (mysqlNum(l) | 0) ^ (mysqlNum(r) | 0);
|
|
3656
|
-
|
|
3657
|
-
case '>>': return
|
|
3763
|
+
// Issue #109:移位量截断 + BigInt 精确计算
|
|
3764
|
+
case '<<': case '>>': return sqlBitShift(l, r, operand.op);
|
|
3658
3765
|
default: return null;
|
|
3659
3766
|
}
|
|
3660
3767
|
}
|
|
@@ -4113,8 +4220,14 @@ function applyScalarFunction(fnNode, row, ctx) {
|
|
|
4113
4220
|
// CHAR_LENGTH / CHARACTER_LENGTH 返回**字符**数。
|
|
4114
4221
|
// 此前 LENGTH 返回 String#length:「héllo」得 5(应为 6)、「🚀🌟」得 4(应为 8),
|
|
4115
4222
|
// 按字节计长的 varchar(n) 长度校验会被绕过;OCTET_LENGTH 则整个缺失(静默 NULL)。
|
|
4116
|
-
|
|
4117
|
-
case '
|
|
4223
|
+
// Issue #108:二进制值按原始字节计数,不能再走 UTF-8 编码(会被放大)
|
|
4224
|
+
case 'LENGTH': case 'OCTET_LENGTH':
|
|
4225
|
+
return args[0] == null ? null
|
|
4226
|
+
: (isBinaryValue(args[0]) ? args[0].bytes.length : Buffer.byteLength(String(args[0]), 'utf8'));
|
|
4227
|
+
case 'CHAR_LENGTH': case 'CHARACTER_LENGTH':
|
|
4228
|
+
// MySQL:二进制串的 CHAR_LENGTH 也等于字节数
|
|
4229
|
+
return args[0] == null ? null
|
|
4230
|
+
: (isBinaryValue(args[0]) ? args[0].bytes.length : String(args[0]).length);
|
|
4118
4231
|
// TRIM(s) / TRIM([LEADING|TRAILING|BOTH] chars FROM s) / TRIM(s, chars)
|
|
4119
4232
|
case 'TRIM': {
|
|
4120
4233
|
if (args[0] == null) return null;
|
|
@@ -4396,6 +4509,8 @@ function applyScalarFunction(fnNode, row, ctx) {
|
|
|
4396
4509
|
// MAKE_SET / EXPORT_SET / SOUNDEX 仍未实现(未在文档中承诺)。
|
|
4397
4510
|
case 'BIT_LENGTH': {
|
|
4398
4511
|
if (args[0] == null) return null;
|
|
4512
|
+
// Issue #108:二进制值按原始字节数 × 8
|
|
4513
|
+
if (isBinaryValue(args[0])) return args[0].bytes.length * 8;
|
|
4399
4514
|
return Buffer.byteLength(String(args[0]), 'utf8') * 8;
|
|
4400
4515
|
}
|
|
4401
4516
|
case 'BIN': case 'OCT': {
|
|
@@ -4411,13 +4526,17 @@ function applyScalarFunction(fnNode, row, ctx) {
|
|
|
4411
4526
|
const n = typeof v === 'bigint' ? v : BigInt(Math.trunc(v));
|
|
4412
4527
|
return (n < 0n ? BigInt.asUintN(64, n) : n).toString(16).toUpperCase();
|
|
4413
4528
|
}
|
|
4529
|
+
// Issue #108:二进制值直接按字节转十六进制,保证 HEX(UNHEX(x)) 恒等
|
|
4530
|
+
if (isBinaryValue(v)) return v.bytes.toString('hex').toUpperCase();
|
|
4414
4531
|
return Buffer.from(String(v), 'utf8').toString('hex').toUpperCase();
|
|
4415
4532
|
}
|
|
4416
4533
|
case 'UNHEX': {
|
|
4417
4534
|
if (args[0] == null) return null;
|
|
4418
4535
|
const h = String(args[0]);
|
|
4419
4536
|
if (h.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(h)) return null;
|
|
4420
|
-
|
|
4537
|
+
// Issue #108:返回 BinaryValue 而不是 latin1 字符串 —— 后者在 UTF-8
|
|
4538
|
+
// 编解码往返中会把 0x80-0xFF 摊成两字节,数据被静默放大。
|
|
4539
|
+
return new BinaryValue(Buffer.from(h, 'hex'));
|
|
4421
4540
|
}
|
|
4422
4541
|
case 'CONV': {
|
|
4423
4542
|
if (args[0] == null || args[1] == null || args[2] == null) return null;
|
|
@@ -5405,11 +5524,16 @@ function strictNumeric(v) {
|
|
|
5405
5524
|
// MySQL 默认 collation(utf8mb4_general_ci)下字符串比较不区分大小写,
|
|
5406
5525
|
// 与 LIKE 保持一致。cs=true 表示显式 BINARY/COLLATE 强制大小写敏感。
|
|
5407
5526
|
function ciEq(a, b, cs) {
|
|
5527
|
+
// Issue #108:二进制值先降级为 latin1 文本再比较(MySQL 允许 binary 与文本互比)
|
|
5528
|
+
if (isBinaryValue(a)) a = a.toString();
|
|
5529
|
+
if (isBinaryValue(b)) b = b.toString();
|
|
5408
5530
|
if (cs) return a === b;
|
|
5409
5531
|
if (typeof a === 'string' && typeof b === 'string') return a.toLowerCase() === b.toLowerCase();
|
|
5410
5532
|
return String(a) === String(b);
|
|
5411
5533
|
}
|
|
5412
5534
|
function ciCompare(a, b, cs) {
|
|
5535
|
+
if (isBinaryValue(a)) a = a.toString();
|
|
5536
|
+
if (isBinaryValue(b)) b = b.toString();
|
|
5413
5537
|
if (cs) return a === b ? 0 : (a < b ? -1 : 1);
|
|
5414
5538
|
const as = String(a).toLowerCase(), bs = String(b).toLowerCase();
|
|
5415
5539
|
return as === bs ? 0 : (as < bs ? -1 : 1);
|
|
@@ -5423,6 +5547,8 @@ function sqlTruthy(v) {
|
|
|
5423
5547
|
if (v === null || v === undefined) return null;
|
|
5424
5548
|
if (typeof v === 'boolean') return v;
|
|
5425
5549
|
if (typeof v === 'number') return v !== 0;
|
|
5550
|
+
// Issue #108:二进制值按文本判定真值
|
|
5551
|
+
if (isBinaryValue(v)) return sqlTruthy(v.toString());
|
|
5426
5552
|
if (typeof v === 'string') return v !== '' && !(Number(v) === 0 && String(v).trim() !== '');
|
|
5427
5553
|
return Boolean(v);
|
|
5428
5554
|
}
|
|
@@ -5688,8 +5814,8 @@ function evaluateExpr(expr, row, ctx) {
|
|
|
5688
5814
|
case '&': return (mysqlNum(l) | 0) & (mysqlNum(r) | 0);
|
|
5689
5815
|
case '|': return (mysqlNum(l) | 0) | (mysqlNum(r) | 0);
|
|
5690
5816
|
case '^': return (mysqlNum(l) | 0) ^ (mysqlNum(r) | 0);
|
|
5691
|
-
|
|
5692
|
-
case '>>': return
|
|
5817
|
+
// Issue #109:移位量截断 + BigInt 精确计算
|
|
5818
|
+
case '<<': case '>>': return sqlBitShift(l, r, expr.op);
|
|
5693
5819
|
default: return null;
|
|
5694
5820
|
}
|
|
5695
5821
|
}
|
|
@@ -7458,7 +7584,7 @@ class SQLExecutor {
|
|
|
7458
7584
|
if (distinct) {
|
|
7459
7585
|
const seen = new Set();
|
|
7460
7586
|
values = values.filter(v => {
|
|
7461
|
-
const k =
|
|
7587
|
+
const k = valueKey(v); // Issue #108:二进制值按 latin1 文本去重
|
|
7462
7588
|
if (seen.has(k)) return false;
|
|
7463
7589
|
seen.add(k);
|
|
7464
7590
|
return true;
|
|
@@ -7562,7 +7688,7 @@ class SQLExecutor {
|
|
|
7562
7688
|
if (distinct) {
|
|
7563
7689
|
const seen = new Set();
|
|
7564
7690
|
joined = joined.filter(v => {
|
|
7565
|
-
const k =
|
|
7691
|
+
const k = valueKey(v); // Issue #108:二进制值按 latin1 文本去重
|
|
7566
7692
|
if (seen.has(k)) return false;
|
|
7567
7693
|
seen.add(k);
|
|
7568
7694
|
return true;
|
|
@@ -9477,6 +9603,7 @@ function escapeValue(value) {
|
|
|
9477
9603
|
const p = n => String(n).padStart(2, '0');
|
|
9478
9604
|
return `'${value.getUTCFullYear()}-${p(value.getUTCMonth() + 1)}-${p(value.getUTCDate())} ${p(value.getUTCHours())}:${p(value.getUTCMinutes())}:${p(value.getUTCSeconds())}'`;
|
|
9479
9605
|
}
|
|
9606
|
+
if (isBinaryValue(value)) return "UNHEX('" + value.bytes.toString('hex').toUpperCase() + "')";
|
|
9480
9607
|
if (Buffer.isBuffer(value)) return "X'" + value.toString('hex') + "'";
|
|
9481
9608
|
if (Array.isArray(value)) {
|
|
9482
9609
|
if (value.some(Array.isArray)) {
|
|
@@ -9729,6 +9856,8 @@ async function inferColumnTypes(engine, stmt, r) {
|
|
|
9729
9856
|
// 保留精度且可序列化;内部运算仍走 BigInt,精度不丢。
|
|
9730
9857
|
function finalizeBigInts(value, seen) {
|
|
9731
9858
|
if (typeof value === 'bigint') return value.toString();
|
|
9859
|
+
// Issue #108:二进制值在结果信封里降级为 latin1 字符串,对外 API 形状不变
|
|
9860
|
+
if (isBinaryValue(value)) return value.toString();
|
|
9732
9861
|
if (Array.isArray(value)) {
|
|
9733
9862
|
if (!seen) seen = new Set();
|
|
9734
9863
|
if (seen.has(value)) return value;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsql-neo",
|
|
3
|
-
"version": "6.7.
|
|
3
|
+
"version": "6.7.3",
|
|
4
4
|
"description": "JSQL-NEO — Rust-powered embedded database with WASM, REST API, B-Tree indexes, WAL, crash recovery",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"build:native": "node scripts/build-native.js",
|
|
53
53
|
"check:release": "node scripts/check-release-metadata.js",
|
|
54
54
|
"release:prep": "node scripts/release.js",
|
|
55
|
-
"test": "npm run check:release && node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/native.test.js && node test/json-functions.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/query-opt.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/dml-constraints.test.js && node test/star-nag.test.js && node test/plugin-xql.test.js && node test/bug-regression-2.test.js && node test/issue-34-35-36.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-73-76.test.js && node test/issue-77-84.test.js && node test/issue-86-99.test.js && node test/issue-101-103.test.js && node test/issue-105.test.js && node test/bigint-math.test.js && node test/release-metadata.test.js && node test/date-conversions.test.js && node test/mysql-utility-functions.test.js && node test/limit-pushdown.test.js && node test/columnar.test.js && node test/columnar-vector.test.js && node test/cast-rounding.test.js",
|
|
55
|
+
"test": "npm run check:release && node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/native.test.js && node test/json-functions.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/query-opt.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/dml-constraints.test.js && node test/star-nag.test.js && node test/plugin-xql.test.js && node test/bug-regression-2.test.js && node test/issue-34-35-36.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-73-76.test.js && node test/issue-77-84.test.js && node test/issue-86-99.test.js && node test/issue-101-103.test.js && node test/issue-105.test.js && node test/bigint-math.test.js && node test/release-metadata.test.js && node test/date-conversions.test.js && node test/mysql-utility-functions.test.js && node test/limit-pushdown.test.js && node test/columnar.test.js && node test/columnar-vector.test.js && node test/cast-rounding.test.js && node test/convert-subquery.test.js",
|
|
56
56
|
"test:parser": "node test/sql-parser.test.js",
|
|
57
57
|
"test:btree": "node test/btree.test.js",
|
|
58
58
|
"test:native": "node test/native.test.js",
|
|
59
59
|
"test:regress": "node test/regress-5.1.0.js",
|
|
60
|
-
"test:all": "npm run check:release && node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/native.test.js && node test/native-multi-instance.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/wasm.test.js && node test/coverage.js && node test/regress-5.1.0.js && node test/join.test.js && node test/btree.test.js && node test/dml-constraints.test.js && node test/savepoint.test.js && node test/alter-table.test.js && node test/null-semantics.test.js && node test/identifier-keywords.test.js && node test/issue-34-35-36.test.js && node test/sql-semantics.test.js && node test/extra-coverage.test.js && node test/filter-compile.test.js && node test/recursive-cte.test.js && node test/index-ddl.test.js && node test/mongo-group.test.js && node test/multiprotocol.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-77-84.test.js && node test/issue-86-99.test.js && node test/issue-101-103.test.js && node test/issue-105.test.js && node test/bigint-math.test.js && node test/release-metadata.test.js && node test/date-conversions.test.js && node test/mysql-utility-functions.test.js && node test/limit-pushdown.test.js && node test/columnar.test.js && node test/columnar-vector.test.js && node test/cast-rounding.test.js",
|
|
60
|
+
"test:all": "npm run check:release && node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/native.test.js && node test/native-multi-instance.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/wasm.test.js && node test/coverage.js && node test/regress-5.1.0.js && node test/join.test.js && node test/btree.test.js && node test/dml-constraints.test.js && node test/savepoint.test.js && node test/alter-table.test.js && node test/null-semantics.test.js && node test/identifier-keywords.test.js && node test/issue-34-35-36.test.js && node test/sql-semantics.test.js && node test/extra-coverage.test.js && node test/filter-compile.test.js && node test/recursive-cte.test.js && node test/index-ddl.test.js && node test/mongo-group.test.js && node test/multiprotocol.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-77-84.test.js && node test/issue-86-99.test.js && node test/issue-101-103.test.js && node test/issue-105.test.js && node test/bigint-math.test.js && node test/release-metadata.test.js && node test/date-conversions.test.js && node test/mysql-utility-functions.test.js && node test/limit-pushdown.test.js && node test/columnar.test.js && node test/columnar-vector.test.js && node test/cast-rounding.test.js && node test/convert-subquery.test.js",
|
|
61
61
|
"test:coverage": "c8 --all --include='lib/**' --exclude='lib/web_ui.js' --reporter=text --reporter=lcov node test/coverage.js",
|
|
62
62
|
"test:orms": "node examples/orms/run-all.js",
|
|
63
63
|
"test:dml": "node test/dml-constraints.test.js",
|
package/postinstall.js
CHANGED
|
@@ -30,18 +30,18 @@ const NATIVE_PATH = process.env.JSQL_NATIVE_PATH
|
|
|
30
30
|
? path.resolve(process.env.JSQL_NATIVE_PATH)
|
|
31
31
|
: path.join(ROOT, 'native', 'jsql-neo-native.node');
|
|
32
32
|
|
|
33
|
-
// GitHub
|
|
33
|
+
// GitHub 加速代理前缀(可选,默认关闭)。加速站的用法是把原始 URL 直接拼在后面:
|
|
34
34
|
// https://<host>/https://github.com/owner/repo/releases/download/vX.Y.Z/asset
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
35
|
+
// 启用方式:显式设置 JSQL_GHPROXY(逗号分隔多个,按序回退;空/未设置 = 只直连)。
|
|
36
|
+
// token(可选)只从 JSQL_GHPROXY_TOKEN 读取,并以 `Authorization: Bearer <token>`
|
|
37
|
+
// 请求头发给 **JSQL_GHPROXY 里列出的代理主机** —— 直连 github.com 时不发送;
|
|
38
|
+
// 跨源重定向时也会丢弃该请求头(见 download/fetchText 的 sameOrigin 判断)。
|
|
38
39
|
//
|
|
39
|
-
// 供应链安全(issue #25
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
// 优先级:JSQL_GHPROXY(用户显式)→
|
|
44
|
-
const DEFAULT_PROXIES = ['https://gh-proxy.com/'];
|
|
40
|
+
// 供应链安全(issue #25 / #110):代码内不内置任何加速站,也不内置任何 token。
|
|
41
|
+
// 原生下载只走两条路:官方 GitHub Release 主机(直连),或用户自己显式配置的
|
|
42
|
+
// JSQL_GHPROXY 代理;两者都必须通过 SHA256SUMS 校验(fail closed),
|
|
43
|
+
// 因此就算第三方代理被投毒也装不进去。
|
|
44
|
+
// 优先级:JSQL_GHPROXY(用户显式)→ 直连 github.com。
|
|
45
45
|
const GHPROXY = process.env.JSQL_GHPROXY !== undefined
|
|
46
46
|
? process.env.JSQL_GHPROXY
|
|
47
47
|
: '';
|
|
@@ -61,7 +61,8 @@ const GHPROXY_TOKEN = process.env.JSQL_GHPROXY_TOKEN || '';
|
|
|
61
61
|
// JSQL_NATIVE_TAG=vX.Y.Z|latest 指定远端 tag;默认 v<package.version>
|
|
62
62
|
// JSQL_AUTO_DOWNLOAD_NATIVE=1 / JSQL_NATIVE_DOWNLOAD=1 仍然兼容(显式开)
|
|
63
63
|
//
|
|
64
|
-
// 供应链安全(issue #25):不内置任何加速站/token
|
|
64
|
+
// 供应链安全(issue #25 / #110):不内置任何加速站/token —— 代理只能由用户
|
|
65
|
+
// 显式 JSQL_GHPROXY 指定,未设置时只直连官方 GitHub Release 主机;
|
|
65
66
|
// 且下载必须通过 SHA256SUMS 校验(除非用户显式 JSQL_ALLOW_UNVERIFIED_NATIVE=1)。
|
|
66
67
|
const DOWNLOAD_DISABLED = isOffline()
|
|
67
68
|
|| process.env.JSQL_NO_NATIVE_DOWNLOAD === '1'
|
|
@@ -81,14 +82,14 @@ function proxyHeaders() {
|
|
|
81
82
|
|
|
82
83
|
/**
|
|
83
84
|
* 生成候选下载地址列表(按优先级):
|
|
84
|
-
* JSQL_GHPROXY
|
|
85
|
+
* JSQL_GHPROXY 指定的代理(用户显式)→ 直连官方 github.com
|
|
86
|
+
* 没有内置的第三方加速站;JSQL_GHPROXY 为空时列表里只有直连一项。
|
|
85
87
|
*/
|
|
86
88
|
function proxyCandidates(raw) {
|
|
87
89
|
const bases = String(GHPROXY || '')
|
|
88
90
|
.split(',')
|
|
89
91
|
.map((s) => s.trim())
|
|
90
92
|
.filter(Boolean)
|
|
91
|
-
.concat(DEFAULT_PROXIES)
|
|
92
93
|
.concat('');
|
|
93
94
|
const list = [];
|
|
94
95
|
for (const base of bases) {
|
|
@@ -464,12 +465,12 @@ async function downloadAndVerify(opts = {}) {
|
|
|
464
465
|
console.warn('[jsql-neo] WARNING: JSQL_ALLOW_UNVERIFIED_NATIVE=1 — native module integrity is NOT verified.');
|
|
465
466
|
}
|
|
466
467
|
|
|
467
|
-
//
|
|
468
|
+
// 依次尝试:JSQL_GHPROXY 显式指定的代理 → 直连官方 GitHub Release 主机
|
|
468
469
|
for (const cand of proxyCandidates(raw)) {
|
|
469
470
|
console.log(`[jsql-neo] fetching native module (${tag}): ${cand.url}`);
|
|
470
471
|
const tmp = `${NATIVE_PATH}.${process.pid}.download`;
|
|
471
472
|
try {
|
|
472
|
-
//
|
|
473
|
+
// 代理鉴权(JSQL_GHPROXY_TOKEN)走 Authorization 头,且只发给代理主机;直连时不带
|
|
473
474
|
await download(cand.url, tmp, cand.viaProxy ? proxyHeaders() : undefined);
|
|
474
475
|
if (expected) {
|
|
475
476
|
const actual = sha256File(tmp);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/* ---- CONVERT / BINARY / GROUP_CONCAT / HAVING / IN 子查询的 NULL 语义 ---- */
|
|
2
|
+
/*
|
|
3
|
+
* 这一轮差分探针(16 条)只错 2 条,都是 `CONVERT(expr, type)` 没被解析
|
|
4
|
+
* (报 no such column: SIGNED)—— 功能缺失,不是静默错值。补上后连同
|
|
5
|
+
* 同批验证过、但此前没有回归覆盖的边界一起钉住。
|
|
6
|
+
*/
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const ROOT = path.join(__dirname, '..');
|
|
9
|
+
const { Database, executeSQL } = require(path.join(ROOT, 'index.js'));
|
|
10
|
+
|
|
11
|
+
let pass = 0, fail = 0;
|
|
12
|
+
function ok(name, cond, got) {
|
|
13
|
+
if (cond) { pass++; console.log('[OK] ' + name); }
|
|
14
|
+
else { fail++; console.log('[FAIL] ' + name + ' -> ' + JSON.stringify(got)); }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
(async () => {
|
|
18
|
+
const db = new Database(':memory:', { autoSave: false });
|
|
19
|
+
await db.createTable('t', {
|
|
20
|
+
id: { type: 'integer', primaryKey: true, autoIncrement: true },
|
|
21
|
+
g: { type: 'string' }, v: { type: 'integer' },
|
|
22
|
+
});
|
|
23
|
+
await db.insert('t', [{ g: 'a', v: 1 }, { g: 'a', v: 2 }, { g: 'b', v: 3 }]);
|
|
24
|
+
await db.createTable('s', {
|
|
25
|
+
id: { type: 'integer', primaryKey: true, autoIncrement: true }, v: { type: 'integer' },
|
|
26
|
+
});
|
|
27
|
+
await db.insert('s', [{ v: 1 }, { v: null }]);
|
|
28
|
+
await db.createTable('empty', {
|
|
29
|
+
id: { type: 'integer', primaryKey: true, autoIncrement: true }, v: { type: 'integer' },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const q = async (sql) => (await executeSQL(db, sql, { safety: false })).rows[0][0];
|
|
33
|
+
|
|
34
|
+
// ---------- CONVERT(expr, type):与 CAST 语义一致 ----------
|
|
35
|
+
ok("CONVERT('12abc', SIGNED) = 12", await q("SELECT CONVERT('12abc', SIGNED)") === 12, null);
|
|
36
|
+
ok('CONVERT(42, CHAR) = "42"', await q('SELECT CONVERT(42, CHAR)') === '42', null);
|
|
37
|
+
ok('CONVERT(1.9, SIGNED) = 2(四舍五入)', await q('SELECT CONVERT(1.9, SIGNED)') === 2, null);
|
|
38
|
+
ok('CONVERT(12.9, INTEGER) = 13', await q('SELECT CONVERT(12.9, INTEGER)') === 13, null);
|
|
39
|
+
ok("CONVERT('3.14159', DECIMAL(10,2)) = 3.14",
|
|
40
|
+
await q("SELECT CONVERT('3.14159', DECIMAL(10,2))") === 3.14, null);
|
|
41
|
+
ok('CONVERT(NULL, SIGNED) = NULL', await q('SELECT CONVERT(NULL, SIGNED)') === null, null);
|
|
42
|
+
ok('CONVERT(-5, UNSIGNED) 按 2^64 回绕',
|
|
43
|
+
String(await q('SELECT CONVERT(-5, UNSIGNED)')) === '18446744073709551611', null);
|
|
44
|
+
ok('CONVERT 与 CAST 结果一致',
|
|
45
|
+
await q('SELECT CONVERT(12.9, SIGNED)') === await q('SELECT CAST(12.9 AS SIGNED)'), null);
|
|
46
|
+
|
|
47
|
+
// ---------- BINARY:大小写敏感 ----------
|
|
48
|
+
ok("BINARY g = 'A' 不命中小写 'a'",
|
|
49
|
+
await q("SELECT COUNT(*) AS c FROM t WHERE BINARY g = 'A'") === 0, null);
|
|
50
|
+
ok("默认 collation 下 g = 'A' 命中 'a'(CI)",
|
|
51
|
+
await q("SELECT COUNT(*) AS c FROM t WHERE g = 'A'") === 2, null);
|
|
52
|
+
|
|
53
|
+
// ---------- GROUP_CONCAT ----------
|
|
54
|
+
ok('GROUP_CONCAT 默认逗号', await q('SELECT GROUP_CONCAT(v) AS x FROM t') === '1,2,3', null);
|
|
55
|
+
ok("GROUP_CONCAT SEPARATOR '|'",
|
|
56
|
+
await q("SELECT GROUP_CONCAT(v SEPARATOR '|') AS x FROM t") === '1|2|3', null);
|
|
57
|
+
ok('GROUP_CONCAT ORDER BY DESC',
|
|
58
|
+
await q('SELECT GROUP_CONCAT(v ORDER BY v DESC) AS x FROM t') === '3,2,1', null);
|
|
59
|
+
ok('GROUP_CONCAT DISTINCT', await q('SELECT GROUP_CONCAT(DISTINCT g) AS x FROM t') === 'a,b', null);
|
|
60
|
+
|
|
61
|
+
// ---------- HAVING:表达式与别名等价 ----------
|
|
62
|
+
const h1 = JSON.stringify((await executeSQL(db, 'SELECT g, SUM(v) AS s FROM t GROUP BY g HAVING SUM(v) > 2', { safety: false })).rows);
|
|
63
|
+
const h2 = JSON.stringify((await executeSQL(db, 'SELECT g, SUM(v) AS s FROM t GROUP BY g HAVING s > 2', { safety: false })).rows);
|
|
64
|
+
ok('HAVING 聚合表达式', h1 === '[["a",3],["b",3]]', h1);
|
|
65
|
+
ok('HAVING 用别名与表达式结果一致', h1 === h2, { h1, h2 });
|
|
66
|
+
|
|
67
|
+
// ---------- IN / NOT IN 子查询的三值逻辑 ----------
|
|
68
|
+
ok('IN 子查询命中', await q('SELECT COUNT(*) AS c FROM t WHERE v IN (SELECT v FROM s)') === 1, null);
|
|
69
|
+
// 关键:子查询含 NULL 时,NOT IN 对任何行都不成立(结果集为空)
|
|
70
|
+
ok('NOT IN 含 NULL → 0 行(三值逻辑)',
|
|
71
|
+
await q('SELECT COUNT(*) AS c FROM t WHERE v NOT IN (SELECT v FROM s)') === 0, null);
|
|
72
|
+
ok('IN 空子查询 → 0 行',
|
|
73
|
+
await q('SELECT COUNT(*) AS c FROM t WHERE v IN (SELECT v FROM empty)') === 0, null);
|
|
74
|
+
ok('NOT IN 空子查询 → 全部行',
|
|
75
|
+
await q('SELECT COUNT(*) AS c FROM t WHERE v NOT IN (SELECT v FROM empty)') === 3, null);
|
|
76
|
+
|
|
77
|
+
// ---------- EXISTS / NOT EXISTS ----------
|
|
78
|
+
ok('EXISTS 相关子查询',
|
|
79
|
+
await q('SELECT COUNT(*) AS c FROM t WHERE EXISTS (SELECT 1 FROM s WHERE s.v = t.v)') === 1, null);
|
|
80
|
+
ok('NOT EXISTS 相关子查询',
|
|
81
|
+
await q('SELECT COUNT(*) AS c FROM t WHERE NOT EXISTS (SELECT 1 FROM s WHERE s.v = t.v)') === 2, null);
|
|
82
|
+
|
|
83
|
+
console.log(`\n${pass} passed, ${fail} failed`);
|
|
84
|
+
process.exit(fail === 0 ? 0 : 1);
|
|
85
|
+
})().catch(e => {
|
|
86
|
+
console.log('[FAIL] unexpected exception: ' + e.stack.split('\n').slice(0, 3).join('\n'));
|
|
87
|
+
process.exit(1);
|
|
88
|
+
});
|
|
@@ -62,6 +62,54 @@ function ok(name, cond, got) {
|
|
|
62
62
|
ok('SOUNDEX 空串', await q("SELECT SOUNDEX('')") === '', null);
|
|
63
63
|
ok('SOUNDEX(NULL) → NULL', await q('SELECT SOUNDEX(NULL)') === null, null);
|
|
64
64
|
|
|
65
|
+
// ---------- 位移运算符(Issue #109)----------
|
|
66
|
+
// MySQL:移位量只取整数部分(trunc),操作数按 64 位无符号整数处理,
|
|
67
|
+
// 结果超过 2^53 时保留精确值(以字符串输出,与 #38 的大整数约定一致)。
|
|
68
|
+
ok('#109 1 << 1.9 = 2', await q('SELECT 1 << 1.9') === 2, null);
|
|
69
|
+
ok('#109 1 << 1.5 = 2', await q('SELECT 1 << 1.5') === 2, null);
|
|
70
|
+
ok('#109 1 << 2.9 = 4', await q('SELECT 1 << 2.9') === 4, null);
|
|
71
|
+
ok('#109 8 >> 1.9 = 4', await q('SELECT 8 >> 1.9') === 4, null);
|
|
72
|
+
ok('#109 7 >> 1.5 = 3', await q('SELECT 7 >> 1.5') === 3, null);
|
|
73
|
+
ok('#109 1 << 0.9 = 1', await q('SELECT 1 << 0.9') === 1, null);
|
|
74
|
+
ok('#109 1 << 0 = 1', await q('SELECT 1 << 0') === 1, null);
|
|
75
|
+
ok('#109 1 << 8 = 256(普通值仍是 number)', await q('SELECT 1 << 8') === 256, null);
|
|
76
|
+
ok('#109 1 << 31 = 2147483648(不按 32 位截断)', await q('SELECT 1 << 31') === 2147483648, null);
|
|
77
|
+
ok('#109 1 << 63 精确', String(await q('SELECT 1 << 63')) === '9223372036854775808', null);
|
|
78
|
+
ok('#109 1 << 62 精确', String(await q('SELECT 1 << 62')) === '4611686018427387904', null);
|
|
79
|
+
ok('#109 1 << 64 按 64 位回绕为 0', await q('SELECT 1 << 64') === 0, null);
|
|
80
|
+
ok('#109 8 >> 64 = 0', await q('SELECT 8 >> 64') === 0, null);
|
|
81
|
+
ok('#109 负移位量 → 0', await q('SELECT 1 << -1') === 0, null);
|
|
82
|
+
ok('#109 18446744073709551615 >> 1 精确',
|
|
83
|
+
String(await q('SELECT 18446744073709551615 >> 1')) === '9223372036854775807', null);
|
|
84
|
+
ok('#109 负数按无符号 64 位解释(-1 << 1)',
|
|
85
|
+
String(await q('SELECT -1 << 1')) === '18446744073709551614', null);
|
|
86
|
+
ok('#109 负数右移按无符号(-8 >> 1)',
|
|
87
|
+
String(await q('SELECT -8 >> 1')) === '9223372036854775804', null);
|
|
88
|
+
ok('#109 小数操作数四舍五入(1.9 << 1 = 4)', await q('SELECT 1.9 << 1') === 4, null);
|
|
89
|
+
ok('#109 移位结果可继续参与运算(1 << 4 + 1)', await q('SELECT (1 << 4) + 1') === 17, null);
|
|
90
|
+
|
|
91
|
+
// ---------- UNHEX / HEX 字节往返(Issue #108)----------
|
|
92
|
+
ok("#108 HEX(UNHEX('DEADBEEF')) 往返", await q("SELECT HEX(UNHEX('DEADBEEF'))") === 'DEADBEEF', null);
|
|
93
|
+
ok("#108 LENGTH(UNHEX('DEADBEEF')) = 4", await q("SELECT LENGTH(UNHEX('DEADBEEF'))") === 4, null);
|
|
94
|
+
ok("#108 BIT_LENGTH(UNHEX('DEADBEEF')) = 32", await q("SELECT BIT_LENGTH(UNHEX('DEADBEEF'))") === 32, null);
|
|
95
|
+
ok("#108 HEX(UNHEX('80')) 不被 UTF-8 放大", await q("SELECT HEX(UNHEX('80'))") === '80', null);
|
|
96
|
+
ok("#108 HEX(UNHEX('FF'))", await q("SELECT HEX(UNHEX('FF'))") === 'FF', null);
|
|
97
|
+
ok("#108 LENGTH(UNHEX('80')) = 1", await q("SELECT LENGTH(UNHEX('80'))") === 1, null);
|
|
98
|
+
ok("#108 含 0x00 的二进制串", await q("SELECT HEX(UNHEX('00FF00'))") === '00FF00', null);
|
|
99
|
+
ok("#108 空串往返", await q("SELECT HEX(UNHEX(''))") === '', null);
|
|
100
|
+
{
|
|
101
|
+
const allBytes = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0')).join('').toUpperCase();
|
|
102
|
+
ok('#108 0x00-0xFF 全字节 HEX 往返恒等',
|
|
103
|
+
await q(`SELECT HEX(UNHEX('${allBytes}'))`) === allBytes, null);
|
|
104
|
+
ok('#108 全字节 LENGTH = 256', await q(`SELECT LENGTH(UNHEX('${allBytes}'))`) === 256, null);
|
|
105
|
+
ok('#108 全字节 BIT_LENGTH = 2048', await q(`SELECT BIT_LENGTH(UNHEX('${allBytes}'))`) === 2048, null);
|
|
106
|
+
ok('#108 全字节 CHAR_LENGTH = 256', await q(`SELECT CHAR_LENGTH(UNHEX('${allBytes}'))`) === 256, null);
|
|
107
|
+
}
|
|
108
|
+
ok('#108 二进制串与文本可比较', await q("SELECT UNHEX('4142') = 'AB'") === 1, null);
|
|
109
|
+
ok('#108 二进制串可 CONCAT', await q("SELECT CONCAT(UNHEX('4142'), 'c')") === 'ABc', null);
|
|
110
|
+
ok('#108 对 HEX 结果再取长度', await q("SELECT LENGTH(HEX(UNHEX('DEADBEEF')))") === 8, null);
|
|
111
|
+
ok('#108 文本 HEX 仍按 UTF-8 字节', await q("SELECT HEX('中文')") === 'E4B8ADE69687', null);
|
|
112
|
+
|
|
65
113
|
console.log(`\n${pass} passed, ${fail} failed`);
|
|
66
114
|
process.exit(fail === 0 ? 0 : 1);
|
|
67
115
|
})().catch(e => {
|
|
@@ -104,6 +104,25 @@ function resetCalls() { calls.length = 0; }
|
|
|
104
104
|
ok('jsql plugin list 离线抛 JSQL_OFFLINE', perr && perr.code === 'JSQL_OFFLINE', perr && perr.code);
|
|
105
105
|
ok('jsql plugin list 离线不出网', calls.length === 0, calls);
|
|
106
106
|
|
|
107
|
+
// ---------- 原生下载供应链策略(Issue #110)----------
|
|
108
|
+
// 文档曾声称「只走官方 GitHub Release 主机」,而 postinstall.js 实际会默认
|
|
109
|
+
// 优先走第三方代理 gh-proxy.com。这里钉死修正后的策略:不内置任何代理,
|
|
110
|
+
// 代理只能由用户显式 JSQL_GHPROXY 指定,且文档与代码口径一致。
|
|
111
|
+
{
|
|
112
|
+
const post = fs.readFileSync(path.join(ROOT, 'postinstall.js'), 'utf8');
|
|
113
|
+
ok('#110 postinstall 不内置 DEFAULT_PROXIES', !/DEFAULT_PROXIES/.test(post), null);
|
|
114
|
+
ok('#110 postinstall 不内置 gh-proxy.com', !/gh-proxy\.com/.test(post), null);
|
|
115
|
+
ok('#110 postinstall 仍支持显式 JSQL_GHPROXY', /JSQL_GHPROXY/.test(post), null);
|
|
116
|
+
ok('#110 postinstall 仍强制 SHA256 校验(fail closed)',
|
|
117
|
+
/expectedHashFromManifest/.test(post) && /refusing to download an unverified native module/.test(post), null);
|
|
118
|
+
const readme = fs.readFileSync(path.join(ROOT, 'README.md'), 'utf8');
|
|
119
|
+
const security = fs.readFileSync(path.join(ROOT, 'SECURITY.md'), 'utf8');
|
|
120
|
+
ok('#110 README 说明 JSQL_GHPROXY 与 token 作用域',
|
|
121
|
+
/JSQL_GHPROXY/.test(readme) && /JSQL_GHPROXY_TOKEN/.test(readme), null);
|
|
122
|
+
ok('#110 SECURITY 不再声称「仅官方主机」而无代理例外',
|
|
123
|
+
/JSQL_GHPROXY/.test(security) && /No third-party mirror is built/i.test(security), null);
|
|
124
|
+
}
|
|
125
|
+
|
|
107
126
|
// ---------- 恢复 ----------
|
|
108
127
|
process.env.JSQL_OFFLINE = saved === undefined ? '' : saved;
|
|
109
128
|
if (saved === undefined) delete process.env.JSQL_OFFLINE;
|