@rsdk/http.server.fastify 3.2.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [3.2.0-next.0](https://github.com/R-Vision/rsdk/compare/v3.1.0...v3.2.0-next.0) (2023-08-09)
7
+
8
+ ### Features
9
+
10
+ * **http.server:** split to package by implementation @rsdk/http.server.{fastify,express} ([f3cdad1](https://github.com/R-Vision/rsdk/commit/f3cdad1c7372d2bfbaee21d91973d5354cebf46c))
@@ -0,0 +1,9 @@
1
+ import type { AbstractHttpAdapter } from '@nestjs/core';
2
+ import { AbstractRsdkHttpTransport } from '@rsdk/http.server';
3
+ import type { HttpConfig } from '@rsdk/http.server/dist/http.config';
4
+ import type { FastifyAdapterOptions } from './types';
5
+ export declare class FastifyHttpTransport extends AbstractRsdkHttpTransport {
6
+ readonly options?: FastifyAdapterOptions;
7
+ constructor(options?: FastifyAdapterOptions);
8
+ createHttpAdapter(httpConfig: HttpConfig): AbstractHttpAdapter;
9
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FastifyHttpTransport = void 0;
4
+ const platform_fastify_1 = require("@nestjs/platform-fastify");
5
+ const http_server_1 = require("@rsdk/http.server");
6
+ class FastifyHttpTransport extends http_server_1.AbstractRsdkHttpTransport {
7
+ options;
8
+ constructor(options) {
9
+ super();
10
+ if (options) {
11
+ this.options = options;
12
+ }
13
+ }
14
+ createHttpAdapter(httpConfig) {
15
+ const { parsers } = this.options ?? {};
16
+ const { bodyLimit } = httpConfig;
17
+ const fastifyAdapter = new platform_fastify_1.FastifyAdapter({
18
+ bodyLimit: bodyLimit.bytes(),
19
+ });
20
+ const { body, cookie } = Object.assign({
21
+ body: {
22
+ json: true,
23
+ urlencoded: false,
24
+ },
25
+ cookie: false,
26
+ }, parsers);
27
+ if (body.urlencoded) {
28
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,import/no-extraneous-dependencies
29
+ fastifyAdapter.register(require('@fastify/formbody'));
30
+ }
31
+ if (cookie) {
32
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,import/no-extraneous-dependencies
33
+ fastifyAdapter.register(require('@fastify/cookie'));
34
+ }
35
+ return fastifyAdapter;
36
+ }
37
+ }
38
+ exports.FastifyHttpTransport = FastifyHttpTransport;
39
+ //# sourceMappingURL=fastify-http-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fastify-http-transport.js","sourceRoot":"","sources":["../src/fastify-http-transport.ts"],"names":[],"mappings":";;;AACA,+DAA0D;AAE1D,mDAA8D;AAK9D,MAAa,oBAAqB,SAAQ,uCAAyB;IACxD,OAAO,CAAyB;IACzC,YAAY,OAA+B;QACzC,KAAK,EAAE,CAAC;QACR,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACxB;IACH,CAAC;IAED,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;YACnB,gGAAgG;YAChG,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC;SACvD;QACD,IAAI,MAAM,EAAE;YACV,gGAAgG;YAChG,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC;SACrD;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AApCD,oDAoCC"}
@@ -0,0 +1 @@
1
+ export { FastifyHttpTransport } from './fastify-http-transport';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FastifyHttpTransport = void 0;
4
+ var fastify_http_transport_1 = require("./fastify-http-transport");
5
+ Object.defineProperty(exports, "FastifyHttpTransport", { enumerable: true, get: function () { return fastify_http_transport_1.FastifyHttpTransport; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mEAAgE;AAAvD,8HAAA,oBAAoB,OAAA"}
@@ -0,0 +1,9 @@
1
+ import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
2
+ import type { DeepPartial } from '@rsdk/common';
3
+ import type { ParsersConfig, SwaggerOptions } from '@rsdk/http.server';
4
+ export interface FastifyAdapterOptions {
5
+ cors?: CorsOptions;
6
+ globalPrefix?: string;
7
+ parsers?: DeepPartial<ParsersConfig>;
8
+ swagger?: DeepPartial<SwaggerOptions>;
9
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@rsdk/http.server.fastify",
3
+ "version": "3.2.0-next.0",
4
+ "description": "Adapter for @rsdk/http.server",
5
+ "main": "dist/index.js",
6
+ "repository": {
7
+ "url": "https://github.com/R-Vision/rsdk"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "keywords": [
13
+ "http",
14
+ "rsdk",
15
+ "nestjs",
16
+ "fastify"
17
+ ],
18
+ "license": "Apache License 2.0",
19
+ "dependencies": {
20
+ "@nestjs/common": "^10.1.3",
21
+ "@nestjs/core": "^10.1.3",
22
+ "@nestjs/platform-fastify": "^10.1.3",
23
+ "@rsdk/http.server": "^3.2.0-next.0"
24
+ },
25
+ "peerDependencies": {
26
+ "@fastify/cookie": "^9.0.4",
27
+ "@fastify/formbody": "^7.4.0"
28
+ },
29
+ "peerDependenciesMeta": {
30
+ "@fastify/cookie": {
31
+ "optional": true
32
+ },
33
+ "@fastify/formbody": {
34
+ "optional": true
35
+ }
36
+ },
37
+ "gitHead": "8e68e24b722f6fba6b8b02fbaf1287f7a67f2ffe"
38
+ }
@@ -0,0 +1,45 @@
1
+ import type { AbstractHttpAdapter } from '@nestjs/core';
2
+ import { FastifyAdapter } from '@nestjs/platform-fastify';
3
+ import type { ParsersConfig } from '@rsdk/http.server';
4
+ import { AbstractRsdkHttpTransport } from '@rsdk/http.server';
5
+ import type { HttpConfig } from '@rsdk/http.server/dist/http.config';
6
+
7
+ import type { FastifyAdapterOptions } from './types';
8
+
9
+ export class FastifyHttpTransport extends AbstractRsdkHttpTransport {
10
+ readonly options?: FastifyAdapterOptions;
11
+ constructor(options?: FastifyAdapterOptions) {
12
+ super();
13
+ if (options) {
14
+ this.options = options;
15
+ }
16
+ }
17
+
18
+ createHttpAdapter(httpConfig: HttpConfig): AbstractHttpAdapter {
19
+ const { parsers } = this.options ?? {};
20
+ const { bodyLimit } = httpConfig;
21
+ const fastifyAdapter = new FastifyAdapter({
22
+ bodyLimit: bodyLimit.bytes(),
23
+ });
24
+ const { body, cookie }: ParsersConfig = Object.assign(
25
+ {
26
+ body: {
27
+ json: true,
28
+ urlencoded: false,
29
+ },
30
+ cookie: false,
31
+ },
32
+ parsers,
33
+ );
34
+
35
+ if (body.urlencoded) {
36
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,import/no-extraneous-dependencies
37
+ fastifyAdapter.register(require('@fastify/formbody'));
38
+ }
39
+ if (cookie) {
40
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,import/no-extraneous-dependencies
41
+ fastifyAdapter.register(require('@fastify/cookie'));
42
+ }
43
+ return fastifyAdapter;
44
+ }
45
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { FastifyHttpTransport } from './fastify-http-transport';
package/src/types.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
2
+ import type { DeepPartial } from '@rsdk/common';
3
+ import type { ParsersConfig, SwaggerOptions } from '@rsdk/http.server';
4
+
5
+ export interface FastifyAdapterOptions {
6
+ // CORS middleware options
7
+ cors?: CorsOptions;
8
+
9
+ // Global prefix (will be used in app.setGlobalPrefix())
10
+ globalPrefix?: string;
11
+
12
+ // Configuration of body and cookie parsers
13
+ // WARNING: Has no effect on FastifyAdapter. Use FastifyAdapter
14
+ // constructor options instead
15
+ parsers?: DeepPartial<ParsersConfig>;
16
+
17
+ // Swagger options. You can configure OpenAPI document
18
+ // builder or set file to write on application start
19
+ // NOTE: SwaggerUI is enabled or disabled by HTTP_SWAGGER_UI_ENABLED
20
+ // (true by default).
21
+
22
+ // TODO: It terrible to generate file on application start. Would be
23
+ // much better if we could get OpenAPI spec on demand without actually
24
+ // running the app. Unfortunately there is no way to do it in Nest.js 9.
25
+ // Planned in https://jira.rvision.pro/browse/PFM-134
26
+ swagger?: DeepPartial<SwaggerOptions>;
27
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@rsdk/tsconfig/base.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
9
+ }