function _extends(){return(_extends=Object.assign||function(e){for(var r=1;r()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,url:new RegExp("^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$","i"),hex:/^#?([a-f0-9]{6}|[a-f0-9]{3})$/i},types={integer:function(e){return types.number(e)&&parseInt(e,10)===e},float:function(e){return types.number(e)&&!types.integer(e)},array:function(e){return Array.isArray(e)},regexp:function(e){if(e instanceof RegExp)return!0;try{return!!new RegExp(e)}catch(e){return!1}},date:function(e){return"function"==typeof e.getTime&&"function"==typeof e.getMonth&&"function"==typeof e.getYear},number:function(e){return!isNaN(e)&&"number"==typeof+e},object:function(e){return"object"==typeof e&&!types.array(e)},method:function(e){return"function"==typeof e},email:function(e){return"string"==typeof e&&!!e.match(pattern.email)&&e.length<255},url:function(e){return"string"==typeof e&&!!e.match(pattern.url)},hex:function(e){return"string"==typeof e&&!!e.match(pattern.hex)}};function type(e,r,t,n,a){e.required&&void 0===r?required(e,r,t,n,a):(t=e.type,-1<["integer","float","array","regexp","object","method","email","number","date","url","hex"].indexOf(t)?types[t](r)||n.push(format(a.messages.types[t],e.fullField,e.type)):t&&typeof r!==e.type&&n.push(format(a.messages.types[t],e.fullField,e.type)))}function range(e,r,t,n,a){var i="number"==typeof e.len,s="number"==typeof e.min,u="number"==typeof e.max,o=r,l=null,f="number"==typeof r,p="string"==typeof r,d=Array.isArray(r);if(f?l="number":p?l="string":d&&(l="array"),!l)return!1;d&&(o=r.length),p&&(o=r.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,"_").length),i?o!==e.len&&n.push(format(a.messages[l].len,e.fullField,e.len)):s&&!u&&oe.max?n.push(format(a.messages[l].max,e.fullField,e.max)):s&&u&&(oe.max)&&n.push(format(a.messages[l].range,e.fullField,e.min,e.max))}var ENUM="enum";function enumerable(e,r,t,n,a){e[ENUM]=Array.isArray(e[ENUM])?e[ENUM]:[],-1===e[ENUM].indexOf(r)&&n.push(format(a.messages[ENUM],e.fullField,e[ENUM].join(", ")))}function pattern$1(e,r,t,n,a){e.pattern&&(e.pattern instanceof RegExp?(e.pattern.lastIndex=0,e.pattern.test(r)||n.push(format(a.messages.pattern.mismatch,e.fullField,r,e.pattern))):"string"==typeof e.pattern&&(new RegExp(e.pattern).test(r)||n.push(format(a.messages.pattern.mismatch,e.fullField,r,e.pattern))))}var rules={required:required,whitespace:whitespace,type:type,range:range,enum:enumerable,pattern:pattern$1};function string(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r,"string")&&!e.required)return t();rules.required(e,r,n,i,a,"string"),isEmptyValue(r,"string")||(rules.type(e,r,n,i,a),rules.range(e,r,n,i,a),rules.pattern(e,r,n,i,a),!0===e.whitespace&&rules.whitespace(e,r,n,i,a))}t(i)}function method(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,i,a),void 0!==r&&rules.type(e,r,n,i,a)}t(i)}function number(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(""===r&&(r=void 0),isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,i,a),void 0!==r&&(rules.type(e,r,n,i,a),rules.range(e,r,n,i,a))}t(i)}function _boolean(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,i,a),void 0!==r&&rules.type(e,r,n,i,a)}t(i)}function regexp(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,i,a),isEmptyValue(r)||rules.type(e,r,n,i,a)}t(i)}function integer(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,i,a),void 0!==r&&(rules.type(e,r,n,i,a),rules.range(e,r,n,i,a))}t(i)}function floatFn(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,i,a),void 0!==r&&(rules.type(e,r,n,i,a),rules.range(e,r,n,i,a))}t(i)}function array(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r,"array")&&!e.required)return t();rules.required(e,r,n,i,a,"array"),isEmptyValue(r,"array")||(rules.type(e,r,n,i,a),rules.range(e,r,n,i,a))}t(i)}function object(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,i,a),void 0!==r&&rules.type(e,r,n,i,a)}t(i)}var ENUM$1="enum";function enumerable$1(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,i,a),void 0!==r&&rules[ENUM$1](e,r,n,i,a)}t(i)}function pattern$2(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r,"string")&&!e.required)return t();rules.required(e,r,n,i,a),isEmptyValue(r,"string")||rules.pattern(e,r,n,i,a)}t(i)}function date(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,i,a),isEmptyValue(r)||(r="number"==typeof r?new Date(r):r,rules.type(e,r,n,i,a),r&&rules.range(e,r.getTime(),n,i,a))}t(i)}function required$1(e,r,t,n,a){var i=[],s=Array.isArray(r)?"array":typeof r;rules.required(e,r,n,i,a,s),t(i)}function type$1(e,r,t,n,a){var i=e.type,s=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r,i)&&!e.required)return t();rules.required(e,r,n,s,a,i),isEmptyValue(r,i)||rules.type(e,r,n,s,a)}t(s)}function any(e,r,t,n,a){var i=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,i,a)}t(i)}var validators={string:string,method:method,number:number,boolean:_boolean,regexp:regexp,integer:integer,float:floatFn,array:array,object:object,enum:enumerable$1,pattern:pattern$2,date:date,url:type$1,hex:type$1,email:type$1,required:required$1,any:any};function newMessages(){return{default:"Validation error on field %s",required:"%s is required",enum:"%s must be one of %s",whitespace:"%s cannot be empty",date:{format:"%s date %s is invalid for format %s",parse:"%s date could not be parsed, %s is invalid ",invalid:"%s date %s is invalid"},types:{string:"%s is not a %s",method:"%s is not a %s (function)",array:"%s is not an %s",object:"%s is not an %s",number:"%s is not a %s",date:"%s is not a %s",boolean:"%s is not a %s",integer:"%s is not an %s",float:"%s is not a %s",regexp:"%s is not a valid %s",email:"%s is not a valid %s",url:"%s is not a valid %s",hex:"%s is not a valid %s"},string:{len:"%s must be exactly %s characters",min:"%s must be at least %s characters",max:"%s cannot be longer than %s characters",range:"%s must be between %s and %s characters"},number:{len:"%s must equal %s",min:"%s cannot be less than %s",max:"%s cannot be greater than %s",range:"%s must be between %s and %s"},array:{len:"%s must be exactly %s in length",min:"%s cannot be less than %s in length",max:"%s cannot be greater than %s in length",range:"%s must be between %s and %s in length"},pattern:{mismatch:"%s value %s does not match pattern %s"},clone:function(){var e=JSON.parse(JSON.stringify(this));return e.clone=this.clone,e}}}var messages=newMessages();function Schema(e){this.rules=null,this._messages=messages,this.define(e)}Schema.prototype={messages:function(e){return e&&(this._messages=deepMerge(newMessages(),e)),this._messages},define:function(e){if(!e)throw new Error("Cannot configure a schema with no rules");if("object"!=typeof e||Array.isArray(e))throw new Error("Rules must be an object");var r,t;for(r in this.rules={},e)e.hasOwnProperty(r)&&(t=e[r],this.rules[r]=Array.isArray(t)?t:[t])},validate:function(t,e,r){var n=this;void 0===e&&(e={}),void 0===r&&(r=function(){});var a,i,s=t,p=e,u=r;if("function"==typeof p&&(u=p,p={}),!this.rules||0===Object.keys(this.rules).length)return u&&u(),Promise.resolve();p.messages?((r=this.messages())===messages&&(r=newMessages()),deepMerge(r,p.messages),p.messages=r):p.messages=this.messages();var o={};(p.keys||Object.keys(this.rules)).forEach(function(r){a=n.rules[r],i=s[r],a.forEach(function(e){"function"==typeof e.transform&&(s===t&&(s=_extends({},s)),i=s[r]=e.transform(i)),(e="function"==typeof e?{validator:e}:_extends({},e)).validator=n.getValidationMethod(e),e.field=r,e.fullField=e.fullField||r,e.type=n.getType(e),e.validator&&(o[r]=o[r]||[],o[r].push({rule:e,value:i,source:s,field:r}))})});var d={};return asyncMap(o,p,function(s,u){var e,o=s.rule,l=!("object"!==o.type&&"array"!==o.type||"object"!=typeof o.fields&&"object"!=typeof o.defaultField);function f(e,r){return _extends({},r,{fullField:o.fullField+"."+e})}function r(e){void 0===e&&(e=[]);var t=e;if(Array.isArray(t)||(t=[t]),!p.suppressWarning&&t.length&&Schema.warning("async-validator:",t),t.length&&o.message&&(t=[].concat(o.message)),t=t.map(complementError(o)),p.first&&t.length)return d[o.field]=1,u(t);if(l){if(o.required&&!s.value)return t=o.message?[].concat(o.message).map(complementError(o)):p.error?[p.error(o,format(p.messages.required,o.field))]:[],u(t);var r,n,a={};if(o.defaultField)for(var i in s.value)s.value.hasOwnProperty(i)&&(a[i]=o.defaultField);for(r in a=_extends({},a,{},s.rule.fields))a.hasOwnProperty(r)&&(n=Array.isArray(a[r])?a[r]:[a[r]],a[r]=n.map(f.bind(null,r)));e=new Schema(a);e.messages(p.messages),s.rule.options&&(s.rule.options.messages=p.messages,s.rule.options.error=p.error),e.validate(s.value,s.rule.options||p,function(e){var r=[];t&&t.length&&r.push.apply(r,t),e&&e.length&&r.push.apply(r,e),u(r.length?r:null)})}else u(t)}l=l&&(o.required||!o.required&&s.value),o.field=s.field,o.asyncValidator?e=o.asyncValidator(o,s.value,r,s.source,p):o.validator&&(!0===(e=o.validator(o,s.value,r,s.source,p))?r():!1===e?r(o.message||o.field+" fails"):e instanceof Array?r(e):e instanceof Error&&r(e.message)),e&&e.then&&e.then(function(){return r()},r)},function(e){!function(e){var r,t,n=[],a={};for(r=0;r