@tsed/platform-params 7.0.0-beta.9 → 7.0.0-rc.3

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 (35) hide show
  1. package/jest.config.js +14 -0
  2. package/lib/cjs/builder/PlatformParams.js +27 -30
  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/ParseExpressionPipe.js.map +1 -1
  15. package/lib/cjs/pipes/ValidationPipe.js +1 -0
  16. package/lib/cjs/pipes/ValidationPipe.js.map +1 -1
  17. package/lib/esm/builder/PlatformParams.js +28 -31
  18. package/lib/esm/builder/PlatformParams.js.map +1 -1
  19. package/lib/esm/decorators/useParamType.js +1 -2
  20. package/lib/esm/decorators/useParamType.js.map +1 -1
  21. package/lib/esm/errors/ParamValidationError.js +3 -4
  22. package/lib/esm/errors/ParamValidationError.js.map +1 -1
  23. package/lib/esm/errors/RequiredValidationError.js +1 -4
  24. package/lib/esm/errors/RequiredValidationError.js.map +1 -1
  25. package/lib/esm/errors/ValidationError.js +2 -1
  26. package/lib/esm/errors/ValidationError.js.map +1 -1
  27. package/lib/esm/pipes/DeserializerPipe.js +1 -0
  28. package/lib/esm/pipes/DeserializerPipe.js.map +1 -1
  29. package/lib/esm/pipes/ParseExpressionPipe.js.map +1 -1
  30. package/lib/esm/pipes/ValidationPipe.js +1 -0
  31. package/lib/esm/pipes/ValidationPipe.js.map +1 -1
  32. package/lib/types/builder/PlatformParams.d.ts +16 -13
  33. package/lib/types/pipes/ParseExpressionPipe.d.ts +2 -2
  34. package/package.json +19 -15
  35. package/readme.md +3 -2
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.89,
9
+ branches: 73.19,
10
+ functions: 73.83,
11
+ lines: 89.43
12
+ }
13
+ }
14
+ };
@@ -11,27 +11,42 @@ const ParseExpressionPipe_1 = require("../pipes/ParseExpressionPipe");
11
11
  * @platform
12
12
  */
13
13
  let PlatformParams = class PlatformParams {
14
- async getPipes(param) {
14
+ injector;
15
+ getPipes(param) {
15
16
  const get = (pipe) => {
16
17
  return this.injector.getProvider(pipe).priority || 0;
17
18
  };
18
19
  const sort = (p1, p2) => (get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0);
19
- const map = (token) => this.injector.invoke(token);
20
- const promises = await Promise.all([ParseExpressionPipe_1.ParseExpressionPipe, ...param.pipes.sort(sort)].map(map));
21
- return promises.filter(Boolean);
20
+ const map = (token) => this.injector.get(token);
21
+ return [ParseExpressionPipe_1.ParseExpressionPipe, ...param.pipes.sort(sort)].map(map).filter(Boolean);
22
22
  }
23
- async compile(entity) {
23
+ /**
24
+ * Return a handler with injectable parameters
25
+ * @param handlerMetadata
26
+ */
27
+ compileHandler({ propertyKey, token, handler }) {
28
+ if (!token || !propertyKey) {
29
+ return (scope) => handler(scope.$ctx);
30
+ }
31
+ const store = schema_1.JsonMethodStore.fromMethod(token, propertyKey);
32
+ const getArguments = this.compile(store);
33
+ const provider = this.injector.getProvider(token);
34
+ return async (scope) => {
35
+ const container = provider.scope === di_1.ProviderScope.REQUEST ? scope.$ctx.container : undefined;
36
+ const [instance, args] = await Promise.all([this.injector.invoke(token, container), getArguments(scope)]);
37
+ return instance[propertyKey].call(instance, ...args, scope.$ctx);
38
+ };
39
+ }
40
+ compile(entity) {
24
41
  const params = schema_1.JsonParameterStore.getParams(entity.target, entity.propertyKey);
25
- const argsPipes = await Promise.all(params.map(async (param) => {
42
+ const argsPipes = params.map((param) => {
26
43
  return {
27
44
  param,
28
- pipes: await this.getPipes(param)
45
+ pipes: this.getPipes(param)
29
46
  };
30
- }));
47
+ });
31
48
  return (scope) => {
32
- const promises = argsPipes.map(({ param, pipes }) => {
33
- return this.getArg(scope, pipes, param);
34
- });
49
+ const promises = argsPipes.map(({ param, pipes }) => this.getArg(scope, pipes, param));
35
50
  return Promise.all(promises);
36
51
  };
37
52
  }
@@ -46,24 +61,6 @@ let PlatformParams = class PlatformParams {
46
61
  }
47
62
  }, scope);
48
63
  }
49
- async compileHandler(metadata) {
50
- const { token, propertyKey, getCustomArgs } = metadata;
51
- const provider = this.injector.getProvider(token);
52
- const getArguments = getCustomArgs || (await this.compile(schema_1.JsonEntityStore.fromMethod(token, propertyKey)));
53
- if (!provider || !provider.scope || provider.scope === di_1.ProviderScope.SINGLETON) {
54
- const instance = await this.injector.invoke(token);
55
- const handler = instance[propertyKey].bind(instance);
56
- return async (scope) => {
57
- const args = await getArguments(scope);
58
- return handler(...args, scope.$ctx);
59
- };
60
- }
61
- return async (scope) => {
62
- const [instance, args] = await Promise.all([this.injector.invoke(token, scope.$ctx.container), getArguments(scope)]);
63
- const handler = instance[propertyKey].bind(instance);
64
- return handler(...args, scope.$ctx);
65
- };
66
- }
67
64
  };
68
65
  tslib_1.__decorate([
69
66
  (0, di_1.Inject)(),
@@ -72,7 +69,7 @@ tslib_1.__decorate([
72
69
  PlatformParams = tslib_1.__decorate([
73
70
  (0, di_1.Injectable)({
74
71
  scope: di_1.ProviderScope.SINGLETON,
75
- imports: []
72
+ imports: [ParseExpressionPipe_1.ParseExpressionPipe]
76
73
  })
77
74
  ], PlatformParams);
78
75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Context, 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 const handler = instance[propertyKey!].bind(instance);\n\n return async (scope) => {\n const args = await getArguments(scope);\n\n return handler(...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 const handler = instance[propertyKey!].bind(instance);\n\n return handler(...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;AAKjE;;;GAGG;AAKH,IAAa,cAAc,GAA3B,MAAa,cAAc;IAEf,QAAQ,CAAkB;IAEpC,QAAQ,CAAC,KAAyB;QAChC,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,GAA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ACW,cAAc,CAsE1B;AAtEY,wCAAc","sourcesContent":["import {DIContext, Inject, Injectable, InjectorService, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport {JsonMethodStore, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {ParamValidationError} from \"../errors/ParamValidationError\";\nimport {ParseExpressionPipe} from \"../pipes/ParseExpressionPipe\";\n\nexport type PlatformParamsScope<Context extends DIContext = DIContext> = {$ctx: Context} & Record<string, any>;\nexport type PlatformParamsCallback<Context extends DIContext = DIContext> = (scope: PlatformParamsScope) => Promise<any>;\n\n/**\n * Platform Params abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [ParseExpressionPipe]\n})\nexport class PlatformParams {\n @Inject()\n protected injector: InjectorService;\n\n 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.get<PipeMethods>(token)!;\n\n return [ParseExpressionPipe, ...param.pipes.sort(sort)].map(map).filter(Boolean);\n }\n\n /**\n * Return a handler with injectable parameters\n * @param handlerMetadata\n */\n compileHandler<Context extends DIContext = DIContext>({\n propertyKey,\n token,\n handler\n }: {\n propertyKey?: string | symbol;\n token?: any;\n handler?: any;\n }): PlatformParamsCallback<Context> {\n if (!token || !propertyKey) {\n return (scope: PlatformParamsScope) => handler(scope.$ctx);\n }\n\n const store = JsonMethodStore.fromMethod(token, propertyKey);\n const getArguments = this.compile<Context>(store);\n const provider = this.injector.getProvider(token)!;\n\n return async (scope: PlatformParamsScope) => {\n const container = provider.scope === ProviderScope.REQUEST ? scope.$ctx.container : undefined;\n const [instance, args] = await Promise.all([this.injector.invoke<any>(token, container), getArguments(scope)]);\n\n return instance[propertyKey].call(instance, ...args, scope.$ctx);\n };\n }\n\n compile<Context extends DIContext = DIContext>(entity: JsonMethodStore): PlatformParamsCallback<Context> {\n const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);\n const argsPipes = params.map((param) => {\n return {\n param,\n pipes: this.getPipes(param)\n };\n });\n\n return (scope) => {\n const promises = argsPipes.map(({param, pipes}) => this.getArg(scope, pipes, param));\n return Promise.all(promises);\n };\n }\n\n async getArg<Context extends DIContext = DIContext>(scope: PlatformParamsScope, pipes: PipeMethods[], param: JsonParameterStore) {\n return pipes.reduce(async (value: any | Promise<any>, 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);\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ParseExpressionPipe.js","sourceRoot":"","sources":["../../../src/pipes/ParseExpressionPipe.ts"],"names":[],"mappings":";;;;AAAA,qCAAoC;AACpC,iCAAoC;AAEpC,qDAAgD;AAMhD,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAC9B,SAAS,CAAC,KAAe,EAAE,KAAyB;QAClD,MAAM,EAAC,SAAS,EAAE,IAAI,EAAC,GAAG,KAAK,CAAC;QAEhC,MAAM,KAAK,GAAG,IAAA,eAAQ,EAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAElD,IAAI,CAAC,uBAAU,CAAC,KAAK,EAAE,uBAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAuB,CAAC,IAAI,KAAK,KAAK,EAAE,IAAI,IAAI,KAAK,MAAM,EAAE;YAC5G,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAES,MAAM,CAAC,KAAyB;QACxC,IAAI,EAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAC,GAAG,KAAK,CAAC;QAC9C,SAAS,GAAG,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAEjE,IAAI,UAAU,IAAI,SAAS,KAAK,uBAAU,CAAC,MAAM,EAAE;YACjD,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;SAC/C;QAED,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;CACF,CAAA;AAvBY,mBAAmB;IAH/B,IAAA,eAAU,EAAC;QACV,QAAQ,EAAE,CAAC,IAAI;KAChB,CAAC;GACW,mBAAmB,CAuB/B;AAvBY,kDAAmB","sourcesContent":["import {getValue} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\nimport type {ArgScope} from \"../builder/PlatformParams\";\n\n@Injectable({\n priority: -1000\n})\nexport class ParseExpressionPipe implements PipeMethods {\n transform(scope: ArgScope, param: JsonParameterStore) {\n const {paramType, type} = param;\n\n const value = getValue(scope, this.getKey(param));\n\n if ([ParamTypes.QUERY, ParamTypes.PATH].includes(paramType as ParamTypes) && value === \"\" && type !== String) {\n return undefined;\n }\n\n return value;\n }\n\n protected getKey(param: JsonParameterStore) {\n let {expression, paramType, dataPath} = param;\n paramType = paramType || param.parameter.get(\"in\").toUpperCase();\n\n if (expression && paramType === ParamTypes.HEADER) {\n expression = String(expression).toLowerCase();\n }\n\n return [dataPath, expression].filter(Boolean).join(\".\");\n }\n}\n"]}
1
+ {"version":3,"file":"ParseExpressionPipe.js","sourceRoot":"","sources":["../../../src/pipes/ParseExpressionPipe.ts"],"names":[],"mappings":";;;;AAAA,qCAAoC;AACpC,iCAAoC;AAGpC,qDAAgD;AAKhD,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAC9B,SAAS,CAAC,KAA0B,EAAE,KAAyB;QAC7D,MAAM,EAAC,SAAS,EAAE,IAAI,EAAC,GAAG,KAAK,CAAC;QAEhC,MAAM,KAAK,GAAG,IAAA,eAAQ,EAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAElD,IAAI,CAAC,uBAAU,CAAC,KAAK,EAAE,uBAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAuB,CAAC,IAAI,KAAK,KAAK,EAAE,IAAI,IAAI,KAAK,MAAM,EAAE;YAC5G,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAES,MAAM,CAAC,KAAyB;QACxC,IAAI,EAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAC,GAAG,KAAK,CAAC;QAC9C,SAAS,GAAG,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAEjE,IAAI,UAAU,IAAI,SAAS,KAAK,uBAAU,CAAC,MAAM,EAAE;YACjD,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;SAC/C;QAED,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;CACF,CAAA;AAvBY,mBAAmB;IAH/B,IAAA,eAAU,EAAC;QACV,QAAQ,EAAE,CAAC,IAAI;KAChB,CAAC;GACW,mBAAmB,CAuB/B;AAvBY,kDAAmB","sourcesContent":["import {getValue} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {PlatformParamsScope} from \"../builder/PlatformParams\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\n\n@Injectable({\n priority: -1000\n})\nexport class ParseExpressionPipe implements PipeMethods {\n transform(scope: PlatformParamsScope, param: JsonParameterStore) {\n const {paramType, type} = param;\n\n const value = getValue(scope, this.getKey(param));\n\n if ([ParamTypes.QUERY, ParamTypes.PATH].includes(paramType as ParamTypes) && value === \"\" && type !== String) {\n return undefined;\n }\n\n return value;\n }\n\n protected getKey(param: JsonParameterStore) {\n let {expression, paramType, dataPath} = param;\n paramType = paramType || param.parameter.get(\"in\").toUpperCase();\n\n if (expression && paramType === ParamTypes.HEADER) {\n expression = String(expression).toLowerCase();\n }\n\n return [dataPath, expression].filter(Boolean).join(\".\");\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,qDAAgD;AAEhD,SAAS,IAAI,CAAC,KAAU,EAAE,QAA4B;IACpD,IAAI;QACF,OAAO,IAAA,yBAAW,EAAC,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,IAAA,aAAM,EAAC,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,IAAI,KAAK,KAAK,MAAM,EAAE;YACpB,OAAO,IAAI,CAAC;SACb;QAED,IAAI,QAAQ,CAAC,OAAO,EAAE;YACpB,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACzB;QAED,IAAI,QAAQ,CAAC,WAAW,EAAE;YACxB,OAAO,IAA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I,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,IAAA,yBAAW,EAAC,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,IAAA,aAAM,EAAC,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,IAAI,KAAK,KAAK,MAAM,EAAE;YACpB,OAAO,IAAI,CAAC;SACb;QAED,IAAI,QAAQ,CAAC,OAAO,EAAE;YACpB,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACzB;QAED,IAAI,QAAQ,CAAC,WAAW,EAAE;YACxB,OAAO,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;SAC9B;QAED,OAA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,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,6 +1,6 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { Inject, Injectable, InjectorService, ProviderScope } from "@tsed/di";
3
- import { JsonEntityStore, JsonParameterStore } from "@tsed/schema";
3
+ import { JsonMethodStore, JsonParameterStore } from "@tsed/schema";
4
4
  import { ParamValidationError } from "../errors/ParamValidationError.js";
5
5
  import { ParseExpressionPipe } from "../pipes/ParseExpressionPipe.js";
6
6
  /**
@@ -8,27 +8,42 @@ import { ParseExpressionPipe } from "../pipes/ParseExpressionPipe.js";
8
8
  * @platform
9
9
  */
10
10
  let PlatformParams = class PlatformParams {
11
- async getPipes(param) {
11
+ injector;
12
+ getPipes(param) {
12
13
  const get = (pipe) => {
13
14
  return this.injector.getProvider(pipe).priority || 0;
14
15
  };
15
16
  const sort = (p1, p2) => (get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0);
16
- const map = (token) => this.injector.invoke(token);
17
- const promises = await Promise.all([ParseExpressionPipe, ...param.pipes.sort(sort)].map(map));
18
- return promises.filter(Boolean);
17
+ const map = (token) => this.injector.get(token);
18
+ return [ParseExpressionPipe, ...param.pipes.sort(sort)].map(map).filter(Boolean);
19
19
  }
20
- async compile(entity) {
20
+ /**
21
+ * Return a handler with injectable parameters
22
+ * @param handlerMetadata
23
+ */
24
+ compileHandler({ propertyKey, token, handler }) {
25
+ if (!token || !propertyKey) {
26
+ return (scope) => handler(scope.$ctx);
27
+ }
28
+ const store = JsonMethodStore.fromMethod(token, propertyKey);
29
+ const getArguments = this.compile(store);
30
+ const provider = this.injector.getProvider(token);
31
+ return async (scope) => {
32
+ const container = provider.scope === ProviderScope.REQUEST ? scope.$ctx.container : undefined;
33
+ const [instance, args] = await Promise.all([this.injector.invoke(token, container), getArguments(scope)]);
34
+ return instance[propertyKey].call(instance, ...args, scope.$ctx);
35
+ };
36
+ }
37
+ compile(entity) {
21
38
  const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);
22
- const argsPipes = await Promise.all(params.map(async (param) => {
39
+ const argsPipes = params.map((param) => {
23
40
  return {
24
41
  param,
25
- pipes: await this.getPipes(param)
42
+ pipes: this.getPipes(param)
26
43
  };
27
- }));
44
+ });
28
45
  return (scope) => {
29
- const promises = argsPipes.map(({ param, pipes }) => {
30
- return this.getArg(scope, pipes, param);
31
- });
46
+ const promises = argsPipes.map(({ param, pipes }) => this.getArg(scope, pipes, param));
32
47
  return Promise.all(promises);
33
48
  };
34
49
  }
@@ -43,24 +58,6 @@ let PlatformParams = class PlatformParams {
43
58
  }
44
59
  }, scope);
45
60
  }
46
- async compileHandler(metadata) {
47
- const { token, propertyKey, getCustomArgs } = metadata;
48
- const provider = this.injector.getProvider(token);
49
- const getArguments = getCustomArgs || (await this.compile(JsonEntityStore.fromMethod(token, propertyKey)));
50
- if (!provider || !provider.scope || provider.scope === ProviderScope.SINGLETON) {
51
- const instance = await this.injector.invoke(token);
52
- const handler = instance[propertyKey].bind(instance);
53
- return async (scope) => {
54
- const args = await getArguments(scope);
55
- return handler(...args, scope.$ctx);
56
- };
57
- }
58
- return async (scope) => {
59
- const [instance, args] = await Promise.all([this.injector.invoke(token, scope.$ctx.container), getArguments(scope)]);
60
- const handler = instance[propertyKey].bind(instance);
61
- return handler(...args, scope.$ctx);
62
- };
63
- }
64
61
  };
65
62
  __decorate([
66
63
  Inject(),
@@ -69,7 +66,7 @@ __decorate([
69
66
  PlatformParams = __decorate([
70
67
  Injectable({
71
68
  scope: ProviderScope.SINGLETON,
72
- imports: []
69
+ imports: [ParseExpressionPipe]
73
70
  })
74
71
  ], PlatformParams);
75
72
  export { PlatformParams };
@@ -1 +1 @@
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,EAA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port {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 const handler = instance[propertyKey!].bind(instance);\n\n return async (scope) => {\n const args = await getArguments(scope);\n\n return handler(...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 const handler = instance[propertyKey!].bind(instance);\n\n return handler(...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;AAKjE;;;GAGG;AAKH,IAAa,cAAc,GAA3B,MAAa,cAAc;IAEf,QAAQ,CAAkB;IAEpC,QAAQ,CAAC,KAAyB;QAChC,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,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FzB,cAAc;IAJ1B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,mBAAmB,CAAC;KAC/B,CAAC;GACW,cAAc,CAsE1B;SAtEY,cAAc","sourcesContent":["import {DIContext, Inject, Injectable, InjectorService, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport {JsonMethodStore, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {ParamValidationError} from \"../errors/ParamValidationError\";\nimport {ParseExpressionPipe} from \"../pipes/ParseExpressionPipe\";\n\nexport type PlatformParamsScope<Context extends DIContext = DIContext> = {$ctx: Context} & Record<string, any>;\nexport type PlatformParamsCallback<Context extends DIContext = DIContext> = (scope: PlatformParamsScope) => Promise<any>;\n\n/**\n * Platform Params abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [ParseExpressionPipe]\n})\nexport class PlatformParams {\n @Inject()\n protected injector: InjectorService;\n\n 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.get<PipeMethods>(token)!;\n\n return [ParseExpressionPipe, ...param.pipes.sort(sort)].map(map).filter(Boolean);\n }\n\n /**\n * Return a handler with injectable parameters\n * @param handlerMetadata\n */\n compileHandler<Context extends DIContext = DIContext>({\n propertyKey,\n token,\n handler\n }: {\n propertyKey?: string | symbol;\n token?: any;\n handler?: any;\n }): PlatformParamsCallback<Context> {\n if (!token || !propertyKey) {\n return (scope: PlatformParamsScope) => handler(scope.$ctx);\n }\n\n const store = JsonMethodStore.fromMethod(token, propertyKey);\n const getArguments = this.compile<Context>(store);\n const provider = this.injector.getProvider(token)!;\n\n return async (scope: PlatformParamsScope) => {\n const container = provider.scope === ProviderScope.REQUEST ? scope.$ctx.container : undefined;\n const [instance, args] = await Promise.all([this.injector.invoke<any>(token, container), getArguments(scope)]);\n\n return instance[propertyKey].call(instance, ...args, scope.$ctx);\n };\n }\n\n compile<Context extends DIContext = DIContext>(entity: JsonMethodStore): PlatformParamsCallback<Context> {\n const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);\n const argsPipes = params.map((param) => {\n return {\n param,\n pipes: this.getPipes(param)\n };\n });\n\n return (scope) => {\n const promises = argsPipes.map(({param, pipes}) => this.getArg(scope, pipes, param));\n return Promise.all(promises);\n };\n }\n\n async getArg<Context extends DIContext = DIContext>(scope: PlatformParamsScope, pipes: PipeMethods[], param: JsonParameterStore) {\n return pipes.reduce(async (value: any | Promise<any>, 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);\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ParseExpressionPipe.js","sourceRoot":"","sources":["../../../src/pipes/ParseExpressionPipe.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAMhD,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAC9B,SAAS,CAAC,KAAe,EAAE,KAAyB;QAClD,MAAM,EAAC,SAAS,EAAE,IAAI,EAAC,GAAG,KAAK,CAAC;QAEhC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAElD,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAuB,CAAC,IAAI,KAAK,KAAK,EAAE,IAAI,IAAI,KAAK,MAAM,EAAE;YAC5G,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAES,MAAM,CAAC,KAAyB;QACxC,IAAI,EAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAC,GAAG,KAAK,CAAC;QAC9C,SAAS,GAAG,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAEjE,IAAI,UAAU,IAAI,SAAS,KAAK,UAAU,CAAC,MAAM,EAAE;YACjD,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;SAC/C;QAED,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;CACF,CAAA;AAvBY,mBAAmB;IAH/B,UAAU,CAAC;QACV,QAAQ,EAAE,CAAC,IAAI;KAChB,CAAC;GACW,mBAAmB,CAuB/B;SAvBY,mBAAmB","sourcesContent":["import {getValue} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\nimport type {ArgScope} from \"../builder/PlatformParams\";\n\n@Injectable({\n priority: -1000\n})\nexport class ParseExpressionPipe implements PipeMethods {\n transform(scope: ArgScope, param: JsonParameterStore) {\n const {paramType, type} = param;\n\n const value = getValue(scope, this.getKey(param));\n\n if ([ParamTypes.QUERY, ParamTypes.PATH].includes(paramType as ParamTypes) && value === \"\" && type !== String) {\n return undefined;\n }\n\n return value;\n }\n\n protected getKey(param: JsonParameterStore) {\n let {expression, paramType, dataPath} = param;\n paramType = paramType || param.parameter.get(\"in\").toUpperCase();\n\n if (expression && paramType === ParamTypes.HEADER) {\n expression = String(expression).toLowerCase();\n }\n\n return [dataPath, expression].filter(Boolean).join(\".\");\n }\n}\n"]}
1
+ {"version":3,"file":"ParseExpressionPipe.js","sourceRoot":"","sources":["../../../src/pipes/ParseExpressionPipe.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAKhD,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAC9B,SAAS,CAAC,KAA0B,EAAE,KAAyB;QAC7D,MAAM,EAAC,SAAS,EAAE,IAAI,EAAC,GAAG,KAAK,CAAC;QAEhC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAElD,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAuB,CAAC,IAAI,KAAK,KAAK,EAAE,IAAI,IAAI,KAAK,MAAM,EAAE;YAC5G,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAES,MAAM,CAAC,KAAyB;QACxC,IAAI,EAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAC,GAAG,KAAK,CAAC;QAC9C,SAAS,GAAG,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAEjE,IAAI,UAAU,IAAI,SAAS,KAAK,UAAU,CAAC,MAAM,EAAE;YACjD,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;SAC/C;QAED,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;CACF,CAAA;AAvBY,mBAAmB;IAH/B,UAAU,CAAC;QACV,QAAQ,EAAE,CAAC,IAAI;KAChB,CAAC;GACW,mBAAmB,CAuB/B;SAvBY,mBAAmB","sourcesContent":["import {getValue} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {PlatformParamsScope} from \"../builder/PlatformParams\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\n\n@Injectable({\n priority: -1000\n})\nexport class ParseExpressionPipe implements PipeMethods {\n transform(scope: PlatformParamsScope, param: JsonParameterStore) {\n const {paramType, type} = param;\n\n const value = getValue(scope, this.getKey(param));\n\n if ([ParamTypes.QUERY, ParamTypes.PATH].includes(paramType as ParamTypes) && value === \"\" && type !== String) {\n return undefined;\n }\n\n return value;\n }\n\n protected getKey(param: JsonParameterStore) {\n let {expression, paramType, dataPath} = param;\n paramType = paramType || param.parameter.get(\"in\").toUpperCase();\n\n if (expression && paramType === ParamTypes.HEADER) {\n expression = String(expression).toLowerCase();\n }\n\n return [dataPath, expression].filter(Boolean).join(\".\");\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,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\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,EA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,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,22 +1,25 @@
1
- import { DIContext, InjectorService, TokenProvider } from "@tsed/di";
2
- import { JsonEntityStore, JsonParameterStore, PipeMethods } from "@tsed/schema";
3
- export declare type ArgScope<Context extends DIContext = DIContext> = {
1
+ import { DIContext, InjectorService } from "@tsed/di";
2
+ import { JsonMethodStore, JsonParameterStore, PipeMethods } from "@tsed/schema";
3
+ export declare type PlatformParamsScope<Context extends DIContext = DIContext> = {
4
4
  $ctx: Context;
5
5
  } & Record<string, any>;
6
- export declare type HandlerWithScope<Context extends DIContext = DIContext> = (scope: ArgScope<Context>) => any;
7
- export interface CompileHandlerOptions<Context extends DIContext = DIContext> extends Record<any, unknown> {
8
- token: TokenProvider;
9
- propertyKey: string | symbol;
10
- getCustomArgs?: (scope: ArgScope<Context>) => Promise<any[]>;
11
- }
6
+ export declare type PlatformParamsCallback<Context extends DIContext = DIContext> = (scope: PlatformParamsScope) => Promise<any>;
12
7
  /**
13
8
  * Platform Params abstraction layer.
14
9
  * @platform
15
10
  */
16
11
  export declare class PlatformParams {
17
12
  protected injector: InjectorService;
18
- getPipes(param: JsonParameterStore): Promise<PipeMethods<any, any>[]>;
19
- compile<Context extends DIContext = DIContext>(entity: JsonEntityStore): Promise<(scope: ArgScope<Context>) => Promise<any[]>>;
20
- getArg(scope: ArgScope, pipes: PipeMethods[], param: JsonParameterStore): Promise<any>;
21
- compileHandler<Context extends DIContext = DIContext>(metadata: CompileHandlerOptions<Context>): Promise<HandlerWithScope<Context>>;
13
+ getPipes(param: JsonParameterStore): PipeMethods<any, any>[];
14
+ /**
15
+ * Return a handler with injectable parameters
16
+ * @param handlerMetadata
17
+ */
18
+ compileHandler<Context extends DIContext = DIContext>({ propertyKey, token, handler }: {
19
+ propertyKey?: string | symbol;
20
+ token?: any;
21
+ handler?: any;
22
+ }): PlatformParamsCallback<Context>;
23
+ compile<Context extends DIContext = DIContext>(entity: JsonMethodStore): PlatformParamsCallback<Context>;
24
+ getArg<Context extends DIContext = DIContext>(scope: PlatformParamsScope, pipes: PipeMethods[], param: JsonParameterStore): Promise<any>;
22
25
  }
@@ -1,6 +1,6 @@
1
1
  import { JsonParameterStore, PipeMethods } from "@tsed/schema";
2
- import type { ArgScope } from "../builder/PlatformParams";
2
+ import { PlatformParamsScope } from "../builder/PlatformParams";
3
3
  export declare class ParseExpressionPipe implements PipeMethods {
4
- transform(scope: ArgScope, param: JsonParameterStore): any;
4
+ transform(scope: PlatformParamsScope, param: JsonParameterStore): any;
5
5
  protected getKey(param: JsonParameterStore): string;
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/platform-params",
3
- "version": "7.0.0-beta.9",
3
+ "version": "7.0.0-rc.3",
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": "7.0.0-beta.9",
27
- "@tsed/di": "7.0.0-beta.9",
28
- "@tsed/exceptions": "7.0.0-beta.9",
29
- "@tsed/json-mapper": "7.0.0-beta.9",
30
- "@tsed/schema": "7.0.0-beta.9"
27
+ "@tsed/core": "7.0.0-rc.3",
28
+ "@tsed/di": "7.0.0-rc.3",
29
+ "@tsed/exceptions": "7.0.0-rc.3",
30
+ "@tsed/json-mapper": "7.0.0-rc.3",
31
+ "@tsed/schema": "7.0.0-rc.3"
31
32
  },
32
33
  "peerDependencies": {
33
- "@tsed/core": "^7.0.0-beta.9",
34
- "@tsed/di": "^7.0.0-beta.9",
35
- "@tsed/exceptions": "^7.0.0-beta.9",
36
- "@tsed/json-mapper": "^7.0.0-beta.9",
37
- "@tsed/schema": "^7.0.0-beta.9"
34
+ "@tsed/core": "^7.0.0-rc.3",
35
+ "@tsed/di": "^7.0.0-rc.3",
36
+ "@tsed/exceptions": "^7.0.0-rc.3",
37
+ "@tsed/json-mapper": "^7.0.0-rc.3",
38
+ "@tsed/schema": "^7.0.0-rc.3"
38
39
  },
39
40
  "peerDependenciesMeta": {
40
41
  "@tsed/core": {
@@ -57,7 +58,10 @@
57
58
  "bugs": {
58
59
  "url": "https://github.com/tsedio/tsed/issues"
59
60
  },
60
- "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/platform/platform-params",
61
+ "homepage": "https://github.com/tsedio/tsed/tree/rc/packages/platform/platform-params",
61
62
  "author": "Romain Lenzotti",
62
- "license": "MIT"
63
+ "license": "MIT",
64
+ "publishConfig": {
65
+ "tag": "rc"
66
+ }
63
67
  }
package/readme.md CHANGED
@@ -11,7 +11,8 @@
11
11
  [![npm version](https://badge.fury.io/js/%40tsed%2Fcommon.svg)](https://badge.fury.io/js/%40tsed%2Fcommon)
12
12
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
13
13
  [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
14
- [![backers](https://opencollective.com/tsed/tiers/badge.svg)](https://opencollective.com/tsed)
14
+ [![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita)
15
+ [![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](https://opencollective.com/tsed)
15
16
 
16
17
  </div>
17
18
 
@@ -55,7 +56,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
55
56
 
56
57
  The MIT License (MIT)
57
58
 
58
- Copyright (c) 2016 - 2018 Romain Lenzotti
59
+ Copyright (c) 2016 - 2022 Romain Lenzotti
59
60
 
60
61
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
61
62