@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
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2021-2022 william_zhong
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
# 文档简要说明
|
|
2
|
+
|
|
3
|
+
## 好用的注入和依赖服务框架
|
|
4
|
+
|
|
5
|
+
* 通过注解实现组件的实例化和发现
|
|
6
|
+
|
|
7
|
+
* 提供类似于spring的注解方式(大部分同名的具有一样的功能)
|
|
8
|
+
|
|
9
|
+
## 基本思想
|
|
10
|
+
|
|
11
|
+
在一个入口类定义为Application 然后将各种组件通过依赖的方式加载进入内部,然后可以通过自动注入的方式进行组件的调用
|
|
12
|
+
|
|
13
|
+
## 基本功能
|
|
14
|
+
|
|
15
|
+
* 自动加载声明的组件
|
|
16
|
+
|
|
17
|
+
* 提供数据源的模板(方便对应不同的数据库实现curd操作)
|
|
18
|
+
|
|
19
|
+
* 提供自定义校验数据
|
|
20
|
+
|
|
21
|
+
## 快速安装
|
|
22
|
+
|
|
23
|
+
npm install fastcar-core
|
|
24
|
+
|
|
25
|
+
## 常用注解引用
|
|
26
|
+
|
|
27
|
+
ENV 用于指明环境
|
|
28
|
+
|
|
29
|
+
ApplicationStart 用于在程序启动后调用
|
|
30
|
+
|
|
31
|
+
ApplicationStop 用于在程序停止前调用
|
|
32
|
+
|
|
33
|
+
ApplicationRunner 用于声明程序是否在系统中启动
|
|
34
|
+
|
|
35
|
+
ApplicationInit 用于在程序启动后调用
|
|
36
|
+
|
|
37
|
+
ApplicationDestory 用于在程序停止前调用
|
|
38
|
+
|
|
39
|
+
ComponentScan 用于需要扫描的路径
|
|
40
|
+
|
|
41
|
+
ComponentScanExclusion 用于排除需要扫描的路径
|
|
42
|
+
|
|
43
|
+
Component 标注为组件
|
|
44
|
+
|
|
45
|
+
ComponentInjection 自定义组件入口
|
|
46
|
+
|
|
47
|
+
Hotter 指定热更新类 0.2.13 版本生效(当我们修改代码后,可以自动热加载文件)
|
|
48
|
+
|
|
49
|
+
BeanName 指明组件名称(每个组件具有一个系统生成id为"类名:16位随机值",为了便于调用可自定义逻辑名)
|
|
50
|
+
|
|
51
|
+
Configure 表明为配置组件
|
|
52
|
+
|
|
53
|
+
Controller 表明为控制组件
|
|
54
|
+
|
|
55
|
+
Service 表明为服务组件
|
|
56
|
+
|
|
57
|
+
Repository 表明为依赖的数据组件
|
|
58
|
+
|
|
59
|
+
Injection 拥有指定注入组件
|
|
60
|
+
|
|
61
|
+
Application 声明为一个应用
|
|
62
|
+
|
|
63
|
+
Autowired 自动注入依赖的组件,现在等同为CallDependency
|
|
64
|
+
|
|
65
|
+
CallDependency 调用时注入组件(调用对象可以不是组件 可以是一个普通类) 0.2.11版本以上生效
|
|
66
|
+
|
|
67
|
+
AliasInjection 根据别名注入组件
|
|
68
|
+
|
|
69
|
+
ExceptionMonitor 声明异常监听
|
|
70
|
+
|
|
71
|
+
Deprecate 用于标注方法是否被放弃 当调用时会提示已放弃该方法
|
|
72
|
+
|
|
73
|
+
NotImplemented 用于标注方法未实现
|
|
74
|
+
|
|
75
|
+
Override 用于标注方法已被重新实现
|
|
76
|
+
|
|
77
|
+
Readonly 作用于属性是否只读
|
|
78
|
+
|
|
79
|
+
Log 使用logger
|
|
80
|
+
|
|
81
|
+
AddRequireModule 自定义添加制定木块
|
|
82
|
+
|
|
83
|
+
AddChildValid 自定义添加校验模块
|
|
84
|
+
|
|
85
|
+
DefaultVal 标注属性的默认值
|
|
86
|
+
|
|
87
|
+
NotNull 标注属性不为空
|
|
88
|
+
|
|
89
|
+
Size 标注属性的大小
|
|
90
|
+
|
|
91
|
+
Type 标注属性类型
|
|
92
|
+
|
|
93
|
+
ValidCustom 校验自定义方法
|
|
94
|
+
|
|
95
|
+
ValidForm 校验表单开启
|
|
96
|
+
|
|
97
|
+
Rule 校验规则开启
|
|
98
|
+
|
|
99
|
+
ApplicationSetting 应用内配置设置 具有最高等级
|
|
100
|
+
|
|
101
|
+
ResourcePath 自定义resource的位置
|
|
102
|
+
|
|
103
|
+
## 约定
|
|
104
|
+
|
|
105
|
+
### 配置文件约定
|
|
106
|
+
|
|
107
|
+
* 所有项目配置文件均放在resource文件夹下
|
|
108
|
+
* application.yml (或者js,json) 代表应用配置文件
|
|
109
|
+
* application-{env}.yml (或者js,json) 代表不同环境的配置 在 application中可以采用env指定开发环境
|
|
110
|
+
* application 中 settings 代表第三方自定义组件或者值, application代表应用设置
|
|
111
|
+
* 自定义配置可以通过注解Configure来进行映射(后续考虑支持url的配置)
|
|
112
|
+
|
|
113
|
+
### 应用程序约定
|
|
114
|
+
|
|
115
|
+
* 应用程序声明周期分为启动中->运行时->停止前->结束后
|
|
116
|
+
* 在介于启动中和运行时的阶段,可采用ApplicationStart进行相应的组件逻辑初始化操作
|
|
117
|
+
* 在停止前阶段,可采用ApplicationStop进行相应的组件结束操作
|
|
118
|
+
|
|
119
|
+
### 应用程序执行顺序
|
|
120
|
+
|
|
121
|
+
* 加载系统配置
|
|
122
|
+
* 扫描application所在目录或者指定目录下的组件,并注入实例
|
|
123
|
+
* 遍历所有实例,并进行装配所依赖的服务
|
|
124
|
+
* 运行所有标注为ApplicationStart的组件,而且是按照优先级顺序依次执行
|
|
125
|
+
* 服务停止前运行所有标注为ApplicationStop的组件,也是按照优先级顺序依次执行
|
|
126
|
+
* 结束运行
|
|
127
|
+
|
|
128
|
+
### 声明约定
|
|
129
|
+
|
|
130
|
+
* index.d.ts 代表实现的 Application及其他配置说明
|
|
131
|
+
* annotation.d.ts 代表所实现的注解
|
|
132
|
+
* utils.d.ts 代表基础的工具类
|
|
133
|
+
|
|
134
|
+
## 基本用法
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
//声明一个组件
|
|
138
|
+
import { Service } from "fastcar-core/annotation";
|
|
139
|
+
|
|
140
|
+
@Service
|
|
141
|
+
class HelloService {
|
|
142
|
+
say() {
|
|
143
|
+
console.info("hello world");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export default HelloService;
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
//声明一个别名组件
|
|
152
|
+
import { Service, BeanName } from "fastcar-core/annotation";
|
|
153
|
+
|
|
154
|
+
@Service
|
|
155
|
+
@BeanName("HelloService")
|
|
156
|
+
class HelloService {
|
|
157
|
+
say() {
|
|
158
|
+
console.info("hello world");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export default HelloService;
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
//引入依赖组件
|
|
167
|
+
import { Controller, Autowired } from "fastcar-core/annotation";
|
|
168
|
+
|
|
169
|
+
@Controller
|
|
170
|
+
class HelloController {
|
|
171
|
+
|
|
172
|
+
//自动注入组件
|
|
173
|
+
@Autowired
|
|
174
|
+
private hello!: HelloService;
|
|
175
|
+
|
|
176
|
+
callHello() {
|
|
177
|
+
this.hello.say();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
//生命周期内运行
|
|
184
|
+
import { ApplicationStart } from "fastcar-core/annotation";
|
|
185
|
+
|
|
186
|
+
@ApplicationStart()
|
|
187
|
+
export default class StartRunner {
|
|
188
|
+
run() {
|
|
189
|
+
console.info("服务启动后调用的方法");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
//声明周期内运行
|
|
196
|
+
@ApplicationRunner
|
|
197
|
+
export default class StartRunner {
|
|
198
|
+
@ApplicationInit() //可绑定多个方法
|
|
199
|
+
run() {
|
|
200
|
+
console.info("服务启动后调用的方法");
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
//声明入口应用 这边有个约定 启动后会自动扫描所在文件夹下的文件 并进行注入
|
|
207
|
+
import { FastCarApplication } from "fastcar-core";
|
|
208
|
+
import { Application } from "fastcar-core/annotation";
|
|
209
|
+
|
|
210
|
+
@Application //声明是一个应用
|
|
211
|
+
@ENV("TEST") //声明为TEST环境或者在resource下的application.yml内声明
|
|
212
|
+
@Log() //启用默认日志注释
|
|
213
|
+
class APP {
|
|
214
|
+
app!: FastCarApplication;
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
//表单示例
|
|
220
|
+
import { NotNull, Size, Rule, ValidForm } from "fastcar-core/annotation";
|
|
221
|
+
|
|
222
|
+
class B {
|
|
223
|
+
@NotNull
|
|
224
|
+
c!: string;
|
|
225
|
+
|
|
226
|
+
@Size({ minSize: 1, maxSize: 10 })
|
|
227
|
+
d?: number;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
class A {
|
|
231
|
+
|
|
232
|
+
@ValidForm //开启表单校验
|
|
233
|
+
test(a: string, @Rule() @NotNull b: B) {
|
|
234
|
+
console.log(a, b);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
let instance = new A();
|
|
239
|
+
instance.test("a", { c: "c", d: 13 }); //校验失败
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
//本地配置映射示例
|
|
244
|
+
import { Configure } from "fastcar-core/annotation";
|
|
245
|
+
|
|
246
|
+
//读取resource下的配置 如hello.yml中为hello: "world"
|
|
247
|
+
@Configure("hello.yml")
|
|
248
|
+
class HelloConfig {
|
|
249
|
+
hello!: string; //初始化完成后则为hello=world
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
//根据不同的环境加载不同的映射配置
|
|
253
|
+
@Configure(`evnconfig-${process.env.NODE_ENV}.yml`)
|
|
254
|
+
class EnvConfig {
|
|
255
|
+
text!: string;
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
//调用依赖版本示例
|
|
261
|
+
import HelloService from "./HelloService";
|
|
262
|
+
import { CallDependency } from "fastcar-core/annotation";
|
|
263
|
+
|
|
264
|
+
export default class CallService {
|
|
265
|
+
|
|
266
|
+
//仅在调用时才会注入组件信息
|
|
267
|
+
@CallDependency
|
|
268
|
+
private hello!: HelloService;
|
|
269
|
+
|
|
270
|
+
sayHello() {
|
|
271
|
+
return this.hello.say();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
//指定文件热更新
|
|
278
|
+
@Controller
|
|
279
|
+
@Hotter //实例会被热更新或者在sesttings配置中配置 hotter为true
|
|
280
|
+
export default class IndexController {
|
|
281
|
+
@Autowired
|
|
282
|
+
private exampleService!: ExampleService;
|
|
283
|
+
|
|
284
|
+
@GET("/")
|
|
285
|
+
index() {
|
|
286
|
+
return Result.ok("hello world");
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
//改造一个好用的map-list数据链表
|
|
293
|
+
import { DataMap } from "fastcar-core";
|
|
294
|
+
|
|
295
|
+
describe("数据集合测试", () => {
|
|
296
|
+
it("数据集合", () => {
|
|
297
|
+
type User = {
|
|
298
|
+
uid: number;
|
|
299
|
+
name: string;
|
|
300
|
+
desc?: {
|
|
301
|
+
detail: string;
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
let n: DataMap<number, User> = new DataMap();
|
|
306
|
+
n.set(1, {
|
|
307
|
+
uid: 1,
|
|
308
|
+
name: "小明",
|
|
309
|
+
});
|
|
310
|
+
n.set(2, {
|
|
311
|
+
uid: 2,
|
|
312
|
+
name: "小王",
|
|
313
|
+
desc: {
|
|
314
|
+
detail: "住在隔壁",
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
let xiaoming = n.get(1);
|
|
319
|
+
console.log(xiaoming?.name == "小明"); //true
|
|
320
|
+
|
|
321
|
+
let oo: { [key: number]: User } = n.toObject(); //序列化为一个key-value的对象
|
|
322
|
+
console.log(oo[1]); // 小明
|
|
323
|
+
|
|
324
|
+
let searchList = n.findByAtts({ uid: 1 }); //查找单一对象
|
|
325
|
+
console.log(searchList);
|
|
326
|
+
|
|
327
|
+
let searchList2 = n.findByAtts({ "desc.detail": "住在隔壁" });
|
|
328
|
+
console.log(searchList2);
|
|
329
|
+
|
|
330
|
+
let sortList = n.sort([
|
|
331
|
+
{
|
|
332
|
+
field: "uid",
|
|
333
|
+
order: true, //true为倒序
|
|
334
|
+
},
|
|
335
|
+
]);
|
|
336
|
+
console.log(sortList); //支持多重fields的排序 越在前面排序优先级越高
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
```ts
|
|
342
|
+
//根据启动应用的时机 加载自定义方法
|
|
343
|
+
import { ApplicationHook, FastCarApplication, Logger } from "fastcar-core";
|
|
344
|
+
import { Application } from "fastcar-core/annotation";
|
|
345
|
+
|
|
346
|
+
@Application
|
|
347
|
+
class APP implements ApplicationHook {
|
|
348
|
+
app!: FastCarApplication;
|
|
349
|
+
|
|
350
|
+
@Log("app")
|
|
351
|
+
logger!: Logger;
|
|
352
|
+
|
|
353
|
+
beforeStartServer(): void {
|
|
354
|
+
this.logger.debug("beforeStartServer-----");
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
startServer(): void {
|
|
358
|
+
this.logger.debug("startServer------");
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
beforeStopServer(): void {
|
|
362
|
+
this.logger.debug("beforeStopServer-----");
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
stopServer(): void {
|
|
366
|
+
this.logger.debug("stopServer-----");
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
## 更多用法
|
|
372
|
+
|
|
373
|
+
参考项目git地址 fastcar-core/test 下的simple内
|
|
374
|
+
|
|
375
|
+
## 项目开源地址
|
|
376
|
+
|
|
377
|
+
* 项目下载 git clone <https://github.com/williamDazhangyu/fast-car.git>
|
|
378
|
+
|
|
379
|
+
* 在线查看 <https://github.com/williamDazhangyu/fast-car>
|
package/annotation.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
type Ret = (target: any) => void;
|
|
2
|
+
|
|
3
|
+
type FRet = (target: any, methodName?: string, descriptor?: PropertyDescriptor) => void;
|
|
4
|
+
|
|
5
|
+
type PMRet = (target: any, propertyKey: string) => void;
|
|
6
|
+
|
|
7
|
+
type PRet = (target: any, propertyKey: string, index?: number) => void;
|
|
8
|
+
|
|
9
|
+
type MRet = (target: any, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
10
|
+
|
|
11
|
+
type PPRet = (target: any, method: string, index: number) => void;
|
|
12
|
+
|
|
13
|
+
type SizeModel = {
|
|
14
|
+
minSize?: number;
|
|
15
|
+
maxSize?: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type checkfun = (val: any) => boolean;
|
|
19
|
+
|
|
20
|
+
import { FormRuleModel } from "./src/model/FormRuleModel";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 设置初始化的env 注入在原始的application上面
|
|
24
|
+
*/
|
|
25
|
+
export function ENV(name: string): Ret;
|
|
26
|
+
|
|
27
|
+
/***
|
|
28
|
+
* 应用启动注解类
|
|
29
|
+
* @params order 排序 序号越小排在越前面 系统级的组件 如数据库等一般为0 默认为1
|
|
30
|
+
* @params exec 执行方法 默认函数名为run
|
|
31
|
+
*/
|
|
32
|
+
export function ApplicationStart(order?: number, exec?: string): Ret;
|
|
33
|
+
export function ApplicationStop(order?: number, exec?: string): Ret;
|
|
34
|
+
export function ApplicationRunner(target: any): void;
|
|
35
|
+
export function ApplicationInit(order?: number): MRet;
|
|
36
|
+
export function ApplicationDestory(order?: number): MRet;
|
|
37
|
+
|
|
38
|
+
/***
|
|
39
|
+
* 组件模块扫描类
|
|
40
|
+
*/
|
|
41
|
+
export function ComponentScan(...names: string[]): Ret;
|
|
42
|
+
export function ComponentScanExclusion(...names: string[]): Ret;
|
|
43
|
+
export function ComponentInjection(target: any, ...names: string[]): void;
|
|
44
|
+
export function Hotter(target: any): void;
|
|
45
|
+
|
|
46
|
+
/***
|
|
47
|
+
* 用于描述不同组件的作用类
|
|
48
|
+
*/
|
|
49
|
+
export function Component(target: any): void;
|
|
50
|
+
export function Configure(name: string): Ret;
|
|
51
|
+
export function Controller(target: any): void;
|
|
52
|
+
export function Service(target: any): void;
|
|
53
|
+
export function Repository(target: any): void;
|
|
54
|
+
|
|
55
|
+
//实例自定义名称 并会将改名称作为逻辑名注入到实例内
|
|
56
|
+
export function BeanName(name: string): Ret;
|
|
57
|
+
|
|
58
|
+
//此方法用来构造不同的注入,不建议直接用于注解上
|
|
59
|
+
export function Injection(target: any, name: string): void;
|
|
60
|
+
|
|
61
|
+
//应用注解类
|
|
62
|
+
export function Application(target: any): any;
|
|
63
|
+
|
|
64
|
+
//用于自身手动包装注入方法
|
|
65
|
+
export function AddRequireModule(target: any, m: string, alias: string): void;
|
|
66
|
+
|
|
67
|
+
//自动注入类
|
|
68
|
+
export function Autowired(target: any, propertyKey: string): void;
|
|
69
|
+
|
|
70
|
+
//调用时注入类
|
|
71
|
+
export function CallDependency(target: any, propertyKey: string): void;
|
|
72
|
+
|
|
73
|
+
//异常方法类
|
|
74
|
+
export function ExceptionMonitor(target: any): void;
|
|
75
|
+
|
|
76
|
+
//用于标记废弃
|
|
77
|
+
export function Deprecate(msg: string): void;
|
|
78
|
+
|
|
79
|
+
//标记为未实现
|
|
80
|
+
export function NotImplemented(target: any, name?: string, descriptor?: PropertyDescriptor): void;
|
|
81
|
+
|
|
82
|
+
//用于声明是否被重载了
|
|
83
|
+
export function Override(target: any, name?: string, descriptor?: PropertyDescriptor): void;
|
|
84
|
+
|
|
85
|
+
//用于标记是否只读
|
|
86
|
+
export function Readonly(target: any, name?: string, descriptor?: PropertyDescriptor): void;
|
|
87
|
+
|
|
88
|
+
export function Log(category?: string): PMRet;
|
|
89
|
+
|
|
90
|
+
//添加子表单校验数据
|
|
91
|
+
export function AddChildValid(target: any, name: string, value: { [key: string]: any }, index?: number): void;
|
|
92
|
+
|
|
93
|
+
//默认值放入
|
|
94
|
+
export function DefaultVal(val: any): PRet;
|
|
95
|
+
|
|
96
|
+
//非空字段校验
|
|
97
|
+
export function NotNull(target: any, propertyKey: string, index?: number): void;
|
|
98
|
+
|
|
99
|
+
export function Size(m: SizeModel): PRet;
|
|
100
|
+
|
|
101
|
+
//主要用于获取非基本类型的校验
|
|
102
|
+
export function Type(type: string): PRet;
|
|
103
|
+
|
|
104
|
+
export function ValidCustom(fn: checkfun, message?: string): PRet;
|
|
105
|
+
|
|
106
|
+
/***
|
|
107
|
+
* @version 1.0 校验表单 支持校验大小 类型 和自定义方法
|
|
108
|
+
*/
|
|
109
|
+
export function ValidForm(target: any, methodName: string, descriptor: PropertyDescriptor): void;
|
|
110
|
+
|
|
111
|
+
/***
|
|
112
|
+
*@version 1.0 添加校验规则 type如果不填选择为增强型的类型 若获取不到则为string校验
|
|
113
|
+
*
|
|
114
|
+
*/
|
|
115
|
+
export function Rule(rules?: { [prop: string]: FormRuleModel }): PPRet;
|
|
116
|
+
|
|
117
|
+
//动态数据源标记
|
|
118
|
+
export function DS(name: string): FRet;
|
|
119
|
+
|
|
120
|
+
//指定数据源标记位置
|
|
121
|
+
export function DSIndex(target: any, name: string, index: number): void;
|
|
122
|
+
|
|
123
|
+
//标记数据库类型
|
|
124
|
+
export function DBType(name: string): PMRet;
|
|
125
|
+
|
|
126
|
+
//标记数据列名
|
|
127
|
+
export function Field(name: string): PMRet;
|
|
128
|
+
|
|
129
|
+
//是否为主键
|
|
130
|
+
export function PrimaryKey(target: any, propertyKey: string): void;
|
|
131
|
+
|
|
132
|
+
//标记表名
|
|
133
|
+
export function Table(name: string): Ret;
|
|
134
|
+
|
|
135
|
+
//映射实体类
|
|
136
|
+
export function Entity(className: Function): Ret;
|
|
137
|
+
|
|
138
|
+
//连接会话 如果需要使用同一连接或者使用事务是传递
|
|
139
|
+
export function SqlSession(target: any, name: string, index: number): void;
|
|
140
|
+
|
|
141
|
+
//开启事务 driver: string = "MysqlDataSourceManager"
|
|
142
|
+
export function Transactional(driver?: string): MRet;
|
|
143
|
+
|
|
144
|
+
//设置入口路径
|
|
145
|
+
export function BaseFilePath(name: string): Ret;
|
|
146
|
+
|
|
147
|
+
//设置入口文件夹路径
|
|
148
|
+
export function BasePath(name: string): Ret;
|
|
149
|
+
|
|
150
|
+
//自定义程序内配置
|
|
151
|
+
export function ApplicationSetting(setting: { [key: string]: any }): Ret;
|
|
152
|
+
|
|
153
|
+
//根据别名注入依赖组件
|
|
154
|
+
export function AliasInjection(alias: string): PMRet;
|
|
155
|
+
|
|
156
|
+
//自定义资源路径
|
|
157
|
+
export function ResourcePath(name: string): Ret;
|