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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +70 -52
  2. package/README.md +2 -112
  3. package/dist/cjs/compose.js +7 -0
  4. package/dist/cjs/compounds.js +7 -0
  5. package/dist/cjs/enforce/compose.development.js +139 -0
  6. package/dist/cjs/enforce/compose.production.js +1 -0
  7. package/dist/cjs/enforce/compounds.development.js +132 -0
  8. package/dist/cjs/enforce/compounds.production.js +1 -0
  9. package/dist/cjs/enforce/package.json +1 -0
  10. package/dist/cjs/enforce/schema.development.js +144 -0
  11. package/dist/cjs/enforce/schema.production.js +1 -0
  12. package/dist/cjs/schema.js +7 -0
  13. package/dist/cjs/vest.development.js +504 -1034
  14. package/dist/cjs/vest.production.js +1 -1
  15. package/dist/es/enforce/compose.development.js +137 -0
  16. package/dist/es/enforce/compose.production.js +1 -0
  17. package/dist/es/enforce/compounds.development.js +130 -0
  18. package/dist/es/enforce/compounds.production.js +1 -0
  19. package/dist/es/enforce/package.json +1 -0
  20. package/dist/es/enforce/schema.development.js +140 -0
  21. package/dist/es/enforce/schema.production.js +1 -0
  22. package/dist/es/vest.development.js +497 -1033
  23. package/dist/es/vest.production.js +1 -1
  24. package/dist/umd/enforce/compose.development.js +143 -0
  25. package/dist/umd/enforce/compose.production.js +1 -0
  26. package/dist/umd/enforce/compounds.development.js +136 -0
  27. package/dist/umd/enforce/compounds.production.js +1 -0
  28. package/dist/umd/enforce/schema.development.js +148 -0
  29. package/dist/umd/enforce/schema.production.js +1 -0
  30. package/dist/umd/vest.development.js +1693 -2226
  31. package/dist/umd/vest.production.js +1 -1
  32. package/enforce/compose/package.json +7 -0
  33. package/enforce/compounds/package.json +7 -0
  34. package/enforce/schema/package.json +7 -0
  35. package/package.json +107 -13
  36. package/testUtils/mockThrowError.ts +16 -0
  37. package/types/enforce/compose.d.ts +134 -0
  38. package/types/enforce/compounds.d.ts +146 -0
  39. package/types/enforce/schema.d.ts +151 -0
  40. package/types/vest.d.ts +31 -203
@@ -0,0 +1,144 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var n4s = require('n4s');
6
+
7
+ function mapFirst(array, callback) {
8
+ var broke = false;
9
+ var breakoutValue = null;
10
+ for (var i = 0; i < array.length; i++) {
11
+ callback(array[i], breakout, i);
12
+ if (broke) {
13
+ return breakoutValue;
14
+ }
15
+ }
16
+ function breakout(value) {
17
+ broke = true;
18
+ breakoutValue = value;
19
+ }
20
+ }
21
+
22
+ function isFunction(value) {
23
+ return typeof value === 'function';
24
+ }
25
+
26
+ function optionalFunctionValue(value) {
27
+ var args = [];
28
+ for (var _i = 1; _i < arguments.length; _i++) {
29
+ args[_i - 1] = arguments[_i];
30
+ }
31
+ return isFunction(value) ? value.apply(void 0, args) : value;
32
+ }
33
+
34
+ function defaultTo(callback, defaultValue) {
35
+ var _a;
36
+ return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
37
+ }
38
+
39
+ function ruleReturn(pass, message) {
40
+ var output = { pass: pass };
41
+ if (message) {
42
+ output.message = message;
43
+ }
44
+ return output;
45
+ }
46
+ function failing() {
47
+ return ruleReturn(false);
48
+ }
49
+ function passing() {
50
+ return ruleReturn(true);
51
+ }
52
+ function defaultToPassing(callback) {
53
+ return defaultTo(callback, passing());
54
+ }
55
+
56
+ function runLazyRule(lazyRule, currentValue) {
57
+ try {
58
+ return lazyRule.run(currentValue);
59
+ }
60
+ catch (_a) {
61
+ return failing();
62
+ }
63
+ }
64
+
65
+ function isArrayOf(inputArray, currentRule) {
66
+ return defaultToPassing(mapFirst(inputArray, function (currentValue, breakout, index) {
67
+ var res = n4s.ctx.run({ value: currentValue, set: true, meta: { index: index } }, function () { return runLazyRule(currentRule, currentValue); });
68
+ if (!res.pass) {
69
+ breakout(res);
70
+ }
71
+ }));
72
+ }
73
+
74
+ function loose(inputObject, shapeObject) {
75
+ var _loop_1 = function (key) {
76
+ var currentValue = inputObject[key];
77
+ var currentRule = shapeObject[key];
78
+ var res = n4s.ctx.run({ value: currentValue, set: true, meta: { key: key } }, function () {
79
+ return runLazyRule(currentRule, currentValue);
80
+ });
81
+ if (!res.pass) {
82
+ return { value: res };
83
+ }
84
+ };
85
+ for (var key in shapeObject) {
86
+ var state_1 = _loop_1(key);
87
+ if (typeof state_1 === "object")
88
+ return state_1.value;
89
+ }
90
+ return passing();
91
+ }
92
+
93
+ function isNull(value) {
94
+ return value === null;
95
+ }
96
+
97
+ function isUndefined(value) {
98
+ return value === undefined;
99
+ }
100
+
101
+ function isNullish(value) {
102
+ return isNull(value) || isUndefined(value);
103
+ }
104
+
105
+ function optional(value, ruleChain) {
106
+ if (isNullish(value)) {
107
+ return passing();
108
+ }
109
+ return runLazyRule(ruleChain, value);
110
+ }
111
+
112
+ /**
113
+ * A safe hasOwnProperty access
114
+ */
115
+ function hasOwnProperty(obj, key) {
116
+ return Object.prototype.hasOwnProperty.call(obj, key);
117
+ }
118
+
119
+ function shape(inputObject, shapeObject) {
120
+ var baseRes = loose(inputObject, shapeObject);
121
+ if (!baseRes.pass) {
122
+ return baseRes;
123
+ }
124
+ for (var key in inputObject) {
125
+ if (!hasOwnProperty(shapeObject, key)) {
126
+ return failing();
127
+ }
128
+ }
129
+ return passing();
130
+ }
131
+
132
+ // Help needed improving the typings of this file.
133
+ // Ideally, we'd be able to extend IShapeObject, but that's not possible.
134
+ function partial(shapeObject) {
135
+ var output = {};
136
+ for (var key in shapeObject) {
137
+ output[key] = n4s.enforce.optional(shapeObject[key]);
138
+ }
139
+ return output;
140
+ }
141
+
142
+ n4s.enforce.extend({ isArrayOf: isArrayOf, loose: loose, optional: optional, shape: shape });
143
+
144
+ exports.partial = partial;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("n4s");function r(n){return"function"==typeof n}function t(n,t){var e;return null!==(e=function(n){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return r(n)?n.apply(void 0,t):n}(n))&&void 0!==e?e:t}function e(n,r){return n={pass:n},r&&(n.message=r),n}function u(){return e(!1)}function o(){return e(!0)}function i(n,r){try{return n.run(r)}catch(n){return u()}}function f(r,t){var e,u=function(e){var u=r[e],o=t[e];if(!(e=n.ctx.run({value:u,set:!0,meta:{key:e}},(function(){return i(o,u)}))).pass)return{value:e}};for(e in t){var f=u(e);if("object"==typeof f)return f.value}return o()}function c(n,r){return Object.prototype.hasOwnProperty.call(n,r)}n.enforce.extend({isArrayOf:function(r,e){return function(n){return t(n,o())}(function(n,r){function t(n){e=!0,u=n}for(var e=!1,u=null,o=0;o<n.length;o++)if(r(n[o],t,o),e)return u}(r,(function(r,t,u){(u=n.ctx.run({value:r,set:!0,meta:{index:u}},(function(){return i(e,r)}))).pass||t(u)})))},loose:f,optional:function(n,r){return function(n){return function(n){return null===n}(n)||function(n){return void 0===n}(n)}(n)?o():i(r,n)},shape:function(n,r){var t=f(n,r);if(!t.pass)return t;for(var e in n)if(!c(r,e))return u();return o()}}),exports.partial=function(r){var t,e={};for(t in r)e[t]=n.enforce.optional(r[t]);return e};
@@ -0,0 +1,7 @@
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
+ }