@fastcar/core 0.2.63 → 0.3.0

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 (143) hide show
  1. package/README.md +5 -2
  2. package/annotation.d.ts +3 -0
  3. package/index.d.ts +57 -50
  4. package/package.json +4 -4
  5. package/src/FastCarApplication.ts +184 -123
  6. package/src/annotation/Application.ts +3 -1
  7. package/src/annotation/bind/AddInjectionService.ts +17 -0
  8. package/src/annotation/bind/AddRequireModule.ts +1 -1
  9. package/src/annotation/bind/AliasInjection.ts +8 -15
  10. package/src/annotation/bind/Autowired.ts +1 -1
  11. package/src/annotation/bind/CallDependency.ts +7 -17
  12. package/src/annotation/bind/DemandInjection.ts +16 -0
  13. package/src/annotation/stereotype/Log.ts +13 -9
  14. package/src/annotation/stereotype/Value.ts +5 -0
  15. package/src/annotation.ts +2 -0
  16. package/src/constant/FastCarMetaData.ts +2 -0
  17. package/src/model/WinstonLogger.ts +1 -1
  18. package/src/type/ClassConstructor.ts +5 -0
  19. package/src/type/ComponentDesc.ts +13 -0
  20. package/src/type/FileHotterDesc.ts +6 -0
  21. package/src/utils/ClassLoader.ts +2 -1
  22. package/src/utils/ValidationUtil.ts +1 -1
  23. package/target/FastCarApplication.js +764 -708
  24. package/target/annotation/Application.js +46 -45
  25. package/target/annotation/ExceptionMonitor.js +16 -16
  26. package/target/annotation/bind/AddInjectionService.js +16 -0
  27. package/target/annotation/bind/AddRequireModule.js +21 -21
  28. package/target/annotation/bind/AliasInjection.js +19 -23
  29. package/target/annotation/bind/Autowired.js +13 -13
  30. package/target/annotation/bind/CallDependency.js +16 -23
  31. package/target/annotation/bind/DemandInjection.js +15 -0
  32. package/target/annotation/data/DBType.js +11 -11
  33. package/target/annotation/data/DS.js +54 -54
  34. package/target/annotation/data/DSIndex.js +9 -9
  35. package/target/annotation/data/Entity.js +10 -10
  36. package/target/annotation/data/Field.js +18 -18
  37. package/target/annotation/data/PrimaryKey.js +9 -9
  38. package/target/annotation/data/SqlSession.js +9 -9
  39. package/target/annotation/data/Table.js +35 -35
  40. package/target/annotation/data/Transactional.js +52 -52
  41. package/target/annotation/env/ApplicationSetting.js +25 -25
  42. package/target/annotation/env/BaseFilePath.js +14 -14
  43. package/target/annotation/env/BaseName.js +9 -9
  44. package/target/annotation/env/BasePath.js +14 -14
  45. package/target/annotation/env/ENV.js +10 -10
  46. package/target/annotation/env/ResourcePath.js +9 -9
  47. package/target/annotation/lifeCycle/AddLifeCycleItem.js +17 -18
  48. package/target/annotation/lifeCycle/ApplicationDestory.js +15 -15
  49. package/target/annotation/lifeCycle/ApplicationInit.js +15 -15
  50. package/target/annotation/lifeCycle/ApplicationRunner.js +7 -7
  51. package/target/annotation/lifeCycle/ApplicationStart.js +24 -24
  52. package/target/annotation/lifeCycle/ApplicationStop.js +20 -20
  53. package/target/annotation/property/Deprecate.js +19 -19
  54. package/target/annotation/property/NotImplemented.js +8 -8
  55. package/target/annotation/property/Override.js +7 -7
  56. package/target/annotation/property/Readonly.js +16 -16
  57. package/target/annotation/scan/ComponentInjection.js +21 -21
  58. package/target/annotation/scan/ComponentScan.js +9 -9
  59. package/target/annotation/scan/ComponentScanExclusion.js +25 -25
  60. package/target/annotation/scan/ComponentScanMust.js +25 -25
  61. package/target/annotation/scan/Hotter.js +8 -8
  62. package/target/annotation/stereotype/BeanName.js +11 -11
  63. package/target/annotation/stereotype/Component.js +8 -8
  64. package/target/annotation/stereotype/Configure.js +14 -14
  65. package/target/annotation/stereotype/Controller.js +9 -9
  66. package/target/annotation/stereotype/Injection.js +12 -12
  67. package/target/annotation/stereotype/Log.js +19 -17
  68. package/target/annotation/stereotype/Repository.js +9 -9
  69. package/target/annotation/stereotype/Service.js +9 -9
  70. package/target/annotation/stereotype/Value.js +5 -0
  71. package/target/annotation/valid/AddChildValid.js +56 -56
  72. package/target/annotation/valid/CustomType.js +11 -11
  73. package/target/annotation/valid/DefaultVal.js +10 -10
  74. package/target/annotation/valid/NotNull.js +8 -8
  75. package/target/annotation/valid/Rule.js +99 -100
  76. package/target/annotation/valid/Size.js +10 -10
  77. package/target/annotation/valid/Type.js +10 -10
  78. package/target/annotation/valid/ValidCustom.js +17 -17
  79. package/target/annotation/valid/ValidForm.js +133 -133
  80. package/target/annotation.js +110 -108
  81. package/target/config/ApplicationConfig.js +2 -2
  82. package/target/config/SysConfig.js +19 -19
  83. package/target/constant/AppStatusEnum.js +9 -9
  84. package/target/constant/BootPriority.js +11 -11
  85. package/target/constant/CommonConstant.js +18 -18
  86. package/target/constant/ComponentKind.js +11 -11
  87. package/target/constant/DataTypes.js +19 -19
  88. package/target/constant/FastCarMetaData.js +33 -31
  89. package/target/constant/LifeCycleModule.js +9 -9
  90. package/target/db.js +49 -49
  91. package/target/index.js +21 -21
  92. package/target/interface/ApplicationHook.js +2 -2
  93. package/target/interface/ApplicationInterface.js +2 -2
  94. package/target/interface/ApplicationRunnerService.js +2 -2
  95. package/target/interface/DataSourceManager.js +2 -2
  96. package/target/interface/Logger.js +5 -5
  97. package/target/model/BaseMapper.js +103 -98
  98. package/target/model/DataMap.js +87 -87
  99. package/target/model/FormRuleModel.js +2 -2
  100. package/target/model/ValidError.js +5 -5
  101. package/target/model/WinstonLogger.js +98 -96
  102. package/target/type/ClassConstructor.js +2 -0
  103. package/target/type/ComponentDesc.js +9 -2
  104. package/target/type/DesignMeta.js +15 -15
  105. package/target/type/FileHotterDesc.js +9 -2
  106. package/target/type/MapperType.js +2 -2
  107. package/target/type/ProcessType.js +2 -2
  108. package/target/type/SqlError.js +5 -5
  109. package/target/type/WinstonLoggerType.js +9 -9
  110. package/target/utils/ClassLoader.js +66 -65
  111. package/target/utils/ClassUtils.js +35 -35
  112. package/target/utils/CryptoUtil.js +86 -86
  113. package/target/utils/DataFormat.js +88 -88
  114. package/target/utils/DateUtil.js +71 -71
  115. package/target/utils/FileUtil.js +153 -153
  116. package/target/utils/FormatStr.js +14 -14
  117. package/target/utils/IPUtils.js +34 -34
  118. package/target/utils/Id.js +8 -9
  119. package/target/utils/Mix.js +62 -62
  120. package/target/utils/ReflectUtil.js +22 -22
  121. package/target/utils/TypeUtil.js +53 -53
  122. package/target/utils/ValidationUtil.js +123 -123
  123. package/target/utils.js +25 -25
  124. package/test/example/logs/fastcar-server.app.log +0 -0
  125. package/test/example/logs/fastcar-server.sys.log +10 -0
  126. package/test/example/logs/fastcar-server.sys1.log +8 -0
  127. package/test/example/logs/fastcar-server.sys2.log +11 -0
  128. package/test/example/logs/fastcar-server.sys3.log +0 -0
  129. package/test/example/logs/other-server.app.log +0 -0
  130. package/test/example/logs/other-server.sys.log +5 -0
  131. package/test/example/logs/sys.log +0 -0
  132. package/test/example/logs/sys1.log +0 -0
  133. package/test/example/resource/application.yml +2 -0
  134. package/test/example/resource/hello.yml +1 -1
  135. package/test/example/simple/app-test.ts +2 -1
  136. package/test/example/simple/app.ts +16 -16
  137. package/test/example/simple/service/CallService.ts +2 -0
  138. package/test/example/simple/service/HelloService.ts +2 -0
  139. package/test/unit/sys2.log +6 -0
  140. package/test/unit/sys3.log +6 -0
  141. package/test/unit/sys4.log +6 -0
  142. package/test/unit/sys5.log +6 -0
  143. package/test/unit/sys6.log +6 -0
@@ -1,153 +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;
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 +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;
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 +1,34 @@
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
- }
21
- exports.default = IPUtils;
22
- IPUtils.isInnerIP = (ip) => {
23
- if (["0.0.0.0", "localhost"].includes(ip)) {
24
- return true;
25
- }
26
- let n = ip.split(".");
27
- if (n.length != 4) {
28
- return false;
29
- }
30
- let ipn = getIPNum(ip);
31
- return InnerIPList.some((item) => {
32
- return ipn >= item[0] && ipn <= item[1];
33
- });
34
- };
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 +1,8 @@
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
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.id = id;
4
+ //生成唯一ID
5
+ let idCounter = 0;
6
+ function id() {
7
+ return ++idCounter;
8
+ }
@@ -1,62 +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;
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 +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;
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;