n4s 4.3.7 → 4.3.8-dev-9c596e
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
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("vest-utils"),t=require("context");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("vest-utils"),t=require("context");function e(t,e){return n.isStringValue(t)&&n.isStringValue(e)&&t.endsWith(e)}const i=n.bindNot(e);function s(n,t){return n===t}const r=n.bindNot(s);function u(t,e){return n.numberEquals(t,e)||n.greaterThan(t,e)}function o(t,e){return(n.isArray(e)||!(!n.isStringValue(e)||!n.isStringValue(t)))&&-1!==e.indexOf(t)}const a=n.bindNot(o);function l(t,e){return n.isNumeric(t)&&n.isNumeric(e)&&Number(t)<Number(e)}function c(t,e){return n.numberEquals(t,e)||l(t,e)}function N(n,t,e){return u(n,t)&&c(n,e)}const f=n.bindNot(N);function g(t){return n.isNullish(t)||n.isStringValue(t)&&!t.trim()}const h=n.bindNot(g),d=n.bindNot(n.isBoolean),m=t=>!!n.isNumeric(t)&&t%2==0;function b(n,t){return n in t}const p=n.bindNot(b);function y(n){return Number.isNaN(n)}const E=n.bindNot(y);function v(n){return l(n,0)}function q(n){return Boolean("number"==typeof n)}const S=n.bindNot(q),O=t=>!!n.isNumeric(t)&&t%2!=0,x=n.bindNot(n.isStringValue);function T(n){return!!n}const V=n.bindNot(T);function B(t,e){if(n.isNullish(e))return!1;for(const n in e)if(e[n]===t)return!0;return!1}const w=n.bindNot(B);function P(n,t){return u(n.length,t)}function F(t,e){return e instanceof RegExp?e.test(t):!!n.isStringValue(e)&&new RegExp(e).test(t)}const W=n.bindNot(F);function A(n,t){try{return t(n)}catch(n){return!1}}function U(n,t){return l(n.length,t)}function j(n,t){return c(n.length,t)}function k(t,e){return n.isStringValue(t)&&n.isStringValue(e)&&t.startsWith(e)}const I=n.bindNot(k);const J={condition:A,doesNotEndWith:i,doesNotStartWith:I,endsWith:e,equals:s,greaterThan:n.greaterThan,greaterThanOrEquals:u,gt:n.greaterThan,gte:u,inside:o,isArray:n.isArray,isBetween:N,isBlank:g,isBoolean:n.isBoolean,isEmpty:n.isEmpty,isEven:m,isFalsy:V,isKeyOf:b,isNaN:y,isNegative:v,isNotArray:n.isNotArray,isNotBetween:f,isNotBlank:h,isNotBoolean:d,isNotEmpty:n.isNotEmpty,isNotKeyOf:p,isNotNaN:E,isNotNull:n.isNotNull,isNotNullish:n.isNotNullish,isNotNumber:S,isNotNumeric:n.isNotNumeric,isNotString:x,isNotUndefined:n.isNotUndefined,isNotValueOf:w,isNull:n.isNull,isNullish:n.isNullish,isNumber:q,isNumeric:n.isNumeric,isOdd:O,isPositive:n.isPositive,isString:n.isStringValue,isTruthy:T,isUndefined:n.isUndefined,isValueOf:B,lengthEquals:n.lengthEquals,lengthNotEquals:n.lengthNotEquals,lessThan:l,lessThanOrEquals:c,longerThan:n.longerThan,longerThanOrEquals:P,lt:l,lte:c,matches:F,notEquals:r,notInside:a,notMatches:W,numberEquals:n.numberEquals,numberNotEquals:n.numberNotEquals,shorterThan:U,shorterThanOrEquals:j,startsWith:k};function K(n){return J[n]}function M(t){for(const e in J){const i=K(e);n.isFunction(i)&&t(e,i)}}const R=t.createCascade(((t,e)=>{const i={value:t.value,meta:t.meta||{}};return e?t.set?n.assign(i,{parent:()=>function(n){if(!n)return null;return{value:n.value,meta:n.meta,parent:n.parent}}(e)}):e:n.assign(i,{parent:$})}));function $(){return null}function _(){try{return n.isFunction(Proxy)}catch(n){return!1}}function C(n,t){const e={pass:n};return t&&(e.message=t),e}function X(t){return n.defaultTo(t,C(!0))}function z(t,e,i,...s){return function(t){n.invariant(n.isBoolean(t)||t&&n.isBoolean(t.pass),"Incorrect return value for rule: "+JSON.stringify(t))}(t),n.isBoolean(t)?C(t):C(t.pass,n.optionalFunctionValue(t.message,e,i,...s))}function D(t){const e={message:function(n){return i=n,s}};let i;if(!_())return M(((n,t)=>{e[n]=r(e,t,n)})),e;const s=new Proxy(e,{get:(n,t)=>{const i=K(t);return i?r(s,i,t):e[t]}});return s;function r(e,s,r){return function(...u){const o=R.run({value:t},(()=>z(s(t,...u),r,t,...u)));return n.invariant(o.pass,n.isNullish(i)?n.isNullish(o.message)?`enforce/${r} failed with ${JSON.stringify(t)}`:n.StringObject(o.message):n.StringObject(i)),e}}}function G(t){const e=[];let i;return function t(s){return(...r)=>{const u=K(s);e.push((n=>z(u(n,...r),s,n,...r)));let o={run:t=>X(n.mapFirst(e,((e,s)=>{var r;const u=R.run({value:t},(()=>e(t)));s(!u.pass,C(!!u.pass,null!==(r=n.optionalFunctionValue(i,t,u.message))&&void 0!==r?r:u.message))}))),test:n=>o.run(n).pass,message:n=>(n&&(i=n),o)};return _()?(o=new Proxy(o,{get:(n,e)=>K(e)?t(e):n[e]}),o):(M((n=>{o[n]=t(n)})),o)}}(t)}const H=function(){const t={context:()=>R.useX(),extend:t=>{n.assign(J,t),e()}};return e(),new Proxy(n.assign(D,t),{get:(n,t)=>t in n?n[t]:K(t)?G(t):void 0});function e(){if(!_())return M((n=>{t[n]=G(n)})),n.assign(D,t)}}();exports.ctx=R,exports.enforce=H;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var vestUtils = require('vest-utils');
|
|
6
5
|
var n4s = require('n4s');
|
|
6
|
+
var vestUtils = require('vest-utils');
|
|
7
7
|
|
|
8
8
|
function ruleReturn(pass, message) {
|
|
9
|
-
|
|
9
|
+
const output = { pass };
|
|
10
10
|
if (message) {
|
|
11
11
|
output.message = message;
|
|
12
12
|
}
|
|
@@ -32,27 +32,20 @@ function runLazyRule(lazyRule, currentValue) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function isArrayOf(inputArray, currentRule) {
|
|
35
|
-
return defaultToPassing(vestUtils.mapFirst(inputArray,
|
|
36
|
-
|
|
35
|
+
return defaultToPassing(vestUtils.mapFirst(inputArray, (currentValue, breakout, index) => {
|
|
36
|
+
const res = n4s.ctx.run({ value: currentValue, set: true, meta: { index } }, () => runLazyRule(currentRule, currentValue));
|
|
37
37
|
breakout(!res.pass, res);
|
|
38
38
|
}));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function loose(inputObject, shapeObject) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return runLazyRule(currentRule, currentValue);
|
|
47
|
-
});
|
|
42
|
+
for (const key in shapeObject) {
|
|
43
|
+
const currentValue = inputObject[key];
|
|
44
|
+
const currentRule = shapeObject[key];
|
|
45
|
+
const res = n4s.ctx.run({ value: currentValue, set: true, meta: { key } }, () => runLazyRule(currentRule, currentValue));
|
|
48
46
|
if (!res.pass) {
|
|
49
|
-
return
|
|
47
|
+
return res;
|
|
50
48
|
}
|
|
51
|
-
};
|
|
52
|
-
for (var key in shapeObject) {
|
|
53
|
-
var state_1 = _loop_1(key);
|
|
54
|
-
if (typeof state_1 === "object")
|
|
55
|
-
return state_1.value;
|
|
56
49
|
}
|
|
57
50
|
return passing();
|
|
58
51
|
}
|
|
@@ -65,11 +58,11 @@ function optional(value, ruleChain) {
|
|
|
65
58
|
}
|
|
66
59
|
|
|
67
60
|
function shape(inputObject, shapeObject) {
|
|
68
|
-
|
|
61
|
+
const baseRes = loose(inputObject, shapeObject);
|
|
69
62
|
if (!baseRes.pass) {
|
|
70
63
|
return baseRes;
|
|
71
64
|
}
|
|
72
|
-
for (
|
|
65
|
+
for (const key in inputObject) {
|
|
73
66
|
if (!vestUtils.hasOwnProperty(shapeObject, key)) {
|
|
74
67
|
return failing();
|
|
75
68
|
}
|
|
@@ -80,13 +73,13 @@ function shape(inputObject, shapeObject) {
|
|
|
80
73
|
// Help needed improving the typings of this file.
|
|
81
74
|
// Ideally, we'd be able to extend ShapeObject, but that's not possible.
|
|
82
75
|
function partial(shapeObject) {
|
|
83
|
-
|
|
84
|
-
for (
|
|
76
|
+
const output = {};
|
|
77
|
+
for (const key in shapeObject) {
|
|
85
78
|
output[key] = n4s.enforce.optional(shapeObject[key]);
|
|
86
79
|
}
|
|
87
80
|
return output;
|
|
88
81
|
}
|
|
89
82
|
|
|
90
|
-
n4s.enforce.extend({ isArrayOf
|
|
83
|
+
n4s.enforce.extend({ isArrayOf, loose, optional, shape });
|
|
91
84
|
|
|
92
85
|
exports.partial = partial;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("n4s"),t=require("vest-utils");function r(n,t){const r={pass:n};return t&&(r.message=t),r}function e(){return r(!1)}function s(){return r(!0)}function u(n,t){try{return n.run(t)}catch(n){return e()}}function o(t,r){for(const e in r){const s=t[e],o=r[e],i=n.ctx.run({value:s,set:!0,meta:{key:e}},(()=>u(o,s)));if(!i.pass)return i}return s()}n.enforce.extend({isArrayOf:function(r,e){return o=t.mapFirst(r,((t,r,s)=>{const o=n.ctx.run({value:t,set:!0,meta:{index:s}},(()=>u(e,t)));r(!o.pass,o)})),t.defaultTo(o,s());var o},loose:o,optional:function(n,r){return t.isNullish(n)?s():u(r,n)},shape:function(n,r){const u=o(n,r);if(!u.pass)return u;for(const s in n)if(!t.hasOwnProperty(r,s))return e();return s()}}),exports.partial=function(t){const r={};for(const e in t)r[e]=n.enforce.optional(t[e]);return r};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defaultTo, assign, invariant, StringObject, mapFirst } from 'vest-utils';
|
|
2
1
|
import { ctx } from 'n4s';
|
|
2
|
+
import { defaultTo, assign, invariant, StringObject, mapFirst } from 'vest-utils';
|
|
3
3
|
|
|
4
4
|
function ruleReturn(pass, message) {
|
|
5
|
-
|
|
5
|
+
const output = { pass };
|
|
6
6
|
if (message) {
|
|
7
7
|
output.message = message;
|
|
8
8
|
}
|
|
@@ -28,27 +28,23 @@ function runLazyRule(lazyRule, currentValue) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/* eslint-disable max-lines-per-function */
|
|
31
|
-
function compose() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
composites[_i] = arguments[_i];
|
|
35
|
-
}
|
|
36
|
-
return assign(function (value) {
|
|
37
|
-
var res = run(value);
|
|
31
|
+
function compose(...composites) {
|
|
32
|
+
return assign((value) => {
|
|
33
|
+
const res = run(value);
|
|
38
34
|
invariant(res.pass, StringObject(res.message));
|
|
39
35
|
}, {
|
|
40
|
-
run
|
|
41
|
-
test:
|
|
36
|
+
run,
|
|
37
|
+
test: (value) => run(value).pass,
|
|
42
38
|
});
|
|
43
39
|
function run(value) {
|
|
44
|
-
return ctx.run({ value
|
|
45
|
-
return defaultToPassing(mapFirst(composites,
|
|
40
|
+
return ctx.run({ value }, () => {
|
|
41
|
+
return defaultToPassing(mapFirst(composites, (composite, breakout) => {
|
|
46
42
|
/* HACK: Just a small white lie. ~~HELP WANTED~~.
|
|
47
43
|
The ideal is that instead of `LazyRuleRunners` We would simply use `Lazy` to begin with.
|
|
48
44
|
The problem is that lazy rules can't really be passed to this function due to some generic hell
|
|
49
45
|
so we're limiting it to a small set of functions.
|
|
50
46
|
*/
|
|
51
|
-
|
|
47
|
+
const res = runLazyRule(composite, value);
|
|
52
48
|
breakout(!res.pass, res);
|
|
53
49
|
}));
|
|
54
50
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defaultTo as n,assign as r,invariant as
|
|
1
|
+
import{ctx as t}from"n4s";import{defaultTo as n,assign as r,invariant as s,StringObject as u,mapFirst as e}from"vest-utils";function o(t,n){const r={pass:t};return n&&(r.message=n),r}function a(t){return n(t,o(!0))}function c(t,n){try{return t.run(n)}catch(t){return o(!1)}}function f(...n){return r((t=>{const n=o(t);s(n.pass,u(n.message))}),{run:o,test:t=>o(t).pass});function o(r){return t.run({value:r},(()=>a(e(n,((t,n)=>{const s=c(t,r);n(!s.pass,s)})))))}}export{f as default};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defaultTo, mapFirst, bindNot, greaterThan } from 'vest-utils';
|
|
2
1
|
import { enforce } from 'n4s';
|
|
2
|
+
import { defaultTo, mapFirst, bindNot, greaterThan } from 'vest-utils';
|
|
3
3
|
|
|
4
4
|
function ruleReturn(pass, message) {
|
|
5
|
-
|
|
5
|
+
const output = { pass };
|
|
6
6
|
if (message) {
|
|
7
7
|
output.message = message;
|
|
8
8
|
}
|
|
@@ -30,35 +30,23 @@ function runLazyRule(lazyRule, currentValue) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function allOf(value) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
rules[_i - 1] = arguments[_i];
|
|
37
|
-
}
|
|
38
|
-
return defaultToPassing(mapFirst(rules, function (rule, breakout) {
|
|
39
|
-
var res = runLazyRule(rule, value);
|
|
33
|
+
function allOf(value, ...rules) {
|
|
34
|
+
return defaultToPassing(mapFirst(rules, (rule, breakout) => {
|
|
35
|
+
const res = runLazyRule(rule, value);
|
|
40
36
|
breakout(!res.pass, res);
|
|
41
37
|
}));
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
function anyOf(value) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
rules[_i - 1] = arguments[_i];
|
|
48
|
-
}
|
|
49
|
-
return defaultToFailing(mapFirst(rules, function (rule, breakout) {
|
|
50
|
-
var res = runLazyRule(rule, value);
|
|
40
|
+
function anyOf(value, ...rules) {
|
|
41
|
+
return defaultToFailing(mapFirst(rules, (rule, breakout) => {
|
|
42
|
+
const res = runLazyRule(rule, value);
|
|
51
43
|
breakout(res.pass, res);
|
|
52
44
|
}));
|
|
53
45
|
}
|
|
54
46
|
|
|
55
|
-
function noneOf(value) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
rules[_i - 1] = arguments[_i];
|
|
59
|
-
}
|
|
60
|
-
return defaultToPassing(mapFirst(rules, function (rule, breakout) {
|
|
61
|
-
var res = runLazyRule(rule, value);
|
|
47
|
+
function noneOf(value, ...rules) {
|
|
48
|
+
return defaultToPassing(mapFirst(rules, (rule, breakout) => {
|
|
49
|
+
const res = runLazyRule(rule, value);
|
|
62
50
|
breakout(res.pass, failing());
|
|
63
51
|
}));
|
|
64
52
|
}
|
|
@@ -68,15 +56,11 @@ function equals(value, arg1) {
|
|
|
68
56
|
}
|
|
69
57
|
bindNot(equals);
|
|
70
58
|
|
|
71
|
-
|
|
72
|
-
function oneOf(value) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
var passingCount = 0;
|
|
78
|
-
rules.some(function (rule) {
|
|
79
|
-
var res = runLazyRule(rule, value);
|
|
59
|
+
const REQUIRED_COUNT = 1;
|
|
60
|
+
function oneOf(value, ...rules) {
|
|
61
|
+
let passingCount = 0;
|
|
62
|
+
rules.some(rule => {
|
|
63
|
+
const res = runLazyRule(rule, value);
|
|
80
64
|
if (res.pass) {
|
|
81
65
|
passingCount++;
|
|
82
66
|
}
|
|
@@ -87,4 +71,4 @@ function oneOf(value) {
|
|
|
87
71
|
return ruleReturn(equals(passingCount, REQUIRED_COUNT));
|
|
88
72
|
}
|
|
89
73
|
|
|
90
|
-
enforce.extend({ allOf
|
|
74
|
+
enforce.extend({ allOf, anyOf, noneOf, oneOf });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defaultTo as
|
|
1
|
+
import{enforce as n}from"n4s";import{defaultTo as t,mapFirst as r,bindNot as u,greaterThan as e}from"vest-utils";function o(n,t){const r={pass:n};return t&&(r.message=t),r}function s(){return o(!1)}function f(n){return t(n,o(!0))}function c(n,t){try{return n.run(t)}catch(n){return s()}}function i(n,t){return n===t}u(i);n.extend({allOf:function(n,...t){return f(r(t,((t,r)=>{const u=c(t,n);r(!u.pass,u)})))},anyOf:function(n,...u){return e=r(u,((t,r)=>{const u=c(t,n);r(u.pass,u)})),t(e,s());var e},noneOf:function(n,...t){return f(r(t,((t,r)=>{r(c(t,n).pass,s())})))},oneOf:function(n,...t){let r=0;return t.some((t=>{if(c(t,n).pass&&r++,e(r,1))return!1})),o(i(r,1))}});
|