vest 4.5.0 → 4.6.2-dev-fcaa09

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 (81) hide show
  1. package/dist/cjs/enforce_compose.development.js +2 -0
  2. package/dist/cjs/enforce_compose.js +7 -0
  3. package/dist/cjs/enforce_compose.production.js +1 -0
  4. package/dist/cjs/enforce_compounds.development.js +4 -0
  5. package/dist/cjs/enforce_compounds.js +7 -0
  6. package/dist/cjs/enforce_compounds.production.js +1 -0
  7. package/dist/cjs/enforce_schema.development.js +4 -0
  8. package/dist/cjs/enforce_schema.js +7 -0
  9. package/dist/cjs/enforce_schema.production.js +1 -0
  10. package/dist/cjs/vest.development.js +149 -168
  11. package/dist/cjs/vest.production.js +1 -1
  12. package/dist/es/enforce_compose.development.js +1 -0
  13. package/dist/es/enforce_compose.production.js +1 -0
  14. package/dist/es/enforce_compounds.development.js +1 -0
  15. package/dist/es/enforce_compounds.production.js +1 -0
  16. package/dist/es/enforce_schema.development.js +1 -0
  17. package/dist/es/enforce_schema.production.js +1 -0
  18. package/dist/es/vest.development.js +150 -169
  19. package/dist/es/vest.production.js +1 -1
  20. package/dist/umd/classnames.development.js +11 -59
  21. package/dist/umd/classnames.production.js +1 -1
  22. package/dist/umd/enforce_compose.development.js +8 -0
  23. package/dist/umd/enforce_compose.production.js +1 -0
  24. package/dist/umd/enforce_compounds.development.js +8 -0
  25. package/dist/umd/enforce_compounds.production.js +1 -0
  26. package/dist/umd/enforce_schema.development.js +8 -0
  27. package/dist/umd/enforce_schema.production.js +1 -0
  28. package/dist/umd/parser.development.js +10 -58
  29. package/dist/umd/parser.production.js +1 -1
  30. package/dist/umd/promisify.development.js +5 -31
  31. package/dist/umd/promisify.production.js +1 -1
  32. package/dist/umd/vest.development.js +253 -1066
  33. package/dist/umd/vest.production.js +1 -1
  34. package/enforce_compose/package.json +9 -0
  35. package/enforce_compounds/package.json +9 -0
  36. package/enforce_schema/package.json +9 -0
  37. package/package.json +80 -79
  38. package/tsconfig.json +85 -1
  39. package/types/classnames.d.ts +1 -0
  40. package/types/classnames.d.ts.map +1 -0
  41. package/types/enforce_compose.d.ts +2 -0
  42. package/types/enforce_compose.d.ts.map +1 -0
  43. package/types/enforce_compounds.d.ts +2 -0
  44. package/types/enforce_compounds.d.ts.map +1 -0
  45. package/types/enforce_schema.d.ts +2 -0
  46. package/types/enforce_schema.d.ts.map +1 -0
  47. package/types/parser.d.ts +1 -0
  48. package/types/parser.d.ts.map +1 -0
  49. package/types/promisify.d.ts +1 -0
  50. package/types/promisify.d.ts.map +1 -0
  51. package/types/vest.d.ts +40 -37
  52. package/types/vest.d.ts.map +1 -0
  53. package/dist/cjs/compose.js +0 -7
  54. package/dist/cjs/compounds.js +0 -7
  55. package/dist/cjs/enforce/compose.development.js +0 -60
  56. package/dist/cjs/enforce/compose.production.js +0 -1
  57. package/dist/cjs/enforce/compounds.development.js +0 -92
  58. package/dist/cjs/enforce/compounds.production.js +0 -1
  59. package/dist/cjs/enforce/package.json +0 -1
  60. package/dist/cjs/enforce/schema.development.js +0 -92
  61. package/dist/cjs/enforce/schema.production.js +0 -1
  62. package/dist/cjs/schema.js +0 -7
  63. package/dist/es/enforce/compose.development.js +0 -58
  64. package/dist/es/enforce/compose.production.js +0 -1
  65. package/dist/es/enforce/compounds.development.js +0 -90
  66. package/dist/es/enforce/compounds.production.js +0 -1
  67. package/dist/es/enforce/package.json +0 -1
  68. package/dist/es/enforce/schema.development.js +0 -88
  69. package/dist/es/enforce/schema.production.js +0 -1
  70. package/dist/umd/enforce/compose.development.js +0 -736
  71. package/dist/umd/enforce/compose.production.js +0 -1
  72. package/dist/umd/enforce/compounds.development.js +0 -762
  73. package/dist/umd/enforce/compounds.production.js +0 -1
  74. package/dist/umd/enforce/schema.development.js +0 -768
  75. package/dist/umd/enforce/schema.production.js +0 -1
  76. package/enforce/compose/package.json +0 -9
  77. package/enforce/compounds/package.json +0 -9
  78. package/enforce/schema/package.json +0 -9
  79. package/types/enforce/compose.d.ts +0 -126
  80. package/types/enforce/compounds.d.ts +0 -138
  81. package/types/enforce/schema.d.ts +0 -143
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vest.d.ts","sourceRoot":"","sources":["../src/vest.ts","../src/core/suite/produce/summaryGenerators/SuiteSummaryTypes.ts","../src/core/test/lib/shouldUseErrorAsMessage.ts","../src/hooks/optionalFields.ts","../src/core/isolate/isolateCursor.ts","../src/core/isolate/IsolateTypes.ts","../src/hooks/mode/Modes.ts","../src/core/isolate/generateIsolate.ts","../src/core/ctx/ctx.ts","../src/core/isolate/isolateHooks.ts","../src/core/test/key.ts","../src/core/isolate/isolate.ts","../src/core/suite/produce/summaryGenerators/helpers/matchingFieldName.ts","../src/core/suite/hasRemainingTests.ts","../src/core/suite/produce/produceSuiteRunResult.ts","../src/core/test/omitOptionalFields.ts","../src/core/test/lib/removeTestFromState.ts","../src/core/suite/produce/runCallbacks.ts","../src/core/vestBus.ts","../src/core/suite/create.ts","../src/core/suite/produce/Severity.ts","../src/core/suite/produce/summaryGenerators/helpers/matchingGroupName.ts","../src/core/suite/produce/summaryGenerators/helpers/nonMatchingSeverityProfile.ts","../src/core/suite/produce/summaryGenerators/hasFailuresByTestObjects.ts","../src/core/suite/produce/summaryGenerators/shouldAddValidProperty.ts","../src/core/suite/produce/summaryGenerators/genTestsSummary.ts","../src/core/suite/produce/summarySelectors/collectFailures.ts","../src/core/suite/produce/summarySelectors/suiteSelectors.ts","../src/core/suite/produce/produceSuiteResult.ts","../src/core/state/createStateRef.ts","../src/core/state/stateHooks.ts","../src/core/test/VestTest.ts","../src/core/isolate/isolates/each.ts","../src/hooks/hookErrors.ts","../src/core/isolate/isolates/skipWhen.ts","../src/hooks/exclusive.ts","../src/core/isolate/isolates/group.ts","../src/hooks/include.ts","../src/hooks/mode/mode.ts","../src/core/isolate/isolates/omitWhen.ts","../src/core/test/lib/isSameProfileTest.ts","../src/core/test/lib/cancelOverriddenPendingTest.ts","../src/core/test/runAsyncTest.ts","../src/core/test/runSyncTest.ts","../src/core/test/lib/registerTest.ts","../src/core/test/lib/useTestAtCursor.ts","../src/core/test/lib/registerPrevRunTest.ts","../src/core/test/test.memo.ts","../src/core/test/test.ts","../src/hooks/warn.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoB9B,QAAA,MAAM,OAAO,qBAAqB,CAAC;AAEnC,OAAO,wIAiBN,CAAC;AAEF,YAAY,8DAA8D,CAAC"}
@@ -1,7 +0,0 @@
1
- 'use strict'
2
-
3
- if (process.env.NODE_ENV === 'production') {
4
- module.exports = require('./compose.production.js');
5
- } else {
6
- module.exports = require('./compose.development.js');
7
- }
@@ -1,7 +0,0 @@
1
- 'use strict'
2
-
3
- if (process.env.NODE_ENV === 'production') {
4
- module.exports = require('./compounds.production.js');
5
- } else {
6
- module.exports = require('./compounds.development.js');
7
- }
@@ -1,60 +0,0 @@
1
- 'use strict';
2
-
3
- var vestUtils = require('vest-utils');
4
- var n4s = require('n4s');
5
-
6
- function ruleReturn(pass, message) {
7
- var output = { pass: pass };
8
- if (message) {
9
- output.message = message;
10
- }
11
- return output;
12
- }
13
- function failing() {
14
- return ruleReturn(false);
15
- }
16
- function passing() {
17
- return ruleReturn(true);
18
- }
19
- function defaultToPassing(callback) {
20
- return vestUtils.defaultTo(callback, passing());
21
- }
22
-
23
- function runLazyRule(lazyRule, currentValue) {
24
- try {
25
- return lazyRule.run(currentValue);
26
- }
27
- catch (_a) {
28
- return failing();
29
- }
30
- }
31
-
32
- /* eslint-disable max-lines-per-function */
33
- function compose() {
34
- var composites = [];
35
- for (var _i = 0; _i < arguments.length; _i++) {
36
- composites[_i] = arguments[_i];
37
- }
38
- return vestUtils.assign(function (value) {
39
- var res = run(value);
40
- vestUtils.invariant(res.pass, vestUtils.StringObject(res.message));
41
- }, {
42
- run: run,
43
- test: function (value) { return run(value).pass; }
44
- });
45
- function run(value) {
46
- return n4s.ctx.run({ value: value }, function () {
47
- return defaultToPassing(vestUtils.mapFirst(composites, function (composite, breakout) {
48
- /* HACK: Just a small white lie. ~~HELP WANTED~~.
49
- The ideal is that instead of `LazyRuleRunners` We would simply use `Lazy` to begin with.
50
- The problem is that lazy rules can't really be passed to this function due to some generic hell
51
- so we're limiting it to a small set of functions.
52
- */
53
- var res = runLazyRule(composite, value);
54
- breakout(!res.pass, res);
55
- }));
56
- });
57
- }
58
- }
59
-
60
- module.exports = compose;
@@ -1 +0,0 @@
1
- "use strict";var n=require("vest-utils"),t=require("n4s");function r(n,t){return n={pass:n},t&&(n.message=t),n}function u(t){return n.defaultTo(t,r(!0))}function e(n,t){try{return n.run(t)}catch(n){return r(!1)}}module.exports=function(){function r(r){return t.ctx.run({value:r},(function(){return u(n.mapFirst(s,(function(n,t){t(!(n=e(n,r)).pass,n)})))}))}for(var s=[],i=0;i<arguments.length;i++)s[i]=arguments[i];return n.assign((function(t){t=r(t),n.invariant(t.pass,n.StringObject(t.message))}),{run:r,test:function(n){return r(n).pass}})};
@@ -1,92 +0,0 @@
1
- 'use strict';
2
-
3
- var vestUtils = require('vest-utils');
4
- var n4s = require('n4s');
5
-
6
- function ruleReturn(pass, message) {
7
- var output = { pass: pass };
8
- if (message) {
9
- output.message = message;
10
- }
11
- return output;
12
- }
13
- function failing() {
14
- return ruleReturn(false);
15
- }
16
- function passing() {
17
- return ruleReturn(true);
18
- }
19
- function defaultToFailing(callback) {
20
- return vestUtils.defaultTo(callback, failing());
21
- }
22
- function defaultToPassing(callback) {
23
- return vestUtils.defaultTo(callback, passing());
24
- }
25
-
26
- function runLazyRule(lazyRule, currentValue) {
27
- try {
28
- return lazyRule.run(currentValue);
29
- }
30
- catch (_a) {
31
- return failing();
32
- }
33
- }
34
-
35
- function allOf(value) {
36
- var rules = [];
37
- for (var _i = 1; _i < arguments.length; _i++) {
38
- rules[_i - 1] = arguments[_i];
39
- }
40
- return defaultToPassing(vestUtils.mapFirst(rules, function (rule, breakout) {
41
- var res = runLazyRule(rule, value);
42
- breakout(!res.pass, res);
43
- }));
44
- }
45
-
46
- function anyOf(value) {
47
- var rules = [];
48
- for (var _i = 1; _i < arguments.length; _i++) {
49
- rules[_i - 1] = arguments[_i];
50
- }
51
- return defaultToFailing(vestUtils.mapFirst(rules, function (rule, breakout) {
52
- var res = runLazyRule(rule, value);
53
- breakout(res.pass, res);
54
- }));
55
- }
56
-
57
- function noneOf(value) {
58
- var rules = [];
59
- for (var _i = 1; _i < arguments.length; _i++) {
60
- rules[_i - 1] = arguments[_i];
61
- }
62
- return defaultToPassing(vestUtils.mapFirst(rules, function (rule, breakout) {
63
- var res = runLazyRule(rule, value);
64
- breakout(res.pass, failing());
65
- }));
66
- }
67
-
68
- function equals(value, arg1) {
69
- return value === arg1;
70
- }
71
- vestUtils.bindNot(equals);
72
-
73
- var REQUIRED_COUNT = 1;
74
- function oneOf(value) {
75
- var rules = [];
76
- for (var _i = 1; _i < arguments.length; _i++) {
77
- rules[_i - 1] = arguments[_i];
78
- }
79
- var passingCount = 0;
80
- rules.some(function (rule) {
81
- var res = runLazyRule(rule, value);
82
- if (res.pass) {
83
- passingCount++;
84
- }
85
- if (vestUtils.greaterThan(passingCount, REQUIRED_COUNT)) {
86
- return false;
87
- }
88
- });
89
- return ruleReturn(equals(passingCount, REQUIRED_COUNT));
90
- }
91
-
92
- n4s.enforce.extend({ allOf: allOf, anyOf: anyOf, noneOf: noneOf, oneOf: oneOf });
@@ -1 +0,0 @@
1
- "use strict";var n=require("vest-utils"),r=require("n4s");function t(n,r){return n={pass:n},r&&(n.message=r),n}function e(){return t(!1)}function u(r){return n.defaultTo(r,e())}function f(r){return n.defaultTo(r,t(!0))}function o(n,r){try{return n.run(r)}catch(n){return e()}}function i(n,r){return n===r}n.bindNot(i);r.enforce.extend({allOf:function(r){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return f(n.mapFirst(t,(function(n,t){t(!(n=o(n,r)).pass,n)})))},anyOf:function(r){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return u(n.mapFirst(t,(function(n,t){t((n=o(n,r)).pass,n)})))},noneOf:function(r){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return f(n.mapFirst(t,(function(n,t){t((n=o(n,r)).pass,e())})))},oneOf:function(r){for(var e=[],u=1;u<arguments.length;u++)e[u-1]=arguments[u];var f=0;return e.some((function(t){if(o(t,r).pass&&f++,n.greaterThan(f,1))return!1})),t(i(f,1))}});
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,92 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var vestUtils = require('vest-utils');
6
- var n4s = require('n4s');
7
-
8
- function ruleReturn(pass, message) {
9
- var output = { pass: pass };
10
- if (message) {
11
- output.message = message;
12
- }
13
- return output;
14
- }
15
- function failing() {
16
- return ruleReturn(false);
17
- }
18
- function passing() {
19
- return ruleReturn(true);
20
- }
21
- function defaultToPassing(callback) {
22
- return vestUtils.defaultTo(callback, passing());
23
- }
24
-
25
- function runLazyRule(lazyRule, currentValue) {
26
- try {
27
- return lazyRule.run(currentValue);
28
- }
29
- catch (_a) {
30
- return failing();
31
- }
32
- }
33
-
34
- function isArrayOf(inputArray, currentRule) {
35
- return defaultToPassing(vestUtils.mapFirst(inputArray, function (currentValue, breakout, index) {
36
- var res = n4s.ctx.run({ value: currentValue, set: true, meta: { index: index } }, function () { return runLazyRule(currentRule, currentValue); });
37
- breakout(!res.pass, res);
38
- }));
39
- }
40
-
41
- function loose(inputObject, shapeObject) {
42
- var _loop_1 = function (key) {
43
- var currentValue = inputObject[key];
44
- var currentRule = shapeObject[key];
45
- var res = n4s.ctx.run({ value: currentValue, set: true, meta: { key: key } }, function () {
46
- return runLazyRule(currentRule, currentValue);
47
- });
48
- if (!res.pass) {
49
- return { value: res };
50
- }
51
- };
52
- for (var key in shapeObject) {
53
- var state_1 = _loop_1(key);
54
- if (typeof state_1 === "object")
55
- return state_1.value;
56
- }
57
- return passing();
58
- }
59
-
60
- function optional(value, ruleChain) {
61
- if (vestUtils.isNullish(value)) {
62
- return passing();
63
- }
64
- return runLazyRule(ruleChain, value);
65
- }
66
-
67
- function shape(inputObject, shapeObject) {
68
- var baseRes = loose(inputObject, shapeObject);
69
- if (!baseRes.pass) {
70
- return baseRes;
71
- }
72
- for (var key in inputObject) {
73
- if (!vestUtils.hasOwnProperty(shapeObject, key)) {
74
- return failing();
75
- }
76
- }
77
- return passing();
78
- }
79
-
80
- // Help needed improving the typings of this file.
81
- // Ideally, we'd be able to extend ShapeObject, but that's not possible.
82
- function partial(shapeObject) {
83
- var output = {};
84
- for (var key in shapeObject) {
85
- output[key] = n4s.enforce.optional(shapeObject[key]);
86
- }
87
- return output;
88
- }
89
-
90
- n4s.enforce.extend({ isArrayOf: isArrayOf, loose: loose, optional: optional, shape: shape });
91
-
92
- exports.partial = partial;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("vest-utils"),n=require("n4s");function e(r,n){return r={pass:r},n&&(r.message=n),r}function t(){return e(!1)}function u(){return e(!0)}function i(r,n){try{return r.run(n)}catch(r){return t()}}function o(r,e){var t,o=function(t){var u=r[t],o=e[t];if(!(t=n.ctx.run({value:u,set:!0,meta:{key:t}},(function(){return i(o,u)}))).pass)return{value:t}};for(t in e){var a=o(t);if("object"==typeof a)return a.value}return u()}n.enforce.extend({isArrayOf:function(e,t){return function(n){return r.defaultTo(n,u())}(r.mapFirst(e,(function(r,e,u){e(!(u=n.ctx.run({value:r,set:!0,meta:{index:u}},(function(){return i(t,r)}))).pass,u)})))},loose:o,optional:function(n,e){return r.isNullish(n)?u():i(e,n)},shape:function(n,e){var i=o(n,e);if(!i.pass)return i;for(var a in n)if(!r.hasOwnProperty(e,a))return t();return u()}}),exports.partial=function(r){var e,t={};for(e in r)t[e]=n.enforce.optional(r[e]);return t};
@@ -1,7 +0,0 @@
1
- 'use strict'
2
-
3
- if (process.env.NODE_ENV === 'production') {
4
- module.exports = require('./schema.production.js');
5
- } else {
6
- module.exports = require('./schema.development.js');
7
- }
@@ -1,58 +0,0 @@
1
- import { defaultTo, assign, mapFirst, invariant, StringObject } from 'vest-utils';
2
- import { ctx } from 'n4s';
3
-
4
- function ruleReturn(pass, message) {
5
- var output = { pass: pass };
6
- if (message) {
7
- output.message = message;
8
- }
9
- return output;
10
- }
11
- function failing() {
12
- return ruleReturn(false);
13
- }
14
- function passing() {
15
- return ruleReturn(true);
16
- }
17
- function defaultToPassing(callback) {
18
- return defaultTo(callback, passing());
19
- }
20
-
21
- function runLazyRule(lazyRule, currentValue) {
22
- try {
23
- return lazyRule.run(currentValue);
24
- }
25
- catch (_a) {
26
- return failing();
27
- }
28
- }
29
-
30
- /* eslint-disable max-lines-per-function */
31
- function compose() {
32
- var composites = [];
33
- for (var _i = 0; _i < arguments.length; _i++) {
34
- composites[_i] = arguments[_i];
35
- }
36
- return assign(function (value) {
37
- var res = run(value);
38
- invariant(res.pass, StringObject(res.message));
39
- }, {
40
- run: run,
41
- test: function (value) { return run(value).pass; }
42
- });
43
- function run(value) {
44
- return ctx.run({ value: value }, function () {
45
- return defaultToPassing(mapFirst(composites, function (composite, breakout) {
46
- /* HACK: Just a small white lie. ~~HELP WANTED~~.
47
- The ideal is that instead of `LazyRuleRunners` We would simply use `Lazy` to begin with.
48
- The problem is that lazy rules can't really be passed to this function due to some generic hell
49
- so we're limiting it to a small set of functions.
50
- */
51
- var res = runLazyRule(composite, value);
52
- breakout(!res.pass, res);
53
- }));
54
- });
55
- }
56
- }
57
-
58
- export default compose;
@@ -1 +0,0 @@
1
- import{ctx as n}from"n4s";import{defaultTo as t,assign as r,mapFirst as u,invariant as s,StringObject as e}from"vest-utils";function o(n,t){return n={pass:n},t&&(n.message=t),n}export default function(){function a(r){return n.run({value:r},(function(){return t(u(f,(function(n,t){try{var u=n.run(r)}catch(n){u=o(!1)}t(!u.pass,u)})),o(!0))}))}for(var f=[],i=0;i<arguments.length;i++)f[i]=arguments[i];return r((function(n){n=a(n),s(n.pass,e(n.message))}),{run:a,test:function(n){return a(n).pass}})}
@@ -1,90 +0,0 @@
1
- import { defaultTo, mapFirst, bindNot, greaterThan } from 'vest-utils';
2
- import { enforce } from 'n4s';
3
-
4
- function ruleReturn(pass, message) {
5
- var output = { pass: pass };
6
- if (message) {
7
- output.message = message;
8
- }
9
- return output;
10
- }
11
- function failing() {
12
- return ruleReturn(false);
13
- }
14
- function passing() {
15
- return ruleReturn(true);
16
- }
17
- function defaultToFailing(callback) {
18
- return defaultTo(callback, failing());
19
- }
20
- function defaultToPassing(callback) {
21
- return defaultTo(callback, passing());
22
- }
23
-
24
- function runLazyRule(lazyRule, currentValue) {
25
- try {
26
- return lazyRule.run(currentValue);
27
- }
28
- catch (_a) {
29
- return failing();
30
- }
31
- }
32
-
33
- function allOf(value) {
34
- var rules = [];
35
- for (var _i = 1; _i < arguments.length; _i++) {
36
- rules[_i - 1] = arguments[_i];
37
- }
38
- return defaultToPassing(mapFirst(rules, function (rule, breakout) {
39
- var res = runLazyRule(rule, value);
40
- breakout(!res.pass, res);
41
- }));
42
- }
43
-
44
- function anyOf(value) {
45
- var rules = [];
46
- for (var _i = 1; _i < arguments.length; _i++) {
47
- rules[_i - 1] = arguments[_i];
48
- }
49
- return defaultToFailing(mapFirst(rules, function (rule, breakout) {
50
- var res = runLazyRule(rule, value);
51
- breakout(res.pass, res);
52
- }));
53
- }
54
-
55
- function noneOf(value) {
56
- var rules = [];
57
- for (var _i = 1; _i < arguments.length; _i++) {
58
- rules[_i - 1] = arguments[_i];
59
- }
60
- return defaultToPassing(mapFirst(rules, function (rule, breakout) {
61
- var res = runLazyRule(rule, value);
62
- breakout(res.pass, failing());
63
- }));
64
- }
65
-
66
- function equals(value, arg1) {
67
- return value === arg1;
68
- }
69
- bindNot(equals);
70
-
71
- var REQUIRED_COUNT = 1;
72
- function oneOf(value) {
73
- var rules = [];
74
- for (var _i = 1; _i < arguments.length; _i++) {
75
- rules[_i - 1] = arguments[_i];
76
- }
77
- var passingCount = 0;
78
- rules.some(function (rule) {
79
- var res = runLazyRule(rule, value);
80
- if (res.pass) {
81
- passingCount++;
82
- }
83
- if (greaterThan(passingCount, REQUIRED_COUNT)) {
84
- return false;
85
- }
86
- });
87
- return ruleReturn(equals(passingCount, REQUIRED_COUNT));
88
- }
89
-
90
- enforce.extend({ allOf: allOf, anyOf: anyOf, noneOf: noneOf, oneOf: oneOf });
@@ -1 +0,0 @@
1
- import{enforce as n}from"n4s";import{defaultTo as r,mapFirst as t,bindNot as f,greaterThan as o}from"vest-utils";function u(n,r){return n={pass:n},r&&(n.message=r),n}function e(n,r){try{return n.run(r)}catch(n){return u(!1)}}f((function(n,r){return n===r})),n.extend({allOf:function(n){for(var f=[],o=1;o<arguments.length;o++)f[o-1]=arguments[o];return r(t(f,(function(r,t){t(!(r=e(r,n)).pass,r)})),u(!0))},anyOf:function(n){for(var f=[],o=1;o<arguments.length;o++)f[o-1]=arguments[o];return r(t(f,(function(r,t){t((r=e(r,n)).pass,r)})),u(!1))},noneOf:function(n){for(var f=[],o=1;o<arguments.length;o++)f[o-1]=arguments[o];return r(t(f,(function(r,t){t((r=e(r,n)).pass,u(!1))})),u(!0))},oneOf:function(n){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];var f=0;return r.some((function(r){if(e(r,n).pass&&f++,o(f,1))return!1})),u(1===f)}});
@@ -1 +0,0 @@
1
- {"type":"module"}
@@ -1,88 +0,0 @@
1
- import { defaultTo, mapFirst, isNullish, hasOwnProperty } from 'vest-utils';
2
- import { ctx, enforce } from 'n4s';
3
-
4
- function ruleReturn(pass, message) {
5
- var output = { pass: pass };
6
- if (message) {
7
- output.message = message;
8
- }
9
- return output;
10
- }
11
- function failing() {
12
- return ruleReturn(false);
13
- }
14
- function passing() {
15
- return ruleReturn(true);
16
- }
17
- function defaultToPassing(callback) {
18
- return defaultTo(callback, passing());
19
- }
20
-
21
- function runLazyRule(lazyRule, currentValue) {
22
- try {
23
- return lazyRule.run(currentValue);
24
- }
25
- catch (_a) {
26
- return failing();
27
- }
28
- }
29
-
30
- function isArrayOf(inputArray, currentRule) {
31
- return defaultToPassing(mapFirst(inputArray, function (currentValue, breakout, index) {
32
- var res = ctx.run({ value: currentValue, set: true, meta: { index: index } }, function () { return runLazyRule(currentRule, currentValue); });
33
- breakout(!res.pass, res);
34
- }));
35
- }
36
-
37
- function loose(inputObject, shapeObject) {
38
- var _loop_1 = function (key) {
39
- var currentValue = inputObject[key];
40
- var currentRule = shapeObject[key];
41
- var res = ctx.run({ value: currentValue, set: true, meta: { key: key } }, function () {
42
- return runLazyRule(currentRule, currentValue);
43
- });
44
- if (!res.pass) {
45
- return { value: res };
46
- }
47
- };
48
- for (var key in shapeObject) {
49
- var state_1 = _loop_1(key);
50
- if (typeof state_1 === "object")
51
- return state_1.value;
52
- }
53
- return passing();
54
- }
55
-
56
- function optional(value, ruleChain) {
57
- if (isNullish(value)) {
58
- return passing();
59
- }
60
- return runLazyRule(ruleChain, value);
61
- }
62
-
63
- function shape(inputObject, shapeObject) {
64
- var baseRes = loose(inputObject, shapeObject);
65
- if (!baseRes.pass) {
66
- return baseRes;
67
- }
68
- for (var key in inputObject) {
69
- if (!hasOwnProperty(shapeObject, key)) {
70
- return failing();
71
- }
72
- }
73
- return passing();
74
- }
75
-
76
- // Help needed improving the typings of this file.
77
- // Ideally, we'd be able to extend ShapeObject, but that's not possible.
78
- function partial(shapeObject) {
79
- var output = {};
80
- for (var key in shapeObject) {
81
- output[key] = enforce.optional(shapeObject[key]);
82
- }
83
- return output;
84
- }
85
-
86
- enforce.extend({ isArrayOf: isArrayOf, loose: loose, optional: optional, shape: shape });
87
-
88
- export { partial };
@@ -1 +0,0 @@
1
- import{ctx as r,enforce as n}from"n4s";import{defaultTo as t,mapFirst as e,isNullish as u,hasOwnProperty as o}from"vest-utils";function i(r,n){return r={pass:r},n&&(r.message=n),r}function a(r,n){try{return r.run(n)}catch(r){return i(!1)}}function f(n,t){function e(e){var u=n[e],o=t[e];if(!(e=r.run({value:u,set:!0,meta:{key:e}},(function(){return a(o,u)}))).pass)return{value:e}}for(var u in t){var o=e(u);if("object"==typeof o)return o.value}return i(!0)}n.extend({isArrayOf:function(n,u){return t(e(n,(function(n,t,e){t(!(e=r.run({value:n,set:!0,meta:{index:e}},(function(){return a(u,n)}))).pass,e)})),i(!0))},loose:f,optional:function(r,n){return u(r)?i(!0):a(n,r)},shape:function(r,n){var t=f(r,n);if(!t.pass)return t;for(var e in r)if(!o(n,e))return i(!1);return i(!0)}});export function partial(r){var t,e={};for(t in r)e[t]=n.optional(r[t]);return e}