Comparing version 1.1.22 to 1.1.23
@@ -29,9 +29,20 @@ export declare function Controller(name: any): (target: any, property: any) => void; | ||
} | ||
export declare function Validator(options: any): (target: any, property: any, descriptor: any) => void; | ||
declare interface ValidatorDescriptor { | ||
[paramName: string]: Function | Boolean | string | RegExp | { | ||
required: boolean; | ||
valid: Function; | ||
pattern: string | RegExp; | ||
}; | ||
} | ||
export declare function Validator(options: ValidatorDescriptor): (target: any, property: any, descriptor: any) => void; | ||
export declare namespace Validator { | ||
var keys: string[]; | ||
} | ||
declare type Converters = 'string2bigint' | 'string2int' | 'string2float' | 'convert'; | ||
declare interface ConverterDescriptor { | ||
[paramName: string]: Function | Converters | Object; | ||
} | ||
export declare class ParamDescriber { | ||
readonly validator: any; | ||
readonly converter: any; | ||
readonly validator: ValidatorDescriptor; | ||
readonly converter: ConverterDescriptor; | ||
} | ||
@@ -49,1 +60,2 @@ export declare function Param(describer: ParamDescriber): (target: any, property: any, descriptor: any) => void; | ||
} | ||
export {}; |
@@ -0,3 +1,4 @@ | ||
import { HttpMessageConverter } from "./MessageConverter"; | ||
export default class Parameter { | ||
readonly messageConverters: any[]; | ||
readonly messageConverters: HttpMessageConverter[]; | ||
readonly paramConverter: any; | ||
@@ -4,0 +5,0 @@ readonly params: Array<any>; |
@@ -149,16 +149,22 @@ "use strict"; | ||
let validator = validators[param]; | ||
if (validator === true) { | ||
if (!value) { | ||
errors.push(`Require parameter ${param}, but not found`); | ||
} | ||
let required = validator.required || validator === true; | ||
if (required && !value) { | ||
errors.push(`Require parameter ${param}, but not found`); | ||
return; | ||
} | ||
else if (typeof validator === "function") { | ||
let rs = validator.call(this.parameters, value, param); | ||
let valid = validator.valid || validator; | ||
if (typeof valid === "function") { | ||
let rs = valid.call(this.parameters, value, param); | ||
if (rs === false) { | ||
errors.push(`Parameter ${param} invalid`); | ||
return; | ||
} | ||
} | ||
else if (typeof validator === 'string' || validator instanceof RegExp) { | ||
if (!(validator instanceof RegExp ? validator : new RegExp(validator)).test((value || '').toString())) { | ||
let pattern = validator.pattern || validator; | ||
if (typeof pattern === 'string' || pattern instanceof RegExp) { | ||
if (typeof pattern === 'string') | ||
pattern = new RegExp(pattern); | ||
if (!pattern.test(`${value || ''}`)) { | ||
errors.push(`Parameter ${param} not matches`); | ||
return; | ||
} | ||
@@ -165,0 +171,0 @@ } |
{ | ||
"name": "vweb-mvc", | ||
"version": "1.1.22", | ||
"version": "1.1.23", | ||
"description": "mvc ", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64221
1680