@tsed/platform-response-filter 8.6.0-beta.1 → 8.6.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.
@@ -1,23 +1,23 @@
1
- import { isObject, isStream } from "@tsed/core";
1
+ import { isObject } from "@tsed/core";
2
2
  import { inject, injectable } from "@tsed/di";
3
3
  import { ANY_CONTENT_TYPE } from "../constants/ANY_CONTENT_TYPE.js";
4
4
  import { PLATFORM_CONTENT_TYPES_CONTAINER } from "./PlatformContentTypesContainer.js";
5
5
  /**
6
- * Determine the content type of the response based on the data and the context.
7
- * @param {unknown} data
8
- * @param {BaseContext} ctx
9
6
  * @ignore
10
7
  */
11
8
  export function getContentType(data, ctx) {
12
- const { endpoint, endpoint: { operation }, response } = ctx;
13
- const contentType = response.getContentType() || operation.getContentTypeOf(response.statusCode);
9
+ const { endpoint, response } = ctx;
10
+ const { operation } = endpoint;
11
+ const contentType = response.getContentType() || operation.getContentTypeOf(response.statusCode) || "";
14
12
  if (contentType && contentType !== ANY_CONTENT_TYPE) {
15
- return contentType === "application/json" && isObject(data) ? "application/json" : contentType;
13
+ if (contentType === "application/json" && isObject(data)) {
14
+ return "application/json";
15
+ }
16
+ return contentType;
16
17
  }
17
18
  if (endpoint.view) {
18
19
  return "text/html";
19
20
  }
20
- return isObject(data) && !isStream(data) && !Buffer.isBuffer(data) ? "application/json" : contentType;
21
21
  }
22
22
  /**
23
23
  * @ignore
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformContentTypeResolver.js","sourceRoot":"","sources":["../../../src/services/PlatformContentTypeResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAmB,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAE9D,OAAO,EAAC,gBAAgB,EAAC,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAC,gCAAgC,EAAC,MAAM,oCAAo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AC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,QAAQ,CAAC,IAAS,EAAE,GAAgB;IAC3C,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAE9C,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,MAAM,EAAC,YAAY,EAAC,GAAG,MAAM,CAAmC,gCAAgC,CAAC,CAAC;QAElG,MAAM,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QAEhG,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC,MAAM,CAAC,eAAsB,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAMD,MAAM,CAAC,MAAM,8BAA8B,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;KACnG,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC;KACvB,KAAK,EAAE,CAAC"}
@@ -1,11 +1,8 @@
1
1
  import { type BaseContext } from "@tsed/di";
2
2
  /**
3
- * Determine the content type of the response based on the data and the context.
4
- * @param {unknown} data
5
- * @param {BaseContext} ctx
6
3
  * @ignore
7
4
  */
8
- export declare function getContentType(data: unknown, ctx: BaseContext): any;
5
+ export declare function getContentType(data: any, ctx: BaseContext): any;
9
6
  /**
10
7
  * @ignore
11
8
  */
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsed/platform-response-filter",
3
3
  "description": "Platform response filter module for Ts.ED Framework",
4
4
  "type": "module",
5
- "version": "8.6.0-beta.1",
5
+ "version": "8.6.0",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -26,23 +26,23 @@
26
26
  "tslib": "2.7.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@tsed/barrels": "8.6.0-beta.1",
30
- "@tsed/core": "8.6.0-beta.1",
31
- "@tsed/di": "8.6.0-beta.1",
32
- "@tsed/exceptions": "8.6.0-beta.1",
33
- "@tsed/json-mapper": "8.6.0-beta.1",
34
- "@tsed/schema": "8.6.0-beta.1",
35
- "@tsed/typescript": "8.6.0-beta.1",
29
+ "@tsed/barrels": "8.6.0",
30
+ "@tsed/core": "8.6.0",
31
+ "@tsed/di": "8.6.0",
32
+ "@tsed/exceptions": "8.6.0",
33
+ "@tsed/json-mapper": "8.6.0",
34
+ "@tsed/schema": "8.6.0",
35
+ "@tsed/typescript": "8.6.0",
36
36
  "eslint": "9.12.0",
37
37
  "typescript": "5.4.5",
38
38
  "vitest": "2.1.2"
39
39
  },
40
40
  "peerDependencies": {
41
- "@tsed/core": ">=8.6.0-beta.1",
42
- "@tsed/di": ">=8.6.0-beta.1",
43
- "@tsed/exceptions": ">=8.6.0-beta.1",
44
- "@tsed/json-mapper": ">=8.6.0-beta.1",
45
- "@tsed/schema": ">=8.6.0-beta.1"
41
+ "@tsed/core": ">=8.6.0",
42
+ "@tsed/di": ">=8.6.0",
43
+ "@tsed/exceptions": ">=8.6.0",
44
+ "@tsed/json-mapper": ">=8.6.0",
45
+ "@tsed/schema": ">=8.6.0"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "@tsed/core": {
@@ -67,8 +67,5 @@
67
67
  },
68
68
  "homepage": "https://github.com/tsedio/tsed/tree/production/packages/platform/platform-response-filter",
69
69
  "author": "Romain Lenzotti",
70
- "license": "MIT",
71
- "publishConfig": {
72
- "tag": "beta"
73
- }
70
+ "license": "MIT"
74
71
  }
package/readme.md CHANGED
@@ -20,7 +20,7 @@
20
20
  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
21
21
  <a href="https://tsed.dev/getting-started/">Getting started</a>
22
22
  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
23
- <a href="https://slack.tsed.io">Slack</a>
23
+ <a href="https://slack.tsed.dev">Slack</a>
24
24
  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
25
25
  <a href="https://twitter.com/TsED_io">Twitter</a>
26
26
  </div>
@@ -1,6 +1,5 @@
1
1
  import {PlatformTest} from "@tsed/platform-http/testing";
2
2
  import {EndpointMetadata, Get, Returns, View} from "@tsed/schema";
3
- import {createReadStream} from "fs";
4
3
 
5
4
  import {PLATFORM_CONTENT_TYPE_RESOLVER} from "./PlatformContentTypeResolver.js";
6
5
  import {PLATFORM_CONTENT_TYPES_CONTAINER} from "./PlatformContentTypesContainer.js";
@@ -31,37 +30,7 @@ describe("PlatformContentTypeResolver", () => {
31
30
  beforeEach(() => PlatformTest.create());
32
31
  afterEach(() => PlatformTest.reset());
33
32
 
34
- it("should return the content type (undefined | Buffer)", async () => {
35
- class TestController {
36
- @Get("/")
37
- get() {}
38
- }
39
-
40
- const {contentTypeResolver, ctx, data} = await getTestFixture();
41
-
42
- ctx.endpoint = EndpointMetadata.get(TestController, "get");
43
-
44
- const result = await contentTypeResolver(Buffer.from("data"), ctx);
45
-
46
- expect(result).toEqual(undefined);
47
- });
48
- it("should return the content type (undefined | Stream)", async () => {
49
- class TestController {
50
- @Get("/")
51
- get() {}
52
- }
53
-
54
- const stream = createReadStream(`${import.meta.dirname}/__mock__/response.txt`);
55
-
56
- const {contentTypeResolver, ctx, data} = await getTestFixture();
57
-
58
- ctx.endpoint = EndpointMetadata.get(TestController, "get");
59
-
60
- const result = await contentTypeResolver(stream, ctx);
61
-
62
- expect(result).toEqual(undefined);
63
- });
64
- it("should return the content type (object - empty resolve content type - application/json)", async () => {
33
+ it("should return the content type (undefined)", async () => {
65
34
  class TestController {
66
35
  @Get("/")
67
36
  get() {}
@@ -73,7 +42,7 @@ describe("PlatformContentTypeResolver", () => {
73
42
 
74
43
  const result = await contentTypeResolver(data, ctx);
75
44
 
76
- expect(result).toEqual("application/json");
45
+ expect(result).toEqual(undefined);
77
46
  });
78
47
  it("should return the content type (object - application/json)", async () => {
79
48
  class TestController {
@@ -1,33 +1,29 @@
1
- import {isObject, isStream} from "@tsed/core";
1
+ import {isObject} from "@tsed/core";
2
2
  import {type BaseContext, inject, injectable} from "@tsed/di";
3
3
 
4
4
  import {ANY_CONTENT_TYPE} from "../constants/ANY_CONTENT_TYPE.js";
5
5
  import {PLATFORM_CONTENT_TYPES_CONTAINER} from "./PlatformContentTypesContainer.js";
6
6
 
7
7
  /**
8
- * Determine the content type of the response based on the data and the context.
9
- * @param {unknown} data
10
- * @param {BaseContext} ctx
11
8
  * @ignore
12
9
  */
13
- export function getContentType(data: unknown, ctx: BaseContext) {
14
- const {
15
- endpoint,
16
- endpoint: {operation},
17
- response
18
- } = ctx;
10
+ export function getContentType(data: any, ctx: BaseContext) {
11
+ const {endpoint, response} = ctx;
12
+ const {operation} = endpoint;
19
13
 
20
- const contentType = response.getContentType() || operation.getContentTypeOf(response.statusCode);
14
+ const contentType = response.getContentType() || operation.getContentTypeOf(response.statusCode) || "";
21
15
 
22
16
  if (contentType && contentType !== ANY_CONTENT_TYPE) {
23
- return contentType === "application/json" && isObject(data) ? "application/json" : contentType;
17
+ if (contentType === "application/json" && isObject(data)) {
18
+ return "application/json";
19
+ }
20
+
21
+ return contentType;
24
22
  }
25
23
 
26
24
  if (endpoint.view) {
27
25
  return "text/html";
28
26
  }
29
-
30
- return isObject(data) && !isStream(data) && !Buffer.isBuffer(data) ? "application/json" : contentType;
31
27
  }
32
28
 
33
29
  /**