tods-competition-factory 1.7.1 → 1.7.3

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.
@@ -2962,7 +2962,7 @@ function getRoundMatchUps({
2962
2962
  roundProfile[roundNumber].finishingRound = finishingRoundMap[roundNumber]?.finishingRound;
2963
2963
  roundProfile[roundNumber].roundName = finishingRoundMap[roundNumber]?.roundName;
2964
2964
  roundProfile[roundNumber].abbreviatedRoundName = finishingRoundMap[roundNumber]?.abbreviatedRoundName;
2965
- roundProfile[roundNumber].finishingPositionRange = roundMatchUps[roundNumber][0].finishingPositionRange;
2965
+ roundProfile[roundNumber].finishingPositionRange = roundMatchUps[roundNumber]?.[0]?.finishingPositionRange;
2966
2966
  if (roundNumber === 1 || !roundProfile[roundNumber - 1]) {
2967
2967
  const orderedDrawPositions = currentRoundDrawPositions.sort(numericSort);
2968
2968
  const pairedDrawPositions = chunkArray(orderedDrawPositions, 2);
@@ -10760,7 +10760,7 @@ function assignMatchUpDrawPosition({
10760
10760
  inContext: true,
10761
10761
  drawDefinition,
10762
10762
  matchUpsMap
10763
- }).matchUps || [];
10763
+ }).matchUps ?? [];
10764
10764
  }
10765
10765
  const inContextMatchUp = inContextDrawMatchUps.find(
10766
10766
  (m) => m.matchUpId === matchUpId
@@ -10774,7 +10774,7 @@ function assignMatchUpDrawPosition({
10774
10774
  const matchUp = matchUpsMap?.drawMatchUps?.find(
10775
10775
  (matchUp2) => matchUp2.matchUpId === matchUpId
10776
10776
  );
10777
- const drawPositions = matchUp?.drawPositions || [];
10777
+ const drawPositions = matchUp?.drawPositions ?? [];
10778
10778
  const { positionAdded, positionAssigned, updatedDrawPositions } = getUpdatedDrawPositions({ drawPosition, drawPositions });
10779
10779
  const { positionAssignments } = getPositionAssignments({
10780
10780
  drawDefinition,
@@ -10791,7 +10791,7 @@ function assignMatchUpDrawPosition({
10791
10791
  inContext: true,
10792
10792
  drawDefinition,
10793
10793
  matchUpsMap
10794
- }).matchUps || [];
10794
+ }).matchUps ?? [];
10795
10795
  const exitWinningSide = isDoubleExitExit && getExitWinningSide({
10796
10796
  inContextDrawMatchUps,
10797
10797
  drawPosition,
@@ -10879,7 +10879,7 @@ function assignMatchUpDrawPosition({
10879
10879
  const inContextTargetMatchUp = inContextDrawMatchUps?.find(
10880
10880
  ({ matchUpId: matchUpId2 }) => matchUpId2 === matchUp.matchUpId
10881
10881
  );
10882
- const sides = inContextTargetMatchUp?.sides || [];
10882
+ const sides = inContextTargetMatchUp?.sides ?? [];
10883
10883
  const drawPositionSideIndex = sides.reduce(
10884
10884
  (index, side, i) => side.drawPosition === drawPosition ? i : index,
10885
10885
  void 0
@@ -16342,15 +16342,17 @@ function validateTieFormat(params) {
16342
16342
  function validateCollectionDefinition({
16343
16343
  collectionDefinition,
16344
16344
  checkCollectionIds,
16345
+ checkGender = true,
16345
16346
  referenceGender,
16346
- checkGender
16347
+ event
16347
16348
  }) {
16349
+ referenceGender = referenceGender ?? event?.gender;
16348
16350
  const errors = [];
16349
16351
  if (typeof collectionDefinition !== "object") {
16350
16352
  errors.push(
16351
16353
  `collectionDefinition must be an object: ${collectionDefinition}`
16352
16354
  );
16353
- return { errors };
16355
+ return { errors, error: INVALID_OBJECT };
16354
16356
  }
16355
16357
  const {
16356
16358
  collectionValueProfiles,
@@ -16409,7 +16411,7 @@ function validateCollectionDefinition({
16409
16411
  errors.push(`Invalid gender: ${gender}`);
16410
16412
  }
16411
16413
  if (errors.length)
16412
- return { errors };
16414
+ return { errors, error: INVALID_OBJECT };
16413
16415
  return { valid: true };
16414
16416
  }
16415
16417
  function checkTieFormat(tieFormat) {
@@ -19712,14 +19714,30 @@ function generateAdHocMatchUps({
19712
19714
  structureId = drawDefinition.structures?.[0]?.structureId;
19713
19715
  if (typeof structureId !== "string")
19714
19716
  return { error: MISSING_STRUCTURE_ID };
19717
+ const structure = drawDefinition.structures?.find(
19718
+ (structure2) => structure2.structureId === structureId
19719
+ );
19720
+ if (!structure)
19721
+ return { error: STRUCTURE_NOT_FOUND };
19722
+ if (!matchUpsCount) {
19723
+ const selectedEntries = drawDefinition?.entries?.filter((entry) => {
19724
+ const entryStatus = entry.entryStatus;
19725
+ return STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
19726
+ }) ?? [];
19727
+ const roundMatchUpsCount = Math.floor(selectedEntries?.length / 2) || 1;
19728
+ if (newRound) {
19729
+ matchUpsCount = roundMatchUpsCount;
19730
+ } else {
19731
+ const maxRemaining = roundMatchUpsCount - (structure.matchUps?.length || 0);
19732
+ if (maxRemaining > 0)
19733
+ matchUpsCount = maxRemaining;
19734
+ }
19735
+ }
19715
19736
  if (participantIdPairings && !Array.isArray(participantIdPairings) || matchUpsCount && !isConvertableInteger(matchUpsCount) || matchUpIds && !Array.isArray(matchUpIds) || !participantIdPairings && !matchUpsCount) {
19716
19737
  return { error: INVALID_VALUES, info: "matchUpsCount or pairings error" };
19717
19738
  }
19718
- const structure = drawDefinition?.structures?.find(
19719
- (structure2) => structure2.structureId === structureId
19720
- );
19721
19739
  let structureHasRoundPositions;
19722
- const existingMatchUps = structure?.matchUps;
19740
+ const existingMatchUps = structure.matchUps ?? [];
19723
19741
  const lastRoundNumber = existingMatchUps?.reduce(
19724
19742
  (roundNumber2, matchUp) => {
19725
19743
  if (matchUp.roundPosition)
@@ -19728,12 +19746,12 @@ function generateAdHocMatchUps({
19728
19746
  },
19729
19747
  0
19730
19748
  );
19731
- if (structure?.structures || structureHasRoundPositions || structure?.finishingPosition === ROUND_OUTCOME) {
19749
+ if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
19732
19750
  return { error: INVALID_STRUCTURE };
19733
19751
  }
19734
19752
  if (roundNumber && roundNumber - 1 > (lastRoundNumber || 0))
19735
19753
  return { error: INVALID_VALUES, info: "roundNumber error" };
19736
- const nextRoundNumber = roundNumber ?? (newRound ? (lastRoundNumber ?? 0) + 1 : lastRoundNumber ?? 1);
19754
+ const nextRoundNumber = roundNumber ?? (newRound && (lastRoundNumber ?? 0) + 1 || lastRoundNumber || 1);
19737
19755
  participantIdPairings = participantIdPairings ?? generateRange(0, matchUpsCount).map(() => ({
19738
19756
  participantIds: [void 0, void 0]
19739
19757
  }));