Skip to content

Commit

Permalink
chore(all): prepare release 1.0.0-beta.1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Dec 24, 2016
1 parent 500d69a commit 9c9ab72
Show file tree
Hide file tree
Showing 65 changed files with 2,847 additions and 577 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aurelia-validation",
"version": "1.0.0-beta.1.0.0",
"version": "1.0.0-beta.1.0.1",
"description": "Validation for Aurelia applications",
"keywords": [
"aurelia",
Expand Down
7 changes: 5 additions & 2 deletions dist/amd/validation-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,15 @@ define(["require", "exports", "./validator", "./validate-trigger", "./property-i
// do an in-place replacement of the old result with the new result.
// this ensures any repeats bound to this.results will not thrash.
this_1.results.splice(this_1.results.indexOf(oldResult), 1, newResult);
if (newResult.valid) {
if (!oldResult.valid && newResult.valid) {
this_1.errors.splice(this_1.errors.indexOf(oldResult), 1);
}
else {
else if (!oldResult.valid && !newResult.valid) {
this_1.errors.splice(this_1.errors.indexOf(oldResult), 1, newResult);
}
else if (!newResult.valid) {
this_1.errors.push(newResult);
}
}
};
var this_1 = this;
Expand Down
7 changes: 5 additions & 2 deletions dist/commonjs/validation-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,15 @@ var ValidationController = (function () {
// do an in-place replacement of the old result with the new result.
// this ensures any repeats bound to this.results will not thrash.
this_1.results.splice(this_1.results.indexOf(oldResult), 1, newResult);
if (newResult.valid) {
if (!oldResult.valid && newResult.valid) {
this_1.errors.splice(this_1.errors.indexOf(oldResult), 1);
}
else {
else if (!oldResult.valid && !newResult.valid) {
this_1.errors.splice(this_1.errors.indexOf(oldResult), 1, newResult);
}
else if (!newResult.valid) {
this_1.errors.push(newResult);
}
}
};
var this_1 = this;
Expand Down
22 changes: 10 additions & 12 deletions dist/es2015/aurelia-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,34 @@ import { ValidationRules } from './implementation/validation-rules';
/**
* Aurelia Validation Configuration API
*/
var AureliaValidationConfiguration = (function () {
function AureliaValidationConfiguration() {
export class AureliaValidationConfiguration {
constructor() {
this.validatorType = StandardValidator;
}
/**
* Use a custom Validator implementation.
*/
AureliaValidationConfiguration.prototype.customValidator = function (type) {
customValidator(type) {
this.validatorType = type;
};
}
/**
* Applies the configuration.
*/
AureliaValidationConfiguration.prototype.apply = function (container) {
var validator = container.get(this.validatorType);
apply(container) {
const validator = container.get(this.validatorType);
container.registerInstance(Validator, validator);
};
return AureliaValidationConfiguration;
}());
export { AureliaValidationConfiguration };
}
}
/**
* Configures the plugin.
*/
export function configure(frameworkConfig, callback) {
// the fluent rule definition API needs the parser to translate messages
// to interpolation expressions.
var parser = frameworkConfig.container.get(ValidationParser);
const parser = frameworkConfig.container.get(ValidationParser);
ValidationRules.initialize(parser);
// configure...
var config = new AureliaValidationConfiguration();
const config = new AureliaValidationConfiguration();
if (callback instanceof Function) {
callback(config);
}
Expand Down
20 changes: 8 additions & 12 deletions dist/es2015/implementation/rules.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
/**
* Sets, unsets and retrieves rules on an object or constructor function.
*/
var Rules = (function () {
function Rules() {
}
export class Rules {
/**
* Applies the rules to a target.
*/
Rules.set = function (target, rules) {
static set(target, rules) {
if (target instanceof Function) {
target = target.prototype;
}
Object.defineProperty(target, Rules.key, { enumerable: false, configurable: false, writable: true, value: rules });
};
}
/**
* Removes rules from a target.
*/
Rules.unset = function (target) {
static unset(target) {
if (target instanceof Function) {
target = target.prototype;
}
target[Rules.key] = null;
};
}
/**
* Retrieves the target's rules.
*/
Rules.get = function (target) {
static get(target) {
return target[Rules.key] || null;
};
return Rules;
}());
export { Rules };
}
}
/**
* The name of the property that stores the rules.
*/
Expand Down
89 changes: 38 additions & 51 deletions dist/es2015/implementation/standard-validator.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
import { ViewResources } from 'aurelia-templating';
import { Validator } from '../validator';
import { ValidateResult } from '../validate-result';
Expand All @@ -12,14 +7,12 @@ import { ValidationMessageProvider } from './validation-messages';
* Validates.
* Responsible for validating objects and properties.
*/
var StandardValidator = (function (_super) {
__extends(StandardValidator, _super);
function StandardValidator(messageProvider, resources) {
var _this = _super.call(this) || this;
_this.messageProvider = messageProvider;
_this.lookupFunctions = resources.lookupFunctions;
_this.getDisplayName = messageProvider.getDisplayName.bind(messageProvider);
return _this;
export class StandardValidator extends Validator {
constructor(messageProvider, resources) {
super();
this.messageProvider = messageProvider;
this.lookupFunctions = resources.lookupFunctions;
this.getDisplayName = messageProvider.getDisplayName.bind(messageProvider);
}
/**
* Validates the specified property.
Expand All @@ -28,92 +21,88 @@ var StandardValidator = (function (_super) {
* @param rules Optional. If unspecified, the rules will be looked up using the metadata
* for the object created by ValidationRules....on(class/object)
*/
StandardValidator.prototype.validateProperty = function (object, propertyName, rules) {
validateProperty(object, propertyName, rules) {
return this.validate(object, propertyName, rules || null);
};
}
/**
* Validates all rules for specified object and it's properties.
* @param object The object to validate.
* @param rules Optional. If unspecified, the rules will be looked up using the metadata
* for the object created by ValidationRules....on(class/object)
*/
StandardValidator.prototype.validateObject = function (object, rules) {
validateObject(object, rules) {
return this.validate(object, null, rules || null);
};
}
/**
* Determines whether a rule exists in a set of rules.
* @param rules The rules to search.
* @parem rule The rule to find.
*/
StandardValidator.prototype.ruleExists = function (rules, rule) {
var i = rules.length;
ruleExists(rules, rule) {
let i = rules.length;
while (i--) {
if (rules[i].indexOf(rule) !== -1) {
return true;
}
}
return false;
};
StandardValidator.prototype.getMessage = function (rule, object, value) {
var expression = rule.message || this.messageProvider.getMessage(rule.messageKey);
var _a = rule.property, propertyName = _a.name, displayName = _a.displayName;
}
getMessage(rule, object, value) {
const expression = rule.message || this.messageProvider.getMessage(rule.messageKey);
let { name: propertyName, displayName } = rule.property;
if (propertyName !== null) {
displayName = this.messageProvider.getDisplayName(propertyName, displayName);
}
var overrideContext = {
const overrideContext = {
$displayName: displayName,
$propertyName: propertyName,
$value: value,
$object: object,
$config: rule.config,
$getDisplayName: this.getDisplayName
};
return expression.evaluate({ bindingContext: object, overrideContext: overrideContext }, this.lookupFunctions);
};
StandardValidator.prototype.validateRuleSequence = function (object, propertyName, ruleSequence, sequence, results) {
var _this = this;
return expression.evaluate({ bindingContext: object, overrideContext }, this.lookupFunctions);
}
validateRuleSequence(object, propertyName, ruleSequence, sequence, results) {
// are we validating all properties or a single property?
var validateAllProperties = propertyName === null || propertyName === undefined;
var rules = ruleSequence[sequence];
var allValid = true;
const validateAllProperties = propertyName === null || propertyName === undefined;
const rules = ruleSequence[sequence];
let allValid = true;
// validate each rule.
var promises = [];
var _loop_1 = function (i) {
var rule = rules[i];
const promises = [];
for (let i = 0; i < rules.length; i++) {
const rule = rules[i];
// is the rule related to the property we're validating.
if (!validateAllProperties && rule.property.name !== propertyName) {
return "continue";
continue;
}
// is this a conditional rule? is the condition met?
if (rule.when && !rule.when(object)) {
return "continue";
continue;
}
// validate.
var value = rule.property.name === null ? object : object[rule.property.name];
var promiseOrBoolean = rule.condition(value, object);
const value = rule.property.name === null ? object : object[rule.property.name];
let promiseOrBoolean = rule.condition(value, object);
if (!(promiseOrBoolean instanceof Promise)) {
promiseOrBoolean = Promise.resolve(promiseOrBoolean);
}
promises.push(promiseOrBoolean.then(function (valid) {
var message = valid ? null : _this.getMessage(rule, object, value);
promises.push(promiseOrBoolean.then(valid => {
const message = valid ? null : this.getMessage(rule, object, value);
results.push(new ValidateResult(rule, object, rule.property.name, valid, message));
allValid = allValid && valid;
return valid;
}));
};
for (var i = 0; i < rules.length; i++) {
_loop_1(i);
}
return Promise.all(promises)
.then(function () {
.then(() => {
sequence++;
if (allValid && sequence < ruleSequence.length) {
return _this.validateRuleSequence(object, propertyName, ruleSequence, sequence, results);
return this.validateRuleSequence(object, propertyName, ruleSequence, sequence, results);
}
return results;
});
};
StandardValidator.prototype.validate = function (object, propertyName, rules) {
}
validate(object, propertyName, rules) {
// rules specified?
if (!rules) {
// no. attempt to locate the rules.
Expand All @@ -124,8 +113,6 @@ var StandardValidator = (function (_super) {
return Promise.resolve([]);
}
return this.validateRuleSequence(object, propertyName, rules, 0, []);
};
return StandardValidator;
}(Validator));
export { StandardValidator };
}
}
StandardValidator.inject = [ValidationMessageProvider, ViewResources];
40 changes: 19 additions & 21 deletions dist/es2015/implementation/validation-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,55 @@ import { ValidationParser } from './validation-parser';
/**
* Dictionary of validation messages. [messageKey]: messageExpression
*/
export var validationMessages = {
export const validationMessages = {
/**
* The default validation message. Used with rules that have no standard message.
*/
default: "${$displayName} is invalid.",
required: "${$displayName} is required.",
matches: "${$displayName} is not correctly formatted.",
email: "${$displayName} is not a valid email.",
minLength: "${$displayName} must be at least ${$config.length} character${$config.length === 1 ? '' : 's'}.",
maxLength: "${$displayName} cannot be longer than ${$config.length} character${$config.length === 1 ? '' : 's'}.",
minItems: "${$displayName} must contain at least ${$config.count} item${$config.count === 1 ? '' : 's'}.",
maxItems: "${$displayName} cannot contain more than ${$config.count} item${$config.count === 1 ? '' : 's'}.",
equals: "${$displayName} must be ${$config.expectedValue}.",
default: `\${$displayName} is invalid.`,
required: `\${$displayName} is required.`,
matches: `\${$displayName} is not correctly formatted.`,
email: `\${$displayName} is not a valid email.`,
minLength: `\${$displayName} must be at least \${$config.length} character\${$config.length === 1 ? '' : 's'}.`,
maxLength: `\${$displayName} cannot be longer than \${$config.length} character\${$config.length === 1 ? '' : 's'}.`,
minItems: `\${$displayName} must contain at least \${$config.count} item\${$config.count === 1 ? '' : 's'}.`,
maxItems: `\${$displayName} cannot contain more than \${$config.count} item\${$config.count === 1 ? '' : 's'}.`,
equals: `\${$displayName} must be \${$config.expectedValue}.`,
};
/**
* Retrieves validation messages and property display names.
*/
var ValidationMessageProvider = (function () {
function ValidationMessageProvider(parser) {
export class ValidationMessageProvider {
constructor(parser) {
this.parser = parser;
}
/**
* Returns a message binding expression that corresponds to the key.
* @param key The message key.
*/
ValidationMessageProvider.prototype.getMessage = function (key) {
var message;
getMessage(key) {
let message;
if (key in validationMessages) {
message = validationMessages[key];
}
else {
message = validationMessages['default'];
}
return this.parser.parseMessage(message);
};
}
/**
* Formulates a property display name using the property name and the configured
* displayName (if provided).
* Override this with your own custom logic.
* @param propertyName The property name.
*/
ValidationMessageProvider.prototype.getDisplayName = function (propertyName, displayName) {
getDisplayName(propertyName, displayName) {
if (displayName !== null && displayName !== undefined) {
return displayName;
}
// split on upper-case letters.
var words = propertyName.split(/(?=[A-Z])/).join(' ');
const words = propertyName.split(/(?=[A-Z])/).join(' ');
// capitalize first letter.
return words.charAt(0).toUpperCase() + words.slice(1);
};
return ValidationMessageProvider;
}());
export { ValidationMessageProvider };
}
}
ValidationMessageProvider.inject = [ValidationParser];
Loading

0 comments on commit 9c9ab72

Please sign in to comment.