@rsdk/http.server.fastify 5.7.0-next.2 → 6.0.0-next.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.
@@ -1,6 +1,8 @@
1
1
  import type { AbstractHttpAdapter } from '@nestjs/core';
2
+ import type { LogFormatter } from '@rsdk/core';
2
3
  import { AbstractHttpTransport } from '@rsdk/http.server';
3
4
  import type { HttpConfig } from '@rsdk/http.server/dist/http.config';
4
5
  export declare class FastifyHttpTransport extends AbstractHttpTransport {
5
- createHttpAdapter(httpConfig: HttpConfig): AbstractHttpAdapter;
6
+ createHttpAdapter(config: HttpConfig): AbstractHttpAdapter;
7
+ logFormatter(): LogFormatter;
6
8
  }
@@ -3,13 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FastifyHttpTransport = void 0;
4
4
  const platform_fastify_1 = require("@nestjs/platform-fastify");
5
5
  const http_server_1 = require("@rsdk/http.server");
6
+ const fastify_http_log_formatter_1 = require("./fastify-http.log-formatter");
6
7
  class FastifyHttpTransport extends http_server_1.AbstractHttpTransport {
7
- createHttpAdapter(httpConfig) {
8
+ createHttpAdapter(config) {
8
9
  const { parsers } = this.options ?? {};
9
- const { bodyLimit } = httpConfig;
10
- const fastifyAdapter = new platform_fastify_1.FastifyAdapter({
11
- bodyLimit: bodyLimit.bytes(),
12
- });
10
+ const { bodyLimit } = config;
11
+ const fastifyAdapter = new platform_fastify_1.FastifyAdapter({ bodyLimit: bodyLimit.bytes() });
13
12
  const { body, cookie } = Object.assign({
14
13
  body: {
15
14
  json: true,
@@ -27,6 +26,9 @@ class FastifyHttpTransport extends http_server_1.AbstractHttpTransport {
27
26
  }
28
27
  return fastifyAdapter;
29
28
  }
29
+ logFormatter() {
30
+ return new fastify_http_log_formatter_1.FastifyHttpLogFormatter();
31
+ }
30
32
  }
31
33
  exports.FastifyHttpTransport = FastifyHttpTransport;
32
34
  //# sourceMappingURL=fastify-http-transport.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fastify-http-transport.js","sourceRoot":"","sources":["../src/fastify-http-transport.ts"],"names":[],"mappings":";;;AACA,+DAA0D;AAE1D,mDAA0D;AAG1D,MAAa,oBAAqB,SAAQ,mCAAqB;IAC7D,iBAAiB,CAAC,UAAsB;QACtC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;QACvC,MAAM,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC;QACjC,MAAM,cAAc,GAAG,IAAI,iCAAc,CAAC;YACxC,SAAS,EAAE,SAAS,CAAC,KAAK,EAAE;SAC7B,CAAC,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAkB,MAAM,CAAC,MAAM,CACnD;YACE,IAAI,EAAE;gBACJ,IAAI,EAAE,IAAI;gBACV,UAAU,EAAE,KAAK;aAClB;YACD,MAAM,EAAE,KAAK;SACd,EACD,OAAO,CACR,CAAC;QAEF,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,gGAAgG;YAChG,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,MAAM,EAAE,CAAC;YACX,gGAAgG;YAChG,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AA5BD,oDA4BC"}
1
+ {"version":3,"file":"fastify-http-transport.js","sourceRoot":"","sources":["../src/fastify-http-transport.ts"],"names":[],"mappings":";;;AACA,+DAA0D;AAG1D,mDAA0D;AAG1D,6EAAuE;AAEvE,MAAa,oBAAqB,SAAQ,mCAAqB;IAC7D,iBAAiB,CAAC,MAAkB;QAClC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;QACvC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;QAC7B,MAAM,cAAc,GAAG,IAAI,iCAAc,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAE5E,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAkB,MAAM,CAAC,MAAM,CACnD;YACE,IAAI,EAAE;gBACJ,IAAI,EAAE,IAAI;gBACV,UAAU,EAAE,KAAK;aAClB;YACD,MAAM,EAAE,KAAK;SACd,EACD,OAAO,CACR,CAAC;QAEF,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,gGAAgG;YAChG,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,MAAM,EAAE,CAAC;YACX,gGAAgG;YAChG,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,YAAY;QACV,OAAO,IAAI,oDAAuB,EAAE,CAAC;IACvC,CAAC;CACF;AA/BD,oDA+BC"}
@@ -0,0 +1,8 @@
1
+ import type { ExecutionContext } from '@nestjs/common';
2
+ import type { LogFormatter } from '@rsdk/core';
3
+ export declare class FastifyHttpLogFormatter implements LogFormatter {
4
+ readonly protocol = "http";
5
+ getPath(context: ExecutionContext): string;
6
+ formatRequest(context: ExecutionContext, includeBody: boolean): Record<string, unknown>;
7
+ formatResponse(context: ExecutionContext, body: unknown | undefined): Record<string, unknown>;
8
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FastifyHttpLogFormatter = void 0;
4
+ class FastifyHttpLogFormatter {
5
+ protocol = 'http';
6
+ getPath(context) {
7
+ const request = context.switchToHttp().getRequest();
8
+ // TODO: Может лучше голый путь - без query-параметров
9
+ return `${request.method} ${request.url}`;
10
+ }
11
+ formatRequest(context, includeBody) {
12
+ const request = context.switchToHttp().getRequest();
13
+ return {
14
+ query: request.query,
15
+ params: request.params,
16
+ method: request.method,
17
+ url: request.url,
18
+ headers: request.headers,
19
+ ...(includeBody ? { body: request.body } : {}),
20
+ };
21
+ }
22
+ formatResponse(context, body) {
23
+ const reply = context.switchToHttp().getResponse();
24
+ return {
25
+ statusCode: reply.statusCode,
26
+ headers: reply.getHeaders(),
27
+ body,
28
+ };
29
+ }
30
+ }
31
+ exports.FastifyHttpLogFormatter = FastifyHttpLogFormatter;
32
+ //# sourceMappingURL=fastify-http.log-formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fastify-http.log-formatter.js","sourceRoot":"","sources":["../src/fastify-http.log-formatter.ts"],"names":[],"mappings":";;;AAIA,MAAa,uBAAuB;IACzB,QAAQ,GAAG,MAAM,CAAC;IAE3B,OAAO,CAAC,OAAyB;QAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAkB,CAAC;QAEpE,sDAAsD;QACtD,OAAO,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC5C,CAAC;IAED,aAAa,CACX,OAAyB,EACzB,WAAoB;QAEpB,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAkB,CAAC;QAEpE,OAAO;YACL,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/C,CAAC;IACJ,CAAC;IAED,cAAc,CACZ,OAAyB,EACzB,IAAyB;QAEzB,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,WAAW,EAAgB,CAAC;QAEjE,OAAO;YACL,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,OAAO,EAAE,KAAK,CAAC,UAAU,EAAE;YAC3B,IAAI;SACL,CAAC;IACJ,CAAC;CACF;AAtCD,0DAsCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdk/http.server.fastify",
3
- "version": "5.7.0-next.2",
3
+ "version": "6.0.0-next.0",
4
4
  "description": "Adapter for @rsdk/http.server",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -36,5 +36,5 @@
36
36
  "optional": true
37
37
  }
38
38
  },
39
- "gitHead": "c85fca0b594a2ea168d06f1d2941a4fb05b59440"
39
+ "gitHead": "215cccea23d95118dd8b6af3ce11c6a35ce19c30"
40
40
  }
@@ -1,16 +1,18 @@
1
1
  import type { AbstractHttpAdapter } from '@nestjs/core';
2
2
  import { FastifyAdapter } from '@nestjs/platform-fastify';
3
+ import type { LogFormatter } from '@rsdk/core';
3
4
  import type { ParsersConfig } from '@rsdk/http.server';
4
5
  import { AbstractHttpTransport } from '@rsdk/http.server';
5
6
  import type { HttpConfig } from '@rsdk/http.server/dist/http.config';
6
7
 
8
+ import { FastifyHttpLogFormatter } from './fastify-http.log-formatter';
9
+
7
10
  export class FastifyHttpTransport extends AbstractHttpTransport {
8
- createHttpAdapter(httpConfig: HttpConfig): AbstractHttpAdapter {
11
+ createHttpAdapter(config: HttpConfig): AbstractHttpAdapter {
9
12
  const { parsers } = this.options ?? {};
10
- const { bodyLimit } = httpConfig;
11
- const fastifyAdapter = new FastifyAdapter({
12
- bodyLimit: bodyLimit.bytes(),
13
- });
13
+ const { bodyLimit } = config;
14
+ const fastifyAdapter = new FastifyAdapter({ bodyLimit: bodyLimit.bytes() });
15
+
14
16
  const { body, cookie }: ParsersConfig = Object.assign(
15
17
  {
16
18
  body: {
@@ -32,4 +34,8 @@ export class FastifyHttpTransport extends AbstractHttpTransport {
32
34
  }
33
35
  return fastifyAdapter;
34
36
  }
37
+
38
+ logFormatter(): LogFormatter {
39
+ return new FastifyHttpLogFormatter();
40
+ }
35
41
  }
@@ -0,0 +1,43 @@
1
+ import type { ExecutionContext } from '@nestjs/common';
2
+ import type { LogFormatter } from '@rsdk/core';
3
+ import type { FastifyReply, FastifyRequest } from 'fastify';
4
+
5
+ export class FastifyHttpLogFormatter implements LogFormatter {
6
+ readonly protocol = 'http';
7
+
8
+ getPath(context: ExecutionContext): string {
9
+ const request = context.switchToHttp().getRequest<FastifyRequest>();
10
+
11
+ // TODO: Может лучше голый путь - без query-параметров
12
+ return `${request.method} ${request.url}`;
13
+ }
14
+
15
+ formatRequest(
16
+ context: ExecutionContext,
17
+ includeBody: boolean,
18
+ ): Record<string, unknown> {
19
+ const request = context.switchToHttp().getRequest<FastifyRequest>();
20
+
21
+ return {
22
+ query: request.query,
23
+ params: request.params,
24
+ method: request.method,
25
+ url: request.url,
26
+ headers: request.headers,
27
+ ...(includeBody ? { body: request.body } : {}),
28
+ };
29
+ }
30
+
31
+ formatResponse(
32
+ context: ExecutionContext,
33
+ body: unknown | undefined,
34
+ ): Record<string, unknown> {
35
+ const reply = context.switchToHttp().getResponse<FastifyReply>();
36
+
37
+ return {
38
+ statusCode: reply.statusCode,
39
+ headers: reply.getHeaders(),
40
+ body,
41
+ };
42
+ }
43
+ }