@nsshunt/stsdatamanagement 1.18.199 → 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 (61) 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/pgaccesslayer.js +5 -2
  27. package/dist/pgaccesslayer.js.map +1 -1
  28. package/dist/pgpoolmanager.js +26 -22
  29. package/dist/pgpoolmanager.js.map +1 -1
  30. package/dist/pgutils.js +10 -9
  31. package/dist/pgutils.js.map +1 -1
  32. package/dist/setupdb.js +5 -7
  33. package/dist/setupdb.js.map +1 -1
  34. package/package.json +16 -15
  35. package/types/cliworker.d.ts +1 -1
  36. package/types/cliworker.d.ts.map +1 -1
  37. package/types/commonTypes.d.ts +15 -2
  38. package/types/commonTypes.d.ts.map +1 -1
  39. package/types/dalUserManager.d.ts +1 -1
  40. package/types/dalUserManager.d.ts.map +1 -1
  41. package/types/dalUserManager.test.d.ts.map +1 -1
  42. package/types/databaseutils.d.ts +2 -2
  43. package/types/databaseutils.d.ts.map +1 -1
  44. package/types/datagenerator.d.ts +3 -3
  45. package/types/datagenerator.d.ts.map +1 -1
  46. package/types/dbAccessLayerManager.d.ts +1 -1
  47. package/types/dbAccessLayerManager.d.ts.map +1 -1
  48. package/types/dbaccess.d.ts +7 -7
  49. package/types/dbaccess.d.ts.map +1 -1
  50. package/types/dberrors.d.ts +1 -1
  51. package/types/dberrors.d.ts.map +1 -1
  52. package/types/pgaccesslayer-old.d.ts +4 -4
  53. package/types/pgaccesslayer-old.d.ts.map +1 -1
  54. package/types/pgaccesslayer.d.ts +2 -0
  55. package/types/pgaccesslayer.d.ts.map +1 -1
  56. package/types/pgpoolmanager.d.ts +5 -9
  57. package/types/pgpoolmanager.d.ts.map +1 -1
  58. package/types/pgutils.d.ts +1 -1
  59. package/types/pgutils.d.ts.map +1 -1
  60. package/types/setupdb.d.ts +1 -1
  61. 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.entname.localeCompare(b.detail.entname);
@@ -23,19 +23,17 @@ describe("Test pgaccesslayer", () => {
23
23
  let accessLayer;
24
24
  const finalResults = {};
25
25
  const userResourceType = {
26
- name: 'user-t2',
27
- notes: 'user-t2 notes',
28
- code: 1
26
+ name: "user-t2",
27
+ notes: "user-t2 notes",
28
+ code: 1,
29
29
  };
30
30
  let resourceoid = "";
31
31
  beforeAll(async () => {
32
32
  winston.format.combine(winston.format.colorize(), winston.format.simple());
33
33
  const logger = winston.createLogger({
34
- level: 'silly',
34
+ level: "silly",
35
35
  format: winston.format.combine(winston.format.colorize(), winston.format.simple()),
36
- transports: [
37
- new winston.transports.Console(),
38
- ]
36
+ transports: [new winston.transports.Console()],
39
37
  });
40
38
  postgresContainer = await new GenericContainer("postgres")
41
39
  .withExposedPorts(5432)
@@ -43,13 +41,13 @@ describe("Test pgaccesslayer", () => {
43
41
  POSTGRES_PASSWORD: "postgres",
44
42
  //UV_THREADPOOL_SIZE: "64"
45
43
  })
46
- .withCommand(['-c', 'max_connections=20'])
44
+ .withCommand(["-c", "max_connections=20"])
47
45
  .start();
48
46
  await Sleep(1000);
49
47
  const postgresHttpPort = postgresContainer.getMappedPort(5432);
50
48
  const postgresHost = postgresContainer.getHost();
51
49
  process.env.DB_HOST = `${postgresHost}:${postgresHttpPort}`;
52
- process.env.POOL_SIZE = '10';
50
+ process.env.POOL_SIZE = "10";
53
51
  $ResetOptions();
54
52
  logger.info(chalk.green(`httpPort: [${postgresHttpPort}]`));
55
53
  logger.info(chalk.green(`host: [${postgresHost}]`));
@@ -60,11 +58,11 @@ describe("Test pgaccesslayer", () => {
60
58
  iterations: 10000,
61
59
  minextradata: 0,
62
60
  maxextradata: 1000,
63
- workerScriptFolder: './dist', //@@
64
- useMultiBar: false
61
+ workerScriptFolder: "./dist", //@@
62
+ useMultiBar: false,
65
63
  };
66
64
  const dbUtils = new DatabaseUtils({
67
- logger
65
+ logger,
68
66
  });
69
67
  await dbUtils.CreateDatabase(dbOptions);
70
68
  await Sleep(1000);
@@ -73,19 +71,19 @@ describe("Test pgaccesslayer", () => {
73
71
  accessLayerType: accessLayerType.postgresql,
74
72
  accessLayerOptions: {
75
73
  logger: defaultLogger,
76
- usedefaultdb: false
77
- }
74
+ usedefaultdb: false,
75
+ },
78
76
  });
79
77
  logger.info(chalk.green(`accessLayer:startdatabase()`));
80
78
  await accessLayer.StartDatabase();
81
79
  }, 120000);
82
- test('Testing Database Entity create, update, patch, read and delete', async () => {
80
+ test("Testing Database Entity create, update, patch, read and delete", async () => {
83
81
  expect.assertions(30);
84
82
  const userResourceOptions = {
85
83
  filters: {
86
84
  dbactionuser,
87
- resname: userResourceType.name
88
- }
85
+ resname: userResourceType.name,
86
+ },
89
87
  };
90
88
  const userResourceTypeCreateRecord = await accessLayer.CreateResource(userResourceOptions, userResourceType);
91
89
  const matchCreateResource = {
@@ -99,7 +97,7 @@ describe("Test pgaccesslayer", () => {
99
97
  resname: userResourceType.name,
100
98
  validto: null,
101
99
  vnum: "1",
102
- }
100
+ },
103
101
  };
104
102
  const createdResource = userResourceTypeCreateRecord.detail;
105
103
  expect(userResourceTypeCreateRecord).toMatchObject(matchCreateResource);
@@ -107,17 +105,17 @@ describe("Test pgaccesslayer", () => {
107
105
  expect(new Date(createdResource.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
108
106
  resourceoid = createdResource.oid;
109
107
  const userEntity01 = {
110
- userId: 'user01',
111
- userName: 'user01 name',
108
+ userId: "user01",
109
+ userName: "user01 name",
112
110
  count: 1,
113
- description: `user01 description`
111
+ description: `user01 description`,
114
112
  };
115
113
  const entityResourceOptions = {
116
114
  filters: {
117
115
  dbactionuser,
118
116
  resname: userResourceType.name,
119
- entname: userEntity01.userId
120
- }
117
+ entname: userEntity01.userId,
118
+ },
121
119
  };
122
120
  // Create Record -------------------------------------------------------------------------------------
123
121
  const entityUser01CreateRecord = await accessLayer.CreateEntity(entityResourceOptions, userEntity01);
@@ -133,7 +131,7 @@ describe("Test pgaccesslayer", () => {
133
131
  entname: userEntity01.userId,
134
132
  validto: null,
135
133
  vnum: "1",
136
- }
134
+ },
137
135
  };
138
136
  const createdEntity = entityUser01CreateRecord.detail;
139
137
  expect(entityUser01CreateRecord).toMatchObject(matchCreateEntity);
@@ -145,7 +143,7 @@ describe("Test pgaccesslayer", () => {
145
143
  operation: eOperations.GetEntityCount,
146
144
  options: entityResourceOptions,
147
145
  status: StatusCodes.OK,
148
- detail: 1
146
+ detail: 1,
149
147
  };
150
148
  expect(entityCountPostCreate).toMatchObject(matchEntityCountPostCreate);
151
149
  // Get Record -------------------------------------------------------------------------------------
@@ -162,7 +160,7 @@ describe("Test pgaccesslayer", () => {
162
160
  entname: userEntity01.userId,
163
161
  validto: null,
164
162
  vnum: "1",
165
- }
163
+ },
166
164
  };
167
165
  const getEntityRecord = getRecord1.detail;
168
166
  expect(getRecord1).toMatchObject(matchGetEntity);
@@ -171,9 +169,9 @@ describe("Test pgaccesslayer", () => {
171
169
  // Update Record -------------------------------------------------------------------------------------
172
170
  const updateEntityResource = {
173
171
  userId: userEntity01.userId,
174
- userName: 'user01 name update',
172
+ userName: "user01 name update",
175
173
  count: 2,
176
- description: `user01 description update`
174
+ description: `user01 description update`,
177
175
  };
178
176
  const userEntity01UpdateRecord = await accessLayer.UpdateEntity(entityResourceOptions, updateEntityResource);
179
177
  const matchUpdateEntity = {
@@ -188,7 +186,7 @@ describe("Test pgaccesslayer", () => {
188
186
  entname: updateEntityResource.userId,
189
187
  validto: null,
190
188
  vnum: "2",
191
- }
189
+ },
192
190
  };
193
191
  const updateEntityRecord = userEntity01UpdateRecord.detail;
194
192
  expect(userEntity01UpdateRecord).toMatchObject(matchUpdateEntity);
@@ -197,7 +195,7 @@ describe("Test pgaccesslayer", () => {
197
195
  // Patch Record -------------------------------------------------------------------------------------
198
196
  const patchEntityResource = {
199
197
  userId: userEntity01.userId,
200
- userName: 'user01 name patched'
198
+ userName: "user01 name patched",
201
199
  };
202
200
  const userEntity01PatchRecord = await accessLayer.PatchEntity(entityResourceOptions, patchEntityResource);
203
201
  const matchPatchedEntity = {
@@ -212,7 +210,7 @@ describe("Test pgaccesslayer", () => {
212
210
  entname: patchEntityResource.userId,
213
211
  validto: null,
214
212
  vnum: "3",
215
- }
213
+ },
216
214
  };
217
215
  const patchedEntityRecord = userEntity01PatchRecord.detail;
218
216
  expect(userEntity01PatchRecord).toMatchObject(matchPatchedEntity);
@@ -232,7 +230,7 @@ describe("Test pgaccesslayer", () => {
232
230
  entname: patchEntityResource.userId,
233
231
  validto: null,
234
232
  vnum: "4",
235
- }
233
+ },
236
234
  };
237
235
  const deletedEntityRecord = userEntity01DeleteRecord.detail;
238
236
  expect(userEntity01DeleteRecord).toMatchObject(matchDeletedEntity);
@@ -247,8 +245,8 @@ describe("Test pgaccesslayer", () => {
247
245
  detail: null,
248
246
  error: {
249
247
  operation: eOperations.GetEntity,
250
- status: StatusCodes.NOT_FOUND
251
- }
248
+ status: StatusCodes.NOT_FOUND,
249
+ },
252
250
  };
253
251
  expect(getDeleted).toMatchObject(matchGetDeletedEntity);
254
252
  expect(getDeleted.error?.errorMessage).toMatch(/\(current version\) not found/);
@@ -258,7 +256,7 @@ describe("Test pgaccesslayer", () => {
258
256
  operation: eOperations.GetEntityCount,
259
257
  options: entityResourceOptions,
260
258
  status: StatusCodes.OK,
261
- detail: 0
259
+ detail: 0,
262
260
  };
263
261
  expect(entityCountPostDelete).toMatchObject(matchEntityCountPostDelete);
264
262
  // Create Additional Entities -------------------------------------------------------------------------------------
@@ -270,14 +268,14 @@ describe("Test pgaccesslayer", () => {
270
268
  userId,
271
269
  userName: `${userId} name`,
272
270
  count: 2,
273
- description: `${userId} description`
271
+ description: `${userId} description`,
274
272
  };
275
273
  const entityResourceOptions = {
276
274
  filters: {
277
275
  dbactionuser,
278
276
  resname: userResourceType.name,
279
- entname: userEntity.userId
280
- }
277
+ entname: userEntity.userId,
278
+ },
281
279
  };
282
280
  const entityCreateRecord = await accessLayer.CreateEntity(entityResourceOptions, userEntity);
283
281
  expDetail.push(entityCreateRecord.detail);
@@ -293,7 +291,7 @@ describe("Test pgaccesslayer", () => {
293
291
  entname: userEntity.userId,
294
292
  validto: null,
295
293
  vnum: "1",
296
- }
294
+ },
297
295
  };
298
296
  const createdEntityRecord = entityCreateRecord.detail;
299
297
  expect(entityCreateRecord).toMatchObject(matchCreateEntity);
@@ -303,44 +301,44 @@ describe("Test pgaccesslayer", () => {
303
301
  // Get Entities (using filters) -------------------------------------------------------------------------------------
304
302
  const entities = await accessLayer.GetEntities({
305
303
  filters: {
306
- resname: 'user-t2',
307
- filter: '%'
308
- }
304
+ resname: "user-t2",
305
+ filter: "%",
306
+ },
309
307
  });
310
308
  expect(entities.detail).toMatchObject(expDetail);
311
309
  // Get Entity Count Post Delete -------------------------------------------------------------------------------------
312
310
  const entityCountOptions = {
313
311
  filters: {
314
- resname: 'user-t2'
315
- }
312
+ resname: "user-t2",
313
+ },
316
314
  };
317
315
  const entityCountPostMultiCreate = await accessLayer.GetEntityCount(entityCountOptions);
318
316
  const matchEntityCountPostMultiCreate = {
319
317
  operation: eOperations.GetEntityCount,
320
318
  options: entityCountOptions,
321
319
  status: StatusCodes.OK,
322
- detail: createCount
320
+ detail: createCount,
323
321
  };
324
322
  expect(entityCountPostMultiCreate).toMatchObject(matchEntityCountPostMultiCreate);
325
323
  }, 120000);
326
- test('Testing Database Entity Batch Create', async () => {
324
+ test("Testing Database Entity Batch Create", async () => {
327
325
  const createStart = 100;
328
326
  const createNum = 60;
329
327
  expect.assertions(180);
330
328
  for (let i = createStart; i < createStart + createNum; i++) {
331
- const userId = `user_${String(i).padStart(4, '0')}`;
329
+ const userId = `user_${String(i).padStart(4, "0")}`;
332
330
  const createUserEntity = {
333
331
  userId,
334
332
  userName: `${userId} name`,
335
333
  count: i,
336
- description: `${userId} description`
334
+ description: `${userId} description`,
337
335
  };
338
336
  const userCreateRecord = await accessLayer.CreateEntity({
339
337
  filters: {
340
338
  dbactionuser,
341
339
  resname: userResourceType.name,
342
- entname: createUserEntity.userId
343
- }
340
+ entname: createUserEntity.userId,
341
+ },
344
342
  }, createUserEntity);
345
343
  const checkObject = {
346
344
  status: StatusCodes.CREATED,
@@ -348,11 +346,11 @@ describe("Test pgaccesslayer", () => {
348
346
  entname: createUserEntity.userId,
349
347
  entvalue: createUserEntity,
350
348
  resourceoid,
351
- vnum: '1',
349
+ vnum: "1",
352
350
  validto: null,
353
351
  dbaction: edbaction.created,
354
- dbactionuser
355
- }
352
+ dbactionuser,
353
+ },
356
354
  };
357
355
  const createdRecord = userCreateRecord.detail;
358
356
  finalResults[createdRecord.entname] = createdRecord;
@@ -361,29 +359,29 @@ describe("Test pgaccesslayer", () => {
361
359
  expect(parseInt(createdRecord.oid)).toBeGreaterThan(0);
362
360
  }
363
361
  }, 120000);
364
- test('Testing Database Entity Batch Create using Update', async () => {
362
+ test("Testing Database Entity Batch Create using Update", async () => {
365
363
  const updateStart = 100;
366
364
  const updateNum = 5;
367
365
  expect.assertions(15);
368
366
  const resourceParameterPatchRecord = [];
369
367
  const testRecords = [];
370
368
  for (let i = updateStart; i < updateStart + updateNum; i++) {
371
- const userId = `user_new_${String(i).padStart(4, '0')}`;
369
+ const userId = `user_new_${String(i).padStart(4, "0")}`;
372
370
  const createFromUpdateUserEntity = {
373
371
  userId,
374
372
  userName: `${userId} name`,
375
373
  count: i,
376
- description: `${userId} description`
374
+ description: `${userId} description`,
377
375
  };
378
376
  const resourceParameterRecord = {
379
377
  opitons: {
380
378
  filters: {
381
379
  dbactionuser,
382
380
  resname: userResourceType.name,
383
- entname: createFromUpdateUserEntity.userId
384
- }
381
+ entname: createFromUpdateUserEntity.userId,
382
+ },
385
383
  },
386
- entity: createFromUpdateUserEntity
384
+ entity: createFromUpdateUserEntity,
387
385
  };
388
386
  resourceParameterPatchRecord.push(resourceParameterRecord);
389
387
  const testObject = {
@@ -395,10 +393,10 @@ describe("Test pgaccesslayer", () => {
395
393
  vnum: "1",
396
394
  validto: null,
397
395
  dbaction: edbaction.created,
398
- dbactionuser
396
+ dbactionuser,
399
397
  },
400
398
  operation: eOperations.UpdateEntities,
401
- options: {}
399
+ options: {},
402
400
  };
403
401
  testRecords.push(testObject);
404
402
  }
@@ -409,36 +407,38 @@ describe("Test pgaccesslayer", () => {
409
407
  if (retVal.length === testRecords.length) {
410
408
  for (let i = 0; i < retVal.length; i++) {
411
409
  expect(retVal[i]).toMatchObject(testRecords[i]);
412
- const updatedResourceRecord = retVal[i].detail;
413
- finalResults[updatedResourceRecord.entname] = updatedResourceRecord;
410
+ const updatedResourceRecord = retVal[i]
411
+ .detail;
412
+ finalResults[updatedResourceRecord.entname] =
413
+ updatedResourceRecord;
414
414
  expect(new Date(updatedResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
415
415
  expect(parseInt(updatedResourceRecord.oid)).toBeGreaterThan(0);
416
416
  }
417
417
  }
418
418
  }, 120000);
419
- test('Testing Database Entity Batch Update', async () => {
419
+ test("Testing Database Entity Batch Update", async () => {
420
420
  const updateStart = 100;
421
421
  const updateNum = 5;
422
422
  expect.assertions(15);
423
423
  const resourceParameterPatchRecord = [];
424
424
  const testRecords = [];
425
425
  for (let i = updateStart; i < updateStart + updateNum; i++) {
426
- const userId = `user_${String(i).padStart(4, '0')}`;
426
+ const userId = `user_${String(i).padStart(4, "0")}`;
427
427
  const createFromUpdateUserEntity = {
428
428
  userId,
429
429
  userName: `${userId} updated name`,
430
430
  count: i + 1000,
431
- description: `${userId} updated description`
431
+ description: `${userId} updated description`,
432
432
  };
433
433
  const resourceParameterRecord = {
434
434
  opitons: {
435
435
  filters: {
436
436
  dbactionuser,
437
437
  resname: userResourceType.name,
438
- entname: createFromUpdateUserEntity.userId
439
- }
438
+ entname: createFromUpdateUserEntity.userId,
439
+ },
440
440
  },
441
- entity: createFromUpdateUserEntity
441
+ entity: createFromUpdateUserEntity,
442
442
  };
443
443
  resourceParameterPatchRecord.push(resourceParameterRecord);
444
444
  const testObject = {
@@ -450,10 +450,10 @@ describe("Test pgaccesslayer", () => {
450
450
  vnum: "2",
451
451
  validto: null,
452
452
  dbaction: edbaction.updated,
453
- dbactionuser
453
+ dbactionuser,
454
454
  },
455
455
  operation: eOperations.UpdateEntities,
456
- options: {}
456
+ options: {},
457
457
  };
458
458
  testRecords.push(testObject);
459
459
  }
@@ -464,14 +464,16 @@ describe("Test pgaccesslayer", () => {
464
464
  if (retVal.length === testRecords.length) {
465
465
  for (let i = 0; i < retVal.length; i++) {
466
466
  expect(retVal[i]).toMatchObject(testRecords[i]);
467
- const updatedResourceRecord = retVal[i].detail;
468
- finalResults[updatedResourceRecord.entname] = updatedResourceRecord;
467
+ const updatedResourceRecord = retVal[i]
468
+ .detail;
469
+ finalResults[updatedResourceRecord.entname] =
470
+ updatedResourceRecord;
469
471
  expect(new Date(updatedResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
470
472
  expect(parseInt(updatedResourceRecord.oid)).toBeGreaterThan(0);
471
473
  }
472
474
  }
473
475
  }, 120000);
474
- test('Testing Database Entity Batch Update with Errors', async () => {
476
+ test("Testing Database Entity Batch Update with Errors", async () => {
475
477
  const updateErrorStart = 110;
476
478
  const updateErrorNum = 5;
477
479
  const updateErrorIndex = 112;
@@ -479,26 +481,26 @@ describe("Test pgaccesslayer", () => {
479
481
  const resourceParameterPatchRecord = [];
480
482
  const testRecords = [];
481
483
  for (let i = updateErrorStart; i < updateErrorStart + updateErrorNum; i++) {
482
- let userId = `user_${String(i).padStart(4, '0')}`;
484
+ let userId = `user_${String(i).padStart(4, "0")}`;
483
485
  if (i === updateErrorIndex) {
484
- userId = `user_error_${String(i).padStart(4, '0')}`;
486
+ userId = `user_error_${String(i).padStart(4, "0")}`;
485
487
  }
486
488
  const createFromUpdateUserEntity = {
487
489
  userId,
488
490
  userName: `${userId} updated name`,
489
491
  count: i + 1000,
490
- description: `${userId} updated description`
492
+ description: `${userId} updated description`,
491
493
  };
492
494
  const resourceParameterRecord = {
493
495
  opitons: {
494
496
  filters: {
495
497
  dbactionuser,
496
498
  resname: userResourceType.name,
497
- entname: createFromUpdateUserEntity.userId
499
+ entname: createFromUpdateUserEntity.userId,
498
500
  },
499
- errorOnBatchUpdate: true // We want errors instead of create new records
501
+ errorOnBatchUpdate: true, // We want errors instead of create new records
500
502
  },
501
- entity: createFromUpdateUserEntity
503
+ entity: createFromUpdateUserEntity,
502
504
  };
503
505
  resourceParameterPatchRecord.push(resourceParameterRecord);
504
506
  if (i === updateErrorIndex) {
@@ -509,8 +511,8 @@ describe("Test pgaccesslayer", () => {
509
511
  options: {},
510
512
  error: {
511
513
  operation: eOperations.GetEntity,
512
- status: StatusCodes.NOT_FOUND
513
- }
514
+ status: StatusCodes.NOT_FOUND,
515
+ },
514
516
  };
515
517
  testRecords.push(testObject);
516
518
  }
@@ -519,7 +521,7 @@ describe("Test pgaccesslayer", () => {
519
521
  status: StatusCodes.OK,
520
522
  detail: null,
521
523
  operation: eOperations.UpdateEntities,
522
- options: {}
524
+ options: {},
523
525
  };
524
526
  testRecords.push(testObject);
525
527
  }
@@ -532,46 +534,50 @@ describe("Test pgaccesslayer", () => {
532
534
  for (let i = 0; i < retVal.length; i++) {
533
535
  expect(retVal[i]).toMatchObject(testRecords[i]);
534
536
  if (retVal[i].error) {
535
- const updatedResourceRecordError = retVal[i].error;
536
- const entName = retVal[i].options.filters.entname;
537
+ const updatedResourceRecordError = retVal[i]
538
+ .error;
539
+ const entName = retVal[i].options.filters
540
+ .entname;
537
541
  finalResults[entName] = updatedResourceRecordError;
538
542
  expect(retVal[i].error?.errorMessage).toMatch(/\(current version\) not found/);
539
543
  }
540
544
  else {
541
- const entName = retVal[i].options.filters.entname;
545
+ const entName = retVal[i].options.filters
546
+ .entname;
542
547
  const missingResource = await accessLayer.GetEntity(retVal[i].options);
543
- finalResults[entName] = missingResource.detail;
548
+ finalResults[entName] =
549
+ missingResource.detail;
544
550
  }
545
551
  }
546
552
  }
547
553
  }, 120000);
548
- test('Testing Database Entity Batch Patch', async () => {
554
+ test("Testing Database Entity Batch Patch", async () => {
549
555
  const patchStart = 120;
550
556
  const patchNum = 5;
551
557
  expect.assertions(15);
552
558
  const resourceParameterPatchRecord = [];
553
559
  const testRecords = [];
554
560
  for (let i = patchStart; i < patchStart + patchNum; i++) {
555
- const userId = `user_${String(i).padStart(4, '0')}`;
561
+ const userId = `user_${String(i).padStart(4, "0")}`;
556
562
  const recordPatch = {
557
563
  userId,
558
- description: `${userId} patched description`
564
+ description: `${userId} patched description`,
559
565
  };
560
566
  const recordPostPatch = {
561
567
  userId,
562
568
  userName: `${userId} name`,
563
569
  count: i,
564
- description: recordPatch.description
570
+ description: recordPatch.description,
565
571
  };
566
572
  const resourceParameterRecord = {
567
573
  opitons: {
568
574
  filters: {
569
575
  dbactionuser,
570
576
  resname: userResourceType.name,
571
- entname: recordPatch.userId
572
- }
577
+ entname: recordPatch.userId,
578
+ },
573
579
  },
574
- entity: recordPatch
580
+ entity: recordPatch,
575
581
  };
576
582
  resourceParameterPatchRecord.push(resourceParameterRecord);
577
583
  const testObject = {
@@ -583,10 +589,10 @@ describe("Test pgaccesslayer", () => {
583
589
  vnum: "2",
584
590
  validto: null,
585
591
  dbaction: edbaction.updated,
586
- dbactionuser
592
+ dbactionuser,
587
593
  },
588
594
  operation: eOperations.PatchEntities,
589
- options: {}
595
+ options: {},
590
596
  };
591
597
  testRecords.push(testObject);
592
598
  }
@@ -597,14 +603,16 @@ describe("Test pgaccesslayer", () => {
597
603
  if (retVal.length === testRecords.length) {
598
604
  for (let i = 0; i < retVal.length; i++) {
599
605
  expect(retVal[i]).toMatchObject(testRecords[i]);
600
- const updatedResourceRecord = retVal[i].detail;
601
- finalResults[updatedResourceRecord.entname] = updatedResourceRecord;
606
+ const updatedResourceRecord = retVal[i]
607
+ .detail;
608
+ finalResults[updatedResourceRecord.entname] =
609
+ updatedResourceRecord;
602
610
  expect(new Date(updatedResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
603
611
  expect(parseInt(updatedResourceRecord.oid)).toBeGreaterThan(0);
604
612
  }
605
613
  }
606
614
  }, 120000);
607
- test('Testing Database Entity Batch Patch with Errors', async () => {
615
+ test("Testing Database Entity Batch Patch with Errors", async () => {
608
616
  const patchErrorStart = 130;
609
617
  const patchErrorNum = 5;
610
618
  const patchErrorIndex = 132;
@@ -612,13 +620,13 @@ describe("Test pgaccesslayer", () => {
612
620
  const resourceParameterPatchRecord = [];
613
621
  const testRecords = [];
614
622
  for (let i = patchErrorStart; i < patchErrorStart + patchErrorNum; i++) {
615
- let userId = `user_${String(i).padStart(4, '0')}`;
623
+ let userId = `user_${String(i).padStart(4, "0")}`;
616
624
  if (i === patchErrorIndex) {
617
- userId = `user_error_${String(i).padStart(4, '0')}`;
625
+ userId = `user_error_${String(i).padStart(4, "0")}`;
618
626
  }
619
627
  const recordPatch = {
620
628
  userId,
621
- description: `${userId} patched description`
629
+ description: `${userId} patched description`,
622
630
  };
623
631
  /*
624
632
  const recordPostPatch: Partial<IUserEntity> = {
@@ -632,11 +640,11 @@ describe("Test pgaccesslayer", () => {
632
640
  filters: {
633
641
  dbactionuser,
634
642
  resname: userResourceType.name,
635
- entname: recordPatch.userId
643
+ entname: recordPatch.userId,
636
644
  },
637
- errorOnBatchUpdate: true // We want errors instead of create new records
645
+ errorOnBatchUpdate: true, // We want errors instead of create new records
638
646
  },
639
- entity: recordPatch
647
+ entity: recordPatch,
640
648
  };
641
649
  resourceParameterPatchRecord.push(resourceParameterRecord);
642
650
  if (i === patchErrorIndex) {
@@ -647,8 +655,8 @@ describe("Test pgaccesslayer", () => {
647
655
  options: {},
648
656
  error: {
649
657
  operation: eOperations.GetEntity,
650
- status: StatusCodes.NOT_FOUND
651
- }
658
+ status: StatusCodes.NOT_FOUND,
659
+ },
652
660
  };
653
661
  testRecords.push(testObject);
654
662
  }
@@ -657,7 +665,7 @@ describe("Test pgaccesslayer", () => {
657
665
  status: StatusCodes.OK,
658
666
  detail: null,
659
667
  operation: eOperations.PatchEntities,
660
- options: {}
668
+ options: {},
661
669
  };
662
670
  testRecords.push(testObject);
663
671
  }
@@ -670,27 +678,31 @@ describe("Test pgaccesslayer", () => {
670
678
  for (let i = 0; i < retVal.length; i++) {
671
679
  expect(retVal[i]).toMatchObject(testRecords[i]);
672
680
  if (retVal[i].error) {
673
- const patchedResourceRecordError = retVal[i].error;
674
- const entname = retVal[i].options.filters.entname;
681
+ const patchedResourceRecordError = retVal[i]
682
+ .error;
683
+ const entname = retVal[i].options.filters
684
+ .entname;
675
685
  finalResults[entname] = patchedResourceRecordError;
676
686
  expect(retVal[i].error?.errorMessage).toMatch(/\(current version\) not found/);
677
687
  }
678
688
  else {
679
- const entname = retVal[i].options.filters.entname;
689
+ const entname = retVal[i].options.filters
690
+ .entname;
680
691
  const missingResource = await accessLayer.GetEntity(retVal[i].options);
681
- finalResults[entname] = missingResource.detail;
692
+ finalResults[entname] =
693
+ missingResource.detail;
682
694
  }
683
695
  }
684
696
  }
685
697
  }, 120000);
686
- test('Testing Database Entity Batch Delete', async () => {
698
+ test("Testing Database Entity Batch Delete", async () => {
687
699
  const deleteStart = 140;
688
700
  const deleteNum = 5;
689
701
  expect.assertions(15);
690
702
  const resourceParameterPatchRecord = [];
691
703
  const testRecords = [];
692
704
  for (let i = deleteStart; i < deleteStart + deleteNum; i++) {
693
- const userId = `user_${String(i).padStart(4, '0')}`;
705
+ const userId = `user_${String(i).padStart(4, "0")}`;
694
706
  const recordDelete = {
695
707
  userId,
696
708
  };
@@ -698,17 +710,17 @@ describe("Test pgaccesslayer", () => {
698
710
  userId,
699
711
  userName: `${userId} name`,
700
712
  count: i,
701
- description: `${userId} description`
713
+ description: `${userId} description`,
702
714
  };
703
715
  const resourceParameterRecord = {
704
716
  opitons: {
705
717
  filters: {
706
718
  dbactionuser,
707
719
  resname: userResourceType.name,
708
- entname: recordDelete.userId
709
- }
720
+ entname: recordDelete.userId,
721
+ },
710
722
  },
711
- entity: recordDelete
723
+ entity: recordDelete,
712
724
  };
713
725
  resourceParameterPatchRecord.push(resourceParameterRecord);
714
726
  const testObject = {
@@ -720,10 +732,10 @@ describe("Test pgaccesslayer", () => {
720
732
  vnum: "2",
721
733
  validto: null,
722
734
  dbaction: edbaction.deleted,
723
- dbactionuser
735
+ dbactionuser,
724
736
  },
725
737
  operation: eOperations.DeleteEntities,
726
- options: {}
738
+ options: {},
727
739
  };
728
740
  testRecords.push(testObject);
729
741
  }
@@ -734,14 +746,16 @@ describe("Test pgaccesslayer", () => {
734
746
  if (retVal.length === testRecords.length) {
735
747
  for (let i = 0; i < retVal.length; i++) {
736
748
  expect(retVal[i]).toMatchObject(testRecords[i]);
737
- const updatedResourceRecord = retVal[i].detail;
738
- finalResults[updatedResourceRecord.entname] = updatedResourceRecord;
749
+ const updatedResourceRecord = retVal[i]
750
+ .detail;
751
+ finalResults[updatedResourceRecord.entname] =
752
+ updatedResourceRecord;
739
753
  expect(new Date(updatedResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
740
754
  expect(parseInt(updatedResourceRecord.oid)).toBeGreaterThan(0);
741
755
  }
742
756
  }
743
757
  }, 120000);
744
- test('Testing Database Entity Batch Delete with Errors', async () => {
758
+ test("Testing Database Entity Batch Delete with Errors", async () => {
745
759
  const deleteErrorStart = 150;
746
760
  const deleteErrorNum = 5;
747
761
  const deleteErrorIndex = 152;
@@ -749,9 +763,9 @@ describe("Test pgaccesslayer", () => {
749
763
  const resourceParameterPatchRecord = [];
750
764
  const testRecords = [];
751
765
  for (let i = deleteErrorStart; i < deleteErrorStart + deleteErrorNum; i++) {
752
- let userId = `user_${String(i).padStart(4, '0')}`;
766
+ let userId = `user_${String(i).padStart(4, "0")}`;
753
767
  if (i === deleteErrorIndex) {
754
- userId = `user_error_${String(i).padStart(4, '0')}`;
768
+ userId = `user_error_${String(i).padStart(4, "0")}`;
755
769
  }
756
770
  const recordDelete = {
757
771
  userId,
@@ -761,11 +775,11 @@ describe("Test pgaccesslayer", () => {
761
775
  filters: {
762
776
  dbactionuser,
763
777
  resname: userResourceType.name,
764
- entname: recordDelete.userId
778
+ entname: recordDelete.userId,
765
779
  },
766
- errorOnBatchUpdate: true // We want errors instead of create new records
780
+ errorOnBatchUpdate: true, // We want errors instead of create new records
767
781
  },
768
- entity: recordDelete
782
+ entity: recordDelete,
769
783
  };
770
784
  resourceParameterPatchRecord.push(resourceParameterRecord);
771
785
  if (i === deleteErrorIndex) {
@@ -776,8 +790,8 @@ describe("Test pgaccesslayer", () => {
776
790
  options: {},
777
791
  error: {
778
792
  operation: eOperations.GetEntity,
779
- status: StatusCodes.NOT_FOUND
780
- }
793
+ status: StatusCodes.NOT_FOUND,
794
+ },
781
795
  };
782
796
  testRecords.push(testObject);
783
797
  }
@@ -786,7 +800,7 @@ describe("Test pgaccesslayer", () => {
786
800
  status: StatusCodes.OK,
787
801
  detail: null,
788
802
  operation: eOperations.DeleteEntities,
789
- options: {}
803
+ options: {},
790
804
  };
791
805
  testRecords.push(testObject);
792
806
  }
@@ -799,31 +813,35 @@ describe("Test pgaccesslayer", () => {
799
813
  for (let i = 0; i < retVal.length; i++) {
800
814
  expect(retVal[i]).toMatchObject(testRecords[i]);
801
815
  if (retVal[i].error) {
802
- const patchedResourceRecordError = retVal[i].error;
803
- const entname = retVal[i].options.filters.entname;
816
+ const patchedResourceRecordError = retVal[i]
817
+ .error;
818
+ const entname = retVal[i].options.filters
819
+ .entname;
804
820
  finalResults[entname] = patchedResourceRecordError;
805
821
  expect(retVal[i].error?.errorMessage).toMatch(/\(current version\) not found/);
806
822
  }
807
823
  else {
808
- const entname = retVal[i].options.filters.entname;
824
+ const entname = retVal[i].options.filters
825
+ .entname;
809
826
  const missingResource = await accessLayer.GetEntity(retVal[i].options);
810
- finalResults[entname] = missingResource.detail;
827
+ finalResults[entname] =
828
+ missingResource.detail;
811
829
  }
812
830
  }
813
831
  }
814
832
  }, 120000);
815
- test('Get All user_patch_test_ Resources', async () => {
833
+ test("Get All user_patch_test_ Resources", async () => {
816
834
  expect.assertions(51);
817
835
  // All Records
818
836
  const AllRecords = await accessLayer.GetEntities({
819
837
  filters: {
820
838
  resname: userResourceType.name,
821
- filter: 'user_%',
822
- limit: '50'
823
- }
839
+ filter: "user_%",
840
+ limit: "50",
841
+ },
824
842
  });
825
843
  expect(AllRecords.detail.length).toEqual(50);
826
- AllRecords.detail.forEach(u => {
844
+ AllRecords.detail.forEach((u) => {
827
845
  const compareObject = finalResults[u.entname];
828
846
  if (compareObject) {
829
847
  expect(u).toMatchObject(compareObject);
@@ -833,42 +851,46 @@ describe("Test pgaccesslayer", () => {
833
851
  // Output formatted table
834
852
  const columns = [
835
853
  {
836
- name: 'userId',
854
+ name: "userId",
837
855
  width: 30,
838
856
  left: true,
839
- field: 'userId'
857
+ field: "userId",
840
858
  },
841
859
  {
842
- name: 'userName',
860
+ name: "userName",
843
861
  width: 30,
844
862
  left: true,
845
- field: 'userName'
863
+ field: "userName",
846
864
  },
847
865
  {
848
- name: 'description',
866
+ name: "description",
849
867
  width: 50,
850
868
  left: true,
851
- field: 'description'
869
+ field: "description",
852
870
  },
853
871
  {
854
- name: 'count',
872
+ name: "count",
855
873
  width: 10,
856
874
  left: false,
857
- field: 'count'
858
- }
875
+ field: "count",
876
+ },
859
877
  ];
860
- let header = '';
878
+ let header = "";
861
879
  let length = 0;
862
- columns.forEach(c => {
863
- header += (c.left ? c.name.padEnd(c.width) : c.name.padStart(c.width));
880
+ columns.forEach((c) => {
881
+ header += c.left
882
+ ? c.name.padEnd(c.width)
883
+ : c.name.padStart(c.width);
864
884
  length += c.width;
865
885
  });
866
886
  console.log(header);
867
- console.log('-'.repeat(length));
868
- AllRecords.detail.forEach(u => {
869
- let detail = '';
870
- columns.forEach(c => {
871
- detail += (c.left ? u.entvalue[c.field].toString().padEnd(c.width) : u.entvalue[c.field].toString().padStart(c.width));
887
+ console.log("-".repeat(length));
888
+ AllRecords.detail.forEach((u) => {
889
+ let detail = "";
890
+ columns.forEach((c) => {
891
+ detail += c.left
892
+ ? u.entvalue[c.field].toString().padEnd(c.width)
893
+ : u.entvalue[c.field].toString().padStart(c.width);
872
894
  });
873
895
  console.log(detail);
874
896
  });