tods-competition-factory 1.9.4 → 1.9.5

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.
@@ -1828,1203 +1828,291 @@ function globalLog$1(engine, log) {
1828
1828
  }
1829
1829
  }
1830
1830
 
1831
- var validDateString = /^[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1])$/;
1832
- var validTimeString = /^((0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)([.,][0-9]{3})?$/;
1833
- var dateValidation = /^([\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]))([ T](0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)?([.,][\d]{3})?Z?$/;
1834
- var timeValidation = /^([\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]))?([ T]?(0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)?([.,][\d]{3})?Z?$/;
1831
+ function getDefinedKeys(obj, ignoreValues, ignoreEmptyArrays) {
1832
+ return Object.keys(obj).filter(function (key) {
1833
+ return !ignoreValues.includes(obj[key]) &&
1834
+ (!ignoreEmptyArrays || (Array.isArray(obj[key]) ? obj[key].length : true));
1835
+ });
1836
+ }
1837
+ function definedAttributes(obj, ignoreFalse, ignoreEmptyArrays, shallow) {
1838
+ if (typeof obj !== 'object' || obj === null)
1839
+ return obj;
1840
+ var deepCopy = deepCopyEnabled();
1841
+ if (!(deepCopy === null || deepCopy === void 0 ? void 0 : deepCopy.enabled))
1842
+ shallow = true;
1843
+ var ignoreValues = ['', undefined, null];
1844
+ if (ignoreFalse)
1845
+ ignoreValues.push(false);
1846
+ var definedKeys = getDefinedKeys(obj, ignoreValues, ignoreEmptyArrays);
1847
+ return Object.assign.apply(Object, __spreadArray([{}], __read(definedKeys.map(function (key) {
1848
+ var _a, _b;
1849
+ return Array.isArray(obj[key])
1850
+ ? (_a = {},
1851
+ _a[key] = shallow
1852
+ ? obj[key]
1853
+ : obj[key].map(function (m) { return definedAttributes(m); }),
1854
+ _a) : (_b = {}, _b[key] = shallow ? obj[key] : definedAttributes(obj[key]), _b);
1855
+ })), false));
1856
+ }
1835
1857
 
1836
- function getIsoDateString(schedule) {
1837
- var scheduledDate = schedule.scheduledDate;
1838
- if (!scheduledDate && schedule.scheduledTime)
1839
- scheduledDate = extractDate(schedule.scheduledTime);
1840
- if (!scheduledDate)
1841
- return;
1842
- var extractedTime = extractTime(schedule.scheduledTime);
1843
- var isoDateString = extractDate(scheduledDate);
1844
- if (isoDateString && extractedTime)
1845
- isoDateString += "T".concat(extractedTime);
1846
- return isoDateString;
1858
+ function parse(matchUpFormatCode) {
1859
+ if (typeof matchUpFormatCode === 'string') {
1860
+ var type = (matchUpFormatCode.startsWith('T') && TIMED) ||
1861
+ (matchUpFormatCode.startsWith(SET) && SET) ||
1862
+ '';
1863
+ if (type === TIMED) {
1864
+ var setFormat = parseTimedSet(matchUpFormatCode);
1865
+ var parsedFormat = {
1866
+ simplified: true,
1867
+ setFormat: setFormat,
1868
+ bestOf: 1,
1869
+ };
1870
+ if (setFormat)
1871
+ return parsedFormat;
1872
+ }
1873
+ if (type === SET)
1874
+ return setsMatch(matchUpFormatCode);
1875
+ }
1876
+ return undefined;
1847
1877
  }
1848
- function isDateObject(value) {
1849
- if (typeof value !== 'object' || Array.isArray(value)) {
1850
- return false;
1878
+ function setsMatch(formatstring) {
1879
+ var parts = formatstring.split('-');
1880
+ var setsCount = getNumber(parts[0].slice(3));
1881
+ var bestOf = setsCount === 1 || setsCount % 2 !== 0 ? setsCount : undefined;
1882
+ var exactly = setsCount !== 1 && setsCount % 2 === 0 ? setsCount : undefined;
1883
+ var setFormat = parts && parseSetFormat(parts[1]);
1884
+ var finalSetFormat = parts && parseSetFormat(parts[2]);
1885
+ var timed = (setFormat && setFormat.timed) || (finalSetFormat && finalSetFormat.timed);
1886
+ var validSetsCount = (bestOf && bestOf < 6) || (timed && exactly);
1887
+ var validFinalSet = !parts[2] || finalSetFormat;
1888
+ var validSetsFormat = setFormat;
1889
+ var result = definedAttributes({
1890
+ setFormat: setFormat,
1891
+ exactly: exactly,
1892
+ bestOf: bestOf,
1893
+ });
1894
+ if (finalSetFormat)
1895
+ result.finalSetFormat = finalSetFormat;
1896
+ if (validSetsCount && validSetsFormat && validFinalSet)
1897
+ return result;
1898
+ }
1899
+ function parseSetFormat(formatstring) {
1900
+ if ((formatstring === null || formatstring === void 0 ? void 0 : formatstring[1]) === ':') {
1901
+ var parts = formatstring.split(':');
1902
+ var setType = setTypes$1[parts[0]];
1903
+ var setFormatString = parts[1];
1904
+ if (setType && setFormatString) {
1905
+ var isTiebreakSet = setFormatString.indexOf('TB') === 0;
1906
+ if (isTiebreakSet) {
1907
+ var tiebreakSet = parseTiebreakFormat(setFormatString);
1908
+ if (tiebreakSet === false)
1909
+ return false;
1910
+ return typeof tiebreakSet === 'object' ? { tiebreakSet: tiebreakSet } : undefined;
1911
+ }
1912
+ var timedSet = setFormatString.indexOf('T') === 0;
1913
+ if (timedSet)
1914
+ return parseTimedSet(setFormatString);
1915
+ var parts_1 = formatstring.match(/^[FS]:(\d+)([A-Za-z]*)/);
1916
+ var NoAD = (parts_1 && isNoAD(parts_1[2])) || false;
1917
+ var validNoAD = !(parts_1 === null || parts_1 === void 0 ? void 0 : parts_1[2]) || NoAD;
1918
+ var setTo = parts_1 ? getNumber(parts_1[1]) : undefined;
1919
+ var tiebreakAtValue = parseTiebreakAt(setFormatString);
1920
+ var validTiebreakAt = tiebreakAtValue !== false;
1921
+ var tiebreakAt = (validTiebreakAt && tiebreakAtValue) || setTo;
1922
+ var tiebreakFormat = parseTiebreakFormat(setFormatString.split('/')[1]);
1923
+ var validTiebreak = tiebreakFormat !== false;
1924
+ var result = { setTo: setTo };
1925
+ if (NoAD)
1926
+ result.NoAD = true;
1927
+ if (tiebreakFormat) {
1928
+ result.tiebreakFormat = tiebreakFormat;
1929
+ result.tiebreakAt = tiebreakAt;
1930
+ }
1931
+ else {
1932
+ result.noTiebreak = true;
1933
+ }
1934
+ return ((setTo && validNoAD && validTiebreak && validTiebreakAt && result) ||
1935
+ false);
1936
+ }
1851
1937
  }
1852
- else {
1853
- var datePrototype = Object.prototype.toString.call(value);
1854
- return datePrototype === '[object Date]';
1938
+ return undefined;
1939
+ }
1940
+ function parseTiebreakAt(setFormatString, expectNumber) {
1941
+ if (expectNumber === void 0) { expectNumber = true; }
1942
+ var tiebreakAtValue = (setFormatString === null || setFormatString === void 0 ? void 0 : setFormatString.indexOf('@')) > 0 && setFormatString.split('@');
1943
+ if (tiebreakAtValue) {
1944
+ var tiebreakAt = expectNumber
1945
+ ? getNumber(tiebreakAtValue[1])
1946
+ : tiebreakAtValue[1];
1947
+ return tiebreakAt || false;
1855
1948
  }
1949
+ return undefined;
1856
1950
  }
1857
- function validTimeValue(value) {
1858
- var spaceSplit = typeof value === 'string' ? value === null || value === void 0 ? void 0 : value.split(' ') : [];
1859
- if (value &&
1860
- (spaceSplit === null || spaceSplit === void 0 ? void 0 : spaceSplit.length) > 1 &&
1861
- !['AM', 'PM'].includes(spaceSplit[1].toUpperCase()))
1862
- return false;
1863
- return !!(!value || timeValidation.test(convertTime(value, true, true)));
1951
+ function parseTiebreakFormat(formatstring) {
1952
+ if (formatstring) {
1953
+ if (formatstring.startsWith('TB')) {
1954
+ var modifier = parseTiebreakAt(formatstring, false);
1955
+ var parts = formatstring.match(/^TB(\d+)([A-Za-z]*)/);
1956
+ var tiebreakToString = parts === null || parts === void 0 ? void 0 : parts[1];
1957
+ var NoAD = parts && isNoAD(parts[2]);
1958
+ var validNoAD = !(parts === null || parts === void 0 ? void 0 : parts[2]) || NoAD;
1959
+ var tiebreakTo = getNumber(tiebreakToString);
1960
+ if (tiebreakTo && validNoAD) {
1961
+ var result = { tiebreakTo: tiebreakTo };
1962
+ // modifiers cannot be numeric
1963
+ if (modifier &&
1964
+ typeof modifier === 'string' &&
1965
+ !isConvertableInteger(modifier)) {
1966
+ result.modifier = modifier;
1967
+ }
1968
+ if (NoAD)
1969
+ result.NoAD = true;
1970
+ return result;
1971
+ }
1972
+ else {
1973
+ return false;
1974
+ }
1975
+ }
1976
+ else {
1977
+ return false;
1978
+ }
1979
+ }
1980
+ return undefined;
1864
1981
  }
1865
- function isValidDateString(scheduleDate) {
1866
- return isISODateString(scheduleDate) || validDateString.test(scheduleDate);
1982
+ function parseTimedSet(formatstring) {
1983
+ var _a;
1984
+ var timestring = formatstring.slice(1);
1985
+ var parts = timestring.match(/^(\d+)(@?[A-Za-z]*)/);
1986
+ var minutes = getNumber(parts === null || parts === void 0 ? void 0 : parts[1]);
1987
+ if (!minutes)
1988
+ return;
1989
+ var setFormat = { timed: true, minutes: minutes };
1990
+ var based = parts === null || parts === void 0 ? void 0 : parts[2];
1991
+ var validModifier = [undefined, 'P', 'G'].includes(based);
1992
+ if (based && !validModifier) {
1993
+ var modifier = (_a = timestring.match(/^(\d+)(@)([A-Za-z]+)$/)) === null || _a === void 0 ? void 0 : _a[3];
1994
+ if (modifier) {
1995
+ setFormat.modifier = modifier;
1996
+ return setFormat;
1997
+ }
1998
+ return;
1999
+ }
2000
+ if (based)
2001
+ setFormat.based = parts[2];
2002
+ return setFormat;
1867
2003
  }
1868
- function DateHHMM(date) {
1869
- var dt = new Date(date);
1870
- var secs = dt.getSeconds() + 60 * dt.getMinutes() + 60 * 60 * dt.getHours();
1871
- return HHMMSS(secs, { displaySeconds: false });
2004
+ function isNoAD(formatstring) {
2005
+ return formatstring && formatstring.indexOf(NOAD) >= 0;
1872
2006
  }
1873
- function HHMMSS(s, format) {
1874
- var secondNumber = parseInt(s, 10); // don't forget the second param
1875
- var hours = Math.floor(secondNumber / 3600);
1876
- var minutes = Math.floor((secondNumber - hours * 3600) / 60);
1877
- var seconds = secondNumber - hours * 3600 - minutes * 60;
1878
- var displaySeconds = !format || (format === null || format === void 0 ? void 0 : format.displaySeconds);
1879
- var timeString = displaySeconds
1880
- ? hours + ':' + minutes + ':' + seconds
1881
- : hours + ':' + minutes;
1882
- return timeString.split(':').map(zeroPad).join(':');
2007
+ function getNumber(formatstring) {
2008
+ return !isNaN(Number(formatstring)) ? Number(formatstring) : 0;
1883
2009
  }
1884
- var getUTCdateString = function (date) {
1885
- var dateDate = isDate(date) || isISODateString(date) ? new Date(date) : new Date();
1886
- var monthNumber = dateDate.getUTCMonth() + 1;
1887
- var utcMonth = monthNumber < 10 ? "0".concat(monthNumber) : "".concat(monthNumber);
1888
- return "".concat(dateDate.getUTCFullYear(), "-").concat(zeroPad(utcMonth), "-").concat(zeroPad(dateDate.getUTCDate()));
2010
+
2011
+ function isValid(matchUpFormat) {
2012
+ if (typeof matchUpFormat !== 'string')
2013
+ return false;
2014
+ var parsedFormat = parse(matchUpFormat);
2015
+ var setParts = matchUpFormat.match(/-S:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/);
2016
+ var setsTo = setParts === null || setParts === void 0 ? void 0 : setParts[1];
2017
+ var tiebreakTo = setParts === null || setParts === void 0 ? void 0 : setParts[2];
2018
+ var tiebreakAt = setParts === null || setParts === void 0 ? void 0 : setParts[3];
2019
+ var finalSetParts = matchUpFormat.match(/-F:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/);
2020
+ var finalSetTo = finalSetParts === null || finalSetParts === void 0 ? void 0 : finalSetParts[1];
2021
+ var finalSetTiebreakTo = finalSetParts === null || finalSetParts === void 0 ? void 0 : finalSetParts[2];
2022
+ var finalTiebreakAt = finalSetParts === null || finalSetParts === void 0 ? void 0 : finalSetParts[3];
2023
+ var preserveRedundant = !!((setParts && tiebreakTo && setsTo === tiebreakAt) ||
2024
+ (finalSetParts && finalSetTiebreakTo && finalSetTo === finalTiebreakAt));
2025
+ var stringified = stringify(parsedFormat, preserveRedundant);
2026
+ return stringified === matchUpFormat;
2027
+ }
2028
+
2029
+ var matchUpFormatCode = {
2030
+ isValidMatchUpFormat: isValid,
2031
+ stringify: stringify,
2032
+ isValid: isValid,
2033
+ parse: parse,
1889
2034
  };
1890
- function timeUTC(date) {
1891
- var dateDate = isDate(date) || isISODateString(date) ? new Date(date) : new Date();
1892
- return Date.UTC(dateDate.getFullYear(), dateDate.getMonth(), dateDate.getDate());
2035
+
2036
+ function factoryVersion() {
2037
+ return '1.9.5';
1893
2038
  }
1894
- function formatDate(date, separator, format) {
1895
- if (separator === void 0) { separator = '-'; }
1896
- if (format === void 0) { format = 'YMD'; }
1897
- if (!date)
1898
- return '';
1899
- if (typeof date === 'string' && date.indexOf('T') < 0)
1900
- date = date + 'T00:00';
1901
- var d = new Date(date);
1902
- var month = '' + (d.getMonth() + 1);
1903
- var day = '' + d.getDate();
1904
- var year = d.getFullYear();
1905
- if (month.length < 2)
1906
- month = '0' + month;
1907
- if (day.length < 2)
1908
- day = '0' + day;
1909
- if (format === 'DMY')
1910
- return [day, month, year].join(separator);
1911
- if (format === 'MDY')
1912
- return [month, day, year].join(separator);
1913
- if (format === 'YDM')
1914
- return [year, day, month].join(separator);
1915
- if (format === 'DYM')
1916
- return [day, year, month].join(separator);
1917
- if (format === 'MYD')
1918
- return [month, year, day].join(separator);
1919
- return [year, month, day].join(separator);
1920
- }
1921
- function offsetDate(date) {
1922
- var targetTime = date ? new Date(date) : new Date();
1923
- var tzDifference = targetTime.getTimezoneOffset();
1924
- return new Date(targetTime.getTime() - tzDifference * 60 * 1000);
1925
- }
1926
- function offsetTime(date) {
1927
- return offsetDate(date).getTime();
1928
- }
1929
- // only returns true for valid date objects
1930
- // dateArg = new Date('xxx') produces 'Invalid Date', which return false
1931
- function isDate(dateArg) {
1932
- if (typeof dateArg == 'boolean')
1933
- return false;
1934
- var t = (dateArg instanceof Date && dateArg) ||
1935
- (!isNaN(dateArg) && new Date(dateArg)) ||
1936
- false;
1937
- return t && !isNaN(t.valueOf());
1938
- }
1939
- function dateRange(startDt, endDt) {
1940
- if (!isValidDateString(startDt) || !isValidDateString(endDt))
1941
- return [];
1942
- var startDateString = extractDate(startDt) + 'T00:00';
1943
- var endDateString = extractDate(endDt) + 'T00:00';
1944
- var startDate = new Date(startDateString);
1945
- var endDate = new Date(endDateString);
1946
- var process = isDate(endDate) &&
1947
- isDate(startDate) &&
1948
- isValidDateRange(startDate, endDate);
1949
- var between = [];
1950
- var iterations = 0;
1951
- if (process) {
1952
- var currentDate = startDate;
1953
- var dateSecs = currentDate.getTime();
1954
- while (dateSecs <= endDate.getTime() && iterations < 300) {
1955
- iterations += 1;
1956
- // must be a *new* Date otherwise it is an array of the same object
1957
- between.push(new Date(currentDate));
1958
- dateSecs = currentDate.setDate(currentDate.getDate() + 1);
1959
- }
1960
- }
1961
- return between.map(function (date) { return formatDate(date); });
1962
- function isValidDateRange(minDate, maxDate) {
1963
- return minDate <= maxDate;
2039
+
2040
+ function getObjectTieFormat(obj) {
2041
+ if (!obj)
2042
+ return;
2043
+ var tieFormatId = obj.tieFormatId, tieFormats = obj.tieFormats;
2044
+ if (obj.tieFormat) {
2045
+ return obj.tieFormat;
1964
2046
  }
1965
- }
1966
- // matches valid ISO date string
1967
- var re = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
1968
- function isISODateString(dateString) {
1969
- if (typeof dateString !== 'string')
1970
- return false;
1971
- return re.test(dateString);
1972
- }
1973
- function isTimeString(timeString) {
1974
- if (typeof timeString !== 'string')
1975
- return false;
1976
- var noZ = timeString.split('Z')[0];
1977
- var parts = noZ.split(':');
1978
- var isNumeric = parts.every(function (part) { return !isNaN(parseInt(part)); });
1979
- var invalid = parts.length < 2 ||
1980
- !isNumeric ||
1981
- parseInt(parts[0]) > 23 ||
1982
- parseInt(parts[1]) > 60;
1983
- return !invalid;
1984
- }
1985
- function timeStringMinutes(timeString) {
1986
- var validTimeString = extractTime(timeString);
1987
- if (!validTimeString)
1988
- return 0;
1989
- var _a = __read(validTimeString
1990
- .split(':')
1991
- .map(function (value) { return parseInt(value); }), 2), hours = _a[0], minutes = _a[1];
1992
- return hours * 60 + minutes;
1993
- }
1994
- function dayMinutesToTimeString(totalMinutes) {
1995
- var hours = Math.floor(totalMinutes / 60);
1996
- var minutes = totalMinutes - hours * 60;
1997
- if (hours > 23)
1998
- hours = hours % 24;
1999
- return [zeroPad(hours), zeroPad(minutes)].join(':');
2000
- }
2001
- function tidyTime(timeString) {
2002
- return isTimeString(timeString)
2003
- ? timeString.split(':').slice(0, 2).map(zeroPad).join(':')
2004
- : undefined;
2005
- }
2006
- function extractTime(dateString) {
2007
- return isISODateString(dateString) && dateString.indexOf('T') > 0
2008
- ? tidyTime(dateString.split('T').reverse()[0])
2009
- : tidyTime(dateString);
2010
- }
2011
- function extractDate(dateString) {
2012
- return isISODateString(dateString) || dateValidation.test(dateString)
2013
- ? dateString.split('T')[0]
2014
- : undefined;
2015
- }
2016
- function dateStringDaysChange(dateString, daysChange) {
2017
- var date = new Date(dateString);
2018
- date.setDate(date.getDate() + daysChange);
2019
- return extractDate(date.toISOString());
2020
- }
2021
- function splitTime(value) {
2022
- var _a, _b;
2023
- value = typeof value !== 'string' ? '00:00' : value;
2024
- var o = {}, time = {};
2025
- (_a = value.split(' ') || [], o.time = _a[0], o.ampm = _a[1]);
2026
- (_b = o.time.split(':') || [], time.hours = _b[0], time.minutes = _b[1]);
2027
- time.ampm = o.ampm;
2028
- if (isNaN(time.hours) ||
2029
- isNaN(time.minutes) ||
2030
- (time.ampm && !['AM', 'PM'].includes(time.ampm.toUpperCase())))
2031
- return {};
2032
- return time;
2033
- }
2034
- function militaryTime(value) {
2035
- var time = splitTime(value);
2036
- if (time.ampm && time.hours) {
2037
- if (time.ampm.toLowerCase() === 'pm' && parseInt(time.hours) < 12)
2038
- time.hours = ((time.hours && parseInt(time.hours)) || 0) + 12;
2039
- if (time.ampm.toLowerCase() === 'am' && time.hours === '12')
2040
- time.hours = '00';
2047
+ else if (tieFormatId && Array.isArray(tieFormats)) {
2048
+ return tieFormats.find(function (tf) { return tf.tieFormatId === tieFormatId; });
2041
2049
  }
2042
- var timeString = "".concat(time.hours || '12', ":").concat(time.minutes || '00');
2043
- return timeString.split(':').map(zeroPad).join(':');
2044
2050
  }
2045
- function regularTime(value) {
2046
- var _a;
2047
- var time = splitTime(value);
2048
- if (typeof time === 'object' && !Object.keys(time).length)
2049
- return undefined;
2050
- if (time.ampm)
2051
- return value;
2052
- if (time.hours > 12) {
2053
- time.hours -= 12;
2054
- time.ampm = 'PM';
2051
+
2052
+ function getItemTieFormat(_a) {
2053
+ var _b, _c, _d;
2054
+ var item = _a.item, drawDefinition = _a.drawDefinition, structure = _a.structure, event = _a.event;
2055
+ if (!item)
2056
+ return;
2057
+ if (item.tieFormat)
2058
+ return item.tieFormat;
2059
+ // if there is a tieFormatId, only possible to look for referenced tieFormat in tieFormats on drawDefinition and event
2060
+ if (item.tieFormatId) {
2061
+ if (drawDefinition.tieFormat)
2062
+ return drawDefinition.tieFormat;
2063
+ var tieFormat = (_b = drawDefinition.tieFormats) === null || _b === void 0 ? void 0 : _b.find(function (tf) { return item.tieFormatId === tf.tieFormatId; });
2064
+ if (tieFormat)
2065
+ return tieFormat;
2066
+ if (event.tieFormat)
2067
+ return event.tieFormat;
2068
+ return (_c = event.tieFormats) === null || _c === void 0 ? void 0 : _c.find(function (tf) { return item.tieFormatId === tf.tieFormatId; });
2055
2069
  }
2056
- else if (time.hours === '12') {
2057
- time.ampm = 'PM';
2070
+ if (structure.tieFormat)
2071
+ return structure.tieFormat;
2072
+ if (structure.tieFormatId) {
2073
+ var structureTieFormat = (_d = drawDefinition.tieFormats) === null || _d === void 0 ? void 0 : _d.find(function (tf) { return structure.tieFormatId === tf.tieFormatId; });
2074
+ if (structureTieFormat)
2075
+ return structureTieFormat;
2058
2076
  }
2059
- else if (time.hours === '00') {
2060
- time.hours = '12';
2061
- time.ampm = 'AM';
2077
+ }
2078
+
2079
+ function resolveTieFormat(_a) {
2080
+ var drawDefinition = _a.drawDefinition, structure = _a.structure, matchUp = _a.matchUp, event = _a.event;
2081
+ return {
2082
+ tieFormat: getItemTieFormat({
2083
+ item: matchUp,
2084
+ drawDefinition: drawDefinition,
2085
+ structure: structure,
2086
+ event: event,
2087
+ }) ||
2088
+ getItemTieFormat({
2089
+ item: structure,
2090
+ drawDefinition: drawDefinition,
2091
+ structure: structure,
2092
+ event: event,
2093
+ }) ||
2094
+ getObjectTieFormat(drawDefinition) ||
2095
+ getObjectTieFormat(event),
2096
+ };
2097
+ }
2098
+
2099
+ function decorateResult(_a) {
2100
+ var context = _a.context, result = _a.result, stack = _a.stack, info = _a.info;
2101
+ if (result && !Array.isArray(result === null || result === void 0 ? void 0 : result.stack))
2102
+ result.stack = [];
2103
+ if (result && Array.isArray(result === null || result === void 0 ? void 0 : result.stack) && typeof stack === 'string') {
2104
+ result.stack.push(stack);
2062
2105
  }
2063
- else {
2064
- time.ampm = 'AM';
2106
+ if (result && info) {
2107
+ result.info = info;
2065
2108
  }
2066
- if (((_a = time.hours) === null || _a === void 0 ? void 0 : _a[0]) === '0') {
2067
- time.hours = time.hours.slice(1);
2109
+ if (result && typeof context === 'object' && Object.keys(context).length) {
2110
+ Object.assign(result, definedAttributes(context));
2068
2111
  }
2069
- return "".concat(time.hours || '12', ":").concat(time.minutes || '00', " ").concat(time.ampm);
2070
- }
2071
- function convertTime(value, time24, keepDate) {
2072
- var hasDate = extractDate(value);
2073
- var timeString = extractTime(value);
2074
- var timeValue = hasDate ? timeString : value;
2075
- return !value
2076
- ? undefined
2077
- : (time24 && ((hasDate && keepDate && value) || militaryTime(timeValue))) ||
2078
- regularTime(timeValue);
2079
- }
2080
- function timeSort(a, b) {
2081
- var as = splitTime(a);
2082
- var bs = splitTime(b);
2083
- if (parseInt(as.hours) < parseInt(bs.hours))
2084
- return -1;
2085
- if (parseInt(as.hours) > parseInt(bs.hours))
2086
- return 1;
2087
- if (as.hours === bs.hours) {
2088
- if (parseInt(as.minutes) < parseInt(bs.minutes))
2089
- return -1;
2090
- if (parseInt(as.minutes) > parseInt(bs.minutes))
2091
- return 1;
2112
+ if (result && !(result === null || result === void 0 ? void 0 : result.error) && !(result === null || result === void 0 ? void 0 : result.success)) {
2113
+ Object.assign(result, __assign({}, SUCCESS));
2092
2114
  }
2093
- return 0;
2094
- }
2095
- function addDays(date, days) {
2096
- if (days === void 0) { days = 7; }
2097
- var universalDate = extractDate(date) + 'T00:00';
2098
- var now = new Date(universalDate);
2099
- var adjustedDate = new Date(now.setDate(now.getDate() + days));
2100
- return formatDate(adjustedDate);
2101
- }
2102
- function addWeek(date) {
2103
- return addDays(date);
2104
- }
2105
- function getDateByWeek(week, year, dateFormat, sunday) {
2106
- if (sunday === void 0) { sunday = false; }
2107
- var date = new Date(year, 0, 1 + (week - 1) * 7);
2108
- var startValue = sunday ? 0 : 1;
2109
- date.setDate(date.getDate() + (startValue - date.getDay()));
2110
- return formatDate(date, dateFormat);
2111
- }
2112
- function dateFromDay(year, day, dateFormat) {
2113
- var date = new Date(year, 0); // initialize a date in `year-01-01`
2114
- return formatDate(new Date(date.setDate(day)), dateFormat); // add the number of days
2115
- }
2116
- function timeToDate(timeString, date) {
2117
- if (date === void 0) { date = undefined; }
2118
- var _a = __read((timeString || '00:00').split(':').map(zeroPad), 2), hours = _a[0], minutes = _a[1];
2119
- var milliseconds = offsetDate(date).setHours(hours, minutes, 0, 0);
2120
- return offsetDate(milliseconds);
2121
- }
2122
- function minutesDifference(date1, date2, absolute) {
2123
- if (absolute === void 0) { absolute = true; }
2124
- var dt1 = new Date(date1);
2125
- var dt2 = new Date(date2);
2126
- var diff = (dt2.getTime() - dt1.getTime()) / 1000 / 60;
2127
- return absolute ? Math.abs(Math.round(diff)) : Math.round(diff);
2128
- }
2129
- function addMinutesToTimeString(timeString, minutes) {
2130
- var validTimeString = extractTime(timeString);
2131
- if (!validTimeString)
2132
- return '00:00';
2133
- var minutesToAdd = isNaN(minutes) ? 0 : minutes;
2134
- return extractTime(addMinutes(timeToDate(validTimeString), minutesToAdd).toISOString());
2135
- }
2136
- function addMinutes(startDate, minutes) {
2137
- var date = new Date(startDate);
2138
- return new Date(date.getTime() + minutes * 60000);
2139
- }
2140
- function zeroPad(number) {
2141
- return number.toString()[1] ? number : '0' + number;
2142
- }
2143
- function sameDay(date1, date2) {
2144
- var d1 = new Date(date1);
2145
- var d2 = new Date(date2);
2146
- return (d1.getFullYear() === d2.getFullYear() &&
2147
- d1.getMonth() === d2.getMonth() &&
2148
- d1.getDate() === d2.getDate());
2149
- }
2150
- var dateTime = {
2151
- addDays: addDays,
2152
- addWeek: addWeek,
2153
- addMinutesToTimeString: addMinutesToTimeString,
2154
- convertTime: convertTime,
2155
- getIsoDateString: getIsoDateString,
2156
- getUTCdateString: getUTCdateString,
2157
- DateHHMM: DateHHMM,
2158
- extractDate: extractDate,
2159
- extractTime: extractTime,
2160
- formatDate: formatDate,
2161
- getDateByWeek: getDateByWeek,
2162
- isISODateString: isISODateString,
2163
- isDate: isDate,
2164
- isTimeString: isTimeString,
2165
- offsetDate: offsetDate,
2166
- offsetTime: offsetTime,
2167
- sameDay: sameDay,
2168
- timeStringMinutes: timeStringMinutes,
2169
- timeToDate: timeToDate,
2170
- timeUTC: timeUTC,
2171
- validTimeValue: validTimeValue,
2172
- validDateString: validDateString,
2173
- timeValidation: timeValidation,
2174
- dateValidation: dateValidation,
2175
- };
2176
-
2177
- function makeDeepCopy(sourceObject, // arbitrary JSON object; functions will be stripped.
2178
- convertExtensions, // optional - all extension objects converted to attributes ._key
2179
- internalUse, // disregard deepCopy being disabled within the engine - necessary for query results
2180
- removeExtensions, // optional - strip all extension attributes
2181
- iteration // escape hatch - check against iteration threshold
2182
- ) {
2183
- var e_1, _a;
2184
- if (iteration === void 0) { iteration = 0; }
2185
- if (getProvider().makeDeepCopy)
2186
- return getProvider().makeDeepCopy(sourceObject, convertExtensions, internalUse, removeExtensions);
2187
- var deepCopy = deepCopyEnabled();
2188
- var _b = deepCopy || {}, stringify = _b.stringify, toJSON = _b.toJSON, ignore = _b.ignore, modulate = _b.modulate;
2189
- if ((!(deepCopy === null || deepCopy === void 0 ? void 0 : deepCopy.enabled) && !internalUse) ||
2190
- typeof sourceObject !== 'object' ||
2191
- typeof sourceObject === 'function' ||
2192
- sourceObject === null ||
2193
- (typeof (deepCopy === null || deepCopy === void 0 ? void 0 : deepCopy.threshold) === 'number' && iteration >= deepCopy.threshold)) {
2194
- return sourceObject;
2195
- }
2196
- var targetObject = Array.isArray(sourceObject) ? [] : {};
2197
- var sourceObjectKeys = Object.keys(sourceObject).filter(function (key) {
2198
- return !internalUse ||
2199
- !ignore ||
2200
- (Array.isArray(ignore) && !ignore.includes(key)) ||
2201
- (typeof ignore === 'function' && !ignore(key));
2202
- });
2203
- var stringifyValue = function (key, value) {
2204
- targetObject[key] =
2205
- typeof (value === null || value === void 0 ? void 0 : value.toString) === 'function'
2206
- ? value.toString()
2207
- : JSON.stringify(value);
2208
- };
2209
- try {
2210
- for (var sourceObjectKeys_1 = __values(sourceObjectKeys), sourceObjectKeys_1_1 = sourceObjectKeys_1.next(); !sourceObjectKeys_1_1.done; sourceObjectKeys_1_1 = sourceObjectKeys_1.next()) {
2211
- var key = sourceObjectKeys_1_1.value;
2212
- var value = sourceObject[key];
2213
- var modulated = typeof modulate === 'function' ? modulate(value) : undefined;
2214
- if (modulated !== undefined) {
2215
- targetObject[key] = modulated;
2216
- }
2217
- else if (convertExtensions &&
2218
- key === 'extensions' &&
2219
- Array.isArray(value)) {
2220
- var extensionConversions = extensionsToAttributes(value);
2221
- Object.assign.apply(Object, __spreadArray([targetObject], __read(extensionConversions), false));
2222
- }
2223
- else if (removeExtensions && key === 'extensions') {
2224
- targetObject[key] = [];
2225
- }
2226
- else if (Array.isArray(stringify) && stringify.includes(key)) {
2227
- stringifyValue(key, value);
2228
- }
2229
- else if (Array.isArray(toJSON) &&
2230
- toJSON.includes(key) &&
2231
- typeof (value === null || value === void 0 ? void 0 : value.toJSON) === 'function') {
2232
- targetObject[key] = value.toJSON();
2233
- }
2234
- else if (value === null) {
2235
- targetObject[key] = undefined;
2236
- }
2237
- else if (isDateObject(value)) {
2238
- targetObject[key] = new Date(value).toISOString();
2239
- }
2240
- else {
2241
- targetObject[key] = makeDeepCopy(value, convertExtensions, internalUse, removeExtensions, iteration + 1);
2242
- }
2243
- }
2244
- }
2245
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2246
- finally {
2247
- try {
2248
- if (sourceObjectKeys_1_1 && !sourceObjectKeys_1_1.done && (_a = sourceObjectKeys_1.return)) _a.call(sourceObjectKeys_1);
2249
- }
2250
- finally { if (e_1) throw e_1.error; }
2251
- }
2252
- return targetObject;
2253
- }
2254
- function extensionsToAttributes(extensions) {
2255
- return extensions === null || extensions === void 0 ? void 0 : extensions.map(function (extension) {
2256
- var _a;
2257
- var name = extension.name, value = extension.value;
2258
- return name && value && (_a = {}, _a["_".concat(name)] = value, _a);
2259
- }).filter(Boolean);
2260
- }
2261
-
2262
- function getAccessorValue(_a) {
2263
- var element = _a.element, accessor = _a.accessor;
2264
- if (typeof accessor !== 'string')
2265
- return { values: [] };
2266
- var targetElement = makeDeepCopy(element);
2267
- var attributes = accessor.split('.');
2268
- var values = [];
2269
- var value;
2270
- processKeys({ targetElement: targetElement, attributes: attributes });
2271
- var result = { value: value };
2272
- if (values.length)
2273
- result.values = values;
2274
- return result;
2275
- function processKeys(_a) {
2276
- var e_1, _b;
2277
- var targetElement = _a.targetElement, _c = _a.attributes, attributes = _c === void 0 ? [] : _c, significantCharacters = _a.significantCharacters;
2278
- var _loop_1 = function (index, attribute) {
2279
- if (targetElement === null || targetElement === void 0 ? void 0 : targetElement[attribute]) {
2280
- var remainingKeys_1 = attributes.slice(index + 1);
2281
- if (!remainingKeys_1.length) {
2282
- if (!value)
2283
- value = targetElement[attribute];
2284
- if (!values.includes(targetElement[attribute])) {
2285
- values.push(targetElement[attribute]);
2286
- }
2287
- }
2288
- else if (Array.isArray(targetElement[attribute])) {
2289
- var values_1 = targetElement[attribute];
2290
- values_1.forEach(function (nestedTarget) {
2291
- return processKeys({
2292
- targetElement: nestedTarget,
2293
- attributes: remainingKeys_1,
2294
- });
2295
- });
2296
- }
2297
- else {
2298
- targetElement = targetElement[attribute];
2299
- checkValue({ targetElement: targetElement, index: index });
2300
- }
2301
- }
2302
- };
2303
- try {
2304
- for (var _d = __values(attributes.entries()), _e = _d.next(); !_e.done; _e = _d.next()) {
2305
- var _f = __read(_e.value, 2), index = _f[0], attribute = _f[1];
2306
- _loop_1(index, attribute);
2307
- }
2308
- }
2309
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2310
- finally {
2311
- try {
2312
- if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
2313
- }
2314
- finally { if (e_1) throw e_1.error; }
2315
- }
2316
- function checkValue(_a) {
2317
- var targetElement = _a.targetElement, index = _a.index;
2318
- if (targetElement &&
2319
- index === attributes.length - 1 &&
2320
- ['string', 'number'].includes(typeof targetElement)) {
2321
- var extractedValue = significantCharacters
2322
- ? targetElement.slice(0, significantCharacters)
2323
- : targetElement;
2324
- if (value) {
2325
- if (!values.includes(extractedValue)) {
2326
- values.push(extractedValue);
2327
- }
2328
- }
2329
- else {
2330
- value = extractedValue;
2331
- values.push(extractedValue);
2332
- }
2333
- }
2334
- }
2335
- }
2336
- }
2337
-
2338
- function isString(obj) {
2339
- return typeof obj === 'string';
2340
- }
2341
- function isObject(obj) {
2342
- return obj !== null && typeof obj === 'object';
2343
- }
2344
- function objShallowEqual(o1, o2) {
2345
- var e_1, _a;
2346
- if (!isObject(o1) || !isObject(o2))
2347
- return false;
2348
- var keys1 = Object.keys(o1);
2349
- var keys2 = Object.keys(o2);
2350
- if (keys1.length !== keys2.length) {
2351
- return false;
2352
- }
2353
- try {
2354
- for (var keys1_1 = __values(keys1), keys1_1_1 = keys1_1.next(); !keys1_1_1.done; keys1_1_1 = keys1_1.next()) {
2355
- var key = keys1_1_1.value;
2356
- if (o1[key] !== o2[key]) {
2357
- return false;
2358
- }
2359
- }
2360
- }
2361
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2362
- finally {
2363
- try {
2364
- if (keys1_1_1 && !keys1_1_1.done && (_a = keys1_1.return)) _a.call(keys1_1);
2365
- }
2366
- finally { if (e_1) throw e_1.error; }
2367
- }
2368
- return true;
2369
- }
2370
- function createMap(objectArray, attribute) {
2371
- if (!Array.isArray(objectArray))
2372
- return {};
2373
- return Object.assign.apply(Object, __spreadArray([{}], __read((objectArray !== null && objectArray !== void 0 ? objectArray : [])
2374
- .filter(isObject)
2375
- .map(function (obj) {
2376
- var _a;
2377
- return (obj[attribute] && (_a = {},
2378
- _a[obj[attribute]] = obj,
2379
- _a));
2380
- })
2381
- .filter(Boolean)), false));
2382
- }
2383
- // e.g. result.find(hav({ attr: value })) -or- result.filter(hav({ attr: value }))
2384
- var hasAttributeValues = function (a) { return function (o) {
2385
- return Object.keys(a).every(function (key) { return o[key] === a[key]; });
2386
- }; };
2387
- // extracts targeted attributes
2388
- // e.g. const byeAssignments = positionAssignments.filter(xa('bye')).map(xa('drawPosition'));
2389
- // supports xa('string'), xa(['string', 'string']), xa({ attr1: true, attr2: true })
2390
- var extractAttributes = function (accessor) { return function (element) {
2391
- var _a;
2392
- return !accessor || typeof element !== 'object'
2393
- ? undefined
2394
- : (Array.isArray(accessor) &&
2395
- accessor.map(function (a) {
2396
- var _a;
2397
- var _b;
2398
- return (_a = {},
2399
- _a[a] = (_b = getAccessorValue({ element: element, accessor: a })) === null || _b === void 0 ? void 0 : _b.value,
2400
- _a);
2401
- })) ||
2402
- (typeof accessor === 'object' &&
2403
- Object.keys(accessor).map(function (key) {
2404
- var _a;
2405
- var _b;
2406
- return (_a = {},
2407
- _a[key] = (_b = getAccessorValue({ element: element, accessor: key })) === null || _b === void 0 ? void 0 : _b.value,
2408
- _a);
2409
- })) ||
2410
- ((_a = (typeof accessor === 'string' && getAccessorValue({ element: element, accessor: accessor }))) === null || _a === void 0 ? void 0 : _a.value);
2411
- }; };
2412
- function getDefinedKeys(obj, ignoreValues, ignoreEmptyArrays) {
2413
- return Object.keys(obj).filter(function (key) {
2414
- return !ignoreValues.includes(obj[key]) &&
2415
- (!ignoreEmptyArrays || (Array.isArray(obj[key]) ? obj[key].length : true));
2416
- });
2417
- }
2418
- function definedAttributes(obj, ignoreFalse, ignoreEmptyArrays, shallow) {
2419
- if (typeof obj !== 'object' || obj === null)
2420
- return obj;
2421
- var deepCopy = deepCopyEnabled();
2422
- if (!(deepCopy === null || deepCopy === void 0 ? void 0 : deepCopy.enabled))
2423
- shallow = true;
2424
- var ignoreValues = ['', undefined, null];
2425
- if (ignoreFalse)
2426
- ignoreValues.push(false);
2427
- var definedKeys = getDefinedKeys(obj, ignoreValues, ignoreEmptyArrays);
2428
- return Object.assign.apply(Object, __spreadArray([{}], __read(definedKeys.map(function (key) {
2429
- var _a, _b;
2430
- return Array.isArray(obj[key])
2431
- ? (_a = {},
2432
- _a[key] = shallow
2433
- ? obj[key]
2434
- : obj[key].map(function (m) { return definedAttributes(m); }),
2435
- _a) : (_b = {}, _b[key] = shallow ? obj[key] : definedAttributes(obj[key]), _b);
2436
- })), false));
2437
- }
2438
- function countKeys(o) {
2439
- if (Array.isArray(o)) {
2440
- return o.length + o.map(countKeys).reduce(function (a, b) { return a + b; }, 0);
2441
- }
2442
- else if (typeof o === 'object' && o !== null) {
2443
- return (Object.keys(o).length +
2444
- Object.keys(o)
2445
- .map(function (k) { return countKeys(o[k]); })
2446
- .reduce(function (a, b) { return a + b; }, 0));
2447
- }
2448
- return 0;
2449
- }
2450
- function generateHashCode(o) {
2451
- if (o === null || typeof o !== 'object')
2452
- return undefined;
2453
- var str = JSON.stringify(o);
2454
- var keyCount = countKeys(o);
2455
- var charSum = str.split('').reduce(function (a, b) { return a + b.charCodeAt(0); }, 0);
2456
- return [str.length, keyCount, charSum].map(function (e) { return e.toString(36); }).join('');
2457
- }
2458
-
2459
- // NOTE: type really does need to be any!
2460
- function attributeFilter(params) {
2461
- if (params === null)
2462
- return {};
2463
- var _a = params || {}, source = _a.source, template = _a.template;
2464
- if (!template)
2465
- return source;
2466
- var target = {};
2467
- attributeCopy(source, template, target);
2468
- return target;
2469
- function attributeCopy(valuesObject, templateObject, outputObject) {
2470
- var e_1, _a;
2471
- if (!valuesObject || !templateObject)
2472
- return undefined;
2473
- var vKeys = Object.keys(valuesObject);
2474
- var oKeys = Object.keys(templateObject);
2475
- // the orMap allows spcification of { 'a||b': boolean } so that filter templates can apply to multiple attributes
2476
- var orMap = Object.assign.apply(Object, __spreadArray([{}], __read(oKeys
2477
- .filter(function (key) { return key.indexOf('||'); })
2478
- .map(function (key) { return key.split('||').map(function (or) {
2479
- var _a;
2480
- return (_a = {}, _a[or] = key, _a);
2481
- }); })
2482
- .flat()), false));
2483
- var allKeys = oKeys.concat.apply(oKeys, __spreadArray([], __read(Object.keys(orMap)), false));
2484
- var wildcard = allKeys.includes('*');
2485
- var _loop_1 = function (vKey) {
2486
- if (allKeys.indexOf(vKey) >= 0 || wildcard) {
2487
- var templateKey = orMap[vKey] || vKey;
2488
- var tobj_1 = templateObject[templateKey] || wildcard;
2489
- var vobj = valuesObject[vKey];
2490
- if (typeof tobj_1 === 'object' &&
2491
- typeof vobj !== 'function' &&
2492
- !Array.isArray(tobj_1)) {
2493
- if (Array.isArray(vobj)) {
2494
- var mappedElements = vobj
2495
- .map(function (arrayMember) {
2496
- var target = {};
2497
- var result = attributeCopy(arrayMember, tobj_1, target);
2498
- return result !== false ? target : undefined;
2499
- })
2500
- .filter(Boolean);
2501
- outputObject[vKey] = mappedElements;
2502
- }
2503
- else if (vobj) {
2504
- outputObject[vKey] = {};
2505
- attributeCopy(vobj, tobj_1, outputObject[vKey]);
2506
- }
2507
- }
2508
- else {
2509
- var value = valuesObject[vKey];
2510
- var exclude = Array.isArray(tobj_1) && !tobj_1.includes(value);
2511
- if (exclude)
2512
- return { value: false };
2513
- if (templateObject[vKey] ||
2514
- (wildcard && templateObject[vKey] !== false)) {
2515
- outputObject[vKey] = value;
2516
- }
2517
- }
2518
- }
2519
- };
2520
- try {
2521
- for (var vKeys_1 = __values(vKeys), vKeys_1_1 = vKeys_1.next(); !vKeys_1_1.done; vKeys_1_1 = vKeys_1.next()) {
2522
- var vKey = vKeys_1_1.value;
2523
- var state_1 = _loop_1(vKey);
2524
- if (typeof state_1 === "object")
2525
- return state_1.value;
2526
- }
2527
- }
2528
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2529
- finally {
2530
- try {
2531
- if (vKeys_1_1 && !vKeys_1_1.done && (_a = vKeys_1.return)) _a.call(vKeys_1);
2532
- }
2533
- finally { if (e_1) throw e_1.error; }
2534
- }
2535
- return undefined;
2536
- }
2537
- }
2538
-
2539
- function generateTimeCode(index) {
2540
- if (index === void 0) { index = 0; }
2541
- var uidate = new Date();
2542
- uidate.setHours(uidate.getHours() + index);
2543
- return uidate.getTime().toString(36).slice(-6).toUpperCase();
2544
- }
2545
-
2546
- /**
2547
- *
2548
- * @param {object[]} arrayOfJSON - JSON objects array
2549
- * @param {object} config - object which configures processing (see below)
2550
- * @returns {string} - joined by '\r\n' or specified line separator
2551
- *
2552
- * config {
2553
- * {boolean} includeTransformAccessors, // transform accessors are included with columnAccessors
2554
- * {string[]} columnAccessors, // [ 'includeThis', 'andThis' ]
2555
- * {object} columnTransform, // e.g. { 'newColumnName': ['oldColumn1', 'oldColumn2' ]}
2556
- * {object} columnMap, // e.g. { 'columnName': 'newColumnName' }
2557
- * {object} valuesMap, // e.g. { 'columnName': { 'value1': 'mappedValue' }} // useful for mapping IDs
2558
- * {array} sortOrder // e.g. ['columnName1', 'columnName2'] // determine order of csv columns
2559
- * {object} context, // attributes which are to be added to all rows { 'columnName': 'value }
2560
- * {string} delimiter, // defaults to '"'
2561
- * {string} columnJoiner, // defaults to ',' // defines how CSV columns are joined
2562
- * {string} rowJoiner, // defaults to '\r\n' // defines how CSV lines are joined
2563
- * {string} keyJoiner, // defaults to '.' // defines how flattened column names are constructed
2564
- * }
2565
- *
2566
- * NOTE: `columnTransform` mapped array elements are sensitive to order and will resolve to the first matching value
2567
- * NOTE: `columnMap` should not contain new columnName(s) that are `columnTransform` keys
2568
- */
2569
- function JSON2CSV(arrayOfJSON, config) {
2570
- if (config && typeof config !== 'object')
2571
- return INVALID_VALUES;
2572
- var _a = (config || {}).columnTransform, columnTransform = _a === void 0 ? {} : _a;
2573
- var _b = config || {}, includeTransformAccessors = _b.includeTransformAccessors, _c = _b.includeHeaderRow, includeHeaderRow = _c === void 0 ? true : _c, returnTransformedJSON = _b.returnTransformedJSON, removeEmptyColumns = _b.removeEmptyColumns, onlyHeaderRow = _b.onlyHeaderRow, _d = _b.columnAccessors, columnAccessors = _d === void 0 ? [] : _d, _e = _b.functionMap, functionMap = _e === void 0 ? {} : _e, _f = _b.columnMap, columnMap = _f === void 0 ? {} : _f, _g = _b.valuesMap, valuesMap = _g === void 0 ? {} : _g, _h = _b.context, context = _h === void 0 ? {} : _h, _j = _b.delimiter, delimiter = _j === void 0 ? '"' : _j, _k = _b.columnJoiner, columnJoiner = _k === void 0 ? ',' : _k, _l = _b.rowJoiner, rowJoiner = _l === void 0 ? '\r\n' : _l, _m = _b.keyJoiner, keyJoiner = _m === void 0 ? '.' : _m;
2574
- if (!Array.isArray(arrayOfJSON) ||
2575
- !Array.isArray(columnAccessors) ||
2576
- typeof context !== 'object' ||
2577
- typeof columnMap !== 'object' ||
2578
- typeof columnTransform !== 'object' ||
2579
- typeof functionMap !== 'object' ||
2580
- typeof valuesMap !== 'object' ||
2581
- typeof columnJoiner !== 'string' ||
2582
- typeof rowJoiner !== 'string' ||
2583
- typeof keyJoiner !== 'string' ||
2584
- typeof delimiter !== 'string')
2585
- return INVALID_VALUES;
2586
- // ensure all column transformers are arrays
2587
- columnTransform = Object.assign.apply(Object, __spreadArray([{}], __read(Object.keys(columnTransform)
2588
- .reverse() // reverse so that exported CSV columns are in the order as defined
2589
- .map(function (key) {
2590
- var _a;
2591
- return (_a = {},
2592
- _a[key] = Array.isArray(columnTransform[key])
2593
- ? columnTransform[key]
2594
- : [
2595
- // ensure transform attributes are strings
2596
- typeof columnTransform[key] === 'string' && columnTransform[key],
2597
- ].filter(Boolean),
2598
- _a);
2599
- })), false));
2600
- var flattened = arrayOfJSON
2601
- .filter(Boolean)
2602
- .map(function (obj) { return flattenJSON(obj, keyJoiner); });
2603
- var transformColumns = Object.values(columnTransform).flat();
2604
- if (includeTransformAccessors)
2605
- columnAccessors.push.apply(columnAccessors, __spreadArray([], __read(transformColumns), false));
2606
- var headerRow = flattened
2607
- .reduce(function (aggregator, row) {
2608
- return Object.keys(row).every(function (key) { return (!aggregator.includes(key) && aggregator.push(key)) || true; }) && aggregator;
2609
- }, [])
2610
- .filter(function (key) { return !(columnAccessors === null || columnAccessors === void 0 ? void 0 : columnAccessors.length) || columnAccessors.includes(key); });
2611
- var accessorMap = Object.assign.apply(Object, __spreadArray([{}], __read(Object.keys(columnTransform)
2612
- .reverse() // so that original order is preserved when later pushed
2613
- .map(function (transform) {
2614
- return columnTransform[transform]
2615
- .map(function (value) {
2616
- var _a;
2617
- return (_a = {}, _a[value] = transform, _a);
2618
- })
2619
- .flat();
2620
- })
2621
- .flat()), false));
2622
- var sortColumns = function (a, b) {
2623
- return !(config === null || config === void 0 ? void 0 : config.sortOrder)
2624
- ? 0
2625
- : (config.sortOrder.includes(a) &&
2626
- config.sortOrder.includes(b) &&
2627
- config.sortOrder.indexOf(a) - config.sortOrder.indexOf(b)) ||
2628
- (!config.sortOrder.includes(b) && -1);
2629
- };
2630
- var tranformedHeaderRow = headerRow
2631
- .reduce(function (def, key) {
2632
- var transform = accessorMap[key];
2633
- if (transform) {
2634
- if (!def.includes(transform))
2635
- def.push(transform);
2636
- }
2637
- else {
2638
- def.push(key);
2639
- }
2640
- return def;
2641
- }, [])
2642
- .sort(sortColumns);
2643
- Object.keys(columnMap).forEach(function (columnName) {
2644
- return !tranformedHeaderRow.includes(columnName) &&
2645
- tranformedHeaderRow.unshift(columnName);
2646
- });
2647
- Object.keys(columnTransform).forEach(function (columnName) {
2648
- return !tranformedHeaderRow.includes(columnName) &&
2649
- tranformedHeaderRow.unshift(columnName);
2650
- });
2651
- typeof context === 'object' &&
2652
- Object.keys(context).forEach(function (columnName) {
2653
- return !tranformedHeaderRow.includes(columnName) &&
2654
- tranformedHeaderRow.unshift(columnName);
2655
- });
2656
- var mappedHeaderRow = tranformedHeaderRow.map(function (key) { return columnMap[key] || key; });
2657
- if (onlyHeaderRow)
2658
- return [mappedHeaderRow];
2659
- var withDelimiter = function (value) { return "".concat(delimiter).concat(value).concat(delimiter); };
2660
- var columnValueCounts = [];
2661
- var processRow = function (row) {
2662
- return Object.values(tranformedHeaderRow.reduce(function (columnsMap, columnName, columnIndex) {
2663
- var _a;
2664
- var accessors = columnTransform[columnName];
2665
- var value = ((accessors === null || accessors === void 0 ? void 0 : accessors.length)
2666
- ? row[accessors.find(function (accessor) { return row[accessor]; })]
2667
- : row[columnName]) ||
2668
- (context === null || context === void 0 ? void 0 : context[columnName]) ||
2669
- '';
2670
- var mappedValue = ((_a = valuesMap[columnName]) === null || _a === void 0 ? void 0 : _a[value]) || value;
2671
- var fxValue = typeof functionMap[columnName] === 'function'
2672
- ? functionMap[columnName](mappedValue)
2673
- : mappedValue;
2674
- columnsMap[columnName] = withDelimiter(fxValue);
2675
- if (fxValue) {
2676
- columnValueCounts[columnIndex] =
2677
- (columnValueCounts[columnIndex] || 0) + 1;
2678
- }
2679
- return columnsMap;
2680
- }, {}));
2681
- };
2682
- var flattenedRows = flattened.map(processRow);
2683
- var indicesToRemove = removeEmptyColumns &&
2684
- __spreadArray([], __read(columnValueCounts), false).map(function (count, index) { return !count && index; })
2685
- .filter(isNumeric)
2686
- .reverse();
2687
- if (indicesToRemove) {
2688
- var purge = function (row) {
2689
- return row.filter(function (_, index) { return !indicesToRemove.includes(index); });
2690
- };
2691
- flattenedRows = flattenedRows.map(purge);
2692
- mappedHeaderRow = purge(mappedHeaderRow);
2693
- }
2694
- var rows = flattenedRows.map(function (row) { return row.join(columnJoiner); });
2695
- if (returnTransformedJSON) {
2696
- return rows.map(function (row) {
2697
- var columnValues = row.split(columnJoiner);
2698
- return Object.assign.apply(Object, __spreadArray([{}], __read(columnValues.map(function (v, i) {
2699
- var _a;
2700
- return (_a = {}, _a[mappedHeaderRow[i]] = v, _a);
2701
- })), false));
2702
- });
2703
- }
2704
- return includeHeaderRow
2705
- ? __spreadArray([mappedHeaderRow.map(withDelimiter).join(columnJoiner)], __read(rows), false).join(rowJoiner)
2706
- : rows.join(rowJoiner);
2707
- }
2708
- function flattenJSON(obj, keyJoiner, path) {
2709
- if (keyJoiner === void 0) { keyJoiner = '.'; }
2710
- if (path === void 0) { path = []; }
2711
- return (typeof obj === 'object' &&
2712
- Object.keys(obj).reduce(function (result, key) {
2713
- if (typeof obj[key] !== 'object') {
2714
- result[path.concat(key).join(keyJoiner)] = obj[key];
2715
- return result;
2716
- }
2717
- return Object.assign(result, flattenJSON(obj[key], keyJoiner, path.concat(key)));
2718
- }, {}));
2719
- }
2720
-
2721
- /*
2722
- based on an answer provided by Jeff Ward on StackOverflow; November 2019
2723
- https://stackoverflow.com/users/1026023/jeff-ward
2724
- https://stackoverflow.com/questions/105034/how-to-create-guid-uuid?rq=1
2725
- */
2726
- /**
2727
- * generate a given number of UUIDs
2728
- *
2729
- * @param {number} count - number of UUIDs to generate
2730
- */
2731
- function UUIDS(count) {
2732
- if (count === void 0) { count = 1; }
2733
- return generateRange(0, count).map(UUID);
2734
- }
2735
- function UUID() {
2736
- var lut = [];
2737
- for (var i = 0; i < 256; i++) {
2738
- lut[i] = (i < 16 ? '0' : '') + i.toString(16);
2739
- }
2740
- var d0 = (Math.random() * 0xffffffff) | 0;
2741
- var d1 = (Math.random() * 0xffffffff) | 0;
2742
- var d2 = (Math.random() * 0xffffffff) | 0;
2743
- var d3 = (Math.random() * 0xffffffff) | 0;
2744
- // eslint-disable-next-line no-mixed-operators
2745
- return (lut[d0 & 0xff] +
2746
- lut[(d0 >> 8) & 0xff] +
2747
- lut[(d0 >> 16) & 0xff] +
2748
- lut[(d0 >> 24) & 0xff] +
2749
- '-' +
2750
- // eslint-disable-next-line no-mixed-operators
2751
- lut[d1 & 0xff] +
2752
- lut[(d1 >> 8) & 0xff] +
2753
- '-' +
2754
- lut[((d1 >> 16) & 0x0f) | 0x40] +
2755
- lut[(d1 >> 24) & 0xff] +
2756
- '-' +
2757
- // eslint-disable-next-line no-mixed-operators
2758
- lut[(d2 & 0x3f) | 0x80] +
2759
- lut[(d2 >> 8) & 0xff] +
2760
- '-' +
2761
- lut[(d2 >> 16) & 0xff] +
2762
- lut[(d2 >> 24) & 0xff] +
2763
- // eslint-disable-next-line no-mixed-operators
2764
- lut[d3 & 0xff] +
2765
- lut[(d3 >> 8) & 0xff] +
2766
- lut[(d3 >> 16) & 0xff] +
2767
- lut[(d3 >> 24) & 0xff]);
2768
- }
2769
-
2770
- function parse(matchUpFormatCode) {
2771
- if (typeof matchUpFormatCode === 'string') {
2772
- var type = (matchUpFormatCode.startsWith('T') && TIMED) ||
2773
- (matchUpFormatCode.startsWith(SET) && SET) ||
2774
- '';
2775
- if (type === TIMED) {
2776
- var setFormat = parseTimedSet(matchUpFormatCode);
2777
- var parsedFormat = {
2778
- simplified: true,
2779
- setFormat: setFormat,
2780
- bestOf: 1,
2781
- };
2782
- if (setFormat)
2783
- return parsedFormat;
2784
- }
2785
- if (type === SET)
2786
- return setsMatch(matchUpFormatCode);
2787
- }
2788
- return undefined;
2789
- }
2790
- function setsMatch(formatstring) {
2791
- var parts = formatstring.split('-');
2792
- var setsCount = getNumber(parts[0].slice(3));
2793
- var bestOf = setsCount === 1 || setsCount % 2 !== 0 ? setsCount : undefined;
2794
- var exactly = setsCount !== 1 && setsCount % 2 === 0 ? setsCount : undefined;
2795
- var setFormat = parts && parseSetFormat(parts[1]);
2796
- var finalSetFormat = parts && parseSetFormat(parts[2]);
2797
- var timed = (setFormat && setFormat.timed) || (finalSetFormat && finalSetFormat.timed);
2798
- var validSetsCount = (bestOf && bestOf < 6) || (timed && exactly);
2799
- var validFinalSet = !parts[2] || finalSetFormat;
2800
- var validSetsFormat = setFormat;
2801
- var result = definedAttributes({
2802
- setFormat: setFormat,
2803
- exactly: exactly,
2804
- bestOf: bestOf,
2805
- });
2806
- if (finalSetFormat)
2807
- result.finalSetFormat = finalSetFormat;
2808
- if (validSetsCount && validSetsFormat && validFinalSet)
2809
- return result;
2810
- }
2811
- function parseSetFormat(formatstring) {
2812
- if ((formatstring === null || formatstring === void 0 ? void 0 : formatstring[1]) === ':') {
2813
- var parts = formatstring.split(':');
2814
- var setType = setTypes$1[parts[0]];
2815
- var setFormatString = parts[1];
2816
- if (setType && setFormatString) {
2817
- var isTiebreakSet = setFormatString.indexOf('TB') === 0;
2818
- if (isTiebreakSet) {
2819
- var tiebreakSet = parseTiebreakFormat(setFormatString);
2820
- if (tiebreakSet === false)
2821
- return false;
2822
- return typeof tiebreakSet === 'object' ? { tiebreakSet: tiebreakSet } : undefined;
2823
- }
2824
- var timedSet = setFormatString.indexOf('T') === 0;
2825
- if (timedSet)
2826
- return parseTimedSet(setFormatString);
2827
- var parts_1 = formatstring.match(/^[FS]:(\d+)([A-Za-z]*)/);
2828
- var NoAD = (parts_1 && isNoAD(parts_1[2])) || false;
2829
- var validNoAD = !(parts_1 === null || parts_1 === void 0 ? void 0 : parts_1[2]) || NoAD;
2830
- var setTo = parts_1 ? getNumber(parts_1[1]) : undefined;
2831
- var tiebreakAtValue = parseTiebreakAt(setFormatString);
2832
- var validTiebreakAt = tiebreakAtValue !== false;
2833
- var tiebreakAt = (validTiebreakAt && tiebreakAtValue) || setTo;
2834
- var tiebreakFormat = parseTiebreakFormat(setFormatString.split('/')[1]);
2835
- var validTiebreak = tiebreakFormat !== false;
2836
- var result = { setTo: setTo };
2837
- if (NoAD)
2838
- result.NoAD = true;
2839
- if (tiebreakFormat) {
2840
- result.tiebreakFormat = tiebreakFormat;
2841
- result.tiebreakAt = tiebreakAt;
2842
- }
2843
- else {
2844
- result.noTiebreak = true;
2845
- }
2846
- return ((setTo && validNoAD && validTiebreak && validTiebreakAt && result) ||
2847
- false);
2848
- }
2849
- }
2850
- return undefined;
2851
- }
2852
- function parseTiebreakAt(setFormatString, expectNumber) {
2853
- if (expectNumber === void 0) { expectNumber = true; }
2854
- var tiebreakAtValue = (setFormatString === null || setFormatString === void 0 ? void 0 : setFormatString.indexOf('@')) > 0 && setFormatString.split('@');
2855
- if (tiebreakAtValue) {
2856
- var tiebreakAt = expectNumber
2857
- ? getNumber(tiebreakAtValue[1])
2858
- : tiebreakAtValue[1];
2859
- return tiebreakAt || false;
2860
- }
2861
- return undefined;
2862
- }
2863
- function parseTiebreakFormat(formatstring) {
2864
- if (formatstring) {
2865
- if (formatstring.startsWith('TB')) {
2866
- var modifier = parseTiebreakAt(formatstring, false);
2867
- var parts = formatstring.match(/^TB(\d+)([A-Za-z]*)/);
2868
- var tiebreakToString = parts === null || parts === void 0 ? void 0 : parts[1];
2869
- var NoAD = parts && isNoAD(parts[2]);
2870
- var validNoAD = !(parts === null || parts === void 0 ? void 0 : parts[2]) || NoAD;
2871
- var tiebreakTo = getNumber(tiebreakToString);
2872
- if (tiebreakTo && validNoAD) {
2873
- var result = { tiebreakTo: tiebreakTo };
2874
- // modifiers cannot be numeric
2875
- if (modifier &&
2876
- typeof modifier === 'string' &&
2877
- !isConvertableInteger(modifier)) {
2878
- result.modifier = modifier;
2879
- }
2880
- if (NoAD)
2881
- result.NoAD = true;
2882
- return result;
2883
- }
2884
- else {
2885
- return false;
2886
- }
2887
- }
2888
- else {
2889
- return false;
2890
- }
2891
- }
2892
- return undefined;
2893
- }
2894
- function parseTimedSet(formatstring) {
2895
- var _a;
2896
- var timestring = formatstring.slice(1);
2897
- var parts = timestring.match(/^(\d+)(@?[A-Za-z]*)/);
2898
- var minutes = getNumber(parts === null || parts === void 0 ? void 0 : parts[1]);
2899
- if (!minutes)
2900
- return;
2901
- var setFormat = { timed: true, minutes: minutes };
2902
- var based = parts === null || parts === void 0 ? void 0 : parts[2];
2903
- var validModifier = [undefined, 'P', 'G'].includes(based);
2904
- if (based && !validModifier) {
2905
- var modifier = (_a = timestring.match(/^(\d+)(@)([A-Za-z]+)$/)) === null || _a === void 0 ? void 0 : _a[3];
2906
- if (modifier) {
2907
- setFormat.modifier = modifier;
2908
- return setFormat;
2909
- }
2910
- return;
2911
- }
2912
- if (based)
2913
- setFormat.based = parts[2];
2914
- return setFormat;
2915
- }
2916
- function isNoAD(formatstring) {
2917
- return formatstring && formatstring.indexOf(NOAD) >= 0;
2918
- }
2919
- function getNumber(formatstring) {
2920
- return !isNaN(Number(formatstring)) ? Number(formatstring) : 0;
2921
- }
2922
-
2923
- function isValid(matchUpFormat) {
2924
- if (typeof matchUpFormat !== 'string')
2925
- return false;
2926
- var parsedFormat = parse(matchUpFormat);
2927
- var setParts = matchUpFormat.match(/-S:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/);
2928
- var setsTo = setParts === null || setParts === void 0 ? void 0 : setParts[1];
2929
- var tiebreakTo = setParts === null || setParts === void 0 ? void 0 : setParts[2];
2930
- var tiebreakAt = setParts === null || setParts === void 0 ? void 0 : setParts[3];
2931
- var finalSetParts = matchUpFormat.match(/-F:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/);
2932
- var finalSetTo = finalSetParts === null || finalSetParts === void 0 ? void 0 : finalSetParts[1];
2933
- var finalSetTiebreakTo = finalSetParts === null || finalSetParts === void 0 ? void 0 : finalSetParts[2];
2934
- var finalTiebreakAt = finalSetParts === null || finalSetParts === void 0 ? void 0 : finalSetParts[3];
2935
- var preserveRedundant = !!((setParts && tiebreakTo && setsTo === tiebreakAt) ||
2936
- (finalSetParts && finalSetTiebreakTo && finalSetTo === finalTiebreakAt));
2937
- var stringified = stringify(parsedFormat, preserveRedundant);
2938
- return stringified === matchUpFormat;
2939
- }
2940
-
2941
- var matchUpFormatCode = {
2942
- isValidMatchUpFormat: isValid,
2943
- stringify: stringify,
2944
- isValid: isValid,
2945
- parse: parse,
2946
- };
2947
-
2948
- function factoryVersion() {
2949
- return '1.9.4';
2950
- }
2951
-
2952
- function getObjectTieFormat(obj) {
2953
- if (!obj)
2954
- return;
2955
- var tieFormatId = obj.tieFormatId, tieFormats = obj.tieFormats;
2956
- if (obj.tieFormat) {
2957
- return obj.tieFormat;
2958
- }
2959
- else if (tieFormatId && Array.isArray(tieFormats)) {
2960
- return tieFormats.find(function (tf) { return tf.tieFormatId === tieFormatId; });
2961
- }
2962
- }
2963
-
2964
- function getItemTieFormat(_a) {
2965
- var _b, _c, _d;
2966
- var item = _a.item, drawDefinition = _a.drawDefinition, structure = _a.structure, event = _a.event;
2967
- if (!item)
2968
- return;
2969
- if (item.tieFormat)
2970
- return item.tieFormat;
2971
- // if there is a tieFormatId, only possible to look for referenced tieFormat in tieFormats on drawDefinition and event
2972
- if (item.tieFormatId) {
2973
- if (drawDefinition.tieFormat)
2974
- return drawDefinition.tieFormat;
2975
- var tieFormat = (_b = drawDefinition.tieFormats) === null || _b === void 0 ? void 0 : _b.find(function (tf) { return item.tieFormatId === tf.tieFormatId; });
2976
- if (tieFormat)
2977
- return tieFormat;
2978
- if (event.tieFormat)
2979
- return event.tieFormat;
2980
- return (_c = event.tieFormats) === null || _c === void 0 ? void 0 : _c.find(function (tf) { return item.tieFormatId === tf.tieFormatId; });
2981
- }
2982
- if (structure.tieFormat)
2983
- return structure.tieFormat;
2984
- if (structure.tieFormatId) {
2985
- var structureTieFormat = (_d = drawDefinition.tieFormats) === null || _d === void 0 ? void 0 : _d.find(function (tf) { return structure.tieFormatId === tf.tieFormatId; });
2986
- if (structureTieFormat)
2987
- return structureTieFormat;
2988
- }
2989
- }
2990
-
2991
- function resolveTieFormat(_a) {
2992
- var drawDefinition = _a.drawDefinition, structure = _a.structure, matchUp = _a.matchUp, event = _a.event;
2993
- return {
2994
- tieFormat: getItemTieFormat({
2995
- item: matchUp,
2996
- drawDefinition: drawDefinition,
2997
- structure: structure,
2998
- event: event,
2999
- }) ||
3000
- getItemTieFormat({
3001
- item: structure,
3002
- drawDefinition: drawDefinition,
3003
- structure: structure,
3004
- event: event,
3005
- }) ||
3006
- getObjectTieFormat(drawDefinition) ||
3007
- getObjectTieFormat(event),
3008
- };
3009
- }
3010
-
3011
- function decorateResult(_a) {
3012
- var context = _a.context, result = _a.result, stack = _a.stack, info = _a.info;
3013
- if (result && !Array.isArray(result === null || result === void 0 ? void 0 : result.stack))
3014
- result.stack = [];
3015
- if (result && Array.isArray(result === null || result === void 0 ? void 0 : result.stack) && typeof stack === 'string') {
3016
- result.stack.push(stack);
3017
- }
3018
- if (result && info) {
3019
- result.info = info;
3020
- }
3021
- if (result && typeof context === 'object' && Object.keys(context).length) {
3022
- Object.assign(result, definedAttributes(context));
3023
- }
3024
- if (result && !(result === null || result === void 0 ? void 0 : result.error) && !(result === null || result === void 0 ? void 0 : result.success)) {
3025
- Object.assign(result, __assign({}, SUCCESS));
3026
- }
3027
- return result !== null && result !== void 0 ? result : { success: true };
2115
+ return result !== null && result !== void 0 ? result : { success: true };
3028
2116
  }
3029
2117
 
3030
2118
  var DrawTypeEnum;
@@ -3622,16 +2710,362 @@ function tieFormatGenderValidityCheck(params) {
3622
2710
  stack: stack,
3623
2711
  });
3624
2712
  }
3625
- if (referenceGender === ANY &&
3626
- gender === MIXED &&
3627
- matchUpType !== TypeEnum.Doubles)
3628
- return decorateResult({
3629
- result: { error: INVALID_GENDER, valid: false },
3630
- info: anyMixedError,
3631
- stack: stack,
3632
- });
3633
- return { valid: true };
2713
+ if (referenceGender === ANY &&
2714
+ gender === MIXED &&
2715
+ matchUpType !== TypeEnum.Doubles)
2716
+ return decorateResult({
2717
+ result: { error: INVALID_GENDER, valid: false },
2718
+ info: anyMixedError,
2719
+ stack: stack,
2720
+ });
2721
+ return { valid: true };
2722
+ }
2723
+
2724
+ var validDateString = /^[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1])$/;
2725
+ var validTimeString = /^((0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)([.,][0-9]{3})?$/;
2726
+ var dateValidation = /^([\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]))([ T](0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)?([.,][\d]{3})?Z?$/;
2727
+ var timeValidation = /^([\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]))?([ T]?(0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)?([.,][\d]{3})?Z?$/;
2728
+
2729
+ function getIsoDateString(schedule) {
2730
+ var scheduledDate = schedule.scheduledDate;
2731
+ if (!scheduledDate && schedule.scheduledTime)
2732
+ scheduledDate = extractDate(schedule.scheduledTime);
2733
+ if (!scheduledDate)
2734
+ return;
2735
+ var extractedTime = extractTime(schedule.scheduledTime);
2736
+ var isoDateString = extractDate(scheduledDate);
2737
+ if (isoDateString && extractedTime)
2738
+ isoDateString += "T".concat(extractedTime);
2739
+ return isoDateString;
2740
+ }
2741
+ function isDateObject(value) {
2742
+ if (typeof value !== 'object' || Array.isArray(value)) {
2743
+ return false;
2744
+ }
2745
+ else {
2746
+ var datePrototype = Object.prototype.toString.call(value);
2747
+ return datePrototype === '[object Date]';
2748
+ }
2749
+ }
2750
+ function validTimeValue(value) {
2751
+ var spaceSplit = typeof value === 'string' ? value === null || value === void 0 ? void 0 : value.split(' ') : [];
2752
+ if (value &&
2753
+ (spaceSplit === null || spaceSplit === void 0 ? void 0 : spaceSplit.length) > 1 &&
2754
+ !['AM', 'PM'].includes(spaceSplit[1].toUpperCase()))
2755
+ return false;
2756
+ return !!(!value || timeValidation.test(convertTime(value, true, true)));
2757
+ }
2758
+ function isValidDateString(scheduleDate) {
2759
+ return isISODateString(scheduleDate) || validDateString.test(scheduleDate);
2760
+ }
2761
+ function DateHHMM(date) {
2762
+ var dt = new Date(date);
2763
+ var secs = dt.getSeconds() + 60 * dt.getMinutes() + 60 * 60 * dt.getHours();
2764
+ return HHMMSS(secs, { displaySeconds: false });
2765
+ }
2766
+ function HHMMSS(s, format) {
2767
+ var secondNumber = parseInt(s, 10); // don't forget the second param
2768
+ var hours = Math.floor(secondNumber / 3600);
2769
+ var minutes = Math.floor((secondNumber - hours * 3600) / 60);
2770
+ var seconds = secondNumber - hours * 3600 - minutes * 60;
2771
+ var displaySeconds = !format || (format === null || format === void 0 ? void 0 : format.displaySeconds);
2772
+ var timeString = displaySeconds
2773
+ ? hours + ':' + minutes + ':' + seconds
2774
+ : hours + ':' + minutes;
2775
+ return timeString.split(':').map(zeroPad).join(':');
2776
+ }
2777
+ var getUTCdateString = function (date) {
2778
+ var dateDate = isDate(date) || isISODateString(date) ? new Date(date) : new Date();
2779
+ var monthNumber = dateDate.getUTCMonth() + 1;
2780
+ var utcMonth = monthNumber < 10 ? "0".concat(monthNumber) : "".concat(monthNumber);
2781
+ return "".concat(dateDate.getUTCFullYear(), "-").concat(zeroPad(utcMonth), "-").concat(zeroPad(dateDate.getUTCDate()));
2782
+ };
2783
+ function timeUTC(date) {
2784
+ var dateDate = isDate(date) || isISODateString(date) ? new Date(date) : new Date();
2785
+ return Date.UTC(dateDate.getFullYear(), dateDate.getMonth(), dateDate.getDate());
2786
+ }
2787
+ function formatDate(date, separator, format) {
2788
+ if (separator === void 0) { separator = '-'; }
2789
+ if (format === void 0) { format = 'YMD'; }
2790
+ if (!date)
2791
+ return '';
2792
+ if (typeof date === 'string' && date.indexOf('T') < 0)
2793
+ date = date + 'T00:00';
2794
+ var d = new Date(date);
2795
+ var month = '' + (d.getMonth() + 1);
2796
+ var day = '' + d.getDate();
2797
+ var year = d.getFullYear();
2798
+ if (month.length < 2)
2799
+ month = '0' + month;
2800
+ if (day.length < 2)
2801
+ day = '0' + day;
2802
+ if (format === 'DMY')
2803
+ return [day, month, year].join(separator);
2804
+ if (format === 'MDY')
2805
+ return [month, day, year].join(separator);
2806
+ if (format === 'YDM')
2807
+ return [year, day, month].join(separator);
2808
+ if (format === 'DYM')
2809
+ return [day, year, month].join(separator);
2810
+ if (format === 'MYD')
2811
+ return [month, year, day].join(separator);
2812
+ return [year, month, day].join(separator);
2813
+ }
2814
+ function offsetDate(date) {
2815
+ var targetTime = date ? new Date(date) : new Date();
2816
+ var tzDifference = targetTime.getTimezoneOffset();
2817
+ return new Date(targetTime.getTime() - tzDifference * 60 * 1000);
2818
+ }
2819
+ function offsetTime(date) {
2820
+ return offsetDate(date).getTime();
2821
+ }
2822
+ // only returns true for valid date objects
2823
+ // dateArg = new Date('xxx') produces 'Invalid Date', which return false
2824
+ function isDate(dateArg) {
2825
+ if (typeof dateArg == 'boolean')
2826
+ return false;
2827
+ var t = (dateArg instanceof Date && dateArg) ||
2828
+ (!isNaN(dateArg) && new Date(dateArg)) ||
2829
+ false;
2830
+ return t && !isNaN(t.valueOf());
2831
+ }
2832
+ function dateRange(startDt, endDt) {
2833
+ if (!isValidDateString(startDt) || !isValidDateString(endDt))
2834
+ return [];
2835
+ var startDateString = extractDate(startDt) + 'T00:00';
2836
+ var endDateString = extractDate(endDt) + 'T00:00';
2837
+ var startDate = new Date(startDateString);
2838
+ var endDate = new Date(endDateString);
2839
+ var process = isDate(endDate) &&
2840
+ isDate(startDate) &&
2841
+ isValidDateRange(startDate, endDate);
2842
+ var between = [];
2843
+ var iterations = 0;
2844
+ if (process) {
2845
+ var currentDate = startDate;
2846
+ var dateSecs = currentDate.getTime();
2847
+ while (dateSecs <= endDate.getTime() && iterations < 300) {
2848
+ iterations += 1;
2849
+ // must be a *new* Date otherwise it is an array of the same object
2850
+ between.push(new Date(currentDate));
2851
+ dateSecs = currentDate.setDate(currentDate.getDate() + 1);
2852
+ }
2853
+ }
2854
+ return between.map(function (date) { return formatDate(date); });
2855
+ function isValidDateRange(minDate, maxDate) {
2856
+ return minDate <= maxDate;
2857
+ }
2858
+ }
2859
+ // matches valid ISO date string
2860
+ var re = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
2861
+ function isISODateString(dateString) {
2862
+ if (typeof dateString !== 'string')
2863
+ return false;
2864
+ return re.test(dateString);
2865
+ }
2866
+ function isTimeString(timeString) {
2867
+ if (typeof timeString !== 'string')
2868
+ return false;
2869
+ var noZ = timeString.split('Z')[0];
2870
+ var parts = noZ.split(':');
2871
+ var isNumeric = parts.every(function (part) { return !isNaN(parseInt(part)); });
2872
+ var invalid = parts.length < 2 ||
2873
+ !isNumeric ||
2874
+ parseInt(parts[0]) > 23 ||
2875
+ parseInt(parts[1]) > 60;
2876
+ return !invalid;
2877
+ }
2878
+ function timeStringMinutes(timeString) {
2879
+ var validTimeString = extractTime(timeString);
2880
+ if (!validTimeString)
2881
+ return 0;
2882
+ var _a = __read(validTimeString
2883
+ .split(':')
2884
+ .map(function (value) { return parseInt(value); }), 2), hours = _a[0], minutes = _a[1];
2885
+ return hours * 60 + minutes;
2886
+ }
2887
+ function dayMinutesToTimeString(totalMinutes) {
2888
+ var hours = Math.floor(totalMinutes / 60);
2889
+ var minutes = totalMinutes - hours * 60;
2890
+ if (hours > 23)
2891
+ hours = hours % 24;
2892
+ return [zeroPad(hours), zeroPad(minutes)].join(':');
2893
+ }
2894
+ function tidyTime(timeString) {
2895
+ return isTimeString(timeString)
2896
+ ? timeString.split(':').slice(0, 2).map(zeroPad).join(':')
2897
+ : undefined;
2898
+ }
2899
+ function extractTime(dateString) {
2900
+ return isISODateString(dateString) && dateString.indexOf('T') > 0
2901
+ ? tidyTime(dateString.split('T').reverse()[0])
2902
+ : tidyTime(dateString);
2903
+ }
2904
+ function extractDate(dateString) {
2905
+ return isISODateString(dateString) || dateValidation.test(dateString)
2906
+ ? dateString.split('T')[0]
2907
+ : undefined;
2908
+ }
2909
+ function dateStringDaysChange(dateString, daysChange) {
2910
+ var date = new Date(dateString);
2911
+ date.setDate(date.getDate() + daysChange);
2912
+ return extractDate(date.toISOString());
2913
+ }
2914
+ function splitTime(value) {
2915
+ var _a, _b;
2916
+ value = typeof value !== 'string' ? '00:00' : value;
2917
+ var o = {}, time = {};
2918
+ (_a = value.split(' ') || [], o.time = _a[0], o.ampm = _a[1]);
2919
+ (_b = o.time.split(':') || [], time.hours = _b[0], time.minutes = _b[1]);
2920
+ time.ampm = o.ampm;
2921
+ if (isNaN(time.hours) ||
2922
+ isNaN(time.minutes) ||
2923
+ (time.ampm && !['AM', 'PM'].includes(time.ampm.toUpperCase())))
2924
+ return {};
2925
+ return time;
2926
+ }
2927
+ function militaryTime(value) {
2928
+ var time = splitTime(value);
2929
+ if (time.ampm && time.hours) {
2930
+ if (time.ampm.toLowerCase() === 'pm' && parseInt(time.hours) < 12)
2931
+ time.hours = ((time.hours && parseInt(time.hours)) || 0) + 12;
2932
+ if (time.ampm.toLowerCase() === 'am' && time.hours === '12')
2933
+ time.hours = '00';
2934
+ }
2935
+ var timeString = "".concat(time.hours || '12', ":").concat(time.minutes || '00');
2936
+ return timeString.split(':').map(zeroPad).join(':');
2937
+ }
2938
+ function regularTime(value) {
2939
+ var _a;
2940
+ var time = splitTime(value);
2941
+ if (typeof time === 'object' && !Object.keys(time).length)
2942
+ return undefined;
2943
+ if (time.ampm)
2944
+ return value;
2945
+ if (time.hours > 12) {
2946
+ time.hours -= 12;
2947
+ time.ampm = 'PM';
2948
+ }
2949
+ else if (time.hours === '12') {
2950
+ time.ampm = 'PM';
2951
+ }
2952
+ else if (time.hours === '00') {
2953
+ time.hours = '12';
2954
+ time.ampm = 'AM';
2955
+ }
2956
+ else {
2957
+ time.ampm = 'AM';
2958
+ }
2959
+ if (((_a = time.hours) === null || _a === void 0 ? void 0 : _a[0]) === '0') {
2960
+ time.hours = time.hours.slice(1);
2961
+ }
2962
+ return "".concat(time.hours || '12', ":").concat(time.minutes || '00', " ").concat(time.ampm);
2963
+ }
2964
+ function convertTime(value, time24, keepDate) {
2965
+ var hasDate = extractDate(value);
2966
+ var timeString = extractTime(value);
2967
+ var timeValue = hasDate ? timeString : value;
2968
+ return !value
2969
+ ? undefined
2970
+ : (time24 && ((hasDate && keepDate && value) || militaryTime(timeValue))) ||
2971
+ regularTime(timeValue);
2972
+ }
2973
+ function timeSort(a, b) {
2974
+ var as = splitTime(a);
2975
+ var bs = splitTime(b);
2976
+ if (parseInt(as.hours) < parseInt(bs.hours))
2977
+ return -1;
2978
+ if (parseInt(as.hours) > parseInt(bs.hours))
2979
+ return 1;
2980
+ if (as.hours === bs.hours) {
2981
+ if (parseInt(as.minutes) < parseInt(bs.minutes))
2982
+ return -1;
2983
+ if (parseInt(as.minutes) > parseInt(bs.minutes))
2984
+ return 1;
2985
+ }
2986
+ return 0;
2987
+ }
2988
+ function addDays(date, days) {
2989
+ if (days === void 0) { days = 7; }
2990
+ var universalDate = extractDate(date) + 'T00:00';
2991
+ var now = new Date(universalDate);
2992
+ var adjustedDate = new Date(now.setDate(now.getDate() + days));
2993
+ return formatDate(adjustedDate);
2994
+ }
2995
+ function addWeek(date) {
2996
+ return addDays(date);
2997
+ }
2998
+ function getDateByWeek(week, year, dateFormat, sunday) {
2999
+ if (sunday === void 0) { sunday = false; }
3000
+ var date = new Date(year, 0, 1 + (week - 1) * 7);
3001
+ var startValue = sunday ? 0 : 1;
3002
+ date.setDate(date.getDate() + (startValue - date.getDay()));
3003
+ return formatDate(date, dateFormat);
3004
+ }
3005
+ function dateFromDay(year, day, dateFormat) {
3006
+ var date = new Date(year, 0); // initialize a date in `year-01-01`
3007
+ return formatDate(new Date(date.setDate(day)), dateFormat); // add the number of days
3008
+ }
3009
+ function timeToDate(timeString, date) {
3010
+ if (date === void 0) { date = undefined; }
3011
+ var _a = __read((timeString || '00:00').split(':').map(zeroPad), 2), hours = _a[0], minutes = _a[1];
3012
+ var milliseconds = offsetDate(date).setHours(hours, minutes, 0, 0);
3013
+ return offsetDate(milliseconds);
3014
+ }
3015
+ function minutesDifference(date1, date2, absolute) {
3016
+ if (absolute === void 0) { absolute = true; }
3017
+ var dt1 = new Date(date1);
3018
+ var dt2 = new Date(date2);
3019
+ var diff = (dt2.getTime() - dt1.getTime()) / 1000 / 60;
3020
+ return absolute ? Math.abs(Math.round(diff)) : Math.round(diff);
3021
+ }
3022
+ function addMinutesToTimeString(timeString, minutes) {
3023
+ var validTimeString = extractTime(timeString);
3024
+ if (!validTimeString)
3025
+ return '00:00';
3026
+ var minutesToAdd = isNaN(minutes) ? 0 : minutes;
3027
+ return extractTime(addMinutes(timeToDate(validTimeString), minutesToAdd).toISOString());
3028
+ }
3029
+ function addMinutes(startDate, minutes) {
3030
+ var date = new Date(startDate);
3031
+ return new Date(date.getTime() + minutes * 60000);
3032
+ }
3033
+ function zeroPad(number) {
3034
+ return number.toString()[1] ? number : '0' + number;
3634
3035
  }
3036
+ function sameDay(date1, date2) {
3037
+ var d1 = new Date(date1);
3038
+ var d2 = new Date(date2);
3039
+ return (d1.getFullYear() === d2.getFullYear() &&
3040
+ d1.getMonth() === d2.getMonth() &&
3041
+ d1.getDate() === d2.getDate());
3042
+ }
3043
+ var dateTime = {
3044
+ addDays: addDays,
3045
+ addWeek: addWeek,
3046
+ addMinutesToTimeString: addMinutesToTimeString,
3047
+ convertTime: convertTime,
3048
+ getIsoDateString: getIsoDateString,
3049
+ getUTCdateString: getUTCdateString,
3050
+ DateHHMM: DateHHMM,
3051
+ extractDate: extractDate,
3052
+ extractTime: extractTime,
3053
+ formatDate: formatDate,
3054
+ getDateByWeek: getDateByWeek,
3055
+ isISODateString: isISODateString,
3056
+ isDate: isDate,
3057
+ isTimeString: isTimeString,
3058
+ offsetDate: offsetDate,
3059
+ offsetTime: offsetTime,
3060
+ sameDay: sameDay,
3061
+ timeStringMinutes: timeStringMinutes,
3062
+ timeToDate: timeToDate,
3063
+ timeUTC: timeUTC,
3064
+ validTimeValue: validTimeValue,
3065
+ validDateString: validDateString,
3066
+ timeValidation: timeValidation,
3067
+ dateValidation: dateValidation,
3068
+ };
3635
3069
 
3636
3070
  var typeMatch = function (arr, type) {
3637
3071
  return arr.filter(Boolean).every(function (i) { return typeof i === type; });
@@ -3697,227 +3131,794 @@ function getCategoryAgeDetails(params) {
3697
3131
  addError("Invalid submitted ageMax: ".concat(ageMax));
3698
3132
  calculatedAgeMinDate = undefined;
3699
3133
  }
3700
- ageMax = ageInt - 1;
3134
+ ageMax = ageInt - 1;
3135
+ }
3136
+ };
3137
+ var uPost = function (ageInt) {
3138
+ var ageMinYear = consideredYear - ageInt - 1;
3139
+ var newMinDate = constructedDate(ageMinYear, nextMonthDay);
3140
+ if (category.ageMin && category.ageMin > ageInt) {
3141
+ addError("Invalid submitted ageMin: ".concat(ageMin));
3142
+ }
3143
+ if (category.ageMax && category.ageMax > ageInt) {
3144
+ addError("Invalid submitted ageMax: ".concat(ageMax));
3145
+ }
3146
+ if (category.ageMinDate && category.ageMinDate !== newMinDate)
3147
+ addError("Invalid submitted ageMinDate: ".concat(ageMinDate));
3148
+ ageMinDate = newMinDate;
3149
+ if (ageCategoryCode) {
3150
+ if (category.ageMax && category.ageMax !== ageInt) {
3151
+ addError("Invalid submitted ageMax: ".concat(ageMax));
3152
+ calculatedAgeMaxDate = undefined;
3153
+ }
3154
+ ageMax = ageInt;
3155
+ }
3156
+ };
3157
+ var oPre = function (ageInt) {
3158
+ var ageMaxYear = consideredYear - ageInt;
3159
+ var newMaxDate = constructedDate(ageMaxYear, previousMonthDay);
3160
+ if (category.ageMaxDate && category.ageMaxDate !== newMaxDate)
3161
+ addError("Invalid submitted ageMaxDate: ".concat(ageMaxDate));
3162
+ ageMaxDate = newMaxDate;
3163
+ if (ageCategoryCode) {
3164
+ if (category.ageMin && category.ageMin !== ageInt + 1) {
3165
+ addError("Invalid submitted ageMin: ".concat(ageMin));
3166
+ calculatedAgeMaxDate = undefined;
3167
+ }
3168
+ ageMin = ageInt + 1;
3169
+ }
3170
+ };
3171
+ var oPost = function (ageInt) {
3172
+ var ageMaxYear = consideredYear - ageInt - 1;
3173
+ var newMaxDate = constructedDate(ageMaxYear, previousMonthDay);
3174
+ if (category.ageMaxDate && category.ageMaxDate !== newMaxDate)
3175
+ addError("Invalid submitted ageMaxDate: ".concat(ageMaxDate));
3176
+ ageMaxDate = newMaxDate;
3177
+ if (ageCategoryCode) {
3178
+ if (category.ageMin && category.ageMin !== ageInt) {
3179
+ addError("Invalid submitted ageMin: ".concat(ageMin));
3180
+ calculatedAgeMaxDate = undefined;
3181
+ }
3182
+ ageMin = ageInt;
3183
+ }
3184
+ };
3185
+ var processCode = function (code) {
3186
+ var _a = __read((code.match(prePost) || []).slice(1), 3), pre = _a[0], age = _a[1], post = _a[2];
3187
+ var ageInt = parseInt(age);
3188
+ if (pre === 'U') {
3189
+ if (category.ageMaxDate && category.ageMaxDate !== ageMaxDate) {
3190
+ addError("Invalid submitted ageMaxDate: ".concat(category.ageMaxDate));
3191
+ }
3192
+ uPre(ageInt);
3193
+ }
3194
+ else if (pre === 'O') {
3195
+ oPre(ageInt);
3196
+ }
3197
+ if (post === 'U') {
3198
+ if (category.ageMaxDate && category.ageMaxDate !== ageMaxDate) {
3199
+ addError("Invalid submitted ageMaxDate: ".concat(category.ageMaxDate));
3200
+ }
3201
+ uPost(ageInt);
3202
+ }
3203
+ else if (post === 'O') {
3204
+ oPost(ageInt);
3205
+ }
3206
+ ageMaxDate = ageMaxDate !== null && ageMaxDate !== void 0 ? ageMaxDate : calculatedAgeMaxDate;
3207
+ ageMinDate = ageMinDate !== null && ageMinDate !== void 0 ? ageMinDate : calculatedAgeMinDate;
3208
+ };
3209
+ if (isCombined) {
3210
+ // min and max birthdates are not relevant
3211
+ // TODO: utility function to calculate combined age given two birthdates?
3212
+ ageMaxDate = undefined;
3213
+ ageMinDate = undefined;
3214
+ ageMax = undefined;
3215
+ ageMin = undefined;
3216
+ if (category.ageMin) {
3217
+ // calculate ageMaxDate
3218
+ var ageMaxYear = consideredYear - category.ageMin;
3219
+ ageMaxDate = constructedDate(ageMaxYear, previousMonthDay);
3220
+ }
3221
+ if (category.ageMax) {
3222
+ // calculate ageMinDate
3223
+ var ageMinYear = consideredYear - category.ageMax - 1;
3224
+ ageMinDate = constructedDate(ageMinYear, nextMonthDay);
3225
+ }
3226
+ var _f = __read(((_b = ageCategoryCode === null || ageCategoryCode === void 0 ? void 0 : ageCategoryCode.match(extractCombined)) !== null && _b !== void 0 ? _b : [])
3227
+ .slice(1)
3228
+ .map(function (n) { return parseInt(n); }), 2), lowAge = _f[0], highAge = _f[1];
3229
+ if (lowAge <= highAge) {
3230
+ ageMin = lowAge;
3231
+ ageMax = highAge;
3232
+ combinedAge = true;
3233
+ }
3234
+ else {
3235
+ addError("Invalid combined age range ".concat(ageCategoryCode));
3236
+ }
3237
+ }
3238
+ else if (isBetween) {
3239
+ ageCategoryCode === null || ageCategoryCode === void 0 ? void 0 : ageCategoryCode.split('-').forEach(processCode);
3240
+ }
3241
+ else if (isCoded) {
3242
+ processCode(ageCategoryCode);
3243
+ }
3244
+ else {
3245
+ if (ageMin)
3246
+ oPre(ageMin);
3247
+ if (ageMax)
3248
+ uPost(ageMax);
3249
+ }
3250
+ if (ageMax && category.ageMin && category.ageMin > ageMax) {
3251
+ addError("Invalid submitted ageMin: ".concat(category.ageMin));
3252
+ ageMin = undefined;
3253
+ }
3254
+ var result = definedAttributes({
3255
+ consideredDate: consideredDate,
3256
+ combinedAge: combinedAge,
3257
+ ageMaxDate: ageMaxDate,
3258
+ ageMinDate: ageMinDate,
3259
+ ageMax: ageMax,
3260
+ ageMin: ageMin,
3261
+ });
3262
+ if (errors.length)
3263
+ result.errors = errors;
3264
+ return result;
3265
+ }
3266
+
3267
+ function makeDeepCopy(sourceObject, // arbitrary JSON object; functions will be stripped.
3268
+ convertExtensions, // optional - all extension objects converted to attributes ._key
3269
+ internalUse, // disregard deepCopy being disabled within the engine - necessary for query results
3270
+ removeExtensions, // optional - strip all extension attributes
3271
+ iteration // escape hatch - check against iteration threshold
3272
+ ) {
3273
+ var e_1, _a;
3274
+ if (iteration === void 0) { iteration = 0; }
3275
+ if (getProvider().makeDeepCopy)
3276
+ return getProvider().makeDeepCopy(sourceObject, convertExtensions, internalUse, removeExtensions);
3277
+ var deepCopy = deepCopyEnabled();
3278
+ var _b = deepCopy || {}, stringify = _b.stringify, toJSON = _b.toJSON, ignore = _b.ignore, modulate = _b.modulate;
3279
+ if ((!(deepCopy === null || deepCopy === void 0 ? void 0 : deepCopy.enabled) && !internalUse) ||
3280
+ typeof sourceObject !== 'object' ||
3281
+ typeof sourceObject === 'function' ||
3282
+ sourceObject === null ||
3283
+ (typeof (deepCopy === null || deepCopy === void 0 ? void 0 : deepCopy.threshold) === 'number' && iteration >= deepCopy.threshold)) {
3284
+ return sourceObject;
3285
+ }
3286
+ var targetObject = Array.isArray(sourceObject) ? [] : {};
3287
+ var sourceObjectKeys = Object.keys(sourceObject).filter(function (key) {
3288
+ return !internalUse ||
3289
+ !ignore ||
3290
+ (Array.isArray(ignore) && !ignore.includes(key)) ||
3291
+ (typeof ignore === 'function' && !ignore(key));
3292
+ });
3293
+ var stringifyValue = function (key, value) {
3294
+ targetObject[key] =
3295
+ typeof (value === null || value === void 0 ? void 0 : value.toString) === 'function'
3296
+ ? value.toString()
3297
+ : JSON.stringify(value);
3298
+ };
3299
+ try {
3300
+ for (var sourceObjectKeys_1 = __values(sourceObjectKeys), sourceObjectKeys_1_1 = sourceObjectKeys_1.next(); !sourceObjectKeys_1_1.done; sourceObjectKeys_1_1 = sourceObjectKeys_1.next()) {
3301
+ var key = sourceObjectKeys_1_1.value;
3302
+ var value = sourceObject[key];
3303
+ var modulated = typeof modulate === 'function' ? modulate(value) : undefined;
3304
+ if (modulated !== undefined) {
3305
+ targetObject[key] = modulated;
3306
+ }
3307
+ else if (convertExtensions &&
3308
+ key === 'extensions' &&
3309
+ Array.isArray(value)) {
3310
+ var extensionConversions = extensionsToAttributes(value);
3311
+ Object.assign.apply(Object, __spreadArray([targetObject], __read(extensionConversions), false));
3312
+ }
3313
+ else if (removeExtensions && key === 'extensions') {
3314
+ targetObject[key] = [];
3315
+ }
3316
+ else if (Array.isArray(stringify) && stringify.includes(key)) {
3317
+ stringifyValue(key, value);
3318
+ }
3319
+ else if (Array.isArray(toJSON) &&
3320
+ toJSON.includes(key) &&
3321
+ typeof (value === null || value === void 0 ? void 0 : value.toJSON) === 'function') {
3322
+ targetObject[key] = value.toJSON();
3323
+ }
3324
+ else if (value === null) {
3325
+ targetObject[key] = undefined;
3326
+ }
3327
+ else if (isDateObject(value)) {
3328
+ targetObject[key] = new Date(value).toISOString();
3329
+ }
3330
+ else {
3331
+ targetObject[key] = makeDeepCopy(value, convertExtensions, internalUse, removeExtensions, iteration + 1);
3332
+ }
3701
3333
  }
3702
- };
3703
- var uPost = function (ageInt) {
3704
- var ageMinYear = consideredYear - ageInt - 1;
3705
- var newMinDate = constructedDate(ageMinYear, nextMonthDay);
3706
- if (category.ageMin && category.ageMin > ageInt) {
3707
- addError("Invalid submitted ageMin: ".concat(ageMin));
3334
+ }
3335
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3336
+ finally {
3337
+ try {
3338
+ if (sourceObjectKeys_1_1 && !sourceObjectKeys_1_1.done && (_a = sourceObjectKeys_1.return)) _a.call(sourceObjectKeys_1);
3708
3339
  }
3709
- if (category.ageMax && category.ageMax > ageInt) {
3710
- addError("Invalid submitted ageMax: ".concat(ageMax));
3340
+ finally { if (e_1) throw e_1.error; }
3341
+ }
3342
+ return targetObject;
3343
+ }
3344
+ function extensionsToAttributes(extensions) {
3345
+ return extensions === null || extensions === void 0 ? void 0 : extensions.map(function (extension) {
3346
+ var _a;
3347
+ var name = extension.name, value = extension.value;
3348
+ return name && value && (_a = {}, _a["_".concat(name)] = value, _a);
3349
+ }).filter(Boolean);
3350
+ }
3351
+
3352
+ function getAccessorValue(_a) {
3353
+ var element = _a.element, accessor = _a.accessor;
3354
+ if (typeof accessor !== 'string')
3355
+ return { values: [] };
3356
+ var targetElement = makeDeepCopy(element);
3357
+ var attributes = accessor.split('.');
3358
+ var values = [];
3359
+ var value;
3360
+ processKeys({ targetElement: targetElement, attributes: attributes });
3361
+ var result = { value: value };
3362
+ if (values.length)
3363
+ result.values = values;
3364
+ return result;
3365
+ function processKeys(_a) {
3366
+ var e_1, _b;
3367
+ var targetElement = _a.targetElement, _c = _a.attributes, attributes = _c === void 0 ? [] : _c, significantCharacters = _a.significantCharacters;
3368
+ var _loop_1 = function (index, attribute) {
3369
+ if (targetElement === null || targetElement === void 0 ? void 0 : targetElement[attribute]) {
3370
+ var remainingKeys_1 = attributes.slice(index + 1);
3371
+ if (!remainingKeys_1.length) {
3372
+ if (!value)
3373
+ value = targetElement[attribute];
3374
+ if (!values.includes(targetElement[attribute])) {
3375
+ values.push(targetElement[attribute]);
3376
+ }
3377
+ }
3378
+ else if (Array.isArray(targetElement[attribute])) {
3379
+ var values_1 = targetElement[attribute];
3380
+ values_1.forEach(function (nestedTarget) {
3381
+ return processKeys({
3382
+ targetElement: nestedTarget,
3383
+ attributes: remainingKeys_1,
3384
+ });
3385
+ });
3386
+ }
3387
+ else {
3388
+ targetElement = targetElement[attribute];
3389
+ checkValue({ targetElement: targetElement, index: index });
3390
+ }
3391
+ }
3392
+ };
3393
+ try {
3394
+ for (var _d = __values(attributes.entries()), _e = _d.next(); !_e.done; _e = _d.next()) {
3395
+ var _f = __read(_e.value, 2), index = _f[0], attribute = _f[1];
3396
+ _loop_1(index, attribute);
3397
+ }
3711
3398
  }
3712
- if (category.ageMinDate && category.ageMinDate !== newMinDate)
3713
- addError("Invalid submitted ageMinDate: ".concat(ageMinDate));
3714
- ageMinDate = newMinDate;
3715
- if (ageCategoryCode) {
3716
- if (category.ageMax && category.ageMax !== ageInt) {
3717
- addError("Invalid submitted ageMax: ".concat(ageMax));
3718
- calculatedAgeMaxDate = undefined;
3399
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3400
+ finally {
3401
+ try {
3402
+ if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
3719
3403
  }
3720
- ageMax = ageInt;
3404
+ finally { if (e_1) throw e_1.error; }
3721
3405
  }
3722
- };
3723
- var oPre = function (ageInt) {
3724
- var ageMaxYear = consideredYear - ageInt;
3725
- var newMaxDate = constructedDate(ageMaxYear, previousMonthDay);
3726
- if (category.ageMaxDate && category.ageMaxDate !== newMaxDate)
3727
- addError("Invalid submitted ageMaxDate: ".concat(ageMaxDate));
3728
- ageMaxDate = newMaxDate;
3729
- if (ageCategoryCode) {
3730
- if (category.ageMin && category.ageMin !== ageInt + 1) {
3731
- addError("Invalid submitted ageMin: ".concat(ageMin));
3732
- calculatedAgeMaxDate = undefined;
3406
+ function checkValue(_a) {
3407
+ var targetElement = _a.targetElement, index = _a.index;
3408
+ if (targetElement &&
3409
+ index === attributes.length - 1 &&
3410
+ ['string', 'number'].includes(typeof targetElement)) {
3411
+ var extractedValue = significantCharacters
3412
+ ? targetElement.slice(0, significantCharacters)
3413
+ : targetElement;
3414
+ if (value) {
3415
+ if (!values.includes(extractedValue)) {
3416
+ values.push(extractedValue);
3417
+ }
3418
+ }
3419
+ else {
3420
+ value = extractedValue;
3421
+ values.push(extractedValue);
3422
+ }
3733
3423
  }
3734
- ageMin = ageInt + 1;
3735
3424
  }
3736
- };
3737
- var oPost = function (ageInt) {
3738
- var ageMaxYear = consideredYear - ageInt - 1;
3739
- var newMaxDate = constructedDate(ageMaxYear, previousMonthDay);
3740
- if (category.ageMaxDate && category.ageMaxDate !== newMaxDate)
3741
- addError("Invalid submitted ageMaxDate: ".concat(ageMaxDate));
3742
- ageMaxDate = newMaxDate;
3743
- if (ageCategoryCode) {
3744
- if (category.ageMin && category.ageMin !== ageInt) {
3745
- addError("Invalid submitted ageMin: ".concat(ageMin));
3746
- calculatedAgeMaxDate = undefined;
3425
+ }
3426
+ }
3427
+
3428
+ function isString(obj) {
3429
+ return typeof obj === 'string';
3430
+ }
3431
+ function isObject(obj) {
3432
+ return obj !== null && typeof obj === 'object';
3433
+ }
3434
+ function objShallowEqual(o1, o2) {
3435
+ var e_1, _a;
3436
+ if (!isObject(o1) || !isObject(o2))
3437
+ return false;
3438
+ var keys1 = Object.keys(o1);
3439
+ var keys2 = Object.keys(o2);
3440
+ if (keys1.length !== keys2.length) {
3441
+ return false;
3442
+ }
3443
+ try {
3444
+ for (var keys1_1 = __values(keys1), keys1_1_1 = keys1_1.next(); !keys1_1_1.done; keys1_1_1 = keys1_1.next()) {
3445
+ var key = keys1_1_1.value;
3446
+ if (o1[key] !== o2[key]) {
3447
+ return false;
3448
+ }
3449
+ }
3450
+ }
3451
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3452
+ finally {
3453
+ try {
3454
+ if (keys1_1_1 && !keys1_1_1.done && (_a = keys1_1.return)) _a.call(keys1_1);
3455
+ }
3456
+ finally { if (e_1) throw e_1.error; }
3457
+ }
3458
+ return true;
3459
+ }
3460
+ function createMap(objectArray, attribute) {
3461
+ if (!Array.isArray(objectArray))
3462
+ return {};
3463
+ return Object.assign.apply(Object, __spreadArray([{}], __read((objectArray !== null && objectArray !== void 0 ? objectArray : [])
3464
+ .filter(isObject)
3465
+ .map(function (obj) {
3466
+ var _a;
3467
+ return (obj[attribute] && (_a = {},
3468
+ _a[obj[attribute]] = obj,
3469
+ _a));
3470
+ })
3471
+ .filter(Boolean)), false));
3472
+ }
3473
+ // e.g. result.find(hav({ attr: value })) -or- result.filter(hav({ attr: value }))
3474
+ var hasAttributeValues = function (a) { return function (o) {
3475
+ return Object.keys(a).every(function (key) { return o[key] === a[key]; });
3476
+ }; };
3477
+ // extracts targeted attributes
3478
+ // e.g. const byeAssignments = positionAssignments.filter(xa('bye')).map(xa('drawPosition'));
3479
+ // supports xa('string'), xa(['string', 'string']), xa({ attr1: true, attr2: true })
3480
+ var extractAttributes = function (accessor) { return function (element) {
3481
+ var _a;
3482
+ return !accessor || typeof element !== 'object'
3483
+ ? undefined
3484
+ : (Array.isArray(accessor) &&
3485
+ accessor.map(function (a) {
3486
+ var _a;
3487
+ var _b;
3488
+ return (_a = {},
3489
+ _a[a] = (_b = getAccessorValue({ element: element, accessor: a })) === null || _b === void 0 ? void 0 : _b.value,
3490
+ _a);
3491
+ })) ||
3492
+ (typeof accessor === 'object' &&
3493
+ Object.keys(accessor).map(function (key) {
3494
+ var _a;
3495
+ var _b;
3496
+ return (_a = {},
3497
+ _a[key] = (_b = getAccessorValue({ element: element, accessor: key })) === null || _b === void 0 ? void 0 : _b.value,
3498
+ _a);
3499
+ })) ||
3500
+ ((_a = (typeof accessor === 'string' && getAccessorValue({ element: element, accessor: accessor }))) === null || _a === void 0 ? void 0 : _a.value);
3501
+ }; };
3502
+ function countKeys(o) {
3503
+ if (Array.isArray(o)) {
3504
+ return o.length + o.map(countKeys).reduce(function (a, b) { return a + b; }, 0);
3505
+ }
3506
+ else if (typeof o === 'object' && o !== null) {
3507
+ return (Object.keys(o).length +
3508
+ Object.keys(o)
3509
+ .map(function (k) { return countKeys(o[k]); })
3510
+ .reduce(function (a, b) { return a + b; }, 0));
3511
+ }
3512
+ return 0;
3513
+ }
3514
+ function generateHashCode(o) {
3515
+ if (o === null || typeof o !== 'object')
3516
+ return undefined;
3517
+ var str = JSON.stringify(o);
3518
+ var keyCount = countKeys(o);
3519
+ var charSum = str.split('').reduce(function (a, b) { return a + b.charCodeAt(0); }, 0);
3520
+ return [str.length, keyCount, charSum].map(function (e) { return e.toString(36); }).join('');
3521
+ }
3522
+
3523
+ function validateCategory(_a) {
3524
+ var category = _a.category;
3525
+ if (!isObject(category))
3526
+ return { error: INVALID_VALUES };
3527
+ var categoryDetails = getCategoryAgeDetails({ category: category });
3528
+ if (categoryDetails.error)
3529
+ return { error: categoryDetails };
3530
+ var ratingMax = category.ratingMax, ratingMin = category.ratingMin;
3531
+ if (ratingMax && !isNumeric(ratingMax))
3532
+ return decorateResult({
3533
+ result: { error: INVALID_VALUES },
3534
+ context: { ratingMax: ratingMax },
3535
+ });
3536
+ if (ratingMin && !isNumeric(ratingMin))
3537
+ return decorateResult({
3538
+ result: { error: INVALID_VALUES },
3539
+ context: { ratingMin: ratingMin },
3540
+ });
3541
+ return __assign({}, categoryDetails);
3542
+ }
3543
+
3544
+ function categoryCanContain(_a) {
3545
+ var childCategory = _a.childCategory, withDetails = _a.withDetails, category = _a.category;
3546
+ var categoryDetails = validateCategory({ category: category });
3547
+ var childCategoryDetails = validateCategory({
3548
+ category: childCategory,
3549
+ });
3550
+ var invalidAgeMin = childCategoryDetails.ageMin &&
3551
+ ((categoryDetails.ageMin &&
3552
+ childCategoryDetails.ageMin < categoryDetails.ageMin) ||
3553
+ (categoryDetails.ageMax &&
3554
+ childCategoryDetails.ageMin > categoryDetails.ageMax));
3555
+ var invalidAgeMax = childCategoryDetails.ageMax &&
3556
+ ((categoryDetails.ageMax &&
3557
+ childCategoryDetails.ageMax > categoryDetails.ageMax) ||
3558
+ (categoryDetails.ageMin &&
3559
+ childCategoryDetails.ageMax < categoryDetails.ageMin));
3560
+ var invalidAgeMinDate = childCategoryDetails.ageMinDate &&
3561
+ categoryDetails.ageMaxDate &&
3562
+ new Date(childCategoryDetails.ageMinDate) >
3563
+ new Date(categoryDetails.ageMaxDate);
3564
+ var invalidAgeMaxDate = childCategoryDetails.ageMaxDate &&
3565
+ categoryDetails.ageMinDate &&
3566
+ new Date(childCategoryDetails.ageMaxDate) <
3567
+ new Date(categoryDetails.ageMinDate);
3568
+ var ratingComparison = category.ratingType &&
3569
+ childCategory.ratingType &&
3570
+ category.ratingType === childCategory.ratingType;
3571
+ var invalidRatingRange = ratingComparison &&
3572
+ ((category.ratingMin &&
3573
+ childCategory.ratingMin &&
3574
+ childCategory.ratingMin < category.ratingMin) ||
3575
+ (category.ratingMax &&
3576
+ childCategory.ratingMax &&
3577
+ childCategory.ratingMax > category.ratingMax) ||
3578
+ (category.ratingMin &&
3579
+ childCategory.ratingMax &&
3580
+ childCategory.ratingMax < category.ratingMin) ||
3581
+ (category.ratingMax &&
3582
+ childCategory.ratingMin &&
3583
+ childCategory.ratingMin > category.ratingMax));
3584
+ var invalidBallType = category.ballType &&
3585
+ childCategory.ballType &&
3586
+ category.ballType !== childCategory.ballType;
3587
+ var valid = !invalidRatingRange &&
3588
+ !invalidAgeMinDate &&
3589
+ !invalidAgeMaxDate &&
3590
+ !invalidBallType &&
3591
+ !invalidAgeMax &&
3592
+ !invalidAgeMin;
3593
+ var ignoreFalse = true;
3594
+ var result = definedAttributes({
3595
+ invalidRatingRange: invalidRatingRange,
3596
+ invalidAgeMinDate: invalidAgeMinDate,
3597
+ invalidAgeMaxDate: invalidAgeMaxDate,
3598
+ invalidBallType: invalidBallType,
3599
+ invalidAgeMax: invalidAgeMax,
3600
+ invalidAgeMin: invalidAgeMin,
3601
+ valid: valid,
3602
+ }, ignoreFalse);
3603
+ if (withDetails) {
3604
+ Object.assign(result, { categoryDetails: categoryDetails, childCategoryDetails: childCategoryDetails });
3605
+ }
3606
+ return result;
3607
+ }
3608
+
3609
+ function mustBeAnArray(value) {
3610
+ return "".concat(value, " must be an array");
3611
+ }
3612
+
3613
+ // NOTE: type really does need to be any!
3614
+ function attributeFilter(params) {
3615
+ if (params === null)
3616
+ return {};
3617
+ var _a = params || {}, source = _a.source, template = _a.template;
3618
+ if (!template)
3619
+ return source;
3620
+ var target = {};
3621
+ attributeCopy(source, template, target);
3622
+ return target;
3623
+ function attributeCopy(valuesObject, templateObject, outputObject) {
3624
+ var e_1, _a;
3625
+ if (!valuesObject || !templateObject)
3626
+ return undefined;
3627
+ var vKeys = Object.keys(valuesObject);
3628
+ var oKeys = Object.keys(templateObject);
3629
+ // the orMap allows spcification of { 'a||b': boolean } so that filter templates can apply to multiple attributes
3630
+ var orMap = Object.assign.apply(Object, __spreadArray([{}], __read(oKeys
3631
+ .filter(function (key) { return key.indexOf('||'); })
3632
+ .map(function (key) { return key.split('||').map(function (or) {
3633
+ var _a;
3634
+ return (_a = {}, _a[or] = key, _a);
3635
+ }); })
3636
+ .flat()), false));
3637
+ var allKeys = oKeys.concat.apply(oKeys, __spreadArray([], __read(Object.keys(orMap)), false));
3638
+ var wildcard = allKeys.includes('*');
3639
+ var _loop_1 = function (vKey) {
3640
+ if (allKeys.indexOf(vKey) >= 0 || wildcard) {
3641
+ var templateKey = orMap[vKey] || vKey;
3642
+ var tobj_1 = templateObject[templateKey] || wildcard;
3643
+ var vobj = valuesObject[vKey];
3644
+ if (typeof tobj_1 === 'object' &&
3645
+ typeof vobj !== 'function' &&
3646
+ !Array.isArray(tobj_1)) {
3647
+ if (Array.isArray(vobj)) {
3648
+ var mappedElements = vobj
3649
+ .map(function (arrayMember) {
3650
+ var target = {};
3651
+ var result = attributeCopy(arrayMember, tobj_1, target);
3652
+ return result !== false ? target : undefined;
3653
+ })
3654
+ .filter(Boolean);
3655
+ outputObject[vKey] = mappedElements;
3656
+ }
3657
+ else if (vobj) {
3658
+ outputObject[vKey] = {};
3659
+ attributeCopy(vobj, tobj_1, outputObject[vKey]);
3660
+ }
3661
+ }
3662
+ else {
3663
+ var value = valuesObject[vKey];
3664
+ var exclude = Array.isArray(tobj_1) && !tobj_1.includes(value);
3665
+ if (exclude)
3666
+ return { value: false };
3667
+ if (templateObject[vKey] ||
3668
+ (wildcard && templateObject[vKey] !== false)) {
3669
+ outputObject[vKey] = value;
3670
+ }
3671
+ }
3747
3672
  }
3748
- ageMin = ageInt;
3749
- }
3750
- };
3751
- var processCode = function (code) {
3752
- var _a = __read((code.match(prePost) || []).slice(1), 3), pre = _a[0], age = _a[1], post = _a[2];
3753
- var ageInt = parseInt(age);
3754
- if (pre === 'U') {
3755
- if (category.ageMaxDate && category.ageMaxDate !== ageMaxDate) {
3756
- addError("Invalid submitted ageMaxDate: ".concat(category.ageMaxDate));
3673
+ };
3674
+ try {
3675
+ for (var vKeys_1 = __values(vKeys), vKeys_1_1 = vKeys_1.next(); !vKeys_1_1.done; vKeys_1_1 = vKeys_1.next()) {
3676
+ var vKey = vKeys_1_1.value;
3677
+ var state_1 = _loop_1(vKey);
3678
+ if (typeof state_1 === "object")
3679
+ return state_1.value;
3757
3680
  }
3758
- uPre(ageInt);
3759
- }
3760
- else if (pre === 'O') {
3761
- oPre(ageInt);
3762
3681
  }
3763
- if (post === 'U') {
3764
- if (category.ageMaxDate && category.ageMaxDate !== ageMaxDate) {
3765
- addError("Invalid submitted ageMaxDate: ".concat(category.ageMaxDate));
3682
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3683
+ finally {
3684
+ try {
3685
+ if (vKeys_1_1 && !vKeys_1_1.done && (_a = vKeys_1.return)) _a.call(vKeys_1);
3766
3686
  }
3767
- uPost(ageInt);
3768
- }
3769
- else if (post === 'O') {
3770
- oPost(ageInt);
3771
- }
3772
- ageMaxDate = ageMaxDate !== null && ageMaxDate !== void 0 ? ageMaxDate : calculatedAgeMaxDate;
3773
- ageMinDate = ageMinDate !== null && ageMinDate !== void 0 ? ageMinDate : calculatedAgeMinDate;
3774
- };
3775
- if (isCombined) {
3776
- // min and max birthdates are not relevant
3777
- // TODO: utility function to calculate combined age given two birthdates?
3778
- ageMaxDate = undefined;
3779
- ageMinDate = undefined;
3780
- ageMax = undefined;
3781
- ageMin = undefined;
3782
- if (category.ageMin) {
3783
- // calculate ageMaxDate
3784
- var ageMaxYear = consideredYear - category.ageMin;
3785
- ageMaxDate = constructedDate(ageMaxYear, previousMonthDay);
3786
- }
3787
- if (category.ageMax) {
3788
- // calculate ageMinDate
3789
- var ageMinYear = consideredYear - category.ageMax - 1;
3790
- ageMinDate = constructedDate(ageMinYear, nextMonthDay);
3687
+ finally { if (e_1) throw e_1.error; }
3791
3688
  }
3792
- var _f = __read(((_b = ageCategoryCode === null || ageCategoryCode === void 0 ? void 0 : ageCategoryCode.match(extractCombined)) !== null && _b !== void 0 ? _b : [])
3793
- .slice(1)
3794
- .map(function (n) { return parseInt(n); }), 2), lowAge = _f[0], highAge = _f[1];
3795
- if (lowAge <= highAge) {
3796
- ageMin = lowAge;
3797
- ageMax = highAge;
3798
- combinedAge = true;
3689
+ return undefined;
3690
+ }
3691
+ }
3692
+
3693
+ function generateTimeCode(index) {
3694
+ if (index === void 0) { index = 0; }
3695
+ var uidate = new Date();
3696
+ uidate.setHours(uidate.getHours() + index);
3697
+ return uidate.getTime().toString(36).slice(-6).toUpperCase();
3698
+ }
3699
+
3700
+ /**
3701
+ *
3702
+ * @param {object[]} arrayOfJSON - JSON objects array
3703
+ * @param {object} config - object which configures processing (see below)
3704
+ * @returns {string} - joined by '\r\n' or specified line separator
3705
+ *
3706
+ * config {
3707
+ * {boolean} includeTransformAccessors, // transform accessors are included with columnAccessors
3708
+ * {string[]} columnAccessors, // [ 'includeThis', 'andThis' ]
3709
+ * {object} columnTransform, // e.g. { 'newColumnName': ['oldColumn1', 'oldColumn2' ]}
3710
+ * {object} columnMap, // e.g. { 'columnName': 'newColumnName' }
3711
+ * {object} valuesMap, // e.g. { 'columnName': { 'value1': 'mappedValue' }} // useful for mapping IDs
3712
+ * {array} sortOrder // e.g. ['columnName1', 'columnName2'] // determine order of csv columns
3713
+ * {object} context, // attributes which are to be added to all rows { 'columnName': 'value }
3714
+ * {string} delimiter, // defaults to '"'
3715
+ * {string} columnJoiner, // defaults to ',' // defines how CSV columns are joined
3716
+ * {string} rowJoiner, // defaults to '\r\n' // defines how CSV lines are joined
3717
+ * {string} keyJoiner, // defaults to '.' // defines how flattened column names are constructed
3718
+ * }
3719
+ *
3720
+ * NOTE: `columnTransform` mapped array elements are sensitive to order and will resolve to the first matching value
3721
+ * NOTE: `columnMap` should not contain new columnName(s) that are `columnTransform` keys
3722
+ */
3723
+ function JSON2CSV(arrayOfJSON, config) {
3724
+ if (config && typeof config !== 'object')
3725
+ return INVALID_VALUES;
3726
+ var _a = (config || {}).columnTransform, columnTransform = _a === void 0 ? {} : _a;
3727
+ var _b = config || {}, includeTransformAccessors = _b.includeTransformAccessors, _c = _b.includeHeaderRow, includeHeaderRow = _c === void 0 ? true : _c, returnTransformedJSON = _b.returnTransformedJSON, removeEmptyColumns = _b.removeEmptyColumns, onlyHeaderRow = _b.onlyHeaderRow, _d = _b.columnAccessors, columnAccessors = _d === void 0 ? [] : _d, _e = _b.functionMap, functionMap = _e === void 0 ? {} : _e, _f = _b.columnMap, columnMap = _f === void 0 ? {} : _f, _g = _b.valuesMap, valuesMap = _g === void 0 ? {} : _g, _h = _b.context, context = _h === void 0 ? {} : _h, _j = _b.delimiter, delimiter = _j === void 0 ? '"' : _j, _k = _b.columnJoiner, columnJoiner = _k === void 0 ? ',' : _k, _l = _b.rowJoiner, rowJoiner = _l === void 0 ? '\r\n' : _l, _m = _b.keyJoiner, keyJoiner = _m === void 0 ? '.' : _m;
3728
+ if (!Array.isArray(arrayOfJSON) ||
3729
+ !Array.isArray(columnAccessors) ||
3730
+ typeof context !== 'object' ||
3731
+ typeof columnMap !== 'object' ||
3732
+ typeof columnTransform !== 'object' ||
3733
+ typeof functionMap !== 'object' ||
3734
+ typeof valuesMap !== 'object' ||
3735
+ typeof columnJoiner !== 'string' ||
3736
+ typeof rowJoiner !== 'string' ||
3737
+ typeof keyJoiner !== 'string' ||
3738
+ typeof delimiter !== 'string')
3739
+ return INVALID_VALUES;
3740
+ // ensure all column transformers are arrays
3741
+ columnTransform = Object.assign.apply(Object, __spreadArray([{}], __read(Object.keys(columnTransform)
3742
+ .reverse() // reverse so that exported CSV columns are in the order as defined
3743
+ .map(function (key) {
3744
+ var _a;
3745
+ return (_a = {},
3746
+ _a[key] = Array.isArray(columnTransform[key])
3747
+ ? columnTransform[key]
3748
+ : [
3749
+ // ensure transform attributes are strings
3750
+ typeof columnTransform[key] === 'string' && columnTransform[key],
3751
+ ].filter(Boolean),
3752
+ _a);
3753
+ })), false));
3754
+ var flattened = arrayOfJSON
3755
+ .filter(Boolean)
3756
+ .map(function (obj) { return flattenJSON(obj, keyJoiner); });
3757
+ var transformColumns = Object.values(columnTransform).flat();
3758
+ if (includeTransformAccessors)
3759
+ columnAccessors.push.apply(columnAccessors, __spreadArray([], __read(transformColumns), false));
3760
+ var headerRow = flattened
3761
+ .reduce(function (aggregator, row) {
3762
+ return Object.keys(row).every(function (key) { return (!aggregator.includes(key) && aggregator.push(key)) || true; }) && aggregator;
3763
+ }, [])
3764
+ .filter(function (key) { return !(columnAccessors === null || columnAccessors === void 0 ? void 0 : columnAccessors.length) || columnAccessors.includes(key); });
3765
+ var accessorMap = Object.assign.apply(Object, __spreadArray([{}], __read(Object.keys(columnTransform)
3766
+ .reverse() // so that original order is preserved when later pushed
3767
+ .map(function (transform) {
3768
+ return columnTransform[transform]
3769
+ .map(function (value) {
3770
+ var _a;
3771
+ return (_a = {}, _a[value] = transform, _a);
3772
+ })
3773
+ .flat();
3774
+ })
3775
+ .flat()), false));
3776
+ var sortColumns = function (a, b) {
3777
+ return !(config === null || config === void 0 ? void 0 : config.sortOrder)
3778
+ ? 0
3779
+ : (config.sortOrder.includes(a) &&
3780
+ config.sortOrder.includes(b) &&
3781
+ config.sortOrder.indexOf(a) - config.sortOrder.indexOf(b)) ||
3782
+ (!config.sortOrder.includes(b) && -1);
3783
+ };
3784
+ var tranformedHeaderRow = headerRow
3785
+ .reduce(function (def, key) {
3786
+ var transform = accessorMap[key];
3787
+ if (transform) {
3788
+ if (!def.includes(transform))
3789
+ def.push(transform);
3799
3790
  }
3800
3791
  else {
3801
- addError("Invalid combined age range ".concat(ageCategoryCode));
3792
+ def.push(key);
3802
3793
  }
3803
- }
3804
- else if (isBetween) {
3805
- ageCategoryCode === null || ageCategoryCode === void 0 ? void 0 : ageCategoryCode.split('-').forEach(processCode);
3806
- }
3807
- else if (isCoded) {
3808
- processCode(ageCategoryCode);
3809
- }
3810
- else {
3811
- if (ageMin)
3812
- oPre(ageMin);
3813
- if (ageMax)
3814
- uPost(ageMax);
3815
- }
3816
- if (ageMax && category.ageMin && category.ageMin > ageMax) {
3817
- addError("Invalid submitted ageMin: ".concat(category.ageMin));
3818
- ageMin = undefined;
3819
- }
3820
- var result = definedAttributes({
3821
- consideredDate: consideredDate,
3822
- combinedAge: combinedAge,
3823
- ageMaxDate: ageMaxDate,
3824
- ageMinDate: ageMinDate,
3825
- ageMax: ageMax,
3826
- ageMin: ageMin,
3794
+ return def;
3795
+ }, [])
3796
+ .sort(sortColumns);
3797
+ Object.keys(columnMap).forEach(function (columnName) {
3798
+ return !tranformedHeaderRow.includes(columnName) &&
3799
+ tranformedHeaderRow.unshift(columnName);
3827
3800
  });
3828
- if (errors.length)
3829
- result.errors = errors;
3830
- return result;
3831
- }
3832
-
3833
- function validateCategory(_a) {
3834
- var category = _a.category;
3835
- if (!isObject(category))
3836
- return { error: INVALID_VALUES };
3837
- var categoryDetails = getCategoryAgeDetails({ category: category });
3838
- if (categoryDetails.error)
3839
- return { error: categoryDetails };
3840
- var ratingMax = category.ratingMax, ratingMin = category.ratingMin;
3841
- if (ratingMax && !isNumeric(ratingMax))
3842
- return decorateResult({
3843
- result: { error: INVALID_VALUES },
3844
- context: { ratingMax: ratingMax },
3801
+ Object.keys(columnTransform).forEach(function (columnName) {
3802
+ return !tranformedHeaderRow.includes(columnName) &&
3803
+ tranformedHeaderRow.unshift(columnName);
3804
+ });
3805
+ typeof context === 'object' &&
3806
+ Object.keys(context).forEach(function (columnName) {
3807
+ return !tranformedHeaderRow.includes(columnName) &&
3808
+ tranformedHeaderRow.unshift(columnName);
3845
3809
  });
3846
- if (ratingMin && !isNumeric(ratingMin))
3847
- return decorateResult({
3848
- result: { error: INVALID_VALUES },
3849
- context: { ratingMin: ratingMin },
3810
+ var mappedHeaderRow = tranformedHeaderRow.map(function (key) { return columnMap[key] || key; });
3811
+ if (onlyHeaderRow)
3812
+ return [mappedHeaderRow];
3813
+ var withDelimiter = function (value) { return "".concat(delimiter).concat(value).concat(delimiter); };
3814
+ var columnValueCounts = [];
3815
+ var processRow = function (row) {
3816
+ return Object.values(tranformedHeaderRow.reduce(function (columnsMap, columnName, columnIndex) {
3817
+ var _a;
3818
+ var accessors = columnTransform[columnName];
3819
+ var value = ((accessors === null || accessors === void 0 ? void 0 : accessors.length)
3820
+ ? row[accessors.find(function (accessor) { return row[accessor]; })]
3821
+ : row[columnName]) ||
3822
+ (context === null || context === void 0 ? void 0 : context[columnName]) ||
3823
+ '';
3824
+ var mappedValue = ((_a = valuesMap[columnName]) === null || _a === void 0 ? void 0 : _a[value]) || value;
3825
+ var fxValue = typeof functionMap[columnName] === 'function'
3826
+ ? functionMap[columnName](mappedValue)
3827
+ : mappedValue;
3828
+ columnsMap[columnName] = withDelimiter(fxValue);
3829
+ if (fxValue) {
3830
+ columnValueCounts[columnIndex] =
3831
+ (columnValueCounts[columnIndex] || 0) + 1;
3832
+ }
3833
+ return columnsMap;
3834
+ }, {}));
3835
+ };
3836
+ var flattenedRows = flattened.map(processRow);
3837
+ var indicesToRemove = removeEmptyColumns &&
3838
+ __spreadArray([], __read(columnValueCounts), false).map(function (count, index) { return !count && index; })
3839
+ .filter(isNumeric)
3840
+ .reverse();
3841
+ if (indicesToRemove) {
3842
+ var purge = function (row) {
3843
+ return row.filter(function (_, index) { return !indicesToRemove.includes(index); });
3844
+ };
3845
+ flattenedRows = flattenedRows.map(purge);
3846
+ mappedHeaderRow = purge(mappedHeaderRow);
3847
+ }
3848
+ var rows = flattenedRows.map(function (row) { return row.join(columnJoiner); });
3849
+ if (returnTransformedJSON) {
3850
+ return rows.map(function (row) {
3851
+ var columnValues = row.split(columnJoiner);
3852
+ return Object.assign.apply(Object, __spreadArray([{}], __read(columnValues.map(function (v, i) {
3853
+ var _a;
3854
+ return (_a = {}, _a[mappedHeaderRow[i]] = v, _a);
3855
+ })), false));
3850
3856
  });
3851
- return __assign({}, categoryDetails);
3852
- }
3853
-
3854
- function categoryCanContain(_a) {
3855
- var childCategory = _a.childCategory, withDetails = _a.withDetails, category = _a.category;
3856
- var categoryDetails = validateCategory({ category: category });
3857
- var childCategoryDetails = validateCategory({
3858
- category: childCategory,
3859
- });
3860
- var invalidAgeMin = childCategoryDetails.ageMin &&
3861
- ((categoryDetails.ageMin &&
3862
- childCategoryDetails.ageMin < categoryDetails.ageMin) ||
3863
- (categoryDetails.ageMax &&
3864
- childCategoryDetails.ageMin > categoryDetails.ageMax));
3865
- var invalidAgeMax = childCategoryDetails.ageMax &&
3866
- ((categoryDetails.ageMax &&
3867
- childCategoryDetails.ageMax > categoryDetails.ageMax) ||
3868
- (categoryDetails.ageMin &&
3869
- childCategoryDetails.ageMax < categoryDetails.ageMin));
3870
- var invalidAgeMinDate = childCategoryDetails.ageMinDate &&
3871
- categoryDetails.ageMaxDate &&
3872
- new Date(childCategoryDetails.ageMinDate) >
3873
- new Date(categoryDetails.ageMaxDate);
3874
- var invalidAgeMaxDate = childCategoryDetails.ageMaxDate &&
3875
- categoryDetails.ageMinDate &&
3876
- new Date(childCategoryDetails.ageMaxDate) <
3877
- new Date(categoryDetails.ageMinDate);
3878
- var ratingComparison = category.ratingType &&
3879
- childCategory.ratingType &&
3880
- category.ratingType === childCategory.ratingType;
3881
- var invalidRatingRange = ratingComparison &&
3882
- ((category.ratingMin &&
3883
- childCategory.ratingMin &&
3884
- childCategory.ratingMin < category.ratingMin) ||
3885
- (category.ratingMax &&
3886
- childCategory.ratingMax &&
3887
- childCategory.ratingMax > category.ratingMax) ||
3888
- (category.ratingMin &&
3889
- childCategory.ratingMax &&
3890
- childCategory.ratingMax < category.ratingMin) ||
3891
- (category.ratingMax &&
3892
- childCategory.ratingMin &&
3893
- childCategory.ratingMin > category.ratingMax));
3894
- var invalidBallType = category.ballType &&
3895
- childCategory.ballType &&
3896
- category.ballType !== childCategory.ballType;
3897
- var valid = !invalidRatingRange &&
3898
- !invalidAgeMinDate &&
3899
- !invalidAgeMaxDate &&
3900
- !invalidBallType &&
3901
- !invalidAgeMax &&
3902
- !invalidAgeMin;
3903
- var ignoreFalse = true;
3904
- var result = definedAttributes({
3905
- invalidRatingRange: invalidRatingRange,
3906
- invalidAgeMinDate: invalidAgeMinDate,
3907
- invalidAgeMaxDate: invalidAgeMaxDate,
3908
- invalidBallType: invalidBallType,
3909
- invalidAgeMax: invalidAgeMax,
3910
- invalidAgeMin: invalidAgeMin,
3911
- valid: valid,
3912
- }, ignoreFalse);
3913
- if (withDetails) {
3914
- Object.assign(result, { categoryDetails: categoryDetails, childCategoryDetails: childCategoryDetails });
3915
3857
  }
3916
- return result;
3858
+ return includeHeaderRow
3859
+ ? __spreadArray([mappedHeaderRow.map(withDelimiter).join(columnJoiner)], __read(rows), false).join(rowJoiner)
3860
+ : rows.join(rowJoiner);
3861
+ }
3862
+ function flattenJSON(obj, keyJoiner, path) {
3863
+ if (keyJoiner === void 0) { keyJoiner = '.'; }
3864
+ if (path === void 0) { path = []; }
3865
+ return (typeof obj === 'object' &&
3866
+ Object.keys(obj).reduce(function (result, key) {
3867
+ if (typeof obj[key] !== 'object') {
3868
+ result[path.concat(key).join(keyJoiner)] = obj[key];
3869
+ return result;
3870
+ }
3871
+ return Object.assign(result, flattenJSON(obj[key], keyJoiner, path.concat(key)));
3872
+ }, {}));
3917
3873
  }
3918
3874
 
3919
- function mustBeAnArray(value) {
3920
- return "".concat(value, " must be an array");
3875
+ /*
3876
+ based on an answer provided by Jeff Ward on StackOverflow; November 2019
3877
+ https://stackoverflow.com/users/1026023/jeff-ward
3878
+ https://stackoverflow.com/questions/105034/how-to-create-guid-uuid?rq=1
3879
+ */
3880
+ /**
3881
+ * generate a given number of UUIDs
3882
+ *
3883
+ * @param {number} count - number of UUIDs to generate
3884
+ */
3885
+ function UUIDS(count) {
3886
+ if (count === void 0) { count = 1; }
3887
+ return generateRange(0, count).map(UUID);
3888
+ }
3889
+ function UUID() {
3890
+ var lut = [];
3891
+ for (var i = 0; i < 256; i++) {
3892
+ lut[i] = (i < 16 ? '0' : '') + i.toString(16);
3893
+ }
3894
+ var d0 = (Math.random() * 0xffffffff) | 0;
3895
+ var d1 = (Math.random() * 0xffffffff) | 0;
3896
+ var d2 = (Math.random() * 0xffffffff) | 0;
3897
+ var d3 = (Math.random() * 0xffffffff) | 0;
3898
+ // eslint-disable-next-line no-mixed-operators
3899
+ return (lut[d0 & 0xff] +
3900
+ lut[(d0 >> 8) & 0xff] +
3901
+ lut[(d0 >> 16) & 0xff] +
3902
+ lut[(d0 >> 24) & 0xff] +
3903
+ '-' +
3904
+ // eslint-disable-next-line no-mixed-operators
3905
+ lut[d1 & 0xff] +
3906
+ lut[(d1 >> 8) & 0xff] +
3907
+ '-' +
3908
+ lut[((d1 >> 16) & 0x0f) | 0x40] +
3909
+ lut[(d1 >> 24) & 0xff] +
3910
+ '-' +
3911
+ // eslint-disable-next-line no-mixed-operators
3912
+ lut[(d2 & 0x3f) | 0x80] +
3913
+ lut[(d2 >> 8) & 0xff] +
3914
+ '-' +
3915
+ lut[(d2 >> 16) & 0xff] +
3916
+ lut[(d2 >> 24) & 0xff] +
3917
+ // eslint-disable-next-line no-mixed-operators
3918
+ lut[d3 & 0xff] +
3919
+ lut[(d3 >> 8) & 0xff] +
3920
+ lut[(d3 >> 16) & 0xff] +
3921
+ lut[(d3 >> 24) & 0xff]);
3921
3922
  }
3922
3923
 
3923
3924
  function validateTieFormat(params) {