@nest-omni/core 3.1.1-9 → 3.1.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 (306) hide show
  1. package/.hygen/new/crud/controller.ejs.t +82 -0
  2. package/.hygen/new/crud/create.dto.ejs.t +12 -0
  3. package/.hygen/new/crud/entity.ejs.t +26 -0
  4. package/.hygen/new/crud/get.dto.ejs.t +19 -0
  5. package/.hygen/new/crud/index-dto.ejs.t +29 -0
  6. package/.hygen/new/crud/index-response.dto.ejs.t +18 -0
  7. package/.hygen/new/crud/module.ejs.t +32 -0
  8. package/.hygen/new/crud/prompt.js +89 -0
  9. package/.hygen/new/crud/service.ejs.t +76 -0
  10. package/.hygen/new/crud/update.dto.ejs.t +11 -0
  11. package/.hygen/new/module/controller.ejs.t +93 -0
  12. package/.hygen/new/module/create-command.ejs.t +90 -0
  13. package/.hygen/new/module/create.dto.ejs.t +11 -0
  14. package/.hygen/new/module/dto.ejs.t +24 -0
  15. package/.hygen/new/module/entity.ejs.t +33 -0
  16. package/.hygen/new/module/get-query.ejs.t +57 -0
  17. package/.hygen/new/module/module.ejs.t +44 -0
  18. package/.hygen/new/module/not-found.exception.ejs.t +18 -0
  19. package/.hygen/new/module/page-options.dto.ejs.t +12 -0
  20. package/.hygen/new/module/prompt.js +104 -0
  21. package/.hygen/new/module/repository.ejs.t +16 -0
  22. package/.hygen/new/module/service.ejs.t +139 -0
  23. package/.hygen/new/module/translation-dto.ejs.t +27 -0
  24. package/.hygen/new/module/translation-entity.ejs.t +40 -0
  25. package/.hygen/new/module/translation-repository.ejs.t +16 -0
  26. package/.hygen/new/module/update.dto.ejs.t +10 -0
  27. package/.hygen.js +116 -0
  28. package/cache/cache-metrics.service.d.ts +83 -0
  29. package/cache/cache-metrics.service.js +298 -0
  30. package/cache/cache-serialization.service.d.ts +22 -0
  31. package/cache/cache-serialization.service.js +122 -0
  32. package/cache/cache.constants.d.ts +2 -0
  33. package/cache/cache.constants.js +5 -0
  34. package/cache/cache.health.d.ts +35 -0
  35. package/cache/cache.health.js +193 -0
  36. package/cache/cache.module.d.ts +26 -0
  37. package/cache/cache.module.js +155 -0
  38. package/cache/cache.service.d.ts +37 -0
  39. package/cache/cache.service.js +308 -0
  40. package/cache/cache.warmup.service.d.ts +34 -0
  41. package/cache/cache.warmup.service.js +199 -0
  42. package/cache/decorators/cache-evict.decorator.d.ts +2 -0
  43. package/cache/decorators/cache-evict.decorator.js +72 -0
  44. package/cache/decorators/cache-put.decorator.d.ts +2 -0
  45. package/cache/decorators/cache-put.decorator.js +48 -0
  46. package/cache/decorators/cacheable.decorator.d.ts +4 -0
  47. package/cache/decorators/cacheable.decorator.js +68 -0
  48. package/cache/decorators/index.d.ts +3 -0
  49. package/cache/decorators/index.js +11 -0
  50. package/cache/dependencies/callback.dependency.d.ts +11 -0
  51. package/cache/dependencies/callback.dependency.js +92 -0
  52. package/cache/dependencies/chain.dependency.d.ts +20 -0
  53. package/cache/dependencies/chain.dependency.js +113 -0
  54. package/cache/dependencies/db.dependency.d.ts +15 -0
  55. package/cache/dependencies/db.dependency.js +71 -0
  56. package/cache/dependencies/file.dependency.d.ts +17 -0
  57. package/cache/dependencies/file.dependency.js +63 -0
  58. package/cache/dependencies/index.d.ts +6 -0
  59. package/cache/dependencies/index.js +22 -0
  60. package/cache/dependencies/tag.dependency.d.ts +16 -0
  61. package/cache/dependencies/tag.dependency.js +75 -0
  62. package/cache/dependencies/time.dependency.d.ts +19 -0
  63. package/cache/dependencies/time.dependency.js +71 -0
  64. package/cache/examples/basic-usage.d.ts +58 -0
  65. package/cache/examples/basic-usage.js +379 -0
  66. package/cache/index.d.ts +15 -0
  67. package/cache/index.js +44 -0
  68. package/cache/interfaces/cache-dependency.interface.d.ts +11 -0
  69. package/cache/interfaces/cache-dependency.interface.js +2 -0
  70. package/cache/interfaces/cache-options.interface.d.ts +32 -0
  71. package/cache/interfaces/cache-options.interface.js +9 -0
  72. package/cache/interfaces/cache-provider.interface.d.ts +28 -0
  73. package/cache/interfaces/cache-provider.interface.js +2 -0
  74. package/cache/interfaces/index.d.ts +3 -0
  75. package/cache/interfaces/index.js +19 -0
  76. package/cache/providers/base-cache.provider.d.ts +16 -0
  77. package/cache/providers/base-cache.provider.js +32 -0
  78. package/cache/providers/cls-cache.provider.d.ts +16 -0
  79. package/cache/providers/cls-cache.provider.js +140 -0
  80. package/cache/providers/index.d.ts +4 -0
  81. package/cache/providers/index.js +23 -0
  82. package/cache/providers/memory-cache.provider.d.ts +26 -0
  83. package/cache/providers/memory-cache.provider.js +171 -0
  84. package/cache/providers/redis-cache.provider.d.ts +23 -0
  85. package/cache/providers/redis-cache.provider.js +215 -0
  86. package/cache/utils/dependency-manager.util.d.ts +15 -0
  87. package/cache/utils/dependency-manager.util.js +141 -0
  88. package/cache/utils/index.d.ts +2 -0
  89. package/cache/utils/index.js +18 -0
  90. package/cache/utils/key-generator.util.d.ts +13 -0
  91. package/cache/utils/key-generator.util.js +74 -0
  92. package/common/abstract.entity.d.ts +20 -0
  93. package/common/abstract.entity.js +81 -0
  94. package/common/boilerplate.polyfill.d.ts +50 -0
  95. package/common/boilerplate.polyfill.js +152 -0
  96. package/common/dto/abstract.dto.d.ts +13 -0
  97. package/common/dto/abstract.dto.js +59 -0
  98. package/common/dto/bulk-id.dto.d.ts +3 -0
  99. package/common/dto/bulk-id.dto.js +27 -0
  100. package/common/dto/create-translation.dto.d.ts +5 -0
  101. package/common/dto/create-translation.dto.js +25 -0
  102. package/common/dto/dto-container.d.ts +9 -0
  103. package/common/dto/dto-container.js +59 -0
  104. package/common/dto/dto-decorators.d.ts +18 -0
  105. package/common/dto/dto-decorators.js +59 -0
  106. package/common/dto/dto-extensions.d.ts +12 -0
  107. package/common/dto/dto-extensions.js +63 -0
  108. package/common/dto/dto-service-accessor.d.ts +7 -0
  109. package/common/dto/dto-service-accessor.js +49 -0
  110. package/common/dto/dto-transformer.d.ts +11 -0
  111. package/common/dto/dto-transformer.js +49 -0
  112. package/common/dto/index.d.ts +12 -0
  113. package/common/dto/index.js +28 -0
  114. package/common/dto/page-meta.dto.d.ts +15 -0
  115. package/common/dto/page-meta.dto.js +48 -0
  116. package/common/dto/page-options.dto.d.ts +5 -0
  117. package/common/dto/page-options.dto.js +40 -0
  118. package/common/dto/page.dto.d.ts +11 -0
  119. package/common/dto/page.dto.js +53 -0
  120. package/common/examples/paginate-and-map.example.d.ts +14 -0
  121. package/common/examples/paginate-and-map.example.js +158 -0
  122. package/common/index.d.ts +6 -0
  123. package/common/index.js +22 -0
  124. package/common/snake-naming.strategy.d.ts +11 -0
  125. package/common/snake-naming.strategy.js +37 -0
  126. package/common/types.d.ts +9 -0
  127. package/common/types.js +2 -0
  128. package/common/utils.d.ts +3 -0
  129. package/common/utils.js +24 -0
  130. package/constants/index.d.ts +2 -0
  131. package/constants/index.js +18 -0
  132. package/constants/language-code.d.ts +5 -0
  133. package/constants/language-code.js +9 -0
  134. package/constants/order.d.ts +4 -0
  135. package/constants/order.js +8 -0
  136. package/decorators/api-page-ok-response.decorator.d.ts +5 -0
  137. package/decorators/api-page-ok-response.decorator.js +24 -0
  138. package/decorators/auth-user.decorator.d.ts +1 -0
  139. package/decorators/auth-user.decorator.js +14 -0
  140. package/decorators/controller.decorator.d.ts +1 -0
  141. package/decorators/controller.decorator.js +10 -0
  142. package/decorators/examples/validation-decorators.example.d.ts +69 -0
  143. package/decorators/examples/validation-decorators.example.js +331 -0
  144. package/decorators/field.decorators.d.ts +79 -0
  145. package/decorators/field.decorators.js +499 -0
  146. package/decorators/http.decorators.d.ts +3 -0
  147. package/decorators/http.decorators.js +7 -0
  148. package/decorators/index.d.ts +12 -0
  149. package/decorators/index.js +28 -0
  150. package/decorators/operation.decorator.d.ts +1 -0
  151. package/decorators/operation.decorator.js +6 -0
  152. package/decorators/property.decorators.d.ts +15 -0
  153. package/decorators/property.decorators.js +31 -0
  154. package/decorators/public-route.decorator.d.ts +3 -0
  155. package/decorators/public-route.decorator.js +7 -0
  156. package/decorators/swagger.schema.d.ts +5 -0
  157. package/decorators/swagger.schema.js +78 -0
  158. package/decorators/timestamp-column.decorator.d.ts +1 -0
  159. package/decorators/timestamp-column.decorator.js +27 -0
  160. package/decorators/transform.decorators.d.ts +8 -0
  161. package/decorators/transform.decorators.js +100 -0
  162. package/decorators/translate.decorator.d.ts +5 -0
  163. package/decorators/translate.decorator.js +17 -0
  164. package/decorators/use-dto.decorator.d.ts +4 -0
  165. package/decorators/use-dto.decorator.js +8 -0
  166. package/decorators/user-check.decorator.d.ts +6 -0
  167. package/decorators/user-check.decorator.js +21 -0
  168. package/decorators/user.decorator.d.ts +12 -0
  169. package/decorators/user.decorator.js +44 -0
  170. package/decorators/user_auth.decorator.d.ts +1 -0
  171. package/decorators/user_auth.decorator.js +15 -0
  172. package/decorators/validator.decorators.d.ts +18 -0
  173. package/decorators/validator.decorators.js +193 -0
  174. package/exceptions/file-not-image.exception.d.ts +4 -0
  175. package/exceptions/file-not-image.exception.js +10 -0
  176. package/exceptions/index.d.ts +2 -0
  177. package/exceptions/index.js +18 -0
  178. package/exceptions/page-type.exception.d.ts +4 -0
  179. package/exceptions/page-type.exception.js +10 -0
  180. package/exceptions/user-not-found.exception.d.ts +4 -0
  181. package/exceptions/user-not-found.exception.js +10 -0
  182. package/filters/bad-request.filter.d.ts +5 -0
  183. package/filters/bad-request.filter.js +71 -0
  184. package/filters/constraint-errors.d.ts +1 -0
  185. package/filters/constraint-errors.js +6 -0
  186. package/filters/index.d.ts +3 -0
  187. package/filters/index.js +19 -0
  188. package/filters/query-failed.filter.d.ts +10 -0
  189. package/filters/query-failed.filter.js +42 -0
  190. package/health-checker/health-checker.controller.d.ts +13 -0
  191. package/health-checker/health-checker.controller.js +69 -0
  192. package/health-checker/health-checker.module.d.ts +2 -0
  193. package/health-checker/health-checker.module.js +24 -0
  194. package/health-checker/index.d.ts +2 -0
  195. package/health-checker/index.js +18 -0
  196. package/helpers/common.helper.d.ts +3 -0
  197. package/helpers/common.helper.js +36 -0
  198. package/helpers/date.helper.d.ts +10 -0
  199. package/helpers/date.helper.js +57 -0
  200. package/helpers/index.d.ts +2 -0
  201. package/helpers/index.js +18 -0
  202. package/i18n/en_US/validation.json +44 -0
  203. package/i18n/zh_CN/validation.json +44 -0
  204. package/index.d.ts +18 -0
  205. package/index.js +3 -0
  206. package/interceptors/index.d.ts +2 -0
  207. package/interceptors/index.js +18 -0
  208. package/interceptors/language-interceptor.service.d.ts +6 -0
  209. package/interceptors/language-interceptor.service.js +29 -0
  210. package/interceptors/translation-interceptor.service.d.ts +5 -0
  211. package/interceptors/translation-interceptor.service.js +34 -0
  212. package/interfaces/IApiFile.d.ts +4 -0
  213. package/interfaces/IApiFile.js +2 -0
  214. package/interfaces/IFile.d.ts +8 -0
  215. package/interfaces/IFile.js +2 -0
  216. package/interfaces/ITranslationDecoratorInterface.d.ts +3 -0
  217. package/interfaces/ITranslationDecoratorInterface.js +2 -0
  218. package/interfaces/index.d.ts +3 -0
  219. package/interfaces/index.js +19 -0
  220. package/interfaces/response.d.ts +25 -0
  221. package/interfaces/response.js +2 -0
  222. package/middlewares/index.d.ts +4 -0
  223. package/middlewares/index.js +20 -0
  224. package/middlewares/omni-auth.middleware.d.ts +1 -0
  225. package/middlewares/omni-auth.middleware.js +13 -0
  226. package/middlewares/powerby.middleware.d.ts +1 -0
  227. package/middlewares/powerby.middleware.js +10 -0
  228. package/middlewares/request-id.middleware.d.ts +7 -0
  229. package/middlewares/request-id.middleware.js +22 -0
  230. package/middlewares/xml.middleware.d.ts +4 -0
  231. package/middlewares/xml.middleware.js +24 -0
  232. package/package.json +41 -116
  233. package/providers/context.provider.d.ts +34 -0
  234. package/providers/context.provider.js +80 -0
  235. package/providers/generator.provider.d.ts +9 -0
  236. package/providers/generator.provider.js +50 -0
  237. package/providers/index.d.ts +2 -0
  238. package/providers/index.js +18 -0
  239. package/redis-lock/examples/lock-strategy.examples.d.ts +73 -0
  240. package/redis-lock/examples/lock-strategy.examples.js +387 -0
  241. package/redis-lock/index.d.ts +4 -0
  242. package/redis-lock/index.js +16 -0
  243. package/redis-lock/redis-lock.decorator.d.ts +12 -0
  244. package/redis-lock/redis-lock.decorator.js +125 -0
  245. package/redis-lock/redis-lock.module.d.ts +23 -0
  246. package/redis-lock/redis-lock.module.js +117 -0
  247. package/redis-lock/redis-lock.service.d.ts +66 -0
  248. package/redis-lock/redis-lock.service.js +413 -0
  249. package/setup/bootstrap.setup.d.ts +2 -0
  250. package/setup/bootstrap.setup.js +184 -0
  251. package/setup/index.d.ts +4 -0
  252. package/setup/index.js +20 -0
  253. package/setup/mode.setup.d.ts +12 -0
  254. package/setup/mode.setup.js +60 -0
  255. package/setup/schedule.decorator.d.ts +23 -0
  256. package/setup/schedule.decorator.js +233 -0
  257. package/setup/worker.decorator.d.ts +14 -0
  258. package/setup/worker.decorator.js +130 -0
  259. package/shared/index.d.ts +2 -0
  260. package/shared/index.js +18 -0
  261. package/shared/serviceRegistryModule.d.ts +2 -0
  262. package/shared/serviceRegistryModule.js +170 -0
  263. package/shared/services/api-config.service.d.ts +54 -0
  264. package/shared/services/api-config.service.js +287 -0
  265. package/shared/services/generator.service.d.ts +4 -0
  266. package/shared/services/generator.service.js +23 -0
  267. package/shared/services/index.d.ts +4 -0
  268. package/shared/services/index.js +20 -0
  269. package/shared/services/translation.service.d.ts +9 -0
  270. package/shared/services/translation.service.js +70 -0
  271. package/shared/services/validator.service.d.ts +3 -0
  272. package/shared/services/validator.service.js +20 -0
  273. package/validator-json/decorators.d.ts +6 -0
  274. package/validator-json/decorators.js +22 -0
  275. package/validator-json/default.d.ts +6 -0
  276. package/validator-json/default.js +138 -0
  277. package/validator-json/defaultConverters.d.ts +8 -0
  278. package/validator-json/defaultConverters.js +376 -0
  279. package/validator-json/index.d.ts +4 -0
  280. package/validator-json/index.js +20 -0
  281. package/validator-json/options.d.ts +11 -0
  282. package/validator-json/options.js +10 -0
  283. package/validators/file-mimetype.validator.d.ts +13 -0
  284. package/validators/file-mimetype.validator.js +21 -0
  285. package/validators/index.d.ts +6 -0
  286. package/validators/index.js +22 -0
  287. package/validators/is-exists.validator.d.ts +18 -0
  288. package/validators/is-exists.validator.js +60 -0
  289. package/validators/is-unique.validator.d.ts +17 -0
  290. package/validators/is-unique.validator.js +91 -0
  291. package/validators/phone-country-code.validator.d.ts +2 -0
  292. package/validators/phone-country-code.validator.js +29 -0
  293. package/validators/same-as.validator.d.ts +2 -0
  294. package/validators/same-as.validator.js +24 -0
  295. package/validators/skip-empty.validator.d.ts +1 -0
  296. package/validators/skip-empty.validator.js +17 -0
  297. package/vault/index.d.ts +4 -0
  298. package/vault/index.js +20 -0
  299. package/vault/interfaces/vault-options.interface.d.ts +22 -0
  300. package/vault/interfaces/vault-options.interface.js +2 -0
  301. package/vault/vault-config.loader.d.ts +13 -0
  302. package/vault/vault-config.loader.js +246 -0
  303. package/vault/vault-config.service.d.ts +18 -0
  304. package/vault/vault-config.service.js +174 -0
  305. package/vault/vault.module.d.ts +2 -0
  306. package/vault/vault.module.js +21 -0
@@ -0,0 +1,376 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultConverters = void 0;
4
+ const cv = require("class-validator");
5
+ require("reflect-metadata");
6
+ exports.defaultConverters = {
7
+ [cv.ValidationTypes.CUSTOM_VALIDATION]: (meta, options) => {
8
+ if (typeof meta.target === 'function') {
9
+ const type = getPropType(meta.target.prototype, meta.propertyName);
10
+ return targetToSchema(type, options);
11
+ }
12
+ },
13
+ [cv.ValidationTypes.NESTED_VALIDATION]: (meta, options) => {
14
+ if (typeof meta.target === 'function') {
15
+ const typeMeta = options.classTransformerMetadataStorage
16
+ ? options.classTransformerMetadataStorage.findTypeMetadata(meta.target, meta.propertyName)
17
+ : null;
18
+ const childType = typeMeta
19
+ ? typeMeta.typeFunction()
20
+ : getPropType(meta.target.prototype, meta.propertyName);
21
+ return targetToSchema(childType, options);
22
+ }
23
+ },
24
+ [cv.ValidationTypes.WHITELIST]: {},
25
+ [cv.ValidationTypes.CONDITIONAL_VALIDATION]: {},
26
+ [cv.ValidationTypes.IS_DEFINED]: {
27
+ not: { type: 'null' },
28
+ },
29
+ [cv.EQUALS]: (meta) => {
30
+ const schema = constraintToSchema(meta.constraints[0]);
31
+ if (schema) {
32
+ return Object.assign(Object.assign({}, schema), { enum: [meta.constraints[0]] });
33
+ }
34
+ },
35
+ [cv.NOT_EQUALS]: (meta) => {
36
+ const schema = constraintToSchema(meta.constraints[0]);
37
+ if (schema) {
38
+ return { not: Object.assign(Object.assign({}, schema), { enum: [meta.constraints[0]] }) };
39
+ }
40
+ },
41
+ [cv.IS_EMPTY]: {
42
+ type: 'string',
43
+ anyOf: [
44
+ { type: 'string', enum: [''] },
45
+ {
46
+ not: {
47
+ anyOf: [
48
+ { type: 'string' },
49
+ { type: 'number' },
50
+ { type: 'boolean' },
51
+ { type: 'integer' },
52
+ { type: 'array' },
53
+ { type: 'object' },
54
+ ],
55
+ },
56
+ nullable: true,
57
+ },
58
+ ],
59
+ },
60
+ [cv.IS_NOT_EMPTY]: {
61
+ minLength: 1,
62
+ type: 'string',
63
+ },
64
+ [cv.IS_IN]: (meta) => {
65
+ const [head, ...rest] = meta.constraints[0].map(constraintToSchema);
66
+ if (head && rest.every((item) => item.type === head.type)) {
67
+ return Object.assign(Object.assign({}, head), { enum: meta.constraints[0] });
68
+ }
69
+ return {
70
+ type: 'string',
71
+ };
72
+ },
73
+ [cv.IS_NOT_IN]: (meta) => {
74
+ const [head, ...rest] = meta.constraints[0].map(constraintToSchema);
75
+ if (head && rest.every((item) => item.type === head.type)) {
76
+ return { not: Object.assign(Object.assign({}, head), { enum: meta.constraints[0] }) };
77
+ }
78
+ return {
79
+ type: 'string',
80
+ };
81
+ },
82
+ [cv.IS_BOOLEAN]: {
83
+ type: 'boolean',
84
+ },
85
+ [cv.IS_DATE]: {
86
+ type: 'string',
87
+ oneOf: [
88
+ { format: 'date', type: 'string' },
89
+ { format: 'date-time', type: 'string' },
90
+ ],
91
+ },
92
+ [cv.IS_NUMBER]: {
93
+ type: 'number',
94
+ },
95
+ [cv.IS_STRING]: {
96
+ type: 'string',
97
+ },
98
+ [cv.IS_DATE_STRING]: {
99
+ pattern: '\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d.\\d+Z?',
100
+ type: 'string',
101
+ },
102
+ [cv.IS_ARRAY]: {
103
+ items: {},
104
+ type: 'array',
105
+ },
106
+ [cv.IS_INT]: {
107
+ type: 'integer',
108
+ },
109
+ [cv.IS_ENUM]: (meta) => {
110
+ return {
111
+ enum: Object.values(meta.constraints[0]),
112
+ type: 'string',
113
+ };
114
+ },
115
+ [cv.IS_DIVISIBLE_BY]: (meta) => ({
116
+ multipleOf: meta.constraints[0],
117
+ type: 'number',
118
+ }),
119
+ [cv.IS_POSITIVE]: {
120
+ exclusiveMinimum: 0,
121
+ type: 'number',
122
+ },
123
+ [cv.IS_NEGATIVE]: {
124
+ exclusiveMaximum: 0,
125
+ type: 'number',
126
+ },
127
+ [cv.MIN]: (meta) => ({
128
+ minimum: meta.constraints[0],
129
+ type: 'number',
130
+ }),
131
+ [cv.MAX]: (meta) => ({
132
+ maximum: meta.constraints[0],
133
+ type: 'number',
134
+ }),
135
+ [cv.MIN_DATE]: (meta) => ({
136
+ description: `After ${meta.constraints[0].toJSON()}`,
137
+ oneOf: [
138
+ { format: 'date', type: 'string' },
139
+ { format: 'date-time', type: 'string' },
140
+ ],
141
+ }),
142
+ [cv.MAX_DATE]: (meta) => ({
143
+ description: `Before ${meta.constraints[0].toJSON()}`,
144
+ oneOf: [
145
+ { format: 'date', type: 'string' },
146
+ { format: 'date-time', type: 'string' },
147
+ ],
148
+ }),
149
+ [cv.IS_BOOLEAN_STRING]: {
150
+ enum: ['true', 'false'],
151
+ type: 'string',
152
+ },
153
+ [cv.IS_NUMBER_STRING]: {
154
+ pattern: '^[-+]?[0-9]+$',
155
+ type: 'string',
156
+ },
157
+ [cv.CONTAINS]: (meta) => ({
158
+ pattern: meta.constraints[0],
159
+ type: 'string',
160
+ }),
161
+ [cv.NOT_CONTAINS]: (meta) => ({
162
+ not: { pattern: meta.constraints[0] },
163
+ type: 'string',
164
+ }),
165
+ [cv.IS_ALPHA]: {
166
+ pattern: '^[a-zA-Z]+$',
167
+ type: 'string',
168
+ },
169
+ [cv.IS_ALPHANUMERIC]: {
170
+ pattern: '^[0-9a-zA-Z]+$',
171
+ type: 'string',
172
+ },
173
+ [cv.IS_ASCII]: {
174
+ pattern: '^[\\x00-\\x7F]+$',
175
+ type: 'string',
176
+ },
177
+ [cv.IS_BASE64]: {
178
+ format: 'base64',
179
+ type: 'string',
180
+ },
181
+ [cv.IS_BYTE_LENGTH]: {
182
+ type: 'string',
183
+ },
184
+ [cv.IS_CREDIT_CARD]: {
185
+ format: 'credit-card',
186
+ type: 'string',
187
+ },
188
+ [cv.IS_CURRENCY]: {
189
+ format: 'currency',
190
+ type: 'string',
191
+ },
192
+ [cv.IS_EMAIL]: {
193
+ format: 'email',
194
+ type: 'string',
195
+ },
196
+ [cv.IS_FQDN]: {
197
+ format: 'hostname',
198
+ type: 'string',
199
+ },
200
+ [cv.IS_FULL_WIDTH]: {
201
+ pattern: '[^\\u0020-\\u007E\\uFF61-\\uFF9F\\uFFA0-\\uFFDC\\uFFE8-\\uFFEE0-9a-zA-Z]',
202
+ type: 'string',
203
+ },
204
+ [cv.IS_HALF_WIDTH]: {
205
+ pattern: '[\\u0020-\\u007E\\uFF61-\\uFF9F\\uFFA0-\\uFFDC\\uFFE8-\\uFFEE0-9a-zA-Z]',
206
+ type: 'string',
207
+ },
208
+ [cv.IS_VARIABLE_WIDTH]: {
209
+ type: 'string',
210
+ },
211
+ [cv.IS_HEX_COLOR]: {
212
+ pattern: '^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$',
213
+ type: 'string',
214
+ },
215
+ [cv.IS_HEXADECIMAL]: {
216
+ pattern: '^[0-9a-fA-F]+$',
217
+ type: 'string',
218
+ },
219
+ [cv.IS_IP]: (meta) => ({
220
+ format: 'ipv' + (meta.constraints[0] === '6' ? 6 : 4),
221
+ type: 'string',
222
+ }),
223
+ [cv.IS_ISBN]: {
224
+ format: 'isbn',
225
+ type: 'string',
226
+ },
227
+ [cv.IS_ISIN]: {
228
+ format: 'isin',
229
+ type: 'string',
230
+ },
231
+ [cv.IS_ISO8601]: {
232
+ oneOf: [
233
+ { format: 'date', type: 'string' },
234
+ { format: 'date-time', type: 'string' },
235
+ ],
236
+ },
237
+ [cv.IS_JSON]: {
238
+ format: 'json',
239
+ type: 'string',
240
+ },
241
+ [cv.IS_LOWERCASE]: {
242
+ type: 'string',
243
+ },
244
+ [cv.IS_MOBILE_PHONE]: {
245
+ format: 'mobile-phone',
246
+ type: 'string',
247
+ },
248
+ [cv.IS_MONGO_ID]: {
249
+ pattern: '^[0-9a-fA-F]{24}$',
250
+ type: 'string',
251
+ },
252
+ [cv.IS_MULTIBYTE]: {
253
+ pattern: '[^\\x00-\\x7F]',
254
+ type: 'string',
255
+ },
256
+ [cv.IS_SURROGATE_PAIR]: {
257
+ pattern: '[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]',
258
+ type: 'string',
259
+ },
260
+ [cv.IS_URL]: {
261
+ format: 'url',
262
+ type: 'string',
263
+ },
264
+ [cv.IS_UUID]: {
265
+ format: 'uuid',
266
+ type: 'string',
267
+ },
268
+ [cv.IS_LENGTH]: (meta) => {
269
+ const [minLength, maxLength] = meta.constraints;
270
+ if (maxLength || maxLength === 0) {
271
+ return { min: minLength, max: maxLength, type: 'Range' };
272
+ }
273
+ return { min: minLength, type: 'Range' };
274
+ },
275
+ [cv.IS_UPPERCASE]: {
276
+ type: 'string',
277
+ },
278
+ [cv.IS_OBJECT]: {
279
+ type: 'object',
280
+ },
281
+ [cv.IS_NOT_EMPTY_OBJECT]: {
282
+ type: 'object',
283
+ minProperties: 1,
284
+ },
285
+ [cv.MIN_LENGTH]: (meta) => ({
286
+ minLength: meta.constraints[0],
287
+ type: 'string',
288
+ }),
289
+ [cv.MAX_LENGTH]: (meta) => ({
290
+ maxLength: meta.constraints[0],
291
+ type: 'string',
292
+ }),
293
+ [cv.MATCHES]: (meta) => ({
294
+ pattern: meta.constraints[0].source,
295
+ type: 'string',
296
+ }),
297
+ [cv.IS_MILITARY_TIME]: {
298
+ pattern: '^([01]\\d|2[0-3]):?([0-5]\\d)$',
299
+ type: 'string',
300
+ },
301
+ [cv.ARRAY_CONTAINS]: (meta) => {
302
+ const schemas = meta.constraints[0].map(constraintToSchema);
303
+ if (schemas.length > 0 && schemas.every((s) => s && s.type)) {
304
+ return {
305
+ not: {
306
+ anyOf: schemas.map((d, i) => ({
307
+ items: {
308
+ not: Object.assign(Object.assign({}, d), { enum: [meta.constraints[0][i]] }),
309
+ },
310
+ })),
311
+ },
312
+ type: 'array',
313
+ };
314
+ }
315
+ return { items: {}, type: 'array' };
316
+ },
317
+ [cv.ARRAY_NOT_CONTAINS]: (meta) => {
318
+ const schemas = meta.constraints[0].map(constraintToSchema);
319
+ if (schemas.length > 0 && schemas.every((s) => s && s.type)) {
320
+ return {
321
+ items: {
322
+ not: {
323
+ anyOf: schemas.map((d, i) => (Object.assign(Object.assign({}, d), { enum: [meta.constraints[0][i]] }))),
324
+ },
325
+ },
326
+ type: 'array',
327
+ };
328
+ }
329
+ return { items: {}, type: 'array' };
330
+ },
331
+ [cv.ARRAY_NOT_EMPTY]: {
332
+ items: {},
333
+ minItems: 1,
334
+ type: 'array',
335
+ },
336
+ [cv.ARRAY_MIN_SIZE]: (meta) => ({
337
+ items: {},
338
+ minItems: meta.constraints[0],
339
+ type: 'array',
340
+ }),
341
+ [cv.ARRAY_MAX_SIZE]: (meta) => ({
342
+ items: {},
343
+ maxItems: meta.constraints[0],
344
+ type: 'array',
345
+ }),
346
+ [cv.ARRAY_UNIQUE]: {
347
+ items: {},
348
+ type: 'array',
349
+ uniqueItems: true,
350
+ },
351
+ };
352
+ function getPropType(target, property) {
353
+ return Reflect.getMetadata('design:type', target, property);
354
+ }
355
+ function constraintToSchema(primitive) {
356
+ const primitives = ['string', 'number', 'boolean'];
357
+ const type = typeof primitive;
358
+ if (primitives.includes(type)) {
359
+ return { type: type };
360
+ }
361
+ }
362
+ function targetToSchema(type, options) {
363
+ if (typeof type === 'function') {
364
+ if (type.prototype === String.prototype ||
365
+ type.prototype === Symbol.prototype) {
366
+ return { type: 'string' };
367
+ }
368
+ else if (type.prototype === Number.prototype) {
369
+ return { type: 'number' };
370
+ }
371
+ else if (type.prototype === Boolean.prototype) {
372
+ return { type: 'boolean' };
373
+ }
374
+ return { $ref: options.refPointerPrefix + type.name };
375
+ }
376
+ }
@@ -0,0 +1,4 @@
1
+ export * from './default';
2
+ export * from './decorators';
3
+ export * from './defaultConverters';
4
+ export * from './options';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./default"), exports);
18
+ __exportStar(require("./decorators"), exports);
19
+ __exportStar(require("./defaultConverters"), exports);
20
+ __exportStar(require("./options"), exports);
@@ -0,0 +1,11 @@
1
+ import type { MetadataStorage as ClassTransformerMetadataStorage } from 'class-transformer/types/MetadataStorage';
2
+ import { MetadataStorage, ValidatorOptions } from 'class-validator';
3
+ import { ISchemaConverters } from './defaultConverters';
4
+ export interface IOptions extends ValidatorOptions {
5
+ additionalConverters: ISchemaConverters;
6
+ classTransformerMetadataStorage?: ClassTransformerMetadataStorage;
7
+ classValidatorMetadataStorage: MetadataStorage;
8
+ refPointerPrefix: string;
9
+ schemaNameField: string;
10
+ }
11
+ export declare const defaultOptions: IOptions;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultOptions = void 0;
4
+ const class_validator_1 = require("class-validator");
5
+ exports.defaultOptions = {
6
+ additionalConverters: {},
7
+ classValidatorMetadataStorage: (0, class_validator_1.getMetadataStorage)(),
8
+ refPointerPrefix: '#/definitions/',
9
+ schemaNameField: 'name',
10
+ };
@@ -0,0 +1,13 @@
1
+ import { FileValidator } from '@nestjs/common/pipes/file/file-validator.interface';
2
+ import { IFile } from '@nestjs/common/pipes/file/interfaces';
3
+ export type FileMimetypeValidatorOptions = {
4
+ allowedMimetypes: string[];
5
+ message?: string;
6
+ };
7
+ export declare class FileMimetypeValidator extends FileValidator<FileMimetypeValidatorOptions, IFile> {
8
+ private allowedMimetypes;
9
+ private message;
10
+ constructor(options: FileMimetypeValidatorOptions);
11
+ buildErrorMessage(): string;
12
+ isValid(file?: IFile): boolean;
13
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileMimetypeValidator = void 0;
4
+ const file_validator_interface_1 = require("@nestjs/common/pipes/file/file-validator.interface");
5
+ class FileMimetypeValidator extends file_validator_interface_1.FileValidator {
6
+ constructor(options) {
7
+ super(options);
8
+ this.allowedMimetypes = options.allowedMimetypes;
9
+ this.message = options.message;
10
+ }
11
+ buildErrorMessage() {
12
+ if (this.message) {
13
+ return this.message;
14
+ }
15
+ return `Invalid file type. Only ${this.allowedMimetypes.join(', ')} are allowed.`;
16
+ }
17
+ isValid(file) {
18
+ return this.allowedMimetypes.includes(file.mimetype);
19
+ }
20
+ }
21
+ exports.FileMimetypeValidator = FileMimetypeValidator;
@@ -0,0 +1,6 @@
1
+ export * from './phone-country-code.validator';
2
+ export * from './skip-empty.validator';
3
+ export * from './file-mimetype.validator';
4
+ export * from './is-exists.validator';
5
+ export * from './is-unique.validator';
6
+ export * from './same-as.validator';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./phone-country-code.validator"), exports);
18
+ __exportStar(require("./skip-empty.validator"), exports);
19
+ __exportStar(require("./file-mimetype.validator"), exports);
20
+ __exportStar(require("./is-exists.validator"), exports);
21
+ __exportStar(require("./is-unique.validator"), exports);
22
+ __exportStar(require("./same-as.validator"), exports);
@@ -0,0 +1,18 @@
1
+ import type { ValidationArguments, ValidationOptions, ValidatorConstraintInterface } from 'class-validator';
2
+ import type { EntitySchema, FindOptionsWhere, ObjectType } from 'typeorm';
3
+ import { DataSource } from 'typeorm';
4
+ export declare class IsExistsValidator implements ValidatorConstraintInterface {
5
+ private readonly dataSource;
6
+ constructor(dataSource: DataSource);
7
+ validate<E>(value: string, args: IExistsValidationArguments<E>): Promise<boolean>;
8
+ defaultMessage(args: ValidationArguments): string;
9
+ }
10
+ type ExistsValidationConstraints<E> = [
11
+ ObjectType<E> | EntitySchema<E> | string,
12
+ (validationArguments: ValidationArguments) => FindOptionsWhere<E>
13
+ ];
14
+ interface IExistsValidationArguments<E> extends ValidationArguments {
15
+ constraints: ExistsValidationConstraints<E>;
16
+ }
17
+ export declare function IsExists<E>(constraints: Partial<ExistsValidationConstraints<E>>, validationOptions?: ValidationOptions): PropertyDecorator;
18
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.IsExistsValidator = void 0;
22
+ exports.IsExists = IsExists;
23
+ const class_validator_1 = require("class-validator");
24
+ const typeorm_1 = require("typeorm");
25
+ const nestjs_i18n_1 = require("nestjs-i18n");
26
+ const common_1 = require("@nestjs/common");
27
+ let IsExistsValidator = class IsExistsValidator {
28
+ constructor(dataSource) {
29
+ this.dataSource = dataSource;
30
+ }
31
+ validate(value, args) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const [entityClass, findCondition] = args.constraints;
34
+ args.value = value;
35
+ return ((yield this.dataSource.getRepository(entityClass).count({
36
+ where: findCondition(args),
37
+ })) > 0);
38
+ });
39
+ }
40
+ defaultMessage(args) {
41
+ return (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_EXISTS')(args);
42
+ }
43
+ };
44
+ exports.IsExistsValidator = IsExistsValidator;
45
+ exports.IsExistsValidator = IsExistsValidator = __decorate([
46
+ (0, common_1.Injectable)(),
47
+ (0, class_validator_1.ValidatorConstraint)({ name: 'isExists', async: true }),
48
+ __metadata("design:paramtypes", [typeorm_1.DataSource])
49
+ ], IsExistsValidator);
50
+ function IsExists(constraints, validationOptions) {
51
+ return (object, propertyName) => {
52
+ (0, class_validator_1.registerDecorator)({
53
+ target: object.constructor,
54
+ propertyName,
55
+ options: validationOptions,
56
+ constraints,
57
+ validator: IsExistsValidator,
58
+ });
59
+ };
60
+ }
@@ -0,0 +1,17 @@
1
+ import type { ValidationArguments, ValidationOptions, ValidatorConstraintInterface } from 'class-validator';
2
+ import { DataSource, EntitySchema, FindOptionsWhere, ObjectType } from 'typeorm';
3
+ export declare class IsUniqueValidator implements ValidatorConstraintInterface {
4
+ private readonly dataSource;
5
+ constructor(dataSource: DataSource);
6
+ validate<E>(value: string, args: IUniqueValidationArguments<E>): Promise<boolean>;
7
+ defaultMessage(args: ValidationArguments): string;
8
+ }
9
+ type UniqueValidationConstraints<E> = [
10
+ ObjectType<E> | EntitySchema<E> | string,
11
+ (validationArguments: ValidationArguments) => FindOptionsWhere<E>
12
+ ];
13
+ interface IUniqueValidationArguments<E> extends ValidationArguments {
14
+ constraints: UniqueValidationConstraints<E>;
15
+ }
16
+ export declare function IsUnique<E>(constraints: Partial<UniqueValidationConstraints<E>>, validationOptions?: ValidationOptions): PropertyDecorator;
17
+ export {};
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.IsUniqueValidator = void 0;
22
+ exports.IsUnique = IsUnique;
23
+ const class_validator_1 = require("class-validator");
24
+ const typeorm_1 = require("typeorm");
25
+ const nestjs_i18n_1 = require("nestjs-i18n");
26
+ let IsUniqueValidator = class IsUniqueValidator {
27
+ constructor(dataSource) {
28
+ this.dataSource = dataSource;
29
+ }
30
+ validate(value, args) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const [entityClass, findCondition] = args.constraints;
33
+ args.value = value;
34
+ let exists;
35
+ const defCon = findCondition(args);
36
+ const pkCols = this.dataSource
37
+ .getMetadata(entityClass)
38
+ .primaryColumns.map((column) => column.propertyName);
39
+ const isNew = pkCols.some((pk) => args.object[pk]);
40
+ if (!isNew) {
41
+ exists =
42
+ (yield this.dataSource
43
+ .getRepository(entityClass)
44
+ .count({ where: defCon })) < 1;
45
+ }
46
+ else {
47
+ const entities = yield this.dataSource
48
+ .getRepository(entityClass)
49
+ .createQueryBuilder()
50
+ .where(defCon)
51
+ .select(pkCols)
52
+ .limit(2)
53
+ .execute();
54
+ const entityCount = entities.length;
55
+ if (entityCount === 1) {
56
+ const entity = entities[0];
57
+ const oldPk = {};
58
+ const newPk = {};
59
+ pkCols.map((pk) => {
60
+ oldPk[pk] = entity[pk];
61
+ newPk[pk] = args.object[pk];
62
+ });
63
+ exists = JSON.stringify(oldPk) === JSON.stringify(newPk);
64
+ }
65
+ else {
66
+ exists = entityCount < 1;
67
+ }
68
+ }
69
+ return exists;
70
+ });
71
+ }
72
+ defaultMessage(args) {
73
+ return (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_UNIQUE')(args);
74
+ }
75
+ };
76
+ exports.IsUniqueValidator = IsUniqueValidator;
77
+ exports.IsUniqueValidator = IsUniqueValidator = __decorate([
78
+ (0, class_validator_1.ValidatorConstraint)({ name: 'isUnique', async: true }),
79
+ __metadata("design:paramtypes", [typeorm_1.DataSource])
80
+ ], IsUniqueValidator);
81
+ function IsUnique(constraints, validationOptions) {
82
+ return function (object, propertyName) {
83
+ (0, class_validator_1.registerDecorator)({
84
+ target: object.constructor,
85
+ propertyName,
86
+ options: validationOptions,
87
+ constraints,
88
+ validator: IsUniqueValidator,
89
+ });
90
+ };
91
+ }