@nest-omni/core 2.0.1-0 → 2.0.1-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/package.json +1 -1
  2. package/.history/src/common/boilerplate.polyfill_20250521135408.ts +0 -202
  3. package/.history/src/common/boilerplate.polyfill_20250712165919.ts +0 -254
  4. package/.history/src/common/boilerplate.polyfill_20250712165924.ts +0 -254
  5. package/.history/src/common/boilerplate.polyfill_20250712165927.ts +0 -254
  6. package/.history/src/common/boilerplate.polyfill_20250712170044.ts +0 -265
  7. package/.history/src/common/boilerplate.polyfill_20250712170049.ts +0 -265
  8. package/.history/src/common/boilerplate.polyfill_20250712170053.ts +0 -265
  9. package/.history/src/common/boilerplate.polyfill_20250712170610.ts +0 -280
  10. package/.history/src/common/boilerplate.polyfill_20250712170614.ts +0 -280
  11. package/.history/src/common/boilerplate.polyfill_20250712170739.ts +0 -265
  12. package/.history/src/common/boilerplate.polyfill_20250712170801.ts +0 -291
  13. package/.history/src/common/boilerplate.polyfill_20250712170809.ts +0 -317
  14. package/.history/src/common/boilerplate.polyfill_20250712170816.ts +0 -319
  15. package/.history/src/common/boilerplate.polyfill_20250712170820.ts +0 -318
  16. package/.history/src/common/boilerplate.polyfill_20250712170824.ts +0 -318
  17. package/.history/src/common/boilerplate.polyfill_20250712171040.ts +0 -289
  18. package/README.md +0 -16
  19. package/build.sh +0 -45
  20. package/dist/package.json +0 -71
  21. package/dist/yarn.lock +0 -644
  22. package/src/.hygen.js +0 -116
  23. package/src/common/abstract-client.service.ts +0 -56
  24. package/src/common/abstract.entity.ts +0 -82
  25. package/src/common/boilerplate.polyfill.ts +0 -202
  26. package/src/common/dto/abstract.dto.ts +0 -61
  27. package/src/common/dto/bulk-id.dto.ts +0 -13
  28. package/src/common/dto/create-translation.dto.ts +0 -10
  29. package/src/common/dto/index.ts +0 -6
  30. package/src/common/dto/page-meta.dto.ts +0 -37
  31. package/src/common/dto/page-options.dto.ts +0 -35
  32. package/src/common/dto/page.dto.ts +0 -36
  33. package/src/common/index.ts +0 -7
  34. package/src/common/snake-naming.strategy.ts +0 -64
  35. package/src/common/types.ts +0 -44
  36. package/src/common/utils.ts +0 -45
  37. package/src/constants/index.ts +0 -2
  38. package/src/constants/language-code.ts +0 -7
  39. package/src/constants/order.ts +0 -4
  40. package/src/decorators/api-page-ok-response.decorator.ts +0 -32
  41. package/src/decorators/auth-user.decorator.ts +0 -16
  42. package/src/decorators/controller.decorator.ts +0 -8
  43. package/src/decorators/field.decorators.ts +0 -856
  44. package/src/decorators/http.decorators.ts +0 -10
  45. package/src/decorators/index.ts +0 -12
  46. package/src/decorators/operation.decorator.ts +0 -4
  47. package/src/decorators/property.decorators.ts +0 -62
  48. package/src/decorators/public-route.decorator.ts +0 -8
  49. package/src/decorators/swagger.schema.ts +0 -117
  50. package/src/decorators/timestamp-column.decorator.ts +0 -29
  51. package/src/decorators/transform.decorators.ts +0 -159
  52. package/src/decorators/translate.decorator.ts +0 -19
  53. package/src/decorators/use-dto.decorator.ts +0 -11
  54. package/src/decorators/user-check.decorator.ts +0 -30
  55. package/src/decorators/user.decorator.ts +0 -59
  56. package/src/decorators/user_auth.decorator.ts +0 -15
  57. package/src/decorators/validator.decorators.ts +0 -98
  58. package/src/exceptions/file-not-image.exception.ts +0 -7
  59. package/src/exceptions/index.ts +0 -2
  60. package/src/exceptions/page-type.exception.ts +0 -7
  61. package/src/exceptions/user-not-found.exception.ts +0 -7
  62. package/src/filters/bad-request.filter.ts +0 -77
  63. package/src/filters/constraint-errors.ts +0 -5
  64. package/src/filters/index.ts +0 -3
  65. package/src/filters/query-failed.filter.ts +0 -32
  66. package/src/health-checker/health-checker.controller.ts +0 -51
  67. package/src/health-checker/health-checker.module.ts +0 -13
  68. package/src/health-checker/health-indicators/service.indicator.ts +0 -44
  69. package/src/helpers/common.helper.ts +0 -49
  70. package/src/helpers/date.helper.ts +0 -64
  71. package/src/helpers/index.ts +0 -2
  72. package/src/i18n/en_US/validation.json +0 -41
  73. package/src/i18n/zh_CN/validation.json +0 -41
  74. package/src/index.ts +0 -11
  75. package/src/interceptors/index.ts +0 -2
  76. package/src/interceptors/language-interceptor.service.ts +0 -28
  77. package/src/interceptors/translation-interceptor.service.ts +0 -43
  78. package/src/interfaces/IApiFile.ts +0 -4
  79. package/src/interfaces/IFile.ts +0 -8
  80. package/src/interfaces/ITranslationDecoratorInterface.ts +0 -3
  81. package/src/interfaces/index.ts +0 -3
  82. package/src/interfaces/response.ts +0 -37
  83. package/src/middlewares/index.ts +0 -4
  84. package/src/middlewares/omni-auth.middleware.ts +0 -10
  85. package/src/middlewares/powerby.middleware.ts +0 -6
  86. package/src/middlewares/request-id.middleware.ts +0 -28
  87. package/src/middlewares/xml.middleware.ts +0 -14
  88. package/src/providers/context.provider.ts +0 -109
  89. package/src/providers/generator.provider.ts +0 -66
  90. package/src/providers/index.ts +0 -2
  91. package/src/setup/bootstrap.setup.ts +0 -254
  92. package/src/setup/index.ts +0 -1
  93. package/src/shared/index.ts +0 -2
  94. package/src/shared/serviceRegistryModule.ts +0 -135
  95. package/src/shared/services/api-config.service.ts +0 -336
  96. package/src/shared/services/generator.service.ts +0 -13
  97. package/src/shared/services/index.ts +0 -4
  98. package/src/shared/services/translation.service.ts +0 -59
  99. package/src/shared/services/validator.service.ts +0 -10
  100. package/src/validator-json/decorators.ts +0 -63
  101. package/src/validator-json/default.ts +0 -257
  102. package/src/validator-json/defaultConverters.ts +0 -402
  103. package/src/validator-json/index.ts +0 -4
  104. package/src/validator-json/options.ts +0 -50
  105. package/src/validators/file-mimetype.validator.ts +0 -34
  106. package/src/validators/index.ts +0 -6
  107. package/src/validators/is-exists.validator.ts +0 -60
  108. package/src/validators/is-unique.validator.ts +0 -93
  109. package/src/validators/phone-country-code.validator.ts +0 -36
  110. package/src/validators/same-as.validator.ts +0 -27
  111. package/src/validators/skip-empty.validator.ts +0 -25
  112. package/tsconfig.json +0 -31
  113. package/tsconfig.lib.json +0 -16
  114. /package/{dist/.hygen → .hygen}/new/crud/controller.ejs.t +0 -0
  115. /package/{dist/.hygen → .hygen}/new/crud/create.dto.ejs.t +0 -0
  116. /package/{dist/.hygen → .hygen}/new/crud/entity.ejs.t +0 -0
  117. /package/{dist/.hygen → .hygen}/new/crud/get.dto.ejs.t +0 -0
  118. /package/{dist/.hygen → .hygen}/new/crud/index-dto.ejs.t +0 -0
  119. /package/{dist/.hygen → .hygen}/new/crud/index-response.dto.ejs.t +0 -0
  120. /package/{dist/.hygen → .hygen}/new/crud/module.ejs.t +0 -0
  121. /package/{dist/.hygen → .hygen}/new/crud/prompt.js +0 -0
  122. /package/{dist/.hygen → .hygen}/new/crud/service.ejs.t +0 -0
  123. /package/{dist/.hygen → .hygen}/new/crud/update.dto.ejs.t +0 -0
  124. /package/{dist/.hygen → .hygen}/new/module/controller.ejs.t +0 -0
  125. /package/{dist/.hygen → .hygen}/new/module/create-command.ejs.t +0 -0
  126. /package/{dist/.hygen → .hygen}/new/module/create.dto.ejs.t +0 -0
  127. /package/{dist/.hygen → .hygen}/new/module/dto.ejs.t +0 -0
  128. /package/{dist/.hygen → .hygen}/new/module/entity.ejs.t +0 -0
  129. /package/{dist/.hygen → .hygen}/new/module/get-query.ejs.t +0 -0
  130. /package/{dist/.hygen → .hygen}/new/module/module.ejs.t +0 -0
  131. /package/{dist/.hygen → .hygen}/new/module/not-found.exception.ejs.t +0 -0
  132. /package/{dist/.hygen → .hygen}/new/module/page-options.dto.ejs.t +0 -0
  133. /package/{dist/.hygen → .hygen}/new/module/prompt.js +0 -0
  134. /package/{dist/.hygen → .hygen}/new/module/repository.ejs.t +0 -0
  135. /package/{dist/.hygen → .hygen}/new/module/service.ejs.t +0 -0
  136. /package/{dist/.hygen → .hygen}/new/module/translation-dto.ejs.t +0 -0
  137. /package/{dist/.hygen → .hygen}/new/module/translation-entity.ejs.t +0 -0
  138. /package/{dist/.hygen → .hygen}/new/module/translation-repository.ejs.t +0 -0
  139. /package/{dist/.hygen → .hygen}/new/module/update.dto.ejs.t +0 -0
  140. /package/{dist/.hygen.js → .hygen.js} +0 -0
  141. /package/{dist/common → common}/abstract-client.service.d.ts +0 -0
  142. /package/{dist/common → common}/abstract-client.service.js +0 -0
  143. /package/{dist/common → common}/abstract.entity.d.ts +0 -0
  144. /package/{dist/common → common}/abstract.entity.js +0 -0
  145. /package/{dist/common → common}/boilerplate.polyfill.d.ts +0 -0
  146. /package/{dist/common → common}/boilerplate.polyfill.js +0 -0
  147. /package/{dist/common → common}/dto/abstract.dto.d.ts +0 -0
  148. /package/{dist/common → common}/dto/abstract.dto.js +0 -0
  149. /package/{dist/common → common}/dto/bulk-id.dto.d.ts +0 -0
  150. /package/{dist/common → common}/dto/bulk-id.dto.js +0 -0
  151. /package/{dist/common → common}/dto/create-translation.dto.d.ts +0 -0
  152. /package/{dist/common → common}/dto/create-translation.dto.js +0 -0
  153. /package/{dist/common → common}/dto/index.d.ts +0 -0
  154. /package/{dist/common → common}/dto/index.js +0 -0
  155. /package/{dist/common → common}/dto/page-meta.dto.d.ts +0 -0
  156. /package/{dist/common → common}/dto/page-meta.dto.js +0 -0
  157. /package/{dist/common → common}/dto/page-options.dto.d.ts +0 -0
  158. /package/{dist/common → common}/dto/page-options.dto.js +0 -0
  159. /package/{dist/common → common}/dto/page.dto.d.ts +0 -0
  160. /package/{dist/common → common}/dto/page.dto.js +0 -0
  161. /package/{dist/common → common}/index.d.ts +0 -0
  162. /package/{dist/common → common}/index.js +0 -0
  163. /package/{dist/common → common}/snake-naming.strategy.d.ts +0 -0
  164. /package/{dist/common → common}/snake-naming.strategy.js +0 -0
  165. /package/{dist/common → common}/types.d.ts +0 -0
  166. /package/{dist/common → common}/types.js +0 -0
  167. /package/{dist/common → common}/utils.d.ts +0 -0
  168. /package/{dist/common → common}/utils.js +0 -0
  169. /package/{dist/constants → constants}/index.d.ts +0 -0
  170. /package/{dist/constants → constants}/index.js +0 -0
  171. /package/{dist/constants → constants}/language-code.d.ts +0 -0
  172. /package/{dist/constants → constants}/language-code.js +0 -0
  173. /package/{dist/constants → constants}/order.d.ts +0 -0
  174. /package/{dist/constants → constants}/order.js +0 -0
  175. /package/{dist/decorators → decorators}/api-page-ok-response.decorator.d.ts +0 -0
  176. /package/{dist/decorators → decorators}/api-page-ok-response.decorator.js +0 -0
  177. /package/{dist/decorators → decorators}/auth-user.decorator.d.ts +0 -0
  178. /package/{dist/decorators → decorators}/auth-user.decorator.js +0 -0
  179. /package/{dist/decorators → decorators}/controller.decorator.d.ts +0 -0
  180. /package/{dist/decorators → decorators}/controller.decorator.js +0 -0
  181. /package/{dist/decorators → decorators}/field.decorators.d.ts +0 -0
  182. /package/{dist/decorators → decorators}/field.decorators.js +0 -0
  183. /package/{dist/decorators → decorators}/http.decorators.d.ts +0 -0
  184. /package/{dist/decorators → decorators}/http.decorators.js +0 -0
  185. /package/{dist/decorators → decorators}/index.d.ts +0 -0
  186. /package/{dist/decorators → decorators}/index.js +0 -0
  187. /package/{dist/decorators → decorators}/operation.decorator.d.ts +0 -0
  188. /package/{dist/decorators → decorators}/operation.decorator.js +0 -0
  189. /package/{dist/decorators → decorators}/property.decorators.d.ts +0 -0
  190. /package/{dist/decorators → decorators}/property.decorators.js +0 -0
  191. /package/{dist/decorators → decorators}/public-route.decorator.d.ts +0 -0
  192. /package/{dist/decorators → decorators}/public-route.decorator.js +0 -0
  193. /package/{dist/decorators → decorators}/swagger.schema.d.ts +0 -0
  194. /package/{dist/decorators → decorators}/swagger.schema.js +0 -0
  195. /package/{dist/decorators → decorators}/timestamp-column.decorator.d.ts +0 -0
  196. /package/{dist/decorators → decorators}/timestamp-column.decorator.js +0 -0
  197. /package/{dist/decorators → decorators}/transform.decorators.d.ts +0 -0
  198. /package/{dist/decorators → decorators}/transform.decorators.js +0 -0
  199. /package/{dist/decorators → decorators}/translate.decorator.d.ts +0 -0
  200. /package/{dist/decorators → decorators}/translate.decorator.js +0 -0
  201. /package/{dist/decorators → decorators}/use-dto.decorator.d.ts +0 -0
  202. /package/{dist/decorators → decorators}/use-dto.decorator.js +0 -0
  203. /package/{dist/decorators → decorators}/user-check.decorator.d.ts +0 -0
  204. /package/{dist/decorators → decorators}/user-check.decorator.js +0 -0
  205. /package/{dist/decorators → decorators}/user.decorator.d.ts +0 -0
  206. /package/{dist/decorators → decorators}/user.decorator.js +0 -0
  207. /package/{dist/decorators → decorators}/user_auth.decorator.d.ts +0 -0
  208. /package/{dist/decorators → decorators}/user_auth.decorator.js +0 -0
  209. /package/{dist/decorators → decorators}/validator.decorators.d.ts +0 -0
  210. /package/{dist/decorators → decorators}/validator.decorators.js +0 -0
  211. /package/{dist/exceptions → exceptions}/file-not-image.exception.d.ts +0 -0
  212. /package/{dist/exceptions → exceptions}/file-not-image.exception.js +0 -0
  213. /package/{dist/exceptions → exceptions}/index.d.ts +0 -0
  214. /package/{dist/exceptions → exceptions}/index.js +0 -0
  215. /package/{dist/exceptions → exceptions}/page-type.exception.d.ts +0 -0
  216. /package/{dist/exceptions → exceptions}/page-type.exception.js +0 -0
  217. /package/{dist/exceptions → exceptions}/user-not-found.exception.d.ts +0 -0
  218. /package/{dist/exceptions → exceptions}/user-not-found.exception.js +0 -0
  219. /package/{dist/filters → filters}/bad-request.filter.d.ts +0 -0
  220. /package/{dist/filters → filters}/bad-request.filter.js +0 -0
  221. /package/{dist/filters → filters}/constraint-errors.d.ts +0 -0
  222. /package/{dist/filters → filters}/constraint-errors.js +0 -0
  223. /package/{dist/filters → filters}/index.d.ts +0 -0
  224. /package/{dist/filters → filters}/index.js +0 -0
  225. /package/{dist/filters → filters}/query-failed.filter.d.ts +0 -0
  226. /package/{dist/filters → filters}/query-failed.filter.js +0 -0
  227. /package/{dist/health-checker → health-checker}/health-checker.controller.d.ts +0 -0
  228. /package/{dist/health-checker → health-checker}/health-checker.controller.js +0 -0
  229. /package/{dist/health-checker → health-checker}/health-checker.module.d.ts +0 -0
  230. /package/{dist/health-checker → health-checker}/health-checker.module.js +0 -0
  231. /package/{dist/health-checker → health-checker}/health-indicators/service.indicator.d.ts +0 -0
  232. /package/{dist/health-checker → health-checker}/health-indicators/service.indicator.js +0 -0
  233. /package/{dist/helpers → helpers}/common.helper.d.ts +0 -0
  234. /package/{dist/helpers → helpers}/common.helper.js +0 -0
  235. /package/{dist/helpers → helpers}/date.helper.d.ts +0 -0
  236. /package/{dist/helpers → helpers}/date.helper.js +0 -0
  237. /package/{dist/helpers → helpers}/index.d.ts +0 -0
  238. /package/{dist/helpers → helpers}/index.js +0 -0
  239. /package/{dist/i18n → i18n}/en_US/validation.json +0 -0
  240. /package/{dist/i18n → i18n}/zh_CN/validation.json +0 -0
  241. /package/{dist/index.d.ts → index.d.ts} +0 -0
  242. /package/{dist/index.js → index.js} +0 -0
  243. /package/{dist/interceptors → interceptors}/index.d.ts +0 -0
  244. /package/{dist/interceptors → interceptors}/index.js +0 -0
  245. /package/{dist/interceptors → interceptors}/language-interceptor.service.d.ts +0 -0
  246. /package/{dist/interceptors → interceptors}/language-interceptor.service.js +0 -0
  247. /package/{dist/interceptors → interceptors}/translation-interceptor.service.d.ts +0 -0
  248. /package/{dist/interceptors → interceptors}/translation-interceptor.service.js +0 -0
  249. /package/{dist/interfaces → interfaces}/IApiFile.d.ts +0 -0
  250. /package/{dist/interfaces → interfaces}/IApiFile.js +0 -0
  251. /package/{dist/interfaces → interfaces}/IFile.d.ts +0 -0
  252. /package/{dist/interfaces → interfaces}/IFile.js +0 -0
  253. /package/{dist/interfaces → interfaces}/ITranslationDecoratorInterface.d.ts +0 -0
  254. /package/{dist/interfaces → interfaces}/ITranslationDecoratorInterface.js +0 -0
  255. /package/{dist/interfaces → interfaces}/index.d.ts +0 -0
  256. /package/{dist/interfaces → interfaces}/index.js +0 -0
  257. /package/{dist/interfaces → interfaces}/response.d.ts +0 -0
  258. /package/{dist/interfaces → interfaces}/response.js +0 -0
  259. /package/{dist/middlewares → middlewares}/index.d.ts +0 -0
  260. /package/{dist/middlewares → middlewares}/index.js +0 -0
  261. /package/{dist/middlewares → middlewares}/omni-auth.middleware.d.ts +0 -0
  262. /package/{dist/middlewares → middlewares}/omni-auth.middleware.js +0 -0
  263. /package/{dist/middlewares → middlewares}/powerby.middleware.d.ts +0 -0
  264. /package/{dist/middlewares → middlewares}/powerby.middleware.js +0 -0
  265. /package/{dist/middlewares → middlewares}/request-id.middleware.d.ts +0 -0
  266. /package/{dist/middlewares → middlewares}/request-id.middleware.js +0 -0
  267. /package/{dist/middlewares → middlewares}/xml.middleware.d.ts +0 -0
  268. /package/{dist/middlewares → middlewares}/xml.middleware.js +0 -0
  269. /package/{dist/providers → providers}/context.provider.d.ts +0 -0
  270. /package/{dist/providers → providers}/context.provider.js +0 -0
  271. /package/{dist/providers → providers}/generator.provider.d.ts +0 -0
  272. /package/{dist/providers → providers}/generator.provider.js +0 -0
  273. /package/{dist/providers → providers}/index.d.ts +0 -0
  274. /package/{dist/providers → providers}/index.js +0 -0
  275. /package/{dist/setup → setup}/bootstrap.setup.d.ts +0 -0
  276. /package/{dist/setup → setup}/bootstrap.setup.js +0 -0
  277. /package/{dist/setup → setup}/index.d.ts +0 -0
  278. /package/{dist/setup → setup}/index.js +0 -0
  279. /package/{dist/shared → shared}/index.d.ts +0 -0
  280. /package/{dist/shared → shared}/index.js +0 -0
  281. /package/{dist/shared → shared}/serviceRegistryModule.d.ts +0 -0
  282. /package/{dist/shared → shared}/serviceRegistryModule.js +0 -0
  283. /package/{dist/shared → shared}/services/api-config.service.d.ts +0 -0
  284. /package/{dist/shared → shared}/services/api-config.service.js +0 -0
  285. /package/{dist/shared → shared}/services/generator.service.d.ts +0 -0
  286. /package/{dist/shared → shared}/services/generator.service.js +0 -0
  287. /package/{dist/shared → shared}/services/index.d.ts +0 -0
  288. /package/{dist/shared → shared}/services/index.js +0 -0
  289. /package/{dist/shared → shared}/services/translation.service.d.ts +0 -0
  290. /package/{dist/shared → shared}/services/translation.service.js +0 -0
  291. /package/{dist/shared → shared}/services/validator.service.d.ts +0 -0
  292. /package/{dist/shared → shared}/services/validator.service.js +0 -0
  293. /package/{dist/tsconfig.tsbuildinfo → tsconfig.tsbuildinfo} +0 -0
  294. /package/{dist/validator-json → validator-json}/decorators.d.ts +0 -0
  295. /package/{dist/validator-json → validator-json}/decorators.js +0 -0
  296. /package/{dist/validator-json → validator-json}/default.d.ts +0 -0
  297. /package/{dist/validator-json → validator-json}/default.js +0 -0
  298. /package/{dist/validator-json → validator-json}/defaultConverters.d.ts +0 -0
  299. /package/{dist/validator-json → validator-json}/defaultConverters.js +0 -0
  300. /package/{dist/validator-json → validator-json}/index.d.ts +0 -0
  301. /package/{dist/validator-json → validator-json}/index.js +0 -0
  302. /package/{dist/validator-json → validator-json}/options.d.ts +0 -0
  303. /package/{dist/validator-json → validator-json}/options.js +0 -0
  304. /package/{dist/validators → validators}/file-mimetype.validator.d.ts +0 -0
  305. /package/{dist/validators → validators}/file-mimetype.validator.js +0 -0
  306. /package/{dist/validators → validators}/index.d.ts +0 -0
  307. /package/{dist/validators → validators}/index.js +0 -0
  308. /package/{dist/validators → validators}/is-exists.validator.d.ts +0 -0
  309. /package/{dist/validators → validators}/is-exists.validator.js +0 -0
  310. /package/{dist/validators → validators}/is-unique.validator.d.ts +0 -0
  311. /package/{dist/validators → validators}/is-unique.validator.js +0 -0
  312. /package/{dist/validators → validators}/phone-country-code.validator.d.ts +0 -0
  313. /package/{dist/validators → validators}/phone-country-code.validator.js +0 -0
  314. /package/{dist/validators → validators}/same-as.validator.d.ts +0 -0
  315. /package/{dist/validators → validators}/same-as.validator.js +0 -0
  316. /package/{dist/validators → validators}/skip-empty.validator.d.ts +0 -0
  317. /package/{dist/validators → validators}/skip-empty.validator.js +0 -0
@@ -1,336 +0,0 @@
1
- import { BadRequestException, Injectable } from '@nestjs/common';
2
- import { ConfigService } from '@nestjs/config';
3
- import type { TypeOrmModuleOptions } from '@nestjs/typeorm';
4
- import { isNil } from 'lodash';
5
- import session from 'express-session';
6
- import { Params } from 'nestjs-pino';
7
- import { redisStore } from 'cache-manager-ioredis-yet';
8
- import { BullRootModuleOptions } from '@nestjs/bull/dist/interfaces/bull-module-options.interface';
9
- import RedisStore from 'connect-redis';
10
- import Redis from 'ioredis';
11
- import { AxiosProxyConfig } from 'axios';
12
- import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
13
- import { SnakeNamingStrategy } from '../../common';
14
-
15
- @Injectable()
16
- export class ApiConfigService {
17
- static rootPath: string;
18
-
19
- constructor(private configService: ConfigService) {}
20
-
21
- static getRootPath(): string {
22
- if (!ApiConfigService.rootPath) {
23
- throw new Error(`rootPath is not set`);
24
- }
25
- return ApiConfigService.rootPath;
26
- }
27
-
28
- get isDev(): boolean {
29
- return this.nodeEnv === 'dev';
30
- }
31
-
32
- get apiVersion(): string {
33
- return this.getString('API_VERSION');
34
- }
35
-
36
- get isProd(): boolean {
37
- return this.nodeEnv === 'prod';
38
- }
39
-
40
- get isSit(): boolean {
41
- return this.nodeEnv === 'sit';
42
- }
43
-
44
- get isUat(): boolean {
45
- return this.nodeEnv === 'uat';
46
- }
47
-
48
- get isTest(): boolean {
49
- return this.nodeEnv === 'test';
50
- }
51
-
52
- getNumber(key: string, defaultValue?: number): number {
53
- const value = this.get(key, defaultValue);
54
-
55
- try {
56
- return Number(value);
57
- } catch {
58
- throw new Error(`key:${key}, value:${value} - is not a number`);
59
- }
60
- }
61
-
62
- getBoolean(key: string, defaultValue?: boolean): boolean {
63
- const value = this.get(key, defaultValue);
64
-
65
- return ApiConfigService.toBoolean(value);
66
- }
67
-
68
- static toBoolean(value: string, defaultValue = null): boolean {
69
- try {
70
- return Boolean(JSON.parse(value));
71
- } catch {
72
- if (!isNil(defaultValue)) {
73
- return defaultValue;
74
- }
75
- throw new Error(`value:${value} - is not a boolean`);
76
- }
77
- }
78
-
79
- getString(key: string): string {
80
- const value = this.get(key);
81
-
82
- return value.replace(/\\n/g, '\n');
83
- }
84
-
85
- get nodeEnv(): string {
86
- return this.getString('NODE_ENV');
87
- }
88
-
89
- get fallbackLanguage(): string {
90
- return this.getString('FALLBACK_LANGUAGE');
91
- }
92
-
93
- get typeormConfig(): TypeOrmModuleOptions {
94
- return {
95
- autoLoadEntities: true,
96
- keepConnectionAlive: !this.isDev,
97
- type: 'mysql',
98
- host: this.getString('DB_HOST'),
99
- port: this.getNumber('DB_PORT'),
100
- username: this.getString('DB_USERNAME'),
101
- password: this.getString('DB_PASSWORD'),
102
- database: this.getString('DB_DATABASE'),
103
- subscribers: [],
104
- synchronize: this.isDev,
105
- migrationsRun: true,
106
- logging: this.getBoolean('DB_LOG_ENABLED'),
107
- maxQueryExecutionTime: 3000,
108
- namingStrategy: new SnakeNamingStrategy(),
109
- timezone: this.getString('TZ'),
110
- cache: this.getBoolean('DB_CACHE_ENABLED')
111
- ? {
112
- type: 'ioredis',
113
- options: this.ioRedisConfig,
114
- }
115
- : false,
116
- };
117
- }
118
-
119
- get documentationEnabled(): boolean {
120
- return this.getBoolean('SWAGGER_ENABLED');
121
- }
122
-
123
- get documentationPath(): string {
124
- return this.getString('SWAGGER_PATH');
125
- }
126
-
127
- get viewsEnabled(): boolean {
128
- return this.getBoolean('VIEWS_ENABLED');
129
- }
130
-
131
- get sessionEnabled(): boolean {
132
- return this.getBoolean('SESSION_ENABLED');
133
- }
134
-
135
- get corsEnabled(): boolean {
136
- try {
137
- return this.getBoolean('CORS_ENABLED');
138
- } catch (error) {
139
- return false;
140
- }
141
- }
142
-
143
- get corsConfig(): CorsOptions {
144
- const allowedDomains = this.getString('CORS_ORIGIN').split(',');
145
- return {
146
- origin: (origin, callback) => {
147
- if (!origin) {
148
- return callback(null, true);
149
- }
150
-
151
- // 支持通配符匹配逻辑
152
- const isAllowed = allowedDomains.some((domain) => {
153
- // 处理包含通配符的情况(如 *.example.com)
154
- if (domain.includes('*')) {
155
- // 将通配符转换为正则表达式
156
- const regexPattern = domain
157
- .replace(/\./g, '\\.')
158
- .replace(':*', '(:\\d+)?') // 处理端口通配符
159
- .replace('*\\.', '(.*\\.)?');
160
- const fullRegex = new RegExp(`^https?:\/\/${regexPattern}$`, 'i');
161
- return fullRegex.test(origin);
162
- }
163
-
164
- // 完全匹配(包含端口匹配)
165
- return origin === domain || origin.startsWith(`${domain}:`);
166
- });
167
-
168
- isAllowed
169
- ? callback(null, origin)
170
- : callback(new BadRequestException('Not allowed by CORS'));
171
- },
172
- methods: this.getString('CORS_METHODS'),
173
- allowedHeaders: this.getString('CORS_ALLOWED_HEADERS'),
174
- exposedHeaders: this.getString('CORS_EXPOSED_HEADERS'),
175
- credentials: this.getBoolean('CORS_CREDENTIALS'),
176
- optionsSuccessStatus: 200,
177
- };
178
- }
179
-
180
- get sessionConfig(): session.SessionOptions {
181
- const config: session.SessionOptions = {
182
- secret: this.getString('SESSION_KEY'),
183
- resave: false,
184
- saveUninitialized: false,
185
- };
186
-
187
- if (this.getBoolean('SESSION_REDIS_ENABLED')) {
188
- config.store = new RedisStore({
189
- client: new Redis(this.ioRedisConfig),
190
- prefix: this.getString('SESSION_REDIS_PREFIX'),
191
- });
192
- }
193
-
194
- return config;
195
- }
196
-
197
- get authConfig() {
198
- return {
199
- privateKey: this.getString('JWT_PRIVATE_KEY'),
200
- publicKey: this.getString('JWT_PUBLIC_KEY'),
201
- jwtExpirationTime: this.getNumber('JWT_EXPIRATION_TIME'),
202
- };
203
- }
204
-
205
- get appConfig() {
206
- return {
207
- port: this.getString('PORT'),
208
- };
209
- }
210
-
211
- get apiKey(): string {
212
- return this.getString('API_KEY');
213
- }
214
-
215
- get ioRedisConfig() {
216
- return {
217
- host: this.getString('REDIS_HOST'),
218
- port: this.getNumber('REDIS_PORT'),
219
- username: this.getString('REDIS_USERNAME'),
220
- password: this.getString('REDIS_PASSWORD'),
221
- db: this.getNumber('REDIS_DB'),
222
- };
223
- }
224
-
225
- /**
226
- * 是否使用Redis,用于health check
227
- */
228
- get isRedisEnabled(): boolean {
229
- return (
230
- this.getBoolean('BULL_ENABLED') ||
231
- this.getBoolean('CACHE_ENABLED') ||
232
- this.getBoolean('DB_CACHE_ENABLED') ||
233
- (this.sessionEnabled && this.getBoolean('SESSION_REDIS_ENABLED'))
234
- );
235
- }
236
-
237
- get bullConfig(): BullRootModuleOptions {
238
- return {
239
- redis: {
240
- ...this.ioRedisConfig,
241
- // 增加重连策略
242
- retryStrategy: (times: number) => Math.min(times * 1000, 5000),
243
- },
244
- prefix: this.getString('BULL_PREFIX'),
245
- defaultJobOptions: {
246
- removeOnComplete: true,
247
- removeOnFail: true,
248
- attempts: this.getNumber('BULL_JOB_ATTEMPTS', 5),
249
- backoff: {
250
- type: 'exponential',
251
- delay: this.getNumber('BULL_JOB_BACKOFF_DELAY_MS', 5000),
252
- },
253
- timeout: this.getNumber('BULL_JOB_TIMEOUT_MS', 30 * 1000), // 默认30秒超时
254
- },
255
- settings: {
256
- // 增强稳定性配置
257
- maxStalledCount: 2, // 最大卡住重试次数
258
- guardInterval: 5000, // 检查卡住任务间隔
259
- retryProcessDelay: 1000, // 进程重启后的重试延迟
260
- },
261
- // 增加队列级限流配置
262
- limiter: {
263
- max: this.getNumber('BULL_MAX_CONCURRENT_JOBS', 100), // 最大并发任务数
264
- duration: 1000, // 时间窗口
265
- },
266
- };
267
- }
268
-
269
- async cacheConfig() {
270
- return {
271
- isGlobal: true,
272
- store: await redisStore({
273
- ...this.ioRedisConfig,
274
- ttl: this.getNumber('CACHE_TTL'),
275
- }),
276
- };
277
- }
278
-
279
- get pinoConfig(): Params {
280
- const transport = this.isDev
281
- ? {
282
- target: 'pino-pretty',
283
- }
284
- : null;
285
-
286
- return {
287
- pinoHttp: {
288
- genReqId: (req: any) => req.id,
289
- transport,
290
- level: this.isDev ? 'debug' : 'info',
291
- customLogLevel: function (res) {
292
- if (res.statusCode >= 500) return 'error';
293
- if (res.statusCode >= 400) return 'warn';
294
- return 'info';
295
- },
296
- wrapSerializers: true,
297
- customProps: (req: any, res: any) => {
298
- return {
299
- env: this.nodeEnv,
300
- appName: this.getString('NAME'),
301
- user: req?.user,
302
- 'req.body': req?.body,
303
- 'res.body': res?.body,
304
- };
305
- },
306
- redact: {
307
- paths: ['req.headers.authorization', 'req.headers.apikey'],
308
- remove: true,
309
- },
310
- },
311
- };
312
- }
313
-
314
- get axiosProxyConfig(): AxiosProxyConfig | false {
315
- if (!this.getBoolean('DIRECT_PROXY_ENABLED')) {
316
- return false;
317
- }
318
- return {
319
- host: this.getString('DIRECT_PROXY_HOST'),
320
- port: this.getNumber('DIRECT_PROXY_PORT'),
321
- };
322
- }
323
-
324
- private get(key: string, defaultValue?: any): string {
325
- const value = this.configService.get<string>(key);
326
-
327
- if (isNil(value)) {
328
- if (defaultValue) {
329
- return defaultValue;
330
- }
331
- throw new Error(`key:'${key}' - environment does not set`); // probably we should call process.exit() too to avoid locking the service
332
- }
333
-
334
- return value;
335
- }
336
- }
@@ -1,13 +0,0 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { v1 as uuid } from 'uuid';
3
-
4
- @Injectable()
5
- export class GeneratorService {
6
- public uuid(): string {
7
- return uuid();
8
- }
9
-
10
- public fileName(ext: string): string {
11
- return this.uuid() + '.' + ext;
12
- }
13
- }
@@ -1,4 +0,0 @@
1
- export * from './api-config.service';
2
- export * from './generator.service';
3
- export * from './translation.service';
4
- export * from './validator.service';
@@ -1,59 +0,0 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { isArray, isString, map } from 'lodash';
3
- import type { TranslateOptions } from 'nestjs-i18n';
4
- import { I18nService } from 'nestjs-i18n';
5
-
6
- import { AbstractDto } from '../../common/dto/abstract.dto';
7
- import { STATIC_TRANSLATION_DECORATOR_KEY } from '../../decorators';
8
- import type { ITranslationDecoratorInterface } from '../../interfaces';
9
- import { ContextProvider } from '../../providers';
10
-
11
- @Injectable()
12
- export class TranslationService {
13
- constructor(private readonly i18n: I18nService) {}
14
-
15
- async translate(key: string, options?: TranslateOptions): Promise<string> {
16
- return this.i18n.translate(`${key}`, {
17
- ...options,
18
- lang: ContextProvider.getLanguage(),
19
- });
20
- }
21
-
22
- async translateNecessaryKeys<T extends AbstractDto>(dto: T): Promise<T> {
23
- if (isString(dto)) {
24
- return dto;
25
- }
26
- await Promise.all(
27
- map(dto, async (value, key) => {
28
- if (isString(value)) {
29
- const translateDec: ITranslationDecoratorInterface | undefined =
30
- Reflect.getMetadata(STATIC_TRANSLATION_DECORATOR_KEY, dto, key);
31
-
32
- if (translateDec) {
33
- return this.translate(
34
- `${translateDec.translationKey ?? key}.${value}`,
35
- );
36
- }
37
-
38
- return;
39
- }
40
-
41
- if (value instanceof AbstractDto) {
42
- return this.translateNecessaryKeys(value);
43
- }
44
-
45
- if (isArray(value)) {
46
- return Promise.all(
47
- map(value, (v) => {
48
- if (v instanceof AbstractDto) {
49
- return this.translateNecessaryKeys(v);
50
- }
51
- }),
52
- );
53
- }
54
- }),
55
- );
56
-
57
- return dto;
58
- }
59
- }
@@ -1,10 +0,0 @@
1
- import { Injectable } from '@nestjs/common';
2
-
3
- @Injectable()
4
- export class ValidatorService {
5
- public isImage(mimeType: string): boolean {
6
- const imageMimeTypes = ['image/jpeg', 'image/png'];
7
-
8
- return imageMimeTypes.includes(mimeType);
9
- }
10
- }
@@ -1,63 +0,0 @@
1
- // tslint:disable:ban-types
2
- import {
3
- ReferenceObject,
4
- SchemaObject,
5
- } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
6
- import 'reflect-metadata';
7
-
8
- import { IOptions } from './options';
9
-
10
- const SCHEMA_KEY = Symbol('class-validator-jsonschema:JSONSchema');
11
-
12
- /**
13
- * Either a plain JSON Schema object that gets merged into the existing schema,
14
- * or a function that receives as parameters the existing schema and global
15
- * options, returning an updated schema.
16
- */
17
- export type DecoratorSchema =
18
- | ReferenceObject
19
- | SchemaObject
20
- | ((
21
- source: SchemaObject,
22
- options: IOptions,
23
- ) => ReferenceObject | SchemaObject);
24
-
25
- /**
26
- * Supplement class or property with additional JSON Schema keywords.
27
- *
28
- * @param schema JSON Schema object that is merged into the schema derived from
29
- * class-validator decorators. In case of conflicts, keywords defined here
30
- * overwrite the existing ones. Alternatively you can supply a function that
31
- * receives as parameters the existing schema and global options, returning an
32
- * updated schema.
33
- */
34
- export function JSONSchema(schema: DecoratorSchema) {
35
- return (target: object | Function, key?: string) => {
36
- if (key) {
37
- setMetadataSchema(schema, target.constructor, key); // Property metadata
38
- } else {
39
- setMetadataSchema(schema, target, (target as Function).name); // Class metadata
40
- }
41
- };
42
- }
43
-
44
- /**
45
- * Get the JSON Schema stored in given target's metadata.
46
- */
47
- export function getMetadataSchema(
48
- target: object | Function,
49
- key: string,
50
- ): DecoratorSchema {
51
- return Reflect.getMetadata(SCHEMA_KEY, target.constructor, key) || {};
52
- }
53
-
54
- /**
55
- * Store given JSON Schema into target object's metadata.
56
- */
57
- function setMetadataSchema(
58
- value: DecoratorSchema,
59
- target: object | Function,
60
- key: string,
61
- ) {
62
- return Reflect.defineMetadata(SCHEMA_KEY, value, target, key);
63
- }