@nsshunt/stsdatamanagement 1.17.18 → 1.17.19

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 CHANGED
@@ -19,10 +19,8 @@
19
19
  ],
20
20
  "ignorePatterns": ["temp.js", "**/k6scripts/*.js", "**/public/*", "**/dist/*", "**/types/*"],
21
21
  "rules": {
22
- "indent": ["error", "tab"],
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@v2
17
- - uses: actions/setup-node@v2
16
+ - uses: actions/checkout@v3
17
+ - uses: actions/setup-node@v3
18
18
  with:
19
- node-version: 18
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@v2
29
- - uses: actions/setup-node@v2
28
+ - uses: actions/checkout@v3
29
+ - uses: actions/setup-node@v3
30
30
  with:
31
- node-version: 18
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
- const { parentPort, workerData } = require('worker_threads');
4
- const crypto = require('crypto');
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
- 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();
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
- 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
- {
62
- //oid: i
63
- resname: id
64
- ,resdesc: randcardstring
65
- ,vnum: 1
66
- ,validfrom: datanow
67
- ,validto: null
68
- ,dbaction: 1
69
- ,dbactionuser: userid
70
- };
71
-
72
- fakerdataarray.push(fakerdata);
73
- const fakerdata2 = Object.assign({}, fakerdata);
74
- fakerdata2.resname = cpid;
75
- fakerdataarray2.push(fakerdata2);
76
-
77
- parentPort.postMessage( { command: '', data: { totalDataSize: totalDataSize, avgDataSize: avgDataSize } } );
78
-
79
- if ((i+1) % copybatchsize === 0)
80
- {
81
- await accesslayer.bulkInsert(fakerdataarray);
82
- await accesslayer.bulkInsert(fakerdataarray2);
83
- fakerdataarray = [ ];
84
- fakerdataarray2 = [ ];
85
- }
86
- }
87
-
88
- if (fakerdataarray.length > 0)
89
- {
90
- await accesslayer.bulkInsert(fakerdataarray);
91
- await accesslayer.bulkInsert(fakerdataarray2);
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
- private _accessLayer = null;
21
-
22
- constructor(accessLayer?: any)
23
- {
24
- this._accessLayer = accessLayer;
25
- }
26
-
27
- // options ::= { start: <int>, entries: <int>, minextradata: <int>, maxextradata: <int>,
28
- // user: { name: <string>, password: <string>, email: <string> } }
29
- CreateDatabase = async (options: ICreateDatabaseOptions) =>
30
- {
31
- const fname = 'CreateDatabase';
32
- const { start, iterations, minextradata, maxextradata, workerScriptFolder, useMultiBar } = options;
33
- const builddbscript = `${options.databaseScriptFolder}/builddb.sql`;
34
- debug(`Database Build Script: [${builddbscript}]`.yellow);
35
-
36
- let localAccesslayer = null;
37
- try
38
- {
39
- try
40
- {
41
- debug(`Dropping database.`.yellow);
42
- await PGUtils.dropdatabase();
43
- } catch (error)
44
- {
45
- console.error(`[${fname}]: Could not drop database: ${error}`);
46
- // Do not re-throw. If there is no initial database, this will throw an error, ignore this.
47
- }
48
-
49
- // Create a new empty database
50
- debug(`Creating new empty database.`.yellow);
51
- await PGUtils.createdatabase();
52
-
53
- localAccesslayer = new PGAccessLayer(new PGPoolManager());
54
-
55
- // Build the database assets (tables, functions, etc.)
56
- debug(`Building database assets (tables, functions, etc.).`.yellow);
57
- await localAccesslayer.executedbscript(builddbscript);
58
-
59
- //@@ make optional or move
60
- if (typeof iterations !== 'undefined') {
61
- // Add new faker entries
62
- debug(`Adding test data.`.yellow);
63
- const dg = new DataGenerator(localAccesslayer, workerScriptFolder);
64
- await dg.RunAddFakerBulkInsert(options);
65
- }
66
-
67
- //@@ double logging
68
- debug(`Database successfully initiailized.`.green);
69
- console.log(`Database successfully initiailized.`.green);
70
- } catch (error)
71
- {
72
- console.error(`[${fname}]: Could not create fresh database: ${error}`);
73
- debug(`[${fname}]: Could not create fresh database: ${error}`);
74
- } finally {
75
- if (localAccesslayer !== null) {
76
- await localAccesslayer.enddatabase();
77
- }
78
- }
79
-
80
- };
81
-
82
- ResourceCount = async () =>
83
- {
84
- const retVal = await this._accessLayer.getResourceCount();
85
- return retVal;
86
- };
87
-
88
- ExecuteDatabaseScript = async (scriptfile) =>
89
- {
90
- const retVal = await this._accessLayer.executedbscript(scriptfile);
91
- return retVal;
92
- };
93
-
94
- ExecutedCustomScript = async () =>
95
- {
96
- const response = await prompts({
97
- type: 'text',
98
- name: 'script',
99
- message: 'Script name to execute (stsrest01.sql)',
100
- initial: './db-scripts/stsrest01.sql'
101
- });
102
- return this.ExecuteDatabaseScript(response.script);
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
  }