tods-competition-factory 1.8.22 → 1.8.24

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.
@@ -5061,7 +5061,7 @@ function getMatchUpFormatTiming({
5061
5061
  }) {
5062
5062
  if (!tournamentRecord)
5063
5063
  return { error: MISSING_TOURNAMENT_RECORD };
5064
- eventType = eventType || event?.eventType || TypeEnum.Singles;
5064
+ eventType = eventType ?? event?.eventType ?? TypeEnum.Singles;
5065
5065
  const defaultTiming = {
5066
5066
  averageTimes: [{ minutes: { default: defaultAverageMinutes } }],
5067
5067
  recoveryTimes: [{ minutes: { default: defaultRecoveryMinutes } }]
@@ -5389,7 +5389,7 @@ function findVenue({
5389
5389
  if (!venue && tournamentRecords) {
5390
5390
  const linkedTournamentIds = getLinkedTournamentIds({
5391
5391
  tournamentRecords
5392
- }).linkedTournamentIds || [];
5392
+ }).linkedTournamentIds ?? [];
5393
5393
  const relevantIds = linkedTournamentIds[tournamentRecord.tournamentId];
5394
5394
  for (const tournamentId of relevantIds) {
5395
5395
  const record = tournamentRecords[tournamentId];
@@ -5931,7 +5931,7 @@ function getPairedParticipant({
5931
5931
  result: { error: MISSING_PARTICIPANT_IDS },
5932
5932
  stack
5933
5933
  });
5934
- tournamentParticipants = tournamentParticipants || tournamentRecord?.participants || [];
5934
+ tournamentParticipants = tournamentParticipants ?? tournamentRecord?.participants ?? [];
5935
5935
  const existingPairedParticipants = tournamentParticipants.filter(
5936
5936
  (participant) => participant.participantType === PAIR && intersection(participantIds, participant.individualParticipantIds).length === participantIds.length && participant.individualParticipantIds.length === participantIds.length
5937
5937
  );
@@ -6760,7 +6760,8 @@ const POLICY_ROUND_NAMING_DEFAULT = {
6760
6760
  [POLICY_TYPE_ROUND_NAMING]: {
6761
6761
  policyName: "Round Naming Default",
6762
6762
  namingConventions: {
6763
- round: "Round"
6763
+ round: "Round",
6764
+ pre: "Pre"
6764
6765
  },
6765
6766
  qualifyingFinishMap: {
6766
6767
  1: "Final"
@@ -6804,12 +6805,11 @@ function getRoundContextProfile({
6804
6805
  const roundNamingProfile = {};
6805
6806
  const defaultRoundNamingPolicy = POLICY_ROUND_NAMING_DEFAULT[POLICY_TYPE_ROUND_NAMING];
6806
6807
  const isQualifying = structure.stage === QUALIFYING;
6807
- const qualifyingFinishgMap = isQualifying && (roundNamingPolicy?.qualifyingFinishMap || defaultRoundNamingPolicy?.qualifyingFinishMap || {});
6808
6808
  const qualifyingStageSequences = isQualifying ? Math.max(
6809
6809
  ...(drawDefinition?.structures ?? []).filter((structure2) => structure2.stage === QUALIFYING).map(({ stageSequence }) => stageSequence ?? 1),
6810
6810
  0
6811
6811
  ) : 0;
6812
- const preQualifyingSequence = qualifyingStageSequences ? qualifyingStageSequences - (structure.stageSequence || 1) || "" : "";
6812
+ const preQualifyingSequence = (structure.stageSequence ?? 1) < qualifyingStageSequences ? structure.stageSequence ?? 1 : "";
6813
6813
  const preQualifyingAffix = preQualifyingSequence ? roundNamingPolicy?.affixes?.preQualifying || defaultRoundNamingPolicy.affixes.preQualifying || "" : "";
6814
6814
  const roundNamingMap = roundNamingPolicy?.roundNamingMap || defaultRoundNamingPolicy.roundNamingMap || {};
6815
6815
  const abbreviatedRoundNamingMap = roundNamingPolicy?.abbreviatedRoundNamingMap || defaultRoundNamingPolicy.abbreviatedRoundNamingMap || {};
@@ -6833,6 +6833,7 @@ function getRoundContextProfile({
6833
6833
  })
6834
6834
  );
6835
6835
  } else {
6836
+ const qualifyingFinishgMap = isQualifying && (roundNamingPolicy?.qualifyingFinishMap || defaultRoundNamingPolicy?.qualifyingFinishMap || {});
6836
6837
  Object.assign(
6837
6838
  roundNamingProfile,
6838
6839
  ...roundProfileKeys.map((round) => {
@@ -7108,7 +7109,13 @@ function getAllStructureMatchUps({
7108
7109
  matchUps
7109
7110
  }));
7110
7111
  }
7111
- return { matchUps, roundMatchUps, roundProfile, collectionPositionMatchUps };
7112
+ return {
7113
+ collectionPositionMatchUps,
7114
+ roundMatchUps,
7115
+ roundProfile,
7116
+ matchUpsMap,
7117
+ matchUps
7118
+ };
7112
7119
  function addMatchUpContext({
7113
7120
  scheduleVisibilityFilters: scheduleVisibilityFilters2,
7114
7121
  sourceDrawPositionRanges,
@@ -8554,7 +8561,7 @@ function parseScoreString({
8554
8561
  isSide1: winningSide === 2,
8555
8562
  tiebreakTo
8556
8563
  });
8557
- const setTiebreak = side1TiebreakPerspective || [];
8564
+ const setTiebreak = side1TiebreakPerspective ?? [];
8558
8565
  const [side1Score, side2Score] = setScores || [];
8559
8566
  const [side1TiebreakScore, side2TiebreakScore] = matchTiebreak || setTiebreak || [];
8560
8567
  return {
@@ -9869,12 +9876,12 @@ function matchUpActions$1({
9869
9876
  if (!tournamentRecord)
9870
9877
  return { error: MISSING_TOURNAMENT_RECORD };
9871
9878
  if (!drawId) {
9872
- const matchUps = allTournamentMatchUps({ tournamentRecord }).matchUps || [];
9879
+ const matchUps = allTournamentMatchUps({ tournamentRecord }).matchUps ?? [];
9873
9880
  drawId = matchUps.reduce((drawId2, candidate) => {
9874
9881
  return candidate.matchUpId === matchUpId ? candidate.drawId : drawId2;
9875
9882
  }, void 0);
9876
- const events = tournamentRecord.events || [];
9877
- const drawDefinitions = events.map((event2) => event2.drawDefinitions || []).flat();
9883
+ const events = tournamentRecord.events ?? [];
9884
+ const drawDefinitions = events.map((event2) => event2.drawDefinitions ?? []).flat();
9878
9885
  drawDefinition = drawDefinitions.reduce(
9879
9886
  (drawDefinition2, candidate) => {
9880
9887
  return candidate.drawId === drawId ? candidate : drawDefinition2;
@@ -9888,7 +9895,7 @@ function matchUpActions$1({
9888
9895
  drawDefinition,
9889
9896
  event
9890
9897
  });
9891
- policyDefinitions = policyDefinitions || attachedPolicy;
9898
+ policyDefinitions = policyDefinitions ?? attachedPolicy;
9892
9899
  if (drawDefinition) {
9893
9900
  return matchUpActions$2({
9894
9901
  tournamentParticipants: tournamentRecord.participants,
@@ -9959,7 +9966,6 @@ function getVenuesAndCourts({
9959
9966
  tournamentIds.forEach((tournamentId) => {
9960
9967
  const tournamentRecord = tournamentRecords[tournamentId];
9961
9968
  for (const venue of tournamentRecord.venues || []) {
9962
- tournamentRecord.venues;
9963
9969
  if (venueIds.length && !venueIds.includes(venue.venueId))
9964
9970
  continue;
9965
9971
  if (ignoreDisabled) {
@@ -10558,12 +10564,12 @@ function getParticipantEventDetails({
10558
10564
  if (!participantId)
10559
10565
  return { error: MISSING_PARTICIPANT_ID };
10560
10566
  const relevantParticipantIds = [participantId].concat(
10561
- (tournamentRecord.participants || []).filter(
10567
+ (tournamentRecord.participants ?? []).filter(
10562
10568
  (participant) => participant?.participantType && [TEAM$2, PAIR].includes(participant.participantType) && participant.individualParticipantIds?.includes(participantId)
10563
10569
  ).map((participant) => participant.participantId)
10564
10570
  );
10565
- const relevantEvents = (tournamentRecord.events || []).filter((event) => {
10566
- const enteredParticipantIds = (event?.entries || []).map(
10571
+ const relevantEvents = (tournamentRecord.events ?? []).filter((event) => {
10572
+ const enteredParticipantIds = (event?.entries ?? []).map(
10567
10573
  (entry) => entry.participantId
10568
10574
  );
10569
10575
  return overlap(enteredParticipantIds, relevantParticipantIds);
@@ -11355,7 +11361,7 @@ function filterParticipants({
11355
11361
  );
11356
11362
  if (event.eventType === SINGLES)
11357
11363
  return enteredParticipantIds;
11358
- const individualParticipantIds = (tournamentRecord?.participants || []).filter(
11364
+ const individualParticipantIds = (tournamentRecord?.participants ?? []).filter(
11359
11365
  (participant) => enteredParticipantIds.includes(participant.participantId)
11360
11366
  ).map((participant) => participant.individualParticipantIds).flat(1);
11361
11367
  return enteredParticipantIds.concat(...individualParticipantIds);
@@ -13074,7 +13080,7 @@ function getContainedStructures({
13074
13080
  const containerStructures = {};
13075
13081
  const structureContainers = drawDefinitions.map((dd) => dd?.structures?.filter((structure) => structure?.structures)).flat().filter(Boolean);
13076
13082
  for (const structureContainer of structureContainers) {
13077
- const { structures, structureId } = structureContainer || {};
13083
+ const { structures, structureId } = structureContainer ?? {};
13078
13084
  structures && structureId && (containedStructures[structureId] = structures?.map(
13079
13085
  (structure) => structure.structureId
13080
13086
  )) && structures.forEach(
@@ -14552,13 +14558,42 @@ function positionActions(params) {
14552
14558
 
14553
14559
  const hasParticipantId = (o) => o?.participantId;
14554
14560
 
14555
- function getStructureGroups({ drawDefinition }) {
14561
+ function getStructureGroups({
14562
+ drawDefinition
14563
+ }) {
14564
+ const structures = drawDefinition.structures || [];
14556
14565
  const links = drawDefinition.links || [];
14566
+ const structureProfiles = /* @__PURE__ */ new Map();
14567
+ const initStructureProfile = (structureId) => {
14568
+ const profile = structureProfiles.get(structureId) || structureProfiles.set(structureId, {
14569
+ drawSources: [],
14570
+ drawTargets: [],
14571
+ progeny: [],
14572
+ sources: [],
14573
+ targets: []
14574
+ }) && structureProfiles.get(structureId);
14575
+ if (profile && !profile?.stage) {
14576
+ const structure = structures.find(
14577
+ (structure2) => structure2.structureId === structureId
14578
+ );
14579
+ profile.stage = structure?.stage;
14580
+ }
14581
+ return profile;
14582
+ };
14557
14583
  const sourceStructureIds = {};
14558
14584
  const hasDrawFeedProfile = {};
14559
14585
  let linkedStructureIds = links.map((link) => {
14560
14586
  const sourceId = link.source.structureId;
14561
14587
  const targetId = link.target.structureId;
14588
+ const sourceProfile = initStructureProfile(sourceId);
14589
+ const targetProfile = initStructureProfile(targetId);
14590
+ if ([BOTTOM_UP, TOP_DOWN, RANDOM, WATERFALL].includes(link.target.feedProfile)) {
14591
+ sourceProfile?.targets.push(targetId);
14592
+ targetProfile?.sources.push(sourceId);
14593
+ } else if (link.target.feedProfile === DRAW) {
14594
+ targetProfile?.drawSources.push(sourceId);
14595
+ sourceProfile?.drawTargets.push(targetId);
14596
+ }
14562
14597
  hasDrawFeedProfile[targetId] = hasDrawFeedProfile[targetId] || link.target.feedProfile === DRAW;
14563
14598
  sourceStructureIds[targetId] = unique([
14564
14599
  ...sourceStructureIds[targetId] || [],
@@ -14566,6 +14601,56 @@ function getStructureGroups({ drawDefinition }) {
14566
14601
  ]).filter(Boolean);
14567
14602
  return [link.source.structureId, link.target.structureId];
14568
14603
  });
14604
+ for (const structureId of structureProfiles.keys()) {
14605
+ const profile = structureProfiles.get(structureId);
14606
+ if (profile) {
14607
+ const sourceIds = profile.targets ?? [];
14608
+ while (sourceIds.length) {
14609
+ const sourceId = sourceIds.pop();
14610
+ const sourceProfile = sourceId && structureProfiles[sourceId];
14611
+ if (sourceProfile?.targets?.length) {
14612
+ sourceIds.push(...sourceProfile.targets);
14613
+ } else if (sourceProfile) {
14614
+ profile.rootStage = sourceProfile.stage;
14615
+ }
14616
+ }
14617
+ if (!profile.rootStage)
14618
+ profile.rootStage = profile.stage;
14619
+ if (!profile.targets?.length) {
14620
+ const targetIds = profile.sources ?? [];
14621
+ while (targetIds.length) {
14622
+ const targetId = targetIds.pop();
14623
+ const targetProfile = targetId && structureProfiles[targetId];
14624
+ if (targetProfile?.sources?.length) {
14625
+ for (const id of targetProfile.sources) {
14626
+ if (!profile.progeny?.includes(id))
14627
+ profile.progeny?.push(id);
14628
+ }
14629
+ targetIds.push(...targetProfile.sources);
14630
+ }
14631
+ }
14632
+ }
14633
+ }
14634
+ }
14635
+ let maxQualifyingDepth = 0;
14636
+ for (const structureId of structureProfiles.keys()) {
14637
+ const profile = structureProfiles.get(structureId);
14638
+ if (profile && profile.rootStage === QUALIFYING) {
14639
+ const drawTargets = [profile.drawTargets?.[0]];
14640
+ let distanceFromMain = 0;
14641
+ while (drawTargets.length) {
14642
+ distanceFromMain += 1;
14643
+ const drawTarget = drawTargets.pop();
14644
+ const targetProfile = drawTarget ? structureProfiles.get(drawTarget) : void 0;
14645
+ if (targetProfile?.drawTargets?.length) {
14646
+ drawTargets.push(targetProfile.drawTargets[0]);
14647
+ }
14648
+ }
14649
+ profile.distanceFromMain = distanceFromMain;
14650
+ if (distanceFromMain > maxQualifyingDepth)
14651
+ maxQualifyingDepth = distanceFromMain;
14652
+ }
14653
+ }
14569
14654
  const iterations = linkedStructureIds.length;
14570
14655
  generateRange(0, Math.ceil(iterations / 2)).forEach(() => {
14571
14656
  linkedStructureIds = generateRange(0, iterations).map((index) => {
@@ -14584,7 +14669,6 @@ function getStructureGroups({ drawDefinition }) {
14584
14669
  }, true);
14585
14670
  const structureGroups = [groupedStructureIds].filter(Boolean);
14586
14671
  const linkCheck = [groupedStructureIds].filter(Boolean);
14587
- const structures = drawDefinition.structures || [];
14588
14672
  structures.forEach((structure) => {
14589
14673
  const { structureId, stage } = structure;
14590
14674
  const existingGroup = structureGroups.find((group) => {
@@ -14593,12 +14677,17 @@ function getStructureGroups({ drawDefinition }) {
14593
14677
  if (!existingGroup) {
14594
14678
  structureGroups.push([structureId]);
14595
14679
  if (stage !== VOLUNTARY_CONSOLATION)
14596
- linkCheck.push(structureId);
14680
+ linkCheck.push([structureId]);
14597
14681
  }
14598
14682
  });
14599
14683
  const allStructuresLinked = allLinkStructuresLinked && linkCheck.length === 1;
14684
+ if (!links?.length && structures.length === 1) {
14685
+ initStructureProfile(structures[0].structureId);
14686
+ }
14600
14687
  return {
14688
+ structureProfiles: Object.fromEntries(structureProfiles),
14601
14689
  allStructuresLinked,
14690
+ maxQualifyingDepth,
14602
14691
  sourceStructureIds,
14603
14692
  hasDrawFeedProfile,
14604
14693
  structureGroups
@@ -14663,12 +14752,18 @@ function getDrawData(params) {
14663
14752
  }
14664
14753
  return structure;
14665
14754
  }).sort((a, b) => structureSort(a, b, sortConfig)).map((structure) => {
14666
- const { structureId } = structure;
14755
+ if (!structure)
14756
+ return;
14757
+ const structureId = structure?.structureId;
14667
14758
  let seedAssignments = [];
14668
- if ([MAIN, CONSOLATION, PLAY_OFF].includes(structure.stage)) {
14759
+ if (structure.stage && [
14760
+ StageTypeEnum.Main,
14761
+ StageTypeEnum.Consolation,
14762
+ StageTypeEnum.PlayOff
14763
+ ].includes(structure.stage)) {
14669
14764
  seedAssignments = mainStageSeedAssignments;
14670
14765
  }
14671
- if (structure.stage === QUALIFYING) {
14766
+ if (structure?.stage === QUALIFYING) {
14672
14767
  seedAssignments = qualificationStageSeedAssignments;
14673
14768
  }
14674
14769
  const { matchUps, roundMatchUps, roundProfile } = getAllStructureMatchUps({
@@ -14699,7 +14794,7 @@ function getDrawData(params) {
14699
14794
  participantResult: extension.value
14700
14795
  };
14701
14796
  }).filter((f) => f?.participantResult);
14702
- const structureInfo = (({
14797
+ const structureInfo = structure ? (({
14703
14798
  stageSequence,
14704
14799
  structureName,
14705
14800
  structureType,
@@ -14711,7 +14806,7 @@ function getDrawData(params) {
14711
14806
  structureType,
14712
14807
  matchUpFormat,
14713
14808
  stage
14714
- }))(structure);
14809
+ }))(structure) : {};
14715
14810
  structureInfo.sourceStructureIds = sourceStructureIds[structureId];
14716
14811
  structureInfo.hasDrawFeedProfile = hasDrawFeedProfile[structureId];
14717
14812
  structureInfo.positionAssignments = positionAssignments;