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.
package/dist/index.mjs CHANGED
@@ -2382,7 +2382,7 @@ const matchUpFormatCode = {
2382
2382
  };
2383
2383
 
2384
2384
  function factoryVersion() {
2385
- return "1.8.22";
2385
+ return "1.8.24";
2386
2386
  }
2387
2387
 
2388
2388
  function getObjectTieFormat(obj) {
@@ -3811,18 +3811,17 @@ function getTallyReport({ matchUps, order, report }) {
3811
3811
  readable.push(excluded);
3812
3812
  } else {
3813
3813
  const floatSort = (a, b) => parseFloat(step.reversed ? a : b) - parseFloat(step.reversed ? b : a);
3814
+ const participantsCount = step.groups ? Object.values(step.groups).flat(Infinity).length : step.participantIds?.length ?? 0;
3814
3815
  const getExplanation = (step2) => {
3815
- Object.keys(step2.groups).sort(floatSort).forEach((key) => {
3816
+ step2.groups && Object.keys(step2.groups).sort(floatSort).forEach((key) => {
3816
3817
  const participantNames = step2.groups[key].map((participantId) => participants[participantId]).join(", ");
3817
3818
  const explanation = `${key} ${step2.attribute}: ${participantNames}`;
3818
3819
  readable.push(explanation);
3819
3820
  });
3820
3821
  };
3821
3822
  const reversed = step.reversed ? " in reverse order" : "";
3822
- const participantsCount = Object.values(step.groups).flat(
3823
- Infinity
3824
- ).length;
3825
- const description = `Step ${i + 1}: ${participantsCount} particiants were grouped${reversed} by ${step.attribute}`;
3823
+ const action = step.groups ? "grouped" : "separated";
3824
+ const description = `Step ${i + 1}: ${participantsCount} particiants were ${action}${reversed} by ${step.attribute}`;
3826
3825
  readable.push(description);
3827
3826
  if (step.idsFilter) {
3828
3827
  const note = `${step.attribute} was calculated considering ONLY TIED PARTICIPANTS`;
@@ -3838,7 +3837,7 @@ function getTallyReport({ matchUps, order, report }) {
3838
3837
  const { participantId, resolved } = orderEntry;
3839
3838
  const pOrder = orderEntry.groupOrder || orderEntry.provisionalOrder;
3840
3839
  readable.push(
3841
- `${pOrder}: ${participants[participantId]} => resolved: ${resolved}`
3840
+ `${pOrder}: ${participants[participantId]} => resolved: ${!!resolved}`
3842
3841
  );
3843
3842
  });
3844
3843
  return readable.join("\r\n");
@@ -3927,7 +3926,7 @@ function getGroupOrder(params) {
3927
3926
  report.push({ attribute, groups: orderedTallyGroups });
3928
3927
  const groupOrder = Object.keys(orderedTallyGroups).map((key) => parseFloat(key)).sort((a, b) => b - a).map((key) => orderedTallyGroups[key]).map((participantIds) => {
3929
3928
  const result = groupSubSort({ participantIds, ...params });
3930
- report.push(result.report);
3929
+ report.push(...result.report || []);
3931
3930
  return result.order;
3932
3931
  }).flat(Infinity);
3933
3932
  let groupPosition = 1;
@@ -4019,7 +4018,7 @@ function processAttribute({
4019
4018
  tallyPolicy,
4020
4019
  matchUps
4021
4020
  });
4022
- report.push(result.report);
4021
+ report.push(...result.report || []);
4023
4022
  return result.order;
4024
4023
  }).flat(Infinity);
4025
4024
  }
@@ -4033,6 +4032,9 @@ function groupSubSort({
4033
4032
  tallyPolicy,
4034
4033
  matchUps
4035
4034
  }) {
4035
+ const excludedDirectives = [];
4036
+ const report = [];
4037
+ let result;
4036
4038
  if (participantIds?.length === 1) {
4037
4039
  const participantId = participantIds[0];
4038
4040
  return {
@@ -4041,13 +4043,13 @@ function groupSubSort({
4041
4043
  }
4042
4044
  if (participantIds?.length === 2 && (!tallyPolicy?.headToHead || !tallyPolicy.headToHead.disabled && !disableHeadToHead)) {
4043
4045
  const result2 = headToHeadWinner({ participantIds, participantResults });
4044
- if (result2)
4045
- return { order: [result2], headToHeadWinner: result2[0].participantId };
4046
+ if (result2) {
4047
+ const headToHeadWinner2 = result2[0].participantId;
4048
+ report.push({ attribute: "head2Head", participantIds, headToHeadWinner: headToHeadWinner2 });
4049
+ return { order: [result2], headToHeadWinner: headToHeadWinner2, report };
4050
+ }
4046
4051
  }
4047
4052
  const directives = tallyPolicy?.tallyDirectives || headToHeadTallyDirectives;
4048
- const excludedDirectives = [];
4049
- const report = [];
4050
- let result;
4051
4053
  const filteredDirectives = directives.filter((directive) => {
4052
4054
  const keepDirective = isNumeric(directive.maxParticipants) && participantIds?.length > directive.maxParticipants ? false : true;
4053
4055
  if (!keepDirective)
@@ -4857,7 +4859,7 @@ function getMatchUpFormatTiming({
4857
4859
  }) {
4858
4860
  if (!tournamentRecord)
4859
4861
  return { error: MISSING_TOURNAMENT_RECORD };
4860
- eventType = eventType || event?.eventType || TypeEnum.Singles;
4862
+ eventType = eventType ?? event?.eventType ?? TypeEnum.Singles;
4861
4863
  const defaultTiming = {
4862
4864
  averageTimes: [{ minutes: { default: defaultAverageMinutes } }],
4863
4865
  recoveryTimes: [{ minutes: { default: defaultRecoveryMinutes } }]
@@ -5507,7 +5509,7 @@ function findVenue({
5507
5509
  if (!venue && tournamentRecords) {
5508
5510
  const linkedTournamentIds = getLinkedTournamentIds({
5509
5511
  tournamentRecords
5510
- }).linkedTournamentIds || [];
5512
+ }).linkedTournamentIds ?? [];
5511
5513
  const relevantIds = linkedTournamentIds[tournamentRecord.tournamentId];
5512
5514
  for (const tournamentId of relevantIds) {
5513
5515
  const record = tournamentRecords[tournamentId];
@@ -6185,7 +6187,7 @@ function getPairedParticipant({
6185
6187
  result: { error: MISSING_PARTICIPANT_IDS },
6186
6188
  stack
6187
6189
  });
6188
- tournamentParticipants = tournamentParticipants || tournamentRecord?.participants || [];
6190
+ tournamentParticipants = tournamentParticipants ?? tournamentRecord?.participants ?? [];
6189
6191
  const existingPairedParticipants = tournamentParticipants.filter(
6190
6192
  (participant) => participant.participantType === PAIR && intersection(participantIds, participant.individualParticipantIds).length === participantIds.length && participant.individualParticipantIds.length === participantIds.length
6191
6193
  );
@@ -7775,7 +7777,8 @@ const POLICY_ROUND_NAMING_DEFAULT = {
7775
7777
  [POLICY_TYPE_ROUND_NAMING]: {
7776
7778
  policyName: "Round Naming Default",
7777
7779
  namingConventions: {
7778
- round: "Round"
7780
+ round: "Round",
7781
+ pre: "Pre"
7779
7782
  },
7780
7783
  qualifyingFinishMap: {
7781
7784
  1: "Final"
@@ -7819,12 +7822,11 @@ function getRoundContextProfile({
7819
7822
  const roundNamingProfile = {};
7820
7823
  const defaultRoundNamingPolicy = POLICY_ROUND_NAMING_DEFAULT[POLICY_TYPE_ROUND_NAMING];
7821
7824
  const isQualifying = structure.stage === QUALIFYING;
7822
- const qualifyingFinishgMap = isQualifying && (roundNamingPolicy?.qualifyingFinishMap || defaultRoundNamingPolicy?.qualifyingFinishMap || {});
7823
7825
  const qualifyingStageSequences = isQualifying ? Math.max(
7824
7826
  ...(drawDefinition?.structures ?? []).filter((structure2) => structure2.stage === QUALIFYING).map(({ stageSequence }) => stageSequence ?? 1),
7825
7827
  0
7826
7828
  ) : 0;
7827
- const preQualifyingSequence = qualifyingStageSequences ? qualifyingStageSequences - (structure.stageSequence || 1) || "" : "";
7829
+ const preQualifyingSequence = (structure.stageSequence ?? 1) < qualifyingStageSequences ? structure.stageSequence ?? 1 : "";
7828
7830
  const preQualifyingAffix = preQualifyingSequence ? roundNamingPolicy?.affixes?.preQualifying || defaultRoundNamingPolicy.affixes.preQualifying || "" : "";
7829
7831
  const roundNamingMap = roundNamingPolicy?.roundNamingMap || defaultRoundNamingPolicy.roundNamingMap || {};
7830
7832
  const abbreviatedRoundNamingMap = roundNamingPolicy?.abbreviatedRoundNamingMap || defaultRoundNamingPolicy.abbreviatedRoundNamingMap || {};
@@ -7848,6 +7850,7 @@ function getRoundContextProfile({
7848
7850
  })
7849
7851
  );
7850
7852
  } else {
7853
+ const qualifyingFinishgMap = isQualifying && (roundNamingPolicy?.qualifyingFinishMap || defaultRoundNamingPolicy?.qualifyingFinishMap || {});
7851
7854
  Object.assign(
7852
7855
  roundNamingProfile,
7853
7856
  ...roundProfileKeys.map((round) => {
@@ -8133,7 +8136,13 @@ function getAllStructureMatchUps({
8133
8136
  matchUps
8134
8137
  }));
8135
8138
  }
8136
- return { matchUps, roundMatchUps, roundProfile, collectionPositionMatchUps };
8139
+ return {
8140
+ collectionPositionMatchUps,
8141
+ roundMatchUps,
8142
+ roundProfile,
8143
+ matchUpsMap,
8144
+ matchUps
8145
+ };
8137
8146
  function addMatchUpContext({
8138
8147
  scheduleVisibilityFilters: scheduleVisibilityFilters2,
8139
8148
  sourceDrawPositionRanges,
@@ -10116,8 +10125,10 @@ function modifyMatchUpScore({
10116
10125
  const matchUpFilters = isDualMatchUp ? { matchUpTypes: [TEAM$2] } : void 0;
10117
10126
  const { matchUps } = getAllStructureMatchUps({
10118
10127
  afterRecoveryTimes: false,
10128
+ tournamentRecord,
10119
10129
  inContext: true,
10120
10130
  matchUpFilters,
10131
+ drawDefinition,
10121
10132
  structure: structure2,
10122
10133
  event
10123
10134
  });
@@ -17811,7 +17822,7 @@ function parseScoreString({
17811
17822
  isSide1: winningSide === 2,
17812
17823
  tiebreakTo
17813
17824
  });
17814
- const setTiebreak = side1TiebreakPerspective || [];
17825
+ const setTiebreak = side1TiebreakPerspective ?? [];
17815
17826
  const [side1Score, side2Score] = setScores || [];
17816
17827
  const [side1TiebreakScore, side2TiebreakScore] = matchTiebreak || setTiebreak || [];
17817
17828
  return {
@@ -18001,7 +18012,9 @@ function getSuper(values, index) {
18001
18012
  values.slice(index, index + 2),
18002
18013
  index ? values.slice(0, 1) : values.slice(2)
18003
18014
  ].map((n) => parseInt(n.join("")));
18004
- const scores = index ? parts.reverse() : parts;
18015
+ if (index)
18016
+ parts.reverse();
18017
+ const scores = parts;
18005
18018
  const diff = Math.abs(scores.reduce((a, b) => +a - +b));
18006
18019
  if (diff >= 2)
18007
18020
  return scores.join("-");
@@ -19012,7 +19025,7 @@ function handleNumeric(params) {
19012
19025
  if (superParse && score !== superParse) {
19013
19026
  applied.push("parsedSuperPattern");
19014
19027
  }
19015
- score = superParse || score;
19028
+ score = superParse ?? score;
19016
19029
  }
19017
19030
  }
19018
19031
  return { score, applied, matchUpStatus };
@@ -19053,7 +19066,9 @@ function sensibleSets({ score, matchUpStatus, attributes }) {
19053
19066
  const maxSetScore = Math.max(...sideScores);
19054
19067
  const maxIndex = setScores.indexOf(maxSetScore);
19055
19068
  const sensibleSetScores = [maxSetScore, maxSetScore - 1];
19056
- const sensibleSetScore = maxIndex ? sensibleSetScores.reverse().join("-") : sensibleSetScores.join("-");
19069
+ if (maxIndex)
19070
+ sensibleSetScores.reverse();
19071
+ const sensibleSetScore = sensibleSetScores.join("-");
19057
19072
  return sensibleSetScore + tiebreak;
19058
19073
  }
19059
19074
  } else if (set.length === 2 && isNumeric(set)) {
@@ -19072,7 +19087,7 @@ function sensibleSets({ score, matchUpStatus, attributes }) {
19072
19087
  const splitMax = max.toString().split("");
19073
19088
  const reasonable = splitMax.find(
19074
19089
  (value) => parseInt(value) > min || index && parseInt(value) <= maxSetValue
19075
- ) || splitMax[0];
19090
+ ) ?? splitMax[0];
19076
19091
  if (reasonable) {
19077
19092
  set = minIndex ? [reasonable, min].join("-") : [min, reasonable].join("-");
19078
19093
  }
@@ -19536,7 +19551,6 @@ function getVenuesAndCourts({
19536
19551
  tournamentIds.forEach((tournamentId) => {
19537
19552
  const tournamentRecord = tournamentRecords[tournamentId];
19538
19553
  for (const venue of tournamentRecord.venues || []) {
19539
- tournamentRecord.venues;
19540
19554
  if (venueIds.length && !venueIds.includes(venue.venueId))
19541
19555
  continue;
19542
19556
  if (ignoreDisabled) {
@@ -21007,7 +21021,7 @@ function getContainedStructures({
21007
21021
  const containerStructures = {};
21008
21022
  const structureContainers = drawDefinitions.map((dd) => dd?.structures?.filter((structure) => structure?.structures)).flat().filter(Boolean);
21009
21023
  for (const structureContainer of structureContainers) {
21010
- const { structures, structureId } = structureContainer || {};
21024
+ const { structures, structureId } = structureContainer ?? {};
21011
21025
  structures && structureId && (containedStructures[structureId] = structures?.map(
21012
21026
  (structure) => structure.structureId
21013
21027
  )) && structures.forEach(
@@ -23079,7 +23093,10 @@ function getAffectedTargetStructureIds({
23079
23093
  return { structureIds };
23080
23094
  }
23081
23095
 
23082
- function getPlayoffStructures({ drawDefinition, structureId }) {
23096
+ function getPlayoffStructures({
23097
+ drawDefinition,
23098
+ structureId
23099
+ }) {
23083
23100
  if (!drawDefinition)
23084
23101
  return { error: MISSING_DRAW_DEFINITION };
23085
23102
  const { structure } = findStructure({ drawDefinition, structureId });
@@ -23214,7 +23231,7 @@ function allPlayoffPositionsFilled(params) {
23214
23231
  return assignment?.bye || assignment?.participantId;
23215
23232
  }
23216
23233
  ).length;
23217
- return structurePositionsFilled && allFilled;
23234
+ return !!(structurePositionsFilled && allFilled);
23218
23235
  },
23219
23236
  !!playoffStructures.length
23220
23237
  );
@@ -27875,7 +27892,7 @@ function filterParticipants({
27875
27892
  );
27876
27893
  if (event.eventType === SINGLES)
27877
27894
  return enteredParticipantIds;
27878
- const individualParticipantIds = (tournamentRecord?.participants || []).filter(
27895
+ const individualParticipantIds = (tournamentRecord?.participants ?? []).filter(
27879
27896
  (participant) => enteredParticipantIds.includes(participant.participantId)
27880
27897
  ).map((participant) => participant.individualParticipantIds).flat(1);
27881
27898
  return enteredParticipantIds.concat(...individualParticipantIds);
@@ -28242,7 +28259,7 @@ function addPenalty$1({
28242
28259
  return { error: MISSING_PARTICIPANT_ID };
28243
28260
  if (!penaltyType)
28244
28261
  return { error: MISSING_PENALTY_TYPE };
28245
- const participants = tournamentRecord?.participants || [];
28262
+ const participants = tournamentRecord?.participants ?? [];
28246
28263
  const relevantParticipants = participants.filter(
28247
28264
  (participant) => participantIds.includes(participant.participantId)
28248
28265
  );
@@ -28285,13 +28302,13 @@ function removePenalty$1({
28285
28302
  return { error: MISSING_TOURNAMENT_RECORD };
28286
28303
  if (!penaltyId)
28287
28304
  return { error: MISSING_PENALTY_ID };
28288
- const participants = tournamentRecord?.participants || [];
28305
+ const participants = tournamentRecord?.participants ?? [];
28289
28306
  const modifiedParticipants = [];
28290
28307
  let penaltyRemoved = false;
28291
28308
  let removedPenalty;
28292
28309
  participants.forEach((participant) => {
28293
28310
  let participantModified = false;
28294
- participant.penalties = (participant.penalties || []).filter((penalty) => {
28311
+ participant.penalties = (participant.penalties ?? []).filter((penalty) => {
28295
28312
  if (penalty.penaltyId === penaltyId) {
28296
28313
  participantModified = true;
28297
28314
  if (!penaltyRemoved) {
@@ -28320,10 +28337,10 @@ function getTournamentPenalties({
28320
28337
  }) {
28321
28338
  if (!tournamentRecord)
28322
28339
  return { error: MISSING_TOURNAMENT_RECORD };
28323
- const participants = tournamentRecord?.participants || [];
28340
+ const participants = tournamentRecord?.participants ?? [];
28324
28341
  const allPenalties = participants.reduce((penalties, participant) => {
28325
28342
  const { participantId } = participant;
28326
- (participant.penalties || []).forEach((penalty) => {
28343
+ (participant.penalties ?? []).forEach((penalty) => {
28327
28344
  const { penaltyId } = penalty || {};
28328
28345
  if (penalties[penaltyId]) {
28329
28346
  penalties[penaltyId].participants.push(participantId);
@@ -28349,7 +28366,7 @@ function modifyPenalty$1({
28349
28366
  return { error: INVALID_VALUES, modifications };
28350
28367
  if (!penaltyId)
28351
28368
  return { error: MISSING_PENALTY_ID };
28352
- const participants = tournamentRecord?.participants || [];
28369
+ const participants = tournamentRecord?.participants ?? [];
28353
28370
  const validAttributes = Object.keys(penaltyTemplate()).filter(
28354
28371
  (attribute) => attribute !== "penaltyId"
28355
28372
  );
@@ -28362,7 +28379,7 @@ function modifyPenalty$1({
28362
28379
  const modifiedParticipants = [];
28363
28380
  participants.forEach((participant) => {
28364
28381
  let participantModified = false;
28365
- participant.penalties = (participant.penalties || []).map((penalty) => {
28382
+ participant.penalties = (participant.penalties ?? []).map((penalty) => {
28366
28383
  if (penalty.penaltyId === penaltyId) {
28367
28384
  participantModified = true;
28368
28385
  validModificationAttributes.forEach(
@@ -28399,7 +28416,7 @@ function addPenalty(params) {
28399
28416
  if (tournamentParticipantIds.length) {
28400
28417
  const result = addPenalty$1({
28401
28418
  ...params,
28402
- penaltyId: params.penaltyId || penaltyId,
28419
+ penaltyId: params.penaltyId ?? penaltyId,
28403
28420
  tournamentRecord,
28404
28421
  participantIds: tournamentParticipantIds
28405
28422
  });
@@ -28438,7 +28455,7 @@ function getCompetitionPenalties({
28438
28455
  const allPenalties = [];
28439
28456
  for (const tournamentRecord of Object.values(tournamentRecords)) {
28440
28457
  const { penalties } = getTournamentPenalties({ tournamentRecord });
28441
- allPenalties.push(...penalties || []);
28458
+ allPenalties.push(...penalties ?? []);
28442
28459
  }
28443
28460
  return { penalties: allPenalties };
28444
28461
  }
@@ -33748,18 +33765,18 @@ function clearScheduledMatchUps$1({
33748
33765
  const inContextMatchUps = allTournamentMatchUps({
33749
33766
  matchUpFilters: { scheduledDates },
33750
33767
  tournamentRecord
33751
- }).matchUps || [];
33768
+ }).matchUps ?? [];
33752
33769
  const relevantMatchUpIds = inContextMatchUps.filter(
33753
33770
  (matchUp) => matchUp.matchUpStatus && !ignoreMatchUpStatuses.includes(matchUp.matchUpStatus) && hasSchedule({ schedule: matchUp.schedule, scheduleAttributes }) && (!venueIds?.length || venueIds.includes(matchUp.schedule.venueId))
33754
33771
  ).map(getMatchUpId);
33755
33772
  const matchUps = allTournamentMatchUps({
33756
33773
  tournamentRecord,
33757
33774
  inContext: false
33758
- }).matchUps || [];
33775
+ }).matchUps ?? [];
33759
33776
  let clearedScheduleCount = 0;
33760
33777
  for (const matchUp of matchUps) {
33761
33778
  if (relevantMatchUpIds.includes(matchUp.matchUpId)) {
33762
- matchUp.timeItems = (matchUp.timeItems || []).filter(
33779
+ matchUp.timeItems = (matchUp.timeItems ?? []).filter(
33763
33780
  (timeItem) => timeItem?.itemType && ![
33764
33781
  ALLOCATE_COURTS,
33765
33782
  ASSIGN_COURT,
@@ -36712,12 +36729,12 @@ function matchUpActions$1({
36712
36729
  if (!tournamentRecord)
36713
36730
  return { error: MISSING_TOURNAMENT_RECORD };
36714
36731
  if (!drawId) {
36715
- const matchUps = allTournamentMatchUps({ tournamentRecord }).matchUps || [];
36732
+ const matchUps = allTournamentMatchUps({ tournamentRecord }).matchUps ?? [];
36716
36733
  drawId = matchUps.reduce((drawId2, candidate) => {
36717
36734
  return candidate.matchUpId === matchUpId ? candidate.drawId : drawId2;
36718
36735
  }, void 0);
36719
- const events = tournamentRecord.events || [];
36720
- const drawDefinitions = events.map((event2) => event2.drawDefinitions || []).flat();
36736
+ const events = tournamentRecord.events ?? [];
36737
+ const drawDefinitions = events.map((event2) => event2.drawDefinitions ?? []).flat();
36721
36738
  drawDefinition = drawDefinitions.reduce(
36722
36739
  (drawDefinition2, candidate) => {
36723
36740
  return candidate.drawId === drawId ? candidate : drawDefinition2;
@@ -36731,7 +36748,7 @@ function matchUpActions$1({
36731
36748
  drawDefinition,
36732
36749
  event
36733
36750
  });
36734
- policyDefinitions = policyDefinitions || attachedPolicy;
36751
+ policyDefinitions = policyDefinitions ?? attachedPolicy;
36735
36752
  if (drawDefinition) {
36736
36753
  return matchUpActions$2({
36737
36754
  tournamentParticipants: tournamentRecord.participants,
@@ -37107,7 +37124,7 @@ function deleteVenue$1({
37107
37124
  const matchUpsToUnschedule = allTournamentMatchUps({
37108
37125
  tournamentRecord,
37109
37126
  contextFilters
37110
- }).matchUps || [];
37127
+ }).matchUps ?? [];
37111
37128
  if (!matchUpsToUnschedule.length || force) {
37112
37129
  for (const matchUp of matchUpsToUnschedule) {
37113
37130
  const result = removeCourtAssignment({
@@ -37122,7 +37139,7 @@ function deleteVenue$1({
37122
37139
  return deletionMessage({ matchUpsCount: matchUpsToUnschedule.length });
37123
37140
  }
37124
37141
  let deleted;
37125
- tournamentRecord.venues = (tournamentRecord.venues || []).filter(
37142
+ tournamentRecord.venues = (tournamentRecord.venues ?? []).filter(
37126
37143
  (venue) => {
37127
37144
  if (venue?.venueId !== venueId)
37128
37145
  return true;
@@ -37334,7 +37351,7 @@ function deleteCourt$1({
37334
37351
  courtId
37335
37352
  });
37336
37353
  if (!matchUps?.length || force) {
37337
- for (const matchUp of matchUps || []) {
37354
+ for (const matchUp of matchUps ?? []) {
37338
37355
  const result2 = removeCourtAssignment({
37339
37356
  matchUpId: matchUp.matchUpId,
37340
37357
  drawId: matchUp.drawId,
@@ -37345,7 +37362,7 @@ function deleteCourt$1({
37345
37362
  return result2;
37346
37363
  }
37347
37364
  if (venue) {
37348
- venue.courts = (venue.courts || []).filter((courtRecord) => {
37365
+ venue.courts = (venue.courts ?? []).filter((courtRecord) => {
37349
37366
  return courtRecord.courtId !== courtId;
37350
37367
  });
37351
37368
  if (!disableNotice)
@@ -38608,7 +38625,7 @@ function treeMatchUps({
38608
38625
  uuids
38609
38626
  }));
38610
38627
  roundNumber++;
38611
- roundLimit = roundLimit || qualifyingRoundNumber;
38628
+ roundLimit = roundLimit ?? qualifyingRoundNumber;
38612
38629
  while (roundNodes.length > 1) {
38613
38630
  if (qualifyingPositions && roundNodes.length === qualifyingPositions) {
38614
38631
  roundLimit = roundNumber - 1;
@@ -38636,7 +38653,7 @@ function treeMatchUps({
38636
38653
  roundLimit = roundNumber - 1;
38637
38654
  } else {
38638
38655
  matchUps = matchUps.filter(
38639
- (matchUp) => roundLimit && (matchUp.roundNumber || 0) <= roundLimit
38656
+ (matchUp) => roundLimit && (matchUp.roundNumber ?? 0) <= roundLimit
38640
38657
  );
38641
38658
  }
38642
38659
  return { drawSize, matchUps, roundsCount, roundLimit };
@@ -38769,7 +38786,6 @@ function generateQualifyingStructures({
38769
38786
  roundTarget,
38770
38787
  linkType
38771
38788
  });
38772
- targetRoundQualifiersCount = 0;
38773
38789
  roundTarget += 1;
38774
38790
  }
38775
38791
  return {
@@ -38784,6 +38800,7 @@ function generateQualifyingStructures({
38784
38800
 
38785
38801
  function getStructureRoundProfile({
38786
38802
  drawDefinition,
38803
+ matchUpsMap,
38787
38804
  structureId
38788
38805
  }) {
38789
38806
  const result = findStructure({
@@ -38791,9 +38808,12 @@ function getStructureRoundProfile({
38791
38808
  structureId
38792
38809
  });
38793
38810
  if (result.error)
38794
- return result;
38795
- const { matchUps } = getAllStructureMatchUps({ structure: result.structure });
38796
- return getRoundMatchUps$1({ matchUps });
38811
+ return decorateResult({ result });
38812
+ const { matchUps } = getAllStructureMatchUps({
38813
+ structure: result.structure,
38814
+ matchUpsMap
38815
+ });
38816
+ return { ...getRoundMatchUps$1({ matchUps }), matchUps, matchUpsMap };
38797
38817
  }
38798
38818
 
38799
38819
  function getFinishingPositionSourceRoundsMap({
@@ -38844,16 +38864,18 @@ function roundValueRanges(values) {
38844
38864
 
38845
38865
  function getPositionsPlayedOff({
38846
38866
  drawDefinition,
38847
- structureIds
38867
+ structureIds,
38868
+ matchUpsMap
38848
38869
  }) {
38849
38870
  if (structureIds && !Array.isArray(structureIds))
38850
38871
  return { error: INVALID_VALUES, context: { structureIds } };
38851
38872
  if (!drawDefinition)
38852
38873
  return { error: MISSING_DRAW_DEFINITION };
38853
- structureIds = structureIds || (drawDefinition.structures || []).filter((structure) => structure.stage !== QUALIFYING).map(({ structureId }) => structureId);
38874
+ structureIds = structureIds ?? (drawDefinition.structures ?? []).filter((structure) => structure.stage !== QUALIFYING).map(({ structureId }) => structureId);
38854
38875
  const allFinishingPositionRanges = structureIds.map((structureId) => {
38855
38876
  const { roundProfile } = getStructureRoundProfile({
38856
38877
  drawDefinition,
38878
+ matchUpsMap,
38857
38879
  structureId
38858
38880
  });
38859
38881
  const values = roundProfile && Object.values(roundProfile);
@@ -38948,18 +38970,19 @@ function getPlayoffRoundsRanges({ playoffSourceRounds, roundProfile }) {
38948
38970
  function getAvailablePlayoffProfiles$1({ drawDefinition, structureId }) {
38949
38971
  if (!drawDefinition)
38950
38972
  return { error: MISSING_DRAW_DEFINITION };
38951
- const { positionsNotPlayedOff, positionsPlayedOff } = getPositionsPlayedOff({
38973
+ const { matchUps, matchUpsMap } = allDrawMatchUps$1({
38974
+ inContext: true,
38952
38975
  drawDefinition
38953
38976
  });
38977
+ const { positionsNotPlayedOff, positionsPlayedOff } = getPositionsPlayedOff({
38978
+ drawDefinition,
38979
+ matchUpsMap
38980
+ });
38954
38981
  const { structures } = getDrawStructures({ drawDefinition });
38955
38982
  const filteredStructures = structures.filter(
38956
38983
  (structure) => !structureId && structure.stage !== VOLUNTARY_CONSOLATION || structure.structureId === structureId
38957
38984
  );
38958
38985
  const available = {};
38959
- const matchUps = allDrawMatchUps$1({
38960
- inContext: true,
38961
- drawDefinition
38962
- }).matchUps;
38963
38986
  for (const structure of filteredStructures) {
38964
38987
  const structureId2 = structure?.structureId;
38965
38988
  const result = availablePlayoffProfiles({
@@ -43378,11 +43401,147 @@ function generateVoluntaryConsolation$1(params) {
43378
43401
  return { links, structures, ...SUCCESS };
43379
43402
  }
43380
43403
 
43404
+ function getStructureGroups({
43405
+ drawDefinition
43406
+ }) {
43407
+ const structures = drawDefinition.structures || [];
43408
+ const links = drawDefinition.links || [];
43409
+ const structureProfiles = /* @__PURE__ */ new Map();
43410
+ const initStructureProfile = (structureId) => {
43411
+ const profile = structureProfiles.get(structureId) || structureProfiles.set(structureId, {
43412
+ drawSources: [],
43413
+ drawTargets: [],
43414
+ progeny: [],
43415
+ sources: [],
43416
+ targets: []
43417
+ }) && structureProfiles.get(structureId);
43418
+ if (profile && !profile?.stage) {
43419
+ const structure = structures.find(
43420
+ (structure2) => structure2.structureId === structureId
43421
+ );
43422
+ profile.stage = structure?.stage;
43423
+ }
43424
+ return profile;
43425
+ };
43426
+ const sourceStructureIds = {};
43427
+ const hasDrawFeedProfile = {};
43428
+ let linkedStructureIds = links.map((link) => {
43429
+ const sourceId = link.source.structureId;
43430
+ const targetId = link.target.structureId;
43431
+ const sourceProfile = initStructureProfile(sourceId);
43432
+ const targetProfile = initStructureProfile(targetId);
43433
+ if ([BOTTOM_UP, TOP_DOWN, RANDOM, WATERFALL].includes(link.target.feedProfile)) {
43434
+ sourceProfile?.targets.push(targetId);
43435
+ targetProfile?.sources.push(sourceId);
43436
+ } else if (link.target.feedProfile === DRAW) {
43437
+ targetProfile?.drawSources.push(sourceId);
43438
+ sourceProfile?.drawTargets.push(targetId);
43439
+ }
43440
+ hasDrawFeedProfile[targetId] = hasDrawFeedProfile[targetId] || link.target.feedProfile === DRAW;
43441
+ sourceStructureIds[targetId] = unique([
43442
+ ...sourceStructureIds[targetId] || [],
43443
+ sourceId
43444
+ ]).filter(Boolean);
43445
+ return [link.source.structureId, link.target.structureId];
43446
+ });
43447
+ for (const structureId of structureProfiles.keys()) {
43448
+ const profile = structureProfiles.get(structureId);
43449
+ if (profile) {
43450
+ const sourceIds = profile.targets ?? [];
43451
+ while (sourceIds.length) {
43452
+ const sourceId = sourceIds.pop();
43453
+ const sourceProfile = sourceId && structureProfiles[sourceId];
43454
+ if (sourceProfile?.targets?.length) {
43455
+ sourceIds.push(...sourceProfile.targets);
43456
+ } else if (sourceProfile) {
43457
+ profile.rootStage = sourceProfile.stage;
43458
+ }
43459
+ }
43460
+ if (!profile.rootStage)
43461
+ profile.rootStage = profile.stage;
43462
+ if (!profile.targets?.length) {
43463
+ const targetIds = profile.sources ?? [];
43464
+ while (targetIds.length) {
43465
+ const targetId = targetIds.pop();
43466
+ const targetProfile = targetId && structureProfiles[targetId];
43467
+ if (targetProfile?.sources?.length) {
43468
+ for (const id of targetProfile.sources) {
43469
+ if (!profile.progeny?.includes(id))
43470
+ profile.progeny?.push(id);
43471
+ }
43472
+ targetIds.push(...targetProfile.sources);
43473
+ }
43474
+ }
43475
+ }
43476
+ }
43477
+ }
43478
+ let maxQualifyingDepth = 0;
43479
+ for (const structureId of structureProfiles.keys()) {
43480
+ const profile = structureProfiles.get(structureId);
43481
+ if (profile && profile.rootStage === QUALIFYING) {
43482
+ const drawTargets = [profile.drawTargets?.[0]];
43483
+ let distanceFromMain = 0;
43484
+ while (drawTargets.length) {
43485
+ distanceFromMain += 1;
43486
+ const drawTarget = drawTargets.pop();
43487
+ const targetProfile = drawTarget ? structureProfiles.get(drawTarget) : void 0;
43488
+ if (targetProfile?.drawTargets?.length) {
43489
+ drawTargets.push(targetProfile.drawTargets[0]);
43490
+ }
43491
+ }
43492
+ profile.distanceFromMain = distanceFromMain;
43493
+ if (distanceFromMain > maxQualifyingDepth)
43494
+ maxQualifyingDepth = distanceFromMain;
43495
+ }
43496
+ }
43497
+ const iterations = linkedStructureIds.length;
43498
+ generateRange(0, Math.ceil(iterations / 2)).forEach(() => {
43499
+ linkedStructureIds = generateRange(0, iterations).map((index) => {
43500
+ const structureIds = linkedStructureIds[index];
43501
+ const mergedWithOverlappingIds = linkedStructureIds.reduce((biggest, ids) => {
43502
+ const hasOverlap = overlap(structureIds, ids);
43503
+ return hasOverlap ? biggest.concat(...ids) : biggest;
43504
+ }, []) || [];
43505
+ return unique(structureIds.concat(...mergedWithOverlappingIds));
43506
+ });
43507
+ });
43508
+ const groupedStructureIds = linkedStructureIds[0];
43509
+ const identityLink = (a, b) => intersection(a, b).length === a.length;
43510
+ const allLinkStructuresLinked = linkedStructureIds.slice(1).reduce((allLinkStructuresLinked2, ids) => {
43511
+ return allLinkStructuresLinked2 && identityLink(ids, groupedStructureIds);
43512
+ }, true);
43513
+ const structureGroups = [groupedStructureIds].filter(Boolean);
43514
+ const linkCheck = [groupedStructureIds].filter(Boolean);
43515
+ structures.forEach((structure) => {
43516
+ const { structureId, stage } = structure;
43517
+ const existingGroup = structureGroups.find((group) => {
43518
+ return group.includes(structureId);
43519
+ });
43520
+ if (!existingGroup) {
43521
+ structureGroups.push([structureId]);
43522
+ if (stage !== VOLUNTARY_CONSOLATION)
43523
+ linkCheck.push([structureId]);
43524
+ }
43525
+ });
43526
+ const allStructuresLinked = allLinkStructuresLinked && linkCheck.length === 1;
43527
+ if (!links?.length && structures.length === 1) {
43528
+ initStructureProfile(structures[0].structureId);
43529
+ }
43530
+ return {
43531
+ structureProfiles: Object.fromEntries(structureProfiles),
43532
+ allStructuresLinked,
43533
+ maxQualifyingDepth,
43534
+ sourceStructureIds,
43535
+ hasDrawFeedProfile,
43536
+ structureGroups
43537
+ };
43538
+ }
43539
+
43381
43540
  function generateQualifyingStructure$1(params) {
43382
43541
  if (!params.drawDefinition)
43383
43542
  return { error: MISSING_DRAW_DEFINITION };
43384
43543
  const stack = "generateQualifyingStructure";
43385
- let drawSize = params.drawSize || coerceEven(params.participantsCount);
43544
+ let drawSize = params.drawSize ?? coerceEven(params.participantsCount);
43386
43545
  const {
43387
43546
  qualifyingRoundNumber,
43388
43547
  qualifyingPositions,
@@ -43390,6 +43549,7 @@ function generateQualifyingStructure$1(params) {
43390
43549
  structureOptions,
43391
43550
  appliedPolicies,
43392
43551
  drawDefinition,
43552
+ matchUpFormat,
43393
43553
  structureName,
43394
43554
  structureId,
43395
43555
  roundTarget,
@@ -43401,68 +43561,29 @@ function generateQualifyingStructure$1(params) {
43401
43561
  let roundLimit, roundsCount, structure, matchUps;
43402
43562
  let qualifiersCount = 0;
43403
43563
  let finishingPositions;
43404
- let stageSequence = 1;
43564
+ const stageSequence = 1;
43405
43565
  if (!isConvertableInteger(drawSize)) {
43406
43566
  return decorateResult({ result: { error: MISSING_DRAW_SIZE }, stack });
43407
43567
  }
43408
- const result = findStructure({
43409
- structureId: targetStructureId,
43410
- drawDefinition
43411
- });
43412
- if (result.error) {
43568
+ const { structureProfiles } = getStructureGroups({ drawDefinition });
43569
+ const structureProfile = structureProfiles[targetStructureId];
43570
+ if (!structureProfile) {
43413
43571
  return decorateResult({
43572
+ result: { error: STRUCTURE_NOT_FOUND },
43414
43573
  context: { targetStructureId },
43415
- result,
43416
43574
  stack
43417
43575
  });
43418
43576
  }
43419
- if (!result.structure)
43420
- return { error: STRUCTURE_NOT_FOUND };
43421
- const targetStructure = result.structure;
43422
- const matchUpType = targetStructure.matchUpType;
43423
- if (targetStructure.stage === QUALIFYING) {
43424
- if (targetStructure.stageSequence && targetStructure.stageSequence > 1) {
43425
- stageSequence = targetStructure.stageSequence - 1;
43426
- } else {
43427
- let nextStructureId = targetStructureId;
43428
- let nextStageSequence = 2;
43429
- let chainModified;
43430
- while (!chainModified && nextStructureId) {
43431
- targetStructure.stageSequence = nextStageSequence;
43432
- const targetTargetStructureId = drawDefinition.links?.find(
43433
- (link2) => link2.source.structureId === nextStructureId
43434
- )?.target?.structureId;
43435
- nextStructureId = targetTargetStructureId;
43436
- nextStageSequence += 1;
43437
- if (!targetTargetStructureId) {
43438
- chainModified = true;
43439
- } else {
43440
- const result2 = findStructure({
43441
- structureId: targetTargetStructureId,
43442
- drawDefinition
43443
- });
43444
- if (!result2.structure)
43445
- return { error: STRUCTURE_NOT_FOUND };
43446
- if (result2.error) {
43447
- return decorateResult({
43448
- context: { targetTargetStructureId },
43449
- result: result2,
43450
- stack
43451
- });
43452
- }
43453
- if (result2.structure.stage !== QUALIFYING)
43454
- chainModified = true;
43455
- }
43456
- }
43457
- }
43458
- }
43577
+ const matchUpType = drawDefinition.matchUpType;
43459
43578
  const roundTargetName = roundTarget ? `${roundTarget}-` : "";
43460
- const stageSequenceName = `${stageSequence}`;
43461
- const qualifyingStructureName = structureName || (roundTargetName || stageSequenceName ? `${constantToString(QUALIFYING)} ${roundTargetName}${stageSequenceName}` : constantToString(QUALIFYING));
43579
+ const isPreQualifying = structureProfile.stage === QUALIFYING;
43580
+ const preQualifyingNaming = appliedPolicies?.[POLICY_TYPE_ROUND_NAMING]?.namingConventions?.pre ?? POLICY_ROUND_NAMING_DEFAULT[POLICY_TYPE_ROUND_NAMING]?.namingConventions?.pre;
43581
+ const pre = isPreQualifying && preQualifyingNaming ? `${preQualifyingNaming}-` : "";
43582
+ const qualifyingStructureName = structureName ?? (roundTargetName ? `${pre}${constantToString(QUALIFYING)} ${roundTargetName}` : `${pre}${constantToString(QUALIFYING)}`);
43462
43583
  if (drawType === ROUND_ROBIN) {
43463
43584
  const { maxRoundNumber, structures, groupCount } = generateRoundRobin({
43464
- structureName: structureName || qualifyingStructureName,
43465
- structureId: structureId || uuids?.pop(),
43585
+ structureName: structureName ?? qualifyingStructureName,
43586
+ structureId: structureId ?? uuids?.pop(),
43466
43587
  stage: QUALIFYING,
43467
43588
  structureOptions,
43468
43589
  appliedPolicies,
@@ -43491,10 +43612,11 @@ function generateQualifyingStructure$1(params) {
43491
43612
  if (!roundLimit)
43492
43613
  roundLimit = roundsCount;
43493
43614
  structure = structureTemplate({
43494
- structureName: structureName || qualifyingStructureName,
43495
- structureId: structureId || uuids?.pop(),
43615
+ structureName: structureName ?? qualifyingStructureName,
43616
+ structureId: structureId ?? uuids?.pop(),
43496
43617
  qualifyingRoundNumber: roundLimit,
43497
43618
  stage: QUALIFYING,
43619
+ matchUpFormat,
43498
43620
  stageSequence,
43499
43621
  matchUpType,
43500
43622
  roundLimit,
@@ -43512,13 +43634,13 @@ function generateQualifyingStructure$1(params) {
43512
43634
  )?.length;
43513
43635
  }
43514
43636
  const linkType = drawType === ROUND_ROBIN ? LinkTypeEnum.Position : LinkTypeEnum.Winner;
43515
- const { link } = generateQualifyingLink({
43637
+ const link = structure && roundLimit && generateQualifyingLink({
43516
43638
  sourceStructureId: structure.structureId,
43517
43639
  sourceRoundNumber: roundLimit,
43518
43640
  targetStructureId,
43519
43641
  finishingPositions,
43520
43642
  linkType
43521
- });
43643
+ })?.link;
43522
43644
  return {
43523
43645
  qualifyingDrawPositionsCount: drawSize,
43524
43646
  qualifiersCount,
@@ -43558,6 +43680,15 @@ function attachQualifyingStructure$1({
43558
43680
  drawDefinition.links = [];
43559
43681
  drawDefinition.structures.push(structure);
43560
43682
  drawDefinition.links.push(link);
43683
+ const { maxQualifyingDepth, structureProfiles } = getStructureGroups({
43684
+ drawDefinition
43685
+ });
43686
+ for (const structure2 of drawDefinition.structures) {
43687
+ const profile = structureProfiles[structure2.structureId];
43688
+ if (profile.distanceFromMain) {
43689
+ structure2.stageSequence = maxQualifyingDepth + 1 - profile.distanceFromMain;
43690
+ }
43691
+ }
43561
43692
  const matchUps = getAllStructureMatchUps({ structure })?.matchUps || [];
43562
43693
  addMatchUpsNotice({
43563
43694
  drawDefinition,
@@ -43781,6 +43912,10 @@ function getAdvancingParticipantId(matchUp) {
43781
43912
  }
43782
43913
 
43783
43914
  function addQualifyingStructure$1(params) {
43915
+ if (!params.drawDefinition)
43916
+ return { error: MISSING_DRAW_DEFINITION };
43917
+ if (!params.targetStructureId)
43918
+ return { error: MISSING_STRUCTURE_ID };
43784
43919
  const result = generateQualifyingStructure$1(params);
43785
43920
  if (result.error)
43786
43921
  return result;
@@ -44078,21 +44213,26 @@ function removeStructure({
44078
44213
  ({ stage, stageSequence }) => stage === MAIN && stageSequence === 1
44079
44214
  );
44080
44215
  const isMainStageSequence1 = structureId === mainStageSequence1.structureId;
44081
- const hasQualifying = structures.find(({ stage }) => stage === QUALIFYING);
44082
- if (isMainStageSequence1 && !hasQualifying) {
44216
+ const qualifyingStructureIds = structures.filter(({ stage }) => stage === QUALIFYING).map(extractAttributes("structureId"));
44217
+ if (isMainStageSequence1 && !qualifyingStructureIds.length) {
44083
44218
  return { error: CANNOT_REMOVE_MAIN_STRUCTURE };
44084
44219
  }
44220
+ const structureIds = structures.map(extractAttributes("structureId"));
44085
44221
  const removedMatchUpIds = [];
44086
44222
  const idsToRemove = [structureId];
44087
44223
  const getTargetedStructureIds = (structureId2) => drawDefinition.links?.map(
44088
44224
  (link) => link.source.structureId === structureId2 && link.target.structureId !== mainStageSequence1.structureId && link.target.structureId
44089
44225
  ).filter(Boolean);
44090
- const structureIds = structures.map(({ structureId: structureId2 }) => structureId2);
44091
- const targetedStructureIdsMap = Object.assign(
44092
- {},
44093
- ...structureIds.map((structureId2) => ({
44094
- [structureId2]: getTargetedStructureIds(structureId2)
44095
- }))
44226
+ const getQualifyingSourceStructureIds = (structureId2) => drawDefinition.links?.map(
44227
+ (link) => qualifyingStructureIds.includes(link.source.structureId) && link.target.structureId === structureId2 && link.source.structureId
44228
+ ).filter(Boolean);
44229
+ const isQualifyingStructure = qualifyingStructureIds.includes(structureId);
44230
+ const relatedStructureIdsMap = /* @__PURE__ */ new Map();
44231
+ structureIds.forEach(
44232
+ (id) => relatedStructureIdsMap.set(
44233
+ id,
44234
+ isQualifyingStructure ? getQualifyingSourceStructureIds(id) : getTargetedStructureIds(id)
44235
+ )
44096
44236
  );
44097
44237
  while (idsToRemove.length) {
44098
44238
  const idBeingRemoved = idsToRemove.pop();
@@ -44115,7 +44255,8 @@ function removeStructure({
44115
44255
  }
44116
44256
  );
44117
44257
  }
44118
- const targetedStructureIds = idBeingRemoved && targetedStructureIdsMap[idBeingRemoved].filter(
44258
+ const targetedStructureIds = idBeingRemoved && // targetedStructureIdsMap[idBeingRemoved].filter(
44259
+ relatedStructureIdsMap.get(idBeingRemoved)?.filter(
44119
44260
  (id) => (
44120
44261
  // IMPORTANT: only delete MAIN stageSequence: 1 if specified to protect against DOUBLE_ELIMINATION scenario
44121
44262
  id !== mainStageSequence1.structureId || structureId === mainStageSequence1.structureId
@@ -44912,7 +45053,7 @@ function modifyEntriesStatus({
44912
45053
  }).assignedParticipantIds ?? [];
44913
45054
  assignedParticipantIds.push(...participantIds2);
44914
45055
  });
44915
- const tournamentParticipants = tournamentRecord?.participants || [];
45056
+ const tournamentParticipants = tournamentRecord?.participants ?? [];
44916
45057
  const validEntryStatusForAllParticipantIds = participantIds.every(
44917
45058
  (participantId) => {
44918
45059
  const participantType = findParticipant({
@@ -44960,7 +45101,7 @@ function modifyEntriesStatus({
44960
45101
  const autoPosition = ({ flight: flight2, drawDefinition: drawDefinition2 }) => {
44961
45102
  if (event) {
44962
45103
  event.entries = refreshEntryPositions({
44963
- entries: event.entries || []
45104
+ entries: event.entries ?? []
44964
45105
  });
44965
45106
  }
44966
45107
  if (flight2) {
@@ -44991,7 +45132,7 @@ function modifyEntriesStatus({
44991
45132
  }
44992
45133
  return { ...SUCCESS };
44993
45134
  };
44994
- const entryPositionsExist = event?.entries?.find(({ entryPosition }) => entryPosition) || flight?.drawEntries?.find(({ entryPosition }) => entryPosition) || drawDefinition?.entries?.find(({ entryPosition }) => entryPosition);
45135
+ const entryPositionsExist = event?.entries?.find(({ entryPosition }) => entryPosition) ?? (flight?.drawEntries?.find(({ entryPosition }) => entryPosition) || drawDefinition?.entries?.find(({ entryPosition }) => entryPosition));
44995
45136
  if (autoEntryPositions && !entryPositionsExist)
44996
45137
  autoPosition({ flight, drawDefinition });
44997
45138
  if (flight || drawDefinition) {
@@ -44999,7 +45140,7 @@ function modifyEntriesStatus({
44999
45140
  if (result.error)
45000
45141
  return decorateResult({ result, stack });
45001
45142
  }
45002
- const generatedDrawIds = event?.drawDefinitions?.map(({ drawId: drawId2 }) => drawId2) || [];
45143
+ const generatedDrawIds = event?.drawDefinitions?.map(({ drawId: drawId2 }) => drawId2) ?? [];
45003
45144
  const flightsNoDraw = flightProfile?.flights?.filter(
45004
45145
  (flight2) => !generatedDrawIds.includes(flight2.drawId)
45005
45146
  ) || [];
@@ -45008,7 +45149,7 @@ function modifyEntriesStatus({
45008
45149
  if (result?.error)
45009
45150
  return decorateResult({ result, stack });
45010
45151
  }
45011
- const singleDraw = flightProfile?.flights?.length === 1 && (event?.drawDefinitions?.length || 0) <= flightProfile?.flights?.length;
45152
+ const singleDraw = flightProfile?.flights?.length === 1 && (event?.drawDefinitions?.length ?? 0) <= flightProfile?.flights?.length;
45012
45153
  if (!flight && !drawDefinition && entryStatus && DRAW_SPECIFIC_STATUSES.includes(entryStatus)) {
45013
45154
  return { error: ENTRY_STATUS_NOT_ALLOWED_FOR_EVENT };
45014
45155
  }
@@ -45046,7 +45187,7 @@ function modifyEntriesStatus({
45046
45187
  }
45047
45188
  if (autoEntryPositions)
45048
45189
  autoPosition({ flight, drawDefinition });
45049
- for (const drawDefinition2 of event?.drawDefinitions || []) {
45190
+ for (const drawDefinition2 of event?.drawDefinitions ?? []) {
45050
45191
  if (modifiedDrawIds.length && !modifiedDrawIds.includes(drawDefinition2.drawId))
45051
45192
  continue;
45052
45193
  modifyDrawNotice({
@@ -45412,7 +45553,7 @@ function removeEventEntries({
45412
45553
  if (!participantIds?.length)
45413
45554
  return { ...SUCCESS, participantIdsRemoved: [] };
45414
45555
  const participantIdsRemoved = [];
45415
- event.entries = (event.entries || []).filter((entry) => {
45556
+ event.entries = (event.entries ?? []).filter((entry) => {
45416
45557
  const keepEntry = !participantIds.includes(entry?.participantId);
45417
45558
  if (!keepEntry)
45418
45559
  participantIdsRemoved.push(entry.participantId);
@@ -45430,7 +45571,7 @@ function removeEventEntries({
45430
45571
  );
45431
45572
  });
45432
45573
  event.drawDefinitions?.forEach((drawDefinition) => {
45433
- drawDefinition.entries = (drawDefinition.entries || []).filter(
45574
+ drawDefinition.entries = (drawDefinition.entries ?? []).filter(
45434
45575
  (entry) => !participantIds.includes(entry.participantId)
45435
45576
  );
45436
45577
  });
@@ -45611,7 +45752,7 @@ function removeIndividualParticipantIds({
45611
45752
  });
45612
45753
  if (!groupingParticipantId || !individualParticipantIds)
45613
45754
  return decorateResult({ result: { error: MISSING_VALUE }, stack });
45614
- const tournamentParticipants = tournamentRecord.participants || [];
45755
+ const tournamentParticipants = tournamentRecord.participants ?? [];
45615
45756
  const groupingParticipant = tournamentParticipants.find(
45616
45757
  (participant) => {
45617
45758
  return participant.participantId === groupingParticipantId;
@@ -45638,8 +45779,8 @@ function removeIndividualParticipantIds({
45638
45779
  if (error)
45639
45780
  return decorateResult({ result, stack });
45640
45781
  if (addIndividualParticipantsToEvents) {
45641
- for (const event of tournamentRecord.events || []) {
45642
- const enteredIds = (event.entries || []).map(({ participantId }) => participantId).filter(Boolean);
45782
+ for (const event of tournamentRecord.events ?? []) {
45783
+ const enteredIds = (event.entries ?? []).map(({ participantId }) => participantId).filter(Boolean);
45643
45784
  if (enteredIds.includes(groupingParticipantId)) {
45644
45785
  const participantIdsToEnter = removed?.filter(
45645
45786
  (participantId) => !enteredIds.includes(participantId)
@@ -45690,7 +45831,7 @@ function removeParticipantIdsFromGroupingParticipant({
45690
45831
  const groupingParticipantEventIds = inContextGroupingParticipant?.events?.map(
45691
45832
  ({ eventId }) => eventId
45692
45833
  );
45693
- const updatedIndividualParticipantIds = (groupingParticipant.individualParticipantIds || []).filter((participantId) => {
45834
+ const updatedIndividualParticipantIds = (groupingParticipant.individualParticipantIds ?? []).filter((participantId) => {
45694
45835
  const targetParticipant = individualParticipantIds?.includes(participantId);
45695
45836
  const scoredParticipantGroupingMatchUps = targetParticipant && participants?.find((participant) => participant.participantId === participantId)?.matchUps.filter(
45696
45837
  ({ eventId }) => groupingParticipantEventIds.includes(eventId)
@@ -45703,25 +45844,25 @@ function removeParticipantIdsFromGroupingParticipant({
45703
45844
  }
45704
45845
  if (removeParticipant) {
45705
45846
  removed.push(participantId);
45706
- for (const event of tournamentRecord.events || []) {
45707
- for (const drawDefinition of event.drawDefinitions || []) {
45847
+ for (const event of tournamentRecord.events ?? []) {
45848
+ for (const drawDefinition of event.drawDefinitions ?? []) {
45708
45849
  const { extension } = findExtension$2({
45709
45850
  element: drawDefinition,
45710
45851
  name: LINEUPS
45711
45852
  });
45712
- let lineUp = extension?.value[groupingParticipant.participantId];
45853
+ const lineUp = extension?.value[groupingParticipant.participantId];
45713
45854
  if (extension && lineUp) {
45714
- lineUp = lineUp.filter(
45855
+ extension.value[groupingParticipant.participantId] = lineUp.filter(
45715
45856
  (assignment) => assignment.participantId !== participantId
45716
45857
  );
45717
45858
  addExtension$1({ element: drawDefinition, extension });
45718
45859
  addDrawNotice({ drawDefinition });
45719
45860
  }
45720
- const matchUps = allDrawMatchUps$1({ drawDefinition, inContext: false }).matchUps || [];
45861
+ const matchUps = allDrawMatchUps$1({ drawDefinition, inContext: false }).matchUps ?? [];
45721
45862
  for (const matchUp of matchUps) {
45722
- const sides = matchUp.sides || [];
45863
+ const sides = matchUp.sides ?? [];
45723
45864
  for (const side of sides) {
45724
- const lineUp2 = side.lineUp || [];
45865
+ const lineUp2 = side.lineUp ?? [];
45725
45866
  const containsParticipant = lineUp2.find(
45726
45867
  (assignment) => assignment.participantId === participantId
45727
45868
  );
@@ -45765,7 +45906,7 @@ function removeParticipantIdsFromAllTeams({
45765
45906
  }) {
45766
45907
  if (!tournamentRecord)
45767
45908
  return { error: MISSING_TOURNAMENT_RECORD };
45768
- const tournamentParticipants = tournamentRecord.participants || [];
45909
+ const tournamentParticipants = tournamentRecord.participants ?? [];
45769
45910
  const { participants, mappedMatchUps } = getParticipants$1({
45770
45911
  withMatchUps: true,
45771
45912
  tournamentRecord,
@@ -45811,7 +45952,7 @@ function deleteParticipants(params) {
45811
45952
  const matchUps = allTournamentMatchUps({
45812
45953
  matchUpFilters: { drawIds: teamDrawIds, matchUpTypes: [DOUBLES$1] },
45813
45954
  tournamentRecord
45814
- }).matchUps || [];
45955
+ }).matchUps ?? [];
45815
45956
  const placedPairParticipantIds2 = matchUps.map(({ sides }) => sides?.map(({ participantId }) => participantId)).flat().filter(Boolean);
45816
45957
  return intersection(placedPairParticipantIds2, participantIds);
45817
45958
  };
@@ -45934,7 +46075,7 @@ function destroyGroupEntry({
45934
46075
  if (!event.eventType || ![TypeEnum.Doubles, TypeEnum.Team].includes(event.eventType)) {
45935
46076
  return decorateResult({ result: { error: INVALID_EVENT_TYPE }, stack });
45936
46077
  }
45937
- const tournamentParticipants = tournamentRecord.participants || [];
46078
+ const tournamentParticipants = tournamentRecord.participants ?? [];
45938
46079
  const participant = tournamentParticipants.find(
45939
46080
  (participant2) => participant2.participantId === participantId
45940
46081
  );
@@ -45946,7 +46087,7 @@ function destroyGroupEntry({
45946
46087
  ) || participant.participantType === TEAM$1 && event.eventType !== TEAM$1 || participant.participantType === PAIR && event.eventType !== DOUBLES) {
45947
46088
  return { error: INVALID_PARTICIPANT_TYPE };
45948
46089
  }
45949
- const eventEntries = event.entries || [];
46090
+ const eventEntries = event.entries ?? [];
45950
46091
  const entry = eventEntries.find(
45951
46092
  (entry2) => entry2.participantId === participantId
45952
46093
  );
@@ -46052,7 +46193,7 @@ function removeDrawPositionAssignment(params) {
46052
46193
  tournamentRecord: tournamentRecord2,
46053
46194
  participantId
46054
46195
  });
46055
- const { participantType, individualParticipantIds } = participant || {};
46196
+ const { participantType, individualParticipantIds } = participant ?? {};
46056
46197
  if (destroyPair && participantType === PAIR) {
46057
46198
  const result2 = destroyPairEntry({
46058
46199
  tournamentRecord: tournamentRecord2,
@@ -49587,12 +49728,12 @@ function getParticipantEventDetails({
49587
49728
  if (!participantId)
49588
49729
  return { error: MISSING_PARTICIPANT_ID };
49589
49730
  const relevantParticipantIds = [participantId].concat(
49590
- (tournamentRecord.participants || []).filter(
49731
+ (tournamentRecord.participants ?? []).filter(
49591
49732
  (participant) => participant?.participantType && [TEAM, PAIR].includes(participant.participantType) && participant.individualParticipantIds?.includes(participantId)
49592
49733
  ).map((participant) => participant.participantId)
49593
49734
  );
49594
- const relevantEvents = (tournamentRecord.events || []).filter((event) => {
49595
- const enteredParticipantIds = (event?.entries || []).map(
49735
+ const relevantEvents = (tournamentRecord.events ?? []).filter((event) => {
49736
+ const enteredParticipantIds = (event?.entries ?? []).map(
49596
49737
  (entry) => entry.participantId
49597
49738
  );
49598
49739
  return overlap(enteredParticipantIds, relevantParticipantIds);
@@ -49633,7 +49774,7 @@ function getRelevantParticipantIdsMap({
49633
49774
  }) {
49634
49775
  if (typeof tournamentRecord !== "object" && typeof tournamentRecords !== "object")
49635
49776
  return { error: MISSING_TOURNAMENT_RECORD };
49636
- const allParticipants = tournamentRecords ? Object.values(tournamentRecords).map((tournamentRecord2) => tournamentRecord2?.participants || []).flat() : tournamentRecord?.participants || [];
49777
+ const allParticipants = tournamentRecords ? Object.values(tournamentRecords).map((tournamentRecord2) => tournamentRecord2?.participants || []).flat() : tournamentRecord?.participants ?? [];
49637
49778
  const relevantParticipantIdsMap = Object.assign(
49638
49779
  {},
49639
49780
  ...allParticipants.map(
@@ -49901,7 +50042,7 @@ function annotateParticipant(params) {
49901
50042
  );
49902
50043
  const scheduledMatchUps = participantScheduledMatchUps({
49903
50044
  matchUps: allParticipantMatchUps
49904
- })?.scheduledMatchUps || [];
50045
+ })?.scheduledMatchUps ?? [];
49905
50046
  const { scheduledMinutesDifference } = scheduleAnalysis || {};
49906
50047
  const dates = Object.keys(scheduledMatchUps);
49907
50048
  dates.forEach((date) => {
@@ -50706,7 +50847,7 @@ function getParticipantMembership({
50706
50847
  participantFilters: { participantTypes: [TEAM, PAIR, GROUP] },
50707
50848
  tournamentRecord
50708
50849
  });
50709
- const memberOf = (participants || []).filter((participant) => {
50850
+ const memberOf = (participants ?? []).filter((participant) => {
50710
50851
  return participant.individualParticipantIds?.includes(participantId);
50711
50852
  });
50712
50853
  return memberOf.reduce((groupingTypesMap, participant) => {
@@ -50732,7 +50873,7 @@ function getParticipantSchedules({
50732
50873
  const matchUps = allTournamentMatchUps({
50733
50874
  tournamentRecord,
50734
50875
  contextFilters
50735
- }).matchUps || [];
50876
+ }).matchUps ?? [];
50736
50877
  const matchUpsMap = Object.assign(
50737
50878
  {},
50738
50879
  ...matchUps.map((matchUp) => ({ [matchUp.matchUpId]: matchUp }))
@@ -50743,7 +50884,7 @@ function getParticipantSchedules({
50743
50884
  const sourceMatchUpIds = getMatchUpDependencies({
50744
50885
  tournamentRecord,
50745
50886
  matchUps
50746
- }).sourceMatchUpIds || [];
50887
+ }).sourceMatchUpIds ?? [];
50747
50888
  const participantAggregator = {};
50748
50889
  for (const matchUp of scheduledMatchUps) {
50749
50890
  const { sides } = matchUp;
@@ -50753,13 +50894,11 @@ function getParticipantSchedules({
50753
50894
  return [side.participant].concat(
50754
50895
  ...side.participant.individualParticipants || []
50755
50896
  );
50756
- } else {
50757
- if (sourceMatchUpIds[matchUp.matchUpId] && !relevantSourceMatchUps) {
50758
- relevantSourceMatchUps = (sourceMatchUpIds[matchUp.matchUpId] || []).map((matchUpId) => matchUpsMap[matchUpId]).filter(({ winningSide, bye }) => !winningSide && !bye);
50759
- }
50897
+ } else if (sourceMatchUpIds[matchUp.matchUpId] && !relevantSourceMatchUps) {
50898
+ relevantSourceMatchUps = (sourceMatchUpIds[matchUp.matchUpId] || []).map((matchUpId) => matchUpsMap[matchUpId]).filter(({ winningSide, bye }) => !winningSide && !bye);
50760
50899
  }
50761
50900
  return void 0;
50762
- }).filter(Boolean).flat() || [];
50901
+ }).filter(Boolean).flat() ?? [];
50763
50902
  for (const participant of participants) {
50764
50903
  const { participantId } = participant;
50765
50904
  if (!participantAggregator[participantId]) {
@@ -50890,7 +51029,7 @@ function addPersons({
50890
51029
  const tournamentParticipants = getParticipants$1({
50891
51030
  participantFilters: { participantTypes: [INDIVIDUAL] },
50892
51031
  tournamentRecord
50893
- })?.participants || [];
51032
+ })?.participants ?? [];
50894
51033
  if (participantRole === COMPETITOR) {
50895
51034
  persons.filter(({ pairedPersons }) => pairedPersons).forEach(({ personId, pairedPersons }) => {
50896
51035
  Array.isArray(pairedPersons) && pairedPersons.forEach((pairing) => {
@@ -50965,7 +51104,7 @@ function addIndividualParticipantIds({
50965
51104
  });
50966
51105
  if (!groupingParticipantId || !individualParticipantIds)
50967
51106
  return decorateResult({ result: { error: MISSING_VALUE }, stack });
50968
- const tournamentParticipants = tournamentRecord.participants || [];
51107
+ const tournamentParticipants = tournamentRecord.participants ?? [];
50969
51108
  const groupingParticipant = tournamentParticipants.find(
50970
51109
  (participant) => participant.participantId === groupingParticipantId
50971
51110
  );
@@ -51126,7 +51265,7 @@ function generateTeamsFromParticipantAttribute({
51126
51265
  if (!tournamentRecord)
51127
51266
  return { error: MISSING_TOURNAMENT_RECORD };
51128
51267
  const teams = {};
51129
- const individualParticipants = (tournamentRecord.participants || []).filter(
51268
+ const individualParticipants = (tournamentRecord.participants ?? []).filter(
51130
51269
  ({ participantType, participantRole }) => participantType === INDIVIDUAL && participantRole === COMPETITOR
51131
51270
  );
51132
51271
  let teamIndex = 0;
@@ -51139,15 +51278,15 @@ function generateTeamsFromParticipantAttribute({
51139
51278
  if (attributeValue) {
51140
51279
  if (!Object.keys(teams).includes(attributeValue)) {
51141
51280
  teams[attributeValue] = {
51142
- participantName: teamNames?.[teamIndex] || attributeValue,
51143
- participantId: uuids?.pop() || UUID(),
51281
+ participantName: teamNames?.[teamIndex] ?? attributeValue,
51282
+ participantId: uuids?.pop() ?? UUID(),
51144
51283
  individualParticipantIds: [],
51145
51284
  participantRole: COMPETITOR,
51146
51285
  participantType: TEAM
51147
51286
  };
51148
51287
  const extension = {
51149
- name: GROUPING_ATTRIBUTE,
51150
- value: personAttribute || participantAttribute
51288
+ value: personAttribute ?? participantAttribute,
51289
+ name: GROUPING_ATTRIBUTE
51151
51290
  };
51152
51291
  addExtension$1({ element: teams[attributeValue], extension });
51153
51292
  teamIndex += 1;
@@ -51158,7 +51297,7 @@ function generateTeamsFromParticipantAttribute({
51158
51297
  }
51159
51298
  }
51160
51299
  const groupingAttributes = Object.keys(teams);
51161
- const overlappingTeamParticipantIds = (tournamentRecord.participants || []).map((participant) => {
51300
+ const overlappingTeamParticipantIds = (tournamentRecord.participants ?? []).map((participant) => {
51162
51301
  if (participant.participantType !== TEAM)
51163
51302
  return void 0;
51164
51303
  if (participant.participantRole !== COMPETITOR)
@@ -51303,16 +51442,16 @@ function scaledTeamAssignment({
51303
51442
  error: MISSING_VALUE
51304
51443
  };
51305
51444
  }
51306
- let participantIdsToAssign = individualParticipantIds || scaledParticipants.map(({ participantId }) => participantId);
51445
+ let participantIdsToAssign = individualParticipantIds ?? scaledParticipants.map(({ participantId }) => participantId);
51307
51446
  if (reverseAssignmentOrder) {
51308
51447
  teamParticipantIds?.reverse();
51309
51448
  initialTeamIndex += 1;
51310
51449
  }
51311
51450
  if (initialTeamIndex > (teamParticipantIds?.length || 0) - 1)
51312
51451
  initialTeamIndex = 0;
51313
- const orderedTeamParticipantIds = teamParticipantIds?.slice(initialTeamIndex).concat(...teamParticipantIds.slice(0, initialTeamIndex)) || [];
51452
+ const orderedTeamParticipantIds = teamParticipantIds?.slice(initialTeamIndex).concat(...teamParticipantIds.slice(0, initialTeamIndex)) ?? [];
51314
51453
  const relevantTeams = [];
51315
- for (const participant of tournamentRecord.participants || []) {
51454
+ for (const participant of tournamentRecord.participants ?? []) {
51316
51455
  const { participantId, participantType } = participant;
51317
51456
  if (!orderedTeamParticipantIds.includes(participantId))
51318
51457
  continue;
@@ -51322,7 +51461,7 @@ function scaledTeamAssignment({
51322
51461
  }
51323
51462
  if (teamsCount && relevantTeams.length < teamsCount) {
51324
51463
  const addCount = teamsCount - (relevantTeams?.length || 0);
51325
- const nameBase = teamNameBase || "Team";
51464
+ const nameBase = teamNameBase ?? "Team";
51326
51465
  const teamParticipants = generateRange(0, addCount).map((i) => ({
51327
51466
  participantName: `${nameBase} ${i + 1}`,
51328
51467
  participantType: TEAM_PARTICIPANT,
@@ -51361,7 +51500,7 @@ function scaledTeamAssignment({
51361
51500
  return { error: NO_CANDIDATES, info: "Nothing to be done" };
51362
51501
  }
51363
51502
  if (!scaledParticipants.length) {
51364
- for (const participant of tournamentRecord.participants || []) {
51503
+ for (const participant of tournamentRecord.participants ?? []) {
51365
51504
  const { participantId, participantType } = participant;
51366
51505
  if (!participantIdsToAssign.includes(participantId))
51367
51506
  continue;
@@ -51399,10 +51538,10 @@ function scaledTeamAssignment({
51399
51538
  relevantTeams.reverse();
51400
51539
  }
51401
51540
  const relevantTeamParticipantIds = relevantTeams.map(getParticipantId);
51402
- for (const event2 of tournamentRecord.events || []) {
51541
+ for (const event2 of tournamentRecord.events ?? []) {
51403
51542
  if (event2.eventType !== TEAM_EVENT)
51404
51543
  continue;
51405
- const relevantTeamEntries = (event2.entries || []).filter(
51544
+ const relevantTeamEntries = (event2.entries ?? []).filter(
51406
51545
  (entry) => relevantTeamParticipantIds.includes(entry.participantId)
51407
51546
  );
51408
51547
  for (const relevantEntry of relevantTeamEntries) {
@@ -51411,11 +51550,11 @@ function scaledTeamAssignment({
51411
51550
  (teamParticipant) => teamParticipant.participantId === relevantTeamParticipantId
51412
51551
  );
51413
51552
  const individualParticipantIds2 = relevantTeam?.individualParticipantIds;
51414
- event2.entries = (event2.entries || []).filter(
51553
+ event2.entries = (event2.entries ?? []).filter(
51415
51554
  (entry) => !individualParticipantIds2.includes(entry.participantId)
51416
51555
  );
51417
- (event2.drawDefinitions || []).forEach((drawDefinition) => {
51418
- drawDefinition.entries = (drawDefinition.entries || []).filter(
51556
+ (event2.drawDefinitions ?? []).forEach((drawDefinition) => {
51557
+ drawDefinition.entries = (drawDefinition.entries ?? []).filter(
51419
51558
  (entry) => !individualParticipantIds2.includes(entry.participantId)
51420
51559
  );
51421
51560
  });
@@ -52329,59 +52468,6 @@ function unPublishEvent({
52329
52468
  return { eventId: event.eventId, ...SUCCESS };
52330
52469
  }
52331
52470
 
52332
- function getStructureGroups({ drawDefinition }) {
52333
- const links = drawDefinition.links || [];
52334
- const sourceStructureIds = {};
52335
- const hasDrawFeedProfile = {};
52336
- let linkedStructureIds = links.map((link) => {
52337
- const sourceId = link.source.structureId;
52338
- const targetId = link.target.structureId;
52339
- hasDrawFeedProfile[targetId] = hasDrawFeedProfile[targetId] || link.target.feedProfile === DRAW;
52340
- sourceStructureIds[targetId] = unique([
52341
- ...sourceStructureIds[targetId] || [],
52342
- sourceId
52343
- ]).filter(Boolean);
52344
- return [link.source.structureId, link.target.structureId];
52345
- });
52346
- const iterations = linkedStructureIds.length;
52347
- generateRange(0, Math.ceil(iterations / 2)).forEach(() => {
52348
- linkedStructureIds = generateRange(0, iterations).map((index) => {
52349
- const structureIds = linkedStructureIds[index];
52350
- const mergedWithOverlappingIds = linkedStructureIds.reduce((biggest, ids) => {
52351
- const hasOverlap = overlap(structureIds, ids);
52352
- return hasOverlap ? biggest.concat(...ids) : biggest;
52353
- }, []) || [];
52354
- return unique(structureIds.concat(...mergedWithOverlappingIds));
52355
- });
52356
- });
52357
- const groupedStructureIds = linkedStructureIds[0];
52358
- const identityLink = (a, b) => intersection(a, b).length === a.length;
52359
- const allLinkStructuresLinked = linkedStructureIds.slice(1).reduce((allLinkStructuresLinked2, ids) => {
52360
- return allLinkStructuresLinked2 && identityLink(ids, groupedStructureIds);
52361
- }, true);
52362
- const structureGroups = [groupedStructureIds].filter(Boolean);
52363
- const linkCheck = [groupedStructureIds].filter(Boolean);
52364
- const structures = drawDefinition.structures || [];
52365
- structures.forEach((structure) => {
52366
- const { structureId, stage } = structure;
52367
- const existingGroup = structureGroups.find((group) => {
52368
- return group.includes(structureId);
52369
- });
52370
- if (!existingGroup) {
52371
- structureGroups.push([structureId]);
52372
- if (stage !== VOLUNTARY_CONSOLATION)
52373
- linkCheck.push(structureId);
52374
- }
52375
- });
52376
- const allStructuresLinked = allLinkStructuresLinked && linkCheck.length === 1;
52377
- return {
52378
- allStructuresLinked,
52379
- sourceStructureIds,
52380
- hasDrawFeedProfile,
52381
- structureGroups
52382
- };
52383
- }
52384
-
52385
52471
  function getDrawData(params) {
52386
52472
  const {
52387
52473
  tournamentParticipants = [],
@@ -52440,12 +52526,18 @@ function getDrawData(params) {
52440
52526
  }
52441
52527
  return structure;
52442
52528
  }).sort((a, b) => structureSort(a, b, sortConfig)).map((structure) => {
52443
- const { structureId } = structure;
52529
+ if (!structure)
52530
+ return;
52531
+ const structureId = structure?.structureId;
52444
52532
  let seedAssignments = [];
52445
- if ([MAIN, CONSOLATION, PLAY_OFF].includes(structure.stage)) {
52533
+ if (structure.stage && [
52534
+ StageTypeEnum.Main,
52535
+ StageTypeEnum.Consolation,
52536
+ StageTypeEnum.PlayOff
52537
+ ].includes(structure.stage)) {
52446
52538
  seedAssignments = mainStageSeedAssignments;
52447
52539
  }
52448
- if (structure.stage === QUALIFYING) {
52540
+ if (structure?.stage === QUALIFYING) {
52449
52541
  seedAssignments = qualificationStageSeedAssignments;
52450
52542
  }
52451
52543
  const { matchUps, roundMatchUps, roundProfile } = getAllStructureMatchUps({
@@ -52476,7 +52568,7 @@ function getDrawData(params) {
52476
52568
  participantResult: extension.value
52477
52569
  };
52478
52570
  }).filter((f) => f?.participantResult);
52479
- const structureInfo = (({
52571
+ const structureInfo = structure ? (({
52480
52572
  stageSequence,
52481
52573
  structureName,
52482
52574
  structureType,
@@ -52488,7 +52580,7 @@ function getDrawData(params) {
52488
52580
  structureType,
52489
52581
  matchUpFormat,
52490
52582
  stage
52491
- }))(structure);
52583
+ }))(structure) : {};
52492
52584
  structureInfo.sourceStructureIds = sourceStructureIds[structureId];
52493
52585
  structureInfo.hasDrawFeedProfile = hasDrawFeedProfile[structureId];
52494
52586
  structureInfo.positionAssignments = positionAssignments;
@@ -52682,7 +52774,7 @@ function publishEvent(params) {
52682
52774
  policyDefinitions = appliedPolicies;
52683
52775
  }
52684
52776
  const itemType = `${PUBLISH}.${STATUS$1}`;
52685
- const eventDrawIds = event.drawDefinitions?.map(({ drawId }) => drawId) || [];
52777
+ const eventDrawIds = event.drawDefinitions?.map(({ drawId }) => drawId) ?? [];
52686
52778
  const { timeItem } = getEventTimeItem({
52687
52779
  itemType,
52688
52780
  event
@@ -52692,7 +52784,7 @@ function publishEvent(params) {
52692
52784
  } else if (!drawIds && (drawIdsToAdd?.length || drawIdsToRemove?.length)) {
52693
52785
  drawIds = timeItem?.itemValue?.PUBLIC?.drawIds || [];
52694
52786
  }
52695
- drawIds = (drawIds || []).filter(
52787
+ drawIds = (drawIds ?? []).filter(
52696
52788
  (drawId) => !drawIdsToRemove?.length || !drawIdsToRemove.includes(drawId)
52697
52789
  );
52698
52790
  if (drawIdsToAdd?.length) {
@@ -52705,7 +52797,7 @@ function publishEvent(params) {
52705
52797
  if (!structureIds && (structureIdsToAdd?.length || structureIdsToRemove?.length)) {
52706
52798
  structureIds = timeItem?.itemValue?.PUBLIC?.structureIds || [];
52707
52799
  }
52708
- structureIds = (structureIds || []).filter(
52800
+ structureIds = (structureIds ?? []).filter(
52709
52801
  (structureId) => !structureIdsToRemove?.length || !structureIdsToRemove.includes(structureId)
52710
52802
  );
52711
52803
  if (structureIdsToAdd?.length) {
@@ -52714,7 +52806,7 @@ function publishEvent(params) {
52714
52806
  if (!stages && (stagesToAdd?.length || stagesToRemove?.length)) {
52715
52807
  stages = timeItem?.itemValue?.PUBLIC?.stages || [];
52716
52808
  }
52717
- stages = (stages || []).filter(
52809
+ stages = (stages ?? []).filter(
52718
52810
  (stage) => !stagesToRemove?.length || !stagesToRemove.includes(stage)
52719
52811
  );
52720
52812
  if (stagesToAdd?.length) {
@@ -54033,14 +54125,14 @@ function analyzeDraws({ tournamentRecord }) {
54033
54125
  const positionsAssigned = positionAssignments?.filter(
54034
54126
  ({ participantId }) => participantId
54035
54127
  );
54036
- positionsAssignedCount += positionsAssigned?.length || 0;
54037
- const unassignedPositionsCount = (positionAssignments?.length || 0) - (positionsAssigned?.length || 0);
54128
+ positionsAssignedCount += positionsAssigned?.length ?? 0;
54129
+ const unassignedPositionsCount = (positionAssignments?.length ?? 0) - (positionsAssigned?.length ?? 0);
54038
54130
  const { roundMatchUps, roundProfile, roundNumbers, maxMatchUpsCount } = getRoundMatchUps$1({ matchUps: inContextStructureMatchUps });
54039
54131
  const activeRounds = roundProfile && Object.keys(roundProfile).filter((roundNumber) => !roundProfile[roundNumber].inactiveRound).map((roundNumber) => parseInt(roundNumber));
54040
54132
  const inactiveRounds = roundProfile && Object.keys(roundProfile).filter((roundNumber) => roundProfile[roundNumber].inactiveRound).map((roundNumber) => parseInt(roundNumber));
54041
54133
  const inactiveStructure = roundProfile && Object.values(roundProfile).every((profile) => profile.inactiveRound);
54042
54134
  return {
54043
- positionsAssignedCount: positionsAssigned?.length || 0,
54135
+ positionsAssignedCount: positionsAssigned?.length ?? 0,
54044
54136
  maxWinningSideFirstRoundPosition,
54045
54137
  unassignedPositionsCount,
54046
54138
  inactiveStructure,
@@ -54166,7 +54258,7 @@ function updateCourtAvailability({ tournamentRecord }) {
54166
54258
  courts.push(...venue.courts);
54167
54259
  }
54168
54260
  for (const court of courts) {
54169
- const { startTime, endTime } = (court.dateAvailability || []).reduce(
54261
+ const { startTime, endTime } = (court.dateAvailability ?? []).reduce(
54170
54262
  (extents, availability) => {
54171
54263
  const startMinutes = timeStringMinutes(extents.startTime);
54172
54264
  const endMinutes = timeStringMinutes(extents.endTime);
@@ -54182,7 +54274,7 @@ function updateCourtAvailability({ tournamentRecord }) {
54182
54274
  const existing = court.dateAvailability?.find(
54183
54275
  (availability) => availability.date === date
54184
54276
  );
54185
- return existing || { date, startTime, endTime };
54277
+ return existing ?? { date, startTime, endTime };
54186
54278
  });
54187
54279
  const defaultAvailability = court.dateAvailability?.find(
54188
54280
  (availability) => !availability.date
@@ -54399,7 +54491,7 @@ function clearMatchUpSchedule({
54399
54491
  }).matchUps?.[0];
54400
54492
  if (!matchUp)
54401
54493
  return { error: MATCHUP_NOT_FOUND };
54402
- const newTimeItems = (matchUp.timeItems || []).filter(
54494
+ const newTimeItems = (matchUp.timeItems ?? []).filter(
54403
54495
  (timeItem) => timeItem?.itemType && !scheduleAttributes.includes(timeItem?.itemType)
54404
54496
  );
54405
54497
  matchUp.timeItems = newTimeItems;
@@ -54605,7 +54697,7 @@ function getEntryStatusReports({
54605
54697
  drawDefinitionsCount += 1;
54606
54698
  const stageFilter = ({ stage, stageSequence }) => stage === MAIN && stageSequence === 1 || stage === QUALIFYING;
54607
54699
  const structures = params.structures ?? [];
54608
- const assignedParticipantIds = structures.filter(stageFilter).flatMap(({ positionAssignments }) => positionAssignments).map(({ participantId }) => participantId).filter(Boolean);
54700
+ const assignedParticipantIds = structures.filter(stageFilter).flatMap(({ positionAssignments }) => positionAssignments).filter(Boolean).map(({ participantId }) => participantId);
54609
54701
  const entryFilter = ({ participantId }) => assignedParticipantIds.includes(participantId);
54610
54702
  const createEntryProfile = (params2) => {
54611
54703
  const { participantId, entryStatus, entryStage } = params2;
@@ -55303,7 +55395,7 @@ function assignMatchUpSideParticipant({
55303
55395
  matchUp.sides = [1, 2].map((currentSideNumber) => {
55304
55396
  const existingSide = matchUp.sides?.find(
55305
55397
  (side) => side.sideNumber === currentSideNumber
55306
- ) || { sideNumber: currentSideNumber };
55398
+ ) ?? { sideNumber: currentSideNumber };
55307
55399
  return sideNumber === currentSideNumber ? { ...existingSide, participantId } : existingSide;
55308
55400
  });
55309
55401
  if (noSideNumberProvided) {
@@ -55703,7 +55795,7 @@ function removeTieMatchUpParticipantId(params) {
55703
55795
  const tieMatchUpSide = inContextTieMatchUp?.sides?.find(
55704
55796
  (side2) => side2.sideNumber === dualMatchUpSide?.sideNumber
55705
55797
  );
55706
- const { participantId: pairParticipantId } = tieMatchUpSide || {};
55798
+ const { participantId: pairParticipantId } = tieMatchUpSide ?? {};
55707
55799
  const pairParticipant = pairParticipantId && getParticipants$1({
55708
55800
  participantFilters: { participantIds: [pairParticipantId] },
55709
55801
  tournamentRecord,
@@ -55739,26 +55831,24 @@ function removeTieMatchUpParticipantId(params) {
55739
55831
  if (result.error)
55740
55832
  console.log("cleanup", { result });
55741
55833
  }
55742
- } else {
55743
- if (individualParticipantIds.length === 1) {
55744
- const { participant: existingParticipant } = getPairedParticipant({
55745
- participantIds: individualParticipantIds,
55834
+ } else if (individualParticipantIds.length === 1) {
55835
+ const { participant: existingParticipant } = getPairedParticipant({
55836
+ participantIds: individualParticipantIds,
55837
+ tournamentRecord
55838
+ });
55839
+ if (!existingParticipant) {
55840
+ const newPairParticipant = {
55841
+ participantRole: COMPETITOR,
55842
+ individualParticipantIds,
55843
+ participantType: PAIR
55844
+ };
55845
+ const result = addParticipant$1({
55846
+ participant: newPairParticipant,
55847
+ pairOverride: true,
55746
55848
  tournamentRecord
55747
55849
  });
55748
- if (!existingParticipant) {
55749
- const newPairParticipant = {
55750
- participantRole: COMPETITOR,
55751
- individualParticipantIds,
55752
- participantType: PAIR
55753
- };
55754
- const result = addParticipant$1({
55755
- participant: newPairParticipant,
55756
- pairOverride: true,
55757
- tournamentRecord
55758
- });
55759
- if (result.error)
55760
- return decorateResult({ result, stack });
55761
- }
55850
+ if (result.error)
55851
+ return decorateResult({ result, stack });
55762
55852
  }
55763
55853
  }
55764
55854
  } else {
@@ -55820,9 +55910,9 @@ function getPositionAssignments({
55820
55910
  structure
55821
55911
  });
55822
55912
  return {
55823
- error,
55824
- positionAssignments: assignments || [],
55825
- structureId: structure?.structureId
55913
+ positionAssignments: assignments ?? [],
55914
+ structureId: structure?.structureId,
55915
+ error
55826
55916
  };
55827
55917
  }
55828
55918
 
@@ -56168,7 +56258,7 @@ function addEventEntryPairs({
56168
56258
  return { error: MISSING_EVENT };
56169
56259
  if (event.eventType !== DOUBLES$1)
56170
56260
  return { error: INVALID_EVENT_TYPE };
56171
- const tournamentParticipants = tournamentRecord.participants || [];
56261
+ const tournamentParticipants = tournamentRecord.participants ?? [];
56172
56262
  const individualParticipantIds = tournamentParticipants.filter((participant) => participant.participantType === INDIVIDUAL).map((participant) => participant.participantId);
56173
56263
  const invalidParticipantIds = individualParticipantIds.filter(
56174
56264
  (participantId) => !individualParticipantIds.includes(participantId)
@@ -56183,7 +56273,7 @@ function addEventEntryPairs({
56183
56273
  const existingParticipantIdPairs = tournamentParticipants.filter((participant) => participant.participantType === PAIR).map((participant) => participant.individualParticipantIds);
56184
56274
  const provisionalParticipants = participantIdPairs.map(
56185
56275
  (individualParticipantIds2) => ({
56186
- participantId: uuids?.pop() || UUID(),
56276
+ participantId: uuids?.pop() ?? UUID(),
56187
56277
  participantRole: COMPETITOR,
56188
56278
  individualParticipantIds: individualParticipantIds2,
56189
56279
  participantType: PAIR
@@ -56325,7 +56415,7 @@ function assignSeedPositions(params) {
56325
56415
  const { seedAssignments, seedLimit } = result;
56326
56416
  const mergeObject = Object.assign(
56327
56417
  {},
56328
- ...(seedAssignments || []).filter((assignment) => assignment.seedNumber).map((assignment) => ({ [assignment.seedNumber]: assignment }))
56418
+ ...(seedAssignments ?? []).filter((assignment) => assignment.seedNumber).map((assignment) => ({ [assignment.seedNumber]: assignment }))
56329
56419
  );
56330
56420
  assignments.forEach((newAssignment) => {
56331
56421
  const { seedNumber } = newAssignment;
@@ -56606,17 +56696,14 @@ function addEvent({
56606
56696
  context
56607
56697
  };
56608
56698
  }
56609
- const eventRecord = Object.assign(
56610
- {},
56611
- {
56612
- drawDefinitions: [],
56613
- eventType: TypeEnum.Singles,
56614
- entries: [],
56615
- startDate,
56616
- endDate
56617
- },
56618
- event
56619
- );
56699
+ const eventRecord = {
56700
+ drawDefinitions: [],
56701
+ eventType: TypeEnum.Singles,
56702
+ entries: [],
56703
+ startDate,
56704
+ endDate,
56705
+ ...event
56706
+ };
56620
56707
  if (event.eventType === TypeEnum.Team) {
56621
56708
  if (event.tieFormat) {
56622
56709
  const result = validateTieFormat({ tieFormat: event.tieFormat });
@@ -56646,7 +56733,7 @@ function addEvent({
56646
56733
  if (!suppressNotifications) {
56647
56734
  const { topics } = getTopics();
56648
56735
  if (topics.includes(ADD_MATCHUPS)) {
56649
- const matchUps = allEventMatchUps({ event }).matchUps || [];
56736
+ const matchUps = allEventMatchUps({ event }).matchUps ?? [];
56650
56737
  addMatchUpsNotice({
56651
56738
  tournamentId: tournamentRecord?.tournamentId,
56652
56739
  eventId: event.eventId,
@@ -57263,11 +57350,9 @@ function setMatchUpFormat({
57263
57350
  drawDefinition: drawDefinition2
57264
57351
  });
57265
57352
  }
57266
- } else {
57267
- if (event2.matchUpFormat !== matchUpFormat) {
57268
- event2.matchUpFormat = matchUpFormat;
57269
- modificationsCount += 1;
57270
- }
57353
+ } else if (event2.matchUpFormat !== matchUpFormat) {
57354
+ event2.matchUpFormat = matchUpFormat;
57355
+ modificationsCount += 1;
57271
57356
  }
57272
57357
  }
57273
57358
  if (!modificationsCount)
@@ -57488,7 +57573,7 @@ function getScaledEntries({
57488
57573
  }) {
57489
57574
  if (!tournamentRecord)
57490
57575
  return { error: MISSING_TOURNAMENT_RECORD };
57491
- entries = entries || event?.entries || [];
57576
+ entries = entries ?? event?.entries ?? [];
57492
57577
  const stageEntries = entries.filter(
57493
57578
  (entry) => (!stage || !entry.entryStage || entry.entryStage === stage) && (!stageSequence || !entry.entryStageSequence || entry.entryStageSequence === stageSequence) && STRUCTURE_SELECTED_STATUSES.includes(entry.entryStatus)
57494
57579
  );
@@ -57807,7 +57892,7 @@ function generateFlightProfile(params) {
57807
57892
  } = params;
57808
57893
  if (!event)
57809
57894
  return { error: MISSING_EVENT };
57810
- const eventEntries = event.entries || [];
57895
+ const eventEntries = event.entries ?? [];
57811
57896
  const { flightProfile } = getFlightProfile({ event });
57812
57897
  if (flightProfile && attachFlightProfile$1 && !deleteExisting) {
57813
57898
  return { error: EXISTING_PROFILE };
@@ -57856,7 +57941,7 @@ function generateFlightProfile(params) {
57856
57941
  const flightNumber = index + 1;
57857
57942
  return {
57858
57943
  flightNumber,
57859
- drawId: uuids?.pop() || UUID(),
57944
+ drawId: uuids?.pop() ?? UUID(),
57860
57945
  drawEntries: getDrawEntries(splitEntries[index]),
57861
57946
  drawName: drawNames?.length && drawNames[index] || `${drawNameRoot} ${flightNumber}`
57862
57947
  };
@@ -58152,7 +58237,7 @@ function pruneDrawDefinition({
58152
58237
  const structureData = drawAnalysis.structuresData.find(
58153
58238
  ({ structureId }) => mainStructure.structureId === structureId
58154
58239
  );
58155
- const matchUps = mainStructure.matchUps || [];
58240
+ const matchUps = mainStructure.matchUps ?? [];
58156
58241
  relevantMatchUps = matchUps.sort((a, b) => a.roundPosition - b.roundPosition).filter(
58157
58242
  ({ roundNumber }) => !structureData.inactiveRounds.includes(roundNumber)
58158
58243
  );
@@ -58167,7 +58252,7 @@ function pruneDrawDefinition({
58167
58252
  (matchUpId) => !matchPlayMatchUpIds.includes(matchUpId)
58168
58253
  );
58169
58254
  deletedMatchUpIds.push(...matchUpIdsToDelete);
58170
- const existingDrawPositionPairings = matchPlayMatchUps.flatMap((matchUp) => matchUp.drawPositions || []).filter(Boolean);
58255
+ const existingDrawPositionPairings = matchPlayMatchUps.flatMap((matchUp) => matchUp.drawPositions ?? []).filter(Boolean);
58171
58256
  const existingDrawPositions = existingDrawPositionPairings.flat();
58172
58257
  const drawPositionsMap = Object.assign(
58173
58258
  {},
@@ -58224,7 +58309,7 @@ function modifyEventEntries({
58224
58309
  return { error: MISSING_TOURNAMENT_RECORD };
58225
58310
  if (!event)
58226
58311
  return { error: MISSING_EVENT };
58227
- const tournamentParticipants = tournamentRecord.participants || [];
58312
+ const tournamentParticipants = tournamentRecord.participants ?? [];
58228
58313
  const individualParticipantIds = tournamentParticipants.filter((participant) => participant.participantType === INDIVIDUAL).map((participant) => participant.participantId);
58229
58314
  const incomingIndividualParticipantIds = unpairedParticipantIds.concat(...participantIdPairs).flat(Infinity);
58230
58315
  const invalidParticipantIds = incomingIndividualParticipantIds.filter(
@@ -58274,7 +58359,7 @@ function modifyEventEntries({
58274
58359
  entryStage
58275
58360
  })
58276
58361
  );
58277
- event.entries = (event.entries || []).filter(
58362
+ event.entries = (event.entries ?? []).filter(
58278
58363
  (entry) => entry.entryStage === entryStage
58279
58364
  );
58280
58365
  event.entries = event.entries.concat(
@@ -58305,7 +58390,7 @@ function addFlight({
58305
58390
  if (!drawName)
58306
58391
  return decorateResult({ result: { error: MISSING_VALUE }, stack });
58307
58392
  if (drawEntries?.length) {
58308
- const enteredParticipantIds = (event.entries || []).map(
58393
+ const enteredParticipantIds = (event.entries ?? []).map(
58309
58394
  extractAttributes("participantId")
58310
58395
  );
58311
58396
  const flightParticipantIds = drawEntries.map(
@@ -59429,7 +59514,10 @@ function isValidForQualifying({ structureId, drawDefinition }) {
59429
59514
  if (result.error)
59430
59515
  return result;
59431
59516
  const targetFeedProfiles = result.links.target.flatMap((t) => t.target.feedProfile).filter(Boolean);
59432
- const valid = !intersection([BOTTOM_UP, TOP_DOWN, RANDOM], targetFeedProfiles).length;
59517
+ const valid = !intersection(
59518
+ [BOTTOM_UP, TOP_DOWN, RANDOM, WATERFALL],
59519
+ targetFeedProfiles
59520
+ ).length;
59433
59521
  return { ...SUCCESS, valid };
59434
59522
  }
59435
59523
 
@@ -59786,7 +59874,7 @@ function getPredictiveAccuracy(params) {
59786
59874
  const ascending = scaleProfile?.ascending ?? params.ascending ?? false;
59787
59875
  const valueAccessor = scaleProfile?.accessor ?? params.valueAccessor;
59788
59876
  const ratingsRangeDifference = Array.isArray(scaleProfile?.range) ? Math.abs(scaleProfile.range[0] - scaleProfile.range[1]) : 0;
59789
- const zoneMargin = isConvertableInteger(zonePct) && ratingsRangeDifference ? (zonePct || 0 / 100) * ratingsRangeDifference : params.zoneMargin || ratingsRangeDifference;
59877
+ const zoneMargin = isConvertableInteger(zonePct) && ratingsRangeDifference ? (zonePct ?? 0 / 100) * ratingsRangeDifference : params.zoneMargin ?? ratingsRangeDifference;
59790
59878
  const contextProfile = { withScaleValues: true, withCompetitiveness: true };
59791
59879
  const contextFilters = {
59792
59880
  matchUpTypes: matchUpType ? [matchUpType] : [SINGLES$1, DOUBLES$1]
@@ -59824,7 +59912,7 @@ function getPredictiveAccuracy(params) {
59824
59912
  }
59825
59913
  const relevantMatchUps = matchUps.filter(
59826
59914
  ({ winningSide, score, sides, matchUpStatus }) => ![RETIRED$1, DEFAULTED, WALKOVER$2, DEAD_RUBBER, ABANDONED$1].includes(
59827
- matchUpStatus || ""
59915
+ matchUpStatus ?? ""
59828
59916
  ) && scoreHasValue({ score }) && sides?.length === 2 && winningSide
59829
59917
  );
59830
59918
  const accuracy = getGroupingAccuracy({
@@ -61101,7 +61189,7 @@ function getTournamentPoints({
61101
61189
  policyTypes: [POLICY_TYPE_RANKING_POINTS],
61102
61190
  tournamentRecord
61103
61191
  });
61104
- const pointsPolicy = policyDefinitions?.[POLICY_TYPE_RANKING_POINTS] || attachedPolicies?.[POLICY_TYPE_RANKING_POINTS];
61192
+ const pointsPolicy = policyDefinitions?.[POLICY_TYPE_RANKING_POINTS] ?? attachedPolicies?.[POLICY_TYPE_RANKING_POINTS];
61105
61193
  if (!pointsPolicy)
61106
61194
  return { error: MISSING_POLICY_DEFINITION };
61107
61195
  const awardProfiles = pointsPolicy.awardProfiles;
@@ -61116,7 +61204,7 @@ function getTournamentPoints({
61116
61204
  const personPoints = {};
61117
61205
  const teamPoints = {};
61118
61206
  const pairPoints = {};
61119
- for (const participant of participantsWithOutcomes || []) {
61207
+ for (const participant of participantsWithOutcomes ?? []) {
61120
61208
  const { participantType, participantId, person, draws } = participant;
61121
61209
  for (const draw of draws) {
61122
61210
  const { drawId, structureParticipation, eventId } = draw;
@@ -61424,8 +61512,9 @@ function generateDynamicRatings({
61424
61512
  matchUpFilters: { matchUpIds, matchUpStatuses: completedMatchUpStatuses },
61425
61513
  tournamentRecord,
61426
61514
  inContext: true
61427
- }).matchUps || [];
61428
- for (const matchUp of matchUps.sort(matchUpSort)) {
61515
+ }).matchUps ?? [];
61516
+ matchUps.sort(matchUpSort);
61517
+ for (const matchUp of matchUps) {
61429
61518
  const { endDate, matchUpFormat, score, sides, winningSide } = matchUp;
61430
61519
  const matchUpType = matchUp.matchUpType;
61431
61520
  const scaleAttributes = {
@@ -61441,12 +61530,12 @@ function generateDynamicRatings({
61441
61530
  };
61442
61531
  const sideParticipantIds = Object.assign(
61443
61532
  {},
61444
- ...(sides || []).map((side) => {
61533
+ ...(sides ?? []).map((side) => {
61445
61534
  const { sideNumber, participant } = side;
61446
61535
  return sideNumber && {
61447
61536
  [sideNumber]: [
61448
61537
  participant?.participantId,
61449
- ...participant?.individualParticipantIds || []
61538
+ ...participant?.individualParticipantIds ?? []
61450
61539
  ].filter(Boolean).flat()
61451
61540
  };
61452
61541
  })
@@ -62983,11 +63072,10 @@ function generateParticipants(params) {
62983
63072
  }
62984
63073
  if (ratingType && ratingsParameters$1[ratingType]) {
62985
63074
  const { ratingMax, ratingMin, ratingAttributes } = category;
62986
- const ratingParameters = Object.assign(
62987
- {},
62988
- ratingsParameters$1[ratingType],
62989
- ratingAttributes || {}
62990
- );
63075
+ const ratingParameters = {
63076
+ ...ratingsParameters$1[ratingType],
63077
+ ...ratingAttributes || {}
63078
+ };
62991
63079
  const {
62992
63080
  attributes = {},
62993
63081
  decimalsCount,
@@ -63326,15 +63414,13 @@ function getParticipantsCount({
63326
63414
  } else if (drawSize + alternatesCount && drawSize + alternatesCount > largestDoublesDraw) {
63327
63415
  largestDoublesDraw = drawSize + alternatesCount;
63328
63416
  }
63329
- } else {
63330
- if (requiresUniqueParticipants) {
63331
- const additionalParticipantsCount = drawSize + alternatesCount;
63332
- if (gender)
63333
- gendersCount[gender] += additionalParticipantsCount;
63334
- uniqueParticipantsCount += additionalParticipantsCount;
63335
- } else if (drawSize && drawSize > largestSinglesDraw) {
63336
- largestSinglesDraw = drawSize + alternatesCount;
63337
- }
63417
+ } else if (requiresUniqueParticipants) {
63418
+ const additionalParticipantsCount = drawSize + alternatesCount;
63419
+ if (gender)
63420
+ gendersCount[gender] += additionalParticipantsCount;
63421
+ uniqueParticipantsCount += additionalParticipantsCount;
63422
+ } else if (drawSize && drawSize > largestSinglesDraw) {
63423
+ largestSinglesDraw = drawSize + alternatesCount;
63338
63424
  }
63339
63425
  };
63340
63426
  eventProfiles?.forEach((eventProfile) => {
@@ -64270,7 +64356,7 @@ function generateVenues({
64270
64356
  for (const [index, venueProfile] of venueProfiles.entries()) {
64271
64357
  const {
64272
64358
  venueAbbreviation,
64273
- venueId = uuids?.pop() || UUID(),
64359
+ venueId = uuids?.pop() ?? UUID(),
64274
64360
  dateAvailability,
64275
64361
  startTime = "07:00",
64276
64362
  endTime = "19:00",
@@ -64533,7 +64619,7 @@ function generateScheduledRounds({
64533
64619
  const containedStructures = getContainedStructures({
64534
64620
  tournamentRecord
64535
64621
  }).containedStructures;
64536
- const matchUps = allTournamentMatchUps({ tournamentRecord }).matchUps || [];
64622
+ const matchUps = allTournamentMatchUps({ tournamentRecord }).matchUps ?? [];
64537
64623
  const { tournamentId } = tournamentRecord;
64538
64624
  const scheduledRounds = [];
64539
64625
  for (const dateProfile of schedulingProfile) {
@@ -64554,7 +64640,7 @@ function generateScheduledRounds({
64554
64640
  if (roundNumber && !winnerFinishingPositionRange) {
64555
64641
  structureId = Object.keys(containedStructures).find(
64556
64642
  (containingStructureId) => containedStructures[containingStructureId].includes(structureId)
64557
- ) || structureId;
64643
+ ) ?? structureId;
64558
64644
  }
64559
64645
  const roundToSchedule = {
64560
64646
  tournamentId,