@nestjs/platform-fastify 7.4.2 → 7.5.1

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/Readme.md CHANGED
@@ -89,7 +89,7 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
89
89
  <a href="https://sparkfabrik.com/" target="_blank"><img src="https://nestjs.com/img/sparkfabrik-logo.png" width="120" valign="middle" /></a></td><td align="center" valign="middle"><a href="https://www.thebigphonestore.co.uk/" target="_blank"><img src="https://nestjs.com/img/the-big-phone-store-logo.png" width="65" valign="middle" /></a></td>
90
90
  <td align="center" valign="middle">
91
91
  <a href="https://genuinebee.com/" target="_blank"><img src="https://nestjs.com/img/genuinebee.svg" width="97" valign="middle" /></a> </td></tr>
92
- <tr><td align="center" valign="middle"><a href="https://sanyodigital.com/" target="_blank"><img src="https://nestjs.com/img/sanyo-digital.png" width="130" valign="middle" /></a></td>
92
+ <tr><td align="center" valign="middle"><a href="https://sanyodigital.com/" target="_blank"><img src="https://nestjs.com/img/sanyo-digital.png" width="130" valign="middle" /></a></td><td align="center" valign="middle"><a href="https://vpn-review.com/vpn-for-torrenting" target="_blank"><img src="https://nestjs.com/img/vpn-review-logo.png" width="85" valign="middle" /></a></td>
93
93
  </tr></table>
94
94
 
95
95
  ## Backers
@@ -2,10 +2,10 @@
2
2
  import { RequestMethod } from '@nestjs/common';
3
3
  import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
4
4
  import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
5
- import { FastifyInstance, FastifyLoggerInstance, FastifyPlugin, FastifyPluginOptions, FastifyRegisterOptions, FastifyReply, FastifyRequest, FastifyServerOptions, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestGenericInterface } from 'fastify';
5
+ import { FastifyInstance, FastifyLoggerInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions, FastifyRegisterOptions, FastifyReply, FastifyRequest, FastifyServerOptions, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestGenericInterface } from 'fastify';
6
6
  import * as http2 from 'http2';
7
7
  import * as https from 'https';
8
- import { InjectOptions } from 'light-my-request';
8
+ import { Chain as LightMyRequestChain, InjectOptions, Response as LightMyRequestResponse } from 'light-my-request';
9
9
  import { FastifyStaticOptions, PointOfViewOptions } from '../interfaces/external';
10
10
  declare type FastifyHttp2SecureOptions<Server extends http2.Http2SecureServer, Logger extends FastifyLoggerInstance = FastifyLoggerInstance> = FastifyServerOptions<Server, Logger> & {
11
11
  http2: true;
@@ -31,12 +31,17 @@ export declare class FastifyAdapter<TServer extends RawServerBase = RawServerDef
31
31
  view: Function;
32
32
  }, view: string, options: any): any;
33
33
  redirect(response: FastifyReply, statusCode: number, url: string): FastifyReply<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify/types/route").RouteGenericInterface, unknown>;
34
- setErrorHandler(handler: Parameters<FastifyInstance<TServer, TRawRequest, TRawResponse>['setErrorHandler']>[0]): void;
35
- setNotFoundHandler(handler: Parameters<FastifyInstance<TServer, TRawRequest, TRawResponse>['setNotFoundHandler']>[0]): void;
34
+ setErrorHandler(handler: Parameters<FastifyInstance<TServer, TRawRequest, TRawResponse>['setErrorHandler']>[0]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyLoggerInstance>;
35
+ setNotFoundHandler(handler: Parameters<FastifyInstance<TServer, TRawRequest, TRawResponse>['setNotFoundHandler']>[0]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyLoggerInstance>;
36
36
  getHttpServer<T = TServer>(): T;
37
37
  getInstance<T = FastifyInstance<TServer, TRawRequest, TRawResponse>>(): T;
38
- register<Options extends FastifyPluginOptions>(plugin: FastifyPlugin<Options>, opts?: FastifyRegisterOptions<Options>): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyLoggerInstance> & PromiseLike<undefined>;
39
- inject(opts: InjectOptions | string): Promise<import("light-my-request").Response>;
38
+ register<Options extends FastifyPluginOptions = any>(plugin: FastifyPluginCallback<Options> | FastifyPluginAsync<Options> | Promise<{
39
+ default: FastifyPluginCallback<Options>;
40
+ }> | Promise<{
41
+ default: FastifyPluginAsync<Options>;
42
+ }>, opts?: FastifyRegisterOptions<Options>): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyLoggerInstance> & PromiseLike<undefined>;
43
+ inject(): LightMyRequestChain;
44
+ inject(opts: InjectOptions | string): Promise<LightMyRequestResponse>;
40
45
  close(): Promise<undefined>;
41
46
  initHttpServer(): void;
42
47
  useStaticAssets(options: FastifyStaticOptions): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyLoggerInstance> & PromiseLike<undefined>;
@@ -49,7 +54,11 @@ export declare class FastifyAdapter<TServer extends RawServerBase = RawServerDef
49
54
  registerParserMiddleware(): void;
50
55
  createMiddlewareFactory(requestMethod: RequestMethod): Promise<(path: string, callback: Function) => any>;
51
56
  getType(): string;
52
- protected registerWithPrefix(factory: FastifyPlugin, prefix?: string): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyLoggerInstance> & PromiseLike<undefined>;
57
+ protected registerWithPrefix(factory: FastifyPluginCallback<any> | FastifyPluginAsync<any> | Promise<{
58
+ default: FastifyPluginCallback<any>;
59
+ }> | Promise<{
60
+ default: FastifyPluginAsync<any>;
61
+ }>, prefix?: string): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyLoggerInstance> & PromiseLike<undefined>;
53
62
  private isNativeResponse;
54
63
  private registerMiddie;
55
64
  }
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FastifyAdapter = void 0;
4
+ /* eslint-disable @typescript-eslint/no-var-requires */
4
5
  const common_1 = require("@nestjs/common");
5
6
  const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
6
7
  const http_adapter_1 = require("@nestjs/core/adapters/http-adapter");
7
8
  const fastify_1 = require("fastify");
8
- const reply_1 = require("fastify/lib/reply");
9
+ const Reply = require("fastify/lib/reply");
9
10
  const pathToRegexp = require("path-to-regexp");
10
11
  class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
11
12
  constructor(instanceOrOptions = fastify_1.fastify()) {
@@ -29,12 +30,14 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
29
30
  }
30
31
  reply(response, body, statusCode) {
31
32
  const fastifyReply = this.isNativeResponse(response)
32
- ? new reply_1.Reply(response, {
33
- preSerialization: null,
34
- preValidation: [],
35
- preHandler: [],
36
- onSend: [],
37
- onError: [],
33
+ ? new Reply(response, {
34
+ context: {
35
+ preSerialization: null,
36
+ preValidation: [],
37
+ preHandler: [],
38
+ onSend: [],
39
+ onError: [],
40
+ },
38
41
  }, {})
39
42
  : response;
40
43
  if (statusCode) {
@@ -71,8 +74,8 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
71
74
  register(plugin, opts) {
72
75
  return this.instance.register(plugin, opts);
73
76
  }
74
- async inject(opts) {
75
- return await this.instance.inject(opts);
77
+ inject(opts) {
78
+ return this.instance.inject(opts);
76
79
  }
77
80
  async close() {
78
81
  try {
@@ -112,10 +115,10 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
112
115
  return request.raw ? request.raw.url : request.url;
113
116
  }
114
117
  enableCors(options) {
115
- this.register(load_package_util_1.loadPackage('fastify-cors', 'FastifyAdapter.enableCors()'), options);
118
+ this.register(require('fastify-cors'), options);
116
119
  }
117
120
  registerParserMiddleware() {
118
- this.register(load_package_util_1.loadPackage('fastify-formbody', 'FastifyAdapter.registerParserMiddleware()'));
121
+ this.register(require('fastify-formbody'));
119
122
  }
120
123
  async createMiddlewareFactory(requestMethod) {
121
124
  if (!this.isMiddieRegistered) {
@@ -124,7 +127,12 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
124
127
  return (path, callback) => {
125
128
  const re = pathToRegexp(path);
126
129
  const normalizedPath = path === '/*' ? '' : path;
127
- this.instance.use(normalizedPath, (req, res, next) => {
130
+ // The following type assertion is valid as we enforce "middie" plugin registration
131
+ // which enhances the FastifyInstance with the "use()" method.
132
+ // ref https://github.com/fastify/middie/pull/55
133
+ const instanceWithUseFn = this
134
+ .instance;
135
+ instanceWithUseFn.use(normalizedPath, (req, res, next) => {
128
136
  const queryParamsIndex = req.originalUrl.indexOf('?');
129
137
  const pathname = queryParamsIndex >= 0
130
138
  ? req.originalUrl.slice(0, queryParamsIndex)
@@ -151,7 +159,6 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
151
159
  }
152
160
  async registerMiddie() {
153
161
  this.isMiddieRegistered = true;
154
- // eslint-disable-next-line @typescript-eslint/no-var-requires
155
162
  await this.register(require('middie'));
156
163
  }
157
164
  }
@@ -1,19 +1,21 @@
1
1
  import { INestApplication } from '@nestjs/common';
2
- import { FastifyPlugin, FastifyPluginOptions, FastifyRegisterOptions } from 'fastify';
3
- import { InjectOptions, Response as LightMyRequestResponse } from 'light-my-request';
2
+ import { FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions, FastifyRegisterOptions } from 'fastify';
3
+ import { Chain as LightMyRequestChain, InjectOptions, Response as LightMyRequestResponse } from 'light-my-request';
4
4
  import { FastifyStaticOptions, PointOfViewOptions } from './external';
5
5
  export interface NestFastifyApplication extends INestApplication {
6
6
  /**
7
7
  * A wrapper function around native `fastify.register()` method.
8
- * Example `app.register(require('fastify-formbody'))`
9
- *
10
- * @returns {this}
8
+ * Example `app.register(require('fastify-formbody'))
9
+ * @returns {Promise<FastifyInstance>}
11
10
  */
12
- register<Options extends FastifyPluginOptions>(plugin: FastifyPlugin<Options>, opts?: FastifyRegisterOptions<Options>): this;
11
+ register<Options extends FastifyPluginOptions = any>(plugin: FastifyPluginCallback<Options> | FastifyPluginAsync<Options> | Promise<{
12
+ default: FastifyPluginCallback<Options>;
13
+ }> | Promise<{
14
+ default: FastifyPluginAsync<Options>;
15
+ }>, opts?: FastifyRegisterOptions<Options>): Promise<FastifyInstance>;
13
16
  /**
14
17
  * Sets a base directory for public assets.
15
18
  * Example `app.useStaticAssets({ root: 'public' })`
16
- *
17
19
  * @returns {this}
18
20
  */
19
21
  useStaticAssets(options: FastifyStaticOptions): this;
@@ -28,6 +30,7 @@ export interface NestFastifyApplication extends INestApplication {
28
30
  * A wrapper function around native `fastify.inject()` method.
29
31
  * @returns {void}
30
32
  */
33
+ inject(): LightMyRequestChain;
31
34
  inject(opts: InjectOptions | string): Promise<LightMyRequestResponse>;
32
35
  /**
33
36
  * Starts the application.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/platform-fastify",
3
- "version": "7.4.2",
3
+ "version": "7.5.1",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@platform-fastify)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -17,13 +17,13 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "fastify": "3.1.1",
20
+ "fastify": "3.7.0",
21
21
  "fastify-cors": "4.1.0",
22
- "fastify-formbody": "4.0.3",
23
- "light-my-request": "4.0.1",
22
+ "fastify-formbody": "5.0.0",
23
+ "light-my-request": "4.2.1",
24
24
  "middie": "5.1.0",
25
25
  "path-to-regexp": "3.2.0",
26
- "tslib": "2.0.0"
26
+ "tslib": "2.0.3"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@nestjs/common": "^7.0.0",