vest 4.0.0-dev-31f012 → 4.0.0-dev-e266d9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +70 -52
  2. package/README.md +2 -112
  3. package/dist/cjs/compose.js +7 -0
  4. package/dist/cjs/compounds.js +7 -0
  5. package/dist/cjs/enforce/compose.development.js +139 -0
  6. package/dist/cjs/enforce/compose.production.js +1 -0
  7. package/dist/cjs/enforce/compounds.development.js +132 -0
  8. package/dist/cjs/enforce/compounds.production.js +1 -0
  9. package/dist/cjs/enforce/package.json +1 -0
  10. package/dist/cjs/enforce/schema.development.js +144 -0
  11. package/dist/cjs/enforce/schema.production.js +1 -0
  12. package/dist/cjs/schema.js +7 -0
  13. package/dist/cjs/vest.development.js +504 -1034
  14. package/dist/cjs/vest.production.js +1 -1
  15. package/dist/es/enforce/compose.development.js +137 -0
  16. package/dist/es/enforce/compose.production.js +1 -0
  17. package/dist/es/enforce/compounds.development.js +130 -0
  18. package/dist/es/enforce/compounds.production.js +1 -0
  19. package/dist/es/enforce/package.json +1 -0
  20. package/dist/es/enforce/schema.development.js +140 -0
  21. package/dist/es/enforce/schema.production.js +1 -0
  22. package/dist/es/vest.development.js +497 -1033
  23. package/dist/es/vest.production.js +1 -1
  24. package/dist/umd/enforce/compose.development.js +143 -0
  25. package/dist/umd/enforce/compose.production.js +1 -0
  26. package/dist/umd/enforce/compounds.development.js +136 -0
  27. package/dist/umd/enforce/compounds.production.js +1 -0
  28. package/dist/umd/enforce/schema.development.js +148 -0
  29. package/dist/umd/enforce/schema.production.js +1 -0
  30. package/dist/umd/vest.development.js +1693 -2226
  31. package/dist/umd/vest.production.js +1 -1
  32. package/enforce/compose/package.json +7 -0
  33. package/enforce/compounds/package.json +7 -0
  34. package/enforce/schema/package.json +7 -0
  35. package/package.json +107 -13
  36. package/testUtils/mockThrowError.ts +16 -0
  37. package/types/enforce/compose.d.ts +134 -0
  38. package/types/enforce/compounds.d.ts +146 -0
  39. package/types/enforce/schema.d.ts +151 -0
  40. package/types/vest.d.ts +31 -203
@@ -1 +1 @@
1
- "use strict";!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).vest={})}(this,(function(n){function t(n,t,r){if(r||2===arguments.length)for(var e,u=0,i=t.length;u<i;u++)!e&&u in t||(e||(e=Array.prototype.slice.call(t,0,u)),e[u]=t[u]);return n.concat(e||t)}function r(n){return"function"==typeof n}function e(n,t){function r(n){e=!0,u=n}for(var e=!1,u=null,i=0;i<n.length;i++)if(t(n[i],r,i),e)return u}function u(n){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return r(n)?n.apply(void 0,t):n}function i(n,t){var r;return null!==(r=u(n))&&void 0!==r?r:t}function o(n,t){return n={pass:n},t&&(n.message=t),n}function s(n,t){try{return n.run(t)}catch(n){return o(!1)}}function a(n){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return!n.apply(void 0,t)}}function c(n,t){return n.length===Number(t)}function f(n,t){return n.length>Number(t)}function l(n){return null===n}function p(n){return void 0===n}function v(n){return String(n)===n}function d(n,t){return v(n)&&v(t)&&n.endsWith(t)}function h(n,t){return n===t}function g(n){var t=Number(n);return!(isNaN(parseFloat(String(n)))||isNaN(Number(n))||!isFinite(t))}function m(n,t){return g(n)&&g(t)&&Number(n)>Number(t)}function y(n,t){return g(n)&&g(t)&&Number(n)>=Number(t)}function N(n){return!!Array.isArray(n)}function b(n,t){return!!(N(t)||v(t)&&v(n))&&-1!==t.indexOf(n)}function E(n,t){return g(n)&&g(t)&&Number(n)<=Number(t)}function C(n,t,r){return y(n,t)&&E(n,r)}function O(n){return v(n)&&!n.trim()}function T(n){return!!n===n}function S(n){return"number"==typeof n}function w(n){if(n){if(S(n))return 0===n;if(Object.prototype.hasOwnProperty.call(n,"length"))return c(n,0);if("object"==typeof n)return c(Object.keys(n),0)}return!0}function P(n){return Number.isNaN(n)}function x(n){return!!g(n)&&0>Number(n)}function F(n){return!!n}function k(n,t){return g(n)&&g(t)&&Number(n)<Number(t)}function I(n,t){return t instanceof RegExp?t.test(n):!!v(t)&&new RegExp(t).test(n)}function A(n,t){return g(n)&&g(t)&&Number(n)===Number(t)}function D(n,t){return v(n)&&v(t)&&n.startsWith(t)}function L(n,t){throw Error(i(t,n))}function W(n){function t(t,u){var i,o,s=r();return t=qn({},s||{},null!==(i=null==n?void 0:n(t,s))&&void 0!==i?i:t),i=e.ctx=Object.freeze(t),e.ancestry.unshift(i),u=u(i),e.ancestry.shift(),e.ctx=null!==(o=e.ancestry[0])&&void 0!==o?o:null,u}function r(){return e.ctx}var e={ancestry:[]};return{bind:function(n,r){return function(){for(var e=[],u=0;u<arguments.length;u++)e[u]=arguments[u];return t(n,(function(){return r.apply(void 0,e)}))}},run:t,use:r,useX:function(n){var t;return null!==(t=e.ctx)&&void 0!==t?t:L(i(n,"Context was used after it was closed"))}}}function U(){return null}function j(n,t){var r,e=function(r){var e=n[r],u=t[r];if(!(r=ft.run({value:e,set:!0,meta:{key:r}},(function(){return s(u,e)}))).pass)return{value:r}};for(r in t){var u=e(r);if("object"==typeof u)return u.value}return o(!0)}function R(n){for(var t in lt){var e=lt[t];r(e)&&n(t,e)}}function X(){try{return r(Proxy)}catch(n){return!1}}function _(n,r,e){for(var i=[],s=3;s<arguments.length;s++)i[s-3]=arguments[s];return T(n)||n&&T(n.pass)||L("Incorrect return value for rule: "+JSON.stringify(n)),T(n)?o(n):o(n.pass,u.apply(void 0,t([n.message,r,e],i)))}function M(n){function r(r,e,u){return function(){for(var i=[],o=0;o<arguments.length;o++)i[o]=arguments[o];if(!(o=_.apply(void 0,t([ft.run({value:n},(function(){return e.apply(void 0,t([n],i))})),u,n],i))).pass){if(!w(o.message))throw o.message;L("enforce/"+u+" failed with "+JSON.stringify(n))}return r}}var e={};if(!X())return R((function(n,t){e[n]=r(e,t,n)})),e;var u=new Proxy(e,{get:function(n,t){if(n=lt[t])return r(u,n,t)}});return u}function G(n){var r,s=[];return function n(a){return function(){for(var c=[],f=0;f<arguments.length;f++)c[f]=arguments[f];var l=lt[a];s.push((function(n){return _.apply(void 0,t([l.apply(void 0,t([n],c)),a,n],c))}));var p={run:function(n){return i(e(s,(function(t,e){var i,s=ft.run({value:n},(function(){return t(n)}));s.pass||e(o(!!s.pass,null!==(i=u(r,n,s.message))&&void 0!==i?i:s.message))})),o(!0))},test:function(n){return p.run(n).pass},message:function(n){return n&&(r=n),p}};return X()?p=new Proxy(p,{get:function(t,r){return lt[r]?n(r):t[r]}}):(R((function(t){p[t]=n(t)})),p)}}(n)}function q(n){var t,r={};for(t in n)r[t]=pt.optional(n[t]);return r}function B(n,t){return t=t.suiteId,{optionalFields:n.registerStateKey((function(){return{}})),suiteId:n.registerStateKey(t),testCallbacks:n.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:n.registerStateKey((function(n){return{prev:n?n.current:[],current:[]}}))}}function K(n){return(n=[].concat(n))[n.length-1]}function H(){function n(){t=[0]}var t=[];return n(),{addLevel:function(){t.push(0)},cursorAt:function(){return K(t)},getCursor:function(){return[].concat(t)},next:function(){return t[t.length-1]++,K(t)},removeLevel:function(){t.pop()},reset:n}}function V(n,t){for(var r=[],e=0;e<n.length;e++){var u=n[e];N(u)?r.push(V(u,t)):(u=t(u),Kn(u)&&r.push(u))}return r}function J(n){return[].concat(n).reduce((function(n,t){return N(t)?n.concat(J(t)):[].concat(n).concat(t)}),[])}function z(n,t){var r=0;for(t=t.slice(0,-1);r<t.length;r++){var e=t[r];n[e]=i(n[e],[]),n=n[e]}return n}function Y(n){void 0===n&&(n=1);var t=[],r=function(e,u){var i=r.get(e);return i?i[1]:(u=u(),t.unshift([e.concat(),u]),f(t,n)&&(t.length=n),u)};return r.invalidate=function(n){var r=t.findIndex((function(t){var r=t[0];return c(n,r.length)&&n.every((function(n,t){return n===r[t]}))}));-1<r&&t.splice(r,1)},r.get=function(n){return t[t.findIndex((function(t){var r=t[0];return c(n,r.length)&&n.every((function(n,t){return n===r[t]}))}))]||null},r}function Q(){return ht.useX().stateRef}function Z(){(0,Q().testObjects()[1])((function(n){return{prev:n.prev,current:[].concat(n.current)}}))}function $(n){(0,Q().testObjects()[1])((function(t){return{prev:t.prev,current:[].concat(n(t.current))}}))}function nn(){return J(V(Q().testObjects()[0].current,(function(n){return n.isPending()?n:null})))}function tn(){var n=Q().testObjects()[0].current;return gt([n],(function(){return J(n)}))}function rn(){return ht.useX().testCursor.getCursor()}function en(n,t){if(n=void 0===(n=n.type)?_n.DEFAULT:n,r(t)){var e=rn();return ht.run({isolate:{type:n}},(function(){ht.useX().testCursor.addLevel(),$((function(n){return z(n,e)[K(e)]=[],n}));var n=t();return ht.useX().testCursor.removeLevel(),ht.useX().testCursor.next(),n}))}}function un(n,t){return!(!t||n.fieldName!==t)}function on(n){var t=nn();return!w(t)&&(n?t.some((function(t){return un(t,n)})):rt(t))}function sn(n,t){function r(n,t){i[n]++,u&&(i[t]=(i[t]||[]).concat(u))}var e=t.fieldName,u=t.message;n[e]=n[e]||{errorCount:0,warnCount:0,testCount:0};var i=n[e];return t.isSkipped()||(n[e].testCount++,t.isFailing()?r("errorCount","errors"):t.isWarning()&&r("warnCount","warnings")),i}function an(n,t,r){var e;void 0===r&&(r={});var u=(r=r||{}).group,i=r.fieldName;return t.reduce((function(t,r){return u&&r.groupName!==u||i&&!un(r,i)||"warnings"===n!=!!r.warns||!r.hasFailures()||(t[r.fieldName]=(t[r.fieldName]||[]).concat(r.message||[])),t}),Gn({},i&&((e={})[i]=[],e)))}function cn(n){return ln("errors",n)}function fn(n){return ln("warnings",n)}function ln(n,t){return n=an(n,tn(),{fieldName:t}),t?n[t]:n}function pn(n,t){return n=dn("errors",n,t),t?n[t]:n}function vn(n,t){return n=dn("warnings",n,t),t?n[t]:n}function dn(n,t,r){return t||L("get"+n[0].toUpperCase()+n.slice(1)+"ByGroup requires a group name. Received `"+t+"` instead."),an(n,tn(),{group:t,fieldName:r})}function hn(n,t,r){return!(!n.hasFailures()||r&&!un(n,r)||"warnings"===t!=!!n.warns)}function gn(n){return yn("errors",n)}function mn(n){return yn("warnings",n)}function yn(n,t){return tn().some((function(r){return hn(r,n,t)}))}function Nn(n,t){return En("errors",n,t)}function bn(n,t){return En("warnings",n,t)}function En(n,t,r){return tn().some((function(e){return t===e.groupName&&hn(e,n,r)}))}function Cn(){var n=tn(),t={stateRef:Q()};return mt([n],ht.bind(t,(function(){return qn(function(){var n={errorCount:0,groups:{},testCount:0,tests:{},warnCount:0};return tn().forEach((function(t){var r=t.fieldName,e=t.groupName;n.tests[r]=sn(n.tests,t),e&&(n.groups[e]=n.groups[e]||{},n.groups[e][r]=sn(n.groups[e],t))})),function(n){for(var t in n.tests)n.errorCount+=n.tests[t].errorCount,n.warnCount+=n.tests[t].warnCount,n.testCount+=n.tests[t].testCount;return n}(n)}(),{getErrors:ht.bind(t,cn),getErrorsByGroup:ht.bind(t,pn),getWarnings:ht.bind(t,fn),getWarningsByGroup:ht.bind(t,vn),hasErrors:ht.bind(t,gn),hasErrorsByGroup:ht.bind(t,Nn),hasWarnings:ht.bind(t,mn),hasWarningsByGroup:ht.bind(t,bn),isValid:ht.bind(t,(function(n){var t=Cn(),r=tn().reduce((function(n,t){return n[t.fieldName]||t.isOmitted()&&(n[t.fieldName]=!0),n}),{});return(r=!!n&&!!r[n])?n=!0:t.hasErrors(n)?n=!1:n=!(w(r=tn())||n&&w(t.tests[n])||function(n){var t=Q().optionalFields()[0];return rt(nn().filter((function(r){return!(n&&!un(r,n))&&!0!==t[r.fieldName]})))}(n))&&function(n){var t=tn(),r=Q().optionalFields()[0];return t.every((function(t){return!(!n||un(t,n))||!0===r[t.fieldName]||t.isTested()||t.isOmitted()}))}(n),n}))})})))}function On(){var n=tn(),t={stateRef:Q()};return yt([n],ht.bind(t,(function(){return qn({},Cn(),{done:ht.bind(t,Nt)})})))}function Tn(n,t,e){return!(r(n)&&(!t||e.tests[t]&&0!==e.tests[t].testCount))}function Sn(n){return!(on()&&(!n||on(n)))}function wn(n,t){var r=ht.bind({},n);(0,Q().testCallbacks()[1])((function(n){return t?n.fieldCallbacks[t]=(n.fieldCallbacks[t]||[]).concat(r):n.doneCallbacks.push(r),n}))}function Pn(n){return n.forEach((function(n){return n()}))}function xn(){var n=function(){var n={};return{emit:function(t,r){n[t]&&n[t].forEach((function(n){n(r)}))},on:function(t,r){return n[t]||(n[t]=[]),n[t].push(r),{off:function(){n[t]=n[t].filter((function(n){return n!==r}))}}}}}();return n.on(dt.TEST_COMPLETED,(function(n){if(!n.isCanceled()){n.done(),n=n.fieldName;var t=Q().testCallbacks()[0].fieldCallbacks;n&&!on(n)&&N(t[n])&&Pn(t[n]),n=Q().testCallbacks()[0].doneCallbacks,on()||Pn(n)}})),n.on(dt.SUITE_COMPLETED,(function(){!function(){var n=Q().optionalFields()[0];if(!w(n)){var t={};$((function(e){return V(e,(function(e){var u=e.fieldName;if(t.hasOwnProperty(u))t[e.fieldName]&&e.omit();else{var i=n[u];r(i)&&(t[u]=i(),t[e.fieldName]&&e.omit())}return e}))}))}}()})),n.on(dt.REMOVE_FIELD,(function(n){tn().forEach((function(t){un(t,n)&&(t.cancel(),function(n){$((function(t){return V(t,(function(t){return n!==t?t:null}))}))}(t))}))})),n}function Fn(){var n=ht.useX();return n.bus||L(),n.bus}function kn(n){return An(0,"tests",n)}function In(n){return An(1,"tests",n)}function An(n,t,r){var e=ht.useX("hook called outside of a running suite.");r&&[].concat(r).forEach((function(r){v(r)&&(e.exclusion[t][r]=0===n)}))}function Dn(n){for(var t in n)if(!0===n[t])return!0;return!1}function Ln(n){L("Wrong arguments passed to group. Group "+n+".")}function Wn(n){var t=n.asyncTest,e=n.message;if(t&&r(t.then)){var u=Fn().emit,i=Q(),o=ht.bind({stateRef:i},(function(){Z(),u(dt.TEST_COMPLETED,n)}));i=ht.bind({stateRef:i},(function(t){n.isCanceled()||(n.message=v(t)?t:e,n.fail(),o())}));try{t.then(o,i)}catch(n){i()}}}function Un(n){var t=Q().testObjects(),r=t[1],e=t[0].prev;if(w(e))return jn(n),n;if(function(n,t){return rt(n)&&!(n.fieldName===t.fieldName&&n.groupName===t.groupName)}(t=function(n){var t=rn();return z(n,t)[K(t)]}(e),n)){!function(n,t){ht.useX().isolate.type!==_n.EACH&&function(n,t){setTimeout((function(){L(n,t)}),0)}("Vest Critical Error: Tests called in different order than previous run.\n expected: "+n.fieldName+"\n received: "+t.fieldName+"\n This happens when you conditionally call your tests using if/else.\n This might lead to incorrect validation results.\n Replacing if/else with skipWhen solves these issues.")}(t,n),t=z(e,rn());var u=ht.useX().testCursor.cursorAt();t.splice(u),r((function(n){return{prev:e,current:n.current}})),t=null}return jn(n=i(t,n)),n}function jn(n){var t=rn();$((function(r){return z(r,t)[K(t)]=n,r}))}function Rn(n){var t=Un(n);if(function(n){var t=n.fieldName;n=n.groupName;var r=ht.useX();if(r.skipped)return!0;var e=(r=r.exclusion).tests,u=e[t];if(!1===u)return!0;if(u=!0===u,n){n:{var i=ht.useX().exclusion.groups;if(Object.prototype.hasOwnProperty.call(i,n))var o=!1===i[n];else{for(o in i)if(!0===i[o]){o=!0;break n}o=!1}}if(o)return!0;if(!0===r.groups[n])return!(u||!Dn(e)&&!1!==e[t])}return!u&&Dn(e)}(n))return n.skip(),ht.useX().testCursor.next(),t;if(n!==t&&t.fieldName===n.fieldName&&t.groupName===n.groupName&&t.isPending()&&t.cancel(),jn(n),ht.useX().testCursor.next(),n.isUntested()){t=Fn();var e=function(n){return ht.run({currentTest:n},(function(){try{var t=n.testFn()}catch(r){t=r,p(n.message)&&v(t)&&(n.message=r),t=!1}return!1===t&&n.fail(),t}))}(n);try{e&&r(e.then)?(n.asyncTest=e,n.setPending(),Wn(n)):t.emit(dt.TEST_COMPLETED,n)}catch(t){L("Your test function "+n.fieldName+' returned a value. Only "false" or Promise returns are supported.')}}else(t=n.asyncTest)&&r(t.then)&&(n.setPending(),Wn(n));return n}function Xn(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];r=t.reverse(),t=r[0],r=r[1];var e=ht.useX();return Rn(t=new bt(n,t,{message:r,groupName:null==e?void 0:e.groupName}))}var _n,Mn,Gn=function(){return(Gn=Object.assign||function(n){for(var t,r=1,e=arguments.length;r<e;r++)for(var u in t=arguments[r])Object.prototype.hasOwnProperty.call(t,u)&&(n[u]=t[u]);return n}).apply(this,arguments)},qn=Object.assign,Bn=a(c),Kn=a(l),Hn=a(p),Vn=a(d),Jn=a(h),zn=a(g),Yn=a(N),Qn=a(b),Zn=a(C),$n=a(O),nt=a(T),tt=a(S),rt=a(w),et=a(P),ut=a(x),it=a(v),ot=a(F),st=a(I),at=a(A),ct=a(D),ft=W((function(n,t){var r={value:n.value,meta:n.meta||{}};return t?n.set?qn(r,{parent:function(){return t?{value:t.value,meta:t.meta,parent:t.parent}:t}}):t:qn(r,{parent:U})})),lt=qn({condition:function(n,t){try{return t(n)}catch(n){return!1}},doesNotEndWith:Vn,doesNotStartWith:ct,endsWith:d,equals:h,greaterThan:m,greaterThanOrEquals:y,gt:m,gte:y,inside:b,isArray:N,isBetween:C,isBlank:O,isBoolean:T,isEmpty:w,isEven:function(n){return!!g(n)&&0==n%2},isFalsy:ot,isNaN:P,isNegative:x,isNotArray:Yn,isNotBetween:Zn,isNotBlank:$n,isNotBoolean:nt,isNotEmpty:rt,isNotNaN:et,isNotNull:Kn,isNotNumber:tt,isNotNumeric:zn,isNotString:it,isNotUndefined:Hn,isNull:l,isNumber:S,isNumeric:g,isOdd:function(n){return!!g(n)&&0!=n%2},isPositive:ut,isString:v,isTruthy:F,isUndefined:p,lengthEquals:c,lengthNotEquals:Bn,lessThan:k,lessThanOrEquals:E,longerThan:f,longerThanOrEquals:function(n,t){return n.length>=Number(t)},lt:k,lte:E,matches:I,notEquals:Jn,notInside:Qn,notMatches:st,numberEquals:A,numberNotEquals:at,shorterThan:function(n,t){return n.length<Number(t)},shorterThanOrEquals:function(n,t){return n.length<=Number(t)},startsWith:D},{allOf:function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return i(e(t,(function(t,r){(t=s(t,n)).pass||r(t)})),o(!0))},anyOf:function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return i(e(t,(function(t,r){(t=s(t,n)).pass&&r(t)})),o(!1))},noneOf:function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return i(e(t,(function(t,r){s(t,n).pass&&r(o(!1))})),o(!0))},oneOf:function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var e=[];return t.some((function(t){if(f(e,1))return!1;(t=s(t,n)).pass&&e.push(t)})),o(c(e,1))},optional:function(n,t){return p(n)||null===n?o(!0):s(t,n)}},{shape:function(n,t){var r=j(n,t);if(!r.pass)return r;for(var e in n)if(!Object.prototype.hasOwnProperty.call(t,e))return o(!1);return o(!0)},loose:j,isArrayOf:function(n,t){return i(e(n,(function(n,r,e){(e=ft.run({value:n,set:!0,meta:{index:e}},(function(){return s(t,n)}))).pass||r(e)})),o(!0))}}),pt=(Mn=Gn({context:function(){return ft.useX()},extend:function(n){qn(lt,n)}},{partial:q}),X()?new Proxy(qn(M,Mn),{get:function(n,t){return t in n?n[t]:lt[t]?G(t):void 0}}):(R((function(n){Mn[n]=G(n)})),Mn)),vt=function(n){return function(){return""+n++}}(0);!function(n){n[n.DEFAULT=0]="DEFAULT",n[n.SUITE=1]="SUITE",n[n.EACH=2]="EACH",n[n.SKIP_WHEN=3]="SKIP_WHEN",n[n.GROUP=4]="GROUP"}(_n||(_n={}));var dt,ht=W((function(n,t){return t?null:qn({},{isolate:{type:_n.DEFAULT},testCursor:H(),exclusion:{tests:{},groups:{}}},n)})),gt=Y(),mt=Y(20),yt=Y(20),Nt=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var r=(n=n.reverse())[0];if(n=n[1],t=On(),Tn(r,n,t))return t;var e=function(){return r(Cn())};return Sn(n)?(e(),t):(wn(e,n),t)};!function(n){n.TEST_COMPLETED="test_completed",n.REMOVE_FIELD="remove_field",n.SUITE_COMPLETED="suite_completed"}(dt||(dt={})),kn.group=function(n){return An(0,"groups",n)},In.group=function(n){return An(1,"groups",n)};var bt=function(){function n(n,t,r){var e=void 0===r?{}:r;r=e.message,e=e.groupName,this.id=vt(),this.warns=!1,this.status=Et,this.fieldName=n,this.testFn=t,e&&(this.groupName=e),r&&(this.message=r)}return n.prototype.run=function(){try{var n=this.testFn()}catch(t){n=t,p(this.message)&&v(n)&&(this.message=t),n=!1}return!1===n&&this.fail(),n},n.prototype.setStatus=function(n){this.isFinalStatus()&&n!==xt||(this.status=n)},n.prototype.setPending=function(){this.setStatus(wt)},n.prototype.fail=function(){this.setStatus(this.warns?Tt:Ot)},n.prototype.done=function(){this.isFinalStatus()||this.setStatus(St)},n.prototype.warn=function(){this.warns=!0},n.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},n.prototype.skip=function(){this.isPending()||this.setStatus(Ct)},n.prototype.cancel=function(){this.setStatus(Pt),Z()},n.prototype.omit=function(){this.setStatus(xt)},n.prototype.valueOf=function(){return!this.isFailing()},n.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},n.prototype.isPending=function(){return this.status===wt},n.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},n.prototype.isOmitted=function(){return this.status===xt},n.prototype.isUntested=function(){return this.status===Et},n.prototype.isFailing=function(){return this.status===Ot},n.prototype.isCanceled=function(){return this.status===Pt},n.prototype.isSkipped=function(){return this.status===Ct},n.prototype.isPassing=function(){return this.status===St},n.prototype.isWarning=function(){return this.status===Tt},n}(),Et="UNTESTED",Ct="SKIPPED",Ot="FAILED",Tt="WARNING",St="PASSING",wt="PENDING",Pt="CANCELED",xt="OMITTED",Ft=qn(Xn,{each:function(n){return function(r){return N(r)||L("test.each: Expected table to be an array."),function(e){for(var i=[],o=1;o<arguments.length;o++)i[o-1]=arguments[o];var s=(i=i.reverse())[0],a=i[1];return en({type:_n.EACH},(function(){return r.map((function(r){return r=[].concat(r),n(u.apply(void 0,t([e],r)),u.apply(void 0,t([a],r)),(function(){return s.apply(void 0,r)}))}))}))}}}(Xn),memo:function(n){var t=Y(100);return function(r){for(var e=[],u=1;u<arguments.length;u++)e[u-1]=arguments[u];u=Q().suiteId()[0];var i=ht.useX().testCursor.cursorAt(),o=(e=e.reverse())[1],s=e[2];return e=[u,r,i].concat(e[0]),null===(u=t.get(e))?t(e,(function(){return n(r,s,o)})):u[1].isCanceled()?(t.invalidate(e),t(e,(function(){return n(r,s,o)}))):Rn(u[1])}}(Xn)});n.VERSION="4.0.0-dev-31f012",n.create=function(n){r(n)||L("vest.create: Expected callback to be a function.");var t=xn(),e=function(n){function t(n,t,r){return i.references.push(),e(n,u(t,r)),function(){return[i.references[n],function(t){return e(n,u(t,i.references[n]))}]}}function e(t,e){var u=i.references[t];i.references[t]=e,r(t=o[t][1])&&t(e,u),r(n)&&n()}var i={references:[]},o=[];return{registerStateKey:function(n,r){var e=o.length;return o.push([n,r]),t(e,n)},reset:function(){var n=i.references;i.references=[],o.forEach((function(r,e){return t(e,r[0],n[e])}))}}}(),i={stateRef:B(e,{suiteId:vt()}),bus:t};return qn(ht.bind(i,(function(){for(var r=[],u=0;u<arguments.length;u++)r[u]=arguments[u];return e.reset(),en({type:_n.SUITE},(function(){n.apply(void 0,r)})),t.emit(dt.SUITE_COMPLETED),On()})),{get:ht.bind(i,Cn),reset:e.reset,remove:ht.bind(i,(function(n){t.emit(dt.REMOVE_FIELD,n)}))})},n.enforce=pt,n.group=function(n,t){v(n)||Ln("name must be a string"),r(t)||Ln("callback must be a function"),en({type:_n.GROUP},(function(){ht.run({groupName:n},t)}))},n.only=kn,n.optional=function(n){(0,Q().optionalFields()[1])((function(t){if(N(n)||v(n))[].concat(n).forEach((function(n){t[n]=!0}));else for(var r in n)t[r]=n[r];return t}))},n.skip=In,n.skipWhen=function(n,t){en({type:_n.SKIP_WHEN},(function(){ht.run({skipped:u(n)},(function(){return t()}))}))},n.test=Ft,n.warn=function(){var n=ht.useX("warn hook called outside of a running suite.");n.currentTest||L("warn called outside of a test."),n.currentTest.warn()},Object.defineProperty(n,"__esModule",{value:!0})}));
1
+ "use strict";!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("n4s"),require("context")):"function"==typeof define&&define.amd?define(["exports","n4s","context"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).vest={},t.n4s,t.context)}(this,(function(t,n,e){function r(t){return"function"==typeof t}function u(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return r(t)?t.apply(void 0,n):t}function i(t,n){var e;return null!==(e=u(t))&&void 0!==e?e:n}function o(t,n){throw Error(i(n,t))}function s(t,n){setTimeout((function(){o(t,n)}),0)}function a(t){function n(t,n,r){return i.references.push(),e(t,u(n,r)),function(){return[i.references[t],function(n){return e(t,u(n,i.references[t]))}]}}function e(n,e){var u=i.references[n];i.references[n]=e,r(n=o[n][1])&&n(e,u),r(t)&&t()}var i={references:[]},o=[];return{registerStateKey:function(t,e){var r=o.length;return o.push([t,e]),n(r,t)},reset:function(){var t=i.references;i.references=[],o.forEach((function(e,r){return n(r,e[0],t[r])}))}}}function c(t,n){var e=n.suiteId;return n=n.suiteName,{optionalFields:t.registerStateKey((function(){return{}})),suiteId:t.registerStateKey(e),suiteName:t.registerStateKey(n),testCallbacks:t.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:t.registerStateKey((function(t){return{prev:t?t.current:[],current:[]}}))}}function f(t){return(t=[].concat(t))[t.length-1]}function l(){function t(){n=[0]}var n=[];return t(),{addLevel:function(){n.push(0)},cursorAt:function(){return f(n)},getCursor:function(){return[].concat(n)},next:function(){return n[n.length-1]++,f(n)},removeLevel:function(){n.pop()},reset:t}}function p(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return!t.apply(void 0,n)}}function d(t,n){for(var e=[],r=0;r<t.length;r++){var u=t[r];Array.isArray(u)?e.push(d(u,n)):(u=n(u),ht(u)&&e.push(u))}return e}function v(t){return[].concat(t).reduce((function(t,n){return Array.isArray(n)?t.concat(v(n)):[].concat(t).concat(n)}),[])}function g(t,n){var e=0;for(n=n.slice(0,-1);e<n.length;e++){var r=n[e];t[r]=i(t[r],[]),t=t[r]}return t}function h(t){return null==t}function y(t){return String(t)===t}function m(t){void 0===t&&(t=1);var n=[],e=function(r,u){var i=e.get(r);return i?i[1]:(u=u(),n.unshift([r.concat(),u]),n.length>Number(t)&&(n.length=t),u)};return e.invalidate=function(t){var e=n.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}));-1<e&&n.splice(e,1)},e.get=function(t){return n[n.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}))]||null},e}function E(){return gt.useX().stateRef}function b(){return E().testObjects()}function N(){(0,b()[1])((function(t){return{prev:t.prev,current:[].concat(t.current)}}))}function C(t){(0,b()[1])((function(n){return{prev:n.prev,current:[].concat(t(n.current))}}))}function k(){return v(d(b()[0].current,(function(t){return t.isPending()?t:null})))}function T(){var t=b()[0].current;return yt([t],(function(){return v(t)}))}function S(){return gt.useX().testCursor.getCursor()}function O(t,n){if(t=void 0===(t=t.type)?ft.DEFAULT:t,r(n)){var e={current:{},prev:{}},u=S();return gt.run({isolate:{type:t,keys:e}},(function(){gt.useX().testCursor.addLevel(),e.prev=function(){var t=b()[0].prev;return[].concat(g(t,S())).reduce((function(t,n){return n instanceof Et&&!h(n.key)?(t[n.key]=n,t):t}),{})}(),C((function(t){return g(t,u)[f(u)]=[],t}));var t=n();return gt.useX().testCursor.removeLevel(),gt.useX().testCursor.next(),t}))}}function P(t){if(t){if("number"==typeof t)return 0===t;if(Object.prototype.hasOwnProperty.call(t,"length"))return t.length===Number(0);if("object"==typeof t)return Object.keys(t).length===Number(0)}return!0}function w(t,n){return!(!n||t.fieldName!==n)}function F(t){var n=k();return!P(n)&&(t?n.some((function(n){return w(n,t)})):wt(n))}function I(t,n){function e(t,n){i[t]++,u&&(i[n]=(i[n]||[]).concat(u))}var r=n.fieldName,u=n.message;t[r]=t[r]||{errorCount:0,warnCount:0,testCount:0};var i=t[r];return n.isSkipped()||(t[r].testCount++,n.isFailing()?e("errorCount","errors"):n.isWarning()&&e("warnCount","warnings")),i}function A(t,n,e){if(e||2===arguments.length)for(var r,u=0,i=n.length;u<i;u++)!r&&u in n||(r||(r=Array.prototype.slice.call(n,0,u)),r[u]=n[u]);return t.concat(r||n)}function x(t,n,e){var r;void 0===e&&(e={});var u=(e=e||{}).group,i=e.fieldName;return n.reduce((function(n,e){if(u&&e.groupName!==u)var r=!0;else i&&!w(e,i)?r=!0:(r=e.warns(),r="warnings"===t!=!!r);return r||!e.hasFailures()||(n[e.fieldName]=(n[e.fieldName]||[]).concat(e.message||[])),n}),Ft({},i&&((r={})[i]=[],r)))}function X(t){return L("errors",t)}function D(t){return L("warnings",t)}function L(t,n){return t=x(t,T(),{fieldName:n}),n?t[n]:t}function U(t,n){return t=W("errors",t,n),n?t[n]:t}function _(t,n){return t=W("warnings",t,n),n?t[n]:t}function W(t,n,e){return n||o("get"+t[0].toUpperCase()+t.slice(1)+"ByGroup requires a group name. Received `"+n+"` instead."),x(t,T(),{group:n,fieldName:e})}function R(t,n,e){return(e=!t.hasFailures()||e&&!w(t,e))||(e="warnings"===n!=!!(t=t.warns())),!e}function j(t){return M("errors",t)}function G(t){return M("warnings",t)}function M(t,n){return T().some((function(e){return R(e,t,n)}))}function K(t,n){return V("errors",t,n)}function H(t,n){return V("warnings",t,n)}function V(t,n,e){return T().some((function(r){return n===r.groupName&&R(r,t,e)}))}function B(){var t=T(),n={stateRef:E()};return It([t],gt.bind(n,(function(){var t=E().suiteName()[0];return pt(function(){var t={errorCount:0,groups:{},testCount:0,tests:{},warnCount:0};return T().forEach((function(n){var e=n.fieldName,r=n.groupName;t.tests[e]=I(t.tests,n),r&&(t.groups[r]=t.groups[r]||{},t.groups[r][e]=I(t.groups[r],n))})),function(t){for(var n in t.tests)t.errorCount+=t.tests[n].errorCount,t.warnCount+=t.tests[n].warnCount,t.testCount+=t.tests[n].testCount;return t}(t)}(),{getErrors:gt.bind(n,X),getErrorsByGroup:gt.bind(n,U),getWarnings:gt.bind(n,D),getWarningsByGroup:gt.bind(n,_),hasErrors:gt.bind(n,j),hasErrorsByGroup:gt.bind(n,K),hasWarnings:gt.bind(n,G),hasWarningsByGroup:gt.bind(n,H),isValid:gt.bind(n,(function(t){var n=B(),e=T().reduce((function(t,n){return t[n.fieldName]||n.isOmitted()&&(t[n.fieldName]=!0),t}),{});return(e=!!t&&!!e[t])?t=!0:n.hasErrors(t)?t=!1:t=!(P(e=T())||t&&P(n.tests[t])||function(t){var n=E().optionalFields()[0];return wt(k().filter((function(e){return!(t&&!w(e,t))&&!0!==n[e.fieldName]})))}(t))&&function(t){var n=T(),e=E().optionalFields()[0];return n.every((function(n){return!(!t||w(n,t))||!0===e[n.fieldName]||n.isTested()||n.isOmitted()}))}(t),t})),suiteName:t})})))}function q(){var t=T(),n={stateRef:E()};return At([t],gt.bind(n,(function(){return pt({},B(),{done:gt.bind(n,xt)})})))}function Y(t,n,e){return!(r(t)&&(!n||e.tests[n]&&!P(e.tests[n].testCount)))}function z(t){return!(F()&&(!t||F(t)))}function J(t,n){var e=gt.bind({},t);(0,E().testCallbacks()[1])((function(t){return n?t.fieldCallbacks[n]=(t.fieldCallbacks[n]||[]).concat(e):t.doneCallbacks.push(e),t}))}function Q(t){return t.forEach((function(t){return t()}))}function Z(){var t=function(){var t={};return{emit:function(n,e){t[n]&&t[n].forEach((function(t){t(e)}))},on:function(n,e){return t[n]||(t[n]=[]),t[n].push(e),{off:function(){t[n]=t[n].filter((function(t){return t!==e}))}}}}}();return t.on(mt.TEST_COMPLETED,(function(t){if(!t.isCanceled()){t.done(),t=t.fieldName;var n=E().testCallbacks()[0].fieldCallbacks;t&&!F(t)&&Array.isArray(n[t])&&Q(n[t]),t=E().testCallbacks()[0].doneCallbacks,F()||Q(t)}})),t.on(mt.SUITE_COMPLETED,(function(){!function(){var t=E().optionalFields()[0];if(!P(t)){var n={};C((function(e){return d(e,(function(e){var u=e.fieldName;if(n.hasOwnProperty(u))n[e.fieldName]&&e.omit();else{var i=t[u];r(i)&&(n[u]=i(),n[e.fieldName]&&e.omit())}return e}))}))}}()})),t.on(mt.REMOVE_FIELD,(function(t){T().forEach((function(n){w(n,t)&&(n.cancel(),function(t){C((function(n){return d(n,(function(n){return t!==n?n:null}))}))}(n))}))})),t}function $(){var t=gt.useX();return t.bus||o(),t.bus}function tt(t){return et(0,"tests",t)}function nt(t){return et(1,"tests",t)}function et(t,n,e){var r=gt.useX("hook called outside of a running suite.");e&&[].concat(e).forEach((function(e){y(e)&&(r.exclusion[n][e]=0===t)}))}function rt(t){for(var n in t)if(!0===t[n])return!0;return!1}function ut(t){o("Wrong arguments passed to group. Group "+t+".")}function it(t){var n=t.asyncTest,e=t.message;if(n&&r(n.then)){var u=$().emit,i=E(),o=gt.bind({stateRef:i},(function(){N(),u(mt.TEST_COMPLETED,t)}));i=gt.bind({stateRef:i},(function(n){t.isCanceled()||(t.message=y(n)?n:e,t.fail(),o())}));try{n.then(o,i)}catch(t){i()}}}function ot(t){var n=S();C((function(e){return g(e,n)[f(n)]=t,e}))}function st(t){var n=b()[0].prev;if(P(n))ot(t),n=t;else{var e=S();if(n=g(n,e)[f(e)],h(t.key))!wt(e=n)||e.fieldName===t.fieldName&&e.groupName===t.groupName||(gt.useX().isolate.type!==ft.EACH&&s("Vest Critical Error: Tests called in different order than previous run.\n expected: "+n.fieldName+"\n received: "+t.fieldName+'\n This can happen on one of two reasons:\n 1. You\'re using if/else statements to conditionally select tests. Instead, use "skipWhen".\n 2. You are iterating over a list of tests, and their order changed. Use "each" and a custom key prop so that Vest retains their state.'),function(){var t=b(),n=t[1],e=t[0].prev;t=g(e,S());var r=gt.useX().testCursor.cursorAt();t.splice(r),n((function(t){return{prev:e,current:t.current}}))}(),n=null),ot(n=i(n,t));else{n=t.key;var u=gt.useX().isolate.keys.prev[n];e=t,u&&(e=u),u=e;var a=gt.useX().isolate.keys.current;h(a[n])?a[n]=u:s('Encountered the same test key "'+n+"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."),ot(n=e)}}if(function(t){var n=t.fieldName;if(t=t.groupName,gt.useX().skipped)return!0;var e=gt.useX().exclusion,r=e.tests,u=r[n];if(!1===u)return!0;if(u=!0===u,t){t:{var i=gt.useX().exclusion.groups;if(Object.prototype.hasOwnProperty.call(i,t))var o=!1===i[t];else{for(o in i)if(!0===i[o]){o=!0;break t}o=!1}}if(o)return!0;if(!0===e.groups[t])return!(u||!rt(r)&&!1!==r[n])}n=gt.useX().exclusion;t:{for(s in(e=gt.useX().exclusion).groups)if(e.groups[s]){var s=!0;break t}s=!1}return!(!s||t&&t in n.groups&&n.groups[t])||!u&&rt(r)}(t))return n.skip(!!gt.useX().skipped),gt.useX().testCursor.next(),n;if(t!==n&&n.fieldName===t.fieldName&&n.groupName===t.groupName&&n.isPending()&&n.cancel(),ot(t),gt.useX().testCursor.next(),t.isUntested()){n=$(),e=function(t){return gt.run({currentTest:t},(function(){try{var n=t.testFn()}catch(e){n=e,void 0===t.message&&y(n)&&(t.message=e),n=!1}return!1===n&&t.fail(),n}))}(t);try{e&&r(e.then)?(t.asyncTest=e,t.setPending(),it(t)):n.emit(mt.TEST_COMPLETED,t)}catch(n){o("Your test function "+t.fieldName+' returned a value. Only "false" or Promise returns are supported.')}}else(n=t.asyncTest)&&r(n.then)&&(t.setPending(),it(t));return t}function at(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];var u=r(n[1])?n:A([void 0],n);n=u[0],e=u[1],u=u[2],Xt(t)&&ct("fieldName","string"),r(e)||ct("Test callback","function");var i=gt.useX();return st(n=new Et(t,e,{message:n,groupName:i.groupName,key:u}))}function ct(t,n){o("Incompatible params passed to test function. "+t+" must be a "+n)}var ft,lt,pt=Object.assign,dt=(lt=0,function(){return""+lt++});!function(t){t[t.DEFAULT=0]="DEFAULT",t[t.SUITE=1]="SUITE",t[t.EACH=2]="EACH",t[t.SKIP_WHEN=3]="SKIP_WHEN",t[t.GROUP=4]="GROUP"}(ft||(ft={}));var vt,gt=e.createContext((function(t,n){return n?null:pt({},{exclusion:{tests:{},groups:{}},isolate:{type:ft.DEFAULT,keys:{current:{},prev:{}}},testCursor:l()},t)})),ht=p((function(t){return null===t})),yt=m();!function(t){t.Error="error",t.Warning="warning"}(vt||(vt={}));var mt,Et=function(){function t(t,n,e){var r=void 0===e?{}:e;e=r.message;var u=r.groupName;r=r.key,this.key=null,this.id=dt(),this.severity=vt.Error,this.status=bt,this.fieldName=t,this.testFn=n,u&&(this.groupName=u),e&&(this.message=e),r&&(this.key=r)}return t.prototype.run=function(){try{var t=this.testFn()}catch(n){t=n,void 0===this.message&&y(t)&&(this.message=n),t=!1}return!1===t&&this.fail(),t},t.prototype.setStatus=function(t){this.isFinalStatus()&&t!==Pt||(this.status=t)},t.prototype.warns=function(){return this.severity===vt.Warning},t.prototype.setPending=function(){this.setStatus(St)},t.prototype.fail=function(){this.setStatus(this.warns()?kt:Ct)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(Tt)},t.prototype.warn=function(){this.severity=vt.Warning},t.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},t.prototype.skip=function(t){this.isPending()&&!t||this.setStatus(Nt)},t.prototype.cancel=function(){this.setStatus(Ot),N()},t.prototype.omit=function(){this.setStatus(Pt)},t.prototype.valueOf=function(){return!this.isFailing()},t.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},t.prototype.isPending=function(){return this.status===St},t.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},t.prototype.isOmitted=function(){return this.status===Pt},t.prototype.isUntested=function(){return this.status===bt},t.prototype.isFailing=function(){return this.status===Ct},t.prototype.isCanceled=function(){return this.status===Ot},t.prototype.isSkipped=function(){return this.status===Nt},t.prototype.isPassing=function(){return this.status===Tt},t.prototype.isWarning=function(){return this.status===kt},t}(),bt="UNTESTED",Nt="SKIPPED",Ct="FAILED",kt="WARNING",Tt="PASSING",St="PENDING",Ot="CANCELED",Pt="OMITTED",wt=p(P),Ft=function(){return(Ft=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t}).apply(this,arguments)},It=m(20),At=m(20),xt=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=(t=t.reverse())[0];if(t=t[1],n=q(),Y(e,t,n))return n;var r=function(){return e(B())};return z(t)?(r(),n):(J(r,t),n)};!function(t){t.TEST_COMPLETED="test_completed",t.REMOVE_FIELD="remove_field",t.SUITE_COMPLETED="suite_completed"}(mt||(mt={})),tt.group=function(t){return et(0,"groups",t)},nt.group=function(t){return et(1,"groups",t)};var Xt=p(y),Dt=pt(at,{memo:function(t){var n=m(100);return function(e){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];u=gt.useX().testCursor.cursorAt();var i=(r=r.reverse())[0],o=r[1],s=r[2];return u=[E().suiteId()[0],e,u].concat(i),null===(r=n.get(u))?n(u,(function(){return t(e,s,o)})):r[1].isCanceled()?(n.invalidate(u),n(u,(function(){return t(e,s,o)}))):st(r[1])}}(at)});Object.defineProperty(t,"enforce",{enumerable:!0,get:function(){return n.enforce}}),t.VERSION="4.0.0-dev-e266d9",t.create=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=(t=t.reverse())[0];t=t[1],r(e)||o("vest.create: Expected callback to be a function.");var u=Z(),i=a();return t={stateRef:c(i,{suiteId:dt(),suiteName:t}),bus:u},pt(gt.bind(t,(function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return i.reset(),O({type:ft.SUITE},(function(){e.apply(void 0,t)})),u.emit(mt.SUITE_COMPLETED),q()})),{get:gt.bind(t,B),reset:i.reset,remove:gt.bind(t,(function(t){u.emit(mt.REMOVE_FIELD,t)}))})},t.each=function(t,n){r(n)||o("callback must be a function"),O({type:ft.EACH},(function(){t.forEach((function(t,e){n(t,e)}))}))},t.group=function(t,n){y(t)||ut("name must be a string"),r(n)||ut("callback must be a function"),O({type:ft.GROUP},(function(){gt.run({groupName:t},n)}))},t.only=tt,t.optional=function(t){(0,E().optionalFields()[1])((function(n){if(Array.isArray(t)||y(t))[].concat(t).forEach((function(t){n[t]=!0}));else for(var e in t)n[e]=t[e];return n}))},t.skip=nt,t.skipWhen=function(t,n){O({type:ft.SKIP_WHEN},(function(){gt.run({skipped:u(t,u(B))},(function(){return n()}))}))},t.test=Dt,t.warn=function(){var t=gt.useX("warn hook called outside of a running suite.");t.currentTest||o("warn called outside of a test."),t.currentTest.warn()},Object.defineProperty(t,"__esModule",{value:!0})}));
@@ -0,0 +1,7 @@
1
+ {
2
+ "main": "../../dist/cjs/enforce/compose.js",
3
+ "module": "../../dist/es/enforce/compose.production.js",
4
+ "name": "compose",
5
+ "types": "../../types/enforce/compose.d.ts",
6
+ "private": true
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "main": "../../dist/cjs/enforce/compounds.js",
3
+ "module": "../../dist/es/enforce/compounds.production.js",
4
+ "name": "compounds",
5
+ "types": "../../types/enforce/compounds.d.ts",
6
+ "private": true
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "main": "../../dist/cjs/enforce/schema.js",
3
+ "module": "../../dist/es/enforce/schema.production.js",
4
+ "name": "schema",
5
+ "types": "../../types/enforce/schema.d.ts",
6
+ "private": true
7
+ }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.0.0-dev-31f012",
2
+ "version": "4.0.0-dev-e266d9",
3
3
  "license": "MIT",
4
4
  "name": "vest",
5
5
  "author": "ealush",
@@ -19,6 +19,10 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/ealush/vest.git/issues"
21
21
  },
22
+ "dependencies": {
23
+ "context": "next",
24
+ "n4s": "next"
25
+ },
22
26
  "homepage": "https://vestjs.dev/",
23
27
  "exports": {
24
28
  "./classnames": {
@@ -46,10 +50,100 @@
46
50
  "browser": "./dist/es/classnames.production.js",
47
51
  "umd": "./dist/umd/classnames.production.js",
48
52
  "import": "./dist/es/classnames.production.js",
49
- "require": "./dist/cjs/classnames.js",
50
- "node": "./dist/cjs/classnames.js",
53
+ "require": "./dist/cjs/classnames.production.js",
54
+ "node": "./dist/cjs/classnames.production.js",
51
55
  "module": "./dist/es/classnames.production.js",
52
- "default": "./dist/cjs/classnames.js"
56
+ "default": "./dist/cjs/classnames.production.js"
57
+ },
58
+ "./enforce/compose": {
59
+ "production": {
60
+ "types": "./types/enforce/compose.d.ts",
61
+ "browser": "./dist/es/enforce/compose.production.js",
62
+ "umd": "./dist/umd/enforce/compose.production.js",
63
+ "import": "./dist/es/enforce/compose.production.js",
64
+ "require": "./dist/cjs/enforce/compose.production.js",
65
+ "node": "./dist/cjs/enforce/compose.production.js",
66
+ "module": "./dist/es/enforce/compose.production.js",
67
+ "default": "./dist/cjs/enforce/compose.production.js"
68
+ },
69
+ "development": {
70
+ "types": "./types/enforce/compose.d.ts",
71
+ "browser": "./dist/es/enforce/compose.development.js",
72
+ "umd": "./dist/umd/enforce/compose.development.js",
73
+ "import": "./dist/es/enforce/compose.development.js",
74
+ "require": "./dist/cjs/enforce/compose.development.js",
75
+ "node": "./dist/cjs/enforce/compose.development.js",
76
+ "module": "./dist/es/enforce/compose.development.js",
77
+ "default": "./dist/cjs/enforce/compose.development.js"
78
+ },
79
+ "types": "./types/enforce/compose.d.ts",
80
+ "browser": "./dist/es/enforce/compose.production.js",
81
+ "umd": "./dist/umd/enforce/compose.production.js",
82
+ "import": "./dist/es/enforce/compose.production.js",
83
+ "require": "./dist/cjs/enforce/compose.production.js",
84
+ "node": "./dist/cjs/enforce/compose.production.js",
85
+ "module": "./dist/es/enforce/compose.production.js",
86
+ "default": "./dist/cjs/enforce/compose.production.js"
87
+ },
88
+ "./enforce/compounds": {
89
+ "production": {
90
+ "types": "./types/enforce/compounds.d.ts",
91
+ "browser": "./dist/es/enforce/compounds.production.js",
92
+ "umd": "./dist/umd/enforce/compounds.production.js",
93
+ "import": "./dist/es/enforce/compounds.production.js",
94
+ "require": "./dist/cjs/enforce/compounds.production.js",
95
+ "node": "./dist/cjs/enforce/compounds.production.js",
96
+ "module": "./dist/es/enforce/compounds.production.js",
97
+ "default": "./dist/cjs/enforce/compounds.production.js"
98
+ },
99
+ "development": {
100
+ "types": "./types/enforce/compounds.d.ts",
101
+ "browser": "./dist/es/enforce/compounds.development.js",
102
+ "umd": "./dist/umd/enforce/compounds.development.js",
103
+ "import": "./dist/es/enforce/compounds.development.js",
104
+ "require": "./dist/cjs/enforce/compounds.development.js",
105
+ "node": "./dist/cjs/enforce/compounds.development.js",
106
+ "module": "./dist/es/enforce/compounds.development.js",
107
+ "default": "./dist/cjs/enforce/compounds.development.js"
108
+ },
109
+ "types": "./types/enforce/compounds.d.ts",
110
+ "browser": "./dist/es/enforce/compounds.production.js",
111
+ "umd": "./dist/umd/enforce/compounds.production.js",
112
+ "import": "./dist/es/enforce/compounds.production.js",
113
+ "require": "./dist/cjs/enforce/compounds.production.js",
114
+ "node": "./dist/cjs/enforce/compounds.production.js",
115
+ "module": "./dist/es/enforce/compounds.production.js",
116
+ "default": "./dist/cjs/enforce/compounds.production.js"
117
+ },
118
+ "./enforce/schema": {
119
+ "production": {
120
+ "types": "./types/enforce/schema.d.ts",
121
+ "browser": "./dist/es/enforce/schema.production.js",
122
+ "umd": "./dist/umd/enforce/schema.production.js",
123
+ "import": "./dist/es/enforce/schema.production.js",
124
+ "require": "./dist/cjs/enforce/schema.production.js",
125
+ "node": "./dist/cjs/enforce/schema.production.js",
126
+ "module": "./dist/es/enforce/schema.production.js",
127
+ "default": "./dist/cjs/enforce/schema.production.js"
128
+ },
129
+ "development": {
130
+ "types": "./types/enforce/schema.d.ts",
131
+ "browser": "./dist/es/enforce/schema.development.js",
132
+ "umd": "./dist/umd/enforce/schema.development.js",
133
+ "import": "./dist/es/enforce/schema.development.js",
134
+ "require": "./dist/cjs/enforce/schema.development.js",
135
+ "node": "./dist/cjs/enforce/schema.development.js",
136
+ "module": "./dist/es/enforce/schema.development.js",
137
+ "default": "./dist/cjs/enforce/schema.development.js"
138
+ },
139
+ "types": "./types/enforce/schema.d.ts",
140
+ "browser": "./dist/es/enforce/schema.production.js",
141
+ "umd": "./dist/umd/enforce/schema.production.js",
142
+ "import": "./dist/es/enforce/schema.production.js",
143
+ "require": "./dist/cjs/enforce/schema.production.js",
144
+ "node": "./dist/cjs/enforce/schema.production.js",
145
+ "module": "./dist/es/enforce/schema.production.js",
146
+ "default": "./dist/cjs/enforce/schema.production.js"
53
147
  },
54
148
  "./parser": {
55
149
  "production": {
@@ -76,10 +170,10 @@
76
170
  "browser": "./dist/es/parser.production.js",
77
171
  "umd": "./dist/umd/parser.production.js",
78
172
  "import": "./dist/es/parser.production.js",
79
- "require": "./dist/cjs/parser.js",
80
- "node": "./dist/cjs/parser.js",
173
+ "require": "./dist/cjs/parser.production.js",
174
+ "node": "./dist/cjs/parser.production.js",
81
175
  "module": "./dist/es/parser.production.js",
82
- "default": "./dist/cjs/parser.js"
176
+ "default": "./dist/cjs/parser.production.js"
83
177
  },
84
178
  "./promisify": {
85
179
  "production": {
@@ -106,10 +200,10 @@
106
200
  "browser": "./dist/es/promisify.production.js",
107
201
  "umd": "./dist/umd/promisify.production.js",
108
202
  "import": "./dist/es/promisify.production.js",
109
- "require": "./dist/cjs/promisify.js",
110
- "node": "./dist/cjs/promisify.js",
203
+ "require": "./dist/cjs/promisify.production.js",
204
+ "node": "./dist/cjs/promisify.production.js",
111
205
  "module": "./dist/es/promisify.production.js",
112
- "default": "./dist/cjs/promisify.js"
206
+ "default": "./dist/cjs/promisify.production.js"
113
207
  },
114
208
  ".": {
115
209
  "development": {
@@ -126,10 +220,10 @@
126
220
  "browser": "./dist/es/vest.production.js",
127
221
  "umd": "./dist/umd/vest.production.js",
128
222
  "import": "./dist/es/vest.production.js",
129
- "require": "./dist/cjs/vest.js",
130
- "node": "./dist/cjs/vest.js",
223
+ "require": "./dist/cjs/vest.production.js",
224
+ "node": "./dist/cjs/vest.production.js",
131
225
  "module": "./dist/es/vest.production.js",
132
- "default": "./dist/cjs/vest.js"
226
+ "default": "./dist/cjs/vest.production.js"
133
227
  },
134
228
  "./package.json": "./package.json",
135
229
  "./": "./"
@@ -0,0 +1,16 @@
1
+ export default function mockThrowError() {
2
+ const throwErrorDeferred = jest.fn();
3
+ const throwError = jest.fn();
4
+ jest.resetModules();
5
+ jest.mock('throwError', () => ({
6
+ throwErrorDeferred,
7
+ default: throwError,
8
+ }));
9
+ const vest = require('vest');
10
+
11
+ return {
12
+ throwErrorDeferred,
13
+ throwError,
14
+ vest,
15
+ };
16
+ }
@@ -0,0 +1,134 @@
1
+ type DropFirst<T extends unknown[]> = T extends [
2
+ unknown,
3
+ ...infer U
4
+ ] ? U : never;
5
+ type TStringable = string | ((...args: any[]) => string);
6
+ type TRuleReturn = boolean | {
7
+ pass: boolean;
8
+ message?: TStringable;
9
+ };
10
+ type TRuleDetailedResult = {
11
+ pass: boolean;
12
+ message?: string;
13
+ };
14
+ type TArgs = any[];
15
+ type TBaseRules = typeof baseRules;
16
+ type KBaseRules = keyof TBaseRules;
17
+ declare function condition(value: any, callback: (value: any) => TRuleReturn): TRuleReturn;
18
+ declare function endsWith(value: string, arg1: string): boolean;
19
+ declare function equals(value: unknown, arg1: unknown): boolean;
20
+ declare function greaterThan(value: number | string, gt: number | string): boolean;
21
+ declare function greaterThanOrEquals(value: string | number, gte: string | number): boolean;
22
+ declare function inside(value: unknown, arg1: string | unknown[]): boolean;
23
+ // The module is named "isArrayValue" since it
24
+ // is conflicting with a nested npm dependency.
25
+ // We may need to revisit this in the future.
26
+ declare function isArray(value: unknown): value is Array<unknown>;
27
+ declare function isBetween(value: number | string, min: number | string, max: number | string): boolean;
28
+ declare function isBlank(value: unknown): boolean;
29
+ declare function isBoolean(value: unknown): value is boolean;
30
+ declare function isEmpty(value: unknown): boolean;
31
+ declare function isNaN(value: unknown): boolean;
32
+ declare function isNegative(value: number | string): boolean;
33
+ declare function isNull(value: unknown): value is null;
34
+ declare function isNullish(value: any): value is null | undefined;
35
+ declare function isNumber(value: unknown): value is number;
36
+ declare function isNumeric(value: string | number): boolean;
37
+ declare function isStringValue(v: unknown): v is string;
38
+ declare function isTruthy(value: unknown): boolean;
39
+ declare function isUndefined(value?: unknown): boolean;
40
+ declare function lengthEquals(value: string | unknown[], arg1: string | number): boolean;
41
+ declare function lessThan(value: string | number, lt: string | number): boolean;
42
+ declare function lessThanOrEquals(value: string | number, lte: string | number): boolean;
43
+ declare function longerThan(value: string | unknown[], arg1: string | number): boolean;
44
+ declare function longerThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
45
+ declare function matches(value: string, regex: RegExp | string): boolean;
46
+ declare function numberEquals(value: string | number, eq: string | number): boolean;
47
+ declare function shorterThan(value: string | unknown[], arg1: string | number): boolean;
48
+ declare function shorterThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
49
+ declare function startsWith(value: string, arg1: string): boolean;
50
+ declare const baseRules: {
51
+ condition: typeof condition;
52
+ doesNotEndWith: (value: string, arg1: string) => boolean;
53
+ doesNotStartWith: (value: string, arg1: string) => boolean;
54
+ endsWith: typeof endsWith;
55
+ equals: typeof equals;
56
+ greaterThan: typeof greaterThan;
57
+ greaterThanOrEquals: typeof greaterThanOrEquals;
58
+ gt: typeof greaterThan;
59
+ gte: typeof greaterThanOrEquals;
60
+ inside: typeof inside;
61
+ isArray: typeof isArray;
62
+ isBetween: typeof isBetween;
63
+ isBlank: typeof isBlank;
64
+ isBoolean: typeof isBoolean;
65
+ isEmpty: typeof isEmpty;
66
+ isEven: (value: any) => boolean;
67
+ isFalsy: (value: unknown) => boolean;
68
+ isNaN: typeof isNaN;
69
+ isNegative: typeof isNegative;
70
+ isNotArray: (value: unknown) => boolean;
71
+ isNotBetween: (value: string | number, min: string | number, max: string | number) => boolean;
72
+ isNotBlank: (value: unknown) => boolean;
73
+ isNotBoolean: (value: unknown) => boolean;
74
+ isNotEmpty: (value: unknown) => boolean;
75
+ isNotNaN: (value: unknown) => boolean;
76
+ isNotNull: (value: unknown) => boolean;
77
+ isNotNullish: (value: any) => boolean;
78
+ isNotNumber: (value: unknown) => boolean;
79
+ isNotNumeric: (value: string | number) => boolean;
80
+ isNotString: (v: unknown) => boolean;
81
+ isNotUndefined: (value?: unknown) => boolean;
82
+ isNull: typeof isNull;
83
+ isNullish: typeof isNullish;
84
+ isNumber: typeof isNumber;
85
+ isNumeric: typeof isNumeric;
86
+ isOdd: (value: any) => boolean;
87
+ isPositive: (value: string | number) => boolean;
88
+ isString: typeof isStringValue;
89
+ isTruthy: typeof isTruthy;
90
+ isUndefined: typeof isUndefined;
91
+ lengthEquals: typeof lengthEquals;
92
+ lengthNotEquals: (value: string | unknown[], arg1: string | number) => boolean;
93
+ lessThan: typeof lessThan;
94
+ lessThanOrEquals: typeof lessThanOrEquals;
95
+ longerThan: typeof longerThan;
96
+ longerThanOrEquals: typeof longerThanOrEquals;
97
+ lt: typeof lessThan;
98
+ lte: typeof lessThanOrEquals;
99
+ matches: typeof matches;
100
+ notEquals: (value: unknown, arg1: unknown) => boolean;
101
+ notInside: (value: unknown, arg1: string | unknown[]) => boolean;
102
+ notMatches: (value: string, regex: string | RegExp) => boolean;
103
+ numberEquals: typeof numberEquals;
104
+ numberNotEquals: (value: string | number, eq: string | number) => boolean;
105
+ shorterThan: typeof shorterThan;
106
+ shorterThanOrEquals: typeof shorterThanOrEquals;
107
+ startsWith: typeof startsWith;
108
+ };
109
+ type TRules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<TRules<E> & E> & Record<string, (...args: TArgs) => TRules<E> & E> & {
110
+ [P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules<E> & E;
111
+ };
112
+ /* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
113
+ declare global {
114
+ namespace n4s {
115
+ interface IRules<E> extends TRules<E> {
116
+ }
117
+ }
118
+ }
119
+ type TLazyRules = n4s.IRules<TLazyRuleMethods>;
120
+ type TLazy = TLazyRules & TLazyRuleMethods &
121
+ // This is a "catch all" hack to make TS happy while not
122
+ // losing type hints
123
+ Record<string, (...args: any[]) => any>;
124
+ type TLazyRuleMethods = TLazyRuleRunners & {
125
+ message: (message: TLazyMessage) => TLazy;
126
+ };
127
+ type TLazyRuleRunners = {
128
+ test: (value: unknown) => boolean;
129
+ run: (value: unknown) => TRuleDetailedResult;
130
+ };
131
+ type TComposeResult = TLazyRuleRunners & ((value: any) => void);
132
+ type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
133
+ declare function compose(...composites: TLazyRuleRunners[]): TComposeResult;
134
+ export { compose as default };
@@ -0,0 +1,146 @@
1
+ type DropFirst<T extends unknown[]> = T extends [
2
+ unknown,
3
+ ...infer U
4
+ ] ? U : never;
5
+ type TStringable = string | ((...args: any[]) => string);
6
+ type TRuleReturn = boolean | {
7
+ pass: boolean;
8
+ message?: TStringable;
9
+ };
10
+ type TRuleDetailedResult = {
11
+ pass: boolean;
12
+ message?: string;
13
+ };
14
+ type TArgs = any[];
15
+ type TBaseRules = typeof baseRules;
16
+ type KBaseRules = keyof TBaseRules;
17
+ declare function condition(value: any, callback: (value: any) => TRuleReturn): TRuleReturn;
18
+ declare function endsWith(value: string, arg1: string): boolean;
19
+ declare function equals(value: unknown, arg1: unknown): boolean;
20
+ declare function greaterThan(value: number | string, gt: number | string): boolean;
21
+ declare function greaterThanOrEquals(value: string | number, gte: string | number): boolean;
22
+ declare function inside(value: unknown, arg1: string | unknown[]): boolean;
23
+ // The module is named "isArrayValue" since it
24
+ // is conflicting with a nested npm dependency.
25
+ // We may need to revisit this in the future.
26
+ declare function isArray(value: unknown): value is Array<unknown>;
27
+ declare function isBetween(value: number | string, min: number | string, max: number | string): boolean;
28
+ declare function isBlank(value: unknown): boolean;
29
+ declare function isBoolean(value: unknown): value is boolean;
30
+ declare function isEmpty(value: unknown): boolean;
31
+ declare function isNaN(value: unknown): boolean;
32
+ declare function isNegative(value: number | string): boolean;
33
+ declare function isNull(value: unknown): value is null;
34
+ declare function isNullish(value: any): value is null | undefined;
35
+ declare function isNumber(value: unknown): value is number;
36
+ declare function isNumeric(value: string | number): boolean;
37
+ declare function isStringValue(v: unknown): v is string;
38
+ declare function isTruthy(value: unknown): boolean;
39
+ declare function isUndefined(value?: unknown): boolean;
40
+ declare function lengthEquals(value: string | unknown[], arg1: string | number): boolean;
41
+ declare function lessThan(value: string | number, lt: string | number): boolean;
42
+ declare function lessThanOrEquals(value: string | number, lte: string | number): boolean;
43
+ declare function longerThan(value: string | unknown[], arg1: string | number): boolean;
44
+ declare function longerThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
45
+ declare function matches(value: string, regex: RegExp | string): boolean;
46
+ declare function numberEquals(value: string | number, eq: string | number): boolean;
47
+ declare function shorterThan(value: string | unknown[], arg1: string | number): boolean;
48
+ declare function shorterThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
49
+ declare function startsWith(value: string, arg1: string): boolean;
50
+ declare const baseRules: {
51
+ condition: typeof condition;
52
+ doesNotEndWith: (value: string, arg1: string) => boolean;
53
+ doesNotStartWith: (value: string, arg1: string) => boolean;
54
+ endsWith: typeof endsWith;
55
+ equals: typeof equals;
56
+ greaterThan: typeof greaterThan;
57
+ greaterThanOrEquals: typeof greaterThanOrEquals;
58
+ gt: typeof greaterThan;
59
+ gte: typeof greaterThanOrEquals;
60
+ inside: typeof inside;
61
+ isArray: typeof isArray;
62
+ isBetween: typeof isBetween;
63
+ isBlank: typeof isBlank;
64
+ isBoolean: typeof isBoolean;
65
+ isEmpty: typeof isEmpty;
66
+ isEven: (value: any) => boolean;
67
+ isFalsy: (value: unknown) => boolean;
68
+ isNaN: typeof isNaN;
69
+ isNegative: typeof isNegative;
70
+ isNotArray: (value: unknown) => boolean;
71
+ isNotBetween: (value: string | number, min: string | number, max: string | number) => boolean;
72
+ isNotBlank: (value: unknown) => boolean;
73
+ isNotBoolean: (value: unknown) => boolean;
74
+ isNotEmpty: (value: unknown) => boolean;
75
+ isNotNaN: (value: unknown) => boolean;
76
+ isNotNull: (value: unknown) => boolean;
77
+ isNotNullish: (value: any) => boolean;
78
+ isNotNumber: (value: unknown) => boolean;
79
+ isNotNumeric: (value: string | number) => boolean;
80
+ isNotString: (v: unknown) => boolean;
81
+ isNotUndefined: (value?: unknown) => boolean;
82
+ isNull: typeof isNull;
83
+ isNullish: typeof isNullish;
84
+ isNumber: typeof isNumber;
85
+ isNumeric: typeof isNumeric;
86
+ isOdd: (value: any) => boolean;
87
+ isPositive: (value: string | number) => boolean;
88
+ isString: typeof isStringValue;
89
+ isTruthy: typeof isTruthy;
90
+ isUndefined: typeof isUndefined;
91
+ lengthEquals: typeof lengthEquals;
92
+ lengthNotEquals: (value: string | unknown[], arg1: string | number) => boolean;
93
+ lessThan: typeof lessThan;
94
+ lessThanOrEquals: typeof lessThanOrEquals;
95
+ longerThan: typeof longerThan;
96
+ longerThanOrEquals: typeof longerThanOrEquals;
97
+ lt: typeof lessThan;
98
+ lte: typeof lessThanOrEquals;
99
+ matches: typeof matches;
100
+ notEquals: (value: unknown, arg1: unknown) => boolean;
101
+ notInside: (value: unknown, arg1: string | unknown[]) => boolean;
102
+ notMatches: (value: string, regex: string | RegExp) => boolean;
103
+ numberEquals: typeof numberEquals;
104
+ numberNotEquals: (value: string | number, eq: string | number) => boolean;
105
+ shorterThan: typeof shorterThan;
106
+ shorterThanOrEquals: typeof shorterThanOrEquals;
107
+ startsWith: typeof startsWith;
108
+ };
109
+ type TRules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<TRules<E> & E> & Record<string, (...args: TArgs) => TRules<E> & E> & {
110
+ [P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules<E> & E;
111
+ };
112
+ /* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
113
+ declare global {
114
+ namespace n4s {
115
+ interface IRules<E> extends TRules<E> {
116
+ }
117
+ }
118
+ }
119
+ type TLazyRules = n4s.IRules<TLazyRuleMethods>;
120
+ type TLazy = TLazyRules & TLazyRuleMethods &
121
+ // This is a "catch all" hack to make TS happy while not
122
+ // losing type hints
123
+ Record<string, (...args: any[]) => any>;
124
+ type TLazyRuleMethods = TLazyRuleRunners & {
125
+ message: (message: TLazyMessage) => TLazy;
126
+ };
127
+ type TLazyRuleRunners = {
128
+ test: (value: unknown) => boolean;
129
+ run: (value: unknown) => TRuleDetailedResult;
130
+ };
131
+ type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
132
+ declare function allOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
133
+ declare function anyOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
134
+ declare function noneOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
135
+ declare function oneOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
136
+ declare global {
137
+ namespace n4s {
138
+ interface EnforceCustomMatchers<R> {
139
+ allOf: (...args: DropFirst<Parameters<typeof allOf>>) => R;
140
+ anyOf: (...args: DropFirst<Parameters<typeof anyOf>>) => R;
141
+ noneOf: (...args: DropFirst<Parameters<typeof noneOf>>) => R;
142
+ oneOf: (...args: DropFirst<Parameters<typeof oneOf>>) => R;
143
+ }
144
+ }
145
+ }
146
+ export {};