n4s 5.0.0-dev-781e21 → 5.0.0-dev-ae6b14

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 (36) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/compose.development.js +9 -13
  3. package/dist/cjs/compose.production.js +1 -1
  4. package/dist/cjs/compounds.development.js +16 -32
  5. package/dist/cjs/compounds.production.js +1 -1
  6. package/dist/cjs/n4s.development.js +137 -213
  7. package/dist/cjs/n4s.production.js +1 -1
  8. package/dist/cjs/schema.development.js +13 -22
  9. package/dist/cjs/schema.production.js +1 -1
  10. package/dist/es/compose.development.js +11 -15
  11. package/dist/es/compose.production.js +1 -1
  12. package/dist/es/compounds.development.js +16 -32
  13. package/dist/es/compounds.production.js +1 -1
  14. package/dist/es/n4s.development.js +158 -232
  15. package/dist/es/n4s.production.js +1 -1
  16. package/dist/es/schema.development.js +13 -20
  17. package/dist/es/schema.production.js +1 -1
  18. package/dist/umd/compose.development.js +12 -16
  19. package/dist/umd/compose.production.js +1 -1
  20. package/dist/umd/compounds.development.js +19 -35
  21. package/dist/umd/compounds.production.js +1 -1
  22. package/dist/umd/n4s.development.js +140 -216
  23. package/dist/umd/n4s.production.js +1 -1
  24. package/dist/umd/schema.development.js +16 -25
  25. package/dist/umd/schema.production.js +1 -1
  26. package/package.json +62 -55
  27. package/testUtils/TEnforceMock.ts +3 -0
  28. package/types/compose.d.ts +17 -21
  29. package/types/compose.d.ts.map +1 -0
  30. package/types/compounds.d.ts +17 -22
  31. package/types/compounds.d.ts.map +1 -0
  32. package/types/n4s.d.ts +22 -22
  33. package/types/n4s.d.ts.map +1 -0
  34. package/types/schema.d.ts +17 -21
  35. package/types/schema.d.ts.map +1 -0
  36. package/tsconfig.json +0 -8
@@ -1,15 +1,46 @@
1
- import { bindNot, isStringValue, numberEquals, greaterThan, isArray, isNumeric, isNullish, isBoolean, isEmpty, isNotArray, isNotEmpty, isNotNull, isNotNullish, isNotNumeric, isNotUndefined, isNull, isPositive, isUndefined, lengthEquals, lengthNotEquals, longerThan, numberNotEquals, isFunction, assign, defaultTo, optionalFunctionValue, invariant, StringObject, mapFirst } from 'vest-utils';
1
+ import { assign, bindNot, isStringValue, numberEquals, greaterThan, isArray, isNumeric, isNullish, isBoolean, isEmpty, isNotArray, isNotEmpty, isNotNull, isNotNullish, isNotNumeric, isNotUndefined, isNull, isPositive, isUndefined, lengthEquals, lengthNotEquals, longerThan, numberNotEquals, defaultTo, optionalFunctionValue, invariant, StringObject, mapFirst } from 'vest-utils';
2
2
  import { createCascade } from 'context';
3
3
 
4
+ const ctx = createCascade((ctxRef, parentContext) => {
5
+ const base = {
6
+ value: ctxRef.value,
7
+ meta: ctxRef.meta || {},
8
+ };
9
+ if (!parentContext) {
10
+ return assign(base, {
11
+ parent: emptyParent,
12
+ });
13
+ }
14
+ else if (ctxRef.set) {
15
+ return assign(base, {
16
+ parent: () => stripContext(parentContext),
17
+ });
18
+ }
19
+ return parentContext;
20
+ });
21
+ function stripContext(ctx) {
22
+ if (!ctx) {
23
+ return null;
24
+ }
25
+ return {
26
+ value: ctx.value,
27
+ meta: ctx.meta,
28
+ parent: ctx.parent,
29
+ };
30
+ }
31
+ function emptyParent() {
32
+ return null;
33
+ }
34
+
4
35
  function endsWith(value, arg1) {
5
36
  return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
6
37
  }
7
- var doesNotEndWith = bindNot(endsWith);
38
+ const doesNotEndWith = bindNot(endsWith);
8
39
 
9
40
  function equals(value, arg1) {
10
41
  return value === arg1;
11
42
  }
12
- var notEquals = bindNot(equals);
43
+ const notEquals = bindNot(equals);
13
44
 
14
45
  function greaterThanOrEquals(value, gte) {
15
46
  return numberEquals(value, gte) || greaterThan(value, gte);
@@ -25,7 +56,7 @@ function inside(value, arg1) {
25
56
  }
26
57
  return false;
27
58
  }
28
- var notInside = bindNot(inside);
59
+ const notInside = bindNot(inside);
29
60
 
30
61
  function lessThan(value, lt) {
31
62
  return isNumeric(value) && isNumeric(lt) && Number(value) < Number(lt);
@@ -38,19 +69,19 @@ function lessThanOrEquals(value, lte) {
38
69
  function isBetween(value, min, max) {
39
70
  return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
40
71
  }
41
- var isNotBetween = bindNot(isBetween);
72
+ const isNotBetween = bindNot(isBetween);
42
73
 
43
74
  function isBlank(value) {
44
75
  return isNullish(value) || (isStringValue(value) && !value.trim());
45
76
  }
46
- var isNotBlank = bindNot(isBlank);
77
+ const isNotBlank = bindNot(isBlank);
47
78
 
48
- var isNotBoolean = bindNot(isBoolean);
79
+ const isNotBoolean = bindNot(isBoolean);
49
80
 
50
81
  /**
51
82
  * Validates that a given value is an even number
52
83
  */
53
- var isEven = function (value) {
84
+ const isEven = (value) => {
54
85
  if (isNumeric(value)) {
55
86
  return value % 2 === 0;
56
87
  }
@@ -60,12 +91,12 @@ var isEven = function (value) {
60
91
  function isKeyOf(key, obj) {
61
92
  return key in obj;
62
93
  }
63
- var isNotKeyOf = bindNot(isKeyOf);
94
+ const isNotKeyOf = bindNot(isKeyOf);
64
95
 
65
96
  function isNaN(value) {
66
97
  return Number.isNaN(value);
67
98
  }
68
- var isNotNaN = bindNot(isNaN);
99
+ const isNotNaN = bindNot(isNaN);
69
100
 
70
101
  function isNegative(value) {
71
102
  return lessThan(value, 0);
@@ -74,37 +105,37 @@ function isNegative(value) {
74
105
  function isNumber(value) {
75
106
  return Boolean(typeof value === 'number');
76
107
  }
77
- var isNotNumber = bindNot(isNumber);
108
+ const isNotNumber = bindNot(isNumber);
78
109
 
79
110
  /**
80
111
  * Validates that a given value is an odd number
81
112
  */
82
- var isOdd = function (value) {
113
+ const isOdd = (value) => {
83
114
  if (isNumeric(value)) {
84
115
  return value % 2 !== 0;
85
116
  }
86
117
  return false;
87
118
  };
88
119
 
89
- var isNotString = bindNot(isStringValue);
120
+ const isNotString = bindNot(isStringValue);
90
121
 
91
122
  function isTruthy(value) {
92
123
  return !!value;
93
124
  }
94
- var isFalsy = bindNot(isTruthy);
125
+ const isFalsy = bindNot(isTruthy);
95
126
 
96
127
  function isValueOf(value, objectToCheck) {
97
128
  if (isNullish(objectToCheck)) {
98
129
  return false;
99
130
  }
100
- for (var key in objectToCheck) {
131
+ for (const key in objectToCheck) {
101
132
  if (objectToCheck[key] === value) {
102
133
  return true;
103
134
  }
104
135
  }
105
136
  return false;
106
137
  }
107
- var isNotValueOf = bindNot(isValueOf);
138
+ const isNotValueOf = bindNot(isValueOf);
108
139
 
109
140
  function longerThanOrEquals(value, arg1) {
110
141
  return greaterThanOrEquals(value.length, arg1);
@@ -117,11 +148,9 @@ function matches(value, regex) {
117
148
  else if (isStringValue(regex)) {
118
149
  return new RegExp(regex).test(value);
119
150
  }
120
- else {
121
- return false;
122
- }
151
+ return false;
123
152
  }
124
- var notMatches = bindNot(matches);
153
+ const notMatches = bindNot(matches);
125
154
 
126
155
  function condition(value, callback) {
127
156
  try {
@@ -143,156 +172,82 @@ function shorterThanOrEquals(value, arg1) {
143
172
  function startsWith(value, arg1) {
144
173
  return isStringValue(value) && isStringValue(arg1) && value.startsWith(arg1);
145
174
  }
146
- var doesNotStartWith = bindNot(startsWith);
175
+ const doesNotStartWith = bindNot(startsWith);
147
176
 
148
177
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, max-lines-per-function
149
178
  function rules() {
150
179
  return {
151
- condition: condition,
152
- doesNotEndWith: doesNotEndWith,
153
- doesNotStartWith: doesNotStartWith,
154
- endsWith: endsWith,
155
- equals: equals,
156
- greaterThan: greaterThan,
157
- greaterThanOrEquals: greaterThanOrEquals,
180
+ condition,
181
+ doesNotEndWith,
182
+ doesNotStartWith,
183
+ endsWith,
184
+ equals,
185
+ greaterThan,
186
+ greaterThanOrEquals,
158
187
  gt: greaterThan,
159
188
  gte: greaterThanOrEquals,
160
- inside: inside,
161
- isArray: isArray,
162
- isBetween: isBetween,
163
- isBlank: isBlank,
164
- isBoolean: isBoolean,
165
- isEmpty: isEmpty,
166
- isEven: isEven,
167
- isFalsy: isFalsy,
168
- isKeyOf: isKeyOf,
169
- isNaN: isNaN,
170
- isNegative: isNegative,
171
- isNotArray: isNotArray,
172
- isNotBetween: isNotBetween,
173
- isNotBlank: isNotBlank,
174
- isNotBoolean: isNotBoolean,
175
- isNotEmpty: isNotEmpty,
176
- isNotKeyOf: isNotKeyOf,
177
- isNotNaN: isNotNaN,
178
- isNotNull: isNotNull,
179
- isNotNullish: isNotNullish,
180
- isNotNumber: isNotNumber,
181
- isNotNumeric: isNotNumeric,
182
- isNotString: isNotString,
183
- isNotUndefined: isNotUndefined,
184
- isNotValueOf: isNotValueOf,
185
- isNull: isNull,
186
- isNullish: isNullish,
187
- isNumber: isNumber,
188
- isNumeric: isNumeric,
189
- isOdd: isOdd,
190
- isPositive: isPositive,
189
+ inside,
190
+ isArray,
191
+ isBetween,
192
+ isBlank,
193
+ isBoolean,
194
+ isEmpty,
195
+ isEven,
196
+ isFalsy,
197
+ isKeyOf,
198
+ isNaN,
199
+ isNegative,
200
+ isNotArray,
201
+ isNotBetween,
202
+ isNotBlank,
203
+ isNotBoolean,
204
+ isNotEmpty,
205
+ isNotKeyOf,
206
+ isNotNaN,
207
+ isNotNull,
208
+ isNotNullish,
209
+ isNotNumber,
210
+ isNotNumeric,
211
+ isNotString,
212
+ isNotUndefined,
213
+ isNotValueOf,
214
+ isNull,
215
+ isNullish,
216
+ isNumber,
217
+ isNumeric,
218
+ isOdd,
219
+ isPositive,
191
220
  isString: isStringValue,
192
- isTruthy: isTruthy,
193
- isUndefined: isUndefined,
194
- isValueOf: isValueOf,
195
- lengthEquals: lengthEquals,
196
- lengthNotEquals: lengthNotEquals,
197
- lessThan: lessThan,
198
- lessThanOrEquals: lessThanOrEquals,
199
- longerThan: longerThan,
200
- longerThanOrEquals: longerThanOrEquals,
221
+ isTruthy,
222
+ isUndefined,
223
+ isValueOf,
224
+ lengthEquals,
225
+ lengthNotEquals,
226
+ lessThan,
227
+ lessThanOrEquals,
228
+ longerThan,
229
+ longerThanOrEquals,
201
230
  lt: lessThan,
202
231
  lte: lessThanOrEquals,
203
- matches: matches,
204
- notEquals: notEquals,
205
- notInside: notInside,
206
- notMatches: notMatches,
207
- numberEquals: numberEquals,
208
- numberNotEquals: numberNotEquals,
209
- shorterThan: shorterThan,
210
- shorterThanOrEquals: shorterThanOrEquals,
211
- startsWith: startsWith
232
+ matches,
233
+ notEquals,
234
+ notInside,
235
+ notMatches,
236
+ numberEquals,
237
+ numberNotEquals,
238
+ shorterThan,
239
+ shorterThanOrEquals,
240
+ startsWith,
212
241
  };
213
242
  }
214
243
 
215
- var baseRules = rules();
244
+ const baseRules = rules();
216
245
  function getRule(ruleName) {
217
246
  return baseRules[ruleName];
218
247
  }
219
248
 
220
- function eachEnforceRule(action) {
221
- for (var ruleName in baseRules) {
222
- var ruleFn = getRule(ruleName);
223
- if (isFunction(ruleFn)) {
224
- action(ruleName, ruleFn);
225
- }
226
- }
227
- }
228
-
229
- var ctx = createCascade(function (ctxRef, parentContext) {
230
- var base = {
231
- value: ctxRef.value,
232
- meta: ctxRef.meta || {}
233
- };
234
- if (!parentContext) {
235
- return assign(base, {
236
- parent: emptyParent
237
- });
238
- }
239
- else if (ctxRef.set) {
240
- return assign(base, {
241
- parent: function () { return stripContext(parentContext); }
242
- });
243
- }
244
- return parentContext;
245
- });
246
- function stripContext(ctx) {
247
- if (!ctx) {
248
- return ctx;
249
- }
250
- return {
251
- value: ctx.value,
252
- meta: ctx.meta,
253
- parent: ctx.parent
254
- };
255
- }
256
- function emptyParent() {
257
- return null;
258
- }
259
-
260
- /******************************************************************************
261
- Copyright (c) Microsoft Corporation.
262
-
263
- Permission to use, copy, modify, and/or distribute this software for any
264
- purpose with or without fee is hereby granted.
265
-
266
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
267
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
268
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
269
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
270
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
271
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272
- PERFORMANCE OF THIS SOFTWARE.
273
- ***************************************************************************** */
274
-
275
- function __spreadArray(to, from, pack) {
276
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
277
- if (ar || !(i in from)) {
278
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
279
- ar[i] = from[i];
280
- }
281
- }
282
- return to.concat(ar || Array.prototype.slice.call(from));
283
- }
284
-
285
- function isProxySupported() {
286
- try {
287
- return isFunction(Proxy);
288
- }
289
- catch (_a) {
290
- return false;
291
- }
292
- }
293
-
294
249
  function ruleReturn(pass, message) {
295
- var output = { pass: pass };
250
+ const output = { pass };
296
251
  if (message) {
297
252
  output.message = message;
298
253
  }
@@ -308,124 +263,106 @@ function defaultToPassing(callback) {
308
263
  /**
309
264
  * Transform the result of a rule into a standard format
310
265
  */
311
- function transformResult(result, ruleName, value) {
312
- var args = [];
313
- for (var _i = 3; _i < arguments.length; _i++) {
314
- args[_i - 3] = arguments[_i];
315
- }
266
+ function transformResult(result, ruleName, value, ...args) {
316
267
  validateResult(result);
317
268
  // if result is boolean
318
269
  if (isBoolean(result)) {
319
270
  return ruleReturn(result);
320
271
  }
321
- else {
322
- return ruleReturn(result.pass, optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args, false)));
323
- }
272
+ return ruleReturn(result.pass, optionalFunctionValue(result.message, ruleName, value, ...args));
324
273
  }
325
274
  function validateResult(result) {
326
275
  // if result is boolean, or if result.pass is boolean
327
276
  invariant(isBoolean(result) || (result && isBoolean(result.pass)), 'Incorrect return value for rule: ' + JSON.stringify(result));
328
277
  }
329
278
 
279
+ // eslint-disable-next-line max-lines-per-function
330
280
  function enforceEager(value) {
331
- var target = {};
332
- // This condition is for when we don't have proxy support (ES5).
333
- // In this case, we need to manually assign the rules to the target object on runtime.
334
- // The follow up proxy block is used in case we do have proxy support, and we can assign each rule upon invocation.
335
- if (!isProxySupported()) {
336
- // We iterate over each of the rules, and add them to the target object being return by enforce
337
- eachEnforceRule(function (ruleName, ruleFn) {
338
- // We then wrap the rule with `genRuleCall` that adds the base enforce behavior
339
- target[ruleName] = genRuleCall(target, ruleFn, ruleName);
340
- });
341
- return target;
342
- }
281
+ const target = {
282
+ message,
283
+ };
284
+ let customMessage = undefined;
343
285
  // We create a proxy intercepting access to the target object (which is empty).
344
- var proxy = new Proxy(target, {
345
- get: function (_, ruleName) {
286
+ const proxy = new Proxy(target, {
287
+ get: (_, key) => {
346
288
  // On property access, we identify if it is a rule or not.
347
- var rule = getRule(ruleName);
289
+ const rule = getRule(key);
348
290
  // If it is a rule, we wrap it with `genRuleCall` that adds the base enforce behavior
349
291
  if (rule) {
350
- return genRuleCall(proxy, rule, ruleName);
292
+ return genRuleCall(proxy, rule, key);
351
293
  }
352
- }
294
+ return target[key];
295
+ },
353
296
  });
354
297
  return proxy;
355
298
  // This function is used to wrap a rule with the base enforce behavior
356
299
  // It takes the target object, the rule function, and the rule name
357
300
  // It then returns the rule, in a manner that can be used by enforce
358
301
  function genRuleCall(target, rule, ruleName) {
359
- return function ruleCall() {
360
- var args = [];
361
- for (var _i = 0; _i < arguments.length; _i++) {
362
- args[_i] = arguments[_i];
363
- }
302
+ return function ruleCall(...args) {
364
303
  // Order of operation:
365
304
  // 1. Create a context with the value being enforced
366
305
  // 2. Call the rule within the context, and pass over the arguments passed to it
367
306
  // 3. Transform the result to the correct output format
368
- var transformedResult = ctx.run({ value: value }, function () {
369
- return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
307
+ const transformedResult = ctx.run({ value }, () => {
308
+ return transformResult(rule(value, ...args), ruleName, value, ...args);
370
309
  });
310
+ function enforceMessage() {
311
+ if (!isNullish(customMessage))
312
+ return StringObject(customMessage);
313
+ if (isNullish(transformedResult.message)) {
314
+ return `enforce/${ruleName} failed with ${JSON.stringify(value)}`;
315
+ }
316
+ return StringObject(transformedResult.message);
317
+ }
371
318
  // On rule failure (the result is false), we either throw an error
372
319
  // or throw a string value if the rule has a message defined in it.
373
- invariant(transformedResult.pass, isNullish(transformedResult.message)
374
- ? "enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value))
375
- : StringObject(transformedResult.message));
320
+ invariant(transformedResult.pass, enforceMessage());
376
321
  return target;
377
322
  };
378
323
  }
324
+ function message(input) {
325
+ customMessage = input;
326
+ return proxy;
327
+ }
379
328
  }
380
329
 
381
330
  // eslint-disable-next-line max-lines-per-function
382
331
  function genEnforceLazy(key) {
383
- var registeredRules = [];
384
- var lazyMessage;
332
+ const registeredRules = [];
333
+ let lazyMessage;
385
334
  return addLazyRule(key);
386
335
  // eslint-disable-next-line max-lines-per-function
387
336
  function addLazyRule(ruleName) {
388
337
  // eslint-disable-next-line max-lines-per-function
389
- return function () {
390
- var args = [];
391
- for (var _i = 0; _i < arguments.length; _i++) {
392
- args[_i] = arguments[_i];
393
- }
394
- var rule = getRule(ruleName);
395
- registeredRules.push(function (value) {
396
- return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
397
- });
398
- var proxy = {
399
- run: function (value) {
400
- return defaultToPassing(mapFirst(registeredRules, function (rule, breakout) {
338
+ return (...args) => {
339
+ const rule = getRule(ruleName);
340
+ registeredRules.push((value) => transformResult(rule(value, ...args), ruleName, value, ...args));
341
+ let proxy = {
342
+ run: (value) => {
343
+ return defaultToPassing(mapFirst(registeredRules, (rule, breakout) => {
401
344
  var _a;
402
- var res = ctx.run({ value: value }, function () { return rule(value); });
345
+ const res = ctx.run({ value }, () => rule(value));
403
346
  breakout(!res.pass, ruleReturn(!!res.pass, (_a = optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
404
347
  }));
405
348
  },
406
- test: function (value) { return proxy.run(value).pass; },
407
- message: function (message) {
349
+ test: (value) => proxy.run(value).pass,
350
+ message: (message) => {
408
351
  if (message) {
409
352
  lazyMessage = message;
410
353
  }
411
354
  return proxy;
412
- }
355
+ },
413
356
  };
414
- if (!isProxySupported()) {
415
- eachEnforceRule(function (ruleName) {
416
- proxy[ruleName] = addLazyRule(ruleName);
417
- });
418
- return proxy;
419
- }
420
357
  // reassigning the proxy here is not pretty
421
358
  // but it's a cleaner way of getting `run` and `test` for free
422
359
  proxy = new Proxy(proxy, {
423
- get: function (target, key) {
360
+ get: (target, key) => {
424
361
  if (getRule(key)) {
425
362
  return addLazyRule(key);
426
363
  }
427
364
  return target[key]; // already has `run` and `test` on it
428
- }
365
+ },
429
366
  });
430
367
  return proxy;
431
368
  };
@@ -459,16 +396,14 @@ function genEnforceLazy(key) {
459
396
  * while run will return an object with the validation result and an optional message created by the rule.
460
397
  */
461
398
  function genEnforce() {
462
- var target = {
463
- context: function () { return ctx.useX(); },
464
- extend: function (customRules) {
399
+ const target = {
400
+ context: () => ctx.useX(),
401
+ extend: (customRules) => {
465
402
  assign(baseRules, customRules);
466
- handleNoProxy(); // TODO: REMOVE when we stop supporting ES5
467
- }
403
+ },
468
404
  };
469
- handleNoProxy();
470
405
  return new Proxy(assign(enforceEager, target), {
471
- get: function (target, key) {
406
+ get: (target, key) => {
472
407
  if (key in target) {
473
408
  return target[key];
474
409
  }
@@ -477,18 +412,9 @@ function genEnforce() {
477
412
  }
478
413
  // Only on the first rule access - start the chain of calls
479
414
  return genEnforceLazy(key);
480
- }
415
+ },
481
416
  });
482
- function handleNoProxy() {
483
- if (!isProxySupported()) {
484
- eachEnforceRule(function (ruleName) {
485
- // Only on the first rule access - start the chain of calls
486
- target[ruleName] = genEnforceLazy(ruleName);
487
- });
488
- return assign(enforceEager, target);
489
- }
490
- }
491
417
  }
492
- var enforce = genEnforce();
418
+ const enforce = genEnforce();
493
419
 
494
420
  export { ctx, enforce };
@@ -1 +1 @@
1
- import{createCascade as n}from"context";import{bindNot as t,isStringValue as r,numberEquals as e,greaterThan as u,isArray as i,isNumeric as o,isNullish as a,isBoolean as s,isEmpty as f,isNotArray as c,isNotEmpty as l,isNotNull as v,isNotNullish as N,isNotNumeric as h,isNotUndefined as p,isNull as g,isPositive as m,isUndefined as y,lengthEquals as d,lengthNotEquals as E,longerThan as x,numberNotEquals as O,isFunction as q,assign as T,defaultTo as b,optionalFunctionValue as w,invariant as B,StringObject as W,mapFirst as P}from"vest-utils";function S(n,t){return r(n)&&r(t)&&n.endsWith(t)}var A=t(S);function k(n,t){return n===t}var I=t(k);function J(n,t){return e(n,t)||u(n,t)}function K(n,t){return!!(i(t)||r(t)&&r(n))&&-1!==t.indexOf(n)}var R=t(K);function U(n,t){return o(n)&&o(t)&&Number(n)<Number(t)}function V(n,t){return e(n,t)||U(n,t)}function F(n,t,r){return J(n,t)&&V(n,r)}var M=t(F);function X(n){return a(n)||r(n)&&!n.trim()}var j=t(X),z=t(s);function C(n,t){return n in t}var D=t(C);function G(n){return Number.isNaN(n)}var H=t(G);function L(n){return"number"==typeof n}var Q=t(L),Y=t(r);function Z(n){return!!n}var $=t(Z);function _(n,t){if(a(t))return!1;for(var r in t)if(t[r]===n)return!0;return!1}var nn=t(_);function tn(n,t){return t instanceof RegExp?t.test(n):!!r(t)&&new RegExp(t).test(n)}var rn=t(tn);function en(n,t){return r(n)&&r(t)&&n.startsWith(t)}var un={condition:function(n,t){try{return t(n)}catch(n){return!1}},doesNotEndWith:A,doesNotStartWith:t(en),endsWith:S,equals:k,greaterThan:u,greaterThanOrEquals:J,gt:u,gte:J,inside:K,isArray:i,isBetween:F,isBlank:X,isBoolean:s,isEmpty:f,isEven:function(n){return!!o(n)&&0==n%2},isFalsy:$,isKeyOf:C,isNaN:G,isNegative:function(n){return U(n,0)},isNotArray:c,isNotBetween:M,isNotBlank:j,isNotBoolean:z,isNotEmpty:l,isNotKeyOf:D,isNotNaN:H,isNotNull:v,isNotNullish:N,isNotNumber:Q,isNotNumeric:h,isNotString:Y,isNotUndefined:p,isNotValueOf:nn,isNull:g,isNullish:a,isNumber:L,isNumeric:o,isOdd:function(n){return!!o(n)&&0!=n%2},isPositive:m,isString:r,isTruthy:Z,isUndefined:y,isValueOf:_,lengthEquals:d,lengthNotEquals:E,lessThan:U,lessThanOrEquals:V,longerThan:x,longerThanOrEquals:function(n,t){return J(n.length,t)},lt:U,lte:V,matches:tn,notEquals:I,notInside:R,notMatches:rn,numberEquals:e,numberNotEquals:O,shorterThan:function(n,t){return U(n.length,t)},shorterThanOrEquals:function(n,t){return V(n.length,t)},startsWith:en};function on(n){for(var t in un){var r=un[t];q(r)&&n(t,r)}}var an=n((function(n,t){var r={value:n.value,meta:n.meta||{}};return t?n.set?T(r,{parent:function(){return t?{value:t.value,meta:t.meta,parent:t.parent}:t}}):t:T(r,{parent:sn})}));function sn(){return null}function fn(n,t,r){if(r||2===arguments.length)for(var e,u=0,i=t.length;u<i;u++)!e&&u in t||(e||(e=Array.prototype.slice.call(t,0,u)),e[u]=t[u]);return n.concat(e||Array.prototype.slice.call(t))}function cn(){try{return q(Proxy)}catch(n){return!1}}function ln(n,t){return n={pass:n},t&&(n.message=t),n}function vn(n,t,r){for(var e=[],u=3;u<arguments.length;u++)e[u-3]=arguments[u];return B(s(n)||n&&s(n.pass),"Incorrect return value for rule: "+JSON.stringify(n)),s(n)?ln(n):ln(n.pass,w.apply(void 0,fn([n.message,t,r],e,!1)))}function Nn(n){function t(t,r,e){return function(){for(var u=[],i=0;i<arguments.length;i++)u[i]=arguments[i];return i=an.run({value:n},(function(){return vn.apply(void 0,fn([r.apply(void 0,fn([n],u,!1)),e,n],u,!1))})),B(i.pass,a(i.message)?"enforce/".concat(e," failed with ").concat(JSON.stringify(n)):W(i.message)),t}}var r={};if(!cn())return on((function(n,e){r[n]=t(r,e,n)})),r;var e=new Proxy(r,{get:function(n,r){if(n=un[r])return t(e,n,r)}});return e}function hn(n){var t,r=[];return function n(e){return function(){for(var u=[],i=0;i<arguments.length;i++)u[i]=arguments[i];var o=un[e];r.push((function(n){return vn.apply(void 0,fn([o.apply(void 0,fn([n],u,!1)),e,n],u,!1))}));var a={run:function(n){return b(P(r,(function(r,e){var u,i=an.run({value:n},(function(){return r(n)}));e(!i.pass,ln(!!i.pass,null!==(u=w(t,n,i.message))&&void 0!==u?u:i.message))})),ln(!0))},test:function(n){return a.run(n).pass},message:function(n){return n&&(t=n),a}};return cn()?a=new Proxy(a,{get:function(t,r){return un[r]?n(r):t[r]}}):(on((function(t){a[t]=n(t)})),a)}}(n)}var pn=function(){function n(){if(!cn())return on((function(n){t[n]=hn(n)})),T(Nn,t)}var t={context:function(){return an.useX()},extend:function(t){T(un,t),n()}};return n(),new Proxy(T(Nn,t),{get:function(n,t){return t in n?n[t]:un[t]?hn(t):void 0}})}();export{an as ctx,pn as enforce};
1
+ import{assign as n,bindNot as t,isStringValue as e,numberEquals as r,greaterThan as s,isArray as u,isNumeric as o,isNullish as i,isBoolean as c,isEmpty as a,isNotArray as l,isNotEmpty as f,isNotNull as N,isNotNullish as m,isNotNumeric as g,isNotUndefined as h,isNull as p,isPositive as d,isUndefined as y,lengthEquals as E,lengthNotEquals as v,longerThan as O,numberNotEquals as q,defaultTo as x,optionalFunctionValue as T,invariant as b,StringObject as w,mapFirst as B}from"vest-utils";import{createCascade as W}from"context";const S=W(((t,e)=>{const r={value:t.value,meta:t.meta||{}};return e?t.set?n(r,{parent:()=>function(n){if(!n)return null;return{value:n.value,meta:n.meta,parent:n.parent}}(e)}):e:n(r,{parent:P})}));function P(){return null}function k(n,t){return e(n)&&e(t)&&n.endsWith(t)}const A=t(k);function I(n,t){return n===t}const J=t(I);function K(n,t){return r(n,t)||s(n,t)}function R(n,t){return(u(t)||!(!e(t)||!e(n)))&&-1!==t.indexOf(n)}const U=t(R);function V(n,t){return o(n)&&o(t)&&Number(n)<Number(t)}function $(n,t){return r(n,t)||V(n,t)}function F(n,t,e){return K(n,t)&&$(n,e)}const M=t(F);function X(n){return i(n)||e(n)&&!n.trim()}const j=t(X),z=t(c),C=n=>!!o(n)&&n%2==0;function D(n,t){return n in t}const G=t(D);function H(n){return Number.isNaN(n)}const L=t(H);function Q(n){return V(n,0)}function Y(n){return Boolean("number"==typeof n)}const Z=t(Y),_=n=>!!o(n)&&n%2!=0,nn=t(e);function tn(n){return!!n}const en=t(tn);function rn(n,t){if(i(t))return!1;for(const e in t)if(t[e]===n)return!0;return!1}const sn=t(rn);function un(n,t){return K(n.length,t)}function on(n,t){return t instanceof RegExp?t.test(n):!!e(t)&&new RegExp(t).test(n)}const cn=t(on);function an(n,t){try{return t(n)}catch(n){return!1}}function ln(n,t){return V(n.length,t)}function fn(n,t){return $(n.length,t)}function Nn(n,t){return e(n)&&e(t)&&n.startsWith(t)}const mn=t(Nn);const gn={condition:an,doesNotEndWith:A,doesNotStartWith:mn,endsWith:k,equals:I,greaterThan:s,greaterThanOrEquals:K,gt:s,gte:K,inside:R,isArray:u,isBetween:F,isBlank:X,isBoolean:c,isEmpty:a,isEven:C,isFalsy:en,isKeyOf:D,isNaN:H,isNegative:Q,isNotArray:l,isNotBetween:M,isNotBlank:j,isNotBoolean:z,isNotEmpty:f,isNotKeyOf:G,isNotNaN:L,isNotNull:N,isNotNullish:m,isNotNumber:Z,isNotNumeric:g,isNotString:nn,isNotUndefined:h,isNotValueOf:sn,isNull:p,isNullish:i,isNumber:Y,isNumeric:o,isOdd:_,isPositive:d,isString:e,isTruthy:tn,isUndefined:y,isValueOf:rn,lengthEquals:E,lengthNotEquals:v,lessThan:V,lessThanOrEquals:$,longerThan:O,longerThanOrEquals:un,lt:V,lte:$,matches:on,notEquals:J,notInside:U,notMatches:cn,numberEquals:r,numberNotEquals:q,shorterThan:ln,shorterThanOrEquals:fn,startsWith:Nn};function hn(n){return gn[n]}function pn(n,t){const e={pass:n};return t&&(e.message=t),e}function dn(n){return x(n,pn(!0))}function yn(n,t,e,...r){return function(n){b(c(n)||n&&c(n.pass),"Incorrect return value for rule: "+JSON.stringify(n))}(n),c(n)?pn(n):pn(n.pass,T(n.message,t,e,...r))}function En(n){const t={message:function(n){return e=n,r}};let e;const r=new Proxy(t,{get:(s,u)=>{const o=hn(u);return o?function(t,r,s){return function(...u){const o=S.run({value:n},(()=>yn(r(n,...u),s,n,...u)));function c(){return i(e)?i(o.message)?`enforce/${s} failed with ${JSON.stringify(n)}`:w(o.message):w(e)}return b(o.pass,c()),t}}(r,o,u):t[u]}});return r}const vn=function(){const t={context:()=>S.useX(),extend:t=>{n(gn,t)}};return new Proxy(n(En,t),{get:(n,t)=>t in n?n[t]:hn(t)?function(n){const t=[];let e;return function n(r){return(...s)=>{const u=hn(r);t.push((n=>yn(u(n,...s),r,n,...s)));let o={run:n=>dn(B(t,((t,r)=>{var s;const u=S.run({value:n},(()=>t(n)));r(!u.pass,pn(!!u.pass,null!==(s=T(e,n,u.message))&&void 0!==s?s:u.message))}))),test:n=>o.run(n).pass,message:n=>(n&&(e=n),o)};return o=new Proxy(o,{get:(t,e)=>hn(e)?n(e):t[e]}),o}}(n)}(t):void 0})}();export{S as ctx,vn as enforce};