@decaf-ts/decorator-validation 1.10.5 → 1.11.1

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 (218) hide show
  1. package/README.md +1 -1
  2. package/dist/decorator-validation.cjs +1 -1
  3. package/dist/decorator-validation.cjs.map +1 -1
  4. package/dist/decorator-validation.js +1 -1
  5. package/dist/decorator-validation.js.map +1 -1
  6. package/lib/esm/index.d.ts +2 -1
  7. package/lib/esm/index.js +2 -1
  8. package/lib/esm/index.js.map +1 -1
  9. package/lib/esm/model/Builder.d.ts +84 -0
  10. package/lib/esm/model/Builder.js +395 -129
  11. package/lib/esm/model/Builder.js.map +1 -1
  12. package/lib/esm/model/Model.d.ts +21 -19
  13. package/lib/esm/model/Model.js +112 -105
  14. package/lib/esm/model/Model.js.map +1 -1
  15. package/lib/esm/model/constants.d.ts +8 -8
  16. package/lib/esm/model/constants.js +8 -9
  17. package/lib/esm/model/constants.js.map +1 -1
  18. package/lib/esm/model/decorators.d.ts +2 -12
  19. package/lib/esm/model/decorators.js +5 -39
  20. package/lib/esm/model/decorators.js.map +1 -1
  21. package/lib/esm/model/index.d.ts +1 -0
  22. package/lib/esm/model/index.js +1 -0
  23. package/lib/esm/model/index.js.map +1 -1
  24. package/lib/esm/model/types.d.ts +9 -12
  25. package/lib/esm/model/utils.d.ts +0 -3
  26. package/lib/esm/model/utils.js +0 -10
  27. package/lib/esm/model/utils.js.map +1 -1
  28. package/lib/esm/model/validation.d.ts +4 -37
  29. package/lib/esm/model/validation.js +30 -106
  30. package/lib/esm/model/validation.js.map +1 -1
  31. package/lib/esm/overrides/Metadata.d.ts +128 -0
  32. package/lib/esm/overrides/Metadata.js +2 -0
  33. package/lib/esm/overrides/Metadata.js.map +1 -0
  34. package/lib/esm/overrides/index.d.ts +3 -0
  35. package/lib/esm/overrides/index.js +4 -0
  36. package/lib/esm/overrides/index.js.map +1 -0
  37. package/lib/esm/overrides/overrides.d.ts +1 -0
  38. package/lib/esm/overrides/overrides.js +79 -0
  39. package/lib/esm/overrides/overrides.js.map +1 -0
  40. package/lib/esm/overrides/types.d.ts +9 -0
  41. package/lib/esm/overrides/types.js +2 -0
  42. package/lib/esm/overrides/types.js.map +1 -0
  43. package/lib/esm/types/validation.d.ts +4 -2
  44. package/lib/esm/utils/constants.d.ts +4 -18
  45. package/lib/esm/utils/constants.js +4 -17
  46. package/lib/esm/utils/constants.js.map +1 -1
  47. package/lib/esm/utils/dates.d.ts +0 -1
  48. package/lib/esm/utils/dates.js +0 -1
  49. package/lib/esm/utils/dates.js.map +1 -1
  50. package/lib/esm/utils/equality.d.ts +56 -0
  51. package/lib/esm/utils/equality.js +160 -0
  52. package/lib/esm/utils/equality.js.map +1 -0
  53. package/lib/esm/utils/index.d.ts +1 -2
  54. package/lib/esm/utils/index.js +1 -2
  55. package/lib/esm/utils/index.js.map +1 -1
  56. package/lib/esm/utils/registry.d.ts +1 -1
  57. package/lib/esm/utils/serialization.d.ts +2 -2
  58. package/lib/esm/utils/serialization.js +10 -2
  59. package/lib/esm/utils/serialization.js.map +1 -1
  60. package/lib/esm/utils/types.d.ts +0 -102
  61. package/lib/esm/validation/Validation.d.ts +2 -3
  62. package/lib/esm/validation/Validation.js +11 -6
  63. package/lib/esm/validation/Validation.js.map +1 -1
  64. package/lib/esm/validation/Validators/BaseValidator.js +7 -3
  65. package/lib/esm/validation/Validators/BaseValidator.js.map +1 -1
  66. package/lib/esm/validation/Validators/DiffValidator.js +1 -1
  67. package/lib/esm/validation/Validators/DiffValidator.js.map +1 -1
  68. package/lib/esm/validation/Validators/EqualsValidator.js +1 -1
  69. package/lib/esm/validation/Validators/EqualsValidator.js.map +1 -1
  70. package/lib/esm/validation/Validators/GreaterThanOrEqualValidator.js +1 -1
  71. package/lib/esm/validation/Validators/GreaterThanOrEqualValidator.js.map +1 -1
  72. package/lib/esm/validation/Validators/LessThanOrEqualValidator.js +1 -1
  73. package/lib/esm/validation/Validators/LessThanOrEqualValidator.js.map +1 -1
  74. package/lib/esm/validation/Validators/ListValidator.js +4 -4
  75. package/lib/esm/validation/Validators/ListValidator.js.map +1 -1
  76. package/lib/esm/validation/Validators/MaxLengthValidator.js +3 -2
  77. package/lib/esm/validation/Validators/MaxLengthValidator.js.map +1 -1
  78. package/lib/esm/validation/Validators/MaxValidator.js +1 -1
  79. package/lib/esm/validation/Validators/MaxValidator.js.map +1 -1
  80. package/lib/esm/validation/Validators/MinLengthValidator.js +3 -2
  81. package/lib/esm/validation/Validators/MinLengthValidator.js.map +1 -1
  82. package/lib/esm/validation/Validators/MinValidator.js +1 -1
  83. package/lib/esm/validation/Validators/MinValidator.js.map +1 -1
  84. package/lib/esm/validation/Validators/OptionValidator.d.ts +29 -0
  85. package/lib/esm/validation/Validators/OptionValidator.js +61 -0
  86. package/lib/esm/validation/Validators/OptionValidator.js.map +1 -0
  87. package/lib/esm/validation/Validators/TypeValidator.js +2 -2
  88. package/lib/esm/validation/Validators/TypeValidator.js.map +1 -1
  89. package/lib/esm/validation/Validators/constants.d.ts +2 -1
  90. package/lib/esm/validation/Validators/constants.js +3 -2
  91. package/lib/esm/validation/Validators/constants.js.map +1 -1
  92. package/lib/esm/validation/Validators/decorators.d.ts +1 -1
  93. package/lib/esm/validation/Validators/decorators.js +2 -2
  94. package/lib/esm/validation/Validators/decorators.js.map +1 -1
  95. package/lib/esm/validation/Validators/index.d.ts +1 -0
  96. package/lib/esm/validation/Validators/index.js +1 -0
  97. package/lib/esm/validation/Validators/index.js.map +1 -1
  98. package/lib/esm/validation/Validators/utils.d.ts +33 -0
  99. package/lib/esm/validation/Validators/utils.js +62 -0
  100. package/lib/esm/validation/Validators/utils.js.map +1 -1
  101. package/lib/esm/validation/decorators.d.ts +28 -17
  102. package/lib/esm/validation/decorators.js +138 -55
  103. package/lib/esm/validation/decorators.js.map +1 -1
  104. package/lib/esm/validation/types.d.ts +15 -5
  105. package/lib/esm/validation/types.js.map +1 -1
  106. package/lib/index.cjs +2 -1
  107. package/lib/index.d.ts +2 -1
  108. package/lib/index.js.map +1 -1
  109. package/lib/model/Builder.cjs +399 -128
  110. package/lib/model/Builder.d.ts +84 -0
  111. package/lib/model/Builder.js.map +1 -1
  112. package/lib/model/Model.cjs +114 -107
  113. package/lib/model/Model.d.ts +21 -19
  114. package/lib/model/Model.js.map +1 -1
  115. package/lib/model/constants.cjs +8 -9
  116. package/lib/model/constants.d.ts +8 -8
  117. package/lib/model/constants.js.map +1 -1
  118. package/lib/model/decorators.cjs +4 -39
  119. package/lib/model/decorators.d.ts +2 -12
  120. package/lib/model/decorators.js.map +1 -1
  121. package/lib/model/index.cjs +1 -0
  122. package/lib/model/index.d.ts +1 -0
  123. package/lib/model/index.js.map +1 -1
  124. package/lib/model/types.d.ts +9 -12
  125. package/lib/model/utils.cjs +0 -12
  126. package/lib/model/utils.d.ts +0 -3
  127. package/lib/model/utils.js.map +1 -1
  128. package/lib/model/validation.cjs +30 -108
  129. package/lib/model/validation.d.ts +4 -37
  130. package/lib/model/validation.js.map +1 -1
  131. package/lib/overrides/Metadata.cjs +3 -0
  132. package/lib/overrides/Metadata.d.ts +128 -0
  133. package/lib/overrides/Metadata.js.map +1 -0
  134. package/lib/overrides/index.cjs +20 -0
  135. package/lib/overrides/index.d.ts +3 -0
  136. package/lib/overrides/index.js.map +1 -0
  137. package/lib/overrides/overrides.cjs +81 -0
  138. package/lib/overrides/overrides.d.ts +1 -0
  139. package/lib/overrides/overrides.js.map +1 -0
  140. package/lib/overrides/types.cjs +3 -0
  141. package/lib/overrides/types.d.ts +9 -0
  142. package/lib/overrides/types.js.map +1 -0
  143. package/lib/types/validation.d.ts +4 -2
  144. package/lib/utils/constants.cjs +5 -18
  145. package/lib/utils/constants.d.ts +4 -18
  146. package/lib/utils/constants.js.map +1 -1
  147. package/lib/utils/dates.cjs +0 -1
  148. package/lib/utils/dates.d.ts +0 -1
  149. package/lib/utils/dates.js.map +1 -1
  150. package/lib/utils/equality.cjs +163 -0
  151. package/lib/utils/equality.d.ts +56 -0
  152. package/lib/utils/equality.js.map +1 -0
  153. package/lib/utils/index.cjs +1 -2
  154. package/lib/utils/index.d.ts +1 -2
  155. package/lib/utils/index.js.map +1 -1
  156. package/lib/utils/registry.d.ts +1 -1
  157. package/lib/utils/serialization.cjs +10 -2
  158. package/lib/utils/serialization.d.ts +2 -2
  159. package/lib/utils/serialization.js.map +1 -1
  160. package/lib/utils/types.d.ts +0 -102
  161. package/lib/validation/Validation.cjs +11 -6
  162. package/lib/validation/Validation.d.ts +2 -3
  163. package/lib/validation/Validation.js.map +1 -1
  164. package/lib/validation/Validators/BaseValidator.cjs +7 -3
  165. package/lib/validation/Validators/BaseValidator.js.map +1 -1
  166. package/lib/validation/Validators/DiffValidator.cjs +2 -2
  167. package/lib/validation/Validators/DiffValidator.js.map +1 -1
  168. package/lib/validation/Validators/EqualsValidator.cjs +2 -2
  169. package/lib/validation/Validators/EqualsValidator.js.map +1 -1
  170. package/lib/validation/Validators/GreaterThanOrEqualValidator.cjs +2 -2
  171. package/lib/validation/Validators/GreaterThanOrEqualValidator.js.map +1 -1
  172. package/lib/validation/Validators/LessThanOrEqualValidator.cjs +2 -2
  173. package/lib/validation/Validators/LessThanOrEqualValidator.js.map +1 -1
  174. package/lib/validation/Validators/ListValidator.cjs +4 -4
  175. package/lib/validation/Validators/ListValidator.js.map +1 -1
  176. package/lib/validation/Validators/MaxLengthValidator.cjs +3 -2
  177. package/lib/validation/Validators/MaxLengthValidator.js.map +1 -1
  178. package/lib/validation/Validators/MaxValidator.cjs +1 -1
  179. package/lib/validation/Validators/MaxValidator.js.map +1 -1
  180. package/lib/validation/Validators/MinLengthValidator.cjs +3 -2
  181. package/lib/validation/Validators/MinLengthValidator.js.map +1 -1
  182. package/lib/validation/Validators/MinValidator.cjs +1 -1
  183. package/lib/validation/Validators/MinValidator.js.map +1 -1
  184. package/lib/validation/Validators/OptionValidator.cjs +64 -0
  185. package/lib/validation/Validators/OptionValidator.d.ts +29 -0
  186. package/lib/validation/Validators/OptionValidator.js.map +1 -0
  187. package/lib/validation/Validators/TypeValidator.cjs +2 -2
  188. package/lib/validation/Validators/TypeValidator.js.map +1 -1
  189. package/lib/validation/Validators/constants.cjs +5 -4
  190. package/lib/validation/Validators/constants.d.ts +2 -1
  191. package/lib/validation/Validators/constants.js.map +1 -1
  192. package/lib/validation/Validators/decorators.cjs +3 -3
  193. package/lib/validation/Validators/decorators.d.ts +1 -1
  194. package/lib/validation/Validators/decorators.js.map +1 -1
  195. package/lib/validation/Validators/index.cjs +1 -0
  196. package/lib/validation/Validators/index.d.ts +1 -0
  197. package/lib/validation/Validators/index.js.map +1 -1
  198. package/lib/validation/Validators/utils.cjs +66 -0
  199. package/lib/validation/Validators/utils.d.ts +33 -0
  200. package/lib/validation/Validators/utils.js.map +1 -1
  201. package/lib/validation/decorators.cjs +154 -69
  202. package/lib/validation/decorators.d.ts +28 -17
  203. package/lib/validation/decorators.js.map +1 -1
  204. package/lib/validation/types.d.ts +15 -5
  205. package/lib/validation/types.js.map +1 -1
  206. package/package.json +2 -3
  207. package/lib/esm/utils/Decoration.d.ts +0 -135
  208. package/lib/esm/utils/Decoration.js +0 -227
  209. package/lib/esm/utils/Decoration.js.map +0 -1
  210. package/lib/esm/utils/decorators.d.ts +0 -38
  211. package/lib/esm/utils/decorators.js +0 -64
  212. package/lib/esm/utils/decorators.js.map +0 -1
  213. package/lib/utils/Decoration.cjs +0 -231
  214. package/lib/utils/Decoration.d.ts +0 -135
  215. package/lib/utils/Decoration.js.map +0 -1
  216. package/lib/utils/decorators.cjs +0 -68
  217. package/lib/utils/decorators.d.ts +0 -38
  218. package/lib/utils/decorators.js.map +0 -1
@@ -188,4 +188,66 @@ export function isGreaterThan(a, b) {
188
188
  }
189
189
  throw new TypeError(sf(COMPARISON_ERROR_MESSAGES.UNSUPPORTED_TYPES_COMPARISON, getTypeName(a), getTypeName(b)));
190
190
  }
191
+ /**
192
+ * @description Checks if a value matches a specified type name
193
+ * @summary Utility function to verify if a value's type matches the provided type name
194
+ * @param {unknown} value - The value to check the type of
195
+ * @param {string} acceptedType - The type name to check against
196
+ * @return {boolean} Returns true if the value matches the accepted type, false otherwise
197
+ */
198
+ export function checkType(value, acceptedType) {
199
+ if (typeof value === acceptedType.toLowerCase())
200
+ return true;
201
+ if (typeof value === "undefined")
202
+ return false;
203
+ if (typeof value !== "object")
204
+ return false;
205
+ return (value.constructor &&
206
+ value.constructor.name.toLowerCase() ===
207
+ acceptedType.toLowerCase());
208
+ }
209
+ /**
210
+ * @description Checks if a value matches any of the specified type names
211
+ * @summary Utility function to verify if a value's type matches any of the provided type names
212
+ * @param {unknown} value - The value to check the type of
213
+ * @param {string[]} acceptedTypes - Array of type names to check against
214
+ * @return {boolean} Returns true if the value matches any of the accepted types, false otherwise
215
+ */
216
+ export function checkTypes(value, acceptedTypes) {
217
+ return !acceptedTypes.every((t) => !checkType(value, t));
218
+ }
219
+ /**
220
+ * @description Evaluates if a value matches the specified type metadata
221
+ * @summary Compares a value against type metadata to determine if they match
222
+ * @param {unknown} value - The value to evaluate
223
+ * @param {string | string[] | {name: string}} types - Type metadata to check against, can be a string, array of strings, or an object with a name property
224
+ * @return {boolean} Returns true if the value matches the type metadata, false otherwise
225
+ */
226
+ export function evaluateDesignTypes(value, types) {
227
+ switch (typeof types) {
228
+ case "string":
229
+ return checkType(value, types);
230
+ case "object":
231
+ if (Array.isArray(types))
232
+ return checkTypes(value, types);
233
+ return true;
234
+ case "function":
235
+ if (types.name && types.name !== "Object")
236
+ return checkType(value, types.name);
237
+ return true;
238
+ default:
239
+ return true;
240
+ }
241
+ }
242
+ /**
243
+ * @description Returns the length of a value
244
+ * @summary Returns the length of a value
245
+ * @param {string | Set<any> | any[] | Map<any, any>} value - The value to evaluate
246
+ * @return {number} Returns the length of a value
247
+ */
248
+ export function valueLength(value) {
249
+ return value instanceof Set || value instanceof Map
250
+ ? value.size
251
+ : value.length;
252
+ }
191
253
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/validation/Validators/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,mCAAwB;AAC5D,OAAO,EAAE,EAAE,EAAE,+BAAoB;AAEjC,MAAM;AACN,8FAA8F;AAC9F,KAAK;AACL,mEAAmE;AACnE,KAAK;AACL,sFAAsF;AACtF,gIAAgI;AAChI,KAAK;AACL,0DAA0D;AAC1D,KAAK;AACL,sIAAsI;AACtI,2CAA2C;AAC3C,MAAM;AACN,iFAAiF;AACjF,oDAAoD;AACpD,yEAAyE;AACzE,MAAM;AACN,EAAE;AACF,6CAA6C;AAC7C,yDAAyD;AACzD,gDAAgD;AAChD,mDAAmD;AACnD,EAAE;AACF,oCAAoC;AACpC,mCAAmC;AACnC,4CAA4C;AAC5C,mEAAmE;AACnE,yBAAyB;AACzB,mFAAmF;AACnF,WAAW;AACX,QAAQ;AACR,EAAE;AACF,oDAAoD;AACpD,yBAAyB;AACzB,0EAA0E;AAC1E,WAAW;AACX,QAAQ;AACR,EAAE;AACF,8DAA8D;AAC9D,MAAM;AACN,EAAE;AACF,iCAAiC;AACjC,wCAAwC;AACxC,4CAA4C;AAC5C,EAAE;AACF,gCAAgC;AAChC,WAAW;AACX,iCAAiC;AACjC,4CAA4C;AAC5C,6BAA6B;AAC7B,UAAU;AACV,oEAAoE;AACpE,eAAe;AACf,iCAAiC;AACjC,4BAA4B;AAC5B,2DAA2D;AAC3D,gCAAgC;AAChC,uEAAuE;AACvE,2EAA2E;AAC3E,EAAE;AACF,wEAAwE;AACxE,QAAQ;AACR,MAAM;AACN,EAAE;AACF,8BAA8B;AAC9B,IAAI;AAEJ,MAAM,WAAW,GAAG,CAAC,KAAc,EAAU,EAAE;IAC7C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,YAAY,IAAI;QAAE,OAAO,MAAM,CAAC;IACzC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CA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I,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;YAC1C,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,uBAAuB,CAAC,CAAC;QACzE,OAAO,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,IAAI,SAAS,CACjB,EAAE,CACA,yBAAyB,CAAC,4BAA4B,EACtD,WAAW,CAAC,CAAC,CAAC,EACd,WAAW,CAAC,CAAC,CAAC,CACf,CACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/validation/Validators/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,mCAAwB;AAC5D,OAAO,EAAE,EAAE,EAAE,+BAAoB;AAEjC,MAAM;AACN,8FAA8F;AAC9F,KAAK;AACL,mEAAmE;AACnE,KAAK;AACL,sFAAsF;AACtF,gIAAgI;AAChI,KAAK;AACL,0DAA0D;AAC1D,KAAK;AACL,sIAAsI;AACtI,2CAA2C;AAC3C,MAAM;AACN,iFAAiF;AACjF,oDAAoD;AACpD,yEAAyE;AACzE,MAAM;AACN,EAAE;AACF,6CAA6C;AAC7C,yDAAyD;AACzD,gDAAgD;AAChD,mDAAmD;AACnD,EAAE;AACF,oCAAoC;AACpC,mCAAmC;AACnC,4CAA4C;AAC5C,mEAAmE;AACnE,yBAAyB;AACzB,mFAAmF;AACnF,WAAW;AACX,QAAQ;AACR,EAAE;AACF,oDAAoD;AACpD,yBAAyB;AACzB,0EAA0E;AAC1E,WAAW;AACX,QAAQ;AACR,EAAE;AACF,8DAA8D;AAC9D,MAAM;AACN,EAAE;AACF,iCAAiC;AACjC,wCAAwC;AACxC,4CAA4C;AAC5C,EAAE;AACF,gCAAgC;AAChC,WAAW;AACX,iCAAiC;AACjC,4CAA4C;AAC5C,6BAA6B;AAC7B,UAAU;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;AACH,MAAM,UAAU,UAAU,CAAC,KAAc,EAAE,aAAuB;IAChE,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAc,EACd,KAA2C;IAE3C,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACjC,KAAK,QAAQ;YACX,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;gBAAE,OAAO,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC;QACd,KAAK,UAAU;YACb,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ;gBACvC,OAAO,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YACtC,OAAO,IAAI,CAAC;QACd;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAgD;IAC1E,OAAO,KAAK,YAAY,GAAG,IAAI,KAAK,YAAY,GAAG;QACjD,CAAC,CAAC,KAAK,CAAC,IAAI;QACZ,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;AACnB,CAAC"}
@@ -1,6 +1,6 @@
1
- import "reflect-metadata";
2
1
  import { ComparisonValidatorOptions, DateValidatorOptions, ListValidatorOptions, ValidatorOptions } from "./types";
3
- import { Constructor, ModelConstructor } from "../model/types";
2
+ import { ModelConstructor } from "../model/types";
3
+ import { Constructor } from "@decaf-ts/decoration";
4
4
  /**
5
5
  * @description Combined property decorator factory for metadata and attribute marking
6
6
  * @summary Creates a decorator that both marks a property as a model attribute and assigns metadata to it
@@ -13,7 +13,8 @@ import { Constructor, ModelConstructor } from "../model/types";
13
13
  * @function validationMetadata
14
14
  * @category Property Decorators
15
15
  */
16
- export declare function validationMetadata<V>(decorator: any, key: string, value: V): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
16
+ export declare function validationMetadata<V>(decorator: any, key: string, value: V): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor | number) => void;
17
+ export declare function innerValidationDecorator(dec: any, key: string, meta: any): (obj: any, prop: any) => void;
17
18
  export declare function async(): (model: object) => void;
18
19
  /**
19
20
  * @description Property decorator that marks a field as required
@@ -139,23 +140,22 @@ export declare function email(message?: string): (target: any, propertyKey?: any
139
140
  * @category Property Decorators
140
141
  */
141
142
  export declare function url(message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
143
+ export type TypeConstructor = Constructor | typeof BigInt;
142
144
  export interface TypeMetadata extends ValidatorOptions {
143
- customTypes: (string | (() => string))[] | string | (() => string);
145
+ customTypes: (TypeConstructor | (() => TypeConstructor))[] | TypeConstructor | (() => TypeConstructor);
144
146
  }
145
147
  /**
146
148
  * @summary Enforces type verification
147
149
  * @description Validators to validate a decorated property must use key {@link ValidationKeys#TYPE}
148
150
  *
149
- * @param {string[] | string} types accepted types
150
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#TYPE}
151
+ * @param {Constructor[] | Constructor} types accepted types
152
+ * @param {Constructor} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#TYPE}
151
153
  *
152
154
  * @function type
153
155
  * @category Property Decorators
154
156
  */
155
- export declare function type(types: (string | (() => string))[] | string | (() => string), message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
156
- export interface DateMetadata extends DateValidatorOptions {
157
- types: string[];
158
- }
157
+ export declare function type(types: (TypeConstructor | (() => TypeConstructor))[] | TypeConstructor | (() => TypeConstructor), message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
158
+ export type DateMetadata = DateValidatorOptions;
159
159
  /**
160
160
  * @summary Date Handler Decorator
161
161
  * @description Validators to validate a decorated property must use key {@link ValidationKeys#DATE}
@@ -197,7 +197,7 @@ export interface ListMetadata extends ListValidatorOptions {
197
197
  *
198
198
  * @category Property Decorators
199
199
  */
200
- export declare function list(clazz: Constructor<any> | (() => Constructor<any>) | (Constructor<any> | (() => Constructor<any>))[], collection?: "Array" | "Set", message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
200
+ export declare function list(clazz: Constructor | (() => Constructor) | (Constructor | (() => Constructor))[], collection?: "Array" | "Set", message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
201
201
  /**
202
202
  * @summary Set Decorator
203
203
  * @description Wrapper for {@link list} with the 'Set' Collection
@@ -224,7 +224,7 @@ export declare function set(clazz: ModelConstructor<any>, message?: string): (ta
224
224
  * @function eq
225
225
  * @category Property Decorators
226
226
  */
227
- export declare function eq(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
227
+ export declare function eq(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
228
228
  /**
229
229
  * @summary Declares that the decorated property must be different from another specified property.
230
230
  * @description Applies the {@link ValidationKeys.DIFF} validator to ensure the decorated value is different from the value of the given property.
@@ -239,7 +239,7 @@ export declare function eq(propertyToCompare: string, options?: Omit<ComparisonV
239
239
  * @function diff
240
240
  * @category Property Decorators
241
241
  */
242
- export declare function diff(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
242
+ export declare function diff(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
243
243
  /**
244
244
  * @summary Declares that the decorated property must be less than another specified property.
245
245
  * @description Applies the {@link ValidationKeys.LESS_THAN} validator to ensure the decorated value is less than the value of the given property.
@@ -254,7 +254,7 @@ export declare function diff(propertyToCompare: string, options?: Omit<Compariso
254
254
  * @function lt
255
255
  * @category Property Decorators
256
256
  */
257
- export declare function lt(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
257
+ export declare function lt(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
258
258
  /**
259
259
  * @summary Declares that the decorated property must be equal or less than another specified property.
260
260
  * @description Applies the {@link ValidationKeys.LESS_THAN_OR_EQUAL} validator to ensure the decorated value is equal or less than the value of the given property.
@@ -269,7 +269,7 @@ export declare function lt(propertyToCompare: string, options?: Omit<ComparisonV
269
269
  * @function lte
270
270
  * @category Property Decorators
271
271
  */
272
- export declare function lte(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
272
+ export declare function lte(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
273
273
  /**
274
274
  * @summary Declares that the decorated property must be greater than another specified property.
275
275
  * @description Applies the {@link ValidationKeys.GREATER_THAN} validator to ensure the decorated value is greater than the value of the given property.
@@ -284,7 +284,7 @@ export declare function lte(propertyToCompare: string, options?: Omit<Comparison
284
284
  * @function gt
285
285
  * @category Property Decorators
286
286
  */
287
- export declare function gt(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
287
+ export declare function gt(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
288
288
  /**
289
289
  * @summary Declares that the decorated property must be equal or greater than another specified property.
290
290
  * @description Applies the {@link ValidationKeys.GREATER_THAN_OR_EQUAL} validator to ensure the decorated value is equal or greater than the value of the given property.
@@ -299,4 +299,15 @@ export declare function gt(propertyToCompare: string, options?: Omit<ComparisonV
299
299
  * @function gte
300
300
  * @category Property Decorators
301
301
  */
302
- export declare function gte(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
302
+ export declare function gte(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
303
+ /**
304
+ * @summary Defines a list or an object of accepted values for the property
305
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#ENUM}
306
+ *
307
+ * @param {any[] | Record<any, any>} value
308
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#ENUM}
309
+ *
310
+ * @function option
311
+ * @category Property Decorators
312
+ */
313
+ export declare function option(value: any[] | Record<any, any>, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
@@ -1,11 +1,8 @@
1
- import "reflect-metadata";
2
1
  import { DEFAULT_ERROR_MESSAGES, DEFAULT_PATTERNS, ValidationKeys, } from "./Validators/constants.js";
3
2
  import { sf } from "./../utils/strings.js";
4
3
  import { parseDate } from "./../utils/dates.js";
5
- import { propMetadata } from "./../utils/decorators.js";
6
4
  import { Validation } from "./Validation.js";
7
- import { Decoration } from "./../utils/Decoration.js";
8
- import { apply } from "@decaf-ts/reflection";
5
+ import { Decoration, apply, propMetadata, } from "@decaf-ts/decoration";
9
6
  import { ASYNC_META_KEY } from "./../constants/index.js";
10
7
  /**
11
8
  * @description Combined property decorator factory for metadata and attribute marking
@@ -20,9 +17,14 @@ import { ASYNC_META_KEY } from "./../constants/index.js";
20
17
  * @category Property Decorators
21
18
  */
22
19
  export function validationMetadata(decorator, key, value) {
23
- Validation.registerDecorator(key, decorator);
24
20
  return apply(propMetadata(key, value));
25
21
  }
22
+ export function innerValidationDecorator(dec, key, meta) {
23
+ Validation.registerDecorator(key, dec);
24
+ return function innerValidationDecorator(obj, prop) {
25
+ return validationMetadata(dec, `${ValidationKeys.REFLECT}.${prop}.${key}`, meta)(obj, prop);
26
+ };
27
+ }
26
28
  export function async() {
27
29
  return (model) => {
28
30
  if (!Object.prototype.hasOwnProperty.call(model, ASYNC_META_KEY))
@@ -53,7 +55,7 @@ export function async() {
53
55
  * ```
54
56
  */
55
57
  export function required(message = DEFAULT_ERROR_MESSAGES.REQUIRED) {
56
- const key = Validation.key(ValidationKeys.REQUIRED);
58
+ const key = ValidationKeys.REQUIRED;
57
59
  const meta = {
58
60
  message: message,
59
61
  description: `defines the attribute as required`,
@@ -61,7 +63,7 @@ export function required(message = DEFAULT_ERROR_MESSAGES.REQUIRED) {
61
63
  };
62
64
  return Decoration.for(key)
63
65
  .define({
64
- decorator: (validationMetadata),
66
+ decorator: innerValidationDecorator,
65
67
  args: [required, key, meta],
66
68
  })
67
69
  .apply();
@@ -91,17 +93,16 @@ export function required(message = DEFAULT_ERROR_MESSAGES.REQUIRED) {
91
93
  * ```
92
94
  */
93
95
  export function min(value, message = DEFAULT_ERROR_MESSAGES.MIN) {
94
- const key = Validation.key(ValidationKeys.MIN);
96
+ const key = ValidationKeys.MIN;
95
97
  const meta = {
96
98
  [ValidationKeys.MIN]: value,
97
99
  message: message,
98
- types: [Number.name, Date.name],
99
100
  description: `defines the max value of the attribute as ${value} (applies to numbers or Dates)`,
100
101
  async: false,
101
102
  };
102
103
  return Decoration.for(key)
103
104
  .define({
104
- decorator: (validationMetadata),
105
+ decorator: innerValidationDecorator,
105
106
  args: [min, key, meta],
106
107
  })
107
108
  .apply();
@@ -117,17 +118,16 @@ export function min(value, message = DEFAULT_ERROR_MESSAGES.MIN) {
117
118
  * @category Property Decorators
118
119
  */
119
120
  export function max(value, message = DEFAULT_ERROR_MESSAGES.MAX) {
120
- const key = Validation.key(ValidationKeys.MAX);
121
+ const key = ValidationKeys.MAX;
121
122
  const meta = {
122
123
  [ValidationKeys.MAX]: value,
123
124
  message: message,
124
- types: [Number.name, Date.name],
125
125
  description: `defines the max value of the attribute as ${value} (applies to numbers or Dates)`,
126
126
  async: false,
127
127
  };
128
128
  return Decoration.for(key)
129
129
  .define({
130
- decorator: (validationMetadata),
130
+ decorator: innerValidationDecorator,
131
131
  args: [max, key, meta],
132
132
  })
133
133
  .apply();
@@ -143,17 +143,16 @@ export function max(value, message = DEFAULT_ERROR_MESSAGES.MAX) {
143
143
  * @category Property Decorators
144
144
  */
145
145
  export function step(value, message = DEFAULT_ERROR_MESSAGES.STEP) {
146
- const key = Validation.key(ValidationKeys.STEP);
146
+ const key = ValidationKeys.STEP;
147
147
  const meta = {
148
148
  [ValidationKeys.STEP]: value,
149
149
  message: message,
150
- types: [Number.name],
151
150
  description: `defines the step of the attribute as ${value}`,
152
151
  async: false,
153
152
  };
154
153
  return Decoration.for(key)
155
154
  .define({
156
- decorator: (validationMetadata),
155
+ decorator: innerValidationDecorator,
157
156
  args: [step, key, meta],
158
157
  })
159
158
  .apply();
@@ -169,17 +168,16 @@ export function step(value, message = DEFAULT_ERROR_MESSAGES.STEP) {
169
168
  * @category Property Decorators
170
169
  */
171
170
  export function minlength(value, message = DEFAULT_ERROR_MESSAGES.MIN_LENGTH) {
172
- const key = Validation.key(ValidationKeys.MIN_LENGTH);
171
+ const key = ValidationKeys.MIN_LENGTH;
173
172
  const meta = {
174
173
  [ValidationKeys.MIN_LENGTH]: value,
175
174
  message: message,
176
- types: [String.name, Array.name, Set.name],
177
175
  description: `defines the min length of the attribute as ${value} (applies to strings or lists)`,
178
176
  async: false,
179
177
  };
180
178
  return Decoration.for(key)
181
179
  .define({
182
- decorator: (validationMetadata),
180
+ decorator: innerValidationDecorator,
183
181
  args: [minlength, key, meta],
184
182
  })
185
183
  .apply();
@@ -195,17 +193,16 @@ export function minlength(value, message = DEFAULT_ERROR_MESSAGES.MIN_LENGTH) {
195
193
  * @category Property Decorators
196
194
  */
197
195
  export function maxlength(value, message = DEFAULT_ERROR_MESSAGES.MAX_LENGTH) {
198
- const key = Validation.key(ValidationKeys.MAX_LENGTH);
196
+ const key = ValidationKeys.MAX_LENGTH;
199
197
  const meta = {
200
198
  [ValidationKeys.MAX_LENGTH]: value,
201
199
  message: message,
202
- types: [String.name, Array.name, Set.name],
203
200
  description: `defines the max length of the attribute as ${value} (applies to strings or lists)`,
204
201
  async: false,
205
202
  };
206
203
  return Decoration.for(key)
207
204
  .define({
208
- decorator: (validationMetadata),
205
+ decorator: innerValidationDecorator,
209
206
  args: [maxlength, key, meta],
210
207
  })
211
208
  .apply();
@@ -221,17 +218,16 @@ export function maxlength(value, message = DEFAULT_ERROR_MESSAGES.MAX_LENGTH) {
221
218
  * @category Property Decorators
222
219
  */
223
220
  export function pattern(value, message = DEFAULT_ERROR_MESSAGES.PATTERN) {
224
- const key = Validation.key(ValidationKeys.PATTERN);
221
+ const key = ValidationKeys.PATTERN;
225
222
  const meta = {
226
223
  [ValidationKeys.PATTERN]: typeof value === "string" ? value : value.toString(),
227
224
  message: message,
228
- types: [String.name],
229
225
  description: `assigns the ${value === "string" ? value : value.toString()} pattern to the attribute`,
230
226
  async: false,
231
227
  };
232
228
  return Decoration.for(key)
233
229
  .define({
234
- decorator: (validationMetadata),
230
+ decorator: innerValidationDecorator,
235
231
  args: [pattern, key, meta],
236
232
  })
237
233
  .apply();
@@ -246,17 +242,16 @@ export function pattern(value, message = DEFAULT_ERROR_MESSAGES.PATTERN) {
246
242
  * @category Property Decorators
247
243
  */
248
244
  export function email(message = DEFAULT_ERROR_MESSAGES.EMAIL) {
249
- const key = Validation.key(ValidationKeys.EMAIL);
245
+ const key = ValidationKeys.EMAIL;
250
246
  const meta = {
251
247
  [ValidationKeys.PATTERN]: DEFAULT_PATTERNS.EMAIL.toString(),
252
248
  message: message,
253
- types: [String.name],
254
249
  description: "marks the attribute as an email",
255
250
  async: false,
256
251
  };
257
252
  return Decoration.for(key)
258
253
  .define({
259
- decorator: (validationMetadata),
254
+ decorator: innerValidationDecorator,
260
255
  args: [email, key, meta],
261
256
  })
262
257
  .apply();
@@ -271,17 +266,16 @@ export function email(message = DEFAULT_ERROR_MESSAGES.EMAIL) {
271
266
  * @category Property Decorators
272
267
  */
273
268
  export function url(message = DEFAULT_ERROR_MESSAGES.URL) {
274
- const key = Validation.key(ValidationKeys.URL);
269
+ const key = ValidationKeys.URL;
275
270
  const meta = {
276
271
  [ValidationKeys.PATTERN]: DEFAULT_PATTERNS.URL.toString(),
277
272
  message: message,
278
- types: [String.name],
279
273
  description: "marks the attribute as an url",
280
274
  async: false,
281
275
  };
282
276
  return Decoration.for(key)
283
277
  .define({
284
- decorator: (validationMetadata),
278
+ decorator: innerValidationDecorator,
285
279
  args: [url, key, meta],
286
280
  })
287
281
  .apply();
@@ -290,14 +284,15 @@ export function url(message = DEFAULT_ERROR_MESSAGES.URL) {
290
284
  * @summary Enforces type verification
291
285
  * @description Validators to validate a decorated property must use key {@link ValidationKeys#TYPE}
292
286
  *
293
- * @param {string[] | string} types accepted types
294
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#TYPE}
287
+ * @param {Constructor[] | Constructor} types accepted types
288
+ * @param {Constructor} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#TYPE}
295
289
  *
296
290
  * @function type
297
291
  * @category Property Decorators
298
292
  */
293
+ //TODO
299
294
  export function type(types, message = DEFAULT_ERROR_MESSAGES.TYPE) {
300
- const key = Validation.key(ValidationKeys.TYPE);
295
+ const key = ValidationKeys.TYPE;
301
296
  const meta = {
302
297
  customTypes: types,
303
298
  message: message,
@@ -306,7 +301,7 @@ export function type(types, message = DEFAULT_ERROR_MESSAGES.TYPE) {
306
301
  };
307
302
  return Decoration.for(key)
308
303
  .define({
309
- decorator: (validationMetadata),
304
+ decorator: innerValidationDecorator,
310
305
  args: [type, key, meta],
311
306
  })
312
307
  .apply();
@@ -325,19 +320,70 @@ export function type(types, message = DEFAULT_ERROR_MESSAGES.TYPE) {
325
320
  * @category Property Decorators
326
321
  */
327
322
  export function date(format = "dd/MM/yyyy", message = DEFAULT_ERROR_MESSAGES.DATE) {
328
- const key = Validation.key(ValidationKeys.DATE);
329
- function dateDec(format, message) {
323
+ const key = ValidationKeys.DATE;
324
+ function innerDateDec(format, message) {
330
325
  const meta = {
331
326
  [ValidationKeys.FORMAT]: format,
332
327
  message: message,
333
- types: [Date.name],
334
328
  description: `defines the attribute as a date with the format ${format}`,
335
329
  async: false,
336
330
  };
331
+ // return function dateDec(
332
+ // target: Record<string, any>,
333
+ // propertyKey?: any
334
+ // ): any {
335
+ // const definitionTarget =
336
+ // typeof target === "function" ? target.prototype : target;
337
+ // const values = new WeakMap<any, Date | undefined>();
338
+ //
339
+ // const ensureInstanceDescriptor = (instance: any) => {
340
+ // if (
341
+ // Object.prototype.hasOwnProperty.call(instance, propertyKey) &&
342
+ // !Object.getOwnPropertyDescriptor(instance, propertyKey)?.configurable
343
+ // )
344
+ // return;
345
+ //
346
+ // Object.defineProperty(instance, propertyKey, {
347
+ // enumerable: true,
348
+ // configurable: false,
349
+ // get(this: any) {
350
+ // return values.get(this);
351
+ // },
352
+ // set(this: any, newValue: string | Date | number | undefined | null) {
353
+ // if (typeof newValue === "undefined" || newValue === null) {
354
+ // values.delete(this);
355
+ // return;
356
+ // }
357
+ //
358
+ // try {
359
+ // const val = parseDate(format, newValue);
360
+ // values.set(this, val);
361
+ // } catch (e: any) {
362
+ // console.error(sf("Failed to parse date: {0}", e.message || e));
363
+ // }
364
+ // },
365
+ // });
366
+ // };
367
+ //
368
+ // Object.defineProperty(definitionTarget, propertyKey, {
369
+ // configurable: true,
370
+ // enumerable: true,
371
+ // get(this: any) {
372
+ // ensureInstanceDescriptor(this);
373
+ // return (this as any)[propertyKey];
374
+ // },
375
+ // set(this: any, newValue: string | Date | number | undefined | null) {
376
+ // ensureInstanceDescriptor(this);
377
+ // (this as any)[propertyKey] = newValue;
378
+ // },
379
+ // });
380
+ //
381
+ // return innerValidationDecorator(date, key, meta)(target, propertyKey);
382
+ // };
337
383
  return function dateDec(target, propertyKey) {
338
384
  const values = new WeakMap();
339
385
  Object.defineProperty(target, propertyKey, {
340
- configurable: false,
386
+ configurable: true,
341
387
  set(newValue) {
342
388
  const descriptor = Object.getOwnPropertyDescriptor(this, propertyKey);
343
389
  if (!descriptor || descriptor.configurable)
@@ -362,12 +408,12 @@ export function date(format = "dd/MM/yyyy", message = DEFAULT_ERROR_MESSAGES.DAT
362
408
  return values.get(this);
363
409
  },
364
410
  });
365
- return validationMetadata(date, key, meta)(target, propertyKey);
411
+ return innerValidationDecorator(date, key, meta)(target, propertyKey);
366
412
  };
367
413
  }
368
414
  return Decoration.for(key)
369
415
  .define({
370
- decorator: dateDec,
416
+ decorator: innerDateDec,
371
417
  args: [format, message],
372
418
  })
373
419
  .apply();
@@ -384,17 +430,16 @@ export function date(format = "dd/MM/yyyy", message = DEFAULT_ERROR_MESSAGES.DAT
384
430
  * @category Property Decorators
385
431
  */
386
432
  export function password(pattern = DEFAULT_PATTERNS.PASSWORD.CHAR8_ONE_OF_EACH, message = DEFAULT_ERROR_MESSAGES.PASSWORD) {
387
- const key = Validation.key(ValidationKeys.PASSWORD);
433
+ const key = ValidationKeys.PASSWORD;
388
434
  const meta = {
389
435
  [ValidationKeys.PATTERN]: pattern.toString(),
390
436
  message: message,
391
- types: [String.name],
392
437
  description: `attribute as a password`,
393
438
  async: false,
394
439
  };
395
440
  return Decoration.for(key)
396
441
  .define({
397
- decorator: validationMetadata,
442
+ decorator: innerValidationDecorator,
398
443
  args: [password, key, meta],
399
444
  })
400
445
  .apply();
@@ -412,11 +457,9 @@ export function password(pattern = DEFAULT_PATTERNS.PASSWORD.CHAR8_ONE_OF_EACH,
412
457
  * @category Property Decorators
413
458
  */
414
459
  export function list(clazz, collection = "Array", message = DEFAULT_ERROR_MESSAGES.LIST) {
415
- const key = Validation.key(ValidationKeys.LIST);
460
+ const key = ValidationKeys.LIST;
416
461
  const meta = {
417
- clazz: (Array.isArray(clazz)
418
- ? clazz.map((c) => (c.name ? c.name : c))
419
- : [clazz.name ? clazz.name : clazz]),
462
+ clazz: (Array.isArray(clazz) ? clazz : [clazz]),
420
463
  type: collection,
421
464
  message: message,
422
465
  async: false,
@@ -424,7 +467,7 @@ export function list(clazz, collection = "Array", message = DEFAULT_ERROR_MESSAG
424
467
  };
425
468
  return Decoration.for(key)
426
469
  .define({
427
- decorator: validationMetadata,
470
+ decorator: innerValidationDecorator,
428
471
  args: [list, key, meta],
429
472
  })
430
473
  .apply();
@@ -466,7 +509,10 @@ export function eq(propertyToCompare, options
466
509
  [ValidationKeys.EQUALS]: propertyToCompare,
467
510
  description: `defines attribute as equal to ${propertyToCompare}`,
468
511
  };
469
- return validationMetadata(eq, Validation.key(ValidationKeys.EQUALS), { ...equalsOptions, async: false });
512
+ return innerValidationDecorator(eq, ValidationKeys.EQUALS, {
513
+ ...equalsOptions,
514
+ async: false,
515
+ });
470
516
  }
471
517
  /**
472
518
  * @summary Declares that the decorated property must be different from another specified property.
@@ -489,7 +535,7 @@ export function diff(propertyToCompare, options) {
489
535
  [ValidationKeys.DIFF]: propertyToCompare,
490
536
  description: `defines attribute as different to ${propertyToCompare}`,
491
537
  };
492
- return validationMetadata(diff, Validation.key(ValidationKeys.DIFF), {
538
+ return innerValidationDecorator(diff, ValidationKeys.DIFF, {
493
539
  ...diffOptions,
494
540
  async: false,
495
541
  });
@@ -515,7 +561,10 @@ export function lt(propertyToCompare, options) {
515
561
  [ValidationKeys.LESS_THAN]: propertyToCompare,
516
562
  description: `defines attribute as less than to ${propertyToCompare}`,
517
563
  };
518
- return validationMetadata(lt, Validation.key(ValidationKeys.LESS_THAN), { ...ltOptions, async: false });
564
+ return innerValidationDecorator(lt, ValidationKeys.LESS_THAN, {
565
+ ...ltOptions,
566
+ async: false,
567
+ });
519
568
  }
520
569
  /**
521
570
  * @summary Declares that the decorated property must be equal or less than another specified property.
@@ -538,7 +587,10 @@ export function lte(propertyToCompare, options) {
538
587
  [ValidationKeys.LESS_THAN_OR_EQUAL]: propertyToCompare,
539
588
  description: `defines attribute as less or equal to ${propertyToCompare}`,
540
589
  };
541
- return validationMetadata(lte, Validation.key(ValidationKeys.LESS_THAN_OR_EQUAL), { ...lteOptions, async: false });
590
+ return innerValidationDecorator(lte, ValidationKeys.LESS_THAN_OR_EQUAL, {
591
+ ...lteOptions,
592
+ async: false,
593
+ });
542
594
  }
543
595
  /**
544
596
  * @summary Declares that the decorated property must be greater than another specified property.
@@ -561,7 +613,10 @@ export function gt(propertyToCompare, options) {
561
613
  [ValidationKeys.GREATER_THAN]: propertyToCompare,
562
614
  description: `defines attribute as greater than ${propertyToCompare}`,
563
615
  };
564
- return validationMetadata(gt, Validation.key(ValidationKeys.GREATER_THAN), { ...gtOptions, async: false });
616
+ return innerValidationDecorator(gt, ValidationKeys.GREATER_THAN, {
617
+ ...gtOptions,
618
+ async: false,
619
+ });
565
620
  }
566
621
  /**
567
622
  * @summary Declares that the decorated property must be equal or greater than another specified property.
@@ -584,6 +639,34 @@ export function gte(propertyToCompare, options) {
584
639
  [ValidationKeys.GREATER_THAN_OR_EQUAL]: propertyToCompare,
585
640
  description: `defines attribute as greater or equal to ${propertyToCompare}`,
586
641
  };
587
- return validationMetadata(gte, Validation.key(ValidationKeys.GREATER_THAN_OR_EQUAL), { ...gteOptions, async: false });
642
+ return innerValidationDecorator(gte, ValidationKeys.GREATER_THAN_OR_EQUAL, {
643
+ ...gteOptions,
644
+ async: false,
645
+ });
646
+ }
647
+ /**
648
+ * @summary Defines a list or an object of accepted values for the property
649
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#ENUM}
650
+ *
651
+ * @param {any[] | Record<any, any>} value
652
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#ENUM}
653
+ *
654
+ * @function option
655
+ * @category Property Decorators
656
+ */
657
+ export function option(value, message = DEFAULT_ERROR_MESSAGES.ENUM) {
658
+ const key = ValidationKeys.ENUM;
659
+ const meta = {
660
+ [ValidationKeys.ENUM]: value,
661
+ message: message,
662
+ description: `defines a list or an object of accepted values for the attribute`,
663
+ async: false,
664
+ };
665
+ return Decoration.for(key)
666
+ .define({
667
+ decorator: innerValidationDecorator,
668
+ args: [option, key, meta],
669
+ })
670
+ .apply();
588
671
  }
589
672
  //# sourceMappingURL=decorators.js.map