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.
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
@@ -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
- var output = { pass: pass };
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, function (currentValue, breakout, index) {
32
- var res = ctx.run({ value: currentValue, set: true, meta: { index: index } }, function () { return runLazyRule(currentRule, currentValue); });
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
- var _loop_1 = function (key) {
39
- var currentValue = inputObject[key];
40
- var currentRule = shapeObject[key];
41
- var res = ctx.run({ value: currentValue, set: true, meta: { key: key } }, function () {
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 { value: res };
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
- var baseRes = loose(inputObject, shapeObject);
57
+ const baseRes = loose(inputObject, shapeObject);
65
58
  if (!baseRes.pass) {
66
59
  return baseRes;
67
60
  }
68
- for (var key in inputObject) {
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
- var output = {};
80
- for (var key in shapeObject) {
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: isArrayOf, loose: loose, optional: optional, shape: shape });
79
+ enforce.extend({ isArrayOf, loose, optional, shape });
87
80
 
88
81
  export { partial };
@@ -1 +1 @@
1
- import{defaultTo as r,mapFirst as n,isNullish as t,hasOwnProperty as e}from"vest-utils";import{ctx as u,enforce as o}from"n4s";function i(r,n){return r={pass:r},n&&(r.message=n),r}function a(r,n){try{return r.run(n)}catch(r){return i(!1)}}function f(r,n){function t(t){var e=r[t],o=n[t];if(!(t=u.run({value:e,set:!0,meta:{key:t}},(function(){return a(o,e)}))).pass)return{value:t}}for(var e in n){var o=t(e);if("object"==typeof o)return o.value}return i(!0)}o.extend({isArrayOf:function(t,e){return r(n(t,(function(r,n,t){n(!(t=u.run({value:r,set:!0,meta:{index:t}},(function(){return a(e,r)}))).pass,t)})),i(!0))},loose:f,optional:function(r,n){return t(r)?i(!0):a(n,r)},shape:function(r,n){var t=f(r,n);if(!t.pass)return t;for(var u in r)if(!e(n,u))return i(!1);return i(!0)}});export function partial(r){var n,t={};for(n in r)t[n]=o.optional(r[n]);return t}
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['vest-utils']));
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
- var output = { pass: pass };
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
- var composites = [];
36
- for (var _i = 0; _i < arguments.length; _i++) {
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: run,
44
- test: function (value) { return run(value).pass; }
39
+ run,
40
+ test: (value) => run(value).pass,
45
41
  });
46
42
  function run(value) {
47
- return n4s.ctx.run({ value: value }, function () {
48
- return defaultToPassing(vestUtils.mapFirst(composites, function (composite, breakout) {
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
- var res = runLazyRule(composite, value);
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
- "use strict";!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("n4s"),require("vest-utils")):"function"==typeof define&&define.amd?define(["n4s","vest-utils"],n):(e="undefined"!=typeof globalThis?globalThis:e||self).compose=n(e.n4s,e["vest-utils"])}(this,(function(e,n){function t(e,n){return e={pass:e},n&&(e.message=n),e}return function(){function s(s){return e.ctx.run({value:s},(function(){return n.defaultTo(n.mapFirst(u,(function(e,n){try{var u=e.run(s)}catch(e){u=t(!1)}n(!u.pass,u)})),t(!0))}))}for(var u=[],i=0;i<arguments.length;i++)u[i]=arguments[i];return n.assign((function(e){e=s(e),n.invariant(e.pass,n.StringObject(e.message))}),{run:s,test:function(e){return s(e).pass}})}}));
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['vest-utils']));
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
- var output = { pass: pass };
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
- var rules = [];
38
- for (var _i = 1; _i < arguments.length; _i++) {
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
- var rules = [];
49
- for (var _i = 1; _i < arguments.length; _i++) {
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
- var rules = [];
60
- for (var _i = 1; _i < arguments.length; _i++) {
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
- var REQUIRED_COUNT = 1;
75
- function oneOf(value) {
76
- var rules = [];
77
- for (var _i = 1; _i < arguments.length; _i++) {
78
- rules[_i - 1] = arguments[_i];
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: allOf, anyOf: anyOf, noneOf: noneOf, oneOf: oneOf });
77
+ n4s.enforce.extend({ allOf, anyOf, noneOf, oneOf });
94
78
 
95
- })));
79
+ }));
@@ -1 +1 @@
1
- "use strict";!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("n4s"),require("vest-utils")):"function"==typeof define&&define.amd?define(["n4s","vest-utils"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).n4s,n["vest-utils"])}(this,(function(n,e){function t(n,e){return n={pass:n},e&&(n.message=e),n}function r(n,e){try{return n.run(e)}catch(n){return t(!1)}}e.bindNot((function(n,e){return n===e})),n.enforce.extend({allOf:function(n){for(var f=[],u=1;u<arguments.length;u++)f[u-1]=arguments[u];return e.defaultTo(e.mapFirst(f,(function(e,t){t(!(e=r(e,n)).pass,e)})),t(!0))},anyOf:function(n){for(var f=[],u=1;u<arguments.length;u++)f[u-1]=arguments[u];return e.defaultTo(e.mapFirst(f,(function(e,t){t((e=r(e,n)).pass,e)})),t(!1))},noneOf:function(n){for(var f=[],u=1;u<arguments.length;u++)f[u-1]=arguments[u];return e.defaultTo(e.mapFirst(f,(function(e,f){f((e=r(e,n)).pass,t(!1))})),t(!0))},oneOf:function(n){for(var f=[],u=1;u<arguments.length;u++)f[u-1]=arguments[u];var o=0;return f.some((function(t){if(r(t,n).pass&&o++,e.greaterThan(o,1))return!1})),t(1===o)}})}));
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))}})}));