Skip to content

Commit f1acb0d

Browse files
author
Benajmin Bondi
committed
Releasing 0.13.2-bondi
1 parent a4b3866 commit f1acb0d

File tree

88 files changed

+813
-489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+813
-489
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aurelia-validation",
3-
"version": "0.13.1",
3+
"version": "0.13.2-bondi",
44
"description": "Validation for Aurelia applications",
55
"keywords": [
66
"aurelia",

dist/amd/implementation/rules.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export declare class Rules {
66
/**
77
* The name of the property that stores the rules.
88
*/
9-
static key: string;
9+
private static key;
1010
/**
1111
* Applies the rules to a target.
1212
*/

dist/amd/implementation/standard-validator.d.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import { ViewResources } from 'aurelia-templating';
22
import { Validator } from '../validator';
33
import { ValidationError } from '../validation-error';
4+
import { Rule } from './rule';
45
import { ValidationMessageProvider } from './validation-messages';
56
/**
67
* Validates.
78
* Responsible for validating objects and properties.
89
*/
910
export declare class StandardValidator extends Validator {
10-
static inject: (typeof ValidationMessageProvider | typeof ViewResources)[];
11+
static inject: (typeof ViewResources | typeof ValidationMessageProvider)[];
1112
private messageProvider;
1213
private lookupFunctions;
1314
private getDisplayName;
1415
constructor(messageProvider: ValidationMessageProvider, resources: ViewResources);
15-
private getMessage(rule, object, value);
16-
private validateRuleSequence(object, propertyName, ruleSequence, sequence);
17-
private validate(object, propertyName, rules);
1816
/**
1917
* Validates the specified property.
2018
* @param object The object to validate.
@@ -30,4 +28,13 @@ export declare class StandardValidator extends Validator {
3028
* for the object created by ValidationRules....on(class/object)
3129
*/
3230
validateObject(object: any, rules?: any): Promise<ValidationError[]>;
31+
/**
32+
* Determines whether a rule exists in a set of rules.
33+
* @param rules The rules to search.
34+
* @parem rule The rule to find.
35+
*/
36+
ruleExists(rules: Rule<any, any>[][], rule: Rule<any, any>): boolean;
37+
private getMessage(rule, object, value);
38+
private validateRuleSequence(object, propertyName, ruleSequence, sequence);
39+
private validate(object, propertyName, rules);
3340
}

dist/amd/implementation/standard-validator.js

+33-19
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,39 @@ define(["require", "exports", 'aurelia-templating', '../validator', '../validati
1717
this.lookupFunctions = resources.lookupFunctions;
1818
this.getDisplayName = messageProvider.getDisplayName.bind(messageProvider);
1919
}
20+
/**
21+
* Validates the specified property.
22+
* @param object The object to validate.
23+
* @param propertyName The name of the property to validate.
24+
* @param rules Optional. If unspecified, the rules will be looked up using the metadata
25+
* for the object created by ValidationRules....on(class/object)
26+
*/
27+
StandardValidator.prototype.validateProperty = function (object, propertyName, rules) {
28+
return this.validate(object, propertyName, rules || null);
29+
};
30+
/**
31+
* Validates all rules for specified object and it's properties.
32+
* @param object The object to validate.
33+
* @param rules Optional. If unspecified, the rules will be looked up using the metadata
34+
* for the object created by ValidationRules....on(class/object)
35+
*/
36+
StandardValidator.prototype.validateObject = function (object, rules) {
37+
return this.validate(object, null, rules || null);
38+
};
39+
/**
40+
* Determines whether a rule exists in a set of rules.
41+
* @param rules The rules to search.
42+
* @parem rule The rule to find.
43+
*/
44+
StandardValidator.prototype.ruleExists = function (rules, rule) {
45+
var i = rules.length;
46+
while (i--) {
47+
if (rules[i].indexOf(rule) !== -1) {
48+
return true;
49+
}
50+
}
51+
return false;
52+
};
2053
StandardValidator.prototype.getMessage = function (rule, object, value) {
2154
var expression = rule.message || this.messageProvider.getMessage(rule.messageKey);
2255
var _a = rule.property, propertyName = _a.name, displayName = _a.displayName;
@@ -88,25 +121,6 @@ define(["require", "exports", 'aurelia-templating', '../validator', '../validati
88121
}
89122
return this.validateRuleSequence(object, propertyName, rules, 0);
90123
};
91-
/**
92-
* Validates the specified property.
93-
* @param object The object to validate.
94-
* @param propertyName The name of the property to validate.
95-
* @param rules Optional. If unspecified, the rules will be looked up using the metadata
96-
* for the object created by ValidationRules....on(class/object)
97-
*/
98-
StandardValidator.prototype.validateProperty = function (object, propertyName, rules) {
99-
return this.validate(object, propertyName, rules || null);
100-
};
101-
/**
102-
* Validates all rules for specified object and it's properties.
103-
* @param object The object to validate.
104-
* @param rules Optional. If unspecified, the rules will be looked up using the metadata
105-
* for the object created by ValidationRules....on(class/object)
106-
*/
107-
StandardValidator.prototype.validateObject = function (object, rules) {
108-
return this.validate(object, null, rules || null);
109-
};
110124
StandardValidator.inject = [validation_messages_1.ValidationMessageProvider, aurelia_templating_1.ViewResources];
111125
return StandardValidator;
112126
}(validator_1.Validator));

dist/amd/implementation/validation-parser.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export declare class ValidationParser {
1313
private undefinedExpression;
1414
private cache;
1515
constructor(parser: Parser, bindinqLanguage: BindingLanguage);
16-
private coalesce(part);
1716
parseMessage(message: string): Expression;
18-
private getAccessorExpression(fn);
1917
parseProperty<TObject, TValue>(property: string | PropertyAccessor<TObject, TValue>): RuleProperty;
18+
private coalesce(part);
19+
private getAccessorExpression(fn);
2020
}
2121
export declare class MessageExpressionValidator extends Unparser {
2222
private originalMessage;

dist/amd/implementation/validation-parser.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ define(["require", "exports", 'aurelia-binding', 'aurelia-templating', './util',
1414
this.undefinedExpression = new aurelia_binding_1.LiteralPrimitive(undefined);
1515
this.cache = {};
1616
}
17-
ValidationParser.prototype.coalesce = function (part) {
18-
// part === null || part === undefined ? '' : part
19-
return new aurelia_binding_1.Conditional(new aurelia_binding_1.Binary('||', new aurelia_binding_1.Binary('===', part, this.nullExpression), new aurelia_binding_1.Binary('===', part, this.undefinedExpression)), this.emptyStringExpression, new aurelia_binding_1.CallMember(part, 'toString', []));
20-
};
2117
ValidationParser.prototype.parseMessage = function (message) {
2218
if (this.cache[message] !== undefined) {
2319
return this.cache[message];
@@ -34,15 +30,6 @@ define(["require", "exports", 'aurelia-binding', 'aurelia-templating', './util',
3430
this.cache[message] = expression;
3531
return expression;
3632
};
37-
ValidationParser.prototype.getAccessorExpression = function (fn) {
38-
var classic = /^function\s*\([$_\w\d]+\)\s*\{\s*(?:"use strict";)?\s*return\s+[$_\w\d]+\.([$_\w\d]+)\s*;?\s*\}$/;
39-
var arrow = /^[$_\w\d]+\s*=>\s*[$_\w\d]+\.([$_\w\d]+)$/;
40-
var match = classic.exec(fn) || arrow.exec(fn);
41-
if (match === null) {
42-
throw new Error("Unable to parse accessor function:\n" + fn);
43-
}
44-
return this.parser.parse(match[1]);
45-
};
4633
ValidationParser.prototype.parseProperty = function (property) {
4734
if (util_1.isString(property)) {
4835
return { name: property, displayName: null };
@@ -57,6 +44,19 @@ define(["require", "exports", 'aurelia-binding', 'aurelia-templating', './util',
5744
}
5845
throw new Error("Invalid subject: \"" + accessor + "\"");
5946
};
47+
ValidationParser.prototype.coalesce = function (part) {
48+
// part === null || part === undefined ? '' : part
49+
return new aurelia_binding_1.Conditional(new aurelia_binding_1.Binary('||', new aurelia_binding_1.Binary('===', part, this.nullExpression), new aurelia_binding_1.Binary('===', part, this.undefinedExpression)), this.emptyStringExpression, new aurelia_binding_1.CallMember(part, 'toString', []));
50+
};
51+
ValidationParser.prototype.getAccessorExpression = function (fn) {
52+
var classic = /^function\s*\([$_\w\d]+\)\s*\{\s*(?:"use strict";)?\s*return\s+[$_\w\d]+\.([$_\w\d]+)\s*;?\s*\}$/;
53+
var arrow = /^[$_\w\d]+\s*=>\s*[$_\w\d]+\.([$_\w\d]+)$/;
54+
var match = classic.exec(fn) || arrow.exec(fn);
55+
if (match === null) {
56+
throw new Error("Unable to parse accessor function:\n" + fn);
57+
}
58+
return this.parser.parse(match[1]);
59+
};
6060
ValidationParser.inject = [aurelia_binding_1.Parser, aurelia_templating_1.BindingLanguage];
6161
return ValidationParser;
6262
}());

dist/amd/implementation/validation-rules.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ export declare class FluentEnsure<TObject> {
195195
constructor(parser: ValidationParser);
196196
/**
197197
* Target a property with validation rules.
198-
* @param property The property to target. Can be the property name or a property accessor function.
198+
* @param property The property to target. Can be the property name or a property accessor
199+
* function.
199200
*/
200201
ensure<TValue>(property: string | PropertyAccessor<TObject, TValue>): FluentRules<TObject, TValue>;
201202
/**
@@ -233,7 +234,8 @@ export declare class ValidationRules {
233234
* @param name The name of the custom rule. Also serves as the message key.
234235
* @param condition The rule function.
235236
* @param message The message expression
236-
* @param argsToConfig A function that maps the rule's arguments to a "config" object that can be used when evaluating the message expression.
237+
* @param argsToConfig A function that maps the rule's arguments to a "config"
238+
* object that can be used when evaluating the message expression.
237239
*/
238240
static customRule(name: string, condition: (value: any, object?: any, ...args: any[]) => boolean | Promise<boolean>, message: string, argsToConfig?: (...args: any[]) => any): void;
239241
/**

dist/amd/implementation/validation-rules.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ define(["require", "exports", './util', './rules', './validation-messages'], fun
250250
* null, undefined and empty-string values are considered valid.
251251
*/
252252
FluentRules.prototype.email = function () {
253-
return this.matches(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i)
253+
// regex from https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address
254+
/* tslint:disable:max-line-length */
255+
return this.matches(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/)
254256
.withMessageKey('email');
255257
};
256258
/**
@@ -301,17 +303,20 @@ define(["require", "exports", './util', './rules', './validation-messages'], fun
301303
* Part of the fluent rule API. Enables targeting properties and objects with rules.
302304
*/
303305
var FluentEnsure = (function () {
306+
/* tslint:enable */
304307
function FluentEnsure(parser) {
305308
this.parser = parser;
306309
/**
307310
* Rules that have been defined using the fluent API.
308311
*/
309312
this.rules = [];
313+
/* tslint:disable */
310314
this._sequence = 0;
311315
}
312316
/**
313317
* Target a property with validation rules.
314-
* @param property The property to target. Can be the property name or a property accessor function.
318+
* @param property The property to target. Can be the property name or a property accessor
319+
* function.
315320
*/
316321
FluentEnsure.prototype.ensure = function (property) {
317322
this.assertInitialized();
@@ -377,7 +382,8 @@ define(["require", "exports", './util', './rules', './validation-messages'], fun
377382
* @param name The name of the custom rule. Also serves as the message key.
378383
* @param condition The rule function.
379384
* @param message The message expression
380-
* @param argsToConfig A function that maps the rule's arguments to a "config" object that can be used when evaluating the message expression.
385+
* @param argsToConfig A function that maps the rule's arguments to a "config"
386+
* object that can be used when evaluating the message expression.
381387
*/
382388
ValidationRules.customRule = function (name, condition, message, argsToConfig) {
383389
validation_messages_1.validationMessages[name] = message;

dist/amd/property-info.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import { Expression } from 'aurelia-binding';
55
* @param source The scope
66
*/
77
export declare function getPropertyInfo(expression: Expression, source: any): {
8-
object: any;
8+
object: Object;
99
propertyName: string;
10-
};
10+
} | null;

dist/amd/property-info.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ define(["require", "exports", 'aurelia-binding'], function (require, exports, au
22
"use strict";
33
function getObject(expression, objectExpression, source) {
44
var value = objectExpression.evaluate(source, null);
5-
if (value !== null && (typeof value === 'object' || typeof value === 'function')) {
5+
if (value === null || value === undefined || value instanceof Object) {
66
return value;
77
}
8-
if (value === null) {
9-
value = 'null';
10-
}
11-
else if (value === undefined) {
12-
value = 'undefined';
13-
}
14-
throw new Error("The '" + objectExpression + "' part of '" + expression + "' evaluates to " + value + " instead of an object.");
8+
/* tslint:disable */
9+
throw new Error("The '" + objectExpression + "' part of '" + expression + "' evaluates to " + value + " instead of an object, null or undefined.");
10+
/* tslint:enable */
1511
}
1612
/**
1713
* Retrieves the object and property name for the specified expression.
@@ -40,6 +36,9 @@ define(["require", "exports", 'aurelia-binding'], function (require, exports, au
4036
else {
4137
throw new Error("Expression '" + originalExpression + "' is not compatible with the validate binding-behavior.");
4238
}
39+
if (object === null || object === undefined) {
40+
return null;
41+
}
4342
return { object: object, propertyName: propertyName };
4443
}
4544
exports.getPropertyInfo = getPropertyInfo;

dist/amd/validate-binding-behavior-base.d.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export declare abstract class ValidateBindingBehaviorBase {
88
constructor(taskQueue: TaskQueue);
99
protected abstract getValidateTrigger(controller: ValidationController): number;
1010
/**
11-
* Gets the DOM element associated with the data-binding. Most of the time it's
12-
* the binding.target but sometimes binding.target is an aurelia custom element,
13-
* or custom attribute which is a javascript "class" instance, so we need to use
14-
* the controller's container to retrieve the actual DOM element.
15-
*/
11+
* Gets the DOM element associated with the data-binding. Most of the time it's
12+
* the binding.target but sometimes binding.target is an aurelia custom element,
13+
* or custom attribute which is a javascript "class" instance, so we need to use
14+
* the controller's container to retrieve the actual DOM element.
15+
*/
1616
getTarget(binding: any, view: any): any;
1717
bind(binding: any, source: any, rulesOrController?: ValidationController | any, rules?: any): void;
1818
unbind(binding: any): void;

dist/amd/validate-binding-behavior-base.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ define(["require", "exports", 'aurelia-dependency-injection', 'aurelia-pal', './
88
this.taskQueue = taskQueue;
99
}
1010
/**
11-
* Gets the DOM element associated with the data-binding. Most of the time it's
12-
* the binding.target but sometimes binding.target is an aurelia custom element,
13-
* or custom attribute which is a javascript "class" instance, so we need to use
14-
* the controller's container to retrieve the actual DOM element.
15-
*/
11+
* Gets the DOM element associated with the data-binding. Most of the time it's
12+
* the binding.target but sometimes binding.target is an aurelia custom element,
13+
* or custom attribute which is a javascript "class" instance, so we need to use
14+
* the controller's container to retrieve the actual DOM element.
15+
*/
1616
ValidateBindingBehaviorBase.prototype.getTarget = function (binding, view) {
1717
var target = binding.target;
1818
// DOM element
@@ -51,14 +51,20 @@ define(["require", "exports", 'aurelia-dependency-injection', 'aurelia-pal', './
5151
controller.registerBinding(binding, target, rules);
5252
binding.validationController = controller;
5353
var trigger = this.getValidateTrigger(controller);
54+
/* tslint:disable:no-bitwise */
5455
if (trigger & validate_trigger_1.validateTrigger.change) {
56+
/* tslint:enable:no-bitwise */
5557
binding.standardUpdateSource = binding.updateSource;
58+
/* tslint:disable:only-arrow-functions */
5659
binding.updateSource = function (value) {
60+
/* tslint:enable:only-arrow-functions */
5761
this.standardUpdateSource(value);
5862
this.validationController.validateBinding(this);
5963
};
6064
}
65+
/* tslint:disable:no-bitwise */
6166
if (trigger & validate_trigger_1.validateTrigger.blur) {
67+
/* tslint:enable:no-bitwise */
6268
binding.validateBlurHandler = function () {
6369
_this.taskQueue.queueMicroTask(function () { return controller.validateBinding(binding); });
6470
};
@@ -67,7 +73,9 @@ define(["require", "exports", 'aurelia-dependency-injection', 'aurelia-pal', './
6773
}
6874
if (trigger !== validate_trigger_1.validateTrigger.manual) {
6975
binding.standardUpdateTarget = binding.updateTarget;
76+
/* tslint:disable:only-arrow-functions */
7077
binding.updateTarget = function (value) {
78+
/* tslint:enable:only-arrow-functions */
7179
this.standardUpdateTarget(value);
7280
this.validationController.resetBinding(this);
7381
};

dist/amd/validate-trigger.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Validation triggers.
3-
*/
2+
* Validation triggers.
3+
*/
44
export declare const validateTrigger: {
55
manual: number;
66
blur: number;

0 commit comments

Comments
 (0)