@nestjs/platform-fastify 10.1.2 → 10.2.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/Readme.md CHANGED
@@ -23,7 +23,7 @@
23
23
 
24
24
  ## Description
25
25
 
26
- Nest is a framework for building efficient, scalable <a href="https://nodejs.org" target="_blank">Node.js</a> server-side applications. It uses modern JavaScript, is built with <a href="https://www.typescriptlang.org" target="_blank">TypeScript</a> (preserves compatibility with pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
26
+ Nest is a framework for building efficient, scalable <a href="https://nodejs.org" target="_blank">Node.js</a> server-side applications. It uses modern JavaScript, is built with <a href="https://www.typescriptlang.org" target="_blank">TypeScript</a> (preserves compatibility with pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
27
27
 
28
28
  <p>Under the hood, Nest makes use of <a href="https://expressjs.com/" target="_blank">Express</a>, but also, provides compatibility with a wide range of other libraries, like e.g. <a href="https://github.com/fastify/fastify" target="_blank">Fastify</a>, allowing for easy use of the myriad third-party plugins which are available.</p>
29
29
 
@@ -34,10 +34,10 @@ Nest is a framework for building efficient, scalable <a href="https://nodejs.org
34
34
 
35
35
  ## Getting started
36
36
 
37
- * To check out the [guide](https://docs.nestjs.com), visit [docs.nestjs.com](https://docs.nestjs.com). :books:
38
- * 要查看中文 [指南](readme_zh.md), 请访问 [docs.nestjs.cn](https://docs.nestjs.cn). :books:
39
- * [가이드](readme_kr.md) 문서는 [docs.nestjs.com](https://docs.nestjs.com)에서 확인하실 수 있습니다. :books:
40
- * [ガイド](readme_jp.md)は [docs.nestjs.com](https://docs.nestjs.com)でご確認ください。 :books:
37
+ - To check out the [guide](https://docs.nestjs.com), visit [docs.nestjs.com](https://docs.nestjs.com). :books:
38
+ - 要查看中文 [指南](readme_zh.md), 请访问 [docs.nestjs.cn](https://docs.nestjs.cn). :books:
39
+ - [가이드](readme_kr.md) 문서는 [docs.nestjs.com](https://docs.nestjs.com)에서 확인하실 수 있습니다. :books:
40
+ - [ガイド](readme_jp.md)は [docs.nestjs.com](https://docs.nestjs.com)でご確認ください。 :books:
41
41
 
42
42
  ## Questions
43
43
 
@@ -56,10 +56,13 @@ With official support, you can get expert help straight from Nest core team. We
56
56
  Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support from the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
57
57
 
58
58
  #### Principal Sponsors
59
+
59
60
  <table style="text-align:center;"><tr>
60
61
  <td><a href="https://trilon.io" target="_blank"><img src="https://nestjs.com/img/trilon.svg" width="200" valign="middle" /></a></td>
61
62
  <td>
62
63
  <a href="https://valor-software.com/" target="_blank"><img src="https://docs.nestjs.com/assets/sponsors/valor-software.png" width="170" valign="middle" /></a></td>
64
+ <td>
65
+ <a href="https://amplication.com/" target="_blank"><img src="https://nestjs.com/img/amplication-logo.svg" width="190" valign="middle" /></a></td>
63
66
  </tr></table>
64
67
 
65
68
  #### Gold Sponsors
@@ -69,8 +72,7 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
69
72
  <td>
70
73
  <a href="https://github.com/Sanofi-IADC" target="_blank"><img src="https://docs.nestjs.com/assets/sponsors/sanofi.png" width="180" valign="middle" /></a></td>
71
74
  <td>
72
- <a href="https://nx.dev" target="_blank"><img src="https://nestjs.com/img/nx-logo.png" height="45" valign="middle" /></a></td><td>
73
- <a href="https://amplication.com/" target="_blank"><img src="https://nestjs.com/img/amplication-logo.svg" width="190" valign="middle" /></a></td>
75
+ <a href="https://nx.dev" target="_blank"><img src="https://nestjs.com/img/nx-logo.png" height="45" valign="middle" /></a></td>
74
76
  <td>
75
77
  <a href="https://weld.app/" target="_blank"><img src="https://nestjs.com/img/weld-logo.svg" width="140" valign="middle" /></a></td>
76
78
  <td>
@@ -86,7 +88,8 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
86
88
  #### Silver Sponsors
87
89
 
88
90
  <table style="text-align:center;"><tr>
89
- <td><a href="https://n.inc" target="_blank"><img src="https://nestjs.com/img/n-inc-logo.svg" width="120" valign="middle" /></td></tr>
91
+ <td><a href="https://n.inc" target="_blank"><img src="https://nestjs.com/img/n-inc-logo.svg" width="120" valign="middle" /></td>
92
+ <td><a href="https://twistag.com/" target="_blank"><img src="https://nestjs.com/img/twistag-logo.png" width="120" valign="middle" /></td></tr>
90
93
  </table>
91
94
 
92
95
  #### Sponsors
@@ -111,6 +114,8 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
111
114
  <td align="center" valign="middle"><a href="https://nordbot.app/" target="_blank"><img src="https://nestjs.com/img/nordbot-logo.png" width="120" valign="middle" /></a></td></tr><tr>
112
115
  <td align="center" valign="middle"><a href="https://doppio.sh/" target="_blank"><img src="https://nestjs.com/img/dopiosh-logo.png" width="50" valign="middle" /></a></td>
113
116
  <td align="center" valign="middle"><a href="https://www.hingehealth.com/" target="_blank"><img src="https://nestjs.com/img/hinge-health-logo.svg" width="100" valign="middle" /></a></td>
117
+ <td align="center" valign="middle"><a href="https://julienferand.dev/" target="_blank"><img src="https://nestjs.com/img/julienferand-logo.jpeg" width="65" valign="middle" /></a></td>
118
+ <td align="center" valign="middle"><a href="https://www.tripoffice.com/" target="_blank"><img src="https://nestjs.com/img/tripoffice-logo.png" width="140" valign="middle" /></a></td>
114
119
  </tr></table>
115
120
 
116
121
  ## Backers
@@ -119,9 +124,9 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
119
124
 
120
125
  ## Stay in touch
121
126
 
122
- * Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
123
- * Website - [https://nestjs.com](https://nestjs.com/)
124
- * Twitter - [@nestframework](https://twitter.com/nestframework)
127
+ - Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
128
+ - Website - [https://nestjs.com](https://nestjs.com/)
129
+ - Twitter - [@nestframework](https://twitter.com/nestframework)
125
130
 
126
131
  ## License
127
132
 
@@ -96,6 +96,6 @@ export declare class FastifyAdapter<TServer extends RawServerBase = RawServerDef
96
96
  private registerUrlencodedContentParser;
97
97
  private registerMiddie;
98
98
  private getRequestOriginalUrl;
99
- private injectConstraintsIfVersioned;
99
+ private injectRouteOptions;
100
100
  }
101
101
  export {};
@@ -11,6 +11,7 @@ const symbols_1 = require("fastify/lib/symbols");
11
11
  const pathToRegexp = require("path-to-regexp");
12
12
  // `querystring` is used internally in fastify for registering urlencoded body parser.
13
13
  const querystring_1 = require("querystring");
14
+ const constants_1 = require("../constants");
14
15
  /**
15
16
  * @publicApi
16
17
  */
@@ -122,25 +123,25 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
122
123
  return this.instance.listen(options, callback);
123
124
  }
124
125
  get(...args) {
125
- return this.injectConstraintsIfVersioned('get', ...args);
126
+ return this.injectRouteOptions('get', ...args);
126
127
  }
127
128
  post(...args) {
128
- return this.injectConstraintsIfVersioned('post', ...args);
129
+ return this.injectRouteOptions('post', ...args);
129
130
  }
130
131
  head(...args) {
131
- return this.injectConstraintsIfVersioned('head', ...args);
132
+ return this.injectRouteOptions('head', ...args);
132
133
  }
133
134
  delete(...args) {
134
- return this.injectConstraintsIfVersioned('delete', ...args);
135
+ return this.injectRouteOptions('delete', ...args);
135
136
  }
136
137
  put(...args) {
137
- return this.injectConstraintsIfVersioned('put', ...args);
138
+ return this.injectRouteOptions('put', ...args);
138
139
  }
139
140
  patch(...args) {
140
- return this.injectConstraintsIfVersioned('patch', ...args);
141
+ return this.injectRouteOptions('patch', ...args);
141
142
  }
142
143
  options(...args) {
143
- return this.injectConstraintsIfVersioned('options', ...args);
144
+ return this.injectRouteOptions('options', ...args);
144
145
  }
145
146
  applyVersionFilter(handler, version, versioningOptions) {
146
147
  if (!this.versioningOptions) {
@@ -353,17 +354,26 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
353
354
  getRequestOriginalUrl(rawRequest) {
354
355
  return rawRequest.originalUrl || rawRequest.url;
355
356
  }
356
- injectConstraintsIfVersioned(routerMethodKey, ...args) {
357
+ injectRouteOptions(routerMethodKey, ...args) {
357
358
  const handlerRef = args[args.length - 1];
358
359
  const isVersioned = !(0, shared_utils_1.isUndefined)(handlerRef.version) &&
359
360
  handlerRef.version !== common_1.VERSION_NEUTRAL;
360
- if (isVersioned) {
361
+ const routeConfig = Reflect.getMetadata(constants_1.FASTIFY_ROUTE_CONFIG_METADATA, handlerRef);
362
+ const hasConfig = !(0, shared_utils_1.isUndefined)(routeConfig);
363
+ if (isVersioned || hasConfig) {
361
364
  const isPathAndRouteTuple = args.length === 2;
362
365
  if (isPathAndRouteTuple) {
363
366
  const options = {
364
- constraints: {
365
- version: handlerRef.version,
366
- },
367
+ ...(isVersioned && {
368
+ constraints: {
369
+ version: handlerRef.version,
370
+ },
371
+ }),
372
+ ...(hasConfig && {
373
+ config: {
374
+ ...routeConfig,
375
+ },
376
+ }),
367
377
  };
368
378
  const path = args[0];
369
379
  return this.instance[routerMethodKey](path, options, handlerRef);
package/constants.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const FASTIFY_ROUTE_CONFIG_METADATA = "__fastify_route_config__";
package/constants.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FASTIFY_ROUTE_CONFIG_METADATA = void 0;
4
+ exports.FASTIFY_ROUTE_CONFIG_METADATA = '__fastify_route_config__';
@@ -0,0 +1 @@
1
+ export * from './route-config.decorator';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./route-config.decorator"), exports);
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @param config See {@link https://fastify.dev/docs/latest/Reference/Routes/#config}
3
+ */
4
+ export declare const RouteConfig: (config: any) => import("@nestjs/common").CustomDecorator<string>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RouteConfig = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const constants_1 = require("../constants");
6
+ /**
7
+ * @param config See {@link https://fastify.dev/docs/latest/Reference/Routes/#config}
8
+ */
9
+ const RouteConfig = (config) => (0, common_1.SetMetadata)(constants_1.FASTIFY_ROUTE_CONFIG_METADATA, config);
10
+ exports.RouteConfig = RouteConfig;
package/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './adapters';
2
2
  export * from './interfaces';
3
+ export * from './decorators';
package/index.js CHANGED
@@ -9,3 +9,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const tslib_1 = require("tslib");
10
10
  tslib_1.__exportStar(require("./adapters"), exports);
11
11
  tslib_1.__exportStar(require("./interfaces"), exports);
12
+ tslib_1.__exportStar(require("./decorators"), exports);
@@ -16,7 +16,7 @@ export interface FastifyViewOptions {
16
16
  liquid?: any;
17
17
  dot?: any;
18
18
  };
19
- templates?: string;
19
+ templates?: string | string[];
20
20
  includeViewExtension?: boolean;
21
21
  options?: object;
22
22
  charset?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/platform-fastify",
3
- "version": "10.1.2",
3
+ "version": "10.2.0",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@platform-fastify)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -21,7 +21,7 @@
21
21
  "@fastify/cors": "8.3.0",
22
22
  "@fastify/formbody": "7.4.0",
23
23
  "@fastify/middie": "8.3.0",
24
- "fastify": "4.20.0",
24
+ "fastify": "4.21.0",
25
25
  "light-my-request": "5.10.0",
26
26
  "path-to-regexp": "3.2.0",
27
27
  "tslib": "2.6.1"