@nestjs/platform-fastify 8.3.1 → 8.4.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.
package/Readme.md CHANGED
@@ -54,7 +54,7 @@ With official support, you can get expert help straight from Nest core team. We
54
54
 
55
55
  ## Support
56
56
 
57
- Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
57
+ 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).
58
58
 
59
59
  #### Principal Sponsors
60
60
  <table style="text-align:center;"><tr>
@@ -14,7 +14,7 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
14
14
  this.versionConstraint = {
15
15
  name: 'version',
16
16
  validate(value) {
17
- if (!shared_utils_1.isString(value) && !Array.isArray(value)) {
17
+ if (!(0, shared_utils_1.isString)(value) && !Array.isArray(value)) {
18
18
  throw new Error('Version constraint should be a string or an array of strings.');
19
19
  }
20
20
  },
@@ -22,17 +22,25 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
22
22
  const versions = new Map();
23
23
  return {
24
24
  get(version) {
25
+ if (Array.isArray(version)) {
26
+ return versions.get(version.find(v => versions.has(v))) || null;
27
+ }
25
28
  return versions.get(version) || null;
26
29
  },
27
30
  set(versionOrVersions, store) {
28
- const storeVersionConstraint = version => versions.set(version, store);
31
+ const storeVersionConstraint = (version) => versions.set(version, store);
29
32
  if (Array.isArray(versionOrVersions))
30
33
  versionOrVersions.forEach(storeVersionConstraint);
31
34
  else
32
35
  storeVersionConstraint(versionOrVersions);
33
36
  },
34
37
  del(version) {
35
- versions.delete(version);
38
+ if (Array.isArray(version)) {
39
+ version.forEach(v => versions.delete(v));
40
+ }
41
+ else {
42
+ versions.delete(version);
43
+ }
36
44
  },
37
45
  empty() {
38
46
  versions.clear();
@@ -61,13 +69,17 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
61
69
  return customHeaderVersionParameter;
62
70
  }
63
71
  }
72
+ // Custom Versioning Handler
73
+ else if (this.versioningOptions.type === common_1.VersioningType.CUSTOM) {
74
+ return this.versioningOptions.extractor(req);
75
+ }
64
76
  return undefined;
65
77
  },
66
78
  mustMatchWhenDerived: false,
67
79
  };
68
80
  const instance = instanceOrOptions && instanceOrOptions.server
69
81
  ? instanceOrOptions
70
- : fastify_1.fastify(Object.assign({ constraints: {
82
+ : (0, fastify_1.fastify)(Object.assign({ constraints: {
71
83
  version: this.versionConstraint,
72
84
  } }, instanceOrOptions));
73
85
  this.setInstance(instance);
@@ -130,12 +142,18 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
130
142
  }
131
143
  if (body instanceof common_1.StreamableFile) {
132
144
  const streamHeaders = body.getHeaders();
133
- if (fastifyReply.getHeader('Content-Type') === undefined) {
145
+ if (fastifyReply.getHeader('Content-Type') === undefined &&
146
+ streamHeaders.type !== undefined) {
134
147
  fastifyReply.header('Content-Type', streamHeaders.type);
135
148
  }
136
- if (fastifyReply.getHeader('Content-Disposition') === undefined) {
149
+ if (fastifyReply.getHeader('Content-Disposition') === undefined &&
150
+ streamHeaders.disposition !== undefined) {
137
151
  fastifyReply.header('Content-Disposition', streamHeaders.disposition);
138
152
  }
153
+ if (fastifyReply.getHeader('Content-Length') === undefined &&
154
+ streamHeaders.length !== undefined) {
155
+ fastifyReply.header('Content-Length', streamHeaders.length);
156
+ }
139
157
  body = body.getStream();
140
158
  }
141
159
  return fastifyReply.send(body);
@@ -188,14 +206,14 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
188
206
  this.httpServer = this.instance.server;
189
207
  }
190
208
  useStaticAssets(options) {
191
- return this.register(load_package_util_1.loadPackage('fastify-static', 'FastifyAdapter.useStaticAssets()', () => require('fastify-static')), options);
209
+ return this.register((0, load_package_util_1.loadPackage)('fastify-static', 'FastifyAdapter.useStaticAssets()', () => require('fastify-static')), options);
192
210
  }
193
211
  setViewEngine(options) {
194
- if (shared_utils_1.isString(options)) {
212
+ if ((0, shared_utils_1.isString)(options)) {
195
213
  new common_1.Logger('FastifyAdapter').error("setViewEngine() doesn't support a string argument.");
196
214
  process.exit(1);
197
215
  }
198
- return this.register(load_package_util_1.loadPackage('point-of-view', 'FastifyAdapter.setViewEngine()', () => require('point-of-view')), options);
216
+ return this.register((0, load_package_util_1.loadPackage)('point-of-view', 'FastifyAdapter.setViewEngine()', () => require('point-of-view')), options);
199
217
  }
200
218
  setHeader(response, name, value) {
201
219
  return response.header(name, value);
@@ -252,7 +270,7 @@ class FastifyAdapter extends http_adapter_1.AbstractHttpAdapter {
252
270
  }
253
271
  injectConstraintsIfVersioned(routerMethodKey, ...args) {
254
272
  const handlerRef = args[args.length - 1];
255
- const isVersioned = !shared_utils_1.isUndefined(handlerRef.version) &&
273
+ const isVersioned = !(0, shared_utils_1.isUndefined)(handlerRef.version) &&
256
274
  handlerRef.version !== interfaces_1.VERSION_NEUTRAL;
257
275
  if (isVersioned) {
258
276
  const isPathAndRouteTuple = args.length === 2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/platform-fastify",
3
- "version": "8.3.1",
3
+ "version": "8.4.2",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@platform-fastify)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -17,10 +17,10 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "fastify": "3.27.1",
21
- "fastify-cors": "6.0.2",
20
+ "fastify": "3.27.4",
21
+ "fastify-cors": "6.0.3",
22
22
  "fastify-formbody": "5.2.0",
23
- "light-my-request": "4.7.1",
23
+ "light-my-request": "4.8.0",
24
24
  "middie": "6.0.0",
25
25
  "path-to-regexp": "3.2.0",
26
26
  "tslib": "2.3.1"
package/CHANGELOG.md DELETED
@@ -1,18 +0,0 @@
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
- <a name="8.2.0"></a>
7
- # [8.2.0](https://github.com/nestjs/nest/compare/v8.1.2...v8.2.0) (2021-11-08)
8
-
9
-
10
- ### Bug Fixes
11
-
12
- * **deps:** update dependency fastify to v3.23.1 ([63113d8](https://github.com/nestjs/nest/commit/63113d8))
13
- * **platform-fastify:** fix streamable file processing ([365c40b](https://github.com/nestjs/nest/commit/365c40b))
14
-
15
-
16
- ### Features
17
-
18
- * **common:** add the ability to set some extra metadata about returned files ([5100573](https://github.com/nestjs/nest/commit/5100573))