@nest-omni/core 1.0.3 → 1.0.5

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 (265) hide show
  1. package/package.json +1 -4
  2. package/src/boilerplate.polyfill.d.ts +39 -0
  3. package/src/boilerplate.polyfill.js +78 -0
  4. package/src/boilerplate.polyfill.ts +202 -0
  5. package/src/common/abstract-client.service.d.ts +20 -0
  6. package/src/common/abstract-client.service.js +39 -0
  7. package/src/common/abstract-client.service.ts +56 -0
  8. package/src/common/abstract.entity.d.ts +24 -0
  9. package/src/common/abstract.entity.js +152 -0
  10. package/src/common/abstract.entity.ts +73 -0
  11. package/src/common/dto/abstract.dto.d.ts +13 -0
  12. package/src/common/dto/abstract.dto.js +96 -0
  13. package/src/common/dto/abstract.dto.ts +64 -0
  14. package/src/common/dto/bulk-id.dto.d.ts +3 -0
  15. package/src/common/dto/bulk-id.dto.js +63 -0
  16. package/src/common/dto/bulk-id.dto.ts +13 -0
  17. package/src/common/dto/create-translation.dto.d.ts +5 -0
  18. package/src/common/dto/create-translation.dto.js +63 -0
  19. package/src/common/dto/create-translation.dto.ts +10 -0
  20. package/src/common/dto/page-meta.dto.d.ts +15 -0
  21. package/src/common/dto/page-meta.dto.js +88 -0
  22. package/src/common/dto/page-meta.dto.ts +37 -0
  23. package/src/common/dto/page-options.dto.d.ts +8 -0
  24. package/src/common/dto/page-options.dto.js +87 -0
  25. package/src/common/dto/page-options.dto.ts +35 -0
  26. package/src/common/dto/page.dto.d.ts +11 -0
  27. package/src/common/dto/page.dto.js +94 -0
  28. package/src/common/dto/page.dto.ts +36 -0
  29. package/src/common/utils.d.ts +14 -0
  30. package/src/common/utils.js +39 -0
  31. package/src/common/utils.ts +45 -0
  32. package/src/constants/index.d.ts +4 -0
  33. package/src/constants/index.js +20 -0
  34. package/src/constants/index.ts +4 -0
  35. package/src/constants/language-code.d.ts +5 -0
  36. package/src/constants/language-code.js +10 -0
  37. package/src/constants/language-code.ts +7 -0
  38. package/src/constants/order.d.ts +4 -0
  39. package/src/constants/order.js +8 -0
  40. package/src/constants/order.ts +4 -0
  41. package/src/constants/role-type.d.ts +4 -0
  42. package/src/constants/role-type.js +8 -0
  43. package/src/constants/role-type.ts +4 -0
  44. package/src/constants/token-type.d.ts +4 -0
  45. package/src/constants/token-type.js +8 -0
  46. package/src/constants/token-type.ts +4 -0
  47. package/src/decorators/api-page-ok-response.decorator.d.ts +5 -0
  48. package/src/decorators/api-page-ok-response.decorator.js +25 -0
  49. package/src/decorators/api-page-ok-response.decorator.ts +31 -0
  50. package/src/decorators/auth-user.decorator.d.ts +1 -0
  51. package/src/decorators/auth-user.decorator.js +15 -0
  52. package/src/decorators/auth-user.decorator.ts +16 -0
  53. package/src/decorators/controller.decorator.d.ts +1 -0
  54. package/src/decorators/controller.decorator.js +34 -0
  55. package/src/decorators/controller.decorator.ts +8 -0
  56. package/src/decorators/field.decorators.d.ts +71 -0
  57. package/src/decorators/field.decorators.js +455 -0
  58. package/src/decorators/field.decorators.ts +773 -0
  59. package/src/decorators/http.decorators.d.ts +3 -0
  60. package/src/decorators/http.decorators.js +8 -0
  61. package/src/decorators/http.decorators.ts +10 -0
  62. package/src/decorators/index.d.ts +12 -0
  63. package/src/decorators/index.js +28 -0
  64. package/src/decorators/index.ts +12 -0
  65. package/src/decorators/omni-auth.decorator.d.ts +8 -0
  66. package/src/decorators/omni-auth.decorator.js +60 -0
  67. package/src/decorators/omni-auth.decorator.ts +46 -0
  68. package/src/decorators/operation.decorator.d.ts +1 -0
  69. package/src/decorators/operation.decorator.js +6 -0
  70. package/src/decorators/operation.decorator.ts +4 -0
  71. package/src/decorators/property.decorators.d.ts +15 -0
  72. package/src/decorators/property.decorators.js +36 -0
  73. package/src/decorators/property.decorators.ts +62 -0
  74. package/src/decorators/public-route.decorator.d.ts +3 -0
  75. package/src/decorators/public-route.decorator.js +8 -0
  76. package/src/decorators/public-route.decorator.ts +8 -0
  77. package/src/decorators/swagger.schema.d.ts +5 -0
  78. package/src/decorators/swagger.schema.js +82 -0
  79. package/src/decorators/swagger.schema.ts +117 -0
  80. package/src/decorators/timestamp-column.decorator.d.ts +1 -0
  81. package/src/decorators/timestamp-column.decorator.js +28 -0
  82. package/src/decorators/timestamp-column.decorator.ts +29 -0
  83. package/src/decorators/transform.decorators.d.ts +35 -0
  84. package/src/decorators/transform.decorators.js +122 -0
  85. package/src/decorators/transform.decorators.ts +147 -0
  86. package/src/decorators/translate.decorator.d.ts +5 -0
  87. package/src/decorators/translate.decorator.js +18 -0
  88. package/src/decorators/translate.decorator.ts +19 -0
  89. package/src/decorators/use-dto.decorator.d.ts +4 -0
  90. package/src/decorators/use-dto.decorator.js +9 -0
  91. package/src/decorators/use-dto.decorator.ts +11 -0
  92. package/src/decorators/user-check.decorator.d.ts +6 -0
  93. package/src/decorators/user-check.decorator.js +44 -0
  94. package/src/decorators/user-check.decorator.ts +30 -0
  95. package/src/decorators/user.decorator.d.ts +8 -0
  96. package/src/decorators/user.decorator.js +62 -0
  97. package/src/decorators/user.decorator.ts +48 -0
  98. package/src/decorators/user_auth.decorator.d.ts +1 -0
  99. package/src/decorators/user_auth.decorator.js +16 -0
  100. package/src/decorators/user_auth.decorator.ts +15 -0
  101. package/src/decorators/validator.decorators.d.ts +10 -0
  102. package/src/decorators/validator.decorators.js +59 -0
  103. package/src/decorators/validator.decorators.ts +78 -0
  104. package/src/exceptions/file-not-image.exception.d.ts +4 -0
  105. package/src/exceptions/file-not-image.exception.js +10 -0
  106. package/src/exceptions/file-not-image.exception.ts +7 -0
  107. package/src/exceptions/index.d.ts +2 -0
  108. package/src/exceptions/index.js +18 -0
  109. package/src/exceptions/index.ts +2 -0
  110. package/src/exceptions/page-type.exception.d.ts +4 -0
  111. package/src/exceptions/page-type.exception.js +10 -0
  112. package/src/exceptions/page-type.exception.ts +7 -0
  113. package/src/exceptions/user-not-found.exception.d.ts +4 -0
  114. package/src/exceptions/user-not-found.exception.js +10 -0
  115. package/src/exceptions/user-not-found.exception.ts +7 -0
  116. package/src/filters/bad-request.filter.d.ts +5 -0
  117. package/src/filters/bad-request.filter.js +104 -0
  118. package/src/filters/bad-request.filter.ts +67 -0
  119. package/src/filters/constraint-errors.d.ts +1 -0
  120. package/src/filters/constraint-errors.js +7 -0
  121. package/src/filters/constraint-errors.ts +5 -0
  122. package/src/filters/index.d.ts +3 -0
  123. package/src/filters/index.js +19 -0
  124. package/src/filters/index.ts +3 -0
  125. package/src/filters/query-failed.filter.d.ts +10 -0
  126. package/src/filters/query-failed.filter.js +81 -0
  127. package/src/filters/query-failed.filter.ts +32 -0
  128. package/src/health-checker/health-checker.controller.d.ts +15 -0
  129. package/src/health-checker/health-checker.controller.js +104 -0
  130. package/src/health-checker/health-checker.controller.ts +51 -0
  131. package/src/health-checker/health-checker.module.d.ts +2 -0
  132. package/src/health-checker/health-checker.module.js +69 -0
  133. package/src/health-checker/health-checker.module.ts +13 -0
  134. package/src/health-checker/health-indicators/service.indicator.d.ts +8 -0
  135. package/src/health-checker/health-indicators/service.indicator.js +102 -0
  136. package/src/health-checker/health-indicators/service.indicator.ts +44 -0
  137. package/src/helpers/common.helper.d.ts +16 -0
  138. package/src/helpers/common.helper.js +49 -0
  139. package/src/helpers/common.helper.ts +49 -0
  140. package/src/helpers/date.helper.d.ts +10 -0
  141. package/src/helpers/date.helper.js +81 -0
  142. package/src/helpers/date.helper.ts +64 -0
  143. package/src/helpers/excel.helper.d.ts +27 -0
  144. package/src/helpers/excel.helper.js +338 -0
  145. package/src/helpers/index.d.ts +3 -0
  146. package/src/helpers/index.js +19 -0
  147. package/src/helpers/index.ts +3 -0
  148. package/src/i18n/en_US/validation.json +38 -0
  149. package/src/i18n/zh_CN/validation.json +38 -0
  150. package/src/index.d.ts +11 -0
  151. package/src/index.js +28 -0
  152. package/src/index.ts +12 -0
  153. package/src/interceptors/auth-user.interceptor.d.ts +4 -0
  154. package/src/interceptors/auth-user.interceptor.js +68 -0
  155. package/src/interceptors/auth-user.interceptor.ts +20 -0
  156. package/src/interceptors/index.d.ts +2 -0
  157. package/src/interceptors/index.js +18 -0
  158. package/src/interceptors/index.ts +2 -0
  159. package/src/interceptors/language-interceptor.service.d.ts +6 -0
  160. package/src/interceptors/language-interceptor.service.js +74 -0
  161. package/src/interceptors/language-interceptor.service.ts +31 -0
  162. package/src/interceptors/translation-interceptor.service.d.ts +5 -0
  163. package/src/interceptors/translation-interceptor.service.js +83 -0
  164. package/src/interceptors/translation-interceptor.service.ts +43 -0
  165. package/src/interfaces/IApiFile.d.ts +4 -0
  166. package/src/interfaces/IApiFile.js +2 -0
  167. package/src/interfaces/IApiFile.ts +4 -0
  168. package/src/interfaces/IFile.d.ts +9 -0
  169. package/src/interfaces/IFile.js +2 -0
  170. package/src/interfaces/IFile.ts +8 -0
  171. package/src/interfaces/ITranslationDecoratorInterface.d.ts +3 -0
  172. package/src/interfaces/ITranslationDecoratorInterface.js +2 -0
  173. package/src/interfaces/ITranslationDecoratorInterface.ts +3 -0
  174. package/src/interfaces/index.d.ts +3 -0
  175. package/src/interfaces/index.js +19 -0
  176. package/src/interfaces/index.ts +3 -0
  177. package/src/interfaces/response.d.ts +25 -0
  178. package/src/interfaces/response.js +2 -0
  179. package/src/interfaces/response.ts +37 -0
  180. package/src/middlewares/index.d.ts +3 -0
  181. package/src/middlewares/index.js +19 -0
  182. package/src/middlewares/index.ts +3 -0
  183. package/src/middlewares/omni-auth.middleware.d.ts +1 -0
  184. package/src/middlewares/omni-auth.middleware.js +13 -0
  185. package/src/middlewares/omni-auth.middleware.ts +10 -0
  186. package/src/middlewares/powerby.middleware.d.ts +1 -0
  187. package/src/middlewares/powerby.middleware.js +10 -0
  188. package/src/middlewares/powerby.middleware.ts +6 -0
  189. package/src/middlewares/request-id.middleware.d.ts +7 -0
  190. package/src/middlewares/request-id.middleware.js +22 -0
  191. package/src/middlewares/request-id.middleware.ts +28 -0
  192. package/src/providers/context.provider.d.ts +32 -0
  193. package/src/providers/context.provider.js +73 -0
  194. package/src/providers/context.provider.ts +98 -0
  195. package/src/providers/generator.provider.d.ts +13 -0
  196. package/src/providers/generator.provider.js +54 -0
  197. package/src/providers/generator.provider.ts +66 -0
  198. package/src/providers/index.d.ts +2 -0
  199. package/src/providers/index.js +18 -0
  200. package/src/providers/index.ts +2 -0
  201. package/src/setup/bootstrap.setup.d.ts +5 -0
  202. package/src/setup/bootstrap.setup.js +138 -0
  203. package/src/setup/bootstrap.setup.ts +139 -0
  204. package/src/setup/index.d.ts +1 -0
  205. package/src/setup/index.js +17 -0
  206. package/src/setup/index.ts +1 -0
  207. package/src/setup/microservices.setup.js +55 -0
  208. package/src/setup-swagger.d.ts +2 -0
  209. package/src/setup-swagger.js +62 -0
  210. package/src/setup-swagger.ts +67 -0
  211. package/src/shared/index.d.ts +2 -0
  212. package/src/shared/index.js +18 -0
  213. package/src/shared/index.ts +2 -0
  214. package/src/shared/serviceRegistryModule.d.ts +2 -0
  215. package/src/shared/serviceRegistryModule.js +176 -0
  216. package/src/shared/serviceRegistryModule.ts +110 -0
  217. package/src/shared/services/api-config.service.d.ts +73 -0
  218. package/src/shared/services/api-config.service.js +335 -0
  219. package/src/shared/services/api-config.service.ts +319 -0
  220. package/src/shared/services/aws-s3.service.d.ts +10 -0
  221. package/src/shared/services/aws-s3.service.js +96 -0
  222. package/src/shared/services/aws-s3.service.ts +39 -0
  223. package/src/shared/services/generator.service.d.ts +4 -0
  224. package/src/shared/services/generator.service.js +67 -0
  225. package/src/shared/services/generator.service.ts +13 -0
  226. package/src/shared/services/index.d.ts +5 -0
  227. package/src/shared/services/index.js +21 -0
  228. package/src/shared/services/index.ts +5 -0
  229. package/src/shared/services/translation.service.d.ts +9 -0
  230. package/src/shared/services/translation.service.js +109 -0
  231. package/src/shared/services/translation.service.ts +59 -0
  232. package/src/shared/services/validator.service.d.ts +3 -0
  233. package/src/shared/services/validator.service.js +64 -0
  234. package/src/shared/services/validator.service.ts +10 -0
  235. package/src/snake-naming.strategy.d.ts +11 -0
  236. package/src/snake-naming.strategy.js +37 -0
  237. package/src/snake-naming.strategy.ts +64 -0
  238. package/src/types.d.ts +9 -0
  239. package/src/types.js +2 -0
  240. package/src/types.ts +44 -0
  241. package/src/validators/file-mimetype.validator.d.ts +13 -0
  242. package/src/validators/file-mimetype.validator.js +21 -0
  243. package/src/validators/file-mimetype.validator.ts +34 -0
  244. package/src/validators/index.d.ts +3 -0
  245. package/src/validators/index.js +19 -0
  246. package/src/validators/index.ts +3 -0
  247. package/src/validators/is-exists.validator.d.ts +18 -0
  248. package/src/validators/is-exists.validator.js +99 -0
  249. package/src/validators/is-exists.validator.ts +60 -0
  250. package/src/validators/is-unique.validator.d.ts +17 -0
  251. package/src/validators/is-unique.validator.js +131 -0
  252. package/src/validators/is-unique.validator.ts +93 -0
  253. package/src/validators/phone-country-code.validator.d.ts +2 -0
  254. package/src/validators/phone-country-code.validator.js +30 -0
  255. package/src/validators/phone-country-code.validator.ts +36 -0
  256. package/src/validators/same-as.validator.d.ts +2 -0
  257. package/src/validators/same-as.validator.js +25 -0
  258. package/src/validators/same-as.validator.ts +27 -0
  259. package/src/validators/skip-empty.validator.d.ts +6 -0
  260. package/src/validators/skip-empty.validator.js +23 -0
  261. package/src/validators/skip-empty.validator.ts +25 -0
  262. package/tsconfig.json +26 -0
  263. package/tsconfig.lib.json +16 -0
  264. package/tsconfig.tsbuildinfo +1 -0
  265. /package/{README → README.md} +0 -0
@@ -0,0 +1,3 @@
1
+ import type { PipeTransform } from '@nestjs/common';
2
+ import type { Type } from '@nestjs/common/interfaces';
3
+ export declare function UUIDParam(property: string, ...pipes: Array<Type<PipeTransform> | PipeTransform>): ParameterDecorator;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UUIDParam = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ function UUIDParam(property, ...pipes) {
6
+ return (0, common_1.Param)(property, new common_1.ParseUUIDPipe({ version: '4' }), ...pipes);
7
+ }
8
+ exports.UUIDParam = UUIDParam;
@@ -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,28 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api-page-ok-response.decorator"), exports);
18
+ __exportStar(require("./auth-user.decorator"), exports);
19
+ __exportStar(require("./field.decorators"), exports);
20
+ __exportStar(require("./http.decorators"), exports);
21
+ __exportStar(require("./property.decorators"), exports);
22
+ __exportStar(require("./public-route.decorator"), exports);
23
+ __exportStar(require("./swagger.schema"), exports);
24
+ __exportStar(require("./transform.decorators"), exports);
25
+ __exportStar(require("./translate.decorator"), exports);
26
+ __exportStar(require("./use-dto.decorator"), exports);
27
+ __exportStar(require("./validator.decorators"), exports);
28
+ __exportStar(require("./controller.decorator"), exports);
@@ -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,8 @@
1
+ export interface IOmniAuth {
2
+ uid: number;
3
+ username: string;
4
+ tenantId: string;
5
+ appId: string;
6
+ }
7
+ export declare const OmniAuth: (...dataOrPipes: (string | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
8
+ export declare function getOmniAuthData(req: any, data?: string): IOmniAuth;
@@ -0,0 +1,60 @@
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.getOmniAuthData = exports.OmniAuth = void 0;
27
+ const common_1 = require("@nestjs/common");
28
+ const lodash = __importStar(require("lodash"));
29
+ const config_1 = require("@nestjs/config");
30
+ exports.OmniAuth = (0, common_1.createParamDecorator)((field, ctx) => {
31
+ return getOmniAuthData(ctx.switchToHttp().getRequest(), field);
32
+ });
33
+ function getOmniAuthData(req, data) {
34
+ const headers = req.headers;
35
+ let user;
36
+ const configService = new config_1.ConfigService(req);
37
+ // 未通过网关透传用户信息且处于local开发环境,则从配置获取用户信息
38
+ if (lodash.isEmpty(headers['x-userid']) ||
39
+ lodash.isEmpty(headers['x-username'])) {
40
+ //todo 需要删除
41
+ if (process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'uat') {
42
+ user = {
43
+ uid: configService.get('MOCK_UID'),
44
+ username: configService.get('MOCK_USERNAME'),
45
+ appId: configService.get('MOCK_APP_ID'),
46
+ tenantId: configService.get('MOCK_TENANT_ID'),
47
+ };
48
+ }
49
+ }
50
+ else {
51
+ user = {
52
+ uid: headers['x-userid'],
53
+ username: headers['x-username'],
54
+ appId: headers['x-appid'],
55
+ tenantId: headers['x-tenantid'],
56
+ };
57
+ }
58
+ return data ? user[data] : user;
59
+ }
60
+ exports.getOmniAuthData = getOmniAuthData;
@@ -0,0 +1,46 @@
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
+ }
@@ -0,0 +1 @@
1
+ export declare const OperationLog: (operation: string) => import("@nestjs/common").CustomDecorator<string>;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OperationLog = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const OperationLog = (operation) => (0, common_1.SetMetadata)('operation-log', operation);
6
+ exports.OperationLog = OperationLog;
@@ -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,15 @@
1
+ import type { ApiPropertyOptions } from '@nestjs/swagger';
2
+ export declare function ApiBooleanProperty(options?: Omit<ApiPropertyOptions, 'type'>): PropertyDecorator;
3
+ export declare function ApiBooleanPropertyOptional(options?: Omit<ApiPropertyOptions, 'type' | 'required'>): PropertyDecorator;
4
+ export declare function ApiUUIDProperty(options?: Omit<ApiPropertyOptions, 'type' | 'format'> & Partial<{
5
+ each: boolean;
6
+ }>): PropertyDecorator;
7
+ export declare function ApiUUIDPropertyOptional(options?: Omit<ApiPropertyOptions, 'type' | 'format' | 'required'> & Partial<{
8
+ each: boolean;
9
+ }>): PropertyDecorator;
10
+ export declare function ApiEnumProperty<TEnum>(getEnum: () => TEnum, options?: Omit<ApiPropertyOptions, 'type'> & {
11
+ each?: boolean;
12
+ }): PropertyDecorator;
13
+ export declare function ApiEnumPropertyOptional<TEnum>(getEnum: () => TEnum, options?: Omit<ApiPropertyOptions, 'type' | 'required'> & {
14
+ each?: boolean;
15
+ }): PropertyDecorator;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiEnumPropertyOptional = exports.ApiEnumProperty = exports.ApiUUIDPropertyOptional = exports.ApiUUIDProperty = exports.ApiBooleanPropertyOptional = exports.ApiBooleanProperty = void 0;
4
+ const swagger_1 = require("@nestjs/swagger");
5
+ const utils_1 = require("../common/utils");
6
+ const field_decorators_1 = require("../decorators/field.decorators");
7
+ function ApiBooleanProperty(options = {}) {
8
+ return (0, swagger_1.ApiProperty)(Object.assign({ type: Boolean }, options));
9
+ }
10
+ exports.ApiBooleanProperty = ApiBooleanProperty;
11
+ function ApiBooleanPropertyOptional(options = {}) {
12
+ return ApiBooleanProperty(Object.assign({ required: false }, options));
13
+ }
14
+ exports.ApiBooleanPropertyOptional = ApiBooleanPropertyOptional;
15
+ function ApiUUIDProperty(options = {}) {
16
+ return (0, swagger_1.ApiProperty)(Object.assign({ type: options.each ? [String] : String, format: 'uuid', isArray: options.each }, options));
17
+ }
18
+ exports.ApiUUIDProperty = ApiUUIDProperty;
19
+ function ApiUUIDPropertyOptional(options = {}) {
20
+ return ApiUUIDProperty(Object.assign({ required: false }, options));
21
+ }
22
+ exports.ApiUUIDPropertyOptional = ApiUUIDPropertyOptional;
23
+ function ApiEnumProperty(getEnum, options = {}) {
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ const enumValue = getEnum();
26
+ options.description = (0, field_decorators_1.getEnumDescription)(enumValue);
27
+ return (0, swagger_1.ApiProperty)(Object.assign({ type: 'enum',
28
+ // throw error during the compilation of swagger
29
+ // isArray: options.each,
30
+ enum: enumValue, enumName: (0, utils_1.getVariableName)(getEnum) }, options));
31
+ }
32
+ exports.ApiEnumProperty = ApiEnumProperty;
33
+ function ApiEnumPropertyOptional(getEnum, options = {}) {
34
+ return ApiEnumProperty(getEnum, Object.assign({ required: false }, options));
35
+ }
36
+ exports.ApiEnumPropertyOptional = ApiEnumPropertyOptional;
@@ -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,3 @@
1
+ import type { CustomDecorator } from '@nestjs/common';
2
+ export declare const PUBLIC_ROUTE_KEY = "public_route";
3
+ export declare const PublicRoute: (isPublic?: boolean) => CustomDecorator;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PublicRoute = exports.PUBLIC_ROUTE_KEY = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.PUBLIC_ROUTE_KEY = 'public_route';
6
+ // eslint-disable-next-line @typescript-eslint/naming-convention
7
+ const PublicRoute = (isPublic = false) => (0, common_1.SetMetadata)(exports.PUBLIC_ROUTE_KEY, isPublic);
8
+ exports.PublicRoute = PublicRoute;
@@ -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,5 @@
1
+ import _ from 'lodash';
2
+ import type { IApiFile } from '../interfaces';
3
+ export declare function ApiFile(files: _.Many<IApiFile>, options?: Partial<{
4
+ isRequired: boolean;
5
+ }>): MethodDecorator;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ApiFile = void 0;
7
+ const common_1 = require("@nestjs/common");
8
+ const constants_1 = require("@nestjs/common/constants");
9
+ const route_paramtypes_enum_1 = require("@nestjs/common/enums/route-paramtypes.enum");
10
+ const platform_express_1 = require("@nestjs/platform-express");
11
+ const swagger_1 = require("@nestjs/swagger");
12
+ const reverse_object_keys_util_1 = require("@nestjs/swagger/dist/utils/reverse-object-keys.util");
13
+ const lodash_1 = __importDefault(require("lodash"));
14
+ function explore(instance, propertyKey) {
15
+ const types = Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, instance, propertyKey);
16
+ const routeArgsMetadata = Reflect.getMetadata(constants_1.ROUTE_ARGS_METADATA, instance.constructor, propertyKey) || {};
17
+ const parametersWithType = lodash_1.default.mapValues((0, reverse_object_keys_util_1.reverseObjectKeys)(routeArgsMetadata), (param) => ({
18
+ type: types[param.index],
19
+ name: param.data,
20
+ required: true,
21
+ }));
22
+ for (const [key, value] of Object.entries(parametersWithType)) {
23
+ const keyPair = key.split(':');
24
+ if (Number(keyPair[0]) === route_paramtypes_enum_1.RouteParamtypes.BODY) {
25
+ return value.type;
26
+ }
27
+ }
28
+ }
29
+ function RegisterModels() {
30
+ return (target, propertyKey, descriptor) => {
31
+ const body = explore(target, propertyKey);
32
+ return body && (0, swagger_1.ApiExtraModels)(body)(target, propertyKey, descriptor);
33
+ };
34
+ }
35
+ function ApiFileDecorator(files = [], options = {}) {
36
+ return (target, propertyKey, descriptor) => {
37
+ const { isRequired = false } = options;
38
+ const fileSchema = {
39
+ type: 'string',
40
+ format: 'binary',
41
+ };
42
+ const properties = {};
43
+ for (const file of files) {
44
+ if (file.isArray) {
45
+ properties[file.name] = {
46
+ type: 'array',
47
+ items: fileSchema,
48
+ };
49
+ }
50
+ else {
51
+ properties[file.name] = fileSchema;
52
+ }
53
+ }
54
+ let schema = {
55
+ properties,
56
+ type: 'object',
57
+ };
58
+ const body = explore(target, propertyKey);
59
+ if (body) {
60
+ schema = {
61
+ allOf: [
62
+ {
63
+ $ref: (0, swagger_1.getSchemaPath)(body),
64
+ },
65
+ { properties, type: 'object' },
66
+ ],
67
+ };
68
+ }
69
+ return (0, swagger_1.ApiBody)({
70
+ schema,
71
+ required: isRequired,
72
+ })(target, propertyKey, descriptor);
73
+ };
74
+ }
75
+ function ApiFile(files, options = {}) {
76
+ const filesArray = lodash_1.default.castArray(files);
77
+ const apiFileInterceptors = filesArray.map((file) => file.isArray
78
+ ? (0, common_1.UseInterceptors)((0, platform_express_1.FilesInterceptor)(file.name))
79
+ : (0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)(file.name)));
80
+ return (0, common_1.applyDecorators)(RegisterModels(), (0, swagger_1.ApiConsumes)('multipart/form-data'), ApiFileDecorator(filesArray, options), ...apiFileInterceptors);
81
+ }
82
+ exports.ApiFile = ApiFile;
@@ -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 @@
1
+ export declare function TimestampColumn(name: string, description?: string): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimestampColumn = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const swagger_1 = require("@nestjs/swagger");
6
+ const typeorm_1 = require("typeorm");
7
+ const helpers_1 = require("./helpers");
8
+ function TimestampColumn(name, description) {
9
+ return (0, common_1.applyDecorators)((0, swagger_1.ApiProperty)({
10
+ required: false,
11
+ type: 'string',
12
+ format: 'date-time',
13
+ example: '2018-10-01 12:18:48',
14
+ description,
15
+ }), (0, typeorm_1.Column)({
16
+ type: 'int',
17
+ name,
18
+ nullable: false,
19
+ unsigned: true,
20
+ default: 0,
21
+ comment: description,
22
+ transformer: {
23
+ to: (value) => value === 0 || /\d{10}/.test(value) ? value : (0, helpers_1.strToTimeStamp)(value),
24
+ from: (value) => (0, helpers_1.formatDateTime)(value),
25
+ },
26
+ }));
27
+ }
28
+ exports.TimestampColumn = TimestampColumn;
@@ -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,35 @@
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;