@tsed/platform-params 7.0.0-beta.2 → 7.0.0-beta.20
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 +30 -33
- package/lib/cjs/builder/PlatformParams.js.map +1 -1
- package/lib/cjs/decorators/bodyParams.js +3 -10
- package/lib/cjs/decorators/bodyParams.js.map +1 -1
- package/lib/cjs/decorators/context.js +0 -1
- package/lib/cjs/decorators/context.js.map +1 -1
- package/lib/cjs/decorators/cookies.js +0 -1
- package/lib/cjs/decorators/cookies.js.map +1 -1
- package/lib/cjs/decorators/headerParams.js +0 -1
- package/lib/cjs/decorators/headerParams.js.map +1 -1
- package/lib/cjs/decorators/locals.js +0 -1
- package/lib/cjs/decorators/locals.js.map +1 -1
- package/lib/cjs/decorators/paramFn.js +2 -7
- package/lib/cjs/decorators/paramFn.js.map +1 -1
- package/lib/cjs/decorators/pathParams.js +0 -1
- package/lib/cjs/decorators/pathParams.js.map +1 -1
- package/lib/cjs/decorators/queryParams.js +4 -5
- package/lib/cjs/decorators/queryParams.js.map +1 -1
- package/lib/cjs/decorators/session.js +0 -1
- package/lib/cjs/decorators/session.js.map +1 -1
- package/lib/cjs/decorators/useParam.js +0 -4
- package/lib/cjs/decorators/useParam.js.map +1 -1
- package/lib/cjs/decorators/useParamType.js +7 -2
- package/lib/cjs/decorators/useParamType.js.map +1 -1
- package/lib/cjs/decorators/usePipe.js.map +1 -1
- package/lib/cjs/domain/ParamMetadata.js +2 -30
- package/lib/cjs/domain/ParamMetadata.js.map +1 -1
- package/lib/cjs/domain/ParamTypes.js +11 -1
- package/lib/cjs/domain/ParamTypes.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/exports.js +3 -0
- package/lib/cjs/exports.js.map +1 -0
- package/lib/cjs/index.js +31 -33
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/pipes/DeserializerPipe.js +4 -3
- package/lib/cjs/pipes/DeserializerPipe.js.map +1 -1
- package/lib/cjs/pipes/ParseExpressionPipe.js +10 -2
- package/lib/cjs/pipes/ParseExpressionPipe.js.map +1 -1
- package/lib/cjs/pipes/ValidationPipe.js +3 -2
- package/lib/cjs/pipes/ValidationPipe.js.map +1 -1
- package/lib/esm/builder/PlatformParams.js +30 -33
- package/lib/esm/builder/PlatformParams.js.map +1 -1
- package/lib/esm/decorators/bodyParams.js +6 -13
- package/lib/esm/decorators/bodyParams.js.map +1 -1
- package/lib/esm/decorators/context.js +3 -4
- package/lib/esm/decorators/context.js.map +1 -1
- package/lib/esm/decorators/cookies.js +3 -4
- package/lib/esm/decorators/cookies.js.map +1 -1
- package/lib/esm/decorators/headerParams.js +3 -4
- package/lib/esm/decorators/headerParams.js.map +1 -1
- package/lib/esm/decorators/locals.js +3 -4
- package/lib/esm/decorators/locals.js.map +1 -1
- package/lib/esm/decorators/paramFn.js +2 -7
- package/lib/esm/decorators/paramFn.js.map +1 -1
- package/lib/esm/decorators/pathParams.js +3 -4
- package/lib/esm/decorators/pathParams.js.map +1 -1
- package/lib/esm/decorators/queryParams.js +7 -8
- package/lib/esm/decorators/queryParams.js.map +1 -1
- package/lib/esm/decorators/session.js +3 -4
- package/lib/esm/decorators/session.js.map +1 -1
- package/lib/esm/decorators/useDeserialization.js +2 -2
- package/lib/esm/decorators/useParam.js +6 -10
- package/lib/esm/decorators/useParam.js.map +1 -1
- package/lib/esm/decorators/useParamExpression.js +1 -1
- package/lib/esm/decorators/useParamType.js +10 -5
- package/lib/esm/decorators/useParamType.js.map +1 -1
- package/lib/esm/decorators/usePipe.js +1 -1
- package/lib/esm/decorators/usePipe.js.map +1 -1
- package/lib/esm/decorators/useValidation.js +2 -2
- package/lib/esm/domain/ParamMetadata.js +1 -30
- package/lib/esm/domain/ParamMetadata.js.map +1 -1
- package/lib/esm/domain/ParamTypes.js +10 -0
- package/lib/esm/domain/ParamTypes.js.map +1 -1
- package/lib/esm/errors/ParamValidationError.js +4 -5
- package/lib/esm/errors/ParamValidationError.js.map +1 -1
- package/lib/esm/errors/RequiredValidationError.js +2 -5
- 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/exports.js +2 -0
- package/lib/esm/exports.js.map +1 -0
- package/lib/esm/index.js +31 -33
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/pipes/DeserializerPipe.js +1 -0
- package/lib/esm/pipes/DeserializerPipe.js.map +1 -1
- package/lib/esm/pipes/ParseExpressionPipe.js +10 -2
- package/lib/esm/pipes/ParseExpressionPipe.js.map +1 -1
- package/lib/esm/pipes/ValidationPipe.js +3 -2
- package/lib/esm/pipes/ValidationPipe.js.map +1 -1
- package/lib/types/builder/PlatformParams.d.ts +16 -14
- package/lib/types/decorators/bodyParams.d.ts +1 -0
- package/lib/types/decorators/context.d.ts +0 -6
- package/lib/types/decorators/paramFn.d.ts +2 -2
- package/lib/types/decorators/usePipe.d.ts +1 -1
- package/lib/types/domain/ParamMetadata.d.ts +1 -16
- package/lib/types/domain/ParamTypes.d.ts +1 -0
- package/lib/types/errors/ParamValidationError.d.ts +2 -2
- package/lib/types/errors/RequiredValidationError.d.ts +2 -2
- package/lib/types/exports.d.ts +1 -0
- package/lib/types/index.d.ts +24 -21
- package/lib/types/pipes/DeserializerPipe.d.ts +2 -2
- package/lib/types/pipes/ParseExpressionPipe.d.ts +4 -3
- package/lib/types/pipes/ValidationPipe.d.ts +5 -5
- package/package.json +39 -16
- package/readme.md +4 -4
- package/tsconfig.compile.esm.json +1 -12
|
@@ -1 +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","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"]}
|
|
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"]}
|
|
@@ -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;
|
|
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"]}
|
|
@@ -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
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Automatically generated by barrelsby.
|
|
4
|
+
*/
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
(0, tslib_1.__exportStar)(require("./decorators/locals"), exports);
|
|
33
|
-
(0, tslib_1.__exportStar)(require("./decorators/pathParams"), exports);
|
|
34
|
-
(0, tslib_1.__exportStar)(require("./decorators/queryParams"), exports);
|
|
35
|
-
(0, tslib_1.__exportStar)(require("./decorators/session"), exports);
|
|
36
|
-
(0, tslib_1.__exportStar)(require("./decorators/paramFn"), exports);
|
|
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);
|
|
37
35
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
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"]}
|
|
@@ -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,
|
|
@@ -19,11 +20,11 @@ let DeserializerPipe = DeserializerPipe_1 = class DeserializerPipe {
|
|
|
19
20
|
});
|
|
20
21
|
}
|
|
21
22
|
};
|
|
22
|
-
|
|
23
|
+
tslib_1.__decorate([
|
|
23
24
|
(0, di_1.Constant)("converter", {}),
|
|
24
|
-
|
|
25
|
+
tslib_1.__metadata("design:type", Object)
|
|
25
26
|
], DeserializerPipe.prototype, "settings", void 0);
|
|
26
|
-
DeserializerPipe = DeserializerPipe_1 =
|
|
27
|
+
DeserializerPipe = DeserializerPipe_1 = tslib_1.__decorate([
|
|
27
28
|
(0, di_1.Injectable)()
|
|
28
29
|
], DeserializerPipe);
|
|
29
30
|
exports.DeserializerPipe = DeserializerPipe;
|
|
@@ -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"]}
|
|
@@ -8,14 +8,22 @@ const ParamTypes_1 = require("../domain/ParamTypes");
|
|
|
8
8
|
let ParseExpressionPipe = class ParseExpressionPipe {
|
|
9
9
|
transform(scope, param) {
|
|
10
10
|
const { paramType, type } = param;
|
|
11
|
-
const value = (0, core_1.getValue)(scope, param
|
|
11
|
+
const value = (0, core_1.getValue)(scope, this.getKey(param));
|
|
12
12
|
if ([ParamTypes_1.ParamTypes.QUERY, ParamTypes_1.ParamTypes.PATH].includes(paramType) && value === "" && type !== String) {
|
|
13
13
|
return undefined;
|
|
14
14
|
}
|
|
15
15
|
return value;
|
|
16
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
|
+
}
|
|
17
25
|
};
|
|
18
|
-
ParseExpressionPipe =
|
|
26
|
+
ParseExpressionPipe = tslib_1.__decorate([
|
|
19
27
|
(0, di_1.Injectable)({
|
|
20
28
|
priority: -1000
|
|
21
29
|
})
|
|
@@ -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) {
|
|
@@ -73,11 +74,11 @@ let ValidationPipe = class ValidationPipe {
|
|
|
73
74
|
return true;
|
|
74
75
|
}
|
|
75
76
|
};
|
|
76
|
-
ValidationPipe =
|
|
77
|
+
ValidationPipe = tslib_1.__decorate([
|
|
77
78
|
(0, di_1.Injectable)({
|
|
78
79
|
type: "validator"
|
|
79
80
|
}),
|
|
80
|
-
|
|
81
|
+
tslib_1.__metadata("design:paramtypes", [di_1.InjectorService])
|
|
81
82
|
], ValidationPipe);
|
|
82
83
|
exports.ValidationPipe = ValidationPipe;
|
|
83
84
|
//# sourceMappingURL=ValidationPipe.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationPipe.js","sourceRoot":"","sources":["../../../src/pipes/ValidationPipe.ts"],"names":[],"mappings":";;;;AAAA,qCAAkC;AAClC,iCAAqD;AACrD,mDAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"ValidationPipe.js","sourceRoot":"","sources":["../../../src/pipes/ValidationPipe.ts"],"names":[],"mappings":"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","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,34 +1,49 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Inject, Injectable, InjectorService, ProviderScope } from "@tsed/di";
|
|
3
|
-
import {
|
|
4
|
-
import { ParamValidationError } from "../errors/ParamValidationError";
|
|
5
|
-
import { ParseExpressionPipe } from "../pipes/ParseExpressionPipe";
|
|
3
|
+
import { JsonMethodStore, JsonParameterStore } from "@tsed/schema";
|
|
4
|
+
import { ParamValidationError } from "../errors/ParamValidationError.js";
|
|
5
|
+
import { ParseExpressionPipe } from "../pipes/ParseExpressionPipe.js";
|
|
6
6
|
/**
|
|
7
7
|
* Platform Params abstraction layer.
|
|
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, handler }) {
|
|
25
|
+
if (!token || !propertyKey) {
|
|
26
|
+
return (scope) => handler(scope.$ctx);
|
|
27
|
+
}
|
|
28
|
+
const store = JsonMethodStore.fromMethod(token, propertyKey);
|
|
29
|
+
const getArguments = this.compile(store);
|
|
30
|
+
const provider = this.injector.getProvider(token);
|
|
31
|
+
return async (scope) => {
|
|
32
|
+
const container = provider.scope === ProviderScope.REQUEST ? scope.$ctx.container : undefined;
|
|
33
|
+
const [instance, args] = await Promise.all([this.injector.invoke(token, container), getArguments(scope)]);
|
|
34
|
+
return instance[propertyKey].call(instance, ...args, scope.$ctx);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
compile(entity) {
|
|
21
38
|
const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);
|
|
22
|
-
const argsPipes =
|
|
39
|
+
const argsPipes = params.map((param) => {
|
|
23
40
|
return {
|
|
24
41
|
param,
|
|
25
|
-
pipes:
|
|
42
|
+
pipes: this.getPipes(param)
|
|
26
43
|
};
|
|
27
|
-
})
|
|
44
|
+
});
|
|
28
45
|
return (scope) => {
|
|
29
|
-
const promises = argsPipes.map(({ param, pipes }) =>
|
|
30
|
-
return this.getArg(scope, pipes, param);
|
|
31
|
-
});
|
|
46
|
+
const promises = argsPipes.map(({ param, pipes }) => this.getArg(scope, pipes, param));
|
|
32
47
|
return Promise.all(promises);
|
|
33
48
|
};
|
|
34
49
|
}
|
|
@@ -43,24 +58,6 @@ let PlatformParams = class PlatformParams {
|
|
|
43
58
|
}
|
|
44
59
|
}, scope);
|
|
45
60
|
}
|
|
46
|
-
async compileHandler(metadata) {
|
|
47
|
-
const { token, propertyKey, getCustomArgs } = metadata;
|
|
48
|
-
const provider = this.injector.getProvider(token);
|
|
49
|
-
const getArguments = getCustomArgs || (await this.compile(JsonEntityStore.fromMethod(token, propertyKey)));
|
|
50
|
-
if (!provider || !provider.scope || provider.scope === ProviderScope.SINGLETON) {
|
|
51
|
-
const instance = await this.injector.invoke(token);
|
|
52
|
-
const handler = instance[propertyKey].bind(instance);
|
|
53
|
-
return async (scope) => {
|
|
54
|
-
const args = await getArguments(scope);
|
|
55
|
-
return handler(...args, scope.$ctx);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return async (scope) => {
|
|
59
|
-
const [instance, args] = await Promise.all([this.injector.invoke(token, scope.$ctx.container), getArguments(scope)]);
|
|
60
|
-
const handler = instance[propertyKey].bind(instance);
|
|
61
|
-
return handler(...args, scope.$ctx);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
61
|
};
|
|
65
62
|
__decorate([
|
|
66
63
|
Inject(),
|
|
@@ -69,7 +66,7 @@ __decorate([
|
|
|
69
66
|
PlatformParams = __decorate([
|
|
70
67
|
Injectable({
|
|
71
68
|
scope: ProviderScope.SINGLETON,
|
|
72
|
-
imports: []
|
|
69
|
+
imports: [ParseExpressionPipe]
|
|
73
70
|
})
|
|
74
71
|
], PlatformParams);
|
|
75
72
|
export { PlatformParams };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformParams.js","sourceRoot":"","sources":["../../../src/builder/PlatformParams.ts"],"names":[],"mappings":";AAAA,OAAO,EAAY,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAAgB,MAAM,UAAU,CAAC;AACtG,OAAO,EAAC,eAAe,EAAE,kBAAkB,
|
|
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 {JsonMethodStore, JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {ParamValidationError} from \"../errors/ParamValidationError\";\nimport {ParseExpressionPipe} from \"../pipes/ParseExpressionPipe\";\n\nexport type PlatformParamsScope<Context extends DIContext = DIContext> = {$ctx: Context} & Record<string, any>;\nexport type PlatformParamsCallback<Context extends DIContext = DIContext> = (scope: PlatformParamsScope) => Promise<any>;\n\n/**\n * Platform Params abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [ParseExpressionPipe]\n})\nexport class PlatformParams {\n @Inject()\n protected injector: InjectorService;\n\n getPipes(param: JsonParameterStore) {\n const get = (pipe: TokenProvider) => {\n return this.injector.getProvider(pipe)!.priority || 0;\n };\n\n const sort = (p1: TokenProvider, p2: TokenProvider) => (get(p1) < get(p2) ? -1 : get(p1) > get(p2) ? 1 : 0);\n const map = (token: TokenProvider) => this.injector.get<PipeMethods>(token)!;\n\n return [ParseExpressionPipe, ...param.pipes.sort(sort)].map(map).filter(Boolean);\n }\n\n /**\n * Return a handler with injectable parameters\n * @param handlerMetadata\n */\n compileHandler<Context extends DIContext = DIContext>({\n propertyKey,\n token,\n handler\n }: {\n propertyKey?: string | symbol;\n token?: any;\n handler?: any;\n }): PlatformParamsCallback<Context> {\n if (!token || !propertyKey) {\n return (scope: PlatformParamsScope) => handler(scope.$ctx);\n }\n\n const store = JsonMethodStore.fromMethod(token, propertyKey);\n const getArguments = this.compile<Context>(store);\n const provider = this.injector.getProvider(token)!;\n\n return async (scope: PlatformParamsScope) => {\n const container = provider.scope === ProviderScope.REQUEST ? scope.$ctx.container : undefined;\n const [instance, args] = await Promise.all([this.injector.invoke<any>(token, container), getArguments(scope)]);\n\n return instance[propertyKey].call(instance, ...args, scope.$ctx);\n };\n }\n\n compile<Context extends DIContext = DIContext>(entity: JsonMethodStore): PlatformParamsCallback<Context> {\n const params = JsonParameterStore.getParams(entity.target, entity.propertyKey);\n const argsPipes = params.map((param) => {\n return {\n param,\n pipes: this.getPipes(param)\n };\n });\n\n return (scope) => {\n const promises = argsPipes.map(({param, pipes}) => this.getArg(scope, pipes, param));\n return Promise.all(promises);\n };\n }\n\n async getArg<Context extends DIContext = DIContext>(scope: PlatformParamsScope, pipes: PipeMethods[], param: JsonParameterStore) {\n return pipes.reduce(async (value: any | Promise<any>, pipe) => {\n value = await value;\n\n try {\n return await pipe.transform(value, param);\n } catch (er) {\n throw ParamValidationError.from(param, er);\n }\n }, scope);\n }\n}\n"]}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { mapParamsOptions } from "../utils/mapParamsOptions";
|
|
5
|
-
import { JsonEntityFn } from "@tsed/schema";
|
|
1
|
+
import { ParamTypes } from "../domain/ParamTypes.js";
|
|
2
|
+
import { UseParam } from "./useParam.js";
|
|
3
|
+
import { mapParamsOptions } from "../utils/mapParamsOptions.js";
|
|
6
4
|
export function BodyParams(...args) {
|
|
7
5
|
const { expression, useType, useConverter = true, useValidation = true } = mapParamsOptions(args);
|
|
8
6
|
return UseParam({
|
|
9
7
|
paramType: ParamTypes.BODY,
|
|
10
|
-
dataPath: "$ctx.request.body",
|
|
11
8
|
expression,
|
|
12
9
|
useType,
|
|
13
10
|
useConverter,
|
|
@@ -32,17 +29,13 @@ export function BodyParams(...args) {
|
|
|
32
29
|
* @decorator
|
|
33
30
|
* @operation
|
|
34
31
|
* @input
|
|
32
|
+
* @alias BodyParams Example: @BodyParams() payload: Buffer
|
|
35
33
|
*/
|
|
36
34
|
export function RawBodyParams() {
|
|
37
|
-
return
|
|
35
|
+
return UseParam({
|
|
38
36
|
paramType: ParamTypes.RAW_BODY,
|
|
39
|
-
dataPath: "$ctx.request.rawBody",
|
|
40
|
-
useType: String,
|
|
41
37
|
useConverter: false,
|
|
42
38
|
useValidation: false
|
|
43
|
-
})
|
|
44
|
-
var _a;
|
|
45
|
-
(_a = entity.parent.operation) === null || _a === void 0 ? void 0 : _a.consumes(["*/*"]);
|
|
46
|
-
}));
|
|
39
|
+
});
|
|
47
40
|
}
|
|
48
41
|
//# sourceMappingURL=bodyParams.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bodyParams.js","sourceRoot":"","sources":["../../../src/decorators/bodyParams.ts"],"names":[],"mappings":"
|
|
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"]}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ParamTypes } from "../domain/ParamTypes";
|
|
2
|
-
import { mapParamsOptions } from "../utils/mapParamsOptions";
|
|
3
|
-
import { UseParam } from "./useParam";
|
|
1
|
+
import { ParamTypes } from "../domain/ParamTypes.js";
|
|
2
|
+
import { mapParamsOptions } from "../utils/mapParamsOptions.js";
|
|
3
|
+
import { UseParam } from "./useParam.js";
|
|
4
4
|
export function Context(...args) {
|
|
5
5
|
const { expression, useType, useConverter = false, useValidation = false } = mapParamsOptions(args);
|
|
6
6
|
return UseParam({
|
|
7
7
|
paramType: ParamTypes.$CTX,
|
|
8
|
-
dataPath: "$ctx",
|
|
9
8
|
expression,
|
|
10
9
|
useType,
|
|
11
10
|
useConverter,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/decorators/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/decorators/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAqDpC,MAAM,UAAU,OAAO,CAAC,GAAG,IAAW;IACpC,MAAM,EAAC,UAAU,EAAE,OAAO,EAAE,YAAY,GAAG,KAAK,EAAE,aAAa,GAAG,KAAK,EAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAElG,OAAO,QAAQ,CAAC;QACd,SAAS,EAAE,UAAU,CAAC,IAAI;QAC1B,UAAU;QACV,OAAO;QACP,YAAY;QACZ,aAAa;KACd,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {BaseContext} from \"@tsed/di\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\nimport {mapParamsOptions} from \"../utils/mapParamsOptions\";\nimport {UseParam} from \"./useParam\";\n\n/**\n * Context decorator return the @@PlatformContext@@ created by Ts.ED when request is handled by the server.\n *\n * It contains some information as following:\n *\n * - The request id,\n * - The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`,\n * - The current @@EndpointMetadata@@ resolved by Ts.ED during the request,\n * - The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty.\n *\n * ::: tip\n * The @@PlatformContext@@ inherit from Map class. So you can store any information with.\n * :::\n *\n * #### Example\n *\n * ```typescript\n * @Middleware()\n * class AuthTokenMiddleware {\n * use(@Req() request: Req, @Context() context: PlatformContext) {\n * if (!context.has(\"auth\")){\n * context.set('auth', new AuthToken(request))\n * }\n *\n * try {\n * context.get(\"auth\").claims() // check token\n * } catch(er){\n * throw new Forbidden(\"Access forbidden - Bad token\")\n * }\n * }\n * }\n *\n * @Controller('/')\n * @UseBefore(AuthTokenMiddleware) // protect all routes for this controller\n * class MyCtrl {\n * @Get('/')\n * get(@Context('auth') auth: AuthToken) {\n * console.log('auth', auth);\n * console.log('auth.accessToken', auth.accessToken);\n * console.log('auth.idToken', auth.idToken);\n * }\n * }\n * ```\n *\n * @param expression The path of the property to get.\n * @decorator\n * @operation\n * @input\n */\nexport function Context(expression: string): ParameterDecorator;\nexport function Context(): ParameterDecorator;\nexport function Context(...args: any[]): ParameterDecorator {\n const {expression, useType, useConverter = false, useValidation = false} = mapParamsOptions(args);\n\n return UseParam({\n paramType: ParamTypes.$CTX,\n expression,\n useType,\n useConverter,\n useValidation\n });\n}\n\nexport type Context = BaseContext;\n"]}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ParamTypes } from "../domain/ParamTypes";
|
|
2
|
-
import { mapParamsOptions } from "../utils/mapParamsOptions";
|
|
3
|
-
import { UseParam } from "./useParam";
|
|
1
|
+
import { ParamTypes } from "../domain/ParamTypes.js";
|
|
2
|
+
import { mapParamsOptions } from "../utils/mapParamsOptions.js";
|
|
3
|
+
import { UseParam } from "./useParam.js";
|
|
4
4
|
export function CookiesParams(...args) {
|
|
5
5
|
const { expression, useType, useConverter = false, useValidation = false } = mapParamsOptions(args);
|
|
6
6
|
return UseParam({
|
|
7
7
|
paramType: ParamTypes.COOKIES,
|
|
8
|
-
dataPath: "$ctx.request.cookies",
|
|
9
8
|
expression,
|
|
10
9
|
useType,
|
|
11
10
|
useConverter,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../../src/decorators/cookies.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAsCpC,MAAM,UAAU,aAAa,CAAC,GAAG,IAAW;IAC1C,MAAM,EAAC,UAAU,EAAE,OAAO,EAAE,YAAY,GAAG,KAAK,EAAE,aAAa,GAAG,KAAK,EAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAElG,OAAO,QAAQ,CAAC;QACd,SAAS,EAAE,UAAU,CAAC,OAAO;QAC7B,
|
|
1
|
+
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../../src/decorators/cookies.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAsCpC,MAAM,UAAU,aAAa,CAAC,GAAG,IAAW;IAC1C,MAAM,EAAC,UAAU,EAAE,OAAO,EAAE,YAAY,GAAG,KAAK,EAAE,aAAa,GAAG,KAAK,EAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAElG,OAAO,QAAQ,CAAC;QACd,SAAS,EAAE,UAAU,CAAC,OAAO;QAC7B,UAAU;QACV,OAAO;QACP,YAAY;QACZ,aAAa;KACd,CAAC,CAAC;AACL,CAAC;AA6CD,MAAM,UAAU,OAAO,CAAC,GAAG,IAAW;IACpC,aAAa;IACb,OAAO,aAAa,CAAC,GAAG,IAAI,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {ParamOptions} from \"../domain/ParamOptions\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\nimport {mapParamsOptions} from \"../utils/mapParamsOptions\";\nimport {UseParam} from \"./useParam\";\n\n/**\n * Cookies or CookiesParams return the value from [request.cookies](http://expressjs.com/en/4x/api.html#req.cookies) object.\n *\n * #### Example\n *\n * ```typescript\n * @Controller('/')\n * class MyCtrl {\n * @Post('/')\n * create(@Cookies() cookies: any) {\n * console.log('Entire cookies', cookies);\n * }\n *\n * @Post('/')\n * create(@Cookies('id') id: string) {\n * console.log('ID', id);\n * }\n *\n * @Post('/')\n * create(@Cookies('user') user: IUser) {\n * console.log('user', user);\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 CookiesParams(expression: string | any, useType: any): ParameterDecorator;\nexport function CookiesParams(): ParameterDecorator;\nexport function CookiesParams(expression: string | any): ParameterDecorator;\nexport function CookiesParams(options: ParamOptions<any>): ParameterDecorator;\nexport function CookiesParams(...args: any[]): ParameterDecorator {\n const {expression, useType, useConverter = false, useValidation = false} = mapParamsOptions(args);\n\n return UseParam({\n paramType: ParamTypes.COOKIES,\n expression,\n useType,\n useConverter,\n useValidation\n });\n}\n\n/**\n * Cookies or CookiesParams return the value from [request.cookies](http://expressjs.com/en/4x/api.html#req.cookies) object.\n *\n * #### Example\n *\n * ```typescript\n * @Controller('/')\n * class MyCtrl {\n * @Post('/')\n * create(@Cookies() body: any) {\n * console.log('Entire body', body);\n * }\n *\n * @Post('/')\n * create(@Cookies('id') id: string) {\n * console.log('ID', id);\n * }\n *\n * @Post('/')\n * create(@Cookies('user') user: User) { // with deserialization\n * console.log('user', user);\n * }\n *\n * @Post('/')\n * create(@Cookies('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 * @aliasof CookiesParams\n * @operation\n * @input\n */\nexport function Cookies(expression: string, useType: Type<any>): ParameterDecorator;\nexport function Cookies(expression: string): ParameterDecorator;\nexport function Cookies(useType: Type<any>): ParameterDecorator;\nexport function Cookies(options: Partial<ParamOptions>): ParameterDecorator;\nexport function Cookies(): ParameterDecorator;\nexport function Cookies(...args: any[]): ParameterDecorator {\n // @ts-ignore\n return CookiesParams(...args);\n}\n"]}
|