jsql-neo 6.8.17 → 6.8.18

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.18** — 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.18 — 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);
package/lib/pg_server.js CHANGED
@@ -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
  }
@@ -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.18",
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",
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",
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,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); });