fluentvalidation-ts
Version:
A TypeScript-first library for building strongly-typed validation rules
1 lines • 24.6 kB
JavaScript
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 a=e[l](i);var s=a.value}catch(e){t(e);return}if(a.done){n(s)}else{Promise.resolve(s).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 a(e){n(i,u,l,a,s,"next",e)}function s(e){n(i,u,l,a,s,"throw",e)}a(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 a(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 s(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=a(0),i["throw"]=a(1),i["return"]=a(2),typeof Symbol==="function"&&(i[Symbol.iterator]=function(){return this}),i;function a(e){return function(n){return s([e,n])}}function s(a){if(t)throw new TypeError("Generator is already executing.");while(i&&(i=0,a[0]&&(l=0)),l)try{if(t=1,r&&(u=a[0]&2?r["return"]:a[0]?r["throw"]||((u=r["return"])&&u.call(r),0):r.next)&&!(u=u.call(r,a[1])).done)return u;if(r=0,u)a=[a[0]&2,u.value];switch(a[0]){case 0:case 1:u=a;break;case 4:l.label++;return{value:a[1],done:false};case 5:l.label++;r=a[1];a=[0];continue;case 7:a=l.ops.pop();l.trys.pop();continue;default:if(!(u=l.trys,u=u.length>0&&u[u.length-1])&&(a[0]===6||a[0]===2)){l=0;continue}if(a[0]===3&&(!u||a[1]>u[0]&&a[1]<u[3])){l.label=a[1];break}if(a[0]===6&&l.label<u[1]){l.label=u[1];u=a;break}if(u&&l.label<u[2]){l.label=u[2];l.ops.push(a);break}if(u[2])l.ops.pop();l.trys.pop();continue}a=n.call(e,l)}catch(e){a=[6,e];r=0}finally{t=u=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}}var fluentvalidation=function(e){"use strict";var n=function(e){return e==null?false:Array.isArray(e)?e.filter(function(e){return n(e)}).length>0:(typeof e==="undefined"?"undefined":d(e))=="object"?Object.keys(e).length>0:true};var l=function e(){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 i=/*#__PURE__*/function(e){a(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}(l);var o=/^[a-zA-Z0-9.!#$%&’"*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+$/,f=/*#__PURE__*/function(e){a(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 o.test(e)?null:"Not a valid email address"}])}return n}(i);var h=/*#__PURE__*/function(e){a(n,e);function n(e){u(this,n);return r(this,n,[function(n){return n===e?null:"Must equal '".concat(e,"'")}])}return n}(i);var y=function(e){return e.toLocaleString(void 0,{maximumFractionDigits:20})};var p=/*#__PURE__*/function(e){a(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(y(e)," and ").concat(y(t)," (exclusive)")}])}return n}(i);var b=/*#__PURE__*/function(e){a(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(y(e))}])}return n}(i);var w=/*#__PURE__*/function(e){a(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(y(e))}])}return n}(i);var g=/*#__PURE__*/function(e){a(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(y(e)," and ").concat(y(t)," (inclusive)")}])}return n}(i);var m=/*#__PURE__*/function(e){a(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(y(e)," and ").concat(y(t)," characters long")}])}return n}(i);var A=/*#__PURE__*/function(e){a(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(y(e))}])}return n}(i);var _=/*#__PURE__*/function(e){a(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(y(e))}])}return n}(i);var R=/*#__PURE__*/function(e){a(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}(i);var V=/*#__PURE__*/function(e){a(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(y(e)," characters long")}])}return n}(i);var E=/*#__PURE__*/function(e){a(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(y(e)," characters long")}])}return n}(i);var P=/*#__PURE__*/function(e){a(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](),a;!(r=(a=i.next()).done);r=true){var s=a.value;if(typeof s=="function"){if(!s(n,t))return"Value is not valid"}else if(!s.predicate(n,t))return typeof s.message=="function"?s.message(n,t):s.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}(i);var B=/*#__PURE__*/function(e){a(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}(i);var C=/*#__PURE__*/function(e){a(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}(i);var x=/*#__PURE__*/function(e){a(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}(i);var O=/*#__PURE__*/function(e){a(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}(i);var T=/*#__PURE__*/function(e){a(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 U({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}(i),U=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 N=/*#__PURE__*/function(e){a(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}(i);var j=/*#__PURE__*/function(e){a(n,e);function n(){u(this,n);return r(this,n,[function(e){return e===void 0?"Value cannot be undefined":null}])}return n}(i);var S=/*#__PURE__*/function(e){a(n,e);function n(){u(this,n);return r(this,n,[function(e){return e===void 0?null:"Value must be undefined"}])}return n}(i);var q=function e(n,t){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](),a;!(t=(a=i.next()).done);t=true){var s=a.value;s.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](),a;!(t=(a=i.next()).done);t=true){var s=a.value;s.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 C(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.equal=function(e){var n=new h(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.must=function(e){var n=new P(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 x(e);return l.pushRule(n),l.getAllRulesAndExtensions()};this.notUndefined=function(){var e=new j;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 O(e);return l.pushRule(n),l.getAllRulesAndExtensions()};this.undefined=function(){var e=new S;return r.pushRule(e),r.getAllRulesAndExtensions()};this.notEmpty=function(){var e=new B;return r.pushRule(e),r.getAllRulesAndExtensions()};this.length=function(e,n){var t=new m(e,n);return r.pushRule(t),r.getAllRulesAndExtensions()};this.maxLength=function(e){var n=new V(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.minLength=function(e){var n=new E(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.matches=function(e){var n=new R(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.emailAddress=function(){var e=new f;return r.pushRule(e),r.getAllRulesAndExtensions()};this.lessThan=function(e){var n=new _(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.lessThanOrEqualTo=function(e){var n=new A(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.greaterThan=function(e){var n=new w(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.greaterThanOrEqualTo=function(e){var n=new b(e);return r.pushRule(n),r.getAllRulesAndExtensions()};this.exclusiveBetween=function(e,n){var t=new p(e,n);return r.pushRule(t),r.getAllRulesAndExtensions()};this.inclusiveBetween=function(e,n){var t=new g(e,n);return r.pushRule(t),r.getAllRulesAndExtensions()};this.setValidator=function(e){var n=new N(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 T(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 L=/*#__PURE__*/function(e){a(t,e);function t(e,l){u(this,t);var i;i=r(this,t,[e,l]);i.build=function(){return function(e,t){var r=i.transformValue(e);var u=true,l=false,a=undefined;try{for(var s=i.rules[Symbol.iterator](),o;!(u=(o=s.next()).done);u=true){var c=o.value;var f=c.rule.validate(r,t);if(n(f))return f}}catch(e){l=true;a=e}finally{try{if(!u&&s.return!=null){s.return()}}finally{if(l){throw a}}}return null}};i.getAllRules=function(){return i._getAllRules()};i.getAllRulesAndConditionExtensions=function(){return c(s({},i.getAllRules()),{when:i.when,unless:i.unless})};i.getAllRulesAndExtensions=function(){return c(s({},i.getAllRulesAndConditionExtensions()),{withMessage:i.withMessage})};return i}return t}(q);var k=function e(t,r){var l=this;u(this,e);this.build=function(){return function(e,t){if(e==null)return null;var r=l.eachValueValidatorBuilder.build(),u=e.map(function(e){var u=r(e,t);return n(u)?u:null});return n(u)?u:null}};this.getAllRules=function(){return l.eachValueValidatorBuilder.getAllRules()};this.eachValueValidatorBuilder=new L(t,r)};var I=function e(){var t=this;u(this,e);this.valueValidatorBuildersByPropertyName={};this._validate=function(){return{}};this.validate=function(e){return t._validate(e)};this.rebuildValidate=function(){t._validate=function(e){var r={};var u=true,l=false,i=undefined;try{for(var a=Object.keys(t.valueValidatorBuildersByPropertyName)[Symbol.iterator](),s;!(u=(s=a.next()).done);u=true){var o=s.value;var c=t.valueValidatorBuildersByPropertyName[o];var f=true,h=false,d=undefined;try{for(var y=c[Symbol.iterator](),v;!(f=(v=y.next()).done);f=true){var p=v.value;var b=p.build()(e[o],e);n(b)&&(r[o]=b)}}catch(e){h=true;d=e}finally{try{if(!f&&y.return!=null){y.return()}}finally{if(h){throw d}}}}}catch(e){l=true;i=e}finally{try{if(!u&&a.return!=null){a.return()}}finally{if(l){throw i}}}return r}};this.ruleFor=function(e){var n=new L(t.rebuildValidate,function(e){return e});return t.valueValidatorBuildersByPropertyName[e]=t.valueValidatorBuildersByPropertyName[e]||[],t.valueValidatorBuildersByPropertyName[e].push(n),n.getAllRules()};this.ruleForTransformed=function(e,n){var r=new L(t.rebuildValidate,n);return t.valueValidatorBuildersByPropertyName[e]=t.valueValidatorBuildersByPropertyName[e]||[],t.valueValidatorBuildersByPropertyName[e].push(r),r.getAllRules()};this.ruleForEach=function(e){var n=new k(t.rebuildValidate,function(e){return e});return t.valueValidatorBuildersByPropertyName[e]==null&&(t.valueValidatorBuildersByPropertyName[e]=[]),t.valueValidatorBuildersByPropertyName[e].push(n),n.getAllRules()};this.ruleForEachTransformed=function(e,n){var r=new k(t.rebuildValidate,n);return t.valueValidatorBuildersByPropertyName[e]==null&&(t.valueValidatorBuildersByPropertyName[e]=[]),t.valueValidatorBuildersByPropertyName[e].push(r),r.getAllRules()}};var M=/*#__PURE__*/function(e){a(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}(l);var F=/*#__PURE__*/function(e){a(n,e);function n(e){u(this,n);return r(this,n,[function(n,r){return t(function(){var t,u,l,i,a,s,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=(a=i.next()).done))return[3,7];s=a.value;if(!(typeof s=="function"))return[3,4];return[4,s(n,r)];case 3:if(!h.sent())return[2,"Value is not valid"];return[3,6];case 4:return[4,s.predicate(n,r)];case 5:if(!h.sent())return[2,typeof s.message=="function"?s.message(n,r):s.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}(M);var D=/*#__PURE__*/function(e){a(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}(M);var $=/*#__PURE__*/function(e){a(l,e);function l(e,i){u(this,l);var a;var o;a=r(this,l,[e,i]),o=a;o.build=function(){return function(e,r){return t(function(){var t,u,l,i,a,s,c,f,h,d;return v(this,function(y){switch(y.label){case 0:t=o.transformValue(e);u=true,l=false,i=undefined;y.label=1;case 1:y.trys.push([1,8,9,10]);a=o.rules[Symbol.iterator]();y.label=2;case 2:if(!!(u=(s=a.next()).done))return[3,7];c=s.value;if(!c.isAsync)return[3,4];return[4,c.rule.validateAsync(t,r)];case 3:h=y.sent();return[3,5];case 4:h=c.rule.validate(t,r);y.label=5;case 5:f=h;if(n(f))return[2,f];y.label=6;case 6:u=true;return[3,2];case 7:return[3,10];case 8:d=y.sent();l=true;i=d;return[3,10];case 9:try{if(!u&&a.return!=null){a.return()}}finally{if(l){throw i}}return[7];case 10:return[2,null]}})})()}};o.mustAsync=function(e){var n=new F(e);return o.pushAsyncRule(n),o.getAllRulesAndExtensions()};o.setAsyncValidator=function(e){var n=new D(e);return o.pushAsyncRule(n),o.getAllRulesAndExtensions()};o.getAllRules=function(){return c(s({},o._getAllRules()),{mustAsync:o.mustAsync,setAsyncValidator:o.setAsyncValidator})};o.getAllRulesAndConditionExtensions=function(){return c(s({},o.getAllRules()),{when:o.when,unless:o.unless})};o.getAllRulesAndExtensions=function(){return c(s({},o.getAllRulesAndConditionExtensions()),{withMessage:o.withMessage})};return a}return l}(q);var z=function e(r,l){var i=this;u(this,e);this.build=function(){return function(e,r){return t(function(){var t,u,l,i,a,s,o,c,f,h,d;return v(this,function(y){switch(y.label){case 0:if(e==null)return[2,null];t=this.eachAsyncValueValidatorBuilder.build(),u=[];l=true,i=false,a=undefined;y.label=1;case 1:y.trys.push([1,6,7,8]);s=e[Symbol.iterator]();y.label=2;case 2:if(!!(l=(o=s.next()).done))return[3,5];c=o.value;return[4,t(c,r)];case 3:f=y.sent(),h=n(f)?f:null;u.push(h);y.label=4;case 4:l=true;return[3,2];case 5:return[3,8];case 6:d=y.sent();i=true;a=d;return[3,8];case 7:try{if(!l&&s.return!=null){s.return()}}finally{if(i){throw a}}return[7];case 8:return[2,n(u)?u:null]}})}).call(i)}};this.getAllRules=function(){return i.eachAsyncValueValidatorBuilder.getAllRules()};this.eachAsyncValueValidatorBuilder=new $(r,l)};var W=function e(){var r=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 r._validateAsync(e)};this.rebuildValidateAsync=function(){r._validateAsync=function(e){return t(function(){var t,r,u,l,i,a,s,o,c,f,h,d,y,p,b,w,w;return v(this,function(v){switch(v.label){case 0:t={};r=true,u=false,l=undefined;v.label=1;case 1:v.trys.push([1,12,13,14]);i=Object.keys(this.asyncValueValidatorBuildersByPropertyName)[Symbol.iterator]();v.label=2;case 2:if(!!(r=(a=i.next()).done))return[3,11];s=a.value;o=this.asyncValueValidatorBuildersByPropertyName[s];c=true,f=false,h=undefined;v.label=3;case 3:v.trys.push([3,8,9,10]);d=o[Symbol.iterator]();v.label=4;case 4:if(!!(c=(y=d.next()).done))return[3,7];p=y.value;return[4,p.build()(e[s],e)];case 5:b=v.sent();n(b)&&(t[s]=b);v.label=6;case 6:c=true;return[3,4];case 7:return[3,10];case 8:w=v.sent();f=true;h=w;return[3,10];case 9:try{if(!c&&d.return!=null){d.return()}}finally{if(f){throw h}}return[7];case 10:r=true;return[3,2];case 11:return[3,14];case 12:w=v.sent();u=true;l=w;return[3,14];case 13:try{if(!r&&i.return!=null){i.return()}}finally{if(u){throw l}}return[7];case 14:return[2,t]}})}).call(r)}};this.ruleFor=function(e){var n=new $(r.rebuildValidateAsync,function(e){return e});return r.asyncValueValidatorBuildersByPropertyName[e]=r.asyncValueValidatorBuildersByPropertyName[e]||[],r.asyncValueValidatorBuildersByPropertyName[e].push(n),n.getAllRules()};this.ruleForTransformed=function(e,n){var t=new $(r.rebuildValidateAsync,n);return r.asyncValueValidatorBuildersByPropertyName[e]=r.asyncValueValidatorBuildersByPropertyName[e]||[],r.asyncValueValidatorBuildersByPropertyName[e].push(t),t.getAllRules()};this.ruleForEach=function(e){var n=new z(r.rebuildValidateAsync,function(e){return e});return r.asyncValueValidatorBuildersByPropertyName[e]==null&&(r.asyncValueValidatorBuildersByPropertyName[e]=[]),r.asyncValueValidatorBuildersByPropertyName[e].push(n),n.getAllRules()};this.ruleForEachTransformed=function(e,n){var t=new z(r.rebuildValidateAsync,n);return r.asyncValueValidatorBuildersByPropertyName[e]==null&&(r.asyncValueValidatorBuildersByPropertyName[e]=[]),r.asyncValueValidatorBuildersByPropertyName[e].push(t),t.getAllRules()}};e.AsyncValidator=W;e.Validator=I;return e}({});//# sourceMappingURL=index.global.js.map