tp-react-elements-dev 0.3.0 → 0.4.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/dist/index.js CHANGED
@@ -13174,7 +13174,7 @@ function createFilterOptions(config = {}) {
13174
13174
  }
13175
13175
 
13176
13176
  // To replace with .findIndex() once we stop IE11 support.
13177
- function findIndex$1(array, comp) {
13177
+ function findIndex$2(array, comp) {
13178
13178
  for (let i = 0; i < array.length; i += 1) {
13179
13179
  if (comp(array[i])) {
13180
13180
  return i;
@@ -13522,7 +13522,7 @@ function useAutocomplete(props) {
13522
13522
  if (highlightedIndexRef.current !== -1 && previousProps.filteredOptions && previousProps.filteredOptions.length !== filteredOptions.length && previousProps.inputValue === inputValue && (multiple ? value.length === previousProps.value.length && previousProps.value.every((val, i) => getOptionLabel(value[i]) === getOptionLabel(val)) : isSameValue(previousProps.value, value))) {
13523
13523
  const previousHighlightedOption = previousProps.filteredOptions[highlightedIndexRef.current];
13524
13524
  if (previousHighlightedOption) {
13525
- return findIndex$1(filteredOptions, option => {
13525
+ return findIndex$2(filteredOptions, option => {
13526
13526
  return getOptionLabel(option) === getOptionLabel(previousHighlightedOption);
13527
13527
  });
13528
13528
  }
@@ -13559,10 +13559,10 @@ function useAutocomplete(props) {
13559
13559
  const currentOption = filteredOptions[highlightedIndexRef.current];
13560
13560
 
13561
13561
  // Keep the current highlighted index if possible
13562
- if (multiple && currentOption && findIndex$1(value, val => isOptionEqualToValue(currentOption, val)) !== -1) {
13562
+ if (multiple && currentOption && findIndex$2(value, val => isOptionEqualToValue(currentOption, val)) !== -1) {
13563
13563
  return;
13564
13564
  }
13565
- const itemIndex = findIndex$1(filteredOptions, optionItem => isOptionEqualToValue(optionItem, valueItem));
13565
+ const itemIndex = findIndex$2(filteredOptions, optionItem => isOptionEqualToValue(optionItem, valueItem));
13566
13566
  if (itemIndex === -1) {
13567
13567
  changeHighlightedIndex({
13568
13568
  diff: 'reset'
@@ -13661,7 +13661,7 @@ function useAutocomplete(props) {
13661
13661
  console.error([`MUI: The \`isOptionEqualToValue\` method of ${componentName} does not handle the arguments correctly.`, `The component expects a single value to match a given option but found ${matches.length} matches.`].join('\n'));
13662
13662
  }
13663
13663
  }
13664
- const itemIndex = findIndex$1(newValue, valueItem => isOptionEqualToValue(option, valueItem));
13664
+ const itemIndex = findIndex$2(newValue, valueItem => isOptionEqualToValue(option, valueItem));
13665
13665
  if (itemIndex === -1) {
13666
13666
  newValue.push(option);
13667
13667
  } else if (origin !== 'freeSolo') {
@@ -23380,12 +23380,12 @@ var isDateObject = (value) => value instanceof Date;
23380
23380
  var isNullOrUndefined = (value) => value == null;
23381
23381
 
23382
23382
  const isObjectType = (value) => typeof value === 'object';
23383
- var isObject = (value) => !isNullOrUndefined(value) &&
23383
+ var isObject$1 = (value) => !isNullOrUndefined(value) &&
23384
23384
  !Array.isArray(value) &&
23385
23385
  isObjectType(value) &&
23386
23386
  !isDateObject(value);
23387
23387
 
23388
- var getEventValue = (event) => isObject(event) && event.target
23388
+ var getEventValue = (event) => isObject$1(event) && event.target
23389
23389
  ? isCheckBoxInput(event.target)
23390
23390
  ? event.target.checked
23391
23391
  : event.target.value
@@ -23397,7 +23397,7 @@ var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
23397
23397
 
23398
23398
  var isPlainObject = (tempObject) => {
23399
23399
  const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
23400
- return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
23400
+ return (isObject$1(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
23401
23401
  };
23402
23402
 
23403
23403
  var isWeb = typeof window !== 'undefined' &&
@@ -23414,7 +23414,7 @@ function cloneObject(data) {
23414
23414
  copy = new Set(data);
23415
23415
  }
23416
23416
  else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
23417
- (isArray || isObject(data))) {
23417
+ (isArray || isObject$1(data))) {
23418
23418
  copy = isArray ? [] : {};
23419
23419
  if (!isArray && !isPlainObject(data)) {
23420
23420
  copy = data;
@@ -23438,7 +23438,7 @@ var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
23438
23438
  var isUndefined = (val) => val === undefined;
23439
23439
 
23440
23440
  var get = (object, path, defaultValue) => {
23441
- if (!path || !isObject(object)) {
23441
+ if (!path || !isObject$1(object)) {
23442
23442
  return defaultValue;
23443
23443
  }
23444
23444
  const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], object);
@@ -23466,7 +23466,7 @@ var set = (object, path, value) => {
23466
23466
  if (index !== lastIndex) {
23467
23467
  const objValue = object[key];
23468
23468
  newValue =
23469
- isObject(objValue) || Array.isArray(objValue)
23469
+ isObject$1(objValue) || Array.isArray(objValue)
23470
23470
  ? objValue
23471
23471
  : !isNaN(+tempPath[index + 1])
23472
23472
  ? []
@@ -23546,7 +23546,7 @@ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true)
23546
23546
  return result;
23547
23547
  };
23548
23548
 
23549
- var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
23549
+ var isEmptyObject = (value) => isObject$1(value) && !Object.keys(value).length;
23550
23550
 
23551
23551
  var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
23552
23552
  updateFormState(formStateData);
@@ -42201,7 +42201,7 @@ function isSameDay(dateLeft, dateRight) {
42201
42201
  * const result = isDate({})
42202
42202
  * //=> false
42203
42203
  */
42204
- function isDate(value) {
42204
+ function isDate$1(value) {
42205
42205
  return (
42206
42206
  value instanceof Date ||
42207
42207
  (typeof value === "object" &&
@@ -42243,7 +42243,7 @@ function isDate(value) {
42243
42243
  * //=> false
42244
42244
  */
42245
42245
  function isValid(date) {
42246
- if (!isDate(date) && typeof date !== "number") {
42246
+ if (!isDate$1(date) && typeof date !== "number") {
42247
42247
  return false;
42248
42248
  }
42249
42249
  const _date = toDate(date);
@@ -42873,7 +42873,7 @@ function buildMatchFn(args) {
42873
42873
  args.parsePatterns[args.defaultParseWidth];
42874
42874
 
42875
42875
  const key = Array.isArray(parsePatterns)
42876
- ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString))
42876
+ ? findIndex$1(parsePatterns, (pattern) => pattern.test(matchedString))
42877
42877
  : // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type
42878
42878
  findKey(parsePatterns, (pattern) => pattern.test(matchedString));
42879
42879
 
@@ -42903,7 +42903,7 @@ function findKey(object, predicate) {
42903
42903
  return undefined;
42904
42904
  }
42905
42905
 
42906
- function findIndex(array, predicate) {
42906
+ function findIndex$1(array, predicate) {
42907
42907
  for (let key = 0; key < array.length; key++) {
42908
42908
  if (predicate(array[key])) {
42909
42909
  return key;
@@ -45914,7 +45914,7 @@ function createRule(name, decl, options) {
45914
45914
  return null;
45915
45915
  }
45916
45916
 
45917
- var join = function join(value, by) {
45917
+ var join$1 = function join(value, by) {
45918
45918
  var result = '';
45919
45919
 
45920
45920
  for (var i = 0; i < value.length; i++) {
@@ -45944,9 +45944,9 @@ var toCssValue = function toCssValue(value) {
45944
45944
  for (var i = 0; i < value.length; i++) {
45945
45945
  if (value[i] === '!important') break;
45946
45946
  if (cssValue) cssValue += ', ';
45947
- cssValue += join(value[i], ' ');
45947
+ cssValue += join$1(value[i], ' ');
45948
45948
  }
45949
- } else cssValue = join(value, ', '); // Add !important, because it was ignored.
45949
+ } else cssValue = join$1(value, ', '); // Add !important, because it was ignored.
45950
45950
 
45951
45951
 
45952
45952
  if (value[value.length - 1] === '!important') {
@@ -48482,7 +48482,7 @@ function convertCase(style) {
48482
48482
  */
48483
48483
 
48484
48484
 
48485
- function camelCase() {
48485
+ function camelCase$1() {
48486
48486
  function onProcessStyle(style) {
48487
48487
  if (Array.isArray(style)) {
48488
48488
  // Handle rules like @font-face, which can have multiple styles in an array
@@ -49445,7 +49445,7 @@ function jssPropsSort() {
49445
49445
  // Subset of jss-preset-default with only the plugins the MUI components are using.
49446
49446
  function jssPreset() {
49447
49447
  return {
49448
- plugins: [functionPlugin(), jssGlobal(), jssNested(), camelCase(), defaultUnit(),
49448
+ plugins: [functionPlugin(), jssGlobal(), jssNested(), camelCase$1(), defaultUnit(),
49449
49449
  // Disable the vendor prefixer server-side, it does nothing.
49450
49450
  // This way, we can get a performance boost.
49451
49451
  // In the documentation, we are using `autoprefixer` to solve this problem.
@@ -50765,6 +50765,2334 @@ const FormRenderWrapper = ({ formArray, name, numberOfColumns = 3, form, }) => {
50765
50765
  }) })) })));
50766
50766
  };
50767
50767
 
50768
+ /**
50769
+ * Based on Kendo UI Core expression code <https://github.com/telerik/kendo-ui-core#license-information>
50770
+ */
50771
+
50772
+ function Cache(maxSize) {
50773
+ this._maxSize = maxSize;
50774
+ this.clear();
50775
+ }
50776
+ Cache.prototype.clear = function () {
50777
+ this._size = 0;
50778
+ this._values = Object.create(null);
50779
+ };
50780
+ Cache.prototype.get = function (key) {
50781
+ return this._values[key]
50782
+ };
50783
+ Cache.prototype.set = function (key, value) {
50784
+ this._size >= this._maxSize && this.clear();
50785
+ if (!(key in this._values)) this._size++;
50786
+
50787
+ return (this._values[key] = value)
50788
+ };
50789
+
50790
+ var SPLIT_REGEX = /[^.^\]^[]+|(?=\[\]|\.\.)/g,
50791
+ DIGIT_REGEX = /^\d+$/,
50792
+ LEAD_DIGIT_REGEX = /^\d/,
50793
+ SPEC_CHAR_REGEX = /[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g,
50794
+ CLEAN_QUOTES_REGEX = /^\s*(['"]?)(.*?)(\1)\s*$/,
50795
+ MAX_CACHE_SIZE = 512;
50796
+
50797
+ var pathCache = new Cache(MAX_CACHE_SIZE),
50798
+ setCache = new Cache(MAX_CACHE_SIZE),
50799
+ getCache = new Cache(MAX_CACHE_SIZE);
50800
+
50801
+ var propertyExpr = {
50802
+ Cache: Cache,
50803
+
50804
+ split: split,
50805
+
50806
+ normalizePath: normalizePath,
50807
+
50808
+ setter: function (path) {
50809
+ var parts = normalizePath(path);
50810
+
50811
+ return (
50812
+ setCache.get(path) ||
50813
+ setCache.set(path, function setter(obj, value) {
50814
+ var index = 0;
50815
+ var len = parts.length;
50816
+ var data = obj;
50817
+
50818
+ while (index < len - 1) {
50819
+ var part = parts[index];
50820
+ if (
50821
+ part === '__proto__' ||
50822
+ part === 'constructor' ||
50823
+ part === 'prototype'
50824
+ ) {
50825
+ return obj
50826
+ }
50827
+
50828
+ data = data[parts[index++]];
50829
+ }
50830
+ data[parts[index]] = value;
50831
+ })
50832
+ )
50833
+ },
50834
+
50835
+ getter: function (path, safe) {
50836
+ var parts = normalizePath(path);
50837
+ return (
50838
+ getCache.get(path) ||
50839
+ getCache.set(path, function getter(data) {
50840
+ var index = 0,
50841
+ len = parts.length;
50842
+ while (index < len) {
50843
+ if (data != null || !safe) data = data[parts[index++]];
50844
+ else return
50845
+ }
50846
+ return data
50847
+ })
50848
+ )
50849
+ },
50850
+
50851
+ join: function (segments) {
50852
+ return segments.reduce(function (path, part) {
50853
+ return (
50854
+ path +
50855
+ (isQuoted(part) || DIGIT_REGEX.test(part)
50856
+ ? '[' + part + ']'
50857
+ : (path ? '.' : '') + part)
50858
+ )
50859
+ }, '')
50860
+ },
50861
+
50862
+ forEach: function (path, cb, thisArg) {
50863
+ forEach(Array.isArray(path) ? path : split(path), cb, thisArg);
50864
+ },
50865
+ };
50866
+
50867
+ function normalizePath(path) {
50868
+ return (
50869
+ pathCache.get(path) ||
50870
+ pathCache.set(
50871
+ path,
50872
+ split(path).map(function (part) {
50873
+ return part.replace(CLEAN_QUOTES_REGEX, '$2')
50874
+ })
50875
+ )
50876
+ )
50877
+ }
50878
+
50879
+ function split(path) {
50880
+ return path.match(SPLIT_REGEX) || ['']
50881
+ }
50882
+
50883
+ function forEach(parts, iter, thisArg) {
50884
+ var len = parts.length,
50885
+ part,
50886
+ idx,
50887
+ isArray,
50888
+ isBracket;
50889
+
50890
+ for (idx = 0; idx < len; idx++) {
50891
+ part = parts[idx];
50892
+
50893
+ if (part) {
50894
+ if (shouldBeQuoted(part)) {
50895
+ part = '"' + part + '"';
50896
+ }
50897
+
50898
+ isBracket = isQuoted(part);
50899
+ isArray = !isBracket && /^\d+$/.test(part);
50900
+
50901
+ iter.call(thisArg, part, isBracket, isArray, idx, parts);
50902
+ }
50903
+ }
50904
+ }
50905
+
50906
+ function isQuoted(str) {
50907
+ return (
50908
+ typeof str === 'string' && str && ["'", '"'].indexOf(str.charAt(0)) !== -1
50909
+ )
50910
+ }
50911
+
50912
+ function hasLeadingNumber(part) {
50913
+ return part.match(LEAD_DIGIT_REGEX) && !part.match(DIGIT_REGEX)
50914
+ }
50915
+
50916
+ function hasSpecialChars(part) {
50917
+ return SPEC_CHAR_REGEX.test(part)
50918
+ }
50919
+
50920
+ function shouldBeQuoted(part) {
50921
+ return !isQuoted(part) && (hasLeadingNumber(part) || hasSpecialChars(part))
50922
+ }
50923
+
50924
+ const reWords = /[A-Z\xc0-\xd6\xd8-\xde]?[a-z\xdf-\xf6\xf8-\xff]+(?:['’](?:d|ll|m|re|s|t|ve))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde]|$)|(?:[A-Z\xc0-\xd6\xd8-\xde]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:D|LL|M|RE|S|T|VE))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde](?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])|$)|[A-Z\xc0-\xd6\xd8-\xde]?(?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:d|ll|m|re|s|t|ve))?|[A-Z\xc0-\xd6\xd8-\xde]+(?:['’](?:D|LL|M|RE|S|T|VE))?|\d*(?:1ST|2ND|3RD|(?![123])\dTH)(?=\b|[a-z_])|\d*(?:1st|2nd|3rd|(?![123])\dth)(?=\b|[A-Z_])|\d+|(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?)*/g;
50925
+
50926
+ const words = (str) => str.match(reWords) || [];
50927
+
50928
+ const upperFirst = (str) => str[0].toUpperCase() + str.slice(1);
50929
+
50930
+ const join = (str, d) => words(str).join(d).toLowerCase();
50931
+
50932
+ const camelCase = (str) =>
50933
+ words(str).reduce(
50934
+ (acc, next) =>
50935
+ `${acc}${
50936
+ !acc
50937
+ ? next.toLowerCase()
50938
+ : next[0].toUpperCase() + next.slice(1).toLowerCase()
50939
+ }`,
50940
+ '',
50941
+ );
50942
+
50943
+ const pascalCase = (str) => upperFirst(camelCase(str));
50944
+
50945
+ const snakeCase = (str) => join(str, '_');
50946
+
50947
+ const kebabCase = (str) => join(str, '-');
50948
+
50949
+ const sentenceCase = (str) => upperFirst(join(str, ' '));
50950
+
50951
+ const titleCase = (str) => words(str).map(upperFirst).join(' ');
50952
+
50953
+ var tinyCase = {
50954
+ words,
50955
+ upperFirst,
50956
+ camelCase,
50957
+ pascalCase,
50958
+ snakeCase,
50959
+ kebabCase,
50960
+ sentenceCase,
50961
+ titleCase,
50962
+ };
50963
+
50964
+ var toposort$2 = {exports: {}};
50965
+
50966
+ /**
50967
+ * Topological sorting function
50968
+ *
50969
+ * @param {Array} edges
50970
+ * @returns {Array}
50971
+ */
50972
+
50973
+ toposort$2.exports = function(edges) {
50974
+ return toposort(uniqueNodes(edges), edges)
50975
+ };
50976
+
50977
+ toposort$2.exports.array = toposort;
50978
+
50979
+ function toposort(nodes, edges) {
50980
+ var cursor = nodes.length
50981
+ , sorted = new Array(cursor)
50982
+ , visited = {}
50983
+ , i = cursor
50984
+ // Better data structures make algorithm much faster.
50985
+ , outgoingEdges = makeOutgoingEdges(edges)
50986
+ , nodesHash = makeNodesHash(nodes);
50987
+
50988
+ // check for unknown nodes
50989
+ edges.forEach(function(edge) {
50990
+ if (!nodesHash.has(edge[0]) || !nodesHash.has(edge[1])) {
50991
+ throw new Error('Unknown node. There is an unknown node in the supplied edges.')
50992
+ }
50993
+ });
50994
+
50995
+ while (i--) {
50996
+ if (!visited[i]) visit(nodes[i], i, new Set());
50997
+ }
50998
+
50999
+ return sorted
51000
+
51001
+ function visit(node, i, predecessors) {
51002
+ if(predecessors.has(node)) {
51003
+ var nodeRep;
51004
+ try {
51005
+ nodeRep = ", node was:" + JSON.stringify(node);
51006
+ } catch(e) {
51007
+ nodeRep = "";
51008
+ }
51009
+ throw new Error('Cyclic dependency' + nodeRep)
51010
+ }
51011
+
51012
+ if (!nodesHash.has(node)) {
51013
+ throw new Error('Found unknown node. Make sure to provided all involved nodes. Unknown node: '+JSON.stringify(node))
51014
+ }
51015
+
51016
+ if (visited[i]) return;
51017
+ visited[i] = true;
51018
+
51019
+ var outgoing = outgoingEdges.get(node) || new Set();
51020
+ outgoing = Array.from(outgoing);
51021
+
51022
+ if (i = outgoing.length) {
51023
+ predecessors.add(node);
51024
+ do {
51025
+ var child = outgoing[--i];
51026
+ visit(child, nodesHash.get(child), predecessors);
51027
+ } while (i)
51028
+ predecessors.delete(node);
51029
+ }
51030
+
51031
+ sorted[--cursor] = node;
51032
+ }
51033
+ }
51034
+
51035
+ function uniqueNodes(arr){
51036
+ var res = new Set();
51037
+ for (var i = 0, len = arr.length; i < len; i++) {
51038
+ var edge = arr[i];
51039
+ res.add(edge[0]);
51040
+ res.add(edge[1]);
51041
+ }
51042
+ return Array.from(res)
51043
+ }
51044
+
51045
+ function makeOutgoingEdges(arr){
51046
+ var edges = new Map();
51047
+ for (var i = 0, len = arr.length; i < len; i++) {
51048
+ var edge = arr[i];
51049
+ if (!edges.has(edge[0])) edges.set(edge[0], new Set());
51050
+ if (!edges.has(edge[1])) edges.set(edge[1], new Set());
51051
+ edges.get(edge[0]).add(edge[1]);
51052
+ }
51053
+ return edges
51054
+ }
51055
+
51056
+ function makeNodesHash(arr){
51057
+ var res = new Map();
51058
+ for (var i = 0, len = arr.length; i < len; i++) {
51059
+ res.set(arr[i], i);
51060
+ }
51061
+ return res
51062
+ }
51063
+
51064
+ var toposortExports = toposort$2.exports;
51065
+ var toposort$1 = /*@__PURE__*/getDefaultExportFromCjs(toposortExports);
51066
+
51067
+ const toString = Object.prototype.toString;
51068
+ const errorToString = Error.prototype.toString;
51069
+ const regExpToString = RegExp.prototype.toString;
51070
+ const symbolToString = typeof Symbol !== 'undefined' ? Symbol.prototype.toString : () => '';
51071
+ const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
51072
+ function printNumber(val) {
51073
+ if (val != +val) return 'NaN';
51074
+ const isNegativeZero = val === 0 && 1 / val < 0;
51075
+ return isNegativeZero ? '-0' : '' + val;
51076
+ }
51077
+ function printSimpleValue(val, quoteStrings = false) {
51078
+ if (val == null || val === true || val === false) return '' + val;
51079
+ const typeOf = typeof val;
51080
+ if (typeOf === 'number') return printNumber(val);
51081
+ if (typeOf === 'string') return quoteStrings ? `"${val}"` : val;
51082
+ if (typeOf === 'function') return '[Function ' + (val.name || 'anonymous') + ']';
51083
+ if (typeOf === 'symbol') return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)');
51084
+ const tag = toString.call(val).slice(8, -1);
51085
+ if (tag === 'Date') return isNaN(val.getTime()) ? '' + val : val.toISOString(val);
51086
+ if (tag === 'Error' || val instanceof Error) return '[' + errorToString.call(val) + ']';
51087
+ if (tag === 'RegExp') return regExpToString.call(val);
51088
+ return null;
51089
+ }
51090
+ function printValue(value, quoteStrings) {
51091
+ let result = printSimpleValue(value, quoteStrings);
51092
+ if (result !== null) return result;
51093
+ return JSON.stringify(value, function (key, value) {
51094
+ let result = printSimpleValue(this[key], quoteStrings);
51095
+ if (result !== null) return result;
51096
+ return value;
51097
+ }, 2);
51098
+ }
51099
+
51100
+ function toArray(value) {
51101
+ return value == null ? [] : [].concat(value);
51102
+ }
51103
+
51104
+ let _Symbol$toStringTag, _Symbol$hasInstance, _Symbol$toStringTag2;
51105
+ let strReg = /\$\{\s*(\w+)\s*\}/g;
51106
+ _Symbol$toStringTag = Symbol.toStringTag;
51107
+ class ValidationErrorNoStack {
51108
+ constructor(errorOrErrors, value, field, type) {
51109
+ this.name = void 0;
51110
+ this.message = void 0;
51111
+ this.value = void 0;
51112
+ this.path = void 0;
51113
+ this.type = void 0;
51114
+ this.params = void 0;
51115
+ this.errors = void 0;
51116
+ this.inner = void 0;
51117
+ this[_Symbol$toStringTag] = 'Error';
51118
+ this.name = 'ValidationError';
51119
+ this.value = value;
51120
+ this.path = field;
51121
+ this.type = type;
51122
+ this.errors = [];
51123
+ this.inner = [];
51124
+ toArray(errorOrErrors).forEach(err => {
51125
+ if (ValidationError.isError(err)) {
51126
+ this.errors.push(...err.errors);
51127
+ const innerErrors = err.inner.length ? err.inner : [err];
51128
+ this.inner.push(...innerErrors);
51129
+ } else {
51130
+ this.errors.push(err);
51131
+ }
51132
+ });
51133
+ this.message = this.errors.length > 1 ? `${this.errors.length} errors occurred` : this.errors[0];
51134
+ }
51135
+ }
51136
+ _Symbol$hasInstance = Symbol.hasInstance;
51137
+ _Symbol$toStringTag2 = Symbol.toStringTag;
51138
+ class ValidationError extends Error {
51139
+ static formatError(message, params) {
51140
+ const path = params.label || params.path || 'this';
51141
+ if (path !== params.path) params = Object.assign({}, params, {
51142
+ path
51143
+ });
51144
+ if (typeof message === 'string') return message.replace(strReg, (_, key) => printValue(params[key]));
51145
+ if (typeof message === 'function') return message(params);
51146
+ return message;
51147
+ }
51148
+ static isError(err) {
51149
+ return err && err.name === 'ValidationError';
51150
+ }
51151
+ constructor(errorOrErrors, value, field, type, disableStack) {
51152
+ const errorNoStack = new ValidationErrorNoStack(errorOrErrors, value, field, type);
51153
+ if (disableStack) {
51154
+ return errorNoStack;
51155
+ }
51156
+ super();
51157
+ this.value = void 0;
51158
+ this.path = void 0;
51159
+ this.type = void 0;
51160
+ this.params = void 0;
51161
+ this.errors = [];
51162
+ this.inner = [];
51163
+ this[_Symbol$toStringTag2] = 'Error';
51164
+ this.name = errorNoStack.name;
51165
+ this.message = errorNoStack.message;
51166
+ this.type = errorNoStack.type;
51167
+ this.value = errorNoStack.value;
51168
+ this.path = errorNoStack.path;
51169
+ this.errors = errorNoStack.errors;
51170
+ this.inner = errorNoStack.inner;
51171
+ if (Error.captureStackTrace) {
51172
+ Error.captureStackTrace(this, ValidationError);
51173
+ }
51174
+ }
51175
+ static [_Symbol$hasInstance](inst) {
51176
+ return ValidationErrorNoStack[Symbol.hasInstance](inst) || super[Symbol.hasInstance](inst);
51177
+ }
51178
+ }
51179
+
51180
+ let mixed = {
51181
+ default: '${path} is invalid',
51182
+ required: '${path} is a required field',
51183
+ defined: '${path} must be defined',
51184
+ notNull: '${path} cannot be null',
51185
+ oneOf: '${path} must be one of the following values: ${values}',
51186
+ notOneOf: '${path} must not be one of the following values: ${values}',
51187
+ notType: ({
51188
+ path,
51189
+ type,
51190
+ value,
51191
+ originalValue
51192
+ }) => {
51193
+ const castMsg = originalValue != null && originalValue !== value ? ` (cast from the value \`${printValue(originalValue, true)}\`).` : '.';
51194
+ return type !== 'mixed' ? `${path} must be a \`${type}\` type, ` + `but the final value was: \`${printValue(value, true)}\`` + castMsg : `${path} must match the configured type. ` + `The validated value was: \`${printValue(value, true)}\`` + castMsg;
51195
+ }
51196
+ };
51197
+ let string = {
51198
+ length: '${path} must be exactly ${length} characters',
51199
+ min: '${path} must be at least ${min} characters',
51200
+ max: '${path} must be at most ${max} characters',
51201
+ matches: '${path} must match the following: "${regex}"',
51202
+ email: '${path} must be a valid email',
51203
+ url: '${path} must be a valid URL',
51204
+ uuid: '${path} must be a valid UUID',
51205
+ datetime: '${path} must be a valid ISO date-time',
51206
+ datetime_precision: '${path} must be a valid ISO date-time with a sub-second precision of exactly ${precision} digits',
51207
+ datetime_offset: '${path} must be a valid ISO date-time with UTC "Z" timezone',
51208
+ trim: '${path} must be a trimmed string',
51209
+ lowercase: '${path} must be a lowercase string',
51210
+ uppercase: '${path} must be a upper case string'
51211
+ };
51212
+ let number = {
51213
+ min: '${path} must be greater than or equal to ${min}',
51214
+ max: '${path} must be less than or equal to ${max}',
51215
+ lessThan: '${path} must be less than ${less}',
51216
+ moreThan: '${path} must be greater than ${more}',
51217
+ positive: '${path} must be a positive number',
51218
+ negative: '${path} must be a negative number',
51219
+ integer: '${path} must be an integer'
51220
+ };
51221
+ let date = {
51222
+ min: '${path} field must be later than ${min}',
51223
+ max: '${path} field must be at earlier than ${max}'
51224
+ };
51225
+ let boolean = {
51226
+ isValue: '${path} field must be ${value}'
51227
+ };
51228
+ let object = {
51229
+ noUnknown: '${path} field has unspecified keys: ${unknown}'
51230
+ };
51231
+ let array = {
51232
+ min: '${path} field must have at least ${min} items',
51233
+ max: '${path} field must have less than or equal to ${max} items',
51234
+ length: '${path} must have ${length} items'
51235
+ };
51236
+ let tuple = {
51237
+ notType: params => {
51238
+ const {
51239
+ path,
51240
+ value,
51241
+ spec
51242
+ } = params;
51243
+ const typeLen = spec.types.length;
51244
+ if (Array.isArray(value)) {
51245
+ if (value.length < typeLen) return `${path} tuple value has too few items, expected a length of ${typeLen} but got ${value.length} for value: \`${printValue(value, true)}\``;
51246
+ if (value.length > typeLen) return `${path} tuple value has too many items, expected a length of ${typeLen} but got ${value.length} for value: \`${printValue(value, true)}\``;
51247
+ }
51248
+ return ValidationError.formatError(mixed.notType, params);
51249
+ }
51250
+ };
51251
+ Object.assign(Object.create(null), {
51252
+ mixed,
51253
+ string,
51254
+ number,
51255
+ date,
51256
+ object,
51257
+ array,
51258
+ boolean,
51259
+ tuple
51260
+ });
51261
+
51262
+ const isSchema = obj => obj && obj.__isYupSchema__;
51263
+
51264
+ class Condition {
51265
+ static fromOptions(refs, config) {
51266
+ if (!config.then && !config.otherwise) throw new TypeError('either `then:` or `otherwise:` is required for `when()` conditions');
51267
+ let {
51268
+ is,
51269
+ then,
51270
+ otherwise
51271
+ } = config;
51272
+ let check = typeof is === 'function' ? is : (...values) => values.every(value => value === is);
51273
+ return new Condition(refs, (values, schema) => {
51274
+ var _branch;
51275
+ let branch = check(...values) ? then : otherwise;
51276
+ return (_branch = branch == null ? void 0 : branch(schema)) != null ? _branch : schema;
51277
+ });
51278
+ }
51279
+ constructor(refs, builder) {
51280
+ this.fn = void 0;
51281
+ this.refs = refs;
51282
+ this.refs = refs;
51283
+ this.fn = builder;
51284
+ }
51285
+ resolve(base, options) {
51286
+ let values = this.refs.map(ref =>
51287
+ // TODO: ? operator here?
51288
+ ref.getValue(options == null ? void 0 : options.value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context));
51289
+ let schema = this.fn(values, base, options);
51290
+ if (schema === undefined ||
51291
+ // @ts-ignore this can be base
51292
+ schema === base) {
51293
+ return base;
51294
+ }
51295
+ if (!isSchema(schema)) throw new TypeError('conditions must return a schema object');
51296
+ return schema.resolve(options);
51297
+ }
51298
+ }
51299
+
51300
+ const prefixes = {
51301
+ context: '$',
51302
+ value: '.'
51303
+ };
51304
+ class Reference {
51305
+ constructor(key, options = {}) {
51306
+ this.key = void 0;
51307
+ this.isContext = void 0;
51308
+ this.isValue = void 0;
51309
+ this.isSibling = void 0;
51310
+ this.path = void 0;
51311
+ this.getter = void 0;
51312
+ this.map = void 0;
51313
+ if (typeof key !== 'string') throw new TypeError('ref must be a string, got: ' + key);
51314
+ this.key = key.trim();
51315
+ if (key === '') throw new TypeError('ref must be a non-empty string');
51316
+ this.isContext = this.key[0] === prefixes.context;
51317
+ this.isValue = this.key[0] === prefixes.value;
51318
+ this.isSibling = !this.isContext && !this.isValue;
51319
+ let prefix = this.isContext ? prefixes.context : this.isValue ? prefixes.value : '';
51320
+ this.path = this.key.slice(prefix.length);
51321
+ this.getter = this.path && propertyExpr.getter(this.path, true);
51322
+ this.map = options.map;
51323
+ }
51324
+ getValue(value, parent, context) {
51325
+ let result = this.isContext ? context : this.isValue ? value : parent;
51326
+ if (this.getter) result = this.getter(result || {});
51327
+ if (this.map) result = this.map(result);
51328
+ return result;
51329
+ }
51330
+
51331
+ /**
51332
+ *
51333
+ * @param {*} value
51334
+ * @param {Object} options
51335
+ * @param {Object=} options.context
51336
+ * @param {Object=} options.parent
51337
+ */
51338
+ cast(value, options) {
51339
+ return this.getValue(value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context);
51340
+ }
51341
+ resolve() {
51342
+ return this;
51343
+ }
51344
+ describe() {
51345
+ return {
51346
+ type: 'ref',
51347
+ key: this.key
51348
+ };
51349
+ }
51350
+ toString() {
51351
+ return `Ref(${this.key})`;
51352
+ }
51353
+ static isRef(value) {
51354
+ return value && value.__isYupRef;
51355
+ }
51356
+ }
51357
+
51358
+ // @ts-ignore
51359
+ Reference.prototype.__isYupRef = true;
51360
+
51361
+ const isAbsent = value => value == null;
51362
+
51363
+ function createValidation(config) {
51364
+ function validate({
51365
+ value,
51366
+ path = '',
51367
+ options,
51368
+ originalValue,
51369
+ schema
51370
+ }, panic, next) {
51371
+ const {
51372
+ name,
51373
+ test,
51374
+ params,
51375
+ message,
51376
+ skipAbsent
51377
+ } = config;
51378
+ let {
51379
+ parent,
51380
+ context,
51381
+ abortEarly = schema.spec.abortEarly,
51382
+ disableStackTrace = schema.spec.disableStackTrace
51383
+ } = options;
51384
+ function resolve(item) {
51385
+ return Reference.isRef(item) ? item.getValue(value, parent, context) : item;
51386
+ }
51387
+ function createError(overrides = {}) {
51388
+ const nextParams = Object.assign({
51389
+ value,
51390
+ originalValue,
51391
+ label: schema.spec.label,
51392
+ path: overrides.path || path,
51393
+ spec: schema.spec,
51394
+ disableStackTrace: overrides.disableStackTrace || disableStackTrace
51395
+ }, params, overrides.params);
51396
+ for (const key of Object.keys(nextParams)) nextParams[key] = resolve(nextParams[key]);
51397
+ const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name, nextParams.disableStackTrace);
51398
+ error.params = nextParams;
51399
+ return error;
51400
+ }
51401
+ const invalid = abortEarly ? panic : next;
51402
+ let ctx = {
51403
+ path,
51404
+ parent,
51405
+ type: name,
51406
+ from: options.from,
51407
+ createError,
51408
+ resolve,
51409
+ options,
51410
+ originalValue,
51411
+ schema
51412
+ };
51413
+ const handleResult = validOrError => {
51414
+ if (ValidationError.isError(validOrError)) invalid(validOrError);else if (!validOrError) invalid(createError());else next(null);
51415
+ };
51416
+ const handleError = err => {
51417
+ if (ValidationError.isError(err)) invalid(err);else panic(err);
51418
+ };
51419
+ const shouldSkip = skipAbsent && isAbsent(value);
51420
+ if (shouldSkip) {
51421
+ return handleResult(true);
51422
+ }
51423
+ let result;
51424
+ try {
51425
+ var _result;
51426
+ result = test.call(ctx, value, ctx);
51427
+ if (typeof ((_result = result) == null ? void 0 : _result.then) === 'function') {
51428
+ if (options.sync) {
51429
+ throw new Error(`Validation test of type: "${ctx.type}" returned a Promise during a synchronous validate. ` + `This test will finish after the validate call has returned`);
51430
+ }
51431
+ return Promise.resolve(result).then(handleResult, handleError);
51432
+ }
51433
+ } catch (err) {
51434
+ handleError(err);
51435
+ return;
51436
+ }
51437
+ handleResult(result);
51438
+ }
51439
+ validate.OPTIONS = config;
51440
+ return validate;
51441
+ }
51442
+
51443
+ function getIn(schema, path, value, context = value) {
51444
+ let parent, lastPart, lastPartDebug;
51445
+
51446
+ // root path: ''
51447
+ if (!path) return {
51448
+ parent,
51449
+ parentPath: path,
51450
+ schema
51451
+ };
51452
+ propertyExpr.forEach(path, (_part, isBracket, isArray) => {
51453
+ let part = isBracket ? _part.slice(1, _part.length - 1) : _part;
51454
+ schema = schema.resolve({
51455
+ context,
51456
+ parent,
51457
+ value
51458
+ });
51459
+ let isTuple = schema.type === 'tuple';
51460
+ let idx = isArray ? parseInt(part, 10) : 0;
51461
+ if (schema.innerType || isTuple) {
51462
+ if (isTuple && !isArray) throw new Error(`Yup.reach cannot implicitly index into a tuple type. the path part "${lastPartDebug}" must contain an index to the tuple element, e.g. "${lastPartDebug}[0]"`);
51463
+ if (value && idx >= value.length) {
51464
+ throw new Error(`Yup.reach cannot resolve an array item at index: ${_part}, in the path: ${path}. ` + `because there is no value at that index. `);
51465
+ }
51466
+ parent = value;
51467
+ value = value && value[idx];
51468
+ schema = isTuple ? schema.spec.types[idx] : schema.innerType;
51469
+ }
51470
+
51471
+ // sometimes the array index part of a path doesn't exist: "nested.arr.child"
51472
+ // in these cases the current part is the next schema and should be processed
51473
+ // in this iteration. For cases where the index signature is included this
51474
+ // check will fail and we'll handle the `child` part on the next iteration like normal
51475
+ if (!isArray) {
51476
+ if (!schema.fields || !schema.fields[part]) throw new Error(`The schema does not contain the path: ${path}. ` + `(failed at: ${lastPartDebug} which is a type: "${schema.type}")`);
51477
+ parent = value;
51478
+ value = value && value[part];
51479
+ schema = schema.fields[part];
51480
+ }
51481
+ lastPart = part;
51482
+ lastPartDebug = isBracket ? '[' + _part + ']' : '.' + _part;
51483
+ });
51484
+ return {
51485
+ schema,
51486
+ parent,
51487
+ parentPath: lastPart
51488
+ };
51489
+ }
51490
+
51491
+ class ReferenceSet extends Set {
51492
+ describe() {
51493
+ const description = [];
51494
+ for (const item of this.values()) {
51495
+ description.push(Reference.isRef(item) ? item.describe() : item);
51496
+ }
51497
+ return description;
51498
+ }
51499
+ resolveAll(resolve) {
51500
+ let result = [];
51501
+ for (const item of this.values()) {
51502
+ result.push(resolve(item));
51503
+ }
51504
+ return result;
51505
+ }
51506
+ clone() {
51507
+ return new ReferenceSet(this.values());
51508
+ }
51509
+ merge(newItems, removeItems) {
51510
+ const next = this.clone();
51511
+ newItems.forEach(value => next.add(value));
51512
+ removeItems.forEach(value => next.delete(value));
51513
+ return next;
51514
+ }
51515
+ }
51516
+
51517
+ // tweaked from https://github.com/Kelin2025/nanoclone/blob/0abeb7635bda9b68ef2277093f76dbe3bf3948e1/src/index.js
51518
+ function clone(src, seen = new Map()) {
51519
+ if (isSchema(src) || !src || typeof src !== 'object') return src;
51520
+ if (seen.has(src)) return seen.get(src);
51521
+ let copy;
51522
+ if (src instanceof Date) {
51523
+ // Date
51524
+ copy = new Date(src.getTime());
51525
+ seen.set(src, copy);
51526
+ } else if (src instanceof RegExp) {
51527
+ // RegExp
51528
+ copy = new RegExp(src);
51529
+ seen.set(src, copy);
51530
+ } else if (Array.isArray(src)) {
51531
+ // Array
51532
+ copy = new Array(src.length);
51533
+ seen.set(src, copy);
51534
+ for (let i = 0; i < src.length; i++) copy[i] = clone(src[i], seen);
51535
+ } else if (src instanceof Map) {
51536
+ // Map
51537
+ copy = new Map();
51538
+ seen.set(src, copy);
51539
+ for (const [k, v] of src.entries()) copy.set(k, clone(v, seen));
51540
+ } else if (src instanceof Set) {
51541
+ // Set
51542
+ copy = new Set();
51543
+ seen.set(src, copy);
51544
+ for (const v of src) copy.add(clone(v, seen));
51545
+ } else if (src instanceof Object) {
51546
+ // Object
51547
+ copy = {};
51548
+ seen.set(src, copy);
51549
+ for (const [k, v] of Object.entries(src)) copy[k] = clone(v, seen);
51550
+ } else {
51551
+ throw Error(`Unable to clone ${src}`);
51552
+ }
51553
+ return copy;
51554
+ }
51555
+
51556
+ // If `CustomSchemaMeta` isn't extended with any keys, we'll fall back to a
51557
+ // loose Record definition allowing free form usage.
51558
+ class Schema {
51559
+ constructor(options) {
51560
+ this.type = void 0;
51561
+ this.deps = [];
51562
+ this.tests = void 0;
51563
+ this.transforms = void 0;
51564
+ this.conditions = [];
51565
+ this._mutate = void 0;
51566
+ this.internalTests = {};
51567
+ this._whitelist = new ReferenceSet();
51568
+ this._blacklist = new ReferenceSet();
51569
+ this.exclusiveTests = Object.create(null);
51570
+ this._typeCheck = void 0;
51571
+ this.spec = void 0;
51572
+ this.tests = [];
51573
+ this.transforms = [];
51574
+ this.withMutation(() => {
51575
+ this.typeError(mixed.notType);
51576
+ });
51577
+ this.type = options.type;
51578
+ this._typeCheck = options.check;
51579
+ this.spec = Object.assign({
51580
+ strip: false,
51581
+ strict: false,
51582
+ abortEarly: true,
51583
+ recursive: true,
51584
+ disableStackTrace: false,
51585
+ nullable: false,
51586
+ optional: true,
51587
+ coerce: true
51588
+ }, options == null ? void 0 : options.spec);
51589
+ this.withMutation(s => {
51590
+ s.nonNullable();
51591
+ });
51592
+ }
51593
+
51594
+ // TODO: remove
51595
+ get _type() {
51596
+ return this.type;
51597
+ }
51598
+ clone(spec) {
51599
+ if (this._mutate) {
51600
+ if (spec) Object.assign(this.spec, spec);
51601
+ return this;
51602
+ }
51603
+
51604
+ // if the nested value is a schema we can skip cloning, since
51605
+ // they are already immutable
51606
+ const next = Object.create(Object.getPrototypeOf(this));
51607
+
51608
+ // @ts-expect-error this is readonly
51609
+ next.type = this.type;
51610
+ next._typeCheck = this._typeCheck;
51611
+ next._whitelist = this._whitelist.clone();
51612
+ next._blacklist = this._blacklist.clone();
51613
+ next.internalTests = Object.assign({}, this.internalTests);
51614
+ next.exclusiveTests = Object.assign({}, this.exclusiveTests);
51615
+
51616
+ // @ts-expect-error this is readonly
51617
+ next.deps = [...this.deps];
51618
+ next.conditions = [...this.conditions];
51619
+ next.tests = [...this.tests];
51620
+ next.transforms = [...this.transforms];
51621
+ next.spec = clone(Object.assign({}, this.spec, spec));
51622
+ return next;
51623
+ }
51624
+ label(label) {
51625
+ let next = this.clone();
51626
+ next.spec.label = label;
51627
+ return next;
51628
+ }
51629
+ meta(...args) {
51630
+ if (args.length === 0) return this.spec.meta;
51631
+ let next = this.clone();
51632
+ next.spec.meta = Object.assign(next.spec.meta || {}, args[0]);
51633
+ return next;
51634
+ }
51635
+ withMutation(fn) {
51636
+ let before = this._mutate;
51637
+ this._mutate = true;
51638
+ let result = fn(this);
51639
+ this._mutate = before;
51640
+ return result;
51641
+ }
51642
+ concat(schema) {
51643
+ if (!schema || schema === this) return this;
51644
+ if (schema.type !== this.type && this.type !== 'mixed') throw new TypeError(`You cannot \`concat()\` schema's of different types: ${this.type} and ${schema.type}`);
51645
+ let base = this;
51646
+ let combined = schema.clone();
51647
+ const mergedSpec = Object.assign({}, base.spec, combined.spec);
51648
+ combined.spec = mergedSpec;
51649
+ combined.internalTests = Object.assign({}, base.internalTests, combined.internalTests);
51650
+
51651
+ // manually merge the blacklist/whitelist (the other `schema` takes
51652
+ // precedence in case of conflicts)
51653
+ combined._whitelist = base._whitelist.merge(schema._whitelist, schema._blacklist);
51654
+ combined._blacklist = base._blacklist.merge(schema._blacklist, schema._whitelist);
51655
+
51656
+ // start with the current tests
51657
+ combined.tests = base.tests;
51658
+ combined.exclusiveTests = base.exclusiveTests;
51659
+
51660
+ // manually add the new tests to ensure
51661
+ // the deduping logic is consistent
51662
+ combined.withMutation(next => {
51663
+ schema.tests.forEach(fn => {
51664
+ next.test(fn.OPTIONS);
51665
+ });
51666
+ });
51667
+ combined.transforms = [...base.transforms, ...combined.transforms];
51668
+ return combined;
51669
+ }
51670
+ isType(v) {
51671
+ if (v == null) {
51672
+ if (this.spec.nullable && v === null) return true;
51673
+ if (this.spec.optional && v === undefined) return true;
51674
+ return false;
51675
+ }
51676
+ return this._typeCheck(v);
51677
+ }
51678
+ resolve(options) {
51679
+ let schema = this;
51680
+ if (schema.conditions.length) {
51681
+ let conditions = schema.conditions;
51682
+ schema = schema.clone();
51683
+ schema.conditions = [];
51684
+ schema = conditions.reduce((prevSchema, condition) => condition.resolve(prevSchema, options), schema);
51685
+ schema = schema.resolve(options);
51686
+ }
51687
+ return schema;
51688
+ }
51689
+ resolveOptions(options) {
51690
+ var _options$strict, _options$abortEarly, _options$recursive, _options$disableStack;
51691
+ return Object.assign({}, options, {
51692
+ from: options.from || [],
51693
+ strict: (_options$strict = options.strict) != null ? _options$strict : this.spec.strict,
51694
+ abortEarly: (_options$abortEarly = options.abortEarly) != null ? _options$abortEarly : this.spec.abortEarly,
51695
+ recursive: (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive,
51696
+ disableStackTrace: (_options$disableStack = options.disableStackTrace) != null ? _options$disableStack : this.spec.disableStackTrace
51697
+ });
51698
+ }
51699
+
51700
+ /**
51701
+ * Run the configured transform pipeline over an input value.
51702
+ */
51703
+
51704
+ cast(value, options = {}) {
51705
+ let resolvedSchema = this.resolve(Object.assign({
51706
+ value
51707
+ }, options));
51708
+ let allowOptionality = options.assert === 'ignore-optionality';
51709
+ let result = resolvedSchema._cast(value, options);
51710
+ if (options.assert !== false && !resolvedSchema.isType(result)) {
51711
+ if (allowOptionality && isAbsent(result)) {
51712
+ return result;
51713
+ }
51714
+ let formattedValue = printValue(value);
51715
+ let formattedResult = printValue(result);
51716
+ throw new TypeError(`The value of ${options.path || 'field'} could not be cast to a value ` + `that satisfies the schema type: "${resolvedSchema.type}". \n\n` + `attempted value: ${formattedValue} \n` + (formattedResult !== formattedValue ? `result of cast: ${formattedResult}` : ''));
51717
+ }
51718
+ return result;
51719
+ }
51720
+ _cast(rawValue, options) {
51721
+ let value = rawValue === undefined ? rawValue : this.transforms.reduce((prevValue, fn) => fn.call(this, prevValue, rawValue, this), rawValue);
51722
+ if (value === undefined) {
51723
+ value = this.getDefault(options);
51724
+ }
51725
+ return value;
51726
+ }
51727
+ _validate(_value, options = {}, panic, next) {
51728
+ let {
51729
+ path,
51730
+ originalValue = _value,
51731
+ strict = this.spec.strict
51732
+ } = options;
51733
+ let value = _value;
51734
+ if (!strict) {
51735
+ value = this._cast(value, Object.assign({
51736
+ assert: false
51737
+ }, options));
51738
+ }
51739
+ let initialTests = [];
51740
+ for (let test of Object.values(this.internalTests)) {
51741
+ if (test) initialTests.push(test);
51742
+ }
51743
+ this.runTests({
51744
+ path,
51745
+ value,
51746
+ originalValue,
51747
+ options,
51748
+ tests: initialTests
51749
+ }, panic, initialErrors => {
51750
+ // even if we aren't ending early we can't proceed further if the types aren't correct
51751
+ if (initialErrors.length) {
51752
+ return next(initialErrors, value);
51753
+ }
51754
+ this.runTests({
51755
+ path,
51756
+ value,
51757
+ originalValue,
51758
+ options,
51759
+ tests: this.tests
51760
+ }, panic, next);
51761
+ });
51762
+ }
51763
+
51764
+ /**
51765
+ * Executes a set of validations, either schema, produced Tests or a nested
51766
+ * schema validate result.
51767
+ */
51768
+ runTests(runOptions, panic, next) {
51769
+ let fired = false;
51770
+ let {
51771
+ tests,
51772
+ value,
51773
+ originalValue,
51774
+ path,
51775
+ options
51776
+ } = runOptions;
51777
+ let panicOnce = arg => {
51778
+ if (fired) return;
51779
+ fired = true;
51780
+ panic(arg, value);
51781
+ };
51782
+ let nextOnce = arg => {
51783
+ if (fired) return;
51784
+ fired = true;
51785
+ next(arg, value);
51786
+ };
51787
+ let count = tests.length;
51788
+ let nestedErrors = [];
51789
+ if (!count) return nextOnce([]);
51790
+ let args = {
51791
+ value,
51792
+ originalValue,
51793
+ path,
51794
+ options,
51795
+ schema: this
51796
+ };
51797
+ for (let i = 0; i < tests.length; i++) {
51798
+ const test = tests[i];
51799
+ test(args, panicOnce, function finishTestRun(err) {
51800
+ if (err) {
51801
+ Array.isArray(err) ? nestedErrors.push(...err) : nestedErrors.push(err);
51802
+ }
51803
+ if (--count <= 0) {
51804
+ nextOnce(nestedErrors);
51805
+ }
51806
+ });
51807
+ }
51808
+ }
51809
+ asNestedTest({
51810
+ key,
51811
+ index,
51812
+ parent,
51813
+ parentPath,
51814
+ originalParent,
51815
+ options
51816
+ }) {
51817
+ const k = key != null ? key : index;
51818
+ if (k == null) {
51819
+ throw TypeError('Must include `key` or `index` for nested validations');
51820
+ }
51821
+ const isIndex = typeof k === 'number';
51822
+ let value = parent[k];
51823
+ const testOptions = Object.assign({}, options, {
51824
+ // Nested validations fields are always strict:
51825
+ // 1. parent isn't strict so the casting will also have cast inner values
51826
+ // 2. parent is strict in which case the nested values weren't cast either
51827
+ strict: true,
51828
+ parent,
51829
+ value,
51830
+ originalValue: originalParent[k],
51831
+ // FIXME: tests depend on `index` being passed around deeply,
51832
+ // we should not let the options.key/index bleed through
51833
+ key: undefined,
51834
+ // index: undefined,
51835
+ [isIndex ? 'index' : 'key']: k,
51836
+ path: isIndex || k.includes('.') ? `${parentPath || ''}[${isIndex ? k : `"${k}"`}]` : (parentPath ? `${parentPath}.` : '') + key
51837
+ });
51838
+ return (_, panic, next) => this.resolve(testOptions)._validate(value, testOptions, panic, next);
51839
+ }
51840
+ validate(value, options) {
51841
+ var _options$disableStack2;
51842
+ let schema = this.resolve(Object.assign({}, options, {
51843
+ value
51844
+ }));
51845
+ let disableStackTrace = (_options$disableStack2 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack2 : schema.spec.disableStackTrace;
51846
+ return new Promise((resolve, reject) => schema._validate(value, options, (error, parsed) => {
51847
+ if (ValidationError.isError(error)) error.value = parsed;
51848
+ reject(error);
51849
+ }, (errors, validated) => {
51850
+ if (errors.length) reject(new ValidationError(errors, validated, undefined, undefined, disableStackTrace));else resolve(validated);
51851
+ }));
51852
+ }
51853
+ validateSync(value, options) {
51854
+ var _options$disableStack3;
51855
+ let schema = this.resolve(Object.assign({}, options, {
51856
+ value
51857
+ }));
51858
+ let result;
51859
+ let disableStackTrace = (_options$disableStack3 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack3 : schema.spec.disableStackTrace;
51860
+ schema._validate(value, Object.assign({}, options, {
51861
+ sync: true
51862
+ }), (error, parsed) => {
51863
+ if (ValidationError.isError(error)) error.value = parsed;
51864
+ throw error;
51865
+ }, (errors, validated) => {
51866
+ if (errors.length) throw new ValidationError(errors, value, undefined, undefined, disableStackTrace);
51867
+ result = validated;
51868
+ });
51869
+ return result;
51870
+ }
51871
+ isValid(value, options) {
51872
+ return this.validate(value, options).then(() => true, err => {
51873
+ if (ValidationError.isError(err)) return false;
51874
+ throw err;
51875
+ });
51876
+ }
51877
+ isValidSync(value, options) {
51878
+ try {
51879
+ this.validateSync(value, options);
51880
+ return true;
51881
+ } catch (err) {
51882
+ if (ValidationError.isError(err)) return false;
51883
+ throw err;
51884
+ }
51885
+ }
51886
+ _getDefault(options) {
51887
+ let defaultValue = this.spec.default;
51888
+ if (defaultValue == null) {
51889
+ return defaultValue;
51890
+ }
51891
+ return typeof defaultValue === 'function' ? defaultValue.call(this, options) : clone(defaultValue);
51892
+ }
51893
+ getDefault(options
51894
+ // If schema is defaulted we know it's at least not undefined
51895
+ ) {
51896
+ let schema = this.resolve(options || {});
51897
+ return schema._getDefault(options);
51898
+ }
51899
+ default(def) {
51900
+ if (arguments.length === 0) {
51901
+ return this._getDefault();
51902
+ }
51903
+ let next = this.clone({
51904
+ default: def
51905
+ });
51906
+ return next;
51907
+ }
51908
+ strict(isStrict = true) {
51909
+ return this.clone({
51910
+ strict: isStrict
51911
+ });
51912
+ }
51913
+ nullability(nullable, message) {
51914
+ const next = this.clone({
51915
+ nullable
51916
+ });
51917
+ next.internalTests.nullable = createValidation({
51918
+ message,
51919
+ name: 'nullable',
51920
+ test(value) {
51921
+ return value === null ? this.schema.spec.nullable : true;
51922
+ }
51923
+ });
51924
+ return next;
51925
+ }
51926
+ optionality(optional, message) {
51927
+ const next = this.clone({
51928
+ optional
51929
+ });
51930
+ next.internalTests.optionality = createValidation({
51931
+ message,
51932
+ name: 'optionality',
51933
+ test(value) {
51934
+ return value === undefined ? this.schema.spec.optional : true;
51935
+ }
51936
+ });
51937
+ return next;
51938
+ }
51939
+ optional() {
51940
+ return this.optionality(true);
51941
+ }
51942
+ defined(message = mixed.defined) {
51943
+ return this.optionality(false, message);
51944
+ }
51945
+ nullable() {
51946
+ return this.nullability(true);
51947
+ }
51948
+ nonNullable(message = mixed.notNull) {
51949
+ return this.nullability(false, message);
51950
+ }
51951
+ required(message = mixed.required) {
51952
+ return this.clone().withMutation(next => next.nonNullable(message).defined(message));
51953
+ }
51954
+ notRequired() {
51955
+ return this.clone().withMutation(next => next.nullable().optional());
51956
+ }
51957
+ transform(fn) {
51958
+ let next = this.clone();
51959
+ next.transforms.push(fn);
51960
+ return next;
51961
+ }
51962
+
51963
+ /**
51964
+ * Adds a test function to the schema's queue of tests.
51965
+ * tests can be exclusive or non-exclusive.
51966
+ *
51967
+ * - exclusive tests, will replace any existing tests of the same name.
51968
+ * - non-exclusive: can be stacked
51969
+ *
51970
+ * If a non-exclusive test is added to a schema with an exclusive test of the same name
51971
+ * the exclusive test is removed and further tests of the same name will be stacked.
51972
+ *
51973
+ * If an exclusive test is added to a schema with non-exclusive tests of the same name
51974
+ * the previous tests are removed and further tests of the same name will replace each other.
51975
+ */
51976
+
51977
+ test(...args) {
51978
+ let opts;
51979
+ if (args.length === 1) {
51980
+ if (typeof args[0] === 'function') {
51981
+ opts = {
51982
+ test: args[0]
51983
+ };
51984
+ } else {
51985
+ opts = args[0];
51986
+ }
51987
+ } else if (args.length === 2) {
51988
+ opts = {
51989
+ name: args[0],
51990
+ test: args[1]
51991
+ };
51992
+ } else {
51993
+ opts = {
51994
+ name: args[0],
51995
+ message: args[1],
51996
+ test: args[2]
51997
+ };
51998
+ }
51999
+ if (opts.message === undefined) opts.message = mixed.default;
52000
+ if (typeof opts.test !== 'function') throw new TypeError('`test` is a required parameters');
52001
+ let next = this.clone();
52002
+ let validate = createValidation(opts);
52003
+ let isExclusive = opts.exclusive || opts.name && next.exclusiveTests[opts.name] === true;
52004
+ if (opts.exclusive) {
52005
+ if (!opts.name) throw new TypeError('Exclusive tests must provide a unique `name` identifying the test');
52006
+ }
52007
+ if (opts.name) next.exclusiveTests[opts.name] = !!opts.exclusive;
52008
+ next.tests = next.tests.filter(fn => {
52009
+ if (fn.OPTIONS.name === opts.name) {
52010
+ if (isExclusive) return false;
52011
+ if (fn.OPTIONS.test === validate.OPTIONS.test) return false;
52012
+ }
52013
+ return true;
52014
+ });
52015
+ next.tests.push(validate);
52016
+ return next;
52017
+ }
52018
+ when(keys, options) {
52019
+ if (!Array.isArray(keys) && typeof keys !== 'string') {
52020
+ options = keys;
52021
+ keys = '.';
52022
+ }
52023
+ let next = this.clone();
52024
+ let deps = toArray(keys).map(key => new Reference(key));
52025
+ deps.forEach(dep => {
52026
+ // @ts-ignore readonly array
52027
+ if (dep.isSibling) next.deps.push(dep.key);
52028
+ });
52029
+ next.conditions.push(typeof options === 'function' ? new Condition(deps, options) : Condition.fromOptions(deps, options));
52030
+ return next;
52031
+ }
52032
+ typeError(message) {
52033
+ let next = this.clone();
52034
+ next.internalTests.typeError = createValidation({
52035
+ message,
52036
+ name: 'typeError',
52037
+ skipAbsent: true,
52038
+ test(value) {
52039
+ if (!this.schema._typeCheck(value)) return this.createError({
52040
+ params: {
52041
+ type: this.schema.type
52042
+ }
52043
+ });
52044
+ return true;
52045
+ }
52046
+ });
52047
+ return next;
52048
+ }
52049
+ oneOf(enums, message = mixed.oneOf) {
52050
+ let next = this.clone();
52051
+ enums.forEach(val => {
52052
+ next._whitelist.add(val);
52053
+ next._blacklist.delete(val);
52054
+ });
52055
+ next.internalTests.whiteList = createValidation({
52056
+ message,
52057
+ name: 'oneOf',
52058
+ skipAbsent: true,
52059
+ test(value) {
52060
+ let valids = this.schema._whitelist;
52061
+ let resolved = valids.resolveAll(this.resolve);
52062
+ return resolved.includes(value) ? true : this.createError({
52063
+ params: {
52064
+ values: Array.from(valids).join(', '),
52065
+ resolved
52066
+ }
52067
+ });
52068
+ }
52069
+ });
52070
+ return next;
52071
+ }
52072
+ notOneOf(enums, message = mixed.notOneOf) {
52073
+ let next = this.clone();
52074
+ enums.forEach(val => {
52075
+ next._blacklist.add(val);
52076
+ next._whitelist.delete(val);
52077
+ });
52078
+ next.internalTests.blacklist = createValidation({
52079
+ message,
52080
+ name: 'notOneOf',
52081
+ test(value) {
52082
+ let invalids = this.schema._blacklist;
52083
+ let resolved = invalids.resolveAll(this.resolve);
52084
+ if (resolved.includes(value)) return this.createError({
52085
+ params: {
52086
+ values: Array.from(invalids).join(', '),
52087
+ resolved
52088
+ }
52089
+ });
52090
+ return true;
52091
+ }
52092
+ });
52093
+ return next;
52094
+ }
52095
+ strip(strip = true) {
52096
+ let next = this.clone();
52097
+ next.spec.strip = strip;
52098
+ return next;
52099
+ }
52100
+
52101
+ /**
52102
+ * Return a serialized description of the schema including validations, flags, types etc.
52103
+ *
52104
+ * @param options Provide any needed context for resolving runtime schema alterations (lazy, when conditions, etc).
52105
+ */
52106
+ describe(options) {
52107
+ const next = (options ? this.resolve(options) : this).clone();
52108
+ const {
52109
+ label,
52110
+ meta,
52111
+ optional,
52112
+ nullable
52113
+ } = next.spec;
52114
+ const description = {
52115
+ meta,
52116
+ label,
52117
+ optional,
52118
+ nullable,
52119
+ default: next.getDefault(options),
52120
+ type: next.type,
52121
+ oneOf: next._whitelist.describe(),
52122
+ notOneOf: next._blacklist.describe(),
52123
+ tests: next.tests.map(fn => ({
52124
+ name: fn.OPTIONS.name,
52125
+ params: fn.OPTIONS.params
52126
+ })).filter((n, idx, list) => list.findIndex(c => c.name === n.name) === idx)
52127
+ };
52128
+ return description;
52129
+ }
52130
+ }
52131
+ // @ts-expect-error
52132
+ Schema.prototype.__isYupSchema__ = true;
52133
+ for (const method of ['validate', 'validateSync']) Schema.prototype[`${method}At`] = function (path, value, options = {}) {
52134
+ const {
52135
+ parent,
52136
+ parentPath,
52137
+ schema
52138
+ } = getIn(this, path, value, options.context);
52139
+ return schema[method](parent && parent[parentPath], Object.assign({}, options, {
52140
+ parent,
52141
+ path
52142
+ }));
52143
+ };
52144
+ for (const alias of ['equals', 'is']) Schema.prototype[alias] = Schema.prototype.oneOf;
52145
+ for (const alias of ['not', 'nope']) Schema.prototype[alias] = Schema.prototype.notOneOf;
52146
+
52147
+ const returnsTrue = () => true;
52148
+ function create$8(spec) {
52149
+ return new MixedSchema(spec);
52150
+ }
52151
+ class MixedSchema extends Schema {
52152
+ constructor(spec) {
52153
+ super(typeof spec === 'function' ? {
52154
+ type: 'mixed',
52155
+ check: spec
52156
+ } : Object.assign({
52157
+ type: 'mixed',
52158
+ check: returnsTrue
52159
+ }, spec));
52160
+ }
52161
+ }
52162
+ create$8.prototype = MixedSchema.prototype;
52163
+
52164
+ /**
52165
+ * This file is a modified version of the file from the following repository:
52166
+ * Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
52167
+ * NON-CONFORMANT EDITION.
52168
+ * © 2011 Colin Snover <http://zetafleet.com>
52169
+ * Released under MIT license.
52170
+ */
52171
+
52172
+ // prettier-ignore
52173
+ // 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm
52174
+ const isoReg = /^(\d{4}|[+-]\d{6})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[ T]?(\d{2}):?(\d{2})(?::?(\d{2})(?:[,.](\d{1,}))?)?(?:(Z)|([+-])(\d{2})(?::?(\d{2}))?)?)?$/;
52175
+ function parseIsoDate(date) {
52176
+ const struct = parseDateStruct(date);
52177
+ if (!struct) return Date.parse ? Date.parse(date) : Number.NaN;
52178
+
52179
+ // timestamps without timezone identifiers should be considered local time
52180
+ if (struct.z === undefined && struct.plusMinus === undefined) {
52181
+ return new Date(struct.year, struct.month, struct.day, struct.hour, struct.minute, struct.second, struct.millisecond).valueOf();
52182
+ }
52183
+ let totalMinutesOffset = 0;
52184
+ if (struct.z !== 'Z' && struct.plusMinus !== undefined) {
52185
+ totalMinutesOffset = struct.hourOffset * 60 + struct.minuteOffset;
52186
+ if (struct.plusMinus === '+') totalMinutesOffset = 0 - totalMinutesOffset;
52187
+ }
52188
+ return Date.UTC(struct.year, struct.month, struct.day, struct.hour, struct.minute + totalMinutesOffset, struct.second, struct.millisecond);
52189
+ }
52190
+ function parseDateStruct(date) {
52191
+ var _regexResult$7$length, _regexResult$;
52192
+ const regexResult = isoReg.exec(date);
52193
+ if (!regexResult) return null;
52194
+
52195
+ // use of toNumber() avoids NaN timestamps caused by “undefined”
52196
+ // values being passed to Date constructor
52197
+ return {
52198
+ year: toNumber(regexResult[1]),
52199
+ month: toNumber(regexResult[2], 1) - 1,
52200
+ day: toNumber(regexResult[3], 1),
52201
+ hour: toNumber(regexResult[4]),
52202
+ minute: toNumber(regexResult[5]),
52203
+ second: toNumber(regexResult[6]),
52204
+ millisecond: regexResult[7] ?
52205
+ // allow arbitrary sub-second precision beyond milliseconds
52206
+ toNumber(regexResult[7].substring(0, 3)) : 0,
52207
+ precision: (_regexResult$7$length = (_regexResult$ = regexResult[7]) == null ? void 0 : _regexResult$.length) != null ? _regexResult$7$length : undefined,
52208
+ z: regexResult[8] || undefined,
52209
+ plusMinus: regexResult[9] || undefined,
52210
+ hourOffset: toNumber(regexResult[10]),
52211
+ minuteOffset: toNumber(regexResult[11])
52212
+ };
52213
+ }
52214
+ function toNumber(str, defaultValue = 0) {
52215
+ return Number(str) || defaultValue;
52216
+ }
52217
+
52218
+ // Taken from HTML spec: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
52219
+ let rEmail =
52220
+ // eslint-disable-next-line
52221
+ /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
52222
+ let rUrl =
52223
+ // eslint-disable-next-line
52224
+ /^((https?|ftp):)?\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
52225
+
52226
+ // eslint-disable-next-line
52227
+ let rUUID = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
52228
+ let yearMonthDay = '^\\d{4}-\\d{2}-\\d{2}';
52229
+ let hourMinuteSecond = '\\d{2}:\\d{2}:\\d{2}';
52230
+ let zOrOffset = '(([+-]\\d{2}(:?\\d{2})?)|Z)';
52231
+ let rIsoDateTime = new RegExp(`${yearMonthDay}T${hourMinuteSecond}(\\.\\d+)?${zOrOffset}$`);
52232
+ let isTrimmed = value => isAbsent(value) || value === value.trim();
52233
+ let objStringTag = {}.toString();
52234
+ function create$6() {
52235
+ return new StringSchema();
52236
+ }
52237
+ class StringSchema extends Schema {
52238
+ constructor() {
52239
+ super({
52240
+ type: 'string',
52241
+ check(value) {
52242
+ if (value instanceof String) value = value.valueOf();
52243
+ return typeof value === 'string';
52244
+ }
52245
+ });
52246
+ this.withMutation(() => {
52247
+ this.transform((value, _raw, ctx) => {
52248
+ if (!ctx.spec.coerce || ctx.isType(value)) return value;
52249
+
52250
+ // don't ever convert arrays
52251
+ if (Array.isArray(value)) return value;
52252
+ const strValue = value != null && value.toString ? value.toString() : value;
52253
+
52254
+ // no one wants plain objects converted to [Object object]
52255
+ if (strValue === objStringTag) return value;
52256
+ return strValue;
52257
+ });
52258
+ });
52259
+ }
52260
+ required(message) {
52261
+ return super.required(message).withMutation(schema => schema.test({
52262
+ message: message || mixed.required,
52263
+ name: 'required',
52264
+ skipAbsent: true,
52265
+ test: value => !!value.length
52266
+ }));
52267
+ }
52268
+ notRequired() {
52269
+ return super.notRequired().withMutation(schema => {
52270
+ schema.tests = schema.tests.filter(t => t.OPTIONS.name !== 'required');
52271
+ return schema;
52272
+ });
52273
+ }
52274
+ length(length, message = string.length) {
52275
+ return this.test({
52276
+ message,
52277
+ name: 'length',
52278
+ exclusive: true,
52279
+ params: {
52280
+ length
52281
+ },
52282
+ skipAbsent: true,
52283
+ test(value) {
52284
+ return value.length === this.resolve(length);
52285
+ }
52286
+ });
52287
+ }
52288
+ min(min, message = string.min) {
52289
+ return this.test({
52290
+ message,
52291
+ name: 'min',
52292
+ exclusive: true,
52293
+ params: {
52294
+ min
52295
+ },
52296
+ skipAbsent: true,
52297
+ test(value) {
52298
+ return value.length >= this.resolve(min);
52299
+ }
52300
+ });
52301
+ }
52302
+ max(max, message = string.max) {
52303
+ return this.test({
52304
+ name: 'max',
52305
+ exclusive: true,
52306
+ message,
52307
+ params: {
52308
+ max
52309
+ },
52310
+ skipAbsent: true,
52311
+ test(value) {
52312
+ return value.length <= this.resolve(max);
52313
+ }
52314
+ });
52315
+ }
52316
+ matches(regex, options) {
52317
+ let excludeEmptyString = false;
52318
+ let message;
52319
+ let name;
52320
+ if (options) {
52321
+ if (typeof options === 'object') {
52322
+ ({
52323
+ excludeEmptyString = false,
52324
+ message,
52325
+ name
52326
+ } = options);
52327
+ } else {
52328
+ message = options;
52329
+ }
52330
+ }
52331
+ return this.test({
52332
+ name: name || 'matches',
52333
+ message: message || string.matches,
52334
+ params: {
52335
+ regex
52336
+ },
52337
+ skipAbsent: true,
52338
+ test: value => value === '' && excludeEmptyString || value.search(regex) !== -1
52339
+ });
52340
+ }
52341
+ email(message = string.email) {
52342
+ return this.matches(rEmail, {
52343
+ name: 'email',
52344
+ message,
52345
+ excludeEmptyString: true
52346
+ });
52347
+ }
52348
+ url(message = string.url) {
52349
+ return this.matches(rUrl, {
52350
+ name: 'url',
52351
+ message,
52352
+ excludeEmptyString: true
52353
+ });
52354
+ }
52355
+ uuid(message = string.uuid) {
52356
+ return this.matches(rUUID, {
52357
+ name: 'uuid',
52358
+ message,
52359
+ excludeEmptyString: false
52360
+ });
52361
+ }
52362
+ datetime(options) {
52363
+ let message = '';
52364
+ let allowOffset;
52365
+ let precision;
52366
+ if (options) {
52367
+ if (typeof options === 'object') {
52368
+ ({
52369
+ message = '',
52370
+ allowOffset = false,
52371
+ precision = undefined
52372
+ } = options);
52373
+ } else {
52374
+ message = options;
52375
+ }
52376
+ }
52377
+ return this.matches(rIsoDateTime, {
52378
+ name: 'datetime',
52379
+ message: message || string.datetime,
52380
+ excludeEmptyString: true
52381
+ }).test({
52382
+ name: 'datetime_offset',
52383
+ message: message || string.datetime_offset,
52384
+ params: {
52385
+ allowOffset
52386
+ },
52387
+ skipAbsent: true,
52388
+ test: value => {
52389
+ if (!value || allowOffset) return true;
52390
+ const struct = parseDateStruct(value);
52391
+ if (!struct) return false;
52392
+ return !!struct.z;
52393
+ }
52394
+ }).test({
52395
+ name: 'datetime_precision',
52396
+ message: message || string.datetime_precision,
52397
+ params: {
52398
+ precision
52399
+ },
52400
+ skipAbsent: true,
52401
+ test: value => {
52402
+ if (!value || precision == undefined) return true;
52403
+ const struct = parseDateStruct(value);
52404
+ if (!struct) return false;
52405
+ return struct.precision === precision;
52406
+ }
52407
+ });
52408
+ }
52409
+
52410
+ //-- transforms --
52411
+ ensure() {
52412
+ return this.default('').transform(val => val === null ? '' : val);
52413
+ }
52414
+ trim(message = string.trim) {
52415
+ return this.transform(val => val != null ? val.trim() : val).test({
52416
+ message,
52417
+ name: 'trim',
52418
+ test: isTrimmed
52419
+ });
52420
+ }
52421
+ lowercase(message = string.lowercase) {
52422
+ return this.transform(value => !isAbsent(value) ? value.toLowerCase() : value).test({
52423
+ message,
52424
+ name: 'string_case',
52425
+ exclusive: true,
52426
+ skipAbsent: true,
52427
+ test: value => isAbsent(value) || value === value.toLowerCase()
52428
+ });
52429
+ }
52430
+ uppercase(message = string.uppercase) {
52431
+ return this.transform(value => !isAbsent(value) ? value.toUpperCase() : value).test({
52432
+ message,
52433
+ name: 'string_case',
52434
+ exclusive: true,
52435
+ skipAbsent: true,
52436
+ test: value => isAbsent(value) || value === value.toUpperCase()
52437
+ });
52438
+ }
52439
+ }
52440
+ create$6.prototype = StringSchema.prototype;
52441
+
52442
+ //
52443
+ // String Interfaces
52444
+ //
52445
+
52446
+ let isNaN$1 = value => value != +value;
52447
+ function create$5() {
52448
+ return new NumberSchema();
52449
+ }
52450
+ class NumberSchema extends Schema {
52451
+ constructor() {
52452
+ super({
52453
+ type: 'number',
52454
+ check(value) {
52455
+ if (value instanceof Number) value = value.valueOf();
52456
+ return typeof value === 'number' && !isNaN$1(value);
52457
+ }
52458
+ });
52459
+ this.withMutation(() => {
52460
+ this.transform((value, _raw, ctx) => {
52461
+ if (!ctx.spec.coerce) return value;
52462
+ let parsed = value;
52463
+ if (typeof parsed === 'string') {
52464
+ parsed = parsed.replace(/\s/g, '');
52465
+ if (parsed === '') return NaN;
52466
+ // don't use parseFloat to avoid positives on alpha-numeric strings
52467
+ parsed = +parsed;
52468
+ }
52469
+
52470
+ // null -> NaN isn't useful; treat all nulls as null and let it fail on
52471
+ // nullability check vs TypeErrors
52472
+ if (ctx.isType(parsed) || parsed === null) return parsed;
52473
+ return parseFloat(parsed);
52474
+ });
52475
+ });
52476
+ }
52477
+ min(min, message = number.min) {
52478
+ return this.test({
52479
+ message,
52480
+ name: 'min',
52481
+ exclusive: true,
52482
+ params: {
52483
+ min
52484
+ },
52485
+ skipAbsent: true,
52486
+ test(value) {
52487
+ return value >= this.resolve(min);
52488
+ }
52489
+ });
52490
+ }
52491
+ max(max, message = number.max) {
52492
+ return this.test({
52493
+ message,
52494
+ name: 'max',
52495
+ exclusive: true,
52496
+ params: {
52497
+ max
52498
+ },
52499
+ skipAbsent: true,
52500
+ test(value) {
52501
+ return value <= this.resolve(max);
52502
+ }
52503
+ });
52504
+ }
52505
+ lessThan(less, message = number.lessThan) {
52506
+ return this.test({
52507
+ message,
52508
+ name: 'max',
52509
+ exclusive: true,
52510
+ params: {
52511
+ less
52512
+ },
52513
+ skipAbsent: true,
52514
+ test(value) {
52515
+ return value < this.resolve(less);
52516
+ }
52517
+ });
52518
+ }
52519
+ moreThan(more, message = number.moreThan) {
52520
+ return this.test({
52521
+ message,
52522
+ name: 'min',
52523
+ exclusive: true,
52524
+ params: {
52525
+ more
52526
+ },
52527
+ skipAbsent: true,
52528
+ test(value) {
52529
+ return value > this.resolve(more);
52530
+ }
52531
+ });
52532
+ }
52533
+ positive(msg = number.positive) {
52534
+ return this.moreThan(0, msg);
52535
+ }
52536
+ negative(msg = number.negative) {
52537
+ return this.lessThan(0, msg);
52538
+ }
52539
+ integer(message = number.integer) {
52540
+ return this.test({
52541
+ name: 'integer',
52542
+ message,
52543
+ skipAbsent: true,
52544
+ test: val => Number.isInteger(val)
52545
+ });
52546
+ }
52547
+ truncate() {
52548
+ return this.transform(value => !isAbsent(value) ? value | 0 : value);
52549
+ }
52550
+ round(method) {
52551
+ var _method;
52552
+ let avail = ['ceil', 'floor', 'round', 'trunc'];
52553
+ method = ((_method = method) == null ? void 0 : _method.toLowerCase()) || 'round';
52554
+
52555
+ // this exists for symemtry with the new Math.trunc
52556
+ if (method === 'trunc') return this.truncate();
52557
+ if (avail.indexOf(method.toLowerCase()) === -1) throw new TypeError('Only valid options for round() are: ' + avail.join(', '));
52558
+ return this.transform(value => !isAbsent(value) ? Math[method](value) : value);
52559
+ }
52560
+ }
52561
+ create$5.prototype = NumberSchema.prototype;
52562
+
52563
+ //
52564
+ // Number Interfaces
52565
+ //
52566
+
52567
+ let invalidDate = new Date('');
52568
+ let isDate = obj => Object.prototype.toString.call(obj) === '[object Date]';
52569
+ class DateSchema extends Schema {
52570
+ constructor() {
52571
+ super({
52572
+ type: 'date',
52573
+ check(v) {
52574
+ return isDate(v) && !isNaN(v.getTime());
52575
+ }
52576
+ });
52577
+ this.withMutation(() => {
52578
+ this.transform((value, _raw, ctx) => {
52579
+ // null -> InvalidDate isn't useful; treat all nulls as null and let it fail on
52580
+ // nullability check vs TypeErrors
52581
+ if (!ctx.spec.coerce || ctx.isType(value) || value === null) return value;
52582
+ value = parseIsoDate(value);
52583
+
52584
+ // 0 is a valid timestamp equivalent to 1970-01-01T00:00:00Z(unix epoch) or before.
52585
+ return !isNaN(value) ? new Date(value) : DateSchema.INVALID_DATE;
52586
+ });
52587
+ });
52588
+ }
52589
+ prepareParam(ref, name) {
52590
+ let param;
52591
+ if (!Reference.isRef(ref)) {
52592
+ let cast = this.cast(ref);
52593
+ if (!this._typeCheck(cast)) throw new TypeError(`\`${name}\` must be a Date or a value that can be \`cast()\` to a Date`);
52594
+ param = cast;
52595
+ } else {
52596
+ param = ref;
52597
+ }
52598
+ return param;
52599
+ }
52600
+ min(min, message = date.min) {
52601
+ let limit = this.prepareParam(min, 'min');
52602
+ return this.test({
52603
+ message,
52604
+ name: 'min',
52605
+ exclusive: true,
52606
+ params: {
52607
+ min
52608
+ },
52609
+ skipAbsent: true,
52610
+ test(value) {
52611
+ return value >= this.resolve(limit);
52612
+ }
52613
+ });
52614
+ }
52615
+ max(max, message = date.max) {
52616
+ let limit = this.prepareParam(max, 'max');
52617
+ return this.test({
52618
+ message,
52619
+ name: 'max',
52620
+ exclusive: true,
52621
+ params: {
52622
+ max
52623
+ },
52624
+ skipAbsent: true,
52625
+ test(value) {
52626
+ return value <= this.resolve(limit);
52627
+ }
52628
+ });
52629
+ }
52630
+ }
52631
+ DateSchema.INVALID_DATE = invalidDate;
52632
+ DateSchema.prototype;
52633
+
52634
+ // @ts-expect-error
52635
+ function sortFields(fields, excludedEdges = []) {
52636
+ let edges = [];
52637
+ let nodes = new Set();
52638
+ let excludes = new Set(excludedEdges.map(([a, b]) => `${a}-${b}`));
52639
+ function addNode(depPath, key) {
52640
+ let node = propertyExpr.split(depPath)[0];
52641
+ nodes.add(node);
52642
+ if (!excludes.has(`${key}-${node}`)) edges.push([key, node]);
52643
+ }
52644
+ for (const key of Object.keys(fields)) {
52645
+ let value = fields[key];
52646
+ nodes.add(key);
52647
+ if (Reference.isRef(value) && value.isSibling) addNode(value.path, key);else if (isSchema(value) && 'deps' in value) value.deps.forEach(path => addNode(path, key));
52648
+ }
52649
+ return toposort$1.array(Array.from(nodes), edges).reverse();
52650
+ }
52651
+
52652
+ function findIndex(arr, err) {
52653
+ let idx = Infinity;
52654
+ arr.some((key, ii) => {
52655
+ var _err$path;
52656
+ if ((_err$path = err.path) != null && _err$path.includes(key)) {
52657
+ idx = ii;
52658
+ return true;
52659
+ }
52660
+ });
52661
+ return idx;
52662
+ }
52663
+ function sortByKeyOrder(keys) {
52664
+ return (a, b) => {
52665
+ return findIndex(keys, a) - findIndex(keys, b);
52666
+ };
52667
+ }
52668
+
52669
+ const parseJson = (value, _, ctx) => {
52670
+ if (typeof value !== 'string') {
52671
+ return value;
52672
+ }
52673
+ let parsed = value;
52674
+ try {
52675
+ parsed = JSON.parse(value);
52676
+ } catch (err) {
52677
+ /* */
52678
+ }
52679
+ return ctx.isType(parsed) ? parsed : value;
52680
+ };
52681
+
52682
+ // @ts-ignore
52683
+ function deepPartial(schema) {
52684
+ if ('fields' in schema) {
52685
+ const partial = {};
52686
+ for (const [key, fieldSchema] of Object.entries(schema.fields)) {
52687
+ partial[key] = deepPartial(fieldSchema);
52688
+ }
52689
+ return schema.setFields(partial);
52690
+ }
52691
+ if (schema.type === 'array') {
52692
+ const nextArray = schema.optional();
52693
+ if (nextArray.innerType) nextArray.innerType = deepPartial(nextArray.innerType);
52694
+ return nextArray;
52695
+ }
52696
+ if (schema.type === 'tuple') {
52697
+ return schema.optional().clone({
52698
+ types: schema.spec.types.map(deepPartial)
52699
+ });
52700
+ }
52701
+ if ('optional' in schema) {
52702
+ return schema.optional();
52703
+ }
52704
+ return schema;
52705
+ }
52706
+ const deepHas = (obj, p) => {
52707
+ const path = [...propertyExpr.normalizePath(p)];
52708
+ if (path.length === 1) return path[0] in obj;
52709
+ let last = path.pop();
52710
+ let parent = propertyExpr.getter(propertyExpr.join(path), true)(obj);
52711
+ return !!(parent && last in parent);
52712
+ };
52713
+ let isObject = obj => Object.prototype.toString.call(obj) === '[object Object]';
52714
+ function unknown(ctx, value) {
52715
+ let known = Object.keys(ctx.fields);
52716
+ return Object.keys(value).filter(key => known.indexOf(key) === -1);
52717
+ }
52718
+ const defaultSort = sortByKeyOrder([]);
52719
+ function create$3(spec) {
52720
+ return new ObjectSchema(spec);
52721
+ }
52722
+ class ObjectSchema extends Schema {
52723
+ constructor(spec) {
52724
+ super({
52725
+ type: 'object',
52726
+ check(value) {
52727
+ return isObject(value) || typeof value === 'function';
52728
+ }
52729
+ });
52730
+ this.fields = Object.create(null);
52731
+ this._sortErrors = defaultSort;
52732
+ this._nodes = [];
52733
+ this._excludedEdges = [];
52734
+ this.withMutation(() => {
52735
+ if (spec) {
52736
+ this.shape(spec);
52737
+ }
52738
+ });
52739
+ }
52740
+ _cast(_value, options = {}) {
52741
+ var _options$stripUnknown;
52742
+ let value = super._cast(_value, options);
52743
+
52744
+ //should ignore nulls here
52745
+ if (value === undefined) return this.getDefault(options);
52746
+ if (!this._typeCheck(value)) return value;
52747
+ let fields = this.fields;
52748
+ let strip = (_options$stripUnknown = options.stripUnknown) != null ? _options$stripUnknown : this.spec.noUnknown;
52749
+ let props = [].concat(this._nodes, Object.keys(value).filter(v => !this._nodes.includes(v)));
52750
+ let intermediateValue = {}; // is filled during the transform below
52751
+ let innerOptions = Object.assign({}, options, {
52752
+ parent: intermediateValue,
52753
+ __validating: options.__validating || false
52754
+ });
52755
+ let isChanged = false;
52756
+ for (const prop of props) {
52757
+ let field = fields[prop];
52758
+ let exists = (prop in value);
52759
+ if (field) {
52760
+ let fieldValue;
52761
+ let inputValue = value[prop];
52762
+
52763
+ // safe to mutate since this is fired in sequence
52764
+ innerOptions.path = (options.path ? `${options.path}.` : '') + prop;
52765
+ field = field.resolve({
52766
+ value: inputValue,
52767
+ context: options.context,
52768
+ parent: intermediateValue
52769
+ });
52770
+ let fieldSpec = field instanceof Schema ? field.spec : undefined;
52771
+ let strict = fieldSpec == null ? void 0 : fieldSpec.strict;
52772
+ if (fieldSpec != null && fieldSpec.strip) {
52773
+ isChanged = isChanged || prop in value;
52774
+ continue;
52775
+ }
52776
+ fieldValue = !options.__validating || !strict ?
52777
+ // TODO: use _cast, this is double resolving
52778
+ field.cast(value[prop], innerOptions) : value[prop];
52779
+ if (fieldValue !== undefined) {
52780
+ intermediateValue[prop] = fieldValue;
52781
+ }
52782
+ } else if (exists && !strip) {
52783
+ intermediateValue[prop] = value[prop];
52784
+ }
52785
+ if (exists !== prop in intermediateValue || intermediateValue[prop] !== value[prop]) {
52786
+ isChanged = true;
52787
+ }
52788
+ }
52789
+ return isChanged ? intermediateValue : value;
52790
+ }
52791
+ _validate(_value, options = {}, panic, next) {
52792
+ let {
52793
+ from = [],
52794
+ originalValue = _value,
52795
+ recursive = this.spec.recursive
52796
+ } = options;
52797
+ options.from = [{
52798
+ schema: this,
52799
+ value: originalValue
52800
+ }, ...from];
52801
+ // this flag is needed for handling `strict` correctly in the context of
52802
+ // validation vs just casting. e.g strict() on a field is only used when validating
52803
+ options.__validating = true;
52804
+ options.originalValue = originalValue;
52805
+ super._validate(_value, options, panic, (objectErrors, value) => {
52806
+ if (!recursive || !isObject(value)) {
52807
+ next(objectErrors, value);
52808
+ return;
52809
+ }
52810
+ originalValue = originalValue || value;
52811
+ let tests = [];
52812
+ for (let key of this._nodes) {
52813
+ let field = this.fields[key];
52814
+ if (!field || Reference.isRef(field)) {
52815
+ continue;
52816
+ }
52817
+ tests.push(field.asNestedTest({
52818
+ options,
52819
+ key,
52820
+ parent: value,
52821
+ parentPath: options.path,
52822
+ originalParent: originalValue
52823
+ }));
52824
+ }
52825
+ this.runTests({
52826
+ tests,
52827
+ value,
52828
+ originalValue,
52829
+ options
52830
+ }, panic, fieldErrors => {
52831
+ next(fieldErrors.sort(this._sortErrors).concat(objectErrors), value);
52832
+ });
52833
+ });
52834
+ }
52835
+ clone(spec) {
52836
+ const next = super.clone(spec);
52837
+ next.fields = Object.assign({}, this.fields);
52838
+ next._nodes = this._nodes;
52839
+ next._excludedEdges = this._excludedEdges;
52840
+ next._sortErrors = this._sortErrors;
52841
+ return next;
52842
+ }
52843
+ concat(schema) {
52844
+ let next = super.concat(schema);
52845
+ let nextFields = next.fields;
52846
+ for (let [field, schemaOrRef] of Object.entries(this.fields)) {
52847
+ const target = nextFields[field];
52848
+ nextFields[field] = target === undefined ? schemaOrRef : target;
52849
+ }
52850
+ return next.withMutation(s =>
52851
+ // XXX: excludes here is wrong
52852
+ s.setFields(nextFields, [...this._excludedEdges, ...schema._excludedEdges]));
52853
+ }
52854
+ _getDefault(options) {
52855
+ if ('default' in this.spec) {
52856
+ return super._getDefault(options);
52857
+ }
52858
+
52859
+ // if there is no default set invent one
52860
+ if (!this._nodes.length) {
52861
+ return undefined;
52862
+ }
52863
+ let dft = {};
52864
+ this._nodes.forEach(key => {
52865
+ var _innerOptions;
52866
+ const field = this.fields[key];
52867
+ let innerOptions = options;
52868
+ if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
52869
+ innerOptions = Object.assign({}, innerOptions, {
52870
+ parent: innerOptions.value,
52871
+ value: innerOptions.value[key]
52872
+ });
52873
+ }
52874
+ dft[key] = field && 'getDefault' in field ? field.getDefault(innerOptions) : undefined;
52875
+ });
52876
+ return dft;
52877
+ }
52878
+ setFields(shape, excludedEdges) {
52879
+ let next = this.clone();
52880
+ next.fields = shape;
52881
+ next._nodes = sortFields(shape, excludedEdges);
52882
+ next._sortErrors = sortByKeyOrder(Object.keys(shape));
52883
+ // XXX: this carries over edges which may not be what you want
52884
+ if (excludedEdges) next._excludedEdges = excludedEdges;
52885
+ return next;
52886
+ }
52887
+ shape(additions, excludes = []) {
52888
+ return this.clone().withMutation(next => {
52889
+ let edges = next._excludedEdges;
52890
+ if (excludes.length) {
52891
+ if (!Array.isArray(excludes[0])) excludes = [excludes];
52892
+ edges = [...next._excludedEdges, ...excludes];
52893
+ }
52894
+
52895
+ // XXX: excludes here is wrong
52896
+ return next.setFields(Object.assign(next.fields, additions), edges);
52897
+ });
52898
+ }
52899
+ partial() {
52900
+ const partial = {};
52901
+ for (const [key, schema] of Object.entries(this.fields)) {
52902
+ partial[key] = 'optional' in schema && schema.optional instanceof Function ? schema.optional() : schema;
52903
+ }
52904
+ return this.setFields(partial);
52905
+ }
52906
+ deepPartial() {
52907
+ const next = deepPartial(this);
52908
+ return next;
52909
+ }
52910
+ pick(keys) {
52911
+ const picked = {};
52912
+ for (const key of keys) {
52913
+ if (this.fields[key]) picked[key] = this.fields[key];
52914
+ }
52915
+ return this.setFields(picked, this._excludedEdges.filter(([a, b]) => keys.includes(a) && keys.includes(b)));
52916
+ }
52917
+ omit(keys) {
52918
+ const remaining = [];
52919
+ for (const key of Object.keys(this.fields)) {
52920
+ if (keys.includes(key)) continue;
52921
+ remaining.push(key);
52922
+ }
52923
+ return this.pick(remaining);
52924
+ }
52925
+ from(from, to, alias) {
52926
+ let fromGetter = propertyExpr.getter(from, true);
52927
+ return this.transform(obj => {
52928
+ if (!obj) return obj;
52929
+ let newObj = obj;
52930
+ if (deepHas(obj, from)) {
52931
+ newObj = Object.assign({}, obj);
52932
+ if (!alias) delete newObj[from];
52933
+ newObj[to] = fromGetter(obj);
52934
+ }
52935
+ return newObj;
52936
+ });
52937
+ }
52938
+
52939
+ /** Parse an input JSON string to an object */
52940
+ json() {
52941
+ return this.transform(parseJson);
52942
+ }
52943
+ noUnknown(noAllow = true, message = object.noUnknown) {
52944
+ if (typeof noAllow !== 'boolean') {
52945
+ message = noAllow;
52946
+ noAllow = true;
52947
+ }
52948
+ let next = this.test({
52949
+ name: 'noUnknown',
52950
+ exclusive: true,
52951
+ message: message,
52952
+ test(value) {
52953
+ if (value == null) return true;
52954
+ const unknownKeys = unknown(this.schema, value);
52955
+ return !noAllow || unknownKeys.length === 0 || this.createError({
52956
+ params: {
52957
+ unknown: unknownKeys.join(', ')
52958
+ }
52959
+ });
52960
+ }
52961
+ });
52962
+ next.spec.noUnknown = noAllow;
52963
+ return next;
52964
+ }
52965
+ unknown(allow = true, message = object.noUnknown) {
52966
+ return this.noUnknown(!allow, message);
52967
+ }
52968
+ transformKeys(fn) {
52969
+ return this.transform(obj => {
52970
+ if (!obj) return obj;
52971
+ const result = {};
52972
+ for (const key of Object.keys(obj)) result[fn(key)] = obj[key];
52973
+ return result;
52974
+ });
52975
+ }
52976
+ camelCase() {
52977
+ return this.transformKeys(tinyCase.camelCase);
52978
+ }
52979
+ snakeCase() {
52980
+ return this.transformKeys(tinyCase.snakeCase);
52981
+ }
52982
+ constantCase() {
52983
+ return this.transformKeys(key => tinyCase.snakeCase(key).toUpperCase());
52984
+ }
52985
+ describe(options) {
52986
+ const next = (options ? this.resolve(options) : this).clone();
52987
+ const base = super.describe(options);
52988
+ base.fields = {};
52989
+ for (const [key, value] of Object.entries(next.fields)) {
52990
+ var _innerOptions2;
52991
+ let innerOptions = options;
52992
+ if ((_innerOptions2 = innerOptions) != null && _innerOptions2.value) {
52993
+ innerOptions = Object.assign({}, innerOptions, {
52994
+ parent: innerOptions.value,
52995
+ value: innerOptions.value[key]
52996
+ });
52997
+ }
52998
+ base.fields[key] = value.describe(innerOptions);
52999
+ }
53000
+ return base;
53001
+ }
53002
+ }
53003
+ create$3.prototype = ObjectSchema.prototype;
53004
+
53005
+ const useFormValidatingContext = (formArray) => {
53006
+ const initialValues = {};
53007
+ const validationShape = {};
53008
+ formArray.forEach((field) => {
53009
+ switch (field.inputType) {
53010
+ case "text":
53011
+ initialValues[field.name] = "";
53012
+ if (field.required) {
53013
+ validationShape[field.name] = create$6()
53014
+ .typeError(`Select ${field.label}`)
53015
+ .required(field.errorMessage);
53016
+ }
53017
+ break;
53018
+ case "number":
53019
+ initialValues[field.name] = null;
53020
+ if (field.required) {
53021
+ validationShape[field.name] = create$5()
53022
+ .nullable()
53023
+ .typeError(`Enters ${field.label}`)
53024
+ .required(field.errorMessage);
53025
+ }
53026
+ break;
53027
+ case "password":
53028
+ initialValues[field.name] = "";
53029
+ if (field.required) {
53030
+ validationShape[field.name] = create$5()
53031
+ .nullable()
53032
+ .typeError(`Enters ${field.label}`)
53033
+ .required(field.errorMessage);
53034
+ }
53035
+ break;
53036
+ case "select":
53037
+ initialValues[field.name] = "";
53038
+ if (field.required) {
53039
+ validationShape[field.name] = create$6()
53040
+ .typeError(`Select ${field.label}`)
53041
+ .required(field.errorMessage);
53042
+ }
53043
+ break;
53044
+ case "multiselect":
53045
+ initialValues[field.name] = null;
53046
+ if (field.required) {
53047
+ validationShape[field.name] = validationShape[field.name] =
53048
+ create$6()
53049
+ .typeError(`Select atleast one ${field.label}`)
53050
+ .required(field.errorMessage);
53051
+ }
53052
+ break;
53053
+ case "datepicker":
53054
+ initialValues[field.name] = null;
53055
+ if (field.required) {
53056
+ validationShape[field.name] = validationShape[field.name] =
53057
+ create$6()
53058
+ .typeError(`Select ${field.label}`)
53059
+ .required(field.errorMessage);
53060
+ }
53061
+ break;
53062
+ case "dateRangePicker":
53063
+ const today = new Date();
53064
+ const day = String(today.getDate()).padStart(2, "0");
53065
+ const month = String(today.getMonth() + 1).padStart(2, "0"); // January is 0!
53066
+ const year = today.getFullYear();
53067
+ const formattedDate = `${day}/${month}/${year}`;
53068
+ const threeMonthsAgo = new Date(today);
53069
+ threeMonthsAgo.setMonth(today.getMonth() - 3);
53070
+ const dayBeforeThreeMonths = String(threeMonthsAgo.getDate()).padStart(2, "0");
53071
+ const monthBeforeThreeMonths = String(threeMonthsAgo.getMonth() + 1).padStart(2, "0"); // January is 0!
53072
+ const yearBeforeThreeMonths = threeMonthsAgo.getFullYear();
53073
+ const formattedDateForThreeMonths = `${dayBeforeThreeMonths}/${monthBeforeThreeMonths}/${yearBeforeThreeMonths}`;
53074
+ initialValues["FromDate"] = formattedDateForThreeMonths;
53075
+ initialValues["ToDate"] = formattedDate;
53076
+ if (field.required) {
53077
+ validationShape[field.name] = validationShape[field.name] =
53078
+ create$6()
53079
+ .typeError(`Select ${field.label}`)
53080
+ .required(field.errorMessage);
53081
+ }
53082
+ break;
53083
+ default:
53084
+ initialValues[field.name] = null; // default value if inputType is not recognized
53085
+ if (field.required) {
53086
+ validationShape[field.name] = create$8().required(field.errorMessage);
53087
+ }
53088
+ break;
53089
+ }
53090
+ });
53091
+ const validationSchema = create$3().shape(validationShape);
53092
+ return { validationSchema, initialValues };
53093
+ };
53094
+
50768
53095
  exports.Button = Button$1;
50769
53096
  exports.RenderForm = FormRenderWrapper;
53097
+ exports.useFormValidatingContext = useFormValidatingContext;
50770
53098
  //# sourceMappingURL=index.js.map