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
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";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
1
|
import { ctx } from 'n4s';
|
|
2
|
-
import { defaultTo, assign,
|
|
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,31 +28,27 @@ 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
|
});
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
export default
|
|
54
|
+
export { compose as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defaultTo as n,assign 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};
|
|
@@ -2,7 +2,7 @@ import { enforce } from 'n4s';
|
|
|
2
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))}});
|