taon 19.0.54 → 19.0.56

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 (156) hide show
  1. package/README.md +160 -160
  2. package/bin/start.js +279 -279
  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 +271 -156
  8. package/browser/fesm2022/taon.mjs.map +1 -1
  9. package/browser/lib/config/controller-config.d.ts +22 -0
  10. package/{websql/lib/decorators/classes → browser/lib/config}/controller-options.d.ts +6 -1
  11. package/browser/lib/config/method-config.d.ts +39 -0
  12. package/browser/lib/config/param-config.d.ts +9 -0
  13. package/browser/lib/decorators/classes/controller-decorator.d.ts +1 -1
  14. package/browser/lib/decorators/http/http-methods-decorators.d.ts +14 -1
  15. package/browser/lib/endpoint-context.d.ts +3 -1
  16. package/browser/lib/helpers/class-helpers.d.ts +5 -2
  17. package/browser/lib/helpers/clone-obj.d.ts +2 -0
  18. package/browser/lib/helpers/taon-helpers.d.ts +5 -5
  19. package/browser/lib/models.d.ts +1 -32
  20. package/browser/lib/symbols.d.ts +0 -2
  21. package/browser/lib/validators.d.ts +2 -2
  22. package/browser/package.json +1 -1
  23. package/lib/base-classes/base-class.js +2 -16
  24. package/lib/base-classes/base-class.js.map +1 -1
  25. package/lib/base-classes/base-controller.js +4 -1
  26. package/lib/base-classes/base-controller.js.map +1 -1
  27. package/lib/build-info._auto-generated_.d.ts +1 -1
  28. package/lib/build-info._auto-generated_.js +1 -1
  29. package/lib/config/controller-config.d.ts +21 -0
  30. package/lib/config/controller-config.js +34 -0
  31. package/lib/config/controller-config.js.map +1 -0
  32. package/lib/{decorators/classes → config}/controller-options.d.ts +6 -1
  33. package/lib/config/controller-options.js +8 -0
  34. package/lib/config/controller-options.js.map +1 -0
  35. package/lib/config/method-config.d.ts +38 -0
  36. package/lib/config/method-config.js +12 -0
  37. package/lib/config/method-config.js.map +1 -0
  38. package/lib/config/param-config.d.ts +8 -0
  39. package/lib/config/param-config.js +8 -0
  40. package/lib/config/param-config.js.map +1 -0
  41. package/lib/decorators/classes/controller-decorator.d.ts +1 -1
  42. package/lib/decorators/classes/controller-decorator.js +6 -1
  43. package/lib/decorators/classes/controller-decorator.js.map +1 -1
  44. package/lib/decorators/classes/middleware-decorator.js.map +1 -1
  45. package/lib/decorators/classes/provider-decorator.js.map +1 -1
  46. package/lib/decorators/decorator-abstract-opt.js +0 -1
  47. package/lib/decorators/decorator-abstract-opt.js.map +1 -1
  48. package/lib/decorators/http/http-methods-decorators.d.ts +14 -1
  49. package/lib/decorators/http/http-methods-decorators.js +3 -10
  50. package/lib/decorators/http/http-methods-decorators.js.map +1 -1
  51. package/lib/decorators/http/http-params-decorators.js +10 -16
  52. package/lib/decorators/http/http-params-decorators.js.map +1 -1
  53. package/lib/endpoint-context.d.ts +3 -1
  54. package/lib/endpoint-context.js +244 -144
  55. package/lib/endpoint-context.js.map +1 -1
  56. package/lib/helpers/class-helpers.d.ts +5 -2
  57. package/lib/helpers/class-helpers.js +47 -35
  58. package/lib/helpers/class-helpers.js.map +1 -1
  59. package/lib/helpers/clone-obj.d.ts +1 -0
  60. package/lib/helpers/clone-obj.js +22 -0
  61. package/lib/helpers/clone-obj.js.map +1 -0
  62. package/lib/helpers/taon-helpers.d.ts +5 -5
  63. package/lib/helpers/taon-helpers.js.map +1 -1
  64. package/lib/models.d.ts +1 -32
  65. package/lib/models.js +0 -33
  66. package/lib/models.js.map +1 -1
  67. package/lib/symbols.d.ts +0 -2
  68. package/lib/symbols.js +5 -7
  69. package/lib/symbols.js.map +1 -1
  70. package/lib/ui/index.js +2 -2
  71. package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
  72. package/lib/validators.d.ts +2 -2
  73. package/lib/validators.js.map +1 -1
  74. package/package.json +1 -1
  75. package/scss/vars.scss +6 -6
  76. package/websql/README.md +24 -24
  77. package/websql/fesm2022/taon.mjs +272 -157
  78. package/websql/fesm2022/taon.mjs.map +1 -1
  79. package/websql/lib/config/controller-config.d.ts +22 -0
  80. package/{browser/lib/decorators/classes → websql/lib/config}/controller-options.d.ts +6 -1
  81. package/websql/lib/config/method-config.d.ts +39 -0
  82. package/websql/lib/config/param-config.d.ts +9 -0
  83. package/websql/lib/decorators/classes/controller-decorator.d.ts +1 -1
  84. package/websql/lib/decorators/http/http-methods-decorators.d.ts +14 -1
  85. package/websql/lib/endpoint-context.d.ts +3 -1
  86. package/websql/lib/helpers/class-helpers.d.ts +5 -2
  87. package/websql/lib/helpers/clone-obj.d.ts +2 -0
  88. package/websql/lib/helpers/taon-helpers.d.ts +5 -5
  89. package/websql/lib/models.d.ts +1 -32
  90. package/websql/lib/symbols.d.ts +0 -2
  91. package/websql/lib/validators.d.ts +2 -2
  92. package/websql/package.json +1 -1
  93. package/browser/lib/decorators/classes/controller-config.d.ts +0 -10
  94. package/lib/decorators/classes/controller-config.d.ts +0 -9
  95. package/lib/decorators/classes/controller-config.js +0 -11
  96. package/lib/decorators/classes/controller-config.js.map +0 -1
  97. package/lib/decorators/classes/controller-options.js +0 -16
  98. package/lib/decorators/classes/controller-options.js.map +0 -1
  99. package/lib/env.d.ts +0 -2
  100. package/lib/env.js +0 -7
  101. package/lib/env.js.map +0 -1
  102. package/lib/storage.d.ts +0 -1
  103. package/lib/storage.js +0 -6
  104. package/lib/storage.js.map +0 -1
  105. package/lib/ui/directives/index.d.ts +0 -3
  106. package/lib/ui/directives/index.js +0 -5
  107. package/lib/ui/directives/index.js.map +0 -1
  108. package/lib/ui/directives/safe.pipe.d.ts +0 -7
  109. package/lib/ui/directives/taon-inject-html.directive.d.ts +0 -6
  110. package/lib/ui/directives/taon-long-press.directive.d.ts +0 -22
  111. package/lib/ui/directives/view-mode.d.ts +0 -5
  112. package/lib/ui/directives/view-mode.js +0 -10
  113. package/lib/ui/directives/view-mode.js.map +0 -1
  114. package/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.d.ts +0 -43
  115. package/lib/ui/taon-admin-mode-configuration/taon-admin.models.d.ts +0 -5
  116. package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js +0 -3
  117. package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js.map +0 -1
  118. package/lib/ui/taon-full-material.module.d.ts +0 -5
  119. package/lib/ui/taon-github-fork-me-corner/index.d.ts +0 -2
  120. package/lib/ui/taon-github-fork-me-corner/index.js +0 -5
  121. package/lib/ui/taon-github-fork-me-corner/index.js.map +0 -1
  122. package/lib/ui/taon-github-fork-me-corner/taon-github-fork-me-corner.component.d.ts +0 -3
  123. package/lib/ui/taon-github-fork-me-corner/taon-github-fork-me-corner.module.d.ts +0 -2
  124. package/lib/ui/taon-github-fork-me-ribbon/index.d.ts +0 -2
  125. package/lib/ui/taon-github-fork-me-ribbon/index.js +0 -5
  126. package/lib/ui/taon-github-fork-me-ribbon/index.js.map +0 -1
  127. package/lib/ui/taon-github-fork-me-ribbon/taon-github-fork-me-ribbon.component.d.ts +0 -3
  128. package/lib/ui/taon-github-fork-me-ribbon/taon-github-fork-me-ribbon.module.d.ts +0 -2
  129. package/lib/ui/taon-notifications/index.d.ts +0 -4
  130. package/lib/ui/taon-notifications/index.js +0 -24
  131. package/lib/ui/taon-notifications/index.js.map +0 -1
  132. package/lib/ui/taon-notifications/taon-notifications.component.d.ts +0 -9
  133. package/lib/ui/taon-notifications/taon-notifications.models.d.ts +0 -6
  134. package/lib/ui/taon-notifications/taon-notifications.models.js +0 -5
  135. package/lib/ui/taon-notifications/taon-notifications.models.js.map +0 -1
  136. package/lib/ui/taon-notifications/taon-notifications.module.d.ts +0 -2
  137. package/lib/ui/taon-notifications/taon-notifications.service.d.ts +0 -11
  138. package/lib/ui/taon-progress-bar/index.d.ts +0 -2
  139. package/lib/ui/taon-progress-bar/index.js +0 -5
  140. package/lib/ui/taon-progress-bar/index.js.map +0 -1
  141. package/lib/ui/taon-progress-bar/taon-progress-bar.component.d.ts +0 -13
  142. package/lib/ui/taon-progress-bar/taon-progress-bar.module.d.ts +0 -2
  143. package/lib/ui/taon-session-passcode/index.d.ts +0 -1
  144. package/lib/ui/taon-session-passcode/index.js +0 -5
  145. package/lib/ui/taon-session-passcode/index.js.map +0 -1
  146. package/lib/ui/taon-session-passcode/taon-session-passcode.component.d.ts +0 -35
  147. package/lib/ui/taon-table/index.d.ts +0 -2
  148. package/lib/ui/taon-table/index.js +0 -5
  149. package/lib/ui/taon-table/index.js.map +0 -1
  150. package/lib/ui/taon-table/taon-table.component.d.ts +0 -34
  151. package/lib/ui/taon-table/taon-table.module.d.ts +0 -2
  152. package/lib/ui/taon.models.d.ts +0 -11
  153. package/lib/ui/taon.models.js +0 -3
  154. package/lib/ui/taon.models.js.map +0 -1
  155. package/tmp-environment.json +0 -39
  156. package/websql/lib/decorators/classes/controller-config.d.ts +0 -10
@@ -4,14 +4,15 @@ import { _, Utils, UtilsMigrations, Helpers, UtilsOs, crossPlatformPath } from '
4
4
  import { __decorate, __metadata, __param } from 'tslib';
5
5
  import * as tsorm from 'taon-typeorm/websql';
6
6
  import { OrignalClassKey, Entity, Table, TableIndex, EventSubscriber, DataSource } from 'taon-typeorm/websql';
7
- import { walk } from 'lodash-walk-object/websql';
8
7
  import { SYMBOL, CLASS } from 'typescript-class-helpers/websql';
8
+ import { walk } from 'lodash-walk-object/websql';
9
9
  import * as i0 from '@angular/core';
10
10
  import { InjectionToken, inject as inject$1, Injectable } from '@angular/core';
11
11
  import axios from 'axios';
12
12
  import { JSON10 } from 'json10/websql';
13
13
  import { Models as Models$1, Resource, RestHeaders, Mapping } from 'ng2-rest/websql';
14
14
  import { Observable, Subject, from } from 'rxjs';
15
+ import { config } from 'tnp-config/websql';
15
16
  import * as JSON5 from 'json5';
16
17
  import { io } from 'socket.io-client';
17
18
  import { MySqlQuerySource } from 'taon-type-sql/websql';
@@ -128,12 +129,33 @@ class DecoratorAbstractOpt {
128
129
  class TaonControllerOptions extends DecoratorAbstractOpt {
129
130
  }
130
131
 
132
+ // import { cloneObj } from '../helpers/clone-obj';
133
+ // import { ParamConfig } from './param-config';
131
134
  class ControllerConfig extends TaonControllerOptions {
132
- constructor() {
133
- super(...arguments);
134
- this.methods = {};
135
- }
136
135
  }
136
+ const controllerConfigFrom = (partial) => {
137
+ const newObj = partial || {};
138
+ newObj.methods = newObj.methods || {};
139
+ for (const methodName in newObj.methods) {
140
+ if (newObj.methods.hasOwnProperty(methodName)) {
141
+ // newObj.methods[methodName] = new MethodConfig().clone(
142
+ // newObj.methods[methodName],
143
+ // );
144
+ newObj.methods[methodName] = newObj.methods[methodName] || {};
145
+ const params = newObj.methods[methodName].parameters || {};
146
+ newObj.methods[methodName].parameters = params
147
+ ? params
148
+ : {};
149
+ for (const paramName in params) {
150
+ if (params.hasOwnProperty(paramName)) {
151
+ params[paramName] = params[paramName] || {};
152
+ // params[paramName] = new ParamConfig().clone(params[paramName]);
153
+ }
154
+ }
155
+ }
156
+ }
157
+ return newObj;
158
+ };
137
159
 
138
160
  var Symbols;
139
161
  (function (Symbols) {
@@ -209,9 +231,7 @@ var Symbols;
209
231
  Symbols.metadata = {
210
232
  className: `class:realname`,
211
233
  options: {
212
- runtimeController: `runtime:controller:options`,
213
234
  controller: `controller:options`,
214
- controllerMethod: `controller:method:options`,
215
235
  entity: `entity:options`,
216
236
  repository: `repository:options`,
217
237
  provider: `provider:options`,
@@ -387,7 +407,7 @@ var ClassHelpers;
387
407
  const classFn = _.isFunction(classFnOrObject)
388
408
  ? classFnOrObject
389
409
  : classFnOrObject.constructor;
390
- const config = Reflect.getMetadata(Symbols.metadata.options.controller, classFn);
410
+ const config = Reflect.getMetadata(Symbols.metadata.options.entity, classFn);
391
411
  return config.uniqueKeyProp;
392
412
  };
393
413
  //#endregion
@@ -429,23 +449,6 @@ var ClassHelpers;
429
449
  return ClassHelpers.hasParentClassWithName(targetProto, className, targets);
430
450
  };
431
451
  //#endregion
432
- //#region get all metadata for controller
433
- ClassHelpers.getControllerConfig = (target) => {
434
- const classMetadataOptions = Reflect.getMetadata(Symbols.metadata.options.controller, target);
435
- const classMetadata = _.merge(new ControllerConfig(), classMetadataOptions);
436
- // Iterate over all methods of the class
437
- const methodNames = ClassHelpers.getMethodsNames(target); // Object.getOwnPropertyNames(target.prototype);
438
- // console.log(`methodNames for ${ClassHelpers.getName(target)} `, methodNames)
439
- for (const methodName of methodNames) {
440
- const methodMetadata = Reflect.getMetadata(Symbols.metadata.options.controllerMethod, target, methodName);
441
- // console.log('methodMetadata for ' + methodName, methodMetadata)
442
- if (methodMetadata) {
443
- classMetadata.methods[methodName] = methodMetadata;
444
- }
445
- }
446
- return classMetadata;
447
- };
448
- //#endregion
449
452
  //#region get methods name
450
453
  //#region not allowed as method name
451
454
  const notAllowedAsMethodName = [
@@ -508,37 +511,81 @@ var ClassHelpers;
508
511
  //#region get controller configs
509
512
  ClassHelpers.getControllerConfigs = (target, configs = [], callerTarget) => {
510
513
  if (!_.isFunction(target)) {
511
- throw `[typescript-class-helper][getClassConfig] Cannot get class config from: ${target}`;
514
+ throw `[typescript-class-helper][getControllerConfigs] Cannot get class config from: ${target}`;
512
515
  }
513
516
  let config;
514
517
  const parentClass = Object.getPrototypeOf(target);
515
518
  const parentName = parentClass ? ClassHelpers.getName(parentClass) : void 0;
516
519
  const isValidParent = _.isFunction(parentClass) && parentName !== '';
517
- config = ClassHelpers.getControllerConfig(target);
520
+ config = controllerConfigFrom(ClassHelpers.getClassConfig(target));
518
521
  configs.push(config);
519
522
  return isValidParent
520
523
  ? ClassHelpers.getControllerConfigs(parentClass, configs, target)
521
524
  : configs;
522
525
  };
523
526
  //#endregion
524
- //#region get path for
525
- // export const getCalculatedPathFor = (target: Function) => {
526
- // const configs = getControllerConfigs(target);
527
- // const parentscalculatedPath = _.slice(configs, 1)
528
- // .reverse()
529
- // .map(bc => {
530
- // if (TaonHelpers.isGoodPath(bc.path)) {
531
- // return bc.path;
532
- // }
533
- // return bc.className;
534
- // })
535
- // .join('/');
536
- // return `/${parentscalculatedPath}/${ClassHelpers.getName(target)}`;
537
- // };
527
+ //#region ensure configs
528
+ // Ensure ClassConfig on constructor, clone parent if needed
529
+ ClassHelpers.ensureClassConfig = (target) => {
530
+ let cfg = Reflect.getOwnMetadata(Symbols.metadata.options.controller, // META_KEYS.class,
531
+ target);
532
+ if (!cfg) {
533
+ cfg = { methods: {} };
534
+ const parent = Object.getPrototypeOf(target);
535
+ if (parent && parent !== Function.prototype) {
536
+ const parentCfg = Reflect.getMetadata(Symbols.metadata.options.controller, // META_KEYS.class,
537
+ parent);
538
+ if (parentCfg) {
539
+ // Deep copy each method config so child gets its own objects
540
+ const clonedMethods = {};
541
+ for (const [k, v] of Object.entries(parentCfg.methods)) {
542
+ clonedMethods[k] = {
543
+ ...v,
544
+ parameters: { ...v.parameters }, // shallow clone parameters too
545
+ };
546
+ }
547
+ cfg = {
548
+ ...parentCfg,
549
+ methods: clonedMethods,
550
+ };
551
+ }
552
+ }
553
+ Reflect.defineMetadata(Symbols.metadata.options.controller, cfg, target);
554
+ }
555
+ return cfg;
556
+ };
557
+ // Ensure MethodConfig inside ClassConfig
558
+ ClassHelpers.ensureMethodConfig = (target, propertyKey) => {
559
+ const classCfg = ClassHelpers.ensureClassConfig(target.constructor);
560
+ let methodCfg = classCfg.methods[propertyKey?.toString()];
561
+ if (!methodCfg) {
562
+ methodCfg = { methodName: propertyKey?.toString(), parameters: {} };
563
+ classCfg.methods[propertyKey?.toString()] = methodCfg;
564
+ }
565
+ return methodCfg;
566
+ };
567
+ ClassHelpers.getClassConfig = (constructor) => {
568
+ return Reflect.getMetadata(Symbols.metadata.options.controller, constructor);
569
+ };
538
570
  //#endregion
539
571
  })(ClassHelpers || (ClassHelpers = {}));
540
572
 
541
- //#region imports
573
+ const cloneObj = (override, classFn) => {
574
+ const result = _.merge(new classFn(), _.cloneDeep(this));
575
+ walk.Object(override || {}, (value, lodashPath) => {
576
+ if (_.isNil(value) || _.isFunction(value) || _.isObject(value)) {
577
+ // skipping
578
+ }
579
+ else {
580
+ _.set(result, lodashPath, value);
581
+ }
582
+ }, {
583
+ walkGetters: false,
584
+ });
585
+ // console.log({result})
586
+ return result;
587
+ };
588
+
542
589
  //#endregion
543
590
  class BaseClass {
544
591
  //#region class initialization hook
@@ -551,19 +598,7 @@ class BaseClass {
551
598
  //#region clone
552
599
  clone(override) {
553
600
  const classFn = ClassHelpers.getClassFnFromObject(this);
554
- const result = _.merge(new classFn(), _.cloneDeep(this));
555
- walk.Object(override || {}, (value, lodashPath) => {
556
- if (_.isNil(value) || _.isFunction(value) || _.isObject(value)) {
557
- // skipping
558
- }
559
- else {
560
- _.set(result, lodashPath, value);
561
- }
562
- }, {
563
- walkGetters: false,
564
- });
565
- // console.log({result})
566
- return result;
601
+ return cloneObj(override, classFn);
567
602
  }
568
603
  }
569
604
 
@@ -820,22 +855,6 @@ var Models;
820
855
  }
821
856
  Models.DatabaseConfig = DatabaseConfig;
822
857
  //#endregion
823
- //#region models / param config
824
- class ParamConfig {
825
- }
826
- Models.ParamConfig = ParamConfig;
827
- //#endregion
828
- //#region models / method config
829
- /**
830
- * @link './decorators/http/http-methods-decorators.ts' TaonHttpDecoratorOptions
831
- */
832
- class MethodConfig {
833
- constructor() {
834
- this.parameters = {};
835
- }
836
- }
837
- Models.MethodConfig = MethodConfig;
838
- //#endregion
839
858
  //#region models / http
840
859
  let Http;
841
860
  (function (Http) {
@@ -3078,6 +3097,8 @@ class EndpointContext {
3078
3097
  /* */
3079
3098
  /* */
3080
3099
  /* */
3100
+ /* */
3101
+ /* */
3081
3102
  await this.initCustomClientMiddlewares();
3082
3103
  }
3083
3104
  //#endregion
@@ -3598,15 +3619,12 @@ class EndpointContext {
3598
3619
  return url;
3599
3620
  }
3600
3621
  //#endregion
3601
- get uriPort() {
3602
- if (!this.uri?.origin?.includes('localhost')) {
3603
- return this.config?.hostPortNumber?.toString();
3604
- }
3605
- return this.uri?.port;
3606
- }
3622
+ //#region methods & getters / host uri protocol
3607
3623
  get uriProtocol() {
3608
3624
  return this.uri?.protocol;
3609
3625
  }
3626
+ //#endregion
3627
+ //#region methods & getters / host uri origin
3610
3628
  /**
3611
3629
  * Examples
3612
3630
  * http://localhost:3000
@@ -3615,6 +3633,8 @@ class EndpointContext {
3615
3633
  get uriOrigin() {
3616
3634
  return this.uri?.origin;
3617
3635
  }
3636
+ //#endregion
3637
+ //#region methods & getters / host uri pathname
3618
3638
  /**
3619
3639
  * Exampels
3620
3640
  * http://localhost:3000/path/to/somewhere
@@ -3628,6 +3648,8 @@ class EndpointContext {
3628
3648
  get uriPathname() {
3629
3649
  return this.uri?.pathname;
3630
3650
  }
3651
+ //#endregion
3652
+ //#region methods & getters / uri pathname or nothing if root
3631
3653
  /**
3632
3654
  * Examples
3633
3655
  * http://localhost:3000/path/to/somewhere -> '/path/to/somewhere'
@@ -3638,6 +3660,15 @@ class EndpointContext {
3638
3660
  const isNonRootProperPathName = this.uri?.pathname && this.uri.pathname !== '/';
3639
3661
  return isNonRootProperPathName ? this.uri.pathname.replace(/\/$/, '') : '';
3640
3662
  }
3663
+ //#endregion
3664
+ //#region port from uri
3665
+ get uriPort() {
3666
+ if (!this.uri?.origin?.includes('localhost')) {
3667
+ return this.config?.hostPortNumber?.toString();
3668
+ }
3669
+ return this.uri?.port;
3670
+ }
3671
+ // TODO do i need 2 getters for port?
3641
3672
  /**
3642
3673
  * Port from uri as number
3643
3674
  * @returns {Number | undefined}
@@ -3645,6 +3676,7 @@ class EndpointContext {
3645
3676
  get port() {
3646
3677
  return this.uri?.port ? Number(this.uriPort) : undefined;
3647
3678
  }
3679
+ //#endregion
3648
3680
  //#region methods & getters / is https server
3649
3681
  get isHttpServer() {
3650
3682
  return this.uriProtocol === 'https:';
@@ -3658,15 +3690,21 @@ class EndpointContext {
3658
3690
  return this.config.contextName;
3659
3691
  }
3660
3692
  //#endregion
3693
+ //#region methods & getters / current working directory
3661
3694
  get cwd() {
3662
3695
  return this.config.cwd || process.cwd();
3663
3696
  }
3697
+ //#endregion
3698
+ //#region methods & getters / active context
3664
3699
  get activeContext() {
3665
3700
  return this.config.activeContext || null;
3666
3701
  }
3702
+ //#endregion
3703
+ //#region methods & getters / app id
3667
3704
  get appId() {
3668
3705
  return this.config.appId;
3669
3706
  }
3707
+ //#endregion
3670
3708
  //#region methods & getters / public assets
3671
3709
  get publicAssets() {
3672
3710
  return this.config?.publicAssets || [];
@@ -3852,66 +3890,124 @@ class EndpointContext {
3852
3890
  }
3853
3891
  //#endregion
3854
3892
  //#region methods & getters / initialize metadata
3893
+ //#region methods & getters / update class calculate path
3894
+ updateCalculatedPathsForControllers(rawConfigs, classConfig, controllerClassFn) {
3895
+ const parentsCalculatedPath = _.slice(rawConfigs, 1)
3896
+ .reverse()
3897
+ .map(bc => {
3898
+ if (TaonHelpers.isGoodPath(bc.path)) {
3899
+ return bc.path;
3900
+ }
3901
+ return bc.className;
3902
+ })
3903
+ .join('/');
3904
+ if (TaonHelpers.isGoodPath(classConfig.path)) {
3905
+ classConfig.calculatedPath = classConfig.path;
3906
+ }
3907
+ else {
3908
+ classConfig.calculatedPath = (`${this.uriPathnameOrNothingIfRoot}` +
3909
+ `/${apiPrefix}/${this.contextName}/tcp${parentsCalculatedPath}/` +
3910
+ `${ClassHelpers.getName(controllerClassFn)}`)
3911
+ .replace(/\/\//g, '/')
3912
+ .split('/')
3913
+ .reduce((acc, bc) => {
3914
+ return _.last(acc) === bc ? acc : [...acc, bc];
3915
+ }, [])
3916
+ .join('/');
3917
+ }
3918
+ // console.log('calculatedPath', classConfig.calculatedPath);
3919
+ }
3920
+ //#endregion
3921
+ //#region methods & getters / dedupe class configs
3922
+ mergeControllerMethodsConfigs(rawConfigs, classConfig, controllerClassFn) {
3923
+ const currentControllerMethodsConfig = classConfig.methods;
3924
+ _.slice(rawConfigs, 1).forEach(bc => {
3925
+ const parentControllerMethods = _.cloneDeep(bc.methods);
3926
+ for (const methodsName in parentControllerMethods) {
3927
+ if (parentControllerMethods.hasOwnProperty(methodsName)) {
3928
+ if (!currentControllerMethodsConfig[methodsName]) {
3929
+ //#region add non existed method
3930
+ const methodConfig = parentControllerMethods[methodsName];
3931
+ currentControllerMethodsConfig[methodsName] = methodConfig;
3932
+ //#endregion
3933
+ }
3934
+ }
3935
+ }
3936
+ });
3937
+ }
3938
+ //#endregion
3855
3939
  async initControllers() {
3856
3940
  if (this.isRunOrRevertOnlyMigrationAppStart) {
3857
3941
  return;
3858
3942
  }
3859
3943
  const allControllers = this.getClassFunByArr(Models.ClassType.CONTROLLER);
3944
+ // debugger
3860
3945
  // console.log('allControllers', allControllers);
3861
3946
  for (const controllerClassFn of allControllers) {
3947
+ // console.log(ClassHelpers.getClassConfig(controllerClassFn));
3948
+ // const controllerName = ClassHelpers.getName(controllerClassFn);
3949
+ // console.log(
3950
+ // `for ${controllerName}`,
3951
+ // ClassHelpers.getClassConfig(controllerClassFn),
3952
+ // );
3862
3953
  controllerClassFn[Symbols.classMethodsNames] =
3863
3954
  ClassHelpers.getMethodsNames(controllerClassFn);
3864
- const configs = ClassHelpers.getControllerConfigs(controllerClassFn);
3955
+ const rawConfigs = ClassHelpers.getControllerConfigs(controllerClassFn);
3956
+ // console.log(controllerName, { rawConfigs });
3865
3957
  // console.log(`Class config for ${ClassHelpers.getName(controllerClassFn)}`, configs)
3866
- const classConfig = configs[0];
3867
- //#region update class calculate path
3868
- const parentscalculatedPath = _.slice(configs, 1)
3869
- .reverse()
3870
- .map(bc => {
3871
- if (TaonHelpers.isGoodPath(bc.path)) {
3872
- return bc.path;
3873
- }
3874
- return bc.className;
3875
- })
3876
- .join('/');
3877
- if (TaonHelpers.isGoodPath(classConfig.path)) {
3878
- classConfig.calculatedPath = classConfig.path;
3879
- }
3880
- else {
3881
- classConfig.calculatedPath = (`${this.uriPathnameOrNothingIfRoot}` +
3882
- `/${apiPrefix}/${this.contextName}/tcp${parentscalculatedPath}/` +
3883
- `${ClassHelpers.getName(controllerClassFn)}`)
3884
- .replace(/\/\//g, '/')
3885
- .split('/')
3886
- .reduce((acc, bc) => {
3887
- return _.last(acc) === bc ? acc : [...acc, bc];
3888
- }, [])
3889
- .join('/');
3890
- }
3891
- //#endregion
3892
- // console.log('calculatedPath', classConfig.calculatedPath);
3893
- _.slice(configs, 1).forEach(bc => {
3894
- const alreadyIs = classConfig.methods;
3895
- const toMerge = _.cloneDeep(bc.methods);
3896
- for (const key in toMerge) {
3897
- if (toMerge.hasOwnProperty(key) && !alreadyIs[key]) {
3898
- const element = toMerge[key];
3899
- alreadyIs[key] = element;
3900
- }
3958
+ const classConfig = rawConfigs[0];
3959
+ this.updateCalculatedPathsForControllers(rawConfigs, classConfig, controllerClassFn);
3960
+ this.mergeControllerMethodsConfigs(rawConfigs, classConfig, controllerClassFn);
3961
+ //#region combine middlewares from controllers
3962
+ classConfig.calculatedMiddlewaresControllerObj = {};
3963
+ [...rawConfigs].reverse().forEach(rc => {
3964
+ if (_.isFunction(rc.middlewares)) {
3965
+ classConfig.calculatedMiddlewaresControllerObj = rc.middlewares({
3966
+ parentMiddlewares: classConfig.calculatedMiddlewaresControllerObj,
3967
+ className(middlewareClass) {
3968
+ return ClassHelpers.getName(controllerClassFn);
3969
+ },
3970
+ });
3901
3971
  }
3902
3972
  });
3973
+ //#endregion
3974
+ //#region group start
3903
3975
  /* */
3904
3976
  /* */
3905
3977
  this.logHttp &&
3906
3978
  console.groupCollapsed(`[taon][express-server] routes [${classConfig.className}]`);
3907
3979
  /* */
3908
3980
  /* */
3909
- // console.log('methods', classConfig.methods);
3981
+ //#endregion
3982
+ //#region init client or server methods
3910
3983
  const methodNames = Object.keys(classConfig.methods);
3911
3984
  for (const methodName of methodNames) {
3912
3985
  const methodConfig = classConfig.methods[methodName];
3913
- // debugger
3914
- const type = methodConfig.type;
3986
+ //#region combine all class methods middlewares
3987
+ let calculatedMiddlewaresMethodObj = {};
3988
+ [...rawConfigs].reverse().forEach(rc => {
3989
+ if (rc.methods[methodName]) {
3990
+ const parentMethodConfig = rc.methods[methodName];
3991
+ if (_.isFunction(parentMethodConfig.middlewares)) {
3992
+ calculatedMiddlewaresMethodObj = parentMethodConfig.middlewares({
3993
+ parentMiddlewares: calculatedMiddlewaresMethodObj,
3994
+ className(middlewareClass) {
3995
+ return ClassHelpers.getName(controllerClassFn);
3996
+ },
3997
+ });
3998
+ }
3999
+ }
4000
+ });
4001
+ // add class middlewares to method middlewares
4002
+ methodConfig.calculatedMiddlewaresMethodObj = {
4003
+ ...calculatedMiddlewaresMethodObj,
4004
+ ...classConfig.calculatedMiddlewaresControllerObj,
4005
+ };
4006
+ methodConfig.calculatedMiddlewares = Object.values(methodConfig.calculatedMiddlewaresMethodObj || {});
4007
+ //#endregion
4008
+ // methodConfig.calculatedMiddlewares = TODO
4009
+ //#region initialized method express path
4010
+ const httpMethodType = methodConfig.type;
3915
4011
  // this is quick fix - in docker global path should not be used
3916
4012
  const globalPathPart = this.isRunningInsideDocker ||
3917
4013
  !this.frontendHostUri?.origin?.includes('localhost') // fe with domain -> is in docker
@@ -3920,16 +4016,20 @@ class EndpointContext {
3920
4016
  const expressPath = methodConfig.global
3921
4017
  ? `${globalPathPart}/${methodConfig.path?.replace(/\/$/, '')}`.replace(/\/\//, '/')
3922
4018
  : TaonHelpers.getExpressPath(classConfig, methodConfig);
4019
+ //#endregion
4020
+ //#region init server
3923
4021
  // console.log({ expressPath });
3924
4022
  if (Helpers.isNode || Helpers.isWebSQL) {
3925
4023
  //#region @websql
3926
- const route = this.initServer(type, methodConfig, classConfig, expressPath, controllerClassFn);
4024
+ const route = this.initServer(httpMethodType, methodConfig, classConfig, expressPath, controllerClassFn);
3927
4025
  this.activeRoutes.push({
3928
4026
  expressPath: route.expressPath,
3929
4027
  method: route.method,
3930
4028
  });
3931
4029
  //#endregion
3932
4030
  }
4031
+ //#endregion
4032
+ //#region init client
3933
4033
  const shouldInitClient = Helpers.isBrowser || this.remoteHost || Helpers.isWebSQL;
3934
4034
  // console.log('shouldInitClient', shouldInitClient);
3935
4035
  if (shouldInitClient) {
@@ -3940,14 +4040,18 @@ class EndpointContext {
3940
4040
  // methodConfig,
3941
4041
  // expressPath,
3942
4042
  // );
3943
- await this.initClient(controllerClassFn, type, methodConfig, expressPath);
4043
+ await this.initClient(controllerClassFn, httpMethodType, methodConfig, expressPath);
3944
4044
  }
4045
+ //#endregion
3945
4046
  }
4047
+ //#endregion
4048
+ //#region group end
3946
4049
  /* */
3947
4050
  /* */
3948
4051
  this.logHttp && console.groupEnd();
3949
4052
  /* */
3950
4053
  /* */
4054
+ //#endregion
3951
4055
  }
3952
4056
  }
3953
4057
  //#endregion
@@ -4001,15 +4105,15 @@ class EndpointContext {
4001
4105
  const middlewares = this.getClassesInstancesArrBy(Models.ClassType.MIDDLEWARE)
4002
4106
  .map(f => f)
4003
4107
  .filter(f => _.isFunction(f.interceptClient));
4004
- middlewares.forEach(instance => {
4108
+ middlewares.forEach(middlewareInstanceName => {
4005
4109
  const contextName = this.contextName;
4006
- const interceptorName = `${contextName}-${ClassHelpers.getName(instance)}`;
4110
+ const interceptorName = `${contextName}-${ClassHelpers.getName(middlewareInstanceName)}`;
4007
4111
  Resource.request.interceptors.set(interceptorName, {
4008
4112
  intercept: ({ req, next }) => {
4009
4113
  const url = new URL(req.url);
4010
4114
  if (url.pathname.startsWith(`${this.uriPathnameOrNothingIfRoot}/${apiPrefix}/${contextName}/`)) {
4011
4115
  // console.log('intercepting', url.pathname, req);
4012
- return instance.interceptClient({
4116
+ return middlewareInstanceName.interceptClient({
4013
4117
  req,
4014
4118
  next,
4015
4119
  });
@@ -4167,10 +4271,10 @@ class EndpointContext {
4167
4271
  //#region parameters
4168
4272
  httpMethodType, methodConfig, classConfig, expressPath, target) {
4169
4273
  //#region resolve variables
4170
- const middlewareHandlers = (Array.isArray(methodConfig.middlewares) &&
4171
- methodConfig.middlewares?.length > 0
4172
- ? methodConfig.middlewares
4173
- : [])
4274
+ // console.log(
4275
+ // `CLIENT: expressPath: "${expressPath}" interceptor for method: ${methodConfig.calculatedMiddlewares.length}`,
4276
+ // );
4277
+ const middlewareHandlers = methodConfig.calculatedMiddlewares
4174
4278
  .map(middlewareClassFun => {
4175
4279
  const middlewareInstance = this.getInstanceBy(middlewareClassFun);
4176
4280
  if (middlewareInstance &&
@@ -4459,7 +4563,6 @@ class EndpointContext {
4459
4563
  /* */
4460
4564
  /* */
4461
4565
  /* */
4462
- /* */
4463
4566
  }
4464
4567
  return {
4465
4568
  expressPath: expressPath,
@@ -4471,17 +4574,22 @@ class EndpointContext {
4471
4574
  /**
4472
4575
  * client can be browser or nodejs (when remote host)
4473
4576
  */
4474
- async initClient(
4475
- //#region parameters
4476
- target, httpRequestType, methodConfig, // Models.Http.Rest.MethodConfig,
4577
+ async initClient(target, httpRequestType, methodConfig, // Models.Http.Rest.MethodConfig,
4477
4578
  expressPath) {
4478
4579
  const ctx = this;
4580
+ // console.log(
4581
+ // `CLIENT: expressPath: "${expressPath}" interceptor for method: ${methodConfig.calculatedMiddlewares?.length} `,
4582
+ // );
4479
4583
  //#region init middlewares
4480
- const middlewares = methodConfig.middlewares
4584
+ const middlewares = methodConfig.calculatedMiddlewares;
4585
+ const middlewaresInstances = middlewares
4481
4586
  .map(f => this.getInstanceBy(f))
4482
4587
  .filter(f => _.isFunction(f.interceptClientMethod));
4483
- middlewares.forEach(instance => {
4484
- Resource.request.methodsInterceptors.set(`${methodConfig.type?.toUpperCase()}-${expressPath}`, {
4588
+ middlewaresInstances.forEach(instance => {
4589
+ const middlewareName = ClassHelpers.getName(instance);
4590
+ // middlewareName - only needed for inheritace and uniqness of interceptors
4591
+ const interceptorKey = `${middlewareName}-${methodConfig.type?.toUpperCase()}-${expressPath}`;
4592
+ Resource.request.methodsInterceptors.set(interceptorKey, {
4485
4593
  intercept: ({ req, next }) => {
4486
4594
  return instance.interceptClientMethod({
4487
4595
  req,
@@ -4727,6 +4835,14 @@ class EndpointContext {
4727
4835
  break;
4728
4836
  }
4729
4837
  }
4838
+ if (!currentParam) {
4839
+ const errorMessage = `[${config.frameworkName}] Unable to resolve parameter` +
4840
+ ` at index ${i} for method ${methodConfig.methodName} at path ${expressPath}.`;
4841
+ /* */
4842
+ /* */
4843
+ /* */
4844
+ throw new Error(errorMessage);
4845
+ }
4730
4846
  if (currentParam.paramType === 'Path') {
4731
4847
  pathPrams[currentParam.paramName] = param;
4732
4848
  }
@@ -4812,7 +4928,9 @@ instead
4812
4928
  }
4813
4929
  //#endregion
4814
4930
  const httpResultObj = {
4815
- received: rest.model(pathPrams)[method](bodyObject, [queryParams]),
4931
+ get received() {
4932
+ return rest.model(pathPrams)[method](bodyObject, [queryParams]);
4933
+ },
4816
4934
  request(axiosConfig) {
4817
4935
  return rest
4818
4936
  .model(pathPrams)[method](bodyObject, [queryParams], axiosConfig);
@@ -5943,12 +6061,18 @@ var baseContext = /*#__PURE__*/Object.freeze({
5943
6061
  function TaonController(options) {
5944
6062
  return function (constructor) {
5945
6063
  ClassHelpers.setName(constructor, options?.className);
5946
- Reflect.defineMetadata(Symbols.metadata.options.controller, options, constructor);
5947
6064
  Reflect.defineMetadata(Symbols.metadata.className, options?.className || constructor.name, constructor);
6065
+ const cfg = ClassHelpers.ensureClassConfig(constructor);
6066
+ options = options || {};
6067
+ cfg.className = options.className || constructor.name;
6068
+ cfg.path = options.path || '';
6069
+ cfg.realtime = options.realtime;
6070
+ cfg.middlewares = options.middlewares;
5948
6071
  };
5949
6072
  }
5950
6073
 
5951
6074
  const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal) => {
6075
+ const methodConfig = ClassHelpers.ensureMethodConfig(target, propertyKey);
5952
6076
  let options;
5953
6077
  if (typeof pathOrOptions === 'object') {
5954
6078
  options = pathOrOptions;
@@ -5960,13 +6084,8 @@ const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, p
5960
6084
  options = { pathOrOptions, pathIsGlobal };
5961
6085
  }
5962
6086
  const { overrideContentType, overrideResponseType, middlewares } = options;
5963
- let methodConfig = Reflect.getMetadata(Symbols.metadata.options.controllerMethod, target.constructor, propertyKey);
5964
- if (!methodConfig) {
5965
- methodConfig = new Models.MethodConfig();
5966
- Reflect.defineMetadata(Symbols.metadata.options.controllerMethod, methodConfig, target.constructor, propertyKey);
5967
- }
5968
6087
  methodConfig.methodName = propertyKey;
5969
- methodConfig.middlewares = middlewares || [];
6088
+ methodConfig.middlewares = middlewares;
5970
6089
  methodConfig.type = method;
5971
6090
  if (!path) {
5972
6091
  let paramsPathConcatedPath = '';
@@ -5989,8 +6108,6 @@ const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, p
5989
6108
  methodConfig.global = pathIsGlobal;
5990
6109
  methodConfig.contentType = overrideContentType;
5991
6110
  methodConfig.responseType = overrideResponseType;
5992
- Reflect.defineMetadata(Symbols.metadata.options.controllerMethod, methodConfig, target.constructor, propertyKey);
5993
- // console.log('methods updated', methodConfig);
5994
6111
  };
5995
6112
  function GET(pathOrOptions, pathIsGlobal = false) {
5996
6113
  return function (target, propertyKey, descriptor) {
@@ -6024,21 +6141,16 @@ function DELETE(pathOrOptions, pathIsGlobal = false) {
6024
6141
  }
6025
6142
 
6026
6143
  function metaParam(param, name, expire, defaultValue = undefined, target, propertyKey, parameterIndex) {
6027
- let methodConfig = Reflect.getMetadata(Symbols.metadata.options.controllerMethod, target.constructor, propertyKey);
6028
- if (!methodConfig) {
6029
- methodConfig = new Models.MethodConfig();
6030
- Reflect.defineMetadata(Symbols.metadata.options.controllerMethod, methodConfig, target.constructor, propertyKey);
6031
- }
6144
+ const methodCfg = ClassHelpers.ensureMethodConfig(target, propertyKey);
6032
6145
  const nameKey = name ? name : param;
6033
- const p = (methodConfig.parameters[nameKey] = !methodConfig.parameters[nameKey]
6034
- ? new Models.ParamConfig()
6035
- : methodConfig.parameters[nameKey]);
6036
- p.index = parameterIndex;
6037
- p.paramName = name;
6038
- p.paramType = param;
6039
- p.defaultType = defaultValue;
6040
- p.expireInSeconds = expire;
6041
- Reflect.defineMetadata(Symbols.metadata.options.controllerMethod, methodConfig, target.constructor, propertyKey);
6146
+ // const key = name || `${param}_${parameterIndex}`;
6147
+ methodCfg.parameters[nameKey] = {
6148
+ index: parameterIndex,
6149
+ paramName: name,
6150
+ paramType: param,
6151
+ defaultType: defaultValue,
6152
+ expireInSeconds: expire,
6153
+ };
6042
6154
  // console.log('params updated', methodConfig);
6043
6155
  }
6044
6156
  function Path(name) {
@@ -6116,7 +6228,10 @@ let BaseController = class BaseController extends BaseInjector {
6116
6228
  __decorate([
6117
6229
  POST({
6118
6230
  overrideContentType: 'multipart/form-data',
6119
- middlewares: [BaseFileUploadMiddleware],
6231
+ middlewares: ({ parentMiddlewares }) => ({
6232
+ ...parentMiddlewares,
6233
+ BaseFileUploadMiddleware,
6234
+ }),
6120
6235
  }),
6121
6236
  __param(0, Body()),
6122
6237
  __metadata("design:type", Function),