@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,33 +1,3 @@
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 JwtAuthGuard () {
13
- return JwtAuthGuard;
14
- },
15
- get Own () {
16
- return Own;
17
- },
18
- get Private () {
19
- return Private;
20
- },
21
- get Public () {
22
- return Public;
23
- },
24
- get Roles () {
25
- return Roles;
26
- }
27
- });
28
- const _common = require("@nestjs/common");
29
- const _core = require("@nestjs/core");
30
- const _passport = require("@nestjs/passport");
31
1
  function _ts_decorate(decorators, target, key, desc) {
32
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
33
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -37,13 +7,47 @@ function _ts_decorate(decorators, target, key, desc) {
37
7
  function _ts_metadata(k, v) {
38
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
39
9
  }
40
- const Public = ()=>(0, _common.SetMetadata)('isPublic', true);
41
- const Private = ()=>(0, _common.SetMetadata)('isPublic', false);
42
- const Roles = (...roles)=>(0, _common.SetMetadata)('roles', roles);
43
- const Own = (field = 'user')=>(0, _common.SetMetadata)('own', field);
44
- let JwtAuthGuard = class JwtAuthGuard extends (0, _passport.AuthGuard)([
10
+ import { Injectable, SetMetadata, UnauthorizedException } from "@nestjs/common";
11
+ import { Reflector } from "@nestjs/core";
12
+ import { AuthGuard } from "@nestjs/passport";
13
+ /**
14
+ * attach this decorator to public endpoints to exclude them from the auth guard
15
+ * @example `@public() getPublicResource(){}`
16
+ */ export const Public = ()=>SetMetadata('isPublic', true);
17
+ /** use this decorator to remove the `@Public` mark from a route */ export const Private = ()=>SetMetadata('isPublic', false);
18
+ /**
19
+ * only provided roles can access the endpoint
20
+ * the guard for each endpoint overrides the controller's guard
21
+ *
22
+ * @example @Roles('admin', 'moderator') -> user's that has role==="admin" can access
23
+ *
24
+ */ // or use @SetMetadata('roles', values)
25
+ export const Roles = (...roles)=>SetMetadata('roles', roles);
26
+ /**
27
+ * every user can access only his own data,
28
+ * except the system admin who can access any data in this endpoint
29
+ *
30
+ * for example, if `@Own('author')` is set before `findAll()` it converted into `findAll({author: userId})`
31
+ * to limit the results for data that he owns
32
+ *
33
+ * to disable this guard for a specific endpoint, i.e. to bypass the controller's value use `@Own(false)`
34
+ *
35
+ * @example @Own('user')
36
+ *
37
+ * @param field the field name that specify the document owner in the database, default=user.
38
+ * if set to false, it disables the guard
39
+ */ // todo: @Limit('criteria' | {field: value})
40
+ // todo: create an interceptor to add this condition to the controller's handler
41
+ // todo: @Own(field, excludeRoles=['admin'])
42
+ export const Own = (field = 'user')=>SetMetadata('own', field);
43
+ export class JwtAuthGuard extends AuthGuard([
45
44
  'jwt'
46
45
  ]) {
46
+ // todo: DI is not working here, so `this.reflector` is undefined
47
+ // https://github.com/its-dibo/dibo/issues/582
48
+ constructor(reflector){
49
+ super(), this.reflector = reflector;
50
+ }
47
51
  async canActivate(context) {
48
52
  try {
49
53
  // call canActivate() first to allow passport to set `req.user` for the logged in users
@@ -71,21 +75,16 @@ let JwtAuthGuard = class JwtAuthGuard extends (0, _passport.AuthGuard)([
71
75
  }
72
76
  handleRequest(err, user, _info) {
73
77
  if (err || !user) {
74
- throw err || new _common.UnauthorizedException();
78
+ throw err || new UnauthorizedException();
75
79
  }
76
80
  return user;
77
81
  }
78
- // todo: DI is not working here, so `this.reflector` is undefined
79
- // https://github.com/its-dibo/dibo/issues/582
80
- constructor(reflector){
81
- super(), this.reflector = reflector;
82
- }
83
- };
82
+ }
84
83
  JwtAuthGuard = _ts_decorate([
85
- (0, _common.Injectable)(),
84
+ Injectable(),
86
85
  _ts_metadata("design:type", Function),
87
86
  _ts_metadata("design:paramtypes", [
88
- typeof _core.Reflector === "undefined" ? Object : _core.Reflector
87
+ typeof Reflector === "undefined" ? Object : Reflector
89
88
  ])
90
89
  ], JwtAuthGuard);
91
90
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/guards/auth.guard.ts"],"sourcesContent":["import {\n ExecutionContext,\n Injectable,\n SetMetadata,\n UnauthorizedException,\n} from '@nestjs/common';\nimport { Reflector } from '@nestjs/core';\nimport { AuthGuard } from '@nestjs/passport';\n\n/**\n * attach this decorator to public endpoints to exclude them from the auth guard\n * @example `@public() getPublicResource(){}`\n */\nexport const Public = () => SetMetadata('isPublic', true);\n/** use this decorator to remove the `@Public` mark from a route */\nexport const Private = () => SetMetadata('isPublic', false);\n\n/**\n * only provided roles can access the endpoint\n * the guard for each endpoint overrides the controller's guard\n *\n * @example @Roles('admin', 'moderator') -> user's that has role===\"admin\" can access\n *\n */\n// or use @SetMetadata('roles', values)\nexport const Roles = (...roles: any[]) => SetMetadata('roles', roles);\n\n/**\n * every user can access only his own data,\n * except the system admin who can access any data in this endpoint\n *\n * for example, if `@Own('author')` is set before `findAll()` it converted into `findAll({author: userId})`\n * to limit the results for data that he owns\n *\n * to disable this guard for a specific endpoint, i.e. to bypass the controller's value use `@Own(false)`\n *\n * @example @Own('user')\n *\n * @param field the field name that specify the document owner in the database, default=user.\n * if set to false, it disables the guard\n */\n// todo: @Limit('criteria' | {field: value})\n// todo: create an interceptor to add this condition to the controller's handler\n// todo: @Own(field, excludeRoles=['admin'])\nexport const Own = (field: string | false = 'user') =>\n SetMetadata('own', field);\n\n/**\n * a guard that limits the access to the authenticated users\n * or specific roles that are provided by @Roles()\n * only the users that have one of the provided roles can access the resource\n * to allow public access use `@public()`\n *\n * @example\n * @Get()\n * // limit the access to admins only\n * @Roles('admin', 'moderator')\n * findAll(){ return this.service.getAll(); }\n *\n * @Get()\n * // enable public access\n * @Public()\n * findAll(){ return this.service.getAll(); }\n *\n * @Get()\n * // allow the logged in users only to access the route\n * // by not providing any annotation\n * findAll(){ return this.service.getAll(); }\n */\n@Injectable()\nexport class JwtAuthGuard extends AuthGuard(['jwt']) {\n // todo: DI is not working here, so `this.reflector` is undefined\n // https://github.com/its-dibo/dibo/issues/582\n constructor(private reflector: Reflector) {\n super();\n }\n\n async canActivate(context: ExecutionContext) {\n try {\n // call canActivate() first to allow passport to set `req.user` for the logged in users\n // and call handleRequest()\n await super.canActivate(context);\n } catch {\n // allow non-logged in users to access public resources\n let isPublic = this.reflector.getAllAndOverride<boolean>('isPublic', [\n context.getHandler(),\n context.getClass(),\n ]);\n return isPublic;\n }\n\n // check user roles\n let roles = this.reflector.getAllAndOverride('roles', [\n context.getClass(),\n context.getHandler(),\n ]);\n\n // if no role provided, then the resource access is not limited\n if (!roles?.length) {\n return true;\n }\n\n let req = context.switchToHttp().getRequest(),\n user = req.user;\n return roles.includes(user?.role);\n }\n\n handleRequest<UserEntity>(err: Error, user: UserEntity, _info: any) {\n if (err || !user) {\n throw err || new UnauthorizedException();\n }\n return user;\n }\n}\n"],"names":["JwtAuthGuard","Own","Private","Public","Roles","SetMetadata","roles","field","AuthGuard","canActivate","context","isPublic","reflector","getAllAndOverride","getHandler","getClass","length","req","switchToHttp","getRequest","user","includes","role","handleRequest","err","_info","UnauthorizedException"],"mappings":";;;;;;;;;;;QAsEaA;eAAAA;;QA1BAC;eAAAA;;QA7BAC;eAAAA;;QAFAC;eAAAA;;QAYAC;eAAAA;;;wBApBN;sBACmB;0BACA;;;;;;;;;;AAMnB,MAAMD,SAAS,IAAME,IAAAA,mBAAW,EAAC,YAAY;AAE7C,MAAMH,UAAU,IAAMG,IAAAA,mBAAW,EAAC,YAAY;AAU9C,MAAMD,QAAQ,CAAC,GAAGE,QAAiBD,IAAAA,mBAAW,EAAC,SAASC;AAmBxD,MAAML,MAAM,CAACM,QAAwB,MAAM,GAChDF,IAAAA,mBAAW,EAAC,OAAOE;AAyBd,IAAA,AAAMP,eAAN,MAAMA,qBAAqBQ,IAAAA,mBAAS,EAAC;IAAC;CAAM;IAOjD,MAAMC,YAAYC,OAAyB,EAAE;QAC3C,IAAI;YACF,uFAAuF;YACvF,2BAA2B;YAC3B,MAAM,KAAK,CAACD,YAAYC;QAC1B,EAAE,OAAM;YACN,uDAAuD;YACvD,IAAIC,WAAW,IAAI,CAACC,SAAS,CAACC,iBAAiB,CAAU,YAAY;gBACnEH,QAAQI,UAAU;gBAClBJ,QAAQK,QAAQ;aACjB;YACD,OAAOJ;QACT;QAEA,mBAAmB;QACnB,IAAIL,QAAQ,IAAI,CAACM,SAAS,CAACC,iBAAiB,CAAC,SAAS;YACpDH,QAAQK,QAAQ;YAChBL,QAAQI,UAAU;SACnB;QAED,+DAA+D;QAC/D,IAAI,CAACR,OAAOU,QAAQ;YAClB,OAAO;QACT;QAEA,IAAIC,MAAMP,QAAQQ,YAAY,GAAGC,UAAU,IACzCC,OAAOH,IAAIG,IAAI;QACjB,OAAOd,MAAMe,QAAQ,CAACD,MAAME;IAC9B;IAEAC,cAA0BC,GAAU,EAAEJ,IAAgB,EAAEK,KAAU,EAAE;QAClE,IAAID,OAAO,CAACJ,MAAM;YAChB,MAAMI,OAAO,IAAIE,6BAAqB;QACxC;QACA,OAAON;IACT;IAzCA,iEAAiE;IACjE,8CAA8C;IAC9C,YAAY,AAAQR,SAAoB,CAAE;QACxC,KAAK,SADaA,YAAAA;IAEpB;AAsCF"}
1
+ {"version":3,"sources":["../../../src/guards/auth.guard.ts"],"sourcesContent":["import {\n ExecutionContext,\n Injectable,\n SetMetadata,\n UnauthorizedException,\n} from '@nestjs/common';\nimport { Reflector } from '@nestjs/core';\nimport { AuthGuard } from '@nestjs/passport';\n\n/**\n * attach this decorator to public endpoints to exclude them from the auth guard\n * @example `@public() getPublicResource(){}`\n */\nexport const Public = () => SetMetadata('isPublic', true);\n/** use this decorator to remove the `@Public` mark from a route */\nexport const Private = () => SetMetadata('isPublic', false);\n\n/**\n * only provided roles can access the endpoint\n * the guard for each endpoint overrides the controller's guard\n *\n * @example @Roles('admin', 'moderator') -> user's that has role===\"admin\" can access\n *\n */\n// or use @SetMetadata('roles', values)\nexport const Roles = (...roles: any[]) => SetMetadata('roles', roles);\n\n/**\n * every user can access only his own data,\n * except the system admin who can access any data in this endpoint\n *\n * for example, if `@Own('author')` is set before `findAll()` it converted into `findAll({author: userId})`\n * to limit the results for data that he owns\n *\n * to disable this guard for a specific endpoint, i.e. to bypass the controller's value use `@Own(false)`\n *\n * @example @Own('user')\n *\n * @param field the field name that specify the document owner in the database, default=user.\n * if set to false, it disables the guard\n */\n// todo: @Limit('criteria' | {field: value})\n// todo: create an interceptor to add this condition to the controller's handler\n// todo: @Own(field, excludeRoles=['admin'])\nexport const Own = (field: string | false = 'user') =>\n SetMetadata('own', field);\n\n/**\n * a guard that limits the access to the authenticated users\n * or specific roles that are provided by @Roles()\n * only the users that have one of the provided roles can access the resource\n * to allow public access use `@public()`\n *\n * @example\n * @Get()\n * // limit the access to admins only\n * @Roles('admin', 'moderator')\n * findAll(){ return this.service.getAll(); }\n *\n * @Get()\n * // enable public access\n * @Public()\n * findAll(){ return this.service.getAll(); }\n *\n * @Get()\n * // allow the logged in users only to access the route\n * // by not providing any annotation\n * findAll(){ return this.service.getAll(); }\n */\n@Injectable()\nexport class JwtAuthGuard extends AuthGuard(['jwt']) {\n // todo: DI is not working here, so `this.reflector` is undefined\n // https://github.com/its-dibo/dibo/issues/582\n constructor(private reflector: Reflector) {\n super();\n }\n\n async canActivate(context: ExecutionContext) {\n try {\n // call canActivate() first to allow passport to set `req.user` for the logged in users\n // and call handleRequest()\n await super.canActivate(context);\n } catch {\n // allow non-logged in users to access public resources\n let isPublic = this.reflector.getAllAndOverride<boolean>('isPublic', [\n context.getHandler(),\n context.getClass(),\n ]);\n return isPublic;\n }\n\n // check user roles\n let roles = this.reflector.getAllAndOverride('roles', [\n context.getClass(),\n context.getHandler(),\n ]);\n\n // if no role provided, then the resource access is not limited\n if (!roles?.length) {\n return true;\n }\n\n let req = context.switchToHttp().getRequest(),\n user = req.user;\n return roles.includes(user?.role);\n }\n\n handleRequest<UserEntity>(err: Error, user: UserEntity, _info: any) {\n if (err || !user) {\n throw err || new UnauthorizedException();\n }\n return user;\n }\n}\n"],"names":["Injectable","SetMetadata","UnauthorizedException","Reflector","AuthGuard","Public","Private","Roles","roles","Own","field","JwtAuthGuard","reflector","canActivate","context","isPublic","getAllAndOverride","getHandler","getClass","length","req","switchToHttp","getRequest","user","includes","role","handleRequest","err","_info"],"mappings":";;;;;;;;;AAAA,SAEEA,UAAU,EACVC,WAAW,EACXC,qBAAqB,QAChB,iBAAiB;AACxB,SAASC,SAAS,QAAQ,eAAe;AACzC,SAASC,SAAS,QAAQ,mBAAmB;AAE7C;;;CAGC,GACD,OAAO,MAAMC,SAAS,IAAMJ,YAAY,YAAY,MAAM;AAC1D,iEAAiE,GACjE,OAAO,MAAMK,UAAU,IAAML,YAAY,YAAY,OAAO;AAE5D;;;;;;CAMC,GACD,uCAAuC;AACvC,OAAO,MAAMM,QAAQ,CAAC,GAAGC,QAAiBP,YAAY,SAASO,OAAO;AAEtE;;;;;;;;;;;;;CAaC,GACD,4CAA4C;AAC5C,gFAAgF;AAChF,4CAA4C;AAC5C,OAAO,MAAMC,MAAM,CAACC,QAAwB,MAAM,GAChDT,YAAY,OAAOS,OAAO;AAyB5B,OAAO,MAAMC,qBAAqBP,UAAU;IAAC;CAAM;IACjD,iEAAiE;IACjE,8CAA8C;IAC9C,YAAY,AAAQQ,SAAoB,CAAE;QACxC,KAAK,SADaA,YAAAA;IAEpB;IAEA,MAAMC,YAAYC,OAAyB,EAAE;QAC3C,IAAI;YACF,uFAAuF;YACvF,2BAA2B;YAC3B,MAAM,KAAK,CAACD,YAAYC;QAC1B,EAAE,OAAM;YACN,uDAAuD;YACvD,IAAIC,WAAW,IAAI,CAACH,SAAS,CAACI,iBAAiB,CAAU,YAAY;gBACnEF,QAAQG,UAAU;gBAClBH,QAAQI,QAAQ;aACjB;YACD,OAAOH;QACT;QAEA,mBAAmB;QACnB,IAAIP,QAAQ,IAAI,CAACI,SAAS,CAACI,iBAAiB,CAAC,SAAS;YACpDF,QAAQI,QAAQ;YAChBJ,QAAQG,UAAU;SACnB;QAED,+DAA+D;QAC/D,IAAI,CAACT,OAAOW,QAAQ;YAClB,OAAO;QACT;QAEA,IAAIC,MAAMN,QAAQO,YAAY,GAAGC,UAAU,IACzCC,OAAOH,IAAIG,IAAI;QACjB,OAAOf,MAAMgB,QAAQ,CAACD,MAAME;IAC9B;IAEAC,cAA0BC,GAAU,EAAEJ,IAAgB,EAAEK,KAAU,EAAE;QAClE,IAAID,OAAO,CAACJ,MAAM;YAChB,MAAMI,OAAO,IAAIzB;QACnB;QACA,OAAOqB;IACT;AACF"}
@@ -1,22 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "BasicController", {
6
- enumerable: true,
7
- get: function() {
8
- return BasicController;
9
- }
10
- });
11
- const _authguard = require("../../guards/auth.guard");
12
- const _common = require("@nestjs/common");
13
1
  function _ts_decorate(decorators, target, key, desc) {
14
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
4
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
18
6
  }
19
- let BasicController = class BasicController {
7
+ import { Public } from "../../guards/auth.guard.js";
8
+ import { Controller } from "@nestjs/common";
9
+ export class BasicController {
20
10
  // http decorators like `@Get()` causes error:
21
11
  // Reflect.defineMetadata(constants_1.PATH_METADATA, path, descriptor.value);
22
12
  // https://github.com/its-dibo/dibo/issues/547
@@ -24,10 +14,10 @@ let BasicController = class BasicController {
24
14
  // @HttpCode(204)
25
15
  // @Version(VERSION_NEUTRAL)
26
16
  healthCheck() {}
27
- };
17
+ }
28
18
  BasicController = _ts_decorate([
29
- (0, _common.Controller)(),
30
- (0, _authguard.Public)()
19
+ Controller(),
20
+ Public()
31
21
  ], BasicController);
32
22
 
33
23
  //# sourceMappingURL=basic.controller.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/basic/basic.controller.ts"],"sourcesContent":["import { Public } from '../../guards/auth.guard';\nimport {\n Controller,\n // Get,\n // HttpCode,\n // VERSION_NEUTRAL,\n // Version,\n} from '@nestjs/common';\n\n@Controller()\n@Public()\nexport class BasicController {\n // http decorators like `@Get()` causes error:\n // Reflect.defineMetadata(constants_1.PATH_METADATA, path, descriptor.value);\n // https://github.com/its-dibo/dibo/issues/547\n\n // @Get()\n // @HttpCode(204)\n // @Version(VERSION_NEUTRAL)\n healthCheck(): void {}\n}\n"],"names":["BasicController","healthCheck"],"mappings":";;;;+BAWaA;;;eAAAA;;;2BAXU;wBAOhB;;;;;;;AAIA,IAAA,AAAMA,kBAAN,MAAMA;IACX,8CAA8C;IAC9C,6EAA6E;IAC7E,8CAA8C;IAE9C,SAAS;IACT,iBAAiB;IACjB,4BAA4B;IAC5BC,cAAoB,CAAC;AACvB"}
1
+ {"version":3,"sources":["../../../../src/modules/basic/basic.controller.ts"],"sourcesContent":["import { Public } from '../../guards/auth.guard.js';\nimport {\n Controller,\n // Get,\n // HttpCode,\n // VERSION_NEUTRAL,\n // Version,\n} from '@nestjs/common';\n\n@Controller()\n@Public()\nexport class BasicController {\n // http decorators like `@Get()` causes error:\n // Reflect.defineMetadata(constants_1.PATH_METADATA, path, descriptor.value);\n // https://github.com/its-dibo/dibo/issues/547\n\n // @Get()\n // @HttpCode(204)\n // @Version(VERSION_NEUTRAL)\n healthCheck(): void {}\n}\n"],"names":["Public","Controller","BasicController","healthCheck"],"mappings":";;;;;;AAAA,SAASA,MAAM,QAAQ,6BAA6B;AACpD,SACEC,UAAU,QAKL,iBAAiB;AAIxB,OAAO,MAAMC;IACX,8CAA8C;IAC9C,6EAA6E;IAC7E,8CAA8C;IAE9C,SAAS;IACT,iBAAiB;IACjB,4BAA4B;IAC5BC,cAAoB,CAAC;AACvB"}
@@ -1,43 +1,35 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "BasicModule", {
6
- enumerable: true,
7
- get: function() {
8
- return BasicModule;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const _core = require("@nestjs/core");
13
- const _basiccontroller = require("./basic.controller");
14
- const _basicservice = require("./basic.service");
15
- const _authguard = require("../../guards/auth.guard");
16
1
  function _ts_decorate(decorators, target, key, desc) {
17
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
18
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
19
4
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
20
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
21
6
  }
22
- let BasicModule = class BasicModule {
23
- };
7
+ import { Module } from "@nestjs/common";
8
+ import { APP_GUARD } from "@nestjs/core";
9
+ import { BasicController } from "./basic.controller.js";
10
+ import { BasicService } from "./basic.service.js";
11
+ // todo: use alias paths
12
+ // not works when building an app that depends on this package
13
+ import { JwtAuthGuard } from "../../guards/auth.guard.js";
14
+ export class BasicModule {
15
+ }
24
16
  BasicModule = _ts_decorate([
25
- (0, _common.Module)({
17
+ Module({
26
18
  imports: [],
27
19
  controllers: [
28
- _basiccontroller.BasicController
20
+ BasicController
29
21
  ],
30
22
  providers: [
31
- _basicservice.BasicService,
23
+ BasicService,
32
24
  {
33
25
  // use JWT auth guard globally to protect all routes
34
26
  // unless a route is marked as public by `@Public()` decorator
35
- provide: _core.APP_GUARD,
36
- useClass: _authguard.JwtAuthGuard
27
+ provide: APP_GUARD,
28
+ useClass: JwtAuthGuard
37
29
  }
38
30
  ],
39
31
  exports: [
40
- _basicservice.BasicService
32
+ BasicService
41
33
  ]
42
34
  })
43
35
  ], BasicModule);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/basic/basic.module.ts"],"sourcesContent":["import { Module } from '@nestjs/common';\nimport { APP_GUARD } from '@nestjs/core';\nimport { BasicController } from './basic.controller';\nimport { BasicService } from './basic.service';\n// todo: use alias paths\n// not works when building an app that depends on this package\nimport { JwtAuthGuard } from '../../guards/auth.guard';\n\n@Module({\n imports: [],\n controllers: [BasicController],\n providers: [\n BasicService,\n {\n // use JWT auth guard globally to protect all routes\n // unless a route is marked as public by `@Public()` decorator\n provide: APP_GUARD,\n useClass: JwtAuthGuard,\n },\n ],\n exports: [BasicService],\n})\nexport class BasicModule {}\n"],"names":["BasicModule","imports","controllers","BasicController","providers","BasicService","provide","APP_GUARD","useClass","JwtAuthGuard","exports"],"mappings":";;;;+BAsBaA;;;eAAAA;;;wBAtBU;sBACG;iCACM;8BACH;2BAGA;;;;;;;AAgBtB,IAAA,AAAMA,cAAN,MAAMA;AAAa;;;QAbxBC,SAAS,EAAE;QACXC,aAAa;YAACC,gCAAe;SAAC;QAC9BC,WAAW;YACTC,0BAAY;YACZ;gBACE,oDAAoD;gBACpD,8DAA8D;gBAC9DC,SAASC,eAAS;gBAClBC,UAAUC,uBAAY;YACxB;SACD;QACDC,SAAS;YAACL,0BAAY;SAAC"}
1
+ {"version":3,"sources":["../../../../src/modules/basic/basic.module.ts"],"sourcesContent":["import { Module } from '@nestjs/common';\nimport { APP_GUARD } from '@nestjs/core';\nimport { BasicController } from './basic.controller.js';\nimport { BasicService } from './basic.service.js';\n// todo: use alias paths\n// not works when building an app that depends on this package\nimport { JwtAuthGuard } from '../../guards/auth.guard.js';\n\n@Module({\n imports: [],\n controllers: [BasicController],\n providers: [\n BasicService,\n {\n // use JWT auth guard globally to protect all routes\n // unless a route is marked as public by `@Public()` decorator\n provide: APP_GUARD,\n useClass: JwtAuthGuard,\n },\n ],\n exports: [BasicService],\n})\nexport class BasicModule {}\n"],"names":["Module","APP_GUARD","BasicController","BasicService","JwtAuthGuard","BasicModule","imports","controllers","providers","provide","useClass","exports"],"mappings":";;;;;;AAAA,SAASA,MAAM,QAAQ,iBAAiB;AACxC,SAASC,SAAS,QAAQ,eAAe;AACzC,SAASC,eAAe,QAAQ,wBAAwB;AACxD,SAASC,YAAY,QAAQ,qBAAqB;AAClD,wBAAwB;AACxB,8DAA8D;AAC9D,SAASC,YAAY,QAAQ,6BAA6B;AAgB1D,OAAO,MAAMC;AAAa;;;QAbxBC,SAAS,EAAE;QACXC,aAAa;YAACL;SAAgB;QAC9BM,WAAW;YACTL;YACA;gBACE,oDAAoD;gBACpD,8DAA8D;gBAC9DM,SAASR;gBACTS,UAAUN;YACZ;SACD;QACDO,SAAS;YAACR;SAAa"}
@@ -1,24 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "BasicService", {
6
- enumerable: true,
7
- get: function() {
8
- return BasicService;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
1
  function _ts_decorate(decorators, target, key, desc) {
13
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
15
4
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
16
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
17
6
  }
18
- let BasicService = class BasicService {
19
- };
7
+ import { Injectable } from "@nestjs/common";
8
+ export class BasicService {
9
+ }
20
10
  BasicService = _ts_decorate([
21
- (0, _common.Injectable)()
11
+ Injectable()
22
12
  ], BasicService);
23
13
 
24
14
  //# sourceMappingURL=basic.service.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/basic/basic.service.ts"],"sourcesContent":["import { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class BasicService {}\n"],"names":["BasicService"],"mappings":";;;;+BAGaA;;;eAAAA;;;wBAHc;;;;;;;AAGpB,IAAA,AAAMA,eAAN,MAAMA;AAAc"}
1
+ {"version":3,"sources":["../../../../src/modules/basic/basic.service.ts"],"sourcesContent":["import { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class BasicService {}\n"],"names":["Injectable","BasicService"],"mappings":";;;;;;AAAA,SAASA,UAAU,QAAQ,iBAAiB;AAG5C,OAAO,MAAMC;AAAc"}
@@ -0,0 +1 @@
1
+ export declare function registerEntities(models?: Function[]): void;
@@ -0,0 +1,135 @@
1
+ import { typeORMToSwagger } from "./utils/typeorm-to-swagger.js";
2
+ import { ApiProperty } from "@nestjs/swagger";
3
+ import { getMetadataArgsStorage } from "typeorm";
4
+ /**
5
+ * Register models and add Swagger and class-validator decorators
6
+ * call this function before `SwaggerModule.createDocument()`
7
+ *
8
+ * This function extracts info from each column to generate best Swagger model and best validations as much as possible.
9
+ *
10
+ * add `@Hide()` to properties that you want to hide from Swagger
11
+ * `@ApiHideProperty()` doesn't work.
12
+ *
13
+ * to skip processing a property by this function add `@Skip()`
14
+ *
15
+ * to apply this function on a specific model, decorate it with `@Entity()`
16
+ * or use `registerEntities([model])`
17
+ *
18
+ * existing options in `@ApiProperty()` will be merged into options generated by this function
19
+ *
20
+ * `ManyToMany` and `OneToMany` relations are ignored by default, you need to add `@ApiProperty()` to include them
21
+ * `OneToOne` and `ManyToOne` relation is included but with a different name, after suffixing the primary key name
22
+ *
23
+ * @param models list of models to apply this function to
24
+ */ export function registerEntities(models) {
25
+ let storage = getMetadataArgsStorage(), // todo: handle when col.target is string
26
+ cols = storage.columns.filter((el)=>typeof el.target === 'function'), relations = storage.relations.filter((el)=>typeof el.target === 'function' && el.relationType.endsWith('to-one')), joinColumns = storage.joinColumns;
27
+ if (Array.isArray(models)) {
28
+ cols = cols.filter((el)=>models.includes(el.target));
29
+ relations = relations.filter((el)=>models.includes(el.target));
30
+ }
31
+ for (let col of cols){
32
+ // existing props, i.e. options that the consumer already specified in `@ApiProperty()`
33
+ let props = Reflect.getMetadata('swagger/apiModelProperties', col.target.prototype, col.propertyName), // if the column is auto generated
34
+ // this is similar to `storage.generations.filter()`
35
+ // this also contains the generation strategy, such as "uuid"
36
+ isGenerated = [
37
+ 'createDate',
38
+ 'updateDate',
39
+ 'deleteDate',
40
+ 'version',
41
+ 'treeChildrenCount',
42
+ 'treeLevel',
43
+ 'objectId'
44
+ ].includes(col.mode) || !!storage.findGenerated(col.target, col.propertyName);
45
+ Reflect.decorate([
46
+ ApiProperty({
47
+ isArray: col.options.array || [
48
+ 'array',
49
+ 'simple-array',
50
+ 'set',
51
+ 'cube',
52
+ 'ltree'
53
+ ].includes(col.options.type),
54
+ readOnly: isGenerated,
55
+ // try using the column type as "format",
56
+ // unless `typeORMToSwagger()` returned the correct one
57
+ // todo: if `format` cannot detected, try to infer it from the column name
58
+ // for instance:
59
+ // - email -> format: email
60
+ // - password -> format: password
61
+ // - image -> format: binary
62
+ format: col.options.type?.toString(),
63
+ ...col.options.type ? typeORMToSwagger(col.options.type) : {},
64
+ enumName: col.options.enumName,
65
+ default: col.options.default,
66
+ required: !!col.options.nullable,
67
+ nullable: col.options.nullable,
68
+ ...col.options.enum ? {
69
+ enum: col.options.enum
70
+ } : {},
71
+ ...col.options.length ? {
72
+ maxLength: +col.options.length
73
+ } : {},
74
+ ...props
75
+ })
76
+ ], col.target.prototype, col.propertyName, Reflect.getOwnPropertyDescriptor(col.target.prototype, col.propertyName));
77
+ }
78
+ for (let rel of relations){
79
+ let props = Reflect.getMetadata('swagger/apiModelProperties', rel.target.prototype, rel.propertyName);
80
+ // todo: get the reference column name, mostly the primary key of the other table
81
+ // for instance if `posts.user` -> `user.id`, then FK name is "id"
82
+ let foreignKey = joinColumns.find((el)=>el.propertyName === rel.propertyName)?.foreignKeyConstraintName || // todo: this should be the PK of the other table,
83
+ // but currently we are unable to get the other table
84
+ 'id';
85
+ if (rel.relationType.endsWith('to-one')) {
86
+ // todo: in one-to-one, we may want to display this field in the join column only
87
+ // for instance, for this relation `user.info <-> info.user`,
88
+ // we may need to inset `user.info.id`, not `info.user.id`
89
+ Reflect.decorate([
90
+ ApiProperty({
91
+ // todo: `type: rel.type` -> gives `string`
92
+ // or get `design:type` metadata -> gives `{}`
93
+ // i.e. `Reflect.getMetadata('design:type',(<Function>rel.target).prototype, rel.propertyName)`
94
+ type: 'object',
95
+ // todo: properties{} should refer to the other table definition
96
+ // for `post.user`, it should be `user{}` props
97
+ properties: {
98
+ // todo: get foreign column name (by default the PK of the other table), type (string/number), and format (uuid)
99
+ [foreignKey]: {
100
+ type: 'string'
101
+ }
102
+ },
103
+ required: !!rel.options.nullable,
104
+ nullable: rel.options.nullable,
105
+ ...props
106
+ })
107
+ ], rel.target.prototype, rel.propertyName, Reflect.getOwnPropertyDescriptor(rel.target.prototype, rel.propertyName));
108
+ } else {
109
+ // `*-to-many` relations should appear in GET operations only
110
+ // we don't need to insert them when creating or updating the record
111
+ // we insert them from the other side
112
+ // for instance, for this relation `posts.user <-> user.posts`,
113
+ // we often refer to the user when inserting a new post, not the other way around
114
+ // todo: we need to specify the relation definition, i.e. the shape of the other table
115
+ // todo: in `many-to-many`, we can allow inserting relations from the joining side
116
+ // todo: these fields don't display in Swagger UI even after applying `@ApiProperty()` on them
117
+ ApiProperty({
118
+ readOnly: true,
119
+ isArray: true,
120
+ type: 'array',
121
+ items: {
122
+ type: 'object',
123
+ properties: {
124
+ [foreignKey]: {
125
+ type: 'string'
126
+ }
127
+ }
128
+ },
129
+ ...props
130
+ });
131
+ }
132
+ }
133
+ }
134
+
135
+ //# sourceMappingURL=register-entities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/register-entities.ts"],"sourcesContent":["import { typeORMToSwagger } from './utils/typeorm-to-swagger.js';\nimport { ApiProperty } from '@nestjs/swagger';\nimport { getMetadataArgsStorage } from 'typeorm';\n\n/**\n * Register models and add Swagger and class-validator decorators\n * call this function before `SwaggerModule.createDocument()`\n *\n * This function extracts info from each column to generate best Swagger model and best validations as much as possible.\n *\n * add `@Hide()` to properties that you want to hide from Swagger\n * `@ApiHideProperty()` doesn't work.\n *\n * to skip processing a property by this function add `@Skip()`\n *\n * to apply this function on a specific model, decorate it with `@Entity()`\n * or use `registerEntities([model])`\n *\n * existing options in `@ApiProperty()` will be merged into options generated by this function\n *\n * `ManyToMany` and `OneToMany` relations are ignored by default, you need to add `@ApiProperty()` to include them\n * `OneToOne` and `ManyToOne` relation is included but with a different name, after suffixing the primary key name\n *\n * @param models list of models to apply this function to\n */\nexport function registerEntities(models?: Function[]) {\n let storage = getMetadataArgsStorage(),\n // todo: handle when col.target is string\n cols = storage.columns.filter((el) => typeof el.target === 'function'),\n relations = storage.relations.filter(\n (el) =>\n typeof el.target === 'function' && el.relationType.endsWith('to-one'),\n ),\n joinColumns = storage.joinColumns;\n\n if (Array.isArray(models)) {\n cols = cols.filter((el) => models.includes(el.target as Function));\n relations = relations.filter((el) =>\n models.includes(el.target as Function),\n );\n }\n\n for (let col of cols) {\n // existing props, i.e. options that the consumer already specified in `@ApiProperty()`\n let props = Reflect.getMetadata(\n 'swagger/apiModelProperties',\n (col.target as Function).prototype,\n col.propertyName,\n ),\n // if the column is auto generated\n // this is similar to `storage.generations.filter()`\n // this also contains the generation strategy, such as \"uuid\"\n isGenerated =\n [\n 'createDate',\n 'updateDate',\n 'deleteDate',\n 'version',\n 'treeChildrenCount',\n 'treeLevel',\n 'objectId',\n ].includes(col.mode) ||\n !!storage.findGenerated(col.target, col.propertyName);\n\n Reflect.decorate(\n [\n ApiProperty({\n isArray:\n col.options.array ||\n ['array', 'simple-array', 'set', 'cube', 'ltree'].includes(\n col.options.type as string,\n ),\n readOnly: isGenerated,\n // try using the column type as \"format\",\n // unless `typeORMToSwagger()` returned the correct one\n // todo: if `format` cannot detected, try to infer it from the column name\n // for instance:\n // - email -> format: email\n // - password -> format: password\n // - image -> format: binary\n format: col.options.type?.toString(),\n ...(col.options.type ? typeORMToSwagger(col.options.type) : {}),\n enumName: col.options.enumName,\n default: col.options.default,\n required: !!col.options.nullable,\n nullable: col.options.nullable,\n ...(col.options.enum ? { enum: col.options.enum } : {}),\n ...(col.options.length ? { maxLength: +col.options.length } : {}),\n ...props,\n }),\n ],\n (col.target as Function).prototype,\n col.propertyName,\n Reflect.getOwnPropertyDescriptor(\n (col.target as Function).prototype,\n col.propertyName,\n ),\n );\n }\n\n for (let rel of relations) {\n let props = Reflect.getMetadata(\n 'swagger/apiModelProperties',\n (rel.target as Function).prototype,\n rel.propertyName,\n );\n // todo: get the reference column name, mostly the primary key of the other table\n // for instance if `posts.user` -> `user.id`, then FK name is \"id\"\n let foreignKey =\n joinColumns.find((el) => el.propertyName === rel.propertyName)\n ?.foreignKeyConstraintName ||\n // todo: this should be the PK of the other table,\n // but currently we are unable to get the other table\n 'id';\n\n if (rel.relationType.endsWith('to-one')) {\n // todo: in one-to-one, we may want to display this field in the join column only\n // for instance, for this relation `user.info <-> info.user`,\n // we may need to inset `user.info.id`, not `info.user.id`\n Reflect.decorate(\n [\n ApiProperty({\n // todo: `type: rel.type` -> gives `string`\n // or get `design:type` metadata -> gives `{}`\n // i.e. `Reflect.getMetadata('design:type',(<Function>rel.target).prototype, rel.propertyName)`\n type: 'object',\n // todo: properties{} should refer to the other table definition\n // for `post.user`, it should be `user{}` props\n properties: {\n // todo: get foreign column name (by default the PK of the other table), type (string/number), and format (uuid)\n [foreignKey]: { type: 'string' },\n },\n required: !!rel.options.nullable,\n nullable: rel.options.nullable,\n ...props,\n }),\n ],\n (rel.target as Function).prototype,\n rel.propertyName,\n Reflect.getOwnPropertyDescriptor(\n (rel.target as Function).prototype,\n rel.propertyName,\n ),\n );\n } else {\n // `*-to-many` relations should appear in GET operations only\n // we don't need to insert them when creating or updating the record\n // we insert them from the other side\n // for instance, for this relation `posts.user <-> user.posts`,\n // we often refer to the user when inserting a new post, not the other way around\n // todo: we need to specify the relation definition, i.e. the shape of the other table\n // todo: in `many-to-many`, we can allow inserting relations from the joining side\n // todo: these fields don't display in Swagger UI even after applying `@ApiProperty()` on them\n ApiProperty({\n readOnly: true,\n isArray: true,\n type: 'array',\n items: {\n type: 'object',\n properties: {\n [foreignKey]: { type: 'string' },\n },\n // required: [foreignKey],\n },\n ...props,\n });\n }\n }\n}\n"],"names":["typeORMToSwagger","ApiProperty","getMetadataArgsStorage","registerEntities","models","storage","cols","columns","filter","el","target","relations","relationType","endsWith","joinColumns","Array","isArray","includes","col","props","Reflect","getMetadata","prototype","propertyName","isGenerated","mode","findGenerated","decorate","options","array","type","readOnly","format","toString","enumName","default","required","nullable","enum","length","maxLength","getOwnPropertyDescriptor","rel","foreignKey","find","foreignKeyConstraintName","properties","items"],"mappings":"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"}
@@ -1,14 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "logger", {
6
- enumerable: true,
7
- get: function() {
8
- return logger;
9
- }
10
- });
11
- const _common = require("@nestjs/common");
12
- const logger = new _common.Logger();
1
+ import { Logger } from "@nestjs/common";
2
+ export const logger = new Logger();
13
3
 
14
4
  //# sourceMappingURL=logger.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/logger.ts"],"sourcesContent":["import { Logger } from '@nestjs/common';\n\nexport const logger = new Logger();\n"],"names":["logger","Logger"],"mappings":";;;;+BAEaA;;;eAAAA;;;wBAFU;AAEhB,MAAMA,SAAS,IAAIC,cAAM"}
1
+ {"version":3,"sources":["../../../src/utils/logger.ts"],"sourcesContent":["import { Logger } from '@nestjs/common';\n\nexport const logger = new Logger();\n"],"names":["Logger","logger"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAiB;AAExC,OAAO,MAAMC,SAAS,IAAID,SAAS"}
@@ -0,0 +1,3 @@
1
+ import { ApiPropertyOptions } from '@nestjs/swagger';
2
+ import { ColumnType } from 'typeorm';
3
+ export declare function typeORMToSwagger(type: ColumnType): ApiPropertyOptions;