@tsed/platform-response-filter 6.97.2 → 7.0.0-beta.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/lib/cjs/index.js +0 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/services/PlatformResponseFilter.js +8 -2
- package/lib/cjs/services/PlatformResponseFilter.js.map +1 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/services/PlatformResponseFilter.js +8 -2
- package/lib/esm/services/PlatformResponseFilter.js.map +1 -1
- package/lib/types/index.d.ts +0 -1
- package/lib/types/services/PlatformResponseFilter.d.ts +1 -0
- package/package.json +14 -14
- package/readme.md +123 -7
- package/lib/cjs/services/ConverterService.js +0 -54
- package/lib/cjs/services/ConverterService.js.map +0 -1
- package/lib/esm/services/ConverterService.js +0 -51
- package/lib/esm/services/ConverterService.js.map +0 -1
- package/lib/types/services/ConverterService.d.ts +0 -30
package/lib/cjs/index.js
CHANGED
|
@@ -10,7 +10,6 @@ const tslib_1 = require("tslib");
|
|
|
10
10
|
(0, tslib_1.__exportStar)(require("./interfaces/ResponseFilterMethods"), exports);
|
|
11
11
|
// services
|
|
12
12
|
(0, tslib_1.__exportStar)(require("./services/PlatformResponseFilter"), exports);
|
|
13
|
-
(0, tslib_1.__exportStar)(require("./services/ConverterService"), exports);
|
|
14
13
|
(0, tslib_1.__exportStar)(require("./utils/getContentType"), exports);
|
|
15
14
|
(0, tslib_1.__exportStar)(require("./utils/renderView"), exports);
|
|
16
15
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,aAAa;AACb,2EAA4C;AAE5C,SAAS;AACT,iFAAkD;AAClD,4EAA6C;AAE7C,aAAa;AACb,kFAAmD;AAEnD,WAAW;AACX,iFAAkD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,aAAa;AACb,2EAA4C;AAE5C,SAAS;AACT,iFAAkD;AAClD,4EAA6C;AAE7C,aAAa;AACb,kFAAmD;AAEnD,WAAW;AACX,iFAAkD;AAElD,sEAAuC;AACvC,kEAAmC","sourcesContent":["// decorators\nexport * from \"./decorators/responseFilter\";\n\n// domain\nexport * from \"./domain/ResponseFiltersContainer\";\nexport * from \"./errors/TemplateRenderError\";\n\n// interfaces\nexport * from \"./interfaces/ResponseFilterMethods\";\n\n// services\nexport * from \"./services/PlatformResponseFilter\";\n\nexport * from \"./utils/getContentType\";\nexport * from \"./utils/renderView\";\n"]}
|
|
@@ -6,7 +6,7 @@ const core_1 = require("@tsed/core");
|
|
|
6
6
|
const di_1 = require("@tsed/di");
|
|
7
7
|
const ResponseFiltersContainer_1 = require("../domain/ResponseFiltersContainer");
|
|
8
8
|
const getContentType_1 = require("../utils/getContentType");
|
|
9
|
-
const
|
|
9
|
+
const json_mapper_1 = require("@tsed/json-mapper");
|
|
10
10
|
const renderView_1 = require("../utils/renderView");
|
|
11
11
|
/**
|
|
12
12
|
* @platform
|
|
@@ -64,8 +64,10 @@ let PlatformResponseFilter = class PlatformResponseFilter {
|
|
|
64
64
|
data = await (0, renderView_1.renderView)(data, ctx);
|
|
65
65
|
}
|
|
66
66
|
else if ((0, core_1.isSerializable)(data)) {
|
|
67
|
-
data =
|
|
67
|
+
data = (0, json_mapper_1.serialize)(data, {
|
|
68
68
|
...endpoint.getResponseOptions(response.statusCode),
|
|
69
|
+
additionalProperties: this.additionalProperties,
|
|
70
|
+
useAlias: true,
|
|
69
71
|
endpoint: true
|
|
70
72
|
});
|
|
71
73
|
}
|
|
@@ -81,6 +83,10 @@ let PlatformResponseFilter = class PlatformResponseFilter {
|
|
|
81
83
|
(0, di_1.Constant)("responseFilters", []),
|
|
82
84
|
(0, tslib_1.__metadata)("design:type", Array)
|
|
83
85
|
], PlatformResponseFilter.prototype, "responseFilters", void 0);
|
|
86
|
+
(0, tslib_1.__decorate)([
|
|
87
|
+
(0, di_1.Constant)("additionalProperties"),
|
|
88
|
+
(0, tslib_1.__metadata)("design:type", Boolean)
|
|
89
|
+
], PlatformResponseFilter.prototype, "additionalProperties", void 0);
|
|
84
90
|
PlatformResponseFilter = (0, tslib_1.__decorate)([
|
|
85
91
|
(0, di_1.Injectable)()
|
|
86
92
|
], PlatformResponseFilter);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformResponseFilter.js","sourceRoot":"","sources":["../../../src/services/PlatformResponseFilter.ts"],"names":[],"mappings":";;;;AAAA,qCAAgD;AAChD,iCAAoF;AACpF,iFAA+F;AAE/F,4DAAyE;AACzE,
|
|
1
|
+
{"version":3,"file":"PlatformResponseFilter.js","sourceRoot":"","sources":["../../../src/services/PlatformResponseFilter.ts"],"names":[],"mappings":";;;;AAAA,qCAAgD;AAChD,iCAAoF;AACpF,iFAA+F;AAE/F,4DAAyE;AACzE,mDAA4C;AAC5C,oDAA+C;AAE/C;;GAEG;AAEH,IAAa,sBAAsB,GAAnC,MAAa,sBAAsB;IAAnC;QACE,UAAK,GAAkD,IAAI,GAAG,EAAE,CAAC;IAiFnE,CAAC;IAtEC,IAAI,YAAY;QACd,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAChC,CAAC;IAED,OAAO;QACL,mDAAwB,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAC/C,IAAI,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;gBACxC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,CAAC;aACjD;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,kBAAkB,CAAC,IAAS,EAAE,GAAgB;Q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AAE,GAAgB;QAC7C,MAAM,EAAC,QAAQ,EAAE,QAAQ,EAAC,GAAG,GAAG,CAAC;QAEjC,IAAI,QAAQ,EAAE;YACZ,IAAI,QAAQ,CAAC,IAAI,EAAE;gBACjB,IAAI,GAAG,MAAM,IAAA,uBAAU,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC;aACpC;iBAAM,IAAI,IAAA,qBAAc,EAAC,IAAI,CAAC,EAAE;gBAC/B,IAAI,GAAG,IAAA,uBAAS,EAAC,IAAI,EAAE;oBACrB,GAAG,QAAQ,CAAC,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC;oBACnD,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;oBAC/C,QAAQ,EAAE,IAAI;oBACd,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAC;aACJ;SACF;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA9EC;IADC,IAAA,WAAM,GAAE;2CACC,oBAAe;wDAAC;AAG1B;IADC,IAAA,aAAQ,EAAC,iBAAiB,EAAE,EAAE,CAAC;;+DACyB;AAGzD;IADC,IAAA,aAAQ,EAAC,sBAAsB,CAAC;;oEACK;AAV3B,sBAAsB;IADlC,IAAA,eAAU,GAAE;GACA,sBAAsB,CAkFlC;AAlFY,wDAAsB","sourcesContent":["import {isSerializable, Type} from \"@tsed/core\";\nimport {BaseContext, Constant, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {ResponseFilterKey, ResponseFiltersContainer} from \"../domain/ResponseFiltersContainer\";\nimport {ResponseFilterMethods} from \"../interfaces/ResponseFilterMethods\";\nimport {ANY_CONTENT_TYPE, getContentType} from \"../utils/getContentType\";\nimport {serialize} from \"@tsed/json-mapper\";\nimport {renderView} from \"../utils/renderView\";\n\n/**\n * @platform\n */\n@Injectable()\nexport class PlatformResponseFilter {\n types: Map<ResponseFilterKey, ResponseFilterMethods> = new Map();\n\n @Inject()\n injector: InjectorService;\n\n @Constant(\"responseFilters\", [])\n protected responseFilters: Type<ResponseFilterMethods>[];\n\n @Constant(\"additionalProperties\")\n private additionalProperties: boolean;\n\n get contentTypes(): ResponseFilterKey[] {\n return [...this.types.keys()];\n }\n\n $onInit() {\n ResponseFiltersContainer.forEach((token, type) => {\n if (this.responseFilters.includes(token)) {\n this.types.set(type, this.injector.get(token)!);\n }\n });\n }\n\n getBestContentType(data: any, ctx: BaseContext) {\n const contentType = getContentType(data, ctx);\n\n if (ctx.request.get(\"Accept\")) {\n const bestContentType = ctx.request.accepts([contentType].concat(this.contentTypes).filter(Boolean));\n\n if (bestContentType) {\n return [].concat(bestContentType as any).filter((type) => type !== \"*/*\")[0];\n }\n }\n\n return contentType;\n }\n\n /**\n * Call filters to transform data\n * @param data\n * @param ctx\n */\n async transform(data: unknown, ctx: BaseContext) {\n const {response} = ctx;\n const bestContentType = this.getBestContentType(data, ctx);\n\n bestContentType && response.contentType(bestContentType);\n\n if (this.types.has(bestContentType)) {\n return this.types.get(bestContentType)!.transform(data, ctx);\n }\n\n if (this.types.has(ANY_CONTENT_TYPE)) {\n return this.types.get(ANY_CONTENT_TYPE)!.transform(data, ctx);\n }\n\n return data;\n }\n /**\n * Serialize data before calling filters\n * @param data\n * @param ctx\n */\n async serialize(data: unknown, ctx: BaseContext) {\n const {response, endpoint} = ctx;\n\n if (endpoint) {\n if (endpoint.view) {\n data = await renderView(data, ctx);\n } else if (isSerializable(data)) {\n data = serialize(data, {\n ...endpoint.getResponseOptions(response.statusCode),\n additionalProperties: this.additionalProperties,\n useAlias: true,\n endpoint: true\n });\n }\n }\n\n return data;\n }\n}\n"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -7,7 +7,6 @@ export * from "./errors/TemplateRenderError";
|
|
|
7
7
|
export * from "./interfaces/ResponseFilterMethods";
|
|
8
8
|
// services
|
|
9
9
|
export * from "./services/PlatformResponseFilter";
|
|
10
|
-
export * from "./services/ConverterService";
|
|
11
10
|
export * from "./utils/getContentType";
|
|
12
11
|
export * from "./utils/renderView";
|
|
13
12
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,6BAA6B,CAAC;AAE5C,SAAS;AACT,cAAc,mCAAmC,CAAC;AAClD,cAAc,8BAA8B,CAAC;AAE7C,aAAa;AACb,cAAc,oCAAoC,CAAC;AAEnD,WAAW;AACX,cAAc,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,6BAA6B,CAAC;AAE5C,SAAS;AACT,cAAc,mCAAmC,CAAC;AAClD,cAAc,8BAA8B,CAAC;AAE7C,aAAa;AACb,cAAc,oCAAoC,CAAC;AAEnD,WAAW;AACX,cAAc,mCAAmC,CAAC;AAElD,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC","sourcesContent":["// decorators\nexport * from \"./decorators/responseFilter\";\n\n// domain\nexport * from \"./domain/ResponseFiltersContainer\";\nexport * from \"./errors/TemplateRenderError\";\n\n// interfaces\nexport * from \"./interfaces/ResponseFilterMethods\";\n\n// services\nexport * from \"./services/PlatformResponseFilter\";\n\nexport * from \"./utils/getContentType\";\nexport * from \"./utils/renderView\";\n"]}
|
|
@@ -3,7 +3,7 @@ import { isSerializable } from "@tsed/core";
|
|
|
3
3
|
import { Constant, Inject, Injectable, InjectorService } from "@tsed/di";
|
|
4
4
|
import { ResponseFiltersContainer } from "../domain/ResponseFiltersContainer";
|
|
5
5
|
import { ANY_CONTENT_TYPE, getContentType } from "../utils/getContentType";
|
|
6
|
-
import {
|
|
6
|
+
import { serialize } from "@tsed/json-mapper";
|
|
7
7
|
import { renderView } from "../utils/renderView";
|
|
8
8
|
/**
|
|
9
9
|
* @platform
|
|
@@ -61,8 +61,10 @@ let PlatformResponseFilter = class PlatformResponseFilter {
|
|
|
61
61
|
data = await renderView(data, ctx);
|
|
62
62
|
}
|
|
63
63
|
else if (isSerializable(data)) {
|
|
64
|
-
data =
|
|
64
|
+
data = serialize(data, {
|
|
65
65
|
...endpoint.getResponseOptions(response.statusCode),
|
|
66
|
+
additionalProperties: this.additionalProperties,
|
|
67
|
+
useAlias: true,
|
|
66
68
|
endpoint: true
|
|
67
69
|
});
|
|
68
70
|
}
|
|
@@ -78,6 +80,10 @@ __decorate([
|
|
|
78
80
|
Constant("responseFilters", []),
|
|
79
81
|
__metadata("design:type", Array)
|
|
80
82
|
], PlatformResponseFilter.prototype, "responseFilters", void 0);
|
|
83
|
+
__decorate([
|
|
84
|
+
Constant("additionalProperties"),
|
|
85
|
+
__metadata("design:type", Boolean)
|
|
86
|
+
], PlatformResponseFilter.prototype, "additionalProperties", void 0);
|
|
81
87
|
PlatformResponseFilter = __decorate([
|
|
82
88
|
Injectable()
|
|
83
89
|
], PlatformResponseFilter);
|
|
@@ -1 +1 @@
|
|
|
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,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AACpF,OAAO,EAAoB,wBAAwB,EAAC,MAAM,oCAAoC,CAAC;AAE/F,OAAO,EAAC,gBAAgB,EAAE,cAAc,EAAC,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAC,
|
|
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,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AACpF,OAAO,EAAoB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AAC,CAAC;aACJ;SACF;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA9EC;IADC,MAAM,EAAE;8BACC,eAAe;wDAAC;AAG1B;IADC,QAAQ,CAAC,iBAAiB,EAAE,EAAE,CAAC;;+DACyB;AAGzD;IADC,QAAQ,CAAC,sBAAsB,CAAC;;oEACK;AAV3B,sBAAsB;IADlC,UAAU,EAAE;GACA,sBAAsB,CAkFlC;SAlFY,sBAAsB","sourcesContent":["import {isSerializable, Type} from \"@tsed/core\";\nimport {BaseContext, Constant, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {ResponseFilterKey, ResponseFiltersContainer} from \"../domain/ResponseFiltersContainer\";\nimport {ResponseFilterMethods} from \"../interfaces/ResponseFilterMethods\";\nimport {ANY_CONTENT_TYPE, getContentType} from \"../utils/getContentType\";\nimport {serialize} from \"@tsed/json-mapper\";\nimport {renderView} from \"../utils/renderView\";\n\n/**\n * @platform\n */\n@Injectable()\nexport class PlatformResponseFilter {\n types: Map<ResponseFilterKey, ResponseFilterMethods> = new Map();\n\n @Inject()\n injector: InjectorService;\n\n @Constant(\"responseFilters\", [])\n protected responseFilters: Type<ResponseFilterMethods>[];\n\n @Constant(\"additionalProperties\")\n private additionalProperties: boolean;\n\n get contentTypes(): ResponseFilterKey[] {\n return [...this.types.keys()];\n }\n\n $onInit() {\n ResponseFiltersContainer.forEach((token, type) => {\n if (this.responseFilters.includes(token)) {\n this.types.set(type, this.injector.get(token)!);\n }\n });\n }\n\n getBestContentType(data: any, ctx: BaseContext) {\n const contentType = getContentType(data, ctx);\n\n if (ctx.request.get(\"Accept\")) {\n const bestContentType = ctx.request.accepts([contentType].concat(this.contentTypes).filter(Boolean));\n\n if (bestContentType) {\n return [].concat(bestContentType as any).filter((type) => type !== \"*/*\")[0];\n }\n }\n\n return contentType;\n }\n\n /**\n * Call filters to transform data\n * @param data\n * @param ctx\n */\n async transform(data: unknown, ctx: BaseContext) {\n const {response} = ctx;\n const bestContentType = this.getBestContentType(data, ctx);\n\n bestContentType && response.contentType(bestContentType);\n\n if (this.types.has(bestContentType)) {\n return this.types.get(bestContentType)!.transform(data, ctx);\n }\n\n if (this.types.has(ANY_CONTENT_TYPE)) {\n return this.types.get(ANY_CONTENT_TYPE)!.transform(data, ctx);\n }\n\n return data;\n }\n /**\n * Serialize data before calling filters\n * @param data\n * @param ctx\n */\n async serialize(data: unknown, ctx: BaseContext) {\n const {response, endpoint} = ctx;\n\n if (endpoint) {\n if (endpoint.view) {\n data = await renderView(data, ctx);\n } else if (isSerializable(data)) {\n data = serialize(data, {\n ...endpoint.getResponseOptions(response.statusCode),\n additionalProperties: this.additionalProperties,\n useAlias: true,\n endpoint: true\n });\n }\n }\n\n return data;\n }\n}\n"]}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -3,6 +3,5 @@ export * from "./domain/ResponseFiltersContainer";
|
|
|
3
3
|
export * from "./errors/TemplateRenderError";
|
|
4
4
|
export * from "./interfaces/ResponseFilterMethods";
|
|
5
5
|
export * from "./services/PlatformResponseFilter";
|
|
6
|
-
export * from "./services/ConverterService";
|
|
7
6
|
export * from "./utils/getContentType";
|
|
8
7
|
export * from "./utils/renderView";
|
|
@@ -9,6 +9,7 @@ export declare class PlatformResponseFilter {
|
|
|
9
9
|
types: Map<ResponseFilterKey, ResponseFilterMethods>;
|
|
10
10
|
injector: InjectorService;
|
|
11
11
|
protected responseFilters: Type<ResponseFilterMethods>[];
|
|
12
|
+
private additionalProperties;
|
|
12
13
|
get contentTypes(): ResponseFilterKey[];
|
|
13
14
|
$onInit(): void;
|
|
14
15
|
getBestContentType(data: any, ctx: BaseContext): any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-response-filter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-beta.2",
|
|
4
4
|
"description": "Platform response filter module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -21,26 +21,26 @@
|
|
|
21
21
|
"tslib": "2.2.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@tsed/core": "
|
|
25
|
-
"@tsed/di": "
|
|
26
|
-
"@tsed/exceptions": "
|
|
27
|
-
"@tsed/json-mapper": "
|
|
28
|
-
"@tsed/platform-views": "
|
|
29
|
-
"@tsed/schema": "
|
|
24
|
+
"@tsed/core": "7.0.0-beta.2",
|
|
25
|
+
"@tsed/di": "7.0.0-beta.2",
|
|
26
|
+
"@tsed/exceptions": "7.0.0-beta.2",
|
|
27
|
+
"@tsed/json-mapper": "7.0.0-beta.2",
|
|
28
|
+
"@tsed/platform-views": "7.0.0-beta.2",
|
|
29
|
+
"@tsed/schema": "7.0.0-beta.2"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@tsed/core": "^
|
|
33
|
-
"@tsed/di": "^
|
|
34
|
-
"@tsed/exceptions": "^
|
|
35
|
-
"@tsed/json-mapper": "^
|
|
36
|
-
"@tsed/platform-views": "^
|
|
37
|
-
"@tsed/schema": "^
|
|
32
|
+
"@tsed/core": "^7.0.0-beta.2",
|
|
33
|
+
"@tsed/di": "^7.0.0-beta.2",
|
|
34
|
+
"@tsed/exceptions": "^7.0.0-beta.2",
|
|
35
|
+
"@tsed/json-mapper": "^7.0.0-beta.2",
|
|
36
|
+
"@tsed/platform-views": "^7.0.0-beta.2",
|
|
37
|
+
"@tsed/schema": "^7.0.0-beta.2"
|
|
38
38
|
},
|
|
39
39
|
"repository": "https://github.com/tsedio/tsed",
|
|
40
40
|
"bugs": {
|
|
41
41
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
42
42
|
},
|
|
43
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
43
|
+
"homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/platform/platform-response-filter",
|
|
44
44
|
"author": "Romain Lenzotti",
|
|
45
45
|
"license": "MIT"
|
|
46
46
|
}
|
package/readme.md
CHANGED
|
@@ -29,28 +29,137 @@
|
|
|
29
29
|
|
|
30
30
|
A package of Ts.ED framework. See website: https://tsed.io/
|
|
31
31
|
|
|
32
|
+
# Features
|
|
33
|
+
|
|
34
|
+
Transform data returned by a method to a formatted response based on the stored metadata.
|
|
35
|
+
|
|
32
36
|
# Installation
|
|
33
37
|
|
|
34
38
|
```bash
|
|
35
|
-
npm install --save @tsed/platform-response-filter
|
|
39
|
+
npm install --save @tsed/di @tsed/platform-views @tsed/schema @tsed/json-schema @tsed/platform-response-filter
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
Define a class that return data:
|
|
45
|
+
```typescript
|
|
46
|
+
import {Injectable} from "@tsed/di";
|
|
47
|
+
import {Returns} from "@tsed/schema";
|
|
48
|
+
import {MyModel} from "../models/MyModel";
|
|
49
|
+
|
|
50
|
+
@Injectable()
|
|
51
|
+
class MyService {
|
|
52
|
+
@Returns(200, MyModel)
|
|
53
|
+
async getData() {
|
|
54
|
+
return new MyModel({ id: "id", test: "test" })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Returns(200, MyModel)
|
|
58
|
+
@View("myview.ejs")
|
|
59
|
+
async getDataView() {
|
|
60
|
+
return new MyModel({ id: "id", test: "test" })
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Add a response filter for a specific content-type:
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import {ResponseFilter, Context, ResponseFilterMethods} from "@tsed/common";
|
|
69
|
+
|
|
70
|
+
@ResponseFilter("application/json")
|
|
71
|
+
export class WrapperResponseFilter implements ResponseFilterMethods {
|
|
72
|
+
transform(data: any, ctx: Context) {
|
|
73
|
+
return {data, errors: [], links: {}};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Then call the service in you module:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import {Module, DIContext} from "@tsed/di";
|
|
82
|
+
import {ResponseFilter} from "@tsed/platform-response-filter";
|
|
83
|
+
import "./filters/WrapperResponseFilter"
|
|
84
|
+
|
|
85
|
+
@Module()
|
|
86
|
+
class MyModule {
|
|
87
|
+
@Inject()
|
|
88
|
+
injector: InjectorService;
|
|
89
|
+
|
|
90
|
+
@Inject()
|
|
91
|
+
responseFilter: ResponseFilter;
|
|
92
|
+
|
|
93
|
+
async onRequest(req: any, res: any) {
|
|
94
|
+
const context = new DIContext({
|
|
95
|
+
id: uuid.v4(),
|
|
96
|
+
injector: this.injector,
|
|
97
|
+
logger: this.injector.logger
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
// must implement these methods
|
|
101
|
+
context.request = {
|
|
102
|
+
accepts(...args: any[]) {
|
|
103
|
+
return req.accepts(...args)
|
|
104
|
+
},
|
|
105
|
+
get(key: string) {
|
|
106
|
+
return req.get(key)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
context.response = {
|
|
110
|
+
contentType(contentType: string) {
|
|
111
|
+
res.contentType(contentType)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const service = this.injector.get<MyService>(MyService);
|
|
116
|
+
let data = await service.getData()
|
|
117
|
+
|
|
118
|
+
// serialize data (map Model to Plain object)
|
|
119
|
+
data = await this.responseFilter.serialize(data, context);
|
|
120
|
+
|
|
121
|
+
// call filter based on the right content type
|
|
122
|
+
data = await this.responseFilter.transform(data, context)
|
|
123
|
+
|
|
124
|
+
if (isObject(data)) {
|
|
125
|
+
res.json(data)
|
|
126
|
+
} else {
|
|
127
|
+
res.send(data)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
This example will call the getData() method, serialize the instance MyModel to a plain object then call the WrapperResponseFilter,
|
|
134
|
+
to produce the following response:
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
{
|
|
138
|
+
"data": {
|
|
139
|
+
"id": "id",
|
|
140
|
+
"test": "test"
|
|
141
|
+
},
|
|
142
|
+
"error": [],
|
|
143
|
+
"links": {}
|
|
144
|
+
}
|
|
36
145
|
```
|
|
37
146
|
|
|
38
147
|
## Contributors
|
|
148
|
+
|
|
39
149
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html).
|
|
40
150
|
|
|
41
151
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
42
152
|
|
|
43
|
-
|
|
44
153
|
## Backers
|
|
45
154
|
|
|
46
155
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
47
156
|
|
|
48
157
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
|
|
49
158
|
|
|
50
|
-
|
|
51
159
|
## Sponsors
|
|
52
160
|
|
|
53
|
-
Support this project by becoming a sponsor. Your logo will show up here with a link to your
|
|
161
|
+
Support this project by becoming a sponsor. Your logo will show up here with a link to your
|
|
162
|
+
website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
54
163
|
|
|
55
164
|
## License
|
|
56
165
|
|
|
@@ -58,8 +167,15 @@ The MIT License (MIT)
|
|
|
58
167
|
|
|
59
168
|
Copyright (c) 2016 - 2018 Romain Lenzotti
|
|
60
169
|
|
|
61
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
170
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
171
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
172
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
173
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
62
174
|
|
|
63
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
175
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
176
|
+
Software.
|
|
64
177
|
|
|
65
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
178
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
179
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
180
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
181
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConverterService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const di_1 = require("@tsed/di");
|
|
6
|
-
const json_mapper_1 = require("@tsed/json-mapper");
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated Since 2021-10-03. Use serialize/deserialize functions from @tsed/json-mapper instead
|
|
9
|
-
*/
|
|
10
|
-
let ConverterService = class ConverterService {
|
|
11
|
-
constructor(injectorService, configuration) {
|
|
12
|
-
this.injectorService = injectorService;
|
|
13
|
-
this._additionalProperties = configuration.get("converter.additionalProperties");
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Convert instance to plainObject.
|
|
17
|
-
*
|
|
18
|
-
* @param obj
|
|
19
|
-
* @param options
|
|
20
|
-
*/
|
|
21
|
-
serialize(obj, options = {}) {
|
|
22
|
-
return (0, json_mapper_1.serialize)(obj, {
|
|
23
|
-
useAlias: true,
|
|
24
|
-
additionalProperties: this._additionalProperties === "accept",
|
|
25
|
-
...options
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Convert a plainObject to targetType.
|
|
30
|
-
*
|
|
31
|
-
* ### Options
|
|
32
|
-
*
|
|
33
|
-
* - `ignoreCallback`: callback called for each object which will be deserialized. The callback can return a boolean to avoid the default converter behavior.
|
|
34
|
-
* - `checkRequiredValue`: Disable the required check condition.
|
|
35
|
-
*
|
|
36
|
-
* @param obj Object source that will be deserialized
|
|
37
|
-
* @param options Mapping options
|
|
38
|
-
* @returns {any}
|
|
39
|
-
*/
|
|
40
|
-
deserialize(obj, options = {}) {
|
|
41
|
-
return (0, json_mapper_1.deserialize)(obj, {
|
|
42
|
-
useAlias: true,
|
|
43
|
-
additionalProperties: this._additionalProperties === "accept",
|
|
44
|
-
...options
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
ConverterService = (0, tslib_1.__decorate)([
|
|
49
|
-
(0, di_1.Injectable)(),
|
|
50
|
-
(0, tslib_1.__param)(1, (0, di_1.Configuration)()),
|
|
51
|
-
(0, tslib_1.__metadata)("design:paramtypes", [di_1.InjectorService, Object])
|
|
52
|
-
], ConverterService);
|
|
53
|
-
exports.ConverterService = ConverterService;
|
|
54
|
-
//# sourceMappingURL=ConverterService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConverterService.js","sourceRoot":"","sources":["../../../src/services/ConverterService.ts"],"names":[],"mappings":";;;;AAAA,iCAAoE;AACpE,mDAAyG;AAEzG;;GAEG;AAEH,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAG3B,YAAoB,eAAgC,EAAmB,aAA4B;QAA/E,oBAAe,GAAf,eAAe,CAAiB;QAClD,IAAI,CAAC,qBAAqB,GAAG,aAAa,CAAC,GAAG,CAAS,gCAAgC,CAAC,CAAC;IAC3F,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,GAAQ,EAAE,UAAiC,EAAE;QACrD,OAAO,IAAA,uBAAS,EAAC,GAAG,EAAE;YACpB,QAAQ,EAAE,IAAI;YACd,oBAAoB,EAAE,IAAI,CAAC,qBAAqB,KAAK,QAAQ;YAC7D,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;OAWG;IACH,WAAW,CAAC,GAAQ,EAAE,UAAmC,EAAE;QACzD,OAAO,IAAA,yBAAW,EAAC,GAAG,EAAE;YACtB,QAAQ,EAAE,IAAI;YACd,oBAAoB,EAAE,IAAI,CAAC,qBAAqB,KAAK,QAAQ;YAC7D,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAxCY,gBAAgB;IAD5B,IAAA,eAAU,GAAE;IAI4C,wBAAA,IAAA,kBAAa,GAAE,CAAA;kDAAjC,oBAAe;GAHzC,gBAAgB,CAwC5B;AAxCY,4CAAgB","sourcesContent":["import {Configuration, Injectable, InjectorService} from \"@tsed/di\";\nimport {deserialize, JsonDeserializerOptions, JsonSerializerOptions, serialize} from \"@tsed/json-mapper\";\n\n/**\n * @deprecated Since 2021-10-03. Use serialize/deserialize functions from @tsed/json-mapper instead\n */\n@Injectable()\nexport class ConverterService {\n private readonly _additionalProperties: string;\n\n constructor(private injectorService: InjectorService, @Configuration() configuration: Configuration) {\n this._additionalProperties = configuration.get<string>(\"converter.additionalProperties\");\n }\n\n /**\n * Convert instance to plainObject.\n *\n * @param obj\n * @param options\n */\n serialize(obj: any, options: JsonSerializerOptions = {}): any {\n return serialize(obj, {\n useAlias: true,\n additionalProperties: this._additionalProperties === \"accept\",\n ...options\n });\n }\n\n /**\n * Convert a plainObject to targetType.\n *\n * ### Options\n *\n * - `ignoreCallback`: callback called for each object which will be deserialized. The callback can return a boolean to avoid the default converter behavior.\n * - `checkRequiredValue`: Disable the required check condition.\n *\n * @param obj Object source that will be deserialized\n * @param options Mapping options\n * @returns {any}\n */\n deserialize(obj: any, options: JsonDeserializerOptions = {}): any {\n return deserialize(obj, {\n useAlias: true,\n additionalProperties: this._additionalProperties === \"accept\",\n ...options\n });\n }\n}\n"]}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
-
import { Configuration, Injectable, InjectorService } from "@tsed/di";
|
|
3
|
-
import { deserialize, serialize } from "@tsed/json-mapper";
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated Since 2021-10-03. Use serialize/deserialize functions from @tsed/json-mapper instead
|
|
6
|
-
*/
|
|
7
|
-
let ConverterService = class ConverterService {
|
|
8
|
-
constructor(injectorService, configuration) {
|
|
9
|
-
this.injectorService = injectorService;
|
|
10
|
-
this._additionalProperties = configuration.get("converter.additionalProperties");
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Convert instance to plainObject.
|
|
14
|
-
*
|
|
15
|
-
* @param obj
|
|
16
|
-
* @param options
|
|
17
|
-
*/
|
|
18
|
-
serialize(obj, options = {}) {
|
|
19
|
-
return serialize(obj, {
|
|
20
|
-
useAlias: true,
|
|
21
|
-
additionalProperties: this._additionalProperties === "accept",
|
|
22
|
-
...options
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Convert a plainObject to targetType.
|
|
27
|
-
*
|
|
28
|
-
* ### Options
|
|
29
|
-
*
|
|
30
|
-
* - `ignoreCallback`: callback called for each object which will be deserialized. The callback can return a boolean to avoid the default converter behavior.
|
|
31
|
-
* - `checkRequiredValue`: Disable the required check condition.
|
|
32
|
-
*
|
|
33
|
-
* @param obj Object source that will be deserialized
|
|
34
|
-
* @param options Mapping options
|
|
35
|
-
* @returns {any}
|
|
36
|
-
*/
|
|
37
|
-
deserialize(obj, options = {}) {
|
|
38
|
-
return deserialize(obj, {
|
|
39
|
-
useAlias: true,
|
|
40
|
-
additionalProperties: this._additionalProperties === "accept",
|
|
41
|
-
...options
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
ConverterService = __decorate([
|
|
46
|
-
Injectable(),
|
|
47
|
-
__param(1, Configuration()),
|
|
48
|
-
__metadata("design:paramtypes", [InjectorService, Object])
|
|
49
|
-
], ConverterService);
|
|
50
|
-
export { ConverterService };
|
|
51
|
-
//# sourceMappingURL=ConverterService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConverterService.js","sourceRoot":"","sources":["../../../src/services/ConverterService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AACpE,OAAO,EAAC,WAAW,EAAkD,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAEzG;;GAEG;AAEH,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAG3B,YAAoB,eAAgC,EAAmB,aAA4B;QAA/E,oBAAe,GAAf,eAAe,CAAiB;QAClD,IAAI,CAAC,qBAAqB,GAAG,aAAa,CAAC,GAAG,CAAS,gCAAgC,CAAC,CAAC;IAC3F,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,GAAQ,EAAE,UAAiC,EAAE;QACrD,OAAO,SAAS,CAAC,GAAG,EAAE;YACpB,QAAQ,EAAE,IAAI;YACd,oBAAoB,EAAE,IAAI,CAAC,qBAAqB,KAAK,QAAQ;YAC7D,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;OAWG;IACH,WAAW,CAAC,GAAQ,EAAE,UAAmC,EAAE;QACzD,OAAO,WAAW,CAAC,GAAG,EAAE;YACtB,QAAQ,EAAE,IAAI;YACd,oBAAoB,EAAE,IAAI,CAAC,qBAAqB,KAAK,QAAQ;YAC7D,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAxCY,gBAAgB;IAD5B,UAAU,EAAE;IAI4C,WAAA,aAAa,EAAE,CAAA;qCAAjC,eAAe;GAHzC,gBAAgB,CAwC5B;SAxCY,gBAAgB","sourcesContent":["import {Configuration, Injectable, InjectorService} from \"@tsed/di\";\nimport {deserialize, JsonDeserializerOptions, JsonSerializerOptions, serialize} from \"@tsed/json-mapper\";\n\n/**\n * @deprecated Since 2021-10-03. Use serialize/deserialize functions from @tsed/json-mapper instead\n */\n@Injectable()\nexport class ConverterService {\n private readonly _additionalProperties: string;\n\n constructor(private injectorService: InjectorService, @Configuration() configuration: Configuration) {\n this._additionalProperties = configuration.get<string>(\"converter.additionalProperties\");\n }\n\n /**\n * Convert instance to plainObject.\n *\n * @param obj\n * @param options\n */\n serialize(obj: any, options: JsonSerializerOptions = {}): any {\n return serialize(obj, {\n useAlias: true,\n additionalProperties: this._additionalProperties === \"accept\",\n ...options\n });\n }\n\n /**\n * Convert a plainObject to targetType.\n *\n * ### Options\n *\n * - `ignoreCallback`: callback called for each object which will be deserialized. The callback can return a boolean to avoid the default converter behavior.\n * - `checkRequiredValue`: Disable the required check condition.\n *\n * @param obj Object source that will be deserialized\n * @param options Mapping options\n * @returns {any}\n */\n deserialize(obj: any, options: JsonDeserializerOptions = {}): any {\n return deserialize(obj, {\n useAlias: true,\n additionalProperties: this._additionalProperties === \"accept\",\n ...options\n });\n }\n}\n"]}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Configuration, InjectorService } from "@tsed/di";
|
|
2
|
-
import { JsonDeserializerOptions, JsonSerializerOptions } from "@tsed/json-mapper";
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated Since 2021-10-03. Use serialize/deserialize functions from @tsed/json-mapper instead
|
|
5
|
-
*/
|
|
6
|
-
export declare class ConverterService {
|
|
7
|
-
private injectorService;
|
|
8
|
-
private readonly _additionalProperties;
|
|
9
|
-
constructor(injectorService: InjectorService, configuration: Configuration);
|
|
10
|
-
/**
|
|
11
|
-
* Convert instance to plainObject.
|
|
12
|
-
*
|
|
13
|
-
* @param obj
|
|
14
|
-
* @param options
|
|
15
|
-
*/
|
|
16
|
-
serialize(obj: any, options?: JsonSerializerOptions): any;
|
|
17
|
-
/**
|
|
18
|
-
* Convert a plainObject to targetType.
|
|
19
|
-
*
|
|
20
|
-
* ### Options
|
|
21
|
-
*
|
|
22
|
-
* - `ignoreCallback`: callback called for each object which will be deserialized. The callback can return a boolean to avoid the default converter behavior.
|
|
23
|
-
* - `checkRequiredValue`: Disable the required check condition.
|
|
24
|
-
*
|
|
25
|
-
* @param obj Object source that will be deserialized
|
|
26
|
-
* @param options Mapping options
|
|
27
|
-
* @returns {any}
|
|
28
|
-
*/
|
|
29
|
-
deserialize(obj: any, options?: JsonDeserializerOptions): any;
|
|
30
|
-
}
|