@futdevpro/nts-dynamo 1.5.69 → 1.5.73

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 (80) hide show
  1. package/lib/_models/dynamo-nts-api-call-params.d.ts.map +1 -1
  2. package/lib/_models/dynamo-nts-api-call-params.js +3 -1
  3. package/lib/_models/dynamo-nts-api-call-params.js.map +1 -1
  4. package/lib/_models/dynamo-nts-app-params.js +3 -2
  5. package/lib/_models/dynamo-nts-app-params.js.map +1 -1
  6. package/lib/_models/dynamo-nts-endpoint-params.d.ts.map +1 -1
  7. package/lib/_models/dynamo-nts-endpoint-params.js +12 -8
  8. package/lib/_models/dynamo-nts-endpoint-params.js.map +1 -1
  9. package/lib/_modules/constants.index.d.ts +2 -0
  10. package/lib/_modules/constants.index.d.ts.map +1 -0
  11. package/lib/_modules/constants.index.js +5 -0
  12. package/lib/_modules/constants.index.js.map +1 -0
  13. package/lib/_modules/custom-data-module.index.d.ts +2 -0
  14. package/lib/_modules/custom-data-module.index.d.ts.map +1 -0
  15. package/lib/_modules/custom-data-module.index.js +5 -0
  16. package/lib/_modules/custom-data-module.index.js.map +1 -0
  17. package/lib/_modules/enums.index.d.ts +2 -0
  18. package/lib/_modules/enums.index.d.ts.map +1 -0
  19. package/lib/_modules/enums.index.js +5 -0
  20. package/lib/_modules/enums.index.js.map +1 -0
  21. package/lib/_modules/models.index.d.ts +2 -0
  22. package/lib/_modules/models.index.d.ts.map +1 -0
  23. package/lib/_modules/models.index.js +5 -0
  24. package/lib/_modules/models.index.js.map +1 -0
  25. package/lib/_modules/services.index.d.ts +2 -0
  26. package/lib/_modules/services.index.d.ts.map +1 -0
  27. package/lib/_modules/services.index.js +5 -0
  28. package/lib/_modules/services.index.js.map +1 -0
  29. package/lib/_modules/test/test.controller.d.ts.map +1 -1
  30. package/lib/_modules/test/test.controller.js +4 -1
  31. package/lib/_modules/test/test.controller.js.map +1 -1
  32. package/lib/_modules/test-module.index.d.ts +2 -0
  33. package/lib/_modules/test-module.index.d.ts.map +1 -0
  34. package/lib/_modules/test-module.index.js +5 -0
  35. package/lib/_modules/test-module.index.js.map +1 -0
  36. package/lib/_modules/usage-module.index.d.ts +2 -0
  37. package/lib/_modules/usage-module.index.d.ts.map +1 -0
  38. package/lib/_modules/usage-module.index.js +5 -0
  39. package/lib/_modules/usage-module.index.js.map +1 -0
  40. package/lib/_services/dynamo-nts-api.service.js +1 -1
  41. package/lib/_services/dynamo-nts-api.service.js.map +1 -1
  42. package/lib/_services/dynamo-nts-app-extended.d.ts +5 -1
  43. package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
  44. package/lib/_services/dynamo-nts-app-extended.js +6 -4
  45. package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
  46. package/lib/_services/dynamo-nts-app.d.ts +46 -37
  47. package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
  48. package/lib/_services/dynamo-nts-app.js +67 -39
  49. package/lib/_services/dynamo-nts-app.js.map +1 -1
  50. package/lib/_services/dynamo-nts-data.service.d.ts +2 -0
  51. package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
  52. package/lib/_services/dynamo-nts-data.service.js +45 -47
  53. package/lib/_services/dynamo-nts-data.service.js.map +1 -1
  54. package/lib/_services/dynamo-nts-db.service.d.ts +10 -11
  55. package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
  56. package/lib/_services/dynamo-nts-db.service.js +76 -224
  57. package/lib/_services/dynamo-nts-db.service.js.map +1 -1
  58. package/lib/_services/dynamo-nts-global.service.d.ts +22 -14
  59. package/lib/_services/dynamo-nts-global.service.d.ts.map +1 -1
  60. package/lib/_services/dynamo-nts-global.service.js +7 -0
  61. package/lib/_services/dynamo-nts-global.service.js.map +1 -1
  62. package/lib/tsconfig.tsbuildinfo +1 -1
  63. package/package.json +2 -2
  64. package/src/_models/dynamo-nts-api-call-params.ts +5 -1
  65. package/src/_models/dynamo-nts-app-params.ts +2 -2
  66. package/src/_models/dynamo-nts-endpoint-params.ts +22 -8
  67. package/src/_modules/constants.index.ts +2 -0
  68. package/src/_modules/custom-data-module.index.ts +2 -0
  69. package/src/_modules/enums.index.ts +2 -0
  70. package/src/_modules/models.index.ts +2 -0
  71. package/src/_modules/services.index.ts +2 -0
  72. package/src/_modules/test/test.controller.ts +4 -1
  73. package/src/_modules/test-module.index.ts +2 -0
  74. package/src/_modules/usage-module.index.ts +2 -0
  75. package/src/_services/dynamo-nts-api.service.ts +1 -1
  76. package/src/_services/dynamo-nts-app-extended.ts +11 -4
  77. package/src/_services/dynamo-nts-app.ts +131 -76
  78. package/src/_services/dynamo-nts-data.service.ts +54 -49
  79. package/src/_services/dynamo-nts-db.service.ts +92 -229
  80. package/src/_services/dynamo-nts-global.service.ts +30 -18
@@ -0,0 +1,2 @@
1
+
2
+ export * from '../_models';
@@ -0,0 +1,2 @@
1
+
2
+ export * from '../_services';
@@ -4,6 +4,7 @@ import { testModuleSettings } from '@futdevpro/fsm-dynamo/test-module';
4
4
  import { HttpCallType } from '../../_enums/http/http-call-type.enum';
5
5
  import { DynamoNTS_EndpointParams } from '../../_models/dynamo-nts-endpoint-params';
6
6
  import { DynamoNTS_Controller } from '../../_services/dynamo-nts-controller.service';
7
+ import { DynamoNTS_GlobalService } from '../app-extended.index';
7
8
 
8
9
  export class TestController extends DynamoNTS_Controller {
9
10
 
@@ -97,7 +98,9 @@ export class TestController extends DynamoNTS_Controller {
97
98
  async (req: Request, res: Response) => {
98
99
 
99
100
  res.send({
100
- status: 'ready'
101
+ status: 'ready',
102
+ version: DynamoNTS_GlobalService.params.version,
103
+ upTime: DynamoNTS_GlobalService.upTime,
101
104
  });
102
105
  }
103
106
  ]
@@ -0,0 +1,2 @@
1
+
2
+ export * from './test';
@@ -0,0 +1,2 @@
1
+
2
+ export * from './usage';
@@ -155,7 +155,7 @@ export class DynamoNTS_ApiService {
155
155
  }
156
156
  } catch (error) {
157
157
  Dynamo_Log.error(`\nAPI ERROR: ${callParams?.name} failed...` +
158
- `\n${callParams?.baseUrl}${callParams?.endPoint}`);
158
+ `\n${callParams?.baseUrl}${callParams?.endPoint}\n`, callParams);
159
159
 
160
160
  if (callParams?.httpOptions?.responseType === HttpResponseType.text) {
161
161
  error.error = JSON.parse(error.error);
@@ -127,10 +127,12 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
127
127
  super();
128
128
 
129
129
  try {
130
- if (0 < this.socketServices.length) {
130
+ this.socketServices = this.getSocketServices();
131
+
132
+ if (this.socketServices?.length) {
131
133
  this.setSocketSecurity();
132
134
 
133
- this.setupSocketServices();
135
+ this.mountSocketServices();
134
136
 
135
137
  if (this.debugLog) console.log(`\nAll sockets setted up.... sockets using security: ${this.socketSecurity}`);
136
138
  } else {
@@ -160,7 +162,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
160
162
  /**
161
163
  *
162
164
  */
163
- private setupSocketServices(): void {
165
+ private mountSocketServices(): void {
164
166
  let httpSocketServer: Http.Server;
165
167
  if (this.socketSecurity !== DynamoNTS_RouteSecurity.secure) {
166
168
  if (!this.openExpress) {
@@ -205,7 +207,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
205
207
  (mod: DynamoNTS_SocketService<any>) => mod.port === service.port
206
208
  );
207
209
 
208
- if (1 < existingPorts.length || this.httpPort === service.port || this.httpsPort === service.port) {
210
+ if (1 < existingPorts.length || this.ports.httpPort === service.port || this.ports.httpsPort === service.port) {
209
211
  let error = new Error(`PORT DUPLICATION: ${service.port}`);
210
212
  let errorStack: string[] = error.stack.split('\n');
211
213
  errorStack.splice(1, 4);
@@ -230,4 +232,9 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
230
232
  }
231
233
  });
232
234
  }
235
+
236
+ /**
237
+ * MISSING Description (TODO)
238
+ */
239
+ abstract getSocketServices(): DynamoNTS_SocketService<any>[];
233
240
  }
@@ -12,6 +12,17 @@ import { DynamoNTS_RoutingModule } from './dynamo-nts-routing-module.service';
12
12
  import { DynamoNTS_EndpointParams } from '../_models/dynamo-nts-endpoint-params';
13
13
  import { dynamoNTS_GlobalSettings } from '../_constants';
14
14
  import { Dynamo_Log } from '@futdevpro/fsm-dynamo';
15
+ import { DynamoNTS_GlobalService, DynamoNTS_GlobalServiceSettings } from './dynamo-nts-global.service';
16
+
17
+ export interface DynamoNTS_CertificationSettings {
18
+ keyPath: FileSystem.PathLike,
19
+ certPath: FileSystem.PathLike,
20
+ }
21
+
22
+ export interface DynamoNTS_PortSettings {
23
+ httpPort?: number,
24
+ httpsPort?: number,
25
+ }
15
26
 
16
27
  /**
17
28
  * This will be the MAIN service of our server project,
@@ -125,49 +136,26 @@ import { Dynamo_Log } from '@futdevpro/fsm-dynamo';
125
136
  */
126
137
  export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
127
138
 
128
- /**
129
- * Setup this in the setupAppParams(), which will be called first in the constuctor
130
- *
131
- * @example
132
- *
133
- * this.params = new DynamoNTS_AppParams({
134
- * name: 'Warbots Server',
135
- * title: warbotsTitleLog,
136
- * version: version,
137
- * dbName: 'warbots',
138
- * });
139
- */
140
- protected params: DynamoNTS_AppParams;
139
+ private _params: DynamoNTS_AppParams;
140
+ protected get params(): DynamoNTS_AppParams { return this._params; }
141
141
 
142
142
  protected mongoose = Mongoose;
143
143
 
144
- protected security: DynamoNTS_RouteSecurity;
144
+ private _security: DynamoNTS_RouteSecurity;
145
+ protected get security(): DynamoNTS_RouteSecurity { return this._security; }
145
146
 
146
- /**
147
- * setup this in the setupRoutingModules()
148
- */
149
- protected httpPort?: number;
150
- /**
151
- * setup this in the setupRoutingModules()
152
- */
153
- protected httpsPort?: number;
147
+ protected _ports: DynamoNTS_PortSettings;
148
+ protected get ports(): DynamoNTS_PortSettings { return this._ports; }
154
149
 
155
- /**
156
- * setup this in the setupRoutingModules()
157
- */
158
- protected cert?: {
159
- keyPath: FileSystem.PathLike,
160
- certPath: FileSystem.PathLike,
161
- };
150
+ private _cert?: DynamoNTS_CertificationSettings;
151
+ protected get cert(): DynamoNTS_CertificationSettings { return this._cert; }
162
152
 
163
153
  protected openExpress: Express.Application;
164
154
  private secureExpress: Express.Application;
165
155
  protected httpsServer: Https.Server;
166
156
 
167
- /**
168
- * setup this in the setupRoutingModules()
169
- */
170
- protected routingModules: DynamoNTS_RoutingModule[];
157
+ private _routingModules: DynamoNTS_RoutingModule[];
158
+ protected get routingModules(): DynamoNTS_RoutingModule[] { return this._routingModules; }
171
159
 
172
160
  /**
173
161
  * setting this value to true, enables this service debug logs
@@ -178,30 +166,59 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
178
166
  super();
179
167
 
180
168
  try {
181
- this.setupAppParams();
182
- console.log(`\n\n\nStarting ${this.params.name}... \nVersion: ${this.params.version}`);
183
- if (this.params.title) console.log(this.params.title);
169
+ this._params = this.getAppParams();
170
+
171
+ if (this.overrideDynamoNTSGlobalSettings) {
172
+ this.overrideDynamoNTSGlobalSettings();
173
+ }
174
+
175
+ DynamoNTS_GlobalService.setServices(this.getGlobalServiceCollection());
176
+ DynamoNTS_GlobalService.setParams(this.params);
177
+
178
+ this._ports = this.getPortSettings();
179
+ if (this.getCertificationSettings) {
180
+ this._cert = this.getCertificationSettings();
181
+ }
182
+ this._routingModules = this.getRoutingModules();
183
+
184
+ if (this.createEntries) {
185
+ this.createEntries();
186
+ }
187
+
188
+ console.log(
189
+ `\n\n\nStarting ${this._params.name}... ` +
190
+ `\nVersion: ${this._params.version}`
191
+ );
192
+ if (this._params.title) {
193
+ console.log(this._params.title);
194
+ }
184
195
 
185
196
  this.startDB();
186
197
 
187
- this.setGlobalServiceCollection();
198
+ this.getGlobalServiceCollection();
188
199
  this.debugLog = dynamoNTS_GlobalSettings.logSetup;
189
200
 
190
- this.setupRoutingModules();
201
+ this.getRoutingModules();
191
202
  this.setSecurity();
192
203
 
193
- if (0 < this.routingModules.length) {
204
+ if (this._routingModules?.length) {
194
205
  this.initExpresses();
195
206
  this.startExpresses();
196
207
 
197
- if (this.security !== DynamoNTS_RouteSecurity.secure) {
208
+ if (this._security !== DynamoNTS_RouteSecurity.secure) {
198
209
  this.mountOpenRoutes();
199
210
  }
200
- if (this.security !== DynamoNTS_RouteSecurity.open && this.cert) {
211
+ if (this._security !== DynamoNTS_RouteSecurity.open && this._cert) {
201
212
  this.mountSecureRoutes();
202
213
  }
203
214
 
204
- if (this.debugLog) console.log(`\nRoutes mounted.... server using security: ${this.security}`);
215
+ if (this.debugLog) {
216
+ console.log(`\nRoutes mounted.... server using security: ${this._security}`);
217
+ }
218
+ }
219
+
220
+ if (this.postProcess) {
221
+ this.postProcess();
205
222
  }
206
223
  } catch (error) {
207
224
  Dynamo_Log.error('\nApplication start failed.\n', error);
@@ -221,7 +238,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
221
238
  });
222
239
 
223
240
  this.mongoose.connect(
224
- this.params.dbUri,
241
+ this._params.dbUri,
225
242
  {
226
243
  useNewUrlParser: true,
227
244
  useUnifiedTopology: true
@@ -233,15 +250,15 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
233
250
  *
234
251
  */
235
252
  private initExpresses() {
236
- if (this.security !== DynamoNTS_RouteSecurity.secure) {
237
- if (!this.httpPort) {
253
+ if (this._security !== DynamoNTS_RouteSecurity.secure) {
254
+ if (!this._ports.httpPort) {
238
255
  let errorMsg: string =
239
256
  `\nYou have open routes, but httpPort is not set!` +
240
- `\nsecurity: ${this.security}` +
257
+ `\nsecurity: ${this._security}` +
241
258
  `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
242
259
 
243
260
  errorMsg += '\n\nThe routes setted to use open server:';
244
- this.routingModules.forEach((module: DynamoNTS_RoutingModule) => {
261
+ this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
245
262
  if (module.security != DynamoNTS_RouteSecurity.secure) {
246
263
  errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using open sever:`;
247
264
  module.endpoints.forEach((endpoint: DynamoNTS_EndpointParams) => {
@@ -264,11 +281,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
264
281
  this.initOpenExpress();
265
282
  }
266
283
 
267
- if (this.security !== DynamoNTS_RouteSecurity.open) {
268
- if (!this.cert || !this.httpsPort) {
284
+ if (this._security !== DynamoNTS_RouteSecurity.open) {
285
+ if (!this._cert || !this._ports.httpsPort) {
269
286
  let errorMsg: string =
270
287
  `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
271
- `\nsecurity: ${this.security}` +
288
+ `\nsecurity: ${this._security}` +
272
289
  `\nset...` +
273
290
  `\n httpsPort and` +
274
291
  `\n cert: {` +
@@ -278,7 +295,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
278
295
  `\nin DynamoBEServer - setupRoutingModules() to enable secure routes.`;
279
296
 
280
297
  errorMsg += '\n\nThe routes setted to use secure server:';
281
- this.routingModules.forEach((module: DynamoNTS_RoutingModule) => {
298
+ this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
282
299
  if (module.security != DynamoNTS_RouteSecurity.open) {
283
300
  errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using secure sever:`;
284
301
  module.endpoints.forEach((endpoint: DynamoNTS_EndpointParams) => {
@@ -320,8 +337,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
320
337
  this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
321
338
 
322
339
  const options = {
323
- key: FileSystem.readFileSync(this.cert.keyPath),
324
- cert: FileSystem.readFileSync(this.cert.certPath),
340
+ key: FileSystem.readFileSync(this._cert.keyPath),
341
+ cert: FileSystem.readFileSync(this._cert.certPath),
325
342
  };
326
343
  this.httpsServer = Https.createServer(options, this.secureExpress);
327
344
  }
@@ -331,10 +348,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
331
348
  */
332
349
  private async startExpresses(): Promise<void> {
333
350
  try {
334
- if (this.security !== DynamoNTS_RouteSecurity.open) {
351
+ if (this._security !== DynamoNTS_RouteSecurity.open) {
335
352
  this.httpsServer
336
- .listen(this.httpsPort, 'localhost', 0, () => {
337
- Dynamo_Log.success(`\nHTTPS (secure) server is listening on port ${this.httpsPort}\n`);
353
+ .listen(this._ports.httpsPort, 'localhost', 0, () => {
354
+ Dynamo_Log.success(`\nHTTPS (secure) server is listening on port ${this._ports.httpsPort}\n`);
338
355
  })
339
356
  .on('error', (error) => {
340
357
  Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
@@ -344,10 +361,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
344
361
  });
345
362
  }
346
363
 
347
- if (this.security !== DynamoNTS_RouteSecurity.secure) {
364
+ if (this._security !== DynamoNTS_RouteSecurity.secure) {
348
365
  this.openExpress
349
- .listen(this.httpPort, () => {
350
- Dynamo_Log.success(`\nHTTP (-open-) server is listening on port ${this.httpPort}\n`);
366
+ .listen(this._ports.httpPort, () => {
367
+ Dynamo_Log.success(`\nHTTP (-open-) server is listening on port ${this._ports.httpPort}\n`);
351
368
  })
352
369
  .on('error', (error) => {
353
370
  Dynamo_Log.error(`\nHTTP (-open-) server ERROR`, error);
@@ -365,11 +382,16 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
365
382
  *
366
383
  */
367
384
  private mountSecureRoutes (): void {
368
- this.routingModules.forEach((module: DynamoNTS_RoutingModule) => {
385
+ this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
369
386
  if (module.security !== DynamoNTS_RouteSecurity.open) {
370
- if (this.debugLog) console.log(`route mount (secure): ${module.route}`);
371
- const existingRoutes: DynamoNTS_RoutingModule[] = this.routingModules.filter(
372
- (mod: DynamoNTS_RoutingModule) => mod.route === module.route);
387
+ if (this.debugLog) {
388
+ console.log(`route mount (secure): ${module.route}`);
389
+ }
390
+
391
+ const existingRoutes: DynamoNTS_RoutingModule[] = this._routingModules.filter(
392
+ (mod: DynamoNTS_RoutingModule) => mod.route === module.route
393
+ );
394
+
373
395
  if (1 < existingRoutes.length) {
374
396
  let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
375
397
  let errorStack: string[] = error.stack.split('\n');
@@ -387,11 +409,16 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
387
409
  *
388
410
  */
389
411
  private mountOpenRoutes (): void {
390
- this.routingModules.forEach((module: DynamoNTS_RoutingModule) => {
412
+ this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
391
413
  if (module.security !== DynamoNTS_RouteSecurity.secure) {
392
- if (this.debugLog) console.log(`route mount (open): ${module.route}`);
393
- const existingRoutes: DynamoNTS_RoutingModule[] = this.routingModules.filter(
394
- (mod: DynamoNTS_RoutingModule) => mod.route === module.route);
414
+ if (this.debugLog) {
415
+ console.log(`route mount (open): ${module.route}`);
416
+ }
417
+
418
+ const existingRoutes: DynamoNTS_RoutingModule[] = this._routingModules.filter(
419
+ (mod: DynamoNTS_RoutingModule) => mod.route === module.route
420
+ );
421
+
395
422
  if (1 < existingRoutes.length) {
396
423
  let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
397
424
  let errorStack: string[] = error.stack.split('\n');
@@ -408,17 +435,18 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
408
435
  /**
409
436
  *
410
437
  */
411
- protected setSecurity(): void {
412
- this.routingModules.forEach((module: DynamoNTS_RoutingModule) => {
413
- if (!this.security) {
414
- this.security = module.security;
415
- } else if (this.security !== module.security) {
416
- this.security = DynamoNTS_RouteSecurity.both;
438
+ private setSecurity(): void {
439
+ this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
440
+ if (!this._security) {
441
+ this._security = module.security;
442
+ } else if (this._security !== module.security) {
443
+ this._security = DynamoNTS_RouteSecurity.both;
417
444
  }
418
445
  });
419
446
  }
420
447
 
421
448
  /**
449
+ * #OUTDATED
422
450
  * Setting up App params, and preparing project global settings
423
451
  * You must setup app params in this function like this:
424
452
  *
@@ -437,9 +465,15 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
437
465
  * });
438
466
  * }
439
467
  */
440
- abstract setupAppParams(): void;
468
+ abstract getAppParams(): DynamoNTS_AppParams;
441
469
 
442
470
  /**
471
+ * MISSING Description (TODO)
472
+ */
473
+ abstract overrideDynamoNTSGlobalSettings?(): void;
474
+
475
+ /**
476
+ * #OUTDATED
443
477
  * Setting up DBServices
444
478
  * You must setup globalServiceCollection and dbServices in this function
445
479
  *
@@ -456,9 +490,15 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
456
490
  * });
457
491
  * }
458
492
  */
459
- abstract setGlobalServiceCollection(): void;
493
+ abstract getGlobalServiceCollection(): DynamoNTS_GlobalServiceSettings;
494
+
495
+ /**
496
+ * MISSING Description (TODO)
497
+ */
498
+ abstract getPortSettings(): DynamoNTS_PortSettings;
460
499
 
461
500
  /**
501
+ * #OUTDATED
462
502
  * You must setup endpoints and required services in this function
463
503
  *
464
504
  * @example
@@ -492,5 +532,20 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
492
532
  * ];
493
533
  * }
494
534
  */
495
- abstract setupRoutingModules(): void;
535
+ abstract getRoutingModules(): DynamoNTS_RoutingModule[];
536
+
537
+ /**
538
+ * MISSING Description (TODO)
539
+ */
540
+ getCertificationSettings?(): DynamoNTS_CertificationSettings;
541
+
542
+ /**
543
+ * MISSING Description (TODO)
544
+ */
545
+ createEntries?(): void;
546
+
547
+ /**
548
+ * MISSING Description (TODO)
549
+ */
550
+ postProcess?(): void;
496
551
  }
@@ -104,6 +104,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
104
104
  * use db-service update instead.
105
105
  *
106
106
  * @param {string} id
107
+ * (using id from service.data, if not provided)
107
108
  * @param dontSetToService
108
109
  *
109
110
  * @return {T} data: T
@@ -120,14 +121,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
120
121
  });
121
122
  }
122
123
 
123
- const dataExists: T = await this.dataDBService.getDataById(id ?? this.data._id).catch(error => {
124
- if (error?.errorCode == 'NTS-DBS-GI1') {
125
- Dynamo_Log.warn(`getDataById ${this.dataParams.dataName} (${id ?? this.data._id}) didn't found any.`);
126
- return null;
127
- } else {
128
- throw error;
129
- }
130
- });
124
+ const dataExists: T = await this.dataDBService.getDataById(id ?? this.data._id);
131
125
  if (!dontSetToService) {
132
126
  this.data = dataExists;
133
127
  }
@@ -151,6 +145,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
151
145
 
152
146
  /**
153
147
  * returns data from database by dependencyId to the service
148
+ * (using id from service.data, if not provided)
154
149
  * @param dependencyId
155
150
  */
156
151
  async getDataByDependencyId(dependencyId?: string, dontSetToService?: boolean): Promise<T> {
@@ -475,57 +470,67 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
475
470
  */
476
471
  async saveData(): Promise<void> {
477
472
  try {
473
+ if (!this.data._id && (!this.depKey || !this.data[this.depKey])) {
474
+ // if ID of dependencyID is not present, data not exists, create new data
475
+ this.data = await this.dataDBService.createData(this.data, this.issuer);
476
+ return;
477
+ }
478
+
479
+ let dataExists: T;
480
+
481
+ // check if data already exists with the specific ID
478
482
  if (this.data._id) {
479
- // check if already exists
480
- const dataExists: T = await this.getDataById(null, true);
483
+ dataExists = await this.getDataById(null, true);
484
+ if (dataExists) {
485
+ // if data exists do modify
486
+ this.data = await this.dataDBService.modifyData(this.data, this.issuer);
487
+ return;
488
+ } else {
489
+ throw new Dynamo_Error({
490
+ status: 417,
491
+ errorCode: 'NTS-DS0-SD1',
492
+ addECToUserMsg: true,
493
+ message: `saveData was unsuccessful: provided ID not exists (id: ${this.data._id})`,
494
+ userMessage: this.defaultErrorUserMsg
495
+ });
496
+ }
497
+ }
498
+
499
+ if (this.depKey) {
500
+ if (!this.data[this.depKey]) {
501
+ throw new Dynamo_Error({
502
+ status: 417,
503
+ errorCode: 'NTS-DS0-SD2',
504
+ addECToUserMsg: true,
505
+ message: `saveData was unsuccessful: dependency data id missing from data (key: ${this.depKey})`,
506
+ userMessage: this.defaultErrorUserMsg
507
+ });
508
+ }
509
+
510
+ dataExists = await this.getDataByDependencyId(null, true);
511
+
481
512
  if (dataExists) {
482
513
  // if data exists do modify
483
514
  this.data = await this.dataDBService.modifyData(this.data, this.issuer);
515
+ return;
484
516
  } else {
485
517
  // if data not exists check that dependency already exists for this
486
- if (this.depKey) {
487
- if (!this.data[this.depKey]) {
488
- throw new Dynamo_Error({
489
- status: 417,
490
- errorCode: 'NTS-DS0-SD1',
491
- addECToUserMsg: true,
492
- message: `saveData was unsuccessful: dependency data id missing from data (key: ${this.depKey})`,
493
- userMessage: this.defaultErrorUserMsg
494
- });
495
- }
496
-
497
- /* const dependencyExists = */
498
- await this.getDependencyDataDBService().getDataById(this.data[this.depKey]).catch(error => {
499
- if (error?.errorCode === 'NTS-DBS-GI1') {
500
- throw new Dynamo_Error({
501
- status: 417,
502
- errorCode: 'NTS-DS0-SD2',
503
- addECToUserMsg: true,
504
- message: `saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]})`,
505
- userMessage: this.defaultErrorUserMsg
506
- });
507
- } else {
508
- throw error;
509
- }
518
+ const dependencyExists = await this.getDependencyDataDBService().getDataById(this.data[this.depKey]);
519
+ if(!dependencyExists) {
520
+ throw new Dynamo_Error({
521
+ status: 417,
522
+ errorCode: 'NTS-DS0-SD3',
523
+ addECToUserMsg: true,
524
+ message: `saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]})`,
525
+ userMessage: this.defaultErrorUserMsg
510
526
  });
511
- /* if (!dependencyExists) {
512
- throw new Dynamo_Error({
513
- status: 417,
514
- errorCode: 'NTS-DS0-SD2',
515
- addECToUserMsg: true,
516
- message: `saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]})`,
517
- userMessage: this.defaultErrorUserMsg
518
- });
519
- } */
520
527
  }
521
-
522
- // if data not exists create new data
523
- this.data = await this.dataDBService.createData(this.data, this.issuer);
524
528
  }
525
- } else {
526
- // if ID is not present, data not exists, create new data
527
- this.data = await this.dataDBService.createData(this.data, this.issuer);
528
529
  }
530
+
531
+ // if data not exists create new data
532
+ this.data = await this.dataDBService.createData(this.data, this.issuer);
533
+
529
534
  } catch (error) {
530
535
  if (['NTS-DS0-SD1', 'NTS-DS0-SD2'].includes(error?.errorCode)) {
531
536
  throw error;