@nsshunt/stsdatamanagement 1.3.18 → 1.3.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/package.json +5 -5
- package/pgaccesslayer.js +95 -95
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsshunt/stsdatamanagement",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.19",
|
|
4
4
|
"description": "STS Data Management Modules, Utilities and Services",
|
|
5
5
|
"main": "dbaccess.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@nsshunt/stsconfig": "^1.3.
|
|
8
|
-
"@nsshunt/stsutils": "^1.3.
|
|
7
|
+
"@nsshunt/stsconfig": "^1.3.22",
|
|
8
|
+
"@nsshunt/stsutils": "^1.3.26",
|
|
9
9
|
"axios": "^0.24.0",
|
|
10
10
|
"bcryptjs": "^2.4.3",
|
|
11
11
|
"cli-progress": "^3.9.1",
|
|
12
12
|
"colors": "^1.4.0",
|
|
13
13
|
"debug": "^4.3.3",
|
|
14
|
-
"ioredis": "^4.28.
|
|
14
|
+
"ioredis": "^4.28.2",
|
|
15
15
|
"pg": "^8.7.1",
|
|
16
16
|
"pg-copy-streams": "^6.0.2",
|
|
17
17
|
"prompts": "^2.4.2",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
32
32
|
"@babel/plugin-proposal-private-methods": "^7.16.0",
|
|
33
33
|
"eslint": "^8.3.0",
|
|
34
|
-
"jest": "^27.3
|
|
34
|
+
"jest": "^27.4.3"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"lint": "eslint . --ext js,jsx,ts,tsx --fix",
|
package/pgaccesslayer.js
CHANGED
|
@@ -9,29 +9,29 @@ const debug = require('debug')(`proc:${process.pid}`);
|
|
|
9
9
|
|
|
10
10
|
class PGAccessLayer
|
|
11
11
|
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
#cache = null;
|
|
13
|
+
#pgpool = null;
|
|
14
|
+
#logger = null;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
constructor(poolManager)
|
|
17
|
+
{
|
|
18
18
|
this.#pgpool = poolManager.pool;
|
|
19
19
|
if (useRedis === true)
|
|
20
20
|
{
|
|
21
21
|
this.#cache = new Redis(redisPort, redisServer);
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
#latestResourceVersion(inputfilter)
|
|
26
|
+
{
|
|
27
27
|
// Check if we are getting the latest version
|
|
28
28
|
const { resname, entname, vnum, filter, incdel, startdate, enddate, dbaction, dbactionuser } = inputfilter;
|
|
29
29
|
return (resname !== undefined && entname === undefined && vnum === undefined && filter === undefined && incdel === undefined && startdate === undefined
|
|
30
30
|
&& enddate === undefined && dbaction === undefined && dbactionuser === undefined);
|
|
31
|
-
|
|
31
|
+
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
#buildQueryString(filters, restype)
|
|
34
|
+
{
|
|
35
35
|
const { resname, entname, vnum, filter, incdel, startdate, enddate, dbaction, dbactionuser } = filters;
|
|
36
36
|
|
|
37
37
|
// Build query string
|
|
@@ -111,15 +111,15 @@ class PGAccessLayer
|
|
|
111
111
|
} else {
|
|
112
112
|
return { qstring: qstring, qparams: qparams };
|
|
113
113
|
}
|
|
114
|
-
|
|
114
|
+
}
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
async getLatestResource(resid)
|
|
117
|
+
{
|
|
118
118
|
return await this.getResource({ resname: resid });
|
|
119
|
-
|
|
119
|
+
}
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
async saveResource(userid, resid, data)
|
|
122
|
+
{
|
|
123
123
|
let retVal = await this.getLatestResource(resid);
|
|
124
124
|
if (retVal.status !== status.success)
|
|
125
125
|
{
|
|
@@ -128,20 +128,20 @@ class PGAccessLayer
|
|
|
128
128
|
let vnum = retVal.detail.vnum;
|
|
129
129
|
await this.updateResource(userid, resid, vnum, data);
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
}
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
async getDefaultConfig()
|
|
134
|
+
{
|
|
135
135
|
return await this.getLatestResource(defaultConfigId);
|
|
136
|
-
|
|
136
|
+
}
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
async saveDefaultConfig(config)
|
|
139
|
+
{
|
|
140
140
|
await this.saveResource(systemUserId, defaultConfigId, config);
|
|
141
|
-
|
|
141
|
+
}
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
async getResourceCount(filter = null)
|
|
144
|
+
{
|
|
145
145
|
const fname = 'getResourceCount';
|
|
146
146
|
try
|
|
147
147
|
{
|
|
@@ -166,10 +166,10 @@ class PGAccessLayer
|
|
|
166
166
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
167
167
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
168
168
|
}
|
|
169
|
-
|
|
169
|
+
}
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
async createResource(userid, resourceid, payload)
|
|
172
|
+
{
|
|
173
173
|
const fname = 'createResource';
|
|
174
174
|
try
|
|
175
175
|
{
|
|
@@ -206,10 +206,10 @@ class PGAccessLayer
|
|
|
206
206
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
207
207
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
208
208
|
}
|
|
209
|
-
|
|
209
|
+
}
|
|
210
210
|
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
async beginX()
|
|
212
|
+
{
|
|
213
213
|
const fname = 'beginX';
|
|
214
214
|
try
|
|
215
215
|
{
|
|
@@ -222,10 +222,10 @@ class PGAccessLayer
|
|
|
222
222
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
223
223
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
224
224
|
}
|
|
225
|
-
|
|
225
|
+
}
|
|
226
226
|
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
async commitX(client)
|
|
228
|
+
{
|
|
229
229
|
const fname = 'commitX';
|
|
230
230
|
try
|
|
231
231
|
{
|
|
@@ -237,10 +237,10 @@ class PGAccessLayer
|
|
|
237
237
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
238
238
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
239
239
|
}
|
|
240
|
-
|
|
240
|
+
}
|
|
241
241
|
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
async rollbackX(client)
|
|
243
|
+
{
|
|
244
244
|
const fname = 'rollbackX';
|
|
245
245
|
try
|
|
246
246
|
{
|
|
@@ -252,10 +252,10 @@ class PGAccessLayer
|
|
|
252
252
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
253
253
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
254
254
|
}
|
|
255
|
-
|
|
255
|
+
}
|
|
256
256
|
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
async createResourceX(client, userid, resourceid, payload)
|
|
258
|
+
{
|
|
259
259
|
const fname = 'createResourceX';
|
|
260
260
|
const createQuery = `select * from create_stsresource($1, $2, $3)`;
|
|
261
261
|
const values = [
|
|
@@ -277,10 +277,10 @@ class PGAccessLayer
|
|
|
277
277
|
}
|
|
278
278
|
return err;
|
|
279
279
|
}
|
|
280
|
-
|
|
280
|
+
}
|
|
281
281
|
|
|
282
|
-
|
|
283
|
-
|
|
282
|
+
async updateResource(userid, resourceid, resourcevnum, payload)
|
|
283
|
+
{
|
|
284
284
|
const fname = 'updateResource';
|
|
285
285
|
try
|
|
286
286
|
{
|
|
@@ -330,10 +330,10 @@ class PGAccessLayer
|
|
|
330
330
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
331
331
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
332
332
|
}
|
|
333
|
-
|
|
333
|
+
}
|
|
334
334
|
|
|
335
|
-
|
|
336
|
-
|
|
335
|
+
async deleteResource(userid, resourceid, resourcevnum)
|
|
336
|
+
{
|
|
337
337
|
const fname = 'deleteResource';
|
|
338
338
|
try
|
|
339
339
|
{
|
|
@@ -378,10 +378,10 @@ class PGAccessLayer
|
|
|
378
378
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
379
379
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
380
380
|
}
|
|
381
|
-
|
|
381
|
+
}
|
|
382
382
|
|
|
383
|
-
|
|
384
|
-
|
|
383
|
+
async createEntity(userid, resourceid, resourcevnum, entityid, payload)
|
|
384
|
+
{
|
|
385
385
|
const fname = 'createEntity';
|
|
386
386
|
try
|
|
387
387
|
{
|
|
@@ -417,10 +417,10 @@ class PGAccessLayer
|
|
|
417
417
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
418
418
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
419
419
|
}
|
|
420
|
-
|
|
420
|
+
}
|
|
421
421
|
|
|
422
|
-
|
|
423
|
-
|
|
422
|
+
async updateEntity(userid, resourceid, resourcevnum, entityid, entityvnum, payload)
|
|
423
|
+
{
|
|
424
424
|
const fname = 'updateEntity';
|
|
425
425
|
try
|
|
426
426
|
{
|
|
@@ -461,10 +461,10 @@ class PGAccessLayer
|
|
|
461
461
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
462
462
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
463
463
|
}
|
|
464
|
-
|
|
464
|
+
}
|
|
465
465
|
|
|
466
|
-
|
|
467
|
-
|
|
466
|
+
async deleteEntity(userid, resourceid, resourcevnum, entityid, entityvnum)
|
|
467
|
+
{
|
|
468
468
|
const fname = 'deleteEntity';
|
|
469
469
|
try
|
|
470
470
|
{
|
|
@@ -504,11 +504,11 @@ class PGAccessLayer
|
|
|
504
504
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
505
505
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
506
506
|
}
|
|
507
|
-
|
|
507
|
+
}
|
|
508
508
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
509
|
+
// get single resource and all associated entities for this resource
|
|
510
|
+
async getResource(filters)
|
|
511
|
+
{
|
|
512
512
|
const fname = 'getResource';
|
|
513
513
|
try
|
|
514
514
|
{
|
|
@@ -564,11 +564,11 @@ class PGAccessLayer
|
|
|
564
564
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
565
565
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
566
566
|
}
|
|
567
|
-
|
|
567
|
+
}
|
|
568
568
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
569
|
+
// get single resource and all associated entities for this resource
|
|
570
|
+
async getEntity(filters)
|
|
571
|
+
{
|
|
572
572
|
const fname = 'getEntity';
|
|
573
573
|
try
|
|
574
574
|
{
|
|
@@ -607,11 +607,11 @@ class PGAccessLayer
|
|
|
607
607
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
608
608
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
609
609
|
}
|
|
610
|
-
|
|
610
|
+
}
|
|
611
611
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
612
|
+
// get single resource and all associated entities for this resource
|
|
613
|
+
async getEntities(filters)
|
|
614
|
+
{
|
|
615
615
|
const fname = 'getEntities';
|
|
616
616
|
try
|
|
617
617
|
{
|
|
@@ -642,11 +642,11 @@ class PGAccessLayer
|
|
|
642
642
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
643
643
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
644
644
|
}
|
|
645
|
-
|
|
645
|
+
}
|
|
646
646
|
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
647
|
+
// get current resource
|
|
648
|
+
async getResources(filters)
|
|
649
|
+
{
|
|
650
650
|
const fname = 'getResources';
|
|
651
651
|
try
|
|
652
652
|
{
|
|
@@ -675,10 +675,10 @@ class PGAccessLayer
|
|
|
675
675
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
676
676
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
677
677
|
}
|
|
678
|
-
|
|
678
|
+
}
|
|
679
679
|
|
|
680
|
-
|
|
681
|
-
|
|
680
|
+
async deleteResources(resname, actionuser)
|
|
681
|
+
{
|
|
682
682
|
const fname = 'deleteResources';
|
|
683
683
|
try
|
|
684
684
|
{
|
|
@@ -703,10 +703,10 @@ class PGAccessLayer
|
|
|
703
703
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
704
704
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
705
705
|
}
|
|
706
|
-
|
|
706
|
+
}
|
|
707
707
|
|
|
708
|
-
|
|
709
|
-
|
|
708
|
+
async deleteAllResources()
|
|
709
|
+
{
|
|
710
710
|
const fname = 'createResource';
|
|
711
711
|
try
|
|
712
712
|
{
|
|
@@ -731,10 +731,10 @@ class PGAccessLayer
|
|
|
731
731
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
732
732
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
733
733
|
}
|
|
734
|
-
|
|
734
|
+
}
|
|
735
735
|
|
|
736
|
-
|
|
737
|
-
|
|
736
|
+
async getTotalResources()
|
|
737
|
+
{
|
|
738
738
|
const fname = 'getTotalResources';
|
|
739
739
|
try
|
|
740
740
|
{
|
|
@@ -758,10 +758,10 @@ class PGAccessLayer
|
|
|
758
758
|
if (consoleLogErrors) console.error(`[${fname}]: Could not get client from pool: ${error}`);
|
|
759
759
|
return { status: status.error, error: `[${fname}]: Operation was not successful`, detail: error };
|
|
760
760
|
}
|
|
761
|
-
|
|
761
|
+
}
|
|
762
762
|
|
|
763
|
-
|
|
764
|
-
|
|
763
|
+
async executedbscript(scriptfile)
|
|
764
|
+
{
|
|
765
765
|
try
|
|
766
766
|
{
|
|
767
767
|
const fname = 'executedbscript';
|
|
@@ -794,19 +794,19 @@ class PGAccessLayer
|
|
|
794
794
|
if (consoleLogErrors) console.error(`Error executing script: [${scriptfile}]`);
|
|
795
795
|
throw error;
|
|
796
796
|
}
|
|
797
|
-
|
|
797
|
+
}
|
|
798
798
|
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
799
|
+
// Method only used for testing. Ensure that if redis is being used that the cache is always flushed.
|
|
800
|
+
async startdatabase()
|
|
801
|
+
{
|
|
802
802
|
if (this.#cache !== null)
|
|
803
803
|
{
|
|
804
804
|
await this.#cache.flushall();
|
|
805
805
|
}
|
|
806
|
-
|
|
806
|
+
}
|
|
807
807
|
|
|
808
|
-
|
|
809
|
-
|
|
808
|
+
async enddatabase()
|
|
809
|
+
{
|
|
810
810
|
debug(`Ending database for process PID: ${process.pid}`);
|
|
811
811
|
await this.#pgpool.end();
|
|
812
812
|
if (this.#cache !== null)
|
|
@@ -819,10 +819,10 @@ class PGAccessLayer
|
|
|
819
819
|
await this.#cache.quit();
|
|
820
820
|
this.#cache = null;
|
|
821
821
|
}
|
|
822
|
-
|
|
822
|
+
}
|
|
823
823
|
|
|
824
|
-
|
|
825
|
-
|
|
824
|
+
bulkInsert(fakerdata)
|
|
825
|
+
{
|
|
826
826
|
return new Promise((resolve, reject) =>
|
|
827
827
|
{
|
|
828
828
|
this.#pgpool.connect().then(client =>
|
|
@@ -883,7 +883,7 @@ class PGAccessLayer
|
|
|
883
883
|
console.log(error);
|
|
884
884
|
});
|
|
885
885
|
});
|
|
886
|
-
|
|
886
|
+
}
|
|
887
887
|
}
|
|
888
888
|
|
|
889
889
|
module.exports = { PGAccessLayer };
|