tods-competition-factory 2.2.38 → 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.38';
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
- }
32247
- }
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
- }
32351
+ return validateTiebreakSet(winnerScore, loserScore, setTo, tiebreakAt, side1TiebreakScore, side2TiebreakScore, tiebreakFormat);
32306
32352
  }
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) {
@@ -36509,9 +36555,9 @@ function courtGridRows({ courtPrefix = 'C|', minRowsCount, courtsData }) {
36509
36555
  const maxCourtOrder = courtsData?.reduce((order, court) => {
36510
36556
  const matchUps = court.matchUps || [];
36511
36557
  const courtOrder = Math.max(0, ...matchUps.map((m) => m.schedule.courtOrder || 0));
36512
- return courtOrder > order ? courtOrder : order;
36558
+ return Math.max(courtOrder, order);
36513
36559
  }, 1);
36514
- const rowsCount = minRowsCount ? Math.max(minRowsCount, maxCourtOrder) : maxCourtOrder;
36560
+ const rowsCount = Math.max(minRowsCount || 0, maxCourtOrder);
36515
36561
  const rowBuilder = generateRange(0, rowsCount).map((rowIndex) => ({
36516
36562
  matchUps: generateRange(0, courtsData.length).map((courtIndex) => {
36517
36563
  const courtInfo = courtsData[courtIndex];
@@ -37282,24 +37328,22 @@ function competitionScheduleMatchUps(params) {
37282
37328
  ({ drawIds: publishedDrawIds, detailsMap } = getCompetitionPublishedDrawDetails({ tournamentRecords }));
37283
37329
  }
37284
37330
  if (publishedDrawIds?.length) {
37285
- if (!params.contextFilters)
37286
- params.contextFilters = {};
37287
- if (!params.contextFilters?.drawIds) {
37288
- params.contextFilters.drawIds = publishedDrawIds;
37331
+ params.contextFilters ??= {};
37332
+ if (params.contextFilters.drawIds) {
37333
+ params.contextFilters.drawIds = params.contextFilters.drawIds.filter((drawId) => publishedDrawIds.includes(drawId));
37289
37334
  }
37290
37335
  else {
37291
- params.contextFilters.drawIds = params.contextFilters.drawIds.filter((drawId) => publishedDrawIds.includes(drawId));
37336
+ params.contextFilters.drawIds = publishedDrawIds;
37292
37337
  }
37293
37338
  }
37294
37339
  if (tournamentPublishStatus?.eventIds?.length) {
37295
- if (!params.matchUpFilters)
37296
- params.matchUpFilters = {};
37340
+ params.matchUpFilters ??= {};
37297
37341
  if (params.matchUpFilters?.eventIds) {
37298
- if (!params.matchUpFilters.eventIds.length) {
37299
- params.matchUpFilters.eventIds = tournamentPublishStatus.eventIds;
37342
+ if (params.matchUpFilters.eventIds.length) {
37343
+ params.matchUpFilters.eventIds = params.matchUpFilters.eventIds.filter((eventId) => tournamentPublishStatus.eventIds.includes(eventId));
37300
37344
  }
37301
37345
  else {
37302
- params.matchUpFilters.eventIds = params.matchUpFilters.eventIds.filter((eventId) => tournamentPublishStatus.eventIds.includes(eventId));
37346
+ params.matchUpFilters.eventIds = tournamentPublishStatus.eventIds;
37303
37347
  }
37304
37348
  }
37305
37349
  else {
@@ -37307,14 +37351,13 @@ function competitionScheduleMatchUps(params) {
37307
37351
  }
37308
37352
  }
37309
37353
  if (tournamentPublishStatus?.scheduledDates?.length) {
37310
- if (!params.matchUpFilters)
37311
- params.matchUpFilters = {};
37354
+ params.matchUpFilters ??= {};
37312
37355
  if (params.matchUpFilters.scheduledDates) {
37313
- if (!params.matchUpFilters.scheduledDates.length) {
37314
- params.matchUpFilters.scheduledDates = tournamentPublishStatus.scheduledDates;
37356
+ if (params.matchUpFilters.scheduledDates.length) {
37357
+ params.matchUpFilters.scheduledDates = params.matchUpFilters.scheduledDates.filter((scheduledDate) => tournamentPublishStatus.scheduledDates.includes(scheduledDate));
37315
37358
  }
37316
37359
  else {
37317
- params.matchUpFilters.scheduledDates = params.matchUpFilters.scheduledDates.filter((scheduledDate) => tournamentPublishStatus.scheduledDates.includes(scheduledDate));
37360
+ params.matchUpFilters.scheduledDates = tournamentPublishStatus.scheduledDates;
37318
37361
  }
37319
37362
  }
37320
37363
  else {
@@ -37322,8 +37365,7 @@ function competitionScheduleMatchUps(params) {
37322
37365
  }
37323
37366
  }
37324
37367
  if (alwaysReturnCompleted) {
37325
- if (!params.matchUpFilters)
37326
- params.matchUpFilters = {};
37368
+ params.matchUpFilters ??= {};
37327
37369
  if (params.matchUpFilters?.excludeMatchUpStatuses?.length) {
37328
37370
  if (!params.matchUpFilters.excludeMatchUpStatuses.includes(COMPLETED$1)) {
37329
37371
  params.matchUpFilters.excludeMatchUpStatuses.push(COMPLETED$1);
@@ -37390,7 +37432,7 @@ function competitionScheduleMatchUps(params) {
37390
37432
  };
37391
37433
  if (withCourtGridRows) {
37392
37434
  const { rows, courtPrefix } = courtGridRows({
37393
- minRowsCount: minCourtGridRows,
37435
+ minRowsCount: Math.max(minCourtGridRows || 0, dateMatchUps.length || 0),
37394
37436
  courtsData,
37395
37437
  });
37396
37438
  result.courtPrefix = courtPrefix;
@@ -51976,7 +52018,7 @@ function generateTournamentRecord(params) {
51976
52018
  return result;
51977
52019
  }
51978
52020
  if (params.drawProfiles) {
51979
- const result = processDrawProfiles({
52021
+ const result = processDrawProfiles$1({
51980
52022
  allUniqueParticipantIds,
51981
52023
  ratingsParameters: ratingsParameters$1,
51982
52024
  tournamentRecord,
@@ -51988,7 +52030,7 @@ function generateTournamentRecord(params) {
51988
52030
  return result;
51989
52031
  }
51990
52032
  if (params.eventProfiles) {
51991
- const result = processEventProfiles({
52033
+ const result = processEventProfiles$1({
51992
52034
  allUniqueParticipantIds,
51993
52035
  ratingsParameters: ratingsParameters$1,
51994
52036
  tournamentRecord,
@@ -52013,7 +52055,7 @@ function generateTournamentRecord(params) {
52013
52055
  drawIds,
52014
52056
  });
52015
52057
  }
52016
- function processDrawProfiles(params) {
52058
+ function processDrawProfiles$1(params) {
52017
52059
  const { tournamentRecord, drawProfiles, allUniqueParticipantIds, eventIds, drawIds } = params;
52018
52060
  let drawIndex = 0;
52019
52061
  for (const drawProfile of drawProfiles) {
@@ -52045,7 +52087,7 @@ function processDrawProfiles(params) {
52045
52087
  drawIndex += 1;
52046
52088
  }
52047
52089
  }
52048
- function processEventProfiles(params) {
52090
+ function processEventProfiles$1(params) {
52049
52091
  const { eventProfiles, allUniqueParticipantIds, eventIds, drawIds } = params;
52050
52092
  let eventIndex = 0;
52051
52093
  for (const eventProfile of eventProfiles) {
@@ -52372,164 +52414,150 @@ function generatePairParticipantName({ individualParticipantIds, individualParti
52372
52414
  return participantName;
52373
52415
  }
52374
52416
 
52375
- function modifyTournamentRecord(params) {
52376
- const { ratingsParameters: ratingsParameters$1 = ratingsParameters, participantsProfile = {}, matchUpStatusProfile, completeAllMatchUps, autoEntryPositions, hydrateCollections, randomWinningSide, schedulingProfile, tournamentRecord, autoSchedule, eventProfiles, periodLength, venueProfiles, drawProfiles, isMock, uuids, } = params;
52377
- if (!tournamentRecord)
52378
- return { error: MISSING_TOURNAMENT_RECORD };
52379
- const allUniqueParticipantIds = [];
52380
- const eventIds = [];
52381
- const drawIds = [];
52382
- eventProfiles?.forEach((eventProfile) => {
52383
- const event = tournamentRecord.events?.find((event, index) => (eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex) ||
52384
- (eventProfile.eventName && event.eventName === eventProfile.eventName) ||
52385
- (eventProfile.eventId && event.eventId === eventProfile.eventId));
52386
- if (event?.gender) {
52387
- eventProfile.gender = event.gender;
52388
- }
52389
- });
52390
- const participantsCount = tournamentRecord.participants?.length || undefined;
52391
- if (participantsCount && participantsProfile?.idPrefix) {
52392
- 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);
52393
52471
  }
52394
- const result = addTournamentParticipants({
52395
- startDate: tournamentRecord.startDate,
52396
- participantsProfile,
52397
- tournamentRecord,
52398
- eventProfiles,
52399
- drawProfiles,
52400
- uuids,
52401
- });
52402
- if (!result.success)
52403
- return result;
52404
- if (eventProfiles) {
52405
- let eventIndex = tournamentRecord.events?.length || 0;
52406
- for (const eventProfile of eventProfiles) {
52407
- const { ratingsParameters } = eventProfile;
52408
- const event = tournamentRecord.events?.find((event, index) => (eventProfile.eventIndex !== undefined && index === eventProfile.eventIndex) ||
52409
- (eventProfile.eventName && event.eventName === eventProfile.eventName) ||
52410
- (eventProfile.eventId && event.eventId === eventProfile.eventId));
52411
- if (!event) {
52412
- const result = generateEventWithFlights({
52413
- startDate: tournamentRecord.startDate,
52414
- allUniqueParticipantIds,
52415
- matchUpStatusProfile,
52416
- participantsProfile,
52417
- completeAllMatchUps,
52418
- autoEntryPositions,
52419
- randomWinningSide,
52420
- ratingsParameters,
52421
- tournamentRecord,
52422
- eventProfile,
52423
- eventIndex,
52424
- uuids,
52425
- });
52426
- if (result.error)
52427
- return result;
52428
- const { eventId, drawIds: generatedDrawIds, uniqueParticipantIds } = result;
52429
- if (generatedDrawIds)
52430
- drawIds.push(...generatedDrawIds);
52431
- eventIds.push(eventId);
52432
- if (uniqueParticipantIds?.length)
52433
- allUniqueParticipantIds.push(...uniqueParticipantIds);
52434
- eventIndex += 1;
52435
- }
52436
- else {
52437
- const { gender, category, eventType } = event;
52438
- const { drawProfiles, publish } = eventProfile;
52439
- const eventParticipantType = (isMatchUpEventType(SINGLES)(eventType) && INDIVIDUAL) ||
52440
- (isMatchUpEventType(DOUBLES)(eventType) && PAIR) ||
52441
- eventType;
52442
- if (drawProfiles) {
52443
- const { stageParticipantsCount, uniqueParticipantsCount, uniqueParticipantStages } = getStageParticipantsCount({
52444
- drawProfiles,
52445
- category,
52446
- gender,
52447
- });
52448
- const { uniqueDrawParticipants = [], uniqueParticipantIds = [] } = uniqueParticipantStages
52449
- ? generateEventParticipants({
52450
- event: { eventType, category, gender },
52451
- uniqueParticipantsCount,
52452
- participantsProfile,
52453
- ratingsParameters,
52454
- tournamentRecord,
52455
- eventProfile,
52456
- uuids,
52457
- })
52458
- : {};
52459
- allUniqueParticipantIds.push(...uniqueParticipantIds);
52460
- const { stageParticipants } = getStageParticipants({
52461
- targetParticipants: tournamentRecord.participants || [],
52462
- allUniqueParticipantIds,
52463
- stageParticipantsCount,
52464
- eventParticipantType,
52465
- });
52466
- let result = generateFlights({
52467
- uniqueDrawParticipants,
52468
- autoEntryPositions,
52469
- stageParticipants,
52470
- tournamentRecord,
52471
- drawProfiles,
52472
- category,
52473
- gender,
52474
- event,
52475
- });
52476
- if (result.error)
52477
- return result;
52478
- result = generateFlightDrawDefinitions({
52479
- matchUpStatusProfile,
52480
- completeAllMatchUps,
52481
- randomWinningSide,
52482
- tournamentRecord,
52483
- drawProfiles,
52484
- isMock,
52485
- event,
52486
- });
52487
- if (result.error)
52488
- return result;
52489
- drawIds.push(...result.drawIds);
52490
- }
52491
- if (publish) {
52492
- publishEvent({ tournamentRecord, event });
52493
- }
52494
- }
52495
- }
52472
+ if (publish) {
52473
+ publishEvent({ tournamentRecord, event });
52496
52474
  }
52497
- if (drawProfiles) {
52498
- let drawIndex = (tournamentRecord.events || [])
52499
- .map((event) => event.drawDefinitions?.map(() => 1) || [])
52500
- .flat()
52501
- .reduce((a, b) => a + b, 0);
52502
- for (const drawProfile of drawProfiles) {
52503
- let result = generateEventWithDraw({
52504
- startDate: tournamentRecord.startDate,
52505
- allUniqueParticipantIds,
52506
- matchUpStatusProfile,
52507
- participantsProfile,
52508
- completeAllMatchUps,
52509
- autoEntryPositions,
52510
- hydrateCollections,
52511
- randomWinningSide,
52512
- 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 },
52513
52490
  tournamentRecord,
52514
- drawProfile,
52515
- drawIndex,
52516
- uuids,
52491
+ allUniqueParticipantIds,
52492
+ drawIds,
52517
52493
  });
52518
52494
  if (result.error)
52519
52495
  return result;
52520
- const { drawId, eventId, event, uniqueParticipantIds } = result;
52521
- 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
+ });
52522
52512
  if (result.error)
52523
52513
  return result;
52524
- if (drawId)
52525
- drawIds.push(drawId);
52514
+ const { eventId, drawIds: generatedDrawIds, uniqueParticipantIds } = result;
52515
+ if (generatedDrawIds)
52516
+ drawIds.push(...generatedDrawIds);
52526
52517
  eventIds.push(eventId);
52527
52518
  if (uniqueParticipantIds?.length)
52528
52519
  allUniqueParticipantIds.push(...uniqueParticipantIds);
52529
- drawIndex += 1;
52520
+ eventIndex += 1;
52530
52521
  }
52531
52522
  }
52532
- 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 }) {
52533
52561
  let scheduledRounds;
52534
52562
  let schedulerResult = {};
52535
52563
  if (schedulingProfile?.length) {
@@ -52551,6 +52579,69 @@ function modifyTournamentRecord(params) {
52551
52579
  });
52552
52580
  }
52553
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;
52554
52645
  const totalParticipantsCount = tournamentRecord.participants.length;
52555
52646
  return {
52556
52647
  totalParticipantsCount,