aurelia-validation
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -1,2 +0,2 @@ | ||
import { AccessKeyed, AccessMember, AccessScope, Binary, Binding, BindingBehavior, CallMember, Conditional, Expression, Parser, Scope, ValueConverter } from 'aurelia-binding'; | ||
import { AccessKeyed, AccessMember, AccessScope, Binary, Binding, BindingBehavior, CallMember, Conditional, Expression, LiteralPrimitive, LiteralString, Parser, Scope, ValueConverter } from 'aurelia-binding'; | ||
import { Container, Lazy } from 'aurelia-dependency-injection'; | ||
@@ -31,2 +31,70 @@ import { DOM } from 'aurelia-pal'; | ||
/** | ||
* Validates objects and properties. | ||
*/ | ||
export declare abstract class Validator { | ||
/** | ||
* Validates the specified property. | ||
* @param object The object to validate. | ||
* @param propertyName The name of the property to validate. | ||
* @param rules Optional. If unspecified, the implementation should lookup the rules for the | ||
* specified object. This may not be possible for all implementations of this interface. | ||
*/ | ||
abstract validateProperty(object: any, propertyName: string, rules?: any): Promise<ValidateResult[]>; | ||
/** | ||
* Validates all rules for specified object and it's properties. | ||
* @param object The object to validate. | ||
* @param rules Optional. If unspecified, the implementation should lookup the rules for the | ||
* specified object. This may not be possible for all implementations of this interface. | ||
*/ | ||
abstract validateObject(object: any, rules?: any): Promise<ValidateResult[]>; | ||
/** | ||
* Determines whether a rule exists in a set of rules. | ||
* @param rules The rules to search. | ||
* @parem rule The rule to find. | ||
*/ | ||
abstract ruleExists(rules: any, rule: any): boolean; | ||
} | ||
/** | ||
* Validation triggers. | ||
*/ | ||
export declare enum validateTrigger { | ||
/** | ||
* Manual validation. Use the controller's `validate()` and `reset()` methods | ||
* to validate all bindings. | ||
*/ | ||
manual = 0, | ||
/** | ||
* Validate the binding when the binding's target element fires a DOM "blur" event. | ||
*/ | ||
blur = 1, | ||
/** | ||
* Validate the binding when it updates the model due to a change in the view. | ||
*/ | ||
change = 2, | ||
/** | ||
* Validate the binding when the binding's target element fires a DOM "blur" event and | ||
* when it updates the model due to a change in the view. | ||
*/ | ||
changeOrBlur = 3 | ||
} | ||
export declare type ValidatorCtor = new (...args: any[]) => Validator; | ||
/** | ||
* Aurelia Validation Configuration API | ||
*/ | ||
export declare class GlobalValidationConfiguration { | ||
static DEFAULT_VALIDATION_TRIGGER: validateTrigger; | ||
private validatorType; | ||
private validationTrigger; | ||
/** | ||
* Use a custom Validator implementation. | ||
*/ | ||
customValidator(type: ValidatorCtor): this; | ||
defaultValidationTrigger(trigger: validateTrigger): this; | ||
getDefaultValidationTrigger(): validateTrigger; | ||
/** | ||
* Applies the configuration. | ||
*/ | ||
apply(container: Container): void; | ||
} | ||
/** | ||
* Instructions for the validation controller's validate method. | ||
@@ -90,51 +158,2 @@ */ | ||
/** | ||
* Validates objects and properties. | ||
*/ | ||
export declare abstract class Validator { | ||
/** | ||
* Validates the specified property. | ||
* @param object The object to validate. | ||
* @param propertyName The name of the property to validate. | ||
* @param rules Optional. If unspecified, the implementation should lookup the rules for the | ||
* specified object. This may not be possible for all implementations of this interface. | ||
*/ | ||
abstract validateProperty(object: any, propertyName: string, rules?: any): Promise<ValidateResult[]>; | ||
/** | ||
* Validates all rules for specified object and it's properties. | ||
* @param object The object to validate. | ||
* @param rules Optional. If unspecified, the implementation should lookup the rules for the | ||
* specified object. This may not be possible for all implementations of this interface. | ||
*/ | ||
abstract validateObject(object: any, rules?: any): Promise<ValidateResult[]>; | ||
/** | ||
* Determines whether a rule exists in a set of rules. | ||
* @param rules The rules to search. | ||
* @parem rule The rule to find. | ||
*/ | ||
abstract ruleExists(rules: any, rule: any): boolean; | ||
} | ||
/** | ||
* Validation triggers. | ||
*/ | ||
export declare enum validateTrigger { | ||
/** | ||
* Manual validation. Use the controller's `validate()` and `reset()` methods | ||
* to validate all bindings. | ||
*/ | ||
manual = 0, | ||
/** | ||
* Validate the binding when the binding's target element fires a DOM "blur" event. | ||
*/ | ||
blur = 1, | ||
/** | ||
* Validate the binding when it updates the model due to a change in the view. | ||
*/ | ||
change = 2, | ||
/** | ||
* Validate the binding when the binding's target element fires a DOM "blur" event and | ||
* when it updates the model due to a change in the view. | ||
*/ | ||
changeOrBlur = 3 | ||
} | ||
/** | ||
* A result to render (or unrender) and the associated elements (if any) | ||
@@ -247,3 +266,3 @@ */ | ||
private propertyParser; | ||
static inject: (typeof PropertyAccessorParser | typeof Validator)[]; | ||
static inject: (typeof Validator | typeof GlobalValidationConfiguration | typeof PropertyAccessorParser)[]; | ||
private bindings; | ||
@@ -271,3 +290,3 @@ private renderers; | ||
private eventCallbacks; | ||
constructor(validator: Validator, propertyParser: PropertyAccessorParser); | ||
constructor(validator: Validator, propertyParser: PropertyAccessorParser, config?: GlobalValidationConfiguration); | ||
/** | ||
@@ -506,31 +525,20 @@ * Subscribe to controller validate and reset events. These events occur when the | ||
} | ||
export declare type Chain = any; | ||
export declare type Assign = any; | ||
export declare type AccessThis = any; | ||
export declare type AccessScope = any; | ||
export declare type CallScope = any; | ||
export declare type CallFunction = any; | ||
export declare type PrefixNot = any; | ||
export declare type LiteralPrimitive = any; | ||
export declare type LiteralArray = any; | ||
export declare type LiteralObject = any; | ||
export declare type LiteralString = any; | ||
declare class ExpressionVisitor { | ||
visitChain(chain: Chain): void; | ||
visitChain(chain: any): void; | ||
visitBindingBehavior(behavior: BindingBehavior): void; | ||
visitValueConverter(converter: ValueConverter): void; | ||
visitAssign(assign: Assign): void; | ||
visitAssign(assign: any): void; | ||
visitConditional(conditional: Conditional): void; | ||
visitAccessThis(access: AccessThis): void; | ||
visitAccessThis(access: any): void; | ||
visitAccessScope(access: AccessScope): void; | ||
visitAccessMember(access: AccessMember): void; | ||
visitAccessKeyed(access: AccessKeyed): void; | ||
visitCallScope(call: CallScope): void; | ||
visitCallFunction(call: CallFunction): void; | ||
visitCallScope(call: any): void; | ||
visitCallFunction(call: any): void; | ||
visitCallMember(call: CallMember): void; | ||
visitPrefix(prefix: PrefixNot): void; | ||
visitPrefix(prefix: any): void; | ||
visitBinary(binary: Binary): void; | ||
visitLiteralPrimitive(literal: LiteralPrimitive): void; | ||
visitLiteralArray(literal: LiteralArray): void; | ||
visitLiteralObject(literal: LiteralObject): void; | ||
visitLiteralArray(literal: any): void; | ||
visitLiteralObject(literal: any): void; | ||
visitLiteralString(literal: LiteralString): void; | ||
@@ -664,3 +672,3 @@ private visitArgs; | ||
*/ | ||
readonly rules: Rule<TObject, any>[][]; | ||
get rules(): Rule<TObject, any>[][]; | ||
/** | ||
@@ -927,18 +935,2 @@ * Applies the rules to a class or object, making them discoverable by the StandardValidator. | ||
/** | ||
* Aurelia Validation Configuration API | ||
*/ | ||
export declare class AureliaValidationConfiguration { | ||
private validatorType; | ||
/** | ||
* Use a custom Validator implementation. | ||
*/ | ||
customValidator(type: { | ||
new (...args: any[]): Validator; | ||
}): void; | ||
/** | ||
* Applies the configuration. | ||
*/ | ||
apply(container: Container): void; | ||
} | ||
/** | ||
* Configures the plugin. | ||
@@ -949,2 +941,2 @@ */ | ||
globalResources?: (...resources: any[]) => any; | ||
}, callback?: (config: AureliaValidationConfiguration) => void): void; | ||
}, callback?: (config: GlobalValidationConfiguration) => void): void; |
@@ -5,2 +5,20 @@ # Change Log | ||
# [1.6.0](https://github.com/aurelia/validation/compare/1.5.0...1.6.0) (2019-12-18) | ||
### Bug Fixes | ||
* **all:** update binding library and fix TS errors ([33c91a1](https://github.com/aurelia/validation/commit/33c91a1120c0cc41a3a1bb093aca7fd682d56e34)) | ||
* **ExpressionVisitor:** not redeclare imports ([15109b3](https://github.com/aurelia/validation/commit/15109b3a82f0d0ecebaf19c7b1490c4373731c13)), closes [#537](https://github.com/aurelia/validation/issues/537) | ||
### Features | ||
* **config:** make config constructor param optional and place default trigger in static property ([a52f4c4](https://github.com/aurelia/validation/commit/a52f4c403bb68ed895fd0b7a3ea217c67ce22e2d)) | ||
* **config:** make the setters chainable ([bd118a6](https://github.com/aurelia/validation/commit/bd118a61c9cb283cbb9db36712660a0362f5994c)) | ||
* **config:** rename global config class ([c4e5fe2](https://github.com/aurelia/validation/commit/c4e5fe29e2a9bcd11cfdaba0f70050ef9c894be6)) | ||
* **config:** support global config option for default validation trigger ([39a4e67](https://github.com/aurelia/validation/commit/39a4e679513e3fa716b46cedce24931b3b57028f)) | ||
## [1.5.0](https://github.com/aurelia/validation/compare/1.4.0...1.5.0) (2019-08-09) | ||
@@ -7,0 +25,0 @@ |
{ | ||
"name": "aurelia-validation", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Validation for Aurelia applications", | ||
@@ -21,3 +21,2 @@ "keywords": [ | ||
"types": "dist/aurelia-validation.d.ts", | ||
"typings": "dist/aurelia-validation.d.ts", | ||
"repository": { | ||
@@ -38,3 +37,3 @@ "type": "git", | ||
"pretest": "cross-env npm run lint", | ||
"test": "cross-env rimraf dist && tsc && karma start --single-run", | ||
"test": "cross-env rimraf dist/test dist/src && tsc && karma start --single-run", | ||
"develop": "concurrently \"./node_modules/.bin/tsc --watch\" \"./node_modules/.bin/karma start\"", | ||
@@ -60,3 +59,3 @@ "prebuild": "cross-env rimraf dist", | ||
"peerDependencies": { | ||
"aurelia-binding": "^2.1.5", | ||
"aurelia-binding": "^2.5.2", | ||
"aurelia-dependency-injection": "^1.5.0", | ||
@@ -69,3 +68,3 @@ "aurelia-logging": "^1.5.0", | ||
"dependencies": { | ||
"aurelia-binding": "^2.1.5", | ||
"aurelia-binding": "^2.5.2", | ||
"aurelia-dependency-injection": "^1.4.1", | ||
@@ -80,3 +79,3 @@ "aurelia-logging": "^1.5.0", | ||
"dependencies": { | ||
"aurelia-binding": "^2.1.5", | ||
"aurelia-binding": "^2.5.2", | ||
"aurelia-dependency-injection": "^1.5.0", | ||
@@ -112,5 +111,5 @@ "aurelia-logging": "^1.5.0", | ||
"rollup": "^0.66.2", | ||
"rollup-plugin-typescript2": "^0.17.0", | ||
"rollup-plugin-typescript2": "^0.25.3", | ||
"standard-version": "^5.0.2", | ||
"tslib": "^1.9.3", | ||
"tslib": "^1.10.0", | ||
"tslint": "^5.11.0", | ||
@@ -117,0 +116,0 @@ "typedoc": "^0.12.0", |
// Exports | ||
export * from './config'; | ||
export * from './controller-validate-result'; | ||
@@ -29,4 +30,3 @@ export * from './get-target-dom-element'; | ||
import { Container } from 'aurelia-dependency-injection'; | ||
import { Validator } from './validator'; | ||
import { StandardValidator } from './implementation/standard-validator'; | ||
import { GlobalValidationConfiguration } from './config'; | ||
import { ValidationMessageParser } from './implementation/validation-message-parser'; | ||
@@ -46,24 +46,2 @@ import { PropertyAccessorParser } from './property-accessor-parser'; | ||
/** | ||
* Aurelia Validation Configuration API | ||
*/ | ||
export class AureliaValidationConfiguration { | ||
private validatorType: { new (...args: any[]): Validator } = StandardValidator; | ||
/** | ||
* Use a custom Validator implementation. | ||
*/ | ||
public customValidator(type: { new (...args: any[]): Validator }) { | ||
this.validatorType = type; | ||
} | ||
/** | ||
* Applies the configuration. | ||
*/ | ||
public apply(container: Container) { | ||
const validator = container.get(this.validatorType); | ||
container.registerInstance(Validator, validator); | ||
} | ||
} | ||
/** | ||
* Configures the plugin. | ||
@@ -74,3 +52,3 @@ */ | ||
frameworkConfig: { container: Container, globalResources?: (...resources: any[]) => any }, | ||
callback?: (config: AureliaValidationConfiguration) => void | ||
callback?: (config: GlobalValidationConfiguration) => void | ||
) { | ||
@@ -84,3 +62,3 @@ // the fluent rule definition API needs the parser to translate messages | ||
// configure... | ||
const config = new AureliaValidationConfiguration(); | ||
const config = new GlobalValidationConfiguration(); | ||
if (callback instanceof Function) { | ||
@@ -87,0 +65,0 @@ callback(config); |
import { | ||
Expression, | ||
// Chain, | ||
ValueConverter, | ||
// Assign, | ||
Conditional, | ||
// AccessThis, | ||
// AccessScope, | ||
AccessScope, | ||
AccessMember, | ||
AccessKeyed, | ||
// CallScope, | ||
// CallFunction, | ||
CallMember, | ||
// PrefixNot, | ||
BindingBehavior, | ||
Binary, | ||
// LiteralPrimitive, | ||
// LiteralArray, | ||
// LiteralObject, | ||
// LiteralString | ||
LiteralPrimitive, | ||
LiteralString | ||
} from 'aurelia-binding'; | ||
export type Chain = any; | ||
export type Assign = any; | ||
export type AccessThis = any; | ||
export type AccessScope = any; | ||
export type CallScope = any; | ||
export type CallFunction = any; | ||
export type PrefixNot = any; | ||
export type LiteralPrimitive = any; | ||
export type LiteralArray = any; | ||
export type LiteralObject = any; | ||
export type LiteralString = any; | ||
// tslint:disable:no-empty | ||
export class ExpressionVisitor { | ||
public visitChain(chain: Chain) { | ||
public visitChain(chain: any) { | ||
this.visitArgs(chain.expressions); | ||
@@ -51,3 +31,3 @@ } | ||
public visitAssign(assign: Assign) { | ||
public visitAssign(assign: any) { | ||
assign.target.accept(this); | ||
@@ -63,3 +43,3 @@ assign.value.accept(this); | ||
public visitAccessThis(access: AccessThis) { | ||
public visitAccessThis(access: any) { | ||
access.ancestor = access.ancestor; | ||
@@ -81,7 +61,7 @@ } | ||
public visitCallScope(call: CallScope) { | ||
public visitCallScope(call: any) { | ||
this.visitArgs(call.args); | ||
} | ||
public visitCallFunction(call: CallFunction) { | ||
public visitCallFunction(call: any) { | ||
call.func.accept(this); | ||
@@ -96,3 +76,3 @@ this.visitArgs(call.args); | ||
public visitPrefix(prefix: PrefixNot) { | ||
public visitPrefix(prefix: any) { | ||
prefix.expression.accept(this); | ||
@@ -110,7 +90,7 @@ } | ||
public visitLiteralArray(literal: LiteralArray) { | ||
public visitLiteralArray(literal: any) { | ||
this.visitArgs(literal.elements); | ||
} | ||
public visitLiteralObject(literal: LiteralObject) { | ||
public visitLiteralObject(literal: any) { | ||
this.visitArgs(literal.values); | ||
@@ -117,0 +97,0 @@ } |
@@ -445,3 +445,3 @@ import { Rule, RuleProperty, ValidationDisplayNameAccessor } from './rule'; | ||
*/ | ||
public ensure<TValue>(property: string | number | PropertyAccessor<TObject, TValue>) { | ||
public ensure<TValue>(property: string | number | PropertyAccessor<TObject, TValue>): FluentRules<TObject, any> { | ||
this.assertInitialized(); | ||
@@ -459,3 +459,3 @@ const name = this.parsers.property.parse(property); | ||
*/ | ||
public ensureObject() { | ||
public ensureObject(): FluentRules<TObject, any> { | ||
this.assertInitialized(); | ||
@@ -462,0 +462,0 @@ const fluentRules = new FluentRules<TObject, TObject>( |
import { Container } from 'aurelia-dependency-injection'; | ||
import { GlobalValidationConfiguration } from './config'; | ||
import { ValidationController } from './validation-controller'; | ||
@@ -24,3 +25,4 @@ import { Validator } from './validator'; | ||
const propertyParser = this.container.get(PropertyAccessorParser) as PropertyAccessorParser; | ||
return new ValidationController(validator, propertyParser); | ||
const config = this.container.get(GlobalValidationConfiguration) as GlobalValidationConfiguration; | ||
return new ValidationController(validator, propertyParser, config); | ||
} | ||
@@ -27,0 +29,0 @@ |
import { Binding, Expression } from 'aurelia-binding'; | ||
import { GlobalValidationConfiguration } from './config'; | ||
import { Validator } from './validator'; | ||
@@ -18,3 +19,3 @@ import { validateTrigger } from './validate-trigger'; | ||
export class ValidationController { | ||
public static inject = [Validator, PropertyAccessorParser]; | ||
public static inject = [Validator, PropertyAccessorParser, GlobalValidationConfiguration]; | ||
@@ -51,3 +52,3 @@ // Registered bindings (via the validate binding behavior) | ||
*/ | ||
public validateTrigger = validateTrigger.blur; | ||
public validateTrigger: validateTrigger; | ||
@@ -59,3 +60,11 @@ // Promise that resolves when validation has completed. | ||
constructor(private validator: Validator, private propertyParser: PropertyAccessorParser) { } | ||
constructor( | ||
private validator: Validator, | ||
private propertyParser: PropertyAccessorParser, | ||
config?: GlobalValidationConfiguration, | ||
) { | ||
this.validateTrigger = config instanceof GlobalValidationConfiguration | ||
? config.getDefaultValidationTrigger() | ||
: GlobalValidationConfiguration.DEFAULT_VALIDATION_TRIGGER; | ||
} | ||
@@ -62,0 +71,0 @@ /** |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
953927
43
18291
1
Updatedaurelia-binding@^2.5.2