function R(){return R=Object.assign?Object.assign.bind():function(i){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(i[r]=n[r])}return i},R.apply(this,arguments)}function ee(i,e){i.prototype=Object.create(e.prototype),i.prototype.constructor=i,T(i,e)}function U(i){return U=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},U(i)}function T(i,e){return T=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,t){return r.__proto__=t,r},T(i,e)}function ne(){if(typeof Reflect=="undefined"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(i){return!1}}function I(i,e,n){return ne()?I=Reflect.construct.bind():I=function(t,s,a){var o=[null];o.push.apply(o,s);var p=Function.bind.apply(t,o),y=new p;return a&&T(y,a.prototype),y},I.apply(null,arguments)}function re(i){return Function.toString.call(i).indexOf("[native code]")!==-1}function V(i){var e=typeof Map=="function"?new Map:void 0;return V=function(r){if(r===null||!re(r))return r;if(typeof r!="function")throw new TypeError("Super expression must either be null or a function");if(typeof e!="undefined"){if(e.has(r))return e.get(r);e.set(r,t)}function t(){return I(r,arguments,U(this).constructor)}return t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),T(t,r)},V(i)}var te=/%[sdj%]/g,ie=function(){};function k(i){if(!i||!i.length)return null;var e={};return i.forEach(function(n){var r=n.field;e[r]=e[r]||[],e[r].push(n)}),e}function E(i){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];var t=0,s=n.length;if(typeof i=="function")return i.apply(null,n);if(typeof i=="string"){var a=i.replace(te,function(o){if(o==="%%")return"%";if(t>=s)return o;switch(o){case"%s":return String(n[t++]);case"%d":return Number(n[t++]);case"%j":try{return JSON.stringify(n[t++])}catch(p){return"[Circular]"}break;default:return o}});return a}return i}function ae(i){return i==="string"||i==="url"||i==="hex"||i==="email"||i==="date"||i==="pattern"}function v(i,e){return!!(i==null||e==="array"&&Array.isArray(i)&&!i.length||ae(e)&&typeof i=="string"&&!i)}function se(i,e,n){var r=[],t=0,s=i.length;function a(o){r.push.apply(r,o||[]),t++,t===s&&n(r)}i.forEach(function(o){e(o,a)})}function $(i,e,n){var r=0,t=i.length;function s(a){if(a&&a.length){n(a);return}var o=r;r=r+1,o<t?e(i[o],s):n([])}s([])}function oe(i){var e=[];return Object.keys(i).forEach(function(n){e.push.apply(e,i[n]||[])}),e}var K=function(i){ee(e,i);function e(n,r){var t;return t=i.call(this,"Async Validation Error")||this,t.errors=n,t.fields=r,t}return e}(V(Error));function fe(i,e,n,r,t){if(e.first){var s=new Promise(function(O,C){var S=function(f){return r(f),f.length?C(new K(f,k(f))):O(t)},d=oe(i);$(d,n,S)});return s.catch(function(O){return O}),s}var a=e.firstFields===!0?Object.keys(i):e.firstFields||[],o=Object.keys(i),p=o.length,y=0,_=[],h=new Promise(function(O,C){var S=function(l){if(_.push.apply(_,l),y++,y===p)return r(_),_.length?C(new K(_,k(_))):O(t)};o.length||(r(_),O(t)),o.forEach(function(d){var l=i[d];a.indexOf(d)!==-1?$(l,n,S):se(l,n,S)})});return h.catch(function(O){return O}),h}function pe(i){return!!(i&&i.message!==void 0)}function de(i,e){for(var n=i,r=0;r<e.length;r++){if(n==null)return n;n=n[e[r]]}return n}function Y(i,e){return function(n){var r;return i.fullFields?r=de(e,i.fullFields):r=e[n.field||i.fullField],pe(n)?(n.field=n.field||i.fullField,n.fieldValue=r,n):{message:typeof n=="function"?n():n,fieldValue:r,field:n.field||i.fullField}}}function X(i,e){if(e){for(var n in e)if(e.hasOwnProperty(n)){var r=e[n];typeof r=="object"&&typeof i[n]=="object"?i[n]=R({},i[n],r):i[n]=r}}return i}var Q=function(e,n,r,t,s,a){e.required&&(!r.hasOwnProperty(e.field)||v(n,a||e.type))&&t.push(E(s.messages.required,e.fullField))},ce=function(e,n,r,t,s){(/^\s+$/.test(n)||n==="")&&t.push(E(s.messages.whitespace,e.fullField))},M,me=function(){if(M)return M;var e="[a-fA-F\\d:]",n=function(g){return g&&g.includeBoundaries?"(?:(?<=\\s|^)(?="+e+")|(?<="+e+")(?=\\s|$))":""},r="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",t="[a-fA-F\\d]{1,4}",s=(`
(?:
(?:`+t+":){7}(?:"+t+`|:)|                                    // 1:2:3:4:5:6:7::  1:2:3:4:5:6:7:8
(?:`+t+":){6}(?:"+r+"|:"+t+`|:)|                             // 1:2:3:4:5:6::    1:2:3:4:5:6::8   1:2:3:4:5:6::8  1:2:3:4:5:6::1.2.3.4
(?:`+t+":){5}(?::"+r+"|(?::"+t+`){1,2}|:)|                   // 1:2:3:4:5::      1:2:3:4:5::7:8   1:2:3:4:5::8    1:2:3:4:5::7:1.2.3.4
(?:`+t+":){4}(?:(?::"+t+"){0,1}:"+r+"|(?::"+t+`){1,3}|:)| // 1:2:3:4::        1:2:3:4::6:7:8   1:2:3:4::8      1:2:3:4::6:7:1.2.3.4
(?:`+t+":){3}(?:(?::"+t+"){0,2}:"+r+"|(?::"+t+`){1,4}|:)| // 1:2:3::          1:2:3::5:6:7:8   1:2:3::8        1:2:3::5:6:7:1.2.3.4
(?:`+t+":){2}(?:(?::"+t+"){0,3}:"+r+"|(?::"+t+`){1,5}|:)| // 1:2::            1:2::4:5:6:7:8   1:2::8          1:2::4:5:6:7:1.2.3.4
(?:`+t+":){1}(?:(?::"+t+"){0,4}:"+r+"|(?::"+t+`){1,6}|:)| // 1::              1::3:4:5:6:7:8   1::8            1::3:4:5:6:7:1.2.3.4
(?::(?:(?::`+t+"){0,5}:"+r+"|(?::"+t+`){1,7}|:))             // ::2:3:4:5:6:7:8  ::2:3:4:5:6:7:8  ::8             ::1.2.3.4
)(?:%[0-9a-zA-Z]{1,})?                                             // %eth0            %1
`).replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),a=new RegExp("(?:^"+r+"$)|(?:^"+s+"$)"),o=new RegExp("^"+r+"$"),p=new RegExp("^"+s+"$"),y=function(g){return g&&g.exact?a:new RegExp("(?:"+n(g)+r+n(g)+")|(?:"+n(g)+s+n(g)+")","g")};y.v4=function(m){return m&&m.exact?o:new RegExp(""+n(m)+r+n(m),"g")},y.v6=function(m){return m&&m.exact?p:new RegExp(""+n(m)+s+n(m),"g")};var _="(?:(?:[a-z]+:)?//)",h="(?:\\S+(?::\\S*)?@)?",O=y.v4().source,C=y.v6().source,S="(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)",d="(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*",l="(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))",f="(?::\\d{2,5})?",D='(?:[/?#][^\\s"]*)?',u="(?:"+_+"|www\\.)"+h+"(?:localhost|"+O+"|"+C+"|"+S+d+l+")"+f+D;return M=new RegExp("(?:^"+u+"$)","i"),M},Z={email:/^(([^<>()\[\]\\.,;:\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},x={integer:function(e){return x.number(e)&&parseInt(e,10)===e},float:function(e){return x.number(e)&&!x.integer(e)},array:function(e){return Array.isArray(e)},regexp:function(e){if(e instanceof RegExp)return!0;try{return!!new RegExp(e)}catch(n){return!1}},date:function(e){return typeof e.getTime=="function"&&typeof e.getMonth=="function"&&typeof e.getYear=="function"&&!isNaN(e.getTime())},number:function(e){return isNaN(e)?!1:typeof e=="number"},object:function(e){return typeof e=="object"&&!x.array(e)},method:function(e){return typeof e=="function"},email:function(e){return typeof e=="string"&&e.length<=320&&!!e.match(Z.email)},url:function(e){return typeof e=="string"&&e.length<=2048&&!!e.match(me())},hex:function(e){return typeof e=="string"&&!!e.match(Z.hex)}},ue=function(e,n,r,t,s){if(e.required&&n===void 0){Q(e,n,r,t,s);return}var a=["integer","float","array","regexp","object","method","email","number","date","url","hex"],o=e.type;a.indexOf(o)>-1?x[o](n)||t.push(E(s.messages.types[o],e.fullField,e.type)):o&&typeof n!==e.type&&t.push(E(s.messages.types[o],e.fullField,e.type))},ge=function(e,n,r,t,s){var a=typeof e.len=="number",o=typeof e.min=="number",p=typeof e.max=="number",y=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,_=n,h=null,O=typeof n=="number",C=typeof n=="string",S=Array.isArray(n);if(O?h="number":C?h="string":S&&(h="array"),!h)return!1;S&&(_=n.length),C&&(_=n.replace(y,"_").length),a?_!==e.len&&t.push(E(s.messages[h].len,e.fullField,e.len)):o&&!p&&_<e.min?t.push(E(s.messages[h].min,e.fullField,e.min)):p&&!o&&_>e.max?t.push(E(s.messages[h].max,e.fullField,e.max)):o&&p&&(_<e.min||_>e.max)&&t.push(E(s.messages[h].range,e.fullField,e.min,e.max))},j="enum",le=function(e,n,r,t,s){e[j]=Array.isArray(e[j])?e[j]:[],e[j].indexOf(n)===-1&&t.push(E(s.messages[j],e.fullField,e[j].join(", ")))},_e=function(e,n,r,t,s){if(e.pattern){if(e.pattern instanceof RegExp)e.pattern.lastIndex=0,e.pattern.test(n)||t.push(E(s.messages.pattern.mismatch,e.fullField,n,e.pattern));else if(typeof e.pattern=="string"){var a=new RegExp(e.pattern);a.test(n)||t.push(E(s.messages.pattern.mismatch,e.fullField,n,e.pattern))}}},c={required:Q,whitespace:ce,type:ue,range:ge,enum:le,pattern:_e},ve=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(v(n,"string")&&!e.required)return r();c.required(e,n,t,a,s,"string"),v(n,"string")||(c.type(e,n,t,a,s),c.range(e,n,t,a,s),c.pattern(e,n,t,a,s),e.whitespace===!0&&c.whitespace(e,n,t,a,s))}r(a)},ye=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(v(n)&&!e.required)return r();c.required(e,n,t,a,s),n!==void 0&&c.type(e,n,t,a,s)}r(a)},he=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(n===""&&(n=void 0),v(n)&&!e.required)return r();c.required(e,n,t,a,s),n!==void 0&&(c.type(e,n,t,a,s),c.range(e,n,t,a,s))}r(a)},Oe=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(v(n)&&!e.required)return r();c.required(e,n,t,a,s),n!==void 0&&c.type(e,n,t,a,s)}r(a)},Pe=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(v(n)&&!e.required)return r();c.required(e,n,t,a,s),v(n)||c.type(e,n,t,a,s)}r(a)},Ee=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(v(n)&&!e.required)return r();c.required(e,n,t,a,s),n!==void 0&&(c.type(e,n,t,a,s),c.range(e,n,t,a,s))}r(a)},Se=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(v(n)&&!e.required)return r();c.required(e,n,t,a,s),n!==void 0&&(c.type(e,n,t,a,s),c.range(e,n,t,a,s))}r(a)},Ce=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(n==null&&!e.required)return r();c.required(e,n,t,a,s,"array"),n!=null&&(c.type(e,n,t,a,s),c.range(e,n,t,a,s))}r(a)},Ae=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(v(n)&&!e.required)return r();c.required(e,n,t,a,s),n!==void 0&&c.type(e,n,t,a,s)}r(a)},De="enum",be=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(v(n)&&!e.required)return r();c.required(e,n,t,a,s),n!==void 0&&c[De](e,n,t,a,s)}r(a)},we=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(v(n,"string")&&!e.required)return r();c.required(e,n,t,a,s),v(n,"string")||c.pattern(e,n,t,a,s)}r(a)},Fe=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(v(n,"date")&&!e.required)return r();if(c.required(e,n,t,a,s),!v(n,"date")){var p;n instanceof Date?p=n:p=new Date(n),c.type(e,p,t,a,s),p&&c.range(e,p.getTime(),t,a,s)}}r(a)},Re=function(e,n,r,t,s){var a=[],o=Array.isArray(n)?"array":typeof n;c.required(e,n,t,a,s,o),r(a)},L=function(e,n,r,t,s){var a=e.type,o=[],p=e.required||!e.required&&t.hasOwnProperty(e.field);if(p){if(v(n,a)&&!e.required)return r();c.required(e,n,t,o,s,a),v(n,a)||c.type(e,n,t,o,s)}r(o)},je=function(e,n,r,t,s){var a=[],o=e.required||!e.required&&t.hasOwnProperty(e.field);if(o){if(v(n)&&!e.required)return r();c.required(e,n,t,a,s)}r(a)},q={string:ve,method:ye,number:he,boolean:Oe,regexp:Pe,integer:Ee,float:Se,array:Ce,object:Ae,enum:be,pattern:we,date:Fe,url:L,hex:L,email:L,required:Re,any:je};function H(){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 G=H(),W=function(){function i(n){this.rules=null,this._messages=G,this.define(n)}var e=i.prototype;return e.define=function(r){var t=this;if(!r)throw new Error("Cannot configure a schema with no rules");if(typeof r!="object"||Array.isArray(r))throw new Error("Rules must be an object");this.rules={},Object.keys(r).forEach(function(s){var a=r[s];t.rules[s]=Array.isArray(a)?a:[a]})},e.messages=function(r){return r&&(this._messages=X(H(),r)),this._messages},e.validate=function(r,t,s){var a=this;t===void 0&&(t={}),s===void 0&&(s=function(){});var o=r,p=t,y=s;if(typeof p=="function"&&(y=p,p={}),!this.rules||Object.keys(this.rules).length===0)return y&&y(null,o),Promise.resolve(o);function _(d){var l=[],f={};function D(m){if(Array.isArray(m)){var g;l=(g=l).concat.apply(g,m)}else l.push(m)}for(var u=0;u<d.length;u++)D(d[u]);l.length?(f=k(l),y(l,f)):y(null,o)}if(p.messages){var h=this.messages();h===G&&(h=H()),X(h,p.messages),p.messages=h}else p.messages=this.messages();var O={},C=p.keys||Object.keys(this.rules);C.forEach(function(d){var l=a.rules[d],f=o[d];l.forEach(function(D){var u=D;typeof u.transform=="function"&&(o===r&&(o=R({},o)),f=o[d]=u.transform(f)),typeof u=="function"?u={validator:u}:u=R({},u),u.validator=a.getValidationMethod(u),u.validator&&(u.field=d,u.fullField=u.fullField||d,u.type=a.getType(u),O[d]=O[d]||[],O[d].push({rule:u,value:f,source:o,field:d}))})});var S={};return fe(O,p,function(d,l){var f=d.rule,D=(f.type==="object"||f.type==="array")&&(typeof f.fields=="object"||typeof f.defaultField=="object");D=D&&(f.required||!f.required&&d.value),f.field=d.field;function u(P,F){return R({},F,{fullField:f.fullField+"."+P,fullFields:f.fullFields?[].concat(f.fullFields,[P]):[P]})}function m(P){P===void 0&&(P=[]);var F=Array.isArray(P)?P:[P];!p.suppressWarning&&F.length&&i.warning("async-validator:",F),F.length&&f.message!==void 0&&(F=[].concat(f.message));var b=F.map(Y(f,o));if(p.first&&b.length)return S[f.field]=1,l(b);if(!D)l(b);else{if(f.required&&!d.value)return f.message!==void 0?b=[].concat(f.message).map(Y(f,o)):p.error&&(b=[p.error(f,E(p.messages.required,f.field))]),l(b);var N={};f.defaultField&&Object.keys(d.value).map(function(w){N[w]=f.defaultField}),N=R({},N,d.rule.fields);var J={};Object.keys(N).forEach(function(w){var A=N[w],z=Array.isArray(A)?A:[A];J[w]=z.map(u.bind(null,w))});var B=new i(J);B.messages(p.messages),d.rule.options&&(d.rule.options.messages=p.messages,d.rule.options.error=p.error),B.validate(d.value,d.rule.options||p,function(w){var A=[];b&&b.length&&A.push.apply(A,b),w&&w.length&&A.push.apply(A,w),l(A.length?A:null)})}}var g;if(f.asyncValidator)g=f.asyncValidator(f,d.value,m,d.source,p);else if(f.validator){try{g=f.validator(f,d.value,m,d.source,p)}catch(P){console.error==null||console.error(P),p.suppressValidatorError||setTimeout(function(){throw P},0),m(P.message)}g===!0?m():g===!1?m(typeof f.message=="function"?f.message(f.fullField||f.field):f.message||(f.fullField||f.field)+" fails"):g instanceof Array?m(g):g instanceof Error&&m(g.message)}g&&g.then&&g.then(function(){return m()},function(P){return m(P)})},function(d){_(d)},o)},e.getType=function(r){if(r.type===void 0&&r.pattern instanceof RegExp&&(r.type="pattern"),typeof r.validator!="function"&&r.type&&!q.hasOwnProperty(r.type))throw new Error(E("Unknown rule type %s",r.type));return r.type||"string"},e.getValidationMethod=function(r){if(typeof r.validator=="function")return r.validator;var t=Object.keys(r),s=t.indexOf("message");return s!==-1&&t.splice(s,1),t.length===1&&t[0]==="required"?q.required:q[this.getType(r)]||void 0},i}();W.register=function(e,n){if(typeof n!="function")throw new Error("Cannot register a validator by type, validator is not a function");q[e]=n};W.warning=ie;W.messages=G;W.validators=q;export{W as S};
