@nest-omni/core 1.0.57 → 2.0.1-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (321) hide show
  1. package/.history/src/common/boilerplate.polyfill_20250521135408.ts +202 -0
  2. package/.history/src/common/boilerplate.polyfill_20250712165919.ts +254 -0
  3. package/.history/src/common/boilerplate.polyfill_20250712165924.ts +254 -0
  4. package/.history/src/common/boilerplate.polyfill_20250712165927.ts +254 -0
  5. package/.history/src/common/boilerplate.polyfill_20250712170044.ts +265 -0
  6. package/.history/src/common/boilerplate.polyfill_20250712170049.ts +265 -0
  7. package/.history/src/common/boilerplate.polyfill_20250712170053.ts +265 -0
  8. package/.history/src/common/boilerplate.polyfill_20250712170610.ts +280 -0
  9. package/.history/src/common/boilerplate.polyfill_20250712170614.ts +280 -0
  10. package/.history/src/common/boilerplate.polyfill_20250712170739.ts +265 -0
  11. package/.history/src/common/boilerplate.polyfill_20250712170801.ts +291 -0
  12. package/.history/src/common/boilerplate.polyfill_20250712170809.ts +317 -0
  13. package/.history/src/common/boilerplate.polyfill_20250712170816.ts +319 -0
  14. package/.history/src/common/boilerplate.polyfill_20250712170820.ts +318 -0
  15. package/.history/src/common/boilerplate.polyfill_20250712170824.ts +318 -0
  16. package/.history/src/common/boilerplate.polyfill_20250712171040.ts +289 -0
  17. package/README.md +16 -0
  18. package/build.sh +45 -0
  19. package/{common → dist/common}/abstract.entity.d.ts +1 -0
  20. package/{common → dist/common}/abstract.entity.js +13 -0
  21. package/{decorators → dist/decorators}/field.decorators.d.ts +1 -1
  22. package/dist/package.json +71 -0
  23. package/dist/setup/bootstrap.setup.d.ts +2 -0
  24. package/{setup → dist/setup}/bootstrap.setup.js +45 -27
  25. package/{shared → dist/shared}/serviceRegistryModule.js +4 -11
  26. package/{shared → dist/shared}/services/api-config.service.d.ts +3 -15
  27. package/{shared → dist/shared}/services/api-config.service.js +15 -42
  28. package/{shared → dist/shared}/services/index.d.ts +0 -1
  29. package/{shared → dist/shared}/services/index.js +0 -1
  30. package/dist/tsconfig.tsbuildinfo +1 -0
  31. package/dist/yarn.lock +644 -0
  32. package/package.json +1 -3
  33. package/src/.hygen.js +116 -0
  34. package/src/common/abstract-client.service.ts +56 -0
  35. package/src/common/abstract.entity.ts +82 -0
  36. package/src/common/boilerplate.polyfill.ts +202 -0
  37. package/src/common/dto/abstract.dto.ts +61 -0
  38. package/src/common/dto/bulk-id.dto.ts +13 -0
  39. package/src/common/dto/create-translation.dto.ts +10 -0
  40. package/src/common/dto/index.ts +6 -0
  41. package/src/common/dto/page-meta.dto.ts +37 -0
  42. package/src/common/dto/page-options.dto.ts +35 -0
  43. package/src/common/dto/page.dto.ts +36 -0
  44. package/src/common/index.ts +7 -0
  45. package/src/common/snake-naming.strategy.ts +64 -0
  46. package/src/common/types.ts +44 -0
  47. package/src/common/utils.ts +45 -0
  48. package/src/constants/index.ts +2 -0
  49. package/src/constants/language-code.ts +7 -0
  50. package/src/constants/order.ts +4 -0
  51. package/src/decorators/api-page-ok-response.decorator.ts +32 -0
  52. package/src/decorators/auth-user.decorator.ts +16 -0
  53. package/src/decorators/controller.decorator.ts +8 -0
  54. package/src/decorators/field.decorators.ts +856 -0
  55. package/src/decorators/http.decorators.ts +10 -0
  56. package/src/decorators/index.ts +12 -0
  57. package/src/decorators/operation.decorator.ts +4 -0
  58. package/src/decorators/property.decorators.ts +62 -0
  59. package/src/decorators/public-route.decorator.ts +8 -0
  60. package/src/decorators/swagger.schema.ts +117 -0
  61. package/src/decorators/timestamp-column.decorator.ts +29 -0
  62. package/src/decorators/transform.decorators.ts +159 -0
  63. package/src/decorators/translate.decorator.ts +19 -0
  64. package/src/decorators/use-dto.decorator.ts +11 -0
  65. package/src/decorators/user-check.decorator.ts +30 -0
  66. package/src/decorators/user.decorator.ts +59 -0
  67. package/src/decorators/user_auth.decorator.ts +15 -0
  68. package/src/decorators/validator.decorators.ts +98 -0
  69. package/src/exceptions/file-not-image.exception.ts +7 -0
  70. package/src/exceptions/index.ts +2 -0
  71. package/src/exceptions/page-type.exception.ts +7 -0
  72. package/src/exceptions/user-not-found.exception.ts +7 -0
  73. package/src/filters/bad-request.filter.ts +77 -0
  74. package/src/filters/constraint-errors.ts +5 -0
  75. package/src/filters/index.ts +3 -0
  76. package/src/filters/query-failed.filter.ts +32 -0
  77. package/src/health-checker/health-checker.controller.ts +51 -0
  78. package/src/health-checker/health-checker.module.ts +13 -0
  79. package/src/health-checker/health-indicators/service.indicator.ts +44 -0
  80. package/src/helpers/common.helper.ts +49 -0
  81. package/src/helpers/date.helper.ts +64 -0
  82. package/src/helpers/index.ts +2 -0
  83. package/src/i18n/en_US/validation.json +41 -0
  84. package/src/i18n/zh_CN/validation.json +41 -0
  85. package/src/index.ts +11 -0
  86. package/src/interceptors/index.ts +2 -0
  87. package/src/interceptors/language-interceptor.service.ts +28 -0
  88. package/src/interceptors/translation-interceptor.service.ts +43 -0
  89. package/src/interfaces/IApiFile.ts +4 -0
  90. package/src/interfaces/IFile.ts +8 -0
  91. package/src/interfaces/ITranslationDecoratorInterface.ts +3 -0
  92. package/src/interfaces/index.ts +3 -0
  93. package/src/interfaces/response.ts +37 -0
  94. package/src/middlewares/index.ts +4 -0
  95. package/src/middlewares/omni-auth.middleware.ts +10 -0
  96. package/src/middlewares/powerby.middleware.ts +6 -0
  97. package/src/middlewares/request-id.middleware.ts +28 -0
  98. package/src/middlewares/xml.middleware.ts +14 -0
  99. package/src/providers/context.provider.ts +109 -0
  100. package/src/providers/generator.provider.ts +66 -0
  101. package/src/providers/index.ts +2 -0
  102. package/src/setup/bootstrap.setup.ts +254 -0
  103. package/src/setup/index.ts +1 -0
  104. package/src/shared/index.ts +2 -0
  105. package/src/shared/serviceRegistryModule.ts +135 -0
  106. package/src/shared/services/api-config.service.ts +336 -0
  107. package/src/shared/services/generator.service.ts +13 -0
  108. package/src/shared/services/index.ts +4 -0
  109. package/src/shared/services/translation.service.ts +59 -0
  110. package/src/shared/services/validator.service.ts +10 -0
  111. package/src/validator-json/decorators.ts +63 -0
  112. package/src/validator-json/default.ts +257 -0
  113. package/src/validator-json/defaultConverters.ts +402 -0
  114. package/src/validator-json/index.ts +4 -0
  115. package/src/validator-json/options.ts +50 -0
  116. package/src/validators/file-mimetype.validator.ts +34 -0
  117. package/src/validators/index.ts +6 -0
  118. package/src/validators/is-exists.validator.ts +60 -0
  119. package/src/validators/is-unique.validator.ts +93 -0
  120. package/src/validators/phone-country-code.validator.ts +36 -0
  121. package/src/validators/same-as.validator.ts +27 -0
  122. package/src/validators/skip-empty.validator.ts +25 -0
  123. package/tsconfig.json +31 -0
  124. package/tsconfig.lib.json +16 -0
  125. package/setup/bootstrap.setup.d.ts +0 -2
  126. package/shared/services/aws-s3.service.d.ts +0 -10
  127. package/shared/services/aws-s3.service.js +0 -56
  128. package/tsconfig.tsbuildinfo +0 -1
  129. /package/{.hygen → dist/.hygen}/new/crud/controller.ejs.t +0 -0
  130. /package/{.hygen → dist/.hygen}/new/crud/create.dto.ejs.t +0 -0
  131. /package/{.hygen → dist/.hygen}/new/crud/entity.ejs.t +0 -0
  132. /package/{.hygen → dist/.hygen}/new/crud/get.dto.ejs.t +0 -0
  133. /package/{.hygen → dist/.hygen}/new/crud/index-dto.ejs.t +0 -0
  134. /package/{.hygen → dist/.hygen}/new/crud/index-response.dto.ejs.t +0 -0
  135. /package/{.hygen → dist/.hygen}/new/crud/module.ejs.t +0 -0
  136. /package/{.hygen → dist/.hygen}/new/crud/prompt.js +0 -0
  137. /package/{.hygen → dist/.hygen}/new/crud/service.ejs.t +0 -0
  138. /package/{.hygen → dist/.hygen}/new/crud/update.dto.ejs.t +0 -0
  139. /package/{.hygen → dist/.hygen}/new/module/controller.ejs.t +0 -0
  140. /package/{.hygen → dist/.hygen}/new/module/create-command.ejs.t +0 -0
  141. /package/{.hygen → dist/.hygen}/new/module/create.dto.ejs.t +0 -0
  142. /package/{.hygen → dist/.hygen}/new/module/dto.ejs.t +0 -0
  143. /package/{.hygen → dist/.hygen}/new/module/entity.ejs.t +0 -0
  144. /package/{.hygen → dist/.hygen}/new/module/get-query.ejs.t +0 -0
  145. /package/{.hygen → dist/.hygen}/new/module/module.ejs.t +0 -0
  146. /package/{.hygen → dist/.hygen}/new/module/not-found.exception.ejs.t +0 -0
  147. /package/{.hygen → dist/.hygen}/new/module/page-options.dto.ejs.t +0 -0
  148. /package/{.hygen → dist/.hygen}/new/module/prompt.js +0 -0
  149. /package/{.hygen → dist/.hygen}/new/module/repository.ejs.t +0 -0
  150. /package/{.hygen → dist/.hygen}/new/module/service.ejs.t +0 -0
  151. /package/{.hygen → dist/.hygen}/new/module/translation-dto.ejs.t +0 -0
  152. /package/{.hygen → dist/.hygen}/new/module/translation-entity.ejs.t +0 -0
  153. /package/{.hygen → dist/.hygen}/new/module/translation-repository.ejs.t +0 -0
  154. /package/{.hygen → dist/.hygen}/new/module/update.dto.ejs.t +0 -0
  155. /package/{.hygen.js → dist/.hygen.js} +0 -0
  156. /package/{common → dist/common}/abstract-client.service.d.ts +0 -0
  157. /package/{common → dist/common}/abstract-client.service.js +0 -0
  158. /package/{common → dist/common}/boilerplate.polyfill.d.ts +0 -0
  159. /package/{common → dist/common}/boilerplate.polyfill.js +0 -0
  160. /package/{common → dist/common}/dto/abstract.dto.d.ts +0 -0
  161. /package/{common → dist/common}/dto/abstract.dto.js +0 -0
  162. /package/{common → dist/common}/dto/bulk-id.dto.d.ts +0 -0
  163. /package/{common → dist/common}/dto/bulk-id.dto.js +0 -0
  164. /package/{common → dist/common}/dto/create-translation.dto.d.ts +0 -0
  165. /package/{common → dist/common}/dto/create-translation.dto.js +0 -0
  166. /package/{common → dist/common}/dto/index.d.ts +0 -0
  167. /package/{common → dist/common}/dto/index.js +0 -0
  168. /package/{common → dist/common}/dto/page-meta.dto.d.ts +0 -0
  169. /package/{common → dist/common}/dto/page-meta.dto.js +0 -0
  170. /package/{common → dist/common}/dto/page-options.dto.d.ts +0 -0
  171. /package/{common → dist/common}/dto/page-options.dto.js +0 -0
  172. /package/{common → dist/common}/dto/page.dto.d.ts +0 -0
  173. /package/{common → dist/common}/dto/page.dto.js +0 -0
  174. /package/{common → dist/common}/index.d.ts +0 -0
  175. /package/{common → dist/common}/index.js +0 -0
  176. /package/{common → dist/common}/snake-naming.strategy.d.ts +0 -0
  177. /package/{common → dist/common}/snake-naming.strategy.js +0 -0
  178. /package/{common → dist/common}/types.d.ts +0 -0
  179. /package/{common → dist/common}/types.js +0 -0
  180. /package/{common → dist/common}/utils.d.ts +0 -0
  181. /package/{common → dist/common}/utils.js +0 -0
  182. /package/{constants → dist/constants}/index.d.ts +0 -0
  183. /package/{constants → dist/constants}/index.js +0 -0
  184. /package/{constants → dist/constants}/language-code.d.ts +0 -0
  185. /package/{constants → dist/constants}/language-code.js +0 -0
  186. /package/{constants → dist/constants}/order.d.ts +0 -0
  187. /package/{constants → dist/constants}/order.js +0 -0
  188. /package/{decorators → dist/decorators}/api-page-ok-response.decorator.d.ts +0 -0
  189. /package/{decorators → dist/decorators}/api-page-ok-response.decorator.js +0 -0
  190. /package/{decorators → dist/decorators}/auth-user.decorator.d.ts +0 -0
  191. /package/{decorators → dist/decorators}/auth-user.decorator.js +0 -0
  192. /package/{decorators → dist/decorators}/controller.decorator.d.ts +0 -0
  193. /package/{decorators → dist/decorators}/controller.decorator.js +0 -0
  194. /package/{decorators → dist/decorators}/field.decorators.js +0 -0
  195. /package/{decorators → dist/decorators}/http.decorators.d.ts +0 -0
  196. /package/{decorators → dist/decorators}/http.decorators.js +0 -0
  197. /package/{decorators → dist/decorators}/index.d.ts +0 -0
  198. /package/{decorators → dist/decorators}/index.js +0 -0
  199. /package/{decorators → dist/decorators}/operation.decorator.d.ts +0 -0
  200. /package/{decorators → dist/decorators}/operation.decorator.js +0 -0
  201. /package/{decorators → dist/decorators}/property.decorators.d.ts +0 -0
  202. /package/{decorators → dist/decorators}/property.decorators.js +0 -0
  203. /package/{decorators → dist/decorators}/public-route.decorator.d.ts +0 -0
  204. /package/{decorators → dist/decorators}/public-route.decorator.js +0 -0
  205. /package/{decorators → dist/decorators}/swagger.schema.d.ts +0 -0
  206. /package/{decorators → dist/decorators}/swagger.schema.js +0 -0
  207. /package/{decorators → dist/decorators}/timestamp-column.decorator.d.ts +0 -0
  208. /package/{decorators → dist/decorators}/timestamp-column.decorator.js +0 -0
  209. /package/{decorators → dist/decorators}/transform.decorators.d.ts +0 -0
  210. /package/{decorators → dist/decorators}/transform.decorators.js +0 -0
  211. /package/{decorators → dist/decorators}/translate.decorator.d.ts +0 -0
  212. /package/{decorators → dist/decorators}/translate.decorator.js +0 -0
  213. /package/{decorators → dist/decorators}/use-dto.decorator.d.ts +0 -0
  214. /package/{decorators → dist/decorators}/use-dto.decorator.js +0 -0
  215. /package/{decorators → dist/decorators}/user-check.decorator.d.ts +0 -0
  216. /package/{decorators → dist/decorators}/user-check.decorator.js +0 -0
  217. /package/{decorators → dist/decorators}/user.decorator.d.ts +0 -0
  218. /package/{decorators → dist/decorators}/user.decorator.js +0 -0
  219. /package/{decorators → dist/decorators}/user_auth.decorator.d.ts +0 -0
  220. /package/{decorators → dist/decorators}/user_auth.decorator.js +0 -0
  221. /package/{decorators → dist/decorators}/validator.decorators.d.ts +0 -0
  222. /package/{decorators → dist/decorators}/validator.decorators.js +0 -0
  223. /package/{exceptions → dist/exceptions}/file-not-image.exception.d.ts +0 -0
  224. /package/{exceptions → dist/exceptions}/file-not-image.exception.js +0 -0
  225. /package/{exceptions → dist/exceptions}/index.d.ts +0 -0
  226. /package/{exceptions → dist/exceptions}/index.js +0 -0
  227. /package/{exceptions → dist/exceptions}/page-type.exception.d.ts +0 -0
  228. /package/{exceptions → dist/exceptions}/page-type.exception.js +0 -0
  229. /package/{exceptions → dist/exceptions}/user-not-found.exception.d.ts +0 -0
  230. /package/{exceptions → dist/exceptions}/user-not-found.exception.js +0 -0
  231. /package/{filters → dist/filters}/bad-request.filter.d.ts +0 -0
  232. /package/{filters → dist/filters}/bad-request.filter.js +0 -0
  233. /package/{filters → dist/filters}/constraint-errors.d.ts +0 -0
  234. /package/{filters → dist/filters}/constraint-errors.js +0 -0
  235. /package/{filters → dist/filters}/index.d.ts +0 -0
  236. /package/{filters → dist/filters}/index.js +0 -0
  237. /package/{filters → dist/filters}/query-failed.filter.d.ts +0 -0
  238. /package/{filters → dist/filters}/query-failed.filter.js +0 -0
  239. /package/{health-checker → dist/health-checker}/health-checker.controller.d.ts +0 -0
  240. /package/{health-checker → dist/health-checker}/health-checker.controller.js +0 -0
  241. /package/{health-checker → dist/health-checker}/health-checker.module.d.ts +0 -0
  242. /package/{health-checker → dist/health-checker}/health-checker.module.js +0 -0
  243. /package/{health-checker → dist/health-checker}/health-indicators/service.indicator.d.ts +0 -0
  244. /package/{health-checker → dist/health-checker}/health-indicators/service.indicator.js +0 -0
  245. /package/{helpers → dist/helpers}/common.helper.d.ts +0 -0
  246. /package/{helpers → dist/helpers}/common.helper.js +0 -0
  247. /package/{helpers → dist/helpers}/date.helper.d.ts +0 -0
  248. /package/{helpers → dist/helpers}/date.helper.js +0 -0
  249. /package/{helpers → dist/helpers}/index.d.ts +0 -0
  250. /package/{helpers → dist/helpers}/index.js +0 -0
  251. /package/{i18n → dist/i18n}/en_US/validation.json +0 -0
  252. /package/{i18n → dist/i18n}/zh_CN/validation.json +0 -0
  253. /package/{index.d.ts → dist/index.d.ts} +0 -0
  254. /package/{index.js → dist/index.js} +0 -0
  255. /package/{interceptors → dist/interceptors}/index.d.ts +0 -0
  256. /package/{interceptors → dist/interceptors}/index.js +0 -0
  257. /package/{interceptors → dist/interceptors}/language-interceptor.service.d.ts +0 -0
  258. /package/{interceptors → dist/interceptors}/language-interceptor.service.js +0 -0
  259. /package/{interceptors → dist/interceptors}/translation-interceptor.service.d.ts +0 -0
  260. /package/{interceptors → dist/interceptors}/translation-interceptor.service.js +0 -0
  261. /package/{interfaces → dist/interfaces}/IApiFile.d.ts +0 -0
  262. /package/{interfaces → dist/interfaces}/IApiFile.js +0 -0
  263. /package/{interfaces → dist/interfaces}/IFile.d.ts +0 -0
  264. /package/{interfaces → dist/interfaces}/IFile.js +0 -0
  265. /package/{interfaces → dist/interfaces}/ITranslationDecoratorInterface.d.ts +0 -0
  266. /package/{interfaces → dist/interfaces}/ITranslationDecoratorInterface.js +0 -0
  267. /package/{interfaces → dist/interfaces}/index.d.ts +0 -0
  268. /package/{interfaces → dist/interfaces}/index.js +0 -0
  269. /package/{interfaces → dist/interfaces}/response.d.ts +0 -0
  270. /package/{interfaces → dist/interfaces}/response.js +0 -0
  271. /package/{middlewares → dist/middlewares}/index.d.ts +0 -0
  272. /package/{middlewares → dist/middlewares}/index.js +0 -0
  273. /package/{middlewares → dist/middlewares}/omni-auth.middleware.d.ts +0 -0
  274. /package/{middlewares → dist/middlewares}/omni-auth.middleware.js +0 -0
  275. /package/{middlewares → dist/middlewares}/powerby.middleware.d.ts +0 -0
  276. /package/{middlewares → dist/middlewares}/powerby.middleware.js +0 -0
  277. /package/{middlewares → dist/middlewares}/request-id.middleware.d.ts +0 -0
  278. /package/{middlewares → dist/middlewares}/request-id.middleware.js +0 -0
  279. /package/{middlewares → dist/middlewares}/xml.middleware.d.ts +0 -0
  280. /package/{middlewares → dist/middlewares}/xml.middleware.js +0 -0
  281. /package/{providers → dist/providers}/context.provider.d.ts +0 -0
  282. /package/{providers → dist/providers}/context.provider.js +0 -0
  283. /package/{providers → dist/providers}/generator.provider.d.ts +0 -0
  284. /package/{providers → dist/providers}/generator.provider.js +0 -0
  285. /package/{providers → dist/providers}/index.d.ts +0 -0
  286. /package/{providers → dist/providers}/index.js +0 -0
  287. /package/{setup → dist/setup}/index.d.ts +0 -0
  288. /package/{setup → dist/setup}/index.js +0 -0
  289. /package/{shared → dist/shared}/index.d.ts +0 -0
  290. /package/{shared → dist/shared}/index.js +0 -0
  291. /package/{shared → dist/shared}/serviceRegistryModule.d.ts +0 -0
  292. /package/{shared → dist/shared}/services/generator.service.d.ts +0 -0
  293. /package/{shared → dist/shared}/services/generator.service.js +0 -0
  294. /package/{shared → dist/shared}/services/translation.service.d.ts +0 -0
  295. /package/{shared → dist/shared}/services/translation.service.js +0 -0
  296. /package/{shared → dist/shared}/services/validator.service.d.ts +0 -0
  297. /package/{shared → dist/shared}/services/validator.service.js +0 -0
  298. /package/{validator-json → dist/validator-json}/decorators.d.ts +0 -0
  299. /package/{validator-json → dist/validator-json}/decorators.js +0 -0
  300. /package/{validator-json → dist/validator-json}/default.d.ts +0 -0
  301. /package/{validator-json → dist/validator-json}/default.js +0 -0
  302. /package/{validator-json → dist/validator-json}/defaultConverters.d.ts +0 -0
  303. /package/{validator-json → dist/validator-json}/defaultConverters.js +0 -0
  304. /package/{validator-json → dist/validator-json}/index.d.ts +0 -0
  305. /package/{validator-json → dist/validator-json}/index.js +0 -0
  306. /package/{validator-json → dist/validator-json}/options.d.ts +0 -0
  307. /package/{validator-json → dist/validator-json}/options.js +0 -0
  308. /package/{validators → dist/validators}/file-mimetype.validator.d.ts +0 -0
  309. /package/{validators → dist/validators}/file-mimetype.validator.js +0 -0
  310. /package/{validators → dist/validators}/index.d.ts +0 -0
  311. /package/{validators → dist/validators}/index.js +0 -0
  312. /package/{validators → dist/validators}/is-exists.validator.d.ts +0 -0
  313. /package/{validators → dist/validators}/is-exists.validator.js +0 -0
  314. /package/{validators → dist/validators}/is-unique.validator.d.ts +0 -0
  315. /package/{validators → dist/validators}/is-unique.validator.js +0 -0
  316. /package/{validators → dist/validators}/phone-country-code.validator.d.ts +0 -0
  317. /package/{validators → dist/validators}/phone-country-code.validator.js +0 -0
  318. /package/{validators → dist/validators}/same-as.validator.d.ts +0 -0
  319. /package/{validators → dist/validators}/same-as.validator.js +0 -0
  320. /package/{validators → dist/validators}/skip-empty.validator.d.ts +0 -0
  321. /package/{validators → dist/validators}/skip-empty.validator.js +0 -0
@@ -0,0 +1,34 @@
1
+ import { FileValidator } from '@nestjs/common/pipes/file/file-validator.interface';
2
+ import { IFile } from '@nestjs/common/pipes/file/interfaces';
3
+
4
+ export type FileMimetypeValidatorOptions = {
5
+ allowedMimetypes: string[];
6
+ message?: string;
7
+ };
8
+
9
+ export class FileMimetypeValidator extends FileValidator<
10
+ FileMimetypeValidatorOptions,
11
+ IFile
12
+ > {
13
+ private allowedMimetypes: string[];
14
+ private message: string;
15
+
16
+ constructor(options: FileMimetypeValidatorOptions) {
17
+ super(options);
18
+ this.allowedMimetypes = options.allowedMimetypes;
19
+ this.message = options.message;
20
+ }
21
+
22
+ buildErrorMessage(): string {
23
+ if (this.message) {
24
+ return this.message;
25
+ }
26
+ return `Invalid file type. Only ${this.allowedMimetypes.join(
27
+ ', ',
28
+ )} are allowed.`;
29
+ }
30
+
31
+ isValid(file?: IFile): boolean {
32
+ return this.allowedMimetypes.includes(file.mimetype);
33
+ }
34
+ }
@@ -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,60 @@
1
+ import type {
2
+ ValidationArguments,
3
+ ValidationOptions,
4
+ ValidatorConstraintInterface,
5
+ } from 'class-validator';
6
+ import { registerDecorator, ValidatorConstraint } from 'class-validator';
7
+ import type { EntitySchema, FindOptionsWhere, ObjectType } from 'typeorm';
8
+ import { DataSource } from 'typeorm';
9
+ import { getDataSourceByName } from 'typeorm-transactional';
10
+ import { i18nValidationMessage } from 'nestjs-i18n';
11
+ import { Injectable } from '@nestjs/common';
12
+
13
+ @Injectable()
14
+ @ValidatorConstraint({ name: 'isExists', async: true })
15
+ export class IsExistsValidator implements ValidatorConstraintInterface {
16
+ constructor(private readonly dataSource: DataSource) {
17
+ this.dataSource = getDataSourceByName('default');
18
+ }
19
+
20
+ public async validate<E>(
21
+ value: string,
22
+ args: IExistsValidationArguments<E>,
23
+ ): Promise<boolean> {
24
+ const [entityClass, findCondition] = args.constraints;
25
+ args.value = value;
26
+ return (
27
+ (await this.dataSource.getRepository(entityClass).count({
28
+ where: findCondition(args),
29
+ })) > 0
30
+ );
31
+ }
32
+
33
+ defaultMessage(args: ValidationArguments): string {
34
+ return i18nValidationMessage('validation.IS_EXISTS')(args);
35
+ }
36
+ }
37
+
38
+ type ExistsValidationConstraints<E> = [
39
+ ObjectType<E> | EntitySchema<E> | string,
40
+ (validationArguments: ValidationArguments) => FindOptionsWhere<E>,
41
+ ];
42
+
43
+ interface IExistsValidationArguments<E> extends ValidationArguments {
44
+ constraints: ExistsValidationConstraints<E>;
45
+ }
46
+
47
+ export function IsExists<E>(
48
+ constraints: Partial<ExistsValidationConstraints<E>>,
49
+ validationOptions?: ValidationOptions,
50
+ ): PropertyDecorator {
51
+ return (object, propertyName: string) => {
52
+ registerDecorator({
53
+ target: object.constructor,
54
+ propertyName,
55
+ options: validationOptions,
56
+ constraints,
57
+ validator: IsExistsValidator,
58
+ });
59
+ };
60
+ }
@@ -0,0 +1,93 @@
1
+ import type {
2
+ ValidationArguments,
3
+ ValidationOptions,
4
+ ValidatorConstraintInterface,
5
+ } from 'class-validator';
6
+ import { registerDecorator, ValidatorConstraint } from 'class-validator';
7
+ import {
8
+ DataSource,
9
+ EntitySchema,
10
+ FindOptionsWhere,
11
+ ObjectType,
12
+ } from 'typeorm';
13
+ import { getDataSourceByName } from 'typeorm-transactional';
14
+ import { i18nValidationMessage } from 'nestjs-i18n';
15
+
16
+ @ValidatorConstraint({ name: 'isUnique', async: true })
17
+ export class IsUniqueValidator implements ValidatorConstraintInterface {
18
+ constructor(private readonly dataSource: DataSource) {
19
+ this.dataSource = getDataSourceByName('default');
20
+ }
21
+
22
+ public async validate<E>(
23
+ value: string,
24
+ args: IUniqueValidationArguments<E>,
25
+ ): Promise<boolean> {
26
+ const [entityClass, findCondition] = args.constraints;
27
+ args.value = value;
28
+ let exists: boolean;
29
+ const defCon = findCondition(args);
30
+ const pkCols = this.dataSource
31
+ .getMetadata(entityClass)
32
+ .primaryColumns.map((column) => column.propertyName);
33
+
34
+ const isNew = pkCols.some((pk) => args.object[pk]);
35
+ if (!isNew) {
36
+ exists =
37
+ (await this.dataSource
38
+ .getRepository(entityClass)
39
+ .count({ where: defCon })) < 1;
40
+ } else {
41
+ const entities = await this.dataSource
42
+ .getRepository(entityClass)
43
+ .createQueryBuilder()
44
+ .where(defCon)
45
+ .select(pkCols)
46
+ .limit(2)
47
+ .execute();
48
+
49
+ const entityCount = entities.length;
50
+ if (entityCount === 1) {
51
+ const entity = entities[0];
52
+ const oldPk = {};
53
+ const newPk = {};
54
+ pkCols.map((pk) => {
55
+ oldPk[pk] = entity[pk];
56
+ newPk[pk] = args.object[pk];
57
+ });
58
+ exists = JSON.stringify(oldPk) === JSON.stringify(newPk);
59
+ } else {
60
+ exists = entityCount < 1;
61
+ }
62
+ }
63
+ return exists;
64
+ }
65
+
66
+ defaultMessage(args: ValidationArguments): string {
67
+ return i18nValidationMessage('validation.IS_UNIQUE')(args);
68
+ }
69
+ }
70
+
71
+ type UniqueValidationConstraints<E> = [
72
+ ObjectType<E> | EntitySchema<E> | string,
73
+ (validationArguments: ValidationArguments) => FindOptionsWhere<E>,
74
+ ];
75
+
76
+ interface IUniqueValidationArguments<E> extends ValidationArguments {
77
+ constraints: UniqueValidationConstraints<E>;
78
+ }
79
+
80
+ export function IsUnique<E>(
81
+ constraints: Partial<UniqueValidationConstraints<E>>,
82
+ validationOptions?: ValidationOptions,
83
+ ): PropertyDecorator {
84
+ return function (object, propertyName: string) {
85
+ registerDecorator({
86
+ target: object.constructor,
87
+ propertyName,
88
+ options: validationOptions,
89
+ constraints,
90
+ validator: IsUniqueValidator,
91
+ });
92
+ };
93
+ }
@@ -0,0 +1,36 @@
1
+ import {
2
+ isPhoneNumber,
3
+ registerDecorator,
4
+ ValidateIf,
5
+ ValidationArguments,
6
+ ValidationOptions,
7
+ } from 'class-validator';
8
+
9
+ export function IsPhoneNumberWithCountryCode(
10
+ validationOptions?: ValidationOptions,
11
+ ) {
12
+ return function (object: NonNullable<unknown>, propertyName: string) {
13
+ ValidateIf((_, value) => !!value)(object, propertyName);
14
+ const countryCodePropertyName = 'countryCode';
15
+
16
+ registerDecorator({
17
+ name: 'isPhoneNumberWithCountryCode',
18
+ target: object.constructor,
19
+ propertyName: propertyName,
20
+ constraints: [countryCodePropertyName],
21
+ options: validationOptions,
22
+ validator: {
23
+ validate(value: any, args: ValidationArguments) {
24
+ const [countryCodePropertyName] = args.constraints;
25
+ const countryCode = args.object[countryCodePropertyName];
26
+ return isPhoneNumber(value, countryCode);
27
+ },
28
+ defaultMessage(args: ValidationArguments) {
29
+ const [countryCodePropertyName] = args.constraints;
30
+ const countryCode = args.object[countryCodePropertyName];
31
+ return `$property must be a valid phone number in the country code ${countryCode}`;
32
+ },
33
+ },
34
+ });
35
+ };
36
+ }
@@ -0,0 +1,27 @@
1
+ import type { ValidationOptions } from 'class-validator';
2
+ import { registerDecorator } from 'class-validator';
3
+
4
+ export function SameAs(
5
+ property: string,
6
+ validationOptions?: ValidationOptions,
7
+ ): PropertyDecorator {
8
+ return function (object, propertyName: string) {
9
+ registerDecorator({
10
+ name: 'sameAs',
11
+ target: object.constructor,
12
+ propertyName,
13
+ options: validationOptions,
14
+ constraints: [property],
15
+ validator: {
16
+ validate(value, args) {
17
+ const [relatedPropertyName] = args!.constraints;
18
+
19
+ return args?.object[relatedPropertyName] === value;
20
+ },
21
+ defaultMessage() {
22
+ return '$property must match $constraint1';
23
+ },
24
+ },
25
+ });
26
+ };
27
+ }
@@ -0,0 +1,25 @@
1
+ import { applyDecorators } from '@nestjs/common';
2
+ import { ApiProperty } from '@nestjs/swagger';
3
+ import { ValidateIf } from 'class-validator';
4
+ import { isString } from 'lodash';
5
+
6
+ /**
7
+ * When the value is emtpy, validation is skipped
8
+ * @param field
9
+ * @constructor
10
+ */
11
+ export function SkipEmpty(field?: string) {
12
+ return applyDecorators(
13
+ ApiProperty({ required: false }),
14
+ ValidateIf((obj, value) => {
15
+ if (field) {
16
+ value = obj[field];
17
+ }
18
+ return !(
19
+ value === null ||
20
+ value === undefined ||
21
+ (isString(value) && value.trim() === '')
22
+ );
23
+ }),
24
+ );
25
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "declaration": true,
5
+ "removeComments": true,
6
+ "emitDecoratorMetadata": true,
7
+ "experimentalDecorators": true,
8
+ "allowSyntheticDefaultImports": true,
9
+ "target": "es6",
10
+ "sourceMap": false,
11
+ "outDir": "./dist",
12
+ "baseUrl": "./dist",
13
+ "incremental": true,
14
+ "skipLibCheck": true,
15
+ "strictNullChecks": false,
16
+ "noImplicitAny": false,
17
+ "strictBindCallApply": false,
18
+ "forceConsistentCasingInFileNames": false,
19
+ "noFallthroughCasesInSwitch": false,
20
+ "resolveJsonModule": true
21
+ },
22
+ "include": [
23
+ "./src/**/*.ts",
24
+ "./src/i18n/**/*.json"
25
+ ],
26
+ "exclude": [
27
+ "node_modules",
28
+ "**/*.spec.ts",
29
+ "tests"
30
+ ]
31
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "outDir": "../../dist/libs/core"
6
+ },
7
+ "include": [
8
+ "src/**/*"
9
+ ],
10
+ "exclude": [
11
+ "node_modules",
12
+ "dist",
13
+ "test",
14
+ "**/*spec.ts"
15
+ ]
16
+ }
@@ -1,2 +0,0 @@
1
- import type { NestExpressApplication } from '@nestjs/platform-express';
2
- export declare function bootstrapSetup(AppModule: any, SetupSwagger: any): Promise<NestExpressApplication<import("http").Server>>;
@@ -1,10 +0,0 @@
1
- import type { IFile } from '../../interfaces';
2
- import { ApiConfigService } from './api-config.service';
3
- import { GeneratorService } from './generator.service';
4
- export declare class AwsS3Service {
5
- configService: ApiConfigService;
6
- generatorService: GeneratorService;
7
- private readonly s3;
8
- constructor(configService: ApiConfigService, generatorService: GeneratorService);
9
- uploadImage(file: IFile): Promise<string>;
10
- }
@@ -1,56 +0,0 @@
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.AwsS3Service = void 0;
22
- const client_s3_1 = require("@aws-sdk/client-s3");
23
- const common_1 = require("@nestjs/common");
24
- const mime_types_1 = require("mime-types");
25
- const api_config_service_1 = require("./api-config.service");
26
- const generator_service_1 = require("./generator.service");
27
- let AwsS3Service = class AwsS3Service {
28
- constructor(configService, generatorService) {
29
- this.configService = configService;
30
- this.generatorService = generatorService;
31
- const awsS3Config = configService.awsS3Config;
32
- this.s3 = new client_s3_1.S3({
33
- apiVersion: awsS3Config.bucketApiVersion,
34
- region: awsS3Config.bucketRegion,
35
- });
36
- }
37
- uploadImage(file) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const fileName = this.generatorService.fileName(mime_types_1.default.extension(file.mimetype));
40
- const key = 'images/' + fileName;
41
- yield this.s3.putObject({
42
- Bucket: this.configService.awsS3Config.bucketName,
43
- Body: file.buffer,
44
- ACL: 'public-read',
45
- Key: key,
46
- });
47
- return key;
48
- });
49
- }
50
- };
51
- exports.AwsS3Service = AwsS3Service;
52
- exports.AwsS3Service = AwsS3Service = __decorate([
53
- (0, common_1.Injectable)(),
54
- __metadata("design:paramtypes", [api_config_service_1.ApiConfigService,
55
- generator_service_1.GeneratorService])
56
- ], AwsS3Service);