@nest-omni/core 1.0.7 → 1.0.8

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 (264) hide show
  1. package/package.json +4 -1
  2. package/src/boilerplate.polyfill.d.ts +0 -39
  3. package/src/boilerplate.polyfill.js +0 -78
  4. package/src/boilerplate.polyfill.ts +0 -202
  5. package/src/common/abstract-client.service.d.ts +0 -20
  6. package/src/common/abstract-client.service.js +0 -39
  7. package/src/common/abstract-client.service.ts +0 -56
  8. package/src/common/abstract.entity.d.ts +0 -24
  9. package/src/common/abstract.entity.js +0 -152
  10. package/src/common/abstract.entity.ts +0 -73
  11. package/src/common/dto/abstract.dto.d.ts +0 -13
  12. package/src/common/dto/abstract.dto.js +0 -96
  13. package/src/common/dto/abstract.dto.ts +0 -64
  14. package/src/common/dto/bulk-id.dto.d.ts +0 -3
  15. package/src/common/dto/bulk-id.dto.js +0 -63
  16. package/src/common/dto/bulk-id.dto.ts +0 -13
  17. package/src/common/dto/create-translation.dto.d.ts +0 -5
  18. package/src/common/dto/create-translation.dto.js +0 -63
  19. package/src/common/dto/create-translation.dto.ts +0 -10
  20. package/src/common/dto/page-meta.dto.d.ts +0 -15
  21. package/src/common/dto/page-meta.dto.js +0 -88
  22. package/src/common/dto/page-meta.dto.ts +0 -37
  23. package/src/common/dto/page-options.dto.d.ts +0 -8
  24. package/src/common/dto/page-options.dto.js +0 -87
  25. package/src/common/dto/page-options.dto.ts +0 -35
  26. package/src/common/dto/page.dto.d.ts +0 -11
  27. package/src/common/dto/page.dto.js +0 -94
  28. package/src/common/dto/page.dto.ts +0 -36
  29. package/src/common/utils.d.ts +0 -14
  30. package/src/common/utils.js +0 -39
  31. package/src/common/utils.ts +0 -45
  32. package/src/constants/index.d.ts +0 -4
  33. package/src/constants/index.js +0 -20
  34. package/src/constants/index.ts +0 -4
  35. package/src/constants/language-code.d.ts +0 -5
  36. package/src/constants/language-code.js +0 -10
  37. package/src/constants/language-code.ts +0 -7
  38. package/src/constants/order.d.ts +0 -4
  39. package/src/constants/order.js +0 -8
  40. package/src/constants/order.ts +0 -4
  41. package/src/constants/role-type.d.ts +0 -4
  42. package/src/constants/role-type.js +0 -8
  43. package/src/constants/role-type.ts +0 -4
  44. package/src/constants/token-type.d.ts +0 -4
  45. package/src/constants/token-type.js +0 -8
  46. package/src/constants/token-type.ts +0 -4
  47. package/src/decorators/api-page-ok-response.decorator.d.ts +0 -5
  48. package/src/decorators/api-page-ok-response.decorator.js +0 -25
  49. package/src/decorators/api-page-ok-response.decorator.ts +0 -31
  50. package/src/decorators/auth-user.decorator.d.ts +0 -1
  51. package/src/decorators/auth-user.decorator.js +0 -15
  52. package/src/decorators/auth-user.decorator.ts +0 -16
  53. package/src/decorators/controller.decorator.d.ts +0 -1
  54. package/src/decorators/controller.decorator.js +0 -34
  55. package/src/decorators/controller.decorator.ts +0 -8
  56. package/src/decorators/field.decorators.d.ts +0 -71
  57. package/src/decorators/field.decorators.js +0 -455
  58. package/src/decorators/field.decorators.ts +0 -773
  59. package/src/decorators/http.decorators.d.ts +0 -3
  60. package/src/decorators/http.decorators.js +0 -8
  61. package/src/decorators/http.decorators.ts +0 -10
  62. package/src/decorators/index.d.ts +0 -12
  63. package/src/decorators/index.js +0 -28
  64. package/src/decorators/index.ts +0 -12
  65. package/src/decorators/omni-auth.decorator.d.ts +0 -8
  66. package/src/decorators/omni-auth.decorator.js +0 -60
  67. package/src/decorators/omni-auth.decorator.ts +0 -46
  68. package/src/decorators/operation.decorator.d.ts +0 -1
  69. package/src/decorators/operation.decorator.js +0 -6
  70. package/src/decorators/operation.decorator.ts +0 -4
  71. package/src/decorators/property.decorators.d.ts +0 -15
  72. package/src/decorators/property.decorators.js +0 -36
  73. package/src/decorators/property.decorators.ts +0 -62
  74. package/src/decorators/public-route.decorator.d.ts +0 -3
  75. package/src/decorators/public-route.decorator.js +0 -8
  76. package/src/decorators/public-route.decorator.ts +0 -8
  77. package/src/decorators/swagger.schema.d.ts +0 -5
  78. package/src/decorators/swagger.schema.js +0 -82
  79. package/src/decorators/swagger.schema.ts +0 -117
  80. package/src/decorators/timestamp-column.decorator.d.ts +0 -1
  81. package/src/decorators/timestamp-column.decorator.js +0 -28
  82. package/src/decorators/timestamp-column.decorator.ts +0 -29
  83. package/src/decorators/transform.decorators.d.ts +0 -35
  84. package/src/decorators/transform.decorators.js +0 -122
  85. package/src/decorators/transform.decorators.ts +0 -147
  86. package/src/decorators/translate.decorator.d.ts +0 -5
  87. package/src/decorators/translate.decorator.js +0 -18
  88. package/src/decorators/translate.decorator.ts +0 -19
  89. package/src/decorators/use-dto.decorator.d.ts +0 -4
  90. package/src/decorators/use-dto.decorator.js +0 -9
  91. package/src/decorators/use-dto.decorator.ts +0 -11
  92. package/src/decorators/user-check.decorator.d.ts +0 -6
  93. package/src/decorators/user-check.decorator.js +0 -44
  94. package/src/decorators/user-check.decorator.ts +0 -30
  95. package/src/decorators/user.decorator.d.ts +0 -8
  96. package/src/decorators/user.decorator.js +0 -62
  97. package/src/decorators/user.decorator.ts +0 -48
  98. package/src/decorators/user_auth.decorator.d.ts +0 -1
  99. package/src/decorators/user_auth.decorator.js +0 -16
  100. package/src/decorators/user_auth.decorator.ts +0 -15
  101. package/src/decorators/validator.decorators.d.ts +0 -10
  102. package/src/decorators/validator.decorators.js +0 -59
  103. package/src/decorators/validator.decorators.ts +0 -78
  104. package/src/exceptions/file-not-image.exception.d.ts +0 -4
  105. package/src/exceptions/file-not-image.exception.js +0 -10
  106. package/src/exceptions/file-not-image.exception.ts +0 -7
  107. package/src/exceptions/index.d.ts +0 -2
  108. package/src/exceptions/index.js +0 -18
  109. package/src/exceptions/index.ts +0 -2
  110. package/src/exceptions/page-type.exception.d.ts +0 -4
  111. package/src/exceptions/page-type.exception.js +0 -10
  112. package/src/exceptions/page-type.exception.ts +0 -7
  113. package/src/exceptions/user-not-found.exception.d.ts +0 -4
  114. package/src/exceptions/user-not-found.exception.js +0 -10
  115. package/src/exceptions/user-not-found.exception.ts +0 -7
  116. package/src/filters/bad-request.filter.d.ts +0 -5
  117. package/src/filters/bad-request.filter.js +0 -104
  118. package/src/filters/bad-request.filter.ts +0 -67
  119. package/src/filters/constraint-errors.d.ts +0 -1
  120. package/src/filters/constraint-errors.js +0 -7
  121. package/src/filters/constraint-errors.ts +0 -5
  122. package/src/filters/index.d.ts +0 -3
  123. package/src/filters/index.js +0 -19
  124. package/src/filters/index.ts +0 -3
  125. package/src/filters/query-failed.filter.d.ts +0 -10
  126. package/src/filters/query-failed.filter.js +0 -81
  127. package/src/filters/query-failed.filter.ts +0 -32
  128. package/src/health-checker/health-checker.controller.d.ts +0 -15
  129. package/src/health-checker/health-checker.controller.js +0 -104
  130. package/src/health-checker/health-checker.controller.ts +0 -51
  131. package/src/health-checker/health-checker.module.d.ts +0 -2
  132. package/src/health-checker/health-checker.module.js +0 -69
  133. package/src/health-checker/health-checker.module.ts +0 -13
  134. package/src/health-checker/health-indicators/service.indicator.d.ts +0 -8
  135. package/src/health-checker/health-indicators/service.indicator.js +0 -102
  136. package/src/health-checker/health-indicators/service.indicator.ts +0 -44
  137. package/src/helpers/common.helper.d.ts +0 -16
  138. package/src/helpers/common.helper.js +0 -49
  139. package/src/helpers/common.helper.ts +0 -49
  140. package/src/helpers/date.helper.d.ts +0 -10
  141. package/src/helpers/date.helper.js +0 -81
  142. package/src/helpers/date.helper.ts +0 -64
  143. package/src/helpers/excel.helper.d.ts +0 -27
  144. package/src/helpers/excel.helper.js +0 -338
  145. package/src/helpers/index.d.ts +0 -3
  146. package/src/helpers/index.js +0 -19
  147. package/src/helpers/index.ts +0 -3
  148. package/src/i18n/en_US/validation.json +0 -38
  149. package/src/i18n/zh_CN/validation.json +0 -38
  150. package/src/index.d.ts +0 -11
  151. package/src/index.js +0 -28
  152. package/src/index.ts +0 -12
  153. package/src/interceptors/auth-user.interceptor.d.ts +0 -4
  154. package/src/interceptors/auth-user.interceptor.js +0 -68
  155. package/src/interceptors/auth-user.interceptor.ts +0 -20
  156. package/src/interceptors/index.d.ts +0 -2
  157. package/src/interceptors/index.js +0 -18
  158. package/src/interceptors/index.ts +0 -2
  159. package/src/interceptors/language-interceptor.service.d.ts +0 -6
  160. package/src/interceptors/language-interceptor.service.js +0 -74
  161. package/src/interceptors/language-interceptor.service.ts +0 -31
  162. package/src/interceptors/translation-interceptor.service.d.ts +0 -5
  163. package/src/interceptors/translation-interceptor.service.js +0 -83
  164. package/src/interceptors/translation-interceptor.service.ts +0 -43
  165. package/src/interfaces/IApiFile.d.ts +0 -4
  166. package/src/interfaces/IApiFile.js +0 -2
  167. package/src/interfaces/IApiFile.ts +0 -4
  168. package/src/interfaces/IFile.d.ts +0 -9
  169. package/src/interfaces/IFile.js +0 -2
  170. package/src/interfaces/IFile.ts +0 -8
  171. package/src/interfaces/ITranslationDecoratorInterface.d.ts +0 -3
  172. package/src/interfaces/ITranslationDecoratorInterface.js +0 -2
  173. package/src/interfaces/ITranslationDecoratorInterface.ts +0 -3
  174. package/src/interfaces/index.d.ts +0 -3
  175. package/src/interfaces/index.js +0 -19
  176. package/src/interfaces/index.ts +0 -3
  177. package/src/interfaces/response.d.ts +0 -25
  178. package/src/interfaces/response.js +0 -2
  179. package/src/interfaces/response.ts +0 -37
  180. package/src/middlewares/index.d.ts +0 -3
  181. package/src/middlewares/index.js +0 -19
  182. package/src/middlewares/index.ts +0 -3
  183. package/src/middlewares/omni-auth.middleware.d.ts +0 -1
  184. package/src/middlewares/omni-auth.middleware.js +0 -13
  185. package/src/middlewares/omni-auth.middleware.ts +0 -10
  186. package/src/middlewares/powerby.middleware.d.ts +0 -1
  187. package/src/middlewares/powerby.middleware.js +0 -10
  188. package/src/middlewares/powerby.middleware.ts +0 -6
  189. package/src/middlewares/request-id.middleware.d.ts +0 -7
  190. package/src/middlewares/request-id.middleware.js +0 -22
  191. package/src/middlewares/request-id.middleware.ts +0 -28
  192. package/src/providers/context.provider.d.ts +0 -32
  193. package/src/providers/context.provider.js +0 -73
  194. package/src/providers/context.provider.ts +0 -98
  195. package/src/providers/generator.provider.d.ts +0 -13
  196. package/src/providers/generator.provider.js +0 -54
  197. package/src/providers/generator.provider.ts +0 -66
  198. package/src/providers/index.d.ts +0 -2
  199. package/src/providers/index.js +0 -18
  200. package/src/providers/index.ts +0 -2
  201. package/src/setup/bootstrap.setup.d.ts +0 -5
  202. package/src/setup/bootstrap.setup.js +0 -138
  203. package/src/setup/bootstrap.setup.ts +0 -139
  204. package/src/setup/index.d.ts +0 -1
  205. package/src/setup/index.js +0 -17
  206. package/src/setup/index.ts +0 -1
  207. package/src/setup/microservices.setup.js +0 -55
  208. package/src/setup-swagger.d.ts +0 -2
  209. package/src/setup-swagger.js +0 -62
  210. package/src/setup-swagger.ts +0 -67
  211. package/src/shared/index.d.ts +0 -2
  212. package/src/shared/index.js +0 -18
  213. package/src/shared/index.ts +0 -2
  214. package/src/shared/serviceRegistryModule.d.ts +0 -2
  215. package/src/shared/serviceRegistryModule.js +0 -176
  216. package/src/shared/serviceRegistryModule.ts +0 -110
  217. package/src/shared/services/api-config.service.d.ts +0 -73
  218. package/src/shared/services/api-config.service.js +0 -335
  219. package/src/shared/services/api-config.service.ts +0 -319
  220. package/src/shared/services/aws-s3.service.d.ts +0 -10
  221. package/src/shared/services/aws-s3.service.js +0 -96
  222. package/src/shared/services/aws-s3.service.ts +0 -39
  223. package/src/shared/services/generator.service.d.ts +0 -4
  224. package/src/shared/services/generator.service.js +0 -67
  225. package/src/shared/services/generator.service.ts +0 -13
  226. package/src/shared/services/index.d.ts +0 -5
  227. package/src/shared/services/index.js +0 -21
  228. package/src/shared/services/index.ts +0 -5
  229. package/src/shared/services/translation.service.d.ts +0 -9
  230. package/src/shared/services/translation.service.js +0 -109
  231. package/src/shared/services/translation.service.ts +0 -59
  232. package/src/shared/services/validator.service.d.ts +0 -3
  233. package/src/shared/services/validator.service.js +0 -64
  234. package/src/shared/services/validator.service.ts +0 -10
  235. package/src/snake-naming.strategy.d.ts +0 -11
  236. package/src/snake-naming.strategy.js +0 -37
  237. package/src/snake-naming.strategy.ts +0 -64
  238. package/src/types.d.ts +0 -9
  239. package/src/types.js +0 -2
  240. package/src/types.ts +0 -44
  241. package/src/validators/file-mimetype.validator.d.ts +0 -13
  242. package/src/validators/file-mimetype.validator.js +0 -21
  243. package/src/validators/file-mimetype.validator.ts +0 -34
  244. package/src/validators/index.d.ts +0 -3
  245. package/src/validators/index.js +0 -19
  246. package/src/validators/index.ts +0 -3
  247. package/src/validators/is-exists.validator.d.ts +0 -18
  248. package/src/validators/is-exists.validator.js +0 -99
  249. package/src/validators/is-exists.validator.ts +0 -60
  250. package/src/validators/is-unique.validator.d.ts +0 -17
  251. package/src/validators/is-unique.validator.js +0 -131
  252. package/src/validators/is-unique.validator.ts +0 -93
  253. package/src/validators/phone-country-code.validator.d.ts +0 -2
  254. package/src/validators/phone-country-code.validator.js +0 -30
  255. package/src/validators/phone-country-code.validator.ts +0 -36
  256. package/src/validators/same-as.validator.d.ts +0 -2
  257. package/src/validators/same-as.validator.js +0 -25
  258. package/src/validators/same-as.validator.ts +0 -27
  259. package/src/validators/skip-empty.validator.d.ts +0 -6
  260. package/src/validators/skip-empty.validator.js +0 -23
  261. package/src/validators/skip-empty.validator.ts +0 -25
  262. package/tsconfig.json +0 -30
  263. package/tsconfig.lib.json +0 -16
  264. package/tsconfig.tsbuildinfo +0 -1
@@ -1,773 +0,0 @@
1
- import { applyDecorators } from '@nestjs/common';
2
- import type { ApiPropertyOptions } from '@nestjs/swagger';
3
- import { ApiProperty } from '@nestjs/swagger';
4
- import { i18nValidationMessage } from 'nestjs-i18n';
5
- import { Type } from 'class-transformer';
6
- import {
7
- ArrayMaxSize,
8
- ArrayMinSize,
9
- IsBoolean,
10
- IsDate,
11
- IsDefined,
12
- IsEmail,
13
- IsEnum,
14
- IsFQDN,
15
- IsInt,
16
- IsIP,
17
- IsNumber,
18
- IsObject,
19
- IsPositive,
20
- IsString,
21
- IsUrl,
22
- IsUUID,
23
- Max,
24
- MaxDate,
25
- MaxLength,
26
- Min,
27
- MinDate,
28
- MinLength,
29
- NotEquals,
30
- ValidateNested,
31
- } from 'class-validator';
32
-
33
- import { supportedLanguageCount } from '../constants';
34
- import { ApiEnumProperty, ApiUUIDProperty } from './property.decorators';
35
- import {
36
- PhoneNumberSerializer,
37
- ToArray,
38
- ToBoolean,
39
- ToLowerCase,
40
- ToUpperCase,
41
- } from './transform.decorators';
42
- import {
43
- IsEmptyable,
44
- IsNullable,
45
- IsPhoneNumber,
46
- IsTmpKey as IsTemporaryKey,
47
- } from './validator.decorators';
48
- import ValidatorJS from 'validator';
49
-
50
- type RequireField<T, K extends keyof T> = T & Required<Pick<T, K>>;
51
-
52
- interface IFieldOptions {
53
- each?: boolean;
54
- swagger?: boolean;
55
- nullable?: boolean;
56
- group?: string[];
57
- message?: string;
58
- }
59
-
60
- interface INumberFieldOptions extends IFieldOptions {
61
- min?: number;
62
- max?: number;
63
- int?: boolean;
64
- isPositive?: boolean;
65
- }
66
-
67
- interface IDateFieldOptions extends IFieldOptions {
68
- minDate?: Date | (() => Date);
69
- maxDate?: Date | (() => Date);
70
- }
71
-
72
- interface IStringFieldOptions extends IFieldOptions {
73
- minLength?: number;
74
- maxLength?: number;
75
- toLowerCase?: boolean;
76
- toUpperCase?: boolean;
77
- }
78
-
79
- interface IEmailFieldOptions {
80
- emailOptions?: ValidatorJS.IsEmailOptions;
81
- }
82
-
83
- interface IIPFieldOptions {
84
- version?: ValidatorJS.IPVersion;
85
- }
86
-
87
- interface IFQDNFieldOptions extends ValidatorJS.IsFQDNOptions {}
88
-
89
- type IClassFieldOptions = IFieldOptions;
90
- type IBooleanFieldOptions = IFieldOptions;
91
- type IEnumFieldOptions = IFieldOptions;
92
-
93
- export function NumberField(
94
- options: Omit<ApiPropertyOptions, 'type'> & INumberFieldOptions = {},
95
- ): PropertyDecorator {
96
- const decorators = [Type(() => Number)];
97
-
98
- if (options.nullable) {
99
- decorators.push(
100
- IsNullable({
101
- each: options.each,
102
- }),
103
- );
104
- } else {
105
- decorators.push(
106
- NotEquals(null, {
107
- each: options.each,
108
- message: i18nValidationMessage('validation.NOT_EQUALS'),
109
- }),
110
- );
111
- }
112
-
113
- if (options.swagger !== false) {
114
- decorators.push(ApiProperty({ type: Number, ...options }));
115
- }
116
-
117
- if (options.each) {
118
- decorators.push(ToArray());
119
- }
120
-
121
- if (options.int) {
122
- decorators.push(
123
- IsInt({
124
- each: options.each,
125
- message: i18nValidationMessage('validation.IS_INT'),
126
- }),
127
- );
128
- } else {
129
- decorators.push(
130
- IsNumber(
131
- {},
132
- {
133
- each: options.each,
134
- message: i18nValidationMessage('validation.IS_NUMBER'),
135
- },
136
- ),
137
- );
138
- }
139
-
140
- if (typeof options.min === 'number') {
141
- decorators.push(
142
- Min(options.min, {
143
- each: options.each,
144
- message: i18nValidationMessage('validation.MIN'),
145
- }),
146
- );
147
- }
148
-
149
- if (typeof options.max === 'number') {
150
- decorators.push(
151
- Max(options.max, {
152
- each: options.each,
153
- message: i18nValidationMessage('validation.MAX'),
154
- }),
155
- );
156
- }
157
-
158
- if (options.isPositive) {
159
- decorators.push(
160
- IsPositive({
161
- each: options.each,
162
- message: i18nValidationMessage('validation.IS_POSITIVE'),
163
- }),
164
- );
165
- }
166
-
167
- return applyDecorators(...decorators);
168
- }
169
-
170
- export function NumberFieldOptional(
171
- options: Omit<ApiPropertyOptions, 'type' | 'required'> &
172
- INumberFieldOptions = {},
173
- ): PropertyDecorator {
174
- return applyDecorators(
175
- IsEmptyable(),
176
- NumberField({ required: false, ...options }),
177
- );
178
- }
179
-
180
- export function StringField(
181
- options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions = {},
182
- ): PropertyDecorator {
183
- const decorators = [
184
- Type(() => String),
185
- IsString({
186
- each: options.each,
187
- message: i18nValidationMessage('validation.IS_STRING'),
188
- }),
189
- ];
190
-
191
- if (options.nullable) {
192
- decorators.push(IsNullable({ each: options.each }));
193
- } else {
194
- decorators.push(
195
- NotEquals(null, {
196
- each: options.each,
197
- message: i18nValidationMessage('validation.NOT_EQUALS'),
198
- }),
199
- );
200
- }
201
-
202
- if (options.swagger !== false) {
203
- decorators.push(
204
- ApiProperty({ type: String, ...options, isArray: options.each }),
205
- );
206
- }
207
-
208
- const minLength = options.minLength ?? 1;
209
-
210
- decorators.push(
211
- MinLength(minLength, {
212
- each: options.each,
213
- message: i18nValidationMessage('validation.MIN_LENGTH'),
214
- }),
215
- );
216
-
217
- if (options.maxLength) {
218
- decorators.push(
219
- MaxLength(options.maxLength, {
220
- each: options.each,
221
- message: i18nValidationMessage('validation.MAX_LENGTH'),
222
- }),
223
- );
224
- }
225
-
226
- if (options.toLowerCase) {
227
- decorators.push(ToLowerCase());
228
- }
229
-
230
- if (options.toUpperCase) {
231
- decorators.push(ToUpperCase());
232
- }
233
-
234
- return applyDecorators(...decorators);
235
- }
236
-
237
- export function StringFieldOptional(
238
- options: Omit<ApiPropertyOptions, 'type' | 'required'> &
239
- IStringFieldOptions = {},
240
- ): PropertyDecorator {
241
- return applyDecorators(
242
- IsEmptyable(),
243
- StringField({ required: false, ...options }),
244
- );
245
- }
246
-
247
- export function PasswordField(
248
- options: Omit<ApiPropertyOptions, 'type' | 'minLength'> &
249
- IStringFieldOptions = {},
250
- ): PropertyDecorator {
251
- const decorators = [
252
- StringField({ ...options, minLength: 6 }) /*IsPassword()*/,
253
- ];
254
-
255
- if (options.nullable) {
256
- decorators.push(IsNullable());
257
- } else {
258
- decorators.push(NotEquals(null));
259
- }
260
-
261
- return applyDecorators(...decorators);
262
- }
263
-
264
- export function PasswordFieldOptional(
265
- options: Omit<ApiPropertyOptions, 'type' | 'required' | 'minLength'> &
266
- IStringFieldOptions = {},
267
- ): PropertyDecorator {
268
- return applyDecorators(
269
- IsEmptyable(),
270
- PasswordField({ required: false, ...options }),
271
- );
272
- }
273
-
274
- export function BooleanField(
275
- options: Omit<ApiPropertyOptions, 'type'> & IBooleanFieldOptions = {},
276
- ): PropertyDecorator {
277
- const decorators = [
278
- ToBoolean(),
279
- IsBoolean({ message: 'validation.INVALID_BOOLEAN' }),
280
- ];
281
-
282
- if (options.nullable) {
283
- decorators.push(IsNullable());
284
- } else {
285
- decorators.push(NotEquals(null));
286
- }
287
-
288
- if (options.swagger !== false) {
289
- decorators.push(ApiProperty({ type: Boolean, ...options }));
290
- }
291
-
292
- return applyDecorators(...decorators);
293
- }
294
-
295
- export function BooleanFieldOptional(
296
- options: Omit<ApiPropertyOptions, 'type' | 'required'> &
297
- IBooleanFieldOptions = {},
298
- ): PropertyDecorator {
299
- return applyDecorators(
300
- IsEmptyable(),
301
- BooleanField({ required: false, ...options }),
302
- );
303
- }
304
-
305
- export function TranslationsField(
306
- options: RequireField<Omit<ApiPropertyOptions, 'isArray'>, 'type'> &
307
- IFieldOptions,
308
- ): PropertyDecorator {
309
- const decorators = [
310
- ArrayMinSize(supportedLanguageCount),
311
- ArrayMaxSize(supportedLanguageCount),
312
- ValidateNested({
313
- each: true,
314
- }),
315
- Type(() => options.type as FunctionConstructor),
316
- ];
317
-
318
- if (options.nullable) {
319
- decorators.push(IsNullable());
320
- } else {
321
- decorators.push(NotEquals(null));
322
- }
323
-
324
- if (options.swagger !== false) {
325
- decorators.push(ApiProperty({ isArray: true, ...options }));
326
- }
327
-
328
- return applyDecorators(...decorators);
329
- }
330
-
331
- export function TranslationsFieldOptional(
332
- options: RequireField<Omit<ApiPropertyOptions, 'isArray'>, 'type'> &
333
- IFieldOptions,
334
- ): PropertyDecorator {
335
- return applyDecorators(
336
- IsEmptyable(),
337
- TranslationsField({ required: false, ...options }),
338
- );
339
- }
340
-
341
- export function TmpKeyField(
342
- options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions = {},
343
- ): PropertyDecorator {
344
- const decorators = [
345
- StringField(options),
346
- IsTemporaryKey({ each: options.each }),
347
- ];
348
-
349
- if (options.nullable) {
350
- decorators.push(IsNullable());
351
- } else {
352
- decorators.push(NotEquals(null));
353
- }
354
-
355
- if (options.swagger !== false) {
356
- decorators.push(
357
- ApiProperty({ type: String, ...options, isArray: options.each }),
358
- );
359
- }
360
-
361
- return applyDecorators(...decorators);
362
- }
363
-
364
- export function TmpKeyFieldOptional(
365
- options: Omit<ApiPropertyOptions, 'type' | 'required'> &
366
- IStringFieldOptions = {},
367
- ): PropertyDecorator {
368
- return applyDecorators(
369
- IsEmptyable(),
370
- TmpKeyField({ required: false, ...options }),
371
- );
372
- }
373
-
374
- export function getEnumDescription(enumType: any): string {
375
- const keys = Object.keys(enumType).filter(
376
- (k) => typeof enumType[k as any] === 'number',
377
- );
378
- return keys.map((k) => `${enumType[k]}: ${k}`).join(', ');
379
- }
380
-
381
- // eslint-disable-next-line @typescript-eslint/ban-types
382
- export function EnumField<TEnum extends object>(
383
- getEnum: () => TEnum,
384
- options: Omit<ApiPropertyOptions, 'type' | 'enum' | 'enumName' | 'isArray'> &
385
- IEnumFieldOptions = {},
386
- ): PropertyDecorator {
387
- // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/ban-types
388
- const enumValue = getEnum();
389
- const decorators = [
390
- IsEnum(enumValue, {
391
- each: options.each,
392
- message: i18nValidationMessage('validation.IS_ENUM'),
393
- }),
394
- ];
395
-
396
- if (options.nullable) {
397
- decorators.push(IsNullable());
398
- } else {
399
- decorators.push(NotEquals(null));
400
- }
401
-
402
- if (options.each) {
403
- decorators.push(ToArray());
404
- }
405
-
406
- if (options.swagger !== false) {
407
- decorators.push(
408
- ApiEnumProperty(getEnum, {
409
- ...options,
410
- isArray: options.each,
411
- }),
412
- );
413
- }
414
-
415
- return applyDecorators(...decorators);
416
- }
417
-
418
- // eslint-disable-next-line @typescript-eslint/ban-types
419
- export function ClassField<TClass extends object>(
420
- getClass: () => TClass,
421
- options: Omit<ApiPropertyOptions, 'type'> & IClassFieldOptions = {},
422
- ): PropertyDecorator {
423
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
424
- const classValue = getClass() as any;
425
-
426
- if (!classValue) {
427
- throw new Error('ClassField: recursive class definition');
428
- }
429
-
430
- const decorators = [
431
- Type(() => classValue),
432
- ValidateNested({ each: options.each }),
433
- ];
434
-
435
- if (options.required !== false) {
436
- decorators.push(IsDefined());
437
- }
438
-
439
- if (options.nullable) {
440
- decorators.push(IsNullable());
441
- } else {
442
- decorators.push(NotEquals(null));
443
- }
444
-
445
- if (options.swagger !== false) {
446
- decorators.push(
447
- ApiProperty({
448
- type: () => classValue,
449
- ...options,
450
- }),
451
- );
452
- }
453
-
454
- if (options.each) {
455
- decorators.push(ToArray());
456
- }
457
-
458
- return applyDecorators(...decorators);
459
- }
460
-
461
- // eslint-disable-next-line @typescript-eslint/ban-types
462
- export function EnumFieldOptional<TEnum extends object>(
463
- getEnum: () => TEnum,
464
- options: Omit<ApiPropertyOptions, 'type' | 'required' | 'enum' | 'enumName'> &
465
- IEnumFieldOptions = {},
466
- ): PropertyDecorator {
467
- return applyDecorators(
468
- IsEmptyable(),
469
- EnumField(getEnum, { required: false, ...options }),
470
- );
471
- }
472
-
473
- // eslint-disable-next-line @typescript-eslint/ban-types
474
- export function ClassFieldOptional<TClass extends object>(
475
- getClass: () => TClass,
476
- options: Omit<ApiPropertyOptions, 'type' | 'required'> &
477
- IClassFieldOptions = {},
478
- ): PropertyDecorator {
479
- return applyDecorators(
480
- IsEmptyable(),
481
- ClassField(getClass, { required: false, ...options }),
482
- );
483
- }
484
-
485
- export function EmailField(
486
- options: Omit<ApiPropertyOptions, 'type'> &
487
- IStringFieldOptions &
488
- IEmailFieldOptions = {},
489
- ): PropertyDecorator {
490
- const decorators = [
491
- IsEmail(options.emailOptions, {
492
- message:
493
- options.message ?? i18nValidationMessage('validation.INVALID_EMAIL'),
494
- }),
495
- StringField({ toLowerCase: true, ...options }),
496
- ];
497
-
498
- if (options.nullable) {
499
- decorators.push(IsNullable());
500
- } else {
501
- decorators.push(NotEquals(null));
502
- }
503
-
504
- if (options.swagger !== false) {
505
- decorators.push(ApiProperty({ type: String, ...options }));
506
- }
507
-
508
- return applyDecorators(...decorators);
509
- }
510
-
511
- export function EmailFieldOptional(
512
- options: Omit<ApiPropertyOptions, 'type'> &
513
- IStringFieldOptions &
514
- IEmailFieldOptions = {},
515
- ): PropertyDecorator {
516
- return applyDecorators(
517
- IsEmptyable(),
518
- EmailField({ required: false, ...options }),
519
- );
520
- }
521
-
522
- export function PhoneField(
523
- options: Omit<ApiPropertyOptions, 'type'> & IFieldOptions = {},
524
- ): PropertyDecorator {
525
- const decorators = [IsPhoneNumber(), PhoneNumberSerializer()];
526
-
527
- if (options.nullable) {
528
- decorators.push(IsNullable());
529
- } else {
530
- decorators.push(NotEquals(null));
531
- }
532
-
533
- if (options.swagger !== false) {
534
- decorators.push(ApiProperty({ type: String, ...options }));
535
- }
536
-
537
- return applyDecorators(...decorators);
538
- }
539
-
540
- export function PhoneFieldOptional(
541
- options: Omit<ApiPropertyOptions, 'type' | 'required'> & IFieldOptions = {},
542
- ): PropertyDecorator {
543
- return applyDecorators(
544
- IsEmptyable(),
545
- PhoneField({ required: false, ...options }),
546
- );
547
- }
548
-
549
- export function UUIDField(
550
- options: Omit<ApiPropertyOptions, 'type' | 'format' | 'isArray'> &
551
- IFieldOptions = {},
552
- ): PropertyDecorator {
553
- const decorators = [
554
- Type(() => String),
555
- IsUUID('4', {
556
- each: options.each,
557
- message: i18nValidationMessage('validation.IS_UUID'),
558
- }),
559
- ];
560
-
561
- if (options.nullable) {
562
- decorators.push(
563
- IsNullable({ message: i18nValidationMessage('validation.IS_NULLABLE') }),
564
- );
565
- } else {
566
- decorators.push(NotEquals(null));
567
- }
568
-
569
- if (options.swagger !== false) {
570
- decorators.push(ApiUUIDProperty(options));
571
- }
572
-
573
- if (options.each) {
574
- decorators.push(ToArray());
575
- }
576
-
577
- return applyDecorators(...decorators);
578
- }
579
-
580
- export function UUIDFieldOptional(
581
- options: Omit<ApiPropertyOptions, 'type' | 'required' | 'isArray'> &
582
- IFieldOptions = {},
583
- ): PropertyDecorator {
584
- return applyDecorators(
585
- IsEmptyable(),
586
- UUIDField({ required: false, ...options }),
587
- );
588
- }
589
-
590
- export function URLField(
591
- options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions = {},
592
- ): PropertyDecorator {
593
- const decorators = [
594
- IsUrl(
595
- {},
596
- {
597
- each: options.each,
598
- message: i18nValidationMessage('validation.IS_URL'),
599
- },
600
- ),
601
- StringField({ toLowerCase: true, ...options }),
602
- ];
603
-
604
- if (options.nullable) {
605
- decorators.push(IsNullable({ each: options.each }));
606
- } else {
607
- decorators.push(NotEquals(null, { each: options.each }));
608
- }
609
-
610
- return applyDecorators(...decorators);
611
- }
612
-
613
- export function URLFieldOptional(
614
- options: Omit<ApiPropertyOptions, 'type'> & IStringFieldOptions = {},
615
- ): PropertyDecorator {
616
- return applyDecorators(
617
- IsEmptyable(),
618
- URLField({ required: false, ...options }),
619
- );
620
- }
621
-
622
- export function FQDNField(
623
- options: Omit<ApiPropertyOptions, 'type'> &
624
- IFQDNFieldOptions &
625
- IStringFieldOptions = {},
626
- ): PropertyDecorator {
627
- const decorators = [
628
- IsFQDN(options, {
629
- each: options.each,
630
- message: i18nValidationMessage('validation.IS_FQDN'),
631
- }),
632
- StringField({ toLowerCase: true, ...options }),
633
- ];
634
-
635
- if (options.nullable) {
636
- decorators.push(IsNullable({ each: options.each }));
637
- } else {
638
- decorators.push(NotEquals(null, { each: options.each }));
639
- }
640
-
641
- return applyDecorators(...decorators);
642
- }
643
-
644
- export function FQDNFieldOptional(
645
- options: Omit<ApiPropertyOptions, 'type'> &
646
- IFQDNFieldOptions &
647
- IStringFieldOptions = {},
648
- ): PropertyDecorator {
649
- return applyDecorators(
650
- IsEmptyable(),
651
- FQDNField({ required: false, ...options }),
652
- );
653
- }
654
-
655
- export function DateField(
656
- options: Omit<ApiPropertyOptions, 'type'> & IDateFieldOptions = {},
657
- ): PropertyDecorator {
658
- const decorators = [
659
- Type(() => Date),
660
- IsDate({ message: i18nValidationMessage('validation.IS_DATE') }),
661
- ];
662
-
663
- if (options.nullable) {
664
- decorators.push(IsNullable());
665
- } else {
666
- decorators.push(NotEquals(null));
667
- }
668
-
669
- if (options.minDate) {
670
- decorators.push(
671
- MinDate(options.minDate, {
672
- each: options.each,
673
- message: i18nValidationMessage('validation.MIN_DATE'),
674
- }),
675
- );
676
- }
677
-
678
- if (options.maxDate) {
679
- decorators.push(
680
- MaxDate(options.maxDate, {
681
- each: options.each,
682
- message: i18nValidationMessage('validation.MAX_DATE'),
683
- }),
684
- );
685
- }
686
-
687
- if (options.swagger !== false) {
688
- decorators.push(ApiProperty({ type: Date, ...options }));
689
- }
690
-
691
- return applyDecorators(...decorators);
692
- }
693
-
694
- export function DateFieldOptional(
695
- options: Omit<ApiPropertyOptions, 'type' | 'required'> &
696
- IDateFieldOptions = {},
697
- ): PropertyDecorator {
698
- return applyDecorators(
699
- IsEmptyable(),
700
- DateField({ ...options, required: false }),
701
- );
702
- }
703
-
704
- export function IpFieldOptional(
705
- options: Omit<ApiPropertyOptions, 'type'> &
706
- IIPFieldOptions &
707
- IStringFieldOptions = {},
708
- ): PropertyDecorator {
709
- return applyDecorators(
710
- IsEmptyable(),
711
- IpField({ required: false, ...options }),
712
- );
713
- }
714
-
715
- export function IpField(
716
- options: Omit<ApiPropertyOptions, 'type'> &
717
- IStringFieldOptions &
718
- IIPFieldOptions,
719
- ): PropertyDecorator {
720
- const decorators = [
721
- IsIP(options.version || 4, {
722
- each: options.each,
723
- message: i18nValidationMessage('validation.IS_IP'),
724
- }),
725
- StringField({ toLowerCase: true, ...options }),
726
- ];
727
-
728
- if (options.nullable) {
729
- decorators.push(IsNullable({ each: options.each }));
730
- } else {
731
- decorators.push(NotEquals(null, { each: options.each }));
732
- }
733
-
734
- return applyDecorators(...decorators);
735
- }
736
-
737
- export function ObjectField(
738
- options: Omit<ApiPropertyOptions, 'type'> & IFieldOptions,
739
- ): PropertyDecorator {
740
- const decorators = [
741
- Type(() => Object),
742
- IsObject({
743
- each: options.each,
744
- message: i18nValidationMessage('validation.IS_OBJECT'),
745
- }),
746
- ];
747
-
748
- if (options.nullable) {
749
- decorators.push(IsNullable({ each: options.each }));
750
- } else {
751
- decorators.push(NotEquals(null, { each: options.each }));
752
- }
753
-
754
- if (options.swagger !== false) {
755
- decorators.push(
756
- ApiProperty({
757
- type: 'object',
758
- ...options,
759
- }),
760
- );
761
- }
762
-
763
- return applyDecorators(...decorators);
764
- }
765
-
766
- export function ObjectFieldOptional(
767
- options: Omit<ApiPropertyOptions, 'type'> & IFieldOptions = {},
768
- ): PropertyDecorator {
769
- return applyDecorators(
770
- IsEmptyable(),
771
- ObjectField({ required: false, ...options }),
772
- );
773
- }