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