tods-competition-factory 1.6.18 → 1.6.20

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.
@@ -3617,6 +3617,7 @@ function getInContextCourt({
3617
3617
  return { inContextCourt };
3618
3618
  }
3619
3619
 
3620
+ const ADD_DRAW_DEFINITION = "addDrawDefinition";
3620
3621
  const ADD_VENUE = "addVenue";
3621
3622
  const MODIFY_DRAW_DEFINITION = "modifyDrawDefinition";
3622
3623
  const MODIFY_MATCHUP = "modifyMatchUp";
@@ -4470,15 +4471,15 @@ function getRoundMatchUps({
4470
4471
  roundIndex += 1;
4471
4472
  }
4472
4473
  });
4473
- const isNotEliminationStructure = !!Object.values(roundProfile).find(
4474
+ const roundsNotPowerOf2 = !!Object.values(roundProfile).find(
4474
4475
  ({ matchUpsCount }) => !isPowerOf2(matchUpsCount)
4475
4476
  );
4476
4477
  const hasNoRoundPositions = matchUps.some(
4477
4478
  (matchUp) => !matchUp.roundPosition
4478
4479
  );
4479
4480
  return {
4480
- isNotEliminationStructure,
4481
4481
  hasNoRoundPositions,
4482
+ roundsNotPowerOf2,
4482
4483
  maxMatchUpsCount,
4483
4484
  roundMatchUps,
4484
4485
  roundNumbers,
@@ -5505,31 +5506,29 @@ function filterMatchUps(params) {
5505
5506
  }
5506
5507
 
5507
5508
  function isLucky({
5508
- isNotEliminationStructure,
5509
+ roundsNotPowerOf2,
5509
5510
  drawDefinition,
5510
- roundMatchUps,
5511
- structure
5511
+ structure,
5512
+ matchUps
5512
5513
  }) {
5513
5514
  if (!structure)
5514
5515
  return false;
5515
- if (!roundMatchUps) {
5516
- ({ isNotEliminationStructure, roundMatchUps } = getRoundMatchUps({
5517
- matchUps: structure.matchUps ?? []
5518
- }));
5519
- }
5520
- const hasFirstRoundDrawPositions = !!roundMatchUps?.[1]?.find(
5521
- ({ drawPositions }) => drawPositions
5522
- );
5523
- const noSecondRoundDrawPositions = !roundMatchUps?.[2]?.find(
5524
- ({ drawPositions }) => drawPositions
5525
- );
5526
- return isNotEliminationStructure && !structure?.structures && hasFirstRoundDrawPositions && noSecondRoundDrawPositions && !(drawDefinition?.drawType && drawDefinition.drawType !== LUCKY_DRAW);
5516
+ matchUps = matchUps ?? structure.matchUps ?? [];
5517
+ roundsNotPowerOf2 = roundsNotPowerOf2 ?? getRoundMatchUps({ matchUps }).roundsNotPowerOf2;
5518
+ const hasDrawPositions = !!structure.positionAssignments?.find(({ drawPosition }) => drawPosition) || !!matchUps?.find(({ drawPositions }) => drawPositions?.length);
5519
+ return (!drawDefinition?.drawType || drawDefinition.drawType !== LUCKY_DRAW) && !structure?.structures && roundsNotPowerOf2 && hasDrawPositions;
5527
5520
  }
5528
5521
 
5529
5522
  function isAdHoc({ drawDefinition, structure }) {
5530
5523
  if (!structure)
5531
5524
  return false;
5532
- return !structure?.structures && !(drawDefinition?.drawType && drawDefinition.drawType !== AD_HOC) && !structure?.matchUps?.find(({ roundPosition }) => !!roundPosition);
5525
+ const hasRoundPosition = structure?.matchUps?.find(
5526
+ (matchUp) => matchUp?.roundPosition
5527
+ );
5528
+ const hasDrawPosition = structure?.matchUps?.find(
5529
+ (matchUp) => matchUp?.drawPositions?.length
5530
+ );
5531
+ return !structure?.structures && !(drawDefinition?.drawType && drawDefinition.drawType !== AD_HOC) && !hasRoundPosition && !hasDrawPosition;
5533
5532
  }
5534
5533
 
5535
5534
  const POLICY_ROUND_NAMING_DEFAULT = {
@@ -5564,14 +5563,10 @@ function getRoundContextProfile({
5564
5563
  structure,
5565
5564
  matchUps
5566
5565
  }) {
5567
- const { isNotEliminationStructure, roundProfile, roundMatchUps } = getRoundMatchUps({ matchUps });
5566
+ const { roundProfile, roundMatchUps } = getRoundMatchUps({ matchUps });
5568
5567
  const { structureAbbreviation, stage } = structure;
5569
5568
  const isAdHocStructure = isAdHoc({ structure });
5570
- const isLuckyStructure = isLucky({
5571
- isNotEliminationStructure,
5572
- roundMatchUps,
5573
- structure
5574
- });
5569
+ const isLuckyStructure = isLucky({ structure });
5575
5570
  const isRoundRobin = structure.structures;
5576
5571
  const roundNamingProfile = {};
5577
5572
  const defaultRoundNamingPolicy = POLICY_ROUND_NAMING_DEFAULT[POLICY_TYPE_ROUND_NAMING];
@@ -7480,6 +7475,23 @@ function updateInContextMatchUp({ tournamentId, inContextMatchUp }) {
7480
7475
  });
7481
7476
  return { ...SUCCESS };
7482
7477
  }
7478
+ function addDrawNotice({
7479
+ tournamentId,
7480
+ eventId,
7481
+ drawDefinition
7482
+ }) {
7483
+ if (!drawDefinition) {
7484
+ console.log(MISSING_DRAW_DEFINITION);
7485
+ return { error: MISSING_DRAW_DEFINITION };
7486
+ }
7487
+ drawUpdatedAt(drawDefinition);
7488
+ addNotice({
7489
+ payload: { drawDefinition, tournamentId, eventId },
7490
+ topic: ADD_DRAW_DEFINITION,
7491
+ key: drawDefinition.drawId
7492
+ });
7493
+ return { ...SUCCESS };
7494
+ }
7483
7495
  function modifyDrawNotice({
7484
7496
  drawDefinition,
7485
7497
  tournamentId,
@@ -13097,7 +13109,7 @@ function getValidSeedBlocks({
13097
13109
  let validSeedBlocks = [];
13098
13110
  if (!structure)
13099
13111
  return { error: MISSING_STRUCTURE };
13100
- const { roundMatchUps } = getAllStructureMatchUps({
13112
+ const { matchUps, roundMatchUps } = getAllStructureMatchUps({
13101
13113
  matchUpFilters: { roundNumbers: [1] },
13102
13114
  provisionalPositioning,
13103
13115
  structure
@@ -13130,12 +13142,16 @@ function getValidSeedBlocks({
13130
13142
  const { stage, structureType, roundLimit } = structure;
13131
13143
  const isContainer = structureType === CONTAINER;
13132
13144
  const isFeedIn = !isContainer && uniqueDrawPositionsByRound?.length;
13133
- const isLucky = firstRoundDrawPositions?.length && !isPowerOf2(baseDrawSize);
13134
13145
  const qualifyingBlocks = !isContainer && stage === QUALIFYING && roundLimit;
13135
13146
  const fedSeedBlockPositions = seedRangeDrawPositionBlocks.flat(Infinity);
13136
13147
  const fedSeedNumberOffset = isFeedIn ? fedSeedBlockPositions?.length : 0;
13137
13148
  const countLimit = allPositions ? positionsCount : seedsCount;
13138
- const firstRoundSeedsCount = isLucky ? 0 : !isFeedIn && countLimit || countLimit && fedSeedBlockPositions.length < countLimit && countLimit - fedSeedBlockPositions.length || 0;
13149
+ const isLuckyStructure = isLucky({
13150
+ drawDefinition,
13151
+ structure,
13152
+ matchUps
13153
+ });
13154
+ const firstRoundSeedsCount = isLuckyStructure ? 0 : !isFeedIn && countLimit || countLimit && fedSeedBlockPositions.length < countLimit && countLimit - fedSeedBlockPositions.length || 0;
13139
13155
  if (qualifyingBlocks) {
13140
13156
  const seedingBlocksCount = structure?.matchUps ? structure.matchUps.filter(
13141
13157
  ({ roundNumber }) => roundNumber === structure.roundLimit
@@ -13171,14 +13187,14 @@ function getValidSeedBlocks({
13171
13187
  validSeedBlocks = seedRangeDrawPositionBlocks.map((block) => {
13172
13188
  return { seedNumbers: block, drawPositions: block };
13173
13189
  });
13174
- } else if (isLucky) {
13190
+ } else if (isLuckyStructure) {
13175
13191
  const blocks = chunkArray(firstRoundDrawPositions, 2).map((block, i) => ({
13176
13192
  drawPositions: [block[0]],
13177
13193
  seedNumbers: [i + 1]
13178
13194
  }));
13179
13195
  blocks.forEach((block) => validSeedBlocks.push(block));
13180
13196
  }
13181
- if (!isContainer && !isLucky && !qualifyingBlocks) {
13197
+ if (!isContainer && !isLuckyStructure && !qualifyingBlocks) {
13182
13198
  const { blocks } = constructPower2Blocks({
13183
13199
  drawPositionOffset: firstRoundDrawPositionOffset,
13184
13200
  seedNumberOffset: fedSeedNumberOffset,
@@ -13197,7 +13213,7 @@ function getValidSeedBlocks({
13197
13213
  },
13198
13214
  true
13199
13215
  );
13200
- if (!isLucky && !isFeedIn && !isContainer && !validSeedPositions) {
13216
+ if (!isLuckyStructure && !isFeedIn && !isContainer && !validSeedPositions) {
13201
13217
  return {
13202
13218
  error: INVALID_SEED_POSITION,
13203
13219
  validSeedBlocks: [],
@@ -13206,10 +13222,10 @@ function getValidSeedBlocks({
13206
13222
  };
13207
13223
  }
13208
13224
  return {
13225
+ isLuckyStructure,
13209
13226
  validSeedBlocks,
13210
13227
  isContainer,
13211
- isFeedIn,
13212
- isLucky
13228
+ isFeedIn
13213
13229
  };
13214
13230
  }
13215
13231
  function getContainerBlocks({ seedingProfile, structure }) {
@@ -13453,6 +13469,75 @@ function getTargetMatchUps({
13453
13469
  return { drawPositions, matchUps, targetMatchUps };
13454
13470
  }
13455
13471
 
13472
+ function validateLineUp({ lineUp, tieFormat }) {
13473
+ const errors = [];
13474
+ if (!Array.isArray(lineUp)) {
13475
+ errors.push(mustBeAnArray("lineUp"));
13476
+ return { valid: false, errors, error: INVALID_VALUES };
13477
+ }
13478
+ const validItems = lineUp.every((item) => {
13479
+ if (typeof item !== "object") {
13480
+ errors.push(`lineUp entries must be objects`);
13481
+ return false;
13482
+ }
13483
+ const { participantId, collectionAssignments } = item;
13484
+ if (!participantId) {
13485
+ errors.push("Missing participantId");
13486
+ return false;
13487
+ }
13488
+ if (typeof participantId !== "string") {
13489
+ errors.push("participantIds must be strings");
13490
+ return false;
13491
+ }
13492
+ if (!Array.isArray(collectionAssignments)) {
13493
+ errors.push(mustBeAnArray("collectionAssignments"));
13494
+ return false;
13495
+ }
13496
+ return collectionAssignments.every((collectionAssignment) => {
13497
+ if (typeof collectionAssignment !== "object") {
13498
+ errors.push("collectionAssignments must be objects");
13499
+ return false;
13500
+ }
13501
+ const { collectionPosition } = collectionAssignment;
13502
+ if (typeof collectionPosition !== "number") {
13503
+ errors.push("collectionPosition must be a number");
13504
+ return false;
13505
+ }
13506
+ return true;
13507
+ });
13508
+ });
13509
+ const noDuplicates = unique(lineUp.map(getParticipantId)).length === lineUp.length;
13510
+ if (!noDuplicates)
13511
+ errors.push("Duplicated participantId(s)");
13512
+ const valid = validItems && noDuplicates;
13513
+ return { valid, errors, error: errors.length ? INVALID_VALUES : void 0 };
13514
+ }
13515
+
13516
+ function updateTeamLineUp({
13517
+ drawDefinition,
13518
+ participantId,
13519
+ tieFormat,
13520
+ lineUp
13521
+ }) {
13522
+ if (typeof drawDefinition !== "object")
13523
+ return { error: MISSING_DRAW_DEFINITION };
13524
+ if (typeof participantId !== "string")
13525
+ return { error: MISSING_PARTICIPANT_ID };
13526
+ const validation = validateLineUp({ lineUp, tieFormat });
13527
+ if (!validation.valid)
13528
+ return validation;
13529
+ const { extension: existingExtension } = findExtension({
13530
+ element: drawDefinition,
13531
+ name: LINEUPS
13532
+ });
13533
+ const value = existingExtension?.value || {};
13534
+ value[participantId] = removeLineUpSubstitutions({ lineUp });
13535
+ const extension = { name: LINEUPS, value };
13536
+ addExtension$1({ element: drawDefinition, extension });
13537
+ addDrawNotice({ drawDefinition });
13538
+ return { ...SUCCESS };
13539
+ }
13540
+
13456
13541
  function resetLineUps({
13457
13542
  inContextDrawMatchUps,
13458
13543
  inheritance = true,
@@ -13480,10 +13565,18 @@ function resetLineUps({
13480
13565
  ({ matchUpId }) => matchUpId === inContextMatchUp.matchUpId
13481
13566
  );
13482
13567
  if (matchUp?.sides?.[sideIndex]) {
13483
- if (inheritance) {
13484
- delete matchUp.sides[sideIndex].lineUp;
13485
- } else {
13486
- matchUp.sides[sideIndex].lineUp = [];
13568
+ delete matchUp.sides[sideIndex].lineUp;
13569
+ if (inheritance === false) {
13570
+ const tieFormat = inContextMatchUp.tieFormat;
13571
+ const participantId = side.participantId;
13572
+ if (tieFormat && participantId) {
13573
+ updateTeamLineUp({
13574
+ drawDefinition,
13575
+ participantId,
13576
+ lineUp: [],
13577
+ tieFormat
13578
+ });
13579
+ }
13487
13580
  }
13488
13581
  modifyMatchUpNotice({
13489
13582
  tournamentId: tournamentRecord?.tournamentId,