@nestjs/platform-fastify 10.4.11 → 11.0.0-next.2
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,11 +1,11 @@
|
|
|
1
|
-
import { RequestMethod, VersioningOptions } from '@nestjs/common';
|
|
1
|
+
import { Logger, RequestMethod, VersioningOptions } from '@nestjs/common';
|
|
2
2
|
import { VersionValue } from '@nestjs/common/interfaces';
|
|
3
3
|
import { CorsOptions, CorsOptionsDelegate } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
4
4
|
import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
|
|
5
|
-
import { FastifyBaseLogger, FastifyBodyParser, FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyRegister, FastifyReply, FastifyRequest, FastifyServerOptions, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestGenericInterface } from 'fastify';
|
|
5
|
+
import { FastifyBaseLogger, FastifyBodyParser, FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyRegister, FastifyReply, FastifyRequest, FastifyServerOptions, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestGenericInterface, RouteGenericInterface } from 'fastify';
|
|
6
|
+
import * as http from 'http';
|
|
6
7
|
import * as http2 from 'http2';
|
|
7
8
|
import * as https from 'https';
|
|
8
|
-
import * as http from 'http';
|
|
9
9
|
import { InjectOptions, Chain as LightMyRequestChain, Response as LightMyRequestResponse } from 'light-my-request';
|
|
10
10
|
import { NestFastifyBodyParserOptions } from '../interfaces';
|
|
11
11
|
import { FastifyStaticOptions, FastifyViewOptions } from '../interfaces/external';
|
|
@@ -42,8 +42,10 @@ type FastifyRawRequest<TServer extends RawServerBase> = RawRequestDefaultExpress
|
|
|
42
42
|
/**
|
|
43
43
|
* @publicApi
|
|
44
44
|
*/
|
|
45
|
-
export declare class FastifyAdapter<TServer extends RawServerBase = RawServerDefault, TRawRequest extends FastifyRawRequest<TServer> = FastifyRawRequest<TServer>, TRawResponse extends RawReplyDefaultExpression<TServer> = RawReplyDefaultExpression<TServer>, TRequest extends FastifyRequest<RequestGenericInterface, TServer, TRawRequest> = FastifyRequest<RequestGenericInterface, TServer, TRawRequest>, TReply extends FastifyReply<TServer, TRawRequest, TRawResponse> = FastifyReply<TServer, TRawRequest, TRawResponse>, TInstance extends FastifyInstance<TServer, TRawRequest, TRawResponse> = FastifyInstance<TServer, TRawRequest, TRawResponse>> extends AbstractHttpAdapter<TServer, TRequest, TReply> {
|
|
45
|
+
export declare class FastifyAdapter<TServer extends RawServerBase = RawServerDefault, TRawRequest extends FastifyRawRequest<TServer> = FastifyRawRequest<TServer>, TRawResponse extends RawReplyDefaultExpression<TServer> = RawReplyDefaultExpression<TServer>, TRequest extends FastifyRequest<RequestGenericInterface, TServer, TRawRequest> = FastifyRequest<RequestGenericInterface, TServer, TRawRequest>, TReply extends FastifyReply<RouteGenericInterface, TServer, TRawRequest, TRawResponse> = FastifyReply<RouteGenericInterface, TServer, TRawRequest, TRawResponse>, TInstance extends FastifyInstance<TServer, TRawRequest, TRawResponse> = FastifyInstance<TServer, TRawRequest, TRawResponse>> extends AbstractHttpAdapter<TServer, TRequest, TReply> {
|
|
46
|
+
protected readonly logger: Logger;
|
|
46
47
|
protected readonly instance: TInstance;
|
|
48
|
+
protected _pathPrefix?: string;
|
|
47
49
|
private _isParserRegistered;
|
|
48
50
|
private isMiddieRegistered;
|
|
49
51
|
private versioningOptions?;
|
|
@@ -61,28 +63,35 @@ export declare class FastifyAdapter<TServer extends RawServerBase = RawServerDef
|
|
|
61
63
|
patch(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
62
64
|
options(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
63
65
|
search(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
66
|
+
propfind(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
67
|
+
proppatch(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
68
|
+
mkcol(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
69
|
+
copy(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
70
|
+
move(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
71
|
+
lock(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
72
|
+
unlock(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
64
73
|
applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): VersionedRoute<TRequest, TReply>;
|
|
65
|
-
reply(response: TRawResponse | TReply, body: any, statusCode?: number): FastifyReply<TServer, TRawRequest, TRawResponse,
|
|
66
|
-
status(response: TRawResponse | TReply, statusCode: number):
|
|
74
|
+
reply(response: TRawResponse | TReply, body: any, statusCode?: number): FastifyReply<RouteGenericInterface, TServer, TRawRequest, TRawResponse, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>;
|
|
75
|
+
status(response: TRawResponse | TReply, statusCode: number): any;
|
|
67
76
|
end(response: TReply, message?: string): void;
|
|
68
77
|
render(response: TReply & {
|
|
69
78
|
view: Function;
|
|
70
79
|
}, view: string, options: any): any;
|
|
71
|
-
redirect(response: TReply, statusCode: number, url: string): FastifyReply<TServer, TRawRequest, TRawResponse,
|
|
80
|
+
redirect(response: TReply, statusCode: number, url: string): FastifyReply<RouteGenericInterface, TServer, TRawRequest, TRawResponse, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>;
|
|
72
81
|
setErrorHandler(handler: Parameters<TInstance['setErrorHandler']>[0]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProvider>;
|
|
73
82
|
setNotFoundHandler(handler: Function): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
|
|
74
83
|
getHttpServer<T = TServer>(): T;
|
|
75
84
|
getInstance<T = TInstance>(): T;
|
|
76
|
-
register<TRegister extends Parameters<FastifyRegister<TInstance>>>(plugin: TRegister['0'], opts?: TRegister['1']):
|
|
85
|
+
register<TRegister extends Parameters<FastifyRegister<TInstance>>>(plugin: TRegister['0'], opts?: TRegister['1']): any;
|
|
77
86
|
inject(): LightMyRequestChain;
|
|
78
87
|
inject(opts: InjectOptions | string): Promise<LightMyRequestResponse>;
|
|
79
88
|
close(): Promise<undefined>;
|
|
80
89
|
initHttpServer(): void;
|
|
81
|
-
useStaticAssets(options: FastifyStaticOptions):
|
|
82
|
-
setViewEngine(options: FastifyViewOptions | string):
|
|
90
|
+
useStaticAssets(options: FastifyStaticOptions): any;
|
|
91
|
+
setViewEngine(options: FastifyViewOptions | string): any;
|
|
83
92
|
isHeadersSent(response: TReply): boolean;
|
|
84
93
|
getHeader?(response: any, name: string): any;
|
|
85
|
-
setHeader(response: TReply, name: string, value: string): FastifyReply<TServer, TRawRequest, TRawResponse,
|
|
94
|
+
setHeader(response: TReply, name: string, value: string): FastifyReply<RouteGenericInterface, TServer, TRawRequest, TRawResponse, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>;
|
|
86
95
|
appendHeader?(response: any, name: string, value: string): void;
|
|
87
96
|
getRequestHostname(request: TRequest): string;
|
|
88
97
|
getRequestMethod(request: TRequest): string;
|
|
@@ -97,7 +106,9 @@ export declare class FastifyAdapter<TServer extends RawServerBase = RawServerDef
|
|
|
97
106
|
default: FastifyPluginCallback<any>;
|
|
98
107
|
}> | Promise<{
|
|
99
108
|
default: FastifyPluginAsync<any>;
|
|
100
|
-
}>, prefix?: string): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<undefined
|
|
109
|
+
}>, prefix?: string): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<undefined> & {
|
|
110
|
+
__linterBrands: "SafePromiseLike";
|
|
111
|
+
};
|
|
101
112
|
private isNativeResponse;
|
|
102
113
|
private registerJsonContentParser;
|
|
103
114
|
private registerUrlencodedContentParser;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FastifyAdapter = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-floating-promises */
|
|
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 shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
7
8
|
const http_adapter_1 = require("@nestjs/core/adapters/http-adapter");
|
|
9
|
+
const legacy_route_converter_1 = require("@nestjs/core/router/legacy-route-converter");
|
|
8
10
|
const fastify_1 = require("fastify");
|
|
9
11
|
const Reply = require("fastify/lib/reply");
|
|
10
12
|
const symbols_1 = require("fastify/lib/symbols");
|
|
11
|
-
const
|
|
13
|
+
const path_to_regexp_1 = require("path-to-regexp");
|
|
12
14
|
// `querystring` is used internally in fastify for registering urlencoded body parser.
|
|
13
15
|
const querystring_1 = require("querystring");
|
|
14
16
|
const constants_1 = require("../constants");
|
|
@@ -21,6 +23,7 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
21
23
|
}
|
|
22
24
|
constructor(instanceOrOptions) {
|
|
23
25
|
super();
|
|
26
|
+
this.logger = new common_1.Logger(FastifyAdapter.name);
|
|
24
27
|
this.versionConstraint = {
|
|
25
28
|
name: 'version',
|
|
26
29
|
validate(value) {
|
|
@@ -149,6 +152,27 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
149
152
|
search(...args) {
|
|
150
153
|
return this.injectRouteOptions('SEARCH', ...args);
|
|
151
154
|
}
|
|
155
|
+
propfind(...args) {
|
|
156
|
+
return this.injectRouteOptions('PROPFIND', ...args);
|
|
157
|
+
}
|
|
158
|
+
proppatch(...args) {
|
|
159
|
+
return this.injectRouteOptions('PROPPATCH', ...args);
|
|
160
|
+
}
|
|
161
|
+
mkcol(...args) {
|
|
162
|
+
return this.injectRouteOptions('MKCOL', ...args);
|
|
163
|
+
}
|
|
164
|
+
copy(...args) {
|
|
165
|
+
return this.injectRouteOptions('COPY', ...args);
|
|
166
|
+
}
|
|
167
|
+
move(...args) {
|
|
168
|
+
return this.injectRouteOptions('MOVE', ...args);
|
|
169
|
+
}
|
|
170
|
+
lock(...args) {
|
|
171
|
+
return this.injectRouteOptions('LOCK', ...args);
|
|
172
|
+
}
|
|
173
|
+
unlock(...args) {
|
|
174
|
+
return this.injectRouteOptions('UNLOCK', ...args);
|
|
175
|
+
}
|
|
152
176
|
applyVersionFilter(handler, version, versioningOptions) {
|
|
153
177
|
if (!this.versioningOptions) {
|
|
154
178
|
this.versioningOptions = versioningOptions;
|
|
@@ -287,6 +311,11 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
287
311
|
this.registerUrlencodedContentParser(rawBody);
|
|
288
312
|
this.registerJsonContentParser(rawBody);
|
|
289
313
|
this._isParserRegistered = true;
|
|
314
|
+
this._pathPrefix = prefix
|
|
315
|
+
? !prefix.startsWith('/')
|
|
316
|
+
? `/${prefix}`
|
|
317
|
+
: prefix
|
|
318
|
+
: undefined;
|
|
290
319
|
}
|
|
291
320
|
useBodyParser(type, rawBody, options, parser) {
|
|
292
321
|
const parserOptions = {
|
|
@@ -314,25 +343,38 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
314
343
|
return (path, callback) => {
|
|
315
344
|
const hasEndOfStringCharacter = path.endsWith('$');
|
|
316
345
|
path = hasEndOfStringCharacter ? path.slice(0, -1) : path;
|
|
317
|
-
let normalizedPath =
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
//
|
|
321
|
-
normalizedPath =
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
346
|
+
let normalizedPath = legacy_route_converter_1.LegacyRouteConverter.tryConvert(path);
|
|
347
|
+
// Fallback to "*path" to support plugins like GraphQL
|
|
348
|
+
normalizedPath = normalizedPath === '/*path' ? '*path' : normalizedPath;
|
|
349
|
+
// Normalize the path to support the prefix if it set in application
|
|
350
|
+
normalizedPath =
|
|
351
|
+
this._pathPrefix && !normalizedPath.startsWith(this._pathPrefix)
|
|
352
|
+
? `${this._pathPrefix}${normalizedPath}*path`
|
|
353
|
+
: normalizedPath;
|
|
354
|
+
try {
|
|
355
|
+
let { regexp: re } = (0, path_to_regexp_1.pathToRegexp)(normalizedPath);
|
|
356
|
+
re = hasEndOfStringCharacter
|
|
357
|
+
? new RegExp(re.source + '$', re.flags)
|
|
358
|
+
: re;
|
|
359
|
+
// The following type assertion is valid as we use import('@fastify/middie') rather than require('@fastify/middie')
|
|
360
|
+
// ref https://github.com/fastify/middie/pull/55
|
|
361
|
+
this.instance.use(normalizedPath, (req, res, next) => {
|
|
362
|
+
const queryParamsIndex = req.originalUrl.indexOf('?');
|
|
363
|
+
const pathname = queryParamsIndex >= 0
|
|
364
|
+
? req.originalUrl.slice(0, queryParamsIndex)
|
|
365
|
+
: req.originalUrl;
|
|
366
|
+
if (!re.exec(pathname + '/') && normalizedPath) {
|
|
367
|
+
return next();
|
|
368
|
+
}
|
|
369
|
+
return callback(req, res, next);
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
catch (e) {
|
|
373
|
+
if (e instanceof TypeError) {
|
|
374
|
+
legacy_route_converter_1.LegacyRouteConverter.printError(path);
|
|
333
375
|
}
|
|
334
|
-
|
|
335
|
-
}
|
|
376
|
+
throw e;
|
|
377
|
+
}
|
|
336
378
|
};
|
|
337
379
|
}
|
|
338
380
|
getType() {
|
|
@@ -3,8 +3,14 @@
|
|
|
3
3
|
* @see https://github.com/fastify/fastify-static/blob/master/types/index.d.ts
|
|
4
4
|
* @publicApi
|
|
5
5
|
*/
|
|
6
|
-
import { RouteOptions, FastifyRequest } from 'fastify';
|
|
6
|
+
import { RouteOptions, FastifyRequest, FastifyReply } from 'fastify';
|
|
7
7
|
import { Stats } from 'fs';
|
|
8
|
+
interface SetHeadersResponse {
|
|
9
|
+
getHeader: FastifyReply['getHeader'];
|
|
10
|
+
setHeader: FastifyReply['header'];
|
|
11
|
+
readonly filename: string;
|
|
12
|
+
statusCode: number;
|
|
13
|
+
}
|
|
8
14
|
interface ExtendedInformation {
|
|
9
15
|
fileCount: number;
|
|
10
16
|
totalFileCount: number;
|
|
@@ -28,12 +34,18 @@ interface ListRender {
|
|
|
28
34
|
(dirs: ListDir[], files: ListFile[]): string;
|
|
29
35
|
}
|
|
30
36
|
interface ListOptions {
|
|
31
|
-
format: 'json' | 'html';
|
|
32
37
|
names: string[];
|
|
33
|
-
render: ListRender;
|
|
34
38
|
extendedFolderInfo?: boolean;
|
|
35
39
|
jsonFormat?: 'names' | 'extended';
|
|
36
40
|
}
|
|
41
|
+
export interface ListOptionsJsonFormat extends ListOptions {
|
|
42
|
+
format: 'json';
|
|
43
|
+
render?: ListRender;
|
|
44
|
+
}
|
|
45
|
+
export interface ListOptionsHtmlFormat extends ListOptions {
|
|
46
|
+
format: 'html';
|
|
47
|
+
render: ListRender;
|
|
48
|
+
}
|
|
37
49
|
interface SendOptions {
|
|
38
50
|
acceptRanges?: boolean;
|
|
39
51
|
cacheControl?: boolean;
|
|
@@ -47,16 +59,16 @@ interface SendOptions {
|
|
|
47
59
|
serveDotFiles?: boolean;
|
|
48
60
|
}
|
|
49
61
|
export interface FastifyStaticOptions extends SendOptions {
|
|
50
|
-
root: string | string[];
|
|
62
|
+
root: string | string[] | URL | URL[];
|
|
51
63
|
prefix?: string;
|
|
52
64
|
prefixAvoidTrailingSlash?: boolean;
|
|
53
65
|
serve?: boolean;
|
|
54
66
|
decorateReply?: boolean;
|
|
55
67
|
schemaHide?: boolean;
|
|
56
|
-
setHeaders?: (
|
|
68
|
+
setHeaders?: (res: SetHeadersResponse, path: string, stat: Stats) => void;
|
|
57
69
|
redirect?: boolean;
|
|
58
70
|
wildcard?: boolean;
|
|
59
|
-
list?: boolean |
|
|
71
|
+
list?: boolean | ListOptionsJsonFormat | ListOptionsHtmlFormat;
|
|
60
72
|
allowedPath?: (pathName: string, root: string, request: FastifyRequest) => boolean;
|
|
61
73
|
/**
|
|
62
74
|
* @description
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/platform-fastify",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0-next.2",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@platform-fastify)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,17 +18,17 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@fastify/cors": "
|
|
22
|
-
"@fastify/formbody": "
|
|
23
|
-
"@fastify/middie": "
|
|
24
|
-
"fastify": "
|
|
21
|
+
"@fastify/cors": "10.0.1",
|
|
22
|
+
"@fastify/formbody": "8.0.1",
|
|
23
|
+
"@fastify/middie": "9.0.2",
|
|
24
|
+
"fastify": "5.1.0",
|
|
25
25
|
"light-my-request": "6.3.0",
|
|
26
|
-
"path-to-regexp": "
|
|
26
|
+
"path-to-regexp": "8.2.0",
|
|
27
27
|
"tslib": "2.7.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@fastify/static": "^6.0.0 || ^7.0.0",
|
|
31
|
-
"@fastify/view": "^7.0.0 || ^8.0.0",
|
|
30
|
+
"@fastify/static": "^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
31
|
+
"@fastify/view": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
32
32
|
"@nestjs/common": "^10.0.0",
|
|
33
33
|
"@nestjs/core": "^10.0.0"
|
|
34
34
|
},
|