@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,21 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "addSwaggerOperation", {
6
- enumerable: true,
7
- get: function() {
8
- return addSwaggerOperation;
9
- }
10
- });
11
- const _reflect = require("../utils/reflect");
12
- const _swagger = require("@nestjs/swagger");
13
- function addSwaggerOperation(route, factory) {
14
- if ((0, _reflect.has)('swagger/apiOperation', factory, route)) return;
1
+ import { has } from "../utils/reflect.js";
2
+ import { ApiOperation } from "@nestjs/swagger";
3
+ /**
4
+ * add Swagger's \@ApiOperation()
5
+ * @param route
6
+ */ export function addSwaggerOperation(route, factory) {
7
+ if (has('swagger/apiOperation', factory, route)) return;
15
8
  // remove "path" or add "prefix" metadata to it from the constructor
16
9
  // to prevent displaying the path without the controller prefix in Swagger docs
17
10
  let { path, ...operation } = route;
18
- route.decorators.push((0, _swagger.ApiOperation)(operation));
11
+ route.decorators.push(ApiOperation(operation));
19
12
  }
20
13
 
21
14
  //# sourceMappingURL=add-swagger-operation.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/decorators/controller/add-decorators/add-swagger-operation.ts"],"sourcesContent":["import { has } from '../utils/reflect';\nimport { ControllerFactory } from '../controller.factory';\nimport type { IRoute } from '../types';\nimport { ApiOperation } from '@nestjs/swagger';\n\n/**\n * add Swagger's \\@ApiOperation()\n * @param route\n */\nexport function addSwaggerOperation(route: IRoute, factory: ControllerFactory) {\n if (has('swagger/apiOperation', factory, route)) return;\n\n // remove \"path\" or add \"prefix\" metadata to it from the constructor\n // to prevent displaying the path without the controller prefix in Swagger docs\n let { path, ...operation } = route;\n route.decorators.push(ApiOperation(operation));\n}\n"],"names":["addSwaggerOperation","route","factory","has","path","operation","decorators","push","ApiOperation"],"mappings":";;;;+BASgBA;;;eAAAA;;;yBATI;yBAGS;AAMtB,SAASA,oBAAoBC,KAAa,EAAEC,OAA0B;IAC3E,IAAIC,IAAAA,YAAG,EAAC,wBAAwBD,SAASD,QAAQ;IAEjD,oEAAoE;IACpE,+EAA+E;IAC/E,IAAI,EAAEG,IAAI,EAAE,GAAGC,WAAW,GAAGJ;IAC7BA,MAAMK,UAAU,CAACC,IAAI,CAACC,IAAAA,qBAAY,EAACH;AACrC"}
1
+ {"version":3,"sources":["../../../../../src/decorators/controller/add-decorators/add-swagger-operation.ts"],"sourcesContent":["import { has } from '../utils/reflect.js';\nimport { ControllerFactory } from '../controller.factory.js';\nimport type { IRoute } from '../types/index.js';\nimport { ApiOperation } from '@nestjs/swagger';\n\n/**\n * add Swagger's \\@ApiOperation()\n * @param route\n */\nexport function addSwaggerOperation(route: IRoute, factory: ControllerFactory) {\n if (has('swagger/apiOperation', factory, route)) return;\n\n // remove \"path\" or add \"prefix\" metadata to it from the constructor\n // to prevent displaying the path without the controller prefix in Swagger docs\n let { path, ...operation } = route;\n route.decorators.push(ApiOperation(operation));\n}\n"],"names":["has","ApiOperation","addSwaggerOperation","route","factory","path","operation","decorators","push"],"mappings":"AAAA,SAASA,GAAG,QAAQ,sBAAsB;AAG1C,SAASC,YAAY,QAAQ,kBAAkB;AAE/C;;;CAGC,GACD,OAAO,SAASC,oBAAoBC,KAAa,EAAEC,OAA0B;IAC3E,IAAIJ,IAAI,wBAAwBI,SAASD,QAAQ;IAEjD,oEAAoE;IACpE,+EAA+E;IAC/E,IAAI,EAAEE,IAAI,EAAE,GAAGC,WAAW,GAAGH;IAC7BA,MAAMI,UAAU,CAACC,IAAI,CAACP,aAAaK;AACrC"}
@@ -1,3 +1,3 @@
1
- import { ControllerFactory } from '../controller.factory';
2
- import type { IRoute } from '../types';
1
+ import { ControllerFactory } from '../controller.factory.js';
2
+ import type { IRoute } from '../types/index.js';
3
3
  export declare function addSwaggerParams(route: IRoute, factory: ControllerFactory): void;
@@ -1,17 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "addSwaggerParams", {
6
- enumerable: true,
7
- get: function() {
8
- return addSwaggerParams;
9
- }
10
- });
11
- const _reflect = require("../utils/reflect");
12
- const _swagger = require("@nestjs/swagger");
13
- function addSwaggerParams(route, factory) {
14
- if ((0, _reflect.has)('swagger/apiParameters', factory, route)) return;
1
+ import { has } from "../utils/reflect.js";
2
+ import { ApiParam, ApiQuery } from "@nestjs/swagger";
3
+ /**
4
+ * add Swagger's \@ApiQuery() and \ApiParam() for each param
5
+ * @param route
6
+ */ export function addSwaggerParams(route, factory) {
7
+ if (has('swagger/apiParameters', factory, route)) return;
15
8
  let queryParams = route.queryParams || factory.options?.queryParams;
16
9
  queryParams?.map((param)=>{
17
10
  // exclude params that doesn't match the route
@@ -42,9 +35,9 @@ function addSwaggerParams(route, factory) {
42
35
  }
43
36
  // if param.required not provided, set it to false
44
37
  param.required = !!param.required;
45
- route.decorators.push((0, _swagger.ApiQuery)(param));
38
+ route.decorators.push(ApiQuery(param));
46
39
  });
47
- route.pathParams?.map((param)=>route.decorators.push((0, _swagger.ApiParam)(param)));
40
+ route.pathParams?.map((param)=>route.decorators.push(ApiParam(param)));
48
41
  }
49
42
 
50
43
  //# sourceMappingURL=add-swagger-params.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/decorators/controller/add-decorators/add-swagger-params.ts"],"sourcesContent":["import { has } from '../utils/reflect';\nimport { ControllerFactory } from '../controller.factory';\nimport type { IRoute } from '../types';\nimport { ApiParam, ApiQuery } from '@nestjs/swagger';\n\n/**\n * add Swagger's \\@ApiQuery() and \\ApiParam() for each param\n * @param route\n */\nexport function addSwaggerParams(route: IRoute, factory: ControllerFactory) {\n if (has('swagger/apiParameters', factory, route)) return;\n\n let queryParams = route.queryParams || factory.options?.queryParams;\n queryParams?.map((param) => {\n // exclude params that doesn't match the route\n if (param.many === false && route.many) return;\n if (param.many === true && !route.many) return;\n\n if (param.httpMethods && !param.httpMethods.includes(route.httpMethod))\n return;\n\n if (!param.type && ['number', 'string'].includes(typeof param.example))\n param.type = typeof param.example;\n else if (\n param.type === 'array' ||\n (Array.isArray(param?.example) && !param.type && !param.schema)\n ) {\n param = {\n schema: {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n // add items as array to prevent sending items as v1%2Cv2 instead of v1,v2\n // converts the array into ?key=v1,v2,...\n style: 'form',\n // don't generate separate params for each item\n // i.e. ?key=v1&key=v2\n explode: false,\n ...param,\n };\n\n delete param.type;\n }\n\n // if param.required not provided, set it to false\n param.required = !!param.required;\n\n route.decorators.push(ApiQuery(param));\n });\n\n route.pathParams?.map((param) => route.decorators.push(ApiParam(param)));\n}\n"],"names":["addSwaggerParams","route","factory","has","queryParams","options","map","param","many","httpMethods","includes","httpMethod","type","example","Array","isArray","schema","items","style","explode","required","decorators","push","ApiQuery","pathParams","ApiParam"],"mappings":";;;;+BASgBA;;;eAAAA;;;yBATI;yBAGe;AAM5B,SAASA,iBAAiBC,KAAa,EAAEC,OAA0B;IACxE,IAAIC,IAAAA,YAAG,EAAC,yBAAyBD,SAASD,QAAQ;IAElD,IAAIG,cAAcH,MAAMG,WAAW,IAAIF,QAAQG,OAAO,EAAED;IACxDA,aAAaE,IAAI,CAACC;QAChB,8CAA8C;QAC9C,IAAIA,MAAMC,IAAI,KAAK,SAASP,MAAMO,IAAI,EAAE;QACxC,IAAID,MAAMC,IAAI,KAAK,QAAQ,CAACP,MAAMO,IAAI,EAAE;QAExC,IAAID,MAAME,WAAW,IAAI,CAACF,MAAME,WAAW,CAACC,QAAQ,CAACT,MAAMU,UAAU,GACnE;QAEF,IAAI,CAACJ,MAAMK,IAAI,IAAI;YAAC;YAAU;SAAS,CAACF,QAAQ,CAAC,OAAOH,MAAMM,OAAO,GACnEN,MAAMK,IAAI,GAAG,OAAOL,MAAMM,OAAO;aAC9B,IACHN,MAAMK,IAAI,KAAK,WACdE,MAAMC,OAAO,CAACR,OAAOM,YAAY,CAACN,MAAMK,IAAI,IAAI,CAACL,MAAMS,MAAM,EAC9D;YACAT,QAAQ;gBACNS,QAAQ;oBACNJ,MAAM;oBACNK,OAAO;wBACLL,MAAM;oBACR;gBACF;gBACA,0EAA0E;gBAC1E,yCAAyC;gBACzCM,OAAO;gBACP,+CAA+C;gBAC/C,sBAAsB;gBACtBC,SAAS;gBACT,GAAGZ,KAAK;YACV;YAEA,OAAOA,MAAMK,IAAI;QACnB;QAEA,kDAAkD;QAClDL,MAAMa,QAAQ,GAAG,CAAC,CAACb,MAAMa,QAAQ;QAEjCnB,MAAMoB,UAAU,CAACC,IAAI,CAACC,IAAAA,iBAAQ,EAAChB;IACjC;IAEAN,MAAMuB,UAAU,EAAElB,IAAI,CAACC,QAAUN,MAAMoB,UAAU,CAACC,IAAI,CAACG,IAAAA,iBAAQ,EAAClB;AAClE"}
1
+ {"version":3,"sources":["../../../../../src/decorators/controller/add-decorators/add-swagger-params.ts"],"sourcesContent":["import { has } from '../utils/reflect.js';\nimport { ControllerFactory } from '../controller.factory.js';\nimport type { IRoute } from '../types/index.js';\nimport { ApiParam, ApiQuery } from '@nestjs/swagger';\n\n/**\n * add Swagger's \\@ApiQuery() and \\ApiParam() for each param\n * @param route\n */\nexport function addSwaggerParams(route: IRoute, factory: ControllerFactory) {\n if (has('swagger/apiParameters', factory, route)) return;\n\n let queryParams = route.queryParams || factory.options?.queryParams;\n queryParams?.map((param) => {\n // exclude params that doesn't match the route\n if (param.many === false && route.many) return;\n if (param.many === true && !route.many) return;\n\n if (param.httpMethods && !param.httpMethods.includes(route.httpMethod))\n return;\n\n if (!param.type && ['number', 'string'].includes(typeof param.example))\n param.type = typeof param.example;\n else if (\n param.type === 'array' ||\n (Array.isArray(param?.example) && !param.type && !param.schema)\n ) {\n param = {\n schema: {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n // add items as array to prevent sending items as v1%2Cv2 instead of v1,v2\n // converts the array into ?key=v1,v2,...\n style: 'form',\n // don't generate separate params for each item\n // i.e. ?key=v1&key=v2\n explode: false,\n ...param,\n };\n\n delete param.type;\n }\n\n // if param.required not provided, set it to false\n param.required = !!param.required;\n\n route.decorators.push(ApiQuery(param));\n });\n\n route.pathParams?.map((param) => route.decorators.push(ApiParam(param)));\n}\n"],"names":["has","ApiParam","ApiQuery","addSwaggerParams","route","factory","queryParams","options","map","param","many","httpMethods","includes","httpMethod","type","example","Array","isArray","schema","items","style","explode","required","decorators","push","pathParams"],"mappings":"AAAA,SAASA,GAAG,QAAQ,sBAAsB;AAG1C,SAASC,QAAQ,EAAEC,QAAQ,QAAQ,kBAAkB;AAErD;;;CAGC,GACD,OAAO,SAASC,iBAAiBC,KAAa,EAAEC,OAA0B;IACxE,IAAIL,IAAI,yBAAyBK,SAASD,QAAQ;IAElD,IAAIE,cAAcF,MAAME,WAAW,IAAID,QAAQE,OAAO,EAAED;IACxDA,aAAaE,IAAI,CAACC;QAChB,8CAA8C;QAC9C,IAAIA,MAAMC,IAAI,KAAK,SAASN,MAAMM,IAAI,EAAE;QACxC,IAAID,MAAMC,IAAI,KAAK,QAAQ,CAACN,MAAMM,IAAI,EAAE;QAExC,IAAID,MAAME,WAAW,IAAI,CAACF,MAAME,WAAW,CAACC,QAAQ,CAACR,MAAMS,UAAU,GACnE;QAEF,IAAI,CAACJ,MAAMK,IAAI,IAAI;YAAC;YAAU;SAAS,CAACF,QAAQ,CAAC,OAAOH,MAAMM,OAAO,GACnEN,MAAMK,IAAI,GAAG,OAAOL,MAAMM,OAAO;aAC9B,IACHN,MAAMK,IAAI,KAAK,WACdE,MAAMC,OAAO,CAACR,OAAOM,YAAY,CAACN,MAAMK,IAAI,IAAI,CAACL,MAAMS,MAAM,EAC9D;YACAT,QAAQ;gBACNS,QAAQ;oBACNJ,MAAM;oBACNK,OAAO;wBACLL,MAAM;oBACR;gBACF;gBACA,0EAA0E;gBAC1E,yCAAyC;gBACzCM,OAAO;gBACP,+CAA+C;gBAC/C,sBAAsB;gBACtBC,SAAS;gBACT,GAAGZ,KAAK;YACV;YAEA,OAAOA,MAAMK,IAAI;QACnB;QAEA,kDAAkD;QAClDL,MAAMa,QAAQ,GAAG,CAAC,CAACb,MAAMa,QAAQ;QAEjClB,MAAMmB,UAAU,CAACC,IAAI,CAACtB,SAASO;IACjC;IAEAL,MAAMqB,UAAU,EAAEjB,IAAI,CAACC,QAAUL,MAAMmB,UAAU,CAACC,IAAI,CAACvB,SAASQ;AAClE"}
@@ -1,3 +1,3 @@
1
- import { ControllerFactory } from '../controller.factory';
2
- import type { IRoute } from '../types';
1
+ import { ControllerFactory } from '../controller.factory.js';
2
+ import type { IRoute } from '../types/index.js';
3
3
  export declare function addSwaggerResponse(route: IRoute, factory: ControllerFactory): void;
@@ -1,33 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "addSwaggerResponse", {
6
- enumerable: true,
7
- get: function() {
8
- return addSwaggerResponse;
9
- }
10
- });
11
- const _reflect = require("../utils/reflect");
12
- const _common = require("@nestjs/common");
13
- const _swagger = require("@nestjs/swagger");
14
- function addSwaggerResponse(route, factory) {
15
- if ((0, _reflect.has)('swagger/apiResponse', factory, route)) return;
1
+ import { has } from "../utils/reflect.js";
2
+ import { HttpStatus } from "@nestjs/common";
3
+ import { ApiResponse } from "@nestjs/swagger";
4
+ export function addSwaggerResponse(route, factory) {
5
+ if (has('swagger/apiResponse', factory, route)) return;
16
6
  let responseModel = route.responseModel || route.model || factory.options?.model;
17
7
  // todo: add other status responses
18
8
  // todo: add options.responseModels[status] -> example: response models for 200, 401, 500, ...
19
- route.decorators.push((0, _swagger.ApiResponse)({
20
- status: _common.HttpStatus.OK,
9
+ route.decorators.push(ApiResponse({
10
+ status: HttpStatus.OK,
21
11
  type: route.many ? [
22
12
  responseModel
23
13
  ] : responseModel
24
- }), (0, _swagger.ApiResponse)({
25
- status: _common.HttpStatus.INTERNAL_SERVER_ERROR,
14
+ }), ApiResponse({
15
+ status: HttpStatus.INTERNAL_SERVER_ERROR,
26
16
  type: route.errorResponseModel || factory.options?.errorResponseModel
27
17
  }), ...[
28
18
  ...factory.options?.responseModels || [],
29
19
  ...route.responseModels || []
30
- ].map((model)=>(0, _swagger.ApiResponse)(model)));
20
+ ].map((model)=>ApiResponse(model)));
31
21
  }
32
22
 
33
23
  //# sourceMappingURL=add-swagger-response.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/decorators/controller/add-decorators/add-swagger-response.ts"],"sourcesContent":["import { has } from '../utils/reflect';\nimport { ControllerFactory } from '../controller.factory';\nimport type { IRoute } from '../types';\nimport { HttpStatus } from '@nestjs/common';\nimport { ApiResponse } from '@nestjs/swagger';\n\nexport function addSwaggerResponse(route: IRoute, factory: ControllerFactory) {\n if (has('swagger/apiResponse', factory, route)) return;\n\n let responseModel =\n route.responseModel || route.model || factory.options?.model;\n\n // todo: add other status responses\n // todo: add options.responseModels[status] -> example: response models for 200, 401, 500, ...\n route.decorators.push(\n ApiResponse({\n status: HttpStatus.OK,\n type: route.many ? [responseModel] : responseModel,\n }),\n ApiResponse({\n status: HttpStatus.INTERNAL_SERVER_ERROR,\n type: route.errorResponseModel || factory.options?.errorResponseModel,\n }),\n ...[\n ...(factory.options?.responseModels || []),\n ...(route.responseModels || []),\n ].map((model) => ApiResponse(model)),\n );\n}\n"],"names":["addSwaggerResponse","route","factory","has","responseModel","model","options","decorators","push","ApiResponse","status","HttpStatus","OK","type","many","INTERNAL_SERVER_ERROR","errorResponseModel","responseModels","map"],"mappings":";;;;+BAMgBA;;;eAAAA;;;yBANI;wBAGO;yBACC;AAErB,SAASA,mBAAmBC,KAAa,EAAEC,OAA0B;IAC1E,IAAIC,IAAAA,YAAG,EAAC,uBAAuBD,SAASD,QAAQ;IAEhD,IAAIG,gBACFH,MAAMG,aAAa,IAAIH,MAAMI,KAAK,IAAIH,QAAQI,OAAO,EAAED;IAEzD,mCAAmC;IACnC,8FAA8F;IAC9FJ,MAAMM,UAAU,CAACC,IAAI,CACnBC,IAAAA,oBAAW,EAAC;QACVC,QAAQC,kBAAU,CAACC,EAAE;QACrBC,MAAMZ,MAAMa,IAAI,GAAG;YAACV;SAAc,GAAGA;IACvC,IACAK,IAAAA,oBAAW,EAAC;QACVC,QAAQC,kBAAU,CAACI,qBAAqB;QACxCF,MAAMZ,MAAMe,kBAAkB,IAAId,QAAQI,OAAO,EAAEU;IACrD,OACG;WACGd,QAAQI,OAAO,EAAEW,kBAAkB,EAAE;WACrChB,MAAMgB,cAAc,IAAI,EAAE;KAC/B,CAACC,GAAG,CAAC,CAACb,QAAUI,IAAAA,oBAAW,EAACJ;AAEjC"}
1
+ {"version":3,"sources":["../../../../../src/decorators/controller/add-decorators/add-swagger-response.ts"],"sourcesContent":["import { has } from '../utils/reflect.js';\nimport { ControllerFactory } from '../controller.factory.js';\nimport type { IRoute } from '../types/index.js';\nimport { HttpStatus } from '@nestjs/common';\nimport { ApiResponse } from '@nestjs/swagger';\n\nexport function addSwaggerResponse(route: IRoute, factory: ControllerFactory) {\n if (has('swagger/apiResponse', factory, route)) return;\n\n let responseModel =\n route.responseModel || route.model || factory.options?.model;\n\n // todo: add other status responses\n // todo: add options.responseModels[status] -> example: response models for 200, 401, 500, ...\n route.decorators.push(\n ApiResponse({\n status: HttpStatus.OK,\n type: route.many ? [responseModel] : responseModel,\n }),\n ApiResponse({\n status: HttpStatus.INTERNAL_SERVER_ERROR,\n type: route.errorResponseModel || factory.options?.errorResponseModel,\n }),\n ...[\n ...(factory.options?.responseModels || []),\n ...(route.responseModels || []),\n ].map((model) => ApiResponse(model)),\n );\n}\n"],"names":["has","HttpStatus","ApiResponse","addSwaggerResponse","route","factory","responseModel","model","options","decorators","push","status","OK","type","many","INTERNAL_SERVER_ERROR","errorResponseModel","responseModels","map"],"mappings":"AAAA,SAASA,GAAG,QAAQ,sBAAsB;AAG1C,SAASC,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,OAAO,SAASC,mBAAmBC,KAAa,EAAEC,OAA0B;IAC1E,IAAIL,IAAI,uBAAuBK,SAASD,QAAQ;IAEhD,IAAIE,gBACFF,MAAME,aAAa,IAAIF,MAAMG,KAAK,IAAIF,QAAQG,OAAO,EAAED;IAEzD,mCAAmC;IACnC,8FAA8F;IAC9FH,MAAMK,UAAU,CAACC,IAAI,CACnBR,YAAY;QACVS,QAAQV,WAAWW,EAAE;QACrBC,MAAMT,MAAMU,IAAI,GAAG;YAACR;SAAc,GAAGA;IACvC,IACAJ,YAAY;QACVS,QAAQV,WAAWc,qBAAqB;QACxCF,MAAMT,MAAMY,kBAAkB,IAAIX,QAAQG,OAAO,EAAEQ;IACrD,OACG;WACGX,QAAQG,OAAO,EAAES,kBAAkB,EAAE;WACrCb,MAAMa,cAAc,IAAI,EAAE;KAC/B,CAACC,GAAG,CAAC,CAACX,QAAUL,YAAYK;AAEjC"}
@@ -1,2 +1,2 @@
1
- import type { ControllerOptions, InitControllerOptions } from './types';
1
+ import type { ControllerOptions, InitControllerOptions } from './types/index.js';
2
2
  export declare function Controller(options?: InitControllerOptions | ((defaultOptions: ControllerOptions) => ControllerOptions)): ClassDecorator;
@@ -1,17 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "Controller", {
6
- enumerable: true,
7
- get: function() {
8
- return Controller;
9
- }
10
- });
11
- const _controllerfactory = require("./controller.factory");
12
- function Controller(options) {
1
+ import { ControllerFactory } from "./controller.factory.js";
2
+ /**
3
+ * Mark a class as a controller and automatically generate its crud routes, and add swagger decorators
4
+ * This decorator must be placed before other decorators to avoid overriding their values
5
+ * otherwise, you can disable any functionality by setting it to `null`
6
+ * for instance `@ApiTags("users"); @Controller("my-users")`
7
+ * may cause that the value of `ApiTags` to be replaced
8
+ * either place `@Controller()` first, or use `@Controller({tags: null})`
9
+ * @param options
10
+ * @returns
11
+ */ export function Controller(options) {
13
12
  return (target)=>{
14
- new _controllerfactory.ControllerFactory(target, options);
13
+ new ControllerFactory(target, options);
15
14
  };
16
15
  }
17
16
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/decorators/controller/controller.decorator.ts"],"sourcesContent":["import { ControllerFactory } from './controller.factory';\nimport type { ControllerOptions, InitControllerOptions } from './types';\n\n/**\n * Mark a class as a controller and automatically generate its crud routes, and add swagger decorators\n * This decorator must be placed before other decorators to avoid overriding their values\n * otherwise, you can disable any functionality by setting it to `null`\n * for instance `@ApiTags(\"users\"); @Controller(\"my-users\")`\n * may cause that the value of `ApiTags` to be replaced\n * either place `@Controller()` first, or use `@Controller({tags: null})`\n * @param options\n * @returns\n */\nexport function Controller(\n options?:\n | InitControllerOptions\n | ((defaultOptions: ControllerOptions) => ControllerOptions),\n): ClassDecorator {\n return (target: Function) => {\n new ControllerFactory(target, options);\n };\n}\n"],"names":["Controller","options","target","ControllerFactory"],"mappings":";;;;+BAagBA;;;eAAAA;;;mCAbkB;AAa3B,SAASA,WACdC,OAE8D;IAE9D,OAAO,CAACC;QACN,IAAIC,oCAAiB,CAACD,QAAQD;IAChC;AACF"}
1
+ {"version":3,"sources":["../../../../src/decorators/controller/controller.decorator.ts"],"sourcesContent":["import { ControllerFactory } from './controller.factory.js';\nimport type {\n ControllerOptions,\n InitControllerOptions,\n} from './types/index.js';\n\n/**\n * Mark a class as a controller and automatically generate its crud routes, and add swagger decorators\n * This decorator must be placed before other decorators to avoid overriding their values\n * otherwise, you can disable any functionality by setting it to `null`\n * for instance `@ApiTags(\"users\"); @Controller(\"my-users\")`\n * may cause that the value of `ApiTags` to be replaced\n * either place `@Controller()` first, or use `@Controller({tags: null})`\n * @param options\n * @returns\n */\nexport function Controller(\n options?:\n | InitControllerOptions\n | ((defaultOptions: ControllerOptions) => ControllerOptions),\n): ClassDecorator {\n return (target: Function) => {\n new ControllerFactory(target, options);\n };\n}\n"],"names":["ControllerFactory","Controller","options","target"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,0BAA0B;AAM5D;;;;;;;;;CASC,GACD,OAAO,SAASC,WACdC,OAE8D;IAE9D,OAAO,CAACC;QACN,IAAIH,kBAAkBG,QAAQD;IAChC;AACF"}
@@ -1,4 +1,4 @@
1
- import type { ControllerOptions, InitControllerOptions, InitRoute } from './types';
1
+ import type { ControllerOptions, InitControllerOptions, InitRoute } from './types/index.js';
2
2
  export declare class ControllerFactory {
3
3
  controller: Function;
4
4
  options: ControllerOptions;
@@ -1,28 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "ControllerFactory", {
6
- enumerable: true,
7
- get: function() {
8
- return ControllerFactory;
1
+ import { Body, Param, Query, Req } from "@nestjs/common";
2
+ import { addHttpMethod } from "./add-decorators/add-http-method.js";
3
+ import { addSwaggerParams } from "./add-decorators/add-swagger-params.js";
4
+ import { routeHandler } from "./route-handler.js";
5
+ import { addSwaggerOperation } from "./add-decorators/add-swagger-operation.js";
6
+ import { addSwaggerBody } from "./add-decorators/add-swagger-body.js";
7
+ import { addSwaggerResponse } from "./add-decorators/add-swagger-response.js";
8
+ import { QueryInterceptor } from "./interceptors/query.interceptor.js";
9
+ import { defaultOptions } from "./default-options.js";
10
+ import { mergeOptions } from "./utils/merge-options.js";
11
+ import { addControllerTags } from "./add-decorators/add-controller-tags.js";
12
+ import { merge, mergeByKey, removeValues } from "@impactor/javascript";
13
+ import { applyDecorators } from "./utils/reflect.js";
14
+ import { addControllerPath } from "./add-decorators/add-controller-path.js";
15
+ import { toKebabCase } from "@impactor/javascript";
16
+ // import 'reflect-metadata';
17
+ export class ControllerFactory {
18
+ constructor(controller, // if options is provided as a function, the consumer has to maintain the merge strategy
19
+ options){
20
+ this.controller = controller;
21
+ this.decorators = [];
22
+ this.options = typeof options === 'function' ? // we'll need to call it again after receiving the user options to adjust its routes
23
+ options(this.adjustRoutes(defaultOptions)) : mergeOptions(defaultOptions, options || {});
24
+ this.options = this.adjustRoutes({
25
+ ...this.options,
26
+ // todo: merge matched routes instead of overriding them
27
+ // i.e. routes with the same methodName, httpMethod, and path
28
+ routes: [
29
+ ...this.options.routes || [],
30
+ ...this.getExistingMethods()
31
+ ]
32
+ });
33
+ // if path is not provided, use the class name, without the suffix `Controller`,
34
+ // after converting it into url-friendly kebab-case
35
+ if (this.options.path === undefined) {
36
+ this.options.path = toKebabCase(this.controller.name.replace(/Controller$/, ''));
37
+ }
38
+ this.createRoutes();
39
+ this.mergeRoutes();
40
+ addControllerPath(this);
41
+ addControllerTags(this);
42
+ applyDecorators(this);
9
43
  }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _addhttpmethod = require("./add-decorators/add-http-method");
13
- const _addswaggerparams = require("./add-decorators/add-swagger-params");
14
- const _routehandler = require("./route-handler");
15
- const _addswaggeroperation = require("./add-decorators/add-swagger-operation");
16
- const _addswaggerbody = require("./add-decorators/add-swagger-body");
17
- const _addswaggerresponse = require("./add-decorators/add-swagger-response");
18
- const _queryinterceptor = require("./interceptors/query.interceptor");
19
- const _defaultoptions = require("./default-options");
20
- const _mergeoptions = require("./utils/merge-options");
21
- const _addcontrollertags = require("./add-decorators/add-controller-tags");
22
- const _javascript = require("@impactor/javascript");
23
- const _reflect = require("./utils/reflect");
24
- const _addcontrollerpath = require("./add-decorators/add-controller-path");
25
- let ControllerFactory = class ControllerFactory {
26
44
  getExistingMethods() {
27
45
  let proto = this.controller.prototype;
28
46
  return Reflect.ownKeys(proto).filter((key)=>typeof proto[key] === 'function')// convert symbol to string
@@ -113,10 +131,10 @@ let ControllerFactory = class ControllerFactory {
113
131
  // todo: we may need to exclude other keys that have a class value such as errorResponseModel
114
132
  let { routes, model, ...otherOptions } = opts;
115
133
  // todo: use merge()?
116
- route = (0, _javascript.merge)([
134
+ route = merge([
117
135
  otherOptions || {},
118
136
  route || {}
119
- ].map((el)=>(0, _javascript.removeValues)(el, [
137
+ ].map((el)=>removeValues(el, [
120
138
  undefined,
121
139
  null
122
140
  ])));
@@ -139,7 +157,7 @@ let ControllerFactory = class ControllerFactory {
139
157
  // opts[key as keyof typeof opts] || [];
140
158
  // }
141
159
  // });
142
- route.interceptors.push(new _queryinterceptor.QueryInterceptor((0, _javascript.merge)([
160
+ route.interceptors.push(new QueryInterceptor(merge([
143
161
  opts.query || {},
144
162
  route.query || {}
145
163
  ])));
@@ -155,22 +173,22 @@ let ControllerFactory = class ControllerFactory {
155
173
  // create a route method and add it to the controller
156
174
  // todo: use interceptor to create ParsedRequest
157
175
  if (!controller[route.methodName]) {
158
- controller[route.methodName] = (0, _routehandler.routeHandler)(route, this);
176
+ controller[route.methodName] = routeHandler(route, this);
159
177
  // inject the required params
160
178
  // similar to patchOne(@Req() req: Request, @Query() query, @Body() dto: MyEntity, @Param("id") id:string)
161
179
  // we can get other info such as body and params from req
162
180
  // without the need to inject @Body() and @Query()
163
181
  // todo: route.primary || getPrimaryKeyFromEntity(opts.model) || "id"
164
182
  let paramKey = route.primaryKey || 'id';
165
- (0, _common.Req)()(this.controller.prototype, route.methodName, 0);
166
- (0, _common.Query)()(this.controller.prototype, route.methodName, 1);
183
+ Req()(this.controller.prototype, route.methodName, 0);
184
+ Query()(this.controller.prototype, route.methodName, 1);
167
185
  if ([
168
186
  'GET',
169
187
  'DELETE'
170
188
  ].includes(route.httpMethod) && !route.many) {
171
- (0, _common.Param)(paramKey)(this.controller.prototype, route.methodName, 2);
189
+ Param(paramKey)(this.controller.prototype, route.methodName, 2);
172
190
  } else if (route.httpMethod === 'POST') {
173
- (0, _common.Body)()(this.controller.prototype, route.methodName, 2);
191
+ Body()(this.controller.prototype, route.methodName, 2);
174
192
  // add 'design:paramtypes' to define the types of each param
175
193
  // for instance, the param `@Body()` should be defined as `this.options.model`,
176
194
  // so `ValidationPipe()` can work fine.
@@ -187,7 +205,7 @@ let ControllerFactory = class ControllerFactory {
187
205
  'PATCH',
188
206
  'PUT'
189
207
  ].includes(route.httpMethod)) {
190
- (0, _common.Body)()(this.controller.prototype, route.methodName, 2);
208
+ Body()(this.controller.prototype, route.methodName, 2);
191
209
  if (route.many) {
192
210
  Reflect.defineMetadata('design:paramtypes', [
193
211
  Object,
@@ -199,7 +217,7 @@ let ControllerFactory = class ControllerFactory {
199
217
  // todo: accept list of pipes for each param -> `Param(paramName, ...pipes)(...)`
200
218
  // to accept only string or number -> add a validation in routerHandler i.e. `if(! typeof params[paramKey]) throw ...`,
201
219
  // as class-validator will not validate its type because it is not a DTO i.e. `getOne(@param() params: ParamsDTO)`
202
- (0, _common.Param)(paramKey)(this.controller.prototype, route.methodName, 3);
220
+ Param(paramKey)(this.controller.prototype, route.methodName, 3);
203
221
  Reflect.defineMetadata('design:paramtypes', [
204
222
  Object,
205
223
  Object,
@@ -216,46 +234,20 @@ let ControllerFactory = class ControllerFactory {
216
234
  // if the method is not listed and doesn't has @Route(), the annotations will not be added
217
235
  // if no http decorator already applied such as @GET()
218
236
  // when adding @Get(), nest adds "method" and "path" metadata
219
- (0, _addhttpmethod.addHttpMethod)(route, this);
220
- (0, _addswaggeroperation.addSwaggerOperation)(route, this);
221
- (0, _addswaggerparams.addSwaggerParams)(route, this);
222
- (0, _addswaggerbody.addSwaggerBody)(route, this);
223
- (0, _addswaggerresponse.addSwaggerResponse)(route, this);
237
+ addHttpMethod(route, this);
238
+ addSwaggerOperation(route, this);
239
+ addSwaggerParams(route, this);
240
+ addSwaggerBody(route, this);
241
+ addSwaggerResponse(route, this);
224
242
  }
225
243
  }
226
244
  /**
227
245
  * Merges routes that share the same methodName.
228
246
  */ mergeRoutes() {
229
- this.options.routes = (0, _javascript.mergeByKey)(this.options.routes, 'methodName', {
247
+ this.options.routes = mergeByKey(this.options.routes, 'methodName', {
230
248
  deep: true
231
249
  });
232
250
  }
233
- constructor(controller, // if options is provided as a function, the consumer has to maintain the merge strategy
234
- options){
235
- this.controller = controller;
236
- this.decorators = [];
237
- this.options = typeof options === 'function' ? // we'll need to call it again after receiving the user options to adjust its routes
238
- options(this.adjustRoutes(_defaultoptions.defaultOptions)) : (0, _mergeoptions.mergeOptions)(_defaultoptions.defaultOptions, options || {});
239
- this.options = this.adjustRoutes({
240
- ...this.options,
241
- // todo: merge matched routes instead of overriding them
242
- // i.e. routes with the same methodName, httpMethod, and path
243
- routes: [
244
- ...this.options.routes || [],
245
- ...this.getExistingMethods()
246
- ]
247
- });
248
- // if path is not provided, use the class name, without the suffix `Controller`,
249
- // after converting it into url-friendly kebab-case
250
- if (this.options.path === undefined) {
251
- this.options.path = (0, _javascript.toKebabCase)(this.controller.name.replace(/Controller$/, ''));
252
- }
253
- this.createRoutes();
254
- this.mergeRoutes();
255
- (0, _addcontrollerpath.addControllerPath)(this);
256
- (0, _addcontrollertags.addControllerTags)(this);
257
- (0, _reflect.applyDecorators)(this);
258
- }
259
- };
251
+ }
260
252
 
261
253
  //# sourceMappingURL=controller.factory.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/decorators/controller/controller.factory.ts"],"sourcesContent":["import { Body, Param, Query, Req } from '@nestjs/common';\nimport type {\n ControllerOptions,\n HttpMethod,\n InitControllerOptions,\n InitRoute,\n IRoute,\n} from './types';\nimport { addHttpMethod } from './add-decorators/add-http-method';\nimport { addSwaggerParams } from './add-decorators/add-swagger-params';\nimport { routeHandler } from './route-handler';\nimport { addSwaggerOperation } from './add-decorators/add-swagger-operation';\nimport { addSwaggerBody } from './add-decorators/add-swagger-body';\nimport { addSwaggerResponse } from './add-decorators/add-swagger-response';\nimport { QueryInterceptor } from './interceptors/query.interceptor';\nimport { defaultOptions } from './default-options';\nimport { mergeOptions } from './utils/merge-options';\nimport { addControllerTags } from './add-decorators/add-controller-tags';\nimport { merge, mergeByKey, removeValues } from '@impactor/javascript';\nimport { applyDecorators } from './utils/reflect';\nimport { addControllerPath } from './add-decorators/add-controller-path';\nimport { toKebabCase } from '@impactor/javascript';\n// import 'reflect-metadata';\n\nexport class ControllerFactory {\n public options: ControllerOptions;\n public decorators: ClassDecorator[] = [];\n\n constructor(\n public controller: Function,\n // if options is provided as a function, the consumer has to maintain the merge strategy\n options?:\n | InitControllerOptions\n | ((defaultOptions: ControllerOptions) => ControllerOptions),\n ) {\n this.options =\n typeof options === 'function'\n ? // The consumer should receive the adjusted routes, so we need to call `adjustRoutes()` here\n // we'll need to call it again after receiving the user options to adjust its routes\n options(this.adjustRoutes(defaultOptions))\n : mergeOptions(defaultOptions, options || {});\n\n this.options = this.adjustRoutes({\n ...this.options,\n // todo: merge matched routes instead of overriding them\n // i.e. routes with the same methodName, httpMethod, and path\n routes: [...(this.options.routes || []), ...this.getExistingMethods()],\n });\n\n // if path is not provided, use the class name, without the suffix `Controller`,\n // after converting it into url-friendly kebab-case\n if (this.options.path === undefined) {\n this.options.path = toKebabCase(\n this.controller.name.replace(/Controller$/, ''),\n );\n }\n\n this.createRoutes();\n this.mergeRoutes();\n\n addControllerPath(this);\n addControllerTags(this);\n\n applyDecorators(this);\n }\n\n getExistingMethods() {\n let proto = this.controller.prototype;\n\n return (\n Reflect.ownKeys(proto)\n .filter((key) => typeof proto[key] === 'function')\n // convert symbol to string\n .map(String)\n .filter(\n (key) =>\n key !== 'constructor' &&\n // a method can be excluded from being handling by this factory, by adding `@Route(false)`\n Reflect.getMetadata('routeOptions', proto, key) !== false &&\n // skip methods that are already included in routes[]\n !this.options.routes?.some((route) => route.methodName === key),\n )\n // convert method to InitRoute{}\n .map((methodName) => {\n let routeOptions: InitRoute = Reflect.getMetadata(\n 'routeOptions',\n proto,\n methodName,\n );\n\n return {\n methodName,\n path: Reflect.getMetadata('path', proto[methodName]),\n ...routeOptions,\n } as InitRoute;\n })\n );\n }\n /**\n * add all missing props to each route, uch as the HTTP method, primaryKey, and operationId .\n * @param opts\n * @returns\n */\n adjustRoutes(opts: InitControllerOptions = this.options): ControllerOptions {\n return <ControllerOptions>{\n ...opts,\n routes: opts?.routes?.map((el) => {\n let route = { ...el };\n\n // NestJs request methods\n let requestMethods = [\n 'GET',\n 'POST',\n 'PUT',\n 'DELETE',\n 'PATCH',\n 'ALL',\n 'OPTIONS',\n 'HEAD',\n 'SEARCH',\n ];\n // capitalize route.httpMethod to much the HttpMethod type\n route.httpMethod = <HttpMethod>(\n (typeof route.httpMethod === 'number'\n ? requestMethods[route.httpMethod]\n : (<HttpMethod>route.httpMethod)?.toUpperCase() || 'GET')\n );\n route.primaryKey = route.primaryKey || opts.primaryKey || 'id';\n\n // generate the default methodName from path\n // examples\n // - {path: \"users/:id\"} -> \"getOneUserById\"\n // - {path: \"users/:userId/profiles/:profileId/posts\", many:true} -> \"getManyUsersByUserIdProfilesProfileIdPosts\"\n route.methodName =\n route.methodName ||\n route.httpMethod.toLowerCase() +\n (route.httpMethod === 'POST' ? '' : route.many ? 'Many' : 'One');\n\n route.operationId =\n route.operationId ||\n `${this.controller.name}_${String(route.methodName)}`;\n\n if (!route.path) {\n // for \"*One()\" operations, add /:id path param\n // example: GET /users/:id\n route.path =\n route.many || ['POST'].includes(route.httpMethod)\n ? '/'\n : `/:${route.primaryKey}`;\n }\n\n route.pathParams = route.pathParams\n ? route.pathParams.map((param) =>\n typeof param === 'string'\n ? { name: param, schema: { type: 'string' }, required: true }\n : param,\n )\n : // generate path params from route.path\n // matches `:id`, `/:id` and `other/:id/:userId`\n [...route.path.matchAll(/^\\/?:([^/]+)/g)].map((match) => ({\n name: match[1],\n schema: { type: 'string' },\n required: true,\n }));\n\n // todo: generate the corresponding service methods\n // +route.path\n // // remove the leading \"/\"\n // .replace(/^\\//, '')\n // .replace(/^:/,'By')\n // // replace \"/:id\" with \"ById\"\n // .replaceAll(/\\/:/g, '/By')\n // .split('/')\n // // convert parts to camel case\n // // example: \"users/profiles\" -> \"usersProfiles\"\n // .map((el, idx) =>\n // idx === 0 ? el : el.charAt(0).toUpperCase() + el.slice(1),\n // )\n // .join('');\n\n // override options per route\n // for example: route.primaryKey = route.primaryKey || opts.primaryKey\n // when opts.model is a class that extends another class, an exception is thrown `OtherClass is not defined`\n // todo: we may need to exclude other keys that have a class value such as errorResponseModel\n let { routes, model, ...otherOptions } = opts;\n // todo: use merge()?\n route = <IRoute>(\n merge(\n [otherOptions || {}, route || {}].map((el) =>\n removeValues(el, [undefined, null]),\n ),\n )\n );\n\n // merge arrays\n // todo: use mergeArray()?\n ['decorators', 'interceptors'].map((key) => {\n route[key as keyof typeof route] = [\n ...(opts[key as keyof typeof opts] || []),\n ...(route[key as keyof typeof route] || []),\n ];\n });\n\n // merge empty arrays\n // for example if route.interceptors=[] but opts.interceptors has values, opts.interceptors is used\n // Object.keys(opts).map((key) => {\n // if (Array.isArray(key) && !route[key as keyof typeof route]?.length) {\n // route[key as keyof typeof route] =\n // opts[key as keyof typeof opts] || [];\n // }\n // });\n\n route.interceptors!.push(\n new QueryInterceptor(\n merge([opts.query || {}, route.query || {}]) as {\n [key: string]: any;\n },\n ),\n );\n\n return route;\n }),\n };\n }\n\n /**\n * add options.routes[] as class methods\n */\n createRoutes() {\n let routes = this.options.routes?.filter(\n (route) => route.disabled === undefined || !route.disabled,\n ),\n controller = this.controller.prototype;\n\n for (let route of routes) {\n // create a route method and add it to the controller\n // todo: use interceptor to create ParsedRequest\n if (!controller[route.methodName]) {\n controller[route.methodName] = routeHandler(route, this);\n\n // inject the required params\n // similar to patchOne(@Req() req: Request, @Query() query, @Body() dto: MyEntity, @Param(\"id\") id:string)\n // we can get other info such as body and params from req\n // without the need to inject @Body() and @Query()\n // todo: route.primary || getPrimaryKeyFromEntity(opts.model) || \"id\"\n let paramKey = route.primaryKey || 'id';\n Req()(this.controller.prototype, route.methodName, 0);\n Query()(this.controller.prototype, route.methodName, 1);\n\n if (['GET', 'DELETE'].includes(route.httpMethod) && !route.many) {\n Param(paramKey)(this.controller.prototype, route.methodName, 2);\n } else if (route.httpMethod === 'POST') {\n Body()(this.controller.prototype, route.methodName, 2);\n // add 'design:paramtypes' to define the types of each param\n // for instance, the param `@Body()` should be defined as `this.options.model`,\n // so `ValidationPipe()` can work fine.\n // without it, wrong body will bypass class-validator and class-transformer decorators such as `@IsString()`\n Reflect.defineMetadata(\n 'design:paramtypes',\n // 0: `@Req() req: Request`\n // 1: `@Query() query: any` -> todo: add type definition\n // 2: `@Body() body: Model`\n [Request, Object, this.options.model],\n this.controller.prototype,\n route.methodName,\n );\n } else if (['PATCH', 'PUT'].includes(route.httpMethod)) {\n Body()(this.controller.prototype, route.methodName, 2);\n if (route.many) {\n Reflect.defineMetadata(\n 'design:paramtypes',\n [Object, Object, this.options.model],\n this.controller.prototype,\n route.methodName,\n );\n } else {\n // todo: or use `Param()` without `paramKey`, then use it like param[paramKey]\n // todo: accept list of pipes for each param -> `Param(paramName, ...pipes)(...)`\n // to accept only string or number -> add a validation in routerHandler i.e. `if(! typeof params[paramKey]) throw ...`,\n // as class-validator will not validate its type because it is not a DTO i.e. `getOne(@param() params: ParamsDTO)`\n Param(paramKey)(this.controller.prototype, route.methodName, 3);\n Reflect.defineMetadata(\n 'design:paramtypes',\n [Object, Object, this.options.model, Object],\n this.controller.prototype,\n route.methodName,\n );\n }\n }\n }\n\n // add decorators to the route\n // annotations are added only if:\n // - the method listed in this.options.routes[] and doesn't has @Route(false)\n // - the method is not listed and has @Route(options?)\n // if the method is not listed and doesn't has @Route(), the annotations will not be added\n // if no http decorator already applied such as @GET()\n // when adding @Get(), nest adds \"method\" and \"path\" metadata\n addHttpMethod(route, this);\n addSwaggerOperation(route, this);\n addSwaggerParams(route, this);\n addSwaggerBody(route, this);\n addSwaggerResponse(route, this);\n }\n }\n\n /**\n * Merges routes that share the same methodName.\n */\n mergeRoutes() {\n this.options.routes = mergeByKey<IRoute>(\n this.options.routes,\n 'methodName',\n {\n deep: true,\n },\n );\n }\n}\n"],"names":["ControllerFactory","getExistingMethods","proto","controller","prototype","Reflect","ownKeys","filter","key","map","String","getMetadata","options","routes","some","route","methodName","routeOptions","path","adjustRoutes","opts","el","requestMethods","httpMethod","toUpperCase","primaryKey","toLowerCase","many","operationId","name","includes","pathParams","param","schema","type","required","matchAll","match","model","otherOptions","merge","removeValues","undefined","interceptors","push","QueryInterceptor","query","createRoutes","disabled","routeHandler","paramKey","Req","Query","Param","Body","defineMetadata","Request","Object","addHttpMethod","addSwaggerOperation","addSwaggerParams","addSwaggerBody","addSwaggerResponse","mergeRoutes","mergeByKey","deep","decorators","defaultOptions","mergeOptions","toKebabCase","replace","addControll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AAI,CAACA,OAAO,GAAG,IAAI,CAACO,YAAY,CAAC;YAC/B,GAAG,IAAI,CAACP,OAAO;YACf,wDAAwD;YACxD,6DAA6D;YAC7DC,QAAQ;mBAAK,IAAI,CAACD,OAAO,CAACC,MAAM,IAAI,EAAE;mBAAM,IAAI,CAACZ,kBAAkB;aAAG;QACxE;QAEA,gFAAgF;QAChF,mDAAmD;QACnD,IAAI,IAAI,CAACW,OAAO,CAACM,IAAI,KAAKwB,WAAW;YACnC,IAAI,CAAC9B,OAAO,CAACM,IAAI,GAAGmD,IAAAA,uBAAW,EAC7B,IAAI,CAAClE,UAAU,CAAC0B,IAAI,CAACyC,OAAO,CAAC,eAAe;QAEhD;QAEA,IAAI,CAACvB,YAAY;QACjB,IAAI,CAACgB,WAAW;QAEhBQ,IAAAA,oCAAiB,EAAC,IAAI;QACtBC,IAAAA,oCAAiB,EAAC,IAAI;QAEtBC,IAAAA,wBAAe,EAAC,IAAI;IACtB;AA8PF"}
1
+ {"version":3,"sources":["../../../../src/decorators/controller/controller.factory.ts"],"sourcesContent":["import { Body, Param, Query, Req } from '@nestjs/common';\nimport type {\n ControllerOptions,\n HttpMethod,\n InitControllerOptions,\n InitRoute,\n IRoute,\n} from './types/index.js';\nimport { addHttpMethod } from './add-decorators/add-http-method.js';\nimport { addSwaggerParams } from './add-decorators/add-swagger-params.js';\nimport { routeHandler } from './route-handler.js';\nimport { addSwaggerOperation } from './add-decorators/add-swagger-operation.js';\nimport { addSwaggerBody } from './add-decorators/add-swagger-body.js';\nimport { addSwaggerResponse } from './add-decorators/add-swagger-response.js';\nimport { QueryInterceptor } from './interceptors/query.interceptor.js';\nimport { defaultOptions } from './default-options.js';\nimport { mergeOptions } from './utils/merge-options.js';\nimport { addControllerTags } from './add-decorators/add-controller-tags.js';\nimport { merge, mergeByKey, removeValues } from '@impactor/javascript';\nimport { applyDecorators } from './utils/reflect.js';\nimport { addControllerPath } from './add-decorators/add-controller-path.js';\nimport { toKebabCase } from '@impactor/javascript';\n// import 'reflect-metadata';\n\nexport class ControllerFactory {\n public options: ControllerOptions;\n public decorators: ClassDecorator[] = [];\n\n constructor(\n public controller: Function,\n // if options is provided as a function, the consumer has to maintain the merge strategy\n options?:\n | InitControllerOptions\n | ((defaultOptions: ControllerOptions) => ControllerOptions),\n ) {\n this.options =\n typeof options === 'function'\n ? // The consumer should receive the adjusted routes, so we need to call `adjustRoutes()` here\n // we'll need to call it again after receiving the user options to adjust its routes\n options(this.adjustRoutes(defaultOptions))\n : mergeOptions(defaultOptions, options || {});\n\n this.options = this.adjustRoutes({\n ...this.options,\n // todo: merge matched routes instead of overriding them\n // i.e. routes with the same methodName, httpMethod, and path\n routes: [...(this.options.routes || []), ...this.getExistingMethods()],\n });\n\n // if path is not provided, use the class name, without the suffix `Controller`,\n // after converting it into url-friendly kebab-case\n if (this.options.path === undefined) {\n this.options.path = toKebabCase(\n this.controller.name.replace(/Controller$/, ''),\n );\n }\n\n this.createRoutes();\n this.mergeRoutes();\n\n addControllerPath(this);\n addControllerTags(this);\n\n applyDecorators(this);\n }\n\n getExistingMethods() {\n let proto = this.controller.prototype;\n\n return (\n Reflect.ownKeys(proto)\n .filter((key) => typeof proto[key] === 'function')\n // convert symbol to string\n .map(String)\n .filter(\n (key) =>\n key !== 'constructor' &&\n // a method can be excluded from being handling by this factory, by adding `@Route(false)`\n Reflect.getMetadata('routeOptions', proto, key) !== false &&\n // skip methods that are already included in routes[]\n !this.options.routes?.some((route) => route.methodName === key),\n )\n // convert method to InitRoute{}\n .map((methodName) => {\n let routeOptions: InitRoute = Reflect.getMetadata(\n 'routeOptions',\n proto,\n methodName,\n );\n\n return {\n methodName,\n path: Reflect.getMetadata('path', proto[methodName]),\n ...routeOptions,\n } as InitRoute;\n })\n );\n }\n /**\n * add all missing props to each route, uch as the HTTP method, primaryKey, and operationId .\n * @param opts\n * @returns\n */\n adjustRoutes(opts: InitControllerOptions = this.options): ControllerOptions {\n return <ControllerOptions>{\n ...opts,\n routes: opts?.routes?.map((el) => {\n let route = { ...el };\n\n // NestJs request methods\n let requestMethods = [\n 'GET',\n 'POST',\n 'PUT',\n 'DELETE',\n 'PATCH',\n 'ALL',\n 'OPTIONS',\n 'HEAD',\n 'SEARCH',\n ];\n // capitalize route.httpMethod to much the HttpMethod type\n route.httpMethod = <HttpMethod>(\n (typeof route.httpMethod === 'number'\n ? requestMethods[route.httpMethod]\n : (<HttpMethod>route.httpMethod)?.toUpperCase() || 'GET')\n );\n route.primaryKey = route.primaryKey || opts.primaryKey || 'id';\n\n // generate the default methodName from path\n // examples\n // - {path: \"users/:id\"} -> \"getOneUserById\"\n // - {path: \"users/:userId/profiles/:profileId/posts\", many:true} -> \"getManyUsersByUserIdProfilesProfileIdPosts\"\n route.methodName =\n route.methodName ||\n route.httpMethod.toLowerCase() +\n (route.httpMethod === 'POST' ? '' : route.many ? 'Many' : 'One');\n\n route.operationId =\n route.operationId ||\n `${this.controller.name}_${String(route.methodName)}`;\n\n if (!route.path) {\n // for \"*One()\" operations, add /:id path param\n // example: GET /users/:id\n route.path =\n route.many || ['POST'].includes(route.httpMethod)\n ? '/'\n : `/:${route.primaryKey}`;\n }\n\n route.pathParams = route.pathParams\n ? route.pathParams.map((param) =>\n typeof param === 'string'\n ? { name: param, schema: { type: 'string' }, required: true }\n : param,\n )\n : // generate path params from route.path\n // matches `:id`, `/:id` and `other/:id/:userId`\n [...route.path.matchAll(/^\\/?:([^/]+)/g)].map((match) => ({\n name: match[1],\n schema: { type: 'string' },\n required: true,\n }));\n\n // todo: generate the corresponding service methods\n // +route.path\n // // remove the leading \"/\"\n // .replace(/^\\//, '')\n // .replace(/^:/,'By')\n // // replace \"/:id\" with \"ById\"\n // .replaceAll(/\\/:/g, '/By')\n // .split('/')\n // // convert parts to camel case\n // // example: \"users/profiles\" -> \"usersProfiles\"\n // .map((el, idx) =>\n // idx === 0 ? el : el.charAt(0).toUpperCase() + el.slice(1),\n // )\n // .join('');\n\n // override options per route\n // for example: route.primaryKey = route.primaryKey || opts.primaryKey\n // when opts.model is a class that extends another class, an exception is thrown `OtherClass is not defined`\n // todo: we may need to exclude other keys that have a class value such as errorResponseModel\n let { routes, model, ...otherOptions } = opts;\n // todo: use merge()?\n route = <IRoute>(\n merge(\n [otherOptions || {}, route || {}].map((el) =>\n removeValues(el, [undefined, null]),\n ),\n )\n );\n\n // merge arrays\n // todo: use mergeArray()?\n ['decorators', 'interceptors'].map((key) => {\n route[key as keyof typeof route] = [\n ...(opts[key as keyof typeof opts] || []),\n ...(route[key as keyof typeof route] || []),\n ];\n });\n\n // merge empty arrays\n // for example if route.interceptors=[] but opts.interceptors has values, opts.interceptors is used\n // Object.keys(opts).map((key) => {\n // if (Array.isArray(key) && !route[key as keyof typeof route]?.length) {\n // route[key as keyof typeof route] =\n // opts[key as keyof typeof opts] || [];\n // }\n // });\n\n route.interceptors!.push(\n new QueryInterceptor(\n merge([opts.query || {}, route.query || {}]) as {\n [key: string]: any;\n },\n ),\n );\n\n return route;\n }),\n };\n }\n\n /**\n * add options.routes[] as class methods\n */\n createRoutes() {\n let routes = this.options.routes?.filter(\n (route) => route.disabled === undefined || !route.disabled,\n ),\n controller = this.controller.prototype;\n\n for (let route of routes) {\n // create a route method and add it to the controller\n // todo: use interceptor to create ParsedRequest\n if (!controller[route.methodName]) {\n controller[route.methodName] = routeHandler(route, this);\n\n // inject the required params\n // similar to patchOne(@Req() req: Request, @Query() query, @Body() dto: MyEntity, @Param(\"id\") id:string)\n // we can get other info such as body and params from req\n // without the need to inject @Body() and @Query()\n // todo: route.primary || getPrimaryKeyFromEntity(opts.model) || \"id\"\n let paramKey = route.primaryKey || 'id';\n Req()(this.controller.prototype, route.methodName, 0);\n Query()(this.controller.prototype, route.methodName, 1);\n\n if (['GET', 'DELETE'].includes(route.httpMethod) && !route.many) {\n Param(paramKey)(this.controller.prototype, route.methodName, 2);\n } else if (route.httpMethod === 'POST') {\n Body()(this.controller.prototype, route.methodName, 2);\n // add 'design:paramtypes' to define the types of each param\n // for instance, the param `@Body()` should be defined as `this.options.model`,\n // so `ValidationPipe()` can work fine.\n // without it, wrong body will bypass class-validator and class-transformer decorators such as `@IsString()`\n Reflect.defineMetadata(\n 'design:paramtypes',\n // 0: `@Req() req: Request`\n // 1: `@Query() query: any` -> todo: add type definition\n // 2: `@Body() body: Model`\n [Request, Object, this.options.model],\n this.controller.prototype,\n route.methodName,\n );\n } else if (['PATCH', 'PUT'].includes(route.httpMethod)) {\n Body()(this.controller.prototype, route.methodName, 2);\n if (route.many) {\n Reflect.defineMetadata(\n 'design:paramtypes',\n [Object, Object, this.options.model],\n this.controller.prototype,\n route.methodName,\n );\n } else {\n // todo: or use `Param()` without `paramKey`, then use it like param[paramKey]\n // todo: accept list of pipes for each param -> `Param(paramName, ...pipes)(...)`\n // to accept only string or number -> add a validation in routerHandler i.e. `if(! typeof params[paramKey]) throw ...`,\n // as class-validator will not validate its type because it is not a DTO i.e. `getOne(@param() params: ParamsDTO)`\n Param(paramKey)(this.controller.prototype, route.methodName, 3);\n Reflect.defineMetadata(\n 'design:paramtypes',\n [Object, Object, this.options.model, Object],\n this.controller.prototype,\n route.methodName,\n );\n }\n }\n }\n\n // add decorators to the route\n // annotations are added only if:\n // - the method listed in this.options.routes[] and doesn't has @Route(false)\n // - the method is not listed and has @Route(options?)\n // if the method is not listed and doesn't has @Route(), the annotations will not be added\n // if no http decorator already applied such as @GET()\n // when adding @Get(), nest adds \"method\" and \"path\" metadata\n addHttpMethod(route, this);\n addSwaggerOperation(route, this);\n addSwaggerParams(route, this);\n addSwaggerBody(route, this);\n addSwaggerResponse(route, this);\n }\n }\n\n /**\n * Merges routes that share the same methodName.\n */\n mergeRoutes() {\n this.options.routes = mergeByKey<IRoute>(\n this.options.routes,\n 'methodName',\n {\n deep: true,\n },\n );\n }\n}\n"],"names":["Body","Param","Query","Req","addHttpMethod","addSwaggerParams","routeHandler","addSwaggerOperation","addSwaggerBody","addSwaggerResponse","QueryInterceptor","defaultOptions","mergeOptions","addControllerTags","merge","mergeByKey","removeValues","applyDecorators","addControllerPath","toKebabCase","ControllerFactory","controller","options","decorators","adjustRoutes","routes","getExistingMethods","path","undefined","name","replace","createRoutes","mergeRoutes","proto","prototype","Reflect","ownKeys","filter","key","map","String","getMetadata","some","route","methodName","routeOptions","opts","el","requestMethods","httpMethod","toUpperCase","primaryKey","toLowerCase","many","operationId","includes","pathParams","param","schema","type","required","matchAll","match","model","otherOptions","interceptors","push","query","disabled","paramKey","defineMetadata","Request","Object","deep"],"mappings":"AAAA,SAASA,IAAI,EAAEC,KAAK,EAAEC,KAAK,EAAEC,GAAG,QAAQ,iBAAiB;AAQzD,SAASC,aAAa,QAAQ,sCAAsC;AACpE,SAASC,gBAAgB,QAAQ,yCAAyC;AAC1E,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,mBAAmB,QAAQ,4CAA4C;AAChF,SAASC,cAAc,QAAQ,uCAAuC;AACtE,SAASC,kBAAkB,QAAQ,2CAA2C;AAC9E,SAASC,gBAAgB,QAAQ,sCAAsC;AACvE,SAASC,cAAc,QAAQ,uBAAuB;AACtD,SAASC,YAAY,QAAQ,2BAA2B;AACxD,SAASC,iBAAiB,QAAQ,0CAA0C;AAC5E,SAASC,KAAK,EAAEC,UAAU,EAAEC,YAAY,QAAQ,uBAAuB;AACvE,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,iBAAiB,QAAQ,0CAA0C;AAC5E,SAASC,WAAW,QAAQ,uBAAuB;AACnD,6BAA6B;AAE7B,OAAO,MAAMC;IAIX,YACE,AAAOC,UAAoB,EAC3B,yFAAyF;IACzFC,OAE8D,CAC9D;aALOD,aAAAA;aAHFE,aAA+B,EAAE;QAStC,IAAI,CAACD,OAAO,GACV,OAAOA,YAAY,aAEf,oFAAoF;QACpFA,QAAQ,IAAI,CAACE,YAAY,CAACb,mBAC1BC,aAAaD,gBAAgBW,WAAW,CAAC;QAE/C,IAAI,CAACA,OAAO,GAAG,IAAI,CAACE,YAAY,CAAC;YAC/B,GAAG,I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BACtDjD,OAAO,IAAI,CAACqB,UAAU,CAACa,SAAS,EAAES,MAAMC,UAAU,EAAE;oBACpD,IAAID,MAAMU,IAAI,EAAE;wBACdlB,QAAQmC,cAAc,CACpB,qBACA;4BAACE;4BAAQA;4BAAQ,IAAI,CAAClD,OAAO,CAACyC,KAAK;yBAAC,EACpC,IAAI,CAAC1C,UAAU,CAACa,SAAS,EACzBS,MAAMC,UAAU;oBAEpB,OAAO;wBACL,8EAA8E;wBAC9E,iFAAiF;wBACjF,uHAAuH;wBACvH,kHAAkH;wBAClH3C,MAAMoE,UAAU,IAAI,CAAChD,UAAU,CAACa,SAAS,EAAES,MAAMC,UAAU,EAAE;wBAC7DT,QAAQmC,cAAc,CACpB,qBACA;4BAACE;4BAAQA;4BAAQ,IAAI,CAAClD,OAAO,CAACyC,KAAK;4BAAES;yBAAO,EAC5C,IAAI,CAACnD,UAAU,CAACa,SAAS,EACzBS,MAAMC,UAAU;oBAEpB;gBACF;YACF;YAEA,8BAA8B;YAC9B,iCAAiC;YACjC,6EAA6E;YAC7E,sDAAsD;YACtD,0FAA0F;YAC1F,sDAAsD;YACtD,6DAA6D;YAC7DxC,cAAcuC,OAAO,IAAI;YACzBpC,oBAAoBoC,OAAO,IAAI;YAC/BtC,iBAAiBsC,OAAO,IAAI;YAC5BnC,eAAemC,OAAO,IAAI;YAC1BlC,mBAAmBkC,OAAO,IAAI;QAChC;IACF;IAEA;;GAEC,GACDX,cAAc;QACZ,IAAI,CAACV,OAAO,CAACG,MAAM,GAAGV,WACpB,IAAI,CAACO,OAAO,CAACG,MAAM,EACnB,cACA;YACEgD,MAAM;QACR;IAEJ;AACF"}
@@ -1,2 +1,2 @@
1
- import type { InitControllerOptions } from './types';
1
+ import type { InitControllerOptions } from './types/index.js';
2
2
  export declare const defaultOptions: Partial<InitControllerOptions>;
@@ -1,15 +1,8 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "defaultOptions", {
7
- enumerable: true,
8
- get: function() {
9
- return defaultOptions;
10
- }
11
- });
12
- const defaultOptions = {
2
+ // todo: add opts.maxTake to limit ?take=
3
+ /**
4
+ * the default options for \@Controller()
5
+ */ export const defaultOptions = {
13
6
  // todo: allow sub routes, such as `/:field`
14
7
  routes: [
15
8
  {
@@ -74,8 +67,7 @@ const defaultOptions = {
74
67
  },
75
68
  {
76
69
  name: 'skip',
77
- description: 'skip rows.',
78
- example: 2,
70
+ description: 'skip rows. example: `2`',
79
71
  many: true,
80
72
  httpMethods: [
81
73
  'GET',
@@ -98,21 +90,16 @@ const defaultOptions = {
98
90
  },
99
91
  {
100
92
  name: 'relations',
101
- description: 'add joined relational objects, supports nested relations',
102
- example: [
103
- 'user.profile:name,age'
104
- ],
93
+ description: 'add joined relational objects, supports nested relations. example: `["age", "user.profile:name"]`',
105
94
  httpMethods: [
106
95
  'GET'
107
96
  ]
108
97
  },
109
98
  {
110
99
  name: 'where',
111
- description: 'add where condition. to use sql statement, start the value with `>`.\n to search in an array column, put the value in an array. see <a href="https://orkhan.gitbook.io/typeorm/docs/find-options#advanced-options" target="_blank">see advanced options</a>',
112
- example: {
113
- name: 'john',
114
- email: ">Like '%john%'"
115
- },
100
+ description: 'add where condition. to use sql statement, start the value with `>`.\n to search in an array column, put the value in an array. see <a href="https://orkhan.gitbook.io/typeorm/docs/find-options#advanced-options" target="_blank">see advanced options</a>\n example: `{ name: "john", email: ">Like \'%john@%\'" }`',
101
+ // when adding an example here, Swagger adds it to the query by default, causing the query to has properties may not be defined in the entity
102
+ // example: { name: 'john', email: ">Like '%john@%'" },
116
103
  many: true,
117
104
  httpMethods: [
118
105
  'GET',
@@ -124,10 +111,8 @@ const defaultOptions = {
124
111
  {
125
112
  name: 'order',
126
113
  // or 'name,id:DESC'
127
- example: {
128
- name: 'ASC',
129
- id: 'DESC'
130
- },
114
+ // example: { name: 'ASC', id: 'DESC' },
115
+ description: "example: `{ name: 'ASC', id: 'DESC' }`",
131
116
  many: true,
132
117
  httpMethods: [
133
118
  'GET',