@tsed/platform-response-filter 6.107.5 → 6.108.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/cjs/index.js CHANGED
@@ -4,12 +4,12 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const tslib_1 = require("tslib");
7
- (0, tslib_1.__exportStar)(require("./decorators/responseFilter"), exports);
8
- (0, tslib_1.__exportStar)(require("./domain/ResponseFiltersContainer"), exports);
9
- (0, tslib_1.__exportStar)(require("./errors/TemplateRenderError"), exports);
10
- (0, tslib_1.__exportStar)(require("./interfaces/ResponseFilterMethods"), exports);
11
- (0, tslib_1.__exportStar)(require("./services/ConverterService"), exports);
12
- (0, tslib_1.__exportStar)(require("./services/PlatformResponseFilter"), exports);
13
- (0, tslib_1.__exportStar)(require("./utils/getContentType"), exports);
14
- (0, tslib_1.__exportStar)(require("./utils/renderView"), exports);
7
+ tslib_1.__exportStar(require("./decorators/responseFilter"), exports);
8
+ tslib_1.__exportStar(require("./domain/ResponseFiltersContainer"), exports);
9
+ tslib_1.__exportStar(require("./errors/TemplateRenderError"), exports);
10
+ tslib_1.__exportStar(require("./interfaces/ResponseFilterMethods"), exports);
11
+ tslib_1.__exportStar(require("./services/ConverterService"), exports);
12
+ tslib_1.__exportStar(require("./services/PlatformResponseFilter"), exports);
13
+ tslib_1.__exportStar(require("./utils/getContentType"), exports);
14
+ tslib_1.__exportStar(require("./utils/renderView"), exports);
15
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2EAA4C;AAC5C,iFAAkD;AAClD,4EAA6C;AAC7C,kFAAmD;AACnD,2EAA4C;AAC5C,iFAAkD;AAClD,sEAAuC;AACvC,kEAAmC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./decorators/responseFilter\";\nexport * from \"./domain/ResponseFiltersContainer\";\nexport * from \"./errors/TemplateRenderError\";\nexport * from \"./interfaces/ResponseFilterMethods\";\nexport * from \"./services/ConverterService\";\nexport * from \"./services/PlatformResponseFilter\";\nexport * from \"./utils/getContentType\";\nexport * from \"./utils/renderView\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,sEAA4C;AAC5C,4EAAkD;AAClD,uEAA6C;AAC7C,6EAAmD;AACnD,sEAA4C;AAC5C,4EAAkD;AAClD,iEAAuC;AACvC,6DAAmC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./decorators/responseFilter\";\nexport * from \"./domain/ResponseFiltersContainer\";\nexport * from \"./errors/TemplateRenderError\";\nexport * from \"./interfaces/ResponseFilterMethods\";\nexport * from \"./services/ConverterService\";\nexport * from \"./services/PlatformResponseFilter\";\nexport * from \"./utils/getContentType\";\nexport * from \"./utils/renderView\";\n"]}
@@ -45,10 +45,10 @@ let ConverterService = class ConverterService {
45
45
  });
46
46
  }
47
47
  };
48
- ConverterService = (0, tslib_1.__decorate)([
48
+ ConverterService = tslib_1.__decorate([
49
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])
50
+ tslib_1.__param(1, (0, di_1.Configuration)()),
51
+ tslib_1.__metadata("design:paramtypes", [di_1.InjectorService, Object])
52
52
  ], ConverterService);
53
53
  exports.ConverterService = ConverterService;
54
54
  //# sourceMappingURL=ConverterService.js.map
@@ -1 +1 @@
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
+ {"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,mBAAA,IAAA,kBAAa,GAAE,CAAA;6CAAjC,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"]}
@@ -73,15 +73,15 @@ let PlatformResponseFilter = class PlatformResponseFilter {
73
73
  return data;
74
74
  }
75
75
  };
76
- (0, tslib_1.__decorate)([
76
+ tslib_1.__decorate([
77
77
  (0, di_1.Inject)(),
78
- (0, tslib_1.__metadata)("design:type", di_1.InjectorService)
78
+ tslib_1.__metadata("design:type", di_1.InjectorService)
79
79
  ], PlatformResponseFilter.prototype, "injector", void 0);
80
- (0, tslib_1.__decorate)([
80
+ tslib_1.__decorate([
81
81
  (0, di_1.Constant)("responseFilters", []),
82
- (0, tslib_1.__metadata)("design:type", Array)
82
+ tslib_1.__metadata("design:type", Array)
83
83
  ], PlatformResponseFilter.prototype, "responseFilters", void 0);
84
- PlatformResponseFilter = (0, tslib_1.__decorate)([
84
+ PlatformResponseFilter = tslib_1.__decorate([
85
85
  (0, di_1.Injectable)()
86
86
  ], PlatformResponseFilter);
87
87
  exports.PlatformResponseFilter = 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,yDAAoD;AACpD,oDAA+C;AAE/C;;GAEG;AAEH,IAAa,sBAAsB,GAAnC,MAAa,sBAAsB;IAAnC;QACE,UAAK,GAAkD,IAAI,GAAG,EAAE,CAAC;IA2EnE,CAAC;IAnEC,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;QAC5C,MAAM,WAAW,GAAG,IAAA,+BAAc,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAE9C,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YAC7B,MAAM,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;YAErG,IAAI,eAAe,EAAE;gBACnB,OAAO,EAAE,CAAC,MAAM,CAAC,eAAsB,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,K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CAAC;oBACnD,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAC;aACJ;SACF;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAxEC;IADC,IAAA,WAAM,GAAE;2CACC,oBAAe;wDAAC;AAG1B;IADC,IAAA,aAAQ,EAAC,iBAAiB,EAAE,EAAE,CAAC;;+DACyB;AAP9C,sBAAsB;IADlC,IAAA,eAAU,GAAE;GACA,sBAAsB,CA4ElC;AA5EY,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 {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"]}
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,yDAAoD;AACpD,oDAA+C;AAE/C;;GAEG;AAEH,IAAa,sBAAsB,GAAnC,MAAa,sBAAsB;IAAnC;QACE,UAAK,GAAkD,IAAI,GAAG,EAAE,CAAC;IA2EnE,CAAC;IAnEC,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;QAC5C,MAAM,WAAW,GAAG,IAAA,+BAAc,EAAC,IAAI,EAAE,GA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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,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAmB,mCAAgB,CAAE,CAAC,SAAS,CAAC,IAAI,EAAE;oBAC5E,GAAG,QAAQ,CAAC,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC;oBACnD,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAC;aACJ;SACF;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAxEC;IADC,IAAA,WAAM,GAAE;sCACC,oBAAe;wDAAC;AAG1B;IADC,IAAA,aAAQ,EAAC,iBAAiB,EAAE,EAAE,CAAC;;+DACyB;AAP9C,sBAAsB;IADlC,IAAA,eAAU,GAAE;GACA,sBAAsB,CA4ElC;AA5EY,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 {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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/platform-response-filter",
3
- "version": "6.107.5",
3
+ "version": "6.108.0",
4
4
  "description": "Platform response filter module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -20,21 +20,38 @@
20
20
  "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\""
21
21
  },
22
22
  "dependencies": {
23
- "tslib": "2.2.0"
23
+ "tslib": "2.3.1"
24
24
  },
25
25
  "devDependencies": {
26
- "@tsed/core": "6.107.5",
27
- "@tsed/di": "6.107.5",
28
- "@tsed/exceptions": "6.107.5",
29
- "@tsed/json-mapper": "6.107.5",
30
- "@tsed/schema": "6.107.5"
26
+ "@tsed/core": "6.108.0",
27
+ "@tsed/di": "6.108.0",
28
+ "@tsed/exceptions": "6.108.0",
29
+ "@tsed/json-mapper": "6.108.0",
30
+ "@tsed/schema": "6.108.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "@tsed/core": "^6.107.5",
34
- "@tsed/di": "^6.107.5",
35
- "@tsed/exceptions": "^6.107.5",
36
- "@tsed/json-mapper": "^6.107.5",
37
- "@tsed/schema": "^6.107.5"
33
+ "@tsed/core": "^6.108.0",
34
+ "@tsed/di": "^6.108.0",
35
+ "@tsed/exceptions": "^6.108.0",
36
+ "@tsed/json-mapper": "^6.108.0",
37
+ "@tsed/schema": "^6.108.0"
38
+ },
39
+ "peerDependenciesMeta": {
40
+ "@tsed/core": {
41
+ "optional": false
42
+ },
43
+ "@tsed/di": {
44
+ "optional": false
45
+ },
46
+ "@tsed/exceptions": {
47
+ "optional": false
48
+ },
49
+ "@tsed/json-mapper": {
50
+ "optional": false
51
+ },
52
+ "@tsed/schema": {
53
+ "optional": false
54
+ }
38
55
  },
39
56
  "repository": "https://github.com/tsedio/tsed",
40
57
  "bugs": {