@tsed/platform-params 7.0.0-beta.11 → 7.0.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.js +14 -0
- package/lib/cjs/builder/PlatformParams.js +22 -30
- package/lib/cjs/builder/PlatformParams.js.map +1 -1
- package/lib/cjs/decorators/useParamType.js +1 -2
- package/lib/cjs/decorators/useParamType.js.map +1 -1
- package/lib/cjs/errors/ParamValidationError.js +3 -4
- package/lib/cjs/errors/ParamValidationError.js.map +1 -1
- package/lib/cjs/errors/RequiredValidationError.js +1 -4
- package/lib/cjs/errors/RequiredValidationError.js.map +1 -1
- package/lib/cjs/errors/ValidationError.js +2 -1
- package/lib/cjs/errors/ValidationError.js.map +1 -1
- package/lib/cjs/pipes/DeserializerPipe.js +1 -0
- package/lib/cjs/pipes/DeserializerPipe.js.map +1 -1
- package/lib/cjs/pipes/ParseExpressionPipe.js.map +1 -1
- package/lib/cjs/pipes/ValidationPipe.js +1 -0
- package/lib/cjs/pipes/ValidationPipe.js.map +1 -1
- package/lib/esm/builder/PlatformParams.js +23 -31
- package/lib/esm/builder/PlatformParams.js.map +1 -1
- package/lib/esm/decorators/useParamType.js +1 -2
- package/lib/esm/decorators/useParamType.js.map +1 -1
- package/lib/esm/errors/ParamValidationError.js +3 -4
- package/lib/esm/errors/ParamValidationError.js.map +1 -1
- package/lib/esm/errors/RequiredValidationError.js +1 -4
- package/lib/esm/errors/RequiredValidationError.js.map +1 -1
- package/lib/esm/errors/ValidationError.js +2 -1
- package/lib/esm/errors/ValidationError.js.map +1 -1
- package/lib/esm/pipes/DeserializerPipe.js +1 -0
- package/lib/esm/pipes/DeserializerPipe.js.map +1 -1
- package/lib/esm/pipes/ParseExpressionPipe.js.map +1 -1
- package/lib/esm/pipes/ValidationPipe.js +1 -0
- package/lib/esm/pipes/ValidationPipe.js.map +1 -1
- package/lib/types/builder/PlatformParams.d.ts +15 -13
- package/lib/types/pipes/ParseExpressionPipe.d.ts +2 -2
- package/package.json +18 -14
- package/readme.md +2 -1
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,37 @@ const ParseExpressionPipe_1 = require("../pipes/ParseExpressionPipe");
|
|
|
11
11
|
* @platform
|
|
12
12
|
*/
|
|
13
13
|
let PlatformParams = class PlatformParams {
|
|
14
|
-
|
|
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.
|
|
20
|
-
|
|
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
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Return a handler with injectable parameters
|
|
25
|
+
* @param handlerMetadata
|
|
26
|
+
*/
|
|
27
|
+
compileHandler({ propertyKey, token }) {
|
|
28
|
+
const store = schema_1.JsonMethodStore.fromMethod(token, propertyKey);
|
|
29
|
+
const getArguments = this.compile(store);
|
|
30
|
+
return async (scope) => {
|
|
31
|
+
const [instance, args] = await Promise.all([this.injector.invoke(token, scope.$ctx.container), getArguments(scope)]);
|
|
32
|
+
return instance[propertyKey].call(instance, ...args, scope.$ctx);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
compile(entity) {
|
|
24
36
|
const params = schema_1.JsonParameterStore.getParams(entity.target, entity.propertyKey);
|
|
25
|
-
const argsPipes =
|
|
37
|
+
const argsPipes = params.map((param) => {
|
|
26
38
|
return {
|
|
27
39
|
param,
|
|
28
|
-
pipes:
|
|
40
|
+
pipes: this.getPipes(param)
|
|
29
41
|
};
|
|
30
|
-
})
|
|
42
|
+
});
|
|
31
43
|
return (scope) => {
|
|
32
|
-
const promises = argsPipes.map(({ param, pipes }) =>
|
|
33
|
-
return this.getArg(scope, pipes, param);
|
|
34
|
-
});
|
|
44
|
+
const promises = argsPipes.map(({ param, pipes }) => this.getArg(scope, pipes, param));
|
|
35
45
|
return Promise.all(promises);
|
|
36
46
|
};
|
|
37
47
|
}
|
|
@@ -46,24 +56,6 @@ let PlatformParams = class PlatformParams {
|
|
|
46
56
|
}
|
|
47
57
|
}, scope);
|
|
48
58
|
}
|
|
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
59
|
};
|
|
68
60
|
tslib_1.__decorate([
|
|
69
61
|
(0, di_1.Inject)(),
|
|
@@ -72,7 +64,7 @@ tslib_1.__decorate([
|
|
|
72
64
|
PlatformParams = tslib_1.__decorate([
|
|
73
65
|
(0, di_1.Injectable)({
|
|
74
66
|
scope: di_1.ProviderScope.SINGLETON,
|
|
75
|
-
imports: []
|
|
67
|
+
imports: [ParseExpressionPipe_1.ParseExpressionPipe]
|
|
76
68
|
})
|
|
77
69
|
], PlatformParams);
|
|
78
70
|
exports.PlatformParams = PlatformParams;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformParams.js","sourceRoot":"","sources":["../../../src/builder/PlatformParams.ts"],"names":[],"mappings":";;;;AAAA,iCAAsG;AACtG,yCAA8E;AAC9E,yEAAoE;AACpE,sEAAiE;
|
|
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,C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CAAC;QAEH,OAAO,CAAC,KAAK,EAAE,EAAE;YACf,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,EAAC,KAAK,EAAE,KAAK,EAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;YACrF,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAwC,KAA0B,EAAE,KAAoB,EAAE,KAAyB;QAC7H,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,KAAyB,EAAE,IAAI,EAAE,EAAE;YAC5D,KAAK,GAAG,MAAM,KAAK,CAAC;YAEpB,IAAI;gBACF,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;aAC3C;YAAC,OAAO,EAAE,EAAE;gBACX,MAAM,2CAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;aAC5C;QACH,CAAC,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC;CACF,CAAA;AA5DC;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;gDAAC;AAFzB,cAAc;IAJ1B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,yCAAmB,CAAC;KAC/B,CAAC;GACW,cAAc,CA8D1B;AA9DY,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 }: {\n propertyKey: string | symbol;\n token: any;\n }): PlatformParamsCallback<Context> {\n const store = JsonMethodStore.fromMethod(token, propertyKey);\n const getArguments = this.compile<Context>(store);\n\n return async (scope: PlatformParamsScope) => {\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 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
|
-
|
|
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
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
|
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
|
-
|
|
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;
|
|
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;
|
|
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;
|
|
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;
|
|
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;
|
|
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,OA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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,6 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Inject, Injectable, InjectorService, ProviderScope } from "@tsed/di";
|
|
3
|
-
import {
|
|
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,37 @@ import { ParseExpressionPipe } from "../pipes/ParseExpressionPipe.js";
|
|
|
8
8
|
* @platform
|
|
9
9
|
*/
|
|
10
10
|
let PlatformParams = class PlatformParams {
|
|
11
|
-
|
|
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.
|
|
17
|
-
|
|
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
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Return a handler with injectable parameters
|
|
22
|
+
* @param handlerMetadata
|
|
23
|
+
*/
|
|
24
|
+
compileHandler({ propertyKey, token }) {
|
|
25
|
+
const store = JsonMethodStore.fromMethod(token, propertyKey);
|
|
26
|
+
const getArguments = this.compile(store);
|
|
27
|
+
return async (scope) => {
|
|
28
|
+
const [instance, args] = await Promise.all([this.injector.invoke(token, scope.$ctx.container), getArguments(scope)]);
|
|
29
|
+
return instance[propertyKey].call(instance, ...args, scope.$ctx);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
compile(entity) {
|
|
21
33
|
const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);
|
|
22
|
-
const argsPipes =
|
|
34
|
+
const argsPipes = params.map((param) => {
|
|
23
35
|
return {
|
|
24
36
|
param,
|
|
25
|
-
pipes:
|
|
37
|
+
pipes: this.getPipes(param)
|
|
26
38
|
};
|
|
27
|
-
})
|
|
39
|
+
});
|
|
28
40
|
return (scope) => {
|
|
29
|
-
const promises = argsPipes.map(({ param, pipes }) =>
|
|
30
|
-
return this.getArg(scope, pipes, param);
|
|
31
|
-
});
|
|
41
|
+
const promises = argsPipes.map(({ param, pipes }) => this.getArg(scope, pipes, param));
|
|
32
42
|
return Promise.all(promises);
|
|
33
43
|
};
|
|
34
44
|
}
|
|
@@ -43,24 +53,6 @@ let PlatformParams = class PlatformParams {
|
|
|
43
53
|
}
|
|
44
54
|
}, scope);
|
|
45
55
|
}
|
|
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
56
|
};
|
|
65
57
|
__decorate([
|
|
66
58
|
Inject(),
|
|
@@ -69,7 +61,7 @@ __decorate([
|
|
|
69
61
|
PlatformParams = __decorate([
|
|
70
62
|
Injectable({
|
|
71
63
|
scope: ProviderScope.SINGLETON,
|
|
72
|
-
imports: []
|
|
64
|
+
imports: [ParseExpressionPipe]
|
|
73
65
|
})
|
|
74
66
|
], PlatformParams);
|
|
75
67
|
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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AI,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;YACrF,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAwC,KAA0B,EAAE,KAAoB,EAAE,KAAyB;QAC7H,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,KAAyB,EAAE,IAAI,EAAE,EAAE;YAC5D,KAAK,GAAG,MAAM,KAAK,CAAC;YAEpB,IAAI;gBACF,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;aAC3C;YAAC,OAAO,EAAE,EAAE;gBACX,MAAM,oBAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;aAC5C;QACH,CAAC,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC;CACF,CAAA;AA5DC;IADC,MAAM,EAAE;8BACW,eAAe;gDAAC;AAFzB,cAAc;IAJ1B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,mBAAmB,CAAC;KAC/B,CAAC;GACW,cAAc,CA8D1B;SA9DY,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 }: {\n propertyKey: string | symbol;\n token: any;\n }): PlatformParamsCallback<Context> {\n const store = JsonMethodStore.fromMethod(token, propertyKey);\n const getArguments = this.compile<Context>(store);\n\n return async (scope: PlatformParamsScope) => {\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 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
|
-
|
|
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
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
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
|
-
|
|
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;
|
|
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 +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;
|
|
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;
|
|
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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AAC,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"]}
|
|
@@ -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,E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AAE,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,22 +1,24 @@
|
|
|
1
|
-
import { DIContext, InjectorService
|
|
2
|
-
import {
|
|
3
|
-
export declare type
|
|
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
|
|
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):
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 }: {
|
|
19
|
+
propertyKey: string | symbol;
|
|
20
|
+
token: any;
|
|
21
|
+
}): PlatformParamsCallback<Context>;
|
|
22
|
+
compile<Context extends DIContext = DIContext>(entity: JsonMethodStore): PlatformParamsCallback<Context>;
|
|
23
|
+
getArg<Context extends DIContext = DIContext>(scope: PlatformParamsScope, pipes: PipeMethods[], param: JsonParameterStore): Promise<any>;
|
|
22
24
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JsonParameterStore, PipeMethods } from "@tsed/schema";
|
|
2
|
-
import
|
|
2
|
+
import { PlatformParamsScope } from "../builder/PlatformParams";
|
|
3
3
|
export declare class ParseExpressionPipe implements PipeMethods {
|
|
4
|
-
transform(scope:
|
|
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.
|
|
3
|
+
"version": "7.0.0-beta.14",
|
|
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.
|
|
24
|
+
"tslib": "2.4.0"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@tsed/core": "7.0.0-beta.
|
|
27
|
-
"@tsed/di": "7.0.0-beta.
|
|
28
|
-
"@tsed/exceptions": "7.0.0-beta.
|
|
29
|
-
"@tsed/json-mapper": "7.0.0-beta.
|
|
30
|
-
"@tsed/schema": "7.0.0-beta.
|
|
27
|
+
"@tsed/core": "7.0.0-beta.14",
|
|
28
|
+
"@tsed/di": "7.0.0-beta.14",
|
|
29
|
+
"@tsed/exceptions": "7.0.0-beta.14",
|
|
30
|
+
"@tsed/json-mapper": "7.0.0-beta.14",
|
|
31
|
+
"@tsed/schema": "7.0.0-beta.14"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
|
-
"@tsed/core": "^7.0.0-beta.
|
|
34
|
-
"@tsed/di": "^7.0.0-beta.
|
|
35
|
-
"@tsed/exceptions": "^7.0.0-beta.
|
|
36
|
-
"@tsed/json-mapper": "^7.0.0-beta.
|
|
37
|
-
"@tsed/schema": "^7.0.0-beta.
|
|
34
|
+
"@tsed/core": "^7.0.0-beta.14",
|
|
35
|
+
"@tsed/di": "^7.0.0-beta.14",
|
|
36
|
+
"@tsed/exceptions": "^7.0.0-beta.14",
|
|
37
|
+
"@tsed/json-mapper": "^7.0.0-beta.14",
|
|
38
|
+
"@tsed/schema": "^7.0.0-beta.14"
|
|
38
39
|
},
|
|
39
40
|
"peerDependenciesMeta": {
|
|
40
41
|
"@tsed/core": {
|
|
@@ -59,5 +60,8 @@
|
|
|
59
60
|
},
|
|
60
61
|
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/platform/platform-params",
|
|
61
62
|
"author": "Romain Lenzotti",
|
|
62
|
-
"license": "MIT"
|
|
63
|
+
"license": "MIT",
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"tag": "beta"
|
|
66
|
+
}
|
|
63
67
|
}
|
package/readme.md
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
[](https://badge.fury.io/js/%40tsed%2Fcommon)
|
|
12
12
|
[](https://github.com/semantic-release/semantic-release)
|
|
13
13
|
[](https://github.com/prettier/prettier)
|
|
14
|
-
[](https://github.com/sponsors/romakita)
|
|
15
|
+
[](https://opencollective.com/tsed)
|
|
15
16
|
|
|
16
17
|
</div>
|
|
17
18
|
|