@elsikora/nestjs-crud-automator 1.1.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 (287) hide show
  1. package/dist/class/api/base-service.class.d.ts +8 -0
  2. package/dist/class/api/base-service.class.js +13 -0
  3. package/dist/class/api/base-service.class.js.map +1 -0
  4. package/dist/class/api/index.d.ts +1 -0
  5. package/dist/class/api/index.js +18 -0
  6. package/dist/class/api/index.js.map +1 -0
  7. package/dist/class/index.d.ts +1 -0
  8. package/dist/class/index.js +18 -0
  9. package/dist/class/index.js.map +1 -0
  10. package/dist/constant/date.constant.d.ts +4 -0
  11. package/dist/constant/date.constant.js +10 -0
  12. package/dist/constant/date.constant.js.map +1 -0
  13. package/dist/constant/decorator/api/function.constant.d.ts +4 -0
  14. package/dist/constant/decorator/api/function.constant.js +9 -0
  15. package/dist/constant/decorator/api/function.constant.js.map +1 -0
  16. package/dist/constant/decorator/api/index.d.ts +1 -0
  17. package/dist/constant/decorator/api/index.js +18 -0
  18. package/dist/constant/decorator/api/index.js.map +1 -0
  19. package/dist/constant/decorator/index.d.ts +1 -0
  20. package/dist/constant/decorator/index.js +18 -0
  21. package/dist/constant/decorator/index.js.map +1 -0
  22. package/dist/constant/dto/exception.constant.d.ts +6 -0
  23. package/dist/constant/dto/exception.constant.js +14 -0
  24. package/dist/constant/dto/exception.constant.js.map +1 -0
  25. package/dist/constant/dto/index.d.ts +1 -0
  26. package/dist/constant/dto/index.js +18 -0
  27. package/dist/constant/dto/index.js.map +1 -0
  28. package/dist/constant/index.d.ts +5 -0
  29. package/dist/constant/index.js +22 -0
  30. package/dist/constant/index.js.map +1 -0
  31. package/dist/constant/interface/api/filter.constant.d.ts +3 -0
  32. package/dist/constant/interface/api/filter.constant.js +12 -0
  33. package/dist/constant/interface/api/filter.constant.js.map +1 -0
  34. package/dist/constant/interface/api/index.d.ts +1 -0
  35. package/dist/constant/interface/api/index.js +18 -0
  36. package/dist/constant/interface/api/index.js.map +1 -0
  37. package/dist/constant/interface/api/property/index.d.ts +2 -0
  38. package/dist/constant/interface/api/property/index.js +19 -0
  39. package/dist/constant/interface/api/property/index.js.map +1 -0
  40. package/dist/constant/interface/api/property/string.constant.d.ts +6 -0
  41. package/dist/constant/interface/api/property/string.constant.js +12 -0
  42. package/dist/constant/interface/api/property/string.constant.js.map +1 -0
  43. package/dist/constant/interface/api/property/wallet.constant.d.ts +5 -0
  44. package/dist/constant/interface/api/property/wallet.constant.js +12 -0
  45. package/dist/constant/interface/api/property/wallet.constant.js.map +1 -0
  46. package/dist/constant/interface/index.d.ts +1 -0
  47. package/dist/constant/interface/index.js +18 -0
  48. package/dist/constant/interface/index.js.map +1 -0
  49. package/dist/constant/number.constant.d.ts +18 -0
  50. package/dist/constant/number.constant.js +38 -0
  51. package/dist/constant/number.constant.js.map +1 -0
  52. package/dist/decorator/api/function/decorator.d.ts +7 -0
  53. package/dist/decorator/api/function/decorator.js +27 -0
  54. package/dist/decorator/api/function/decorator.js.map +1 -0
  55. package/dist/decorator/api/function/get-list.decorator.d.ts +5 -0
  56. package/dist/decorator/api/function/get-list.decorator.js +129 -0
  57. package/dist/decorator/api/function/get-list.decorator.js.map +1 -0
  58. package/dist/decorator/api/function/get.decorator.d.ts +4 -0
  59. package/dist/decorator/api/function/get.decorator.js +58 -0
  60. package/dist/decorator/api/function/get.decorator.js.map +1 -0
  61. package/dist/decorator/api/function/index.d.ts +2 -0
  62. package/dist/decorator/api/function/index.js +19 -0
  63. package/dist/decorator/api/function/index.js.map +1 -0
  64. package/dist/decorator/api/index.d.ts +3 -0
  65. package/dist/decorator/api/index.js +20 -0
  66. package/dist/decorator/api/index.js.map +1 -0
  67. package/dist/decorator/api/method.decorator.d.ts +2 -0
  68. package/dist/decorator/api/method.decorator.js +203 -0
  69. package/dist/decorator/api/method.decorator.js.map +1 -0
  70. package/dist/decorator/api/property/boolean.decorator.d.ts +2 -0
  71. package/dist/decorator/api/property/boolean.decorator.js +77 -0
  72. package/dist/decorator/api/property/boolean.decorator.js.map +1 -0
  73. package/dist/decorator/api/property/date.decorator.d.ts +2 -0
  74. package/dist/decorator/api/property/date.decorator.js +87 -0
  75. package/dist/decorator/api/property/date.decorator.js.map +1 -0
  76. package/dist/decorator/api/property/index.d.ts +7 -0
  77. package/dist/decorator/api/property/index.js +24 -0
  78. package/dist/decorator/api/property/index.js.map +1 -0
  79. package/dist/decorator/api/property/number.decorator.d.ts +2 -0
  80. package/dist/decorator/api/property/number.decorator.js +146 -0
  81. package/dist/decorator/api/property/number.decorator.js.map +1 -0
  82. package/dist/decorator/api/property/object.decorator.d.ts +2 -0
  83. package/dist/decorator/api/property/object.decorator.js +124 -0
  84. package/dist/decorator/api/property/object.decorator.js.map +1 -0
  85. package/dist/decorator/api/property/string.decorator.d.ts +2 -0
  86. package/dist/decorator/api/property/string.decorator.js +282 -0
  87. package/dist/decorator/api/property/string.decorator.js.map +1 -0
  88. package/dist/decorator/api/property/uuid.decorator.d.ts +2 -0
  89. package/dist/decorator/api/property/uuid.decorator.js +63 -0
  90. package/dist/decorator/api/property/uuid.decorator.js.map +1 -0
  91. package/dist/decorator/api/property/wallet.decorator.d.ts +2 -0
  92. package/dist/decorator/api/property/wallet.decorator.js +25 -0
  93. package/dist/decorator/api/property/wallet.decorator.js.map +1 -0
  94. package/dist/decorator/api/service.decorator.d.ts +8 -0
  95. package/dist/decorator/api/service.decorator.js +71 -0
  96. package/dist/decorator/api/service.decorator.js.map +1 -0
  97. package/dist/decorator/index.d.ts +1 -0
  98. package/dist/decorator/index.js +18 -0
  99. package/dist/decorator/index.js.map +1 -0
  100. package/dist/dto/exception/bad-request.dto.d.ts +8 -0
  101. package/dist/dto/exception/bad-request.dto.js +84 -0
  102. package/dist/dto/exception/bad-request.dto.js.map +1 -0
  103. package/dist/dto/exception/conflict.dto.d.ts +8 -0
  104. package/dist/dto/exception/conflict.dto.js +84 -0
  105. package/dist/dto/exception/conflict.dto.js.map +1 -0
  106. package/dist/dto/exception/forbidden.dto.d.ts +8 -0
  107. package/dist/dto/exception/forbidden.dto.js +84 -0
  108. package/dist/dto/exception/forbidden.dto.js.map +1 -0
  109. package/dist/dto/exception/index.d.ts +7 -0
  110. package/dist/dto/exception/index.js +24 -0
  111. package/dist/dto/exception/index.js.map +1 -0
  112. package/dist/dto/exception/internal-server-error.dto.d.ts +8 -0
  113. package/dist/dto/exception/internal-server-error.dto.js +84 -0
  114. package/dist/dto/exception/internal-server-error.dto.js.map +1 -0
  115. package/dist/dto/exception/not-found.dto.d.ts +8 -0
  116. package/dist/dto/exception/not-found.dto.js +84 -0
  117. package/dist/dto/exception/not-found.dto.js.map +1 -0
  118. package/dist/dto/exception/too-many-requests.dto.d.ts +8 -0
  119. package/dist/dto/exception/too-many-requests.dto.js +84 -0
  120. package/dist/dto/exception/too-many-requests.dto.js.map +1 -0
  121. package/dist/dto/exception/unauthorized.dto.d.ts +8 -0
  122. package/dist/dto/exception/unauthorized.dto.js +84 -0
  123. package/dist/dto/exception/unauthorized.dto.js.map +1 -0
  124. package/dist/dto/index.d.ts +1 -0
  125. package/dist/dto/index.js +18 -0
  126. package/dist/dto/index.js.map +1 -0
  127. package/dist/enum/decorator/api/action.enum.d.ts +14 -0
  128. package/dist/enum/decorator/api/action.enum.js +19 -0
  129. package/dist/enum/decorator/api/action.enum.js.map +1 -0
  130. package/dist/enum/decorator/api/authentication-type.enum.d.ts +5 -0
  131. package/dist/enum/decorator/api/authentication-type.enum.js +10 -0
  132. package/dist/enum/decorator/api/authentication-type.enum.js.map +1 -0
  133. package/dist/enum/decorator/api/function/index.d.ts +1 -0
  134. package/dist/enum/decorator/api/function/index.js +18 -0
  135. package/dist/enum/decorator/api/function/index.js.map +1 -0
  136. package/dist/enum/decorator/api/function/type.enum.d.ts +10 -0
  137. package/dist/enum/decorator/api/function/type.enum.js +15 -0
  138. package/dist/enum/decorator/api/function/type.enum.js.map +1 -0
  139. package/dist/enum/decorator/api/index.d.ts +4 -0
  140. package/dist/enum/decorator/api/index.js +21 -0
  141. package/dist/enum/decorator/api/index.js.map +1 -0
  142. package/dist/enum/decorator/api/property/data-type.enum.d.ts +23 -0
  143. package/dist/enum/decorator/api/property/data-type.enum.js +42 -0
  144. package/dist/enum/decorator/api/property/data-type.enum.js.map +1 -0
  145. package/dist/enum/decorator/api/property/date-type.enum.d.ts +14 -0
  146. package/dist/enum/decorator/api/property/date-type.enum.js +19 -0
  147. package/dist/enum/decorator/api/property/date-type.enum.js.map +1 -0
  148. package/dist/enum/decorator/api/property/index.d.ts +2 -0
  149. package/dist/enum/decorator/api/property/index.js +19 -0
  150. package/dist/enum/decorator/api/property/index.js.map +1 -0
  151. package/dist/enum/decorator/index.d.ts +1 -0
  152. package/dist/enum/decorator/index.js +18 -0
  153. package/dist/enum/decorator/index.js.map +1 -0
  154. package/dist/enum/filter-order-direction.enum.d.ts +4 -0
  155. package/dist/enum/filter-order-direction.enum.js +9 -0
  156. package/dist/enum/filter-order-direction.enum.js.map +1 -0
  157. package/dist/enum/index.d.ts +3 -0
  158. package/dist/enum/index.js +20 -0
  159. package/dist/enum/index.js.map +1 -0
  160. package/dist/enum/utility/error-string-action.enum.d.ts +55 -0
  161. package/dist/enum/utility/error-string-action.enum.js +60 -0
  162. package/dist/enum/utility/error-string-action.enum.js.map +1 -0
  163. package/dist/enum/utility/index.d.ts +1 -0
  164. package/dist/enum/utility/index.js +18 -0
  165. package/dist/enum/utility/index.js.map +1 -0
  166. package/dist/index.d.ts +10 -0
  167. package/dist/index.js +27 -0
  168. package/dist/index.js.map +1 -0
  169. package/dist/interceptor/correlation-id-response-body.interceptor.d.ts +5 -0
  170. package/dist/interceptor/correlation-id-response-body.interceptor.js +90 -0
  171. package/dist/interceptor/correlation-id-response-body.interceptor.js.map +1 -0
  172. package/dist/interceptor/index.d.ts +1 -0
  173. package/dist/interceptor/index.js +18 -0
  174. package/dist/interceptor/index.js.map +1 -0
  175. package/dist/interface/api-base-entity.interface.d.ts +3 -0
  176. package/dist/interface/api-base-entity.interface.js +3 -0
  177. package/dist/interface/api-base-entity.interface.js.map +1 -0
  178. package/dist/interface/decorator/api/function/index.d.ts +1 -0
  179. package/dist/interface/decorator/api/function/index.js +3 -0
  180. package/dist/interface/decorator/api/function/index.js.map +1 -0
  181. package/dist/interface/decorator/api/get-list-response-result.interface.d.ts +7 -0
  182. package/dist/interface/decorator/api/get-list-response-result.interface.js +3 -0
  183. package/dist/interface/decorator/api/get-list-response-result.interface.js.map +1 -0
  184. package/dist/interface/decorator/api/index.d.ts +5 -0
  185. package/dist/interface/decorator/api/index.js +22 -0
  186. package/dist/interface/decorator/api/index.js.map +1 -0
  187. package/dist/interface/decorator/api/method/index.d.ts +2 -0
  188. package/dist/interface/decorator/api/method/index.js +19 -0
  189. package/dist/interface/decorator/api/method/index.js.map +1 -0
  190. package/dist/interface/decorator/api/method/properties.interface.d.ts +16 -0
  191. package/dist/interface/decorator/api/method/properties.interface.js +3 -0
  192. package/dist/interface/decorator/api/method/properties.interface.js.map +1 -0
  193. package/dist/interface/decorator/api/method/throttler-properties.interface.d.ts +4 -0
  194. package/dist/interface/decorator/api/method/throttler-properties.interface.js +3 -0
  195. package/dist/interface/decorator/api/method/throttler-properties.interface.js.map +1 -0
  196. package/dist/interface/decorator/api/property/base-properties.interface.d.ts +13 -0
  197. package/dist/interface/decorator/api/property/base-properties.interface.js +3 -0
  198. package/dist/interface/decorator/api/property/base-properties.interface.js.map +1 -0
  199. package/dist/interface/decorator/api/property/date-properties.interface.d.ts +5 -0
  200. package/dist/interface/decorator/api/property/date-properties.interface.js +3 -0
  201. package/dist/interface/decorator/api/property/date-properties.interface.js.map +1 -0
  202. package/dist/interface/decorator/api/property/index.d.ts +6 -0
  203. package/dist/interface/decorator/api/property/index.js +23 -0
  204. package/dist/interface/decorator/api/property/index.js.map +1 -0
  205. package/dist/interface/decorator/api/property/number-properties.interface.d.ts +9 -0
  206. package/dist/interface/decorator/api/property/number-properties.interface.js +3 -0
  207. package/dist/interface/decorator/api/property/number-properties.interface.js.map +1 -0
  208. package/dist/interface/decorator/api/property/object-properties.interface.d.ts +10 -0
  209. package/dist/interface/decorator/api/property/object-properties.interface.js +3 -0
  210. package/dist/interface/decorator/api/property/object-properties.interface.js.map +1 -0
  211. package/dist/interface/decorator/api/property/string-properties.interface.d.ts +10 -0
  212. package/dist/interface/decorator/api/property/string-properties.interface.js +3 -0
  213. package/dist/interface/decorator/api/property/string-properties.interface.js.map +1 -0
  214. package/dist/interface/decorator/api/property/uuid-properties.interface.d.ts +8 -0
  215. package/dist/interface/decorator/api/property/uuid-properties.interface.js +3 -0
  216. package/dist/interface/decorator/api/property/uuid-properties.interface.js.map +1 -0
  217. package/dist/interface/decorator/api/response-type.interface.d.ts +9 -0
  218. package/dist/interface/decorator/api/response-type.interface.js +3 -0
  219. package/dist/interface/decorator/api/response-type.interface.js.map +1 -0
  220. package/dist/interface/decorator/index.d.ts +1 -0
  221. package/dist/interface/decorator/index.js +18 -0
  222. package/dist/interface/decorator/index.js.map +1 -0
  223. package/dist/interface/index.d.ts +4 -0
  224. package/dist/interface/index.js +21 -0
  225. package/dist/interface/index.js.map +1 -0
  226. package/dist/interface/service.interface.d.ts +1 -0
  227. package/dist/interface/service.interface.js +3 -0
  228. package/dist/interface/service.interface.js.map +1 -0
  229. package/dist/interface/utility/error-string-properties.interface.d.ts +5 -0
  230. package/dist/interface/utility/error-string-properties.interface.js +3 -0
  231. package/dist/interface/utility/error-string-properties.interface.js.map +1 -0
  232. package/dist/interface/utility/index.d.ts +1 -0
  233. package/dist/interface/utility/index.js +18 -0
  234. package/dist/interface/utility/index.js.map +1 -0
  235. package/dist/tsconfig.build.tsbuildinfo +1 -0
  236. package/dist/type/api/filter/allowed-types.type.d.ts +1 -0
  237. package/dist/type/api/filter/allowed-types.type.js +3 -0
  238. package/dist/type/api/filter/allowed-types.type.js.map +1 -0
  239. package/dist/type/api/filter/extracted-allowed-types.type.d.ts +2 -0
  240. package/dist/type/api/filter/extracted-allowed-types.type.js +3 -0
  241. package/dist/type/api/filter/extracted-allowed-types.type.js.map +1 -0
  242. package/dist/type/api/filter/field-selector.type.d.ts +3 -0
  243. package/dist/type/api/filter/field-selector.type.js +3 -0
  244. package/dist/type/api/filter/field-selector.type.js.map +1 -0
  245. package/dist/type/api/filter/index.d.ts +4 -0
  246. package/dist/type/api/filter/index.js +21 -0
  247. package/dist/type/api/filter/index.js.map +1 -0
  248. package/dist/type/api/filter/order-by.type.d.ts +5 -0
  249. package/dist/type/api/filter/order-by.type.js +3 -0
  250. package/dist/type/api/filter/order-by.type.js.map +1 -0
  251. package/dist/type/api/function/get-list-properties.type.d.ts +23 -0
  252. package/dist/type/api/function/get-list-properties.type.js +3 -0
  253. package/dist/type/api/function/get-list-properties.type.js.map +1 -0
  254. package/dist/type/api/function/get-properties.type.d.ts +6 -0
  255. package/dist/type/api/function/get-properties.type.js +3 -0
  256. package/dist/type/api/function/get-properties.type.js.map +1 -0
  257. package/dist/type/api/function/index.d.ts +1 -0
  258. package/dist/type/api/function/index.js +18 -0
  259. package/dist/type/api/function/index.js.map +1 -0
  260. package/dist/type/api/index.d.ts +2 -0
  261. package/dist/type/api/index.js +19 -0
  262. package/dist/type/api/index.js.map +1 -0
  263. package/dist/type/index.d.ts +1 -0
  264. package/dist/type/index.js +18 -0
  265. package/dist/type/index.js.map +1 -0
  266. package/dist/utility/api/filter-order-by-from-entity.utility.d.ts +4 -0
  267. package/dist/utility/api/filter-order-by-from-entity.utility.js +34 -0
  268. package/dist/utility/api/filter-order-by-from-entity.utility.js.map +1 -0
  269. package/dist/utility/api/index.d.ts +1 -0
  270. package/dist/utility/api/index.js +18 -0
  271. package/dist/utility/api/index.js.map +1 -0
  272. package/dist/utility/create-rest-application.utility.d.ts +3 -0
  273. package/dist/utility/create-rest-application.utility.js +9 -0
  274. package/dist/utility/create-rest-application.utility.js.map +1 -0
  275. package/dist/utility/error-string.utility.d.ts +2 -0
  276. package/dist/utility/error-string.utility.js +7 -0
  277. package/dist/utility/error-string.utility.js.map +1 -0
  278. package/dist/utility/index.d.ts +3 -0
  279. package/dist/utility/index.js +20 -0
  280. package/dist/utility/index.js.map +1 -0
  281. package/dist/validator/index.d.ts +1 -0
  282. package/dist/validator/index.js +18 -0
  283. package/dist/validator/index.js.map +1 -0
  284. package/dist/validator/is-regular-expression.validator.d.ts +4 -0
  285. package/dist/validator/is-regular-expression.validator.js +31 -0
  286. package/dist/validator/is-regular-expression.validator.js.map +1 -0
  287. package/package.json +64 -0
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiPropertyDate = ApiPropertyDate;
4
+ const common_1 = require("@nestjs/common");
5
+ const class_transformer_1 = require("class-transformer");
6
+ const enum_1 = require("../../../enum");
7
+ const string_decorator_1 = require("./string.decorator");
8
+ const constant_1 = require("../../../constant");
9
+ function getDescription(type) {
10
+ switch (type) {
11
+ case enum_1.EApiPropertyDateType.CREATED: {
12
+ return "creation date";
13
+ }
14
+ case enum_1.EApiPropertyDateType.UPDATED: {
15
+ return "last update date";
16
+ }
17
+ case enum_1.EApiPropertyDateType.CREATED_AT_FROM: {
18
+ return "createdAt from";
19
+ }
20
+ case enum_1.EApiPropertyDateType.CREATED_AT_TO: {
21
+ return "createdAt to";
22
+ }
23
+ case enum_1.EApiPropertyDateType.UPDATED_AT_TO: {
24
+ return "updatedAt to";
25
+ }
26
+ case enum_1.EApiPropertyDateType.UPDATED_AT_FROM: {
27
+ return "updatedAt from";
28
+ }
29
+ case enum_1.EApiPropertyDateType.EXPIRES_IN: {
30
+ return "expiration date";
31
+ }
32
+ case enum_1.EApiPropertyDateType.REFRESH_IN: {
33
+ return "refresh date";
34
+ }
35
+ case enum_1.EApiPropertyDateType.DATE: {
36
+ return "date";
37
+ }
38
+ case enum_1.EApiPropertyDateType.RECEIVED_AT_FROM: {
39
+ return "receivedAt from";
40
+ }
41
+ case enum_1.EApiPropertyDateType.RECEIVED_AT_TO: {
42
+ return "receivedAt to";
43
+ }
44
+ case enum_1.EApiPropertyDateType.RECEIVED_AT: {
45
+ return "receivedAt date";
46
+ }
47
+ default: {
48
+ return "";
49
+ }
50
+ }
51
+ }
52
+ function ApiPropertyDate(properties) {
53
+ validateOptions(properties);
54
+ const startOfYearUTCDate = new Date(Date.UTC(new Date().getUTCFullYear(), 0, 1, 0, 0, 0, 0)).toISOString();
55
+ const apiPropertyStringOptions = {
56
+ description: getDescription(properties.type),
57
+ entity: properties.entity,
58
+ example: startOfYearUTCDate,
59
+ expose: properties.expose,
60
+ format: enum_1.EApiPropertyDataType.DATE_TIME,
61
+ maxLength: startOfYearUTCDate.length,
62
+ minLength: startOfYearUTCDate.length,
63
+ nullable: properties.nullable,
64
+ pattern: "/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}Z$/",
65
+ required: !properties.response && properties.required,
66
+ response: properties.response,
67
+ type: enum_1.EApiPropertyDataType.DATE_TIME,
68
+ };
69
+ const decorators = [(0, string_decorator_1.ApiPropertyString)({ ...apiPropertyStringOptions })];
70
+ if (!properties.response) {
71
+ decorators.push((0, class_transformer_1.Type)(() => Date));
72
+ }
73
+ return (0, common_1.applyDecorators)(...decorators);
74
+ }
75
+ function validateOptions(properties) {
76
+ const errors = [];
77
+ if (!properties.response && typeof properties.required !== "boolean") {
78
+ errors.push("Required is not defined");
79
+ }
80
+ if (properties.response && properties.required) {
81
+ errors.push("Required is defined for response");
82
+ }
83
+ if (errors.length > constant_1.NUMBER_CONSTANT.ZERO_LIST_LENGTH) {
84
+ throw new Error(`ApiPropertyDate error: ${errors.join("\n")}`);
85
+ }
86
+ }
87
+ //# sourceMappingURL=date.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.decorator.js","sourceRoot":"/","sources":["decorator/api/property/date.decorator.ts"],"names":[],"mappings":";;AAgEA,0CA2BC;AA3FD,2CAAiD;AAEjD,yDAAyC;AACzC,wCAA2E;AAE3E,yDAAuD;AACvD,g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QAAQ,KAAK,SAAS,EAAE,CAAC;QACtE,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,0BAAe,CAAC,gBAAgB,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,0BAA0B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChE,CAAC;AACF,CAAC","sourcesContent":["import { applyDecorators } from \"@nestjs/common\";\n\nimport { Type } from \"class-transformer\";\nimport { EApiPropertyDataType, EApiPropertyDateType } from \"../../../enum\";\nimport type { IApiBaseEntity, IApiPropertyDateProperties, IApiPropertyStringProperties } from \"../../../interface\";\nimport { ApiPropertyString } from \"./string.decorator\";\nimport { NUMBER_CONSTANT } from \"../../../constant\";\n\nfunction getDescription(type: EApiPropertyDateType): string {\n\tswitch (type) {\n\t\tcase EApiPropertyDateType.CREATED: {\n\t\t\treturn \"creation date\";\n\t\t}\n\n\t\tcase EApiPropertyDateType.UPDATED: {\n\t\t\treturn \"last update date\";\n\t\t}\n\n\t\tcase EApiPropertyDateType.CREATED_AT_FROM: {\n\t\t\treturn \"createdAt from\";\n\t\t}\n\n\t\tcase EApiPropertyDateType.CREATED_AT_TO: {\n\t\t\treturn \"createdAt to\";\n\t\t}\n\n\t\tcase EApiPropertyDateType.UPDATED_AT_TO: {\n\t\t\treturn \"updatedAt to\";\n\t\t}\n\n\t\tcase EApiPropertyDateType.UPDATED_AT_FROM: {\n\t\t\treturn \"updatedAt from\";\n\t\t}\n\n\t\tcase EApiPropertyDateType.EXPIRES_IN: {\n\t\t\treturn \"expiration date\";\n\t\t}\n\n\t\tcase EApiPropertyDateType.REFRESH_IN: {\n\t\t\treturn \"refresh date\";\n\t\t}\n\n\t\tcase EApiPropertyDateType.DATE: {\n\t\t\treturn \"date\";\n\t\t}\n\n\t\tcase EApiPropertyDateType.RECEIVED_AT_FROM: {\n\t\t\treturn \"receivedAt from\";\n\t\t}\n\n\t\tcase EApiPropertyDateType.RECEIVED_AT_TO: {\n\t\t\treturn \"receivedAt to\";\n\t\t}\n\n\t\tcase EApiPropertyDateType.RECEIVED_AT: {\n\t\t\treturn \"receivedAt date\";\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn \"\";\n\t\t}\n\t}\n}\n\nexport function ApiPropertyDate<T extends IApiBaseEntity>(properties: IApiPropertyDateProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void {\n\tvalidateOptions<T>(properties);\n\n\tconst startOfYearUTCDate: string = new Date(Date.UTC(new Date().getUTCFullYear(), 0, 1, 0, 0, 0, 0)).toISOString();\n\n\tconst apiPropertyStringOptions: IApiPropertyStringProperties<T> = {\n\t\tdescription: getDescription(properties.type),\n\t\tentity: properties.entity,\n\t\texample: startOfYearUTCDate,\n\t\texpose: properties.expose,\n\t\tformat: EApiPropertyDataType.DATE_TIME,\n\t\tmaxLength: startOfYearUTCDate.length,\n\t\tminLength: startOfYearUTCDate.length,\n\t\tnullable: properties.nullable,\n\t\tpattern: \"/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}Z$/\",\n\t\trequired: !properties.response && properties.required,\n\t\tresponse: properties.response,\n\t\ttype: EApiPropertyDataType.DATE_TIME,\n\t};\n\n\tconst decorators: Array<PropertyDecorator> = [ApiPropertyString({ ...apiPropertyStringOptions })];\n\n\tif (!properties.response) {\n\t\tdecorators.push(Type(() => Date));\n\t}\n\n\treturn applyDecorators(...decorators);\n}\n\nfunction validateOptions<T extends IApiBaseEntity>(properties: IApiPropertyDateProperties<T>): void {\n\tconst errors: Array<string> = [];\n\n\tif (!properties.response && typeof properties.required !== \"boolean\") {\n\t\terrors.push(\"Required is not defined\");\n\t}\n\n\tif (properties.response && properties.required) {\n\t\terrors.push(\"Required is defined for response\");\n\t}\n\n\tif (errors.length > NUMBER_CONSTANT.ZERO_LIST_LENGTH) {\n\t\tthrow new Error(`ApiPropertyDate error: ${errors.join(\"\\n\")}`);\n\t}\n}\n"]}
@@ -0,0 +1,7 @@
1
+ export * from "./boolean.decorator";
2
+ export * from "./date.decorator";
3
+ export * from "./wallet.decorator";
4
+ export * from "./number.decorator";
5
+ export * from "./uuid.decorator";
6
+ export * from "./object.decorator";
7
+ export * from "./string.decorator";
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./boolean.decorator"), exports);
18
+ __exportStar(require("./date.decorator"), exports);
19
+ __exportStar(require("./wallet.decorator"), exports);
20
+ __exportStar(require("./number.decorator"), exports);
21
+ __exportStar(require("./uuid.decorator"), exports);
22
+ __exportStar(require("./object.decorator"), exports);
23
+ __exportStar(require("./string.decorator"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["decorator/api/property/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,mDAAiC;AACjC,qDAAmC;AACnC,qDAAmC;AACnC,mDAAiC;AACjC,qDAAmC;AACnC,qDAAmC","sourcesContent":["export * from \"./boolean.decorator\";\nexport * from \"./date.decorator\";\nexport * from \"./wallet.decorator\";\nexport * from \"./number.decorator\";\nexport * from \"./uuid.decorator\";\nexport * from \"./object.decorator\";\nexport * from \"./string.decorator\";\n"]}
@@ -0,0 +1,2 @@
1
+ import type { IApiBaseEntity, IApiPropertyNumberProperties } from "../../../interface";
2
+ export declare function ApiPropertyNumber<T extends IApiBaseEntity>(properties: IApiPropertyNumberProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ApiPropertyNumber = ApiPropertyNumber;
7
+ const common_1 = require("@nestjs/common");
8
+ const swagger_1 = require("@nestjs/swagger");
9
+ const class_transformer_1 = require("class-transformer");
10
+ const class_validator_1 = require("class-validator");
11
+ const random_1 = __importDefault(require("lodash/random"));
12
+ const enum_1 = require("../../../enum");
13
+ const constant_1 = require("../../../constant");
14
+ function ApiPropertyNumber(properties) {
15
+ if (properties.example === undefined) {
16
+ properties.example = (0, random_1.default)(properties.minimum, properties.maximum);
17
+ }
18
+ validateOptions(properties);
19
+ const apiPropertyOptions = buildApiPropertyOptions(properties);
20
+ const decorators = buildDecorators(properties, apiPropertyOptions);
21
+ return (0, common_1.applyDecorators)(...decorators);
22
+ }
23
+ function getFormat(properties) {
24
+ switch (properties.type) {
25
+ case enum_1.EApiPropertyDataType.INTEGER: {
26
+ return properties.maximum <= constant_1.NUMBER_CONSTANT.MAX_INTEGER && properties.maximum >= constant_1.NUMBER_CONSTANT.MIN_INTEGER ? "int32" : "int64";
27
+ }
28
+ case enum_1.EApiPropertyDataType.FLOAT: {
29
+ return "float";
30
+ }
31
+ case enum_1.EApiPropertyDataType.DOUBLE: {
32
+ return "double";
33
+ }
34
+ default: {
35
+ throw new Error("ApiPropertyNumber error: Format is not defined");
36
+ }
37
+ }
38
+ }
39
+ function validateOptions(properties) {
40
+ const errors = [];
41
+ if (!properties.response && typeof properties.required !== "boolean") {
42
+ errors.push("Required is not defined");
43
+ }
44
+ if (properties.response && properties.required) {
45
+ errors.push("Required is defined for response");
46
+ }
47
+ if (!enum_1.EApiPropertyDataTypeNumber.has(properties.type)) {
48
+ errors.push("Type is not valid for number property: " + properties.type);
49
+ }
50
+ if (properties.minimum > properties.maximum) {
51
+ errors.push("Minimum is greater than maximum");
52
+ }
53
+ if (properties.example && properties.example < properties.minimum) {
54
+ errors.push("Example is less than minimum");
55
+ }
56
+ if (properties.example && properties.example > properties.maximum) {
57
+ errors.push("Example is greater than maximum");
58
+ }
59
+ if (properties.example && properties.multipleOf && !(0, class_validator_1.isInt)(properties.example / properties.multipleOf)) {
60
+ errors.push("Example is not a multiple of 'multipleOf' value");
61
+ }
62
+ if (errors.length > 0) {
63
+ throw new Error(`ApiPropertyNumber error: ${errors.join("\n")}`);
64
+ }
65
+ }
66
+ function buildApiPropertyOptions(properties) {
67
+ const apiPropertyOptions = {
68
+ description: `${properties.entity.name} ${properties.description || ""}`,
69
+ example: properties.example,
70
+ format: getFormat(properties),
71
+ maximum: properties.maximum,
72
+ minimum: properties.minimum,
73
+ nullable: properties.nullable,
74
+ required: !properties.response && properties.required,
75
+ type: "number",
76
+ };
77
+ if (properties.enum) {
78
+ apiPropertyOptions.enum = properties.enum;
79
+ }
80
+ if (properties.isArray) {
81
+ apiPropertyOptions.isArray = true;
82
+ apiPropertyOptions.minItems = properties.minItems;
83
+ apiPropertyOptions.maxItems = properties.maxItems;
84
+ apiPropertyOptions.uniqueItems = properties.uniqueItems;
85
+ }
86
+ if (properties.isArray && properties.enum) {
87
+ delete apiPropertyOptions.type;
88
+ }
89
+ else if (properties.isArray) {
90
+ apiPropertyOptions.type = "number[]";
91
+ }
92
+ return apiPropertyOptions;
93
+ }
94
+ function buildDecorators(properties, apiPropertyOptions) {
95
+ const decorators = [(0, swagger_1.ApiProperty)(apiPropertyOptions)];
96
+ if (properties.response) {
97
+ decorators.push(swagger_1.ApiResponseProperty);
98
+ if (properties.expose) {
99
+ decorators.push((0, class_transformer_1.Expose)());
100
+ }
101
+ decorators.push((0, class_transformer_1.Transform)(({ value }) => {
102
+ return Number(value);
103
+ }, { toClassOnly: true }));
104
+ }
105
+ else if (properties.isArray) {
106
+ if (!properties.required) {
107
+ decorators.push((0, class_validator_1.IsOptional)());
108
+ }
109
+ decorators.push((0, class_validator_1.IsArray)(), (0, class_validator_1.ArrayNotEmpty)());
110
+ if (properties.minItems) {
111
+ decorators.push((0, class_validator_1.ArrayMinSize)(properties.minItems));
112
+ }
113
+ if (properties.maxItems) {
114
+ decorators.push((0, class_validator_1.ArrayMaxSize)(properties.maxItems));
115
+ }
116
+ if (properties.enum) {
117
+ decorators.push((0, class_validator_1.IsEnum)(properties.enum, { each: true }));
118
+ }
119
+ else {
120
+ decorators.push((0, class_validator_1.IsNumber)({}, { each: true }));
121
+ }
122
+ if (properties.multipleOf) {
123
+ decorators.push((0, class_validator_1.IsDivisibleBy)(properties.multipleOf, { each: true }));
124
+ }
125
+ decorators.push((0, class_transformer_1.Transform)(({ value }) => value.map(Number), { toClassOnly: true }), (0, class_validator_1.Min)(properties.minimum, { each: true }), (0, class_validator_1.Max)(properties.maximum, { each: true }));
126
+ }
127
+ else {
128
+ if (!properties.required) {
129
+ decorators.push((0, class_validator_1.IsOptional)());
130
+ }
131
+ if (properties.enum) {
132
+ decorators.push((0, class_validator_1.IsEnum)(properties.enum));
133
+ }
134
+ else {
135
+ decorators.push((0, class_validator_1.IsNumber)());
136
+ }
137
+ if (properties.multipleOf) {
138
+ decorators.push((0, class_validator_1.IsDivisibleBy)(properties.multipleOf));
139
+ }
140
+ decorators.push((0, class_transformer_1.Transform)(({ value }) => {
141
+ return Number(value);
142
+ }, { toClassOnly: true }), (0, class_validator_1.Min)(properties.minimum), (0, class_validator_1.Max)(properties.maximum));
143
+ }
144
+ return decorators;
145
+ }
146
+ //# sourceMappingURL=number.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.decorator.js","sourceRoot":"/","sources":["decorator/api/property/number.decorator.ts"],"names":[],"mappings":";;;;;AAeA,8CAWC;AA1BD,2CAAiD;AAEjD,6CAAmE;AAEnE,yDAAsD;AAEtD,qDAAmJ;AAEnJ,2DAAmC;AAInC,wCAAiF;AACjF,gDAAoD;AAEpD,SAAgB,iBAAiB,CAA2B,UAA2C;IACtG,IAAI,UAAU,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACtC,UAAU,CAAC,OAAO,GAAG,IAAA,gBAAM,EAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IACrE,CAAC;IAED,eAAe,CAAI,UAAU,CAAC,CAAC;IAE/B,MAAM,kBAAkB,GAAuB,uBAAuB,CAAI,UAAU,CAAC,CAAC;IACtF,MAAM,UAAU,GAA6B,eAAe,CAAI,UAAU,EAAE,kBAAkB,CAAC,CAAC;IAEhG,OAAO,IAAA,wBAAe,EAAC,GAAG,UAAU,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,SAAS,CAA2B,UAA2C;IACvF,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;QACzB,KAAK,2BAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;YACnC,OAAO,UAAU,CAAC,OAAO,IAAI,0BAAe,CAAC,WAAW,IAAI,UAAU,CAAC,OAAO,IAAI,0BAAe,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;QACnI,CAAC;QAED,KAAK,2BAAoB,CAAC,KAAK,CAAC,CAAC,CAAC;YACjC,OAAO,OAAO,CAAC;QAChB,CAAC;QAED,KAAK,2BAAoB,CAA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C;YAC3B,UAAU,CAAC,IAAI,CAAC,IAAA,+BAAa,EAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;QACvD,CAAC;QAED,UAAU,CAAC,IAAI,CACd,IAAA,6BAAS,EACR,CAAC,EAAE,KAAK,EAAqB,EAAE,EAAE;YAChC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC,EACD,EAAE,WAAW,EAAE,IAAI,EAAE,CACrB,EACD,IAAA,qBAAG,EAAC,UAAU,CAAC,OAAO,CAAC,EACvB,IAAA,qBAAG,EAAC,UAAU,CAAC,OAAO,CAAC,CACvB,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import { applyDecorators } from \"@nestjs/common\";\n\nimport { ApiProperty, ApiResponseProperty } from \"@nestjs/swagger\";\n\nimport { Expose, Transform } from \"class-transformer\";\n\nimport { ArrayMaxSize, ArrayMinSize, ArrayNotEmpty, IsArray, IsDivisibleBy, IsEnum, isInt, IsNumber, IsOptional, Max, Min } from \"class-validator\";\n\nimport random from \"lodash/random\";\n\nimport type { ApiPropertyOptions } from \"@nestjs/swagger\";\nimport type { IApiBaseEntity, IApiPropertyNumberProperties } from \"../../../interface\";\nimport { EApiPropertyDataType, EApiPropertyDataTypeNumber } from \"../../../enum\";\nimport { NUMBER_CONSTANT } from \"../../../constant\";\n\nexport function ApiPropertyNumber<T extends IApiBaseEntity>(properties: IApiPropertyNumberProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void {\n\tif (properties.example === undefined) {\n\t\tproperties.example = random(properties.minimum, properties.maximum);\n\t}\n\n\tvalidateOptions<T>(properties);\n\n\tconst apiPropertyOptions: ApiPropertyOptions = buildApiPropertyOptions<T>(properties);\n\tconst decorators: Array<PropertyDecorator> = buildDecorators<T>(properties, apiPropertyOptions);\n\n\treturn applyDecorators(...decorators);\n}\n\nfunction getFormat<T extends IApiBaseEntity>(properties: IApiPropertyNumberProperties<T>): string {\n\tswitch (properties.type) {\n\t\tcase EApiPropertyDataType.INTEGER: {\n\t\t\treturn properties.maximum <= NUMBER_CONSTANT.MAX_INTEGER && properties.maximum >= NUMBER_CONSTANT.MIN_INTEGER ? \"int32\" : \"int64\";\n\t\t}\n\n\t\tcase EApiPropertyDataType.FLOAT: {\n\t\t\treturn \"float\";\n\t\t}\n\n\t\tcase EApiPropertyDataType.DOUBLE: {\n\t\t\treturn \"double\";\n\t\t}\n\n\t\tdefault: {\n\t\t\tthrow new Error(\"ApiPropertyNumber error: Format is not defined\");\n\t\t}\n\t}\n}\n\nfunction validateOptions<T extends IApiBaseEntity>(properties: IApiPropertyNumberProperties<T>): void {\n\tconst errors: Array<string> = [];\n\n\tif (!properties.response && typeof properties.required !== \"boolean\") {\n\t\terrors.push(\"Required is not defined\");\n\t}\n\n\tif (properties.response && properties.required) {\n\t\terrors.push(\"Required is defined for response\");\n\t}\n\n\tif (!EApiPropertyDataTypeNumber.has(properties.type)) {\n\t\terrors.push(\"Type is not valid for number property: \" + properties.type);\n\t}\n\n\tif (properties.minimum > properties.maximum) {\n\t\terrors.push(\"Minimum is greater than maximum\");\n\t}\n\n\tif (properties.example && properties.example < properties.minimum) {\n\t\terrors.push(\"Example is less than minimum\");\n\t}\n\n\tif (properties.example && properties.example > properties.maximum) {\n\t\terrors.push(\"Example is greater than maximum\");\n\t}\n\n\tif (properties.example && properties.multipleOf && !isInt(properties.example / properties.multipleOf)) {\n\t\terrors.push(\"Example is not a multiple of 'multipleOf' value\");\n\t}\n\n\tif (errors.length > 0) {\n\t\tthrow new Error(`ApiPropertyNumber error: ${errors.join(\"\\n\")}`);\n\t}\n}\n\nfunction buildApiPropertyOptions<T extends IApiBaseEntity>(properties: IApiPropertyNumberProperties<T>): ApiPropertyOptions {\n\tconst apiPropertyOptions: ApiPropertyOptions = {\n\t\tdescription: `${properties.entity.name} ${properties.description || \"\"}`,\n\t\texample: properties.example,\n\t\tformat: getFormat(properties),\n\t\tmaximum: properties.maximum,\n\t\tminimum: properties.minimum,\n\t\tnullable: properties.nullable,\n\t\trequired: !properties.response && properties.required,\n\t\ttype: \"number\",\n\t};\n\n\tif (properties.enum) {\n\t\tapiPropertyOptions.enum = properties.enum;\n\t}\n\n\tif (properties.isArray) {\n\t\tapiPropertyOptions.isArray = true;\n\t\tapiPropertyOptions.minItems = properties.minItems;\n\t\tapiPropertyOptions.maxItems = properties.maxItems;\n\t\tapiPropertyOptions.uniqueItems = properties.uniqueItems;\n\t}\n\n\tif (properties.isArray && properties.enum) {\n\t\tdelete apiPropertyOptions.type;\n\t} else if (properties.isArray) {\n\t\tapiPropertyOptions.type = \"number[]\";\n\t}\n\n\treturn apiPropertyOptions;\n}\n\nfunction buildDecorators<T extends IApiBaseEntity>(properties: IApiPropertyNumberProperties<T>, apiPropertyOptions: ApiPropertyOptions): Array<PropertyDecorator> {\n\tconst decorators: Array<PropertyDecorator> = [ApiProperty(apiPropertyOptions)];\n\n\tif (properties.response) {\n\t\tdecorators.push(ApiResponseProperty);\n\n\t\tif (properties.expose) {\n\t\t\tdecorators.push(Expose());\n\t\t}\n\n\t\tdecorators.push(\n\t\t\tTransform(\n\t\t\t\t({ value }: { value: string }) => {\n\t\t\t\t\treturn Number(value);\n\t\t\t\t},\n\t\t\t\t{ toClassOnly: true },\n\t\t\t),\n\t\t);\n\t} else if (properties.isArray) {\n\t\tif (!properties.required) {\n\t\t\tdecorators.push(IsOptional());\n\t\t}\n\n\t\tdecorators.push(IsArray(), ArrayNotEmpty());\n\n\t\tif (properties.minItems) {\n\t\t\tdecorators.push(ArrayMinSize(properties.minItems));\n\t\t}\n\n\t\tif (properties.maxItems) {\n\t\t\tdecorators.push(ArrayMaxSize(properties.maxItems));\n\t\t}\n\n\t\tif (properties.enum) {\n\t\t\tdecorators.push(IsEnum(properties.enum, { each: true }));\n\t\t} else {\n\t\t\tdecorators.push(IsNumber({}, { each: true }));\n\t\t}\n\n\t\tif (properties.multipleOf) {\n\t\t\tdecorators.push(IsDivisibleBy(properties.multipleOf, { each: true }));\n\t\t}\n\n\t\tdecorators.push(\n\t\t\tTransform(({ value }: { value: Array<string> }) => value.map(Number), { toClassOnly: true }),\n\t\t\tMin(properties.minimum, { each: true }),\n\t\t\tMax(properties.maximum, { each: true }),\n\t\t);\n\t} else {\n\t\tif (!properties.required) {\n\t\t\tdecorators.push(IsOptional());\n\t\t}\n\n\t\tif (properties.enum) {\n\t\t\tdecorators.push(IsEnum(properties.enum));\n\t\t} else {\n\t\t\tdecorators.push(IsNumber());\n\t\t}\n\n\t\tif (properties.multipleOf) {\n\t\t\tdecorators.push(IsDivisibleBy(properties.multipleOf));\n\t\t}\n\n\t\tdecorators.push(\n\t\t\tTransform(\n\t\t\t\t({ value }: { value: string }) => {\n\t\t\t\t\treturn Number(value);\n\t\t\t\t},\n\t\t\t\t{ toClassOnly: true },\n\t\t\t),\n\t\t\tMin(properties.minimum),\n\t\t\tMax(properties.maximum),\n\t\t);\n\t}\n\n\treturn decorators;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { IApiBaseEntity, IApiPropertyObjectProperties } from "../../../interface";
2
+ export declare function ApiPropertyObject<T extends IApiBaseEntity>(options: IApiPropertyObjectProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiPropertyObject = ApiPropertyObject;
4
+ const common_1 = require("@nestjs/common");
5
+ const swagger_1 = require("@nestjs/swagger");
6
+ const class_transformer_1 = require("class-transformer");
7
+ const class_validator_1 = require("class-validator");
8
+ function ApiPropertyObject(options) {
9
+ validateOptions(options);
10
+ const apiPropertyOptions = buildApiPropertyOptions(options);
11
+ const decorators = buildDecorators(options, apiPropertyOptions);
12
+ return (0, common_1.applyDecorators)(...decorators);
13
+ }
14
+ function validateOptions(properties) {
15
+ const errors = [];
16
+ if (!properties.response && typeof properties.required !== "boolean") {
17
+ errors.push("Required is not defined");
18
+ }
19
+ if (properties.response && properties.required) {
20
+ errors.push("Required is defined for response");
21
+ }
22
+ if (properties.isArray && !properties.nested && !properties.response && !properties.enum) {
23
+ errors.push("Array property must be nested");
24
+ }
25
+ if (properties.isArray && !properties.type && !properties.enum) {
26
+ errors.push("Array property must have type or enum");
27
+ }
28
+ if (properties.isArray) {
29
+ if (properties.minItems !== undefined && properties.maxItems !== undefined && properties.minItems > properties.maxItems) {
30
+ errors.push("Min items is greater than max items");
31
+ }
32
+ if (properties.minItems !== undefined && properties.minItems < 0) {
33
+ errors.push("Min items is less than 0");
34
+ }
35
+ if (properties.maxItems !== undefined && properties.maxItems < 0) {
36
+ errors.push("Max items is less than 0");
37
+ }
38
+ if (properties.uniqueItems === undefined) {
39
+ errors.push("Unique items is not defined");
40
+ }
41
+ if (properties.uniqueItems && properties.maxItems !== undefined && properties.maxItems <= 1) {
42
+ errors.push("Unique items is true but max items is less than or equal to 1");
43
+ }
44
+ }
45
+ if (errors.length > 0) {
46
+ throw new Error(`ApiPropertyString error: ${errors.join("\n")}`);
47
+ }
48
+ }
49
+ function buildApiPropertyOptions(properties) {
50
+ const apiPropertyOptions = {
51
+ description: `${properties.entity.name} ${properties.description || ""}`,
52
+ nullable: properties.nullable,
53
+ required: !properties.response && properties.required,
54
+ type: properties.type,
55
+ };
56
+ if (properties.additionalProperties) {
57
+ apiPropertyOptions.additionalProperties = properties.additionalProperties;
58
+ }
59
+ if (properties.default) {
60
+ apiPropertyOptions.default = properties.default;
61
+ }
62
+ if (properties.enum) {
63
+ apiPropertyOptions.enum = properties.enum;
64
+ }
65
+ if (properties.isArray) {
66
+ apiPropertyOptions.isArray = true;
67
+ apiPropertyOptions.minItems = properties.minItems;
68
+ apiPropertyOptions.maxItems = properties.maxItems;
69
+ apiPropertyOptions.uniqueItems = properties.uniqueItems;
70
+ apiPropertyOptions.description = `Array of ${properties.entity.name} ${properties.description || ""}`;
71
+ }
72
+ if (properties.nullable) {
73
+ apiPropertyOptions.nullable = true;
74
+ }
75
+ return apiPropertyOptions;
76
+ }
77
+ function buildDecorators(properties, apiPropertyOptions) {
78
+ const decorators = [(0, swagger_1.ApiProperty)(apiPropertyOptions)];
79
+ if (properties.response) {
80
+ decorators.push(swagger_1.ApiResponseProperty);
81
+ if (properties.expose) {
82
+ decorators.push((0, class_transformer_1.Expose)());
83
+ }
84
+ }
85
+ else if (properties.isArray) {
86
+ if (!properties.required) {
87
+ decorators.push((0, class_validator_1.IsOptional)());
88
+ }
89
+ decorators.push((0, class_validator_1.IsArray)(), (0, class_validator_1.ArrayNotEmpty)());
90
+ if (properties.minItems) {
91
+ decorators.push((0, class_validator_1.ArrayMinSize)(properties.minItems));
92
+ }
93
+ if (properties.maxItems) {
94
+ decorators.push((0, class_validator_1.ArrayMaxSize)(properties.maxItems));
95
+ }
96
+ if (properties.enum) {
97
+ decorators.push((0, class_validator_1.IsEnum)(properties.enum, { each: true }));
98
+ }
99
+ }
100
+ else {
101
+ if (!properties.required) {
102
+ decorators.push((0, class_validator_1.IsOptional)());
103
+ }
104
+ if (properties.enum) {
105
+ decorators.push((0, class_validator_1.IsEnum)(properties.enum));
106
+ }
107
+ }
108
+ if (!properties.response && properties.nested && !properties.enum) {
109
+ if (properties.isArray) {
110
+ decorators.push((0, class_validator_1.ValidateNested)({ each: true }));
111
+ }
112
+ else {
113
+ decorators.push((0, class_validator_1.ValidateNested)());
114
+ }
115
+ }
116
+ if (!properties.response && properties.isArray && properties.enum) {
117
+ decorators.push((0, class_transformer_1.Transform)(({ value }) => (Array.isArray(value) ? value : [value])));
118
+ }
119
+ if (properties.type) {
120
+ decorators.push((0, class_transformer_1.Type)(() => properties.type));
121
+ }
122
+ return decorators;
123
+ }
124
+ //# sourceMappingURL=object.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.decorator.js","sourceRoot":"/","sources":["decorator/api/property/object.decorator.ts"],"names":[],"m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AI,CAAC,IAAA,gCAAc,GAAE,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,OAAO,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;QAEnE,UAAU,CAAC,IAAI,CAAC,IAAA,6BAAS,EAAC,CAAC,EAAE,KAAK,EAAO,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;QACrB,UAAU,CAAC,IAAI,CAAC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAgB,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import { applyDecorators } from \"@nestjs/common\";\n\nimport { ApiProperty, ApiResponseProperty } from \"@nestjs/swagger\";\n\nimport { Expose, Transform, Type } from \"class-transformer\";\n\nimport { ArrayMaxSize, ArrayMinSize, ArrayNotEmpty, IsArray, IsEnum, IsOptional, ValidateNested } from \"class-validator\";\n\nimport type { ApiPropertyOptions } from \"@nestjs/swagger\";\nimport type { IApiBaseEntity, IApiPropertyObjectProperties } from \"../../../interface\";\n\nexport function ApiPropertyObject<T extends IApiBaseEntity>(options: IApiPropertyObjectProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void {\n\tvalidateOptions<T>(options);\n\n\tconst apiPropertyOptions: ApiPropertyOptions = buildApiPropertyOptions<T>(options);\n\tconst decorators: Array<PropertyDecorator> = buildDecorators<T>(options, apiPropertyOptions);\n\n\treturn applyDecorators(...decorators);\n}\n\nfunction validateOptions<T extends IApiBaseEntity>(properties: IApiPropertyObjectProperties<T>): void {\n\tconst errors: Array<string> = [];\n\n\tif (!properties.response && typeof properties.required !== \"boolean\") {\n\t\terrors.push(\"Required is not defined\");\n\t}\n\n\tif (properties.response && properties.required) {\n\t\terrors.push(\"Required is defined for response\");\n\t}\n\n\tif (properties.isArray && !properties.nested && !properties.response && !properties.enum) {\n\t\terrors.push(\"Array property must be nested\");\n\t}\n\n\tif (properties.isArray && !properties.type && !properties.enum) {\n\t\terrors.push(\"Array property must have type or enum\");\n\t}\n\n\tif (properties.isArray) {\n\t\tif (properties.minItems !== undefined && properties.maxItems !== undefined && properties.minItems > properties.maxItems) {\n\t\t\terrors.push(\"Min items is greater than max items\");\n\t\t}\n\n\t\tif (properties.minItems !== undefined && properties.minItems < 0) {\n\t\t\terrors.push(\"Min items is less than 0\");\n\t\t}\n\n\t\tif (properties.maxItems !== undefined && properties.maxItems < 0) {\n\t\t\terrors.push(\"Max items is less than 0\");\n\t\t}\n\n\t\tif (properties.uniqueItems === undefined) {\n\t\t\terrors.push(\"Unique items is not defined\");\n\t\t}\n\n\t\tif (properties.uniqueItems && properties.maxItems !== undefined && properties.maxItems <= 1) {\n\t\t\terrors.push(\"Unique items is true but max items is less than or equal to 1\");\n\t\t}\n\t}\n\n\tif (errors.length > 0) {\n\t\tthrow new Error(`ApiPropertyString error: ${errors.join(\"\\n\")}`);\n\t}\n}\n\nfunction buildApiPropertyOptions<T extends IApiBaseEntity>(properties: IApiPropertyObjectProperties<T>): ApiPropertyOptions {\n\tconst apiPropertyOptions: ApiPropertyOptions = {\n\t\tdescription: `${properties.entity.name} ${properties.description || \"\"}`,\n\t\tnullable: properties.nullable,\n\t\trequired: !properties.response && properties.required,\n\t\ttype: properties.type,\n\t};\n\n\tif (properties.additionalProperties) {\n\t\tapiPropertyOptions.additionalProperties = properties.additionalProperties;\n\t}\n\n\tif (properties.default) {\n\t\tapiPropertyOptions.default = properties.default;\n\t}\n\n\tif (properties.enum) {\n\t\tapiPropertyOptions.enum = properties.enum;\n\t}\n\n\tif (properties.isArray) {\n\t\tapiPropertyOptions.isArray = true;\n\t\tapiPropertyOptions.minItems = properties.minItems;\n\t\tapiPropertyOptions.maxItems = properties.maxItems;\n\t\tapiPropertyOptions.uniqueItems = properties.uniqueItems;\n\t\tapiPropertyOptions.description = `Array of ${properties.entity.name} ${properties.description || \"\"}`;\n\t}\n\n\tif (properties.nullable) {\n\t\tapiPropertyOptions.nullable = true;\n\t}\n\n\treturn apiPropertyOptions;\n}\n\nfunction buildDecorators<T extends IApiBaseEntity>(properties: IApiPropertyObjectProperties<T>, apiPropertyOptions: ApiPropertyOptions): Array<PropertyDecorator> {\n\tconst decorators: Array<PropertyDecorator> = [ApiProperty(apiPropertyOptions)];\n\n\tif (properties.response) {\n\t\tdecorators.push(ApiResponseProperty);\n\n\t\tif (properties.expose) {\n\t\t\tdecorators.push(Expose());\n\t\t}\n\t} else if (properties.isArray) {\n\t\tif (!properties.required) {\n\t\t\tdecorators.push(IsOptional());\n\t\t}\n\n\t\tdecorators.push(IsArray(), ArrayNotEmpty());\n\n\t\tif (properties.minItems) {\n\t\t\tdecorators.push(ArrayMinSize(properties.minItems));\n\t\t}\n\n\t\tif (properties.maxItems) {\n\t\t\tdecorators.push(ArrayMaxSize(properties.maxItems));\n\t\t}\n\n\t\tif (properties.enum) {\n\t\t\tdecorators.push(IsEnum(properties.enum, { each: true }));\n\t\t}\n\t} else {\n\t\tif (!properties.required) {\n\t\t\tdecorators.push(IsOptional());\n\t\t}\n\n\t\tif (properties.enum) {\n\t\t\tdecorators.push(IsEnum(properties.enum));\n\t\t}\n\t}\n\n\tif (!properties.response && properties.nested && !properties.enum) {\n\t\tif (properties.isArray) {\n\t\t\tdecorators.push(ValidateNested({ each: true }));\n\t\t} else {\n\t\t\tdecorators.push(ValidateNested());\n\t\t}\n\t}\n\n\tif (!properties.response && properties.isArray && properties.enum) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\tdecorators.push(Transform(({ value }: any) => (Array.isArray(value) ? value : [value])));\n\t}\n\n\tif (properties.type) {\n\t\tdecorators.push(Type(() => properties.type as Function));\n\t}\n\n\treturn decorators;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { IApiBaseEntity, IApiPropertyStringProperties } from "../../../interface";
2
+ export declare function ApiPropertyString<T extends IApiBaseEntity>(properties: IApiPropertyStringProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;