UNPKG

@cowwoc/requirements

Version:

A fluent API for enforcing design contracts with automatic message generation.

1 lines 111 kB
var TypeCategory;!function(e){e[e.UNDEFINED=0]="UNDEFINED",e[e.NULL=1]="NULL",e[e.BOOLEAN=2]="BOOLEAN",e[e.NUMBER=3]="NUMBER",e[e.BIGINT=4]="BIGINT",e[e.STRING=5]="STRING",e[e.SYMBOL=6]="SYMBOL",e[e.ARRAY=7]="ARRAY",e[e.FUNCTION=8]="FUNCTION",e[e.CLASS=9]="CLASS"}(TypeCategory||(TypeCategory={}));const FUNCTION_NAME_REGEX=/^function\s+([^(]+)?\(/,CLASS_NAME_REGEX=/^class\s+([^{\s]+)?.*?{/,BUILT_IN_CLASS_NAME_REGEX=/^function\s+([^(]+)?\(\) { \[native code] }/,STARTS_WITH_VOWEL_REGEX=/^[aeiouAEIOU]/;class Type{static UNDEFINED=new Type(TypeCategory.UNDEFINED);static NULL=new Type(TypeCategory.NULL);static BOOLEAN=new Type(TypeCategory.BOOLEAN);static NUMBER=new Type(TypeCategory.NUMBER);static BIGINT=new Type(TypeCategory.BIGINT);static STRING=new Type(TypeCategory.STRING);static SYMBOL=new Type(TypeCategory.SYMBOL);static ARRAY=new Type(TypeCategory.ARRAY);static ANONYMOUS_FUNCTION=new Type(TypeCategory.FUNCTION);category;name;typeGuard;static of(e){const t=Type.getPrimitive(e);if(null!==t)return t;if(Array.isArray(e))return Type.ARRAY;const r=e;if("Function"===Object.prototype.toString.call(e).slice(8,-1)){const e=r.toString(),t=e.indexOf("=>"),i=e.indexOf("{");if(-1!==t&&(-1===i||t<i))return Type.ANONYMOUS_FUNCTION;const n=CLASS_NAME_REGEX.exec(e);if(null!==n&&n.length>=2){const e=n[1];return Type.namedClass(e)}const a=BUILT_IN_CLASS_NAME_REGEX.exec(e);if(null!==a&&a.length>=2){const e=a[1].trim();return Type.namedClass(e)}const s=FUNCTION_NAME_REGEX.exec(e);if(null!==s&&s.length>=2){const e=s[1].trim();return Type.namedFunction(e)}return Type.ANONYMOUS_FUNCTION}return Type.namedClass(r.constructor.name)}static namedClass(e,t){return new Type(TypeCategory.CLASS,e,t)}static namedFunction(e){return new Type(TypeCategory.FUNCTION,e)}static getPrimitive(e){if(void 0===e)return Type.UNDEFINED;if(null===e)return Type.NULL;switch(typeof e){case"boolean":return Type.BOOLEAN;case"number":return Type.NUMBER;case"bigint":return Type.BIGINT;case"string":return Type.STRING;case"symbol":return Type.SYMBOL}return null}constructor(e,t=null,r){if(!Object.values(TypeCategory).includes(e))throw new RangeError(`category must be an instance of TypeCategory.\nActual: ${Type.of(e).toString()}`);this.category=e,this.name=t,this.typeGuard=r}isPrimitive(){switch(this.category){case TypeCategory.UNDEFINED:case TypeCategory.NULL:case TypeCategory.BOOLEAN:case TypeCategory.NUMBER:case TypeCategory.BIGINT:case TypeCategory.STRING:case TypeCategory.SYMBOL:return!0;default:return!1}}equals(e){return e.category===this.category&&(e.name===this.name||null===this.name||null===e.name)}getTypeOf(){switch(this.category){case TypeCategory.UNDEFINED:case TypeCategory.NULL:case TypeCategory.BOOLEAN:case TypeCategory.NUMBER:case TypeCategory.BIGINT:case TypeCategory.STRING:case TypeCategory.SYMBOL:case TypeCategory.ARRAY:case TypeCategory.FUNCTION:return this;case TypeCategory.CLASS:return Type.namedClass(this.name)}}isSubtypeOf(e){switch(this.category){case TypeCategory.UNDEFINED:case TypeCategory.NULL:return!1;case TypeCategory.BOOLEAN:case TypeCategory.NUMBER:case TypeCategory.BIGINT:case TypeCategory.STRING:case TypeCategory.SYMBOL:case TypeCategory.ARRAY:case TypeCategory.FUNCTION:return this.equals(e);case TypeCategory.CLASS:{if(e===Type.UNDEFINED||e===Type.NULL)return!1;if(null===e.name)return!0;const t=globalThis[e.name];if(null==this.name)return!0;return globalThis[this.name].prototype instanceof t}}}toString(){switch(this.category){case TypeCategory.UNDEFINED:return"undefined";case TypeCategory.NULL:return"null";case TypeCategory.BOOLEAN:return"a boolean";case TypeCategory.NUMBER:return"a number";case TypeCategory.BIGINT:return"a bigint";case TypeCategory.STRING:return"a string";case TypeCategory.SYMBOL:return"a symbol";case TypeCategory.ARRAY:return"an array";case TypeCategory.FUNCTION:return null===this.name?"a function":`a function named ${this.name}`;case TypeCategory.CLASS:return null===this.name?"an object":STARTS_WITH_VOWEL_REGEX.test(this.name)?`an ${this.name}`:`a ${this.name}`}}}var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var hasRequiredLodash_isequal,lodash_isequal={exports:{}};function requireLodash_isequal(){return hasRequiredLodash_isequal||(hasRequiredLodash_isequal=1,function(e,t){var r="__lodash_hash_undefined__",i=9007199254740991,n="[object Arguments]",a="[object Array]",s="[object Boolean]",o="[object Date]",l="[object Error]",u="[object Function]",h="[object Map]",c="[object Number]",d="[object Object]",f="[object Promise]",p="[object RegExp]",g="[object Set]",m="[object String]",T="[object Symbol]",y="[object WeakMap]",v="[object ArrayBuffer]",N="[object DataView]",E=/^\[object .+?Constructor\]$/,S=/^(?:0|[1-9]\d*)$/,O={};O["[object Float32Array]"]=O["[object Float64Array]"]=O["[object Int8Array]"]=O["[object Int16Array]"]=O["[object Int32Array]"]=O["[object Uint8Array]"]=O["[object Uint8ClampedArray]"]=O["[object Uint16Array]"]=O["[object Uint32Array]"]=!0,O[n]=O[a]=O[v]=O[s]=O[N]=O[o]=O[l]=O[u]=O[h]=O[c]=O[d]=O[p]=O[g]=O[m]=O[y]=!1;var b="object"==typeof commonjsGlobal&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,w="object"==typeof self&&self&&self.Object===Object&&self,I=b||w||Function("return this")(),C=t&&!t.nodeType&&t,A=C&&e&&!e.nodeType&&e,x=A&&A.exports===C,L=x&&b.process,D=function(){try{return L&&L.binding&&L.binding("util")}catch(e){}}(),_=D&&D.isTypedArray;function M(e,t){for(var r=-1,i=null==e?0:e.length;++r<i;)if(t(e[r],r,e))return!0;return!1}function V(e){var t=-1,r=Array(e.size);return e.forEach((function(e,i){r[++t]=[i,e]})),r}function R(e){var t=-1,r=Array(e.size);return e.forEach((function(e){r[++t]=e})),r}var q,F,U,B=Array.prototype,$=Function.prototype,k=Object.prototype,j=I["__core-js_shared__"],G=$.toString,P=k.hasOwnProperty,z=(q=/[^.]+$/.exec(j&&j.keys&&j.keys.IE_PROTO||""))?"Symbol(src)_1."+q:"",W=k.toString,Y=RegExp("^"+G.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),J=x?I.Buffer:void 0,Z=I.Symbol,K=I.Uint8Array,Q=k.propertyIsEnumerable,X=B.splice,H=Z?Z.toStringTag:void 0,ee=Object.getOwnPropertySymbols,te=J?J.isBuffer:void 0,re=(F=Object.keys,U=Object,function(e){return F(U(e))}),ie=De(I,"DataView"),ne=De(I,"Map"),ae=De(I,"Promise"),se=De(I,"Set"),oe=De(I,"WeakMap"),le=De(Object,"create"),ue=Re(ie),he=Re(ne),ce=Re(ae),de=Re(se),fe=Re(oe),pe=Z?Z.prototype:void 0,ge=pe?pe.valueOf:void 0;function me(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}function Te(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}function ye(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}function ve(e){var t=-1,r=null==e?0:e.length;for(this.__data__=new ye;++t<r;)this.add(e[t])}function Ne(e){var t=this.__data__=new Te(e);this.size=t.size}function Ee(e,t){var r=Ue(e),i=!r&&Fe(e),n=!r&&!i&&Be(e),a=!r&&!i&&!n&&Pe(e),s=r||i||n||a,o=s?function(e,t){for(var r=-1,i=Array(e);++r<e;)i[r]=t(r);return i}(e.length,String):[],l=o.length;for(var u in e)!P.call(e,u)||s&&("length"==u||n&&("offset"==u||"parent"==u)||a&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||Ve(u,l))||o.push(u);return o}function Se(e,t){for(var r=e.length;r--;)if(qe(e[r][0],t))return r;return-1}function Oe(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":H&&H in Object(e)?function(e){var t=P.call(e,H),r=e[H];try{e[H]=void 0;var i=!0}catch(e){}var n=W.call(e);i&&(t?e[H]=r:delete e[H]);return n}(e):function(e){return W.call(e)}(e)}function be(e){return Ge(e)&&Oe(e)==n}function we(e,t,r,i,u){return e===t||(null==e||null==t||!Ge(e)&&!Ge(t)?e!=e&&t!=t:function(e,t,r,i,u,f){var y=Ue(e),E=Ue(t),S=y?a:Me(e),O=E?a:Me(t),b=(S=S==n?d:S)==d,w=(O=O==n?d:O)==d,I=S==O;if(I&&Be(e)){if(!Be(t))return!1;y=!0,b=!1}if(I&&!b)return f||(f=new Ne),y||Pe(e)?Ae(e,t,r,i,u,f):function(e,t,r,i,n,a,u){switch(r){case N:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case v:return!(e.byteLength!=t.byteLength||!a(new K(e),new K(t)));case s:case o:case c:return qe(+e,+t);case l:return e.name==t.name&&e.message==t.message;case p:case m:return e==t+"";case h:var d=V;case g:var f=1&i;if(d||(d=R),e.size!=t.size&&!f)return!1;var y=u.get(e);if(y)return y==t;i|=2,u.set(e,t);var E=Ae(d(e),d(t),i,n,a,u);return u.delete(e),E;case T:if(ge)return ge.call(e)==ge.call(t)}return!1}(e,t,S,r,i,u,f);if(!(1&r)){var C=b&&P.call(e,"__wrapped__"),A=w&&P.call(t,"__wrapped__");if(C||A){var x=C?e.value():e,L=A?t.value():t;return f||(f=new Ne),u(x,L,r,i,f)}}if(!I)return!1;return f||(f=new Ne),function(e,t,r,i,n,a){var s=1&r,o=xe(e),l=o.length,u=xe(t),h=u.length;if(l!=h&&!s)return!1;var c=l;for(;c--;){var d=o[c];if(!(s?d in t:P.call(t,d)))return!1}var f=a.get(e);if(f&&a.get(t))return f==t;var p=!0;a.set(e,t),a.set(t,e);var g=s;for(;++c<l;){var m=e[d=o[c]],T=t[d];if(i)var y=s?i(T,m,d,t,e,a):i(m,T,d,e,t,a);if(!(void 0===y?m===T||n(m,T,r,i,a):y)){p=!1;break}g||(g="constructor"==d)}if(p&&!g){var v=e.constructor,N=t.constructor;v==N||!("constructor"in e)||!("constructor"in t)||"function"==typeof v&&v instanceof v&&"function"==typeof N&&N instanceof N||(p=!1)}return a.delete(e),a.delete(t),p}(e,t,r,i,u,f)}(e,t,r,i,we,u))}function Ie(e){return!(!je(e)||function(e){return!!z&&z in e}(e))&&($e(e)?Y:E).test(Re(e))}function Ce(e){if(!function(e){var t=e&&e.constructor,r="function"==typeof t&&t.prototype||k;return e===r}(e))return re(e);var t=[];for(var r in Object(e))P.call(e,r)&&"constructor"!=r&&t.push(r);return t}function Ae(e,t,r,i,n,a){var s=1&r,o=e.length,l=t.length;if(o!=l&&!(s&&l>o))return!1;var u=a.get(e);if(u&&a.get(t))return u==t;var h=-1,c=!0,d=2&r?new ve:void 0;for(a.set(e,t),a.set(t,e);++h<o;){var f=e[h],p=t[h];if(i)var g=s?i(p,f,h,t,e,a):i(f,p,h,e,t,a);if(void 0!==g){if(g)continue;c=!1;break}if(d){if(!M(t,(function(e,t){if(s=t,!d.has(s)&&(f===e||n(f,e,r,i,a)))return d.push(t);var s}))){c=!1;break}}else if(f!==p&&!n(f,p,r,i,a)){c=!1;break}}return a.delete(e),a.delete(t),c}function xe(e){return function(e,t,r){var i=t(e);return Ue(e)?i:function(e,t){for(var r=-1,i=t.length,n=e.length;++r<i;)e[n+r]=t[r];return e}(i,r(e))}(e,ze,_e)}function Le(e,t){var r,i,n=e.__data__;return("string"==(i=typeof(r=t))||"number"==i||"symbol"==i||"boolean"==i?"__proto__"!==r:null===r)?n["string"==typeof t?"string":"hash"]:n.map}function De(e,t){var r=function(e,t){return null==e?void 0:e[t]}(e,t);return Ie(r)?r:void 0}me.prototype.clear=function(){this.__data__=le?le(null):{},this.size=0},me.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},me.prototype.get=function(e){var t=this.__data__;if(le){var i=t[e];return i===r?void 0:i}return P.call(t,e)?t[e]:void 0},me.prototype.has=function(e){var t=this.__data__;return le?void 0!==t[e]:P.call(t,e)},me.prototype.set=function(e,t){var i=this.__data__;return this.size+=this.has(e)?0:1,i[e]=le&&void 0===t?r:t,this},Te.prototype.clear=function(){this.__data__=[],this.size=0},Te.prototype.delete=function(e){var t=this.__data__,r=Se(t,e);return!(r<0)&&(r==t.length-1?t.pop():X.call(t,r,1),--this.size,!0)},Te.prototype.get=function(e){var t=this.__data__,r=Se(t,e);return r<0?void 0:t[r][1]},Te.prototype.has=function(e){return Se(this.__data__,e)>-1},Te.prototype.set=function(e,t){var r=this.__data__,i=Se(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this},ye.prototype.clear=function(){this.size=0,this.__data__={hash:new me,map:new(ne||Te),string:new me}},ye.prototype.delete=function(e){var t=Le(this,e).delete(e);return this.size-=t?1:0,t},ye.prototype.get=function(e){return Le(this,e).get(e)},ye.prototype.has=function(e){return Le(this,e).has(e)},ye.prototype.set=function(e,t){var r=Le(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this},ve.prototype.add=ve.prototype.push=function(e){return this.__data__.set(e,r),this},ve.prototype.has=function(e){return this.__data__.has(e)},Ne.prototype.clear=function(){this.__data__=new Te,this.size=0},Ne.prototype.delete=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r},Ne.prototype.get=function(e){return this.__data__.get(e)},Ne.prototype.has=function(e){return this.__data__.has(e)},Ne.prototype.set=function(e,t){var r=this.__data__;if(r instanceof Te){var i=r.__data__;if(!ne||i.length<199)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new ye(i)}return r.set(e,t),this.size=r.size,this};var _e=ee?function(e){return null==e?[]:(e=Object(e),function(e,t){for(var r=-1,i=null==e?0:e.length,n=0,a=[];++r<i;){var s=e[r];t(s,r,e)&&(a[n++]=s)}return a}(ee(e),(function(t){return Q.call(e,t)})))}:function(){return[]},Me=Oe;function Ve(e,t){return!!(t=t??i)&&("number"==typeof e||S.test(e))&&e>-1&&e%1==0&&e<t}function Re(e){if(null!=e){try{return G.call(e)}catch(e){}try{return e+""}catch(e){}}return""}function qe(e,t){return e===t||e!=e&&t!=t}(ie&&Me(new ie(new ArrayBuffer(1)))!=N||ne&&Me(new ne)!=h||ae&&Me(ae.resolve())!=f||se&&Me(new se)!=g||oe&&Me(new oe)!=y)&&(Me=function(e){var t=Oe(e),r=t==d?e.constructor:void 0,i=r?Re(r):"";if(i)switch(i){case ue:return N;case he:return h;case ce:return f;case de:return g;case fe:return y}return t});var Fe=be(function(){return arguments}())?be:function(e){return Ge(e)&&P.call(e,"callee")&&!Q.call(e,"callee")},Ue=Array.isArray;var Be=te||function(){return!1};function $e(e){if(!je(e))return!1;var t=Oe(e);return t==u||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}function ke(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=i}function je(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function Ge(e){return null!=e&&"object"==typeof e}var Pe=_?function(e){return function(t){return e(t)}}(_):function(e){return Ge(e)&&ke(e.length)&&!!O[Oe(e)]};function ze(e){return null!=(t=e)&&ke(t.length)&&!$e(t)?Ee(e):Ce(e);var t}e.exports=function(e,t){return we(e,t)}}(lodash_isequal,lodash_isequal.exports)),lodash_isequal.exports}lodash_isequal.exports;var lodash_isequalExports=requireLodash_isequal(),isEqual=getDefaultExportFromCjs(lodash_isequalExports);function assert(e,t=e=>new AssertionError(e),r){if(!e)throw t(r)}function requireThatValueIsDefined(e,t){const r=Type.of(t);if(r!==Type.STRING)throw new TypeError(`name must be a string.\nActual: ${internalValueToString(t)}\nType : ${internalValueToString(r)}`);if(void 0===e)throw new TypeError(t+" must be defined");return!0}function requireThatValueIsNotNull(e,t){if(requireThatValueIsDefined(e,t),null===e)throw new TypeError(t+" may not be null");return!0}function assertThatValueIsNotNull(e,t){try{assert(requireThatValueIsNotNull(e,t))}catch(e){if(e instanceof Error){const t=new AssertionError(e.message);throw t.stack=e.stack?.replace(e.name,t.name),t}throw e}}function requireThatType(e,t,r){const i=Type.of(t);if(i!==Type.STRING)throw new TypeError(`name must be a string.\nActual: ${internalValueToString(t)}\nType : ${i.toString()}`);const n=Type.of(e);let a;if(a=void 0!==r.typeGuard?r.typeGuard(e):isEqual(n,r),!a)throw new TypeError(`${t} must be a ${internalValueToString(r)}.\nActual: ${internalValueToString(e)}\nType : ${n.toString()}`);return!0}function assertThatType(e,t,r){try{assert(requireThatType(e,t,r))}catch(e){if(e instanceof Error){const t=new AssertionError(e.message);throw t.stack=e.stack?.replace(e.name,t.name),t}throw e}}function requireThatTypeCategory(e,t,r,i){const n=Type.of(t);if(n!==Type.STRING)throw new TypeError(`name must be a string.\nActual: ${internalValueToString(t)}\nType : ${n.toString()}`);const a=Type.of(e).category;let s;if(s=void 0!==i?i(e):isEqual(a,r),!s)throw new TypeError(`${t} must be a ${TypeCategory[r]}.\nActual : ${internalValueToString(e)}\nTypeCategory: ${TypeCategory[a]}`);return!0}function requireThatInstanceOf(e,t,r){const i=Type.of(t);if(i!==Type.STRING)throw new TypeError(`name must be a string.\nActual : ${internalValueToString(t)}\nActual.type: ${i.toString()}`);const n=Type.of(r);switch(n.category){case TypeCategory.CLASS:if(!(e instanceof r)){const r=Type.of(e);throw new TypeError(`${t} must be ${n.toString()}.\nActual: ${r.toString()}`)}break;case TypeCategory.NUMBER:case TypeCategory.STRING:if(!Object.values(r).includes(e))throw new TypeError(`${t} must be ${n.toString()}.\nActual: ${internalValueToString(r)}\nType : ${n.toString()}`);break;default:throw new TypeError(`type must be a class or enum.\nActual: ${internalValueToString(n)}`)}return!0}function assertThatInstanceOf(e,t,r){try{assert(requireThatInstanceOf(e,t,r))}catch(e){if(e instanceof Error){const t=new AssertionError(e.message);throw t.stack=e.stack?.replace(e.name,t.name),t}throw e}}function requireThatStringIsNotEmpty(e,t){if(requireThatType(t,"name",Type.STRING),0===(t=t.trim()).length)throw new RangeError("name may not be empty");if(requireThatType(e,"value",Type.STRING),0===(e=e.trim()).length)throw new RangeError(`${t} may not be empty`);return!0}function assertThatStringIsNotEmpty(e,t){try{assert(requireThatStringIsNotEmpty(e,t))}catch(e){if(e instanceof Error){const t=new AssertionError(e.message);throw t.stack=e.stack?.replace(e.name,t.name),t}throw e}}function internalValueToString(e){let t=Type.of(e);switch(t.category){case TypeCategory.CLASS:switch(t.name){case"Set":{const t=e;return arrayToString(Array.from(t.values()))}case"Map":{const t={},r=e;for(const e of r.entries()){t[internalValueToString(e[0])]=e[1]}return JSON.stringify(t,null,2)}}break;case TypeCategory.UNDEFINED:return"undefined";case TypeCategory.NULL:return"null";case TypeCategory.STRING:return quoteString(e);default:return JSON.stringify(e,void 0,2)}let r=e;for(;;){if(Object.prototype.hasOwnProperty.call(r.constructor.prototype,"toString"))return r.toString();const i=getSuperclass(r);let n;if(null===i?n="Object":(r=i,t=Type.of(r),assert(t.category===TypeCategory.CLASS,void 0,`expected: CLASS\nactual: ${t.toString()}`),n=t.name),"Object"===n)return JSON.stringify(e,null,2)}}function quoteString(e){let t="";for(let r=0;r<e.length;++r){const i=e.charAt(r);t+='"'==i?'\\"':i}return t='"'+t,t+='"',t.toString()}function getSuperclass(e){return Object.getPrototypeOf(e.constructor.prototype)}function arrayToString(e){let t="[";const r=e.length;for(let i=0;i<r;++i)t+=internalValueToString(e[i]),i<r-1&&(t+=", ");return t+="]",t}function verifyName(e,t){requireThatType(t,"name",Type.STRING),requireThatType(e,"value",Type.STRING);const r=e.trim();if(e.length!==r.length)throw new RangeError(`${t} may not contain leading or trailing whitespace.\nActual: "${t}"`);if(0===r.length)throw new RangeError(`${t} may not be empty`)}function isErrorBuilder(e){return"function"==typeof e&&1===e.length}class AbstractValidator{static VALUE_IS_UNDEFINED=()=>new IllegalStateError("value is invalid");static CONTAINS_WHITESPACE=/.*\\s.*/u;scope;_configuration;name;value;context;failures;constructor(e,t,r,i,n,a){if(assertThatType(e,"scope",Type.namedClass("ApplicationScope",(()=>isApplicationScope(e)))),assertThatInstanceOf(t,"configuration",Configuration),requireThatStringIsNotEmpty(r,"name"),AbstractValidator.CONTAINS_WHITESPACE.test(r))throw new RangeError('name may not contain whitespace.\nactual: "'+r+'"');assertThatValueIsNotNull(i,"value"),assertThatValueIsNotNull(n,"context"),assertThatValueIsNotNull(a,"failures"),this.scope=e,this._configuration=t,this.name=r,this.value=i,this.context=n,this.failures=a}getScope(){return this.scope}getName(){return this.name}validationFailed(){return 0!==this.failures.length}getValue(){return this.value.orThrow(ObjectSizeValidatorImpl.VALUE_IS_UNDEFINED)}getValueOrDefault(e){return this.value.or(e)}and(e){return e(this),this}addFailure(e,t){const r=new ValidationFailureImpl(this._configuration,e,t);if(this.failures.push(r),this._configuration.throwOnFailure())throw r.getError()}addTypeError(e){this.addFailure(e,(e=>new TypeError(e)))}addRangeError(e){this.addFailure(e,(e=>new RangeError(e)))}configuration(){return this._configuration}elseGetFailures(){return new ValidationFailures(this.failures)}elseThrow(){const e=this.elseGetError();if(null===e)return!0;throw e}elseGetError(){return 0===this.failures.length?null:1===this.failures.length?this.failures[0].getError():new MultipleFailuresError(this.failures)}getContext(){return new Map(this.context)}withContext(e,t){return this.requireThatNameIsUnique(t,!1),null===e?this.context.delete(t):this.context.set(t,e),this}getContextAsString(){return new MessageBuilder(this,"").toString()}requireThatNameIsUnique(e,t=!0){const r=JavascriptValidatorsImpl.INTERNAL;if(r.requireThatString(e,"name").isTrimmed().isNotEmpty(),AbstractValidator.CONTAINS_WHITESPACE.test(e))throw new RangeError("name may not contain whitespace");if(e===this.name)throw new RangeError(`The name "${e}" is already in use by the value being validated.\nChoose a different name.`);if(t&&this.context.has(e))throw new RangeError(`The name "${e}" is already in use by the validator context. Choose a different name.`);return r}isUndefined(){return this.value.isUndefined()||this.addTypeError(messagesIsUndefined(this).toString()),this}isNotUndefined(){return this.value.isUndefined()&&this.addTypeError(messagesIsUndefined(this).toString()),this}isNull(){return this.value.isNull()||this.addTypeError(messagesIsNull(this).toString()),this}isNotNull(){return this.value.isNull()&&this.addTypeError(messagesIsNotNull(this).toString()),this}validateType(e,t){return!this.value.map((r=>{const i=Type.of(r);return void 0!==e.typeGuard?e.typeGuard(r):isEqual(i,e)!==t})).or(!0)||(this.addTypeError(messagesIsInstanceOf(this,e).toString()),!1)}isType(e){return JavascriptValidatorsImpl.INTERNAL.requireThat(e,"expected").isNotNull(),this.value.map((t=>!Type.of(t).equals(e))).or(!0)&&this.addTypeError(messagesIsInstanceOf(this,e).toString()),this}isInstanceOf(e){JavascriptValidatorsImpl.INTERNAL.requireThat(e,"expected").isNotNull();const t=Type.of(e).name;return this.validateType(Type.namedClass(t),!0),this}isNotInstanceOf(e){JavascriptValidatorsImpl.INTERNAL.requireThat(e,"expected").isNotNull();const t=Type.of(e).name;return this.validateType(Type.namedClass(t),!1),this}isEqualTo(e,t){return void 0!==t&&this.requireThatNameIsUnique(t),this.value.map((t=>!isEqual(t,e))).or(!0)&&this.addRangeError(messagesIsEqualTo(this,t??null,e).toString()),this}isNotEqualTo(e,t){return void 0!==t&&this.requireThatNameIsUnique(t),this.value.map((t=>isEqual(t,e))).or(!0)&&this.addRangeError(messagesIsNotEqualTo(this,t??null,e).toString()),this}getNameOrValue(e,t,r,i){return null===t?r+this.configuration().stringMappers().toString(i):e+MessageBuilder.quoteName(t)}failOnUndefinedOrNull(){this.value.ifValid((e=>{void 0===e?this.addRangeError(messagesIsNotUndefined(this).toString()):null===e&&this.addRangeError(messagesIsNotNull(this).toString())}))}}class AbstractCollectionValidator extends AbstractValidator{pluralizer;constructor(e,t,r,i,n,a,s){super(e,t,r,i,a,s),requireThatValueIsNotNull(n,"pluralizer"),this.pluralizer=n}isEmpty(){return this.value.validationFailed((e=>0===this.getLength(e)))&&(this.failOnUndefinedOrNull(),this.addRangeError(objectIsEmpty(this).toString())),this}getLength(e){return this.collectionAsArray(e).length}collectionAsArray(e){return Array.isArray(e)?e:(assertThatType(e,"value",Type.namedClass("Set")),Array.from(e))}collectionAsSet(e){return e instanceof Set?e:(assertThatType(e,"value",Type.ARRAY),new Set(e))}isNotEmpty(){return this.value.validationFailed((e=>0!==this.getLength(e)))&&(this.failOnUndefinedOrNull(),this.addRangeError(objectIsNotEmpty(this).toString())),this}contains(e,t){return void 0!==t&&this.requireThatNameIsUnique(t),this.value.validationFailed((t=>this.collectionContainsElement(t,e)))&&(this.failOnUndefinedOrNull(),this.addRangeError(collectionContains(this,t??null,e).toString())),this}collectionContainsElement(e,t){const r=this.collectionAsArray(e);for(let e=0;e<r.length;++e)if(isEqual(r[e],t))return!0;return!1}doesNotContain(e,t){return void 0!==t&&this.requireThatNameIsUnique(t),this.value.validationFailed((t=>!this.collectionContainsElement(t,e)))&&(this.failOnUndefinedOrNull(),this.addRangeError(collectionDoesNotContain(this,t??null,e).toString())),this}containsExactly(e,t){void 0!==t&&this.requireThatNameIsUnique(t);const r=this.value.undefinedOrNullToInvalid().map((t=>Difference.actualVsOther(t,e))).or(null);return null!==r&&r.areTheSame()||(this.failOnUndefinedOrNull(),this.addRangeError(collectionContainsExactly(this,r,t??null,e,this.pluralizer).toString())),this}doesNotContainExactly(e,t){void 0!==t&&this.requireThatNameIsUnique(t);const r=this.value.undefinedOrNullToInvalid().map((t=>Difference.actualVsOther(t,e))).or(null);return null!==r&&r.areDifferent()||(this.failOnUndefinedOrNull(),this.addRangeError(collectionDoesNotContainExactly(this,t??null,e,this.pluralizer).toString())),this}containsAny(e,t){return void 0!==t&&this.requireThatNameIsUnique(t),this.value.validationFailed((t=>!this.isDisjoint(this.collectionAsSet(t),this.collectionAsSet(e))))&&(this.failOnUndefinedOrNull(),this.addRangeError(collectionContainsAny(this,t??null,e,this.pluralizer).toString())),this}isDisjoint(e,t){for(const r of e)if(t.has(r))return!1;return!0}doesNotContainAny(e,t){void 0!==t&&this.requireThatNameIsUnique(t);const r=this.value.undefinedOrNullToInvalid().map((t=>Difference.actualVsOther(t,e))).or(null);return null!==r&&0===r.common.size||(this.failOnUndefinedOrNull(),this.addRangeError(collectionDoesNotContainAny(this,r,t??null,e,this.pluralizer).toString())),this}containsAll(e,t){void 0!==t&&this.requireThatNameIsUnique(t);const r=this.value.undefinedOrNullToInvalid().map((t=>Difference.actualVsOther(t,e))).or(null);return null!==r&&0===r.onlyInOther.size||(this.failOnUndefinedOrNull(),this.addRangeError(collectionContainsAll(this,r,t??null,e,this.pluralizer).toString())),this}doesNotContainAll(e,t){return void 0!==t&&this.requireThatNameIsUnique(t),this.value.validationFailed((t=>!this.collectionContainsAll(t,e)))&&(this.failOnUndefinedOrNull(),this.addRangeError(collectionDoesNotContainAll(this,t??null,e,this.pluralizer).toString())),this}collectionContainsAll(e,t){for(const r of this.collectionAsArray(t))if(!this.collectionContainsElement(e,r))return!1;return!0}doesNotContainDuplicates(){const e=this.value.undefinedOrNullToInvalid().map((e=>this.getDuplicates(this.collectionAsArray(e))));return e.validationFailed((e=>0===e.size))&&(this.failOnUndefinedOrNull(),this.addRangeError(collectionDoesNotContainDuplicates(this,e.or(null),this.pluralizer).toString())),this}getDuplicates(e){const t=new Set,r=new Set;for(let i=0;i<e.length;++i){const n=e[i];t.has(n)?r.add(n):t.add(n)}return r}length(){return this.failOnUndefinedOrNull(),new ObjectSizeValidatorImpl(this.scope,this._configuration,this,this.name+".length()",this.value.undefinedOrNullToInvalid().map((e=>this.getLength(e))),this.pluralizer,this.context,this.failures)}}class ArrayValidatorImpl extends AbstractCollectionValidator{constructor(e,t,r,i,n,a,s){super(e,t,r,i,n,a,s)}isSorted(e){const t=this.value.undefinedOrNullToInvalid().map((t=>{const r=this.collectionAsArray(t),i=[...r];return i.sort(e),isEqual(r,i)?null:i})).or(null);return null!==t&&(this.failOnUndefinedOrNull(),this.addRangeError(collectionIsSorted(this,t).toString())),this}size(){return this.failOnUndefinedOrNull(),new ObjectSizeValidatorImpl(this.scope,this._configuration,this,this.name+".size()",this.value.undefinedOrNullToInvalid().map((e=>e.length)),this.pluralizer,this.context,this.failures)}}const ANSI_BACKGROUND_OFFSET=10,wrapAnsi16=(e=0)=>t=>`[${t+e}m`,wrapAnsi256=(e=0)=>t=>`[${38+e};5;${t}m`,wrapAnsi16m=(e=0)=>(t,r,i)=>`[${38+e};2;${t};${r};${i}m`,styles$1={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};Object.keys(styles$1.modifier);const foregroundColorNames=Object.keys(styles$1.color),backgroundColorNames=Object.keys(styles$1.bgColor);function assembleStyles(){const e=new Map;for(const[t,r]of Object.entries(styles$1)){for(const[t,i]of Object.entries(r))styles$1[t]={open:`[${i[0]}m`,close:`[${i[1]}m`},r[t]=styles$1[t],e.set(i[0],i[1]);Object.defineProperty(styles$1,t,{value:r,enumerable:!1})}return Object.defineProperty(styles$1,"codes",{value:e,enumerable:!1}),styles$1.color.close="",styles$1.bgColor.close="",styles$1.color.ansi=wrapAnsi16(),styles$1.color.ansi256=wrapAnsi256(),styles$1.color.ansi16m=wrapAnsi16m(),styles$1.bgColor.ansi=wrapAnsi16(10),styles$1.bgColor.ansi256=wrapAnsi256(10),styles$1.bgColor.ansi16m=wrapAnsi16m(10),Object.defineProperties(styles$1,{rgbToAnsi256:{value:(e,t,r)=>e===t&&t===r?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(r/255*5),enumerable:!1},hexToRgb:{value(e){const t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[r]=t;3===r.length&&(r=[...r].map((e=>e+e)).join(""));const i=Number.parseInt(r,16);return[i>>16&255,i>>8&255,255&i]},enumerable:!1},hexToAnsi256:{value:e=>styles$1.rgbToAnsi256(...styles$1.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return e-8+90;let t,r,i;if(e>=232)t=(10*(e-232)+8)/255,r=t,i=t;else{const n=(e-=16)%36;t=Math.floor(e/36)/5,r=Math.floor(n/6)/5,i=n%6/5}const n=2*Math.max(t,r,i);if(0===n)return 30;let a=30+(Math.round(i)<<2|Math.round(r)<<1|Math.round(t));return 2===n&&(a+=60),a},enumerable:!1},rgbToAnsi:{value:(e,t,r)=>styles$1.ansi256ToAnsi(styles$1.rgbToAnsi256(e,t,r)),enumerable:!1},hexToAnsi:{value:e=>styles$1.ansi256ToAnsi(styles$1.hexToAnsi256(e)),enumerable:!1}}),styles$1}const ansiStyles=assembleStyles(),level=(()=>{if(!("navigator"in globalThis))return 0;if(globalThis.navigator.userAgentData){const e=navigator.userAgentData.brands.find((({brand:e})=>"Chromium"===e));if(e&&e.version>93)return 3}return/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)?1:0})(),colorSupport=0!==level&&{level,hasBasic:!0,has256:level>=2,has16m:level>=3},supportsColor={stdout:colorSupport,stderr:colorSupport};function stringReplaceAll(e,t,r){let i=e.indexOf(t);if(-1===i)return e;const n=t.length;let a=0,s="";do{s+=e.slice(a,i)+t+r,a=i+n,i=e.indexOf(t,a)}while(-1!==i);return s+=e.slice(a),s}function stringEncaseCRLFWithFirstIndex(e,t,r,i){let n=0,a="";do{const s="\r"===e[i-1];a+=e.slice(n,s?i-1:i)+t+(s?"\r\n":"\n")+r,n=i+1,i=e.indexOf("\n",n)}while(-1!==i);return a+=e.slice(n),a}const{stdout:stdoutColor,stderr:stderrColor}=supportsColor,GENERATOR=Symbol("GENERATOR"),STYLER=Symbol("STYLER"),IS_EMPTY=Symbol("IS_EMPTY"),levelMapping=["ansi","ansi","ansi256","ansi16m"],styles=Object.create(null),applyOptions=(e,t={})=>{if(t.level&&!(Number.isInteger(t.level)&&t.level>=0&&t.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");const r=stdoutColor?stdoutColor.level:0;e.level=void 0===t.level?r:t.level},chalkFactory=e=>{const t=(...e)=>e.join(" ");return applyOptions(t,e),Object.setPrototypeOf(t,createChalk.prototype),t};function createChalk(e){return chalkFactory(e)}Object.setPrototypeOf(createChalk.prototype,Function.prototype);for(const[e,t]of Object.entries(ansiStyles))styles[e]={get(){const r=createBuilder(this,createStyler(t.open,t.close,this[STYLER]),this[IS_EMPTY]);return Object.defineProperty(this,e,{value:r}),r}};styles.visible={get(){const e=createBuilder(this,this[STYLER],!0);return Object.defineProperty(this,"visible",{value:e}),e}};const getModelAnsi=(e,t,r,...i)=>"rgb"===e?"ansi16m"===t?ansiStyles[r].ansi16m(...i):"ansi256"===t?ansiStyles[r].ansi256(ansiStyles.rgbToAnsi256(...i)):ansiStyles[r].ansi(ansiStyles.rgbToAnsi(...i)):"hex"===e?getModelAnsi("rgb",t,r,...ansiStyles.hexToRgb(...i)):ansiStyles[r][e](...i),usedModels=["rgb","hex","ansi256"];for(const e of usedModels){styles[e]={get(){const{level:t}=this;return function(...r){const i=createStyler(getModelAnsi(e,levelMapping[t],"color",...r),ansiStyles.color.close,this[STYLER]);return createBuilder(this,i,this[IS_EMPTY])}}};styles["bg"+e[0].toUpperCase()+e.slice(1)]={get(){const{level:t}=this;return function(...r){const i=createStyler(getModelAnsi(e,levelMapping[t],"bgColor",...r),ansiStyles.bgColor.close,this[STYLER]);return createBuilder(this,i,this[IS_EMPTY])}}}}const proto=Object.defineProperties((()=>{}),{...styles,level:{enumerable:!0,get(){return this[GENERATOR].level},set(e){this[GENERATOR].level=e}}}),createStyler=(e,t,r)=>{let i,n;return void 0===r?(i=e,n=t):(i=r.openAll+e,n=t+r.closeAll),{open:e,close:t,openAll:i,closeAll:n,parent:r}},createBuilder=(e,t,r)=>{const i=(...e)=>applyStyle(i,1===e.length?""+e[0]:e.join(" "));return Object.setPrototypeOf(i,proto),i[GENERATOR]=e,i[STYLER]=t,i[IS_EMPTY]=r,i},applyStyle=(e,t)=>{if(e.level<=0||!t)return e[IS_EMPTY]?"":t;let r=e[STYLER];if(void 0===r)return t;const{openAll:i,closeAll:n}=r;if(t.includes(""))for(;void 0!==r;)t=stringReplaceAll(t,r.close,r.open),r=r.parent;const a=t.indexOf("\n");return-1!==a&&(t=stringEncaseCRLFWithFirstIndex(t,n,i,a)),i+t+n};Object.defineProperties(createChalk.prototype,styles);const chalk=createChalk();createChalk({level:stderrColor?stderrColor.level:0});class Terminal{supportedTypes;encoding;getSupportedTypes(){if(void 0===this.supportedTypes&&(this.supportedTypes=new Set,this.supportedTypes.add(TerminalEncoding.NONE),void 0===globalThis.window))switch(chalk.level){case 3:this.supportedTypes.add(TerminalEncoding.NODE_16MILLION_COLORS);case 2:this.supportedTypes.add(TerminalEncoding.NODE_256_COLORS);case 1:this.supportedTypes.add(TerminalEncoding.NODE_16_COLORS);case 0:break;default:throw new RangeError(`chalk.level had an unexpected value.\nActual: ${String(chalk.level)}`)}return this.supportedTypes}setEncodingImpl(e,t){assertThatType(t,"force",Type.BOOLEAN),this.getSupportedTypes().has(e)||t?this.encoding=e:this.encoding=TerminalEncoding.NONE}setEncoding(e){this.setEncodingImpl(e,!0)}useBestEncoding(){const e=[...this.getSupportedTypes()].sort(sortByDecreasingRank);this.setEncodingImpl(e[0],!1)}getEncoding(){let e=this.encoding;return void 0===e&&(this.useBestEncoding(),e=this.encoding),e}}class DefaultProcessScope{static INSTANCE=new DefaultProcessScope;terminal=new Terminal;constructor(){}getTerminal(){return this.terminal}close(){}}class MainGlobalConfiguration{terminal;constructor(e){assertThatValueIsNotNull(e,"terminal"),this.terminal=e}supportedTerminalEncodings(){return this.terminal.getSupportedTypes()}terminalEncoding(e){return void 0===e?this.terminal.getEncoding():(this.terminal.setEncoding(e),this)}toString(){return`MainGlobalConfiguration[supportedTerminalEncodings=\n${internalValueToString(this.supportedTerminalEncodings())}, terminalEncoding=\n${internalValueToString(this.terminalEncoding())}]`}}class StringMappers{static DEFAULT=new StringMappers;typeToMapper;constructor(e){void 0===e?(this.typeToMapper=new Map,this.typeToMapper.set(Type.STRING,(e=>quoteString(e))),this.typeToMapper.set(Type.ARRAY,((e,t)=>this.arrayToString(e,t))),this.typeToMapper.set(Type.namedClass("Set"),((e,t)=>this.setToString(e,t))),this.typeToMapper.set(Type.namedClass("Map"),((e,t)=>this.mapToString(e,t))),this.typeToMapper.set(Type.namedClass("Error"),(e=>this.errorToString(e))),this.typeToMapper.set(Type.namedClass("Type"),(e=>e.toString()))):this.typeToMapper=new Map(e)}arrayToString(e,t){void 0===t&&(t=new Set);const r=[];for(const i of e)null!==i&&Array.isArray(i)?t.has(i)?r.push("..."):(t.add(i),r.push(this.valueToString(i,t))):r.push(this.valueToString(i,t));return`[${r.join(", ")}]`}valueToString(e,t){return getMapper(e,this.typeToMapper)(e,t)}setToString(e,t){return void 0===t&&(t=new Set),this.orderedToString([...e],t)}orderedToString(e,t){let r="[";for(const i of e)if(i===e)r+="(this Collection)";else{r+=getMapper(i,this.typeToMapper)(i,t)}return r+"]"}mapToString(e,t){return void 0===t&&(t=new Set),this.mapEntriesToString([...e.entries()],t)}mapEntriesToString(e,t){let r="{";for(const i of e){const n=i[0],a=i[1];let s,o;s=n===e?"(this Map)":getMapper(n,this.typeToMapper)(n,t),o=a===e?"(this Map)":getMapper(a,this.typeToMapper)(a,t),r+=`${s} = ${o}`}return r+"}"}errorToString(e){return void 0===e.stack?"":e.stack}toString(e){return getMapper(e,this.typeToMapper)(e)}}class MutableStringMappers{typeToMapper;constructor(e){this.typeToMapper=new Map(e)}static from(e){return new MutableStringMappers(e.typeToMapper)}toImmutable(){return new StringMappers(this.typeToMapper)}put(e,t){return this.typeToMapper.set(e,t),this}remove(e){return this.typeToMapper.delete(e),this}toString(){return internalValueToString(this.typeToMapper)}}class MutableConfiguration{_stringMappers;_allowDiff;_recordStacktrace;_throwOnFailure;_errorTransformer;constructor(e,t,r,i,n){this._allowDiff=e,this._stringMappers=t,this._recordStacktrace=r,this._throwOnFailure=i,this._errorTransformer=n}static from(e){return new MutableConfiguration(e.allowDiff(),MutableStringMappers.from(e.stringMappers()),e.recordStacktrace(),e.throwOnFailure(),e.errorTransformer())}toImmutable(){return new Configuration(this._allowDiff,this._stringMappers.toImmutable(),this._recordStacktrace,this._throwOnFailure,this._errorTransformer)}allowDiff(e){return void 0===e?this._allowDiff:(this._allowDiff=e,this)}stringMappers(){return this._stringMappers}recordStacktrace(e){return void 0===e?this._recordStacktrace:(this._recordStacktrace=e,this)}throwOnFailure(e){return void 0===e?this._throwOnFailure:(this._throwOnFailure=e,this)}errorTransformer(e){return void 0===e?this._errorTransformer:(this._errorTransformer=e,this)}toString(){return`Configuration[allowDiff=${this._allowDiff}, stringMappers=${internalValueToString(this._stringMappers)}, recordStacktrace: ${this._recordStacktrace}, throwOnFailure: ${this._throwOnFailure}]`}}class ConfigurationUpdaterImpl{outer;_allowDiff;mutableStringMappers;_recordStacktrace;_errorTransformer;changed=!1;closed=!1;constructor(e){this.outer=e;const t=e.getRequireThatConfiguration();this._allowDiff=t.allowDiff(),this.mutableStringMappers=MutableStringMappers.from(t.stringMappers()),this._recordStacktrace=t.recordStacktrace(),this._errorTransformer=t.errorTransformer()}allowDiff(e){return this.ensureOpen(),void 0===e?this._allowDiff:(e!==this._allowDiff&&(this._allowDiff=e,this.changed=!0),this)}stringMappers(){return this.ensureOpen(),this.mutableStringMappers}recordStacktrace(e){return this.ensureOpen(),void 0===e?this._recordStacktrace:(e!==this._recordStacktrace&&(this._recordStacktrace=e,this.changed=!0),this)}errorTransformer(e){return this.ensureOpen(),void 0===e?this._errorTransformer:(e!==this._errorTransformer&&(this._errorTransformer=e,this.changed=!0),this)}ensureOpen(){if(this.closed)throw new IllegalStateError("The changes have already been applied")}close(){if(this.closed)return;this.closed=!0;const e=this.outer.getRequireThatConfiguration(),t=this.mutableStringMappers.toImmutable();this.changed||=t!==e.stringMappers(),this.changed&&this.outer.setConfiguration(new Configuration(this._allowDiff,t,this._recordStacktrace,e.throwOnFailure(),this._errorTransformer))}toString(){return`allowDiff: ${this._allowDiff}, stringMappers: ${internalValueToString(this.mutableStringMappers)}, recordStacktrace: ${this._recordStacktrace}`}}class AbstractValidators{static CONVERT_TO_ASSERTION_ERROR=e=>{const t=new AssertionError(e.message);throw t.stack=e.stack?.replace(e.name,t.name),t};scope;requireThatConfiguration;assertThatConfiguration;checkIfConfiguration;context=new Map;constructor(e,t){this.scope=e,requireThatValueIsNotNull(t,"configuration"),this.requireThatConfiguration=t,this.assertThatConfiguration=MutableConfiguration.from(t).throwOnFailure(!1).errorTransformer(AbstractValidators.CONVERT_TO_ASSERTION_ERROR).toImmutable(),this.checkIfConfiguration=MutableConfiguration.from(t).throwOnFailure(!1).toImmutable()}getScope(){return this.scope}getRequireThatConfiguration(){return this.requireThatConfiguration}getAssertThatConfiguration(){return this.assertThatConfiguration}getCheckIfConfiguration(){return this.checkIfConfiguration}updateConfiguration(e){if(void 0===e)return new ConfigurationUpdaterImpl(this);const t=this.updateConfiguration();return e(t),t.close(),this}setConfiguration(e){requireThatValueIsNotNull(e,"configuration"),this.requireThatConfiguration=e,this.assertThatConfiguration=MutableConfiguration.from(e).errorTransformer(AbstractValidators.CONVERT_TO_ASSERTION_ERROR).toImmutable(),this.checkIfConfiguration=MutableConfiguration.from(e).throwOnFailure(!1).toImmutable()}getContext(){return new Map(this.context)}getGlobalConfiguration(){return this.scope.getGlobalConfiguration()}}function isApplicationScope(e){return void 0!==e.getGlobalConfiguration}class AbstractApplicationScope{parent;globalConfiguration;constructor(e,t){assertThatValueIsNotNull(e,"parent"),assertThatValueIsNotNull(t,"globalConfiguration"),this.parent=e,this.globalConfiguration=t}getGlobalConfiguration(){return this.globalConfiguration}getTerminal(){return this.parent.getTerminal()}}class MainApplicationScope extends AbstractApplicationScope{static INSTANCE=new MainApplicationScope(DefaultProcessScope.INSTANCE);constructor(e){super(e,new MainGlobalConfiguration(e.getTerminal()))}close(){}}class Configuration{static DEFAULT=new Configuration;_stringMappers;_allowDiff;_recordStacktrace;_throwOnFailure;_errorTransformer;constructor(e=!0,t=StringMappers.DEFAULT,r=!0,i=!0,n=e=>e){requireThatValueIsNotNull(t,"stripMappers"),requireThatValueIsNotNull(n,"errorTransformer"),this._allowDiff=e,this._stringMappers=t,this._recordStacktrace=r,this._throwOnFailure=i,this._errorTransformer=n}allowDiff(){return this._allowDiff}stringMappers(){return this._stringMappers}recordStacktrace(){return this._recordStacktrace}throwOnFailure(){return this._throwOnFailure}errorTransformer(){return this._errorTransformer}toString(){return`Configuration[allowDiff=${this._allowDiff}, , stringMappers=${this._stringMappers.toString()},recordStacktrace: ${this._recordStacktrace}, throwOnFailure: ${this._throwOnFailure}`}}class JavascriptValidatorsImpl extends AbstractValidators{static DEFAULT_NAME="value";static INTERNAL=new JavascriptValidatorsImpl(MainApplicationScope.INSTANCE,Configuration.DEFAULT);constructor(e,t){if(super(e,JavascriptValidatorsImpl.getRequireThatConfiguration(t)),t instanceof JavascriptValidatorsImpl)for(const e of t.context)this.context.set(e[0],e[1])}static getRequireThatConfiguration(e){return e instanceof Configuration?e:e.getRequireThatConfiguration()}requireThatNumber(e,t){return verifyName(t,"name"),this.validateNumber(e,t,this.getRequireThatConfiguration())}requireThatBoolean(e,t){return verifyName(t,"name"),this.validateBoolean(e,t,this.getRequireThatConfiguration())}requireThatArray(e,t){return verifyName(t,"name"),this.validateArray(e,t,this.getRequireThatConfiguration())}requireThatSet(e,t){return verifyName(t,"name"),this.validateSet(e,t,this.getRequireThatConfiguration())}requireThatMap(e,t){return verifyName(t,"name"),this.validateMap(e,t,this.getRequireThatConfiguration())}requireThatString(e,t){return verifyName(t,"name"),this.validateString(e,t,this.getRequireThatConfiguration())}requireThat(e,t){return verifyName(t,"name"),this.validateUnknown(e,t,this.getRequireThatConfiguration())}assertThatNumber(e,t){return this.validateNumber(e,t,this.getAssertThatConfiguration())}assertThatBoolean(e,t){return this.validateBoolean(e,t,this.getAssertThatConfiguration())}assertThatArray(e,t){return this.validateArray(e,t,this.getAssertThatConfiguration())}assertThatSet(e,t){return this.validateSet(e,t,this.getAssertThatConfiguration())}assertThatMap(e,t){return this.validateMap(e,t,this.getAssertThatConfiguration())}assertThatString(e,t){return this.validateString(e,t,this.getAssertThatConfiguration())}assertThat(e,t){return this.validateUnknown(e,t,this.getAssertThatConfiguration())}checkIfNumber(e,t){return this.validateNumber(e,t,this.getCheckIfConfiguration())}checkIfBoolean(e,t){return this.validateBoolean(e,t,this.getCheckIfConfiguration())}checkIfArray(e,t){return this.validateArray(e,t,this.getCheckIfConfiguration())}checkIfSet(e,t){return this.validateSet(e,t,this.getCheckIfConfiguration())}checkIfMap(e,t){return this.validateMap(e,t,this.getCheckIfConfiguration())}checkIfString(e,t){return this.validateString(e,t,this.getCheckIfConfiguration())}checkIf(e,t){return this.validateUnknown(e,t,this.getCheckIfConfiguration())}validateNumber(e,t,r){void 0===t?t=JavascriptValidatorsImpl.DEFAULT_NAME:verifyName(t,"name");const i=new NumberValidatorImpl(this.scope,r,t,ValidationTarget.valid(e),new Map,[]);return this.validateType(i,e,Type.NUMBER),i}validateType(e,t,r){switch(Type.of(t)){case Type.UNDEFINED:case Type.NULL:return}r.equals(r)||e.addTypeError(messagesIsInstanceOf(e,r).toString())}validateBoolean(e,t,r){void 0===t?t=JavascriptValidatorsImpl.DEFAULT_NAME:verifyName(t,"name");const i=new BooleanValidatorImpl(this.scope,r,t,ValidationTarget.valid(e),new Map,[]);return this.validateType(i,e,Type.BOOLEAN),i}validateArray(e,t,r){void 0===t?t=JavascriptValidatorsImpl.DEFAULT_NAME:verifyName(t,"name");const i=new ArrayValidatorImpl(this.scope,r,t,ValidationTarget.valid(e),Pluralizer.ELEMENT,new Map,[]);return this.validateType(i,e,Type.ARRAY),i}validateSet(e,t,r){void 0===t?t=JavascriptValidatorsImpl.DEFAULT_NAME:verifyName(t,"name");const i=new SetValidatorImpl(this.scope,r,t,ValidationTarget.valid(e),Pluralizer.ELEMENT,new Map,[]);return this.validateType(i,e,Type.namedClass("Set")),i}validateMap(e,t,r){void 0===t?t=JavascriptValidatorsImpl.DEFAULT_NAME:verifyName(t,"name");const i=new MapValidatorImpl(this.scope,r,t,ValidationTarget.valid(e),new Map,[]);return this.validateType(i,e,Type.namedClass("Map")),i}validateString(e,t,r){void 0===t?t=JavascriptValidatorsImpl.DEFAULT_NAME:verifyName(t,"name");const i=new StringValidatorImpl(this.scope,r,t,ValidationTarget.valid(e),new Map,[]);return this.validateType(i,e,Type.STRING),i}validateUnknown(e,t,r){void 0===t?t=JavascriptValidatorsImpl.DEFAULT_NAME:verifyName(t,"name");const i=new UnknownValidatorImpl(this.scope,r,t,ValidationTarget.valid(e),new Map,[]);return this.validateType(i,e,Type.namedClass(null)),i}copy(){return new JavascriptValidatorsImpl(this.scope,this)}withContext(e,t){return requireThatType(t,"name",Type.STRING),this.context.set(t,e),this}removeContext(e){return this.context.delete(e),this}}class UnknownValidatorImpl extends AbstractValidator{constructor(e,t,r,i,n,a){super(e,t,r,i,n,a)}}class MapValidatorImpl extends AbstractValidator{constructor(e,t,r,i,n,a){super(e,t,r,i,n,a)}isEmpty(){return this.value.validationFailed((e=>0===e.size))&&(this.failOnUndefinedOrNull(),this.addRangeError(objectIsEmpty(this).toString())),this}isNotEmpty(){return this.value.validationFailed((e=>0!==e.size))&&(this.failOnUndefinedOrNull(),this.addRangeError(objectIsNotEmpty(this).toString())),this}keys(){this.failOnUndefinedOrNull();const e=this.value.undefinedOrNullToInvalid(),t=new ArrayValidatorImpl(this.scope,this._configuration,this.name+".keys()",e.map((e=>[...e.keys()])),Pluralizer.KEY,this.context,this.failures);return e.ifValid((e=>t.withContext(e,this.name))),t}values(){this.failOnUndefinedOrNull();const e=this.value.undefinedOrNullToInvalid(),t=new ArrayValidatorImpl(this.scope,this._configuration,this.name+".values()",e.map((e=>[...e.values()])),Pluralizer.VALUE,this.context,this.failures);return e.ifValid((e=>t.withContext(e,this.name))),t}entries(){this.failOnUndefinedOrNull();const e=this.value.undefinedOrNullToInvalid(),t=new ArrayValidatorImpl(this.scope,this._configuration,this.name+".entries()",e.map((e=>[...e.entries()])),Pluralizer.ENTRY,this.context,this.failures);return e.ifValid((e=>t.withContext(e,this.name))),t}size(){return this.failOnUndefinedOrNull(),new ObjectSizeValidatorImpl(this.scope,this._configuration,this,this.name+".size()",this.value.undefinedOrNullToInvalid().map((e=>e.size)),Pluralizer.ELEMENT,this.context,this.failures)}}class NumberValidatorImpl extends AbstractValidator{constructor(e,t,r,i,n,a){super(e,t,r,i,n,a)}isNegative(){return this.value.validationFailed((e=>e<0))&&(this.failOnUndefinedOrNull(),this.addRangeError(numberIsNegative(this).toString())),this}isNotNegative(){return this.value.validationFailed((e=>!(e<0)))&&(this.failOnUndefinedOrNull(),this.addRangeError(numberIsNegative(this).toString())),this}isZero(){return this.value.validationFailed((e=>0===e))&&(this.failOnUndefinedOrNull(),this.addRangeError(numberIsZero(this).toString())),this}isNotZero(){return this.value.validationFailed((e=>!(0===e)))&&(this.failOnUndefinedOrNull(),this.addRangeError(numberIsNotZero(this).toString())),this}isPositive(){return this.value.validationFailed((e=>e>0))&&(this.failOnUndefinedOrNull(),this.addRangeError(numberIsPositive(this).toString())),this}isNotPositive(){return this.value.validationFailed((e=>!(e>0)))&&(this.failOnUndefinedOrNull(),this.addRangeError(numberIsNotPositive(this).toString())),this}isGreaterThan(e,t){return void 0!==t&&this.requireThatNameIsUnique(t),this.value.validationFailed((t=>t>e))&&(this.failOnUndefinedOrNull(),this.addRangeError(co