tods-competition-factory 2.2.39 → 2.2.41

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.
@@ -4626,11 +4626,11 @@ declare function deleteFlightProfileAndFlightDraws({ autoPublish, tournamentReco
4626
4626
  event: any;
4627
4627
  force: any;
4628
4628
  }): {
4629
+ error: any;
4630
+ } | {
4629
4631
  success?: boolean;
4630
4632
  error?: ErrorType;
4631
4633
  info?: any;
4632
- } | {
4633
- error: any;
4634
4634
  };
4635
4635
 
4636
4636
  type ModifyEventMatchUpFormatTimingArgs = {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.2.39';
6
+ return '2.2.41';
7
7
  }
8
8
 
9
9
  const SINGLES_MATCHUP = 'SINGLES';
@@ -1992,8 +1992,15 @@ function getNumber$1(formatstring) {
1992
1992
  }
1993
1993
  function timedSetFormat(matchUpFormatObject) {
1994
1994
  let value = `T${matchUpFormatObject.minutes}`;
1995
- if (matchUpFormatObject.based)
1996
- value += matchUpFormatObject.based;
1995
+ if (matchUpFormatObject.based === 'A') {
1996
+ value += 'A';
1997
+ }
1998
+ else if (matchUpFormatObject.based === 'P') {
1999
+ value += 'P';
2000
+ }
2001
+ if (matchUpFormatObject.tiebreakFormat?.tiebreakTo) {
2002
+ value += `/TB${matchUpFormatObject.tiebreakFormat.tiebreakTo}`;
2003
+ }
1997
2004
  if (matchUpFormatObject.modifier)
1998
2005
  value += `@${matchUpFormatObject.modifier}`;
1999
2006
  return value;
@@ -2103,44 +2110,56 @@ function setsMatch(formatstring) {
2103
2110
  return result;
2104
2111
  }
2105
2112
  function parseSetFormat(formatstring) {
2106
- if (formatstring?.[1] === ':') {
2107
- const parts = formatstring.split(':');
2108
- const setType = setTypes$1[parts[0]];
2109
- const setFormatString = parts[1];
2110
- if (setType && setFormatString) {
2111
- const isTiebreakSet = setFormatString.startsWith('TB');
2112
- if (isTiebreakSet) {
2113
- const tiebreakSet = parseTiebreakFormat(setFormatString);
2114
- if (tiebreakSet === false)
2115
- return false;
2116
- return typeof tiebreakSet === 'object' ? { tiebreakSet } : undefined;
2117
- }
2118
- const timedSet = setFormatString.startsWith('T');
2119
- if (timedSet)
2120
- return parseTimedSet(setFormatString);
2121
- const parts = formatstring.match(/^[FS]:(\d+)([A-Za-z]*)/);
2122
- const NoAD = (parts && isNoAD(parts[2])) || false;
2123
- const validNoAD = !parts?.[2] || NoAD;
2124
- const setTo = parts ? getNumber(parts[1]) : undefined;
2125
- const tiebreakAtValue = parseTiebreakAt(setFormatString);
2126
- const validTiebreakAt = tiebreakAtValue !== false;
2127
- const tiebreakAt = (validTiebreakAt && tiebreakAtValue) || setTo;
2128
- const tiebreakFormat = parseTiebreakFormat(setFormatString.split('/')[1]);
2129
- const validTiebreak = tiebreakFormat !== false;
2130
- const result = { setTo };
2131
- if (NoAD)
2132
- result.NoAD = true;
2133
- if (tiebreakFormat) {
2134
- result.tiebreakFormat = tiebreakFormat;
2135
- result.tiebreakAt = tiebreakAt;
2136
- }
2137
- else {
2138
- result.noTiebreak = true;
2139
- }
2140
- return (setTo && validNoAD && validTiebreak && validTiebreakAt && result) || false;
2141
- }
2113
+ if (formatstring?.[1] !== ':')
2114
+ return undefined;
2115
+ const parts = formatstring.split(':');
2116
+ const setType = setTypes$1[parts[0]];
2117
+ const setFormatString = parts[1];
2118
+ if (!setType || !setFormatString)
2119
+ return undefined;
2120
+ return parseSetFormatString(formatstring, setFormatString);
2121
+ }
2122
+ function parseSetFormatString(formatstring, setFormatString) {
2123
+ if (setFormatString.startsWith('TB')) {
2124
+ return parseTiebreakSetFormat(setFormatString);
2142
2125
  }
2143
- return undefined;
2126
+ if (setFormatString.startsWith('T')) {
2127
+ return parseTimedSet(setFormatString);
2128
+ }
2129
+ return parseStandardSetFormat(formatstring, setFormatString);
2130
+ }
2131
+ function parseTiebreakSetFormat(setFormatString) {
2132
+ const tiebreakSet = parseTiebreakFormat(setFormatString);
2133
+ if (tiebreakSet === false)
2134
+ return false;
2135
+ return typeof tiebreakSet === 'object' ? { tiebreakSet } : undefined;
2136
+ }
2137
+ function parseStandardSetFormat(formatstring, setFormatString) {
2138
+ const parts = /^[FS]:(\d+)([A-Za-z]*)/.exec(formatstring);
2139
+ const NoAD = (parts && isNoAD(parts[2])) || false;
2140
+ const validNoAD = !parts?.[2] || NoAD;
2141
+ const setTo = parts ? getNumber(parts[1]) : undefined;
2142
+ const tiebreakAtValue = parseTiebreakAt(setFormatString);
2143
+ const validTiebreakAt = tiebreakAtValue !== false;
2144
+ const tiebreakAt = (validTiebreakAt && tiebreakAtValue) || setTo;
2145
+ const tiebreakFormat = parseTiebreakFormat(setFormatString.split('/')[1]);
2146
+ const validTiebreak = tiebreakFormat !== false;
2147
+ if (!setTo || !validNoAD || !validTiebreak || !validTiebreakAt)
2148
+ return false;
2149
+ return buildSetFormatResult(setTo, NoAD, tiebreakFormat, tiebreakAt);
2150
+ }
2151
+ function buildSetFormatResult(setTo, NoAD, tiebreakFormat, tiebreakAt) {
2152
+ const result = { setTo };
2153
+ if (NoAD)
2154
+ result.NoAD = true;
2155
+ if (tiebreakFormat) {
2156
+ result.tiebreakFormat = tiebreakFormat;
2157
+ result.tiebreakAt = tiebreakAt;
2158
+ }
2159
+ else {
2160
+ result.noTiebreak = true;
2161
+ }
2162
+ return result;
2144
2163
  }
2145
2164
  function parseTiebreakAt(setFormatString, expectNumber = true) {
2146
2165
  const tiebreakAtValue = setFormatString?.indexOf('@') > 0 && setFormatString.split('@');
@@ -2151,59 +2170,73 @@ function parseTiebreakAt(setFormatString, expectNumber = true) {
2151
2170
  return undefined;
2152
2171
  }
2153
2172
  function parseTiebreakFormat(formatstring) {
2154
- if (formatstring) {
2155
- if (formatstring.startsWith('TB')) {
2156
- const modifier = parseTiebreakAt(formatstring, false);
2157
- const parts = formatstring.match(/^TB(\d+)([A-Za-z]*)/);
2158
- const tiebreakToString = parts?.[1];
2159
- const NoAD = parts && isNoAD(parts[2]);
2160
- const validNoAD = !parts?.[2] || NoAD;
2161
- const tiebreakTo = getNumber(tiebreakToString);
2162
- if (tiebreakTo && validNoAD) {
2163
- const result = { tiebreakTo };
2164
- if (modifier && typeof modifier === 'string' && !isConvertableInteger(modifier)) {
2165
- result.modifier = modifier;
2166
- }
2167
- if (NoAD)
2168
- result.NoAD = true;
2169
- return result;
2170
- }
2171
- else {
2172
- return false;
2173
- }
2174
- }
2175
- else {
2176
- return false;
2177
- }
2173
+ if (!formatstring)
2174
+ return undefined;
2175
+ if (!formatstring.startsWith('TB'))
2176
+ return false;
2177
+ return parseTiebreakDetails(formatstring);
2178
+ }
2179
+ function parseTiebreakDetails(formatstring) {
2180
+ const modifier = parseTiebreakAt(formatstring, false);
2181
+ const parts = /^TB(\d+)([A-Za-z]*)/.exec(formatstring);
2182
+ const tiebreakToString = parts?.[1];
2183
+ const NoAD = parts && isNoAD(parts[2]);
2184
+ const validNoAD = !parts?.[2] || NoAD;
2185
+ const tiebreakTo = getNumber(tiebreakToString);
2186
+ if (!tiebreakTo || !validNoAD)
2187
+ return false;
2188
+ const result = { tiebreakTo };
2189
+ if (modifier && typeof modifier === 'string' && !isConvertableInteger(modifier)) {
2190
+ result.modifier = modifier;
2178
2191
  }
2179
- return undefined;
2192
+ if (NoAD)
2193
+ result.NoAD = true;
2194
+ return result;
2180
2195
  }
2181
2196
  function parseTimedSet(formatstring) {
2182
2197
  const timestring = formatstring.slice(1);
2183
- const parts = timestring.match(/^(\d+)(@?[A-Za-z]*)/);
2198
+ const parts = /^(\d+)([PGA])?(?:\/TB(\d+))?(@?[A-Za-z]*)?/.exec(timestring);
2184
2199
  const minutes = getNumber(parts?.[1]);
2185
2200
  if (!minutes)
2186
2201
  return;
2187
2202
  const setFormat = { timed: true, minutes };
2188
- const based = parts?.[2];
2189
- const validModifier = [undefined, 'P', 'G'].includes(based);
2190
- if (based && !validModifier) {
2191
- const modifier = timestring.match(/^(\d+)(@)([A-Za-z]+)$/)?.[3];
2203
+ const scoringMethod = parts?.[2];
2204
+ if (scoringMethod === 'A') {
2205
+ setFormat.based = 'A';
2206
+ }
2207
+ else if (scoringMethod === 'P') {
2208
+ setFormat.based = 'P';
2209
+ }
2210
+ else if (scoringMethod === 'G') {
2211
+ setFormat.based = 'G';
2212
+ }
2213
+ const setTiebreakTo = parts?.[3];
2214
+ if (setTiebreakTo) {
2215
+ const tiebreakToNumber = getNumber(setTiebreakTo);
2216
+ if (tiebreakToNumber) {
2217
+ setFormat.tiebreakFormat = { tiebreakTo: tiebreakToNumber };
2218
+ }
2219
+ }
2220
+ const legacyModifier = parts?.[4];
2221
+ const validModifier = [undefined, 'P', 'G', ''].includes(legacyModifier);
2222
+ if (legacyModifier && !validModifier) {
2223
+ const modifier = /^(\d+)([PGA])?(?:\/TB\d+)?(@)([A-Za-z]+)$/.exec(timestring)?.[4];
2192
2224
  if (modifier) {
2193
2225
  setFormat.modifier = modifier;
2194
2226
  return setFormat;
2195
2227
  }
2196
2228
  return;
2197
2229
  }
2198
- if (based)
2199
- setFormat.based = parts[2];
2230
+ if (legacyModifier)
2231
+ setFormat.based = legacyModifier;
2200
2232
  return setFormat;
2201
2233
  }
2202
2234
  function isNoAD(formatstring) {
2203
- return formatstring && formatstring.indexOf(NOAD) >= 0;
2235
+ return formatstring?.includes(NOAD);
2204
2236
  }
2205
2237
  function getNumber(formatstring) {
2206
- return !isNaN(Number(formatstring)) ? Number(formatstring) : 0;
2238
+ const num = Number(formatstring);
2239
+ return Number.isNaN(num) ? 0 : num;
2207
2240
  }
2208
2241
 
2209
2242
  function isValidMatchUpFormat({ matchUpFormat }) {
@@ -32333,6 +32366,24 @@ function validateSetScore(set, matchUpFormat, isDecidingSet, allowIncomplete) {
32333
32366
  const setFormat = isDecidingSet && parsed.finalSetFormat ? parsed.finalSetFormat : parsed.setFormat;
32334
32367
  if (!setFormat)
32335
32368
  return { isValid: true };
32369
+ if (setFormat.timed) {
32370
+ if (!allowIncomplete) {
32371
+ const side1Score = set.side1Score ?? 0;
32372
+ const side2Score = set.side2Score ?? 0;
32373
+ if (side1Score === 0 && side2Score === 0) {
32374
+ return { isValid: false, error: 'Timed set requires at least one side to have scored' };
32375
+ }
32376
+ if (setFormat.based === 'P') {
32377
+ if (side1Score === side2Score && side1Score > 0 && setFormat.tiebreakFormat) {
32378
+ const hasTiebreak = set.side1TiebreakScore !== undefined || set.side2TiebreakScore !== undefined;
32379
+ if (!hasTiebreak) {
32380
+ return { isValid: false, error: 'Tied timed set requires tiebreak' };
32381
+ }
32382
+ }
32383
+ }
32384
+ }
32385
+ return { isValid: true };
32386
+ }
32336
32387
  const { setTo, tiebreakAt, tiebreakFormat, tiebreakSet } = setFormat;
32337
32388
  const tiebreakSetTo = tiebreakSet?.tiebreakTo;
32338
32389
  const isTiebreakOnlyFormat = !!tiebreakSetTo && !setTo;
@@ -32429,12 +32480,39 @@ function analyzeScore({ existingMatchUpStatus, matchUpFormat, matchUpStatus, win
32429
32480
  const excessiveSetScore = !setValues.noTiebreak && maxSetScore > setValues.setTo + 1;
32430
32481
  return !excessiveSetScore;
32431
32482
  });
32432
- const calculatedWinningSide = ((!matchUpFormat || maxSetsCount === setsToWin) &&
32433
- maxSetsInstances === 1 &&
32434
- setsWinCounts.indexOf(maxSetsCount) + 1) ||
32435
- undefined;
32483
+ const isAggregateScoring = matchUpScoringFormat?.setFormat?.based === 'A' || matchUpScoringFormat?.finalSetFormat?.based === 'A';
32484
+ let calculatedWinningSide;
32485
+ if (isAggregateScoring && sets.length > 0) {
32486
+ const aggregateTotals = sets.reduce((totals, set) => {
32487
+ if (set.side1Score !== undefined || set.side2Score !== undefined) {
32488
+ totals[0] += set.side1Score ?? 0;
32489
+ totals[1] += set.side2Score ?? 0;
32490
+ }
32491
+ return totals;
32492
+ }, [0, 0]);
32493
+ if (aggregateTotals[0] > aggregateTotals[1]) {
32494
+ calculatedWinningSide = 1;
32495
+ }
32496
+ else if (aggregateTotals[1] > aggregateTotals[0]) {
32497
+ calculatedWinningSide = 2;
32498
+ }
32499
+ else {
32500
+ const tiebreakSet = sets.find((set) => set.side1TiebreakScore !== undefined || set.side2TiebreakScore !== undefined);
32501
+ if (tiebreakSet) {
32502
+ calculatedWinningSide = tiebreakSet.winningSide;
32503
+ }
32504
+ }
32505
+ }
32506
+ else {
32507
+ calculatedWinningSide =
32508
+ ((!matchUpFormat || maxSetsCount === setsToWin) &&
32509
+ maxSetsInstances === 1 &&
32510
+ setsWinCounts.indexOf(maxSetsCount) + 1) ||
32511
+ undefined;
32512
+ }
32436
32513
  const valid = !!(validSets &&
32437
- ((winningSide && winningSideSetsCount > losingSideSetsCount && winningSide === calculatedWinningSide) ||
32514
+ ((winningSide && isAggregateScoring && winningSide === calculatedWinningSide) ||
32515
+ (winningSide && !isAggregateScoring && winningSideSetsCount > losingSideSetsCount && winningSide === calculatedWinningSide) ||
32438
32516
  (winningSide && irregularEnding) ||
32439
32517
  (!winningSide &&
32440
32518
  !calculatedWinningSide &&
@@ -47177,43 +47255,79 @@ function generateOutcomeFromScoreString(params) {
47177
47255
  const isBracketNotation = scoreString?.trim().startsWith('[');
47178
47256
  let inferredWinningSide = winningSide;
47179
47257
  if (!inferredWinningSide && matchUpFormat && neutralParsedSets) {
47180
- const setsWon = { side1: 0, side2: 0 };
47181
- neutralParsedSets.forEach((set) => {
47182
- if (set.winningSide === 1)
47183
- setsWon.side1++;
47184
- else if (set.winningSide === 2)
47185
- setsWon.side2++;
47186
- });
47187
- if (setsWon.side1 > setsWon.side2)
47188
- inferredWinningSide = 1;
47189
- else if (setsWon.side2 > setsWon.side1)
47190
- inferredWinningSide = 2;
47258
+ const parsedFormat = parse(matchUpFormat);
47259
+ const isAggregateScoring = parsedFormat?.setFormat?.based === 'A' || parsedFormat?.finalSetFormat?.based === 'A';
47260
+ if (isAggregateScoring) {
47261
+ const aggregateTotals = neutralParsedSets.reduce((totals, set) => {
47262
+ if (set.side1Score !== undefined || set.side2Score !== undefined) {
47263
+ totals.side1 += set.side1Score ?? 0;
47264
+ totals.side2 += set.side2Score ?? 0;
47265
+ }
47266
+ return totals;
47267
+ }, { side1: 0, side2: 0 });
47268
+ if (aggregateTotals.side1 > aggregateTotals.side2)
47269
+ inferredWinningSide = 1;
47270
+ else if (aggregateTotals.side2 > aggregateTotals.side1)
47271
+ inferredWinningSide = 2;
47272
+ else {
47273
+ const tiebreakSet = neutralParsedSets.find((set) => set.side1TiebreakScore !== undefined || set.side2TiebreakScore !== undefined);
47274
+ if (tiebreakSet)
47275
+ inferredWinningSide = tiebreakSet.winningSide;
47276
+ }
47277
+ }
47278
+ else {
47279
+ const setsWon = { side1: 0, side2: 0 };
47280
+ neutralParsedSets.forEach((set) => {
47281
+ if (set.winningSide === 1)
47282
+ setsWon.side1++;
47283
+ else if (set.winningSide === 2)
47284
+ setsWon.side2++;
47285
+ });
47286
+ if (setsWon.side1 > setsWon.side2)
47287
+ inferredWinningSide = 1;
47288
+ else if (setsWon.side2 > setsWon.side1)
47289
+ inferredWinningSide = 2;
47290
+ }
47191
47291
  }
47192
47292
  const score = {};
47193
- const winningScoreString = generateScoreString({
47194
- sets: neutralParsedSets,
47195
- matchUpFormat,
47196
- setTBlast,
47197
- });
47198
- const losingScoreString = generateScoreString({
47199
- sets: neutralParsedSets,
47200
- reversed: true,
47201
- matchUpFormat,
47202
- setTBlast,
47203
- });
47204
- if (isBracketNotation) {
47205
- score.scoreStringSide1 = winningScoreString;
47206
- score.scoreStringSide2 = losingScoreString;
47207
- }
47208
- else if (inferredWinningSide === 2) {
47209
- score.scoreStringSide1 = losingScoreString;
47210
- score.scoreStringSide2 = winningScoreString;
47293
+ const parsedFormat = parse(matchUpFormat);
47294
+ const isAggregateScoring = parsedFormat?.setFormat?.based === 'A' || parsedFormat?.finalSetFormat?.based === 'A';
47295
+ if (isBracketNotation || isAggregateScoring) {
47296
+ score.sets = parseScoreString({ scoreString, matchUpFormat });
47297
+ score.scoreStringSide1 = generateScoreString({
47298
+ sets: score.sets,
47299
+ matchUpFormat,
47300
+ setTBlast,
47301
+ });
47302
+ score.scoreStringSide2 = generateScoreString({
47303
+ sets: score.sets,
47304
+ reversed: true,
47305
+ matchUpFormat,
47306
+ setTBlast,
47307
+ });
47211
47308
  }
47212
47309
  else {
47213
- score.scoreStringSide1 = winningScoreString;
47214
- score.scoreStringSide2 = losingScoreString;
47310
+ const winningScoreString = generateScoreString({
47311
+ sets: neutralParsedSets,
47312
+ matchUpFormat,
47313
+ setTBlast,
47314
+ });
47315
+ const losingScoreString = generateScoreString({
47316
+ sets: neutralParsedSets,
47317
+ reversed: true,
47318
+ matchUpFormat,
47319
+ setTBlast,
47320
+ });
47321
+ if (inferredWinningSide === 2) {
47322
+ score.scoreStringSide1 = losingScoreString;
47323
+ score.scoreStringSide2 = winningScoreString;
47324
+ }
47325
+ else {
47326
+ score.scoreStringSide1 = winningScoreString;
47327
+ score.scoreStringSide2 = losingScoreString;
47328
+ }
47329
+ score.sets = parseScoreString({ scoreString: score.scoreStringSide1, matchUpFormat });
47215
47330
  }
47216
- score.sets = parseScoreString({ scoreString: score.scoreStringSide1, matchUpFormat });
47217
47331
  return definedAttributes({
47218
47332
  outcome: {
47219
47333
  matchUpStatus,