vest 4.4.1 → 4.4.2-dev-afe5de
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/dist/cjs/classnames.development.js +9 -60
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +6 -53
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +16 -71
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +6 -58
- package/dist/cjs/enforce/schema.production.js +1 -1
- package/dist/cjs/parser.development.js +8 -59
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/promisify.development.js +2 -26
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +94 -293
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +1 -52
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +4 -51
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/enforce/compounds.development.js +11 -66
- package/dist/es/enforce/compounds.production.js +1 -1
- package/dist/es/enforce/schema.development.js +2 -54
- package/dist/es/enforce/schema.production.js +1 -1
- package/dist/es/parser.development.js +1 -52
- package/dist/es/parser.production.js +1 -1
- package/dist/es/promisify.development.js +1 -25
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +19 -218
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +13 -13
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +121 -121
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +180 -184
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +132 -132
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +13 -13
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/vest.development.js +277 -277
- package/dist/umd/vest.production.js +1 -1
- package/package.json +4 -3
- package/testUtils/mockThrowError.ts +2 -1
- package/testUtils/suiteDummy.ts +1 -1
- package/testUtils/testObjects.ts +0 -8
- package/types/enforce/compose.d.ts +14 -30
- package/types/enforce/compounds.d.ts +14 -30
- package/types/enforce/schema.d.ts +14 -30
- package/types/vest.d.ts +4 -3
- package/testUtils/itWithContext.ts +0 -23
|
@@ -4,12 +4,6 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vest = {}));
|
|
5
5
|
}(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
var assign = Object.assign;
|
|
8
|
-
|
|
9
|
-
function isFunction(value) {
|
|
10
|
-
return typeof value === 'function';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
7
|
function bindNot(fn) {
|
|
14
8
|
return function () {
|
|
15
9
|
var args = [];
|
|
@@ -20,6 +14,69 @@
|
|
|
20
14
|
};
|
|
21
15
|
}
|
|
22
16
|
|
|
17
|
+
function isNumeric(value) {
|
|
18
|
+
var str = String(value);
|
|
19
|
+
var num = Number(value);
|
|
20
|
+
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
21
|
+
return Boolean(result);
|
|
22
|
+
}
|
|
23
|
+
var isNotNumeric = bindNot(isNumeric);
|
|
24
|
+
|
|
25
|
+
function numberEquals(value, eq) {
|
|
26
|
+
return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
|
|
27
|
+
}
|
|
28
|
+
var numberNotEquals = bindNot(numberEquals);
|
|
29
|
+
|
|
30
|
+
function lengthEquals(value, arg1) {
|
|
31
|
+
return numberEquals(value.length, arg1);
|
|
32
|
+
}
|
|
33
|
+
var lengthNotEquals = bindNot(lengthEquals);
|
|
34
|
+
|
|
35
|
+
function greaterThan(value, gt) {
|
|
36
|
+
return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function longerThan(value, arg1) {
|
|
40
|
+
return greaterThan(value.length, arg1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Creates a cache function
|
|
45
|
+
*/
|
|
46
|
+
function createCache(maxSize) {
|
|
47
|
+
if (maxSize === void 0) { maxSize = 1; }
|
|
48
|
+
var cacheStorage = [];
|
|
49
|
+
var cache = function (deps, cacheAction) {
|
|
50
|
+
var cacheHit = cache.get(deps);
|
|
51
|
+
// cache hit is not null
|
|
52
|
+
if (cacheHit)
|
|
53
|
+
return cacheHit[1];
|
|
54
|
+
var result = cacheAction();
|
|
55
|
+
cacheStorage.unshift([deps.concat(), result]);
|
|
56
|
+
if (longerThan(cacheStorage, maxSize))
|
|
57
|
+
cacheStorage.length = maxSize;
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
// invalidate an item in the cache by its dependencies
|
|
61
|
+
cache.invalidate = function (deps) {
|
|
62
|
+
var index = findIndex(deps);
|
|
63
|
+
if (index > -1)
|
|
64
|
+
cacheStorage.splice(index, 1);
|
|
65
|
+
};
|
|
66
|
+
// Retrieves an item from the cache.
|
|
67
|
+
cache.get = function (deps) {
|
|
68
|
+
return cacheStorage[findIndex(deps)] || null;
|
|
69
|
+
};
|
|
70
|
+
return cache;
|
|
71
|
+
function findIndex(deps) {
|
|
72
|
+
return cacheStorage.findIndex(function (_a) {
|
|
73
|
+
var cachedDeps = _a[0];
|
|
74
|
+
return lengthEquals(deps, cachedDeps.length) &&
|
|
75
|
+
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
23
80
|
function isNull(value) {
|
|
24
81
|
return value === null;
|
|
25
82
|
}
|
|
@@ -35,39 +92,25 @@
|
|
|
35
92
|
}
|
|
36
93
|
var isNotNullish = bindNot(isNullish);
|
|
37
94
|
|
|
38
|
-
function
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function endsWith(value, arg1) {
|
|
43
|
-
return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
|
|
44
|
-
}
|
|
45
|
-
var doesNotEndWith = bindNot(endsWith);
|
|
46
|
-
|
|
47
|
-
function equals(value, arg1) {
|
|
48
|
-
return value === arg1;
|
|
49
|
-
}
|
|
50
|
-
var notEquals = bindNot(equals);
|
|
51
|
-
|
|
52
|
-
function isNumeric(value) {
|
|
53
|
-
var str = String(value);
|
|
54
|
-
var num = Number(value);
|
|
55
|
-
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
56
|
-
return Boolean(result);
|
|
95
|
+
function asArray(possibleArg) {
|
|
96
|
+
return [].concat(possibleArg);
|
|
57
97
|
}
|
|
58
|
-
var isNotNumeric = bindNot(isNumeric);
|
|
59
98
|
|
|
60
|
-
function
|
|
61
|
-
return
|
|
99
|
+
function isFunction(value) {
|
|
100
|
+
return typeof value === 'function';
|
|
62
101
|
}
|
|
63
102
|
|
|
64
|
-
function
|
|
65
|
-
|
|
103
|
+
function optionalFunctionValue(value) {
|
|
104
|
+
var args = [];
|
|
105
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
106
|
+
args[_i - 1] = arguments[_i];
|
|
107
|
+
}
|
|
108
|
+
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
66
109
|
}
|
|
67
|
-
var numberNotEquals = bindNot(numberEquals);
|
|
68
110
|
|
|
69
|
-
function
|
|
70
|
-
|
|
111
|
+
function defaultTo(value, defaultValue) {
|
|
112
|
+
var _a;
|
|
113
|
+
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
|
|
71
114
|
}
|
|
72
115
|
|
|
73
116
|
// The module is named "isArrayValue" since it
|
|
@@ -78,66 +121,159 @@
|
|
|
78
121
|
}
|
|
79
122
|
var isNotArray = bindNot(isArray);
|
|
80
123
|
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
|
|
124
|
+
function last(values) {
|
|
125
|
+
var valuesArray = asArray(values);
|
|
126
|
+
return valuesArray[valuesArray.length - 1];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// This is kind of a map/filter in one function.
|
|
130
|
+
// Normally, behaves like a nested-array map,
|
|
131
|
+
// but returning `null` will drop the element from the array
|
|
132
|
+
function transform(array, cb) {
|
|
133
|
+
var res = [];
|
|
134
|
+
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
|
|
135
|
+
var v = array_1[_i];
|
|
136
|
+
if (isArray(v)) {
|
|
137
|
+
res.push(transform(v, cb));
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
var output = cb(v);
|
|
141
|
+
if (isNotNull(output)) {
|
|
142
|
+
res.push(output);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
84
145
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
146
|
+
return res;
|
|
147
|
+
}
|
|
148
|
+
function valueAtPath(array, path) {
|
|
149
|
+
return getCurrent(array, path)[last(path)];
|
|
150
|
+
}
|
|
151
|
+
function setValueAtPath(array, path, value) {
|
|
152
|
+
var current = getCurrent(array, path);
|
|
153
|
+
current[last(path)] = value;
|
|
154
|
+
return array;
|
|
155
|
+
}
|
|
156
|
+
function flatten(values) {
|
|
157
|
+
return asArray(values).reduce(function (acc, value) {
|
|
158
|
+
if (isArray(value)) {
|
|
159
|
+
return acc.concat(flatten(value));
|
|
160
|
+
}
|
|
161
|
+
return asArray(acc).concat(value);
|
|
162
|
+
}, []);
|
|
163
|
+
}
|
|
164
|
+
function getCurrent(array, path) {
|
|
165
|
+
var current = array;
|
|
166
|
+
for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
|
|
167
|
+
var p = _a[_i];
|
|
168
|
+
current[p] = defaultTo(current[p], []);
|
|
169
|
+
current = current[p];
|
|
88
170
|
}
|
|
89
|
-
return
|
|
171
|
+
return current;
|
|
90
172
|
}
|
|
91
|
-
var notInside = bindNot(inside);
|
|
92
173
|
|
|
93
|
-
function
|
|
94
|
-
return
|
|
174
|
+
function callEach(arr) {
|
|
175
|
+
return arr.forEach(function (fn) { return fn(); });
|
|
95
176
|
}
|
|
96
177
|
|
|
97
|
-
|
|
98
|
-
|
|
178
|
+
/**
|
|
179
|
+
* A safe hasOwnProperty access
|
|
180
|
+
*/
|
|
181
|
+
function hasOwnProperty(obj, key) {
|
|
182
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
99
183
|
}
|
|
100
184
|
|
|
101
|
-
function
|
|
102
|
-
return
|
|
185
|
+
function isPromise(value) {
|
|
186
|
+
return value && isFunction(value.then);
|
|
103
187
|
}
|
|
104
|
-
var isNotBetween = bindNot(isBetween);
|
|
105
188
|
|
|
106
|
-
|
|
107
|
-
|
|
189
|
+
var assign = Object.assign;
|
|
190
|
+
|
|
191
|
+
function invariant(condition,
|
|
192
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
193
|
+
message) {
|
|
194
|
+
if (condition) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
// If message is a string object (rather than string literal)
|
|
198
|
+
// Throw the value directly as a string
|
|
199
|
+
// Alternatively, throw an error with the message
|
|
200
|
+
throw message instanceof String
|
|
201
|
+
? message.valueOf()
|
|
202
|
+
: new Error(message ? optionalFunctionValue(message) : message);
|
|
203
|
+
}
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
205
|
+
function StringObject(value) {
|
|
206
|
+
return new String(optionalFunctionValue(value));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function isStringValue(v) {
|
|
210
|
+
return String(v) === v;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function either(a, b) {
|
|
214
|
+
return !!a !== !!b;
|
|
108
215
|
}
|
|
109
|
-
var isNotBlank = bindNot(isBlank);
|
|
110
216
|
|
|
111
217
|
function isBoolean(value) {
|
|
112
218
|
return !!value === value;
|
|
113
219
|
}
|
|
114
220
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
*/
|
|
120
|
-
function hasOwnProperty(obj, key) {
|
|
121
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
221
|
+
function deferThrow(message) {
|
|
222
|
+
setTimeout(function () {
|
|
223
|
+
throw new Error(message);
|
|
224
|
+
}, 0);
|
|
122
225
|
}
|
|
123
226
|
|
|
124
|
-
function
|
|
125
|
-
|
|
227
|
+
function createBus() {
|
|
228
|
+
var listeners = {};
|
|
229
|
+
return {
|
|
230
|
+
emit: function (event, data) {
|
|
231
|
+
listener(event).forEach(function (handler) {
|
|
232
|
+
handler(data);
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
on: function (event, handler) {
|
|
236
|
+
listeners[event] = listener(event).concat(handler);
|
|
237
|
+
return {
|
|
238
|
+
off: function () {
|
|
239
|
+
listeners[event] = listener(event).filter(function (h) { return h !== handler; });
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
function listener(event) {
|
|
245
|
+
return listeners[event] || [];
|
|
246
|
+
}
|
|
126
247
|
}
|
|
127
|
-
var isNotNumber = bindNot(isNumber);
|
|
128
248
|
|
|
129
|
-
|
|
130
|
-
|
|
249
|
+
/**
|
|
250
|
+
* @returns a unique numeric id.
|
|
251
|
+
*/
|
|
252
|
+
var genId = (function (n) { return function () {
|
|
253
|
+
return "".concat(n++);
|
|
254
|
+
}; })(0);
|
|
255
|
+
|
|
256
|
+
function mapFirst(array, callback) {
|
|
257
|
+
var broke = false;
|
|
258
|
+
var breakoutValue = null;
|
|
259
|
+
for (var i = 0; i < array.length; i++) {
|
|
260
|
+
callback(array[i], breakout, i);
|
|
261
|
+
if (broke) {
|
|
262
|
+
return breakoutValue;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function breakout(conditional, value) {
|
|
266
|
+
if (conditional) {
|
|
267
|
+
broke = true;
|
|
268
|
+
breakoutValue = value;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
131
271
|
}
|
|
132
|
-
var lengthNotEquals = bindNot(lengthEquals);
|
|
133
272
|
|
|
134
273
|
function isEmpty(value) {
|
|
135
274
|
if (!value) {
|
|
136
275
|
return true;
|
|
137
276
|
}
|
|
138
|
-
else if (isNumber(value)) {
|
|
139
|
-
return value === 0;
|
|
140
|
-
}
|
|
141
277
|
else if (hasOwnProperty(value, 'length')) {
|
|
142
278
|
return lengthEquals(value, 0);
|
|
143
279
|
}
|
|
@@ -148,6 +284,56 @@
|
|
|
148
284
|
}
|
|
149
285
|
var isNotEmpty = bindNot(isEmpty);
|
|
150
286
|
|
|
287
|
+
function isPositive(value) {
|
|
288
|
+
return greaterThan(value, 0);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function endsWith(value, arg1) {
|
|
292
|
+
return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
|
|
293
|
+
}
|
|
294
|
+
var doesNotEndWith = bindNot(endsWith);
|
|
295
|
+
|
|
296
|
+
function equals(value, arg1) {
|
|
297
|
+
return value === arg1;
|
|
298
|
+
}
|
|
299
|
+
var notEquals = bindNot(equals);
|
|
300
|
+
|
|
301
|
+
function greaterThanOrEquals(value, gte) {
|
|
302
|
+
return numberEquals(value, gte) || greaterThan(value, gte);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function inside(value, arg1) {
|
|
306
|
+
if (isArray(arg1)) {
|
|
307
|
+
return arg1.indexOf(value) !== -1;
|
|
308
|
+
}
|
|
309
|
+
// both value and arg1 are strings
|
|
310
|
+
if (isStringValue(arg1) && isStringValue(value)) {
|
|
311
|
+
return arg1.indexOf(value) !== -1;
|
|
312
|
+
}
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
var notInside = bindNot(inside);
|
|
316
|
+
|
|
317
|
+
function lessThan(value, lt) {
|
|
318
|
+
return isNumeric(value) && isNumeric(lt) && Number(value) < Number(lt);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function lessThanOrEquals(value, lte) {
|
|
322
|
+
return numberEquals(value, lte) || lessThan(value, lte);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function isBetween(value, min, max) {
|
|
326
|
+
return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
|
|
327
|
+
}
|
|
328
|
+
var isNotBetween = bindNot(isBetween);
|
|
329
|
+
|
|
330
|
+
function isBlank(value) {
|
|
331
|
+
return isNullish(value) || (isStringValue(value) && !value.trim());
|
|
332
|
+
}
|
|
333
|
+
var isNotBlank = bindNot(isBlank);
|
|
334
|
+
|
|
335
|
+
var isNotBoolean = bindNot(isBoolean);
|
|
336
|
+
|
|
151
337
|
/**
|
|
152
338
|
* Validates that a given value is an even number
|
|
153
339
|
*/
|
|
@@ -172,6 +358,11 @@
|
|
|
172
358
|
return lessThan(value, 0);
|
|
173
359
|
}
|
|
174
360
|
|
|
361
|
+
function isNumber(value) {
|
|
362
|
+
return Boolean(typeof value === 'number');
|
|
363
|
+
}
|
|
364
|
+
var isNotNumber = bindNot(isNumber);
|
|
365
|
+
|
|
175
366
|
/**
|
|
176
367
|
* Validates that a given value is an odd number
|
|
177
368
|
*/
|
|
@@ -182,10 +373,6 @@
|
|
|
182
373
|
return false;
|
|
183
374
|
};
|
|
184
375
|
|
|
185
|
-
function isPositive(value) {
|
|
186
|
-
return greaterThan(value, 0);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
376
|
var isNotString = bindNot(isStringValue);
|
|
190
377
|
|
|
191
378
|
function isTruthy(value) {
|
|
@@ -206,10 +393,6 @@
|
|
|
206
393
|
}
|
|
207
394
|
var isNotValueOf = bindNot(isValueOf);
|
|
208
395
|
|
|
209
|
-
function longerThan(value, arg1) {
|
|
210
|
-
return greaterThan(value.length, arg1);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
396
|
function longerThanOrEquals(value, arg1) {
|
|
214
397
|
return greaterThanOrEquals(value.length, arg1);
|
|
215
398
|
}
|
|
@@ -330,33 +513,6 @@
|
|
|
330
513
|
}
|
|
331
514
|
}
|
|
332
515
|
|
|
333
|
-
function optionalFunctionValue(value) {
|
|
334
|
-
var args = [];
|
|
335
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
336
|
-
args[_i - 1] = arguments[_i];
|
|
337
|
-
}
|
|
338
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
function defaultTo(callback, defaultValue) {
|
|
342
|
-
var _a;
|
|
343
|
-
return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
function invariant(condition,
|
|
347
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
348
|
-
message) {
|
|
349
|
-
if (condition) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
// If message is a string object (rather than string literal)
|
|
353
|
-
// Throw the value directly as a string
|
|
354
|
-
// Alternatively, throw an error with the message
|
|
355
|
-
throw message instanceof String
|
|
356
|
-
? message.valueOf()
|
|
357
|
-
: new Error(message ? optionalFunctionValue(message) : message);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
516
|
// eslint-disable-next-line max-lines-per-function
|
|
361
517
|
function createContext(init) {
|
|
362
518
|
var storage = { ancestry: [] };
|
|
@@ -367,8 +523,9 @@
|
|
|
367
523
|
useX: useX
|
|
368
524
|
};
|
|
369
525
|
function useX(errorMessage) {
|
|
370
|
-
|
|
371
|
-
|
|
526
|
+
var ctx = use();
|
|
527
|
+
invariant(ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
|
|
528
|
+
return ctx;
|
|
372
529
|
}
|
|
373
530
|
function run(ctxRef, fn) {
|
|
374
531
|
var _a;
|
|
@@ -531,32 +688,17 @@
|
|
|
531
688
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
532
689
|
args[_i] = arguments[_i];
|
|
533
690
|
}
|
|
534
|
-
var transformedResult =
|
|
535
|
-
ruleName,
|
|
536
|
-
|
|
537
|
-
invariant(transformedResult.pass,
|
|
691
|
+
var transformedResult = ctx.run({ value: value }, function () {
|
|
692
|
+
return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
|
|
693
|
+
});
|
|
694
|
+
invariant(transformedResult.pass, isNullish(transformedResult.message)
|
|
538
695
|
? "enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value))
|
|
539
|
-
:
|
|
696
|
+
: StringObject(transformedResult.message));
|
|
540
697
|
return target;
|
|
541
698
|
};
|
|
542
699
|
}
|
|
543
700
|
}
|
|
544
701
|
|
|
545
|
-
function mapFirst(array, callback) {
|
|
546
|
-
var broke = false;
|
|
547
|
-
var breakoutValue = null;
|
|
548
|
-
for (var i = 0; i < array.length; i++) {
|
|
549
|
-
callback(array[i], breakout, i);
|
|
550
|
-
if (broke) {
|
|
551
|
-
return breakoutValue;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
function breakout(value) {
|
|
555
|
-
broke = true;
|
|
556
|
-
breakoutValue = value;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
702
|
// eslint-disable-next-line max-lines-per-function
|
|
561
703
|
function genEnforceLazy(key) {
|
|
562
704
|
var registeredRules = [];
|
|
@@ -579,9 +721,7 @@
|
|
|
579
721
|
return defaultToPassing(mapFirst(registeredRules, function (rule, breakout) {
|
|
580
722
|
var _a;
|
|
581
723
|
var res = ctx.run({ value: value }, function () { return rule(value); });
|
|
582
|
-
|
|
583
|
-
breakout(ruleReturn(!!res.pass, (_a = optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
|
|
584
|
-
}
|
|
724
|
+
breakout(!res.pass, ruleReturn(!!res.pass, (_a = optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
|
|
585
725
|
}));
|
|
586
726
|
},
|
|
587
727
|
test: function (value) { return proxy.run(value).pass; },
|
|
@@ -672,109 +812,11 @@
|
|
|
672
812
|
}
|
|
673
813
|
var enforce = genEnforce();
|
|
674
814
|
|
|
675
|
-
/**
|
|
676
|
-
* @returns a unique numeric id.
|
|
677
|
-
*/
|
|
678
|
-
var genId = (function (n) { return function () {
|
|
679
|
-
return "".concat(n++);
|
|
680
|
-
}; })(0);
|
|
681
|
-
|
|
682
815
|
function shouldUseErrorAsMessage(message, error) {
|
|
683
816
|
// kind of cheating with this safe guard, but it does the job
|
|
684
817
|
return isUndefined(message) && isStringValue(error);
|
|
685
818
|
}
|
|
686
819
|
|
|
687
|
-
function asArray(possibleArg) {
|
|
688
|
-
return [].concat(possibleArg);
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
/**
|
|
692
|
-
* Creates a cache function
|
|
693
|
-
*/
|
|
694
|
-
function createCache(maxSize) {
|
|
695
|
-
if (maxSize === void 0) { maxSize = 1; }
|
|
696
|
-
var cacheStorage = [];
|
|
697
|
-
var cache = function (deps, cacheAction) {
|
|
698
|
-
var cacheHit = cache.get(deps);
|
|
699
|
-
// cache hit is not null
|
|
700
|
-
if (cacheHit)
|
|
701
|
-
return cacheHit[1];
|
|
702
|
-
var result = cacheAction();
|
|
703
|
-
cacheStorage.unshift([deps.concat(), result]);
|
|
704
|
-
if (longerThan(cacheStorage, maxSize))
|
|
705
|
-
cacheStorage.length = maxSize;
|
|
706
|
-
return result;
|
|
707
|
-
};
|
|
708
|
-
// invalidate an item in the cache by its dependencies
|
|
709
|
-
cache.invalidate = function (deps) {
|
|
710
|
-
var index = findIndex(deps);
|
|
711
|
-
if (index > -1)
|
|
712
|
-
cacheStorage.splice(index, 1);
|
|
713
|
-
};
|
|
714
|
-
// Retrieves an item from the cache.
|
|
715
|
-
cache.get = function (deps) {
|
|
716
|
-
return cacheStorage[findIndex(deps)] || null;
|
|
717
|
-
};
|
|
718
|
-
return cache;
|
|
719
|
-
function findIndex(deps) {
|
|
720
|
-
return cacheStorage.findIndex(function (_a) {
|
|
721
|
-
var cachedDeps = _a[0];
|
|
722
|
-
return lengthEquals(deps, cachedDeps.length) &&
|
|
723
|
-
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
function last(values) {
|
|
729
|
-
var valuesArray = asArray(values);
|
|
730
|
-
return valuesArray[valuesArray.length - 1];
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
// This is kind of a map/filter in one function.
|
|
734
|
-
// Normally, behaves like a nested-array map,
|
|
735
|
-
// but returning `null` will drop the element from the array
|
|
736
|
-
function transform(array, cb) {
|
|
737
|
-
var res = [];
|
|
738
|
-
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
|
|
739
|
-
var v = array_1[_i];
|
|
740
|
-
if (isArray(v)) {
|
|
741
|
-
res.push(transform(v, cb));
|
|
742
|
-
}
|
|
743
|
-
else {
|
|
744
|
-
var output = cb(v);
|
|
745
|
-
if (isNotNull(output)) {
|
|
746
|
-
res.push(output);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
return res;
|
|
751
|
-
}
|
|
752
|
-
function valueAtPath(array, path) {
|
|
753
|
-
return getCurrent(array, path)[last(path)];
|
|
754
|
-
}
|
|
755
|
-
function setValueAtPath(array, path, value) {
|
|
756
|
-
var current = getCurrent(array, path);
|
|
757
|
-
current[last(path)] = value;
|
|
758
|
-
return array;
|
|
759
|
-
}
|
|
760
|
-
function flatten(values) {
|
|
761
|
-
return asArray(values).reduce(function (acc, value) {
|
|
762
|
-
if (isArray(value)) {
|
|
763
|
-
return acc.concat(flatten(value));
|
|
764
|
-
}
|
|
765
|
-
return asArray(acc).concat(value);
|
|
766
|
-
}, []);
|
|
767
|
-
}
|
|
768
|
-
function getCurrent(array, path) {
|
|
769
|
-
var current = array;
|
|
770
|
-
for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
|
|
771
|
-
var p = _a[_i];
|
|
772
|
-
current[p] = defaultTo(current[p], []);
|
|
773
|
-
current = current[p];
|
|
774
|
-
}
|
|
775
|
-
return current;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
820
|
var IsolateTypes;
|
|
779
821
|
(function (IsolateTypes) {
|
|
780
822
|
IsolateTypes[IsolateTypes["DEFAULT"] = 0] = "DEFAULT";
|
|
@@ -1138,12 +1180,6 @@
|
|
|
1138
1180
|
};
|
|
1139
1181
|
}
|
|
1140
1182
|
|
|
1141
|
-
function deferThrow(message) {
|
|
1142
|
-
setTimeout(function () {
|
|
1143
|
-
throw new Error(message);
|
|
1144
|
-
}, 0);
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
1183
|
function usePrevKeys() {
|
|
1148
1184
|
var prev = useTestObjects()[0].prev;
|
|
1149
1185
|
return asArray(getCurrent(prev, useCurrentPath())).reduce(function (prevKeys, testObject) {
|
|
@@ -1240,10 +1276,6 @@
|
|
|
1240
1276
|
return testObject.groupName === groupName;
|
|
1241
1277
|
}
|
|
1242
1278
|
|
|
1243
|
-
function either(a, b) {
|
|
1244
|
-
return !!a !== !!b;
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
1279
|
/**
|
|
1248
1280
|
* Checks that a given test object matches the currently specified severity level
|
|
1249
1281
|
*/
|
|
@@ -1682,28 +1714,6 @@
|
|
|
1682
1714
|
});
|
|
1683
1715
|
}
|
|
1684
1716
|
|
|
1685
|
-
function createBus() {
|
|
1686
|
-
var listeners = {};
|
|
1687
|
-
return {
|
|
1688
|
-
emit: function (event, data) {
|
|
1689
|
-
listener(event).forEach(function (handler) {
|
|
1690
|
-
handler(data);
|
|
1691
|
-
});
|
|
1692
|
-
},
|
|
1693
|
-
on: function (event, handler) {
|
|
1694
|
-
listeners[event] = listener(event).concat(handler);
|
|
1695
|
-
return {
|
|
1696
|
-
off: function () {
|
|
1697
|
-
listeners[event] = listener(event).filter(function (h) { return h !== handler; });
|
|
1698
|
-
}
|
|
1699
|
-
};
|
|
1700
|
-
}
|
|
1701
|
-
};
|
|
1702
|
-
function listener(event) {
|
|
1703
|
-
return listeners[event] || [];
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
|
|
1707
1717
|
function omitOptionalFields() {
|
|
1708
1718
|
var optionalFields = useOptionalFields()[0];
|
|
1709
1719
|
if (isEmpty(optionalFields)) {
|
|
@@ -1746,10 +1756,6 @@
|
|
|
1746
1756
|
});
|
|
1747
1757
|
}
|
|
1748
1758
|
|
|
1749
|
-
function callEach(arr) {
|
|
1750
|
-
return arr.forEach(function (fn) { return fn(); });
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
1759
|
/**
|
|
1754
1760
|
* Runs done callback per field when async tests are finished running.
|
|
1755
1761
|
*/
|
|
@@ -1771,10 +1777,10 @@
|
|
|
1771
1777
|
|
|
1772
1778
|
// eslint-disable-next-line max-lines-per-function
|
|
1773
1779
|
function initBus() {
|
|
1774
|
-
var
|
|
1780
|
+
var vestBus = createBus();
|
|
1775
1781
|
// Report a the completion of a test. There may be other tests with the same
|
|
1776
1782
|
// name that are still running, or not yet started.
|
|
1777
|
-
|
|
1783
|
+
vestBus.on(Events.TEST_COMPLETED, function (testObject) {
|
|
1778
1784
|
if (testObject.isCanceled()) {
|
|
1779
1785
|
return;
|
|
1780
1786
|
}
|
|
@@ -1782,21 +1788,21 @@
|
|
|
1782
1788
|
runFieldCallbacks(testObject.fieldName);
|
|
1783
1789
|
if (!hasRemainingTests()) {
|
|
1784
1790
|
// When no more tests are running, emit the done event
|
|
1785
|
-
|
|
1791
|
+
vestBus.emit(Events.ALL_RUNNING_TESTS_FINISHED);
|
|
1786
1792
|
}
|
|
1787
1793
|
});
|
|
1788
1794
|
// Report that the suite completed its synchronous test run.
|
|
1789
1795
|
// Async operations may still be running.
|
|
1790
|
-
|
|
1796
|
+
vestBus.on(Events.SUITE_CALLBACK_DONE_RUNNING, function () {
|
|
1791
1797
|
// Remove tests that are optional and need to be omitted
|
|
1792
1798
|
omitOptionalFields();
|
|
1793
1799
|
});
|
|
1794
1800
|
// Called when all the tests, including async, are done running
|
|
1795
|
-
|
|
1801
|
+
vestBus.on(Events.ALL_RUNNING_TESTS_FINISHED, function () {
|
|
1796
1802
|
runDoneCallbacks();
|
|
1797
1803
|
});
|
|
1798
1804
|
// Removes a certain field from the state.
|
|
1799
|
-
|
|
1805
|
+
vestBus.on(Events.REMOVE_FIELD, function (fieldName) {
|
|
1800
1806
|
useEachTestObject(function (testObject) {
|
|
1801
1807
|
if (matchingFieldName(testObject, fieldName)) {
|
|
1802
1808
|
testObject.cancel();
|
|
@@ -1805,14 +1811,14 @@
|
|
|
1805
1811
|
});
|
|
1806
1812
|
});
|
|
1807
1813
|
// Resets a certain field in the state.
|
|
1808
|
-
|
|
1814
|
+
vestBus.on(Events.RESET_FIELD, function (fieldName) {
|
|
1809
1815
|
useEachTestObject(function (testObject) {
|
|
1810
1816
|
if (matchingFieldName(testObject, fieldName)) {
|
|
1811
1817
|
testObject.reset();
|
|
1812
1818
|
}
|
|
1813
1819
|
});
|
|
1814
1820
|
});
|
|
1815
|
-
return
|
|
1821
|
+
return vestBus;
|
|
1816
1822
|
}
|
|
1817
1823
|
function useBus() {
|
|
1818
1824
|
var context$1 = context.useX();
|
|
@@ -2133,9 +2139,7 @@
|
|
|
2133
2139
|
setMode(Modes.EAGER);
|
|
2134
2140
|
}
|
|
2135
2141
|
function shouldSkipBasedOnMode(testObject) {
|
|
2136
|
-
|
|
2137
|
-
return true;
|
|
2138
|
-
return false;
|
|
2142
|
+
return isEager() && hasErrorsByTestObjects(testObject.fieldName);
|
|
2139
2143
|
}
|
|
2140
2144
|
function isEager() {
|
|
2141
2145
|
return isMode(Modes.EAGER);
|
|
@@ -2199,10 +2203,6 @@
|
|
|
2199
2203
|
}
|
|
2200
2204
|
}
|
|
2201
2205
|
|
|
2202
|
-
function isPromise(value) {
|
|
2203
|
-
return value && isFunction(value.then);
|
|
2204
|
-
}
|
|
2205
|
-
|
|
2206
2206
|
function isSameProfileTest(testObject1, testObject2) {
|
|
2207
2207
|
return (testObject1.fieldName === testObject2.fieldName &&
|
|
2208
2208
|
testObject1.groupName === testObject2.groupName);
|
|
@@ -2467,7 +2467,7 @@
|
|
|
2467
2467
|
ctx.currentTest.warn();
|
|
2468
2468
|
}
|
|
2469
2469
|
|
|
2470
|
-
var VERSION = "4.4.
|
|
2470
|
+
var VERSION = "4.4.2-dev-afe5de";
|
|
2471
2471
|
|
|
2472
2472
|
exports.VERSION = VERSION;
|
|
2473
2473
|
exports.context = context;
|