jsql-neo 6.6.4 → 6.6.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.
- package/README.md +19 -1
- package/index.js +1 -1
- package/lib/multiserver.js +2 -0
- package/lib/sql.js +281 -15
- package/package.json +4 -3
- package/test/bigint-math.test.js +63 -0
- package/test/date-conversions.test.js +58 -0
- package/test/issue-105.test.js +87 -0
- package/test/mysql-utility-functions.test.js +70 -0
- package/test/release-metadata.test.js +98 -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.6.
|
|
6
|
+
> **v6.6.6** — 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
|

|
|
@@ -196,6 +196,20 @@ To check which native addon this installation is actually using:
|
|
|
196
196
|
`UNVERIFIED` / `UNREADABLE`.
|
|
197
197
|
- `jsql native refresh` — re-fetches a checksum-verified addon
|
|
198
198
|
|
|
199
|
+
## SQL functions
|
|
200
|
+
|
|
201
|
+
Full reference: [doc/sql-reference.md](doc/sql-reference.md).
|
|
202
|
+
|
|
203
|
+
| Group | Functions |
|
|
204
|
+
| --- | --- |
|
|
205
|
+
| JSON | `JSON_EXTRACT`, `JSON_CONTAINS` (path + type-sensitive), `JSON_SEARCH` (case-sensitive, LIKE wildcards), `JSON_SET`, `JSON_REMOVE`, `JSON_MERGE_PATCH`, … |
|
|
206
|
+
| Date / time | UTC wall-clock semantics; `TO_DAYS`, `FROM_DAYS`, `TO_SECONDS`, `TIME_TO_SEC`, `SEC_TO_TIME`, `DATE_ADD`, `DATE_FORMAT`, `TIMESTAMPDIFF`, … |
|
|
207
|
+
| Base / utility | `BIN`, `OCT`, `HEX`, `UNHEX`, `CONV`, `BIT_LENGTH`, `CRC32`, `QUOTE`, `FIND_IN_SET`, `INSERT`, `FORMAT`, `INET_ATON` / `INET_NTOA`, `MAKE_SET`, `EXPORT_SET`, `SOUNDEX` |
|
|
208
|
+
| Exact integers | Values above `2^53` stay exact via BigInt; integer-math functions use exact paths, floating-point ones return DOUBLE |
|
|
209
|
+
|
|
210
|
+
`JSON_TYPE` / `JSON_DEPTH` follow **this project's** documented semantics
|
|
211
|
+
(lowercase type names, flat object depth 1), not MySQL's. See the SQL reference.
|
|
212
|
+
|
|
199
213
|
## ✨ XQL 集成
|
|
200
214
|
|
|
201
215
|
用 [XQL](https://github.com/vexify-org/XQL) 查询 JSQL 表:把 SQL 直接接到文档上,
|
|
@@ -243,6 +257,10 @@ report the reason instead of failing silently. Loopback traffic (the
|
|
|
243
257
|
`127.0.0.1` links between `jsql serve` and the client / Web UI) is not
|
|
244
258
|
external access and is unaffected.
|
|
245
259
|
|
|
260
|
+
`jsql native status|refresh|verify` is **entirely local** — it reads
|
|
261
|
+
`native/.installed.json` and hashes the on-disk addon. `verify --json` is
|
|
262
|
+
suitable for CI gates. See [doc/cli.md](doc/cli.md).
|
|
263
|
+
|
|
246
264
|
## 📖 Documentation
|
|
247
265
|
|
|
248
266
|
Detailed docs live in `doc/` — click to read.
|
package/index.js
CHANGED
package/lib/multiserver.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Listens on ONE port and sniffs the first bytes of each connection to route
|
|
5
5
|
* to the correct wire-protocol handler:
|
|
6
6
|
*
|
|
7
|
+
* - MongoDB : OP_MSG / OP_QUERY opcode at offset 12 (checked first — its
|
|
8
|
+
* little-endian length can start with 0x00 and look like PG)
|
|
7
9
|
* - PostgreSQL : first byte 0x00 (big-endian Int32 length, length < 2^24)
|
|
8
10
|
* - MySQL : first byte 0x0a/0x0d (protocol handshake version / cap flag)
|
|
9
11
|
* - Redis : anything else (ASCII command or RESP prefix)
|
package/lib/sql.js
CHANGED
|
@@ -179,30 +179,35 @@ function nameOfToken(t) {
|
|
|
179
179
|
* 但此前把 '$' 开头的路径当成字面键名去取(v['$.name']),永远取不到 ——
|
|
180
180
|
* 所以抽出来共用,避免两处实现漂移。
|
|
181
181
|
*/
|
|
182
|
-
function jsonPathGet(data, path) {
|
|
182
|
+
function jsonPathGet(data, path, notFound) {
|
|
183
|
+
// notFound 哨兵:调用方需要区分「路径不存在」与「该路径的值恰好是 JSON null」时
|
|
184
|
+
// 传入一个私有对象;默认仍返回 null,保持 JSON_EXTRACT 等既有行为不变。
|
|
185
|
+
const miss = arguments.length >= 3 ? notFound : null;
|
|
183
186
|
const p = path == null ? '' : String(path);
|
|
184
187
|
if (p === '$' || p === '') return data;
|
|
185
|
-
|
|
186
|
-
|
|
188
|
+
// 支持 $.a.b、$[1]、$.a[0]。此前 /^\$\.?([^.\[]+)/ 要求 $ 后必须紧跟
|
|
189
|
+
// 非 '[' 的字符,导致纯数组索引 $[1] 被直接判为找不到。
|
|
190
|
+
const m = p.match(/^\$(?:\.|\[|$)/);
|
|
191
|
+
if (!m) return miss;
|
|
187
192
|
let current = data;
|
|
188
193
|
for (const seg of p.replace(/^\$\.?/, '').split('.')) {
|
|
189
|
-
if (current === null || current === undefined) return
|
|
194
|
+
if (current === null || current === undefined) return miss;
|
|
190
195
|
const arrMatch = seg.match(/^([^\[]*)\[(\d+)\]$/);
|
|
191
196
|
if (arrMatch) {
|
|
192
197
|
const key = arrMatch[1];
|
|
193
198
|
const idx = parseInt(arrMatch[2], 10);
|
|
194
199
|
if (key) {
|
|
195
|
-
if (typeof current !== 'object' || current === null) return
|
|
200
|
+
if (typeof current !== 'object' || current === null) return miss;
|
|
196
201
|
current = current[key];
|
|
197
202
|
}
|
|
198
|
-
if (!Array.isArray(current)) return
|
|
203
|
+
if (!Array.isArray(current)) return miss;
|
|
199
204
|
current = current[idx];
|
|
200
205
|
} else {
|
|
201
|
-
if (typeof current !== 'object' || current === null) return
|
|
206
|
+
if (typeof current !== 'object' || current === null) return miss;
|
|
202
207
|
current = current[seg];
|
|
203
208
|
}
|
|
204
209
|
}
|
|
205
|
-
return current === undefined ?
|
|
210
|
+
return current === undefined ? miss : current;
|
|
206
211
|
}
|
|
207
212
|
|
|
208
213
|
/**
|
|
@@ -3356,6 +3361,11 @@ function numericIfNumeric(v) {
|
|
|
3356
3361
|
*/
|
|
3357
3362
|
function mysqlNum(v) {
|
|
3358
3363
|
if (typeof v === 'number') return Number.isFinite(v) ? v : 0;
|
|
3364
|
+
// BigInt 是 issue #38 用来保 >2^53 整数精度的内部表示。此前没有这个分支,
|
|
3365
|
+
// 会掉到最后的 `return 0` —— 于是 SELECT -9223372036854775807 静默变成 0。
|
|
3366
|
+
// 这里转成 number 会让超出 2^53 的值丢精度,但至少不再是「悄悄变 0」;
|
|
3367
|
+
// 需要精确保留的一元负号路径在 case 'negate' 里单独短路。
|
|
3368
|
+
if (typeof v === 'bigint') return Number(v);
|
|
3359
3369
|
if (typeof v === 'boolean') return v ? 1 : 0;
|
|
3360
3370
|
if (typeof v === 'string') {
|
|
3361
3371
|
const m = v.trim().match(/^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?/);
|
|
@@ -3607,6 +3617,10 @@ function resolveOperand(operand, row, ctx) {
|
|
|
3607
3617
|
case 'negate': {
|
|
3608
3618
|
const v = resolveOperand(operand.operand, row, ctx);
|
|
3609
3619
|
if (v === null || v === undefined) return null;
|
|
3620
|
+
// 保精度:大整数是 BigInt,直接取负仍然是 BigInt,交给
|
|
3621
|
+
// finalizeResultBigInts 转成字符串输出,与正数路径一致。
|
|
3622
|
+
// 走 mysqlNum 会先转成 number,把 >2^53 的值弄丢精度。
|
|
3623
|
+
if (typeof v === 'bigint') return operand.positive ? v : -v;
|
|
3610
3624
|
const n = mysqlNum(v);
|
|
3611
3625
|
return operand.positive ? n : -n;
|
|
3612
3626
|
}
|
|
@@ -3990,6 +4004,20 @@ function pgAge(from, to) {
|
|
|
3990
4004
|
function finiteOrNull(x) {
|
|
3991
4005
|
return (typeof x === 'number' && !Number.isFinite(x)) ? null : x;
|
|
3992
4006
|
}
|
|
4007
|
+
|
|
4008
|
+
/** 整数语义、必须用 BigInt 精确算的数学函数(见 applyScalarFunction)。 */
|
|
4009
|
+
const INTEGER_MATH_FNS = new Set([
|
|
4010
|
+
'ABS', 'SIGN', 'FLOOR', 'CEIL', 'CEILING', 'ROUND', 'TRUNCATE', 'MOD',
|
|
4011
|
+
'POWER', 'POW',
|
|
4012
|
+
]);
|
|
4013
|
+
|
|
4014
|
+
/** 入参需要 number(不能是 BigInt)的数学标量函数,见 applyScalarFunction。 */
|
|
4015
|
+
const MATH_SCALAR_FNS = new Set([
|
|
4016
|
+
'ABS', 'SIGN', 'SQRT', 'POWER', 'POW', 'FLOOR', 'CEIL', 'CEILING', 'MOD',
|
|
4017
|
+
'ROUND', 'TRUNCATE', 'LOG', 'LOG10', 'LOG2', 'LN', 'EXP',
|
|
4018
|
+
'SIN', 'COS', 'TAN', 'ASIN', 'ACOS', 'ATAN', 'ATAN2',
|
|
4019
|
+
'DEGREES', 'RADIANS', 'COT',
|
|
4020
|
+
]);
|
|
3993
4021
|
function applyScalarFunction(fnNode, row, ctx) {
|
|
3994
4022
|
const name = (fnNode.name || '').toUpperCase();
|
|
3995
4023
|
const rawArgs = fnNode.args || [];
|
|
@@ -3997,6 +4025,41 @@ function applyScalarFunction(fnNode, row, ctx) {
|
|
|
3997
4025
|
const args = rawArgs.map(a => (a && a.type === 'interval')
|
|
3998
4026
|
? { __interval: true, value: a.value, unit: a.unit }
|
|
3999
4027
|
: resolveOperand(a, row, ctx));
|
|
4028
|
+
|
|
4029
|
+
// >2^53 的整数在 jsql 内部是 BigInt(issue #38)。Math.* 不接受 BigInt,
|
|
4030
|
+
// 直接传会抛 "Cannot convert a BigInt value to a number";一律降级成
|
|
4031
|
+
// number 又会把 MOD(9007199254740993, 2) 算成 0(正确是 1)—— 静默错值
|
|
4032
|
+
// 比抛错更糟。所以分两类:
|
|
4033
|
+
// a) 整数语义的函数走 BigInt 精确路径,保留精度;
|
|
4034
|
+
// b) 真正的浮点运算(SQRT/LOG/三角…)降级为 number,MySQL 下本就返回 DOUBLE。
|
|
4035
|
+
if (args.length && args.some(a => typeof a === 'bigint') && INTEGER_MATH_FNS.has(name)) {
|
|
4036
|
+
const v = args[0];
|
|
4037
|
+
if (typeof v === 'bigint') {
|
|
4038
|
+
switch (name) {
|
|
4039
|
+
case 'ABS': return v < 0n ? -v : v;
|
|
4040
|
+
case 'SIGN': return v > 0n ? 1 : (v < 0n ? -1 : 0);
|
|
4041
|
+
case 'FLOOR': case 'CEIL': case 'CEILING': case 'ROUND': case 'TRUNCATE':
|
|
4042
|
+
return v; // 整数本身就是它的 floor/ceil/round
|
|
4043
|
+
case 'MOD': {
|
|
4044
|
+
const d = args[1];
|
|
4045
|
+
if (d == null || d === 0 || d === 0n) return null;
|
|
4046
|
+
return v % (typeof d === 'bigint' ? d : BigInt(Math.trunc(Number(d))));
|
|
4047
|
+
}
|
|
4048
|
+
case 'POWER': case 'POW': {
|
|
4049
|
+
const e = args[1];
|
|
4050
|
+
if (typeof e === 'bigint' || (typeof e === 'number' && Number.isInteger(e) && e >= 0)) {
|
|
4051
|
+
return v ** BigInt(e);
|
|
4052
|
+
}
|
|
4053
|
+
break; // 非整数指数 → 落到下面的浮点路径
|
|
4054
|
+
}
|
|
4055
|
+
}
|
|
4056
|
+
}
|
|
4057
|
+
}
|
|
4058
|
+
if (MATH_SCALAR_FNS.has(name)) {
|
|
4059
|
+
for (let i = 0; i < args.length; i++) {
|
|
4060
|
+
if (typeof args[i] === 'bigint') args[i] = Number(args[i]);
|
|
4061
|
+
}
|
|
4062
|
+
}
|
|
4000
4063
|
const session = ctx && ctx.session;
|
|
4001
4064
|
if (ctx && ctx.functions && Object.prototype.hasOwnProperty.call(ctx.functions, name)) {
|
|
4002
4065
|
return ctx.functions[name].apply(null, args);
|
|
@@ -4258,6 +4321,45 @@ function applyScalarFunction(fnNode, row, ctx) {
|
|
|
4258
4321
|
d.setUTCDate(doy);
|
|
4259
4322
|
return fmtSqlDate(true, d);
|
|
4260
4323
|
}
|
|
4324
|
+
// MySQL 的「天数/秒数 ↔ 日期/时间」互转。此前这五个函数完全没实现,
|
|
4325
|
+
// 调用时落到 switch 的 default 静默返回 null(不是报错,很容易被当成
|
|
4326
|
+
// 「数据里没有这个值」)。基准与 6.6.0 起的 UTC 墙上时间口径一致。
|
|
4327
|
+
case 'TO_DAYS': {
|
|
4328
|
+
const d = parseSqlDate(args[0]);
|
|
4329
|
+
return d ? Math.floor(d.getTime() / 86400000) + 719528 : null;
|
|
4330
|
+
}
|
|
4331
|
+
case 'FROM_DAYS': {
|
|
4332
|
+
if (args[0] == null) return null;
|
|
4333
|
+
const days = Number(args[0]);
|
|
4334
|
+
if (!Number.isFinite(days)) return null;
|
|
4335
|
+
return fmtSqlDate(true, new Date((days - 719528) * 86400000));
|
|
4336
|
+
}
|
|
4337
|
+
case 'TO_SECONDS': {
|
|
4338
|
+
const d = parseSqlDate(args[0]);
|
|
4339
|
+
if (!d) return null;
|
|
4340
|
+
const days = Math.floor(d.getTime() / 86400000) + 719528;
|
|
4341
|
+
const secOfDay = d.getUTCHours() * 3600 + d.getUTCMinutes() * 60 + d.getUTCSeconds();
|
|
4342
|
+
return days * 86400 + secOfDay;
|
|
4343
|
+
}
|
|
4344
|
+
case 'TIME_TO_SEC': {
|
|
4345
|
+
if (args[0] == null) return null;
|
|
4346
|
+
const m = String(args[0]).trim().match(/^(-?)(\d{1,3}):(\d{2})(?::(\d{2}))?$/);
|
|
4347
|
+
if (!m) return null;
|
|
4348
|
+
const sign = m[1] === '-' ? -1 : 1;
|
|
4349
|
+
return sign * (Number(m[2]) * 3600 + Number(m[3]) * 60 +
|
|
4350
|
+
(m[4] === undefined ? 0 : Number(m[4])));
|
|
4351
|
+
}
|
|
4352
|
+
case 'SEC_TO_TIME': {
|
|
4353
|
+
if (args[0] == null) return null;
|
|
4354
|
+
const n = Math.trunc(Number(args[0]));
|
|
4355
|
+
if (!Number.isFinite(n)) return null;
|
|
4356
|
+
const sign = n < 0 ? '-' : '';
|
|
4357
|
+
let rest = Math.abs(n);
|
|
4358
|
+
const h = Math.floor(rest / 3600); rest -= h * 3600;
|
|
4359
|
+
const mi = Math.floor(rest / 60);
|
|
4360
|
+
const s = rest - mi * 60;
|
|
4361
|
+
return sign + String(h).padStart(2, '0') + ':' + pad2(mi) + ':' + pad2(s);
|
|
4362
|
+
}
|
|
4261
4363
|
case 'PERIOD_DIFF': {
|
|
4262
4364
|
const p1 = String(args[0] == null ? '' : args[0]);
|
|
4263
4365
|
const p2 = String(args[1] == null ? '' : args[1]);
|
|
@@ -4283,6 +4385,140 @@ function applyScalarFunction(fnNode, row, ctx) {
|
|
|
4283
4385
|
}
|
|
4284
4386
|
return fmtSqlDate(false, nd);
|
|
4285
4387
|
}
|
|
4388
|
+
// ── MySQL 进制 / 字符串 / IP 工具函数 ──
|
|
4389
|
+
// 这十三个此前全部落到 switch 的 default 静默返回 null —— 调用方很容易
|
|
4390
|
+
// 把「函数没实现」误读成「这个值不存在」。补齐常用的一批;
|
|
4391
|
+
// MAKE_SET / EXPORT_SET / SOUNDEX 仍未实现(未在文档中承诺)。
|
|
4392
|
+
case 'BIT_LENGTH': {
|
|
4393
|
+
if (args[0] == null) return null;
|
|
4394
|
+
return Buffer.byteLength(String(args[0]), 'utf8') * 8;
|
|
4395
|
+
}
|
|
4396
|
+
case 'BIN': case 'OCT': {
|
|
4397
|
+
if (args[0] == null) return null;
|
|
4398
|
+
const v = args[0];
|
|
4399
|
+
const n = typeof v === 'bigint' ? v : BigInt(Math.trunc(Number(v)));
|
|
4400
|
+
return (n < 0n ? BigInt.asUintN(64, n) : n).toString(name === 'BIN' ? 2 : 8);
|
|
4401
|
+
}
|
|
4402
|
+
case 'HEX': {
|
|
4403
|
+
if (args[0] == null) return null;
|
|
4404
|
+
const v = args[0];
|
|
4405
|
+
if (typeof v === 'number' || typeof v === 'bigint') {
|
|
4406
|
+
const n = typeof v === 'bigint' ? v : BigInt(Math.trunc(v));
|
|
4407
|
+
return (n < 0n ? BigInt.asUintN(64, n) : n).toString(16).toUpperCase();
|
|
4408
|
+
}
|
|
4409
|
+
return Buffer.from(String(v), 'utf8').toString('hex').toUpperCase();
|
|
4410
|
+
}
|
|
4411
|
+
case 'UNHEX': {
|
|
4412
|
+
if (args[0] == null) return null;
|
|
4413
|
+
const h = String(args[0]);
|
|
4414
|
+
if (h.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(h)) return null;
|
|
4415
|
+
return Buffer.from(h, 'hex').toString('latin1');
|
|
4416
|
+
}
|
|
4417
|
+
case 'CONV': {
|
|
4418
|
+
if (args[0] == null || args[1] == null || args[2] == null) return null;
|
|
4419
|
+
const from = Math.trunc(Number(args[1])), to = Math.trunc(Number(args[2]));
|
|
4420
|
+
if (from < 2 || from > 36 || to < 2 || to > 36) return null;
|
|
4421
|
+
const digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
4422
|
+
let n = 0n;
|
|
4423
|
+
for (const ch of String(args[0]).trim().toUpperCase()) {
|
|
4424
|
+
const d = digits.indexOf(ch);
|
|
4425
|
+
if (d < 0 || d >= from) return null;
|
|
4426
|
+
n = n * BigInt(from) + BigInt(d);
|
|
4427
|
+
}
|
|
4428
|
+
if (n === 0n) return '0';
|
|
4429
|
+
let out = '';
|
|
4430
|
+
while (n > 0n) { out = digits[Number(n % BigInt(to))] + out; n /= BigInt(to); }
|
|
4431
|
+
return out;
|
|
4432
|
+
}
|
|
4433
|
+
case 'QUOTE': {
|
|
4434
|
+
if (args[0] == null) return null;
|
|
4435
|
+
const s = String(args[0]).replace(/\\/g, '\\\\').replace(/\0/g, '\\0')
|
|
4436
|
+
.replace(/\n/g, '\\n').replace(/\r/g, '\\r')
|
|
4437
|
+
.replace(/'/g, "\\'").replace(/"/g, '\\"').replace(/\x1a/g, '\\Z');
|
|
4438
|
+
return "'" + s + "'";
|
|
4439
|
+
}
|
|
4440
|
+
case 'FIND_IN_SET': {
|
|
4441
|
+
if (args[0] == null || args[1] == null) return null;
|
|
4442
|
+
const i = String(args[1]).split(',').indexOf(String(args[0]));
|
|
4443
|
+
return i < 0 ? 0 : i + 1;
|
|
4444
|
+
}
|
|
4445
|
+
case 'INSERT': {
|
|
4446
|
+
const s = args[0], pos = args[1], len = args[2], ins = args[3];
|
|
4447
|
+
if (s == null || pos == null || len == null || ins == null) return null;
|
|
4448
|
+
const str = String(s), p = Math.trunc(Number(pos)), l = Math.trunc(Number(len));
|
|
4449
|
+
if (p < 1 || p > str.length + 1 || l < 0) return str;
|
|
4450
|
+
return str.slice(0, p - 1) + String(ins) + str.slice(p - 1 + l);
|
|
4451
|
+
}
|
|
4452
|
+
case 'INET_ATON': {
|
|
4453
|
+
if (args[0] == null) return null;
|
|
4454
|
+
const m = String(args[0]).match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
|
|
4455
|
+
if (!m) return null;
|
|
4456
|
+
const o = m.slice(1).map(Number);
|
|
4457
|
+
if (o.some(x => x > 255)) return null;
|
|
4458
|
+
return (((o[0] << 24) >>> 0) + (o[1] << 16) + (o[2] << 8) + o[3]) >>> 0;
|
|
4459
|
+
}
|
|
4460
|
+
case 'INET_NTOA': {
|
|
4461
|
+
if (args[0] == null) return null;
|
|
4462
|
+
const n = Number(args[0]) >>> 0;
|
|
4463
|
+
return [(n >>> 24) & 255, (n >>> 16) & 255, (n >>> 8) & 255, n & 255].join('.');
|
|
4464
|
+
}
|
|
4465
|
+
case 'FORMAT': {
|
|
4466
|
+
if (args[0] == null || args[1] == null) return null;
|
|
4467
|
+
const x = Number(args[0]), d = Math.trunc(Number(args[1]));
|
|
4468
|
+
if (!Number.isFinite(x) || !Number.isFinite(d) || d < 0 || d > 30) return null;
|
|
4469
|
+
const [ip, fp] = x.toFixed(d).split('.');
|
|
4470
|
+
const sign = ip.startsWith('-') ? '-' : '';
|
|
4471
|
+
const grouped = (sign ? ip.slice(1) : ip).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
4472
|
+
return sign + grouped + (fp ? '.' + fp : '');
|
|
4473
|
+
}
|
|
4474
|
+
case 'CRC32': {
|
|
4475
|
+
if (args[0] == null) return null;
|
|
4476
|
+
let crc = 0xFFFFFFFF;
|
|
4477
|
+
for (const b of Buffer.from(String(args[0]), 'utf8')) {
|
|
4478
|
+
crc ^= b;
|
|
4479
|
+
for (let k = 0; k < 8; k++) crc = (crc >>> 1) ^ (0xEDB88320 & -(crc & 1));
|
|
4480
|
+
}
|
|
4481
|
+
return (crc ^ 0xFFFFFFFF) >>> 0;
|
|
4482
|
+
}
|
|
4483
|
+
case 'MAKE_SET': {
|
|
4484
|
+
if (args[0] == null) return null;
|
|
4485
|
+
const bits = Math.trunc(Number(args[0]));
|
|
4486
|
+
if (!Number.isFinite(bits)) return '';
|
|
4487
|
+
const out = [];
|
|
4488
|
+
for (let i = 1; i < args.length; i++) {
|
|
4489
|
+
const v = args[i];
|
|
4490
|
+
if (v != null && (bits & (1 << (i - 1)))) out.push(String(v));
|
|
4491
|
+
}
|
|
4492
|
+
return out.join(',');
|
|
4493
|
+
}
|
|
4494
|
+
case 'EXPORT_SET': {
|
|
4495
|
+
const bits = args[0], on = args[1], off = args[2];
|
|
4496
|
+
if (bits == null || on == null || off == null) return null;
|
|
4497
|
+
const sep = args[3] == null ? ',' : String(args[3]);
|
|
4498
|
+
const n = args[4] == null ? 64 : Math.trunc(Number(args[4]));
|
|
4499
|
+
if (!Number.isFinite(n) || n < 0 || n > 64) return null;
|
|
4500
|
+
const b = BigInt(Math.trunc(Number(bits)));
|
|
4501
|
+
const out = [];
|
|
4502
|
+
for (let i = 0; i < n; i++) {
|
|
4503
|
+
out.push(((b >> BigInt(i)) & 1n) ? String(on) : String(off));
|
|
4504
|
+
}
|
|
4505
|
+
return out.join(sep);
|
|
4506
|
+
}
|
|
4507
|
+
case 'SOUNDEX': {
|
|
4508
|
+
if (args[0] == null) return null;
|
|
4509
|
+
const s = String(args[0]).toUpperCase().replace(/[^A-Z]/g, '');
|
|
4510
|
+
if (!s) return '';
|
|
4511
|
+
const MAP = { B: '1', F: '1', P: '1', V: '1', C: '2', G: '2', J: '2', K: '2', Q: '2', S: '2', X: '2', Z: '2', D: '3', T: '3', L: '4', M: '5', N: '5', R: '6' };
|
|
4512
|
+
let out = s[0];
|
|
4513
|
+
let prev = MAP[s[0]] || '';
|
|
4514
|
+
for (let i = 1; i < s.length && out.length < 4; i++) {
|
|
4515
|
+
const c = MAP[s[i]];
|
|
4516
|
+
if (!c) { prev = ''; continue; } // 元音 / H / W / Y 隔断相邻重复
|
|
4517
|
+
if (c !== prev) out += c;
|
|
4518
|
+
prev = c;
|
|
4519
|
+
}
|
|
4520
|
+
return (out + '000').slice(0, 4);
|
|
4521
|
+
}
|
|
4286
4522
|
case 'LTRIM': return args[0] == null ? null : String(args[0]).replace(/^\s+/, '');
|
|
4287
4523
|
case 'RTRIM': return args[0] == null ? null : String(args[0]).replace(/\s+$/, '');
|
|
4288
4524
|
case 'ABS': return args[0] == null ? null : Math.abs(args[0]);
|
|
@@ -4880,10 +5116,14 @@ function applyScalarFunction(fnNode, row, ctx) {
|
|
|
4880
5116
|
if (typeof json === 'string') {
|
|
4881
5117
|
try { data = JSON.parse(json); } catch (e) { return null; }
|
|
4882
5118
|
}
|
|
4883
|
-
|
|
5119
|
+
// MySQL 的 search_str 是 **LIKE 模式**(% 任意串、_ 单字符,\ 转义),
|
|
5120
|
+
// 且 JSON_SEARCH 大小写敏感(#105)。旧实现用 String.includes +
|
|
5121
|
+
// toLowerCase:既不支持通配符,又把 'hello' 错配到 'Hello'。
|
|
5122
|
+
// 复用 likeMatch(ci=false),与 SQL 的 LIKE 语义保持一致。
|
|
5123
|
+
const searchStr = String(search);
|
|
4884
5124
|
const results = [];
|
|
4885
5125
|
function searchObj(obj, currentPath) {
|
|
4886
|
-
if (typeof obj === 'string' && obj
|
|
5126
|
+
if (typeof obj === 'string' && likeMatch(obj, searchStr, false) === true) {
|
|
4887
5127
|
results.push(currentPath);
|
|
4888
5128
|
} else if (Array.isArray(obj)) {
|
|
4889
5129
|
obj.forEach((item, i) => searchObj(item, currentPath + '[' + i + ']'));
|
|
@@ -4899,15 +5139,38 @@ function applyScalarFunction(fnNode, row, ctx) {
|
|
|
4899
5139
|
return results;
|
|
4900
5140
|
}
|
|
4901
5141
|
case 'JSON_CONTAINS': {
|
|
4902
|
-
// JSON_CONTAINS(
|
|
5142
|
+
// MySQL: JSON_CONTAINS(target, candidate[, path]) → 1 / 0
|
|
5143
|
+
//
|
|
5144
|
+
// 旧实现是 `JSON.stringify(data).includes(JSON.stringify(val))`,
|
|
5145
|
+
// 有两个错(#105):
|
|
5146
|
+
// 1. candidate 是 JSON 文本,从未被解析 —— '2' 一直是字符串 "2",
|
|
5147
|
+
// 所以 '[1,2,3]' 里找不到 '"2"';只有数值字面量 2 碰巧能命中。
|
|
5148
|
+
// 2. 可选的第三个 path 参数被完全忽略。
|
|
5149
|
+
// 同文件里本来就有正确的 jsonContainsValue()(数组/对象/标量递归),
|
|
5150
|
+
// 只是这里没用。现在解析 candidate、用 jsonPathGet 应用 path,再委托它。
|
|
4903
5151
|
const json = args[0];
|
|
4904
5152
|
const val = args[1];
|
|
4905
|
-
|
|
5153
|
+
const path = args[2];
|
|
5154
|
+
if (json == null || val === undefined) return null;
|
|
4906
5155
|
let data = json;
|
|
4907
5156
|
if (typeof json === 'string') {
|
|
4908
5157
|
try { data = JSON.parse(json); } catch (e) { return null; }
|
|
4909
5158
|
}
|
|
4910
|
-
|
|
5159
|
+
if (path != null && String(path) !== '$' && String(path) !== '') {
|
|
5160
|
+
// 用哨兵区分「路径不存在」和「该路径的值恰好是 JSON null」。
|
|
5161
|
+
// jsonPathGet 默认把两者都返回 null;直接判 === null 会把合法的
|
|
5162
|
+
// JSON null 误判成找不到(JSON_CONTAINS('{"a":null}','null','$.a')
|
|
5163
|
+
// 会错返回 0)。
|
|
5164
|
+
const MISSING = {};
|
|
5165
|
+
const sliced = jsonPathGet(data, String(path), MISSING);
|
|
5166
|
+
if (sliced === MISSING) return 0;
|
|
5167
|
+
data = sliced;
|
|
5168
|
+
}
|
|
5169
|
+
let candidate = val;
|
|
5170
|
+
if (typeof val === 'string') {
|
|
5171
|
+
try { candidate = JSON.parse(val); } catch (e) { /* 非法 JSON 文本按字面字符串处理 */ }
|
|
5172
|
+
}
|
|
5173
|
+
return jsonContainsValue(data, candidate) ? 1 : 0;
|
|
4911
5174
|
}
|
|
4912
5175
|
default:
|
|
4913
5176
|
return null;
|
|
@@ -4984,9 +5247,12 @@ function jsonContainsValue(container, target) {
|
|
|
4984
5247
|
if (container === null || typeof container !== 'object' || Array.isArray(container)) return false;
|
|
4985
5248
|
return Object.keys(target).every(k => Object.prototype.hasOwnProperty.call(container, k) && jsonContainsValue(container[k], target[k]));
|
|
4986
5249
|
}
|
|
4987
|
-
|
|
5250
|
+
// JSON 包含是**类型敏感**的:数字 2 与字符串 "2" 是不同值(MySQL / PG
|
|
5251
|
+
// 都如此)。此前用 String(c) === String(target) 做宽松比较,导致
|
|
5252
|
+
// JSON_CONTAINS('[1,2,3]', '"2"') 错返回 1。PG 的 @> 同样受益于此修正。
|
|
5253
|
+
if (Array.isArray(container)) return container.some(c => c === target);
|
|
4988
5254
|
if (container !== null && typeof container === 'object') return false;
|
|
4989
|
-
return container === target
|
|
5255
|
+
return container === target;
|
|
4990
5256
|
}
|
|
4991
5257
|
|
|
4992
5258
|
/** JSON 键存在(PG 的 ? / ?| / ?&)。keys 为单个键名或 '{a,b}' 形式的键列表。 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsql-neo",
|
|
3
|
-
"version": "6.6.
|
|
3
|
+
"version": "6.6.6",
|
|
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",
|
|
@@ -50,12 +50,13 @@
|
|
|
50
50
|
"scripts": {
|
|
51
51
|
"postinstall": "node postinstall.js",
|
|
52
52
|
"build:native": "node scripts/build-native.js",
|
|
53
|
-
"
|
|
53
|
+
"check:release": "node scripts/check-release-metadata.js",
|
|
54
|
+
"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",
|
|
54
55
|
"test:parser": "node test/sql-parser.test.js",
|
|
55
56
|
"test:btree": "node test/btree.test.js",
|
|
56
57
|
"test:native": "node test/native.test.js",
|
|
57
58
|
"test:regress": "node test/regress-5.1.0.js",
|
|
58
|
-
"test:all": "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",
|
|
59
|
+
"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",
|
|
59
60
|
"test:coverage": "c8 --all --include='lib/**' --exclude='lib/web_ui.js' --reporter=text --reporter=lcov node test/coverage.js",
|
|
60
61
|
"test:orms": "node examples/orms/run-all.js",
|
|
61
62
|
"test:dml": "node test/dml-constraints.test.js",
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* ---- BigInt 在数学标量函数与一元负号里的精度回归 ---- */
|
|
2
|
+
/*
|
|
3
|
+
* 起点:SELECT -9223372036854775807 静默返回 0。
|
|
4
|
+
* 根因:mysqlNum() 没有 bigint 分支,掉到最后的 `return 0`;negate 又
|
|
5
|
+
* 把所有入参都过一遍 mysqlNum。修完后顺带发现 Math.* 不接受 BigInt
|
|
6
|
+
* (ABS/SQRT/POWER/FLOOR/CEIL/MOD 抛 TypeError),以及「一律降级 number」
|
|
7
|
+
* 会把 MOD(9007199254740993, 2) 算成 0 这种更糟的静默错值。
|
|
8
|
+
*
|
|
9
|
+
* 现在分两类:整数语义函数走 BigInt 精确路径,浮点函数降级为 DOUBLE。
|
|
10
|
+
*/
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const ROOT = path.join(__dirname, '..');
|
|
13
|
+
const { Database, executeSQL } = require(path.join(ROOT, 'index.js'));
|
|
14
|
+
|
|
15
|
+
let pass = 0, fail = 0;
|
|
16
|
+
function ok(name, cond, got) {
|
|
17
|
+
if (cond) { pass++; console.log('[OK] ' + name); }
|
|
18
|
+
else { fail++; console.log('[FAIL] ' + name + ' -> ' + JSON.stringify(got, (k, v) => typeof v === 'bigint' ? v.toString() + 'n' : v)); }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
(async () => {
|
|
22
|
+
const db = new Database(':memory:', { autoSave: false });
|
|
23
|
+
const q = async (sql) => {
|
|
24
|
+
const r = await executeSQL(db, sql, { safety: false });
|
|
25
|
+
return r.rows[0][0];
|
|
26
|
+
};
|
|
27
|
+
const BIG = '9223372036854775807'; // int64 max
|
|
28
|
+
const ODD = '9007199254740993'; // 2^53 + 1,float64 无法精确表示
|
|
29
|
+
|
|
30
|
+
// ---------- 一元负号保精度 ----------
|
|
31
|
+
ok('正的大整数仍精确', await q(`SELECT ${BIG}`) === BIG, null);
|
|
32
|
+
ok('负的大整数精确取负(此前静默变 0)', await q(`SELECT -${BIG}`) === '-' + BIG, null);
|
|
33
|
+
ok('int64 min 取负', await q('SELECT -9223372036854775808') === '-9223372036854775808', null);
|
|
34
|
+
ok('普通负数仍是 number', await q('SELECT -5') === -5, null);
|
|
35
|
+
ok('普通负小数仍是 number', await q('SELECT -1.5') === -1.5, null);
|
|
36
|
+
|
|
37
|
+
// ---------- 整数语义的数学函数:BigInt 精确路径 ----------
|
|
38
|
+
ok('ABS 大负数精确', await q(`SELECT ABS(-${BIG})`) === BIG, null);
|
|
39
|
+
ok('ABS 普通负数', await q('SELECT ABS(-5)') === 5, null);
|
|
40
|
+
ok('SIGN 大正数', await q(`SELECT SIGN(${BIG})`) === 1, null);
|
|
41
|
+
ok('SIGN 大负数', await q(`SELECT SIGN(-${BIG})`) === -1, null);
|
|
42
|
+
ok(`MOD(${ODD}, 2) = 1(降级 number 会算成 0)`,
|
|
43
|
+
String(await q(`SELECT MOD(${ODD}, 2)`)) === '1', null);
|
|
44
|
+
ok('MOD 被自身整除 = 0', String(await q(`SELECT MOD(${ODD}, ${ODD})`)) === '0', null);
|
|
45
|
+
ok('FLOOR 大整数不变', String(await q(`SELECT FLOOR(${ODD})`)) === ODD, null);
|
|
46
|
+
ok('CEIL 大整数不变', String(await q(`SELECT CEIL(${ODD})`)) === ODD, null);
|
|
47
|
+
ok('POWER 大整数指数 1 精确', String(await q(`SELECT POWER(${ODD}, 1)`)) === ODD, null);
|
|
48
|
+
ok('MOD 除零仍 NULL', await q('SELECT MOD(5, 0)') === null, null);
|
|
49
|
+
|
|
50
|
+
// ---------- 浮点运算:降级 DOUBLE,不抛错也不静默给 0 ----------
|
|
51
|
+
const sq = await q(`SELECT SQRT(${ODD})`);
|
|
52
|
+
ok('SQRT 大整数返回有限数值', typeof sq === 'number' && Number.isFinite(sq) && sq > 0, sq);
|
|
53
|
+
const lg = await q(`SELECT LOG(${ODD})`);
|
|
54
|
+
ok('LOG 大整数不再抛 TypeError', lg === null || (typeof lg === 'number' && Number.isFinite(lg)), lg);
|
|
55
|
+
ok('#65 SQRT(-1) 仍返回 NULL', await q('SELECT SQRT(-1)') === null, null);
|
|
56
|
+
ok('#65 POWER(-2,0.5) 仍返回 NULL', await q('SELECT POWER(-2,0.5)') === null, null);
|
|
57
|
+
|
|
58
|
+
console.log(`\n${pass} passed, ${fail} failed`);
|
|
59
|
+
process.exit(fail === 0 ? 0 : 1);
|
|
60
|
+
})().catch(e => {
|
|
61
|
+
console.log('[FAIL] unexpected exception: ' + e.stack.split('\n').slice(0, 3).join('\n'));
|
|
62
|
+
process.exit(1);
|
|
63
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* ---- MySQL 天数/秒数 ↔ 日期/时间 互转函数 ---- */
|
|
2
|
+
/*
|
|
3
|
+
* 这五个函数此前完全没实现,调用时落到 applyScalarFunction 的 default
|
|
4
|
+
* 静默返回 null —— 很容易被误读成「数据里没这个值」。
|
|
5
|
+
* 基准与 6.6.0 起的 UTC 墙上时间口径一致。
|
|
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
|
+
const q = async (sql) => (await executeSQL(db, sql, { safety: false })).rows[0][0];
|
|
20
|
+
|
|
21
|
+
// ---------- TO_DAYS / FROM_DAYS ----------
|
|
22
|
+
ok('TO_DAYS epoch = 719528', await q("SELECT TO_DAYS('1970-01-01')") === 719528, null);
|
|
23
|
+
ok('FROM_DAYS(719528) = 1970-01-01', await q('SELECT FROM_DAYS(719528)') === '1970-01-01', null);
|
|
24
|
+
for (const d of ['2024-05-06', '2024-02-29', '2000-01-01', '1999-12-31']) {
|
|
25
|
+
const v = await q(`SELECT FROM_DAYS(TO_DAYS('${d}'))`);
|
|
26
|
+
ok('TO_DAYS/FROM_DAYS 往返 ' + d, v === d, v);
|
|
27
|
+
}
|
|
28
|
+
ok('TO_DAYS 非法日期 → NULL', await q("SELECT TO_DAYS('bad')") === null, null);
|
|
29
|
+
ok('TO_DAYS(NULL) → NULL', await q('SELECT TO_DAYS(NULL)') === null, null);
|
|
30
|
+
ok('FROM_DAYS(NULL) → NULL', await q('SELECT FROM_DAYS(NULL)') === null, null);
|
|
31
|
+
|
|
32
|
+
// ---------- TO_SECONDS ----------
|
|
33
|
+
ok('TO_SECONDS epoch = 62167219200',
|
|
34
|
+
await q("SELECT TO_SECONDS('1970-01-01 00:00:00')") === 62167219200, null);
|
|
35
|
+
ok('TO_SECONDS 累加当日秒数',
|
|
36
|
+
await q("SELECT TO_SECONDS('1970-01-01 01:02:03')") === 62167219200 + 3723, null);
|
|
37
|
+
ok('TO_SECONDS 非法 → NULL', await q("SELECT TO_SECONDS('bad')") === null, null);
|
|
38
|
+
|
|
39
|
+
// ---------- TIME_TO_SEC / SEC_TO_TIME ----------
|
|
40
|
+
ok("TIME_TO_SEC('12:30:45') = 45045", await q("SELECT TIME_TO_SEC('12:30:45')") === 45045, null);
|
|
41
|
+
ok("TIME_TO_SEC('-12:30:45') = -45045", await q("SELECT TIME_TO_SEC('-12:30:45')") === -45045, null);
|
|
42
|
+
ok("TIME_TO_SEC('100:00:00') 支持超过 24h", await q("SELECT TIME_TO_SEC('100:00:00')") === 360000, null);
|
|
43
|
+
ok("TIME_TO_SEC('12:30') 省略秒", await q("SELECT TIME_TO_SEC('12:30')") === 45000, null);
|
|
44
|
+
ok('SEC_TO_TIME(45045)', await q('SELECT SEC_TO_TIME(45045)') === '12:30:45', null);
|
|
45
|
+
ok('SEC_TO_TIME(-45045) 带负号', await q('SELECT SEC_TO_TIME(-45045)') === '-12:30:45', null);
|
|
46
|
+
ok('SEC_TO_TIME(360000) 超过 24h', await q('SELECT SEC_TO_TIME(360000)') === '100:00:00', null);
|
|
47
|
+
ok('SEC_TO_TIME(0)', await q('SELECT SEC_TO_TIME(0)') === '00:00:00', null);
|
|
48
|
+
ok('TIME_TO_SEC / SEC_TO_TIME 往返',
|
|
49
|
+
await q("SELECT SEC_TO_TIME(TIME_TO_SEC('50:01:02'))") === '50:01:02', null);
|
|
50
|
+
ok('TIME_TO_SEC 非法 → NULL', await q("SELECT TIME_TO_SEC('bad')") === null, null);
|
|
51
|
+
ok('SEC_TO_TIME(NULL) → NULL', await q('SELECT SEC_TO_TIME(NULL)') === null, null);
|
|
52
|
+
|
|
53
|
+
console.log(`\n${pass} passed, ${fail} failed`);
|
|
54
|
+
process.exit(fail === 0 ? 0 : 1);
|
|
55
|
+
})().catch(e => {
|
|
56
|
+
console.log('[FAIL] unexpected exception: ' + e.stack.split('\n').slice(0, 3).join('\n'));
|
|
57
|
+
process.exit(1);
|
|
58
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* ---- issue #105 + JSON 包含/搜索的语义回归 ---- */
|
|
2
|
+
/*
|
|
3
|
+
* #105:JSON_CONTAINS 用字符串 includes 实现(candidate 不解析、path 被忽略),
|
|
4
|
+
* JSON_SEARCH 用 toLowerCase + includes(大小写不敏感、不支持 LIKE 通配符)。
|
|
5
|
+
*
|
|
6
|
+
* 顺带钉死两个差分发现的 bug:
|
|
7
|
+
* - jsonContainsValue 用 String() 宽松比较,字符串 "2" 能命中数字 2
|
|
8
|
+
* - JSON_SEARCH 不认 % / _ 通配符
|
|
9
|
+
* 参考语义:MySQL 8.0 JSON_CONTAINS / JSON_SEARCH(大小写敏感、LIKE 模式)。
|
|
10
|
+
*/
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const ROOT = path.join(__dirname, '..');
|
|
13
|
+
const { Database, executeSQL } = require(path.join(ROOT, 'index.js'));
|
|
14
|
+
|
|
15
|
+
let pass = 0, fail = 0;
|
|
16
|
+
function ok(name, cond, got) {
|
|
17
|
+
if (cond) { pass++; console.log('[OK] ' + name); }
|
|
18
|
+
else { fail++; console.log('[FAIL] ' + name + ' -> ' + JSON.stringify(got)); }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
(async () => {
|
|
22
|
+
const db = new Database(':memory:', { autoSave: false });
|
|
23
|
+
const q = async (sql) => {
|
|
24
|
+
const r = await executeSQL(db, sql, { safety: false });
|
|
25
|
+
return r.rows[0][0];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// ---------- #105 JSON_CONTAINS ----------
|
|
29
|
+
ok('#105 字符串候选命中数组元素',
|
|
30
|
+
await q("SELECT JSON_CONTAINS('[1,2,3]', '2')") === 1, null);
|
|
31
|
+
ok('#105 第三个 path 参数生效',
|
|
32
|
+
await q("SELECT JSON_CONTAINS('{\"a\":1}', '1', '$.a')") === 1, null);
|
|
33
|
+
ok('#105 嵌套 path',
|
|
34
|
+
await q("SELECT JSON_CONTAINS('{\"a\":{\"b\":1}}', '1', '$.a.b')") === 1, null);
|
|
35
|
+
ok('数值字面量候选仍命中',
|
|
36
|
+
await q("SELECT JSON_CONTAINS('[1,2,3]', 2)") === 1, null);
|
|
37
|
+
ok('path 不存在返回 0',
|
|
38
|
+
await q("SELECT JSON_CONTAINS('{\"a\":1}', '1', '$.b')") === 0, null);
|
|
39
|
+
ok('对象包含(子集)',
|
|
40
|
+
await q("SELECT JSON_CONTAINS('{\"a\":1,\"b\":2}', '{\"a\":1}')") === 1, null);
|
|
41
|
+
ok('对象值不匹配返回 0',
|
|
42
|
+
await q("SELECT JSON_CONTAINS('{\"a\":1}', '{\"a\":2}')") === 0, null);
|
|
43
|
+
ok('数组子集命中',
|
|
44
|
+
await q("SELECT JSON_CONTAINS('[1,2,3]', '[2,3]')") === 1, null);
|
|
45
|
+
ok('数组不含该元素返回 0',
|
|
46
|
+
await q("SELECT JSON_CONTAINS('[1,2,3]', '9')") === 0, null);
|
|
47
|
+
|
|
48
|
+
// ---------- 类型敏感(差分发现) ----------
|
|
49
|
+
ok('字符串 "2" 不应命中数字 2',
|
|
50
|
+
await q("SELECT JSON_CONTAINS('[1,2,3]', '\"2\"')") === 0, null);
|
|
51
|
+
ok('字符串元素只被字符串候选命中',
|
|
52
|
+
await q("SELECT JSON_CONTAINS('[\"2\"]', '\"2\"')") === 1, null);
|
|
53
|
+
ok('数字 2 不应命中字符串元素',
|
|
54
|
+
await q("SELECT JSON_CONTAINS('[\"2\"]', '2')") === 0, null);
|
|
55
|
+
|
|
56
|
+
// ---------- JSON path 解析器(差分发现) ----------
|
|
57
|
+
ok('JSON_EXTRACT 支持纯数组索引 $[1]',
|
|
58
|
+
await q("SELECT JSON_EXTRACT('[1,2,3]', '$[1]')") === 2, null);
|
|
59
|
+
ok('JSON_CONTAINS 的 path 值是合法 JSON null',
|
|
60
|
+
await q("SELECT JSON_CONTAINS('{\"a\":null}', 'null', '$.a')") === 1, null);
|
|
61
|
+
ok('JSON_CONTAINS 支持数组索引 path',
|
|
62
|
+
await q("SELECT JSON_CONTAINS('{\"a\":[1,2]}', '2', '$.a[1]')") === 1, null);
|
|
63
|
+
ok('JSON_EXTRACT 找不到路径仍返回 NULL',
|
|
64
|
+
await q("SELECT JSON_EXTRACT('{\"a\":1}', '$.b')") === null, null);
|
|
65
|
+
|
|
66
|
+
// ---------- #105 JSON_SEARCH 大小写敏感 ----------
|
|
67
|
+
ok('#105 JSON_SEARCH 大小写不同返回 NULL',
|
|
68
|
+
await q("SELECT JSON_SEARCH('[\"Hello\"]', 'one', 'hello')") === null, null);
|
|
69
|
+
ok('JSON_SEARCH 大小写相同命中',
|
|
70
|
+
await q("SELECT JSON_SEARCH('[\"Hello\"]', 'one', 'Hello')") === '$[0]', null);
|
|
71
|
+
|
|
72
|
+
// ---------- LIKE 通配符(差分发现) ----------
|
|
73
|
+
ok('JSON_SEARCH 支持 % 通配符',
|
|
74
|
+
await q("SELECT JSON_SEARCH('[\"hello world\"]', 'one', 'hello%')") === '$[0]', null);
|
|
75
|
+
ok('JSON_SEARCH 支持 _ 通配符',
|
|
76
|
+
await q("SELECT JSON_SEARCH('[\"Hello\"]', 'one', 'H_llo')") === '$[0]', null);
|
|
77
|
+
ok('JSON_SEARCH 的 % 不是字面量',
|
|
78
|
+
await q("SELECT JSON_SEARCH('[\"hello%world\"]', 'one', 'hello%')") === '$[0]', null);
|
|
79
|
+
const all = await q("SELECT JSON_SEARCH('{\"a\":\"x\",\"b\":\"x\"}', 'all', 'x')");
|
|
80
|
+
ok('all 模式拿到两个路径', Array.isArray(all) && all.length === 2, all);
|
|
81
|
+
|
|
82
|
+
console.log(`\n${pass} passed, ${fail} failed`);
|
|
83
|
+
process.exit(fail === 0 ? 0 : 1);
|
|
84
|
+
})().catch(e => {
|
|
85
|
+
console.log('[FAIL] unexpected exception: ' + e.stack.split('\n').slice(0, 3).join('\n'));
|
|
86
|
+
process.exit(1);
|
|
87
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/* ---- MySQL 进制 / 字符串 / IP / 位图工具函数 ---- */
|
|
2
|
+
/*
|
|
3
|
+
* 差分探针发现十几个常用函数全部落到 applyScalarFunction 的 default
|
|
4
|
+
* **静默返回 null** —— 调用方很容易把「没实现」误读成「值不存在」。
|
|
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
|
+
const q = async (sql) => (await executeSQL(db, sql, { safety: false })).rows[0][0];
|
|
20
|
+
|
|
21
|
+
// ---------- 进制 ----------
|
|
22
|
+
ok("BIT_LENGTH('abc') = 24", await q("SELECT BIT_LENGTH('abc')") === 24, null);
|
|
23
|
+
ok("BIT_LENGTH 中文按字节", await q("SELECT BIT_LENGTH('中文')") === 48, null);
|
|
24
|
+
ok('BIN(10)', await q('SELECT BIN(10)') === '1010', null);
|
|
25
|
+
ok('OCT(10)', await q('SELECT OCT(10)') === '12', null);
|
|
26
|
+
ok('HEX(255)', await q('SELECT HEX(255)') === 'FF', null);
|
|
27
|
+
ok("HEX('AB') 按字节", await q("SELECT HEX('AB')") === '4142', null);
|
|
28
|
+
ok("UNHEX('4142')", await q("SELECT UNHEX('4142')") === 'AB', null);
|
|
29
|
+
ok('HEX/UNHEX 往返', await q("SELECT UNHEX(HEX('hello'))") === 'hello', null);
|
|
30
|
+
ok('UNHEX 奇数长度 → NULL', await q("SELECT UNHEX('ABC')") === null, null);
|
|
31
|
+
ok('UNHEX 非十六进制 → NULL', await q("SELECT UNHEX('ZZ')") === null, null);
|
|
32
|
+
ok("CONV('A',16,2) = 1010", await q("SELECT CONV('A', 16, 2)") === '1010', null);
|
|
33
|
+
ok('CONV(1010,2,10) = 10', await q("SELECT CONV('1010', 2, 10)") === '10', null);
|
|
34
|
+
ok('CONV(0) = 0', await q("SELECT CONV('0', 10, 2)") === '0', null);
|
|
35
|
+
ok('CONV 非法数字 → NULL', await q("SELECT CONV('Z', 10, 2)") === null, null);
|
|
36
|
+
ok('CONV 非法进制 → NULL', await q("SELECT CONV('1', 1, 2)") === null, null);
|
|
37
|
+
|
|
38
|
+
// ---------- 字符串 ----------
|
|
39
|
+
ok("QUOTE('abc')", await q("SELECT QUOTE('abc')") === "'abc'", null);
|
|
40
|
+
ok('QUOTE NULL → NULL', await q('SELECT QUOTE(NULL)') === null, null);
|
|
41
|
+
ok("FIND_IN_SET('b','a,b,c') = 2", await q("SELECT FIND_IN_SET('b', 'a,b,c')") === 2, null);
|
|
42
|
+
ok('FIND_IN_SET 找不到 = 0', await q("SELECT FIND_IN_SET('z', 'a,b,c')") === 0, null);
|
|
43
|
+
ok('FIND_IN_SET 是精确匹配(不是子串)', await q("SELECT FIND_IN_SET('a', 'ab,cd')") === 0, null);
|
|
44
|
+
ok("INSERT('abcdef',2,3,'XY')", await q("SELECT INSERT('abcdef', 2, 3, 'XY')") === 'aXYef', null);
|
|
45
|
+
ok('INSERT 位置越界返回原串', await q("SELECT INSERT('abc', 9, 1, 'X')") === 'abc', null);
|
|
46
|
+
ok('FORMAT(1234.567,2)', await q('SELECT FORMAT(1234.567, 2)') === '1,234.57', null);
|
|
47
|
+
ok('FORMAT 负数', await q('SELECT FORMAT(-1234567.5, 1)') === '-1,234,567.5', null);
|
|
48
|
+
ok("CRC32('abc') 标准值", await q("SELECT CRC32('abc')") === 891568578, null);
|
|
49
|
+
ok('CRC32 空串', await q("SELECT CRC32('')") === 0, null);
|
|
50
|
+
|
|
51
|
+
// ---------- IP ----------
|
|
52
|
+
ok("INET_ATON('127.0.0.1')", await q("SELECT INET_ATON('127.0.0.1')") === 2130706433, null);
|
|
53
|
+
ok('INET_NTOA(2130706433)', await q('SELECT INET_NTOA(2130706433)') === '127.0.0.1', null);
|
|
54
|
+
ok('INET_ATON/NTOA 往返', await q("SELECT INET_NTOA(INET_ATON('192.168.1.10'))") === '192.168.1.10', null);
|
|
55
|
+
ok('INET_ATON 非法段 → NULL', await q("SELECT INET_ATON('999.1.1.1')") === null, null);
|
|
56
|
+
|
|
57
|
+
// ---------- 位图 / 语音 ----------
|
|
58
|
+
ok("MAKE_SET(5,'a','b','c') = a,c", await q("SELECT MAKE_SET(5, 'a', 'b', 'c')") === 'a,c', null);
|
|
59
|
+
ok('MAKE_SET(0) 空串', await q("SELECT MAKE_SET(0, 'a', 'b')") === '', null);
|
|
60
|
+
ok("EXPORT_SET(5,'Y','N',',',8)", await q("SELECT EXPORT_SET(5, 'Y', 'N', ',', 8)") === 'Y,N,Y,N,N,N,N,N', null);
|
|
61
|
+
ok("SOUNDEX('Hello') = H400", await q("SELECT SOUNDEX('Hello')") === 'H400', null);
|
|
62
|
+
ok('SOUNDEX 空串', await q("SELECT SOUNDEX('')") === '', null);
|
|
63
|
+
ok('SOUNDEX(NULL) → NULL', await q('SELECT SOUNDEX(NULL)') === null, null);
|
|
64
|
+
|
|
65
|
+
console.log(`\n${pass} passed, ${fail} failed`);
|
|
66
|
+
process.exit(fail === 0 ? 0 : 1);
|
|
67
|
+
})().catch(e => {
|
|
68
|
+
console.log('[FAIL] unexpected exception: ' + e.stack.split('\n').slice(0, 3).join('\n'));
|
|
69
|
+
process.exit(1);
|
|
70
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/* ---- 发版元数据门禁:必须能拦住「漏写 CHANGELOG」等脱节 ---- */
|
|
2
|
+
/*
|
|
3
|
+
* 背景:6.6.0/6.6.1、6.6.3/6.6.4 都发生过 release commit 只 bump 版本标记、
|
|
4
|
+
* 没写 CHANGELOG 章节,却照样打 tag 发版。门禁把这件事变成硬失败。
|
|
5
|
+
*
|
|
6
|
+
* 全部用临时目录构造反例,绝不改仓库里的真实文件。
|
|
7
|
+
*/
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const os = require('os');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const ROOT = path.join(__dirname, '..');
|
|
12
|
+
const { checkReleaseMetadata } = require(path.join(ROOT, 'scripts', 'check-release-metadata.js'));
|
|
13
|
+
|
|
14
|
+
let pass = 0, fail = 0;
|
|
15
|
+
function ok(name, cond, got) {
|
|
16
|
+
if (cond) { pass++; console.log('[OK] ' + name); }
|
|
17
|
+
else { fail++; console.log('[FAIL] ' + name + ' -> ' + JSON.stringify(got)); }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const TMP = fs.mkdtempSync(path.join(os.tmpdir(), 'jsql-release-meta-'));
|
|
21
|
+
const SRC = ['package.json', 'README.md', 'index.js', 'CHANGELOG.md'];
|
|
22
|
+
function fixture(dir, mutate) {
|
|
23
|
+
const root = path.join(TMP, dir);
|
|
24
|
+
fs.mkdirSync(root, { recursive: true });
|
|
25
|
+
const contents = {};
|
|
26
|
+
for (const f of SRC) contents[f] = fs.readFileSync(path.join(ROOT, f), 'utf8');
|
|
27
|
+
mutate(contents);
|
|
28
|
+
for (const f of SRC) fs.writeFileSync(path.join(root, f), contents[f]);
|
|
29
|
+
return root;
|
|
30
|
+
}
|
|
31
|
+
const has = (r, name) => r.checks.find(c => c.name === name);
|
|
32
|
+
// 反例必须随版本 bump 自动跟进:硬编码版本号会让 bump 后替换失配,
|
|
33
|
+
// 反例没构造出来却「通过」,测试自己变成假绿(6.6.5 → 6.6.6 时踩过)。
|
|
34
|
+
const VERSION = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')).version;
|
|
35
|
+
function replaceOrThrow(contents, file, from, to) {
|
|
36
|
+
if (!contents[file].includes(from)) {
|
|
37
|
+
throw new Error('反例构造失败:' + file + ' 里找不到 ' + JSON.stringify(from) + '(当前版本 ' + VERSION + ')');
|
|
38
|
+
}
|
|
39
|
+
contents[file] = contents[file].replace(from, to);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
// 真实仓库当前应通过
|
|
44
|
+
const real = checkReleaseMetadata(ROOT);
|
|
45
|
+
ok('真实仓库通过门禁', real.ok === true, real.checks.filter(c => !c.ok));
|
|
46
|
+
ok('门禁检查了 CHANGELOG 章节', !!has(real, 'CHANGELOG 含 [' + real.version + '] 章节'), real.checks.map(c => c.name));
|
|
47
|
+
|
|
48
|
+
// 反例 1:release commit 漏写 CHANGELOG 章节(这正是历史上反复出现的)
|
|
49
|
+
const missing = fixture('missing-section', (c) => {
|
|
50
|
+
const v = JSON.parse(c['package.json']).version;
|
|
51
|
+
const re = new RegExp('^## \\[' + v.replace(/\./g, '\\.') + '\\][^\\n]*\\n', 'm');
|
|
52
|
+
if (!re.test(c['CHANGELOG.md'])) throw new Error('反例构造失败:CHANGELOG 缺章节');
|
|
53
|
+
c['CHANGELOG.md'] = c['CHANGELOG.md'].replace(re, '');
|
|
54
|
+
});
|
|
55
|
+
const r1 = checkReleaseMetadata(missing);
|
|
56
|
+
ok('漏写 CHANGELOG 章节 → FAIL', r1.ok === false, r1.checks.filter(c => !c.ok));
|
|
57
|
+
ok('失败原因明确指向缺失章节',
|
|
58
|
+
r1.checks.some(c => !c.ok && /缺少 ## \[/.test(c.detail)), r1.checks.filter(c => !c.ok));
|
|
59
|
+
|
|
60
|
+
// 反例 2:README 横幅没跟着 bump
|
|
61
|
+
const banner = fixture('bad-banner', (c) => replaceOrThrow(c, 'README.md', '**v' + VERSION + '**', '**v0.0.1**'));
|
|
62
|
+
const r2 = checkReleaseMetadata(banner);
|
|
63
|
+
ok('README 横幅不一致 → FAIL', r2.ok === false, r2.checks.filter(c => !c.ok));
|
|
64
|
+
|
|
65
|
+
// 反例 3:index.js 头注释没跟着 bump
|
|
66
|
+
const idx = fixture('bad-index', (c) => replaceOrThrow(c, 'index.js', 'JSQL-NEO v' + VERSION, 'JSQL-NEO v0.0.1'));
|
|
67
|
+
const r3 = checkReleaseMetadata(idx);
|
|
68
|
+
ok('index.js 头注释不一致 → FAIL', r3.ok === false, r3.checks.filter(c => !c.ok));
|
|
69
|
+
|
|
70
|
+
// 反例 4:版本号格式非法
|
|
71
|
+
const badVer = fixture('bad-version', (c) => replaceOrThrow(c, 'package.json', '"version": "' + VERSION + '"', '"version": "6.6"'));
|
|
72
|
+
const r4 = checkReleaseMetadata(badVer);
|
|
73
|
+
ok('非法版本号 → FAIL', r4.ok === false, r4.checks.filter(c => !c.ok));
|
|
74
|
+
|
|
75
|
+
// 开发中往 Unreleased 累积内容不应让门禁变红(只给软提示)
|
|
76
|
+
const wip = fixture('wip-unreleased', (c) => {
|
|
77
|
+
c['CHANGELOG.md'] = c['CHANGELOG.md'].replace('## [Unreleased]\n', '## [Unreleased]\n\n### Added\n\n- 开发中\n');
|
|
78
|
+
});
|
|
79
|
+
const r5 = checkReleaseMetadata(wip);
|
|
80
|
+
ok('开发中 Unreleased 有内容仍通过', r5.ok === true, r5.checks.filter(c => !c.ok));
|
|
81
|
+
ok('但给出未转正内容的 WARN', r5.warnings.some(w => /未转正/.test(w)), r5.warnings);
|
|
82
|
+
|
|
83
|
+
// 门禁本身不联网:执行期间不应有子进程网络调用
|
|
84
|
+
const cp = require('child_process');
|
|
85
|
+
const orig = { efs: cp.execFileSync, ef: cp.execFile, sp: cp.spawn };
|
|
86
|
+
const calls = [];
|
|
87
|
+
cp.execFileSync = function (...a) { calls.push(a[0]); return orig.efs.apply(this, a); };
|
|
88
|
+
cp.execFile = function (...a) { calls.push(a[0]); return orig.ef.apply(this, a); };
|
|
89
|
+
cp.spawn = function (...a) { calls.push(a[0]); return orig.sp.apply(this, a); };
|
|
90
|
+
checkReleaseMetadata(ROOT);
|
|
91
|
+
cp.execFileSync = orig.efs; cp.execFile = orig.ef; cp.spawn = orig.sp;
|
|
92
|
+
ok('门禁是纯本地检查,零子进程调用', calls.length === 0, calls);
|
|
93
|
+
} finally {
|
|
94
|
+
try { fs.rmSync(TMP, { recursive: true, force: true }); } catch (_) {}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
console.log(`\n${pass} passed, ${fail} failed`);
|
|
98
|
+
process.exit(fail === 0 ? 0 : 1);
|