@scenid/react-formulator 1.2.2 → 1.2.3
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/index.cjs.js +171 -93
- package/dist/index.esm.js +171 -93
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -20513,90 +20513,149 @@ function requireCompiler () {
|
|
|
20513
20513
|
return compileTypeDefinition;
|
|
20514
20514
|
}()
|
|
20515
20515
|
}, {
|
|
20516
|
-
key: "
|
|
20516
|
+
key: "compileOptions",
|
|
20517
20517
|
value: function () {
|
|
20518
|
-
var
|
|
20519
|
-
var
|
|
20518
|
+
var _compileOptions = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(options) {
|
|
20519
|
+
var res;
|
|
20520
20520
|
return _regenerator["default"].wrap(function _callee9$(_context9) {
|
|
20521
20521
|
while (1) {
|
|
20522
20522
|
switch (_context9.prev = _context9.next) {
|
|
20523
|
+
case 0:
|
|
20524
|
+
if (!((0, _helpers.isObject)(options) && options.$ref !== undefined)) {
|
|
20525
|
+
_context9.next = 7;
|
|
20526
|
+
break;
|
|
20527
|
+
}
|
|
20528
|
+
|
|
20529
|
+
_context9.next = 3;
|
|
20530
|
+
return this.resolveRef(options.$ref);
|
|
20531
|
+
|
|
20532
|
+
case 3:
|
|
20533
|
+
res = _context9.sent;
|
|
20534
|
+
|
|
20535
|
+
if (!(0, _helpers.isObject)(res)) {
|
|
20536
|
+
_context9.next = 6;
|
|
20537
|
+
break;
|
|
20538
|
+
}
|
|
20539
|
+
|
|
20540
|
+
return _context9.abrupt("return", Object.keys(res));
|
|
20541
|
+
|
|
20542
|
+
case 6:
|
|
20543
|
+
return _context9.abrupt("return", res);
|
|
20544
|
+
|
|
20545
|
+
case 7:
|
|
20546
|
+
return _context9.abrupt("return", options);
|
|
20547
|
+
|
|
20548
|
+
case 8:
|
|
20549
|
+
case "end":
|
|
20550
|
+
return _context9.stop();
|
|
20551
|
+
}
|
|
20552
|
+
}
|
|
20553
|
+
}, _callee9, this);
|
|
20554
|
+
}));
|
|
20555
|
+
|
|
20556
|
+
function compileOptions(_x12) {
|
|
20557
|
+
return _compileOptions.apply(this, arguments);
|
|
20558
|
+
}
|
|
20559
|
+
|
|
20560
|
+
return compileOptions;
|
|
20561
|
+
}()
|
|
20562
|
+
}, {
|
|
20563
|
+
key: "compileField",
|
|
20564
|
+
value: function () {
|
|
20565
|
+
var _compileField = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(uncompiledField, name) {
|
|
20566
|
+
var field, prohibited, required, optional, type, defaultDef, options;
|
|
20567
|
+
return _regenerator["default"].wrap(function _callee10$(_context10) {
|
|
20568
|
+
while (1) {
|
|
20569
|
+
switch (_context10.prev = _context10.next) {
|
|
20523
20570
|
case 0:
|
|
20524
20571
|
field = (0, _helpers.deepCopy)(uncompiledField);
|
|
20525
|
-
prohibited = field.prohibited, required = field.required, optional = field.optional, type = field.type, defaultDef = field["default"];
|
|
20572
|
+
prohibited = field.prohibited, required = field.required, optional = field.optional, type = field.type, defaultDef = field["default"], options = field.options;
|
|
20526
20573
|
|
|
20527
20574
|
if (!(type === undefined)) {
|
|
20528
|
-
|
|
20575
|
+
_context10.next = 4;
|
|
20529
20576
|
break;
|
|
20530
20577
|
}
|
|
20531
20578
|
|
|
20532
20579
|
throw new _Error.SchemaError("Field \"".concat(name, "\" is missing a type definition"));
|
|
20533
20580
|
|
|
20534
20581
|
case 4:
|
|
20535
|
-
|
|
20582
|
+
_context10.next = 6;
|
|
20536
20583
|
return this.compileTypeDefinition(type, name);
|
|
20537
20584
|
|
|
20538
20585
|
case 6:
|
|
20539
|
-
field.type =
|
|
20586
|
+
field.type = _context10.sent;
|
|
20540
20587
|
|
|
20541
20588
|
if (!(defaultDef !== undefined)) {
|
|
20542
|
-
|
|
20589
|
+
_context10.next = 11;
|
|
20543
20590
|
break;
|
|
20544
20591
|
}
|
|
20545
20592
|
|
|
20546
|
-
|
|
20593
|
+
_context10.next = 10;
|
|
20547
20594
|
return this.compileTypeDefinition(defaultDef, name);
|
|
20548
20595
|
|
|
20549
20596
|
case 10:
|
|
20550
|
-
field["default"] =
|
|
20597
|
+
field["default"] = _context10.sent;
|
|
20551
20598
|
|
|
20552
20599
|
case 11:
|
|
20553
|
-
if (!
|
|
20554
|
-
|
|
20600
|
+
if (!options) {
|
|
20601
|
+
_context10.next = 15;
|
|
20555
20602
|
break;
|
|
20556
20603
|
}
|
|
20557
20604
|
|
|
20558
|
-
|
|
20559
|
-
return this.
|
|
20605
|
+
_context10.next = 14;
|
|
20606
|
+
return this.compileOptions(options);
|
|
20560
20607
|
|
|
20561
20608
|
case 14:
|
|
20562
|
-
field.
|
|
20609
|
+
field.options = _context10.sent;
|
|
20563
20610
|
|
|
20564
20611
|
case 15:
|
|
20565
|
-
if (!(
|
|
20566
|
-
|
|
20612
|
+
if (!(prohibited !== undefined)) {
|
|
20613
|
+
_context10.next = 19;
|
|
20567
20614
|
break;
|
|
20568
20615
|
}
|
|
20569
20616
|
|
|
20570
|
-
|
|
20571
|
-
return this.compileRules(
|
|
20617
|
+
_context10.next = 18;
|
|
20618
|
+
return this.compileRules(prohibited, name);
|
|
20572
20619
|
|
|
20573
20620
|
case 18:
|
|
20574
|
-
field.
|
|
20621
|
+
field.prohibited = _context10.sent;
|
|
20575
20622
|
|
|
20576
20623
|
case 19:
|
|
20577
|
-
if (!(
|
|
20578
|
-
|
|
20624
|
+
if (!(required !== undefined)) {
|
|
20625
|
+
_context10.next = 23;
|
|
20579
20626
|
break;
|
|
20580
20627
|
}
|
|
20581
20628
|
|
|
20582
|
-
|
|
20583
|
-
return this.compileRules(
|
|
20629
|
+
_context10.next = 22;
|
|
20630
|
+
return this.compileRules(required, name);
|
|
20584
20631
|
|
|
20585
20632
|
case 22:
|
|
20586
|
-
field.
|
|
20633
|
+
field.required = _context10.sent;
|
|
20587
20634
|
|
|
20588
20635
|
case 23:
|
|
20589
|
-
|
|
20636
|
+
if (!(optional !== undefined)) {
|
|
20637
|
+
_context10.next = 27;
|
|
20638
|
+
break;
|
|
20639
|
+
}
|
|
20640
|
+
|
|
20641
|
+
_context10.next = 26;
|
|
20642
|
+
return this.compileRules(optional, name);
|
|
20590
20643
|
|
|
20591
|
-
case
|
|
20644
|
+
case 26:
|
|
20645
|
+
field.optional = _context10.sent;
|
|
20646
|
+
|
|
20647
|
+
case 27:
|
|
20648
|
+
return _context10.abrupt("return", field);
|
|
20649
|
+
|
|
20650
|
+
case 28:
|
|
20592
20651
|
case "end":
|
|
20593
|
-
return
|
|
20652
|
+
return _context10.stop();
|
|
20594
20653
|
}
|
|
20595
20654
|
}
|
|
20596
|
-
},
|
|
20655
|
+
}, _callee10, this);
|
|
20597
20656
|
}));
|
|
20598
20657
|
|
|
20599
|
-
function compileField(
|
|
20658
|
+
function compileField(_x13, _x14) {
|
|
20600
20659
|
return _compileField.apply(this, arguments);
|
|
20601
20660
|
}
|
|
20602
20661
|
|
|
@@ -20605,135 +20664,135 @@ function requireCompiler () {
|
|
|
20605
20664
|
}, {
|
|
20606
20665
|
key: "compileCatalog",
|
|
20607
20666
|
value: function () {
|
|
20608
|
-
var _compileCatalog = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
20667
|
+
var _compileCatalog = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13(uncompiledCatalog) {
|
|
20609
20668
|
var _this2 = this;
|
|
20610
20669
|
|
|
20611
20670
|
var catalog, result;
|
|
20612
|
-
return _regenerator["default"].wrap(function
|
|
20671
|
+
return _regenerator["default"].wrap(function _callee13$(_context13) {
|
|
20613
20672
|
while (1) {
|
|
20614
|
-
switch (
|
|
20673
|
+
switch (_context13.prev = _context13.next) {
|
|
20615
20674
|
case 0:
|
|
20616
20675
|
catalog = (0, _helpers.deepCopy)(uncompiledCatalog);
|
|
20617
20676
|
|
|
20618
20677
|
if ((0, _helpers.isObject)(catalog)) {
|
|
20619
|
-
|
|
20678
|
+
_context13.next = 3;
|
|
20620
20679
|
break;
|
|
20621
20680
|
}
|
|
20622
20681
|
|
|
20623
20682
|
throw new _Error.SchemaError("Invalid type of \"".concat((0, _typeof2["default"])(catalog), "\" for catalog."));
|
|
20624
20683
|
|
|
20625
20684
|
case 3:
|
|
20626
|
-
|
|
20685
|
+
_context13.next = 5;
|
|
20627
20686
|
return Promise.all(Object.entries(catalog).map( /*#__PURE__*/function () {
|
|
20628
|
-
var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
20629
|
-
return _regenerator["default"].wrap(function
|
|
20687
|
+
var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(e) {
|
|
20688
|
+
return _regenerator["default"].wrap(function _callee12$(_context12) {
|
|
20630
20689
|
while (1) {
|
|
20631
|
-
switch (
|
|
20690
|
+
switch (_context12.prev = _context12.next) {
|
|
20632
20691
|
case 0:
|
|
20633
20692
|
if (!(0, _helpers.isObject)(e[1])) {
|
|
20634
|
-
|
|
20693
|
+
_context12.next = 2;
|
|
20635
20694
|
break;
|
|
20636
20695
|
}
|
|
20637
20696
|
|
|
20638
|
-
return
|
|
20697
|
+
return _context12.abrupt("return", (0, _defineProperty2["default"])({}, e[0], e[1]));
|
|
20639
20698
|
|
|
20640
20699
|
case 2:
|
|
20641
20700
|
if (Array.isArray(e[1])) {
|
|
20642
|
-
|
|
20701
|
+
_context12.next = 4;
|
|
20643
20702
|
break;
|
|
20644
20703
|
}
|
|
20645
20704
|
|
|
20646
20705
|
throw new _Error.SchemaError("Invalid type of \"".concat((0, _typeof2["default"])(e[1]), "\" for catalog at path \"").concat(e[0], "\"."));
|
|
20647
20706
|
|
|
20648
20707
|
case 4:
|
|
20649
|
-
|
|
20650
|
-
|
|
20651
|
-
|
|
20652
|
-
|
|
20708
|
+
_context12.t0 = _defineProperty2["default"];
|
|
20709
|
+
_context12.t1 = {};
|
|
20710
|
+
_context12.t2 = e[0];
|
|
20711
|
+
_context12.next = 9;
|
|
20653
20712
|
return Promise.all(e[1].map( /*#__PURE__*/function () {
|
|
20654
|
-
var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
20713
|
+
var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(ee) {
|
|
20655
20714
|
var res;
|
|
20656
|
-
return _regenerator["default"].wrap(function
|
|
20715
|
+
return _regenerator["default"].wrap(function _callee11$(_context11) {
|
|
20657
20716
|
while (1) {
|
|
20658
|
-
switch (
|
|
20717
|
+
switch (_context11.prev = _context11.next) {
|
|
20659
20718
|
case 0:
|
|
20660
20719
|
if ((0, _helpers.isObject)(ee)) {
|
|
20661
|
-
|
|
20720
|
+
_context11.next = 2;
|
|
20662
20721
|
break;
|
|
20663
20722
|
}
|
|
20664
20723
|
|
|
20665
|
-
return
|
|
20724
|
+
return _context11.abrupt("return", ee);
|
|
20666
20725
|
|
|
20667
20726
|
case 2:
|
|
20668
20727
|
if (!(ee.$ref === undefined)) {
|
|
20669
|
-
|
|
20728
|
+
_context11.next = 4;
|
|
20670
20729
|
break;
|
|
20671
20730
|
}
|
|
20672
20731
|
|
|
20673
20732
|
throw new _Error.SchemaError("Objects inside a catalog Array need to define a $ref at path \"".concat(e[0], "\"."));
|
|
20674
20733
|
|
|
20675
20734
|
case 4:
|
|
20676
|
-
|
|
20735
|
+
_context11.next = 6;
|
|
20677
20736
|
return _this2.resolveRef(ee.$ref);
|
|
20678
20737
|
|
|
20679
20738
|
case 6:
|
|
20680
|
-
res =
|
|
20739
|
+
res = _context11.sent;
|
|
20681
20740
|
|
|
20682
20741
|
if (!(0, _helpers.isObject)(res)) {
|
|
20683
|
-
|
|
20742
|
+
_context11.next = 9;
|
|
20684
20743
|
break;
|
|
20685
20744
|
}
|
|
20686
20745
|
|
|
20687
|
-
return
|
|
20746
|
+
return _context11.abrupt("return", Object.keys(res));
|
|
20688
20747
|
|
|
20689
20748
|
case 9:
|
|
20690
|
-
return
|
|
20749
|
+
return _context11.abrupt("return", res);
|
|
20691
20750
|
|
|
20692
20751
|
case 10:
|
|
20693
20752
|
case "end":
|
|
20694
|
-
return
|
|
20753
|
+
return _context11.stop();
|
|
20695
20754
|
}
|
|
20696
20755
|
}
|
|
20697
|
-
},
|
|
20756
|
+
}, _callee11);
|
|
20698
20757
|
}));
|
|
20699
20758
|
|
|
20700
|
-
return function (
|
|
20759
|
+
return function (_x17) {
|
|
20701
20760
|
return _ref8.apply(this, arguments);
|
|
20702
20761
|
};
|
|
20703
20762
|
}()));
|
|
20704
20763
|
|
|
20705
20764
|
case 9:
|
|
20706
|
-
|
|
20707
|
-
return
|
|
20765
|
+
_context12.t3 = _context12.sent;
|
|
20766
|
+
return _context12.abrupt("return", (0, _context12.t0)(_context12.t1, _context12.t2, _context12.t3));
|
|
20708
20767
|
|
|
20709
20768
|
case 11:
|
|
20710
20769
|
case "end":
|
|
20711
|
-
return
|
|
20770
|
+
return _context12.stop();
|
|
20712
20771
|
}
|
|
20713
20772
|
}
|
|
20714
|
-
},
|
|
20773
|
+
}, _callee12);
|
|
20715
20774
|
}));
|
|
20716
20775
|
|
|
20717
|
-
return function (
|
|
20776
|
+
return function (_x16) {
|
|
20718
20777
|
return _ref6.apply(this, arguments);
|
|
20719
20778
|
};
|
|
20720
20779
|
}()));
|
|
20721
20780
|
|
|
20722
20781
|
case 5:
|
|
20723
|
-
result =
|
|
20724
|
-
return
|
|
20782
|
+
result = _context13.sent;
|
|
20783
|
+
return _context13.abrupt("return", result.reduce(function (l, r) {
|
|
20725
20784
|
return _objectSpread(_objectSpread({}, l), r);
|
|
20726
20785
|
}, {}));
|
|
20727
20786
|
|
|
20728
20787
|
case 7:
|
|
20729
20788
|
case "end":
|
|
20730
|
-
return
|
|
20789
|
+
return _context13.stop();
|
|
20731
20790
|
}
|
|
20732
20791
|
}
|
|
20733
|
-
},
|
|
20792
|
+
}, _callee13);
|
|
20734
20793
|
}));
|
|
20735
20794
|
|
|
20736
|
-
function compileCatalog(
|
|
20795
|
+
function compileCatalog(_x15) {
|
|
20737
20796
|
return _compileCatalog.apply(this, arguments);
|
|
20738
20797
|
}
|
|
20739
20798
|
|
|
@@ -20742,16 +20801,16 @@ function requireCompiler () {
|
|
|
20742
20801
|
}, {
|
|
20743
20802
|
key: "process",
|
|
20744
20803
|
value: function () {
|
|
20745
|
-
var _process = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
20804
|
+
var _process = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(schemaArg, resolver) {
|
|
20746
20805
|
var schema, catalog, properties, fieldNames, i, name, field;
|
|
20747
|
-
return _regenerator["default"].wrap(function
|
|
20806
|
+
return _regenerator["default"].wrap(function _callee14$(_context14) {
|
|
20748
20807
|
while (1) {
|
|
20749
|
-
switch (
|
|
20808
|
+
switch (_context14.prev = _context14.next) {
|
|
20750
20809
|
case 0:
|
|
20751
20810
|
this.resolver = resolver;
|
|
20752
20811
|
|
|
20753
20812
|
if ((0, _helpers.isObject)(schemaArg)) {
|
|
20754
|
-
|
|
20813
|
+
_context14.next = 3;
|
|
20755
20814
|
break;
|
|
20756
20815
|
}
|
|
20757
20816
|
|
|
@@ -20764,15 +20823,15 @@ function requireCompiler () {
|
|
|
20764
20823
|
catalog = schema.catalog, properties = schema.properties;
|
|
20765
20824
|
|
|
20766
20825
|
if (!(catalog !== undefined)) {
|
|
20767
|
-
|
|
20826
|
+
_context14.next = 11;
|
|
20768
20827
|
break;
|
|
20769
20828
|
}
|
|
20770
20829
|
|
|
20771
|
-
|
|
20830
|
+
_context14.next = 10;
|
|
20772
20831
|
return this.compileCatalog(catalog);
|
|
20773
20832
|
|
|
20774
20833
|
case 10:
|
|
20775
|
-
schema.catalog =
|
|
20834
|
+
schema.catalog = _context14.sent;
|
|
20776
20835
|
|
|
20777
20836
|
case 11:
|
|
20778
20837
|
fieldNames = Object.keys(properties);
|
|
@@ -20780,35 +20839,35 @@ function requireCompiler () {
|
|
|
20780
20839
|
|
|
20781
20840
|
case 13:
|
|
20782
20841
|
if (!(i < fieldNames.length)) {
|
|
20783
|
-
|
|
20842
|
+
_context14.next = 22;
|
|
20784
20843
|
break;
|
|
20785
20844
|
}
|
|
20786
20845
|
|
|
20787
20846
|
name = fieldNames[i];
|
|
20788
20847
|
field = properties[name];
|
|
20789
|
-
|
|
20848
|
+
_context14.next = 18;
|
|
20790
20849
|
return this.compileField(field, name);
|
|
20791
20850
|
|
|
20792
20851
|
case 18:
|
|
20793
|
-
properties[name] =
|
|
20852
|
+
properties[name] = _context14.sent;
|
|
20794
20853
|
|
|
20795
20854
|
case 19:
|
|
20796
20855
|
i++;
|
|
20797
|
-
|
|
20856
|
+
_context14.next = 13;
|
|
20798
20857
|
break;
|
|
20799
20858
|
|
|
20800
20859
|
case 22:
|
|
20801
|
-
return
|
|
20860
|
+
return _context14.abrupt("return", schema);
|
|
20802
20861
|
|
|
20803
20862
|
case 23:
|
|
20804
20863
|
case "end":
|
|
20805
|
-
return
|
|
20864
|
+
return _context14.stop();
|
|
20806
20865
|
}
|
|
20807
20866
|
}
|
|
20808
|
-
},
|
|
20867
|
+
}, _callee14, this);
|
|
20809
20868
|
}));
|
|
20810
20869
|
|
|
20811
|
-
function process(
|
|
20870
|
+
function process(_x18, _x19) {
|
|
20812
20871
|
return _process.apply(this, arguments);
|
|
20813
20872
|
}
|
|
20814
20873
|
|
|
@@ -28521,6 +28580,11 @@ function requireTypeValidator () {
|
|
|
28521
28580
|
return value === String(other[as]);
|
|
28522
28581
|
};
|
|
28523
28582
|
|
|
28583
|
+
_validator["default"].isZipCode = function (value, _ref3, other) {
|
|
28584
|
+
var localeFrom = _ref3.localeFrom;
|
|
28585
|
+
return _validator["default"].isPostalCode(value, String(other[localeFrom]) || 'any');
|
|
28586
|
+
};
|
|
28587
|
+
|
|
28524
28588
|
var _default = _validator["default"];
|
|
28525
28589
|
exports["default"] = _default;
|
|
28526
28590
|
} (TypeValidator));
|
|
@@ -28541,6 +28605,8 @@ function requireValidator () {
|
|
|
28541
28605
|
});
|
|
28542
28606
|
exports["default"] = void 0;
|
|
28543
28607
|
|
|
28608
|
+
var _defineProperty2 = _interopRequireDefault(requireDefineProperty());
|
|
28609
|
+
|
|
28544
28610
|
var _typeof2 = _interopRequireDefault(require_typeof());
|
|
28545
28611
|
|
|
28546
28612
|
var _classCallCheck2 = _interopRequireDefault(requireClassCallCheck());
|
|
@@ -28553,6 +28619,10 @@ function requireValidator () {
|
|
|
28553
28619
|
|
|
28554
28620
|
var _Error = require_Error();
|
|
28555
28621
|
|
|
28622
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
28623
|
+
|
|
28624
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
28625
|
+
|
|
28556
28626
|
var ValidationResult = /*#__PURE__*/function () {
|
|
28557
28627
|
function ValidationResult() {
|
|
28558
28628
|
(0, _classCallCheck2["default"])(this, ValidationResult);
|
|
@@ -28704,8 +28774,7 @@ function requireValidator () {
|
|
|
28704
28774
|
prohibited = _schema$name.prohibited,
|
|
28705
28775
|
required = _schema$name.required,
|
|
28706
28776
|
optional = _schema$name.optional,
|
|
28707
|
-
type = _schema$name.type
|
|
28708
|
-
defaultVal = _schema$name["default"];
|
|
28777
|
+
type = _schema$name.type;
|
|
28709
28778
|
var value = data[name];
|
|
28710
28779
|
var hasProhibited = prohibited !== undefined;
|
|
28711
28780
|
var hasRequired = required !== undefined;
|
|
@@ -28716,7 +28785,7 @@ function requireValidator () {
|
|
|
28716
28785
|
var isRequired = hasRequired && this.validateRules(name, required, data);
|
|
28717
28786
|
if (!isRequired && !isProhibited && optional === true) isOptional = true;
|
|
28718
28787
|
|
|
28719
|
-
if (isRequired &&
|
|
28788
|
+
if (isRequired && _TypeValidator["default"].isEmpty(value)) {
|
|
28720
28789
|
return new FieldResult(name, data[name], undefined, isProhibited, isRequired, isOptional, true, [{
|
|
28721
28790
|
message: "\"".concat(name, "\" is required"),
|
|
28722
28791
|
path: name,
|
|
@@ -28727,10 +28796,6 @@ function requireValidator () {
|
|
|
28727
28796
|
|
|
28728
28797
|
if (!isOptional && !isRequired) return new FieldResult(name, data[name], undefined, isProhibited, isRequired, isOptional);
|
|
28729
28798
|
|
|
28730
|
-
if (_TypeValidator["default"].isEmpty(value) && defaultVal !== undefined) {
|
|
28731
|
-
return new FieldResult(name, data[name], this.castType(name, type, defaultVal), isProhibited, isRequired, isOptional);
|
|
28732
|
-
}
|
|
28733
|
-
|
|
28734
28799
|
if (_TypeValidator["default"].isEmpty(value) && isOptional) {
|
|
28735
28800
|
return new FieldResult(name, data[name], undefined, isProhibited, isRequired, isOptional);
|
|
28736
28801
|
}
|
|
@@ -28759,12 +28824,25 @@ function requireValidator () {
|
|
|
28759
28824
|
if (!(0, _helpers.isObject)(dirtyData)) throw new Error('No data to validate.');
|
|
28760
28825
|
var properties = schema.properties;
|
|
28761
28826
|
var fields = Object.entries(properties);
|
|
28762
|
-
var result = new ValidationResult();
|
|
28827
|
+
var result = new ValidationResult(); // populate default values
|
|
28828
|
+
|
|
28829
|
+
var populatedData = _objectSpread({}, dirtyData);
|
|
28763
28830
|
|
|
28764
28831
|
for (var i = 0; i < fields.length; i++) {
|
|
28765
28832
|
var field = fields[i];
|
|
28766
28833
|
var name = field[0];
|
|
28767
|
-
|
|
28834
|
+
var type = field[1].type;
|
|
28835
|
+
var defaultVal = field[1]["default"];
|
|
28836
|
+
|
|
28837
|
+
if (populatedData[name] === undefined && defaultVal !== undefined) {
|
|
28838
|
+
populatedData[name] = this.castType(name, type, defaultVal);
|
|
28839
|
+
}
|
|
28840
|
+
}
|
|
28841
|
+
|
|
28842
|
+
for (var _i = 0; _i < fields.length; _i++) {
|
|
28843
|
+
var _field = fields[_i];
|
|
28844
|
+
var _name = _field[0];
|
|
28845
|
+
result.add(this.validateField(_name, properties, populatedData));
|
|
28768
28846
|
}
|
|
28769
28847
|
|
|
28770
28848
|
return result;
|
package/dist/index.esm.js
CHANGED
|
@@ -20473,90 +20473,149 @@ function requireCompiler () {
|
|
|
20473
20473
|
return compileTypeDefinition;
|
|
20474
20474
|
}()
|
|
20475
20475
|
}, {
|
|
20476
|
-
key: "
|
|
20476
|
+
key: "compileOptions",
|
|
20477
20477
|
value: function () {
|
|
20478
|
-
var
|
|
20479
|
-
var
|
|
20478
|
+
var _compileOptions = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(options) {
|
|
20479
|
+
var res;
|
|
20480
20480
|
return _regenerator["default"].wrap(function _callee9$(_context9) {
|
|
20481
20481
|
while (1) {
|
|
20482
20482
|
switch (_context9.prev = _context9.next) {
|
|
20483
|
+
case 0:
|
|
20484
|
+
if (!((0, _helpers.isObject)(options) && options.$ref !== undefined)) {
|
|
20485
|
+
_context9.next = 7;
|
|
20486
|
+
break;
|
|
20487
|
+
}
|
|
20488
|
+
|
|
20489
|
+
_context9.next = 3;
|
|
20490
|
+
return this.resolveRef(options.$ref);
|
|
20491
|
+
|
|
20492
|
+
case 3:
|
|
20493
|
+
res = _context9.sent;
|
|
20494
|
+
|
|
20495
|
+
if (!(0, _helpers.isObject)(res)) {
|
|
20496
|
+
_context9.next = 6;
|
|
20497
|
+
break;
|
|
20498
|
+
}
|
|
20499
|
+
|
|
20500
|
+
return _context9.abrupt("return", Object.keys(res));
|
|
20501
|
+
|
|
20502
|
+
case 6:
|
|
20503
|
+
return _context9.abrupt("return", res);
|
|
20504
|
+
|
|
20505
|
+
case 7:
|
|
20506
|
+
return _context9.abrupt("return", options);
|
|
20507
|
+
|
|
20508
|
+
case 8:
|
|
20509
|
+
case "end":
|
|
20510
|
+
return _context9.stop();
|
|
20511
|
+
}
|
|
20512
|
+
}
|
|
20513
|
+
}, _callee9, this);
|
|
20514
|
+
}));
|
|
20515
|
+
|
|
20516
|
+
function compileOptions(_x12) {
|
|
20517
|
+
return _compileOptions.apply(this, arguments);
|
|
20518
|
+
}
|
|
20519
|
+
|
|
20520
|
+
return compileOptions;
|
|
20521
|
+
}()
|
|
20522
|
+
}, {
|
|
20523
|
+
key: "compileField",
|
|
20524
|
+
value: function () {
|
|
20525
|
+
var _compileField = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(uncompiledField, name) {
|
|
20526
|
+
var field, prohibited, required, optional, type, defaultDef, options;
|
|
20527
|
+
return _regenerator["default"].wrap(function _callee10$(_context10) {
|
|
20528
|
+
while (1) {
|
|
20529
|
+
switch (_context10.prev = _context10.next) {
|
|
20483
20530
|
case 0:
|
|
20484
20531
|
field = (0, _helpers.deepCopy)(uncompiledField);
|
|
20485
|
-
prohibited = field.prohibited, required = field.required, optional = field.optional, type = field.type, defaultDef = field["default"];
|
|
20532
|
+
prohibited = field.prohibited, required = field.required, optional = field.optional, type = field.type, defaultDef = field["default"], options = field.options;
|
|
20486
20533
|
|
|
20487
20534
|
if (!(type === undefined)) {
|
|
20488
|
-
|
|
20535
|
+
_context10.next = 4;
|
|
20489
20536
|
break;
|
|
20490
20537
|
}
|
|
20491
20538
|
|
|
20492
20539
|
throw new _Error.SchemaError("Field \"".concat(name, "\" is missing a type definition"));
|
|
20493
20540
|
|
|
20494
20541
|
case 4:
|
|
20495
|
-
|
|
20542
|
+
_context10.next = 6;
|
|
20496
20543
|
return this.compileTypeDefinition(type, name);
|
|
20497
20544
|
|
|
20498
20545
|
case 6:
|
|
20499
|
-
field.type =
|
|
20546
|
+
field.type = _context10.sent;
|
|
20500
20547
|
|
|
20501
20548
|
if (!(defaultDef !== undefined)) {
|
|
20502
|
-
|
|
20549
|
+
_context10.next = 11;
|
|
20503
20550
|
break;
|
|
20504
20551
|
}
|
|
20505
20552
|
|
|
20506
|
-
|
|
20553
|
+
_context10.next = 10;
|
|
20507
20554
|
return this.compileTypeDefinition(defaultDef, name);
|
|
20508
20555
|
|
|
20509
20556
|
case 10:
|
|
20510
|
-
field["default"] =
|
|
20557
|
+
field["default"] = _context10.sent;
|
|
20511
20558
|
|
|
20512
20559
|
case 11:
|
|
20513
|
-
if (!
|
|
20514
|
-
|
|
20560
|
+
if (!options) {
|
|
20561
|
+
_context10.next = 15;
|
|
20515
20562
|
break;
|
|
20516
20563
|
}
|
|
20517
20564
|
|
|
20518
|
-
|
|
20519
|
-
return this.
|
|
20565
|
+
_context10.next = 14;
|
|
20566
|
+
return this.compileOptions(options);
|
|
20520
20567
|
|
|
20521
20568
|
case 14:
|
|
20522
|
-
field.
|
|
20569
|
+
field.options = _context10.sent;
|
|
20523
20570
|
|
|
20524
20571
|
case 15:
|
|
20525
|
-
if (!(
|
|
20526
|
-
|
|
20572
|
+
if (!(prohibited !== undefined)) {
|
|
20573
|
+
_context10.next = 19;
|
|
20527
20574
|
break;
|
|
20528
20575
|
}
|
|
20529
20576
|
|
|
20530
|
-
|
|
20531
|
-
return this.compileRules(
|
|
20577
|
+
_context10.next = 18;
|
|
20578
|
+
return this.compileRules(prohibited, name);
|
|
20532
20579
|
|
|
20533
20580
|
case 18:
|
|
20534
|
-
field.
|
|
20581
|
+
field.prohibited = _context10.sent;
|
|
20535
20582
|
|
|
20536
20583
|
case 19:
|
|
20537
|
-
if (!(
|
|
20538
|
-
|
|
20584
|
+
if (!(required !== undefined)) {
|
|
20585
|
+
_context10.next = 23;
|
|
20539
20586
|
break;
|
|
20540
20587
|
}
|
|
20541
20588
|
|
|
20542
|
-
|
|
20543
|
-
return this.compileRules(
|
|
20589
|
+
_context10.next = 22;
|
|
20590
|
+
return this.compileRules(required, name);
|
|
20544
20591
|
|
|
20545
20592
|
case 22:
|
|
20546
|
-
field.
|
|
20593
|
+
field.required = _context10.sent;
|
|
20547
20594
|
|
|
20548
20595
|
case 23:
|
|
20549
|
-
|
|
20596
|
+
if (!(optional !== undefined)) {
|
|
20597
|
+
_context10.next = 27;
|
|
20598
|
+
break;
|
|
20599
|
+
}
|
|
20600
|
+
|
|
20601
|
+
_context10.next = 26;
|
|
20602
|
+
return this.compileRules(optional, name);
|
|
20550
20603
|
|
|
20551
|
-
case
|
|
20604
|
+
case 26:
|
|
20605
|
+
field.optional = _context10.sent;
|
|
20606
|
+
|
|
20607
|
+
case 27:
|
|
20608
|
+
return _context10.abrupt("return", field);
|
|
20609
|
+
|
|
20610
|
+
case 28:
|
|
20552
20611
|
case "end":
|
|
20553
|
-
return
|
|
20612
|
+
return _context10.stop();
|
|
20554
20613
|
}
|
|
20555
20614
|
}
|
|
20556
|
-
},
|
|
20615
|
+
}, _callee10, this);
|
|
20557
20616
|
}));
|
|
20558
20617
|
|
|
20559
|
-
function compileField(
|
|
20618
|
+
function compileField(_x13, _x14) {
|
|
20560
20619
|
return _compileField.apply(this, arguments);
|
|
20561
20620
|
}
|
|
20562
20621
|
|
|
@@ -20565,135 +20624,135 @@ function requireCompiler () {
|
|
|
20565
20624
|
}, {
|
|
20566
20625
|
key: "compileCatalog",
|
|
20567
20626
|
value: function () {
|
|
20568
|
-
var _compileCatalog = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
20627
|
+
var _compileCatalog = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13(uncompiledCatalog) {
|
|
20569
20628
|
var _this2 = this;
|
|
20570
20629
|
|
|
20571
20630
|
var catalog, result;
|
|
20572
|
-
return _regenerator["default"].wrap(function
|
|
20631
|
+
return _regenerator["default"].wrap(function _callee13$(_context13) {
|
|
20573
20632
|
while (1) {
|
|
20574
|
-
switch (
|
|
20633
|
+
switch (_context13.prev = _context13.next) {
|
|
20575
20634
|
case 0:
|
|
20576
20635
|
catalog = (0, _helpers.deepCopy)(uncompiledCatalog);
|
|
20577
20636
|
|
|
20578
20637
|
if ((0, _helpers.isObject)(catalog)) {
|
|
20579
|
-
|
|
20638
|
+
_context13.next = 3;
|
|
20580
20639
|
break;
|
|
20581
20640
|
}
|
|
20582
20641
|
|
|
20583
20642
|
throw new _Error.SchemaError("Invalid type of \"".concat((0, _typeof2["default"])(catalog), "\" for catalog."));
|
|
20584
20643
|
|
|
20585
20644
|
case 3:
|
|
20586
|
-
|
|
20645
|
+
_context13.next = 5;
|
|
20587
20646
|
return Promise.all(Object.entries(catalog).map( /*#__PURE__*/function () {
|
|
20588
|
-
var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
20589
|
-
return _regenerator["default"].wrap(function
|
|
20647
|
+
var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(e) {
|
|
20648
|
+
return _regenerator["default"].wrap(function _callee12$(_context12) {
|
|
20590
20649
|
while (1) {
|
|
20591
|
-
switch (
|
|
20650
|
+
switch (_context12.prev = _context12.next) {
|
|
20592
20651
|
case 0:
|
|
20593
20652
|
if (!(0, _helpers.isObject)(e[1])) {
|
|
20594
|
-
|
|
20653
|
+
_context12.next = 2;
|
|
20595
20654
|
break;
|
|
20596
20655
|
}
|
|
20597
20656
|
|
|
20598
|
-
return
|
|
20657
|
+
return _context12.abrupt("return", (0, _defineProperty2["default"])({}, e[0], e[1]));
|
|
20599
20658
|
|
|
20600
20659
|
case 2:
|
|
20601
20660
|
if (Array.isArray(e[1])) {
|
|
20602
|
-
|
|
20661
|
+
_context12.next = 4;
|
|
20603
20662
|
break;
|
|
20604
20663
|
}
|
|
20605
20664
|
|
|
20606
20665
|
throw new _Error.SchemaError("Invalid type of \"".concat((0, _typeof2["default"])(e[1]), "\" for catalog at path \"").concat(e[0], "\"."));
|
|
20607
20666
|
|
|
20608
20667
|
case 4:
|
|
20609
|
-
|
|
20610
|
-
|
|
20611
|
-
|
|
20612
|
-
|
|
20668
|
+
_context12.t0 = _defineProperty2["default"];
|
|
20669
|
+
_context12.t1 = {};
|
|
20670
|
+
_context12.t2 = e[0];
|
|
20671
|
+
_context12.next = 9;
|
|
20613
20672
|
return Promise.all(e[1].map( /*#__PURE__*/function () {
|
|
20614
|
-
var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
20673
|
+
var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(ee) {
|
|
20615
20674
|
var res;
|
|
20616
|
-
return _regenerator["default"].wrap(function
|
|
20675
|
+
return _regenerator["default"].wrap(function _callee11$(_context11) {
|
|
20617
20676
|
while (1) {
|
|
20618
|
-
switch (
|
|
20677
|
+
switch (_context11.prev = _context11.next) {
|
|
20619
20678
|
case 0:
|
|
20620
20679
|
if ((0, _helpers.isObject)(ee)) {
|
|
20621
|
-
|
|
20680
|
+
_context11.next = 2;
|
|
20622
20681
|
break;
|
|
20623
20682
|
}
|
|
20624
20683
|
|
|
20625
|
-
return
|
|
20684
|
+
return _context11.abrupt("return", ee);
|
|
20626
20685
|
|
|
20627
20686
|
case 2:
|
|
20628
20687
|
if (!(ee.$ref === undefined)) {
|
|
20629
|
-
|
|
20688
|
+
_context11.next = 4;
|
|
20630
20689
|
break;
|
|
20631
20690
|
}
|
|
20632
20691
|
|
|
20633
20692
|
throw new _Error.SchemaError("Objects inside a catalog Array need to define a $ref at path \"".concat(e[0], "\"."));
|
|
20634
20693
|
|
|
20635
20694
|
case 4:
|
|
20636
|
-
|
|
20695
|
+
_context11.next = 6;
|
|
20637
20696
|
return _this2.resolveRef(ee.$ref);
|
|
20638
20697
|
|
|
20639
20698
|
case 6:
|
|
20640
|
-
res =
|
|
20699
|
+
res = _context11.sent;
|
|
20641
20700
|
|
|
20642
20701
|
if (!(0, _helpers.isObject)(res)) {
|
|
20643
|
-
|
|
20702
|
+
_context11.next = 9;
|
|
20644
20703
|
break;
|
|
20645
20704
|
}
|
|
20646
20705
|
|
|
20647
|
-
return
|
|
20706
|
+
return _context11.abrupt("return", Object.keys(res));
|
|
20648
20707
|
|
|
20649
20708
|
case 9:
|
|
20650
|
-
return
|
|
20709
|
+
return _context11.abrupt("return", res);
|
|
20651
20710
|
|
|
20652
20711
|
case 10:
|
|
20653
20712
|
case "end":
|
|
20654
|
-
return
|
|
20713
|
+
return _context11.stop();
|
|
20655
20714
|
}
|
|
20656
20715
|
}
|
|
20657
|
-
},
|
|
20716
|
+
}, _callee11);
|
|
20658
20717
|
}));
|
|
20659
20718
|
|
|
20660
|
-
return function (
|
|
20719
|
+
return function (_x17) {
|
|
20661
20720
|
return _ref8.apply(this, arguments);
|
|
20662
20721
|
};
|
|
20663
20722
|
}()));
|
|
20664
20723
|
|
|
20665
20724
|
case 9:
|
|
20666
|
-
|
|
20667
|
-
return
|
|
20725
|
+
_context12.t3 = _context12.sent;
|
|
20726
|
+
return _context12.abrupt("return", (0, _context12.t0)(_context12.t1, _context12.t2, _context12.t3));
|
|
20668
20727
|
|
|
20669
20728
|
case 11:
|
|
20670
20729
|
case "end":
|
|
20671
|
-
return
|
|
20730
|
+
return _context12.stop();
|
|
20672
20731
|
}
|
|
20673
20732
|
}
|
|
20674
|
-
},
|
|
20733
|
+
}, _callee12);
|
|
20675
20734
|
}));
|
|
20676
20735
|
|
|
20677
|
-
return function (
|
|
20736
|
+
return function (_x16) {
|
|
20678
20737
|
return _ref6.apply(this, arguments);
|
|
20679
20738
|
};
|
|
20680
20739
|
}()));
|
|
20681
20740
|
|
|
20682
20741
|
case 5:
|
|
20683
|
-
result =
|
|
20684
|
-
return
|
|
20742
|
+
result = _context13.sent;
|
|
20743
|
+
return _context13.abrupt("return", result.reduce(function (l, r) {
|
|
20685
20744
|
return _objectSpread(_objectSpread({}, l), r);
|
|
20686
20745
|
}, {}));
|
|
20687
20746
|
|
|
20688
20747
|
case 7:
|
|
20689
20748
|
case "end":
|
|
20690
|
-
return
|
|
20749
|
+
return _context13.stop();
|
|
20691
20750
|
}
|
|
20692
20751
|
}
|
|
20693
|
-
},
|
|
20752
|
+
}, _callee13);
|
|
20694
20753
|
}));
|
|
20695
20754
|
|
|
20696
|
-
function compileCatalog(
|
|
20755
|
+
function compileCatalog(_x15) {
|
|
20697
20756
|
return _compileCatalog.apply(this, arguments);
|
|
20698
20757
|
}
|
|
20699
20758
|
|
|
@@ -20702,16 +20761,16 @@ function requireCompiler () {
|
|
|
20702
20761
|
}, {
|
|
20703
20762
|
key: "process",
|
|
20704
20763
|
value: function () {
|
|
20705
|
-
var _process = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
20764
|
+
var _process = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(schemaArg, resolver) {
|
|
20706
20765
|
var schema, catalog, properties, fieldNames, i, name, field;
|
|
20707
|
-
return _regenerator["default"].wrap(function
|
|
20766
|
+
return _regenerator["default"].wrap(function _callee14$(_context14) {
|
|
20708
20767
|
while (1) {
|
|
20709
|
-
switch (
|
|
20768
|
+
switch (_context14.prev = _context14.next) {
|
|
20710
20769
|
case 0:
|
|
20711
20770
|
this.resolver = resolver;
|
|
20712
20771
|
|
|
20713
20772
|
if ((0, _helpers.isObject)(schemaArg)) {
|
|
20714
|
-
|
|
20773
|
+
_context14.next = 3;
|
|
20715
20774
|
break;
|
|
20716
20775
|
}
|
|
20717
20776
|
|
|
@@ -20724,15 +20783,15 @@ function requireCompiler () {
|
|
|
20724
20783
|
catalog = schema.catalog, properties = schema.properties;
|
|
20725
20784
|
|
|
20726
20785
|
if (!(catalog !== undefined)) {
|
|
20727
|
-
|
|
20786
|
+
_context14.next = 11;
|
|
20728
20787
|
break;
|
|
20729
20788
|
}
|
|
20730
20789
|
|
|
20731
|
-
|
|
20790
|
+
_context14.next = 10;
|
|
20732
20791
|
return this.compileCatalog(catalog);
|
|
20733
20792
|
|
|
20734
20793
|
case 10:
|
|
20735
|
-
schema.catalog =
|
|
20794
|
+
schema.catalog = _context14.sent;
|
|
20736
20795
|
|
|
20737
20796
|
case 11:
|
|
20738
20797
|
fieldNames = Object.keys(properties);
|
|
@@ -20740,35 +20799,35 @@ function requireCompiler () {
|
|
|
20740
20799
|
|
|
20741
20800
|
case 13:
|
|
20742
20801
|
if (!(i < fieldNames.length)) {
|
|
20743
|
-
|
|
20802
|
+
_context14.next = 22;
|
|
20744
20803
|
break;
|
|
20745
20804
|
}
|
|
20746
20805
|
|
|
20747
20806
|
name = fieldNames[i];
|
|
20748
20807
|
field = properties[name];
|
|
20749
|
-
|
|
20808
|
+
_context14.next = 18;
|
|
20750
20809
|
return this.compileField(field, name);
|
|
20751
20810
|
|
|
20752
20811
|
case 18:
|
|
20753
|
-
properties[name] =
|
|
20812
|
+
properties[name] = _context14.sent;
|
|
20754
20813
|
|
|
20755
20814
|
case 19:
|
|
20756
20815
|
i++;
|
|
20757
|
-
|
|
20816
|
+
_context14.next = 13;
|
|
20758
20817
|
break;
|
|
20759
20818
|
|
|
20760
20819
|
case 22:
|
|
20761
|
-
return
|
|
20820
|
+
return _context14.abrupt("return", schema);
|
|
20762
20821
|
|
|
20763
20822
|
case 23:
|
|
20764
20823
|
case "end":
|
|
20765
|
-
return
|
|
20824
|
+
return _context14.stop();
|
|
20766
20825
|
}
|
|
20767
20826
|
}
|
|
20768
|
-
},
|
|
20827
|
+
}, _callee14, this);
|
|
20769
20828
|
}));
|
|
20770
20829
|
|
|
20771
|
-
function process(
|
|
20830
|
+
function process(_x18, _x19) {
|
|
20772
20831
|
return _process.apply(this, arguments);
|
|
20773
20832
|
}
|
|
20774
20833
|
|
|
@@ -28481,6 +28540,11 @@ function requireTypeValidator () {
|
|
|
28481
28540
|
return value === String(other[as]);
|
|
28482
28541
|
};
|
|
28483
28542
|
|
|
28543
|
+
_validator["default"].isZipCode = function (value, _ref3, other) {
|
|
28544
|
+
var localeFrom = _ref3.localeFrom;
|
|
28545
|
+
return _validator["default"].isPostalCode(value, String(other[localeFrom]) || 'any');
|
|
28546
|
+
};
|
|
28547
|
+
|
|
28484
28548
|
var _default = _validator["default"];
|
|
28485
28549
|
exports["default"] = _default;
|
|
28486
28550
|
} (TypeValidator));
|
|
@@ -28501,6 +28565,8 @@ function requireValidator () {
|
|
|
28501
28565
|
});
|
|
28502
28566
|
exports["default"] = void 0;
|
|
28503
28567
|
|
|
28568
|
+
var _defineProperty2 = _interopRequireDefault(requireDefineProperty());
|
|
28569
|
+
|
|
28504
28570
|
var _typeof2 = _interopRequireDefault(require_typeof());
|
|
28505
28571
|
|
|
28506
28572
|
var _classCallCheck2 = _interopRequireDefault(requireClassCallCheck());
|
|
@@ -28513,6 +28579,10 @@ function requireValidator () {
|
|
|
28513
28579
|
|
|
28514
28580
|
var _Error = require_Error();
|
|
28515
28581
|
|
|
28582
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
28583
|
+
|
|
28584
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
28585
|
+
|
|
28516
28586
|
var ValidationResult = /*#__PURE__*/function () {
|
|
28517
28587
|
function ValidationResult() {
|
|
28518
28588
|
(0, _classCallCheck2["default"])(this, ValidationResult);
|
|
@@ -28664,8 +28734,7 @@ function requireValidator () {
|
|
|
28664
28734
|
prohibited = _schema$name.prohibited,
|
|
28665
28735
|
required = _schema$name.required,
|
|
28666
28736
|
optional = _schema$name.optional,
|
|
28667
|
-
type = _schema$name.type
|
|
28668
|
-
defaultVal = _schema$name["default"];
|
|
28737
|
+
type = _schema$name.type;
|
|
28669
28738
|
var value = data[name];
|
|
28670
28739
|
var hasProhibited = prohibited !== undefined;
|
|
28671
28740
|
var hasRequired = required !== undefined;
|
|
@@ -28676,7 +28745,7 @@ function requireValidator () {
|
|
|
28676
28745
|
var isRequired = hasRequired && this.validateRules(name, required, data);
|
|
28677
28746
|
if (!isRequired && !isProhibited && optional === true) isOptional = true;
|
|
28678
28747
|
|
|
28679
|
-
if (isRequired &&
|
|
28748
|
+
if (isRequired && _TypeValidator["default"].isEmpty(value)) {
|
|
28680
28749
|
return new FieldResult(name, data[name], undefined, isProhibited, isRequired, isOptional, true, [{
|
|
28681
28750
|
message: "\"".concat(name, "\" is required"),
|
|
28682
28751
|
path: name,
|
|
@@ -28687,10 +28756,6 @@ function requireValidator () {
|
|
|
28687
28756
|
|
|
28688
28757
|
if (!isOptional && !isRequired) return new FieldResult(name, data[name], undefined, isProhibited, isRequired, isOptional);
|
|
28689
28758
|
|
|
28690
|
-
if (_TypeValidator["default"].isEmpty(value) && defaultVal !== undefined) {
|
|
28691
|
-
return new FieldResult(name, data[name], this.castType(name, type, defaultVal), isProhibited, isRequired, isOptional);
|
|
28692
|
-
}
|
|
28693
|
-
|
|
28694
28759
|
if (_TypeValidator["default"].isEmpty(value) && isOptional) {
|
|
28695
28760
|
return new FieldResult(name, data[name], undefined, isProhibited, isRequired, isOptional);
|
|
28696
28761
|
}
|
|
@@ -28719,12 +28784,25 @@ function requireValidator () {
|
|
|
28719
28784
|
if (!(0, _helpers.isObject)(dirtyData)) throw new Error('No data to validate.');
|
|
28720
28785
|
var properties = schema.properties;
|
|
28721
28786
|
var fields = Object.entries(properties);
|
|
28722
|
-
var result = new ValidationResult();
|
|
28787
|
+
var result = new ValidationResult(); // populate default values
|
|
28788
|
+
|
|
28789
|
+
var populatedData = _objectSpread({}, dirtyData);
|
|
28723
28790
|
|
|
28724
28791
|
for (var i = 0; i < fields.length; i++) {
|
|
28725
28792
|
var field = fields[i];
|
|
28726
28793
|
var name = field[0];
|
|
28727
|
-
|
|
28794
|
+
var type = field[1].type;
|
|
28795
|
+
var defaultVal = field[1]["default"];
|
|
28796
|
+
|
|
28797
|
+
if (populatedData[name] === undefined && defaultVal !== undefined) {
|
|
28798
|
+
populatedData[name] = this.castType(name, type, defaultVal);
|
|
28799
|
+
}
|
|
28800
|
+
}
|
|
28801
|
+
|
|
28802
|
+
for (var _i = 0; _i < fields.length; _i++) {
|
|
28803
|
+
var _field = fields[_i];
|
|
28804
|
+
var _name = _field[0];
|
|
28805
|
+
result.add(this.validateField(_name, properties, populatedData));
|
|
28728
28806
|
}
|
|
28729
28807
|
|
|
28730
28808
|
return result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scenid/react-formulator",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"module": "dist/index.esm.js",
|
|
6
6
|
"repository": "https://dennykoch@bitbucket.org/scenid/react-formulator.git",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@rollup/plugin-commonjs": "^22.0.0",
|
|
50
50
|
"@rollup/plugin-node-resolve": "^13.2.1",
|
|
51
51
|
"@scenid/cloud-icons": "^2.6.0",
|
|
52
|
-
"@scenid/formulator": "^2.3.
|
|
52
|
+
"@scenid/formulator": "^2.3.2",
|
|
53
53
|
"@storybook/addon-actions": "^6.4.22",
|
|
54
54
|
"@storybook/addon-essentials": "^6.4.22",
|
|
55
55
|
"@storybook/addon-interactions": "^6.4.22",
|