Skip to content

Commit 9c9ab72

Browse files
chore(all): prepare release 1.0.0-beta.1.0.1
1 parent 500d69a commit 9c9ab72

File tree

65 files changed

+2847
-577
lines changed

Some content is hidden

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

65 files changed

+2847
-577
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aurelia-validation",
3-
"version": "1.0.0-beta.1.0.0",
3+
"version": "1.0.0-beta.1.0.1",
44
"description": "Validation for Aurelia applications",
55
"keywords": [
66
"aurelia",

dist/amd/validation-controller.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,15 @@ define(["require", "exports", "./validator", "./validate-trigger", "./property-i
265265
// do an in-place replacement of the old result with the new result.
266266
// this ensures any repeats bound to this.results will not thrash.
267267
this_1.results.splice(this_1.results.indexOf(oldResult), 1, newResult);
268-
if (newResult.valid) {
268+
if (!oldResult.valid && newResult.valid) {
269269
this_1.errors.splice(this_1.errors.indexOf(oldResult), 1);
270270
}
271-
else {
271+
else if (!oldResult.valid && !newResult.valid) {
272272
this_1.errors.splice(this_1.errors.indexOf(oldResult), 1, newResult);
273273
}
274+
else if (!newResult.valid) {
275+
this_1.errors.push(newResult);
276+
}
274277
}
275278
};
276279
var this_1 = this;

dist/commonjs/validation-controller.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,15 @@ var ValidationController = (function () {
268268
// do an in-place replacement of the old result with the new result.
269269
// this ensures any repeats bound to this.results will not thrash.
270270
this_1.results.splice(this_1.results.indexOf(oldResult), 1, newResult);
271-
if (newResult.valid) {
271+
if (!oldResult.valid && newResult.valid) {
272272
this_1.errors.splice(this_1.errors.indexOf(oldResult), 1);
273273
}
274-
else {
274+
else if (!oldResult.valid && !newResult.valid) {
275275
this_1.errors.splice(this_1.errors.indexOf(oldResult), 1, newResult);
276276
}
277+
else if (!newResult.valid) {
278+
this_1.errors.push(newResult);
279+
}
277280
}
278281
};
279282
var this_1 = this;

dist/es2015/aurelia-validation.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,34 @@ import { ValidationRules } from './implementation/validation-rules';
2020
/**
2121
* Aurelia Validation Configuration API
2222
*/
23-
var AureliaValidationConfiguration = (function () {
24-
function AureliaValidationConfiguration() {
23+
export class AureliaValidationConfiguration {
24+
constructor() {
2525
this.validatorType = StandardValidator;
2626
}
2727
/**
2828
* Use a custom Validator implementation.
2929
*/
30-
AureliaValidationConfiguration.prototype.customValidator = function (type) {
30+
customValidator(type) {
3131
this.validatorType = type;
32-
};
32+
}
3333
/**
3434
* Applies the configuration.
3535
*/
36-
AureliaValidationConfiguration.prototype.apply = function (container) {
37-
var validator = container.get(this.validatorType);
36+
apply(container) {
37+
const validator = container.get(this.validatorType);
3838
container.registerInstance(Validator, validator);
39-
};
40-
return AureliaValidationConfiguration;
41-
}());
42-
export { AureliaValidationConfiguration };
39+
}
40+
}
4341
/**
4442
* Configures the plugin.
4543
*/
4644
export function configure(frameworkConfig, callback) {
4745
// the fluent rule definition API needs the parser to translate messages
4846
// to interpolation expressions.
49-
var parser = frameworkConfig.container.get(ValidationParser);
47+
const parser = frameworkConfig.container.get(ValidationParser);
5048
ValidationRules.initialize(parser);
5149
// configure...
52-
var config = new AureliaValidationConfiguration();
50+
const config = new AureliaValidationConfiguration();
5351
if (callback instanceof Function) {
5452
callback(config);
5553
}

dist/es2015/implementation/rules.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
11
/**
22
* Sets, unsets and retrieves rules on an object or constructor function.
33
*/
4-
var Rules = (function () {
5-
function Rules() {
6-
}
4+
export class Rules {
75
/**
86
* Applies the rules to a target.
97
*/
10-
Rules.set = function (target, rules) {
8+
static set(target, rules) {
119
if (target instanceof Function) {
1210
target = target.prototype;
1311
}
1412
Object.defineProperty(target, Rules.key, { enumerable: false, configurable: false, writable: true, value: rules });
15-
};
13+
}
1614
/**
1715
* Removes rules from a target.
1816
*/
19-
Rules.unset = function (target) {
17+
static unset(target) {
2018
if (target instanceof Function) {
2119
target = target.prototype;
2220
}
2321
target[Rules.key] = null;
24-
};
22+
}
2523
/**
2624
* Retrieves the target's rules.
2725
*/
28-
Rules.get = function (target) {
26+
static get(target) {
2927
return target[Rules.key] || null;
30-
};
31-
return Rules;
32-
}());
33-
export { Rules };
28+
}
29+
}
3430
/**
3531
* The name of the property that stores the rules.
3632
*/
Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
var __extends = (this && this.__extends) || function (d, b) {
2-
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3-
function __() { this.constructor = d; }
4-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
5-
};
61
import { ViewResources } from 'aurelia-templating';
72
import { Validator } from '../validator';
83
import { ValidateResult } from '../validate-result';
@@ -12,14 +7,12 @@ import { ValidationMessageProvider } from './validation-messages';
127
* Validates.
138
* Responsible for validating objects and properties.
149
*/
15-
var StandardValidator = (function (_super) {
16-
__extends(StandardValidator, _super);
17-
function StandardValidator(messageProvider, resources) {
18-
var _this = _super.call(this) || this;
19-
_this.messageProvider = messageProvider;
20-
_this.lookupFunctions = resources.lookupFunctions;
21-
_this.getDisplayName = messageProvider.getDisplayName.bind(messageProvider);
22-
return _this;
10+
export class StandardValidator extends Validator {
11+
constructor(messageProvider, resources) {
12+
super();
13+
this.messageProvider = messageProvider;
14+
this.lookupFunctions = resources.lookupFunctions;
15+
this.getDisplayName = messageProvider.getDisplayName.bind(messageProvider);
2316
}
2417
/**
2518
* Validates the specified property.
@@ -28,92 +21,88 @@ var StandardValidator = (function (_super) {
2821
* @param rules Optional. If unspecified, the rules will be looked up using the metadata
2922
* for the object created by ValidationRules....on(class/object)
3023
*/
31-
StandardValidator.prototype.validateProperty = function (object, propertyName, rules) {
24+
validateProperty(object, propertyName, rules) {
3225
return this.validate(object, propertyName, rules || null);
33-
};
26+
}
3427
/**
3528
* Validates all rules for specified object and it's properties.
3629
* @param object The object to validate.
3730
* @param rules Optional. If unspecified, the rules will be looked up using the metadata
3831
* for the object created by ValidationRules....on(class/object)
3932
*/
40-
StandardValidator.prototype.validateObject = function (object, rules) {
33+
validateObject(object, rules) {
4134
return this.validate(object, null, rules || null);
42-
};
35+
}
4336
/**
4437
* Determines whether a rule exists in a set of rules.
4538
* @param rules The rules to search.
4639
* @parem rule The rule to find.
4740
*/
48-
StandardValidator.prototype.ruleExists = function (rules, rule) {
49-
var i = rules.length;
41+
ruleExists(rules, rule) {
42+
let i = rules.length;
5043
while (i--) {
5144
if (rules[i].indexOf(rule) !== -1) {
5245
return true;
5346
}
5447
}
5548
return false;
56-
};
57-
StandardValidator.prototype.getMessage = function (rule, object, value) {
58-
var expression = rule.message || this.messageProvider.getMessage(rule.messageKey);
59-
var _a = rule.property, propertyName = _a.name, displayName = _a.displayName;
49+
}
50+
getMessage(rule, object, value) {
51+
const expression = rule.message || this.messageProvider.getMessage(rule.messageKey);
52+
let { name: propertyName, displayName } = rule.property;
6053
if (propertyName !== null) {
6154
displayName = this.messageProvider.getDisplayName(propertyName, displayName);
6255
}
63-
var overrideContext = {
56+
const overrideContext = {
6457
$displayName: displayName,
6558
$propertyName: propertyName,
6659
$value: value,
6760
$object: object,
6861
$config: rule.config,
6962
$getDisplayName: this.getDisplayName
7063
};
71-
return expression.evaluate({ bindingContext: object, overrideContext: overrideContext }, this.lookupFunctions);
72-
};
73-
StandardValidator.prototype.validateRuleSequence = function (object, propertyName, ruleSequence, sequence, results) {
74-
var _this = this;
64+
return expression.evaluate({ bindingContext: object, overrideContext }, this.lookupFunctions);
65+
}
66+
validateRuleSequence(object, propertyName, ruleSequence, sequence, results) {
7567
// are we validating all properties or a single property?
76-
var validateAllProperties = propertyName === null || propertyName === undefined;
77-
var rules = ruleSequence[sequence];
78-
var allValid = true;
68+
const validateAllProperties = propertyName === null || propertyName === undefined;
69+
const rules = ruleSequence[sequence];
70+
let allValid = true;
7971
// validate each rule.
80-
var promises = [];
81-
var _loop_1 = function (i) {
82-
var rule = rules[i];
72+
const promises = [];
73+
for (let i = 0; i < rules.length; i++) {
74+
const rule = rules[i];
8375
// is the rule related to the property we're validating.
8476
if (!validateAllProperties && rule.property.name !== propertyName) {
85-
return "continue";
77+
continue;
8678
}
8779
// is this a conditional rule? is the condition met?
8880
if (rule.when && !rule.when(object)) {
89-
return "continue";
81+
continue;
9082
}
9183
// validate.
92-
var value = rule.property.name === null ? object : object[rule.property.name];
93-
var promiseOrBoolean = rule.condition(value, object);
84+
const value = rule.property.name === null ? object : object[rule.property.name];
85+
let promiseOrBoolean = rule.condition(value, object);
9486
if (!(promiseOrBoolean instanceof Promise)) {
9587
promiseOrBoolean = Promise.resolve(promiseOrBoolean);
9688
}
97-
promises.push(promiseOrBoolean.then(function (valid) {
98-
var message = valid ? null : _this.getMessage(rule, object, value);
89+
promises.push(promiseOrBoolean.then(valid => {
90+
const message = valid ? null : this.getMessage(rule, object, value);
9991
results.push(new ValidateResult(rule, object, rule.property.name, valid, message));
10092
allValid = allValid && valid;
10193
return valid;
10294
}));
103-
};
104-
for (var i = 0; i < rules.length; i++) {
105-
_loop_1(i);
10695
}
10796
return Promise.all(promises)
108-
.then(function () {
97+
.then(() => {
10998
sequence++;
11099
if (allValid && sequence < ruleSequence.length) {
111-
return _this.validateRuleSequence(object, propertyName, ruleSequence, sequence, results);
100+
return this.validateRuleSequence(object, propertyName, ruleSequence, sequence, results);
112101
}
113102
return results;
114103
});
115-
};
116-
StandardValidator.prototype.validate = function (object, propertyName, rules) {
104+
}
105+
validate(object, propertyName, rules) {
117106
// rules specified?
118107
if (!rules) {
119108
// no. attempt to locate the rules.
@@ -124,8 +113,6 @@ var StandardValidator = (function (_super) {
124113
return Promise.resolve([]);
125114
}
126115
return this.validateRuleSequence(object, propertyName, rules, 0, []);
127-
};
128-
return StandardValidator;
129-
}(Validator));
130-
export { StandardValidator };
116+
}
117+
}
131118
StandardValidator.inject = [ValidationMessageProvider, ViewResources];

dist/es2015/implementation/validation-messages.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,55 @@ import { ValidationParser } from './validation-parser';
22
/**
33
* Dictionary of validation messages. [messageKey]: messageExpression
44
*/
5-
export var validationMessages = {
5+
export const validationMessages = {
66
/**
77
* The default validation message. Used with rules that have no standard message.
88
*/
9-
default: "${$displayName} is invalid.",
10-
required: "${$displayName} is required.",
11-
matches: "${$displayName} is not correctly formatted.",
12-
email: "${$displayName} is not a valid email.",
13-
minLength: "${$displayName} must be at least ${$config.length} character${$config.length === 1 ? '' : 's'}.",
14-
maxLength: "${$displayName} cannot be longer than ${$config.length} character${$config.length === 1 ? '' : 's'}.",
15-
minItems: "${$displayName} must contain at least ${$config.count} item${$config.count === 1 ? '' : 's'}.",
16-
maxItems: "${$displayName} cannot contain more than ${$config.count} item${$config.count === 1 ? '' : 's'}.",
17-
equals: "${$displayName} must be ${$config.expectedValue}.",
9+
default: `\${$displayName} is invalid.`,
10+
required: `\${$displayName} is required.`,
11+
matches: `\${$displayName} is not correctly formatted.`,
12+
email: `\${$displayName} is not a valid email.`,
13+
minLength: `\${$displayName} must be at least \${$config.length} character\${$config.length === 1 ? '' : 's'}.`,
14+
maxLength: `\${$displayName} cannot be longer than \${$config.length} character\${$config.length === 1 ? '' : 's'}.`,
15+
minItems: `\${$displayName} must contain at least \${$config.count} item\${$config.count === 1 ? '' : 's'}.`,
16+
maxItems: `\${$displayName} cannot contain more than \${$config.count} item\${$config.count === 1 ? '' : 's'}.`,
17+
equals: `\${$displayName} must be \${$config.expectedValue}.`,
1818
};
1919
/**
2020
* Retrieves validation messages and property display names.
2121
*/
22-
var ValidationMessageProvider = (function () {
23-
function ValidationMessageProvider(parser) {
22+
export class ValidationMessageProvider {
23+
constructor(parser) {
2424
this.parser = parser;
2525
}
2626
/**
2727
* Returns a message binding expression that corresponds to the key.
2828
* @param key The message key.
2929
*/
30-
ValidationMessageProvider.prototype.getMessage = function (key) {
31-
var message;
30+
getMessage(key) {
31+
let message;
3232
if (key in validationMessages) {
3333
message = validationMessages[key];
3434
}
3535
else {
3636
message = validationMessages['default'];
3737
}
3838
return this.parser.parseMessage(message);
39-
};
39+
}
4040
/**
4141
* Formulates a property display name using the property name and the configured
4242
* displayName (if provided).
4343
* Override this with your own custom logic.
4444
* @param propertyName The property name.
4545
*/
46-
ValidationMessageProvider.prototype.getDisplayName = function (propertyName, displayName) {
46+
getDisplayName(propertyName, displayName) {
4747
if (displayName !== null && displayName !== undefined) {
4848
return displayName;
4949
}
5050
// split on upper-case letters.
51-
var words = propertyName.split(/(?=[A-Z])/).join(' ');
51+
const words = propertyName.split(/(?=[A-Z])/).join(' ');
5252
// capitalize first letter.
5353
return words.charAt(0).toUpperCase() + words.slice(1);
54-
};
55-
return ValidationMessageProvider;
56-
}());
57-
export { ValidationMessageProvider };
54+
}
55+
}
5856
ValidationMessageProvider.inject = [ValidationParser];

0 commit comments

Comments
 (0)