UNPKG

fluentvalidation-ts

Version:

A TypeScript-first library for building strongly-typed validation rules

1 lines 25 kB
function e(e){if(e===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function n(e,n,t,r,u,l,i){try{var s=e[l](i);var a=s.value}catch(e){t(e);return}if(s.done){n(a)}else{Promise.resolve(a).then(r,u)}}function t(e){return function(){var t=this,r=arguments;return new Promise(function(u,l){var i=e.apply(t,r);function s(e){n(i,u,l,s,a,"next",e)}function a(e){n(i,u,l,s,a,"throw",e)}s(undefined)})}}function r(e,n,t){n=i(n);return f(e,y()?Reflect.construct(n,t||[],i(e).constructor):n.apply(e,t))}function u(e,n){if(!(e instanceof n)){throw new TypeError("Cannot call a class as a function")}}function l(e,n,t){if(n in e){Object.defineProperty(e,n,{value:t,enumerable:true,configurable:true,writable:true})}else{e[n]=t}return e}function i(e){i=Object.setPrototypeOf?Object.getPrototypeOf:function e(e){return e.__proto__||Object.getPrototypeOf(e)};return i(e)}function s(e,n){if(typeof n!=="function"&&n!==null){throw new TypeError("Super expression must either be null or a function")}e.prototype=Object.create(n&&n.prototype,{constructor:{value:e,writable:true,configurable:true}});if(n)h(e,n)}function a(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};var r=Object.keys(t);if(typeof Object.getOwnPropertySymbols==="function"){r=r.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))}r.forEach(function(n){l(e,n,t[n])})}return e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);if(n){r=r.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})}t.push.apply(t,r)}return t}function c(e,n){n=n!=null?n:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(n))}else{o(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function f(n,t){if(t&&(d(t)==="object"||typeof t==="function")){return t}return e(n)}function h(e,n){h=Object.setPrototypeOf||function e(e,n){e.__proto__=n;return e};return h(e,n)}function d(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}function y(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(y=function(){return!!e})()}function v(e,n){var t,r,u,l={label:0,sent:function(){if(u[0]&1)throw u[1];return u[1]},trys:[],ops:[]},i=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return i.next=s(0),i["throw"]=s(1),i["return"]=s(2),typeof Symbol==="function"&&(i[Symbol.iterator]=function(){return this}),i;function s(e){return function(n){return a([e,n])}}function a(s){if(t)throw new TypeError("Generator is already executing.");while(i&&(i=0,s[0]&&(l=0)),l)try{if(t=1,r&&(u=s[0]&2?r["return"]:s[0]?r["throw"]||((u=r["return"])&&u.call(r),0):r.next)&&!(u=u.call(r,s[1])).done)return u;if(r=0,u)s=[s[0]&2,u.value];switch(s[0]){case 0:case 1:u=s;break;case 4:l.label++;return{value:s[1],done:false};case 5:l.label++;r=s[1];s=[0];continue;case 7:s=l.ops.pop();l.trys.pop();continue;default:if(!(u=l.trys,u=u.length>0&&u[u.length-1])&&(s[0]===6||s[0]===2)){l=0;continue}if(s[0]===3&&(!u||s[1]>u[0]&&s[1]<u[3])){l.label=s[1];break}if(s[0]===6&&l.label<u[1]){l.label=u[1];u=s;break}if(u&&l.label<u[2]){l.label=u[2];l.ops.push(s);break}if(u[2])l.ops.pop();l.trys.pop();continue}s=n.call(e,l)}catch(e){s=[6,e];r=0}finally{t=u=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}}var p=function(e){return e==null?false:Array.isArray(e)?e.filter(function(e){return p(e)}).length>0:(typeof e==="undefined"?"undefined":d(e))=="object"?Object.keys(e).length>0:true};var b=function e(){"use strict";var n=this;u(this,e);this.setCustomErrorMessage=function(e){n.customErrorMessage=e};this.setWhenCondition=function(e){n.whenCondition=e};this.setUnlessCondition=function(e){n.unlessCondition=e}};var w=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);var t;t=r(this,n);t.validate=function(e,n){if(t.whenCondition!=null&&!t.whenCondition(n)||t.unlessCondition!=null&&t.unlessCondition(n))return null;var r=t.valueValidator(e,n);return r!=null?t.customErrorMessage||r:null};t.valueValidator=e;return t}return n}(b);var g=/^[a-zA-Z0-9.!#$%&’"*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+$/,m=/*#__PURE__*/function(e){"use strict";s(n,e);function n(){u(this,n);return r(this,n,[function(e){if(e==null)return null;if(typeof e!="string")throw new TypeError("A non-string value was passed to the emailAddress rule");return g.test(e)?null:"Not a valid email address"}])}return n}(w);var A=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n){return n===e?null:"Must equal '".concat(e,"'")}])}return n}(w);var _=function(e){return e.toLocaleString(void 0,{maximumFractionDigits:20})};var R=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e,t){u(this,n);return r(this,n,[function(n){if(n==null)return null;if(typeof n!="number")throw new TypeError("A non-number value was passed to the exclusiveBetween rule");return n>e&&n<t?null:"Value must be between ".concat(_(e)," and ").concat(_(t)," (exclusive)")}])}return n}(w);var V=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n){if(n==null)return null;if(typeof n!="number")throw new TypeError("A non-number value was passed to the greaterThanOrEqualTo rule");return n>=e?null:"Value must be greater than or equal to ".concat(_(e))}])}return n}(w);var E=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n){if(n==null)return null;if(typeof n!="number")throw new TypeError("A non-number value was passed to the greaterThan rule");return n>e?null:"Value must be greater than ".concat(_(e))}])}return n}(w);var P=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e,t){u(this,n);return r(this,n,[function(n){if(n==null)return null;if(typeof n!="number")throw new TypeError("A non-number value was passed to the inclusiveBetween rule");return n>=e&&n<=t?null:"Value must be between ".concat(_(e)," and ").concat(_(t)," (inclusive)")}])}return n}(w);var B=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e,t){u(this,n);return r(this,n,[function(n){if(n==null)return null;if(typeof n!="string")throw new TypeError("A non-string value was passed to the length rule");return n.length>=e&&n.length<=t?null:"Value must be between ".concat(_(e)," and ").concat(_(t)," characters long")}])}return n}(w);var C=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n){if(n==null)return null;if(typeof n!="number")throw new TypeError("A non-number value was passed to the lessThanOrEqualTo rule");return n<=e?null:"Value must be less than or equal to ".concat(_(e))}])}return n}(w);var x=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n){if(n==null)return null;if(typeof n!="number")throw new TypeError("A non-number value was passed to the lessThan rule");return n<e?null:"Value must be less than ".concat(_(e))}])}return n}(w);var O=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n){if(n==null)return null;if(typeof n!="string")throw new TypeError("A non-string value was passed to the matches rule");return e.test(n)?null:"Value does not match the required pattern"}])}return n}(w);var T=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n){if(n==null)return null;if(typeof n!="string")throw new TypeError("A non-string value was passed to the maxLength rule");return n.length<=e?null:"Value must be no more than ".concat(_(e)," characters long")}])}return n}(w);var U=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n){if(n==null)return null;if(typeof n!="string")throw new TypeError("A non-string value was passed to the minLength rule");return n.length>=e?null:"Value must be at least ".concat(_(e)," characters long")}])}return n}(w);var N=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n,t){if(Array.isArray(e)){var r=true,u=false,l=undefined;try{for(var i=e[Symbol.iterator](),s;!(r=(s=i.next()).done);r=true){var a=s.value;if(typeof a=="function"){if(!a(n,t))return"Value is not valid"}else if(!a.predicate(n,t))return typeof a.message=="function"?a.message(n,t):a.message}}catch(e){u=true;l=e}finally{try{if(!r&&i.return!=null){i.return()}}finally{if(u){throw l}}}return null}if(typeof e=="function")return e(n,t)?null:"Value is not valid";var o=e.predicate,c=e.message;return o(n,t)?null:typeof c=="function"?c(n,t):c}])}return n}(w);var j=/*#__PURE__*/function(e){"use strict";s(n,e);function n(){u(this,n);return r(this,n,[function(e){if(typeof e!="string"){if(e==null)return null;throw new TypeError("A non-string value was passed to the notEmpty rule")}return e.trim().length>0?null:"Value cannot be empty"}])}return n}(w);var S=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n){return n!==e?null:"Must not equal '".concat(e,"'")}])}return n}(w);var q=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){var t=e.includeUndefined;u(this,n);return r(this,n,[function(e){return t?e==null?"Value cannot be null":null:e===null?"Value cannot be null":null}])}return n}(w);var L=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){var t=e.includeUndefined;u(this,n);return r(this,n,[function(e){return t?e==null?null:"Value must be null":e===null?null:"Value must be null"}])}return n}(w);var k=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e,t){u(this,n);return r(this,n,[function(n){if(n==null||n===0)return null;if(typeof n!="number")throw new TypeError("A non-number value was passed to the precisionScale rule");return I({precision:e,scale:t}).test(n.toString())?null:"Value must not be more than ".concat(e," digits in total, with allowance for ").concat(t," decimals")}])}return n}(w),I=function(e){var n=e.precision,t=e.scale;var r=n-t;return r===0?new RegExp("^-?0?\\.\\d{0,".concat(t,"}$")):new RegExp("^-?\\d{1,".concat(r,"}(\\.\\d{1,").concat(t,"})?$"))};var M=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n,t){return n==null?null:e(t).validate(n)}])}return n}(w);var F=/*#__PURE__*/function(e){"use strict";s(n,e);function n(){u(this,n);return r(this,n,[function(e){return e===void 0?"Value cannot be undefined":null}])}return n}(w);var D=/*#__PURE__*/function(e){"use strict";s(n,e);function n(){u(this,n);return r(this,n,[function(e){return e===void 0?null:"Value must be undefined"}])}return n}(w);var $=function e(n,t){"use strict";var r=this;var l=this;u(this,e);this.rules=[];this.numberOfRulesInCurrentConditionChain=0;this.pushRule=function(e){r.rules.push({isAsync:false,rule:e}),r.numberOfRulesInCurrentConditionChain+=1,r.rebuildValidate()};this.pushAsyncRule=function(e){r.rules.push({isAsync:true,rule:e}),r.numberOfRulesInCurrentConditionChain+=1,r.rebuildValidate()};this.getRulesInCurrentConditionChain=function(){return r.numberOfRulesInCurrentConditionChain===0?[]:r.rules.slice(-r.numberOfRulesInCurrentConditionChain)};this.breakOffCurrentConditionChain=function(){return r.numberOfRulesInCurrentConditionChain=0};this.withMessage=function(e){return r.getLatestRule().rule.setCustomErrorMessage(e),r.rebuildValidate(),r.getAllRulesAndConditionExtensions()};this.when=function(e){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"AppliesToAllValidators";var t=true,r=false,u=undefined;if(n==="AppliesToAllValidators")try{for(var i=l.getRulesInCurrentConditionChain()[Symbol.iterator](),s;!(t=(s=i.next()).done);t=true){var a=s.value;a.rule.setWhenCondition(e)}}catch(e){r=true;u=e}finally{try{if(!t&&i.return!=null){i.return()}}finally{if(r){throw u}}}else l.getLatestRule().rule.setWhenCondition(e);return l.rebuildValidate(),l.breakOffCurrentConditionChain(),l.getAllRules()};this.unless=function(e){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"AppliesToAllValidators";var t=true,r=false,u=undefined;if(n==="AppliesToAllValidators")try{for(var i=l.getRulesInCurrentConditionChain()[Symbol.iterator](),s;!(t=(s=i.next()).done);t=true){var a=s.value;a.rule.setUnlessCondition(e)}}catch(e){r=true;u=e}finally{try{if(!t&&i.return!=null){i.return()}}finally{if(r){throw u}}}else l.getLatestRule().rule.setUnlessCondition(e);return l.rebuildValidate(),l.breakOffCurrentConditionChain(),l.getAllRules()};this.notEqual=function(e){var n=new S(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.equal=function(e){var n=new A(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.must=function(e){var n=new N(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.notNull=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{includeUndefined:true};var n=new q(e);return l.pushRule(n),l.getAllRulesAndExtensions()};this.notUndefined=function(){var e=new F;return r.pushRule(e),r.getAllRulesAndExtensions()};this.null=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{includeUndefined:true};var n=new L(e);return l.pushRule(n),l.getAllRulesAndExtensions()};this.undefined=function(){var e=new D;return r.pushRule(e),r.getAllRulesAndExtensions()};this.notEmpty=function(){var e=new j;return r.pushRule(e),r.getAllRulesAndExtensions()};this.length=function(e,n){var t=new B(e,n);return r.pushRule(t),r.getAllRulesAndExtensions()};this.maxLength=function(e){var n=new T(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.minLength=function(e){var n=new U(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.matches=function(e){var n=new O(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.emailAddress=function(){var e=new m;return r.pushRule(e),r.getAllRulesAndExtensions()};this.lessThan=function(e){var n=new x(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.lessThanOrEqualTo=function(e){var n=new C(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.greaterThan=function(e){var n=new E(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.greaterThanOrEqualTo=function(e){var n=new V(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.exclusiveBetween=function(e,n){var t=new R(e,n);return r.pushRule(t),r.getAllRulesAndExtensions()};this.inclusiveBetween=function(e,n){var t=new P(e,n);return r.pushRule(t),r.getAllRulesAndExtensions()};this.setValidator=function(e){var n=new M(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.precisionScale=function(e,n){if(e<1||n<0||e<n)throw new Error("Invalid scale and precision were passed to the precisionScale rule");var t=new k(e,n);return r.pushRule(t),r.getAllRulesAndExtensions()};this._getAllRules=function(){return{notEqual:r.notEqual,equal:r.equal,must:r.must,notNull:r.notNull,notUndefined:r.notUndefined,null:r.null,undefined:r.undefined,notEmpty:r.notEmpty,length:r.length,maxLength:r.maxLength,minLength:r.minLength,matches:r.matches,emailAddress:r.emailAddress,lessThan:r.lessThan,lessThanOrEqualTo:r.lessThanOrEqualTo,greaterThan:r.greaterThan,greaterThanOrEqualTo:r.greaterThanOrEqualTo,exclusiveBetween:r.exclusiveBetween,inclusiveBetween:r.inclusiveBetween,setValidator:r.setValidator,precisionScale:r.precisionScale}};this.getLatestRule=function(){return r.rules[r.rules.length-1]};this.rebuildValidate=n,this.transformValue=t};var z=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e,t){u(this,n);var l;l=r(this,n,[e,t]);l.build=function(){return function(e,n){var t=l.transformValue(e);var r=true,u=false,i=undefined;try{for(var s=l.rules[Symbol.iterator](),a;!(r=(a=s.next()).done);r=true){var o=a.value;var c=o.rule.validate(t,n);if(p(c))return c}}catch(e){u=true;i=e}finally{try{if(!r&&s.return!=null){s.return()}}finally{if(u){throw i}}}return null}};l.getAllRules=function(){return l._getAllRules()};l.getAllRulesAndConditionExtensions=function(){return c(a({},l.getAllRules()),{when:l.when,unless:l.unless})};l.getAllRulesAndExtensions=function(){return c(a({},l.getAllRulesAndConditionExtensions()),{withMessage:l.withMessage})};return l}return n}($);var W=function e(n,t){"use strict";var r=this;u(this,e);this.build=function(){return function(e,n){if(e==null)return null;var t=r.eachValueValidatorBuilder.build(),u=e.map(function(e){var r=t(e,n);return p(r)?r:null});return p(u)?u:null}};this.getAllRules=function(){return r.eachValueValidatorBuilder.getAllRules()};this.eachValueValidatorBuilder=new z(n,t)};var Z=function e(){"use strict";var n=this;u(this,e);this.valueValidatorBuildersByPropertyName={};this._validate=function(){return{}};this.validate=function(e){return n._validate(e)};this.rebuildValidate=function(){n._validate=function(e){var t={};var r=true,u=false,l=undefined;try{for(var i=Object.keys(n.valueValidatorBuildersByPropertyName)[Symbol.iterator](),s;!(r=(s=i.next()).done);r=true){var a=s.value;var o=n.valueValidatorBuildersByPropertyName[a];var c=true,f=false,h=undefined;try{for(var d=o[Symbol.iterator](),y;!(c=(y=d.next()).done);c=true){var v=y.value;var b=v.build()(e[a],e);p(b)&&(t[a]=b)}}catch(e){f=true;h=e}finally{try{if(!c&&d.return!=null){d.return()}}finally{if(f){throw h}}}}}catch(e){u=true;l=e}finally{try{if(!r&&i.return!=null){i.return()}}finally{if(u){throw l}}}return t}};this.ruleFor=function(e){var t=new z(n.rebuildValidate,function(e){return e});return n.valueValidatorBuildersByPropertyName[e]=n.valueValidatorBuildersByPropertyName[e]||[],n.valueValidatorBuildersByPropertyName[e].push(t),t.getAllRules()};this.ruleForTransformed=function(e,t){var r=new z(n.rebuildValidate,t);return n.valueValidatorBuildersByPropertyName[e]=n.valueValidatorBuildersByPropertyName[e]||[],n.valueValidatorBuildersByPropertyName[e].push(r),r.getAllRules()};this.ruleForEach=function(e){var t=new W(n.rebuildValidate,function(e){return e});return n.valueValidatorBuildersByPropertyName[e]==null&&(n.valueValidatorBuildersByPropertyName[e]=[]),n.valueValidatorBuildersByPropertyName[e].push(t),t.getAllRules()};this.ruleForEachTransformed=function(e,t){var r=new W(n.rebuildValidate,t);return n.valueValidatorBuildersByPropertyName[e]==null&&(n.valueValidatorBuildersByPropertyName[e]=[]),n.valueValidatorBuildersByPropertyName[e].push(r),r.getAllRules()}};var G=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);var l;var i;l=r(this,n),i=l;i.validateAsync=function(e,n){return t(function(){var t;return v(this,function(r){switch(r.label){case 0:if(i.whenCondition!=null&&!i.whenCondition(n)||i.unlessCondition!=null&&i.unlessCondition(n))return[2,null];return[4,i.asyncValueValidator(e,n)];case 1:t=r.sent();return[2,t!=null?i.customErrorMessage||t:null]}})})()};i.asyncValueValidator=e;return l}return n}(b);var H=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n,r){return t(function(){var t,u,l,i,s,a,o,c,f;return v(this,function(h){switch(h.label){case 0:if(!Array.isArray(e))return[3,11];t=true,u=false,l=undefined;h.label=1;case 1:h.trys.push([1,8,9,10]);i=e[Symbol.iterator]();h.label=2;case 2:if(!!(t=(s=i.next()).done))return[3,7];a=s.value;if(!(typeof a=="function"))return[3,4];return[4,a(n,r)];case 3:if(!h.sent())return[2,"Value is not valid"];return[3,6];case 4:return[4,a.predicate(n,r)];case 5:if(!h.sent())return[2,typeof a.message=="function"?a.message(n,r):a.message];h.label=6;case 6:t=true;return[3,2];case 7:return[3,10];case 8:o=h.sent();u=true;l=o;return[3,10];case 9:try{if(!t&&i.return!=null){i.return()}}finally{if(u){throw l}}return[7];case 10:return[2,null];case 11:if(!(typeof e=="function"))return[3,13];return[4,e(n,r)];case 12:return[2,h.sent()?null:"Value is not valid"];case 13:c=e.predicate,f=e.message;return[4,c(n,r)];case 14:return[2,h.sent()?null:typeof f=="function"?f(n,r):f]}})})()}])}return n}(G);var J=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e){u(this,n);return r(this,n,[function(n,r){return t(function(){var t;return v(this,function(u){switch(u.label){case 0:if(!(n==null))return[3,1];t=Promise.resolve(null);return[3,3];case 1:return[4,e(r).validateAsync(n)];case 2:t=u.sent();u.label=3;case 3:return[2,t]}})})()}])}return n}(G);var K=/*#__PURE__*/function(e){"use strict";s(n,e);function n(e,l){u(this,n);var i;var s;i=r(this,n,[e,l]),s=i;s.build=function(){return function(e,n){return t(function(){var t,r,u,l,i,a,o,c,f,h;return v(this,function(d){switch(d.label){case 0:t=s.transformValue(e);r=true,u=false,l=undefined;d.label=1;case 1:d.trys.push([1,8,9,10]);i=s.rules[Symbol.iterator]();d.label=2;case 2:if(!!(r=(a=i.next()).done))return[3,7];o=a.value;if(!o.isAsync)return[3,4];return[4,o.rule.validateAsync(t,n)];case 3:f=d.sent();return[3,5];case 4:f=o.rule.validate(t,n);d.label=5;case 5:c=f;if(p(c))return[2,c];d.label=6;case 6:r=true;return[3,2];case 7:return[3,10];case 8:h=d.sent();u=true;l=h;return[3,10];case 9:try{if(!r&&i.return!=null){i.return()}}finally{if(u){throw l}}return[7];case 10:return[2,null]}})})()}};s.mustAsync=function(e){var n=new H(e);return s.pushAsyncRule(n),s.getAllRulesAndExtensions()};s.setAsyncValidator=function(e){var n=new J(e);return s.pushAsyncRule(n),s.getAllRulesAndExtensions()};s.getAllRules=function(){return c(a({},s._getAllRules()),{mustAsync:s.mustAsync,setAsyncValidator:s.setAsyncValidator})};s.getAllRulesAndConditionExtensions=function(){return c(a({},s.getAllRules()),{when:s.when,unless:s.unless})};s.getAllRulesAndExtensions=function(){return c(a({},s.getAllRulesAndConditionExtensions()),{withMessage:s.withMessage})};return i}return n}($);var Q=function e(n,r){"use strict";var l=this;u(this,e);this.build=function(){return function(e,n){return t(function(){var t,r,u,l,i,s,a,o,c,f,h;return v(this,function(d){switch(d.label){case 0:if(e==null)return[2,null];t=this.eachAsyncValueValidatorBuilder.build(),r=[];u=true,l=false,i=undefined;d.label=1;case 1:d.trys.push([1,6,7,8]);s=e[Symbol.iterator]();d.label=2;case 2:if(!!(u=(a=s.next()).done))return[3,5];o=a.value;return[4,t(o,n)];case 3:c=d.sent(),f=p(c)?c:null;r.push(f);d.label=4;case 4:u=true;return[3,2];case 5:return[3,8];case 6:h=d.sent();l=true;i=h;return[3,8];case 7:try{if(!u&&s.return!=null){s.return()}}finally{if(l){throw i}}return[7];case 8:return[2,p(r)?r:null]}})}).call(l)}};this.getAllRules=function(){return l.eachAsyncValueValidatorBuilder.getAllRules()};this.eachAsyncValueValidatorBuilder=new K(n,r)};var X=function e(){"use strict";var n=this;u(this,e);this.asyncValueValidatorBuildersByPropertyName={};this._validateAsync=function(){return t(function(){return v(this,function(e){return[2,Promise.resolve({})]})})()};this.validateAsync=function(e){return n._validateAsync(e)};this.rebuildValidateAsync=function(){n._validateAsync=function(e){return t(function(){var n,t,r,u,l,i,s,a,o,c,f,h,d,y,b,w,w;return v(this,function(v){switch(v.label){case 0:n={};t=true,r=false,u=undefined;v.label=1;case 1:v.trys.push([1,12,13,14]);l=Object.keys(this.asyncValueValidatorBuildersByPropertyName)[Symbol.iterator]();v.label=2;case 2:if(!!(t=(i=l.next()).done))return[3,11];s=i.value;a=this.asyncValueValidatorBuildersByPropertyName[s];o=true,c=false,f=undefined;v.label=3;case 3:v.trys.push([3,8,9,10]);h=a[Symbol.iterator]();v.label=4;case 4:if(!!(o=(d=h.next()).done))return[3,7];y=d.value;return[4,y.build()(e[s],e)];case 5:b=v.sent();p(b)&&(n[s]=b);v.label=6;case 6:o=true;return[3,4];case 7:return[3,10];case 8:w=v.sent();c=true;f=w;return[3,10];case 9:try{if(!o&&h.return!=null){h.return()}}finally{if(c){throw f}}return[7];case 10:t=true;return[3,2];case 11:return[3,14];case 12:w=v.sent();r=true;u=w;return[3,14];case 13:try{if(!t&&l.return!=null){l.return()}}finally{if(r){throw u}}return[7];case 14:return[2,n]}})}).call(n)}};this.ruleFor=function(e){var t=new K(n.rebuildValidateAsync,function(e){return e});return n.asyncValueValidatorBuildersByPropertyName[e]=n.asyncValueValidatorBuildersByPropertyName[e]||[],n.asyncValueValidatorBuildersByPropertyName[e].push(t),t.getAllRules()};this.ruleForTransformed=function(e,t){var r=new K(n.rebuildValidateAsync,t);return n.asyncValueValidatorBuildersByPropertyName[e]=n.asyncValueValidatorBuildersByPropertyName[e]||[],n.asyncValueValidatorBuildersByPropertyName[e].push(r),r.getAllRules()};this.ruleForEach=function(e){var t=new Q(n.rebuildValidateAsync,function(e){return e});return n.asyncValueValidatorBuildersByPropertyName[e]==null&&(n.asyncValueValidatorBuildersByPropertyName[e]=[]),n.asyncValueValidatorBuildersByPropertyName[e].push(t),t.getAllRules()};this.ruleForEachTransformed=function(e,t){var r=new Q(n.rebuildValidateAsync,t);return n.asyncValueValidatorBuildersByPropertyName[e]==null&&(n.asyncValueValidatorBuildersByPropertyName[e]=[]),n.asyncValueValidatorBuildersByPropertyName[e].push(r),r.getAllRules()}};export{X as AsyncValidator,Z as Validator};//# sourceMappingURL=index.mjs.map