@tsed/platform-response-filter 6.87.2 → 6.88.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/errors/TemplateRenderError.d.ts +14 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +48 -3
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +46 -3
- package/lib/index.modern.js.map +1 -1
- package/lib/utils/renderView.d.ts +2 -0
- package/package.json +13 -13
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
import { InternalServerError } from "@tsed/exceptions";
|
|
3
|
+
/**
|
|
4
|
+
* @private
|
|
5
|
+
*/
|
|
6
|
+
export declare class TemplateRenderError extends InternalServerError {
|
|
7
|
+
name: string;
|
|
8
|
+
constructor(target: Type<any> | string, method: string | symbol, err: Error);
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
static buildMessage(target: Type<any> | string, method: string | symbol, err: Error): string;
|
|
14
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./decorators/responseFilter";
|
|
2
2
|
export * from "./domain/ResponseFiltersContainer";
|
|
3
|
+
export * from "./errors/TemplateRenderError";
|
|
3
4
|
export * from "./interfaces/ResponseFilterMethods";
|
|
4
5
|
export * from "./services/PlatformResponseFilter";
|
|
5
6
|
export * from "./services/ConverterService";
|
|
6
7
|
export * from "./utils/getContentType";
|
|
8
|
+
export * from "./utils/renderView";
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var di = require('@tsed/di');
|
|
2
|
-
var tslib = require('tslib');
|
|
3
2
|
var core = require('@tsed/core');
|
|
4
|
-
var
|
|
3
|
+
var exceptions = require('@tsed/exceptions');
|
|
4
|
+
var tslib = require('tslib');
|
|
5
5
|
var jsonMapper = require('@tsed/json-mapper');
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -35,6 +35,27 @@ function ResponseFilter(...contentTypes) {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
class TemplateRenderError extends exceptions.InternalServerError {
|
|
43
|
+
constructor(target, method, err) {
|
|
44
|
+
super(TemplateRenderError.buildMessage(target, method, err));
|
|
45
|
+
this.name = "TEMPLATE_RENDER_ERROR";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @returns {string}
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
static buildMessage(target, method, err) {
|
|
54
|
+
return `Template rendering error: ${core.nameOf(target)}.${String(method)}()\n` + err;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
38
59
|
function _extends() {
|
|
39
60
|
_extends = Object.assign || function (target) {
|
|
40
61
|
for (var i = 1; i < arguments.length; i++) {
|
|
@@ -130,6 +151,28 @@ exports.ConverterService = class ConverterService {
|
|
|
130
151
|
};
|
|
131
152
|
exports.ConverterService = tslib.__decorate([di.Injectable(), tslib.__param(1, di.Configuration()), tslib.__metadata("design:paramtypes", [di.InjectorService, Object])], exports.ConverterService);
|
|
132
153
|
|
|
154
|
+
async function renderView(data, $ctx) {
|
|
155
|
+
const {
|
|
156
|
+
response,
|
|
157
|
+
endpoint
|
|
158
|
+
} = $ctx;
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
const {
|
|
162
|
+
data
|
|
163
|
+
} = $ctx;
|
|
164
|
+
const {
|
|
165
|
+
path,
|
|
166
|
+
options
|
|
167
|
+
} = endpoint.view;
|
|
168
|
+
return await response.render(path, _extends({}, options, data, {
|
|
169
|
+
$ctx
|
|
170
|
+
}));
|
|
171
|
+
} catch (err) {
|
|
172
|
+
throw new TemplateRenderError(endpoint.targetName, endpoint.propertyKey, err);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
133
176
|
/**
|
|
134
177
|
* @platform
|
|
135
178
|
*/
|
|
@@ -203,7 +246,7 @@ exports.PlatformResponseFilter = class PlatformResponseFilter {
|
|
|
203
246
|
|
|
204
247
|
if (endpoint) {
|
|
205
248
|
if (endpoint.view) {
|
|
206
|
-
data = await
|
|
249
|
+
data = await renderView(data, ctx);
|
|
207
250
|
} else if (core.isSerializable(data)) {
|
|
208
251
|
data = this.injector.get(exports.ConverterService).serialize(data, _extends({}, endpoint.getResponseOptions(response.statusCode), {
|
|
209
252
|
endpoint: true
|
|
@@ -225,6 +268,8 @@ exports.PlatformResponseFilter = tslib.__decorate([di.Injectable()], exports.Pla
|
|
|
225
268
|
exports.ANY_CONTENT_TYPE = ANY_CONTENT_TYPE;
|
|
226
269
|
exports.ResponseFilter = ResponseFilter;
|
|
227
270
|
exports.ResponseFiltersContainer = ResponseFiltersContainer;
|
|
271
|
+
exports.TemplateRenderError = TemplateRenderError;
|
|
228
272
|
exports.getContentType = getContentType;
|
|
229
273
|
exports.registerResponseFilter = registerResponseFilter;
|
|
274
|
+
exports.renderView = renderView;
|
|
230
275
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/domain/ResponseFiltersContainer.ts","../src/decorators/responseFilter.ts","../src/utils/getContentType.ts","../src/services/ConverterService.ts","../src/services/PlatformResponseFilter.ts"],"sourcesContent":["import {Type} from \"@tsed/core\";\nimport {ResponseFilterMethods} from \"../interfaces/ResponseFilterMethods\";\n/**\n * @ignore\n */\nexport type ResponseFilterKey = \"*/*\" | \"application/json\" | \"text/html\" | \"plain/text\" | string;\n/**\n * @ignore\n */\n// tslint:disable-next-line:variable-name\nexport const ResponseFiltersContainer = new Map<ResponseFilterKey, Type<ResponseFilterMethods>>();\n/**\n * @ignore\n */\nexport function registerResponseFilter(type: ResponseFilterKey, token: Type<ResponseFilterMethods>) {\n ResponseFiltersContainer.set(type, token);\n}\n","import {Type} from \"@tsed/core\";\nimport {registerProvider} from \"@tsed/di\";\nimport {registerResponseFilter, ResponseFilterKey} from \"../domain/ResponseFiltersContainer\";\n\n/**\n * Register a response filter service.\n * @param contentTypes\n * @decorator\n */\nexport function ResponseFilter(...contentTypes: ResponseFilterKey[]): ClassDecorator {\n return <T = any>(target: T): void | T => {\n contentTypes.forEach((contentType) => {\n registerResponseFilter(contentType, target as any);\n });\n registerProvider({\n provide: target,\n useClass: (target as unknown) as Type<any>\n });\n };\n}\n","import {isObject} from \"@tsed/core\";\nimport type {BaseContext} from \"@tsed/di\";\nexport const ANY_CONTENT_TYPE = \"*/*\";\n/**\n * @ignore\n */\nexport function getContentType(data: any, ctx: BaseContext) {\n const {endpoint, response} = ctx;\n const {operation} = endpoint;\n\n const contentType = response.getContentType() || operation.getContentTypeOf(response.statusCode) || \"\";\n\n if (contentType && contentType !== ANY_CONTENT_TYPE) {\n if (contentType === \"application/json\") {\n if (isObject(data)) {\n return contentType;\n }\n } else {\n return contentType;\n }\n }\n\n if (typeof data === \"string\" && endpoint.view) {\n return \"text/html\";\n }\n}\n","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","import {isSerializable, Type} from \"@tsed/core\";\nimport {BaseContext, Constant, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {renderView} from \"@tsed/platform-views\";\nimport {ResponseFilterKey, ResponseFiltersContainer} from \"../domain/ResponseFiltersContainer\";\nimport {ResponseFilterMethods} from \"../interfaces/ResponseFilterMethods\";\nimport {ANY_CONTENT_TYPE, getContentType} from \"../utils/getContentType\";\nimport {ConverterService} from \"./ConverterService\";\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 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 * 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 = this.injector.get<ConverterService>(ConverterService)!.serialize(data, {\n ...endpoint.getResponseOptions(response.statusCode),\n endpoint: true\n });\n }\n }\n\n return data;\n }\n}\n"],"names":["ResponseFiltersContainer","Map","registerResponseFilter","type","token","set","ResponseFilter","contentTypes","target","forEach","contentType","registerProvider","provide","useClass","ANY_CONTENT_TYPE","getContentType","data","ctx","endpoint","response","operation","getContentTypeOf","statusCode","isObject","view","ConverterService","constructor","injectorService","configuration","_additionalProperties","get","serialize","obj","options","useAlias","additionalProperties","deserialize","Injectable","__param","Configuration","InjectorService","PlatformResponseFilter","types","keys","$onInit","responseFilters","includes","injector","getBestContentType","request","bestContentType","accepts","concat","filter","Boolean","transform","has","renderView","isSerializable","getResponseOptions","__decorate","Inject","Constant"],"mappings":";;;;;;AAMA;;;AAGA;MACaA,wBAAwB,GAAG,IAAIC,GAAJ;AACxC;;;;SAGgBC,uBAAuBC,MAAyBC;AAC9DJ,EAAAA,wBAAwB,CAACK,GAAzB,CAA6BF,IAA7B,EAAmCC,KAAnC;AACD;;ACZD;;;;;;SAKgBE,eAAe,GAAGC;AAChC,SAAiBC,MAAV;AACLD,IAAAA,YAAY,CAACE,OAAb,CAAsBC,WAAD;AACnBR,MAAAA,sBAAsB,CAACQ,WAAD,EAAcF,MAAd,CAAtB;AACD,KAFD;AAGAG,IAAAA,mBAAgB,CAAC;AACfC,MAAAA,OAAO,EAAEJ,MADM;AAEfK,MAAAA,QAAQ,EAAGL;AAFI,KAAD,CAAhB;AAID,GARD;AASD;;;;;;;;;;;;;;;;;;;;MCjBYM,gBAAgB,GAAG;AAChC;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}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/domain/ResponseFiltersContainer.ts","../src/decorators/responseFilter.ts","../src/errors/TemplateRenderError.ts","../src/utils/getContentType.ts","../src/services/ConverterService.ts","../src/utils/renderView.ts","../src/services/PlatformResponseFilter.ts"],"sourcesContent":["import {Type} from \"@tsed/core\";\nimport {ResponseFilterMethods} from \"../interfaces/ResponseFilterMethods\";\n/**\n * @ignore\n */\nexport type ResponseFilterKey = \"*/*\" | \"application/json\" | \"text/html\" | \"plain/text\" | string;\n/**\n * @ignore\n */\n// tslint:disable-next-line:variable-name\nexport const ResponseFiltersContainer = new Map<ResponseFilterKey, Type<ResponseFilterMethods>>();\n/**\n * @ignore\n */\nexport function registerResponseFilter(type: ResponseFilterKey, token: Type<ResponseFilterMethods>) {\n ResponseFiltersContainer.set(type, token);\n}\n","import {Type} from \"@tsed/core\";\nimport {registerProvider} from \"@tsed/di\";\nimport {registerResponseFilter, ResponseFilterKey} from \"../domain/ResponseFiltersContainer\";\n\n/**\n * Register a response filter service.\n * @param contentTypes\n * @decorator\n */\nexport function ResponseFilter(...contentTypes: ResponseFilterKey[]): ClassDecorator {\n return <T = any>(target: T): void | T => {\n contentTypes.forEach((contentType) => {\n registerResponseFilter(contentType, target as any);\n });\n registerProvider({\n provide: target,\n useClass: (target as unknown) as Type<any>\n });\n };\n}\n","import {nameOf, Type} from \"@tsed/core\";\nimport {InternalServerError} from \"@tsed/exceptions\";\n\n/**\n * @private\n */\nexport class TemplateRenderError extends InternalServerError {\n name = \"TEMPLATE_RENDER_ERROR\";\n\n constructor(target: Type<any> | string, method: string | symbol, err: Error) {\n super(TemplateRenderError.buildMessage(target, method, err));\n }\n\n /**\n *\n * @returns {string}\n */\n static buildMessage(target: Type<any> | string, method: string | symbol, err: Error) {\n return `Template rendering error: ${nameOf(target)}.${String(method)}()\\n` + err;\n }\n}\n","import {isObject} from \"@tsed/core\";\nimport type {BaseContext} from \"@tsed/di\";\nexport const ANY_CONTENT_TYPE = \"*/*\";\n/**\n * @ignore\n */\nexport function getContentType(data: any, ctx: BaseContext) {\n const {endpoint, response} = ctx;\n const {operation} = endpoint;\n\n const contentType = response.getContentType() || operation.getContentTypeOf(response.statusCode) || \"\";\n\n if (contentType && contentType !== ANY_CONTENT_TYPE) {\n if (contentType === \"application/json\") {\n if (isObject(data)) {\n return contentType;\n }\n } else {\n return contentType;\n }\n }\n\n if (typeof data === \"string\" && endpoint.view) {\n return \"text/html\";\n }\n}\n","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","import {BaseContext} from \"@tsed/di\";\nimport {TemplateRenderError} from \"../errors/TemplateRenderError\";\n\nexport async function renderView(data: any, $ctx: BaseContext) {\n const {response, endpoint} = $ctx;\n try {\n const {data} = $ctx;\n const {path, options} = endpoint.view;\n\n return await response.render(path, {...options, ...data, $ctx});\n } catch (err) {\n throw new TemplateRenderError(endpoint.targetName, endpoint.propertyKey, err);\n }\n}\n","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 {ConverterService} from \"./ConverterService\";\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 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 * 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 = this.injector.get<ConverterService>(ConverterService)!.serialize(data, {\n ...endpoint.getResponseOptions(response.statusCode),\n endpoint: true\n });\n }\n }\n\n return data;\n }\n}\n"],"names":["ResponseFiltersContainer","Map","registerResponseFilter","type","token","set","ResponseFilter","contentTypes","target","forEach","contentType","registerProvider","provide","useClass","TemplateRenderError","InternalServerError","constructor","method","err","buildMessage","nameOf","String","ANY_CONTENT_TYPE","getContentType","data","ctx","endpoint","response","operation","getContentTypeOf","statusCode","isObject","view","ConverterService","injectorService","configuration","_additionalProperties","get","serialize","obj","options","useAlias","additionalProperties","deserialize","Injectable","__param","Configuration","InjectorService","renderView","$ctx","path","render","targetName","propertyKey","PlatformResponseFilter","types","keys","$onInit","responseFilters","includes","injector","getBestContentType","request","bestContentType","accepts","concat","filter","Boolean","transform","has","isSerializable","getResponseOptions","__decorate","Inject","Constant"],"mappings":";;;;;;AAMA;;;AAGA;MACaA,wBAAwB,GAAG,IAAIC,GAAJ;AACxC;;;;SAGgBC,uBAAuBC,MAAyBC;AAC9DJ,EAAAA,wBAAwB,CAACK,GAAzB,CAA6BF,IAA7B,EAAmCC,KAAnC;AACD;;ACZD;;;;;;SAKgBE,eAAe,GAAGC;AAChC,SAAiBC,MAAV;AACLD,IAAAA,YAAY,CAACE,OAAb,CAAsBC,WAAD;AACnBR,MAAAA,sBAAsB,CAACQ,WAAD,EAAcF,MAAd,CAAtB;AACD,KAFD;AAGAG,IAAAA,mBAAgB,CAAC;AACfC,MAAAA,OAAO,EAAEJ,MADM;AAEfK,MAAAA,QAAQ,EAAGL;AAFI,KAAD,CAAhB;AAID,GARD;AASD;;AChBD;;;;MAGaM,4BAA4BC;AAGvCC,EAAAA,YAAYR,QAA4BS,QAAyBC;AAC/D,UAAMJ,mBAAmB,CAACK,YAApB,CAAiCX,MAAjC,EAAyCS,MAAzC,EAAiDC,GAAjD,CAAN;AAHF,aAAA,GAAO,uBAA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kDC,GAAlD,CAAP;AACD;;AAED,WAAOD,IAAP;AACD;AACD;;;;;;;AAKe,QAATc,SAAS,CAACd,IAAD,EAAgBC,GAAhB;AACb,UAAM;AAACE,MAAAA,QAAD;AAAWD,MAAAA;AAAX,QAAuBD,GAA7B;;AAEA,QAAIC,QAAJ,EAAc;AACZ,UAAIA,QAAQ,CAACM,IAAb,EAAmB;AACjBR,QAAAA,IAAI,GAAG,MAAMwB,UAAU,CAACxB,IAAD,EAAOC,GAAP,CAAvB;AACD,OAFD,MAEO,IAAI6C,mBAAc,CAAC9C,IAAD,CAAlB,EAA0B;AAC/BA,QAAAA,IAAI,GAAG,KAAKoC,QAAL,CAAcvB,GAAd,CAAoCJ,wBAApC,EAAuDK,SAAvD,CAAiEd,IAAjE,eACFE,QAAQ,CAAC6C,kBAAT,CAA4B5C,QAAQ,CAACG,UAArC,CADE;AAELJ,UAAAA,QAAQ,EAAE;AAFL,WAAP;AAID;AACF;;AAED,WAAOF,IAAP;AACD;;;;AAvEDgD,kBADCC,SAAM,oCACG1B,mFAAV;;AAGAyB,kBADCE,WAAQ,CAAC,iBAAD,EAAoB,EAApB,gHACT;;AAPWpB,8BAAsB,qBADlCV,aAAU,KACEU,+BAAA;;;;;;;;;;"}
|
package/lib/index.modern.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { registerProvider, Injectable, Configuration, InjectorService, Inject, Constant } from '@tsed/di';
|
|
2
|
+
import { nameOf, isObject, isSerializable } from '@tsed/core';
|
|
3
|
+
import { InternalServerError } from '@tsed/exceptions';
|
|
2
4
|
import { __decorate, __param, __metadata } from 'tslib';
|
|
3
|
-
import { isObject, isSerializable } from '@tsed/core';
|
|
4
|
-
import { renderView } from '@tsed/platform-views';
|
|
5
5
|
import { serialize, deserialize } from '@tsed/json-mapper';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -35,6 +35,27 @@ function ResponseFilter(...contentTypes) {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
class TemplateRenderError extends InternalServerError {
|
|
43
|
+
constructor(target, method, err) {
|
|
44
|
+
super(TemplateRenderError.buildMessage(target, method, err));
|
|
45
|
+
this.name = "TEMPLATE_RENDER_ERROR";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @returns {string}
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
static buildMessage(target, method, err) {
|
|
54
|
+
return `Template rendering error: ${nameOf(target)}.${String(method)}()\n` + err;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
38
59
|
function _extends() {
|
|
39
60
|
_extends = Object.assign || function (target) {
|
|
40
61
|
for (var i = 1; i < arguments.length; i++) {
|
|
@@ -130,6 +151,28 @@ let ConverterService = class ConverterService {
|
|
|
130
151
|
};
|
|
131
152
|
ConverterService = __decorate([Injectable(), __param(1, Configuration()), __metadata("design:paramtypes", [InjectorService, Object])], ConverterService);
|
|
132
153
|
|
|
154
|
+
async function renderView(data, $ctx) {
|
|
155
|
+
const {
|
|
156
|
+
response,
|
|
157
|
+
endpoint
|
|
158
|
+
} = $ctx;
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
const {
|
|
162
|
+
data: _data
|
|
163
|
+
} = $ctx;
|
|
164
|
+
const {
|
|
165
|
+
path,
|
|
166
|
+
options
|
|
167
|
+
} = endpoint.view;
|
|
168
|
+
return await response.render(path, _extends({}, options, _data, {
|
|
169
|
+
$ctx
|
|
170
|
+
}));
|
|
171
|
+
} catch (err) {
|
|
172
|
+
throw new TemplateRenderError(endpoint.targetName, endpoint.propertyKey, err);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
133
176
|
/**
|
|
134
177
|
* @platform
|
|
135
178
|
*/
|
|
@@ -222,5 +265,5 @@ __decorate([Constant("responseFilters", []), __metadata("design:type", Array)],
|
|
|
222
265
|
|
|
223
266
|
PlatformResponseFilter = __decorate([Injectable()], PlatformResponseFilter);
|
|
224
267
|
|
|
225
|
-
export { ANY_CONTENT_TYPE, ConverterService, PlatformResponseFilter, ResponseFilter, ResponseFiltersContainer, getContentType, registerResponseFilter };
|
|
268
|
+
export { ANY_CONTENT_TYPE, ConverterService, PlatformResponseFilter, ResponseFilter, ResponseFiltersContainer, TemplateRenderError, getContentType, registerResponseFilter, renderView };
|
|
226
269
|
//# sourceMappingURL=index.modern.js.map
|
package/lib/index.modern.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/domain/ResponseFiltersContainer.ts","../src/decorators/responseFilter.ts","../src/utils/getContentType.ts","../src/services/ConverterService.ts","../src/services/PlatformResponseFilter.ts"],"sourcesContent":["import {Type} from \"@tsed/core\";\nimport {ResponseFilterMethods} from \"../interfaces/ResponseFilterMethods\";\n/**\n * @ignore\n */\nexport type ResponseFilterKey = \"*/*\" | \"application/json\" | \"text/html\" | \"plain/text\" | string;\n/**\n * @ignore\n */\n// tslint:disable-next-line:variable-name\nexport const ResponseFiltersContainer = new Map<ResponseFilterKey, Type<ResponseFilterMethods>>();\n/**\n * @ignore\n */\nexport function registerResponseFilter(type: ResponseFilterKey, token: Type<ResponseFilterMethods>) {\n ResponseFiltersContainer.set(type, token);\n}\n","import {Type} from \"@tsed/core\";\nimport {registerProvider} from \"@tsed/di\";\nimport {registerResponseFilter, ResponseFilterKey} from \"../domain/ResponseFiltersContainer\";\n\n/**\n * Register a response filter service.\n * @param contentTypes\n * @decorator\n */\nexport function ResponseFilter(...contentTypes: ResponseFilterKey[]): ClassDecorator {\n return <T = any>(target: T): void | T => {\n contentTypes.forEach((contentType) => {\n registerResponseFilter(contentType, target as any);\n });\n registerProvider({\n provide: target,\n useClass: (target as unknown) as Type<any>\n });\n };\n}\n","import {isObject} from \"@tsed/core\";\nimport type {BaseContext} from \"@tsed/di\";\nexport const ANY_CONTENT_TYPE = \"*/*\";\n/**\n * @ignore\n */\nexport function getContentType(data: any, ctx: BaseContext) {\n const {endpoint, response} = ctx;\n const {operation} = endpoint;\n\n const contentType = response.getContentType() || operation.getContentTypeOf(response.statusCode) || \"\";\n\n if (contentType && contentType !== ANY_CONTENT_TYPE) {\n if (contentType === \"application/json\") {\n if (isObject(data)) {\n return contentType;\n }\n } else {\n return contentType;\n }\n }\n\n if (typeof data === \"string\" && endpoint.view) {\n return \"text/html\";\n }\n}\n","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","import {isSerializable, Type} from \"@tsed/core\";\nimport {BaseContext, Constant, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {renderView} from \"@tsed/platform-views\";\nimport {ResponseFilterKey, ResponseFiltersContainer} from \"../domain/ResponseFiltersContainer\";\nimport {ResponseFilterMethods} from \"../interfaces/ResponseFilterMethods\";\nimport {ANY_CONTENT_TYPE, getContentType} from \"../utils/getContentType\";\nimport {ConverterService} from \"./ConverterService\";\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 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 * 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 = this.injector.get<ConverterService>(ConverterService)!.serialize(data, {\n ...endpoint.getResponseOptions(response.statusCode),\n endpoint: true\n });\n }\n }\n\n return data;\n }\n}\n"],"names":["ResponseFiltersContainer","Map","registerResponseFilter","type","token","set","ResponseFilter","contentTypes","target","forEach","contentType","registerProvider","provide","useClass","ANY_CONTENT_TYPE","getContentType","data","ctx","endpoint","response","operation","getContentTypeOf","statusCode","isObject","view","ConverterService","constructor","injectorService","configuration","_additionalProperties","get","serialize","obj","options","useAlias","additionalProperties","deserialize","Injectable","__param","Configuration","InjectorService","PlatformResponseFilter","types","keys","$onInit","responseFilters","includes","injector","getBestContentType","request","bestContentType","accepts","concat","filter","Boolean","transform","has","renderView","isSerializable","getResponseOptions","__decorate","Inject","Constant"],"mappings":";;;;;;AAMA;;;AAGA;MACaA,wBAAwB,GAAG,IAAIC,GAAJ;AACxC;;;;SAGgBC,uBAAuBC,MAAyBC;AAC9DJ,EAAAA,wBAAwB,CAACK,GAAzB,CAA6BF,IAA7B,EAAmCC,KAAnC;AACD;;ACZD;;;;;;SAKgBE,eAAe,GAAGC;AAChC,SAAiBC,MAAV;AACLD,IAAAA,YAAY,CAACE,OAAb,CAAsBC,WAAD;AACnBR,MAAAA,sBAAsB,CAACQ,WAAD,EAAcF,MAAd,CAAtB;AACD,KAFD;AAGAG,IAAAA,gBAAgB,CAAC;AACfC,MAAAA,OAAO,EAAEJ,MADM;AAEfK,MAAAA,QAAQ,EAAGL;AAFI,KAAD,CAAhB;AAID,GARD;AASD;;;;;;;;;;;;;;;;;;;;MCjBYM,gBAAgB,GAAG;AAChC;;;;SAGgBC,eAAeC,MAAWC;AACxC,QAAM;AAACC,IAAAA,QAAD;AAAWC,IAAAA;AAAX,MAAuBF,GAA7B;AACA,QAAM;AAACG,IAAAA;AAAD,MAAcF,QAApB;AAEA,QAAMR,WAAW,GAAGS,QAAQ,CAACJ,cAAT,MAA6BK,SAAS,CAACC,gBAAV,CAA2BF,QAAQ,CAACG,UAApC,CAA7B,IAAgF,EAApG;;AAEA,MAAIZ,WAAW,IAAIA,WAAW,KAAKI,gBAAnC,EAAqD;AACnD,QAAIJ,WAAW,KAAK,kBAApB,EAAwC;AACtC,UAAIa,QAAQ,CAACP,IAAD,CAAZ,EAAoB;AAClB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ehB,gBAAf,EAAkCyC,SAAlC,CAA4CvC,IAA5C,EAAkDC,GAAlD,CAAP;AACD;;AAED,WAAOD,IAAP;AACD;AACD;;;;;;;AAKe,QAATe,SAAS,CAACf,IAAD,EAAgBC,GAAhB;AACb,UAAM;AAACE,MAAAA,QAAD;AAAWD,MAAAA;AAAX,QAAuBD,GAA7B;;AAEA,QAAIC,QAAJ,EAAc;AACZ,UAAIA,QAAQ,CAACM,IAAb,EAAmB;AACjBR,QAAAA,IAAI,GAAG,MAAMyC,UAAU,CAACzC,IAAD,EAAOC,GAAP,CAAvB;AACD,OAFD,MAEO,IAAIyC,cAAc,CAAC1C,IAAD,CAAlB,EAA0B;AAC/BA,QAAAA,IAAI,GAAG,KAAK+B,QAAL,CAAcjB,GAAd,CAAoCL,gBAApC,EAAuDM,SAAvD,CAAiEf,IAAjE,eACFE,QAAQ,CAACyC,kBAAT,CAA4BxC,QAAQ,CAACG,UAArC,CADE;AAELJ,UAAAA,QAAQ,EAAE;AAFL,WAAP;AAID;AACF;;AAED,WAAOF,IAAP;AACD;;;;AAvED4C,YADCC,MAAM,8BACGrB,wEAAV;;AAGAoB,YADCE,QAAQ,CAAC,iBAAD,EAAoB,EAApB,kGACT;;AAPWrB,sBAAsB,eADlCJ,UAAU,KACEI,uBAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../src/domain/ResponseFiltersContainer.ts","../src/decorators/responseFilter.ts","../src/errors/TemplateRenderError.ts","../src/utils/getContentType.ts","../src/services/ConverterService.ts","../src/utils/renderView.ts","../src/services/PlatformResponseFilter.ts"],"sourcesContent":["import {Type} from \"@tsed/core\";\nimport {ResponseFilterMethods} from \"../interfaces/ResponseFilterMethods\";\n/**\n * @ignore\n */\nexport type ResponseFilterKey = \"*/*\" | \"application/json\" | \"text/html\" | \"plain/text\" | string;\n/**\n * @ignore\n */\n// tslint:disable-next-line:variable-name\nexport const ResponseFiltersContainer = new Map<ResponseFilterKey, Type<ResponseFilterMethods>>();\n/**\n * @ignore\n */\nexport function registerResponseFilter(type: ResponseFilterKey, token: Type<ResponseFilterMethods>) {\n ResponseFiltersContainer.set(type, token);\n}\n","import {Type} from \"@tsed/core\";\nimport {registerProvider} from \"@tsed/di\";\nimport {registerResponseFilter, ResponseFilterKey} from \"../domain/ResponseFiltersContainer\";\n\n/**\n * Register a response filter service.\n * @param contentTypes\n * @decorator\n */\nexport function ResponseFilter(...contentTypes: ResponseFilterKey[]): ClassDecorator {\n return <T = any>(target: T): void | T => {\n contentTypes.forEach((contentType) => {\n registerResponseFilter(contentType, target as any);\n });\n registerProvider({\n provide: target,\n useClass: (target as unknown) as Type<any>\n });\n };\n}\n","import {nameOf, Type} from \"@tsed/core\";\nimport {InternalServerError} from \"@tsed/exceptions\";\n\n/**\n * @private\n */\nexport class TemplateRenderError extends InternalServerError {\n name = \"TEMPLATE_RENDER_ERROR\";\n\n constructor(target: Type<any> | string, method: string | symbol, err: Error) {\n super(TemplateRenderError.buildMessage(target, method, err));\n }\n\n /**\n *\n * @returns {string}\n */\n static buildMessage(target: Type<any> | string, method: string | symbol, err: Error) {\n return `Template rendering error: ${nameOf(target)}.${String(method)}()\\n` + err;\n }\n}\n","import {isObject} from \"@tsed/core\";\nimport type {BaseContext} from \"@tsed/di\";\nexport const ANY_CONTENT_TYPE = \"*/*\";\n/**\n * @ignore\n */\nexport function getContentType(data: any, ctx: BaseContext) {\n const {endpoint, response} = ctx;\n const {operation} = endpoint;\n\n const contentType = response.getContentType() || operation.getContentTypeOf(response.statusCode) || \"\";\n\n if (contentType && contentType !== ANY_CONTENT_TYPE) {\n if (contentType === \"application/json\") {\n if (isObject(data)) {\n return contentType;\n }\n } else {\n return contentType;\n }\n }\n\n if (typeof data === \"string\" && endpoint.view) {\n return \"text/html\";\n }\n}\n","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","import {BaseContext} from \"@tsed/di\";\nimport {TemplateRenderError} from \"../errors/TemplateRenderError\";\n\nexport async function renderView(data: any, $ctx: BaseContext) {\n const {response, endpoint} = $ctx;\n try {\n const {data} = $ctx;\n const {path, options} = endpoint.view;\n\n return await response.render(path, {...options, ...data, $ctx});\n } catch (err) {\n throw new TemplateRenderError(endpoint.targetName, endpoint.propertyKey, err);\n }\n}\n","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 {ConverterService} from \"./ConverterService\";\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 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 * 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 = this.injector.get<ConverterService>(ConverterService)!.serialize(data, {\n ...endpoint.getResponseOptions(response.statusCode),\n endpoint: true\n });\n }\n }\n\n return data;\n }\n}\n"],"names":["ResponseFiltersContainer","Map","registerResponseFilter","type","token","set","ResponseFilter","contentTypes","target","forEach","contentType","registerProvider","provide","useClass","TemplateRenderError","InternalServerError","constructor","method","err","buildMessage","nameOf","String","ANY_CONTENT_TYPE","getContentType","data","ctx","endpoint","response","operation","getContentTypeOf","statusCode","isObject","view","ConverterService","injectorService","configuration","_additionalProperties","get","serialize","obj","options","useAlias","additionalProperties","deserialize","Injectable","__param","Configuration","InjectorService","renderView","$ctx","path","render","targetName","propertyKey","PlatformResponseFilter","types","keys","$onInit","responseFilters","includes","injector","getBestContentType","request","bestContentType","accepts","concat","filter","Boolean","transform","has","isSerializable","getResponseOptions","__decorate","Inject","Constant"],"mappings":";;;;;;AAMA;;;AAGA;MACaA,wBAAwB,GAAG,IAAIC,GAAJ;AACxC;;;;SAGgBC,uBAAuBC,MAAyBC;AAC9DJ,EAAAA,wBAAwB,CAACK,GAAzB,CAA6BF,IAA7B,EAAmCC,KAAnC;AACD;;ACZD;;;;;;SAKgBE,eAAe,GAAGC;AAChC,SAAiBC,MAAV;AACLD,IAAAA,YAAY,CAACE,OAAb,CAAsBC,WAAD;AACnBR,MAAAA,sBAAsB,CAACQ,WAAD,EAAcF,MAAd,CAAtB;AACD,KAFD;AAGAG,IAAAA,gBAAgB,CAAC;AACfC,MAAAA,OAAO,EAAEJ,MADM;AAEfK,MAAAA,QAAQ,EAAGL;AAFI,KAAD,CAAhB;AAID,GARD;AASD;;AChBD;;;;MAGaM,4BAA4BC;AAGvCC,EAAAA,YAAYR,QAA4BS,QAAyBC;AAC/D,UAAMJ,mBAAmB,CAACK,YAApB,CAAiCX,MAAjC,EAAyCS,MAAzC,EAAiDC,GAAjD,CAAN;AAHF,aAAA,GAAO,uBAAP;AAIC;AAED;;;;;;AAImB,SAAZC,YAAY,CAACX,MAAD,EAA6BS,MAA7B,EAAsDC,GAAtD;AACjB,wCAAoCE,MAAM,CAACZ,MAAD,KAAYa,MAAM,CAACJ,MAAD,OAArD,GAAsEC,GAA7E;AACD;;;;;;;;;;;;;;;;;;;;;;MCjBUI,gBAAgB,GAAG;AAChC;;;;SAGgBC,eAAeC,MAAWC;AACxC,QAAM;AAACC,IAAAA,QAAD;AAAWC,IAAAA;AAAX,MAAuBF,GAA7B;AACA,QAAM;AAACG,IAAAA;AAAD,MAAcF,QAApB;AAEA,QAAMhB,WAAW,GAAGiB,QAAQ,CAACJ,cAAT,MAA6BK,SAAS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AAcvB,GAAd,CAAoCJ,gBAApC,EAAuDK,SAAvD,CAAiEd,IAAjE,eACFE,QAAQ,CAAC6C,kBAAT,CAA4B5C,QAAQ,CAACG,UAArC,CADE;AAELJ,UAAAA,QAAQ,EAAE;AAFL,WAAP;AAID;AACF;;AAED,WAAOF,IAAP;AACD;;;;AAvEDgD,YADCC,MAAM,8BACG1B,wEAAV;;AAGAyB,YADCE,QAAQ,CAAC,iBAAD,EAAoB,EAApB,kGACT;;AAPWpB,sBAAsB,eADlCV,UAAU,KACEU,uBAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-response-filter",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.88.0",
|
|
4
4
|
"description": "Platform response filter module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -17,20 +17,20 @@
|
|
|
17
17
|
"tslib": "2.2.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@tsed/core": "6.
|
|
21
|
-
"@tsed/di": "6.
|
|
22
|
-
"@tsed/exceptions": "6.
|
|
23
|
-
"@tsed/json-mapper": "6.
|
|
24
|
-
"@tsed/platform-views": "6.
|
|
25
|
-
"@tsed/schema": "6.
|
|
20
|
+
"@tsed/core": "6.88.0",
|
|
21
|
+
"@tsed/di": "6.88.0",
|
|
22
|
+
"@tsed/exceptions": "6.88.0",
|
|
23
|
+
"@tsed/json-mapper": "6.88.0",
|
|
24
|
+
"@tsed/platform-views": "6.88.0",
|
|
25
|
+
"@tsed/schema": "6.88.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@tsed/core": "^6.
|
|
29
|
-
"@tsed/di": "^6.
|
|
30
|
-
"@tsed/exceptions": "^6.
|
|
31
|
-
"@tsed/json-mapper": "^6.
|
|
32
|
-
"@tsed/platform-views": "^6.
|
|
33
|
-
"@tsed/schema": "^6.
|
|
28
|
+
"@tsed/core": "^6.88.0",
|
|
29
|
+
"@tsed/di": "^6.88.0",
|
|
30
|
+
"@tsed/exceptions": "^6.88.0",
|
|
31
|
+
"@tsed/json-mapper": "^6.88.0",
|
|
32
|
+
"@tsed/platform-views": "^6.88.0",
|
|
33
|
+
"@tsed/schema": "^6.88.0"
|
|
34
34
|
},
|
|
35
35
|
"repository": "https://github.com/tsedio/tsed",
|
|
36
36
|
"bugs": {
|