tods-competition-factory 1.7.1 → 1.7.2

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.2";
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) {
@@ -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
@@ -30333,8 +30335,10 @@ function addCollectionDefinition$1({
30333
30335
  updateInProgressMatchUps = true,
30334
30336
  collectionDefinition,
30335
30337
  tournamentRecord,
30338
+ referenceGender,
30336
30339
  drawDefinition,
30337
30340
  tieFormatName,
30341
+ enforceGender,
30338
30342
  structureId,
30339
30343
  matchUpId,
30340
30344
  matchUp,
@@ -30342,8 +30346,18 @@ function addCollectionDefinition$1({
30342
30346
  uuids,
30343
30347
  event
30344
30348
  }) {
30349
+ const appliedPolicies = getAppliedPolicies({
30350
+ tournamentRecord,
30351
+ drawDefinition,
30352
+ event
30353
+ }).appliedPolicies ?? {};
30354
+ enforceGender = enforceGender ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS]?.participants?.enforceGender;
30355
+ const checkGender = !!(enforceGender !== false && event?.gender);
30345
30356
  const { valid, errors } = validateCollectionDefinition({
30346
- collectionDefinition
30357
+ collectionDefinition,
30358
+ referenceGender,
30359
+ checkGender,
30360
+ event
30347
30361
  });
30348
30362
  if (!valid)
30349
30363
  return { error: INVALID_VALUES, errors };
@@ -30358,7 +30372,7 @@ function addCollectionDefinition$1({
30358
30372
  if (result?.error)
30359
30373
  return { error: result.error };
30360
30374
  const structure = result?.structure;
30361
- matchUp = matchUp || result?.matchUp;
30375
+ matchUp = matchUp ?? result?.matchUp;
30362
30376
  const existingTieFormat = result?.tieFormat;
30363
30377
  const tieFormat = copyTieFormat(existingTieFormat);
30364
30378
  result = validateTieFormat({ tieFormat });
@@ -30398,12 +30412,12 @@ function addCollectionDefinition$1({
30398
30412
  result = validateTieFormat({ tieFormat: prunedTieFormat });
30399
30413
  if (result?.error)
30400
30414
  return { error: result.error };
30401
- if (eventId) {
30415
+ if (eventId && event) {
30402
30416
  event.tieFormat = prunedTieFormat;
30403
- for (const drawDefinition2 of event.drawDefinitions || []) {
30417
+ for (const drawDefinition2 of event.drawDefinitions ?? []) {
30404
30418
  if (drawDefinition2.tieFormat)
30405
30419
  continue;
30406
- for (const structure2 of drawDefinition2.structures || []) {
30420
+ for (const structure2 of drawDefinition2.structures ?? []) {
30407
30421
  if (structure2.tieFormat)
30408
30422
  continue;
30409
30423
  const result2 = updateStructureMatchUps({
@@ -30468,7 +30482,7 @@ function addCollectionDefinition$1({
30468
30482
  });
30469
30483
  } else if (drawDefinition) {
30470
30484
  drawDefinition.tieFormat = prunedTieFormat;
30471
- for (const structure2 of drawDefinition.structures || []) {
30485
+ for (const structure2 of drawDefinition.structures ?? []) {
30472
30486
  const result2 = updateStructureMatchUps({
30473
30487
  updateInProgressMatchUps,
30474
30488
  collectionDefinition,
@@ -30490,7 +30504,6 @@ function addCollectionDefinition$1({
30490
30504
  } else {
30491
30505
  return { error: MISSING_DRAW_DEFINITION };
30492
30506
  }
30493
- const { appliedPolicies } = getAppliedPolicies({ tournamentRecord });
30494
30507
  if (appliedPolicies?.audit?.[TIE_FORMAT_MODIFICATIONS]) {
30495
30508
  const auditData = definedAttributes({
30496
30509
  drawId: drawDefinition?.drawId,
@@ -44091,9 +44104,12 @@ function deleteAdHocMatchUps$1({
44091
44104
  if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
44092
44105
  return { error: INVALID_STRUCTURE };
44093
44106
  }
44094
- const matchUpsToDelete = existingMatchUps?.filter(
44095
- ({ matchUpId }) => matchUpIds.includes(matchUpId)
44096
- ) ?? [];
44107
+ const matchUpIdsWithScoreValue = [];
44108
+ const matchUpsToDelete = existingMatchUps?.filter(({ matchUpId, score }) => {
44109
+ if (scoreHasValue({ score }))
44110
+ matchUpIdsWithScoreValue.push(matchUpId);
44111
+ return matchUpIds.includes(matchUpId);
44112
+ }) ?? [];
44097
44113
  const matchUpIdsToDelete = matchUpsToDelete.map(
44098
44114
  extractAttributes("matchUpId")
44099
44115
  );
@@ -44113,15 +44129,40 @@ function deleteAdHocMatchUps$1({
44113
44129
  );
44114
44130
  const missingRoundNumbers = getMissingSequenceNumbers(roundNumbers);
44115
44131
  if (missingRoundNumbers.length) {
44116
- const roundNumbersToConsider = missingRoundNumbers.reverse();
44117
- for (const roundNumber of roundNumbersToConsider) {
44132
+ missingRoundNumbers.reverse();
44133
+ for (const roundNumber of missingRoundNumbers) {
44118
44134
  structure.matchUps.forEach((matchUp) => {
44119
44135
  if (matchUp.roundNumber && matchUp.roundNumber > roundNumber) {
44120
44136
  matchUp.roundNumber -= 1;
44137
+ modifyMatchUpNotice({
44138
+ tournamentId: tournamentRecord?.tournamentId,
44139
+ context: ["adHoc round deletion"],
44140
+ eventId: event?.eventId,
44141
+ drawDefinition,
44142
+ matchUp
44143
+ });
44121
44144
  }
44122
44145
  });
44123
44146
  }
44124
44147
  }
44148
+ if (matchUpIdsWithScoreValue.length) {
44149
+ structure.positionAssignments = unique(
44150
+ structure.matchUps.flatMap(
44151
+ (matchUp) => (matchUp.sides ?? []).map((side) => side.participantId)
44152
+ ).filter(Boolean)
44153
+ ).map((participantId) => ({ participantId }));
44154
+ const matchUpFormat = structure?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
44155
+ const result = updateAssignmentParticipantResults({
44156
+ positionAssignments: structure.positionAssignments,
44157
+ matchUps: structure.matchUps,
44158
+ tournamentRecord,
44159
+ drawDefinition,
44160
+ matchUpFormat,
44161
+ event
44162
+ });
44163
+ if (result.error)
44164
+ console.log(result);
44165
+ }
44125
44166
  modifyDrawNotice({
44126
44167
  structureIds: [structureId],
44127
44168
  eventId: event?.eventId,
@@ -44291,6 +44332,13 @@ function generateAdHocMatchUps$1({
44291
44332
  structureId = drawDefinition.structures?.[0]?.structureId;
44292
44333
  if (typeof structureId !== "string")
44293
44334
  return { error: MISSING_STRUCTURE_ID };
44335
+ if (newRound && !matchUpsCount) {
44336
+ const selectedEntries = drawDefinition?.entries?.filter((entry) => {
44337
+ const entryStatus = entry.entryStatus;
44338
+ return STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
44339
+ }) ?? [];
44340
+ matchUpsCount = Math.floor(selectedEntries?.length / 2) || 1;
44341
+ }
44294
44342
  if (participantIdPairings && !Array.isArray(participantIdPairings) || matchUpsCount && !isConvertableInteger(matchUpsCount) || matchUpIds && !Array.isArray(matchUpIds) || !participantIdPairings && !matchUpsCount) {
44295
44343
  return { error: INVALID_VALUES, info: "matchUpsCount or pairings error" };
44296
44344
  }
@@ -57939,6 +57987,7 @@ const eventGovernor = {
57939
57987
  renameStructures,
57940
57988
  disableTieAutoCalc,
57941
57989
  enableTieAutoCalc,
57990
+ validateCollectionDefinition,
57942
57991
  modifyCollectionDefinition: modifyCollectionDefinition$1,
57943
57992
  orderCollectionDefinitions: orderCollectionDefinitions$1,
57944
57993
  removeCollectionDefinition: removeCollectionDefinition$1,