@tsed/platform-response-filter 8.0.0-rc.5 → 8.0.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/lib/esm/decorators/responseFilter.js +2 -5
- package/lib/esm/decorators/responseFilter.js.map +1 -1
- package/lib/esm/services/PlatformResponseFilter.js +19 -31
- package/lib/esm/services/PlatformResponseFilter.js.map +1 -1
- package/lib/types/services/PlatformResponseFilter.d.ts +6 -6
- package/package.json +14 -17
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { injectable } from "@tsed/di";
|
|
2
2
|
import { registerResponseFilter } from "../domain/ResponseFiltersContainer.js";
|
|
3
3
|
/**
|
|
4
4
|
* Register a response filter service.
|
|
@@ -10,10 +10,7 @@ export function ResponseFilter(...contentTypes) {
|
|
|
10
10
|
contentTypes.forEach((contentType) => {
|
|
11
11
|
registerResponseFilter(contentType, target);
|
|
12
12
|
});
|
|
13
|
-
|
|
14
|
-
provide: target,
|
|
15
|
-
useClass: target
|
|
16
|
-
});
|
|
13
|
+
injectable(target).class(target);
|
|
17
14
|
};
|
|
18
15
|
}
|
|
19
16
|
//# sourceMappingURL=responseFilter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseFilter.js","sourceRoot":"","sources":["../../../src/decorators/responseFilter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"responseFilter.js","sourceRoot":"","sources":["../../../src/decorators/responseFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAC,sBAAsB,EAAoB,MAAM,uCAAuC,CAAC;AAEhG;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,GAAG,YAAiC;IACjE,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,YAAY,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;YACnC,sBAAsB,CAAC,WAAW,EAAE,MAAa,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;QACH,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { __decorate, __metadata } from "tslib";
|
|
2
1
|
import { isSerializable } from "@tsed/core";
|
|
3
|
-
import {
|
|
2
|
+
import { constant, inject, injectable } from "@tsed/di";
|
|
4
3
|
import { serialize } from "@tsed/json-mapper";
|
|
5
4
|
import { ResponseFiltersContainer } from "../domain/ResponseFiltersContainer.js";
|
|
6
5
|
import { ANY_CONTENT_TYPE, getContentType } from "../utils/getContentType.js";
|
|
@@ -8,20 +7,20 @@ import { renderView } from "../utils/renderView.js";
|
|
|
8
7
|
/**
|
|
9
8
|
* @platform
|
|
10
9
|
*/
|
|
11
|
-
|
|
10
|
+
export class PlatformResponseFilter {
|
|
12
11
|
constructor() {
|
|
13
12
|
this.types = new Map();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return [...this.types.keys()];
|
|
17
|
-
}
|
|
18
|
-
$onInit() {
|
|
13
|
+
this.responseFilters = constant("responseFilters", []);
|
|
14
|
+
this.additionalProperties = constant("additionalProperties");
|
|
19
15
|
ResponseFiltersContainer.forEach((token, type) => {
|
|
20
16
|
if (this.responseFilters.includes(token)) {
|
|
21
|
-
this.types.set(type,
|
|
17
|
+
this.types.set(type, token);
|
|
22
18
|
}
|
|
23
19
|
});
|
|
24
20
|
}
|
|
21
|
+
get contentTypes() {
|
|
22
|
+
return [...this.types.keys()];
|
|
23
|
+
}
|
|
25
24
|
getBestContentType(data, ctx) {
|
|
26
25
|
const contentType = getContentType(data, ctx);
|
|
27
26
|
if (ctx.request.get("Accept")) {
|
|
@@ -42,11 +41,9 @@ let PlatformResponseFilter = class PlatformResponseFilter {
|
|
|
42
41
|
if (ctx.endpoint?.operation) {
|
|
43
42
|
const bestContentType = this.getBestContentType(data, ctx);
|
|
44
43
|
bestContentType && response.contentType(bestContentType);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (this.types.has(ANY_CONTENT_TYPE)) {
|
|
49
|
-
return this.types.get(ANY_CONTENT_TYPE).transform(data, ctx);
|
|
44
|
+
const resolved = this.resolve(bestContentType);
|
|
45
|
+
if (resolved) {
|
|
46
|
+
return resolved.transform(data, ctx);
|
|
50
47
|
}
|
|
51
48
|
}
|
|
52
49
|
return data;
|
|
@@ -76,27 +73,18 @@ let PlatformResponseFilter = class PlatformResponseFilter {
|
|
|
76
73
|
}
|
|
77
74
|
return data;
|
|
78
75
|
}
|
|
76
|
+
resolve(bestContentType) {
|
|
77
|
+
const token = this.types.get(bestContentType) || this.types.get(ANY_CONTENT_TYPE);
|
|
78
|
+
if (token) {
|
|
79
|
+
return inject(token);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
79
82
|
getIncludes(ctx) {
|
|
80
83
|
if (ctx.request.query.includes) {
|
|
81
84
|
return [].concat(ctx.request.query.includes).flatMap((include) => include.split(","));
|
|
82
85
|
}
|
|
83
86
|
return undefined;
|
|
84
87
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
Inject(),
|
|
88
|
-
__metadata("design:type", InjectorService)
|
|
89
|
-
], PlatformResponseFilter.prototype, "injector", void 0);
|
|
90
|
-
__decorate([
|
|
91
|
-
Constant("responseFilters", []),
|
|
92
|
-
__metadata("design:type", Array)
|
|
93
|
-
], PlatformResponseFilter.prototype, "responseFilters", void 0);
|
|
94
|
-
__decorate([
|
|
95
|
-
Constant("additionalProperties"),
|
|
96
|
-
__metadata("design:type", Boolean)
|
|
97
|
-
], PlatformResponseFilter.prototype, "additionalProperties", void 0);
|
|
98
|
-
PlatformResponseFilter = __decorate([
|
|
99
|
-
Injectable()
|
|
100
|
-
], PlatformResponseFilter);
|
|
101
|
-
export { PlatformResponseFilter };
|
|
88
|
+
}
|
|
89
|
+
injectable(PlatformResponseFilter);
|
|
102
90
|
//# sourceMappingURL=PlatformResponseFilter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformResponseFilter.js","sourceRoot":"","sources":["../../../src/services/PlatformResponseFilter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlatformResponseFilter.js","sourceRoot":"","sources":["../../../src/services/PlatformResponseFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAO,MAAM,YAAY,CAAC;AAChD,OAAO,EAAc,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAgB,MAAM,UAAU,CAAC;AAClF,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAoB,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AAElG,OAAO,EAAC,gBAAgB,EAAE,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAKjC;QAJU,UAAK,GAA0C,IAAI,GAAG,EAAE,CAAC;QACzD,oBAAe,GAAG,QAAQ,CAAgC,iBAAiB,EAAE,EAAE,CAAC,CAAC;QACjF,yBAAoB,GAAG,QAAQ,CAAU,sBAAsB,CAAC,CAAC;QAGzE,wBAAwB,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAC/C,IAAI,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAChC,CAAC;IAED,kBAAkB,CAAC,IAAS,EAAE,GAAgB;QAC5C,MAAM,WAAW,GAAG,cAAc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
import { BaseContext, TokenProvider } from "@tsed/di";
|
|
3
3
|
import { ResponseFilterKey } from "../domain/ResponseFiltersContainer.js";
|
|
4
4
|
import { ResponseFilterMethods } from "../interfaces/ResponseFilterMethods.js";
|
|
5
5
|
/**
|
|
6
6
|
* @platform
|
|
7
7
|
*/
|
|
8
8
|
export declare class PlatformResponseFilter {
|
|
9
|
-
protected types: Map<ResponseFilterKey,
|
|
10
|
-
protected
|
|
11
|
-
protected
|
|
12
|
-
|
|
9
|
+
protected types: Map<ResponseFilterKey, TokenProvider>;
|
|
10
|
+
protected responseFilters: Type<ResponseFilterMethods<unknown>>[];
|
|
11
|
+
protected additionalProperties: boolean | undefined;
|
|
12
|
+
constructor();
|
|
13
13
|
get contentTypes(): ResponseFilterKey[];
|
|
14
|
-
$onInit(): void;
|
|
15
14
|
getBestContentType(data: any, ctx: BaseContext): any;
|
|
16
15
|
/**
|
|
17
16
|
* Call filters to transform data
|
|
@@ -25,5 +24,6 @@ export declare class PlatformResponseFilter {
|
|
|
25
24
|
* @param ctx
|
|
26
25
|
*/
|
|
27
26
|
serialize(data: unknown, ctx: BaseContext): Promise<unknown>;
|
|
27
|
+
private resolve;
|
|
28
28
|
private getIncludes;
|
|
29
29
|
}
|
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.0.0
|
|
5
|
+
"version": "8.0.0",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -25,23 +25,23 @@
|
|
|
25
25
|
"tslib": "2.7.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@tsed/barrels": "8.0.0
|
|
29
|
-
"@tsed/core": "8.0.0
|
|
30
|
-
"@tsed/di": "8.0.0
|
|
31
|
-
"@tsed/exceptions": "8.0.0
|
|
32
|
-
"@tsed/json-mapper": "8.0.0
|
|
33
|
-
"@tsed/schema": "8.0.0
|
|
34
|
-
"@tsed/typescript": "8.0.0
|
|
28
|
+
"@tsed/barrels": "8.0.0",
|
|
29
|
+
"@tsed/core": "8.0.0",
|
|
30
|
+
"@tsed/di": "8.0.0",
|
|
31
|
+
"@tsed/exceptions": "8.0.0",
|
|
32
|
+
"@tsed/json-mapper": "8.0.0",
|
|
33
|
+
"@tsed/schema": "8.0.0",
|
|
34
|
+
"@tsed/typescript": "8.0.0",
|
|
35
35
|
"eslint": "9.12.0",
|
|
36
36
|
"typescript": "5.4.5",
|
|
37
37
|
"vitest": "2.1.2"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@tsed/core": "8.0.0
|
|
41
|
-
"@tsed/di": "8.0.0
|
|
42
|
-
"@tsed/exceptions": "8.0.0
|
|
43
|
-
"@tsed/json-mapper": "8.0.0
|
|
44
|
-
"@tsed/schema": "8.0.0
|
|
40
|
+
"@tsed/core": "8.0.0",
|
|
41
|
+
"@tsed/di": "8.0.0",
|
|
42
|
+
"@tsed/exceptions": "8.0.0",
|
|
43
|
+
"@tsed/json-mapper": "8.0.0",
|
|
44
|
+
"@tsed/schema": "8.0.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependenciesMeta": {
|
|
47
47
|
"@tsed/core": {
|
|
@@ -66,8 +66,5 @@
|
|
|
66
66
|
},
|
|
67
67
|
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/platform/platform-response-filter",
|
|
68
68
|
"author": "Romain Lenzotti",
|
|
69
|
-
"license": "MIT"
|
|
70
|
-
"publishConfig": {
|
|
71
|
-
"tag": "rc"
|
|
72
|
-
}
|
|
69
|
+
"license": "MIT"
|
|
73
70
|
}
|