@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.
Files changed (239) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +379 -0
  3. package/annotation.d.ts +157 -0
  4. package/db.d.ts +272 -0
  5. package/index.d.ts +262 -0
  6. package/package.json +53 -0
  7. package/src/FastCarApplication.ts +761 -0
  8. package/src/annotation/Application.ts +46 -0
  9. package/src/annotation/ExceptionMonitor.ts +15 -0
  10. package/src/annotation/bind/AddRequireModule.ts +18 -0
  11. package/src/annotation/bind/AliasInjection.ts +24 -0
  12. package/src/annotation/bind/Autowired.ts +11 -0
  13. package/src/annotation/bind/CallDependency.ts +24 -0
  14. package/src/annotation/data/DBType.ts +9 -0
  15. package/src/annotation/data/DS.ts +58 -0
  16. package/src/annotation/data/DSIndex.ts +7 -0
  17. package/src/annotation/data/Entity.ts +8 -0
  18. package/src/annotation/data/Field.ts +15 -0
  19. package/src/annotation/data/PrimaryKey.ts +7 -0
  20. package/src/annotation/data/SqlSession.ts +7 -0
  21. package/src/annotation/data/Table.ts +37 -0
  22. package/src/annotation/data/Transactional.ts +60 -0
  23. package/src/annotation/env/ApplicationSetting.ts +24 -0
  24. package/src/annotation/env/BaseFilePath.ts +12 -0
  25. package/src/annotation/env/BasePath.ts +12 -0
  26. package/src/annotation/env/ENV.ts +8 -0
  27. package/src/annotation/env/ResourcePath.ts +7 -0
  28. package/src/annotation/lifeCycle/AddLifeCycleItem.ts +25 -0
  29. package/src/annotation/lifeCycle/ApplicationDestory.ts +13 -0
  30. package/src/annotation/lifeCycle/ApplicationInit.ts +13 -0
  31. package/src/annotation/lifeCycle/ApplicationRunner.ts +5 -0
  32. package/src/annotation/lifeCycle/ApplicationStart.ts +23 -0
  33. package/src/annotation/lifeCycle/ApplicationStop.ts +18 -0
  34. package/src/annotation/property/Deprecate.ts +17 -0
  35. package/src/annotation/property/NotImplemented.ts +5 -0
  36. package/src/annotation/property/Override.ts +4 -0
  37. package/src/annotation/property/Readonly.ts +12 -0
  38. package/src/annotation/scan/ComponentInjection.ts +22 -0
  39. package/src/annotation/scan/ComponentScan.ts +7 -0
  40. package/src/annotation/scan/ComponentScanExclusion.ts +26 -0
  41. package/src/annotation/scan/Hotter.ts +6 -0
  42. package/src/annotation/stereotype/BeanName.ts +9 -0
  43. package/src/annotation/stereotype/Component.ts +6 -0
  44. package/src/annotation/stereotype/Configure.ts +12 -0
  45. package/src/annotation/stereotype/Controller.ts +7 -0
  46. package/src/annotation/stereotype/Injection.ts +10 -0
  47. package/src/annotation/stereotype/Log.ts +17 -0
  48. package/src/annotation/stereotype/Repository.ts +7 -0
  49. package/src/annotation/stereotype/Service.ts +7 -0
  50. package/src/annotation/valid/AddChildValid.ts +61 -0
  51. package/src/annotation/valid/DefaultVal.ts +8 -0
  52. package/src/annotation/valid/NotNull.ts +7 -0
  53. package/src/annotation/valid/Rule.ts +104 -0
  54. package/src/annotation/valid/Size.ts +13 -0
  55. package/src/annotation/valid/Type.ts +8 -0
  56. package/src/annotation/valid/ValidCustom.ts +21 -0
  57. package/src/annotation/valid/ValidForm.ts +146 -0
  58. package/src/annotation.ts +103 -0
  59. package/src/config/ApplicationConfig.ts +5 -0
  60. package/src/config/SysConfig.ts +28 -0
  61. package/src/constant/AppStatusEnum.ts +5 -0
  62. package/src/constant/BootPriority.ts +7 -0
  63. package/src/constant/CommonConstant.ts +14 -0
  64. package/src/constant/ComponentKind.ts +7 -0
  65. package/src/constant/DataTypes.ts +15 -0
  66. package/src/constant/FastCarMetaData.ts +25 -0
  67. package/src/constant/LifeCycleModule.ts +5 -0
  68. package/src/db.ts +182 -0
  69. package/src/index.ts +11 -0
  70. package/src/interface/ApplicationHook.ts +9 -0
  71. package/src/interface/ApplicationRunnerService.ts +3 -0
  72. package/src/interface/DataSourceManager.ts +14 -0
  73. package/src/interface/Logger.ts +9 -0
  74. package/src/model/BaseMapper.ts +115 -0
  75. package/src/model/DataMap.ts +103 -0
  76. package/src/model/FormRuleModel.ts +23 -0
  77. package/src/model/ValidError.ts +1 -0
  78. package/src/model/WinstonLogger.ts +119 -0
  79. package/src/type/ComponentDesc.ts +5 -0
  80. package/src/type/DesignMeta.ts +11 -0
  81. package/src/type/FileHotterDesc.ts +4 -0
  82. package/src/type/MapperType.ts +8 -0
  83. package/src/type/ProcessType.ts +12 -0
  84. package/src/type/SqlError.ts +3 -0
  85. package/src/type/WinstonLoggerType.ts +18 -0
  86. package/src/utils/ClassLoader.ts +72 -0
  87. package/src/utils/ClassUtils.ts +38 -0
  88. package/src/utils/CryptoUtil.ts +106 -0
  89. package/src/utils/DataFormat.ts +97 -0
  90. package/src/utils/DateUtil.ts +85 -0
  91. package/src/utils/FileUtil.ts +172 -0
  92. package/src/utils/FormatStr.ts +13 -0
  93. package/src/utils/Mix.ts +69 -0
  94. package/src/utils/ReflectUtil.ts +22 -0
  95. package/src/utils/TypeUtil.ts +56 -0
  96. package/src/utils/ValidationUtil.ts +138 -0
  97. package/src/utils.ts +13 -0
  98. package/target/FastCarApplication.js +661 -0
  99. package/target/annotation/AddRequireModule.js +21 -0
  100. package/target/annotation/Application.js +45 -0
  101. package/target/annotation/Autowired.js +15 -0
  102. package/target/annotation/Calldependency.js +18 -0
  103. package/target/annotation/ExceptionMonitor.js +16 -0
  104. package/target/annotation/bind/AddRequireModule.js +21 -0
  105. package/target/annotation/bind/AliasInjection.js +23 -0
  106. package/target/annotation/bind/Autowired.js +13 -0
  107. package/target/annotation/bind/CallDependency.js +23 -0
  108. package/target/annotation/data/DBType.js +11 -0
  109. package/target/annotation/data/DS.js +54 -0
  110. package/target/annotation/data/DSIndex.js +9 -0
  111. package/target/annotation/data/Entity.js +10 -0
  112. package/target/annotation/data/Field.js +18 -0
  113. package/target/annotation/data/PrimaryKey.js +9 -0
  114. package/target/annotation/data/SqlSession.js +9 -0
  115. package/target/annotation/data/Table.js +34 -0
  116. package/target/annotation/data/Transactional.js +52 -0
  117. package/target/annotation/env/ApplicationSetting.js +25 -0
  118. package/target/annotation/env/BaseFilePath.js +14 -0
  119. package/target/annotation/env/BasePath.js +14 -0
  120. package/target/annotation/env/ENV.js +10 -0
  121. package/target/annotation/env/ResourcePath.js +9 -0
  122. package/target/annotation/lifeCycle/AddLifeCycleItem.js +18 -0
  123. package/target/annotation/lifeCycle/ApplicationDestory.js +15 -0
  124. package/target/annotation/lifeCycle/ApplicationInit.js +15 -0
  125. package/target/annotation/lifeCycle/ApplicationRunner.js +7 -0
  126. package/target/annotation/lifeCycle/ApplicationStart.js +24 -0
  127. package/target/annotation/lifeCycle/ApplicationStop.js +20 -0
  128. package/target/annotation/property/Deprecate.js +19 -0
  129. package/target/annotation/property/NotImplemented.js +8 -0
  130. package/target/annotation/property/Override.js +7 -0
  131. package/target/annotation/property/Readonly.js +16 -0
  132. package/target/annotation/scan/ComponentInjection.js +21 -0
  133. package/target/annotation/scan/ComponentScan.js +9 -0
  134. package/target/annotation/scan/ComponentScanExclusion.js +25 -0
  135. package/target/annotation/scan/Hotter.js +8 -0
  136. package/target/annotation/stereotype/BeanName.js +11 -0
  137. package/target/annotation/stereotype/Component.js +8 -0
  138. package/target/annotation/stereotype/Configure.js +14 -0
  139. package/target/annotation/stereotype/Controller.js +9 -0
  140. package/target/annotation/stereotype/Injection.js +12 -0
  141. package/target/annotation/stereotype/Log.js +16 -0
  142. package/target/annotation/stereotype/Repository.js +9 -0
  143. package/target/annotation/stereotype/Service.js +9 -0
  144. package/target/annotation/valid/AddChildValid.js +56 -0
  145. package/target/annotation/valid/DefaultVal.js +10 -0
  146. package/target/annotation/valid/NotNull.js +8 -0
  147. package/target/annotation/valid/Rule.js +100 -0
  148. package/target/annotation/valid/Size.js +10 -0
  149. package/target/annotation/valid/Type.js +10 -0
  150. package/target/annotation/valid/ValidCustom.js +17 -0
  151. package/target/annotation/valid/ValidForm.js +131 -0
  152. package/target/annotation.js +101 -0
  153. package/target/config/ApplicationConfig.js +2 -0
  154. package/target/config/SysConfig.js +19 -0
  155. package/target/constant/AppStatusEnum.js +9 -0
  156. package/target/constant/BootPriority.js +11 -0
  157. package/target/constant/CommonConstant.js +16 -0
  158. package/target/constant/ComponentKind.js +11 -0
  159. package/target/constant/DataTypes.js +19 -0
  160. package/target/constant/FastCarMetaData.js +29 -0
  161. package/target/constant/LifeCycleModule.js +9 -0
  162. package/target/db.js +46 -0
  163. package/target/index.js +21 -0
  164. package/target/interface/ApplicationHook.js +2 -0
  165. package/target/interface/ApplicationRunnerService.js +2 -0
  166. package/target/interface/DataSourceManager.js +2 -0
  167. package/target/interface/Logger.js +5 -0
  168. package/target/model/BaseMapper.js +98 -0
  169. package/target/model/DataMap.js +87 -0
  170. package/target/model/FormRuleModel.js +2 -0
  171. package/target/model/ValidError.js +5 -0
  172. package/target/model/WinstonLogger.js +95 -0
  173. package/target/type/ComponentDesc.js +2 -0
  174. package/target/type/DesignMeta.js +15 -0
  175. package/target/type/FileHotterDesc.js +2 -0
  176. package/target/type/MapperType.js +2 -0
  177. package/target/type/ProcessType.js +2 -0
  178. package/target/type/SqlError.js +5 -0
  179. package/target/type/WinstonLoggerType.js +9 -0
  180. package/target/utils/ClassUtils.js +35 -0
  181. package/target/utils/CryptoUtil.js +84 -0
  182. package/target/utils/DataFormat.js +84 -0
  183. package/target/utils/DateUtil.js +71 -0
  184. package/target/utils/FileUtil.js +153 -0
  185. package/target/utils/FormatStr.js +14 -0
  186. package/target/utils/Mix.js +62 -0
  187. package/target/utils/ReflectUtil.js +22 -0
  188. package/target/utils/TypeUtil.js +47 -0
  189. package/target/utils/ValidationUtil.js +118 -0
  190. package/target/utils/classLoader.js +65 -0
  191. package/target/utils.js +23 -0
  192. package/test/example/logs/app.log +0 -0
  193. package/test/example/logs/logger.log +12 -0
  194. package/test/example/logs/logger1.log +12 -0
  195. package/test/example/logs/logger2.log +12 -0
  196. package/test/example/logs/logger3.log +12 -0
  197. package/test/example/logs/logger4.log +12 -0
  198. package/test/example/logs/logger5.log +6 -0
  199. package/test/example/logs/sys.log +7 -0
  200. package/test/example/logs/sys1.log +14 -0
  201. package/test/example/logs/sys10.log +12 -0
  202. package/test/example/logs/sys11.log +5 -0
  203. package/test/example/logs/sys13.log +5 -0
  204. package/test/example/logs/sys2.log +3 -0
  205. package/test/example/logs/sys4.log +15 -0
  206. package/test/example/logs/sys5.log +9 -0
  207. package/test/example/logs/sys6.log +10 -0
  208. package/test/example/logs/sys7.log +15 -0
  209. package/test/example/logs/sys8.log +11 -0
  210. package/test/example/logs/sys9.log +10 -0
  211. package/test/example/resource/application-test.yml +0 -0
  212. package/test/example/resource/application.yml +7 -0
  213. package/test/example/resource/evnconfig-test.yml +1 -0
  214. package/test/example/resource/hello.yml +1 -0
  215. package/test/example/simple/app.ts +99 -0
  216. package/test/example/simple/component/StartRunner.ts +10 -0
  217. package/test/example/simple/component/StopRunner.ts +14 -0
  218. package/test/example/simple/config/EnvConfig.ts +6 -0
  219. package/test/example/simple/config/HelloConfig.ts +8 -0
  220. package/test/example/simple/controller/AliasController.ts +6 -0
  221. package/test/example/simple/controller/HelloController.ts +39 -0
  222. package/test/example/simple/controller/NotFoundController.ts +20 -0
  223. package/test/example/simple/service/CallService.ts +11 -0
  224. package/test/example/simple/service/HelloService.ts +10 -0
  225. package/test/example/simple/service/LogService.ts +19 -0
  226. package/test/logs/logger.log +0 -0
  227. package/test/logs/sys.log +227 -0
  228. package/test/multi/app.ts +15 -0
  229. package/test/multi/service/aService.ts +16 -0
  230. package/test/multi/service/bService.ts +18 -0
  231. package/test/multi/service/cService.ts +21 -0
  232. package/test/unit/dataMap-test.ts +48 -0
  233. package/test/unit/decorators-test.ts +38 -0
  234. package/test/unit/ds-test.ts +33 -0
  235. package/test/unit/logs/sys.log +24 -0
  236. package/test/unit/reflectMetadata-test.ts +15 -0
  237. package/test/unit/valid-test.ts +65 -0
  238. package/test/unit/winston-test.ts +15 -0
  239. package/utils.d.ts +166 -0
package/db.d.ts ADDED
@@ -0,0 +1,272 @@
1
+ export enum OperatorEnum {
2
+ eq = "=",
3
+ neq = "!=",
4
+ gt = ">",
5
+ gte = ">=",
6
+ lt = "<",
7
+ lte = "<=",
8
+ like = "LIKE",
9
+ in = "IN",
10
+ isNUll = "ISNULL",
11
+ isNotNull = "IS NOT NULL",
12
+ inc = "+", //累加
13
+ dec = "-", //累减
14
+ multiply = "*", //累乘
15
+ division = "/", //累除
16
+ }
17
+
18
+ export enum JoinEnum {
19
+ and = "AND",
20
+ or = "OR",
21
+ }
22
+
23
+ export enum OrderEnum {
24
+ asc = "ASC",
25
+ desc = "DESC",
26
+ }
27
+
28
+ export type SqlValue = number | string | number[] | string[] | boolean | boolean[] | null | Date;
29
+
30
+ //where表达式
31
+ type SqlExpression =
32
+ | {
33
+ [key: string]: { [key: string]: SqlValue };
34
+ }
35
+ | SqlValue;
36
+
37
+ export type SqlWhere = { [key: string]: SqlExpression | SqlWhere };
38
+
39
+ export type RowData = {
40
+ [key: string]: SqlValue | { operate: string; value: SqlValue };
41
+ };
42
+
43
+ export type OrderType = { [key: string]: OrderEnum };
44
+
45
+ export type SqlDelete = {
46
+ where?: SqlWhere; //查询条件
47
+ limit?: number; //限制行数
48
+ };
49
+
50
+ export type SqlQuery = {
51
+ where?: SqlWhere; //查询条件
52
+ fields?: string[]; //查询出来的元素
53
+ groups?: string[]; //分组排序
54
+ orders?: OrderType; //排序
55
+ limit?: number; //限制行数
56
+ offest?: number; //偏移量
57
+ };
58
+
59
+ export type SqlUpdate = {
60
+ where?: SqlWhere; //查询条件
61
+ row: RowData;
62
+ limit?: number; //限制行数
63
+ };
64
+
65
+ export type RowType = {
66
+ sql: string;
67
+ args: any[];
68
+ };
69
+
70
+ export interface DBMapper<T> {
71
+ /***
72
+ * @version 1.0 更新或者添加记录多条记录(一般用于整条记录的更新)
73
+ */
74
+ saveORUpdate(rows: T | T[], ds?: string, sessionId?: string): Promise<number | string>;
75
+
76
+ /***
77
+ * @version 1.0 插入单条记录返回主键
78
+ */
79
+ saveOne(row: T, ds?: string, sessionId?: string): Promise<number | string>;
80
+
81
+ /***
82
+ * @version 1.0 批量插入记录
83
+ */
84
+ saveList(rows: T[], ds?: string, sessionId?: string): Promise<boolean>;
85
+
86
+ /***
87
+ * @version 1.0 更新记录
88
+ *
89
+ */
90
+ update({ row, where, limit }: SqlUpdate, ds?: string, sessionId?: string): Promise<boolean>;
91
+
92
+ /****
93
+ * @version 1.0 更新一条数据
94
+ *
95
+ */
96
+ updateOne(sqlUpdate: SqlUpdate, ds?: string, sessionId?: string): Promise<boolean>;
97
+
98
+ /***
99
+ * @version 1.0 根据实体类的主键来更新数据
100
+ *
101
+ */
102
+ updateByPrimaryKey(row: T, ds?: string, sessionId?: string): Promise<boolean>;
103
+
104
+ /***
105
+ * @version 1.0 根据条件进行查找
106
+ */
107
+ select(conditions: SqlQuery, ds?: string, sessionId?: string): Promise<T[]>;
108
+
109
+ /***
110
+ * @version 1.0 查询单个对象
111
+ *
112
+ */
113
+ selectOne(conditions?: SqlQuery, ds?: string, sessionId?: string): Promise<T | null>;
114
+
115
+ /***
116
+ * @version 1.0 通过主键查找对象
117
+ *
118
+ */
119
+ selectByPrimaryKey(row: T, ds?: string, sessionId?: string): Promise<T | null>;
120
+
121
+ /***
122
+ * @version 1.0 判定是否存在
123
+ *
124
+ */
125
+ exist(where: SqlWhere, ds?: string, sessionId?: string): Promise<boolean>;
126
+
127
+ /***
128
+ * @version 1.0 统计符合条件的记录
129
+ */
130
+ count(where: SqlWhere, ds?: string, sessionId?: string): Promise<number>;
131
+
132
+ /***
133
+ * @version 1.0 按照条件删除记录
134
+ */
135
+ delete(conditions: SqlDelete, ds?: string, sessionId?: string): Promise<boolean>;
136
+
137
+ /***
138
+ * @version 1.0 删除某条记录
139
+ */
140
+ deleteOne(where: SqlWhere, ds?: string, sessionId?: string): Promise<boolean>;
141
+
142
+ /***
143
+ * @version 1.0 删除某条记录根据主键
144
+ */
145
+ deleteByPrimaryKey(row: T, ds?: string, sessionId?: string): Promise<boolean>;
146
+ }
147
+
148
+ export class BaseMapper<T extends Object> implements DBMapper<T> {
149
+ protected tableName: string;
150
+ protected classZ: any; //映射的原型类
151
+ protected mappingMap: Map<string, MapperType>; //代码别名-映射关系
152
+ protected mappingList: MapperType[];
153
+ protected dbFields: Map<string, string>; //数据库别名-代码别名
154
+
155
+ protected getFieldName(name: string): string;
156
+
157
+ //格式化数据库数据转化为程序设计内的
158
+ protected setRow(rowData: Object): T;
159
+
160
+ protected setRows(rowDataList: Object[]): T[];
161
+
162
+ /***
163
+ * @version 1.0 更新或者添加记录多条记录(一般用于整条记录的更新)
164
+ */
165
+ saveORUpdate(rows: T | T[], ds?: string, sessionId?: string): Promise<number | string>;
166
+
167
+ /***
168
+ * @version 1.0 插入单条记录返回主键
169
+ */
170
+ saveOne(row: T, ds?: string, sessionId?: string): Promise<number | string>;
171
+
172
+ /***
173
+ * @version 1.0 批量插入记录
174
+ */
175
+ saveList(rows: T[], ds?: string, sessionId?: string): Promise<boolean>;
176
+
177
+ /***
178
+ * @version 1.0 更新记录
179
+ *
180
+ */
181
+ update({ row, where, limit }: SqlUpdate, ds?: string, sessionId?: string): Promise<boolean>;
182
+
183
+ /****
184
+ * @version 1.0 更新一条数据
185
+ *
186
+ */
187
+ updateOne(sqlUpdate: SqlUpdate, ds?: string, sessionId?: string): Promise<boolean>;
188
+
189
+ /***
190
+ * @version 1.0 根据实体类的主键来更新数据
191
+ *
192
+ */
193
+ updateByPrimaryKey(row: T, ds?: string, sessionId?: string): Promise<boolean>;
194
+
195
+ /***
196
+ * @version 1.0 根据条件进行查找
197
+ */
198
+ select(conditions: SqlQuery, ds?: string, sessionId?: string): Promise<T[]>;
199
+
200
+ /***
201
+ * @version 1.0 查询单个对象
202
+ *
203
+ */
204
+ selectOne(conditions?: SqlQuery, ds?: string, sessionId?: string): Promise<T | null>;
205
+
206
+ /***
207
+ * @version 1.0 通过主键查找对象
208
+ *
209
+ */
210
+ selectByPrimaryKey(row: T, ds?: string, sessionId?: string): Promise<T | null>;
211
+
212
+ /***
213
+ * @version 1.0 判定是否存在
214
+ *
215
+ */
216
+ exist(where: SqlWhere, ds?: string, sessionId?: string): Promise<boolean>;
217
+
218
+ /***
219
+ * @version 1.0 统计符合条件的记录
220
+ */
221
+ count(where: SqlWhere, ds?: string, sessionId?: string): Promise<number>;
222
+
223
+ /***
224
+ * @version 1.0 按照条件删除记录
225
+ */
226
+ delete(conditions: SqlDelete, ds?: string, sessionId?: string): Promise<boolean>;
227
+
228
+ /***
229
+ * @version 1.0 删除某条记录
230
+ */
231
+ deleteOne(where: SqlWhere, ds?: string, sessionId?: string): Promise<boolean>;
232
+
233
+ /***
234
+ * @version 1.0 删除某条记录根据主键
235
+ */
236
+ deleteByPrimaryKey(row: T, ds?: string, sessionId?: string): Promise<boolean>;
237
+ }
238
+
239
+ export type MapperType = {
240
+ name: string; //量变名称
241
+ type: string; //类型
242
+ field: string; //数据库列名
243
+ dbType: string; //数据类型
244
+ primaryKey?: boolean; //是否为主键 默认为false
245
+ serialize?: Function; //序列化对象方法
246
+ };
247
+
248
+ export enum DesignMeta {
249
+ table = "db:table", //表名
250
+ field = "db:field", //列名
251
+ fieldMap = "db:fieldMap", //注入列名集合
252
+ dbType = "db:dbType", //数据类型
253
+ primaryKey = "db:primaryKey", //主键类型
254
+ entity = "db:entity", //实例化的数据库类
255
+ mapping = "db:mapping", //映射描述
256
+ dbFields = "db:fields", //数据库名-ts名
257
+ sqlSession = "SqlSession", //sql会话
258
+ }
259
+
260
+ export interface DataSourceManager {
261
+ createSession(): string;
262
+
263
+ destorySession(sessionId: string, status: boolean): void;
264
+
265
+ destorySession(sessionId: string, status: boolean): Promise<void>;
266
+
267
+ start(): void;
268
+
269
+ stop(): void;
270
+ }
271
+
272
+ export class SqlError extends Error {}
package/index.d.ts ADDED
@@ -0,0 +1,262 @@
1
+ import * as Events from "events";
2
+ import { ApplicationConfig } from "./src/config/ApplicationConfig";
3
+ import { ComponentKind } from "./src/constant/ComponentKind";
4
+ import { LifeCycleModule } from "./src/constant/LifeCycleModule";
5
+ import { FIELDTYPE } from "./src/model/DataMap";
6
+ import { ProcessType } from "./src/type/ProcessType";
7
+
8
+ declare type ComponentDesc = {
9
+ id: string;
10
+ name: string;
11
+ path: string;
12
+ };
13
+
14
+ export * from "./src/config/SysConfig";
15
+
16
+ export * from "./src/config/ApplicationConfig";
17
+
18
+ export * from "./src/constant/LifeCycleModule";
19
+
20
+ export * from "./src/constant/ComponentKind";
21
+
22
+ export * from "./src/constant/BootPriority";
23
+
24
+ //元数据加载模块
25
+ export * from "./src/constant/FastCarMetaData";
26
+
27
+ //自定义常量模块
28
+ export * from "./src/constant/CommonConstant";
29
+
30
+ //生命周期约定
31
+ export * from "./src/interface/ApplicationHook";
32
+
33
+ export { FIELDTYPE } from "./src/model/DataMap";
34
+
35
+ export abstract class Logger {
36
+ abstract info(...args: any[]): void;
37
+
38
+ abstract debug(...args: any[]): void;
39
+
40
+ abstract warn(...args: any[]): void;
41
+
42
+ abstract error(...args: any[]): void;
43
+ }
44
+
45
+ export class FastCarApplication extends Events {
46
+ /***
47
+ * @version 1.0 根据原型加载注入的方法
48
+ *
49
+ */
50
+ getInjectionUniqueKey(target: Object): string;
51
+
52
+ /**
53
+ * @version 1.0 自身作为一个组件注入进去
54
+ */
55
+ loadSelf(): void;
56
+
57
+ /***
58
+ * @version 1.0 热更新组件
59
+ */
60
+ addHot(): void;
61
+
62
+ /**
63
+ * @version 1.0 获取资源路径
64
+ */
65
+ getResourcePath(): string;
66
+
67
+ /***
68
+ * @version 1.0 获取项目的基本路径
69
+ *
70
+ */
71
+ getBasePath(): string;
72
+
73
+ /**
74
+ * @version 1.0 加载系统配置 加载顺序为 default json < yaml < env
75
+ *
76
+ */
77
+ loadSysConfig(): void;
78
+
79
+ setSetting(key: string | symbol, value: any): void;
80
+
81
+ /**
82
+ * @version 1.0 获取自定义设置 设置优先级 配置自定义>系统配置>初始化
83
+ * @param key
84
+ */
85
+ getSetting(key: string | symbol): any;
86
+
87
+ /**
88
+ * @version 1.0 获取应用配置
89
+ * @return
90
+ */
91
+ getapplicationConfig(): ApplicationConfig;
92
+
93
+ /**
94
+ * @version 1.0 扫描组件
95
+ */
96
+ loadClass(): void;
97
+
98
+ /***
99
+ * @version 1.0 装配单个模块
100
+ * @deprecated 修改为主动查找时装配
101
+ */
102
+ injectionModule(instance: any, instanceName: string | symbol): void;
103
+
104
+ /***
105
+ * @version 1.0 根据名称获取组件的加载情况
106
+ *
107
+ */
108
+ getComponentDetailByName(name: string | symbol): ComponentDesc | undefined;
109
+
110
+ /***
111
+ * @version 1.0 根据原型获取组件的加载信息
112
+ *
113
+ */
114
+ getComponentDetailByTarget(target: Object): ComponentDesc | undefined;
115
+
116
+ /**
117
+ * @version 1.0 加载需要注入的类
118
+ * @deprecated 修改为主动查找时装配
119
+ */
120
+ loadInjectionModule(): void;
121
+
122
+ /**
123
+ * @version 1.0 根据类型获取组件
124
+ * @param name
125
+ * @return
126
+ */
127
+ getComponentByType(name: ComponentKind): any[];
128
+
129
+ /**
130
+ * @version 1.0 获取全部的组件列表
131
+ * @return
132
+ */
133
+ getComponentList(): any[];
134
+
135
+ /**
136
+ * @version 1.0 根据名称组件
137
+ * @param name
138
+ */
139
+ getComponentByName(name: string | symbol): any;
140
+
141
+ /***
142
+ * @version 1.0 根据原型获取实例
143
+ */
144
+ getComponentByTarget(target: Object): any;
145
+
146
+ /**
147
+ * @version 1.0 获取组件详情列表
148
+ *
149
+ */
150
+ getComponentDetailsList(): ComponentDesc[];
151
+
152
+ /**
153
+ * @version 1.0 开启日志系统
154
+ */
155
+ startLog(): void;
156
+
157
+ /**
158
+ * @version 1.0 初始化应用
159
+ */
160
+ init(): void;
161
+
162
+ /***
163
+ * @version 1.0 退出事件监听
164
+ *
165
+ */
166
+ addExitEvent(): void;
167
+
168
+ /***
169
+ * @version 1.0 异常事件进行监听 不至于程序异常直接退出
170
+ */
171
+ addExecptionEvent(): void;
172
+
173
+ /**
174
+ * @version 1.0 自动调用方法
175
+ * @param name
176
+ */
177
+ automaticRun(name: LifeCycleModule): void;
178
+
179
+ /**
180
+ * @version 1.0 开启应用前执行的操作 加载配置,扫描组件,注入依赖组件
181
+ */
182
+ beforeStartServer(): void;
183
+
184
+ /**
185
+ * @version 1.0 启动服务
186
+ */
187
+ startServer(): void;
188
+
189
+ /**
190
+ * @version 1.0 停止服务前自动调用服务
191
+ */
192
+ beforeStopServer(): void;
193
+
194
+ /**
195
+ * @version 1.0 停止服务
196
+ */
197
+ stopServer(): void;
198
+
199
+ /**
200
+ * @version 1.0 获取app名称
201
+ */
202
+ getApplicationName(): string;
203
+
204
+ /***
205
+ * @version 1.0 获取系统日志
206
+ *
207
+ */
208
+ getSysLogger(): Logger;
209
+
210
+ /***
211
+ * @version 0.2.11 根据名称获取logger
212
+ *
213
+ */
214
+ getLogger(category?: string): Logger;
215
+
216
+ /***
217
+ * @version 1.0 获取文件内容
218
+ */
219
+ getFileContent(fp: string): string;
220
+
221
+ /***
222
+ * @version 1.0 是否支持热更
223
+ *
224
+ */
225
+ isHotter(): boolean;
226
+
227
+ /**
228
+ * @version 1.0 指定热更新文件
229
+ *
230
+ */
231
+ specifyHotUpdate(fp: string): void;
232
+
233
+ /***
234
+ * @version 1.0 获取进程的信息
235
+ *
236
+ */
237
+ getMemoryUsage(): ProcessType;
238
+ }
239
+
240
+ //校验错误
241
+ export class ValidError {
242
+ message?: string;
243
+ }
244
+
245
+ export class DataMap<K, V extends Object> extends Map<K, V> {
246
+ toValues(): V[];
247
+
248
+ toKeys(): K[];
249
+
250
+ //构造一个字典对象
251
+ toObject(): { [key: string]: V };
252
+
253
+ //自定义排序 支持多个排序
254
+ sort(sorts?: FIELDTYPE[], list?: V[]): V[];
255
+
256
+ /***
257
+ * @version 1.0 查找属性名称
258
+ * @params atts代表属性键值对匹配
259
+ *
260
+ */
261
+ findByAtts(atts: { [key: string]: any }): V[];
262
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@fastcar/core",
3
+ "version": "0.2.38",
4
+ "homepage": "https://github.com/williamDazhangyu/fast-car",
5
+ "main": "target/index.js",
6
+ "author": "william_zhong",
7
+ "license": "MIT",
8
+ "types": "index.d.ts",
9
+ "exports": {
10
+ ".": "./target/index.js",
11
+ "./annotation": "./target/annotation.js",
12
+ "./utils": "./target/utils.js",
13
+ "./db": "./target/db.js"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "target",
18
+ "test",
19
+ "index.d.ts",
20
+ "annotation.d.ts",
21
+ "db.d.ts",
22
+ "utils.d.ts",
23
+ "LICENSE"
24
+ ],
25
+ "keywords": [
26
+ "ioc",
27
+ "spring",
28
+ "node",
29
+ "fastcar-core"
30
+ ],
31
+ "engines": {
32
+ "node": ">=16"
33
+ },
34
+ "dependencies": {
35
+ "reflect-metadata": "^0.1.13",
36
+ "winston": "^3.6.0",
37
+ "yaml": "^1.10.2"
38
+ },
39
+ "devDependencies": {
40
+ "@types/mocha": "^9.0.0",
41
+ "@types/node": "^16.11.7",
42
+ "@types/reflect-metadata": "^0.1.0",
43
+ "@types/yaml": "^1.9.7",
44
+ "typescript": "^4.4.2"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/williamDazhangyu/fast-car.git"
49
+ },
50
+ "scripts": {
51
+ "build": "tsc"
52
+ }
53
+ }