@nsshunt/stsdatamanagement 1.16.8 → 1.16.9
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/dist/pgpoolmanager.js +4 -4
- package/dist/pgpoolmanager.js.map +1 -1
- package/package.json +2 -1
- package/pgpoolmanager.ts +13 -13
- package/types/pgpoolmanager.d.ts +2 -1
- package/types/pgpoolmanager.d.ts.map +1 -1
- package/types/pgutils.d.ts +2 -2
package/dist/pgpoolmanager.js
CHANGED
|
@@ -11,11 +11,11 @@ const stsinstrumentation_1 = require("@nsshunt/stsinstrumentation");
|
|
|
11
11
|
const debug_1 = __importDefault(require("debug"));
|
|
12
12
|
const debug = (0, debug_1.default)(`proc:${process.pid}`);
|
|
13
13
|
require("colors");
|
|
14
|
-
const
|
|
14
|
+
const cluster_1 = __importDefault(require("cluster"));
|
|
15
15
|
//const pg = require('pg');
|
|
16
16
|
//pg.types.setTypeParser(20, BigInt); // Type Id 20 = BIGINT | BIGSERIAL
|
|
17
17
|
// https://stackoverflow.com/questions/39168501/pg-promise-returns-integers-as-strings
|
|
18
|
-
const
|
|
18
|
+
const pg_1 = require("pg");
|
|
19
19
|
class PGPoolManager {
|
|
20
20
|
constructor(options) {
|
|
21
21
|
this._options = null;
|
|
@@ -29,7 +29,7 @@ class PGPoolManager {
|
|
|
29
29
|
this._options = options;
|
|
30
30
|
const connectionStringURI = isProduction ? databaseUrl : (options.usedefaultdb === true ? defaultDatabaseConnectionString : connectionString);
|
|
31
31
|
// https://mylifedigital.co.uk/securing-node-postgres-with-ssl/
|
|
32
|
-
this._pool = new Pool({
|
|
32
|
+
this._pool = new pg_1.Pool({
|
|
33
33
|
connectionString: connectionStringURI,
|
|
34
34
|
ssl: isProduction,
|
|
35
35
|
max: poolSize // Default is 10 - This will be the number in a pool per thread (worker)
|
|
@@ -50,7 +50,7 @@ class PGPoolManager {
|
|
|
50
50
|
const sep = usernamepassword.split(':');
|
|
51
51
|
const usernamepasswordReplacement = usernamepassword.replace(sep[1], '*****************************');
|
|
52
52
|
const safeConnectionStringURI = connectionStringURI.replace(usernamepassword, usernamepasswordReplacement);
|
|
53
|
-
if (
|
|
53
|
+
if (cluster_1.default.isPrimary) {
|
|
54
54
|
debug(`Created Database Pool with Master Thread, PID: [${process.pid}]`.yellow);
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgpoolmanager.js","sourceRoot":"","sources":["../pgpoolmanager.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAC7C,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,+BAA+B,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,IAAA,oBAAQ,GAAE,CAAA;AAE7G,gDAA0C;AAC1C,oEAA6E;AAE7E,kDAA0B;AAC1B,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,QAAQ,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AAE3C,kBAAe;AAEf,
|
|
1
|
+
{"version":3,"file":"pgpoolmanager.js","sourceRoot":"","sources":["../pgpoolmanager.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAC7C,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,+BAA+B,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,IAAA,oBAAQ,GAAE,CAAA;AAE7G,gDAA0C;AAC1C,oEAA6E;AAE7E,kDAA0B;AAC1B,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,QAAQ,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AAE3C,kBAAe;AAEf,sDAA6B;AAE7B,2BAA2B;AAC3B,wEAAwE;AACxE,sFAAsF;AACtF,2BAAqC;AAMrC,MAAa,aAAa;IAMzB,YAAY,OAA8B;QAJlC,aAAQ,GAAyB,IAAI,CAAC;QACtC,cAAS,GAAiB,IAAI,CAAC;QAC/B,UAAK,GAAS,IAAI,CAAC;QAI1B,IAAI,CAAC,OAA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I,CAAC,SAAS;aACI,CAAC,CAAC;YAE/B,iBAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,0BAAK,CAAC,6BAA6B,EAAE;gBAChE,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY;aACC,CAAC,CAAC;SAC/B;IACF,CAAC;IAED,iBAAiB,CAAC,QAAQ,GAAG,IAAI;QAEhC,IAAI,iBAAM,CAAC,GAAG,EAAE;YACf,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE;gBAEjC,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC1B,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,CAAC;SACrB;QAED;;;;;;;;;;;;UAYE;IACH,CAAC;IAED,iBAAiB;QAEhB,2BAA2B;QAC3B,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACvB,CAAC;CACD;AAtID,sCAsIC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsshunt/stsdatamanagement",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.9",
|
|
4
4
|
"description": "STS Data Management Modules, Utilities and Services",
|
|
5
5
|
"main": "dist/dbaccess.js",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@nsshunt/stsconfig": "^1.24.9",
|
|
8
8
|
"@nsshunt/stsinstrumentation": "^6.10.1",
|
|
9
9
|
"@nsshunt/stsutils": "^1.14.9",
|
|
10
|
+
"@types/pg": "^8.6.5",
|
|
10
11
|
"axios": "^0.27.2",
|
|
11
12
|
"bcryptjs": "^2.4.3",
|
|
12
13
|
"cli-progress": "^3.11.0",
|
package/pgpoolmanager.ts
CHANGED
|
@@ -9,12 +9,12 @@ const debug = Debug(`proc:${process.pid}`);
|
|
|
9
9
|
|
|
10
10
|
import 'colors'
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
import cluster from 'cluster'
|
|
13
13
|
|
|
14
14
|
//const pg = require('pg');
|
|
15
15
|
//pg.types.setTypeParser(20, BigInt); // Type Id 20 = BIGINT | BIGSERIAL
|
|
16
16
|
// https://stackoverflow.com/questions/39168501/pg-promise-returns-integers-as-strings
|
|
17
|
-
|
|
17
|
+
import { Pool, PoolConfig } from 'pg'
|
|
18
18
|
|
|
19
19
|
export interface PGPoolManagerOptions {
|
|
20
20
|
usedefaultdb: boolean
|
|
@@ -24,7 +24,7 @@ export class PGPoolManager
|
|
|
24
24
|
{
|
|
25
25
|
private _options: PGPoolManagerOptions = null;
|
|
26
26
|
private _observer: NodeJS.Timer = null;
|
|
27
|
-
private _pool = null;
|
|
27
|
+
private _pool: Pool = null;
|
|
28
28
|
|
|
29
29
|
constructor(options?: PGPoolManagerOptions)
|
|
30
30
|
{
|
|
@@ -35,7 +35,7 @@ export class PGPoolManager
|
|
|
35
35
|
}
|
|
36
36
|
this._options = options;
|
|
37
37
|
|
|
38
|
-
const connectionStringURI = isProduction ? databaseUrl : (options.usedefaultdb === true ? defaultDatabaseConnectionString : connectionString );
|
|
38
|
+
const connectionStringURI: string = isProduction ? databaseUrl : (options.usedefaultdb === true ? defaultDatabaseConnectionString : connectionString );
|
|
39
39
|
// https://mylifedigital.co.uk/securing-node-postgres-with-ssl/
|
|
40
40
|
this._pool = new Pool({
|
|
41
41
|
connectionString: connectionStringURI,
|
|
@@ -52,15 +52,15 @@ export class PGPoolManager
|
|
|
52
52
|
//cert: fs.readFileSync('/path/to/client-certificates/postgresql.crt').toString(),
|
|
53
53
|
}
|
|
54
54
|
*/
|
|
55
|
-
});
|
|
55
|
+
} as PoolConfig);
|
|
56
56
|
|
|
57
|
-
const re = new RegExp('//(.*)@').exec(connectionStringURI);
|
|
58
|
-
const usernamepassword = re[1];
|
|
59
|
-
const sep = usernamepassword.split(':');
|
|
60
|
-
const usernamepasswordReplacement = usernamepassword.replace(sep[1], '*****************************');
|
|
61
|
-
const safeConnectionStringURI = connectionStringURI.replace(usernamepassword, usernamepasswordReplacement);
|
|
57
|
+
const re: RegExpExecArray = new RegExp('//(.*)@').exec(connectionStringURI);
|
|
58
|
+
const usernamepassword: string = re[1];
|
|
59
|
+
const sep: string[] = usernamepassword.split(':');
|
|
60
|
+
const usernamepasswordReplacement: string = usernamepassword.replace(sep[1], '*****************************');
|
|
61
|
+
const safeConnectionStringURI: string = connectionStringURI.replace(usernamepassword, usernamepasswordReplacement);
|
|
62
62
|
|
|
63
|
-
if (cluster.
|
|
63
|
+
if (cluster.isPrimary) {
|
|
64
64
|
debug(`Created Database Pool with Master Thread, PID: [${process.pid}]`.yellow);
|
|
65
65
|
} else {
|
|
66
66
|
debug(`Created Database Pool with Worker Thread, PID: [${process.pid}]`.yellow);
|
|
@@ -72,7 +72,7 @@ export class PGPoolManager
|
|
|
72
72
|
|
|
73
73
|
// the pool will emit an error on behalf of any idle clients
|
|
74
74
|
// it contains if a backend error or network partition happens
|
|
75
|
-
this._pool.on('error', (error) => {
|
|
75
|
+
this._pool.on('error', (error: Error) => {
|
|
76
76
|
console.error(`Unexpected error on idle client: [${error}]`.red);
|
|
77
77
|
process.exit(-1)
|
|
78
78
|
});
|
|
@@ -95,7 +95,7 @@ export class PGPoolManager
|
|
|
95
95
|
this.AttachInstruments();
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
get pool()
|
|
98
|
+
get pool(): Pool
|
|
99
99
|
{
|
|
100
100
|
return this._pool;
|
|
101
101
|
}
|
package/types/pgpoolmanager.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import 'colors';
|
|
2
|
+
import { Pool } from 'pg';
|
|
2
3
|
export interface PGPoolManagerOptions {
|
|
3
4
|
usedefaultdb: boolean;
|
|
4
5
|
}
|
|
@@ -7,7 +8,7 @@ export declare class PGPoolManager {
|
|
|
7
8
|
private _observer;
|
|
8
9
|
private _pool;
|
|
9
10
|
constructor(options?: PGPoolManagerOptions);
|
|
10
|
-
get pool():
|
|
11
|
+
get pool(): Pool;
|
|
11
12
|
UpdateInstruments(): void;
|
|
12
13
|
AttachInstruments(interval?: number): void;
|
|
13
14
|
DetachInstruments(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgpoolmanager.d.ts","sourceRoot":"","sources":["../pgpoolmanager.ts"],"names":[],"mappings":"AASA,OAAO,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"pgpoolmanager.d.ts","sourceRoot":"","sources":["../pgpoolmanager.ts"],"names":[],"mappings":"AASA,OAAO,QAAQ,CAAA;AAOf,OAAO,EAAE,IAAI,EAAc,MAAM,IAAI,CAAA;AAErC,MAAM,WAAW,oBAAoB;IACpC,YAAY,EAAE,OAAO,CAAA;CACrB;AAED,qBAAa,aAAa;IAEzB,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,KAAK,CAAc;gBAEf,OAAO,CAAC,EAAE,oBAAoB;IAqE1C,IAAI,IAAI,IAAI,IAAI,CAGf;IASD,iBAAiB;IAiBjB,iBAAiB,CAAC,QAAQ,SAAO;IAwBjC,iBAAiB;CAMjB"}
|
package/types/pgutils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare class PGUtils {
|
|
2
2
|
static CheckDatabase(): Promise<void>;
|
|
3
|
-
static createdatabase(): Promise<any
|
|
4
|
-
static dropdatabase(): Promise<any
|
|
3
|
+
static createdatabase(): Promise<import("pg").QueryResult<any>>;
|
|
4
|
+
static dropdatabase(): Promise<import("pg").QueryResult<any>>;
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=pgutils.d.ts.map
|