@pi-r/postgres 0.9.4 → 0.10.0

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/client/index.js CHANGED
@@ -73,7 +73,7 @@ function setCredential(item) {
73
73
  errors.push('user');
74
74
  }
75
75
  if (errors.length > 0) {
76
- throw (0, types_1.errorMessage)("postgres", 'Not defined - ' + errors.join(' | '));
76
+ throw (0, types_1.errorMessage)("postgres", "Invalid credentials", errors.join(', '));
77
77
  }
78
78
  }
79
79
  if (credential.host?.endsWith('.rds.amazonaws.com')) {
@@ -96,7 +96,8 @@ function setCredential(item) {
96
96
  }
97
97
  let username, password, pool;
98
98
  if ((0, types_1.isString)(usePool)) {
99
- if (username = credential.user || credential.connectionString && (0, util_1.parseConnectionString)(credential.connectionString)?.username) {
99
+ username = credential.user || credential.connectionString && (0, util_1.parseConnectionString)(credential.connectionString)?.username;
100
+ if (username) {
100
101
  [password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
101
102
  if (pool) {
102
103
  pool.add(item, password);
@@ -110,10 +111,7 @@ function setCredential(item) {
110
111
  }
111
112
  const config = this.getPoolConfig("postgres", password);
112
113
  if (config) {
113
- const { min, max, idle, timeout } = config;
114
- if (min >= 0) {
115
- credential.min ??= min;
116
- }
114
+ const { max, idle, timeout } = config;
117
115
  if (max > 0) {
118
116
  credential.max ??= max;
119
117
  }
package/client/pool.js CHANGED
@@ -3,6 +3,7 @@ const types_1 = require("@e-mc/types");
3
3
  const DbPool = require('@e-mc/db/pool');
4
4
  const POOL_ACTIVE = new WeakSet();
5
5
  class PostgresPool extends DbPool {
6
+ static CACHE_UNUSED = ['statement_timeout', 'query_timeout', 'keepAliveInitialDelayMillis', 'idle_in_transaction_session_timeout', 'connectionTimeoutMillis', 'idleTimeoutMillis', 'keepAlive', 'max', 'log', 'allowExitOnIdle', 'maxUses'];
6
7
  static asString(credential) {
7
8
  if (credential.host && credential.user) {
8
9
  return JSON.stringify(this.removeUUIDKey(credential));
@@ -24,10 +25,10 @@ class PostgresPool extends DbPool {
24
25
  result.ssl = { cert };
25
26
  }
26
27
  else if (Buffer.isBuffer(cert)) {
27
- result.ssl = { cert: cert.toString('utf-8') };
28
+ result.ssl = { cert: cert.toString('utf8') };
28
29
  }
29
30
  else if ((0, types_1.isArray)(cert)) {
30
- result.ssl = { cert: cert.reduce((a, b) => a + (Buffer.isBuffer(b) ? b.toString('utf-8') : b), '') };
31
+ result.ssl = { cert: cert.reduce((a, b) => a + (Buffer.isBuffer(b) ? b.toString('utf8') : b), '') };
31
32
  }
32
33
  else {
33
34
  result.ssl = { cert: "Unknown" };
@@ -45,11 +46,10 @@ class PostgresPool extends DbPool {
45
46
  return this.client.end();
46
47
  }
47
48
  isEmpty() {
48
- return this.closed || this.client.totalCount === 0 && this.client.waitingCount === 0;
49
+ return this.closed || this.client.totalCount === 0 && this.client.waitingCount === 0 && this.client.idleCount === 0;
49
50
  }
50
51
  get closed() {
51
52
  return this.client.ended;
52
53
  }
53
54
  }
54
- PostgresPool.CACHE_UNUSED = ['keepAlive', 'statement_timeout', 'query_timeout', 'keepAliveInitialDelayMillis', 'idle_in_transaction_session_timeout', 'connectionTimeoutMillis', 'max', 'min', 'idleTimeoutMillis', 'log', 'allowExitOnIdle', 'maxUses'];
55
55
  module.exports = PostgresPool;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/postgres",
3
- "version": "0.9.4",
3
+ "version": "0.10.0",
4
4
  "description": "PostgreSQL client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -20,10 +20,10 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/db": "^0.11.5",
24
- "@e-mc/types": "^0.11.5",
25
- "pg": "^8.14.1",
26
- "pg-connection-string": "^2.7.0",
27
- "pg-query-stream": "^4.8.1"
23
+ "@e-mc/db": "^0.12.0",
24
+ "@e-mc/types": "^0.12.0",
25
+ "pg": "^8.15.5",
26
+ "pg-connection-string": "^2.8.5",
27
+ "pg-query-stream": "^4.9.5"
28
28
  }
29
29
  }