@fastcar/core 0.2.60 → 0.2.62
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/package.json +2 -4
- package/src/model/WinstonLogger.ts +4 -3
- package/src/utils/ClassLoader.ts +1 -1
- package/src/utils/ValidationUtil.ts +8 -1
- package/target/FastCarApplication.js +692 -692
- package/target/annotation/Application.js +45 -45
- package/target/annotation/ExceptionMonitor.js +16 -16
- package/target/annotation/bind/AddRequireModule.js +21 -21
- package/target/annotation/bind/AliasInjection.js +23 -23
- package/target/annotation/bind/Autowired.js +13 -13
- package/target/annotation/bind/CallDependency.js +23 -23
- 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 +18 -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 +17 -17
- package/target/annotation/stereotype/Repository.js +9 -9
- package/target/annotation/stereotype/Service.js +9 -9
- 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 +100 -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 +108 -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 +31 -31
- package/target/constant/LifeCycleModule.js +9 -9
- package/target/db.js +49 -48
- 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 +98 -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 +96 -95
- package/target/src/FastCarApplication.js +704 -0
- package/target/src/annotation/Application.js +45 -0
- package/target/src/annotation/ExceptionMonitor.js +16 -0
- package/target/src/annotation/bind/AddRequireModule.js +21 -0
- package/target/src/annotation/bind/AliasInjection.js +23 -0
- package/target/src/annotation/bind/Autowired.js +13 -0
- package/target/src/annotation/bind/CallDependency.js +23 -0
- package/target/src/annotation/data/DBType.js +11 -0
- package/target/src/annotation/data/DS.js +54 -0
- package/target/src/annotation/data/DSIndex.js +9 -0
- package/target/src/annotation/data/Entity.js +10 -0
- package/target/src/annotation/data/Field.js +18 -0
- package/target/src/annotation/data/PrimaryKey.js +9 -0
- package/target/src/annotation/data/SqlSession.js +9 -0
- package/target/src/annotation/data/Table.js +35 -0
- package/target/src/annotation/data/Transactional.js +52 -0
- package/target/src/annotation/env/ApplicationSetting.js +25 -0
- package/target/src/annotation/env/BaseFilePath.js +14 -0
- package/target/src/annotation/env/BaseName.js +9 -0
- package/target/src/annotation/env/BasePath.js +14 -0
- package/target/src/annotation/env/ENV.js +10 -0
- package/target/src/annotation/env/ResourcePath.js +9 -0
- package/target/src/annotation/lifeCycle/AddLifeCycleItem.js +18 -0
- package/target/src/annotation/lifeCycle/ApplicationDestory.js +15 -0
- package/target/src/annotation/lifeCycle/ApplicationInit.js +15 -0
- package/target/src/annotation/lifeCycle/ApplicationRunner.js +7 -0
- package/target/src/annotation/lifeCycle/ApplicationStart.js +24 -0
- package/target/src/annotation/lifeCycle/ApplicationStop.js +20 -0
- package/target/src/annotation/property/Deprecate.js +19 -0
- package/target/src/annotation/property/NotImplemented.js +8 -0
- package/target/src/annotation/property/Override.js +7 -0
- package/target/src/annotation/property/Readonly.js +16 -0
- package/target/src/annotation/scan/ComponentInjection.js +21 -0
- package/target/src/annotation/scan/ComponentScan.js +9 -0
- package/target/src/annotation/scan/ComponentScanExclusion.js +25 -0
- package/target/src/annotation/scan/ComponentScanMust.js +25 -0
- package/target/src/annotation/scan/Hotter.js +8 -0
- package/target/src/annotation/stereotype/BeanName.js +11 -0
- package/target/src/annotation/stereotype/Component.js +8 -0
- package/target/src/annotation/stereotype/Configure.js +14 -0
- package/target/src/annotation/stereotype/Controller.js +9 -0
- package/target/src/annotation/stereotype/Injection.js +12 -0
- package/target/src/annotation/stereotype/Log.js +22 -0
- package/target/src/annotation/stereotype/Repository.js +9 -0
- package/target/src/annotation/stereotype/Service.js +9 -0
- package/target/src/annotation/valid/AddChildValid.js +56 -0
- package/target/src/annotation/valid/CustomType.js +11 -0
- package/target/src/annotation/valid/DefaultVal.js +10 -0
- package/target/src/annotation/valid/NotNull.js +8 -0
- package/target/src/annotation/valid/Rule.js +100 -0
- package/target/src/annotation/valid/Size.js +10 -0
- package/target/src/annotation/valid/Type.js +10 -0
- package/target/src/annotation/valid/ValidCustom.js +17 -0
- package/target/src/annotation/valid/ValidForm.js +133 -0
- package/target/src/annotation.js +108 -0
- package/target/src/config/ApplicationConfig.js +2 -0
- package/target/src/config/SysConfig.js +19 -0
- package/target/src/constant/AppStatusEnum.js +9 -0
- package/target/src/constant/BootPriority.js +11 -0
- package/target/src/constant/CommonConstant.js +18 -0
- package/target/src/constant/ComponentKind.js +11 -0
- package/target/src/constant/DataTypes.js +19 -0
- package/target/src/constant/FastCarMetaData.js +31 -0
- package/target/src/constant/LifeCycleModule.js +9 -0
- package/target/src/db.js +49 -0
- package/target/src/index.js +21 -0
- package/target/src/interface/ApplicationHook.js +2 -0
- package/target/src/interface/ApplicationInterface.js +2 -0
- package/target/src/interface/ApplicationRunnerService.js +2 -0
- package/target/src/interface/DataSourceManager.js +2 -0
- package/target/src/interface/Logger.js +5 -0
- package/target/src/model/BaseMapper.js +103 -0
- package/target/src/model/DataMap.js +87 -0
- package/target/src/model/FormRuleModel.js +2 -0
- package/target/src/model/ValidError.js +5 -0
- package/target/src/model/WinstonLogger.js +97 -0
- package/target/src/type/ComponentDesc.js +2 -0
- package/target/src/type/DesignMeta.js +15 -0
- package/target/src/type/FileHotterDesc.js +2 -0
- package/target/src/type/MapperType.js +2 -0
- package/target/src/type/ProcessType.js +2 -0
- package/target/src/type/SqlError.js +5 -0
- package/target/src/type/WinstonLoggerType.js +9 -0
- package/target/src/utils/ClassLoader.js +65 -0
- package/target/src/utils/ClassUtils.js +35 -0
- package/target/src/utils/CryptoUtil.js +86 -0
- package/target/src/utils/DataFormat.js +88 -0
- package/target/src/utils/DateUtil.js +71 -0
- package/target/src/utils/FileUtil.js +153 -0
- package/target/src/utils/FormatStr.js +14 -0
- package/target/src/utils/IPUtils.js +34 -0
- package/target/src/utils/Id.js +9 -0
- package/target/src/utils/Mix.js +62 -0
- package/target/src/utils/ReflectUtil.js +22 -0
- package/target/src/utils/TypeUtil.js +53 -0
- package/target/src/utils/ValidationUtil.js +118 -0
- package/target/src/utils.js +25 -0
- package/target/test/example/simple/app-test.js +57 -0
- package/target/test/example/simple/app.js +116 -0
- package/target/test/example/simple/component/StartRunner.js +19 -0
- package/target/test/example/simple/component/StopRunner.js +23 -0
- package/target/test/example/simple/config/EnvConfig.js +16 -0
- package/target/test/example/simple/config/HelloConfig.js +16 -0
- package/target/test/example/simple/config/HotConfig.js +18 -0
- package/target/test/example/simple/controller/AliasController.js +17 -0
- package/target/test/example/simple/controller/HelloController.js +55 -0
- package/target/test/example/simple/controller/NotFoundController.js +36 -0
- package/target/test/example/simple/noclude/excludeApp.js +17 -0
- package/target/test/example/simple/service/CallService.js +24 -0
- package/target/test/example/simple/service/HelloService.js +18 -0
- package/target/test/example/simple/service/LogService.js +32 -0
- package/target/test/multi/app.js +29 -0
- package/target/test/multi/service/aService.js +33 -0
- package/target/test/multi/service/bService.js +35 -0
- package/target/test/multi/service/cService.js +40 -0
- package/target/test/unit/dataMap-test.js +35 -0
- package/target/test/unit/decorators-test.js +59 -0
- package/target/test/unit/ds-test.js +58 -0
- package/target/test/unit/reflectMetadata-test.js +27 -0
- package/target/test/unit/valid-test.js +99 -0
- package/target/test/unit/winston-test.js +15 -0
- package/target/type/ComponentDesc.js +2 -2
- package/target/type/DesignMeta.js +15 -15
- package/target/type/FileHotterDesc.js +2 -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 +65 -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 +9 -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 -118
- package/target/utils.js +25 -25
- package/test/unit/decorators-test.ts +3 -3
- package/test/unit/valid-test.ts +54 -49
- package/test/unit/logs/sys.log +0 -24
package/target/utils/TypeUtil.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const FileUtil_1 = require("./FileUtil");
|
|
4
|
-
const BasicTypes = ["boolean", "number", "string"];
|
|
5
|
-
class TypeUtil {
|
|
6
|
-
static isFunction(f) {
|
|
7
|
-
let typeName = typeof f;
|
|
8
|
-
return typeName == "function";
|
|
9
|
-
}
|
|
10
|
-
static isClass(f) {
|
|
11
|
-
if (f.prototype === undefined) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
if (!f.prototype.constructor) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
return TypeUtil.isFunction(f);
|
|
18
|
-
}
|
|
19
|
-
static isString(str) {
|
|
20
|
-
let typeName = typeof str;
|
|
21
|
-
return typeName == "string";
|
|
22
|
-
}
|
|
23
|
-
static isObject(f) {
|
|
24
|
-
let typeName = typeof f;
|
|
25
|
-
return typeName == "object";
|
|
26
|
-
}
|
|
27
|
-
//忽略.d.ts文件
|
|
28
|
-
static isTSORJS(fp) {
|
|
29
|
-
let suffix = FileUtil_1.default.getSuffix(fp);
|
|
30
|
-
return ["ts", "js"].includes(suffix) && !fp.endsWith(".d.ts");
|
|
31
|
-
}
|
|
32
|
-
static isPromise(f) {
|
|
33
|
-
return f.constructor.name === "AsyncFunction";
|
|
34
|
-
}
|
|
35
|
-
static isArray(value) {
|
|
36
|
-
return Array.isArray(value);
|
|
37
|
-
}
|
|
38
|
-
static isDate(value) {
|
|
39
|
-
return value instanceof Date;
|
|
40
|
-
}
|
|
41
|
-
//是否为基本类型
|
|
42
|
-
static isBasic(name) {
|
|
43
|
-
let fname = name.toLowerCase();
|
|
44
|
-
return BasicTypes.includes(fname);
|
|
45
|
-
}
|
|
46
|
-
static isMap(value) {
|
|
47
|
-
return value instanceof Map;
|
|
48
|
-
}
|
|
49
|
-
static isSet(value) {
|
|
50
|
-
return value instanceof Set;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.default = TypeUtil;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const FileUtil_1 = require("./FileUtil");
|
|
4
|
+
const BasicTypes = ["boolean", "number", "string"];
|
|
5
|
+
class TypeUtil {
|
|
6
|
+
static isFunction(f) {
|
|
7
|
+
let typeName = typeof f;
|
|
8
|
+
return typeName == "function";
|
|
9
|
+
}
|
|
10
|
+
static isClass(f) {
|
|
11
|
+
if (f.prototype === undefined) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (!f.prototype.constructor) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return TypeUtil.isFunction(f);
|
|
18
|
+
}
|
|
19
|
+
static isString(str) {
|
|
20
|
+
let typeName = typeof str;
|
|
21
|
+
return typeName == "string";
|
|
22
|
+
}
|
|
23
|
+
static isObject(f) {
|
|
24
|
+
let typeName = typeof f;
|
|
25
|
+
return typeName == "object";
|
|
26
|
+
}
|
|
27
|
+
//忽略.d.ts文件
|
|
28
|
+
static isTSORJS(fp) {
|
|
29
|
+
let suffix = FileUtil_1.default.getSuffix(fp);
|
|
30
|
+
return ["ts", "js"].includes(suffix) && !fp.endsWith(".d.ts");
|
|
31
|
+
}
|
|
32
|
+
static isPromise(f) {
|
|
33
|
+
return f.constructor.name === "AsyncFunction";
|
|
34
|
+
}
|
|
35
|
+
static isArray(value) {
|
|
36
|
+
return Array.isArray(value);
|
|
37
|
+
}
|
|
38
|
+
static isDate(value) {
|
|
39
|
+
return value instanceof Date;
|
|
40
|
+
}
|
|
41
|
+
//是否为基本类型
|
|
42
|
+
static isBasic(name) {
|
|
43
|
+
let fname = name.toLowerCase();
|
|
44
|
+
return BasicTypes.includes(fname);
|
|
45
|
+
}
|
|
46
|
+
static isMap(value) {
|
|
47
|
+
return value instanceof Map;
|
|
48
|
+
}
|
|
49
|
+
static isSet(value) {
|
|
50
|
+
return value instanceof Set;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.default = TypeUtil;
|
|
@@ -1,118 +1,123 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const TypeUtil_1 = require("./TypeUtil");
|
|
4
|
-
//类型校验器
|
|
5
|
-
class ValidationUtil {
|
|
6
|
-
//是否为空
|
|
7
|
-
static isNotNull(param) {
|
|
8
|
-
if (param != undefined && param != null) {
|
|
9
|
-
if (TypeUtil_1.default.isString(param)) {
|
|
10
|
-
return param.length > 0;
|
|
11
|
-
}
|
|
12
|
-
if (TypeUtil_1.default.isObject(param)) {
|
|
13
|
-
if (TypeUtil_1.default.isDate(param) || TypeUtil_1.default.isMap(param) || TypeUtil_1.default.isSet(param)) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
return Reflect.ownKeys(param).length > 0;
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
static isNull(param) {
|
|
25
|
-
return !ValidationUtil.isNotNull(param);
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
case "
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
case "
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const TypeUtil_1 = require("./TypeUtil");
|
|
4
|
+
//类型校验器
|
|
5
|
+
class ValidationUtil {
|
|
6
|
+
//是否为空
|
|
7
|
+
static isNotNull(param) {
|
|
8
|
+
if (param != undefined && param != null) {
|
|
9
|
+
if (TypeUtil_1.default.isString(param)) {
|
|
10
|
+
return param.length > 0;
|
|
11
|
+
}
|
|
12
|
+
if (TypeUtil_1.default.isObject(param)) {
|
|
13
|
+
if (TypeUtil_1.default.isDate(param) || TypeUtil_1.default.isMap(param) || TypeUtil_1.default.isSet(param)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return Reflect.ownKeys(param).length > 0;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
static isNull(param) {
|
|
25
|
+
return !ValidationUtil.isNotNull(param);
|
|
26
|
+
}
|
|
27
|
+
//修改数字的判断方法
|
|
28
|
+
static isNumber(param) {
|
|
29
|
+
return !isNaN(param);
|
|
30
|
+
}
|
|
31
|
+
static isString(param) {
|
|
32
|
+
return typeof param === "string";
|
|
33
|
+
}
|
|
34
|
+
static isBoolean(param) {
|
|
35
|
+
return typeof param === "boolean";
|
|
36
|
+
}
|
|
37
|
+
static isDate(param) {
|
|
38
|
+
return param instanceof Date;
|
|
39
|
+
}
|
|
40
|
+
static isObject(param) {
|
|
41
|
+
return typeof param == "object";
|
|
42
|
+
}
|
|
43
|
+
// poaram >= value
|
|
44
|
+
static isNotMinSize(param, value) {
|
|
45
|
+
if (ValidationUtil.isString(param)) {
|
|
46
|
+
return param.length >= value;
|
|
47
|
+
}
|
|
48
|
+
if (ValidationUtil.isNumber(param)) {
|
|
49
|
+
return param >= value;
|
|
50
|
+
}
|
|
51
|
+
if (ValidationUtil.isBoolean(param)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
//修正数组的判断
|
|
55
|
+
if (Array.isArray(param)) {
|
|
56
|
+
return param.length >= value;
|
|
57
|
+
}
|
|
58
|
+
let v = ValidationUtil.isNotNull(param) ? param.toString() : "";
|
|
59
|
+
return v.length >= value;
|
|
60
|
+
}
|
|
61
|
+
static isNotMaxSize(param, value) {
|
|
62
|
+
return !ValidationUtil.isNotMinSize(param, value + 1);
|
|
63
|
+
}
|
|
64
|
+
static isArray(param, type) {
|
|
65
|
+
if (!Array.isArray(param)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
//修正校验数组的错误
|
|
69
|
+
if (type.startsWith("array")) {
|
|
70
|
+
type = type.replace(/array/, "");
|
|
71
|
+
}
|
|
72
|
+
let checkFun = this.getCheckFun(type);
|
|
73
|
+
if (checkFun) {
|
|
74
|
+
return param.every((item) => {
|
|
75
|
+
return Reflect.apply(checkFun, ValidationUtil, [item]);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
static getCheckFun(type) {
|
|
81
|
+
//判定类型
|
|
82
|
+
if (type.startsWith("array")) {
|
|
83
|
+
return ValidationUtil.isArray;
|
|
84
|
+
}
|
|
85
|
+
let formatFun = null;
|
|
86
|
+
switch (type) {
|
|
87
|
+
case "string": {
|
|
88
|
+
formatFun = ValidationUtil.isString;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case "boolean": {
|
|
92
|
+
formatFun = ValidationUtil.isBoolean;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case "object": {
|
|
96
|
+
formatFun = ValidationUtil.isObject;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case "int":
|
|
100
|
+
case "float":
|
|
101
|
+
case "number": {
|
|
102
|
+
formatFun = ValidationUtil.isNumber;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case "date": {
|
|
106
|
+
formatFun = ValidationUtil.isDate;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
default: {
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return formatFun;
|
|
114
|
+
}
|
|
115
|
+
static checkType(param, type) {
|
|
116
|
+
let formatFun = ValidationUtil.getCheckFun(type);
|
|
117
|
+
if (!formatFun) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return Reflect.apply(formatFun, ValidationUtil, [param, type]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.default = ValidationUtil;
|
package/target/utils.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IPUtils = exports.MixTool = exports.ClassLoader = exports.ClassUtils = exports.FormatStr = exports.ValidationUtil = exports.TypeUtil = exports.FileUtil = exports.CryptoUtil = exports.DataFormat = exports.DateUtil = void 0;
|
|
4
|
-
const ClassLoader_1 = require("./utils/ClassLoader");
|
|
5
|
-
exports.ClassLoader = ClassLoader_1.default;
|
|
6
|
-
const ClassUtils_1 = require("./utils/ClassUtils");
|
|
7
|
-
exports.ClassUtils = ClassUtils_1.default;
|
|
8
|
-
const CryptoUtil_1 = require("./utils/CryptoUtil");
|
|
9
|
-
exports.CryptoUtil = CryptoUtil_1.default;
|
|
10
|
-
const DataFormat_1 = require("./utils/DataFormat");
|
|
11
|
-
exports.DataFormat = DataFormat_1.default;
|
|
12
|
-
const DateUtil_1 = require("./utils/DateUtil");
|
|
13
|
-
exports.DateUtil = DateUtil_1.default;
|
|
14
|
-
const FileUtil_1 = require("./utils/FileUtil");
|
|
15
|
-
exports.FileUtil = FileUtil_1.default;
|
|
16
|
-
const FormatStr_1 = require("./utils/FormatStr");
|
|
17
|
-
exports.FormatStr = FormatStr_1.default;
|
|
18
|
-
const Mix_1 = require("./utils/Mix");
|
|
19
|
-
exports.MixTool = Mix_1.default;
|
|
20
|
-
const TypeUtil_1 = require("./utils/TypeUtil");
|
|
21
|
-
exports.TypeUtil = TypeUtil_1.default;
|
|
22
|
-
const ValidationUtil_1 = require("./utils/ValidationUtil");
|
|
23
|
-
exports.ValidationUtil = ValidationUtil_1.default;
|
|
24
|
-
const IPUtils_1 = require("./utils/IPUtils");
|
|
25
|
-
exports.IPUtils = IPUtils_1.default;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IPUtils = exports.MixTool = exports.ClassLoader = exports.ClassUtils = exports.FormatStr = exports.ValidationUtil = exports.TypeUtil = exports.FileUtil = exports.CryptoUtil = exports.DataFormat = exports.DateUtil = void 0;
|
|
4
|
+
const ClassLoader_1 = require("./utils/ClassLoader");
|
|
5
|
+
exports.ClassLoader = ClassLoader_1.default;
|
|
6
|
+
const ClassUtils_1 = require("./utils/ClassUtils");
|
|
7
|
+
exports.ClassUtils = ClassUtils_1.default;
|
|
8
|
+
const CryptoUtil_1 = require("./utils/CryptoUtil");
|
|
9
|
+
exports.CryptoUtil = CryptoUtil_1.default;
|
|
10
|
+
const DataFormat_1 = require("./utils/DataFormat");
|
|
11
|
+
exports.DataFormat = DataFormat_1.default;
|
|
12
|
+
const DateUtil_1 = require("./utils/DateUtil");
|
|
13
|
+
exports.DateUtil = DateUtil_1.default;
|
|
14
|
+
const FileUtil_1 = require("./utils/FileUtil");
|
|
15
|
+
exports.FileUtil = FileUtil_1.default;
|
|
16
|
+
const FormatStr_1 = require("./utils/FormatStr");
|
|
17
|
+
exports.FormatStr = FormatStr_1.default;
|
|
18
|
+
const Mix_1 = require("./utils/Mix");
|
|
19
|
+
exports.MixTool = Mix_1.default;
|
|
20
|
+
const TypeUtil_1 = require("./utils/TypeUtil");
|
|
21
|
+
exports.TypeUtil = TypeUtil_1.default;
|
|
22
|
+
const ValidationUtil_1 = require("./utils/ValidationUtil");
|
|
23
|
+
exports.ValidationUtil = ValidationUtil_1.default;
|
|
24
|
+
const IPUtils_1 = require("./utils/IPUtils");
|
|
25
|
+
exports.IPUtils = IPUtils_1.default;
|
|
@@ -5,7 +5,7 @@ describe("装饰器测试", () => {
|
|
|
5
5
|
it("只读装饰器测试", () => {
|
|
6
6
|
class TestModel {
|
|
7
7
|
@Readonly
|
|
8
|
-
info
|
|
8
|
+
info!: string;
|
|
9
9
|
|
|
10
10
|
@Readonly
|
|
11
11
|
setInfo(s: string) {
|
|
@@ -25,13 +25,13 @@ describe("装饰器测试", () => {
|
|
|
25
25
|
class TestModel {
|
|
26
26
|
@Deprecate("hello is Deprecate")
|
|
27
27
|
async hello() {
|
|
28
|
-
return new Promise(resolve => {
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
29
|
resolve("hello is Deprecate");
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
new TestModel().hello().then(res => {
|
|
34
|
+
new TestModel().hello().then((res) => {
|
|
35
35
|
console.log(res);
|
|
36
36
|
});
|
|
37
37
|
});
|
package/test/unit/valid-test.ts
CHANGED
|
@@ -7,66 +7,71 @@ import { ValidationUtil } from "../../src/utils";
|
|
|
7
7
|
|
|
8
8
|
describe("表单校验测试", () => {
|
|
9
9
|
it("表单单个测试", () => {
|
|
10
|
-
class A {
|
|
11
|
-
//简单类型
|
|
12
|
-
@ValidForm
|
|
13
|
-
test(@Rule() @NotNull a?: string) {
|
|
14
|
-
console.log(a);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
let instance = new A();
|
|
18
|
-
instance.test("");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("表单复合型测试", () => {
|
|
22
|
-
type B = {
|
|
23
|
-
c: string;
|
|
24
|
-
d?: number;
|
|
25
|
-
};
|
|
26
10
|
class A {
|
|
27
11
|
//简单类型
|
|
28
12
|
@ValidForm
|
|
29
13
|
test(
|
|
30
14
|
@Rule({
|
|
31
|
-
a: { required: true },
|
|
32
|
-
})
|
|
33
|
-
a: string,
|
|
34
|
-
@Rule({
|
|
35
|
-
c: { required: true },
|
|
36
|
-
d: { type: "number", minSize: 1, maxSize: 10 },
|
|
15
|
+
a: { required: true, type: "int" },
|
|
37
16
|
})
|
|
38
|
-
|
|
17
|
+
{ a }: { a: any }
|
|
39
18
|
) {
|
|
40
|
-
console.log(a
|
|
19
|
+
console.log(a);
|
|
41
20
|
}
|
|
42
21
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
instance.test("a", { c: "c", d: 13 }); //校验失败
|
|
22
|
+
console.log("");
|
|
23
|
+
new A().test({ a: [] });
|
|
46
24
|
});
|
|
47
25
|
|
|
48
|
-
it("
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
26
|
+
// it("表单复合型测试", () => {
|
|
27
|
+
// type B = {
|
|
28
|
+
// c: string;
|
|
29
|
+
// d?: number;
|
|
30
|
+
// };
|
|
31
|
+
// class A {
|
|
32
|
+
// //简单类型
|
|
33
|
+
// @ValidForm
|
|
34
|
+
// test(
|
|
35
|
+
// @Rule({
|
|
36
|
+
// a: { required: true },
|
|
37
|
+
// })
|
|
38
|
+
// a: string,
|
|
39
|
+
// @Rule({
|
|
40
|
+
// c: { required: true },
|
|
41
|
+
// d: { type: "number", minSize: 1, maxSize: 10 },
|
|
42
|
+
// })
|
|
43
|
+
// b: B
|
|
44
|
+
// ) {
|
|
45
|
+
// console.log(a, b);
|
|
46
|
+
// }
|
|
47
|
+
// }
|
|
48
|
+
// let instance = new A();
|
|
49
|
+
// instance.test("a", { c: "c", d: 6 }); // 校验通过
|
|
50
|
+
// instance.test("a", { c: "c", d: 13 }); //校验失败
|
|
51
|
+
// });
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
//简单类型
|
|
58
|
-
@ValidForm
|
|
59
|
-
test(a: string, @Rule() @NotNull b: B) {
|
|
60
|
-
console.log(a, b);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
let instance = new A();
|
|
64
|
-
instance.test("a", { c: "c", d: 13 }); //校验失败
|
|
65
|
-
});
|
|
53
|
+
// it("表单类测试", () => {
|
|
54
|
+
// class B {
|
|
55
|
+
// @NotNull
|
|
56
|
+
// c!: string;
|
|
66
57
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
// @Size({ minSize: 1, maxSize: 10 })
|
|
59
|
+
// d?: number;
|
|
60
|
+
// }
|
|
61
|
+
// class A {
|
|
62
|
+
// //简单类型
|
|
63
|
+
// @ValidForm
|
|
64
|
+
// test(a: string, @Rule() @NotNull b: B) {
|
|
65
|
+
// console.log(a, b);
|
|
66
|
+
// }
|
|
67
|
+
// }
|
|
68
|
+
// let instance = new A();
|
|
69
|
+
// instance.test("a", { c: "c", d: 13 }); //校验失败
|
|
70
|
+
// });
|
|
71
|
+
|
|
72
|
+
// it("测试map是否为空", () => {
|
|
73
|
+
// let d = new Map();
|
|
74
|
+
// d.set("hello", "world");
|
|
75
|
+
// console.log(ValidationUtil.isNotNull(d) == true);
|
|
76
|
+
// });
|
|
72
77
|
});
|
package/test/unit/logs/sys.log
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{"timestamp":"2022-09-09 10:58:51.75","level":"INFO","label":"sys","message":"Start scanning component"}
|
|
2
|
-
{"timestamp":"2022-09-09 10:58:51.78","level":"INFO","label":"sys","message":"Complete component scan"}
|
|
3
|
-
{"timestamp":"2022-09-09 10:58:51.78","level":"INFO","label":"sys","message":"Call application initialization method"}
|
|
4
|
-
{"timestamp":"2022-09-09 10:58:51.80","level":"INFO","label":"sys","message":"start server app is run"}
|
|
5
|
-
{"timestamp":"2022-09-09 10:58:51.81","level":"INFO","label":"sys","message":"version 1.0.0"}
|
|
6
|
-
{"timestamp":"2022-09-09 10:58:51.84","level":"INFO","label":"sys","message":"exit reason","splat":"[\"beforeExit exit\"]"}
|
|
7
|
-
{"timestamp":"2022-09-09 11:11:48.302","level":"INFO","label":"sys","message":"Start scanning component"}
|
|
8
|
-
{"timestamp":"2022-09-09 11:11:48.305","level":"INFO","label":"sys","message":"Complete component scan"}
|
|
9
|
-
{"timestamp":"2022-09-09 11:11:48.306","level":"INFO","label":"sys","message":"Call application initialization method"}
|
|
10
|
-
{"timestamp":"2022-09-09 11:11:48.308","level":"INFO","label":"sys","message":"start server app is run"}
|
|
11
|
-
{"timestamp":"2022-09-09 11:11:48.309","level":"INFO","label":"sys","message":"version 1.0.0"}
|
|
12
|
-
{"timestamp":"2022-09-09 11:11:48.322","level":"INFO","label":"sys","message":"exit reason","splat":"[\"beforeExit exit\"]"}
|
|
13
|
-
{"timestamp":"2022-09-09 11:12:01.418","level":"INFO","label":"sys","message":"Start scanning component"}
|
|
14
|
-
{"timestamp":"2022-09-09 11:12:01.421","level":"INFO","label":"sys","message":"Complete component scan"}
|
|
15
|
-
{"timestamp":"2022-09-09 11:12:01.422","level":"INFO","label":"sys","message":"Call application initialization method"}
|
|
16
|
-
{"timestamp":"2022-09-09 11:12:01.424","level":"INFO","label":"sys","message":"start server app is run"}
|
|
17
|
-
{"timestamp":"2022-09-09 11:12:01.424","level":"INFO","label":"sys","message":"version 1.0.0"}
|
|
18
|
-
{"timestamp":"2022-09-09 11:12:01.427","level":"INFO","label":"sys","message":"exit reason","splat":"[\"beforeExit exit\"]"}
|
|
19
|
-
{"timestamp":"2022-09-09 11:17:03.161","level":"INFO","label":"sys","message":"Start scanning component"}
|
|
20
|
-
{"timestamp":"2022-09-09 11:17:03.164","level":"INFO","label":"sys","message":"Complete component scan"}
|
|
21
|
-
{"timestamp":"2022-09-09 11:17:03.905","level":"INFO","label":"sys","message":"Call application initialization method"}
|
|
22
|
-
{"timestamp":"2022-09-09 11:17:03.907","level":"INFO","label":"sys","message":"start server app is run"}
|
|
23
|
-
{"timestamp":"2022-09-09 11:17:03.908","level":"INFO","label":"sys","message":"version 1.0.0"}
|
|
24
|
-
{"timestamp":"2022-09-09 11:17:03.911","level":"INFO","label":"sys","message":"exit reason","splat":"[\"beforeExit exit\"]"}
|