@jivanf/vest
Version:
Declarative Form Validations Framework
3 lines (2 loc) • 24.2 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("n4s"),require("vest-utils"),require("vestjs-runtime"),require("context"),require("@angular/core")):"function"==typeof define&&define.amd?define(["exports","n4s","vest-utils","vestjs-runtime","context","@angular/core"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).vest={},t.n4s,t["vest-utils"],t["vestjs-runtime"],t.context,t.core)}(this,(function(t,e,n,s,i,r){"use strict";const a={Each:"Each",Focused:"Focused",Group:"Group",OmitWhen:"OmitWhen",SkipWhen:"SkipWhen",Suite:"Suite",Test:"Test"};class u{static setOptionalField(t,e,s){const i=t.data.optional,r=i[e];n.assign(i,{[e]:n.assign({},r,s(r))})}static getOptionalField(t,e){var n;return null!==(n=u.getOptionalFields(t)[e])&&void 0!==n?n:{}}static getOptionalFields(t){var e,n;return null!==(n=null===(e=t.data)||void 0===e?void 0:e.optional)&&void 0!==n?n:{}}}var o,c;!function(t){t[t.CUSTOM_LOGIC=0]="CUSTOM_LOGIC",t[t.AUTO=1]="AUTO"}(o||(o={})),t.Modes=void 0,(c=t.Modes||(t.Modes={})).EAGER="EAGER",c.ALL="ALL",c.ONE="ONE";const l=i.createCascade(((e,s)=>s?null:n.assign({inclusion:{},mode:n.tinyState.createTinyState(t.Modes.EAGER),suiteParams:[],testMemoCache:E},e)));function d(){return l.useX().inclusion}function f(){return l.useX().mode()}const E=n.cache(10);function g(t){var i;const r=s.VestRuntime.useAvailableRoot(),a=l.useX().suiteParams,c=null!==(i=null==a?void 0:a[0])&&void 0!==i?i:{};if(n.isArray(t)||n.isStringValue(t))n.asArray(t).forEach((t=>{u.setOptionalField(r,t,(()=>({type:o.AUTO,applied:!!n.hasOwnProperty(c,t)&&e.enforce.isBlank().test(null==c?void 0:c[t]),rule:null})))}));else for(const n in t){const s=t[n];u.setOptionalField(r,n,(()=>({type:o.CUSTOM_LOGIC,rule:s,applied:e.enforce.isBlank().test(s)||!0===s})))}}function N(t){var e,n;if(!t)return!1;const i=s.VestRuntime.useAvailableRoot();return null!==(n=null===(e=u.getOptionalField(i,t))||void 0===e?void 0:e.applied)&&void 0!==n&&n}const T="PENDING",S="INITIAL",p="DONE",R={[T]:T,[S]:S,[p]:p},m={initial:R.INITIAL,states:{[R.DONE]:{},[R.INITIAL]:{[R.PENDING]:R.PENDING,[R.DONE]:R.DONE},[R.PENDING]:{[R.DONE]:R.DONE}}},I=n.StateMachine(m),v={[T]:T,CANCELED:"CANCELED",FAILED:"FAILED",OMITTED:"OMITTED",PASSING:"PASSING",SKIPPED:"SKIPPED",UNTESTED:"UNTESTED",WARNING:"WARNING"},O="RESET",D={initial:v.UNTESTED,states:{"*":{[v.OMITTED]:v.OMITTED,[O]:v.UNTESTED},[v.UNTESTED]:{[v.CANCELED]:v.CANCELED,[v.FAILED]:v.FAILED,[v.PASSING]:v.PASSING,[v.PENDING]:v.PENDING,[v.SKIPPED]:v.SKIPPED,[v.WARNING]:v.WARNING},[v.PENDING]:{[v.CANCELED]:v.CANCELED,[v.FAILED]:v.FAILED,[v.PASSING]:v.PASSING,[v.SKIPPED]:[v.SKIPPED,t=>!0===t],[v.WARNING]:v.WARNING},[v.SKIPPED]:{},[v.FAILED]:{},[v.WARNING]:{},[v.PASSING]:{},[v.CANCELED]:{},[v.OMITTED]:{}}},A=n.StateMachine(D);var _,h,C;function P(t){return t===_.ERRORS?h.ERROR_COUNT:h.WARN_COUNT}function F(t,e,n){const i=Object.assign(Object.assign({},{severity:C.Error,status:A.initial()}),{fieldName:e.fieldName,testFn:e.testFn});e.groupName&&(i.groupName=e.groupName),e.message&&(i.message=e.message);return s.Isolate.create(a.Test,t,i,null!=n?n:null)}!function(t){t.WARNINGS="warnings",t.ERRORS="errors"}(_||(_={})),function(t){t.ERROR_COUNT="errorCount",t.WARN_COUNT="warnCount"}(h||(h={})),function(t){t.Error="error",t.Warning="warning"}(C||(C={}));const y=new r.InjectionToken("VEST_TEST_CONTEXT");var L,W,U,G;!function(t){t.HOOK_CALLED_OUTSIDE="hook called outside of a running suite.",t.EXPECTED_VEST_TEST="Expected value to be an instance of IsolateTest",t.FIELD_NAME_REQUIRED="Field name must be passed",t.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION="Suite must be initialized with a function",t.PROMISIFY_REQUIRE_FUNCTION="Vest.Promisify must be called with a function",t.PARSER_EXPECT_RESULT_OBJECT="Vest parser: expected argument at position 0 to be Vest's result object.",t.WARN_MUST_BE_CALLED_FROM_TEST="Warn must be called from within the body of a test function",t.EACH_CALLBACK_MUST_BE_A_FUNCTION="Each must be called with a function",t.INVALID_PARAM_PASSED_TO_FUNCTION='Incompatible params passed to {fn_name} function. "{param}" must be of type {expected}',t.TESTS_CALLED_IN_DIFFERENT_ORDER='Vest Critical Error: Tests called in different order than previous run.\n expected: {fieldName}\n received: {prevName}\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.',t.UNEXPECTED_TEST_REGISTRATION_ERROR="Unexpected error encountered during test registration.\n Please report this issue to Vest's Github repository.\n Test Object: {testObject}.\n Error: {error}.",t.UNEXPECTED_TEST_RUN_ERROR="Unexpected error encountered during test run. Please report this issue to Vest's Github repository.\n Test Object: {testObject}.",t.INCLUDE_SELF="Trying to call include.when on the same field."}(L||(L={}));class b{static getStatus(t){var e;return null!==(e=t.status)&&void 0!==e?e:S}static setStatus(t,e,n){t.status=this.stateMachine.staticTransition(b.getStatus(t),e,n)}static statusEquals(t,e){return b.getStatus(t)===e}static setPending(t){this.setStatus(t,T)}static setDone(t){this.setStatus(t,p)}static isPending(t){return b.statusEquals(t,T)}}b.stateMachine=I;class V extends b{static getData(t){return n.invariant(t.data),t.data}static is(t){return s.IsolateSelectors.isIsolateType(t,a.Test)}static isX(t){n.invariant(V.is(t),L.EXPECTED_VEST_TEST)}static cast(t){return V.isX(t),t}static warns(t){return V.getData(t).severity===C.Warning}static isOmitted(t){return V.statusEquals(t,v.OMITTED)}static isUntested(t){return V.statusEquals(t,v.UNTESTED)}static isFailing(t){return V.statusEquals(t,v.FAILED)}static isCanceled(t){return V.statusEquals(t,v.CANCELED)}static isSkipped(t){return V.statusEquals(t,v.SKIPPED)}static isPassing(t){return V.statusEquals(t,v.PASSING)}static isWarning(t){return V.statusEquals(t,v.WARNING)}static hasFailures(t){return V.isFailing(t)||V.isWarning(t)}static isNonActionable(t){return V.isSkipped(t)||V.isOmitted(t)||V.isCanceled(t)}static isTested(t){return V.hasFailures(t)||V.isPassing(t)}static awaitsResolution(t){return V.isSkipped(t)||V.isUntested(t)||V.isPending(t)}static isAsyncTest(t){return n.isPromise(V.getData(t).asyncTest)}static fail(t){V.setStatus(t,V.warns(t)?v.WARNING:v.FAILED)}static pass(t){V.setStatus(t,v.PASSING)}static warn(t){V.setData(t,(t=>Object.assign(Object.assign({},t),{severity:C.Warning})))}static setData(t,e){t.data=n.optionalFunctionValue(e,V.getData(t))}static skip(t,e){V.setStatus(t,v.SKIPPED,e)}static cancel(t){V.setStatus(t,v.CANCELED),s.IsolateMutator.abort(t,v.CANCELED)}static omit(t){V.setStatus(t,v.OMITTED)}static reset(t){V.setStatus(t,O)}}function M(t,e){return!!e&&!k(t,e)}function k(t,e){return!(!e||t.fieldName!==e)}function w(t,e){const{groupName:n}=V.getData(t),{groupName:s,fieldName:i}=V.getData(e);return k(V.getData(t),i)&&n===s&&t.key==e.key}function B(t,e){return s.Isolate.create(a.Focused,n.noop,{focusMode:t,match:n.asArray(e).filter(n.isStringValue),matchAll:!0===e})}V.stateMachine=A,function(t){t[t.ONLY=0]="ONLY",t[t.SKIP=1]="SKIP"}(W||(W={}));class j{static isSkipFocused(t,e){return(null==t?void 0:t.data.focusMode)===W.SKIP&&(K(t,e)||!0===t.data.matchAll)}static isOnlyFocused(t,e){return(null==t?void 0:t.data.focusMode)===W.ONLY&&K(t,e)}static isIsolateFocused(t){return s.IsolateSelectors.isIsolateType(t,a.Focused)}}function x(t){return B(W.ONLY,H(t))}function X(t){return B(W.SKIP,H(t))}function H(t){return!1===t?[]:t}function K(t,e){var s,i;return n.isNotEmpty(null==t?void 0:t.data.match)&&(!e||(null===(i=null===(s=null==t?void 0:t.data.match)||void 0===s?void 0:s.includes(e))||void 0===i||i))}class q{constructor(){this.errorCount=0,this.warnCount=0,this.testCount=0,this.pendingCount=0}}class Y extends q{constructor(){super(...arguments),this[U]=[],this[G]=[],this.groups={},this.tests={},this.valid=null}}U=_.ERRORS,G=_.WARNINGS;const z=n.cache(),J=n.cache();function Q(){return s.VestRuntime.useXAppData()}function Z(){return Q().doneCallbacks()}function $(){return Q().fieldCallbacks()}function tt(){return Q().suiteId}function et(){Q().suiteResultCache.invalidate([tt()]),J.invalidate([tt()])}function nt(){const[,,t]=Z(),[,,e]=$();t(),e()}function st(t){s.VestRuntime.useSetHistoryRoot(t),et()}function it(t,e,s){return s?function(t,e,n){var s;return(null===(s=null==t?void 0:t[n])||void 0===s?void 0:s[e])||[]}(t,e,s):function(t,e){const s={},i=P(e);for(const r in t)n.isPositive(t[r][i])&&(s[r]=t[r][e]||[]);return s}(t,e)}function rt(t){const e={getError:i,getErrors:function(e){return at(t,_.ERRORS,e)},getErrorsByGroup:function(e,n){return ut(t,_.ERRORS,e,n)},getMessage:function(t){return i(t)||s(t)},getWarning:s,getWarnings:function(e){return at(t,_.WARNINGS,e)},getWarningsByGroup:function(e,n){return ut(t,_.WARNINGS,e,n)},hasErrors:function(e){return lt(t,h.ERROR_COUNT,e)},hasErrorsByGroup:function(e,n){return ct(t,h.ERROR_COUNT,e,n)},hasWarnings:function(e){return lt(t,h.WARN_COUNT,e)},hasWarningsByGroup:function(e,n){return ct(t,h.WARN_COUNT,e,n)},isPending:function(e){var s;return e?n.greaterThan(null===(s=t.tests[e])||void 0===s?void 0:s.pendingCount,0):n.greaterThan(t.pendingCount,0)},isTested:function(e){var s;return n.isPositive(null===(s=t.tests[e])||void 0===s?void 0:s.testCount)},isValid:function(e){var n;return Boolean(e?null===(n=t.tests[e])||void 0===n?void 0:n.valid:t.valid)},isValidByGroup:function(e,n){const s=t.groups[e];if(!s)return!1;if(n)return ot(s,n);for(const t in s)if(!ot(s,t))return!1;return!0}};return e;function s(e){return dt(_.WARNINGS,t,e)}function i(e){return dt(_.ERRORS,t,e)}}function at(t,e,n){return it(t.tests,e,n)}function ut(t,e,n,s){return it(t.groups[n],e,s)}function ot(t,e){var n;return!!(null===(n=t[e])||void 0===n?void 0:n.valid)}function ct(t,e,s,i){var r,a;const u=t.groups[s];if(!u)return!1;if(i)return n.isPositive(null===(r=u[i])||void 0===r?void 0:r[e]);for(const t in u)if(n.isPositive(null===(a=u[t])||void 0===a?void 0:a[e]))return!0;return!1}function lt(t,e,s){var i;const r=s?null===(i=t.tests[s])||void 0===i?void 0:i[e]:t[e]||0;return n.isPositive(r)}function dt(t,e,n){var s;const i=e[t];return n?null===(s=i.find((t=>k(t,n))))||void 0===s?void 0:s.message:i[0]}class ft{constructor(t,e,n){this.fieldName=t,this.message=e,this.groupName=n}static fromTestObject(t){const{fieldName:e,message:n,groupName:s}=V.getData(t);return new ft(e,n,s)}}class Et{static hasNoTests(t=Et.defaultRoot()){return!t||!s.Walker.has(t,V.is)}static someTests(t,e=Et.defaultRoot()){return!!e&&s.Walker.some(e,(e=>(V.isX(e),t(e))),V.is)}static everyTest(t,e=Et.defaultRoot()){return!!e&&s.Walker.every(e,(e=>(V.isX(e),t(e))),V.is)}static walkTests(t,e=Et.defaultRoot()){e&&s.Walker.walk(e,((e,n)=>{t(V.cast(e),n)}),V.is)}static reduceTests(t,e,n=Et.defaultRoot()){return n?s.Walker.reduce(n,((e,n,s)=>t(e,V.cast(n),s)),e,V.is):e}static pluckTests(t,e=Et.defaultRoot()){e&&s.Walker.pluck(e,(e=>(V.isX(e),t(e))),V.is)}static resetField(t){Et.walkTests((e=>{k(V.getData(e),t)&&V.reset(e)}),Et.defaultRoot())}static removeTestByFieldName(t,e=Et.defaultRoot()){Et.pluckTests((e=>k(V.getData(e),t)),e)}}Et.defaultRoot=s.VestRuntime.useAvailableRoot;class gt{static useHasPending(t){if(!gt.defaultRoot())return!1;const e=gt.usePreAggs().pending;return!n.isEmpty(e)&&e.some(n.Predicates.all(null==t||t))}static usePreAggs(){return t=Nt,(0,Q().preAggCache)([tt()],t);var t}static useHasRemainingWithTestNameMatching(t){return gt.useHasPending(n.Predicates.any(n.isNullish(t),n.Predicates.all(V.is,(e=>function(t,e){return!e||k(t,e)}(V.getData(e),t)))))}}function Nt(){const t=gt.defaultRoot(),e={pending:[],failures:{errors:{},warnings:{}}};return t?s.Walker.reduce(t,((t,e)=>{var n,s;if(b.isPending(e)&&t.pending.push(e),V.is(e)){const i=V.getData(e).fieldName;V.isWarning(e)&&(t.failures.warnings[i]=null!==(n=t.failures.warnings[i])&&void 0!==n?n:[],t.failures.warnings[i].push(e)),V.isFailing(e)&&(t.failures.errors[i]=null!==(s=t.failures.errors[i])&&void 0!==s?s:[],t.failures.errors[i].push(e))}return t}),e):e}gt.defaultRoot=s.VestRuntime.useAvailableRoot;const Tt=n.bindNot((function(t,e){return V.getData(t).groupName===e}));function St(t){return function(t,e){const s=gt.usePreAggs().failures;if(n.isEmpty(s[t]))return!1;if(e)return!n.isEmpty(s[t][e]);return!0}(_.ERRORS,t)}function pt(t,e,s){return Et.someTests((i=>!Tt(i,e)&&function(t,e,s){if(!V.hasFailures(t))return!1;if(M(V.getData(t),s))return!1;if(function(t,e){return n.either(t===_.WARNINGS,V.warns(e))}(e,t))return!1;return!0}(i,t,s)))}function Rt(t){return!!N(t)||!Et.hasNoTests()&&(!St(t)&&(!function(t){return gt.useHasPending(n.Predicates.all(V.is,(e=>!M(V.getData(e),t)),(()=>!N(t))))}(t)&&function(t){return Et.everyTest((e=>It(e,t)))}(t)))}function mt(t,e){return!!N(e)||!pt(_.ERRORS,t,e)&&(!function(t,e){return gt.useHasPending(n.Predicates.all(V.is,(e=>!Tt(e,t)),(t=>!M(V.getData(t),e)),(()=>!N(e))))}(t,e)&&function(t,e){return Et.everyTest((n=>!!Tt(n,t)||It(n,e)))}(t,e))}function It(t,e){return!!M(V.getData(t),e)||(V.isOmitted(t)||V.isTested(t)||function(t){const e=s.VestRuntime.useAvailableRoot(),{fieldName:n}=V.getData(t);return u.getOptionalField(e,n).type===o.AUTO&&V.awaitsResolution(t)}(t))}function vt(){const t=Et.reduceTests(((t,e)=>{const n=V.getData(e).fieldName;return t.tests[n]=function(t,e){const n=V.getData(e).fieldName,s=Ot(t[n],e);return s.valid=!1!==s.valid&&Rt(n),s}(t.tests,e),t.groups=function(t,e){const{groupName:n,fieldName:s}=V.getData(e);if(!n)return t;t[n]=t[n]||{};const i=t[n];return i[s]=Ot(i[s],e),i[s].valid=!1!==i[s].valid&&mt(n,s),t}(t.groups,e),V.isOmitted(e)?t:(!1===t.tests[n].valid&&(t.valid=!1),function(t,e){V.isWarning(t)?(e.warnCount++,e.warnings.push(ft.fromTestObject(t))):V.isFailing(t)&&(e.errorCount++,e.errors.push(ft.fromTestObject(t)));V.isPending(t)&&e.pendingCount++;At(t)&&e.testCount++;return e}(e,t))}),new Y);return t.valid=!1!==t.valid&&Rt(),t}function Ot(t,e){const{message:s}=V.getData(e),i=n.defaultTo(t?Object.assign({},t):null,Dt);return V.isNonActionable(e)||(V.isPending(e)&&i.pendingCount++,V.isFailing(e)?r(_.ERRORS):V.isWarning(e)&&r(_.WARNINGS),At(e)&&i.testCount++),i;function r(t){const e=P(t);i[e]++,s&&(i[t]=(i[t]||[]).concat(s))}}function Dt(){return n.assign(new q,{errors:[],valid:!0,warnings:[]})}function At(t){return V.isTested(t)||V.isPending(t)}function _t(){return t=()=>{const t=vt(),e=Q().suiteName;return Object.freeze(ht(t,e))},(0,Q().suiteResultCache)([tt()],t);var t}function ht(t,e){return n.assign(t,rt(t),{suiteName:e})}function Ct(){const t=ht(new Y);return new Proxy(t,{get:(t,e)=>_t()[e]})}function Pt(t,e){s.Isolate.create(a.SkipWhen,(()=>{l.run({skipped:Ft()||n.optionalFunctionValue(t,Ct())},e)}))}function Ft(){return function(){var t;return null!==(t=l.useX().skipped)&&void 0!==t&&t}()}function yt(t,e){return n.isNotNullish(s.Walker.findClosest(t,(t=>!!j.isIsolateFocused(t)&&j.isOnlyFocused(t,e))))}function Lt(t){const{fieldName:e}=V.getData(t);if(Ft())return!0;const i=d(),r=function(t){return s.Walker.findClosest(t,(e=>{var n;if(!j.isIsolateFocused(e))return!1;const{fieldName:s}=V.getData(t);return(null===(n=e.data.match)||void 0===n?void 0:n.includes(s))||e.data.matchAll}))}(t);if(j.isSkipFocused(r))return!0;return!j.isOnlyFocused(r)&&(!!yt(t)&&!n.optionalFunctionValue(i[e],t))}function Wt(t){const[e]=f();return e===t}function Ut(e){return Wt(t.Modes.ONE)?St():!!Wt(t.Modes.EAGER)&&St(e.fieldName)}function Gt(t,e){s.Isolate.create(a.OmitWhen,(()=>{l.run({omitted:bt()||n.optionalFunctionValue(t,Ct())},e)}))}function bt(){return function(){var t;return null!==(t=l.useX().omitted)&&void 0!==t&&t}()}function Vt(t,e=t){const n=V.getData(t);return Ut(n)?(s=t,V.skip(s),s):(i=n.fieldName,bt()||N(i)?function(t){return V.omit(t),t}(t):Lt(t)?function(t){return V.skip(t,Ft()),t}(e):t);var s,i}function Mt(t,e){return V.is(e)&&!w(e,t)}const kt=[class{static match(t,e){return V.is(t)&&V.is(e)}static reconcile(t,e){const i=Vt(t,function(t,e){if(s.IsolateInspector.usesKey(t))return function(t){return V.cast(s.Reconciler.handleIsolateNodeWithKey(t,(e=>!!V.isNonActionable(e)||!Lt(t))))}(t);if(s.Reconciler.dropNextNodesOnReorder(Mt,t,e))return function(t,e){if(s.IsolateInspector.canReorder(t))return;n.deferThrow(n.text(L.TESTS_CALLED_IN_DIFFERENT_ORDER,{fieldName:V.getData(t).fieldName,prevName:V.is(e)?V.getData(e).fieldName:void 0}))}(t,e),t;if(!V.is(e))return t;if(V.isOmitted(e))return t;return e}(t,e));return function(t,e,n){t===e&&V.is(e)&&(i=e)!==(s=n)&&w(s,i)&&V.isPending(s)&&V.cancel(s);var s,i}(i,t,e),i}}];function wt(t,e){var n,s;return null!==(s=null===(n=kt.find((n=>n.match(t,e))))||void 0===n?void 0:n.reconcile(t,e))&&void 0!==s?s:null}function Bt(...t){const[e,n]=t.reverse();return s.Isolate.create(a.Group,(()=>l.run(Object.assign({},n&&{groupName:n}),e)))}function jt(t){n.invariant(n.isStringValue(t));return d()[t]=!0,{when:function(e){n.invariant(e!==t,L.INCLUDE_SELF);const s=d();s[t]=function(t){return n.isStringValue(e)?yt(t,e):n.optionalFunctionValue(e,n.optionalFunctionValue(_t))}}}}function xt(t){if(Vt(t),V.isUntested(t))return function(t){const e=function(t){return l.run({currentTest:t},(()=>{var e;let s;const{message:i,testFn:a}=V.getData(t),u=null!==(e=r.inject(r.Injector,{optional:!0}))&&void 0!==e?e:void 0,o=r.Injector.create({providers:[{provide:y,useValue:t}],parent:u});try{r.runInInjectionContext(o,(()=>{s=a({signal:t.abortController.signal})}))}catch(e){(function(t,e){return n.isUndefined(t)&&n.isStringValue(e)})(i,e)&&(V.getData(t).message=e),s=!1}return!1===s&&V.fail(t),s}))}(t);try{if(n.isPromise(e))return V.getData(t).asyncTest=e,function(t){const{asyncTest:e,message:i}=V.getData(t);if(!n.isPromise(e))return;const r=s.VestRuntime.persist((()=>{Xt(t)})),a=s.VestRuntime.persist((e=>{V.isCanceled(t)||(V.getData(t).message=n.isStringValue(e)?e:i,V.fail(t),r())}));return e.then(r,a)}(t);Xt(t)}catch(e){throw new Error(n.text(L.UNEXPECTED_TEST_REGISTRATION_ERROR,{testObject:JSON.stringify(t),error:e}))}}(t);V.isNonActionable(t)||n.deferThrow(n.text(L.UNEXPECTED_TEST_REGISTRATION_ERROR,{testObject:JSON.stringify(t)}))}function Xt(t){V.pass(t)}function Ht(t,...e){const[i,r,a]=n.isFunction(e[1])?e:[void 0,...e];!function(t,e){const s="test";n.invariant(n.isStringValue(t),n.text(L.INVALID_PARAM_PASSED_TO_FUNCTION,{fn_name:s,param:"fieldName",expected:"string"})),n.invariant(n.isFunction(e),n.text(L.INVALID_PARAM_PASSED_TO_FUNCTION,{fn_name:s,param:"callback",expected:"function"}))}(t,r);const u={fieldName:t,groupName:l.useX().groupName,message:i,testFn:r};return s.Bus.useEmit("TEST_RUN_STARTED"),F(xt,u,a)}const Kt=n.assign(Ht,{memo:function(t){return function(e,...i){const[r,a,u]=i.reverse();return function(t,e){const i=l.useX().testMemoCache,r=i.get(t);if(n.isNull(r))return i(t,e);const[,a]=r;if(V.isCanceled(a))return i.invalidate(t),i(t,e);return s.VestRuntime.useSetNextIsolateChild(a),a}([tt(),e,s.VestRuntime.useCurrentCursor()].concat(r),(function(){return t(e,u,a)}))}}(Ht)});function qt(){return{group:Bt,include:jt,omitWhen:Gt,only:x,optional:g,skip:X,skipWhen:Pt,test:Kt}}function Yt(){const t=s.VestRuntime.useAvailableRoot(),e=u.getOptionalFields(t);if(n.isEmpty(e))return;const i=new Set;function r(e){const{fieldName:n}=V.getData(e);i.has(n)&&(V.omit(e),u.setOptionalField(t,n,(t=>Object.assign(Object.assign({},t),{applied:!0}))))}Et.walkTests((e=>{if(V.isPending(e))return;const{fieldName:s}=V.getData(e);i.has(s)?r(e):function(e){const{fieldName:s}=V.getData(e),a=u.getOptionalField(t,s);!0===n.optionalFunctionValue(a.rule)&&i.add(s);r(e)}(e)})),s.Bus.useEmit("DONE_TEST_OMISSION_PASS")}function zt(){const t=s.Bus.useBus();return e("TEST_COMPLETED",(()=>{})),e("TEST_RUN_STARTED",(()=>{})),t.on(s.RuntimeEvents.ISOLATE_PENDING,(t=>{V.is(t)&&V.setPending(t),b.setPending(t)})),t.on(s.RuntimeEvents.ISOLATE_DONE,(e=>{V.is(e)&&t.emit("TEST_COMPLETED",e),b.setDone(e)})),t.on(s.RuntimeEvents.ASYNC_ISOLATE_DONE,(e=>{if(V.is(e)&&!V.isCanceled(e)){const{fieldName:t}=V.getData(e);!function(t){const[e]=$();t&&!gt.useHasRemainingWithTestNameMatching(t)&&n.isArray(e[t])&&n.callEach(e[t])}(t)}gt.useHasPending()||t.emit("ALL_RUNNING_TESTS_FINISHED")})),e("DONE_TEST_OMISSION_PASS",(()=>{})),t.on("ALL_RUNNING_TESTS_FINISHED",(()=>{Et.someTests(V.isAsyncTest)&&Yt(),function(){const[t]=Z();n.callEach(t)}()})),e("RESET_FIELD",(t=>{Et.resetField(t)})),e("SUITE_RUN_STARTED",(()=>{nt()})),e("SUITE_CALLBACK_RUN_FINISHED",(()=>{gt.useHasPending()||t.emit("ALL_RUNNING_TESTS_FINISHED"),Yt()})),e("REMOVE_FIELD",(t=>{Et.removeTestByFieldName(t)})),e("RESET_SUITE",(()=>{nt(),s.VestRuntime.reset()})),{subscribe:function(...e){const[n,s]=e.reverse();return t.on(null!=s?s:"*",(()=>{n()})).off}};function e(e,n){t.on(e,((...t)=>{et(),n(...t)}))}}function Jt(){return n.freezeAssign({done:s.VestRuntime.persist(Qt)},_t())}function Qt(...t){const[e,s]=t.reverse(),i=Jt();if(function(t,e,s){var i,r;return!!(!n.isFunction(t)||e&&n.numberEquals(null!==(r=null===(i=s.tests[e])||void 0===i?void 0:i.testCount)&&void 0!==r?r:0,0))}(e,s,i))return i;const r=()=>e(_t());return gt.useHasRemainingWithTestNameMatching(s)?(function(t,e){const[,s]=$(),[,i]=Z();e?s((s=>n.assign(s,{[e]:(s[e]||[]).concat(t)}))):i((e=>e.concat(t)))}(r,s),i):(r(),i)}function Zt(...t){const[e,i]=n.asArray(t).reverse();!function(t){n.invariant(n.isFunction(t),L.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION)}(e);const r=function({suiteName:t,VestReconciler:e}){const i={doneCallbacks:n.tinyState.createTinyState((()=>[])),fieldCallbacks:n.tinyState.createTinyState((()=>({}))),preAggCache:J,suiteId:n.seq(),suiteName:t,suiteResultCache:z};return s.VestRuntime.createRef(e,i)}({suiteName:i,VestReconciler:wt});function u(...t){return l.run({suiteParams:t},(()=>{return s.Bus.useEmit("SUITE_RUN_STARTED"),n=function(t,...e){const n=s.Bus.useEmit();return()=>(t(...e),n("SUITE_CALLBACK_RUN_FINISHED"),Jt())}(e,...t),s.Isolate.create(a.Suite,n,{optional:{}});var n})).output}const o=$t(...t);return s.VestRuntime.Run(r,(()=>{const t=zt();return n.assign(s.VestRuntime.persist(u),Object.assign(Object.assign({dump:s.VestRuntime.persist((()=>s.VestRuntime.useAvailableRoot())),get:s.VestRuntime.persist(_t),remove:s.Bus.usePrepareEmitter("REMOVE_FIELD"),reset:s.Bus.usePrepareEmitter("RESET_SUITE"),resetField:s.Bus.usePrepareEmitter("RESET_FIELD"),resume:s.VestRuntime.persist(st),runStatic:(...t)=>o(...t),subscribe:t.subscribe},(e=s.VestRuntime.persist(_t),{getError:(...t)=>e().getError(...t),getErrors:(...t)=>e().getErrors(...t),getErrorsByGroup:(...t)=>e().getErrorsByGroup(...t),getMessage:(...t)=>e().getMessage(...t),getWarning:(...t)=>e().getWarning(...t),getWarnings:(...t)=>e().getWarnings(...t),getWarningsByGroup:(...t)=>e().getWarningsByGroup(...t),hasErrors:(...t)=>e().hasErrors(...t),hasErrorsByGroup:(...t)=>e().hasErrorsByGroup(...t),hasWarnings:(...t)=>e().hasWarnings(...t),hasWarningsByGroup:(...t)=>e().hasWarningsByGroup(...t),isPending:(...t)=>e().isPending(...t),isTested:(...t)=>e().isTested(...t),isValid:(...t)=>e().isValid(...t),isValidByGroup:(...t)=>e().isValidByGroup(...t)})),qt()));var e}))}function $t(...t){return n.assign(((...e)=>{const s=Zt(...t),i=s(...e);return n.assign(new Promise((t=>{i.done((e=>{t(r(e))}))})),r(i));function r(t){return n.assign({dump:s.dump},t)}}),Object.assign({},qt()))}const te=L.WARN_MUST_BE_CALLED_FROM_TEST;Object.defineProperty(t,"enforce",{enumerable:!0,get:function(){return e.enforce}}),t.VEST_TEST_CONTEXT=y,t.create=Zt,t.each=function(t,e){n.invariant(n.isFunction(e),L.EACH_CALLBACK_MUST_BE_A_FUNCTION),function(t){s.Isolate.create(a.Each,t,{allowReorder:!0})}((()=>{t.forEach(((t,n)=>{e(t,n)}))}))},t.group=Bt,t.include=jt,t.mode=function(t){const[,e]=f();e(t)},t.omitWhen=Gt,t.only=x,t.optional=g,t.registerReconciler=function(t){kt.includes(t)||kt.push(t)},t.skip=X,t.skipWhen=Pt,t.staticSuite=$t,t.suiteSelectors=rt,t.test=Kt,t.warn=function(){const t=(e=L.HOOK_CALLED_OUTSIDE,l.useX(e).currentTest);var e;n.invariant(t,te),V.warn(t)}}));
//# sourceMappingURL=vest.production.js.map