@fastcar/core 0.2.38
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/LICENSE +20 -0
- package/README.md +379 -0
- package/annotation.d.ts +157 -0
- package/db.d.ts +272 -0
- package/index.d.ts +262 -0
- package/package.json +53 -0
- package/src/FastCarApplication.ts +761 -0
- package/src/annotation/Application.ts +46 -0
- package/src/annotation/ExceptionMonitor.ts +15 -0
- package/src/annotation/bind/AddRequireModule.ts +18 -0
- package/src/annotation/bind/AliasInjection.ts +24 -0
- package/src/annotation/bind/Autowired.ts +11 -0
- package/src/annotation/bind/CallDependency.ts +24 -0
- package/src/annotation/data/DBType.ts +9 -0
- package/src/annotation/data/DS.ts +58 -0
- package/src/annotation/data/DSIndex.ts +7 -0
- package/src/annotation/data/Entity.ts +8 -0
- package/src/annotation/data/Field.ts +15 -0
- package/src/annotation/data/PrimaryKey.ts +7 -0
- package/src/annotation/data/SqlSession.ts +7 -0
- package/src/annotation/data/Table.ts +37 -0
- package/src/annotation/data/Transactional.ts +60 -0
- package/src/annotation/env/ApplicationSetting.ts +24 -0
- package/src/annotation/env/BaseFilePath.ts +12 -0
- package/src/annotation/env/BasePath.ts +12 -0
- package/src/annotation/env/ENV.ts +8 -0
- package/src/annotation/env/ResourcePath.ts +7 -0
- package/src/annotation/lifeCycle/AddLifeCycleItem.ts +25 -0
- package/src/annotation/lifeCycle/ApplicationDestory.ts +13 -0
- package/src/annotation/lifeCycle/ApplicationInit.ts +13 -0
- package/src/annotation/lifeCycle/ApplicationRunner.ts +5 -0
- package/src/annotation/lifeCycle/ApplicationStart.ts +23 -0
- package/src/annotation/lifeCycle/ApplicationStop.ts +18 -0
- package/src/annotation/property/Deprecate.ts +17 -0
- package/src/annotation/property/NotImplemented.ts +5 -0
- package/src/annotation/property/Override.ts +4 -0
- package/src/annotation/property/Readonly.ts +12 -0
- package/src/annotation/scan/ComponentInjection.ts +22 -0
- package/src/annotation/scan/ComponentScan.ts +7 -0
- package/src/annotation/scan/ComponentScanExclusion.ts +26 -0
- package/src/annotation/scan/Hotter.ts +6 -0
- package/src/annotation/stereotype/BeanName.ts +9 -0
- package/src/annotation/stereotype/Component.ts +6 -0
- package/src/annotation/stereotype/Configure.ts +12 -0
- package/src/annotation/stereotype/Controller.ts +7 -0
- package/src/annotation/stereotype/Injection.ts +10 -0
- package/src/annotation/stereotype/Log.ts +17 -0
- package/src/annotation/stereotype/Repository.ts +7 -0
- package/src/annotation/stereotype/Service.ts +7 -0
- package/src/annotation/valid/AddChildValid.ts +61 -0
- package/src/annotation/valid/DefaultVal.ts +8 -0
- package/src/annotation/valid/NotNull.ts +7 -0
- package/src/annotation/valid/Rule.ts +104 -0
- package/src/annotation/valid/Size.ts +13 -0
- package/src/annotation/valid/Type.ts +8 -0
- package/src/annotation/valid/ValidCustom.ts +21 -0
- package/src/annotation/valid/ValidForm.ts +146 -0
- package/src/annotation.ts +103 -0
- package/src/config/ApplicationConfig.ts +5 -0
- package/src/config/SysConfig.ts +28 -0
- package/src/constant/AppStatusEnum.ts +5 -0
- package/src/constant/BootPriority.ts +7 -0
- package/src/constant/CommonConstant.ts +14 -0
- package/src/constant/ComponentKind.ts +7 -0
- package/src/constant/DataTypes.ts +15 -0
- package/src/constant/FastCarMetaData.ts +25 -0
- package/src/constant/LifeCycleModule.ts +5 -0
- package/src/db.ts +182 -0
- package/src/index.ts +11 -0
- package/src/interface/ApplicationHook.ts +9 -0
- package/src/interface/ApplicationRunnerService.ts +3 -0
- package/src/interface/DataSourceManager.ts +14 -0
- package/src/interface/Logger.ts +9 -0
- package/src/model/BaseMapper.ts +115 -0
- package/src/model/DataMap.ts +103 -0
- package/src/model/FormRuleModel.ts +23 -0
- package/src/model/ValidError.ts +1 -0
- package/src/model/WinstonLogger.ts +119 -0
- package/src/type/ComponentDesc.ts +5 -0
- package/src/type/DesignMeta.ts +11 -0
- package/src/type/FileHotterDesc.ts +4 -0
- package/src/type/MapperType.ts +8 -0
- package/src/type/ProcessType.ts +12 -0
- package/src/type/SqlError.ts +3 -0
- package/src/type/WinstonLoggerType.ts +18 -0
- package/src/utils/ClassLoader.ts +72 -0
- package/src/utils/ClassUtils.ts +38 -0
- package/src/utils/CryptoUtil.ts +106 -0
- package/src/utils/DataFormat.ts +97 -0
- package/src/utils/DateUtil.ts +85 -0
- package/src/utils/FileUtil.ts +172 -0
- package/src/utils/FormatStr.ts +13 -0
- package/src/utils/Mix.ts +69 -0
- package/src/utils/ReflectUtil.ts +22 -0
- package/src/utils/TypeUtil.ts +56 -0
- package/src/utils/ValidationUtil.ts +138 -0
- package/src/utils.ts +13 -0
- package/target/FastCarApplication.js +661 -0
- package/target/annotation/AddRequireModule.js +21 -0
- package/target/annotation/Application.js +45 -0
- package/target/annotation/Autowired.js +15 -0
- package/target/annotation/Calldependency.js +18 -0
- package/target/annotation/ExceptionMonitor.js +16 -0
- package/target/annotation/bind/AddRequireModule.js +21 -0
- package/target/annotation/bind/AliasInjection.js +23 -0
- package/target/annotation/bind/Autowired.js +13 -0
- package/target/annotation/bind/CallDependency.js +23 -0
- package/target/annotation/data/DBType.js +11 -0
- package/target/annotation/data/DS.js +54 -0
- package/target/annotation/data/DSIndex.js +9 -0
- package/target/annotation/data/Entity.js +10 -0
- package/target/annotation/data/Field.js +18 -0
- package/target/annotation/data/PrimaryKey.js +9 -0
- package/target/annotation/data/SqlSession.js +9 -0
- package/target/annotation/data/Table.js +34 -0
- package/target/annotation/data/Transactional.js +52 -0
- package/target/annotation/env/ApplicationSetting.js +25 -0
- package/target/annotation/env/BaseFilePath.js +14 -0
- package/target/annotation/env/BasePath.js +14 -0
- package/target/annotation/env/ENV.js +10 -0
- package/target/annotation/env/ResourcePath.js +9 -0
- package/target/annotation/lifeCycle/AddLifeCycleItem.js +18 -0
- package/target/annotation/lifeCycle/ApplicationDestory.js +15 -0
- package/target/annotation/lifeCycle/ApplicationInit.js +15 -0
- package/target/annotation/lifeCycle/ApplicationRunner.js +7 -0
- package/target/annotation/lifeCycle/ApplicationStart.js +24 -0
- package/target/annotation/lifeCycle/ApplicationStop.js +20 -0
- package/target/annotation/property/Deprecate.js +19 -0
- package/target/annotation/property/NotImplemented.js +8 -0
- package/target/annotation/property/Override.js +7 -0
- package/target/annotation/property/Readonly.js +16 -0
- package/target/annotation/scan/ComponentInjection.js +21 -0
- package/target/annotation/scan/ComponentScan.js +9 -0
- package/target/annotation/scan/ComponentScanExclusion.js +25 -0
- package/target/annotation/scan/Hotter.js +8 -0
- package/target/annotation/stereotype/BeanName.js +11 -0
- package/target/annotation/stereotype/Component.js +8 -0
- package/target/annotation/stereotype/Configure.js +14 -0
- package/target/annotation/stereotype/Controller.js +9 -0
- package/target/annotation/stereotype/Injection.js +12 -0
- package/target/annotation/stereotype/Log.js +16 -0
- package/target/annotation/stereotype/Repository.js +9 -0
- package/target/annotation/stereotype/Service.js +9 -0
- package/target/annotation/valid/AddChildValid.js +56 -0
- package/target/annotation/valid/DefaultVal.js +10 -0
- package/target/annotation/valid/NotNull.js +8 -0
- package/target/annotation/valid/Rule.js +100 -0
- package/target/annotation/valid/Size.js +10 -0
- package/target/annotation/valid/Type.js +10 -0
- package/target/annotation/valid/ValidCustom.js +17 -0
- package/target/annotation/valid/ValidForm.js +131 -0
- package/target/annotation.js +101 -0
- package/target/config/ApplicationConfig.js +2 -0
- package/target/config/SysConfig.js +19 -0
- package/target/constant/AppStatusEnum.js +9 -0
- package/target/constant/BootPriority.js +11 -0
- package/target/constant/CommonConstant.js +16 -0
- package/target/constant/ComponentKind.js +11 -0
- package/target/constant/DataTypes.js +19 -0
- package/target/constant/FastCarMetaData.js +29 -0
- package/target/constant/LifeCycleModule.js +9 -0
- package/target/db.js +46 -0
- package/target/index.js +21 -0
- package/target/interface/ApplicationHook.js +2 -0
- package/target/interface/ApplicationRunnerService.js +2 -0
- package/target/interface/DataSourceManager.js +2 -0
- package/target/interface/Logger.js +5 -0
- package/target/model/BaseMapper.js +98 -0
- package/target/model/DataMap.js +87 -0
- package/target/model/FormRuleModel.js +2 -0
- package/target/model/ValidError.js +5 -0
- package/target/model/WinstonLogger.js +95 -0
- package/target/type/ComponentDesc.js +2 -0
- package/target/type/DesignMeta.js +15 -0
- package/target/type/FileHotterDesc.js +2 -0
- package/target/type/MapperType.js +2 -0
- package/target/type/ProcessType.js +2 -0
- package/target/type/SqlError.js +5 -0
- package/target/type/WinstonLoggerType.js +9 -0
- package/target/utils/ClassUtils.js +35 -0
- package/target/utils/CryptoUtil.js +84 -0
- package/target/utils/DataFormat.js +84 -0
- package/target/utils/DateUtil.js +71 -0
- package/target/utils/FileUtil.js +153 -0
- package/target/utils/FormatStr.js +14 -0
- package/target/utils/Mix.js +62 -0
- package/target/utils/ReflectUtil.js +22 -0
- package/target/utils/TypeUtil.js +47 -0
- package/target/utils/ValidationUtil.js +118 -0
- package/target/utils/classLoader.js +65 -0
- package/target/utils.js +23 -0
- package/test/example/logs/app.log +0 -0
- package/test/example/logs/logger.log +12 -0
- package/test/example/logs/logger1.log +12 -0
- package/test/example/logs/logger2.log +12 -0
- package/test/example/logs/logger3.log +12 -0
- package/test/example/logs/logger4.log +12 -0
- package/test/example/logs/logger5.log +6 -0
- package/test/example/logs/sys.log +7 -0
- package/test/example/logs/sys1.log +14 -0
- package/test/example/logs/sys10.log +12 -0
- package/test/example/logs/sys11.log +5 -0
- package/test/example/logs/sys13.log +5 -0
- package/test/example/logs/sys2.log +3 -0
- package/test/example/logs/sys4.log +15 -0
- package/test/example/logs/sys5.log +9 -0
- package/test/example/logs/sys6.log +10 -0
- package/test/example/logs/sys7.log +15 -0
- package/test/example/logs/sys8.log +11 -0
- package/test/example/logs/sys9.log +10 -0
- package/test/example/resource/application-test.yml +0 -0
- package/test/example/resource/application.yml +7 -0
- package/test/example/resource/evnconfig-test.yml +1 -0
- package/test/example/resource/hello.yml +1 -0
- package/test/example/simple/app.ts +99 -0
- package/test/example/simple/component/StartRunner.ts +10 -0
- package/test/example/simple/component/StopRunner.ts +14 -0
- package/test/example/simple/config/EnvConfig.ts +6 -0
- package/test/example/simple/config/HelloConfig.ts +8 -0
- package/test/example/simple/controller/AliasController.ts +6 -0
- package/test/example/simple/controller/HelloController.ts +39 -0
- package/test/example/simple/controller/NotFoundController.ts +20 -0
- package/test/example/simple/service/CallService.ts +11 -0
- package/test/example/simple/service/HelloService.ts +10 -0
- package/test/example/simple/service/LogService.ts +19 -0
- package/test/logs/logger.log +0 -0
- package/test/logs/sys.log +227 -0
- package/test/multi/app.ts +15 -0
- package/test/multi/service/aService.ts +16 -0
- package/test/multi/service/bService.ts +18 -0
- package/test/multi/service/cService.ts +21 -0
- package/test/unit/dataMap-test.ts +48 -0
- package/test/unit/decorators-test.ts +38 -0
- package/test/unit/ds-test.ts +33 -0
- package/test/unit/logs/sys.log +24 -0
- package/test/unit/reflectMetadata-test.ts +15 -0
- package/test/unit/valid-test.ts +65 -0
- package/test/unit/winston-test.ts +15 -0
- package/utils.d.ts +166 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FastCarMetaData } from "../../constant/FastCarMetaData";
|
|
2
|
+
|
|
3
|
+
//应用别名声明
|
|
4
|
+
export default function BeanName(name: string) {
|
|
5
|
+
return function(target: any) {
|
|
6
|
+
//生成别名 用于逻辑识别
|
|
7
|
+
Reflect.defineMetadata(FastCarMetaData.Alias, name, target.prototype); //放入至原型中
|
|
8
|
+
};
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Component from "./Component";
|
|
2
|
+
import { LifeCycleModule } from "../../constant/LifeCycleModule";
|
|
3
|
+
|
|
4
|
+
//配置文件层
|
|
5
|
+
export default function Configure(name: string) {
|
|
6
|
+
return function (target: any) {
|
|
7
|
+
//配置对象也为组件
|
|
8
|
+
Component(target);
|
|
9
|
+
//当实例化时 加载默认配置并进行赋值
|
|
10
|
+
Reflect.defineMetadata(LifeCycleModule.LoadConfigure, name, target);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import CryptoUtil from "../../utils/CryptoUtil";
|
|
3
|
+
import { FastCarMetaData } from "../../constant/FastCarMetaData";
|
|
4
|
+
|
|
5
|
+
export default function Injection(target: any, name: string) {
|
|
6
|
+
//生成别名 避免名称重复的情况
|
|
7
|
+
let key = `${name}:${CryptoUtil.getHashStr()}`;
|
|
8
|
+
Reflect.defineMetadata(name, true, target.prototype);
|
|
9
|
+
Reflect.defineMetadata(FastCarMetaData.InjectionUniqueKey, key, target); //放入至原型中
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CommonConstant } from "../../constant/CommonConstant";
|
|
2
|
+
import FastCarApplication from "../../FastCarApplication";
|
|
3
|
+
import Logger from "../../interface/Logger";
|
|
4
|
+
|
|
5
|
+
//日志实例
|
|
6
|
+
export default function Log(category?: string) {
|
|
7
|
+
return function (target: any, propertyKey: string) {
|
|
8
|
+
let m = category || propertyKey;
|
|
9
|
+
|
|
10
|
+
Reflect.defineProperty(target, propertyKey, {
|
|
11
|
+
get: (): Logger => {
|
|
12
|
+
let app: FastCarApplication = Reflect.get(global, CommonConstant.FastcarApp);
|
|
13
|
+
return app ? app.getLogger(m) : console;
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { FastCarMetaData } from "../../constant/FastCarMetaData";
|
|
3
|
+
import { FormRuleModel } from "../../model/FormRuleModel";
|
|
4
|
+
import TypeUtil from "../../utils/TypeUtil";
|
|
5
|
+
import ValidationUtil from "../../utils/ValidationUtil";
|
|
6
|
+
|
|
7
|
+
//添加子元素的校验规则
|
|
8
|
+
export default function AddChildValid(target: any, name: string, value: { [key: string]: any }, index?: number) {
|
|
9
|
+
let childMap: Map<string, FormRuleModel>;
|
|
10
|
+
|
|
11
|
+
let paramsFlag = ValidationUtil.isNumber(index);
|
|
12
|
+
let alias = paramsFlag ? `${name}-${index}` : name;
|
|
13
|
+
if (paramsFlag) {
|
|
14
|
+
childMap = Reflect.getMetadata(FastCarMetaData.ValidChildFormRules, target, alias);
|
|
15
|
+
if (!childMap) {
|
|
16
|
+
childMap = new Map();
|
|
17
|
+
Reflect.defineMetadata(FastCarMetaData.ValidChildFormRules, childMap, target, alias);
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
childMap = Reflect.getMetadata(FastCarMetaData.ValidChildFormRules, target);
|
|
21
|
+
if (!childMap) {
|
|
22
|
+
childMap = new Map();
|
|
23
|
+
Reflect.defineMetadata(FastCarMetaData.ValidChildFormRules, childMap, target);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let item = childMap.get(alias);
|
|
28
|
+
if (!item) {
|
|
29
|
+
let proto = Reflect.getMetadata(FastCarMetaData.designType, target, name);
|
|
30
|
+
|
|
31
|
+
if (paramsFlag) {
|
|
32
|
+
//修改为方法获取原型
|
|
33
|
+
let paramsTypes = Reflect.getMetadata(FastCarMetaData.paramTypes, target, name);
|
|
34
|
+
if (typeof index == "number") {
|
|
35
|
+
proto = paramsTypes[index];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let typeName = proto.name.toLowerCase();
|
|
40
|
+
if (!TypeUtil.isBasic(typeName)) {
|
|
41
|
+
typeName = typeName == "array" ? "array" : "object";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
item = {
|
|
45
|
+
type: typeName,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//自定义方法合并
|
|
50
|
+
if (Reflect.has(value, "filters")) {
|
|
51
|
+
if (Array.isArray(item.filters)) {
|
|
52
|
+
item.filters.forEach((f) => {
|
|
53
|
+
value.filters.push(f);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//合并所有属性
|
|
59
|
+
Object.assign(item, value);
|
|
60
|
+
childMap.set(alias, item);
|
|
61
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import AddChildValid from "./AddChildValid";
|
|
2
|
+
import ValidationUtil from "../../utils/ValidationUtil";
|
|
3
|
+
|
|
4
|
+
//是否为非空字段
|
|
5
|
+
export default function NotNull(target: any, propertyKey: string, index?: number) {
|
|
6
|
+
AddChildValid(target, propertyKey, { required: true }, index);
|
|
7
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { FastCarMetaData } from "../../constant/FastCarMetaData";
|
|
3
|
+
import { FormRuleModel, FormRuleType } from "../../model/FormRuleModel";
|
|
4
|
+
import TypeUtil from "../../utils/TypeUtil";
|
|
5
|
+
|
|
6
|
+
export function Rule(rules: { [prop: string]: FormRuleModel } = {}) {
|
|
7
|
+
return function(target: any, method: string, index: number) {
|
|
8
|
+
//获取设计类型
|
|
9
|
+
//获取增强类型的增加严格校验
|
|
10
|
+
let paramsTypes = Reflect.getMetadata(FastCarMetaData.paramTypes, target, method);
|
|
11
|
+
|
|
12
|
+
//对rules进行进一步的补充
|
|
13
|
+
let designObj = paramsTypes[index];
|
|
14
|
+
let basicFlag = false;
|
|
15
|
+
if (!designObj) {
|
|
16
|
+
console.warn(`Design type not found by ${method} in ${index}`);
|
|
17
|
+
} else {
|
|
18
|
+
basicFlag = TypeUtil.isBasic(designObj.name);
|
|
19
|
+
//获取表单类型
|
|
20
|
+
let childMap: Map<string, FormRuleModel> = Reflect.getMetadata(FastCarMetaData.ValidChildFormRules, target, `${method}-${index}`);
|
|
21
|
+
|
|
22
|
+
//进行合并添加
|
|
23
|
+
if (TypeUtil.isClass(designObj)) {
|
|
24
|
+
let appendMap: Map<string, FormRuleModel> = Reflect.getMetadata(FastCarMetaData.ValidChildFormRules, designObj.prototype);
|
|
25
|
+
if (appendMap) {
|
|
26
|
+
if (!childMap) {
|
|
27
|
+
childMap = new Map();
|
|
28
|
+
}
|
|
29
|
+
appendMap.forEach((v, key) => {
|
|
30
|
+
if (!childMap.has(key)) {
|
|
31
|
+
childMap.set(key, v);
|
|
32
|
+
return;
|
|
33
|
+
} else {
|
|
34
|
+
//进行覆盖更新
|
|
35
|
+
let item = childMap.get(key);
|
|
36
|
+
if (Reflect.has(v, "filters")) {
|
|
37
|
+
if (Array.isArray(item?.filters)) {
|
|
38
|
+
v.filters?.forEach(f => {
|
|
39
|
+
item?.filters?.push(f);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//合并所有属性
|
|
45
|
+
item = Object.assign(v, item);
|
|
46
|
+
childMap.set(key, item);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (childMap && childMap.size > 0) {
|
|
52
|
+
//补充表单
|
|
53
|
+
childMap.forEach((citem, prop) => {
|
|
54
|
+
if (Reflect.has(rules, prop)) {
|
|
55
|
+
//优先取表单里的
|
|
56
|
+
rules[prop] = Object.assign(citem, rules[prop]);
|
|
57
|
+
} else {
|
|
58
|
+
Reflect.set(rules, prop, citem);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let rulesMap: Map<number, FormRuleType> = Reflect.getMetadata(FastCarMetaData.ValidFormRules, target, method);
|
|
65
|
+
if (!rulesMap) {
|
|
66
|
+
rulesMap = new Map<number, FormRuleType>();
|
|
67
|
+
Reflect.defineMetadata(FastCarMetaData.ValidFormRules, rulesMap, target, method);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//补全消息
|
|
71
|
+
Object.keys(rules).forEach(prop => {
|
|
72
|
+
let r = rules[prop];
|
|
73
|
+
|
|
74
|
+
//根据增强型补全type
|
|
75
|
+
if (basicFlag && !Reflect.has(r, "type")) {
|
|
76
|
+
if (designObj) {
|
|
77
|
+
r.type = designObj.name.toLowerCase();
|
|
78
|
+
} else {
|
|
79
|
+
r.type = "string";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (r.message) {
|
|
84
|
+
if (r.required) {
|
|
85
|
+
r.nullMessage = r.nullMessage ? r.nullMessage : r.message;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (r.maxSize || r.minSize) {
|
|
89
|
+
r.sizeMessgae = r.sizeMessgae ? r.sizeMessgae : r.message;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
r.typeMessage = r.typeMessage ? r.typeMessage : r.message;
|
|
93
|
+
} else {
|
|
94
|
+
if (r.required) {
|
|
95
|
+
r.nullMessage = `${prop} is required`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
r.typeMessage = `${prop} type is ${r.type}`;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
rulesMap.set(index, { rules, basicFlag, index });
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import AddChildValid from "./AddChildValid";
|
|
2
|
+
|
|
3
|
+
type SizeModel = {
|
|
4
|
+
minSize?: number;
|
|
5
|
+
maxSize?: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
//校验长度
|
|
9
|
+
export default function Size(m: SizeModel = { minSize: 0, maxSize: 0 }) {
|
|
10
|
+
return function(target: any, propertyKey: string, index?: number) {
|
|
11
|
+
AddChildValid(target, propertyKey, m, index);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import AddChildValid from "./AddChildValid";
|
|
2
|
+
type checkfun = (val: any) => boolean;
|
|
3
|
+
|
|
4
|
+
//自定义表单校验
|
|
5
|
+
export default function ValidCustom(fn: checkfun, message?: string) {
|
|
6
|
+
return function(target: any, propertyKey: string, index?: number) {
|
|
7
|
+
AddChildValid(
|
|
8
|
+
target,
|
|
9
|
+
propertyKey,
|
|
10
|
+
{
|
|
11
|
+
filters: [
|
|
12
|
+
{
|
|
13
|
+
fn,
|
|
14
|
+
message,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
index
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { FormRuleModel, FormRuleType } from "../../model/FormRuleModel";
|
|
2
|
+
import ValidError from "../../model/ValidError";
|
|
3
|
+
import { TypeUtil } from "../../utils";
|
|
4
|
+
import ValidationUtil from "../../utils/ValidationUtil";
|
|
5
|
+
import DATAFORMAT from "../../utils/DataFormat";
|
|
6
|
+
import { FastCarMetaData } from "../../constant/FastCarMetaData";
|
|
7
|
+
|
|
8
|
+
function throwErrMsg(rule: FormRuleModel, prop: string, msg?: string) {
|
|
9
|
+
let showMsg = msg;
|
|
10
|
+
if (!showMsg) {
|
|
11
|
+
showMsg = rule.message ? rule.message : `The ${prop} parameter is invalid `;
|
|
12
|
+
}
|
|
13
|
+
throw new ValidError(showMsg);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getFormValue(value: any, prop: string, defaultValue?: any) {
|
|
17
|
+
//查看是否校验子属性
|
|
18
|
+
if (ValidationUtil.isNotNull(value)) {
|
|
19
|
+
if (TypeUtil.isObject(value)) {
|
|
20
|
+
if (Reflect.has(value, prop)) {
|
|
21
|
+
let propValue = Reflect.get(value, prop);
|
|
22
|
+
if (ValidationUtil.isNotNull(propValue)) {
|
|
23
|
+
return propValue;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (ValidationUtil.isNotNull(defaultValue)) {
|
|
32
|
+
return defaultValue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function setFormValue(obj: any, prop: string, val: any) {
|
|
39
|
+
//查看是否校验子属性
|
|
40
|
+
if (ValidationUtil.isNotNull(obj) || TypeUtil.isObject(obj)) {
|
|
41
|
+
//修正为{}对象时无法赋值错误
|
|
42
|
+
if (TypeUtil.isObject(obj)) {
|
|
43
|
+
Reflect.set(obj, prop, val);
|
|
44
|
+
} else {
|
|
45
|
+
obj = val;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function delFormValue(value: any, prop: string) {
|
|
53
|
+
if (ValidationUtil.isNotNull(value)) {
|
|
54
|
+
if (TypeUtil.isObject(value)) {
|
|
55
|
+
if (Reflect.has(value, prop)) {
|
|
56
|
+
Reflect.deleteProperty(value, prop);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/***
|
|
63
|
+
* @version 1.0 校验表单 支持校验大小 类型 和自定义方法
|
|
64
|
+
* @param rules key - value的形式 通常一个参数一个校验方式
|
|
65
|
+
* @param paramIndex 位于第几个参数的校验表单
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
export default function ValidForm(target: any, methodName: string, descriptor: PropertyDescriptor) {
|
|
69
|
+
let next = descriptor.value;
|
|
70
|
+
|
|
71
|
+
descriptor.value = function (...args: any[]) {
|
|
72
|
+
let rulesMap: Map<number, FormRuleType> = Reflect.getMetadata(FastCarMetaData.ValidFormRules, target, methodName);
|
|
73
|
+
|
|
74
|
+
if (rulesMap && rulesMap.size > 0) {
|
|
75
|
+
rulesMap.forEach((item, paramIndex) => {
|
|
76
|
+
let { rules, basicFlag } = item;
|
|
77
|
+
let currObj = args[paramIndex];
|
|
78
|
+
|
|
79
|
+
if (ValidationUtil.isNull(currObj)) {
|
|
80
|
+
currObj = basicFlag ? "" : {};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (let prop in rules) {
|
|
84
|
+
let rule = rules[prop];
|
|
85
|
+
|
|
86
|
+
//进行取值
|
|
87
|
+
let val = getFormValue(currObj, prop, rule.defaultVal);
|
|
88
|
+
|
|
89
|
+
//判断关键字是否相同
|
|
90
|
+
if (`${methodName}-${paramIndex}` == prop) {
|
|
91
|
+
val = currObj || rule.defaultVal;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//优先判断是否为必填项
|
|
95
|
+
if (ValidationUtil.isNull(val)) {
|
|
96
|
+
if (rule.required) {
|
|
97
|
+
throwErrMsg(rule, prop, rule.nullMessage);
|
|
98
|
+
} else {
|
|
99
|
+
delFormValue(currObj, prop);
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
//进行类型判断并赋值
|
|
103
|
+
let checkType = rule.type || "string";
|
|
104
|
+
val = DATAFORMAT.formatValue(val, checkType);
|
|
105
|
+
//调用check的方法
|
|
106
|
+
if (!ValidationUtil.checkType(val, checkType)) {
|
|
107
|
+
throwErrMsg(rule, prop, rule.typeMessage);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//判断长度
|
|
111
|
+
if (rule?.minSize) {
|
|
112
|
+
if (!ValidationUtil.isNotMinSize(val, rule.minSize)) {
|
|
113
|
+
throwErrMsg(rule, prop, rule.sizeMessgae ? rule.sizeMessgae : `${prop} should be greater than ${rule.minSize} `);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (rule?.maxSize) {
|
|
118
|
+
if (!ValidationUtil.isNotMaxSize(val, rule.maxSize)) {
|
|
119
|
+
throwErrMsg(rule, prop, rule.sizeMessgae ? rule.sizeMessgae : `${prop} should be less than ${rule.maxSize} `);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//自定义方法校验
|
|
124
|
+
if (Array.isArray(rule.filters)) {
|
|
125
|
+
for (let fnItem of rule.filters) {
|
|
126
|
+
let fn = fnItem.fn;
|
|
127
|
+
let flag = Reflect.apply(fn, this, [val]);
|
|
128
|
+
if (!flag) {
|
|
129
|
+
//抛出错误提示
|
|
130
|
+
throwErrMsg(rule, prop, fnItem.message || rule.message);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//进行赋值
|
|
136
|
+
currObj = setFormValue(currObj, prop, val);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
args[paramIndex] = currObj;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return Reflect.apply(next, this, args);
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import Application from "./annotation/Application";
|
|
2
|
+
import Autowired from "./annotation/bind/Autowired";
|
|
3
|
+
import ENV from "./annotation/env/ENV";
|
|
4
|
+
import ExceptionMonitor from "./annotation/ExceptionMonitor";
|
|
5
|
+
import ApplicationStart from "./annotation/lifeCycle/ApplicationStart";
|
|
6
|
+
import ApplicationStop from "./annotation/lifeCycle/ApplicationStop";
|
|
7
|
+
import Deprecate from "./annotation/property/Deprecate";
|
|
8
|
+
import NotImplemented from "./annotation/property/NotImplemented";
|
|
9
|
+
import Override from "./annotation/property/Override";
|
|
10
|
+
import Readonly from "./annotation/property/Readonly";
|
|
11
|
+
import ComponentScan from "./annotation/scan/ComponentScan";
|
|
12
|
+
import ComponentScanExclusion from "./annotation/scan/ComponentScanExclusion";
|
|
13
|
+
import Component from "./annotation/stereotype/Component";
|
|
14
|
+
import Configure from "./annotation/stereotype/Configure";
|
|
15
|
+
import Controller from "./annotation/stereotype/Controller";
|
|
16
|
+
import Injection from "./annotation/stereotype/Injection";
|
|
17
|
+
import Service from "./annotation/stereotype/Service";
|
|
18
|
+
import Repository from "./annotation/stereotype/Repository";
|
|
19
|
+
import AddRequireModule from "./annotation/bind/AddRequireModule";
|
|
20
|
+
import DS from "./annotation/data/DS";
|
|
21
|
+
import DSIndex from "./annotation/data/DSIndex";
|
|
22
|
+
import AddChildValid from "./annotation/valid/AddChildValid";
|
|
23
|
+
import DefaultVal from "./annotation/valid/DefaultVal";
|
|
24
|
+
import NotNull from "./annotation/valid/NotNull";
|
|
25
|
+
import Size from "./annotation/valid/Size";
|
|
26
|
+
import Type from "./annotation/valid/Type";
|
|
27
|
+
import ValidCustom from "./annotation/valid/ValidCustom";
|
|
28
|
+
import ValidForm from "./annotation/valid/ValidForm";
|
|
29
|
+
import { Rule } from "./annotation/valid/Rule";
|
|
30
|
+
import BeanName from "./annotation/stereotype/BeanName";
|
|
31
|
+
import ComponentInjection from "./annotation/scan/ComponentInjection";
|
|
32
|
+
import DBType from "./annotation/data/DBType";
|
|
33
|
+
import Field from "./annotation/data/Field";
|
|
34
|
+
import PrimaryKey from "./annotation/data/PrimaryKey";
|
|
35
|
+
import Table from "./annotation/data/Table";
|
|
36
|
+
import Entity from "./annotation/data/Entity";
|
|
37
|
+
import SqlSession from "./annotation/data/SqlSession";
|
|
38
|
+
import Transactional from "./annotation/data/Transactional";
|
|
39
|
+
import Log from "./annotation/stereotype/Log";
|
|
40
|
+
import BaseFilePath from "./annotation/env/BaseFilePath";
|
|
41
|
+
import BasePath from "./annotation/env/BasePath";
|
|
42
|
+
import CallDependency from "./annotation/bind/CallDependency";
|
|
43
|
+
import Hotter from "./annotation/scan/Hotter";
|
|
44
|
+
import ApplicationRunner from "./annotation/lifeCycle/ApplicationRunner";
|
|
45
|
+
import ApplicationInit from "./annotation/lifeCycle/ApplicationInit";
|
|
46
|
+
import ApplicationDestory from "./annotation/lifeCycle/ApplicationDestory";
|
|
47
|
+
import ApplicationSetting from "./annotation/env/ApplicationSetting";
|
|
48
|
+
import AliasInjection from "./annotation/bind/AliasInjection";
|
|
49
|
+
import ResourcePath from "./annotation/env/ResourcePath";
|
|
50
|
+
|
|
51
|
+
//注解暴露出去
|
|
52
|
+
export {
|
|
53
|
+
ApplicationStart,
|
|
54
|
+
ApplicationStop,
|
|
55
|
+
ApplicationRunner,
|
|
56
|
+
ApplicationInit,
|
|
57
|
+
ApplicationDestory,
|
|
58
|
+
ComponentScan,
|
|
59
|
+
ComponentScanExclusion,
|
|
60
|
+
Component,
|
|
61
|
+
ComponentInjection,
|
|
62
|
+
Hotter,
|
|
63
|
+
BeanName,
|
|
64
|
+
Configure,
|
|
65
|
+
Controller,
|
|
66
|
+
Service,
|
|
67
|
+
Repository,
|
|
68
|
+
Injection,
|
|
69
|
+
Application,
|
|
70
|
+
Autowired,
|
|
71
|
+
CallDependency,
|
|
72
|
+
AliasInjection,
|
|
73
|
+
ExceptionMonitor,
|
|
74
|
+
Deprecate,
|
|
75
|
+
NotImplemented,
|
|
76
|
+
Override,
|
|
77
|
+
Readonly,
|
|
78
|
+
Log,
|
|
79
|
+
AddRequireModule,
|
|
80
|
+
AddChildValid,
|
|
81
|
+
DefaultVal,
|
|
82
|
+
NotNull,
|
|
83
|
+
Size,
|
|
84
|
+
Type,
|
|
85
|
+
ValidCustom,
|
|
86
|
+
ValidForm,
|
|
87
|
+
Rule,
|
|
88
|
+
ResourcePath,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
DS,
|
|
93
|
+
DSIndex,
|
|
94
|
+
DBType, //数据库类型
|
|
95
|
+
Field, //数据库字段名
|
|
96
|
+
PrimaryKey, //是否为主键
|
|
97
|
+
Table, //表名
|
|
98
|
+
Entity, //表和对应编程内的类型映射
|
|
99
|
+
SqlSession, //连接会话 如果需要使用同一连接或者使用事务是传递
|
|
100
|
+
Transactional, //事务管理
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export { ENV, BaseFilePath, BasePath, ApplicationSetting };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WinstonLoggerType } from "../type/WinstonLoggerType";
|
|
2
|
+
import { ApplicationConfig } from "./ApplicationConfig";
|
|
3
|
+
|
|
4
|
+
/***
|
|
5
|
+
* @version 1.0 系统基础配置
|
|
6
|
+
*/
|
|
7
|
+
export type SYSConfig = {
|
|
8
|
+
application: ApplicationConfig; //应用配置
|
|
9
|
+
settings: Map<string | symbol, any>; //自定义设置项
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const SYSDefaultConfig: SYSConfig = {
|
|
13
|
+
application: {
|
|
14
|
+
name: "app",
|
|
15
|
+
env: "development",
|
|
16
|
+
version: "1.0.0",
|
|
17
|
+
},
|
|
18
|
+
settings: new Map<string, Object>(), //自定义配置
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const LogDefaultConfig: WinstonLoggerType = {
|
|
22
|
+
consoleLevel: "info",
|
|
23
|
+
fileLevel: "info",
|
|
24
|
+
rootPath: __dirname, //日志路径
|
|
25
|
+
maxsize: 1024 * 1024 * 10, //默认10M
|
|
26
|
+
maxFiles: 30,
|
|
27
|
+
printConsole: true,
|
|
28
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const CommonConstant = {
|
|
2
|
+
Application: "application",
|
|
3
|
+
Settings: "settings",
|
|
4
|
+
Resource: "resource",
|
|
5
|
+
ENV: Symbol("env"),
|
|
6
|
+
BasePath: Symbol("basePath"),
|
|
7
|
+
BaseFileName: Symbol("baseFileName"),
|
|
8
|
+
SYSLOGGER: "sys",
|
|
9
|
+
FastcarApp: Symbol("FastcarApp"), //应用app
|
|
10
|
+
FastcarSetting: Symbol("FastcarSetting"),
|
|
11
|
+
ResourcePath: "resourcePath",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const FileResSuffix = ["json", "yml", "js"];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//数据类型枚举
|
|
2
|
+
export enum DataTypes {
|
|
3
|
+
BOOLEAN = "boolean",
|
|
4
|
+
NUMBER = "number",
|
|
5
|
+
STRING = "string",
|
|
6
|
+
INT = "int",
|
|
7
|
+
FLOAT = "float",
|
|
8
|
+
DATE = "date",
|
|
9
|
+
Object = "object",
|
|
10
|
+
ARRAYNUMBER = "arraynumber",
|
|
11
|
+
ARRAYINT = "arrayint",
|
|
12
|
+
ARRAYFLOAT = "arrayfloat",
|
|
13
|
+
ARRAYSTRING = "arraystring",
|
|
14
|
+
ARRAYOBJECT = "arrayobject",
|
|
15
|
+
}
|