@nest-omni/core 1.0.56 → 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/{providers → dist/providers}/context.provider.d.ts +3 -3
  24. package/dist/setup/bootstrap.setup.d.ts +2 -0
  25. package/{setup → dist/setup}/bootstrap.setup.js +45 -27
  26. package/{shared → dist/shared}/serviceRegistryModule.js +4 -11
  27. package/{shared → dist/shared}/services/api-config.service.d.ts +3 -15
  28. package/{shared → dist/shared}/services/api-config.service.js +15 -42
  29. package/{shared → dist/shared}/services/index.d.ts +0 -1
  30. package/{shared → dist/shared}/services/index.js +0 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -0
  32. package/dist/yarn.lock +644 -0
  33. package/package.json +1 -3
  34. package/src/.hygen.js +116 -0
  35. package/src/common/abstract-client.service.ts +56 -0
  36. package/src/common/abstract.entity.ts +82 -0
  37. package/src/common/boilerplate.polyfill.ts +202 -0
  38. package/src/common/dto/abstract.dto.ts +61 -0
  39. package/src/common/dto/bulk-id.dto.ts +13 -0
  40. package/src/common/dto/create-translation.dto.ts +10 -0
  41. package/src/common/dto/index.ts +6 -0
  42. package/src/common/dto/page-meta.dto.ts +37 -0
  43. package/src/common/dto/page-options.dto.ts +35 -0
  44. package/src/common/dto/page.dto.ts +36 -0
  45. package/src/common/index.ts +7 -0
  46. package/src/common/snake-naming.strategy.ts +64 -0
  47. package/src/common/types.ts +44 -0
  48. package/src/common/utils.ts +45 -0
  49. package/src/constants/index.ts +2 -0
  50. package/src/constants/language-code.ts +7 -0
  51. package/src/constants/order.ts +4 -0
  52. package/src/decorators/api-page-ok-response.decorator.ts +32 -0
  53. package/src/decorators/auth-user.decorator.ts +16 -0
  54. package/src/decorators/controller.decorator.ts +8 -0
  55. package/src/decorators/field.decorators.ts +856 -0
  56. package/src/decorators/http.decorators.ts +10 -0
  57. package/src/decorators/index.ts +12 -0
  58. package/src/decorators/operation.decorator.ts +4 -0
  59. package/src/decorators/property.decorators.ts +62 -0
  60. package/src/decorators/public-route.decorator.ts +8 -0
  61. package/src/decorators/swagger.schema.ts +117 -0
  62. package/src/decorators/timestamp-column.decorator.ts +29 -0
  63. package/src/decorators/transform.decorators.ts +159 -0
  64. package/src/decorators/translate.decorator.ts +19 -0
  65. package/src/decorators/use-dto.decorator.ts +11 -0
  66. package/src/decorators/user-check.decorator.ts +30 -0
  67. package/src/decorators/user.decorator.ts +59 -0
  68. package/src/decorators/user_auth.decorator.ts +15 -0
  69. package/src/decorators/validator.decorators.ts +98 -0
  70. package/src/exceptions/file-not-image.exception.ts +7 -0
  71. package/src/exceptions/index.ts +2 -0
  72. package/src/exceptions/page-type.exception.ts +7 -0
  73. package/src/exceptions/user-not-found.exception.ts +7 -0
  74. package/src/filters/bad-request.filter.ts +77 -0
  75. package/src/filters/constraint-errors.ts +5 -0
  76. package/src/filters/index.ts +3 -0
  77. package/src/filters/query-failed.filter.ts +32 -0
  78. package/src/health-checker/health-checker.controller.ts +51 -0
  79. package/src/health-checker/health-checker.module.ts +13 -0
  80. package/src/health-checker/health-indicators/service.indicator.ts +44 -0
  81. package/src/helpers/common.helper.ts +49 -0
  82. package/src/helpers/date.helper.ts +64 -0
  83. package/src/helpers/index.ts +2 -0
  84. package/src/i18n/en_US/validation.json +41 -0
  85. package/src/i18n/zh_CN/validation.json +41 -0
  86. package/src/index.ts +11 -0
  87. package/src/interceptors/index.ts +2 -0
  88. package/src/interceptors/language-interceptor.service.ts +28 -0
  89. package/src/interceptors/translation-interceptor.service.ts +43 -0
  90. package/src/interfaces/IApiFile.ts +4 -0
  91. package/src/interfaces/IFile.ts +8 -0
  92. package/src/interfaces/ITranslationDecoratorInterface.ts +3 -0
  93. package/src/interfaces/index.ts +3 -0
  94. package/src/interfaces/response.ts +37 -0
  95. package/src/middlewares/index.ts +4 -0
  96. package/src/middlewares/omni-auth.middleware.ts +10 -0
  97. package/src/middlewares/powerby.middleware.ts +6 -0
  98. package/src/middlewares/request-id.middleware.ts +28 -0
  99. package/src/middlewares/xml.middleware.ts +14 -0
  100. package/src/providers/context.provider.ts +109 -0
  101. package/src/providers/generator.provider.ts +66 -0
  102. package/src/providers/index.ts +2 -0
  103. package/src/setup/bootstrap.setup.ts +254 -0
  104. package/src/setup/index.ts +1 -0
  105. package/src/shared/index.ts +2 -0
  106. package/src/shared/serviceRegistryModule.ts +135 -0
  107. package/src/shared/services/api-config.service.ts +336 -0
  108. package/src/shared/services/generator.service.ts +13 -0
  109. package/src/shared/services/index.ts +4 -0
  110. package/src/shared/services/translation.service.ts +59 -0
  111. package/src/shared/services/validator.service.ts +10 -0
  112. package/src/validator-json/decorators.ts +63 -0
  113. package/src/validator-json/default.ts +257 -0
  114. package/src/validator-json/defaultConverters.ts +402 -0
  115. package/src/validator-json/index.ts +4 -0
  116. package/src/validator-json/options.ts +50 -0
  117. package/src/validators/file-mimetype.validator.ts +34 -0
  118. package/src/validators/index.ts +6 -0
  119. package/src/validators/is-exists.validator.ts +60 -0
  120. package/src/validators/is-unique.validator.ts +93 -0
  121. package/src/validators/phone-country-code.validator.ts +36 -0
  122. package/src/validators/same-as.validator.ts +27 -0
  123. package/src/validators/skip-empty.validator.ts +25 -0
  124. package/tsconfig.json +31 -0
  125. package/tsconfig.lib.json +16 -0
  126. package/setup/bootstrap.setup.d.ts +0 -2
  127. package/shared/services/aws-s3.service.d.ts +0 -10
  128. package/shared/services/aws-s3.service.js +0 -56
  129. package/tsconfig.tsbuildinfo +0 -1
  130. /package/{.hygen → dist/.hygen}/new/crud/controller.ejs.t +0 -0
  131. /package/{.hygen → dist/.hygen}/new/crud/create.dto.ejs.t +0 -0
  132. /package/{.hygen → dist/.hygen}/new/crud/entity.ejs.t +0 -0
  133. /package/{.hygen → dist/.hygen}/new/crud/get.dto.ejs.t +0 -0
  134. /package/{.hygen → dist/.hygen}/new/crud/index-dto.ejs.t +0 -0
  135. /package/{.hygen → dist/.hygen}/new/crud/index-response.dto.ejs.t +0 -0
  136. /package/{.hygen → dist/.hygen}/new/crud/module.ejs.t +0 -0
  137. /package/{.hygen → dist/.hygen}/new/crud/prompt.js +0 -0
  138. /package/{.hygen → dist/.hygen}/new/crud/service.ejs.t +0 -0
  139. /package/{.hygen → dist/.hygen}/new/crud/update.dto.ejs.t +0 -0
  140. /package/{.hygen → dist/.hygen}/new/module/controller.ejs.t +0 -0
  141. /package/{.hygen → dist/.hygen}/new/module/create-command.ejs.t +0 -0
  142. /package/{.hygen → dist/.hygen}/new/module/create.dto.ejs.t +0 -0
  143. /package/{.hygen → dist/.hygen}/new/module/dto.ejs.t +0 -0
  144. /package/{.hygen → dist/.hygen}/new/module/entity.ejs.t +0 -0
  145. /package/{.hygen → dist/.hygen}/new/module/get-query.ejs.t +0 -0
  146. /package/{.hygen → dist/.hygen}/new/module/module.ejs.t +0 -0
  147. /package/{.hygen → dist/.hygen}/new/module/not-found.exception.ejs.t +0 -0
  148. /package/{.hygen → dist/.hygen}/new/module/page-options.dto.ejs.t +0 -0
  149. /package/{.hygen → dist/.hygen}/new/module/prompt.js +0 -0
  150. /package/{.hygen → dist/.hygen}/new/module/repository.ejs.t +0 -0
  151. /package/{.hygen → dist/.hygen}/new/module/service.ejs.t +0 -0
  152. /package/{.hygen → dist/.hygen}/new/module/translation-dto.ejs.t +0 -0
  153. /package/{.hygen → dist/.hygen}/new/module/translation-entity.ejs.t +0 -0
  154. /package/{.hygen → dist/.hygen}/new/module/translation-repository.ejs.t +0 -0
  155. /package/{.hygen → dist/.hygen}/new/module/update.dto.ejs.t +0 -0
  156. /package/{.hygen.js → dist/.hygen.js} +0 -0
  157. /package/{common → dist/common}/abstract-client.service.d.ts +0 -0
  158. /package/{common → dist/common}/abstract-client.service.js +0 -0
  159. /package/{common → dist/common}/boilerplate.polyfill.d.ts +0 -0
  160. /package/{common → dist/common}/boilerplate.polyfill.js +0 -0
  161. /package/{common → dist/common}/dto/abstract.dto.d.ts +0 -0
  162. /package/{common → dist/common}/dto/abstract.dto.js +0 -0
  163. /package/{common → dist/common}/dto/bulk-id.dto.d.ts +0 -0
  164. /package/{common → dist/common}/dto/bulk-id.dto.js +0 -0
  165. /package/{common → dist/common}/dto/create-translation.dto.d.ts +0 -0
  166. /package/{common → dist/common}/dto/create-translation.dto.js +0 -0
  167. /package/{common → dist/common}/dto/index.d.ts +0 -0
  168. /package/{common → dist/common}/dto/index.js +0 -0
  169. /package/{common → dist/common}/dto/page-meta.dto.d.ts +0 -0
  170. /package/{common → dist/common}/dto/page-meta.dto.js +0 -0
  171. /package/{common → dist/common}/dto/page-options.dto.d.ts +0 -0
  172. /package/{common → dist/common}/dto/page-options.dto.js +0 -0
  173. /package/{common → dist/common}/dto/page.dto.d.ts +0 -0
  174. /package/{common → dist/common}/dto/page.dto.js +0 -0
  175. /package/{common → dist/common}/index.d.ts +0 -0
  176. /package/{common → dist/common}/index.js +0 -0
  177. /package/{common → dist/common}/snake-naming.strategy.d.ts +0 -0
  178. /package/{common → dist/common}/snake-naming.strategy.js +0 -0
  179. /package/{common → dist/common}/types.d.ts +0 -0
  180. /package/{common → dist/common}/types.js +0 -0
  181. /package/{common → dist/common}/utils.d.ts +0 -0
  182. /package/{common → dist/common}/utils.js +0 -0
  183. /package/{constants → dist/constants}/index.d.ts +0 -0
  184. /package/{constants → dist/constants}/index.js +0 -0
  185. /package/{constants → dist/constants}/language-code.d.ts +0 -0
  186. /package/{constants → dist/constants}/language-code.js +0 -0
  187. /package/{constants → dist/constants}/order.d.ts +0 -0
  188. /package/{constants → dist/constants}/order.js +0 -0
  189. /package/{decorators → dist/decorators}/api-page-ok-response.decorator.d.ts +0 -0
  190. /package/{decorators → dist/decorators}/api-page-ok-response.decorator.js +0 -0
  191. /package/{decorators → dist/decorators}/auth-user.decorator.d.ts +0 -0
  192. /package/{decorators → dist/decorators}/auth-user.decorator.js +0 -0
  193. /package/{decorators → dist/decorators}/controller.decorator.d.ts +0 -0
  194. /package/{decorators → dist/decorators}/controller.decorator.js +0 -0
  195. /package/{decorators → dist/decorators}/field.decorators.js +0 -0
  196. /package/{decorators → dist/decorators}/http.decorators.d.ts +0 -0
  197. /package/{decorators → dist/decorators}/http.decorators.js +0 -0
  198. /package/{decorators → dist/decorators}/index.d.ts +0 -0
  199. /package/{decorators → dist/decorators}/index.js +0 -0
  200. /package/{decorators → dist/decorators}/operation.decorator.d.ts +0 -0
  201. /package/{decorators → dist/decorators}/operation.decorator.js +0 -0
  202. /package/{decorators → dist/decorators}/property.decorators.d.ts +0 -0
  203. /package/{decorators → dist/decorators}/property.decorators.js +0 -0
  204. /package/{decorators → dist/decorators}/public-route.decorator.d.ts +0 -0
  205. /package/{decorators → dist/decorators}/public-route.decorator.js +0 -0
  206. /package/{decorators → dist/decorators}/swagger.schema.d.ts +0 -0
  207. /package/{decorators → dist/decorators}/swagger.schema.js +0 -0
  208. /package/{decorators → dist/decorators}/timestamp-column.decorator.d.ts +0 -0
  209. /package/{decorators → dist/decorators}/timestamp-column.decorator.js +0 -0
  210. /package/{decorators → dist/decorators}/transform.decorators.d.ts +0 -0
  211. /package/{decorators → dist/decorators}/transform.decorators.js +0 -0
  212. /package/{decorators → dist/decorators}/translate.decorator.d.ts +0 -0
  213. /package/{decorators → dist/decorators}/translate.decorator.js +0 -0
  214. /package/{decorators → dist/decorators}/use-dto.decorator.d.ts +0 -0
  215. /package/{decorators → dist/decorators}/use-dto.decorator.js +0 -0
  216. /package/{decorators → dist/decorators}/user-check.decorator.d.ts +0 -0
  217. /package/{decorators → dist/decorators}/user-check.decorator.js +0 -0
  218. /package/{decorators → dist/decorators}/user.decorator.d.ts +0 -0
  219. /package/{decorators → dist/decorators}/user.decorator.js +0 -0
  220. /package/{decorators → dist/decorators}/user_auth.decorator.d.ts +0 -0
  221. /package/{decorators → dist/decorators}/user_auth.decorator.js +0 -0
  222. /package/{decorators → dist/decorators}/validator.decorators.d.ts +0 -0
  223. /package/{decorators → dist/decorators}/validator.decorators.js +0 -0
  224. /package/{exceptions → dist/exceptions}/file-not-image.exception.d.ts +0 -0
  225. /package/{exceptions → dist/exceptions}/file-not-image.exception.js +0 -0
  226. /package/{exceptions → dist/exceptions}/index.d.ts +0 -0
  227. /package/{exceptions → dist/exceptions}/index.js +0 -0
  228. /package/{exceptions → dist/exceptions}/page-type.exception.d.ts +0 -0
  229. /package/{exceptions → dist/exceptions}/page-type.exception.js +0 -0
  230. /package/{exceptions → dist/exceptions}/user-not-found.exception.d.ts +0 -0
  231. /package/{exceptions → dist/exceptions}/user-not-found.exception.js +0 -0
  232. /package/{filters → dist/filters}/bad-request.filter.d.ts +0 -0
  233. /package/{filters → dist/filters}/bad-request.filter.js +0 -0
  234. /package/{filters → dist/filters}/constraint-errors.d.ts +0 -0
  235. /package/{filters → dist/filters}/constraint-errors.js +0 -0
  236. /package/{filters → dist/filters}/index.d.ts +0 -0
  237. /package/{filters → dist/filters}/index.js +0 -0
  238. /package/{filters → dist/filters}/query-failed.filter.d.ts +0 -0
  239. /package/{filters → dist/filters}/query-failed.filter.js +0 -0
  240. /package/{health-checker → dist/health-checker}/health-checker.controller.d.ts +0 -0
  241. /package/{health-checker → dist/health-checker}/health-checker.controller.js +0 -0
  242. /package/{health-checker → dist/health-checker}/health-checker.module.d.ts +0 -0
  243. /package/{health-checker → dist/health-checker}/health-checker.module.js +0 -0
  244. /package/{health-checker → dist/health-checker}/health-indicators/service.indicator.d.ts +0 -0
  245. /package/{health-checker → dist/health-checker}/health-indicators/service.indicator.js +0 -0
  246. /package/{helpers → dist/helpers}/common.helper.d.ts +0 -0
  247. /package/{helpers → dist/helpers}/common.helper.js +0 -0
  248. /package/{helpers → dist/helpers}/date.helper.d.ts +0 -0
  249. /package/{helpers → dist/helpers}/date.helper.js +0 -0
  250. /package/{helpers → dist/helpers}/index.d.ts +0 -0
  251. /package/{helpers → dist/helpers}/index.js +0 -0
  252. /package/{i18n → dist/i18n}/en_US/validation.json +0 -0
  253. /package/{i18n → dist/i18n}/zh_CN/validation.json +0 -0
  254. /package/{index.d.ts → dist/index.d.ts} +0 -0
  255. /package/{index.js → dist/index.js} +0 -0
  256. /package/{interceptors → dist/interceptors}/index.d.ts +0 -0
  257. /package/{interceptors → dist/interceptors}/index.js +0 -0
  258. /package/{interceptors → dist/interceptors}/language-interceptor.service.d.ts +0 -0
  259. /package/{interceptors → dist/interceptors}/language-interceptor.service.js +0 -0
  260. /package/{interceptors → dist/interceptors}/translation-interceptor.service.d.ts +0 -0
  261. /package/{interceptors → dist/interceptors}/translation-interceptor.service.js +0 -0
  262. /package/{interfaces → dist/interfaces}/IApiFile.d.ts +0 -0
  263. /package/{interfaces → dist/interfaces}/IApiFile.js +0 -0
  264. /package/{interfaces → dist/interfaces}/IFile.d.ts +0 -0
  265. /package/{interfaces → dist/interfaces}/IFile.js +0 -0
  266. /package/{interfaces → dist/interfaces}/ITranslationDecoratorInterface.d.ts +0 -0
  267. /package/{interfaces → dist/interfaces}/ITranslationDecoratorInterface.js +0 -0
  268. /package/{interfaces → dist/interfaces}/index.d.ts +0 -0
  269. /package/{interfaces → dist/interfaces}/index.js +0 -0
  270. /package/{interfaces → dist/interfaces}/response.d.ts +0 -0
  271. /package/{interfaces → dist/interfaces}/response.js +0 -0
  272. /package/{middlewares → dist/middlewares}/index.d.ts +0 -0
  273. /package/{middlewares → dist/middlewares}/index.js +0 -0
  274. /package/{middlewares → dist/middlewares}/omni-auth.middleware.d.ts +0 -0
  275. /package/{middlewares → dist/middlewares}/omni-auth.middleware.js +0 -0
  276. /package/{middlewares → dist/middlewares}/powerby.middleware.d.ts +0 -0
  277. /package/{middlewares → dist/middlewares}/powerby.middleware.js +0 -0
  278. /package/{middlewares → dist/middlewares}/request-id.middleware.d.ts +0 -0
  279. /package/{middlewares → dist/middlewares}/request-id.middleware.js +0 -0
  280. /package/{middlewares → dist/middlewares}/xml.middleware.d.ts +0 -0
  281. /package/{middlewares → dist/middlewares}/xml.middleware.js +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
package/src/.hygen.js ADDED
@@ -0,0 +1,116 @@
1
+ module.exports = {
2
+ templates: `${__dirname}/.hygen`,
3
+ helpers: {
4
+ ControllerName(name) {
5
+ return `${this.ClassName(name)}Controller`;
6
+ },
7
+ ServiceName(name) {
8
+ return `${this.ClassName(name)}Service`;
9
+ },
10
+ ModuleName(name) {
11
+ return `${this.ClassName(name)}Module`;
12
+ },
13
+ DtoName(name) {
14
+ return `${this.ClassName(name)}Dto`;
15
+ },
16
+ TranslationDtoName(name) {
17
+ return `${this.ClassName(name)}TranslationDto`;
18
+ },
19
+ UpdateDtoName(name) {
20
+ return `Update${this.DtoName(name)}`;
21
+ },
22
+ DtoOptionName(name) {
23
+ return `I${this.DtoName(name)}Options`;
24
+ },
25
+ CreateDtoName(name) {
26
+ return `Create${this.DtoName(name)}`;
27
+ },
28
+ EntityName(name) {
29
+ return `${this.ClassName(name)}Entity`;
30
+ },
31
+ TranslationEntityName(name) {
32
+ return `${this.ClassName(name)}TranslationEntity`;
33
+ },
34
+ CreateCommandName(name) {
35
+ return `Create${this.ClassName(name)}Command`;
36
+ },
37
+ CreateHandlerName(name) {
38
+ return `Create${this.ClassName(name)}Handler`;
39
+ },
40
+ GetHandlerName(name) {
41
+ return `Get${this.ClassName(name)}Handler`;
42
+ },
43
+ GetQueryName(name) {
44
+ return `Get${this.ClassName(name)}Query`;
45
+ },
46
+ PageOptionsDtoName(name) {
47
+ return this.ClassName(name) + 'PageOptionsDto';
48
+ },
49
+ NotFoundExceptionName(name) {
50
+ return this.ClassName(name) + 'NotFoundException';
51
+ },
52
+ entityFileName(name) {
53
+ return `${this.fileName(name)}.entity`;
54
+ },
55
+ translationEntityFileName(name) {
56
+ return `${this.fileName(name)}-translation.entity`;
57
+ },
58
+ translationDtoFileName(name) {
59
+ return `${this.fileName(name)}-translation.dto`;
60
+ },
61
+ repositoryFileName(name) {
62
+ return `${this.fileName(name)}.repository`;
63
+ },
64
+ translationRepositoryFileName(name) {
65
+ return `${this.fileName(name)}-translation.repository`;
66
+ },
67
+ createCommandFileName(name) {
68
+ return `create-${this.fileName(name)}.command`;
69
+ },
70
+ getQueryFileName(name) {
71
+ return `get-${this.fileName(name)}.query`;
72
+ },
73
+ controllerFileName(name) {
74
+ return `${this.fileName(name)}.controller`;
75
+ },
76
+ dtoFileName(name) {
77
+ return `${this.fileName(name)}.dto`;
78
+ },
79
+ notFoundExceptionFileName(name) {
80
+ return `${this.fileName(name)}-not-found.exception`;
81
+ },
82
+ createDtoFileName(name) {
83
+ return `create-${this.fileName(name)}.dto`;
84
+ },
85
+ updateDtoFileName(name) {
86
+ return `update-${this.fileName(name)}.dto`;
87
+ },
88
+ pageOptionsDtoFileName(name) {
89
+ return `${this.fileName(name)}-page-options.dto`;
90
+ },
91
+ serviceFileName(name) {
92
+ return `${this.fileName(name)}.service`;
93
+ },
94
+ moduleFileName(name) {
95
+ return `${this.fileName(name)}.module`;
96
+ },
97
+ ClassName(name) {
98
+ return this.changeCase.pascal(name);
99
+ },
100
+ TableName(name) {
101
+ return this.inflection.underscore(this.ClassName(name));
102
+ },
103
+ RepositoryName(name) {
104
+ return `${this.ClassName(name)}Repository`;
105
+ },
106
+ TranslationRepositoryName(name) {
107
+ return `${this.ClassName(name)}TranslationRepository`;
108
+ },
109
+ moduleName(name) {
110
+ return this.changeCase.camel(name);
111
+ },
112
+ fileName(name) {
113
+ return this.inflection.dasherize(name).toLowerCase();
114
+ },
115
+ },
116
+ }
@@ -0,0 +1,56 @@
1
+ import type { ClientProxy } from '@nestjs/microservices';
2
+ import { plainToInstance } from 'class-transformer';
3
+ import { firstValueFrom } from 'rxjs';
4
+
5
+ import { PageTypeException } from '../exceptions/page-type.exception';
6
+ import type { Constructor } from './types';
7
+ import type { PageDto } from './dto/page.dto';
8
+ import type { PageMetaDto } from './dto/page-meta.dto';
9
+
10
+ /**
11
+ * Fixme: This class designed to use with @nestjs/microservices by extending and creating a new class.
12
+ * TODO: Create Implementation and usage of it
13
+ */
14
+ export class AbstractClientService<ActionType> {
15
+ constructor(private client: ClientProxy) {}
16
+
17
+ public async send(pattern: ActionType, data: unknown): Promise<void>;
18
+
19
+ public async send<R>(
20
+ pattern: ActionType,
21
+ data: unknown,
22
+ returnDataOptions: { class: Constructor<R>; isPage: true },
23
+ ): Promise<PageDto<R>>;
24
+
25
+ public async send<R>(
26
+ pattern: ActionType,
27
+ data: unknown,
28
+ returnDataOptions?: { class: Constructor<R>; isPage?: false },
29
+ ): Promise<R>;
30
+
31
+ public async send<R, I>(
32
+ pattern: ActionType,
33
+ data: I,
34
+ returnDataOptions?: Partial<{
35
+ class?: Constructor<R>;
36
+ isPage?: boolean;
37
+ }>,
38
+ ): Promise<R | PageDto<R> | void> {
39
+ const returnData = await firstValueFrom(
40
+ this.client.send<{ data?: R; meta?: PageMetaDto }>(pattern, data),
41
+ {
42
+ defaultValue: undefined,
43
+ },
44
+ );
45
+
46
+ if (returnDataOptions?.isPage && (!returnData?.data || !returnData.meta)) {
47
+ throw new PageTypeException();
48
+ }
49
+
50
+ if (!returnDataOptions?.class || returnDataOptions.isPage) {
51
+ return returnData as R;
52
+ }
53
+
54
+ return plainToInstance(returnDataOptions.class, returnData);
55
+ }
56
+ }
@@ -0,0 +1,82 @@
1
+ import {
2
+ BeforeInsert,
3
+ Column,
4
+ CreateDateColumn,
5
+ PrimaryGeneratedColumn,
6
+ UpdateDateColumn,
7
+ } from 'typeorm';
8
+
9
+ import type { AbstractDto, AbstractTranslationDto } from './dto/abstract.dto';
10
+ import { NumberFieldOptional, StringFieldOptional } from '../decorators';
11
+ import { LanguageCode } from '../constants';
12
+ import { v4 as uuidv4 } from 'uuid';
13
+ /**
14
+ * Abstract Entity
15
+ *
16
+ * @description This class is an abstract class for all entities.
17
+ * It's experimental and recommended using it only in microservice architecture,
18
+ * otherwise just delete and use your own entity.
19
+ */
20
+ export abstract class AbstractBaseEntity<DTO, O> {
21
+ @CreateDateColumn({
22
+ type: 'timestamp',
23
+ })
24
+ createdAt: Date;
25
+
26
+ @UpdateDateColumn({
27
+ type: 'timestamp',
28
+ })
29
+ updatedAt: Date;
30
+
31
+ translations?: AbstractTranslationEntity[];
32
+
33
+ toDto(options?: O): DTO {
34
+ const dtoClass = Object.getPrototypeOf(this).dtoClass;
35
+
36
+ if (!dtoClass) {
37
+ throw new Error(
38
+ `You need to use @UseDto on class (${this.constructor.name}) be able to call toDto function`,
39
+ );
40
+ }
41
+
42
+ return new dtoClass(this, options);
43
+ }
44
+ }
45
+
46
+ export class AbstractEntity<
47
+ DTO extends AbstractDto = AbstractDto,
48
+ O = never,
49
+ > extends AbstractBaseEntity<DTO, O> {
50
+ @PrimaryGeneratedColumn('increment')
51
+ @NumberFieldOptional({ swagger: false })
52
+ id: number;
53
+ }
54
+
55
+ export class AbstractTranslationEntity<
56
+ DTO extends AbstractTranslationDto = AbstractTranslationDto,
57
+ O = never,
58
+ > extends AbstractEntity<DTO, O> {
59
+ @Column({ type: 'enum', enum: LanguageCode })
60
+ languageCode: LanguageCode;
61
+ }
62
+
63
+ export class AbstractUuidPrimaryEntity<
64
+ DTO extends AbstractDto = AbstractDto,
65
+ O = never,
66
+ > extends AbstractBaseEntity<DTO, O> {
67
+ @PrimaryGeneratedColumn('uuid')
68
+ @StringFieldOptional({
69
+ maxLength: 36,
70
+ minLength: 2,
71
+ example: '23247899-c237-4ab1-9639-3322029d2e1c',
72
+ swagger: false,
73
+ })
74
+ id: string;
75
+
76
+ @BeforeInsert()
77
+ generateId() {
78
+ if (!this.id || this.id?.length < 2) {
79
+ this.id = uuidv4();
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,202 @@
1
+ import 'source-map-support/register';
2
+
3
+ import { compact, map } from 'lodash';
4
+ import type { ObjectLiteral } from 'typeorm';
5
+ import { Brackets, SelectQueryBuilder } from 'typeorm';
6
+
7
+ import type { AbstractEntity } from './abstract.entity';
8
+ import type { AbstractDto } from './dto/abstract.dto';
9
+ import type { CreateTranslationDto } from './dto/create-translation.dto';
10
+ import { PageDto } from './dto/page.dto';
11
+ import { PageMetaDto } from './dto/page-meta.dto';
12
+ import type { PageOptionsDto } from './dto/page-options.dto';
13
+ import type { LanguageCode } from '../constants/language-code';
14
+ import type { KeyOfType } from './types';
15
+ import { ContextProvider } from '../providers';
16
+
17
+ declare global {
18
+ export type Uuid = string & { _uuidBrand: undefined };
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-redundant-type-constituents
20
+ export type Todo = any & { _todoBrand: undefined };
21
+
22
+ // eslint-disable-next-line @typescript-eslint/naming-convention
23
+ interface Array<T> {
24
+ toDtos<Dto extends AbstractDto>(this: T[], options?: unknown): Dto[];
25
+
26
+ getByLanguage(
27
+ this: CreateTranslationDto[],
28
+ languageCode: LanguageCode,
29
+ ): string;
30
+
31
+ toPageDto<Dto extends AbstractDto>(
32
+ this: T[],
33
+ pageMetaDto: PageMetaDto,
34
+ // FIXME make option type visible from entity
35
+ options?: unknown,
36
+ ): PageDto<Dto>;
37
+ }
38
+ }
39
+
40
+ declare module 'typeorm' {
41
+ // eslint-disable-next-line @typescript-eslint/naming-convention
42
+ interface SelectQueryBuilder<Entity> {
43
+ searchByString(
44
+ q: string,
45
+ columnNames: string[],
46
+ options?: {
47
+ formStart: boolean;
48
+ },
49
+ ): this;
50
+
51
+ withTenant(tenantId?: string | number, tenantFieldName?: string): this;
52
+
53
+ paginate(
54
+ this: SelectQueryBuilder<Entity>,
55
+ pageOptionsDto: PageOptionsDto,
56
+ options?: Partial<{ takeAll: boolean; skipCount: boolean }>,
57
+ ): Promise<[Entity[], PageMetaDto]>;
58
+
59
+ leftJoinAndSelect<AliasEntity extends AbstractEntity, A extends string>(
60
+ this: SelectQueryBuilder<Entity>,
61
+ property: `${A}.${Exclude<
62
+ KeyOfType<AliasEntity, AbstractEntity>,
63
+ symbol
64
+ >}`,
65
+ alias: string,
66
+ condition?: string,
67
+ parameters?: ObjectLiteral,
68
+ ): this;
69
+
70
+ leftJoin<AliasEntity extends AbstractEntity, A extends string>(
71
+ this: SelectQueryBuilder<Entity>,
72
+ property: `${A}.${Exclude<
73
+ KeyOfType<AliasEntity, AbstractEntity>,
74
+ symbol
75
+ >}`,
76
+ alias: string,
77
+ condition?: string,
78
+ parameters?: ObjectLiteral,
79
+ ): this;
80
+
81
+ innerJoinAndSelect<AliasEntity extends AbstractEntity, A extends string>(
82
+ this: SelectQueryBuilder<Entity>,
83
+ property: `${A}.${Exclude<
84
+ KeyOfType<AliasEntity, AbstractEntity>,
85
+ symbol
86
+ >}`,
87
+ alias: string,
88
+ condition?: string,
89
+ parameters?: ObjectLiteral,
90
+ ): this;
91
+
92
+ innerJoin<AliasEntity extends AbstractEntity, A extends string>(
93
+ this: SelectQueryBuilder<Entity>,
94
+ property: `${A}.${Exclude<
95
+ KeyOfType<AliasEntity, AbstractEntity>,
96
+ symbol
97
+ >}`,
98
+ alias: string,
99
+ condition?: string,
100
+ parameters?: ObjectLiteral,
101
+ ): this;
102
+ }
103
+ }
104
+
105
+ Array.prototype.toDtos = function <
106
+ Entity extends AbstractEntity<Dto>,
107
+ Dto extends AbstractDto,
108
+ >(options?: unknown): Dto[] {
109
+ return compact(
110
+ map<Entity, Dto>(this as Entity[], (item) => item.toDto(options as never)),
111
+ );
112
+ };
113
+
114
+ Array.prototype.getByLanguage = function (languageCode: LanguageCode): string {
115
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
116
+ return this.find((translation) => languageCode === translation.languageCode)!
117
+ .text;
118
+ };
119
+
120
+ Array.prototype.toPageDto = function (
121
+ pageMetaDto: PageMetaDto,
122
+ options?: unknown,
123
+ ) {
124
+ return new PageDto(this.toDtos(options), pageMetaDto);
125
+ };
126
+
127
+ SelectQueryBuilder.prototype.searchByString = function (
128
+ q,
129
+ columnNames,
130
+ options,
131
+ ) {
132
+ if (!q) {
133
+ return this;
134
+ }
135
+
136
+ this.andWhere(
137
+ new Brackets((qb) => {
138
+ for (const item of columnNames) {
139
+ qb.orWhere(`${item} ILIKE :q`);
140
+ }
141
+ }),
142
+ );
143
+
144
+ if (options?.formStart) {
145
+ this.setParameter('q', `${q}%`);
146
+ } else {
147
+ this.setParameter('q', `%${q}%`);
148
+ }
149
+
150
+ return this;
151
+ };
152
+
153
+ SelectQueryBuilder.prototype.paginate = async function (
154
+ pageOptionsDto: PageOptionsDto,
155
+ options?: Partial<{
156
+ skipCount: boolean;
157
+ takeAll: boolean;
158
+ }>,
159
+ ) {
160
+ if (!options?.takeAll) {
161
+ this.skip(pageOptionsDto.skip).take(pageOptionsDto.pageSize);
162
+ }
163
+
164
+ const entities = await this.getMany();
165
+
166
+ let itemCount = -1;
167
+
168
+ if (!options?.skipCount) {
169
+ itemCount = await this.getCount();
170
+ }
171
+
172
+ const pageMetaDto = new PageMetaDto({
173
+ itemCount,
174
+ pageOptionsDto,
175
+ });
176
+
177
+ return [entities, pageMetaDto];
178
+ };
179
+
180
+ SelectQueryBuilder.prototype.withTenant = function (
181
+ tenantId?: number | string,
182
+ tenantFieldName: string = 'tenantId',
183
+ ) {
184
+ if (!tenantId) {
185
+ tenantId = ContextProvider.getTenantId();
186
+ }
187
+
188
+ if (this.expressionMap.mainAlias.hasMetadata) {
189
+ const entityMetadata = this.expressionMap.mainAlias.metadata;
190
+ const columnName = entityMetadata.columns.find(
191
+ (column: any) => column.propertyName === tenantFieldName,
192
+ )?.databaseName;
193
+
194
+ if (columnName) {
195
+ return this.andWhere(`${this.alias}.${columnName} = :tenantId`, {
196
+ tenantId,
197
+ });
198
+ }
199
+ }
200
+
201
+ return this;
202
+ };
@@ -0,0 +1,61 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+
3
+ import { DYNAMIC_TRANSLATION_DECORATOR_KEY } from '../../decorators';
4
+ import { ContextProvider } from '../../providers';
5
+ import { AbstractEntity, AbstractUuidPrimaryEntity } from '../abstract.entity';
6
+
7
+ export class AbstractDto {
8
+ @ApiProperty()
9
+ id: number | string;
10
+
11
+ @ApiProperty()
12
+ createdAt: Date;
13
+
14
+ @ApiProperty()
15
+ updatedAt: Date;
16
+
17
+ translations?: AbstractTranslationDto[];
18
+
19
+ constructor(
20
+ entity: AbstractEntity | AbstractUuidPrimaryEntity,
21
+ options?: { excludeFields?: boolean },
22
+ ) {
23
+ if (!options?.excludeFields) {
24
+ this.id = entity.id;
25
+ this.createdAt = entity.createdAt;
26
+ this.updatedAt = entity.updatedAt;
27
+ }
28
+
29
+ const languageCode = ContextProvider.getLanguage();
30
+
31
+ if (languageCode && entity.translations) {
32
+ const translationEntity = entity.translations.find(
33
+ (titleTranslation) => titleTranslation.languageCode === languageCode,
34
+ )!;
35
+
36
+ const fields: Record<string, string> = {};
37
+
38
+ for (const key of Object.keys(translationEntity)) {
39
+ const metadata = Reflect.getMetadata(
40
+ DYNAMIC_TRANSLATION_DECORATOR_KEY,
41
+ this,
42
+ key,
43
+ );
44
+
45
+ if (metadata) {
46
+ fields[key] = translationEntity[key];
47
+ }
48
+ }
49
+
50
+ Object.assign(this, fields);
51
+ } else {
52
+ this.translations = entity.translations?.toDtos();
53
+ }
54
+ }
55
+ }
56
+
57
+ export class AbstractTranslationDto extends AbstractDto {
58
+ constructor(entity: AbstractEntity | AbstractUuidPrimaryEntity) {
59
+ super(entity, { excludeFields: true });
60
+ }
61
+ }
@@ -0,0 +1,13 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import { IsArray } from 'class-validator';
3
+
4
+ export class BulkIdDto {
5
+ @ApiProperty({
6
+ type: 'string',
7
+ description: 'ID',
8
+ isArray: true,
9
+ required: true,
10
+ })
11
+ @IsArray()
12
+ id: number[] | string[];
13
+ }
@@ -0,0 +1,10 @@
1
+ import { LanguageCode } from '../../constants';
2
+ import { EnumField, StringField } from '../../decorators';
3
+
4
+ export class CreateTranslationDto {
5
+ @EnumField(() => LanguageCode)
6
+ languageCode: LanguageCode;
7
+
8
+ @StringField()
9
+ text: string;
10
+ }
@@ -0,0 +1,6 @@
1
+ export * from './abstract.dto';
2
+ export * from './bulk-id.dto';
3
+ export * from './create-translation.dto';
4
+ export * from './page.dto';
5
+ export * from './page-meta.dto';
6
+ export * from './page-options.dto';
@@ -0,0 +1,37 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+
3
+ import type { PageOptionsDto } from './page-options.dto';
4
+
5
+ interface IPageMetaDtoParameters {
6
+ pageOptionsDto: PageOptionsDto;
7
+ itemCount: number;
8
+ }
9
+
10
+ export class PageMetaDto {
11
+ @ApiProperty()
12
+ readonly page: number;
13
+
14
+ @ApiProperty()
15
+ readonly pageSize: number;
16
+
17
+ @ApiProperty()
18
+ readonly itemCount: number;
19
+
20
+ @ApiProperty()
21
+ readonly pageCount: number;
22
+
23
+ @ApiProperty()
24
+ readonly hasPreviousPage: boolean;
25
+
26
+ @ApiProperty()
27
+ readonly hasNextPage: boolean;
28
+
29
+ constructor({ pageOptionsDto, itemCount }: IPageMetaDtoParameters) {
30
+ this.page = pageOptionsDto.page;
31
+ this.pageSize = pageOptionsDto.pageSize;
32
+ this.itemCount = itemCount;
33
+ this.pageCount = Math.ceil(this.itemCount / this.pageSize);
34
+ this.hasPreviousPage = this.page > 1;
35
+ this.hasNextPage = this.page < this.pageCount;
36
+ }
37
+ }
@@ -0,0 +1,35 @@
1
+ import { Order } from '../../constants';
2
+ import {
3
+ EnumFieldOptional,
4
+ NumberFieldOptional,
5
+ StringFieldOptional,
6
+ } from '../../decorators';
7
+
8
+ export class PageOptionsDto {
9
+ @EnumFieldOptional(() => Order, {
10
+ default: Order.ASC,
11
+ })
12
+ readonly order: Order = Order.ASC;
13
+
14
+ @NumberFieldOptional({
15
+ minimum: 1,
16
+ default: 1,
17
+ int: true,
18
+ })
19
+ readonly page: number = 1;
20
+
21
+ @NumberFieldOptional({
22
+ minimum: 1,
23
+ maximum: 50,
24
+ default: 10,
25
+ int: true,
26
+ })
27
+ readonly pageSize: number = 10;
28
+
29
+ get skip(): number {
30
+ return (this.page - 1) * this.pageSize;
31
+ }
32
+
33
+ @StringFieldOptional()
34
+ readonly q?: string;
35
+ }
@@ -0,0 +1,36 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+
3
+ import { PageMetaDto } from './page-meta.dto';
4
+
5
+ export class PageDto<T> {
6
+ @ApiProperty({ isArray: true })
7
+ readonly data: T[];
8
+
9
+ @ApiProperty()
10
+ count: number;
11
+
12
+ @ApiProperty()
13
+ total: number;
14
+
15
+ @ApiProperty()
16
+ page: number;
17
+
18
+ @ApiProperty()
19
+ pageCount: number;
20
+
21
+ @ApiProperty()
22
+ hasPreviousPage: boolean;
23
+
24
+ @ApiProperty()
25
+ hasNextPage: boolean;
26
+
27
+ constructor(data: T[], meta: PageMetaDto) {
28
+ this.data = data;
29
+ this.count = meta.pageSize;
30
+ this.pageCount = meta.pageCount;
31
+ this.page = meta.page;
32
+ this.total = meta.itemCount;
33
+ this.hasPreviousPage = meta.hasPreviousPage;
34
+ this.hasNextPage = meta.hasNextPage;
35
+ }
36
+ }
@@ -0,0 +1,7 @@
1
+ export * from './abstract.entity';
2
+ export * from './abstract-client.service';
3
+ export * from './utils';
4
+ export * from './dto';
5
+ export * from './types';
6
+ export * from './snake-naming.strategy';
7
+ export * from './boilerplate.polyfill';