@impactor/nest 3.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +89 -6
  2. package/index.d.ts +41 -40
  3. package/package.json +31 -33
  4. package/src/configs/app.d.ts +7 -4
  5. package/src/configs/app.js +11 -18
  6. package/src/configs/app.js.map +1 -1
  7. package/src/configs/database.js +1 -11
  8. package/src/configs/database.js.map +1 -1
  9. package/src/configs/microservice.js +6 -16
  10. package/src/configs/microservice.js.map +1 -1
  11. package/src/configs/multi-queue-rabbitmq-server.js +28 -34
  12. package/src/configs/multi-queue-rabbitmq-server.js.map +1 -1
  13. package/src/configs/redis-config.js +1 -11
  14. package/src/configs/redis-config.js.map +1 -1
  15. package/src/create-app.d.ts +1 -1
  16. package/src/create-app.js +47 -55
  17. package/src/create-app.js.map +1 -1
  18. package/src/create-microservice.d.ts +1 -1
  19. package/src/create-microservice.js +18 -22
  20. package/src/create-microservice.js.map +1 -1
  21. package/src/create-testing-microservice.d.ts +1 -1
  22. package/src/create-testing-microservice.js +16 -20
  23. package/src/create-testing-microservice.js.map +1 -1
  24. package/src/decorators/controller/add-decorators/add-controller-path.d.ts +1 -1
  25. package/src/decorators/controller/add-decorators/add-controller-path.js +7 -15
  26. package/src/decorators/controller/add-decorators/add-controller-path.js.map +1 -1
  27. package/src/decorators/controller/add-decorators/add-controller-tags.d.ts +1 -1
  28. package/src/decorators/controller/add-decorators/add-controller-tags.js +9 -17
  29. package/src/decorators/controller/add-decorators/add-controller-tags.js.map +1 -1
  30. package/src/decorators/controller/add-decorators/add-http-method.d.ts +2 -2
  31. package/src/decorators/controller/add-decorators/add-http-method.js +13 -20
  32. package/src/decorators/controller/add-decorators/add-http-method.js.map +1 -1
  33. package/src/decorators/controller/add-decorators/add-swagger-body.d.ts +2 -2
  34. package/src/decorators/controller/add-decorators/add-swagger-body.js +7 -17
  35. package/src/decorators/controller/add-decorators/add-swagger-body.js.map +1 -1
  36. package/src/decorators/controller/add-decorators/add-swagger-operation.d.ts +2 -2
  37. package/src/decorators/controller/add-decorators/add-swagger-operation.js +8 -15
  38. package/src/decorators/controller/add-decorators/add-swagger-operation.js.map +1 -1
  39. package/src/decorators/controller/add-decorators/add-swagger-params.d.ts +2 -2
  40. package/src/decorators/controller/add-decorators/add-swagger-params.js +9 -16
  41. package/src/decorators/controller/add-decorators/add-swagger-params.js.map +1 -1
  42. package/src/decorators/controller/add-decorators/add-swagger-response.d.ts +2 -2
  43. package/src/decorators/controller/add-decorators/add-swagger-response.js +10 -20
  44. package/src/decorators/controller/add-decorators/add-swagger-response.js.map +1 -1
  45. package/src/decorators/controller/controller.decorator.d.ts +1 -1
  46. package/src/decorators/controller/controller.decorator.js +12 -13
  47. package/src/decorators/controller/controller.decorator.js.map +1 -1
  48. package/src/decorators/controller/controller.factory.d.ts +1 -1
  49. package/src/decorators/controller/controller.factory.js +59 -67
  50. package/src/decorators/controller/controller.factory.js.map +1 -1
  51. package/src/decorators/controller/default-options.d.ts +1 -1
  52. package/src/decorators/controller/default-options.js +11 -26
  53. package/src/decorators/controller/default-options.js.map +1 -1
  54. package/src/decorators/controller/dto/empty.dto.js +2 -12
  55. package/src/decorators/controller/dto/empty.dto.js.map +1 -1
  56. package/src/decorators/controller/dto/update-response.dto.js +2 -12
  57. package/src/decorators/controller/dto/update-response.dto.js.map +1 -1
  58. package/src/decorators/controller/interceptors/query.interceptor.d.ts +1 -1
  59. package/src/decorators/controller/interceptors/query.interceptor.js +10 -19
  60. package/src/decorators/controller/interceptors/query.interceptor.js.map +1 -1
  61. package/src/decorators/controller/route-handler.d.ts +2 -2
  62. package/src/decorators/controller/route-handler.js +8 -16
  63. package/src/decorators/controller/route-handler.js.map +1 -1
  64. package/src/decorators/controller/route.decorator.d.ts +1 -1
  65. package/src/decorators/controller/route.decorator.js +11 -11
  66. package/src/decorators/controller/route.decorator.js.map +1 -1
  67. package/src/decorators/controller/services/crud-typeorm.service.d.ts +1 -2
  68. package/src/decorators/controller/services/crud-typeorm.service.js +19 -24
  69. package/src/decorators/controller/services/crud-typeorm.service.js.map +1 -1
  70. package/src/decorators/controller/types/index.d.ts +2 -2
  71. package/src/decorators/controller/types/index.js +1 -4
  72. package/src/decorators/controller/types/index.js.map +1 -1
  73. package/src/decorators/controller/utils/merge-options.d.ts +1 -1
  74. package/src/decorators/controller/utils/merge-options.js +3 -13
  75. package/src/decorators/controller/utils/merge-options.js.map +1 -1
  76. package/src/decorators/controller/utils/reflect.d.ts +2 -2
  77. package/src/decorators/controller/utils/reflect.js +24 -38
  78. package/src/decorators/controller/utils/reflect.js.map +1 -1
  79. package/src/decorators/entity.decorator.d.ts +6 -0
  80. package/src/decorators/entity.decorator.js +73 -0
  81. package/src/decorators/entity.decorator.js.map +1 -0
  82. package/src/decorators/prop.decorator.js +79 -38
  83. package/src/decorators/prop.decorator.js.map +1 -1
  84. package/src/exceptions/rpc-bad-request.exception.d.ts +1 -1
  85. package/src/exceptions/rpc-bad-request.exception.js +5 -15
  86. package/src/exceptions/rpc-bad-request.exception.js.map +1 -1
  87. package/src/exceptions/rpc-base.exception.js +10 -15
  88. package/src/exceptions/rpc-base.exception.js.map +1 -1
  89. package/src/exceptions/rpc-conflict.exception.d.ts +1 -1
  90. package/src/exceptions/rpc-conflict.exception.js +5 -15
  91. package/src/exceptions/rpc-conflict.exception.js.map +1 -1
  92. package/src/exceptions/rpc-internal-server-error.exception.d.ts +1 -1
  93. package/src/exceptions/rpc-internal-server-error.exception.js +5 -15
  94. package/src/exceptions/rpc-internal-server-error.exception.js.map +1 -1
  95. package/src/exceptions/rpc-method-not-allowed.exception.d.ts +1 -1
  96. package/src/exceptions/rpc-method-not-allowed.exception.js +5 -15
  97. package/src/exceptions/rpc-method-not-allowed.exception.js.map +1 -1
  98. package/src/exceptions/rpc-not-found.exception.d.ts +1 -1
  99. package/src/exceptions/rpc-not-found.exception.js +5 -15
  100. package/src/exceptions/rpc-not-found.exception.js.map +1 -1
  101. package/src/exceptions/rpc-not-implemented.exception.d.ts +1 -1
  102. package/src/exceptions/rpc-not-implemented.exception.js +5 -15
  103. package/src/exceptions/rpc-not-implemented.exception.js.map +1 -1
  104. package/src/exceptions/rpc-unauthorized.exception.d.ts +1 -1
  105. package/src/exceptions/rpc-unauthorized.exception.js +5 -15
  106. package/src/exceptions/rpc-unauthorized.exception.js.map +1 -1
  107. package/src/filters/error-to-rpc-exception.filter.js +12 -22
  108. package/src/filters/error-to-rpc-exception.filter.js.map +1 -1
  109. package/src/filters/error-to-ws-exception.filter.js +10 -20
  110. package/src/filters/error-to-ws-exception.filter.js.map +1 -1
  111. package/src/filters/typeorm-exception.filter.js +9 -19
  112. package/src/filters/typeorm-exception.filter.js.map +1 -1
  113. package/src/filters/ws-exception.filter.js +6 -16
  114. package/src/filters/ws-exception.filter.js.map +1 -1
  115. package/src/generate-metadata.d.ts +3 -3
  116. package/src/generate-metadata.js +18 -74
  117. package/src/generate-metadata.js.map +1 -1
  118. package/src/guards/auth.guard.js +43 -44
  119. package/src/guards/auth.guard.js.map +1 -1
  120. package/src/modules/basic/basic.controller.js +6 -16
  121. package/src/modules/basic/basic.controller.js.map +1 -1
  122. package/src/modules/basic/basic.module.js +15 -23
  123. package/src/modules/basic/basic.module.js.map +1 -1
  124. package/src/modules/basic/basic.service.js +4 -14
  125. package/src/modules/basic/basic.service.js.map +1 -1
  126. package/src/register-entities.d.ts +1 -0
  127. package/src/register-entities.js +135 -0
  128. package/src/register-entities.js.map +1 -0
  129. package/src/utils/logger.js +2 -12
  130. package/src/utils/logger.js.map +1 -1
  131. package/src/utils/typeorm-to-swagger.d.ts +3 -0
  132. package/src/utils/typeorm-to-swagger.js +308 -0
  133. package/src/utils/typeorm-to-swagger.js.map +1 -0
  134. package/nx.json +0 -190
  135. package/src/nest-swagger-metadata.js +0 -553
  136. package/src/nest-swagger-metadata.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/exceptions/rpc-method-not-allowed.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception';\n\nexport class RpcMethodNotAllowedException extends RpcBaseException {\n constructor(message = 'Method not allowed') {\n super(message, HttpStatus.METHOD_NOT_ALLOWED);\n }\n}\n"],"names":["RpcMethodNotAllowedException","RpcBaseException","message","HttpStatus","METHOD_NOT_ALLOWED"],"mappings":";;;;+BAGaA;;;eAAAA;;;wBAHc;kCACM;AAE1B,IAAA,AAAMA,+BAAN,MAAMA,qCAAqCC,kCAAgB;IAChE,YAAYC,UAAU,oBAAoB,CAAE;QAC1C,KAAK,CAACA,SAASC,kBAAU,CAACC,kBAAkB;IAC9C;AACF"}
1
+ {"version":3,"sources":["../../../src/exceptions/rpc-method-not-allowed.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception.js';\n\nexport class RpcMethodNotAllowedException extends RpcBaseException {\n constructor(message = 'Method not allowed') {\n super(message, HttpStatus.METHOD_NOT_ALLOWED);\n }\n}\n"],"names":["HttpStatus","RpcBaseException","RpcMethodNotAllowedException","message","METHOD_NOT_ALLOWED"],"mappings":"AAAA,SAASA,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,gBAAgB,QAAQ,0BAA0B;AAE3D,OAAO,MAAMC,qCAAqCD;IAChD,YAAYE,UAAU,oBAAoB,CAAE;QAC1C,KAAK,CAACA,SAASH,WAAWI,kBAAkB;IAC9C;AACF"}
@@ -1,4 +1,4 @@
1
- import { RpcBaseException } from './rpc-base.exception';
1
+ import { RpcBaseException } from './rpc-base.exception.js';
2
2
  export declare class RpcNotFoundException extends RpcBaseException {
3
3
  constructor(message?: string);
4
4
  }
@@ -1,19 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "RpcNotFoundException", {
6
- enumerable: true,
7
- get: function() {
8
- return RpcNotFoundException;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _rpcbaseexception = require("./rpc-base.exception");
13
- let RpcNotFoundException = class RpcNotFoundException extends _rpcbaseexception.RpcBaseException {
1
+ import { HttpStatus } from "@nestjs/common";
2
+ import { RpcBaseException } from "./rpc-base.exception.js";
3
+ export class RpcNotFoundException extends RpcBaseException {
14
4
  constructor(message = 'Not Found'){
15
- super(message, _common.HttpStatus.NOT_FOUND);
5
+ super(message, HttpStatus.NOT_FOUND);
16
6
  }
17
- };
7
+ }
18
8
 
19
9
  //# sourceMappingURL=rpc-not-found.exception.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/exceptions/rpc-not-found.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception';\n\nexport class RpcNotFoundException extends RpcBaseException {\n constructor(message = 'Not Found') {\n super(message, HttpStatus.NOT_FOUND);\n }\n}\n"],"names":["RpcNotFoundException","RpcBaseException","message","HttpStatus","NOT_FOUND"],"mappings":";;;;+BAGaA;;;eAAAA;;;wBAHc;kCACM;AAE1B,IAAA,AAAMA,uBAAN,MAAMA,6BAA6BC,kCAAgB;IACxD,YAAYC,UAAU,WAAW,CAAE;QACjC,KAAK,CAACA,SAASC,kBAAU,CAACC,SAAS;IACrC;AACF"}
1
+ {"version":3,"sources":["../../../src/exceptions/rpc-not-found.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception.js';\n\nexport class RpcNotFoundException extends RpcBaseException {\n constructor(message = 'Not Found') {\n super(message, HttpStatus.NOT_FOUND);\n }\n}\n"],"names":["HttpStatus","RpcBaseException","RpcNotFoundException","message","NOT_FOUND"],"mappings":"AAAA,SAASA,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,gBAAgB,QAAQ,0BAA0B;AAE3D,OAAO,MAAMC,6BAA6BD;IACxC,YAAYE,UAAU,WAAW,CAAE;QACjC,KAAK,CAACA,SAASH,WAAWI,SAAS;IACrC;AACF"}
@@ -1,4 +1,4 @@
1
- import { RpcBaseException } from './rpc-base.exception';
1
+ import { RpcBaseException } from './rpc-base.exception.js';
2
2
  export declare class RpcNotImplementedException extends RpcBaseException {
3
3
  constructor(message?: string);
4
4
  }
@@ -1,19 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "RpcNotImplementedException", {
6
- enumerable: true,
7
- get: function() {
8
- return RpcNotImplementedException;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _rpcbaseexception = require("./rpc-base.exception");
13
- let RpcNotImplementedException = class RpcNotImplementedException extends _rpcbaseexception.RpcBaseException {
1
+ import { HttpStatus } from "@nestjs/common";
2
+ import { RpcBaseException } from "./rpc-base.exception.js";
3
+ export class RpcNotImplementedException extends RpcBaseException {
14
4
  constructor(message = 'Not implemented'){
15
- super(message, _common.HttpStatus.NOT_IMPLEMENTED);
5
+ super(message, HttpStatus.NOT_IMPLEMENTED);
16
6
  }
17
- };
7
+ }
18
8
 
19
9
  //# sourceMappingURL=rpc-not-implemented.exception.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/exceptions/rpc-not-implemented.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception';\n\nexport class RpcNotImplementedException extends RpcBaseException {\n constructor(message = 'Not implemented') {\n super(message, HttpStatus.NOT_IMPLEMENTED);\n }\n}\n"],"names":["RpcNotImplementedException","RpcBaseException","message","HttpStatus","NOT_IMPLEMENTED"],"mappings":";;;;+BAGaA;;;eAAAA;;;wBAHc;kCACM;AAE1B,IAAA,AAAMA,6BAAN,MAAMA,mCAAmCC,kCAAgB;IAC9D,YAAYC,UAAU,iBAAiB,CAAE;QACvC,KAAK,CAACA,SAASC,kBAAU,CAACC,eAAe;IAC3C;AACF"}
1
+ {"version":3,"sources":["../../../src/exceptions/rpc-not-implemented.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception.js';\n\nexport class RpcNotImplementedException extends RpcBaseException {\n constructor(message = 'Not implemented') {\n super(message, HttpStatus.NOT_IMPLEMENTED);\n }\n}\n"],"names":["HttpStatus","RpcBaseException","RpcNotImplementedException","message","NOT_IMPLEMENTED"],"mappings":"AAAA,SAASA,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,gBAAgB,QAAQ,0BAA0B;AAE3D,OAAO,MAAMC,mCAAmCD;IAC9C,YAAYE,UAAU,iBAAiB,CAAE;QACvC,KAAK,CAACA,SAASH,WAAWI,eAAe;IAC3C;AACF"}
@@ -1,4 +1,4 @@
1
- import { RpcBaseException } from './rpc-base.exception';
1
+ import { RpcBaseException } from './rpc-base.exception.js';
2
2
  export declare class RpcUnauthorizedException extends RpcBaseException {
3
3
  constructor(message?: string);
4
4
  }
@@ -1,19 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "RpcUnauthorizedException", {
6
- enumerable: true,
7
- get: function() {
8
- return RpcUnauthorizedException;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _rpcbaseexception = require("./rpc-base.exception");
13
- let RpcUnauthorizedException = class RpcUnauthorizedException extends _rpcbaseexception.RpcBaseException {
1
+ import { HttpStatus } from "@nestjs/common";
2
+ import { RpcBaseException } from "./rpc-base.exception.js";
3
+ export class RpcUnauthorizedException extends RpcBaseException {
14
4
  constructor(message = 'Invalid credentials'){
15
- super(message, _common.HttpStatus.UNAUTHORIZED);
5
+ super(message, HttpStatus.UNAUTHORIZED);
16
6
  }
17
- };
7
+ }
18
8
 
19
9
  //# sourceMappingURL=rpc-unauthorized.exception.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/exceptions/rpc-unauthorized.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception';\n\nexport class RpcUnauthorizedException extends RpcBaseException {\n constructor(message = 'Invalid credentials') {\n super(message, HttpStatus.UNAUTHORIZED);\n }\n}\n"],"names":["RpcUnauthorizedException","RpcBaseException","message","HttpStatus","UNAUTHORIZED"],"mappings":";;;;+BAGaA;;;eAAAA;;;wBAHc;kCACM;AAE1B,IAAA,AAAMA,2BAAN,MAAMA,iCAAiCC,kCAAgB;IAC5D,YAAYC,UAAU,qBAAqB,CAAE;QAC3C,KAAK,CAACA,SAASC,kBAAU,CAACC,YAAY;IACxC;AACF"}
1
+ {"version":3,"sources":["../../../src/exceptions/rpc-unauthorized.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception.js';\n\nexport class RpcUnauthorizedException extends RpcBaseException {\n constructor(message = 'Invalid credentials') {\n super(message, HttpStatus.UNAUTHORIZED);\n }\n}\n"],"names":["HttpStatus","RpcBaseException","RpcUnauthorizedException","message","UNAUTHORIZED"],"mappings":"AAAA,SAASA,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,gBAAgB,QAAQ,0BAA0B;AAE3D,OAAO,MAAMC,iCAAiCD;IAC5C,YAAYE,UAAU,qBAAqB,CAAE;QAC3C,KAAK,CAACA,SAASH,WAAWI,YAAY;IACxC;AACF"}
@@ -1,48 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "ErrorToRpcExceptionFilter", {
6
- enumerable: true,
7
- get: function() {
8
- return ErrorToRpcExceptionFilter;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _microservices = require("@nestjs/microservices");
13
- const _rxjs = require("rxjs");
14
1
  function _ts_decorate(decorators, target, key, desc) {
15
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
4
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
19
6
  }
20
- let ErrorToRpcExceptionFilter = class ErrorToRpcExceptionFilter {
7
+ import { Catch, HttpException, Logger } from "@nestjs/common";
8
+ import { RpcException } from "@nestjs/microservices";
9
+ import { throwError } from "rxjs";
10
+ export class ErrorToRpcExceptionFilter {
21
11
  catch(exception) {
22
12
  if (process.env.NODE_ENV === 'development') {
23
- let logger = new _common.Logger('ErrorToRpc');
13
+ let logger = new Logger('ErrorToRpc');
24
14
  logger.debug(exception);
25
15
  }
26
16
  // HttpException is converted by NestJs into a response object with a statusCode
27
17
  // The response object contains the error message and the statusCode,
28
18
  // and the exception itself contains the exception name such as NoFoundError
29
- if (exception instanceof _common.HttpException) {
19
+ if (exception instanceof HttpException) {
30
20
  let res = exception.getResponse(), error = typeof res === 'string' ? {
31
21
  message: res
32
22
  } : res;
33
- return (0, _rxjs.throwError)(()=>({
23
+ return throwError(()=>({
34
24
  ...exception,
35
25
  ...error
36
26
  }));
37
27
  }
38
- if (exception instanceof _microservices.RpcException) {
39
- return (0, _rxjs.throwError)(()=>exception);
28
+ if (exception instanceof RpcException) {
29
+ return throwError(()=>exception);
40
30
  }
41
- return (0, _rxjs.throwError)(()=>new _microservices.RpcException(exception));
31
+ return throwError(()=>new RpcException(exception));
42
32
  }
43
- };
33
+ }
44
34
  ErrorToRpcExceptionFilter = _ts_decorate([
45
- (0, _common.Catch)()
35
+ Catch()
46
36
  ], ErrorToRpcExceptionFilter);
47
37
 
48
38
  //# sourceMappingURL=error-to-rpc-exception.filter.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/filters/error-to-rpc-exception.filter.ts"],"sourcesContent":["import {\n Catch,\n HttpException,\n Logger,\n type RpcExceptionFilter,\n} from '@nestjs/common';\nimport { RpcException } from '@nestjs/microservices';\nimport { throwError } from 'rxjs';\n\n/**\n * convert Error to RpcException\n */\n@Catch()\nexport class ErrorToRpcExceptionFilter implements RpcExceptionFilter<Error> {\n catch(exception: Error) {\n if (process.env.NODE_ENV === 'development') {\n let logger = new Logger('ErrorToRpc');\n logger.debug(exception);\n }\n\n // HttpException is converted by NestJs into a response object with a statusCode\n // The response object contains the error message and the statusCode,\n // and the exception itself contains the exception name such as NoFoundError\n if (exception instanceof HttpException) {\n let res = exception.getResponse(),\n error = typeof res === 'string' ? { message: res } : res;\n return throwError(() => ({ ...exception, ...error }));\n }\n\n if (exception instanceof RpcException) {\n return throwError(() => exception);\n }\n\n return throwError(() => new RpcException(exception));\n }\n}\n"],"names":["ErrorToRpcExceptionFilter","catch","exception","process","env","NODE_ENV","logger","Logger","debug","HttpException","res","getResponse","error","message","throwError","RpcException"],"mappings":";;;;+BAaaA;;;eAAAA;;;wBARN;+BACsB;sBACF;;;;;;;AAMpB,IAAA,AAAMA,4BAAN,MAAMA;IACXC,MAAMC,SAAgB,EAAE;QACtB,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;YAC1C,IAAIC,SAAS,IAAIC,cAAM,CAAC;YACxBD,OAAOE,KAAK,CAACN;QACf;QAEA,gFAAgF;QAChF,qEAAqE;QACrE,4EAA4E;QAC5E,IAAIA,qBAAqBO,qBAAa,EAAE;YACtC,IAAIC,MAAMR,UAAUS,WAAW,IAC7BC,QAAQ,OAAOF,QAAQ,WAAW;gBAAEG,SAASH;YAAI,IAAIA;YACvD,OAAOI,IAAAA,gBAAU,EAAC,IAAO,CAAA;oBAAE,GAAGZ,SAAS;oBAAE,GAAGU,KAAK;gBAAC,CAAA;QACpD;QAEA,IAAIV,qBAAqBa,2BAAY,EAAE;YACrC,OAAOD,IAAAA,gBAAU,EAAC,IAAMZ;QAC1B;QAEA,OAAOY,IAAAA,gBAAU,EAAC,IAAM,IAAIC,2BAAY,CAACb;IAC3C;AACF"}
1
+ {"version":3,"sources":["../../../src/filters/error-to-rpc-exception.filter.ts"],"sourcesContent":["import {\n Catch,\n HttpException,\n Logger,\n type RpcExceptionFilter,\n} from '@nestjs/common';\nimport { RpcException } from '@nestjs/microservices';\nimport { throwError } from 'rxjs';\n\n/**\n * convert Error to RpcException\n */\n@Catch()\nexport class ErrorToRpcExceptionFilter implements RpcExceptionFilter<Error> {\n catch(exception: Error) {\n if (process.env.NODE_ENV === 'development') {\n let logger = new Logger('ErrorToRpc');\n logger.debug(exception);\n }\n\n // HttpException is converted by NestJs into a response object with a statusCode\n // The response object contains the error message and the statusCode,\n // and the exception itself contains the exception name such as NoFoundError\n if (exception instanceof HttpException) {\n let res = exception.getResponse(),\n error = typeof res === 'string' ? { message: res } : res;\n return throwError(() => ({ ...exception, ...error }));\n }\n\n if (exception instanceof RpcException) {\n return throwError(() => exception);\n }\n\n return throwError(() => new RpcException(exception));\n }\n}\n"],"names":["Catch","HttpException","Logger","RpcException","throwError","ErrorToRpcExceptionFilter","catch","exception","process","env","NODE_ENV","logger","debug","res","getResponse","error","message"],"mappings":";;;;;;AAAA,SACEA,KAAK,EACLC,aAAa,EACbC,MAAM,QAED,iBAAiB;AACxB,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SAASC,UAAU,QAAQ,OAAO;AAMlC,OAAO,MAAMC;IACXC,MAAMC,SAAgB,EAAE;QACtB,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;YAC1C,IAAIC,SAAS,IAAIT,OAAO;YACxBS,OAAOC,KAAK,CAACL;QACf;QAEA,gFAAgF;QAChF,qEAAqE;QACrE,4EAA4E;QAC5E,IAAIA,qBAAqBN,eAAe;YACtC,IAAIY,MAAMN,UAAUO,WAAW,IAC7BC,QAAQ,OAAOF,QAAQ,WAAW;gBAAEG,SAASH;YAAI,IAAIA;YACvD,OAAOT,WAAW,IAAO,CAAA;oBAAE,GAAGG,SAAS;oBAAE,GAAGQ,KAAK;gBAAC,CAAA;QACpD;QAEA,IAAIR,qBAAqBJ,cAAc;YACrC,OAAOC,WAAW,IAAMG;QAC1B;QAEA,OAAOH,WAAW,IAAM,IAAID,aAAaI;IAC3C;AACF"}
@@ -1,23 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "ErrorToWsExceptionFilter", {
6
- enumerable: true,
7
- get: function() {
8
- return ErrorToWsExceptionFilter;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _rxjs = require("rxjs");
13
- const _websockets = require("@nestjs/websockets");
14
1
  function _ts_decorate(decorators, target, key, desc) {
15
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
4
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
19
6
  }
20
- let ErrorToWsExceptionFilter = class ErrorToWsExceptionFilter {
7
+ import { Catch, Logger } from "@nestjs/common";
8
+ import { throwError } from "rxjs";
9
+ import { WsException } from "@nestjs/websockets";
10
+ export class ErrorToWsExceptionFilter {
21
11
  catch(exception, host) {
22
12
  let ctx = host.switchToWs(), client = ctx.getClient(), pattern = ctx.getPattern(), data = ctx.getData();
23
13
  client.emit('exception', {
@@ -26,7 +16,7 @@ let ErrorToWsExceptionFilter = class ErrorToWsExceptionFilter {
26
16
  data
27
17
  });
28
18
  if (process.env.NODE_ENV === 'development') {
29
- let logger = new _common.Logger(`WebSocket @${pattern}`);
19
+ let logger = new Logger(`WebSocket @${pattern}`);
30
20
  logger.debug(`WS Error in ${pattern}`, exception, {
31
21
  data
32
22
  });
@@ -34,14 +24,14 @@ let ErrorToWsExceptionFilter = class ErrorToWsExceptionFilter {
34
24
  // todo: this doesn't trigger the next filter, similar to RpcExceptionFilter does,
35
25
  // so we need to handle WsException here, i.e. emit 'exception' event here
36
26
  // instead of relying on the custom WebSocketExceptionFilter
37
- if (exception instanceof _websockets.WsException) {
38
- return (0, _rxjs.throwError)(()=>exception);
27
+ if (exception instanceof WsException) {
28
+ return throwError(()=>exception);
39
29
  }
40
- return (0, _rxjs.throwError)(()=>new _websockets.WsException(exception));
30
+ return throwError(()=>new WsException(exception));
41
31
  }
42
- };
32
+ }
43
33
  ErrorToWsExceptionFilter = _ts_decorate([
44
- (0, _common.Catch)()
34
+ Catch()
45
35
  ], ErrorToWsExceptionFilter);
46
36
 
47
37
  //# sourceMappingURL=error-to-ws-exception.filter.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/filters/error-to-ws-exception.filter.ts"],"sourcesContent":["import {\n ArgumentsHost,\n Catch,\n Logger,\n type WsExceptionFilter,\n} from '@nestjs/common';\nimport { throwError } from 'rxjs';\nimport { WsException } from '@nestjs/websockets';\n\n/**\n * convert Error to WsException\n */\n@Catch()\nexport class ErrorToWsExceptionFilter implements WsExceptionFilter<Error> {\n catch(exception: Error, host: ArgumentsHost) {\n let ctx = host.switchToWs(),\n client = ctx.getClient(),\n pattern = ctx.getPattern(),\n data = ctx.getData();\n\n client.emit('exception', {\n pattern,\n message: exception.message,\n data,\n });\n\n if (process.env.NODE_ENV === 'development') {\n let logger = new Logger(`WebSocket @${pattern}`);\n logger.debug(`WS Error in ${pattern}`, exception, {\n data,\n });\n }\n\n // todo: this doesn't trigger the next filter, similar to RpcExceptionFilter does,\n // so we need to handle WsException here, i.e. emit 'exception' event here\n // instead of relying on the custom WebSocketExceptionFilter\n if (exception instanceof WsException) {\n return throwError(() => exception);\n }\n\n return throwError(() => new WsException(exception));\n }\n}\n"],"names":["ErrorToWsExceptionFilter","catch","exception","host","ctx","switchToWs","client","getClient","pattern","getPattern","data","getData","emit","message","process","env","NODE_ENV","logger","Logger","debug","WsException","throwError"],"mappings":";;;;+BAaaA;;;eAAAA;;;wBARN;sBACoB;4BACC;;;;;;;AAMrB,IAAA,AAAMA,2BAAN,MAAMA;IACXC,MAAMC,SAAgB,EAAEC,IAAmB,EAAE;QAC3C,IAAIC,MAAMD,KAAKE,UAAU,IACvBC,SAASF,IAAIG,SAAS,IACtBC,UAAUJ,IAAIK,UAAU,IACxBC,OAAON,IAAIO,OAAO;QAEpBL,OAAOM,IAAI,CAAC,aAAa;YACvBJ;YACAK,SAASX,UAAUW,OAAO;YAC1BH;QACF;QAEA,IAAII,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;YAC1C,IAAIC,SAAS,IAAIC,cAAM,CAAC,CAAC,WAAW,EAAEV,SAAS;YAC/CS,OAAOE,KAAK,CAAC,CAAC,YAAY,EAAEX,SAAS,EAAEN,WAAW;gBAChDQ;YACF;QACF;QAEA,kFAAkF;QAClF,0EAA0E;QAC1E,4DAA4D;QAC5D,IAAIR,qBAAqBkB,uBAAW,EAAE;YACpC,OAAOC,IAAAA,gBAAU,EAAC,IAAMnB;QAC1B;QAEA,OAAOmB,IAAAA,gBAAU,EAAC,IAAM,IAAID,uBAAW,CAAClB;IAC1C;AACF"}
1
+ {"version":3,"sources":["../../../src/filters/error-to-ws-exception.filter.ts"],"sourcesContent":["import {\n ArgumentsHost,\n Catch,\n Logger,\n type WsExceptionFilter,\n} from '@nestjs/common';\nimport { throwError } from 'rxjs';\nimport { WsException } from '@nestjs/websockets';\n\n/**\n * convert Error to WsException\n */\n@Catch()\nexport class ErrorToWsExceptionFilter implements WsExceptionFilter<Error> {\n catch(exception: Error, host: ArgumentsHost) {\n let ctx = host.switchToWs(),\n client = ctx.getClient(),\n pattern = ctx.getPattern(),\n data = ctx.getData();\n\n client.emit('exception', {\n pattern,\n message: exception.message,\n data,\n });\n\n if (process.env.NODE_ENV === 'development') {\n let logger = new Logger(`WebSocket @${pattern}`);\n logger.debug(`WS Error in ${pattern}`, exception, {\n data,\n });\n }\n\n // todo: this doesn't trigger the next filter, similar to RpcExceptionFilter does,\n // so we need to handle WsException here, i.e. emit 'exception' event here\n // instead of relying on the custom WebSocketExceptionFilter\n if (exception instanceof WsException) {\n return throwError(() => exception);\n }\n\n return throwError(() => new WsException(exception));\n }\n}\n"],"names":["Catch","Logger","throwError","WsException","ErrorToWsExceptionFilter","catch","exception","host","ctx","switchToWs","client","getClient","pattern","getPattern","data","getData","emit","message","process","env","NODE_ENV","logger","debug"],"mappings":";;;;;;AAAA,SAEEA,KAAK,EACLC,MAAM,QAED,iBAAiB;AACxB,SAASC,UAAU,QAAQ,OAAO;AAClC,SAASC,WAAW,QAAQ,qBAAqB;AAMjD,OAAO,MAAMC;IACXC,MAAMC,SAAgB,EAAEC,IAAmB,EAAE;QAC3C,IAAIC,MAAMD,KAAKE,UAAU,IACvBC,SAASF,IAAIG,SAAS,IACtBC,UAAUJ,IAAIK,UAAU,IACxBC,OAAON,IAAIO,OAAO;QAEpBL,OAAOM,IAAI,CAAC,aAAa;YACvBJ;YACAK,SAASX,UAAUW,OAAO;YAC1BH;QACF;QAEA,IAAII,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;YAC1C,IAAIC,SAAS,IAAIpB,OAAO,CAAC,WAAW,EAAEW,SAAS;YAC/CS,OAAOC,KAAK,CAAC,CAAC,YAAY,EAAEV,SAAS,EAAEN,WAAW;gBAChDQ;YACF;QACF;QAEA,kFAAkF;QAClF,0EAA0E;QAC1E,4DAA4D;QAC5D,IAAIR,qBAAqBH,aAAa;YACpC,OAAOD,WAAW,IAAMI;QAC1B;QAEA,OAAOJ,WAAW,IAAM,IAAIC,YAAYG;IAC1C;AACF"}
@@ -1,32 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "TypeORMExceptionFilter", {
6
- enumerable: true,
7
- get: function() {
8
- return TypeORMExceptionFilter;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _typeorm = require("typeorm");
13
- const _rxjs = require("rxjs");
14
1
  function _ts_decorate(decorators, target, key, desc) {
15
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
4
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
19
6
  }
20
- let TypeORMExceptionFilter = class TypeORMExceptionFilter {
7
+ import { Catch, HttpStatus, Logger } from "@nestjs/common";
8
+ import { TypeORMError } from "typeorm";
9
+ import { throwError } from "rxjs";
10
+ export class TypeORMExceptionFilter {
21
11
  catch(exception, _host) {
22
12
  if (process.env.NODE_ENV === 'development') {
23
- let logger = new _common.Logger('TypeORM');
13
+ let logger = new Logger('TypeORM');
24
14
  logger.debug(exception);
25
15
  }
26
- return (0, _rxjs.throwError)(()=>({
16
+ return throwError(()=>({
27
17
  statusCode: // if the error is "duplicate keys", set the status code to 409 conflict
28
18
  // otherwise, set it to 400 bad request
29
- exception.code === '23505' ? _common.HttpStatus.CONFLICT : _common.HttpStatus.BAD_REQUEST,
19
+ exception.code === '23505' ? HttpStatus.CONFLICT : HttpStatus.BAD_REQUEST,
30
20
  // example:
31
21
  // message: duplicate key value violates unique constraint "UQ_8e1f623798118e629b46a9e6299"
32
22
  // detail: Key (phone)=(+12345678900) already exists.
@@ -36,9 +26,9 @@ let TypeORMExceptionFilter = class TypeORMExceptionFilter {
36
26
  code: exception.code
37
27
  }));
38
28
  }
39
- };
29
+ }
40
30
  TypeORMExceptionFilter = _ts_decorate([
41
- (0, _common.Catch)(_typeorm.TypeORMError)
31
+ Catch(TypeORMError)
42
32
  ], TypeORMExceptionFilter);
43
33
 
44
34
  //# sourceMappingURL=typeorm-exception.filter.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/filters/typeorm-exception.filter.ts"],"sourcesContent":["import {\n type ArgumentsHost,\n Catch,\n type ExceptionFilter,\n HttpStatus,\n Logger,\n} from '@nestjs/common';\nimport { QueryFailedError, TypeORMError } from 'typeorm';\nimport { Observable, throwError } from 'rxjs';\n\n// todo: rename file to typeorm-exception.filter.ts\n@Catch(TypeORMError)\nexport class TypeORMExceptionFilter implements ExceptionFilter<TypeORMError> {\n catch(exception: TypeORMError, _host: ArgumentsHost): Observable<any> {\n if (process.env.NODE_ENV === 'development') {\n let logger = new Logger('TypeORM');\n logger.debug(exception);\n }\n\n return throwError(() => ({\n statusCode:\n // if the error is \"duplicate keys\", set the status code to 409 conflict\n // otherwise, set it to 400 bad request\n (<any>exception).code === '23505'\n ? HttpStatus.CONFLICT\n : HttpStatus.BAD_REQUEST,\n // example:\n // message: duplicate key value violates unique constraint \"UQ_8e1f623798118e629b46a9e6299\"\n // detail: Key (phone)=(+12345678900) already exists.\n message: `${exception.message}${(<any>exception).detail ? `, ${(<any>exception).detail}` : ''}`,\n query: (<QueryFailedError>exception).query,\n parameters: (<QueryFailedError>exception).parameters,\n code: (<any>exception).code,\n }));\n }\n}\n"],"names":["TypeORMExceptionFilter","catch","exception","_host","process","env","NODE_ENV","logger","Logger","debug","throwError","statusCode","code","HttpStatus","CONFLICT","BAD_REQUEST","message","detail","query","parameters"],"mappings":";;;;+BAYaA;;;eAAAA;;;wBANN;yBACwC;sBACR;;;;;;;AAIhC,IAAA,AAAMA,yBAAN,MAAMA;IACXC,MAAMC,SAAuB,EAAEC,KAAoB,EAAmB;QACpE,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;YAC1C,IAAIC,SAAS,IAAIC,cAAM,CAAC;YACxBD,OAAOE,KAAK,CAACP;QACf;QAEA,OAAOQ,IAAAA,gBAAU,EAAC,IAAO,CAAA;gBACvBC,YAGE,AAFA,wEAAwE;gBACxE,uCAAuC;gBACjCT,UAAWU,IAAI,KAAK,UACtBC,kBAAU,CAACC,QAAQ,GACnBD,kBAAU,CAACE,WAAW;gBAC5B,WAAW;gBACX,2FAA2F;gBAC3F,qDAAqD;gBACrDC,SAAS,GAAGd,UAAUc,OAAO,GAAG,AAAMd,UAAWe,MAAM,GAAG,CAAC,EAAE,EAAE,AAAMf,UAAWe,MAAM,EAAE,GAAG,IAAI;gBAC/FC,OAAO,AAAmBhB,UAAWgB,KAAK;gBAC1CC,YAAY,AAAmBjB,UAAWiB,UAAU;gBACpDP,MAAM,AAAMV,UAAWU,IAAI;YAC7B,CAAA;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/filters/typeorm-exception.filter.ts"],"sourcesContent":["import {\n type ArgumentsHost,\n Catch,\n type ExceptionFilter,\n HttpStatus,\n Logger,\n} from '@nestjs/common';\nimport { QueryFailedError, TypeORMError } from 'typeorm';\nimport { Observable, throwError } from 'rxjs';\n\n// todo: rename file to typeorm-exception.filter.ts\n@Catch(TypeORMError)\nexport class TypeORMExceptionFilter implements ExceptionFilter<TypeORMError> {\n catch(exception: TypeORMError, _host: ArgumentsHost): Observable<any> {\n if (process.env.NODE_ENV === 'development') {\n let logger = new Logger('TypeORM');\n logger.debug(exception);\n }\n\n return throwError(() => ({\n statusCode:\n // if the error is \"duplicate keys\", set the status code to 409 conflict\n // otherwise, set it to 400 bad request\n (<any>exception).code === '23505'\n ? HttpStatus.CONFLICT\n : HttpStatus.BAD_REQUEST,\n // example:\n // message: duplicate key value violates unique constraint \"UQ_8e1f623798118e629b46a9e6299\"\n // detail: Key (phone)=(+12345678900) already exists.\n message: `${exception.message}${(<any>exception).detail ? `, ${(<any>exception).detail}` : ''}`,\n query: (<QueryFailedError>exception).query,\n parameters: (<QueryFailedError>exception).parameters,\n code: (<any>exception).code,\n }));\n }\n}\n"],"names":["Catch","HttpStatus","Logger","TypeORMError","throwError","TypeORMExceptionFilter","catch","exception","_host","process","env","NODE_ENV","logger","debug","statusCode","code","CONFLICT","BAD_REQUEST","message","detail","query","parameters"],"mappings":";;;;;;AAAA,SAEEA,KAAK,EAELC,UAAU,EACVC,MAAM,QACD,iBAAiB;AACxB,SAA2BC,YAAY,QAAQ,UAAU;AACzD,SAAqBC,UAAU,QAAQ,OAAO;AAI9C,OAAO,MAAMC;IACXC,MAAMC,SAAuB,EAAEC,KAAoB,EAAmB;QACpE,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;YAC1C,IAAIC,SAAS,IAAIV,OAAO;YACxBU,OAAOC,KAAK,CAACN;QACf;QAEA,OAAOH,WAAW,IAAO,CAAA;gBACvBU,YAGE,AAFA,wEAAwE;gBACxE,uCAAuC;gBACjCP,UAAWQ,IAAI,KAAK,UACtBd,WAAWe,QAAQ,GACnBf,WAAWgB,WAAW;gBAC5B,WAAW;gBACX,2FAA2F;gBAC3F,qDAAqD;gBACrDC,SAAS,GAAGX,UAAUW,OAAO,GAAG,AAAMX,UAAWY,MAAM,GAAG,CAAC,EAAE,EAAE,AAAMZ,UAAWY,MAAM,EAAE,GAAG,IAAI;gBAC/FC,OAAO,AAAmBb,UAAWa,KAAK;gBAC1CC,YAAY,AAAmBd,UAAWc,UAAU;gBACpDN,MAAM,AAAMR,UAAWQ,IAAI;YAC7B,CAAA;IACF;AACF"}
@@ -1,22 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "WebSocketExceptionFilter", {
6
- enumerable: true,
7
- get: function() {
8
- return WebSocketExceptionFilter;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _websockets = require("@nestjs/websockets");
13
1
  function _ts_decorate(decorators, target, key, desc) {
14
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
4
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
18
6
  }
19
- let WebSocketExceptionFilter = class WebSocketExceptionFilter {
7
+ import { Catch, Logger } from "@nestjs/common";
8
+ import { WsException } from "@nestjs/websockets";
9
+ export class WebSocketExceptionFilter {
20
10
  catch(exception, host) {
21
11
  let ctx = host.switchToWs(), client = ctx.getClient(), pattern = ctx.getPattern(), data = ctx.getData();
22
12
  client.emit('exception', {
@@ -25,15 +15,15 @@ let WebSocketExceptionFilter = class WebSocketExceptionFilter {
25
15
  data
26
16
  });
27
17
  if (process.env.NODE_ENV === 'development') {
28
- let logger = new _common.Logger(`WebSocket @${pattern}`);
18
+ let logger = new Logger(`WebSocket @${pattern}`);
29
19
  logger.debug(`WS Error in ${pattern}`, exception, {
30
20
  data
31
21
  });
32
22
  }
33
23
  }
34
- };
24
+ }
35
25
  WebSocketExceptionFilter = _ts_decorate([
36
- (0, _common.Catch)(_websockets.WsException)
26
+ Catch(WsException)
37
27
  ], WebSocketExceptionFilter);
38
28
 
39
29
  //# sourceMappingURL=ws-exception.filter.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/filters/ws-exception.filter.ts"],"sourcesContent":["import {\n type ArgumentsHost,\n Catch,\n Logger,\n type WsExceptionFilter,\n} from '@nestjs/common';\nimport { WsException } from '@nestjs/websockets';\n@Catch(WsException)\nexport class WebSocketExceptionFilter implements WsExceptionFilter {\n catch(exception: WsException, host: ArgumentsHost) {\n let ctx = host.switchToWs(),\n client = ctx.getClient(),\n pattern = ctx.getPattern(),\n data = ctx.getData();\n\n client.emit('exception', {\n pattern,\n message: exception.message,\n data,\n });\n\n if (process.env.NODE_ENV === 'development') {\n let logger = new Logger(`WebSocket @${pattern}`);\n logger.debug(`WS Error in ${pattern}`, exception, {\n data,\n });\n }\n }\n}\n"],"names":["WebSocketExceptionFilter","catch","exception","host","ctx","switchToWs","client","getClient","pattern","getPattern","data","getData","emit","message","process","env","NODE_ENV","logger","Logger","debug"],"mappings":";;;;+BAQaA;;;eAAAA;;;wBAHN;4BACqB;;;;;;;AAErB,IAAA,AAAMA,2BAAN,MAAMA;IACXC,MAAMC,SAAsB,EAAEC,IAAmB,EAAE;QACjD,IAAIC,MAAMD,KAAKE,UAAU,IACvBC,SAASF,IAAIG,SAAS,IACtBC,UAAUJ,IAAIK,UAAU,IACxBC,OAAON,IAAIO,OAAO;QAEpBL,OAAOM,IAAI,CAAC,aAAa;YACvBJ;YACAK,SAASX,UAAUW,OAAO;YAC1BH;QACF;QAEA,IAAII,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;YAC1C,IAAIC,SAAS,IAAIC,cAAM,CAAC,CAAC,WAAW,EAAEV,SAAS;YAC/CS,OAAOE,KAAK,CAAC,CAAC,YAAY,EAAEX,SAAS,EAAEN,WAAW;gBAChDQ;YACF;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/filters/ws-exception.filter.ts"],"sourcesContent":["import {\n type ArgumentsHost,\n Catch,\n Logger,\n type WsExceptionFilter,\n} from '@nestjs/common';\nimport { WsException } from '@nestjs/websockets';\n@Catch(WsException)\nexport class WebSocketExceptionFilter implements WsExceptionFilter {\n catch(exception: WsException, host: ArgumentsHost) {\n let ctx = host.switchToWs(),\n client = ctx.getClient(),\n pattern = ctx.getPattern(),\n data = ctx.getData();\n\n client.emit('exception', {\n pattern,\n message: exception.message,\n data,\n });\n\n if (process.env.NODE_ENV === 'development') {\n let logger = new Logger(`WebSocket @${pattern}`);\n logger.debug(`WS Error in ${pattern}`, exception, {\n data,\n });\n }\n }\n}\n"],"names":["Catch","Logger","WsException","WebSocketExceptionFilter","catch","exception","host","ctx","switchToWs","client","getClient","pattern","getPattern","data","getData","emit","message","process","env","NODE_ENV","logger","debug"],"mappings":";;;;;;AAAA,SAEEA,KAAK,EACLC,MAAM,QAED,iBAAiB;AACxB,SAASC,WAAW,QAAQ,qBAAqB;AAEjD,OAAO,MAAMC;IACXC,MAAMC,SAAsB,EAAEC,IAAmB,EAAE;QACjD,IAAIC,MAAMD,KAAKE,UAAU,IACvBC,SAASF,IAAIG,SAAS,IACtBC,UAAUJ,IAAIK,UAAU,IACxBC,OAAON,IAAIO,OAAO;QAEpBL,OAAOM,IAAI,CAAC,aAAa;YACvBJ;YACAK,SAASX,UAAUW,OAAO;YAC1BH;QACF;QAEA,IAAII,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;YAC1C,IAAIC,SAAS,IAAInB,OAAO,CAAC,WAAW,EAAEU,SAAS;YAC/CS,OAAOC,KAAK,CAAC,CAAC,YAAY,EAAEV,SAAS,EAAEN,WAAW;gBAChDQ;YACF;QACF;IACF;AACF"}
@@ -1,6 +1,6 @@
1
- import { type PluginMetadataGenerateOptions } from '@nestjs/cli/lib/compiler/plugins/plugin-metadata-generator';
2
- import { ReadonlyVisitor } from '@nestjs/swagger/dist/plugin';
3
- import type { PluginOptions } from '@nestjs/swagger/dist/plugin/merge-options';
1
+ import { type PluginMetadataGenerateOptions } from '@nestjs/cli/lib/compiler/plugins/plugin-metadata-generator.js';
2
+ import { ReadonlyVisitor } from '@nestjs/swagger/dist/plugin/visitors/readonly.visitor.js';
3
+ import type { PluginOptions } from '@nestjs/swagger/dist/plugin/merge-options.js';
4
4
  export interface SwaggerMetadataOptions extends Omit<PluginMetadataGenerateOptions, 'visitors'> {
5
5
  visitors?: ReadonlyVisitor[];
6
6
  visitorOptions?: PluginOptions;
@@ -1,76 +1,17 @@
1
1
  // todo: rename file to swagger-metadata.ts
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- function _export(target, all) {
7
- for(var name in all)Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: Object.getOwnPropertyDescriptor(all, name).get
10
- });
11
- }
12
- _export(exports, {
13
- get generateSwaggerMetadata () {
14
- return generateSwaggerMetadata;
15
- },
16
- get loadSwaggerMetadata () {
17
- return loadSwaggerMetadata;
18
- }
19
- });
20
- const _pluginmetadatagenerator = require("@nestjs/cli/lib/compiler/plugins/plugin-metadata-generator");
21
- const _plugin = require("@nestjs/swagger/dist/plugin");
22
- const _nodefs = require("node:fs");
23
- const _nodepath = require("node:path");
24
- const _swagger = require("@nestjs/swagger");
25
- function _getRequireWildcardCache(nodeInterop) {
26
- if (typeof WeakMap !== "function") return null;
27
- var cacheBabelInterop = new WeakMap();
28
- var cacheNodeInterop = new WeakMap();
29
- return (_getRequireWildcardCache = function(nodeInterop) {
30
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
31
- })(nodeInterop);
32
- }
33
- function _interop_require_wildcard(obj, nodeInterop) {
34
- if (!nodeInterop && obj && obj.__esModule) {
35
- return obj;
36
- }
37
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
38
- return {
39
- default: obj
40
- };
41
- }
42
- var cache = _getRequireWildcardCache(nodeInterop);
43
- if (cache && cache.has(obj)) {
44
- return cache.get(obj);
45
- }
46
- var newObj = {
47
- __proto__: null
48
- };
49
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
50
- for(var key in obj){
51
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
52
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
53
- if (desc && (desc.get || desc.set)) {
54
- Object.defineProperty(newObj, key, desc);
55
- } else {
56
- newObj[key] = obj[key];
57
- }
58
- }
59
- }
60
- newObj.default = obj;
61
- if (cache) {
62
- cache.set(obj, newObj);
63
- }
64
- return newObj;
65
- }
66
- function generateSwaggerMetadata(options) {
2
+ import { PluginMetadataGenerator } from "@nestjs/cli/lib/compiler/plugins/plugin-metadata-generator.js";
3
+ import { ReadonlyVisitor } from "@nestjs/swagger/dist/plugin/visitors/readonly.visitor.js";
4
+ import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
5
+ import { resolve } from "node:path";
6
+ import { SwaggerModule } from "@nestjs/swagger";
7
+ export function generateSwaggerMetadata(options) {
67
8
  let generateOptions = {
68
9
  filename: 'nest-swagger-metadata.js',
69
10
  watch: false,
70
11
  // ~ if this function is called in runtime, tsconfig must be copied into dist
71
12
  tsconfigPath: './tsconfig.json',
72
13
  visitors: options.visitors || [
73
- new _plugin.ReadonlyVisitor({
14
+ new ReadonlyVisitor({
74
15
  introspectComments: true,
75
16
  classValidatorShim: true,
76
17
  pathToSource: options.outputDir,
@@ -79,19 +20,22 @@ function generateSwaggerMetadata(options) {
79
20
  ],
80
21
  ...options
81
22
  };
82
- let generator = new _pluginmetadatagenerator.PluginMetadataGenerator(), outFile = (0, _nodepath.resolve)(`${generateOptions.outputDir}/${generateOptions.filename}`);
83
- if ((0, _nodefs.existsSync)(outFile)) (0, _nodefs.unlinkSync)(outFile);
23
+ let generator = new PluginMetadataGenerator(), outFile = resolve(`${generateOptions.outputDir}/${generateOptions.filename}`);
24
+ if (existsSync(outFile)) unlinkSync(outFile);
84
25
  generator.generate(generateOptions);
85
- if (options.transform && (0, _nodefs.existsSync)(outFile)) {
86
- let content = (0, _nodefs.readFileSync)(outFile, 'utf8');
87
- (0, _nodefs.writeFileSync)(outFile, options.transform(content));
26
+ if (options.transform && existsSync(outFile)) {
27
+ let content = readFileSync(outFile, 'utf8');
28
+ writeFileSync(outFile, options.transform(content));
88
29
  }
89
30
  return outFile;
90
31
  }
91
- function loadSwaggerMetadata(file = './nest-swagger-metadata') {
92
- return Promise.resolve(file).then((p)=>/*#__PURE__*/ _interop_require_wildcard(require(p))).catch(()=>{
32
+ /**
33
+ * Load the metadata that is generated by generateSwaggerMetadata()
34
+ * @param file the generated metadata file
35
+ */ export function loadSwaggerMetadata(file = './nest-swagger-metadata') {
36
+ return import(file).catch(()=>{
93
37
  throw new Error('Swagger metadata is not generated');
94
- }).then((m)=>m.default).then((metadataFn)=>_swagger.SwaggerModule.loadPluginMetadata(metadataFn));
38
+ }).then((m)=>m.default).then((metadataFn)=>SwaggerModule.loadPluginMetadata(metadataFn));
95
39
  }
96
40
 
97
41
  //# sourceMappingURL=generate-metadata.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/generate-metadata.ts"],"sourcesContent":["// todo: rename file to swagger-metadata.ts\nimport {\n type PluginMetadataGenerateOptions,\n PluginMetadataGenerator,\n} from '@nestjs/cli/lib/compiler/plugins/plugin-metadata-generator';\nimport { ReadonlyVisitor } from '@nestjs/swagger/dist/plugin';\nimport type { PluginOptions } from '@nestjs/swagger/dist/plugin/merge-options';\nimport { existsSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { SwaggerModule } from '@nestjs/swagger';\n\n/**\n * generate the metadata required for Swagger docs\n * when building the app with SWC, the metadata is not generated automatically\n * causing the docs don't appear in Swagger UI\n *\n * https://docs.nestjs.com/recipes/swc#monorepo-and-cli-plugins\n * @example generate the metadata in build time, add a \"prebuild\" script that calls generateSwaggerMetadata()\n * @example generate the metadata in runtime\n * src/main.ts\n * ```\n * import { generateSwaggerMetadata } from `@impactor/nestjs`\n * generateSwaggerMetadata({...})\n * loadSwaggerMetadata()\n * ```\n * @returns the generated file path\n */\nexport interface SwaggerMetadataOptions extends Omit<\n PluginMetadataGenerateOptions,\n 'visitors'\n> {\n visitors?: ReadonlyVisitor[];\n visitorOptions?: PluginOptions;\n /**\n * a function that transforms the generated metadata\n * @param metadata\n * @returns\n */\n transform?: (metadata: string) => string;\n}\n\nexport function generateSwaggerMetadata(options: SwaggerMetadataOptions) {\n let generateOptions: PluginMetadataGenerateOptions = {\n filename: 'nest-swagger-metadata.js',\n watch: false,\n // ~ if this function is called in runtime, tsconfig must be copied into dist\n tsconfigPath: './tsconfig.json',\n visitors: options.visitors || [\n new ReadonlyVisitor({\n introspectComments: true,\n classValidatorShim: true,\n pathToSource: options.outputDir,\n ...options.visitorOptions,\n }),\n ],\n ...options,\n };\n\n let generator = new PluginMetadataGenerator(),\n outFile = resolve(\n `${generateOptions.outputDir}/${generateOptions.filename}`,\n );\n\n if (existsSync(outFile)) unlinkSync(outFile);\n generator.generate(generateOptions);\n\n if (options.transform && existsSync(outFile)) {\n let content = readFileSync(outFile, 'utf8');\n writeFileSync(outFile, options.transform(content));\n }\n return outFile;\n}\n\n/**\n * Load the metadata that is generated by generateSwaggerMetadata()\n * @param file the generated metadata file\n */\nexport function loadSwaggerMetadata(file = './nest-swagger-metadata') {\n return import(file)\n .catch(() => {\n throw new Error('Swagger metadata is not generated');\n })\n .then((m) => m.default)\n .then((metadataFn) => SwaggerModule.loadPluginMetadata(metadataFn));\n}\n"],"names":["generateSwaggerMetadata","loadSwaggerMetadata","options","generateOptions","filename","watch","tsconfigPath","visitors","ReadonlyVisitor","introspectComments","classValidatorShim","pathToSource","outputDir","visitorOptions","generator","PluginMetadataGenerator","outFile","resolve","existsSync","unlinkSync","generate","transform","content","readFileSync","writeFileSync","file","catch","Error","then","m","default","metadataFn","SwaggerModule","loadPluginMetadata"],"mappings":"AAAA,2CAA2C;;;;;;;;;;;;QAyC3BA;eAAAA;;QAoCAC;eAAAA;;;yCAzET;wBACyB;wBAEoC;0BAC5C;yBACM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCvB,SAASD,wBAAwBE,OAA+B;IACrE,IAAIC,kBAAiD;QACnDC,UAAU;QACVC,OAAO;QACP,6EAA6E;QAC7EC,cAAc;QACdC,UAAUL,QAAQK,QAAQ,IAAI;YAC5B,IAAIC,uBAAe,CAAC;gBAClBC,oBAAoB;gBACpBC,oBAAoB;gBACpBC,cAAcT,QAAQU,SAAS;gBAC/B,GAAGV,QAAQW,cAAc;YAC3B;SACD;QACD,GAAGX,OAAO;IACZ;IAEA,IAAIY,YAAY,IAAIC,gDAAuB,IACzCC,UAAUC,IAAAA,iBAAO,EACf,GAAGd,gBAAgBS,SAAS,CAAC,CAAC,EAAET,gBAAgBC,QAAQ,EAAE;IAG9D,IAAIc,IAAAA,kBAAU,EAACF,UAAUG,IAAAA,kBAAU,EAACH;IACpCF,UAAUM,QAAQ,CAACjB;IAEnB,IAAID,QAAQmB,SAAS,IAAIH,IAAAA,kBAAU,EAACF,UAAU;QAC5C,IAAIM,UAAUC,IAAAA,oBAAY,EAACP,SAAS;QACpCQ,IAAAA,qBAAa,EAACR,SAASd,QAAQmB,SAAS,CAACC;IAC3C;IACA,OAAON;AACT;AAMO,SAASf,oBAAoBwB,OAAO,yBAAyB;IAClE,OAAO,gBAAOA,wDAAP,aACJC,KAAK,CAAC;QACL,MAAM,IAAIC,MAAM;IAClB,GACCC,IAAI,CAAC,CAACC,IAAMA,EAAEC,OAAO,EACrBF,IAAI,CAAC,CAACG,aAAeC,sBAAa,CAACC,kBAAkB,CAACF;AAC3D"}
1
+ {"version":3,"sources":["../../src/generate-metadata.ts"],"sourcesContent":["// todo: rename file to swagger-metadata.ts\nimport {\n type PluginMetadataGenerateOptions,\n PluginMetadataGenerator,\n} from '@nestjs/cli/lib/compiler/plugins/plugin-metadata-generator.js';\nimport { ReadonlyVisitor } from '@nestjs/swagger/dist/plugin/visitors/readonly.visitor.js';\nimport type { PluginOptions } from '@nestjs/swagger/dist/plugin/merge-options.js';\nimport { existsSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { SwaggerModule } from '@nestjs/swagger';\n\n/**\n * generate the metadata required for Swagger docs\n * when building the app with SWC, the metadata is not generated automatically\n * causing the docs don't appear in Swagger UI\n *\n * https://docs.nestjs.com/recipes/swc#monorepo-and-cli-plugins\n * @example generate the metadata in build time, add a \"prebuild\" script that calls generateSwaggerMetadata()\n * @example generate the metadata in runtime\n * src/main.ts\n * ```\n * import { generateSwaggerMetadata } from `@impactor/nestjs`\n * generateSwaggerMetadata({...})\n * loadSwaggerMetadata()\n * ```\n * @returns the generated file path\n */\nexport interface SwaggerMetadataOptions extends Omit<\n PluginMetadataGenerateOptions,\n 'visitors'\n> {\n visitors?: ReadonlyVisitor[];\n visitorOptions?: PluginOptions;\n /**\n * a function that transforms the generated metadata\n * @param metadata\n * @returns\n */\n transform?: (metadata: string) => string;\n}\n\nexport function generateSwaggerMetadata(options: SwaggerMetadataOptions) {\n let generateOptions: PluginMetadataGenerateOptions = {\n filename: 'nest-swagger-metadata.js',\n watch: false,\n // ~ if this function is called in runtime, tsconfig must be copied into dist\n tsconfigPath: './tsconfig.json',\n visitors: options.visitors || [\n new ReadonlyVisitor({\n introspectComments: true,\n classValidatorShim: true,\n pathToSource: options.outputDir,\n ...options.visitorOptions,\n }),\n ],\n ...options,\n };\n\n let generator = new PluginMetadataGenerator(),\n outFile = resolve(\n `${generateOptions.outputDir}/${generateOptions.filename}`,\n );\n\n if (existsSync(outFile)) unlinkSync(outFile);\n generator.generate(generateOptions);\n\n if (options.transform && existsSync(outFile)) {\n let content = readFileSync(outFile, 'utf8');\n writeFileSync(outFile, options.transform(content));\n }\n return outFile;\n}\n\n/**\n * Load the metadata that is generated by generateSwaggerMetadata()\n * @param file the generated metadata file\n */\nexport function loadSwaggerMetadata(file = './nest-swagger-metadata') {\n return import(file)\n .catch(() => {\n throw new Error('Swagger metadata is not generated');\n })\n .then((m) => m.default)\n .then((metadataFn) => SwaggerModule.loadPluginMetadata(metadataFn));\n}\n"],"names":["PluginMetadataGenerator","ReadonlyVisitor","existsSync","readFileSync","unlinkSync","writeFileSync","resolve","SwaggerModule","generateSwaggerMetadata","options","generateOptions","filename","watch","tsconfigPath","visitors","introspectComments","classValidatorShim","pathToSource","outputDir","visitorOptions","generator","outFile","generate","transform","content","loadSwaggerMetadata","file","catch","Error","then","m","default","metadataFn","loadPluginMetadata"],"mappings":"AAAA,2CAA2C;AAC3C,SAEEA,uBAAuB,QAClB,gEAAgE;AACvE,SAASC,eAAe,QAAQ,2DAA2D;AAE3F,SAASC,UAAU,EAAEC,YAAY,EAAEC,UAAU,EAAEC,aAAa,QAAQ,UAAU;AAC9E,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,aAAa,QAAQ,kBAAkB;AAgChD,OAAO,SAASC,wBAAwBC,OAA+B;IACrE,IAAIC,kBAAiD;QACnDC,UAAU;QACVC,OAAO;QACP,6EAA6E;QAC7EC,cAAc;QACdC,UAAUL,QAAQK,QAAQ,IAAI;YAC5B,IAAIb,gBAAgB;gBAClBc,oBAAoB;gBACpBC,oBAAoB;gBACpBC,cAAcR,QAAQS,SAAS;gBAC/B,GAAGT,QAAQU,cAAc;YAC3B;SACD;QACD,GAAGV,OAAO;IACZ;IAEA,IAAIW,YAAY,IAAIpB,2BAClBqB,UAAUf,QACR,GAAGI,gBAAgBQ,SAAS,CAAC,CAAC,EAAER,gBAAgBC,QAAQ,EAAE;IAG9D,IAAIT,WAAWmB,UAAUjB,WAAWiB;IACpCD,UAAUE,QAAQ,CAACZ;IAEnB,IAAID,QAAQc,SAAS,IAAIrB,WAAWmB,UAAU;QAC5C,IAAIG,UAAUrB,aAAakB,SAAS;QACpChB,cAAcgB,SAASZ,QAAQc,SAAS,CAACC;IAC3C;IACA,OAAOH;AACT;AAEA;;;CAGC,GACD,OAAO,SAASI,oBAAoBC,OAAO,yBAAyB;IAClE,OAAO,MAAM,CAACA,MACXC,KAAK,CAAC;QACL,MAAM,IAAIC,MAAM;IAClB,GACCC,IAAI,CAAC,CAACC,IAAMA,EAAEC,OAAO,EACrBF,IAAI,CAAC,CAACG,aAAezB,cAAc0B,kBAAkB,CAACD;AAC3D"}