@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
|
@@ -3,6 +3,7 @@ import { __decorate, __metadata } from "tslib";
|
|
|
3
3
|
import { Constant, Injectable } from "@tsed/di";
|
|
4
4
|
import { deserialize } from "@tsed/json-mapper";
|
|
5
5
|
let DeserializerPipe = DeserializerPipe_1 = class DeserializerPipe {
|
|
6
|
+
settings;
|
|
6
7
|
transform(value, param) {
|
|
7
8
|
return deserialize(value, {
|
|
8
9
|
useAlias: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeserializerPipe.js","sourceRoot":"","sources":["../../../src/pipes/DeserializerPipe.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAI9C,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;
|
|
1
|
+
{"version":3,"file":"DeserializerPipe.js","sourceRoot":"","sources":["../../../src/pipes/DeserializerPipe.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAI9C,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IAEnB,QAAQ,CAEd;IAEF,SAAS,CAAC,KAAU,EAAE,KAAyB;QAC7C,OAAO,WAAW,CAAC,KAAK,EAAE;YACxB,QAAQ,EAAE,IAAI;YACd,oBAAoB,EAAE,IAAI,CAAC,QAAQ,CAAC,oBAAoB,KAAK,QAAQ;YACrE,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM;YAC9B,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;YACrC,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAgB,CAAC,IAAI,EAAE,CAAC;SAC7C,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAhBC;IADC,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC;;kDAGxB;AAJS,gBAAgB;IAD5B,UAAU,EAAE;GACA,gBAAgB,CAkB5B;SAlBY,gBAAgB","sourcesContent":["import {Constant, Injectable} from \"@tsed/di\";\nimport {deserialize} from \"@tsed/json-mapper\";\nimport {JsonParameterStore, PipeMethods} from \"@tsed/schema\";\n\n@Injectable()\nexport class DeserializerPipe implements PipeMethods {\n @Constant(\"converter\", {})\n private settings: {\n additionalProperties?: \"error\" | \"accept\" | \"ignore\";\n };\n\n transform(value: any, param: JsonParameterStore) {\n return deserialize(value, {\n useAlias: true,\n additionalProperties: this.settings.additionalProperties === \"accept\",\n type: param.type,\n collectionType: param.collectionType,\n groups: param.parameter.groups,\n genericTypes: param.nestedGenerics[0],\n nestedGenerics: param.nestedGenerics,\n ...(param.store.get(DeserializerPipe) || {})\n });\n }\n}\n"]}
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { getValue } from "@tsed/core";
|
|
3
3
|
import { Injectable } from "@tsed/di";
|
|
4
|
-
import { ParamTypes } from "../domain/ParamTypes";
|
|
4
|
+
import { ParamTypes } from "../domain/ParamTypes.js";
|
|
5
5
|
let ParseExpressionPipe = class ParseExpressionPipe {
|
|
6
6
|
transform(scope, param) {
|
|
7
7
|
const { paramType, type } = param;
|
|
8
|
-
const value = getValue(scope, param
|
|
8
|
+
const value = getValue(scope, this.getKey(param));
|
|
9
9
|
if ([ParamTypes.QUERY, ParamTypes.PATH].includes(paramType) && value === "" && type !== String) {
|
|
10
10
|
return undefined;
|
|
11
11
|
}
|
|
12
12
|
return value;
|
|
13
13
|
}
|
|
14
|
+
getKey(param) {
|
|
15
|
+
let { expression, paramType, dataPath } = param;
|
|
16
|
+
paramType = paramType || param.parameter.get("in").toUpperCase();
|
|
17
|
+
if (expression && paramType === ParamTypes.HEADER) {
|
|
18
|
+
expression = String(expression).toLowerCase();
|
|
19
|
+
}
|
|
20
|
+
return [dataPath, expression].filter(Boolean).join(".");
|
|
21
|
+
}
|
|
14
22
|
};
|
|
15
23
|
ParseExpressionPipe = __decorate([
|
|
16
24
|
Injectable({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParseExpressionPipe.js","sourceRoot":"","sources":["../../../src/pipes/ParseExpressionPipe.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"ParseExpressionPipe.js","sourceRoot":"","sources":["../../../src/pipes/ParseExpressionPipe.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAKhD,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAC9B,SAAS,CAAC,KAA0B,EAAE,KAAyB;QAC7D,MAAM,EAAC,SAAS,EAAE,IAAI,EAAC,GAAG,KAAK,CAAC;QAEhC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAElD,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAuB,CAAC,IAAI,KAAK,KAAK,EAAE,IAAI,IAAI,KAAK,MAAM,EAAE;YAC5G,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAES,MAAM,CAAC,KAAyB;QACxC,IAAI,EAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAC,GAAG,KAAK,CAAC;QAC9C,SAAS,GAAG,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAEjE,IAAI,UAAU,IAAI,SAAS,KAAK,UAAU,CAAC,MAAM,EAAE;YACjD,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;SAC/C;QAED,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;CACF,CAAA;AAvBY,mBAAmB;IAH/B,UAAU,CAAC;QACV,QAAQ,EAAE,CAAC,IAAI;KAChB,CAAC;GACW,mBAAmB,CAuB/B;SAvBY,mBAAmB","sourcesContent":["import {getValue} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {JsonParameterStore, PipeMethods} from \"@tsed/schema\";\nimport {PlatformParamsScope} from \"../builder/PlatformParams\";\nimport {ParamTypes} from \"../domain/ParamTypes\";\n\n@Injectable({\n priority: -1000\n})\nexport class ParseExpressionPipe implements PipeMethods {\n transform(scope: PlatformParamsScope, param: JsonParameterStore) {\n const {paramType, type} = param;\n\n const value = getValue(scope, this.getKey(param));\n\n if ([ParamTypes.QUERY, ParamTypes.PATH].includes(paramType as ParamTypes) && value === \"\" && type !== String) {\n return undefined;\n }\n\n return value;\n }\n\n protected getKey(param: JsonParameterStore) {\n let {expression, paramType, dataPath} = param;\n paramType = paramType || param.parameter.get(\"in\").toUpperCase();\n\n if (expression && paramType === ParamTypes.HEADER) {\n expression = String(expression).toLowerCase();\n }\n\n return [dataPath, expression].filter(Boolean).join(\".\");\n }\n}\n"]}
|
|
@@ -3,8 +3,8 @@ import { nameOf } from "@tsed/core";
|
|
|
3
3
|
import { Injectable, InjectorService } from "@tsed/di";
|
|
4
4
|
import { deserialize } from "@tsed/json-mapper";
|
|
5
5
|
import { getJsonSchema } from "@tsed/schema";
|
|
6
|
-
import { RequiredValidationError } from "../errors/RequiredValidationError";
|
|
7
|
-
import { ParamTypes } from "../domain/ParamTypes";
|
|
6
|
+
import { RequiredValidationError } from "../errors/RequiredValidationError.js";
|
|
7
|
+
import { ParamTypes } from "../domain/ParamTypes.js";
|
|
8
8
|
function cast(value, metadata) {
|
|
9
9
|
try {
|
|
10
10
|
return deserialize(value, {
|
|
@@ -16,6 +16,7 @@ function cast(value, metadata) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
let ValidationPipe = class ValidationPipe {
|
|
19
|
+
validator;
|
|
19
20
|
constructor(injector) {
|
|
20
21
|
const provider = injector.getProviders().find((provider) => nameOf(provider.token) === "AjvService");
|
|
21
22
|
if (provider) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationPipe.js","sourceRoot":"","sources":["../../../src/pipes/ValidationPipe.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,YAAY,CAAC;AAClC,OAAO,EAAC,UAAU,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AACrD,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAC,aAAa,
|
|
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,23 +1,25 @@
|
|
|
1
|
-
import { DIContext, InjectorService
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare type ArgScope<Context extends DIContext = DIContext> = {
|
|
1
|
+
import { DIContext, InjectorService } from "@tsed/di";
|
|
2
|
+
import { JsonMethodStore, JsonParameterStore, PipeMethods } from "@tsed/schema";
|
|
3
|
+
export declare type PlatformParamsScope<Context extends DIContext = DIContext> = {
|
|
5
4
|
$ctx: Context;
|
|
6
5
|
} & Record<string, any>;
|
|
7
|
-
export declare type
|
|
8
|
-
export interface CompileHandlerOptions<Context extends DIContext = DIContext> extends Record<any, unknown> {
|
|
9
|
-
token: TokenProvider;
|
|
10
|
-
propertyKey: string | symbol;
|
|
11
|
-
getCustomArgs?: (scope: ArgScope<Context>) => Promise<any[]>;
|
|
12
|
-
}
|
|
6
|
+
export declare type PlatformParamsCallback<Context extends DIContext = DIContext> = (scope: PlatformParamsScope) => Promise<any>;
|
|
13
7
|
/**
|
|
14
8
|
* Platform Params abstraction layer.
|
|
15
9
|
* @platform
|
|
16
10
|
*/
|
|
17
11
|
export declare class PlatformParams {
|
|
18
12
|
protected injector: InjectorService;
|
|
19
|
-
getPipes(param:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
getPipes(param: JsonParameterStore): PipeMethods<any, any>[];
|
|
14
|
+
/**
|
|
15
|
+
* Return a handler with injectable parameters
|
|
16
|
+
* @param handlerMetadata
|
|
17
|
+
*/
|
|
18
|
+
compileHandler<Context extends DIContext = DIContext>({ propertyKey, token, handler }: {
|
|
19
|
+
propertyKey?: string | symbol;
|
|
20
|
+
token?: any;
|
|
21
|
+
handler?: any;
|
|
22
|
+
}): PlatformParamsCallback<Context>;
|
|
23
|
+
compile<Context extends DIContext = DIContext>(entity: JsonMethodStore): PlatformParamsCallback<Context>;
|
|
24
|
+
getArg<Context extends DIContext = DIContext>(scope: PlatformParamsScope, pipes: PipeMethods[], param: JsonParameterStore): Promise<any>;
|
|
23
25
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DecoratorParameters } from "@tsed/core";
|
|
2
|
-
import {
|
|
2
|
+
import { JsonParameterStore } from "@tsed/schema";
|
|
3
3
|
/**
|
|
4
4
|
* Get the Param metadata. Use this decorator to compose your own decorator.
|
|
5
5
|
*
|
|
@@ -8,4 +8,4 @@ import { ParamMetadata } from "../domain/ParamMetadata";
|
|
|
8
8
|
* @operation
|
|
9
9
|
* @input
|
|
10
10
|
*/
|
|
11
|
-
export declare function ParamFn(fn: (param:
|
|
11
|
+
export declare function ParamFn(fn: (param: JsonParameterStore, parameters: DecoratorParameters) => void): ParameterDecorator;
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { JsonEntityStoreOptions, JsonParameterStore } from "@tsed/schema";
|
|
3
|
-
import { ParamOptions } from "./ParamOptions";
|
|
4
|
-
export interface PipeMethods<T = any, R = any> {
|
|
5
|
-
transform(value: T, metadata: ParamMetadata): R;
|
|
6
|
-
}
|
|
7
|
-
export declare type ParamConstructorOptions = JsonEntityStoreOptions & ParamOptions;
|
|
8
|
-
export declare class ParamMetadata extends JsonParameterStore implements ParamConstructorOptions {
|
|
9
|
-
expression: string;
|
|
10
|
-
dataPath: string;
|
|
11
|
-
paramType: string;
|
|
12
|
-
pipes: Type<PipeMethods>[];
|
|
13
|
-
constructor(options: ParamConstructorOptions);
|
|
14
|
-
get key(): string;
|
|
15
|
-
static get(target: Type<any>, propertyKey: string | symbol, index: number): ParamMetadata;
|
|
16
|
-
}
|
|
1
|
+
export { ParamMetadata } from "@tsed/schema";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BadRequest } from "@tsed/exceptions";
|
|
2
|
-
import {
|
|
2
|
+
import { JsonParameterStore } from "@tsed/schema";
|
|
3
3
|
export declare class ParamValidationError extends BadRequest {
|
|
4
4
|
name: string;
|
|
5
5
|
dataPath: string;
|
|
6
6
|
requestType: string;
|
|
7
|
-
static from(metadata:
|
|
7
|
+
static from(metadata: JsonParameterStore, origin?: any): any;
|
|
8
8
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ParamMetadata } from "../domain/ParamMetadata";
|
|
2
1
|
import { ValidationError } from "./ValidationError";
|
|
2
|
+
import { JsonParameterStore } from "@tsed/schema";
|
|
3
3
|
export declare class RequiredValidationError extends ValidationError {
|
|
4
4
|
name: string;
|
|
5
|
-
static from(metadata:
|
|
5
|
+
static from(metadata: JsonParameterStore): RequiredValidationError;
|
|
6
6
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PipeMethods } from "@tsed/schema";
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./pipes/ParseExpressionPipe";
|
|
6
|
-
export * from "./pipes/DeserializerPipe";
|
|
7
|
-
export * from "./pipes/ValidationPipe";
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./exports";
|
|
8
5
|
export * from "./builder/PlatformParams";
|
|
9
|
-
export * from "./errors/RequiredValidationError";
|
|
10
|
-
export * from "./errors/ValidationError";
|
|
11
|
-
export * from "./errors/ParamValidationError";
|
|
12
|
-
export * from "./decorators/context";
|
|
13
6
|
export * from "./decorators/bodyParams";
|
|
14
|
-
export * from "./decorators/
|
|
15
|
-
export * from "./decorators/useParam";
|
|
16
|
-
export * from "./decorators/useParamType";
|
|
17
|
-
export * from "./decorators/useType";
|
|
18
|
-
export * from "./decorators/useValidation";
|
|
19
|
-
export * from "./decorators/useDeserialization";
|
|
20
|
-
export * from "./decorators/useParamExpression";
|
|
21
|
-
export * from "./decorators/useParamType";
|
|
22
|
-
export * from "./decorators/headerParams";
|
|
7
|
+
export * from "./decorators/context";
|
|
23
8
|
export * from "./decorators/cookies";
|
|
9
|
+
export * from "./decorators/headerParams";
|
|
24
10
|
export * from "./decorators/locals";
|
|
11
|
+
export * from "./decorators/paramFn";
|
|
25
12
|
export * from "./decorators/pathParams";
|
|
26
13
|
export * from "./decorators/queryParams";
|
|
27
14
|
export * from "./decorators/session";
|
|
28
|
-
export * from "./decorators/
|
|
15
|
+
export * from "./decorators/useDeserialization";
|
|
16
|
+
export * from "./decorators/useParam";
|
|
17
|
+
export * from "./decorators/useParamExpression";
|
|
18
|
+
export * from "./decorators/useParamType";
|
|
19
|
+
export * from "./decorators/usePipe";
|
|
20
|
+
export * from "./decorators/useType";
|
|
21
|
+
export * from "./decorators/useValidation";
|
|
22
|
+
export * from "./domain/ParamMetadata";
|
|
23
|
+
export * from "./domain/ParamOptions";
|
|
24
|
+
export * from "./domain/ParamTypes";
|
|
25
|
+
export * from "./errors/ParamValidationError";
|
|
26
|
+
export * from "./errors/RequiredValidationError";
|
|
27
|
+
export * from "./errors/ValidationError";
|
|
28
|
+
export * from "./pipes/DeserializerPipe";
|
|
29
|
+
export * from "./pipes/ParseExpressionPipe";
|
|
30
|
+
export * from "./pipes/ValidationPipe";
|
|
31
|
+
export * from "./utils/mapParamsOptions";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsonParameterStore, PipeMethods } from "@tsed/schema";
|
|
2
2
|
export declare class DeserializerPipe implements PipeMethods {
|
|
3
3
|
private settings;
|
|
4
|
-
transform(value: any, param:
|
|
4
|
+
transform(value: any, param: JsonParameterStore): any;
|
|
5
5
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { JsonParameterStore, PipeMethods } from "@tsed/schema";
|
|
2
|
+
import { PlatformParamsScope } from "../builder/PlatformParams";
|
|
3
3
|
export declare class ParseExpressionPipe implements PipeMethods {
|
|
4
|
-
transform(scope:
|
|
4
|
+
transform(scope: PlatformParamsScope, param: JsonParameterStore): any;
|
|
5
|
+
protected getKey(param: JsonParameterStore): string;
|
|
5
6
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { InjectorService } from "@tsed/di";
|
|
2
|
-
import {
|
|
2
|
+
import { JsonParameterStore, PipeMethods } from "@tsed/schema";
|
|
3
3
|
export declare class ValidationPipe implements PipeMethods {
|
|
4
4
|
private validator;
|
|
5
5
|
constructor(injector: InjectorService);
|
|
6
|
-
coerceTypes(value: any, metadata:
|
|
7
|
-
skip(value: any, metadata:
|
|
8
|
-
transform(value: any, metadata:
|
|
9
|
-
protected checkIsRequired(value: any, metadata:
|
|
6
|
+
coerceTypes(value: any, metadata: JsonParameterStore): any;
|
|
7
|
+
skip(value: any, metadata: JsonParameterStore): boolean;
|
|
8
|
+
transform(value: any, metadata: JsonParameterStore): Promise<any>;
|
|
9
|
+
protected checkIsRequired(value: any, metadata: JsonParameterStore): boolean;
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-params",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.20",
|
|
4
4
|
"description": "Params module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/cjs/index.js",
|
|
8
|
+
"module": "./lib/esm/index.js",
|
|
8
9
|
"typings": "./lib/types/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
"types": "./lib/types/index.d.ts",
|
|
@@ -13,32 +14,54 @@
|
|
|
13
14
|
"default": "./lib/esm/index.js"
|
|
14
15
|
},
|
|
15
16
|
"scripts": {
|
|
16
|
-
"build": "yarn run build:esm && yarn run build:cjs",
|
|
17
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
17
18
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
18
|
-
"build:esm": "tsc --build tsconfig.compile.esm.json"
|
|
19
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
21
|
+
"test": "cross-env NODE_ENV=test yarn jest --max-workers=2"
|
|
19
22
|
},
|
|
20
23
|
"dependencies": {
|
|
21
|
-
"tslib": "2.
|
|
24
|
+
"tslib": "2.4.0"
|
|
22
25
|
},
|
|
23
26
|
"devDependencies": {
|
|
24
|
-
"@tsed/core": "7.0.0-beta.
|
|
25
|
-
"@tsed/di": "7.0.0-beta.
|
|
26
|
-
"@tsed/exceptions": "7.0.0-beta.
|
|
27
|
-
"@tsed/json-mapper": "7.0.0-beta.
|
|
28
|
-
"@tsed/schema": "7.0.0-beta.
|
|
27
|
+
"@tsed/core": "7.0.0-beta.20",
|
|
28
|
+
"@tsed/di": "7.0.0-beta.20",
|
|
29
|
+
"@tsed/exceptions": "7.0.0-beta.20",
|
|
30
|
+
"@tsed/json-mapper": "7.0.0-beta.20",
|
|
31
|
+
"@tsed/schema": "7.0.0-beta.20"
|
|
29
32
|
},
|
|
30
33
|
"peerDependencies": {
|
|
31
|
-
"@tsed/core": "^7.0.0-beta.
|
|
32
|
-
"@tsed/di": "^7.0.0-beta.
|
|
33
|
-
"@tsed/exceptions": "^7.0.0-beta.
|
|
34
|
-
"@tsed/json-mapper": "^7.0.0-beta.
|
|
35
|
-
"@tsed/schema": "^7.0.0-beta.
|
|
34
|
+
"@tsed/core": "^7.0.0-beta.20",
|
|
35
|
+
"@tsed/di": "^7.0.0-beta.20",
|
|
36
|
+
"@tsed/exceptions": "^7.0.0-beta.20",
|
|
37
|
+
"@tsed/json-mapper": "^7.0.0-beta.20",
|
|
38
|
+
"@tsed/schema": "^7.0.0-beta.20"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"@tsed/core": {
|
|
42
|
+
"optional": false
|
|
43
|
+
},
|
|
44
|
+
"@tsed/di": {
|
|
45
|
+
"optional": false
|
|
46
|
+
},
|
|
47
|
+
"@tsed/exceptions": {
|
|
48
|
+
"optional": false
|
|
49
|
+
},
|
|
50
|
+
"@tsed/json-mapper": {
|
|
51
|
+
"optional": false
|
|
52
|
+
},
|
|
53
|
+
"@tsed/schema": {
|
|
54
|
+
"optional": false
|
|
55
|
+
}
|
|
36
56
|
},
|
|
37
57
|
"repository": "https://github.com/tsedio/tsed",
|
|
38
58
|
"bugs": {
|
|
39
59
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
40
60
|
},
|
|
41
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
61
|
+
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/platform/platform-params",
|
|
42
62
|
"author": "Romain Lenzotti",
|
|
43
|
-
"license": "MIT"
|
|
63
|
+
"license": "MIT",
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"tag": "beta"
|
|
66
|
+
}
|
|
44
67
|
}
|
package/readme.md
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
[](https://badge.fury.io/js/%40tsed%2Fcommon)
|
|
12
12
|
[](https://github.com/semantic-release/semantic-release)
|
|
13
13
|
[](https://github.com/prettier/prettier)
|
|
14
|
-
[](https://github.com/sponsors/romakita)
|
|
15
|
+
[](https://opencollective.com/tsed)
|
|
15
16
|
|
|
16
17
|
</div>
|
|
17
18
|
|
|
@@ -36,18 +37,17 @@ npm install --save @tsed/platform-params
|
|
|
36
37
|
```
|
|
37
38
|
|
|
38
39
|
## Contributors
|
|
40
|
+
|
|
39
41
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html).
|
|
40
42
|
|
|
41
43
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
42
44
|
|
|
43
|
-
|
|
44
45
|
## Backers
|
|
45
46
|
|
|
46
47
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
47
48
|
|
|
48
49
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
|
|
49
50
|
|
|
50
|
-
|
|
51
51
|
## Sponsors
|
|
52
52
|
|
|
53
53
|
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
@@ -56,7 +56,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
56
56
|
|
|
57
57
|
The MIT License (MIT)
|
|
58
58
|
|
|
59
|
-
Copyright (c) 2016 -
|
|
59
|
+
Copyright (c) 2016 - 2022 Romain Lenzotti
|
|
60
60
|
|
|
61
61
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
62
62
|
|
|
@@ -8,16 +8,5 @@
|
|
|
8
8
|
"declaration": true,
|
|
9
9
|
"declarationDir": "./lib/types"
|
|
10
10
|
},
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules",
|
|
13
|
-
"test",
|
|
14
|
-
"lib",
|
|
15
|
-
"benchmark",
|
|
16
|
-
"coverage",
|
|
17
|
-
"spec",
|
|
18
|
-
"**/*.benchmark.ts",
|
|
19
|
-
"**/*.spec.ts",
|
|
20
|
-
"keys",
|
|
21
|
-
"jest.config.js"
|
|
22
|
-
]
|
|
11
|
+
"exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
23
12
|
}
|