tods-competition-factory 1.7.13 → 1.7.15

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.13';
365
+ return '1.7.15';
366
366
  }
367
367
 
368
368
  /******************************************************************************
@@ -2947,8 +2947,9 @@ function decorateResult(_a) {
2947
2947
  if (result && Array.isArray(result === null || result === void 0 ? void 0 : result.stack) && typeof stack === 'string') {
2948
2948
  result.stack.push(stack);
2949
2949
  }
2950
- if (info && (result === null || result === void 0 ? void 0 : result.error))
2951
- result.error.info = info;
2950
+ if (result && info) {
2951
+ result.info = info;
2952
+ }
2952
2953
  if (result && typeof context === 'object' && Object.keys(context).length) {
2953
2954
  Object.assign(result, definedAttributes(context));
2954
2955
  }
@@ -3525,34 +3526,28 @@ function validateTieFormat(params) {
3525
3526
  var tieFormat = params === null || params === void 0 ? void 0 : params.tieFormat;
3526
3527
  var stack = 'validateTieFormat';
3527
3528
  var errors = [];
3528
- if (typeof tieFormat !== 'object') {
3529
+ if (!params || !tieFormat || typeof tieFormat !== 'object') {
3529
3530
  errors.push('tieFormat must be an object');
3530
3531
  return decorateResult({
3531
- result: {
3532
- context: { tieFormat: tieFormat, errors: errors },
3533
- error: INVALID_TIE_FORMAT,
3534
- stack: stack,
3535
- },
3532
+ result: { error: INVALID_TIE_FORMAT },
3533
+ context: { tieFormat: tieFormat, errors: errors },
3534
+ stack: stack,
3536
3535
  });
3537
3536
  }
3538
3537
  if (typeof tieFormat.winCriteria !== 'object') {
3539
3538
  errors.push('tieFormat.winCriteria must be an object');
3540
3539
  return decorateResult({
3541
- result: {
3542
- context: { tieFormat: tieFormat, errors: errors },
3543
- error: INVALID_TIE_FORMAT,
3544
- stack: stack,
3545
- },
3540
+ result: { error: INVALID_TIE_FORMAT },
3541
+ context: { tieFormat: tieFormat, errors: errors },
3542
+ stack: stack,
3546
3543
  });
3547
3544
  }
3548
3545
  if (!Array.isArray(tieFormat.collectionDefinitions)) {
3549
3546
  errors.push(mustBeAnArray('tieFormat.collectionDefinitions'));
3550
3547
  return decorateResult({
3551
- result: {
3552
- context: { tieFormat: tieFormat, errors: errors },
3553
- error: INVALID_TIE_FORMAT,
3554
- stack: stack,
3555
- },
3548
+ result: { error: INVALID_TIE_FORMAT },
3549
+ context: { tieFormat: tieFormat, errors: errors },
3550
+ stack: stack,
3556
3551
  });
3557
3552
  }
3558
3553
  var aggregateValueImperative;
@@ -3586,11 +3581,9 @@ function validateTieFormat(params) {
3586
3581
  errors.push('Either non-zero valueGoal, or { aggregateValue: true } must be specified in winCriteria');
3587
3582
  }
3588
3583
  return decorateResult({
3589
- result: {
3590
- context: { tieFormat: tieFormat, errors: errors, aggregateValueImperative: aggregateValueImperative },
3591
- error: INVALID_TIE_FORMAT,
3592
- stack: stack,
3593
- },
3584
+ context: { tieFormat: tieFormat, errors: errors, aggregateValueImperative: aggregateValueImperative },
3585
+ result: { error: INVALID_TIE_FORMAT },
3586
+ stack: stack,
3594
3587
  });
3595
3588
  }
3596
3589
  var collectionIds = tieFormat.collectionDefinitions.map(function (_a) {
@@ -3603,11 +3596,9 @@ function validateTieFormat(params) {
3603
3596
  var result = { valid: valid, errors: errors };
3604
3597
  if (!valid) {
3605
3598
  return decorateResult({
3606
- result: {
3607
- context: { tieFormat: tieFormat, errors: errors },
3608
- error: INVALID_TIE_FORMAT,
3609
- stack: stack,
3610
- },
3599
+ result: { error: INVALID_TIE_FORMAT },
3600
+ context: { tieFormat: tieFormat, errors: errors },
3601
+ stack: stack,
3611
3602
  });
3612
3603
  }
3613
3604
  return result;
@@ -3644,7 +3635,7 @@ function validateCollectionDefinition(_a) {
3644
3635
  errors.push("collectionValue is not type number: ".concat(collectionValue));
3645
3636
  }
3646
3637
  if (collectionValueProfiles) {
3647
- var result = validateCollectionValueProfile({
3638
+ var result = validateCollectionValueProfiles({
3648
3639
  collectionValueProfiles: collectionValueProfiles,
3649
3640
  matchUpCount: matchUpCount,
3650
3641
  });
@@ -3691,7 +3682,7 @@ function checkTieFormat(tieFormat) {
3691
3682
  }
3692
3683
  return { tieFormat: tieFormat };
3693
3684
  }
3694
- function validateCollectionValueProfile(_a) {
3685
+ function validateCollectionValueProfiles(_a) {
3695
3686
  var e_2, _b;
3696
3687
  var collectionValueProfiles = _a.collectionValueProfiles, matchUpCount = _a.matchUpCount;
3697
3688
  var errors = [];
@@ -5931,26 +5922,27 @@ function getEvents(_a) {
5931
5922
  return { events: eventCopies };
5932
5923
  }
5933
5924
  function findEvent(_a) {
5925
+ var _b;
5934
5926
  var tournamentRecord = _a.tournamentRecord, eventId = _a.eventId, drawId = _a.drawId;
5935
5927
  var stack = 'findEvent';
5936
5928
  if (!tournamentRecord)
5937
- return __assign({ event: undefined, drawDefinition: undefined }, decorateResult({
5929
+ return decorateResult({
5938
5930
  result: { error: MISSING_TOURNAMENT_RECORD },
5939
5931
  stack: stack,
5940
- }));
5941
- var events = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.events) || [];
5932
+ });
5933
+ var events = (_b = tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.events) !== null && _b !== void 0 ? _b : [];
5942
5934
  if (drawId) {
5943
5935
  var drawDefinition_1;
5944
5936
  var event_1 = events.find(function (event) {
5945
- var _a;
5946
- var drawDefinitions = (event === null || event === void 0 ? void 0 : event.drawDefinitions) || [];
5937
+ var _a, _b;
5938
+ var drawDefinitions = (_a = event === null || event === void 0 ? void 0 : event.drawDefinitions) !== null && _a !== void 0 ? _a : [];
5947
5939
  var targetDrawDefinition = drawDefinitions.find(function (drawDefinition) { return drawDefinition.drawId === drawId; });
5948
5940
  if (targetDrawDefinition) {
5949
5941
  drawDefinition_1 = targetDrawDefinition;
5950
5942
  }
5951
5943
  else {
5952
5944
  var flightProfile = getFlightProfile({ event: event }).flightProfile;
5953
- var flight = (_a = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _a === void 0 ? void 0 : _a.find(function (flight) { return flight.drawId === drawId; });
5945
+ var flight = (_b = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _b === void 0 ? void 0 : _b.find(function (flight) { return flight.drawId === drawId; });
5954
5946
  if (flight)
5955
5947
  return {
5956
5948
  drawId: drawId,
@@ -5998,6 +5990,7 @@ function getDrawDefinition$2(_a) {
5998
5990
  }
5999
5991
 
6000
5992
  function addExtension$1(params) {
5993
+ var _a;
6001
5994
  if (typeof params !== 'object')
6002
5995
  return { error: MISSING_VALUE };
6003
5996
  var stack = 'addExtension';
@@ -6012,7 +6005,7 @@ function addExtension$1(params) {
6012
6005
  });
6013
6006
  if (!params.element.extensions)
6014
6007
  params.element.extensions = [];
6015
- var creationTime = params.creationTime !== undefined ? params.creationTime : true;
6008
+ var creationTime = (_a = params === null || params === void 0 ? void 0 : params.creationTime) !== null && _a !== void 0 ? _a : true;
6016
6009
  if (creationTime) {
6017
6010
  var createdAt = new Date().toISOString();
6018
6011
  Object.assign(params.extension, { createdAt: createdAt });
@@ -6577,7 +6570,7 @@ function publicFindVenue(_a) {
6577
6570
 
6578
6571
  function findCourt(_a) {
6579
6572
  var e_1, _b;
6580
- var _c;
6573
+ var _c, _d;
6581
6574
  var tournamentRecords = _a.tournamentRecords, tournamentRecord = _a.tournamentRecord, courtId = _a.courtId;
6582
6575
  if (!tournamentRecord)
6583
6576
  return { error: MISSING_TOURNAMENT_RECORD };
@@ -6599,9 +6592,9 @@ function findCourt(_a) {
6599
6592
  }
6600
6593
  else if (tournamentRecords) {
6601
6594
  // if tournamentRecords is provided then call is from competitionEngine
6602
- var linkedTournamentIds = getLinkedTournamentIds({
6595
+ var linkedTournamentIds = (_d = getLinkedTournamentIds({
6603
6596
  tournamentRecords: tournamentRecords,
6604
- }).linkedTournamentIds || [];
6597
+ }).linkedTournamentIds) !== null && _d !== void 0 ? _d : [];
6605
6598
  var relevantIds = linkedTournamentIds[tournamentRecord.tournamentId];
6606
6599
  try {
6607
6600
  // if there are linked tournaments search for court in all linked tournaments
@@ -18178,6 +18171,10 @@ function proConflicts(_a) {
18178
18171
  return { courtIssues: courtIssues, rowIssues: rowIssues };
18179
18172
  }
18180
18173
 
18174
+ function stringSort(a, b) {
18175
+ return (a || '').localeCompare(b || '');
18176
+ }
18177
+
18181
18178
  function getTieFormatDesc(tieFormat) {
18182
18179
  var _a;
18183
18180
  if (!tieFormat)
@@ -18266,18 +18263,57 @@ function compareTieFormats(_a) {
18266
18263
  ancestorDifferences.collectionsValue.totalValue;
18267
18264
  var matchUpCountDifference = descendantDifferences.collectionsValue.totalMatchUps -
18268
18265
  ancestorDifferences.collectionsValue.totalMatchUps;
18266
+ var assignmentValuesCountDifference = ancestorDifferences.collectionsValue.assignmentValues.length !==
18267
+ descendantDifferences.collectionsValue.assignmentValues.length;
18268
+ var assignmentValuesDifference = ancestorDifferences.collectionsValue.assignmentValues.some(function (assignment, i) {
18269
+ var comparisonAssignment = descendantDifferences.collectionsValue.assignmentValues[i];
18270
+ if (!comparisonAssignment)
18271
+ return true;
18272
+ if (assignment.valueKey !== comparisonAssignment.valueKey)
18273
+ return true;
18274
+ if (assignment.value !== comparisonAssignment.value)
18275
+ return true;
18276
+ if (Array.isArray(assignment.value)) {
18277
+ return assignment.value.every(function (value, i) { return comparisonAssignment.value[i] === value; });
18278
+ }
18279
+ return false;
18280
+ });
18269
18281
  var different = nameDifference ||
18270
18282
  orderDifference ||
18271
18283
  ancestorDesc !== descendantDesc ||
18284
+ assignmentValuesCountDifference ||
18285
+ assignmentValuesDifference ||
18272
18286
  valueDifference !== 0;
18273
- return __assign(__assign({ matchUpFormatDifferences: matchUpFormatDifferences, matchUpCountDifference: matchUpCountDifference, descendantDifferences: descendantDifferences, ancestorDifferences: ancestorDifferences, orderDifference: orderDifference, valueDifference: valueDifference, nameDifference: nameDifference, descendantDesc: descendantDesc, ancestorDesc: ancestorDesc }, SUCCESS), { different: different });
18287
+ var invalidValues = __spreadArray(__spreadArray([], __read(ancestorDifferences.collectionsValue.invalidValues), false), __read(descendantDifferences.collectionsValue.invalidValues), false);
18288
+ var invalid = invalidValues.length && invalidValues;
18289
+ return __assign(__assign({ matchUpFormatDifferences: matchUpFormatDifferences, matchUpCountDifference: matchUpCountDifference, descendantDifferences: descendantDifferences, ancestorDifferences: ancestorDifferences, orderDifference: orderDifference, valueDifference: valueDifference, nameDifference: nameDifference, descendantDesc: descendantDesc, ancestorDesc: ancestorDesc }, SUCCESS), { different: different, invalid: invalid });
18274
18290
  }
18275
18291
  function getCollectionsValue(definitions) {
18292
+ var invalidValues = [];
18293
+ var assignmentValues = [];
18276
18294
  var totalMatchUps = 0;
18277
- var collectionIds = Object.keys(definitions);
18295
+ var collectionIds = Object.keys(definitions).sort(stringSort);
18278
18296
  var totalValue = collectionIds.reduce(function (total, collectionId) {
18279
18297
  var collectionDefinition = definitions[collectionId];
18280
18298
  var collectionValueProfiles = collectionDefinition.collectionValueProfiles, collectionValue = collectionDefinition.collectionValue, matchUpCount = collectionDefinition.matchUpCount, matchUpValue = collectionDefinition.matchUpValue, scoreValue = collectionDefinition.scoreValue, setValue = collectionDefinition.setValue;
18299
+ var valueAssignments = {
18300
+ collectionValueProfiles: collectionValueProfiles,
18301
+ collectionValue: collectionValue,
18302
+ matchUpValue: matchUpValue,
18303
+ scoreValue: scoreValue,
18304
+ setValue: setValue,
18305
+ };
18306
+ var valueKeys = Object.keys(valueAssignments).filter(function (key) { return ![undefined, null].includes(valueAssignments[key]); });
18307
+ if (valueKeys.length !== 1) {
18308
+ invalidValues.push({ collectionId: collectionId });
18309
+ }
18310
+ var valueKey = valueKeys[0];
18311
+ if (valueKey) {
18312
+ var value = valueKey === 'collectionValueProfiles'
18313
+ ? Object.values(collectionValueProfiles)
18314
+ : valueAssignments[valueKey];
18315
+ assignmentValues.push({ valueKey: valueKey, value: value });
18316
+ }
18281
18317
  totalMatchUps += matchUpCount;
18282
18318
  if (collectionValueProfiles)
18283
18319
  return (total +
@@ -18293,7 +18329,7 @@ function getCollectionsValue(definitions) {
18293
18329
  }
18294
18330
  return total;
18295
18331
  }, 0);
18296
- return { totalValue: totalValue, totalMatchUps: totalMatchUps };
18332
+ return { totalValue: totalValue, totalMatchUps: totalMatchUps, invalidValues: invalidValues, assignmentValues: assignmentValues };
18297
18333
  }
18298
18334
 
18299
18335
  function dehydrateMatchUps(_a) {
@@ -22870,6 +22906,7 @@ function drawPositionRemovals(_a) {
22870
22906
  return { tasks: tasks, drawPositionCleared: drawPositionCleared, positionAssignments: positionAssignments };
22871
22907
  }
22872
22908
  function removeSubsequentRoundsParticipant(_a) {
22909
+ var _b;
22873
22910
  var inContextDrawMatchUps = _a.inContextDrawMatchUps, targetDrawPosition = _a.targetDrawPosition, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, matchUpsMap = _a.matchUpsMap, roundNumber = _a.roundNumber, structureId = _a.structureId;
22874
22911
  var structure = findStructure({ drawDefinition: drawDefinition, structureId: structureId }).structure;
22875
22912
  if (!structure)
@@ -22889,10 +22926,10 @@ function removeSubsequentRoundsParticipant(_a) {
22889
22926
  matchUp.roundNumber !== initialRoundNumber &&
22890
22927
  ((_a = matchUp.drawPositions) === null || _a === void 0 ? void 0 : _a.includes(targetDrawPosition));
22891
22928
  });
22892
- var positionAssignments = getPositionAssignments$1({
22929
+ var positionAssignments = (_b = getPositionAssignments$1({
22893
22930
  drawDefinition: drawDefinition,
22894
22931
  structureId: structureId,
22895
- }).positionAssignments || [];
22932
+ }).positionAssignments) !== null && _b !== void 0 ? _b : [];
22896
22933
  relevantMatchUps === null || relevantMatchUps === void 0 ? void 0 : relevantMatchUps.forEach(function (matchUp) {
22897
22934
  return removeDrawPosition({
22898
22935
  drawPosition: targetDrawPosition,
@@ -22908,13 +22945,13 @@ function removeSubsequentRoundsParticipant(_a) {
22908
22945
  return __assign({}, SUCCESS);
22909
22946
  }
22910
22947
  function removeDrawPosition(_a) {
22911
- var _b, _c, _d, _e, _f;
22948
+ var _b, _c, _d, _e, _f, _g, _h;
22912
22949
  var inContextDrawMatchUps = _a.inContextDrawMatchUps, positionAssignments = _a.positionAssignments, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, targetMatchUp = _a.targetMatchUp, drawPosition = _a.drawPosition, matchUpsMap = _a.matchUpsMap, structure = _a.structure, event = _a.event;
22913
22950
  var stack = 'removeDrawPosition';
22914
22951
  var initialDrawPositions = (_b = targetMatchUp.drawPositions) === null || _b === void 0 ? void 0 : _b.slice();
22915
22952
  var initialMatchUpStatus = targetMatchUp.matchUpStatus;
22916
22953
  var initialWinningSide = targetMatchUp.winningSide;
22917
- matchUpsMap = matchUpsMap || getMatchUpsMap({ drawDefinition: drawDefinition });
22954
+ matchUpsMap = matchUpsMap !== null && matchUpsMap !== void 0 ? matchUpsMap : getMatchUpsMap({ drawDefinition: drawDefinition });
22918
22955
  var mappedMatchUps = matchUpsMap.mappedMatchUps;
22919
22956
  var matchUps = mappedMatchUps[structure.structureId].matchUps;
22920
22957
  var initialRoundNumber = getInitialRoundNumber({
@@ -22924,18 +22961,18 @@ function removeDrawPosition(_a) {
22924
22961
  if (targetMatchUp.roundNumber &&
22925
22962
  initialRoundNumber &&
22926
22963
  targetMatchUp.roundNumber > initialRoundNumber) {
22927
- var drawPositions = (targetMatchUp.drawPositions || []).map(function (currentDrawPosition) {
22964
+ var drawPositions = ((_c = targetMatchUp.drawPositions) !== null && _c !== void 0 ? _c : []).map(function (currentDrawPosition) {
22928
22965
  return currentDrawPosition === drawPosition ? undefined : currentDrawPosition;
22929
22966
  });
22930
22967
  targetMatchUp.drawPositions = drawPositions;
22931
22968
  }
22932
22969
  if (targetMatchUp.matchUpType === TEAM$2) {
22933
22970
  var inContextTargetMatchUp = inContextDrawMatchUps === null || inContextDrawMatchUps === void 0 ? void 0 : inContextDrawMatchUps.find(function (matchUp) { return matchUp.matchUpId === targetMatchUp.matchUpId; });
22934
- var sides = (inContextTargetMatchUp === null || inContextTargetMatchUp === void 0 ? void 0 : inContextTargetMatchUp.sides) || [];
22971
+ var sides = (_d = inContextTargetMatchUp === null || inContextTargetMatchUp === void 0 ? void 0 : inContextTargetMatchUp.sides) !== null && _d !== void 0 ? _d : [];
22935
22972
  var drawPositionSideIndex = sides.reduce(function (index, side, i) { return (side.drawPosition === drawPosition ? i : index); }, undefined);
22936
22973
  if (drawPositionSideIndex !== undefined &&
22937
- ((_d = (_c = targetMatchUp.sides) === null || _c === void 0 ? void 0 : _c[drawPositionSideIndex]) === null || _d === void 0 ? void 0 : _d.lineUp)) {
22938
- (_e = targetMatchUp.sides) === null || _e === void 0 ? true : delete _e[drawPositionSideIndex].lineUp;
22974
+ ((_f = (_e = targetMatchUp.sides) === null || _e === void 0 ? void 0 : _e[drawPositionSideIndex]) === null || _f === void 0 ? void 0 : _f.lineUp)) {
22975
+ (_g = targetMatchUp.sides) === null || _g === void 0 ? true : delete _g[drawPositionSideIndex].lineUp;
22939
22976
  modifyMatchUpNotice({
22940
22977
  tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
22941
22978
  context: "".concat(stack, "-TEAM"),
@@ -22950,7 +22987,7 @@ function removeDrawPosition(_a) {
22950
22987
  inContextDrawMatchUps: inContextDrawMatchUps,
22951
22988
  drawDefinition: drawDefinition,
22952
22989
  });
22953
- var winnerTargetLink = targetData.targetLinks.winnerTargetLink, _g = targetData.targetMatchUps, loserMatchUp = _g.loserMatchUp, winnerMatchUp = _g.winnerMatchUp, loserMatchUpDrawPositionIndex = _g.loserMatchUpDrawPositionIndex;
22990
+ var winnerTargetLink = targetData.targetLinks.winnerTargetLink, _j = targetData.targetMatchUps, loserMatchUp = _j.loserMatchUp, winnerMatchUp = _j.winnerMatchUp, loserMatchUpDrawPositionIndex = _j.loserMatchUpDrawPositionIndex;
22954
22991
  var matchUpAssignments = positionAssignments.filter(function (_a) {
22955
22992
  var _b;
22956
22993
  var drawPosition = _a.drawPosition;
@@ -22961,7 +22998,7 @@ function removeDrawPosition(_a) {
22961
22998
  (targetMatchUp.matchUpStatus &&
22962
22999
  [DEFAULTED, WALKOVER$2].includes(targetMatchUp.matchUpStatus) &&
22963
23000
  targetMatchUp.matcHUpStatus) ||
22964
- (((_f = targetMatchUp.drawPositions) === null || _f === void 0 ? void 0 : _f.length) === 2 && TO_BE_PLAYED) ||
23001
+ (((_h = targetMatchUp.drawPositions) === null || _h === void 0 ? void 0 : _h.length) === 2 && TO_BE_PLAYED) ||
22965
23002
  undefined;
22966
23003
  targetMatchUp.matchUpStatus = newMatchUpStatus;
22967
23004
  // if the matchUpStatus is WALKOVER then it is DOUBLE_WALKOVER produced
@@ -24088,9 +24125,7 @@ function assignMatchUpDrawPosition(_a) {
24088
24125
  }
24089
24126
  else {
24090
24127
  return decorateResult({
24091
- result: {
24092
- error: DRAW_POSITION_ASSIGNED,
24093
- },
24128
+ result: { error: DRAW_POSITION_ASSIGNED },
24094
24129
  context: { drawPosition: drawPosition },
24095
24130
  stack: stack,
24096
24131
  });
@@ -25171,8 +25206,8 @@ function getSeedGroups(_a) {
25171
25206
  if (roundRobinGroupsCount) {
25172
25207
  if (!isConvertableInteger(roundRobinGroupsCount))
25173
25208
  return __assign({ seedGroups: undefined }, decorateResult({
25174
- result: { error: INVALID_VALUES },
25175
25209
  context: { roundRobinGroupsCount: roundRobinGroupsCount },
25210
+ result: { error: INVALID_VALUES },
25176
25211
  stack: stack,
25177
25212
  }));
25178
25213
  var seedNumber_1 = 1;
@@ -25211,8 +25246,8 @@ function getSeedingThresholds(_a) {
25211
25246
  var invalid = !(validGroupsCounts === null || validGroupsCounts === void 0 ? void 0 : validGroupsCounts.includes(roundRobinGroupsCount));
25212
25247
  if (invalid) {
25213
25248
  return decorateResult({
25214
- result: { error: INVALID_VALUES },
25215
25249
  context: { roundRobinGroupsCount: roundRobinGroupsCount },
25250
+ result: { error: INVALID_VALUES },
25216
25251
  });
25217
25252
  }
25218
25253
  }
@@ -26293,7 +26328,8 @@ function directLoser(params) {
26293
26328
  }
26294
26329
  else if (loserParticipantId && isFeedRound) {
26295
26330
  // if target.roundNumber > 1 then it is a feed round and should always take the lower drawPosition
26296
- var fedDrawPosition = unfilledTargetMatchUpDrawPositions.sort(numericSort)[0];
26331
+ unfilledTargetMatchUpDrawPositions.sort(numericSort);
26332
+ var fedDrawPosition = unfilledTargetMatchUpDrawPositions[0];
26297
26333
  var result = assignDrawPosition$1({
26298
26334
  participantId: loserParticipantId,
26299
26335
  structureId: targetStructureId,
@@ -27245,7 +27281,7 @@ function swapWinnerLoser(params) {
27245
27281
  }
27246
27282
 
27247
27283
  function setMatchUpStatus$2(params) {
27248
- var _a, _b, _c, _d, _e;
27284
+ var _a, _b, _c, _d, _e, _f, _g, _h;
27249
27285
  var stack = 'setMatchUpStatus';
27250
27286
  // always clear score if DOUBLE_WALKOVER or WALKOVER
27251
27287
  if (params.matchUpStatus &&
@@ -27305,13 +27341,13 @@ function setMatchUpStatus$2(params) {
27305
27341
  else if (enableAutoCalc) {
27306
27342
  var existingDualMatchUpWinningSide = matchUp.winningSide;
27307
27343
  removeExtension$1({ name: DISABLE_AUTO_CALC, element: matchUp });
27308
- var _f = generateTieMatchUpScore({
27344
+ var _j = generateTieMatchUpScore({
27309
27345
  drawDefinition: drawDefinition,
27310
27346
  matchUpsMap: matchUpsMap,
27311
27347
  structure: structure,
27312
27348
  matchUp: matchUp,
27313
27349
  event: event,
27314
- }), projectedWinningSide = _f.winningSide, scoreStringSide1 = _f.scoreStringSide1, scoreStringSide2 = _f.scoreStringSide2, set = _f.set;
27350
+ }), projectedWinningSide = _j.winningSide, scoreStringSide1 = _j.scoreStringSide1, scoreStringSide2 = _j.scoreStringSide2, set = _j.set;
27315
27351
  var score_1 = {
27316
27352
  scoreStringSide1: scoreStringSide1,
27317
27353
  scoreStringSide2: scoreStringSide2,
@@ -27350,10 +27386,7 @@ function setMatchUpStatus$2(params) {
27350
27386
  drawDefinition: drawDefinition,
27351
27387
  });
27352
27388
  if (score && matchUp.matchUpType !== TEAM$2 && !disableScoreValidation) {
27353
- var matchUpFormat = matchUp.matchUpFormat ||
27354
- (structure === null || structure === void 0 ? void 0 : structure.matchUpFormat) ||
27355
- (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.matchUpFormat) ||
27356
- (event === null || event === void 0 ? void 0 : event.matchUpFormat);
27389
+ var matchUpFormat = (_d = (_c = (_b = matchUp.matchUpFormat) !== null && _b !== void 0 ? _b : structure === null || structure === void 0 ? void 0 : structure.matchUpFormat) !== null && _c !== void 0 ? _c : drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.matchUpFormat) !== null && _d !== void 0 ? _d : event === null || event === void 0 ? void 0 : event.matchUpFormat;
27357
27390
  var result_1 = validateScore({
27358
27391
  existingMatchUpStatus: matchUp.matchUpStatus,
27359
27392
  matchUpFormat: matchUpFormat,
@@ -27371,7 +27404,7 @@ function setMatchUpStatus$2(params) {
27371
27404
  structureId: structureId,
27372
27405
  }).positionAssignments
27373
27406
  : [];
27374
- var bothSideParticipants = ((_b = matchUp.sides) === null || _b === void 0 ? void 0 : _b.map(function (side) { return side.participantId; }).filter(Boolean).length) ===
27407
+ var bothSideParticipants = ((_e = matchUp.sides) === null || _e === void 0 ? void 0 : _e.map(function (side) { return side.participantId; }).filter(Boolean).length) ===
27375
27408
  2 ||
27376
27409
  ((assignedDrawPositions === null || assignedDrawPositions === void 0 ? void 0 : assignedDrawPositions.length) === 2 &&
27377
27410
  (positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.filter(function (assignment) {
@@ -27381,17 +27414,17 @@ function setMatchUpStatus$2(params) {
27381
27414
  particicipantsRequiredMatchUpStatuses.includes(matchUpStatus) &&
27382
27415
  !bothSideParticipants) {
27383
27416
  return decorateResult({
27384
- result: { error: INVALID_MATCHUP_STATUS },
27385
27417
  info: 'present in participantRequiredMatchUpStatuses',
27386
27418
  context: { matchUpStatus: matchUpStatus, bothSideParticipants: bothSideParticipants },
27419
+ result: { error: INVALID_MATCHUP_STATUS },
27387
27420
  });
27388
27421
  }
27389
- var appliedPolicies = (_d = (_c = getAppliedPolicies({
27422
+ var appliedPolicies = (_g = (_f = getAppliedPolicies({
27390
27423
  policyTypes: [POLICY_TYPE_PROGRESSION],
27391
27424
  tournamentRecord: tournamentRecord,
27392
27425
  drawDefinition: drawDefinition,
27393
27426
  event: event,
27394
- })) === null || _c === void 0 ? void 0 : _c.appliedPolicies) !== null && _d !== void 0 ? _d : {};
27427
+ })) === null || _f === void 0 ? void 0 : _f.appliedPolicies) !== null && _g !== void 0 ? _g : {};
27395
27428
  if (typeof params.policyDefinitions === 'object') {
27396
27429
  Object.assign(appliedPolicies, params.policyDefinitions);
27397
27430
  }
@@ -27432,12 +27465,12 @@ function setMatchUpStatus$2(params) {
27432
27465
  event: event,
27433
27466
  }).matchUp;
27434
27467
  if (dualMatchUp) {
27435
- var tieFormat = (_e = resolveTieFormat({
27468
+ var tieFormat = (_h = resolveTieFormat({
27436
27469
  matchUp: dualMatchUp,
27437
27470
  drawDefinition: drawDefinition,
27438
27471
  structure: structure,
27439
27472
  event: event,
27440
- })) === null || _e === void 0 ? void 0 : _e.tieFormat;
27473
+ })) === null || _h === void 0 ? void 0 : _h.tieFormat;
27441
27474
  var projectedWinningSide = getProjectedDualWinningSide({
27442
27475
  drawDefinition: drawDefinition,
27443
27476
  matchUpStatus: matchUpStatus,
@@ -27533,8 +27566,8 @@ function winningSideWithDownstreamDependencies(params) {
27533
27566
  }
27534
27567
  else {
27535
27568
  return decorateResult({
27536
- result: { error: CANNOT_CHANGE_WINNING_SIDE },
27537
27569
  stack: 'winningSideWithDownstreamDependencies',
27570
+ result: { error: CANNOT_CHANGE_WINNING_SIDE },
27538
27571
  context: { winningSide: winningSide, matchUp: matchUp },
27539
27572
  });
27540
27573
  }
@@ -27991,13 +28024,13 @@ function addDrawDefinition$1(params) {
27991
28024
  return decorateResult({
27992
28025
  result: {
27993
28026
  error: INVALID_DRAW_DEFINITION,
27994
- context: {
27995
- drawEntriesPresentInFlight: drawEntriesPresentInFlight,
27996
- matchingEventEntries: matchingEventEntries,
27997
- relevantFlight: relevantFlight,
27998
- },
27999
- info: 'Draw entries are not present in flight or do not match entryStatuses',
28000
28027
  },
28028
+ context: {
28029
+ drawEntriesPresentInFlight: drawEntriesPresentInFlight,
28030
+ matchingEventEntries: matchingEventEntries,
28031
+ relevantFlight: relevantFlight,
28032
+ },
28033
+ info: 'Draw entries are not present in flight or do not match entryStatuses',
28001
28034
  });
28002
28035
  }
28003
28036
  if (modifyEventEntries) {
@@ -28017,9 +28050,9 @@ function addDrawDefinition$1(params) {
28017
28050
  if (eventEntries && !matchingEventEntries)
28018
28051
  return decorateResult({
28019
28052
  result: {
28020
- error: INVALID_DRAW_DEFINITION,
28021
- context: { matchingEventEntries: matchingEventEntries, eventEntries: eventEntries },
28022
28053
  info: 'Draw entries do not match event entryStatuses',
28054
+ context: { matchingEventEntries: matchingEventEntries, eventEntries: eventEntries },
28055
+ error: INVALID_DRAW_DEFINITION,
28023
28056
  },
28024
28057
  });
28025
28058
  var flightNumbers = ((_f = (_e = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _e === void 0 ? void 0 : _e.map(function (_a) {
@@ -28194,10 +28227,8 @@ function addParticipant$1(_a) {
28194
28227
  else if (participant.individualParticipantIds.length !== 2 &&
28195
28228
  !pairOverride) {
28196
28229
  return decorateResult({
28197
- result: {
28198
- error: INVALID_PARTICIPANT_IDS,
28199
- info: 'PAIR must be 2 individualParticipantIds',
28200
- },
28230
+ info: 'PAIR must be 2 individualParticipantIds',
28231
+ result: { error: INVALID_PARTICIPANT_IDS },
28201
28232
  stack: stack,
28202
28233
  });
28203
28234
  }
@@ -32036,7 +32067,7 @@ function getTieFormat$1(_a) {
32036
32067
  }
32037
32068
  if (!tieFormat)
32038
32069
  return decorateResult({ result: { error: MISSING_TIE_FORMAT }, stack: stack });
32039
- return __assign(__assign({}, SUCCESS), { tieFormat: tieFormat, matchUp: matchUp, structure: structure });
32070
+ return __assign(__assign({}, SUCCESS), { structure: structure, tieFormat: tieFormat, matchUp: matchUp });
32040
32071
  }
32041
32072
 
32042
32073
  function tieFormatTelemetry(_a) {
@@ -32054,6 +32085,38 @@ function tieFormatTelemetry(_a) {
32054
32085
  addExtension$1({ element: drawDefinition, extension: updatedExtension });
32055
32086
  }
32056
32087
 
32088
+ function generateTieMatchUps(_a) {
32089
+ var tieFormat = _a.tieFormat, isMock = _a.isMock, uuids = _a.uuids;
32090
+ var collectionDefinitions = (tieFormat !== null && tieFormat !== void 0 ? tieFormat : {}).collectionDefinitions;
32091
+ var tieMatchUps = (collectionDefinitions !== null && collectionDefinitions !== void 0 ? collectionDefinitions : [])
32092
+ .map(function (collectionDefinition) {
32093
+ return generateCollectionMatchUps({ collectionDefinition: collectionDefinition, uuids: uuids, isMock: isMock });
32094
+ })
32095
+ .filter(Boolean)
32096
+ .flat();
32097
+ return { tieMatchUps: tieMatchUps };
32098
+ }
32099
+ function generateCollectionMatchUps(_a) {
32100
+ var _b;
32101
+ var _c = _a.collectionPositionOffset, collectionPositionOffset = _c === void 0 ? 0 : _c, collectionDefinition = _a.collectionDefinition, matchUpsLimit = _a.matchUpsLimit, // internal use allows generation of missing matchUps on "reset"
32102
+ isMock = _a.isMock, uuids = _a.uuids;
32103
+ var _d = collectionDefinition || {}, matchUpCount = _d.matchUpCount, matchUpType = _d.matchUpType, collectionId = _d.collectionId, processCodes = _d.processCodes;
32104
+ var numberToGenerate = (_b = matchUpsLimit !== null && matchUpsLimit !== void 0 ? matchUpsLimit : matchUpCount) !== null && _b !== void 0 ? _b : 0;
32105
+ return generateRange(0, numberToGenerate).map(function (index) {
32106
+ var collectionPosition = collectionPositionOffset + index + 1;
32107
+ return {
32108
+ sides: [{ sideNumber: 1 }, { sideNumber: 2 }],
32109
+ matchUpId: (uuids === null || uuids === void 0 ? void 0 : uuids.pop()) || UUID(),
32110
+ matchUpStatus: MatchUpStatusEnum.ToBePlayed,
32111
+ collectionPosition: collectionPosition,
32112
+ collectionId: collectionId,
32113
+ processCodes: processCodes,
32114
+ matchUpType: matchUpType,
32115
+ isMock: isMock,
32116
+ };
32117
+ });
32118
+ }
32119
+
32057
32120
  function validUpdate(_a) {
32058
32121
  var matchUp = _a.matchUp, updateInProgressMatchUps = _a.updateInProgressMatchUps;
32059
32122
  return (!matchUp.winningSide &&
@@ -32063,17 +32126,30 @@ function validUpdate(_a) {
32063
32126
  }
32064
32127
 
32065
32128
  // used to determine that all collections have the same collectionIds
32066
- function mapsCheck(map1, map2) {
32067
- var referenceKeys = Object.keys(map1);
32068
- return (intersection(referenceKeys, Object.keys(map2)).length ===
32069
- referenceKeys.length);
32129
+ function checkStructureMatchUpCounts(_a) {
32130
+ var from = _a.from, to = _a.to;
32131
+ var referenceKeys = Object.keys(from);
32132
+ var sameKeys = intersection(referenceKeys, Object.keys(to)).length ===
32133
+ referenceKeys.length;
32134
+ var differentMatchUpsCount = referenceKeys.filter(function (collectionId) { return from[collectionId] !== to[collectionId]; });
32135
+ var matchUpsCountChanges = differentMatchUpsCount.map(function (collectionId) { return ({
32136
+ countChange: to[collectionId] - from[collectionId],
32137
+ collectionId: collectionId,
32138
+ }); });
32139
+ var sameMatchUpsCount = referenceKeys.every(function (key) { return from[key] === to[key]; });
32140
+ var equivalent = sameKeys && sameMatchUpsCount;
32141
+ return { equivalent: equivalent, matchUpsCountChanges: matchUpsCountChanges };
32070
32142
  }
32071
32143
  function updateTieFormat(_a) {
32072
32144
  var e_1, _b;
32073
32145
  var _c, _d, _e, _f, _g;
32074
- var updateInProgressMatchUps = _a.updateInProgressMatchUps, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, structure = _a.structure, tieFormat = _a.tieFormat, eventId = _a.eventId, matchUp = _a.matchUp, event = _a.event;
32146
+ var updateInProgressMatchUps = _a.updateInProgressMatchUps, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, structure = _a.structure, tieFormat = _a.tieFormat, eventId = _a.eventId, matchUp = _a.matchUp, event = _a.event, uuids = _a.uuids;
32147
+ console.log('booo', { matchUp: matchUp });
32075
32148
  var stack = 'updateTieFormat';
32149
+ var tournamentId = tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId;
32076
32150
  var modifiedStructuresCount = 0;
32151
+ var modifiedMatchUpsCount = 0;
32152
+ var addedMatchUpsCount = 0;
32077
32153
  var modifiedCount = 0;
32078
32154
  var collectionMap = tieFormat === null || tieFormat === void 0 ? void 0 : tieFormat.collectionDefinitions.reduce(function (instanceMap, def) {
32079
32155
  instanceMap[def.collectionId] =
@@ -32087,7 +32163,8 @@ function updateTieFormat(_a) {
32087
32163
  (instanceMap[def.collectionId] || 0) + def.matchUpCount;
32088
32164
  return instanceMap;
32089
32165
  }, {});
32090
- return mapsCheck(collectionMap, cMap);
32166
+ return checkStructureMatchUpCounts({ from: cMap, to: collectionMap })
32167
+ .equivalent;
32091
32168
  };
32092
32169
  var drawDefaultTieFormat = (_c = getTieFormat$1({ drawDefinition: drawDefinition })) === null || _c === void 0 ? void 0 : _c.tieFormat;
32093
32170
  var eventDefaultTieFormat = (_d = getTieFormat$1({ event: event })) === null || _d === void 0 ? void 0 : _d.tieFormat;
@@ -32105,7 +32182,7 @@ function updateTieFormat(_a) {
32105
32182
  }
32106
32183
  finally { if (e_1) throw e_1.error; }
32107
32184
  }
32108
- event.tieFormat = tieFormat;
32185
+ event.tieFormat = copyTieFormat(tieFormat);
32109
32186
  modifiedCount += 1;
32110
32187
  }
32111
32188
  else if (matchUp) {
@@ -32117,31 +32194,44 @@ function updateTieFormat(_a) {
32117
32194
  var collectionId = _a.collectionId;
32118
32195
  return collectionId;
32119
32196
  }));
32120
- if (mapsCheck(collectionMap, matchUpMap)) {
32197
+ var check = checkStructureMatchUpCounts({
32198
+ to: collectionMap,
32199
+ from: matchUpMap,
32200
+ });
32201
+ var _k = getMatchUpChangesArePossible({
32202
+ matchUp: matchUp,
32203
+ check: check,
32204
+ }), changes = _k.changes, changesArePossible = _k.changesArePossible, cannotChangeReaon = _k.cannotChangeReaon;
32205
+ if (check.equivalent) {
32121
32206
  if (validUpdate({ matchUp: matchUp, updateInProgressMatchUps: updateInProgressMatchUps })) {
32122
- matchUp.tieFormat = tieFormat;
32207
+ matchUp.tieFormat = copyTieFormat(tieFormat);
32123
32208
  modifiedCount += 1;
32124
32209
  }
32125
32210
  else {
32126
32211
  return decorateResult({
32127
32212
  result: { error: CANNOT_MODIFY_TIEFORMAT },
32128
32213
  info: 'matchUp is IN_PROGRESS or COMPLETE',
32214
+ stack: stack,
32129
32215
  });
32130
32216
  }
32131
32217
  }
32218
+ else if (changesArePossible) {
32219
+ makeChanges({ tieFormat: tieFormat, matchUp: matchUp, changes: changes, uuids: uuids });
32220
+ }
32132
32221
  else {
32133
32222
  return decorateResult({
32134
32223
  context: { collectionMap: collectionMap, matchUpMap: matchUpMap },
32135
32224
  result: { error: INVALID_TIE_FORMAT },
32136
- info: 'on matchUp',
32225
+ info: cannotChangeReaon || 'specified changes not possible',
32137
32226
  stack: stack,
32138
32227
  });
32139
32228
  }
32229
+ modifiedMatchUpsCount += 1;
32140
32230
  modifyMatchUpNotice({
32141
- tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
32142
32231
  eventId: event === null || event === void 0 ? void 0 : event.eventId,
32143
32232
  context: stack,
32144
32233
  drawDefinition: drawDefinition,
32234
+ tournamentId: tournamentId,
32145
32235
  matchUp: matchUp,
32146
32236
  });
32147
32237
  }
@@ -32149,30 +32239,43 @@ function updateTieFormat(_a) {
32149
32239
  // all TEAM matchUps within the structure have tieMatchUps which were created following a tieFormat which occurs higher in the hierarchy
32150
32240
  // attaching a tieFormat to the structure must ensure that affected TEAM matchUps within the structure all have appropriate tieMatchUps
32151
32241
  // therefore those that fail to match the modified tieFormat MUST have an appropriate tieFormat attached from higher in the hierarchy
32152
- var inheritedTieFormat = drawDefaultTieFormat || eventDefaultTieFormat;
32242
+ var inheritedTieFormat = drawDefaultTieFormat !== null && drawDefaultTieFormat !== void 0 ? drawDefaultTieFormat : eventDefaultTieFormat;
32153
32243
  var modified = (_g = processStructure({
32154
32244
  inheritedTieFormat: inheritedTieFormat,
32155
32245
  structure: structure,
32156
- })) === null || _g === void 0 ? void 0 : _g.modifiedCount;
32157
- if (modified)
32158
- modifiedStructuresCount += modified;
32159
- structure.tieFormat = tieFormat;
32160
- modifiedCount += 1;
32161
- modifyDrawNotice({
32162
- structureIds: [structure.structureId],
32163
- eventId: event === null || event === void 0 ? void 0 : event.eventId,
32164
- drawDefinition: drawDefinition,
32165
- });
32246
+ })) === null || _g === void 0 ? void 0 : _g.modifiedMatchUpsCount;
32247
+ if (modified) {
32248
+ modifiedMatchUpsCount += modified;
32249
+ modifiedStructuresCount += 1;
32250
+ modifiedCount += 1;
32251
+ }
32252
+ var different = !structure.tieFormat ||
32253
+ compareTieFormats({
32254
+ ancestor: structure.tieFormat,
32255
+ descendant: tieFormat,
32256
+ }).different;
32257
+ if (different) {
32258
+ structure.tieFormat = copyTieFormat(tieFormat);
32259
+ modifiedStructuresCount += 1;
32260
+ modifiedCount += 1;
32261
+ }
32262
+ (modified || different) &&
32263
+ drawDefinition &&
32264
+ modifyDrawNotice({
32265
+ structureIds: [structure.structureId],
32266
+ eventId: event === null || event === void 0 ? void 0 : event.eventId,
32267
+ drawDefinition: drawDefinition,
32268
+ });
32166
32269
  }
32167
32270
  else if (drawDefinition) {
32168
32271
  processDrawDefinition({ drawDefinition: drawDefinition });
32169
- drawDefinition.tieFormat = tieFormat;
32272
+ drawDefinition.tieFormat = copyTieFormat(tieFormat);
32170
32273
  modifiedCount += 1;
32171
32274
  }
32172
32275
  else {
32173
32276
  return { error: MISSING_DRAW_DEFINITION };
32174
32277
  }
32175
- return __assign(__assign({}, SUCCESS), { modifiedCount: modifiedCount, modifiedStructuresCount: modifiedStructuresCount, tieFormat: tieFormat });
32278
+ return __assign(__assign({ modifiedStructuresCount: modifiedStructuresCount, modifiedMatchUpsCount: modifiedMatchUpsCount, addedMatchUpsCount: addedMatchUpsCount, modifiedCount: modifiedCount }, SUCCESS), { tieFormat: tieFormat });
32176
32279
  function processDrawDefinition(_a) {
32177
32280
  var e_2, _b;
32178
32281
  var _c;
@@ -32189,9 +32292,10 @@ function updateTieFormat(_a) {
32189
32292
  var modifiedCount_1 = (_c = processStructure({
32190
32293
  inheritedTieFormat: inheritedTieFormat,
32191
32294
  structure: structure_1,
32192
- })) === null || _c === void 0 ? void 0 : _c.modifiedCount;
32295
+ })) === null || _c === void 0 ? void 0 : _c.modifiedMatchUpsCount;
32193
32296
  if (modifiedCount_1) {
32194
- modifiedStructuresCount += modifiedCount_1;
32297
+ modifiedStructuresCount += 1;
32298
+ modifiedMatchUpsCount += modifiedCount_1;
32195
32299
  var structureId = structure_1.structureId;
32196
32300
  modifiedStructureIds.push(structureId);
32197
32301
  }
@@ -32215,7 +32319,7 @@ function updateTieFormat(_a) {
32215
32319
  var e_3, _b;
32216
32320
  var _c, _d;
32217
32321
  var inheritedTieFormat = _a.inheritedTieFormat, structure = _a.structure;
32218
- var modifiedCount = 0;
32322
+ var modifiedMatchUpsCount = 0;
32219
32323
  var structureMatchUps = ((_c = getAllStructureMatchUps({
32220
32324
  matchUpFilters: { matchUpTypes: [TEAM$2] },
32221
32325
  structure: structure,
@@ -32223,15 +32327,34 @@ function updateTieFormat(_a) {
32223
32327
  try {
32224
32328
  for (var structureMatchUps_1 = __values(structureMatchUps), structureMatchUps_1_1 = structureMatchUps_1.next(); !structureMatchUps_1_1.done; structureMatchUps_1_1 = structureMatchUps_1.next()) {
32225
32329
  var matchUp_1 = structureMatchUps_1_1.value;
32330
+ var validToUpdate = validUpdate({ matchUp: matchUp_1, updateInProgressMatchUps: updateInProgressMatchUps });
32226
32331
  var modified = false;
32227
32332
  var tieMatchUpsMap = instanceCount((_d = matchUp_1.tieMatchUps) === null || _d === void 0 ? void 0 : _d.map(function (_a) {
32228
32333
  var collectionId = _a.collectionId;
32229
32334
  return collectionId;
32230
32335
  }));
32231
- if (!mapsCheck(collectionMap, tieMatchUpsMap)) {
32232
- if (inheritedTieFormat) {
32233
- matchUp_1.tieFormat = inheritedTieFormat;
32234
- modified = true;
32336
+ var check = checkStructureMatchUpCounts({
32337
+ from: tieMatchUpsMap,
32338
+ to: collectionMap,
32339
+ });
32340
+ if (!check.equivalent) {
32341
+ var _e = getMatchUpChangesArePossible({
32342
+ matchUp: matchUp_1,
32343
+ check: check,
32344
+ }), changes = _e.changes, changesArePossible = _e.changesArePossible;
32345
+ if (changesArePossible && !matchUp_1.tieFormat) {
32346
+ makeChanges({ changes: changes, matchUp: matchUp_1, tieFormat: tieFormat, uuids: uuids });
32347
+ }
32348
+ else if (inheritedTieFormat) {
32349
+ var different = !matchUp_1.tieFormat ||
32350
+ compareTieFormats({
32351
+ ancestor: inheritedTieFormat,
32352
+ descendant: matchUp_1.tieFormat,
32353
+ }).different;
32354
+ if (different) {
32355
+ matchUp_1.tieFormat = inheritedTieFormat;
32356
+ modified = true;
32357
+ }
32235
32358
  }
32236
32359
  else {
32237
32360
  return decorateResult({
@@ -32242,12 +32365,12 @@ function updateTieFormat(_a) {
32242
32365
  }
32243
32366
  else if (matchUp_1.tieFormat &&
32244
32367
  matchingCollections(matchUp_1) &&
32245
- validUpdate({ matchUp: matchUp_1, updateInProgressMatchUps: updateInProgressMatchUps })) {
32368
+ validToUpdate) {
32246
32369
  matchUp_1.tieFormat = copyTieFormat(tieFormat);
32247
32370
  modified = true;
32248
32371
  }
32249
32372
  if (modified) {
32250
- modifiedCount += 1;
32373
+ modifiedMatchUpsCount += 1;
32251
32374
  modifyMatchUpNotice({
32252
32375
  tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
32253
32376
  drawDefinition: drawDefinition,
@@ -32265,11 +32388,83 @@ function updateTieFormat(_a) {
32265
32388
  }
32266
32389
  finally { if (e_3) throw e_3.error; }
32267
32390
  }
32268
- return { modifiedCount: modifiedCount };
32391
+ return { modifiedMatchUpsCount: modifiedMatchUpsCount };
32269
32392
  }
32393
+ function makeChanges(_a) {
32394
+ var uuids = _a.uuids, matchUp = _a.matchUp, tieFormat = _a.tieFormat, changes = _a.changes;
32395
+ matchUp.tieFormat = copyTieFormat(tieFormat);
32396
+ var matchUpIdsRemoved = [];
32397
+ var matchUpsAdded = [];
32398
+ changes.forEach(function (change) {
32399
+ var _a;
32400
+ if (change.countChange > 0) {
32401
+ var collectionPositionOffset = Math.max.apply(Math, __spreadArray([0], __read(matchUp.tieMatchUps
32402
+ .filter(function (tieMatchUp) { return tieMatchUp.collectionId === change.collectionId; })
32403
+ .map(extractAttributes('collectionPosition'))), false));
32404
+ var collectionDefinition = tieFormat.collectionDefinitions.find(function (def) { return def.collectionId === change.collectionId; });
32405
+ var newMatchUps = generateCollectionMatchUps({
32406
+ matchUpsLimit: change.countChange,
32407
+ collectionPositionOffset: collectionPositionOffset,
32408
+ collectionDefinition: collectionDefinition,
32409
+ uuids: uuids,
32410
+ });
32411
+ matchUpsAdded.push.apply(matchUpsAdded, __spreadArray([], __read(makeDeepCopy(newMatchUps, false, true)), false));
32412
+ addedMatchUpsCount += matchUpsAdded.length;
32413
+ (_a = matchUp.tieMatchUps).push.apply(_a, __spreadArray([], __read(newMatchUps), false));
32414
+ }
32415
+ else {
32416
+ var tieMatchUpIdsToRemove_1 = change.toBePlayedTieMatchUpIds.slice(0, Math.abs(change.countChange));
32417
+ console.log('remove', tieMatchUpIdsToRemove_1.length);
32418
+ matchUpIdsRemoved.push.apply(matchUpIdsRemoved, __spreadArray([], __read(tieMatchUpIdsToRemove_1), false));
32419
+ matchUp.tieMatchUps = matchUp.tieMatchUps.filter(function (_a) {
32420
+ var matchUpId = _a.matchUpId;
32421
+ return !tieMatchUpIdsToRemove_1.includes(matchUpId);
32422
+ });
32423
+ }
32424
+ });
32425
+ matchUpsAdded.length &&
32426
+ addMatchUpsNotice({
32427
+ matchUps: matchUpsAdded,
32428
+ drawDefinition: drawDefinition,
32429
+ tournamentId: tournamentId,
32430
+ eventId: eventId,
32431
+ });
32432
+ matchUpIdsRemoved.length &&
32433
+ deleteMatchUpsNotice({
32434
+ matchUpIds: matchUpIdsRemoved,
32435
+ action: 'updateTieFormat',
32436
+ drawDefinition: drawDefinition,
32437
+ tournamentId: tournamentId,
32438
+ eventId: eventId,
32439
+ });
32440
+ return { matchUpIdsRemoved: matchUpIdsRemoved, matchUpsAdded: matchUpsAdded };
32441
+ }
32442
+ }
32443
+ function getMatchUpChangesArePossible(_a) {
32444
+ var check = _a.check, matchUp = _a.matchUp;
32445
+ var cannotChangeReaon = '';
32446
+ var changes = [];
32447
+ var changesArePossible = check.matchUpsCountChanges.every(function (_a) {
32448
+ var collectionId = _a.collectionId, countChange = _a.countChange;
32449
+ var toBePlayedTieMatchUpIds = matchUp.tieMatchUps
32450
+ .filter(function (tieMatchUp) {
32451
+ return tieMatchUp.collectionId === collectionId &&
32452
+ tieMatchUp.matchUpStatus === TO_BE_PLAYED;
32453
+ })
32454
+ .map(extractAttributes('matchUpId'));
32455
+ var possibleToChange = toBePlayedTieMatchUpIds.length + countChange >= 0 || countChange > 0;
32456
+ if (!possibleToChange && countChange < 0)
32457
+ cannotChangeReaon = 'Insufficient TO_BE_PLAYED matchUps';
32458
+ changes.push({
32459
+ toBePlayedTieMatchUpIds: toBePlayedTieMatchUpIds,
32460
+ collectionId: collectionId,
32461
+ countChange: countChange,
32462
+ });
32463
+ return possibleToChange;
32464
+ });
32465
+ return { changesArePossible: changesArePossible, changes: changes, cannotChangeReaon: cannotChangeReaon };
32270
32466
  }
32271
32467
 
32272
- // all child matchUps need to be checked for collectionAssignments / collectionPositions which need to be removed when collectionDefinition.collectionIds are removed
32273
32468
  function modifyCollectionDefinition$1(_a) {
32274
32469
  var _b, _c, _d;
32275
32470
  var _e = _a.updateInProgressMatchUps, updateInProgressMatchUps = _e === void 0 ? false : _e, tournamentRecord = _a.tournamentRecord, collectionOrder = _a.collectionOrder, collectionName = _a.collectionName, tieFormatName = _a.tieFormatName, drawDefinition = _a.drawDefinition, matchUpFormat = _a.matchUpFormat, matchUpCount = _a.matchUpCount, collectionId = _a.collectionId, matchUpType = _a.matchUpType, structureId = _a.structureId, matchUpId = _a.matchUpId, category = _a.category, eventId = _a.eventId, gender = _a.gender, event = _a.event,
@@ -32314,8 +32509,9 @@ function modifyCollectionDefinition$1(_a) {
32314
32509
  if (!Object.values(valueAssignments).filter(Boolean).length &&
32315
32510
  !collectionOrder &&
32316
32511
  !collectionName &&
32512
+ !matchUpFormat &&
32317
32513
  !matchUpCount &&
32318
- !matchUpFormat)
32514
+ !matchUpType)
32319
32515
  return decorateResult({ result: { error: MISSING_VALUE }, stack: stack });
32320
32516
  if (Object.values(valueAssignments).filter(Boolean).length > 1)
32321
32517
  return decorateResult({
@@ -32340,11 +32536,16 @@ function modifyCollectionDefinition$1(_a) {
32340
32536
  });
32341
32537
  var targetCollectionDefinition = tieFormat === null || tieFormat === void 0 ? void 0 : tieFormat.collectionDefinitions.find(function (collectionDefinition) { return collectionDefinition.collectionId === collectionId; });
32342
32538
  if (!sourceCollectionDefinition)
32343
- return decorateResult({ result: { error: NOT_FOUND }, stack: stack });
32539
+ return decorateResult({
32540
+ info: 'source collectionDefinition',
32541
+ result: { error: NOT_FOUND },
32542
+ context: { collectionId: collectionId },
32543
+ stack: stack,
32544
+ });
32344
32545
  var value = (_c = (_b = collectionValue !== null && collectionValue !== void 0 ? collectionValue : matchUpValue) !== null && _b !== void 0 ? _b : scoreValue) !== null && _c !== void 0 ? _c : setValue;
32345
32546
  if (collectionValueProfiles) {
32346
- var result_1 = validateCollectionValueProfile({
32347
- matchUpCount: matchUpCount || (sourceCollectionDefinition === null || sourceCollectionDefinition === void 0 ? void 0 : sourceCollectionDefinition.matchUpCount),
32547
+ var result_1 = validateCollectionValueProfiles({
32548
+ matchUpCount: matchUpCount !== null && matchUpCount !== void 0 ? matchUpCount : sourceCollectionDefinition === null || sourceCollectionDefinition === void 0 ? void 0 : sourceCollectionDefinition.matchUpCount,
32348
32549
  collectionValueProfiles: collectionValueProfiles,
32349
32550
  });
32350
32551
  if (result_1.errors) {
@@ -32442,16 +32643,11 @@ function modifyCollectionDefinition$1(_a) {
32442
32643
  }
32443
32644
  if (isConvertableInteger(matchUpCount) &&
32444
32645
  sourceCollectionDefinition.matchUpCount !== matchUpCount) {
32445
- // TODO: need to calculate tieMatchUp additions/deletions
32446
- // targetCollectionDefinition.matchUpCount = matchUpCount;
32447
- // modifications.push({ structureId, matchUpCount });
32448
- return decorateResult({
32449
- result: { error: NOT_IMPLEMENTED },
32450
- context: { matchUpCount: matchUpCount },
32451
- stack: stack,
32452
- });
32646
+ targetCollectionDefinition.matchUpCount = matchUpCount;
32647
+ modifications.push({ collectionId: collectionId, matchUpCount: matchUpCount });
32453
32648
  }
32454
32649
  if (matchUpType && sourceCollectionDefinition.matchUpType !== matchUpType) {
32650
+ // TODO: updateTieFormat needs to support
32455
32651
  // targetCollectionDefinition.matchUpType = matchUpType;
32456
32652
  // modifications.push({ collectionId, matchUpType });
32457
32653
  return decorateResult({
@@ -32469,8 +32665,8 @@ function modifyCollectionDefinition$1(_a) {
32469
32665
  targetCollectionDefinition.gender = gender;
32470
32666
  modifications.push({ collectionId: collectionId, gender: gender });
32471
32667
  }
32472
- var prunedTieFormat = definedAttributes(tieFormat);
32473
- result = validateTieFormat({ tieFormat: prunedTieFormat });
32668
+ var modifiedTieFormat = definedAttributes(tieFormat);
32669
+ result = validateTieFormat({ tieFormat: modifiedTieFormat });
32474
32670
  if (result.error) {
32475
32671
  return decorateResult({ result: result, stack: stack });
32476
32672
  }
@@ -32482,15 +32678,15 @@ function modifyCollectionDefinition$1(_a) {
32482
32678
  var changedTieFormatName = (existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.tieFormatName) !== tieFormatName;
32483
32679
  // if tieFormat has changed, force renaming of the tieFormat
32484
32680
  if (changedTieFormatName) {
32485
- prunedTieFormat.tieFormatName = tieFormatName;
32681
+ modifiedTieFormat.tieFormatName = tieFormatName;
32486
32682
  modifications.push({ tieFormatName: tieFormatName });
32487
32683
  }
32488
32684
  else if (modifications.length) {
32489
- delete prunedTieFormat.tieFormatName;
32685
+ delete modifiedTieFormat.tieFormatName;
32490
32686
  modifications.push('tieFormatName removed: modifications without new tieFormatName');
32491
32687
  }
32492
32688
  result = updateTieFormat({
32493
- tieFormat: prunedTieFormat,
32689
+ tieFormat: modifiedTieFormat,
32494
32690
  updateInProgressMatchUps: updateInProgressMatchUps,
32495
32691
  tournamentRecord: tournamentRecord,
32496
32692
  drawDefinition: drawDefinition,
@@ -32745,8 +32941,8 @@ function orderCollectionDefinitions(params) {
32745
32941
  // all child matchUps need to be checked for collectionAssignments which need to be removed when collectionDefinition.collectionIds are removed
32746
32942
  function removeCollectionDefinition$1(_a) {
32747
32943
  var e_1, _b, e_2, _c, e_3, _d;
32748
- var _e, _f, _g, _h, _j, _k, _l, _m, _o;
32749
- var _p = _a.updateInProgressMatchUps, updateInProgressMatchUps = _p === void 0 ? true : _p, tieFormatComparison = _a.tieFormatComparison, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, tieFormatName = _a.tieFormatName, collectionId = _a.collectionId, structureId = _a.structureId, matchUpId = _a.matchUpId, eventId = _a.eventId, matchUp = _a.matchUp, event = _a.event;
32944
+ var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
32945
+ var _s = _a.updateInProgressMatchUps, updateInProgressMatchUps = _s === void 0 ? true : _s, tieFormatComparison = _a.tieFormatComparison, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, tieFormatName = _a.tieFormatName, collectionId = _a.collectionId, structureId = _a.structureId, matchUpId = _a.matchUpId, eventId = _a.eventId, matchUp = _a.matchUp, event = _a.event;
32750
32946
  var stack = 'removeCollectionDefinition';
32751
32947
  var result = !matchUp
32752
32948
  ? getTieFormat$1({
@@ -32784,7 +32980,7 @@ function removeCollectionDefinition$1(_a) {
32784
32980
  }
32785
32981
  // calculate new winCriteria for tieFormat
32786
32982
  // if existing winCriteria is aggregateValue, retain
32787
- var _q = calculateWinCriteria(tieFormat), aggregateValue = _q.aggregateValue, valueGoal = _q.valueGoal;
32983
+ var _t = calculateWinCriteria(tieFormat), aggregateValue = _t.aggregateValue, valueGoal = _t.valueGoal;
32788
32984
  tieFormat.winCriteria = definedAttributes({ aggregateValue: aggregateValue, valueGoal: valueGoal });
32789
32985
  // if valueGoal has changed, force renaming of the tieFormat
32790
32986
  var originalValueGoal = existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.winCriteria.valueGoal;
@@ -32805,24 +33001,24 @@ function removeCollectionDefinition$1(_a) {
32805
33001
  }
32806
33002
  else if (structureId && structure) {
32807
33003
  matchUps =
32808
- ((_f = getAllStructureMatchUps({
33004
+ (_g = (_f = getAllStructureMatchUps({
32809
33005
  matchUpFilters: { matchUpTypes: [TEAM$2] },
32810
33006
  structure: structure,
32811
- })) === null || _f === void 0 ? void 0 : _f.matchUps) || [];
33007
+ })) === null || _f === void 0 ? void 0 : _f.matchUps) !== null && _g !== void 0 ? _g : [];
32812
33008
  }
32813
33009
  else if (drawDefinition) {
32814
33010
  matchUps =
32815
- ((_g = allDrawMatchUps$1({
33011
+ (_j = (_h = allDrawMatchUps$1({
32816
33012
  matchUpFilters: { matchUpTypes: [TEAM$2] },
32817
33013
  drawDefinition: drawDefinition,
32818
- })) === null || _g === void 0 ? void 0 : _g.matchUps) || [];
33014
+ })) === null || _h === void 0 ? void 0 : _h.matchUps) !== null && _j !== void 0 ? _j : [];
32819
33015
  }
32820
33016
  else if (event) {
32821
33017
  matchUps =
32822
- ((_h = allEventMatchUps({
33018
+ (_l = (_k = allEventMatchUps({
32823
33019
  matchUpFilters: { matchUpTypes: [TEAM$2] },
32824
33020
  drawDefinition: drawDefinition,
32825
- })) === null || _h === void 0 ? void 0 : _h.matchUps) || [];
33021
+ })) === null || _k === void 0 ? void 0 : _k.matchUps) !== null && _l !== void 0 ? _l : [];
32826
33022
  }
32827
33023
  // all team matchUps in scope which are completed or which have a score should not be modified
32828
33024
  // UNLESS all collectionMatchUps have no score
@@ -32848,10 +33044,10 @@ function removeCollectionDefinition$1(_a) {
32848
33044
  return { error: NO_MODIFICATIONS_APPLIED };
32849
33045
  }
32850
33046
  if (matchUpId && matchUp && updateInProgressMatchUps) {
32851
- var collectionMatchUps = (_j = matchUp.tieMatchUps) === null || _j === void 0 ? void 0 : _j.filter(function (tieMatchUp) { return tieMatchUp.collectionId === collectionId; });
33047
+ var collectionMatchUps = (_m = matchUp.tieMatchUps) === null || _m === void 0 ? void 0 : _m.filter(function (tieMatchUp) { return tieMatchUp.collectionId === collectionId; });
32852
33048
  try {
32853
- for (var _r = __values(collectionMatchUps !== null && collectionMatchUps !== void 0 ? collectionMatchUps : []), _s = _r.next(); !_s.done; _s = _r.next()) {
32854
- var collectionMatchUp = _s.value;
33049
+ for (var _u = __values(collectionMatchUps !== null && collectionMatchUps !== void 0 ? collectionMatchUps : []), _v = _u.next(); !_v.done; _v = _u.next()) {
33050
+ var collectionMatchUp = _v.value;
32855
33051
  var result_1 = setMatchUpStatus$2({
32856
33052
  matchUpId: collectionMatchUp.matchUpId,
32857
33053
  tieMatchUpId: matchUp === null || matchUp === void 0 ? void 0 : matchUp.matchUpId,
@@ -32875,7 +33071,7 @@ function removeCollectionDefinition$1(_a) {
32875
33071
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
32876
33072
  finally {
32877
33073
  try {
32878
- if (_s && !_s.done && (_b = _r.return)) _b.call(_r);
33074
+ if (_v && !_v.done && (_b = _u.return)) _b.call(_u);
32879
33075
  }
32880
33076
  finally { if (e_1) throw e_1.error; }
32881
33077
  }
@@ -32886,9 +33082,9 @@ function removeCollectionDefinition$1(_a) {
32886
33082
  var matchUp_1 = targetMatchUps_1_1.value;
32887
33083
  try {
32888
33084
  // remove any collectionAssignments from LineUps that include collectionId
32889
- for (var _t = (e_3 = void 0, __values((_k = matchUp_1 === null || matchUp_1 === void 0 ? void 0 : matchUp_1.sides) !== null && _k !== void 0 ? _k : [])), _u = _t.next(); !_u.done; _u = _t.next()) {
32890
- var side = _u.value;
32891
- side.lineUp = ((_l = side.lineUp) !== null && _l !== void 0 ? _l : []).map(function (assignment) {
33085
+ for (var _w = (e_3 = void 0, __values((_o = matchUp_1 === null || matchUp_1 === void 0 ? void 0 : matchUp_1.sides) !== null && _o !== void 0 ? _o : [])), _x = _w.next(); !_x.done; _x = _w.next()) {
33086
+ var side = _x.value;
33087
+ side.lineUp = ((_p = side.lineUp) !== null && _p !== void 0 ? _p : []).map(function (assignment) {
32892
33088
  var _a;
32893
33089
  return ({
32894
33090
  participantId: assignment.participantId,
@@ -32902,12 +33098,12 @@ function removeCollectionDefinition$1(_a) {
32902
33098
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
32903
33099
  finally {
32904
33100
  try {
32905
- if (_u && !_u.done && (_d = _t.return)) _d.call(_t);
33101
+ if (_x && !_x.done && (_d = _w.return)) _d.call(_w);
32906
33102
  }
32907
33103
  finally { if (e_3) throw e_3.error; }
32908
33104
  }
32909
33105
  // delete any tieMatchUps that contain collectionId
32910
- matchUp_1.tieMatchUps = ((_m = matchUp_1.tieMatchUps) !== null && _m !== void 0 ? _m : []).filter(function (matchUp) {
33106
+ matchUp_1.tieMatchUps = ((_q = matchUp_1.tieMatchUps) !== null && _q !== void 0 ? _q : []).filter(function (matchUp) {
32911
33107
  var deleteTarget = matchUp.collectionId === collectionId;
32912
33108
  if (deleteTarget)
32913
33109
  deletedMatchUpIds.push(matchUp.matchUpId);
@@ -32976,7 +33172,7 @@ function removeCollectionDefinition$1(_a) {
32976
33172
  }
32977
33173
  modifyDrawNotice({ drawDefinition: drawDefinition, eventId: event === null || event === void 0 ? void 0 : event.eventId });
32978
33174
  var appliedPolicies = getAppliedPolicies({ tournamentRecord: tournamentRecord }).appliedPolicies;
32979
- if ((_o = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.audit) === null || _o === void 0 ? void 0 : _o[TIE_FORMAT_MODIFICATIONS]) {
33175
+ if ((_r = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.audit) === null || _r === void 0 ? void 0 : _r[TIE_FORMAT_MODIFICATIONS]) {
32980
33176
  var auditData = definedAttributes({
32981
33177
  drawId: drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.drawId,
32982
33178
  action: stack,
@@ -32994,41 +33190,11 @@ function removeCollectionDefinition(params) {
32994
33190
  return resolveTournamentRecord(__assign(__assign({}, params), { method: removeCollectionDefinition$1 }));
32995
33191
  }
32996
33192
 
32997
- function generateTieMatchUps(_a) {
32998
- var tieFormat = _a.tieFormat, isMock = _a.isMock, uuids = _a.uuids;
32999
- var collectionDefinitions = (tieFormat || {}).collectionDefinitions;
33000
- var tieMatchUps = (collectionDefinitions || [])
33001
- .map(function (collectionDefinition) {
33002
- return generateCollectionMatchUps({ collectionDefinition: collectionDefinition, uuids: uuids, isMock: isMock });
33003
- })
33004
- .filter(Boolean)
33005
- .flat();
33006
- return { tieMatchUps: tieMatchUps };
33007
- }
33008
- function generateCollectionMatchUps(_a) {
33009
- var collectionDefinition = _a.collectionDefinition, matchUpsLimit = _a.matchUpsLimit, // internal use allows generation of missing matchUps on "reset"
33010
- isMock = _a.isMock, uuids = _a.uuids;
33011
- var _b = collectionDefinition || {}, matchUpCount = _b.matchUpCount, matchUpType = _b.matchUpType, collectionId = _b.collectionId, processCodes = _b.processCodes;
33012
- var numberToGenerate = matchUpsLimit || matchUpCount || 0;
33013
- return generateRange(0, numberToGenerate).map(function (index) {
33014
- var collectionPosition = index + 1;
33015
- return {
33016
- sides: [{ sideNumber: 1 }, { sideNumber: 2 }],
33017
- matchUpId: (uuids === null || uuids === void 0 ? void 0 : uuids.pop()) || UUID(),
33018
- matchUpStatus: MatchUpStatusEnum.ToBePlayed,
33019
- collectionPosition: collectionPosition,
33020
- collectionId: collectionId,
33021
- processCodes: processCodes,
33022
- matchUpType: matchUpType,
33023
- isMock: isMock,
33024
- };
33025
- });
33026
- }
33027
-
33028
33193
  function addCollectionDefinition$1(_a) {
33029
33194
  var e_1, _b, e_2, _c, _d, e_3, _e;
33030
- var _f, _g, _h, _j, _k, _l, _m;
33031
- 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;
33195
+ var _f, _g, _h, _j, _k, _l, _m, _o;
33196
+ var _p = _a.updateInProgressMatchUps, updateInProgressMatchUps = _p === void 0 ? true : _p, 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;
33197
+ var stack = 'addCollectionDefinition';
33032
33198
  var appliedPolicies = (_f = getAppliedPolicies({
33033
33199
  tournamentRecord: tournamentRecord,
33034
33200
  drawDefinition: drawDefinition,
@@ -33037,16 +33203,16 @@ function addCollectionDefinition$1(_a) {
33037
33203
  enforceGender =
33038
33204
  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;
33039
33205
  var checkGender = !!(enforceGender !== false && (event === null || event === void 0 ? void 0 : event.gender));
33040
- var _p = validateCollectionDefinition({
33206
+ var _q = validateCollectionDefinition({
33041
33207
  collectionDefinition: collectionDefinition,
33042
33208
  referenceGender: referenceGender,
33043
33209
  checkGender: checkGender,
33044
33210
  event: event,
33045
- }), valid = _p.valid, errors = _p.errors;
33046
- if (!valid)
33047
- return { error: INVALID_VALUES, errors: errors };
33048
- var stack = 'addCollectionDefinition';
33049
- var result = !matchUp
33211
+ }), valid = _q.valid, errors = _q.errors;
33212
+ if (!valid) {
33213
+ return decorateResult({ result: { error: INVALID_VALUES, errors: errors }, stack: stack });
33214
+ }
33215
+ var result = !(matchUp === null || matchUp === void 0 ? void 0 : matchUp.tieFormat)
33050
33216
  ? getTieFormat$1({
33051
33217
  drawDefinition: drawDefinition,
33052
33218
  structureId: structureId,
@@ -33056,14 +33222,15 @@ function addCollectionDefinition$1(_a) {
33056
33222
  })
33057
33223
  : undefined;
33058
33224
  if (result === null || result === void 0 ? void 0 : result.error)
33059
- return { error: result.error };
33225
+ return decorateResult({ result: { error: result.error }, stack: stack });
33060
33226
  var structure = result === null || result === void 0 ? void 0 : result.structure;
33061
33227
  matchUp = matchUp !== null && matchUp !== void 0 ? matchUp : result === null || result === void 0 ? void 0 : result.matchUp;
33062
- var existingTieFormat = result === null || result === void 0 ? void 0 : result.tieFormat;
33228
+ var existingTieFormat = (_j = matchUp === null || matchUp === void 0 ? void 0 : matchUp.tieFormat) !== null && _j !== void 0 ? _j : result === null || result === void 0 ? void 0 : result.tieFormat;
33063
33229
  var tieFormat = copyTieFormat(existingTieFormat);
33064
33230
  result = validateTieFormat({ tieFormat: tieFormat });
33065
- if (result === null || result === void 0 ? void 0 : result.error)
33066
- return { error: result.error };
33231
+ if (result === null || result === void 0 ? void 0 : result.error) {
33232
+ return decorateResult({ result: { error: result.error }, stack: stack });
33233
+ }
33067
33234
  if (!collectionDefinition.collectionId) {
33068
33235
  collectionDefinition.collectionId = UUID();
33069
33236
  }
@@ -33086,7 +33253,7 @@ function addCollectionDefinition$1(_a) {
33086
33253
  });
33087
33254
  // calculate new winCriteria for tieFormat
33088
33255
  // if existing winCriteria is aggregateValue, retain
33089
- var _q = calculateWinCriteria(tieFormat), aggregateValue = _q.aggregateValue, valueGoal = _q.valueGoal;
33256
+ var _r = calculateWinCriteria(tieFormat), aggregateValue = _r.aggregateValue, valueGoal = _r.valueGoal;
33090
33257
  tieFormat.winCriteria = definedAttributes({ aggregateValue: aggregateValue, valueGoal: valueGoal });
33091
33258
  // if valueGoal has changed, force renaming of the tieFormat
33092
33259
  var originalValueGoal = existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.winCriteria.valueGoal;
@@ -33105,19 +33272,20 @@ function addCollectionDefinition$1(_a) {
33105
33272
  var targetMatchUps = [];
33106
33273
  var prunedTieFormat = definedAttributes(tieFormat);
33107
33274
  result = validateTieFormat({ tieFormat: prunedTieFormat });
33108
- if (result === null || result === void 0 ? void 0 : result.error)
33109
- return { error: result.error };
33275
+ if (result === null || result === void 0 ? void 0 : result.error) {
33276
+ return decorateResult({ result: { error: result.error }, stack: stack });
33277
+ }
33110
33278
  if (eventId && event) {
33111
33279
  event.tieFormat = prunedTieFormat;
33112
33280
  try {
33113
33281
  // all team matchUps in the event which do not have tieFormats and where draws/strucures do not have tieFormats should have matchUps added
33114
- for (var _r = __values((_j = event.drawDefinitions) !== null && _j !== void 0 ? _j : []), _s = _r.next(); !_s.done; _s = _r.next()) {
33115
- var drawDefinition_1 = _s.value;
33282
+ for (var _s = __values((_k = event.drawDefinitions) !== null && _k !== void 0 ? _k : []), _t = _s.next(); !_t.done; _t = _s.next()) {
33283
+ var drawDefinition_1 = _t.value;
33116
33284
  if (drawDefinition_1.tieFormat)
33117
33285
  continue;
33118
33286
  try {
33119
- 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()) {
33120
- var structure_1 = _u.value;
33287
+ for (var _u = (e_2 = void 0, __values((_l = drawDefinition_1.structures) !== null && _l !== void 0 ? _l : [])), _v = _u.next(); !_v.done; _v = _u.next()) {
33288
+ var structure_1 = _v.value;
33121
33289
  if (structure_1.tieFormat)
33122
33290
  continue;
33123
33291
  var result_1 = updateStructureMatchUps({
@@ -33134,7 +33302,7 @@ function addCollectionDefinition$1(_a) {
33134
33302
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
33135
33303
  finally {
33136
33304
  try {
33137
- if (_u && !_u.done && (_c = _t.return)) _c.call(_t);
33305
+ if (_v && !_v.done && (_c = _u.return)) _c.call(_u);
33138
33306
  }
33139
33307
  finally { if (e_2) throw e_2.error; }
33140
33308
  }
@@ -33143,7 +33311,7 @@ function addCollectionDefinition$1(_a) {
33143
33311
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
33144
33312
  finally {
33145
33313
  try {
33146
- if (_s && !_s.done && (_b = _r.return)) _b.call(_r);
33314
+ if (_t && !_t.done && (_b = _s.return)) _b.call(_s);
33147
33315
  }
33148
33316
  finally { if (e_1) throw e_1.error; }
33149
33317
  }
@@ -33206,15 +33374,15 @@ function addCollectionDefinition$1(_a) {
33206
33374
  // all team matchUps in the drawDefinition which do not have tieFormats and where strucures do not have tieFormats should have matchUps added
33207
33375
  drawDefinition.tieFormat = prunedTieFormat;
33208
33376
  try {
33209
- for (var _v = __values((_l = drawDefinition.structures) !== null && _l !== void 0 ? _l : []), _w = _v.next(); !_w.done; _w = _v.next()) {
33210
- var structure_2 = _w.value;
33377
+ for (var _w = __values((_m = drawDefinition.structures) !== null && _m !== void 0 ? _m : []), _x = _w.next(); !_x.done; _x = _w.next()) {
33378
+ var structure_2 = _x.value;
33211
33379
  var result_3 = updateStructureMatchUps({
33212
33380
  updateInProgressMatchUps: updateInProgressMatchUps,
33213
33381
  collectionDefinition: collectionDefinition,
33214
33382
  structure: structure_2,
33215
33383
  uuids: uuids,
33216
33384
  });
33217
- modifiedStructureIds.push(structureId);
33385
+ modifiedStructureIds.push(structure_2.structureId);
33218
33386
  addedMatchUps.push.apply(addedMatchUps, __spreadArray([], __read(result_3.newMatchUps), false));
33219
33387
  targetMatchUps.push.apply(targetMatchUps, __spreadArray([], __read(result_3.targetMatchUps), false));
33220
33388
  }
@@ -33222,7 +33390,7 @@ function addCollectionDefinition$1(_a) {
33222
33390
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
33223
33391
  finally {
33224
33392
  try {
33225
- if (_w && !_w.done && (_e = _v.return)) _e.call(_v);
33393
+ if (_x && !_x.done && (_e = _w.return)) _e.call(_w);
33226
33394
  }
33227
33395
  finally { if (e_3) throw e_3.error; }
33228
33396
  }
@@ -33238,7 +33406,7 @@ function addCollectionDefinition$1(_a) {
33238
33406
  else {
33239
33407
  return { error: MISSING_DRAW_DEFINITION };
33240
33408
  }
33241
- if ((_m = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.audit) === null || _m === void 0 ? void 0 : _m[TIE_FORMAT_MODIFICATIONS]) {
33409
+ if ((_o = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.audit) === null || _o === void 0 ? void 0 : _o[TIE_FORMAT_MODIFICATIONS]) {
33242
33410
  var auditData = definedAttributes({
33243
33411
  drawId: drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.drawId,
33244
33412
  collectionDefinition: collectionDefinition,
@@ -33314,122 +33482,6 @@ function addCollectionDefinition(params) {
33314
33482
  return resolveTournamentRecord(__assign(__assign({}, params), { method: addCollectionDefinition$1 }));
33315
33483
  }
33316
33484
 
33317
- function publicFindMatchUp(params) {
33318
- Object.assign(params, { inContext: true });
33319
- var _a = findMatchUp(params), matchUp = _a.matchUp, error = _a.error;
33320
- return { matchUp: makeDeepCopy(matchUp, true, true), error: error };
33321
- }
33322
- function findMatchUp(_a) {
33323
- var _b;
33324
- var participantsProfile = _a.participantsProfile, afterRecoveryTimes = _a.afterRecoveryTimes, tournamentRecord = _a.tournamentRecord, contextContent = _a.contextContent, contextProfile = _a.contextProfile, drawDefinition = _a.drawDefinition, matchUpId = _a.matchUpId, inContext = _a.inContext, eventId = _a.eventId, drawId = _a.drawId, event = _a.event;
33325
- if (!tournamentRecord)
33326
- return { error: MISSING_TOURNAMENT_RECORD };
33327
- if (typeof matchUpId !== 'string')
33328
- return { error: MISSING_MATCHUP_ID };
33329
- if (!drawDefinition || !event) {
33330
- var matchUps = allTournamentMatchUps({ tournamentRecord: tournamentRecord }).matchUps || [];
33331
- var inContextMatchUp = matchUps.find(function (matchUp) { return matchUp.matchUpId === matchUpId; });
33332
- if (!inContextMatchUp)
33333
- return { error: MATCHUP_NOT_FOUND };
33334
- // since drawEngineFindMatchUp is being used, additional context needs to be provided
33335
- (eventId = inContextMatchUp.eventId, drawId = inContextMatchUp.drawId);
33336
- (_b = findEvent({
33337
- tournamentRecord: tournamentRecord,
33338
- eventId: eventId,
33339
- drawId: drawId,
33340
- }), event = _b.event, drawDefinition = _b.drawDefinition);
33341
- }
33342
- if (!drawDefinition)
33343
- return { error: DRAW_DEFINITION_NOT_FOUND };
33344
- if (contextProfile && !contextContent)
33345
- contextContent = getContextContent({ tournamentRecord: tournamentRecord, contextProfile: contextProfile });
33346
- var additionalContext = {
33347
- surfaceCategory: (event === null || event === void 0 ? void 0 : event.surfaceCategory) || tournamentRecord.surfaceCategory,
33348
- indoorOutDoor: (event === null || event === void 0 ? void 0 : event.indoorOutdoor) || tournamentRecord.indoorOutdoor,
33349
- endDate: (event === null || event === void 0 ? void 0 : event.endDate) || tournamentRecord.endDate,
33350
- tournamentId: tournamentRecord.tournamentId,
33351
- eventId: eventId || (event === null || event === void 0 ? void 0 : event.eventId),
33352
- drawId: drawId,
33353
- };
33354
- var _c = hydrateParticipants({
33355
- participantsProfile: participantsProfile,
33356
- tournamentRecord: tournamentRecord,
33357
- contextProfile: contextProfile,
33358
- inContext: inContext,
33359
- }).participants, tournamentParticipants = _c === void 0 ? [] : _c;
33360
- var _d = findMatchUp$1({
33361
- context: inContext ? additionalContext : undefined,
33362
- tournamentParticipants: tournamentParticipants,
33363
- afterRecoveryTimes: afterRecoveryTimes,
33364
- contextContent: contextContent,
33365
- drawDefinition: drawDefinition,
33366
- contextProfile: contextProfile,
33367
- matchUpId: matchUpId,
33368
- inContext: inContext,
33369
- event: event,
33370
- }), matchUp = _d.matchUp, structure = _d.structure;
33371
- return { matchUp: matchUp, structure: structure, drawDefinition: drawDefinition };
33372
- }
33373
-
33374
- function getTieFormat(_a) {
33375
- var _b, _c, _d, _e, _f;
33376
- var tournamentRecord = _a.tournamentRecord, // passed in automatically by tournamentEngine
33377
- drawDefinition = _a.drawDefinition, // passed in automatically by tournamentEngine when drawId provided
33378
- structureId = _a.structureId, // optional - if only the default matchUpFormat for a structure is required
33379
- matchUpId = _a.matchUpId, // id of matchUp for which the scoped matchUpFormat(s) are desired
33380
- structure = _a.structure, // optional optimization - when structure already known
33381
- eventId = _a.eventId, // optional - if only the default matchUpFormat for an event is required
33382
- drawId = _a.drawId, // avoid brute force search for matchUp
33383
- event = _a.event;
33384
- if (!tournamentRecord)
33385
- return { error: MISSING_TOURNAMENT_RECORD };
33386
- if (!drawId && !event && !structureId && !matchUpId)
33387
- return decorateResult({
33388
- result: { error: MISSING_VALUE },
33389
- stack: 'getTieFormat',
33390
- });
33391
- if (eventId && !event) {
33392
- event = (_b = tournamentRecord.events) === null || _b === void 0 ? void 0 : _b.find(function (event) { return event.eventId === eventId; });
33393
- }
33394
- var matchUpResult = findMatchUp({
33395
- tournamentRecord: tournamentRecord,
33396
- drawDefinition: drawDefinition,
33397
- matchUpId: matchUpId,
33398
- drawId: drawId,
33399
- event: event,
33400
- });
33401
- if (matchUpId && (matchUpResult === null || matchUpResult === void 0 ? void 0 : matchUpResult.error)) {
33402
- return matchUpResult;
33403
- }
33404
- else if (!drawDefinition && (matchUpResult === null || matchUpResult === void 0 ? void 0 : matchUpResult.drawDefinition)) {
33405
- drawDefinition = matchUpResult === null || matchUpResult === void 0 ? void 0 : matchUpResult.drawDefinition;
33406
- }
33407
- structure = structure !== null && structure !== void 0 ? structure : matchUpResult === null || matchUpResult === void 0 ? void 0 : matchUpResult.structure;
33408
- if (!structure && structureId && !matchUpId) {
33409
- if (!drawDefinition)
33410
- return { error: MISSING_DRAW_ID };
33411
- var structureResult = findStructure({ drawDefinition: drawDefinition, structureId: structureId });
33412
- if (structureResult.error)
33413
- return structureResult;
33414
- structure = structureResult.structure;
33415
- }
33416
- var structureDefaultTieFormat = ((structure === null || structure === void 0 ? void 0 : structure.tieFormat) || (structure === null || structure === void 0 ? void 0 : structure.tieFormatId)) &&
33417
- ((_c = resolveTieFormat({ structure: structure, drawDefinition: drawDefinition, event: event })) === null || _c === void 0 ? void 0 : _c.tieFormat);
33418
- var drawDefaultTieFormat = ((drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.tieFormat) || (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.tieFormatId)) &&
33419
- ((_d = resolveTieFormat({
33420
- drawDefinition: drawDefinition,
33421
- event: event,
33422
- })) === null || _d === void 0 ? void 0 : _d.tieFormat);
33423
- var eventDefaultTieFormat = (_e = resolveTieFormat({ event: event })) === null || _e === void 0 ? void 0 : _e.tieFormat;
33424
- var tieFormat = (_f = resolveTieFormat({
33425
- matchUp: matchUpResult === null || matchUpResult === void 0 ? void 0 : matchUpResult.matchUp,
33426
- drawDefinition: drawDefinition,
33427
- structure: structure,
33428
- event: event,
33429
- })) === null || _f === void 0 ? void 0 : _f.tieFormat;
33430
- return __assign(__assign({}, SUCCESS), { matchUp: matchUpResult === null || matchUpResult === void 0 ? void 0 : matchUpResult.matchUp, structureDefaultTieFormat: structureDefaultTieFormat, eventDefaultTieFormat: eventDefaultTieFormat, drawDefaultTieFormat: drawDefaultTieFormat, tieFormat: tieFormat, structure: structure });
33431
- }
33432
-
33433
33485
  function updateTargetTeamMatchUps(_a) {
33434
33486
  var e_1, _b;
33435
33487
  var updateInProgressMatchUps = _a.updateInProgressMatchUps, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, targetMatchUps = _a.targetMatchUps, tieFormat = _a.tieFormat, event = _a.event;
@@ -33574,8 +33626,7 @@ function removeCollectionGroup$1(_a) {
33574
33626
  return { error: INVALID_VALUES };
33575
33627
  var stack = 'removeCollectionGroup';
33576
33628
  var result = !matchUp
33577
- ? getTieFormat({
33578
- tournamentRecord: tournamentRecord,
33629
+ ? getTieFormat$1({
33579
33630
  drawDefinition: drawDefinition,
33580
33631
  structureId: structureId,
33581
33632
  matchUpId: matchUpId,
@@ -33682,10 +33733,8 @@ function addCollectionGroup$1(_a) {
33682
33733
  var collectionId = collectionDefinition.collectionId, collectionGroupNumber_1 = collectionDefinition.collectionGroupNumber;
33683
33734
  if (collectionGroupNumber_1 && collectionIds.includes(collectionId))
33684
33735
  return decorateResult({
33685
- result: {
33686
- error: INVALID_VALUES,
33687
- info: 'collectionIds cannot be part of other collectionGroups',
33688
- },
33736
+ info: 'collectionIds cannot be part of other collectionGroups',
33737
+ result: { error: INVALID_VALUES },
33689
33738
  stack: stack,
33690
33739
  });
33691
33740
  // TODO: calculate the total value of the collectionDefinition
@@ -33737,11 +33786,15 @@ function addCollectionGroup(params) {
33737
33786
 
33738
33787
  function modifyTieFormat$1(_a) {
33739
33788
  var e_1, _b, e_2, _c, e_3, _d;
33740
- var _e;
33741
- var _f = _a.updateInProgressMatchUps, updateInProgressMatchUps = _f === void 0 ? false : _f, tieFormatComparison = _a.tieFormatComparison, modifiedTieFormat = _a.modifiedTieFormat, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, structureId = _a.structureId, matchUpId = _a.matchUpId, eventId = _a.eventId, uuids = _a.uuids, event = _a.event;
33742
- var stack = 'updateTieFormat';
33743
- if (!validateTieFormat(modifiedTieFormat))
33744
- return { error: INVALID_TIE_FORMAT };
33789
+ var _e = _a.updateInProgressMatchUps, updateInProgressMatchUps = _e === void 0 ? false : _e, tieFormatComparison = _a.tieFormatComparison, modifiedTieFormat = _a.modifiedTieFormat, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, structureId = _a.structureId, matchUpId = _a.matchUpId, eventId = _a.eventId, uuids = _a.uuids, event = _a.event;
33790
+ var stack = 'modifyTieFormat';
33791
+ if (!validateTieFormat({ tieFormat: modifiedTieFormat }).valid) {
33792
+ return decorateResult({
33793
+ result: { error: INVALID_TIE_FORMAT },
33794
+ info: 'falied validation',
33795
+ stack: stack,
33796
+ });
33797
+ }
33745
33798
  var result = getTieFormat$1({
33746
33799
  drawDefinition: drawDefinition,
33747
33800
  structureId: structureId,
@@ -33753,8 +33806,23 @@ function modifyTieFormat$1(_a) {
33753
33806
  return decorateResult({ result: result, stack: stack });
33754
33807
  var matchUp = result.matchUp, existingTieFormat = result.tieFormat;
33755
33808
  var tieFormat = copyTieFormat(existingTieFormat);
33756
- if (!((_e = compareTieFormats({ ancestor: tieFormat, descendant: modifiedTieFormat })) === null || _e === void 0 ? void 0 : _e.different)) {
33757
- return __assign({}, SUCCESS);
33809
+ var comparison = compareTieFormats({
33810
+ descendant: modifiedTieFormat,
33811
+ ancestor: tieFormat,
33812
+ });
33813
+ if (comparison.invalid) {
33814
+ return decorateResult({
33815
+ context: { invalid: comparison.invalid },
33816
+ result: { error: INVALID_TIE_FORMAT },
33817
+ stack: stack,
33818
+ });
33819
+ }
33820
+ if (!(comparison === null || comparison === void 0 ? void 0 : comparison.different)) {
33821
+ return decorateResult({
33822
+ result: __assign({}, SUCCESS),
33823
+ info: 'Nothing to do',
33824
+ stack: stack,
33825
+ });
33758
33826
  }
33759
33827
  var existingCollectionIds = tieFormat.collectionDefinitions.map(function (_a) {
33760
33828
  var collectionId = _a.collectionId;
@@ -33769,14 +33837,17 @@ function modifyTieFormat$1(_a) {
33769
33837
  var collectionId = _a.collectionId;
33770
33838
  return !existingCollectionIds.includes(collectionId);
33771
33839
  });
33840
+ var addedCollectionIds = addedCollectionDefinitions.map(extractAttributes('collectionId'));
33772
33841
  var modifications = [];
33773
33842
  var processedTieFormat;
33843
+ var tieFormatName = modifiedTieFormat.tieFormatName;
33774
33844
  try {
33775
- // TODO: if matchUpCount is changing pre-check for cmopleted tieMatchUps
33776
33845
  // TODO: if gender is changing pre-check for misgendered collectionAssignments
33777
- for (var _g = __values(modifiedTieFormat.collectionDefinitions), _h = _g.next(); !_h.done; _h = _g.next()) {
33778
- var collectionDefinition = _h.value;
33779
- var result_1 = modifyCollectionDefinition$1(__assign(__assign({ updateInProgressMatchUps: updateInProgressMatchUps }, collectionDefinition), { tournamentRecord: tournamentRecord, drawDefinition: drawDefinition, structureId: structureId, matchUpId: matchUpId, eventId: eventId, event: event }));
33846
+ for (var _f = __values(modifiedTieFormat.collectionDefinitions), _g = _f.next(); !_g.done; _g = _f.next()) {
33847
+ var collectionDefinition = _g.value;
33848
+ if (addedCollectionIds.includes(collectionDefinition.collectionId))
33849
+ continue;
33850
+ var result_1 = modifyCollectionDefinition$1(__assign(__assign({ updateInProgressMatchUps: updateInProgressMatchUps }, collectionDefinition), { tournamentRecord: tournamentRecord, tieFormatName: tieFormatName, drawDefinition: drawDefinition, structureId: structureId, matchUpId: matchUpId, eventId: eventId, event: event }));
33780
33851
  if (result_1.modifications)
33781
33852
  modifications.push.apply(modifications, __spreadArray([], __read(result_1.modifications), false));
33782
33853
  if (result_1.error)
@@ -33788,11 +33859,10 @@ function modifyTieFormat$1(_a) {
33788
33859
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
33789
33860
  finally {
33790
33861
  try {
33791
- if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
33862
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
33792
33863
  }
33793
33864
  finally { if (e_1) throw e_1.error; }
33794
33865
  }
33795
- var tieFormatName = modifiedTieFormat.tieFormatName;
33796
33866
  try {
33797
33867
  for (var addedCollectionDefinitions_1 = __values(addedCollectionDefinitions), addedCollectionDefinitions_1_1 = addedCollectionDefinitions_1.next(); !addedCollectionDefinitions_1_1.done; addedCollectionDefinitions_1_1 = addedCollectionDefinitions_1.next()) {
33798
33868
  var collectionDefinition = addedCollectionDefinitions_1_1.value;
@@ -33857,7 +33927,9 @@ function modifyTieFormat$1(_a) {
33857
33927
  processedTieFormat.tieFormatName = tieFormatName;
33858
33928
  modifications.push({ tieFormatName: tieFormatName });
33859
33929
  }
33860
- else if (modifications.length) {
33930
+ else if (modifications.length ||
33931
+ addedCollectionIds.length ||
33932
+ removedCollectionIds.length) {
33861
33933
  delete processedTieFormat.tieFormatName;
33862
33934
  modifications.push('tieFormatName removed: modifications without new tieFormatName');
33863
33935
  }
@@ -33868,13 +33940,71 @@ function modifyTieFormat$1(_a) {
33868
33940
  numericSortValue(b.collectionOrder);
33869
33941
  })
33870
33942
  .map(function (def, i) { return (__assign(__assign({}, def), { collectionOrder: i + 1 })); });
33871
- return __assign(__assign({}, SUCCESS), { processedTieFormat: processedTieFormat, modifications: modifications });
33943
+ return __assign({ processedTieFormat: copyTieFormat(processedTieFormat), modifications: modifications }, SUCCESS);
33872
33944
  }
33873
33945
 
33874
33946
  function modifyTieFormat(params) {
33875
33947
  return resolveTournamentRecord(__assign(__assign({}, params), { method: modifyTieFormat$1 }));
33876
33948
  }
33877
33949
 
33950
+ function publicFindMatchUp(params) {
33951
+ Object.assign(params, { inContext: true });
33952
+ var _a = findMatchUp(params), matchUp = _a.matchUp, error = _a.error;
33953
+ return { matchUp: makeDeepCopy(matchUp, true, true), error: error };
33954
+ }
33955
+ function findMatchUp(_a) {
33956
+ var _b;
33957
+ var _c, _d, _e, _f;
33958
+ var participantsProfile = _a.participantsProfile, afterRecoveryTimes = _a.afterRecoveryTimes, tournamentRecord = _a.tournamentRecord, contextContent = _a.contextContent, contextProfile = _a.contextProfile, drawDefinition = _a.drawDefinition, matchUpId = _a.matchUpId, inContext = _a.inContext, eventId = _a.eventId, drawId = _a.drawId, event = _a.event;
33959
+ if (!tournamentRecord)
33960
+ return { error: MISSING_TOURNAMENT_RECORD };
33961
+ if (typeof matchUpId !== 'string')
33962
+ return { error: MISSING_MATCHUP_ID };
33963
+ if (!drawDefinition || !event) {
33964
+ var matchUps = (_c = allTournamentMatchUps({ tournamentRecord: tournamentRecord }).matchUps) !== null && _c !== void 0 ? _c : [];
33965
+ var inContextMatchUp = matchUps.find(function (matchUp) { return matchUp.matchUpId === matchUpId; });
33966
+ if (!inContextMatchUp)
33967
+ return { error: MATCHUP_NOT_FOUND };
33968
+ // since drawEngineFindMatchUp is being used, additional context needs to be provided
33969
+ (eventId = inContextMatchUp.eventId, drawId = inContextMatchUp.drawId);
33970
+ (_b = findEvent({
33971
+ tournamentRecord: tournamentRecord,
33972
+ eventId: eventId,
33973
+ drawId: drawId,
33974
+ }), event = _b.event, drawDefinition = _b.drawDefinition);
33975
+ }
33976
+ if (!drawDefinition)
33977
+ return { error: DRAW_DEFINITION_NOT_FOUND };
33978
+ if (contextProfile && !contextContent)
33979
+ contextContent = getContextContent({ tournamentRecord: tournamentRecord, contextProfile: contextProfile });
33980
+ var additionalContext = {
33981
+ surfaceCategory: (_d = event === null || event === void 0 ? void 0 : event.surfaceCategory) !== null && _d !== void 0 ? _d : tournamentRecord.surfaceCategory,
33982
+ indoorOutDoor: (_e = event === null || event === void 0 ? void 0 : event.indoorOutdoor) !== null && _e !== void 0 ? _e : tournamentRecord.indoorOutdoor,
33983
+ endDate: (_f = event === null || event === void 0 ? void 0 : event.endDate) !== null && _f !== void 0 ? _f : tournamentRecord.endDate,
33984
+ tournamentId: tournamentRecord.tournamentId,
33985
+ eventId: eventId !== null && eventId !== void 0 ? eventId : event === null || event === void 0 ? void 0 : event.eventId,
33986
+ drawId: drawId,
33987
+ };
33988
+ var _g = hydrateParticipants({
33989
+ participantsProfile: participantsProfile,
33990
+ tournamentRecord: tournamentRecord,
33991
+ contextProfile: contextProfile,
33992
+ inContext: inContext,
33993
+ }).participants, tournamentParticipants = _g === void 0 ? [] : _g;
33994
+ var _h = findMatchUp$1({
33995
+ context: inContext ? additionalContext : undefined,
33996
+ tournamentParticipants: tournamentParticipants,
33997
+ afterRecoveryTimes: afterRecoveryTimes,
33998
+ contextContent: contextContent,
33999
+ drawDefinition: drawDefinition,
34000
+ contextProfile: contextProfile,
34001
+ matchUpId: matchUpId,
34002
+ inContext: inContext,
34003
+ event: event,
34004
+ }), matchUp = _h.matchUp, structure = _h.structure;
34005
+ return { matchUp: matchUp, structure: structure, drawDefinition: drawDefinition };
34006
+ }
34007
+
33878
34008
  function resetTieFormat$1(_a) {
33879
34009
  var e_1, _b, e_2, _c;
33880
34010
  var _d;
@@ -46205,17 +46335,14 @@ function positionByes(_a) {
46205
46335
 
46206
46336
  function positionQualifiers(params) {
46207
46337
  var e_1, _a;
46208
- var structure = params.structure, structureId = params.structureId; // participants is being passed in
46209
- if (!structure)
46210
- (structure = findStructure(params).structure);
46211
- if (!structureId)
46212
- (structureId = structure.structureId);
46338
+ var _b;
46339
+ var structure = (_b = params.structure) !== null && _b !== void 0 ? _b : findStructure(params).structure;
46213
46340
  var stack = 'positionQualifiers';
46214
46341
  var qualifierDrawPositions = [];
46215
46342
  if (structure.stage === CONSOLATION) {
46216
46343
  return decorateResult({ result: { error: INVALID_STAGE }, stack: stack });
46217
46344
  }
46218
- var _b = getQualifiersData(params), unplacedRoundQualifierCounts = _b.unplacedRoundQualifierCounts, positionAssignments = _b.positionAssignments, roundDrawPositions = _b.roundDrawPositions;
46345
+ var _c = getQualifiersData(params), unplacedRoundQualifierCounts = _c.unplacedRoundQualifierCounts, positionAssignments = _c.positionAssignments, roundDrawPositions = _c.roundDrawPositions;
46219
46346
  var _loop_1 = function (roundNumber) {
46220
46347
  var unfilledDrawPositions = positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.filter(function (assignment) {
46221
46348
  return (roundDrawPositions[roundNumber].includes(assignment.drawPosition) &&
@@ -46242,8 +46369,8 @@ function positionQualifiers(params) {
46242
46369
  });
46243
46370
  };
46244
46371
  try {
46245
- for (var _c = __values(Object.keys(unplacedRoundQualifierCounts)), _d = _c.next(); !_d.done; _d = _c.next()) {
46246
- var roundNumber = _d.value;
46372
+ for (var _d = __values(Object.keys(unplacedRoundQualifierCounts)), _e = _d.next(); !_e.done; _e = _d.next()) {
46373
+ var roundNumber = _e.value;
46247
46374
  var state_1 = _loop_1(roundNumber);
46248
46375
  if (typeof state_1 === "object")
46249
46376
  return state_1.value;
@@ -46252,7 +46379,7 @@ function positionQualifiers(params) {
46252
46379
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
46253
46380
  finally {
46254
46381
  try {
46255
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
46382
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
46256
46383
  }
46257
46384
  finally { if (e_1) throw e_1.error; }
46258
46385
  }
@@ -46851,7 +46978,7 @@ function generateAndPopulatePlayoffStructures(params) {
46851
46978
  drawDefinition: drawDefinition,
46852
46979
  }).structure;
46853
46980
  if (!structure)
46854
- return decorateResult({ result: { error: STRUCTURE_NOT_FOUND } });
46981
+ return decorateResult({ result: { error: STRUCTURE_NOT_FOUND }, stack: stack });
46855
46982
  if (structure.structureType === CONTAINER || structure.structures) {
46856
46983
  return generateAndPopulateRRplayoffStructures(__assign(__assign(__assign({ sourceStructureId: structure.structureId }, params), availabilityResult), { drawDefinition: drawDefinition }));
46857
46984
  }
@@ -47644,11 +47771,11 @@ function attachStructures$1(_a) {
47644
47771
  var _b;
47645
47772
  var _c, _d, _e;
47646
47773
  var matchUpModifications = _a.matchUpModifications, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, structures = _a.structures, _f = _a.links, links = _f === void 0 ? [] : _f, event = _a.event;
47774
+ var stack = 'attachStructures';
47647
47775
  if (!drawDefinition)
47648
47776
  return { error: MISSING_DRAW_DEFINITION };
47649
47777
  if (!Array.isArray(structures) || !Array.isArray(links))
47650
- return decorateResult({ result: { error: INVALID_VALUES } });
47651
- var stack = 'attachStructures';
47778
+ return decorateResult({ result: { error: INVALID_VALUES }, stack: stack });
47652
47779
  var linkHash = function (link) {
47653
47780
  var _a;
47654
47781
  return [
@@ -48658,7 +48785,9 @@ function positionParticipantAction(params) {
48658
48785
  _b);
48659
48786
  addPositionActionTelemetry({ drawDefinition: drawDefinition, positionAction: positionAction });
48660
48787
  return decorateResult({
48661
- result: __assign(__assign({}, SUCCESS), { context: { removedParticipantId: removedParticipantId }, stack: stack }),
48788
+ context: { removedParticipantId: removedParticipantId },
48789
+ result: __assign({}, SUCCESS),
48790
+ stack: stack,
48662
48791
  });
48663
48792
  }
48664
48793
  }
@@ -49508,8 +49637,8 @@ function addEventEntries(params) {
49508
49637
  (!Array.isArray(extensions) || !extensions.every(isValidExtension))) ||
49509
49638
  (extension && !isValidExtension({ extension: extension }))) {
49510
49639
  return decorateResult({
49511
- result: { error: INVALID_VALUES },
49512
49640
  context: definedAttributes({ extension: extension, extensions: extensions }),
49641
+ result: { error: INVALID_VALUES },
49513
49642
  info: 'Invalid extension(s)',
49514
49643
  stack: stack,
49515
49644
  });
@@ -49634,8 +49763,8 @@ function addEventEntries(params) {
49634
49763
  var invalidParticipantIds = validParticipantIds.length !== participantIds.length;
49635
49764
  if (invalidParticipantIds)
49636
49765
  return decorateResult({
49637
- result: { error: INVALID_PARTICIPANT_IDS },
49638
49766
  context: { misMatchedGender: misMatchedGender, gender: event.gender },
49767
+ result: { error: INVALID_PARTICIPANT_IDS },
49639
49768
  stack: stack,
49640
49769
  });
49641
49770
  if (autoEntryPositions) {
@@ -50721,10 +50850,6 @@ function removeDelegatedOutcome$1(_a) {
50721
50850
  });
50722
50851
  }
50723
50852
 
50724
- function stringSort(a, b) {
50725
- return (a || '').localeCompare(b || '');
50726
- }
50727
-
50728
50853
  function generateCandidate(_a) {
50729
50854
  var _b = _a.maxIterations, maxIterations = _b === void 0 ? 4000 : _b, // cap the processing intensity of the candidate generator
50730
50855
  valueSortedPairings = _a.valueSortedPairings, // pairings sorted by value from low to high
@@ -51372,26 +51497,24 @@ function enableTieAutoCalc$1(_a) {
51372
51497
 
51373
51498
  function setOrderOfFinish$1(_a) {
51374
51499
  var e_1, _b;
51375
- var _c;
51500
+ var _c, _d;
51376
51501
  var drawDefinition = _a.drawDefinition, finishingOrder = _a.finishingOrder;
51377
51502
  if (!drawDefinition)
51378
51503
  return { error: MISSING_DRAW_DEFINITION };
51379
51504
  var stack = 'setOrderOfFinish';
51380
51505
  if (!Array.isArray(finishingOrder))
51381
51506
  return decorateResult({
51382
- result: {
51383
- error: INVALID_VALUES,
51384
- },
51385
51507
  info: mustBeAnArray('finishingOrder'),
51508
+ result: { error: INVALID_VALUES },
51386
51509
  stack: stack,
51387
51510
  });
51388
- var _d = getDrawMatchUps({
51511
+ var _e = getDrawMatchUps({
51389
51512
  inContext: true,
51390
51513
  drawDefinition: drawDefinition,
51391
- }), completedMatchUps = _d.completedMatchUps, matchUpsMap = _d.matchUpsMap;
51392
- var matchUpIds = (completedMatchUps === null || completedMatchUps === void 0 ? void 0 : completedMatchUps.map(getMatchUpId)) || [];
51514
+ }), completedMatchUps = _e.completedMatchUps, matchUpsMap = _e.matchUpsMap;
51515
+ var matchUpIds = (_c = completedMatchUps === null || completedMatchUps === void 0 ? void 0 : completedMatchUps.map(getMatchUpId)) !== null && _c !== void 0 ? _c : [];
51393
51516
  var targetMatchUpIds = finishingOrder.map(getMatchUpId);
51394
- var _e = (completedMatchUps || [])
51517
+ var _f = (completedMatchUps !== null && completedMatchUps !== void 0 ? completedMatchUps : [])
51395
51518
  .filter(function (_a) {
51396
51519
  var matchUpId = _a.matchUpId;
51397
51520
  return targetMatchUpIds.includes(matchUpId);
@@ -51412,17 +51535,15 @@ function setOrderOfFinish$1(_a) {
51412
51535
  roundNumbers: [],
51413
51536
  structureIds: [],
51414
51537
  matchUpTieIds: [],
51415
- }), matchUpTypes = _e.matchUpTypes, roundNumbers = _e.roundNumbers, structureIds = _e.structureIds, matchUpTieIds = _e.matchUpTieIds;
51538
+ }), matchUpTypes = _f.matchUpTypes, roundNumbers = _f.roundNumbers, structureIds = _f.structureIds, matchUpTieIds = _f.matchUpTieIds;
51416
51539
  // targeted matchUps must all be of the same matchUpType and have the same roundNumber and structureId
51417
51540
  if (matchUpTypes.length > 1 ||
51418
51541
  matchUpTieIds.length > 1 ||
51419
51542
  roundNumbers.length > 1 ||
51420
51543
  structureIds.length > 1) {
51421
51544
  return decorateResult({
51422
- result: {
51423
- error: INVALID_VALUES,
51424
- },
51425
51545
  info: 'matchUpType, structureId and roundNumber must be equivalent',
51546
+ result: { error: INVALID_VALUES },
51426
51547
  stack: stack,
51427
51548
  });
51428
51549
  }
@@ -51465,8 +51586,8 @@ function setOrderOfFinish$1(_a) {
51465
51586
  });
51466
51587
  try {
51467
51588
  // throw an error if an existing matchUp has an invalid orderOfFinish value
51468
- for (var _f = __values(otherCohortMatchUps || []), _g = _f.next(); !_g.done; _g = _f.next()) {
51469
- var matchUp = _g.value;
51589
+ for (var _g = __values(otherCohortMatchUps !== null && otherCohortMatchUps !== void 0 ? otherCohortMatchUps : []), _h = _g.next(); !_h.done; _h = _g.next()) {
51590
+ var matchUp = _h.value;
51470
51591
  var orderOfFinish = (matchUp || {}).orderOfFinish;
51471
51592
  if (orderOfFinish) {
51472
51593
  if (!isConvertableInteger(orderOfFinish))
@@ -51482,7 +51603,7 @@ function setOrderOfFinish$1(_a) {
51482
51603
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
51483
51604
  finally {
51484
51605
  try {
51485
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
51606
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
51486
51607
  }
51487
51608
  finally { if (e_1) throw e_1.error; }
51488
51609
  }
@@ -51490,10 +51611,8 @@ function setOrderOfFinish$1(_a) {
51490
51611
  if (uniqueValues(orderOfFinishValues).length !== orderOfFinishValues.length ||
51491
51612
  Math.max.apply(Math, __spreadArray([], __read(orderOfFinishValues), false)) > orderOfFinishValues.length) {
51492
51613
  return decorateResult({
51493
- result: {
51494
- error: INVALID_VALUES,
51495
- },
51496
51614
  info: 'Values not unique or greater than expected number of values',
51615
+ result: { error: INVALID_VALUES },
51497
51616
  stack: stack,
51498
51617
  });
51499
51618
  }
@@ -51508,7 +51627,7 @@ function setOrderOfFinish$1(_a) {
51508
51627
  if (result.error)
51509
51628
  return decorateResult({ result: result, stack: stack });
51510
51629
  // apply the new values to targeted matchUps
51511
- (_c = result.completedMatchUps) === null || _c === void 0 ? void 0 : _c.forEach(function (matchUp) { return (matchUp.orderOfFinish = valuesMap[matchUp.matchUpId]); });
51630
+ (_d = result.completedMatchUps) === null || _d === void 0 ? void 0 : _d.forEach(function (matchUp) { return (matchUp.orderOfFinish = valuesMap[matchUp.matchUpId]); });
51512
51631
  }
51513
51632
  return __assign({}, SUCCESS);
51514
51633
  }
@@ -52415,7 +52534,7 @@ function getValidQualifiersAction(_a) {
52415
52534
  }
52416
52535
  return { validAssignmentActions: validAssignmentActions, sourceStructureIds: sourceStructureIds };
52417
52536
  }
52418
- /*
52537
+ /**
52419
52538
  if (sourceStructureIds.length > 1)
52420
52539
  return decorateResult({
52421
52540
  stack: 'getValidQualifiersSaction',
@@ -54515,10 +54634,8 @@ function addIndividualParticipantIds(_a) {
54515
54634
  if ((groupingParticipant === null || groupingParticipant === void 0 ? void 0 : groupingParticipant.participantType) &&
54516
54635
  ![TEAM, GROUP].includes(groupingParticipant.participantType)) {
54517
54636
  return decorateResult({
54518
- result: {
54519
- error: INVALID_PARTICIPANT_TYPE,
54520
- },
54521
54637
  context: { participantType: groupingParticipant.participantType },
54638
+ result: { error: INVALID_PARTICIPANT_TYPE },
54522
54639
  stack: stack,
54523
54640
  });
54524
54641
  }
@@ -56495,7 +56612,7 @@ function getTieMatchUpContext(_a) {
56495
56612
  */
56496
56613
  function assignTieMatchUpParticipantId(params) {
56497
56614
  var e_1, _a;
56498
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
56615
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
56499
56616
  var matchUpContext = getTieMatchUpContext(params);
56500
56617
  if (matchUpContext.error)
56501
56618
  return matchUpContext;
@@ -56522,12 +56639,12 @@ function assignTieMatchUpParticipantId(params) {
56522
56639
  teamParticipantId ||
56523
56640
  (params.sideNumber &&
56524
56641
  ((_d = (_c = inContextDualMatchUp === null || inContextDualMatchUp === void 0 ? void 0 : inContextDualMatchUp.sides) === null || _c === void 0 ? void 0 : _c.find(function (side) { return side.sideNumber === params.sideNumber; })) === null || _d === void 0 ? void 0 : _d.participantId));
56525
- var _q = __read(getTournamentParticipants({
56642
+ var _r = __read(getTournamentParticipants({
56526
56643
  tournamentRecord: tournamentRecord,
56527
56644
  participantFilters: {
56528
56645
  participantIds: [participantId],
56529
56646
  },
56530
- }).tournamentParticipants, 1), participantToAssign = _q[0];
56647
+ }).tournamentParticipants, 1), participantToAssign = _r[0];
56531
56648
  if (!participantToAssign) {
56532
56649
  return decorateResult({ result: { error: PARTICIPANT_NOT_FOUND }, stack: stack });
56533
56650
  }
@@ -56595,11 +56712,10 @@ function assignTieMatchUpParticipantId(params) {
56595
56712
  }
56596
56713
  var dualMatchUpSide = (_m = dualMatchUp === null || dualMatchUp === void 0 ? void 0 : dualMatchUp.sides) === null || _m === void 0 ? void 0 : _m.find(function (side) { return side.sideNumber === sideNumber; });
56597
56714
  var tieMatchUpSide = (_o = inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.sides) === null || _o === void 0 ? void 0 : _o.find(function (side) { return side.sideNumber === sideNumber; });
56598
- var lineUp = (dualMatchUpSide === null || dualMatchUpSide === void 0 ? void 0 : dualMatchUpSide.lineUp) ||
56599
- ((_p = getTeamLineUp({
56600
- participantId: teamParticipantId,
56601
- drawDefinition: drawDefinition,
56602
- })) === null || _p === void 0 ? void 0 : _p.lineUp);
56715
+ var lineUp = (_p = dualMatchUpSide === null || dualMatchUpSide === void 0 ? void 0 : dualMatchUpSide.lineUp) !== null && _p !== void 0 ? _p : (_q = getTeamLineUp({
56716
+ participantId: teamParticipantId,
56717
+ drawDefinition: drawDefinition,
56718
+ })) === null || _q === void 0 ? void 0 : _q.lineUp;
56603
56719
  var targetAssignments = lineUp === null || lineUp === void 0 ? void 0 : lineUp.filter(function (participantAssignment) {
56604
56720
  var _a;
56605
56721
  return (_a = participantAssignment.collectionAssignments) === null || _a === void 0 ? void 0 : _a.find(function (assignment) {
@@ -59420,8 +59536,8 @@ function deleteDrawDefinitions(_a) {
59420
59536
  var auditTrail = [];
59421
59537
  if (!(event === null || event === void 0 ? void 0 : event.drawDefinitions))
59422
59538
  return decorateResult({
59423
- result: __assign({}, SUCCESS),
59424
59539
  info: 'event has no drawDefinition',
59540
+ result: __assign({}, SUCCESS),
59425
59541
  stack: stack,
59426
59542
  });
59427
59543
  var eventDrawIds = event.drawDefinitions.map(function (_a) {
@@ -59434,8 +59550,8 @@ function deleteDrawDefinitions(_a) {
59434
59550
  drawIds = drawIds.filter(function (drawId) { return eventDrawIds.includes(drawId); });
59435
59551
  if (!drawIds.length)
59436
59552
  return decorateResult({
59437
- result: __assign({}, SUCCESS),
59438
59553
  info: 'nothing to do; no matching drawIds in event.',
59554
+ result: __assign({}, SUCCESS),
59439
59555
  stack: stack,
59440
59556
  });
59441
59557
  var flightProfile = makeDeepCopy(getFlightProfile({ event: event }).flightProfile, false, true);
@@ -62492,6 +62608,7 @@ function addVoluntaryConsolationStructure(params) {
62492
62608
 
62493
62609
  function prepareStage(params) {
62494
62610
  var _a;
62611
+ var stack = 'prepareStage';
62495
62612
  var seedsCount = params.seedsCount;
62496
62613
  var preparedStructureIds = params.preparedStructureIds || [];
62497
62614
  var provisionalPositioning = params.provisionalPositioning, inContextDrawMatchUps = params.inContextDrawMatchUps, tournamentRecord = params.tournamentRecord, appliedPolicies = params.appliedPolicies, qualifyingOnly = params.qualifyingOnly, drawDefinition = params.drawDefinition, seedingProfile = params.seedingProfile, participants = params.participants, matchUpsMap = params.matchUpsMap, automated = params.automated, placeByes = params.placeByes, drawType = params.drawType, drawSize = params.drawSize, entries = params.entries, event = params.event, _b = params.enforcePolicyLimits, enforcePolicyLimits = _b === void 0 ? true : _b, seedAssignmentProfile = params.seedAssignmentProfile, // mainly used by mocksEngine for scenario testing
@@ -62530,7 +62647,7 @@ function prepareStage(params) {
62530
62647
  return !preparedStructureIds.includes(structureId);
62531
62648
  });
62532
62649
  if (!structure)
62533
- return decorateResult({ result: { error: STRUCTURE_NOT_FOUND } });
62650
+ return decorateResult({ result: { error: STRUCTURE_NOT_FOUND }, stack: stack });
62534
62651
  var structureId = structure === null || structure === void 0 ? void 0 : structure.structureId;
62535
62652
  var seedBlockInfo = structure
62536
62653
  ? getValidSeedBlocks({
@@ -62667,7 +62784,7 @@ function prepareStage(params) {
62667
62784
  positionAssignments = result === null || result === void 0 ? void 0 : result.positionAssignments;
62668
62785
  positioningReport = result === null || result === void 0 ? void 0 : result.positioningReport;
62669
62786
  if (result.error) {
62670
- return decorateResult({ result: result, stack: 'prepareStage' });
62787
+ return decorateResult({ result: result, stack: stack });
62671
62788
  }
62672
62789
  }
62673
62790
  return {
@@ -62857,10 +62974,8 @@ function generateDrawDefinition(params) {
62857
62974
  if (policyDefinitions) {
62858
62975
  if (typeof policyDefinitions !== 'object') {
62859
62976
  return decorateResult({
62860
- result: {
62861
- info: 'policyDefinitions must be an object',
62862
- error: INVALID_VALUES,
62863
- },
62977
+ info: 'policyDefinitions must be an object',
62978
+ result: { error: INVALID_VALUES },
62864
62979
  stack: stack,
62865
62980
  });
62866
62981
  }
@@ -63109,8 +63224,9 @@ function generateDrawDefinition(params) {
63109
63224
  var roundTargetProfile = _34.value;
63110
63225
  if (!Array.isArray(roundTargetProfile.structureProfiles))
63111
63226
  return decorateResult({
63112
- result: { error: MISSING_VALUE },
63113
63227
  info: mustBeAnArray('structureProfiles'),
63228
+ result: { error: MISSING_VALUE },
63229
+ stack: stack,
63114
63230
  });
63115
63231
  roundTarget = roundTargetProfile.roundTarget || roundTarget;
63116
63232
  var sortedStructureProfiles = ((_21 = roundTargetProfile.structureProfiles) === null || _21 === void 0 ? void 0 : _21.sort(sequenceSort)) || [];
@@ -63367,26 +63483,26 @@ function enableTieAutoCalc(params) {
63367
63483
  }
63368
63484
 
63369
63485
  function modifyEvent(_a) {
63370
- var _b;
63486
+ var _b, _c, _d, _e, _f;
63371
63487
  var tournamentRecord = _a.tournamentRecord, eventUpdates = _a.eventUpdates, eventId = _a.eventId, event = _a.event;
63372
63488
  if (!tournamentRecord)
63373
63489
  return { error: MISSING_TOURNAMENT_RECORD };
63374
63490
  if (!isString(eventId) || !isObject(eventUpdates))
63375
63491
  return { error: INVALID_VALUES };
63376
- var enteredParticipantIds = ((_b = event === null || event === void 0 ? void 0 : event.entries) === null || _b === void 0 ? void 0 : _b.filter(function (_a) {
63492
+ var enteredParticipantIds = (_c = (_b = event === null || event === void 0 ? void 0 : event.entries) === null || _b === void 0 ? void 0 : _b.filter(function (_a) {
63377
63493
  var entryStatus = _a.entryStatus;
63378
63494
  var status = entryStatus;
63379
63495
  return __spreadArray(__spreadArray([], __read(STRUCTURE_SELECTED_STATUSES), false), [ALTERNATE], false).includes(status);
63380
63496
  }).map(function (_a) {
63381
63497
  var participantId = _a.participantId;
63382
63498
  return participantId;
63383
- })) || [];
63499
+ })) !== null && _c !== void 0 ? _c : [];
63384
63500
  var enteredParticipants = enteredParticipantIds
63385
- ? getParticipants$1({
63501
+ ? (_d = getParticipants$1({
63386
63502
  participantFilters: { participantIds: enteredParticipantIds },
63387
63503
  withIndividualParticipants: true,
63388
63504
  tournamentRecord: tournamentRecord,
63389
- }).participants || []
63505
+ }).participants) !== null && _d !== void 0 ? _d : []
63390
63506
  : [];
63391
63507
  var genderAccumulator = [];
63392
63508
  var enteredParticipantTypes = enteredParticipants.reduce(function (types, participant) {
@@ -63401,7 +63517,7 @@ function modifyEvent(_a) {
63401
63517
  }, []);
63402
63518
  var enteredParticipantGenders = unique(genderAccumulator);
63403
63519
  var validGender = !enteredParticipantGenders.length ||
63404
- [MIXED, ANY].includes(eventUpdates.gender || '') ||
63520
+ [MIXED, ANY].includes((_e = eventUpdates.gender) !== null && _e !== void 0 ? _e : '') ||
63405
63521
  (enteredParticipantGenders.length === 1 &&
63406
63522
  enteredParticipantGenders[0] === eventUpdates.gender);
63407
63523
  if (eventUpdates.gender && !validGender)
@@ -63416,14 +63532,14 @@ function modifyEvent(_a) {
63416
63532
  SINGLES,
63417
63533
  TEAM$1,
63418
63534
  ];
63419
- var validEventType = validEventTypes.includes(eventUpdates.eventType || '');
63535
+ var validEventType = validEventTypes.includes((_f = eventUpdates.eventType) !== null && _f !== void 0 ? _f : '');
63420
63536
  if (eventUpdates.eventType && !validEventType)
63421
63537
  return decorateResult({
63422
63538
  context: { participantType: eventUpdates.eventType },
63423
63539
  result: { error: INVALID_VALUES },
63424
63540
  });
63425
63541
  if (eventUpdates.eventType)
63426
- event.eventType === eventUpdates.eventType;
63542
+ event.eventType = eventUpdates.eventType;
63427
63543
  if (eventUpdates.eventName)
63428
63544
  event.eventName = eventUpdates.eventName;
63429
63545
  if (eventUpdates.gender)
@@ -64066,6 +64182,65 @@ function getParticipantSignInStatus(_a) {
64066
64182
  return timeItem && timeItem.itemValue === SIGNED_IN && SIGNED_IN;
64067
64183
  }
64068
64184
 
64185
+ function getTieFormat(_a) {
64186
+ var _b, _c, _d, _e, _f;
64187
+ var tournamentRecord = _a.tournamentRecord, // passed in automatically by tournamentEngine
64188
+ drawDefinition = _a.drawDefinition, // passed in automatically by tournamentEngine when drawId provided
64189
+ structureId = _a.structureId, // optional - if only the default matchUpFormat for a structure is required
64190
+ matchUpId = _a.matchUpId, // id of matchUp for which the scoped matchUpFormat(s) are desired
64191
+ structure = _a.structure, // optional optimization - when structure already known
64192
+ eventId = _a.eventId, // optional - if only the default matchUpFormat for an event is required
64193
+ drawId = _a.drawId, // avoid brute force search for matchUp
64194
+ event = _a.event;
64195
+ if (!tournamentRecord)
64196
+ return { error: MISSING_TOURNAMENT_RECORD };
64197
+ if (!drawId && !event && !structureId && !matchUpId)
64198
+ return decorateResult({
64199
+ result: { error: MISSING_VALUE },
64200
+ stack: 'getTieFormat',
64201
+ });
64202
+ if (eventId && !event) {
64203
+ event = (_b = tournamentRecord.events) === null || _b === void 0 ? void 0 : _b.find(function (event) { return event.eventId === eventId; });
64204
+ }
64205
+ var matchUpResult = publicFindMatchUp({
64206
+ tournamentRecord: tournamentRecord,
64207
+ drawDefinition: drawDefinition,
64208
+ matchUpId: matchUpId,
64209
+ drawId: drawId,
64210
+ event: event,
64211
+ });
64212
+ if (matchUpId && (matchUpResult === null || matchUpResult === void 0 ? void 0 : matchUpResult.error)) {
64213
+ return matchUpResult;
64214
+ }
64215
+ else if (!drawDefinition && (matchUpResult === null || matchUpResult === void 0 ? void 0 : matchUpResult.drawDefinition)) {
64216
+ drawDefinition = matchUpResult === null || matchUpResult === void 0 ? void 0 : matchUpResult.drawDefinition;
64217
+ }
64218
+ structure = structure !== null && structure !== void 0 ? structure : matchUpResult === null || matchUpResult === void 0 ? void 0 : matchUpResult.structure;
64219
+ if (!structure && structureId && !matchUpId) {
64220
+ if (!drawDefinition)
64221
+ return { error: MISSING_DRAW_ID };
64222
+ var structureResult = findStructure({ drawDefinition: drawDefinition, structureId: structureId });
64223
+ if (structureResult.error)
64224
+ return structureResult;
64225
+ structure = structureResult.structure;
64226
+ }
64227
+ var structureDefaultTieFormat = ((structure === null || structure === void 0 ? void 0 : structure.tieFormat) || (structure === null || structure === void 0 ? void 0 : structure.tieFormatId)) &&
64228
+ ((_c = resolveTieFormat({ structure: structure, drawDefinition: drawDefinition, event: event })) === null || _c === void 0 ? void 0 : _c.tieFormat);
64229
+ var drawDefaultTieFormat = ((drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.tieFormat) || (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.tieFormatId)) &&
64230
+ ((_d = resolveTieFormat({
64231
+ drawDefinition: drawDefinition,
64232
+ event: event,
64233
+ })) === null || _d === void 0 ? void 0 : _d.tieFormat);
64234
+ var eventDefaultTieFormat = (_e = resolveTieFormat({ event: event })) === null || _e === void 0 ? void 0 : _e.tieFormat;
64235
+ var tieFormat = (_f = resolveTieFormat({
64236
+ matchUp: matchUpResult === null || matchUpResult === void 0 ? void 0 : matchUpResult.matchUp,
64237
+ drawDefinition: drawDefinition,
64238
+ structure: structure,
64239
+ event: event,
64240
+ })) === null || _f === void 0 ? void 0 : _f.tieFormat;
64241
+ return __assign(__assign({}, SUCCESS), { matchUp: matchUpResult === null || matchUpResult === void 0 ? void 0 : matchUpResult.matchUp, structureDefaultTieFormat: copyTieFormat(structureDefaultTieFormat), eventDefaultTieFormat: copyTieFormat(eventDefaultTieFormat), drawDefaultTieFormat: copyTieFormat(drawDefaultTieFormat), tieFormat: copyTieFormat(tieFormat), structure: structure });
64242
+ }
64243
+
64069
64244
  function getEventProperties(_a) {
64070
64245
  var _b, _c;
64071
64246
  var tournamentRecord = _a.tournamentRecord, event = _a.event;