@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,53 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: Object.getOwnPropertyDescriptor(all, name).get
9
- });
10
- }
11
- _export(exports, {
12
- get applyDecorators () {
13
- return applyDecorators;
14
- },
15
- get get () {
16
- return get;
17
- },
18
- get getAll () {
19
- return getAll;
20
- },
21
- get getKeys () {
22
- return getKeys;
23
- },
24
- get has () {
25
- return has;
26
- },
27
- get set () {
28
- return set;
29
- }
30
- });
31
- const _common = require("@nestjs/common");
32
- function has(property, factory, route) {
1
+ import { UseInterceptors } from "@nestjs/common";
2
+ /**
3
+ * Check if the class or a method has a metadata property
4
+ * @param property the metadata property to be checked
5
+ * @param factory the class
6
+ * @param route if provided, the method's metadata is checked, otherwise the class's metadata is checked
7
+ * @returns
8
+ */ export function has(property, factory, route) {
33
9
  if (route && !route.methodName) {
34
10
  throw new Error(`route's methodName is not provided (${route.httpMethod?.toUpperCase()} ${route.path})`);
35
11
  }
36
12
  return route ? Reflect.hasMetadata(property, factory.controller.prototype[route.methodName]) : Reflect.hasMetadata(property, factory.controller.prototype) || Reflect.hasMetadata(property, factory.controller);
37
13
  }
38
- function get(property, factory, route) {
14
+ export function get(property, factory, route) {
39
15
  if (route && !route.methodName) {
40
16
  throw new Error(`route's methodName is not provided (${route.httpMethod?.toUpperCase()} ${route.path})`);
41
17
  }
42
18
  return route ? Reflect.getMetadata(property, factory.controller.prototype[route.methodName]) : Reflect.getMetadata(property, factory.controller.prototype) || Reflect.getMetadata(property, factory.controller);
43
19
  }
44
- function set(property, value, factory, route) {
20
+ export function set(property, value, factory, route) {
45
21
  if (route && !route.methodName) {
46
22
  throw new Error(`route's methodName is not provided (${route.httpMethod?.toUpperCase()} ${route.path})`);
47
23
  }
48
24
  return route ? Reflect.defineMetadata(property, value, factory.controller.prototype[route.methodName]) : Reflect.defineMetadata(property, value, factory.controller.prototype);
49
25
  }
50
- function getKeys(factory, route) {
26
+ /**
27
+ * get all metadata keys
28
+ * @param factory
29
+ * @param route
30
+ */ export function getKeys(factory, route) {
51
31
  if (route && !route.methodName) {
52
32
  throw new Error(`route's methodName is not provided (${route.httpMethod?.toUpperCase()} ${route.path})`);
53
33
  }
@@ -58,7 +38,11 @@ function getKeys(factory, route) {
58
38
  ])
59
39
  ];
60
40
  }
61
- function getAll(factory, route) {
41
+ /**
42
+ * get all metadata key-value pairs
43
+ * @param factory
44
+ * @param route
45
+ */ export function getAll(factory, route) {
62
46
  let keys = getKeys(factory, route);
63
47
  let map = {};
64
48
  for (let key of keys){
@@ -66,7 +50,9 @@ function getAll(factory, route) {
66
50
  }
67
51
  return map;
68
52
  }
69
- function applyDecorators(factory) {
53
+ /**
54
+ * apply the provided decorators to the method
55
+ */ export function applyDecorators(factory) {
70
56
  if (factory.decorators?.length) {
71
57
  Reflect.decorate(factory.decorators, factory.controller);
72
58
  }
@@ -76,7 +62,7 @@ function applyDecorators(factory) {
76
62
  Reflect.decorate(route.decorators, factory.controller.prototype, route.methodName, Reflect.getOwnPropertyDescriptor(factory.controller.prototype, route.methodName));
77
63
  if (route.interceptors?.length) {
78
64
  Reflect.decorate([
79
- (0, _common.UseInterceptors)(...route.interceptors)
65
+ UseInterceptors(...route.interceptors)
80
66
  ], factory.controller.prototype, route.methodName, Reflect.getOwnPropertyDescriptor(factory.controller.prototype, route.methodName));
81
67
  }
82
68
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/decorators/controller/utils/reflect.ts"],"sourcesContent":["import { UseInterceptors } from '@nestjs/common';\nimport { ControllerFactory } from '../controller.factory';\nimport { IRoute } from '../types';\n\n/**\n * Check if the class or a method has a metadata property\n * @param property the metadata property to be checked\n * @param factory the class\n * @param route if provided, the method's metadata is checked, otherwise the class's metadata is checked\n * @returns\n */\nexport function has(\n property: string,\n factory: ControllerFactory,\n route?: IRoute,\n) {\n if (route && !route.methodName) {\n throw new Error(\n `route's methodName is not provided (${route.httpMethod?.toUpperCase()} ${route.path})`,\n );\n }\n\n return route\n ? Reflect.hasMetadata(\n property,\n factory.controller.prototype[route.methodName],\n )\n : Reflect.hasMetadata(property, factory.controller.prototype) ||\n Reflect.hasMetadata(property, factory.controller);\n}\n\nexport function get(\n property: string,\n factory: ControllerFactory,\n route?: IRoute,\n) {\n if (route && !route.methodName) {\n throw new Error(\n `route's methodName is not provided (${route.httpMethod?.toUpperCase()} ${route.path})`,\n );\n }\n\n return route\n ? Reflect.getMetadata(\n property,\n factory.controller.prototype[route.methodName],\n )\n : Reflect.getMetadata(property, factory.controller.prototype) ||\n Reflect.getMetadata(property, factory.controller);\n}\n\nexport function set<T extends Object>(\n property: string,\n value: T,\n factory: ControllerFactory,\n route?: IRoute,\n) {\n if (route && !route.methodName) {\n throw new Error(\n `route's methodName is not provided (${route.httpMethod?.toUpperCase()} ${route.path})`,\n );\n }\n\n return route\n ? Reflect.defineMetadata(\n property,\n value,\n factory.controller.prototype[route.methodName],\n )\n : Reflect.defineMetadata(property, value, factory.controller.prototype);\n}\n\n/**\n * get all metadata keys\n * @param factory\n * @param route\n */\nexport function getKeys(factory: ControllerFactory, route?: IRoute) {\n if (route && !route.methodName) {\n throw new Error(\n `route's methodName is not provided (${route.httpMethod?.toUpperCase()} ${route.path})`,\n );\n }\n\n return route\n ? Reflect.getMetadataKeys(factory.controller.prototype[route.methodName])\n : [\n ...new Set([\n ...Reflect.getMetadataKeys(factory.controller.prototype),\n ...Reflect.getMetadataKeys(factory.controller),\n ]),\n ];\n}\n\n/**\n * get all metadata key-value pairs\n * @param factory\n * @param route\n */\nexport function getAll(factory: ControllerFactory, route?: IRoute) {\n let keys = getKeys(factory, route);\n let map: { [key: string]: unknown } = {};\n\n for (let key of keys) {\n map[key] = get(key, factory, route);\n }\n\n return map;\n}\n\n/**\n * apply the provided decorators to the method\n */\nexport function applyDecorators(factory: ControllerFactory) {\n if (factory.decorators?.length) {\n Reflect.decorate(factory.decorators, factory.controller);\n }\n\n for (let route of factory.options.routes) {\n // without reflect-metadata use: `decorator(target, method, descriptor)`\n if (route.decorators?.length) {\n Reflect.decorate(\n route.decorators,\n factory.controller.prototype,\n route.methodName,\n Reflect.getOwnPropertyDescriptor(\n factory.controller.prototype,\n route.methodName,\n ),\n );\n\n if (route.interceptors?.length) {\n Reflect.decorate(\n [UseInterceptors(...route.interceptors)],\n factory.controller.prototype,\n route.methodName,\n Reflect.getOwnPropertyDescriptor(\n factory.controller.prototype,\n route.methodName,\n ),\n );\n }\n }\n }\n}\n"],"names":["applyDecorators","get","getAll","getKeys","has","set","property","factory","route","methodName","Error","httpMethod","toUpperCase","path","Reflect","hasMetadata","controller","prototype","getMetadata","value","defineMetadata","getMetadataKeys","Set","keys","map","key","decorators","length","decorate","options","routes","getOwnPropertyDescriptor","interceptors","UseInterceptors"],"mappings":"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"}
1
+ {"version":3,"sources":["../../../../../src/decorators/controller/utils/reflect.ts"],"sourcesContent":["import { UseInterceptors } from '@nestjs/common';\nimport { ControllerFactory } from '../controller.factory.js';\nimport { IRoute } from '../types/index.js';\n\n/**\n * Check if the class or a method has a metadata property\n * @param property the metadata property to be checked\n * @param factory the class\n * @param route if provided, the method's metadata is checked, otherwise the class's metadata is checked\n * @returns\n */\nexport function has(\n property: string,\n factory: ControllerFactory,\n route?: IRoute,\n) {\n if (route && !route.methodName) {\n throw new Error(\n `route's methodName is not provided (${route.httpMethod?.toUpperCase()} ${route.path})`,\n );\n }\n\n return route\n ? Reflect.hasMetadata(\n property,\n factory.controller.prototype[route.methodName],\n )\n : Reflect.hasMetadata(property, factory.controller.prototype) ||\n Reflect.hasMetadata(property, factory.controller);\n}\n\nexport function get(\n property: string,\n factory: ControllerFactory,\n route?: IRoute,\n) {\n if (route && !route.methodName) {\n throw new Error(\n `route's methodName is not provided (${route.httpMethod?.toUpperCase()} ${route.path})`,\n );\n }\n\n return route\n ? Reflect.getMetadata(\n property,\n factory.controller.prototype[route.methodName],\n )\n : Reflect.getMetadata(property, factory.controller.prototype) ||\n Reflect.getMetadata(property, factory.controller);\n}\n\nexport function set<T extends Object>(\n property: string,\n value: T,\n factory: ControllerFactory,\n route?: IRoute,\n) {\n if (route && !route.methodName) {\n throw new Error(\n `route's methodName is not provided (${route.httpMethod?.toUpperCase()} ${route.path})`,\n );\n }\n\n return route\n ? Reflect.defineMetadata(\n property,\n value,\n factory.controller.prototype[route.methodName],\n )\n : Reflect.defineMetadata(property, value, factory.controller.prototype);\n}\n\n/**\n * get all metadata keys\n * @param factory\n * @param route\n */\nexport function getKeys(factory: ControllerFactory, route?: IRoute) {\n if (route && !route.methodName) {\n throw new Error(\n `route's methodName is not provided (${route.httpMethod?.toUpperCase()} ${route.path})`,\n );\n }\n\n return route\n ? Reflect.getMetadataKeys(factory.controller.prototype[route.methodName])\n : [\n ...new Set([\n ...Reflect.getMetadataKeys(factory.controller.prototype),\n ...Reflect.getMetadataKeys(factory.controller),\n ]),\n ];\n}\n\n/**\n * get all metadata key-value pairs\n * @param factory\n * @param route\n */\nexport function getAll(factory: ControllerFactory, route?: IRoute) {\n let keys = getKeys(factory, route);\n let map: { [key: string]: unknown } = {};\n\n for (let key of keys) {\n map[key] = get(key, factory, route);\n }\n\n return map;\n}\n\n/**\n * apply the provided decorators to the method\n */\nexport function applyDecorators(factory: ControllerFactory) {\n if (factory.decorators?.length) {\n Reflect.decorate(factory.decorators, factory.controller);\n }\n\n for (let route of factory.options.routes) {\n // without reflect-metadata use: `decorator(target, method, descriptor)`\n if (route.decorators?.length) {\n Reflect.decorate(\n route.decorators,\n factory.controller.prototype,\n route.methodName,\n Reflect.getOwnPropertyDescriptor(\n factory.controller.prototype,\n route.methodName,\n ),\n );\n\n if (route.interceptors?.length) {\n Reflect.decorate(\n [UseInterceptors(...route.interceptors)],\n factory.controller.prototype,\n route.methodName,\n Reflect.getOwnPropertyDescriptor(\n factory.controller.prototype,\n route.methodName,\n ),\n );\n }\n }\n }\n}\n"],"names":["UseInterceptors","has","property","factory","route","methodName","Error","httpMethod","toUpperCase","path","Reflect","hasMetadata","controller","prototype","get","getMetadata","set","value","defineMetadata","getKeys","getMetadataKeys","Set","getAll","keys","map","key","applyDecorators","decorators","length","decorate","options","routes","getOwnPropertyDescriptor","interceptors"],"mappings":"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"}
@@ -0,0 +1,6 @@
1
+ import { EntityOptions } from 'typeorm';
2
+ export interface IEntityOptions extends EntityOptions {
3
+ name?: string;
4
+ }
5
+ export declare function Entity(name?: string, options?: EntityOptions): ClassDecorator;
6
+ export declare function Hide(): PropertyDecorator;
@@ -0,0 +1,73 @@
1
+ import { registerEntities } from "../register-entities.js";
2
+ import { Entity as TypeORMEntity, getMetadataArgsStorage } from "typeorm";
3
+ import { snakeCase } from "typeorm/util/StringUtils.js";
4
+ /**
5
+ * Define a class as a TypeORM entity
6
+ * - add Swagger decorators to all columns
7
+ *
8
+ * note: currently, this decorator ignores `@ApiHideProperty()`
9
+ * use `@Hide()` instead
10
+ * https://github.com/nestjs/swagger/issues/3711
11
+ */ // todo: add basic columns such as id, created_at, updated_at
12
+ // this has a downside, that TS cannot detect props that are defined dynamically
13
+ // i.e. `Model.id` will cause a TS error
14
+ // todo: add class validator decorators from column definition
15
+ // for instance `@Column(type: 'varchar', length: 200)` -> `@IsString() @MaxLength(200)`
16
+ // note that we cannot access uninitialized classes properties,
17
+ // so `this.model[col.propertyName]` is always undefined,
18
+ // also Reflect methods cannot be used to decorate those properties as they are not existing
19
+ // otherwise use a property decorator to work with each property separately
20
+ // todo: create `@Column()` decorator to apply these steps on property-level
21
+ // this has a downside: it'll use the property name rather than the final column name,
22
+ // because TypeORM may rename the column using a naming strategy
23
+ // so, we need to access the naming strategy to apply it on each prop
24
+ export function Entity(name, options) {
25
+ return (target)=>{
26
+ new EntityFactory(target, {
27
+ name,
28
+ ...options
29
+ });
30
+ };
31
+ }
32
+ let EntityFactory = class EntityFactory {
33
+ constructor(model, options){
34
+ this.model = model;
35
+ this.options = options;
36
+ /**
37
+ * contains all TypeORM metadata for all entities
38
+ */ this.storage = getMetadataArgsStorage();
39
+ this.addEntity();
40
+ this.addSwaggerDecorators();
41
+ }
42
+ /**
43
+ * decorate the class with TypeORM `@Entity()`
44
+ */ addEntity() {
45
+ // TypeORM's `@Entity()` adds the class to storage.tables
46
+ if (!this.storage.tables.some((el)=>el.target === this.model)) {
47
+ Reflect.decorate([
48
+ TypeORMEntity(this.options?.name || // todo: generate plural names
49
+ snakeCase(this.model.name.replace(/(Entity|DTO|Model)$/i, '') + 's'), this.options)
50
+ ], this.model);
51
+ }
52
+ }
53
+ /**
54
+ * add Swagger decorators to all the model fields
55
+ */ addSwaggerDecorators() {
56
+ // todo: also get the class that this.model extends, if any.
57
+ registerEntities([
58
+ this.model
59
+ ]);
60
+ }
61
+ };
62
+ /**
63
+ * add `@Hide()` to properties that you don't want to hide in Swagger
64
+ * Using `@ApiHideProperty()` from `@nestjs/swagger` is not supported
65
+ * `@ApiHideProperty()` doesn't add a metadata -> use `@Hide()`
66
+ * https://github.com/nestjs/swagger/blob/master/lib/decorators/api-hide-property.decorator.ts
67
+ */ export function Hide() {
68
+ return (target, key)=>{
69
+ Reflect.defineMetadata('swagger/apiModelProperties', false, target, key);
70
+ };
71
+ }
72
+
73
+ //# sourceMappingURL=entity.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/decorators/entity.decorator.ts"],"sourcesContent":["import { registerEntities } from '../register-entities.js';\nimport {\n Entity as TypeORMEntity,\n EntityOptions,\n getMetadataArgsStorage,\n} from 'typeorm';\nimport { MetadataArgsStorage } from 'typeorm/metadata-args/MetadataArgsStorage.js';\nimport { snakeCase } from 'typeorm/util/StringUtils.js';\n\nexport interface IEntityOptions extends EntityOptions {\n name?: string;\n}\n\n/**\n * Define a class as a TypeORM entity\n * - add Swagger decorators to all columns\n *\n * note: currently, this decorator ignores `@ApiHideProperty()`\n * use `@Hide()` instead\n * https://github.com/nestjs/swagger/issues/3711\n */\n// todo: add basic columns such as id, created_at, updated_at\n// this has a downside, that TS cannot detect props that are defined dynamically\n// i.e. `Model.id` will cause a TS error\n// todo: add class validator decorators from column definition\n// for instance `@Column(type: 'varchar', length: 200)` -> `@IsString() @MaxLength(200)`\n// note that we cannot access uninitialized classes properties,\n// so `this.model[col.propertyName]` is always undefined,\n// also Reflect methods cannot be used to decorate those properties as they are not existing\n// otherwise use a property decorator to work with each property separately\n// todo: create `@Column()` decorator to apply these steps on property-level\n// this has a downside: it'll use the property name rather than the final column name,\n// because TypeORM may rename the column using a naming strategy\n// so, we need to access the naming strategy to apply it on each prop\nexport function Entity(name?: string, options?: EntityOptions): ClassDecorator {\n return (target: Function) => {\n new EntityFactory(target, { name, ...options });\n };\n}\n\nclass EntityFactory {\n /**\n * contains all TypeORM metadata for all entities\n */\n private storage: MetadataArgsStorage = getMetadataArgsStorage();\n\n constructor(\n private model: Function,\n private options?: IEntityOptions,\n ) {\n this.addEntity();\n this.addSwaggerDecorators();\n }\n\n /**\n * decorate the class with TypeORM `@Entity()`\n */\n addEntity() {\n // TypeORM's `@Entity()` adds the class to storage.tables\n if (!this.storage.tables.some((el) => el.target === this.model)) {\n Reflect.decorate(\n [\n TypeORMEntity(\n this.options?.name ||\n // todo: generate plural names\n snakeCase(\n this.model.name.replace(/(Entity|DTO|Model)$/i, '') + 's',\n ),\n this.options,\n ),\n ],\n this.model,\n );\n }\n }\n\n /**\n * add Swagger decorators to all the model fields\n */\n addSwaggerDecorators() {\n // todo: also get the class that this.model extends, if any.\n registerEntities([this.model]);\n }\n}\n\n/**\n * add `@Hide()` to properties that you don't want to hide in Swagger\n * Using `@ApiHideProperty()` from `@nestjs/swagger` is not supported\n * `@ApiHideProperty()` doesn't add a metadata -> use `@Hide()`\n * https://github.com/nestjs/swagger/blob/master/lib/decorators/api-hide-property.decorator.ts\n */\nexport function Hide(): PropertyDecorator {\n return (target: Object, key: string | symbol) => {\n Reflect.defineMetadata('swagger/apiModelProperties', false, target, key);\n };\n}\n"],"names":["registerEntities","Entity","TypeORMEntity","getMetadataArgsStorage","snakeCase","name","options","target","EntityFactory","model","storage","addEntity","addSwaggerDecorators","tables","some","el","Reflect","decorate","replace","Hide","key","defineMetadata"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,0BAA0B;AAC3D,SACEC,UAAUC,aAAa,EAEvBC,sBAAsB,QACjB,UAAU;AAEjB,SAASC,SAAS,QAAQ,8BAA8B;AAMxD;;;;;;;CAOC,GACD,6DAA6D;AAC7D,gFAAgF;AAChF,wCAAwC;AACxC,8DAA8D;AAC9D,wFAAwF;AACxF,+DAA+D;AAC/D,yDAAyD;AACzD,4FAA4F;AAC5F,2EAA2E;AAC3E,4EAA4E;AAC5E,sFAAsF;AACtF,gEAAgE;AAChE,qEAAqE;AACrE,OAAO,SAASH,OAAOI,IAAa,EAAEC,OAAuB;IAC3D,OAAO,CAACC;QACN,IAAIC,cAAcD,QAAQ;YAAEF;YAAM,GAAGC,OAAO;QAAC;IAC/C;AACF;AAEA,IAAA,AAAME,gBAAN,MAAMA;IAMJ,YACE,AAAQC,KAAe,EACvB,AAAQH,OAAwB,CAChC;aAFQG,QAAAA;aACAH,UAAAA;QAPV;;GAEC,QACOI,UAA+BP;QAMrC,IAAI,CAACQ,SAAS;QACd,IAAI,CAACC,oBAAoB;IAC3B;IAEA;;GAEC,GACDD,YAAY;QACV,yDAAyD;QACzD,IAAI,CAAC,IAAI,CAACD,OAAO,CAACG,MAAM,CAACC,IAAI,CAAC,CAACC,KAAOA,GAAGR,MAAM,KAAK,IAAI,CAACE,KAAK,GAAG;YAC/DO,QAAQC,QAAQ,CACd;gBACEf,cACE,IAAI,CAACI,OAAO,EAAED,QACZ,8BAA8B;gBAC9BD,UACE,IAAI,CAACK,KAAK,CAACJ,IAAI,CAACa,OAAO,CAAC,wBAAwB,MAAM,MAE1D,IAAI,CAACZ,OAAO;aAEf,EACD,IAAI,CAACG,KAAK;QAEd;IACF;IAEA;;GAEC,GACDG,uBAAuB;QACrB,4DAA4D;QAC5DZ,iBAAiB;YAAC,IAAI,CAACS,KAAK;SAAC;IAC/B;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASU;IACd,OAAO,CAACZ,QAAgBa;QACtBJ,QAAQK,cAAc,CAAC,8BAA8B,OAAOd,QAAQa;IACtE;AACF"}
@@ -1,56 +1,97 @@
1
- /* eslint unicorn/prevent-abbreviations: 0 */ "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: Object.getOwnPropertyDescriptor(all, name).get
9
- });
10
- }
11
- _export(exports, {
12
- get Prop () {
13
- return Prop;
14
- },
15
- get Uuid () {
16
- return Uuid;
17
- },
18
- get UuidApi () {
19
- return UuidApi;
20
- }
21
- });
22
- const _common = require("@nestjs/common");
23
- const _swagger = require("@nestjs/swagger");
24
- const _microservices = require("@nestjs/microservices");
25
- const _websockets = require("@nestjs/websockets");
26
- function Prop(name, scope = 'params', pipes = []) {
1
+ /* eslint unicorn/prevent-abbreviations: 0 */ import { BadRequestException, Body, Param, Query, createParamDecorator } from "@nestjs/common";
2
+ import { ParseUUIDPipe } from "@nestjs/common";
3
+ import { ApiParam } from "@nestjs/swagger";
4
+ import { Payload } from "@nestjs/microservices";
5
+ import { MessageBody } from "@nestjs/websockets";
6
+ /**
7
+ * a param decorator that extracts a field from the request
8
+ * and validates it using pipes
9
+ * and add the suitable Swagger's docs
10
+ *
11
+ * @param name the field's name
12
+ * @param scope the scope where the prop is defined in
13
+ *
14
+ * @example
15
+ * extract userId from params
16
+ * ```
17
+ * @Get(':userId')
18
+ * findUserById(@Prop('userId') userId: string){
19
+ * this.service.findUserById(userId);
20
+ * }
21
+ * ```
22
+ *
23
+ * @example
24
+ * extract the id from the query string
25
+ * ```
26
+ * @Get()
27
+ * filterByTenant(@Prop('tenantId', 'query') tenantId: string){ ... }
28
+ * ```
29
+ *
30
+ * @example
31
+ * extract the product id from the request's body
32
+ * ```
33
+ * @Post()
34
+ * createOrder(@Prop('productId','body') productId: string){ ... }
35
+ * ```
36
+ *
37
+ * @example
38
+ * manipulate the swagger's docs: make the id optional
39
+ * ```
40
+ * @Get('id')
41
+ * find(@Prop('id', 'params', <any>{ required: false }) id?: string){
42
+ * return id?: this.service.findById(id) : this.service.find()
43
+ * }
44
+ * ```
45
+ *
46
+ * @returns the field value
47
+ * @throws BadRequestException
48
+ */ export function Prop(name, scope = 'params', pipes = []) {
27
49
  return (target, propertyKey, parameterIndex)=>{
28
50
  if (scope === 'payload') {
29
- return (0, _microservices.Payload)(name, ...pipes)(target, propertyKey, parameterIndex);
51
+ return Payload(name, ...pipes)(target, propertyKey, parameterIndex);
30
52
  } else if (scope === 'messageBody') {
31
- return (0, _websockets.MessageBody)(name, ...pipes)(target, propertyKey, parameterIndex);
53
+ return MessageBody(name, ...pipes)(target, propertyKey, parameterIndex);
32
54
  } else if (scope === 'params') {
33
- return (0, _common.Param)(name, ...pipes)(target, propertyKey, parameterIndex);
55
+ return Param(name, ...pipes)(target, propertyKey, parameterIndex);
34
56
  } else if (scope === 'query') {
35
- return (0, _common.Query)(name, ...pipes)(target, propertyKey, parameterIndex);
57
+ return Query(name, ...pipes)(target, propertyKey, parameterIndex);
36
58
  } else if (scope === 'body') {
37
- return (0, _common.Body)(name, ...pipes)(target, propertyKey, parameterIndex);
59
+ return Body(name, ...pipes)(target, propertyKey, parameterIndex);
38
60
  }
39
61
  };
40
62
  }
41
- function Uuid(name = 'id', scope = 'params', pipes) {
63
+ /**
64
+ * apply @prop() to extract the id field and validate its value as uuid *
65
+ * to customize the Swagger's docs use uuidApi()
66
+ * @returns the UUID value
67
+ * @throws BadRequestException
68
+ */ export function Uuid(name = 'id', scope = 'params', pipes) {
42
69
  return Prop(name, scope, pipes || [
43
- new _common.ParseUUIDPipe()
70
+ new ParseUUIDPipe()
44
71
  ]);
45
72
  }
46
- function UuidApi(name = 'id', scope = 'params', // TODO: accept options based on the scope's value
73
+ /**
74
+ * same as Uuid() but can provide additional options for Swagger's docs
75
+ *
76
+ * @example
77
+ * if the prop name is id, it is optional
78
+ * ```
79
+ * @Get('id)
80
+ * findById(@Uuid() id: string){}
81
+ * ```
82
+ *
83
+ * @param name
84
+ * @param scope
85
+ * @param apiOptions additional options for swagger's docs
86
+ * @returns
87
+ */ export function UuidApi(name = 'id', scope = 'params', // TODO: accept options based on the scope's value
47
88
  // TODO: allow swapping between scope and apiOptions
48
89
  apiOptions) {
49
90
  return (target, propertyKey, parameterIndex)=>{
50
91
  // TODO: add swagger docs for other scopes
51
92
  // TODO: auto detect if the property is optional -> `@Uuid() id?: string`
52
93
  if (scope === 'params') {
53
- (0, _swagger.ApiParam)({
94
+ ApiParam({
54
95
  name,
55
96
  type: 'string',
56
97
  format: 'uuid',
@@ -58,13 +99,13 @@ apiOptions) {
58
99
  ...apiOptions
59
100
  })(target.constructor, propertyKey, Object.getOwnPropertyDescriptor(target, propertyKey));
60
101
  }
61
- let IdParamDecorator = (0, _common.createParamDecorator)((opts, ctx)=>{
102
+ let IdParamDecorator = createParamDecorator((opts, ctx)=>{
62
103
  let { name = 'id', scope = 'params' } = opts;
63
104
  let req = ctx.switchToHttp().getRequest();
64
105
  let id = req[scope][name];
65
- if (!id) throw new _common.BadRequestException(`${name} is required`);
106
+ if (!id) throw new BadRequestException(`${name} is required`);
66
107
  // Use ParseUUIDPipe to validate the UUID
67
- let parseUUIDPipe = new _common.ParseUUIDPipe();
108
+ let parseUUIDPipe = new ParseUUIDPipe();
68
109
  return parseUUIDPipe.transform(id, {
69
110
  type: 'param',
70
111
  metatype: String
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/decorators/prop.decorator.ts"],"sourcesContent":["/* eslint unicorn/prevent-abbreviations: 0 */\nimport {\n BadRequestException,\n Body,\n type ExecutionContext,\n Param,\n type PipeTransform,\n Query,\n type Type,\n createParamDecorator,\n} from '@nestjs/common';\nimport { ParseUUIDPipe } from '@nestjs/common';\nimport { ApiParam, type ApiParamOptions } from '@nestjs/swagger';\nimport { Payload } from '@nestjs/microservices';\nimport { MessageBody } from '@nestjs/websockets';\n\nexport interface IdParamDecoratorOptions {\n /**\n * The property that is wanted to be extracted\n */\n name?: string;\n /**\n * The scope to extract the property from\n * @example @Params('id')\n * @example @Payload('id')\n */\n scope?: 'params' | 'query' | 'body' | 'payload' | 'messageBody';\n}\n\n/**\n * a param decorator that extracts a field from the request\n * and validates it using pipes\n * and add the suitable Swagger's docs\n *\n * @param name the field's name\n * @param scope the scope where the prop is defined in\n *\n * @example\n * extract userId from params\n * ```\n * @Get(':userId')\n * findUserById(@Prop('userId') userId: string){\n * this.service.findUserById(userId);\n * }\n * ```\n *\n * @example\n * extract the id from the query string\n * ```\n * @Get()\n * filterByTenant(@Prop('tenantId', 'query') tenantId: string){ ... }\n * ```\n *\n * @example\n * extract the product id from the request's body\n * ```\n * @Post()\n * createOrder(@Prop('productId','body') productId: string){ ... }\n * ```\n *\n * @example\n * manipulate the swagger's docs: make the id optional\n * ```\n * @Get('id')\n * find(@Prop('id', 'params', <any>{ required: false }) id?: string){\n * return id?: this.service.findById(id) : this.service.find()\n * }\n * ```\n *\n * @returns the field value\n * @throws BadRequestException\n */\nexport function Prop(\n name: string,\n scope: IdParamDecoratorOptions['scope'] = 'params',\n pipes: (Type<PipeTransform> | PipeTransform)[] = [],\n): ParameterDecorator {\n return (\n target: Object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n ) => {\n if (scope === 'payload') {\n return Payload(name, ...pipes)(target, propertyKey, parameterIndex);\n } else if (scope === 'messageBody') {\n return MessageBody(name, ...pipes)(target, propertyKey, parameterIndex);\n } else if (scope === 'params') {\n return Param(name, ...pipes)(target, propertyKey, parameterIndex);\n } else if (scope === 'query') {\n return Query(name, ...pipes)(target, propertyKey, parameterIndex);\n } else if (scope === 'body') {\n return Body(name, ...pipes)(target, propertyKey, parameterIndex);\n }\n };\n}\n\n/**\n * apply @prop() to extract the id field and validate its value as uuid *\n * to customize the Swagger's docs use uuidApi()\n * @returns the UUID value\n * @throws BadRequestException\n */\nexport function Uuid(\n name = 'id',\n scope: IdParamDecoratorOptions['scope'] = 'params',\n pipes?: (Type<PipeTransform> | PipeTransform)[],\n): ParameterDecorator {\n return Prop(name, scope, pipes || [new ParseUUIDPipe()]);\n}\n\n/**\n * same as Uuid() but can provide additional options for Swagger's docs\n *\n * @example\n * if the prop name is id, it is optional\n * ```\n * @Get('id)\n * findById(@Uuid() id: string){}\n * ```\n *\n * @param name\n * @param scope\n * @param apiOptions additional options for swagger's docs\n * @returns\n */\nexport function UuidApi(\n name = 'id',\n scope: IdParamDecoratorOptions['scope'] = 'params',\n // TODO: accept options based on the scope's value\n // TODO: allow swapping between scope and apiOptions\n apiOptions?: ApiParamOptions,\n): ParameterDecorator {\n return (\n target: Object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n ) => {\n // TODO: add swagger docs for other scopes\n // TODO: auto detect if the property is optional -> `@Uuid() id?: string`\n if (scope === 'params') {\n ApiParam({\n name,\n type: 'string',\n format: 'uuid',\n example: '4eae7b32-9065-42b0-a025-5cb967011e65',\n ...apiOptions,\n })(\n target.constructor,\n propertyKey as string,\n Object.getOwnPropertyDescriptor(target, propertyKey!)!,\n );\n }\n\n let IdParamDecorator = createParamDecorator(\n (opts: IdParamDecoratorOptions, ctx: ExecutionContext) => {\n let { name = 'id', scope = 'params' } = opts;\n\n let req = ctx.switchToHttp().getRequest();\n let id = req[scope][name];\n\n if (!id) throw new BadRequestException(`${name} is required`);\n\n // Use ParseUUIDPipe to validate the UUID\n let parseUUIDPipe = new ParseUUIDPipe();\n return parseUUIDPipe.transform(id, {\n type: 'param',\n metatype: String,\n });\n },\n );\n\n return IdParamDecorator({ name, scope })(\n target,\n propertyKey,\n parameterIndex,\n );\n };\n}\n"],"names":["Prop","Uuid","UuidApi","name","scope","pipes","target","propertyKey","parameterIndex","Payload","MessageBody","Param","Query","Body","ParseUUIDPipe","apiOptions","ApiParam","type","format","example","Object","getOwnPropertyDescriptor","IdParamDecorator","createParamDecorator","opts","ctx","req","switchToHttp","getRequest","id","BadRequestException","parseUUIDPipe","transform","metatype","String"],"mappings":"AAAA,2CAA2C;;;;;;;;;;;QAwE3BA;eAAAA;;QA8BAC;eAAAA;;QAuBAC;eAAAA;;;wBAnHT;yBAEwC;+BACvB;4BACI;AA0DrB,SAASF,KACdG,IAAY,EACZC,QAA0C,QAAQ,EAClDC,QAAiD,EAAE;IAEnD,OAAO,CACLC,QACAC,aACAC;QAEA,IAAIJ,UAAU,WAAW;YACvB,OAAOK,IAAAA,sBAAO,EAACN,SAASE,OAAOC,QAAQC,aAAaC;QACtD,OAAO,IAAIJ,UAAU,eAAe;YAClC,OAAOM,IAAAA,uBAAW,EAACP,SAASE,OAAOC,QAAQC,aAAaC;QAC1D,OAAO,IAAIJ,UAAU,UAAU;YAC7B,OAAOO,IAAAA,aAAK,EAACR,SAASE,OAAOC,QAAQC,aAAaC;QACpD,OAAO,IAAIJ,UAAU,SAAS;YAC5B,OAAOQ,IAAAA,aAAK,EAACT,SAASE,OAAOC,QAAQC,aAAaC;QACpD,OAAO,IAAIJ,UAAU,QAAQ;YAC3B,OAAOS,IAAAA,YAAI,EAACV,SAASE,OAAOC,QAAQC,aAAaC;QACnD;IACF;AACF;AAQO,SAASP,KACdE,OAAO,IAAI,EACXC,QAA0C,QAAQ,EAClDC,KAA+C;IAE/C,OAAOL,KAAKG,MAAMC,OAAOC,SAAS;QAAC,IAAIS,qBAAa;KAAG;AACzD;AAiBO,SAASZ,QACdC,OAAO,IAAI,EACXC,QAA0C,QAAQ,EAClD,kDAAkD;AAClD,oDAAoD;AACpDW,UAA4B;IAE5B,OAAO,CACLT,QACAC,aACAC;QAEA,0CAA0C;QAC1C,yEAAyE;QACzE,IAAIJ,UAAU,UAAU;YACtBY,IAAAA,iBAAQ,EAAC;gBACPb;gBACAc,MAAM;gBACNC,QAAQ;gBACRC,SAAS;gBACT,GAAGJ,UAAU;YACf,GACET,OAAO,WAAW,EAClBC,aACAa,OAAOC,wBAAwB,CAACf,QAAQC;QAE5C;QAEA,IAAIe,mBAAmBC,IAAAA,4BAAoB,EACzC,CAACC,MAA+BC;YAC9B,IAAI,EAAEtB,OAAO,IAAI,EAAEC,QAAQ,QAAQ,EAAE,GAAGoB;YAExC,IAAIE,MAAMD,IAAIE,YAAY,GAAGC,UAAU;YACvC,IAAIC,KAAKH,GAAG,CAACtB,MAAM,CAACD,KAAK;YAEzB,IAAI,CAAC0B,IAAI,MAAM,IAAIC,2BAAmB,CAAC,GAAG3B,KAAK,YAAY,CAAC;YAE5D,yCAAyC;YACzC,IAAI4B,gBAAgB,IAAIjB,qBAAa;YACrC,OAAOiB,cAAcC,SAAS,CAACH,IAAI;gBACjCZ,MAAM;gBACNgB,UAAUC;YACZ;QACF;QAGF,OAAOZ,iBAAiB;YAAEnB;YAAMC;QAAM,GACpCE,QACAC,aACAC;IAEJ;AACF"}
1
+ {"version":3,"sources":["../../../src/decorators/prop.decorator.ts"],"sourcesContent":["/* eslint unicorn/prevent-abbreviations: 0 */\nimport {\n BadRequestException,\n Body,\n type ExecutionContext,\n Param,\n type PipeTransform,\n Query,\n type Type,\n createParamDecorator,\n} from '@nestjs/common';\nimport { ParseUUIDPipe } from '@nestjs/common';\nimport { ApiParam, type ApiParamOptions } from '@nestjs/swagger';\nimport { Payload } from '@nestjs/microservices';\nimport { MessageBody } from '@nestjs/websockets';\n\nexport interface IdParamDecoratorOptions {\n /**\n * The property that is wanted to be extracted\n */\n name?: string;\n /**\n * The scope to extract the property from\n * @example @Params('id')\n * @example @Payload('id')\n */\n scope?: 'params' | 'query' | 'body' | 'payload' | 'messageBody';\n}\n\n/**\n * a param decorator that extracts a field from the request\n * and validates it using pipes\n * and add the suitable Swagger's docs\n *\n * @param name the field's name\n * @param scope the scope where the prop is defined in\n *\n * @example\n * extract userId from params\n * ```\n * @Get(':userId')\n * findUserById(@Prop('userId') userId: string){\n * this.service.findUserById(userId);\n * }\n * ```\n *\n * @example\n * extract the id from the query string\n * ```\n * @Get()\n * filterByTenant(@Prop('tenantId', 'query') tenantId: string){ ... }\n * ```\n *\n * @example\n * extract the product id from the request's body\n * ```\n * @Post()\n * createOrder(@Prop('productId','body') productId: string){ ... }\n * ```\n *\n * @example\n * manipulate the swagger's docs: make the id optional\n * ```\n * @Get('id')\n * find(@Prop('id', 'params', <any>{ required: false }) id?: string){\n * return id?: this.service.findById(id) : this.service.find()\n * }\n * ```\n *\n * @returns the field value\n * @throws BadRequestException\n */\nexport function Prop(\n name: string,\n scope: IdParamDecoratorOptions['scope'] = 'params',\n pipes: (Type<PipeTransform> | PipeTransform)[] = [],\n): ParameterDecorator {\n return (\n target: Object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n ) => {\n if (scope === 'payload') {\n return Payload(name, ...pipes)(target, propertyKey, parameterIndex);\n } else if (scope === 'messageBody') {\n return MessageBody(name, ...pipes)(target, propertyKey, parameterIndex);\n } else if (scope === 'params') {\n return Param(name, ...pipes)(target, propertyKey, parameterIndex);\n } else if (scope === 'query') {\n return Query(name, ...pipes)(target, propertyKey, parameterIndex);\n } else if (scope === 'body') {\n return Body(name, ...pipes)(target, propertyKey, parameterIndex);\n }\n };\n}\n\n/**\n * apply @prop() to extract the id field and validate its value as uuid *\n * to customize the Swagger's docs use uuidApi()\n * @returns the UUID value\n * @throws BadRequestException\n */\nexport function Uuid(\n name = 'id',\n scope: IdParamDecoratorOptions['scope'] = 'params',\n pipes?: (Type<PipeTransform> | PipeTransform)[],\n): ParameterDecorator {\n return Prop(name, scope, pipes || [new ParseUUIDPipe()]);\n}\n\n/**\n * same as Uuid() but can provide additional options for Swagger's docs\n *\n * @example\n * if the prop name is id, it is optional\n * ```\n * @Get('id)\n * findById(@Uuid() id: string){}\n * ```\n *\n * @param name\n * @param scope\n * @param apiOptions additional options for swagger's docs\n * @returns\n */\nexport function UuidApi(\n name = 'id',\n scope: IdParamDecoratorOptions['scope'] = 'params',\n // TODO: accept options based on the scope's value\n // TODO: allow swapping between scope and apiOptions\n apiOptions?: ApiParamOptions,\n): ParameterDecorator {\n return (\n target: Object,\n propertyKey: string | symbol | undefined,\n parameterIndex: number,\n ) => {\n // TODO: add swagger docs for other scopes\n // TODO: auto detect if the property is optional -> `@Uuid() id?: string`\n if (scope === 'params') {\n ApiParam({\n name,\n type: 'string',\n format: 'uuid',\n example: '4eae7b32-9065-42b0-a025-5cb967011e65',\n ...apiOptions,\n })(\n target.constructor,\n propertyKey as string,\n Object.getOwnPropertyDescriptor(target, propertyKey!)!,\n );\n }\n\n let IdParamDecorator = createParamDecorator(\n (opts: IdParamDecoratorOptions, ctx: ExecutionContext) => {\n let { name = 'id', scope = 'params' } = opts;\n\n let req = ctx.switchToHttp().getRequest();\n let id = req[scope][name];\n\n if (!id) throw new BadRequestException(`${name} is required`);\n\n // Use ParseUUIDPipe to validate the UUID\n let parseUUIDPipe = new ParseUUIDPipe();\n return parseUUIDPipe.transform(id, {\n type: 'param',\n metatype: String,\n });\n },\n );\n\n return IdParamDecorator({ name, scope })(\n target,\n propertyKey,\n parameterIndex,\n );\n };\n}\n"],"names":["BadRequestException","Body","Param","Query","createParamDecorator","ParseUUIDPipe","ApiParam","Payload","MessageBody","Prop","name","scope","pipes","target","propertyKey","parameterIndex","Uuid","UuidApi","apiOptions","type","format","example","Object","getOwnPropertyDescriptor","IdParamDecorator","opts","ctx","req","switchToHttp","getRequest","id","parseUUIDPipe","transform","metatype","String"],"mappings":"AAAA,2CAA2C,GAC3C,SACEA,mBAAmB,EACnBC,IAAI,EAEJC,KAAK,EAELC,KAAK,EAELC,oBAAoB,QACf,iBAAiB;AACxB,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,QAAQ,QAA8B,kBAAkB;AACjE,SAASC,OAAO,QAAQ,wBAAwB;AAChD,SAASC,WAAW,QAAQ,qBAAqB;AAejD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0CC,GACD,OAAO,SAASC,KACdC,IAAY,EACZC,QAA0C,QAAQ,EAClDC,QAAiD,EAAE;IAEnD,OAAO,CACLC,QACAC,aACAC;QAEA,IAAIJ,UAAU,WAAW;YACvB,OAAOJ,QAAQG,SAASE,OAAOC,QAAQC,aAAaC;QACtD,OAAO,IAAIJ,UAAU,eAAe;YAClC,OAAOH,YAAYE,SAASE,OAAOC,QAAQC,aAAaC;QAC1D,OAAO,IAAIJ,UAAU,UAAU;YAC7B,OAAOT,MAAMQ,SAASE,OAAOC,QAAQC,aAAaC;QACpD,OAAO,IAAIJ,UAAU,SAAS;YAC5B,OAAOR,MAAMO,SAASE,OAAOC,QAAQC,aAAaC;QACpD,OAAO,IAAIJ,UAAU,QAAQ;YAC3B,OAAOV,KAAKS,SAASE,OAAOC,QAAQC,aAAaC;QACnD;IACF;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASC,KACdN,OAAO,IAAI,EACXC,QAA0C,QAAQ,EAClDC,KAA+C;IAE/C,OAAOH,KAAKC,MAAMC,OAAOC,SAAS;QAAC,IAAIP;KAAgB;AACzD;AAEA;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASY,QACdP,OAAO,IAAI,EACXC,QAA0C,QAAQ,EAClD,kDAAkD;AAClD,oDAAoD;AACpDO,UAA4B;IAE5B,OAAO,CACLL,QACAC,aACAC;QAEA,0CAA0C;QAC1C,yEAAyE;QACzE,IAAIJ,UAAU,UAAU;YACtBL,SAAS;gBACPI;gBACAS,MAAM;gBACNC,QAAQ;gBACRC,SAAS;gBACT,GAAGH,UAAU;YACf,GACEL,OAAO,WAAW,EAClBC,aACAQ,OAAOC,wBAAwB,CAACV,QAAQC;QAE5C;QAEA,IAAIU,mBAAmBpB,qBACrB,CAACqB,MAA+BC;YAC9B,IAAI,EAAEhB,OAAO,IAAI,EAAEC,QAAQ,QAAQ,EAAE,GAAGc;YAExC,IAAIE,MAAMD,IAAIE,YAAY,GAAGC,UAAU;YACvC,IAAIC,KAAKH,GAAG,CAAChB,MAAM,CAACD,KAAK;YAEzB,IAAI,CAACoB,IAAI,MAAM,IAAI9B,oBAAoB,GAAGU,KAAK,YAAY,CAAC;YAE5D,yCAAyC;YACzC,IAAIqB,gBAAgB,IAAI1B;YACxB,OAAO0B,cAAcC,SAAS,CAACF,IAAI;gBACjCX,MAAM;gBACNc,UAAUC;YACZ;QACF;QAGF,OAAOV,iBAAiB;YAAEd;YAAMC;QAAM,GACpCE,QACAC,aACAC;IAEJ;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 RpcBadRequestException 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, "RpcBadRequestException", {
6
- enumerable: true,
7
- get: function() {
8
- return RpcBadRequestException;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _rpcbaseexception = require("./rpc-base.exception");
13
- let RpcBadRequestException = class RpcBadRequestException extends _rpcbaseexception.RpcBaseException {
1
+ import { HttpStatus } from "@nestjs/common";
2
+ import { RpcBaseException } from "./rpc-base.exception.js";
3
+ export class RpcBadRequestException extends RpcBaseException {
14
4
  constructor(message = 'Bad request'){
15
- super(message, _common.HttpStatus.BAD_REQUEST);
5
+ super(message, HttpStatus.BAD_REQUEST);
16
6
  }
17
- };
7
+ }
18
8
 
19
9
  //# sourceMappingURL=rpc-bad-request.exception.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/exceptions/rpc-bad-request.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception';\n\nexport class RpcBadRequestException extends RpcBaseException {\n constructor(message = 'Bad request') {\n super(message, HttpStatus.BAD_REQUEST);\n }\n}\n"],"names":["RpcBadRequestException","RpcBaseException","message","HttpStatus","BAD_REQUEST"],"mappings":";;;;+BAGaA;;;eAAAA;;;wBAHc;kCACM;AAE1B,IAAA,AAAMA,yBAAN,MAAMA,+BAA+BC,kCAAgB;IAC1D,YAAYC,UAAU,aAAa,CAAE;QACnC,KAAK,CAACA,SAASC,kBAAU,CAACC,WAAW;IACvC;AACF"}
1
+ {"version":3,"sources":["../../../src/exceptions/rpc-bad-request.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception.js';\n\nexport class RpcBadRequestException extends RpcBaseException {\n constructor(message = 'Bad request') {\n super(message, HttpStatus.BAD_REQUEST);\n }\n}\n"],"names":["HttpStatus","RpcBaseException","RpcBadRequestException","message","BAD_REQUEST"],"mappings":"AAAA,SAASA,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,gBAAgB,QAAQ,0BAA0B;AAE3D,OAAO,MAAMC,+BAA+BD;IAC1C,YAAYE,UAAU,aAAa,CAAE;QACnC,KAAK,CAACA,SAASH,WAAWI,WAAW;IACvC;AACF"}
@@ -1,22 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "RpcBaseException", {
6
- enumerable: true,
7
- get: function() {
8
- return RpcBaseException;
9
- }
10
- });
11
- const _microservices = require("@nestjs/microservices");
12
- const _common = require("@nestjs/common");
13
- let RpcBaseException = class RpcBaseException extends _microservices.RpcException {
14
- constructor(message, statusCode = _common.HttpStatus.INTERNAL_SERVER_ERROR){
1
+ import { RpcException } from "@nestjs/microservices";
2
+ import { HttpStatus } from "@nestjs/common";
3
+ /**
4
+ * Base Error class for RPC exceptions.
5
+ * This exception resembles the behavior of HTTP exceptions, but for RPC errors.
6
+ */ // todo: use `RpcException(new BadRequestException(message))` instead of creating custom RPC exceptions
7
+ // https://stackoverflow.com/a/75335979
8
+ export class RpcBaseException extends RpcException {
9
+ constructor(message, statusCode = HttpStatus.INTERNAL_SERVER_ERROR){
15
10
  super({
16
11
  message
17
12
  });
18
13
  this.statusCode = statusCode;
19
14
  }
20
- };
15
+ }
21
16
 
22
17
  //# sourceMappingURL=rpc-base.exception.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/exceptions/rpc-base.exception.ts"],"sourcesContent":["import { RpcException } from '@nestjs/microservices';\nimport { HttpStatus } from '@nestjs/common';\n\n/**\n * Base Error class for RPC exceptions.\n * This exception resembles the behavior of HTTP exceptions, but for RPC errors.\n */\n// todo: use `RpcException(new BadRequestException(message))` instead of creating custom RPC exceptions\n// https://stackoverflow.com/a/75335979\nexport class RpcBaseException extends RpcException {\n statusCode: HttpStatus;\n\n constructor(\n message: string,\n statusCode: HttpStatus = HttpStatus.INTERNAL_SERVER_ERROR,\n ) {\n super({ message });\n this.statusCode = statusCode;\n }\n}\n"],"names":["RpcBaseException","RpcException","message","statusCode","HttpStatus","INTERNAL_SERVER_ERROR"],"mappings":";;;;+BASaA;;;eAAAA;;;+BATgB;wBACF;AAQpB,IAAA,AAAMA,mBAAN,MAAMA,yBAAyBC,2BAAY;IAGhD,YACEC,OAAe,EACfC,aAAyBC,kBAAU,CAACC,qBAAqB,CACzD;QACA,KAAK,CAAC;YAAEH;QAAQ;QAChB,IAAI,CAACC,UAAU,GAAGA;IACpB;AACF"}
1
+ {"version":3,"sources":["../../../src/exceptions/rpc-base.exception.ts"],"sourcesContent":["import { RpcException } from '@nestjs/microservices';\nimport { HttpStatus } from '@nestjs/common';\n\n/**\n * Base Error class for RPC exceptions.\n * This exception resembles the behavior of HTTP exceptions, but for RPC errors.\n */\n// todo: use `RpcException(new BadRequestException(message))` instead of creating custom RPC exceptions\n// https://stackoverflow.com/a/75335979\nexport class RpcBaseException extends RpcException {\n statusCode: HttpStatus;\n\n constructor(\n message: string,\n statusCode: HttpStatus = HttpStatus.INTERNAL_SERVER_ERROR,\n ) {\n super({ message });\n this.statusCode = statusCode;\n }\n}\n"],"names":["RpcException","HttpStatus","RpcBaseException","message","statusCode","INTERNAL_SERVER_ERROR"],"mappings":"AAAA,SAASA,YAAY,QAAQ,wBAAwB;AACrD,SAASC,UAAU,QAAQ,iBAAiB;AAE5C;;;CAGC,GACD,uGAAuG;AACvG,uCAAuC;AACvC,OAAO,MAAMC,yBAAyBF;IAGpC,YACEG,OAAe,EACfC,aAAyBH,WAAWI,qBAAqB,CACzD;QACA,KAAK,CAAC;YAAEF;QAAQ;QAChB,IAAI,CAACC,UAAU,GAAGA;IACpB;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 RpcConflictException 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, "RpcConflictException", {
6
- enumerable: true,
7
- get: function() {
8
- return RpcConflictException;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _rpcbaseexception = require("./rpc-base.exception");
13
- let RpcConflictException = class RpcConflictException extends _rpcbaseexception.RpcBaseException {
1
+ import { HttpStatus } from "@nestjs/common";
2
+ import { RpcBaseException } from "./rpc-base.exception.js";
3
+ export class RpcConflictException extends RpcBaseException {
14
4
  constructor(message = 'Conflict'){
15
- super(message, _common.HttpStatus.CONFLICT);
5
+ super(message, HttpStatus.CONFLICT);
16
6
  }
17
- };
7
+ }
18
8
 
19
9
  //# sourceMappingURL=rpc-conflict.exception.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/exceptions/rpc-conflict.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception';\n\nexport class RpcConflictException extends RpcBaseException {\n constructor(message = 'Conflict') {\n super(message, HttpStatus.CONFLICT);\n }\n}\n"],"names":["RpcConflictException","RpcBaseException","message","HttpStatus","CONFLICT"],"mappings":";;;;+BAGaA;;;eAAAA;;;wBAHc;kCACM;AAE1B,IAAA,AAAMA,uBAAN,MAAMA,6BAA6BC,kCAAgB;IACxD,YAAYC,UAAU,UAAU,CAAE;QAChC,KAAK,CAACA,SAASC,kBAAU,CAACC,QAAQ;IACpC;AACF"}
1
+ {"version":3,"sources":["../../../src/exceptions/rpc-conflict.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception.js';\n\nexport class RpcConflictException extends RpcBaseException {\n constructor(message = 'Conflict') {\n super(message, HttpStatus.CONFLICT);\n }\n}\n"],"names":["HttpStatus","RpcBaseException","RpcConflictException","message","CONFLICT"],"mappings":"AAAA,SAASA,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,gBAAgB,QAAQ,0BAA0B;AAE3D,OAAO,MAAMC,6BAA6BD;IACxC,YAAYE,UAAU,UAAU,CAAE;QAChC,KAAK,CAACA,SAASH,WAAWI,QAAQ;IACpC;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 RpcInternalServerErrorException 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, "RpcInternalServerErrorException", {
6
- enumerable: true,
7
- get: function() {
8
- return RpcInternalServerErrorException;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _rpcbaseexception = require("./rpc-base.exception");
13
- let RpcInternalServerErrorException = class RpcInternalServerErrorException extends _rpcbaseexception.RpcBaseException {
1
+ import { HttpStatus } from "@nestjs/common";
2
+ import { RpcBaseException } from "./rpc-base.exception.js";
3
+ export class RpcInternalServerErrorException extends RpcBaseException {
14
4
  constructor(message = 'Internal server error'){
15
- super(message, _common.HttpStatus.INTERNAL_SERVER_ERROR);
5
+ super(message, HttpStatus.INTERNAL_SERVER_ERROR);
16
6
  }
17
- };
7
+ }
18
8
 
19
9
  //# sourceMappingURL=rpc-internal-server-error.exception.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/exceptions/rpc-internal-server-error.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception';\n\nexport class RpcInternalServerErrorException extends RpcBaseException {\n constructor(message = 'Internal server error') {\n super(message, HttpStatus.INTERNAL_SERVER_ERROR);\n }\n}\n"],"names":["RpcInternalServerErrorException","RpcBaseException","message","HttpStatus","INTERNAL_SERVER_ERROR"],"mappings":";;;;+BAGaA;;;eAAAA;;;wBAHc;kCACM;AAE1B,IAAA,AAAMA,kCAAN,MAAMA,wCAAwCC,kCAAgB;IACnE,YAAYC,UAAU,uBAAuB,CAAE;QAC7C,KAAK,CAACA,SAASC,kBAAU,CAACC,qBAAqB;IACjD;AACF"}
1
+ {"version":3,"sources":["../../../src/exceptions/rpc-internal-server-error.exception.ts"],"sourcesContent":["import { HttpStatus } from '@nestjs/common';\nimport { RpcBaseException } from './rpc-base.exception.js';\n\nexport class RpcInternalServerErrorException extends RpcBaseException {\n constructor(message = 'Internal server error') {\n super(message, HttpStatus.INTERNAL_SERVER_ERROR);\n }\n}\n"],"names":["HttpStatus","RpcBaseException","RpcInternalServerErrorException","message","INTERNAL_SERVER_ERROR"],"mappings":"AAAA,SAASA,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,gBAAgB,QAAQ,0BAA0B;AAE3D,OAAO,MAAMC,wCAAwCD;IACnD,YAAYE,UAAU,uBAAuB,CAAE;QAC7C,KAAK,CAACA,SAASH,WAAWI,qBAAqB;IACjD;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 RpcMethodNotAllowedException 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, "RpcMethodNotAllowedException", {
6
- enumerable: true,
7
- get: function() {
8
- return RpcMethodNotAllowedException;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _rpcbaseexception = require("./rpc-base.exception");
13
- let RpcMethodNotAllowedException = class RpcMethodNotAllowedException extends _rpcbaseexception.RpcBaseException {
1
+ import { HttpStatus } from "@nestjs/common";
2
+ import { RpcBaseException } from "./rpc-base.exception.js";
3
+ export class RpcMethodNotAllowedException extends RpcBaseException {
14
4
  constructor(message = 'Method not allowed'){
15
- super(message, _common.HttpStatus.METHOD_NOT_ALLOWED);
5
+ super(message, HttpStatus.METHOD_NOT_ALLOWED);
16
6
  }
17
- };
7
+ }
18
8
 
19
9
  //# sourceMappingURL=rpc-method-not-allowed.exception.js.map