@fastcar/core 0.2.62 → 0.2.64

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 (234) hide show
  1. package/package.json +1 -1
  2. package/src/FastCarApplication.ts +30 -9
  3. package/src/utils/ValidationUtil.ts +1 -1
  4. package/target/FastCarApplication.js +708 -692
  5. package/target/annotation/Application.js +45 -45
  6. package/target/annotation/ExceptionMonitor.js +16 -16
  7. package/target/annotation/bind/AddRequireModule.js +21 -21
  8. package/target/annotation/bind/AliasInjection.js +23 -23
  9. package/target/annotation/bind/Autowired.js +13 -13
  10. package/target/annotation/bind/CallDependency.js +23 -23
  11. package/target/annotation/data/DBType.js +11 -11
  12. package/target/annotation/data/DS.js +54 -54
  13. package/target/annotation/data/DSIndex.js +9 -9
  14. package/target/annotation/data/Entity.js +10 -10
  15. package/target/annotation/data/Field.js +18 -18
  16. package/target/annotation/data/PrimaryKey.js +9 -9
  17. package/target/annotation/data/SqlSession.js +9 -9
  18. package/target/annotation/data/Table.js +35 -35
  19. package/target/annotation/data/Transactional.js +52 -52
  20. package/target/annotation/env/ApplicationSetting.js +25 -25
  21. package/target/annotation/env/BaseFilePath.js +14 -14
  22. package/target/annotation/env/BaseName.js +9 -9
  23. package/target/annotation/env/BasePath.js +14 -14
  24. package/target/annotation/env/ENV.js +10 -10
  25. package/target/annotation/env/ResourcePath.js +9 -9
  26. package/target/annotation/lifeCycle/AddLifeCycleItem.js +18 -18
  27. package/target/annotation/lifeCycle/ApplicationDestory.js +15 -15
  28. package/target/annotation/lifeCycle/ApplicationInit.js +15 -15
  29. package/target/annotation/lifeCycle/ApplicationRunner.js +7 -7
  30. package/target/annotation/lifeCycle/ApplicationStart.js +24 -24
  31. package/target/annotation/lifeCycle/ApplicationStop.js +20 -20
  32. package/target/annotation/property/Deprecate.js +19 -19
  33. package/target/annotation/property/NotImplemented.js +8 -8
  34. package/target/annotation/property/Override.js +7 -7
  35. package/target/annotation/property/Readonly.js +16 -16
  36. package/target/annotation/scan/ComponentInjection.js +21 -21
  37. package/target/annotation/scan/ComponentScan.js +9 -9
  38. package/target/annotation/scan/ComponentScanExclusion.js +25 -25
  39. package/target/annotation/scan/ComponentScanMust.js +25 -25
  40. package/target/annotation/scan/Hotter.js +8 -8
  41. package/target/annotation/stereotype/BeanName.js +11 -11
  42. package/target/annotation/stereotype/Component.js +8 -8
  43. package/target/annotation/stereotype/Configure.js +14 -14
  44. package/target/annotation/stereotype/Controller.js +9 -9
  45. package/target/annotation/stereotype/Injection.js +12 -12
  46. package/target/annotation/stereotype/Log.js +17 -17
  47. package/target/annotation/stereotype/Repository.js +9 -9
  48. package/target/annotation/stereotype/Service.js +9 -9
  49. package/target/annotation/valid/AddChildValid.js +56 -56
  50. package/target/annotation/valid/CustomType.js +11 -11
  51. package/target/annotation/valid/DefaultVal.js +10 -10
  52. package/target/annotation/valid/NotNull.js +8 -8
  53. package/target/annotation/valid/Rule.js +100 -100
  54. package/target/annotation/valid/Size.js +10 -10
  55. package/target/annotation/valid/Type.js +10 -10
  56. package/target/annotation/valid/ValidCustom.js +17 -17
  57. package/target/annotation/valid/ValidForm.js +133 -133
  58. package/target/annotation.js +108 -108
  59. package/target/config/ApplicationConfig.js +2 -2
  60. package/target/config/SysConfig.js +19 -19
  61. package/target/constant/AppStatusEnum.js +9 -9
  62. package/target/constant/BootPriority.js +11 -11
  63. package/target/constant/CommonConstant.js +18 -18
  64. package/target/constant/ComponentKind.js +11 -11
  65. package/target/constant/DataTypes.js +19 -19
  66. package/target/constant/FastCarMetaData.js +31 -31
  67. package/target/constant/LifeCycleModule.js +9 -9
  68. package/target/db.js +49 -49
  69. package/target/index.js +21 -21
  70. package/target/interface/ApplicationHook.js +2 -2
  71. package/target/interface/ApplicationInterface.js +2 -2
  72. package/target/interface/ApplicationRunnerService.js +2 -2
  73. package/target/interface/DataSourceManager.js +2 -2
  74. package/target/interface/Logger.js +5 -5
  75. package/target/model/BaseMapper.js +98 -98
  76. package/target/model/DataMap.js +87 -87
  77. package/target/model/FormRuleModel.js +2 -2
  78. package/target/model/ValidError.js +5 -5
  79. package/target/model/WinstonLogger.js +96 -96
  80. package/target/type/ComponentDesc.js +2 -2
  81. package/target/type/DesignMeta.js +15 -15
  82. package/target/type/FileHotterDesc.js +2 -2
  83. package/target/type/MapperType.js +2 -2
  84. package/target/type/ProcessType.js +2 -2
  85. package/target/type/SqlError.js +5 -5
  86. package/target/type/WinstonLoggerType.js +9 -9
  87. package/target/utils/ClassLoader.js +65 -65
  88. package/target/utils/ClassUtils.js +35 -35
  89. package/target/utils/CryptoUtil.js +86 -86
  90. package/target/utils/DataFormat.js +88 -88
  91. package/target/utils/DateUtil.js +71 -71
  92. package/target/utils/FileUtil.js +153 -153
  93. package/target/utils/FormatStr.js +14 -14
  94. package/target/utils/IPUtils.js +34 -34
  95. package/target/utils/Id.js +9 -9
  96. package/target/utils/Mix.js +62 -62
  97. package/target/utils/ReflectUtil.js +22 -22
  98. package/target/utils/TypeUtil.js +53 -53
  99. package/target/utils/ValidationUtil.js +123 -123
  100. package/target/utils.js +25 -25
  101. package/test/unit/decorators-test.ts +3 -3
  102. package/test/unit/valid-test.ts +49 -54
  103. package/target/src/FastCarApplication.js +0 -704
  104. package/target/src/annotation/Application.js +0 -45
  105. package/target/src/annotation/ExceptionMonitor.js +0 -16
  106. package/target/src/annotation/bind/AddRequireModule.js +0 -21
  107. package/target/src/annotation/bind/AliasInjection.js +0 -23
  108. package/target/src/annotation/bind/Autowired.js +0 -13
  109. package/target/src/annotation/bind/CallDependency.js +0 -23
  110. package/target/src/annotation/data/DBType.js +0 -11
  111. package/target/src/annotation/data/DS.js +0 -54
  112. package/target/src/annotation/data/DSIndex.js +0 -9
  113. package/target/src/annotation/data/Entity.js +0 -10
  114. package/target/src/annotation/data/Field.js +0 -18
  115. package/target/src/annotation/data/PrimaryKey.js +0 -9
  116. package/target/src/annotation/data/SqlSession.js +0 -9
  117. package/target/src/annotation/data/Table.js +0 -35
  118. package/target/src/annotation/data/Transactional.js +0 -52
  119. package/target/src/annotation/env/ApplicationSetting.js +0 -25
  120. package/target/src/annotation/env/BaseFilePath.js +0 -14
  121. package/target/src/annotation/env/BaseName.js +0 -9
  122. package/target/src/annotation/env/BasePath.js +0 -14
  123. package/target/src/annotation/env/ENV.js +0 -10
  124. package/target/src/annotation/env/ResourcePath.js +0 -9
  125. package/target/src/annotation/lifeCycle/AddLifeCycleItem.js +0 -18
  126. package/target/src/annotation/lifeCycle/ApplicationDestory.js +0 -15
  127. package/target/src/annotation/lifeCycle/ApplicationInit.js +0 -15
  128. package/target/src/annotation/lifeCycle/ApplicationRunner.js +0 -7
  129. package/target/src/annotation/lifeCycle/ApplicationStart.js +0 -24
  130. package/target/src/annotation/lifeCycle/ApplicationStop.js +0 -20
  131. package/target/src/annotation/property/Deprecate.js +0 -19
  132. package/target/src/annotation/property/NotImplemented.js +0 -8
  133. package/target/src/annotation/property/Override.js +0 -7
  134. package/target/src/annotation/property/Readonly.js +0 -16
  135. package/target/src/annotation/scan/ComponentInjection.js +0 -21
  136. package/target/src/annotation/scan/ComponentScan.js +0 -9
  137. package/target/src/annotation/scan/ComponentScanExclusion.js +0 -25
  138. package/target/src/annotation/scan/ComponentScanMust.js +0 -25
  139. package/target/src/annotation/scan/Hotter.js +0 -8
  140. package/target/src/annotation/stereotype/BeanName.js +0 -11
  141. package/target/src/annotation/stereotype/Component.js +0 -8
  142. package/target/src/annotation/stereotype/Configure.js +0 -14
  143. package/target/src/annotation/stereotype/Controller.js +0 -9
  144. package/target/src/annotation/stereotype/Injection.js +0 -12
  145. package/target/src/annotation/stereotype/Log.js +0 -22
  146. package/target/src/annotation/stereotype/Repository.js +0 -9
  147. package/target/src/annotation/stereotype/Service.js +0 -9
  148. package/target/src/annotation/valid/AddChildValid.js +0 -56
  149. package/target/src/annotation/valid/CustomType.js +0 -11
  150. package/target/src/annotation/valid/DefaultVal.js +0 -10
  151. package/target/src/annotation/valid/NotNull.js +0 -8
  152. package/target/src/annotation/valid/Rule.js +0 -100
  153. package/target/src/annotation/valid/Size.js +0 -10
  154. package/target/src/annotation/valid/Type.js +0 -10
  155. package/target/src/annotation/valid/ValidCustom.js +0 -17
  156. package/target/src/annotation/valid/ValidForm.js +0 -133
  157. package/target/src/annotation.js +0 -108
  158. package/target/src/config/ApplicationConfig.js +0 -2
  159. package/target/src/config/SysConfig.js +0 -19
  160. package/target/src/constant/AppStatusEnum.js +0 -9
  161. package/target/src/constant/BootPriority.js +0 -11
  162. package/target/src/constant/CommonConstant.js +0 -18
  163. package/target/src/constant/ComponentKind.js +0 -11
  164. package/target/src/constant/DataTypes.js +0 -19
  165. package/target/src/constant/FastCarMetaData.js +0 -31
  166. package/target/src/constant/LifeCycleModule.js +0 -9
  167. package/target/src/db.js +0 -49
  168. package/target/src/index.js +0 -21
  169. package/target/src/interface/ApplicationHook.js +0 -2
  170. package/target/src/interface/ApplicationInterface.js +0 -2
  171. package/target/src/interface/ApplicationRunnerService.js +0 -2
  172. package/target/src/interface/DataSourceManager.js +0 -2
  173. package/target/src/interface/Logger.js +0 -5
  174. package/target/src/model/BaseMapper.js +0 -103
  175. package/target/src/model/DataMap.js +0 -87
  176. package/target/src/model/FormRuleModel.js +0 -2
  177. package/target/src/model/ValidError.js +0 -5
  178. package/target/src/model/WinstonLogger.js +0 -97
  179. package/target/src/type/ComponentDesc.js +0 -2
  180. package/target/src/type/DesignMeta.js +0 -15
  181. package/target/src/type/FileHotterDesc.js +0 -2
  182. package/target/src/type/MapperType.js +0 -2
  183. package/target/src/type/ProcessType.js +0 -2
  184. package/target/src/type/SqlError.js +0 -5
  185. package/target/src/type/WinstonLoggerType.js +0 -9
  186. package/target/src/utils/ClassLoader.js +0 -65
  187. package/target/src/utils/ClassUtils.js +0 -35
  188. package/target/src/utils/CryptoUtil.js +0 -86
  189. package/target/src/utils/DataFormat.js +0 -88
  190. package/target/src/utils/DateUtil.js +0 -71
  191. package/target/src/utils/FileUtil.js +0 -153
  192. package/target/src/utils/FormatStr.js +0 -14
  193. package/target/src/utils/IPUtils.js +0 -34
  194. package/target/src/utils/Id.js +0 -9
  195. package/target/src/utils/Mix.js +0 -62
  196. package/target/src/utils/ReflectUtil.js +0 -22
  197. package/target/src/utils/TypeUtil.js +0 -53
  198. package/target/src/utils/ValidationUtil.js +0 -118
  199. package/target/src/utils.js +0 -25
  200. package/target/test/example/simple/app-test.js +0 -57
  201. package/target/test/example/simple/app.js +0 -116
  202. package/target/test/example/simple/component/StartRunner.js +0 -19
  203. package/target/test/example/simple/component/StopRunner.js +0 -23
  204. package/target/test/example/simple/config/EnvConfig.js +0 -16
  205. package/target/test/example/simple/config/HelloConfig.js +0 -16
  206. package/target/test/example/simple/config/HotConfig.js +0 -18
  207. package/target/test/example/simple/controller/AliasController.js +0 -17
  208. package/target/test/example/simple/controller/HelloController.js +0 -55
  209. package/target/test/example/simple/controller/NotFoundController.js +0 -36
  210. package/target/test/example/simple/noclude/excludeApp.js +0 -17
  211. package/target/test/example/simple/service/CallService.js +0 -24
  212. package/target/test/example/simple/service/HelloService.js +0 -18
  213. package/target/test/example/simple/service/LogService.js +0 -32
  214. package/target/test/multi/app.js +0 -29
  215. package/target/test/multi/service/aService.js +0 -33
  216. package/target/test/multi/service/bService.js +0 -35
  217. package/target/test/multi/service/cService.js +0 -40
  218. package/target/test/unit/dataMap-test.js +0 -35
  219. package/target/test/unit/decorators-test.js +0 -59
  220. package/target/test/unit/ds-test.js +0 -58
  221. package/target/test/unit/reflectMetadata-test.js +0 -27
  222. package/target/test/unit/valid-test.js +0 -99
  223. package/target/test/unit/winston-test.js +0 -15
  224. package/test/example/logs/fastcar-server.sys.log +0 -3
  225. package/test/example/logs/other-server.app.log +0 -0
  226. package/test/example/logs/other-server.sys.log +0 -0
  227. package/test/example/logs/other-server.sys1.log +0 -0
  228. package/test/example/logs/other-server.sys2.log +0 -0
  229. package/test/example/logs/other-server.sys3.log +0 -6
  230. package/test/example/logs/other-server.sys4.log +0 -0
  231. package/test/example/logs/other-server.sys5.log +0 -0
  232. package/test/example/logs/other-server.sys6.log +0 -2
  233. package/test/logs/logger.log +0 -0
  234. package/test/logs/sys.log +0 -227
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class ClassUtils {
4
- //获取一个类所有的proto属性 采用递归的形式
5
- static getProtoType(t) {
6
- if (!t?.prototype) {
7
- return [];
8
- }
9
- let keys = Reflect.ownKeys(t?.prototype).map((item) => {
10
- return item;
11
- });
12
- let parentObj = Reflect.getPrototypeOf(t);
13
- if (!parentObj || !Reflect.has(parentObj, "prototype")) {
14
- return keys;
15
- }
16
- let parentKeys = ClassUtils.getProtoType(parentObj);
17
- let s = new Set([...keys, ...parentKeys]);
18
- return [...s];
19
- }
20
- static getProtoDesc(t, key) {
21
- if (!t?.prototype) {
22
- return null;
23
- }
24
- let desc = Object.getOwnPropertyDescriptor(t.prototype, key);
25
- if (!!desc) {
26
- return desc;
27
- }
28
- let parentObj = Reflect.getPrototypeOf(t);
29
- if (!parentObj || !Reflect.has(parentObj, "prototype")) {
30
- return null;
31
- }
32
- return ClassUtils.getProtoDesc(parentObj, key);
33
- }
34
- }
35
- exports.default = ClassUtils;
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const crypto = require("crypto");
4
- class CryptoUtil {
5
- static aesDecode(cryptkey, iv, secretdata, aesType = "aes-256-cbc" /* aes */) {
6
- let decipher = crypto.createDecipheriv(aesType, cryptkey, iv);
7
- let decoded = decipher.update(secretdata, "base64", "utf8");
8
- decoded += decipher.final("utf8");
9
- return decoded;
10
- }
11
- static aesEncode(cryptkey, iv, cleardata, aesType = "aes-256-cbc" /* aes */) {
12
- let encipher = crypto.createCipheriv("aes-256-cbc" /* aes */, cryptkey, iv);
13
- let encoded = encipher.update(cleardata, "utf8", "base64");
14
- encoded += encipher.final("base64");
15
- return encoded;
16
- }
17
- static shaEncode(cryptkey, data) {
18
- let hash = crypto.createHmac("sha256", cryptkey);
19
- return hash.update(data).digest("base64");
20
- }
21
- static gcmEncrypt(password, msg) {
22
- try {
23
- let pwd = Buffer.from(password, "hex");
24
- let iv = crypto.randomBytes(12);
25
- let cipher = crypto.createCipheriv("aes-128-gcm", pwd, iv);
26
- //加密
27
- let enc = cipher.update(msg, "utf8", "base64");
28
- enc += cipher.final("base64");
29
- //cipher.getAuthTag() 方法返回一个 Buffer,它包含已从给定数据计算后的认证标签。
30
- //cipher.getAuthTag() 方法只能在使用 cipher.final() 之后调用 这里返回的是一个十六进制后的数组
31
- let tags = cipher.getAuthTag();
32
- let encStr = Buffer.from(enc, "base64");
33
- //由于和java对应的AES/GCM/PKCS5Padding模式对应 所以采用这个拼接
34
- let totalLength = iv.length + encStr.length + tags.length;
35
- let bufferMsg = Buffer.concat([iv, encStr, tags], totalLength);
36
- return bufferMsg.toString("base64");
37
- }
38
- catch (e) {
39
- console.log("Encrypt is error", e);
40
- return null;
41
- }
42
- }
43
- static gcmDecrypt(password, serect) {
44
- try {
45
- let tmpSerect = Buffer.from(serect, "base64");
46
- let pwd = Buffer.from(password, "hex");
47
- //读取数组
48
- let iv = tmpSerect.subarray(0, 12);
49
- let cipher = crypto.createDecipheriv("aes-128-gcm", pwd, iv);
50
- //这边的数据为 去除头的iv12位和尾部的tags的16位
51
- let msg = cipher.update(tmpSerect.subarray(12, tmpSerect.length - 16));
52
- return msg.toString("utf8");
53
- }
54
- catch (e) {
55
- console.log("Decrypt is error", e);
56
- return null;
57
- }
58
- }
59
- static sha256Encode(text, serect = crypto.randomBytes(32).toString("hex"), encoding = "base64") {
60
- let msg = crypto.createHmac("sha256", serect).update(text).digest(encoding);
61
- return {
62
- salt: serect,
63
- msg: msg,
64
- };
65
- }
66
- static sha256EncodeContent(str, encoding = "base64") {
67
- let msg = crypto.createHash("sha256").update(str).digest(encoding);
68
- return msg;
69
- }
70
- static sha256Very(msg, serect, encodeMsg, encoding = "base64") {
71
- let result = this.sha256Encode(msg, serect, encoding);
72
- return result.msg === encodeMsg;
73
- }
74
- static getHashStr(num = 16) {
75
- return crypto.randomBytes(num).toString("hex");
76
- }
77
- //根据给定的字符串返回hash值按照追加的原则
78
- static getHashStrByLength(serect, num) {
79
- let list = crypto.createHash("md5").update(serect).digest().toString("hex");
80
- while (list.length < num) {
81
- list = list.repeat(num - list.length);
82
- }
83
- return list.substring(0, num);
84
- }
85
- }
86
- exports.default = CryptoUtil;
@@ -1,88 +0,0 @@
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
- if (!isNaN(parseInt(value))) {
37
- return !!parseInt(value);
38
- }
39
- }
40
- return !!value;
41
- }
42
- static formatArray(value, type) {
43
- if (type.startsWith("array")) {
44
- if (typeof value === "string") {
45
- value = JSON.parse(value);
46
- }
47
- if (Array.isArray(value)) {
48
- let ntype = type.replace(/array/, "");
49
- value = value.map((item) => {
50
- return DataFormat.formatValue(item, ntype);
51
- });
52
- return value;
53
- }
54
- }
55
- return [];
56
- }
57
- static formatDate(value) {
58
- if (value instanceof Date) {
59
- return value;
60
- }
61
- return new Date(value);
62
- }
63
- static formatValue(value, type) {
64
- if (type.startsWith("array")) {
65
- return DataFormat.formatArray(value, type);
66
- }
67
- switch (type) {
68
- case "string": {
69
- return DataFormat.formatString(value);
70
- }
71
- case "boolean": {
72
- return DataFormat.formatBoolean(value);
73
- }
74
- case "int":
75
- case "float":
76
- case "number": {
77
- return DataFormat.formatNumber(value, type);
78
- }
79
- case "date": {
80
- return DataFormat.formatDate(value);
81
- }
82
- default: {
83
- return value;
84
- }
85
- }
86
- }
87
- }
88
- exports.default = DataFormat;
@@ -1,71 +0,0 @@
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;
@@ -1,153 +0,0 @@
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;
@@ -1,14 +0,0 @@
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;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const getIPNum = function (address) {
4
- let ip = address.split(".");
5
- let total = 0;
6
- ip.forEach((item, index) => {
7
- total += parseInt(item) * Math.pow(256, 3 - index);
8
- });
9
- return total;
10
- };
11
- const InnerIPList = [
12
- ["10.0.0.0", "10.255.255.255"],
13
- ["172.16.0.0", "172.31.255.255"],
14
- ["192.168.0.0", "192.168.255.255"],
15
- ["127.0.0.0", "127.255.255.255"],
16
- ].map((item) => {
17
- return [getIPNum(item[0]), getIPNum(item[1])];
18
- });
19
- class IPUtils {
20
- static isInnerIP = (ip) => {
21
- if (["0.0.0.0", "localhost"].includes(ip)) {
22
- return true;
23
- }
24
- let n = ip.split(".");
25
- if (n.length != 4) {
26
- return false;
27
- }
28
- let ipn = getIPNum(ip);
29
- return InnerIPList.some((item) => {
30
- return ipn >= item[0] && ipn <= item[1];
31
- });
32
- };
33
- }
34
- exports.default = IPUtils;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.id = void 0;
4
- //生成唯一ID
5
- let idCounter = 0;
6
- function id() {
7
- return ++idCounter;
8
- }
9
- exports.id = id;
@@ -1,62 +0,0 @@
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;
@@ -1,22 +0,0 @@
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;
@@ -1,53 +0,0 @@
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
- static isMap(value) {
47
- return value instanceof Map;
48
- }
49
- static isSet(value) {
50
- return value instanceof Set;
51
- }
52
- }
53
- exports.default = TypeUtil;