@nsshunt/stsdatamanagement 1.17.18 → 1.17.20
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/.eslintrc.json +1 -3
- package/.github/workflows/npm-publish.yml +6 -6
- package/cliworker.ts +70 -71
- package/databaseutils.ts +84 -87
- package/datagenerator.ts +248 -252
- package/dbaccess.test.ts +6 -6
- package/dbbuild.test.ts +23 -25
- package/dberrors.ts +56 -55
- package/dist/cliworker.js +13 -10
- package/dist/cliworker.js.map +1 -1
- package/dist/databaseutils.js +1 -4
- package/dist/databaseutils.js.map +1 -1
- package/dist/datagenerator.js +15 -17
- package/dist/datagenerator.js.map +1 -1
- package/dist/dbaccess.test.js.map +1 -1
- package/dist/dbbuild.test.js.map +1 -1
- package/dist/dberrors.js +1 -0
- package/dist/dberrors.js.map +1 -1
- package/dist/jest.config.js.map +1 -1
- package/dist/pgaccesslayer.js +36 -8
- package/dist/pgaccesslayer.js.map +1 -1
- package/dist/pgpoolmanager.js.map +1 -1
- package/dist/pgutils.js.map +1 -1
- package/dist/setupdb.js.map +1 -1
- package/jest.config.js +136 -136
- package/package.json +21 -19
- package/pgaccesslayer.ts +888 -874
- package/pgpoolmanager.ts +106 -106
- package/pgutils.ts +61 -61
- package/setupdb.ts +1 -1
- package/types/databaseutils.d.ts +13 -4
- package/types/databaseutils.d.ts.map +1 -1
- package/types/datagenerator.d.ts.map +1 -1
- package/types/dberrors.d.ts.map +1 -1
- package/types/pgaccesslayer.d.ts +9 -4
- package/types/pgaccesslayer.d.ts.map +1 -1
- package/types/pgpoolmanager.d.ts.map +1 -1
- package/types/pgutils.d.ts.map +1 -1
package/.eslintrc.json
CHANGED
|
@@ -19,10 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"ignorePatterns": ["temp.js", "**/k6scripts/*.js", "**/public/*", "**/dist/*", "**/types/*"],
|
|
21
21
|
"rules": {
|
|
22
|
-
"indent": ["error",
|
|
23
|
-
//"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
|
|
22
|
+
"indent": ["error", 4],
|
|
24
23
|
"no-mixed-spaces-and-tabs": [2],
|
|
25
|
-
//"no-mixed-spaces-and-tabs": 0, // disable rule
|
|
26
24
|
"@typescript-eslint/no-var-requires": "warn"
|
|
27
25
|
}
|
|
28
26
|
}
|
|
@@ -13,10 +13,10 @@ jobs:
|
|
|
13
13
|
build:
|
|
14
14
|
runs-on: ubuntu-latest
|
|
15
15
|
steps:
|
|
16
|
-
- uses: actions/checkout@
|
|
17
|
-
- uses: actions/setup-node@
|
|
16
|
+
- uses: actions/checkout@v3
|
|
17
|
+
- uses: actions/setup-node@v3
|
|
18
18
|
with:
|
|
19
|
-
node-version:
|
|
19
|
+
node-version: 19
|
|
20
20
|
- run: npm ci
|
|
21
21
|
- run: npm run lint
|
|
22
22
|
- run: npm test
|
|
@@ -25,10 +25,10 @@ jobs:
|
|
|
25
25
|
needs: build
|
|
26
26
|
runs-on: ubuntu-latest
|
|
27
27
|
steps:
|
|
28
|
-
- uses: actions/checkout@
|
|
29
|
-
- uses: actions/setup-node@
|
|
28
|
+
- uses: actions/checkout@v3
|
|
29
|
+
- uses: actions/setup-node@v3
|
|
30
30
|
with:
|
|
31
|
-
node-version:
|
|
31
|
+
node-version: 19
|
|
32
32
|
registry-url: https://registry.npmjs.org/
|
|
33
33
|
- run: npm ci
|
|
34
34
|
- run: npm run build
|
package/cliworker.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// https://stackoverflow.com/questions/56356655/structuring-a-typescript-project-with-workers
|
|
2
2
|
//let faker = require('faker');
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { parentPort, workerData } from 'worker_threads';
|
|
4
|
+
import crypto from 'crypto';
|
|
5
5
|
|
|
6
6
|
import { PGPoolManager } from './pgpoolmanager'
|
|
7
7
|
import { PGAccessLayer } from './pgaccesslayer'
|
|
@@ -22,74 +22,73 @@ const copybatchsize = 250;
|
|
|
22
22
|
|
|
23
23
|
(async () =>
|
|
24
24
|
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
const accesslayer = new PGAccessLayer(new PGPoolManager());
|
|
26
|
+
|
|
27
|
+
if (datamax > 0)
|
|
28
|
+
{
|
|
29
|
+
datamax = (datamax <= datamin) ? datamin + 1 : datamax;
|
|
30
|
+
}
|
|
31
|
+
for (let i=0; i < iterations; i++)
|
|
32
|
+
{
|
|
33
|
+
//let randcard = faker.helpers.createCard();
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
parentPort.postMessage( { command: 'done', data: null } );
|
|
35
|
+
const coreRecordSizeRange = crypto.randomInt(128, 192);
|
|
36
|
+
const coreRecordSize = Math.floor(coreRecordSizeRange / 2);
|
|
37
|
+
let randcard = crypto.randomBytes(coreRecordSize).toString('hex');
|
|
38
|
+
|
|
39
|
+
if (datamax > 0)
|
|
40
|
+
{
|
|
41
|
+
const n = crypto.randomInt(datamin, datamax);
|
|
42
|
+
const n2 = Math.floor(n / 2);
|
|
43
|
+
const rndid = crypto.randomBytes(n2).toString('hex');
|
|
44
|
+
randcard += rndid;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const randcardstring = randcard;
|
|
48
|
+
//const randcardstring = JSON.stringify(randcard);
|
|
49
|
+
|
|
50
|
+
totalDataSize += randcardstring.length;
|
|
51
|
+
avgDataSize = Math.floor(totalDataSize / (i+1));
|
|
52
|
+
|
|
53
|
+
const pn = ('' + count++).padStart(10, '0');
|
|
54
|
+
const id = resfakerprefix + pn;
|
|
55
|
+
const cpid = rescopyprefix + pn;
|
|
56
|
+
|
|
57
|
+
const datanow = new Date().toISOString();
|
|
58
|
+
//let datanow = new Date().toUTCString();
|
|
59
|
+
|
|
60
|
+
const fakerdata = {
|
|
61
|
+
//oid: i
|
|
62
|
+
resname: id
|
|
63
|
+
,resdesc: randcardstring
|
|
64
|
+
,vnum: 1
|
|
65
|
+
,validfrom: datanow
|
|
66
|
+
,validto: null
|
|
67
|
+
,dbaction: 1
|
|
68
|
+
,dbactionuser: userid
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
fakerdataarray.push(fakerdata);
|
|
72
|
+
const fakerdata2 = Object.assign({}, fakerdata);
|
|
73
|
+
fakerdata2.resname = cpid;
|
|
74
|
+
fakerdataarray2.push(fakerdata2);
|
|
75
|
+
|
|
76
|
+
parentPort.postMessage( { command: '', data: { totalDataSize: totalDataSize, avgDataSize: avgDataSize } } );
|
|
77
|
+
|
|
78
|
+
if ((i+1) % copybatchsize === 0)
|
|
79
|
+
{
|
|
80
|
+
await accesslayer.bulkInsert(fakerdataarray);
|
|
81
|
+
await accesslayer.bulkInsert(fakerdataarray2);
|
|
82
|
+
fakerdataarray = [ ];
|
|
83
|
+
fakerdataarray2 = [ ];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (fakerdataarray.length > 0)
|
|
88
|
+
{
|
|
89
|
+
await accesslayer.bulkInsert(fakerdataarray);
|
|
90
|
+
await accesslayer.bulkInsert(fakerdataarray2);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
parentPort.postMessage( { command: 'done', data: null } );
|
|
95
94
|
})();
|
package/databaseutils.ts
CHANGED
|
@@ -2,9 +2,6 @@ import prompts from 'prompts'
|
|
|
2
2
|
|
|
3
3
|
import 'colors'
|
|
4
4
|
|
|
5
|
-
import { $Options } from '@nsshunt/stsconfig'
|
|
6
|
-
const goptions = $Options()
|
|
7
|
-
|
|
8
5
|
import { PGPoolManager } from './pgpoolmanager'
|
|
9
6
|
import { PGAccessLayer } from './pgaccesslayer'
|
|
10
7
|
import { PGUtils } from './pgutils'
|
|
@@ -17,88 +14,88 @@ import { ICreateDatabaseOptions } from './stsDataManagementTypes'
|
|
|
17
14
|
|
|
18
15
|
export class DatabaseUtils
|
|
19
16
|
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
17
|
+
private _accessLayer: PGAccessLayer;
|
|
18
|
+
|
|
19
|
+
constructor(accessLayer?: PGAccessLayer)
|
|
20
|
+
{
|
|
21
|
+
this._accessLayer = accessLayer;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// options ::= { start: <int>, entries: <int>, minextradata: <int>, maxextradata: <int>,
|
|
25
|
+
// user: { name: <string>, password: <string>, email: <string> } }
|
|
26
|
+
CreateDatabase = async (options: ICreateDatabaseOptions) =>
|
|
27
|
+
{
|
|
28
|
+
const fname = 'CreateDatabase';
|
|
29
|
+
const { iterations, workerScriptFolder } = options;
|
|
30
|
+
const builddbscript = `${options.databaseScriptFolder}/builddb.sql`;
|
|
31
|
+
debug(`Database Build Script: [${builddbscript}]`.yellow);
|
|
32
|
+
|
|
33
|
+
let localAccesslayer = null;
|
|
34
|
+
try
|
|
35
|
+
{
|
|
36
|
+
try
|
|
37
|
+
{
|
|
38
|
+
debug(`Dropping database.`.yellow);
|
|
39
|
+
await PGUtils.dropdatabase();
|
|
40
|
+
} catch (error)
|
|
41
|
+
{
|
|
42
|
+
console.error(`[${fname}]: Could not drop database: ${error}`);
|
|
43
|
+
// Do not re-throw. If there is no initial database, this will throw an error, ignore this.
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Create a new empty database
|
|
47
|
+
debug(`Creating new empty database.`.yellow);
|
|
48
|
+
await PGUtils.createdatabase();
|
|
49
|
+
|
|
50
|
+
localAccesslayer = new PGAccessLayer(new PGPoolManager());
|
|
51
|
+
|
|
52
|
+
// Build the database assets (tables, functions, etc.)
|
|
53
|
+
debug(`Building database assets (tables, functions, etc.).`.yellow);
|
|
54
|
+
await localAccesslayer.executedbscript(builddbscript);
|
|
55
|
+
|
|
56
|
+
//@@ make optional or move
|
|
57
|
+
if (typeof iterations !== 'undefined') {
|
|
58
|
+
// Add new faker entries
|
|
59
|
+
debug(`Adding test data.`.yellow);
|
|
60
|
+
const dg = new DataGenerator(localAccesslayer, workerScriptFolder);
|
|
61
|
+
await dg.RunAddFakerBulkInsert(options);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//@@ double logging
|
|
65
|
+
debug(`Database successfully initiailized.`.green);
|
|
66
|
+
console.log(`Database successfully initiailized.`.green);
|
|
67
|
+
} catch (error)
|
|
68
|
+
{
|
|
69
|
+
console.error(`[${fname}]: Could not create fresh database: ${error}`);
|
|
70
|
+
debug(`[${fname}]: Could not create fresh database: ${error}`);
|
|
71
|
+
} finally {
|
|
72
|
+
if (localAccesslayer !== null) {
|
|
73
|
+
await localAccesslayer.enddatabase();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
ResourceCount = async () =>
|
|
80
|
+
{
|
|
81
|
+
const retVal = await this._accessLayer.getResourceCount();
|
|
82
|
+
return retVal;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
ExecuteDatabaseScript = async (scriptfile) =>
|
|
86
|
+
{
|
|
87
|
+
const retVal = await this._accessLayer.executedbscript(scriptfile);
|
|
88
|
+
return retVal;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
ExecutedCustomScript = async () =>
|
|
92
|
+
{
|
|
93
|
+
const response = await prompts({
|
|
94
|
+
type: 'text',
|
|
95
|
+
name: 'script',
|
|
96
|
+
message: 'Script name to execute (stsrest01.sql)',
|
|
97
|
+
initial: './db-scripts/stsrest01.sql'
|
|
98
|
+
});
|
|
99
|
+
return this.ExecuteDatabaseScript(response.script);
|
|
100
|
+
};
|
|
104
101
|
}
|