tods-competition-factory 1.6.10 → 1.6.12

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.
@@ -3185,7 +3185,7 @@ function structureSort(a, b, config) {
3185
3185
  const completedStructure = (s) => s?.matchUps.every(
3186
3186
  ({ matchUpStatus }) => completedMatchUpStatuses.includes(matchUpStatus) ? 1 : -1
3187
3187
  );
3188
- return completed && completedStructure(a) - completedStructure(b) || aggregate && protocolSequence(a) - protocolSequence(b) || (a?.stage && orderProtocol[a.stage] || 0) - (b?.stage && orderProtocol[b.stage] || 0) || (getRoundTarget(a) || 0) - (getRoundTarget(b) || 0) || !finish && !aggregate && (b?.positionAssignments?.length || Infinity) - (a?.positionAssignments?.length || Infinity) || (a?.stageSequence || 0) - (b?.stageSequence || 0) || (getMinFinishingPositionRange(a) || 0) - (getMinFinishingPositionRange(b) || 0);
3188
+ return completed && completedStructure(a) - completedStructure(b) || aggregate && protocolSequence(a) - protocolSequence(b) || (a?.stage && orderProtocol[a.stage] || 0) - (b?.stage && orderProtocol[b.stage] || 0) || (getRoundTarget(a) || 0) - (getRoundTarget(b) || 0) || !finish && !aggregate && (b?.positionAssignments?.length ?? Infinity) - (a?.positionAssignments?.length ?? Infinity) || (a?.stageSequence ?? 0) - (b?.stageSequence ?? 0) || (getMinFinishingPositionRange(a) || 0) - (getMinFinishingPositionRange(b) || 0);
3189
3189
  }
3190
3190
  function getMinFinishingPositionRange(structure) {
3191
3191
  return (structure?.matchUps || []).reduce((rangeSum, matchUp) => {
@@ -3327,6 +3327,7 @@ function getStageEntryTypeCount({ stage, drawDefinition, entryStatus }) {
3327
3327
  }
3328
3328
  function getStageEntries({
3329
3329
  provisionalPositioning,
3330
+ placementGroup,
3330
3331
  drawDefinition,
3331
3332
  stageSequence,
3332
3333
  entryStatuses,
@@ -3356,7 +3357,9 @@ function getStageEntries({
3356
3357
  if (error) {
3357
3358
  console.log("playoff entries error");
3358
3359
  }
3359
- return playoffEntries?.length ? playoffEntries : entries;
3360
+ return (playoffEntries?.length ? playoffEntries : entries).filter(
3361
+ (entry) => !placementGroup || entry.placementGroup === placementGroup
3362
+ );
3360
3363
  }
3361
3364
  return entries;
3362
3365
  }
@@ -5304,7 +5307,7 @@ function getValidSeedBlocks({
5304
5307
  });
5305
5308
  const { positionAssignments } = structureAssignedDrawPositions({ structure });
5306
5309
  const positionsCount = positionAssignments?.length;
5307
- const seedsCount = seedAssignments?.length || 0;
5310
+ const seedsCount = seedAssignments?.length ?? 0;
5308
5311
  let allDrawPositions = [];
5309
5312
  const roundNumbers = Object.keys(roundMatchUps).map((n) => parseInt(n)).sort((a, b) => a - b);
5310
5313
  const uniqueDrawPositionsByRound = roundNumbers.map((roundNumber) => {
@@ -5566,7 +5569,7 @@ function getNextSeedBlock(params) {
5566
5569
  const seedsWithoutDrawPositions = seedAssignments?.filter(
5567
5570
  (assignment) => !assignment.participantId
5568
5571
  );
5569
- const seedsLeftToAssign = unplacedSeedAssignments?.length || seedsWithoutDrawPositions?.length;
5572
+ const seedsLeftToAssign = unplacedSeedAssignments?.length && unplacedSeedAssignments.length > 0 ? unplacedSeedAssignments.length : seedsWithoutDrawPositions?.length ?? 0;
5570
5573
  const unfilled = seedsLeftToAssign && nextSeedBlock?.drawPositions.filter(
5571
5574
  (drawPosition) => !assignedDrawPositions?.includes(drawPosition)
5572
5575
  ) || [];
@@ -12805,6 +12808,7 @@ function automatedPositioning$1({
12805
12808
  placeByes = true,
12806
12809
  tournamentRecord,
12807
12810
  appliedPolicies,
12811
+ placementGroup,
12808
12812
  drawDefinition,
12809
12813
  seedingProfile,
12810
12814
  participants,
@@ -12856,6 +12860,7 @@ function automatedPositioning$1({
12856
12860
  stageSequence: structure.stageSequence,
12857
12861
  provisionalPositioning,
12858
12862
  stage: structure.stage,
12863
+ placementGroup,
12859
12864
  drawDefinition,
12860
12865
  entryStatuses,
12861
12866
  structureId
@@ -13103,10 +13108,12 @@ function automatedPlayoffPositioning(params) {
13103
13108
  if (!structureIsComplete && !provisionalPositioning) {
13104
13109
  return { error: INCOMPLETE_SOURCE_STRUCTURE };
13105
13110
  }
13106
- const { playoffStructures } = getPlayoffStructures({
13111
+ const playoffStructures = getPlayoffStructures({
13107
13112
  drawDefinition,
13108
13113
  structureId
13109
- });
13114
+ }).playoffStructures?.sort(
13115
+ (a, b) => getMinFinishingPositionRange(a) - getMinFinishingPositionRange(b)
13116
+ );
13110
13117
  const structurePositionAssignments = [];
13111
13118
  const participants = tournamentRecord?.participants;
13112
13119
  if (playoffStructures) {
@@ -14337,10 +14344,10 @@ function processPlayoffGroups({
14337
14344
  finishingPositionOffset = Math.min(...positionsPlayedOff) - 1;
14338
14345
  }
14339
14346
  const params = {
14347
+ structureId: playoffGroup.structureId ?? uuids?.pop(),
14340
14348
  structureName: playoffGroup.structureName,
14341
14349
  idPrefix: idPrefix && `${idPrefix}-po`,
14342
14350
  appliedPolicies: policyDefinitions,
14343
- structureId: uuids?.pop(),
14344
14351
  finishingPositionOffset,
14345
14352
  stage: PLAY_OFF,
14346
14353
  stageSequence,
@@ -14376,9 +14383,9 @@ function processPlayoffGroups({
14376
14383
  uuids
14377
14384
  });
14378
14385
  const playoffStructure = structureTemplate({
14386
+ structureId: playoffGroup.structureId ?? uuids?.pop(),
14379
14387
  structureName: playoffGroup.structureName,
14380
14388
  matchUpFormat: playoffMatchUpFormat,
14381
- structureId: uuids?.pop(),
14382
14389
  stage: PLAY_OFF,
14383
14390
  stageSequence,
14384
14391
  matchUps
@@ -14398,6 +14405,7 @@ function processPlayoffGroups({
14398
14405
  } else if ([COMPASS, OLYMPIC, PLAY_OFF].includes(playoffDrawType)) {
14399
14406
  const { structureName } = playoffGroup;
14400
14407
  const params2 = {
14408
+ structureId: playoffGroup.structureId ?? uuids?.pop(),
14401
14409
  playoffStructureNameBase: structureName,
14402
14410
  idPrefix: idPrefix && `${idPrefix}-po`,
14403
14411
  addNameBaseToAttributeName: true,
@@ -14451,6 +14459,7 @@ function processPlayoffGroups({
14451
14459
  ].includes(playoffDrawType)) {
14452
14460
  const uuidsFMLC = [uuids?.pop(), uuids?.pop()];
14453
14461
  const params2 = {
14462
+ structureId: playoffGroup.structureId ?? uuids?.pop(),
14454
14463
  structureName: playoffGroup.structureName,
14455
14464
  idPrefix: idPrefix && `${idPrefix}-po`,
14456
14465
  finishingPositionOffset,
@@ -14498,9 +14507,9 @@ function processPlayoffGroups({
14498
14507
  updateStructureAndLinks({ playoffStructures, playoffLinks });
14499
14508
  } else if ([AD_HOC].includes(playoffDrawType)) {
14500
14509
  const structure = structureTemplate({
14510
+ structureId: playoffGroup.structureId ?? uuids?.pop(),
14501
14511
  structureName: playoffGroup.structureName,
14502
14512
  finishingPosition: WIN_RATIO$1,
14503
- structureId: uuids?.pop(),
14504
14513
  stage: PLAY_OFF,
14505
14514
  stageSequence,
14506
14515
  matchUps: []
@@ -14682,6 +14691,7 @@ function addNotes(params) {
14682
14691
  }
14683
14692
 
14684
14693
  const FORMAT_STANDARD = "SET3-S:6/TB7";
14694
+ const FORMAT_ATP_DOUBLES = "SET3-S:6/TB7-F:TB10";
14685
14695
 
14686
14696
  function countSets({
14687
14697
  winningSide: matchUpWinningSide,
@@ -14909,7 +14919,7 @@ function getParticipantResults({
14909
14919
  const manualGamesOverride = tieFormat && matchUp._disableAutoCalc && tieFormat.collectionDefinitions.every(({ scoreValue }) => scoreValue);
14910
14920
  const winningParticipantId = winningSide && getWinningSideId(matchUp);
14911
14921
  const losingParticipantId = winningSide && getLosingSideId(matchUp);
14912
- if (!winningParticipantId || !losingParticipantId) {
14922
+ if (!winningParticipantId && !losingParticipantId) {
14913
14923
  if (completedMatchUpStatuses.includes(matchUpStatus)) {
14914
14924
  const participantIdSide1 = getSideId(matchUp, 0);
14915
14925
  const participantIdSide2 = getSideId(matchUp, 1);
@@ -14921,53 +14931,51 @@ function getParticipantResults({
14921
14931
  checkInitializeParticipant(participantResults, participantIdSide2);
14922
14932
  participantResults[participantIdSide2].matchUpsCancelled += 1;
14923
14933
  }
14924
- } else {
14925
- if (tieMatchUps?.length) {
14926
- perPlayer = 0;
14927
- for (const tieMatchUp of tieMatchUps) {
14928
- if (tieMatchUp.winningSide) {
14929
- const tieWinningParticipantId = sides.find(
14930
- ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
14931
- )?.participantId;
14932
- const tieLosingParticipantId = sides.find(
14933
- ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
14934
- )?.participantId;
14935
- if (tieWinningParticipantId && tieLosingParticipantId) {
14936
- checkInitializeParticipant(
14937
- participantResults,
14938
- tieWinningParticipantId
14939
- );
14940
- checkInitializeParticipant(
14941
- participantResults,
14942
- tieLosingParticipantId
14943
- );
14944
- participantResults[tieWinningParticipantId].tieMatchUpsWon += 1;
14945
- participantResults[tieLosingParticipantId].tieMatchUpsLost += 1;
14946
- if (tieMatchUp.matchUpType === SINGLES$1) {
14947
- participantResults[tieWinningParticipantId].tieSinglesWon += 1;
14948
- participantResults[tieLosingParticipantId].tieSinglesLost += 1;
14949
- } else if (tieMatchUp.matchUpType === DOUBLES$1) {
14950
- participantResults[tieWinningParticipantId].tieDoublesWon += 1;
14951
- participantResults[tieLosingParticipantId].tieDoublesLost += 1;
14952
- }
14934
+ } else if (tieMatchUps?.length) {
14935
+ perPlayer = 0;
14936
+ for (const tieMatchUp of tieMatchUps) {
14937
+ if (tieMatchUp.winningSide) {
14938
+ const tieWinningParticipantId = sides.find(
14939
+ ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
14940
+ )?.participantId;
14941
+ const tieLosingParticipantId = sides.find(
14942
+ ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
14943
+ )?.participantId;
14944
+ if (tieWinningParticipantId && tieLosingParticipantId) {
14945
+ checkInitializeParticipant(
14946
+ participantResults,
14947
+ tieWinningParticipantId
14948
+ );
14949
+ checkInitializeParticipant(
14950
+ participantResults,
14951
+ tieLosingParticipantId
14952
+ );
14953
+ participantResults[tieWinningParticipantId].tieMatchUpsWon += 1;
14954
+ participantResults[tieLosingParticipantId].tieMatchUpsLost += 1;
14955
+ if (tieMatchUp.matchUpType === SINGLES$1) {
14956
+ participantResults[tieWinningParticipantId].tieSinglesWon += 1;
14957
+ participantResults[tieLosingParticipantId].tieSinglesLost += 1;
14958
+ } else if (tieMatchUp.matchUpType === DOUBLES$1) {
14959
+ participantResults[tieWinningParticipantId].tieDoublesWon += 1;
14960
+ participantResults[tieLosingParticipantId].tieDoublesLost += 1;
14953
14961
  }
14954
14962
  }
14955
- processScore({
14956
- score: tieMatchUp.score,
14957
- manualGamesOverride,
14958
- participantResults,
14959
- sides
14960
- // use sides from the TEAM matchUp
14961
- });
14962
14963
  }
14963
- } else {
14964
14964
  processScore({
14965
+ score: tieMatchUp.score,
14965
14966
  manualGamesOverride,
14966
14967
  participantResults,
14967
- score,
14968
14968
  sides
14969
+ // use sides from the TEAM matchUp
14969
14970
  });
14970
14971
  }
14972
+ } else {
14973
+ processScore({
14974
+ manualGamesOverride,
14975
+ participantResults,
14976
+ score,
14977
+ sides
14978
+ });
14971
14979
  }
14972
14980
  } else {
14973
14981
  checkInitializeParticipant(participantResults, winningParticipantId);
@@ -15817,9 +15825,8 @@ function modifyMatchUpScore({
15817
15825
  return { error: MATCHUP_NOT_FOUND };
15818
15826
  ({ matchUp, structure } = findResult);
15819
15827
  }
15820
- } else {
15821
- if (matchUp.matchUpId !== matchUpId)
15822
- console.log("!!!!!");
15828
+ } else if (matchUp.matchUpId !== matchUpId) {
15829
+ console.log("!!!!!");
15823
15830
  }
15824
15831
  if (matchUpStatus && [WALKOVER$1, DOUBLE_WALKOVER].includes(matchUpStatus) || removeScore) {
15825
15832
  Object.assign(matchUp, { ...toBePlayed });
@@ -15857,31 +15864,45 @@ function modifyMatchUpScore({
15857
15864
  })?.appliedPolicies;
15858
15865
  defaultedProcessCodes = appliedPolicies?.[POLICY_TYPE_SCORING]?.processCodes?.incompleteAssignmentsOnDefault;
15859
15866
  }
15860
- if (structure?.structureType === CONTAINER && !matchUp.collectionId) {
15861
- matchUpFormat = isDualMatchUp ? "SET1-S:T100" : matchUpFormat || matchUp.matchUpFormat || structure?.matchUpFormat || drawDefinition?.matchUpFormat || event?.matchUpFormat;
15862
- const itemStructure = structure.structures.find((itemStructure2) => {
15863
- return itemStructure2?.matchUps.find(
15864
- (matchUp2) => matchUp2.matchUpId === matchUpId
15865
- );
15866
- });
15867
- const matchUpFilters = isDualMatchUp ? { matchUpTypes: [TEAM$2] } : void 0;
15868
- const { matchUps } = getAllStructureMatchUps({
15869
- afterRecoveryTimes: false,
15870
- structure: itemStructure,
15871
- inContext: true,
15872
- matchUpFilters,
15873
- event
15874
- });
15875
- const result = updateAssignmentParticipantResults({
15876
- positionAssignments: itemStructure.positionAssignments,
15877
- tournamentRecord,
15878
- drawDefinition,
15879
- matchUpFormat,
15880
- matchUps,
15881
- event
15882
- });
15883
- if (result.error)
15884
- return decorateResult({ result, stack });
15867
+ if (!matchUp.collectionId) {
15868
+ const isRoundRobin = structure?.structureType === CONTAINER;
15869
+ const isAdHocStructure = isAdHoc({ drawDefinition, structure });
15870
+ if (isLucky({ drawDefinition, structure }) || isAdHocStructure || isRoundRobin) {
15871
+ const updateTally = (structure2) => {
15872
+ matchUpFormat = isDualMatchUp ? "SET1-S:T100" : matchUpFormat ?? matchUp.matchUpFormat ?? structure2?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
15873
+ const matchUpFilters = isDualMatchUp ? { matchUpTypes: [TEAM$2] } : void 0;
15874
+ const { matchUps } = getAllStructureMatchUps({
15875
+ afterRecoveryTimes: false,
15876
+ inContext: true,
15877
+ matchUpFilters,
15878
+ structure: structure2,
15879
+ event
15880
+ });
15881
+ if (isAdHocStructure) {
15882
+ structure2.positionAssignments = unique(
15883
+ matchUps.flatMap(
15884
+ (matchUp2) => (matchUp2.sides ?? []).map((side) => side.participantId)
15885
+ ).filter(Boolean)
15886
+ ).map((participantId) => ({ participantId }));
15887
+ }
15888
+ return updateAssignmentParticipantResults({
15889
+ positionAssignments: structure2.positionAssignments,
15890
+ tournamentRecord,
15891
+ drawDefinition,
15892
+ matchUpFormat,
15893
+ matchUps,
15894
+ event
15895
+ });
15896
+ };
15897
+ const itemStructure = isRoundRobin && structure.structures.find((itemStructure2) => {
15898
+ return itemStructure2?.matchUps.find(
15899
+ (matchUp2) => matchUp2.matchUpId === matchUpId
15900
+ );
15901
+ });
15902
+ const result = updateTally(itemStructure || structure);
15903
+ if (result.error)
15904
+ return decorateResult({ result, stack });
15905
+ }
15885
15906
  }
15886
15907
  if (notes) {
15887
15908
  const result = addNotes({ element: matchUp, notes });
@@ -17202,9 +17223,9 @@ function generateAndPopulatePlayoffStructures(params) {
17202
17223
  structureId: sourceStructureId,
17203
17224
  addNameBaseToAttributeName,
17204
17225
  playoffStructureNameBase,
17205
- tournamentRecord,
17206
17226
  playoffAttributes,
17207
17227
  playoffPositions,
17228
+ tournamentRecord,
17208
17229
  exitProfileLimit,
17209
17230
  roundProfiles,
17210
17231
  roundNumbers,
@@ -17279,7 +17300,7 @@ function generateAndPopulatePlayoffStructures(params) {
17279
17300
  const roundsRanges = validRoundNumbers ? availablePlayoffRoundsRanges : playoffRoundsRanges;
17280
17301
  const newStructures = [];
17281
17302
  const newLinks = [];
17282
- for (const roundNumber of sourceRounds || []) {
17303
+ for (const roundNumber of sourceRounds ?? []) {
17283
17304
  const roundInfo = roundsRanges?.find(
17284
17305
  (roundInfo2) => roundInfo2.roundNumber === roundNumber
17285
17306
  );
@@ -20275,6 +20296,124 @@ function addDrawDefinition(params) {
20275
20296
  return { ...SUCCESS, modifiedEventEntryStatusCount };
20276
20297
  }
20277
20298
 
20299
+ function generateAdHocMatchUps({
20300
+ participantIdPairings,
20301
+ addToStructure = true,
20302
+ tournamentRecord,
20303
+ matchUpIds = [],
20304
+ drawDefinition,
20305
+ matchUpsCount,
20306
+ roundNumber,
20307
+ structureId,
20308
+ newRound
20309
+ }) {
20310
+ if (typeof drawDefinition !== "object")
20311
+ return { error: MISSING_DRAW_DEFINITION };
20312
+ if (!structureId && drawDefinition.structures?.length === 1)
20313
+ structureId = drawDefinition.structures?.[0]?.structureId;
20314
+ if (typeof structureId !== "string")
20315
+ return { error: MISSING_STRUCTURE_ID };
20316
+ if (participantIdPairings && !Array.isArray(participantIdPairings) || matchUpsCount && !isConvertableInteger(matchUpsCount) || matchUpIds && !Array.isArray(matchUpIds) || !participantIdPairings && !matchUpsCount) {
20317
+ return { error: INVALID_VALUES, info: "matchUpsCount or pairings error" };
20318
+ }
20319
+ const structure = drawDefinition?.structures?.find(
20320
+ (structure2) => structure2.structureId === structureId
20321
+ );
20322
+ let structureHasRoundPositions;
20323
+ const existingMatchUps = structure?.matchUps;
20324
+ const lastRoundNumber = existingMatchUps?.reduce(
20325
+ (roundNumber2, matchUp) => {
20326
+ if (matchUp.roundPosition)
20327
+ structureHasRoundPositions = true;
20328
+ return (matchUp?.roundNumber || 0) > roundNumber2 ? matchUp.roundNumber : roundNumber2;
20329
+ },
20330
+ 0
20331
+ );
20332
+ if (structure?.structures || structureHasRoundPositions || structure?.finishingPosition === ROUND_OUTCOME) {
20333
+ return { error: INVALID_STRUCTURE };
20334
+ }
20335
+ if (roundNumber && roundNumber - 1 > (lastRoundNumber || 0))
20336
+ return { error: INVALID_VALUES, info: "roundNumber error" };
20337
+ const nextRoundNumber = roundNumber ?? (newRound ? (lastRoundNumber ?? 0) + 1 : lastRoundNumber ?? 1);
20338
+ participantIdPairings = participantIdPairings ?? generateRange(0, matchUpsCount).map(() => ({
20339
+ participantIds: [void 0, void 0]
20340
+ }));
20341
+ const matchUps = participantIdPairings?.map((pairing) => {
20342
+ const idStack = pairing?.participantIds ?? [void 0, void 0];
20343
+ idStack.push(...[void 0, void 0]);
20344
+ const participantIds = idStack.slice(0, 2);
20345
+ const sides = participantIds.map(
20346
+ (participantId, i) => definedAttributes({
20347
+ sideNumber: i + 1,
20348
+ participantId
20349
+ })
20350
+ );
20351
+ return {
20352
+ matchUpStatus: MatchUpStatusEnum.ToBePlayed,
20353
+ matchUpId: matchUpIds.pop() ?? UUID(),
20354
+ roundNumber: nextRoundNumber,
20355
+ sides
20356
+ };
20357
+ });
20358
+ if (addToStructure) {
20359
+ const result = addAdHocMatchUps({
20360
+ tournamentRecord,
20361
+ drawDefinition,
20362
+ structureId,
20363
+ matchUps
20364
+ });
20365
+ if (result.error)
20366
+ return result;
20367
+ }
20368
+ return { matchUpsCount: matchUps.length, matchUps, ...SUCCESS };
20369
+ }
20370
+ function addAdHocMatchUps({
20371
+ tournamentRecord,
20372
+ drawDefinition,
20373
+ structureId,
20374
+ matchUps
20375
+ }) {
20376
+ if (typeof drawDefinition !== "object")
20377
+ return { error: MISSING_DRAW_DEFINITION };
20378
+ if (!structureId && drawDefinition.structures?.length === 1)
20379
+ structureId = drawDefinition.structures?.[0]?.structureId;
20380
+ if (typeof structureId !== "string")
20381
+ return { error: MISSING_STRUCTURE_ID };
20382
+ if (!validMatchUps(matchUps))
20383
+ return { error: INVALID_VALUES, info: mustBeAnArray("matchUps") };
20384
+ const structure = drawDefinition.structures?.find(
20385
+ (structure2) => structure2.structureId === structureId
20386
+ );
20387
+ if (!structure)
20388
+ return { error: STRUCTURE_NOT_FOUND };
20389
+ const existingMatchUps = structure?.matchUps;
20390
+ const structureHasRoundPositions = existingMatchUps.find(
20391
+ (matchUp) => !!matchUp.roundPosition
20392
+ );
20393
+ if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
20394
+ return { error: INVALID_STRUCTURE };
20395
+ }
20396
+ const existingMatchUpIds = allTournamentMatchUps({
20397
+ tournamentRecord,
20398
+ inContext: false
20399
+ })?.matchUps?.map(getMatchUpId) ?? [];
20400
+ const newMatchUpIds = matchUps.map(getMatchUpId);
20401
+ if (overlap(existingMatchUpIds, newMatchUpIds)) {
20402
+ return {
20403
+ error: EXISTING_MATCHUP_ID,
20404
+ info: "One or more matchUpIds already present in tournamentRecord"
20405
+ };
20406
+ }
20407
+ structure.matchUps.push(...matchUps);
20408
+ addMatchUpsNotice({
20409
+ tournamentId: tournamentRecord?.tournamentId,
20410
+ drawDefinition,
20411
+ matchUps
20412
+ });
20413
+ modifyDrawNotice({ drawDefinition, structureIds: [structureId] });
20414
+ return { ...SUCCESS };
20415
+ }
20416
+
20278
20417
  function attachPolicies({ drawDefinition, policyDefinitions }) {
20279
20418
  if (!drawDefinition) {
20280
20419
  return { error: MISSING_DRAW_DEFINITION };
@@ -20588,124 +20727,6 @@ function pairingHash(id1, id2) {
20588
20727
  return [id1, id2].sort().join("|");
20589
20728
  }
20590
20729
 
20591
- function generateAdHocMatchUps({
20592
- participantIdPairings,
20593
- addToStructure = true,
20594
- tournamentRecord,
20595
- matchUpIds = [],
20596
- drawDefinition,
20597
- matchUpsCount,
20598
- roundNumber,
20599
- structureId,
20600
- newRound
20601
- }) {
20602
- if (typeof drawDefinition !== "object")
20603
- return { error: MISSING_DRAW_DEFINITION };
20604
- if (!structureId && drawDefinition.structures?.length === 1)
20605
- structureId = drawDefinition.structures?.[0]?.structureId;
20606
- if (typeof structureId !== "string")
20607
- return { error: MISSING_STRUCTURE_ID };
20608
- if (participantIdPairings && !Array.isArray(participantIdPairings) || matchUpsCount && !isConvertableInteger(matchUpsCount) || matchUpIds && !Array.isArray(matchUpIds) || !participantIdPairings && !matchUpsCount) {
20609
- return { error: INVALID_VALUES, info: "matchUpsCount or pairings error" };
20610
- }
20611
- const structure = drawDefinition?.structures?.find(
20612
- (structure2) => structure2.structureId === structureId
20613
- );
20614
- let structureHasRoundPositions;
20615
- const existingMatchUps = structure?.matchUps;
20616
- const lastRoundNumber = existingMatchUps?.reduce(
20617
- (roundNumber2, matchUp) => {
20618
- if (matchUp.roundPosition)
20619
- structureHasRoundPositions = true;
20620
- return (matchUp?.roundNumber || 0) > roundNumber2 ? matchUp.roundNumber : roundNumber2;
20621
- },
20622
- 0
20623
- );
20624
- if (structure?.structures || structureHasRoundPositions || structure?.finishingPosition === ROUND_OUTCOME) {
20625
- return { error: INVALID_STRUCTURE };
20626
- }
20627
- if (roundNumber && roundNumber - 1 > (lastRoundNumber || 0))
20628
- return { error: INVALID_VALUES, info: "roundNumber error" };
20629
- const nextRoundNumber = roundNumber ?? (newRound ? (lastRoundNumber ?? 0) + 1 : lastRoundNumber ?? 1);
20630
- participantIdPairings = participantIdPairings ?? generateRange(0, matchUpsCount).map(() => ({
20631
- participantIds: [void 0, void 0]
20632
- }));
20633
- const matchUps = participantIdPairings?.map((pairing) => {
20634
- const idStack = pairing?.participantIds ?? [void 0, void 0];
20635
- idStack.push(...[void 0, void 0]);
20636
- const participantIds = idStack.slice(0, 2);
20637
- const sides = participantIds.map(
20638
- (participantId, i) => definedAttributes({
20639
- sideNumber: i + 1,
20640
- participantId
20641
- })
20642
- );
20643
- return {
20644
- matchUpStatus: MatchUpStatusEnum.ToBePlayed,
20645
- matchUpId: matchUpIds.pop() ?? UUID(),
20646
- roundNumber: nextRoundNumber,
20647
- sides
20648
- };
20649
- });
20650
- if (addToStructure) {
20651
- const result = addAdHocMatchUps({
20652
- tournamentRecord,
20653
- drawDefinition,
20654
- structureId,
20655
- matchUps
20656
- });
20657
- if (result.error)
20658
- return result;
20659
- }
20660
- return { matchUpsCount: matchUps.length, matchUps, ...SUCCESS };
20661
- }
20662
- function addAdHocMatchUps({
20663
- tournamentRecord,
20664
- drawDefinition,
20665
- structureId,
20666
- matchUps
20667
- }) {
20668
- if (typeof drawDefinition !== "object")
20669
- return { error: MISSING_DRAW_DEFINITION };
20670
- if (!structureId && drawDefinition.structures?.length === 1)
20671
- structureId = drawDefinition.structures?.[0]?.structureId;
20672
- if (typeof structureId !== "string")
20673
- return { error: MISSING_STRUCTURE_ID };
20674
- if (!validMatchUps(matchUps))
20675
- return { error: INVALID_VALUES, info: mustBeAnArray("matchUps") };
20676
- const structure = drawDefinition.structures?.find(
20677
- (structure2) => structure2.structureId === structureId
20678
- );
20679
- if (!structure)
20680
- return { error: STRUCTURE_NOT_FOUND };
20681
- const existingMatchUps = structure?.matchUps;
20682
- const structureHasRoundPositions = existingMatchUps.find(
20683
- (matchUp) => !!matchUp.roundPosition
20684
- );
20685
- if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
20686
- return { error: INVALID_STRUCTURE };
20687
- }
20688
- const existingMatchUpIds = allTournamentMatchUps({
20689
- tournamentRecord,
20690
- inContext: false
20691
- })?.matchUps?.map(getMatchUpId) ?? [];
20692
- const newMatchUpIds = matchUps.map(getMatchUpId);
20693
- if (overlap(existingMatchUpIds, newMatchUpIds)) {
20694
- return {
20695
- error: EXISTING_MATCHUP_ID,
20696
- info: "One or more matchUpIds already present in tournamentRecord"
20697
- };
20698
- }
20699
- structure.matchUps.push(...matchUps);
20700
- addMatchUpsNotice({
20701
- tournamentId: tournamentRecord?.tournamentId,
20702
- drawDefinition,
20703
- matchUps
20704
- });
20705
- modifyDrawNotice({ drawDefinition, structureIds: [structureId] });
20706
- return { ...SUCCESS };
20707
- }
20708
-
20709
20730
  const ENCOUNTER_VALUE = 50;
20710
20731
  const SAME_TEAM_VALUE = 60;
20711
20732
  const DEFAULT_RATING = 0;
@@ -21963,7 +21984,6 @@ const USTA_TOC = "USTA_TOC";
21963
21984
  const USTA_WTT_ITT = "USTA_WTT_ITT";
21964
21985
  const USTA_ZONAL = "USTA_ZONAL";
21965
21986
 
21966
- const bestOf3tbSets = "SET3-S:6/TB7";
21967
21987
  const STANDARD = "STANDARD";
21968
21988
  const namedFormats = {
21969
21989
  [STANDARD]: {
@@ -21980,9 +22000,9 @@ const namedFormats = {
21980
22000
  matchUpFormat: "SET1-S:8/TB7@7"
21981
22001
  },
21982
22002
  singles: {
22003
+ matchUpFormat: FORMAT_STANDARD,
21983
22004
  matchUpCount: 6,
21984
- matchUpValue: 1,
21985
- matchUpFormat: bestOf3tbSets
22005
+ matchUpValue: 1
21986
22006
  },
21987
22007
  tieFormatName: COLLEGE_D3,
21988
22008
  valueGoal: 5
@@ -21992,12 +22012,12 @@ const namedFormats = {
21992
22012
  doubles: {
21993
22013
  matchUpCount: 3,
21994
22014
  collectionValue: 1,
21995
- matchUpFormat: bestOf3tbSets
22015
+ matchUpFormat: FORMAT_STANDARD
21996
22016
  },
21997
22017
  singles: {
21998
22018
  matchUpCount: 6,
21999
22019
  matchUpValue: 1,
22000
- matchUpFormat: bestOf3tbSets
22020
+ matchUpFormat: FORMAT_STANDARD
22001
22021
  },
22002
22022
  tieFormatName: COLLEGE_DEFAULT,
22003
22023
  valueGoal: 4
@@ -22012,7 +22032,7 @@ const namedFormats = {
22012
22032
  singles: {
22013
22033
  matchUpCount: 6,
22014
22034
  matchUpValue: 1,
22015
- matchUpFormat: bestOf3tbSets
22035
+ matchUpFormat: FORMAT_STANDARD
22016
22036
  },
22017
22037
  tieFormatName: COLLEGE_JUCO,
22018
22038
  valueGoal: 5
@@ -22052,7 +22072,7 @@ const tieFormatDefaults = (params) => {
22052
22072
  collectionDefinitions: [
22053
22073
  {
22054
22074
  collectionId: uuids?.pop() || UUID(),
22055
- matchUpFormat: "SET3-S:6/TB7-F:TB10",
22075
+ matchUpFormat: FORMAT_ATP_DOUBLES,
22056
22076
  matchUpType: TypeEnum.Doubles,
22057
22077
  collectionName: "Doubles",
22058
22078
  ...template.doubles
@@ -22060,7 +22080,7 @@ const tieFormatDefaults = (params) => {
22060
22080
  {
22061
22081
  collectionId: uuids?.pop() || UUID(),
22062
22082
  matchUpType: TypeEnum.Singles,
22063
- matchUpFormat: bestOf3tbSets,
22083
+ matchUpFormat: FORMAT_STANDARD,
22064
22084
  collectionName: "Singles",
22065
22085
  ...template.singles
22066
22086
  }
@@ -22568,7 +22588,7 @@ function generateDrawDefinition(params) {
22568
22588
  } else if (!matchUpFormat) {
22569
22589
  tieFormat = void 0;
22570
22590
  if (!event?.matchUpFormat) {
22571
- matchUpFormat = "SET3-S:6/TB7";
22591
+ matchUpFormat = FORMAT_STANDARD;
22572
22592
  }
22573
22593
  }
22574
22594
  const invalidDrawId = params.drawId && typeof params.drawId !== "string";