taon 19.0.66 → 19.0.68

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 (120) hide show
  1. package/README.md +160 -160
  2. package/bin/start.js +281 -281
  3. package/bin/taon +6 -6
  4. package/bin/taon-debug +5 -5
  5. package/bin/taon-debug-brk +5 -5
  6. package/browser/README.md +24 -24
  7. package/browser/fesm2022/taon.mjs +305 -89
  8. package/browser/fesm2022/taon.mjs.map +1 -1
  9. package/browser/lib/base-classes/base-class.d.ts +8 -1
  10. package/browser/lib/base-classes/base-controller.d.ts +56 -4
  11. package/browser/lib/base-classes/base-crud-controller.d.ts +5 -4
  12. package/browser/lib/base-classes/base-middleware.d.ts +2 -2
  13. package/browser/lib/base-classes/base-repository.d.ts +3 -0
  14. package/browser/lib/config/method-config.d.ts +1 -0
  15. package/browser/lib/decorators/http/http-decorators.d.ts +2 -1
  16. package/browser/lib/decorators/http/http-methods-decorators.d.ts +35 -4
  17. package/browser/lib/endpoint-context.d.ts +10 -4
  18. package/browser/lib/get-response-value.d.ts +1 -1
  19. package/browser/lib/helpers/taon-helpers.d.ts +1 -0
  20. package/browser/lib/index.d.ts +4 -0
  21. package/browser/lib/models.d.ts +4 -10
  22. package/browser/lib/realtime/realtime-client.d.ts +18 -14
  23. package/browser/lib/realtime/realtime-server.d.ts +28 -3
  24. package/browser/lib/realtime/realtime.models.d.ts +15 -2
  25. package/browser/package.json +1 -1
  26. package/icon-menu-taon.svg +15 -15
  27. package/lib/base-classes/base-class.d.ts +8 -1
  28. package/lib/base-classes/base-class.js +20 -2
  29. package/lib/base-classes/base-class.js.map +1 -1
  30. package/lib/base-classes/base-controller.d.ts +57 -5
  31. package/lib/base-classes/base-controller.js +83 -12
  32. package/lib/base-classes/base-controller.js.map +1 -1
  33. package/lib/base-classes/base-crud-controller.d.ts +5 -4
  34. package/lib/base-classes/base-crud-controller.js +16 -4
  35. package/lib/base-classes/base-crud-controller.js.map +1 -1
  36. package/lib/base-classes/base-middleware.d.ts +2 -2
  37. package/lib/base-classes/base-middleware.js +1 -0
  38. package/lib/base-classes/base-middleware.js.map +1 -1
  39. package/lib/base-classes/base-repository.d.ts +3 -0
  40. package/lib/base-classes/base-repository.js +3 -0
  41. package/lib/base-classes/base-repository.js.map +1 -1
  42. package/lib/build-info._auto-generated_.d.ts +1 -1
  43. package/lib/build-info._auto-generated_.js +1 -1
  44. package/lib/config/method-config.d.ts +1 -0
  45. package/lib/config/method-config.js.map +1 -1
  46. package/lib/decorators/classes/controller-config.d.ts +20 -0
  47. package/lib/decorators/classes/controller-config.js +21 -0
  48. package/lib/decorators/classes/controller-config.js.map +1 -0
  49. package/lib/decorators/classes/controller-options.d.ts +16 -0
  50. package/lib/decorators/classes/controller-options.js +20 -0
  51. package/lib/decorators/classes/controller-options.js.map +1 -0
  52. package/lib/decorators/http/http-decorators.d.ts +2 -1
  53. package/lib/decorators/http/http-decorators.js +2 -1
  54. package/lib/decorators/http/http-decorators.js.map +1 -1
  55. package/lib/decorators/http/http-methods-decorators.d.ts +35 -4
  56. package/lib/decorators/http/http-methods-decorators.js +34 -1
  57. package/lib/decorators/http/http-methods-decorators.js.map +1 -1
  58. package/lib/endpoint-context.d.ts +10 -4
  59. package/lib/endpoint-context.js +178 -141
  60. package/lib/endpoint-context.js.map +1 -1
  61. package/lib/env/env.angular-node-app.d.ts +1 -2
  62. package/lib/env/env.angular-node-app.js +3 -4
  63. package/lib/env/env.angular-node-app.js.map +1 -1
  64. package/lib/env/env.docs-webapp.d.ts +1 -2
  65. package/lib/env/env.docs-webapp.js +3 -4
  66. package/lib/env/env.docs-webapp.js.map +1 -1
  67. package/lib/env/env.electron-app.d.ts +1 -2
  68. package/lib/env/env.electron-app.js +3 -4
  69. package/lib/env/env.electron-app.js.map +1 -1
  70. package/lib/env/env.mobile-app.d.ts +1 -2
  71. package/lib/env/env.mobile-app.js +3 -4
  72. package/lib/env/env.mobile-app.js.map +1 -1
  73. package/lib/env/env.npm-lib-and-cli-tool.d.ts +1 -2
  74. package/lib/env/env.npm-lib-and-cli-tool.js +3 -4
  75. package/lib/env/env.npm-lib-and-cli-tool.js.map +1 -1
  76. package/lib/env/env.vscode-plugin.d.ts +1 -2
  77. package/lib/env/env.vscode-plugin.js +3 -4
  78. package/lib/env/env.vscode-plugin.js.map +1 -1
  79. package/lib/get-response-value.d.ts +1 -1
  80. package/lib/get-response-value.js +0 -4
  81. package/lib/get-response-value.js.map +1 -1
  82. package/lib/helpers/taon-helpers.d.ts +1 -0
  83. package/lib/helpers/taon-helpers.js +6 -0
  84. package/lib/helpers/taon-helpers.js.map +1 -1
  85. package/lib/index.d.ts +4 -0
  86. package/lib/index.js +13 -2
  87. package/lib/index.js.map +1 -1
  88. package/lib/models.d.ts +4 -10
  89. package/lib/models.js +5 -23
  90. package/lib/models.js.map +1 -1
  91. package/lib/realtime/realtime-client.d.ts +18 -14
  92. package/lib/realtime/realtime-client.js +33 -25
  93. package/lib/realtime/realtime-client.js.map +1 -1
  94. package/lib/realtime/realtime-server.d.ts +28 -3
  95. package/lib/realtime/realtime-server.js +28 -2
  96. package/lib/realtime/realtime-server.js.map +1 -1
  97. package/lib/realtime/realtime.models.d.ts +15 -2
  98. package/lib/ui/index.js +2 -2
  99. package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
  100. package/package.json +1 -1
  101. package/websql/README.md +24 -24
  102. package/websql/fesm2022/taon.mjs +306 -91
  103. package/websql/fesm2022/taon.mjs.map +1 -1
  104. package/websql/lib/base-classes/base-class.d.ts +8 -1
  105. package/websql/lib/base-classes/base-controller.d.ts +56 -4
  106. package/websql/lib/base-classes/base-crud-controller.d.ts +5 -4
  107. package/websql/lib/base-classes/base-middleware.d.ts +2 -2
  108. package/websql/lib/base-classes/base-repository.d.ts +3 -0
  109. package/websql/lib/config/method-config.d.ts +1 -0
  110. package/websql/lib/decorators/http/http-decorators.d.ts +2 -1
  111. package/websql/lib/decorators/http/http-methods-decorators.d.ts +35 -4
  112. package/websql/lib/endpoint-context.d.ts +10 -4
  113. package/websql/lib/get-response-value.d.ts +1 -1
  114. package/websql/lib/helpers/taon-helpers.d.ts +1 -0
  115. package/websql/lib/index.d.ts +4 -0
  116. package/websql/lib/models.d.ts +4 -10
  117. package/websql/lib/realtime/realtime-client.d.ts +18 -14
  118. package/websql/lib/realtime/realtime-server.d.ts +28 -3
  119. package/websql/lib/realtime/realtime.models.d.ts +15 -2
  120. package/websql/package.json +1 -1
@@ -21,11 +21,12 @@ const lib_4 = require("taon-typeorm/lib"); // @websql
21
21
  const lib_5 = require("taon-typeorm/lib"); // @websql
22
22
  const lib_6 = require("taon-typeorm/lib");
23
23
  const lib_7 = require("tnp-config/lib");
24
- const lib_8 = require("tnp-core/lib"); // @backend
25
- const lib_9 = require("tnp-core/lib");
24
+ const lib_8 = require("tnp-core/lib");
25
+ const lib_9 = require("tnp-core/lib"); // @backend
26
26
  const lib_10 = require("tnp-core/lib");
27
27
  const lib_11 = require("tnp-core/lib");
28
28
  const lib_12 = require("tnp-core/lib");
29
+ const lib_13 = require("tnp-core/lib");
29
30
  const constants_1 = require("./constants");
30
31
  const context_db_migrations_1 = require("./context-db-migrations");
31
32
  const di_container_1 = require("./dependency-injection/di-container");
@@ -43,10 +44,6 @@ class EndpointContext {
43
44
  configFn;
44
45
  cloneOptions;
45
46
  //#region static
46
- /**
47
- * JUST FOR TESTING PURPOSES
48
- */
49
- USE_MARIADB_MYSQL_IN_DOCKER = false;
50
47
  /* */
51
48
  /* */
52
49
  /* */
@@ -55,15 +52,14 @@ class EndpointContext {
55
52
  /* */
56
53
  /* */
57
54
  /* */
58
- // public static findForTraget(classFnOrObject: any): EndpointContext {
59
- // const obj = ClassHelpers.getClassFnFromObject(classFnOrObject) || {};
60
- // return (
61
- // classFnOrObject[Symbols.ctxInClassOrClassObj] ||
62
- // obj[Symbols.ctxInClassOrClassObj]
63
- // );
64
- // }
65
55
  //#endregion
66
56
  //#region fields
57
+ //#region fields / use mariadb mysql in docker
58
+ /**
59
+ * JUST FOR TESTING PURPOSES
60
+ */
61
+ USE_MARIADB_MYSQL_IN_DOCKER = false;
62
+ //#endregion
67
63
  //#region fields / flags
68
64
  disabledRealtime = false;
69
65
  /**
@@ -72,8 +68,12 @@ class EndpointContext {
72
68
  */
73
69
  inited = false;
74
70
  //#endregion
71
+ //#region fields / db migrations
75
72
  dbMigrations = new context_db_migrations_1.ContextDbMigrations(this);
73
+ //#endregion
74
+ //#region fields / local instance obj symbol
76
75
  localInstaceObjSymbol = Symbol('localInstaceObjSymbol');
76
+ //#endregion
77
77
  //#region fields / all instances of classes from context
78
78
  /**
79
79
  * all instances of classes from context
@@ -100,7 +100,9 @@ class EndpointContext {
100
100
  return this.cloneOptions?.sourceContext;
101
101
  }
102
102
  //#endregion
103
+ //#region fields / skip writing server routes
103
104
  skipWritingServerRoutes = false;
105
+ //#endregion
104
106
  //#region fields / types from contexts
105
107
  injectableTypesfromContexts = [
106
108
  models_1.Models.ClassType.CONTROLLER,
@@ -111,11 +113,12 @@ class EndpointContext {
111
113
  models_1.Models.ClassType.MIGRATION,
112
114
  ];
113
115
  //#endregion
116
+ //#region fields / all types from contexts
114
117
  allTypesfromContexts = [
115
118
  ...this.injectableTypesfromContexts,
116
119
  models_1.Models.ClassType.ENTITY,
117
120
  ];
118
- // public __contextForControllerInstanceAccess?: EndpointContext;
121
+ //#endregion
119
122
  //#region fields / express app
120
123
  expressApp = {};
121
124
  //#endregion
@@ -161,31 +164,37 @@ class EndpointContext {
161
164
  //#endregion
162
165
  //#region fields / logs
163
166
  get logHttp() {
164
- if (lib_11._.isObject(this.config?.logs)) {
167
+ if (lib_12._.isObject(this.config?.logs)) {
165
168
  return !!this.config.logs.http;
166
169
  }
167
170
  return this.config?.logs === true;
168
171
  }
169
172
  get logRealtime() {
170
- if (lib_11._.isObject(this.config?.logs)) {
173
+ if (lib_12._.isObject(this.config?.logs)) {
171
174
  return !!this.config.logs.realtime;
172
175
  }
173
176
  return this.config?.logs === true;
174
177
  }
175
178
  get logFramework() {
176
- if (lib_11._.isObject(this.config?.logs)) {
179
+ if (lib_12._.isObject(this.config?.logs)) {
177
180
  return !!this.config.logs.framework;
178
181
  }
179
182
  return this.config?.logs === true;
180
183
  }
184
+ get logRoutes() {
185
+ if (lib_12._.isObject(this.config?.logs)) {
186
+ return !!this.config.logs.routes;
187
+ }
188
+ return this.config?.logs === true;
189
+ }
181
190
  get logDb() {
182
- if (lib_11._.isObject(this.config?.logs)) {
191
+ if (lib_12._.isObject(this.config?.logs)) {
183
192
  return !!this.config.logs.db;
184
193
  }
185
194
  return this.config?.logs === true;
186
195
  }
187
196
  get logMigrations() {
188
- if (lib_11._.isObject(this.config?.logs)) {
197
+ if (lib_12._.isObject(this.config?.logs)) {
189
198
  return !!this.config.logs.migrations;
190
199
  }
191
200
  return this.config?.logs === true;
@@ -209,7 +218,7 @@ class EndpointContext {
209
218
  this.configFn = configFn;
210
219
  this.cloneOptions = cloneOptions;
211
220
  this.cloneOptions = this.cloneOptions || {};
212
- this.isRunningInsideDocker = lib_9.UtilsOs.isRunningInDocker();
221
+ this.isRunningInsideDocker = lib_10.UtilsOs.isRunningInDocker();
213
222
  }
214
223
  //#endregion
215
224
  //#region methods & getters / init
@@ -221,7 +230,7 @@ class EndpointContext {
221
230
  // @ts-ignore
222
231
  this.onlyMigrationRevertToTimestamp = onlyMigrationRevertToTimestamp;
223
232
  this.config = this.configFn({});
224
- if (lib_11._.isObject(this.config.database)) {
233
+ if (lib_12._.isObject(this.config.database)) {
225
234
  this.config.database = models_1.Models.DatabaseConfig.from(this.config.database).databaseConfigTypeORM;
226
235
  }
227
236
  this.config.host = this.host === null ? void 0 : this.host;
@@ -236,15 +245,15 @@ class EndpointContext {
236
245
  if (this.config.host &&
237
246
  !this.config.host.startsWith('http://') &&
238
247
  !this.config.host.startsWith('https://')) {
239
- lib_11.Helpers.throw(`[taon-config] Your${this.host ? ' remote' : ''} 'host' must start with http:// or https://`);
248
+ lib_12.Helpers.throw(`[taon-config] Your${this.host ? ' remote' : ''} 'host' must start with http:// or https://`);
240
249
  }
241
- if (lib_11._.isUndefined(this.config.useIpcWhenElectron)) {
250
+ if (lib_12._.isUndefined(this.config.useIpcWhenElectron)) {
242
251
  this.config.useIpcWhenElectron = true;
243
252
  }
244
253
  // console.log(`config for ${this.contextName}`, this.config);
245
254
  //#region resolve if skipping writing server routes
246
255
  //@ts-expect-error overriding readonly
247
- this.skipWritingServerRoutes = lib_11._.isBoolean(this.config.skipWritingServerRoutes)
256
+ this.skipWritingServerRoutes = lib_12._.isBoolean(this.config.skipWritingServerRoutes)
248
257
  ? this.config.skipWritingServerRoutes
249
258
  : false;
250
259
  //#endregion
@@ -261,8 +270,8 @@ class EndpointContext {
261
270
  // useIpcWhenElectron: ${this.config.useIpcWhenElectron}
262
271
  // Helpers.isElectron: ${Helpers.isElectron}
263
272
  // `)
264
- if (this.config.useIpcWhenElectron && lib_11.Helpers.isElectron) {
265
- if (lib_11.Helpers.isWebSQL) {
273
+ if (this.config.useIpcWhenElectron && lib_12.Helpers.isElectron) {
274
+ if (lib_12.Helpers.isWebSQL) {
266
275
  this.mode = 'backend-frontend(websql-electron)';
267
276
  }
268
277
  else {
@@ -277,7 +286,7 @@ class EndpointContext {
277
286
  if (!this.mode && !this.config.abstract) {
278
287
  const errMsg = `You need to provide host property or ` +
279
288
  `useIpcWhenElectron or mark it as abstract`;
280
- lib_11.Helpers.error(`[taon][Context=${this.contextName}]: ${errMsg}`, false, true);
289
+ lib_12.Helpers.error(`[taon][Context=${this.contextName}]: ${errMsg}`, false, true);
281
290
  //#region @backend
282
291
  process.exit(1);
283
292
  //#endregion
@@ -293,7 +302,7 @@ class EndpointContext {
293
302
  `);
294
303
  this.databaseConfig = this.getAutoGeneratedConfig();
295
304
  }
296
- else if (lib_11._.isObject(this.config.database)) {
305
+ else if (lib_12._.isObject(this.config.database)) {
297
306
  this.logFramework &&
298
307
  console.log(`
299
308
 
@@ -302,13 +311,13 @@ class EndpointContext {
302
311
  `);
303
312
  this.databaseConfig = this.getAutoGeneratedConfig();
304
313
  lib_2.walk.Object(this.config.database, (value, lodashPath) => {
305
- if (lib_11._.isNil(value) || lib_11._.isFunction(value) || lib_11._.isObject(value)) {
314
+ if (lib_12._.isNil(value) || lib_12._.isFunction(value) || lib_12._.isObject(value)) {
306
315
  // skipping
307
316
  }
308
317
  else {
309
318
  this.logFramework &&
310
319
  console.info(`Overriding database config: ${lodashPath}=${value}`);
311
- lib_11._.set(this.databaseConfig, lodashPath, value);
320
+ lib_12._.set(this.databaseConfig, lodashPath, value);
312
321
  }
313
322
  }, {
314
323
  walkGetters: false,
@@ -317,7 +326,7 @@ class EndpointContext {
317
326
  //#endregion
318
327
  //#region resolve session
319
328
  if (this.config.session) {
320
- this.session = lib_11._.cloneDeep(this.config.session);
329
+ this.session = lib_12._.cloneDeep(this.config.session);
321
330
  const oneHour = 1000 * 60 * 60 * 1; // 24;
322
331
  if (!this.session.cookieMaxAge) {
323
332
  this.session.cookieMaxAge = oneHour;
@@ -424,17 +433,17 @@ class EndpointContext {
424
433
  await this.initCustomBackendMiddlewares();
425
434
  const shouldStartHttpsSecureServer = this.isHttpServer && !this.isRunningInsideDocker;
426
435
  this.logFramework &&
427
- lib_11.Helpers.info(`
436
+ lib_12.Helpers.info(`
428
437
 
429
438
  Starting server ${shouldStartHttpsSecureServer ? 'with' : 'without'} HTTPS secure server
430
439
 
431
440
  `);
432
441
  this.serverTcpUdp = shouldStartHttpsSecureServer
433
- ? new lib_8.https.Server({
442
+ ? new lib_9.https.Server({
434
443
  key: this.config.https?.key,
435
444
  cert: this.config.https?.cert,
436
445
  }, this.expressApp)
437
- : new lib_8.http.Server(this.expressApp);
446
+ : new lib_9.http.Server(this.expressApp);
438
447
  this.publicAssets.forEach(asset => {
439
448
  this.expressApp.use(asset.serverPath, express.static(asset.locationOnDisk));
440
449
  });
@@ -455,7 +464,7 @@ class EndpointContext {
455
464
  // }
456
465
  //#endregion
457
466
  this.logRealtime &&
458
- lib_11.Helpers.info(`[ctx=${this.contextName}] Init Realtime for ${this.mode}`);
467
+ lib_12.Helpers.info(`[ctx=${this.contextName}] Init Realtime for ${this.mode}`);
459
468
  this.realtime = new realtime_core_1.RealtimeCore(this);
460
469
  }
461
470
  //#endregion
@@ -464,16 +473,16 @@ class EndpointContext {
464
473
  // console.log({ ref })
465
474
  if (this.config.abstract) {
466
475
  this.logFramework &&
467
- lib_11.Helpers.info(`[taon] Create abstract context: ${this.config.contextName}`);
476
+ lib_12.Helpers.info(`[taon] Create abstract context: ${this.config.contextName}`);
468
477
  }
469
478
  else {
470
479
  if (this.isRemoteHost) {
471
480
  this.logFramework &&
472
- lib_11.Helpers.info(`[taon] Create context for remote host: ${this.config.host}`);
481
+ lib_12.Helpers.info(`[taon] Create context for remote host: ${this.config.host}`);
473
482
  }
474
483
  else {
475
484
  this.logFramework &&
476
- lib_11.Helpers.info(`[taon] Create context for host: ${this.config.host}`);
485
+ lib_12.Helpers.info(`[taon] Create context for host: ${this.config.host}`);
477
486
  }
478
487
  }
479
488
  //#endregion
@@ -518,7 +527,7 @@ class EndpointContext {
518
527
 
519
528
  `);
520
529
  //#region @backend
521
- const locationOfTheDatabase = (0, lib_10.crossPlatformPath)([
530
+ const locationOfTheDatabase = (0, lib_11.crossPlatformPath)([
522
531
  process.cwd(),
523
532
  `db-${this.contextName}.sqlite`,
524
533
  ]);
@@ -531,14 +540,14 @@ class EndpointContext {
531
540
  logging: true,
532
541
  });
533
542
  //#region @backend
534
- if (!lib_8.fse.existsSync(locationOfTheDatabase)) {
543
+ if (!lib_9.fse.existsSync(locationOfTheDatabase)) {
535
544
  databaseConfig.recreateMode = 'DROP_DB+MIGRATIONS';
536
545
  }
537
546
  // TODO @LAST add same thing for mariadb/mysql
538
547
  this.logFramework &&
539
548
  console.log(`
540
549
  location of database: ${locationOfTheDatabase}
541
- db file exists: ${lib_8.fse.existsSync(locationOfTheDatabase)}
550
+ db file exists: ${lib_9.fse.existsSync(locationOfTheDatabase)}
542
551
  synchronize: ${databaseConfig.synchronize}
543
552
  dropSchema: ${databaseConfig.dropSchema}
544
553
  `);
@@ -548,24 +557,24 @@ class EndpointContext {
548
557
  else {
549
558
  //#region auto resolve db config
550
559
  this.logFramework &&
551
- lib_11.Helpers.info(`[taon][database] Automatically resolving database config for mode ${this.mode}`);
560
+ lib_12.Helpers.info(`[taon][database] Automatically resolving database config for mode ${this.mode}`);
552
561
  switch (this.mode) {
553
562
  //#region resolve database config for backend-frontend(ipc-electron)
554
563
  case 'backend-frontend(ipc-electron)':
555
564
  let dbLocationInOs;
556
565
  //#region @backend
557
- if (lib_9.UtilsOs.isElectron) {
558
- dbLocationInOs = (0, lib_10.crossPlatformPath)([
559
- lib_9.UtilsOs.getRealHomeDir(),
560
- `.taon/databases-for-electron-apps/${this.appId || lib_11._.snakeCase(process.cwd()).replace(/\_/, '.')}/${this.contextName}.sqlite`,
566
+ if (lib_10.UtilsOs.isElectron) {
567
+ dbLocationInOs = (0, lib_11.crossPlatformPath)([
568
+ lib_10.UtilsOs.getRealHomeDir(),
569
+ `.taon/databases-for-electron-apps/${this.appId || lib_12._.snakeCase(process.cwd()).replace(/\_/, '.')}/${this.contextName}.sqlite`,
561
570
  ]);
562
- if (!lib_11.Helpers.exists(lib_12.path.dirname(dbLocationInOs))) {
563
- lib_11.Helpers.mkdirp(lib_12.path.dirname(dbLocationInOs));
571
+ if (!lib_12.Helpers.exists(lib_13.path.dirname(dbLocationInOs))) {
572
+ lib_12.Helpers.mkdirp(lib_13.path.dirname(dbLocationInOs));
564
573
  }
565
574
  }
566
575
  //#endregion
567
576
  databaseConfig = models_1.Models.DatabaseConfig.from({
568
- location: lib_9.UtilsOs.isElectron
577
+ location: lib_10.UtilsOs.isElectron
569
578
  ? dbLocationInOs
570
579
  : `db-${this.contextName}.sqlite`,
571
580
  type: 'sqljs',
@@ -629,9 +638,9 @@ class EndpointContext {
629
638
  // this.displayRoutes(this.expressApp);
630
639
  this.serverTcpUdp.listen(Number(this.uriPort), '0.0.0.0', () => {
631
640
  this.logFramework &&
632
- lib_11.Helpers.log(`[ctx=${this.contextName}] Express server (inside docker) started 0.0.0.0:${this.uriPort}`);
641
+ lib_12.Helpers.log(`[ctx=${this.contextName}] Express server (inside docker) started 0.0.0.0:${this.uriPort}`);
633
642
  this.logFramework &&
634
- lib_11.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
643
+ lib_12.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
635
644
  address: ${this.uriProtocol}//localhost:${this.uriPort}${this.uriPathname}
636
645
  ExpressJS mode: ${this.expressApp.settings.env}
637
646
  `);
@@ -642,9 +651,9 @@ class EndpointContext {
642
651
  // this.displayRoutes(this.expressApp);
643
652
  this.serverTcpUdp.listen(Number(this.uriPort), () => {
644
653
  this.logFramework &&
645
- lib_11.Helpers.log(`[ctx=${this.contextName}] Express server (inside nodejs app) started on localhost:${this.uriPort}`);
654
+ lib_12.Helpers.log(`[ctx=${this.contextName}] Express server (inside nodejs app) started on localhost:${this.uriPort}`);
646
655
  this.logFramework &&
647
- lib_11.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
656
+ lib_12.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
648
657
  address: ${this.uriProtocol}//localhost:${this.uriPort}${this.uriPathname}
649
658
  expressJS mode: ${this.expressApp.settings.env}
650
659
  `);
@@ -655,7 +664,7 @@ class EndpointContext {
655
664
  }
656
665
  else {
657
666
  this.logFramework &&
658
- lib_11.Helpers.info('Ipc communication enable instead tcp/upd');
667
+ lib_12.Helpers.info('Ipc communication enable instead tcp/upd');
659
668
  }
660
669
  //#endregion
661
670
  }
@@ -763,7 +772,7 @@ class EndpointContext {
763
772
  for (const key of Object.keys(classesInput || {})) {
764
773
  const BaseClass = classesInput[key];
765
774
  if (!BaseClass) {
766
- lib_11.Helpers.error(`Class ${key} is not defined in context ${ctx.contextName}
775
+ lib_12.Helpers.error(`Class ${key} is not defined in context ${ctx.contextName}
767
776
 
768
777
  Please check if you have correct import in context file
769
778
 
@@ -842,7 +851,7 @@ class EndpointContext {
842
851
  let entityName = '';
843
852
  // entity thing is only for repositories local repositories
844
853
  // if (className === 'BaseRepository') {
845
- const entityFn = lib_11._.first(locaInstanceConstructorArgs);
854
+ const entityFn = lib_12._.first(locaInstanceConstructorArgs);
846
855
  const entity = entityFn && entityFn();
847
856
  entityName = (entity && class_helpers_1.ClassHelpers.getName(entity)) || '';
848
857
  // console.log(`entityName `, entityName);
@@ -905,7 +914,7 @@ class EndpointContext {
905
914
  //#endregion
906
915
  //#region methods & getters / check if context initialized
907
916
  checkIfContextInitialized() {
908
- if (lib_11._.isUndefined(this.config)) {
917
+ if (lib_12._.isUndefined(this.config)) {
909
918
  throw new Error(`Please check if your context has been initialized.
910
919
 
911
920
  // ...
@@ -1003,7 +1012,7 @@ class EndpointContext {
1003
1012
  ]) {
1004
1013
  //#region init class static _ property
1005
1014
  for (const classFun of this.getClassFunByArr(classTypeName)) {
1006
- if (lib_11._.isFunction(classFun._)) {
1015
+ if (lib_12._.isFunction(classFun._)) {
1007
1016
  await classFun._();
1008
1017
  }
1009
1018
  }
@@ -1021,7 +1030,7 @@ class EndpointContext {
1021
1030
  // `[taon] REINITING _ INS FN ${classTypeName} ${this.contextName} STARTED`,
1022
1031
  // );
1023
1032
  for (const ctrl of this.getClassesInstancesArrBy(classTypeName)) {
1024
- if (lib_11._.isFunction(ctrl._)) {
1033
+ if (lib_12._.isFunction(ctrl._)) {
1025
1034
  await ctrl._();
1026
1035
  }
1027
1036
  }
@@ -1093,7 +1102,7 @@ class EndpointContext {
1093
1102
  return isNonRootProperPathName ? this.uri.pathname.replace(/\/$/, '') : '';
1094
1103
  }
1095
1104
  //#endregion
1096
- //#region port from uri
1105
+ //#region methods & getters / port from uri
1097
1106
  get uriPort() {
1098
1107
  if (!this.uri?.origin?.includes('localhost')) {
1099
1108
  return this.config?.hostPortNumber?.toString();
@@ -1114,12 +1123,15 @@ class EndpointContext {
1114
1123
  return this.uriProtocol === 'https:';
1115
1124
  }
1116
1125
  //#endregion
1117
- //#region methods & getters / public assets
1126
+ //#region methods & getters / is remote host
1127
+ /**
1128
+ * Check if context is for remote only
1129
+ */
1118
1130
  get isRemoteHost() {
1119
1131
  return !!this.cloneOptions?.useAsRemoteContext;
1120
1132
  }
1121
1133
  //#endregion
1122
- //#region methods & getters / public assets
1134
+ //#region methods & getters / context name
1123
1135
  /**
1124
1136
  * ipc/udp needs this
1125
1137
  */
@@ -1128,7 +1140,7 @@ class EndpointContext {
1128
1140
  return this.config?.contextName || this.originalConfig?.contextName;
1129
1141
  }
1130
1142
  //#endregion
1131
- //#region methods & getters / public assets
1143
+ //#region methods & getters / context name for communication
1132
1144
  /**
1133
1145
  * ipc/udp needs this
1134
1146
  */
@@ -1147,7 +1159,7 @@ class EndpointContext {
1147
1159
  return contextName;
1148
1160
  }
1149
1161
  //#endregion
1150
- //#region methods & getters / public assets
1162
+ //#region methods & getters / get context type
1151
1163
  /**
1152
1164
  * Check context type
1153
1165
  */
@@ -1191,8 +1203,8 @@ class EndpointContext {
1191
1203
  return this.config.host;
1192
1204
  }
1193
1205
  //#endregion
1194
- //#region methods & getters / host
1195
- get orgin() {
1206
+ //#region methods & getters / origin
1207
+ get origin() {
1196
1208
  return this.uri?.origin;
1197
1209
  }
1198
1210
  //#endregion
@@ -1221,7 +1233,7 @@ class EndpointContext {
1221
1233
  const entities = this.getClassFunByArr(models_1.Models.ClassType.ENTITY);
1222
1234
  for (const entity of entities) {
1223
1235
  const options = Reflect.getMetadata(symbols_1.Symbols.metadata.options.entity, entity);
1224
- const createTable = lib_11._.isUndefined(options.createTable)
1236
+ const createTable = lib_12._.isUndefined(options.createTable)
1225
1237
  ? true
1226
1238
  : options.createTable;
1227
1239
  const nameForEntity = class_helpers_1.ClassHelpers.getName(entity);
@@ -1269,7 +1281,7 @@ class EndpointContext {
1269
1281
  });
1270
1282
  const subscribers = this.getClassFunByArr(models_1.Models.ClassType.SUBSCRIBER);
1271
1283
  let autoSave = false;
1272
- if (!lib_11._.isNil(this.databaseConfig.autoSave)) {
1284
+ if (!lib_12._.isNil(this.databaseConfig.autoSave)) {
1273
1285
  autoSave = this.databaseConfig.autoSave;
1274
1286
  }
1275
1287
  else {
@@ -1280,7 +1292,7 @@ class EndpointContext {
1280
1292
  autoSave = true; // on docker with sqljs I need to save db
1281
1293
  }
1282
1294
  }
1283
- const dataSourceDbConfig = lib_11._.isObject(this.databaseConfig)
1295
+ const dataSourceDbConfig = lib_12._.isObject(this.databaseConfig)
1284
1296
  ? {
1285
1297
  type: this.databaseConfig.type,
1286
1298
  port: this.databaseConfig.databasePort,
@@ -1309,7 +1321,7 @@ class EndpointContext {
1309
1321
  if (this.modeAllowsDatabaseCreation && this.databaseConfig) {
1310
1322
  this.logDb &&
1311
1323
  this.logFramework &&
1312
- lib_11.Helpers.info('[taon][database] prepare typeorm connection...');
1324
+ lib_12.Helpers.info('[taon][database] prepare typeorm connection...');
1313
1325
  try {
1314
1326
  const connection = new lib_6.DataSource(dataSourceDbConfig);
1315
1327
  this.connection = connection;
@@ -1351,7 +1363,7 @@ class EndpointContext {
1351
1363
  // debugger;
1352
1364
  }
1353
1365
  else {
1354
- lib_11.Helpers.info(`[taon][typeorm] Not initing db for mode ${this.mode}`);
1366
+ lib_12.Helpers.info(`[taon][typeorm] Not initing db for mode ${this.mode}`);
1355
1367
  }
1356
1368
  //#endregion
1357
1369
  }
@@ -1359,7 +1371,7 @@ class EndpointContext {
1359
1371
  //#region methods & getters / initialize metadata
1360
1372
  //#region methods & getters / update class calculate path
1361
1373
  updateCalculatedPathsForControllers(rawConfigs, classConfig, controllerClassFn) {
1362
- const parentsCalculatedPath = lib_11._.slice(rawConfigs, 1)
1374
+ const parentsCalculatedPath = lib_12._.slice(rawConfigs, 1)
1363
1375
  .reverse()
1364
1376
  .map(bc => {
1365
1377
  if (taon_helpers_1.TaonHelpers.isGoodPath(bc.path)) {
@@ -1379,7 +1391,7 @@ class EndpointContext {
1379
1391
  .replace(/\/\//g, '/')
1380
1392
  .split('/')
1381
1393
  .reduce((acc, bc) => {
1382
- return lib_11._.last(acc) === bc ? acc : [...acc, bc];
1394
+ return lib_12._.last(acc) === bc ? acc : [...acc, bc];
1383
1395
  }, [])
1384
1396
  .join('/');
1385
1397
  }
@@ -1389,8 +1401,8 @@ class EndpointContext {
1389
1401
  //#region methods & getters / dedupe class configs
1390
1402
  mergeControllerMethodsConfigs(rawConfigs, classConfig, controllerClassFn) {
1391
1403
  const currentControllerMethodsConfig = classConfig.methods;
1392
- lib_11._.slice(rawConfigs, 1).forEach(bc => {
1393
- const parentControllerMethods = lib_11._.cloneDeep(bc.methods);
1404
+ lib_12._.slice(rawConfigs, 1).forEach(bc => {
1405
+ const parentControllerMethods = lib_12._.cloneDeep(bc.methods);
1394
1406
  for (const methodsName in parentControllerMethods) {
1395
1407
  if (parentControllerMethods.hasOwnProperty(methodsName)) {
1396
1408
  if (!currentControllerMethodsConfig[methodsName]) {
@@ -1411,7 +1423,7 @@ class EndpointContext {
1411
1423
  const allControllers = this.getClassFunByArr(models_1.Models.ClassType.CONTROLLER);
1412
1424
  for (const controllerClassFn of allControllers) {
1413
1425
  const instance = this.getInstanceBy(controllerClassFn);
1414
- if (lib_11._.isFunction(instance.afterAllCtxInited)) {
1426
+ if (lib_12._.isFunction(instance.afterAllCtxInited)) {
1415
1427
  await instance.afterAllCtxInited({ ctxStorage });
1416
1428
  }
1417
1429
  }
@@ -1441,7 +1453,7 @@ class EndpointContext {
1441
1453
  //#region combine middlewares from controllers
1442
1454
  classConfig.calculatedMiddlewaresControllerObj = {};
1443
1455
  [...rawConfigs].reverse().forEach(rc => {
1444
- if (lib_11._.isFunction(rc.middlewares)) {
1456
+ if (lib_12._.isFunction(rc.middlewares)) {
1445
1457
  classConfig.calculatedMiddlewaresControllerObj = rc.middlewares({
1446
1458
  parentMiddlewares: classConfig.calculatedMiddlewaresControllerObj,
1447
1459
  className(middlewareClass) {
@@ -1453,7 +1465,7 @@ class EndpointContext {
1453
1465
  //#endregion
1454
1466
  //#region group start
1455
1467
  //#region @backend
1456
- if (!lib_11.Helpers.isRunningIn.cliMode()) {
1468
+ if (!lib_12.Helpers.isRunningIn.cliMode()) {
1457
1469
  //#endregion
1458
1470
  this.logHttp &&
1459
1471
  console.groupCollapsed(`[taon][express-server] routes [${classConfig.className}]`);
@@ -1470,7 +1482,7 @@ class EndpointContext {
1470
1482
  [...rawConfigs].reverse().forEach(rc => {
1471
1483
  if (rc.methods[methodName]) {
1472
1484
  const parentMethodConfig = rc.methods[methodName];
1473
- if (lib_11._.isFunction(parentMethodConfig.middlewares)) {
1485
+ if (lib_12._.isFunction(parentMethodConfig.middlewares)) {
1474
1486
  calculatedMiddlewaresMethodObj = parentMethodConfig.middlewares({
1475
1487
  parentMiddlewares: calculatedMiddlewaresMethodObj,
1476
1488
  className(middlewareClass) {
@@ -1501,7 +1513,7 @@ class EndpointContext {
1501
1513
  //#endregion
1502
1514
  //#region init server
1503
1515
  // console.log({ expressPath });
1504
- if (lib_11.Helpers.isNode || lib_11.Helpers.isWebSQL) {
1516
+ if (lib_12.Helpers.isNode || lib_12.Helpers.isWebSQL) {
1505
1517
  //#region @websql
1506
1518
  const route = this.initServer(httpMethodType, methodConfig, classConfig, expressPath, controllerClassFn);
1507
1519
  this.activeRoutes.push({
@@ -1512,7 +1524,7 @@ class EndpointContext {
1512
1524
  }
1513
1525
  //#endregion
1514
1526
  //#region init client
1515
- const shouldInitClient = lib_11.Helpers.isBrowser || this.isRemoteHost || lib_11.Helpers.isWebSQL;
1527
+ const shouldInitClient = lib_12.Helpers.isBrowser || this.isRemoteHost || lib_12.Helpers.isWebSQL;
1516
1528
  // console.log('shouldInitClient', shouldInitClient);
1517
1529
  if (shouldInitClient) {
1518
1530
  // console.log(
@@ -1529,7 +1541,7 @@ class EndpointContext {
1529
1541
  //#endregion
1530
1542
  //#region group end
1531
1543
  //#region @backend
1532
- if (!lib_11.Helpers.isRunningIn.cliMode()) {
1544
+ if (!lib_12.Helpers.isRunningIn.cliMode()) {
1533
1545
  //#endregion
1534
1546
  this.logHttp && console.groupEnd();
1535
1547
  //#region @backend
@@ -1541,18 +1553,16 @@ class EndpointContext {
1541
1553
  //#endregion
1542
1554
  //#region methods & getters / write active routes
1543
1555
  writeActiveRoutes() {
1544
- if (this.isRemoteHost ||
1545
- this.isRunOrRevertOnlyMigrationAppStart ||
1546
- this.skipWritingServerRoutes) {
1556
+ if (this.isRemoteHost || this.isRunOrRevertOnlyMigrationAppStart) {
1547
1557
  return;
1548
1558
  }
1549
1559
  // const contexts: EndpointContext[] = [this];
1550
1560
  //#region @websql
1551
- const troutes = lib_9.Utils.uniqArray(this.activeRoutes.map(f => {
1561
+ const troutes = lib_10.Utils.uniqArray(this.activeRoutes.map(f => {
1552
1562
  return `${f.method} ${f.expressPath}`;
1553
1563
  })).map(f => {
1554
1564
  const [method, expressPath] = f.split(' ');
1555
- return (`\n### ${lib_11._.startCase(lib_11._.last(expressPath.split('/')))}\n` +
1565
+ return (`\n### ${lib_12._.startCase(lib_12._.last(expressPath.split('/')))}\n` +
1556
1566
  taon_helpers_1.TaonHelpers.fillUpTo(method.toUpperCase() + ' ', 10) +
1557
1567
  this.uriOrigin +
1558
1568
  expressPath);
@@ -1563,17 +1573,17 @@ class EndpointContext {
1563
1573
  ...['', `# ROUTES FOR HOST ${this.uriOrigin} `],
1564
1574
  ...troutes,
1565
1575
  ].join('\n');
1566
- const fileName = (0, lib_10.crossPlatformPath)([
1576
+ const fileName = (0, lib_11.crossPlatformPath)([
1567
1577
  //#region @backend
1568
1578
  process.cwd(),
1569
1579
  //#endregion
1570
1580
  `routes-${this.config.contextName}.rest`,
1571
1581
  ]);
1572
1582
  this.logFramework && console.log(`[taon] routes file: ${fileName} `);
1573
- // Helpers.log(JSON.stringify(routes, null, 4))
1583
+ this.logRoutes && console.log(routes);
1574
1584
  //#region @backend
1575
- if (!lib_9.UtilsOs.isElectron) {
1576
- lib_11.Helpers.writeFile(fileName, routes);
1585
+ if (!lib_10.UtilsOs.isElectron && !this.skipWritingServerRoutes) {
1586
+ lib_12.Helpers.writeFile(fileName, routes);
1577
1587
  }
1578
1588
  //#endregion
1579
1589
  //#endregion
@@ -1590,7 +1600,7 @@ class EndpointContext {
1590
1600
  async initCustomClientMiddlewares() {
1591
1601
  const middlewares = this.getClassesInstancesArrBy(models_1.Models.ClassType.MIDDLEWARE)
1592
1602
  .map(f => f)
1593
- .filter(f => lib_11._.isFunction(f.interceptClient));
1603
+ .filter(f => lib_12._.isFunction(f.interceptClient));
1594
1604
  middlewares.forEach(middlewareInstanceName => {
1595
1605
  const contextName = this.contextName;
1596
1606
  const interceptorName = `${contextName}-${class_helpers_1.ClassHelpers.getName(middlewareInstanceName)}`;
@@ -1615,7 +1625,7 @@ class EndpointContext {
1615
1625
  const middlewares = this.getClassesInstancesArrBy(models_1.Models.ClassType.MIDDLEWARE);
1616
1626
  for (const middleware of middlewares) {
1617
1627
  const middlewareInstance = middleware;
1618
- if (lib_11._.isFunction(middlewareInstance.interceptServer)) {
1628
+ if (lib_12._.isFunction(middlewareInstance.interceptServer)) {
1619
1629
  const middlewareFn = class_helpers_1.ClassHelpers.asyncHandler(async (req, res, next) => {
1620
1630
  if (req.originalUrl.startsWith(`${this.uriPathnameOrNothingIfRoot}/${constants_1.apiPrefix}/${this.contextName}/`)) {
1621
1631
  await middlewareInstance.interceptServer({
@@ -1651,7 +1661,7 @@ class EndpointContext {
1651
1661
  app.use(methodOverride());
1652
1662
  app.use(cookieParser());
1653
1663
  if (this.session) {
1654
- lib_11.Helpers.info('[taon][express-server] session enabled for this context ' +
1664
+ lib_12.Helpers.info('[taon][express-server] session enabled for this context ' +
1655
1665
  this.contextName);
1656
1666
  const { cookieMaxAge } = this.session;
1657
1667
  const frontendHost = this.config.frontendHost;
@@ -1677,7 +1687,7 @@ class EndpointContext {
1677
1687
  else {
1678
1688
  // if(this.config?.serverLogs) {
1679
1689
  this.logHttp &&
1680
- lib_11.Helpers.info(`[taon][express-server] session not enabled for this context '${this.contextName}'`);
1690
+ lib_12.Helpers.info(`[taon][express-server] session not enabled for this context '${this.contextName}'`);
1681
1691
  // }
1682
1692
  app.use(cors({
1683
1693
  // origin: "http://localhost:5555",
@@ -1734,7 +1744,7 @@ class EndpointContext {
1734
1744
  .map(middlewareClassFun => {
1735
1745
  const middlewareInstance = this.getInstanceBy(middlewareClassFun);
1736
1746
  if (middlewareInstance &&
1737
- lib_11._.isFunction(middlewareInstance.interceptServerMethod)) {
1747
+ lib_12._.isFunction(middlewareInstance.interceptServerMethod)) {
1738
1748
  const middlewareFn = class_helpers_1.ClassHelpers.asyncHandler(async (req, res, next) => {
1739
1749
  await middlewareInstance.interceptServerMethod({
1740
1750
  req,
@@ -1768,7 +1778,7 @@ class EndpointContext {
1768
1778
  //#endregion
1769
1779
  // console.log(`BACKEND: expressPath: "${expressPath}" `);
1770
1780
  //#endregion
1771
- if (lib_11.Helpers.isElectron) {
1781
+ if (lib_12.Helpers.isElectron) {
1772
1782
  //#region @backend
1773
1783
  const ipcKeyName = taon_helpers_1.TaonHelpers.ipcKeyNameRequest(target, methodConfig, expressPath);
1774
1784
  electron_1.ipcMain.on(ipcKeyName, async (event, paramsFromBrowser) => {
@@ -1786,7 +1796,7 @@ class EndpointContext {
1786
1796
  if (!this.isRemoteHost) {
1787
1797
  //#region apply dummy websql express routers
1788
1798
  //#region @websql
1789
- if (lib_11.Helpers.isWebSQL) {
1799
+ if (lib_12.Helpers.isWebSQL) {
1790
1800
  if (!this.expressApp[httpMethodType.toLowerCase()]) {
1791
1801
  this.expressApp[httpMethodType.toLowerCase()] = () => { };
1792
1802
  // TODO add middlewares for WEBSQL and ELECTRON mode
@@ -1795,8 +1805,8 @@ class EndpointContext {
1795
1805
  //#endregion
1796
1806
  //#endregion
1797
1807
  //#region @backend
1798
- this.logHttp &&
1799
- console.log(`[${httpMethodType.toUpperCase()}] ${expressPath} `);
1808
+ // this.logHttp &&
1809
+ // console.log(`[${httpMethodType.toUpperCase()}] ${expressPath} `);
1800
1810
  this.expressApp[httpMethodType.toLowerCase()](expressPath, ...middlewareHandlers, async (req, res) => {
1801
1811
  // console.log(`[${type.toUpperCase()}] ${expressPath} `);
1802
1812
  //#region process params
@@ -1806,13 +1816,13 @@ class EndpointContext {
1806
1816
  let tQuery = req.query;
1807
1817
  if (req.headers[symbols_1.Symbols.old.CIRCURAL_OBJECTS_MAP_BODY]) {
1808
1818
  try {
1809
- tBody = JSON.parse(JSON.stringify(tBody), JSON.parse(req.headers[symbols_1.Symbols.old.CIRCURAL_OBJECTS_MAP_BODY]));
1819
+ tBody = JSON.parse(JSON.stringify(tBody), JSON.parse(taon_helpers_1.TaonHelpers.firstStringOrElemFromArray(req.headers[symbols_1.Symbols.old.CIRCURAL_OBJECTS_MAP_BODY])));
1810
1820
  }
1811
1821
  catch (e) { }
1812
1822
  }
1813
1823
  if (req.headers[symbols_1.Symbols.old.CIRCURAL_OBJECTS_MAP_QUERY_PARAM]) {
1814
1824
  try {
1815
- tQuery = JSON.parse(JSON.stringify(tQuery), JSON.parse(req.headers[symbols_1.Symbols.old.CIRCURAL_OBJECTS_MAP_QUERY_PARAM]));
1825
+ tQuery = JSON.parse(JSON.stringify(tQuery), JSON.parse(taon_helpers_1.TaonHelpers.firstStringOrElemFromArray(req.headers[symbols_1.Symbols.old.CIRCURAL_OBJECTS_MAP_QUERY_PARAM])));
1816
1826
  }
1817
1827
  catch (e) { }
1818
1828
  }
@@ -1820,7 +1830,7 @@ class EndpointContext {
1820
1830
  // console.log('req.headers', req.headers)
1821
1831
  if (req.headers[symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_BODY_PARAMS]) {
1822
1832
  try {
1823
- const entity = JSON.parse(req.headers[symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_BODY_PARAMS]);
1833
+ const entity = JSON.parse(taon_helpers_1.TaonHelpers.firstStringOrElemFromArray(req.headers[symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_BODY_PARAMS]));
1824
1834
  tBody = lib_3.Mapping.encode(tBody, entity);
1825
1835
  }
1826
1836
  catch (e) { }
@@ -1828,7 +1838,7 @@ class EndpointContext {
1828
1838
  else {
1829
1839
  Object.keys(tBody).forEach(paramName => {
1830
1840
  try {
1831
- const entityForParam = JSON.parse(req.headers[`${symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_BODY_PARAMS}${paramName} `]);
1841
+ const entityForParam = JSON.parse(taon_helpers_1.TaonHelpers.firstStringOrElemFromArray(req.headers[`${symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_BODY_PARAMS}${paramName} `]));
1832
1842
  tBody[paramName] = lib_3.Mapping.encode(tBody[paramName], entityForParam);
1833
1843
  }
1834
1844
  catch (e) { }
@@ -1838,7 +1848,7 @@ class EndpointContext {
1838
1848
  // console.log('req.headers', tQuery)
1839
1849
  if (req.headers[symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_QUERY_PARAMS]) {
1840
1850
  try {
1841
- const entity = JSON.parse(req.headers[symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_QUERY_PARAMS]);
1851
+ const entity = JSON.parse(taon_helpers_1.TaonHelpers.firstStringOrElemFromArray(req.headers[symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_QUERY_PARAMS]));
1842
1852
  tQuery = taon_helpers_1.TaonHelpers.parseJSONwithStringJSONs(lib_3.Mapping.encode(tQuery, entity));
1843
1853
  }
1844
1854
  catch (e) { }
@@ -1846,9 +1856,9 @@ class EndpointContext {
1846
1856
  else {
1847
1857
  Object.keys(tQuery).forEach(queryParamName => {
1848
1858
  try {
1849
- const entityForParam = JSON.parse(req.headers[`${symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_QUERY_PARAMS}${queryParamName} `]);
1859
+ const entityForParam = JSON.parse(taon_helpers_1.TaonHelpers.firstStringOrElemFromArray(req.headers[`${symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_QUERY_PARAMS}${queryParamName} `]));
1850
1860
  let beforeTransofrm = tQuery[queryParamName];
1851
- if (lib_11._.isString(beforeTransofrm)) {
1861
+ if (lib_12._.isString(beforeTransofrm)) {
1852
1862
  try {
1853
1863
  const paresed = taon_helpers_1.TaonHelpers.tryTransformParam(beforeTransofrm);
1854
1864
  beforeTransofrm = paresed;
@@ -1896,6 +1906,16 @@ class EndpointContext {
1896
1906
  .map(v => taon_helpers_1.TaonHelpers.tryTransformParam(v));
1897
1907
  try {
1898
1908
  let result = await getResult(resolvedParams, req, res);
1909
+ if (methodConfig.responseType)
1910
+ if (res.headersSent) {
1911
+ // SKIP FURTHER PROCESSING IF RESPONSE ALREADY SENT
1912
+ return;
1913
+ }
1914
+ if (methodConfig.overrideExpressSendAsHtml) {
1915
+ res.setHeader('Content-Type', 'text/html');
1916
+ res.send(result);
1917
+ return;
1918
+ }
1899
1919
  if (result instanceof Blob &&
1900
1920
  methodConfig.responseType ===
1901
1921
  'blob') {
@@ -1910,7 +1930,7 @@ class EndpointContext {
1910
1930
  res.end(file);
1911
1931
  //#endregion
1912
1932
  }
1913
- else if (lib_11._.isString(result) &&
1933
+ else if (lib_12._.isString(result) &&
1914
1934
  methodConfig.responseType ===
1915
1935
  'blob') {
1916
1936
  // console.log('BASE64')
@@ -1936,36 +1956,16 @@ class EndpointContext {
1936
1956
  }
1937
1957
  }
1938
1958
  catch (error) {
1939
- //#region process error
1940
- if (lib_11._.isString(error)) {
1941
- res.status(400).send(lib_1.JSON10.stringify({
1942
- message: `
1943
- Error inside: ${req.path}
1944
-
1945
- ${error}
1946
-
1947
- `,
1948
- }));
1949
- }
1950
- else if (error instanceof models_1.Models.Http.Errors) {
1951
- lib_11.Helpers.error(error, true, false);
1952
- const err = error;
1953
- res.status(400).send(lib_1.JSON10.stringify(err));
1959
+ if (res.headersSent) {
1960
+ // SKIP FURTHER PROCESSING IF RESPONSE ALREADY SENT
1961
+ return;
1954
1962
  }
1955
- else if (error instanceof Error) {
1956
- const err = error;
1957
- lib_11.Helpers.error(error, true, false);
1958
- res.status(400).send(lib_1.JSON10.stringify({
1959
- stack: err.stack,
1960
- message: err.message,
1961
- }));
1963
+ if (methodConfig.overrideExpressSendAsHtml) {
1964
+ res.setHeader('Content-Type', 'text/html');
1965
+ res.send(error);
1966
+ return;
1962
1967
  }
1963
- else {
1964
- lib_11.Helpers.log(error);
1965
- lib_11.Helpers.error(`[Taon] Bad result isomorphic method: ${error} `, true, false);
1966
- res.status(400).send(lib_1.JSON10.stringify(error));
1967
- }
1968
- //#endregion
1968
+ this.sendError(res, error, req, expressPath);
1969
1969
  }
1970
1970
  });
1971
1971
  //#endregion
@@ -1976,6 +1976,43 @@ class EndpointContext {
1976
1976
  };
1977
1977
  }
1978
1978
  //#endregion
1979
+ //#region methods & getters / send error
1980
+ sendError(res, error, req, expressPath) {
1981
+ //#region @backendFunc
1982
+ let status = 500;
1983
+ let message = 'Internal Server Error';
1984
+ let details = undefined;
1985
+ let success = false;
1986
+ let code = undefined;
1987
+ if (typeof error === 'function') {
1988
+ const obj = error(res) || {};
1989
+ status = obj.status || 400;
1990
+ message = obj.message;
1991
+ details = obj.details;
1992
+ code = obj.code;
1993
+ }
1994
+ else if (typeof error === 'string') {
1995
+ message = error;
1996
+ status = 400;
1997
+ }
1998
+ else if (error instanceof Error) {
1999
+ message = error.message;
2000
+ details = process.env.NODE_ENV !== 'production' ? error.stack : undefined;
2001
+ }
2002
+ else {
2003
+ message = 'Unexpected error';
2004
+ details = error;
2005
+ }
2006
+ res.status(status).json({
2007
+ success,
2008
+ message,
2009
+ details,
2010
+ code,
2011
+ [lib_8.CoreModels.TaonHttpErrorCustomProp]: true,
2012
+ });
2013
+ //#endregion
2014
+ }
2015
+ //#endregion
1979
2016
  //#region methods & getters / init client
1980
2017
  /**
1981
2018
  * client can be browser or nodejs (when remote host)
@@ -1990,7 +2027,7 @@ class EndpointContext {
1990
2027
  const middlewares = methodConfig.calculatedMiddlewares;
1991
2028
  const middlewaresInstances = middlewares
1992
2029
  .map(f => this.getInstanceBy(f))
1993
- .filter(f => lib_11._.isFunction(f.interceptClientMethod));
2030
+ .filter(f => lib_12._.isFunction(f.interceptClientMethod));
1994
2031
  middlewaresInstances.forEach(instance => {
1995
2032
  const middlewareName = class_helpers_1.ClassHelpers.getName(instance);
1996
2033
  // middlewareName - only needed for inheritace and uniqness of interceptors
@@ -2010,8 +2047,8 @@ class EndpointContext {
2010
2047
  });
2011
2048
  //#endregion
2012
2049
  // : { received: any; /* Rest<any, any> */ }
2013
- this.logHttp &&
2014
- console.log(`${httpRequestType?.toUpperCase()} ${expressPath} `);
2050
+ // this.logHttp &&
2051
+ // console.log(`${httpRequestType?.toUpperCase()} ${expressPath} `);
2015
2052
  // console.log('INITING', methodConfig); // TODO inject in static
2016
2053
  //#region resolve storage
2017
2054
  // TODO not a good idea
@@ -2019,7 +2056,7 @@ class EndpointContext {
2019
2056
  //#endregion
2020
2057
  const orgMethods = target.prototype[methodConfig.methodName];
2021
2058
  //#region handle electron ipc request
2022
- if (lib_11.Helpers.isElectron) {
2059
+ if (lib_12.Helpers.isElectron) {
2023
2060
  const ipcRenderer = window.require('electron').ipcRenderer;
2024
2061
  target.prototype[methodConfig.methodName] = function (...args) {
2025
2062
  const received = new Promise(async (resolve, reject) => {
@@ -2302,7 +2339,7 @@ class EndpointContext {
2302
2339
  if (mapping) {
2303
2340
  rest.headers.set(symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_QUERY_PARAMS, JSON.stringify(mapping));
2304
2341
  }
2305
- queryParams = lib_11._.cloneDeep(param);
2342
+ queryParams = lib_12._.cloneDeep(param);
2306
2343
  }
2307
2344
  }
2308
2345
  if (currentParam.paramType === 'Header') {