@impactor/nest 3.0.2 → 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 (133) hide show
  1. package/index.d.ts +41 -41
  2. package/package.json +29 -33
  3. package/src/configs/app.d.ts +5 -4
  4. package/src/configs/app.js +10 -18
  5. package/src/configs/app.js.map +1 -1
  6. package/src/configs/database.js +1 -11
  7. package/src/configs/database.js.map +1 -1
  8. package/src/configs/microservice.js +6 -16
  9. package/src/configs/microservice.js.map +1 -1
  10. package/src/configs/multi-queue-rabbitmq-server.js +28 -34
  11. package/src/configs/multi-queue-rabbitmq-server.js.map +1 -1
  12. package/src/configs/redis-config.js +1 -11
  13. package/src/configs/redis-config.js.map +1 -1
  14. package/src/create-app.d.ts +1 -1
  15. package/src/create-app.js +44 -61
  16. package/src/create-app.js.map +1 -1
  17. package/src/create-microservice.d.ts +1 -1
  18. package/src/create-microservice.js +18 -22
  19. package/src/create-microservice.js.map +1 -1
  20. package/src/create-testing-microservice.d.ts +1 -1
  21. package/src/create-testing-microservice.js +16 -20
  22. package/src/create-testing-microservice.js.map +1 -1
  23. package/src/decorators/controller/add-decorators/add-controller-path.d.ts +1 -1
  24. package/src/decorators/controller/add-decorators/add-controller-path.js +7 -15
  25. package/src/decorators/controller/add-decorators/add-controller-path.js.map +1 -1
  26. package/src/decorators/controller/add-decorators/add-controller-tags.d.ts +1 -1
  27. package/src/decorators/controller/add-decorators/add-controller-tags.js +9 -17
  28. package/src/decorators/controller/add-decorators/add-controller-tags.js.map +1 -1
  29. package/src/decorators/controller/add-decorators/add-http-method.d.ts +2 -2
  30. package/src/decorators/controller/add-decorators/add-http-method.js +13 -20
  31. package/src/decorators/controller/add-decorators/add-http-method.js.map +1 -1
  32. package/src/decorators/controller/add-decorators/add-swagger-body.d.ts +2 -2
  33. package/src/decorators/controller/add-decorators/add-swagger-body.js +7 -17
  34. package/src/decorators/controller/add-decorators/add-swagger-body.js.map +1 -1
  35. package/src/decorators/controller/add-decorators/add-swagger-operation.d.ts +2 -2
  36. package/src/decorators/controller/add-decorators/add-swagger-operation.js +8 -15
  37. package/src/decorators/controller/add-decorators/add-swagger-operation.js.map +1 -1
  38. package/src/decorators/controller/add-decorators/add-swagger-params.d.ts +2 -2
  39. package/src/decorators/controller/add-decorators/add-swagger-params.js +9 -16
  40. package/src/decorators/controller/add-decorators/add-swagger-params.js.map +1 -1
  41. package/src/decorators/controller/add-decorators/add-swagger-response.d.ts +2 -2
  42. package/src/decorators/controller/add-decorators/add-swagger-response.js +10 -20
  43. package/src/decorators/controller/add-decorators/add-swagger-response.js.map +1 -1
  44. package/src/decorators/controller/controller.decorator.d.ts +1 -1
  45. package/src/decorators/controller/controller.decorator.js +12 -13
  46. package/src/decorators/controller/controller.decorator.js.map +1 -1
  47. package/src/decorators/controller/controller.factory.d.ts +1 -1
  48. package/src/decorators/controller/controller.factory.js +59 -67
  49. package/src/decorators/controller/controller.factory.js.map +1 -1
  50. package/src/decorators/controller/default-options.d.ts +1 -1
  51. package/src/decorators/controller/default-options.js +11 -26
  52. package/src/decorators/controller/default-options.js.map +1 -1
  53. package/src/decorators/controller/dto/empty.dto.js +2 -12
  54. package/src/decorators/controller/dto/empty.dto.js.map +1 -1
  55. package/src/decorators/controller/dto/update-response.dto.js +2 -12
  56. package/src/decorators/controller/dto/update-response.dto.js.map +1 -1
  57. package/src/decorators/controller/interceptors/query.interceptor.d.ts +1 -1
  58. package/src/decorators/controller/interceptors/query.interceptor.js +10 -19
  59. package/src/decorators/controller/interceptors/query.interceptor.js.map +1 -1
  60. package/src/decorators/controller/route-handler.d.ts +2 -2
  61. package/src/decorators/controller/route-handler.js +8 -16
  62. package/src/decorators/controller/route-handler.js.map +1 -1
  63. package/src/decorators/controller/route.decorator.d.ts +1 -1
  64. package/src/decorators/controller/route.decorator.js +11 -11
  65. package/src/decorators/controller/route.decorator.js.map +1 -1
  66. package/src/decorators/controller/services/crud-typeorm.service.d.ts +1 -2
  67. package/src/decorators/controller/services/crud-typeorm.service.js +19 -24
  68. package/src/decorators/controller/services/crud-typeorm.service.js.map +1 -1
  69. package/src/decorators/controller/types/index.d.ts +2 -2
  70. package/src/decorators/controller/types/index.js +1 -4
  71. package/src/decorators/controller/types/index.js.map +1 -1
  72. package/src/decorators/controller/utils/merge-options.d.ts +1 -1
  73. package/src/decorators/controller/utils/merge-options.js +3 -13
  74. package/src/decorators/controller/utils/merge-options.js.map +1 -1
  75. package/src/decorators/controller/utils/reflect.d.ts +2 -2
  76. package/src/decorators/controller/utils/reflect.js +24 -38
  77. package/src/decorators/controller/utils/reflect.js.map +1 -1
  78. package/src/decorators/entity.decorator.js +42 -35
  79. package/src/decorators/entity.decorator.js.map +1 -1
  80. package/src/decorators/prop.decorator.js +79 -38
  81. package/src/decorators/prop.decorator.js.map +1 -1
  82. package/src/exceptions/rpc-bad-request.exception.d.ts +1 -1
  83. package/src/exceptions/rpc-bad-request.exception.js +5 -15
  84. package/src/exceptions/rpc-bad-request.exception.js.map +1 -1
  85. package/src/exceptions/rpc-base.exception.js +10 -15
  86. package/src/exceptions/rpc-base.exception.js.map +1 -1
  87. package/src/exceptions/rpc-conflict.exception.d.ts +1 -1
  88. package/src/exceptions/rpc-conflict.exception.js +5 -15
  89. package/src/exceptions/rpc-conflict.exception.js.map +1 -1
  90. package/src/exceptions/rpc-internal-server-error.exception.d.ts +1 -1
  91. package/src/exceptions/rpc-internal-server-error.exception.js +5 -15
  92. package/src/exceptions/rpc-internal-server-error.exception.js.map +1 -1
  93. package/src/exceptions/rpc-method-not-allowed.exception.d.ts +1 -1
  94. package/src/exceptions/rpc-method-not-allowed.exception.js +5 -15
  95. package/src/exceptions/rpc-method-not-allowed.exception.js.map +1 -1
  96. package/src/exceptions/rpc-not-found.exception.d.ts +1 -1
  97. package/src/exceptions/rpc-not-found.exception.js +5 -15
  98. package/src/exceptions/rpc-not-found.exception.js.map +1 -1
  99. package/src/exceptions/rpc-not-implemented.exception.d.ts +1 -1
  100. package/src/exceptions/rpc-not-implemented.exception.js +5 -15
  101. package/src/exceptions/rpc-not-implemented.exception.js.map +1 -1
  102. package/src/exceptions/rpc-unauthorized.exception.d.ts +1 -1
  103. package/src/exceptions/rpc-unauthorized.exception.js +5 -15
  104. package/src/exceptions/rpc-unauthorized.exception.js.map +1 -1
  105. package/src/filters/error-to-rpc-exception.filter.js +12 -22
  106. package/src/filters/error-to-rpc-exception.filter.js.map +1 -1
  107. package/src/filters/error-to-ws-exception.filter.js +10 -20
  108. package/src/filters/error-to-ws-exception.filter.js.map +1 -1
  109. package/src/filters/typeorm-exception.filter.js +9 -19
  110. package/src/filters/typeorm-exception.filter.js.map +1 -1
  111. package/src/filters/ws-exception.filter.js +6 -16
  112. package/src/filters/ws-exception.filter.js.map +1 -1
  113. package/src/generate-metadata.d.ts +3 -3
  114. package/src/generate-metadata.js +18 -74
  115. package/src/generate-metadata.js.map +1 -1
  116. package/src/guards/auth.guard.js +43 -44
  117. package/src/guards/auth.guard.js.map +1 -1
  118. package/src/modules/basic/basic.controller.js +6 -16
  119. package/src/modules/basic/basic.controller.js.map +1 -1
  120. package/src/modules/basic/basic.module.js +15 -23
  121. package/src/modules/basic/basic.module.js.map +1 -1
  122. package/src/modules/basic/basic.service.js +4 -14
  123. package/src/modules/basic/basic.service.js.map +1 -1
  124. package/src/register-entities.js +37 -20
  125. package/src/register-entities.js.map +1 -1
  126. package/src/utils/logger.js +2 -12
  127. package/src/utils/logger.js.map +1 -1
  128. package/src/utils/typeorm-to-swagger.d.ts +1 -1
  129. package/src/utils/typeorm-to-swagger.js +4 -11
  130. package/src/utils/typeorm-to-swagger.js.map +1 -1
  131. package/nx.json +0 -190
  132. package/src/nest-swagger-metadata.js +0 -593
  133. package/src/nest-swagger-metadata.js.map +0 -1
@@ -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","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AI;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"}
@@ -1,18 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "registerEntities", {
6
- enumerable: true,
7
- get: function() {
8
- return registerEntities;
9
- }
10
- });
11
- const _typeormtoswagger = require("./utils/typeorm-to-swagger");
12
- const _swagger = require("@nestjs/swagger");
13
- const _typeorm = require("typeorm");
14
- function registerEntities(models) {
15
- let storage = (0, _typeorm.getMetadataArgsStorage)(), // todo: handle when col.target is string
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
16
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;
17
27
  if (Array.isArray(models)) {
18
28
  cols = cols.filter((el)=>models.includes(el.target));
@@ -33,7 +43,14 @@ function registerEntities(models) {
33
43
  'objectId'
34
44
  ].includes(col.mode) || !!storage.findGenerated(col.target, col.propertyName);
35
45
  Reflect.decorate([
36
- (0, _swagger.ApiProperty)({
46
+ ApiProperty({
47
+ isArray: col.options.array || [
48
+ 'array',
49
+ 'simple-array',
50
+ 'set',
51
+ 'cube',
52
+ 'ltree'
53
+ ].includes(col.options.type),
37
54
  readOnly: isGenerated,
38
55
  // try using the column type as "format",
39
56
  // unless `typeORMToSwagger()` returned the correct one
@@ -42,8 +59,8 @@ function registerEntities(models) {
42
59
  // - email -> format: email
43
60
  // - password -> format: password
44
61
  // - image -> format: binary
45
- format: col.options.type,
46
- ...col.options.type ? (0, _typeormtoswagger.typeORMToSwagger)(col.options.type) : {},
62
+ format: col.options.type?.toString(),
63
+ ...col.options.type ? typeORMToSwagger(col.options.type) : {},
47
64
  enumName: col.options.enumName,
48
65
  default: col.options.default,
49
66
  required: !!col.options.nullable,
@@ -70,7 +87,7 @@ function registerEntities(models) {
70
87
  // for instance, for this relation `user.info <-> info.user`,
71
88
  // we may need to inset `user.info.id`, not `info.user.id`
72
89
  Reflect.decorate([
73
- (0, _swagger.ApiProperty)({
90
+ ApiProperty({
74
91
  // todo: `type: rel.type` -> gives `string`
75
92
  // or get `design:type` metadata -> gives `{}`
76
93
  // i.e. `Reflect.getMetadata('design:type',(<Function>rel.target).prototype, rel.propertyName)`
@@ -97,7 +114,7 @@ function registerEntities(models) {
97
114
  // todo: we need to specify the relation definition, i.e. the shape of the other table
98
115
  // todo: in `many-to-many`, we can allow inserting relations from the joining side
99
116
  // todo: these fields don't display in Swagger UI even after applying `@ApiProperty()` on them
100
- (0, _swagger.ApiProperty)({
117
+ ApiProperty({
101
118
  readOnly: true,
102
119
  isArray: true,
103
120
  type: 'array',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/register-entities.ts"],"sourcesContent":["import { typeORMToSwagger } from './utils/typeorm-to-swagger';\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 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,\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":["registerEntities","models","storage","getMetadataArgsStorage","cols","columns","filter","el","target","relations","relationType","endsWith","joinColumns","Array","isArray","includes","col","props","Reflect","getMetadata","prototype","propertyName","isGenerated","mode","findGenerated","decorate","ApiProperty","readOnly","format","options","type","typeORMToSwagger","enumName","default","required","nullable","enum","length","maxLength","getOwnPropertyDescriptor","rel","foreignKey","find","foreignKeyConstraintName","properties","items"],"mappings":";;;;+BAyBgBA;;;eAAAA;;;kCAzBiB;yBACL;yBACW;AAuBhC,SAASA,iBAAiBC,MAAmB;IAClD,IAAIC,UAAUC,IAAAA,+BAAsB,KAClC,yCAAyC;IACzCC,OAAOF,QAAQG,OAAO,CAACC,MAAM,CAAC,CAACC,KAAO,OAAOA,GAAGC,MAAM,KAAK,aAC3DC,YAAYP,QAAQO,SAAS,CAACH,MAAM,CAClC,CAACC,KACC,OAAOA,GAAGC,MAAM,KAAK,cAAcD,GAAGG,YAAY,CAACC,QAAQ,CAAC,YAEhEC,cAAcV,QAAQU,WAAW;IAEnC,IAAIC,MAAMC,OAAO,CAACb,SAAS;QACzBG,OAAOA,KAAKE,MAAM,CAAC,CAACC,KAAON,OAAOc,QAAQ,CAACR,GAAGC,MAAM;QACpDC,YAAYA,UAAUH,MAAM,CAAC,CAACC,KAC5BN,OAAOc,QAAQ,CAACR,GAAGC,MAAM;IAE7B;IAEA,KAAK,IAAIQ,OAAOZ,KAAM;QACpB,uFAAuF;QACvF,IAAIa,QAAQC,QAAQC,WAAW,CAC3B,8BACA,AAACH,IAAIR,MAAM,CAAcY,SAAS,EAClCJ,IAAIK,Y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,IAAIhC,MAAM,CAAcY,SAAS,EAClCoB,IAAInB,YAAY;QAElB,iFAAiF;QACjF,kEAAkE;QAClE,IAAIoB,aACF7B,YAAY8B,IAAI,CAAC,CAACnC,KAAOA,GAAGc,YAAY,KAAKmB,IAAInB,YAAY,GACzDsB,4BACJ,kDAAkD;QAClD,qDAAqD;QACrD;QAEF,IAAIH,IAAI9B,YAAY,CAACC,QAAQ,CAAC,WAAW;YACvC,iFAAiF;YACjF,6DAA6D;YAC7D,0DAA0D;YAC1DO,QAAQO,QAAQ,CACd;gBACEC,IAAAA,oBAAW,EAAC;oBACV,2CAA2C;oBAC3C,8CAA8C;oBAC9C,+FAA+F;oBAC/FI,MAAM;oBACN,gEAAgE;oBAChE,+CAA+C;oBAC/Cc,YAAY;wBACV,gHAAgH;wBAChH,CAACH,WAAW,EAAE;4BAAEX,MAAM;wBAAS;oBACjC;oBACAI,UAAU,CAAC,CAACM,IAAIX,OAAO,CAACM,QAAQ;oBAChCA,UAAUK,IAAIX,OAAO,CAACM,QAAQ;oBAC9B,GAAGlB,KAAK;gBACV;aACD,EACD,AAACuB,IAAIhC,MAAM,CAAcY,SAAS,EAClCoB,IAAInB,YAAY,EAChBH,QAAQqB,wBAAwB,CAC9B,AAACC,IAAIhC,MAAM,CAAcY,SAAS,EAClCoB,IAAInB,YAAY;QAGtB,OAAO;YACL,6DAA6D;YAC7D,oEAAoE;YACpE,qCAAqC;YACrC,+DAA+D;YAC/D,iFAAiF;YACjF,sFAAsF;YACtF,kFAAkF;YAClF,8FAA8F;YAC9FK,IAAAA,oBAAW,EAAC;gBACVC,UAAU;gBACVb,SAAS;gBACTgB,MAAM;gBACNe,OAAO;oBACLf,MAAM;oBACNc,YAAY;wBACV,CAACH,WAAW,EAAE;4BAAEX,MAAM;wBAAS;oBACjC;gBAEF;gBACA,GAAGb,KAAK;YACV;QACF;IACF;AACF"}
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":"AAAA,SAASA,gBAAgB,QAAQ,gCAAgC;AACjE,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,sBAAsB,QAAQ,UAAU;AAEjD;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,SAASC,iBAAiBC,MAAmB;IAClD,IAAIC,UAAUH,0BACZ,yCAAyC;IACzCI,OAAOD,QAAQE,OAAO,CAACC,MAAM,CAAC,CAACC,KAAO,OAAOA,GAAGC,MAAM,KAAK,aAC3DC,YAAYN,QAAQM,SAAS,CAACH,MAAM,CAClC,CAACC,KACC,OAAOA,GAAGC,MAAM,KAAK,cAAcD,GAAGG,YAAY,CAACC,QAAQ,CAAC,YAEhEC,cAAcT,QAAQS,WAAW;IAEnC,IAAIC,MAAMC,OAAO,CAACZ,SAAS;QACzBE,OAAOA,KAAKE,MAAM,CAAC,CAACC,KAAOL,OAAOa,QAAQ,CAACR,GAAGC,MAAM;QACpDC,YAAYA,UAAUH,MAAM,CAAC,CAACC,KAC5BL,OAAOa,QAAQ,CAACR,GAAGC,MAAM;IAE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V8B,UAAU;gBACVf,SAAS;gBACTc,MAAM;gBACNiB,OAAO;oBACLjB,MAAM;oBACNgB,YAAY;wBACV,CAACH,WAAW,EAAE;4BAAEb,MAAM;wBAAS;oBACjC;gBAEF;gBACA,GAAGX,KAAK;YACV;QACF;IACF;AACF"}
@@ -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"}
@@ -1,3 +1,3 @@
1
1
  import { ApiPropertyOptions } from '@nestjs/swagger';
2
- import { ColumnType } from 'typeorm/driver/types/ColumnTypes';
2
+ import { ColumnType } from 'typeorm';
3
3
  export declare function typeORMToSwagger(type: ColumnType): ApiPropertyOptions;
@@ -1,14 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "typeORMToSwagger", {
6
- enumerable: true,
7
- get: function() {
8
- return typeORMToSwagger;
9
- }
10
- });
11
- function typeORMToSwagger(type) {
1
+ /**
2
+ * extract openAPI type and format from TypeORM column type
3
+ * @example `typeORMToSwaggerType("file")` // { type: 'string', format: 'binary' }
4
+ */ export function typeORMToSwagger(type) {
12
5
  // the column type as string
13
6
  // it may be a BooleanConstructor | DateConstructor | ....
14
7
  let value = (typeof type === 'string' ? type : type.name).toLowerCase();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/typeorm-to-swagger.ts"],"sourcesContent":["import { ApiPropertyOptions } from '@nestjs/swagger';\nimport { ColumnType } from 'typeorm/driver/types/ColumnTypes';\n\n/**\n * extract openAPI type and format from TypeORM column type\n * @example `typeORMToSwaggerType(\"file\")` // { type: 'string', format: 'binary' }\n */\nexport function typeORMToSwagger(type: ColumnType): ApiPropertyOptions {\n // the column type as string\n // it may be a BooleanConstructor | DateConstructor | ....\n let value = (typeof type === 'string' ? type : type.name).toLowerCase();\n\n // numbers\n if (\n [\n 'numeric',\n 'number',\n 'int',\n 'int2',\n 'int4',\n 'int8',\n 'int64',\n 'integer',\n 'tinyint',\n 'smallint',\n 'mediumint',\n 'bigint',\n 'unsigned big int',\n 'rowid',\n 'urowid',\n 'float',\n 'float4',\n 'float8',\n 'float64',\n 'money',\n 'smallmoney',\n 'decimal',\n 'smalldecimal',\n 'dec',\n 'double',\n 'double precision',\n 'fixed',\n 'real',\n ].includes(value)\n ) {\n // todo: set the best 'format' for each type\n return { type: 'number' };\n }\n\n // booleans\n if (['boolean', 'bool', 'bit', 'bit varying', 'varbit'].includes(value)) {\n return { type: 'boolean' };\n }\n\n // arrays / collections\n if (['array', 'simple-array', 'set', 'cube', 'ltree'].includes(value)) {\n return { type: 'array' };\n }\n\n // files\n if (\n [\n 'blob',\n 'longblob',\n 'mediumblob',\n 'tinyblob',\n 'bytea',\n 'bytes',\n 'image',\n 'rowversion',\n 'raw',\n 'long raw',\n 'bfile',\n 'binary',\n 'varbinary',\n ].includes(value)\n ) {\n // todo: openAPI v3 changed 'file' to 'string' with format 'binary' | 'byte'\n // https://swagger.io/docs/specification/v3_0/data-models/data-types/#files\n return { type: 'string', format: 'binary' };\n }\n\n // date\n if (['date'].includes(value)) {\n return { type: 'string', format: 'date' };\n }\n\n if (['year'].includes(value)) {\n return {\n type: 'integer',\n format: 'int32',\n example: new Date().getFullYear(),\n };\n }\n\n // time\n if (['time', 'timetz'].includes(value)) {\n return { type: 'string', format: 'time' };\n }\n\n // date-time\n if (\n [\n 'timestamp',\n 'timestamptz',\n 'timestamp without time zone',\n 'timestamp with time zone',\n 'timestamp with local time zone',\n 'datetime',\n 'datetime2',\n 'datetimeoffset',\n 'smalldatetime',\n 'seconddate',\n ].includes(value)\n ) {\n return { type: 'string', format: 'date-time' };\n }\n\n // intervals and durations\n if (\n ['interval', 'interval year to month', 'interval day to second'].includes(\n value,\n )\n ) {\n return { type: 'string', format: 'duration', example: 'P1Y2M3DT4H5M6S' };\n }\n\n // strings\n if (\n [\n 'text',\n 'tinytext',\n 'shorttext',\n 'mediumtext',\n 'longtext',\n 'ntext',\n 'citext',\n 'string',\n 'character varying',\n 'varying character',\n 'char varying',\n 'varchar2',\n 'nvarchar',\n 'nvarchar2',\n 'national varchar',\n 'character',\n 'native character',\n 'varchar',\n 'char',\n 'nchar',\n 'national char',\n 'alphanum',\n 'jsonpath',\n 'xml',\n 'long',\n 'clob',\n 'nclob',\n // ranges\n // this can also represented as object `{start, end}`\n 'int4range',\n 'int8range',\n 'numrange',\n 'tsrange',\n 'tstzrange',\n 'daterange',\n 'int4multirange',\n 'int8multirange',\n 'nummultirange',\n 'tsmultirange',\n 'tstzmultirange',\n 'datemultirange',\n\n // enums\n 'enum',\n 'simple-enum',\n // network\n 'cidr',\n 'inet',\n 'inet4',\n 'inet6',\n 'macaddr',\n 'macaddr8',\n // full-text search types\n 'tsvector',\n 'tsquery',\n // identifiers\n 'rowid',\n 'urowid',\n 'hierarchyid',\n 'sql_variant',\n ].includes(value)\n ) {\n return { type: 'string' };\n }\n\n if (\n [\n 'uuid',\n // most databases generates a 128-bit GUID, the same as a UUID\n // so, it is safe to represent it in Swagger UI as a UUID string\n 'uniqueidentifier',\n ].includes(value)\n ) {\n return { type: 'string', format: 'uuid' };\n }\n\n // vectors\n if (['vector', 'halfvec', 'half_vector', 'real_vector'].includes(value)) {\n return {\n type: 'array',\n items: { type: 'number' },\n };\n }\n\n // JSON\n if (['json', 'jsonb', 'simple-json', 'hstore'].includes(value)) {\n return {\n type: 'object',\n items: { type: 'number' },\n // in hstore, keys must ve string\n additionalProperties: value === 'hstore' ? { type: 'string' } : true,\n };\n }\n\n // geometry types\n if (\n [\n 'geometry',\n 'geography',\n 'st_geometry',\n 'st_point',\n 'point',\n 'line',\n 'polygon',\n 'circle',\n 'multipolygon',\n 'linestring',\n 'multilinestring',\n 'multipoint',\n 'geometrycollection',\n 'lseg',\n 'box',\n 'path',\n ].includes(value)\n ) {\n return {\n // they're saved as JSON objects\n type: 'object',\n properties: {\n type: { type: 'string', example: 'Point' },\n coordinates: {\n type: 'array',\n items: { type: 'number' },\n example: [125.6, 10.1],\n },\n },\n required: ['type', 'coordinates'],\n description: 'GeoJSON object representing geometry or geography',\n };\n }\n\n return { type: 'null' };\n}\n"],"names":["typeORMToSwagger","type","value","name","toLowerCase","includes","format","example","Date","getFullYear","items","additionalProperties","properties","coordinates","required","description"],"mappings":";;;;+BAOgBA;;;eAAAA;;;AAAT,SAASA,iBAAiBC,IAAgB;IAC/C,4BAA4B;IAC5B,0DAA0D;IAC1D,IAAIC,QAAQ,AAAC,CAAA,OAAOD,SAAS,WAAWA,OAAOA,KAAKE,IAAI,AAAD,EAAGC,WAAW;IAErE,UAAU;IACV,IACE;QACE;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD,CAACC,QAAQ,CAACH,QACX;QACA,4CAA4C;QAC5C,OAAO;YAAED,MAAM;QAAS;IAC1B;IAEA,WAAW;IACX,IAAI;QAAC;QAAW;QAAQ;QAAO;QAAe;KAAS,CAACI,QAAQ,CAACH,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;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QAEA,QAAQ;QACR;QACA;QACA,UAAU;QACV;QACA;QACA;QACA;QACA;QACA;QACA,yBAAyB;QACzB;QACA;QACA,cAAc;QACd;QACA;QACA;QACA;KACD,CAACF,QAAQ,CAACH,QACX;QACA,OAAO;YAAED,MAAM;QAAS;IAC1B;IAEA,IACE;QACE;QACA,8DAA8D;QAC9D,gEAAgE;QAChE;KACD,CAACI,QAAQ,CAACH,QACX;QACA,OAAO;YAAED,MAAM;YAAUK,QAAQ;QAAO;IAC1C;IAEA,UAAU;IACV,IAAI;QAAC;QAAU;QAAW;QAAe;KAAc,CAACD,QAAQ,CAACH,QAAQ;QACvE,OAAO;YACLD,MAAM;YACNS,OAAO;gBAAET,MAAM;YAAS;QAC1B;IACF;IAEA,OAAO;IACP,IAAI;QAAC;QAAQ;QAAS;QAAe;KAAS,CAACI,QAAQ,CAACH,QAAQ;QAC9D,OAAO;YACLD,MAAM;YACNS,OAAO;gBAAET,MAAM;YAAS;YACxB,iCAAiC;YACjCU,sBAAsBT,UAAU,WAAW;gBAAED,MAAM;YAAS,IAAI;QAClE;IACF;IAEA,iBAAiB;IACjB,IACE;QACE;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD,CAACI,QAAQ,CAACH,QACX;QACA,OAAO;YACL,gCAAgC;YAChCD,MAAM;YACNW,YAAY;gBACVX,MAAM;oBAAEA,MAAM;oBAAUM,SAAS;gBAAQ;gBACzCM,aAAa;oBACXZ,MAAM;oBACNS,OAAO;wBAAET,MAAM;oBAAS;oBACxBM,SAAS;wBAAC;wBAAO;qBAAK;gBACxB;YACF;YACAO,UAAU;gBAAC;gBAAQ;aAAc;YACjCC,aAAa;QACf;IACF;IAEA,OAAO;QAAEd,MAAM;IAAO;AACxB"}
1
+ {"version":3,"sources":["../../../src/utils/typeorm-to-swagger.ts"],"sourcesContent":["import { ApiPropertyOptions } from '@nestjs/swagger';\nimport { ColumnType } from 'typeorm';\n\n/**\n * extract openAPI type and format from TypeORM column type\n * @example `typeORMToSwaggerType(\"file\")` // { type: 'string', format: 'binary' }\n */\nexport function typeORMToSwagger(type: ColumnType): ApiPropertyOptions {\n // the column type as string\n // it may be a BooleanConstructor | DateConstructor | ....\n let value = (typeof type === 'string' ? type : type.name).toLowerCase();\n\n // numbers\n if (\n [\n 'numeric',\n 'number',\n 'int',\n 'int2',\n 'int4',\n 'int8',\n 'int64',\n 'integer',\n 'tinyint',\n 'smallint',\n 'mediumint',\n 'bigint',\n 'unsigned big int',\n 'rowid',\n 'urowid',\n 'float',\n 'float4',\n 'float8',\n 'float64',\n 'money',\n 'smallmoney',\n 'decimal',\n 'smalldecimal',\n 'dec',\n 'double',\n 'double precision',\n 'fixed',\n 'real',\n ].includes(value)\n ) {\n // todo: set the best 'format' for each type\n return { type: 'number' };\n }\n\n // booleans\n if (['boolean', 'bool', 'bit', 'bit varying', 'varbit'].includes(value)) {\n return { type: 'boolean' };\n }\n\n // arrays / collections\n if (['array', 'simple-array', 'set', 'cube', 'ltree'].includes(value)) {\n return { type: 'array' };\n }\n\n // files\n if (\n [\n 'blob',\n 'longblob',\n 'mediumblob',\n 'tinyblob',\n 'bytea',\n 'bytes',\n 'image',\n 'rowversion',\n 'raw',\n 'long raw',\n 'bfile',\n 'binary',\n 'varbinary',\n ].includes(value)\n ) {\n // todo: openAPI v3 changed 'file' to 'string' with format 'binary' | 'byte'\n // https://swagger.io/docs/specification/v3_0/data-models/data-types/#files\n return { type: 'string', format: 'binary' };\n }\n\n // date\n if (['date'].includes(value)) {\n return { type: 'string', format: 'date' };\n }\n\n if (['year'].includes(value)) {\n return {\n type: 'integer',\n format: 'int32',\n example: new Date().getFullYear(),\n };\n }\n\n // time\n if (['time', 'timetz'].includes(value)) {\n return { type: 'string', format: 'time' };\n }\n\n // date-time\n if (\n [\n 'timestamp',\n 'timestamptz',\n 'timestamp without time zone',\n 'timestamp with time zone',\n 'timestamp with local time zone',\n 'datetime',\n 'datetime2',\n 'datetimeoffset',\n 'smalldatetime',\n 'seconddate',\n ].includes(value)\n ) {\n return { type: 'string', format: 'date-time' };\n }\n\n // intervals and durations\n if (\n ['interval', 'interval year to month', 'interval day to second'].includes(\n value,\n )\n ) {\n return { type: 'string', format: 'duration', example: 'P1Y2M3DT4H5M6S' };\n }\n\n // strings\n if (\n [\n 'text',\n 'tinytext',\n 'shorttext',\n 'mediumtext',\n 'longtext',\n 'ntext',\n 'citext',\n 'string',\n 'character varying',\n 'varying character',\n 'char varying',\n 'varchar2',\n 'nvarchar',\n 'nvarchar2',\n 'national varchar',\n 'character',\n 'native character',\n 'varchar',\n 'char',\n 'nchar',\n 'national char',\n 'alphanum',\n 'jsonpath',\n 'xml',\n 'long',\n 'clob',\n 'nclob',\n // ranges\n // this can also represented as object `{start, end}`\n 'int4range',\n 'int8range',\n 'numrange',\n 'tsrange',\n 'tstzrange',\n 'daterange',\n 'int4multirange',\n 'int8multirange',\n 'nummultirange',\n 'tsmultirange',\n 'tstzmultirange',\n 'datemultirange',\n\n // enums\n 'enum',\n 'simple-enum',\n // network\n 'cidr',\n 'inet',\n 'inet4',\n 'inet6',\n 'macaddr',\n 'macaddr8',\n // full-text search types\n 'tsvector',\n 'tsquery',\n // identifiers\n 'rowid',\n 'urowid',\n 'hierarchyid',\n 'sql_variant',\n ].includes(value)\n ) {\n return { type: 'string' };\n }\n\n if (\n [\n 'uuid',\n // most databases generates a 128-bit GUID, the same as a UUID\n // so, it is safe to represent it in Swagger UI as a UUID string\n 'uniqueidentifier',\n ].includes(value)\n ) {\n return { type: 'string', format: 'uuid' };\n }\n\n // vectors\n if (['vector', 'halfvec', 'half_vector', 'real_vector'].includes(value)) {\n return {\n type: 'array',\n items: { type: 'number' },\n };\n }\n\n // JSON\n if (['json', 'jsonb', 'simple-json', 'hstore'].includes(value)) {\n return {\n type: 'object',\n items: { type: 'number' },\n // in hstore, keys must ve string\n additionalProperties: value === 'hstore' ? { type: 'string' } : true,\n };\n }\n\n // geometry types\n if (\n [\n 'geometry',\n 'geography',\n 'st_geometry',\n 'st_point',\n 'point',\n 'line',\n 'polygon',\n 'circle',\n 'multipolygon',\n 'linestring',\n 'multilinestring',\n 'multipoint',\n 'geometrycollection',\n 'lseg',\n 'box',\n 'path',\n ].includes(value)\n ) {\n return {\n // they're saved as JSON objects\n type: 'object',\n properties: {\n type: { type: 'string', example: 'Point' },\n coordinates: {\n type: 'array',\n items: { type: 'number' },\n example: [125.6, 10.1],\n },\n },\n required: ['type', 'coordinates'],\n description: 'GeoJSON object representing geometry or geography',\n };\n }\n\n return { type: 'null' };\n}\n"],"names":["typeORMToSwagger","type","value","name","toLowerCase","includes","format","example","Date","getFullYear","items","additionalProperties","properties","coordinates","required","description"],"mappings":"AAGA;;;CAGC,GACD,OAAO,SAASA,iBAAiBC,IAAgB;IAC/C,4BAA4B;IAC5B,0DAA0D;IAC1D,IAAIC,QAAQ,AAAC,CAAA,OAAOD,SAAS,WAAWA,OAAOA,KAAKE,IAAI,AAAD,EAAGC,WAAW;IAErE,UAAU;IACV,IACE;QACE;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD,CAACC,QAAQ,CAACH,QACX;QACA,4CAA4C;QAC5C,OAAO;YAAED,MAAM;QAAS;IAC1B;IAEA,WAAW;IACX,IAAI;QAAC;QAAW;QAAQ;QAAO;QAAe;KAAS,CAACI,QAAQ,CAACH,QAAQ;QACvE,OAAO;YAAED,MAAM;QAAU;IAC3B;IAEA,uBAAuB;IACvB,IAAI;QAAC;QAAS;QAAgB;QAAO;QAAQ;KAAQ,CAACI,QAAQ,CAACH,QAAQ;QACrE,OAAO;YAAED,MAAM;QAAQ;IACzB;IAEA,QAAQ;IACR,IACE;QACE;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QAC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gE;QAChE;KACD,CAACI,QAAQ,CAACH,QACX;QACA,OAAO;YAAED,MAAM;YAAUK,QAAQ;QAAO;IAC1C;IAEA,UAAU;IACV,IAAI;QAAC;QAAU;QAAW;QAAe;KAAc,CAACD,QAAQ,CAACH,QAAQ;QACvE,OAAO;YACLD,MAAM;YACNS,OAAO;gBAAET,MAAM;YAAS;QAC1B;IACF;IAEA,OAAO;IACP,IAAI;QAAC;QAAQ;QAAS;QAAe;KAAS,CAACI,QAAQ,CAACH,QAAQ;QAC9D,OAAO;YACLD,MAAM;YACNS,OAAO;gBAAET,MAAM;YAAS;YACxB,iCAAiC;YACjCU,sBAAsBT,UAAU,WAAW;gBAAED,MAAM;YAAS,IAAI;QAClE;IACF;IAEA,iBAAiB;IACjB,IACE;QACE;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD,CAACI,QAAQ,CAACH,QACX;QACA,OAAO;YACL,gCAAgC;YAChCD,MAAM;YACNW,YAAY;gBACVX,MAAM;oBAAEA,MAAM;oBAAUM,SAAS;gBAAQ;gBACzCM,aAAa;oBACXZ,MAAM;oBACNS,OAAO;wBAAET,MAAM;oBAAS;oBACxBM,SAAS;wBAAC;wBAAO;qBAAK;gBACxB;YACF;YACAO,UAAU;gBAAC;gBAAQ;aAAc;YACjCC,aAAa;QACf;IACF;IAEA,OAAO;QAAEd,MAAM;IAAO;AACxB"}
package/nx.json DELETED
@@ -1,190 +0,0 @@
1
- {
2
- "$schema": "./node_modules/nx/schemas/nx-schema.json",
3
- "targetDefaults": {
4
- "build": {
5
- "executor": "@impactor/nx-manager:universal-builder",
6
- "dependsOn": ["typecheck", "prebuild", "^build"],
7
- "cache": true,
8
- "inputs": ["default", "^default"],
9
- "outputs": ["{projectRoot}/dist"],
10
- "options": {
11
- "forceRnDefaultPostBuild": true
12
- }
13
- },
14
- "serve": {
15
- "executor": "nx:run-commands",
16
- "dependsOn": ["build", "preserve"],
17
- "continuous": true,
18
- "options": {
19
- "cwd": "{projectRoot}",
20
- "command": "NODE_ENV=development pnpm tsx --env-file-if-exists=.env --env-file-if-exists=.env.local dist/main.js"
21
- },
22
- "configurations": {
23
- "production": {
24
- "command": "NODE_ENV=production pnpm tsx --env-file-if-exists=.env --env-file-if-exists=.env.local --env-file-if-exists=.env.production --env-file-if-exists=.env.production.local dist/main.js"
25
- }
26
- }
27
- },
28
- "nx-release-publish": {
29
- "options": {
30
- "packageRoot": "{projectRoot}/dist"
31
- }
32
- },
33
- "semantic-release": {
34
- "executor": "nx:run-commands",
35
- "dependsOn": ["build", "prerelease"],
36
- "options": {
37
- "cwd": "{projectRoot}",
38
- "command": "pnpm tsx node_modules/semantic-release/bin/semantic-release.js"
39
- },
40
- "configurations": {
41
- "local": {
42
- "command": "DOTENV_CONFIG_PATH=../../.env pnpm run release --no-ci"
43
- },
44
- "dry": {
45
- "command": "DOTENV_CONFIG_PATH=../../.env pnpm run release --no-ci --dry-run"
46
- }
47
- }
48
- },
49
- "test": {
50
- "inputs": ["test"],
51
- "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
52
- "dependsOn": ["^build", "pretest"],
53
- "configurations": {
54
- "unit": {
55
- "args": [
56
- "--testPathIgnorePatterns '.*\\.e2e\\.spec\\.ts$'",
57
- "--testPathIgnorePatterns '/.*-e2e/'",
58
- "--testPathIgnorePatterns '/.*-e2e/'"
59
- ]
60
- },
61
- "e2e": {
62
- "args": [
63
- "--testMatch '**/*-e2e/**/*.{spec,test}.[mc]?[jt]s?(x)'",
64
- "--testMatch '**/e2e/**/*.{spec,test}.[mc]?[jt]s?(x)'",
65
- "--testMatch '**/*.e2e.(spec|test).?([mc])[jt]s?(x)'"
66
- ]
67
- }
68
- }
69
- },
70
- "@angular/build:application": {
71
- "cache": true,
72
- "dependsOn": ["prebuild", "^build"],
73
- "inputs": ["default", "^default"]
74
- },
75
- "@nx/angular:package": {
76
- "cache": true,
77
- "dependsOn": ["^build"],
78
- "inputs": ["default", "^default"],
79
- "outputs": ["{projectRoot}/dist"],
80
- "options": {
81
- "project": "{projectRoot}/ng-package.json",
82
- "tsConfig": "{projectRoot}/tsconfig.lib.json"
83
- }
84
- },
85
- "@nx/js:tsc": {
86
- "cache": true,
87
- "dependsOn": ["^build"],
88
- "inputs": ["default", "^default"]
89
- }
90
- },
91
- "namedInputs": {
92
- "default": [
93
- "{projectRoot}/src/**/*",
94
- "!{projectRoot}/**/*.(spec|test)(.e2e)?.[tj]sx?",
95
- "!{projectRoot}/**/e2e/**/*",
96
- "{projectRoot}/.env(.*)?",
97
- "{workspaceRoot}/tasks/(post-)?build.ts",
98
- "{projectRoot}/(project|package|tsconfig)(.+)?.json",
99
- "{workspaceRoot}/tsconfig.base.json",
100
- {
101
- "runtime": "node --version"
102
- },
103
- {
104
- "env": "NODE_ENV"
105
- }
106
- ],
107
- "test": [
108
- "default",
109
- "{projectRoot}/tsconfig.spec.json",
110
- "{projectRoot}/jest.config.[jt]s",
111
- "{workspaceRoot}/jest.config.[jt]s",
112
- "{projectRoot}/**/*.(spec|test)(.e2e)?.[jt]sx?",
113
- "{projectRoot}/**/e2e/**/*.[jt]sx?",
114
- {
115
- "externalDependencies": ["jest"]
116
- }
117
- ]
118
- },
119
- "plugins": [
120
- {
121
- "plugin": "@nx/js/typescript",
122
- "options": {
123
- "typecheck": {
124
- "targetName": "typecheck"
125
- },
126
- "build": false
127
- }
128
- },
129
- {
130
- "plugin": "@nx/jest/plugin",
131
- "options": {
132
- "targetName": "test",
133
- "ciTargetName": "test-ci"
134
- }
135
- }
136
- ],
137
- "tasksRunnerOptions": {
138
- "default": {
139
- "options": {
140
- "useDaemonProcess": false
141
- }
142
- }
143
- },
144
- "generators": {
145
- "@nx/angular:library": {
146
- "linter": "eslint",
147
- "unitTestRunner": "jest"
148
- },
149
- "@nx/angular:component": {
150
- "style": "scss"
151
- }
152
- },
153
- "release": {
154
- "groups": {
155
- "libs": {
156
- "projects": ["libs/*"]
157
- },
158
- "apps": {
159
- "projects": ["apps/*"],
160
- "changelog": {
161
- "projectChangelogs": {
162
- "createRelease": "github"
163
- }
164
- }
165
- }
166
- },
167
- "projectsRelationship": "independent",
168
- "version": {
169
- "conventionalCommits": true,
170
- "updateDependents": "always",
171
- "preVersionCommand": "pnpm nx run-many -t build",
172
- "manifestRootsToUpdate": [
173
- "{projectRoot}",
174
- {
175
- "path": "{projectRoot}/dist",
176
- "preserveLocalDependencyProtocols": false
177
- }
178
- ]
179
- },
180
- "releaseTag": {
181
- "pattern": "{projectName}@{version}"
182
- },
183
- "changelog": {
184
- "projectChangelogs": true
185
- }
186
- },
187
- "sync": {
188
- "applyChanges": false
189
- }
190
- }