tods-competition-factory 1.7.0 → 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
@@ -308,11 +308,15 @@ function isValid(matchUpFormat) {
308
308
  if (typeof matchUpFormat !== "string")
309
309
  return false;
310
310
  const parsedFormat = parse(matchUpFormat);
311
- const setParts = matchUpFormat.match(/-S:(\d+)+\/TB(\d+)@?(\d*)*/);
311
+ const setParts = matchUpFormat.match(
312
+ /-S:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/
313
+ );
312
314
  const setsTo = setParts?.[1];
313
315
  const tiebreakTo = setParts?.[2];
314
316
  const tiebreakAt = setParts?.[3];
315
- const finalSetParts = matchUpFormat.match(/-F:(\d+)+\/TB(\d+)@?(\d*)*/);
317
+ const finalSetParts = matchUpFormat.match(
318
+ /-F:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/
319
+ );
316
320
  const finalSetTo = finalSetParts?.[1];
317
321
  const finalSetTiebreakTo = finalSetParts?.[2];
318
322
  const finalTiebreakAt = finalSetParts?.[3];
@@ -329,7 +333,7 @@ const matchUpFormatCode = {
329
333
  };
330
334
 
331
335
  function factoryVersion() {
332
- return "1.7.0";
336
+ return "1.7.2";
333
337
  }
334
338
 
335
339
  function getObjectTieFormat(obj) {
@@ -2574,15 +2578,17 @@ function validateTieFormat(params) {
2574
2578
  function validateCollectionDefinition({
2575
2579
  collectionDefinition,
2576
2580
  checkCollectionIds,
2581
+ checkGender = true,
2577
2582
  referenceGender,
2578
- checkGender
2583
+ event
2579
2584
  }) {
2585
+ referenceGender = referenceGender ?? event?.gender;
2580
2586
  const errors = [];
2581
2587
  if (typeof collectionDefinition !== "object") {
2582
2588
  errors.push(
2583
2589
  `collectionDefinition must be an object: ${collectionDefinition}`
2584
2590
  );
2585
- return { errors };
2591
+ return { errors, error: INVALID_OBJECT };
2586
2592
  }
2587
2593
  const {
2588
2594
  collectionValueProfiles,
@@ -2641,7 +2647,7 @@ function validateCollectionDefinition({
2641
2647
  errors.push(`Invalid gender: ${gender}`);
2642
2648
  }
2643
2649
  if (errors.length)
2644
- return { errors };
2650
+ return { errors, error: INVALID_OBJECT };
2645
2651
  return { valid: true };
2646
2652
  }
2647
2653
  function checkTieFormat(tieFormat) {
@@ -21756,7 +21762,7 @@ function assignMatchUpDrawPosition({
21756
21762
  inContext: true,
21757
21763
  drawDefinition,
21758
21764
  matchUpsMap
21759
- }).matchUps || [];
21765
+ }).matchUps ?? [];
21760
21766
  }
21761
21767
  const inContextMatchUp = inContextDrawMatchUps.find(
21762
21768
  (m) => m.matchUpId === matchUpId
@@ -21770,7 +21776,7 @@ function assignMatchUpDrawPosition({
21770
21776
  const matchUp = matchUpsMap?.drawMatchUps?.find(
21771
21777
  (matchUp2) => matchUp2.matchUpId === matchUpId
21772
21778
  );
21773
- const drawPositions = matchUp?.drawPositions || [];
21779
+ const drawPositions = matchUp?.drawPositions ?? [];
21774
21780
  const { positionAdded, positionAssigned, updatedDrawPositions } = getUpdatedDrawPositions({ drawPosition, drawPositions });
21775
21781
  const { positionAssignments } = getPositionAssignments$1({
21776
21782
  drawDefinition,
@@ -21787,7 +21793,7 @@ function assignMatchUpDrawPosition({
21787
21793
  inContext: true,
21788
21794
  drawDefinition,
21789
21795
  matchUpsMap
21790
- }).matchUps || [];
21796
+ }).matchUps ?? [];
21791
21797
  const exitWinningSide = isDoubleExitExit && getExitWinningSide({
21792
21798
  inContextDrawMatchUps,
21793
21799
  drawPosition,
@@ -21875,7 +21881,7 @@ function assignMatchUpDrawPosition({
21875
21881
  const inContextTargetMatchUp = inContextDrawMatchUps?.find(
21876
21882
  ({ matchUpId: matchUpId2 }) => matchUpId2 === matchUp.matchUpId
21877
21883
  );
21878
- const sides = inContextTargetMatchUp?.sides || [];
21884
+ const sides = inContextTargetMatchUp?.sides ?? [];
21879
21885
  const drawPositionSideIndex = sides.reduce(
21880
21886
  (index, side, i) => side.drawPosition === drawPosition ? i : index,
21881
21887
  void 0
@@ -30329,8 +30335,10 @@ function addCollectionDefinition$1({
30329
30335
  updateInProgressMatchUps = true,
30330
30336
  collectionDefinition,
30331
30337
  tournamentRecord,
30338
+ referenceGender,
30332
30339
  drawDefinition,
30333
30340
  tieFormatName,
30341
+ enforceGender,
30334
30342
  structureId,
30335
30343
  matchUpId,
30336
30344
  matchUp,
@@ -30338,8 +30346,18 @@ function addCollectionDefinition$1({
30338
30346
  uuids,
30339
30347
  event
30340
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);
30341
30356
  const { valid, errors } = validateCollectionDefinition({
30342
- collectionDefinition
30357
+ collectionDefinition,
30358
+ referenceGender,
30359
+ checkGender,
30360
+ event
30343
30361
  });
30344
30362
  if (!valid)
30345
30363
  return { error: INVALID_VALUES, errors };
@@ -30354,7 +30372,7 @@ function addCollectionDefinition$1({
30354
30372
  if (result?.error)
30355
30373
  return { error: result.error };
30356
30374
  const structure = result?.structure;
30357
- matchUp = matchUp || result?.matchUp;
30375
+ matchUp = matchUp ?? result?.matchUp;
30358
30376
  const existingTieFormat = result?.tieFormat;
30359
30377
  const tieFormat = copyTieFormat(existingTieFormat);
30360
30378
  result = validateTieFormat({ tieFormat });
@@ -30394,12 +30412,12 @@ function addCollectionDefinition$1({
30394
30412
  result = validateTieFormat({ tieFormat: prunedTieFormat });
30395
30413
  if (result?.error)
30396
30414
  return { error: result.error };
30397
- if (eventId) {
30415
+ if (eventId && event) {
30398
30416
  event.tieFormat = prunedTieFormat;
30399
- for (const drawDefinition2 of event.drawDefinitions || []) {
30417
+ for (const drawDefinition2 of event.drawDefinitions ?? []) {
30400
30418
  if (drawDefinition2.tieFormat)
30401
30419
  continue;
30402
- for (const structure2 of drawDefinition2.structures || []) {
30420
+ for (const structure2 of drawDefinition2.structures ?? []) {
30403
30421
  if (structure2.tieFormat)
30404
30422
  continue;
30405
30423
  const result2 = updateStructureMatchUps({
@@ -30464,7 +30482,7 @@ function addCollectionDefinition$1({
30464
30482
  });
30465
30483
  } else if (drawDefinition) {
30466
30484
  drawDefinition.tieFormat = prunedTieFormat;
30467
- for (const structure2 of drawDefinition.structures || []) {
30485
+ for (const structure2 of drawDefinition.structures ?? []) {
30468
30486
  const result2 = updateStructureMatchUps({
30469
30487
  updateInProgressMatchUps,
30470
30488
  collectionDefinition,
@@ -30486,7 +30504,6 @@ function addCollectionDefinition$1({
30486
30504
  } else {
30487
30505
  return { error: MISSING_DRAW_DEFINITION };
30488
30506
  }
30489
- const { appliedPolicies } = getAppliedPolicies({ tournamentRecord });
30490
30507
  if (appliedPolicies?.audit?.[TIE_FORMAT_MODIFICATIONS]) {
30491
30508
  const auditData = definedAttributes({
30492
30509
  drawId: drawDefinition?.drawId,
@@ -44087,9 +44104,12 @@ function deleteAdHocMatchUps$1({
44087
44104
  if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
44088
44105
  return { error: INVALID_STRUCTURE };
44089
44106
  }
44090
- const matchUpsToDelete = existingMatchUps?.filter(
44091
- ({ matchUpId }) => matchUpIds.includes(matchUpId)
44092
- ) ?? [];
44107
+ const matchUpIdsWithScoreValue = [];
44108
+ const matchUpsToDelete = existingMatchUps?.filter(({ matchUpId, score }) => {
44109
+ if (scoreHasValue({ score }))
44110
+ matchUpIdsWithScoreValue.push(matchUpId);
44111
+ return matchUpIds.includes(matchUpId);
44112
+ }) ?? [];
44093
44113
  const matchUpIdsToDelete = matchUpsToDelete.map(
44094
44114
  extractAttributes("matchUpId")
44095
44115
  );
@@ -44109,15 +44129,40 @@ function deleteAdHocMatchUps$1({
44109
44129
  );
44110
44130
  const missingRoundNumbers = getMissingSequenceNumbers(roundNumbers);
44111
44131
  if (missingRoundNumbers.length) {
44112
- const roundNumbersToConsider = missingRoundNumbers.reverse();
44113
- for (const roundNumber of roundNumbersToConsider) {
44132
+ missingRoundNumbers.reverse();
44133
+ for (const roundNumber of missingRoundNumbers) {
44114
44134
  structure.matchUps.forEach((matchUp) => {
44115
44135
  if (matchUp.roundNumber && matchUp.roundNumber > roundNumber) {
44116
44136
  matchUp.roundNumber -= 1;
44137
+ modifyMatchUpNotice({
44138
+ tournamentId: tournamentRecord?.tournamentId,
44139
+ context: ["adHoc round deletion"],
44140
+ eventId: event?.eventId,
44141
+ drawDefinition,
44142
+ matchUp
44143
+ });
44117
44144
  }
44118
44145
  });
44119
44146
  }
44120
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
+ }
44121
44166
  modifyDrawNotice({
44122
44167
  structureIds: [structureId],
44123
44168
  eventId: event?.eventId,
@@ -44287,6 +44332,13 @@ function generateAdHocMatchUps$1({
44287
44332
  structureId = drawDefinition.structures?.[0]?.structureId;
44288
44333
  if (typeof structureId !== "string")
44289
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
+ }
44290
44342
  if (participantIdPairings && !Array.isArray(participantIdPairings) || matchUpsCount && !isConvertableInteger(matchUpsCount) || matchUpIds && !Array.isArray(matchUpIds) || !participantIdPairings && !matchUpsCount) {
44291
44343
  return { error: INVALID_VALUES, info: "matchUpsCount or pairings error" };
44292
44344
  }
@@ -57935,6 +57987,7 @@ const eventGovernor = {
57935
57987
  renameStructures,
57936
57988
  disableTieAutoCalc,
57937
57989
  enableTieAutoCalc,
57990
+ validateCollectionDefinition,
57938
57991
  modifyCollectionDefinition: modifyCollectionDefinition$1,
57939
57992
  orderCollectionDefinitions: orderCollectionDefinitions$1,
57940
57993
  removeCollectionDefinition: removeCollectionDefinition$1,
@@ -60522,7 +60575,7 @@ function anonymizeTournamentRecord({
60522
60575
  idMap[tournamentRecord.tournamentId] = newTournamentId;
60523
60576
  tournamentRecord.tournamentId = newTournamentId;
60524
60577
  tournamentRecord.createdAt = (/* @__PURE__ */ new Date()).toISOString();
60525
- tournamentRecord.tournamentName = tournamentName || `Anonymized: ${formatDate( new Date())}`;
60578
+ tournamentRecord.tournamentName = tournamentName || `Anonymized: ${formatDate(/* @__PURE__ */ new Date())}`;
60526
60579
  delete tournamentRecord.parentOrganisation;
60527
60580
  for (const participant of tournamentRecord.participants || []) {
60528
60581
  const newParticipantId = UUID();