@remoteoss/json-schema-form 0.6.4-beta.0 → 0.6.5-beta.0
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/CHANGELOG.md +6 -0
- package/dist/index.cjs +474 -373
- package/dist/index.js +474 -373
- package/dist/standalone.js +1388 -1287
- package/package.json +1 -1
- package/src/tests/checkIfConditionMatches.test.js +6 -6
- package/src/tests/jsonLogic.fixtures.js +405 -1
- package/src/tests/jsonLogic.test.js +201 -42
package/dist/standalone.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.6.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.6.5-beta.0
|
|
5
|
+
Generated: Mon, 18 Sep 2023 10:09:01 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -5648,6 +5648,384 @@ var require_isEmpty = __commonJS({
|
|
|
5648
5648
|
}
|
|
5649
5649
|
});
|
|
5650
5650
|
|
|
5651
|
+
// node_modules/json-logic-js/logic.js
|
|
5652
|
+
var require_logic = __commonJS({
|
|
5653
|
+
"node_modules/json-logic-js/logic.js"(exports2, module2) {
|
|
5654
|
+
(function(root2, factory) {
|
|
5655
|
+
if (typeof define === "function" && define.amd) {
|
|
5656
|
+
define(factory);
|
|
5657
|
+
} else if (typeof exports2 === "object") {
|
|
5658
|
+
module2.exports = factory();
|
|
5659
|
+
} else {
|
|
5660
|
+
root2.jsonLogic = factory();
|
|
5661
|
+
}
|
|
5662
|
+
})(exports2, function() {
|
|
5663
|
+
"use strict";
|
|
5664
|
+
if (!Array.isArray) {
|
|
5665
|
+
Array.isArray = function(arg) {
|
|
5666
|
+
return Object.prototype.toString.call(arg) === "[object Array]";
|
|
5667
|
+
};
|
|
5668
|
+
}
|
|
5669
|
+
function arrayUnique(array2) {
|
|
5670
|
+
var a = [];
|
|
5671
|
+
for (var i = 0, l = array2.length; i < l; i++) {
|
|
5672
|
+
if (a.indexOf(array2[i]) === -1) {
|
|
5673
|
+
a.push(array2[i]);
|
|
5674
|
+
}
|
|
5675
|
+
}
|
|
5676
|
+
return a;
|
|
5677
|
+
}
|
|
5678
|
+
var jsonLogic2 = {};
|
|
5679
|
+
var operations = {
|
|
5680
|
+
"==": function(a, b) {
|
|
5681
|
+
return a == b;
|
|
5682
|
+
},
|
|
5683
|
+
"===": function(a, b) {
|
|
5684
|
+
return a === b;
|
|
5685
|
+
},
|
|
5686
|
+
"!=": function(a, b) {
|
|
5687
|
+
return a != b;
|
|
5688
|
+
},
|
|
5689
|
+
"!==": function(a, b) {
|
|
5690
|
+
return a !== b;
|
|
5691
|
+
},
|
|
5692
|
+
">": function(a, b) {
|
|
5693
|
+
return a > b;
|
|
5694
|
+
},
|
|
5695
|
+
">=": function(a, b) {
|
|
5696
|
+
return a >= b;
|
|
5697
|
+
},
|
|
5698
|
+
"<": function(a, b, c) {
|
|
5699
|
+
return c === void 0 ? a < b : a < b && b < c;
|
|
5700
|
+
},
|
|
5701
|
+
"<=": function(a, b, c) {
|
|
5702
|
+
return c === void 0 ? a <= b : a <= b && b <= c;
|
|
5703
|
+
},
|
|
5704
|
+
"!!": function(a) {
|
|
5705
|
+
return jsonLogic2.truthy(a);
|
|
5706
|
+
},
|
|
5707
|
+
"!": function(a) {
|
|
5708
|
+
return !jsonLogic2.truthy(a);
|
|
5709
|
+
},
|
|
5710
|
+
"%": function(a, b) {
|
|
5711
|
+
return a % b;
|
|
5712
|
+
},
|
|
5713
|
+
"log": function(a) {
|
|
5714
|
+
console.log(a);
|
|
5715
|
+
return a;
|
|
5716
|
+
},
|
|
5717
|
+
"in": function(a, b) {
|
|
5718
|
+
if (!b || typeof b.indexOf === "undefined")
|
|
5719
|
+
return false;
|
|
5720
|
+
return b.indexOf(a) !== -1;
|
|
5721
|
+
},
|
|
5722
|
+
"cat": function() {
|
|
5723
|
+
return Array.prototype.join.call(arguments, "");
|
|
5724
|
+
},
|
|
5725
|
+
"substr": function(source, start, end) {
|
|
5726
|
+
if (end < 0) {
|
|
5727
|
+
var temp = String(source).substr(start);
|
|
5728
|
+
return temp.substr(0, temp.length + end);
|
|
5729
|
+
}
|
|
5730
|
+
return String(source).substr(start, end);
|
|
5731
|
+
},
|
|
5732
|
+
"+": function() {
|
|
5733
|
+
return Array.prototype.reduce.call(arguments, function(a, b) {
|
|
5734
|
+
return parseFloat(a, 10) + parseFloat(b, 10);
|
|
5735
|
+
}, 0);
|
|
5736
|
+
},
|
|
5737
|
+
"*": function() {
|
|
5738
|
+
return Array.prototype.reduce.call(arguments, function(a, b) {
|
|
5739
|
+
return parseFloat(a, 10) * parseFloat(b, 10);
|
|
5740
|
+
});
|
|
5741
|
+
},
|
|
5742
|
+
"-": function(a, b) {
|
|
5743
|
+
if (b === void 0) {
|
|
5744
|
+
return -a;
|
|
5745
|
+
} else {
|
|
5746
|
+
return a - b;
|
|
5747
|
+
}
|
|
5748
|
+
},
|
|
5749
|
+
"/": function(a, b) {
|
|
5750
|
+
return a / b;
|
|
5751
|
+
},
|
|
5752
|
+
"min": function() {
|
|
5753
|
+
return Math.min.apply(this, arguments);
|
|
5754
|
+
},
|
|
5755
|
+
"max": function() {
|
|
5756
|
+
return Math.max.apply(this, arguments);
|
|
5757
|
+
},
|
|
5758
|
+
"merge": function() {
|
|
5759
|
+
return Array.prototype.reduce.call(arguments, function(a, b) {
|
|
5760
|
+
return a.concat(b);
|
|
5761
|
+
}, []);
|
|
5762
|
+
},
|
|
5763
|
+
"var": function(a, b) {
|
|
5764
|
+
var not_found = b === void 0 ? null : b;
|
|
5765
|
+
var data = this;
|
|
5766
|
+
if (typeof a === "undefined" || a === "" || a === null) {
|
|
5767
|
+
return data;
|
|
5768
|
+
}
|
|
5769
|
+
var sub_props = String(a).split(".");
|
|
5770
|
+
for (var i = 0; i < sub_props.length; i++) {
|
|
5771
|
+
if (data === null || data === void 0) {
|
|
5772
|
+
return not_found;
|
|
5773
|
+
}
|
|
5774
|
+
data = data[sub_props[i]];
|
|
5775
|
+
if (data === void 0) {
|
|
5776
|
+
return not_found;
|
|
5777
|
+
}
|
|
5778
|
+
}
|
|
5779
|
+
return data;
|
|
5780
|
+
},
|
|
5781
|
+
"missing": function() {
|
|
5782
|
+
var missing = [];
|
|
5783
|
+
var keys2 = Array.isArray(arguments[0]) ? arguments[0] : arguments;
|
|
5784
|
+
for (var i = 0; i < keys2.length; i++) {
|
|
5785
|
+
var key = keys2[i];
|
|
5786
|
+
var value = jsonLogic2.apply({ "var": key }, this);
|
|
5787
|
+
if (value === null || value === "") {
|
|
5788
|
+
missing.push(key);
|
|
5789
|
+
}
|
|
5790
|
+
}
|
|
5791
|
+
return missing;
|
|
5792
|
+
},
|
|
5793
|
+
"missing_some": function(need_count, options) {
|
|
5794
|
+
var are_missing = jsonLogic2.apply({ "missing": options }, this);
|
|
5795
|
+
if (options.length - are_missing.length >= need_count) {
|
|
5796
|
+
return [];
|
|
5797
|
+
} else {
|
|
5798
|
+
return are_missing;
|
|
5799
|
+
}
|
|
5800
|
+
}
|
|
5801
|
+
};
|
|
5802
|
+
jsonLogic2.is_logic = function(logic) {
|
|
5803
|
+
return typeof logic === "object" && // An object
|
|
5804
|
+
logic !== null && // but not null
|
|
5805
|
+
!Array.isArray(logic) && // and not an array
|
|
5806
|
+
Object.keys(logic).length === 1;
|
|
5807
|
+
};
|
|
5808
|
+
jsonLogic2.truthy = function(value) {
|
|
5809
|
+
if (Array.isArray(value) && value.length === 0) {
|
|
5810
|
+
return false;
|
|
5811
|
+
}
|
|
5812
|
+
return !!value;
|
|
5813
|
+
};
|
|
5814
|
+
jsonLogic2.get_operator = function(logic) {
|
|
5815
|
+
return Object.keys(logic)[0];
|
|
5816
|
+
};
|
|
5817
|
+
jsonLogic2.get_values = function(logic) {
|
|
5818
|
+
return logic[jsonLogic2.get_operator(logic)];
|
|
5819
|
+
};
|
|
5820
|
+
jsonLogic2.apply = function(logic, data) {
|
|
5821
|
+
if (Array.isArray(logic)) {
|
|
5822
|
+
return logic.map(function(l) {
|
|
5823
|
+
return jsonLogic2.apply(l, data);
|
|
5824
|
+
});
|
|
5825
|
+
}
|
|
5826
|
+
if (!jsonLogic2.is_logic(logic)) {
|
|
5827
|
+
return logic;
|
|
5828
|
+
}
|
|
5829
|
+
var op = jsonLogic2.get_operator(logic);
|
|
5830
|
+
var values2 = logic[op];
|
|
5831
|
+
var i;
|
|
5832
|
+
var current;
|
|
5833
|
+
var scopedLogic;
|
|
5834
|
+
var scopedData;
|
|
5835
|
+
var initial;
|
|
5836
|
+
if (!Array.isArray(values2)) {
|
|
5837
|
+
values2 = [values2];
|
|
5838
|
+
}
|
|
5839
|
+
if (op === "if" || op == "?:") {
|
|
5840
|
+
for (i = 0; i < values2.length - 1; i += 2) {
|
|
5841
|
+
if (jsonLogic2.truthy(jsonLogic2.apply(values2[i], data))) {
|
|
5842
|
+
return jsonLogic2.apply(values2[i + 1], data);
|
|
5843
|
+
}
|
|
5844
|
+
}
|
|
5845
|
+
if (values2.length === i + 1) {
|
|
5846
|
+
return jsonLogic2.apply(values2[i], data);
|
|
5847
|
+
}
|
|
5848
|
+
return null;
|
|
5849
|
+
} else if (op === "and") {
|
|
5850
|
+
for (i = 0; i < values2.length; i += 1) {
|
|
5851
|
+
current = jsonLogic2.apply(values2[i], data);
|
|
5852
|
+
if (!jsonLogic2.truthy(current)) {
|
|
5853
|
+
return current;
|
|
5854
|
+
}
|
|
5855
|
+
}
|
|
5856
|
+
return current;
|
|
5857
|
+
} else if (op === "or") {
|
|
5858
|
+
for (i = 0; i < values2.length; i += 1) {
|
|
5859
|
+
current = jsonLogic2.apply(values2[i], data);
|
|
5860
|
+
if (jsonLogic2.truthy(current)) {
|
|
5861
|
+
return current;
|
|
5862
|
+
}
|
|
5863
|
+
}
|
|
5864
|
+
return current;
|
|
5865
|
+
} else if (op === "filter") {
|
|
5866
|
+
scopedData = jsonLogic2.apply(values2[0], data);
|
|
5867
|
+
scopedLogic = values2[1];
|
|
5868
|
+
if (!Array.isArray(scopedData)) {
|
|
5869
|
+
return [];
|
|
5870
|
+
}
|
|
5871
|
+
return scopedData.filter(function(datum) {
|
|
5872
|
+
return jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, datum));
|
|
5873
|
+
});
|
|
5874
|
+
} else if (op === "map") {
|
|
5875
|
+
scopedData = jsonLogic2.apply(values2[0], data);
|
|
5876
|
+
scopedLogic = values2[1];
|
|
5877
|
+
if (!Array.isArray(scopedData)) {
|
|
5878
|
+
return [];
|
|
5879
|
+
}
|
|
5880
|
+
return scopedData.map(function(datum) {
|
|
5881
|
+
return jsonLogic2.apply(scopedLogic, datum);
|
|
5882
|
+
});
|
|
5883
|
+
} else if (op === "reduce") {
|
|
5884
|
+
scopedData = jsonLogic2.apply(values2[0], data);
|
|
5885
|
+
scopedLogic = values2[1];
|
|
5886
|
+
initial = typeof values2[2] !== "undefined" ? values2[2] : null;
|
|
5887
|
+
if (!Array.isArray(scopedData)) {
|
|
5888
|
+
return initial;
|
|
5889
|
+
}
|
|
5890
|
+
return scopedData.reduce(
|
|
5891
|
+
function(accumulator, current2) {
|
|
5892
|
+
return jsonLogic2.apply(
|
|
5893
|
+
scopedLogic,
|
|
5894
|
+
{ current: current2, accumulator }
|
|
5895
|
+
);
|
|
5896
|
+
},
|
|
5897
|
+
initial
|
|
5898
|
+
);
|
|
5899
|
+
} else if (op === "all") {
|
|
5900
|
+
scopedData = jsonLogic2.apply(values2[0], data);
|
|
5901
|
+
scopedLogic = values2[1];
|
|
5902
|
+
if (!Array.isArray(scopedData) || !scopedData.length) {
|
|
5903
|
+
return false;
|
|
5904
|
+
}
|
|
5905
|
+
for (i = 0; i < scopedData.length; i += 1) {
|
|
5906
|
+
if (!jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, scopedData[i]))) {
|
|
5907
|
+
return false;
|
|
5908
|
+
}
|
|
5909
|
+
}
|
|
5910
|
+
return true;
|
|
5911
|
+
} else if (op === "none") {
|
|
5912
|
+
scopedData = jsonLogic2.apply(values2[0], data);
|
|
5913
|
+
scopedLogic = values2[1];
|
|
5914
|
+
if (!Array.isArray(scopedData) || !scopedData.length) {
|
|
5915
|
+
return true;
|
|
5916
|
+
}
|
|
5917
|
+
for (i = 0; i < scopedData.length; i += 1) {
|
|
5918
|
+
if (jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, scopedData[i]))) {
|
|
5919
|
+
return false;
|
|
5920
|
+
}
|
|
5921
|
+
}
|
|
5922
|
+
return true;
|
|
5923
|
+
} else if (op === "some") {
|
|
5924
|
+
scopedData = jsonLogic2.apply(values2[0], data);
|
|
5925
|
+
scopedLogic = values2[1];
|
|
5926
|
+
if (!Array.isArray(scopedData) || !scopedData.length) {
|
|
5927
|
+
return false;
|
|
5928
|
+
}
|
|
5929
|
+
for (i = 0; i < scopedData.length; i += 1) {
|
|
5930
|
+
if (jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, scopedData[i]))) {
|
|
5931
|
+
return true;
|
|
5932
|
+
}
|
|
5933
|
+
}
|
|
5934
|
+
return false;
|
|
5935
|
+
}
|
|
5936
|
+
values2 = values2.map(function(val) {
|
|
5937
|
+
return jsonLogic2.apply(val, data);
|
|
5938
|
+
});
|
|
5939
|
+
if (operations.hasOwnProperty(op) && typeof operations[op] === "function") {
|
|
5940
|
+
return operations[op].apply(data, values2);
|
|
5941
|
+
} else if (op.indexOf(".") > 0) {
|
|
5942
|
+
var sub_ops = String(op).split(".");
|
|
5943
|
+
var operation = operations;
|
|
5944
|
+
for (i = 0; i < sub_ops.length; i++) {
|
|
5945
|
+
if (!operation.hasOwnProperty(sub_ops[i])) {
|
|
5946
|
+
throw new Error("Unrecognized operation " + op + " (failed at " + sub_ops.slice(0, i + 1).join(".") + ")");
|
|
5947
|
+
}
|
|
5948
|
+
operation = operation[sub_ops[i]];
|
|
5949
|
+
}
|
|
5950
|
+
return operation.apply(data, values2);
|
|
5951
|
+
}
|
|
5952
|
+
throw new Error("Unrecognized operation " + op);
|
|
5953
|
+
};
|
|
5954
|
+
jsonLogic2.uses_data = function(logic) {
|
|
5955
|
+
var collection = [];
|
|
5956
|
+
if (jsonLogic2.is_logic(logic)) {
|
|
5957
|
+
var op = jsonLogic2.get_operator(logic);
|
|
5958
|
+
var values2 = logic[op];
|
|
5959
|
+
if (!Array.isArray(values2)) {
|
|
5960
|
+
values2 = [values2];
|
|
5961
|
+
}
|
|
5962
|
+
if (op === "var") {
|
|
5963
|
+
collection.push(values2[0]);
|
|
5964
|
+
} else {
|
|
5965
|
+
values2.forEach(function(val) {
|
|
5966
|
+
collection.push.apply(collection, jsonLogic2.uses_data(val));
|
|
5967
|
+
});
|
|
5968
|
+
}
|
|
5969
|
+
}
|
|
5970
|
+
return arrayUnique(collection);
|
|
5971
|
+
};
|
|
5972
|
+
jsonLogic2.add_operation = function(name, code) {
|
|
5973
|
+
operations[name] = code;
|
|
5974
|
+
};
|
|
5975
|
+
jsonLogic2.rm_operation = function(name) {
|
|
5976
|
+
delete operations[name];
|
|
5977
|
+
};
|
|
5978
|
+
jsonLogic2.rule_like = function(rule, pattern) {
|
|
5979
|
+
if (pattern === rule) {
|
|
5980
|
+
return true;
|
|
5981
|
+
}
|
|
5982
|
+
if (pattern === "@") {
|
|
5983
|
+
return true;
|
|
5984
|
+
}
|
|
5985
|
+
if (pattern === "number") {
|
|
5986
|
+
return typeof rule === "number";
|
|
5987
|
+
}
|
|
5988
|
+
if (pattern === "string") {
|
|
5989
|
+
return typeof rule === "string";
|
|
5990
|
+
}
|
|
5991
|
+
if (pattern === "array") {
|
|
5992
|
+
return Array.isArray(rule) && !jsonLogic2.is_logic(rule);
|
|
5993
|
+
}
|
|
5994
|
+
if (jsonLogic2.is_logic(pattern)) {
|
|
5995
|
+
if (jsonLogic2.is_logic(rule)) {
|
|
5996
|
+
var pattern_op = jsonLogic2.get_operator(pattern);
|
|
5997
|
+
var rule_op = jsonLogic2.get_operator(rule);
|
|
5998
|
+
if (pattern_op === "@" || pattern_op === rule_op) {
|
|
5999
|
+
return jsonLogic2.rule_like(
|
|
6000
|
+
jsonLogic2.get_values(rule, false),
|
|
6001
|
+
jsonLogic2.get_values(pattern, false)
|
|
6002
|
+
);
|
|
6003
|
+
}
|
|
6004
|
+
}
|
|
6005
|
+
return false;
|
|
6006
|
+
}
|
|
6007
|
+
if (Array.isArray(pattern)) {
|
|
6008
|
+
if (Array.isArray(rule)) {
|
|
6009
|
+
if (pattern.length !== rule.length) {
|
|
6010
|
+
return false;
|
|
6011
|
+
}
|
|
6012
|
+
for (var i = 0; i < pattern.length; i += 1) {
|
|
6013
|
+
if (!jsonLogic2.rule_like(rule[i], pattern[i])) {
|
|
6014
|
+
return false;
|
|
6015
|
+
}
|
|
6016
|
+
}
|
|
6017
|
+
return true;
|
|
6018
|
+
} else {
|
|
6019
|
+
return false;
|
|
6020
|
+
}
|
|
6021
|
+
}
|
|
6022
|
+
return false;
|
|
6023
|
+
};
|
|
6024
|
+
return jsonLogic2;
|
|
6025
|
+
});
|
|
6026
|
+
}
|
|
6027
|
+
});
|
|
6028
|
+
|
|
5651
6029
|
// node_modules/lodash/_createFlow.js
|
|
5652
6030
|
var require_createFlow = __commonJS({
|
|
5653
6031
|
"node_modules/lodash/_createFlow.js"(exports2, module2) {
|
|
@@ -6229,573 +6607,195 @@ var require_randexp = __commonJS({
|
|
|
6229
6607
|
} else {
|
|
6230
6608
|
throw new Error("Expected a regexp or string");
|
|
6231
6609
|
}
|
|
6232
|
-
this.tokens = ret(regexp);
|
|
6233
|
-
}
|
|
6234
|
-
/**
|
|
6235
|
-
* Checks if some custom properties have been set for this regexp.
|
|
6236
|
-
*
|
|
6237
|
-
* @param {RandExp} randexp
|
|
6238
|
-
* @param {RegExp} regexp
|
|
6239
|
-
*/
|
|
6240
|
-
_setDefaults(regexp) {
|
|
6241
|
-
this.max = regexp.max != null ? regexp.max : RandExp.prototype.max != null ? RandExp.prototype.max : 100;
|
|
6242
|
-
this.defaultRange = regexp.defaultRange ? regexp.defaultRange : this.defaultRange.clone();
|
|
6243
|
-
if (regexp.randInt) {
|
|
6244
|
-
this.randInt = regexp.randInt;
|
|
6245
|
-
}
|
|
6246
|
-
}
|
|
6247
|
-
/**
|
|
6248
|
-
* Generates the random string.
|
|
6249
|
-
*
|
|
6250
|
-
* @return {String}
|
|
6251
|
-
*/
|
|
6252
|
-
gen() {
|
|
6253
|
-
return this._gen(this.tokens, []);
|
|
6254
|
-
}
|
|
6255
|
-
/**
|
|
6256
|
-
* Generate random string modeled after given tokens.
|
|
6257
|
-
*
|
|
6258
|
-
* @param {Object} token
|
|
6259
|
-
* @param {Array.<String>} groups
|
|
6260
|
-
* @return {String}
|
|
6261
|
-
*/
|
|
6262
|
-
_gen(token, groups) {
|
|
6263
|
-
var stack, str, n, i, l;
|
|
6264
|
-
switch (token.type) {
|
|
6265
|
-
case types.ROOT:
|
|
6266
|
-
case types.GROUP:
|
|
6267
|
-
if (token.followedBy || token.notFollowedBy) {
|
|
6268
|
-
return "";
|
|
6269
|
-
}
|
|
6270
|
-
if (token.remember && token.groupNumber === void 0) {
|
|
6271
|
-
token.groupNumber = groups.push(null) - 1;
|
|
6272
|
-
}
|
|
6273
|
-
stack = token.options ? this._randSelect(token.options) : token.stack;
|
|
6274
|
-
str = "";
|
|
6275
|
-
for (i = 0, l = stack.length; i < l; i++) {
|
|
6276
|
-
str += this._gen(stack[i], groups);
|
|
6277
|
-
}
|
|
6278
|
-
if (token.remember) {
|
|
6279
|
-
groups[token.groupNumber] = str;
|
|
6280
|
-
}
|
|
6281
|
-
return str;
|
|
6282
|
-
case types.POSITION:
|
|
6283
|
-
return "";
|
|
6284
|
-
case types.SET:
|
|
6285
|
-
var expandedSet = this._expand(token);
|
|
6286
|
-
if (!expandedSet.length) {
|
|
6287
|
-
return "";
|
|
6288
|
-
}
|
|
6289
|
-
return String.fromCharCode(this._randSelect(expandedSet));
|
|
6290
|
-
case types.REPETITION:
|
|
6291
|
-
n = this.randInt(
|
|
6292
|
-
token.min,
|
|
6293
|
-
token.max === Infinity ? token.min + this.max : token.max
|
|
6294
|
-
);
|
|
6295
|
-
str = "";
|
|
6296
|
-
for (i = 0; i < n; i++) {
|
|
6297
|
-
str += this._gen(token.value, groups);
|
|
6298
|
-
}
|
|
6299
|
-
return str;
|
|
6300
|
-
case types.REFERENCE:
|
|
6301
|
-
return groups[token.value - 1] || "";
|
|
6302
|
-
case types.CHAR:
|
|
6303
|
-
var code = this.ignoreCase && this._randBool() ? this._toOtherCase(token.value) : token.value;
|
|
6304
|
-
return String.fromCharCode(code);
|
|
6305
|
-
}
|
|
6306
|
-
}
|
|
6307
|
-
/**
|
|
6308
|
-
* If code is alphabetic, converts to other case.
|
|
6309
|
-
* If not alphabetic, returns back code.
|
|
6310
|
-
*
|
|
6311
|
-
* @param {Number} code
|
|
6312
|
-
* @return {Number}
|
|
6313
|
-
*/
|
|
6314
|
-
_toOtherCase(code) {
|
|
6315
|
-
return code + (97 <= code && code <= 122 ? -32 : 65 <= code && code <= 90 ? 32 : 0);
|
|
6316
|
-
}
|
|
6317
|
-
/**
|
|
6318
|
-
* Randomly returns a true or false value.
|
|
6319
|
-
*
|
|
6320
|
-
* @return {Boolean}
|
|
6321
|
-
*/
|
|
6322
|
-
_randBool() {
|
|
6323
|
-
return !this.randInt(0, 1);
|
|
6324
|
-
}
|
|
6325
|
-
/**
|
|
6326
|
-
* Randomly selects and returns a value from the array.
|
|
6327
|
-
*
|
|
6328
|
-
* @param {Array.<Object>} arr
|
|
6329
|
-
* @return {Object}
|
|
6330
|
-
*/
|
|
6331
|
-
_randSelect(arr) {
|
|
6332
|
-
if (arr instanceof DRange) {
|
|
6333
|
-
return arr.index(this.randInt(0, arr.length - 1));
|
|
6334
|
-
}
|
|
6335
|
-
return arr[this.randInt(0, arr.length - 1)];
|
|
6336
|
-
}
|
|
6337
|
-
/**
|
|
6338
|
-
* expands a token to a DiscontinuousRange of characters which has a
|
|
6339
|
-
* length and an index function (for random selecting)
|
|
6340
|
-
*
|
|
6341
|
-
* @param {Object} token
|
|
6342
|
-
* @return {DiscontinuousRange}
|
|
6343
|
-
*/
|
|
6344
|
-
_expand(token) {
|
|
6345
|
-
if (token.type === ret.types.CHAR) {
|
|
6346
|
-
return new DRange(token.value);
|
|
6347
|
-
} else if (token.type === ret.types.RANGE) {
|
|
6348
|
-
return new DRange(token.from, token.to);
|
|
6349
|
-
} else {
|
|
6350
|
-
let drange = new DRange();
|
|
6351
|
-
for (let i = 0; i < token.set.length; i++) {
|
|
6352
|
-
let subrange = this._expand(token.set[i]);
|
|
6353
|
-
drange.add(subrange);
|
|
6354
|
-
if (this.ignoreCase) {
|
|
6355
|
-
for (let j = 0; j < subrange.length; j++) {
|
|
6356
|
-
let code = subrange.index(j);
|
|
6357
|
-
let otherCaseCode = this._toOtherCase(code);
|
|
6358
|
-
if (code !== otherCaseCode) {
|
|
6359
|
-
drange.add(otherCaseCode);
|
|
6360
|
-
}
|
|
6361
|
-
}
|
|
6362
|
-
}
|
|
6363
|
-
}
|
|
6364
|
-
if (token.not) {
|
|
6365
|
-
return this.defaultRange.clone().subtract(drange);
|
|
6366
|
-
} else {
|
|
6367
|
-
return this.defaultRange.clone().intersect(drange);
|
|
6368
|
-
}
|
|
6369
|
-
}
|
|
6370
|
-
}
|
|
6371
|
-
/**
|
|
6372
|
-
* Randomly generates and returns a number between a and b (inclusive).
|
|
6373
|
-
*
|
|
6374
|
-
* @param {Number} a
|
|
6375
|
-
* @param {Number} b
|
|
6376
|
-
* @return {Number}
|
|
6377
|
-
*/
|
|
6378
|
-
randInt(a, b) {
|
|
6379
|
-
return a + Math.floor(Math.random() * (1 + b - a));
|
|
6610
|
+
this.tokens = ret(regexp);
|
|
6380
6611
|
}
|
|
6381
6612
|
/**
|
|
6382
|
-
*
|
|
6613
|
+
* Checks if some custom properties have been set for this regexp.
|
|
6614
|
+
*
|
|
6615
|
+
* @param {RandExp} randexp
|
|
6616
|
+
* @param {RegExp} regexp
|
|
6383
6617
|
*/
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6618
|
+
_setDefaults(regexp) {
|
|
6619
|
+
this.max = regexp.max != null ? regexp.max : RandExp.prototype.max != null ? RandExp.prototype.max : 100;
|
|
6620
|
+
this.defaultRange = regexp.defaultRange ? regexp.defaultRange : this.defaultRange.clone();
|
|
6621
|
+
if (regexp.randInt) {
|
|
6622
|
+
this.randInt = regexp.randInt;
|
|
6623
|
+
}
|
|
6389
6624
|
}
|
|
6390
6625
|
/**
|
|
6626
|
+
* Generates the random string.
|
|
6391
6627
|
*
|
|
6392
|
-
* Enables use of randexp with a shorter call.
|
|
6393
|
-
*
|
|
6394
|
-
* @param {RegExp|String| regexp}
|
|
6395
|
-
* @param {String} m
|
|
6396
6628
|
* @return {String}
|
|
6397
6629
|
*/
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
if (typeof regexp === "string") {
|
|
6401
|
-
regexp = new RegExp(regexp, m);
|
|
6402
|
-
}
|
|
6403
|
-
if (regexp._randexp === void 0) {
|
|
6404
|
-
randexp2 = new RandExp(regexp, m);
|
|
6405
|
-
regexp._randexp = randexp2;
|
|
6406
|
-
} else {
|
|
6407
|
-
randexp2 = regexp._randexp;
|
|
6408
|
-
randexp2._setDefaults(regexp);
|
|
6409
|
-
}
|
|
6410
|
-
return randexp2.gen();
|
|
6630
|
+
gen() {
|
|
6631
|
+
return this._gen(this.tokens, []);
|
|
6411
6632
|
}
|
|
6412
6633
|
/**
|
|
6413
|
-
*
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
"node_modules/json-logic-js/logic.js"(exports2, module2) {
|
|
6427
|
-
(function(root2, factory) {
|
|
6428
|
-
if (typeof define === "function" && define.amd) {
|
|
6429
|
-
define(factory);
|
|
6430
|
-
} else if (typeof exports2 === "object") {
|
|
6431
|
-
module2.exports = factory();
|
|
6432
|
-
} else {
|
|
6433
|
-
root2.jsonLogic = factory();
|
|
6434
|
-
}
|
|
6435
|
-
})(exports2, function() {
|
|
6436
|
-
"use strict";
|
|
6437
|
-
if (!Array.isArray) {
|
|
6438
|
-
Array.isArray = function(arg) {
|
|
6439
|
-
return Object.prototype.toString.call(arg) === "[object Array]";
|
|
6440
|
-
};
|
|
6441
|
-
}
|
|
6442
|
-
function arrayUnique(array2) {
|
|
6443
|
-
var a = [];
|
|
6444
|
-
for (var i = 0, l = array2.length; i < l; i++) {
|
|
6445
|
-
if (a.indexOf(array2[i]) === -1) {
|
|
6446
|
-
a.push(array2[i]);
|
|
6447
|
-
}
|
|
6448
|
-
}
|
|
6449
|
-
return a;
|
|
6450
|
-
}
|
|
6451
|
-
var jsonLogic2 = {};
|
|
6452
|
-
var operations = {
|
|
6453
|
-
"==": function(a, b) {
|
|
6454
|
-
return a == b;
|
|
6455
|
-
},
|
|
6456
|
-
"===": function(a, b) {
|
|
6457
|
-
return a === b;
|
|
6458
|
-
},
|
|
6459
|
-
"!=": function(a, b) {
|
|
6460
|
-
return a != b;
|
|
6461
|
-
},
|
|
6462
|
-
"!==": function(a, b) {
|
|
6463
|
-
return a !== b;
|
|
6464
|
-
},
|
|
6465
|
-
">": function(a, b) {
|
|
6466
|
-
return a > b;
|
|
6467
|
-
},
|
|
6468
|
-
">=": function(a, b) {
|
|
6469
|
-
return a >= b;
|
|
6470
|
-
},
|
|
6471
|
-
"<": function(a, b, c) {
|
|
6472
|
-
return c === void 0 ? a < b : a < b && b < c;
|
|
6473
|
-
},
|
|
6474
|
-
"<=": function(a, b, c) {
|
|
6475
|
-
return c === void 0 ? a <= b : a <= b && b <= c;
|
|
6476
|
-
},
|
|
6477
|
-
"!!": function(a) {
|
|
6478
|
-
return jsonLogic2.truthy(a);
|
|
6479
|
-
},
|
|
6480
|
-
"!": function(a) {
|
|
6481
|
-
return !jsonLogic2.truthy(a);
|
|
6482
|
-
},
|
|
6483
|
-
"%": function(a, b) {
|
|
6484
|
-
return a % b;
|
|
6485
|
-
},
|
|
6486
|
-
"log": function(a) {
|
|
6487
|
-
console.log(a);
|
|
6488
|
-
return a;
|
|
6489
|
-
},
|
|
6490
|
-
"in": function(a, b) {
|
|
6491
|
-
if (!b || typeof b.indexOf === "undefined")
|
|
6492
|
-
return false;
|
|
6493
|
-
return b.indexOf(a) !== -1;
|
|
6494
|
-
},
|
|
6495
|
-
"cat": function() {
|
|
6496
|
-
return Array.prototype.join.call(arguments, "");
|
|
6497
|
-
},
|
|
6498
|
-
"substr": function(source, start, end) {
|
|
6499
|
-
if (end < 0) {
|
|
6500
|
-
var temp = String(source).substr(start);
|
|
6501
|
-
return temp.substr(0, temp.length + end);
|
|
6502
|
-
}
|
|
6503
|
-
return String(source).substr(start, end);
|
|
6504
|
-
},
|
|
6505
|
-
"+": function() {
|
|
6506
|
-
return Array.prototype.reduce.call(arguments, function(a, b) {
|
|
6507
|
-
return parseFloat(a, 10) + parseFloat(b, 10);
|
|
6508
|
-
}, 0);
|
|
6509
|
-
},
|
|
6510
|
-
"*": function() {
|
|
6511
|
-
return Array.prototype.reduce.call(arguments, function(a, b) {
|
|
6512
|
-
return parseFloat(a, 10) * parseFloat(b, 10);
|
|
6513
|
-
});
|
|
6514
|
-
},
|
|
6515
|
-
"-": function(a, b) {
|
|
6516
|
-
if (b === void 0) {
|
|
6517
|
-
return -a;
|
|
6518
|
-
} else {
|
|
6519
|
-
return a - b;
|
|
6520
|
-
}
|
|
6521
|
-
},
|
|
6522
|
-
"/": function(a, b) {
|
|
6523
|
-
return a / b;
|
|
6524
|
-
},
|
|
6525
|
-
"min": function() {
|
|
6526
|
-
return Math.min.apply(this, arguments);
|
|
6527
|
-
},
|
|
6528
|
-
"max": function() {
|
|
6529
|
-
return Math.max.apply(this, arguments);
|
|
6530
|
-
},
|
|
6531
|
-
"merge": function() {
|
|
6532
|
-
return Array.prototype.reduce.call(arguments, function(a, b) {
|
|
6533
|
-
return a.concat(b);
|
|
6534
|
-
}, []);
|
|
6535
|
-
},
|
|
6536
|
-
"var": function(a, b) {
|
|
6537
|
-
var not_found = b === void 0 ? null : b;
|
|
6538
|
-
var data = this;
|
|
6539
|
-
if (typeof a === "undefined" || a === "" || a === null) {
|
|
6540
|
-
return data;
|
|
6541
|
-
}
|
|
6542
|
-
var sub_props = String(a).split(".");
|
|
6543
|
-
for (var i = 0; i < sub_props.length; i++) {
|
|
6544
|
-
if (data === null || data === void 0) {
|
|
6545
|
-
return not_found;
|
|
6546
|
-
}
|
|
6547
|
-
data = data[sub_props[i]];
|
|
6548
|
-
if (data === void 0) {
|
|
6549
|
-
return not_found;
|
|
6550
|
-
}
|
|
6551
|
-
}
|
|
6552
|
-
return data;
|
|
6553
|
-
},
|
|
6554
|
-
"missing": function() {
|
|
6555
|
-
var missing = [];
|
|
6556
|
-
var keys2 = Array.isArray(arguments[0]) ? arguments[0] : arguments;
|
|
6557
|
-
for (var i = 0; i < keys2.length; i++) {
|
|
6558
|
-
var key = keys2[i];
|
|
6559
|
-
var value = jsonLogic2.apply({ "var": key }, this);
|
|
6560
|
-
if (value === null || value === "") {
|
|
6561
|
-
missing.push(key);
|
|
6562
|
-
}
|
|
6563
|
-
}
|
|
6564
|
-
return missing;
|
|
6565
|
-
},
|
|
6566
|
-
"missing_some": function(need_count, options) {
|
|
6567
|
-
var are_missing = jsonLogic2.apply({ "missing": options }, this);
|
|
6568
|
-
if (options.length - are_missing.length >= need_count) {
|
|
6569
|
-
return [];
|
|
6570
|
-
} else {
|
|
6571
|
-
return are_missing;
|
|
6572
|
-
}
|
|
6573
|
-
}
|
|
6574
|
-
};
|
|
6575
|
-
jsonLogic2.is_logic = function(logic) {
|
|
6576
|
-
return typeof logic === "object" && // An object
|
|
6577
|
-
logic !== null && // but not null
|
|
6578
|
-
!Array.isArray(logic) && // and not an array
|
|
6579
|
-
Object.keys(logic).length === 1;
|
|
6580
|
-
};
|
|
6581
|
-
jsonLogic2.truthy = function(value) {
|
|
6582
|
-
if (Array.isArray(value) && value.length === 0) {
|
|
6583
|
-
return false;
|
|
6584
|
-
}
|
|
6585
|
-
return !!value;
|
|
6586
|
-
};
|
|
6587
|
-
jsonLogic2.get_operator = function(logic) {
|
|
6588
|
-
return Object.keys(logic)[0];
|
|
6589
|
-
};
|
|
6590
|
-
jsonLogic2.get_values = function(logic) {
|
|
6591
|
-
return logic[jsonLogic2.get_operator(logic)];
|
|
6592
|
-
};
|
|
6593
|
-
jsonLogic2.apply = function(logic, data) {
|
|
6594
|
-
if (Array.isArray(logic)) {
|
|
6595
|
-
return logic.map(function(l) {
|
|
6596
|
-
return jsonLogic2.apply(l, data);
|
|
6597
|
-
});
|
|
6598
|
-
}
|
|
6599
|
-
if (!jsonLogic2.is_logic(logic)) {
|
|
6600
|
-
return logic;
|
|
6601
|
-
}
|
|
6602
|
-
var op = jsonLogic2.get_operator(logic);
|
|
6603
|
-
var values2 = logic[op];
|
|
6604
|
-
var i;
|
|
6605
|
-
var current;
|
|
6606
|
-
var scopedLogic;
|
|
6607
|
-
var scopedData;
|
|
6608
|
-
var initial;
|
|
6609
|
-
if (!Array.isArray(values2)) {
|
|
6610
|
-
values2 = [values2];
|
|
6611
|
-
}
|
|
6612
|
-
if (op === "if" || op == "?:") {
|
|
6613
|
-
for (i = 0; i < values2.length - 1; i += 2) {
|
|
6614
|
-
if (jsonLogic2.truthy(jsonLogic2.apply(values2[i], data))) {
|
|
6615
|
-
return jsonLogic2.apply(values2[i + 1], data);
|
|
6616
|
-
}
|
|
6617
|
-
}
|
|
6618
|
-
if (values2.length === i + 1) {
|
|
6619
|
-
return jsonLogic2.apply(values2[i], data);
|
|
6620
|
-
}
|
|
6621
|
-
return null;
|
|
6622
|
-
} else if (op === "and") {
|
|
6623
|
-
for (i = 0; i < values2.length; i += 1) {
|
|
6624
|
-
current = jsonLogic2.apply(values2[i], data);
|
|
6625
|
-
if (!jsonLogic2.truthy(current)) {
|
|
6626
|
-
return current;
|
|
6634
|
+
* Generate random string modeled after given tokens.
|
|
6635
|
+
*
|
|
6636
|
+
* @param {Object} token
|
|
6637
|
+
* @param {Array.<String>} groups
|
|
6638
|
+
* @return {String}
|
|
6639
|
+
*/
|
|
6640
|
+
_gen(token, groups) {
|
|
6641
|
+
var stack, str, n, i, l;
|
|
6642
|
+
switch (token.type) {
|
|
6643
|
+
case types.ROOT:
|
|
6644
|
+
case types.GROUP:
|
|
6645
|
+
if (token.followedBy || token.notFollowedBy) {
|
|
6646
|
+
return "";
|
|
6627
6647
|
}
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
} else if (op === "or") {
|
|
6631
|
-
for (i = 0; i < values2.length; i += 1) {
|
|
6632
|
-
current = jsonLogic2.apply(values2[i], data);
|
|
6633
|
-
if (jsonLogic2.truthy(current)) {
|
|
6634
|
-
return current;
|
|
6648
|
+
if (token.remember && token.groupNumber === void 0) {
|
|
6649
|
+
token.groupNumber = groups.push(null) - 1;
|
|
6635
6650
|
}
|
|
6636
|
-
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
scopedLogic = values2[1];
|
|
6641
|
-
if (!Array.isArray(scopedData)) {
|
|
6642
|
-
return [];
|
|
6643
|
-
}
|
|
6644
|
-
return scopedData.filter(function(datum) {
|
|
6645
|
-
return jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, datum));
|
|
6646
|
-
});
|
|
6647
|
-
} else if (op === "map") {
|
|
6648
|
-
scopedData = jsonLogic2.apply(values2[0], data);
|
|
6649
|
-
scopedLogic = values2[1];
|
|
6650
|
-
if (!Array.isArray(scopedData)) {
|
|
6651
|
-
return [];
|
|
6652
|
-
}
|
|
6653
|
-
return scopedData.map(function(datum) {
|
|
6654
|
-
return jsonLogic2.apply(scopedLogic, datum);
|
|
6655
|
-
});
|
|
6656
|
-
} else if (op === "reduce") {
|
|
6657
|
-
scopedData = jsonLogic2.apply(values2[0], data);
|
|
6658
|
-
scopedLogic = values2[1];
|
|
6659
|
-
initial = typeof values2[2] !== "undefined" ? values2[2] : null;
|
|
6660
|
-
if (!Array.isArray(scopedData)) {
|
|
6661
|
-
return initial;
|
|
6662
|
-
}
|
|
6663
|
-
return scopedData.reduce(
|
|
6664
|
-
function(accumulator, current2) {
|
|
6665
|
-
return jsonLogic2.apply(
|
|
6666
|
-
scopedLogic,
|
|
6667
|
-
{ current: current2, accumulator }
|
|
6668
|
-
);
|
|
6669
|
-
},
|
|
6670
|
-
initial
|
|
6671
|
-
);
|
|
6672
|
-
} else if (op === "all") {
|
|
6673
|
-
scopedData = jsonLogic2.apply(values2[0], data);
|
|
6674
|
-
scopedLogic = values2[1];
|
|
6675
|
-
if (!Array.isArray(scopedData) || !scopedData.length) {
|
|
6676
|
-
return false;
|
|
6677
|
-
}
|
|
6678
|
-
for (i = 0; i < scopedData.length; i += 1) {
|
|
6679
|
-
if (!jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, scopedData[i]))) {
|
|
6680
|
-
return false;
|
|
6651
|
+
stack = token.options ? this._randSelect(token.options) : token.stack;
|
|
6652
|
+
str = "";
|
|
6653
|
+
for (i = 0, l = stack.length; i < l; i++) {
|
|
6654
|
+
str += this._gen(stack[i], groups);
|
|
6681
6655
|
}
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
} else if (op === "none") {
|
|
6685
|
-
scopedData = jsonLogic2.apply(values2[0], data);
|
|
6686
|
-
scopedLogic = values2[1];
|
|
6687
|
-
if (!Array.isArray(scopedData) || !scopedData.length) {
|
|
6688
|
-
return true;
|
|
6689
|
-
}
|
|
6690
|
-
for (i = 0; i < scopedData.length; i += 1) {
|
|
6691
|
-
if (jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, scopedData[i]))) {
|
|
6692
|
-
return false;
|
|
6656
|
+
if (token.remember) {
|
|
6657
|
+
groups[token.groupNumber] = str;
|
|
6693
6658
|
}
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
}
|
|
6702
|
-
for (i = 0; i < scopedData.length; i += 1) {
|
|
6703
|
-
if (jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, scopedData[i]))) {
|
|
6704
|
-
return true;
|
|
6659
|
+
return str;
|
|
6660
|
+
case types.POSITION:
|
|
6661
|
+
return "";
|
|
6662
|
+
case types.SET:
|
|
6663
|
+
var expandedSet = this._expand(token);
|
|
6664
|
+
if (!expandedSet.length) {
|
|
6665
|
+
return "";
|
|
6705
6666
|
}
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
var sub_ops = String(op).split(".");
|
|
6716
|
-
var operation = operations;
|
|
6717
|
-
for (i = 0; i < sub_ops.length; i++) {
|
|
6718
|
-
if (!operation.hasOwnProperty(sub_ops[i])) {
|
|
6719
|
-
throw new Error("Unrecognized operation " + op + " (failed at " + sub_ops.slice(0, i + 1).join(".") + ")");
|
|
6667
|
+
return String.fromCharCode(this._randSelect(expandedSet));
|
|
6668
|
+
case types.REPETITION:
|
|
6669
|
+
n = this.randInt(
|
|
6670
|
+
token.min,
|
|
6671
|
+
token.max === Infinity ? token.min + this.max : token.max
|
|
6672
|
+
);
|
|
6673
|
+
str = "";
|
|
6674
|
+
for (i = 0; i < n; i++) {
|
|
6675
|
+
str += this._gen(token.value, groups);
|
|
6720
6676
|
}
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6677
|
+
return str;
|
|
6678
|
+
case types.REFERENCE:
|
|
6679
|
+
return groups[token.value - 1] || "";
|
|
6680
|
+
case types.CHAR:
|
|
6681
|
+
var code = this.ignoreCase && this._randBool() ? this._toOtherCase(token.value) : token.value;
|
|
6682
|
+
return String.fromCharCode(code);
|
|
6724
6683
|
}
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6684
|
+
}
|
|
6685
|
+
/**
|
|
6686
|
+
* If code is alphabetic, converts to other case.
|
|
6687
|
+
* If not alphabetic, returns back code.
|
|
6688
|
+
*
|
|
6689
|
+
* @param {Number} code
|
|
6690
|
+
* @return {Number}
|
|
6691
|
+
*/
|
|
6692
|
+
_toOtherCase(code) {
|
|
6693
|
+
return code + (97 <= code && code <= 122 ? -32 : 65 <= code && code <= 90 ? 32 : 0);
|
|
6694
|
+
}
|
|
6695
|
+
/**
|
|
6696
|
+
* Randomly returns a true or false value.
|
|
6697
|
+
*
|
|
6698
|
+
* @return {Boolean}
|
|
6699
|
+
*/
|
|
6700
|
+
_randBool() {
|
|
6701
|
+
return !this.randInt(0, 1);
|
|
6702
|
+
}
|
|
6703
|
+
/**
|
|
6704
|
+
* Randomly selects and returns a value from the array.
|
|
6705
|
+
*
|
|
6706
|
+
* @param {Array.<Object>} arr
|
|
6707
|
+
* @return {Object}
|
|
6708
|
+
*/
|
|
6709
|
+
_randSelect(arr) {
|
|
6710
|
+
if (arr instanceof DRange) {
|
|
6711
|
+
return arr.index(this.randInt(0, arr.length - 1));
|
|
6712
|
+
}
|
|
6713
|
+
return arr[this.randInt(0, arr.length - 1)];
|
|
6714
|
+
}
|
|
6715
|
+
/**
|
|
6716
|
+
* expands a token to a DiscontinuousRange of characters which has a
|
|
6717
|
+
* length and an index function (for random selecting)
|
|
6718
|
+
*
|
|
6719
|
+
* @param {Object} token
|
|
6720
|
+
* @return {DiscontinuousRange}
|
|
6721
|
+
*/
|
|
6722
|
+
_expand(token) {
|
|
6723
|
+
if (token.type === ret.types.CHAR) {
|
|
6724
|
+
return new DRange(token.value);
|
|
6725
|
+
} else if (token.type === ret.types.RANGE) {
|
|
6726
|
+
return new DRange(token.from, token.to);
|
|
6727
|
+
} else {
|
|
6728
|
+
let drange = new DRange();
|
|
6729
|
+
for (let i = 0; i < token.set.length; i++) {
|
|
6730
|
+
let subrange = this._expand(token.set[i]);
|
|
6731
|
+
drange.add(subrange);
|
|
6732
|
+
if (this.ignoreCase) {
|
|
6733
|
+
for (let j = 0; j < subrange.length; j++) {
|
|
6734
|
+
let code = subrange.index(j);
|
|
6735
|
+
let otherCaseCode = this._toOtherCase(code);
|
|
6736
|
+
if (code !== otherCaseCode) {
|
|
6737
|
+
drange.add(otherCaseCode);
|
|
6738
|
+
}
|
|
6739
|
+
}
|
|
6740
|
+
}
|
|
6734
6741
|
}
|
|
6735
|
-
if (
|
|
6736
|
-
|
|
6742
|
+
if (token.not) {
|
|
6743
|
+
return this.defaultRange.clone().subtract(drange);
|
|
6737
6744
|
} else {
|
|
6738
|
-
|
|
6739
|
-
collection.push.apply(collection, jsonLogic2.uses_data(val));
|
|
6740
|
-
});
|
|
6745
|
+
return this.defaultRange.clone().intersect(drange);
|
|
6741
6746
|
}
|
|
6742
6747
|
}
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
);
|
|
6776
|
-
}
|
|
6777
|
-
}
|
|
6778
|
-
return false;
|
|
6748
|
+
}
|
|
6749
|
+
/**
|
|
6750
|
+
* Randomly generates and returns a number between a and b (inclusive).
|
|
6751
|
+
*
|
|
6752
|
+
* @param {Number} a
|
|
6753
|
+
* @param {Number} b
|
|
6754
|
+
* @return {Number}
|
|
6755
|
+
*/
|
|
6756
|
+
randInt(a, b) {
|
|
6757
|
+
return a + Math.floor(Math.random() * (1 + b - a));
|
|
6758
|
+
}
|
|
6759
|
+
/**
|
|
6760
|
+
* Default range of characters to generate from.
|
|
6761
|
+
*/
|
|
6762
|
+
get defaultRange() {
|
|
6763
|
+
return this._range = this._range || new DRange(32, 126);
|
|
6764
|
+
}
|
|
6765
|
+
set defaultRange(range) {
|
|
6766
|
+
this._range = range;
|
|
6767
|
+
}
|
|
6768
|
+
/**
|
|
6769
|
+
*
|
|
6770
|
+
* Enables use of randexp with a shorter call.
|
|
6771
|
+
*
|
|
6772
|
+
* @param {RegExp|String| regexp}
|
|
6773
|
+
* @param {String} m
|
|
6774
|
+
* @return {String}
|
|
6775
|
+
*/
|
|
6776
|
+
static randexp(regexp, m) {
|
|
6777
|
+
var randexp2;
|
|
6778
|
+
if (typeof regexp === "string") {
|
|
6779
|
+
regexp = new RegExp(regexp, m);
|
|
6779
6780
|
}
|
|
6780
|
-
if (
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
if (!jsonLogic2.rule_like(rule[i], pattern[i])) {
|
|
6787
|
-
return false;
|
|
6788
|
-
}
|
|
6789
|
-
}
|
|
6790
|
-
return true;
|
|
6791
|
-
} else {
|
|
6792
|
-
return false;
|
|
6793
|
-
}
|
|
6781
|
+
if (regexp._randexp === void 0) {
|
|
6782
|
+
randexp2 = new RandExp(regexp, m);
|
|
6783
|
+
regexp._randexp = randexp2;
|
|
6784
|
+
} else {
|
|
6785
|
+
randexp2 = regexp._randexp;
|
|
6786
|
+
randexp2._setDefaults(regexp);
|
|
6794
6787
|
}
|
|
6795
|
-
return
|
|
6796
|
-
}
|
|
6797
|
-
|
|
6798
|
-
|
|
6788
|
+
return randexp2.gen();
|
|
6789
|
+
}
|
|
6790
|
+
/**
|
|
6791
|
+
* Enables sugary /regexp/.gen syntax.
|
|
6792
|
+
*/
|
|
6793
|
+
static sugar() {
|
|
6794
|
+
RegExp.prototype.gen = function() {
|
|
6795
|
+
return RandExp.randexp(this);
|
|
6796
|
+
};
|
|
6797
|
+
}
|
|
6798
|
+
};
|
|
6799
6799
|
}
|
|
6800
6800
|
});
|
|
6801
6801
|
|
|
@@ -11315,670 +11315,441 @@ inherits(ArraySchema, SchemaType, {
|
|
|
11315
11315
|
exclusive: true,
|
|
11316
11316
|
params: {
|
|
11317
11317
|
min: _min
|
|
11318
|
-
},
|
|
11319
|
-
test: function test2(value) {
|
|
11320
|
-
return isAbsent_default(value) || value.length >= this.resolve(_min);
|
|
11321
|
-
}
|
|
11322
|
-
});
|
|
11323
|
-
},
|
|
11324
|
-
max: function max4(_max, message) {
|
|
11325
|
-
message = message || array.max;
|
|
11326
|
-
return this.test({
|
|
11327
|
-
message,
|
|
11328
|
-
name: "max",
|
|
11329
|
-
exclusive: true,
|
|
11330
|
-
params: {
|
|
11331
|
-
max: _max
|
|
11332
|
-
},
|
|
11333
|
-
test: function test2(value) {
|
|
11334
|
-
return isAbsent_default(value) || value.length <= this.resolve(_max);
|
|
11335
|
-
}
|
|
11336
|
-
});
|
|
11337
|
-
},
|
|
11338
|
-
ensure: function ensure2() {
|
|
11339
|
-
var _this4 = this;
|
|
11340
|
-
return this.default(function() {
|
|
11341
|
-
return [];
|
|
11342
|
-
}).transform(function(val, original) {
|
|
11343
|
-
if (_this4._typeCheck(val))
|
|
11344
|
-
return val;
|
|
11345
|
-
return original == null ? [] : [].concat(original);
|
|
11346
|
-
});
|
|
11347
|
-
},
|
|
11348
|
-
compact: function compact(rejector) {
|
|
11349
|
-
var reject = !rejector ? function(v) {
|
|
11350
|
-
return !!v;
|
|
11351
|
-
} : function(v, i, a) {
|
|
11352
|
-
return !rejector(v, i, a);
|
|
11353
|
-
};
|
|
11354
|
-
return this.transform(function(values2) {
|
|
11355
|
-
return values2 != null ? values2.filter(reject) : values2;
|
|
11356
|
-
});
|
|
11357
|
-
},
|
|
11358
|
-
describe: function describe3() {
|
|
11359
|
-
var base = SchemaType.prototype.describe.call(this);
|
|
11360
|
-
if (this.innerType)
|
|
11361
|
-
base.innerType = this.innerType.describe();
|
|
11362
|
-
return base;
|
|
11363
|
-
}
|
|
11364
|
-
});
|
|
11365
|
-
|
|
11366
|
-
// node_modules/yup/es/Lazy.js
|
|
11367
|
-
var Lazy = /* @__PURE__ */ function() {
|
|
11368
|
-
function Lazy2(mapFn) {
|
|
11369
|
-
this._resolve = function(value, options) {
|
|
11370
|
-
var schema = mapFn(value, options);
|
|
11371
|
-
if (!isSchema_default(schema))
|
|
11372
|
-
throw new TypeError("lazy() functions must return a valid schema");
|
|
11373
|
-
return schema.resolve(options);
|
|
11374
|
-
};
|
|
11375
|
-
}
|
|
11376
|
-
var _proto = Lazy2.prototype;
|
|
11377
|
-
_proto.resolve = function resolve2(options) {
|
|
11378
|
-
return this._resolve(options.value, options);
|
|
11379
|
-
};
|
|
11380
|
-
_proto.cast = function cast2(value, options) {
|
|
11381
|
-
return this._resolve(value, options).cast(value, options);
|
|
11382
|
-
};
|
|
11383
|
-
_proto.validate = function validate2(value, options, maybeCb) {
|
|
11384
|
-
return this._resolve(value, options).validate(value, options, maybeCb);
|
|
11385
|
-
};
|
|
11386
|
-
_proto.validateSync = function validateSync2(value, options) {
|
|
11387
|
-
return this._resolve(value, options).validateSync(value, options);
|
|
11388
|
-
};
|
|
11389
|
-
_proto.validateAt = function validateAt(path, value, options) {
|
|
11390
|
-
return this._resolve(value, options).validateAt(path, value, options);
|
|
11391
|
-
};
|
|
11392
|
-
_proto.validateSyncAt = function validateSyncAt(path, value, options) {
|
|
11393
|
-
return this._resolve(value, options).validateSyncAt(path, value, options);
|
|
11394
|
-
};
|
|
11395
|
-
return Lazy2;
|
|
11396
|
-
}();
|
|
11397
|
-
Lazy.prototype.__isYupSchema__ = true;
|
|
11398
|
-
var Lazy_default = Lazy;
|
|
11399
|
-
|
|
11400
|
-
// node_modules/yup/es/index.js
|
|
11401
|
-
var boolean2 = boolean_default;
|
|
11402
|
-
var lazy = function lazy2(fn) {
|
|
11403
|
-
return new Lazy_default(fn);
|
|
11404
|
-
};
|
|
11405
|
-
|
|
11406
|
-
// src/utils.js
|
|
11407
|
-
function convertDiskSizeFromTo(from2, to) {
|
|
11408
|
-
const units = ["bytes", "kb", "mb"];
|
|
11409
|
-
return function convert(value) {
|
|
11410
|
-
return value * Math.pow(1024, units.indexOf(from2.toLowerCase())) / Math.pow(1024, units.indexOf(to.toLowerCase()));
|
|
11411
|
-
};
|
|
11412
|
-
}
|
|
11413
|
-
function containsHTML(str = "") {
|
|
11414
|
-
return /<[a-z][\s\S]*>/i.test(str);
|
|
11415
|
-
}
|
|
11416
|
-
function wrapWithSpan(html, properties = {}) {
|
|
11417
|
-
const attributes = Object.entries(properties).reduce((acc, [key, value]) => `${acc}${key}="${value}" `, "").trim();
|
|
11418
|
-
return `<span ${attributes}>${html}</span>`;
|
|
11419
|
-
}
|
|
11420
|
-
function hasProperty(object2, propertyName) {
|
|
11421
|
-
return Object.prototype.hasOwnProperty.call(object2, propertyName);
|
|
11422
|
-
}
|
|
11423
|
-
|
|
11424
|
-
// src/checkIfConditionMatches.js
|
|
11425
|
-
function checkIfConditionMatches(node, formValues, formFields) {
|
|
11426
|
-
return Object.keys(node.if.properties).every((name) => {
|
|
11427
|
-
const currentProperty = node.if.properties[name];
|
|
11428
|
-
const value = formValues[name];
|
|
11429
|
-
const hasEmptyValue = typeof value === "undefined" || // NOTE: This is a "Remote API" dependency, as empty fields are sent as "null".
|
|
11430
|
-
value === null;
|
|
11431
|
-
const hasIfExplicit = node.if.required?.includes(name);
|
|
11432
|
-
if (hasEmptyValue && !hasIfExplicit) {
|
|
11433
|
-
return true;
|
|
11434
|
-
}
|
|
11435
|
-
if (hasProperty(currentProperty, "const")) {
|
|
11436
|
-
return compareFormValueWithSchemaValue(value, currentProperty.const);
|
|
11437
|
-
}
|
|
11438
|
-
if (currentProperty.contains?.pattern) {
|
|
11439
|
-
const formValue = value || [];
|
|
11440
|
-
if (Array.isArray(formValue)) {
|
|
11441
|
-
const pattern = new RegExp(currentProperty.contains.pattern);
|
|
11442
|
-
return (value || []).some((item) => pattern.test(item));
|
|
11443
|
-
}
|
|
11444
|
-
}
|
|
11445
|
-
if (currentProperty.enum) {
|
|
11446
|
-
return currentProperty.enum.includes(value);
|
|
11447
|
-
}
|
|
11448
|
-
if (currentProperty.properties) {
|
|
11449
|
-
return checkIfConditionMatches(
|
|
11450
|
-
{ if: currentProperty },
|
|
11451
|
-
formValues[name],
|
|
11452
|
-
getField(name, formFields).fields
|
|
11453
|
-
);
|
|
11454
|
-
}
|
|
11455
|
-
const field = getField(name, formFields);
|
|
11456
|
-
return validateFieldSchema(
|
|
11457
|
-
{
|
|
11458
|
-
options: field.options,
|
|
11459
|
-
// @TODO/CODE SMELL. We are passing the property (raw field), but buildYupSchema() expected the output field.
|
|
11460
|
-
...currentProperty,
|
|
11461
|
-
inputType: field.inputType,
|
|
11462
|
-
required: true
|
|
11463
|
-
},
|
|
11464
|
-
value
|
|
11465
|
-
);
|
|
11466
|
-
});
|
|
11467
|
-
}
|
|
11468
|
-
|
|
11469
|
-
// src/internals/helpers.js
|
|
11470
|
-
var import_merge = __toESM(require_merge2());
|
|
11471
|
-
var import_get2 = __toESM(require_get());
|
|
11472
|
-
var import_isEmpty = __toESM(require_isEmpty());
|
|
11473
|
-
var import_isFunction3 = __toESM(require_isFunction());
|
|
11474
|
-
function pickXKey(node, key) {
|
|
11475
|
-
const deprecatedKeys = ["presentation", "errorMessage"];
|
|
11476
|
-
return (0, import_get2.default)(node, `x-jsf-${key}`, deprecatedKeys.includes(key) ? node?.[key] : void 0);
|
|
11477
|
-
}
|
|
11478
|
-
function getFieldDescription(node, customProperties = {}) {
|
|
11479
|
-
const nodeDescription = node?.description ? {
|
|
11480
|
-
description: node.description
|
|
11481
|
-
} : {};
|
|
11482
|
-
const customDescription = customProperties?.description ? {
|
|
11483
|
-
description: (0, import_isFunction3.default)(customProperties.description) ? customProperties.description(node?.description, {
|
|
11484
|
-
...node,
|
|
11485
|
-
...customProperties
|
|
11486
|
-
}) : customProperties.description
|
|
11487
|
-
} : {};
|
|
11488
|
-
const nodePresentation = pickXKey(node, "presentation");
|
|
11489
|
-
const presentation = !(0, import_isEmpty.default)(nodePresentation) && {
|
|
11490
|
-
presentation: { ...nodePresentation, ...customDescription }
|
|
11491
|
-
};
|
|
11492
|
-
return (0, import_merge.default)(nodeDescription, { ...customDescription, ...presentation });
|
|
11493
|
-
}
|
|
11494
|
-
|
|
11495
|
-
// src/internals/fields.js
|
|
11496
|
-
var jsonTypes = {
|
|
11497
|
-
STRING: "string",
|
|
11498
|
-
NUMBER: "number",
|
|
11499
|
-
INTEGER: "integer",
|
|
11500
|
-
OBJECT: "object",
|
|
11501
|
-
ARRAY: "array",
|
|
11502
|
-
BOOLEAN: "boolean",
|
|
11503
|
-
NULL: "null"
|
|
11504
|
-
};
|
|
11505
|
-
var supportedTypes = {
|
|
11506
|
-
TEXT: "text",
|
|
11507
|
-
NUMBER: "number",
|
|
11508
|
-
SELECT: "select",
|
|
11509
|
-
FILE: "file",
|
|
11510
|
-
RADIO: "radio",
|
|
11511
|
-
GROUP_ARRAY: "group-array",
|
|
11512
|
-
EMAIL: "email",
|
|
11513
|
-
DATE: "date",
|
|
11514
|
-
CHECKBOX: "checkbox",
|
|
11515
|
-
FIELDSET: "fieldset"
|
|
11516
|
-
};
|
|
11517
|
-
var jsonTypeToInputType = {
|
|
11518
|
-
[jsonTypes.STRING]: ({ oneOf: oneOf2, format }) => {
|
|
11519
|
-
if (format === "email")
|
|
11520
|
-
return supportedTypes.EMAIL;
|
|
11521
|
-
if (format === "date")
|
|
11522
|
-
return supportedTypes.DATE;
|
|
11523
|
-
if (format === "data-url")
|
|
11524
|
-
return supportedTypes.FILE;
|
|
11525
|
-
if (oneOf2)
|
|
11526
|
-
return supportedTypes.RADIO;
|
|
11527
|
-
return supportedTypes.TEXT;
|
|
11318
|
+
},
|
|
11319
|
+
test: function test2(value) {
|
|
11320
|
+
return isAbsent_default(value) || value.length >= this.resolve(_min);
|
|
11321
|
+
}
|
|
11322
|
+
});
|
|
11528
11323
|
},
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
11532
|
-
|
|
11533
|
-
|
|
11534
|
-
|
|
11535
|
-
|
|
11324
|
+
max: function max4(_max, message) {
|
|
11325
|
+
message = message || array.max;
|
|
11326
|
+
return this.test({
|
|
11327
|
+
message,
|
|
11328
|
+
name: "max",
|
|
11329
|
+
exclusive: true,
|
|
11330
|
+
params: {
|
|
11331
|
+
max: _max
|
|
11332
|
+
},
|
|
11333
|
+
test: function test2(value) {
|
|
11334
|
+
return isAbsent_default(value) || value.length <= this.resolve(_max);
|
|
11335
|
+
}
|
|
11336
|
+
});
|
|
11536
11337
|
},
|
|
11537
|
-
|
|
11538
|
-
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
|
|
11547
|
-
|
|
11548
|
-
|
|
11549
|
-
|
|
11550
|
-
|
|
11551
|
-
return
|
|
11552
|
-
}
|
|
11553
|
-
|
|
11554
|
-
return
|
|
11555
|
-
}
|
|
11556
|
-
|
|
11338
|
+
ensure: function ensure2() {
|
|
11339
|
+
var _this4 = this;
|
|
11340
|
+
return this.default(function() {
|
|
11341
|
+
return [];
|
|
11342
|
+
}).transform(function(val, original) {
|
|
11343
|
+
if (_this4._typeCheck(val))
|
|
11344
|
+
return val;
|
|
11345
|
+
return original == null ? [] : [].concat(original);
|
|
11346
|
+
});
|
|
11347
|
+
},
|
|
11348
|
+
compact: function compact(rejector) {
|
|
11349
|
+
var reject = !rejector ? function(v) {
|
|
11350
|
+
return !!v;
|
|
11351
|
+
} : function(v, i, a) {
|
|
11352
|
+
return !rejector(v, i, a);
|
|
11353
|
+
};
|
|
11354
|
+
return this.transform(function(values2) {
|
|
11355
|
+
return values2 != null ? values2.filter(reject) : values2;
|
|
11356
|
+
});
|
|
11357
|
+
},
|
|
11358
|
+
describe: function describe3() {
|
|
11359
|
+
var base = SchemaType.prototype.describe.call(this);
|
|
11360
|
+
if (this.innerType)
|
|
11361
|
+
base.innerType = this.innerType.describe();
|
|
11362
|
+
return base;
|
|
11557
11363
|
}
|
|
11558
|
-
|
|
11559
|
-
|
|
11560
|
-
|
|
11561
|
-
|
|
11562
|
-
|
|
11563
|
-
|
|
11564
|
-
|
|
11565
|
-
|
|
11566
|
-
|
|
11567
|
-
|
|
11568
|
-
|
|
11569
|
-
};
|
|
11570
|
-
}
|
|
11571
|
-
function _composeFieldText({ name, label: label2, description, required: required2 = true, ...attrs }) {
|
|
11572
|
-
return {
|
|
11573
|
-
type: supportedTypes.TEXT,
|
|
11574
|
-
name,
|
|
11575
|
-
label: label2,
|
|
11576
|
-
description,
|
|
11577
|
-
required: required2,
|
|
11578
|
-
...attrs
|
|
11579
|
-
};
|
|
11580
|
-
}
|
|
11581
|
-
function _composeFieldEmail({ name, label: label2, required: required2 = true, ...attrs }) {
|
|
11582
|
-
return {
|
|
11583
|
-
type: supportedTypes.EMAIL,
|
|
11584
|
-
name,
|
|
11585
|
-
label: label2,
|
|
11586
|
-
required: required2,
|
|
11587
|
-
...attrs
|
|
11588
|
-
};
|
|
11589
|
-
}
|
|
11590
|
-
function _composeFieldNumber({
|
|
11591
|
-
name,
|
|
11592
|
-
label: label2,
|
|
11593
|
-
percentage = false,
|
|
11594
|
-
required: required2 = true,
|
|
11595
|
-
minimum,
|
|
11596
|
-
maximum,
|
|
11597
|
-
...attrs
|
|
11598
|
-
}) {
|
|
11599
|
-
let minValue = minimum;
|
|
11600
|
-
let maxValue = maximum;
|
|
11601
|
-
if (percentage) {
|
|
11602
|
-
minValue = minValue ?? 0;
|
|
11603
|
-
maxValue = maxValue ?? 100;
|
|
11364
|
+
});
|
|
11365
|
+
|
|
11366
|
+
// node_modules/yup/es/Lazy.js
|
|
11367
|
+
var Lazy = /* @__PURE__ */ function() {
|
|
11368
|
+
function Lazy2(mapFn) {
|
|
11369
|
+
this._resolve = function(value, options) {
|
|
11370
|
+
var schema = mapFn(value, options);
|
|
11371
|
+
if (!isSchema_default(schema))
|
|
11372
|
+
throw new TypeError("lazy() functions must return a valid schema");
|
|
11373
|
+
return schema.resolve(options);
|
|
11374
|
+
};
|
|
11604
11375
|
}
|
|
11605
|
-
|
|
11606
|
-
|
|
11607
|
-
|
|
11608
|
-
label: label2,
|
|
11609
|
-
percentage,
|
|
11610
|
-
required: required2,
|
|
11611
|
-
minimum: minValue,
|
|
11612
|
-
maximum: maxValue,
|
|
11613
|
-
...attrs
|
|
11614
|
-
};
|
|
11615
|
-
}
|
|
11616
|
-
function _composeFieldDate({ name, label: label2, required: required2 = true, ...attrs }) {
|
|
11617
|
-
return {
|
|
11618
|
-
type: supportedTypes.DATE,
|
|
11619
|
-
name,
|
|
11620
|
-
label: label2,
|
|
11621
|
-
required: required2,
|
|
11622
|
-
...attrs
|
|
11376
|
+
var _proto = Lazy2.prototype;
|
|
11377
|
+
_proto.resolve = function resolve2(options) {
|
|
11378
|
+
return this._resolve(options.value, options);
|
|
11623
11379
|
};
|
|
11624
|
-
|
|
11625
|
-
|
|
11626
|
-
return {
|
|
11627
|
-
type: supportedTypes.RADIO,
|
|
11628
|
-
name,
|
|
11629
|
-
label: label2,
|
|
11630
|
-
options,
|
|
11631
|
-
required: required2,
|
|
11632
|
-
...attrs
|
|
11380
|
+
_proto.cast = function cast2(value, options) {
|
|
11381
|
+
return this._resolve(value, options).cast(value, options);
|
|
11633
11382
|
};
|
|
11634
|
-
|
|
11635
|
-
|
|
11636
|
-
return {
|
|
11637
|
-
type: supportedTypes.SELECT,
|
|
11638
|
-
name,
|
|
11639
|
-
label: label2,
|
|
11640
|
-
options,
|
|
11641
|
-
required: required2,
|
|
11642
|
-
...attrs
|
|
11383
|
+
_proto.validate = function validate2(value, options, maybeCb) {
|
|
11384
|
+
return this._resolve(value, options).validate(value, options, maybeCb);
|
|
11643
11385
|
};
|
|
11644
|
-
|
|
11645
|
-
|
|
11646
|
-
return [
|
|
11647
|
-
{
|
|
11648
|
-
...nthFieldGroup,
|
|
11649
|
-
type: supportedTypes.GROUP_ARRAY,
|
|
11650
|
-
name,
|
|
11651
|
-
label: label2,
|
|
11652
|
-
required: required2,
|
|
11653
|
-
...attrs
|
|
11654
|
-
}
|
|
11655
|
-
];
|
|
11656
|
-
}
|
|
11657
|
-
function _composeFieldCheckbox({
|
|
11658
|
-
required: required2 = true,
|
|
11659
|
-
name,
|
|
11660
|
-
label: label2,
|
|
11661
|
-
description,
|
|
11662
|
-
default: defaultValue,
|
|
11663
|
-
checkboxValue,
|
|
11664
|
-
...attrs
|
|
11665
|
-
}) {
|
|
11666
|
-
return {
|
|
11667
|
-
type: supportedTypes.CHECKBOX,
|
|
11668
|
-
required: required2,
|
|
11669
|
-
name,
|
|
11670
|
-
label: label2,
|
|
11671
|
-
description,
|
|
11672
|
-
checkboxValue,
|
|
11673
|
-
...defaultValue && { default: defaultValue },
|
|
11674
|
-
...attrs
|
|
11386
|
+
_proto.validateSync = function validateSync2(value, options) {
|
|
11387
|
+
return this._resolve(value, options).validateSync(value, options);
|
|
11675
11388
|
};
|
|
11676
|
-
|
|
11677
|
-
|
|
11678
|
-
return {
|
|
11679
|
-
type: supportedTypes.FIELDSET,
|
|
11680
|
-
name,
|
|
11681
|
-
label: label2,
|
|
11682
|
-
fields,
|
|
11683
|
-
variant,
|
|
11684
|
-
...attrs
|
|
11389
|
+
_proto.validateAt = function validateAt(path, value, options) {
|
|
11390
|
+
return this._resolve(value, options).validateAt(path, value, options);
|
|
11685
11391
|
};
|
|
11686
|
-
|
|
11687
|
-
|
|
11688
|
-
type: inputType,
|
|
11689
|
-
...attrs
|
|
11690
|
-
});
|
|
11691
|
-
var inputTypeMap = {
|
|
11692
|
-
text: _composeFieldText,
|
|
11693
|
-
select: _composeFieldSelect,
|
|
11694
|
-
radio: _composeFieldRadio,
|
|
11695
|
-
date: _composeFieldDate,
|
|
11696
|
-
number: _composeFieldNumber,
|
|
11697
|
-
"group-array": _composeNthFieldGroup,
|
|
11698
|
-
fieldset: _composeFieldset,
|
|
11699
|
-
file: _composeFieldFile,
|
|
11700
|
-
email: _composeFieldEmail,
|
|
11701
|
-
checkbox: _composeFieldCheckbox
|
|
11702
|
-
};
|
|
11703
|
-
function _composeFieldCustomClosure(defaultComposeFn) {
|
|
11704
|
-
return ({ fieldCustomization, ...attrs }) => {
|
|
11705
|
-
const { description, ...restFieldCustomization } = fieldCustomization;
|
|
11706
|
-
const fieldDescription = getFieldDescription(attrs, fieldCustomization);
|
|
11707
|
-
const { nthFieldGroup, ...restAttrs } = attrs;
|
|
11708
|
-
const commonAttrs = {
|
|
11709
|
-
...restAttrs,
|
|
11710
|
-
...restFieldCustomization,
|
|
11711
|
-
...fieldDescription
|
|
11712
|
-
};
|
|
11713
|
-
if (attrs.inputType === supportedTypes.GROUP_ARRAY) {
|
|
11714
|
-
return [
|
|
11715
|
-
{
|
|
11716
|
-
...nthFieldGroup,
|
|
11717
|
-
...commonAttrs
|
|
11718
|
-
}
|
|
11719
|
-
];
|
|
11720
|
-
}
|
|
11721
|
-
return {
|
|
11722
|
-
...defaultComposeFn(attrs),
|
|
11723
|
-
...commonAttrs
|
|
11724
|
-
};
|
|
11392
|
+
_proto.validateSyncAt = function validateSyncAt(path, value, options) {
|
|
11393
|
+
return this._resolve(value, options).validateSyncAt(path, value, options);
|
|
11725
11394
|
};
|
|
11726
|
-
|
|
11395
|
+
return Lazy2;
|
|
11396
|
+
}();
|
|
11397
|
+
Lazy.prototype.__isYupSchema__ = true;
|
|
11398
|
+
var Lazy_default = Lazy;
|
|
11727
11399
|
|
|
11728
|
-
//
|
|
11729
|
-
var
|
|
11730
|
-
var
|
|
11731
|
-
|
|
11400
|
+
// node_modules/yup/es/index.js
|
|
11401
|
+
var boolean2 = boolean_default;
|
|
11402
|
+
var lazy = function lazy2(fn) {
|
|
11403
|
+
return new Lazy_default(fn);
|
|
11404
|
+
};
|
|
11732
11405
|
|
|
11733
|
-
// src/
|
|
11734
|
-
|
|
11735
|
-
|
|
11736
|
-
|
|
11737
|
-
|
|
11738
|
-
const sampleEmptyObject = buildSampleEmptyObject(schema);
|
|
11739
|
-
scopes.set(key, createValidationsScope(jsonSchema));
|
|
11740
|
-
Object.entries(jsonSchema?.properties ?? {}).filter(([, property2]) => property2.type === "object" || property2.type === "array").forEach(([key2, property2]) => {
|
|
11741
|
-
if (property2.type === "array") {
|
|
11742
|
-
createScopes(property2.items, `${key2}[]`);
|
|
11743
|
-
} else {
|
|
11744
|
-
createScopes(property2, key2);
|
|
11745
|
-
}
|
|
11746
|
-
});
|
|
11747
|
-
validateInlineRules(jsonSchema, sampleEmptyObject);
|
|
11748
|
-
}
|
|
11749
|
-
createScopes(schema);
|
|
11750
|
-
return {
|
|
11751
|
-
scopes,
|
|
11752
|
-
getScope(name = "root") {
|
|
11753
|
-
return scopes.get(name);
|
|
11754
|
-
}
|
|
11406
|
+
// src/utils.js
|
|
11407
|
+
function convertDiskSizeFromTo(from2, to) {
|
|
11408
|
+
const units = ["bytes", "kb", "mb"];
|
|
11409
|
+
return function convert(value) {
|
|
11410
|
+
return value * Math.pow(1024, units.indexOf(from2.toLowerCase())) / Math.pow(1024, units.indexOf(to.toLowerCase()));
|
|
11755
11411
|
};
|
|
11756
11412
|
}
|
|
11757
|
-
function
|
|
11758
|
-
|
|
11759
|
-
|
|
11760
|
-
|
|
11761
|
-
|
|
11762
|
-
|
|
11763
|
-
|
|
11764
|
-
|
|
11765
|
-
|
|
11766
|
-
|
|
11767
|
-
|
|
11768
|
-
|
|
11769
|
-
|
|
11413
|
+
function containsHTML(str = "") {
|
|
11414
|
+
return /<[a-z][\s\S]*>/i.test(str);
|
|
11415
|
+
}
|
|
11416
|
+
function wrapWithSpan(html, properties = {}) {
|
|
11417
|
+
const attributes = Object.entries(properties).reduce((acc, [key, value]) => `${acc}${key}="${value}" `, "").trim();
|
|
11418
|
+
return `<span ${attributes}>${html}</span>`;
|
|
11419
|
+
}
|
|
11420
|
+
function hasProperty(object2, propertyName) {
|
|
11421
|
+
return Object.prototype.hasOwnProperty.call(object2, propertyName);
|
|
11422
|
+
}
|
|
11423
|
+
|
|
11424
|
+
// src/checkIfConditionMatches.js
|
|
11425
|
+
function checkIfConditionMatchesProperties(node, formValues, formFields, logic) {
|
|
11426
|
+
return Object.keys(node.if.properties ?? {}).every((name) => {
|
|
11427
|
+
const currentProperty = node.if.properties[name];
|
|
11428
|
+
const value = formValues[name];
|
|
11429
|
+
const hasEmptyValue = typeof value === "undefined" || // NOTE: This is a "Remote API" dependency, as empty fields are sent as "null".
|
|
11430
|
+
value === null;
|
|
11431
|
+
const hasIfExplicit = node.if.required?.includes(name);
|
|
11432
|
+
if (hasEmptyValue && !hasIfExplicit) {
|
|
11433
|
+
return true;
|
|
11770
11434
|
}
|
|
11771
|
-
|
|
11772
|
-
|
|
11773
|
-
});
|
|
11774
|
-
computedValues.forEach(([id, computedValue]) => {
|
|
11775
|
-
if (!computedValue.rule) {
|
|
11776
|
-
throw Error(`[json-schema-form] json-logic error: Computed value "${id}" has missing rule.`);
|
|
11435
|
+
if (hasProperty(currentProperty, "const")) {
|
|
11436
|
+
return compareFormValueWithSchemaValue(value, currentProperty.const);
|
|
11777
11437
|
}
|
|
11778
|
-
|
|
11779
|
-
|
|
11780
|
-
|
|
11781
|
-
|
|
11782
|
-
|
|
11783
|
-
}
|
|
11784
|
-
return {
|
|
11785
|
-
validationMap,
|
|
11786
|
-
computedValuesMap,
|
|
11787
|
-
validate: validate2,
|
|
11788
|
-
applyValidationRuleInCondition(id, values2) {
|
|
11789
|
-
const validation = validationMap.get(id);
|
|
11790
|
-
return validate2(validation.rule, values2);
|
|
11791
|
-
},
|
|
11792
|
-
applyComputedValueInField(id, values2, fieldName) {
|
|
11793
|
-
const validation = computedValuesMap.get(id);
|
|
11794
|
-
if (validation === void 0) {
|
|
11795
|
-
throw Error(
|
|
11796
|
-
`[json-schema-form] json-logic error: Computed value "${id}" doesn't exist in field "${fieldName}".`
|
|
11797
|
-
);
|
|
11438
|
+
if (currentProperty.contains?.pattern) {
|
|
11439
|
+
const formValue = value || [];
|
|
11440
|
+
if (Array.isArray(formValue)) {
|
|
11441
|
+
const pattern = new RegExp(currentProperty.contains.pattern);
|
|
11442
|
+
return (value || []).some((item) => pattern.test(item));
|
|
11798
11443
|
}
|
|
11799
|
-
return validate2(validation.rule, values2);
|
|
11800
|
-
},
|
|
11801
|
-
applyComputedValueRuleInCondition(id, values2) {
|
|
11802
|
-
const validation = computedValuesMap.get(id);
|
|
11803
|
-
return validate2(validation.rule, values2);
|
|
11804
11444
|
}
|
|
11805
|
-
|
|
11806
|
-
|
|
11807
|
-
|
|
11808
|
-
|
|
11809
|
-
|
|
11810
|
-
|
|
11811
|
-
|
|
11812
|
-
|
|
11813
|
-
|
|
11814
|
-
|
|
11815
|
-
|
|
11816
|
-
|
|
11817
|
-
|
|
11445
|
+
if (currentProperty.enum) {
|
|
11446
|
+
return currentProperty.enum.includes(value);
|
|
11447
|
+
}
|
|
11448
|
+
if (currentProperty.properties) {
|
|
11449
|
+
return checkIfConditionMatchesProperties(
|
|
11450
|
+
{ if: currentProperty },
|
|
11451
|
+
formValues[name],
|
|
11452
|
+
getField(name, formFields).fields,
|
|
11453
|
+
logic
|
|
11454
|
+
);
|
|
11455
|
+
}
|
|
11456
|
+
const field = getField(name, formFields);
|
|
11457
|
+
return validateFieldSchema(
|
|
11458
|
+
{
|
|
11459
|
+
options: field.options,
|
|
11460
|
+
// @TODO/CODE SMELL. We are passing the property (raw field), but buildYupSchema() expected the output field.
|
|
11461
|
+
...currentProperty,
|
|
11462
|
+
inputType: field.inputType,
|
|
11463
|
+
required: true
|
|
11464
|
+
},
|
|
11465
|
+
value
|
|
11818
11466
|
);
|
|
11819
|
-
}
|
|
11820
|
-
|
|
11821
|
-
|
|
11822
|
-
|
|
11823
|
-
|
|
11824
|
-
|
|
11467
|
+
});
|
|
11468
|
+
}
|
|
11469
|
+
function checkIfMatchesValidationsAndComputedValues(node, formValues, logic, parentID) {
|
|
11470
|
+
const validationsMatch = Object.entries(node.if.validations ?? {}).every(([name, property2]) => {
|
|
11471
|
+
const currentValue = logic.getScope(parentID).applyValidationRuleInCondition(name, formValues);
|
|
11472
|
+
if (Object.hasOwn(property2, "const") && currentValue === property2.const)
|
|
11473
|
+
return true;
|
|
11474
|
+
return false;
|
|
11475
|
+
});
|
|
11476
|
+
const computedValuesMatch = Object.entries(node.if.computedValues ?? {}).every(
|
|
11477
|
+
([name, property2]) => {
|
|
11478
|
+
const currentValue = logic.getScope(parentID).applyComputedValueRuleInCondition(name, formValues);
|
|
11479
|
+
if (Object.hasOwn(property2, "const") && currentValue === property2.const)
|
|
11825
11480
|
return true;
|
|
11826
|
-
return
|
|
11481
|
+
return false;
|
|
11827
11482
|
}
|
|
11828
11483
|
);
|
|
11484
|
+
return computedValuesMatch && validationsMatch;
|
|
11829
11485
|
}
|
|
11830
|
-
|
|
11831
|
-
|
|
11832
|
-
|
|
11833
|
-
|
|
11834
|
-
|
|
11835
|
-
|
|
11836
|
-
|
|
11837
|
-
|
|
11838
|
-
|
|
11839
|
-
|
|
11840
|
-
|
|
11841
|
-
|
|
11842
|
-
|
|
11843
|
-
|
|
11844
|
-
|
|
11845
|
-
|
|
11486
|
+
|
|
11487
|
+
// src/internals/helpers.js
|
|
11488
|
+
var import_merge = __toESM(require_merge2());
|
|
11489
|
+
var import_get2 = __toESM(require_get());
|
|
11490
|
+
var import_isEmpty = __toESM(require_isEmpty());
|
|
11491
|
+
var import_isFunction3 = __toESM(require_isFunction());
|
|
11492
|
+
function pickXKey(node, key) {
|
|
11493
|
+
const deprecatedKeys = ["presentation", "errorMessage"];
|
|
11494
|
+
return (0, import_get2.default)(node, `x-jsf-${key}`, deprecatedKeys.includes(key) ? node?.[key] : void 0);
|
|
11495
|
+
}
|
|
11496
|
+
function getFieldDescription(node, customProperties = {}) {
|
|
11497
|
+
const nodeDescription = node?.description ? {
|
|
11498
|
+
description: node.description
|
|
11499
|
+
} : {};
|
|
11500
|
+
const customDescription = customProperties?.description ? {
|
|
11501
|
+
description: (0, import_isFunction3.default)(customProperties.description) ? customProperties.description(node?.description, {
|
|
11502
|
+
...node,
|
|
11503
|
+
...customProperties
|
|
11504
|
+
}) : customProperties.description
|
|
11505
|
+
} : {};
|
|
11506
|
+
const nodePresentation = pickXKey(node, "presentation");
|
|
11507
|
+
const presentation = !(0, import_isEmpty.default)(nodePresentation) && {
|
|
11508
|
+
presentation: { ...nodePresentation, ...customDescription }
|
|
11509
|
+
};
|
|
11510
|
+
return (0, import_merge.default)(nodeDescription, { ...customDescription, ...presentation });
|
|
11511
|
+
}
|
|
11512
|
+
|
|
11513
|
+
// src/internals/fields.js
|
|
11514
|
+
var jsonTypes = {
|
|
11515
|
+
STRING: "string",
|
|
11516
|
+
NUMBER: "number",
|
|
11517
|
+
INTEGER: "integer",
|
|
11518
|
+
OBJECT: "object",
|
|
11519
|
+
ARRAY: "array",
|
|
11520
|
+
BOOLEAN: "boolean",
|
|
11521
|
+
NULL: "null"
|
|
11522
|
+
};
|
|
11523
|
+
var supportedTypes = {
|
|
11524
|
+
TEXT: "text",
|
|
11525
|
+
NUMBER: "number",
|
|
11526
|
+
SELECT: "select",
|
|
11527
|
+
FILE: "file",
|
|
11528
|
+
RADIO: "radio",
|
|
11529
|
+
GROUP_ARRAY: "group-array",
|
|
11530
|
+
EMAIL: "email",
|
|
11531
|
+
DATE: "date",
|
|
11532
|
+
CHECKBOX: "checkbox",
|
|
11533
|
+
FIELDSET: "fieldset"
|
|
11534
|
+
};
|
|
11535
|
+
var jsonTypeToInputType = {
|
|
11536
|
+
[jsonTypes.STRING]: ({ oneOf: oneOf2, format }) => {
|
|
11537
|
+
if (format === "email")
|
|
11538
|
+
return supportedTypes.EMAIL;
|
|
11539
|
+
if (format === "date")
|
|
11540
|
+
return supportedTypes.DATE;
|
|
11541
|
+
if (format === "data-url")
|
|
11542
|
+
return supportedTypes.FILE;
|
|
11543
|
+
if (oneOf2)
|
|
11544
|
+
return supportedTypes.RADIO;
|
|
11545
|
+
return supportedTypes.TEXT;
|
|
11546
|
+
},
|
|
11547
|
+
[jsonTypes.NUMBER]: () => supportedTypes.NUMBER,
|
|
11548
|
+
[jsonTypes.INTEGER]: () => supportedTypes.NUMBER,
|
|
11549
|
+
[jsonTypes.OBJECT]: () => supportedTypes.FIELDSET,
|
|
11550
|
+
[jsonTypes.ARRAY]: ({ items }) => {
|
|
11551
|
+
if (items.properties)
|
|
11552
|
+
return supportedTypes.GROUP_ARRAY;
|
|
11553
|
+
return supportedTypes.SELECT;
|
|
11554
|
+
},
|
|
11555
|
+
[jsonTypes.BOOLEAN]: () => supportedTypes.CHECKBOX
|
|
11556
|
+
};
|
|
11557
|
+
function getInputType(fieldProperties, strictInputType, name) {
|
|
11558
|
+
const presentation = pickXKey(fieldProperties, "presentation") ?? {};
|
|
11559
|
+
const presentationInputType = presentation?.inputType;
|
|
11560
|
+
if (presentationInputType) {
|
|
11561
|
+
return presentationInputType;
|
|
11562
|
+
}
|
|
11563
|
+
if (strictInputType) {
|
|
11564
|
+
throw Error(`Strict error: Missing inputType to field "${name || fieldProperties.title}".
|
|
11565
|
+
You can fix the json schema or skip this error by calling createHeadlessForm(schema, { strictInputType: false })`);
|
|
11566
|
+
}
|
|
11567
|
+
if (!fieldProperties.type) {
|
|
11568
|
+
if (fieldProperties.items?.properties) {
|
|
11569
|
+
return supportedTypes.GROUP_ARRAY;
|
|
11570
|
+
}
|
|
11571
|
+
if (fieldProperties.properties) {
|
|
11572
|
+
return supportedTypes.SELECT;
|
|
11846
11573
|
}
|
|
11847
|
-
|
|
11848
|
-
const computedValue = logic.getScope(parentID).validate(rule, formValues);
|
|
11849
|
-
return prev.replaceAll(`{{${key}}}`, computedValue);
|
|
11850
|
-
}, value);
|
|
11851
|
-
return computedTemplateValue.replace(/\{\{([^{}]+)\}\}/g, (match, key) => {
|
|
11852
|
-
return logic.getScope(parentID).applyComputedValueInField(key.trim(), formValues, fieldName);
|
|
11853
|
-
});
|
|
11574
|
+
return jsonTypeToInputType[jsonTypes.STRING](fieldProperties);
|
|
11854
11575
|
}
|
|
11855
|
-
return
|
|
11576
|
+
return jsonTypeToInputType[fieldProperties.type]?.(fieldProperties);
|
|
11856
11577
|
}
|
|
11857
|
-
function
|
|
11858
|
-
return
|
|
11859
|
-
|
|
11860
|
-
|
|
11861
|
-
|
|
11862
|
-
|
|
11863
|
-
|
|
11864
|
-
|
|
11865
|
-
|
|
11866
|
-
{ ...fieldParams, ...attributes, required: isRequired },
|
|
11867
|
-
config,
|
|
11868
|
-
logic
|
|
11869
|
-
)
|
|
11870
|
-
};
|
|
11578
|
+
function _composeFieldFile({ name, label: label2, description, accept, required: required2 = true, ...attrs }) {
|
|
11579
|
+
return {
|
|
11580
|
+
type: supportedTypes.FILE,
|
|
11581
|
+
name,
|
|
11582
|
+
label: label2,
|
|
11583
|
+
description,
|
|
11584
|
+
required: required2,
|
|
11585
|
+
accept,
|
|
11586
|
+
...attrs
|
|
11871
11587
|
};
|
|
11872
11588
|
}
|
|
11873
|
-
function
|
|
11874
|
-
return
|
|
11875
|
-
|
|
11876
|
-
|
|
11877
|
-
|
|
11878
|
-
|
|
11879
|
-
|
|
11880
|
-
|
|
11881
|
-
return [
|
|
11882
|
-
"errorMessage",
|
|
11883
|
-
handleNestedObjectForComputedValues(value, formValues, parentID, logic, name)
|
|
11884
|
-
];
|
|
11885
|
-
case "x-jsf-presentation": {
|
|
11886
|
-
if (value.statement) {
|
|
11887
|
-
return [
|
|
11888
|
-
"statement",
|
|
11889
|
-
handleNestedObjectForComputedValues(value.statement, formValues, parentID, logic, name)
|
|
11890
|
-
];
|
|
11891
|
-
}
|
|
11892
|
-
return [
|
|
11893
|
-
key,
|
|
11894
|
-
handleNestedObjectForComputedValues(value.statement, formValues, parentID, logic, name)
|
|
11895
|
-
];
|
|
11896
|
-
}
|
|
11897
|
-
case "const":
|
|
11898
|
-
default: {
|
|
11899
|
-
if (typeof value === "object" && value.rule) {
|
|
11900
|
-
return [key, logic.getScope(parentID).validate(value.rule, formValues)];
|
|
11901
|
-
}
|
|
11902
|
-
return [key, logic.getScope(parentID).applyComputedValueInField(value, formValues, name)];
|
|
11903
|
-
}
|
|
11904
|
-
}
|
|
11589
|
+
function _composeFieldText({ name, label: label2, description, required: required2 = true, ...attrs }) {
|
|
11590
|
+
return {
|
|
11591
|
+
type: supportedTypes.TEXT,
|
|
11592
|
+
name,
|
|
11593
|
+
label: label2,
|
|
11594
|
+
description,
|
|
11595
|
+
required: required2,
|
|
11596
|
+
...attrs
|
|
11905
11597
|
};
|
|
11906
11598
|
}
|
|
11907
|
-
function
|
|
11908
|
-
return
|
|
11909
|
-
|
|
11910
|
-
|
|
11911
|
-
|
|
11912
|
-
|
|
11599
|
+
function _composeFieldEmail({ name, label: label2, required: required2 = true, ...attrs }) {
|
|
11600
|
+
return {
|
|
11601
|
+
type: supportedTypes.EMAIL,
|
|
11602
|
+
name,
|
|
11603
|
+
label: label2,
|
|
11604
|
+
required: required2,
|
|
11605
|
+
...attrs
|
|
11606
|
+
};
|
|
11913
11607
|
}
|
|
11914
|
-
function
|
|
11915
|
-
|
|
11916
|
-
|
|
11917
|
-
|
|
11608
|
+
function _composeFieldNumber({
|
|
11609
|
+
name,
|
|
11610
|
+
label: label2,
|
|
11611
|
+
percentage = false,
|
|
11612
|
+
required: required2 = true,
|
|
11613
|
+
minimum,
|
|
11614
|
+
maximum,
|
|
11615
|
+
...attrs
|
|
11616
|
+
}) {
|
|
11617
|
+
let minValue = minimum;
|
|
11618
|
+
let maxValue = maximum;
|
|
11619
|
+
if (percentage) {
|
|
11620
|
+
minValue = minValue ?? 0;
|
|
11621
|
+
maxValue = maxValue ?? 100;
|
|
11918
11622
|
}
|
|
11919
|
-
|
|
11920
|
-
|
|
11921
|
-
|
|
11922
|
-
|
|
11923
|
-
|
|
11924
|
-
|
|
11925
|
-
|
|
11926
|
-
|
|
11623
|
+
return {
|
|
11624
|
+
type: supportedTypes.NUMBER,
|
|
11625
|
+
name,
|
|
11626
|
+
label: label2,
|
|
11627
|
+
percentage,
|
|
11628
|
+
required: required2,
|
|
11629
|
+
minimum: minValue,
|
|
11630
|
+
maximum: maxValue,
|
|
11631
|
+
...attrs
|
|
11632
|
+
};
|
|
11633
|
+
}
|
|
11634
|
+
function _composeFieldDate({ name, label: label2, required: required2 = true, ...attrs }) {
|
|
11635
|
+
return {
|
|
11636
|
+
type: supportedTypes.DATE,
|
|
11637
|
+
name,
|
|
11638
|
+
label: label2,
|
|
11639
|
+
required: required2,
|
|
11640
|
+
...attrs
|
|
11641
|
+
};
|
|
11642
|
+
}
|
|
11643
|
+
function _composeFieldRadio({ name, label: label2, options, required: required2 = true, ...attrs }) {
|
|
11644
|
+
return {
|
|
11645
|
+
type: supportedTypes.RADIO,
|
|
11646
|
+
name,
|
|
11647
|
+
label: label2,
|
|
11648
|
+
options,
|
|
11649
|
+
required: required2,
|
|
11650
|
+
...attrs
|
|
11651
|
+
};
|
|
11652
|
+
}
|
|
11653
|
+
function _composeFieldSelect({ name, label: label2, options, required: required2 = true, ...attrs }) {
|
|
11654
|
+
return {
|
|
11655
|
+
type: supportedTypes.SELECT,
|
|
11656
|
+
name,
|
|
11657
|
+
label: label2,
|
|
11658
|
+
options,
|
|
11659
|
+
required: required2,
|
|
11660
|
+
...attrs
|
|
11661
|
+
};
|
|
11662
|
+
}
|
|
11663
|
+
function _composeNthFieldGroup({ name, label: label2, required: required2, nthFieldGroup, ...attrs }) {
|
|
11664
|
+
return [
|
|
11665
|
+
{
|
|
11666
|
+
...nthFieldGroup,
|
|
11667
|
+
type: supportedTypes.GROUP_ARRAY,
|
|
11668
|
+
name,
|
|
11669
|
+
label: label2,
|
|
11670
|
+
required: required2,
|
|
11671
|
+
...attrs
|
|
11927
11672
|
}
|
|
11928
|
-
|
|
11929
|
-
return sample;
|
|
11673
|
+
];
|
|
11930
11674
|
}
|
|
11931
|
-
function
|
|
11932
|
-
|
|
11933
|
-
|
|
11934
|
-
|
|
11935
|
-
|
|
11936
|
-
|
|
11937
|
-
|
|
11938
|
-
|
|
11939
|
-
|
|
11940
|
-
|
|
11941
|
-
|
|
11942
|
-
|
|
11943
|
-
|
|
11944
|
-
|
|
11675
|
+
function _composeFieldCheckbox({
|
|
11676
|
+
required: required2 = true,
|
|
11677
|
+
name,
|
|
11678
|
+
label: label2,
|
|
11679
|
+
description,
|
|
11680
|
+
default: defaultValue,
|
|
11681
|
+
checkboxValue,
|
|
11682
|
+
...attrs
|
|
11683
|
+
}) {
|
|
11684
|
+
return {
|
|
11685
|
+
type: supportedTypes.CHECKBOX,
|
|
11686
|
+
required: required2,
|
|
11687
|
+
name,
|
|
11688
|
+
label: label2,
|
|
11689
|
+
description,
|
|
11690
|
+
checkboxValue,
|
|
11691
|
+
...defaultValue && { default: defaultValue },
|
|
11692
|
+
...attrs
|
|
11693
|
+
};
|
|
11945
11694
|
}
|
|
11946
|
-
function
|
|
11947
|
-
|
|
11948
|
-
|
|
11949
|
-
|
|
11950
|
-
|
|
11951
|
-
|
|
11952
|
-
|
|
11953
|
-
|
|
11954
|
-
|
|
11955
|
-
if (exists === null) {
|
|
11956
|
-
throw Error(errorMessage(item));
|
|
11957
|
-
}
|
|
11958
|
-
} else {
|
|
11959
|
-
checkRuleIntegrity(item, id, data);
|
|
11960
|
-
}
|
|
11961
|
-
});
|
|
11962
|
-
});
|
|
11695
|
+
function _composeFieldset({ name, label: label2, fields, variant, ...attrs }) {
|
|
11696
|
+
return {
|
|
11697
|
+
type: supportedTypes.FIELDSET,
|
|
11698
|
+
name,
|
|
11699
|
+
label: label2,
|
|
11700
|
+
fields,
|
|
11701
|
+
variant,
|
|
11702
|
+
...attrs
|
|
11703
|
+
};
|
|
11963
11704
|
}
|
|
11964
|
-
|
|
11965
|
-
|
|
11966
|
-
|
|
11967
|
-
|
|
11968
|
-
|
|
11969
|
-
|
|
11970
|
-
|
|
11971
|
-
|
|
11705
|
+
var _composeFieldArbitraryClosure = (inputType) => (attrs) => ({
|
|
11706
|
+
type: inputType,
|
|
11707
|
+
...attrs
|
|
11708
|
+
});
|
|
11709
|
+
var inputTypeMap = {
|
|
11710
|
+
text: _composeFieldText,
|
|
11711
|
+
select: _composeFieldSelect,
|
|
11712
|
+
radio: _composeFieldRadio,
|
|
11713
|
+
date: _composeFieldDate,
|
|
11714
|
+
number: _composeFieldNumber,
|
|
11715
|
+
"group-array": _composeNthFieldGroup,
|
|
11716
|
+
fieldset: _composeFieldset,
|
|
11717
|
+
file: _composeFieldFile,
|
|
11718
|
+
email: _composeFieldEmail,
|
|
11719
|
+
checkbox: _composeFieldCheckbox
|
|
11720
|
+
};
|
|
11721
|
+
function _composeFieldCustomClosure(defaultComposeFn) {
|
|
11722
|
+
return ({ fieldCustomization, ...attrs }) => {
|
|
11723
|
+
const { description, ...restFieldCustomization } = fieldCustomization;
|
|
11724
|
+
const fieldDescription = getFieldDescription(attrs, fieldCustomization);
|
|
11725
|
+
const { nthFieldGroup, ...restAttrs } = attrs;
|
|
11726
|
+
const commonAttrs = {
|
|
11727
|
+
...restAttrs,
|
|
11728
|
+
...restFieldCustomization,
|
|
11729
|
+
...fieldDescription
|
|
11730
|
+
};
|
|
11731
|
+
if (attrs.inputType === supportedTypes.GROUP_ARRAY) {
|
|
11732
|
+
return [
|
|
11733
|
+
{
|
|
11734
|
+
...nthFieldGroup,
|
|
11735
|
+
...commonAttrs
|
|
11736
|
+
}
|
|
11737
|
+
];
|
|
11972
11738
|
}
|
|
11973
|
-
|
|
11974
|
-
|
|
11975
|
-
|
|
11976
|
-
|
|
11977
|
-
|
|
11978
|
-
return intermediatePath.replace(/\.\d+$/, "");
|
|
11739
|
+
return {
|
|
11740
|
+
...defaultComposeFn(attrs),
|
|
11741
|
+
...commonAttrs
|
|
11742
|
+
};
|
|
11743
|
+
};
|
|
11979
11744
|
}
|
|
11980
11745
|
|
|
11746
|
+
// src/jsonLogic.js
|
|
11747
|
+
var import_json_logic_js = __toESM(require_logic());
|
|
11748
|
+
|
|
11981
11749
|
// src/yupSchema.js
|
|
11750
|
+
var import_flow = __toESM(require_flow());
|
|
11751
|
+
var import_noop = __toESM(require_noop());
|
|
11752
|
+
var import_randexp = __toESM(require_randexp());
|
|
11982
11753
|
var DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
|
|
11983
11754
|
var baseString = StringSchema().trim();
|
|
11984
11755
|
var todayDateHint = (/* @__PURE__ */ new Date()).toISOString().substring(0, 10);
|
|
@@ -12174,118 +11945,414 @@ function buildYupSchema(field, config, logic) {
|
|
|
12174
11945
|
}) : true
|
|
12175
11946
|
);
|
|
12176
11947
|
}
|
|
12177
|
-
function withConst(yupSchema) {
|
|
12178
|
-
return yupSchema.test(
|
|
12179
|
-
"isConst",
|
|
12180
|
-
errorMessage.const ?? errorMessageFromConfig.const ?? `The only accepted value is ${propertyFields.const}.`,
|
|
12181
|
-
(value) => propertyFields.required === false && value === void 0 || value === null || value === propertyFields.const
|
|
11948
|
+
function withConst(yupSchema) {
|
|
11949
|
+
return yupSchema.test(
|
|
11950
|
+
"isConst",
|
|
11951
|
+
errorMessage.const ?? errorMessageFromConfig.const ?? `The only accepted value is ${propertyFields.const}.`,
|
|
11952
|
+
(value) => propertyFields.required === false && value === void 0 || value === null || value === propertyFields.const
|
|
11953
|
+
);
|
|
11954
|
+
}
|
|
11955
|
+
function withBaseSchema() {
|
|
11956
|
+
const customErrorMsg = errorMessage.type || errorMessageFromConfig.type;
|
|
11957
|
+
if (customErrorMsg) {
|
|
11958
|
+
return baseSchema.typeError(customErrorMsg);
|
|
11959
|
+
}
|
|
11960
|
+
return baseSchema;
|
|
11961
|
+
}
|
|
11962
|
+
function buildFieldSetSchema(innerFields) {
|
|
11963
|
+
const fieldSetShape = {};
|
|
11964
|
+
innerFields.forEach((fieldSetfield) => {
|
|
11965
|
+
if (fieldSetfield.fields) {
|
|
11966
|
+
fieldSetShape[fieldSetfield.name] = ObjectSchema().shape(
|
|
11967
|
+
buildFieldSetSchema(fieldSetfield.fields)
|
|
11968
|
+
);
|
|
11969
|
+
} else {
|
|
11970
|
+
fieldSetShape[fieldSetfield.name] = buildYupSchema(
|
|
11971
|
+
{
|
|
11972
|
+
...fieldSetfield,
|
|
11973
|
+
inputType: fieldSetfield.type
|
|
11974
|
+
},
|
|
11975
|
+
config
|
|
11976
|
+
)();
|
|
11977
|
+
}
|
|
11978
|
+
});
|
|
11979
|
+
return fieldSetShape;
|
|
11980
|
+
}
|
|
11981
|
+
function buildGroupArraySchema() {
|
|
11982
|
+
return ObjectSchema().shape(
|
|
11983
|
+
propertyFields.nthFieldGroup.fields().reduce(
|
|
11984
|
+
(schema, groupArrayField) => ({
|
|
11985
|
+
...schema,
|
|
11986
|
+
[groupArrayField.name]: buildYupSchema(groupArrayField, config)()
|
|
11987
|
+
}),
|
|
11988
|
+
{}
|
|
11989
|
+
)
|
|
11990
|
+
);
|
|
11991
|
+
}
|
|
11992
|
+
const validators = [withBaseSchema];
|
|
11993
|
+
if (inputType === supportedTypes.GROUP_ARRAY) {
|
|
11994
|
+
validators[0] = () => withBaseSchema().of(buildGroupArraySchema());
|
|
11995
|
+
} else if (inputType === supportedTypes.FIELDSET) {
|
|
11996
|
+
validators[0] = () => withBaseSchema().shape(buildFieldSetSchema(propertyFields.fields));
|
|
11997
|
+
}
|
|
11998
|
+
if (propertyFields.required) {
|
|
11999
|
+
validators.push(withRequired);
|
|
12000
|
+
}
|
|
12001
|
+
if (typeof propertyFields.minimum !== "undefined") {
|
|
12002
|
+
validators.push(withMin);
|
|
12003
|
+
}
|
|
12004
|
+
if (typeof propertyFields.minLength !== "undefined") {
|
|
12005
|
+
validators.push(withMinLength);
|
|
12006
|
+
}
|
|
12007
|
+
if (propertyFields.maximum !== void 0) {
|
|
12008
|
+
validators.push(withMax);
|
|
12009
|
+
}
|
|
12010
|
+
if (propertyFields.maxLength) {
|
|
12011
|
+
validators.push(withMaxLength);
|
|
12012
|
+
}
|
|
12013
|
+
if (propertyFields.pattern) {
|
|
12014
|
+
validators.push(withMatches);
|
|
12015
|
+
}
|
|
12016
|
+
if (propertyFields.maxFileSize) {
|
|
12017
|
+
validators.push(withMaxFileSize);
|
|
12018
|
+
}
|
|
12019
|
+
if (propertyFields.accept) {
|
|
12020
|
+
validators.push(withFileFormat);
|
|
12021
|
+
}
|
|
12022
|
+
if (propertyFields.const) {
|
|
12023
|
+
validators.push(withConst);
|
|
12024
|
+
}
|
|
12025
|
+
if (propertyFields.jsonLogicValidations) {
|
|
12026
|
+
propertyFields.jsonLogicValidations.forEach(
|
|
12027
|
+
(id) => validators.push(yupSchemaWithCustomJSONLogic({ field, id, logic, config }))
|
|
12028
|
+
);
|
|
12029
|
+
}
|
|
12030
|
+
return (0, import_flow.default)(validators);
|
|
12031
|
+
}
|
|
12032
|
+
function getNoSortEdges(fields = []) {
|
|
12033
|
+
return fields.reduce((list, field) => {
|
|
12034
|
+
if (field.noSortEdges) {
|
|
12035
|
+
list.push(field.name);
|
|
12036
|
+
}
|
|
12037
|
+
return list;
|
|
12038
|
+
}, []);
|
|
12039
|
+
}
|
|
12040
|
+
function getSchema(fields = [], config) {
|
|
12041
|
+
const newSchema = {};
|
|
12042
|
+
fields.forEach((field) => {
|
|
12043
|
+
if (field.schema) {
|
|
12044
|
+
if (field.name) {
|
|
12045
|
+
if (field.inputType === supportedTypes.FIELDSET) {
|
|
12046
|
+
const fieldsetSchema = buildYupSchema(field, config)();
|
|
12047
|
+
newSchema[field.name] = fieldsetSchema;
|
|
12048
|
+
} else {
|
|
12049
|
+
newSchema[field.name] = field.schema;
|
|
12050
|
+
}
|
|
12051
|
+
} else {
|
|
12052
|
+
Object.assign(newSchema, getSchema(field.fields, config));
|
|
12053
|
+
}
|
|
12054
|
+
}
|
|
12055
|
+
});
|
|
12056
|
+
return newSchema;
|
|
12057
|
+
}
|
|
12058
|
+
function buildCompleteYupSchema(fields, config) {
|
|
12059
|
+
return ObjectSchema().shape(getSchema(fields, config), getNoSortEdges(fields));
|
|
12060
|
+
}
|
|
12061
|
+
|
|
12062
|
+
// src/jsonLogic.js
|
|
12063
|
+
function createValidationChecker(schema) {
|
|
12064
|
+
const scopes = /* @__PURE__ */ new Map();
|
|
12065
|
+
function createScopes(jsonSchema, key = "root") {
|
|
12066
|
+
const sampleEmptyObject = buildSampleEmptyObject(schema);
|
|
12067
|
+
scopes.set(key, createValidationsScope(jsonSchema));
|
|
12068
|
+
Object.entries(jsonSchema?.properties ?? {}).filter(([, property2]) => property2.type === "object" || property2.type === "array").forEach(([key2, property2]) => {
|
|
12069
|
+
if (property2.type === "array") {
|
|
12070
|
+
createScopes(property2.items, `${key2}[]`);
|
|
12071
|
+
} else {
|
|
12072
|
+
createScopes(property2, key2);
|
|
12073
|
+
}
|
|
12074
|
+
});
|
|
12075
|
+
validateInlineRules(jsonSchema, sampleEmptyObject);
|
|
12076
|
+
}
|
|
12077
|
+
createScopes(schema);
|
|
12078
|
+
return {
|
|
12079
|
+
scopes,
|
|
12080
|
+
getScope(name = "root") {
|
|
12081
|
+
return scopes.get(name);
|
|
12082
|
+
}
|
|
12083
|
+
};
|
|
12084
|
+
}
|
|
12085
|
+
function createValidationsScope(schema) {
|
|
12086
|
+
const validationMap = /* @__PURE__ */ new Map();
|
|
12087
|
+
const computedValuesMap = /* @__PURE__ */ new Map();
|
|
12088
|
+
const logic = schema?.["x-jsf-logic"] ?? {
|
|
12089
|
+
validations: {},
|
|
12090
|
+
computedValues: {}
|
|
12091
|
+
};
|
|
12092
|
+
const validations = Object.entries(logic.validations ?? {});
|
|
12093
|
+
const computedValues = Object.entries(logic.computedValues ?? {});
|
|
12094
|
+
const sampleEmptyObject = buildSampleEmptyObject(schema);
|
|
12095
|
+
validations.forEach(([id, validation]) => {
|
|
12096
|
+
if (!validation.rule) {
|
|
12097
|
+
throw Error(`[json-schema-form] json-logic error: Validation "${id}" has missing rule.`);
|
|
12098
|
+
}
|
|
12099
|
+
checkRuleIntegrity(validation.rule, id, sampleEmptyObject);
|
|
12100
|
+
validationMap.set(id, validation);
|
|
12101
|
+
});
|
|
12102
|
+
computedValues.forEach(([id, computedValue]) => {
|
|
12103
|
+
if (!computedValue.rule) {
|
|
12104
|
+
throw Error(`[json-schema-form] json-logic error: Computed value "${id}" has missing rule.`);
|
|
12105
|
+
}
|
|
12106
|
+
checkRuleIntegrity(computedValue.rule, id, sampleEmptyObject);
|
|
12107
|
+
computedValuesMap.set(id, computedValue);
|
|
12108
|
+
});
|
|
12109
|
+
function validate2(rule, values2) {
|
|
12110
|
+
return import_json_logic_js.default.apply(
|
|
12111
|
+
rule,
|
|
12112
|
+
replaceUndefinedValuesWithNulls({ ...sampleEmptyObject, ...values2 })
|
|
12113
|
+
);
|
|
12114
|
+
}
|
|
12115
|
+
return {
|
|
12116
|
+
validationMap,
|
|
12117
|
+
computedValuesMap,
|
|
12118
|
+
validate: validate2,
|
|
12119
|
+
applyValidationRuleInCondition(id, values2) {
|
|
12120
|
+
const validation = validationMap.get(id);
|
|
12121
|
+
return validate2(validation.rule, values2);
|
|
12122
|
+
},
|
|
12123
|
+
applyComputedValueInField(id, values2, fieldName) {
|
|
12124
|
+
const validation = computedValuesMap.get(id);
|
|
12125
|
+
if (validation === void 0) {
|
|
12126
|
+
throw Error(
|
|
12127
|
+
`[json-schema-form] json-logic error: Computed value "${id}" doesn't exist in field "${fieldName}".`
|
|
12128
|
+
);
|
|
12129
|
+
}
|
|
12130
|
+
return validate2(validation.rule, values2);
|
|
12131
|
+
},
|
|
12132
|
+
applyComputedValueRuleInCondition(id, values2) {
|
|
12133
|
+
const validation = computedValuesMap.get(id);
|
|
12134
|
+
return validate2(validation.rule, values2);
|
|
12135
|
+
}
|
|
12136
|
+
};
|
|
12137
|
+
}
|
|
12138
|
+
function replaceUndefinedValuesWithNulls(values2 = {}) {
|
|
12139
|
+
return Object.entries(values2).reduce((prev, [key, value]) => {
|
|
12140
|
+
return { ...prev, [key]: value === void 0 || value === null ? NaN : value };
|
|
12141
|
+
}, {});
|
|
12142
|
+
}
|
|
12143
|
+
function yupSchemaWithCustomJSONLogic({ field, logic, config, id }) {
|
|
12144
|
+
const { parentID = "root" } = config;
|
|
12145
|
+
const validation = logic.getScope(parentID).validationMap.get(id);
|
|
12146
|
+
if (validation === void 0) {
|
|
12147
|
+
throw Error(
|
|
12148
|
+
`[json-schema-form] json-logic error: "${field.name}" required validation "${id}" doesn't exist.`
|
|
12149
|
+
);
|
|
12150
|
+
}
|
|
12151
|
+
return (yupSchema) => yupSchema.test(
|
|
12152
|
+
`${field.name}-validation-${id}`,
|
|
12153
|
+
validation?.errorMessage ?? "This field is invalid.",
|
|
12154
|
+
(value, { parent }) => {
|
|
12155
|
+
if (value === void 0 && !field.required)
|
|
12156
|
+
return true;
|
|
12157
|
+
return import_json_logic_js.default.apply(validation.rule, parent);
|
|
12158
|
+
}
|
|
12159
|
+
);
|
|
12160
|
+
}
|
|
12161
|
+
var HANDLEBARS_REGEX = /\{\{([^{}]+)\}\}/g;
|
|
12162
|
+
function replaceHandlebarsTemplates({
|
|
12163
|
+
value: toReplace,
|
|
12164
|
+
logic,
|
|
12165
|
+
formValues,
|
|
12166
|
+
parentID,
|
|
12167
|
+
name: fieldName
|
|
12168
|
+
}) {
|
|
12169
|
+
if (typeof toReplace === "string") {
|
|
12170
|
+
return toReplace.replace(HANDLEBARS_REGEX, (match, key) => {
|
|
12171
|
+
return logic.getScope(parentID).applyComputedValueInField(key.trim(), formValues, fieldName);
|
|
12172
|
+
});
|
|
12173
|
+
} else if (typeof toReplace === "object") {
|
|
12174
|
+
const { value, ...rules } = toReplace;
|
|
12175
|
+
if (Object.keys(rules).length > 1 && !value) {
|
|
12176
|
+
throw Error("Cannot define multiple rules without a template string with key `value`.");
|
|
12177
|
+
}
|
|
12178
|
+
const computedTemplateValue = Object.entries(rules).reduce((prev, [key, rule]) => {
|
|
12179
|
+
const computedValue = logic.getScope(parentID).validate(rule, formValues);
|
|
12180
|
+
return prev.replaceAll(`{{${key}}}`, computedValue);
|
|
12181
|
+
}, value);
|
|
12182
|
+
return computedTemplateValue.replace(/\{\{([^{}]+)\}\}/g, (match, key) => {
|
|
12183
|
+
return logic.getScope(parentID).applyComputedValueInField(key.trim(), formValues, fieldName);
|
|
12184
|
+
});
|
|
12185
|
+
}
|
|
12186
|
+
return toReplace;
|
|
12187
|
+
}
|
|
12188
|
+
function calculateComputedAttributes(fieldParams, { parentID = "root" } = {}) {
|
|
12189
|
+
return ({ logic, isRequired, config, formValues }) => {
|
|
12190
|
+
const { name, computedAttributes } = fieldParams;
|
|
12191
|
+
const attributes = Object.fromEntries(
|
|
12192
|
+
Object.entries(computedAttributes).map(handleComputedAttribute(logic, formValues, parentID, name)).filter(([, value]) => value !== null)
|
|
12182
12193
|
);
|
|
12194
|
+
return {
|
|
12195
|
+
...attributes,
|
|
12196
|
+
schema: buildYupSchema(
|
|
12197
|
+
{ ...fieldParams, ...attributes, required: isRequired },
|
|
12198
|
+
config,
|
|
12199
|
+
logic
|
|
12200
|
+
)
|
|
12201
|
+
};
|
|
12202
|
+
};
|
|
12203
|
+
}
|
|
12204
|
+
function handleComputedAttribute(logic, formValues, parentID, name) {
|
|
12205
|
+
return ([key, value]) => {
|
|
12206
|
+
switch (key) {
|
|
12207
|
+
case "description":
|
|
12208
|
+
return [key, replaceHandlebarsTemplates({ value, logic, formValues, parentID, name })];
|
|
12209
|
+
case "title":
|
|
12210
|
+
return ["label", replaceHandlebarsTemplates({ value, logic, formValues, parentID, name })];
|
|
12211
|
+
case "x-jsf-errorMessage":
|
|
12212
|
+
return [
|
|
12213
|
+
"errorMessage",
|
|
12214
|
+
handleNestedObjectForComputedValues(value, formValues, parentID, logic, name)
|
|
12215
|
+
];
|
|
12216
|
+
case "x-jsf-presentation": {
|
|
12217
|
+
if (value.statement) {
|
|
12218
|
+
return [
|
|
12219
|
+
"statement",
|
|
12220
|
+
handleNestedObjectForComputedValues(value.statement, formValues, parentID, logic, name)
|
|
12221
|
+
];
|
|
12222
|
+
}
|
|
12223
|
+
return [
|
|
12224
|
+
key,
|
|
12225
|
+
handleNestedObjectForComputedValues(value.statement, formValues, parentID, logic, name)
|
|
12226
|
+
];
|
|
12227
|
+
}
|
|
12228
|
+
case "const":
|
|
12229
|
+
default: {
|
|
12230
|
+
if (typeof value === "object" && value.rule) {
|
|
12231
|
+
return [key, logic.getScope(parentID).validate(value.rule, formValues)];
|
|
12232
|
+
}
|
|
12233
|
+
return [key, logic.getScope(parentID).applyComputedValueInField(value, formValues, name)];
|
|
12234
|
+
}
|
|
12235
|
+
}
|
|
12236
|
+
};
|
|
12237
|
+
}
|
|
12238
|
+
function handleNestedObjectForComputedValues(values2, formValues, parentID, logic, name) {
|
|
12239
|
+
return Object.fromEntries(
|
|
12240
|
+
Object.entries(values2).map(([key, value]) => {
|
|
12241
|
+
return [key, replaceHandlebarsTemplates({ value, logic, formValues, parentID, name })];
|
|
12242
|
+
})
|
|
12243
|
+
);
|
|
12244
|
+
}
|
|
12245
|
+
function buildSampleEmptyObject(schema = {}) {
|
|
12246
|
+
const sample = {};
|
|
12247
|
+
if (typeof schema !== "object" || !schema.properties) {
|
|
12248
|
+
return schema;
|
|
12183
12249
|
}
|
|
12184
|
-
|
|
12185
|
-
|
|
12186
|
-
|
|
12187
|
-
|
|
12250
|
+
for (const key in schema.properties) {
|
|
12251
|
+
if (schema.properties[key].type === "object") {
|
|
12252
|
+
sample[key] = buildSampleEmptyObject(schema.properties[key]);
|
|
12253
|
+
} else if (schema.properties[key].type === "array") {
|
|
12254
|
+
const itemSchema = schema.properties[key].items;
|
|
12255
|
+
sample[key] = buildSampleEmptyObject(itemSchema);
|
|
12256
|
+
} else {
|
|
12257
|
+
sample[key] = true;
|
|
12188
12258
|
}
|
|
12189
|
-
return baseSchema;
|
|
12190
12259
|
}
|
|
12191
|
-
|
|
12192
|
-
|
|
12193
|
-
|
|
12194
|
-
|
|
12195
|
-
|
|
12196
|
-
|
|
12260
|
+
return sample;
|
|
12261
|
+
}
|
|
12262
|
+
function validateInlineRules(jsonSchema, sampleEmptyObject) {
|
|
12263
|
+
const properties = (jsonSchema?.properties || jsonSchema?.items?.properties) ?? {};
|
|
12264
|
+
Object.entries(properties).filter(([, property2]) => property2["x-jsf-logic-computedAttrs"] !== void 0).forEach(([fieldName, property2]) => {
|
|
12265
|
+
Object.entries(property2["x-jsf-logic-computedAttrs"]).filter(([, value]) => typeof value === "object").forEach(([key, item]) => {
|
|
12266
|
+
Object.values(item).forEach((rule) => {
|
|
12267
|
+
checkRuleIntegrity(
|
|
12268
|
+
rule,
|
|
12269
|
+
fieldName,
|
|
12270
|
+
sampleEmptyObject,
|
|
12271
|
+
(item2) => `[json-schema-form] json-logic error: fieldName "${item2.var}" doesn't exist in field "${fieldName}.x-jsf-logic-computedAttrs.${key}".`
|
|
12197
12272
|
);
|
|
12273
|
+
});
|
|
12274
|
+
});
|
|
12275
|
+
});
|
|
12276
|
+
}
|
|
12277
|
+
function checkRuleIntegrity(rule, id, data, errorMessage = (item) => `[json-schema-form] json-logic error: rule "${id}" has no variable "${item.var}".`) {
|
|
12278
|
+
Object.entries(rule ?? {}).map(([operator, subRule]) => {
|
|
12279
|
+
if (!Array.isArray(subRule) && subRule !== null && subRule !== void 0)
|
|
12280
|
+
return;
|
|
12281
|
+
throwIfUnknownOperator(operator, subRule, id);
|
|
12282
|
+
subRule.map((item) => {
|
|
12283
|
+
const isVar = item !== null && typeof item === "object" && Object.hasOwn(item, "var");
|
|
12284
|
+
if (isVar) {
|
|
12285
|
+
const exists = import_json_logic_js.default.apply({ var: removeIndicesFromPath(item.var) }, data);
|
|
12286
|
+
if (exists === null) {
|
|
12287
|
+
throw Error(errorMessage(item));
|
|
12288
|
+
}
|
|
12198
12289
|
} else {
|
|
12199
|
-
|
|
12200
|
-
{
|
|
12201
|
-
...fieldSetfield,
|
|
12202
|
-
inputType: fieldSetfield.type
|
|
12203
|
-
},
|
|
12204
|
-
config
|
|
12205
|
-
)();
|
|
12290
|
+
checkRuleIntegrity(item, id, data);
|
|
12206
12291
|
}
|
|
12207
12292
|
});
|
|
12208
|
-
|
|
12209
|
-
|
|
12210
|
-
|
|
12211
|
-
|
|
12212
|
-
|
|
12213
|
-
|
|
12214
|
-
|
|
12215
|
-
|
|
12216
|
-
}
|
|
12217
|
-
|
|
12218
|
-
|
|
12219
|
-
);
|
|
12220
|
-
}
|
|
12221
|
-
const validators = [withBaseSchema];
|
|
12222
|
-
if (inputType === supportedTypes.GROUP_ARRAY) {
|
|
12223
|
-
validators[0] = () => withBaseSchema().of(buildGroupArraySchema());
|
|
12224
|
-
} else if (inputType === supportedTypes.FIELDSET) {
|
|
12225
|
-
validators[0] = () => withBaseSchema().shape(buildFieldSetSchema(propertyFields.fields));
|
|
12226
|
-
}
|
|
12227
|
-
if (propertyFields.required) {
|
|
12228
|
-
validators.push(withRequired);
|
|
12229
|
-
}
|
|
12230
|
-
if (typeof propertyFields.minimum !== "undefined") {
|
|
12231
|
-
validators.push(withMin);
|
|
12232
|
-
}
|
|
12233
|
-
if (typeof propertyFields.minLength !== "undefined") {
|
|
12234
|
-
validators.push(withMinLength);
|
|
12235
|
-
}
|
|
12236
|
-
if (propertyFields.maximum !== void 0) {
|
|
12237
|
-
validators.push(withMax);
|
|
12238
|
-
}
|
|
12239
|
-
if (propertyFields.maxLength) {
|
|
12240
|
-
validators.push(withMaxLength);
|
|
12241
|
-
}
|
|
12242
|
-
if (propertyFields.pattern) {
|
|
12243
|
-
validators.push(withMatches);
|
|
12244
|
-
}
|
|
12245
|
-
if (propertyFields.maxFileSize) {
|
|
12246
|
-
validators.push(withMaxFileSize);
|
|
12247
|
-
}
|
|
12248
|
-
if (propertyFields.accept) {
|
|
12249
|
-
validators.push(withFileFormat);
|
|
12293
|
+
});
|
|
12294
|
+
}
|
|
12295
|
+
function throwIfUnknownOperator(operator, subRule, id) {
|
|
12296
|
+
try {
|
|
12297
|
+
import_json_logic_js.default.apply({ [operator]: subRule });
|
|
12298
|
+
} catch (e) {
|
|
12299
|
+
if (e.message === `Unrecognized operation ${operator}`) {
|
|
12300
|
+
throw Error(
|
|
12301
|
+
`[json-schema-form] json-logic error: in "${id}" rule there is an unknown operator "${operator}".`
|
|
12302
|
+
);
|
|
12303
|
+
}
|
|
12250
12304
|
}
|
|
12251
|
-
|
|
12252
|
-
|
|
12305
|
+
}
|
|
12306
|
+
var regexToGetIndices = /\.\d+\./g;
|
|
12307
|
+
function removeIndicesFromPath(path) {
|
|
12308
|
+
const intermediatePath = path.replace(regexToGetIndices, ".");
|
|
12309
|
+
return intermediatePath.replace(/\.\d+$/, "");
|
|
12310
|
+
}
|
|
12311
|
+
function processJSONLogicNode({
|
|
12312
|
+
node,
|
|
12313
|
+
formFields,
|
|
12314
|
+
formValues,
|
|
12315
|
+
accRequired,
|
|
12316
|
+
parentID,
|
|
12317
|
+
logic
|
|
12318
|
+
}) {
|
|
12319
|
+
const requiredFields = new Set(accRequired);
|
|
12320
|
+
if (node.allOf) {
|
|
12321
|
+
node.allOf.map(
|
|
12322
|
+
(allOfNode) => processJSONLogicNode({ node: allOfNode, formValues, formFields, logic, parentID })
|
|
12323
|
+
).forEach(({ required: allOfItemRequired }) => {
|
|
12324
|
+
allOfItemRequired.forEach(requiredFields.add, requiredFields);
|
|
12325
|
+
});
|
|
12253
12326
|
}
|
|
12254
|
-
if (
|
|
12255
|
-
|
|
12256
|
-
|
|
12327
|
+
if (node.if) {
|
|
12328
|
+
const matchesPropertyCondition = checkIfConditionMatchesProperties(
|
|
12329
|
+
node,
|
|
12330
|
+
formValues,
|
|
12331
|
+
formFields,
|
|
12332
|
+
logic
|
|
12257
12333
|
);
|
|
12258
|
-
|
|
12259
|
-
|
|
12260
|
-
|
|
12261
|
-
|
|
12262
|
-
|
|
12263
|
-
if (field.noSortEdges) {
|
|
12264
|
-
list.push(field.name);
|
|
12334
|
+
const matchesValidationsAndComputedValues = matchesPropertyCondition && checkIfMatchesValidationsAndComputedValues(node, formValues, logic, parentID);
|
|
12335
|
+
const isConditionMatch = matchesPropertyCondition && matchesValidationsAndComputedValues;
|
|
12336
|
+
let nextNode;
|
|
12337
|
+
if (isConditionMatch && node.then) {
|
|
12338
|
+
nextNode = node.then;
|
|
12265
12339
|
}
|
|
12266
|
-
|
|
12267
|
-
|
|
12268
|
-
}
|
|
12269
|
-
function getSchema(fields = [], config) {
|
|
12270
|
-
const newSchema = {};
|
|
12271
|
-
fields.forEach((field) => {
|
|
12272
|
-
if (field.schema) {
|
|
12273
|
-
if (field.name) {
|
|
12274
|
-
if (field.inputType === supportedTypes.FIELDSET) {
|
|
12275
|
-
const fieldsetSchema = buildYupSchema(field, config)();
|
|
12276
|
-
newSchema[field.name] = fieldsetSchema;
|
|
12277
|
-
} else {
|
|
12278
|
-
newSchema[field.name] = field.schema;
|
|
12279
|
-
}
|
|
12280
|
-
} else {
|
|
12281
|
-
Object.assign(newSchema, getSchema(field.fields, config));
|
|
12282
|
-
}
|
|
12340
|
+
if (!isConditionMatch && node.else) {
|
|
12341
|
+
nextNode = node.else;
|
|
12283
12342
|
}
|
|
12284
|
-
|
|
12285
|
-
|
|
12286
|
-
|
|
12287
|
-
|
|
12288
|
-
|
|
12343
|
+
if (nextNode) {
|
|
12344
|
+
const { required: branchRequired } = processNode({
|
|
12345
|
+
node: nextNode,
|
|
12346
|
+
formValues,
|
|
12347
|
+
formFields,
|
|
12348
|
+
accRequired,
|
|
12349
|
+
logic,
|
|
12350
|
+
parentID
|
|
12351
|
+
});
|
|
12352
|
+
branchRequired.forEach((field) => requiredFields.add(field));
|
|
12353
|
+
}
|
|
12354
|
+
}
|
|
12355
|
+
return { required: requiredFields };
|
|
12289
12356
|
}
|
|
12290
12357
|
|
|
12291
12358
|
// src/helpers.js
|
|
@@ -12404,7 +12471,11 @@ function updateField(field, requiredFields, node, formValues, logic, config) {
|
|
|
12404
12471
|
updateValues(computedFieldValues);
|
|
12405
12472
|
}
|
|
12406
12473
|
if (field.calculateConditionalProperties) {
|
|
12407
|
-
const newFieldValues = field.calculateConditionalProperties(
|
|
12474
|
+
const newFieldValues = field.calculateConditionalProperties({
|
|
12475
|
+
isRequired: fieldIsRequired,
|
|
12476
|
+
conditionBranch: node,
|
|
12477
|
+
formValues
|
|
12478
|
+
});
|
|
12408
12479
|
updateValues(newFieldValues);
|
|
12409
12480
|
}
|
|
12410
12481
|
if (field.calculateCustomValidationProperties) {
|
|
@@ -12436,7 +12507,7 @@ function processNode({
|
|
|
12436
12507
|
});
|
|
12437
12508
|
});
|
|
12438
12509
|
if (node.if) {
|
|
12439
|
-
const matchesCondition =
|
|
12510
|
+
const matchesCondition = checkIfConditionMatchesProperties(node, formValues, formFields, logic);
|
|
12440
12511
|
if (matchesCondition && node.then) {
|
|
12441
12512
|
const { required: branchRequired } = processNode({
|
|
12442
12513
|
node: node.then,
|
|
@@ -12499,6 +12570,17 @@ function processNode({
|
|
|
12499
12570
|
}
|
|
12500
12571
|
});
|
|
12501
12572
|
}
|
|
12573
|
+
if (node["x-jsf-logic"]) {
|
|
12574
|
+
const { required: requiredFromLogic } = processJSONLogicNode({
|
|
12575
|
+
node: node["x-jsf-logic"],
|
|
12576
|
+
formValues,
|
|
12577
|
+
formFields,
|
|
12578
|
+
accRequired: requiredFields,
|
|
12579
|
+
parentID,
|
|
12580
|
+
logic
|
|
12581
|
+
});
|
|
12582
|
+
requiredFromLogic.forEach((field) => requiredFields.add(field));
|
|
12583
|
+
}
|
|
12502
12584
|
return {
|
|
12503
12585
|
required: requiredFields
|
|
12504
12586
|
};
|
|
@@ -12560,7 +12642,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
12560
12642
|
}
|
|
12561
12643
|
const presentation = pickXKey(schemaNode, "presentation") ?? {};
|
|
12562
12644
|
const errorMessage = pickXKey(schemaNode, "errorMessage") ?? {};
|
|
12563
|
-
const
|
|
12645
|
+
const jsonLogicValidations = schemaNode["x-jsf-logic-validations"];
|
|
12564
12646
|
const computedAttributes = schemaNode["x-jsf-logic-computedAttrs"];
|
|
12565
12647
|
const decoratedComputedAttributes = getDecoratedComputedAttributes(computedAttributes);
|
|
12566
12648
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
@@ -12604,7 +12686,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
12604
12686
|
},
|
|
12605
12687
|
// Handle [name].presentation
|
|
12606
12688
|
...presentation,
|
|
12607
|
-
|
|
12689
|
+
jsonLogicValidations,
|
|
12608
12690
|
computedAttributes: decoratedComputedAttributes,
|
|
12609
12691
|
description: containsHTML(description) ? wrapWithSpan(description, {
|
|
12610
12692
|
class: "jsf-description"
|
|
@@ -12704,8 +12786,8 @@ function rebuildFieldset(fields, property2) {
|
|
|
12704
12786
|
required: isFieldRequired(property2, field)
|
|
12705
12787
|
}));
|
|
12706
12788
|
}
|
|
12707
|
-
function calculateConditionalProperties(fieldParams, customProperties) {
|
|
12708
|
-
return (isRequired, conditionBranch) => {
|
|
12789
|
+
function calculateConditionalProperties({ fieldParams, customProperties, logic, config }) {
|
|
12790
|
+
return ({ isRequired, conditionBranch, formValues }) => {
|
|
12709
12791
|
const conditionalProperty = conditionBranch?.properties?.[fieldParams.name];
|
|
12710
12792
|
if (conditionalProperty) {
|
|
12711
12793
|
const presentation = pickXKey(conditionalProperty, "presentation") ?? {};
|
|
@@ -12719,17 +12801,31 @@ function calculateConditionalProperties(fieldParams, customProperties) {
|
|
|
12719
12801
|
fieldSetFields = rebuildFieldset(fieldParams.fields, conditionalProperty);
|
|
12720
12802
|
newFieldParams.fields = fieldSetFields;
|
|
12721
12803
|
}
|
|
12804
|
+
const { computedAttributes, ...restNewFieldParams } = newFieldParams;
|
|
12805
|
+
const calculatedComputedAttributes = computedAttributes ? calculateComputedAttributes(newFieldParams, config)({ logic, formValues }) : {};
|
|
12806
|
+
const jsonLogicValidations = [
|
|
12807
|
+
...fieldParams.jsonLogicValidations ?? [],
|
|
12808
|
+
...restNewFieldParams.jsonLogicValidations ?? []
|
|
12809
|
+
];
|
|
12722
12810
|
const base = {
|
|
12723
12811
|
isVisible: true,
|
|
12724
12812
|
required: isRequired,
|
|
12725
12813
|
...presentation?.inputType && { type: presentation.inputType },
|
|
12726
|
-
|
|
12727
|
-
|
|
12728
|
-
|
|
12729
|
-
|
|
12730
|
-
|
|
12731
|
-
|
|
12732
|
-
|
|
12814
|
+
...calculatedComputedAttributes,
|
|
12815
|
+
...calculatedComputedAttributes.value ? { value: calculatedComputedAttributes.value } : { value: void 0 },
|
|
12816
|
+
schema: buildYupSchema(
|
|
12817
|
+
{
|
|
12818
|
+
...fieldParams,
|
|
12819
|
+
...restNewFieldParams,
|
|
12820
|
+
...calculatedComputedAttributes,
|
|
12821
|
+
jsonLogicValidations,
|
|
12822
|
+
// If there are inner fields (case of fieldset) they need to be updated based on the condition
|
|
12823
|
+
fields: fieldSetFields,
|
|
12824
|
+
required: isRequired
|
|
12825
|
+
},
|
|
12826
|
+
config,
|
|
12827
|
+
logic
|
|
12828
|
+
)
|
|
12733
12829
|
};
|
|
12734
12830
|
return (0, import_omit2.default)((0, import_merge2.default)(base, presentation, newFieldParams), ["inputType"]);
|
|
12735
12831
|
}
|
|
@@ -12823,14 +12919,19 @@ function sortByOrderOrPosition(a, b, order) {
|
|
|
12823
12919
|
function removeInvalidAttributes(fields) {
|
|
12824
12920
|
return (0, import_omit3.default)(fields, ["items", "maxFileSize", "isDynamic"]);
|
|
12825
12921
|
}
|
|
12826
|
-
function buildFieldParameters(name, fieldProperties, required2 = [], config = {}) {
|
|
12922
|
+
function buildFieldParameters(name, fieldProperties, required2 = [], config = {}, logic) {
|
|
12827
12923
|
const { position } = pickXKey(fieldProperties, "presentation") ?? {};
|
|
12828
12924
|
let fields;
|
|
12829
12925
|
const inputType = getInputType(fieldProperties, config.strictInputType, name);
|
|
12830
12926
|
if (inputType === supportedTypes.FIELDSET) {
|
|
12831
|
-
fields = getFieldsFromJSONSchema(
|
|
12832
|
-
|
|
12833
|
-
|
|
12927
|
+
fields = getFieldsFromJSONSchema(
|
|
12928
|
+
fieldProperties,
|
|
12929
|
+
{
|
|
12930
|
+
customProperties: (0, import_get4.default)(config, `customProperties.${name}`, {}),
|
|
12931
|
+
parentID: name
|
|
12932
|
+
},
|
|
12933
|
+
logic
|
|
12934
|
+
);
|
|
12834
12935
|
}
|
|
12835
12936
|
const result = {
|
|
12836
12937
|
name,
|
|
@@ -12887,7 +12988,7 @@ function buildField(fieldParams, config, scopedJsonSchema, logic) {
|
|
|
12887
12988
|
const customProperties = getCustomPropertiesForField(fieldParams, config);
|
|
12888
12989
|
const composeFn = getComposeFunctionForField(fieldParams, !!customProperties);
|
|
12889
12990
|
const yupSchema = buildYupSchema(fieldParams, config, logic);
|
|
12890
|
-
const calculateConditionalFieldsClosure = fieldParams.isDynamic && calculateConditionalProperties(fieldParams, customProperties);
|
|
12991
|
+
const calculateConditionalFieldsClosure = fieldParams.isDynamic && calculateConditionalProperties({ fieldParams, customProperties, logic, config });
|
|
12891
12992
|
const calculateCustomValidationPropertiesClosure = calculateCustomValidationProperties(
|
|
12892
12993
|
fieldParams,
|
|
12893
12994
|
customProperties
|