class-validator
Advanced tools
Comparing version 0.4.0-alpha.4 to 0.4.0
@@ -6,9 +6,20 @@ import { ValidationError } from "./validation/ValidationError"; | ||
/** | ||
* Container options. | ||
*/ | ||
export interface UseContainerOptions { | ||
/** | ||
* If set to true, then default container will be used in the case if given container haven't returned anything. | ||
*/ | ||
fallback?: boolean; | ||
/** | ||
* If set to true, then default container will be used in the case if given container thrown an exception. | ||
*/ | ||
fallbackOnErrors?: boolean; | ||
} | ||
/** | ||
* Sets container to be used by this library. | ||
* | ||
* @param iocContainer | ||
*/ | ||
export declare function useContainer(iocContainer: { | ||
get(someClass: any): any; | ||
}): void; | ||
}, options?: UseContainerOptions): void; | ||
/** | ||
@@ -15,0 +26,0 @@ * Gets the IOC container used by this library. |
29
index.js
@@ -10,5 +10,2 @@ "use strict"; | ||
var Validator_1 = require("./validation/Validator"); | ||
// ------------------------------------------------------------------------- | ||
// Global Container | ||
// ------------------------------------------------------------------------- | ||
/** | ||
@@ -18,3 +15,3 @@ * Container to be used by this library for inversion control. If container was not implicitly set then by default | ||
*/ | ||
var container = new ((function () { | ||
var defaultContainer = new ((function () { | ||
function class_1() { | ||
@@ -30,9 +27,10 @@ this.instances = []; | ||
}()))(); | ||
var userContainer; | ||
var userContainerOptions; | ||
/** | ||
* Sets container to be used by this library. | ||
* | ||
* @param iocContainer | ||
*/ | ||
function useContainer(iocContainer) { | ||
container = iocContainer; | ||
function useContainer(iocContainer, options) { | ||
userContainer = iocContainer; | ||
userContainerOptions = options; | ||
} | ||
@@ -44,3 +42,16 @@ exports.useContainer = useContainer; | ||
function getFromContainer(someClass) { | ||
return container.get(someClass); | ||
if (userContainer) { | ||
try { | ||
var instance = userContainer.get(someClass); | ||
if (instance) | ||
return instance; | ||
if (!userContainerOptions || !userContainerOptions.fallback) | ||
return instance; | ||
} | ||
catch (error) { | ||
if (!userContainerOptions || !userContainerOptions.fallbackOnErrors) | ||
throw error; | ||
} | ||
} | ||
return defaultContainer.get(someClass); | ||
} | ||
@@ -47,0 +58,0 @@ exports.getFromContainer = getFromContainer; |
{ | ||
"name": "class-validator", | ||
"private": false, | ||
"version": "0.4.0-alpha.4", | ||
"version": "0.4.0", | ||
"description": "Class-based validation in Typescript using decorators", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -71,3 +71,3 @@ # class-validator | ||
`validate` method returns you an array of `ValidationError`-s. Each ValidationError is: | ||
`validate` method returns you an array of `ValidationError` objects. Each `ValidationError` is: | ||
@@ -94,3 +94,3 @@ ```javascript | ||
constraints: { | ||
length: "" | ||
length: "$property must be shorter than 10 characters" | ||
} | ||
@@ -102,3 +102,3 @@ }, { | ||
constraints: { | ||
contains: "" | ||
contains: "text must contain a hello string" | ||
} | ||
@@ -105,0 +105,0 @@ }, |
@@ -136,13 +136,13 @@ "use strict"; | ||
if (isMinLength && (!args.value || args.value.length < args.constraints[0])) { | ||
return eachPrefix + "$property must be longer than $constraint1"; | ||
return eachPrefix + "$property must be longer than $constraint1 characters"; | ||
} | ||
else if (isMaxLength && (args.value.length > args.constraints[1])) { | ||
return eachPrefix + "$property must be shorter than $constraint2"; | ||
return eachPrefix + "$property must be shorter than $constraint2 characters"; | ||
} | ||
return eachPrefix + "$property must be longer than $constraint1 and shorter than $constraint2"; | ||
return eachPrefix + "$property must be longer than $constraint1 and shorter than $constraint2 characters"; | ||
}; | ||
case this.MIN_LENGTH: | ||
return eachPrefix + "$property must be longer than $constraint1"; | ||
return eachPrefix + "$property must be longer than $constraint1 characters"; | ||
case this.MAX_LENGTH: | ||
return eachPrefix + "$property must be shorter than $constraint1"; | ||
return eachPrefix + "$property must be shorter than $constraint1 characters"; | ||
case this.MATCHES: | ||
@@ -149,0 +149,0 @@ return eachPrefix + "$property must match $constraint1 regular expression"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
249616
3520