@fastcar/core 0.2.60 → 0.2.61

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 (224) hide show
  1. package/package.json +2 -4
  2. package/src/model/WinstonLogger.ts +4 -3
  3. package/src/utils/ClassLoader.ts +1 -1
  4. package/src/utils/ValidationUtil.ts +10 -1
  5. package/target/FastCarApplication.js +692 -692
  6. package/target/annotation/Application.js +45 -45
  7. package/target/annotation/ExceptionMonitor.js +16 -16
  8. package/target/annotation/bind/AddRequireModule.js +21 -21
  9. package/target/annotation/bind/AliasInjection.js +23 -23
  10. package/target/annotation/bind/Autowired.js +13 -13
  11. package/target/annotation/bind/CallDependency.js +23 -23
  12. package/target/annotation/data/DBType.js +11 -11
  13. package/target/annotation/data/DS.js +54 -54
  14. package/target/annotation/data/DSIndex.js +9 -9
  15. package/target/annotation/data/Entity.js +10 -10
  16. package/target/annotation/data/Field.js +18 -18
  17. package/target/annotation/data/PrimaryKey.js +9 -9
  18. package/target/annotation/data/SqlSession.js +9 -9
  19. package/target/annotation/data/Table.js +35 -35
  20. package/target/annotation/data/Transactional.js +52 -52
  21. package/target/annotation/env/ApplicationSetting.js +25 -25
  22. package/target/annotation/env/BaseFilePath.js +14 -14
  23. package/target/annotation/env/BaseName.js +9 -9
  24. package/target/annotation/env/BasePath.js +14 -14
  25. package/target/annotation/env/ENV.js +10 -10
  26. package/target/annotation/env/ResourcePath.js +9 -9
  27. package/target/annotation/lifeCycle/AddLifeCycleItem.js +18 -18
  28. package/target/annotation/lifeCycle/ApplicationDestory.js +15 -15
  29. package/target/annotation/lifeCycle/ApplicationInit.js +15 -15
  30. package/target/annotation/lifeCycle/ApplicationRunner.js +7 -7
  31. package/target/annotation/lifeCycle/ApplicationStart.js +24 -24
  32. package/target/annotation/lifeCycle/ApplicationStop.js +20 -20
  33. package/target/annotation/property/Deprecate.js +19 -19
  34. package/target/annotation/property/NotImplemented.js +8 -8
  35. package/target/annotation/property/Override.js +7 -7
  36. package/target/annotation/property/Readonly.js +16 -16
  37. package/target/annotation/scan/ComponentInjection.js +21 -21
  38. package/target/annotation/scan/ComponentScan.js +9 -9
  39. package/target/annotation/scan/ComponentScanExclusion.js +25 -25
  40. package/target/annotation/scan/ComponentScanMust.js +25 -25
  41. package/target/annotation/scan/Hotter.js +8 -8
  42. package/target/annotation/stereotype/BeanName.js +11 -11
  43. package/target/annotation/stereotype/Component.js +8 -8
  44. package/target/annotation/stereotype/Configure.js +14 -14
  45. package/target/annotation/stereotype/Controller.js +9 -9
  46. package/target/annotation/stereotype/Injection.js +12 -12
  47. package/target/annotation/stereotype/Log.js +17 -17
  48. package/target/annotation/stereotype/Repository.js +9 -9
  49. package/target/annotation/stereotype/Service.js +9 -9
  50. package/target/annotation/valid/AddChildValid.js +56 -56
  51. package/target/annotation/valid/CustomType.js +11 -11
  52. package/target/annotation/valid/DefaultVal.js +10 -10
  53. package/target/annotation/valid/NotNull.js +8 -8
  54. package/target/annotation/valid/Rule.js +100 -100
  55. package/target/annotation/valid/Size.js +10 -10
  56. package/target/annotation/valid/Type.js +10 -10
  57. package/target/annotation/valid/ValidCustom.js +17 -17
  58. package/target/annotation/valid/ValidForm.js +133 -133
  59. package/target/annotation.js +108 -108
  60. package/target/config/ApplicationConfig.js +2 -2
  61. package/target/config/SysConfig.js +19 -19
  62. package/target/constant/AppStatusEnum.js +9 -9
  63. package/target/constant/BootPriority.js +11 -11
  64. package/target/constant/CommonConstant.js +18 -18
  65. package/target/constant/ComponentKind.js +11 -11
  66. package/target/constant/DataTypes.js +19 -19
  67. package/target/constant/FastCarMetaData.js +31 -31
  68. package/target/constant/LifeCycleModule.js +9 -9
  69. package/target/db.js +49 -48
  70. package/target/index.js +21 -21
  71. package/target/interface/ApplicationHook.js +2 -2
  72. package/target/interface/ApplicationInterface.js +2 -2
  73. package/target/interface/ApplicationRunnerService.js +2 -2
  74. package/target/interface/DataSourceManager.js +2 -2
  75. package/target/interface/Logger.js +5 -5
  76. package/target/model/BaseMapper.js +98 -98
  77. package/target/model/DataMap.js +87 -87
  78. package/target/model/FormRuleModel.js +2 -2
  79. package/target/model/ValidError.js +5 -5
  80. package/target/model/WinstonLogger.js +96 -95
  81. package/target/src/FastCarApplication.js +704 -0
  82. package/target/src/annotation/Application.js +45 -0
  83. package/target/src/annotation/ExceptionMonitor.js +16 -0
  84. package/target/src/annotation/bind/AddRequireModule.js +21 -0
  85. package/target/src/annotation/bind/AliasInjection.js +23 -0
  86. package/target/src/annotation/bind/Autowired.js +13 -0
  87. package/target/src/annotation/bind/CallDependency.js +23 -0
  88. package/target/src/annotation/data/DBType.js +11 -0
  89. package/target/src/annotation/data/DS.js +54 -0
  90. package/target/src/annotation/data/DSIndex.js +9 -0
  91. package/target/src/annotation/data/Entity.js +10 -0
  92. package/target/src/annotation/data/Field.js +18 -0
  93. package/target/src/annotation/data/PrimaryKey.js +9 -0
  94. package/target/src/annotation/data/SqlSession.js +9 -0
  95. package/target/src/annotation/data/Table.js +35 -0
  96. package/target/src/annotation/data/Transactional.js +52 -0
  97. package/target/src/annotation/env/ApplicationSetting.js +25 -0
  98. package/target/src/annotation/env/BaseFilePath.js +14 -0
  99. package/target/src/annotation/env/BaseName.js +9 -0
  100. package/target/src/annotation/env/BasePath.js +14 -0
  101. package/target/src/annotation/env/ENV.js +10 -0
  102. package/target/src/annotation/env/ResourcePath.js +9 -0
  103. package/target/src/annotation/lifeCycle/AddLifeCycleItem.js +18 -0
  104. package/target/src/annotation/lifeCycle/ApplicationDestory.js +15 -0
  105. package/target/src/annotation/lifeCycle/ApplicationInit.js +15 -0
  106. package/target/src/annotation/lifeCycle/ApplicationRunner.js +7 -0
  107. package/target/src/annotation/lifeCycle/ApplicationStart.js +24 -0
  108. package/target/src/annotation/lifeCycle/ApplicationStop.js +20 -0
  109. package/target/src/annotation/property/Deprecate.js +19 -0
  110. package/target/src/annotation/property/NotImplemented.js +8 -0
  111. package/target/src/annotation/property/Override.js +7 -0
  112. package/target/src/annotation/property/Readonly.js +16 -0
  113. package/target/src/annotation/scan/ComponentInjection.js +21 -0
  114. package/target/src/annotation/scan/ComponentScan.js +9 -0
  115. package/target/src/annotation/scan/ComponentScanExclusion.js +25 -0
  116. package/target/src/annotation/scan/ComponentScanMust.js +25 -0
  117. package/target/src/annotation/scan/Hotter.js +8 -0
  118. package/target/src/annotation/stereotype/BeanName.js +11 -0
  119. package/target/src/annotation/stereotype/Component.js +8 -0
  120. package/target/src/annotation/stereotype/Configure.js +14 -0
  121. package/target/src/annotation/stereotype/Controller.js +9 -0
  122. package/target/src/annotation/stereotype/Injection.js +12 -0
  123. package/target/src/annotation/stereotype/Log.js +22 -0
  124. package/target/src/annotation/stereotype/Repository.js +9 -0
  125. package/target/src/annotation/stereotype/Service.js +9 -0
  126. package/target/src/annotation/valid/AddChildValid.js +56 -0
  127. package/target/src/annotation/valid/CustomType.js +11 -0
  128. package/target/src/annotation/valid/DefaultVal.js +10 -0
  129. package/target/src/annotation/valid/NotNull.js +8 -0
  130. package/target/src/annotation/valid/Rule.js +100 -0
  131. package/target/src/annotation/valid/Size.js +10 -0
  132. package/target/src/annotation/valid/Type.js +10 -0
  133. package/target/src/annotation/valid/ValidCustom.js +17 -0
  134. package/target/src/annotation/valid/ValidForm.js +133 -0
  135. package/target/src/annotation.js +108 -0
  136. package/target/src/config/ApplicationConfig.js +2 -0
  137. package/target/src/config/SysConfig.js +19 -0
  138. package/target/src/constant/AppStatusEnum.js +9 -0
  139. package/target/src/constant/BootPriority.js +11 -0
  140. package/target/src/constant/CommonConstant.js +18 -0
  141. package/target/src/constant/ComponentKind.js +11 -0
  142. package/target/src/constant/DataTypes.js +19 -0
  143. package/target/src/constant/FastCarMetaData.js +31 -0
  144. package/target/src/constant/LifeCycleModule.js +9 -0
  145. package/target/src/db.js +49 -0
  146. package/target/src/index.js +21 -0
  147. package/target/src/interface/ApplicationHook.js +2 -0
  148. package/target/src/interface/ApplicationInterface.js +2 -0
  149. package/target/src/interface/ApplicationRunnerService.js +2 -0
  150. package/target/src/interface/DataSourceManager.js +2 -0
  151. package/target/src/interface/Logger.js +5 -0
  152. package/target/src/model/BaseMapper.js +103 -0
  153. package/target/src/model/DataMap.js +87 -0
  154. package/target/src/model/FormRuleModel.js +2 -0
  155. package/target/src/model/ValidError.js +5 -0
  156. package/target/src/model/WinstonLogger.js +97 -0
  157. package/target/src/type/ComponentDesc.js +2 -0
  158. package/target/src/type/DesignMeta.js +15 -0
  159. package/target/src/type/FileHotterDesc.js +2 -0
  160. package/target/src/type/MapperType.js +2 -0
  161. package/target/src/type/ProcessType.js +2 -0
  162. package/target/src/type/SqlError.js +5 -0
  163. package/target/src/type/WinstonLoggerType.js +9 -0
  164. package/target/src/utils/ClassLoader.js +65 -0
  165. package/target/src/utils/ClassUtils.js +35 -0
  166. package/target/src/utils/CryptoUtil.js +86 -0
  167. package/target/src/utils/DataFormat.js +88 -0
  168. package/target/src/utils/DateUtil.js +71 -0
  169. package/target/src/utils/FileUtil.js +153 -0
  170. package/target/src/utils/FormatStr.js +14 -0
  171. package/target/src/utils/IPUtils.js +34 -0
  172. package/target/src/utils/Id.js +9 -0
  173. package/target/src/utils/Mix.js +62 -0
  174. package/target/src/utils/ReflectUtil.js +22 -0
  175. package/target/src/utils/TypeUtil.js +53 -0
  176. package/target/src/utils/ValidationUtil.js +118 -0
  177. package/target/src/utils.js +25 -0
  178. package/target/test/example/simple/app-test.js +57 -0
  179. package/target/test/example/simple/app.js +116 -0
  180. package/target/test/example/simple/component/StartRunner.js +19 -0
  181. package/target/test/example/simple/component/StopRunner.js +23 -0
  182. package/target/test/example/simple/config/EnvConfig.js +16 -0
  183. package/target/test/example/simple/config/HelloConfig.js +16 -0
  184. package/target/test/example/simple/config/HotConfig.js +18 -0
  185. package/target/test/example/simple/controller/AliasController.js +17 -0
  186. package/target/test/example/simple/controller/HelloController.js +55 -0
  187. package/target/test/example/simple/controller/NotFoundController.js +36 -0
  188. package/target/test/example/simple/noclude/excludeApp.js +17 -0
  189. package/target/test/example/simple/service/CallService.js +24 -0
  190. package/target/test/example/simple/service/HelloService.js +18 -0
  191. package/target/test/example/simple/service/LogService.js +32 -0
  192. package/target/test/multi/app.js +29 -0
  193. package/target/test/multi/service/aService.js +33 -0
  194. package/target/test/multi/service/bService.js +35 -0
  195. package/target/test/multi/service/cService.js +40 -0
  196. package/target/test/unit/dataMap-test.js +35 -0
  197. package/target/test/unit/decorators-test.js +59 -0
  198. package/target/test/unit/ds-test.js +58 -0
  199. package/target/test/unit/reflectMetadata-test.js +27 -0
  200. package/target/test/unit/valid-test.js +99 -0
  201. package/target/test/unit/winston-test.js +15 -0
  202. package/target/type/ComponentDesc.js +2 -2
  203. package/target/type/DesignMeta.js +15 -15
  204. package/target/type/FileHotterDesc.js +2 -2
  205. package/target/type/MapperType.js +2 -2
  206. package/target/type/ProcessType.js +2 -2
  207. package/target/type/SqlError.js +5 -5
  208. package/target/type/WinstonLoggerType.js +9 -9
  209. package/target/utils/ClassLoader.js +65 -65
  210. package/target/utils/ClassUtils.js +35 -35
  211. package/target/utils/CryptoUtil.js +86 -86
  212. package/target/utils/DataFormat.js +88 -88
  213. package/target/utils/DateUtil.js +71 -71
  214. package/target/utils/FileUtil.js +153 -153
  215. package/target/utils/FormatStr.js +14 -14
  216. package/target/utils/IPUtils.js +34 -34
  217. package/target/utils/Id.js +9 -9
  218. package/target/utils/Mix.js +62 -62
  219. package/target/utils/ReflectUtil.js +22 -22
  220. package/target/utils/TypeUtil.js +53 -53
  221. package/target/utils/ValidationUtil.js +124 -118
  222. package/target/utils.js +25 -25
  223. package/test/unit/decorators-test.ts +3 -3
  224. package/test/unit/logs/sys.log +0 -24
@@ -1,100 +1,100 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Rule = void 0;
4
- require("reflect-metadata");
5
- const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
6
- const TypeUtil_1 = require("../../utils/TypeUtil");
7
- function Rule(rules = {}) {
8
- return function (target, method, index) {
9
- //获取设计类型
10
- //获取增强类型的增加严格校验
11
- let paramsTypes = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.paramTypes, target, method);
12
- //对rules进行进一步的补充
13
- let designObj = paramsTypes[index];
14
- let basicFlag = false;
15
- if (!designObj) {
16
- console.warn(`Design type not found by ${method} in ${index}`);
17
- }
18
- else {
19
- basicFlag = TypeUtil_1.default.isBasic(designObj.name);
20
- //获取表单类型
21
- let childMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidChildFormRules, target, `${method}-${index}`);
22
- //进行合并添加
23
- if (TypeUtil_1.default.isClass(designObj)) {
24
- let appendMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidChildFormRules, designObj.prototype);
25
- if (appendMap) {
26
- if (!childMap) {
27
- childMap = new Map();
28
- }
29
- appendMap.forEach((v, key) => {
30
- if (!childMap.has(key)) {
31
- childMap.set(key, v);
32
- return;
33
- }
34
- else {
35
- //进行覆盖更新
36
- let item = childMap.get(key);
37
- if (Reflect.has(v, "filters")) {
38
- if (Array.isArray(item?.filters)) {
39
- v.filters?.forEach(f => {
40
- item?.filters?.push(f);
41
- });
42
- }
43
- }
44
- //合并所有属性
45
- item = Object.assign(v, item);
46
- childMap.set(key, item);
47
- }
48
- });
49
- }
50
- }
51
- if (childMap && childMap.size > 0) {
52
- //补充表单
53
- childMap.forEach((citem, prop) => {
54
- if (Reflect.has(rules, prop)) {
55
- //优先取表单里的
56
- rules[prop] = Object.assign(citem, rules[prop]);
57
- }
58
- else {
59
- Reflect.set(rules, prop, citem);
60
- }
61
- });
62
- }
63
- }
64
- let rulesMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidFormRules, target, method);
65
- if (!rulesMap) {
66
- rulesMap = new Map();
67
- Reflect.defineMetadata(FastCarMetaData_1.FastCarMetaData.ValidFormRules, rulesMap, target, method);
68
- }
69
- //补全消息
70
- Object.keys(rules).forEach(prop => {
71
- let r = rules[prop];
72
- //根据增强型补全type
73
- if (basicFlag && !Reflect.has(r, "type")) {
74
- if (designObj) {
75
- r.type = designObj.name.toLowerCase();
76
- }
77
- else {
78
- r.type = "string";
79
- }
80
- }
81
- if (r.message) {
82
- if (r.required) {
83
- r.nullMessage = r.nullMessage ? r.nullMessage : r.message;
84
- }
85
- if (r.maxSize || r.minSize) {
86
- r.sizeMessgae = r.sizeMessgae ? r.sizeMessgae : r.message;
87
- }
88
- r.typeMessage = r.typeMessage ? r.typeMessage : r.message;
89
- }
90
- else {
91
- if (r.required) {
92
- r.nullMessage = `${prop} is required`;
93
- }
94
- r.typeMessage = `${prop} type is ${r.type}`;
95
- }
96
- });
97
- rulesMap.set(index, { rules, basicFlag, index });
98
- };
99
- }
100
- exports.Rule = Rule;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Rule = void 0;
4
+ require("reflect-metadata");
5
+ const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
6
+ const TypeUtil_1 = require("../../utils/TypeUtil");
7
+ function Rule(rules = {}) {
8
+ return function (target, method, index) {
9
+ //获取设计类型
10
+ //获取增强类型的增加严格校验
11
+ let paramsTypes = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.paramTypes, target, method);
12
+ //对rules进行进一步的补充
13
+ let designObj = paramsTypes[index];
14
+ let basicFlag = false;
15
+ if (!designObj) {
16
+ console.warn(`Design type not found by ${method} in ${index}`);
17
+ }
18
+ else {
19
+ basicFlag = TypeUtil_1.default.isBasic(designObj.name);
20
+ //获取表单类型
21
+ let childMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidChildFormRules, target, `${method}-${index}`);
22
+ //进行合并添加
23
+ if (TypeUtil_1.default.isClass(designObj)) {
24
+ let appendMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidChildFormRules, designObj.prototype);
25
+ if (appendMap) {
26
+ if (!childMap) {
27
+ childMap = new Map();
28
+ }
29
+ appendMap.forEach((v, key) => {
30
+ if (!childMap.has(key)) {
31
+ childMap.set(key, v);
32
+ return;
33
+ }
34
+ else {
35
+ //进行覆盖更新
36
+ let item = childMap.get(key);
37
+ if (Reflect.has(v, "filters")) {
38
+ if (Array.isArray(item?.filters)) {
39
+ v.filters?.forEach(f => {
40
+ item?.filters?.push(f);
41
+ });
42
+ }
43
+ }
44
+ //合并所有属性
45
+ item = Object.assign(v, item);
46
+ childMap.set(key, item);
47
+ }
48
+ });
49
+ }
50
+ }
51
+ if (childMap && childMap.size > 0) {
52
+ //补充表单
53
+ childMap.forEach((citem, prop) => {
54
+ if (Reflect.has(rules, prop)) {
55
+ //优先取表单里的
56
+ rules[prop] = Object.assign(citem, rules[prop]);
57
+ }
58
+ else {
59
+ Reflect.set(rules, prop, citem);
60
+ }
61
+ });
62
+ }
63
+ }
64
+ let rulesMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidFormRules, target, method);
65
+ if (!rulesMap) {
66
+ rulesMap = new Map();
67
+ Reflect.defineMetadata(FastCarMetaData_1.FastCarMetaData.ValidFormRules, rulesMap, target, method);
68
+ }
69
+ //补全消息
70
+ Object.keys(rules).forEach(prop => {
71
+ let r = rules[prop];
72
+ //根据增强型补全type
73
+ if (basicFlag && !Reflect.has(r, "type")) {
74
+ if (designObj) {
75
+ r.type = designObj.name.toLowerCase();
76
+ }
77
+ else {
78
+ r.type = "string";
79
+ }
80
+ }
81
+ if (r.message) {
82
+ if (r.required) {
83
+ r.nullMessage = r.nullMessage ? r.nullMessage : r.message;
84
+ }
85
+ if (r.maxSize || r.minSize) {
86
+ r.sizeMessgae = r.sizeMessgae ? r.sizeMessgae : r.message;
87
+ }
88
+ r.typeMessage = r.typeMessage ? r.typeMessage : r.message;
89
+ }
90
+ else {
91
+ if (r.required) {
92
+ r.nullMessage = `${prop} is required`;
93
+ }
94
+ r.typeMessage = `${prop} type is ${r.type}`;
95
+ }
96
+ });
97
+ rulesMap.set(index, { rules, basicFlag, index });
98
+ };
99
+ }
100
+ exports.Rule = Rule;
@@ -1,10 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const AddChildValid_1 = require("./AddChildValid");
4
- //校验长度
5
- function Size(m = { minSize: 0, maxSize: 0 }) {
6
- return function (target, propertyKey, index) {
7
- (0, AddChildValid_1.default)(target, propertyKey, m, index);
8
- };
9
- }
10
- exports.default = Size;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const AddChildValid_1 = require("./AddChildValid");
4
+ //校验长度
5
+ function Size(m = { minSize: 0, maxSize: 0 }) {
6
+ return function (target, propertyKey, index) {
7
+ (0, AddChildValid_1.default)(target, propertyKey, m, index);
8
+ };
9
+ }
10
+ exports.default = Size;
@@ -1,10 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const AddChildValid_1 = require("./AddChildValid");
4
- //表明类型
5
- function Type(type) {
6
- return function (target, propertyKey, index) {
7
- (0, AddChildValid_1.default)(target, propertyKey, { type: type.toLowerCase() }, index);
8
- };
9
- }
10
- exports.default = Type;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const AddChildValid_1 = require("./AddChildValid");
4
+ //表明类型
5
+ function Type(type) {
6
+ return function (target, propertyKey, index) {
7
+ (0, AddChildValid_1.default)(target, propertyKey, { type: type.toLowerCase() }, index);
8
+ };
9
+ }
10
+ exports.default = Type;
@@ -1,17 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const AddChildValid_1 = require("./AddChildValid");
4
- //自定义表单校验
5
- function ValidCustom(fn, message) {
6
- return function (target, propertyKey, index) {
7
- (0, AddChildValid_1.default)(target, propertyKey, {
8
- filters: [
9
- {
10
- fn,
11
- message,
12
- },
13
- ],
14
- }, index);
15
- };
16
- }
17
- exports.default = ValidCustom;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const AddChildValid_1 = require("./AddChildValid");
4
+ //自定义表单校验
5
+ function ValidCustom(fn, message) {
6
+ return function (target, propertyKey, index) {
7
+ (0, AddChildValid_1.default)(target, propertyKey, {
8
+ filters: [
9
+ {
10
+ fn,
11
+ message,
12
+ },
13
+ ],
14
+ }, index);
15
+ };
16
+ }
17
+ exports.default = ValidCustom;
@@ -1,133 +1,133 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ValidError_1 = require("../../model/ValidError");
4
- const utils_1 = require("../../utils");
5
- const ValidationUtil_1 = require("../../utils/ValidationUtil");
6
- const DataFormat_1 = require("../../utils/DataFormat");
7
- const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
8
- function throwErrMsg(rule, prop, msg) {
9
- let showMsg = msg;
10
- if (!showMsg) {
11
- showMsg = rule.message ? rule.message : `The ${prop} parameter is invalid `;
12
- }
13
- throw new ValidError_1.default(showMsg);
14
- }
15
- function getFormValue(value, prop, defaultValue) {
16
- //查看是否校验子属性
17
- if (ValidationUtil_1.default.isNotNull(value)) {
18
- if (utils_1.TypeUtil.isObject(value)) {
19
- if (Reflect.has(value, prop)) {
20
- let propValue = Reflect.get(value, prop);
21
- if (ValidationUtil_1.default.isNotNull(propValue)) {
22
- return propValue;
23
- }
24
- }
25
- }
26
- else {
27
- return value;
28
- }
29
- }
30
- if (ValidationUtil_1.default.isNotNull(defaultValue)) {
31
- return defaultValue;
32
- }
33
- return null;
34
- }
35
- function setFormValue(obj, prop, val) {
36
- //查看是否校验子属性
37
- if (ValidationUtil_1.default.isNotNull(obj) || utils_1.TypeUtil.isObject(obj)) {
38
- //修正为{}对象时无法赋值错误
39
- if (utils_1.TypeUtil.isObject(obj)) {
40
- Reflect.set(obj, prop, val);
41
- }
42
- else {
43
- obj = val;
44
- }
45
- }
46
- return obj;
47
- }
48
- function delFormValue(value, prop) {
49
- if (ValidationUtil_1.default.isNotNull(value)) {
50
- if (utils_1.TypeUtil.isObject(value)) {
51
- if (Reflect.has(value, prop)) {
52
- Reflect.deleteProperty(value, prop);
53
- }
54
- }
55
- }
56
- }
57
- /***
58
- * @version 1.0 校验表单 支持校验大小 类型 和自定义方法
59
- * @param rules key - value的形式 通常一个参数一个校验方式
60
- * @param paramIndex 位于第几个参数的校验表单
61
- *
62
- */
63
- function ValidForm(target, methodName, descriptor) {
64
- let next = descriptor.value;
65
- descriptor.value = function (...args) {
66
- let rulesMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidFormRules, target, methodName);
67
- if (rulesMap && rulesMap.size > 0) {
68
- rulesMap.forEach((item, paramIndex) => {
69
- let { rules, basicFlag } = item;
70
- let currObj = args[paramIndex];
71
- if (ValidationUtil_1.default.isNull(currObj)) {
72
- currObj = basicFlag ? "" : {};
73
- }
74
- for (let prop in rules) {
75
- let rule = rules[prop];
76
- //进行取值
77
- let val = getFormValue(currObj, prop, rule.defaultVal);
78
- //判断关键字是否相同
79
- if (`${methodName}-${paramIndex}` == prop) {
80
- val = currObj || rule.defaultVal;
81
- }
82
- //优先判断是否为必填项
83
- if (ValidationUtil_1.default.isNull(val)) {
84
- if (rule.required) {
85
- throwErrMsg(rule, prop, rule.nullMessage);
86
- }
87
- else {
88
- if (utils_1.TypeUtil.isObject(currObj) && !Reflect.has(currObj, prop)) {
89
- delFormValue(currObj, prop);
90
- }
91
- }
92
- }
93
- else {
94
- //进行类型判断并赋值
95
- let checkType = rule.type || "string";
96
- val = DataFormat_1.default.formatValue(val, checkType);
97
- //调用check的方法
98
- if (!ValidationUtil_1.default.checkType(val, checkType)) {
99
- throwErrMsg(rule, prop, rule.typeMessage);
100
- }
101
- //判断长度
102
- if (rule?.minSize) {
103
- if (!ValidationUtil_1.default.isNotMinSize(val, rule.minSize)) {
104
- throwErrMsg(rule, prop, rule.sizeMessgae ? rule.sizeMessgae : `${prop} should be greater than ${rule.minSize} `);
105
- }
106
- }
107
- if (rule?.maxSize) {
108
- if (!ValidationUtil_1.default.isNotMaxSize(val, rule.maxSize)) {
109
- throwErrMsg(rule, prop, rule.sizeMessgae ? rule.sizeMessgae : `${prop} should be less than ${rule.maxSize} `);
110
- }
111
- }
112
- //自定义方法校验
113
- if (Array.isArray(rule.filters)) {
114
- for (let fnItem of rule.filters) {
115
- let fn = fnItem.fn;
116
- let flag = Reflect.apply(fn, this, [val]);
117
- if (!flag) {
118
- //抛出错误提示
119
- throwErrMsg(rule, prop, fnItem.message || rule.message);
120
- }
121
- }
122
- }
123
- //进行赋值
124
- currObj = setFormValue(currObj, prop, val);
125
- }
126
- }
127
- args[paramIndex] = currObj;
128
- });
129
- }
130
- return Reflect.apply(next, this, args);
131
- };
132
- }
133
- exports.default = ValidForm;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ValidError_1 = require("../../model/ValidError");
4
+ const utils_1 = require("../../utils");
5
+ const ValidationUtil_1 = require("../../utils/ValidationUtil");
6
+ const DataFormat_1 = require("../../utils/DataFormat");
7
+ const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
8
+ function throwErrMsg(rule, prop, msg) {
9
+ let showMsg = msg;
10
+ if (!showMsg) {
11
+ showMsg = rule.message ? rule.message : `The ${prop} parameter is invalid `;
12
+ }
13
+ throw new ValidError_1.default(showMsg);
14
+ }
15
+ function getFormValue(value, prop, defaultValue) {
16
+ //查看是否校验子属性
17
+ if (ValidationUtil_1.default.isNotNull(value)) {
18
+ if (utils_1.TypeUtil.isObject(value)) {
19
+ if (Reflect.has(value, prop)) {
20
+ let propValue = Reflect.get(value, prop);
21
+ if (ValidationUtil_1.default.isNotNull(propValue)) {
22
+ return propValue;
23
+ }
24
+ }
25
+ }
26
+ else {
27
+ return value;
28
+ }
29
+ }
30
+ if (ValidationUtil_1.default.isNotNull(defaultValue)) {
31
+ return defaultValue;
32
+ }
33
+ return null;
34
+ }
35
+ function setFormValue(obj, prop, val) {
36
+ //查看是否校验子属性
37
+ if (ValidationUtil_1.default.isNotNull(obj) || utils_1.TypeUtil.isObject(obj)) {
38
+ //修正为{}对象时无法赋值错误
39
+ if (utils_1.TypeUtil.isObject(obj)) {
40
+ Reflect.set(obj, prop, val);
41
+ }
42
+ else {
43
+ obj = val;
44
+ }
45
+ }
46
+ return obj;
47
+ }
48
+ function delFormValue(value, prop) {
49
+ if (ValidationUtil_1.default.isNotNull(value)) {
50
+ if (utils_1.TypeUtil.isObject(value)) {
51
+ if (Reflect.has(value, prop)) {
52
+ Reflect.deleteProperty(value, prop);
53
+ }
54
+ }
55
+ }
56
+ }
57
+ /***
58
+ * @version 1.0 校验表单 支持校验大小 类型 和自定义方法
59
+ * @param rules key - value的形式 通常一个参数一个校验方式
60
+ * @param paramIndex 位于第几个参数的校验表单
61
+ *
62
+ */
63
+ function ValidForm(target, methodName, descriptor) {
64
+ let next = descriptor.value;
65
+ descriptor.value = function (...args) {
66
+ let rulesMap = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.ValidFormRules, target, methodName);
67
+ if (rulesMap && rulesMap.size > 0) {
68
+ rulesMap.forEach((item, paramIndex) => {
69
+ let { rules, basicFlag } = item;
70
+ let currObj = args[paramIndex];
71
+ if (ValidationUtil_1.default.isNull(currObj)) {
72
+ currObj = basicFlag ? "" : {};
73
+ }
74
+ for (let prop in rules) {
75
+ let rule = rules[prop];
76
+ //进行取值
77
+ let val = getFormValue(currObj, prop, rule.defaultVal);
78
+ //判断关键字是否相同
79
+ if (`${methodName}-${paramIndex}` == prop) {
80
+ val = currObj || rule.defaultVal;
81
+ }
82
+ //优先判断是否为必填项
83
+ if (ValidationUtil_1.default.isNull(val)) {
84
+ if (rule.required) {
85
+ throwErrMsg(rule, prop, rule.nullMessage);
86
+ }
87
+ else {
88
+ if (utils_1.TypeUtil.isObject(currObj) && !Reflect.has(currObj, prop)) {
89
+ delFormValue(currObj, prop);
90
+ }
91
+ }
92
+ }
93
+ else {
94
+ //进行类型判断并赋值
95
+ let checkType = rule.type || "string";
96
+ val = DataFormat_1.default.formatValue(val, checkType);
97
+ //调用check的方法
98
+ if (!ValidationUtil_1.default.checkType(val, checkType)) {
99
+ throwErrMsg(rule, prop, rule.typeMessage);
100
+ }
101
+ //判断长度
102
+ if (rule?.minSize) {
103
+ if (!ValidationUtil_1.default.isNotMinSize(val, rule.minSize)) {
104
+ throwErrMsg(rule, prop, rule.sizeMessgae ? rule.sizeMessgae : `${prop} should be greater than ${rule.minSize} `);
105
+ }
106
+ }
107
+ if (rule?.maxSize) {
108
+ if (!ValidationUtil_1.default.isNotMaxSize(val, rule.maxSize)) {
109
+ throwErrMsg(rule, prop, rule.sizeMessgae ? rule.sizeMessgae : `${prop} should be less than ${rule.maxSize} `);
110
+ }
111
+ }
112
+ //自定义方法校验
113
+ if (Array.isArray(rule.filters)) {
114
+ for (let fnItem of rule.filters) {
115
+ let fn = fnItem.fn;
116
+ let flag = Reflect.apply(fn, this, [val]);
117
+ if (!flag) {
118
+ //抛出错误提示
119
+ throwErrMsg(rule, prop, fnItem.message || rule.message);
120
+ }
121
+ }
122
+ }
123
+ //进行赋值
124
+ currObj = setFormValue(currObj, prop, val);
125
+ }
126
+ }
127
+ args[paramIndex] = currObj;
128
+ });
129
+ }
130
+ return Reflect.apply(next, this, args);
131
+ };
132
+ }
133
+ exports.default = ValidForm;