taon 19.0.55 → 19.0.58
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.
- package/README.md +160 -160
- package/bin/start.js +279 -279
- package/bin/taon +6 -6
- package/bin/taon-debug +5 -5
- package/bin/taon-debug-brk +5 -5
- package/browser/README.md +24 -24
- package/browser/fesm2022/taon.mjs +299 -201
- package/browser/fesm2022/taon.mjs.map +1 -1
- package/browser/lib/base-classes/base-angular-service.d.ts +16 -0
- package/browser/lib/base-classes/base-context.d.ts +0 -9
- package/browser/lib/base-classes/base-controller.d.ts +1 -1
- package/browser/lib/base-classes/base-file-upload.middleware.d.ts +2 -2
- package/browser/lib/base-classes/base-middleware.d.ts +3 -3
- package/browser/lib/base-classes/base.d.ts +0 -9
- package/browser/lib/config/controller-config.d.ts +22 -0
- package/browser/lib/{decorators/classes → config}/controller-options.d.ts +6 -1
- package/browser/lib/config/method-config.d.ts +39 -0
- package/browser/lib/config/param-config.d.ts +9 -0
- package/browser/lib/constants.d.ts +2 -1
- package/browser/lib/create-context.d.ts +2 -20
- package/browser/lib/decorators/classes/controller-decorator.d.ts +1 -1
- package/browser/lib/decorators/http/http-methods-decorators.d.ts +14 -1
- package/browser/lib/endpoint-context.d.ts +3 -1
- package/browser/lib/helpers/class-helpers.d.ts +5 -2
- package/browser/lib/helpers/clone-obj.d.ts +2 -0
- package/browser/lib/helpers/taon-helpers.d.ts +5 -5
- package/browser/lib/index.d.ts +1 -28
- package/browser/lib/models.d.ts +0 -31
- package/browser/lib/symbols.d.ts +0 -2
- package/browser/lib/validators.d.ts +2 -2
- package/browser/package.json +1 -1
- package/lib/base-classes/base-angular-service.d.ts +16 -0
- package/lib/base-classes/base-angular-service.js +32 -0
- package/lib/base-classes/base-angular-service.js.map +1 -1
- package/lib/base-classes/base-class.js +2 -16
- package/lib/base-classes/base-class.js.map +1 -1
- package/lib/base-classes/base-context.d.ts +0 -9
- package/lib/base-classes/base-controller.d.ts +1 -1
- package/lib/base-classes/base-controller.js +4 -1
- package/lib/base-classes/base-controller.js.map +1 -1
- package/lib/base-classes/base-file-upload.middleware.d.ts +2 -2
- package/lib/base-classes/base-file-upload.middleware.js.map +1 -1
- package/lib/base-classes/base-middleware.d.ts +3 -3
- package/lib/base-classes/base.d.ts +0 -9
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/config/controller-config.d.ts +21 -0
- package/lib/config/controller-config.js +34 -0
- package/lib/config/controller-config.js.map +1 -0
- package/lib/config/controller-options.d.ts +16 -0
- package/lib/config/controller-options.js +8 -0
- package/lib/config/controller-options.js.map +1 -0
- package/lib/config/method-config.d.ts +38 -0
- package/lib/config/method-config.js +12 -0
- package/lib/config/method-config.js.map +1 -0
- package/lib/config/param-config.d.ts +8 -0
- package/lib/config/param-config.js +8 -0
- package/lib/config/param-config.js.map +1 -0
- package/lib/constants.d.ts +2 -1
- package/lib/constants.js +6 -1
- package/lib/constants.js.map +1 -1
- package/lib/create-context.d.ts +2 -20
- package/lib/create-context.js +1 -44
- package/lib/create-context.js.map +1 -1
- package/lib/decorators/classes/controller-config.d.ts +11 -0
- package/lib/decorators/classes/controller-config.js +10 -0
- package/lib/decorators/classes/controller-config.js.map +1 -1
- package/lib/decorators/classes/controller-decorator.d.ts +1 -1
- package/lib/decorators/classes/controller-decorator.js +6 -1
- package/lib/decorators/classes/controller-decorator.js.map +1 -1
- package/lib/decorators/classes/controller-options.d.ts +5 -0
- package/lib/decorators/classes/controller-options.js +4 -0
- package/lib/decorators/classes/controller-options.js.map +1 -1
- package/lib/decorators/classes/middleware-decorator.js.map +1 -1
- package/lib/decorators/classes/provider-decorator.js.map +1 -1
- package/lib/decorators/decorator-abstract-opt.js +0 -1
- package/lib/decorators/decorator-abstract-opt.js.map +1 -1
- package/lib/decorators/http/http-methods-decorators.d.ts +14 -1
- package/lib/decorators/http/http-methods-decorators.js +3 -10
- package/lib/decorators/http/http-methods-decorators.js.map +1 -1
- package/lib/decorators/http/http-params-decorators.js +10 -16
- package/lib/decorators/http/http-params-decorators.js.map +1 -1
- package/lib/endpoint-context.d.ts +3 -1
- package/lib/endpoint-context.js +241 -143
- package/lib/endpoint-context.js.map +1 -1
- package/lib/helpers/class-helpers.d.ts +5 -2
- package/lib/helpers/class-helpers.js +47 -35
- package/lib/helpers/class-helpers.js.map +1 -1
- package/lib/helpers/clone-obj.d.ts +1 -0
- package/lib/helpers/clone-obj.js +22 -0
- package/lib/helpers/clone-obj.js.map +1 -0
- package/lib/helpers/taon-helpers.d.ts +5 -5
- package/lib/helpers/taon-helpers.js.map +1 -1
- package/lib/index.d.ts +1 -28
- package/lib/models.d.ts +0 -31
- package/lib/models.js +0 -33
- package/lib/models.js.map +1 -1
- package/lib/symbols.d.ts +0 -2
- package/lib/symbols.js +5 -7
- package/lib/symbols.js.map +1 -1
- package/lib/ui/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
- package/lib/validators.d.ts +2 -2
- package/lib/validators.js.map +1 -1
- package/package.json +1 -1
- package/scss/vars.scss +6 -6
- package/websql/README.md +24 -24
- package/websql/fesm2022/taon.mjs +300 -202
- package/websql/fesm2022/taon.mjs.map +1 -1
- package/websql/lib/base-classes/base-angular-service.d.ts +16 -0
- package/websql/lib/base-classes/base-context.d.ts +0 -9
- package/websql/lib/base-classes/base-controller.d.ts +1 -1
- package/websql/lib/base-classes/base-file-upload.middleware.d.ts +2 -2
- package/websql/lib/base-classes/base-middleware.d.ts +3 -3
- package/websql/lib/base-classes/base.d.ts +0 -9
- package/websql/lib/config/controller-config.d.ts +22 -0
- package/websql/lib/{decorators/classes → config}/controller-options.d.ts +6 -1
- package/websql/lib/config/method-config.d.ts +39 -0
- package/websql/lib/config/param-config.d.ts +9 -0
- package/websql/lib/constants.d.ts +2 -1
- package/websql/lib/create-context.d.ts +2 -20
- package/websql/lib/decorators/classes/controller-decorator.d.ts +1 -1
- package/websql/lib/decorators/http/http-methods-decorators.d.ts +14 -1
- package/websql/lib/endpoint-context.d.ts +3 -1
- package/websql/lib/helpers/class-helpers.d.ts +5 -2
- package/websql/lib/helpers/clone-obj.d.ts +2 -0
- package/websql/lib/helpers/taon-helpers.d.ts +5 -5
- package/websql/lib/index.d.ts +1 -28
- package/websql/lib/models.d.ts +0 -31
- package/websql/lib/symbols.d.ts +0 -2
- package/websql/lib/validators.d.ts +2 -2
- package/websql/package.json +1 -1
- package/browser/lib/decorators/classes/controller-config.d.ts +0 -10
- package/lib/env.d.ts +0 -2
- package/lib/env.js +0 -7
- package/lib/env.js.map +0 -1
- package/lib/storage.d.ts +0 -1
- package/lib/storage.js +0 -6
- package/lib/storage.js.map +0 -1
- package/websql/lib/decorators/classes/controller-config.d.ts +0 -10
package/websql/fesm2022/taon.mjs
CHANGED
|
@@ -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.
|
|
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][
|
|
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.
|
|
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
|
|
525
|
-
//
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -641,6 +676,10 @@ TAON_CONTEXT = new InjectionToken('TAON_CONTEXT');
|
|
|
641
676
|
let CURRENT_HOST_BACKEND_PORT;
|
|
642
677
|
//#region @browser
|
|
643
678
|
CURRENT_HOST_BACKEND_PORT = new InjectionToken('CURRENT_HOST_BACKEND_PORT');
|
|
679
|
+
//#endregion
|
|
680
|
+
let CURRENT_HOST_URL;
|
|
681
|
+
//#region @browser
|
|
682
|
+
CURRENT_HOST_URL = new InjectionToken('CURRENT_HOST_URL');
|
|
644
683
|
const apiPrefix = 'api';
|
|
645
684
|
|
|
646
685
|
const inject = (entity) => {
|
|
@@ -743,6 +782,28 @@ class BaseAngularsService {
|
|
|
743
782
|
constructor() {
|
|
744
783
|
//#region @browser
|
|
745
784
|
this.currentContext = inject$1(TAON_CONTEXT);
|
|
785
|
+
//#region @browser
|
|
786
|
+
this.CURRENT_HOST_BACKEND_PORT = inject$1(CURRENT_HOST_BACKEND_PORT, {
|
|
787
|
+
optional: true,
|
|
788
|
+
});
|
|
789
|
+
this.CURRENT_HOST_URL = inject$1(CURRENT_HOST_URL, {
|
|
790
|
+
optional: true,
|
|
791
|
+
});
|
|
792
|
+
// #endregion
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* @deprecated
|
|
796
|
+
* Returns the host URL for the backend service
|
|
797
|
+
* that is running on localhost (normal NodeJS/ExpressJS mode).
|
|
798
|
+
*/
|
|
799
|
+
get host() {
|
|
800
|
+
//#region @browser
|
|
801
|
+
if (this.CURRENT_HOST_URL) {
|
|
802
|
+
return this.CURRENT_HOST_URL;
|
|
803
|
+
}
|
|
804
|
+
return `http://localhost:${this.CURRENT_HOST_BACKEND_PORT}`;
|
|
805
|
+
//#endregion
|
|
806
|
+
return void 0;
|
|
746
807
|
}
|
|
747
808
|
injectController(ctor,
|
|
748
809
|
/**
|
|
@@ -752,7 +813,9 @@ class BaseAngularsService {
|
|
|
752
813
|
return inject(() => {
|
|
753
814
|
let currentContext;
|
|
754
815
|
//#region @browser
|
|
755
|
-
currentContext = overrideCurrentContext
|
|
816
|
+
currentContext = overrideCurrentContext
|
|
817
|
+
? overrideCurrentContext
|
|
818
|
+
: this.currentContext;
|
|
756
819
|
//#endregion
|
|
757
820
|
if (!currentContext) {
|
|
758
821
|
throw new Error('No context available. Make sure to initialize the context before injecting controllers.');
|
|
@@ -820,22 +883,6 @@ var Models;
|
|
|
820
883
|
}
|
|
821
884
|
Models.DatabaseConfig = DatabaseConfig;
|
|
822
885
|
//#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
886
|
//#region models / http
|
|
840
887
|
let Http;
|
|
841
888
|
(function (Http) {
|
|
@@ -3078,6 +3125,8 @@ class EndpointContext {
|
|
|
3078
3125
|
/* */
|
|
3079
3126
|
/* */
|
|
3080
3127
|
/* */
|
|
3128
|
+
/* */
|
|
3129
|
+
/* */
|
|
3081
3130
|
await this.initCustomClientMiddlewares();
|
|
3082
3131
|
}
|
|
3083
3132
|
//#endregion
|
|
@@ -3598,15 +3647,12 @@ class EndpointContext {
|
|
|
3598
3647
|
return url;
|
|
3599
3648
|
}
|
|
3600
3649
|
//#endregion
|
|
3601
|
-
|
|
3602
|
-
if (!this.uri?.origin?.includes('localhost')) {
|
|
3603
|
-
return this.config?.hostPortNumber?.toString();
|
|
3604
|
-
}
|
|
3605
|
-
return this.uri?.port;
|
|
3606
|
-
}
|
|
3650
|
+
//#region methods & getters / host uri protocol
|
|
3607
3651
|
get uriProtocol() {
|
|
3608
3652
|
return this.uri?.protocol;
|
|
3609
3653
|
}
|
|
3654
|
+
//#endregion
|
|
3655
|
+
//#region methods & getters / host uri origin
|
|
3610
3656
|
/**
|
|
3611
3657
|
* Examples
|
|
3612
3658
|
* http://localhost:3000
|
|
@@ -3615,6 +3661,8 @@ class EndpointContext {
|
|
|
3615
3661
|
get uriOrigin() {
|
|
3616
3662
|
return this.uri?.origin;
|
|
3617
3663
|
}
|
|
3664
|
+
//#endregion
|
|
3665
|
+
//#region methods & getters / host uri pathname
|
|
3618
3666
|
/**
|
|
3619
3667
|
* Exampels
|
|
3620
3668
|
* http://localhost:3000/path/to/somewhere
|
|
@@ -3628,6 +3676,8 @@ class EndpointContext {
|
|
|
3628
3676
|
get uriPathname() {
|
|
3629
3677
|
return this.uri?.pathname;
|
|
3630
3678
|
}
|
|
3679
|
+
//#endregion
|
|
3680
|
+
//#region methods & getters / uri pathname or nothing if root
|
|
3631
3681
|
/**
|
|
3632
3682
|
* Examples
|
|
3633
3683
|
* http://localhost:3000/path/to/somewhere -> '/path/to/somewhere'
|
|
@@ -3638,6 +3688,15 @@ class EndpointContext {
|
|
|
3638
3688
|
const isNonRootProperPathName = this.uri?.pathname && this.uri.pathname !== '/';
|
|
3639
3689
|
return isNonRootProperPathName ? this.uri.pathname.replace(/\/$/, '') : '';
|
|
3640
3690
|
}
|
|
3691
|
+
//#endregion
|
|
3692
|
+
//#region port from uri
|
|
3693
|
+
get uriPort() {
|
|
3694
|
+
if (!this.uri?.origin?.includes('localhost')) {
|
|
3695
|
+
return this.config?.hostPortNumber?.toString();
|
|
3696
|
+
}
|
|
3697
|
+
return this.uri?.port;
|
|
3698
|
+
}
|
|
3699
|
+
// TODO do i need 2 getters for port?
|
|
3641
3700
|
/**
|
|
3642
3701
|
* Port from uri as number
|
|
3643
3702
|
* @returns {Number | undefined}
|
|
@@ -3645,6 +3704,7 @@ class EndpointContext {
|
|
|
3645
3704
|
get port() {
|
|
3646
3705
|
return this.uri?.port ? Number(this.uriPort) : undefined;
|
|
3647
3706
|
}
|
|
3707
|
+
//#endregion
|
|
3648
3708
|
//#region methods & getters / is https server
|
|
3649
3709
|
get isHttpServer() {
|
|
3650
3710
|
return this.uriProtocol === 'https:';
|
|
@@ -3658,15 +3718,21 @@ class EndpointContext {
|
|
|
3658
3718
|
return this.config.contextName;
|
|
3659
3719
|
}
|
|
3660
3720
|
//#endregion
|
|
3721
|
+
//#region methods & getters / current working directory
|
|
3661
3722
|
get cwd() {
|
|
3662
3723
|
return this.config.cwd || process.cwd();
|
|
3663
3724
|
}
|
|
3725
|
+
//#endregion
|
|
3726
|
+
//#region methods & getters / active context
|
|
3664
3727
|
get activeContext() {
|
|
3665
3728
|
return this.config.activeContext || null;
|
|
3666
3729
|
}
|
|
3730
|
+
//#endregion
|
|
3731
|
+
//#region methods & getters / app id
|
|
3667
3732
|
get appId() {
|
|
3668
3733
|
return this.config.appId;
|
|
3669
3734
|
}
|
|
3735
|
+
//#endregion
|
|
3670
3736
|
//#region methods & getters / public assets
|
|
3671
3737
|
get publicAssets() {
|
|
3672
3738
|
return this.config?.publicAssets || [];
|
|
@@ -3852,66 +3918,124 @@ class EndpointContext {
|
|
|
3852
3918
|
}
|
|
3853
3919
|
//#endregion
|
|
3854
3920
|
//#region methods & getters / initialize metadata
|
|
3921
|
+
//#region methods & getters / update class calculate path
|
|
3922
|
+
updateCalculatedPathsForControllers(rawConfigs, classConfig, controllerClassFn) {
|
|
3923
|
+
const parentsCalculatedPath = _.slice(rawConfigs, 1)
|
|
3924
|
+
.reverse()
|
|
3925
|
+
.map(bc => {
|
|
3926
|
+
if (TaonHelpers.isGoodPath(bc.path)) {
|
|
3927
|
+
return bc.path;
|
|
3928
|
+
}
|
|
3929
|
+
return bc.className;
|
|
3930
|
+
})
|
|
3931
|
+
.join('/');
|
|
3932
|
+
if (TaonHelpers.isGoodPath(classConfig.path)) {
|
|
3933
|
+
classConfig.calculatedPath = classConfig.path;
|
|
3934
|
+
}
|
|
3935
|
+
else {
|
|
3936
|
+
classConfig.calculatedPath = (`${this.uriPathnameOrNothingIfRoot}` +
|
|
3937
|
+
`/${apiPrefix}/${this.contextName}/tcp${parentsCalculatedPath}/` +
|
|
3938
|
+
`${ClassHelpers.getName(controllerClassFn)}`)
|
|
3939
|
+
.replace(/\/\//g, '/')
|
|
3940
|
+
.split('/')
|
|
3941
|
+
.reduce((acc, bc) => {
|
|
3942
|
+
return _.last(acc) === bc ? acc : [...acc, bc];
|
|
3943
|
+
}, [])
|
|
3944
|
+
.join('/');
|
|
3945
|
+
}
|
|
3946
|
+
// console.log('calculatedPath', classConfig.calculatedPath);
|
|
3947
|
+
}
|
|
3948
|
+
//#endregion
|
|
3949
|
+
//#region methods & getters / dedupe class configs
|
|
3950
|
+
mergeControllerMethodsConfigs(rawConfigs, classConfig, controllerClassFn) {
|
|
3951
|
+
const currentControllerMethodsConfig = classConfig.methods;
|
|
3952
|
+
_.slice(rawConfigs, 1).forEach(bc => {
|
|
3953
|
+
const parentControllerMethods = _.cloneDeep(bc.methods);
|
|
3954
|
+
for (const methodsName in parentControllerMethods) {
|
|
3955
|
+
if (parentControllerMethods.hasOwnProperty(methodsName)) {
|
|
3956
|
+
if (!currentControllerMethodsConfig[methodsName]) {
|
|
3957
|
+
//#region add non existed method
|
|
3958
|
+
const methodConfig = parentControllerMethods[methodsName];
|
|
3959
|
+
currentControllerMethodsConfig[methodsName] = methodConfig;
|
|
3960
|
+
//#endregion
|
|
3961
|
+
}
|
|
3962
|
+
}
|
|
3963
|
+
}
|
|
3964
|
+
});
|
|
3965
|
+
}
|
|
3966
|
+
//#endregion
|
|
3855
3967
|
async initControllers() {
|
|
3856
3968
|
if (this.isRunOrRevertOnlyMigrationAppStart) {
|
|
3857
3969
|
return;
|
|
3858
3970
|
}
|
|
3859
3971
|
const allControllers = this.getClassFunByArr(Models.ClassType.CONTROLLER);
|
|
3972
|
+
// debugger
|
|
3860
3973
|
// console.log('allControllers', allControllers);
|
|
3861
3974
|
for (const controllerClassFn of allControllers) {
|
|
3975
|
+
// console.log(ClassHelpers.getClassConfig(controllerClassFn));
|
|
3976
|
+
// const controllerName = ClassHelpers.getName(controllerClassFn);
|
|
3977
|
+
// console.log(
|
|
3978
|
+
// `for ${controllerName}`,
|
|
3979
|
+
// ClassHelpers.getClassConfig(controllerClassFn),
|
|
3980
|
+
// );
|
|
3862
3981
|
controllerClassFn[Symbols.classMethodsNames] =
|
|
3863
3982
|
ClassHelpers.getMethodsNames(controllerClassFn);
|
|
3864
|
-
const
|
|
3983
|
+
const rawConfigs = ClassHelpers.getControllerConfigs(controllerClassFn);
|
|
3984
|
+
// console.log(controllerName, { rawConfigs });
|
|
3865
3985
|
// console.log(`Class config for ${ClassHelpers.getName(controllerClassFn)}`, configs)
|
|
3866
|
-
const classConfig =
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
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
|
-
}
|
|
3986
|
+
const classConfig = rawConfigs[0];
|
|
3987
|
+
this.updateCalculatedPathsForControllers(rawConfigs, classConfig, controllerClassFn);
|
|
3988
|
+
this.mergeControllerMethodsConfigs(rawConfigs, classConfig, controllerClassFn);
|
|
3989
|
+
//#region combine middlewares from controllers
|
|
3990
|
+
classConfig.calculatedMiddlewaresControllerObj = {};
|
|
3991
|
+
[...rawConfigs].reverse().forEach(rc => {
|
|
3992
|
+
if (_.isFunction(rc.middlewares)) {
|
|
3993
|
+
classConfig.calculatedMiddlewaresControllerObj = rc.middlewares({
|
|
3994
|
+
parentMiddlewares: classConfig.calculatedMiddlewaresControllerObj,
|
|
3995
|
+
className(middlewareClass) {
|
|
3996
|
+
return ClassHelpers.getName(controllerClassFn);
|
|
3997
|
+
},
|
|
3998
|
+
});
|
|
3901
3999
|
}
|
|
3902
4000
|
});
|
|
4001
|
+
//#endregion
|
|
4002
|
+
//#region group start
|
|
3903
4003
|
/* */
|
|
3904
4004
|
/* */
|
|
3905
4005
|
this.logHttp &&
|
|
3906
4006
|
console.groupCollapsed(`[taon][express-server] routes [${classConfig.className}]`);
|
|
3907
4007
|
/* */
|
|
3908
4008
|
/* */
|
|
3909
|
-
|
|
4009
|
+
//#endregion
|
|
4010
|
+
//#region init client or server methods
|
|
3910
4011
|
const methodNames = Object.keys(classConfig.methods);
|
|
3911
4012
|
for (const methodName of methodNames) {
|
|
3912
4013
|
const methodConfig = classConfig.methods[methodName];
|
|
3913
|
-
|
|
3914
|
-
|
|
4014
|
+
//#region combine all class methods middlewares
|
|
4015
|
+
let calculatedMiddlewaresMethodObj = {};
|
|
4016
|
+
[...rawConfigs].reverse().forEach(rc => {
|
|
4017
|
+
if (rc.methods[methodName]) {
|
|
4018
|
+
const parentMethodConfig = rc.methods[methodName];
|
|
4019
|
+
if (_.isFunction(parentMethodConfig.middlewares)) {
|
|
4020
|
+
calculatedMiddlewaresMethodObj = parentMethodConfig.middlewares({
|
|
4021
|
+
parentMiddlewares: calculatedMiddlewaresMethodObj,
|
|
4022
|
+
className(middlewareClass) {
|
|
4023
|
+
return ClassHelpers.getName(controllerClassFn);
|
|
4024
|
+
},
|
|
4025
|
+
});
|
|
4026
|
+
}
|
|
4027
|
+
}
|
|
4028
|
+
});
|
|
4029
|
+
// add class middlewares to method middlewares
|
|
4030
|
+
methodConfig.calculatedMiddlewaresMethodObj = {
|
|
4031
|
+
...calculatedMiddlewaresMethodObj,
|
|
4032
|
+
...classConfig.calculatedMiddlewaresControllerObj,
|
|
4033
|
+
};
|
|
4034
|
+
methodConfig.calculatedMiddlewares = Object.values(methodConfig.calculatedMiddlewaresMethodObj || {});
|
|
4035
|
+
//#endregion
|
|
4036
|
+
// methodConfig.calculatedMiddlewares = TODO
|
|
4037
|
+
//#region initialized method express path
|
|
4038
|
+
const httpMethodType = methodConfig.type;
|
|
3915
4039
|
// this is quick fix - in docker global path should not be used
|
|
3916
4040
|
const globalPathPart = this.isRunningInsideDocker ||
|
|
3917
4041
|
!this.frontendHostUri?.origin?.includes('localhost') // fe with domain -> is in docker
|
|
@@ -3920,16 +4044,20 @@ class EndpointContext {
|
|
|
3920
4044
|
const expressPath = methodConfig.global
|
|
3921
4045
|
? `${globalPathPart}/${methodConfig.path?.replace(/\/$/, '')}`.replace(/\/\//, '/')
|
|
3922
4046
|
: TaonHelpers.getExpressPath(classConfig, methodConfig);
|
|
4047
|
+
//#endregion
|
|
4048
|
+
//#region init server
|
|
3923
4049
|
// console.log({ expressPath });
|
|
3924
4050
|
if (Helpers.isNode || Helpers.isWebSQL) {
|
|
3925
4051
|
//#region @websql
|
|
3926
|
-
const route = this.initServer(
|
|
4052
|
+
const route = this.initServer(httpMethodType, methodConfig, classConfig, expressPath, controllerClassFn);
|
|
3927
4053
|
this.activeRoutes.push({
|
|
3928
4054
|
expressPath: route.expressPath,
|
|
3929
4055
|
method: route.method,
|
|
3930
4056
|
});
|
|
3931
4057
|
//#endregion
|
|
3932
4058
|
}
|
|
4059
|
+
//#endregion
|
|
4060
|
+
//#region init client
|
|
3933
4061
|
const shouldInitClient = Helpers.isBrowser || this.remoteHost || Helpers.isWebSQL;
|
|
3934
4062
|
// console.log('shouldInitClient', shouldInitClient);
|
|
3935
4063
|
if (shouldInitClient) {
|
|
@@ -3940,14 +4068,18 @@ class EndpointContext {
|
|
|
3940
4068
|
// methodConfig,
|
|
3941
4069
|
// expressPath,
|
|
3942
4070
|
// );
|
|
3943
|
-
await this.initClient(controllerClassFn,
|
|
4071
|
+
await this.initClient(controllerClassFn, httpMethodType, methodConfig, expressPath);
|
|
3944
4072
|
}
|
|
4073
|
+
//#endregion
|
|
3945
4074
|
}
|
|
4075
|
+
//#endregion
|
|
4076
|
+
//#region group end
|
|
3946
4077
|
/* */
|
|
3947
4078
|
/* */
|
|
3948
4079
|
this.logHttp && console.groupEnd();
|
|
3949
4080
|
/* */
|
|
3950
4081
|
/* */
|
|
4082
|
+
//#endregion
|
|
3951
4083
|
}
|
|
3952
4084
|
}
|
|
3953
4085
|
//#endregion
|
|
@@ -4001,15 +4133,15 @@ class EndpointContext {
|
|
|
4001
4133
|
const middlewares = this.getClassesInstancesArrBy(Models.ClassType.MIDDLEWARE)
|
|
4002
4134
|
.map(f => f)
|
|
4003
4135
|
.filter(f => _.isFunction(f.interceptClient));
|
|
4004
|
-
middlewares.forEach(
|
|
4136
|
+
middlewares.forEach(middlewareInstanceName => {
|
|
4005
4137
|
const contextName = this.contextName;
|
|
4006
|
-
const interceptorName = `${contextName}-${ClassHelpers.getName(
|
|
4138
|
+
const interceptorName = `${contextName}-${ClassHelpers.getName(middlewareInstanceName)}`;
|
|
4007
4139
|
Resource.request.interceptors.set(interceptorName, {
|
|
4008
4140
|
intercept: ({ req, next }) => {
|
|
4009
4141
|
const url = new URL(req.url);
|
|
4010
4142
|
if (url.pathname.startsWith(`${this.uriPathnameOrNothingIfRoot}/${apiPrefix}/${contextName}/`)) {
|
|
4011
4143
|
// console.log('intercepting', url.pathname, req);
|
|
4012
|
-
return
|
|
4144
|
+
return middlewareInstanceName.interceptClient({
|
|
4013
4145
|
req,
|
|
4014
4146
|
next,
|
|
4015
4147
|
});
|
|
@@ -4167,10 +4299,10 @@ class EndpointContext {
|
|
|
4167
4299
|
//#region parameters
|
|
4168
4300
|
httpMethodType, methodConfig, classConfig, expressPath, target) {
|
|
4169
4301
|
//#region resolve variables
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4302
|
+
// console.log(
|
|
4303
|
+
// `CLIENT: expressPath: "${expressPath}" interceptor for method: ${methodConfig.calculatedMiddlewares.length}`,
|
|
4304
|
+
// );
|
|
4305
|
+
const middlewareHandlers = methodConfig.calculatedMiddlewares
|
|
4174
4306
|
.map(middlewareClassFun => {
|
|
4175
4307
|
const middlewareInstance = this.getInstanceBy(middlewareClassFun);
|
|
4176
4308
|
if (middlewareInstance &&
|
|
@@ -4459,7 +4591,6 @@ class EndpointContext {
|
|
|
4459
4591
|
/* */
|
|
4460
4592
|
/* */
|
|
4461
4593
|
/* */
|
|
4462
|
-
/* */
|
|
4463
4594
|
}
|
|
4464
4595
|
return {
|
|
4465
4596
|
expressPath: expressPath,
|
|
@@ -4471,17 +4602,22 @@ class EndpointContext {
|
|
|
4471
4602
|
/**
|
|
4472
4603
|
* client can be browser or nodejs (when remote host)
|
|
4473
4604
|
*/
|
|
4474
|
-
async initClient(
|
|
4475
|
-
//#region parameters
|
|
4476
|
-
target, httpRequestType, methodConfig, // Models.Http.Rest.MethodConfig,
|
|
4605
|
+
async initClient(target, httpRequestType, methodConfig, // Models.Http.Rest.MethodConfig,
|
|
4477
4606
|
expressPath) {
|
|
4478
4607
|
const ctx = this;
|
|
4608
|
+
// console.log(
|
|
4609
|
+
// `CLIENT: expressPath: "${expressPath}" interceptor for method: ${methodConfig.calculatedMiddlewares?.length} `,
|
|
4610
|
+
// );
|
|
4479
4611
|
//#region init middlewares
|
|
4480
|
-
const middlewares = methodConfig.
|
|
4612
|
+
const middlewares = methodConfig.calculatedMiddlewares;
|
|
4613
|
+
const middlewaresInstances = middlewares
|
|
4481
4614
|
.map(f => this.getInstanceBy(f))
|
|
4482
4615
|
.filter(f => _.isFunction(f.interceptClientMethod));
|
|
4483
|
-
|
|
4484
|
-
|
|
4616
|
+
middlewaresInstances.forEach(instance => {
|
|
4617
|
+
const middlewareName = ClassHelpers.getName(instance);
|
|
4618
|
+
// middlewareName - only needed for inheritace and uniqness of interceptors
|
|
4619
|
+
const interceptorKey = `${middlewareName}-${methodConfig.type?.toUpperCase()}-${expressPath}`;
|
|
4620
|
+
Resource.request.methodsInterceptors.set(interceptorKey, {
|
|
4485
4621
|
intercept: ({ req, next }) => {
|
|
4486
4622
|
return instance.interceptClientMethod({
|
|
4487
4623
|
req,
|
|
@@ -4727,6 +4863,14 @@ class EndpointContext {
|
|
|
4727
4863
|
break;
|
|
4728
4864
|
}
|
|
4729
4865
|
}
|
|
4866
|
+
if (!currentParam) {
|
|
4867
|
+
const errorMessage = `[${config.frameworkName}] Unable to resolve parameter` +
|
|
4868
|
+
` at index ${i} for method ${methodConfig.methodName} at path ${expressPath}.`;
|
|
4869
|
+
/* */
|
|
4870
|
+
/* */
|
|
4871
|
+
/* */
|
|
4872
|
+
throw new Error(errorMessage);
|
|
4873
|
+
}
|
|
4730
4874
|
if (currentParam.paramType === 'Path') {
|
|
4731
4875
|
pathPrams[currentParam.paramName] = param;
|
|
4732
4876
|
}
|
|
@@ -4851,50 +4995,7 @@ const createContext = (configFn) => {
|
|
|
4851
4995
|
// );
|
|
4852
4996
|
const endpointContextRef = new EndpointContext(config, configFn);
|
|
4853
4997
|
const res = {
|
|
4854
|
-
//#region types
|
|
4855
|
-
types: {
|
|
4856
|
-
//#region entites for
|
|
4857
|
-
// get entities() {
|
|
4858
|
-
// return config.entities;
|
|
4859
|
-
// },
|
|
4860
|
-
// entitiesFor(classInstace: BaseInjector) {
|
|
4861
|
-
// const ctx = classInstace.__endpoint_context__;
|
|
4862
|
-
// if (!entitiesCache[ctx.contextName]) {
|
|
4863
|
-
// entitiesCache[ctx.contextName] = {};
|
|
4864
|
-
// for (const entityClassName of Object.keys(config.entities)) {
|
|
4865
|
-
// entitiesCache[ctx.contextName][entityClassName] =
|
|
4866
|
-
// config.entities[entityClassName][
|
|
4867
|
-
// Taon.symbols.orignalClassClonesObj
|
|
4868
|
-
// ][ctx.contextName];
|
|
4869
|
-
// }
|
|
4870
|
-
// }
|
|
4871
|
-
// return entitiesCache[ctx.contextName] as typeof config.entities;
|
|
4872
|
-
// },
|
|
4873
|
-
//#endregion
|
|
4874
|
-
get controllers() {
|
|
4875
|
-
return config.controllers; // TODO QUICK_FIX new typescript generated wrong types
|
|
4876
|
-
},
|
|
4877
|
-
get repositories() {
|
|
4878
|
-
return config.repositories; // TODO QUICK_FIX new typescript generated wrong types
|
|
4879
|
-
},
|
|
4880
|
-
get providers() {
|
|
4881
|
-
return config.providers; // TODO QUICK_FIX new typescript generated wrong types
|
|
4882
|
-
},
|
|
4883
|
-
get subscribers() {
|
|
4884
|
-
return config.subscribers; // TODO QUICK_FIX new typescript generated wrong types
|
|
4885
|
-
},
|
|
4886
|
-
get migrations() {
|
|
4887
|
-
return config.migrations; // TODO QUICK_FIX new typescript generated wrong types
|
|
4888
|
-
},
|
|
4889
|
-
get middlewares() {
|
|
4890
|
-
return config.middlewares; // TODO QUICK_FIX new typescript generated wrong types
|
|
4891
|
-
},
|
|
4892
|
-
},
|
|
4893
|
-
//#endregion
|
|
4894
4998
|
//#region contexts
|
|
4895
|
-
get contexts() {
|
|
4896
|
-
return config.contexts; // TODO QUICK_FIX new typescript generated wrong types
|
|
4897
|
-
},
|
|
4898
4999
|
get contextName() {
|
|
4899
5000
|
return config.contextName;
|
|
4900
5001
|
},
|
|
@@ -5029,7 +5130,7 @@ const createContext = (configFn) => {
|
|
|
5029
5130
|
},
|
|
5030
5131
|
/**
|
|
5031
5132
|
* realtime communication with server
|
|
5032
|
-
*
|
|
5133
|
+
* TCP(upgrade) socket.io (or ipc) based.
|
|
5033
5134
|
*/
|
|
5034
5135
|
get realtime() {
|
|
5035
5136
|
return {
|
|
@@ -5945,12 +6046,18 @@ var baseContext = /*#__PURE__*/Object.freeze({
|
|
|
5945
6046
|
function TaonController(options) {
|
|
5946
6047
|
return function (constructor) {
|
|
5947
6048
|
ClassHelpers.setName(constructor, options?.className);
|
|
5948
|
-
Reflect.defineMetadata(Symbols.metadata.options.controller, options, constructor);
|
|
5949
6049
|
Reflect.defineMetadata(Symbols.metadata.className, options?.className || constructor.name, constructor);
|
|
6050
|
+
const cfg = ClassHelpers.ensureClassConfig(constructor);
|
|
6051
|
+
options = options || {};
|
|
6052
|
+
cfg.className = options.className || constructor.name;
|
|
6053
|
+
cfg.path = options.path || '';
|
|
6054
|
+
cfg.realtime = options.realtime;
|
|
6055
|
+
cfg.middlewares = options.middlewares;
|
|
5950
6056
|
};
|
|
5951
6057
|
}
|
|
5952
6058
|
|
|
5953
6059
|
const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal) => {
|
|
6060
|
+
const methodConfig = ClassHelpers.ensureMethodConfig(target, propertyKey);
|
|
5954
6061
|
let options;
|
|
5955
6062
|
if (typeof pathOrOptions === 'object') {
|
|
5956
6063
|
options = pathOrOptions;
|
|
@@ -5962,13 +6069,8 @@ const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, p
|
|
|
5962
6069
|
options = { pathOrOptions, pathIsGlobal };
|
|
5963
6070
|
}
|
|
5964
6071
|
const { overrideContentType, overrideResponseType, middlewares } = options;
|
|
5965
|
-
let methodConfig = Reflect.getMetadata(Symbols.metadata.options.controllerMethod, target.constructor, propertyKey);
|
|
5966
|
-
if (!methodConfig) {
|
|
5967
|
-
methodConfig = new Models.MethodConfig();
|
|
5968
|
-
Reflect.defineMetadata(Symbols.metadata.options.controllerMethod, methodConfig, target.constructor, propertyKey);
|
|
5969
|
-
}
|
|
5970
6072
|
methodConfig.methodName = propertyKey;
|
|
5971
|
-
methodConfig.middlewares = middlewares
|
|
6073
|
+
methodConfig.middlewares = middlewares;
|
|
5972
6074
|
methodConfig.type = method;
|
|
5973
6075
|
if (!path) {
|
|
5974
6076
|
let paramsPathConcatedPath = '';
|
|
@@ -5991,8 +6093,6 @@ const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, p
|
|
|
5991
6093
|
methodConfig.global = pathIsGlobal;
|
|
5992
6094
|
methodConfig.contentType = overrideContentType;
|
|
5993
6095
|
methodConfig.responseType = overrideResponseType;
|
|
5994
|
-
Reflect.defineMetadata(Symbols.metadata.options.controllerMethod, methodConfig, target.constructor, propertyKey);
|
|
5995
|
-
// console.log('methods updated', methodConfig);
|
|
5996
6096
|
};
|
|
5997
6097
|
function GET(pathOrOptions, pathIsGlobal = false) {
|
|
5998
6098
|
return function (target, propertyKey, descriptor) {
|
|
@@ -6026,21 +6126,16 @@ function DELETE(pathOrOptions, pathIsGlobal = false) {
|
|
|
6026
6126
|
}
|
|
6027
6127
|
|
|
6028
6128
|
function metaParam(param, name, expire, defaultValue = undefined, target, propertyKey, parameterIndex) {
|
|
6029
|
-
|
|
6030
|
-
if (!methodConfig) {
|
|
6031
|
-
methodConfig = new Models.MethodConfig();
|
|
6032
|
-
Reflect.defineMetadata(Symbols.metadata.options.controllerMethod, methodConfig, target.constructor, propertyKey);
|
|
6033
|
-
}
|
|
6129
|
+
const methodCfg = ClassHelpers.ensureMethodConfig(target, propertyKey);
|
|
6034
6130
|
const nameKey = name ? name : param;
|
|
6035
|
-
const
|
|
6036
|
-
|
|
6037
|
-
:
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
Reflect.defineMetadata(Symbols.metadata.options.controllerMethod, methodConfig, target.constructor, propertyKey);
|
|
6131
|
+
// const key = name || `${param}_${parameterIndex}`;
|
|
6132
|
+
methodCfg.parameters[nameKey] = {
|
|
6133
|
+
index: parameterIndex,
|
|
6134
|
+
paramName: name,
|
|
6135
|
+
paramType: param,
|
|
6136
|
+
defaultType: defaultValue,
|
|
6137
|
+
expireInSeconds: expire,
|
|
6138
|
+
};
|
|
6044
6139
|
// console.log('params updated', methodConfig);
|
|
6045
6140
|
}
|
|
6046
6141
|
function Path(name) {
|
|
@@ -6118,7 +6213,10 @@ let BaseController = class BaseController extends BaseInjector {
|
|
|
6118
6213
|
__decorate([
|
|
6119
6214
|
POST({
|
|
6120
6215
|
overrideContentType: 'multipart/form-data',
|
|
6121
|
-
middlewares:
|
|
6216
|
+
middlewares: ({ parentMiddlewares }) => ({
|
|
6217
|
+
...parentMiddlewares,
|
|
6218
|
+
BaseFileUploadMiddleware,
|
|
6219
|
+
}),
|
|
6122
6220
|
}),
|
|
6123
6221
|
__param(0, Body()),
|
|
6124
6222
|
__metadata("design:type", Function),
|
|
@@ -6729,5 +6827,5 @@ var Taon;
|
|
|
6729
6827
|
* Generated bundle index. Do not edit.
|
|
6730
6828
|
*/
|
|
6731
6829
|
|
|
6732
|
-
export { BaseContext, BaseController, BaseCustomRepository, BaseEntity, BaseMigration, BaseProvider, BaseRepository, CURRENT_HOST_BACKEND_PORT, ClassHelpers, EndpointContext, Models, TAON_CONTEXT, Taon, TaonAdminService, TaonEntityKeysToOmitArr, apiPrefix, createContext, inject };
|
|
6830
|
+
export { BaseContext, BaseController, BaseCustomRepository, BaseEntity, BaseMigration, BaseProvider, BaseRepository, CURRENT_HOST_BACKEND_PORT, CURRENT_HOST_URL, ClassHelpers, EndpointContext, Models, TAON_CONTEXT, Taon, TaonAdminService, TaonEntityKeysToOmitArr, apiPrefix, createContext, inject };
|
|
6733
6831
|
//# sourceMappingURL=taon.mjs.map
|