"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _extends(){return(_extends=Object.assign?Object.assign.bind():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\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/,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&&!isNaN(e.getTime())},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.length<=320&&!!e.match(pattern$2.email)},url:function(e){return"string"==typeof e&&e.length<=2048&&!!e.match(getUrlRegex())},hex:function(e){return"string"==typeof e&&!!e.match(pattern$2.hex)}},type$1=function(e,r,t,n,i){e.required&&void 0===r?required$1(e,r,t,n,i):(t=e.type,-1<["integer","float","array","regexp","object","method","email","number","date","url","hex"].indexOf(t)?types[t](r)||n.push(format(i.messages.types[t],e.fullField,e.type)):t&&_typeof(r)!==e.type&&n.push(format(i.messages.types[t],e.fullField,e.type)))},range=function(e,r,t,n,i){var a="number"==typeof e.len,s="number"==typeof e.min,u="number"==typeof e.max,o=r,l=null,f="number"==typeof r,c="string"==typeof r,p=Array.isArray(r);if(f?l="number":c?l="string":p&&(l="array"),!l)return!1;p&&(o=r.length),c&&(o=r.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,"_").length),a?o!==e.len&&n.push(format(i.messages[l].len,e.fullField,e.len)):s&&!u&&oe.max?n.push(format(i.messages[l].max,e.fullField,e.max)):s&&u&&(oe.max)&&n.push(format(i.messages[l].range,e.fullField,e.min,e.max))},ENUM$1="enum",enumerable$1=function(e,r,t,n,i){e[ENUM$1]=Array.isArray(e[ENUM$1])?e[ENUM$1]:[],-1===e[ENUM$1].indexOf(r)&&n.push(format(i.messages[ENUM$1],e.fullField,e[ENUM$1].join(", ")))},pattern$1=function(e,r,t,n,i){e.pattern&&(e.pattern instanceof RegExp?(e.pattern.lastIndex=0,e.pattern.test(r)||n.push(format(i.messages.pattern.mismatch,e.fullField,r,e.pattern))):"string"!=typeof e.pattern||new RegExp(e.pattern).test(r)||n.push(format(i.messages.pattern.mismatch,e.fullField,r,e.pattern)))},rules={required:required$1,whitespace:whitespace,type:type$1,range:range,enum:enumerable$1,pattern:pattern$1},string=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r,"string")&&!e.required)return t();rules.required(e,r,n,a,i,"string"),isEmptyValue(r,"string")||(rules.type(e,r,n,a,i),rules.range(e,r,n,a,i),rules.pattern(e,r,n,a,i),!0===e.whitespace&&rules.whitespace(e,r,n,a,i))}t(a)},method=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,a,i),void 0!==r&&rules.type(e,r,n,a,i)}t(a)},number=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r=""===r?void 0:r)&&!e.required)return t();rules.required(e,r,n,a,i),void 0!==r&&(rules.type(e,r,n,a,i),rules.range(e,r,n,a,i))}t(a)},_boolean=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,a,i),void 0!==r&&rules.type(e,r,n,a,i)}t(a)},regexp=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,a,i),isEmptyValue(r)||rules.type(e,r,n,a,i)}t(a)},integer=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,a,i),void 0!==r&&(rules.type(e,r,n,a,i),rules.range(e,r,n,a,i))}t(a)},floatFn=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,a,i),void 0!==r&&(rules.type(e,r,n,a,i),rules.range(e,r,n,a,i))}t(a)},array=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(null==r&&!e.required)return t();rules.required(e,r,n,a,i,"array"),null!=r&&(rules.type(e,r,n,a,i),rules.range(e,r,n,a,i))}t(a)},object=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,a,i),void 0!==r&&rules.type(e,r,n,a,i)}t(a)},ENUM="enum",enumerable=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,a,i),void 0!==r&&rules[ENUM](e,r,n,a,i)}t(a)},pattern=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r,"string")&&!e.required)return t();rules.required(e,r,n,a,i),isEmptyValue(r,"string")||rules.pattern(e,r,n,a,i)}t(a)},date=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r,"date")&&!e.required)return t();rules.required(e,r,n,a,i),isEmptyValue(r,"date")||(r=r instanceof Date?r:new Date(r),rules.type(e,r,n,a,i),r&&rules.range(e,r.getTime(),n,a,i))}t(a)},required=function(e,r,t,n,i){var a=[],s=Array.isArray(r)?"array":_typeof(r);rules.required(e,r,n,a,i,s),t(a)},type=function(e,r,t,n,i){var a=e.type,s=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r,a)&&!e.required)return t();rules.required(e,r,n,s,i,a),isEmptyValue(r,a)||rules.type(e,r,n,s,i)}t(s)},any=function(e,r,t,n,i){var a=[];if(e.required||!e.required&&n.hasOwnProperty(e.field)){if(isEmptyValue(r)&&!e.required)return t();rules.required(e,r,n,a,i)}t(a)},validators={string:string,method:method,number:number,boolean:_boolean,regexp:regexp,integer:integer,float:floatFn,array:array,object:object,enum:enumerable,pattern:pattern,date:date,url:type,hex:type,email:type,required:required,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(),Schema=exports.default=function(){function f(e){this.rules=null,this._messages=messages,this.define(e)}var e=f.prototype;return e.define=function(t){var n=this;if(!t)throw new Error("Cannot configure a schema with no rules");if("object"!==_typeof(t)||Array.isArray(t))throw new Error("Rules must be an object");this.rules={},Object.keys(t).forEach(function(e){var r=t[e];n.rules[e]=Array.isArray(r)?r:[r]})},e.messages=function(e){return e&&(this._messages=deepMerge(newMessages(),e)),this._messages},e.validate=function(n,e,r){var i=this,o=n,l=e=void 0===e?{}:e,a=r=void 0===r?function(){}:r;if("function"==typeof l&&(a=l,l={}),!this.rules||0===Object.keys(this.rules).length)return a&&a(null,o),Promise.resolve(o);function t(e){var r,t=[];for(var n,i=0;i