tods-competition-factory 1.7.7 → 1.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -333,7 +333,7 @@ const matchUpFormatCode = {
333
333
  };
334
334
 
335
335
  function factoryVersion() {
336
- return "1.7.7";
336
+ return "1.7.8";
337
337
  }
338
338
 
339
339
  function getObjectTieFormat(obj) {
@@ -1727,119 +1727,6 @@ function handleCaughtError({
1727
1727
  });
1728
1728
  }
1729
1729
 
1730
- function isString(obj) {
1731
- return typeof obj === "string";
1732
- }
1733
- function isObject(obj) {
1734
- return typeof obj === "object";
1735
- }
1736
- const hasAttributeValues = (a) => (o) => Object.keys(a).every((key) => o[key] === a[key]);
1737
- const extractAttributes = (atz) => (o) => !atz || typeof o !== "object" ? void 0 : Array.isArray(atz) && atz.map((a) => ({ [a]: o[a] })) || typeof atz === "object" && Object.keys(atz).map((key) => ({ [key]: o[key] })) || typeof atz === "string" && getAttr(o, atz);
1738
- function getAttr(o, attr) {
1739
- const attrs = attr.split(".");
1740
- for (const a of attrs) {
1741
- o = o?.[a];
1742
- if (!o)
1743
- return;
1744
- }
1745
- return o;
1746
- }
1747
- function definedAttributes(obj, ignoreFalse, ignoreEmptyArrays, shallow) {
1748
- if (typeof obj !== "object" || obj === null)
1749
- return obj;
1750
- const deepCopy = deepCopyEnabled();
1751
- if (!deepCopy?.enabled)
1752
- shallow = true;
1753
- const ignoreValues = ["", void 0, null];
1754
- if (ignoreFalse)
1755
- ignoreValues.push(false);
1756
- const definedKeys = Object.keys(obj).filter(
1757
- (key) => !ignoreValues.includes(obj[key]) && (!ignoreEmptyArrays || (Array.isArray(obj[key]) ? obj[key].length : true))
1758
- );
1759
- return Object.assign(
1760
- {},
1761
- ...definedKeys.map((key) => {
1762
- return Array.isArray(obj[key]) ? {
1763
- [key]: shallow ? obj[key] : obj[key].map((m) => definedAttributes(m))
1764
- } : { [key]: shallow ? obj[key] : definedAttributes(obj[key]) };
1765
- })
1766
- );
1767
- }
1768
- function countKeys(o) {
1769
- if (Array.isArray(o)) {
1770
- return o.length + o.map(countKeys).reduce((a, b) => a + b, 0);
1771
- } else if (typeof o === "object" && o !== null) {
1772
- return Object.keys(o).length + Object.keys(o).map((k) => countKeys(o[k])).reduce((a, b) => a + b, 0);
1773
- }
1774
- return 0;
1775
- }
1776
- function generateHashCode(o) {
1777
- if (o === null || typeof o !== "object")
1778
- return void 0;
1779
- const str = JSON.stringify(o);
1780
- const keyCount = countKeys(o);
1781
- const charSum = str.split("").reduce((a, b) => a + b.charCodeAt(0), 0);
1782
- return [str.length, keyCount, charSum].map((e) => e.toString(36)).join("");
1783
- }
1784
-
1785
- function attributeFilter(params) {
1786
- if (params === null)
1787
- return {};
1788
- const { source, template } = params || {};
1789
- if (!template)
1790
- return source;
1791
- const target = {};
1792
- attributeCopy(source, template, target);
1793
- return target;
1794
- function attributeCopy(valuesObject, templateObject, outputObject) {
1795
- if (!valuesObject || !templateObject)
1796
- return void 0;
1797
- const vKeys = Object.keys(valuesObject);
1798
- const oKeys = Object.keys(templateObject);
1799
- const orMap = Object.assign(
1800
- {},
1801
- ...oKeys.filter((key) => key.indexOf("||")).map((key) => key.split("||").map((or) => ({ [or]: key }))).flat()
1802
- );
1803
- const allKeys = oKeys.concat(...Object.keys(orMap));
1804
- const wildcard = allKeys.includes("*");
1805
- for (const vKey of vKeys) {
1806
- if (allKeys.indexOf(vKey) >= 0 || wildcard) {
1807
- const templateKey = orMap[vKey] || vKey;
1808
- const tobj = templateObject[templateKey] || wildcard;
1809
- const vobj = valuesObject[vKey];
1810
- if (typeof tobj === "object" && typeof vobj !== "function" && !Array.isArray(tobj)) {
1811
- if (Array.isArray(vobj)) {
1812
- const mappedElements = vobj.map((arrayMember) => {
1813
- const target2 = {};
1814
- const result = attributeCopy(arrayMember, tobj, target2);
1815
- return result !== false ? target2 : void 0;
1816
- }).filter(Boolean);
1817
- outputObject[vKey] = mappedElements;
1818
- } else if (vobj) {
1819
- outputObject[vKey] = {};
1820
- attributeCopy(vobj, tobj, outputObject[vKey]);
1821
- }
1822
- } else {
1823
- const value = valuesObject[vKey];
1824
- const exclude = Array.isArray(tobj) && !tobj.includes(value);
1825
- if (exclude)
1826
- return false;
1827
- if (templateObject[vKey] || wildcard && templateObject[vKey] !== false) {
1828
- outputObject[vKey] = value;
1829
- }
1830
- }
1831
- }
1832
- }
1833
- return void 0;
1834
- }
1835
- }
1836
-
1837
- function generateTimeCode(index = 0) {
1838
- const uidate = /* @__PURE__ */ new Date();
1839
- uidate.setHours(uidate.getHours() + index);
1840
- return uidate.getTime().toString(36).slice(-6).toUpperCase();
1841
- }
1842
-
1843
1730
  const validDateString = /^[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1])$/;
1844
1731
  const validTimeString = /^((0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)([.,][0-9]{3})?$/;
1845
1732
  const 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?$/;
@@ -2209,6 +2096,182 @@ function extensionsToAttributes(extensions) {
2209
2096
  }).filter(Boolean);
2210
2097
  }
2211
2098
 
2099
+ function getAccessorValue({ element, accessor }) {
2100
+ if (typeof accessor !== "string")
2101
+ return { values: [] };
2102
+ const targetElement = makeDeepCopy(element);
2103
+ const attributes = accessor.split(".");
2104
+ const values = [];
2105
+ let value;
2106
+ processKeys({ targetElement, attributes });
2107
+ const result = { value };
2108
+ if (values.length)
2109
+ result.values = values;
2110
+ return result;
2111
+ function processKeys({
2112
+ targetElement: targetElement2,
2113
+ attributes: attributes2 = [],
2114
+ significantCharacters
2115
+ }) {
2116
+ for (const [index, attribute] of attributes2.entries()) {
2117
+ if (targetElement2?.[attribute]) {
2118
+ const remainingKeys = attributes2.slice(index + 1);
2119
+ if (!remainingKeys.length) {
2120
+ if (!value)
2121
+ value = targetElement2[attribute];
2122
+ if (!values.includes(targetElement2[attribute])) {
2123
+ values.push(targetElement2[attribute]);
2124
+ }
2125
+ } else if (Array.isArray(targetElement2[attribute])) {
2126
+ const values2 = targetElement2[attribute];
2127
+ values2.forEach(
2128
+ (nestedTarget) => processKeys({
2129
+ targetElement: nestedTarget,
2130
+ attributes: remainingKeys
2131
+ })
2132
+ );
2133
+ } else {
2134
+ targetElement2 = targetElement2[attribute];
2135
+ checkValue({ targetElement: targetElement2, index });
2136
+ }
2137
+ }
2138
+ }
2139
+ function checkValue({ targetElement: targetElement3, index }) {
2140
+ if (targetElement3 && index === attributes2.length - 1 && ["string", "number"].includes(typeof targetElement3)) {
2141
+ const extractedValue = significantCharacters ? targetElement3.slice(0, significantCharacters) : targetElement3;
2142
+ if (value) {
2143
+ if (!values.includes(extractedValue)) {
2144
+ values.push(extractedValue);
2145
+ }
2146
+ } else {
2147
+ value = extractedValue;
2148
+ values.push(extractedValue);
2149
+ }
2150
+ }
2151
+ }
2152
+ }
2153
+ }
2154
+
2155
+ function isString(obj) {
2156
+ return typeof obj === "string";
2157
+ }
2158
+ function isObject(obj) {
2159
+ return typeof obj === "object";
2160
+ }
2161
+ function createMap(objectArray, attribute) {
2162
+ if (!Array.isArray(objectArray))
2163
+ return {};
2164
+ return Object.assign(
2165
+ {},
2166
+ ...(objectArray ?? []).filter(isObject).map((obj) => {
2167
+ return obj[attribute] && {
2168
+ [obj[attribute]]: obj
2169
+ };
2170
+ }).filter(Boolean)
2171
+ );
2172
+ }
2173
+ const hasAttributeValues = (a) => (o) => Object.keys(a).every((key) => o[key] === a[key]);
2174
+ const extractAttributes = (accessor) => (element) => !accessor || typeof element !== "object" ? void 0 : Array.isArray(accessor) && accessor.map((a) => ({
2175
+ [a]: getAccessorValue({ element, accessor: a })?.value
2176
+ })) || typeof accessor === "object" && Object.keys(accessor).map((key) => ({
2177
+ [key]: getAccessorValue({ element, accessor: key })?.value
2178
+ })) || (typeof accessor === "string" && getAccessorValue({ element, accessor }))?.value;
2179
+ function definedAttributes(obj, ignoreFalse, ignoreEmptyArrays, shallow) {
2180
+ if (typeof obj !== "object" || obj === null)
2181
+ return obj;
2182
+ const deepCopy = deepCopyEnabled();
2183
+ if (!deepCopy?.enabled)
2184
+ shallow = true;
2185
+ const ignoreValues = ["", void 0, null];
2186
+ if (ignoreFalse)
2187
+ ignoreValues.push(false);
2188
+ const definedKeys = Object.keys(obj).filter(
2189
+ (key) => !ignoreValues.includes(obj[key]) && (!ignoreEmptyArrays || (Array.isArray(obj[key]) ? obj[key].length : true))
2190
+ );
2191
+ return Object.assign(
2192
+ {},
2193
+ ...definedKeys.map((key) => {
2194
+ return Array.isArray(obj[key]) ? {
2195
+ [key]: shallow ? obj[key] : obj[key].map((m) => definedAttributes(m))
2196
+ } : { [key]: shallow ? obj[key] : definedAttributes(obj[key]) };
2197
+ })
2198
+ );
2199
+ }
2200
+ function countKeys(o) {
2201
+ if (Array.isArray(o)) {
2202
+ return o.length + o.map(countKeys).reduce((a, b) => a + b, 0);
2203
+ } else if (typeof o === "object" && o !== null) {
2204
+ return Object.keys(o).length + Object.keys(o).map((k) => countKeys(o[k])).reduce((a, b) => a + b, 0);
2205
+ }
2206
+ return 0;
2207
+ }
2208
+ function generateHashCode(o) {
2209
+ if (o === null || typeof o !== "object")
2210
+ return void 0;
2211
+ const str = JSON.stringify(o);
2212
+ const keyCount = countKeys(o);
2213
+ const charSum = str.split("").reduce((a, b) => a + b.charCodeAt(0), 0);
2214
+ return [str.length, keyCount, charSum].map((e) => e.toString(36)).join("");
2215
+ }
2216
+
2217
+ function attributeFilter(params) {
2218
+ if (params === null)
2219
+ return {};
2220
+ const { source, template } = params || {};
2221
+ if (!template)
2222
+ return source;
2223
+ const target = {};
2224
+ attributeCopy(source, template, target);
2225
+ return target;
2226
+ function attributeCopy(valuesObject, templateObject, outputObject) {
2227
+ if (!valuesObject || !templateObject)
2228
+ return void 0;
2229
+ const vKeys = Object.keys(valuesObject);
2230
+ const oKeys = Object.keys(templateObject);
2231
+ const orMap = Object.assign(
2232
+ {},
2233
+ ...oKeys.filter((key) => key.indexOf("||")).map((key) => key.split("||").map((or) => ({ [or]: key }))).flat()
2234
+ );
2235
+ const allKeys = oKeys.concat(...Object.keys(orMap));
2236
+ const wildcard = allKeys.includes("*");
2237
+ for (const vKey of vKeys) {
2238
+ if (allKeys.indexOf(vKey) >= 0 || wildcard) {
2239
+ const templateKey = orMap[vKey] || vKey;
2240
+ const tobj = templateObject[templateKey] || wildcard;
2241
+ const vobj = valuesObject[vKey];
2242
+ if (typeof tobj === "object" && typeof vobj !== "function" && !Array.isArray(tobj)) {
2243
+ if (Array.isArray(vobj)) {
2244
+ const mappedElements = vobj.map((arrayMember) => {
2245
+ const target2 = {};
2246
+ const result = attributeCopy(arrayMember, tobj, target2);
2247
+ return result !== false ? target2 : void 0;
2248
+ }).filter(Boolean);
2249
+ outputObject[vKey] = mappedElements;
2250
+ } else if (vobj) {
2251
+ outputObject[vKey] = {};
2252
+ attributeCopy(vobj, tobj, outputObject[vKey]);
2253
+ }
2254
+ } else {
2255
+ const value = valuesObject[vKey];
2256
+ const exclude = Array.isArray(tobj) && !tobj.includes(value);
2257
+ if (exclude)
2258
+ return false;
2259
+ if (templateObject[vKey] || wildcard && templateObject[vKey] !== false) {
2260
+ outputObject[vKey] = value;
2261
+ }
2262
+ }
2263
+ }
2264
+ }
2265
+ return void 0;
2266
+ }
2267
+ }
2268
+
2269
+ function generateTimeCode(index = 0) {
2270
+ const uidate = /* @__PURE__ */ new Date();
2271
+ uidate.setHours(uidate.getHours() + index);
2272
+ return uidate.getTime().toString(36).slice(-6).toUpperCase();
2273
+ }
2274
+
2212
2275
  function numericSort(a, b) {
2213
2276
  return a - b;
2214
2277
  }
@@ -7605,7 +7668,7 @@ function isAdHoc({ drawDefinition, structure }) {
7605
7668
  const hasDrawPosition = matchUps?.find(
7606
7669
  (matchUp) => matchUp?.drawPositions?.length
7607
7670
  );
7608
- return !structure?.structures && !(drawDefinition?.drawType && drawDefinition.drawType !== AD_HOC) && !hasRoundPosition && !hasDrawPosition;
7671
+ return !structure?.structures && structure?.stage !== VOLUNTARY_CONSOLATION && !(drawDefinition?.drawType && drawDefinition.drawType !== AD_HOC) && !hasRoundPosition && !hasDrawPosition;
7609
7672
  }
7610
7673
 
7611
7674
  const POLICY_ROUND_NAMING_DEFAULT = {
@@ -26141,56 +26204,6 @@ function getEventPublishStatuses({ event }) {
26141
26204
  return void 0;
26142
26205
  }
26143
26206
 
26144
- function getAccessorValue({ element, accessor }) {
26145
- if (typeof accessor !== "string")
26146
- return { values: [] };
26147
- const targetElement = makeDeepCopy(element);
26148
- const attributes = accessor.split(".");
26149
- const values = [];
26150
- let value;
26151
- processKeys({ targetElement, attributes });
26152
- const result = { value };
26153
- if (values.length)
26154
- result.values = values;
26155
- return result;
26156
- function processKeys({
26157
- targetElement: targetElement2,
26158
- attributes: attributes2 = [],
26159
- significantCharacters
26160
- }) {
26161
- for (const [index, attribute] of attributes2.entries()) {
26162
- if (targetElement2?.[attribute]) {
26163
- if (Array.isArray(targetElement2[attribute])) {
26164
- const values2 = targetElement2[attribute];
26165
- const remainingKeys = attributes2.slice(index);
26166
- values2.forEach(
26167
- (nestedTarget) => processKeys({
26168
- targetElement: nestedTarget,
26169
- attributes: remainingKeys
26170
- })
26171
- );
26172
- } else {
26173
- targetElement2 = targetElement2[attribute];
26174
- checkValue({ targetElement: targetElement2, index });
26175
- }
26176
- }
26177
- }
26178
- function checkValue({ targetElement: targetElement3, index }) {
26179
- if (targetElement3 && index === attributes2.length - 1 && ["string", "number"].includes(typeof targetElement3)) {
26180
- const extractedValue = significantCharacters ? targetElement3.slice(0, significantCharacters) : targetElement3;
26181
- if (value) {
26182
- if (!values.includes(extractedValue)) {
26183
- values.push(extractedValue);
26184
- }
26185
- } else {
26186
- value = extractedValue;
26187
- values.push(extractedValue);
26188
- }
26189
- }
26190
- }
26191
- }
26192
- }
26193
-
26194
26207
  function participantScaleItem({
26195
26208
  requireTimeStamp,
26196
26209
  scaleAttributes,
@@ -50604,6 +50617,93 @@ function modifyParticipantOtherName({
50604
50617
  return { ...SUCCESS };
50605
50618
  }
50606
50619
 
50620
+ function formatPersonName({
50621
+ personFormat,
50622
+ person
50623
+ }) {
50624
+ const alpha = (str) => str.replace(/\W/g, "");
50625
+ const allLowerCase = (str) => /^[a-z]*$/.test(alpha(str));
50626
+ const allUpperCase = (str) => /^[A-Z]*$/.test(alpha(str));
50627
+ const lastUpperCase = (str) => /^[LAST]{4}/.test(alpha(str));
50628
+ const lastFirst = (str) => str.toLowerCase().indexOf("l") < str.toLowerCase().indexOf("f");
50629
+ const commaSeparated = (str) => str.indexOf(",") >= 0;
50630
+ const firstInital = (str) => str.toLowerCase().indexOf("f.") >= 0;
50631
+ const lastNameOnly = (str) => str.toLowerCase().indexOf("f") < 0;
50632
+ const hasSpacing = (str) => str.indexOf(" ") > 0;
50633
+ if (!person)
50634
+ return;
50635
+ const spacer = hasSpacing(personFormat) ? " " : "";
50636
+ const capitalizeFirst = (str) => str.split(" ").map(
50637
+ (name) => name.split("").map((c, i) => i ? c.toLowerCase() : c.toUpperCase()).join("")
50638
+ ).join(" ");
50639
+ let firstName = capitalizeFirst(person?.standardGivenName ?? "");
50640
+ let lastName = capitalizeFirst(person?.standardFamilyName ?? "");
50641
+ if (!personFormat)
50642
+ return `${firstName}${spacer}${lastName}`;
50643
+ if (firstInital(personFormat) && !commaSeparated(personFormat) && !lastFirst(personFormat)) {
50644
+ firstName = `${firstName[0]}.`;
50645
+ }
50646
+ if (allLowerCase(personFormat)) {
50647
+ firstName = firstName.toLowerCase();
50648
+ lastName = lastName.toLowerCase();
50649
+ } else if (allUpperCase(personFormat)) {
50650
+ firstName = firstName.toUpperCase();
50651
+ lastName = lastName.toUpperCase();
50652
+ } else if (lastUpperCase(personFormat)) {
50653
+ lastName = lastName.toUpperCase();
50654
+ }
50655
+ let participantName = `${firstName}${spacer}${lastName}`;
50656
+ if (lastNameOnly(personFormat)) {
50657
+ participantName = lastName;
50658
+ } else if (lastFirst(personFormat)) {
50659
+ if (commaSeparated(personFormat)) {
50660
+ participantName = `${lastName},${spacer}${firstName}`;
50661
+ } else {
50662
+ participantName = `${lastName}${spacer}${firstName}`;
50663
+ }
50664
+ }
50665
+ return participantName;
50666
+ }
50667
+
50668
+ function formatParticipantName({
50669
+ participantMap,
50670
+ participant,
50671
+ formats
50672
+ }) {
50673
+ const { participantType, individualParticipantIds, person } = participant;
50674
+ const format = participantType && formats[participantType];
50675
+ if (participantType === TEAM_PARTICIPANT)
50676
+ return;
50677
+ if (format) {
50678
+ const { personFormat, doublesJoiner } = format;
50679
+ if (participantType === INDIVIDUAL) {
50680
+ participant.participantName = formatPersonName({ person, personFormat });
50681
+ }
50682
+ if (participantType === PAIR) {
50683
+ participant.participantName = individualParticipantIds?.map((id) => {
50684
+ const person2 = participantMap[id]?.person;
50685
+ return formatPersonName({ person: person2, personFormat });
50686
+ }).filter(Boolean).join(doublesJoiner ?? "/");
50687
+ }
50688
+ }
50689
+ }
50690
+
50691
+ function regenerateParticipantNames({
50692
+ tournamentRecord,
50693
+ formats
50694
+ }) {
50695
+ if (!tournamentRecord)
50696
+ return { error: MISSING_TOURNAMENT_RECORD };
50697
+ if (!isObject(formats))
50698
+ return { error: MISSING_VALUE };
50699
+ const participants = tournamentRecord.participants ?? [];
50700
+ const participantMap = createMap(participants, "participantId");
50701
+ for (const participant of participants) {
50702
+ formatParticipantName({ participant, participantMap, formats });
50703
+ }
50704
+ return { ...SUCCESS };
50705
+ }
50706
+
50607
50707
  function getTournamentPersons({ tournamentRecord, participantFilters }) {
50608
50708
  if (!tournamentRecord)
50609
50709
  return { error: MISSING_TOURNAMENT_RECORD };
@@ -51097,6 +51197,7 @@ const participantGovernor = {
51097
51197
  removeParticipantIdsFromAllTeams,
51098
51198
  getParticipantMembership,
51099
51199
  generateTeamsFromParticipantAttribute,
51200
+ regenerateParticipantNames,
51100
51201
  getParticipantIdFinishingPositions,
51101
51202
  modifyParticipant,
51102
51203
  modifyParticipantName,
@@ -60402,7 +60503,7 @@ function generatePersons(params) {
60402
60503
  return false;
60403
60504
  if (typeof person.lastName !== "string")
60404
60505
  return false;
60405
- if (![MALE, FEMALE].includes(person.sex))
60506
+ if (person.sex && ![MALE, FEMALE].includes(person.sex))
60406
60507
  return false;
60407
60508
  if (person.nationalityCode && (typeof person.nationalityCode !== "string" || person.nationalityCode.length > 3 || !countries.find(
60408
60509
  ({ iso, ioc }) => [iso, ioc].includes(person.nationalityCode)
@@ -60418,7 +60519,7 @@ function generatePersons(params) {
60418
60519
  return { error: INVALID_VALUES };
60419
60520
  }
60420
60521
  }
60421
- const shuffledPersons = shuffleArray(validPersonData);
60522
+ const shuffledPersons = personData ? validPersonData : shuffleArray(validPersonData);
60422
60523
  if (shuffledPersons.length < count) {
60423
60524
  const {
60424
60525
  maleFirstNames,