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.
@@ -362,7 +362,7 @@ var matchUpFormatCode = {
362
362
  };
363
363
 
364
364
  function factoryVersion() {
365
- return '1.7.1';
365
+ return '1.7.3';
366
366
  }
367
367
 
368
368
  /******************************************************************************
@@ -3533,11 +3533,12 @@ function validateTieFormat(params) {
3533
3533
  return result;
3534
3534
  }
3535
3535
  function validateCollectionDefinition(_a) {
3536
- var collectionDefinition = _a.collectionDefinition, checkCollectionIds = _a.checkCollectionIds, referenceGender = _a.referenceGender, checkGender = _a.checkGender;
3536
+ var collectionDefinition = _a.collectionDefinition, checkCollectionIds = _a.checkCollectionIds, _b = _a.checkGender, checkGender = _b === void 0 ? true : _b, referenceGender = _a.referenceGender, event = _a.event;
3537
+ referenceGender = referenceGender !== null && referenceGender !== void 0 ? referenceGender : event === null || event === void 0 ? void 0 : event.gender;
3537
3538
  var errors = [];
3538
3539
  if (typeof collectionDefinition !== 'object') {
3539
3540
  errors.push("collectionDefinition must be an object: ".concat(collectionDefinition));
3540
- return { errors: errors };
3541
+ return { errors: errors, error: INVALID_OBJECT };
3541
3542
  }
3542
3543
  var collectionValueProfiles = collectionDefinition.collectionValueProfiles, collectionGroupNumber = collectionDefinition.collectionGroupNumber, collectionValue = collectionDefinition.collectionValue, collectionId = collectionDefinition.collectionId, matchUpCount = collectionDefinition.matchUpCount, matchUpFormat = collectionDefinition.matchUpFormat, matchUpValue = collectionDefinition.matchUpValue, matchUpType = collectionDefinition.matchUpType, scoreValue = collectionDefinition.scoreValue, setValue = collectionDefinition.setValue, gender = collectionDefinition.gender;
3543
3544
  if (checkCollectionIds && typeof collectionId !== 'string') {
@@ -3585,7 +3586,7 @@ function validateCollectionDefinition(_a) {
3585
3586
  errors.push("Invalid gender: ".concat(gender));
3586
3587
  }
3587
3588
  if (errors.length)
3588
- return { errors: errors };
3589
+ return { errors: errors, error: INVALID_OBJECT };
3589
3590
  return { valid: true };
3590
3591
  }
3591
3592
  // add collectionIds if missing
@@ -7408,7 +7409,7 @@ function getRoundMatchUps$1(_a) {
7408
7409
  .map(function (key) { return ensureInt(key); })
7409
7410
  .filter(function (f) { return !isNaN(f); });
7410
7411
  roundNumbers.forEach(function (roundNumber) {
7411
- var _a, _b, _c;
7412
+ var _a, _b, _c, _d, _e;
7412
7413
  var currentRoundMatchUps = roundMatchUps[roundNumber].sort(function (a, b) { return a.roundPosition - b.roundPosition; });
7413
7414
  var currentRoundDrawPositions = currentRoundMatchUps
7414
7415
  .map(function (matchUp) { return (matchUp === null || matchUp === void 0 ? void 0 : matchUp.drawPositions) || []; })
@@ -7426,7 +7427,7 @@ function getRoundMatchUps$1(_a) {
7426
7427
  roundProfile[roundNumber].abbreviatedRoundName =
7427
7428
  (_c = finishingRoundMap[roundNumber]) === null || _c === void 0 ? void 0 : _c.abbreviatedRoundName;
7428
7429
  roundProfile[roundNumber].finishingPositionRange =
7429
- roundMatchUps[roundNumber][0].finishingPositionRange;
7430
+ (_e = (_d = roundMatchUps[roundNumber]) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.finishingPositionRange;
7430
7431
  if (roundNumber === 1 || !roundProfile[roundNumber - 1]) {
7431
7432
  var orderedDrawPositions = currentRoundDrawPositions.sort(numericSort);
7432
7433
  var pairedDrawPositions = chunkArray(orderedDrawPositions, 2);
@@ -23782,7 +23783,7 @@ function getExitWinningSide(_a) {
23782
23783
  }
23783
23784
 
23784
23785
  function assignMatchUpDrawPosition(_a) {
23785
- var _b, _c, _d;
23786
+ var _b, _c, _d, _e, _f, _g, _h;
23786
23787
  var inContextDrawMatchUps = _a.inContextDrawMatchUps, sourceMatchUpStatus = _a.sourceMatchUpStatus, tournamentRecord = _a.tournamentRecord, sourceMatchUpId = _a.sourceMatchUpId, drawDefinition = _a.drawDefinition, matchUpStatus = _a.matchUpStatus, drawPosition = _a.drawPosition, matchUpsMap = _a.matchUpsMap, matchUpId = _a.matchUpId, event = _a.event;
23787
23788
  var stack = 'assignMatchUpDrawPosition';
23788
23789
  if (!matchUpsMap) {
@@ -23790,20 +23791,20 @@ function assignMatchUpDrawPosition(_a) {
23790
23791
  }
23791
23792
  if (!inContextDrawMatchUps) {
23792
23793
  inContextDrawMatchUps =
23793
- getAllDrawMatchUps({
23794
+ (_b = getAllDrawMatchUps({
23794
23795
  inContext: true,
23795
23796
  drawDefinition: drawDefinition,
23796
23797
  matchUpsMap: matchUpsMap,
23797
- }).matchUps || [];
23798
+ }).matchUps) !== null && _b !== void 0 ? _b : [];
23798
23799
  }
23799
23800
  var inContextMatchUp = inContextDrawMatchUps.find(function (m) { return m.matchUpId === matchUpId; });
23800
23801
  var structureId = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.structureId;
23801
- var structure = (_b = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) === null || _b === void 0 ? void 0 : _b.find(function (structure) { return structure.structureId === structureId; });
23802
+ var structure = (_c = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) === null || _c === void 0 ? void 0 : _c.find(function (structure) { return structure.structureId === structureId; });
23802
23803
  if (!structure)
23803
23804
  return { error: STRUCTURE_NOT_FOUND };
23804
- var matchUp = (_c = matchUpsMap === null || matchUpsMap === void 0 ? void 0 : matchUpsMap.drawMatchUps) === null || _c === void 0 ? void 0 : _c.find(function (matchUp) { return matchUp.matchUpId === matchUpId; });
23805
- var drawPositions = (matchUp === null || matchUp === void 0 ? void 0 : matchUp.drawPositions) || [];
23806
- var _e = getUpdatedDrawPositions({ drawPosition: drawPosition, drawPositions: drawPositions }), positionAdded = _e.positionAdded, positionAssigned = _e.positionAssigned, updatedDrawPositions = _e.updatedDrawPositions;
23805
+ var matchUp = (_d = matchUpsMap === null || matchUpsMap === void 0 ? void 0 : matchUpsMap.drawMatchUps) === null || _d === void 0 ? void 0 : _d.find(function (matchUp) { return matchUp.matchUpId === matchUpId; });
23806
+ var drawPositions = (_e = matchUp === null || matchUp === void 0 ? void 0 : matchUp.drawPositions) !== null && _e !== void 0 ? _e : [];
23807
+ var _j = getUpdatedDrawPositions({ drawPosition: drawPosition, drawPositions: drawPositions }), positionAdded = _j.positionAdded, positionAssigned = _j.positionAssigned, updatedDrawPositions = _j.updatedDrawPositions;
23807
23808
  var positionAssignments = getPositionAssignments$1({
23808
23809
  drawDefinition: drawDefinition,
23809
23810
  structure: structure,
@@ -23829,11 +23830,11 @@ function assignMatchUpDrawPosition(_a) {
23829
23830
  if (matchUp && positionAdded) {
23830
23831
  // necessary to update inContextDrawMatchUps
23831
23832
  inContextDrawMatchUps =
23832
- getAllDrawMatchUps({
23833
+ (_f = getAllDrawMatchUps({
23833
23834
  inContext: true,
23834
23835
  drawDefinition: drawDefinition,
23835
23836
  matchUpsMap: matchUpsMap,
23836
- }).matchUps || [];
23837
+ }).matchUps) !== null && _f !== void 0 ? _f : [];
23837
23838
  var exitWinningSide = (isDoubleExitExit &&
23838
23839
  getExitWinningSide({
23839
23840
  inContextDrawMatchUps: inContextDrawMatchUps,
@@ -23870,7 +23871,7 @@ function assignMatchUpDrawPosition(_a) {
23870
23871
  drawDefinition: drawDefinition,
23871
23872
  matchUpId: matchUpId,
23872
23873
  });
23873
- var _f = targetData.targetMatchUps, winnerMatchUp = _f.winnerMatchUp, loserMatchUp = _f.loserMatchUp, loserTargetDrawPosition = _f.loserTargetDrawPosition, loserTargetLink = targetData.targetLinks.loserTargetLink;
23874
+ var _k = targetData.targetMatchUps, winnerMatchUp = _k.winnerMatchUp, loserMatchUp = _k.loserMatchUp, loserTargetDrawPosition = _k.loserTargetDrawPosition, loserTargetLink = targetData.targetLinks.loserTargetLink;
23874
23875
  var structureMatchUps = getMappedStructureMatchUps({
23875
23876
  structureId: structure.structureId,
23876
23877
  matchUpsMap: matchUpsMap,
@@ -23923,9 +23924,9 @@ function assignMatchUpDrawPosition(_a) {
23923
23924
  var matchUpId = _a.matchUpId;
23924
23925
  return matchUpId === matchUp.matchUpId;
23925
23926
  });
23926
- var sides = (inContextTargetMatchUp === null || inContextTargetMatchUp === void 0 ? void 0 : inContextTargetMatchUp.sides) || [];
23927
+ var sides = (_g = inContextTargetMatchUp === null || inContextTargetMatchUp === void 0 ? void 0 : inContextTargetMatchUp.sides) !== null && _g !== void 0 ? _g : [];
23927
23928
  var drawPositionSideIndex = sides.reduce(function (index, side, i) { return (side.drawPosition === drawPosition ? i : index); }, undefined);
23928
- var teamParticipantId = (_d = positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.find(function (assignment) { return assignment.drawPosition === drawPosition; })) === null || _d === void 0 ? void 0 : _d.participantId;
23929
+ var teamParticipantId = (_h = positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.find(function (assignment) { return assignment.drawPosition === drawPosition; })) === null || _h === void 0 ? void 0 : _h.participantId;
23929
23930
  if (teamParticipantId && drawPositionSideIndex !== undefined) {
23930
23931
  updateSideLineUp({
23931
23932
  inContextTargetMatchUp: inContextTargetMatchUp,
@@ -31249,10 +31250,12 @@ function getParticipantEntries(params) {
31249
31250
  if (!participation)
31250
31251
  return;
31251
31252
  if (!finishingPositionRange_1)
31252
- finishingPositionRange_1 = participation.finishingPositionRange;
31253
+ finishingPositionRange_1 =
31254
+ participation === null || participation === void 0 ? void 0 : participation.finishingPositionRange;
31253
31255
  if (diff_1(finishingPositionRange_1) >
31254
- diff_1(participation.finishingPositionRange))
31255
- finishingPositionRange_1 = participation.finishingPositionRange;
31256
+ diff_1(participation === null || participation === void 0 ? void 0 : participation.finishingPositionRange))
31257
+ finishingPositionRange_1 =
31258
+ participation === null || participation === void 0 ? void 0 : participation.finishingPositionRange;
31256
31259
  var notQualifying = participation.stage !== QUALIFYING;
31257
31260
  if (notQualifying)
31258
31261
  nonQualifyingOrder_1 += 1;
@@ -31262,10 +31265,12 @@ function getParticipantEntries(params) {
31262
31265
  return definedAttributes(__assign(__assign({}, participation), { participationOrder: participationOrder, flightNumber: flightNumber }));
31263
31266
  })
31264
31267
  .filter(Boolean);
31265
- participantAggregator.draws[drawId].finishingPositionRange =
31266
- finishingPositionRange_1;
31267
- participantAggregator.draws[drawId].structureParticipation =
31268
- orderedParticipation;
31268
+ if (participantAggregator.draws[drawId]) {
31269
+ participantAggregator.draws[drawId].finishingPositionRange =
31270
+ finishingPositionRange_1;
31271
+ participantAggregator.draws[drawId].structureParticipation =
31272
+ orderedParticipation;
31273
+ }
31269
31274
  }
31270
31275
  };
31271
31276
  try {
@@ -32852,19 +32857,24 @@ function generateCollectionMatchUps(_a) {
32852
32857
  });
32853
32858
  }
32854
32859
 
32855
- /*
32856
- * collectionDefinition will be added to an event tieFormat (if present)
32857
- * if a matchUpId is provided, will be added to matchUp.tieFormat
32858
- * if a structureId is provided, will be added to structure.tieFormat
32859
- * TODO: determine whether all contained instances of tieFormat should be updated
32860
- */
32861
32860
  function addCollectionDefinition$1(_a) {
32862
32861
  var e_1, _b, e_2, _c, _d, e_3, _e;
32863
- var _f;
32864
- var _g = _a.updateInProgressMatchUps, updateInProgressMatchUps = _g === void 0 ? true : _g, collectionDefinition = _a.collectionDefinition, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, tieFormatName = _a.tieFormatName, structureId = _a.structureId, matchUpId = _a.matchUpId, matchUp = _a.matchUp, eventId = _a.eventId, uuids = _a.uuids, event = _a.event;
32865
- var _h = validateCollectionDefinition({
32862
+ var _f, _g, _h, _j, _k, _l, _m;
32863
+ var _o = _a.updateInProgressMatchUps, updateInProgressMatchUps = _o === void 0 ? true : _o, collectionDefinition = _a.collectionDefinition, tournamentRecord = _a.tournamentRecord, referenceGender = _a.referenceGender, drawDefinition = _a.drawDefinition, tieFormatName = _a.tieFormatName, enforceGender = _a.enforceGender, structureId = _a.structureId, matchUpId = _a.matchUpId, matchUp = _a.matchUp, eventId = _a.eventId, uuids = _a.uuids, event = _a.event;
32864
+ var appliedPolicies = (_f = getAppliedPolicies({
32865
+ tournamentRecord: tournamentRecord,
32866
+ drawDefinition: drawDefinition,
32867
+ event: event,
32868
+ }).appliedPolicies) !== null && _f !== void 0 ? _f : {};
32869
+ enforceGender =
32870
+ enforceGender !== null && enforceGender !== void 0 ? enforceGender : (_h = (_g = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_MATCHUP_ACTIONS]) === null || _g === void 0 ? void 0 : _g.participants) === null || _h === void 0 ? void 0 : _h.enforceGender;
32871
+ var checkGender = !!(enforceGender !== false && (event === null || event === void 0 ? void 0 : event.gender));
32872
+ var _p = validateCollectionDefinition({
32866
32873
  collectionDefinition: collectionDefinition,
32867
- }), valid = _h.valid, errors = _h.errors;
32874
+ referenceGender: referenceGender,
32875
+ checkGender: checkGender,
32876
+ event: event,
32877
+ }), valid = _p.valid, errors = _p.errors;
32868
32878
  if (!valid)
32869
32879
  return { error: INVALID_VALUES, errors: errors };
32870
32880
  var stack = 'addCollectionDefinition';
@@ -32880,7 +32890,7 @@ function addCollectionDefinition$1(_a) {
32880
32890
  if (result === null || result === void 0 ? void 0 : result.error)
32881
32891
  return { error: result.error };
32882
32892
  var structure = result === null || result === void 0 ? void 0 : result.structure;
32883
- matchUp = matchUp || (result === null || result === void 0 ? void 0 : result.matchUp);
32893
+ matchUp = matchUp !== null && matchUp !== void 0 ? matchUp : result === null || result === void 0 ? void 0 : result.matchUp;
32884
32894
  var existingTieFormat = result === null || result === void 0 ? void 0 : result.tieFormat;
32885
32895
  var tieFormat = copyTieFormat(existingTieFormat);
32886
32896
  result = validateTieFormat({ tieFormat: tieFormat });
@@ -32908,7 +32918,7 @@ function addCollectionDefinition$1(_a) {
32908
32918
  });
32909
32919
  // calculate new winCriteria for tieFormat
32910
32920
  // if existing winCriteria is aggregateValue, retain
32911
- var _j = calculateWinCriteria(tieFormat), aggregateValue = _j.aggregateValue, valueGoal = _j.valueGoal;
32921
+ var _q = calculateWinCriteria(tieFormat), aggregateValue = _q.aggregateValue, valueGoal = _q.valueGoal;
32912
32922
  tieFormat.winCriteria = definedAttributes({ aggregateValue: aggregateValue, valueGoal: valueGoal });
32913
32923
  // if valueGoal has changed, force renaming of the tieFormat
32914
32924
  var originalValueGoal = existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.winCriteria.valueGoal;
@@ -32929,17 +32939,17 @@ function addCollectionDefinition$1(_a) {
32929
32939
  result = validateTieFormat({ tieFormat: prunedTieFormat });
32930
32940
  if (result === null || result === void 0 ? void 0 : result.error)
32931
32941
  return { error: result.error };
32932
- if (eventId) {
32942
+ if (eventId && event) {
32933
32943
  event.tieFormat = prunedTieFormat;
32934
32944
  try {
32935
32945
  // all team matchUps in the event which do not have tieFormats and where draws/strucures do not have tieFormats should have matchUps added
32936
- for (var _k = __values(event.drawDefinitions || []), _l = _k.next(); !_l.done; _l = _k.next()) {
32937
- var drawDefinition_1 = _l.value;
32946
+ for (var _r = __values((_j = event.drawDefinitions) !== null && _j !== void 0 ? _j : []), _s = _r.next(); !_s.done; _s = _r.next()) {
32947
+ var drawDefinition_1 = _s.value;
32938
32948
  if (drawDefinition_1.tieFormat)
32939
32949
  continue;
32940
32950
  try {
32941
- for (var _m = (e_2 = void 0, __values(drawDefinition_1.structures || [])), _o = _m.next(); !_o.done; _o = _m.next()) {
32942
- var structure_1 = _o.value;
32951
+ for (var _t = (e_2 = void 0, __values((_k = drawDefinition_1.structures) !== null && _k !== void 0 ? _k : [])), _u = _t.next(); !_u.done; _u = _t.next()) {
32952
+ var structure_1 = _u.value;
32943
32953
  if (structure_1.tieFormat)
32944
32954
  continue;
32945
32955
  var result_1 = updateStructureMatchUps({
@@ -32956,7 +32966,7 @@ function addCollectionDefinition$1(_a) {
32956
32966
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
32957
32967
  finally {
32958
32968
  try {
32959
- if (_o && !_o.done && (_c = _m.return)) _c.call(_m);
32969
+ if (_u && !_u.done && (_c = _t.return)) _c.call(_t);
32960
32970
  }
32961
32971
  finally { if (e_2) throw e_2.error; }
32962
32972
  }
@@ -32965,7 +32975,7 @@ function addCollectionDefinition$1(_a) {
32965
32975
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
32966
32976
  finally {
32967
32977
  try {
32968
- if (_l && !_l.done && (_b = _k.return)) _b.call(_k);
32978
+ if (_s && !_s.done && (_b = _r.return)) _b.call(_r);
32969
32979
  }
32970
32980
  finally { if (e_1) throw e_1.error; }
32971
32981
  }
@@ -33025,8 +33035,8 @@ function addCollectionDefinition$1(_a) {
33025
33035
  // all team matchUps in the drawDefinition which do not have tieFormats and where strucures do not have tieFormats should have matchUps added
33026
33036
  drawDefinition.tieFormat = prunedTieFormat;
33027
33037
  try {
33028
- for (var _p = __values(drawDefinition.structures || []), _q = _p.next(); !_q.done; _q = _p.next()) {
33029
- var structure_2 = _q.value;
33038
+ for (var _v = __values((_l = drawDefinition.structures) !== null && _l !== void 0 ? _l : []), _w = _v.next(); !_w.done; _w = _v.next()) {
33039
+ var structure_2 = _w.value;
33030
33040
  var result_3 = updateStructureMatchUps({
33031
33041
  updateInProgressMatchUps: updateInProgressMatchUps,
33032
33042
  collectionDefinition: collectionDefinition,
@@ -33041,7 +33051,7 @@ function addCollectionDefinition$1(_a) {
33041
33051
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
33042
33052
  finally {
33043
33053
  try {
33044
- if (_q && !_q.done && (_e = _p.return)) _e.call(_p);
33054
+ if (_w && !_w.done && (_e = _v.return)) _e.call(_v);
33045
33055
  }
33046
33056
  finally { if (e_3) throw e_3.error; }
33047
33057
  }
@@ -33057,8 +33067,7 @@ function addCollectionDefinition$1(_a) {
33057
33067
  else {
33058
33068
  return { error: MISSING_DRAW_DEFINITION };
33059
33069
  }
33060
- var appliedPolicies = getAppliedPolicies({ tournamentRecord: tournamentRecord }).appliedPolicies;
33061
- if ((_f = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.audit) === null || _f === void 0 ? void 0 : _f[TIE_FORMAT_MODIFICATIONS]) {
33070
+ if ((_m = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.audit) === null || _m === void 0 ? void 0 : _m[TIE_FORMAT_MODIFICATIONS]) {
33062
33071
  var auditData = definedAttributes({
33063
33072
  drawId: drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.drawId,
33064
33073
  collectionDefinition: collectionDefinition,
@@ -47604,8 +47613,8 @@ function addPlayoffStructures$1(params) {
47604
47613
 
47605
47614
  function deleteAdHocMatchUps$1(_a) {
47606
47615
  var e_1, _b;
47607
- var _c, _d, _e;
47608
- var tournamentRecord = _a.tournamentRecord, _f = _a.matchUpIds, matchUpIds = _f === void 0 ? [] : _f, drawDefinition = _a.drawDefinition, structureId = _a.structureId, event = _a.event;
47616
+ var _c, _d, _e, _f, _g;
47617
+ var tournamentRecord = _a.tournamentRecord, _h = _a.matchUpIds, matchUpIds = _h === void 0 ? [] : _h, drawDefinition = _a.drawDefinition, structureId = _a.structureId, event = _a.event;
47609
47618
  if (typeof drawDefinition !== 'object')
47610
47619
  return { error: MISSING_DRAW_DEFINITION };
47611
47620
  if (typeof structureId !== 'string')
@@ -47622,8 +47631,11 @@ function deleteAdHocMatchUps$1(_a) {
47622
47631
  structure.finishingPosition === ROUND_OUTCOME) {
47623
47632
  return { error: INVALID_STRUCTURE };
47624
47633
  }
47634
+ var matchUpIdsWithScoreValue = [];
47625
47635
  var matchUpsToDelete = (_d = existingMatchUps === null || existingMatchUps === void 0 ? void 0 : existingMatchUps.filter(function (_a) {
47626
- var matchUpId = _a.matchUpId;
47636
+ var matchUpId = _a.matchUpId, score = _a.score;
47637
+ if (scoreHasValue({ score: score }))
47638
+ matchUpIdsWithScoreValue.push(matchUpId);
47627
47639
  return matchUpIds.includes(matchUpId);
47628
47640
  })) !== null && _d !== void 0 ? _d : [];
47629
47641
  var matchUpIdsToDelete = matchUpsToDelete.map(extractAttributes('matchUpId'));
@@ -47642,28 +47654,51 @@ function deleteAdHocMatchUps$1(_a) {
47642
47654
  var roundNumbers = unique(structure.matchUps.map(extractAttributes('roundNumber')));
47643
47655
  var missingRoundNumbers = getMissingSequenceNumbers(roundNumbers);
47644
47656
  if (missingRoundNumbers.length) {
47645
- var roundNumbersToConsider = missingRoundNumbers.reverse();
47657
+ missingRoundNumbers.reverse();
47646
47658
  var _loop_1 = function (roundNumber) {
47647
47659
  structure.matchUps.forEach(function (matchUp) {
47648
47660
  if (matchUp.roundNumber && matchUp.roundNumber > roundNumber) {
47649
47661
  matchUp.roundNumber -= 1;
47662
+ modifyMatchUpNotice({
47663
+ tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
47664
+ context: ['adHoc round deletion'],
47665
+ eventId: event === null || event === void 0 ? void 0 : event.eventId,
47666
+ drawDefinition: drawDefinition,
47667
+ matchUp: matchUp,
47668
+ });
47650
47669
  }
47651
47670
  });
47652
47671
  };
47653
47672
  try {
47654
- for (var roundNumbersToConsider_1 = __values(roundNumbersToConsider), roundNumbersToConsider_1_1 = roundNumbersToConsider_1.next(); !roundNumbersToConsider_1_1.done; roundNumbersToConsider_1_1 = roundNumbersToConsider_1.next()) {
47655
- var roundNumber = roundNumbersToConsider_1_1.value;
47673
+ for (var missingRoundNumbers_1 = __values(missingRoundNumbers), missingRoundNumbers_1_1 = missingRoundNumbers_1.next(); !missingRoundNumbers_1_1.done; missingRoundNumbers_1_1 = missingRoundNumbers_1.next()) {
47674
+ var roundNumber = missingRoundNumbers_1_1.value;
47656
47675
  _loop_1(roundNumber);
47657
47676
  }
47658
47677
  }
47659
47678
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
47660
47679
  finally {
47661
47680
  try {
47662
- if (roundNumbersToConsider_1_1 && !roundNumbersToConsider_1_1.done && (_b = roundNumbersToConsider_1.return)) _b.call(roundNumbersToConsider_1);
47681
+ if (missingRoundNumbers_1_1 && !missingRoundNumbers_1_1.done && (_b = missingRoundNumbers_1.return)) _b.call(missingRoundNumbers_1);
47663
47682
  }
47664
47683
  finally { if (e_1) throw e_1.error; }
47665
47684
  }
47666
47685
  }
47686
+ if (matchUpIdsWithScoreValue.length) {
47687
+ structure.positionAssignments = unique(structure.matchUps
47688
+ .flatMap(function (matchUp) { var _a; return ((_a = matchUp.sides) !== null && _a !== void 0 ? _a : []).map(function (side) { return side.participantId; }); })
47689
+ .filter(Boolean)).map(function (participantId) { return ({ participantId: participantId }); });
47690
+ var matchUpFormat = (_g = (_f = structure === null || structure === void 0 ? void 0 : structure.matchUpFormat) !== null && _f !== void 0 ? _f : drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.matchUpFormat) !== null && _g !== void 0 ? _g : event === null || event === void 0 ? void 0 : event.matchUpFormat;
47691
+ var result = updateAssignmentParticipantResults({
47692
+ positionAssignments: structure.positionAssignments,
47693
+ matchUps: structure.matchUps,
47694
+ tournamentRecord: tournamentRecord,
47695
+ drawDefinition: drawDefinition,
47696
+ matchUpFormat: matchUpFormat,
47697
+ event: event,
47698
+ });
47699
+ if (result.error)
47700
+ console.log(result);
47701
+ }
47667
47702
  modifyDrawNotice({
47668
47703
  structureIds: [structureId],
47669
47704
  eventId: event === null || event === void 0 ? void 0 : event.eventId,
@@ -47847,24 +47882,41 @@ function removeStructure(_a) {
47847
47882
  }
47848
47883
 
47849
47884
  function generateAdHocMatchUps$1(_a) {
47850
- var _b, _c, _d, _e;
47851
- var participantIdPairings = _a.participantIdPairings, _f = _a.addToStructure, addToStructure = _f === void 0 ? true : _f, tournamentRecord = _a.tournamentRecord, _g = _a.matchUpIds, matchUpIds = _g === void 0 ? [] : _g, drawDefinition = _a.drawDefinition, matchUpsCount = _a.matchUpsCount, roundNumber = _a.roundNumber, structureId = _a.structureId, newRound = _a.newRound;
47885
+ var _b, _c, _d, _e, _f, _g, _h, _j;
47886
+ var participantIdPairings = _a.participantIdPairings, _k = _a.addToStructure, addToStructure = _k === void 0 ? true : _k, tournamentRecord = _a.tournamentRecord, _l = _a.matchUpIds, matchUpIds = _l === void 0 ? [] : _l, drawDefinition = _a.drawDefinition, matchUpsCount = _a.matchUpsCount, roundNumber = _a.roundNumber, structureId = _a.structureId, newRound = _a.newRound;
47852
47887
  if (typeof drawDefinition !== 'object')
47853
47888
  return { error: MISSING_DRAW_DEFINITION };
47854
47889
  if (!structureId && ((_b = drawDefinition.structures) === null || _b === void 0 ? void 0 : _b.length) === 1)
47855
47890
  structureId = (_d = (_c = drawDefinition.structures) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.structureId;
47856
47891
  if (typeof structureId !== 'string')
47857
47892
  return { error: MISSING_STRUCTURE_ID };
47893
+ // if drawDefinition and structureId are provided it is possible to infer roundNumber
47894
+ var structure = (_e = drawDefinition.structures) === null || _e === void 0 ? void 0 : _e.find(function (structure) { return structure.structureId === structureId; });
47895
+ if (!structure)
47896
+ return { error: STRUCTURE_NOT_FOUND };
47897
+ if (!matchUpsCount) {
47898
+ var selectedEntries = (_g = (_f = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) === null || _f === void 0 ? void 0 : _f.filter(function (entry) {
47899
+ var entryStatus = entry.entryStatus;
47900
+ return STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
47901
+ })) !== null && _g !== void 0 ? _g : [];
47902
+ var roundMatchUpsCount = Math.floor((selectedEntries === null || selectedEntries === void 0 ? void 0 : selectedEntries.length) / 2) || 1;
47903
+ if (newRound) {
47904
+ matchUpsCount = roundMatchUpsCount;
47905
+ }
47906
+ else {
47907
+ var maxRemaining = roundMatchUpsCount - (((_h = structure.matchUps) === null || _h === void 0 ? void 0 : _h.length) || 0); // TODO: minus the number of existing matchUps in roundNumber
47908
+ if (maxRemaining > 0)
47909
+ matchUpsCount = maxRemaining;
47910
+ }
47911
+ }
47858
47912
  if ((participantIdPairings && !Array.isArray(participantIdPairings)) ||
47859
47913
  (matchUpsCount && !isConvertableInteger(matchUpsCount)) ||
47860
47914
  (matchUpIds && !Array.isArray(matchUpIds)) ||
47861
47915
  (!participantIdPairings && !matchUpsCount)) {
47862
47916
  return { error: INVALID_VALUES, info: 'matchUpsCount or pairings error' };
47863
47917
  }
47864
- // if drawDefinition and structureId are provided it is possible to infer roundNumber
47865
- var structure = (_e = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) === null || _e === void 0 ? void 0 : _e.find(function (structure) { return structure.structureId === structureId; });
47866
47918
  var structureHasRoundPositions;
47867
- var existingMatchUps = structure === null || structure === void 0 ? void 0 : structure.matchUps;
47919
+ var existingMatchUps = (_j = structure.matchUps) !== null && _j !== void 0 ? _j : [];
47868
47920
  var lastRoundNumber = existingMatchUps === null || existingMatchUps === void 0 ? void 0 : existingMatchUps.reduce(function (roundNumber, matchUp) {
47869
47921
  if (matchUp.roundPosition)
47870
47922
  structureHasRoundPositions = true;
@@ -47875,14 +47927,14 @@ function generateAdHocMatchUps$1(_a) {
47875
47927
  // structure must not be a container of other structures
47876
47928
  // structure must not contain matchUps with roundPosition
47877
47929
  // structure must not determine finishingPosition by ROUND_OUTCOME
47878
- if ((structure === null || structure === void 0 ? void 0 : structure.structures) ||
47930
+ if (structure.structures ||
47879
47931
  structureHasRoundPositions ||
47880
- (structure === null || structure === void 0 ? void 0 : structure.finishingPosition) === ROUND_OUTCOME) {
47932
+ structure.finishingPosition === ROUND_OUTCOME) {
47881
47933
  return { error: INVALID_STRUCTURE };
47882
47934
  }
47883
47935
  if (roundNumber && roundNumber - 1 > (lastRoundNumber || 0))
47884
47936
  return { error: INVALID_VALUES, info: 'roundNumber error' };
47885
- var nextRoundNumber = roundNumber !== null && roundNumber !== void 0 ? roundNumber : (newRound ? (lastRoundNumber !== null && lastRoundNumber !== void 0 ? lastRoundNumber : 0) + 1 : lastRoundNumber !== null && lastRoundNumber !== void 0 ? lastRoundNumber : 1);
47937
+ var nextRoundNumber = roundNumber !== null && roundNumber !== void 0 ? roundNumber : ((newRound && (lastRoundNumber !== null && lastRoundNumber !== void 0 ? lastRoundNumber : 0) + 1) || lastRoundNumber || 1);
47886
47938
  participantIdPairings =
47887
47939
  participantIdPairings !== null && participantIdPairings !== void 0 ? participantIdPairings : generateRange(0, matchUpsCount).map(function () { return ({
47888
47940
  participantIds: [undefined, undefined],
@@ -62873,6 +62925,7 @@ var eventGovernor = {
62873
62925
  renameStructures: renameStructures,
62874
62926
  disableTieAutoCalc: disableTieAutoCalc,
62875
62927
  enableTieAutoCalc: enableTieAutoCalc,
62928
+ validateCollectionDefinition: validateCollectionDefinition,
62876
62929
  modifyCollectionDefinition: modifyCollectionDefinition$1,
62877
62930
  orderCollectionDefinitions: orderCollectionDefinitions$1,
62878
62931
  removeCollectionDefinition: removeCollectionDefinition$1,