@tsed/platform-params 7.0.0-alpha.1 → 7.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/builder/PlatformParams.js +79 -0
- package/lib/cjs/builder/PlatformParams.js.map +1 -0
- package/lib/cjs/decorators/bodyParams.js +46 -0
- package/lib/cjs/decorators/bodyParams.js.map +1 -0
- package/lib/cjs/decorators/context.js +18 -0
- package/lib/cjs/decorators/context.js.map +1 -0
- package/lib/cjs/decorators/cookies.js +23 -0
- package/lib/cjs/decorators/cookies.js.map +1 -0
- package/lib/cjs/decorators/headerParams.js +18 -0
- package/lib/cjs/decorators/headerParams.js.map +1 -0
- package/lib/cjs/decorators/locals.js +18 -0
- package/lib/cjs/decorators/locals.js.map +1 -0
- package/lib/cjs/decorators/paramFn.js +17 -0
- package/lib/cjs/decorators/paramFn.js.map +1 -0
- package/lib/cjs/decorators/pathParams.js +54 -0
- package/lib/cjs/decorators/pathParams.js.map +1 -0
- package/lib/cjs/decorators/queryParams.js +54 -0
- package/lib/cjs/decorators/queryParams.js.map +1 -0
- package/lib/cjs/decorators/session.js +18 -0
- package/lib/cjs/decorators/session.js.map +1 -0
- package/lib/cjs/decorators/useDeserialization.js +18 -0
- package/lib/cjs/decorators/useDeserialization.js.map +1 -0
- package/lib/cjs/decorators/useParam.js +50 -0
- package/lib/cjs/decorators/useParam.js.map +1 -0
- package/lib/cjs/decorators/useParamExpression.js +20 -0
- package/lib/cjs/decorators/useParamExpression.js.map +1 -0
- package/lib/cjs/decorators/useParamType.js +32 -0
- package/lib/cjs/decorators/useParamType.js.map +1 -0
- package/lib/cjs/decorators/usePipe.js +22 -0
- package/lib/cjs/decorators/usePipe.js.map +1 -0
- package/lib/cjs/decorators/useType.js +20 -0
- package/lib/cjs/decorators/useType.js.map +1 -0
- package/lib/cjs/decorators/useValidation.js +22 -0
- package/lib/cjs/decorators/useValidation.js.map +1 -0
- package/lib/cjs/domain/ParamMetadata.js +6 -0
- package/lib/cjs/domain/ParamMetadata.js.map +1 -0
- package/lib/cjs/domain/ParamOptions.js +3 -0
- package/lib/cjs/domain/ParamOptions.js.map +1 -0
- package/lib/cjs/domain/ParamTypes.js +40 -0
- package/lib/cjs/domain/ParamTypes.js.map +1 -0
- package/lib/cjs/errors/ParamValidationError.js +29 -0
- package/lib/cjs/errors/ParamValidationError.js.map +1 -0
- package/lib/cjs/errors/RequiredValidationError.js +32 -0
- package/lib/cjs/errors/RequiredValidationError.js.map +1 -0
- package/lib/cjs/errors/ValidationError.js +13 -0
- package/lib/cjs/errors/ValidationError.js.map +1 -0
- package/lib/cjs/exports.js +3 -0
- package/lib/cjs/exports.js.map +1 -0
- package/lib/cjs/index.js +35 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/pipes/DeserializerPipe.js +30 -0
- package/lib/cjs/pipes/DeserializerPipe.js.map +1 -0
- package/lib/cjs/pipes/ParseExpressionPipe.js +32 -0
- package/lib/cjs/pipes/ParseExpressionPipe.js.map +1 -0
- package/lib/cjs/pipes/ValidationPipe.js +83 -0
- package/lib/cjs/pipes/ValidationPipe.js.map +1 -0
- package/lib/cjs/utils/mapParamsOptions.js +30 -0
- package/lib/cjs/utils/mapParamsOptions.js.map +1 -0
- package/lib/esm/builder/PlatformParams.js +76 -0
- package/lib/esm/builder/PlatformParams.js.map +1 -0
- package/lib/esm/decorators/bodyParams.js +41 -0
- package/lib/esm/decorators/bodyParams.js.map +1 -0
- package/lib/esm/decorators/context.js +14 -0
- package/lib/esm/decorators/context.js.map +1 -0
- package/lib/esm/decorators/cookies.js +18 -0
- package/lib/esm/decorators/cookies.js.map +1 -0
- package/lib/esm/decorators/headerParams.js +14 -0
- package/lib/esm/decorators/headerParams.js.map +1 -0
- package/lib/esm/decorators/locals.js +14 -0
- package/lib/esm/decorators/locals.js.map +1 -0
- package/lib/esm/decorators/paramFn.js +13 -0
- package/lib/esm/decorators/paramFn.js.map +1 -0
- package/lib/esm/decorators/pathParams.js +49 -0
- package/lib/esm/decorators/pathParams.js.map +1 -0
- package/lib/esm/decorators/queryParams.js +49 -0
- package/lib/esm/decorators/queryParams.js.map +1 -0
- package/lib/esm/decorators/session.js +14 -0
- package/lib/esm/decorators/session.js.map +1 -0
- package/lib/esm/decorators/useDeserialization.js +14 -0
- package/lib/esm/decorators/useDeserialization.js.map +1 -0
- package/lib/esm/decorators/useParam.js +46 -0
- package/lib/esm/decorators/useParam.js.map +1 -0
- package/lib/esm/decorators/useParamExpression.js +16 -0
- package/lib/esm/decorators/useParamExpression.js.map +1 -0
- package/lib/esm/decorators/useParamType.js +28 -0
- package/lib/esm/decorators/useParamType.js.map +1 -0
- package/lib/esm/decorators/usePipe.js +18 -0
- package/lib/esm/decorators/usePipe.js.map +1 -0
- package/lib/esm/decorators/useType.js +16 -0
- package/lib/esm/decorators/useType.js.map +1 -0
- package/lib/esm/decorators/useValidation.js +18 -0
- package/lib/esm/decorators/useValidation.js.map +1 -0
- package/lib/esm/domain/ParamMetadata.js +2 -0
- package/lib/esm/domain/ParamMetadata.js.map +1 -0
- package/lib/esm/domain/ParamOptions.js +2 -0
- package/lib/esm/domain/ParamOptions.js.map +1 -0
- package/lib/esm/domain/ParamTypes.js +37 -0
- package/lib/esm/domain/ParamTypes.js.map +1 -0
- package/lib/esm/errors/ParamValidationError.js +25 -0
- package/lib/esm/errors/ParamValidationError.js.map +1 -0
- package/lib/esm/errors/RequiredValidationError.js +28 -0
- package/lib/esm/errors/RequiredValidationError.js.map +1 -0
- package/lib/esm/errors/ValidationError.js +9 -0
- package/lib/esm/errors/ValidationError.js.map +1 -0
- package/lib/esm/exports.js +2 -0
- package/lib/esm/exports.js.map +1 -0
- package/lib/esm/index.js +32 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/pipes/DeserializerPipe.js +27 -0
- package/lib/esm/pipes/DeserializerPipe.js.map +1 -0
- package/lib/esm/pipes/ParseExpressionPipe.js +29 -0
- package/lib/esm/pipes/ParseExpressionPipe.js.map +1 -0
- package/lib/esm/pipes/ValidationPipe.js +80 -0
- package/lib/esm/pipes/ValidationPipe.js.map +1 -0
- package/lib/esm/utils/mapParamsOptions.js +26 -0
- package/lib/esm/utils/mapParamsOptions.js.map +1 -0
- package/lib/{builder → types/builder}/PlatformParams.d.ts +3 -4
- package/lib/{decorators → types/decorators}/bodyParams.d.ts +2 -1
- package/lib/{decorators → types/decorators}/context.d.ts +0 -6
- package/lib/{decorators → types/decorators}/cookies.d.ts +0 -0
- package/lib/{decorators → types/decorators}/headerParams.d.ts +0 -0
- package/lib/{decorators → types/decorators}/locals.d.ts +0 -0
- package/lib/{decorators → types/decorators}/paramFn.d.ts +2 -2
- package/lib/{decorators → types/decorators}/pathParams.d.ts +0 -0
- package/lib/{decorators → types/decorators}/queryParams.d.ts +0 -0
- package/lib/{decorators → types/decorators}/session.d.ts +0 -0
- package/lib/{decorators → types/decorators}/useDeserialization.d.ts +0 -0
- package/lib/{decorators → types/decorators}/useParam.d.ts +0 -0
- package/lib/{decorators → types/decorators}/useParamExpression.d.ts +0 -0
- package/lib/{decorators → types/decorators}/useParamType.d.ts +0 -0
- package/lib/{decorators → types/decorators}/usePipe.d.ts +1 -1
- package/lib/{decorators → types/decorators}/useType.d.ts +0 -0
- package/lib/{decorators → types/decorators}/useValidation.d.ts +0 -0
- package/lib/types/domain/ParamMetadata.d.ts +1 -0
- package/lib/{domain → types/domain}/ParamOptions.d.ts +0 -0
- package/lib/{domain → types/domain}/ParamTypes.d.ts +1 -0
- package/lib/{errors → types/errors}/ParamValidationError.d.ts +2 -2
- package/lib/{errors → types/errors}/RequiredValidationError.d.ts +2 -3
- package/lib/{errors → types/errors}/ValidationError.d.ts +0 -0
- package/lib/types/exports.d.ts +1 -0
- package/lib/{index.d.ts → types/index.d.ts} +24 -21
- package/lib/types/pipes/DeserializerPipe.d.ts +5 -0
- package/lib/types/pipes/ParseExpressionPipe.d.ts +6 -0
- package/lib/types/pipes/ValidationPipe.d.ts +10 -0
- package/lib/{utils → types/utils}/mapParamsOptions.d.ts +0 -0
- package/package.json +41 -18
- package/readme.md +1 -2
- package/tsconfig.compile.esm.json +12 -0
- package/lib/domain/ParamMetadata.d.ts +0 -21
- package/lib/index.js +0 -844
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -825
- package/lib/index.modern.js.map +0 -1
- package/lib/pipes/DeserializerPipe.d.ts +0 -5
- package/lib/pipes/ParseExpressionPipe.d.ts +0 -5
- package/lib/pipes/ValidationPipe.d.ts +0 -10
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UseType = void 0;
|
|
4
|
+
const schema_1 = require("@tsed/schema");
|
|
5
|
+
/**
|
|
6
|
+
* Set the type of the item colllection.
|
|
7
|
+
*
|
|
8
|
+
* Prefer @@CollectionOf@@ usage.
|
|
9
|
+
*
|
|
10
|
+
* @param type
|
|
11
|
+
* @decorator
|
|
12
|
+
* @operation
|
|
13
|
+
* @input
|
|
14
|
+
* @alias CollectionOf
|
|
15
|
+
*/
|
|
16
|
+
function UseType(type) {
|
|
17
|
+
return (0, schema_1.CollectionOf)(type);
|
|
18
|
+
}
|
|
19
|
+
exports.UseType = UseType;
|
|
20
|
+
//# sourceMappingURL=useType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useType.js","sourceRoot":"","sources":["../../../src/decorators/useType.ts"],"names":[],"mappings":";;;AACA,yCAA0C;AAE1C;;;;;;;;;;GAUG;AACH,SAAgB,OAAO,CAAC,IAAqB;IAC3C,OAAO,IAAA,qBAAY,EAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAFD,0BAEC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {CollectionOf} from \"@tsed/schema\";\n\n/**\n * Set the type of the item colllection.\n *\n * Prefer @@CollectionOf@@ usage.\n *\n * @param type\n * @decorator\n * @operation\n * @input\n * @alias CollectionOf\n */\nexport function UseType(type: any | Type<any>) {\n return CollectionOf(type);\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UseValidation = void 0;
|
|
4
|
+
const ValidationPipe_1 = require("../pipes/ValidationPipe");
|
|
5
|
+
const paramFn_1 = require("./paramFn");
|
|
6
|
+
/**
|
|
7
|
+
* Enable validation on the decoratored parameter.
|
|
8
|
+
*
|
|
9
|
+
* @decorator
|
|
10
|
+
* @operation
|
|
11
|
+
* @input
|
|
12
|
+
* @pipe
|
|
13
|
+
*/
|
|
14
|
+
function UseValidation() {
|
|
15
|
+
return (0, paramFn_1.ParamFn)((param) => {
|
|
16
|
+
if (param.type || param.collectionType) {
|
|
17
|
+
param.pipes.push(ValidationPipe_1.ValidationPipe);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
exports.UseValidation = UseValidation;
|
|
22
|
+
//# sourceMappingURL=useValidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useValidation.js","sourceRoot":"","sources":["../../../src/decorators/useValidation.ts"],"names":[],"mappings":";;;AAAA,4DAAuD;AACvD,uCAAkC;AAElC;;;;;;;GAOG;AACH,SAAgB,aAAa;IAC3B,OAAO,IAAA,iBAAO,EAAC,CAAC,KAAK,EAAE,EAAE;QACvB,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,cAAc,EAAE;YACtC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,+BAAc,CAAC,CAAC;SAClC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAND,sCAMC","sourcesContent":["import {ValidationPipe} from \"../pipes/ValidationPipe\";\nimport {ParamFn} from \"./paramFn\";\n\n/**\n * Enable validation on the decoratored parameter.\n *\n * @decorator\n * @operation\n * @input\n * @pipe\n */\nexport function UseValidation() {\n return ParamFn((param) => {\n if (param.type || param.collectionType) {\n param.pipes.push(ValidationPipe);\n }\n });\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParamMetadata = void 0;
|
|
4
|
+
var schema_1 = require("@tsed/schema");
|
|
5
|
+
Object.defineProperty(exports, "ParamMetadata", { enumerable: true, get: function () { return schema_1.ParamMetadata; } });
|
|
6
|
+
//# sourceMappingURL=ParamMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParamMetadata.js","sourceRoot":"","sources":["../../../src/domain/ParamMetadata.ts"],"names":[],"mappings":";;;AAAA,uCAA2C;AAAnC,uGAAA,aAAa,OAAA","sourcesContent":["export {ParamMetadata} from \"@tsed/schema\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParamOptions.js","sourceRoot":"","sources":["../../../src/domain/ParamOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\n\nexport interface ParamOptions<T = any> {\n dataPath: string;\n paramType: string;\n expression?: string;\n useType?: Type<T>;\n useConverter?: boolean;\n useValidation?: boolean;\n\n [key: string]: any;\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PARAM_TYPES_DATA_PATH = exports.ParamTypes = void 0;
|
|
4
|
+
var ParamTypes;
|
|
5
|
+
(function (ParamTypes) {
|
|
6
|
+
ParamTypes["$CTX"] = "$CTX";
|
|
7
|
+
ParamTypes["BODY"] = "BODY";
|
|
8
|
+
ParamTypes["PATH"] = "PATH";
|
|
9
|
+
ParamTypes["QUERY"] = "QUERY";
|
|
10
|
+
ParamTypes["HEADER"] = "HEADER";
|
|
11
|
+
ParamTypes["RAW_BODY"] = "RAW_BODY";
|
|
12
|
+
ParamTypes["COOKIES"] = "COOKIES";
|
|
13
|
+
ParamTypes["LOCALS"] = "LOCALS";
|
|
14
|
+
ParamTypes["SESSION"] = "SESSION";
|
|
15
|
+
ParamTypes["FILES"] = "FILES";
|
|
16
|
+
/// NOT STD
|
|
17
|
+
ParamTypes["NEXT_FN"] = "NEXT_FN";
|
|
18
|
+
ParamTypes["ERR"] = "ERR";
|
|
19
|
+
ParamTypes["REQUEST"] = "REQUEST";
|
|
20
|
+
ParamTypes["PLATFORM_REQUEST"] = "PLATFORM_REQUEST";
|
|
21
|
+
ParamTypes["NODE_REQUEST"] = "NODE_REQUEST";
|
|
22
|
+
ParamTypes["RESPONSE"] = "RESPONSE";
|
|
23
|
+
ParamTypes["PLATFORM_RESPONSE"] = "PLATFORM_RESPONSE";
|
|
24
|
+
ParamTypes["NODE_RESPONSE"] = "NODE_RESPONSE";
|
|
25
|
+
ParamTypes["RESPONSE_DATA"] = "RESPONSE_DATA";
|
|
26
|
+
ParamTypes["ENDPOINT_INFO"] = "ENDPOINT_INFO";
|
|
27
|
+
ParamTypes["RES"] = "RES";
|
|
28
|
+
ParamTypes["REQ"] = "REQ";
|
|
29
|
+
})(ParamTypes = exports.ParamTypes || (exports.ParamTypes = {}));
|
|
30
|
+
exports.PARAM_TYPES_DATA_PATH = {
|
|
31
|
+
[ParamTypes.HEADER]: "$ctx.request.headers",
|
|
32
|
+
[ParamTypes.RAW_BODY]: "$ctx.request.rawBody",
|
|
33
|
+
[ParamTypes.BODY]: "$ctx.request.body",
|
|
34
|
+
[ParamTypes.QUERY]: "$ctx.request.query",
|
|
35
|
+
[ParamTypes.PATH]: "$ctx.request.params",
|
|
36
|
+
[ParamTypes.COOKIES]: "$ctx.request.cookies",
|
|
37
|
+
[ParamTypes.SESSION]: "$ctx.request.session",
|
|
38
|
+
[ParamTypes.LOCALS]: "$ctx.response.locals"
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=ParamTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParamTypes.js","sourceRoot":"","sources":["../../../src/domain/ParamTypes.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAyBX;AAzBD,WAAY,UAAU;IACpB,2BAAa,CAAA;IACb,2BAAa,CAAA;IACb,2BAAa,CAAA;IACb,6BAAe,CAAA;IACf,+BAAiB,CAAA;IACjB,mCAAqB,CAAA;IACrB,iCAAmB,CAAA;IACnB,+BAAiB,CAAA;IACjB,iCAAmB,CAAA;IACnB,6BAAe,CAAA;IAEf,WAAW;IACX,iCAAmB,CAAA;IACnB,yBAAW,CAAA;IACX,iCAAmB,CAAA;IACnB,mDAAqC,CAAA;IACrC,2CAA6B,CAAA;IAC7B,mCAAqB,CAAA;IACrB,qDAAuC,CAAA;IACvC,6CAA+B,CAAA;IAC/B,6CAA+B,CAAA;IAC/B,6CAA+B,CAAA;IAC/B,yBAAW,CAAA;IACX,yBAAW,CAAA;AACb,CAAC,EAzBW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAyBrB;AAEY,QAAA,qBAAqB,GAA2B;IAC3D,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,sBAAsB;IAC3C,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,sBAAsB;IAC7C,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,mBAAmB;IACtC,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,oBAAoB;IACxC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,qBAAqB;IACxC,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,sBAAsB;IAC5C,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,sBAAsB;IAC5C,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,sBAAsB;CAC5C,CAAC","sourcesContent":["export enum ParamTypes {\n $CTX = \"$CTX\",\n BODY = \"BODY\",\n PATH = \"PATH\",\n QUERY = \"QUERY\",\n HEADER = \"HEADER\",\n RAW_BODY = \"RAW_BODY\",\n COOKIES = \"COOKIES\",\n LOCALS = \"LOCALS\",\n SESSION = \"SESSION\",\n FILES = \"FILES\",\n\n /// NOT STD\n NEXT_FN = \"NEXT_FN\",\n ERR = \"ERR\",\n REQUEST = \"REQUEST\",\n PLATFORM_REQUEST = \"PLATFORM_REQUEST\",\n NODE_REQUEST = \"NODE_REQUEST\",\n RESPONSE = \"RESPONSE\",\n PLATFORM_RESPONSE = \"PLATFORM_RESPONSE\",\n NODE_RESPONSE = \"NODE_RESPONSE\",\n RESPONSE_DATA = \"RESPONSE_DATA\",\n ENDPOINT_INFO = \"ENDPOINT_INFO\",\n RES = \"RES\",\n REQ = \"REQ\"\n}\n\nexport const PARAM_TYPES_DATA_PATH: Record<string, string> = {\n [ParamTypes.HEADER]: \"$ctx.request.headers\",\n [ParamTypes.RAW_BODY]: \"$ctx.request.rawBody\",\n [ParamTypes.BODY]: \"$ctx.request.body\",\n [ParamTypes.QUERY]: \"$ctx.request.query\",\n [ParamTypes.PATH]: \"$ctx.request.params\",\n [ParamTypes.COOKIES]: \"$ctx.request.cookies\",\n [ParamTypes.SESSION]: \"$ctx.request.session\",\n [ParamTypes.LOCALS]: \"$ctx.response.locals\"\n};\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParamValidationError = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const exceptions_1 = require("@tsed/exceptions");
|
|
6
|
+
const ValidationError_1 = require("./ValidationError");
|
|
7
|
+
class ParamValidationError extends exceptions_1.BadRequest {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.name = "PARAM_VALIDATION_ERROR";
|
|
11
|
+
}
|
|
12
|
+
static from(metadata, origin = {}) {
|
|
13
|
+
if (origin instanceof ValidationError_1.ValidationError || origin instanceof exceptions_1.BadRequest) {
|
|
14
|
+
const name = (0, core_1.nameOf)(metadata.paramType)
|
|
15
|
+
.toLowerCase()
|
|
16
|
+
.replace(/parse|params|filter/gi, "");
|
|
17
|
+
const expression = metadata.expression;
|
|
18
|
+
const message = `Bad request on parameter "request.${name}${expression ? "." + expression : ""}".\n${origin.message}`.trim();
|
|
19
|
+
const error = new ParamValidationError(message);
|
|
20
|
+
error.dataPath = String(metadata.expression) || "";
|
|
21
|
+
error.requestType = (0, core_1.nameOf)(metadata.paramType);
|
|
22
|
+
error.origin = origin.origin || origin;
|
|
23
|
+
return error;
|
|
24
|
+
}
|
|
25
|
+
return origin;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ParamValidationError = ParamValidationError;
|
|
29
|
+
//# sourceMappingURL=ParamValidationError.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequiredValidationError = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const ValidationError_1 = require("./ValidationError");
|
|
6
|
+
class RequiredValidationError extends ValidationError_1.ValidationError {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.name = "REQUIRED_VALIDATION_ERROR";
|
|
10
|
+
}
|
|
11
|
+
static from(metadata) {
|
|
12
|
+
const name = (0, core_1.nameOf)(metadata.paramType);
|
|
13
|
+
const expression = metadata.expression;
|
|
14
|
+
const type = name.toLowerCase().replace(/parse|params|filter/gi, "");
|
|
15
|
+
const message = `It should have required parameter '${expression}'`;
|
|
16
|
+
const errors = [
|
|
17
|
+
{
|
|
18
|
+
dataPath: "",
|
|
19
|
+
keyword: "required",
|
|
20
|
+
message,
|
|
21
|
+
modelName: type,
|
|
22
|
+
params: {
|
|
23
|
+
missingProperty: expression
|
|
24
|
+
},
|
|
25
|
+
schemaPath: "#/required"
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
return new RequiredValidationError(message, errors);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.RequiredValidationError = RequiredValidationError;
|
|
32
|
+
//# sourceMappingURL=RequiredValidationError.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationError = void 0;
|
|
4
|
+
const exceptions_1 = require("@tsed/exceptions");
|
|
5
|
+
class ValidationError extends exceptions_1.BadRequest {
|
|
6
|
+
constructor(message, errors = []) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "VALIDATION_ERROR";
|
|
9
|
+
this.errors = errors;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ValidationError = ValidationError;
|
|
13
|
+
//# sourceMappingURL=ValidationError.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":"","sourcesContent":["export {PipeMethods} from \"@tsed/schema\";\n"]}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Automatically generated by barrelsby.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
tslib_1.__exportStar(require("./exports"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./builder/PlatformParams"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./decorators/bodyParams"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./decorators/context"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./decorators/cookies"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./decorators/headerParams"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./decorators/locals"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./decorators/paramFn"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./decorators/pathParams"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./decorators/queryParams"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./decorators/session"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./decorators/useDeserialization"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./decorators/useParam"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./decorators/useParamExpression"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./decorators/useParamType"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./decorators/usePipe"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./decorators/useType"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./decorators/useValidation"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./domain/ParamMetadata"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./domain/ParamOptions"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./domain/ParamTypes"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./errors/ParamValidationError"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./errors/RequiredValidationError"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./errors/ValidationError"), exports);
|
|
31
|
+
tslib_1.__exportStar(require("./pipes/DeserializerPipe"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./pipes/ParseExpressionPipe"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./pipes/ValidationPipe"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./utils/mapParamsOptions"), exports);
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,mEAAyC;AACzC,kEAAwC;AACxC,+DAAqC;AACrC,+DAAqC;AACrC,oEAA0C;AAC1C,8DAAoC;AACpC,+DAAqC;AACrC,kEAAwC;AACxC,mEAAyC;AACzC,+DAAqC;AACrC,0EAAgD;AAChD,gEAAsC;AACtC,0EAAgD;AAChD,oEAA0C;AAC1C,+DAAqC;AACrC,+DAAqC;AACrC,qEAA2C;AAC3C,iEAAuC;AACvC,gEAAsC;AACtC,8DAAoC;AACpC,wEAA8C;AAC9C,2EAAiD;AACjD,mEAAyC;AACzC,mEAAyC;AACzC,sEAA4C;AAC5C,iEAAuC;AACvC,mEAAyC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./builder/PlatformParams\";\nexport * from \"./decorators/bodyParams\";\nexport * from \"./decorators/context\";\nexport * from \"./decorators/cookies\";\nexport * from \"./decorators/headerParams\";\nexport * from \"./decorators/locals\";\nexport * from \"./decorators/paramFn\";\nexport * from \"./decorators/pathParams\";\nexport * from \"./decorators/queryParams\";\nexport * from \"./decorators/session\";\nexport * from \"./decorators/useDeserialization\";\nexport * from \"./decorators/useParam\";\nexport * from \"./decorators/useParamExpression\";\nexport * from \"./decorators/useParamType\";\nexport * from \"./decorators/usePipe\";\nexport * from \"./decorators/useType\";\nexport * from \"./decorators/useValidation\";\nexport * from \"./domain/ParamMetadata\";\nexport * from \"./domain/ParamOptions\";\nexport * from \"./domain/ParamTypes\";\nexport * from \"./errors/ParamValidationError\";\nexport * from \"./errors/RequiredValidationError\";\nexport * from \"./errors/ValidationError\";\nexport * from \"./pipes/DeserializerPipe\";\nexport * from \"./pipes/ParseExpressionPipe\";\nexport * from \"./pipes/ValidationPipe\";\nexport * from \"./utils/mapParamsOptions\";\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var DeserializerPipe_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.DeserializerPipe = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const di_1 = require("@tsed/di");
|
|
7
|
+
const json_mapper_1 = require("@tsed/json-mapper");
|
|
8
|
+
let DeserializerPipe = DeserializerPipe_1 = class DeserializerPipe {
|
|
9
|
+
transform(value, param) {
|
|
10
|
+
return (0, json_mapper_1.deserialize)(value, {
|
|
11
|
+
useAlias: true,
|
|
12
|
+
additionalProperties: this.settings.additionalProperties === "accept",
|
|
13
|
+
type: param.type,
|
|
14
|
+
collectionType: param.collectionType,
|
|
15
|
+
groups: param.parameter.groups,
|
|
16
|
+
genericTypes: param.nestedGenerics[0],
|
|
17
|
+
nestedGenerics: param.nestedGenerics,
|
|
18
|
+
...(param.store.get(DeserializerPipe_1) || {})
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
tslib_1.__decorate([
|
|
23
|
+
(0, di_1.Constant)("converter", {}),
|
|
24
|
+
tslib_1.__metadata("design:type", Object)
|
|
25
|
+
], DeserializerPipe.prototype, "settings", void 0);
|
|
26
|
+
DeserializerPipe = DeserializerPipe_1 = tslib_1.__decorate([
|
|
27
|
+
(0, di_1.Injectable)()
|
|
28
|
+
], DeserializerPipe);
|
|
29
|
+
exports.DeserializerPipe = DeserializerPipe;
|
|
30
|
+
//# sourceMappingURL=DeserializerPipe.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseExpressionPipe = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@tsed/core");
|
|
6
|
+
const di_1 = require("@tsed/di");
|
|
7
|
+
const ParamTypes_1 = require("../domain/ParamTypes");
|
|
8
|
+
let ParseExpressionPipe = class ParseExpressionPipe {
|
|
9
|
+
transform(scope, param) {
|
|
10
|
+
const { paramType, type } = param;
|
|
11
|
+
const value = (0, core_1.getValue)(scope, this.getKey(param));
|
|
12
|
+
if ([ParamTypes_1.ParamTypes.QUERY, ParamTypes_1.ParamTypes.PATH].includes(paramType) && value === "" && type !== String) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
getKey(param) {
|
|
18
|
+
let { expression, paramType, dataPath } = param;
|
|
19
|
+
paramType = paramType || param.parameter.get("in").toUpperCase();
|
|
20
|
+
if (expression && paramType === ParamTypes_1.ParamTypes.HEADER) {
|
|
21
|
+
expression = String(expression).toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
return [dataPath, expression].filter(Boolean).join(".");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
ParseExpressionPipe = tslib_1.__decorate([
|
|
27
|
+
(0, di_1.Injectable)({
|
|
28
|
+
priority: -1000
|
|
29
|
+
})
|
|
30
|
+
], ParseExpressionPipe);
|
|
31
|
+
exports.ParseExpressionPipe = ParseExpressionPipe;
|
|
32
|
+
//# sourceMappingURL=ParseExpressionPipe.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationPipe = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@tsed/core");
|
|
6
|
+
const di_1 = require("@tsed/di");
|
|
7
|
+
const json_mapper_1 = require("@tsed/json-mapper");
|
|
8
|
+
const schema_1 = require("@tsed/schema");
|
|
9
|
+
const RequiredValidationError_1 = require("../errors/RequiredValidationError");
|
|
10
|
+
const ParamTypes_1 = require("../domain/ParamTypes");
|
|
11
|
+
function cast(value, metadata) {
|
|
12
|
+
try {
|
|
13
|
+
return (0, json_mapper_1.deserialize)(value, {
|
|
14
|
+
type: metadata.type
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (er) {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
let ValidationPipe = class ValidationPipe {
|
|
22
|
+
constructor(injector) {
|
|
23
|
+
const provider = injector.getProviders().find((provider) => (0, core_1.nameOf)(provider.token) === "AjvService");
|
|
24
|
+
if (provider) {
|
|
25
|
+
this.validator = injector.invoke(provider.token);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
coerceTypes(value, metadata) {
|
|
29
|
+
if (value === undefined) {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
if (value === "null") {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (metadata.isArray) {
|
|
36
|
+
return [].concat(value);
|
|
37
|
+
}
|
|
38
|
+
if (metadata.isPrimitive) {
|
|
39
|
+
return cast(value, metadata);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
skip(value, metadata) {
|
|
44
|
+
return metadata.paramType === ParamTypes_1.ParamTypes.PATH && !metadata.isPrimitive;
|
|
45
|
+
}
|
|
46
|
+
async transform(value, metadata) {
|
|
47
|
+
if (!this.validator) {
|
|
48
|
+
this.checkIsRequired(value, metadata);
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
if (this.skip(value, metadata)) {
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
value = this.coerceTypes(value, metadata);
|
|
55
|
+
this.checkIsRequired(value, metadata);
|
|
56
|
+
if (value === undefined) {
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
const schema = (0, schema_1.getJsonSchema)(metadata, {
|
|
60
|
+
customKeys: true
|
|
61
|
+
});
|
|
62
|
+
await this.validator.validate(value, {
|
|
63
|
+
schema,
|
|
64
|
+
type: metadata.isClass ? metadata.type : undefined,
|
|
65
|
+
collectionType: metadata.collectionType
|
|
66
|
+
});
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
checkIsRequired(value, metadata) {
|
|
70
|
+
if (metadata.isRequired(value)) {
|
|
71
|
+
throw RequiredValidationError_1.RequiredValidationError.from(metadata);
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
ValidationPipe = tslib_1.__decorate([
|
|
77
|
+
(0, di_1.Injectable)({
|
|
78
|
+
type: "validator"
|
|
79
|
+
}),
|
|
80
|
+
tslib_1.__metadata("design:paramtypes", [di_1.InjectorService])
|
|
81
|
+
], ValidationPipe);
|
|
82
|
+
exports.ValidationPipe = ValidationPipe;
|
|
83
|
+
//# sourceMappingURL=ValidationPipe.js.map
|
|
@@ -0,0 +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,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;SAC9B;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,KAAU,EAAE,QAA4B;QAC3C,OAAO,QAAQ,CAAC,SAAS,KAAK,uBAAU,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;IACzE,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,KAAU,EAAE,QAA4B;QACtD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YACtC,OAAO,KAAK,CAAC;SACd;QAED,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;YAC9B,OAAO,KAAK,CAAC;SACd;QAED,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE1C,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAEtC,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,OAAO,KAAK,CAAC;SACd;QAED,MAAM,MAAM,GAAG,IAAA,sBAAa,EAAC,QAAQ,EAAE;YACrC,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE;YACnC,MAAM;YACN,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YAClD,cAAc,EAAE,QAAQ,CAAC,cAAc;SACxC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;IAES,eAAe,CAAC,KAAU,EAAE,QAA4B;QAChE,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAC9B,MAAM,iDAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC9C;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzEY,cAAc;IAH1B,IAAA,eAAU,EAAC;QACV,IAAI,EAAE,WAAW;KAClB,CAAC;6CAIsB,oBAAe;GAH1B,cAAc,CAyE1B;AAzEY,wCAAc","sourcesContent":["import {nameOf} from \"@tsed/core\";\nimport {Injectable, InjectorService} from \"@tsed/di\";\nimport {deserialize} from \"@tsed/json-mapper\";\nimport {getJsonSchema, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {RequiredValidationError} from \"../errors/RequiredValidationError\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\n\nfunction cast(value: any, metadata: JsonParameterStore) {\n try {\n return deserialize(value, {\n type: metadata.type\n });\n } catch (er) {\n return value;\n }\n}\n\n@Injectable({\n type: \"validator\"\n})\nexport class ValidationPipe implements PipeMethods {\n private validator: {validate(value: any, options: any): Promise<any>};\n\n constructor(injector: InjectorService) {\n const provider = injector.getProviders().find((provider) => nameOf(provider.token) === \"AjvService\");\n\n if (provider) {\n this.validator = injector.invoke<any>(provider.token);\n }\n }\n\n coerceTypes(value: any, metadata: JsonParameterStore) {\n if (value === undefined) {\n return value;\n }\n\n if (value === \"null\") {\n return null;\n }\n\n if (metadata.isArray) {\n return [].concat(value);\n }\n\n if (metadata.isPrimitive) {\n return cast(value, metadata);\n }\n\n return value;\n }\n\n skip(value: any, metadata: JsonParameterStore) {\n return metadata.paramType === ParamTypes.PATH && !metadata.isPrimitive;\n }\n\n async transform(value: any, metadata: JsonParameterStore): Promise<any> {\n if (!this.validator) {\n this.checkIsRequired(value, metadata);\n return value;\n }\n\n if (this.skip(value, metadata)) {\n return value;\n }\n\n value = this.coerceTypes(value, metadata);\n\n this.checkIsRequired(value, metadata);\n\n if (value === undefined) {\n return value;\n }\n\n const schema = getJsonSchema(metadata, {\n customKeys: true\n });\n\n await this.validator.validate(value, {\n schema,\n type: metadata.isClass ? metadata.type : undefined,\n collectionType: metadata.collectionType\n });\n\n return value;\n }\n\n protected checkIsRequired(value: any, metadata: JsonParameterStore) {\n if (metadata.isRequired(value)) {\n throw RequiredValidationError.from(metadata);\n }\n\n return true;\n }\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapParamsOptions = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
/**
|
|
6
|
+
* @ignore
|
|
7
|
+
*/
|
|
8
|
+
function mapParamsOptions(args) {
|
|
9
|
+
if (args.length === 1) {
|
|
10
|
+
if (typeof args[0] === "string") {
|
|
11
|
+
return {
|
|
12
|
+
expression: args[0]
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (!(0, core_1.isObject)(args[0])) {
|
|
16
|
+
return {
|
|
17
|
+
useType: args[0]
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
...args[0]
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
expression: args[0],
|
|
26
|
+
useType: args[1]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.mapParamsOptions = mapParamsOptions;
|
|
30
|
+
//# sourceMappingURL=mapParamsOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapParamsOptions.js","sourceRoot":"","sources":["../../../src/utils/mapParamsOptions.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAGpC;;GAEG;AACH,SAAgB,gBAAgB,CAAC,IAAW;IAC1C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACrB,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;YAC/B,OAAO;gBACL,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;aACpB,CAAC;SACH;QAED,IAAI,CAAC,IAAA,eAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;YACtB,OAAO;gBACL,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;aACjB,CAAC;SACH;QAED,OAAO;YACL,GAAG,IAAI,CAAC,CAAC,CAAC;SACX,CAAC;KACH;IAED,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;QACnB,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;KACjB,CAAC;AACJ,CAAC;AAvBD,4CAuBC","sourcesContent":["import {isObject} from \"@tsed/core\";\nimport {ParamOptions} from \"../domain/ParamOptions\";\n\n/**\n * @ignore\n */\nexport function mapParamsOptions(args: any[]): Partial<ParamOptions<any>> {\n if (args.length === 1) {\n if (typeof args[0] === \"string\") {\n return {\n expression: args[0]\n };\n }\n\n if (!isObject(args[0])) {\n return {\n useType: args[0]\n };\n }\n\n return {\n ...args[0]\n };\n }\n\n return {\n expression: args[0],\n useType: args[1]\n };\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Inject, Injectable, InjectorService, ProviderScope } from "@tsed/di";
|
|
3
|
+
import { JsonEntityStore, JsonParameterStore } from "@tsed/schema";
|
|
4
|
+
import { ParamValidationError } from "../errors/ParamValidationError.js";
|
|
5
|
+
import { ParseExpressionPipe } from "../pipes/ParseExpressionPipe.js";
|
|
6
|
+
/**
|
|
7
|
+
* Platform Params abstraction layer.
|
|
8
|
+
* @platform
|
|
9
|
+
*/
|
|
10
|
+
let PlatformParams = class PlatformParams {
|
|
11
|
+
async getPipes(param) {
|
|
12
|
+
const get = (pipe) => {
|
|
13
|
+
return this.injector.getProvider(pipe).priority || 0;
|
|
14
|
+
};
|
|
15
|
+
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);
|
|
19
|
+
}
|
|
20
|
+
async compile(entity) {
|
|
21
|
+
const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);
|
|
22
|
+
const argsPipes = await Promise.all(params.map(async (param) => {
|
|
23
|
+
return {
|
|
24
|
+
param,
|
|
25
|
+
pipes: await this.getPipes(param)
|
|
26
|
+
};
|
|
27
|
+
}));
|
|
28
|
+
return (scope) => {
|
|
29
|
+
const promises = argsPipes.map(({ param, pipes }) => {
|
|
30
|
+
return this.getArg(scope, pipes, param);
|
|
31
|
+
});
|
|
32
|
+
return Promise.all(promises);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async getArg(scope, pipes, param) {
|
|
36
|
+
return pipes.reduce(async (value, pipe) => {
|
|
37
|
+
value = await value;
|
|
38
|
+
try {
|
|
39
|
+
return await pipe.transform(value, param);
|
|
40
|
+
}
|
|
41
|
+
catch (er) {
|
|
42
|
+
throw ParamValidationError.from(param, er);
|
|
43
|
+
}
|
|
44
|
+
}, scope);
|
|
45
|
+
}
|
|
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
|
+
};
|
|
65
|
+
__decorate([
|
|
66
|
+
Inject(),
|
|
67
|
+
__metadata("design:type", InjectorService)
|
|
68
|
+
], PlatformParams.prototype, "injector", void 0);
|
|
69
|
+
PlatformParams = __decorate([
|
|
70
|
+
Injectable({
|
|
71
|
+
scope: ProviderScope.SINGLETON,
|
|
72
|
+
imports: []
|
|
73
|
+
})
|
|
74
|
+
], PlatformParams);
|
|
75
|
+
export { PlatformParams };
|
|
76
|
+
//# sourceMappingURL=PlatformParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformParams.js","sourceRoot":"","sources":["../../../src/builder/PlatformParams.ts"],"names":[],"mappings":"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","sourcesContent":["import {DIContext, Inject, Injectable, InjectorService, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport {JsonEntityStore, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {ParamValidationError} from \"../errors/ParamValidationError\";\nimport {ParseExpressionPipe} from \"../pipes/ParseExpressionPipe\";\n\nexport type ArgScope<Context extends DIContext = DIContext> = {$ctx: Context} & Record<string, any>;\nexport type HandlerWithScope<Context extends DIContext = DIContext> = (scope: ArgScope<Context>) => any;\n\nexport interface CompileHandlerOptions<Context extends DIContext = DIContext> extends Record<any, unknown> {\n token: TokenProvider;\n propertyKey: string | symbol;\n getCustomArgs?: (scope: ArgScope<Context>) => Promise<any[]>;\n}\n\n/**\n * Platform Params abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: []\n})\nexport class PlatformParams {\n @Inject()\n protected injector: InjectorService;\n\n async getPipes(param: JsonParameterStore) {\n const get = (pipe: TokenProvider) => {\n return this.injector.getProvider(pipe)!.priority || 0;\n };\n\n const sort = (p1: TokenProvider, p2: TokenProvider) => (get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0);\n const map = (token: TokenProvider) => this.injector.invoke<PipeMethods>(token)!;\n const promises = await Promise.all([ParseExpressionPipe, ...param.pipes.sort(sort)].map(map));\n\n return promises.filter(Boolean);\n }\n\n async compile<Context extends DIContext = DIContext>(entity: JsonEntityStore) {\n const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);\n\n const argsPipes = await Promise.all(\n params.map(async (param) => {\n return {\n param,\n pipes: await this.getPipes(param)\n };\n })\n );\n\n return (scope: ArgScope<Context>) => {\n const promises = argsPipes.map(({param, pipes}) => {\n return this.getArg(scope, pipes, param);\n });\n\n return Promise.all(promises);\n };\n }\n\n async getArg(scope: ArgScope, pipes: PipeMethods[], param: JsonParameterStore) {\n return pipes.reduce(async (value, pipe) => {\n value = await value;\n\n try {\n return await pipe.transform(value, param);\n } catch (er) {\n throw ParamValidationError.from(param, er);\n }\n }, scope as any);\n }\n\n async compileHandler<Context extends DIContext = DIContext>(\n metadata: CompileHandlerOptions<Context>\n ): Promise<HandlerWithScope<Context>> {\n const {token, propertyKey, getCustomArgs} = metadata;\n\n const provider = this.injector.getProvider(token);\n const getArguments = getCustomArgs || (await this.compile<Context>(JsonEntityStore.fromMethod(token, propertyKey!)));\n\n if (!provider || !provider.scope || provider.scope === ProviderScope.SINGLETON) {\n const instance = await this.injector.invoke<any>(token);\n 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"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ParamTypes } from "../domain/ParamTypes.js";
|
|
2
|
+
import { UseParam } from "./useParam.js";
|
|
3
|
+
import { mapParamsOptions } from "../utils/mapParamsOptions.js";
|
|
4
|
+
export function BodyParams(...args) {
|
|
5
|
+
const { expression, useType, useConverter = true, useValidation = true } = mapParamsOptions(args);
|
|
6
|
+
return UseParam({
|
|
7
|
+
paramType: ParamTypes.BODY,
|
|
8
|
+
expression,
|
|
9
|
+
useType,
|
|
10
|
+
useConverter,
|
|
11
|
+
useValidation
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* RawBodyParams return the value from [request.body](http://expressjs.com/en/4x/api.html#req.body) as a Buffer.
|
|
16
|
+
*
|
|
17
|
+
* #### Example
|
|
18
|
+
*
|
|
19
|
+
* ```typescript
|
|
20
|
+
* @Controller('/')
|
|
21
|
+
* class MyCtrl {
|
|
22
|
+
* @Post('/')
|
|
23
|
+
* create(@RawBodyParams() body: Buffer) {
|
|
24
|
+
* console.log('Entire body', body.toString("utf8"));
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @decorator
|
|
30
|
+
* @operation
|
|
31
|
+
* @input
|
|
32
|
+
* @alias BodyParams Example: @BodyParams() payload: Buffer
|
|
33
|
+
*/
|
|
34
|
+
export function RawBodyParams() {
|
|
35
|
+
return UseParam({
|
|
36
|
+
paramType: ParamTypes.RAW_BODY,
|
|
37
|
+
useConverter: false,
|
|
38
|
+
useValidation: false
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=bodyParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bodyParams.js","sourceRoot":"","sources":["../../../src/decorators/bodyParams.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AA4C3D,MAAM,UAAU,UAAU,CAAC,GAAG,IAAW;IACvC,MAAM,EAAC,UAAU,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,EAAE,aAAa,GAAG,IAAI,EAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAEhG,OAAO,QAAQ,CAAC;QACd,SAAS,EAAE,UAAU,CAAC,IAAI;QAC1B,UAAU;QACV,OAAO;QACP,YAAY;QACZ,aAAa;KACd,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,QAAQ,CAAC;QACd,SAAS,EAAE,UAAU,CAAC,QAAQ;QAC9B,YAAY,EAAE,KAAK;QACnB,aAAa,EAAE,KAAK;KACrB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {ParamOptions} from \"../domain/ParamOptions\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\nimport {UseParam} from \"./useParam\";\nimport {mapParamsOptions} from \"../utils/mapParamsOptions\";\n\n/**\n * BodyParams return the value from [request.body](http://expressjs.com/en/4x/api.html#req.body) object.\n *\n * #### Example\n *\n * ```typescript\n * @Controller('/')\n * class MyCtrl {\n * @Post('/')\n * create(@BodyParams() body: any) {\n * console.log('Entire body', body);\n * }\n *\n * @Post('/')\n * create(@BodyParams('id') id: string) {\n * console.log('ID', id);\n * }\n *\n * @Post('/')\n * create(@BodyParams('user') user: User) { // with deserialization\n * console.log('user', user);\n * }\n *\n * @Post('/')\n * create(@BodyParams('users', User) users: User[]) { // with deserialization\n * console.log('users', users);\n * }\n * }\n * ```\n * > For more information on deserialization see [converters](/docs/converters.md) page.\n *\n * @param expression The path of the property to get.\n * @param useType The type of the class that to be used to deserialize the data.\n * @decorator\n * @operation\n * @input\n */\nexport function BodyParams(expression: string, useType: Type<any>): ParameterDecorator;\nexport function BodyParams(expression: string): ParameterDecorator;\nexport function BodyParams(useType: Type<any>): ParameterDecorator;\nexport function BodyParams(options: Partial<ParamOptions>): ParameterDecorator;\nexport function BodyParams(): ParameterDecorator;\nexport function BodyParams(...args: any[]): ParameterDecorator {\n const {expression, useType, useConverter = true, useValidation = true} = mapParamsOptions(args);\n\n return UseParam({\n paramType: ParamTypes.BODY,\n expression,\n useType,\n useConverter,\n useValidation\n });\n}\n\n/**\n * RawBodyParams return the value from [request.body](http://expressjs.com/en/4x/api.html#req.body) as a Buffer.\n *\n * #### Example\n *\n * ```typescript\n * @Controller('/')\n * class MyCtrl {\n * @Post('/')\n * create(@RawBodyParams() body: Buffer) {\n * console.log('Entire body', body.toString(\"utf8\"));\n * }\n * }\n * ```\n *\n * @decorator\n * @operation\n * @input\n * @alias BodyParams Example: @BodyParams() payload: Buffer\n */\nexport function RawBodyParams(): ParameterDecorator {\n return UseParam({\n paramType: ParamTypes.RAW_BODY,\n useConverter: false,\n useValidation: false\n });\n}\n"]}
|