@nsshunt/stsdatamanagement 1.16.6 → 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/build.sh +29 -0
- package/dist/pgpoolmanager.js +43 -26
- package/dist/pgpoolmanager.js.map +1 -1
- package/package.json +2 -1
- package/pgpoolmanager.ts +55 -34
- package/types/pgpoolmanager.d.ts +8 -6
- package/types/pgpoolmanager.d.ts.map +1 -1
- package/types/pgutils.d.ts +2 -2
package/build.sh
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
rm -rf dist
|
|
3
|
+
rm -rf types
|
|
4
|
+
npm run build
|
|
5
|
+
RESULT=$?
|
|
6
|
+
if [ $RESULT -eq 0 ]; then
|
|
7
|
+
echo success build
|
|
8
|
+
npm run lint
|
|
9
|
+
RESULT=$?
|
|
10
|
+
if [ $RESULT -eq 0 ]; then
|
|
11
|
+
echo success lint
|
|
12
|
+
npm run test
|
|
13
|
+
RESULT=$?
|
|
14
|
+
if [ $RESULT -eq 0 ]; then
|
|
15
|
+
echo success test
|
|
16
|
+
git commit -a -m "changed"
|
|
17
|
+
npm version patch
|
|
18
|
+
npm i
|
|
19
|
+
git commit -a -m "changed"
|
|
20
|
+
git push
|
|
21
|
+
else
|
|
22
|
+
echo failed test
|
|
23
|
+
fi
|
|
24
|
+
else
|
|
25
|
+
echo failed lint
|
|
26
|
+
fi
|
|
27
|
+
else
|
|
28
|
+
echo failed build
|
|
29
|
+
fi
|
package/dist/pgpoolmanager.js
CHANGED
|
@@ -6,28 +6,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.PGPoolManager = void 0;
|
|
7
7
|
const stsconfig_1 = require("@nsshunt/stsconfig");
|
|
8
8
|
const { databaseUrl, connectionString, defaultDatabaseConnectionString, isProduction, poolSize } = (0, stsconfig_1.$Options)();
|
|
9
|
-
const
|
|
9
|
+
const stsutils_1 = require("@nsshunt/stsutils");
|
|
10
|
+
const stsinstrumentation_1 = require("@nsshunt/stsinstrumentation");
|
|
10
11
|
const debug_1 = __importDefault(require("debug"));
|
|
11
12
|
const debug = (0, debug_1.default)(`proc:${process.pid}`);
|
|
12
13
|
require("colors");
|
|
13
|
-
const
|
|
14
|
+
const cluster_1 = __importDefault(require("cluster"));
|
|
14
15
|
//const pg = require('pg');
|
|
15
16
|
//pg.types.setTypeParser(20, BigInt); // Type Id 20 = BIGINT | BIGSERIAL
|
|
16
17
|
// https://stackoverflow.com/questions/39168501/pg-promise-returns-integers-as-strings
|
|
17
|
-
const
|
|
18
|
+
const pg_1 = require("pg");
|
|
18
19
|
class PGPoolManager {
|
|
19
|
-
constructor(options
|
|
20
|
+
constructor(options) {
|
|
20
21
|
this._options = null;
|
|
21
22
|
this._observer = null;
|
|
22
|
-
this._instruments = null;
|
|
23
23
|
this._pool = null;
|
|
24
|
-
if (options
|
|
25
|
-
options = {
|
|
24
|
+
if (!options) {
|
|
25
|
+
options = {
|
|
26
|
+
usedefaultdb: false
|
|
27
|
+
};
|
|
26
28
|
}
|
|
27
29
|
this._options = options;
|
|
28
30
|
const connectionStringURI = isProduction ? databaseUrl : (options.usedefaultdb === true ? defaultDatabaseConnectionString : connectionString);
|
|
29
31
|
// https://mylifedigital.co.uk/securing-node-postgres-with-ssl/
|
|
30
|
-
this._pool = new Pool({
|
|
32
|
+
this._pool = new pg_1.Pool({
|
|
31
33
|
connectionString: connectionStringURI,
|
|
32
34
|
ssl: isProduction,
|
|
33
35
|
max: poolSize // Default is 10 - This will be the number in a pool per thread (worker)
|
|
@@ -48,7 +50,7 @@ class PGPoolManager {
|
|
|
48
50
|
const sep = usernamepassword.split(':');
|
|
49
51
|
const usernamepasswordReplacement = usernamepassword.replace(sep[1], '*****************************');
|
|
50
52
|
const safeConnectionStringURI = connectionStringURI.replace(usernamepassword, usernamepasswordReplacement);
|
|
51
|
-
if (
|
|
53
|
+
if (cluster_1.default.isPrimary) {
|
|
52
54
|
debug(`Created Database Pool with Master Thread, PID: [${process.pid}]`.yellow);
|
|
53
55
|
}
|
|
54
56
|
else {
|
|
@@ -65,45 +67,60 @@ class PGPoolManager {
|
|
|
65
67
|
process.exit(-1);
|
|
66
68
|
});
|
|
67
69
|
this._pool.on('connect', () => {
|
|
68
|
-
this.UpdateInstruments(
|
|
70
|
+
this.UpdateInstruments();
|
|
69
71
|
});
|
|
70
72
|
this._pool.on('acquire', () => {
|
|
71
|
-
this.UpdateInstruments(
|
|
73
|
+
this.UpdateInstruments();
|
|
72
74
|
});
|
|
73
75
|
this._pool.on('remove', () => {
|
|
74
|
-
this.UpdateInstruments(
|
|
76
|
+
this.UpdateInstruments();
|
|
75
77
|
});
|
|
76
|
-
this.AttachInstruments(
|
|
78
|
+
this.AttachInstruments();
|
|
77
79
|
}
|
|
78
80
|
get pool() {
|
|
79
81
|
return this._pool;
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
/*
|
|
84
|
+
get instruments()
|
|
85
|
+
{
|
|
82
86
|
return this._instruments;
|
|
83
87
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
*/
|
|
89
|
+
UpdateInstruments() {
|
|
90
|
+
if (stsutils_1.$stsgd.app) {
|
|
91
|
+
stsutils_1.$stsgd.app.UpdateInstrument(stsinstrumentation_1.Gauge.CONNECTION_POOL_TOTAL_GAUGE, {
|
|
92
|
+
val: this.pool.totalCount
|
|
93
|
+
});
|
|
94
|
+
stsutils_1.$stsgd.app.UpdateInstrument(stsinstrumentation_1.Gauge.CONNECTION_POOL_IDLE_GAUGE, {
|
|
95
|
+
val: this.pool.idleCount
|
|
96
|
+
});
|
|
97
|
+
stsutils_1.$stsgd.app.UpdateInstrument(stsinstrumentation_1.Gauge.CONNECTION_POOL_WAITING_GAUGE, {
|
|
98
|
+
val: this.pool.waitingCount
|
|
99
|
+
});
|
|
92
100
|
}
|
|
93
101
|
}
|
|
94
|
-
AttachInstruments(
|
|
102
|
+
AttachInstruments(interval = 1000) {
|
|
103
|
+
if (stsutils_1.$stsgd.app) {
|
|
104
|
+
this._observer = setInterval(() => {
|
|
105
|
+
this.UpdateInstruments();
|
|
106
|
+
}, interval).unref();
|
|
107
|
+
}
|
|
108
|
+
/*
|
|
95
109
|
this._instruments = instruments;
|
|
96
110
|
if (instruments !== null &&
|
|
97
111
|
typeof instruments[Gauge.CONNECTION_POOL_TOTAL_GAUGE] !== 'undefined' &&
|
|
98
112
|
typeof instruments[Gauge.CONNECTION_POOL_IDLE_GAUGE] !== 'undefined' &&
|
|
99
|
-
typeof instruments[Gauge.CONNECTION_POOL_WAITING_GAUGE] !== 'undefined')
|
|
100
|
-
|
|
113
|
+
typeof instruments[Gauge.CONNECTION_POOL_WAITING_GAUGE] !== 'undefined')
|
|
114
|
+
{
|
|
115
|
+
this._observer = setInterval(() =>
|
|
116
|
+
{
|
|
101
117
|
this.UpdateInstruments(this);
|
|
102
118
|
}, interval).unref();
|
|
103
119
|
}
|
|
120
|
+
*/
|
|
104
121
|
}
|
|
105
122
|
DetachInstruments() {
|
|
106
|
-
this._instruments = null;
|
|
123
|
+
//this._instruments = null;
|
|
107
124
|
clearInterval(this._observer);
|
|
108
125
|
this._observer = null;
|
|
109
126
|
}
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"pgpoolmanager.js","sourceRoot":"","sources":["../pgpoolmanager.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAC7C,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,+B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ules, 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
|
@@ -1,35 +1,41 @@
|
|
|
1
1
|
import { $Options } from '@nsshunt/stsconfig'
|
|
2
2
|
const { databaseUrl, connectionString, defaultDatabaseConnectionString, isProduction, poolSize } = $Options()
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import { $stsgd } from '@nsshunt/stsutils'
|
|
5
|
+
import { Gauge, InstrumentGaugeTelemetry } from '@nsshunt/stsinstrumentation'
|
|
5
6
|
|
|
6
7
|
import Debug from "debug";
|
|
7
8
|
const debug = Debug(`proc:${process.pid}`);
|
|
8
9
|
|
|
9
10
|
import 'colors'
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
import cluster from 'cluster'
|
|
12
13
|
|
|
13
14
|
//const pg = require('pg');
|
|
14
15
|
//pg.types.setTypeParser(20, BigInt); // Type Id 20 = BIGINT | BIGSERIAL
|
|
15
16
|
// https://stackoverflow.com/questions/39168501/pg-promise-returns-integers-as-strings
|
|
16
|
-
|
|
17
|
+
import { Pool, PoolConfig } from 'pg'
|
|
18
|
+
|
|
19
|
+
export interface PGPoolManagerOptions {
|
|
20
|
+
usedefaultdb: boolean
|
|
21
|
+
}
|
|
17
22
|
|
|
18
23
|
export class PGPoolManager
|
|
19
24
|
{
|
|
20
|
-
private _options = null;
|
|
25
|
+
private _options: PGPoolManagerOptions = null;
|
|
21
26
|
private _observer: NodeJS.Timer = null;
|
|
22
|
-
private
|
|
23
|
-
private _pool = null;
|
|
27
|
+
private _pool: Pool = null;
|
|
24
28
|
|
|
25
|
-
constructor(options
|
|
29
|
+
constructor(options?: PGPoolManagerOptions)
|
|
26
30
|
{
|
|
27
|
-
if (options
|
|
28
|
-
options = {
|
|
31
|
+
if (!options) {
|
|
32
|
+
options = {
|
|
33
|
+
usedefaultdb: false
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
this._options = options;
|
|
31
37
|
|
|
32
|
-
const connectionStringURI = isProduction ? databaseUrl : (options.usedefaultdb === true ? defaultDatabaseConnectionString : connectionString );
|
|
38
|
+
const connectionStringURI: string = isProduction ? databaseUrl : (options.usedefaultdb === true ? defaultDatabaseConnectionString : connectionString );
|
|
33
39
|
// https://mylifedigital.co.uk/securing-node-postgres-with-ssl/
|
|
34
40
|
this._pool = new Pool({
|
|
35
41
|
connectionString: connectionStringURI,
|
|
@@ -46,15 +52,15 @@ export class PGPoolManager
|
|
|
46
52
|
//cert: fs.readFileSync('/path/to/client-certificates/postgresql.crt').toString(),
|
|
47
53
|
}
|
|
48
54
|
*/
|
|
49
|
-
});
|
|
55
|
+
} as PoolConfig);
|
|
50
56
|
|
|
51
|
-
const re = new RegExp('//(.*)@').exec(connectionStringURI);
|
|
52
|
-
const usernamepassword = re[1];
|
|
53
|
-
const sep = usernamepassword.split(':');
|
|
54
|
-
const usernamepasswordReplacement = usernamepassword.replace(sep[1], '*****************************');
|
|
55
|
-
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);
|
|
56
62
|
|
|
57
|
-
if (cluster.
|
|
63
|
+
if (cluster.isPrimary) {
|
|
58
64
|
debug(`Created Database Pool with Master Thread, PID: [${process.pid}]`.yellow);
|
|
59
65
|
} else {
|
|
60
66
|
debug(`Created Database Pool with Worker Thread, PID: [${process.pid}]`.yellow);
|
|
@@ -66,54 +72,68 @@ export class PGPoolManager
|
|
|
66
72
|
|
|
67
73
|
// the pool will emit an error on behalf of any idle clients
|
|
68
74
|
// it contains if a backend error or network partition happens
|
|
69
|
-
this._pool.on('error', (error) => {
|
|
75
|
+
this._pool.on('error', (error: Error) => {
|
|
70
76
|
console.error(`Unexpected error on idle client: [${error}]`.red);
|
|
71
77
|
process.exit(-1)
|
|
72
78
|
});
|
|
73
79
|
|
|
74
80
|
this._pool.on('connect', () =>
|
|
75
81
|
{
|
|
76
|
-
this.UpdateInstruments(
|
|
82
|
+
this.UpdateInstruments();
|
|
77
83
|
});
|
|
78
84
|
|
|
79
85
|
this._pool.on('acquire', () =>
|
|
80
86
|
{
|
|
81
|
-
this.UpdateInstruments(
|
|
87
|
+
this.UpdateInstruments();
|
|
82
88
|
});
|
|
83
89
|
|
|
84
90
|
this._pool.on('remove', () =>
|
|
85
91
|
{
|
|
86
|
-
this.UpdateInstruments(
|
|
92
|
+
this.UpdateInstruments();
|
|
87
93
|
});
|
|
88
94
|
|
|
89
|
-
this.AttachInstruments(
|
|
95
|
+
this.AttachInstruments();
|
|
90
96
|
}
|
|
91
97
|
|
|
92
|
-
get pool()
|
|
98
|
+
get pool(): Pool
|
|
93
99
|
{
|
|
94
100
|
return this._pool;
|
|
95
101
|
}
|
|
96
102
|
|
|
103
|
+
/*
|
|
97
104
|
get instruments()
|
|
98
105
|
{
|
|
99
106
|
return this._instruments;
|
|
100
107
|
}
|
|
108
|
+
*/
|
|
101
109
|
|
|
102
|
-
UpdateInstruments(
|
|
110
|
+
UpdateInstruments()
|
|
103
111
|
{
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
if ($stsgd.app) {
|
|
113
|
+
$stsgd.app.UpdateInstrument(Gauge.CONNECTION_POOL_TOTAL_GAUGE, {
|
|
114
|
+
val: this.pool.totalCount
|
|
115
|
+
} as InstrumentGaugeTelemetry);
|
|
116
|
+
|
|
117
|
+
$stsgd.app.UpdateInstrument(Gauge.CONNECTION_POOL_IDLE_GAUGE, {
|
|
118
|
+
val: this.pool.idleCount
|
|
119
|
+
} as InstrumentGaugeTelemetry);
|
|
120
|
+
|
|
121
|
+
$stsgd.app.UpdateInstrument(Gauge.CONNECTION_POOL_WAITING_GAUGE, {
|
|
122
|
+
val: this.pool.waitingCount
|
|
123
|
+
} as InstrumentGaugeTelemetry);
|
|
112
124
|
}
|
|
113
125
|
}
|
|
114
126
|
|
|
115
|
-
AttachInstruments(
|
|
127
|
+
AttachInstruments(interval = 1000)
|
|
116
128
|
{
|
|
129
|
+
if ($stsgd.app) {
|
|
130
|
+
this._observer = setInterval(() =>
|
|
131
|
+
{
|
|
132
|
+
this.UpdateInstruments();
|
|
133
|
+
}, interval).unref();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/*
|
|
117
137
|
this._instruments = instruments;
|
|
118
138
|
if (instruments !== null &&
|
|
119
139
|
typeof instruments[Gauge.CONNECTION_POOL_TOTAL_GAUGE] !== 'undefined' &&
|
|
@@ -125,11 +145,12 @@ export class PGPoolManager
|
|
|
125
145
|
this.UpdateInstruments(this);
|
|
126
146
|
}, interval).unref();
|
|
127
147
|
}
|
|
148
|
+
*/
|
|
128
149
|
}
|
|
129
150
|
|
|
130
151
|
DetachInstruments()
|
|
131
152
|
{
|
|
132
|
-
this._instruments = null;
|
|
153
|
+
//this._instruments = null;
|
|
133
154
|
clearInterval(this._observer);
|
|
134
155
|
this._observer = null;
|
|
135
156
|
}
|
package/types/pgpoolmanager.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import 'colors';
|
|
2
|
+
import { Pool } from 'pg';
|
|
3
|
+
export interface PGPoolManagerOptions {
|
|
4
|
+
usedefaultdb: boolean;
|
|
5
|
+
}
|
|
2
6
|
export declare class PGPoolManager {
|
|
3
7
|
private _options;
|
|
4
8
|
private _observer;
|
|
5
|
-
private _instruments;
|
|
6
9
|
private _pool;
|
|
7
|
-
constructor(options?:
|
|
8
|
-
get pool():
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
AttachInstruments(instruments: any, interval?: number): void;
|
|
10
|
+
constructor(options?: PGPoolManagerOptions);
|
|
11
|
+
get pool(): Pool;
|
|
12
|
+
UpdateInstruments(): void;
|
|
13
|
+
AttachInstruments(interval?: number): void;
|
|
12
14
|
DetachInstruments(): void;
|
|
13
15
|
}
|
|
14
16
|
//# sourceMappingURL=pgpoolmanager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgpoolmanager.d.ts","sourceRoot":"","sources":["../pgpoolmanager.ts"],"names":[],"mappings":"
|
|
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
|