@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,56 @@
|
|
|
1
|
+
import FileUtil from "./FileUtil";
|
|
2
|
+
|
|
3
|
+
const BasicTypes = ["boolean", "number", "string"];
|
|
4
|
+
|
|
5
|
+
export default class TypeUtil {
|
|
6
|
+
static isFunction(f: any): boolean {
|
|
7
|
+
let typeName = typeof f;
|
|
8
|
+
return typeName == "function";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static isClass(f: any): boolean {
|
|
12
|
+
if (f.prototype === undefined) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!f.prototype.constructor) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return TypeUtil.isFunction(f);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static isString(str: any): boolean {
|
|
24
|
+
let typeName = typeof str;
|
|
25
|
+
return typeName == "string";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static isObject(f: any): boolean {
|
|
29
|
+
let typeName = typeof f;
|
|
30
|
+
return typeName == "object";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//忽略.d.ts文件
|
|
34
|
+
static isTSORJS(fp: string): boolean {
|
|
35
|
+
let suffix = FileUtil.getSuffix(fp);
|
|
36
|
+
return ["ts", "js"].includes(suffix) && !fp.endsWith(".d.ts");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static isPromise(f: Function) {
|
|
40
|
+
return f.constructor.name === "AsyncFunction";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static isArray(value: any) {
|
|
44
|
+
return Array.isArray(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static isDate(value: any) {
|
|
48
|
+
return value instanceof Date;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//是否为基本类型
|
|
52
|
+
static isBasic(name: string): boolean {
|
|
53
|
+
let fname = name.toLowerCase();
|
|
54
|
+
return BasicTypes.includes(fname);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { DataTypes } from "../constant/DataTypes";
|
|
2
|
+
import TypeUtil from "./TypeUtil";
|
|
3
|
+
//类型校验器
|
|
4
|
+
export default class ValidationUtil {
|
|
5
|
+
//是否为空
|
|
6
|
+
static isNotNull(param: any): boolean {
|
|
7
|
+
if (param != undefined && param != null) {
|
|
8
|
+
if (TypeUtil.isString(param)) {
|
|
9
|
+
return param.length > 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (TypeUtil.isObject(param)) {
|
|
13
|
+
if (TypeUtil.isDate(param)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return Reflect.ownKeys(param).length > 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return true;
|
|
20
|
+
} else {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static isNull(param: any): boolean {
|
|
26
|
+
return !ValidationUtil.isNotNull(param);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static isNumber(param: any): boolean {
|
|
30
|
+
return typeof param === "number" && !isNaN(param);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static isString(param: any): boolean {
|
|
34
|
+
return typeof param === "string";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static isBoolean(param: any): boolean {
|
|
38
|
+
return typeof param === "boolean";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static isDate(param: any): boolean {
|
|
42
|
+
return param instanceof Date;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static isObject(param: any): boolean {
|
|
46
|
+
return typeof param == "object";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// poaram >= value
|
|
50
|
+
static isNotMinSize(param: any, value: number): boolean {
|
|
51
|
+
if (ValidationUtil.isString(param)) {
|
|
52
|
+
return param.length >= value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (ValidationUtil.isNumber(param)) {
|
|
56
|
+
return param >= value;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (ValidationUtil.isBoolean(param)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let v = ValidationUtil.isNotNull(param) ? param.toString() : "";
|
|
64
|
+
return v.length >= value;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static isNotMaxSize(param: any, value: number): boolean {
|
|
68
|
+
return !ValidationUtil.isNotMinSize(param, value + 1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static isArray(param: any, type: string): boolean {
|
|
72
|
+
if (!Array.isArray(param)) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//修正校验数组的错误
|
|
77
|
+
if (type.startsWith("array")) {
|
|
78
|
+
type = type.replace(/array/, "");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let checkFun: any = this.getCheckFun(type);
|
|
82
|
+
if (checkFun) {
|
|
83
|
+
return param.every((item) => {
|
|
84
|
+
return Reflect.apply(checkFun, ValidationUtil, [item]);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static getCheckFun(type: DataTypes | string): Function | null {
|
|
92
|
+
//判定类型
|
|
93
|
+
if (type.startsWith("array")) {
|
|
94
|
+
return ValidationUtil.isArray;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let formatFun = null;
|
|
98
|
+
switch (type) {
|
|
99
|
+
case "string": {
|
|
100
|
+
formatFun = ValidationUtil.isString;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case "boolean": {
|
|
104
|
+
formatFun = ValidationUtil.isBoolean;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case "object": {
|
|
108
|
+
formatFun = ValidationUtil.isObject;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case "int":
|
|
112
|
+
case "float":
|
|
113
|
+
case "number": {
|
|
114
|
+
formatFun = ValidationUtil.isNumber;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case "date": {
|
|
118
|
+
formatFun = ValidationUtil.isDate;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
default: {
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return formatFun;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static checkType(param: any, type: string): boolean {
|
|
130
|
+
let formatFun = ValidationUtil.getCheckFun(type);
|
|
131
|
+
|
|
132
|
+
if (!formatFun) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return Reflect.apply(formatFun, ValidationUtil, [param, type]);
|
|
137
|
+
}
|
|
138
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ClassLoader from "./utils/classLoader";
|
|
2
|
+
import ClassUtils from "./utils/ClassUtils";
|
|
3
|
+
import CryptoUtil from "./utils/CryptoUtil";
|
|
4
|
+
import DataFormat from "./utils/DataFormat";
|
|
5
|
+
import DateUtil from "./utils/DateUtil";
|
|
6
|
+
import FileUtil from "./utils/FileUtil";
|
|
7
|
+
import FormatStr from "./utils/FormatStr";
|
|
8
|
+
import MixTool from "./utils/Mix";
|
|
9
|
+
import TypeUtil from "./utils/TypeUtil";
|
|
10
|
+
import ValidationUtil from "./utils/ValidationUtil";
|
|
11
|
+
|
|
12
|
+
//实用工具集合类
|
|
13
|
+
export { DateUtil, DataFormat, CryptoUtil, FileUtil, TypeUtil, ValidationUtil, FormatStr, ClassUtils, ClassLoader, MixTool };
|