@fastcar/core 0.2.63 → 0.3.0
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 +5 -2
- package/annotation.d.ts +3 -0
- package/index.d.ts +57 -50
- package/package.json +4 -4
- package/src/FastCarApplication.ts +184 -123
- package/src/annotation/Application.ts +3 -1
- package/src/annotation/bind/AddInjectionService.ts +17 -0
- package/src/annotation/bind/AddRequireModule.ts +1 -1
- package/src/annotation/bind/AliasInjection.ts +8 -15
- package/src/annotation/bind/Autowired.ts +1 -1
- package/src/annotation/bind/CallDependency.ts +7 -17
- package/src/annotation/bind/DemandInjection.ts +16 -0
- package/src/annotation/stereotype/Log.ts +13 -9
- package/src/annotation/stereotype/Value.ts +5 -0
- package/src/annotation.ts +2 -0
- package/src/constant/FastCarMetaData.ts +2 -0
- package/src/model/WinstonLogger.ts +1 -1
- package/src/type/ClassConstructor.ts +5 -0
- package/src/type/ComponentDesc.ts +13 -0
- package/src/type/FileHotterDesc.ts +6 -0
- package/src/utils/ClassLoader.ts +2 -1
- package/src/utils/ValidationUtil.ts +1 -1
- package/target/FastCarApplication.js +764 -708
- package/target/annotation/Application.js +46 -45
- package/target/annotation/ExceptionMonitor.js +16 -16
- package/target/annotation/bind/AddInjectionService.js +16 -0
- package/target/annotation/bind/AddRequireModule.js +21 -21
- package/target/annotation/bind/AliasInjection.js +19 -23
- package/target/annotation/bind/Autowired.js +13 -13
- package/target/annotation/bind/CallDependency.js +16 -23
- package/target/annotation/bind/DemandInjection.js +15 -0
- package/target/annotation/data/DBType.js +11 -11
- package/target/annotation/data/DS.js +54 -54
- package/target/annotation/data/DSIndex.js +9 -9
- package/target/annotation/data/Entity.js +10 -10
- package/target/annotation/data/Field.js +18 -18
- package/target/annotation/data/PrimaryKey.js +9 -9
- package/target/annotation/data/SqlSession.js +9 -9
- package/target/annotation/data/Table.js +35 -35
- package/target/annotation/data/Transactional.js +52 -52
- package/target/annotation/env/ApplicationSetting.js +25 -25
- package/target/annotation/env/BaseFilePath.js +14 -14
- package/target/annotation/env/BaseName.js +9 -9
- package/target/annotation/env/BasePath.js +14 -14
- package/target/annotation/env/ENV.js +10 -10
- package/target/annotation/env/ResourcePath.js +9 -9
- package/target/annotation/lifeCycle/AddLifeCycleItem.js +17 -18
- package/target/annotation/lifeCycle/ApplicationDestory.js +15 -15
- package/target/annotation/lifeCycle/ApplicationInit.js +15 -15
- package/target/annotation/lifeCycle/ApplicationRunner.js +7 -7
- package/target/annotation/lifeCycle/ApplicationStart.js +24 -24
- package/target/annotation/lifeCycle/ApplicationStop.js +20 -20
- package/target/annotation/property/Deprecate.js +19 -19
- package/target/annotation/property/NotImplemented.js +8 -8
- package/target/annotation/property/Override.js +7 -7
- package/target/annotation/property/Readonly.js +16 -16
- package/target/annotation/scan/ComponentInjection.js +21 -21
- package/target/annotation/scan/ComponentScan.js +9 -9
- package/target/annotation/scan/ComponentScanExclusion.js +25 -25
- package/target/annotation/scan/ComponentScanMust.js +25 -25
- package/target/annotation/scan/Hotter.js +8 -8
- package/target/annotation/stereotype/BeanName.js +11 -11
- package/target/annotation/stereotype/Component.js +8 -8
- package/target/annotation/stereotype/Configure.js +14 -14
- package/target/annotation/stereotype/Controller.js +9 -9
- package/target/annotation/stereotype/Injection.js +12 -12
- package/target/annotation/stereotype/Log.js +19 -17
- package/target/annotation/stereotype/Repository.js +9 -9
- package/target/annotation/stereotype/Service.js +9 -9
- package/target/annotation/stereotype/Value.js +5 -0
- package/target/annotation/valid/AddChildValid.js +56 -56
- package/target/annotation/valid/CustomType.js +11 -11
- package/target/annotation/valid/DefaultVal.js +10 -10
- package/target/annotation/valid/NotNull.js +8 -8
- package/target/annotation/valid/Rule.js +99 -100
- package/target/annotation/valid/Size.js +10 -10
- package/target/annotation/valid/Type.js +10 -10
- package/target/annotation/valid/ValidCustom.js +17 -17
- package/target/annotation/valid/ValidForm.js +133 -133
- package/target/annotation.js +110 -108
- package/target/config/ApplicationConfig.js +2 -2
- package/target/config/SysConfig.js +19 -19
- package/target/constant/AppStatusEnum.js +9 -9
- package/target/constant/BootPriority.js +11 -11
- package/target/constant/CommonConstant.js +18 -18
- package/target/constant/ComponentKind.js +11 -11
- package/target/constant/DataTypes.js +19 -19
- package/target/constant/FastCarMetaData.js +33 -31
- package/target/constant/LifeCycleModule.js +9 -9
- package/target/db.js +49 -49
- package/target/index.js +21 -21
- package/target/interface/ApplicationHook.js +2 -2
- package/target/interface/ApplicationInterface.js +2 -2
- package/target/interface/ApplicationRunnerService.js +2 -2
- package/target/interface/DataSourceManager.js +2 -2
- package/target/interface/Logger.js +5 -5
- package/target/model/BaseMapper.js +103 -98
- package/target/model/DataMap.js +87 -87
- package/target/model/FormRuleModel.js +2 -2
- package/target/model/ValidError.js +5 -5
- package/target/model/WinstonLogger.js +98 -96
- package/target/type/ClassConstructor.js +2 -0
- package/target/type/ComponentDesc.js +9 -2
- package/target/type/DesignMeta.js +15 -15
- package/target/type/FileHotterDesc.js +9 -2
- package/target/type/MapperType.js +2 -2
- package/target/type/ProcessType.js +2 -2
- package/target/type/SqlError.js +5 -5
- package/target/type/WinstonLoggerType.js +9 -9
- package/target/utils/ClassLoader.js +66 -65
- package/target/utils/ClassUtils.js +35 -35
- package/target/utils/CryptoUtil.js +86 -86
- package/target/utils/DataFormat.js +88 -88
- package/target/utils/DateUtil.js +71 -71
- package/target/utils/FileUtil.js +153 -153
- package/target/utils/FormatStr.js +14 -14
- package/target/utils/IPUtils.js +34 -34
- package/target/utils/Id.js +8 -9
- package/target/utils/Mix.js +62 -62
- package/target/utils/ReflectUtil.js +22 -22
- package/target/utils/TypeUtil.js +53 -53
- package/target/utils/ValidationUtil.js +123 -123
- package/target/utils.js +25 -25
- package/test/example/logs/fastcar-server.app.log +0 -0
- package/test/example/logs/fastcar-server.sys.log +10 -0
- package/test/example/logs/fastcar-server.sys1.log +8 -0
- package/test/example/logs/fastcar-server.sys2.log +11 -0
- package/test/example/logs/fastcar-server.sys3.log +0 -0
- package/test/example/logs/other-server.app.log +0 -0
- package/test/example/logs/other-server.sys.log +5 -0
- package/test/example/logs/sys.log +0 -0
- package/test/example/logs/sys1.log +0 -0
- package/test/example/resource/application.yml +2 -0
- package/test/example/resource/hello.yml +1 -1
- package/test/example/simple/app-test.ts +2 -1
- package/test/example/simple/app.ts +16 -16
- package/test/example/simple/service/CallService.ts +2 -0
- package/test/example/simple/service/HelloService.ts +2 -0
- package/test/unit/sys2.log +6 -0
- package/test/unit/sys3.log +6 -0
- package/test/unit/sys4.log +6 -0
- package/test/unit/sys5.log +6 -0
- package/test/unit/sys6.log +6 -0
|
@@ -1,100 +1,99 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Rule =
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
|
|
6
|
-
const TypeUtil_1 = require("../../utils/TypeUtil");
|
|
7
|
-
function Rule(rules = {}) {
|
|
8
|
-
return function (target, method, index) {
|
|
9
|
-
//获取设计类型
|
|
10
|
-
//获取增强类型的增加严格校验
|
|
11
|
-
let paramsTypes = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.paramTypes, target, method);
|
|
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
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
basicFlag = TypeUtil_1.default.isBasic(designObj.name);
|
|
20
|
-
//获取表单类型
|
|
21
|
-
let childMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidChildFormRules, target, `${method}-${index}`);
|
|
22
|
-
//进行合并添加
|
|
23
|
-
if (TypeUtil_1.default.isClass(designObj)) {
|
|
24
|
-
let appendMap = Reflect.getMetadata(FastCarMetaData_1.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
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
//进行覆盖更新
|
|
36
|
-
let item = childMap.get(key);
|
|
37
|
-
if (Reflect.has(v, "filters")) {
|
|
38
|
-
if (Array.isArray(item?.filters)) {
|
|
39
|
-
v.filters?.forEach(f => {
|
|
40
|
-
item?.filters?.push(f);
|
|
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
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
Reflect.set(rules, prop, citem);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
let rulesMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidFormRules, target, method);
|
|
65
|
-
if (!rulesMap) {
|
|
66
|
-
rulesMap = new Map();
|
|
67
|
-
Reflect.defineMetadata(FastCarMetaData_1.FastCarMetaData.ValidFormRules, rulesMap, target, method);
|
|
68
|
-
}
|
|
69
|
-
//补全消息
|
|
70
|
-
Object.keys(rules).forEach(prop => {
|
|
71
|
-
let r = rules[prop];
|
|
72
|
-
//根据增强型补全type
|
|
73
|
-
if (basicFlag && !Reflect.has(r, "type")) {
|
|
74
|
-
if (designObj) {
|
|
75
|
-
r.type = designObj.name.toLowerCase();
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
r.type = "string";
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (r.message) {
|
|
82
|
-
if (r.required) {
|
|
83
|
-
r.nullMessage = r.nullMessage ? r.nullMessage : r.message;
|
|
84
|
-
}
|
|
85
|
-
if (r.maxSize || r.minSize) {
|
|
86
|
-
r.sizeMessgae = r.sizeMessgae ? r.sizeMessgae : r.message;
|
|
87
|
-
}
|
|
88
|
-
r.typeMessage = r.typeMessage ? r.typeMessage : r.message;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
if (r.required) {
|
|
92
|
-
r.nullMessage = `${prop} is required`;
|
|
93
|
-
}
|
|
94
|
-
r.typeMessage = `${prop} type is ${r.type}`;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
rulesMap.set(index, { rules, basicFlag, index });
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
exports.Rule = Rule;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Rule = Rule;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
|
|
6
|
+
const TypeUtil_1 = require("../../utils/TypeUtil");
|
|
7
|
+
function Rule(rules = {}) {
|
|
8
|
+
return function (target, method, index) {
|
|
9
|
+
//获取设计类型
|
|
10
|
+
//获取增强类型的增加严格校验
|
|
11
|
+
let paramsTypes = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.paramTypes, target, method);
|
|
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
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
basicFlag = TypeUtil_1.default.isBasic(designObj.name);
|
|
20
|
+
//获取表单类型
|
|
21
|
+
let childMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidChildFormRules, target, `${method}-${index}`);
|
|
22
|
+
//进行合并添加
|
|
23
|
+
if (TypeUtil_1.default.isClass(designObj)) {
|
|
24
|
+
let appendMap = Reflect.getMetadata(FastCarMetaData_1.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
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
//进行覆盖更新
|
|
36
|
+
let item = childMap.get(key);
|
|
37
|
+
if (Reflect.has(v, "filters")) {
|
|
38
|
+
if (Array.isArray(item?.filters)) {
|
|
39
|
+
v.filters?.forEach(f => {
|
|
40
|
+
item?.filters?.push(f);
|
|
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
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
Reflect.set(rules, prop, citem);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
let rulesMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidFormRules, target, method);
|
|
65
|
+
if (!rulesMap) {
|
|
66
|
+
rulesMap = new Map();
|
|
67
|
+
Reflect.defineMetadata(FastCarMetaData_1.FastCarMetaData.ValidFormRules, rulesMap, target, method);
|
|
68
|
+
}
|
|
69
|
+
//补全消息
|
|
70
|
+
Object.keys(rules).forEach(prop => {
|
|
71
|
+
let r = rules[prop];
|
|
72
|
+
//根据增强型补全type
|
|
73
|
+
if (basicFlag && !Reflect.has(r, "type")) {
|
|
74
|
+
if (designObj) {
|
|
75
|
+
r.type = designObj.name.toLowerCase();
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
r.type = "string";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (r.message) {
|
|
82
|
+
if (r.required) {
|
|
83
|
+
r.nullMessage = r.nullMessage ? r.nullMessage : r.message;
|
|
84
|
+
}
|
|
85
|
+
if (r.maxSize || r.minSize) {
|
|
86
|
+
r.sizeMessgae = r.sizeMessgae ? r.sizeMessgae : r.message;
|
|
87
|
+
}
|
|
88
|
+
r.typeMessage = r.typeMessage ? r.typeMessage : r.message;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (r.required) {
|
|
92
|
+
r.nullMessage = `${prop} is required`;
|
|
93
|
+
}
|
|
94
|
+
r.typeMessage = `${prop} type is ${r.type}`;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
rulesMap.set(index, { rules, basicFlag, index });
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = Size;
|
|
4
|
+
const AddChildValid_1 = require("./AddChildValid");
|
|
5
|
+
//校验长度
|
|
6
|
+
function Size(m = { minSize: 0, maxSize: 0 }) {
|
|
7
|
+
return function (target, propertyKey, index) {
|
|
8
|
+
(0, AddChildValid_1.default)(target, propertyKey, m, index);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = Type;
|
|
4
|
+
const AddChildValid_1 = require("./AddChildValid");
|
|
5
|
+
//表明类型
|
|
6
|
+
function Type(type) {
|
|
7
|
+
return function (target, propertyKey, index) {
|
|
8
|
+
(0, AddChildValid_1.default)(target, propertyKey, { type: type.toLowerCase() }, index);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = ValidCustom;
|
|
4
|
+
const AddChildValid_1 = require("./AddChildValid");
|
|
5
|
+
//自定义表单校验
|
|
6
|
+
function ValidCustom(fn, message) {
|
|
7
|
+
return function (target, propertyKey, index) {
|
|
8
|
+
(0, AddChildValid_1.default)(target, propertyKey, {
|
|
9
|
+
filters: [
|
|
10
|
+
{
|
|
11
|
+
fn,
|
|
12
|
+
message,
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
}, index);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* @
|
|
60
|
-
* @param
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
descriptor.value
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
let
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = ValidForm;
|
|
4
|
+
const ValidError_1 = require("../../model/ValidError");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const ValidationUtil_1 = require("../../utils/ValidationUtil");
|
|
7
|
+
const DataFormat_1 = require("../../utils/DataFormat");
|
|
8
|
+
const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
|
|
9
|
+
function throwErrMsg(rule, prop, msg) {
|
|
10
|
+
let showMsg = msg;
|
|
11
|
+
if (!showMsg) {
|
|
12
|
+
showMsg = rule.message ? rule.message : `The ${prop} parameter is invalid `;
|
|
13
|
+
}
|
|
14
|
+
throw new ValidError_1.default(showMsg);
|
|
15
|
+
}
|
|
16
|
+
function getFormValue(value, prop, defaultValue) {
|
|
17
|
+
//查看是否校验子属性
|
|
18
|
+
if (ValidationUtil_1.default.isNotNull(value)) {
|
|
19
|
+
if (utils_1.TypeUtil.isObject(value)) {
|
|
20
|
+
if (Reflect.has(value, prop)) {
|
|
21
|
+
let propValue = Reflect.get(value, prop);
|
|
22
|
+
if (ValidationUtil_1.default.isNotNull(propValue)) {
|
|
23
|
+
return propValue;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (ValidationUtil_1.default.isNotNull(defaultValue)) {
|
|
32
|
+
return defaultValue;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
function setFormValue(obj, prop, val) {
|
|
37
|
+
//查看是否校验子属性
|
|
38
|
+
if (ValidationUtil_1.default.isNotNull(obj) || utils_1.TypeUtil.isObject(obj)) {
|
|
39
|
+
//修正为{}对象时无法赋值错误
|
|
40
|
+
if (utils_1.TypeUtil.isObject(obj)) {
|
|
41
|
+
Reflect.set(obj, prop, val);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
obj = val;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return obj;
|
|
48
|
+
}
|
|
49
|
+
function delFormValue(value, prop) {
|
|
50
|
+
if (ValidationUtil_1.default.isNotNull(value)) {
|
|
51
|
+
if (utils_1.TypeUtil.isObject(value)) {
|
|
52
|
+
if (Reflect.has(value, prop)) {
|
|
53
|
+
Reflect.deleteProperty(value, prop);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/***
|
|
59
|
+
* @version 1.0 校验表单 支持校验大小 类型 和自定义方法
|
|
60
|
+
* @param rules key - value的形式 通常一个参数一个校验方式
|
|
61
|
+
* @param paramIndex 位于第几个参数的校验表单
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
function ValidForm(target, methodName, descriptor) {
|
|
65
|
+
let next = descriptor.value;
|
|
66
|
+
descriptor.value = function (...args) {
|
|
67
|
+
let rulesMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidFormRules, target, methodName);
|
|
68
|
+
if (rulesMap && rulesMap.size > 0) {
|
|
69
|
+
rulesMap.forEach((item, paramIndex) => {
|
|
70
|
+
let { rules, basicFlag } = item;
|
|
71
|
+
let currObj = args[paramIndex];
|
|
72
|
+
if (ValidationUtil_1.default.isNull(currObj)) {
|
|
73
|
+
currObj = basicFlag ? "" : {};
|
|
74
|
+
}
|
|
75
|
+
for (let prop in rules) {
|
|
76
|
+
let rule = rules[prop];
|
|
77
|
+
//进行取值
|
|
78
|
+
let val = getFormValue(currObj, prop, rule.defaultVal);
|
|
79
|
+
//判断关键字是否相同
|
|
80
|
+
if (`${methodName}-${paramIndex}` == prop) {
|
|
81
|
+
val = currObj || rule.defaultVal;
|
|
82
|
+
}
|
|
83
|
+
//优先判断是否为必填项
|
|
84
|
+
if (ValidationUtil_1.default.isNull(val)) {
|
|
85
|
+
if (rule.required) {
|
|
86
|
+
throwErrMsg(rule, prop, rule.nullMessage);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if (utils_1.TypeUtil.isObject(currObj) && !Reflect.has(currObj, prop)) {
|
|
90
|
+
delFormValue(currObj, prop);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
//进行类型判断并赋值
|
|
96
|
+
let checkType = rule.type || "string";
|
|
97
|
+
val = DataFormat_1.default.formatValue(val, checkType);
|
|
98
|
+
//调用check的方法
|
|
99
|
+
if (!ValidationUtil_1.default.checkType(val, checkType)) {
|
|
100
|
+
throwErrMsg(rule, prop, rule.typeMessage);
|
|
101
|
+
}
|
|
102
|
+
//判断长度
|
|
103
|
+
if (rule?.minSize) {
|
|
104
|
+
if (!ValidationUtil_1.default.isNotMinSize(val, rule.minSize)) {
|
|
105
|
+
throwErrMsg(rule, prop, rule.sizeMessgae ? rule.sizeMessgae : `${prop} should be greater than ${rule.minSize} `);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (rule?.maxSize) {
|
|
109
|
+
if (!ValidationUtil_1.default.isNotMaxSize(val, rule.maxSize)) {
|
|
110
|
+
throwErrMsg(rule, prop, rule.sizeMessgae ? rule.sizeMessgae : `${prop} should be less than ${rule.maxSize} `);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//自定义方法校验
|
|
114
|
+
if (Array.isArray(rule.filters)) {
|
|
115
|
+
for (let fnItem of rule.filters) {
|
|
116
|
+
let fn = fnItem.fn;
|
|
117
|
+
let flag = Reflect.apply(fn, this, [val]);
|
|
118
|
+
if (!flag) {
|
|
119
|
+
//抛出错误提示
|
|
120
|
+
throwErrMsg(rule, prop, fnItem.message || rule.message);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//进行赋值
|
|
125
|
+
currObj = setFormValue(currObj, prop, val);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
args[paramIndex] = currObj;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return Reflect.apply(next, this, args);
|
|
132
|
+
};
|
|
133
|
+
}
|