tods-competition-factory 1.7.1 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -333,7 +333,7 @@ const matchUpFormatCode = {
333
333
  };
334
334
 
335
335
  function factoryVersion() {
336
- return "1.7.1";
336
+ return "1.7.3";
337
337
  }
338
338
 
339
339
  function getObjectTieFormat(obj) {
@@ -2578,15 +2578,17 @@ function validateTieFormat(params) {
2578
2578
  function validateCollectionDefinition({
2579
2579
  collectionDefinition,
2580
2580
  checkCollectionIds,
2581
+ checkGender = true,
2581
2582
  referenceGender,
2582
- checkGender
2583
+ event
2583
2584
  }) {
2585
+ referenceGender = referenceGender ?? event?.gender;
2584
2586
  const errors = [];
2585
2587
  if (typeof collectionDefinition !== "object") {
2586
2588
  errors.push(
2587
2589
  `collectionDefinition must be an object: ${collectionDefinition}`
2588
2590
  );
2589
- return { errors };
2591
+ return { errors, error: INVALID_OBJECT };
2590
2592
  }
2591
2593
  const {
2592
2594
  collectionValueProfiles,
@@ -2645,7 +2647,7 @@ function validateCollectionDefinition({
2645
2647
  errors.push(`Invalid gender: ${gender}`);
2646
2648
  }
2647
2649
  if (errors.length)
2648
- return { errors };
2650
+ return { errors, error: INVALID_OBJECT };
2649
2651
  return { valid: true };
2650
2652
  }
2651
2653
  function checkTieFormat(tieFormat) {
@@ -6181,7 +6183,7 @@ function getRoundMatchUps$1({
6181
6183
  roundProfile[roundNumber].finishingRound = finishingRoundMap[roundNumber]?.finishingRound;
6182
6184
  roundProfile[roundNumber].roundName = finishingRoundMap[roundNumber]?.roundName;
6183
6185
  roundProfile[roundNumber].abbreviatedRoundName = finishingRoundMap[roundNumber]?.abbreviatedRoundName;
6184
- roundProfile[roundNumber].finishingPositionRange = roundMatchUps[roundNumber][0].finishingPositionRange;
6186
+ roundProfile[roundNumber].finishingPositionRange = roundMatchUps[roundNumber]?.[0]?.finishingPositionRange;
6185
6187
  if (roundNumber === 1 || !roundProfile[roundNumber - 1]) {
6186
6188
  const orderedDrawPositions = currentRoundDrawPositions.sort(numericSort);
6187
6189
  const pairedDrawPositions = chunkArray(orderedDrawPositions, 2);
@@ -21760,7 +21762,7 @@ function assignMatchUpDrawPosition({
21760
21762
  inContext: true,
21761
21763
  drawDefinition,
21762
21764
  matchUpsMap
21763
- }).matchUps || [];
21765
+ }).matchUps ?? [];
21764
21766
  }
21765
21767
  const inContextMatchUp = inContextDrawMatchUps.find(
21766
21768
  (m) => m.matchUpId === matchUpId
@@ -21774,7 +21776,7 @@ function assignMatchUpDrawPosition({
21774
21776
  const matchUp = matchUpsMap?.drawMatchUps?.find(
21775
21777
  (matchUp2) => matchUp2.matchUpId === matchUpId
21776
21778
  );
21777
- const drawPositions = matchUp?.drawPositions || [];
21779
+ const drawPositions = matchUp?.drawPositions ?? [];
21778
21780
  const { positionAdded, positionAssigned, updatedDrawPositions } = getUpdatedDrawPositions({ drawPosition, drawPositions });
21779
21781
  const { positionAssignments } = getPositionAssignments$1({
21780
21782
  drawDefinition,
@@ -21791,7 +21793,7 @@ function assignMatchUpDrawPosition({
21791
21793
  inContext: true,
21792
21794
  drawDefinition,
21793
21795
  matchUpsMap
21794
- }).matchUps || [];
21796
+ }).matchUps ?? [];
21795
21797
  const exitWinningSide = isDoubleExitExit && getExitWinningSide({
21796
21798
  inContextDrawMatchUps,
21797
21799
  drawPosition,
@@ -21879,7 +21881,7 @@ function assignMatchUpDrawPosition({
21879
21881
  const inContextTargetMatchUp = inContextDrawMatchUps?.find(
21880
21882
  ({ matchUpId: matchUpId2 }) => matchUpId2 === matchUp.matchUpId
21881
21883
  );
21882
- const sides = inContextTargetMatchUp?.sides || [];
21884
+ const sides = inContextTargetMatchUp?.sides ?? [];
21883
21885
  const drawPositionSideIndex = sides.reduce(
21884
21886
  (index, side, i) => side.drawPosition === drawPosition ? i : index,
21885
21887
  void 0
@@ -28914,9 +28916,9 @@ function getParticipantEntries(params) {
28914
28916
  if (!participation)
28915
28917
  return;
28916
28918
  if (!finishingPositionRange)
28917
- finishingPositionRange = participation.finishingPositionRange;
28918
- if (diff(finishingPositionRange) > diff(participation.finishingPositionRange))
28919
- finishingPositionRange = participation.finishingPositionRange;
28919
+ finishingPositionRange = participation?.finishingPositionRange;
28920
+ if (diff(finishingPositionRange) > diff(participation?.finishingPositionRange))
28921
+ finishingPositionRange = participation?.finishingPositionRange;
28920
28922
  const notQualifying = participation.stage !== QUALIFYING;
28921
28923
  if (notQualifying)
28922
28924
  nonQualifyingOrder += 1;
@@ -28927,8 +28929,10 @@ function getParticipantEntries(params) {
28927
28929
  flightNumber
28928
28930
  });
28929
28931
  }).filter(Boolean);
28930
- participantAggregator.draws[drawId].finishingPositionRange = finishingPositionRange;
28931
- participantAggregator.draws[drawId].structureParticipation = orderedParticipation;
28932
+ if (participantAggregator.draws[drawId]) {
28933
+ participantAggregator.draws[drawId].finishingPositionRange = finishingPositionRange;
28934
+ participantAggregator.draws[drawId].structureParticipation = orderedParticipation;
28935
+ }
28932
28936
  }
28933
28937
  }
28934
28938
  }
@@ -30333,8 +30337,10 @@ function addCollectionDefinition$1({
30333
30337
  updateInProgressMatchUps = true,
30334
30338
  collectionDefinition,
30335
30339
  tournamentRecord,
30340
+ referenceGender,
30336
30341
  drawDefinition,
30337
30342
  tieFormatName,
30343
+ enforceGender,
30338
30344
  structureId,
30339
30345
  matchUpId,
30340
30346
  matchUp,
@@ -30342,8 +30348,18 @@ function addCollectionDefinition$1({
30342
30348
  uuids,
30343
30349
  event
30344
30350
  }) {
30351
+ const appliedPolicies = getAppliedPolicies({
30352
+ tournamentRecord,
30353
+ drawDefinition,
30354
+ event
30355
+ }).appliedPolicies ?? {};
30356
+ enforceGender = enforceGender ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS]?.participants?.enforceGender;
30357
+ const checkGender = !!(enforceGender !== false && event?.gender);
30345
30358
  const { valid, errors } = validateCollectionDefinition({
30346
- collectionDefinition
30359
+ collectionDefinition,
30360
+ referenceGender,
30361
+ checkGender,
30362
+ event
30347
30363
  });
30348
30364
  if (!valid)
30349
30365
  return { error: INVALID_VALUES, errors };
@@ -30358,7 +30374,7 @@ function addCollectionDefinition$1({
30358
30374
  if (result?.error)
30359
30375
  return { error: result.error };
30360
30376
  const structure = result?.structure;
30361
- matchUp = matchUp || result?.matchUp;
30377
+ matchUp = matchUp ?? result?.matchUp;
30362
30378
  const existingTieFormat = result?.tieFormat;
30363
30379
  const tieFormat = copyTieFormat(existingTieFormat);
30364
30380
  result = validateTieFormat({ tieFormat });
@@ -30398,12 +30414,12 @@ function addCollectionDefinition$1({
30398
30414
  result = validateTieFormat({ tieFormat: prunedTieFormat });
30399
30415
  if (result?.error)
30400
30416
  return { error: result.error };
30401
- if (eventId) {
30417
+ if (eventId && event) {
30402
30418
  event.tieFormat = prunedTieFormat;
30403
- for (const drawDefinition2 of event.drawDefinitions || []) {
30419
+ for (const drawDefinition2 of event.drawDefinitions ?? []) {
30404
30420
  if (drawDefinition2.tieFormat)
30405
30421
  continue;
30406
- for (const structure2 of drawDefinition2.structures || []) {
30422
+ for (const structure2 of drawDefinition2.structures ?? []) {
30407
30423
  if (structure2.tieFormat)
30408
30424
  continue;
30409
30425
  const result2 = updateStructureMatchUps({
@@ -30468,7 +30484,7 @@ function addCollectionDefinition$1({
30468
30484
  });
30469
30485
  } else if (drawDefinition) {
30470
30486
  drawDefinition.tieFormat = prunedTieFormat;
30471
- for (const structure2 of drawDefinition.structures || []) {
30487
+ for (const structure2 of drawDefinition.structures ?? []) {
30472
30488
  const result2 = updateStructureMatchUps({
30473
30489
  updateInProgressMatchUps,
30474
30490
  collectionDefinition,
@@ -30490,7 +30506,6 @@ function addCollectionDefinition$1({
30490
30506
  } else {
30491
30507
  return { error: MISSING_DRAW_DEFINITION };
30492
30508
  }
30493
- const { appliedPolicies } = getAppliedPolicies({ tournamentRecord });
30494
30509
  if (appliedPolicies?.audit?.[TIE_FORMAT_MODIFICATIONS]) {
30495
30510
  const auditData = definedAttributes({
30496
30511
  drawId: drawDefinition?.drawId,
@@ -44091,9 +44106,12 @@ function deleteAdHocMatchUps$1({
44091
44106
  if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
44092
44107
  return { error: INVALID_STRUCTURE };
44093
44108
  }
44094
- const matchUpsToDelete = existingMatchUps?.filter(
44095
- ({ matchUpId }) => matchUpIds.includes(matchUpId)
44096
- ) ?? [];
44109
+ const matchUpIdsWithScoreValue = [];
44110
+ const matchUpsToDelete = existingMatchUps?.filter(({ matchUpId, score }) => {
44111
+ if (scoreHasValue({ score }))
44112
+ matchUpIdsWithScoreValue.push(matchUpId);
44113
+ return matchUpIds.includes(matchUpId);
44114
+ }) ?? [];
44097
44115
  const matchUpIdsToDelete = matchUpsToDelete.map(
44098
44116
  extractAttributes("matchUpId")
44099
44117
  );
@@ -44113,15 +44131,40 @@ function deleteAdHocMatchUps$1({
44113
44131
  );
44114
44132
  const missingRoundNumbers = getMissingSequenceNumbers(roundNumbers);
44115
44133
  if (missingRoundNumbers.length) {
44116
- const roundNumbersToConsider = missingRoundNumbers.reverse();
44117
- for (const roundNumber of roundNumbersToConsider) {
44134
+ missingRoundNumbers.reverse();
44135
+ for (const roundNumber of missingRoundNumbers) {
44118
44136
  structure.matchUps.forEach((matchUp) => {
44119
44137
  if (matchUp.roundNumber && matchUp.roundNumber > roundNumber) {
44120
44138
  matchUp.roundNumber -= 1;
44139
+ modifyMatchUpNotice({
44140
+ tournamentId: tournamentRecord?.tournamentId,
44141
+ context: ["adHoc round deletion"],
44142
+ eventId: event?.eventId,
44143
+ drawDefinition,
44144
+ matchUp
44145
+ });
44121
44146
  }
44122
44147
  });
44123
44148
  }
44124
44149
  }
44150
+ if (matchUpIdsWithScoreValue.length) {
44151
+ structure.positionAssignments = unique(
44152
+ structure.matchUps.flatMap(
44153
+ (matchUp) => (matchUp.sides ?? []).map((side) => side.participantId)
44154
+ ).filter(Boolean)
44155
+ ).map((participantId) => ({ participantId }));
44156
+ const matchUpFormat = structure?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
44157
+ const result = updateAssignmentParticipantResults({
44158
+ positionAssignments: structure.positionAssignments,
44159
+ matchUps: structure.matchUps,
44160
+ tournamentRecord,
44161
+ drawDefinition,
44162
+ matchUpFormat,
44163
+ event
44164
+ });
44165
+ if (result.error)
44166
+ console.log(result);
44167
+ }
44125
44168
  modifyDrawNotice({
44126
44169
  structureIds: [structureId],
44127
44170
  eventId: event?.eventId,
@@ -44291,14 +44334,30 @@ function generateAdHocMatchUps$1({
44291
44334
  structureId = drawDefinition.structures?.[0]?.structureId;
44292
44335
  if (typeof structureId !== "string")
44293
44336
  return { error: MISSING_STRUCTURE_ID };
44337
+ const structure = drawDefinition.structures?.find(
44338
+ (structure2) => structure2.structureId === structureId
44339
+ );
44340
+ if (!structure)
44341
+ return { error: STRUCTURE_NOT_FOUND };
44342
+ if (!matchUpsCount) {
44343
+ const selectedEntries = drawDefinition?.entries?.filter((entry) => {
44344
+ const entryStatus = entry.entryStatus;
44345
+ return STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
44346
+ }) ?? [];
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
+ }
44355
+ }
44294
44356
  if (participantIdPairings && !Array.isArray(participantIdPairings) || matchUpsCount && !isConvertableInteger(matchUpsCount) || matchUpIds && !Array.isArray(matchUpIds) || !participantIdPairings && !matchUpsCount) {
44295
44357
  return { error: INVALID_VALUES, info: "matchUpsCount or pairings error" };
44296
44358
  }
44297
- const structure = drawDefinition?.structures?.find(
44298
- (structure2) => structure2.structureId === structureId
44299
- );
44300
44359
  let structureHasRoundPositions;
44301
- const existingMatchUps = structure?.matchUps;
44360
+ const existingMatchUps = structure.matchUps ?? [];
44302
44361
  const lastRoundNumber = existingMatchUps?.reduce(
44303
44362
  (roundNumber2, matchUp) => {
44304
44363
  if (matchUp.roundPosition)
@@ -44307,12 +44366,12 @@ function generateAdHocMatchUps$1({
44307
44366
  },
44308
44367
  0
44309
44368
  );
44310
- if (structure?.structures || structureHasRoundPositions || structure?.finishingPosition === ROUND_OUTCOME) {
44369
+ if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
44311
44370
  return { error: INVALID_STRUCTURE };
44312
44371
  }
44313
44372
  if (roundNumber && roundNumber - 1 > (lastRoundNumber || 0))
44314
44373
  return { error: INVALID_VALUES, info: "roundNumber error" };
44315
- const nextRoundNumber = roundNumber ?? (newRound ? (lastRoundNumber ?? 0) + 1 : lastRoundNumber ?? 1);
44374
+ const nextRoundNumber = roundNumber ?? (newRound && (lastRoundNumber ?? 0) + 1 || lastRoundNumber || 1);
44316
44375
  participantIdPairings = participantIdPairings ?? generateRange(0, matchUpsCount).map(() => ({
44317
44376
  participantIds: [void 0, void 0]
44318
44377
  }));
@@ -57939,6 +57998,7 @@ const eventGovernor = {
57939
57998
  renameStructures,
57940
57999
  disableTieAutoCalc,
57941
58000
  enableTieAutoCalc,
58001
+ validateCollectionDefinition,
57942
58002
  modifyCollectionDefinition: modifyCollectionDefinition$1,
57943
58003
  orderCollectionDefinitions: orderCollectionDefinitions$1,
57944
58004
  removeCollectionDefinition: removeCollectionDefinition$1,