tods-competition-factory 2.2.37 → 2.2.39

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.2.37';
6
+ return '2.2.39';
7
7
  }
8
8
 
9
9
  const SINGLES_MATCHUP = 'SINGLES';
@@ -2005,7 +2005,8 @@ function getSetFormat(matchUpFormatObject, preserveRedundant) {
2005
2005
  if (matchUpFormatObject.setFormat?.timed && matchUpFormatObject.simplified && setLimit === 1) {
2006
2006
  return timedSetFormat(matchUpFormatObject.setFormat);
2007
2007
  }
2008
- const setLimitCode = (setLimit && `${SET}${setLimit}`) || '';
2008
+ const exactlySuffix = exactly && exactly !== 1 ? 'X' : '';
2009
+ const setLimitCode = (setLimit && `${SET}${setLimit}${exactlySuffix}`) || '';
2009
2010
  const setCountValue = stringifySet(matchUpFormatObject.setFormat, preserveRedundant);
2010
2011
  const setCode = (setCountValue && `S:${setCountValue}`) || '';
2011
2012
  const finalSetCountValue = stringifySet(matchUpFormatObject.finalSetFormat, preserveRedundant);
@@ -2079,9 +2080,12 @@ function parse(matchUpFormatCode) {
2079
2080
  }
2080
2081
  function setsMatch(formatstring) {
2081
2082
  const parts = formatstring.split('-');
2082
- const setsCount = getNumber(parts[0].slice(3));
2083
- const bestOf = setsCount === 1 || setsCount % 2 !== 0 ? setsCount : undefined;
2084
- const exactly = setsCount !== 1 && setsCount % 2 === 0 ? setsCount : undefined;
2083
+ const setsPart = parts[0].slice(3);
2084
+ const hasExactlySuffix = setsPart.endsWith('X');
2085
+ const setsCountString = hasExactlySuffix ? setsPart.slice(0, -1) : setsPart;
2086
+ const setsCount = getNumber(setsCountString);
2087
+ const bestOf = hasExactlySuffix && setsCount !== 1 ? undefined : setsCount;
2088
+ const exactly = hasExactlySuffix && setsCount !== 1 ? setsCount : undefined;
2085
2089
  const setFormat = parts && parseSetFormat(parts[1]);
2086
2090
  const finalSetFormat = parts && parseSetFormat(parts[2]);
2087
2091
  const timed = (setFormat && setFormat.timed) || (finalSetFormat && finalSetFormat.timed);
@@ -32114,7 +32118,7 @@ function tidyScore(params) {
32114
32118
  doProcess(processingOrder);
32115
32119
  let isValid = isValidPattern(score);
32116
32120
  if (!isValid) {
32117
- score = incomingScore.toString().replace(/\D/g, '');
32121
+ score = incomingScore.toString().replaceAll(/\D/g, '');
32118
32122
  if (attributes?.removed) {
32119
32123
  attributes.removed = undefined;
32120
32124
  }
@@ -32147,6 +32151,179 @@ var help = {
32147
32151
  tidyScore: tidyScore
32148
32152
  };
32149
32153
 
32154
+ function validateTiebreakOnlySet(winnerScore, loserScore, scoreDiff, tiebreakSetTo, allowIncomplete) {
32155
+ if (allowIncomplete) {
32156
+ return { isValid: true };
32157
+ }
32158
+ if (winnerScore === 0 && loserScore === 0) {
32159
+ return { isValid: false, error: 'Tiebreak-only set requires both scores' };
32160
+ }
32161
+ if (winnerScore < tiebreakSetTo) {
32162
+ return {
32163
+ isValid: false,
32164
+ error: `Tiebreak-only set winner must reach at least ${tiebreakSetTo}, got ${winnerScore}`,
32165
+ };
32166
+ }
32167
+ if (scoreDiff < 2) {
32168
+ return {
32169
+ isValid: false,
32170
+ error: `Tiebreak-only set must be won by at least 2 points, got ${winnerScore}-${loserScore}`,
32171
+ };
32172
+ }
32173
+ if (winnerScore === tiebreakSetTo && loserScore > tiebreakSetTo - 2) {
32174
+ return {
32175
+ isValid: false,
32176
+ error: `Tiebreak-only set at ${tiebreakSetTo}-${loserScore} requires playing past ${tiebreakSetTo}`,
32177
+ };
32178
+ }
32179
+ if (winnerScore > tiebreakSetTo && scoreDiff !== 2) {
32180
+ return {
32181
+ isValid: false,
32182
+ error: `Tiebreak-only set past ${tiebreakSetTo} must be won by exactly 2 points, got ${winnerScore}-${loserScore}`,
32183
+ };
32184
+ }
32185
+ return { isValid: true };
32186
+ }
32187
+ function validateTiebreakSetGames(winnerScore, loserScore, setTo, tiebreakAt) {
32188
+ const expectedWinnerScore = tiebreakAt === setTo ? setTo + 1 : setTo;
32189
+ const expectedLoserScore = tiebreakAt;
32190
+ if (winnerScore !== expectedWinnerScore) {
32191
+ return {
32192
+ isValid: false,
32193
+ error: `Tiebreak set winner must have ${expectedWinnerScore} games, got ${winnerScore}`,
32194
+ };
32195
+ }
32196
+ if (loserScore !== expectedLoserScore) {
32197
+ return {
32198
+ isValid: false,
32199
+ error: `Tiebreak set loser must have ${expectedLoserScore} games, got ${loserScore}`,
32200
+ };
32201
+ }
32202
+ return { isValid: true };
32203
+ }
32204
+ function validateExplicitTiebreakScore(side1TiebreakScore, side2TiebreakScore, tiebreakFormat) {
32205
+ const tbWinnerScore = Math.max(side1TiebreakScore || 0, side2TiebreakScore || 0);
32206
+ const tbLoserScore = Math.min(side1TiebreakScore || 0, side2TiebreakScore || 0);
32207
+ const tbDiff = tbWinnerScore - tbLoserScore;
32208
+ const tbTo = tiebreakFormat.tiebreakTo || 7;
32209
+ if (tbWinnerScore < tbTo) {
32210
+ return {
32211
+ isValid: false,
32212
+ error: `Tiebreak winner must reach ${tbTo} points, got ${tbWinnerScore}`,
32213
+ };
32214
+ }
32215
+ if (tbDiff < 2) {
32216
+ return {
32217
+ isValid: false,
32218
+ error: `Tiebreak must be won by 2 points, got ${tbWinnerScore}-${tbLoserScore}`,
32219
+ };
32220
+ }
32221
+ if (tbLoserScore >= tbTo - 1 && tbDiff > 2) {
32222
+ return {
32223
+ isValid: false,
32224
+ error: `Tiebreak score ${tbWinnerScore}-${tbLoserScore} is invalid`,
32225
+ };
32226
+ }
32227
+ return { isValid: true };
32228
+ }
32229
+ function validateTwoGameMargin(side1Score, side2Score, setTo, tiebreakAt) {
32230
+ if (!tiebreakAt)
32231
+ return { isValid: true };
32232
+ if (side1Score === setTo + 1 && side2Score < setTo - 1) {
32233
+ return {
32234
+ isValid: false,
32235
+ error: `With tiebreak format, if side 1 has ${setTo + 1} games, side 2 must be at least ${setTo - 1}, got ${side2Score}`,
32236
+ };
32237
+ }
32238
+ if (side2Score === setTo + 1 && side1Score < setTo - 1) {
32239
+ return {
32240
+ isValid: false,
32241
+ error: `With tiebreak format, if side 2 has ${setTo + 1} games, side 1 must be at least ${setTo - 1}, got ${side1Score}`,
32242
+ };
32243
+ }
32244
+ return { isValid: true };
32245
+ }
32246
+ function validateRegularSetCompletion(winnerScore, loserScore, scoreDiff, setTo, tiebreakAt) {
32247
+ if (winnerScore < setTo) {
32248
+ return {
32249
+ isValid: false,
32250
+ error: `Set winner must reach ${setTo} games, got ${winnerScore}`,
32251
+ };
32252
+ }
32253
+ const isTiebreakWon = tiebreakAt && winnerScore === setTo && loserScore === tiebreakAt && scoreDiff === 1;
32254
+ if (scoreDiff < 2 && !isTiebreakWon) {
32255
+ return {
32256
+ isValid: false,
32257
+ error: `Set must be won by at least 2 games, got ${winnerScore}-${loserScore}`,
32258
+ };
32259
+ }
32260
+ if (tiebreakAt) {
32261
+ if (loserScore >= tiebreakAt && !isTiebreakWon) {
32262
+ return {
32263
+ isValid: false,
32264
+ error: `When tied at ${tiebreakAt}-${tiebreakAt}, must play tiebreak. Use format like ${tiebreakAt + 1}-${tiebreakAt}(5)`,
32265
+ };
32266
+ }
32267
+ const maxWinnerScore = tiebreakAt === setTo ? setTo + 1 : setTo;
32268
+ if (winnerScore > maxWinnerScore) {
32269
+ return {
32270
+ isValid: false,
32271
+ error: `With tiebreak format, set score cannot exceed ${maxWinnerScore}-${tiebreakAt}. Got ${winnerScore}-${loserScore}`,
32272
+ };
32273
+ }
32274
+ }
32275
+ else if (winnerScore > setTo + 10) {
32276
+ return {
32277
+ isValid: false,
32278
+ error: `Set score ${winnerScore}-${loserScore} exceeds reasonable limits`,
32279
+ };
32280
+ }
32281
+ return { isValid: true };
32282
+ }
32283
+ function parseSetScores(set, isTiebreakOnlyFormat, hasTiebreakScores) {
32284
+ const side1TiebreakScore = set.side1TiebreakScore;
32285
+ const side2TiebreakScore = set.side2TiebreakScore;
32286
+ const side1Score = isTiebreakOnlyFormat && hasTiebreakScores ? side1TiebreakScore : set.side1Score || set.side1 || 0;
32287
+ const side2Score = isTiebreakOnlyFormat && hasTiebreakScores ? side2TiebreakScore : set.side2Score || set.side2 || 0;
32288
+ return { side1Score, side2Score, side1TiebreakScore, side2TiebreakScore };
32289
+ }
32290
+ function validateTiebreakSet(winnerScore, loserScore, setTo, tiebreakAt, side1TiebreakScore, side2TiebreakScore, tiebreakFormat) {
32291
+ if (setTo && tiebreakAt) {
32292
+ const validation = validateTiebreakSetGames(winnerScore, loserScore, setTo, tiebreakAt);
32293
+ if (!validation.isValid)
32294
+ return validation;
32295
+ }
32296
+ const hasExplicitTiebreak = side1TiebreakScore !== undefined || side2TiebreakScore !== undefined;
32297
+ if (hasExplicitTiebreak && tiebreakFormat) {
32298
+ return validateExplicitTiebreakScore(side1TiebreakScore, side2TiebreakScore, tiebreakFormat);
32299
+ }
32300
+ return { isValid: true };
32301
+ }
32302
+ function validateIncompleteSet(winnerScore, loserScore, setTo) {
32303
+ if (setTo && (winnerScore > setTo + 10 || loserScore > setTo + 10)) {
32304
+ return {
32305
+ isValid: false,
32306
+ error: `Set score ${winnerScore}-${loserScore} exceeds expected range for ${setTo}-game sets`,
32307
+ };
32308
+ }
32309
+ return { isValid: true };
32310
+ }
32311
+ function validateRegularSet(scores, setFormat, allowIncomplete) {
32312
+ const { side1: side1Score, side2: side2Score, winner: winnerScore, loser: loserScore, diff: scoreDiff } = scores;
32313
+ const { setTo, tiebreakAt } = setFormat;
32314
+ if (setTo && tiebreakAt) {
32315
+ const marginValidation = validateTwoGameMargin(side1Score, side2Score, setTo, tiebreakAt);
32316
+ if (!marginValidation.isValid)
32317
+ return marginValidation;
32318
+ }
32319
+ if (allowIncomplete) {
32320
+ return validateIncompleteSet(winnerScore, loserScore, setTo);
32321
+ }
32322
+ if (setTo) {
32323
+ return validateRegularSetCompletion(winnerScore, loserScore, scoreDiff, setTo, tiebreakAt);
32324
+ }
32325
+ return { isValid: true };
32326
+ }
32150
32327
  function validateSetScore(set, matchUpFormat, isDecidingSet, allowIncomplete) {
32151
32328
  if (!matchUpFormat)
32152
32329
  return { isValid: true };
@@ -32159,152 +32336,21 @@ function validateSetScore(set, matchUpFormat, isDecidingSet, allowIncomplete) {
32159
32336
  const { setTo, tiebreakAt, tiebreakFormat, tiebreakSet } = setFormat;
32160
32337
  const tiebreakSetTo = tiebreakSet?.tiebreakTo;
32161
32338
  const isTiebreakOnlyFormat = !!tiebreakSetTo && !setTo;
32162
- const side1TiebreakScore = set.side1TiebreakScore;
32163
- const side2TiebreakScore = set.side2TiebreakScore;
32164
- const hasTiebreakScores = side1TiebreakScore !== undefined && side2TiebreakScore !== undefined;
32165
- const side1Score = isTiebreakOnlyFormat && hasTiebreakScores ? side1TiebreakScore : set.side1Score || set.side1 || 0;
32166
- const side2Score = isTiebreakOnlyFormat && hasTiebreakScores ? side2TiebreakScore : set.side2Score || set.side2 || 0;
32339
+ const hasTiebreakScores = set.side1TiebreakScore !== undefined && set.side2TiebreakScore !== undefined;
32340
+ const { side1Score, side2Score, side1TiebreakScore, side2TiebreakScore } = parseSetScores(set, isTiebreakOnlyFormat, hasTiebreakScores);
32167
32341
  const winnerScore = Math.max(side1Score, side2Score);
32168
32342
  const loserScore = Math.min(side1Score, side2Score);
32169
32343
  const scoreDiff = winnerScore - loserScore;
32170
32344
  if (isTiebreakOnlyFormat) {
32171
- if (allowIncomplete) {
32172
- return { isValid: true };
32173
- }
32174
- if (side1Score === 0 && side2Score === 0) {
32175
- return { isValid: false, error: 'Tiebreak-only set requires both scores' };
32176
- }
32177
- if (winnerScore < tiebreakSetTo) {
32178
- return {
32179
- isValid: false,
32180
- error: `Tiebreak-only set winner must reach at least ${tiebreakSetTo}, got ${winnerScore}`,
32181
- };
32182
- }
32183
- if (scoreDiff < 2) {
32184
- return {
32185
- isValid: false,
32186
- error: `Tiebreak-only set must be won by at least 2 points, got ${winnerScore}-${loserScore}`,
32187
- };
32188
- }
32189
- if (winnerScore === tiebreakSetTo && loserScore > tiebreakSetTo - 2) {
32190
- return {
32191
- isValid: false,
32192
- error: `Tiebreak-only set at ${tiebreakSetTo}-${loserScore} requires playing past ${tiebreakSetTo}`,
32193
- };
32194
- }
32195
- if (winnerScore > tiebreakSetTo && scoreDiff !== 2) {
32196
- return {
32197
- isValid: false,
32198
- error: `Tiebreak-only set past ${tiebreakSetTo} must be won by exactly 2 points, got ${winnerScore}-${loserScore}`,
32199
- };
32200
- }
32201
- return { isValid: true };
32345
+ return validateTiebreakOnlySet(winnerScore, loserScore, scoreDiff, tiebreakSetTo, allowIncomplete ?? false);
32202
32346
  }
32203
32347
  const hasExplicitTiebreak = side1TiebreakScore !== undefined || side2TiebreakScore !== undefined;
32204
32348
  const isImplicitTiebreak = setTo && winnerScore === setTo + 1 && loserScore === setTo;
32205
32349
  const hasTiebreak = hasExplicitTiebreak || isImplicitTiebreak;
32206
32350
  if (hasTiebreak) {
32207
- if (setTo && tiebreakAt) {
32208
- const expectedWinnerScore = tiebreakAt === setTo ? setTo + 1 : setTo;
32209
- const expectedLoserScore = tiebreakAt;
32210
- if (winnerScore !== expectedWinnerScore) {
32211
- return {
32212
- isValid: false,
32213
- error: `Tiebreak set winner must have ${expectedWinnerScore} games, got ${winnerScore}`,
32214
- };
32215
- }
32216
- if (loserScore !== expectedLoserScore) {
32217
- return {
32218
- isValid: false,
32219
- error: `Tiebreak set loser must have ${expectedLoserScore} games, got ${loserScore}`,
32220
- };
32221
- }
32222
- }
32223
- if (hasExplicitTiebreak && tiebreakFormat) {
32224
- const tbWinnerScore = Math.max(side1TiebreakScore || 0, side2TiebreakScore || 0);
32225
- const tbLoserScore = Math.min(side1TiebreakScore || 0, side2TiebreakScore || 0);
32226
- const tbDiff = tbWinnerScore - tbLoserScore;
32227
- const tbTo = tiebreakFormat.tiebreakTo || 7;
32228
- if (tbWinnerScore < tbTo) {
32229
- return {
32230
- isValid: false,
32231
- error: `Tiebreak winner must reach ${tbTo} points, got ${tbWinnerScore}`,
32232
- };
32233
- }
32234
- if (tbDiff < 2) {
32235
- return {
32236
- isValid: false,
32237
- error: `Tiebreak must be won by 2 points, got ${tbWinnerScore}-${tbLoserScore}`,
32238
- };
32239
- }
32240
- if (tbLoserScore >= tbTo - 1 && tbDiff > 2) {
32241
- return {
32242
- isValid: false,
32243
- error: `Tiebreak score ${tbWinnerScore}-${tbLoserScore} is invalid`,
32244
- };
32245
- }
32246
- }
32351
+ return validateTiebreakSet(winnerScore, loserScore, setTo, tiebreakAt, side1TiebreakScore, side2TiebreakScore, tiebreakFormat);
32247
32352
  }
32248
- else {
32249
- if (setTo && tiebreakAt) {
32250
- if (side1Score === setTo + 1 && side2Score < setTo - 1) {
32251
- return {
32252
- isValid: false,
32253
- error: `With tiebreak format, if side 1 has ${setTo + 1} games, side 2 must be at least ${setTo - 1}, got ${side2Score}`,
32254
- };
32255
- }
32256
- if (side2Score === setTo + 1 && side1Score < setTo - 1) {
32257
- return {
32258
- isValid: false,
32259
- error: `With tiebreak format, if side 2 has ${setTo + 1} games, side 1 must be at least ${setTo - 1}, got ${side1Score}`,
32260
- };
32261
- }
32262
- }
32263
- if (allowIncomplete) {
32264
- if (setTo && (winnerScore > setTo + 10 || loserScore > setTo + 10)) {
32265
- return {
32266
- isValid: false,
32267
- error: `Set score ${winnerScore}-${loserScore} exceeds expected range for ${setTo}-game sets`,
32268
- };
32269
- }
32270
- return { isValid: true };
32271
- }
32272
- if (setTo && winnerScore < setTo) {
32273
- return {
32274
- isValid: false,
32275
- error: `Set winner must reach ${setTo} games, got ${winnerScore}`,
32276
- };
32277
- }
32278
- const isTiebreakWon = tiebreakAt && winnerScore === setTo && loserScore === tiebreakAt && scoreDiff === 1;
32279
- if (scoreDiff < 2 && !isTiebreakWon) {
32280
- return {
32281
- isValid: false,
32282
- error: `Set must be won by at least 2 games, got ${winnerScore}-${loserScore}`,
32283
- };
32284
- }
32285
- if (tiebreakAt) {
32286
- if (loserScore >= tiebreakAt && !isTiebreakWon) {
32287
- return {
32288
- isValid: false,
32289
- error: `When tied at ${tiebreakAt}-${tiebreakAt}, must play tiebreak. Use format like ${tiebreakAt + 1}-${tiebreakAt}(5)`,
32290
- };
32291
- }
32292
- const maxWinnerScore = tiebreakAt === setTo ? setTo + 1 : setTo;
32293
- if (winnerScore > maxWinnerScore) {
32294
- return {
32295
- isValid: false,
32296
- error: `With tiebreak format, set score cannot exceed ${maxWinnerScore}-${tiebreakAt}. Got ${winnerScore}-${loserScore}`,
32297
- };
32298
- }
32299
- }
32300
- else if (winnerScore > setTo + 10) {
32301
- return {
32302
- isValid: false,
32303
- error: `Set score ${winnerScore}-${loserScore} exceeds reasonable limits`,
32304
- };
32305
- }
32306
- }
32307
- return { isValid: true };
32353
+ return validateRegularSet({ side1: side1Score, side2: side2Score, winner: winnerScore, loser: loserScore, diff: scoreDiff }, { setTo, tiebreakAt }, allowIncomplete);
32308
32354
  }
32309
32355
  function validateMatchUpScore(sets, matchUpFormat, matchUpStatus) {
32310
32356
  if (!sets || sets.length === 0) {
@@ -32566,10 +32612,18 @@ function parseScoreString({ tiebreakTo = 7, scoreString = '', matchUpFormat }) {
32566
32612
  winningSide = (side1Score > side2Score && 1) || (side1Score < side2Score && 2) || undefined;
32567
32613
  if (tiebreak) {
32568
32614
  const setTiebreakLowScore = tiebreak[1];
32615
+ let setSpecificTiebreakTo = tiebreakTo;
32616
+ if (parsedFormat) {
32617
+ const isDecidingSet = setNumber === bestOfSets;
32618
+ const setFormat = isDecidingSet && parsedFormat.finalSetFormat ? parsedFormat.finalSetFormat : parsedFormat.setFormat;
32619
+ if (setFormat?.tiebreakFormat?.tiebreakTo) {
32620
+ setSpecificTiebreakTo = setFormat.tiebreakFormat.tiebreakTo;
32621
+ }
32622
+ }
32569
32623
  const side1TiebreakPerspective = getTiebreakComplement({
32570
32624
  lowValue: setTiebreakLowScore,
32571
32625
  isSide1: winningSide === 2,
32572
- tiebreakTo,
32626
+ tiebreakTo: setSpecificTiebreakTo,
32573
32627
  });
32574
32628
  if (Array.isArray(side1TiebreakPerspective)) {
32575
32629
  [side1TiebreakScore, side2TiebreakScore] = side1TiebreakPerspective;
@@ -36501,9 +36555,9 @@ function courtGridRows({ courtPrefix = 'C|', minRowsCount, courtsData }) {
36501
36555
  const maxCourtOrder = courtsData?.reduce((order, court) => {
36502
36556
  const matchUps = court.matchUps || [];
36503
36557
  const courtOrder = Math.max(0, ...matchUps.map((m) => m.schedule.courtOrder || 0));
36504
- return courtOrder > order ? courtOrder : order;
36558
+ return Math.max(courtOrder, order);
36505
36559
  }, 1);
36506
- const rowsCount = minRowsCount ? Math.max(minRowsCount, maxCourtOrder) : maxCourtOrder;
36560
+ const rowsCount = Math.max(minRowsCount || 0, maxCourtOrder);
36507
36561
  const rowBuilder = generateRange(0, rowsCount).map((rowIndex) => ({
36508
36562
  matchUps: generateRange(0, courtsData.length).map((courtIndex) => {
36509
36563
  const courtInfo = courtsData[courtIndex];
@@ -37274,24 +37328,22 @@ function competitionScheduleMatchUps(params) {
37274
37328
  ({ drawIds: publishedDrawIds, detailsMap } = getCompetitionPublishedDrawDetails({ tournamentRecords }));
37275
37329
  }
37276
37330
  if (publishedDrawIds?.length) {
37277
- if (!params.contextFilters)
37278
- params.contextFilters = {};
37279
- if (!params.contextFilters?.drawIds) {
37280
- params.contextFilters.drawIds = publishedDrawIds;
37331
+ params.contextFilters ??= {};
37332
+ if (params.contextFilters.drawIds) {
37333
+ params.contextFilters.drawIds = params.contextFilters.drawIds.filter((drawId) => publishedDrawIds.includes(drawId));
37281
37334
  }
37282
37335
  else {
37283
- params.contextFilters.drawIds = params.contextFilters.drawIds.filter((drawId) => publishedDrawIds.includes(drawId));
37336
+ params.contextFilters.drawIds = publishedDrawIds;
37284
37337
  }
37285
37338
  }
37286
37339
  if (tournamentPublishStatus?.eventIds?.length) {
37287
- if (!params.matchUpFilters)
37288
- params.matchUpFilters = {};
37340
+ params.matchUpFilters ??= {};
37289
37341
  if (params.matchUpFilters?.eventIds) {
37290
- if (!params.matchUpFilters.eventIds.length) {
37291
- params.matchUpFilters.eventIds = tournamentPublishStatus.eventIds;
37342
+ if (params.matchUpFilters.eventIds.length) {
37343
+ params.matchUpFilters.eventIds = params.matchUpFilters.eventIds.filter((eventId) => tournamentPublishStatus.eventIds.includes(eventId));
37292
37344
  }
37293
37345
  else {
37294
- params.matchUpFilters.eventIds = params.matchUpFilters.eventIds.filter((eventId) => tournamentPublishStatus.eventIds.includes(eventId));
37346
+ params.matchUpFilters.eventIds = tournamentPublishStatus.eventIds;
37295
37347
  }
37296
37348
  }
37297
37349
  else {
@@ -37299,14 +37351,13 @@ function competitionScheduleMatchUps(params) {
37299
37351
  }
37300
37352
  }
37301
37353
  if (tournamentPublishStatus?.scheduledDates?.length) {
37302
- if (!params.matchUpFilters)
37303
- params.matchUpFilters = {};
37354
+ params.matchUpFilters ??= {};
37304
37355
  if (params.matchUpFilters.scheduledDates) {
37305
- if (!params.matchUpFilters.scheduledDates.length) {
37306
- params.matchUpFilters.scheduledDates = tournamentPublishStatus.scheduledDates;
37356
+ if (params.matchUpFilters.scheduledDates.length) {
37357
+ params.matchUpFilters.scheduledDates = params.matchUpFilters.scheduledDates.filter((scheduledDate) => tournamentPublishStatus.scheduledDates.includes(scheduledDate));
37307
37358
  }
37308
37359
  else {
37309
- params.matchUpFilters.scheduledDates = params.matchUpFilters.scheduledDates.filter((scheduledDate) => tournamentPublishStatus.scheduledDates.includes(scheduledDate));
37360
+ params.matchUpFilters.scheduledDates = tournamentPublishStatus.scheduledDates;
37310
37361
  }
37311
37362
  }
37312
37363
  else {
@@ -37314,8 +37365,7 @@ function competitionScheduleMatchUps(params) {
37314
37365
  }
37315
37366
  }
37316
37367
  if (alwaysReturnCompleted) {
37317
- if (!params.matchUpFilters)
37318
- params.matchUpFilters = {};
37368
+ params.matchUpFilters ??= {};
37319
37369
  if (params.matchUpFilters?.excludeMatchUpStatuses?.length) {
37320
37370
  if (!params.matchUpFilters.excludeMatchUpStatuses.includes(COMPLETED$1)) {
37321
37371
  params.matchUpFilters.excludeMatchUpStatuses.push(COMPLETED$1);
@@ -37382,7 +37432,7 @@ function competitionScheduleMatchUps(params) {
37382
37432
  };
37383
37433
  if (withCourtGridRows) {
37384
37434
  const { rows, courtPrefix } = courtGridRows({
37385
- minRowsCount: minCourtGridRows,
37435
+ minRowsCount: Math.max(minCourtGridRows || 0, dateMatchUps.length || 0),
37386
37436
  courtsData,
37387
37437
  });
37388
37438
  result.courtPrefix = courtPrefix;
@@ -51968,7 +52018,7 @@ function generateTournamentRecord(params) {
51968
52018
  return result;
51969
52019
  }
51970
52020
  if (params.drawProfiles) {
51971
- const result = processDrawProfiles({
52021
+ const result = processDrawProfiles$1({
51972
52022
  allUniqueParticipantIds,
51973
52023
  ratingsParameters: ratingsParameters$1,
51974
52024
  tournamentRecord,
@@ -51980,7 +52030,7 @@ function generateTournamentRecord(params) {
51980
52030
  return result;
51981
52031
  }
51982
52032
  if (params.eventProfiles) {
51983
- const result = processEventProfiles({
52033
+ const result = processEventProfiles$1({
51984
52034
  allUniqueParticipantIds,
51985
52035
  ratingsParameters: ratingsParameters$1,
51986
52036
  tournamentRecord,
@@ -52005,7 +52055,7 @@ function generateTournamentRecord(params) {
52005
52055
  drawIds,
52006
52056
  });
52007
52057
  }
52008
- function processDrawProfiles(params) {
52058
+ function processDrawProfiles$1(params) {
52009
52059
  const { tournamentRecord, drawProfiles, allUniqueParticipantIds, eventIds, drawIds } = params;
52010
52060
  let drawIndex = 0;
52011
52061
  for (const drawProfile of drawProfiles) {
@@ -52037,7 +52087,7 @@ function processDrawProfiles(params) {
52037
52087
  drawIndex += 1;
52038
52088
  }
52039
52089
  }
52040
- function processEventProfiles(params) {
52090
+ function processEventProfiles$1(params) {
52041
52091
  const { eventProfiles, allUniqueParticipantIds, eventIds, drawIds } = params;
52042
52092
  let eventIndex = 0;
52043
52093
  for (const eventProfile of eventProfiles) {
@@ -52364,164 +52414,150 @@ function generatePairParticipantName({ individualParticipantIds, individualParti
52364
52414
  return participantName;
52365
52415
  }
52366
52416
 
52367
- function modifyTournamentRecord(params) {
52368
- const { ratingsParameters: ratingsParameters$1 = ratingsParameters, participantsProfile = {}, matchUpStatusProfile, completeAllMatchUps, autoEntryPositions, hydrateCollections, randomWinningSide, schedulingProfile, tournamentRecord, autoSchedule, eventProfiles, periodLength, venueProfiles, drawProfiles, isMock, uuids, } = params;
52369
- if (!tournamentRecord)
52370
- return { error: MISSING_TOURNAMENT_RECORD };
52371
- const allUniqueParticipantIds = [];
52372
- const eventIds = [];
52373
- const drawIds = [];
52374
- eventProfiles?.forEach((eventProfile) => {
52375
- const event = tournamentRecord.events?.find((event, index) => (eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex) ||
52376
- (eventProfile.eventName && event.eventName === eventProfile.eventName) ||
52377
- (eventProfile.eventId && event.eventId === eventProfile.eventId));
52378
- if (event?.gender) {
52379
- eventProfile.gender = event.gender;
52380
- }
52381
- });
52382
- const participantsCount = tournamentRecord.participants?.length || undefined;
52383
- if (participantsCount && participantsProfile?.idPrefix) {
52384
- participantsProfile.idPrefix = `${participantsProfile.idPrefix}-${participantsCount}`;
52417
+ function processExistingEvent({ event, eventProfile, tournamentRecord, allUniqueParticipantIds, drawIds }) {
52418
+ const { gender, category, eventType } = event;
52419
+ const { drawProfiles, publish } = eventProfile;
52420
+ const eventParticipantType = (isMatchUpEventType(SINGLES)(eventType) && INDIVIDUAL) ||
52421
+ (isMatchUpEventType(DOUBLES)(eventType) && PAIR) ||
52422
+ eventType;
52423
+ if (drawProfiles) {
52424
+ const { stageParticipantsCount, uniqueParticipantsCount, uniqueParticipantStages } = getStageParticipantsCount({
52425
+ drawProfiles,
52426
+ category,
52427
+ gender,
52428
+ });
52429
+ const { uniqueDrawParticipants = [], uniqueParticipantIds = [] } = uniqueParticipantStages
52430
+ ? generateEventParticipants({
52431
+ event: { eventType, category, gender },
52432
+ uniqueParticipantsCount,
52433
+ participantsProfile: eventProfile.participantsProfile,
52434
+ ratingsParameters: eventProfile.ratingsParameters,
52435
+ tournamentRecord,
52436
+ eventProfile,
52437
+ uuids: eventProfile.uuids,
52438
+ })
52439
+ : {};
52440
+ allUniqueParticipantIds.push(...uniqueParticipantIds);
52441
+ const { stageParticipants } = getStageParticipants({
52442
+ targetParticipants: tournamentRecord.participants || [],
52443
+ allUniqueParticipantIds,
52444
+ stageParticipantsCount,
52445
+ eventParticipantType,
52446
+ });
52447
+ let result = generateFlights({
52448
+ uniqueDrawParticipants,
52449
+ autoEntryPositions: eventProfile.autoEntryPositions,
52450
+ stageParticipants,
52451
+ tournamentRecord,
52452
+ drawProfiles,
52453
+ category,
52454
+ gender,
52455
+ event,
52456
+ });
52457
+ if (result.error)
52458
+ return result;
52459
+ result = generateFlightDrawDefinitions({
52460
+ matchUpStatusProfile: eventProfile.matchUpStatusProfile,
52461
+ completeAllMatchUps: eventProfile.completeAllMatchUps,
52462
+ randomWinningSide: eventProfile.randomWinningSide,
52463
+ tournamentRecord,
52464
+ drawProfiles,
52465
+ isMock: eventProfile.isMock,
52466
+ event,
52467
+ });
52468
+ if (result.error)
52469
+ return result;
52470
+ drawIds.push(...result.drawIds);
52385
52471
  }
52386
- const result = addTournamentParticipants({
52387
- startDate: tournamentRecord.startDate,
52388
- participantsProfile,
52389
- tournamentRecord,
52390
- eventProfiles,
52391
- drawProfiles,
52392
- uuids,
52393
- });
52394
- if (!result.success)
52395
- return result;
52396
- if (eventProfiles) {
52397
- let eventIndex = tournamentRecord.events?.length || 0;
52398
- for (const eventProfile of eventProfiles) {
52399
- const { ratingsParameters } = eventProfile;
52400
- const event = tournamentRecord.events?.find((event, index) => (eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex) ||
52401
- (eventProfile.eventName && event.eventName === eventProfile.eventName) ||
52402
- (eventProfile.eventId && event.eventId === eventProfile.eventId));
52403
- if (!event) {
52404
- const result = generateEventWithFlights({
52405
- startDate: tournamentRecord.startDate,
52406
- allUniqueParticipantIds,
52407
- matchUpStatusProfile,
52408
- participantsProfile,
52409
- completeAllMatchUps,
52410
- autoEntryPositions,
52411
- randomWinningSide,
52412
- ratingsParameters,
52413
- tournamentRecord,
52414
- eventProfile,
52415
- eventIndex,
52416
- uuids,
52417
- });
52418
- if (result.error)
52419
- return result;
52420
- const { eventId, drawIds: generatedDrawIds, uniqueParticipantIds } = result;
52421
- if (generatedDrawIds)
52422
- drawIds.push(...generatedDrawIds);
52423
- eventIds.push(eventId);
52424
- if (uniqueParticipantIds?.length)
52425
- allUniqueParticipantIds.push(...uniqueParticipantIds);
52426
- eventIndex += 1;
52427
- }
52428
- else {
52429
- const { gender, category, eventType } = event;
52430
- const { drawProfiles, publish } = eventProfile;
52431
- const eventParticipantType = (isMatchUpEventType(SINGLES)(eventType) && INDIVIDUAL) ||
52432
- (isMatchUpEventType(DOUBLES)(eventType) && PAIR) ||
52433
- eventType;
52434
- if (drawProfiles) {
52435
- const { stageParticipantsCount, uniqueParticipantsCount, uniqueParticipantStages } = getStageParticipantsCount({
52436
- drawProfiles,
52437
- category,
52438
- gender,
52439
- });
52440
- const { uniqueDrawParticipants = [], uniqueParticipantIds = [] } = uniqueParticipantStages
52441
- ? generateEventParticipants({
52442
- event: { eventType, category, gender },
52443
- uniqueParticipantsCount,
52444
- participantsProfile,
52445
- ratingsParameters,
52446
- tournamentRecord,
52447
- eventProfile,
52448
- uuids,
52449
- })
52450
- : {};
52451
- allUniqueParticipantIds.push(...uniqueParticipantIds);
52452
- const { stageParticipants } = getStageParticipants({
52453
- targetParticipants: tournamentRecord.participants || [],
52454
- allUniqueParticipantIds,
52455
- stageParticipantsCount,
52456
- eventParticipantType,
52457
- });
52458
- let result = generateFlights({
52459
- uniqueDrawParticipants,
52460
- autoEntryPositions,
52461
- stageParticipants,
52462
- tournamentRecord,
52463
- drawProfiles,
52464
- category,
52465
- gender,
52466
- event,
52467
- });
52468
- if (result.error)
52469
- return result;
52470
- result = generateFlightDrawDefinitions({
52471
- matchUpStatusProfile,
52472
- completeAllMatchUps,
52473
- randomWinningSide,
52474
- tournamentRecord,
52475
- drawProfiles,
52476
- isMock,
52477
- event,
52478
- });
52479
- if (result.error)
52480
- return result;
52481
- drawIds.push(...result.drawIds);
52482
- }
52483
- if (publish) {
52484
- publishEvent({ tournamentRecord, event });
52485
- }
52486
- }
52487
- }
52472
+ if (publish) {
52473
+ publishEvent({ tournamentRecord, event });
52488
52474
  }
52489
- if (drawProfiles) {
52490
- let drawIndex = (tournamentRecord.events || [])
52491
- .map((event) => event.drawDefinitions?.map(() => 1) || [])
52492
- .flat()
52493
- .reduce((a, b) => a + b, 0);
52494
- for (const drawProfile of drawProfiles) {
52495
- let result = generateEventWithDraw({
52496
- startDate: tournamentRecord.startDate,
52497
- allUniqueParticipantIds,
52498
- matchUpStatusProfile,
52499
- participantsProfile,
52500
- completeAllMatchUps,
52501
- autoEntryPositions,
52502
- hydrateCollections,
52503
- randomWinningSide,
52504
- ratingsParameters: ratingsParameters$1,
52475
+ return SUCCESS;
52476
+ }
52477
+ function findEventByProfile(events, eventProfile) {
52478
+ return events?.find((event, index) => (eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex) ||
52479
+ (eventProfile.eventName && event.eventName === eventProfile.eventName) ||
52480
+ (eventProfile.eventId && event.eventId === eventProfile.eventId));
52481
+ }
52482
+ function processEventProfiles({ eventProfiles, tournamentRecord, allUniqueParticipantIds, eventIds, drawIds, params }) {
52483
+ let eventIndex = tournamentRecord.events?.length || 0;
52484
+ for (const eventProfile of eventProfiles) {
52485
+ const event = findEventByProfile(tournamentRecord.events, eventProfile);
52486
+ if (event) {
52487
+ const result = processExistingEvent({
52488
+ event,
52489
+ eventProfile: { ...eventProfile, ...params },
52505
52490
  tournamentRecord,
52506
- drawProfile,
52507
- drawIndex,
52508
- uuids,
52491
+ allUniqueParticipantIds,
52492
+ drawIds,
52509
52493
  });
52510
52494
  if (result.error)
52511
52495
  return result;
52512
- const { drawId, eventId, event, uniqueParticipantIds } = result;
52513
- result = addEvent({ tournamentRecord, event, internalUse: true });
52496
+ }
52497
+ else {
52498
+ const result = generateEventWithFlights({
52499
+ startDate: tournamentRecord.startDate,
52500
+ allUniqueParticipantIds,
52501
+ matchUpStatusProfile: params.matchUpStatusProfile,
52502
+ participantsProfile: params.participantsProfile,
52503
+ completeAllMatchUps: params.completeAllMatchUps,
52504
+ autoEntryPositions: params.autoEntryPositions,
52505
+ randomWinningSide: params.randomWinningSide,
52506
+ ratingsParameters: eventProfile.ratingsParameters,
52507
+ tournamentRecord,
52508
+ eventProfile,
52509
+ eventIndex,
52510
+ uuids: params.uuids,
52511
+ });
52514
52512
  if (result.error)
52515
52513
  return result;
52516
- if (drawId)
52517
- drawIds.push(drawId);
52514
+ const { eventId, drawIds: generatedDrawIds, uniqueParticipantIds } = result;
52515
+ if (generatedDrawIds)
52516
+ drawIds.push(...generatedDrawIds);
52518
52517
  eventIds.push(eventId);
52519
52518
  if (uniqueParticipantIds?.length)
52520
52519
  allUniqueParticipantIds.push(...uniqueParticipantIds);
52521
- drawIndex += 1;
52520
+ eventIndex += 1;
52522
52521
  }
52523
52522
  }
52524
- const venueIds = venueProfiles?.length ? generateVenues({ tournamentRecord, venueProfiles }) : [];
52523
+ return SUCCESS;
52524
+ }
52525
+ function processDrawProfiles({ drawProfiles, tournamentRecord, allUniqueParticipantIds, eventIds, drawIds, params }) {
52526
+ let drawIndex = (tournamentRecord.events || [])
52527
+ .flatMap((event) => event.drawDefinitions?.map(() => 1) || [])
52528
+ .reduce((a, b) => a + b, 0);
52529
+ for (const drawProfile of drawProfiles) {
52530
+ let result = generateEventWithDraw({
52531
+ startDate: tournamentRecord.startDate,
52532
+ allUniqueParticipantIds,
52533
+ matchUpStatusProfile: params.matchUpStatusProfile,
52534
+ participantsProfile: params.participantsProfile,
52535
+ completeAllMatchUps: params.completeAllMatchUps,
52536
+ autoEntryPositions: params.autoEntryPositions,
52537
+ hydrateCollections: params.hydrateCollections,
52538
+ randomWinningSide: params.randomWinningSide,
52539
+ ratingsParameters: params.ratingsParameters,
52540
+ tournamentRecord,
52541
+ drawProfile,
52542
+ drawIndex,
52543
+ uuids: params.uuids,
52544
+ });
52545
+ if (result.error)
52546
+ return result;
52547
+ const { drawId, eventId, event, uniqueParticipantIds } = result;
52548
+ result = addEvent({ tournamentRecord, event, internalUse: true });
52549
+ if (result.error)
52550
+ return result;
52551
+ if (drawId)
52552
+ drawIds.push(drawId);
52553
+ eventIds.push(eventId);
52554
+ if (uniqueParticipantIds?.length)
52555
+ allUniqueParticipantIds.push(...uniqueParticipantIds);
52556
+ drawIndex += 1;
52557
+ }
52558
+ return SUCCESS;
52559
+ }
52560
+ function applySchedulingProfile({ schedulingProfile, autoSchedule, periodLength, tournamentRecord }) {
52525
52561
  let scheduledRounds;
52526
52562
  let schedulerResult = {};
52527
52563
  if (schedulingProfile?.length) {
@@ -52543,6 +52579,69 @@ function modifyTournamentRecord(params) {
52543
52579
  });
52544
52580
  }
52545
52581
  }
52582
+ return { scheduledRounds, schedulerResult };
52583
+ }
52584
+ function modifyTournamentRecord(params) {
52585
+ const { participantsProfile = {}, schedulingProfile, tournamentRecord, autoSchedule, eventProfiles, periodLength, venueProfiles, drawProfiles, uuids, } = params;
52586
+ if (!tournamentRecord)
52587
+ return { error: MISSING_TOURNAMENT_RECORD };
52588
+ const allUniqueParticipantIds = [];
52589
+ const eventIds = [];
52590
+ const drawIds = [];
52591
+ eventProfiles?.forEach((eventProfile) => {
52592
+ const event = findEventByProfile(tournamentRecord.events, eventProfile);
52593
+ if (event?.gender) {
52594
+ eventProfile.gender = event.gender;
52595
+ }
52596
+ });
52597
+ const participantsCount = tournamentRecord.participants?.length || undefined;
52598
+ if (participantsCount && participantsProfile?.idPrefix) {
52599
+ participantsProfile.idPrefix = `${participantsProfile.idPrefix}-${participantsCount}`;
52600
+ }
52601
+ const result = addTournamentParticipants({
52602
+ startDate: tournamentRecord.startDate,
52603
+ participantsProfile,
52604
+ tournamentRecord,
52605
+ eventProfiles,
52606
+ drawProfiles,
52607
+ uuids,
52608
+ });
52609
+ if (!result.success)
52610
+ return result;
52611
+ if (eventProfiles) {
52612
+ const eventResult = processEventProfiles({
52613
+ eventProfiles,
52614
+ tournamentRecord,
52615
+ allUniqueParticipantIds,
52616
+ eventIds,
52617
+ drawIds,
52618
+ params,
52619
+ });
52620
+ if (eventResult.error)
52621
+ return eventResult;
52622
+ }
52623
+ if (drawProfiles) {
52624
+ const drawResult = processDrawProfiles({
52625
+ drawProfiles,
52626
+ tournamentRecord,
52627
+ allUniqueParticipantIds,
52628
+ eventIds,
52629
+ drawIds,
52630
+ params,
52631
+ });
52632
+ if (drawResult.error)
52633
+ return drawResult;
52634
+ }
52635
+ const venueIds = venueProfiles?.length ? generateVenues({ tournamentRecord, venueProfiles }) : [];
52636
+ const schedulingResult = applySchedulingProfile({
52637
+ schedulingProfile,
52638
+ autoSchedule,
52639
+ periodLength,
52640
+ tournamentRecord,
52641
+ });
52642
+ if (schedulingResult.error)
52643
+ return schedulingResult;
52644
+ const { scheduledRounds, schedulerResult } = schedulingResult;
52546
52645
  const totalParticipantsCount = tournamentRecord.participants.length;
52547
52646
  return {
52548
52647
  totalParticipantsCount,