@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,25 @@
|
|
|
1
|
+
//元数据加载模块
|
|
2
|
+
export enum FastCarMetaData {
|
|
3
|
+
paramTypes = "design:paramtypes", //传参类型
|
|
4
|
+
returnType = "design:returntype", //返回类型
|
|
5
|
+
designType = "design:type", //设计类型
|
|
6
|
+
InjectionMap = "InjectionMap", //应用服务需要加载的模块
|
|
7
|
+
IocModule = "IocModule", //每个中间件需要加载的模块
|
|
8
|
+
ComponentScan = "ComponentScan", //扫描路径
|
|
9
|
+
ComponentScanExclusion = "ComponentScanExclusion", //排序的扫描路径
|
|
10
|
+
RouterMap = "RouterMap", //路由集合模块
|
|
11
|
+
SpecifyMap = "SpecifyMap", //特定的组件集合
|
|
12
|
+
APP = "APP", //用于指定名称
|
|
13
|
+
DS = "dynamicDataSource",
|
|
14
|
+
DSIndex = "dynamicDataSourceIndex", //数据源索引位置
|
|
15
|
+
ValidFormRules = "validFormRules", //表单校验原始数据
|
|
16
|
+
ValidChildFormRules = "validChildFormRules", //原始
|
|
17
|
+
ValidSize = "valid:size", //校验长度
|
|
18
|
+
NotNull = "valid:notNull", //不为空
|
|
19
|
+
ValidCustom = "valid:custom", //自定义校验方式
|
|
20
|
+
Hotter = "hotter", //是否支持热更
|
|
21
|
+
InjectionUniqueKey = "injection_uniqueKey",
|
|
22
|
+
Alias = "alias", //别名
|
|
23
|
+
LoggerModule = "LoggerModule", //日志模块集合
|
|
24
|
+
HotterSysConfig = "hotterSysConfig", //支持热更系统配置
|
|
25
|
+
}
|
package/src/db.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import BaseMapper from "./model/BaseMapper";
|
|
2
|
+
import SqlError from "./type/SqlError";
|
|
3
|
+
|
|
4
|
+
export enum OperatorEnum {
|
|
5
|
+
eq = "=",
|
|
6
|
+
neq = "!=",
|
|
7
|
+
gt = ">",
|
|
8
|
+
gte = ">=",
|
|
9
|
+
lt = "<",
|
|
10
|
+
lte = "<=",
|
|
11
|
+
like = "LIKE",
|
|
12
|
+
in = "IN",
|
|
13
|
+
isNUll = "ISNULL",
|
|
14
|
+
isNotNull = "IS NOT NULL",
|
|
15
|
+
inc = "+", //累加
|
|
16
|
+
dec = "-", //累减
|
|
17
|
+
multiply = "*", //累乘
|
|
18
|
+
division = "/", //累除
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export enum JoinEnum {
|
|
22
|
+
and = "AND",
|
|
23
|
+
or = "OR",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export enum OrderEnum {
|
|
27
|
+
asc = "ASC",
|
|
28
|
+
desc = "DESC",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type SqlValue = number | string | number[] | string[] | null | Date;
|
|
32
|
+
|
|
33
|
+
//where表达式
|
|
34
|
+
type SqlExpression =
|
|
35
|
+
| {
|
|
36
|
+
[key: string]: { [key: string]: SqlValue };
|
|
37
|
+
}
|
|
38
|
+
| SqlValue;
|
|
39
|
+
|
|
40
|
+
export type SqlWhere = { [key: string]: SqlExpression | SqlWhere };
|
|
41
|
+
|
|
42
|
+
export type RowData = {
|
|
43
|
+
[key: string]: SqlValue | { operate: string; value: SqlValue };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type OrderType = { [key: string]: OrderEnum };
|
|
47
|
+
|
|
48
|
+
export type SqlDelete = {
|
|
49
|
+
where?: SqlWhere; //查询条件
|
|
50
|
+
limit?: number; //限制行数
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type SqlQuery = {
|
|
54
|
+
where?: SqlWhere; //查询条件
|
|
55
|
+
fields?: string[]; //查询出来的元素
|
|
56
|
+
groups?: string[]; //分组排序
|
|
57
|
+
orders?: OrderType; //排序
|
|
58
|
+
limit?: number; //限制行数
|
|
59
|
+
offest?: number; //偏移量
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type SqlUpdate = {
|
|
63
|
+
where?: SqlWhere; //查询条件
|
|
64
|
+
row: RowData;
|
|
65
|
+
limit?: number; //限制行数
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type RowType = {
|
|
69
|
+
sql: string;
|
|
70
|
+
args: any[];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export interface DBMapper<T> {
|
|
74
|
+
/***
|
|
75
|
+
* @version 1.0 更新或者添加记录多条记录(一般用于整条记录的更新)
|
|
76
|
+
*/
|
|
77
|
+
saveORUpdate(rows: T | T[], ds?: string, sessionId?: string): Promise<number | string>;
|
|
78
|
+
|
|
79
|
+
/***
|
|
80
|
+
* @version 1.0 插入单条记录返回主键
|
|
81
|
+
*/
|
|
82
|
+
saveOne(row: T, ds?: string, sessionId?: string): Promise<number | string>;
|
|
83
|
+
|
|
84
|
+
/***
|
|
85
|
+
* @version 1.0 批量插入记录
|
|
86
|
+
*/
|
|
87
|
+
saveList(rows: T[], ds?: string, sessionId?: string): Promise<boolean>;
|
|
88
|
+
|
|
89
|
+
/***
|
|
90
|
+
* @version 1.0 更新记录
|
|
91
|
+
*
|
|
92
|
+
*/
|
|
93
|
+
update({ row, where, limit }: SqlUpdate, ds?: string, sessionId?: string): Promise<boolean>;
|
|
94
|
+
|
|
95
|
+
/****
|
|
96
|
+
* @version 1.0 更新一条数据
|
|
97
|
+
*
|
|
98
|
+
*/
|
|
99
|
+
updateOne(sqlUpdate: SqlUpdate, ds?: string, sessionId?: string): Promise<boolean>;
|
|
100
|
+
|
|
101
|
+
/***
|
|
102
|
+
* @version 1.0 根据实体类的主键来更新数据
|
|
103
|
+
*
|
|
104
|
+
*/
|
|
105
|
+
updateByPrimaryKey(row: T, ds?: string, sessionId?: string): Promise<boolean>;
|
|
106
|
+
|
|
107
|
+
/***
|
|
108
|
+
* @version 1.0 根据条件进行查找
|
|
109
|
+
*/
|
|
110
|
+
select(conditions: SqlQuery, ds?: string, sessionId?: string): Promise<T[]>;
|
|
111
|
+
|
|
112
|
+
/***
|
|
113
|
+
* @version 1.0 查询单个对象
|
|
114
|
+
*
|
|
115
|
+
*/
|
|
116
|
+
selectOne(conditions?: SqlQuery, ds?: string, sessionId?: string): Promise<T | null>;
|
|
117
|
+
|
|
118
|
+
/***
|
|
119
|
+
* @version 1.0 通过主键查找对象
|
|
120
|
+
*
|
|
121
|
+
*/
|
|
122
|
+
selectByPrimaryKey(row: T, ds?: string, sessionId?: string): Promise<T | null>;
|
|
123
|
+
|
|
124
|
+
/***
|
|
125
|
+
* @version 1.0 判定是否存在
|
|
126
|
+
*
|
|
127
|
+
*/
|
|
128
|
+
exist(where: SqlWhere, ds?: string, sessionId?: string): Promise<boolean>;
|
|
129
|
+
|
|
130
|
+
/***
|
|
131
|
+
* @version 1.0 统计符合条件的记录
|
|
132
|
+
*/
|
|
133
|
+
count(where: SqlWhere, ds?: string, sessionId?: string): Promise<number>;
|
|
134
|
+
|
|
135
|
+
/***
|
|
136
|
+
* @version 1.0 按照条件删除记录
|
|
137
|
+
*/
|
|
138
|
+
delete(conditions: SqlDelete, ds?: string, sessionId?: string): Promise<boolean>;
|
|
139
|
+
|
|
140
|
+
/***
|
|
141
|
+
* @version 1.0 删除某条记录
|
|
142
|
+
*/
|
|
143
|
+
deleteOne(where: SqlWhere, ds?: string, sessionId?: string): Promise<boolean>;
|
|
144
|
+
|
|
145
|
+
/***
|
|
146
|
+
* @version 1.0 删除某条记录根据主键
|
|
147
|
+
*/
|
|
148
|
+
deleteByPrimaryKey(row: T, ds?: string, sessionId?: string): Promise<boolean>;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export { BaseMapper, SqlError };
|
|
152
|
+
|
|
153
|
+
export type MapperType = {
|
|
154
|
+
name: string; //量变名称
|
|
155
|
+
type: string; //类型
|
|
156
|
+
field: string; //数据库列名
|
|
157
|
+
dbType: string; //数据类型
|
|
158
|
+
primaryKey?: boolean; //是否为主键 默认为false
|
|
159
|
+
serialize?: Function; //序列化对象方法
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export enum DesignMeta {
|
|
163
|
+
table = "db:table", //表名
|
|
164
|
+
field = "db:field", //列名
|
|
165
|
+
fieldMap = "db:fieldMap", //注入列名集合
|
|
166
|
+
dbType = "db:dbType", //数据类型
|
|
167
|
+
primaryKey = "db:primaryKey", //主键类型
|
|
168
|
+
entity = "db:entity", //实例化的数据库类
|
|
169
|
+
mapping = "db:mapping", //映射描述
|
|
170
|
+
dbFields = "db:fields", //数据库名-ts名
|
|
171
|
+
sqlSession = "SqlSession", //sql会话
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface DataSourceManager {
|
|
175
|
+
createSession(): string;
|
|
176
|
+
|
|
177
|
+
destorySession(sessionId: string, status: boolean): void;
|
|
178
|
+
|
|
179
|
+
start(): void;
|
|
180
|
+
|
|
181
|
+
stop(): void;
|
|
182
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BootPriority } from "./constant/BootPriority";
|
|
2
|
+
import { CommonConstant } from "./constant/CommonConstant";
|
|
3
|
+
import { ComponentKind } from "./constant/ComponentKind";
|
|
4
|
+
import { FastCarMetaData } from "./constant/FastCarMetaData";
|
|
5
|
+
import { LifeCycleModule } from "./constant/LifeCycleModule";
|
|
6
|
+
import FastCarApplication from "./FastCarApplication";
|
|
7
|
+
import Logger from "./interface/Logger";
|
|
8
|
+
import DataMap from "./model/DataMap";
|
|
9
|
+
import ValidError from "./model/ValidError";
|
|
10
|
+
|
|
11
|
+
export { LifeCycleModule, ComponentKind, BootPriority, FastCarApplication, FastCarMetaData, ValidError, DataMap, Logger, CommonConstant };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/***
|
|
2
|
+
* @version 1.0 数据源管理器
|
|
3
|
+
*/
|
|
4
|
+
export default interface DataSourceManager {
|
|
5
|
+
createSession(): string;
|
|
6
|
+
|
|
7
|
+
destorySession(sessionId: string, status: boolean): Promise<void>;
|
|
8
|
+
|
|
9
|
+
destorySession(sessionId: string, status: boolean): void;
|
|
10
|
+
|
|
11
|
+
start(): void;
|
|
12
|
+
|
|
13
|
+
stop(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { DBMapper, MapperType, SqlDelete, SqlQuery, SqlUpdate, SqlWhere } from "../db";
|
|
2
|
+
import { DesignMeta } from "../type/DesignMeta";
|
|
3
|
+
import DataFormat from "../utils/DataFormat";
|
|
4
|
+
|
|
5
|
+
export default class BaseMapper<T> implements DBMapper<T> {
|
|
6
|
+
protected tableName: string;
|
|
7
|
+
protected classZ: any; //映射的原型类
|
|
8
|
+
protected mappingMap: Map<string, MapperType>; //代码别名-映射关系
|
|
9
|
+
protected mappingList: MapperType[];
|
|
10
|
+
protected dbFields: Map<string, string>; //数据库别名-代码别名
|
|
11
|
+
|
|
12
|
+
/***
|
|
13
|
+
* @version 1.0 对于类型做一个转换
|
|
14
|
+
*/
|
|
15
|
+
constructor() {
|
|
16
|
+
let tClass = Reflect.getMetadata(DesignMeta.entity, this);
|
|
17
|
+
this.classZ = tClass;
|
|
18
|
+
|
|
19
|
+
let tableName = Reflect.getMetadata(DesignMeta.table, tClass);
|
|
20
|
+
if (!tableName) {
|
|
21
|
+
throw new Error(`This class ${tClass.name} has no annotation table name`);
|
|
22
|
+
}
|
|
23
|
+
this.tableName = tableName;
|
|
24
|
+
this.mappingMap = Reflect.getMetadata(DesignMeta.mapping, tClass); //映射关系
|
|
25
|
+
this.dbFields = Reflect.getMetadata(DesignMeta.dbFields, tClass); //作用的列名
|
|
26
|
+
this.mappingList = Array.of();
|
|
27
|
+
|
|
28
|
+
this.mappingMap.forEach(item => {
|
|
29
|
+
this.mappingList.push(item);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//获取数据库别名通过代码内的名称
|
|
34
|
+
protected getFieldName(name: string): string {
|
|
35
|
+
let info = this.mappingMap.get(name);
|
|
36
|
+
return info ? info.field : name;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
protected setRow(rowData: Object): T {
|
|
40
|
+
let t = new this.classZ();
|
|
41
|
+
|
|
42
|
+
this.mappingMap.forEach((item, key) => {
|
|
43
|
+
let value = Reflect.get(rowData, item.field) || Reflect.get(rowData, key);
|
|
44
|
+
if (value != null) {
|
|
45
|
+
let fvalue = DataFormat.formatValue(value, item.type);
|
|
46
|
+
Reflect.set(t, key, fvalue);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return t;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected setRows(rowDataList: Object[]): T[] {
|
|
54
|
+
let list: T[] = Array.of();
|
|
55
|
+
rowDataList.forEach(item => {
|
|
56
|
+
list.push(this.setRow(item));
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return list;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
saveORUpdate(rows: T | T[], ds?: string, sessionId?: string): Promise<string | number> {
|
|
63
|
+
throw new Error("Method not implemented.");
|
|
64
|
+
}
|
|
65
|
+
saveOne(row: T, ds?: string, sessionId?: string): Promise<string | number> {
|
|
66
|
+
throw new Error("Method not implemented.");
|
|
67
|
+
}
|
|
68
|
+
saveList(rows: T[], ds?: string, sessionId?: string): Promise<boolean> {
|
|
69
|
+
throw new Error("Method not implemented.");
|
|
70
|
+
}
|
|
71
|
+
update({ row, where, limit }: SqlUpdate, ds?: string, sessionId?: string): Promise<boolean> {
|
|
72
|
+
throw new Error("Method not implemented.");
|
|
73
|
+
}
|
|
74
|
+
updateOne(sqlUpdate: SqlUpdate, ds?: string, sessionId?: string): Promise<boolean> {
|
|
75
|
+
throw new Error("Method not implemented.");
|
|
76
|
+
}
|
|
77
|
+
updateByPrimaryKey(row: T, ds?: string, sessionId?: string): Promise<boolean> {
|
|
78
|
+
throw new Error("Method not implemented.");
|
|
79
|
+
}
|
|
80
|
+
select(conditions: SqlQuery, ds?: string, sessionId?: string): Promise<T[]> {
|
|
81
|
+
throw new Error("Method not implemented.");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/***
|
|
85
|
+
* @version 1.0 查询单个对象
|
|
86
|
+
*
|
|
87
|
+
*/
|
|
88
|
+
async selectOne(conditions?: SqlQuery, ds?: string, sessionId?: string): Promise<T | null> {
|
|
89
|
+
throw new Error("Method not implemented.");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/***
|
|
93
|
+
* @version 1.0 通过主键查找对象
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
async selectByPrimaryKey(row: T, ds?: string, sessionId?: string): Promise<T | null> {
|
|
97
|
+
throw new Error("Method not implemented.");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
exist(where: SqlWhere, ds?: string, sessionId?: string): Promise<boolean> {
|
|
101
|
+
throw new Error("Method not implemented.");
|
|
102
|
+
}
|
|
103
|
+
count(where: SqlWhere, ds?: string, sessionId?: string): Promise<number> {
|
|
104
|
+
throw new Error("Method not implemented.");
|
|
105
|
+
}
|
|
106
|
+
delete(conditions: SqlDelete, ds?: string, sessionId?: string): Promise<boolean> {
|
|
107
|
+
throw new Error("Method not implemented.");
|
|
108
|
+
}
|
|
109
|
+
deleteOne(where: SqlWhere, ds?: string, sessionId?: string): Promise<boolean> {
|
|
110
|
+
throw new Error("Method not implemented.");
|
|
111
|
+
}
|
|
112
|
+
deleteByPrimaryKey(row: T, ds?: string, sessionId?: string): Promise<boolean> {
|
|
113
|
+
throw new Error("Method not implemented.");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export type FIELDTYPE = {
|
|
2
|
+
field: string;
|
|
3
|
+
order?: boolean; //是否为倒序 order true为倒序
|
|
4
|
+
compare?: (a: any, b: any) => boolean;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export default class DataMap<K, V extends Object> extends Map<K, V> {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
toValues(): V[] {
|
|
13
|
+
return [...this.values()];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
toKeys(): K[] {
|
|
17
|
+
return [...this.keys()];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
toObject(): { [key: string]: V } {
|
|
21
|
+
let o = {};
|
|
22
|
+
this.forEach((v, k: any) => {
|
|
23
|
+
Reflect.set(o, k, v);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return o;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//自定义排序 支持多个排序
|
|
30
|
+
sort(sorts?: FIELDTYPE[], list?: V[]): V[] {
|
|
31
|
+
list = !list ? this.toValues() : list;
|
|
32
|
+
if (!sorts || sorts?.length == 0) {
|
|
33
|
+
return list;
|
|
34
|
+
}
|
|
35
|
+
let total = sorts.length;
|
|
36
|
+
list.sort((a, b) => {
|
|
37
|
+
let resultNum = 0;
|
|
38
|
+
sorts.some((f, index) => {
|
|
39
|
+
let field = f.field;
|
|
40
|
+
let aValue = Reflect.get(a, field);
|
|
41
|
+
let bValue = Reflect.get(b, field);
|
|
42
|
+
let flag = f.compare ? f.compare(aValue, bValue) : aValue > bValue;
|
|
43
|
+
resultNum = flag ? total - index : index - total;
|
|
44
|
+
|
|
45
|
+
//降序则倒着
|
|
46
|
+
if (f.order) {
|
|
47
|
+
resultNum = -resultNum;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return !!flag;
|
|
51
|
+
});
|
|
52
|
+
return resultNum;
|
|
53
|
+
});
|
|
54
|
+
return list;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/***
|
|
58
|
+
* @version 1.0 查找属性名称
|
|
59
|
+
* @params atts代表属性键值对匹配
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
findByAtts(atts: { [key: string]: any }): V[] {
|
|
63
|
+
let list: V[] = [];
|
|
64
|
+
let keys = Object.keys(atts);
|
|
65
|
+
|
|
66
|
+
this.forEach((item) => {
|
|
67
|
+
let flag = keys.every((key) => {
|
|
68
|
+
let v = Reflect.get(atts, key);
|
|
69
|
+
|
|
70
|
+
//这边判断 是不是一个复合属性
|
|
71
|
+
if (Reflect.has(item, key)) {
|
|
72
|
+
let itemV = Reflect.get(item, key);
|
|
73
|
+
return itemV == v;
|
|
74
|
+
} else {
|
|
75
|
+
let keyList = key.split(".");
|
|
76
|
+
if (keyList.length > 1) {
|
|
77
|
+
let tmpV: any = item;
|
|
78
|
+
let f = keyList.every((tk) => {
|
|
79
|
+
if (!Reflect.has(tmpV, tk)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
tmpV = Reflect.get(tmpV, tk);
|
|
83
|
+
return true;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (!f) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return tmpV == v;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return false;
|
|
95
|
+
});
|
|
96
|
+
if (flag) {
|
|
97
|
+
list.push(item);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return list;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type CheckTool = {
|
|
2
|
+
fn: (val: any) => boolean;
|
|
3
|
+
message?: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export interface FormRuleModel {
|
|
7
|
+
message?: string; //错误信息
|
|
8
|
+
type?: string; // 类型
|
|
9
|
+
minSize?: number; //最小值
|
|
10
|
+
maxSize?: number; //最大值
|
|
11
|
+
required?: boolean; //是否为必填项
|
|
12
|
+
defaultVal?: any; //默认值
|
|
13
|
+
filters?: CheckTool[]; //校验方法
|
|
14
|
+
nullMessage?: string; //是否为空的错误提示
|
|
15
|
+
sizeMessgae?: string; //长度错误提示
|
|
16
|
+
typeMessage?: string; //类型错误提示
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type FormRuleType = {
|
|
20
|
+
rules: { [prop: string]: FormRuleModel };
|
|
21
|
+
index: number;
|
|
22
|
+
basicFlag: boolean;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default class ValidError extends Error {}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import * as winston from "winston";
|
|
2
|
+
import { ColorLevelType, WinstonLoggerType } from "../type/WinstonLoggerType";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { DateUtil, ValidationUtil } from "../utils";
|
|
5
|
+
import * as util from "util";
|
|
6
|
+
const SPLAT = Symbol.for("splat");
|
|
7
|
+
|
|
8
|
+
export default class WinstonLogger {
|
|
9
|
+
protected config: WinstonLoggerType;
|
|
10
|
+
protected categoryMap: Map<string, winston.Logger>;
|
|
11
|
+
|
|
12
|
+
constructor(config: WinstonLoggerType) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.categoryMap = new Map();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//控制台着色
|
|
18
|
+
private colorize(str: string, level: string) {
|
|
19
|
+
let colorStyle = Reflect.get(ColorLevelType, level);
|
|
20
|
+
if (!colorStyle) {
|
|
21
|
+
return str;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return `\x1B[${colorStyle[0]}m ${str} \x1B[${colorStyle[1]}m`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//数据着色为白色
|
|
28
|
+
private colorizeData(data: any) {
|
|
29
|
+
let msg = ValidationUtil.isObject(data) ? JSON.stringify(data) : data;
|
|
30
|
+
return `\x1B[37m ${msg} \x1B[39m`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setConfig(config: WinstonLoggerType) {
|
|
34
|
+
this.config = config;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
hasLogger(category: string): boolean {
|
|
38
|
+
return winston.loggers.has(category);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getLogger(category: string): winston.Logger | undefined {
|
|
42
|
+
return this.categoryMap.get(category);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
addLogger(category: string) {
|
|
46
|
+
if (this.categoryMap.has(category)) {
|
|
47
|
+
winston.loggers.close(category);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let newLogger = winston.loggers.add(category, {
|
|
51
|
+
format: winston.format.combine(
|
|
52
|
+
winston.format.label({ label: category }),
|
|
53
|
+
winston.format.printf(info => {
|
|
54
|
+
//debug模式等级时仅为控制台输出
|
|
55
|
+
let level = info.level.toUpperCase();
|
|
56
|
+
let timestamp = DateUtil.toDateTimeMS();
|
|
57
|
+
|
|
58
|
+
let content = {
|
|
59
|
+
timestamp,
|
|
60
|
+
level,
|
|
61
|
+
label: info.label,
|
|
62
|
+
message: info.message,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
if (Reflect.has(info, SPLAT)) {
|
|
66
|
+
Reflect.set(content, "splat", JSON.stringify(Reflect.get(info, SPLAT)));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (info.stack) {
|
|
70
|
+
Reflect.set(content, "stack", info.stack);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Reflect.set(info, "timestamp", content.timestamp);
|
|
74
|
+
|
|
75
|
+
//新增打印控制台
|
|
76
|
+
if (this.config.printConsole) {
|
|
77
|
+
let text = this.colorize(util.format("[%s] [%s] %s - ", timestamp, level, info.label), info.level);
|
|
78
|
+
text += this.colorizeData(content.message);
|
|
79
|
+
|
|
80
|
+
if (Reflect.has(info, SPLAT)) {
|
|
81
|
+
let splatMsg: any[] = Reflect.get(info, SPLAT);
|
|
82
|
+
splatMsg.forEach(item => {
|
|
83
|
+
text += " " + this.colorizeData(item);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (info.stack) {
|
|
88
|
+
text += this.colorizeData(`\nstatck: ${info.stack}`);
|
|
89
|
+
}
|
|
90
|
+
let fn = console.info;
|
|
91
|
+
if (Reflect.has(console, info.level)) {
|
|
92
|
+
fn = Reflect.get(console, info.level);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
Reflect.apply(fn, console, [text]);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return util.format("%j", content);
|
|
99
|
+
})
|
|
100
|
+
),
|
|
101
|
+
|
|
102
|
+
transports: [
|
|
103
|
+
new winston.transports.File({
|
|
104
|
+
level: this.config.fileLevel,
|
|
105
|
+
filename: path.join(this.config.rootPath, `${category}.log`),
|
|
106
|
+
maxsize: this.config.maxsize,
|
|
107
|
+
maxFiles: this.config.maxFiles,
|
|
108
|
+
}),
|
|
109
|
+
],
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
this.categoryMap.set(category, newLogger);
|
|
113
|
+
return newLogger;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
getLoggerList(): winston.Logger[] {
|
|
117
|
+
return [...this.categoryMap.values()];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export enum DesignMeta {
|
|
2
|
+
table = "db:table", //表名
|
|
3
|
+
field = "db:field", //列名
|
|
4
|
+
fieldMap = "db:fieldMap", //注入列名集合
|
|
5
|
+
dbType = "db:dbType", //数据类型
|
|
6
|
+
primaryKey = "db:primaryKey", //主键类型
|
|
7
|
+
entity = "db:entity", //实例化的数据库类
|
|
8
|
+
mapping = "db:mapping", //映射描述
|
|
9
|
+
dbFields = "db:fields", //数据库名-ts名
|
|
10
|
+
sqlSession = "SqlSession", //sql会话
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ProcessType = {
|
|
2
|
+
pid: number; //进程id
|
|
3
|
+
name: string; //进程名称
|
|
4
|
+
env: string; //环境
|
|
5
|
+
version: string; //版本
|
|
6
|
+
rss: string; //常驻集大小
|
|
7
|
+
heapTotal: string; //V8 的内存使用量
|
|
8
|
+
heapUsed: string;
|
|
9
|
+
arrayBuffers: string; //包含所有的Buffer
|
|
10
|
+
external: string; //绑定到 V8 管理的 JavaScript 对象的 C++ 对象的内存使用量
|
|
11
|
+
uptime: string; //运行时间
|
|
12
|
+
};
|