@nsshunt/stsdatamanagement 1.18.200 → 1.18.201

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.
Files changed (57) hide show
  1. package/dist/cliworker.js +20 -14
  2. package/dist/cliworker.js.map +1 -1
  3. package/dist/commonTypes.js.map +1 -1
  4. package/dist/dalUserManager.js +19 -19
  5. package/dist/dalUserManager.js.map +1 -1
  6. package/dist/dalUserManager.test.js +34 -34
  7. package/dist/dalUserManager.test.js.map +1 -1
  8. package/dist/databaseutils.js +11 -11
  9. package/dist/databaseutils.js.map +1 -1
  10. package/dist/datagenerator.js +77 -67
  11. package/dist/datagenerator.js.map +1 -1
  12. package/dist/dbAccessLayerManager.js +2 -2
  13. package/dist/dbAccessLayerManager.js.map +1 -1
  14. package/dist/dbaccess.js +7 -7
  15. package/dist/dbaccess.js.map +1 -1
  16. package/dist/dbbuild.test.js +41 -46
  17. package/dist/dbbuild.test.js.map +1 -1
  18. package/dist/dberrors.js +5 -5
  19. package/dist/dberrors.js.map +1 -1
  20. package/dist/pcaccesslayer-entity.test.js +189 -167
  21. package/dist/pcaccesslayer-entity.test.js.map +1 -1
  22. package/dist/pcaccesslayer.test.js +186 -164
  23. package/dist/pcaccesslayer.test.js.map +1 -1
  24. package/dist/pgaccesslayer-old.js +514 -264
  25. package/dist/pgaccesslayer-old.js.map +1 -1
  26. package/dist/pgpoolmanager.js +26 -22
  27. package/dist/pgpoolmanager.js.map +1 -1
  28. package/dist/pgutils.js +10 -9
  29. package/dist/pgutils.js.map +1 -1
  30. package/dist/setupdb.js +5 -7
  31. package/dist/setupdb.js.map +1 -1
  32. package/package.json +16 -15
  33. package/types/cliworker.d.ts +1 -1
  34. package/types/cliworker.d.ts.map +1 -1
  35. package/types/commonTypes.d.ts +3 -3
  36. package/types/commonTypes.d.ts.map +1 -1
  37. package/types/dalUserManager.d.ts +1 -1
  38. package/types/dalUserManager.d.ts.map +1 -1
  39. package/types/dalUserManager.test.d.ts.map +1 -1
  40. package/types/databaseutils.d.ts +2 -2
  41. package/types/databaseutils.d.ts.map +1 -1
  42. package/types/datagenerator.d.ts +3 -3
  43. package/types/datagenerator.d.ts.map +1 -1
  44. package/types/dbAccessLayerManager.d.ts +1 -1
  45. package/types/dbAccessLayerManager.d.ts.map +1 -1
  46. package/types/dbaccess.d.ts +7 -7
  47. package/types/dbaccess.d.ts.map +1 -1
  48. package/types/dberrors.d.ts +1 -1
  49. package/types/dberrors.d.ts.map +1 -1
  50. package/types/pgaccesslayer-old.d.ts +4 -4
  51. package/types/pgaccesslayer-old.d.ts.map +1 -1
  52. package/types/pgpoolmanager.d.ts +4 -4
  53. package/types/pgpoolmanager.d.ts.map +1 -1
  54. package/types/pgutils.d.ts +1 -1
  55. package/types/pgutils.d.ts.map +1 -1
  56. package/types/setupdb.d.ts +1 -1
  57. package/types/setupdb.d.ts.map +1 -1
@@ -1,15 +1,15 @@
1
1
  /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
- import { beforeAll, afterAll, test, describe, expect } from 'vitest';
3
- import chalk from 'chalk';
4
- import { goptions, $ResetOptions } from '@nsshunt/stsconfig';
5
- import { defaultLogger, Sleep, edbaction } from '@nsshunt/stsutils';
6
- import { DatabaseUtils } from './databaseutils.js';
2
+ import { beforeAll, afterAll, test, describe, expect } from "vitest";
3
+ import chalk from "chalk";
4
+ import { goptions, $ResetOptions } from "@nsshunt/stsconfig";
5
+ import { defaultLogger, Sleep, edbaction, } from "@nsshunt/stsutils";
6
+ import { DatabaseUtils } from "./databaseutils.js";
7
7
  import { GenericContainer } from "testcontainers";
8
- import winston from 'winston';
9
- import { DBAccessLayerManager } from './dbAccessLayerManager.js';
10
- import { accessLayerType, eOperations } from './commonTypes.js';
11
- import { StatusCodes } from 'http-status-codes';
12
- const dbactionuser = 'jesttest';
8
+ import winston from "winston";
9
+ import { DBAccessLayerManager } from "./dbAccessLayerManager.js";
10
+ import { accessLayerType, eOperations, } from "./commonTypes.js";
11
+ import { StatusCodes } from "http-status-codes";
12
+ const dbactionuser = "jesttest";
13
13
  const sort = (a, b) => {
14
14
  if (a.detail && b.detail) {
15
15
  return a.detail.resname.localeCompare(b.detail.resname);
@@ -25,11 +25,9 @@ describe("Test pgaccesslayer", () => {
25
25
  beforeAll(async () => {
26
26
  winston.format.combine(winston.format.colorize(), winston.format.simple());
27
27
  const logger = winston.createLogger({
28
- level: 'silly',
28
+ level: "silly",
29
29
  format: winston.format.combine(winston.format.colorize(), winston.format.simple()),
30
- transports: [
31
- new winston.transports.Console(),
32
- ]
30
+ transports: [new winston.transports.Console()],
33
31
  });
34
32
  postgresContainer = await new GenericContainer("postgres")
35
33
  .withExposedPorts(5432)
@@ -37,13 +35,13 @@ describe("Test pgaccesslayer", () => {
37
35
  POSTGRES_PASSWORD: "postgres",
38
36
  //UV_THREADPOOL_SIZE: "64"
39
37
  })
40
- .withCommand(['-c', 'max_connections=20'])
38
+ .withCommand(["-c", "max_connections=20"])
41
39
  .start();
42
40
  await Sleep(1000);
43
41
  const postgresHttpPort = postgresContainer.getMappedPort(5432);
44
42
  const postgresHost = postgresContainer.getHost();
45
43
  process.env.DB_HOST = `${postgresHost}:${postgresHttpPort}`;
46
- process.env.POOL_SIZE = '10';
44
+ process.env.POOL_SIZE = "10";
47
45
  $ResetOptions();
48
46
  logger.info(chalk.green(`httpPort: [${postgresHttpPort}]`));
49
47
  logger.info(chalk.green(`host: [${postgresHost}]`));
@@ -54,11 +52,11 @@ describe("Test pgaccesslayer", () => {
54
52
  iterations: 10000,
55
53
  minextradata: 0,
56
54
  maxextradata: 1000,
57
- workerScriptFolder: './dist', //@@
58
- useMultiBar: false
55
+ workerScriptFolder: "./dist", //@@
56
+ useMultiBar: false,
59
57
  };
60
58
  const dbUtils = new DatabaseUtils({
61
- logger
59
+ logger,
62
60
  });
63
61
  await dbUtils.CreateDatabase(dbOptions);
64
62
  await Sleep(1000);
@@ -67,13 +65,13 @@ describe("Test pgaccesslayer", () => {
67
65
  accessLayerType: accessLayerType.postgresql,
68
66
  accessLayerOptions: {
69
67
  logger: defaultLogger,
70
- usedefaultdb: false
71
- }
68
+ usedefaultdb: false,
69
+ },
72
70
  });
73
71
  logger.info(chalk.green(`accessLayer:startdatabase()`));
74
72
  await accessLayer.StartDatabase();
75
73
  }, 120000);
76
- test('Testing Database Resource create, update, patch, read and delete', async () => {
74
+ test("Testing Database Resource create, update, patch, read and delete", async () => {
77
75
  expect.assertions(22);
78
76
  const initialCount = await accessLayer.GetResourceCount();
79
77
  expect(initialCount.detail).toEqual(20000);
@@ -81,13 +79,13 @@ describe("Test pgaccesslayer", () => {
81
79
  const userResourceType = {
82
80
  name: `user`,
83
81
  notes: `user notes`,
84
- code: 1
82
+ code: 1,
85
83
  };
86
84
  const userResourceOptions = {
87
85
  filters: {
88
86
  dbactionuser,
89
- resname: userResourceType.name
90
- }
87
+ resname: userResourceType.name,
88
+ },
91
89
  };
92
90
  const userResourceTypeCreateRecord = await accessLayer.CreateResource(userResourceOptions, userResourceType);
93
91
  const matchCreateResource = {
@@ -101,7 +99,7 @@ describe("Test pgaccesslayer", () => {
101
99
  resname: userResourceType.name,
102
100
  validto: null,
103
101
  vnum: "1",
104
- }
102
+ },
105
103
  };
106
104
  const createdResource = userResourceTypeCreateRecord.detail;
107
105
  expect(userResourceTypeCreateRecord).toMatchObject(matchCreateResource);
@@ -114,7 +112,7 @@ describe("Test pgaccesslayer", () => {
114
112
  operation: eOperations.GetResourceCount,
115
113
  options: {},
116
114
  status: StatusCodes.OK,
117
- detail: 20001
115
+ detail: 20001,
118
116
  };
119
117
  expect(count).toMatchObject(matchGetResourceCount);
120
118
  // Get Record -------------------------------------------------------------------------------------
@@ -130,7 +128,7 @@ describe("Test pgaccesslayer", () => {
130
128
  resname: userResourceType.name,
131
129
  validto: null,
132
130
  vnum: "1",
133
- }
131
+ },
134
132
  };
135
133
  const getResource = getRecord1.detail;
136
134
  expect(getRecord1).toMatchObject(matchGetResource);
@@ -140,7 +138,7 @@ describe("Test pgaccesslayer", () => {
140
138
  const updateUserResource = {
141
139
  name: userResourceType.name,
142
140
  notes: `Updated notes`,
143
- code: 2
141
+ code: 2,
144
142
  };
145
143
  const userResourceTypeUpdateRecord = await accessLayer.UpdateResource(userResourceOptions, updateUserResource);
146
144
  const matchUpdateResource = {
@@ -154,7 +152,7 @@ describe("Test pgaccesslayer", () => {
154
152
  resname: userResourceType.name,
155
153
  validto: null,
156
154
  vnum: "2",
157
- }
155
+ },
158
156
  };
159
157
  const updatedResource = userResourceTypeUpdateRecord.detail;
160
158
  expect(userResourceTypeUpdateRecord).toMatchObject(matchUpdateResource);
@@ -176,12 +174,12 @@ describe("Test pgaccesslayer", () => {
176
174
  resdesc: {
177
175
  name: userResourceType.name,
178
176
  notes: patchUserResource.notes,
179
- code: 2
177
+ code: 2,
180
178
  },
181
179
  resname: userResourceType.name,
182
180
  validto: null,
183
181
  vnum: "3",
184
- }
182
+ },
185
183
  };
186
184
  const patchedResource = patchResourceRecord.detail;
187
185
  expect(patchResourceRecord).toMatchObject(matchPatchResource);
@@ -199,12 +197,12 @@ describe("Test pgaccesslayer", () => {
199
197
  resdesc: {
200
198
  name: userResourceType.name,
201
199
  notes: patchUserResource.notes,
202
- code: 2
200
+ code: 2,
203
201
  },
204
202
  resname: userResourceType.name,
205
203
  validto: null,
206
204
  vnum: "4",
207
- }
205
+ },
208
206
  };
209
207
  const deletedResource = userResourceTypeDeleteRecord.detail;
210
208
  expect(userResourceTypeDeleteRecord).toMatchObject(matchDeleteResource);
@@ -219,8 +217,8 @@ describe("Test pgaccesslayer", () => {
219
217
  detail: null,
220
218
  error: {
221
219
  operation: eOperations.GetResource,
222
- status: StatusCodes.NOT_FOUND
223
- }
220
+ status: StatusCodes.NOT_FOUND,
221
+ },
224
222
  };
225
223
  expect(getDeletedRecord).toMatchObject(matchNotFoundResource);
226
224
  expect(getDeletedRecord.error?.errorMessage).toMatch(/\(current version\) not found/);
@@ -230,30 +228,30 @@ describe("Test pgaccesslayer", () => {
230
228
  operation: eOperations.GetResourceCount,
231
229
  options: {},
232
230
  status: StatusCodes.OK,
233
- detail: 20000
231
+ detail: 20000,
234
232
  };
235
233
  expect(resourceCountPostDelete).toMatchObject(matchResourceCountPostDelete);
236
234
  // Get Resources using filter -------------------------------------------------------------------------------------
237
235
  const resources = await accessLayer.GetResources({
238
236
  filters: {
239
- filter: 'RESCP-%',
240
- limit: '10',
241
- }
237
+ filter: "RESCP-%",
238
+ limit: "10",
239
+ },
242
240
  });
243
241
  expect(resources.detail.length).toEqual(10);
244
242
  }, 120000);
245
- test('Testing Database Entity create, update, patch, read and delete', async () => {
243
+ test("Testing Database Entity create, update, patch, read and delete", async () => {
246
244
  expect.assertions(30);
247
245
  const userResourceType = {
248
- name: 'user-t2',
249
- notes: 'user-t2 notes',
250
- code: 1
246
+ name: "user-t2",
247
+ notes: "user-t2 notes",
248
+ code: 1,
251
249
  };
252
250
  const userResourceOptions = {
253
251
  filters: {
254
252
  dbactionuser,
255
- resname: userResourceType.name
256
- }
253
+ resname: userResourceType.name,
254
+ },
257
255
  };
258
256
  const userResourceTypeCreateRecord = await accessLayer.CreateResource(userResourceOptions, userResourceType);
259
257
  const matchCreateResource = {
@@ -267,7 +265,7 @@ describe("Test pgaccesslayer", () => {
267
265
  resname: userResourceType.name,
268
266
  validto: null,
269
267
  vnum: "1",
270
- }
268
+ },
271
269
  };
272
270
  const createdResource = userResourceTypeCreateRecord.detail;
273
271
  expect(userResourceTypeCreateRecord).toMatchObject(matchCreateResource);
@@ -275,17 +273,17 @@ describe("Test pgaccesslayer", () => {
275
273
  expect(new Date(createdResource.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
276
274
  const resOid = createdResource.oid;
277
275
  const userEntity01 = {
278
- userId: 'user01',
279
- userName: 'user01 name',
276
+ userId: "user01",
277
+ userName: "user01 name",
280
278
  count: 1,
281
- description: `user01 description`
279
+ description: `user01 description`,
282
280
  };
283
281
  const entityResourceOptions = {
284
282
  filters: {
285
283
  dbactionuser,
286
284
  resname: userResourceType.name,
287
- entname: userEntity01.userId
288
- }
285
+ entname: userEntity01.userId,
286
+ },
289
287
  };
290
288
  // Create Record -------------------------------------------------------------------------------------
291
289
  const entityUser01CreateRecord = await accessLayer.CreateEntity(entityResourceOptions, userEntity01);
@@ -301,7 +299,7 @@ describe("Test pgaccesslayer", () => {
301
299
  entname: userEntity01.userId,
302
300
  validto: null,
303
301
  vnum: "1",
304
- }
302
+ },
305
303
  };
306
304
  const createdEntity = entityUser01CreateRecord.detail;
307
305
  expect(entityUser01CreateRecord).toMatchObject(matchCreateEntity);
@@ -313,7 +311,7 @@ describe("Test pgaccesslayer", () => {
313
311
  operation: eOperations.GetEntityCount,
314
312
  options: entityResourceOptions,
315
313
  status: StatusCodes.OK,
316
- detail: 1
314
+ detail: 1,
317
315
  };
318
316
  expect(entityCountPostCreate).toMatchObject(matchEntityCountPostCreate);
319
317
  // Get Record -------------------------------------------------------------------------------------
@@ -330,7 +328,7 @@ describe("Test pgaccesslayer", () => {
330
328
  entname: userEntity01.userId,
331
329
  validto: null,
332
330
  vnum: "1",
333
- }
331
+ },
334
332
  };
335
333
  const getEntityRecord = getRecord1.detail;
336
334
  expect(getRecord1).toMatchObject(matchGetEntity);
@@ -339,9 +337,9 @@ describe("Test pgaccesslayer", () => {
339
337
  // Update Record -------------------------------------------------------------------------------------
340
338
  const updateEntityResource = {
341
339
  userId: userEntity01.userId,
342
- userName: 'user01 name update',
340
+ userName: "user01 name update",
343
341
  count: 2,
344
- description: `user01 description update`
342
+ description: `user01 description update`,
345
343
  };
346
344
  const userEntity01UpdateRecord = await accessLayer.UpdateEntity(entityResourceOptions, updateEntityResource);
347
345
  const matchUpdateEntity = {
@@ -356,7 +354,7 @@ describe("Test pgaccesslayer", () => {
356
354
  entname: updateEntityResource.userId,
357
355
  validto: null,
358
356
  vnum: "2",
359
- }
357
+ },
360
358
  };
361
359
  const updateEntityRecord = userEntity01UpdateRecord.detail;
362
360
  expect(userEntity01UpdateRecord).toMatchObject(matchUpdateEntity);
@@ -365,7 +363,7 @@ describe("Test pgaccesslayer", () => {
365
363
  // Patch Record -------------------------------------------------------------------------------------
366
364
  const patchEntityResource = {
367
365
  userId: userEntity01.userId,
368
- userName: 'user01 name patched'
366
+ userName: "user01 name patched",
369
367
  };
370
368
  const userEntity01PatchRecord = await accessLayer.PatchEntity(entityResourceOptions, patchEntityResource);
371
369
  const matchPatchedEntity = {
@@ -380,7 +378,7 @@ describe("Test pgaccesslayer", () => {
380
378
  entname: patchEntityResource.userId,
381
379
  validto: null,
382
380
  vnum: "3",
383
- }
381
+ },
384
382
  };
385
383
  const patchedEntityRecord = userEntity01PatchRecord.detail;
386
384
  expect(userEntity01PatchRecord).toMatchObject(matchPatchedEntity);
@@ -400,7 +398,7 @@ describe("Test pgaccesslayer", () => {
400
398
  entname: patchEntityResource.userId,
401
399
  validto: null,
402
400
  vnum: "4",
403
- }
401
+ },
404
402
  };
405
403
  const deletedEntityRecord = userEntity01DeleteRecord.detail;
406
404
  expect(userEntity01DeleteRecord).toMatchObject(matchDeletedEntity);
@@ -415,8 +413,8 @@ describe("Test pgaccesslayer", () => {
415
413
  detail: null,
416
414
  error: {
417
415
  operation: eOperations.GetEntity,
418
- status: StatusCodes.NOT_FOUND
419
- }
416
+ status: StatusCodes.NOT_FOUND,
417
+ },
420
418
  };
421
419
  expect(getDeleted).toMatchObject(matchGetDeletedEntity);
422
420
  expect(getDeleted.error?.errorMessage).toMatch(/\(current version\) not found/);
@@ -426,7 +424,7 @@ describe("Test pgaccesslayer", () => {
426
424
  operation: eOperations.GetEntityCount,
427
425
  options: entityResourceOptions,
428
426
  status: StatusCodes.OK,
429
- detail: 0
427
+ detail: 0,
430
428
  };
431
429
  expect(entityCountPostDelete).toMatchObject(matchEntityCountPostDelete);
432
430
  // Create Additional Entities -------------------------------------------------------------------------------------
@@ -437,14 +435,14 @@ describe("Test pgaccesslayer", () => {
437
435
  userId: `user_${i}`,
438
436
  userName: `user_${i} name`,
439
437
  count: 2,
440
- description: `user_${i} description`
438
+ description: `user_${i} description`,
441
439
  };
442
440
  const entityResourceOptions = {
443
441
  filters: {
444
442
  dbactionuser,
445
443
  resname: userResourceType.name,
446
- entname: userEntity.userId
447
- }
444
+ entname: userEntity.userId,
445
+ },
448
446
  };
449
447
  const entityCreateRecord = await accessLayer.CreateEntity(entityResourceOptions, userEntity);
450
448
  expDetail.push(entityCreateRecord.detail);
@@ -460,7 +458,7 @@ describe("Test pgaccesslayer", () => {
460
458
  entname: userEntity.userId,
461
459
  validto: null,
462
460
  vnum: "1",
463
- }
461
+ },
464
462
  };
465
463
  const createdEntityRecord = entityCreateRecord.detail;
466
464
  expect(entityCreateRecord).toMatchObject(matchCreateEntity);
@@ -470,23 +468,23 @@ describe("Test pgaccesslayer", () => {
470
468
  // Get Entities (using filters) -------------------------------------------------------------------------------------
471
469
  const entities = await accessLayer.GetEntities({
472
470
  filters: {
473
- resname: 'user-t2',
474
- filter: '%'
475
- }
471
+ resname: "user-t2",
472
+ filter: "%",
473
+ },
476
474
  });
477
475
  expect(entities.detail).toMatchObject(expDetail);
478
476
  // Get Entity Count Post Delete -------------------------------------------------------------------------------------
479
477
  const entityCountOptions = {
480
478
  filters: {
481
- resname: 'user-t2'
482
- }
479
+ resname: "user-t2",
480
+ },
483
481
  };
484
482
  const entityCountPostMultiCreate = await accessLayer.GetEntityCount(entityCountOptions);
485
483
  const matchEntityCountPostMultiCreate = {
486
484
  operation: eOperations.GetEntityCount,
487
485
  options: entityCountOptions,
488
486
  status: StatusCodes.OK,
489
- detail: createCount
487
+ detail: createCount,
490
488
  };
491
489
  expect(entityCountPostMultiCreate).toMatchObject(matchEntityCountPostMultiCreate);
492
490
  }, 120000);
@@ -1101,7 +1099,7 @@ describe("Test pgaccesslayer", () => {
1101
1099
  });
1102
1100
  }, 120000);
1103
1101
  */
1104
- test('Testing Database Resource Batch Create', async () => {
1102
+ test("Testing Database Resource Batch Create", async () => {
1105
1103
  const createStart = 100;
1106
1104
  const createNum = 60;
1107
1105
  expect.assertions(180);
@@ -1114,19 +1112,19 @@ describe("Test pgaccesslayer", () => {
1114
1112
  const userResourceTypeCreateRecord = await accessLayer.CreateResource({
1115
1113
  filters: {
1116
1114
  dbactionuser,
1117
- resname: userResourceType.name
1118
- }
1115
+ resname: userResourceType.name,
1116
+ },
1119
1117
  }, userResourceType);
1120
1118
  const checkObject = {
1121
1119
  status: StatusCodes.CREATED,
1122
1120
  detail: {
1123
1121
  resname: userResourceType.name,
1124
1122
  resdesc: userResourceType,
1125
- vnum: '1',
1123
+ vnum: "1",
1126
1124
  validto: null,
1127
1125
  dbaction: edbaction.created,
1128
- dbactionuser
1129
- }
1126
+ dbactionuser,
1127
+ },
1130
1128
  };
1131
1129
  const createdResourceRecord = userResourceTypeCreateRecord.detail;
1132
1130
  finalResults[createdResourceRecord.resname] = createdResourceRecord;
@@ -1135,7 +1133,7 @@ describe("Test pgaccesslayer", () => {
1135
1133
  expect(parseInt(createdResourceRecord.oid)).toBeGreaterThan(0);
1136
1134
  }
1137
1135
  }, 120000);
1138
- test('Testing Database Resource Batch Create using Update', async () => {
1136
+ test("Testing Database Resource Batch Create using Update", async () => {
1139
1137
  const updateStart = 100;
1140
1138
  const updateNum = 5;
1141
1139
  expect.assertions(15);
@@ -1146,16 +1144,16 @@ describe("Test pgaccesslayer", () => {
1146
1144
  const userResourceTypePatch = {
1147
1145
  name,
1148
1146
  notes: `New record for user: [${i}]`,
1149
- code: i + 5000
1147
+ code: i + 5000,
1150
1148
  };
1151
1149
  const resourceParameterRecord = {
1152
1150
  opitons: {
1153
1151
  filters: {
1154
1152
  dbactionuser,
1155
1153
  resname: userResourceTypePatch.name,
1156
- }
1154
+ },
1157
1155
  },
1158
- resource: userResourceTypePatch
1156
+ resource: userResourceTypePatch,
1159
1157
  };
1160
1158
  resourceParameterPatchRecord.push(resourceParameterRecord);
1161
1159
  const testObject = {
@@ -1166,10 +1164,10 @@ describe("Test pgaccesslayer", () => {
1166
1164
  vnum: "1",
1167
1165
  validto: null,
1168
1166
  dbaction: edbaction.created,
1169
- dbactionuser
1167
+ dbactionuser,
1170
1168
  },
1171
1169
  operation: eOperations.UpdateResources,
1172
- options: {}
1170
+ options: {},
1173
1171
  };
1174
1172
  testRecords.push(testObject);
1175
1173
  }
@@ -1180,14 +1178,16 @@ describe("Test pgaccesslayer", () => {
1180
1178
  if (retVal.length === testRecords.length) {
1181
1179
  for (let i = 0; i < retVal.length; i++) {
1182
1180
  expect(retVal[i]).toMatchObject(testRecords[i]);
1183
- const updatedResourceRecord = retVal[i].detail;
1184
- finalResults[updatedResourceRecord.resname] = updatedResourceRecord;
1181
+ const updatedResourceRecord = retVal[i]
1182
+ .detail;
1183
+ finalResults[updatedResourceRecord.resname] =
1184
+ updatedResourceRecord;
1185
1185
  expect(new Date(updatedResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
1186
1186
  expect(parseInt(updatedResourceRecord.oid)).toBeGreaterThan(0);
1187
1187
  }
1188
1188
  }
1189
1189
  }, 120000);
1190
- test('Testing Database Resource Batch Update', async () => {
1190
+ test("Testing Database Resource Batch Update", async () => {
1191
1191
  const updateStart = 100;
1192
1192
  const updateNum = 5;
1193
1193
  expect.assertions(15);
@@ -1198,16 +1198,16 @@ describe("Test pgaccesslayer", () => {
1198
1198
  const userResourceTypePatch = {
1199
1199
  name,
1200
1200
  notes: `Updated notes for user: [${i}]`,
1201
- code: i + 1000
1201
+ code: i + 1000,
1202
1202
  };
1203
1203
  const resourceParameterRecord = {
1204
1204
  opitons: {
1205
1205
  filters: {
1206
1206
  dbactionuser,
1207
1207
  resname: userResourceTypePatch.name,
1208
- }
1208
+ },
1209
1209
  },
1210
- resource: userResourceTypePatch
1210
+ resource: userResourceTypePatch,
1211
1211
  };
1212
1212
  resourceParameterPatchRecord.push(resourceParameterRecord);
1213
1213
  const testObject = {
@@ -1218,10 +1218,10 @@ describe("Test pgaccesslayer", () => {
1218
1218
  vnum: "2",
1219
1219
  validto: null,
1220
1220
  dbaction: edbaction.updated,
1221
- dbactionuser
1221
+ dbactionuser,
1222
1222
  },
1223
1223
  operation: eOperations.UpdateResources,
1224
- options: {}
1224
+ options: {},
1225
1225
  };
1226
1226
  testRecords.push(testObject);
1227
1227
  }
@@ -1232,14 +1232,16 @@ describe("Test pgaccesslayer", () => {
1232
1232
  if (retVal.length === testRecords.length) {
1233
1233
  for (let i = 0; i < retVal.length; i++) {
1234
1234
  expect(retVal[i]).toMatchObject(testRecords[i]);
1235
- const updatedResourceRecord = retVal[i].detail;
1236
- finalResults[updatedResourceRecord.resname] = updatedResourceRecord;
1235
+ const updatedResourceRecord = retVal[i]
1236
+ .detail;
1237
+ finalResults[updatedResourceRecord.resname] =
1238
+ updatedResourceRecord;
1237
1239
  expect(new Date(updatedResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
1238
1240
  expect(parseInt(updatedResourceRecord.oid)).toBeGreaterThan(0);
1239
1241
  }
1240
1242
  }
1241
1243
  }, 120000);
1242
- test('Testing Database Resource Batch Update with Errors', async () => {
1244
+ test("Testing Database Resource Batch Update with Errors", async () => {
1243
1245
  const updateErrorStart = 110;
1244
1246
  const updateErrorNum = 5;
1245
1247
  const updateErrorIndex = 112;
@@ -1254,7 +1256,7 @@ describe("Test pgaccesslayer", () => {
1254
1256
  const userResourceTypePatch = {
1255
1257
  name,
1256
1258
  notes: `Updated notes for user: [${i}]`,
1257
- code: i + 1000
1259
+ code: i + 1000,
1258
1260
  };
1259
1261
  const resourceParameterRecord = {
1260
1262
  opitons: {
@@ -1262,9 +1264,9 @@ describe("Test pgaccesslayer", () => {
1262
1264
  dbactionuser,
1263
1265
  resname: userResourceTypePatch.name,
1264
1266
  },
1265
- errorOnBatchUpdate: true // We want errors instead of create new records
1267
+ errorOnBatchUpdate: true, // We want errors instead of create new records
1266
1268
  },
1267
- resource: userResourceTypePatch
1269
+ resource: userResourceTypePatch,
1268
1270
  };
1269
1271
  resourceParameterPatchRecord.push(resourceParameterRecord);
1270
1272
  if (i === updateErrorIndex) {
@@ -1275,8 +1277,8 @@ describe("Test pgaccesslayer", () => {
1275
1277
  options: {},
1276
1278
  error: {
1277
1279
  operation: eOperations.GetResource,
1278
- status: StatusCodes.NOT_FOUND
1279
- }
1280
+ status: StatusCodes.NOT_FOUND,
1281
+ },
1280
1282
  };
1281
1283
  testRecords.push(testObject);
1282
1284
  }
@@ -1285,7 +1287,7 @@ describe("Test pgaccesslayer", () => {
1285
1287
  status: StatusCodes.OK,
1286
1288
  detail: null,
1287
1289
  operation: eOperations.UpdateResources,
1288
- options: {}
1290
+ options: {},
1289
1291
  };
1290
1292
  testRecords.push(testObject);
1291
1293
  }
@@ -1298,20 +1300,24 @@ describe("Test pgaccesslayer", () => {
1298
1300
  for (let i = 0; i < retVal.length; i++) {
1299
1301
  expect(retVal[i]).toMatchObject(testRecords[i]);
1300
1302
  if (retVal[i].error) {
1301
- const updatedResourceRecordError = retVal[i].error;
1302
- const resName = retVal[i].options.filters.resname;
1303
+ const updatedResourceRecordError = retVal[i]
1304
+ .error;
1305
+ const resName = retVal[i].options.filters
1306
+ .resname;
1303
1307
  finalResults[resName] = updatedResourceRecordError;
1304
1308
  expect(retVal[i].error?.errorMessage).toMatch(/\(current version\) not found/);
1305
1309
  }
1306
1310
  else {
1307
- const resName = retVal[i].options.filters.resname;
1311
+ const resName = retVal[i].options.filters
1312
+ .resname;
1308
1313
  const missingResource = await accessLayer.GetResource(retVal[i].options);
1309
- finalResults[resName] = missingResource.detail;
1314
+ finalResults[resName] =
1315
+ missingResource.detail;
1310
1316
  }
1311
1317
  }
1312
1318
  }
1313
1319
  }, 120000);
1314
- test('Testing Database Resource Batch Patch', async () => {
1320
+ test("Testing Database Resource Batch Patch", async () => {
1315
1321
  const patchStart = 120;
1316
1322
  const patchNum = 5;
1317
1323
  expect.assertions(15);
@@ -1321,21 +1327,21 @@ describe("Test pgaccesslayer", () => {
1321
1327
  const name = `user_patch_test_${i}`;
1322
1328
  const userResourceTypePatch = {
1323
1329
  name,
1324
- notes: `Patched notes for user: [${i}]`
1330
+ notes: `Patched notes for user: [${i}]`,
1325
1331
  };
1326
1332
  const userResourceTypePostPatch = {
1327
1333
  name,
1328
1334
  notes: userResourceTypePatch.notes,
1329
- code: i // Note that the original code from the create should remain the same
1335
+ code: i, // Note that the original code from the create should remain the same
1330
1336
  };
1331
1337
  const resourceParameterRecord = {
1332
1338
  opitons: {
1333
1339
  filters: {
1334
1340
  dbactionuser,
1335
1341
  resname: userResourceTypePatch.name,
1336
- }
1342
+ },
1337
1343
  },
1338
- resource: userResourceTypePatch
1344
+ resource: userResourceTypePatch,
1339
1345
  };
1340
1346
  resourceParameterPatchRecord.push(resourceParameterRecord);
1341
1347
  const testObject = {
@@ -1346,10 +1352,10 @@ describe("Test pgaccesslayer", () => {
1346
1352
  vnum: "2",
1347
1353
  validto: null,
1348
1354
  dbaction: edbaction.updated,
1349
- dbactionuser
1355
+ dbactionuser,
1350
1356
  },
1351
1357
  operation: eOperations.PatchResources,
1352
- options: {}
1358
+ options: {},
1353
1359
  };
1354
1360
  testRecords.push(testObject);
1355
1361
  }
@@ -1360,14 +1366,16 @@ describe("Test pgaccesslayer", () => {
1360
1366
  if (retVal.length === testRecords.length) {
1361
1367
  for (let i = 0; i < retVal.length; i++) {
1362
1368
  expect(retVal[i]).toMatchObject(testRecords[i]);
1363
- const patchedResourceRecord = retVal[i].detail;
1364
- finalResults[patchedResourceRecord.resname] = patchedResourceRecord;
1369
+ const patchedResourceRecord = retVal[i]
1370
+ .detail;
1371
+ finalResults[patchedResourceRecord.resname] =
1372
+ patchedResourceRecord;
1365
1373
  expect(new Date(patchedResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
1366
1374
  expect(parseInt(patchedResourceRecord.oid)).toBeGreaterThan(0);
1367
1375
  }
1368
1376
  }
1369
1377
  }, 120000);
1370
- test('Testing Database Resource Batch Patch with Errors', async () => {
1378
+ test("Testing Database Resource Batch Patch with Errors", async () => {
1371
1379
  const patchErrorStart = 130;
1372
1380
  const patchErrorNum = 5;
1373
1381
  const patchErrorIndex = 132;
@@ -1381,7 +1389,7 @@ describe("Test pgaccesslayer", () => {
1381
1389
  }
1382
1390
  const userResourceTypePatch = {
1383
1391
  name,
1384
- notes: `Patched notes for user: [${i}]`
1392
+ notes: `Patched notes for user: [${i}]`,
1385
1393
  };
1386
1394
  const resourceParameterRecord = {
1387
1395
  opitons: {
@@ -1389,9 +1397,9 @@ describe("Test pgaccesslayer", () => {
1389
1397
  dbactionuser,
1390
1398
  resname: userResourceTypePatch.name,
1391
1399
  },
1392
- errorOnBatchUpdate: true // We want errors instead of create new records
1400
+ errorOnBatchUpdate: true, // We want errors instead of create new records
1393
1401
  },
1394
- resource: userResourceTypePatch
1402
+ resource: userResourceTypePatch,
1395
1403
  };
1396
1404
  resourceParameterPatchRecord.push(resourceParameterRecord);
1397
1405
  if (i === patchErrorIndex) {
@@ -1402,8 +1410,8 @@ describe("Test pgaccesslayer", () => {
1402
1410
  options: {},
1403
1411
  error: {
1404
1412
  operation: eOperations.GetResource,
1405
- status: StatusCodes.NOT_FOUND
1406
- }
1413
+ status: StatusCodes.NOT_FOUND,
1414
+ },
1407
1415
  };
1408
1416
  testRecords.push(testObject);
1409
1417
  }
@@ -1412,7 +1420,7 @@ describe("Test pgaccesslayer", () => {
1412
1420
  status: StatusCodes.OK,
1413
1421
  detail: null,
1414
1422
  operation: eOperations.PatchResources,
1415
- options: {}
1423
+ options: {},
1416
1424
  };
1417
1425
  testRecords.push(testObject);
1418
1426
  }
@@ -1425,20 +1433,24 @@ describe("Test pgaccesslayer", () => {
1425
1433
  for (let i = 0; i < retVal.length; i++) {
1426
1434
  expect(retVal[i]).toMatchObject(testRecords[i]);
1427
1435
  if (retVal[i].error) {
1428
- const patchedResourceRecordError = retVal[i].error;
1429
- const resName = retVal[i].options.filters.resname;
1436
+ const patchedResourceRecordError = retVal[i]
1437
+ .error;
1438
+ const resName = retVal[i].options.filters
1439
+ .resname;
1430
1440
  finalResults[resName] = patchedResourceRecordError;
1431
1441
  expect(retVal[i].error?.errorMessage).toMatch(/\(current version\) not found/);
1432
1442
  }
1433
1443
  else {
1434
- const resName = retVal[i].options.filters.resname;
1444
+ const resName = retVal[i].options.filters
1445
+ .resname;
1435
1446
  const missingResource = await accessLayer.GetResource(retVal[i].options);
1436
- finalResults[resName] = missingResource.detail;
1447
+ finalResults[resName] =
1448
+ missingResource.detail;
1437
1449
  }
1438
1450
  }
1439
1451
  }
1440
1452
  }, 120000);
1441
- test('Testing Database Resource Batch Delete', async () => {
1453
+ test("Testing Database Resource Batch Delete", async () => {
1442
1454
  const deleteStart = 140;
1443
1455
  const deleteNum = 5;
1444
1456
  expect.assertions(15);
@@ -1459,9 +1471,9 @@ describe("Test pgaccesslayer", () => {
1459
1471
  filters: {
1460
1472
  dbactionuser,
1461
1473
  resname: userResourceTypeDelete.name,
1462
- }
1474
+ },
1463
1475
  },
1464
- resource: userResourceTypeDelete
1476
+ resource: userResourceTypeDelete,
1465
1477
  };
1466
1478
  resourceParameterPatchRecord.push(resourceParameterRecord);
1467
1479
  const testObject = {
@@ -1472,10 +1484,10 @@ describe("Test pgaccesslayer", () => {
1472
1484
  vnum: "2",
1473
1485
  validto: null,
1474
1486
  dbaction: edbaction.deleted,
1475
- dbactionuser
1487
+ dbactionuser,
1476
1488
  },
1477
1489
  operation: eOperations.DeleteResources,
1478
- options: {}
1490
+ options: {},
1479
1491
  };
1480
1492
  testRecords.push(testObject);
1481
1493
  }
@@ -1486,14 +1498,16 @@ describe("Test pgaccesslayer", () => {
1486
1498
  if (retVal.length === testRecords.length) {
1487
1499
  for (let i = 0; i < retVal.length; i++) {
1488
1500
  expect(retVal[i]).toMatchObject(testRecords[i]);
1489
- const deletedResourceRecord = retVal[i].detail;
1490
- finalResults[deletedResourceRecord.resname] = deletedResourceRecord;
1501
+ const deletedResourceRecord = retVal[i]
1502
+ .detail;
1503
+ finalResults[deletedResourceRecord.resname] =
1504
+ deletedResourceRecord;
1491
1505
  expect(new Date(deletedResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
1492
1506
  expect(parseInt(deletedResourceRecord.oid)).toBeGreaterThan(0);
1493
1507
  }
1494
1508
  }
1495
1509
  }, 120000);
1496
- test('Testing Database Resource Batch Delete with Error', async () => {
1510
+ test("Testing Database Resource Batch Delete with Error", async () => {
1497
1511
  const deleteErrorStart = 150;
1498
1512
  const deleteErrorNum = 5;
1499
1513
  const deleteErrorIndex = 152;
@@ -1513,9 +1527,9 @@ describe("Test pgaccesslayer", () => {
1513
1527
  filters: {
1514
1528
  dbactionuser,
1515
1529
  resname: userResourceTypeDelete.name,
1516
- }
1530
+ },
1517
1531
  },
1518
- resource: userResourceTypeDelete
1532
+ resource: userResourceTypeDelete,
1519
1533
  };
1520
1534
  resourceParameterPatchRecord.push(resourceParameterRecord);
1521
1535
  if (i === deleteErrorIndex) {
@@ -1526,8 +1540,8 @@ describe("Test pgaccesslayer", () => {
1526
1540
  options: {},
1527
1541
  error: {
1528
1542
  operation: eOperations.GetResource,
1529
- status: StatusCodes.NOT_FOUND
1530
- }
1543
+ status: StatusCodes.NOT_FOUND,
1544
+ },
1531
1545
  };
1532
1546
  testRecords.push(testObject);
1533
1547
  }
@@ -1536,7 +1550,7 @@ describe("Test pgaccesslayer", () => {
1536
1550
  status: StatusCodes.OK,
1537
1551
  detail: null,
1538
1552
  operation: eOperations.DeleteResources,
1539
- options: {}
1553
+ options: {},
1540
1554
  };
1541
1555
  testRecords.push(testObject);
1542
1556
  }
@@ -1549,30 +1563,34 @@ describe("Test pgaccesslayer", () => {
1549
1563
  for (let i = 0; i < retVal.length; i++) {
1550
1564
  expect(retVal[i]).toMatchObject(testRecords[i]);
1551
1565
  if (retVal[i].error) {
1552
- const deletedResourceRecordError = retVal[i].error;
1553
- const resName = retVal[i].options.filters.resname;
1566
+ const deletedResourceRecordError = retVal[i]
1567
+ .error;
1568
+ const resName = retVal[i].options.filters
1569
+ .resname;
1554
1570
  finalResults[resName] = deletedResourceRecordError;
1555
1571
  expect(retVal[i].error?.errorMessage).toMatch(/\(current version\) not found/);
1556
1572
  }
1557
1573
  else {
1558
- const resName = retVal[i].options.filters.resname;
1574
+ const resName = retVal[i].options.filters
1575
+ .resname;
1559
1576
  const missingResource = await accessLayer.GetResource(retVal[i].options);
1560
- finalResults[resName] = missingResource.detail;
1577
+ finalResults[resName] =
1578
+ missingResource.detail;
1561
1579
  }
1562
1580
  }
1563
1581
  }
1564
1582
  }, 120000);
1565
- test('Get All user_patch_test_ Resources', async () => {
1583
+ test("Get All user_patch_test_ Resources", async () => {
1566
1584
  expect.assertions(51);
1567
1585
  // All Records
1568
1586
  const AllRecords = await accessLayer.GetResources({
1569
1587
  filters: {
1570
- filter: 'user_patch_test_%',
1571
- limit: '50'
1572
- }
1588
+ filter: "user_patch_test_%",
1589
+ limit: "50",
1590
+ },
1573
1591
  });
1574
1592
  expect(AllRecords.detail.length).toEqual(50);
1575
- AllRecords.detail.forEach(u => {
1593
+ AllRecords.detail.forEach((u) => {
1576
1594
  const compareObject = finalResults[u.resname];
1577
1595
  if (compareObject) {
1578
1596
  expect(u).toMatchObject(compareObject);
@@ -1582,36 +1600,40 @@ describe("Test pgaccesslayer", () => {
1582
1600
  // Output formatted table
1583
1601
  const columns = [
1584
1602
  {
1585
- name: 'Name',
1603
+ name: "Name",
1586
1604
  width: 30,
1587
1605
  left: true,
1588
- field: 'name'
1606
+ field: "name",
1589
1607
  },
1590
1608
  {
1591
- name: 'Notes',
1609
+ name: "Notes",
1592
1610
  width: 50,
1593
1611
  left: true,
1594
- field: 'notes'
1612
+ field: "notes",
1595
1613
  },
1596
1614
  {
1597
- name: 'Code',
1615
+ name: "Code",
1598
1616
  width: 10,
1599
1617
  left: false,
1600
- field: 'code'
1601
- }
1618
+ field: "code",
1619
+ },
1602
1620
  ];
1603
- let header = '';
1621
+ let header = "";
1604
1622
  let length = 0;
1605
- columns.forEach(c => {
1606
- header += (c.left ? c.name.padEnd(c.width) : c.name.padStart(c.width));
1623
+ columns.forEach((c) => {
1624
+ header += c.left
1625
+ ? c.name.padEnd(c.width)
1626
+ : c.name.padStart(c.width);
1607
1627
  length += c.width;
1608
1628
  });
1609
1629
  console.log(header);
1610
- console.log('-'.repeat(length));
1611
- AllRecords.detail.forEach(u => {
1612
- let detail = '';
1613
- columns.forEach(c => {
1614
- detail += (c.left ? u.resdesc[c.field].toString().padEnd(c.width) : u.resdesc[c.field].toString().padStart(c.width));
1630
+ console.log("-".repeat(length));
1631
+ AllRecords.detail.forEach((u) => {
1632
+ let detail = "";
1633
+ columns.forEach((c) => {
1634
+ detail += c.left
1635
+ ? u.resdesc[c.field].toString().padEnd(c.width)
1636
+ : u.resdesc[c.field].toString().padStart(c.width);
1615
1637
  });
1616
1638
  console.log(detail);
1617
1639
  });