jsql-neo 6.8.3 → 6.8.4

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 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.8.3** — stable release · [github.com/vexify-org/JSQL-neo](https://github.com/vexify-org/JSQL-neo) · [jsql.vexify.top](https://jsql.vexify.top)
6
+ > **v6.8.4** — 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
  ![Engines](https://img.shields.io/badge/engines-Native%20%7C%20WASM%20%7C%20Pure%20JS-7ee787)
9
9
  ![MySQL](https://img.shields.io/badge/protocol-MySQL%20compatible-1f6feb)
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * JSQL-NEO v6.8.3 — Rust-Powered Embedded Database (WASM + HTTP)
2
+ * JSQL-NEO v6.8.4 — Rust-Powered Embedded Database (WASM + HTTP)
3
3
  *
4
4
  * @example
5
5
  * const jsql = require('jsql-neo');
@@ -20,6 +20,16 @@ const net = require('net');
20
20
  const fs = require('fs');
21
21
  const path = require('path');
22
22
 
23
+ // Redis score/increment 必须是完整合法浮点数;parseFloat 会吞掉尾随垃圾("1abc" → 1)
24
+ function parseRedisFloat(raw) {
25
+ const s = String(raw).trim();
26
+ if (/^[+-]?inf(inity)?$/i.test(s)) return s.startsWith('-') ? -Infinity : Infinity;
27
+ if (!/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/.test(s)) {
28
+ throw new Error('ERR value is not a valid float');
29
+ }
30
+ return Number(s);
31
+ }
32
+
23
33
  const TYPE_SIGNATURES = {
24
34
  PING: 0, ECHO: 1, SET: -2, SETNX: 2, GET: 1, DEL: -1, EXISTS: -1, KEYS: 1,
25
35
  TYPE: 1, EXPIRE: 2, TTL: 1, PERSIST: 1,
@@ -162,15 +172,24 @@ class RedisServer {
162
172
  // Parse optional arguments: EX seconds | PX milliseconds | NX | XX
163
173
  let ttl = null;
164
174
  let nx = false, xx = false;
175
+ const seen = new Set();
165
176
  for (let i = 2; i < args.length; i++) {
166
- const opt = args[i].toUpperCase();
177
+ const opt = String(args[i]).toUpperCase();
178
+ if ((opt === 'EX' || opt === 'PX' || opt === 'NX' || opt === 'XX') && seen.has(opt)) {
179
+ throw new Error('ERR syntax error');
180
+ }
181
+ seen.add(opt);
167
182
  if (opt === 'EX') {
168
- const secs = parseInt(args[++i], 10);
169
- if (isNaN(secs) || secs < 0) throw new Error('ERR invalid expire time in set');
183
+ const raw = String(args[++i]).trim();
184
+ if (!/^[+-]?\d+$/.test(raw)) throw new Error("ERR invalid expire time in 'set' command");
185
+ const secs = Number(raw);
186
+ if (secs <= 0) throw new Error("ERR invalid expire time in 'set' command");
170
187
  ttl = Date.now() + secs * 1000;
171
188
  } else if (opt === 'PX') {
172
- const ms = parseInt(args[++i], 10);
173
- if (isNaN(ms) || ms < 0) throw new Error('ERR invalid expire time in set');
189
+ const raw = String(args[++i]).trim();
190
+ if (!/^[+-]?\d+$/.test(raw)) throw new Error("ERR invalid expire time in 'set' command");
191
+ const ms = Number(raw);
192
+ if (ms <= 0) throw new Error("ERR invalid expire time in 'set' command");
174
193
  ttl = Date.now() + ms;
175
194
  } else if (opt === 'NX') {
176
195
  nx = true;
@@ -180,6 +199,7 @@ class RedisServer {
180
199
  throw new Error('ERR syntax error');
181
200
  }
182
201
  }
202
+ if (nx && xx) throw new Error('ERR syntax error');
183
203
  const prev = this._get(key);
184
204
  if (nx && prev) return null;
185
205
  if (xx && !prev) return null;
@@ -239,8 +259,9 @@ class RedisServer {
239
259
  return n;
240
260
  }
241
261
  case 'EXISTS': {
262
+ // Redis:重复 key 只计一次
242
263
  let n = 0;
243
- for (const k of args) if (this._get(k)) n++;
264
+ for (const k of new Set(args)) if (this._get(k)) n++;
244
265
  return n;
245
266
  }
246
267
  case 'KEYS': {
@@ -275,6 +296,7 @@ class RedisServer {
275
296
  const v = this._get(args[0]);
276
297
  if (!v || !v.ttl) return 0;
277
298
  v.ttl = null;
299
+ this._scheduleSnapshot();
278
300
  return 1;
279
301
  }
280
302
  case 'HSET': {
@@ -458,9 +480,8 @@ class RedisServer {
458
480
  if (rest.length % 2 !== 0) throw new Error('ERR syntax error');
459
481
  let added = 0;
460
482
  for (let i = 0; i < rest.length; i += 2) {
461
- const score = parseFloat(rest[i]);
483
+ const score = parseRedisFloat(rest[i]);
462
484
  const member = rest[i + 1];
463
- if (isNaN(score)) throw new Error('ERR value is not a valid float');
464
485
  if (!(member in zset)) added++;
465
486
  zset[member] = score;
466
487
  }
@@ -526,8 +547,7 @@ class RedisServer {
526
547
  }
527
548
  case 'ZINCRBY': {
528
549
  const key = args[0];
529
- const inc = parseFloat(args[1]);
530
- if (isNaN(inc)) throw new Error('ERR value is not a valid float');
550
+ const inc = parseRedisFloat(args[1]);
531
551
  const v = this._get(key);
532
552
  let zset;
533
553
  if (v && v.type === 'zset') zset = v.val;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsql-neo",
3
- "version": "6.8.3",
3
+ "version": "6.8.4",
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/issue-118-136.test.js && node test/issue-127.test.js && node test/issue-138-156.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 && node test/mongo-persistence.test.js && node test/mongo-objectid.test.js && node test/mongo-arrays.test.js && node test/issue-117.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/issue-118-136.test.js && node test/issue-127.test.js && node test/issue-138-156.test.js && node test/issue-157-161.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 && node test/mongo-persistence.test.js && node test/mongo-objectid.test.js && node test/mongo-arrays.test.js && node test/issue-117.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/issue-118-136.test.js && node test/issue-127.test.js && node test/issue-138-156.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 && node test/mongo-persistence.test.js && node test/mongo-objectid.test.js && node test/mongo-arrays.test.js && node test/issue-117.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/issue-118-136.test.js && node test/issue-127.test.js && node test/issue-138-156.test.js && node test/issue-157-161.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 && node test/mongo-persistence.test.js && node test/mongo-objectid.test.js && node test/mongo-arrays.test.js && node test/issue-117.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",
@@ -0,0 +1,54 @@
1
+ /* 回归测试:issue #157-#161(Redis RESP 命令语义) */
2
+ const path = require('path');
3
+ const ROOT = path.join(__dirname, '..');
4
+ const { RedisServer } = require(path.join(ROOT, 'lib', 'redis_server.js'));
5
+
6
+ let pass = 0, fail = 0;
7
+ function ok(name, cond, got) {
8
+ if (cond) { pass++; console.log('[OK] ' + name); }
9
+ else { fail++; console.log('[FAIL] ' + name + ' -> ' + JSON.stringify(got)); }
10
+ }
11
+ function throws(fn, re) {
12
+ try { fn(); return false; } catch (e) { return re ? re.test(e.message) : true; }
13
+ }
14
+
15
+ const s = new RedisServer({ port: 0, noAuth: true });
16
+
17
+ // #157 SET EX/PX 非正过期时间报错
18
+ ok('#157 SET EX 0 报错', throws(() => s.execute('SET', ['k', 'v', 'EX', '0']), /invalid expire time/));
19
+ ok('#157 SET PX 0 报错', throws(() => s.execute('SET', ['k2', 'v', 'PX', '0']), /invalid expire time/));
20
+ ok('#157 SET EX -5 报错', throws(() => s.execute('SET', ['k3', 'v', 'EX', '-5']), /invalid expire time/));
21
+ ok('#157 SET EX 10 正常', s.execute('SET', ['ok1', 'v', 'EX', '10']) === 'OK');
22
+
23
+ // #158 互斥/重复选项报错
24
+ ok('#158 NX+XX 报错', throws(() => s.execute('SET', ['k', 'v', 'NX', 'XX']), /syntax error/));
25
+ ok('#158 重复 EX 报错', throws(() => s.execute('SET', ['k', 'v', 'EX', '10', 'EX', '20']), /syntax error/));
26
+
27
+ // #159 EXISTS 去重计数
28
+ s.execute('SET', ['ek', 'v']);
29
+ ok('#159 EXISTS k k k = 1', s.execute('EXISTS', ['ek', 'ek', 'ek']) === 1);
30
+ ok('#159 EXISTS k missing k = 1', s.execute('EXISTS', ['ek', 'nope', 'ek']) === 1);
31
+ ok('#159 EXISTS 两个不同 key', s.execute('EXISTS', ['ek', 'ok1']) === 2);
32
+
33
+ // #160 PERSIST 触发快照
34
+ {
35
+ s.execute('SET', ['pk', 'v', 'EX', '100']);
36
+ const orig = s._scheduleSnapshot.bind(s);
37
+ let called = 0;
38
+ s._scheduleSnapshot = () => { called++; orig(); };
39
+ const r = s.execute('PERSIST', ['pk']);
40
+ s._scheduleSnapshot = orig;
41
+ ok('#160 PERSIST 返回 1 且调度快照', r === 1 && called > 0, { r, called });
42
+ }
43
+
44
+ // #161 ZADD/ZINCRBY 严格浮点
45
+ ok('#161 ZADD 尾随垃圾报错', throws(() => s.execute('ZADD', ['z', '1abc', 'm']), /valid float/));
46
+ ok('#161 ZINCRBY 尾随垃圾报错', throws(() => s.execute('ZINCRBY', ['z', '2xyz', 'm']), /valid float/));
47
+ ok('#161 ZADD 合法小数', s.execute('ZADD', ['z', '1.5', 'm']) === 1 && s.execute('ZSCORE', ['z', 'm']) === '1.5');
48
+ ok('#161 ZADD NaN 报错', throws(() => s.execute('ZADD', ['z2', 'NaN', 'm']), /valid float/));
49
+ ok('#161 ZADD inf 放行', s.execute('ZADD', ['z3', 'inf', 'm']) === 1);
50
+
51
+ console.log(`\n${pass} passed, ${fail} failed`);
52
+ process.exitCode = fail ? 1 : 0;
53
+ if (s.stop) s.stop();
54
+ process.exit(fail ? 1 : 0);