tods-competition-factory 1.7.2 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -333,7 +333,7 @@ const matchUpFormatCode = {
333
333
  };
334
334
 
335
335
  function factoryVersion() {
336
- return "1.7.2";
336
+ return "1.7.3";
337
337
  }
338
338
 
339
339
  function getObjectTieFormat(obj) {
@@ -6183,7 +6183,7 @@ function getRoundMatchUps$1({
6183
6183
  roundProfile[roundNumber].finishingRound = finishingRoundMap[roundNumber]?.finishingRound;
6184
6184
  roundProfile[roundNumber].roundName = finishingRoundMap[roundNumber]?.roundName;
6185
6185
  roundProfile[roundNumber].abbreviatedRoundName = finishingRoundMap[roundNumber]?.abbreviatedRoundName;
6186
- roundProfile[roundNumber].finishingPositionRange = roundMatchUps[roundNumber][0].finishingPositionRange;
6186
+ roundProfile[roundNumber].finishingPositionRange = roundMatchUps[roundNumber]?.[0]?.finishingPositionRange;
6187
6187
  if (roundNumber === 1 || !roundProfile[roundNumber - 1]) {
6188
6188
  const orderedDrawPositions = currentRoundDrawPositions.sort(numericSort);
6189
6189
  const pairedDrawPositions = chunkArray(orderedDrawPositions, 2);
@@ -28916,9 +28916,9 @@ function getParticipantEntries(params) {
28916
28916
  if (!participation)
28917
28917
  return;
28918
28918
  if (!finishingPositionRange)
28919
- finishingPositionRange = participation.finishingPositionRange;
28920
- if (diff(finishingPositionRange) > diff(participation.finishingPositionRange))
28921
- finishingPositionRange = participation.finishingPositionRange;
28919
+ finishingPositionRange = participation?.finishingPositionRange;
28920
+ if (diff(finishingPositionRange) > diff(participation?.finishingPositionRange))
28921
+ finishingPositionRange = participation?.finishingPositionRange;
28922
28922
  const notQualifying = participation.stage !== QUALIFYING;
28923
28923
  if (notQualifying)
28924
28924
  nonQualifyingOrder += 1;
@@ -28929,8 +28929,10 @@ function getParticipantEntries(params) {
28929
28929
  flightNumber
28930
28930
  });
28931
28931
  }).filter(Boolean);
28932
- participantAggregator.draws[drawId].finishingPositionRange = finishingPositionRange;
28933
- participantAggregator.draws[drawId].structureParticipation = orderedParticipation;
28932
+ if (participantAggregator.draws[drawId]) {
28933
+ participantAggregator.draws[drawId].finishingPositionRange = finishingPositionRange;
28934
+ participantAggregator.draws[drawId].structureParticipation = orderedParticipation;
28935
+ }
28934
28936
  }
28935
28937
  }
28936
28938
  }
@@ -44332,21 +44334,30 @@ function generateAdHocMatchUps$1({
44332
44334
  structureId = drawDefinition.structures?.[0]?.structureId;
44333
44335
  if (typeof structureId !== "string")
44334
44336
  return { error: MISSING_STRUCTURE_ID };
44335
- if (newRound && !matchUpsCount) {
44337
+ const structure = drawDefinition.structures?.find(
44338
+ (structure2) => structure2.structureId === structureId
44339
+ );
44340
+ if (!structure)
44341
+ return { error: STRUCTURE_NOT_FOUND };
44342
+ if (!matchUpsCount) {
44336
44343
  const selectedEntries = drawDefinition?.entries?.filter((entry) => {
44337
44344
  const entryStatus = entry.entryStatus;
44338
44345
  return STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
44339
44346
  }) ?? [];
44340
- matchUpsCount = Math.floor(selectedEntries?.length / 2) || 1;
44347
+ const roundMatchUpsCount = Math.floor(selectedEntries?.length / 2) || 1;
44348
+ if (newRound) {
44349
+ matchUpsCount = roundMatchUpsCount;
44350
+ } else {
44351
+ const maxRemaining = roundMatchUpsCount - (structure.matchUps?.length || 0);
44352
+ if (maxRemaining > 0)
44353
+ matchUpsCount = maxRemaining;
44354
+ }
44341
44355
  }
44342
44356
  if (participantIdPairings && !Array.isArray(participantIdPairings) || matchUpsCount && !isConvertableInteger(matchUpsCount) || matchUpIds && !Array.isArray(matchUpIds) || !participantIdPairings && !matchUpsCount) {
44343
44357
  return { error: INVALID_VALUES, info: "matchUpsCount or pairings error" };
44344
44358
  }
44345
- const structure = drawDefinition?.structures?.find(
44346
- (structure2) => structure2.structureId === structureId
44347
- );
44348
44359
  let structureHasRoundPositions;
44349
- const existingMatchUps = structure?.matchUps;
44360
+ const existingMatchUps = structure.matchUps ?? [];
44350
44361
  const lastRoundNumber = existingMatchUps?.reduce(
44351
44362
  (roundNumber2, matchUp) => {
44352
44363
  if (matchUp.roundPosition)
@@ -44355,12 +44366,12 @@ function generateAdHocMatchUps$1({
44355
44366
  },
44356
44367
  0
44357
44368
  );
44358
- if (structure?.structures || structureHasRoundPositions || structure?.finishingPosition === ROUND_OUTCOME) {
44369
+ if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
44359
44370
  return { error: INVALID_STRUCTURE };
44360
44371
  }
44361
44372
  if (roundNumber && roundNumber - 1 > (lastRoundNumber || 0))
44362
44373
  return { error: INVALID_VALUES, info: "roundNumber error" };
44363
- const nextRoundNumber = roundNumber ?? (newRound ? (lastRoundNumber ?? 0) + 1 : lastRoundNumber ?? 1);
44374
+ const nextRoundNumber = roundNumber ?? (newRound && (lastRoundNumber ?? 0) + 1 || lastRoundNumber || 1);
44364
44375
  participantIdPairings = participantIdPairings ?? generateRange(0, matchUpsCount).map(() => ({
44365
44376
  participantIds: [void 0, void 0]
44366
44377
  }));