n4s 5.0.0-dev-781e21 → 5.0.0-dev-ec989a
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/README.md +2 -0
- package/dist/cjs/compose.development.js +9 -13
- package/dist/cjs/compose.production.js +1 -1
- package/dist/cjs/compounds.development.js +16 -32
- package/dist/cjs/compounds.production.js +1 -1
- package/dist/cjs/n4s.development.js +137 -213
- package/dist/cjs/n4s.production.js +1 -1
- package/dist/cjs/schema.development.js +13 -22
- package/dist/cjs/schema.production.js +1 -1
- package/dist/es/compose.development.js +11 -15
- package/dist/es/compose.production.js +1 -1
- package/dist/es/compounds.development.js +16 -32
- package/dist/es/compounds.production.js +1 -1
- package/dist/es/n4s.development.js +158 -232
- package/dist/es/n4s.production.js +1 -1
- package/dist/es/schema.development.js +13 -20
- package/dist/es/schema.production.js +1 -1
- package/dist/umd/compose.development.js +12 -16
- package/dist/umd/compose.production.js +1 -1
- package/dist/umd/compounds.development.js +19 -35
- package/dist/umd/compounds.production.js +1 -1
- package/dist/umd/n4s.development.js +140 -216
- package/dist/umd/n4s.production.js +1 -1
- package/dist/umd/schema.development.js +16 -25
- package/dist/umd/schema.production.js +1 -1
- package/package.json +62 -55
- package/testUtils/TEnforceMock.ts +3 -0
- package/types/compose.d.ts +17 -21
- package/types/compose.d.ts.map +1 -0
- package/types/compounds.d.ts +17 -22
- package/types/compounds.d.ts.map +1 -0
- package/types/n4s.d.ts +22 -22
- package/types/n4s.d.ts.map +1 -0
- package/types/schema.d.ts +17 -21
- package/types/schema.d.ts.map +1 -0
- package/tsconfig.json +0 -8
|
@@ -2,7 +2,7 @@ import { ctx, enforce } from 'n4s';
|
|
|
2
2
|
import { defaultTo, mapFirst, isNullish, hasOwnProperty } 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,20 @@ function runLazyRule(lazyRule, currentValue) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function isArrayOf(inputArray, currentRule) {
|
|
31
|
-
return defaultToPassing(mapFirst(inputArray,
|
|
32
|
-
|
|
31
|
+
return defaultToPassing(mapFirst(inputArray, (currentValue, breakout, index) => {
|
|
32
|
+
const res = ctx.run({ value: currentValue, set: true, meta: { index } }, () => runLazyRule(currentRule, currentValue));
|
|
33
33
|
breakout(!res.pass, res);
|
|
34
34
|
}));
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
function loose(inputObject, shapeObject) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return runLazyRule(currentRule, currentValue);
|
|
43
|
-
});
|
|
38
|
+
for (const key in shapeObject) {
|
|
39
|
+
const currentValue = inputObject[key];
|
|
40
|
+
const currentRule = shapeObject[key];
|
|
41
|
+
const res = ctx.run({ value: currentValue, set: true, meta: { key } }, () => runLazyRule(currentRule, currentValue));
|
|
44
42
|
if (!res.pass) {
|
|
45
|
-
return
|
|
43
|
+
return res;
|
|
46
44
|
}
|
|
47
|
-
};
|
|
48
|
-
for (var key in shapeObject) {
|
|
49
|
-
var state_1 = _loop_1(key);
|
|
50
|
-
if (typeof state_1 === "object")
|
|
51
|
-
return state_1.value;
|
|
52
45
|
}
|
|
53
46
|
return passing();
|
|
54
47
|
}
|
|
@@ -61,11 +54,11 @@ function optional(value, ruleChain) {
|
|
|
61
54
|
}
|
|
62
55
|
|
|
63
56
|
function shape(inputObject, shapeObject) {
|
|
64
|
-
|
|
57
|
+
const baseRes = loose(inputObject, shapeObject);
|
|
65
58
|
if (!baseRes.pass) {
|
|
66
59
|
return baseRes;
|
|
67
60
|
}
|
|
68
|
-
for (
|
|
61
|
+
for (const key in inputObject) {
|
|
69
62
|
if (!hasOwnProperty(shapeObject, key)) {
|
|
70
63
|
return failing();
|
|
71
64
|
}
|
|
@@ -76,13 +69,13 @@ function shape(inputObject, shapeObject) {
|
|
|
76
69
|
// Help needed improving the typings of this file.
|
|
77
70
|
// Ideally, we'd be able to extend ShapeObject, but that's not possible.
|
|
78
71
|
function partial(shapeObject) {
|
|
79
|
-
|
|
80
|
-
for (
|
|
72
|
+
const output = {};
|
|
73
|
+
for (const key in shapeObject) {
|
|
81
74
|
output[key] = enforce.optional(shapeObject[key]);
|
|
82
75
|
}
|
|
83
76
|
return output;
|
|
84
77
|
}
|
|
85
78
|
|
|
86
|
-
enforce.extend({ isArrayOf
|
|
79
|
+
enforce.extend({ isArrayOf, loose, optional, shape });
|
|
87
80
|
|
|
88
81
|
export { partial };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ctx as n,enforce as t}from"n4s";import{defaultTo as r,mapFirst as o,isNullish as e,hasOwnProperty as u}from"vest-utils";function s(n,t){const r={pass:n};return t&&(r.message=t),r}function i(){return s(!1)}function c(){return s(!0)}function f(n,t){try{return n.run(t)}catch(n){return i()}}function a(t,r){for(const o in r){const e=t[o],u=r[o],s=n.run({value:e,set:!0,meta:{key:o}},(()=>f(u,e)));if(!s.pass)return s}return c()}function p(n){const r={};for(const o in n)r[o]=t.optional(n[o]);return r}t.extend({isArrayOf:function(t,e){return u=o(t,((t,r,o)=>{const u=n.run({value:t,set:!0,meta:{index:o}},(()=>f(e,t)));r(!u.pass,u)})),r(u,c());var u},loose:a,optional:function(n,t){return e(n)?c():f(t,n)},shape:function(n,t){const r=a(n,t);if(!r.pass)return r;for(const r in n)if(!u(t,r))return i();return c()}});export{p as partial};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('n4s'), require('vest-utils')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['n4s', 'vest-utils'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.compose = factory(global.n4s, global[
|
|
5
|
-
}(this, (function (n4s, vestUtils) { 'use strict';
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.compose = factory(global.n4s, global["vest-utils"]));
|
|
5
|
+
})(this, (function (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,23 @@
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/* eslint-disable max-lines-per-function */
|
|
34
|
-
function compose() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
composites[_i] = arguments[_i];
|
|
38
|
-
}
|
|
39
|
-
return vestUtils.assign(function (value) {
|
|
40
|
-
var res = run(value);
|
|
34
|
+
function compose(...composites) {
|
|
35
|
+
return vestUtils.assign((value) => {
|
|
36
|
+
const res = run(value);
|
|
41
37
|
vestUtils.invariant(res.pass, vestUtils.StringObject(res.message));
|
|
42
38
|
}, {
|
|
43
|
-
run
|
|
44
|
-
test:
|
|
39
|
+
run,
|
|
40
|
+
test: (value) => run(value).pass,
|
|
45
41
|
});
|
|
46
42
|
function run(value) {
|
|
47
|
-
return n4s.ctx.run({ value
|
|
48
|
-
return defaultToPassing(vestUtils.mapFirst(composites,
|
|
43
|
+
return n4s.ctx.run({ value }, () => {
|
|
44
|
+
return defaultToPassing(vestUtils.mapFirst(composites, (composite, breakout) => {
|
|
49
45
|
/* HACK: Just a small white lie. ~~HELP WANTED~~.
|
|
50
46
|
The ideal is that instead of `LazyRuleRunners` We would simply use `Lazy` to begin with.
|
|
51
47
|
The problem is that lazy rules can't really be passed to this function due to some generic hell
|
|
52
48
|
so we're limiting it to a small set of functions.
|
|
53
49
|
*/
|
|
54
|
-
|
|
50
|
+
const res = runLazyRule(composite, value);
|
|
55
51
|
breakout(!res.pass, res);
|
|
56
52
|
}));
|
|
57
53
|
});
|
|
@@ -60,4 +56,4 @@
|
|
|
60
56
|
|
|
61
57
|
return compose;
|
|
62
58
|
|
|
63
|
-
}))
|
|
59
|
+
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("n4s"),require("vest-utils")):"function"==typeof define&&define.amd?define(["n4s","vest-utils"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).compose=t(e.n4s,e["vest-utils"])}(this,(function(e,t){"use strict";function n(e,t){const n={pass:e};return t&&(n.message=t),n}function s(e){return t.defaultTo(e,n(!0))}function u(e,t){try{return e.run(t)}catch(e){return n(!1)}}return function(...n){return t.assign((e=>{const n=r(e);t.invariant(n.pass,t.StringObject(n.message))}),{run:r,test:e=>r(e).pass});function r(r){return e.ctx.run({value:r},(()=>s(t.mapFirst(n,((e,t)=>{const n=u(e,r);t(!n.pass,n)})))))}}}));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('n4s'), require('vest-utils')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['n4s', 'vest-utils'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.n4s, global[
|
|
5
|
-
}(this, (function (n4s, vestUtils) { 'use strict';
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.n4s, global["vest-utils"]));
|
|
5
|
+
})(this, (function (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
|
}
|
|
@@ -33,35 +33,23 @@
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function allOf(value) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
rules[_i - 1] = arguments[_i];
|
|
40
|
-
}
|
|
41
|
-
return defaultToPassing(vestUtils.mapFirst(rules, function (rule, breakout) {
|
|
42
|
-
var res = runLazyRule(rule, value);
|
|
36
|
+
function allOf(value, ...rules) {
|
|
37
|
+
return defaultToPassing(vestUtils.mapFirst(rules, (rule, breakout) => {
|
|
38
|
+
const res = runLazyRule(rule, value);
|
|
43
39
|
breakout(!res.pass, res);
|
|
44
40
|
}));
|
|
45
41
|
}
|
|
46
42
|
|
|
47
|
-
function anyOf(value) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
rules[_i - 1] = arguments[_i];
|
|
51
|
-
}
|
|
52
|
-
return defaultToFailing(vestUtils.mapFirst(rules, function (rule, breakout) {
|
|
53
|
-
var res = runLazyRule(rule, value);
|
|
43
|
+
function anyOf(value, ...rules) {
|
|
44
|
+
return defaultToFailing(vestUtils.mapFirst(rules, (rule, breakout) => {
|
|
45
|
+
const res = runLazyRule(rule, value);
|
|
54
46
|
breakout(res.pass, res);
|
|
55
47
|
}));
|
|
56
48
|
}
|
|
57
49
|
|
|
58
|
-
function noneOf(value) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
rules[_i - 1] = arguments[_i];
|
|
62
|
-
}
|
|
63
|
-
return defaultToPassing(vestUtils.mapFirst(rules, function (rule, breakout) {
|
|
64
|
-
var res = runLazyRule(rule, value);
|
|
50
|
+
function noneOf(value, ...rules) {
|
|
51
|
+
return defaultToPassing(vestUtils.mapFirst(rules, (rule, breakout) => {
|
|
52
|
+
const res = runLazyRule(rule, value);
|
|
65
53
|
breakout(res.pass, failing());
|
|
66
54
|
}));
|
|
67
55
|
}
|
|
@@ -71,15 +59,11 @@
|
|
|
71
59
|
}
|
|
72
60
|
vestUtils.bindNot(equals);
|
|
73
61
|
|
|
74
|
-
|
|
75
|
-
function oneOf(value) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
var passingCount = 0;
|
|
81
|
-
rules.some(function (rule) {
|
|
82
|
-
var res = runLazyRule(rule, value);
|
|
62
|
+
const REQUIRED_COUNT = 1;
|
|
63
|
+
function oneOf(value, ...rules) {
|
|
64
|
+
let passingCount = 0;
|
|
65
|
+
rules.some(rule => {
|
|
66
|
+
const res = runLazyRule(rule, value);
|
|
83
67
|
if (res.pass) {
|
|
84
68
|
passingCount++;
|
|
85
69
|
}
|
|
@@ -90,6 +74,6 @@
|
|
|
90
74
|
return ruleReturn(equals(passingCount, REQUIRED_COUNT));
|
|
91
75
|
}
|
|
92
76
|
|
|
93
|
-
n4s.enforce.extend({ allOf
|
|
77
|
+
n4s.enforce.extend({ allOf, anyOf, noneOf, oneOf });
|
|
94
78
|
|
|
95
|
-
}))
|
|
79
|
+
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("n4s"),require("vest-utils")):"function"==typeof define&&define.amd?define(["n4s","vest-utils"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).n4s,n["vest-utils"])}(this,(function(n,t){"use strict";function e(n,t){const e={pass:n};return t&&(e.message=t),e}function r(){return e(!1)}function s(n){return t.defaultTo(n,e(!0))}function u(n,t){try{return n.run(t)}catch(n){return r()}}function i(n,t){return n===t}t.bindNot(i);n.enforce.extend({allOf:function(n,...e){return s(t.mapFirst(e,((t,e)=>{const r=u(t,n);e(!r.pass,r)})))},anyOf:function(n,...e){return s=t.mapFirst(e,((t,e)=>{const r=u(t,n);e(r.pass,r)})),t.defaultTo(s,r());var s},noneOf:function(n,...e){return s(t.mapFirst(e,((t,e)=>{e(u(t,n).pass,r())})))},oneOf:function(n,...r){let s=0;return r.some((e=>{if(u(e,n).pass&&s++,t.greaterThan(s,1))return!1})),e(i(s,1))}})}));
|