@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
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /***
4
+ * @version 1.0 数据格式处理
5
+ */
6
+ class DataFormat {
7
+ static formatNumber(value, type) {
8
+ if (type === "int") {
9
+ return parseInt(value);
10
+ }
11
+ if (type === "float" || type == "number") {
12
+ return parseFloat(value);
13
+ }
14
+ return null;
15
+ }
16
+ static formatString(value) {
17
+ if (typeof value != "string") {
18
+ if (typeof value == "number") {
19
+ return value + "";
20
+ }
21
+ if (typeof value == "object") {
22
+ if (Reflect.has(value, "toString")) {
23
+ return value.toString();
24
+ }
25
+ }
26
+ return null;
27
+ }
28
+ return value;
29
+ }
30
+ static formatBoolean(value) {
31
+ if (typeof value == "string") {
32
+ if (value == "false") {
33
+ return false;
34
+ }
35
+ }
36
+ return !!value;
37
+ }
38
+ static formatArray(value, type) {
39
+ if (type.startsWith("array")) {
40
+ if (typeof value === "string") {
41
+ value = JSON.parse(value);
42
+ }
43
+ if (Array.isArray(value)) {
44
+ let ntype = type.replace(/array/, "");
45
+ value = value.map((item) => {
46
+ return DataFormat.formatValue(item, ntype);
47
+ });
48
+ return value;
49
+ }
50
+ }
51
+ return [];
52
+ }
53
+ static formatDate(value) {
54
+ if (value instanceof Date) {
55
+ return value;
56
+ }
57
+ return new Date(value);
58
+ }
59
+ static formatValue(value, type) {
60
+ if (type.startsWith("array")) {
61
+ return DataFormat.formatArray(value, type);
62
+ }
63
+ switch (type) {
64
+ case "string": {
65
+ return DataFormat.formatString(value);
66
+ }
67
+ case "boolean": {
68
+ return DataFormat.formatBoolean(value);
69
+ }
70
+ case "int":
71
+ case "float":
72
+ case "number": {
73
+ return DataFormat.formatNumber(value, type);
74
+ }
75
+ case "date": {
76
+ return DataFormat.formatDate(value);
77
+ }
78
+ default: {
79
+ return value;
80
+ }
81
+ }
82
+ }
83
+ }
84
+ exports.default = DataFormat;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class DateUtil {
4
+ static twoDigits(num) {
5
+ return num.toString().padStart(2, "0");
6
+ }
7
+ //返回年月日时分秒
8
+ static toDateDesc(datetime = Date.now()) {
9
+ let dataC = new Date(datetime);
10
+ return {
11
+ YYYY: DateUtil.twoDigits(dataC.getFullYear()),
12
+ MM: DateUtil.twoDigits(dataC.getMonth() + 1),
13
+ DD: DateUtil.twoDigits(dataC.getDate()),
14
+ hh: DateUtil.twoDigits(dataC.getHours()),
15
+ mm: DateUtil.twoDigits(dataC.getMinutes()),
16
+ ss: DateUtil.twoDigits(dataC.getSeconds()),
17
+ ms: DateUtil.twoDigits(dataC.getMilliseconds()),
18
+ };
19
+ }
20
+ static toDay(datetime = Date.now(), format = "YYYY-MM-DD") {
21
+ let desc = DateUtil.toDateDesc(datetime);
22
+ let ymd = format.replace(/YYYY/, desc.YYYY).replace(/MM/, desc.MM).replace(/DD/, desc.DD);
23
+ return ymd;
24
+ }
25
+ static toHms(datetime = Date.now(), format = "hh:mm:ss") {
26
+ let desc = DateUtil.toDateDesc(datetime);
27
+ let hms = format.replace(/hh/, desc.hh).replace(/mm/, desc.mm).replace(/ss/, desc.ss);
28
+ return hms;
29
+ }
30
+ static toDateTime(datetime = Date.now(), format = "YYYY-MM-DD hh:mm:ss") {
31
+ let desc = DateUtil.toDateDesc(datetime);
32
+ let str = format.replace(/YYYY/, desc.YYYY).replace(/MM/, desc.MM).replace(/DD/, desc.DD).replace(/hh/, desc.hh).replace(/mm/, desc.mm).replace(/ss/, desc.ss);
33
+ return str;
34
+ }
35
+ static toDateTimeMS(datetime = Date.now(), format = "YYYY-MM-DD hh:mm:ss.sss") {
36
+ let desc = DateUtil.toDateDesc(datetime);
37
+ let str = format.replace(/YYYY/, desc.YYYY).replace(/MM/, desc.MM).replace(/DD/, desc.DD).replace(/hh/, desc.hh).replace(/mm/, desc.mm).replace(/ss/, desc.ss).replace(/sss/, desc.ms);
38
+ return str;
39
+ }
40
+ static toCutDown(datetime, format = "hh:mm:ss") {
41
+ let hours = Math.floor(datetime / 60 / 60);
42
+ let minutes = Math.floor((datetime - hours * 60 * 60) / 60);
43
+ let seconds = datetime - (hours * 60 + minutes) * 60;
44
+ let str = format.replace(/hh/, hours.toString()).replace(/mm/, minutes.toString()).replace(/ss/, seconds.toString());
45
+ return str;
46
+ }
47
+ static getTimeStr(datetime) {
48
+ let days = datetime / (1000 * 60 * 60 * 24);
49
+ if (days >= 1) {
50
+ return `${days.toFixed(2)}d`;
51
+ }
52
+ let hours = datetime / (1000 * 60 * 60);
53
+ if (hours >= 1) {
54
+ return `${hours.toFixed(2)}h`;
55
+ }
56
+ let minutes = datetime / (1000 * 60);
57
+ if (minutes >= 1) {
58
+ return `${minutes.toFixed(2)}m`;
59
+ }
60
+ let seconds = datetime / 1000;
61
+ return `${Math.floor(seconds)}s`;
62
+ }
63
+ static getDateTime(datetimeStr) {
64
+ if (datetimeStr) {
65
+ let dataC = new Date(datetimeStr);
66
+ return dataC.getTime();
67
+ }
68
+ return Date.now();
69
+ }
70
+ }
71
+ exports.default = DateUtil;
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const yaml = require("yaml");
6
+ const SysConfig_1 = require("../config/SysConfig");
7
+ const CommonConstant_1 = require("../constant/CommonConstant");
8
+ const Mix_1 = require("./Mix");
9
+ const fileResSuffix = ["json", "yml", "js"]; //文件资源后缀名
10
+ const bytesUnit = ["B", "K", "M", "G"];
11
+ class FileUtil {
12
+ /***
13
+ * @version 1.0 获取文件路径
14
+ *
15
+ */
16
+ static getFilePathList(filePath) {
17
+ let pathList = Array.of();
18
+ let existFlag = fs.existsSync(filePath);
19
+ if (!existFlag) {
20
+ return pathList;
21
+ }
22
+ let currStats = fs.statSync(filePath);
23
+ let cfile = currStats.isFile();
24
+ let cdir = currStats.isDirectory();
25
+ if (!cdir && !cfile) {
26
+ return pathList;
27
+ }
28
+ if (cfile) {
29
+ pathList.push(filePath);
30
+ return pathList;
31
+ }
32
+ let childPaths = fs.readdirSync(filePath);
33
+ for (let c of childPaths) {
34
+ let fullPath = path.join(filePath, c);
35
+ let tmpStats = fs.statSync(fullPath);
36
+ if (tmpStats.isDirectory()) {
37
+ let childPaths = FileUtil.getFilePathList(fullPath);
38
+ if (childPaths.length > 0) {
39
+ pathList = [...pathList, ...childPaths];
40
+ }
41
+ }
42
+ else if (tmpStats.isFile()) {
43
+ pathList.push(fullPath);
44
+ }
45
+ }
46
+ return pathList;
47
+ }
48
+ /***
49
+ * @version 1.0 获取后缀名
50
+ *
51
+ */
52
+ static getSuffix(filePath) {
53
+ let lastIndex = filePath.lastIndexOf(".") + 1;
54
+ if (lastIndex <= 0) {
55
+ return "";
56
+ }
57
+ let suffix = filePath.substring(lastIndex);
58
+ return suffix;
59
+ }
60
+ /***
61
+ * @version 1.0 获取文件的文件名
62
+ */
63
+ static getFileName(filePath) {
64
+ let pList = filePath.split(path.sep);
65
+ let lastPath = pList[pList.length - 1];
66
+ let lastName = lastPath.split(".");
67
+ return lastName[0];
68
+ }
69
+ //加载配置文件
70
+ static getResource(fp) {
71
+ let currSuffix = FileUtil.getSuffix(fp);
72
+ if (!fileResSuffix.includes(currSuffix)) {
73
+ return null;
74
+ }
75
+ if (fs.existsSync(fp)) {
76
+ let currStats = fs.statSync(fp);
77
+ if (currStats.isFile()) {
78
+ //进行解析
79
+ let content = fs.readFileSync(fp, "utf-8");
80
+ switch (currSuffix) {
81
+ case "yml": {
82
+ return yaml.parse(content);
83
+ }
84
+ case "json": {
85
+ return JSON.parse(content);
86
+ }
87
+ case "js":
88
+ case "ts": {
89
+ if (Reflect.has(require.cache, fp)) {
90
+ Reflect.deleteProperty(require.cache, fp);
91
+ }
92
+ return require(fp);
93
+ }
94
+ default: {
95
+ return null;
96
+ }
97
+ }
98
+ }
99
+ }
100
+ return null;
101
+ }
102
+ //格式化字节大小
103
+ static formatBytes(n) {
104
+ for (let i = 0; i < bytesUnit.length; i++) {
105
+ let nn = n / Math.pow(1024, i);
106
+ if (nn <= 1024) {
107
+ return `${nn.toFixed(2)}(${bytesUnit[i]})`;
108
+ }
109
+ }
110
+ let maxL = bytesUnit.length - 1;
111
+ return `${(n / Math.pow(1024, maxL)).toFixed(2)}(${bytesUnit[maxL]})`;
112
+ }
113
+ //获取加载配置项
114
+ static getApplicationConfig(resPath, configName, sysConfig = SysConfig_1.SYSDefaultConfig) {
115
+ const replaceSetting = (property, fileContent) => {
116
+ let addConfig = Reflect.get(fileContent, property);
117
+ if (addConfig) {
118
+ let currConfig = Reflect.get(sysConfig, property);
119
+ Reflect.deleteProperty(fileContent, property);
120
+ if (CommonConstant_1.CommonConstant.Settings == property) {
121
+ Object.keys(addConfig).forEach((key) => {
122
+ let afterConfig = addConfig[key];
123
+ let beforeConfig = sysConfig.settings.get(key);
124
+ if (beforeConfig) {
125
+ //对settings的属性进行覆盖
126
+ if (typeof beforeConfig == "object") {
127
+ afterConfig = Object.assign(beforeConfig, afterConfig);
128
+ }
129
+ }
130
+ sysConfig.settings.set(key, afterConfig);
131
+ });
132
+ }
133
+ else {
134
+ Object.assign(currConfig, addConfig);
135
+ }
136
+ }
137
+ };
138
+ CommonConstant_1.FileResSuffix.forEach((suffix) => {
139
+ let fileContent = FileUtil.getResource(path.join(resPath, `${configName}.${suffix}`));
140
+ if (fileContent) {
141
+ replaceSetting(CommonConstant_1.CommonConstant.Settings, fileContent);
142
+ replaceSetting(CommonConstant_1.CommonConstant.Application, fileContent);
143
+ //将application和sesstings进行删除
144
+ Reflect.deleteProperty(fileContent, CommonConstant_1.CommonConstant.Application);
145
+ Reflect.deleteProperty(fileContent, CommonConstant_1.CommonConstant.Settings);
146
+ //追加自定的属性
147
+ Mix_1.default.copyProperties(sysConfig, fileContent);
148
+ }
149
+ });
150
+ return sysConfig;
151
+ }
152
+ }
153
+ exports.default = FileUtil;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class FormatStr {
4
+ static formatFirstToUp(str) {
5
+ return str.charAt(0).toUpperCase() + str.substring(1);
6
+ }
7
+ static formatFirstToLow(str) {
8
+ return str.charAt(0).toLowerCase() + str.substring(1);
9
+ }
10
+ static formatFirstToUpEnd(str) {
11
+ return str.charAt(0).toUpperCase() + str.substring(1).toLowerCase();
12
+ }
13
+ }
14
+ exports.default = FormatStr;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ClassUtils_1 = require("./ClassUtils");
4
+ const BASETYPE = ["constructor", "prototype", "name"];
5
+ /***
6
+ * @version 1.0 混合多个类
7
+ *
8
+ */
9
+ class MixTool {
10
+ static mix(...mixins) {
11
+ class Mix {
12
+ constructor() {
13
+ for (let mixin of mixins) {
14
+ MixTool.copyProperties(this, new mixin()); // 拷贝实例属性
15
+ }
16
+ }
17
+ }
18
+ for (let mixin of mixins) {
19
+ MixTool.copyProperties(Mix, mixin); // 拷贝静态属性
20
+ MixTool.copyProperties(Mix.prototype, mixin.prototype); // 拷贝原型属性
21
+ }
22
+ return Mix;
23
+ }
24
+ static copyProperties(target, source) {
25
+ let keys = Reflect.ownKeys(source);
26
+ for (let key of keys) {
27
+ if (!BASETYPE.includes(key.toString())) {
28
+ let desc = Object.getOwnPropertyDescriptor(source, key);
29
+ if (desc) {
30
+ Object.defineProperty(target, key, desc);
31
+ }
32
+ }
33
+ }
34
+ }
35
+ //仅仅改变属性的值
36
+ static copPropertyValue(target, source) {
37
+ let keys = Reflect.ownKeys(source);
38
+ for (let key of keys) {
39
+ if (!BASETYPE.includes(key.toString())) {
40
+ let desc = Reflect.getOwnPropertyDescriptor(source, key);
41
+ if (!!desc) {
42
+ Reflect.defineProperty(target, key, desc);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ //多个对象赋值
48
+ static assign(target, source) {
49
+ Object.assign(target, source);
50
+ let keys = ClassUtils_1.default.getProtoType(source);
51
+ keys.forEach((key) => {
52
+ let keyStr = key.toString();
53
+ if (!BASETYPE.includes(keyStr)) {
54
+ let desc = Object.getOwnPropertyDescriptor(source?.prototype, key);
55
+ if (desc) {
56
+ Reflect.defineProperty(target, key, desc);
57
+ }
58
+ }
59
+ });
60
+ }
61
+ }
62
+ exports.default = MixTool;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const FastCarMetaData_1 = require("../constant/FastCarMetaData");
4
+ const FormatStr_1 = require("./FormatStr");
5
+ const SpecWords = ["Boolean", "Number", "String", "Object"];
6
+ class ReflectUtil {
7
+ static getNameByPropertyKey(target, propertyKey) {
8
+ const designType = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.designType, target, propertyKey);
9
+ let key = "";
10
+ let name = "";
11
+ if (designType) {
12
+ name = designType.name;
13
+ key = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.InjectionUniqueKey, designType); //放入至原型中
14
+ }
15
+ //获取不到注入的值时默认为别名的值
16
+ if (!name || SpecWords.includes(name)) {
17
+ key = FormatStr_1.default.formatFirstToUp(propertyKey);
18
+ }
19
+ return key;
20
+ }
21
+ }
22
+ exports.default = ReflectUtil;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const FileUtil_1 = require("./FileUtil");
4
+ const BasicTypes = ["boolean", "number", "string"];
5
+ class TypeUtil {
6
+ static isFunction(f) {
7
+ let typeName = typeof f;
8
+ return typeName == "function";
9
+ }
10
+ static isClass(f) {
11
+ if (f.prototype === undefined) {
12
+ return false;
13
+ }
14
+ if (!f.prototype.constructor) {
15
+ return false;
16
+ }
17
+ return TypeUtil.isFunction(f);
18
+ }
19
+ static isString(str) {
20
+ let typeName = typeof str;
21
+ return typeName == "string";
22
+ }
23
+ static isObject(f) {
24
+ let typeName = typeof f;
25
+ return typeName == "object";
26
+ }
27
+ //忽略.d.ts文件
28
+ static isTSORJS(fp) {
29
+ let suffix = FileUtil_1.default.getSuffix(fp);
30
+ return ["ts", "js"].includes(suffix) && !fp.endsWith(".d.ts");
31
+ }
32
+ static isPromise(f) {
33
+ return f.constructor.name === "AsyncFunction";
34
+ }
35
+ static isArray(value) {
36
+ return Array.isArray(value);
37
+ }
38
+ static isDate(value) {
39
+ return value instanceof Date;
40
+ }
41
+ //是否为基本类型
42
+ static isBasic(name) {
43
+ let fname = name.toLowerCase();
44
+ return BasicTypes.includes(fname);
45
+ }
46
+ }
47
+ exports.default = TypeUtil;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const TypeUtil_1 = require("./TypeUtil");
4
+ //类型校验器
5
+ class ValidationUtil {
6
+ //是否为空
7
+ static isNotNull(param) {
8
+ if (param != undefined && param != null) {
9
+ if (TypeUtil_1.default.isString(param)) {
10
+ return param.length > 0;
11
+ }
12
+ if (TypeUtil_1.default.isObject(param)) {
13
+ if (TypeUtil_1.default.isDate(param)) {
14
+ return true;
15
+ }
16
+ return Reflect.ownKeys(param).length > 0;
17
+ }
18
+ return true;
19
+ }
20
+ else {
21
+ return false;
22
+ }
23
+ }
24
+ static isNull(param) {
25
+ return !ValidationUtil.isNotNull(param);
26
+ }
27
+ static isNumber(param) {
28
+ return typeof param === "number" && !isNaN(param);
29
+ }
30
+ static isString(param) {
31
+ return typeof param === "string";
32
+ }
33
+ static isBoolean(param) {
34
+ return typeof param === "boolean";
35
+ }
36
+ static isDate(param) {
37
+ return param instanceof Date;
38
+ }
39
+ static isObject(param) {
40
+ return typeof param == "object";
41
+ }
42
+ // poaram >= value
43
+ static isNotMinSize(param, value) {
44
+ if (ValidationUtil.isString(param)) {
45
+ return param.length >= value;
46
+ }
47
+ if (ValidationUtil.isNumber(param)) {
48
+ return param >= value;
49
+ }
50
+ if (ValidationUtil.isBoolean(param)) {
51
+ return true;
52
+ }
53
+ let v = ValidationUtil.isNotNull(param) ? param.toString() : "";
54
+ return v.length >= value;
55
+ }
56
+ static isNotMaxSize(param, value) {
57
+ return !ValidationUtil.isNotMinSize(param, value + 1);
58
+ }
59
+ static isArray(param, type) {
60
+ if (!Array.isArray(param)) {
61
+ return false;
62
+ }
63
+ //修正校验数组的错误
64
+ if (type.startsWith("array")) {
65
+ type = type.replace(/array/, "");
66
+ }
67
+ let checkFun = this.getCheckFun(type);
68
+ if (checkFun) {
69
+ return param.every((item) => {
70
+ return Reflect.apply(checkFun, ValidationUtil, [item]);
71
+ });
72
+ }
73
+ return true;
74
+ }
75
+ static getCheckFun(type) {
76
+ //判定类型
77
+ if (type.startsWith("array")) {
78
+ return ValidationUtil.isArray;
79
+ }
80
+ let formatFun = null;
81
+ switch (type) {
82
+ case "string": {
83
+ formatFun = ValidationUtil.isString;
84
+ break;
85
+ }
86
+ case "boolean": {
87
+ formatFun = ValidationUtil.isBoolean;
88
+ break;
89
+ }
90
+ case "object": {
91
+ formatFun = ValidationUtil.isObject;
92
+ break;
93
+ }
94
+ case "int":
95
+ case "float":
96
+ case "number": {
97
+ formatFun = ValidationUtil.isNumber;
98
+ break;
99
+ }
100
+ case "date": {
101
+ formatFun = ValidationUtil.isDate;
102
+ break;
103
+ }
104
+ default: {
105
+ break;
106
+ }
107
+ }
108
+ return formatFun;
109
+ }
110
+ static checkType(param, type) {
111
+ let formatFun = ValidationUtil.getCheckFun(type);
112
+ if (!formatFun) {
113
+ return false;
114
+ }
115
+ return Reflect.apply(formatFun, ValidationUtil, [param, type]);
116
+ }
117
+ }
118
+ exports.default = ValidationUtil;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const TypeUtil_1 = require("./TypeUtil");
4
+ const FileUtil_1 = require("./FileUtil");
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+ class ClassLoader {
8
+ /***
9
+ * @version 1.0 加载模块
10
+ * @version 1.1 新增是否强制重载模块
11
+ *
12
+ */
13
+ static loadModule(filePath, force = false) {
14
+ //校验后缀名是否为js或者ts
15
+ if (!TypeUtil_1.default.isTSORJS(filePath)) {
16
+ return null;
17
+ }
18
+ //避免重复加载或者想要重新进行挂载
19
+ if (Reflect.has(require.cache, filePath)) {
20
+ if (force) {
21
+ Reflect.deleteProperty(require.cache, filePath);
22
+ }
23
+ }
24
+ //可能不止一个方法
25
+ const modulesMap = new Map();
26
+ //进行方法加载
27
+ let moduleClass = require(filePath);
28
+ let keys = Object.keys(moduleClass);
29
+ let fileName = FileUtil_1.default.getFileName(filePath);
30
+ keys.forEach((key) => {
31
+ let instance = moduleClass[key];
32
+ if (TypeUtil_1.default.isFunction(instance)) {
33
+ modulesMap.set(instance.name, instance);
34
+ return;
35
+ }
36
+ if (TypeUtil_1.default.isObject(instance)) {
37
+ modulesMap.set(fileName, instance);
38
+ }
39
+ });
40
+ return modulesMap;
41
+ }
42
+ /**
43
+ * @version 1.0 监听某个文件或者文件夹
44
+ */
45
+ static watchServices(fp, context, eventName = "reload") {
46
+ if (typeof context.emit != "function") {
47
+ return false;
48
+ }
49
+ const currStats = fs.statSync(fp);
50
+ let fileFlag = currStats.isFile();
51
+ //添加热更方法
52
+ fs.watch(fp, function (event, filename) {
53
+ if (event === "change") {
54
+ if (!fileFlag) {
55
+ context.emit(eventName, path.join(fp, filename));
56
+ }
57
+ else {
58
+ context.emit(eventName, fp);
59
+ }
60
+ }
61
+ });
62
+ return true;
63
+ }
64
+ }
65
+ exports.default = ClassLoader;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MixTool = exports.ClassLoader = exports.ClassUtils = exports.FormatStr = exports.ValidationUtil = exports.TypeUtil = exports.FileUtil = exports.CryptoUtil = exports.DataFormat = exports.DateUtil = void 0;
4
+ const classLoader_1 = require("./utils/classLoader");
5
+ exports.ClassLoader = classLoader_1.default;
6
+ const ClassUtils_1 = require("./utils/ClassUtils");
7
+ exports.ClassUtils = ClassUtils_1.default;
8
+ const CryptoUtil_1 = require("./utils/CryptoUtil");
9
+ exports.CryptoUtil = CryptoUtil_1.default;
10
+ const DataFormat_1 = require("./utils/DataFormat");
11
+ exports.DataFormat = DataFormat_1.default;
12
+ const DateUtil_1 = require("./utils/DateUtil");
13
+ exports.DateUtil = DateUtil_1.default;
14
+ const FileUtil_1 = require("./utils/FileUtil");
15
+ exports.FileUtil = FileUtil_1.default;
16
+ const FormatStr_1 = require("./utils/FormatStr");
17
+ exports.FormatStr = FormatStr_1.default;
18
+ const Mix_1 = require("./utils/Mix");
19
+ exports.MixTool = Mix_1.default;
20
+ const TypeUtil_1 = require("./utils/TypeUtil");
21
+ exports.TypeUtil = TypeUtil_1.default;
22
+ const ValidationUtil_1 = require("./utils/ValidationUtil");
23
+ exports.ValidationUtil = ValidationUtil_1.default;
File without changes
@@ -0,0 +1,12 @@
1
+ {"timestamp":"2022-08-26 18:04:16.808","level":"INFO","label":"logger","message":"自定义的日志输出"}
2
+ {"timestamp":"2022-08-26 18:04:16.809","level":"WARN","label":"logger","message":"自定义警告"}
3
+ {"timestamp":"2022-08-26 18:04:16.810","level":"ERROR","label":"logger","message":"自定义报错"}
4
+ {"timestamp":"2022-08-26 18:05:14.219","level":"INFO","label":"logger","message":"自定义的日志输出"}
5
+ {"timestamp":"2022-08-26 18:05:14.221","level":"WARN","label":"logger","message":"自定义警告"}
6
+ {"timestamp":"2022-08-26 18:05:14.221","level":"ERROR","label":"logger","message":"自定义报错"}
7
+ {"timestamp":"2022-08-26 18:07:32.805","level":"INFO","label":"logger","message":"自定义的日志输出"}
8
+ {"timestamp":"2022-08-26 18:07:32.806","level":"WARN","label":"logger","message":"自定义警告"}
9
+ {"timestamp":"2022-08-26 18:07:32.807","level":"ERROR","label":"logger","message":"自定义报错"}
10
+ {"timestamp":"2022-09-02 14:17:35.618","level":"INFO","label":"logger","message":"自定义的日志输出"}
11
+ {"timestamp":"2022-09-02 14:17:35.619","level":"WARN","label":"logger","message":"自定义警告"}
12
+ {"timestamp":"2022-09-02 14:17:35.619","level":"ERROR","label":"logger","message":"自定义报错"}