@nest-omni/core 1.0.6 → 1.0.8

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 (294) hide show
  1. package/{src → dist}/boilerplate.polyfill.js +0 -1
  2. package/{src → dist}/common/abstract-client.service.d.ts +0 -4
  3. package/{src → dist}/common/abstract-client.service.js +0 -4
  4. package/{src → dist}/common/abstract.entity.d.ts +0 -7
  5. package/dist/common/abstract.entity.js +64 -0
  6. package/dist/common/dto/abstract.dto.js +59 -0
  7. package/dist/common/dto/bulk-id.dto.js +27 -0
  8. package/dist/common/dto/create-translation.dto.js +25 -0
  9. package/dist/common/dto/page-meta.dto.js +48 -0
  10. package/dist/common/dto/page-options.dto.js +52 -0
  11. package/dist/common/dto/page.dto.js +53 -0
  12. package/{src → dist}/common/utils.d.ts +0 -11
  13. package/{src → dist}/common/utils.js +1 -15
  14. package/{src → dist}/constants/language-code.js +0 -1
  15. package/dist/decorators/controller.decorator.js +11 -0
  16. package/{src → dist}/decorators/field.decorators.js +1 -7
  17. package/{src → dist}/decorators/omni-auth.decorator.js +1 -26
  18. package/{src → dist}/decorators/property.decorators.js +1 -5
  19. package/{src → dist}/decorators/public-route.decorator.js +0 -1
  20. package/{src → dist}/decorators/swagger.schema.js +1 -4
  21. package/{src → dist}/decorators/timestamp-column.decorator.js +1 -1
  22. package/dist/decorators/transform.decorators.d.ts +8 -0
  23. package/{src → dist}/decorators/transform.decorators.js +0 -27
  24. package/{src → dist}/decorators/translate.decorator.js +0 -1
  25. package/dist/decorators/user-check.decorator.js +21 -0
  26. package/{src → dist}/decorators/user.decorator.js +1 -25
  27. package/dist/filters/bad-request.filter.js +60 -0
  28. package/{src → dist}/filters/constraint-errors.js +0 -1
  29. package/dist/filters/query-failed.filter.js +42 -0
  30. package/dist/health-checker/health-checker.controller.js +72 -0
  31. package/dist/health-checker/health-checker.module.js +25 -0
  32. package/dist/health-checker/health-indicators/service.indicator.js +66 -0
  33. package/dist/helpers/common.helper.d.ts +3 -0
  34. package/{src → dist}/helpers/common.helper.js +0 -13
  35. package/{src → dist}/helpers/date.helper.d.ts +3 -3
  36. package/{src → dist}/helpers/date.helper.js +2 -25
  37. package/dist/i18n/en_US/validation.json +38 -0
  38. package/dist/i18n/zh_CN/validation.json +38 -0
  39. package/{src → dist}/index.js +0 -1
  40. package/dist/interceptors/auth-user.interceptor.js +24 -0
  41. package/dist/interceptors/language-interceptor.service.js +30 -0
  42. package/dist/interceptors/translation-interceptor.service.js +34 -0
  43. package/{src → dist}/providers/context.provider.js +0 -2
  44. package/{src → dist}/providers/generator.provider.d.ts +0 -4
  45. package/{src → dist}/providers/generator.provider.js +0 -4
  46. package/{src → dist}/setup/bootstrap.setup.js +7 -33
  47. package/dist/shared/serviceRegistryModule.js +110 -0
  48. package/{src → dist}/shared/services/api-config.service.d.ts +0 -3
  49. package/dist/shared/services/api-config.service.js +290 -0
  50. package/dist/shared/services/aws-s3.service.js +56 -0
  51. package/dist/shared/services/generator.service.js +23 -0
  52. package/dist/shared/services/translation.service.js +70 -0
  53. package/dist/shared/services/validator.service.js +20 -0
  54. package/dist/tsconfig.tsbuildinfo +1 -0
  55. package/dist/validators/is-exists.validator.js +61 -0
  56. package/dist/validators/is-unique.validator.js +92 -0
  57. package/{src → dist}/validators/skip-empty.validator.d.ts +0 -5
  58. package/{src → dist}/validators/skip-empty.validator.js +0 -5
  59. package/package.json +4 -1
  60. package/src/boilerplate.polyfill.ts +0 -202
  61. package/src/common/abstract-client.service.ts +0 -56
  62. package/src/common/abstract.entity.js +0 -152
  63. package/src/common/abstract.entity.ts +0 -73
  64. package/src/common/dto/abstract.dto.js +0 -96
  65. package/src/common/dto/abstract.dto.ts +0 -64
  66. package/src/common/dto/bulk-id.dto.js +0 -63
  67. package/src/common/dto/bulk-id.dto.ts +0 -13
  68. package/src/common/dto/create-translation.dto.js +0 -63
  69. package/src/common/dto/create-translation.dto.ts +0 -10
  70. package/src/common/dto/page-meta.dto.js +0 -88
  71. package/src/common/dto/page-meta.dto.ts +0 -37
  72. package/src/common/dto/page-options.dto.js +0 -87
  73. package/src/common/dto/page-options.dto.ts +0 -35
  74. package/src/common/dto/page.dto.js +0 -94
  75. package/src/common/dto/page.dto.ts +0 -36
  76. package/src/common/utils.ts +0 -45
  77. package/src/constants/index.ts +0 -4
  78. package/src/constants/language-code.ts +0 -7
  79. package/src/constants/order.ts +0 -4
  80. package/src/constants/role-type.ts +0 -4
  81. package/src/constants/token-type.ts +0 -4
  82. package/src/decorators/api-page-ok-response.decorator.ts +0 -31
  83. package/src/decorators/auth-user.decorator.ts +0 -16
  84. package/src/decorators/controller.decorator.js +0 -34
  85. package/src/decorators/controller.decorator.ts +0 -8
  86. package/src/decorators/field.decorators.ts +0 -773
  87. package/src/decorators/http.decorators.ts +0 -10
  88. package/src/decorators/index.ts +0 -12
  89. package/src/decorators/omni-auth.decorator.ts +0 -46
  90. package/src/decorators/operation.decorator.ts +0 -4
  91. package/src/decorators/property.decorators.ts +0 -62
  92. package/src/decorators/public-route.decorator.ts +0 -8
  93. package/src/decorators/swagger.schema.ts +0 -117
  94. package/src/decorators/timestamp-column.decorator.ts +0 -29
  95. package/src/decorators/transform.decorators.d.ts +0 -35
  96. package/src/decorators/transform.decorators.ts +0 -147
  97. package/src/decorators/translate.decorator.ts +0 -19
  98. package/src/decorators/use-dto.decorator.ts +0 -11
  99. package/src/decorators/user-check.decorator.js +0 -44
  100. package/src/decorators/user-check.decorator.ts +0 -30
  101. package/src/decorators/user.decorator.ts +0 -48
  102. package/src/decorators/user_auth.decorator.ts +0 -15
  103. package/src/decorators/validator.decorators.ts +0 -78
  104. package/src/exceptions/file-not-image.exception.ts +0 -7
  105. package/src/exceptions/index.ts +0 -2
  106. package/src/exceptions/page-type.exception.ts +0 -7
  107. package/src/exceptions/user-not-found.exception.ts +0 -7
  108. package/src/filters/bad-request.filter.js +0 -104
  109. package/src/filters/bad-request.filter.ts +0 -67
  110. package/src/filters/constraint-errors.ts +0 -5
  111. package/src/filters/index.ts +0 -3
  112. package/src/filters/query-failed.filter.js +0 -81
  113. package/src/filters/query-failed.filter.ts +0 -32
  114. package/src/health-checker/health-checker.controller.js +0 -104
  115. package/src/health-checker/health-checker.controller.ts +0 -51
  116. package/src/health-checker/health-checker.module.js +0 -69
  117. package/src/health-checker/health-checker.module.ts +0 -13
  118. package/src/health-checker/health-indicators/service.indicator.js +0 -102
  119. package/src/health-checker/health-indicators/service.indicator.ts +0 -44
  120. package/src/helpers/common.helper.d.ts +0 -16
  121. package/src/helpers/common.helper.ts +0 -49
  122. package/src/helpers/date.helper.ts +0 -64
  123. package/src/helpers/excel.helper.d.ts +0 -27
  124. package/src/helpers/excel.helper.js +0 -338
  125. package/src/helpers/index.ts +0 -3
  126. package/src/i18n/en_US/validation.json +0 -38
  127. package/src/i18n/zh_CN/validation.json +0 -38
  128. package/src/index.ts +0 -12
  129. package/src/interceptors/auth-user.interceptor.js +0 -68
  130. package/src/interceptors/auth-user.interceptor.ts +0 -20
  131. package/src/interceptors/index.ts +0 -2
  132. package/src/interceptors/language-interceptor.service.js +0 -74
  133. package/src/interceptors/language-interceptor.service.ts +0 -31
  134. package/src/interceptors/translation-interceptor.service.js +0 -83
  135. package/src/interceptors/translation-interceptor.service.ts +0 -43
  136. package/src/interfaces/IApiFile.ts +0 -4
  137. package/src/interfaces/IFile.ts +0 -8
  138. package/src/interfaces/ITranslationDecoratorInterface.ts +0 -3
  139. package/src/interfaces/index.ts +0 -3
  140. package/src/interfaces/response.ts +0 -37
  141. package/src/middlewares/index.ts +0 -3
  142. package/src/middlewares/omni-auth.middleware.ts +0 -10
  143. package/src/middlewares/powerby.middleware.ts +0 -6
  144. package/src/middlewares/request-id.middleware.ts +0 -28
  145. package/src/providers/context.provider.ts +0 -98
  146. package/src/providers/generator.provider.ts +0 -66
  147. package/src/providers/index.ts +0 -2
  148. package/src/setup/bootstrap.setup.ts +0 -139
  149. package/src/setup/index.ts +0 -1
  150. package/src/setup/microservices.setup.js +0 -55
  151. package/src/setup-swagger.ts +0 -67
  152. package/src/shared/index.ts +0 -2
  153. package/src/shared/serviceRegistryModule.js +0 -176
  154. package/src/shared/serviceRegistryModule.ts +0 -110
  155. package/src/shared/services/api-config.service.js +0 -335
  156. package/src/shared/services/api-config.service.ts +0 -319
  157. package/src/shared/services/aws-s3.service.js +0 -96
  158. package/src/shared/services/aws-s3.service.ts +0 -39
  159. package/src/shared/services/generator.service.js +0 -67
  160. package/src/shared/services/generator.service.ts +0 -13
  161. package/src/shared/services/index.ts +0 -5
  162. package/src/shared/services/translation.service.js +0 -109
  163. package/src/shared/services/translation.service.ts +0 -59
  164. package/src/shared/services/validator.service.js +0 -64
  165. package/src/shared/services/validator.service.ts +0 -10
  166. package/src/snake-naming.strategy.ts +0 -64
  167. package/src/types.ts +0 -44
  168. package/src/validators/file-mimetype.validator.ts +0 -34
  169. package/src/validators/index.ts +0 -3
  170. package/src/validators/is-exists.validator.js +0 -99
  171. package/src/validators/is-exists.validator.ts +0 -60
  172. package/src/validators/is-unique.validator.js +0 -131
  173. package/src/validators/is-unique.validator.ts +0 -93
  174. package/src/validators/phone-country-code.validator.ts +0 -36
  175. package/src/validators/same-as.validator.ts +0 -27
  176. package/src/validators/skip-empty.validator.ts +0 -25
  177. package/tsconfig.json +0 -26
  178. package/tsconfig.lib.json +0 -16
  179. package/tsconfig.tsbuildinfo +0 -1
  180. /package/{src → dist}/boilerplate.polyfill.d.ts +0 -0
  181. /package/{src → dist}/common/dto/abstract.dto.d.ts +0 -0
  182. /package/{src → dist}/common/dto/bulk-id.dto.d.ts +0 -0
  183. /package/{src → dist}/common/dto/create-translation.dto.d.ts +0 -0
  184. /package/{src → dist}/common/dto/page-meta.dto.d.ts +0 -0
  185. /package/{src → dist}/common/dto/page-options.dto.d.ts +0 -0
  186. /package/{src → dist}/common/dto/page.dto.d.ts +0 -0
  187. /package/{src → dist}/constants/index.d.ts +0 -0
  188. /package/{src → dist}/constants/index.js +0 -0
  189. /package/{src → dist}/constants/language-code.d.ts +0 -0
  190. /package/{src → dist}/constants/order.d.ts +0 -0
  191. /package/{src → dist}/constants/order.js +0 -0
  192. /package/{src → dist}/constants/role-type.d.ts +0 -0
  193. /package/{src → dist}/constants/role-type.js +0 -0
  194. /package/{src → dist}/constants/token-type.d.ts +0 -0
  195. /package/{src → dist}/constants/token-type.js +0 -0
  196. /package/{src → dist}/decorators/api-page-ok-response.decorator.d.ts +0 -0
  197. /package/{src → dist}/decorators/api-page-ok-response.decorator.js +0 -0
  198. /package/{src → dist}/decorators/auth-user.decorator.d.ts +0 -0
  199. /package/{src → dist}/decorators/auth-user.decorator.js +0 -0
  200. /package/{src → dist}/decorators/controller.decorator.d.ts +0 -0
  201. /package/{src → dist}/decorators/field.decorators.d.ts +0 -0
  202. /package/{src → dist}/decorators/http.decorators.d.ts +0 -0
  203. /package/{src → dist}/decorators/http.decorators.js +0 -0
  204. /package/{src → dist}/decorators/index.d.ts +0 -0
  205. /package/{src → dist}/decorators/index.js +0 -0
  206. /package/{src → dist}/decorators/omni-auth.decorator.d.ts +0 -0
  207. /package/{src → dist}/decorators/operation.decorator.d.ts +0 -0
  208. /package/{src → dist}/decorators/operation.decorator.js +0 -0
  209. /package/{src → dist}/decorators/property.decorators.d.ts +0 -0
  210. /package/{src → dist}/decorators/public-route.decorator.d.ts +0 -0
  211. /package/{src → dist}/decorators/swagger.schema.d.ts +0 -0
  212. /package/{src → dist}/decorators/timestamp-column.decorator.d.ts +0 -0
  213. /package/{src → dist}/decorators/translate.decorator.d.ts +0 -0
  214. /package/{src → dist}/decorators/use-dto.decorator.d.ts +0 -0
  215. /package/{src → dist}/decorators/use-dto.decorator.js +0 -0
  216. /package/{src → dist}/decorators/user-check.decorator.d.ts +0 -0
  217. /package/{src → dist}/decorators/user.decorator.d.ts +0 -0
  218. /package/{src → dist}/decorators/user_auth.decorator.d.ts +0 -0
  219. /package/{src → dist}/decorators/user_auth.decorator.js +0 -0
  220. /package/{src → dist}/decorators/validator.decorators.d.ts +0 -0
  221. /package/{src → dist}/decorators/validator.decorators.js +0 -0
  222. /package/{src → dist}/exceptions/file-not-image.exception.d.ts +0 -0
  223. /package/{src → dist}/exceptions/file-not-image.exception.js +0 -0
  224. /package/{src → dist}/exceptions/index.d.ts +0 -0
  225. /package/{src → dist}/exceptions/index.js +0 -0
  226. /package/{src → dist}/exceptions/page-type.exception.d.ts +0 -0
  227. /package/{src → dist}/exceptions/page-type.exception.js +0 -0
  228. /package/{src → dist}/exceptions/user-not-found.exception.d.ts +0 -0
  229. /package/{src → dist}/exceptions/user-not-found.exception.js +0 -0
  230. /package/{src → dist}/filters/bad-request.filter.d.ts +0 -0
  231. /package/{src → dist}/filters/constraint-errors.d.ts +0 -0
  232. /package/{src → dist}/filters/index.d.ts +0 -0
  233. /package/{src → dist}/filters/index.js +0 -0
  234. /package/{src → dist}/filters/query-failed.filter.d.ts +0 -0
  235. /package/{src → dist}/health-checker/health-checker.controller.d.ts +0 -0
  236. /package/{src → dist}/health-checker/health-checker.module.d.ts +0 -0
  237. /package/{src → dist}/health-checker/health-indicators/service.indicator.d.ts +0 -0
  238. /package/{src → dist}/helpers/index.d.ts +0 -0
  239. /package/{src → dist}/helpers/index.js +0 -0
  240. /package/{src → dist}/index.d.ts +0 -0
  241. /package/{src → dist}/interceptors/auth-user.interceptor.d.ts +0 -0
  242. /package/{src → dist}/interceptors/index.d.ts +0 -0
  243. /package/{src → dist}/interceptors/index.js +0 -0
  244. /package/{src → dist}/interceptors/language-interceptor.service.d.ts +0 -0
  245. /package/{src → dist}/interceptors/translation-interceptor.service.d.ts +0 -0
  246. /package/{src → dist}/interfaces/IApiFile.d.ts +0 -0
  247. /package/{src → dist}/interfaces/IApiFile.js +0 -0
  248. /package/{src → dist}/interfaces/IFile.d.ts +0 -0
  249. /package/{src → dist}/interfaces/IFile.js +0 -0
  250. /package/{src → dist}/interfaces/ITranslationDecoratorInterface.d.ts +0 -0
  251. /package/{src → dist}/interfaces/ITranslationDecoratorInterface.js +0 -0
  252. /package/{src → dist}/interfaces/index.d.ts +0 -0
  253. /package/{src → dist}/interfaces/index.js +0 -0
  254. /package/{src → dist}/interfaces/response.d.ts +0 -0
  255. /package/{src → dist}/interfaces/response.js +0 -0
  256. /package/{src → dist}/middlewares/index.d.ts +0 -0
  257. /package/{src → dist}/middlewares/index.js +0 -0
  258. /package/{src → dist}/middlewares/omni-auth.middleware.d.ts +0 -0
  259. /package/{src → dist}/middlewares/omni-auth.middleware.js +0 -0
  260. /package/{src → dist}/middlewares/powerby.middleware.d.ts +0 -0
  261. /package/{src → dist}/middlewares/powerby.middleware.js +0 -0
  262. /package/{src → dist}/middlewares/request-id.middleware.d.ts +0 -0
  263. /package/{src → dist}/middlewares/request-id.middleware.js +0 -0
  264. /package/{src → dist}/providers/context.provider.d.ts +0 -0
  265. /package/{src → dist}/providers/index.d.ts +0 -0
  266. /package/{src → dist}/providers/index.js +0 -0
  267. /package/{src → dist}/setup/bootstrap.setup.d.ts +0 -0
  268. /package/{src → dist}/setup/index.d.ts +0 -0
  269. /package/{src → dist}/setup/index.js +0 -0
  270. /package/{src → dist}/setup-swagger.d.ts +0 -0
  271. /package/{src → dist}/setup-swagger.js +0 -0
  272. /package/{src → dist}/shared/index.d.ts +0 -0
  273. /package/{src → dist}/shared/index.js +0 -0
  274. /package/{src → dist}/shared/serviceRegistryModule.d.ts +0 -0
  275. /package/{src → dist}/shared/services/aws-s3.service.d.ts +0 -0
  276. /package/{src → dist}/shared/services/generator.service.d.ts +0 -0
  277. /package/{src → dist}/shared/services/index.d.ts +0 -0
  278. /package/{src → dist}/shared/services/index.js +0 -0
  279. /package/{src → dist}/shared/services/translation.service.d.ts +0 -0
  280. /package/{src → dist}/shared/services/validator.service.d.ts +0 -0
  281. /package/{src → dist}/snake-naming.strategy.d.ts +0 -0
  282. /package/{src → dist}/snake-naming.strategy.js +0 -0
  283. /package/{src → dist}/types.d.ts +0 -0
  284. /package/{src → dist}/types.js +0 -0
  285. /package/{src → dist}/validators/file-mimetype.validator.d.ts +0 -0
  286. /package/{src → dist}/validators/file-mimetype.validator.js +0 -0
  287. /package/{src → dist}/validators/index.d.ts +0 -0
  288. /package/{src → dist}/validators/index.js +0 -0
  289. /package/{src → dist}/validators/is-exists.validator.d.ts +0 -0
  290. /package/{src → dist}/validators/is-unique.validator.d.ts +0 -0
  291. /package/{src → dist}/validators/phone-country-code.validator.d.ts +0 -0
  292. /package/{src → dist}/validators/phone-country-code.validator.js +0 -0
  293. /package/{src → dist}/validators/same-as.validator.d.ts +0 -0
  294. /package/{src → dist}/validators/same-as.validator.js +0 -0
@@ -1,10 +0,0 @@
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
- }
@@ -1,12 +0,0 @@
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';
@@ -1,46 +0,0 @@
1
- import { createParamDecorator, ExecutionContext } from '@nestjs/common';
2
- import * as lodash from 'lodash';
3
- import { ConfigService } from '@nestjs/config';
4
-
5
- export interface IOmniAuth {
6
- uid: number;
7
- username: string;
8
- tenantId: string;
9
- appId: string;
10
- }
11
-
12
- export const OmniAuth = createParamDecorator(
13
- (field: string, ctx: ExecutionContext): IOmniAuth => {
14
- return getOmniAuthData(ctx.switchToHttp().getRequest(), field);
15
- },
16
- );
17
-
18
- export function getOmniAuthData(req, data?: string): IOmniAuth {
19
- const headers = req.headers;
20
- let user: IOmniAuth;
21
- const configService = new ConfigService(req);
22
- // 未通过网关透传用户信息且处于local开发环境,则从配置获取用户信息
23
- if (
24
- lodash.isEmpty(headers['x-userid']) ||
25
- lodash.isEmpty(headers['x-username'])
26
- ) {
27
- //todo 需要删除
28
- if (process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'uat') {
29
- user = {
30
- uid: configService.get('MOCK_UID'),
31
- username: configService.get('MOCK_USERNAME'),
32
- appId: configService.get('MOCK_APP_ID'),
33
- tenantId: configService.get('MOCK_TENANT_ID'),
34
- };
35
- }
36
- } else {
37
- user = {
38
- uid: headers['x-userid'],
39
- username: headers['x-username'],
40
- appId: headers['x-appid'],
41
- tenantId: headers['x-tenantid'],
42
- };
43
- }
44
-
45
- return data ? user[data] : user;
46
- }
@@ -1,4 +0,0 @@
1
- import { SetMetadata } from '@nestjs/common';
2
-
3
- export const OperationLog = (operation: string) =>
4
- SetMetadata('operation-log', operation);
@@ -1,62 +0,0 @@
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
- }
@@ -1,8 +0,0 @@
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);
@@ -1,117 +0,0 @@
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
- }
@@ -1,29 +0,0 @@
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
- }
@@ -1,35 +0,0 @@
1
- /**
2
- * @description trim spaces from start and end, replace multiple spaces with one.
3
- * @example
4
- * @ApiProperty()
5
- * @IsString()
6
- * @Trim()
7
- * name: string;
8
- * @returns PropertyDecorator
9
- * @constructor
10
- */
11
- export declare function Trim(): PropertyDecorator;
12
- export declare function ToBoolean(): PropertyDecorator;
13
- /**
14
- * @description convert string or number to integer
15
- * @example
16
- * @NumberField()
17
- * @ToInt()
18
- * name: number;
19
- * @returns PropertyDecorator
20
- * @constructor
21
- */
22
- export declare function ToInt(): PropertyDecorator;
23
- /**
24
- * @description transforms to array, specially for query params
25
- * @example
26
- * @NumberField()
27
- * @ToArray()
28
- * name: number;
29
- * @constructor
30
- */
31
- export declare function ToArray(): PropertyDecorator;
32
- export declare function ToLowerCase(): PropertyDecorator;
33
- export declare function ToUpperCase(): PropertyDecorator;
34
- export declare function S3UrlParser(): PropertyDecorator;
35
- export declare function PhoneNumberSerializer(): PropertyDecorator;
@@ -1,147 +0,0 @@
1
- import { Transform, TransformationType } from 'class-transformer';
2
- import { castArray, isArray, isNil, map, trim } from 'lodash';
3
-
4
- import { GeneratorProvider } from '../providers';
5
- import { parsePhoneNumber } from 'libphonenumber-js';
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
- return map(value, (v) => trim(v).replace(/\s\s+/g, ' '));
23
- }
24
-
25
- return trim(value).replace(/\s\s+/g, ' ');
26
- });
27
- }
28
-
29
- export function ToBoolean(): PropertyDecorator {
30
- return Transform(
31
- (params) => {
32
- switch (params.value) {
33
- case 'true':
34
- return true;
35
- case 'false':
36
- return false;
37
- default:
38
- return params.value;
39
- }
40
- },
41
- { toClassOnly: true },
42
- );
43
- }
44
-
45
- /**
46
- * @description convert string or number to integer
47
- * @example
48
- * @NumberField()
49
- * @ToInt()
50
- * name: number;
51
- * @returns PropertyDecorator
52
- * @constructor
53
- */
54
- export function ToInt(): PropertyDecorator {
55
- return Transform(
56
- (params) => {
57
- const value = params.value as string;
58
-
59
- return Number.parseInt(value, 10);
60
- },
61
- { toClassOnly: true },
62
- );
63
- }
64
-
65
- /**
66
- * @description transforms to array, specially for query params
67
- * @example
68
- * @NumberField()
69
- * @ToArray()
70
- * name: number;
71
- * @constructor
72
- */
73
- export function ToArray(): PropertyDecorator {
74
- return Transform(
75
- (params) => {
76
- const value = params.value;
77
-
78
- if (isNil(value)) {
79
- return [];
80
- }
81
-
82
- return castArray(value);
83
- },
84
- { toClassOnly: true },
85
- );
86
- }
87
-
88
- export function ToLowerCase(): PropertyDecorator {
89
- return Transform(
90
- (params) => {
91
- const value = params.value;
92
-
93
- if (!value) {
94
- return;
95
- }
96
-
97
- if (!Array.isArray(value)) {
98
- return value.toLowerCase();
99
- }
100
-
101
- return value.map((v) => v.toLowerCase());
102
- },
103
- {
104
- toClassOnly: true,
105
- },
106
- );
107
- }
108
-
109
- export function ToUpperCase(): PropertyDecorator {
110
- return Transform(
111
- (params) => {
112
- const value = params.value;
113
-
114
- if (!value) {
115
- return;
116
- }
117
-
118
- if (!Array.isArray(value)) {
119
- return value.toUpperCase();
120
- }
121
-
122
- return value.map((v) => v.toUpperCase());
123
- },
124
- {
125
- toClassOnly: true,
126
- },
127
- );
128
- }
129
-
130
- export function S3UrlParser(): PropertyDecorator {
131
- return Transform((params) => {
132
- const key = params.value as string;
133
-
134
- switch (params.type) {
135
- case TransformationType.CLASS_TO_PLAIN:
136
- return GeneratorProvider.getS3PublicUrl(key);
137
- case TransformationType.PLAIN_TO_CLASS:
138
- return GeneratorProvider.getS3Key(key);
139
- default:
140
- return key;
141
- }
142
- });
143
- }
144
-
145
- export function PhoneNumberSerializer(): PropertyDecorator {
146
- return Transform((params) => parsePhoneNumber(params.value as string).number);
147
- }
@@ -1,19 +0,0 @@
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
- }
@@ -1,11 +0,0 @@
1
- import type { AbstractEntity } from '../common/abstract.entity';
2
- import type { AbstractDto } from '../common/dto/abstract.dto';
3
- import type { Constructor } from '../types';
4
-
5
- export function UseDto(
6
- dtoClass: Constructor<AbstractDto, [AbstractEntity, unknown]>,
7
- ): ClassDecorator {
8
- return (ctor) => {
9
- ctor.prototype.dtoClass = dtoClass;
10
- };
11
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getUserData = exports.User = void 0;
27
- const common_1 = require("@nestjs/common");
28
- const lodash = __importStar(require("lodash"));
29
- exports.User = (0, common_1.createParamDecorator)((data, ctx) => {
30
- return getUserData(ctx.switchToHttp().getRequest(), data);
31
- });
32
- function getUserData(req, data) {
33
- const headers = req.headers;
34
- if (lodash.isEmpty(headers['x-userid']) ||
35
- lodash.isEmpty(headers['x-username'])) {
36
- return null;
37
- }
38
- const user = {
39
- uid: headers['x-userid'],
40
- username: headers['x-username'],
41
- };
42
- return data ? user[data] : user;
43
- }
44
- exports.getUserData = getUserData;
@@ -1,30 +0,0 @@
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-userid']) ||
19
- lodash.isEmpty(headers['x-username'])
20
- ) {
21
- return null;
22
- }
23
-
24
- const user = {
25
- uid: headers['x-userid'],
26
- username: headers['x-username'],
27
- };
28
-
29
- return data ? user[data] : user;
30
- }
@@ -1,48 +0,0 @@
1
- import { createParamDecorator, ExecutionContext } from '@nestjs/common';
2
- import * as lodash from 'lodash';
3
- import { ConfigService } from '@nestjs/config';
4
-
5
- export interface IUser {
6
- uid: number;
7
- username: string;
8
- tenantId?: string;
9
- appId?: string;
10
- }
11
-
12
- export const User = createParamDecorator(
13
- (data: string, ctx: ExecutionContext): IUser => {
14
- return getUserData(ctx.switchToHttp().getRequest(), data);
15
- },
16
- );
17
-
18
- export function getUserData(req, data?: string): IUser {
19
- const headers = req.headers;
20
- let user: IUser = {
21
- uid: 0,
22
- username: '',
23
- };
24
- const configService = new ConfigService(req);
25
- // 未通过网关透传用户信息且处于local开发环境,则从配置获取用户信息
26
- if (
27
- lodash.isEmpty(headers['x-userid']) ||
28
- lodash.isEmpty(headers['x-username'])
29
- ) {
30
- if (process.env.NODE_ENV === 'dev') {
31
- user = {
32
- uid: configService.get('MOCK_UID'),
33
- username: configService.get('MOCK_USERNAME'),
34
- appId: configService.get('MOCK_APP_ID'),
35
- tenantId: configService.get('MOCK_TENANT_ID'),
36
- };
37
- }
38
- } else {
39
- user = {
40
- uid: headers['x-userid'],
41
- username: headers['x-username'],
42
- appId: headers['x-appid'],
43
- tenantId: headers['x-tenantid'],
44
- };
45
-
46
- return data ? user[data] : user;
47
- }
48
- }
@@ -1,15 +0,0 @@
1
- import { applyDecorators } from '@nestjs/common';
2
- import { CrudAuth } from '@dataui/crud';
3
- import { getUserData } from './user.decorator';
4
-
5
- export function UserFilter(field: string) {
6
- const obj = {};
7
- return applyDecorators(
8
- CrudAuth({
9
- filter: (req) => {
10
- obj[field] = getUserData(req, 'uid');
11
- return obj;
12
- },
13
- }),
14
- );
15
- }