@tsed/platform-params 6.114.15 → 6.114.18

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.
Files changed (30) hide show
  1. package/jest.config.js +14 -0
  2. package/lib/cjs/builder/PlatformParams.js +1 -0
  3. package/lib/cjs/builder/PlatformParams.js.map +1 -1
  4. package/lib/cjs/decorators/useParamType.js +1 -2
  5. package/lib/cjs/decorators/useParamType.js.map +1 -1
  6. package/lib/cjs/errors/ParamValidationError.js +3 -4
  7. package/lib/cjs/errors/ParamValidationError.js.map +1 -1
  8. package/lib/cjs/errors/RequiredValidationError.js +1 -4
  9. package/lib/cjs/errors/RequiredValidationError.js.map +1 -1
  10. package/lib/cjs/errors/ValidationError.js +2 -1
  11. package/lib/cjs/errors/ValidationError.js.map +1 -1
  12. package/lib/cjs/pipes/DeserializerPipe.js +1 -0
  13. package/lib/cjs/pipes/DeserializerPipe.js.map +1 -1
  14. package/lib/cjs/pipes/ValidationPipe.js +1 -0
  15. package/lib/cjs/pipes/ValidationPipe.js.map +1 -1
  16. package/lib/esm/builder/PlatformParams.js +1 -0
  17. package/lib/esm/builder/PlatformParams.js.map +1 -1
  18. package/lib/esm/decorators/useParamType.js +1 -2
  19. package/lib/esm/decorators/useParamType.js.map +1 -1
  20. package/lib/esm/errors/ParamValidationError.js +3 -4
  21. package/lib/esm/errors/ParamValidationError.js.map +1 -1
  22. package/lib/esm/errors/RequiredValidationError.js +1 -4
  23. package/lib/esm/errors/RequiredValidationError.js.map +1 -1
  24. package/lib/esm/errors/ValidationError.js +2 -1
  25. package/lib/esm/errors/ValidationError.js.map +1 -1
  26. package/lib/esm/pipes/DeserializerPipe.js +1 -0
  27. package/lib/esm/pipes/DeserializerPipe.js.map +1 -1
  28. package/lib/esm/pipes/ValidationPipe.js +1 -0
  29. package/lib/esm/pipes/ValidationPipe.js.map +1 -1
  30. package/package.json +14 -13
package/jest.config.js ADDED
@@ -0,0 +1,14 @@
1
+ // For a detailed explanation regarding each configuration property, visit:
2
+ // https://jestjs.io/docs/en/configuration.html
3
+
4
+ module.exports = {
5
+ ...require("@tsed/jest-config")(__dirname, "platform-params"),
6
+ coverageThreshold: {
7
+ global: {
8
+ statements: 89.92,
9
+ branches: 73.78,
10
+ functions: 73.83,
11
+ lines: 89.47
12
+ }
13
+ }
14
+ };
@@ -11,6 +11,7 @@ const ParseExpressionPipe_1 = require("../pipes/ParseExpressionPipe");
11
11
  * @platform
12
12
  */
13
13
  let PlatformParams = class PlatformParams {
14
+ injector;
14
15
  async getPipes(param) {
15
16
  const get = (pipe) => {
16
17
  return this.injector.getProvider(pipe).priority || 0;
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformParams.js","sourceRoot":"","sources":["../../../src/builder/PlatformParams.ts"],"names":[],"mappings":";;;;AAAA,iCAAsG;AACtG,yCAA8E;AAC9E,yEAAoE;AACpE,sEAAiE;AAWjE;;;GAGG;AAKH,IAAa,cAAc,GAA3B,MAAa,cAAc;IAIzB,KAAK,CAAC,QAAQ,CAAC,KAAyB;QACtC,MAAM,GAAG,GAAG,CAAC,IAAmB,EAAE,EAAE;YAClC,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAE,CAAC,QAAQ,IAAI,CAAC,CAAC;QACxD,CAAC,CAAC;QAEF,MAAM,IAAI,GAAG,CAAC,EAAiB,EAAE,EAAiB,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5G,MAAM,GAAG,GAAG,CAAC,KAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAc,KAAK,CAAE,CAAC;QAChF,MAAM,QAAQ,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I,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACnE,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AAvEC;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;gDAAC;AAFzB,cAAc;IAJ1B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,EAAE;KACZ,CAAC;GACW,cAAc,CAyE1B;AAzEY,wCAAc","sourcesContent":["import {DIContext, Inject, Injectable, InjectorService, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport {JsonEntityStore, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {ParamValidationError} from \"../errors/ParamValidationError\";\nimport {ParseExpressionPipe} from \"../pipes/ParseExpressionPipe\";\n\nexport type ArgScope<Context extends DIContext = DIContext> = {$ctx: Context} & Record<string, any>;\nexport type HandlerWithScope<Context extends DIContext = DIContext> = (scope: ArgScope<Context>) => any;\n\nexport interface CompileHandlerOptions<Context extends DIContext = DIContext> extends Record<any, unknown> {\n token: TokenProvider;\n propertyKey: string | symbol;\n getCustomArgs?: (scope: ArgScope<Context>) => Promise<any[]>;\n}\n\n/**\n * Platform Params abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: []\n})\nexport class PlatformParams {\n @Inject()\n protected injector: InjectorService;\n\n async getPipes(param: JsonParameterStore) {\n const get = (pipe: TokenProvider) => {\n return this.injector.getProvider(pipe)!.priority || 0;\n };\n\n const sort = (p1: TokenProvider, p2: TokenProvider) => (get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0);\n const map = (token: TokenProvider) => this.injector.invoke<PipeMethods>(token)!;\n const promises = await Promise.all([ParseExpressionPipe, ...param.pipes.sort(sort)].map(map));\n\n return promises.filter(Boolean);\n }\n\n async compile<Context extends DIContext = DIContext>(entity: JsonEntityStore) {\n const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);\n\n const argsPipes = await Promise.all(\n params.map(async (param) => {\n return {\n param,\n pipes: await this.getPipes(param)\n };\n })\n );\n\n return (scope: ArgScope<Context>) => {\n const promises = argsPipes.map(({param, pipes}) => {\n return this.getArg(scope, pipes, param);\n });\n\n return Promise.all(promises);\n };\n }\n\n async getArg(scope: ArgScope, pipes: PipeMethods[], param: JsonParameterStore) {\n return pipes.reduce(async (value, pipe) => {\n value = await value;\n\n try {\n return await pipe.transform(value, param);\n } catch (er) {\n throw ParamValidationError.from(param, er);\n }\n }, scope as any);\n }\n\n async compileHandler<Context extends DIContext = DIContext>(\n metadata: CompileHandlerOptions<Context>\n ): Promise<HandlerWithScope<Context>> {\n const {token, propertyKey, getCustomArgs} = metadata;\n\n const provider = this.injector.getProvider(token);\n const getArguments = getCustomArgs || (await this.compile<Context>(JsonEntityStore.fromMethod(token, propertyKey!)));\n\n if (!provider || !provider.scope || provider.scope === ProviderScope.SINGLETON) {\n const instance = await this.injector.invoke<any>(token);\n\n return async (scope) => {\n const args = await getArguments(scope);\n\n return instance[propertyKey!].call(instance, ...args, scope.$ctx);\n };\n }\n\n return async (scope) => {\n const [instance, args] = await Promise.all([this.injector.invoke<any>(token, scope.$ctx.container), getArguments(scope)]);\n\n return instance[propertyKey].call(instance, ...args, scope.$ctx);\n };\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformParams.js","sourceRoot":"","sources":["../../../src/builder/PlatformParams.ts"],"names":[],"mappings":";;;;AAAA,iCAAsG;AACtG,yCAA8E;AAC9E,yEAAoE;AACpE,sEAAiE;AAWjE;;;GAGG;AAKH,IAAa,cAAc,GAA3B,MAAa,cAAc;IAEf,QAAQ,CAAkB;IAEpC,KAAK,CAAC,QAAQ,CAAC,KAAyB;QACtC,MAAM,GAAG,GAAG,CAAC,IAAmB,EAAE,EAAE;YAClC,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAE,CAAC,QAAQ,IAAI,CAAC,CAAC;QACxD,CAAC,CAAC;QAEF,MAAM,IAAI,GAAG,CAAC,EAAiB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CAAC,IAAI,CAAC,CAAC;YACpE,CAAC,CAAC;SACH;QAED,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE;YACrB,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAM,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAE1H,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACnE,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AAvEC;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;gDAAC;AAFzB,cAAc;IAJ1B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,EAAE;KACZ,CAAC;GACW,cAAc,CAyE1B;AAzEY,wCAAc","sourcesContent":["import {DIContext, Inject, Injectable, InjectorService, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport {JsonEntityStore, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {ParamValidationError} from \"../errors/ParamValidationError\";\nimport {ParseExpressionPipe} from \"../pipes/ParseExpressionPipe\";\n\nexport type ArgScope<Context extends DIContext = DIContext> = {$ctx: Context} & Record<string, any>;\nexport type HandlerWithScope<Context extends DIContext = DIContext> = (scope: ArgScope<Context>) => any;\n\nexport interface CompileHandlerOptions<Context extends DIContext = DIContext> extends Record<any, unknown> {\n token: TokenProvider;\n propertyKey: string | symbol;\n getCustomArgs?: (scope: ArgScope<Context>) => Promise<any[]>;\n}\n\n/**\n * Platform Params abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: []\n})\nexport class PlatformParams {\n @Inject()\n protected injector: InjectorService;\n\n async getPipes(param: JsonParameterStore) {\n const get = (pipe: TokenProvider) => {\n return this.injector.getProvider(pipe)!.priority || 0;\n };\n\n const sort = (p1: TokenProvider, p2: TokenProvider) => (get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0);\n const map = (token: TokenProvider) => this.injector.invoke<PipeMethods>(token)!;\n const promises = await Promise.all([ParseExpressionPipe, ...param.pipes.sort(sort)].map(map));\n\n return promises.filter(Boolean);\n }\n\n async compile<Context extends DIContext = DIContext>(entity: JsonEntityStore) {\n const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);\n\n const argsPipes = await Promise.all(\n params.map(async (param) => {\n return {\n param,\n pipes: await this.getPipes(param)\n };\n })\n );\n\n return (scope: ArgScope<Context>) => {\n const promises = argsPipes.map(({param, pipes}) => {\n return this.getArg(scope, pipes, param);\n });\n\n return Promise.all(promises);\n };\n }\n\n async getArg(scope: ArgScope, pipes: PipeMethods[], param: JsonParameterStore) {\n return pipes.reduce(async (value, pipe) => {\n value = await value;\n\n try {\n return await pipe.transform(value, param);\n } catch (er) {\n throw ParamValidationError.from(param, er);\n }\n }, scope as any);\n }\n\n async compileHandler<Context extends DIContext = DIContext>(\n metadata: CompileHandlerOptions<Context>\n ): Promise<HandlerWithScope<Context>> {\n const {token, propertyKey, getCustomArgs} = metadata;\n\n const provider = this.injector.getProvider(token);\n const getArguments = getCustomArgs || (await this.compile<Context>(JsonEntityStore.fromMethod(token, propertyKey!)));\n\n if (!provider || !provider.scope || provider.scope === ProviderScope.SINGLETON) {\n const instance = await this.injector.invoke<any>(token);\n\n return async (scope) => {\n const args = await getArguments(scope);\n\n return instance[propertyKey!].call(instance, ...args, scope.$ctx);\n };\n }\n\n return async (scope) => {\n const [instance, args] = await Promise.all([this.injector.invoke<any>(token, scope.$ctx.container), getArguments(scope)]);\n\n return instance[propertyKey].call(instance, ...args, scope.$ctx);\n };\n }\n}\n"]}
@@ -16,14 +16,13 @@ const ParamTypes_1 = require("../domain/ParamTypes");
16
16
  */
17
17
  function UseParamType(options) {
18
18
  return (0, core_1.useDecorators)((0, paramFn_1.ParamFn)((param) => {
19
- var _a;
20
19
  if ((0, schema_1.isParameterType)(options.paramType)) {
21
20
  param.parameter.in(options.paramType);
22
21
  }
23
22
  param.paramType = options.paramType;
24
23
  if ((0, core_1.isBuffer)(param.type) || (0, core_1.isBuffer)(options.useType) || options.paramType === ParamTypes_1.ParamTypes.RAW_BODY) {
25
24
  param.paramType = ParamTypes_1.ParamTypes.RAW_BODY;
26
- (_a = param.parent.operation) === null || _a === void 0 ? void 0 : _a.consumes(["*/*"]);
25
+ param.parent.operation?.consumes(["*/*"]);
27
26
  }
28
27
  param.dataPath = options.dataPath || ParamTypes_1.PARAM_TYPES_DATA_PATH[param.paramType] || "$ctx";
29
28
  }), options.expression && (0, useParamExpression_1.UseParamExpression)(options.expression), options.expression && (0, schema_1.Name)(options.expression));
@@ -1 +1 @@
1
- {"version":3,"file":"useParamType.js","sourceRoot":"","sources":["../../../src/decorators/useParamType.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AACnD,yCAAmD;AACnD,uCAAkC;AAElC,6DAAwD;AACxD,qDAAuE;AAEvE;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAC,OAAqB;IAChD,OAAO,IAAA,oBAAa,EAClB,IAAA,iBAAO,EAAC,CAAC,KAAK,EAAE,EAAE;;QAChB,IAAI,IAAA,wBAAe,EAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YACtC,KAAK,CAAC,SAAU,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;SACxC;QAED,KAAK,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QAEpC,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,IAAI,CAAC,IAAI,IAAA,eAAQ,EAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,SAAS,KAAK,uBAAU,CAAC,QAAQ,EAAE;YAClG,KAAK,CAAC,SAAS,GAAG,uBAAU,CAAC,QAAQ,CAAC;YACtC,MAAA,KAAK,CAAC,MAAM,CAAC,SAAS,0CAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;SAC3C;QAED,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,kCAAqB,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC;IACxF,CAAC,CAAC,EACF,OAAO,CAAC,UAAU,IAAI,IAAA,uCAAkB,EAAC,OAAO,CAAC,UAAU,CAAC,EAC5D,OAAO,CAAC,UAAU,IAAI,IAAA,aAAI,EAAC,OAAO,CAAC,UAAU,CAAC,CAC/C,CAAC;AACJ,CAAC;AAnBD,oCAmBC","sourcesContent":["import {isBuffer, useDecorators} from \"@tsed/core\";\nimport {isParameterType, Name} from \"@tsed/schema\";\nimport {ParamFn} from \"./paramFn\";\nimport {ParamOptions} from \"../domain/ParamOptions\";\nimport {UseParamExpression} from \"./useParamExpression\";\nimport {PARAM_TYPES_DATA_PATH, ParamTypes} from \"../domain/ParamTypes\";\n\n/**\n * Get the object from request (like body, params, query, etc...).\n *\n * @decorator\n * @operation\n * @input\n * @pipe\n */\nexport function UseParamType(options: ParamOptions) {\n return useDecorators(\n ParamFn((param) => {\n if (isParameterType(options.paramType)) {\n param.parameter!.in(options.paramType);\n }\n\n param.paramType = options.paramType;\n\n if (isBuffer(param.type) || isBuffer(options.useType) || options.paramType === ParamTypes.RAW_BODY) {\n param.paramType = ParamTypes.RAW_BODY;\n param.parent.operation?.consumes([\"*/*\"]);\n }\n\n param.dataPath = options.dataPath || PARAM_TYPES_DATA_PATH[param.paramType] || \"$ctx\";\n }),\n options.expression && UseParamExpression(options.expression),\n options.expression && Name(options.expression)\n );\n}\n"]}
1
+ {"version":3,"file":"useParamType.js","sourceRoot":"","sources":["../../../src/decorators/useParamType.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AACnD,yCAAmD;AACnD,uCAAkC;AAElC,6DAAwD;AACxD,qDAAuE;AAEvE;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAC,OAAqB;IAChD,OAAO,IAAA,oBAAa,EAClB,IAAA,iBAAO,EAAC,CAAC,KAAK,EAAE,EAAE;QAChB,IAAI,IAAA,wBAAe,EAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YACtC,KAAK,CAAC,SAAU,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;SACxC;QAED,KAAK,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QAEpC,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,IAAI,CAAC,IAAI,IAAA,eAAQ,EAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,SAAS,KAAK,uBAAU,CAAC,QAAQ,EAAE;YAClG,KAAK,CAAC,SAAS,GAAG,uBAAU,CAAC,QAAQ,CAAC;YACtC,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;SAC3C;QAED,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,kCAAqB,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC;IACxF,CAAC,CAAC,EACF,OAAO,CAAC,UAAU,IAAI,IAAA,uCAAkB,EAAC,OAAO,CAAC,UAAU,CAAC,EAC5D,OAAO,CAAC,UAAU,IAAI,IAAA,aAAI,EAAC,OAAO,CAAC,UAAU,CAAC,CAC/C,CAAC;AACJ,CAAC;AAnBD,oCAmBC","sourcesContent":["import {isBuffer, useDecorators} from \"@tsed/core\";\nimport {isParameterType, Name} from \"@tsed/schema\";\nimport {ParamFn} from \"./paramFn\";\nimport {ParamOptions} from \"../domain/ParamOptions\";\nimport {UseParamExpression} from \"./useParamExpression\";\nimport {PARAM_TYPES_DATA_PATH, ParamTypes} from \"../domain/ParamTypes\";\n\n/**\n * Get the object from request (like body, params, query, etc...).\n *\n * @decorator\n * @operation\n * @input\n * @pipe\n */\nexport function UseParamType(options: ParamOptions) {\n return useDecorators(\n ParamFn((param) => {\n if (isParameterType(options.paramType)) {\n param.parameter!.in(options.paramType);\n }\n\n param.paramType = options.paramType;\n\n if (isBuffer(param.type) || isBuffer(options.useType) || options.paramType === ParamTypes.RAW_BODY) {\n param.paramType = ParamTypes.RAW_BODY;\n param.parent.operation?.consumes([\"*/*\"]);\n }\n\n param.dataPath = options.dataPath || PARAM_TYPES_DATA_PATH[param.paramType] || \"$ctx\";\n }),\n options.expression && UseParamExpression(options.expression),\n options.expression && Name(options.expression)\n );\n}\n"]}
@@ -5,10 +5,9 @@ const core_1 = require("@tsed/core");
5
5
  const exceptions_1 = require("@tsed/exceptions");
6
6
  const ValidationError_1 = require("./ValidationError");
7
7
  class ParamValidationError extends exceptions_1.BadRequest {
8
- constructor() {
9
- super(...arguments);
10
- this.name = "PARAM_VALIDATION_ERROR";
11
- }
8
+ name = "PARAM_VALIDATION_ERROR";
9
+ dataPath;
10
+ requestType;
12
11
  static from(metadata, origin = {}) {
13
12
  if (origin instanceof ValidationError_1.ValidationError || origin instanceof exceptions_1.BadRequest) {
14
13
  const name = (0, core_1.nameOf)(metadata.paramType)
@@ -1 +1 @@
1
- {"version":3,"file":"ParamValidationError.js","sourceRoot":"","sources":["../../../src/errors/ParamValidationError.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAClC,iDAA4C;AAE5C,uDAAkD;AAElD,MAAa,oBAAqB,SAAQ,uBAAU;IAApD;;QACS,SAAI,GAAW,wBAAwB,CAAC;IAsBjD,CAAC;IAlBC,MAAM,CAAC,IAAI,CAAC,QAA4B,EAAE,SAAc,EAAE;QACxD,IAAI,MAAM,YAAY,iCAAe,IAAI,MAAM,YAAY,uBAAU,EAAE;YACrE,MAAM,IAAI,GAAG,IAAA,aAAM,EAAC,QAAQ,CAAC,SAAS,CAAC;iBACpC,WAAW,EAAE;iBACb,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;YACxC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;YACvC,MAAM,OAAO,GAAG,qCAAqC,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC;YAE7H,MAAM,KAAK,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAC;YAChD,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YACnD,KAAK,CAAC,WAAW,GAAG,IAAA,aAAM,EAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;YAC/C,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC;YAEvC,OAAO,KAAK,CAAC;SACd;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAvBD,oDAuBC","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {BadRequest} from \"@tsed/exceptions\";\nimport {JsonParameterStore} from \"@tsed/schema\";\nimport {ValidationError} from \"./ValidationError\";\n\nexport class ParamValidationError extends BadRequest {\n public name: string = \"PARAM_VALIDATION_ERROR\";\n public dataPath: string;\n public requestType: string;\n\n static from(metadata: JsonParameterStore, origin: any = {}) {\n if (origin instanceof ValidationError || origin instanceof BadRequest) {\n const name = nameOf(metadata.paramType)\n .toLowerCase()\n .replace(/parse|params|filter/gi, \"\");\n const expression = metadata.expression;\n const message = `Bad request on parameter \"request.${name}${expression ? \".\" + expression : \"\"}\".\\n${origin.message}`.trim();\n\n const error = new ParamValidationError(message);\n error.dataPath = String(metadata.expression) || \"\";\n error.requestType = nameOf(metadata.paramType);\n error.origin = origin.origin || origin;\n\n return error;\n }\n\n return origin;\n }\n}\n"]}
1
+ {"version":3,"file":"ParamValidationError.js","sourceRoot":"","sources":["../../../src/errors/ParamValidationError.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAClC,iDAA4C;AAE5C,uDAAkD;AAElD,MAAa,oBAAqB,SAAQ,uBAAU;IAC3C,IAAI,GAAW,wBAAwB,CAAC;IACxC,QAAQ,CAAS;IACjB,WAAW,CAAS;IAE3B,MAAM,CAAC,IAAI,CAAC,QAA4B,EAAE,SAAc,EAAE;QACxD,IAAI,MAAM,YAAY,iCAAe,IAAI,MAAM,YAAY,uBAAU,EAAE;YACrE,MAAM,IAAI,GAAG,IAAA,aAAM,EAAC,QAAQ,CAAC,SAAS,CAAC;iBACpC,WAAW,EAAE;iBACb,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;YACxC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;YACvC,MAAM,OAAO,GAAG,qCAAqC,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC;YAE7H,MAAM,KAAK,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAC;YAChD,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YACnD,KAAK,CAAC,WAAW,GAAG,IAAA,aAAM,EAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;YAC/C,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC;YAEvC,OAAO,KAAK,CAAC;SACd;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAvBD,oDAuBC","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {BadRequest} from \"@tsed/exceptions\";\nimport {JsonParameterStore} from \"@tsed/schema\";\nimport {ValidationError} from \"./ValidationError\";\n\nexport class ParamValidationError extends BadRequest {\n public name: string = \"PARAM_VALIDATION_ERROR\";\n public dataPath: string;\n public requestType: string;\n\n static from(metadata: JsonParameterStore, origin: any = {}) {\n if (origin instanceof ValidationError || origin instanceof BadRequest) {\n const name = nameOf(metadata.paramType)\n .toLowerCase()\n .replace(/parse|params|filter/gi, \"\");\n const expression = metadata.expression;\n const message = `Bad request on parameter \"request.${name}${expression ? \".\" + expression : \"\"}\".\\n${origin.message}`.trim();\n\n const error = new ParamValidationError(message);\n error.dataPath = String(metadata.expression) || \"\";\n error.requestType = nameOf(metadata.paramType);\n error.origin = origin.origin || origin;\n\n return error;\n }\n\n return origin;\n }\n}\n"]}
@@ -4,10 +4,7 @@ exports.RequiredValidationError = void 0;
4
4
  const core_1 = require("@tsed/core");
5
5
  const ValidationError_1 = require("./ValidationError");
6
6
  class RequiredValidationError extends ValidationError_1.ValidationError {
7
- constructor() {
8
- super(...arguments);
9
- this.name = "REQUIRED_VALIDATION_ERROR";
10
- }
7
+ name = "REQUIRED_VALIDATION_ERROR";
11
8
  static from(metadata) {
12
9
  const name = (0, core_1.nameOf)(metadata.paramType);
13
10
  const expression = metadata.expression;
@@ -1 +1 @@
1
- {"version":3,"file":"RequiredValidationError.js","sourceRoot":"","sources":["../../../src/errors/RequiredValidationError.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAClC,uDAAkD;AAGlD,MAAa,uBAAwB,SAAQ,iCAAe;IAA5D;;QACS,SAAI,GAAW,2BAA2B,CAAC;IAuBpD,CAAC;IArBC,MAAM,CAAC,IAAI,CAAC,QAA4B;QACtC,MAAM,IAAI,GAAG,IAAA,aAAM,EAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACxC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;QACvC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;QACrE,MAAM,OAAO,GAAG,sCAAsC,UAAU,GAAG,CAAC;QAEpE,MAAM,MAAM,GAAG;YACb;gBACE,QAAQ,EAAE,EAAE;gBACZ,OAAO,EAAE,UAAU;gBACnB,OAAO;gBACP,SAAS,EAAE,IAAI;gBACf,MAAM,EAAE;oBACN,eAAe,EAAE,UAAU;iBAC5B;gBACD,UAAU,EAAE,YAAY;aACzB;SACF,CAAC;QAEF,OAAO,IAAI,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACtD,CAAC;CACF;AAxBD,0DAwBC","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {ValidationError} from \"./ValidationError\";\nimport {JsonParameterStore} from \"@tsed/schema\";\n\nexport class RequiredValidationError extends ValidationError {\n public name: string = \"REQUIRED_VALIDATION_ERROR\";\n\n static from(metadata: JsonParameterStore) {\n const name = nameOf(metadata.paramType);\n const expression = metadata.expression;\n const type = name.toLowerCase().replace(/parse|params|filter/gi, \"\");\n const message = `It should have required parameter '${expression}'`;\n\n const errors = [\n {\n dataPath: \"\",\n keyword: \"required\",\n message,\n modelName: type,\n params: {\n missingProperty: expression\n },\n schemaPath: \"#/required\"\n }\n ];\n\n return new RequiredValidationError(message, errors);\n }\n}\n"]}
1
+ {"version":3,"file":"RequiredValidationError.js","sourceRoot":"","sources":["../../../src/errors/RequiredValidationError.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAClC,uDAAkD;AAGlD,MAAa,uBAAwB,SAAQ,iCAAe;IACnD,IAAI,GAAW,2BAA2B,CAAC;IAElD,MAAM,CAAC,IAAI,CAAC,QAA4B;QACtC,MAAM,IAAI,GAAG,IAAA,aAAM,EAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACxC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;QACvC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;QACrE,MAAM,OAAO,GAAG,sCAAsC,UAAU,GAAG,CAAC;QAEpE,MAAM,MAAM,GAAG;YACb;gBACE,QAAQ,EAAE,EAAE;gBACZ,OAAO,EAAE,UAAU;gBACnB,OAAO;gBACP,SAAS,EAAE,IAAI;gBACf,MAAM,EAAE;oBACN,eAAe,EAAE,UAAU;iBAC5B;gBACD,UAAU,EAAE,YAAY;aACzB;SACF,CAAC;QAEF,OAAO,IAAI,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACtD,CAAC;CACF;AAxBD,0DAwBC","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {ValidationError} from \"./ValidationError\";\nimport {JsonParameterStore} from \"@tsed/schema\";\n\nexport class RequiredValidationError extends ValidationError {\n public name: string = \"REQUIRED_VALIDATION_ERROR\";\n\n static from(metadata: JsonParameterStore) {\n const name = nameOf(metadata.paramType);\n const expression = metadata.expression;\n const type = name.toLowerCase().replace(/parse|params|filter/gi, \"\");\n const message = `It should have required parameter '${expression}'`;\n\n const errors = [\n {\n dataPath: \"\",\n keyword: \"required\",\n message,\n modelName: type,\n params: {\n missingProperty: expression\n },\n schemaPath: \"#/required\"\n }\n ];\n\n return new RequiredValidationError(message, errors);\n }\n}\n"]}
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ValidationError = void 0;
4
4
  const exceptions_1 = require("@tsed/exceptions");
5
5
  class ValidationError extends exceptions_1.BadRequest {
6
+ name = "VALIDATION_ERROR";
7
+ errors;
6
8
  constructor(message, errors = []) {
7
9
  super(message);
8
- this.name = "VALIDATION_ERROR";
9
10
  this.errors = errors;
10
11
  }
11
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ValidationError.js","sourceRoot":"","sources":["../../../src/errors/ValidationError.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAE5C,MAAa,eAAgB,SAAQ,uBAAU;IAI7C,YAAY,OAAe,EAAE,SAAgB,EAAE;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QAJV,SAAI,GAAW,kBAAkB,CAAC;QAKvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AARD,0CAQC","sourcesContent":["import {BadRequest} from \"@tsed/exceptions\";\n\nexport class ValidationError extends BadRequest {\n public name: string = \"VALIDATION_ERROR\";\n public errors: any[];\n\n constructor(message: string, errors: any[] = []) {\n super(message);\n this.errors = errors;\n }\n}\n"]}
1
+ {"version":3,"file":"ValidationError.js","sourceRoot":"","sources":["../../../src/errors/ValidationError.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAE5C,MAAa,eAAgB,SAAQ,uBAAU;IACtC,IAAI,GAAW,kBAAkB,CAAC;IAClC,MAAM,CAAQ;IAErB,YAAY,OAAe,EAAE,SAAgB,EAAE;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AARD,0CAQC","sourcesContent":["import {BadRequest} from \"@tsed/exceptions\";\n\nexport class ValidationError extends BadRequest {\n public name: string = \"VALIDATION_ERROR\";\n public errors: any[];\n\n constructor(message: string, errors: any[] = []) {\n super(message);\n this.errors = errors;\n }\n}\n"]}
@@ -6,6 +6,7 @@ const tslib_1 = require("tslib");
6
6
  const di_1 = require("@tsed/di");
7
7
  const json_mapper_1 = require("@tsed/json-mapper");
8
8
  let DeserializerPipe = DeserializerPipe_1 = class DeserializerPipe {
9
+ settings;
9
10
  transform(value, param) {
10
11
  return (0, json_mapper_1.deserialize)(value, {
11
12
  useAlias: true,
@@ -1 +1 @@
1
- {"version":3,"file":"DeserializerPipe.js","sourceRoot":"","sources":["../../../src/pipes/DeserializerPipe.ts"],"names":[],"mappings":";;;;;AAAA,iCAA8C;AAC9C,mDAA8C;AAI9C,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IAM3B,SAAS,CAAC,KAAU,EAAE,KAAyB;QAC7C,OAAO,IAAA,yBAAW,EAAC,KAAK,EAAE;YACxB,QAAQ,EAAE,IAAI;YACd,oBAAoB,EAAE,IAAI,CAAC,QAAQ,CAAC,oBAAoB,KAAK,QAAQ;YACrE,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM;YAC9B,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;YACrC,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAgB,CAAC,IAAI,EAAE,CAAC;SAC7C,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAhBC;IADC,IAAA,aAAQ,EAAC,WAAW,EAAE,EAAE,CAAC;;kDAGxB;AAJS,gBAAgB;IAD5B,IAAA,eAAU,GAAE;GACA,gBAAgB,CAkB5B;AAlBY,4CAAgB","sourcesContent":["import {Constant, Injectable} from \"@tsed/di\";\nimport {deserialize} from \"@tsed/json-mapper\";\nimport {JsonParameterStore, PipeMethods} from \"@tsed/schema\";\n\n@Injectable()\nexport class DeserializerPipe implements PipeMethods {\n @Constant(\"converter\", {})\n private settings: {\n additionalProperties?: \"error\" | \"accept\" | \"ignore\";\n };\n\n transform(value: any, param: JsonParameterStore) {\n return deserialize(value, {\n useAlias: true,\n additionalProperties: this.settings.additionalProperties === \"accept\",\n type: param.type,\n collectionType: param.collectionType,\n groups: param.parameter.groups,\n genericTypes: param.nestedGenerics[0],\n nestedGenerics: param.nestedGenerics,\n ...(param.store.get(DeserializerPipe) || {})\n });\n }\n}\n"]}
1
+ {"version":3,"file":"DeserializerPipe.js","sourceRoot":"","sources":["../../../src/pipes/DeserializerPipe.ts"],"names":[],"mappings":";;;;;AAAA,iCAA8C;AAC9C,mDAA8C;AAI9C,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IAEnB,QAAQ,CAEd;IAEF,SAAS,CAAC,KAAU,EAAE,KAAyB;QAC7C,OAAO,IAAA,yBAAW,EAAC,KAAK,EAAE;YACxB,QAAQ,EAAE,IAAI;YACd,oBAAoB,EAAE,IAAI,CAAC,QAAQ,CAAC,oBAAoB,KAAK,QAAQ;YACrE,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM;YAC9B,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;YACrC,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAgB,CAAC,IAAI,EAAE,CAAC;SAC7C,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAhBC;IADC,IAAA,aAAQ,EAAC,WAAW,EAAE,EAAE,CAAC;;kDAGxB;AAJS,gBAAgB;IAD5B,IAAA,eAAU,GAAE;GACA,gBAAgB,CAkB5B;AAlBY,4CAAgB","sourcesContent":["import {Constant, Injectable} from \"@tsed/di\";\nimport {deserialize} from \"@tsed/json-mapper\";\nimport {JsonParameterStore, PipeMethods} from \"@tsed/schema\";\n\n@Injectable()\nexport class DeserializerPipe implements PipeMethods {\n @Constant(\"converter\", {})\n private settings: {\n additionalProperties?: \"error\" | \"accept\" | \"ignore\";\n };\n\n transform(value: any, param: JsonParameterStore) {\n return deserialize(value, {\n useAlias: true,\n additionalProperties: this.settings.additionalProperties === \"accept\",\n type: param.type,\n collectionType: param.collectionType,\n groups: param.parameter.groups,\n genericTypes: param.nestedGenerics[0],\n nestedGenerics: param.nestedGenerics,\n ...(param.store.get(DeserializerPipe) || {})\n });\n }\n}\n"]}
@@ -19,6 +19,7 @@ function cast(value, metadata) {
19
19
  }
20
20
  }
21
21
  let ValidationPipe = class ValidationPipe {
22
+ validator;
22
23
  constructor(injector) {
23
24
  const provider = injector.getProviders().find((provider) => (0, core_1.nameOf)(provider.token) === "AjvService");
24
25
  if (provider) {
@@ -1 +1 @@
1
- {"version":3,"file":"ValidationPipe.js","sourceRoot":"","sources":["../../../src/pipes/ValidationPipe.ts"],"names":[],"mappings":";;;;AAAA,qCAAkC;AAClC,iCAAqD;AACrD,mDAA8C;AAC9C,yCAA4E;AAC5E,+EAA0E;AAC1E,q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e,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YACtC,OAAO,KAAK,CAAC;SACd;QAED,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;YAC9B,OAAO,KAAK,CAAC;SACd;QAED,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE1C,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAEtC,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,OAAO,KAAK,CAAC;SACd;QAED,MAAM,MAAM,GAAG,IAAA,sBAAa,EAAC,QAAQ,EAAE;YACrC,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE;YACnC,MAAM;YACN,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YAClD,cAAc,EAAE,QAAQ,CAAC,cAAc;SACxC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;IAES,eAAe,CAAC,KAAU,EAAE,QAA4B;QAChE,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAC9B,MAAM,iDAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC9C;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzEY,cAAc;IAH1B,IAAA,eAAU,EAAC;QACV,IAAI,EAAE,WAAW;KAClB,CAAC;6CAIsB,oBAAe;GAH1B,cAAc,CAyE1B;AAzEY,wCAAc","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {Injectable, InjectorService} from \"@tsed/di\";\nimport {deserialize} from \"@tsed/json-mapper\";\nimport {getJsonSchema, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {RequiredValidationError} from \"../errors/RequiredValidationError\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\n\nfunction cast(value: any, metadata: JsonParameterStore) {\n try {\n return deserialize(value, {\n type: metadata.type\n });\n } catch (er) {\n return value;\n }\n}\n\n@Injectable({\n type: \"validator\"\n})\nexport class ValidationPipe implements PipeMethods {\n private validator: {validate(value: any, options: any): Promise<any>};\n\n constructor(injector: InjectorService) {\n const provider = injector.getProviders().find((provider) => nameOf(provider.token) === \"AjvService\");\n\n if (provider) {\n this.validator = injector.invoke<any>(provider.token);\n }\n }\n\n coerceTypes(value: any, metadata: JsonParameterStore) {\n if (value === undefined) {\n return value;\n }\n\n if (value === \"null\") {\n return null;\n }\n\n if (metadata.isArray) {\n return [].concat(value);\n }\n\n if (metadata.isPrimitive) {\n return cast(value, metadata);\n }\n\n return value;\n }\n\n skip(value: any, metadata: JsonParameterStore) {\n return metadata.paramType === ParamTypes.PATH && !metadata.isPrimitive;\n }\n\n async transform(value: any, metadata: JsonParameterStore): Promise<any> {\n if (!this.validator) {\n this.checkIsRequired(value, metadata);\n return value;\n }\n\n if (this.skip(value, metadata)) {\n return value;\n }\n\n value = this.coerceTypes(value, metadata);\n\n this.checkIsRequired(value, metadata);\n\n if (value === undefined) {\n return value;\n }\n\n const schema = getJsonSchema(metadata, {\n customKeys: true\n });\n\n await this.validator.validate(value, {\n schema,\n type: metadata.isClass ? metadata.type : undefined,\n collectionType: metadata.collectionType\n });\n\n return value;\n }\n\n protected checkIsRequired(value: any, metadata: JsonParameterStore) {\n if (metadata.isRequired(value)) {\n throw RequiredValidationError.from(metadata);\n }\n\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"ValidationPipe.js","sourceRoot":"","sources":["../../../src/pipes/ValidationPipe.ts"],"names":[],"mappings":";;;;AAAA,qCAAkC;AAClC,iCAAqD;AACrD,mDAA8C;AAC9C,yCAA4E;AAC5E,+EAA0E;AAC1E,qDAAgD;AAEhD,SAAS,IAAI,CAAC,KAAU,EAAE,QAA4B;IACpD,IAAI;QACF,OAAO,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K,CAAC;SACd;QAED,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;YAC9B,OAAO,KAAK,CAAC;SACd;QAED,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE1C,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAEtC,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,OAAO,KAAK,CAAC;SACd;QAED,MAAM,MAAM,GAAG,IAAA,sBAAa,EAAC,QAAQ,EAAE;YACrC,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE;YACnC,MAAM;YACN,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YAClD,cAAc,EAAE,QAAQ,CAAC,cAAc;SACxC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;IAES,eAAe,CAAC,KAAU,EAAE,QAA4B;QAChE,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAC9B,MAAM,iDAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC9C;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzEY,cAAc;IAH1B,IAAA,eAAU,EAAC;QACV,IAAI,EAAE,WAAW;KAClB,CAAC;6CAIsB,oBAAe;GAH1B,cAAc,CAyE1B;AAzEY,wCAAc","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {Injectable, InjectorService} from \"@tsed/di\";\nimport {deserialize} from \"@tsed/json-mapper\";\nimport {getJsonSchema, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {RequiredValidationError} from \"../errors/RequiredValidationError\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\n\nfunction cast(value: any, metadata: JsonParameterStore) {\n try {\n return deserialize(value, {\n type: metadata.type\n });\n } catch (er) {\n return value;\n }\n}\n\n@Injectable({\n type: \"validator\"\n})\nexport class ValidationPipe implements PipeMethods {\n private validator: {validate(value: any, options: any): Promise<any>};\n\n constructor(injector: InjectorService) {\n const provider = injector.getProviders().find((provider) => nameOf(provider.token) === \"AjvService\");\n\n if (provider) {\n this.validator = injector.invoke<any>(provider.token);\n }\n }\n\n coerceTypes(value: any, metadata: JsonParameterStore) {\n if (value === undefined) {\n return value;\n }\n\n if (value === \"null\") {\n return null;\n }\n\n if (metadata.isArray) {\n return [].concat(value);\n }\n\n if (metadata.isPrimitive) {\n return cast(value, metadata);\n }\n\n return value;\n }\n\n skip(value: any, metadata: JsonParameterStore) {\n return metadata.paramType === ParamTypes.PATH && !metadata.isPrimitive;\n }\n\n async transform(value: any, metadata: JsonParameterStore): Promise<any> {\n if (!this.validator) {\n this.checkIsRequired(value, metadata);\n return value;\n }\n\n if (this.skip(value, metadata)) {\n return value;\n }\n\n value = this.coerceTypes(value, metadata);\n\n this.checkIsRequired(value, metadata);\n\n if (value === undefined) {\n return value;\n }\n\n const schema = getJsonSchema(metadata, {\n customKeys: true\n });\n\n await this.validator.validate(value, {\n schema,\n type: metadata.isClass ? metadata.type : undefined,\n collectionType: metadata.collectionType\n });\n\n return value;\n }\n\n protected checkIsRequired(value: any, metadata: JsonParameterStore) {\n if (metadata.isRequired(value)) {\n throw RequiredValidationError.from(metadata);\n }\n\n return true;\n }\n}\n"]}
@@ -8,6 +8,7 @@ import { ParseExpressionPipe } from "../pipes/ParseExpressionPipe.js";
8
8
  * @platform
9
9
  */
10
10
  let PlatformParams = class PlatformParams {
11
+ injector;
11
12
  async getPipes(param) {
12
13
  const get = (pipe) => {
13
14
  return this.injector.getProvider(pipe).priority || 0;
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformParams.js","sourceRoot":"","sources":["../../../src/builder/PlatformParams.ts"],"names":[],"mappings":";AAAA,OAAO,EAAY,MA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\";\nimport {JsonEntityStore, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {ParamValidationError} from \"../errors/ParamValidationError\";\nimport {ParseExpressionPipe} from \"../pipes/ParseExpressionPipe\";\n\nexport type ArgScope<Context extends DIContext = DIContext> = {$ctx: Context} & Record<string, any>;\nexport type HandlerWithScope<Context extends DIContext = DIContext> = (scope: ArgScope<Context>) => any;\n\nexport interface CompileHandlerOptions<Context extends DIContext = DIContext> extends Record<any, unknown> {\n token: TokenProvider;\n propertyKey: string | symbol;\n getCustomArgs?: (scope: ArgScope<Context>) => Promise<any[]>;\n}\n\n/**\n * Platform Params abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: []\n})\nexport class PlatformParams {\n @Inject()\n protected injector: InjectorService;\n\n async getPipes(param: JsonParameterStore) {\n const get = (pipe: TokenProvider) => {\n return this.injector.getProvider(pipe)!.priority || 0;\n };\n\n const sort = (p1: TokenProvider, p2: TokenProvider) => (get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0);\n const map = (token: TokenProvider) => this.injector.invoke<PipeMethods>(token)!;\n const promises = await Promise.all([ParseExpressionPipe, ...param.pipes.sort(sort)].map(map));\n\n return promises.filter(Boolean);\n }\n\n async compile<Context extends DIContext = DIContext>(entity: JsonEntityStore) {\n const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);\n\n const argsPipes = await Promise.all(\n params.map(async (param) => {\n return {\n param,\n pipes: await this.getPipes(param)\n };\n })\n );\n\n return (scope: ArgScope<Context>) => {\n const promises = argsPipes.map(({param, pipes}) => {\n return this.getArg(scope, pipes, param);\n });\n\n return Promise.all(promises);\n };\n }\n\n async getArg(scope: ArgScope, pipes: PipeMethods[], param: JsonParameterStore) {\n return pipes.reduce(async (value, pipe) => {\n value = await value;\n\n try {\n return await pipe.transform(value, param);\n } catch (er) {\n throw ParamValidationError.from(param, er);\n }\n }, scope as any);\n }\n\n async compileHandler<Context extends DIContext = DIContext>(\n metadata: CompileHandlerOptions<Context>\n ): Promise<HandlerWithScope<Context>> {\n const {token, propertyKey, getCustomArgs} = metadata;\n\n const provider = this.injector.getProvider(token);\n const getArguments = getCustomArgs || (await this.compile<Context>(JsonEntityStore.fromMethod(token, propertyKey!)));\n\n if (!provider || !provider.scope || provider.scope === ProviderScope.SINGLETON) {\n const instance = await this.injector.invoke<any>(token);\n\n return async (scope) => {\n const args = await getArguments(scope);\n\n return instance[propertyKey!].call(instance, ...args, scope.$ctx);\n };\n }\n\n return async (scope) => {\n const [instance, args] = await Promise.all([this.injector.invoke<any>(token, scope.$ctx.container), getArguments(scope)]);\n\n return instance[propertyKey].call(instance, ...args, scope.$ctx);\n };\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformParams.js","sourceRoot":"","sources":["../../../src/builder/PlatformParams.ts"],"names":[],"mappings":";AAAA,OAAO,EAAY,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAAgB,MAAM,UAAU,CAAC;AACtG,OAAO,EAAC,eAAe,EAAE,kBAAkB,EAAc,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAWjE;;;GAGG;AAKH,IAAa,cAAc,GAA3B,MAAa,cAAc;IAEf,QAAQ,CAAkB;IAEpC,KAAK,CAAC,QAAQ,CAAC,KAAyB;QACtC,MAAM,GAAG,GAAG,CAAC,IAAmB,EAAE,EAAE;YAClC,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAE,CAAC,QAAQ,IAAI,CAAC,CAAC;QACxD,CAAC,CAAC;QAEF,MAAM,IAAI,GAAG,CAAC,EAAiB,EAAE,EAAiB,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,C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AAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAM,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAE1H,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACnE,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AAvEC;IADC,MAAM,EAAE;8BACW,eAAe;gDAAC;AAFzB,cAAc;IAJ1B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,EAAE;KACZ,CAAC;GACW,cAAc,CAyE1B;SAzEY,cAAc","sourcesContent":["import {DIContext, Inject, Injectable, InjectorService, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport {JsonEntityStore, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {ParamValidationError} from \"../errors/ParamValidationError\";\nimport {ParseExpressionPipe} from \"../pipes/ParseExpressionPipe\";\n\nexport type ArgScope<Context extends DIContext = DIContext> = {$ctx: Context} & Record<string, any>;\nexport type HandlerWithScope<Context extends DIContext = DIContext> = (scope: ArgScope<Context>) => any;\n\nexport interface CompileHandlerOptions<Context extends DIContext = DIContext> extends Record<any, unknown> {\n token: TokenProvider;\n propertyKey: string | symbol;\n getCustomArgs?: (scope: ArgScope<Context>) => Promise<any[]>;\n}\n\n/**\n * Platform Params abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: []\n})\nexport class PlatformParams {\n @Inject()\n protected injector: InjectorService;\n\n async getPipes(param: JsonParameterStore) {\n const get = (pipe: TokenProvider) => {\n return this.injector.getProvider(pipe)!.priority || 0;\n };\n\n const sort = (p1: TokenProvider, p2: TokenProvider) => (get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0);\n const map = (token: TokenProvider) => this.injector.invoke<PipeMethods>(token)!;\n const promises = await Promise.all([ParseExpressionPipe, ...param.pipes.sort(sort)].map(map));\n\n return promises.filter(Boolean);\n }\n\n async compile<Context extends DIContext = DIContext>(entity: JsonEntityStore) {\n const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);\n\n const argsPipes = await Promise.all(\n params.map(async (param) => {\n return {\n param,\n pipes: await this.getPipes(param)\n };\n })\n );\n\n return (scope: ArgScope<Context>) => {\n const promises = argsPipes.map(({param, pipes}) => {\n return this.getArg(scope, pipes, param);\n });\n\n return Promise.all(promises);\n };\n }\n\n async getArg(scope: ArgScope, pipes: PipeMethods[], param: JsonParameterStore) {\n return pipes.reduce(async (value, pipe) => {\n value = await value;\n\n try {\n return await pipe.transform(value, param);\n } catch (er) {\n throw ParamValidationError.from(param, er);\n }\n }, scope as any);\n }\n\n async compileHandler<Context extends DIContext = DIContext>(\n metadata: CompileHandlerOptions<Context>\n ): Promise<HandlerWithScope<Context>> {\n const {token, propertyKey, getCustomArgs} = metadata;\n\n const provider = this.injector.getProvider(token);\n const getArguments = getCustomArgs || (await this.compile<Context>(JsonEntityStore.fromMethod(token, propertyKey!)));\n\n if (!provider || !provider.scope || provider.scope === ProviderScope.SINGLETON) {\n const instance = await this.injector.invoke<any>(token);\n\n return async (scope) => {\n const args = await getArguments(scope);\n\n return instance[propertyKey!].call(instance, ...args, scope.$ctx);\n };\n }\n\n return async (scope) => {\n const [instance, args] = await Promise.all([this.injector.invoke<any>(token, scope.$ctx.container), getArguments(scope)]);\n\n return instance[propertyKey].call(instance, ...args, scope.$ctx);\n };\n }\n}\n"]}
@@ -13,14 +13,13 @@ import { PARAM_TYPES_DATA_PATH, ParamTypes } from "../domain/ParamTypes.js";
13
13
  */
14
14
  export function UseParamType(options) {
15
15
  return useDecorators(ParamFn((param) => {
16
- var _a;
17
16
  if (isParameterType(options.paramType)) {
18
17
  param.parameter.in(options.paramType);
19
18
  }
20
19
  param.paramType = options.paramType;
21
20
  if (isBuffer(param.type) || isBuffer(options.useType) || options.paramType === ParamTypes.RAW_BODY) {
22
21
  param.paramType = ParamTypes.RAW_BODY;
23
- (_a = param.parent.operation) === null || _a === void 0 ? void 0 : _a.consumes(["*/*"]);
22
+ param.parent.operation?.consumes(["*/*"]);
24
23
  }
25
24
  param.dataPath = options.dataPath || PARAM_TYPES_DATA_PATH[param.paramType] || "$ctx";
26
25
  }), options.expression && UseParamExpression(options.expression), options.expression && Name(options.expression));
@@ -1 +1 @@
1
- {"version":3,"file":"useParamType.js","sourceRoot":"","sources":["../../../src/decorators/useParamType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACnD,OAAO,EAAC,eAAe,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,qBAAqB,EAAE,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAEvE;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,OAAqB;IAChD,OAAO,aAAa,CAClB,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;;QAChB,IAAI,eAAe,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YACtC,KAAK,CAAC,SAAU,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;SACxC;QAED,KAAK,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QAEpC,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,SAAS,KAAK,UAAU,CAAC,QAAQ,EAAE;YAClG,KAAK,CAAC,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC;YACtC,MAAA,KAAK,CAAC,MAAM,CAAC,SAAS,0CAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;SAC3C;QAED,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,qBAAqB,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC;IACxF,CAAC,CAAC,EACF,OAAO,CAAC,UAAU,IAAI,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,EAC5D,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAC/C,CAAC;AACJ,CAAC","sourcesContent":["import {isBuffer, useDecorators} from \"@tsed/core\";\nimport {isParameterType, Name} from \"@tsed/schema\";\nimport {ParamFn} from \"./paramFn\";\nimport {ParamOptions} from \"../domain/ParamOptions\";\nimport {UseParamExpression} from \"./useParamExpression\";\nimport {PARAM_TYPES_DATA_PATH, ParamTypes} from \"../domain/ParamTypes\";\n\n/**\n * Get the object from request (like body, params, query, etc...).\n *\n * @decorator\n * @operation\n * @input\n * @pipe\n */\nexport function UseParamType(options: ParamOptions) {\n return useDecorators(\n ParamFn((param) => {\n if (isParameterType(options.paramType)) {\n param.parameter!.in(options.paramType);\n }\n\n param.paramType = options.paramType;\n\n if (isBuffer(param.type) || isBuffer(options.useType) || options.paramType === ParamTypes.RAW_BODY) {\n param.paramType = ParamTypes.RAW_BODY;\n param.parent.operation?.consumes([\"*/*\"]);\n }\n\n param.dataPath = options.dataPath || PARAM_TYPES_DATA_PATH[param.paramType] || \"$ctx\";\n }),\n options.expression && UseParamExpression(options.expression),\n options.expression && Name(options.expression)\n );\n}\n"]}
1
+ {"version":3,"file":"useParamType.js","sourceRoot":"","sources":["../../../src/decorators/useParamType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACnD,OAAO,EAAC,eAAe,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,qBAAqB,EAAE,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAEvE;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,OAAqB;IAChD,OAAO,aAAa,CAClB,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QAChB,IAAI,eAAe,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YACtC,KAAK,CAAC,SAAU,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;SACxC;QAED,KAAK,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QAEpC,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,SAAS,KAAK,UAAU,CAAC,QAAQ,EAAE;YAClG,KAAK,CAAC,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC;YACtC,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;SAC3C;QAED,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,qBAAqB,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC;IACxF,CAAC,CAAC,EACF,OAAO,CAAC,UAAU,IAAI,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,EAC5D,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAC/C,CAAC;AACJ,CAAC","sourcesContent":["import {isBuffer, useDecorators} from \"@tsed/core\";\nimport {isParameterType, Name} from \"@tsed/schema\";\nimport {ParamFn} from \"./paramFn\";\nimport {ParamOptions} from \"../domain/ParamOptions\";\nimport {UseParamExpression} from \"./useParamExpression\";\nimport {PARAM_TYPES_DATA_PATH, ParamTypes} from \"../domain/ParamTypes\";\n\n/**\n * Get the object from request (like body, params, query, etc...).\n *\n * @decorator\n * @operation\n * @input\n * @pipe\n */\nexport function UseParamType(options: ParamOptions) {\n return useDecorators(\n ParamFn((param) => {\n if (isParameterType(options.paramType)) {\n param.parameter!.in(options.paramType);\n }\n\n param.paramType = options.paramType;\n\n if (isBuffer(param.type) || isBuffer(options.useType) || options.paramType === ParamTypes.RAW_BODY) {\n param.paramType = ParamTypes.RAW_BODY;\n param.parent.operation?.consumes([\"*/*\"]);\n }\n\n param.dataPath = options.dataPath || PARAM_TYPES_DATA_PATH[param.paramType] || \"$ctx\";\n }),\n options.expression && UseParamExpression(options.expression),\n options.expression && Name(options.expression)\n );\n}\n"]}
@@ -2,10 +2,9 @@ import { nameOf } from "@tsed/core";
2
2
  import { BadRequest } from "@tsed/exceptions";
3
3
  import { ValidationError } from "./ValidationError.js";
4
4
  export class ParamValidationError extends BadRequest {
5
- constructor() {
6
- super(...arguments);
7
- this.name = "PARAM_VALIDATION_ERROR";
8
- }
5
+ name = "PARAM_VALIDATION_ERROR";
6
+ dataPath;
7
+ requestType;
9
8
  static from(metadata, origin = {}) {
10
9
  if (origin instanceof ValidationError || origin instanceof BadRequest) {
11
10
  const name = nameOf(metadata.paramType)
@@ -1 +1 @@
1
- {"version":3,"file":"ParamValidationError.js","sourceRoot":"","sources":["../../../src/errors/ParamValidationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,YAAY,CAAC;AAClC,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD,MAAM,OAAO,oBAAqB,SAAQ,UAAU;IAApD;;QACS,SAAI,GAAW,wBAAwB,CAAC;IAsBjD,CAAC;IAlBC,MAAM,CAAC,IAAI,CAAC,QAA4B,EAAE,SAAc,EAAE;QACxD,IAAI,MAAM,YAAY,eAAe,IAAI,MAAM,YAAY,UAAU,EAAE;YACrE,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;iBACpC,WAAW,EAAE;iBACb,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;YACxC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;YACvC,MAAM,OAAO,GAAG,qCAAqC,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC;YAE7H,MAAM,KAAK,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAC;YAChD,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YACnD,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;YAC/C,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC;YAEvC,OAAO,KAAK,CAAC;SACd;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {BadRequest} from \"@tsed/exceptions\";\nimport {JsonParameterStore} from \"@tsed/schema\";\nimport {ValidationError} from \"./ValidationError\";\n\nexport class ParamValidationError extends BadRequest {\n public name: string = \"PARAM_VALIDATION_ERROR\";\n public dataPath: string;\n public requestType: string;\n\n static from(metadata: JsonParameterStore, origin: any = {}) {\n if (origin instanceof ValidationError || origin instanceof BadRequest) {\n const name = nameOf(metadata.paramType)\n .toLowerCase()\n .replace(/parse|params|filter/gi, \"\");\n const expression = metadata.expression;\n const message = `Bad request on parameter \"request.${name}${expression ? \".\" + expression : \"\"}\".\\n${origin.message}`.trim();\n\n const error = new ParamValidationError(message);\n error.dataPath = String(metadata.expression) || \"\";\n error.requestType = nameOf(metadata.paramType);\n error.origin = origin.origin || origin;\n\n return error;\n }\n\n return origin;\n }\n}\n"]}
1
+ {"version":3,"file":"ParamValidationError.js","sourceRoot":"","sources":["../../../src/errors/ParamValidationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,YAAY,CAAC;AAClC,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD,MAAM,OAAO,oBAAqB,SAAQ,UAAU;IAC3C,IAAI,GAAW,wBAAwB,CAAC;IACxC,QAAQ,CAAS;IACjB,WAAW,CAAS;IAE3B,MAAM,CAAC,IAAI,CAAC,QAA4B,EAAE,SAAc,EAAE;QACxD,IAAI,MAAM,YAAY,eAAe,IAAI,MAAM,YAAY,UAAU,EAAE;YACrE,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;iBACpC,WAAW,EAAE;iBACb,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;YACxC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;YACvC,MAAM,OAAO,GAAG,qCAAqC,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC;YAE7H,MAAM,KAAK,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAC;YAChD,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YACnD,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;YAC/C,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC;YAEvC,OAAO,KAAK,CAAC;SACd;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {BadRequest} from \"@tsed/exceptions\";\nimport {JsonParameterStore} from \"@tsed/schema\";\nimport {ValidationError} from \"./ValidationError\";\n\nexport class ParamValidationError extends BadRequest {\n public name: string = \"PARAM_VALIDATION_ERROR\";\n public dataPath: string;\n public requestType: string;\n\n static from(metadata: JsonParameterStore, origin: any = {}) {\n if (origin instanceof ValidationError || origin instanceof BadRequest) {\n const name = nameOf(metadata.paramType)\n .toLowerCase()\n .replace(/parse|params|filter/gi, \"\");\n const expression = metadata.expression;\n const message = `Bad request on parameter \"request.${name}${expression ? \".\" + expression : \"\"}\".\\n${origin.message}`.trim();\n\n const error = new ParamValidationError(message);\n error.dataPath = String(metadata.expression) || \"\";\n error.requestType = nameOf(metadata.paramType);\n error.origin = origin.origin || origin;\n\n return error;\n }\n\n return origin;\n }\n}\n"]}
@@ -1,10 +1,7 @@
1
1
  import { nameOf } from "@tsed/core";
2
2
  import { ValidationError } from "./ValidationError.js";
3
3
  export class RequiredValidationError extends ValidationError {
4
- constructor() {
5
- super(...arguments);
6
- this.name = "REQUIRED_VALIDATION_ERROR";
7
- }
4
+ name = "REQUIRED_VALIDATION_ERROR";
8
5
  static from(metadata) {
9
6
  const name = nameOf(metadata.paramType);
10
7
  const expression = metadata.expression;
@@ -1 +1 @@
1
- {"version":3,"file":"RequiredValidationError.js","sourceRoot":"","sources":["../../../src/errors/RequiredValidationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,YAAY,CAAC;AAClC,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAGlD,MAAM,OAAO,uBAAwB,SAAQ,eAAe;IAA5D;;QACS,SAAI,GAAW,2BAA2B,CAAC;IAuBpD,CAAC;IArBC,MAAM,CAAC,IAAI,CAAC,QAA4B;QACtC,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACxC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;QACvC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;QACrE,MAAM,OAAO,GAAG,sCAAsC,UAAU,GAAG,CAAC;QAEpE,MAAM,MAAM,GAAG;YACb;gBACE,QAAQ,EAAE,EAAE;gBACZ,OAAO,EAAE,UAAU;gBACnB,OAAO;gBACP,SAAS,EAAE,IAAI;gBACf,MAAM,EAAE;oBACN,eAAe,EAAE,UAAU;iBAC5B;gBACD,UAAU,EAAE,YAAY;aACzB;SACF,CAAC;QAEF,OAAO,IAAI,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {ValidationError} from \"./ValidationError\";\nimport {JsonParameterStore} from \"@tsed/schema\";\n\nexport class RequiredValidationError extends ValidationError {\n public name: string = \"REQUIRED_VALIDATION_ERROR\";\n\n static from(metadata: JsonParameterStore) {\n const name = nameOf(metadata.paramType);\n const expression = metadata.expression;\n const type = name.toLowerCase().replace(/parse|params|filter/gi, \"\");\n const message = `It should have required parameter '${expression}'`;\n\n const errors = [\n {\n dataPath: \"\",\n keyword: \"required\",\n message,\n modelName: type,\n params: {\n missingProperty: expression\n },\n schemaPath: \"#/required\"\n }\n ];\n\n return new RequiredValidationError(message, errors);\n }\n}\n"]}
1
+ {"version":3,"file":"RequiredValidationError.js","sourceRoot":"","sources":["../../../src/errors/RequiredValidationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,YAAY,CAAC;AAClC,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAGlD,MAAM,OAAO,uBAAwB,SAAQ,eAAe;IACnD,IAAI,GAAW,2BAA2B,CAAC;IAElD,MAAM,CAAC,IAAI,CAAC,QAA4B;QACtC,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACxC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;QACvC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;QACrE,MAAM,OAAO,GAAG,sCAAsC,UAAU,GAAG,CAAC;QAEpE,MAAM,MAAM,GAAG;YACb;gBACE,QAAQ,EAAE,EAAE;gBACZ,OAAO,EAAE,UAAU;gBACnB,OAAO;gBACP,SAAS,EAAE,IAAI;gBACf,MAAM,EAAE;oBACN,eAAe,EAAE,UAAU;iBAC5B;gBACD,UAAU,EAAE,YAAY;aACzB;SACF,CAAC;QAEF,OAAO,IAAI,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {ValidationError} from \"./ValidationError\";\nimport {JsonParameterStore} from \"@tsed/schema\";\n\nexport class RequiredValidationError extends ValidationError {\n public name: string = \"REQUIRED_VALIDATION_ERROR\";\n\n static from(metadata: JsonParameterStore) {\n const name = nameOf(metadata.paramType);\n const expression = metadata.expression;\n const type = name.toLowerCase().replace(/parse|params|filter/gi, \"\");\n const message = `It should have required parameter '${expression}'`;\n\n const errors = [\n {\n dataPath: \"\",\n keyword: \"required\",\n message,\n modelName: type,\n params: {\n missingProperty: expression\n },\n schemaPath: \"#/required\"\n }\n ];\n\n return new RequiredValidationError(message, errors);\n }\n}\n"]}
@@ -1,8 +1,9 @@
1
1
  import { BadRequest } from "@tsed/exceptions";
2
2
  export class ValidationError extends BadRequest {
3
+ name = "VALIDATION_ERROR";
4
+ errors;
3
5
  constructor(message, errors = []) {
4
6
  super(message);
5
- this.name = "VALIDATION_ERROR";
6
7
  this.errors = errors;
7
8
  }
8
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ValidationError.js","sourceRoot":"","sources":["../../../src/errors/ValidationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAE5C,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAI7C,YAAY,OAAe,EAAE,SAAgB,EAAE;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QAJV,SAAI,GAAW,kBAAkB,CAAC;QAKvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF","sourcesContent":["import {BadRequest} from \"@tsed/exceptions\";\n\nexport class ValidationError extends BadRequest {\n public name: string = \"VALIDATION_ERROR\";\n public errors: any[];\n\n constructor(message: string, errors: any[] = []) {\n super(message);\n this.errors = errors;\n }\n}\n"]}
1
+ {"version":3,"file":"ValidationError.js","sourceRoot":"","sources":["../../../src/errors/ValidationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAE5C,MAAM,OAAO,eAAgB,SAAQ,UAAU;IACtC,IAAI,GAAW,kBAAkB,CAAC;IAClC,MAAM,CAAQ;IAErB,YAAY,OAAe,EAAE,SAAgB,EAAE;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF","sourcesContent":["import {BadRequest} from \"@tsed/exceptions\";\n\nexport class ValidationError extends BadRequest {\n public name: string = \"VALIDATION_ERROR\";\n public errors: any[];\n\n constructor(message: string, errors: any[] = []) {\n super(message);\n this.errors = errors;\n }\n}\n"]}
@@ -3,6 +3,7 @@ import { __decorate, __metadata } from "tslib";
3
3
  import { Constant, Injectable } from "@tsed/di";
4
4
  import { deserialize } from "@tsed/json-mapper";
5
5
  let DeserializerPipe = DeserializerPipe_1 = class DeserializerPipe {
6
+ settings;
6
7
  transform(value, param) {
7
8
  return deserialize(value, {
8
9
  useAlias: true,
@@ -1 +1 @@
1
- {"version":3,"file":"DeserializerPipe.js","sourceRoot":"","sources":["../../../src/pipes/DeserializerPipe.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAI9C,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IAM3B,SAAS,CAAC,KAAU,EAAE,KAAyB;QAC7C,OAAO,WAAW,CAAC,KAAK,EAAE;YACxB,QAAQ,EAAE,IAAI;YACd,oBAAoB,EAAE,IAAI,CAAC,QAAQ,CAAC,oBAAoB,KAAK,QAAQ;YACrE,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM;YAC9B,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;YACrC,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAgB,CAAC,IAAI,EAAE,CAAC;SAC7C,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAhBC;IADC,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC;;kDAGxB;AAJS,gBAAgB;IAD5B,UAAU,EAAE;GACA,gBAAgB,CAkB5B;SAlBY,gBAAgB","sourcesContent":["import {Constant, Injectable} from \"@tsed/di\";\nimport {deserialize} from \"@tsed/json-mapper\";\nimport {JsonParameterStore, PipeMethods} from \"@tsed/schema\";\n\n@Injectable()\nexport class DeserializerPipe implements PipeMethods {\n @Constant(\"converter\", {})\n private settings: {\n additionalProperties?: \"error\" | \"accept\" | \"ignore\";\n };\n\n transform(value: any, param: JsonParameterStore) {\n return deserialize(value, {\n useAlias: true,\n additionalProperties: this.settings.additionalProperties === \"accept\",\n type: param.type,\n collectionType: param.collectionType,\n groups: param.parameter.groups,\n genericTypes: param.nestedGenerics[0],\n nestedGenerics: param.nestedGenerics,\n ...(param.store.get(DeserializerPipe) || {})\n });\n }\n}\n"]}
1
+ {"version":3,"file":"DeserializerPipe.js","sourceRoot":"","sources":["../../../src/pipes/DeserializerPipe.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAI9C,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IAEnB,QAAQ,CAEd;IAEF,SAAS,CAAC,KAAU,EAAE,KAAyB;QAC7C,OAAO,WAAW,CAAC,KAAK,EAAE;YACxB,QAAQ,EAAE,IAAI;YACd,oBAAoB,EAAE,IAAI,CAAC,QAAQ,CAAC,oBAAoB,KAAK,QAAQ;YACrE,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM;YAC9B,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;YACrC,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAgB,CAAC,IAAI,EAAE,CAAC;SAC7C,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAhBC;IADC,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC;;kDAGxB;AAJS,gBAAgB;IAD5B,UAAU,EAAE;GACA,gBAAgB,CAkB5B;SAlBY,gBAAgB","sourcesContent":["import {Constant, Injectable} from \"@tsed/di\";\nimport {deserialize} from \"@tsed/json-mapper\";\nimport {JsonParameterStore, PipeMethods} from \"@tsed/schema\";\n\n@Injectable()\nexport class DeserializerPipe implements PipeMethods {\n @Constant(\"converter\", {})\n private settings: {\n additionalProperties?: \"error\" | \"accept\" | \"ignore\";\n };\n\n transform(value: any, param: JsonParameterStore) {\n return deserialize(value, {\n useAlias: true,\n additionalProperties: this.settings.additionalProperties === \"accept\",\n type: param.type,\n collectionType: param.collectionType,\n groups: param.parameter.groups,\n genericTypes: param.nestedGenerics[0],\n nestedGenerics: param.nestedGenerics,\n ...(param.store.get(DeserializerPipe) || {})\n });\n }\n}\n"]}
@@ -16,6 +16,7 @@ function cast(value, metadata) {
16
16
  }
17
17
  }
18
18
  let ValidationPipe = class ValidationPipe {
19
+ validator;
19
20
  constructor(injector) {
20
21
  const provider = injector.getProviders().find((provider) => nameOf(provider.token) === "AjvService");
21
22
  if (provider) {
@@ -1 +1 @@
1
- {"version":3,"file":"ValidationPipe.js","sourceRoot":"","sources":["../../../src/pipes/ValidationPipe.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,YAAY,CAAC;AAClC,OAAO,EAAC,UAAU,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AACrD,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAC,aAAa,EAAkC,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAC,uBAAuB,EAAC,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAEhD,SAAS,IAAI,CAAC,KAAU,EAAE,QAA4B;IACpD,IAAI;QACF,OAAO,WAAW,CAAC,KAAK,EAAE;YACxB,IAAI,EAAE,QAAQ,CAAC,IAAI;SACpB,CAAC,CAAC;KACJ;IAAC,OAAO,EAAE,EAAE;QACX,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAKD,IAAa,cAAc,GAA3B,MAAa,cAAc;IAGzB,YAAY,QAAyB;QACnC,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,YAAY,CAAC,CAAC;QAErG,IAAI,QAAQ,EAAE;YACZ,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;SACvD;IACH,CAAC;IAED,WAAW,CAAC,KAAU,EAAE,QAA4B;QAClD,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,OAAO,KAAK,CAAC;SACd;QAED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AAO,KAAK,CAAC;IACf,CAAC;IAES,eAAe,CAAC,KAAU,EAAE,QAA4B;QAChE,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAC9B,MAAM,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC9C;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzEY,cAAc;IAH1B,UAAU,CAAC;QACV,IAAI,EAAE,WAAW;KAClB,CAAC;qCAIsB,eAAe;GAH1B,cAAc,CAyE1B;SAzEY,cAAc","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {Injectable, InjectorService} from \"@tsed/di\";\nimport {deserialize} from \"@tsed/json-mapper\";\nimport {getJsonSchema, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {RequiredValidationError} from \"../errors/RequiredValidationError\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\n\nfunction cast(value: any, metadata: JsonParameterStore) {\n try {\n return deserialize(value, {\n type: metadata.type\n });\n } catch (er) {\n return value;\n }\n}\n\n@Injectable({\n type: \"validator\"\n})\nexport class ValidationPipe implements PipeMethods {\n private validator: {validate(value: any, options: any): Promise<any>};\n\n constructor(injector: InjectorService) {\n const provider = injector.getProviders().find((provider) => nameOf(provider.token) === \"AjvService\");\n\n if (provider) {\n this.validator = injector.invoke<any>(provider.token);\n }\n }\n\n coerceTypes(value: any, metadata: JsonParameterStore) {\n if (value === undefined) {\n return value;\n }\n\n if (value === \"null\") {\n return null;\n }\n\n if (metadata.isArray) {\n return [].concat(value);\n }\n\n if (metadata.isPrimitive) {\n return cast(value, metadata);\n }\n\n return value;\n }\n\n skip(value: any, metadata: JsonParameterStore) {\n return metadata.paramType === ParamTypes.PATH && !metadata.isPrimitive;\n }\n\n async transform(value: any, metadata: JsonParameterStore): Promise<any> {\n if (!this.validator) {\n this.checkIsRequired(value, metadata);\n return value;\n }\n\n if (this.skip(value, metadata)) {\n return value;\n }\n\n value = this.coerceTypes(value, metadata);\n\n this.checkIsRequired(value, metadata);\n\n if (value === undefined) {\n return value;\n }\n\n const schema = getJsonSchema(metadata, {\n customKeys: true\n });\n\n await this.validator.validate(value, {\n schema,\n type: metadata.isClass ? metadata.type : undefined,\n collectionType: metadata.collectionType\n });\n\n return value;\n }\n\n protected checkIsRequired(value: any, metadata: JsonParameterStore) {\n if (metadata.isRequired(value)) {\n throw RequiredValidationError.from(metadata);\n }\n\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"ValidationPipe.js","sourceRoot":"","sources":["../../../src/pipes/ValidationPipe.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,YAAY,CAAC;AAClC,OAAO,EAAC,UAAU,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AACrD,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAC,aAAa,EAAkC,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAC,uBAAuB,EAAC,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAEhD,SAAS,IAAI,CAAC,KAAU,EAAE,QAA4B;IACpD,IAAI;QACF,OAAO,WAAW,CAAC,KAAK,EAAE;YACxB,IAAI,EAAE,QAAQ,CAAC,IAAI;SACpB,CAAC,CAAC;KACJ;IAAC,OAAO,EAAE,EAAE;QACX,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAKD,IAAa,cAAc,GAA3B,MAAa,cAAc;IACjB,SAAS,CAAqD;IAEtE,YAAY,QAAyB;QACnC,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,YAAY,CAAC,CAAC;QAErG,IAAI,QAAQ,EAAE;YACZ,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAM,QAAQ,CAAC,KAA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CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YAClD,cAAc,EAAE,QAAQ,CAAC,cAAc;SACxC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;IAES,eAAe,CAAC,KAAU,EAAE,QAA4B;QAChE,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAC9B,MAAM,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC9C;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzEY,cAAc;IAH1B,UAAU,CAAC;QACV,IAAI,EAAE,WAAW;KAClB,CAAC;qCAIsB,eAAe;GAH1B,cAAc,CAyE1B;SAzEY,cAAc","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {Injectable, InjectorService} from \"@tsed/di\";\nimport {deserialize} from \"@tsed/json-mapper\";\nimport {getJsonSchema, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {RequiredValidationError} from \"../errors/RequiredValidationError\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\n\nfunction cast(value: any, metadata: JsonParameterStore) {\n try {\n return deserialize(value, {\n type: metadata.type\n });\n } catch (er) {\n return value;\n }\n}\n\n@Injectable({\n type: \"validator\"\n})\nexport class ValidationPipe implements PipeMethods {\n private validator: {validate(value: any, options: any): Promise<any>};\n\n constructor(injector: InjectorService) {\n const provider = injector.getProviders().find((provider) => nameOf(provider.token) === \"AjvService\");\n\n if (provider) {\n this.validator = injector.invoke<any>(provider.token);\n }\n }\n\n coerceTypes(value: any, metadata: JsonParameterStore) {\n if (value === undefined) {\n return value;\n }\n\n if (value === \"null\") {\n return null;\n }\n\n if (metadata.isArray) {\n return [].concat(value);\n }\n\n if (metadata.isPrimitive) {\n return cast(value, metadata);\n }\n\n return value;\n }\n\n skip(value: any, metadata: JsonParameterStore) {\n return metadata.paramType === ParamTypes.PATH && !metadata.isPrimitive;\n }\n\n async transform(value: any, metadata: JsonParameterStore): Promise<any> {\n if (!this.validator) {\n this.checkIsRequired(value, metadata);\n return value;\n }\n\n if (this.skip(value, metadata)) {\n return value;\n }\n\n value = this.coerceTypes(value, metadata);\n\n this.checkIsRequired(value, metadata);\n\n if (value === undefined) {\n return value;\n }\n\n const schema = getJsonSchema(metadata, {\n customKeys: true\n });\n\n await this.validator.validate(value, {\n schema,\n type: metadata.isClass ? metadata.type : undefined,\n collectionType: metadata.collectionType\n });\n\n return value;\n }\n\n protected checkIsRequired(value: any, metadata: JsonParameterStore) {\n if (metadata.isRequired(value)) {\n throw RequiredValidationError.from(metadata);\n }\n\n return true;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/platform-params",
3
- "version": "6.114.15",
3
+ "version": "6.114.18",
4
4
  "description": "Params module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -17,24 +17,25 @@
17
17
  "build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
18
18
  "build:cjs": "tsc --build tsconfig.compile.json",
19
19
  "build:esm": "tsc --build tsconfig.compile.esm.json",
20
- "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\""
20
+ "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
21
+ "test": "cross-env NODE_ENV=test yarn jest --max-workers=2"
21
22
  },
22
23
  "dependencies": {
23
- "tslib": "2.3.1"
24
+ "tslib": "2.4.0"
24
25
  },
25
26
  "devDependencies": {
26
- "@tsed/core": "6.114.15",
27
- "@tsed/di": "6.114.15",
28
- "@tsed/exceptions": "6.114.15",
29
- "@tsed/json-mapper": "6.114.15",
30
- "@tsed/schema": "6.114.15"
27
+ "@tsed/core": "6.114.18",
28
+ "@tsed/di": "6.114.18",
29
+ "@tsed/exceptions": "6.114.18",
30
+ "@tsed/json-mapper": "6.114.18",
31
+ "@tsed/schema": "6.114.18"
31
32
  },
32
33
  "peerDependencies": {
33
- "@tsed/core": "^6.114.15",
34
- "@tsed/di": "^6.114.15",
35
- "@tsed/exceptions": "^6.114.15",
36
- "@tsed/json-mapper": "^6.114.15",
37
- "@tsed/schema": "^6.114.15"
34
+ "@tsed/core": "^6.114.18",
35
+ "@tsed/di": "^6.114.18",
36
+ "@tsed/exceptions": "^6.114.18",
37
+ "@tsed/json-mapper": "^6.114.18",
38
+ "@tsed/schema": "^6.114.18"
38
39
  },
39
40
  "peerDependenciesMeta": {
40
41
  "@tsed/core": {