{"id":306942,"date":"2020-07-14T15:01:32","date_gmt":"2020-07-14T15:01:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=306942"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=306942","title":{"rendered":"\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f NestJS: \u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043a \u0441\u043b\u043e\u0436\u043d\u043e\u043c\u0443"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/qiwi\/blog\/510864\/\">\n<p><a href=\"https:\/\/habr.com\/ru\/company\/qiwi\/blog\/510864\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/3q\/4w\/kz\/3q4wkzbprjrvqazqtedlfqsekf8.jpeg\" alt=\"image\"><\/a><\/p>\n<p>  <\/p>\n<h2 id=\"vvedenie\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>NestJS \u2014 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e <a href=\"https:\/\/www.npmtrends.com\/@nestjs\/common\">\u043d\u0430\u0431\u0438\u0440\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c<\/a> \u0444\u0440e\u0439\u043c\u0432\u043e\u0440\u043a, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u0438\u0434\u0435\u044f\u0445 IoC\/DI, \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0438\u0437\u0430\u0439\u043d\u0430 \u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c, Nest \u0438\u043c\u0435\u0435\u0442 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441, \u0447\u0442\u043e \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0438\u043b\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u2014 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Aspect-oriented_programming\">\u0430\u0441\u043f\u0435\u043a\u0442\u043e\u0432<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443, \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0438\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440.<br \/>  \u0412\u0430\u0436\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f. \u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0435, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441 Nest.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"bazovye-dekoratory\">\u0411\u0430\u0437\u043e\u0432\u044b\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b<\/h2>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 http-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u0435\u0439\u0441\u0430 \u0432 Nest \u0435\u0441\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c <a href=\"https:\/\/docs.nestjs.com\/guards\">\u0433\u0430\u0440\u0434\u043e\u0432<\/a>.<\/p>\n<p>  <\/p>\n<p>Guard \u2014 \u044d\u0442\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>CanActivate<\/code> \u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 <code>@UseGuard<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">@Injectable() export class RoleGuard implements CanActivate {   canActivate(     context: ExecutionContext,   ): boolean | Promise&lt;boolean&gt; | Observable&lt;boolean&gt; {     const request = context.switchToHttp().getRequest();     return getRole(request) === 'superuser'   } }  @Controller() export class MyController {   @Post('secure-path')   @UseGuards(RoleGuard)   async method() {     return   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u0445\u0430\u0440\u0434\u043a\u043e\u0436\u0435\u043d\u043d\u044b\u0439 <code>superuser<\/code> \u2014 \u043d\u0435 \u0441\u0430\u043c\u043e\u0435 \u043b\u0443\u0447\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u0443\u0434\u0430 \u0447\u0430\u0449\u0435 \u043d\u0443\u0436\u043d\u044b \u0431\u043e\u043b\u0435\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b. <\/p>\n<p>  <\/p>\n<p>Nest \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <a href=\"https:\/\/docs.nestjs.com\/guards#setting-roles-per-handler\">\u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/a> \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>@SetMetadata<\/code>. \u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u2014 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u044d\u0442\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Reflector<\/code>, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/github.com\/rbuckton\/reflect-metadata\">reflect-metadata<\/a>.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">@Injectable() export class RoleGuard implements CanActivate {   constructor(private reflector: Reflector) {}   canActivate(     context: ExecutionContext,   ): boolean | Promise&lt;boolean&gt; | Observable&lt;boolean&gt; {     const role = this.reflector.get&lt;string&gt;('role', context.getHandler());     const request = context.switchToHttp().getRequest();     return getRole(request) === role   } }  @Controller() export class MyController {   @Post('secure-path')   @SetMetadata('role', 'superuser')   @UseGuards(RoleGuard)   async test() {     return   } }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"kompozitnye-dekoratory\">\u041a\u043e\u043c\u043f\u043e\u0437\u0438\u0442\u043d\u044b\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b<\/h2>\n<p>  <\/p>\n<p>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0441\u0432\u044f\u0437\u043a\u0430\u0445.<\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d\u043e \u0442\u0435\u0441\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u044c\u044e \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432 \u0432 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0432 \u043e\u0434\u0438\u043d.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u0442\u0438\u043b\u0438\u0442\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <a href=\"https:\/\/docs.nestjs.com\/custom-decorators#decorator-composition\">applyDecorators<\/a>.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Role = (role) =&gt; applyDecorators(UseGuards(RoleGuard), SetMetadata('role', role))<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043e\u0440 \u0441\u0430\u043c\u0438\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const Role = role =&gt; (proto, propName, descriptor) =&gt; {   UseGuards(RoleGuard)(proto, propName, descriptor)   SetMetadata('role', role)(proto, propName, descriptor) }  @Controller() export class MyController {   @Post('secure-path')   @Role('superuser')   async test() {     return   } }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"polimorfnye-dekoratory\">\u041f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b<\/h2>\n<p>  <\/p>\n<p>\u041b\u0435\u0433\u043a\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0435\u0439, \u043a\u043e\u0433\u0434\u0430 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u044b\u043c \u0437\u0430\u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">@Controller() @UseGuards(RoleGuard) export class MyController {   @Post('secure-path')   @Role('superuser')   async test1() {     return   }    @Post('almost-securest-path')   @Role('superuser')   async test2() {     return   }    @Post('securest-path')   @Role('superuser')   async test3() {     return   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0438\u0449\u0435, \u0435\u0441\u043b\u0438 \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043d\u0430 \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441. \u0418 \u0443\u0436\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0431\u043e\u0439\u0442\u0438 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u044b \u043d\u0430 \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0431\u044b\u043b\u0438 \u043f\u043e\u0432\u0435\u0448\u0435\u043d\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e-\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u2014 \u043a\u043b\u0430\u0441\u0441 \u0438 \u043c\u0435\u0442\u043e\u0434 \u2014 \u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/decorators.html\">\u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0432 typescript<\/a> \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u0432 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0438\u0437 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0432\u044b\u0437\u043e\u0432\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">type ClassDecorator = &lt;TFunction extends Function&gt;(target: TFunction) =&gt; TFunction | void; type MethodDecorator = &lt;T&gt;(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor&lt;T&gt;) =&gt; TypedPropertyDescriptor&lt;T&gt; | void; type ParameterDecorator = (target: Object, propertyKey: string | symbol, parameterIndex: number) =&gt; void;  const Role = (role: string): MethodDecorator | ClassDecorator =&gt; (...args) =&gt; {   if (typeof args[0] === 'function') {     \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430     const ctor = args[0]     \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430     const proto = ctor.prototype     \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432     const methods = Object       .getOwnPropertyNames(proto)       .filter(prop =&gt; prop !== 'constructor')      \/\/ \u041e\u0431\u0445\u043e\u0434 \u0438 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432     methods.forEach((propName) =&gt; {       RoleMethodDecorator(         proto,         propName,         Object.getOwnPropertyDescriptor(proto, propName),         role,       )     })   } else {     const [proto, propName, descriptor] = args     RoleMethodDecorator(proto, propName, descriptor, role)   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0435\u0440\u0443\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0447\u0430\u0441\u0442\u044c \u044d\u0442\u043e\u0439 \u0440\u0443\u0442\u0438\u043d\u044b: <a href=\"https:\/\/github.com\/lukehorvat\/decorator-utils\">lukehorvat\/decorator-utils<\/a>, <a href=\"https:\/\/github.com\/qiwi\/decorator-utils\">qiwi\/decorator-utils<\/a>.<br \/>  \u042d\u0442\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">import { constructDecorator, CLASS, METHOD } from '@qiwi\/decorator-utils'  const Role = constructDecorator(   ({ targetType, descriptor, proto, propName, args: [role] }) =&gt; {     if (targetType === METHOD) {       RoleMethodDecorator(proto, propName, descriptor, role)     }      if (targetType === CLASS) {       const methods = Object.getOwnPropertyNames(proto)       methods.forEach((propName) =&gt; {         RoleMethodDecorator(           proto,           propName,           Object.getOwnPropertyDescriptor(proto, propName),           role,         )       })     }   }, )<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0432\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0435 \u043b\u043e\u0433\u0438\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0434\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0432\u0435\u0441\u043e\u043c\u044b\u0439 \u043f\u043b\u044e\u0441 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438:<br \/>  \u0432\u043c\u0435\u0441\u0442\u043e <code>@DecForClass<\/code>, <code>@DecForMethood<\/code>, <code>@DecForParam<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u043c\u043d\u043e\u0433\u043e\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 <code>@Dec<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0440\u043e\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u0434\u0440\u0443\u0433 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432 \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u043b\u043e\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 <code>@Role<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0440\u0430\u043d\u0435\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430.<br \/>  \u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432\u044b\u0437\u043e\u0432\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043d\u0435\u043b\u044c\u0437\u044f, <a href=\"https:\/\/docs.nestjs.com\/custom-decorators#param-decorators\">createParamDecorator<\/a> \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u043e \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0443 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<p>  <\/p>\n<p>\u0418 \u0434\u0430\u043b\u0435\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u0430 \/ \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u044b\u0437\u043e\u0432\u0430 (\u0447\u0435\u0440\u0435\u0437 \u043e\u0447\u0435\u043d\u044c \u0434\u043b\u0438\u043d\u043d\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043e\u0442 <a href=\"https:\/\/github.com\/nestjs\/nest\/blob\/ae1988be3c681fcc6d985d795107b18313fe1358\/packages\/core\/pipes\/params-token-factory.ts\">ParamsTokenFactory<\/a> \u0434\u043e <a href=\"https:\/\/github.com\/nestjs\/nest\/blob\/bf10f001c855997d2887129c467b313101d7e219\/packages\/core\/router\/router-execution-context.ts#L383\">RouterExecutionContext<\/a>).<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/\/ \u0421\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430   if (typeof args[2] === 'number') {     const [proto, propName, paramIndex] = args     createParamDecorator((_data: unknown, ctx: ExecutionContext) =&gt; {       return getRole(ctx.switchToHttp().getRequest())     })()(proto, propName, paramIndex)   }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0435\u0442\u0430\u0434\u0430\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043a\u0435\u0439\u0441\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u0441\u043e\u0447\u0435\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0438 <a href=\"https:\/\/github.com\/qiwi\/nestjs-enterprise\/tree\/master\/packages\/common#requestsize\">\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440<\/a> \u043f\u043e\u0432\u0435\u0441\u0438\u043b\u0438 \u0434\u0432\u0430\u0436\u0434\u044b. \u041a\u0430\u043a\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0434\u043e\u0432\u0435\u0440\u044f\u0442\u044c?<\/p>\n<p>  <\/p>\n<p>\u0411\u0435\u0437 \u0437\u043d\u0430\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c. \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0431\u044b\u043b\u043e \u0431\u044b \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">class SomeController {    @RequestSize(1000)    @RequestSize(5000)    @Post('foo')    method(@Body() body) {    } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 <a href=\"https:\/\/github.com\/qiwi\/nestjs-enterprise\/tree\/master\/packages\/common#port\">\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e\u0440\u0442\u0430\u043c\u0438<\/a>. \u0417\u0434\u0435\u0441\u044c, \u0441\u043a\u043e\u0440\u0435\u0435, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0435 \u0437\u0430\u0442\u0438\u0440\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u043a \u0438\u043c\u0435\u044e\u0449\u0438\u043c\u0441\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">class SomeController {    @Port(9092)    @Port(8080)    @Post('foo')    method(@Body() body) {    } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0445\u043e\u0436\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0441 \u0440\u043e\u043b\u0435\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">class SomeController {   @Post('securest-path')   @Role('superuser')   @Role('usert')   @Role('otheruser')   method(@Role() role) {    } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u043e\u0431\u0449\u0430\u044f \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>reflect-metadata<\/code> \u0438 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">import { ExecutionContext, createParamDecorator } from '@nestjs\/common' import { constructDecorator, METHOD, PARAM } from '@qiwi\/decorator-utils'  @Injectable() export class RoleGuard implements CanActivate {   canActivate(context: ExecutionContext): boolean | Promise&lt;boolean&gt; {     const roleMetadata = Reflect.getMetadata(       'roleMetadata',       context.getClass().prototype,     )     const request = context.switchToHttp().getRequest()     const role = getRole(request)     return roleMetadata.find(({ value }) =&gt; value === role)   } }  const RoleMethodDecorator = (proto, propName, decsriptor, role) =&gt; {   UseGuards(RoleGuard)(proto, propName, decsriptor)   const meta = Reflect.getMetadata('roleMetadata', proto) || []    Reflect.defineMetadata(     'roleMetadata',     [       ...meta, {         repeatable: true,         value: role,       },     ],     proto,   ) }  export const Role = constructDecorator(   ({ targetType, descriptor, proto, propName, paramIndex, args: [role] }) =&gt; {     if (targetType === METHOD) {       RoleMethodDecorator(proto, propName, descriptor, role)     }      if (targetType === PARAM) {       createParamDecorator((_data: unknown, ctx: ExecutionContext) =&gt;         getRole(ctx.switchToHttp().getRequest()),       )()(proto, propName, paramIndex)     }   }, )<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"makrodekoratory\">\u041c\u0430\u043a\u0440\u043e\u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b<\/h2>\n<p>  <\/p>\n<p>Nest \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u0435\u0433\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0443\u0434\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043a\u0435\u0439\u0441\u044b, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u0432, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u043e\u0439 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u0441\u0442\u0440\u043e\u043a \u043e\u0431\u0432\u044f\u0437\u043e\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0422\u0430\u043a, \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 <code>@Controller<\/code> \u043c\u043e\u0436\u043d\u043e \u00ab<a href=\"https:\/\/github.com\/qiwi\/json-rpc\/tree\/master\/packages\/nestjs\">\u043e\u0431\u0441\u0430\u0445\u0430\u0440\u0438\u0442\u044c<\/a>\u00bb<br \/>  \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 <a href=\"https:\/\/en.wikipedia.org\/wiki\/JSON-RPC\">JSON-RPC<\/a>.<br \/>  \u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e, \u044d\u0442\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u044b \u0434\u0430\u043b\u0435\u043a\u043e \u0432\u044b\u0448\u043b\u043e \u0437\u0430 \u0444\u043e\u0440\u043c\u0430\u0442 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u043d\u043e \u043f\u043e\u043a\u0430\u0436\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0438\u0434\u0435\u044e: \u043d\u0430 \u0447\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b, \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 Nest.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">import {   ControllerOptions,   Controller,   Post,   Req,   Res,   HttpCode,   HttpStatus, } from '@nestjs\/common'  import { Request, Response } from 'express' import { Extender } from '@qiwi\/json-rpc-common' import { JsonRpcMiddleware } from 'expressjs-json-rpc'  export const JsonRpcController = (   prefixOrOptions?: string | ControllerOptions, ): ClassDecorator =&gt; {   return &lt;TFunction extends Function&gt;(target: TFunction) =&gt; {     const extend: Extender = (base) =&gt; {       @Controller(prefixOrOptions as any)       @JsonRpcMiddleware()       class Extended extends base {         @Post('\/')         @HttpCode(HttpStatus.OK)         rpc(@Req() req: Request, @Res() res: Response): any {           return this.middleware(req, res)         }       }        return Extended     }      return extend(target as any)   } } <\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c <code>@Req()<\/code> \u0438\u0437 <code>rpc-method<\/code> \u0432 \u043c\u0438\u0434\u043b\u0432\u0430\u0440\u0435, \u043d\u0430\u0439\u0442\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0441 \u043c\u0435\u0442\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>@JsonRpcMethod<\/code>. <\/p>\n<p>  <\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">import {   JsonRpcController,   JsonRpcMethod,   IJsonRpcId,   IJsonRpcParams, } from 'nestjs-json-rpc'  @JsonRpcController('\/jsonrpc\/endpoint') export class SomeJsonRpcController {   @JsonRpcMethod('some-method')   doSomething(     @JsonRpcId() id: IJsonRpcId,     @JsonRpcParams() params: IJsonRpcParams,   ) {     const { foo } = params      if (foo === 'bar') {       return new JsonRpcError(-100, '&quot;foo&quot; param should not be equal &quot;bar&quot;')     }      return 'ok'   }   @JsonRpcMethod('other-method')   doElse(@JsonRpcId() id: IJsonRpcId) {     return 'ok'   } } <\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"vyvod\">\u0412\u044b\u0432\u043e\u0434<\/h2>\n<p>  <\/p>\n<p>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b Nest \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043a \u0448\u0438\u0440\u043e\u043a\u043e\u043c\u0443 \u0441\u043f\u0435\u043a\u0442\u0440\u0443 \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u0412 \u043d\u0438\u0445 \u043b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0443\u0442\u0438\u043b\u0438\u0442\u043d\u0430\u044f \u0438 \u0431\u0438\u0437\u043d\u0435\u0441\u043e\u0432\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430. \u0418\u0445 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c, \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0441\u043e\u0432\u043c\u0435\u0449\u0430\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432. \u0418 \u0432 \u044d\u0442\u043e\u043c, \u0431\u0435\u0437 \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u044f, \u043e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0438\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u043e\u0440\u043e\u043d \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430.<\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0441\u0435 \u0435\u0449\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c, \u0430 \u0438\u0445 \u0447\u0440\u0435\u0437\u043c\u0435\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442, \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0430\u0448 \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u044b\u043c.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/qiwi\/blog\/510864\/\"> https:\/\/habr.com\/ru\/company\/qiwi\/blog\/510864\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/qiwi\/blog\/510864\/\">\n<p><a href=\"https:\/\/habr.com\/ru\/company\/qiwi\/blog\/510864\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/3q\/4w\/kz\/3q4wkzbprjrvqazqtedlfqsekf8.jpeg\" alt=\"image\"><\/a><\/p>\n<p>  <\/p>\n<h2 id=\"vvedenie\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>NestJS \u2014 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e <a href=\"https:\/\/www.npmtrends.com\/@nestjs\/common\">\u043d\u0430\u0431\u0438\u0440\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c<\/a> \u0444\u0440e\u0439\u043c\u0432\u043e\u0440\u043a, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u0438\u0434\u0435\u044f\u0445 IoC\/DI, \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0438\u0437\u0430\u0439\u043d\u0430 \u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c, Nest \u0438\u043c\u0435\u0435\u0442 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441, \u0447\u0442\u043e \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0438\u043b\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u2014 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Aspect-oriented_programming\">\u0430\u0441\u043f\u0435\u043a\u0442\u043e\u0432<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443, \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0438\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440.<br \/>  \u0412\u0430\u0436\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f. \u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0435, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441 Nest.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-306942","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/306942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=306942"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/306942\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=306942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=306942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=306942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}