jsql-neo 6.8.17 → 6.8.19

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.17** — 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.19** — 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.17 — Rust-Powered Embedded Database (WASM + HTTP)
2
+ * JSQL-NEO v6.8.19 — Rust-Powered Embedded Database (WASM + HTTP)
3
3
  *
4
4
  * @example
5
5
  * const jsql = require('jsql-neo');
@@ -885,10 +885,12 @@ class MongoServer {
885
885
  const key = dbName + '.' + coll;
886
886
  const list = this._indexesByColl.get(key) || [{ name: '_id_', columns: ['_id'], unique: true }];
887
887
  for (const spec of (doc.indexes || [])) {
888
- const columns = Object.keys(spec.key || {});
888
+ const keySpec = spec.key || {};
889
+ const columns = Object.keys(keySpec);
889
890
  if (columns.length === 0) continue;
890
891
  const name = spec.name || columns.map(c => c + '_1').join('_');
891
- const entry = { name, columns, unique: !!spec.unique, sparse: !!spec.sparse };
892
+ // #281:保留方向({a:-1}),listIndexes 原样回包
893
+ const entry = { name, columns, keySpec, unique: !!spec.unique, sparse: !!spec.sparse };
892
894
  const at = list.findIndex(i => i.name === name);
893
895
  if (at >= 0) list[at] = entry; else list.push(entry);
894
896
  }
@@ -908,7 +910,7 @@ class MongoServer {
908
910
  const list = this._indexesByColl.get(key) || [{ name: '_id_', columns: ['_id'], unique: true }];
909
911
  const ns = `${dbName}.${coll}`;
910
912
  const firstBatch = list.map(i => ({
911
- v: 2, key: Object.fromEntries(i.columns.map(c => [c, 1])), name: i.name, ns,
913
+ v: 2, key: i.keySpec || Object.fromEntries(i.columns.map(c => [c, 1])), name: i.name, ns,
912
914
  }));
913
915
  return { ok: 1, cursor: { id: { $long: 0 }, ns, firstBatch } };
914
916
  }
@@ -920,7 +922,7 @@ class MongoServer {
920
922
  if (spec === '*') {
921
923
  this._indexesByColl.set(key, [{ name: '_id_', columns: ['_id'], unique: true }]);
922
924
  } else {
923
- const name = typeof spec === 'string' ? spec : Object.keys(spec || {}).map(c => c + '_1').join('_');
925
+ const name = typeof spec === 'string' ? spec : Object.keys(spec || {}).map(c => c + '_' + (spec[c] < 0 ? '-1' : '1')).join('_');
924
926
  this._indexesByColl.set(key, list.filter(i => i.name !== name));
925
927
  }
926
928
  return { ok: 1, nIndexesWas: list.length };
@@ -928,8 +930,12 @@ class MongoServer {
928
930
  case 'count': {
929
931
  const coll = String(doc.count);
930
932
  const engine = await this._ensureCollection(coll, this._dbOf(doc));
931
- const rows = await this._matching(engine, coll, doc.query);
932
- return { ok: 1, n: Number(doc.limit) > 0 ? Math.min(rows.length, doc.limit) : rows.length };
933
+ let rows = await this._matching(engine, coll, doc.query);
934
+ // #280:count 也要尊重 skip
935
+ const skip = typeof doc.skip === 'number' && doc.skip > 0 ? Math.trunc(doc.skip) : 0;
936
+ if (skip > 0) rows = rows.slice(skip);
937
+ const limit = Number(doc.limit) > 0 ? Math.trunc(Number(doc.limit)) : 0;
938
+ return { ok: 1, n: limit > 0 ? Math.min(rows.length, limit) : rows.length };
933
939
  }
934
940
  case 'aggregate': {
935
941
  const coll = String(doc.aggregate);
@@ -211,7 +211,16 @@ function eofPacket(status = SERVER_STATUS_AUTOCOMMIT) {
211
211
  return b.build();
212
212
  }
213
213
 
214
- function errPacket(errno, message, sqlState = 'HY000') {
214
+ function mysqlSqlState(errno) {
215
+ return ({
216
+ 1048: '23000', 1050: '42S01', 1054: '42S22', 1062: '23000',
217
+ 1064: '42000', 1102: '42000', 1136: '21S01', 1146: '42S02',
218
+ 1264: '22003', 1406: '22001', 3819: 'HY000',
219
+ })[errno] || 'HY000';
220
+ }
221
+
222
+ function errPacket(errno, message, sqlState) {
223
+ if (!sqlState) sqlState = mysqlSqlState(errno);
215
224
  const b = new PacketBuilder();
216
225
  b.byte(0xff);
217
226
  b.int16(errno);
@@ -224,6 +233,15 @@ function errPacket(errno, message, sqlState = 'HY000') {
224
233
  function toMysqlErrno(e) {
225
234
  if (e && typeof e.code === 'number') return e.code;
226
235
  const m = e && e.message ? String(e.message).match(/^(ER_[A-Z_]+)/) : null;
236
+ // 引擎异常可能只有 message 没有 ER_ 前缀,补常见回退映射(#274)
237
+ const text = String((e && e.message) || '');
238
+ if (!m) {
239
+ if (/no such table|table .*(doesn't|does not) exist/i.test(text)) return 1146;
240
+ if (/no such column|unknown column/i.test(text)) return 1054;
241
+ if (/duplicate entry|unique constraint/i.test(text)) return 1062;
242
+ if (/cannot be null|not null constraint/i.test(text)) return 1048;
243
+ if (/syntax error|unexpected token|expected /i.test(text)) return 1064;
244
+ }
227
245
  if (m) {
228
246
  const known = {
229
247
  ER_DUP_ENTRY: 1062,
@@ -565,8 +583,9 @@ class MysqlConnection {
565
583
  case 0x02: { // COM_INIT_DB
566
584
  const db = body.toString('utf8');
567
585
  if (!this.server._safeDbName(db)) {
568
- this._malicious('COM_INIT_DB with invalid database name');
569
- return;
586
+ // #272:非法库名回 ERR_Packet,不能直接销毁连接
587
+ this._send(errPacket(1102, `Incorrect database name '${db}'`));
588
+ break;
570
589
  }
571
590
  this.server._switchDb(this, db)
572
591
  .then(() => this._send(okPacket()))
package/lib/pg_server.js CHANGED
@@ -160,7 +160,7 @@ function buildRowDescription(columns, types) {
160
160
  p.i32(0); // table oid
161
161
  p.i16(0); // column attnum
162
162
  p.i32(pgTypeOid(types[i]));
163
- p.i16(types[i] === 'integer' ? 4 : (types[i] === 'bigint' ? 8 : -1)); // typlen
163
+ p.i16(types[i] === 'integer' ? 4 : (types[i] === 'bigint' ? 8 : (types[i] === 'boolean' ? 1 : -1))); // typlen
164
164
  p.i32(-1); // typmod
165
165
  p.i16(0); // format code (text)
166
166
  }
@@ -436,7 +436,7 @@ class PgConnection {
436
436
  const password = this.server._userPassword(this.user);
437
437
  if (password === undefined) {
438
438
  // 用户不存在
439
- this._send(buildErrorResponse('28000', `password authentication failed for user "${this.user}"`));
439
+ this._send(buildErrorResponse('28P01', `password authentication failed for user "${this.user}"`));
440
440
  this.socket.end();
441
441
  return;
442
442
  }
@@ -493,7 +493,7 @@ class PgConnection {
493
493
  this._send(frame(0x52, sf.build())); // 'R'
494
494
  this._completeAuth();
495
495
  } catch (e) {
496
- this._send(buildErrorResponse('28000', 'password authentication failed for user "' + this.user + '"'));
496
+ this._send(buildErrorResponse('28P01', 'password authentication failed for user "' + this.user + '"'));
497
497
  this.socket.end();
498
498
  }
499
499
  }
@@ -616,7 +616,8 @@ class PgConnection {
616
616
  if (kind === 0x53) { // 'S' statement
617
617
  const stmt = this._prepared.get(name);
618
618
  if (!stmt) throw new Error(`prepared statement "${name}" does not exist`);
619
- this._send(buildParameterDesc(stmt.paramTypes.length > 0 ? stmt.paramTypes : [0]));
619
+ // #309:无参语句 ParameterDescription 应为 paramCount=0
620
+ this._send(buildParameterDesc(stmt.paramTypes || []));
620
621
  const cols = this._describeCols(stmt.sql);
621
622
  if (cols && cols.length > 0) {
622
623
  this._send(buildRowDescription(cols.columns, cols.types));
@@ -776,7 +777,9 @@ class PgConnection {
776
777
  this._txAborted = false;
777
778
  this._send(buildCommandComplete(String(res.type).toUpperCase()));
778
779
  } else if (res.type === 'createTable' || res.type === 'dropTable' || res.type === 'createDatabase' || res.type === 'dropDatabase') {
779
- this._send(buildCommandComplete('OK'));
780
+ // #308:DDL CommandComplete tag 用真实语句类型
781
+ const tags = { createTable: 'CREATE TABLE', dropTable: 'DROP TABLE', createDatabase: 'CREATE DATABASE', dropDatabase: 'DROP DATABASE' };
782
+ this._send(buildCommandComplete(tags[res.type] || 'OK'));
780
783
  } else if (res.type === 'showTables' || res.type === 'showDatabases' || res.type === 'showColumns') {
781
784
  const types = (res.columns || []).map(() => 'string');
782
785
  this._send(buildRowDescription(res.columns || [], types));
@@ -280,6 +280,10 @@ class RedisServer {
280
280
  if ((opt === 'EX' || opt === 'PX' || opt === 'NX' || opt === 'XX') && seen.has(opt)) {
281
281
  throw new Error('ERR syntax error');
282
282
  }
283
+ // #286:EX 与 PX 互斥
284
+ if ((opt === 'EX' && seen.has('PX')) || (opt === 'PX' && seen.has('EX'))) {
285
+ throw new Error('ERR syntax error');
286
+ }
283
287
  seen.add(opt);
284
288
  if (opt === 'EX') {
285
289
  const raw = String(args[++i]).trim();
@@ -625,12 +629,12 @@ class RedisServer {
625
629
  const rest = args.slice(1);
626
630
  if (rest.length % 2 !== 0) throw new Error('ERR syntax error');
627
631
  // #174:先完整校验所有 (score, member),任一非法则整条命令不产生变更
628
- const zset = v ? { ...v.val } : {};
632
+ const zset = v ? Object.assign(Object.create(null), v.val) : Object.create(null);
629
633
  let added = 0;
630
634
  for (let i = 0; i < rest.length; i += 2) {
631
635
  const score = parseRedisFloat(rest[i]);
632
636
  const member = rest[i + 1];
633
- if (!(member in zset)) added++;
637
+ if (!Object.prototype.hasOwnProperty.call(zset, member)) added++;
634
638
  zset[member] = score;
635
639
  }
636
640
  this.db.set(key, { type: 'zset', val: zset, ttl: v ? v.ttl : null });
@@ -674,7 +678,7 @@ class RedisServer {
674
678
  case 'ZSCORE': {
675
679
  const v = this._get(args[0]);
676
680
  if (v && v.type !== 'zset') throw new Error('WRONGTYPE Operation against a key holding the wrong kind of value');
677
- if (!v || !(args[1] in v.val)) return null;
681
+ if (!v || !Object.prototype.hasOwnProperty.call(v.val, args[1])) return null;
678
682
  // ZSCORE 的分数恒为 bulk string(含整数分数),不能落进 integer reply(#67)
679
683
  return String(v.val[args[1]]);
680
684
  }
@@ -690,7 +694,7 @@ class RedisServer {
690
694
  if (v.type !== 'zset') throw new Error('WRONGTYPE Operation against a key holding the wrong kind of value');
691
695
  let n = 0;
692
696
  for (const m of args.slice(1)) {
693
- if (m in v.val) { delete v.val[m]; n++; }
697
+ if (Object.prototype.hasOwnProperty.call(v.val, m)) { delete v.val[m]; n++; }
694
698
  }
695
699
  // #173:最后一个成员删除后键也要删除
696
700
  if (Object.keys(v.val).length === 0) this.db.delete(args[0]);
@@ -702,11 +706,13 @@ class RedisServer {
702
706
  const inc = parseRedisFloat(args[1]);
703
707
  const v = this._get(key);
704
708
  let zset;
705
- if (v && v.type === 'zset') zset = v.val;
709
+ if (v && v.type === 'zset') zset = Object.assign(Object.create(null), v.val);
706
710
  else if (v) throw new Error('WRONGTYPE Operation against a key holding the wrong kind of value');
707
- else { this.db.set(key, { type: 'zset', val: {} }); zset = this.db.get(key).val; }
711
+ else zset = Object.create(null);
708
712
  const member = args[2];
709
- zset[member] = (zset[member] || 0) + inc;
713
+ const prev = Object.prototype.hasOwnProperty.call(zset, member) ? zset[member] : 0;
714
+ zset[member] = prev + inc;
715
+ this.db.set(key, { type: 'zset', val: zset, ttl: v ? v.ttl : null });
710
716
  this._scheduleSnapshot();
711
717
  // 同 ZSCORE:分数用 bulk string 回复(#67)
712
718
  return String(zset[member]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsql-neo",
3
- "version": "6.8.17",
3
+ "version": "6.8.19",
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/issue-157-161.test.js && node test/issue-162-179.test.js && node test/issue-181-186.test.js && node test/issue-187.test.js && node test/issue-188-237.test.js && node test/issue-238-241.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 && node test/issue-314-321.test.js && node test/issue-312-320.test.js && node test/issue-243-289.test.js && node test/issue-284-292.test.js && node test/issue-301-305.test.js && node test/issue-248-252.test.js && node test/issue-259-264.test.js && node test/issue-255-270.test.js && node test/issue-253-269.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/issue-162-179.test.js && node test/issue-181-186.test.js && node test/issue-187.test.js && node test/issue-188-237.test.js && node test/issue-238-241.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 && node test/issue-314-321.test.js && node test/issue-312-320.test.js && node test/issue-243-289.test.js && node test/issue-284-292.test.js && node test/issue-301-305.test.js && node test/issue-248-252.test.js && node test/issue-259-264.test.js && node test/issue-255-270.test.js && node test/issue-253-269.test.js && node test/issue-280-310.test.js && node test/issue-272-311.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/issue-157-161.test.js && node test/issue-162-179.test.js && node test/issue-181-186.test.js && node test/issue-187.test.js && node test/issue-188-237.test.js && node test/issue-238-241.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 && node test/issue-314-321.test.js && node test/issue-312-320.test.js && node test/issue-243-289.test.js && node test/issue-284-292.test.js && node test/issue-301-305.test.js && node test/issue-248-252.test.js && node test/issue-259-264.test.js && node test/issue-255-270.test.js && node test/issue-253-269.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/issue-162-179.test.js && node test/issue-181-186.test.js && node test/issue-187.test.js && node test/issue-188-237.test.js && node test/issue-238-241.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 && node test/issue-314-321.test.js && node test/issue-312-320.test.js && node test/issue-243-289.test.js && node test/issue-284-292.test.js && node test/issue-301-305.test.js && node test/issue-248-252.test.js && node test/issue-259-264.test.js && node test/issue-255-270.test.js && node test/issue-253-269.test.js && node test/issue-280-310.test.js && node test/issue-272-311.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,68 @@
1
+ /*
2
+ * Regression tests for #272 #274 #308 #309 #311.
3
+ * node test/issue-272-311.test.js
4
+ */
5
+ const path = require('path');
6
+ const ROOT = path.join(__dirname, '..');
7
+
8
+ let passed = 0, failed = 0;
9
+ function ok(name, cond, extra) {
10
+ if (cond) { passed++; console.log('[OK]', name); }
11
+ else { failed++; console.log('[FAIL]', name, extra !== undefined ? '→ ' + JSON.stringify(extra) : ''); }
12
+ }
13
+
14
+ (async () => {
15
+ const mysql = (() => { try { return require(path.join(ROOT, 'node_modules', 'mysql2/promise')); } catch (e) { return null; } })();
16
+ if (mysql) {
17
+ const { createMysqlServer } = require(path.join(ROOT, 'lib', 'mysql_server.js'));
18
+ const srv = createMysqlServer({ port: 0, host: '127.0.0.1', dataDir: ':memory:', noAuth: true });
19
+ await new Promise((r) => srv.listen(r));
20
+ const conn = await mysql.createConnection({ host: '127.0.0.1', port: srv.address.port, user: 'root', database: 'app' });
21
+ // #274
22
+ let missing = null;
23
+ try { await conn.query('SELECT * FROM no_such_table'); } catch (e) { missing = e; }
24
+ ok('#274 missing table errno/sqlstate', missing && missing.errno === 1146 && missing.sqlState === '42S02', missing && { errno: missing.errno, state: missing.sqlState });
25
+ // #272
26
+ try { await conn.changeUser({ database: 'bad/name' }); } catch (e) { /* expected */ }
27
+ let alive = null;
28
+ try { await conn.query('SELECT 1 AS x'); alive = 1; } catch (e) { alive = e.message; }
29
+ ok('#272 invalid COM_INIT_DB keeps connection alive', alive === 1, alive);
30
+ await conn.end();
31
+ srv.close();
32
+ } else {
33
+ console.log('[SKIP] MySQL protocol tests (mysql2 not installed)');
34
+ }
35
+
36
+ // #311 boolean typlen = 1
37
+ {
38
+ const { buildRowDescription, buildParameterDesc } = require(path.join(ROOT, 'lib', 'pg_server.js'));
39
+ const buf = buildRowDescription(['b'], ['boolean']);
40
+ // frame: type(1)+len(4)+count(2)+name('b'+nul=2)+tableoid(4)+attnum(2)+typeoid(4)+typlen(2)
41
+ const typlen = buf.readInt16BE(5 + 2 + 2 + 4 + 2 + 4);
42
+ ok('#311 PG boolean typlen is 1', typlen === 1, typlen);
43
+ // #309 builder emits paramCount=0 for empty list
44
+ const pd = buildParameterDesc([]);
45
+ ok('#309 ParameterDescription has zero params', pd.readInt16BE(5) === 0, pd.readInt16BE(5));
46
+ }
47
+
48
+ // #308 DDL tag (pg driver exposes only the leading word, so check it is not "OK")
49
+ {
50
+ const { Client } = (() => { try { return require(path.join(ROOT, 'node_modules', 'pg')); } catch (e) { return {}; } })();
51
+ if (Client) {
52
+ const { createPgServer } = require(path.join(ROOT, 'lib', 'pg_server.js'));
53
+ const srv = createPgServer({ port: 0, host: '127.0.0.1', dataDir: ':memory:', noAuth: true });
54
+ await new Promise((r) => srv.listen(r));
55
+ const c = new Client({ host: '127.0.0.1', port: srv.address.port, user: 'root', database: 'app' });
56
+ await c.connect();
57
+ const r = await c.query('CREATE TABLE t (id INT)');
58
+ ok('#308 PG DDL CommandComplete tag is statement type', r.command === 'CREATE', r.command);
59
+ await c.end();
60
+ srv.close();
61
+ } else {
62
+ console.log('[SKIP] PG DDL tag (pg not installed)');
63
+ }
64
+ }
65
+
66
+ console.log(`\n${passed} passed, ${failed} failed`);
67
+ process.exit(failed === 0 ? 0 : 1);
68
+ })().catch((e) => { console.error('FATAL', e); process.exit(1); });
@@ -0,0 +1,77 @@
1
+ /*
2
+ * Regression tests for #280 #281 #286 #287 #310.
3
+ * node test/issue-280-310.test.js
4
+ */
5
+ const path = require('path');
6
+ const ROOT = path.join(__dirname, '..');
7
+ const { createRedisServer } = require(path.join(ROOT, 'lib', 'redis_server.js'));
8
+ const { createMongoServer } = require(path.join(ROOT, 'lib', 'mongo_server.js'));
9
+
10
+ let passed = 0, failed = 0;
11
+ function ok(name, cond, extra) {
12
+ if (cond) { passed++; console.log('[OK]', name); }
13
+ else { failed++; console.log('[FAIL]', name, extra !== undefined ? '→ ' + JSON.stringify(extra) : ''); }
14
+ }
15
+ function call(s, cmd, ...args) {
16
+ try { return { value: s.execute(cmd, args) }; } catch (e) { return { error: e.message }; }
17
+ }
18
+
19
+ (async () => {
20
+ // #286
21
+ {
22
+ const s = createRedisServer({ port: 0, dataDir: null });
23
+ const r = call(s, 'SET', 'k', 'v', 'EX', '10', 'PX', '5000');
24
+ ok('#286 SET EX+PX is a syntax error', /syntax error/.test(r.error || ''), r);
25
+ }
26
+ // #287
27
+ {
28
+ const s = createRedisServer({ port: 0, dataDir: null });
29
+ const a = call(s, 'ZADD', 'z', 1, '__proto__');
30
+ const b = call(s, 'ZADD', 'z', 2, 'constructor');
31
+ const c = call(s, 'ZADD', 'z', 3, '__proto__');
32
+ ok('#287 ZADD prototype names count as members', a.value === 1 && b.value === 1 && c.value === 0, { a, b, c });
33
+ const score = call(s, 'ZSCORE', 'z', '__proto__');
34
+ ok('#287 ZSCORE finds __proto__ member', score.value === '3', score);
35
+ const rem = call(s, 'ZREM', 'z', '__proto__');
36
+ ok('#287 ZREM removes prototype-named member', rem.value === 1, rem);
37
+ const left = call(s, 'ZRANGE', 'z', 0, -1);
38
+ ok('#287 ZSET contents intact', JSON.stringify(left.value) === JSON.stringify(['constructor']), left.value);
39
+ }
40
+ // #280 / #281
41
+ {
42
+ const mongo = createMongoServer({ dataDir: ':memory:' });
43
+ const dispatch = (cmd, doc) => mongo._dispatch(cmd, doc);
44
+ await dispatch('insert', {
45
+ insert: 'c', $db: 'test',
46
+ documents: [{ n: 1 }, { n: 2 }, { n: 3 }, { n: 4 }],
47
+ });
48
+ const count = await dispatch('count', { count: 'c', query: {}, skip: 2, limit: 1, $db: 'test' });
49
+ ok('#280 count honors skip then limit', count.n === 1, count);
50
+
51
+ await dispatch('createIndexes', { createIndexes: 'c', indexes: [{ key: { n: -1 }, name: 'n_-1', unique: false }], $db: 'test' });
52
+ const idx = await dispatch('listIndexes', { listIndexes: 'c', $db: 'test' });
53
+ const found = (idx.cursor && idx.cursor.firstBatch || []).find(i => i.name === 'n_-1');
54
+ ok('#281 listIndexes keeps index direction', found && found.key && found.key.n === -1, found);
55
+ }
56
+ // #310
57
+ {
58
+ const { Client } = (() => { try { return require(path.join(ROOT, 'node_modules', 'pg')); } catch (e) { return {}; } })();
59
+ if (Client) {
60
+ const { createPgServer } = require(path.join(ROOT, 'lib', 'pg_server.js'));
61
+ const srv = createPgServer({
62
+ port: 0, host: '127.0.0.1', dataDir: ':memory:',
63
+ auth: { root: { password: 'right', databases: ['app'] } },
64
+ });
65
+ await new Promise((r) => srv.listen(r));
66
+ const c = new Client({ host: '127.0.0.1', port: srv.address.port, user: 'root', database: 'app', password: 'wrong' });
67
+ let code = null;
68
+ try { await c.connect(); await c.end(); } catch (e) { code = e.code; }
69
+ ok('#310 wrong password returns 28P01', code === '28P01', code);
70
+ srv.close();
71
+ } else {
72
+ console.log('[SKIP] PG auth (pg not installed)');
73
+ }
74
+ }
75
+ console.log(`\n${passed} passed, ${failed} failed`);
76
+ process.exit(failed === 0 ? 0 : 1);
77
+ })().catch((e) => { console.error('FATAL', e); process.exit(1); });