pg-cache 3.15.1 → 3.15.3
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/esm/lru.js +3 -8
- package/esm/pg.js +4 -9
- package/lru.js +3 -8
- package/package.json +5 -4
- package/pg.js +4 -9
package/esm/lru.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseEnvNumber } from '12factor-env';
|
|
1
2
|
import { Logger } from '@pgpmjs/logger';
|
|
2
3
|
import { LRUCache } from 'lru-cache';
|
|
3
4
|
const log = new Logger('pg-cache');
|
|
@@ -6,12 +7,6 @@ const ONE_DAY = ONE_HOUR_IN_MS * 24;
|
|
|
6
7
|
const ONE_YEAR = ONE_DAY * 366;
|
|
7
8
|
// Kubernetes sends only SIGTERM on pod shutdown
|
|
8
9
|
const SYS_EVENTS = ['SIGTERM'];
|
|
9
|
-
const parseEnvInt = (val, fallback) => {
|
|
10
|
-
if (!val)
|
|
11
|
-
return fallback;
|
|
12
|
-
const n = parseInt(val, 10);
|
|
13
|
-
return isNaN(n) ? fallback : n;
|
|
14
|
-
};
|
|
15
10
|
/**
|
|
16
11
|
* Read cache configuration from environment variables.
|
|
17
12
|
*
|
|
@@ -21,8 +16,8 @@ const parseEnvInt = (val, fallback) => {
|
|
|
21
16
|
*/
|
|
22
17
|
export function getPgCacheConfig() {
|
|
23
18
|
return {
|
|
24
|
-
max:
|
|
25
|
-
ttl:
|
|
19
|
+
max: parseEnvNumber(process.env.PG_CACHE_MAX) ?? 50,
|
|
20
|
+
ttl: parseEnvNumber(process.env.PG_CACHE_TTL_MS) ?? ONE_YEAR,
|
|
26
21
|
};
|
|
27
22
|
}
|
|
28
23
|
class ManagedPgPool {
|
package/esm/pg.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseEnvNumber } from '12factor-env';
|
|
1
2
|
import pg from 'pg';
|
|
2
3
|
import { getPgEnvOptions } from 'pg-env';
|
|
3
4
|
import { Logger } from '@pgpmjs/logger';
|
|
@@ -5,12 +6,6 @@ import { getActivePgPoolFactory } from './driver';
|
|
|
5
6
|
import { pgCache } from './lru';
|
|
6
7
|
const log = new Logger('pg-cache');
|
|
7
8
|
export const buildConnectionString = (user, password, host, port, database) => `postgres://${user}:${password}@${host}:${port}/${database}`;
|
|
8
|
-
const parseEnvInt = (val, fallback) => {
|
|
9
|
-
if (!val)
|
|
10
|
-
return fallback;
|
|
11
|
-
const n = parseInt(val, 10);
|
|
12
|
-
return isNaN(n) ? fallback : n;
|
|
13
|
-
};
|
|
14
9
|
/**
|
|
15
10
|
* Read per-pool configuration from environment variables.
|
|
16
11
|
*
|
|
@@ -21,9 +16,9 @@ const parseEnvInt = (val, fallback) => {
|
|
|
21
16
|
*/
|
|
22
17
|
export function getPgPoolConfig(overrides) {
|
|
23
18
|
return {
|
|
24
|
-
max: overrides?.max ??
|
|
25
|
-
idleTimeoutMillis: overrides?.idleTimeoutMillis ??
|
|
26
|
-
connectionTimeoutMillis: overrides?.connectionTimeoutMillis ??
|
|
19
|
+
max: overrides?.max ?? parseEnvNumber(process.env.PG_POOL_MAX) ?? 5,
|
|
20
|
+
idleTimeoutMillis: overrides?.idleTimeoutMillis ?? parseEnvNumber(process.env.PG_POOL_IDLE_TIMEOUT_MS) ?? 30000,
|
|
21
|
+
connectionTimeoutMillis: overrides?.connectionTimeoutMillis ?? parseEnvNumber(process.env.PG_POOL_CONNECTION_TIMEOUT_MS) ?? 5000,
|
|
27
22
|
...(overrides?.allowExitOnIdle !== undefined && { allowExitOnIdle: overrides.allowExitOnIdle }),
|
|
28
23
|
};
|
|
29
24
|
}
|
package/lru.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.teardownPgPools = exports.close = exports.pgCache = exports.PgPoolCacheManager = void 0;
|
|
4
4
|
exports.getPgCacheConfig = getPgCacheConfig;
|
|
5
|
+
const _12factor_env_1 = require("12factor-env");
|
|
5
6
|
const logger_1 = require("@pgpmjs/logger");
|
|
6
7
|
const lru_cache_1 = require("lru-cache");
|
|
7
8
|
const log = new logger_1.Logger('pg-cache');
|
|
@@ -10,12 +11,6 @@ const ONE_DAY = ONE_HOUR_IN_MS * 24;
|
|
|
10
11
|
const ONE_YEAR = ONE_DAY * 366;
|
|
11
12
|
// Kubernetes sends only SIGTERM on pod shutdown
|
|
12
13
|
const SYS_EVENTS = ['SIGTERM'];
|
|
13
|
-
const parseEnvInt = (val, fallback) => {
|
|
14
|
-
if (!val)
|
|
15
|
-
return fallback;
|
|
16
|
-
const n = parseInt(val, 10);
|
|
17
|
-
return isNaN(n) ? fallback : n;
|
|
18
|
-
};
|
|
19
14
|
/**
|
|
20
15
|
* Read cache configuration from environment variables.
|
|
21
16
|
*
|
|
@@ -25,8 +20,8 @@ const parseEnvInt = (val, fallback) => {
|
|
|
25
20
|
*/
|
|
26
21
|
function getPgCacheConfig() {
|
|
27
22
|
return {
|
|
28
|
-
max:
|
|
29
|
-
ttl:
|
|
23
|
+
max: (0, _12factor_env_1.parseEnvNumber)(process.env.PG_CACHE_MAX) ?? 50,
|
|
24
|
+
ttl: (0, _12factor_env_1.parseEnvNumber)(process.env.PG_CACHE_TTL_MS) ?? ONE_YEAR,
|
|
30
25
|
};
|
|
31
26
|
}
|
|
32
27
|
class ManagedPgPool {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg-cache",
|
|
3
|
-
"version": "3.15.
|
|
3
|
+
"version": "3.15.3",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PostgreSQL connection pool LRU cache manager",
|
|
6
6
|
"main": "index.js",
|
|
@@ -29,11 +29,12 @@
|
|
|
29
29
|
"test:watch": "jest --watch"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"12factor-env": "^1.17.1",
|
|
32
33
|
"@pgpmjs/logger": "^2.14.0",
|
|
33
|
-
"@pgpmjs/types": "^2.
|
|
34
|
+
"@pgpmjs/types": "^2.36.0",
|
|
34
35
|
"lru-cache": "^11.2.7",
|
|
35
36
|
"pg": "^8.21.0",
|
|
36
|
-
"pg-env": "^1.18.
|
|
37
|
+
"pg-env": "^1.18.1"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@types/pg": "^8.20.0",
|
|
@@ -48,5 +49,5 @@
|
|
|
48
49
|
"connection",
|
|
49
50
|
"constructive"
|
|
50
51
|
],
|
|
51
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "39db6d576bce7bc1de8123849f237b1695779d88"
|
|
52
53
|
}
|
package/pg.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getPgPool = exports.defaultPgPoolFactory = exports.buildConnectionString = void 0;
|
|
7
7
|
exports.getPgPoolConfig = getPgPoolConfig;
|
|
8
|
+
const _12factor_env_1 = require("12factor-env");
|
|
8
9
|
const pg_1 = __importDefault(require("pg"));
|
|
9
10
|
const pg_env_1 = require("pg-env");
|
|
10
11
|
const logger_1 = require("@pgpmjs/logger");
|
|
@@ -13,12 +14,6 @@ const lru_1 = require("./lru");
|
|
|
13
14
|
const log = new logger_1.Logger('pg-cache');
|
|
14
15
|
const buildConnectionString = (user, password, host, port, database) => `postgres://${user}:${password}@${host}:${port}/${database}`;
|
|
15
16
|
exports.buildConnectionString = buildConnectionString;
|
|
16
|
-
const parseEnvInt = (val, fallback) => {
|
|
17
|
-
if (!val)
|
|
18
|
-
return fallback;
|
|
19
|
-
const n = parseInt(val, 10);
|
|
20
|
-
return isNaN(n) ? fallback : n;
|
|
21
|
-
};
|
|
22
17
|
/**
|
|
23
18
|
* Read per-pool configuration from environment variables.
|
|
24
19
|
*
|
|
@@ -29,9 +24,9 @@ const parseEnvInt = (val, fallback) => {
|
|
|
29
24
|
*/
|
|
30
25
|
function getPgPoolConfig(overrides) {
|
|
31
26
|
return {
|
|
32
|
-
max: overrides?.max ??
|
|
33
|
-
idleTimeoutMillis: overrides?.idleTimeoutMillis ??
|
|
34
|
-
connectionTimeoutMillis: overrides?.connectionTimeoutMillis ??
|
|
27
|
+
max: overrides?.max ?? (0, _12factor_env_1.parseEnvNumber)(process.env.PG_POOL_MAX) ?? 5,
|
|
28
|
+
idleTimeoutMillis: overrides?.idleTimeoutMillis ?? (0, _12factor_env_1.parseEnvNumber)(process.env.PG_POOL_IDLE_TIMEOUT_MS) ?? 30000,
|
|
29
|
+
connectionTimeoutMillis: overrides?.connectionTimeoutMillis ?? (0, _12factor_env_1.parseEnvNumber)(process.env.PG_POOL_CONNECTION_TIMEOUT_MS) ?? 5000,
|
|
35
30
|
...(overrides?.allowExitOnIdle !== undefined && { allowExitOnIdle: overrides.allowExitOnIdle }),
|
|
36
31
|
};
|
|
37
32
|
}
|