vest 5.0.0-dev-040354 → 5.0.0-dev-9c596e
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.
- package/LICENSE +2 -2
- package/README.md +2 -57
- package/dist/cjs/classnames.development.js +38 -17
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +5 -54
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +20 -83
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +19 -82
- package/dist/cjs/enforce/schema.production.js +1 -1
- package/dist/cjs/parser.development.js +31 -9
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/promisify.development.js +22 -9
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +1421 -1223
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +40 -19
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +1 -58
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/enforce/compounds.development.js +2 -90
- package/dist/es/enforce/compounds.production.js +1 -1
- package/dist/es/enforce/schema.development.js +2 -88
- package/dist/es/enforce/schema.production.js +1 -1
- package/dist/es/parser.development.js +32 -10
- package/dist/es/parser.production.js +1 -1
- package/dist/es/promisify.development.js +23 -10
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +1415 -1214
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +41 -20
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +9 -57
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +32 -94
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +32 -94
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +34 -12
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/promisify.development.js +25 -12
- package/dist/umd/promisify.production.js +1 -1
- package/dist/umd/vest.development.js +1423 -1225
- package/dist/umd/vest.production.js +1 -1
- package/package.json +12 -16
- package/testUtils/TVestMock.ts +7 -0
- package/testUtils/__tests__/partition.test.ts +4 -4
- package/testUtils/mockThrowError.ts +4 -2
- package/testUtils/suiteDummy.ts +4 -1
- package/testUtils/testDummy.ts +12 -10
- package/testUtils/testPromise.ts +3 -0
- package/types/classnames.d.ts +63 -12
- package/types/classnames.d.ts.map +1 -0
- package/types/enforce/compose.d.ts +2 -126
- package/types/enforce/compose.d.ts.map +1 -0
- package/types/enforce/compounds.d.ts +2 -136
- package/types/enforce/compounds.d.ts.map +1 -0
- package/types/enforce/schema.d.ts +2 -144
- package/types/enforce/schema.d.ts.map +1 -0
- package/types/parser.d.ts +69 -18
- package/types/parser.d.ts.map +1 -0
- package/types/promisify.d.ts +60 -42
- package/types/promisify.d.ts.map +1 -0
- package/types/vest.d.ts +246 -243
- package/types/vest.d.ts.map +1 -0
- package/CHANGELOG.md +0 -87
- package/testUtils/expandStateRef.ts +0 -8
- package/testUtils/runCreateRef.ts +0 -10
- package/testUtils/testObjects.ts +0 -6
- package/tsconfig.json +0 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("n4s"),require("vest-utils"),require("context")):"function"==typeof define&&define.amd?define(["exports","n4s","vest-utils","context"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).vest={},t.n4s,t["vest-utils"],t.context)}(this,(function(t,n,e,r){function i(){var t=0;return{current:function(){return t},next:function(){t++}}}function u(t,n){return void 0===n&&(n=[]),{cursor:i(),keys:{current:{},prev:{}},path:n,type:t}}function s(){return rt.useX().stateRef}function o(t,n){(0,s().optionalFields()[1])((function(r){var i;return e.assign(r,((i={})[t]=e.assign({},r[t],n(r[t])),i))}))}function a(t){var n;return null!==(n=s().optionalFields()[0][t])&&void 0!==n?n:{}}function c(){f((function(t){return t}))}function f(t){(0,s().testObjects()[1])((function(n){return{prev:n.prev,current:e.asArray(t(n.current))}}))}function l(){return d().filter((function(t){return t.isPending()}))}function d(){var t=s().testObjects()[0].current;return it([t],(function(){return e.nestedArray.flatten(t)}))}function p(t){function n(t,n,u){return i.references.push(),r(t,e.optionalFunctionValue(n,u)),function(){return[i.references[t],function(n){return r(t,e.optionalFunctionValue(n,i.references[t]))}]}}function r(n,r){var s=i.references[n];i.references[n]=r,n=u[n][1],e.isFunction(n)&&n(r,s),e.isFunction(t)&&t()}var i={references:[]},u=[];return{registerStateKey:function(t,e){var r=u.length;return u.push([t,e]),n(r,t)},reset:function(){var t=i.references;i.references=[],u.forEach((function(e,r){return n(r,e[0],t[r])}))}}}function v(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 E(){return rt.useX().isolate}function h(){var t=E();return t.path.concat(t.cursor.current())}function g(t,n){t=void 0===(t=t.type)?$.DEFAULT:t,e.invariant(e.isFunction(n));var r=u(t,h());return t=rt.run({isolate:r},(function(){return r.keys.prev=function(){var t=s().testObjects()[0].prev;return e.asArray(e.nestedArray.getCurrent(t,h())).reduce((function(t,n){return n instanceof ot&&!e.isNullish(n.key)?(t[n.key]=n,t):t}),{})}(),f((function(t){return e.nestedArray.setValueAtPath(t,r.path,[])})),n()})),E().cursor.next(),t}function N(t,n){return!(!n||t.fieldName!==n)}function m(t,n){return d().some((function(e){return y(e,t,n)}))}function y(t,n,r){return!(!t.hasFailures()||r&&!N(t,r)||e.either(n===ut.WARNINGS,t.warns()))}function R(t){return!!t&&a(t).applied}function S(t){if(R(t))return!0;var n=d();return!(e.isEmpty(n)||m(ut.ERRORS,t)||function(t){return e.isNotEmpty(l().filter((function(n){return T(n,t)})))}(t))&&function(t){return d().every((function(n){return C(n,t)}))}(t)}function T(t,n){return!(n&&!N(t,n))&&R(n)}function C(t,n){return!(!n||N(t,n))||(a(t.fieldName).type===ht.Delayed&&t.awaitsResolution()||t.isTested()||t.isOmitted())}function O(){var t=d(),n=e.assign({errorCount:0,warnCount:0,testCount:0},{groups:{},tests:{},valid:!1});return t.reduce((function(t,n){var r=t.tests;r[n.fieldName]=A(r,n),r[n.fieldName].valid=!1!==r[n.fieldName].valid&&S(n.fieldName);var i=t.groups,u=n.groupName;return u&&(i[u]=i[u]||{},i[u][n.fieldName]=A(i[u],n),r=i[u][n.fieldName],!1===i[u][n.fieldName].valid?n=!1:n=!!R(n=n.fieldName)||!function(t,n,e){return d().some((function(r){return!gt(r,n)&&y(r,t,e)}))}(ut.ERRORS,u,n)&&!function(t,n){return e.isNotEmpty(l().filter((function(e){return!gt(e,t)&&T(e,n)})))}(u,n)&&function(t,n){return d().every((function(e){return!!gt(e,t)||C(e,n)}))}(u,n),r.valid=n),t}),n),n.valid=S(),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}(n)}function A(t,n){function r(t){s[t===ut.ERRORS?st.ERROR_COUNT:st.WARN_COUNT]++,u&&(s[t]=(s[t]||[]).concat(u))}var i=n.fieldName,u=n.message;t[i]=t[i]||e.assign({errorCount:0,warnCount:0,testCount:0},{errors:[],warnings:[]});var s=t[i];return n.isNonActionable()||(t[i].testCount++,n.isFailing()?r(ut.ERRORS):n.isWarning()&&r(ut.WARNINGS)),s}function _(t,n,r){if(r){var i;t=(null===(i=null==t?void 0:t[r])||void 0===i?void 0:i[n])||[]}else{for(var u in i={},r=n===ut.ERRORS?st.ERROR_COUNT:st.WARN_COUNT,t)e.isPositive(t[u][r])&&(i[u]=t[u][n]||[]);t=i}return t}function b(t){return{getErrors:function(n){return _(t.tests,ut.ERRORS,n)},getErrorsByGroup:function(n,e){return _(t.groups[n],ut.ERRORS,e)},getWarnings:function(n){return _(t.tests,ut.WARNINGS,n)},getWarningsByGroup:function(n,e){return _(t.groups[n],ut.WARNINGS,e)},hasErrors:function(n){return k(t,st.ERROR_COUNT,n)},hasErrorsByGroup:function(n,e){return I(t,st.ERROR_COUNT,n,e)},hasWarnings:function(n){return k(t,st.WARN_COUNT,n)},hasWarningsByGroup:function(n,e){return I(t,st.WARN_COUNT,n,e)},isValid:function(n){var e;return n?!(null===(e=t.tests[n])||void 0===e||!e.valid):t.valid},isValidByGroup:function(n,e){if(!(n=t.groups[n]))return!1;if(e)return F(n,e);for(var r in n)if(!F(n,r))return!1;return!0}}}function F(t,n){var e;return!(null===(e=t[n])||void 0===e||!e.valid)}function I(t,n,r,i){var u,s;if(!(t=t.groups[r]))return!1;if(i)return e.isPositive(null===(u=t[i])||void 0===u?void 0:u[n]);for(var o in t)if(e.isPositive(null===(s=t[o])||void 0===s?void 0:s[n]))return!0;return!1}function k(t,n,r){var i;return t=r?null===(i=t.tests[r])||void 0===i?void 0:i[n]:t[n]||0,e.isPositive(t)}function P(){var t=d(),n={stateRef:s()};return mt([t],rt.bind(n,(function(){var t=O(),n=s().suiteName()[0];return e.assign(t,b(t),{suiteName:n})})))}function U(t){var n=l();return!e.isEmpty(n)&&(!t||n.some((function(n){return N(n,t)})))}function L(){var t=d(),n={stateRef:s()};return yt([t],rt.bind(n,(function(){return e.assign({},P(),{done:rt.bind(n,Rt)})})))}function W(t,n,r){var i;return!!(!e.isFunction(t)||n&&e.numberEquals(null===(i=r.tests[n])||void 0===i?void 0:i.testCount,0))}function D(t){return!(U()&&(!t||U(t)))}function V(t,n){(0,s().testCallbacks()[1])((function(e){return n?e.fieldCallbacks[n]=(e.fieldCallbacks[n]||[]).concat(t):e.doneCallbacks.push(t),e}))}function w(){var t=e.bus.createBus();return t.on(Nt.TEST_COMPLETED,(function(n){if(!n.isCanceled()){n.done(),n=n.fieldName;var r=s().testCallbacks()[0].fieldCallbacks;n&&!U(n)&&e.isArray(r[n])&&e.callEach(r[n]),U()||t.emit(Nt.ALL_RUNNING_TESTS_FINISHED)}})),t.on(Nt.SUITE_CALLBACK_DONE_RUNNING,(function(){!function(){function t(t){r[t.fieldName]&&(t.omit(),o(t.fieldName,(function(){return{applied:!0}})))}var n=s().optionalFields()[0];if(!e.isEmpty(n)){var r={};d().forEach((function(n){if(e.hasOwnProperty(r,n.fieldName))t(n);else{var i=a(n.fieldName);i.type===ht.Immediate&&(r[n.fieldName]=e.optionalFunctionValue(i.rule),t(n))}})),c()}}()})),t.on(Nt.ALL_RUNNING_TESTS_FINISHED,(function(){var t=s().testCallbacks()[0].doneCallbacks;e.callEach(t)})),t.on(Nt.REMOVE_FIELD,(function(t){d().forEach((function(n){N(n,t)&&(n.cancel(),function(t){f((function(n){return e.nestedArray.transform(n,(function(n){return t!==n?n:null}))}))}(n))}))})),t.on(Nt.RESET_FIELD,(function(t){d().forEach((function(n){N(n,t)&&n.reset()}))})),t}function G(){var t=rt.useX();return e.invariant(t.bus),t.bus}function x(t){return q(0,"tests",t)}function X(t){return q(1,"tests",t)}function q(t,n,r){var i=rt.useX("hook called outside of a running suite.");r&&e.asArray(r).forEach((function(r){e.isStringValue(r)&&(i.exclusion[n][r]=0===t)}))}function H(t){for(var n in t)if(!0===t[n])return!0;return!1}function K(){var t,n=rt.useX().exclusion;for(t in n.groups)if(n.groups[t])return!0;return!1}function M(t){return"Wrong arguments passed to group. Group ".concat(t,".")}function j(t,n,e){if(e||2===arguments.length)for(var r,i=0,u=n.length;i<u;i++)!r&&i in n||(r||(r=Array.prototype.slice.call(n,0,i)),r[i]=n[i]);return t.concat(r||Array.prototype.slice.call(n))}function B(t){var n=t.asyncTest,r=t.message;if(e.isPromise(n)){var i=G().emit,u=s(),o=rt.bind({stateRef:u},(function(){c(),i(Nt.TEST_COMPLETED,t)}));u=rt.bind({stateRef:u},(function(n){t.isCanceled()||(t.message=e.isStringValue(n)?n:r,t.fail(),o())}));try{n.then(o,u)}catch(t){u()}}}function Y(t){var n=s().testObjects()[0].prev;if(e.isEmpty(n))return J(t),t;var r=h();if(n=e.nestedArray.valueAtPath(n,r),!e.isNullish(t.key)){n=t.key,(r=E().keys.prev[n])&&(t=r),r=t;var i=E().keys.current;return e.isNullish(i[n])?i[n]=r:e.deferThrow('Encountered the same test key "'.concat(n,"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.")),J(t),t}return r=n,!e.isNotEmpty(r)||r.fieldName===t.fieldName&&r.groupName===t.groupName||(E().type===$.EACH||e.deferThrow("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(n.fieldName,"\n received: ").concat(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=E().cursor.current();f((function(n){return n.splice(t),n}))}(),n=null),J(t=e.defaultTo(n,t)),t}function J(t){var n=h();f((function(r){return e.nestedArray.setValueAtPath(r,n,t)}))}function z(t){var n=E().cursor,r=nt.EAGER;if(rt.useX().mode[0]===r&&m(ut.ERRORS,t.fieldName))return t.skip(),Y(t),n.next(),t;if(r=Y(t),rt.useX().omitted||R(t.fieldName))return r.omit(),n.next(),r;if(function(t){var n=t.fieldName;if(t=t.groupName,rt.useX().skipped)return!0;var r=rt.useX(),i=r.exclusion;r=r.inclusion;var u=i.tests,s=u[n];if(!1===s)return!0;if(s=!0===s,t){var o=rt.useX().exclusion.groups;if(o=e.hasOwnProperty(o,t)?!1===o[t]:K())return!0;if(!0===i.groups[t])return!(s||!H(u)&&!1!==u[n])}return!!(t=!!K()&&!t)||!s&&!!H(u)&&!e.optionalFunctionValue(r[n])}(t))return r.skip(!!rt.useX().skipped),n.next(),r;if(t!==r&&r.fieldName===t.fieldName&&r.groupName===t.groupName&&r.isPending()&&r.cancel(),J(t),t.isUntested()){r=G();var i=function(t){return rt.run({currentTest:t},(function(){return t.run()}))}(t);try{e.isPromise(i)?(t.asyncTest=i,t.setPending(),B(t)):r.emit(Nt.TEST_COMPLETED,t)}catch(n){throw Error("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(t),".\n Error: ").concat(n,"."))}}else e.isPromise(t.asyncTest)&&(t.setPending(),B(t));return n.next(),t}function Q(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var i=e.isFunction(n[1])?n:j([void 0],n,!0);n=i[0],r=i[1],i=i[2],e.invariant(e.isStringValue(t),Z("fieldName","string")),e.invariant(e.isFunction(r),Z("Test callback","function"));var u=rt.useX();return z(n=new ot(t,r,{message:n,groupName:u.groupName,key:i}))}function Z(t,n){return"Incompatible params passed to test function. ".concat(t," must be a ").concat(n)}var $,tt,nt;(tt=$||($={}))[tt.DEFAULT=0]="DEFAULT",tt[tt.SUITE=1]="SUITE",tt[tt.EACH=2]="EACH",tt[tt.SKIP_WHEN=3]="SKIP_WHEN",tt[tt.OMIT_WHEN=4]="OMIT_WHEN",tt[tt.GROUP=5]="GROUP",function(t){t[t.ALL=0]="ALL",t[t.EAGER=1]="EAGER"}(nt||(nt={}));var et,rt=r.createCascade((function(t,n){return n?null:e.assign({exclusion:{tests:{},groups:{}},inclusion:{},isolate:u($.DEFAULT),mode:[nt.ALL]},t)})),it=e.cache();!function(t){t.Error="error",t.Warning="warning"}(et||(et={}));var ut,st,ot=function(){function t(t,n,r){var i=void 0===r?{}:r;r=i.message;var u=i.groupName;i=i.key,this.key=null,this.id=e.seq(),this.severity=et.Error,this.status=at,this.fieldName=t,this.testFn=n,u&&(this.groupName=u),r&&(this.message=r),i&&(this.key=i)}return t.prototype.run=function(){try{var t=this.testFn()}catch(n){t=n,e.isUndefined(this.message)&&e.isStringValue(t)&&(this.message=n),t=!1}return!1===t&&this.fail(),t},t.prototype.setStatus=function(t){this.isFinalStatus()&&t!==Et||(this.status=t)},t.prototype.warns=function(){return this.severity===et.Warning},t.prototype.setPending=function(){this.setStatus(pt)},t.prototype.fail=function(){this.setStatus(this.warns()?lt:ft)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(dt)},t.prototype.warn=function(){this.severity=et.Warning},t.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},t.prototype.skip=function(t){this.isPending()&&!t||this.setStatus(ct)},t.prototype.cancel=function(){this.setStatus(vt),c()},t.prototype.reset=function(){this.status=at,c()},t.prototype.omit=function(){this.setStatus(Et)},t.prototype.valueOf=function(){return!this.isFailing()},t.prototype.isPending=function(){return this.statusEquals(pt)},t.prototype.isOmitted=function(){return this.statusEquals(Et)},t.prototype.isUntested=function(){return this.statusEquals(at)},t.prototype.isFailing=function(){return this.statusEquals(ft)},t.prototype.isCanceled=function(){return this.statusEquals(vt)},t.prototype.isSkipped=function(){return this.statusEquals(ct)},t.prototype.isPassing=function(){return this.statusEquals(dt)},t.prototype.isWarning=function(){return this.statusEquals(lt)},t.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},t.prototype.isNonActionable=function(){return this.isSkipped()||this.isOmitted()||this.isCanceled()},t.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},t.prototype.awaitsResolution=function(){return this.isSkipped()||this.isUntested()||this.isPending()},t.prototype.statusEquals=function(t){return this.status===t},t}(),at="UNTESTED",ct="SKIPPED",ft="FAILED",lt="WARNING",dt="PASSING",pt="PENDING",vt="CANCELED",Et="OMITTED";!function(t){t.WARNINGS="warnings",t.ERRORS="errors"}(ut||(ut={})),function(t){t.ERROR_COUNT="errorCount",t.WARN_COUNT="warnCount"}(st||(st={}));var ht,gt=e.bindNot((function(t,n){return t.groupName===n}));!function(t){t[t.Immediate=0]="Immediate",t[t.Delayed=1]="Delayed"}(ht||(ht={}));var Nt,mt=e.cache(1),yt=e.cache(20),Rt=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=L(),W(e,t,n))return n;var r=function(){return e(P())};return D(t)?(r(),n):(V(r,t),n)};!function(t){t.TEST_COMPLETED="test_completed",t.ALL_RUNNING_TESTS_FINISHED="all_running_tests_finished",t.REMOVE_FIELD="remove_field",t.RESET_FIELD="reset_field",t.SUITE_CALLBACK_DONE_RUNNING="suite_callback_done_running"}(Nt||(Nt={})),x.group=function(t){return q(0,"groups",t)},X.group=function(t){return q(1,"groups",t)},r=e.assign(Q,{memo:function(t){var n=e.cache(10);return function(r){for(var i=[],u=1;u<arguments.length;u++)i[u-1]=arguments[u];u=E().cursor.current();var o=(i=i.reverse())[0],a=i[1],c=i[2];return u=[s().suiteId()[0],r,u].concat(o),i=n.get(u),e.isNull(i)?n(u,(function(){return t(r,c,a)})):i[1].isCanceled()?(n.invalidate(u),n(u,(function(){return t(r,c,a)}))):z(i[1])}}(Q)}),Object.defineProperty(t,"enforce",{enumerable:!0,get:function(){return n.enforce}}),t.VERSION="5.0.0-dev-040354",t.context=rt,t.create=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=(t=t.reverse())[0];t=t[1],e.invariant(e.isFunction(r),"vest.create: Expected callback to be a function.");var i=w(),u=p();return t={stateRef:v(u,{suiteId:e.seq(),suiteName:t}),bus:i},e.assign(rt.bind(t,(function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return u.reset(),g({type:$.SUITE},(function(){r.apply(void 0,t)})),i.emit(Nt.SUITE_CALLBACK_DONE_RUNNING),L()})),{get:rt.bind(t,P),remove:rt.bind(t,(function(t){i.emit(Nt.REMOVE_FIELD,t)})),reset:u.reset,resetField:rt.bind(t,(function(t){i.emit(Nt.RESET_FIELD,t)}))})},t.each=function(t,n){e.invariant(e.isFunction(n),"each callback must be a function"),g({type:$.EACH},(function(){t.forEach((function(t,e){n(t,e)}))}))},t.eager=function(){var t=nt.EAGER;rt.useX().mode[0]=t},t.group=function(t,n){e.invariant(e.isStringValue(t),M("name must be a string")),e.invariant(e.isFunction(n),M("callback must be a function")),g({type:$.GROUP},(function(){rt.run({groupName:t},n)}))},t.include=function(t){var n=rt.useX(),r=n.inclusion;return n=n.exclusion,e.invariant(e.isStringValue(t)),r[t]=e.defaultTo(n.tests[t],!0),{when:function(n){var r=rt.useX(),i=r.exclusion;r.inclusion[t]=function(){return e.hasOwnProperty(i.tests,t)?e.defaultTo(i.tests[t],!0):e.isStringValue(n)?!!i.tests[n]:e.optionalFunctionValue(n,e.optionalFunctionValue(P))}}}},t.omitWhen=function(t,n){g({type:$.OMIT_WHEN},(function(){rt.run({omitted:!!rt.useX().omitted||e.optionalFunctionValue(t,e.optionalFunctionValue(P))},(function(){return n()}))}))},t.only=x,t.optional=function(t){if(e.isArray(t)||e.isStringValue(t))e.asArray(t).forEach((function(t){o(t,(function(){return{type:ht.Delayed,applied:!1,rule:null}}))}));else{var n,r=function(n){var r=t[n];o(n,(function(){return{type:ht.Immediate,rule:r,applied:e.optionalFunctionValue(r)}}))};for(n in t)r(n)}},t.skip=X,t.skipWhen=function(t,n){g({type:$.SKIP_WHEN},(function(){rt.run({skipped:!!rt.useX().skipped||e.optionalFunctionValue(t,e.optionalFunctionValue(P))},(function(){return n()}))}))},t.suiteSelectors=b,t.test=r,t.warn=function(){var t=rt.useX("warn hook called outside of a running suite.");e.invariant(t.currentTest,"warn called outside of a test."),t.currentTest.warn()},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("n4s"),require("vest-utils"),require("context")):"function"==typeof define&&define.amd?define(["exports","n4s","vest-utils","context"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).vest={},t.n4s,t["vest-utils"],t.context)}(this,(function(t,e,n,i){"use strict";var s,r,o,u,a;function c(t,e,i){if(n.isNullish(t.children))return;let s=!1;for(const o of t.children){if(s)return;if((n.isNullish(i)||n.optionalFunctionValue(i,o))&&e(o,r),s)return;c(o,((t,n)=>{e(t,(()=>{n(),r()}))}),i)}function r(){s=!0}}function l(t,e,n){let i=!1;return c(t,((t,n)=>{e(t)&&(n(),i=!0)}),n),i}function d(t,e){let n=t;for(;n.parent;){if(e(n))return n;n=n.parent}return null}!function(t){t[t.Immediate=0]="Immediate",t[t.Delayed=1]="Delayed"}(s||(s={})),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.NO_ACTIVE_ISOLATE="Not within an active isolate",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.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same test key "{key}" twice. This may lead to tests overriding each other\'s results, or to tests being unexpectedly omitted.',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}."}(r||(r={})),function(t){t.TEST_RUN_STARTED="test_run_started",t.TEST_COMPLETED="test_completed",t.ALL_RUNNING_TESTS_FINISHED="all_running_tests_finished",t.REMOVE_FIELD="remove_field",t.RESET_FIELD="reset_field",t.RESET_SUITE="reset_suite",t.SUITE_RUN_STARTED="suite_run_started"}(o||(o={}));class f{static reconciler(t,e){return n.isNullish(e),t}static reconcile(t,e){var i;const s=Ct(),r=Dt();let o=r;s&&(o=null!==(i=null==r?void 0:r.at(yt()))&&void 0!==i?i:null);const u=this.reconciler(t,o);return n.invariant(u),Object.is(u,t)?[t,E(o,t,e)]:[u,u.output]}static removeAllNextNodesInIsolate(){const t=Ct(),e=Dt();e&&t&&e.slice(yt())}static handleCollision(t,e){return t.usesKey()?this.handleIsolateNodeWithKey(t):(this.nodeReorderDetected(t,e)&&this.onNodeReorder(t,e),e||t)}static nodeReorderDetected(t,e){return!(null!=t?t:e)}static onNodeReorder(t,e){return this.removeAllNextNodesInIsolate(),null!=t?t:e}static handleIsolateNodeWithKey(t){n.invariant(t.usesKey());const e=function(t){var e;if(n.isNullish(t))return null;const i=It().historyNode;return null!==(e=null==i?void 0:i.keys[t])&&void 0!==e?e:null}(t.key);let i=t;return n.isNullish(e)||(i=e),function(t,e){if(!t)return;const i=Ct();if(n.invariant(i,r.NO_ACTIVE_ISOLATE),n.isNullish(i.keys[t]))return void(i.keys[t]=e);n.deferThrow(n.text(r.ENCOUNTERED_THE_SAME_KEY_TWICE,{key:t}))}(t.key,t),i}}function E(t,e,n){const i=Pt(),s=Tt.run(Object.assign({historyNode:t,runtimeNode:e},!i&&{runtimeRoot:e}),(()=>n(e)));return e.output=s,s}class N{constructor(t){this.children=[],this.keys={},this.parent=null,this.key=null,this.allowReorder=!1}setParent(t){return this.parent=t,this}saveOutput(t){return this.output=t,this}setKey(t){return this.key=t,this}usesKey(){return n.isNotNullish(this.key)}addChild(t){n.invariant(this.children),this.children.push(t)}removeChild(t){var e,n;this.children=null!==(n=null===(e=this.children)||void 0===e?void 0:e.filter((e=>e!==t)))&&void 0!==n?n:null}slice(t){n.isNullish(this.children)||(this.children.length=t)}at(t){var e,n;return null!==(n=null===(e=this.children)||void 0===e?void 0:e[t])&&void 0!==n?n:null}cursor(){var t,e;return null!==(e=null===(t=this.children)||void 0===t?void 0:t.length)&&void 0!==e?e:0}shouldAllowReorder(){var t;return null!==(t=!!d(this,(t=>t.allowReorder)))&&void 0!==t&&t}get rootNode(){var t;return null!==(t=d(this,(t=>n.isNullish(t.parent))))&&void 0!==t?t:this}static create(t,e){return this.createImplementation(t,e)}static createImplementation(t,e){const n=Ct(),i=new this(e).setParent(n),[s,r]=this.reconciler.reconcile(i,t);return s.saveOutput(r),this.setNode(s),s}static setNode(t){const e=Ct();e?function(t){const e=Ct();n.invariant(e,r.NO_ACTIVE_ISOLATE),e.addChild(t)}(t):function(t){const e=Tt.useX(),[,n]=e.historyRoot();n(t)}(t),t.setParent(e)}static is(t){return t instanceof N}}function h(t,e){return!!e&&!T(t,e)}function T(t,e){return!(!e||t.fieldName!==e)}function R(t,e){return T(t,e.fieldName)&&t.groupName===e.groupName&&t.key===e.key}function S(t){return t===u.ERRORS?a.ERROR_COUNT:a.WARN_COUNT}N.reconciler=f,function(t){t.WARNINGS="warnings",t.ERRORS="errors"}(u||(u={})),function(t){t.ERROR_COUNT="errorCount",t.WARN_COUNT="warnCount"}(a||(a={}));const I=n.bindNot((function(t,e){return t.groupName===e}));function p(t){return function(t,e){return Et.someTests((n=>v(n,t,e)))}(u.ERRORS,t)}function v(t,e,i){return!!t.hasFailures()&&(!h(t,i)&&!function(t,e){return n.either(t===u.WARNINGS,e.warns())}(e,t))}var _;function m(){return function(t){const[e]=O();return e===t}(t.Modes.EAGER)}t.Modes=void 0,(_=t.Modes||(t.Modes={})).ALL="ALL",_.EAGER="EAGER";const g=i.createCascade(((e,i)=>i?null:n.assign({exclusion:{tests:{},groups:{}},inclusion:{},mode:n.tinyState.createTinyState(t.Modes.EAGER),testMemoCache:C},e)));function A(t){return g.useX(t).exclusion}function D(){return g.useX().inclusion}function O(){return g.useX().mode()}const C=n.cache(10);var y,P,F,U;class L{constructor(){this.errorCount=0,this.warnCount=0,this.testCount=0}}class W extends L{constructor(){super(...arguments),this[y]=[],this[P]=[],this.groups={},this.tests={},this.valid=!1}}function G(t){return!!Lt(t)||!Et.hasNoTests()&&(!p(t)&&(!function(t){return Et.someIncompleteTests((e=>k(e,t)))}(t)&&function(t){return Et.everyTest((e=>w(e,t)))}(t)))}function b(t,e){return!!Lt(e)||!function(t,e,n){return Et.someTests((i=>!I(i,e)&&v(i,t,n)))}(u.ERRORS,t,e)&&(!function(t,e){return Et.someIncompleteTests((n=>!I(n,t)&&k(n,e)))}(t,e)&&function(t,e){return Et.everyTest((n=>!!I(n,t)||w(n,e)))}(t,e))}function k(t,e){return!h(t,e)&&Lt(e)}function w(t,e){return!!h(t,e)||(function(t){var e;return(null===(e=Ft())||void 0===e?void 0:e.getOptionalField(t.fieldName).type)===s.Delayed&&t.awaitsResolution()}(t)||t.isTested()||t.isOmitted())}function M(){const t=new W;return Et.walkTests((e=>{t.tests=function(t,e){const{fieldName:n}=e,i=Object.assign({},t);return i[n]=x(i[n],e),i[n].valid=!1!==i[n].valid&&G(n),i}(t.tests,e),t.groups=function(t,e){const{groupName:n,fieldName:i}=e;if(!n)return t;const s=Object.assign({},t);return s[n]=s[n]||{},s[n][i]=x(s[n][i],e),s[n][i].valid=!1!==s[n][i].valid&&b(n,i),s}(t.groups,e),t.errors=V(u.ERRORS,t.errors,e),t.warnings=V(u.WARNINGS,t.warnings,e)})),t.valid=G(),function(t){for(const e in t.tests)t.errorCount+=t.tests[e].errorCount,t.warnCount+=t.tests[e].warnCount,t.testCount+=t.tests[e].testCount;return t}(t)}function V(t,e,n){return(t===u.WARNINGS?n.isWarning():n.isFailing())?e.concat({fieldName:n.fieldName,groupName:n.groupName,message:n.message}):e}function x(t,e){const{message:i}=e,s=n.defaultTo(t?Object.assign({},t):null,K);return e.isNonActionable()||(s.testCount++,e.isFailing()?r(u.ERRORS):e.isWarning()&&r(u.WARNINGS)),s;function r(t){const e=S(t);s[e]++,i&&(s[t]=(s[t]||[]).concat(i))}}function K(){return n.assign(new L,{errors:[],warnings:[],valid:!0})}function B(t,e,i){return i?function(t,e,n){var i;return(null===(i=null==t?void 0:t[n])||void 0===i?void 0:i[e])||[]}(t,e,i):function(t,e){const i={},s=S(e);for(const r in t)n.isPositive(t[r][s])&&(i[r]=t[r][e]||[]);return i}(t,e)}function X(t){const e={getError:function(e){return Q(u.ERRORS,t,e)},getErrors:function(e){return j(t,u.ERRORS,e)},getErrorsByGroup:function(e,n){return q(t,u.ERRORS,e,n)},getWarning:function(e){return Q(u.WARNINGS,t,e)},getWarnings:function(e){return j(t,u.WARNINGS,e)},getWarningsByGroup:function(e,n){return q(t,u.WARNINGS,e,n)},hasErrors:function(e){return J(t,a.ERROR_COUNT,e)},hasErrorsByGroup:function(e,n){return Y(t,a.ERROR_COUNT,e,n)},hasWarnings:function(e){return J(t,a.WARN_COUNT,e)},hasWarningsByGroup:function(e,n){return Y(t,a.WARN_COUNT,e,n)},isValid:function(e){var n;return e?Boolean(null===(n=t.tests[e])||void 0===n?void 0:n.valid):t.valid},isValidByGroup:function(e,n){const i=t.groups[e];if(!i)return!1;if(n)return H(i,n);for(const t in i)if(!H(i,t))return!1;return!0}};return e}function j(t,e,n){return B(t.tests,e,n)}function q(t,e,n,i){return B(t.groups[n],e,i)}function H(t,e){var n;return!!(null===(n=t[e])||void 0===n?void 0:n.valid)}function Y(t,e,i,s){var r,o;const u=t.groups[i];if(!u)return!1;if(s)return n.isPositive(null===(r=u[s])||void 0===r?void 0:r[e]);for(const t in u)if(n.isPositive(null===(o=u[t])||void 0===o?void 0:o[e]))return!0;return!1}function J(t,e,i){var s;const r=i?null===(s=t.tests[i])||void 0===s?void 0:s[e]:t[e]||0;return n.isPositive(r)}function Q(t,e,n){var i;const s=e[t];return n?null===(i=s.find((t=>T(t,n))))||void 0===i?void 0:i.message:s[0]}function Z(){const t=M(),e=It().suiteName;return function(t){const e=It().suiteResultCache;return e([Ot()],t)}((()=>n.assign(t,X(t),{suiteName:e})))}function z(t,e){N.create((()=>{g.run({skipped:$()||n.optionalFunctionValue(t,n.optionalFunctionValue(Z))},e)}))}function $(){return function(){var t;return null!==(t=g.useX().skipped)&&void 0!==t&&t}()}function tt(t){return it(0,"tests",t)}function et(t){return it(1,"tests",t)}function nt(t){const{fieldName:e,groupName:i}=t;if($())return!0;const s=A(),r=D(),o=s.tests,u=o[e];if(!1===u)return!0;const a=!0===u;if(i){if(function(t){const e=A(),i=e.groups,s=n.hasOwnProperty(i,t);if(s)return!1===i[t];return rt()}(i))return!0;if(!0===s.groups[i])return!a&&(!!st(o)||!1===o[e])}return!!function(t){if(!rt())return!1;return!t}(i)||!a&&(!!st(o)&&!n.optionalFunctionValue(r[e]))}function it(t,e,i){const s=A(r.HOOK_CALLED_OUTSIDE);i&&n.asArray(i).forEach((i=>{n.isStringValue(i)&&(s[e][i]=0===t)}))}function st(t){for(const e in t)if(!0===t[e])return!0;return!1}function rt(){const t=A();for(const e in t.groups)if(t.groups[e])return!0;return!1}function ot(t,e){N.create((()=>{g.run({omitted:ut()||n.optionalFunctionValue(t,n.optionalFunctionValue(Z))},e)}))}function ut(){return function(){var t;return null!==(t=g.useX().omitted)&&void 0!==t&&t}()}function at(t,e=t){return function(t){return m()&&p(t.fieldName)}(t)?((n=t).skip(),n):function(t){return ut()||Lt(t.fieldName)}(t)?function(t){return t.omit(),t}(t):nt(t)?function(t){return t.skip($()),t}(e):t;var n}y=u.ERRORS,P=u.WARNINGS,tt.group=function(t){return it(0,"groups",t)},et.group=function(t){return it(1,"groups",t)};function ct(){return function(t){let e=t.initial;return{getState:function(){return e},transition:function(n,i){let s=t.states[e][n];if(Array.isArray(s)){const[,t]=s;if(!t(i))return;s=s[0]}s&&s!==e&&(e=s)}}}(lt)}!function(t){t.UNTESTED="UNTESTED",t.SKIPPED="SKIPPED",t.FAILED="FAILED",t.WARNING="WARNING",t.PASSING="PASSING",t.PENDING="PENDING",t.CANCELED="CANCELED",t.OMITTED="OMITTED"}(F||(F={})),function(t){t.RESET="RESET"}(U||(U={}));const lt={initial:F.UNTESTED,states:{[F.UNTESTED]:{[F.CANCELED]:F.CANCELED,[F.FAILED]:F.FAILED,[F.OMITTED]:F.OMITTED,[F.PASSING]:F.PASSING,[F.PENDING]:F.PENDING,[F.SKIPPED]:F.SKIPPED,[F.WARNING]:F.WARNING},[F.SKIPPED]:{[U.RESET]:F.UNTESTED},[F.FAILED]:{[U.RESET]:F.UNTESTED},[F.WARNING]:{[U.RESET]:F.UNTESTED},[F.PASSING]:{[U.RESET]:F.UNTESTED},[F.PENDING]:{[U.RESET]:F.UNTESTED,[F.CANCELED]:F.CANCELED,[F.FAILED]:F.FAILED,[F.OMITTED]:F.OMITTED,[F.PASSING]:F.PASSING,[F.SKIPPED]:[F.SKIPPED,t=>!0===t],[F.WARNING]:F.WARNING},[F.CANCELED]:{[U.RESET]:F.UNTESTED},[F.OMITTED]:{[U.RESET]:F.UNTESTED}}};class dt extends N{constructor({fieldName:t,testFn:e,message:i,groupName:s,key:r=null}){super(),this.children=null,this.id=n.seq(),this.severity=ft.Error,this.stateMachine=ct(),this.fieldName=t,this.testFn=e,s&&(this.groupName=s),i&&(this.message=i),this.setKey(r)}static create(t,e){return dt.cast(super.create(t,e))}static cast(t){return dt.isX(t),t}get status(){return this.stateMachine.getState()}setStatus(t,e){this.stateMachine.transition(t,e)}run(){let t;try{t=this.testFn()}catch(e){(function(t,e){return n.isUndefined(t)&&n.isStringValue(e)})(this.message,e)&&(this.message=e),t=!1}return!1===t&&this.fail(),t}warns(){return this.severity===ft.Warning}isPending(){return this.statusEquals(F.PENDING)}isOmitted(){return this.statusEquals(F.OMITTED)}isUntested(){return this.statusEquals(F.UNTESTED)}isFailing(){return this.statusEquals(F.FAILED)}isCanceled(){return this.statusEquals(F.CANCELED)}isSkipped(){return this.statusEquals(F.SKIPPED)}isPassing(){return this.statusEquals(F.PASSING)}isWarning(){return this.statusEquals(F.WARNING)}hasFailures(){return this.isFailing()||this.isWarning()}isNonActionable(){return this.isSkipped()||this.isOmitted()||this.isCanceled()}isTested(){return this.hasFailures()||this.isPassing()}awaitsResolution(){return this.isSkipped()||this.isUntested()||this.isPending()}statusEquals(t){return this.status===t}setPending(){this.setStatus(F.PENDING)}fail(){this.setStatus(this.warns()?F.WARNING:F.FAILED)}pass(){this.setStatus(F.PASSING)}warn(){this.severity=ft.Warning}skip(t){this.setStatus(F.SKIPPED,t)}cancel(){this.setStatus(F.CANCELED)}reset(){this.stateMachine.transition(U.RESET)}omit(){this.setStatus(F.OMITTED)}valueOf(){return!this.isFailing()}isAsyncTest(){return n.isPromise(this.asyncTest)}static is(t){return t instanceof dt}static isX(t){n.invariant(this.is(t))}}var ft;dt.reconciler=class extends f{static reconciler(t,e){if(!dt.is(t))return t;if(n.isNullish(e))return this.handleNoHistoryNode(t);if(!dt.is(e))return t;const i=this.pickNode(e,t);return function(t,e,n){t===e&&dt.is(e)&&(s=e)!==(i=n)&&R(i,s)&&i.isPending()&&i.cancel();var i,s}(i,t,e),i}static nodeReorderDetected(t,e){return!!dt.is(e)&&!R(e,t)}static handleCollision(t,e){return t.usesKey()?dt.cast(this.handleIsolateNodeWithKey(t)):this.nodeReorderDetected(t,e)?this.onNodeReorder(t,e):dt.cast(e||t)}static onNodeReorder(t,e){return function(t,e){if(t.shouldAllowReorder())return;n.deferThrow(n.text(r.TESTS_CALLED_IN_DIFFERENT_ORDER,{fieldName:t.fieldName,prevName:dt.is(e)?e.fieldName:void 0}))}(t,e),this.removeAllNextNodesInIsolate(),t}static pickNode(t,e){return at(e,this.handleCollision(e,t))}static handleNoHistoryNode(t){return t.usesKey()?dt.cast(this.handleIsolateNodeWithKey(t)):t}},function(t){t.Error="error",t.Warning="warning"}(ft||(ft={}));class Et{static defaultRoot(){return Ft()}static hasNoTests(t=Et.defaultRoot()){return!t||(e=t,n=dt.is,!l(e,(()=>!0),n));var e,n}static someIncompleteTests(t,e=Et.defaultRoot()){return!!e&&l(e,(e=>(dt.isX(e),e.isPending()&&t(e))),dt.is)}static someTests(t,e=Et.defaultRoot()){return!!e&&l(e,(e=>(dt.isX(e),t(e))),dt.is)}static everyTest(t,e=Et.defaultRoot()){return!!e&&function(t,e,n){let i=!0;return c(t,((t,n)=>{e(t)||(n(),i=!1)}),n),i}(e,(e=>(dt.isX(e),t(e))),dt.is)}static walkTests(t,e=Et.defaultRoot()){e&&c(e,((e,n)=>{t(dt.cast(e),n)}),dt.is)}static hasRemainingTests(t){return Et.someIncompleteTests((e=>!t||T(e,t)))}static pluckTests(t,e=Et.defaultRoot()){e&&function(t,e,n){c(t,(t=>{e(t)&&t.parent&&t.parent.removeChild(t)}),n)}(e,(e=>(dt.isX(e),t(e))),dt.is)}static resetField(t){Et.walkTests((e=>{T(e,t)&&e.reset()}),Et.defaultRoot())}static removeTestByFieldName(t,e=Et.defaultRoot()){Et.pluckTests((e=>T(e,t)),e)}}function Nt(){const t=n.bus.createBus();return e(o.TEST_COMPLETED,(e=>{e.isCanceled()||(!function(t){const[e]=gt();t&&!Et.hasRemainingTests(t)&&n.isArray(e[t])&&n.callEach(e[t])}(e.fieldName),Et.hasRemainingTests()||t.emit(o.ALL_RUNNING_TESTS_FINISHED))})),e(o.TEST_RUN_STARTED,(()=>{})),e(o.ALL_RUNNING_TESTS_FINISHED,(()=>{!function(){const[t]=mt();n.callEach(t)}()})),e(o.RESET_FIELD,(t=>{Et.resetField(t)})),e(o.SUITE_RUN_STARTED,(()=>{St()})),e(o.REMOVE_FIELD,(t=>{Et.removeTestByFieldName(t)})),e(o.RESET_SUITE,(()=>{!function(){St();const[,,t]=At();t()}()})),t;function e(e,n){t.on(e,((...t)=>{!function(){const t=It().suiteResultCache;t.invalidate([Ot()])}(),n(...t)}))}}const ht=n.cache(),Tt=i.createCascade(((t,e)=>{if(e)return null;n.invariant(t.historyRoot);const[i]=t.historyRoot(),s={};return n.assign(s,{historyNode:i,runtimeNode:null,runtimeRoot:null},t),s}));function Rt(t){const e=Tt.useX();return function(...n){var i;const s=null!==(i=Tt.use())&&void 0!==i?i:e;return Tt.run(s,(()=>t(...n)))}}function St(){const[,,t]=mt(),[,,e]=gt();t(),e()}function It(){return Tt.useX()}function pt(){return It().VestBus}function vt(){return Rt(pt().emit)}function _t(t){const e=vt();return n=>e(t,n)}function mt(){return It().doneCallbacks()}function gt(){return It().fieldCallbacks()}function At(){return It().historyRoot()}function Dt(){return It().historyNode}function Ot(){return It().suiteId}function Ct(){var t;return null!==(t=It().runtimeNode)&&void 0!==t?t:null}function yt(){var t,e;return null!==(e=null===(t=Ct())||void 0===t?void 0:t.cursor())&&void 0!==e?e:0}function Pt(){return It().runtimeRoot}function Ft(){const t=Pt();if(t)return t;const[e]=At();return e}function Ut(t){const e=Pt();if(n.isArray(t)||n.isStringValue(t))n.asArray(t).forEach((t=>{e.setOptionalField(t,(()=>({type:s.Delayed,applied:!1,rule:null})))}));else for(const i in t){const r=t[i];e.setOptionalField(i,(()=>({type:s.Immediate,rule:r,applied:n.optionalFunctionValue(r)})))}}function Lt(t){var e,n,i;return!!t&&(null!==(i=null===(n=null===(e=Ft())||void 0===e?void 0:e.getOptionalField(t))||void 0===n?void 0:n.applied)&&void 0!==i&&i)}class Wt extends N{constructor(){super(...arguments),this.optional={}}setOptionalField(t,e){const n=this.optional,i=n[t];Object.assign(n,{[t]:Object.assign({},i,e(i))})}getOptionalField(t){var e;return null!==(e=this.optional[t])&&void 0!==e?e:{}}}function Gt(t){const e=D(),i=A();return n.invariant(n.isStringValue(t)),e[t]=n.defaultTo(i.tests[t],!0),{when:function(e){const i=D(),s=A();i[t]=()=>n.hasOwnProperty(s.tests,t)?n.defaultTo(s.tests[t],!0):n.isStringValue(e)?Boolean(s.tests[e]):n.optionalFunctionValue(e,n.optionalFunctionValue(Z))}}}function bt(t){at(t),t.isNonActionable()||(t.isUntested()?function(t){const e=pt(),i=function(t){return g.run({currentTest:t},(()=>t.run()))}(t);try{n.isPromise(i)?(t.asyncTest=i,t.setPending(),kt(t)):wt(e,t)}catch(e){throw new Error(n.text(r.UNEXPECTED_TEST_REGISTRATION_ERROR,{testObject:JSON.stringify(t),error:e}))}}(t):t.isAsyncTest()&&(t.setPending(),kt(t)))}function kt(t){const{asyncTest:e,message:i}=t;if(!n.isPromise(e))return;const s=pt(),r=Rt((()=>{wt(s,t)})),o=Rt((e=>{t.isCanceled()||(t.message=n.isStringValue(e)?e:i,t.fail(),r())}));e.then(r,o)}function wt(t,e){e.pass(),t.emit(o.TEST_COMPLETED,e)}function Mt(t,...e){const[i,s,u]=n.isFunction(e[1])?e:[void 0,...e];!function(t,e){const i="test";n.invariant(n.isStringValue(t),n.text(r.INVALID_PARAM_PASSED_TO_FUNCTION,{fn_name:i,param:"fieldName",expected:"string"})),n.invariant(n.isFunction(e),n.text(r.INVALID_PARAM_PASSED_TO_FUNCTION,{fn_name:i,param:"callback",expected:"function"}))}(t,s);const a={fieldName:t,groupName:g.useX().groupName,key:u,message:i,testFn:s};return vt()(o.TEST_RUN_STARTED),dt.create(bt,a)}const Vt=n.assign(Mt,{memo:function(t){return function(e,...i){const[s,r,o]=i.reverse();return function(t,e){const i=g.useX().testMemoCache,s=i.get(t);if(n.isNull(s))return i(t,e);const[,r]=s;if(r.isCanceled())return i.invalidate(t),i(t,e);return dt.setNode(r),r}([Ot(),e,yt()].concat(s),(function(){return t(e,o,r)}))}}(Mt)});function xt(){return{group:qt,include:Gt,omitWhen:ot,only:tt,optional:Ut,skip:et,skipWhen:z,test:Vt}}function Kt(){return n.assign({},Z(),{done:Rt(Bt)})}function Bt(...t){const[e,i]=t.reverse(),s=Kt();if(function(t,e,i){var s;return!!(!n.isFunction(t)||e&&n.numberEquals(null===(s=i.tests[e])||void 0===s?void 0:s.testCount,0))}(e,i,s))return s;const r=()=>e(Z());return Et.hasRemainingTests(i)?(function(t,e){const[,i]=gt(),[,s]=mt();e?i((i=>n.assign(i,{[e]:(i[e]||[]).concat(t)}))):s((e=>e.concat(t)))}(r,i),s):(r(),s)}function Xt(...t){const[e,i]=t.reverse();!function(t){n.invariant(n.isFunction(t),r.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION)}(e);const s=function({suiteName:t}={}){return{VestBus:Nt(),doneCallbacks:n.tinyState.createTinyState((()=>[])),fieldCallbacks:n.tinyState.createTinyState((()=>({}))),historyRoot:n.tinyState.createTinyState(null),suiteId:n.seq(),suiteName:t,suiteResultCache:ht}}({suiteName:i});function u(...t){return g.run({},(()=>(vt()(o.SUITE_RUN_STARTED),Wt.create(function(t,...e){return()=>(t(...e),Kt())}(e,...t))))).output}return Tt.run(s,(()=>n.assign(Tt.bind(s,u),Object.assign({get:Rt(Z),remove:_t(o.REMOVE_FIELD),reset:_t(o.RESET_SUITE),resetField:_t(o.RESET_FIELD)},xt()))))}class jt extends N{constructor(){super(...arguments),this.allowReorder=!0}}function qt(t,e){return N.create((()=>{g.run({groupName:t},e)}))}const Ht=r.WARN_MUST_BE_CALLED_FROM_TEST;Object.defineProperty(t,"enforce",{enumerable:!0,get:function(){return e.enforce}}),t.create=Xt,t.each=function(t,e){n.invariant(n.isFunction(e),r.EACH_CALLBACK_MUST_BE_A_FUNCTION),jt.create((()=>{t.forEach(((t,n)=>{e(t,n)}))}))},t.group=qt,t.include=Gt,t.mode=function(t){const[,e]=O();e(t)},t.omitWhen=ot,t.only=tt,t.optional=Ut,t.skip=et,t.skipWhen=z,t.staticSuite=function(t){return n.assign(((...e)=>Xt(t)(...e)),Object.assign({},xt()))},t.suiteSelectors=X,t.test=Vt,t.warn=function(){const t=(e=r.HOOK_CALLED_OUTSIDE,g.useX(e).currentTest);var e;n.invariant(t,Ht),t.warn()},Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "5.0.0-dev-040354",
|
|
3
|
-
"license": "MIT",
|
|
4
2
|
"name": "vest",
|
|
3
|
+
"version": "5.0.0-dev-9c596e",
|
|
4
|
+
"description": "Declarative Form Validations Framework",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"author": "ealush",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "vx test",
|
|
8
|
-
"build": "vx build",
|
|
9
|
-
"release": "vx release"
|
|
10
|
-
},
|
|
11
7
|
"main": "./dist/cjs/vest.js",
|
|
12
|
-
"types": "./types/vest.d.ts",
|
|
13
8
|
"module": "./dist/es/vest.production.js",
|
|
9
|
+
"unpkg": "./dist/umd/vest.production.js",
|
|
10
|
+
"jsdelivr": "./dist/umd/vest.production.js",
|
|
11
|
+
"types": "./types/vest.d.ts",
|
|
14
12
|
"repository": {
|
|
15
13
|
"type": "git",
|
|
16
14
|
"url": "https://github.com/ealush/vest.git",
|
|
@@ -20,11 +18,11 @@
|
|
|
20
18
|
"url": "https://github.com/ealush/vest.git/issues"
|
|
21
19
|
},
|
|
22
20
|
"dependencies": {
|
|
23
|
-
"context": "
|
|
24
|
-
"n4s": "
|
|
25
|
-
"
|
|
21
|
+
"context": "3.0.8-dev-9c596e",
|
|
22
|
+
"n4s": "4.3.8-dev-9c596e",
|
|
23
|
+
"vast": "1.0.18-dev-9c596e",
|
|
24
|
+
"vest-utils": "1.0.0-dev-9c596e"
|
|
26
25
|
},
|
|
27
|
-
"homepage": "https://vestjs.dev/",
|
|
28
26
|
"exports": {
|
|
29
27
|
"./classnames": {
|
|
30
28
|
"production": {
|
|
@@ -227,8 +225,6 @@
|
|
|
227
225
|
"default": "./dist/cjs/vest.production.js"
|
|
228
226
|
},
|
|
229
227
|
"./package.json": "./package.json",
|
|
230
|
-
"
|
|
231
|
-
}
|
|
232
|
-
"unpkg": "./dist/umd/vest.production.js",
|
|
233
|
-
"jsdelivr": "./dist/umd/vest.production.js"
|
|
228
|
+
"./*": "./*"
|
|
229
|
+
}
|
|
234
230
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TFieldName, TGroupName } from 'SuiteResultTypes';
|
|
2
|
+
import * as vest from 'vest';
|
|
3
|
+
|
|
4
|
+
export type TVestMock = typeof vest;
|
|
5
|
+
|
|
6
|
+
export type TTestSuiteCallback = (...args: any[]) => void;
|
|
7
|
+
export type TTestSuite = vest.Suite<TTestSuiteCallback, TFieldName, TGroupName>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import partition from '../partition';
|
|
2
2
|
|
|
3
3
|
describe('partition', () => {
|
|
4
4
|
it('Should correctly partition array', () => {
|
|
5
5
|
expect(partition([300, 200, 10, 50, 0, -500], v => v <= 100))
|
|
6
6
|
.toMatchInlineSnapshot(`
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
[
|
|
8
|
+
[
|
|
9
9
|
10,
|
|
10
10
|
50,
|
|
11
11
|
0,
|
|
12
12
|
-500,
|
|
13
13
|
],
|
|
14
|
-
|
|
14
|
+
[
|
|
15
15
|
300,
|
|
16
16
|
200,
|
|
17
17
|
],
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { TVestMock } from './TVestMock';
|
|
2
|
+
|
|
1
3
|
export default function mockThrowError() {
|
|
2
|
-
const deferThrow = jest.fn();
|
|
4
|
+
const deferThrow = jest.fn<string, any>();
|
|
3
5
|
jest.resetModules();
|
|
4
6
|
jest.mock('vest-utils', () => ({
|
|
5
7
|
...jest.requireActual('vest-utils'),
|
|
6
8
|
deferThrow,
|
|
7
9
|
}));
|
|
8
|
-
const vest = require('vest');
|
|
10
|
+
const vest = require('vest') as TVestMock;
|
|
9
11
|
|
|
10
12
|
return {
|
|
11
13
|
deferThrow,
|
package/testUtils/suiteDummy.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { asArray } from 'vest-utils';
|
|
|
2
2
|
|
|
3
3
|
import { dummyTest } from './testDummy';
|
|
4
4
|
|
|
5
|
+
import { TFieldName, TGroupName } from 'SuiteResultTypes';
|
|
5
6
|
import { optional, create, skip, SuiteResult } from 'vest';
|
|
6
7
|
|
|
7
8
|
export function failing(failingFields?: string | string[]) {
|
|
@@ -103,6 +104,8 @@ function createSuite(
|
|
|
103
104
|
});
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
export function ser
|
|
107
|
+
export function ser<F extends TFieldName, G extends TGroupName>(
|
|
108
|
+
res: SuiteResult<F, G>
|
|
109
|
+
) {
|
|
107
110
|
return JSON.parse(JSON.stringify(res));
|
|
108
111
|
}
|
package/testUtils/testDummy.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable jest/valid-title */
|
|
2
|
-
import faker from 'faker';
|
|
2
|
+
import { faker } from '@faker-js/faker';
|
|
3
3
|
|
|
4
|
-
import { test, warn } from 'vest';
|
|
4
|
+
import { test as vestTest, warn } from 'vest';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Generates dummy vest tests.
|
|
@@ -12,7 +12,7 @@ const testDummy = () => {
|
|
|
12
12
|
message: string = faker.random.words(),
|
|
13
13
|
groupName?: string
|
|
14
14
|
) => {
|
|
15
|
-
const to =
|
|
15
|
+
const to = vestTest(
|
|
16
16
|
name,
|
|
17
17
|
message,
|
|
18
18
|
jest.fn(() => {
|
|
@@ -32,7 +32,7 @@ const testDummy = () => {
|
|
|
32
32
|
message = faker.random.words(),
|
|
33
33
|
groupName?: string
|
|
34
34
|
) => {
|
|
35
|
-
const to =
|
|
35
|
+
const to = vestTest(
|
|
36
36
|
name,
|
|
37
37
|
message,
|
|
38
38
|
jest.fn(() => {
|
|
@@ -53,7 +53,7 @@ const testDummy = () => {
|
|
|
53
53
|
message = faker.random.words(),
|
|
54
54
|
groupName?: string
|
|
55
55
|
) => {
|
|
56
|
-
const to =
|
|
56
|
+
const to = vestTest(name, message, jest.fn());
|
|
57
57
|
|
|
58
58
|
if (groupName) {
|
|
59
59
|
to.groupName = groupName;
|
|
@@ -67,7 +67,7 @@ const testDummy = () => {
|
|
|
67
67
|
message = faker.random.words(),
|
|
68
68
|
groupName?: string
|
|
69
69
|
) => {
|
|
70
|
-
const to =
|
|
70
|
+
const to = vestTest(
|
|
71
71
|
name,
|
|
72
72
|
message,
|
|
73
73
|
jest.fn(() => {
|
|
@@ -84,7 +84,7 @@ const testDummy = () => {
|
|
|
84
84
|
name = faker.random.word(),
|
|
85
85
|
{ message = faker.random.words(), time = 0 } = {}
|
|
86
86
|
) =>
|
|
87
|
-
|
|
87
|
+
vestTest(
|
|
88
88
|
name,
|
|
89
89
|
message,
|
|
90
90
|
jest.fn(
|
|
@@ -99,7 +99,7 @@ const testDummy = () => {
|
|
|
99
99
|
name = faker.random.word(),
|
|
100
100
|
{ message = faker.random.words(), time = 0 } = {}
|
|
101
101
|
) =>
|
|
102
|
-
|
|
102
|
+
vestTest(
|
|
103
103
|
name,
|
|
104
104
|
message,
|
|
105
105
|
jest.fn(() => {
|
|
@@ -114,7 +114,7 @@ const testDummy = () => {
|
|
|
114
114
|
name = faker.random.word(),
|
|
115
115
|
{ message = faker.random.words(), time = 0 } = {}
|
|
116
116
|
) =>
|
|
117
|
-
|
|
117
|
+
vestTest(
|
|
118
118
|
name,
|
|
119
119
|
message,
|
|
120
120
|
jest.fn(
|
|
@@ -129,7 +129,7 @@ const testDummy = () => {
|
|
|
129
129
|
name = faker.random.word(),
|
|
130
130
|
{ message = faker.random.words(), time = 0 } = {}
|
|
131
131
|
) =>
|
|
132
|
-
|
|
132
|
+
vestTest(
|
|
133
133
|
name,
|
|
134
134
|
message,
|
|
135
135
|
jest.fn(() => {
|
|
@@ -153,3 +153,5 @@ const testDummy = () => {
|
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
export const dummyTest = testDummy();
|
|
156
|
+
|
|
157
|
+
export type TDummyTest = typeof dummyTest;
|
package/types/classnames.d.ts
CHANGED
|
@@ -1,26 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
declare enum Severity {
|
|
2
|
+
WARNINGS = "warnings",
|
|
3
|
+
ERRORS = "errors"
|
|
4
|
+
}
|
|
5
|
+
type WithFieldName<F extends TFieldName = TFieldName> = {
|
|
6
|
+
fieldName: F;
|
|
7
|
+
};
|
|
8
|
+
interface Done<F extends TFieldName, G extends TGroupName> {
|
|
9
|
+
(...args: [
|
|
10
|
+
cb: (res: SuiteResult<F, G>) => void
|
|
11
|
+
]): SuiteRunResult<F, G>;
|
|
12
|
+
(...args: [
|
|
13
|
+
fieldName: F,
|
|
14
|
+
cb: (res: SuiteResult<F, G>) => void
|
|
15
|
+
]): SuiteRunResult<F, G>;
|
|
16
|
+
}
|
|
17
|
+
interface SuiteSelectors<F extends TFieldName, G extends TGroupName> {
|
|
18
|
+
getWarning(fieldName?: F): void | string | SummaryFailure<F, G>;
|
|
19
|
+
getError(fieldName?: F): void | string | SummaryFailure<F, G>;
|
|
20
|
+
getErrors(fieldName: F): string[];
|
|
21
|
+
getErrors(): FailureMessages;
|
|
22
|
+
getWarnings(): FailureMessages;
|
|
23
|
+
getWarnings(fieldName: F): string[];
|
|
24
|
+
getErrorsByGroup(groupName: G, fieldName: F): string[];
|
|
25
|
+
getErrorsByGroup(groupName: G): FailureMessages;
|
|
26
|
+
getWarningsByGroup(groupName: G): FailureMessages;
|
|
27
|
+
getWarningsByGroup(groupName: G, fieldName: F): string[];
|
|
28
|
+
hasErrors(fieldName?: F): boolean;
|
|
29
|
+
hasWarnings(fieldName?: F): boolean;
|
|
30
|
+
hasErrorsByGroup(groupName: G, fieldName?: F): boolean;
|
|
31
|
+
hasWarningsByGroup(groupName: G, fieldName?: F): boolean;
|
|
32
|
+
isValid(fieldName?: F): boolean;
|
|
33
|
+
isValidByGroup(groupName: G, fieldName?: F): boolean;
|
|
34
|
+
}
|
|
35
|
+
declare class SummaryBase {
|
|
36
|
+
errorCount: number;
|
|
37
|
+
warnCount: number;
|
|
38
|
+
testCount: number;
|
|
39
|
+
}
|
|
40
|
+
declare class SuiteSummary<F extends TFieldName, G extends TGroupName> extends SummaryBase {
|
|
41
|
+
[Severity.ERRORS]: SummaryFailure<F, G>[];
|
|
42
|
+
[Severity.WARNINGS]: SummaryFailure<F, G>[];
|
|
43
|
+
groups: Groups<G, F>;
|
|
44
|
+
tests: Tests<F>;
|
|
4
45
|
valid: boolean;
|
|
5
|
-
}
|
|
46
|
+
}
|
|
6
47
|
type GroupTestSummary = SingleTestSummary;
|
|
7
|
-
type Groups = Record<
|
|
8
|
-
type Group = Record<
|
|
9
|
-
type Tests = Record<
|
|
48
|
+
type Groups<G extends TGroupName, F extends TFieldName> = Record<G, Group<F>>;
|
|
49
|
+
type Group<F extends TFieldName> = Record<F, GroupTestSummary>;
|
|
50
|
+
type Tests<F extends TFieldName> = Record<F, SingleTestSummary>;
|
|
10
51
|
type SingleTestSummary = SummaryBase & {
|
|
11
52
|
errors: string[];
|
|
12
53
|
warnings: string[];
|
|
13
54
|
valid: boolean;
|
|
14
55
|
};
|
|
15
|
-
type
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
56
|
+
type SummaryFailure<F extends TFieldName, G extends TGroupName> = WithFieldName<F> & {
|
|
57
|
+
groupName: G | undefined;
|
|
58
|
+
message: string | undefined;
|
|
59
|
+
};
|
|
60
|
+
type FailureMessages = Record<string, string[]>;
|
|
61
|
+
type SuiteResult<F extends TFieldName, G extends TGroupName> = SuiteSummary<F, G> & SuiteSelectors<F, G> & {
|
|
62
|
+
suiteName: SuiteName;
|
|
63
|
+
};
|
|
64
|
+
type SuiteRunResult<F extends TFieldName, G extends TGroupName> = SuiteResult<F, G> & {
|
|
65
|
+
done: Done<F, G>;
|
|
19
66
|
};
|
|
67
|
+
type SuiteName = string | undefined;
|
|
68
|
+
type TFieldName<T extends string = string> = T;
|
|
69
|
+
type TGroupName<G extends string = string> = G;
|
|
20
70
|
/**
|
|
21
71
|
* Creates a function that returns class names that match the validation result
|
|
22
72
|
*/
|
|
23
|
-
declare function classnames(res: SuiteSummary, classes?: SupportedClasses): (fieldName:
|
|
73
|
+
declare function classnames<F extends TFieldName, G extends TGroupName>(res: SuiteSummary<F, G>, classes?: SupportedClasses): (fieldName: F) => string;
|
|
24
74
|
type SupportedClasses = {
|
|
25
75
|
valid?: string;
|
|
26
76
|
tested?: string;
|
|
@@ -29,3 +79,4 @@ type SupportedClasses = {
|
|
|
29
79
|
untested?: string;
|
|
30
80
|
};
|
|
31
81
|
export { classnames as default };
|
|
82
|
+
//# sourceMappingURL=classnames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classnames.d.ts","sourceRoot":"","sources":["../src/exports/classnames.ts","../src/suiteResult/Severity.ts","../src/core/test/TestTypes.ts","../src/core/VestBus/Events.ts","../src/errors/ErrorStrings.ts","../src/core/isolate/walker.ts","../src/core/isolate/reconciler/Reconciler/Reconciler.ts","../src/core/isolate/Isolate.ts","../src/hooks/optional/OptionalTypes.ts","../src/core/isolate/IsolateSuite/IsolateSuite.ts","../src/core/test/helpers/matchingFieldName.ts","../src/core/isolate/reconciler/isSameProfileTest.ts","../src/core/isolate/reconciler/cancelOverriddenPendingTest.ts","../src/hooks/optional/optional.ts","../src/core/isolate/IsolateTest/TestWalker.ts","../src/core/test/helpers/matchingGroupName.ts","../src/core/test/helpers/nonMatchingSeverityProfile.ts","../src/suiteResult/selectors/hasFailuresByTestObjects.ts","../src/hooks/mode.ts","../src/core/context/SuiteContext.ts","../src/suiteResult/selectors/shouldAddValidProperty.ts","../src/suiteResult/selectors/produceSuiteSummary.ts","../src/suiteResult/selectors/collectFailures.ts","../src/suiteResult/selectors/suiteSelectors.ts","../src/suiteResult/suiteResult.ts","../src/isolates/skipWhen.ts","../src/hooks/exclusive.ts","../src/isolates/omitWhen.ts","../src/core/test/testLevelFlowControl/verifyTestRun.ts","../src/core/isolate/IsolateTest/IsolateTestReconciler.ts","../src/core/isolate/IsolateTest/SimpleStateMachine.ts","../src/core/isolate/IsolateTest/IsolateTestStateMachine.ts","../src/core/test/helpers/shouldUseErrorMessage.ts","../src/core/isolate/IsolateTest/IsolateTest.ts","../src/suite/runCallbacks.ts","../src/core/VestBus/VestBus.ts","../src/core/context/PersistedContext.ts","../src/suiteResult/done/deferDoneCallback.ts","../src/suiteResult/done/shouldSkipDoneRegistration.ts","../src/suiteResult/suiteRunResult.ts","../src/suiteResult/SuiteResultTypes.ts","../src/exports/parser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA;;GAEG;AACH,iBAAwB,UAAU,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAC3E,GAAG,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,OAAO,GAAE,gBAAqB,GAC7B,CAAC,SAAS,EAAE,CAAC,KAAK,MAAM,CAe1B;AAED,KAAK,gBAAgB,GAAG;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC"}
|
|
@@ -1,126 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
...infer U
|
|
4
|
-
] ? U : never;
|
|
5
|
-
type Stringable = string | ((...args: any[]) => string);
|
|
6
|
-
type CB = (...args: any[]) => any;
|
|
7
|
-
type RuleReturn = boolean | {
|
|
8
|
-
pass: boolean;
|
|
9
|
-
message?: Stringable;
|
|
10
|
-
};
|
|
11
|
-
type RuleDetailedResult = {
|
|
12
|
-
pass: boolean;
|
|
13
|
-
message?: string;
|
|
14
|
-
};
|
|
15
|
-
type Args = any[];
|
|
16
|
-
type BaseRules = typeof baseRules;
|
|
17
|
-
type KBaseRules = keyof BaseRules;
|
|
18
|
-
declare function condition(value: any, callback: (value: any) => RuleReturn): RuleReturn;
|
|
19
|
-
declare function endsWith(value: string, arg1: string): boolean;
|
|
20
|
-
declare function equals(value: unknown, arg1: unknown): boolean;
|
|
21
|
-
declare function greaterThanOrEquals(value: string | number, gte: string | number): boolean;
|
|
22
|
-
declare function inside(value: unknown, arg1: string | unknown[]): boolean;
|
|
23
|
-
declare function isBetween(value: number | string, min: number | string, max: number | string): boolean;
|
|
24
|
-
declare function isBlank(value: unknown): boolean;
|
|
25
|
-
declare function isKeyOf(key: string | symbol | number, obj: any): boolean;
|
|
26
|
-
declare function isNaN(value: unknown): boolean;
|
|
27
|
-
declare function isNegative(value: number | string): boolean;
|
|
28
|
-
declare function isNumber(value: unknown): value is number;
|
|
29
|
-
declare function isTruthy(value: unknown): boolean;
|
|
30
|
-
declare function isValueOf(value: any, objectToCheck: any): boolean;
|
|
31
|
-
declare function lessThan(value: string | number, lt: string | number): boolean;
|
|
32
|
-
declare function lessThanOrEquals(value: string | number, lte: string | number): boolean;
|
|
33
|
-
declare function longerThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
34
|
-
declare function matches(value: string, regex: RegExp | string): boolean;
|
|
35
|
-
declare function shorterThan(value: string | unknown[], arg1: string | number): boolean;
|
|
36
|
-
declare function shorterThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
37
|
-
declare function startsWith(value: string, arg1: string): boolean;
|
|
38
|
-
declare const baseRules: {
|
|
39
|
-
condition: typeof condition;
|
|
40
|
-
doesNotEndWith: (value: string, arg1: string) => boolean;
|
|
41
|
-
doesNotStartWith: (value: string, arg1: string) => boolean;
|
|
42
|
-
endsWith: typeof endsWith;
|
|
43
|
-
equals: typeof equals;
|
|
44
|
-
greaterThan: typeof import("packages/vest-utils/types/vest-utils").greaterThan;
|
|
45
|
-
greaterThanOrEquals: typeof greaterThanOrEquals;
|
|
46
|
-
gt: typeof import("packages/vest-utils/types/vest-utils").greaterThan;
|
|
47
|
-
gte: typeof greaterThanOrEquals;
|
|
48
|
-
inside: typeof inside;
|
|
49
|
-
isArray: typeof import("packages/vest-utils/types/vest-utils").isArray;
|
|
50
|
-
isBetween: typeof isBetween;
|
|
51
|
-
isBlank: typeof isBlank;
|
|
52
|
-
isBoolean: typeof import("packages/vest-utils/types/vest-utils").isBoolean;
|
|
53
|
-
isEmpty: typeof import("packages/vest-utils/types/vest-utils").isEmpty;
|
|
54
|
-
isEven: (value: any) => boolean;
|
|
55
|
-
isFalsy: (value: unknown) => boolean;
|
|
56
|
-
isKeyOf: typeof isKeyOf;
|
|
57
|
-
isNaN: typeof isNaN;
|
|
58
|
-
isNegative: typeof isNegative;
|
|
59
|
-
isNotArray: (value: unknown) => boolean;
|
|
60
|
-
isNotBetween: (value: string | number, min: string | number, max: string | number) => boolean;
|
|
61
|
-
isNotBlank: (value: unknown) => boolean;
|
|
62
|
-
isNotBoolean: (value: unknown) => boolean;
|
|
63
|
-
isNotEmpty: (value: unknown) => boolean;
|
|
64
|
-
isNotKeyOf: (key: string | number | symbol, obj: any) => boolean;
|
|
65
|
-
isNotNaN: (value: unknown) => boolean;
|
|
66
|
-
isNotNull: (value: unknown) => boolean;
|
|
67
|
-
isNotNullish: (value: any) => boolean;
|
|
68
|
-
isNotNumber: (value: unknown) => boolean;
|
|
69
|
-
isNotNumeric: (value: string | number) => boolean;
|
|
70
|
-
isNotString: (v: unknown) => boolean;
|
|
71
|
-
isNotUndefined: (value?: unknown) => boolean;
|
|
72
|
-
isNotValueOf: (value: any, objectToCheck: any) => boolean;
|
|
73
|
-
isNull: typeof import("packages/vest-utils/types/vest-utils").isNull;
|
|
74
|
-
isNullish: typeof import("packages/vest-utils/types/vest-utils").isNullish;
|
|
75
|
-
isNumber: typeof isNumber;
|
|
76
|
-
isNumeric: typeof import("packages/vest-utils/types/vest-utils").isNumeric;
|
|
77
|
-
isOdd: (value: any) => boolean;
|
|
78
|
-
isPositive: typeof import("packages/vest-utils/types/vest-utils").isPositive;
|
|
79
|
-
isString: typeof import("packages/vest-utils/types/vest-utils").isStringValue;
|
|
80
|
-
isTruthy: typeof isTruthy;
|
|
81
|
-
isUndefined: typeof import("packages/vest-utils/types/vest-utils").isUndefined;
|
|
82
|
-
isValueOf: typeof isValueOf;
|
|
83
|
-
lengthEquals: typeof import("packages/vest-utils/types/vest-utils").lengthEquals;
|
|
84
|
-
lengthNotEquals: (value: string | unknown[], arg1: string | number) => boolean;
|
|
85
|
-
lessThan: typeof lessThan;
|
|
86
|
-
lessThanOrEquals: typeof lessThanOrEquals;
|
|
87
|
-
longerThan: typeof import("packages/vest-utils/types/vest-utils").longerThan;
|
|
88
|
-
longerThanOrEquals: typeof longerThanOrEquals;
|
|
89
|
-
lt: typeof lessThan;
|
|
90
|
-
lte: typeof lessThanOrEquals;
|
|
91
|
-
matches: typeof matches;
|
|
92
|
-
notEquals: (value: unknown, arg1: unknown) => boolean;
|
|
93
|
-
notInside: (value: unknown, arg1: string | unknown[]) => boolean;
|
|
94
|
-
notMatches: (value: string, regex: string | RegExp) => boolean;
|
|
95
|
-
numberEquals: typeof import("packages/vest-utils/types/vest-utils").numberEquals;
|
|
96
|
-
numberNotEquals: (value: string | number, eq: string | number) => boolean;
|
|
97
|
-
shorterThan: typeof shorterThan;
|
|
98
|
-
shorterThanOrEquals: typeof shorterThanOrEquals;
|
|
99
|
-
startsWith: typeof startsWith;
|
|
100
|
-
};
|
|
101
|
-
type Rules<E> = n4s.EnforceCustomMatchers<Rules<E> & E> & Record<string, (...args: Args) => Rules<E> & E> & {
|
|
102
|
-
[P in KBaseRules]: (...args: DropFirst<Parameters<BaseRules[P]>> | Args) => Rules<E> & E;
|
|
103
|
-
};
|
|
104
|
-
/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
|
|
105
|
-
declare global {
|
|
106
|
-
namespace n4s {
|
|
107
|
-
interface IRules<E> extends Rules<E> {
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
type LazyRules = n4s.IRules<LazyRuleMethods>;
|
|
112
|
-
type Lazy = LazyRules & LazyRuleMethods &
|
|
113
|
-
// This is a "catch all" hack to make TS happy while not
|
|
114
|
-
// losing type hints
|
|
115
|
-
Record<string, CB>;
|
|
116
|
-
type LazyRuleMethods = LazyRuleRunners & {
|
|
117
|
-
message: (message: LazyMessage) => Lazy;
|
|
118
|
-
};
|
|
119
|
-
type LazyRuleRunners = {
|
|
120
|
-
test: (value: unknown) => boolean;
|
|
121
|
-
run: (value: unknown) => RuleDetailedResult;
|
|
122
|
-
};
|
|
123
|
-
type ComposeResult = LazyRuleRunners & ((value: any) => void);
|
|
124
|
-
type LazyMessage = string | ((value: unknown, originalMessage?: Stringable) => string);
|
|
125
|
-
declare function compose(...composites: LazyRuleRunners[]): ComposeResult;
|
|
126
|
-
export { compose as default };
|
|
1
|
+
export { default } from 'n4s/compose';
|
|
2
|
+
//# sourceMappingURL=compose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/exports/enforce@compose.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,aAAa,CAAC"}
|