tods-competition-factory 1.6.11 → 1.6.13

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.
package/dist/index.mjs CHANGED
@@ -329,7 +329,7 @@ const matchUpFormatCode = {
329
329
  };
330
330
 
331
331
  function factoryVersion() {
332
- return "1.6.11";
332
+ return "1.6.13";
333
333
  }
334
334
 
335
335
  function getObjectTieFormat(obj) {
@@ -2784,7 +2784,7 @@ function validMatchUp(matchUp) {
2784
2784
  const { matchUpId, drawPositions } = matchUp;
2785
2785
  const validMatchUpId = typeof matchUpId === "string";
2786
2786
  const validDrawPositions = !drawPositions || Array.isArray(drawPositions) && drawPositions.length <= 2 && drawPositions.every(
2787
- (dp) => isConvertableInteger(dp) || dp === void 0
2787
+ (dp) => isConvertableInteger(dp) || dp === void 0 || dp === null
2788
2788
  );
2789
2789
  return validMatchUpId && validDrawPositions;
2790
2790
  }
@@ -3054,7 +3054,7 @@ function getParticipantResults({
3054
3054
  const manualGamesOverride = tieFormat && matchUp._disableAutoCalc && tieFormat.collectionDefinitions.every(({ scoreValue }) => scoreValue);
3055
3055
  const winningParticipantId = winningSide && getWinningSideId(matchUp);
3056
3056
  const losingParticipantId = winningSide && getLosingSideId(matchUp);
3057
- if (!winningParticipantId || !losingParticipantId) {
3057
+ if (!winningParticipantId && !losingParticipantId) {
3058
3058
  if (completedMatchUpStatuses.includes(matchUpStatus)) {
3059
3059
  const participantIdSide1 = getSideId(matchUp, 0);
3060
3060
  const participantIdSide2 = getSideId(matchUp, 1);
@@ -3066,53 +3066,51 @@ function getParticipantResults({
3066
3066
  checkInitializeParticipant(participantResults, participantIdSide2);
3067
3067
  participantResults[participantIdSide2].matchUpsCancelled += 1;
3068
3068
  }
3069
- } else {
3070
- if (tieMatchUps?.length) {
3071
- perPlayer = 0;
3072
- for (const tieMatchUp of tieMatchUps) {
3073
- if (tieMatchUp.winningSide) {
3074
- const tieWinningParticipantId = sides.find(
3075
- ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
3076
- )?.participantId;
3077
- const tieLosingParticipantId = sides.find(
3078
- ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
3079
- )?.participantId;
3080
- if (tieWinningParticipantId && tieLosingParticipantId) {
3081
- checkInitializeParticipant(
3082
- participantResults,
3083
- tieWinningParticipantId
3084
- );
3085
- checkInitializeParticipant(
3086
- participantResults,
3087
- tieLosingParticipantId
3088
- );
3089
- participantResults[tieWinningParticipantId].tieMatchUpsWon += 1;
3090
- participantResults[tieLosingParticipantId].tieMatchUpsLost += 1;
3091
- if (tieMatchUp.matchUpType === SINGLES$1) {
3092
- participantResults[tieWinningParticipantId].tieSinglesWon += 1;
3093
- participantResults[tieLosingParticipantId].tieSinglesLost += 1;
3094
- } else if (tieMatchUp.matchUpType === DOUBLES$1) {
3095
- participantResults[tieWinningParticipantId].tieDoublesWon += 1;
3096
- participantResults[tieLosingParticipantId].tieDoublesLost += 1;
3097
- }
3069
+ } else if (tieMatchUps?.length) {
3070
+ perPlayer = 0;
3071
+ for (const tieMatchUp of tieMatchUps) {
3072
+ if (tieMatchUp.winningSide) {
3073
+ const tieWinningParticipantId = sides.find(
3074
+ ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
3075
+ )?.participantId;
3076
+ const tieLosingParticipantId = sides.find(
3077
+ ({ sideNumber }) => sideNumber === tieMatchUp.winningSide
3078
+ )?.participantId;
3079
+ if (tieWinningParticipantId && tieLosingParticipantId) {
3080
+ checkInitializeParticipant(
3081
+ participantResults,
3082
+ tieWinningParticipantId
3083
+ );
3084
+ checkInitializeParticipant(
3085
+ participantResults,
3086
+ tieLosingParticipantId
3087
+ );
3088
+ participantResults[tieWinningParticipantId].tieMatchUpsWon += 1;
3089
+ participantResults[tieLosingParticipantId].tieMatchUpsLost += 1;
3090
+ if (tieMatchUp.matchUpType === SINGLES$1) {
3091
+ participantResults[tieWinningParticipantId].tieSinglesWon += 1;
3092
+ participantResults[tieLosingParticipantId].tieSinglesLost += 1;
3093
+ } else if (tieMatchUp.matchUpType === DOUBLES$1) {
3094
+ participantResults[tieWinningParticipantId].tieDoublesWon += 1;
3095
+ participantResults[tieLosingParticipantId].tieDoublesLost += 1;
3098
3096
  }
3099
3097
  }
3100
- processScore({
3101
- score: tieMatchUp.score,
3102
- manualGamesOverride,
3103
- participantResults,
3104
- sides
3105
- // use sides from the TEAM matchUp
3106
- });
3107
3098
  }
3108
- } else {
3109
3099
  processScore({
3100
+ score: tieMatchUp.score,
3110
3101
  manualGamesOverride,
3111
3102
  participantResults,
3112
- score,
3113
3103
  sides
3104
+ // use sides from the TEAM matchUp
3114
3105
  });
3115
3106
  }
3107
+ } else {
3108
+ processScore({
3109
+ manualGamesOverride,
3110
+ participantResults,
3111
+ score,
3112
+ sides
3113
+ });
3116
3114
  }
3117
3115
  } else {
3118
3116
  checkInitializeParticipant(participantResults, winningParticipantId);
@@ -7010,9 +7008,10 @@ function getSourceDrawPositionRanges({
7010
7008
  structureId: sourceStructureId,
7011
7009
  matchUpsMap
7012
7010
  });
7013
- const { roundProfile } = getRoundMatchUps$1({
7011
+ const roundMatchUpsResult = getRoundMatchUps$1({
7014
7012
  matchUps: structureMatchUps2
7015
7013
  });
7014
+ const roundProfile = roundMatchUpsResult.roundProfile;
7016
7015
  return { [sourceStructureId]: roundProfile };
7017
7016
  })
7018
7017
  );
@@ -9652,9 +9651,8 @@ function modifyMatchUpScore({
9652
9651
  return { error: MATCHUP_NOT_FOUND };
9653
9652
  ({ matchUp, structure } = findResult);
9654
9653
  }
9655
- } else {
9656
- if (matchUp.matchUpId !== matchUpId)
9657
- console.log("!!!!!");
9654
+ } else if (matchUp.matchUpId !== matchUpId) {
9655
+ console.log("!!!!!");
9658
9656
  }
9659
9657
  if (matchUpStatus && [WALKOVER$2, DOUBLE_WALKOVER].includes(matchUpStatus) || removeScore) {
9660
9658
  Object.assign(matchUp, { ...toBePlayed });
@@ -9692,31 +9690,45 @@ function modifyMatchUpScore({
9692
9690
  })?.appliedPolicies;
9693
9691
  defaultedProcessCodes = appliedPolicies?.[POLICY_TYPE_SCORING]?.processCodes?.incompleteAssignmentsOnDefault;
9694
9692
  }
9695
- if (structure?.structureType === CONTAINER && !matchUp.collectionId) {
9696
- matchUpFormat = isDualMatchUp ? "SET1-S:T100" : matchUpFormat || matchUp.matchUpFormat || structure?.matchUpFormat || drawDefinition?.matchUpFormat || event?.matchUpFormat;
9697
- const itemStructure = structure.structures.find((itemStructure2) => {
9698
- return itemStructure2?.matchUps.find(
9699
- (matchUp2) => matchUp2.matchUpId === matchUpId
9700
- );
9701
- });
9702
- const matchUpFilters = isDualMatchUp ? { matchUpTypes: [TEAM$2] } : void 0;
9703
- const { matchUps } = getAllStructureMatchUps({
9704
- afterRecoveryTimes: false,
9705
- structure: itemStructure,
9706
- inContext: true,
9707
- matchUpFilters,
9708
- event
9709
- });
9710
- const result = updateAssignmentParticipantResults({
9711
- positionAssignments: itemStructure.positionAssignments,
9712
- tournamentRecord,
9713
- drawDefinition,
9714
- matchUpFormat,
9715
- matchUps,
9716
- event
9717
- });
9718
- if (result.error)
9719
- return decorateResult({ result, stack });
9693
+ if (!matchUp.collectionId) {
9694
+ const isRoundRobin = structure?.structureType === CONTAINER;
9695
+ const isAdHocStructure = isAdHoc({ drawDefinition, structure });
9696
+ if (isLucky({ drawDefinition, structure }) || isAdHocStructure || isRoundRobin) {
9697
+ const updateTally = (structure2) => {
9698
+ matchUpFormat = isDualMatchUp ? "SET1-S:T100" : matchUpFormat ?? matchUp.matchUpFormat ?? structure2?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
9699
+ const matchUpFilters = isDualMatchUp ? { matchUpTypes: [TEAM$2] } : void 0;
9700
+ const { matchUps } = getAllStructureMatchUps({
9701
+ afterRecoveryTimes: false,
9702
+ inContext: true,
9703
+ matchUpFilters,
9704
+ structure: structure2,
9705
+ event
9706
+ });
9707
+ if (isAdHocStructure) {
9708
+ structure2.positionAssignments = unique(
9709
+ matchUps.flatMap(
9710
+ (matchUp2) => (matchUp2.sides ?? []).map((side) => side.participantId)
9711
+ ).filter(Boolean)
9712
+ ).map((participantId) => ({ participantId }));
9713
+ }
9714
+ return updateAssignmentParticipantResults({
9715
+ positionAssignments: structure2.positionAssignments,
9716
+ tournamentRecord,
9717
+ drawDefinition,
9718
+ matchUpFormat,
9719
+ matchUps,
9720
+ event
9721
+ });
9722
+ };
9723
+ const itemStructure = isRoundRobin && structure.structures.find((itemStructure2) => {
9724
+ return itemStructure2?.matchUps.find(
9725
+ (matchUp2) => matchUp2.matchUpId === matchUpId
9726
+ );
9727
+ });
9728
+ const result = updateTally(itemStructure || structure);
9729
+ if (result.error)
9730
+ return decorateResult({ result, stack });
9731
+ }
9720
9732
  }
9721
9733
  if (notes) {
9722
9734
  const result = addNotes({ element: matchUp, notes });
@@ -23020,7 +23032,7 @@ function getValidSeedBlocks({
23020
23032
  });
23021
23033
  const { positionAssignments } = structureAssignedDrawPositions({ structure });
23022
23034
  const positionsCount = positionAssignments?.length;
23023
- const seedsCount = seedAssignments?.length || 0;
23035
+ const seedsCount = seedAssignments?.length ?? 0;
23024
23036
  let allDrawPositions = [];
23025
23037
  const roundNumbers = Object.keys(roundMatchUps).map((n) => parseInt(n)).sort((a, b) => a - b);
23026
23038
  const uniqueDrawPositionsByRound = roundNumbers.map((roundNumber) => {
@@ -23282,7 +23294,7 @@ function getNextSeedBlock(params) {
23282
23294
  const seedsWithoutDrawPositions = seedAssignments?.filter(
23283
23295
  (assignment) => !assignment.participantId
23284
23296
  );
23285
- const seedsLeftToAssign = unplacedSeedAssignments?.length || seedsWithoutDrawPositions?.length;
23297
+ const seedsLeftToAssign = unplacedSeedAssignments?.length && unplacedSeedAssignments.length > 0 ? unplacedSeedAssignments.length : seedsWithoutDrawPositions?.length ?? 0;
23286
23298
  const unfilled = seedsLeftToAssign && nextSeedBlock?.drawPositions.filter(
23287
23299
  (drawPosition) => !assignedDrawPositions?.includes(drawPosition)
23288
23300
  ) || [];
@@ -28483,7 +28495,7 @@ function getParticipantEntries(params) {
28483
28495
  }));
28484
28496
  }
28485
28497
  const addEventEntry = (id) => {
28486
- if (participantMap[id]?.events[eventId])
28498
+ if (participantMap[id]?.events?.[eventId])
28487
28499
  return;
28488
28500
  const participant = participantMap[id];
28489
28501
  processEventEntry({
@@ -28552,7 +28564,7 @@ function getParticipantEntries(params) {
28552
28564
  const relevantEntries = entries2.filter(
28553
28565
  ({ participantId }) => assignedParticipantIds.includes(participantId)
28554
28566
  );
28555
- const publishedSeeding2 = eventsPublishStatuses[eventId]?.publishedSeeding;
28567
+ const publishedSeeding2 = eventsPublishStatuses?.[eventId]?.publishedSeeding;
28556
28568
  const seedingPublished = !usePublishState || publishedSeeding2?.published && (publishedSeeding2?.drawIds?.length === 0 || publishedSeeding2?.drawIds?.includes(drawId));
28557
28569
  for (const entry of relevantEntries) {
28558
28570
  const { entryStatus, entryStage, entryPosition, participantId } = entry;
@@ -28562,7 +28574,7 @@ function getParticipantEntries(params) {
28562
28574
  eventType
28563
28575
  });
28564
28576
  const addDrawEntry = (id) => {
28565
- if (participantMap[id].draws[drawId])
28577
+ if (participantMap[id].draws?.[drawId])
28566
28578
  return;
28567
28579
  const includeSeeding = withSeeding && seedingPublished;
28568
28580
  const seedAssignments = includeSeeding ? {} : void 0;
@@ -28894,9 +28906,9 @@ function getParticipants$1(params) {
28894
28906
  withIOC
28895
28907
  });
28896
28908
  const entriesResult = getParticipantEntries({
28897
- withMatchUps: withMatchUps || withRankingProfile,
28898
- withEvents: withEvents || withRankingProfile,
28899
- withDraws: withDraws || withRankingProfile,
28909
+ withMatchUps: withMatchUps ?? withRankingProfile,
28910
+ withEvents: withEvents ?? withRankingProfile,
28911
+ withDraws: withDraws ?? withRankingProfile,
28900
28912
  withPotentialMatchUps,
28901
28913
  participantFilters,
28902
28914
  withRankingProfile,
@@ -28922,7 +28934,7 @@ function getParticipants$1(params) {
28922
28934
  } = entriesResult;
28923
28935
  const matchUps = entriesResult.matchUps;
28924
28936
  participantMap = entriesResult.participantMap;
28925
- const nextMatchUps = scheduleAnalysis || withPotentialMatchUps;
28937
+ const nextMatchUps = scheduleAnalysis ?? withPotentialMatchUps;
28926
28938
  const processedParticipants = Object.values(participantMap).map(
28927
28939
  ({
28928
28940
  potentialMatchUps,