@decaf-ts/decorator-validation 1.0.7

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 (151) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +302 -0
  3. package/dist/decorator-validation.bundle.min.js +2 -0
  4. package/dist/decorator-validation.bundle.min.js.LICENSE.txt +14 -0
  5. package/dist/esm/decorator-validation.bundle.min.esm.js +2 -0
  6. package/dist/esm/decorator-validation.bundle.min.esm.js.LICENSE.txt +14 -0
  7. package/lib/esm/index.d.ts +61 -0
  8. package/lib/esm/index.js +1 -0
  9. package/lib/esm/model/Model.d.ts +160 -0
  10. package/lib/esm/model/Model.js +1 -0
  11. package/lib/esm/model/ModelErrorDefinition.d.ts +22 -0
  12. package/lib/esm/model/ModelErrorDefinition.js +3 -0
  13. package/lib/esm/model/Registry.d.ts +61 -0
  14. package/lib/esm/model/Registry.js +1 -0
  15. package/lib/esm/model/constants.d.ts +40 -0
  16. package/lib/esm/model/constants.js +1 -0
  17. package/lib/esm/model/construction.d.ts +45 -0
  18. package/lib/esm/model/construction.js +1 -0
  19. package/lib/esm/model/decorators.d.ts +33 -0
  20. package/lib/esm/model/decorators.js +1 -0
  21. package/lib/esm/model/index.d.ts +7 -0
  22. package/lib/esm/model/index.js +1 -0
  23. package/lib/esm/model/types.d.ts +67 -0
  24. package/lib/esm/model/types.js +0 -0
  25. package/lib/esm/utils/constants.d.ts +22 -0
  26. package/lib/esm/utils/constants.js +1 -0
  27. package/lib/esm/utils/general.d.ts +193 -0
  28. package/lib/esm/utils/general.js +1 -0
  29. package/lib/esm/utils/index.d.ts +4 -0
  30. package/lib/esm/utils/index.js +1 -0
  31. package/lib/esm/utils/registry.d.ts +68 -0
  32. package/lib/esm/utils/registry.js +0 -0
  33. package/lib/esm/utils/serialization.d.ts +65 -0
  34. package/lib/esm/utils/serialization.js +1 -0
  35. package/lib/esm/validation/Validation.d.ts +39 -0
  36. package/lib/esm/validation/Validation.js +1 -0
  37. package/lib/esm/validation/Validators/DateValidator.d.ts +29 -0
  38. package/lib/esm/validation/Validators/DateValidator.js +1 -0
  39. package/lib/esm/validation/Validators/EmailValidator.d.ts +29 -0
  40. package/lib/esm/validation/Validators/EmailValidator.js +1 -0
  41. package/lib/esm/validation/Validators/ListValidator.d.ts +29 -0
  42. package/lib/esm/validation/Validators/ListValidator.js +1 -0
  43. package/lib/esm/validation/Validators/MaxLengthValidator.d.ts +30 -0
  44. package/lib/esm/validation/Validators/MaxLengthValidator.js +1 -0
  45. package/lib/esm/validation/Validators/MaxValidator.d.ts +29 -0
  46. package/lib/esm/validation/Validators/MaxValidator.js +1 -0
  47. package/lib/esm/validation/Validators/MinLengthValidator.d.ts +30 -0
  48. package/lib/esm/validation/Validators/MinLengthValidator.js +1 -0
  49. package/lib/esm/validation/Validators/MinValidator.d.ts +29 -0
  50. package/lib/esm/validation/Validators/MinValidator.js +1 -0
  51. package/lib/esm/validation/Validators/PasswordValidator.d.ts +31 -0
  52. package/lib/esm/validation/Validators/PasswordValidator.js +1 -0
  53. package/lib/esm/validation/Validators/PatternValidator.d.ts +38 -0
  54. package/lib/esm/validation/Validators/PatternValidator.js +1 -0
  55. package/lib/esm/validation/Validators/RequiredValidator.d.ts +28 -0
  56. package/lib/esm/validation/Validators/RequiredValidator.js +1 -0
  57. package/lib/esm/validation/Validators/StepValidator.d.ts +29 -0
  58. package/lib/esm/validation/Validators/StepValidator.js +1 -0
  59. package/lib/esm/validation/Validators/TypeValidator.d.ts +28 -0
  60. package/lib/esm/validation/Validators/TypeValidator.js +1 -0
  61. package/lib/esm/validation/Validators/URLValidator.d.ts +28 -0
  62. package/lib/esm/validation/Validators/URLValidator.js +1 -0
  63. package/lib/esm/validation/Validators/Validator.d.ts +42 -0
  64. package/lib/esm/validation/Validators/Validator.js +1 -0
  65. package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +47 -0
  66. package/lib/esm/validation/Validators/ValidatorRegistry.js +1 -0
  67. package/lib/esm/validation/Validators/constants.d.ts +91 -0
  68. package/lib/esm/validation/Validators/constants.js +1 -0
  69. package/lib/esm/validation/Validators/index.d.ts +50 -0
  70. package/lib/esm/validation/Validators/index.js +1 -0
  71. package/lib/esm/validation/Validators/types.d.ts +51 -0
  72. package/lib/esm/validation/Validators/types.js +0 -0
  73. package/lib/esm/validation/decorators.d.ts +263 -0
  74. package/lib/esm/validation/decorators.js +1 -0
  75. package/lib/esm/validation/index.d.ts +13 -0
  76. package/lib/esm/validation/index.js +1 -0
  77. package/lib/esm/validation/types.d.ts +53 -0
  78. package/lib/esm/validation/types.js +0 -0
  79. package/lib/index.cjs +1 -0
  80. package/lib/index.d.ts +61 -0
  81. package/lib/model/Model.cjs +1 -0
  82. package/lib/model/Model.d.ts +160 -0
  83. package/lib/model/ModelErrorDefinition.cjs +3 -0
  84. package/lib/model/ModelErrorDefinition.d.ts +22 -0
  85. package/lib/model/Registry.cjs +1 -0
  86. package/lib/model/Registry.d.ts +61 -0
  87. package/lib/model/constants.cjs +1 -0
  88. package/lib/model/constants.d.ts +40 -0
  89. package/lib/model/construction.cjs +1 -0
  90. package/lib/model/construction.d.ts +45 -0
  91. package/lib/model/decorators.cjs +1 -0
  92. package/lib/model/decorators.d.ts +33 -0
  93. package/lib/model/index.cjs +1 -0
  94. package/lib/model/index.d.ts +7 -0
  95. package/lib/model/types.cjs +1 -0
  96. package/lib/model/types.d.ts +67 -0
  97. package/lib/utils/constants.cjs +1 -0
  98. package/lib/utils/constants.d.ts +22 -0
  99. package/lib/utils/general.cjs +1 -0
  100. package/lib/utils/general.d.ts +193 -0
  101. package/lib/utils/index.cjs +1 -0
  102. package/lib/utils/index.d.ts +4 -0
  103. package/lib/utils/registry.cjs +1 -0
  104. package/lib/utils/registry.d.ts +68 -0
  105. package/lib/utils/serialization.cjs +1 -0
  106. package/lib/utils/serialization.d.ts +65 -0
  107. package/lib/validation/Validation.cjs +1 -0
  108. package/lib/validation/Validation.d.ts +39 -0
  109. package/lib/validation/Validators/DateValidator.cjs +1 -0
  110. package/lib/validation/Validators/DateValidator.d.ts +29 -0
  111. package/lib/validation/Validators/EmailValidator.cjs +1 -0
  112. package/lib/validation/Validators/EmailValidator.d.ts +29 -0
  113. package/lib/validation/Validators/ListValidator.cjs +1 -0
  114. package/lib/validation/Validators/ListValidator.d.ts +29 -0
  115. package/lib/validation/Validators/MaxLengthValidator.cjs +1 -0
  116. package/lib/validation/Validators/MaxLengthValidator.d.ts +30 -0
  117. package/lib/validation/Validators/MaxValidator.cjs +1 -0
  118. package/lib/validation/Validators/MaxValidator.d.ts +29 -0
  119. package/lib/validation/Validators/MinLengthValidator.cjs +1 -0
  120. package/lib/validation/Validators/MinLengthValidator.d.ts +30 -0
  121. package/lib/validation/Validators/MinValidator.cjs +1 -0
  122. package/lib/validation/Validators/MinValidator.d.ts +29 -0
  123. package/lib/validation/Validators/PasswordValidator.cjs +1 -0
  124. package/lib/validation/Validators/PasswordValidator.d.ts +31 -0
  125. package/lib/validation/Validators/PatternValidator.cjs +1 -0
  126. package/lib/validation/Validators/PatternValidator.d.ts +38 -0
  127. package/lib/validation/Validators/RequiredValidator.cjs +1 -0
  128. package/lib/validation/Validators/RequiredValidator.d.ts +28 -0
  129. package/lib/validation/Validators/StepValidator.cjs +1 -0
  130. package/lib/validation/Validators/StepValidator.d.ts +29 -0
  131. package/lib/validation/Validators/TypeValidator.cjs +1 -0
  132. package/lib/validation/Validators/TypeValidator.d.ts +28 -0
  133. package/lib/validation/Validators/URLValidator.cjs +1 -0
  134. package/lib/validation/Validators/URLValidator.d.ts +28 -0
  135. package/lib/validation/Validators/Validator.cjs +1 -0
  136. package/lib/validation/Validators/Validator.d.ts +42 -0
  137. package/lib/validation/Validators/ValidatorRegistry.cjs +1 -0
  138. package/lib/validation/Validators/ValidatorRegistry.d.ts +47 -0
  139. package/lib/validation/Validators/constants.cjs +1 -0
  140. package/lib/validation/Validators/constants.d.ts +91 -0
  141. package/lib/validation/Validators/index.cjs +1 -0
  142. package/lib/validation/Validators/index.d.ts +50 -0
  143. package/lib/validation/Validators/types.cjs +1 -0
  144. package/lib/validation/Validators/types.d.ts +51 -0
  145. package/lib/validation/decorators.cjs +1 -0
  146. package/lib/validation/decorators.d.ts +263 -0
  147. package/lib/validation/index.cjs +1 -0
  148. package/lib/validation/index.d.ts +13 -0
  149. package/lib/validation/types.cjs +1 -0
  150. package/lib/validation/types.d.ts +53 -0
  151. package/package.json +96 -0
@@ -0,0 +1,263 @@
1
+ import "reflect-metadata";
2
+ import { Validator } from "./Validators";
3
+ import { Constructor, ModelConstructor } from "../model";
4
+ /**
5
+ * @summary Builds the key to store as Metadata under Reflections
6
+ * @description concatenates {@link ValidationKeys#REFLECT} with the provided key
7
+ *
8
+ * @param {string} key
9
+ *
10
+ * @function getModelKey
11
+ * @memberOf module:decorator-validation.Utils
12
+ * @category Utilities
13
+ */
14
+ export declare function getValidationKey(key: string): string;
15
+ /**
16
+ * @summary Marks the property as required.
17
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#REQUIRED}
18
+ *
19
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
20
+ * @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link RequiredValidator}
21
+ *
22
+ * @function required
23
+ * @memberOf module:decorator-validation.Decorators.Validation
24
+ * @category Decorators
25
+ */
26
+ export declare function required(message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
27
+ /**
28
+ * @summary Defines a minimum value for the property
29
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#MIN}
30
+ *
31
+ * @param {number | Date} value
32
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN}
33
+ * @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link MinValidator}
34
+ *
35
+ * @function min
36
+ * @memberOf module:decorator-validation.Decorators.Validation
37
+ * @category Decorators
38
+ */
39
+ export declare function min(value: number | Date | string, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
40
+ /**
41
+ * @summary Defines a maximum value for the property
42
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX}
43
+ *
44
+ * @param {number | Date} value
45
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX}
46
+ * @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link MaxValidator}
47
+ *
48
+ * @function max
49
+ * @memberOf module:decorator-validation.Decorators.Validation
50
+ * @category Decorators
51
+ */
52
+ export declare function max(value: number | Date | string, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
53
+ /**
54
+ * @summary Defines a step value for the property
55
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#STEP}
56
+ *
57
+ * @param {number} value
58
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
59
+ * @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link StepValidator}
60
+ *
61
+ * @function step
62
+ * @memberOf module:decorator-validation.Decorators.Validation
63
+ * @category Decorators
64
+ */
65
+ export declare function step(value: number, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
66
+ /**
67
+ * @summary Defines a minimum length for the property
68
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#MIN_LENGTH}
69
+ *
70
+ * @param {string} value
71
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN_LENGTH}
72
+ * @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link MinLengthValidator}
73
+ *
74
+ * @function minlength
75
+ * @memberOf module:decorator-validation.Decorators.Validation
76
+ * @category Decorators
77
+ */
78
+ export declare function minlength(value: number, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
79
+ /**
80
+ * @summary Defines a maximum length for the property
81
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX_LENGTH}
82
+ *
83
+ * @param {string} value
84
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX_LENGTH}
85
+ * @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link MaxLengthValidator}
86
+ *
87
+ * @function maxlength
88
+ * @memberOf module:decorator-validation.Decorators.Validation
89
+ * @category Decorators
90
+ */
91
+ export declare function maxlength(value: number, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
92
+ /**
93
+ * @summary Defines a RegExp pattern the property must respect
94
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#PATTERN}
95
+ *
96
+ * @param {string} value
97
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
98
+ * @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link PatternValidator}
99
+ *
100
+ * @function pattern
101
+ * @memberOf module:decorator-validation.Decorators.Validation
102
+ * @category Decorators
103
+ */
104
+ export declare function pattern(value: RegExp | string, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
105
+ /**
106
+ * @summary Defines the property as an email
107
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#EMAIL}
108
+ *
109
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
110
+ * @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link EmailValidator}
111
+ *
112
+ * @function email
113
+ * @memberOf module:decorator-validation.Decorators.Validation
114
+ * @category Decorators
115
+ */
116
+ export declare function email(message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
117
+ /**
118
+ * @summary Defines the property as an URL
119
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#URL}
120
+ *
121
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#URL}
122
+ * @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link URLValidator}
123
+ *
124
+ * @function url
125
+ * @memberOf module:decorator-validation.Decorators.Validation
126
+ * @category Decorators
127
+ */
128
+ export declare function url(message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
129
+ /**
130
+ * @summary Enforces type verification
131
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#TYPE}
132
+ *
133
+ * @param {string[] | string} types accepted types
134
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#TYPE}
135
+ * @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link TypeValidator}
136
+ *
137
+ * @function type
138
+ * @memberOf module:decorator-validation.Decorators.Validation
139
+ * @category Decorators
140
+ */
141
+ export declare function type(types: string[] | string, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
142
+ /**
143
+ * @summary Binds a date format to a string
144
+ * @param {Date} [date]
145
+ * @param {string} [format]
146
+ * @memberOf module:decorator-validation.Utils.Format
147
+ * @category Utilities
148
+ */
149
+ export declare function bindDateToString(date: Date | undefined, format: string): Date | undefined;
150
+ /**
151
+ * @summary Helper function to be used instead of instanceOf Date
152
+ * @param date
153
+ * @memberOf module:decorator-validation.Utils.Dates
154
+ * @category Validation
155
+ */
156
+ export declare function isValidDate(date: any): boolean;
157
+ /**
158
+ * @summary Util function to pad numbers
159
+ * @param {number} num
160
+ *
161
+ * @return {string}
162
+ *
163
+ * @function twoDigitPad
164
+ * @memberOf module:decorator-validation.Utils.Format
165
+ * @category Format
166
+ */
167
+ export declare function twoDigitPad(num: number): string;
168
+ /**
169
+ * @summary Date Format Handling
170
+ * @description Code from {@link https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date}
171
+ *
172
+ * <pre>
173
+ * Using similar formatting as Moment.js, Class DateTimeFormatter (Java), and Class SimpleDateFormat (Java),
174
+ * I implemented a comprehensive solution formatDate(date, patternStr) where the code is easy to read and modify.
175
+ * You can display date, time, AM/PM, etc.
176
+ *
177
+ * Date and Time Patterns
178
+ * yy = 2-digit year; yyyy = full year
179
+ * M = digit month; MM = 2-digit month; MMM = short month name; MMMM = full month name
180
+ * EEEE = full weekday name; EEE = short weekday name
181
+ * d = digit day; dd = 2-digit day
182
+ * h = hours am/pm; hh = 2-digit hours am/pm; H = hours; HH = 2-digit hours
183
+ * m = minutes; mm = 2-digit minutes; aaa = AM/PM
184
+ * s = seconds; ss = 2-digit seconds
185
+ * S = miliseconds
186
+ * </pre>
187
+ *
188
+ * @param {Date} date
189
+ * @param {string} [patternStr] defaults to 'yyyy/MM/dd'
190
+ * @return {string} the formatted date
191
+ *
192
+ * @function formatDate
193
+ * @memberOf module:decorator-validation.Utils.Dates
194
+ * @category Format
195
+ */
196
+ export declare function formatDate(date: Date, patternStr?: string): string;
197
+ /**
198
+ * @summary Parses a date from a specified format
199
+ * @param {string} format
200
+ * @param {string | Date | number} [v]
201
+ * @memberOf module:decorator-validation.Utils.Dates
202
+ * @category Format
203
+ */
204
+ export declare function parseDate(format: string, v?: string | Date | number): Date | undefined;
205
+ /**
206
+ * @summary Date Handler Decorator
207
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#DATE}
208
+ *
209
+ * Will enforce serialization according to the selected format
210
+ *
211
+ * @param {string} format accepted format according to {@link formatDate}
212
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
213
+ * @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link DateValidator}
214
+ *
215
+ * @function date
216
+ *
217
+ * @memberOf module:decorator-validation.Decorators.Validation
218
+ * @category Decorators
219
+ */
220
+ export declare function date(format?: string, message?: string, validator?: Constructor<Validator>): (target: Record<string, any>, propertyKey: string) => any;
221
+ /**
222
+ * @summary Password Handler Decorator
223
+ * @description Validators to validate a decorated property must use key {@link ValidationKeys#PASSWORD}
224
+ *
225
+ * @param {RegExp} [pattern] defaults to {@link PasswordPatterns#CHAR8_ONE_OF_EACH}
226
+ * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PASSWORD}
227
+ * @param {Constructor<Validator>} [validator] Defaults to {@link PasswordValidator}
228
+ *
229
+ * @function password
230
+ *
231
+ * @memberOf module:decorator-validation.Decorators.Validation
232
+ * @category Decorators
233
+ */
234
+ export declare function password(pattern?: RegExp, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
235
+ /**
236
+ * @summary List Decorator
237
+ * @description Also sets the {@link type} to the provided collection
238
+ *
239
+ * @param {ModelConstructor} clazz
240
+ * @param {string} [collection] The collection being used. defaults to Array
241
+ * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
242
+ * @param {Constructor<Validator>} [validator] defaults to {@link ListValidator}
243
+ *
244
+ * @function list
245
+ *
246
+ * @memberOf module:decorator-validation.Decorators.Validation
247
+ * @category Decorators
248
+ */
249
+ export declare function list(clazz: ModelConstructor<any>, collection?: "Array" | "Set", message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => any;
250
+ /**
251
+ * @summary Set Decorator
252
+ * @description Wrapper for {@link list} with the 'Set' Collection
253
+ *
254
+ * @param {ModelConstructor} clazz
255
+ * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
256
+ * @param {Constructor<Validator>} [validator]
257
+ *
258
+ * @function set
259
+ *
260
+ * @memberOf module:decorator-validation.Decorators.Validation
261
+ * @category Decorators
262
+ */
263
+ export declare function set(clazz: ModelConstructor<any>, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => any;
@@ -0,0 +1 @@
1
+ import"reflect-metadata";import{ValidationKeys,DEFAULT_ERROR_MESSAGES,PasswordPatterns,MONTH_NAMES,DAYS_OF_WEEK_NAMES}from"./Validators";import{DateValidator,EmailValidator,MaxLengthValidator,MaxValidator,MinLengthValidator,MinValidator,PasswordValidator,PatternValidator,RequiredValidator,StepValidator,TypeValidator,URLValidator}from"./Validators";import{dateFromFormat,stringFormat}from"../utils";import{ListValidator}from"./Validators/ListValidator";import{Validation}from"./Validation";function getValidationKey(e){return ValidationKeys.REFLECT+e}function required(t=DEFAULT_ERROR_MESSAGES.REQUIRED,i=RequiredValidator){return(e,a)=>{Reflect.defineMetadata(getValidationKey(ValidationKeys.REQUIRED),{message:t},e,a),Validation.register({validator:i,validationKey:ValidationKeys.REQUIRED,save:!0})}}function min(t,i=DEFAULT_ERROR_MESSAGES.MIN,r=MinValidator){return(e,a)=>{Reflect.defineMetadata(getValidationKey(ValidationKeys.MIN),{value:t,message:i,types:[Number.name,Date.name]},e,a),Validation.register({validator:r,validationKey:ValidationKeys.MIN,save:!0})}}function max(t,i=DEFAULT_ERROR_MESSAGES.MAX,r=MaxValidator){return(e,a)=>{Reflect.defineMetadata(getValidationKey(ValidationKeys.MAX),{value:t,message:i,types:[Number.name,Date.name]},e,a),Validation.register({validator:r,validationKey:ValidationKeys.MAX,save:!0})}}function step(t,i=DEFAULT_ERROR_MESSAGES.STEP,r=StepValidator){return(e,a)=>{Reflect.defineMetadata(getValidationKey(ValidationKeys.STEP),{value:t,message:i,types:[Number.name]},e,a),Validation.register({validator:r,validationKey:ValidationKeys.STEP,save:!0})}}function minlength(t,i=DEFAULT_ERROR_MESSAGES.MIN_LENGTH,r=MinLengthValidator){return(e,a)=>{Reflect.defineMetadata(getValidationKey(ValidationKeys.MIN_LENGTH),{value:t,message:i,types:[String.name,Array.name,Set.name]},e,a),Validation.register({validator:r,validationKey:ValidationKeys.MIN_LENGTH,save:!0})}}function maxlength(t,i=DEFAULT_ERROR_MESSAGES.MAX_LENGTH,r=MaxLengthValidator){return(e,a)=>{Reflect.defineMetadata(getValidationKey(ValidationKeys.MAX_LENGTH),{value:t,message:i,types:[String.name,Array.name,Set.name]},e,a),Validation.register({validator:r,validationKey:ValidationKeys.MAX_LENGTH,save:!0})}}function pattern(t,i=DEFAULT_ERROR_MESSAGES.PATTERN,r=PatternValidator){return(e,a)=>{Reflect.defineMetadata(getValidationKey(ValidationKeys.PATTERN),{value:"string"==typeof t?t:t.toString(),message:i,types:[String.name]},e,a),Validation.register({validator:r,validationKey:ValidationKeys.PATTERN,save:!0})}}function email(t=DEFAULT_ERROR_MESSAGES.EMAIL,i=EmailValidator){return(e,a)=>{Reflect.defineMetadata(getValidationKey(ValidationKeys.EMAIL),{message:t,types:[String.name]},e,a),Validation.register({validator:i,validationKey:ValidationKeys.EMAIL,save:!0})}}function url(t=DEFAULT_ERROR_MESSAGES.URL,i=URLValidator){return(e,a)=>{Reflect.defineMetadata(getValidationKey(ValidationKeys.URL),{message:t,types:[String.name]},e,a),Validation.register({validator:i,validationKey:ValidationKeys.URL,save:!0})}}function type(t,i=DEFAULT_ERROR_MESSAGES.TYPE,r=TypeValidator){return(e,a)=>{Reflect.defineMetadata(getValidationKey(ValidationKeys.TYPE),{customTypes:t,message:i},e,a),Validation.register({validator:r,validationKey:ValidationKeys.TYPE,save:!0})}}function bindDateToString(e,a){var t;if(e)return t=()=>formatDate(e,a),Object.defineProperty(e,"toISOString",{enumerable:!1,configurable:!1,value:t}),Object.defineProperty(e,"toString",{enumerable:!1,configurable:!1,value:t}),e}function isValidDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}function twoDigitPad(e){return e<10?"0"+e:e.toString()}function formatDate(e,a="yyyy/MM/dd"){var t=e.getDate(),i=e.getMonth(),r=e.getFullYear(),n=e.getHours(),o=e.getMinutes(),l=e.getSeconds(),d=e.getMilliseconds(),s=n%12,E=twoDigitPad(s),g=twoDigitPad(n),y=twoDigitPad(o),S=twoDigitPad(l),V=n<12?"AM":"PM",e=DAYS_OF_WEEK_NAMES[e.getDay()],m=e.substr(0,3),c=twoDigitPad(t),f=i+1,M=twoDigitPad(f),i=MONTH_NAMES[i],R=i.substr(0,3),r=r+"",u=r.substr(2,2);return a=-1<(a=a.replace("hh",E).replace("h",s.toString()).replace("HH",g).replace("H",n.toString()).replace("mm",y).replace("m",o.toString()).replace("ss",S).replace("s",l.toString()).replace("S",d.toString()).replace("dd",c).replace("d",t.toString()).replace("EEEE",e).replace("EEE",m).replace("yyyy",r).replace("yy",u).replace("aaa",V)).indexOf("MMM")?a.replace("MMMM",i).replace("MMM",R):a.replace("MM",M).replace("M",f.toString())}function parseDate(a,t){let e=void 0;if(t){if(t instanceof Date)try{e=dateFromFormat(formatDate(t,a),a)}catch(e){throw new Error(stringFormat("Could not convert date {0} to format: {1}",t.toString(),a))}else if("string"==typeof t)e=dateFromFormat(t,a);else if("number"==typeof t){var i=new Date(t);e=dateFromFormat(formatDate(i,a),a)}else{if(!isValidDate(t))throw new Error("Invalid value provided "+t);try{var r=new Date(t);e=dateFromFormat(formatDate(r,a),a)}catch(e){throw new Error(stringFormat("Could not convert date {0} to format: {1}",t,a))}}return bindDateToString(e,a)}}function date(r="dd/MM/yyyy",a=DEFAULT_ERROR_MESSAGES.DATE,n=DateValidator){return(e,t)=>{Reflect.defineMetadata(getValidationKey(ValidationKeys.DATE),{format:r,message:a,types:[Date.name]},e,t),Validation.register({validator:n,validationKey:ValidationKeys.DATE,save:!0});const i=new WeakMap;Object.defineProperty(e,t,{configurable:!1,set(e){var a=Object.getOwnPropertyDescriptor(this,t);a&&!a.configurable||Object.defineProperty(this,t,{enumerable:!0,configurable:!1,get:()=>i.get(this),set:e=>{var a;try{a=parseDate(r,e),i.set(this,a)}catch(e){console.error(stringFormat("Failed to parse date: {0}",e.message||e))}}}),this[t]=e},get(){console.log("here")}})}}function password(t=PasswordPatterns.CHAR8_ONE_OF_EACH,i=DEFAULT_ERROR_MESSAGES.PASSWORD,r=PasswordValidator){return(e,a)=>{Reflect.defineMetadata(getValidationKey(ValidationKeys.PASSWORD),{pattern:t,message:i,types:[String.name]},e,a),Validation.register({validator:r,validationKey:ValidationKeys.PASSWORD,save:!0})}}function list(t,i="Array",r=DEFAULT_ERROR_MESSAGES.LIST,n=ListValidator){return(e,a)=>{type(i)(e,a),Reflect.defineMetadata(getValidationKey(ValidationKeys.LIST),{class:t.name,type:i,message:r},e,a),Validation.register({validator:n,validationKey:ValidationKeys.LIST,save:!0})}}function set(t,i=DEFAULT_ERROR_MESSAGES.LIST,r){return(e,a)=>{list(t,"Set",i,r)(e,a)}}export{getValidationKey,required,min,max,step,minlength,maxlength,pattern,email,url,type,bindDateToString,isValidDate,twoDigitPad,formatDate,parseDate,date,password,list,set};
@@ -0,0 +1,13 @@
1
+ export * from "./types";
2
+ export * from "./Validators";
3
+ import { ValidatorRegistry } from "./Validators";
4
+ /**
5
+ * @summary exports the Validator Registry
6
+ * @constant ValidatorRegistryImp
7
+ * @memberOf module:decorator-validation.Validation
8
+ * @category Validation
9
+ */
10
+ export declare const ValidatorRegistryImp: typeof ValidatorRegistry;
11
+ export * as Decorators from "./decorators";
12
+ export * from "./decorators";
13
+ export * from "./Validation";
@@ -0,0 +1 @@
1
+ export*from"./types";export*from"./Validators";import{ValidatorRegistry}from"./Validators";const ValidatorRegistryImp=ValidatorRegistry;export*as Decorators from"./decorators";export*from"./decorators";export*from"./Validation";export{ValidatorRegistryImp};
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @summary Validator Error type
3
+ * @memberOf module:decorator-validation.Validation
4
+ * @category Validation
5
+ */
6
+ export type Errors = string | undefined;
7
+ /**
8
+ * @summary Type for decorator metadata
9
+ * @memberOf module:decorator-validation.Reflection
10
+ * @category Reflection
11
+ */
12
+ export type DecoratorMetadata = {
13
+ key: string;
14
+ props: Record<string, any>;
15
+ };
16
+ /**
17
+ * @summary Type for a validator property decorator definition
18
+ * @memberOf module:decorator-validation.Validation
19
+ * @category Validation
20
+ */
21
+ export type ValidationPropertyDecoratorDefinition = {
22
+ prop: string | symbol;
23
+ decorators: ValidationDecoratorDefinition[];
24
+ };
25
+ /**
26
+ * @summary Type for a validator decorator definition
27
+ * @memberOf module:decorator-validation.Validation
28
+ * @category Validation
29
+ */
30
+ export type ValidationDecoratorDefinition = DecoratorMetadata & {
31
+ props: ValidationElementDefinition;
32
+ };
33
+ /**
34
+ * @summary Type for a validator element metadata
35
+ * @memberOf module:decorator-validation.Validation
36
+ * @category Validation
37
+ */
38
+ export type ValidationElementDefinition = {
39
+ [indexer: string]: any;
40
+ value?: string | number;
41
+ message: string;
42
+ types?: string[];
43
+ };
44
+ /**
45
+ * @summary Type for a model errors
46
+ * @memberOf module:decorator-validation.Validation
47
+ * @category Validation
48
+ */
49
+ export type ModelErrors = {
50
+ [indexer: string]: {
51
+ [indexer: string]: Errors;
52
+ };
53
+ };
File without changes
package/lib/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&("get"in o?t.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,o)}:function(e,t,r,i){e[i=void 0===i?r:i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.VERSION=void 0,__exportStar(require("./utils/index.cjs"),exports),__exportStar(require("./validation/index.cjs"),exports),__exportStar(require("./model/index.cjs"),exports),exports.VERSION="1.0.7";
package/lib/index.d.ts ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @module decorator-validation
3
+ */
4
+ /**
5
+ * @summary Defines the Model object
6
+ * @namespace Model
7
+ * @memberOf module:decorator-validation
8
+ */
9
+ /**
10
+ * @summary Holds all the supported decorators
11
+ * @namespace Decorators
12
+ * @memberOf module:decorator-validation
13
+ */
14
+ /**
15
+ * @namespace Validation
16
+ * @memberOf module:decorator-validation.Decorators
17
+ */
18
+ /**
19
+ * @namespace Model
20
+ * @memberOf module:decorator-validation.Decorators
21
+ */
22
+ /**
23
+ * @namespace Construction
24
+ * @memberOf module:decorator-validation
25
+ */
26
+ /**
27
+ * @namespace Validation
28
+ * @memberOf module:decorator-validation
29
+ */
30
+ /**
31
+ * @namespace Validators
32
+ * @memberOf module:decorator-validation.Validation
33
+ */
34
+ /**
35
+ * @namespace Utils
36
+ * @memberOf module:decorator-validation
37
+ */
38
+ /**
39
+ * @namespace Dates
40
+ * @memberOf module:decorator-validation.Utils
41
+ */
42
+ /**
43
+ * @namespace Equality
44
+ * @memberOf module:decorator-validation.Utils
45
+ */
46
+ /**
47
+ * @namespace Hashing
48
+ * @memberOf module:decorator-validation.Utils
49
+ */
50
+ /**
51
+ * @namespace Serialization
52
+ * @memberOf module:decorator-validation.Utils
53
+ */
54
+ /**
55
+ * @namespace Format
56
+ * @memberOf module:decorator-validation.Utils
57
+ */
58
+ export * from "./utils";
59
+ export * from "./validation";
60
+ export * from "./model";
61
+ export declare const VERSION = "1.0.7";
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Model=exports.validate=void 0;const validation_1=require("../validation/index.cjs"),utils_1=require("../utils/index.cjs"),ModelErrorDefinition_1=require("./ModelErrorDefinition/index.cjs"),constants_1=require("./constants/index.cjs"),constants_2=require("../utils/constants/index.cjs"),construction_1=require("./construction/index.cjs"),Registry_1=require("./Registry/index.cjs"),Validation_1=require("../validation/Validation/index.cjs");function validate(n,...t){var e=[];for(const i in n)n.hasOwnProperty(i)&&-1===t.indexOf(i)&&e.push((0,utils_1.getPropertyDecorators)(validation_1.ValidationKeys.REFLECT,n,i));var r=e.reduce((t,r)=>{const{prop:i,decorators:s}=r;if(s&&s.length){const o=s[0];s.find(t=>t.key===validation_1.ValidationKeys.TYPE||!!t.props.types?.find(t=>t===o.props.name))&&s.shift();let e=s.reduce((t,e)=>{var r=Validation_1.Validation.get(e.key);return r&&(r=r.hasErrors(n[i.toString()],...e.key===constants_2.ModelKeys.TYPE?[e.props]:Object.values(e.props)))&&((t=t||{})[e.key]=r),t},void 0);(e=e||Object.keys(n).filter(t=>!e||!e[t]).reduce((t,r)=>{let i;const s=(0,utils_1.getPropertyDecorators)(validation_1.ValidationKeys.REFLECT,n,r).decorators;var e=s.filter(t=>-1!==[constants_2.ModelKeys.TYPE,validation_1.ValidationKeys.TYPE].indexOf(t.key));if(e&&e.length){e=e.pop(),e=e.props.name?[e.props.name]:Array.isArray(e.props.customTypes)?e.props.customTypes:[e.props.customTypes];const o=Object.values(constants_1.ReservedModels).map(t=>t.toLowerCase());e.forEach(t=>{if(-1===o.indexOf(t.toLowerCase()))switch(t){case"Array":case"Set":var e;s.length&&s.find(t=>t.key===validation_1.ValidationKeys.LIST)&&(e="Array"===t?n[r].find(t=>t.hasErrors()):n[r].values().find(t=>t.hasErrors()))&&(i=(0,utils_1.stringFormat)(validation_1.DEFAULT_ERROR_MESSAGES.LIST_INSIDE,e.toString()));break;default:try{n[r]&&(i=n[r].hasErrors())}catch(t){console.warn((0,utils_1.stringFormat)("Model should be validatable but its not"))}}}),i&&((t=t||{})[r]=i)}return t},void 0))&&((t=t||{})[r.prop.toString()]=e)}return t},void 0);return r?new ModelErrorDefinition_1.ModelErrorDefinition(r):void 0}exports.validate=validate;let modelBuilderFunction,actingModelRegistry,serializer,hashingFunction;class Model{constructor(t){}hasErrors(...t){return validate(this,...t)}equals(t,...e){return(0,utils_1.isEqual)(this,t,...e)}serialize(){return Model.serialize(this)}toString(){return this.constructor.name+": "+JSON.stringify(this,void 0,2)}toHash(){return Model.getHashingFunction()(this).toString()}static deserialize(t){return Model.getSerializer().deserialize(t)}static serialize(t){return Model.getSerializer().serialize(t)}static hash(t){return Model.getHashingFunction()(t)}static fromObject(t,e){return(0,construction_1.constructFromObject)(t,e)}static fromModel(t,e){return(0,construction_1.constructFromModel)(t,e)}static setBuilder(t){modelBuilderFunction=t}static getBuilder(){return modelBuilderFunction}static getRegistry(){return actingModelRegistry=actingModelRegistry||new Registry_1.ModelRegistryManager}static setRegistry(t){actingModelRegistry=t}static register(t,e){return Model.getRegistry().register(t,e)}static get(t){return Model.getRegistry().get(t)}static build(t={},e){return Model.getRegistry().build(t,e)}static setSerializer(t){serializer=t}static getSerializer(){return serializer=serializer||new utils_1.JSONSerializer}static setHashingFunction(t){hashingFunction=t}static getHashingFunction(){return hashingFunction=hashingFunction||utils_1.hashObj}}exports.Model=Model;
@@ -0,0 +1,160 @@
1
+ import { BuilderRegistry, HashingFunction, Serializer } from "../utils";
2
+ import { ModelErrorDefinition } from "./ModelErrorDefinition";
3
+ import { ModelArg, ModelConstructor, Serializable, Validatable } from "./types";
4
+ import { ModelBuilderFunction } from "./construction";
5
+ /**
6
+ * @summary Analyses the decorations of the properties and validates the obj according to them
7
+ *
8
+ * @typedef T extends Model
9
+ * @prop {T} obj Model object to validate
10
+ * @prop {string[]} [propsToIgnore] object properties to ignore in the validation
11
+ *
12
+ * @function validate
13
+ * @memberOf module:decorator-validation.Validation
14
+ * @category Validation
15
+ */
16
+ export declare function validate<T extends Model>(obj: T, ...propsToIgnore: string[]): ModelErrorDefinition | undefined;
17
+ /**
18
+ * @summary Abstract class representing a Validatable Model object
19
+ * @description Meant to be used as a base class for all Model classes
20
+ *
21
+ * Model objects must:
22
+ * - Have all their properties defined as optional;
23
+ * - Have all their properties initialized eg:
24
+ *
25
+ * <pre>
26
+ * class ClassName {
27
+ * propertyName?: PropertyType = undefined;
28
+ * }
29
+ * </pre>
30
+ *
31
+ * @param {Model | {}} model base object from which to populate properties from
32
+ *
33
+ * @class Model
34
+ * @abstract
35
+ * @implements Validatable
36
+ * @implements Serializable
37
+ *
38
+ * @category Model
39
+ */
40
+ export declare abstract class Model implements Validatable, Serializable {
41
+ [indexer: string]: any;
42
+ protected constructor(model?: ModelArg<Model>);
43
+ /**
44
+ * @summary Validates the object according to its decorated properties
45
+ *
46
+ * @param {any[]} [exceptions] properties in the object to be ignored for he validation. Marked as 'any' to allow for extension but expects strings
47
+ */
48
+ hasErrors(...exceptions: any[]): ModelErrorDefinition | undefined;
49
+ /**
50
+ * @summary Compare object equality recursively
51
+ * @param {any} obj object to compare to
52
+ * @param {string} [exceptions] property names to be excluded from the comparison
53
+ */
54
+ equals(obj: any, ...exceptions: string[]): boolean;
55
+ /**
56
+ * @summary Returns the serialized model according to the currently defined {@link Serializer}
57
+ */
58
+ serialize(): string;
59
+ /**
60
+ * @summary Override the implementation for js's 'toString()' which sucks...
61
+ * @override
62
+ */
63
+ toString(): string;
64
+ /**
65
+ * @summary Defines a default implementation for object hash. Relies on a very basic implementation based on Java's string hash;
66
+ */
67
+ toHash(): string;
68
+ /**
69
+ * @summary Deserializes a Model
70
+ * @param {string} str
71
+ *
72
+ * @throws {Error} If it fails to parse the string, or if it fails to build the model
73
+ */
74
+ static deserialize(str: string): any;
75
+ /**
76
+ * @summary Serializes a Model
77
+ * @param {Model} model
78
+ */
79
+ static serialize(model: any): string;
80
+ static hash(obj: any): string;
81
+ /**
82
+ * @summary Wrapper around {@link constructFromObject}
83
+ * @param {T} self
84
+ * @param {T | Record<string, any>} obj
85
+ */
86
+ static fromObject<T extends Model>(self: T, obj?: T | Record<string, any>): T;
87
+ /**
88
+ * @summary Wrapper around {@link constructFromModel}
89
+ * @param {T} self
90
+ * @param {T | Record<string, any>} obj
91
+ */
92
+ static fromModel<T extends Model>(self: T, obj?: T | Record<string, any>): T;
93
+ /**
94
+ * @summary Sets the Global {@link ModelBuilderFunction}
95
+ * @param {ModelBuilderFunction} [builder]
96
+ */
97
+ static setBuilder(builder?: ModelBuilderFunction): void;
98
+ /**
99
+ * @summary Retrieves the current global {@link ModelBuilderFunction}
100
+ */
101
+ static getBuilder(): ModelBuilderFunction | undefined;
102
+ /**
103
+ * Returns the current {@link ModelRegistryManager}
104
+ *
105
+ * @return ModelRegistry, defaults to {@link ModelRegistryManager}
106
+ */
107
+ private static getRegistry;
108
+ /**
109
+ * Returns the current actingModelRegistry
110
+ *
111
+ * @param {BuilderRegistry} modelRegistry the new implementation of Registry
112
+ */
113
+ static setRegistry(modelRegistry: BuilderRegistry<any>): void;
114
+ /**
115
+ * @summary register new Models
116
+ * @param {any} constructor
117
+ * @param {string} [name] when not defined, the name of the constructor will be used
118
+ *
119
+ * @see ModelRegistry
120
+ */
121
+ static register<T extends Model>(constructor: ModelConstructor<T>, name?: string): void;
122
+ /**
123
+ * @summary Gets a registered Model {@link ModelConstructor}
124
+ * @param {string} name
125
+ *
126
+ * @see ModelRegistry
127
+ */
128
+ static get<T extends Model>(name: string): ModelConstructor<T> | undefined;
129
+ /**
130
+ * @param {Record<string, any>} obj
131
+ * @param {string} [clazz] when provided, it will attempt to find the matching constructor
132
+ *
133
+ * @throws Error If clazz is not found, or obj is not a {@link Model} meaning it has no {@link ModelKeys.ANCHOR} property
134
+ *
135
+ * @see ModelRegistry
136
+ */
137
+ static build<T extends Model>(obj?: Record<string, any>, clazz?: string): T;
138
+ /**
139
+ * @summary Sets the {@link Serializer}
140
+ *
141
+ * @param {Serializer} ser
142
+ */
143
+ static setSerializer(ser: Serializer<any>): void;
144
+ /**
145
+ * @summary Retrieves the current defined {@link Serializer}
146
+ *
147
+ */
148
+ private static getSerializer;
149
+ /**
150
+ * @summary Sets the {@link HashingFunction}
151
+ *
152
+ * @param {HashingFunction} hasher
153
+ */
154
+ static setHashingFunction(hasher: HashingFunction): void;
155
+ /**
156
+ * @summary Retrieves the current defined {@link HashingFunction}
157
+ *
158
+ */
159
+ private static getHashingFunction;
160
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ModelErrorDefinition=void 0;class ModelErrorDefinition{constructor(e){for(const r in e)e.hasOwnProperty(r)&&e[r]&&Object.defineProperty(this,r,{enumerable:!0,configurable:!1,value:e[r],writable:!1})}toString(){const t=this;return Object.keys(t).filter(e=>t.hasOwnProperty(e)&&"function"!=typeof t[e]).reduce((e,o)=>{var r=Object.keys(t[o]).reduce((e,r)=>(e?e+=`
2
+ `+t[o][r]:e=t[o][r],e),void 0);return r&&(r=o+" - "+r,e?e+=`
3
+ `+r:e=r),e},"")}}exports.ModelErrorDefinition=ModelErrorDefinition;
@@ -0,0 +1,22 @@
1
+ import { Errors, ModelErrors } from "../validation";
2
+ /**
3
+ * @summary Helper Class to hold the error results
4
+ * @description holds error results in an 'indexable' manner
5
+ * while still providing the same result on toString
6
+ *
7
+ * @param {ModelErrors} errors
8
+ *
9
+ * @class ModelErrorDefinition
10
+ *
11
+ * @category Model
12
+ */
13
+ export declare class ModelErrorDefinition {
14
+ [indexer: string]: Record<string, Errors> | (() => Errors);
15
+ constructor(errors: ModelErrors);
16
+ /**
17
+ * @summary Outputs the class to a nice readable string
18
+ *
19
+ * @override
20
+ */
21
+ toString(): string;
22
+ }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.bulkModelRegister=exports.ModelRegistryManager=void 0;const Model_1=require("./Model/index.cjs"),utils_1=require("../utils/index.cjs"),constants_1=require("../utils/constants/index.cjs");class ModelRegistryManager{constructor(e=constants_1.ModelKeys.ANCHOR,t=utils_1.isModel){this.cache={},this.testFunction=t,this.anchorKey=e}register(e,t){if("function"!=typeof e)throw new Error("Model registering failed. Missing Class name or constructor");t=t||e.name,this.cache[t]=e}get(e){try{return this.cache[e]}catch(e){}}build(e={},t){if(!t&&!this.testFunction(e))throw new Error("Provided obj is not a Model object");t=t||e[this.anchorKey].class;if(t in this.cache)return new this.cache[t](e);throw new Error((0,utils_1.stringFormat)("Provided class {0} is not a registered Model object",t))}}function bulkModelRegister(...e){e.forEach(e=>{var t=e.constructor||e;Model_1.Model.register(t,e.name)})}exports.ModelRegistryManager=ModelRegistryManager,exports.bulkModelRegister=bulkModelRegister;