@futdevpro/nts-dynamo 1.10.6 → 1.10.8

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 (73) hide show
  1. package/build/_collections/stack.util.d.ts +7 -0
  2. package/build/_collections/stack.util.d.ts.map +1 -0
  3. package/build/_collections/stack.util.js +31 -0
  4. package/build/_collections/stack.util.js.map +1 -0
  5. package/build/_collections/stack.util.test.d.ts +2 -0
  6. package/build/_collections/stack.util.test.d.ts.map +1 -0
  7. package/build/_collections/stack.util.test.js +96 -0
  8. package/build/_collections/stack.util.test.js.map +1 -0
  9. package/build/_models/control-models/api-call-params.control-model.d.ts +4 -30
  10. package/build/_models/control-models/api-call-params.control-model.d.ts.map +1 -1
  11. package/build/_models/control-models/api-call-params.control-model.js +30 -13
  12. package/build/_models/control-models/api-call-params.control-model.js.map +1 -1
  13. package/build/_models/control-models/api-call-params.control-model.spec.js +6 -6
  14. package/build/_models/control-models/endpoint-params.control-model.d.ts +0 -1
  15. package/build/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
  16. package/build/_models/control-models/endpoint-params.control-model.js +26 -13
  17. package/build/_models/control-models/endpoint-params.control-model.js.map +1 -1
  18. package/build/_modules/mock/data-model.mock.d.ts.map +1 -1
  19. package/build/_modules/mock/data-model.mock.js +0 -1
  20. package/build/_modules/mock/data-model.mock.js.map +1 -1
  21. package/build/_modules/mock/data-model.mock.spec.js +0 -1
  22. package/build/_modules/mock/data-model.mock.spec.js.map +1 -1
  23. package/build/_modules/socket/_services/socket-client.service.d.ts +1 -1
  24. package/build/_modules/socket/_services/socket-client.service.d.ts.map +1 -1
  25. package/build/_modules/socket/_services/socket-client.service.js.map +1 -1
  26. package/build/_modules/socket/_services/socket-server.service.d.ts.map +1 -1
  27. package/build/_modules/socket/_services/socket-server.service.js +46 -10
  28. package/build/_modules/socket/_services/socket-server.service.js.map +1 -1
  29. package/build/_modules/socket/app-extended.server.d.ts.map +1 -1
  30. package/build/_modules/socket/app-extended.server.js +11 -2
  31. package/build/_modules/socket/app-extended.server.js.map +1 -1
  32. package/build/_modules/test/test.controller.js +6 -6
  33. package/build/_modules/test/test.controller.js.map +1 -1
  34. package/build/_services/base/data.service.d.ts.map +1 -1
  35. package/build/_services/base/data.service.js +9 -1
  36. package/build/_services/base/data.service.js.map +1 -1
  37. package/build/_services/base/db.service.d.ts.map +1 -1
  38. package/build/_services/base/db.service.js +42 -39
  39. package/build/_services/base/db.service.js.map +1 -1
  40. package/build/_services/core/api.service.d.ts +1 -1
  41. package/build/_services/core/api.service.d.ts.map +1 -1
  42. package/build/_services/core/api.service.js +29 -12
  43. package/build/_services/core/api.service.js.map +1 -1
  44. package/build/_services/core/api.service.spec.js +4 -3
  45. package/build/_services/core/api.service.spec.js.map +1 -1
  46. package/build/_services/core/global.service.d.ts.map +1 -1
  47. package/build/_services/core/global.service.js +2 -1
  48. package/build/_services/core/global.service.js.map +1 -1
  49. package/build/_services/server/app.server.js +5 -5
  50. package/build/_services/server/app.server.js.map +1 -1
  51. package/build/index.d.ts +2 -0
  52. package/build/index.d.ts.map +1 -1
  53. package/build/index.js +2 -0
  54. package/build/index.js.map +1 -1
  55. package/package.json +4 -4
  56. package/src/_collections/stack.util.test.ts +111 -0
  57. package/src/_collections/stack.util.ts +33 -0
  58. package/src/_models/control-models/api-call-params.control-model.spec.ts +6 -6
  59. package/src/_models/control-models/api-call-params.control-model.ts +44 -43
  60. package/src/_models/control-models/endpoint-params.control-model.ts +26 -19
  61. package/src/_modules/mock/data-model.mock.spec.ts +0 -1
  62. package/src/_modules/mock/data-model.mock.ts +0 -1
  63. package/src/_modules/socket/_services/socket-client.service.ts +1 -1
  64. package/src/_modules/socket/_services/socket-server.service.ts +65 -21
  65. package/src/_modules/socket/app-extended.server.ts +21 -6
  66. package/src/_modules/test/test.controller.ts +7 -7
  67. package/src/_services/base/data.service.ts +21 -1
  68. package/src/_services/base/db.service.ts +47 -39
  69. package/src/_services/core/api.service.spec.ts +3 -3
  70. package/src/_services/core/api.service.ts +37 -15
  71. package/src/_services/core/global.service.ts +4 -1
  72. package/src/_services/server/app.server.ts +7 -7
  73. package/src/index.ts +2 -0
@@ -23,7 +23,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
23
23
 
24
24
  serviceName: string;
25
25
 
26
- dataModel/* : mongoose.Model<T> */; // = mongoose.model(this.dataParams.dbName, this.getSchema());
26
+ dataModel/* : mongoose.Model<T> */; // = mongoose.model(this.dataParams.dataName, this.getSchema());
27
27
 
28
28
  private depDataName: string;
29
29
 
@@ -43,11 +43,17 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
43
43
  try {
44
44
  this.serviceName = this.constructor?.name;
45
45
 
46
+ if (!this.dataParams.dataName) {
47
+ throw new Error(
48
+ `dbName not setted up for this db-service (${this.dataParams.dataName}) (NTS DB)`
49
+ );
50
+ }
51
+
46
52
  try {
47
- this.dataModel = mongoose.model(this.dataParams.dbName, this.getSchema());
53
+ this.dataModel = mongoose.model(this.dataParams.dataName, this.getSchema());
48
54
  } catch (error) {
49
- if (mongoose.models[this.dataParams.dbName]) {
50
- this.dataModel = mongoose.models[this.dataParams.dbName];
55
+ if (mongoose.models[this.dataParams.dataName]) {
56
+ this.dataModel = mongoose.models[this.dataParams.dataName];
51
57
  } else {
52
58
  throw error;
53
59
  }
@@ -87,7 +93,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
87
93
  ...this._getDefaultErrorSettings(
88
94
  'createData',
89
95
  new Error(
90
- `createData failed, save "${this.dataParams.dbName}" result not found! (NTS DB)`
96
+ `createData failed, save "${this.dataParams.dataName}" result not found! (NTS DB)`
91
97
  ),
92
98
  issuer
93
99
  ),
@@ -109,7 +115,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
109
115
  dataModel: this.dataModel,
110
116
  },
111
117
  message:
112
- `createData failed, Create new "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
118
+ `createData failed, Create new "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
113
119
  issuer,
114
120
  });
115
121
  }
@@ -141,7 +147,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
141
147
  throw new DyFM_Error({
142
148
  ...this._getDefaultErrorSettings(
143
149
  'modifyData',
144
- new Error(`modifyData failed, modify "${this.dataParams.dbName}" result not found! (NTS DB)`),
150
+ new Error(`modifyData failed, modify "${this.dataParams.dataName}" result not found! (NTS DB)`),
145
151
  issuer,
146
152
  ),
147
153
 
@@ -156,7 +162,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
156
162
  ...this._getDefaultErrorSettings('modifyData', error, issuer),
157
163
  errorCode: 'NTS-DBS-FU0',
158
164
  additionalContent: { data },
159
- message: `modifyData "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
165
+ message: `modifyData "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
160
166
  issuer,
161
167
  });
162
168
  });
@@ -175,7 +181,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
175
181
  ...this._getDefaultErrorSettings('getDataById', new Error(`No ID provided! (NTS DB)`)),
176
182
 
177
183
  errorCode: 'NTS-DBS-GI1',
178
- message: `get "${this.dataParams.dbName}" by ID was unsuccessful (NTS DB)`,
184
+ message: `get "${this.dataParams.dataName}" by ID was unsuccessful (NTS DB)`,
179
185
  });
180
186
  }
181
187
 
@@ -187,7 +193,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
187
193
  ...this._getDefaultErrorSettings('getDataById', error),
188
194
  errorCode: 'NTS-DBS-GI0',
189
195
  additionalContent: { id },
190
- message: `get "${this.dataParams.dbName}" by ID was unsuccessful (NTS DB)`,
196
+ message: `get "${this.dataParams.dataName}" by ID was unsuccessful (NTS DB)`,
191
197
  });
192
198
  });
193
199
 
@@ -207,7 +213,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
207
213
  ...this._getDefaultErrorSettings(
208
214
  'getDataByDependencyId',
209
215
  new Error(
210
- `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) ` +
216
+ `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dataName}) ` +
211
217
  `(NTS DB)`
212
218
  )
213
219
  ),
@@ -225,7 +231,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
225
231
  errorCode: 'NTS-DBS-GD1',
226
232
  additionalContent: { dependencyId },
227
233
  message:
228
- `get "${this.dataParams.dbName}" by ${this.depDataName} was unsuccessful (NTS DB)`,
234
+ `get "${this.dataParams.dataName}" by ${this.depDataName} was unsuccessful (NTS DB)`,
229
235
  });
230
236
  });
231
237
 
@@ -245,7 +251,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
245
251
  ...this._getDefaultErrorSettings(
246
252
  'getDataListByDependencyId',
247
253
  new Error(
248
- `isDependencyHook not setted up for this dataModel (${this.dataParams.dbName}) ` +
254
+ `isDependencyHook not setted up for this dataModel (${this.dataParams.dataName}) ` +
249
255
  `(NTS DB)`
250
256
  )
251
257
  ),
@@ -267,7 +273,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
267
273
  errorCode: 'NTS-DBS-GLD1',
268
274
  additionalContent: { dependencyId },
269
275
  message:
270
- `get "${this.dataParams.dbName}" by ${this.depDataName} was unsuccessful (NTS DB)`,
276
+ `get "${this.dataParams.dataName}" by ${this.depDataName} was unsuccessful (NTS DB)`,
271
277
  });
272
278
  });
273
279
 
@@ -292,7 +298,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
292
298
  'getDataListByDependencyIds',
293
299
  new Error(
294
300
  `getDataListByDependencyIds not setted up for this db-service ` +
295
- `(${this.dataParams.dbName}) (NTS DB)`
301
+ `(${this.dataParams.dataName}) (NTS DB)`
296
302
  )
297
303
  ),
298
304
  errorCode: 'NTS-DBS-GLDS0',
@@ -310,7 +316,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
310
316
  errorCode: 'NTS-DBS-GLDS1',
311
317
  additionalContent: { dependencyIds },
312
318
  message:
313
- `get "${this.dataParams.dbName}" by ${this.depDataName} was unsuccessful (NTS DB)`,
319
+ `get "${this.dataParams.dataName}" by ${this.depDataName} was unsuccessful (NTS DB)`,
314
320
  });
315
321
  });
316
322
 
@@ -336,7 +342,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
336
342
  ...this._getDefaultErrorSettings('getAll', error),
337
343
 
338
344
  errorCode: 'NTS-DBS-GA0',
339
- message: `get all "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
345
+ message: `get all "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
340
346
  });
341
347
  });
342
348
 
@@ -362,7 +368,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
362
368
 
363
369
  errorCode: 'NTS-DBS-MD0',
364
370
  additionalContent: { id },
365
- message: `mark deleted "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
371
+ message: `mark deleted "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
366
372
  issuer,
367
373
  });
368
374
  }
@@ -382,7 +388,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
382
388
  errorCode: 'NTS-DBS-MDD0',
383
389
  additionalContent: { dependencyId },
384
390
  message:
385
- `markDeleted "${this.dataParams.dbName}" by ${this.depDataName} was unsuccessful ` +
391
+ `markDeleted "${this.dataParams.dataName}" by ${this.depDataName} was unsuccessful ` +
386
392
  `(NTS DB)`,
387
393
  issuer,
388
394
  });
@@ -403,7 +409,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
403
409
  ...this._getDefaultErrorSettings('restoreDeletedById', error, issuer),
404
410
  errorCode: 'NTS-DBS-RD0',
405
411
  additionalContent: { id },
406
- message: `restoreDeleted "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
412
+ message: `restoreDeleted "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
407
413
  issuer,
408
414
  });
409
415
  });
@@ -423,7 +429,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
423
429
  errorCode: 'NTS-DBS-RDD0',
424
430
  additionalContent: { dependencyId },
425
431
  message:
426
- `restoreDeleted "${this.dataParams.dbName}" by ${this.depDataName} was unsuccessful ` +
432
+ `restoreDeleted "${this.dataParams.dataName}" by ${this.depDataName} was unsuccessful ` +
427
433
  `(NTS DB)`,
428
434
  issuer,
429
435
  });
@@ -438,7 +444,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
438
444
  throw new DyFM_Error({
439
445
  ...this._getDefaultErrorSettings('getDeletedData', error),
440
446
  errorCode: 'NTS-DBS-GDD0',
441
- message: `get deleted "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
447
+ message: `get deleted "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
442
448
  });
443
449
  });
444
450
 
@@ -459,7 +465,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
459
465
  ...this._getDefaultErrorSettings('deleteDataById', error),
460
466
  errorCode: 'NTS-DBS-DD0',
461
467
  additionalContent: { id },
462
- message: `delete "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
468
+ message: `delete "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
463
469
  });
464
470
  });
465
471
  }
@@ -474,7 +480,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
474
480
  ...this._getDefaultErrorSettings(
475
481
  'deleteDataByDependencyId',
476
482
  new Error(
477
- `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) ` +
483
+ `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dataName}) ` +
478
484
  `(NTS DB)`
479
485
  )
480
486
  ),
@@ -490,7 +496,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
490
496
  errorCode: 'NTS-DBS-DDD1',
491
497
  additionalContent: { dependencyId },
492
498
  message:
493
- `delete "${this.dataParams.dbName}" by ${this.depDataName} was unsuccessful (NTS DB)`,
499
+ `delete "${this.dataParams.dataName}" by ${this.depDataName} was unsuccessful (NTS DB)`,
494
500
  });
495
501
  });
496
502
  }
@@ -500,7 +506,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
500
506
  throw new DyFM_Error({
501
507
  ...this._getDefaultErrorSettings('deleteAllData', error),
502
508
  errorCode: 'NTS-DBS-DAD0',
503
- message: `delete all "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
509
+ message: `delete all "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
504
510
  });
505
511
  });
506
512
  }
@@ -525,7 +531,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
525
531
  ...this._getDefaultErrorSettings(
526
532
  'searchData',
527
533
  new Error(
528
- `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) ` +
534
+ `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dataName}) ` +
529
535
  `(NTS DB)`
530
536
  )
531
537
  ),
@@ -602,7 +608,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
602
608
  ...this._getDefaultErrorSettings('searchData', error),
603
609
  errorCode: 'NTS-DBS-SD1',
604
610
  additionalContent: { filterBy, narrowByDependencyIds },
605
- message: `search "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
611
+ message: `search "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
606
612
  });
607
613
  });
608
614
 
@@ -653,7 +659,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
653
659
  ...this._getDefaultErrorSettings('findOne', error),
654
660
  errorCode: 'NTS-DBS-FO0',
655
661
  additionalContent: { filterBy },
656
- message: `findOne "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
662
+ message: `findOne "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
657
663
  });
658
664
  });
659
665
 
@@ -696,7 +702,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
696
702
  ...this._getDefaultErrorSettings('find', error),
697
703
  errorCode: 'NTS-DBS-F0',
698
704
  additionalContent: { filterBy },
699
- message: `find "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
705
+ message: `find "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
700
706
  });
701
707
  });
702
708
 
@@ -762,7 +768,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
762
768
  ...this._getDefaultErrorSettings('findWithPaging', error),
763
769
  errorCode: 'NTS-DBS-WP0',
764
770
  additionalContent: { filterBy, page, pageSize, sort },
765
- message: `findWithPaging "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
771
+ message: `findWithPaging "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
766
772
  });
767
773
  });
768
774
 
@@ -800,7 +806,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
800
806
  ...this._getDefaultErrorSettings('findByIdAndUpdate', error, issuer),
801
807
  errorCode: 'NTS-DBS-FIU0',
802
808
  additionalContent: { id, update },
803
- message: `findByIdAndUpdate "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
809
+ message: `findByIdAndUpdate "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
804
810
  issuer,
805
811
  });
806
812
  });
@@ -878,7 +884,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
878
884
  ...this._getDefaultErrorSettings('updateOne', error, issuer),
879
885
  errorCode: 'NTS-DBS-UO0',
880
886
  additionalContent: { filterBy, update },
881
- message: `updateOne "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
887
+ message: `updateOne "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
882
888
  issuer,
883
889
  });
884
890
  });
@@ -953,7 +959,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
953
959
  ...this._getDefaultErrorSettings('updateMany', error, issuer),
954
960
  errorCode: 'NTS-DBS-UM0',
955
961
  additionalContent: { filterBy, update },
956
- message: `updateMany "${this.dataParams.dbName}" was unsuccessful (NTS DB)`,
962
+ message: `updateMany "${this.dataParams.dataName}" was unsuccessful (NTS DB)`,
957
963
  issuer,
958
964
  });
959
965
  });
@@ -1045,7 +1051,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
1045
1051
 
1046
1052
  Object.values(properties).forEach((property: DyFM_DataProperty_Params<any>): void => {
1047
1053
  if (!property) {
1048
- DyFM_Log.warn(`property is undefined on ${this.dataParams.dbName} (NTS DB)`);
1054
+ DyFM_Log.warn(`property is undefined on ${this.dataParams.dataName} (NTS DB)`);
1049
1055
 
1050
1056
  return;
1051
1057
  }
@@ -1055,7 +1061,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
1055
1061
  ...this._getDefaultErrorSettings(
1056
1062
  'buildMongooseSchemaByModelParams',
1057
1063
  new Error(
1058
- `property.key is undefined on ${this.dataParams.dbName} (NTS DB)` +
1064
+ `property.key is undefined on ${this.dataParams.dataName} (NTS DB)` +
1059
1065
  `(keys: ${Object.keys(properties)})`
1060
1066
  )
1061
1067
  ),
@@ -1227,19 +1233,21 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
1227
1233
  private lookForDependencyDataSettings(): void {
1228
1234
  const dependencyParam: DyFM_DataProperty_Params<any> =
1229
1235
  Object.values(this.dataParams.properties).find(
1230
- (modelParams: DyFM_DataProperty_Params<any>): boolean => modelParams.isDependencyHook
1236
+ (modelParams: DyFM_DataProperty_Params<any>): boolean =>
1237
+ Boolean(modelParams.dependencyDataName)
1231
1238
  );
1232
1239
 
1233
1240
  if (
1234
1241
  Object.values(this.dataParams.properties).filter(
1235
- (modelParams: DyFM_DataProperty_Params<any>): boolean => modelParams.isDependencyHook
1242
+ (modelParams: DyFM_DataProperty_Params<any>): boolean =>
1243
+ Boolean(modelParams.dependencyDataName)
1236
1244
  ).length > 1
1237
1245
  ) {
1238
1246
  throw new DyFM_Error({
1239
1247
  ...this._getDefaultErrorSettings(
1240
1248
  'lookForDependencyDataSettings',
1241
1249
  new Error(
1242
- `Multiple "isDependencyHook" found for this dataModel (${this.dataParams.dbName}) ` +
1250
+ `Multiple "dependencyDataName" found for this dataModel (${this.dataParams.dataName}) ` +
1243
1251
  `(NTS DB)` +
1244
1252
  `\nSorry, but this is not supported yet! (Donate to Dynamo to get this feature!)`
1245
1253
  )
@@ -11,9 +11,9 @@ describe('DyNTS_ApiService', () => {
11
11
  let inputParams: DyNTS_ApiCallInput_Params;
12
12
 
13
13
  beforeEach(() => {
14
- callParams = {
14
+ callParams = new DyNTS_ApiCall_Params({
15
15
  baseUrl: 'http://example.com',
16
- endPoint: '/api/test',
16
+ endpoint: '/api/test',
17
17
  type: DyFM_HttpCallType.get,
18
18
  httpOptions: {
19
19
  headers: {},
@@ -21,7 +21,7 @@ describe('DyNTS_ApiService', () => {
21
21
  },
22
22
  name: 'Test API Call',
23
23
  getFullResponse: false,
24
- };
24
+ });
25
25
 
26
26
  inputParams = {
27
27
  pathParams: { id: '123' },
@@ -30,7 +30,7 @@ export interface DyNTS_ApiCallInput_Params<T_Body = any> {
30
30
  */
31
31
  export class DyNTS_ApiService {
32
32
 
33
- static defaultErrorUserMsg =
33
+ static readonly defaultErrorUserMsg =
34
34
  `We encountered a BackEnd API Error, ` +
35
35
  `\nplease contact the responsible development team.\n` +
36
36
  `\n(Internal BE to BE error)`;
@@ -54,11 +54,27 @@ export class DyNTS_ApiService {
54
54
  */
55
55
  inputParams?: DyNTS_ApiCallInput_Params<T_Body>
56
56
  ): Promise<T_Response /* | Axios.AxiosResponse */> {
57
+ let url: string;
58
+
57
59
  try {
58
60
  let a: T_Response;
59
- let url: string = callParams.baseUrl + callParams.endPoint;
61
+ url = callParams.baseUrl + callParams.endpoint;
60
62
  const axios = Axios.default.create();
61
63
 
64
+ if (callParams.pathParamKeys.length) {
65
+ callParams.pathParamKeys.forEach(key => {
66
+ if (!inputParams?.pathParams?.[key]) {
67
+ throw new DyFM_Error({
68
+ ...this._getDefaultErrorSettings(
69
+ 'startApiCall',
70
+ new Error(`missing pathParam: "${key}"`)
71
+ ),
72
+ errorCode: 'NTS-API-SAC1',
73
+ });
74
+ }
75
+ });
76
+ }
77
+
62
78
  if (callParams?.httpOptions?.headers) {
63
79
  this.setupHeaders(callParams, axios);
64
80
  }
@@ -128,7 +144,7 @@ export class DyNTS_ApiService {
128
144
  return a as T_Response;
129
145
  } */
130
146
  } catch (error) {
131
- this.handleError<T_Body>(callParams, error, inputParams);
147
+ this.handleError<T_Body>(callParams, error, inputParams, url);
132
148
  }
133
149
  }
134
150
 
@@ -165,15 +181,18 @@ export class DyNTS_ApiService {
165
181
  * api call's body
166
182
  */
167
183
  body?: T_Body;
168
- }
184
+ },
185
+ url: string
169
186
  ): void {
170
- DyFM_Log.error(
171
- `\n---> API ERROR: '${callParams?.name}' failed...` +
172
- `\n${callParams?.baseUrl}${callParams?.endPoint}`
173
- );
187
+ let msg: string =
188
+ `\n---> API ERROR: "${callParams?.name}" failed...` +
189
+ `\n endpoint: ${callParams?.type} "${callParams?.baseUrl}${callParams?.endpoint}"` +
190
+ `\n BE-BE requestStackLocation: "${callParams.stack}"`;
174
191
 
175
192
  if (DyNTS_global_settings.log_settings.detailedErrors) {
176
- DyFM_Log.error(`\ncallParams:`, callParams);
193
+ DyFM_Log.error(`${msg}\ncallParams:`, callParams);
194
+ } else {
195
+ DyFM_Log.error(msg);
177
196
  }
178
197
 
179
198
  if (error && callParams?.httpOptions?.responseType === DyFM_HttpResponseType.text) {
@@ -189,8 +208,10 @@ export class DyNTS_ApiService {
189
208
  error.response.data
190
209
  ),
191
210
 
192
- errorCode: 'NTS-API-SAC1',
193
- message: 'API call failed on the other end! error response found...',
211
+ errorCode: 'NTS-API-HE1',
212
+ message:
213
+ `API call "${callParams.name}" failed on the other end! error response found...`,
214
+ error: error.response.data,
194
215
  additionalContent: {
195
216
  callParams,
196
217
  inputParams,
@@ -207,7 +228,7 @@ export class DyNTS_ApiService {
207
228
  ),
208
229
 
209
230
  status: 404,
210
- errorCode: 'NTS-API-SAC2',
231
+ errorCode: 'NTS-API-HE2',
211
232
  message: 'DNS error; address cannot be resolved!',
212
233
  additionalContent: {
213
234
  callParams,
@@ -225,11 +246,12 @@ export class DyNTS_ApiService {
225
246
  ),
226
247
 
227
248
  status: 404,
228
- errorCode: 'NTS-API-SAC3',
229
- message: `Can't connect to the endpoint!`,
249
+ errorCode: 'NTS-API-HE3',
250
+ message: `Can't connect to the endpoint! ${callParams.type} "${url}"`,
230
251
  additionalContent: {
231
252
  callParams,
232
253
  inputParams,
254
+ url,
233
255
  },
234
256
  });
235
257
 
@@ -242,7 +264,7 @@ export class DyNTS_ApiService {
242
264
  ),
243
265
 
244
266
  status: +error.message.substring(error.message.length - 4, 3),
245
- errorCode: 'NTS-API-SAC4',
267
+ errorCode: 'NTS-API-HE4',
246
268
  additionalContent: {
247
269
  callParams,
248
270
  inputParams,
@@ -126,7 +126,10 @@ export class DyNTS_GlobalService extends DyNTS_SingletonService {
126
126
  throw new DyFM_Error({
127
127
  ...this.getDefaultErrorSettings(
128
128
  'setDBServices',
129
- new Error(`dbModel is not constructed!`),
129
+ new Error(
130
+ `dbModel is not constructed!` +
131
+ `\n use new DyFM_DataModel_Params() to properly construct it.`
132
+ ),
130
133
  'DyNTS_GlobalService'
131
134
  ),
132
135
 
@@ -315,19 +315,19 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
315
315
  }
316
316
 
317
317
  if (
318
- DyNTS_global_settings.log_settings.highDetailedLogs ||
319
- !(error instanceof DyFM_Error)
318
+ !DyNTS_global_settings.log_settings.highDetailedLogs &&
319
+ (error instanceof DyFM_Error)
320
320
  ) {
321
- DyFM_Log.H_error(
322
- `Application: "${this.params?.name}" start failed. (constructor asyncConstruct.catch)`,
323
- `\n ERROR:`, error
324
- );
325
- } else {
326
321
  error.logSimple(
327
322
  `Application: "${this.params?.name}" start failed. (constructor asyncConstruct.catch)` +
328
323
  '\n all error messages (from this stack):\n\n"' +
329
324
  error._messages.join('"\n\n"') + '"\n\n'
330
325
  );
326
+ } else if (error instanceof DyFM_Error) {
327
+ DyFM_Log.H_error(
328
+ `Application: "${this.params?.name}" start failed. (constructor asyncConstruct.catch)`,
329
+ `\n ERROR:`, error
330
+ );
331
331
  }
332
332
  });
333
333
  }
package/src/index.ts CHANGED
@@ -1,6 +1,8 @@
1
1
 
2
2
  // COLLECTIONS
3
+ export * from './_collections/archive.util';
3
4
  export * from './_collections/global-settings.const';
5
+ export * from './_collections/stack.util';
4
6
 
5
7
 
6
8
  // ENUMS