@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
@@ -0,0 +1,10 @@
1
+ import type { PipeTransform } from '@nestjs/common';
2
+ import { Param, ParseUUIDPipe } from '@nestjs/common';
3
+ import type { Type } from '@nestjs/common/interfaces';
4
+
5
+ export function UUIDParam(
6
+ property: string,
7
+ ...pipes: Array<Type<PipeTransform> | PipeTransform>
8
+ ): ParameterDecorator {
9
+ return Param(property, new ParseUUIDPipe({ version: '4' }), ...pipes);
10
+ }
@@ -0,0 +1,12 @@
1
+ export * from './api-page-ok-response.decorator';
2
+ export * from './auth-user.decorator';
3
+ export * from './field.decorators';
4
+ export * from './http.decorators';
5
+ export * from './property.decorators';
6
+ export * from './public-route.decorator';
7
+ export * from './swagger.schema';
8
+ export * from './transform.decorators';
9
+ export * from './translate.decorator';
10
+ export * from './use-dto.decorator';
11
+ export * from './validator.decorators';
12
+ export * from './controller.decorator';
@@ -0,0 +1,4 @@
1
+ import { SetMetadata } from '@nestjs/common';
2
+
3
+ export const OperationLog = (operation: string) =>
4
+ SetMetadata('operation-log', operation);
@@ -0,0 +1,62 @@
1
+ import type { ApiPropertyOptions } from '@nestjs/swagger';
2
+ import { ApiProperty } from '@nestjs/swagger';
3
+
4
+ import { getVariableName } from '../common/utils';
5
+ import { getEnumDescription } from '../decorators/field.decorators';
6
+
7
+ export function ApiBooleanProperty(
8
+ options: Omit<ApiPropertyOptions, 'type'> = {},
9
+ ): PropertyDecorator {
10
+ return ApiProperty({ type: Boolean, ...options });
11
+ }
12
+
13
+ export function ApiBooleanPropertyOptional(
14
+ options: Omit<ApiPropertyOptions, 'type' | 'required'> = {},
15
+ ): PropertyDecorator {
16
+ return ApiBooleanProperty({ required: false, ...options });
17
+ }
18
+
19
+ export function ApiUUIDProperty(
20
+ options: Omit<ApiPropertyOptions, 'type' | 'format'> &
21
+ Partial<{ each: boolean }> = {},
22
+ ): PropertyDecorator {
23
+ return ApiProperty({
24
+ type: options.each ? [String] : String,
25
+ format: 'uuid',
26
+ isArray: options.each,
27
+ ...options,
28
+ });
29
+ }
30
+
31
+ export function ApiUUIDPropertyOptional(
32
+ options: Omit<ApiPropertyOptions, 'type' | 'format' | 'required'> &
33
+ Partial<{ each: boolean }> = {},
34
+ ): PropertyDecorator {
35
+ return ApiUUIDProperty({ required: false, ...options });
36
+ }
37
+
38
+ export function ApiEnumProperty<TEnum>(
39
+ getEnum: () => TEnum,
40
+ options: Omit<ApiPropertyOptions, 'type'> & { each?: boolean } = {},
41
+ ): PropertyDecorator {
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ const enumValue = getEnum() as any;
44
+ options.description = getEnumDescription(enumValue);
45
+ return ApiProperty({
46
+ type: 'enum',
47
+ // throw error during the compilation of swagger
48
+ // isArray: options.each,
49
+ enum: enumValue,
50
+ enumName: getVariableName(getEnum),
51
+ ...options,
52
+ });
53
+ }
54
+
55
+ export function ApiEnumPropertyOptional<TEnum>(
56
+ getEnum: () => TEnum,
57
+ options: Omit<ApiPropertyOptions, 'type' | 'required'> & {
58
+ each?: boolean;
59
+ } = {},
60
+ ): PropertyDecorator {
61
+ return ApiEnumProperty(getEnum, { required: false, ...options });
62
+ }
@@ -0,0 +1,8 @@
1
+ import type { CustomDecorator } from '@nestjs/common';
2
+ import { SetMetadata } from '@nestjs/common';
3
+
4
+ export const PUBLIC_ROUTE_KEY = 'public_route';
5
+
6
+ // eslint-disable-next-line @typescript-eslint/naming-convention
7
+ export const PublicRoute = (isPublic = false): CustomDecorator =>
8
+ SetMetadata(PUBLIC_ROUTE_KEY, isPublic);
@@ -0,0 +1,117 @@
1
+ /* eslint-disable @typescript-eslint/ban-types,@typescript-eslint/no-unsafe-argument */
2
+ import type { Type } from '@nestjs/common';
3
+ import { applyDecorators, UseInterceptors } from '@nestjs/common';
4
+ import { PARAMTYPES_METADATA, ROUTE_ARGS_METADATA } from '@nestjs/common/constants';
5
+ import { RouteParamtypes } from '@nestjs/common/enums/route-paramtypes.enum';
6
+ import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
7
+ import { ApiBody, ApiConsumes, ApiExtraModels, getSchemaPath } from '@nestjs/swagger';
8
+ import type { ReferenceObject, SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
9
+ import { reverseObjectKeys } from '@nestjs/swagger/dist/utils/reverse-object-keys.util';
10
+ import _ from 'lodash';
11
+
12
+ import type { IApiFile } from '../interfaces';
13
+
14
+ function explore(instance: Object, propertyKey: string | symbol) {
15
+ const types: Array<Type<unknown>> = Reflect.getMetadata(
16
+ PARAMTYPES_METADATA,
17
+ instance,
18
+ propertyKey,
19
+ );
20
+ const routeArgsMetadata =
21
+ Reflect.getMetadata(
22
+ ROUTE_ARGS_METADATA,
23
+ instance.constructor,
24
+ propertyKey,
25
+ ) || {};
26
+
27
+ const parametersWithType = _.mapValues(
28
+ reverseObjectKeys(routeArgsMetadata),
29
+ (param) => ({
30
+ type: types[param.index],
31
+ name: param.data,
32
+ required: true,
33
+ }),
34
+ );
35
+
36
+ for (const [key, value] of Object.entries(parametersWithType)) {
37
+ const keyPair = key.split(':');
38
+
39
+ if (Number(keyPair[0]) === RouteParamtypes.BODY) {
40
+ return value.type;
41
+ }
42
+ }
43
+ }
44
+
45
+ function RegisterModels(): MethodDecorator {
46
+ return (target, propertyKey, descriptor: PropertyDescriptor) => {
47
+ const body = explore(target, propertyKey);
48
+
49
+ return body && ApiExtraModels(body)(target, propertyKey, descriptor);
50
+ };
51
+ }
52
+
53
+ function ApiFileDecorator(
54
+ files: IApiFile[] = [],
55
+ options: Partial<{ isRequired: boolean }> = {},
56
+ ): MethodDecorator {
57
+ return (target, propertyKey, descriptor: PropertyDescriptor) => {
58
+ const { isRequired = false } = options;
59
+ const fileSchema: SchemaObject = {
60
+ type: 'string',
61
+ format: 'binary',
62
+ };
63
+ const properties: Record<string, SchemaObject | ReferenceObject> = {};
64
+
65
+ for (const file of files) {
66
+ if (file.isArray) {
67
+ properties[file.name] = {
68
+ type: 'array',
69
+ items: fileSchema,
70
+ };
71
+ } else {
72
+ properties[file.name] = fileSchema;
73
+ }
74
+ }
75
+
76
+ let schema: SchemaObject = {
77
+ properties,
78
+ type: 'object',
79
+ };
80
+ const body = explore(target, propertyKey);
81
+
82
+ if (body) {
83
+ schema = {
84
+ allOf: [
85
+ {
86
+ $ref: getSchemaPath(body),
87
+ },
88
+ { properties, type: 'object' },
89
+ ],
90
+ };
91
+ }
92
+
93
+ return ApiBody({
94
+ schema,
95
+ required: isRequired,
96
+ })(target, propertyKey, descriptor);
97
+ };
98
+ }
99
+
100
+ export function ApiFile(
101
+ files: _.Many<IApiFile>,
102
+ options: Partial<{ isRequired: boolean }> = {},
103
+ ): MethodDecorator {
104
+ const filesArray = _.castArray(files);
105
+ const apiFileInterceptors = filesArray.map((file) =>
106
+ file.isArray
107
+ ? UseInterceptors(FilesInterceptor(file.name))
108
+ : UseInterceptors(FileInterceptor(file.name)),
109
+ );
110
+
111
+ return applyDecorators(
112
+ RegisterModels(),
113
+ ApiConsumes('multipart/form-data'),
114
+ ApiFileDecorator(filesArray, options),
115
+ ...apiFileInterceptors,
116
+ );
117
+ }
@@ -0,0 +1,29 @@
1
+ import { applyDecorators } from '@nestjs/common';
2
+ import { ApiProperty } from '@nestjs/swagger';
3
+ import { Column } from 'typeorm';
4
+ import { formatDateTime, strToTimeStamp } from '../helpers';
5
+
6
+ export function TimestampColumn(name: string, description?: string) {
7
+ return applyDecorators(
8
+ ApiProperty({
9
+ required: false,
10
+ type: 'string',
11
+ format: 'date-time',
12
+ example: '2018-10-01 12:18:48',
13
+ description,
14
+ }),
15
+ Column({
16
+ type: 'int',
17
+ name,
18
+ nullable: false,
19
+ unsigned: true,
20
+ default: 0,
21
+ comment: description,
22
+ transformer: {
23
+ to: (value) =>
24
+ value === 0 || /\d{10}/.test(value) ? value : strToTimeStamp(value),
25
+ from: (value) => formatDateTime(value),
26
+ },
27
+ }),
28
+ );
29
+ }
@@ -0,0 +1,159 @@
1
+ import { Transform, TransformationType } from 'class-transformer';
2
+ import { parsePhoneNumber } from 'libphonenumber-js';
3
+ import { castArray, isArray, map, trim } from 'lodash';
4
+
5
+ import { GeneratorProvider } from '../providers';
6
+
7
+ /**
8
+ * @description trim spaces from start and end, replace multiple spaces with one.
9
+ * @example
10
+ * @ApiProperty()
11
+ * @IsString()
12
+ * @Trim()
13
+ * name: string;
14
+ * @returns PropertyDecorator
15
+ * @constructor
16
+ */
17
+ export function Trim(): PropertyDecorator {
18
+ return Transform((params) => {
19
+ const value = params.value as string[] | string;
20
+
21
+ if (isArray(value)) {
22
+ // @ts-ignore
23
+ return map(value, (v) => trim(v).replaceAll(/\s\s+/g, ' '));
24
+ }
25
+
26
+ // @ts-ignore
27
+ return trim(value).replaceAll(/\s\s+/g, ' ');
28
+ });
29
+ }
30
+
31
+ export function ToBoolean(): PropertyDecorator {
32
+ return Transform(
33
+ (params) => {
34
+ switch (params.value) {
35
+ case 'true': {
36
+ return true;
37
+ }
38
+
39
+ case 'false': {
40
+ return false;
41
+ }
42
+
43
+ default: {
44
+ return params.value;
45
+ }
46
+ }
47
+ },
48
+ { toClassOnly: true },
49
+ );
50
+ }
51
+
52
+ /**
53
+ * @description convert string or number to integer
54
+ * @example
55
+ * @IsNumber()
56
+ * @ToInt()
57
+ * name: number;
58
+ * @returns PropertyDecorator
59
+ * @constructor
60
+ */
61
+ export function ToInt(): PropertyDecorator {
62
+ return Transform(
63
+ (params) => {
64
+ const value = params.value as string;
65
+
66
+ return Number.parseInt(value, 10);
67
+ },
68
+ { toClassOnly: true },
69
+ );
70
+ }
71
+
72
+ /**
73
+ * @description transforms to array, specially for query params
74
+ * @example
75
+ * @IsNumber()
76
+ * @ToArray()
77
+ * name: number;
78
+ * @constructor
79
+ */
80
+ export function ToArray(): PropertyDecorator {
81
+ return Transform(
82
+ (params): unknown[] => {
83
+ const value = params.value;
84
+
85
+ if (!value) {
86
+ return value;
87
+ }
88
+
89
+ return castArray(value);
90
+ },
91
+ { toClassOnly: true },
92
+ );
93
+ }
94
+
95
+ export function ToLowerCase(): PropertyDecorator {
96
+ return Transform(
97
+ (params) => {
98
+ const value = params.value;
99
+
100
+ if (!value) {
101
+ return;
102
+ }
103
+
104
+ if (!Array.isArray(value)) {
105
+ return value.toLowerCase();
106
+ }
107
+
108
+ return value.map((v) => v.toLowerCase());
109
+ },
110
+ {
111
+ toClassOnly: true,
112
+ },
113
+ );
114
+ }
115
+
116
+ export function ToUpperCase(): PropertyDecorator {
117
+ return Transform(
118
+ (params) => {
119
+ const value = params.value;
120
+
121
+ if (!value) {
122
+ return;
123
+ }
124
+
125
+ if (!Array.isArray(value)) {
126
+ return value.toUpperCase();
127
+ }
128
+
129
+ return value.map((v) => v.toUpperCase());
130
+ },
131
+ {
132
+ toClassOnly: true,
133
+ },
134
+ );
135
+ }
136
+
137
+ export function S3UrlParser(): PropertyDecorator {
138
+ return Transform((params) => {
139
+ const key = params.value as string;
140
+
141
+ switch (params.type) {
142
+ case TransformationType.CLASS_TO_PLAIN: {
143
+ return GeneratorProvider.getS3PublicUrl(key);
144
+ }
145
+
146
+ case TransformationType.PLAIN_TO_CLASS: {
147
+ return GeneratorProvider.getS3Key(key);
148
+ }
149
+
150
+ default: {
151
+ return key;
152
+ }
153
+ }
154
+ });
155
+ }
156
+
157
+ export function PhoneNumberSerializer(): PropertyDecorator {
158
+ return Transform((params) => parsePhoneNumber(params.value as string).number);
159
+ }
@@ -0,0 +1,19 @@
1
+ import type { ITranslationDecoratorInterface } from '../interfaces';
2
+
3
+ export const STATIC_TRANSLATION_DECORATOR_KEY = 'custom:static-translate';
4
+ export const DYNAMIC_TRANSLATION_DECORATOR_KEY = 'custom:dynamic-translate';
5
+
6
+ // FIXME: This is a temporary solution to get the translation decorator working.
7
+ export function StaticTranslate(
8
+ data: ITranslationDecoratorInterface = {},
9
+ ): PropertyDecorator {
10
+ return (target, key) => {
11
+ Reflect.defineMetadata(STATIC_TRANSLATION_DECORATOR_KEY, data, target, key);
12
+ };
13
+ }
14
+
15
+ export function DynamicTranslate(): PropertyDecorator {
16
+ return (target, key) => {
17
+ Reflect.defineMetadata(DYNAMIC_TRANSLATION_DECORATOR_KEY, {}, target, key);
18
+ };
19
+ }
@@ -0,0 +1,11 @@
1
+ import type { AbstractEntity } from '../common/abstract.entity';
2
+ import type { AbstractDto } from '../common/dto/abstract.dto';
3
+ import type { Constructor } from '../common/types';
4
+
5
+ export function UseDto(
6
+ dtoClass: Constructor<AbstractDto, [AbstractEntity, unknown]>,
7
+ ): ClassDecorator {
8
+ return (ctor) => {
9
+ ctor.prototype.dtoClass = dtoClass;
10
+ };
11
+ }
@@ -0,0 +1,30 @@
1
+ import { createParamDecorator, ExecutionContext } from '@nestjs/common';
2
+ import * as lodash from 'lodash';
3
+
4
+ export interface IUser {
5
+ uid: number;
6
+ username: string;
7
+ }
8
+
9
+ export const User = createParamDecorator(
10
+ (data: string, ctx: ExecutionContext): IUser => {
11
+ return getUserData(ctx.switchToHttp().getRequest(), data);
12
+ },
13
+ );
14
+
15
+ export function getUserData(req, data?: string): IUser | null {
16
+ const headers = req.headers;
17
+ if (
18
+ lodash.isEmpty(headers['x-user-id']) ||
19
+ lodash.isEmpty(headers['x-username'])
20
+ ) {
21
+ return null;
22
+ }
23
+
24
+ const user = {
25
+ uid: headers['x-user-id'],
26
+ username: headers['x-username'],
27
+ };
28
+
29
+ return data ? user[data] : user;
30
+ }
@@ -0,0 +1,59 @@
1
+ import { createParamDecorator } from '@nestjs/common';
2
+ import { isEmpty } from 'lodash';
3
+ import { ConfigService } from '@nestjs/config';
4
+ import { ContextProvider } from '../providers';
5
+
6
+ export interface IUser {
7
+ uid: string;
8
+ username: string;
9
+ tenantId: string;
10
+ appId: string;
11
+ admin: boolean;
12
+ role: string;
13
+ }
14
+
15
+ export const User = createParamDecorator(
16
+ (key?: keyof IUser): IUser | IUser[keyof IUser] => {
17
+ const authUser = ContextProvider.getAuthUser();
18
+ return key ? authUser[key] : authUser;
19
+ },
20
+ );
21
+
22
+ export function getOmniAuthData<T extends keyof IUser>(
23
+ request: { headers: Record<string, string> },
24
+ key?: T,
25
+ ): IUser[T] | IUser {
26
+ const headers = request.headers;
27
+ let user: IUser;
28
+ const configService = new ConfigService(request);
29
+
30
+ // 未通过网关透传用户信息且处于local开发环境,则从配置获取用户信息
31
+ if (isEmpty(headers['x-user-id']) && isEmpty(headers['x-app-id'])) {
32
+ if (process.env.NODE_ENV === 'dev') {
33
+ user = {
34
+ uid: configService.get('MOCK_UID'),
35
+ username: configService.get('MOCK_USERNAME'),
36
+ appId: configService.get('MOCK_APP_ID'),
37
+ tenantId: configService.get('MOCK_TENANT_ID'),
38
+ admin: configService.get('MOCK_ADMIN', false),
39
+ role: configService.get('MOCK_ROLE', ''),
40
+ };
41
+ } else {
42
+ console.debug(
43
+ 'User information is not transparently transmitted through the gateway: ' +
44
+ JSON.stringify(headers),
45
+ );
46
+ }
47
+ } else {
48
+ user = {
49
+ uid: headers['x-user-id'] || '',
50
+ username: headers['x-username'] || '',
51
+ appId: headers['x-app-id'] || '',
52
+ tenantId: headers['x-tenant-id'] || '',
53
+ admin: headers['x-admin'] === '1',
54
+ role: headers['x-role'] || '',
55
+ };
56
+ }
57
+
58
+ return key ? user[key] : user;
59
+ }
@@ -0,0 +1,15 @@
1
+ import { applyDecorators } from '@nestjs/common';
2
+ import { CrudAuth } from '@dataui/crud';
3
+ import { getOmniAuthData } from './user.decorator';
4
+
5
+ export function UserFilter(field: string) {
6
+ const obj = {};
7
+ return applyDecorators(
8
+ CrudAuth({
9
+ filter: (req) => {
10
+ obj[field] = getOmniAuthData(req, 'uid');
11
+ return obj;
12
+ },
13
+ }),
14
+ );
15
+ }
@@ -0,0 +1,98 @@
1
+ import type { ValidationOptions } from 'class-validator';
2
+ import {
3
+ IsPhoneNumber as isPhoneNumber,
4
+ registerDecorator,
5
+ ValidateIf,
6
+ } from 'class-validator';
7
+ import { isString } from 'lodash';
8
+
9
+ export function IsPassword(
10
+ validationOptions?: ValidationOptions,
11
+ ): PropertyDecorator {
12
+ return (object, propertyName: string) => {
13
+ registerDecorator({
14
+ propertyName,
15
+ name: 'isPassword',
16
+ target: object.constructor,
17
+ constraints: [],
18
+ options: validationOptions,
19
+ validator: {
20
+ validate(value: string) {
21
+ return /^[\d!#$%&*@A-Z^a-z]*$/.test(value);
22
+ },
23
+ },
24
+ });
25
+ };
26
+ }
27
+
28
+ export function IsPhoneNumber(
29
+ validationOptions?: ValidationOptions & {
30
+ region?: Parameters<typeof isPhoneNumber>[0];
31
+ },
32
+ ): PropertyDecorator {
33
+ return isPhoneNumber(validationOptions?.region, {
34
+ message: 'error.phoneNumber',
35
+ ...validationOptions,
36
+ });
37
+ }
38
+
39
+ export function IsTmpKey(
40
+ validationOptions?: ValidationOptions,
41
+ ): PropertyDecorator {
42
+ return (object, propertyName: string) => {
43
+ registerDecorator({
44
+ propertyName,
45
+ name: 'tmpKey',
46
+ target: object.constructor,
47
+ options: validationOptions,
48
+ validator: {
49
+ validate(value: string): boolean {
50
+ return isString(value) && /^tmp\//.test(value);
51
+ },
52
+ defaultMessage(): string {
53
+ return 'error.invalidTmpKey';
54
+ },
55
+ },
56
+ });
57
+ };
58
+ }
59
+
60
+ export function IsUndefinable(options?: ValidationOptions): PropertyDecorator {
61
+ return ValidateIf((obj, value) => value !== undefined, options);
62
+ }
63
+
64
+ export function IsEmptyable(options?: ValidationOptions): PropertyDecorator {
65
+ return ValidateIf(
66
+ (obj, value) =>
67
+ !(
68
+ value === null ||
69
+ value === undefined ||
70
+ (isString(value) && value.trim() === '')
71
+ ),
72
+ options,
73
+ );
74
+ }
75
+
76
+ export function IsNullable(options?: ValidationOptions): PropertyDecorator {
77
+ return ValidateIf((obj, value) => value !== null, options);
78
+ }
79
+
80
+ export function IsHttpUrl(validationOptions?: ValidationOptions) {
81
+ return function (object, propertyName: string) {
82
+ registerDecorator({
83
+ name: 'isHttpUrl',
84
+ target: object.constructor,
85
+ propertyName: propertyName,
86
+ options: validationOptions,
87
+ validator: {
88
+ validate(value: any) {
89
+ const httpUrlPattern = /^(https?:\/\/)/i;
90
+ return typeof value === 'string' && httpUrlPattern.test(value);
91
+ },
92
+ defaultMessage(): string {
93
+ return 'URL must start with http:// or https://';
94
+ },
95
+ },
96
+ });
97
+ };
98
+ }
@@ -0,0 +1,7 @@
1
+ import { BadRequestException } from '@nestjs/common';
2
+
3
+ export class FileNotImageException extends BadRequestException {
4
+ constructor(error?: string) {
5
+ super('error.fileNotImage', error);
6
+ }
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from './file-not-image.exception';
2
+ export * from './user-not-found.exception';
@@ -0,0 +1,7 @@
1
+ import { BadRequestException } from '@nestjs/common';
2
+
3
+ export class PageTypeException extends BadRequestException {
4
+ constructor() {
5
+ super('error.pageType');
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ import { NotFoundException } from '@nestjs/common';
2
+
3
+ export class UserNotFoundException extends NotFoundException {
4
+ constructor(error?: string) {
5
+ super('error.userNotFound', error);
6
+ }
7
+ }