tods-competition-factory 2.0.0-beta.3 → 2.0.0-beta.5

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.0.0-beta.3';
6
+ return '2.0.0-beta.5';
7
7
  }
8
8
 
9
9
  /******************************************************************************
@@ -2604,9 +2604,7 @@ function createMap(objectArray, attribute) {
2604
2604
  .filter(Boolean)), false));
2605
2605
  }
2606
2606
  // e.g. result.find(hav({ attr: value })) -or- result.filter(hav({ attr: value }))
2607
- var hasAttributeValues = function (a) { return function (o) {
2608
- return Object.keys(a).every(function (key) { return o[key] === a[key]; });
2609
- }; };
2607
+ var hasAttributeValues = function (a) { return function (o) { return Object.keys(a).every(function (key) { return o[key] === a[key]; }); }; };
2610
2608
  // extracts targeted attributes
2611
2609
  // e.g. const byeAssignments = positionAssignments.filter(xa('bye')).map(xa('drawPosition'));
2612
2610
  // supports xa('string'), xa(['string', 'string']), xa({ attr1: true, attr2: true })
@@ -2632,6 +2630,7 @@ var extractAttributes = function (accessor) { return function (element) {
2632
2630
  })) ||
2633
2631
  ((_a = (typeof accessor === 'string' && getAccessorValue({ element: element, accessor: accessor }))) === null || _a === void 0 ? void 0 : _a.value);
2634
2632
  }; };
2633
+ var xa = extractAttributes;
2635
2634
  // useful in notifications where back end does not recognize undefined for updates
2636
2635
  function undefinedToNull(obj, shallow) {
2637
2636
  if (obj === undefined)
@@ -3794,7 +3793,7 @@ function getAllPositionedParticipantIds(_a) {
3794
3793
  if (!stagePositionedParticipantIds[stage])
3795
3794
  stagePositionedParticipantIds[stage] = [];
3796
3795
  var positionAssignments = getPositionAssignments$1({ structure: structure }).positionAssignments;
3797
- var particiapntIds = (_b = positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.map(extractAttributes('participantId')).filter(Boolean)) !== null && _b !== void 0 ? _b : [];
3796
+ var particiapntIds = (_b = positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.map(xa('participantId')).filter(Boolean)) !== null && _b !== void 0 ? _b : [];
3798
3797
  (_a = stagePositionedParticipantIds[stage]).push.apply(_a, __spreadArray([], __read(particiapntIds), false));
3799
3798
  return particiapntIds;
3800
3799
  })
@@ -7243,35 +7242,23 @@ function getTeamLineUp(_a) {
7243
7242
  return { lineUp: lineUp };
7244
7243
  }
7245
7244
 
7246
- function getDrawPositionCollectionAssignment(_a) {
7245
+ function getCollectionAssignment(_a) {
7247
7246
  var tournamentParticipants = _a.tournamentParticipants, positionAssignments = _a.positionAssignments, collectionPosition = _a.collectionPosition, _b = _a.drawPositions, drawPositions = _b === void 0 ? [] : _b, participantMap = _a.participantMap, drawDefinition = _a.drawDefinition, collectionId = _a.collectionId, sideLineUps = _a.sideLineUps, matchUpType = _a.matchUpType;
7248
7247
  if (!collectionId || !collectionPosition)
7249
- return;
7250
- var drawPositionCollectionAssignment = (drawPositions === null || drawPositions === void 0 ? void 0 : drawPositions.map(function (drawPosition) {
7251
- var _a, _b, _c;
7252
- var _d, _e, _f, _g, _h, _j;
7253
- var teamParticipantId = (_d = positionAssignments.find(function (assignment) { return assignment.drawPosition === drawPosition; })) === null || _d === void 0 ? void 0 : _d.participantId;
7254
- var side = sideLineUps === null || sideLineUps === void 0 ? void 0 : sideLineUps.find(function (lineUp) { return (lineUp === null || lineUp === void 0 ? void 0 : lineUp.drawPosition) === drawPosition; });
7255
- var teamParticipant = (side === null || side === void 0 ? void 0 : side.teamParticipant) ||
7256
- (teamParticipantId && ((_e = participantMap === null || participantMap === void 0 ? void 0 : participantMap[teamParticipantId]) === null || _e === void 0 ? void 0 : _e.participant)) ||
7257
- (tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.find(function (_a) {
7258
- var participantId = _a.participantId;
7259
- return participantId === teamParticipantId;
7260
- }));
7261
- var lineUp = (side === null || side === void 0 ? void 0 : side.lineUp) ||
7262
- ((_f = getTeamLineUp({
7263
- participantId: teamParticipantId,
7264
- drawDefinition: drawDefinition,
7265
- })) === null || _f === void 0 ? void 0 : _f.lineUp);
7266
- var _k = getCollectionPositionAssignments({
7248
+ return {};
7249
+ var getAssignment = function (_a) {
7250
+ var _b, _c, _d;
7251
+ var _e, _f, _g;
7252
+ var attribute = _a.attribute, lineUp = _a.lineUp, teamParticipant = _a.teamParticipant;
7253
+ var _h = getCollectionPositionAssignments({
7267
7254
  collectionPosition: collectionPosition,
7268
7255
  collectionId: collectionId,
7269
7256
  lineUp: lineUp,
7270
- }), assignedParticipantIds = _k.assignedParticipantIds, substitutions = _k.substitutions;
7257
+ }), assignedParticipantIds = _h.assignedParticipantIds, substitutions = _h.substitutions;
7271
7258
  if (matchUpType === DOUBLES) {
7272
7259
  if ((assignedParticipantIds === null || assignedParticipantIds === void 0 ? void 0 : assignedParticipantIds.length) <= 2) {
7273
- var pairedParticipantId = (_h = (_g = participantMap === null || participantMap === void 0 ? void 0 : participantMap[assignedParticipantIds[0]]) === null || _g === void 0 ? void 0 : _g.pairIdMap) === null || _h === void 0 ? void 0 : _h[assignedParticipantIds[1]];
7274
- var pairedParticipant = pairedParticipantId && ((_j = participantMap[pairedParticipantId]) === null || _j === void 0 ? void 0 : _j.participant);
7260
+ var pairedParticipantId = (_f = (_e = participantMap === null || participantMap === void 0 ? void 0 : participantMap[assignedParticipantIds[0]]) === null || _e === void 0 ? void 0 : _e.pairIdMap) === null || _f === void 0 ? void 0 : _f[assignedParticipantIds[1]];
7261
+ var pairedParticipant = pairedParticipantId && ((_g = participantMap[pairedParticipantId]) === null || _g === void 0 ? void 0 : _g.participant);
7275
7262
  var participant = pairedParticipant ||
7276
7263
  // resort to brute force
7277
7264
  getPairedParticipant({
@@ -7279,23 +7266,49 @@ function getDrawPositionCollectionAssignment(_a) {
7279
7266
  tournamentParticipants: tournamentParticipants,
7280
7267
  }).participant;
7281
7268
  var participantId = participant === null || participant === void 0 ? void 0 : participant.participantId;
7282
- return _a = {},
7283
- _a[drawPosition] = { participantId: participantId, teamParticipant: teamParticipant, substitutions: substitutions },
7284
- _a;
7269
+ return _b = {},
7270
+ _b[attribute] = { participantId: participantId, teamParticipant: teamParticipant, substitutions: substitutions },
7271
+ _b;
7285
7272
  }
7286
7273
  else if ((assignedParticipantIds === null || assignedParticipantIds === void 0 ? void 0 : assignedParticipantIds.length) > 2) {
7287
- return _b = {}, _b[drawPosition] = { teamParticipant: teamParticipant, substitutions: substitutions }, _b;
7274
+ return _c = {}, _c[attribute] = { teamParticipant: teamParticipant, substitutions: substitutions }, _c;
7288
7275
  }
7289
7276
  }
7290
7277
  else {
7291
7278
  var participantId = assignedParticipantIds === null || assignedParticipantIds === void 0 ? void 0 : assignedParticipantIds[0];
7292
- return (participantId && (_c = {},
7293
- _c[drawPosition] = { participantId: participantId, teamParticipant: teamParticipant, substitutions: substitutions },
7294
- _c));
7279
+ return (participantId && (_d = {},
7280
+ _d[attribute] = { participantId: participantId, teamParticipant: teamParticipant, substitutions: substitutions },
7281
+ _d));
7295
7282
  }
7296
7283
  return undefined;
7284
+ };
7285
+ if (!(drawPositions === null || drawPositions === void 0 ? void 0 : drawPositions.length)) {
7286
+ var sideNumberCollectionAssignment = (sideLineUps === null || sideLineUps === void 0 ? void 0 : sideLineUps.map(function (side) {
7287
+ var _a;
7288
+ var teamParticipant = side.teamParticipant, sideNumber = side.sideNumber;
7289
+ var lineUp = side.lineUp || ((_a = getTeamLineUp({ participantId: teamParticipant.teamParticipantId, drawDefinition: drawDefinition })) === null || _a === void 0 ? void 0 : _a.lineUp);
7290
+ return getAssignment({ attribute: sideNumber, lineUp: lineUp, teamParticipant: teamParticipant });
7291
+ }).filter(Boolean)) || {};
7292
+ return { sideNumberCollectionAssignment: Object.assign.apply(Object, __spreadArray([{}], __read(sideNumberCollectionAssignment), false)) };
7293
+ }
7294
+ var drawPositionCollectionAssignment = (drawPositions === null || drawPositions === void 0 ? void 0 : drawPositions.map(function (drawPosition) {
7295
+ var _a, _b, _c;
7296
+ var teamParticipantId = (_a = positionAssignments.find(function (assignment) { return assignment.drawPosition === drawPosition; })) === null || _a === void 0 ? void 0 : _a.participantId;
7297
+ var side = sideLineUps === null || sideLineUps === void 0 ? void 0 : sideLineUps.find(function (lineUp) { return (lineUp === null || lineUp === void 0 ? void 0 : lineUp.drawPosition) === drawPosition; });
7298
+ var teamParticipant = (side === null || side === void 0 ? void 0 : side.teamParticipant) ||
7299
+ (teamParticipantId && ((_b = participantMap === null || participantMap === void 0 ? void 0 : participantMap[teamParticipantId]) === null || _b === void 0 ? void 0 : _b.participant)) ||
7300
+ (tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.find(function (_a) {
7301
+ var participantId = _a.participantId;
7302
+ return participantId === teamParticipantId;
7303
+ }));
7304
+ var lineUp = (side === null || side === void 0 ? void 0 : side.lineUp) ||
7305
+ ((_c = getTeamLineUp({
7306
+ participantId: teamParticipantId,
7307
+ drawDefinition: drawDefinition,
7308
+ })) === null || _c === void 0 ? void 0 : _c.lineUp);
7309
+ return getAssignment({ attribute: drawPosition, lineUp: lineUp, teamParticipant: teamParticipant });
7297
7310
  }).filter(Boolean)) || {};
7298
- return Object.assign.apply(Object, __spreadArray([{}], __read(drawPositionCollectionAssignment), false));
7311
+ return { drawPositionCollectionAssignment: Object.assign.apply(Object, __spreadArray([{}], __read(drawPositionCollectionAssignment), false)) };
7299
7312
  }
7300
7313
 
7301
7314
  function modifyEntryProfile(_a) {
@@ -9779,25 +9792,13 @@ function filterMatchUps(params) {
9779
9792
  });
9780
9793
  }
9781
9794
 
9782
- /**
9783
- *
9784
- * @param {object} drawPositionCollectionAssignment - mapping of drawPositions to participantIds derived from collectionAssignments
9785
- * @param {object[]} positionAssignments - mapping of drawPositions to participantIds (in TIES this is TEAM participantId)
9786
- * @param {number} displaySideNumber - accounts for both top and bottom feed arm positioning
9787
- * @param {object[]} seedAssignments - mapping of participantIds to seedNumber and seedValue
9788
- * @param {number} drawPosition -
9789
- * @param {boolean} isFeedRound - whether a round includes fed drawPositions
9790
- * @param {number} sideNumber - 1 or 2
9791
- */
9792
9795
  function getSide(_a) {
9793
9796
  var _b, _c, _d, _e;
9794
- var drawPositionCollectionAssignment = _a.drawPositionCollectionAssignment, positionAssignments = _a.positionAssignments, displaySideNumber = _a.displaySideNumber, seedAssignments = _a.seedAssignments, drawPosition = _a.drawPosition, isFeedRound = _a.isFeedRound, sideNumber = _a.sideNumber;
9795
- var assignment = positionAssignments.find(function (assignment) {
9796
- return assignment.drawPosition && assignment.drawPosition === drawPosition;
9797
- });
9798
- var participantId = drawPositionCollectionAssignment
9799
- ? (_b = drawPositionCollectionAssignment[drawPosition]) === null || _b === void 0 ? void 0 : _b.participantId
9800
- : assignment === null || assignment === void 0 ? void 0 : assignment.participantId;
9797
+ var drawPositionCollectionAssignment = _a.drawPositionCollectionAssignment, sideNumberCollectionAssignment = _a.sideNumberCollectionAssignment, positionAssignments = _a.positionAssignments, displaySideNumber = _a.displaySideNumber, seedAssignments = _a.seedAssignments, drawPosition = _a.drawPosition, isFeedRound = _a.isFeedRound, sideNumber = _a.sideNumber;
9798
+ var assignment = positionAssignments.find(function (assignment) { return assignment.drawPosition && assignment.drawPosition === drawPosition; });
9799
+ var dpc = drawPosition && drawPositionCollectionAssignment;
9800
+ var snc = sideNumber && sideNumberCollectionAssignment;
9801
+ var participantId = dpc ? (_b = dpc[drawPosition]) === null || _b === void 0 ? void 0 : _b.participantId : assignment === null || assignment === void 0 ? void 0 : assignment.participantId;
9801
9802
  var sideValue = assignment
9802
9803
  ? getSideValue$1({
9803
9804
  displaySideNumber: displaySideNumber,
@@ -9806,7 +9807,7 @@ function getSide(_a) {
9806
9807
  assignment: assignment,
9807
9808
  sideNumber: sideNumber,
9808
9809
  })
9809
- : {};
9810
+ : __assign({}, snc === null || snc === void 0 ? void 0 : snc[sideNumber]);
9810
9811
  if (isFeedRound) {
9811
9812
  if (sideNumber === 1) {
9812
9813
  Object.assign(sideValue, { participantFed: true });
@@ -9815,15 +9816,17 @@ function getSide(_a) {
9815
9816
  Object.assign(sideValue, { participantAdvanced: true });
9816
9817
  }
9817
9818
  }
9818
- var teamParticipant = (_c = drawPositionCollectionAssignment === null || drawPositionCollectionAssignment === void 0 ? void 0 : drawPositionCollectionAssignment[drawPosition]) === null || _c === void 0 ? void 0 : _c.teamParticipant;
9819
- var participant = (_d = drawPositionCollectionAssignment === null || drawPositionCollectionAssignment === void 0 ? void 0 : drawPositionCollectionAssignment[drawPosition]) === null || _d === void 0 ? void 0 : _d.participant;
9820
- var substitutions = (_e = drawPositionCollectionAssignment === null || drawPositionCollectionAssignment === void 0 ? void 0 : drawPositionCollectionAssignment[drawPosition]) === null || _e === void 0 ? void 0 : _e.substitutions;
9821
- if (participant)
9822
- Object.assign(sideValue, { participant: participant });
9823
- if (substitutions)
9824
- Object.assign(sideValue, { substitutions: substitutions });
9825
- if (teamParticipant)
9826
- Object.assign(sideValue, { teamParticipant: teamParticipant });
9819
+ if (drawPosition && dpc) {
9820
+ var teamParticipant = (_c = dpc[drawPosition]) === null || _c === void 0 ? void 0 : _c.teamParticipant;
9821
+ var participant = (_d = dpc[drawPosition]) === null || _d === void 0 ? void 0 : _d.participant;
9822
+ var substitutions = (_e = dpc[drawPosition]) === null || _e === void 0 ? void 0 : _e.substitutions;
9823
+ if (participant)
9824
+ sideValue.participant = participant;
9825
+ if (substitutions)
9826
+ sideValue.substitutions = substitutions;
9827
+ if (teamParticipant)
9828
+ sideValue.teamParticipant = teamParticipant;
9829
+ }
9827
9830
  return sideValue;
9828
9831
  }
9829
9832
  function getSideValue$1(_a) {
@@ -9847,9 +9850,7 @@ function getSideValue$1(_a) {
9847
9850
  }
9848
9851
  function getSeeding(_a) {
9849
9852
  var seedAssignments = _a.seedAssignments, participantId = _a.participantId;
9850
- return seedAssignments === null || seedAssignments === void 0 ? void 0 : seedAssignments.find(function (assignment) {
9851
- return !assignment.seedProxy && assignment.participantId === participantId;
9852
- });
9853
+ return seedAssignments === null || seedAssignments === void 0 ? void 0 : seedAssignments.find(function (assignment) { return !assignment.seedProxy && assignment.participantId === participantId; });
9853
9854
  }
9854
9855
 
9855
9856
  var ANY = 'ANY';
@@ -10069,8 +10070,8 @@ function getAllStructureMatchUps(_a) {
10069
10070
  var drawPositions = (_f = tieDrawPositions !== null && tieDrawPositions !== void 0 ? tieDrawPositions : matchUp.drawPositions) !== null && _f !== void 0 ? _f : [];
10070
10071
  var collectionPosition = matchUp.collectionPosition, collectionId = matchUp.collectionId, roundPosition = matchUp.roundPosition;
10071
10072
  var roundNumber = (_g = matchUp.roundNumber) !== null && _g !== void 0 ? _g : additionalContext.roundNumber;
10072
- var drawPositionCollectionAssignment = collectionId
10073
- ? getDrawPositionCollectionAssignment({
10073
+ var collectionAssignmentDetail = collectionId
10074
+ ? getCollectionAssignment({
10074
10075
  tournamentParticipants: tournamentParticipants,
10075
10076
  positionAssignments: positionAssignments,
10076
10077
  collectionPosition: collectionPosition,
@@ -10170,15 +10171,7 @@ function getAllStructureMatchUps(_a) {
10170
10171
  var _a;
10171
10172
  var sideNumber = index + 1;
10172
10173
  var displaySideNumber = reversedDisplayOrder_1 ? 3 - sideNumber : sideNumber;
10173
- var side = getSide({
10174
- drawPositionCollectionAssignment: drawPositionCollectionAssignment,
10175
- positionAssignments: positionAssignments,
10176
- displaySideNumber: displaySideNumber,
10177
- seedAssignments: seedAssignments,
10178
- drawPosition: drawPosition,
10179
- isFeedRound: isFeedRound_1,
10180
- sideNumber: sideNumber,
10181
- });
10174
+ var side = getSide(__assign(__assign({}, collectionAssignmentDetail), { positionAssignments: positionAssignments, displaySideNumber: displaySideNumber, seedAssignments: seedAssignments, drawPosition: drawPosition, isFeedRound: isFeedRound_1, sideNumber: sideNumber }));
10182
10175
  var existingSide = (_a = matchUp.sides) === null || _a === void 0 ? void 0 : _a.find(function (existing) { return existing.sideNumber === sideNumber; });
10183
10176
  // drawPositions for consolation structures are offset by the number of fed positions in subsequent rounds
10184
10177
  // columnPosition gives an ordered position value relative to a single column
@@ -11369,10 +11362,8 @@ function addFinishingRounds(_a) {
11369
11362
  // for qualifying, offset the final round so that qualifyinground is finishingRound
11370
11363
  var finishingRoundOffset = roundLimit ? roundsCount - roundLimit : 0;
11371
11364
  // for QUALIFYING draws the best finishingPosition is equal to the number of matchUps in the final round of the structure
11372
- var minQualifyingPosition = finishingRoundOffset &&
11373
- ((_b = roundProfile === null || roundProfile === void 0 ? void 0 : roundProfile[roundsCount - finishingRoundOffset]) === null || _b === void 0 ? void 0 : _b.matchUpsCount);
11374
- var roundMatchUpsCountArray = roundProfile &&
11375
- Object.values(roundProfile).map(extractAttributes('matchUpsCount'));
11365
+ var minQualifyingPosition = finishingRoundOffset && ((_b = roundProfile === null || roundProfile === void 0 ? void 0 : roundProfile[roundsCount - finishingRoundOffset]) === null || _b === void 0 ? void 0 : _b.matchUpsCount);
11366
+ var roundMatchUpsCountArray = roundProfile && Object.values(roundProfile).map(xa('matchUpsCount'));
11376
11367
  // returns a range for array of possible finishing drawPositions
11377
11368
  var finishingRange = function (positionRange, winner) {
11378
11369
  var minFinishingPosition = Math.min.apply(Math, __spreadArray([], __read(positionRange), false));
@@ -11399,9 +11390,7 @@ function addFinishingRounds(_a) {
11399
11390
  var fmlcException = fmlc && roundNumber !== 1;
11400
11391
  var rangeOffset = 1 + finishingPositionOffset + (fmlcException ? positionsFed !== null && positionsFed !== void 0 ? positionsFed : 0 : 0);
11401
11392
  var finalPosition = 1;
11402
- var positionRange = generateRange(rangeOffset, lucky
11403
- ? rangeOffset + matchUpsCount * 2
11404
- : upcomingMatchUps + rangeOffset + finalPosition);
11393
+ var positionRange = generateRange(rangeOffset, lucky ? rangeOffset + matchUpsCount * 2 : upcomingMatchUps + rangeOffset + finalPosition);
11405
11394
  var slicer = upcomingMatchUps + finalPosition - matchUpsCount;
11406
11395
  var loser = finishingRange(positionRange.slice(slicer));
11407
11396
  var winner = finishingRange(positionRange.slice(0, slicer), true);
@@ -12945,17 +12934,13 @@ function getAssignedParticipantIds(_a) {
12945
12934
  var drawDefinition = _a.drawDefinition, stages = _a.stages;
12946
12935
  if (!drawDefinition)
12947
12936
  return { error: MISSING_DRAW_DEFINITION };
12948
- var stageStructures = ((_b = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) !== null && _b !== void 0 ? _b : []).filter(function (structure) {
12949
- return !(stages === null || stages === void 0 ? void 0 : stages.length) || (structure.stage && stages.includes(structure.stage));
12950
- });
12937
+ var stageStructures = ((_b = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) !== null && _b !== void 0 ? _b : []).filter(function (structure) { return !(stages === null || stages === void 0 ? void 0 : stages.length) || (structure.stage && stages.includes(structure.stage)); });
12951
12938
  var assignedParticipantIds = unique(stageStructures
12952
12939
  .map(function (structure) {
12953
12940
  var positionAssignments = getPositionAssignments$1({
12954
12941
  structure: structure,
12955
12942
  }).positionAssignments;
12956
- return positionAssignments
12957
- ? positionAssignments.map(extractAttributes('participantId'))
12958
- : [];
12943
+ return positionAssignments ? positionAssignments.map(xa('participantId')) : [];
12959
12944
  })
12960
12945
  .flat()
12961
12946
  .filter(Boolean));
@@ -13917,12 +13902,13 @@ function getParticipantEntries(params) {
13917
13902
  var getRanking = function (_a) {
13918
13903
  var _b, _c, _d, _e;
13919
13904
  var eventType = _a.eventType, scaleNames = _a.scaleNames, participantId = _a.participantId;
13920
- return (_e = (_d = (_c = (_b = participantMap[participantId].participant) === null || _b === void 0 ? void 0 : _b.rankings) === null || _c === void 0 ? void 0 : _c[eventType]) === null || _d === void 0 ? void 0 : _d.find(function (ranking) { return scaleNames.includes(ranking.scaleName); })) === null || _e === void 0 ? void 0 : _e.scaleValue;
13905
+ return (_e = (_d = (_c = (_b = participantMap[participantId].participant) === null || _b === void 0 ? void 0 : _b.rankings) === null || _c === void 0 ? void 0 : _c[eventType]) === null || _d === void 0 ? void 0 : _d.find(function (ranking) {
13906
+ return scaleNames.includes(ranking.scaleName);
13907
+ })) === null || _e === void 0 ? void 0 : _e.scaleValue;
13921
13908
  };
13922
13909
  var _loop_1 = function (event_1) {
13923
13910
  var e_3, _o, e_4, _p, e_5, _q;
13924
- if ((participantFilters === null || participantFilters === void 0 ? void 0 : participantFilters.eventIds) &&
13925
- !participantFilters.eventIds.includes(event_1.eventId))
13911
+ if ((participantFilters === null || participantFilters === void 0 ? void 0 : participantFilters.eventIds) && !participantFilters.eventIds.includes(event_1.eventId))
13926
13912
  return "continue";
13927
13913
  var _r = event_1.drawDefinitions, drawDefinitions = _r === void 0 ? [] : _r, _s = event_1.extensions, extensions = _s === void 0 ? [] : _s, eventType = event_1.eventType, eventName = event_1.eventName, category = event_1.category, entries = event_1.entries, eventId = event_1.eventId, gender = event_1.gender;
13928
13914
  var flightProfile = getFlightProfile({ event: event_1 }).flightProfile;
@@ -13932,13 +13918,9 @@ function getParticipantEntries(params) {
13932
13918
  eventsPublishStatuses[eventId] = publishStatuses;
13933
13919
  var publishedSeeding = publishStatuses === null || publishStatuses === void 0 ? void 0 : publishStatuses.publishedSeeding;
13934
13920
  if (withEvents || withSeeding || withRankingProfile) {
13935
- var extensionConversions = convertExtensions
13936
- ? Object.assign.apply(Object, __spreadArray([{}], __read(extensionsToAttributes(extensions)), false)) : {};
13921
+ var extensionConversions = convertExtensions ? Object.assign.apply(Object, __spreadArray([{}], __read(extensionsToAttributes(extensions)), false)) : {};
13937
13922
  derivedEventInfo[eventId] = __assign(__assign({}, extensionConversions), { eventName: eventName, eventType: eventType, category: category, eventId: eventId, gender: gender });
13938
- var scaleNames = [
13939
- category === null || category === void 0 ? void 0 : category.categoryName,
13940
- category === null || category === void 0 ? void 0 : category.ageCategoryCode,
13941
- ].filter(Boolean);
13923
+ var scaleNames = [category === null || category === void 0 ? void 0 : category.categoryName, category === null || category === void 0 ? void 0 : category.ageCategoryCode].filter(Boolean);
13942
13924
  var _loop_3 = function (entry) {
13943
13925
  var _t;
13944
13926
  var participantId = entry.participantId;
@@ -13978,8 +13960,7 @@ function getParticipantEntries(params) {
13978
13960
  };
13979
13961
  addEventEntry(participantId);
13980
13962
  // add details for individualParticipantIds for TEAM/PAIR events
13981
- var individualParticipantIds = participantMap[participantId].participant.individualParticipantIds ||
13982
- [];
13963
+ var individualParticipantIds = participantMap[participantId].participant.individualParticipantIds || [];
13983
13964
  individualParticipantIds.forEach(addEventEntry);
13984
13965
  };
13985
13966
  try {
@@ -14008,7 +13989,7 @@ function getParticipantEntries(params) {
14008
13989
  _b);
14009
13990
  })), false)) : undefined;
14010
13991
  };
14011
- var drawIds = unique(__spreadArray(__spreadArray([], __read(drawDefinitions.map(extractAttributes('drawId'))), false), __read(flights.map(extractAttributes('drawId'))), false));
13992
+ var drawIds = unique(__spreadArray(__spreadArray([], __read(drawDefinitions.map(xa('drawId'))), false), __read(flights.map(xa('drawId'))), false));
14012
13993
  var _loop_4 = function (drawId) {
14013
13994
  var e_6, _u;
14014
13995
  var drawDefinition = drawDefinitions.find(function (drawDefinition) { return drawDefinition.drawId === drawId; });
@@ -14016,10 +13997,7 @@ function getParticipantEntries(params) {
14016
13997
  var entries_2 = (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) || (flight === null || flight === void 0 ? void 0 : flight.drawEntries);
14017
13998
  var _v = drawDefinition !== null && drawDefinition !== void 0 ? drawDefinition : {}, _w = _v.structures, structures = _w === void 0 ? [] : _w, drawOrder = _v.drawOrder, drawName = _v.drawName, drawType = _v.drawType;
14018
13999
  var flightNumber = flight === null || flight === void 0 ? void 0 : flight.flightNumber;
14019
- var scaleNames = [
14020
- category === null || category === void 0 ? void 0 : category.categoryName,
14021
- category === null || category === void 0 ? void 0 : category.ageCategoryCode,
14022
- ].filter(Boolean);
14000
+ var scaleNames = [category === null || category === void 0 ? void 0 : category.categoryName, category === null || category === void 0 ? void 0 : category.ageCategoryCode].filter(Boolean);
14023
14001
  // used in rankings pipeline.
14024
14002
  // the structures in which a particpant particpates are ordered
14025
14003
  // to enable differentiation for Points-per-round and points-per-win
@@ -14027,9 +14005,7 @@ function getParticipantEntries(params) {
14027
14005
  .sort(function (a, b) { return structureSort(a, b); })
14028
14006
  .map(function (_a) {
14029
14007
  var structureId = _a.structureId, structures = _a.structures;
14030
- return __spreadArray([
14031
- structureId
14032
- ], __read((structures || []).map(function (_a) {
14008
+ return __spreadArray([structureId], __read((structures || []).map(function (_a) {
14033
14009
  var structureId = _a.structureId;
14034
14010
  return structureId;
14035
14011
  })), false);
@@ -14075,8 +14051,7 @@ function getParticipantEntries(params) {
14075
14051
  });
14076
14052
  var seedingPublished = !usePublishState ||
14077
14053
  ((eventPublishedSeeding === null || eventPublishedSeeding === void 0 ? void 0 : eventPublishedSeeding.published) &&
14078
- (((_e = eventPublishedSeeding === null || eventPublishedSeeding === void 0 ? void 0 : eventPublishedSeeding.drawIds) === null || _e === void 0 ? void 0 : _e.length) === 0 ||
14079
- ((_f = eventPublishedSeeding === null || eventPublishedSeeding === void 0 ? void 0 : eventPublishedSeeding.drawIds) === null || _f === void 0 ? void 0 : _f.includes(drawId))));
14054
+ (((_e = eventPublishedSeeding === null || eventPublishedSeeding === void 0 ? void 0 : eventPublishedSeeding.drawIds) === null || _e === void 0 ? void 0 : _e.length) === 0 || ((_f = eventPublishedSeeding === null || eventPublishedSeeding === void 0 ? void 0 : eventPublishedSeeding.drawIds) === null || _f === void 0 ? void 0 : _f.includes(drawId))));
14080
14055
  var _loop_6 = function (entry) {
14081
14056
  var entryStatus = entry.entryStatus, entryStage = entry.entryStage, entryPosition = entry.entryPosition, participantId = entry.participantId;
14082
14057
  // get event ranking
@@ -14095,19 +14070,13 @@ function getParticipantEntries(params) {
14095
14070
  var includeSeeding = withSeeding && seedingPublished;
14096
14071
  var seedAssignments = includeSeeding ? {} : undefined;
14097
14072
  var mainSeeding = includeSeeding
14098
- ? ((_b = mainSeedingMap === null || mainSeedingMap === void 0 ? void 0 : mainSeedingMap[participantId]) === null || _b === void 0 ? void 0 : _b.seedValue) ||
14099
- ((_c = mainSeedingMap === null || mainSeedingMap === void 0 ? void 0 : mainSeedingMap[participantId]) === null || _c === void 0 ? void 0 : _c.seedNumber)
14100
- : undefined;
14101
- var mainSeedingAssignments = mainSeeding
14102
- ? mainSeedingMap === null || mainSeedingMap === void 0 ? void 0 : mainSeedingMap[participantId]
14073
+ ? ((_b = mainSeedingMap === null || mainSeedingMap === void 0 ? void 0 : mainSeedingMap[participantId]) === null || _b === void 0 ? void 0 : _b.seedValue) || ((_c = mainSeedingMap === null || mainSeedingMap === void 0 ? void 0 : mainSeedingMap[participantId]) === null || _c === void 0 ? void 0 : _c.seedNumber)
14103
14074
  : undefined;
14075
+ var mainSeedingAssignments = mainSeeding ? mainSeedingMap === null || mainSeedingMap === void 0 ? void 0 : mainSeedingMap[participantId] : undefined;
14104
14076
  var qualifyingSeeding = includeSeeding
14105
- ? ((_d = qualifyingSeedingMap === null || qualifyingSeedingMap === void 0 ? void 0 : qualifyingSeedingMap[participantId]) === null || _d === void 0 ? void 0 : _d.seedValue) ||
14106
- ((_e = qualifyingSeedingMap === null || qualifyingSeedingMap === void 0 ? void 0 : qualifyingSeedingMap[participantId]) === null || _e === void 0 ? void 0 : _e.seedNumber)
14107
- : undefined;
14108
- var qualifyingSeedingAssignments = qualifyingSeeding
14109
- ? qualifyingSeedingMap === null || qualifyingSeedingMap === void 0 ? void 0 : qualifyingSeedingMap[participantId]
14077
+ ? ((_d = qualifyingSeedingMap === null || qualifyingSeedingMap === void 0 ? void 0 : qualifyingSeedingMap[participantId]) === null || _d === void 0 ? void 0 : _d.seedValue) || ((_e = qualifyingSeedingMap === null || qualifyingSeedingMap === void 0 ? void 0 : qualifyingSeedingMap[participantId]) === null || _e === void 0 ? void 0 : _e.seedNumber)
14110
14078
  : undefined;
14079
+ var qualifyingSeedingAssignments = qualifyingSeeding ? qualifyingSeedingMap === null || qualifyingSeedingMap === void 0 ? void 0 : qualifyingSeedingMap[participantId] : undefined;
14111
14080
  if (seedAssignments && mainSeeding)
14112
14081
  seedAssignments[MAIN] = mainSeedingAssignments;
14113
14082
  if (seedAssignments && qualifyingSeeding)
@@ -14125,10 +14094,7 @@ function getParticipantEntries(params) {
14125
14094
  if (seedAssignments) {
14126
14095
  if (!participantMap[id].events[eventId].seedAssignments)
14127
14096
  participantMap[id].events[eventId].seedAssignments = {};
14128
- Object.keys(seedAssignments).forEach(function (stage) {
14129
- return (participantMap[id].events[eventId].seedAssignments[stage] =
14130
- seedAssignments[stage]);
14131
- });
14097
+ Object.keys(seedAssignments).forEach(function (stage) { return (participantMap[id].events[eventId].seedAssignments[stage] = seedAssignments[stage]); });
14132
14098
  }
14133
14099
  }
14134
14100
  if (withDraws || withRankingProfile) {
@@ -14146,8 +14112,7 @@ function getParticipantEntries(params) {
14146
14112
  };
14147
14113
  if (![UNGROUPED, UNPAIRED].includes(entryStatus)) {
14148
14114
  addDrawEntry(participantId);
14149
- var individualParticipantIds = participantMap[participantId].participant
14150
- .individualParticipantIds || [];
14115
+ var individualParticipantIds = participantMap[participantId].participant.individualParticipantIds || [];
14151
14116
  // add for individualParticipantIds when participantType is TEAM/PAIR
14152
14117
  individualParticipantIds === null || individualParticipantIds === void 0 ? void 0 : individualParticipantIds.forEach(addDrawEntry);
14153
14118
  }
@@ -14255,12 +14220,8 @@ function getParticipantEntries(params) {
14255
14220
  }
14256
14221
  finally { if (e_7) throw e_7.error; }
14257
14222
  }
14258
- if (Array.isArray(potentialParticipants) &&
14259
- (nextMatchUps || !!scheduleAnalysis || withScheduleItems)) {
14260
- var potentialParticipantIds = potentialParticipants
14261
- .flat()
14262
- .map(extractAttributes('participantId'))
14263
- .filter(Boolean);
14223
+ if (Array.isArray(potentialParticipants) && (nextMatchUps || !!scheduleAnalysis || withScheduleItems)) {
14224
+ var potentialParticipantIds = potentialParticipants.flat().map(xa('participantId')).filter(Boolean);
14264
14225
  potentialParticipantIds === null || potentialParticipantIds === void 0 ? void 0 : potentialParticipantIds.forEach(function (participantId) {
14265
14226
  var relevantParticipantIds = getRelevantParticipantIds(participantId);
14266
14227
  relevantParticipantIds === null || relevantParticipantIds === void 0 ? void 0 : relevantParticipantIds.forEach(function (relevantParticipantId) {
@@ -14350,8 +14311,7 @@ function getParticipantEntries(params) {
14350
14311
  };
14351
14312
  var _loop_7 = function (drawId) {
14352
14313
  var _11 = derivedDrawInfo[drawId] || {}, _12 = _11.orderedStructureIds, orderedStructureIds = _12 === void 0 ? [] : _12, flightNumber = _11.flightNumber;
14353
- if (participantAggregator.structureParticipation &&
14354
- orderedStructureIds.length) {
14314
+ if (participantAggregator.structureParticipation && orderedStructureIds.length) {
14355
14315
  var finishingPositionRange_1;
14356
14316
  var nonQualifyingOrder_1 = 0;
14357
14317
  // structures in which a participant participants/exits
@@ -14361,26 +14321,19 @@ function getParticipantEntries(params) {
14361
14321
  if (!participation)
14362
14322
  return;
14363
14323
  if (!finishingPositionRange_1)
14364
- finishingPositionRange_1 =
14365
- participation === null || participation === void 0 ? void 0 : participation.finishingPositionRange;
14366
- if (diff_1(finishingPositionRange_1) >
14367
- diff_1(participation === null || participation === void 0 ? void 0 : participation.finishingPositionRange))
14368
- finishingPositionRange_1 =
14369
- participation === null || participation === void 0 ? void 0 : participation.finishingPositionRange;
14324
+ finishingPositionRange_1 = participation === null || participation === void 0 ? void 0 : participation.finishingPositionRange;
14325
+ if (diff_1(finishingPositionRange_1) > diff_1(participation === null || participation === void 0 ? void 0 : participation.finishingPositionRange))
14326
+ finishingPositionRange_1 = participation === null || participation === void 0 ? void 0 : participation.finishingPositionRange;
14370
14327
  var notQualifying = participation.stage !== QUALIFYING;
14371
14328
  if (notQualifying)
14372
14329
  nonQualifyingOrder_1 += 1;
14373
- var participationOrder = notQualifying
14374
- ? nonQualifyingOrder_1
14375
- : undefined;
14330
+ var participationOrder = notQualifying ? nonQualifyingOrder_1 : undefined;
14376
14331
  return definedAttributes(__assign(__assign({}, participation), { participationOrder: participationOrder, flightNumber: flightNumber }));
14377
14332
  })
14378
14333
  .filter(Boolean);
14379
14334
  if (participantAggregator.draws[drawId]) {
14380
- participantAggregator.draws[drawId].finishingPositionRange =
14381
- finishingPositionRange_1;
14382
- participantAggregator.draws[drawId].structureParticipation =
14383
- orderedParticipation;
14335
+ participantAggregator.draws[drawId].finishingPositionRange = finishingPositionRange_1;
14336
+ participantAggregator.draws[drawId].structureParticipation = orderedParticipation;
14384
14337
  }
14385
14338
  }
14386
14339
  };
@@ -14399,9 +14352,7 @@ function getParticipantEntries(params) {
14399
14352
  }
14400
14353
  }
14401
14354
  if (scheduleAnalysis) {
14402
- var scheduledMinutesDifference = isObject(scheduleAnalysis)
14403
- ? scheduleAnalysis.scheduledMinutesDifference
14404
- : 0;
14355
+ var scheduledMinutesDifference = isObject(scheduleAnalysis) ? scheduleAnalysis.scheduledMinutesDifference : 0;
14405
14356
  // iterate through participantAggregator.scheduleItems
14406
14357
  var scheduleItems = participantAggregator.scheduleItems || [];
14407
14358
  var potentialMatchUps = participantAggregator.potentialMatchUps || {};
@@ -14425,19 +14376,15 @@ function getParticipantEntries(params) {
14425
14376
  for (var scheduleItemsToConsider_1 = (e_10 = void 0, __values(scheduleItemsToConsider)), scheduleItemsToConsider_1_1 = scheduleItemsToConsider_1.next(); !scheduleItemsToConsider_1_1.done; scheduleItemsToConsider_1_1 = scheduleItemsToConsider_1.next()) {
14426
14377
  var consideredItem = scheduleItemsToConsider_1_1.value;
14427
14378
  var ignoreItem = consideredItem.matchUpId === scheduleItem.matchUpId ||
14428
- ([WALKOVER$2, DEFAULTED].includes(consideredItem.matchUpStatus) &&
14429
- !consideredItem.checkScoreHasValue);
14379
+ ([WALKOVER$2, DEFAULTED].includes(consideredItem.matchUpStatus) && !consideredItem.checkScoreHasValue);
14430
14380
  if (ignoreItem)
14431
14381
  continue;
14432
14382
  // if there is a matchType change (SINGLES => DOUBLES or vice versa) then there is potentially a different timeAfterRecovery
14433
14383
  var typeChange = scheduleItem.matchUpType !== consideredItem.matchUpType;
14434
- var notBeforeTime = typeChange
14435
- ? typeChangeTimeAfterRecovery || timeAfterRecovery
14436
- : timeAfterRecovery;
14384
+ var notBeforeTime = typeChange ? typeChangeTimeAfterRecovery || timeAfterRecovery : timeAfterRecovery;
14437
14385
  // if two matchUps are both potentials and both part of the same draw they cannot be considered in conflict
14438
14386
  var sameDraw = scheduleItem.drawId === consideredItem.drawId;
14439
- var bothPotential = potentialMatchUps[scheduleItem.matchUpId] &&
14440
- potentialMatchUps[consideredItem.matchUpId];
14387
+ var bothPotential = potentialMatchUps[scheduleItem.matchUpId] && potentialMatchUps[consideredItem.matchUpId];
14441
14388
  var consideredMinutes = timeStringMinutes(consideredItem.scheduledTime);
14442
14389
  var minutesDifference = Math.abs(consideredMinutes - scheduledMinutes);
14443
14390
  var itemIsPrior = consideredMinutes >= scheduledMinutes;
@@ -14446,14 +14393,10 @@ function getParticipantEntries(params) {
14446
14393
  // 2. A scheduledTime occurring before a prior matchUps notBeforeTime (timeAfterRecovery)
14447
14394
  var timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference)
14448
14395
  ? minutesDifference <= scheduledMinutesDifference
14449
- : itemIsPrior &&
14450
- timeStringMinutes(consideredItem.scheduledTime) <
14451
- timeStringMinutes(notBeforeTime);
14396
+ : itemIsPrior && timeStringMinutes(consideredItem.scheduledTime) < timeStringMinutes(notBeforeTime);
14452
14397
  // if there is a time overlap capture both the prior matchUpId and the conflicted matchUpId
14453
14398
  if (timeOverlap && !(bothPotential && sameDraw) && itemIsPrior) {
14454
- var key = [scheduleItem.matchUpId, consideredItem.matchUpId]
14455
- .sort(stringSort)
14456
- .join('|');
14399
+ var key = [scheduleItem.matchUpId, consideredItem.matchUpId].sort(stringSort).join('|');
14457
14400
  participantAggregator.scheduleConflicts[key] = {
14458
14401
  priorScheduledMatchUpId: scheduleItem.matchUpId,
14459
14402
  matchUpIdWithConflict: consideredItem.matchUpId,
@@ -14481,8 +14424,7 @@ function getParticipantEntries(params) {
14481
14424
  if (Object.keys(participantAggregator.scheduleConflicts).length) {
14482
14425
  participantIdsWithConflicts.push(pid);
14483
14426
  }
14484
- participantMap[pid].scheduleConflicts =
14485
- participantAggregator.scheduleConflicts;
14427
+ participantMap[pid].scheduleConflicts = participantAggregator.scheduleConflicts;
14486
14428
  }
14487
14429
  };
14488
14430
  try {
@@ -15200,28 +15142,23 @@ function removeEventEntries(_a) {
15200
15142
  var stack = 'removeEventEntries';
15201
15143
  if (!(event === null || event === void 0 ? void 0 : event.eventId))
15202
15144
  return { error: MISSING_EVENT };
15203
- if (!Array.isArray(participantIds) ||
15204
- participantIds.some(function (participantId) { return !isString(participantId); })) {
15145
+ if (!Array.isArray(participantIds) || participantIds.some(function (participantId) { return !isString(participantId); })) {
15205
15146
  return decorateResult({ result: { error: INVALID_PARTICIPANT_ID }, stack: stack });
15206
15147
  }
15207
15148
  // do not filter by stages; must kmow all participantIds assigned to any stage!
15208
15149
  var assignedParticipantIds = ((_b = event.drawDefinitions) !== null && _b !== void 0 ? _b : []).flatMap(function (drawDefinition) { var _a; return (_a = getAssignedParticipantIds({ drawDefinition: drawDefinition }).assignedParticipantIds) !== null && _a !== void 0 ? _a : []; });
15209
15150
  var statusParticipantIds = (((entryStatuses === null || entryStatuses === void 0 ? void 0 : entryStatuses.length) &&
15210
- ((_c = event.entries) === null || _c === void 0 ? void 0 : _c.filter(function (entry) {
15211
- return entry.entryStatus && entryStatuses.includes(entry.entryStatus);
15212
- }))) ||
15151
+ ((_c = event.entries) === null || _c === void 0 ? void 0 : _c.filter(function (entry) { return entry.entryStatus && entryStatuses.includes(entry.entryStatus); }))) ||
15213
15152
  [])
15214
- .map(extractAttributes('participantId'))
15153
+ .map(xa('participantId'))
15215
15154
  .filter(function (participantId) { return !assignedParticipantIds.includes(participantId); });
15216
- var stageParticipantIds = ((stage &&
15217
- ((_d = event.entries) === null || _d === void 0 ? void 0 : _d.filter(function (entry) { return entry.entryStage && entry.entryStage === stage; }))) ||
15155
+ var stageParticipantIds = ((stage && ((_d = event.entries) === null || _d === void 0 ? void 0 : _d.filter(function (entry) { return entry.entryStage && entry.entryStage === stage; }))) ||
15218
15156
  [])
15219
- .map(extractAttributes('participantId'))
15157
+ .map(xa('participantId'))
15220
15158
  .filter(function (participantId) { return !assignedParticipantIds.includes(participantId); });
15221
15159
  if (participantIds.length) {
15222
15160
  participantIds = participantIds.filter(function (participantId) {
15223
- return (!(entryStatuses === null || entryStatuses === void 0 ? void 0 : entryStatuses.length) ||
15224
- statusParticipantIds.includes(participantId)) &&
15161
+ return (!(entryStatuses === null || entryStatuses === void 0 ? void 0 : entryStatuses.length) || statusParticipantIds.includes(participantId)) &&
15225
15162
  (!stage || stageParticipantIds.includes(participantId));
15226
15163
  });
15227
15164
  }
@@ -15235,9 +15172,7 @@ function removeEventEntries(_a) {
15235
15172
  participantIds = stageParticipantIds;
15236
15173
  }
15237
15174
  if ((participantIds === null || participantIds === void 0 ? void 0 : participantIds.length) &&
15238
- assignedParticipantIds.some(function (participantId) {
15239
- return participantIds.includes(participantId);
15240
- })) {
15175
+ assignedParticipantIds.some(function (participantId) { return participantIds.includes(participantId); })) {
15241
15176
  return decorateResult({
15242
15177
  result: { error: EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT },
15243
15178
  stack: stack,
@@ -17114,8 +17049,7 @@ function getDrawData(params) {
17114
17049
  var structureId = structure === null || structure === void 0 ? void 0 : structure.structureId;
17115
17050
  var seedAssignments = [];
17116
17051
  // pass seedAssignments from { stageSequence: 1 } to other stages
17117
- if (structure.stage &&
17118
- [MAIN, CONSOLATION, PLAY_OFF].includes(structure.stage)) {
17052
+ if (structure.stage && [MAIN, CONSOLATION, PLAY_OFF].includes(structure.stage)) {
17119
17053
  seedAssignments = mainStageSeedAssignments;
17120
17054
  }
17121
17055
  if ((structure === null || structure === void 0 ? void 0 : structure.stage) === QUALIFYING) {
@@ -17123,9 +17057,7 @@ function getDrawData(params) {
17123
17057
  }
17124
17058
  var _b = getAllStructureMatchUps({
17125
17059
  // only propagate seedAssignments where none are present
17126
- seedAssignments: !((_a = structure === null || structure === void 0 ? void 0 : structure.seedAssignments) === null || _a === void 0 ? void 0 : _a.length)
17127
- ? seedAssignments
17128
- : undefined,
17060
+ seedAssignments: !((_a = structure === null || structure === void 0 ? void 0 : structure.seedAssignments) === null || _a === void 0 ? void 0 : _a.length) ? seedAssignments : undefined,
17129
17061
  context: __assign({ drawId: drawInfo.drawId }, context),
17130
17062
  tournamentParticipants: tournamentParticipants,
17131
17063
  policyDefinitions: policyDefinitions,
@@ -17140,7 +17072,7 @@ function getDrawData(params) {
17140
17072
  var positionAssignments = getPositionAssignments$1({
17141
17073
  structure: structure,
17142
17074
  }).positionAssignments;
17143
- var participantResults = positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.filter(extractAttributes(PARTICIPANT_ID)).map(function (assignment) {
17075
+ var participantResults = positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.filter(xa(PARTICIPANT_ID)).map(function (assignment) {
17144
17076
  participantPlacements = true;
17145
17077
  var drawPosition = assignment.drawPosition, participantId = assignment.participantId;
17146
17078
  var extension = findExtension({
@@ -17180,14 +17112,10 @@ function getDrawData(params) {
17180
17112
  DOUBLE_DEFAULT,
17181
17113
  DOUBLE_WALKOVER,
17182
17114
  ].includes(matchUp.matchUpStatus);
17183
- return (active ||
17184
- activeMatchUpStatus ||
17185
- !!matchUp.winningSide ||
17186
- !!((_a = matchUp.score) === null || _a === void 0 ? void 0 : _a.scoreStringSide1));
17115
+ return active || activeMatchUpStatus || !!matchUp.winningSide || !!((_a = matchUp.score) === null || _a === void 0 ? void 0 : _a.scoreStringSide1);
17187
17116
  }, false);
17188
17117
  var structureCompleted = matchUps.reduce(function (completed, matchUp) {
17189
- return (completed &&
17190
- [BYE, COMPLETED$1, RETIRED$1, WALKOVER$2, DEFAULTED, ABANDONED$1].includes(matchUp.matchUpStatus));
17118
+ return completed && [BYE, COMPLETED$1, RETIRED$1, WALKOVER$2, DEFAULTED, ABANDONED$1].includes(matchUp.matchUpStatus);
17191
17119
  }, !!matchUps.length);
17192
17120
  structureInfo.structureCompleted = structureCompleted;
17193
17121
  completedStructures[structureId] = structureCompleted;
@@ -18301,17 +18229,6 @@ function assignMatchUpDrawPosition(_a) {
18301
18229
  }
18302
18230
  }
18303
18231
 
18304
- function getNumericSeedValue(seedValue) {
18305
- if (!seedValue)
18306
- return Infinity;
18307
- if (isConvertableInteger(seedValue))
18308
- return ensureInt(seedValue);
18309
- var firstValue = seedValue.split('-')[0];
18310
- if (isConvertableInteger(firstValue))
18311
- return ensureInt(firstValue);
18312
- return Infinity;
18313
- }
18314
-
18315
18232
  function getRoundRobinGroupMatchUps(_a) {
18316
18233
  var drawPositions = _a.drawPositions;
18317
18234
  var positionMatchUps = function (position) {
@@ -18664,6 +18581,17 @@ function getSeedingThresholds(_a) {
18664
18581
  return __assign(__assign({}, SUCCESS), { seedingThresholds: seedingThresholds });
18665
18582
  }
18666
18583
 
18584
+ function getNumericSeedValue(seedValue) {
18585
+ if (!seedValue)
18586
+ return Infinity;
18587
+ if (isConvertableInteger(seedValue))
18588
+ return ensureInt(seedValue);
18589
+ var firstValue = seedValue.split('-')[0];
18590
+ if (isConvertableInteger(firstValue))
18591
+ return ensureInt(firstValue);
18592
+ return Infinity;
18593
+ }
18594
+
18667
18595
  function getDivisions(_a) {
18668
18596
  var size = _a.size;
18669
18597
  var divisions = [size];
@@ -18713,7 +18641,7 @@ function generateBlockPattern(_a) {
18713
18641
  var firstMember = function (arr) { return arr[0]; };
18714
18642
  var lastMember = function (arr) { return arr[arr.length - 1]; };
18715
18643
  var getMember = function (arr, i) {
18716
- return (positioning === CLUSTER && i % 2 ? lastMember(arr) : firstMember(arr)) ||
18644
+ return (positioning && [CLUSTER, WATERFALL].includes(positioning) && i % 2 ? lastMember(arr) : firstMember(arr)) ||
18717
18645
  firstMember(arr);
18718
18646
  };
18719
18647
  var noneSelected = function (chunk, i) {
@@ -18828,9 +18756,7 @@ function getValidSeedBlocks(_a) {
18828
18756
  var firstRoundSeedsCount = isLuckyStructure
18829
18757
  ? 0
18830
18758
  : (!isFeedIn && countLimit) ||
18831
- (countLimit &&
18832
- fedSeedBlockPositions.length < countLimit &&
18833
- countLimit - fedSeedBlockPositions.length) ||
18759
+ (countLimit && fedSeedBlockPositions.length < countLimit && countLimit - fedSeedBlockPositions.length) ||
18834
18760
  0;
18835
18761
  if (qualifyingBlocks) {
18836
18762
  var seedingBlocksCount = (structure === null || structure === void 0 ? void 0 : structure.matchUps)
@@ -18955,9 +18881,7 @@ function getSeedBlockPattern(_a) {
18955
18881
  var block = drawPositionBlocks[blockIndex].slice();
18956
18882
  var consideredDrawPositions = block.filter(function (drawPosition, i) { return relativePositions.includes(i + 1) && drawPosition; });
18957
18883
  if (positioning !== WATERFALL) {
18958
- consideredDrawPositions = nonRandom
18959
- ? consideredDrawPositions
18960
- : shuffleArray(consideredDrawPositions);
18884
+ consideredDrawPositions = nonRandom ? consideredDrawPositions : shuffleArray(consideredDrawPositions);
18961
18885
  }
18962
18886
  else if (i % 2) {
18963
18887
  consideredDrawPositions.reverse();
@@ -18966,8 +18890,8 @@ function getSeedBlockPattern(_a) {
18966
18890
  if (drawPosition) {
18967
18891
  assignedPositions.push(drawPosition);
18968
18892
  validSeedBlocks.push({
18969
- seedNumbers: [seedNumber],
18970
18893
  drawPositions: [drawPosition],
18894
+ seedNumbers: [seedNumber],
18971
18895
  });
18972
18896
  }
18973
18897
  });
@@ -19026,9 +18950,7 @@ function isValidSeedPosition(_a) {
19026
18950
  if ((_d = (_c = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.seeding) === null || _c === void 0 ? void 0 : _c.validSeedPositions) === null || _d === void 0 ? void 0 : _d.ignore)
19027
18951
  return true;
19028
18952
  if ((_f = (_e = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.seeding) === null || _e === void 0 ? void 0 : _e.validSeedPositions) === null || _f === void 0 ? void 0 : _f.strict) {
19029
- var targetSeedBlock = validSeedBlocks.find(function (seedBlock) {
19030
- return seedBlock.seedNumbers.includes(seedNumber);
19031
- });
18953
+ var targetSeedBlock = validSeedBlocks.find(function (seedBlock) { return seedBlock.seedNumbers.includes(seedNumber); });
19032
18954
  var validSeedPositions_1 = (targetSeedBlock === null || targetSeedBlock === void 0 ? void 0 : targetSeedBlock.drawPositions) || [];
19033
18955
  return validSeedPositions_1.includes(drawPosition);
19034
18956
  }
@@ -19087,16 +19009,12 @@ function getNextSeedBlock(params) {
19087
19009
  return participantId;
19088
19010
  })
19089
19011
  .filter(Boolean);
19090
- var placedSeedNumbers = seedAssignments === null || seedAssignments === void 0 ? void 0 : seedAssignments.filter(function (assignment) {
19091
- return placedSeedParticipantIds === null || placedSeedParticipantIds === void 0 ? void 0 : placedSeedParticipantIds.includes(assignment.participantId);
19092
- }).map(function (assignment) { return assignment.seedNumber; });
19012
+ var placedSeedNumbers = seedAssignments === null || seedAssignments === void 0 ? void 0 : seedAssignments.filter(function (assignment) { return placedSeedParticipantIds === null || placedSeedParticipantIds === void 0 ? void 0 : placedSeedParticipantIds.includes(assignment.participantId); }).map(function (assignment) { return assignment.seedNumber; });
19093
19013
  var blockSeedNumbers = (nextSeedBlock === null || nextSeedBlock === void 0 ? void 0 : nextSeedBlock.seedNumbers) || [];
19094
19014
  // unplacedSeedNumbers and unplacedSeedNumberIds will only be used
19095
19015
  // when policy specifies that seedNumbers/seedValues must be unique
19096
19016
  var unplacedSeedNumbers = blockSeedNumbers.filter(function (seedNumber) { return !(placedSeedNumbers === null || placedSeedNumbers === void 0 ? void 0 : placedSeedNumbers.includes(seedNumber)); });
19097
- var unplacedSeedNumberIds = seedAssignments === null || seedAssignments === void 0 ? void 0 : seedAssignments.filter(function (assignment) {
19098
- return unplacedSeedNumbers.includes(assignment.seedNumber);
19099
- }).map(function (assignment) { return assignment.participantId; });
19017
+ var unplacedSeedNumberIds = seedAssignments === null || seedAssignments === void 0 ? void 0 : seedAssignments.filter(function (assignment) { return unplacedSeedNumbers.includes(assignment.seedNumber); }).map(function (assignment) { return assignment.participantId; });
19100
19018
  var duplicateSeedNumbers = (_c = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.seeding) === null || _c === void 0 ? void 0 : _c.duplicateSeedNumbers;
19101
19019
  var allowsDuplicateSeedNumbers = duplicateSeedNumbers !== undefined ? duplicateSeedNumbers : true;
19102
19020
  var unplacedSeedParticipantIds = allowsDuplicateSeedNumbers
@@ -19111,12 +19029,8 @@ function getNextSeedBlock(params) {
19111
19029
  };
19112
19030
  function randomlySelectLowestSeedValue(assignments, selectedParticipantIds) {
19113
19031
  var filteredAssignments = assignments.filter(function (assignment) { return !selectedParticipantIds.includes(assignment.participantId); });
19114
- var lowestSeedValue = Math.min.apply(Math, __spreadArray([], __read(filteredAssignments.map(function (assignment) {
19115
- return getNumericSeedValue(assignment.seedValue);
19116
- })), false));
19117
- var assignmentsWithLowestSeedValue = filteredAssignments.filter(function (assignment) {
19118
- return getNumericSeedValue(assignment.seedValue) === lowestSeedValue;
19119
- });
19032
+ var lowestSeedValue = Math.min.apply(Math, __spreadArray([], __read(filteredAssignments.map(function (assignment) { return getNumericSeedValue(assignment.seedValue); })), false));
19033
+ var assignmentsWithLowestSeedValue = filteredAssignments.filter(function (assignment) { return getNumericSeedValue(assignment.seedValue) === lowestSeedValue; });
19120
19034
  var randomizedAssignments = shuffleArray(assignmentsWithLowestSeedValue);
19121
19035
  return randomizedAssignments.pop();
19122
19036
  }
@@ -19150,9 +19064,7 @@ function assignSeed(_a) {
19150
19064
  context: { participantId: participantId },
19151
19065
  stack: stack,
19152
19066
  });
19153
- var flightsCount = event
19154
- ? (_c = (_b = getFlightProfile({ event: event }).flightProfile) === null || _b === void 0 ? void 0 : _b.flights) === null || _c === void 0 ? void 0 : _c.length
19155
- : 0;
19067
+ var flightsCount = event ? (_c = (_b = getFlightProfile({ event: event }).flightProfile) === null || _b === void 0 ? void 0 : _b.flights) === null || _c === void 0 ? void 0 : _c.length : 0;
19156
19068
  var flighted = flightsCount && flightsCount > 1;
19157
19069
  var relevantAssignment = positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.find(function (assignment) { return assignment.participantId === participantId; });
19158
19070
  var assignedDrawPosition = relevantAssignment === null || relevantAssignment === void 0 ? void 0 : relevantAssignment.drawPosition;
@@ -19178,8 +19090,7 @@ function assignSeed(_a) {
19178
19090
  var success;
19179
19091
  seedAssignments.forEach(function (assignment) {
19180
19092
  // ensure that this participantId is not assigned to any other seedNumber
19181
- if (assignment.participantId === participantId &&
19182
- assignment.seedNumber !== seedNumber) {
19093
+ if (assignment.participantId === participantId && assignment.seedNumber !== seedNumber) {
19183
19094
  assignment.participantId = undefined;
19184
19095
  }
19185
19096
  // assign participantId to target seedNumber
@@ -20128,8 +20039,8 @@ function getTieMatchUpContext(_a) {
20128
20039
  drawDefinition: drawDefinition,
20129
20040
  matchUpsMap: matchUpsMap,
20130
20041
  }).matchUp;
20131
- var sideParticipantIds = (_c = (_b = dualMatchUp === null || dualMatchUp === void 0 ? void 0 : dualMatchUp.sides) === null || _b === void 0 ? void 0 : _b.map(extractAttributes('participantId'))) !== null && _c !== void 0 ? _c : [];
20132
- var assignedParticipantIds = (_d = relevantAssignments === null || relevantAssignments === void 0 ? void 0 : relevantAssignments.map(extractAttributes('participantId'))) !== null && _d !== void 0 ? _d : [];
20042
+ var sideParticipantIds = (_c = (_b = dualMatchUp === null || dualMatchUp === void 0 ? void 0 : dualMatchUp.sides) === null || _b === void 0 ? void 0 : _b.map(xa('participantId'))) !== null && _c !== void 0 ? _c : [];
20043
+ var assignedParticipantIds = (_d = relevantAssignments === null || relevantAssignments === void 0 ? void 0 : relevantAssignments.map(xa('participantId'))) !== null && _d !== void 0 ? _d : [];
20133
20044
  var participantIds = __spreadArray(__spreadArray([], __read(sideParticipantIds), false), __read(assignedParticipantIds), false);
20134
20045
  var teamParticipants = getParticipants({
20135
20046
  tournamentRecord: tournamentRecord,
@@ -20935,12 +20846,7 @@ function assignTieMatchUpParticipantId(params) {
20935
20846
  return decorateResult({ result: { error: INVALID_SIDE_NUMBER }, stack: stack });
20936
20847
  }
20937
20848
  var inContextDualMatchUp = matchUpContext.inContextDualMatchUp, inContextTieMatchUp = matchUpContext.inContextTieMatchUp, relevantAssignments = matchUpContext.relevantAssignments, collectionPosition = matchUpContext.collectionPosition, teamParticipants = matchUpContext.teamParticipants, collectionId = matchUpContext.collectionId, matchUpType = matchUpContext.matchUpType, dualMatchUp = matchUpContext.dualMatchUp, tieFormat = matchUpContext.tieFormat;
20938
- var allTieIndividualParticipantIds = (_b = inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.sides) === null || _b === void 0 ? void 0 : _b.flatMap(function (side) {
20939
- var _a, _b;
20940
- return ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipantIds) ||
20941
- ((_b = side.participant) === null || _b === void 0 ? void 0 : _b.participantId) ||
20942
- [];
20943
- });
20849
+ var allTieIndividualParticipantIds = (_b = inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.sides) === null || _b === void 0 ? void 0 : _b.flatMap(function (side) { var _a, _b; return ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipantIds) || ((_b = side.participant) === null || _b === void 0 ? void 0 : _b.participantId) || []; });
20944
20850
  if (allTieIndividualParticipantIds === null || allTieIndividualParticipantIds === void 0 ? void 0 : allTieIndividualParticipantIds.includes(participantId)) {
20945
20851
  return decorateResult({ result: __assign({}, SUCCESS), stack: stack });
20946
20852
  }
@@ -20973,11 +20879,10 @@ function assignTieMatchUpParticipantId(params) {
20973
20879
  return { error: INVALID_PARTICIPANT_TYPE };
20974
20880
  }
20975
20881
  var relevantParticipantIds = participantType === INDIVIDUAL ? [participantId] : individualParticipantIds;
20976
- var participantTeam = (teamParticipantId &&
20977
- (teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.find(function (_a) {
20978
- var participantId = _a.participantId;
20979
- return participantId === teamParticipantId;
20980
- }))) ||
20882
+ var participantTeam = (teamParticipantId && (teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.find(function (_a) {
20883
+ var participantId = _a.participantId;
20884
+ return participantId === teamParticipantId;
20885
+ }))) ||
20981
20886
  (teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.find(function (_a) {
20982
20887
  var individualParticipantIds = _a.individualParticipantIds;
20983
20888
  return overlap(relevantParticipantIds, individualParticipantIds);
@@ -20991,7 +20896,7 @@ function assignTieMatchUpParticipantId(params) {
20991
20896
  var teamAssignment = relevantAssignments === null || relevantAssignments === void 0 ? void 0 : relevantAssignments.find(function (assignment) { return assignment.participantId === (participantTeam === null || participantTeam === void 0 ? void 0 : participantTeam.participantId); });
20992
20897
  var teamDrawPosition = teamAssignment === null || teamAssignment === void 0 ? void 0 : teamAssignment.drawPosition;
20993
20898
  var teamSide = (_o = inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.sides) === null || _o === void 0 ? void 0 : _o.find(function (side) { return side.drawPosition === teamDrawPosition; });
20994
- var sideNumber = (_p = params.sideNumber) !== null && _p !== void 0 ? _p : teamSide === null || teamSide === void 0 ? void 0 : teamSide.sideNumber;
20899
+ var sideNumber = (_p = teamSide === null || teamSide === void 0 ? void 0 : teamSide.sideNumber) !== null && _p !== void 0 ? _p : params.sideNumber;
20995
20900
  if (!tieFormat) {
20996
20901
  return { error: MISSING_TIE_FORMAT };
20997
20902
  }
@@ -21022,9 +20927,7 @@ function assignTieMatchUpParticipantId(params) {
21022
20927
  var assignedParticipantIds = targetAssignments === null || targetAssignments === void 0 ? void 0 : targetAssignments.map(function (assignment) { return assignment === null || assignment === void 0 ? void 0 : assignment.participantId; });
21023
20928
  // participantIds is an array of ids for individual team participants whose assignments should be modified
21024
20929
  var participantIds = ((assignedParticipantIds === null || assignedParticipantIds === void 0 ? void 0 : assignedParticipantIds.length) > 1 && assignedParticipantIds) ||
21025
- (participantType === PAIR
21026
- ? participantToAssign.individualParticipantIds
21027
- : [participantId]);
20930
+ (participantType === PAIR ? participantToAssign.individualParticipantIds : [participantId]);
21028
20931
  // first filter out any collectionAssignment with equivalent collectionId/collectionPosition/participantId
21029
20932
  var removeResult = removeCollectionAssignments({
21030
20933
  collectionPosition: collectionPosition,
@@ -21228,8 +21131,7 @@ function removeTieMatchUpParticipantId(params) {
21228
21131
  if (!side)
21229
21132
  return decorateResult({ result: { error: PARTICIPANT_NOT_FOUND }, stack: stack });
21230
21133
  if (!((_g = side.substitutions) === null || _g === void 0 ? void 0 : _g.length) &&
21231
- (checkScoreHasValue({ score: inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.score }) ||
21232
- (inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.winningSide)))
21134
+ (checkScoreHasValue({ score: inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.score }) || (inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.winningSide)))
21233
21135
  return decorateResult({ result: { error: EXISTING_OUTCOME }, stack: stack });
21234
21136
  var teamParticipantId = (_j = (_h = inContextDualMatchUp === null || inContextDualMatchUp === void 0 ? void 0 : inContextDualMatchUp.sides) === null || _h === void 0 ? void 0 : _h.find(function (_a) {
21235
21137
  var sideNumber = _a.sideNumber;
@@ -21247,9 +21149,7 @@ function removeTieMatchUpParticipantId(params) {
21247
21149
  if (matchUpType === SINGLES && participantToRemove.participantType === PAIR) {
21248
21150
  return decorateResult({ result: { error: INVALID_PARTICIPANT }, stack: stack });
21249
21151
  }
21250
- var participantIds = participantToRemove.participantType === INDIVIDUAL
21251
- ? [participantId]
21252
- : participantToRemove.individualParticipantIds;
21152
+ var participantIds = participantToRemove.participantType === INDIVIDUAL ? [participantId] : participantToRemove.individualParticipantIds;
21253
21153
  ensureSideLineUps({
21254
21154
  tournamentId: tournamentRecord.tournamentId,
21255
21155
  eventId: event.eventId,
@@ -21261,11 +21161,10 @@ function removeTieMatchUpParticipantId(params) {
21261
21161
  var sideNumber = _a.sideNumber;
21262
21162
  return sideNumber === side.sideNumber;
21263
21163
  });
21264
- if (!dualMatchUpSide &&
21265
- (((_o = dualMatchUp.sides) === null || _o === void 0 ? void 0 : _o.filter(function (_a) {
21266
- var lineUp = _a.lineUp;
21267
- return !lineUp;
21268
- }).length) || 0) < 2) {
21164
+ if (!dualMatchUpSide && (((_o = dualMatchUp.sides) === null || _o === void 0 ? void 0 : _o.filter(function (_a) {
21165
+ var lineUp = _a.lineUp;
21166
+ return !lineUp;
21167
+ }).length) || 0) < 2) {
21269
21168
  var drawPositionMap_1 = teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.map(function (_a) {
21270
21169
  var _b;
21271
21170
  var teamParticipantId = _a.participantId;
@@ -21279,7 +21178,8 @@ function removeTieMatchUpParticipantId(params) {
21279
21178
  return ((_a = drawPositionMap_1 === null || drawPositionMap_1 === void 0 ? void 0 : drawPositionMap_1.find(function (_a) {
21280
21179
  var drawPosition = _a.drawPosition;
21281
21180
  return drawPosition === side.drawPosition;
21282
- })) === null || _a === void 0 ? void 0 : _a.teamParticipantId) === teamParticipantId;
21181
+ })) === null || _a === void 0 ? void 0 : _a.teamParticipantId) ===
21182
+ teamParticipantId;
21283
21183
  });
21284
21184
  }
21285
21185
  if (!dualMatchUpSide) {
@@ -21306,8 +21206,7 @@ function removeTieMatchUpParticipantId(params) {
21306
21206
  });
21307
21207
  // if an INDIVIDUAL participant is being removed from a DOUBLES matchUp
21308
21208
  // ...then the PAIR participant may need to be modified
21309
- if (matchUpType === DOUBLES &&
21310
- participantToRemove.participantType === INDIVIDUAL) {
21209
+ if (matchUpType === DOUBLES && participantToRemove.participantType === INDIVIDUAL) {
21311
21210
  var tieMatchUpSide = (_q = inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.sides) === null || _q === void 0 ? void 0 : _q.find(function (side) { return side.sideNumber === (dualMatchUpSide === null || dualMatchUpSide === void 0 ? void 0 : dualMatchUpSide.sideNumber); });
21312
21211
  var pairParticipantId = (tieMatchUpSide !== null && tieMatchUpSide !== void 0 ? tieMatchUpSide : {}).participantId;
21313
21212
  var pairParticipant = pairParticipantId &&
@@ -22734,7 +22633,7 @@ function updateTieFormat(_a) {
22734
22633
  if (change.countChange > 0) {
22735
22634
  var collectionPositionOffset = Math.max.apply(Math, __spreadArray([0], __read(matchUp.tieMatchUps
22736
22635
  .filter(function (tieMatchUp) { return tieMatchUp.collectionId === change.collectionId; })
22737
- .map(extractAttributes('collectionPosition'))), false));
22636
+ .map(xa('collectionPosition'))), false));
22738
22637
  var collectionDefinition = tieFormat.collectionDefinitions.find(function (def) { return def.collectionId === change.collectionId; });
22739
22638
  var newMatchUps = generateCollectionMatchUps({
22740
22639
  matchUpsLimit: change.countChange,
@@ -22783,7 +22682,7 @@ function getMatchUpChangesArePossible(_a) {
22783
22682
  var collectionId = _a.collectionId, countChange = _a.countChange;
22784
22683
  var toBePlayedTieMatchUpIds = matchUp.tieMatchUps
22785
22684
  .filter(function (tieMatchUp) { return tieMatchUp.collectionId === collectionId && tieMatchUp.matchUpStatus === TO_BE_PLAYED; })
22786
- .map(extractAttributes('matchUpId'));
22685
+ .map(xa('matchUpId'));
22787
22686
  var possibleToChange = toBePlayedTieMatchUpIds.length + countChange >= 0 || countChange > 0;
22788
22687
  if (!possibleToChange && countChange < 0)
22789
22688
  cannotChangeReaon = 'Insufficient TO_BE_PLAYED matchUps';
@@ -24940,7 +24839,9 @@ function getUnseededByePositions(_a) {
24940
24839
  var relevantMatchUps = structure.structureType === CONTAINER ? matchUps : firstRoundMatchUps;
24941
24840
  var relevantDrawPositions = unique([].concat.apply([], __spreadArray([], __read(relevantMatchUps.map(function (matchUp) { return matchUp.drawPositions; })), false)));
24942
24841
  var drawPositionOffset = Math.min.apply(Math, __spreadArray([], __read(relevantDrawPositions), false)) - 1;
24943
- var filledRelevantDrawPositions = filledDrawPositions === null || filledDrawPositions === void 0 ? void 0 : filledDrawPositions.filter(function (drawPosition) { return relevantDrawPositions.includes(drawPosition); });
24842
+ var filledRelevantDrawPositions = filledDrawPositions === null || filledDrawPositions === void 0 ? void 0 : filledDrawPositions.filter(function (drawPosition) {
24843
+ return relevantDrawPositions.includes(drawPosition);
24844
+ });
24944
24845
  var getHalves = function (chunk) {
24945
24846
  var halfLength = Math.ceil(chunk.length / 2);
24946
24847
  var halves = [chunk.slice(0, halfLength), chunk.slice(halfLength)];
@@ -24960,25 +24861,15 @@ function getUnseededByePositions(_a) {
24960
24861
  var _b = getHalves(greaterHalf), greaterQuarter = _b.greaterHalf, lesserQuarter = _b.lesserHalf;
24961
24862
  var shuffledQuarter = shuffleArray(greaterQuarter.flat(Infinity));
24962
24863
  var drawPosition = shuffledQuarter.pop();
24963
- var diminishedQuarter = greaterQuarter
24964
- .flat()
24965
- .filter(function (position) { return position !== drawPosition; });
24966
- var newlyFilteredChunks = __spreadArray(__spreadArray(__spreadArray([], __read(lesserHalf), false), __read(lesserQuarter), false), [
24967
- diminishedQuarter,
24968
- ], false);
24864
+ var diminishedQuarter = greaterQuarter.flat().filter(function (position) { return position !== drawPosition; });
24865
+ var newlyFilteredChunks = __spreadArray(__spreadArray(__spreadArray([], __read(lesserHalf), false), __read(lesserQuarter), false), [diminishedQuarter], false);
24969
24866
  return { newlyFilteredChunks: newlyFilteredChunks, drawPosition: drawPosition };
24970
24867
  };
24971
- var notSeedByePosition = function (drawPosition) {
24972
- return !seedOrderByePositions.includes(drawPosition);
24973
- };
24974
- var unfilledDrawPosition = function (drawPosition) {
24975
- return !(filledRelevantDrawPositions === null || filledRelevantDrawPositions === void 0 ? void 0 : filledRelevantDrawPositions.includes(drawPosition));
24976
- };
24868
+ var notSeedByePosition = function (drawPosition) { return !seedOrderByePositions.includes(drawPosition); };
24869
+ var unfilledDrawPosition = function (drawPosition) { return !(filledRelevantDrawPositions === null || filledRelevantDrawPositions === void 0 ? void 0 : filledRelevantDrawPositions.includes(drawPosition)); };
24977
24870
  var quarterSeparateBlock = function (block) {
24978
24871
  var sortedChunked = chunkArray(block.sort(numericSort), Math.ceil(block.length / 4));
24979
- var filteredChunks = sortedChunked.map(function (chunk) {
24980
- return chunk.filter(unfilledDrawPosition);
24981
- });
24872
+ var filteredChunks = sortedChunked.map(function (chunk) { return chunk.filter(unfilledDrawPosition); });
24982
24873
  var drawPositionCount = [].concat.apply([], __spreadArray([], __read(filteredChunks.flat(Infinity)), false)).length;
24983
24874
  var orderedDrawPositions = [];
24984
24875
  for (var i = 0; i < drawPositionCount; i++) {
@@ -24998,10 +24889,7 @@ function getUnseededByePositions(_a) {
24998
24889
  drawDefinition: drawDefinition,
24999
24890
  structure: structure,
25000
24891
  }).validSeedBlocks;
25001
- var validBlockDrawPositions = validSeedBlocks === null || validSeedBlocks === void 0 ? void 0 : validSeedBlocks.map(function (block) {
25002
- var _a;
25003
- return (_a = block.drawPositions) === null || _a === void 0 ? void 0 : _a.map(function (drawPosition) { return drawPosition + drawPositionOffset; });
25004
- });
24892
+ var validBlockDrawPositions = validSeedBlocks === null || validSeedBlocks === void 0 ? void 0 : validSeedBlocks.map(function (block) { var _a; return (_a = block.drawPositions) === null || _a === void 0 ? void 0 : _a.map(function (drawPosition) { return drawPosition + drawPositionOffset; }); });
25005
24893
  var unfilledSeedBlocks;
25006
24894
  if (isFeedIn) {
25007
24895
  // FEED_IN structures calculate seedDrawPositions uniquely
@@ -25014,15 +24902,10 @@ function getUnseededByePositions(_a) {
25014
24902
  var blockDrawPositions = seedBlocks.map(function (seedBlock) {
25015
24903
  return seedBlock.map(function (drawPosition) { return drawPosition + drawPositionOffset; });
25016
24904
  });
25017
- unfilledSeedBlocks = blockDrawPositions
25018
- .map(quarterSeparateBlock)
25019
- .filter(function (block) { return block.length; });
24905
+ unfilledSeedBlocks = blockDrawPositions.map(quarterSeparateBlock).filter(function (block) { return block.length; });
25020
24906
  }
25021
24907
  else if (isQualifying) {
25022
- // if qualifying don't quarter/halve separate because seeding is WATERFALL
25023
- unfilledSeedBlocks = validBlockDrawPositions === null || validBlockDrawPositions === void 0 ? void 0 : validBlockDrawPositions.map(function (block) {
25024
- return block.filter(unfilledDrawPosition);
25025
- });
24908
+ unfilledSeedBlocks = validBlockDrawPositions === null || validBlockDrawPositions === void 0 ? void 0 : validBlockDrawPositions.map(function (block) { return block.filter(unfilledDrawPosition); });
25026
24909
  }
25027
24910
  else {
25028
24911
  unfilledSeedBlocks = validBlockDrawPositions === null || validBlockDrawPositions === void 0 ? void 0 : validBlockDrawPositions.map(quarterSeparateBlock).filter(function (block) { return block.length; });
@@ -27320,7 +27203,7 @@ function findTournamentId(_a) {
27320
27203
  function createSubOrderMap(_a) {
27321
27204
  var positionAssignments = _a.positionAssignments;
27322
27205
  var subOrderArray = (positionAssignments || [])
27323
- .filter(extractAttributes(PARTICIPANT_ID))
27206
+ .filter(xa(PARTICIPANT_ID))
27324
27207
  .map(function (assignment) {
27325
27208
  var extension = findExtension({
27326
27209
  element: assignment,
@@ -31154,16 +31037,14 @@ function removeStructure(_a) {
31154
31037
  return stage === MAIN && stageSequence === 1;
31155
31038
  });
31156
31039
  var isMainStageSequence1 = structureId === (mainStageSequence1 === null || mainStageSequence1 === void 0 ? void 0 : mainStageSequence1.structureId);
31157
- var qualifyingStructureIds = structures
31158
- .filter(function (_a) {
31040
+ var qualifyingStructureIds = structures.filter(function (_a) {
31159
31041
  var stage = _a.stage;
31160
31042
  return stage === QUALIFYING;
31161
- })
31162
- .map(extractAttributes('structureId'));
31043
+ }).map(xa('structureId'));
31163
31044
  if (isMainStageSequence1 && !qualifyingStructureIds.length) {
31164
31045
  return { error: CANNOT_REMOVE_MAIN_STRUCTURE };
31165
31046
  }
31166
- var structureIds = structures.map(extractAttributes('structureId'));
31047
+ var structureIds = structures.map(xa('structureId'));
31167
31048
  var removedMatchUpIds = [];
31168
31049
  var getTargetedStructureIds = function (structureId) {
31169
31050
  var _a, _b;
@@ -31188,9 +31069,7 @@ function removeStructure(_a) {
31188
31069
  ? getQualifyingSourceStructureIds(id)
31189
31070
  : getTargetedStructureIds(id));
31190
31071
  });
31191
- var idsToRemove = isMainStageSequence1
31192
- ? relatedStructureIdsMap.get(structureId)
31193
- : [structureId];
31072
+ var idsToRemove = isMainStageSequence1 ? relatedStructureIdsMap.get(structureId) : [structureId];
31194
31073
  var _loop_1 = function () {
31195
31074
  var idBeingRemoved = idsToRemove.pop();
31196
31075
  var structure_1 = findStructure({
@@ -31201,10 +31080,7 @@ function removeStructure(_a) {
31201
31080
  var matchUpIds = getMatchUpIds(matchUps_1);
31202
31081
  removedMatchUpIds.push.apply(removedMatchUpIds, __spreadArray([], __read(matchUpIds), false));
31203
31082
  drawDefinition.links =
31204
- (_g = (_f = drawDefinition.links) === null || _f === void 0 ? void 0 : _f.filter(function (link) {
31205
- return link.source.structureId !== idBeingRemoved &&
31206
- link.target.structureId !== idBeingRemoved;
31207
- })) !== null && _g !== void 0 ? _g : [];
31083
+ (_g = (_f = drawDefinition.links) === null || _f === void 0 ? void 0 : _f.filter(function (link) { return link.source.structureId !== idBeingRemoved && link.target.structureId !== idBeingRemoved; })) !== null && _g !== void 0 ? _g : [];
31208
31084
  if (!isMainStageSequence1 ||
31209
31085
  (isMainStageSequence1 && qualifyingStructureIds.length) ||
31210
31086
  idBeingRemoved !== structureId) {
@@ -31217,8 +31093,7 @@ function removeStructure(_a) {
31217
31093
  var targetedStructureIds = idBeingRemoved &&
31218
31094
  ((_j = relatedStructureIdsMap.get(idBeingRemoved)) === null || _j === void 0 ? void 0 : _j.filter(function (id) {
31219
31095
  // IMPORTANT: only delete MAIN stageSequence: 1 if specified to protect against DOUBLE_ELIMINATION scenario
31220
- return id !== (mainStageSequence1 === null || mainStageSequence1 === void 0 ? void 0 : mainStageSequence1.structureId) ||
31221
- structureId === mainStageSequence1.structureId;
31096
+ return id !== (mainStageSequence1 === null || mainStageSequence1 === void 0 ? void 0 : mainStageSequence1.structureId) || structureId === mainStageSequence1.structureId;
31222
31097
  }));
31223
31098
  if (targetedStructureIds === null || targetedStructureIds === void 0 ? void 0 : targetedStructureIds.length)
31224
31099
  idsToRemove.push.apply(idsToRemove, __spreadArray([], __read(targetedStructureIds), false));
@@ -31229,18 +31104,16 @@ function removeStructure(_a) {
31229
31104
  // now get all remaining matchUps in the draw
31230
31105
  var matchUps = getAllDrawMatchUps({ drawDefinition: drawDefinition }).matchUps;
31231
31106
  matchUps === null || matchUps === void 0 ? void 0 : matchUps.forEach(function (matchUp) {
31232
- if (matchUp.winnerMatchUpId &&
31233
- removedMatchUpIds.includes(matchUp.winnerMatchUpId)) {
31107
+ if (matchUp.winnerMatchUpId && removedMatchUpIds.includes(matchUp.winnerMatchUpId)) {
31234
31108
  delete matchUp.winnerMatchUpId;
31235
31109
  }
31236
- if (matchUp.loserMatchUpId &&
31237
- removedMatchUpIds.includes(matchUp.loserMatchUpId)) {
31110
+ if (matchUp.loserMatchUpId && removedMatchUpIds.includes(matchUp.loserMatchUpId)) {
31238
31111
  delete matchUp.loserMatchUpId;
31239
31112
  }
31240
31113
  });
31241
31114
  // if this is MAIN stageSequence: 1 there must be qualifying, return to empty state
31242
31115
  if (isMainStageSequence1) {
31243
- var mainStageSequence1MatchUpIds = (_l = ((_k = mainStageSequence1.matchUps) !== null && _k !== void 0 ? _k : [])) === null || _l === void 0 ? void 0 : _l.map(extractAttributes('matchUpId'));
31116
+ var mainStageSequence1MatchUpIds = (_l = ((_k = mainStageSequence1.matchUps) !== null && _k !== void 0 ? _k : [])) === null || _l === void 0 ? void 0 : _l.map(xa('matchUpId'));
31244
31117
  removedMatchUpIds.push.apply(removedMatchUpIds, __spreadArray([], __read(mainStageSequence1MatchUpIds), false));
31245
31118
  mainStageSequence1.positionAssignments = [];
31246
31119
  mainStageSequence1.seedAssignments = [];
@@ -34354,9 +34227,7 @@ function attachStructures(_a) {
34354
34227
  if (newStructures.length)
34355
34228
  (_b = drawDefinition.structures).push.apply(_b, __spreadArray([], __read(newStructures), false));
34356
34229
  addGoesTo({ drawDefinition: drawDefinition });
34357
- var matchUps = structures
34358
- .map(function (structure) { var _a; return ((_a = getAllStructureMatchUps({ structure: structure })) === null || _a === void 0 ? void 0 : _a.matchUps) || []; })
34359
- .flat();
34230
+ var matchUps = structures.map(function (structure) { var _a; return ((_a = getAllStructureMatchUps({ structure: structure })) === null || _a === void 0 ? void 0 : _a.matchUps) || []; }).flat();
34360
34231
  addMatchUpsNotice({
34361
34232
  tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
34362
34233
  eventId: event === null || event === void 0 ? void 0 : event.eventId,
@@ -34388,13 +34259,8 @@ function attachStructures(_a) {
34388
34259
  Object.assign(matchUp, attribs);
34389
34260
  if (tieMatchUps === null || tieMatchUps === void 0 ? void 0 : tieMatchUps.length) {
34390
34261
  var modifiedTieMatchUpsMap_1 = {};
34391
- tieMatchUps.forEach(function (modifiedTieMatchUp) {
34392
- return (modifiedMatchUpMap_1[modifiedTieMatchUp.matchUpId] =
34393
- modifiedTieMatchUp);
34394
- });
34395
- matchUp.tieMatchUps.forEach(function (tm) {
34396
- return Object.assign(tm, modifiedTieMatchUpsMap_1[tm.matchUpId]);
34397
- });
34262
+ tieMatchUps.forEach(function (modifiedTieMatchUp) { return (modifiedMatchUpMap_1[modifiedTieMatchUp.matchUpId] = modifiedTieMatchUp); });
34263
+ matchUp.tieMatchUps.forEach(function (tm) { return Object.assign(tm, modifiedTieMatchUpsMap_1[tm.matchUpId]); });
34398
34264
  }
34399
34265
  modifiedMatchUpMap_1[matchUp.matchUpId].matchUp = matchUp;
34400
34266
  modifyMatchUpNotice(modifiedMatchUpMap_1[matchUp.matchUpId]);
@@ -34426,7 +34292,7 @@ function attachStructures(_a) {
34426
34292
  }
34427
34293
  });
34428
34294
  }
34429
- var addedStructureIds = newStructures.map(extractAttributes('structureId'));
34295
+ var addedStructureIds = newStructures.map(xa('structureId'));
34430
34296
  if (tournamentRecord) {
34431
34297
  var itemValue = { structureIds: structureIds, drawId: drawDefinition.drawId };
34432
34298
  var timeItem = {
@@ -35721,9 +35587,7 @@ function deleteAdHocMatchUps(_a) {
35721
35587
  return { error: STRUCTURE_NOT_FOUND };
35722
35588
  var existingMatchUps = structure === null || structure === void 0 ? void 0 : structure.matchUps;
35723
35589
  var structureHasRoundPositions = existingMatchUps === null || existingMatchUps === void 0 ? void 0 : existingMatchUps.find(function (matchUp) { return !!matchUp.roundPosition; });
35724
- if (structure.structures ||
35725
- structureHasRoundPositions ||
35726
- structure.finishingPosition === ROUND_OUTCOME) {
35590
+ if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
35727
35591
  return { error: INVALID_STRUCTURE };
35728
35592
  }
35729
35593
  var matchUpIdsWithScoreValue = [];
@@ -35733,7 +35597,7 @@ function deleteAdHocMatchUps(_a) {
35733
35597
  matchUpIdsWithScoreValue.push(matchUpId);
35734
35598
  return matchUpIds.includes(matchUpId);
35735
35599
  })) !== null && _d !== void 0 ? _d : [];
35736
- var matchUpIdsToDelete = matchUpsToDelete.map(extractAttributes('matchUpId'));
35600
+ var matchUpIdsToDelete = matchUpsToDelete.map(xa('matchUpId'));
35737
35601
  if (matchUpIdsToDelete.length) {
35738
35602
  structure.matchUps = ((_e = structure.matchUps) !== null && _e !== void 0 ? _e : []).filter(function (_a) {
35739
35603
  var matchUpId = _a.matchUpId;
@@ -35746,7 +35610,7 @@ function deleteAdHocMatchUps(_a) {
35746
35610
  eventId: event === null || event === void 0 ? void 0 : event.eventId,
35747
35611
  drawDefinition: drawDefinition,
35748
35612
  });
35749
- var roundNumbers = unique(structure.matchUps.map(extractAttributes('roundNumber')));
35613
+ var roundNumbers = unique(structure.matchUps.map(xa('roundNumber')));
35750
35614
  var missingRoundNumbers = getMissingSequenceNumbers(roundNumbers);
35751
35615
  if (missingRoundNumbers.length) {
35752
35616
  missingRoundNumbers.reverse();
@@ -35897,7 +35761,7 @@ function modifyTieFormat(_a) {
35897
35761
  var collectionId = _a.collectionId;
35898
35762
  return !existingCollectionIds.includes(collectionId);
35899
35763
  });
35900
- var addedCollectionIds = addedCollectionDefinitions.map(extractAttributes('collectionId'));
35764
+ var addedCollectionIds = addedCollectionDefinitions.map(xa('collectionId'));
35901
35765
  var modifications = [];
35902
35766
  var processedTieFormat;
35903
35767
  var tieFormatName = modifiedTieFormat.tieFormatName;
@@ -35987,19 +35851,13 @@ function modifyTieFormat(_a) {
35987
35851
  processedTieFormat.tieFormatName = tieFormatName;
35988
35852
  modifications.push({ tieFormatName: tieFormatName });
35989
35853
  }
35990
- else if (modifications.length ||
35991
- addedCollectionIds.length ||
35992
- removedCollectionIds.length) {
35854
+ else if (modifications.length || addedCollectionIds.length || removedCollectionIds.length) {
35993
35855
  delete processedTieFormat.tieFormatName;
35994
35856
  modifications.push('tieFormatName removed: modifications without new tieFormatName');
35995
35857
  }
35996
- processedTieFormat.collectionDefinitions =
35997
- processedTieFormat.collectionDefinitions
35998
- .sort(function (a, b) {
35999
- return numericSortValue(a.collectionOrder) -
36000
- numericSortValue(b.collectionOrder);
36001
- })
36002
- .map(function (def, i) { return (__assign(__assign({}, def), { collectionOrder: i + 1 })); });
35858
+ processedTieFormat.collectionDefinitions = processedTieFormat.collectionDefinitions
35859
+ .sort(function (a, b) { return numericSortValue(a.collectionOrder) - numericSortValue(b.collectionOrder); })
35860
+ .map(function (def, i) { return (__assign(__assign({}, def), { collectionOrder: i + 1 })); });
36003
35861
  return __assign({ processedTieFormat: copyTieFormat(processedTieFormat), modifications: modifications }, SUCCESS);
36004
35862
  }
36005
35863
 
@@ -37252,7 +37110,7 @@ function getEncounters(_a) {
37252
37110
  try {
37253
37111
  for (var matchUps_1 = __values(matchUps), matchUps_1_1 = matchUps_1.next(); !matchUps_1_1.done; matchUps_1_1 = matchUps_1.next()) {
37254
37112
  var matchUp = matchUps_1_1.value;
37255
- var participantIds = matchUp.sides.map(extractAttributes('participantId'));
37113
+ var participantIds = matchUp.sides.map(xa('participantId'));
37256
37114
  if (participantIds.length === 2) {
37257
37115
  var _c = __read(participantIds, 2), p1 = _c[0], p2 = _c[1];
37258
37116
  var pairing = pairingHash(p1, p2);
@@ -38760,10 +38618,9 @@ function addFlight(_a) {
38760
38618
  return decorateResult({ result: { error: MISSING_VALUE }, stack: stack });
38761
38619
  if (drawEntries === null || drawEntries === void 0 ? void 0 : drawEntries.length) {
38762
38620
  // check that all drawEntries are in event.entries
38763
- var enteredParticipantIds = ((_b = event.entries) !== null && _b !== void 0 ? _b : []).map(extractAttributes('participantId'));
38764
- var flightParticipantIds = drawEntries.map(extractAttributes('participantId'));
38765
- if (intersection(flightParticipantIds, enteredParticipantIds).length !==
38766
- flightParticipantIds.length) {
38621
+ var enteredParticipantIds = ((_b = event.entries) !== null && _b !== void 0 ? _b : []).map(xa('participantId'));
38622
+ var flightParticipantIds = drawEntries.map(xa('participantId'));
38623
+ if (intersection(flightParticipantIds, enteredParticipantIds).length !== flightParticipantIds.length) {
38767
38624
  return decorateResult({ result: { error: INVALID_VALUES }, stack: stack });
38768
38625
  }
38769
38626
  }
@@ -42337,7 +42194,7 @@ function generateDrawDefinition(params) {
42337
42194
  var entryStage = _a.entryStage, entryStatus = _a.entryStatus;
42338
42195
  return (!entryStage || entryStage === MAIN) && entryStatus && STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
42339
42196
  });
42340
- var participantIds_1 = entries_2 === null || entries_2 === void 0 ? void 0 : entries_2.map(extractAttributes('participantId'));
42197
+ var participantIds_1 = entries_2 === null || entries_2 === void 0 ? void 0 : entries_2.map(xa('participantId'));
42341
42198
  var matchUpsCount_1 = entries_2 ? Math.floor(entries_2.length / 2) : 0;
42342
42199
  generateRange(1, params.roundsCount + 1).forEach(function () {
42343
42200
  var _a, _b, _c;
@@ -45467,8 +45324,7 @@ function generateScheduleTimes(_a) {
45467
45324
  if (tournamentRecord && !tournamentRecords) {
45468
45325
  tournamentRecords = (_b = {}, _b[tournamentRecord.tournamentId] = tournamentRecord, _b);
45469
45326
  }
45470
- if (typeof tournamentRecords !== 'object' ||
45471
- !Object.keys(tournamentRecords).length)
45327
+ if (typeof tournamentRecords !== 'object' || !Object.keys(tournamentRecords).length)
45472
45328
  return { error: MISSING_TOURNAMENT_RECORDS };
45473
45329
  periodLength =
45474
45330
  periodLength !== null && periodLength !== void 0 ? periodLength : calculatePeriodLength({
@@ -45481,10 +45337,8 @@ function generateScheduleTimes(_a) {
45481
45337
  tournamentRecords: tournamentRecords,
45482
45338
  }), allCourts = _e.courts, venues = _e.venues;
45483
45339
  var courts = (_c = allCourts === null || allCourts === void 0 ? void 0 : allCourts.filter(function (court) { return !venueIds || venueIds.includes(court.venueId); })) !== null && _c !== void 0 ? _c : [];
45484
- startTime =
45485
- startTime !== null && startTime !== void 0 ? startTime : getDateTimeBoundary({ courts: courts, scheduleDate: scheduleDate, startTime: true });
45486
- endTime =
45487
- endTime !== null && endTime !== void 0 ? endTime : getDateTimeBoundary({ courts: courts, scheduleDate: scheduleDate, endTime: true });
45340
+ startTime = startTime !== null && startTime !== void 0 ? startTime : getDateTimeBoundary({ courts: courts, scheduleDate: scheduleDate, startTime: true });
45341
+ endTime = endTime !== null && endTime !== void 0 ? endTime : getDateTimeBoundary({ courts: courts, scheduleDate: scheduleDate, endTime: true });
45488
45342
  var _f = generateBookings({
45489
45343
  defaultRecoveryMinutes: defaultRecoveryMinutes,
45490
45344
  averageMatchUpMinutes: averageMatchUpMinutes,
@@ -45508,10 +45362,8 @@ function generateScheduleTimes(_a) {
45508
45362
  };
45509
45363
  var scheduleTimes = getScheduleTimes(timingParameters).scheduleTimes;
45510
45364
  // if a single venue specified, or only one venue available, return venueId
45511
- var venueId = ((venueIds === null || venueIds === void 0 ? void 0 : venueIds.length) === 1 && venueIds[0]) ||
45512
- ((venues === null || venues === void 0 ? void 0 : venues.length) === 1 && venues[0].venueId) ||
45513
- undefined;
45514
- var dateScheduledMatchUpIds = dateScheduledMatchUps === null || dateScheduledMatchUps === void 0 ? void 0 : dateScheduledMatchUps.map(extractAttributes('matchUpId'));
45365
+ var venueId = ((venueIds === null || venueIds === void 0 ? void 0 : venueIds.length) === 1 && venueIds[0]) || ((venues === null || venues === void 0 ? void 0 : venues.length) === 1 && venues[0].venueId) || undefined;
45366
+ var dateScheduledMatchUpIds = dateScheduledMatchUps === null || dateScheduledMatchUps === void 0 ? void 0 : dateScheduledMatchUps.map(xa('matchUpId'));
45515
45367
  return {
45516
45368
  dateScheduledMatchUpIds: dateScheduledMatchUpIds,
45517
45369
  dateScheduledMatchUps: dateScheduledMatchUps,
@@ -49331,13 +49183,9 @@ function generateFlightDrawDefinitions(_a) {
49331
49183
  var drawProfile = drawProfiles[index];
49332
49184
  var _k = drawProfile || {}, seedsCount = _k.seedsCount, _l = _k.generate, generate = _l === void 0 ? true : _l;
49333
49185
  if (generate) {
49334
- var drawParticipantIds_1 = drawEntries
49335
- .filter(extractAttributes(PARTICIPANT_ID))
49336
- .map(extractAttributes(PARTICIPANT_ID));
49186
+ var drawParticipantIds_1 = drawEntries.filter(xa(PARTICIPANT_ID)).map(xa(PARTICIPANT_ID));
49337
49187
  var seedingScaleName_1 = categoryName || eventName;
49338
- if (tournamentRecord &&
49339
- seedsCount &&
49340
- seedsCount <= drawParticipantIds_1.length) {
49188
+ if (tournamentRecord && seedsCount && seedsCount <= drawParticipantIds_1.length) {
49341
49189
  var scaleValues = generateRange(1, seedsCount + 1);
49342
49190
  scaleValues.forEach(function (scaleValue, index) {
49343
49191
  var scaleItem = {
@@ -49367,9 +49215,7 @@ function generateFlightDrawDefinitions(_a) {
49367
49215
  if (Array.isArray(drawExtensions)) {
49368
49216
  drawExtensions
49369
49217
  .filter(isValidExtension)
49370
- .forEach(function (extension) {
49371
- return addExtension({ element: drawDefinition_1, extension: extension });
49372
- });
49218
+ .forEach(function (extension) { return addExtension({ element: drawDefinition_1, extension: extension }); });
49373
49219
  }
49374
49220
  result = addDrawDefinition({
49375
49221
  suppressNotifications: true,
@@ -49415,14 +49261,10 @@ function generateFlightDrawDefinitions(_a) {
49415
49261
  });
49416
49262
  if (result_3.error)
49417
49263
  return { value: { error: result_3.error, drawIds: [] } };
49418
- var playoffCompletionGoal = completionGoal
49419
- ? completionGoal - (completedCount !== null && completedCount !== void 0 ? completedCount : 0)
49420
- : undefined;
49264
+ var playoffCompletionGoal = completionGoal ? completionGoal - (completedCount !== null && completedCount !== void 0 ? completedCount : 0) : undefined;
49421
49265
  result_3 = completeDrawMatchUps({
49422
49266
  completeAllMatchUps: !completionGoal && completeAllMatchUps,
49423
- completionGoal: completionGoal
49424
- ? playoffCompletionGoal
49425
- : undefined,
49267
+ completionGoal: completionGoal ? playoffCompletionGoal : undefined,
49426
49268
  matchUpStatusProfile: matchUpStatusProfile,
49427
49269
  randomWinningSide: randomWinningSide,
49428
49270
  tournamentRecord: tournamentRecord,
@@ -49693,7 +49535,7 @@ function generateEventWithFlights(params) {
49693
49535
  drawIds = drawDefinitionResult.drawIds;
49694
49536
  }
49695
49537
  else if ((_d = eventProfile === null || eventProfile === void 0 ? void 0 : eventProfile.participantsProfile) === null || _d === void 0 ? void 0 : _d.participantsCount) {
49696
- var eventParticipantIds = uniqueDrawParticipants.map(extractAttributes('participantId'));
49538
+ var eventParticipantIds = uniqueDrawParticipants.map(xa('participantId'));
49697
49539
  if (eventParticipantIds.length) {
49698
49540
  var result = addEventEntries({
49699
49541
  participantIds: eventParticipantIds,
@@ -51548,7 +51390,7 @@ function mergeParticipants(_a) {
51548
51390
  if (!tournamentRecord.participants)
51549
51391
  tournamentRecord.participants = [];
51550
51392
  var mappedParticipants = incomingParticipants
51551
- .filter(extractAttributes(PARTICIPANT_ID))
51393
+ .filter(xa(PARTICIPANT_ID))
51552
51394
  .map(function (p) {
51553
51395
  var _a;
51554
51396
  return (_a = {}, _a[p.participantId] = p, _a);
@@ -51564,7 +51406,7 @@ function mergeParticipants(_a) {
51564
51406
  }
51565
51407
  return participant;
51566
51408
  });
51567
- var existingParticipantIds = tournamentRecord.participants.map(extractAttributes(PARTICIPANT_ID)) || [];
51409
+ var existingParticipantIds = tournamentRecord.participants.map(xa(PARTICIPANT_ID)) || [];
51568
51410
  var newParticipants = incomingParticipants.filter(function (_a) {
51569
51411
  var participantId = _a.participantId;
51570
51412
  return !existingParticipantIds.includes(participantId);
@@ -51605,7 +51447,7 @@ function addPenalty(params) {
51605
51447
  var participants = (_e = getParticipants({
51606
51448
  tournamentRecord: tournamentRecord_1,
51607
51449
  }).participants) !== null && _e !== void 0 ? _e : [];
51608
- var tournamentParticipantIds = participants === null || participants === void 0 ? void 0 : participants.map(extractAttributes('participantId')).filter(function (participantId) { return participantIds.includes(participantId); });
51450
+ var tournamentParticipantIds = participants === null || participants === void 0 ? void 0 : participants.map(xa('participantId')).filter(function (participantId) { return participantIds.includes(participantId); });
51609
51451
  if (tournamentParticipantIds.length) {
51610
51452
  var result = penaltyAdd(__assign(__assign({}, params), { penaltyId: (_f = params.penaltyId) !== null && _f !== void 0 ? _f : penaltyId, tournamentRecord: tournamentRecord_1, participantIds: tournamentParticipantIds }));
51611
51453
  penaltyId = result.penaltyId;
@@ -51619,8 +51461,7 @@ function addPenalty(params) {
51619
51461
  }
51620
51462
  finally { if (e_1) throw e_1.error; }
51621
51463
  }
51622
- return penaltyId
51623
- ? __assign(__assign({}, SUCCESS), { penaltyId: penaltyId }) : { error: PARTICIPANT_NOT_FOUND };
51464
+ return penaltyId ? __assign(__assign({}, SUCCESS), { penaltyId: penaltyId }) : { error: PARTICIPANT_NOT_FOUND };
51624
51465
  }
51625
51466
  function penaltyAdd(_a) {
51626
51467
  var _b;
@@ -51633,9 +51474,7 @@ function penaltyAdd(_a) {
51633
51474
  return { error: MISSING_PENALTY_TYPE };
51634
51475
  // TODO: add penalty timeItem to matchUp.timeItems[]
51635
51476
  var participants = (_b = tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) !== null && _b !== void 0 ? _b : [];
51636
- var relevantParticipants = participants.filter(function (participant) {
51637
- return participantIds.includes(participant.participantId);
51638
- });
51477
+ var relevantParticipants = participants.filter(function (participant) { return participantIds.includes(participant.participantId); });
51639
51478
  if (!relevantParticipants.length)
51640
51479
  return { error: PARTICIPANT_NOT_FOUND };
51641
51480
  var createdAt = new Date().toISOString();
@@ -51649,9 +51488,7 @@ function penaltyAdd(_a) {
51649
51488
  createdAt: createdAt,
51650
51489
  });
51651
51490
  if (Array.isArray(extensions)) {
51652
- extensions.forEach(function (extension) {
51653
- return addExtension({ element: penaltyItem, extension: extension });
51654
- });
51491
+ extensions.forEach(function (extension) { return addExtension({ element: penaltyItem, extension: extension }); });
51655
51492
  }
51656
51493
  relevantParticipants.forEach(function (participant) {
51657
51494
  if (!participant.penalties)
@@ -54045,11 +53882,7 @@ function getValidLuckyLosersAction(_a) {
54045
53882
  drawPosition: drawPosition,
54046
53883
  matchUps: matchUps,
54047
53884
  }).initialRoundNumber;
54048
- var relevantLink_1 = (_g = drawDefinition.links) === null || _g === void 0 ? void 0 : _g.find(function (link) {
54049
- var _a;
54050
- return ((_a = link.target) === null || _a === void 0 ? void 0 : _a.structureId) === (structure === null || structure === void 0 ? void 0 : structure.structureId) &&
54051
- link.target.roundNumber === initialRoundNumber_1;
54052
- });
53885
+ var relevantLink_1 = (_g = drawDefinition.links) === null || _g === void 0 ? void 0 : _g.find(function (link) { var _a; return ((_a = link.target) === null || _a === void 0 ? void 0 : _a.structureId) === (structure === null || structure === void 0 ? void 0 : structure.structureId) && link.target.roundNumber === initialRoundNumber_1; });
54053
53886
  var sourceRoundNumber = (_h = relevantLink_1 === null || relevantLink_1 === void 0 ? void 0 : relevantLink_1.source) === null || _h === void 0 ? void 0 : _h.roundNumber;
54054
53887
  matchUpFilters.roundNumbers = [sourceRoundNumber];
54055
53888
  }
@@ -54059,18 +53892,14 @@ function getValidLuckyLosersAction(_a) {
54059
53892
  matchUpFilters: matchUpFilters,
54060
53893
  drawDefinition: drawDefinition,
54061
53894
  }).completedMatchUps;
54062
- var assignedParticipantIds = positionAssignments
54063
- .map(function (assignment) { return assignment.participantId; })
54064
- .filter(Boolean);
53895
+ var assignedParticipantIds = positionAssignments.map(function (assignment) { return assignment.participantId; }).filter(Boolean);
54065
53896
  var availableParticipantIds = completedMatchUps === null || completedMatchUps === void 0 ? void 0 : completedMatchUps.filter(function (_a) {
54066
53897
  var matchUpType = _a.matchUpType, winningSide = _a.winningSide;
54067
53898
  return winningSide && ((event === null || event === void 0 ? void 0 : event.eventType) !== TEAM$2 || matchUpType === TEAM$2);
54068
53899
  }).map(function (_a) {
54069
53900
  var winningSide = _a.winningSide, sides = _a.sides;
54070
53901
  return winningSide && (sides === null || sides === void 0 ? void 0 : sides[1 - (winningSide - 1)]);
54071
- }).map(extractAttributes('participantId')).filter(function (participantId) {
54072
- return participantId && !assignedParticipantIds.includes(participantId);
54073
- });
53902
+ }).map(xa('participantId')).filter(function (participantId) { return participantId && !assignedParticipantIds.includes(participantId); });
54074
53903
  availableParticipantIds === null || availableParticipantIds === void 0 ? void 0 : availableParticipantIds.forEach(function (participantId) {
54075
53904
  // ensure if 'restrictBySourceRound' is false and there are multiple links that participants aren't added multiple times
54076
53905
  if (!availableLuckyLoserParticipantIds.includes(participantId))
@@ -54090,9 +53919,7 @@ function getValidLuckyLosersAction(_a) {
54090
53919
  }
54091
53920
  finally { if (e_1) throw e_1.error; }
54092
53921
  }
54093
- var availableLuckyLosers = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) {
54094
- return availableLuckyLoserParticipantIds === null || availableLuckyLoserParticipantIds === void 0 ? void 0 : availableLuckyLoserParticipantIds.includes(participant.participantId);
54095
- });
53922
+ var availableLuckyLosers = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) { return availableLuckyLoserParticipantIds === null || availableLuckyLoserParticipantIds === void 0 ? void 0 : availableLuckyLoserParticipantIds.includes(participant.participantId); });
54096
53923
  availableLuckyLosers === null || availableLuckyLosers === void 0 ? void 0 : availableLuckyLosers.forEach(function (luckyLoser) {
54097
53924
  var _a;
54098
53925
  var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === luckyLoser.participantId; });
@@ -54248,9 +54075,7 @@ function getValidAssignmentActions(_a) {
54248
54075
  // if there are no unfilledPositions for available seeds then return all unfilled positions
54249
54076
  if (!(unfilledPositions === null || unfilledPositions === void 0 ? void 0 : unfilledPositions.length)) {
54250
54077
  unfilledPositions = positionAssignments
54251
- .filter(function (assignment) {
54252
- return !assignment.participantId && !assignment.bye && !assignment.qualifier;
54253
- })
54078
+ .filter(function (assignment) { return !assignment.participantId && !assignment.bye && !assignment.qualifier; })
54254
54079
  .map(function (assignment) { return assignment.drawPosition; });
54255
54080
  }
54256
54081
  if (!isByePosition) {
@@ -54262,9 +54087,7 @@ function getValidAssignmentActions(_a) {
54262
54087
  });
54263
54088
  }
54264
54089
  if (isWinRatioFedStructure && ignoreSeedPositions) {
54265
- var assignedParticipantIds_1 = positionAssignments
54266
- .map(function (assignment) { return assignment.participantId; })
54267
- .filter(Boolean);
54090
+ var assignedParticipantIds_1 = positionAssignments.map(function (assignment) { return assignment.participantId; }).filter(Boolean);
54268
54091
  var matchUpFilters = { structureIds: positionSourceStructureIds };
54269
54092
  var completedMatchUps = getDrawMatchUps({
54270
54093
  inContext: true,
@@ -54278,14 +54101,10 @@ function getValidAssignmentActions(_a) {
54278
54101
  return (event === null || event === void 0 ? void 0 : event.eventType) !== TEAM$2 || matchUpType === TEAM$2;
54279
54102
  })) === null || _d === void 0 ? void 0 : _d.map(function (_a) {
54280
54103
  var sides = _a.sides;
54281
- return sides === null || sides === void 0 ? void 0 : sides.map(extractAttributes('participantId'));
54282
- }).flat().filter(function (participantId) {
54283
- return participantId && !assignedParticipantIds_1.includes(participantId);
54284
- }));
54104
+ return sides === null || sides === void 0 ? void 0 : sides.map(xa('participantId'));
54105
+ }).flat().filter(function (participantId) { return participantId && !assignedParticipantIds_1.includes(participantId); }));
54285
54106
  var participantsAvailable = returnParticipants
54286
- ? tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) {
54287
- return availableParticipantIds_1 === null || availableParticipantIds_1 === void 0 ? void 0 : availableParticipantIds_1.includes(participant.participantId);
54288
- }).map(function (participant) { return makeDeepCopy(participant, undefined, true); })
54107
+ ? tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) { return availableParticipantIds_1 === null || availableParticipantIds_1 === void 0 ? void 0 : availableParticipantIds_1.includes(participant.participantId); }).map(function (participant) { return makeDeepCopy(participant, undefined, true); })
54289
54108
  : undefined;
54290
54109
  participantsAvailable === null || participantsAvailable === void 0 ? void 0 : participantsAvailable.forEach(function (participant) {
54291
54110
  var _a;
@@ -54309,9 +54128,7 @@ function getValidAssignmentActions(_a) {
54309
54128
  var availableParticipantIds_2;
54310
54129
  if (unplacedSeedAssignments === null || unplacedSeedAssignments === void 0 ? void 0 : unplacedSeedAssignments.length) {
54311
54130
  // return any valid seedAssignments
54312
- var validToAssign = unplacedSeedAssignments.filter(function (seedAssignment) {
54313
- return unplacedSeedParticipantIds === null || unplacedSeedParticipantIds === void 0 ? void 0 : unplacedSeedParticipantIds.includes(seedAssignment.participantId);
54314
- });
54131
+ var validToAssign = unplacedSeedAssignments.filter(function (seedAssignment) { return unplacedSeedParticipantIds === null || unplacedSeedParticipantIds === void 0 ? void 0 : unplacedSeedParticipantIds.includes(seedAssignment.participantId); });
54315
54132
  validToAssign.sort(validAssignmentsSort);
54316
54133
  availableParticipantIds_2 = validToAssign.map(function (assignment) { return assignment.participantId; });
54317
54134
  }
@@ -54321,9 +54138,7 @@ function getValidAssignmentActions(_a) {
54321
54138
  }
54322
54139
  // add structureId and drawPosition to the payload so the client doesn't need to discover
54323
54140
  var participantsAvailable = returnParticipants
54324
- ? tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) {
54325
- return availableParticipantIds_2.includes(participant.participantId);
54326
- }).map(function (participant) { return makeDeepCopy(participant, undefined, true); })
54141
+ ? tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) { return availableParticipantIds_2.includes(participant.participantId); }).map(function (participant) { return makeDeepCopy(participant, undefined, true); })
54327
54142
  : undefined;
54328
54143
  if (participantsAvailable === null || participantsAvailable === void 0 ? void 0 : participantsAvailable.length) {
54329
54144
  validAssignmentActions.push(definedAttributes({
@@ -54341,8 +54156,7 @@ function getValidAssignmentActions(_a) {
54341
54156
  function validAssignmentsSort(a, b) {
54342
54157
  if (a.bye)
54343
54158
  return -1;
54344
- if (getNumericSeedValue(a.seedValue) < getNumericSeedValue(b.seedValue) ||
54345
- (a.seedValue && !b.seedValue))
54159
+ if (getNumericSeedValue(a.seedValue) < getNumericSeedValue(b.seedValue) || (a.seedValue && !b.seedValue))
54346
54160
  return -1;
54347
54161
  return (a.seedNumber || 0) - (b.seedNumber || 0);
54348
54162
  }
@@ -54778,16 +54592,260 @@ var matchUpActionConstants = {
54778
54592
  END: END,
54779
54593
  };
54780
54594
 
54595
+ function collectionMatchUpActions(_a) {
54596
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
54597
+ var specifiedPolicyDefinitions = _a.specifiedPolicyDefinitions, inContextDrawMatchUps = _a.inContextDrawMatchUps, matchUpParticipantIds = _a.matchUpParticipantIds, matchUpActionsPolicy = _a.matchUpActionsPolicy, inContextMatchUp = _a.inContextMatchUp, policyActions = _a.policyActions, enforceGender = _a.enforceGender, participantId = _a.participantId, sideNumber = _a.sideNumber, matchUpId = _a.matchUpId, matchUp = _a.matchUp, drawId = _a.drawId, side = _a.side;
54598
+ var validActions = [];
54599
+ var firstFoundSide = (_b = inContextMatchUp.sides) === null || _b === void 0 ? void 0 : _b.find(function (side) { return side.participant; });
54600
+ var assignedGender = inContextMatchUp.gender === MIXED &&
54601
+ inContextMatchUp.sideNumber &&
54602
+ ((_c = inContextMatchUp.sides) === null || _c === void 0 ? void 0 : _c.filter(function (side) { return side.particiapntId; }).length) === 1 &&
54603
+ ((_e = (_d = firstFoundSide === null || firstFoundSide === void 0 ? void 0 : firstFoundSide.participant) === null || _d === void 0 ? void 0 : _d.person) === null || _e === void 0 ? void 0 : _e.sex);
54604
+ var matchUpType = inContextMatchUp.matchUpType;
54605
+ var genderEnforced = (enforceGender !== null && enforceGender !== void 0 ? enforceGender : (_f = matchUpActionsPolicy === null || matchUpActionsPolicy === void 0 ? void 0 : matchUpActionsPolicy.participants) === null || _f === void 0 ? void 0 : _f.enforceGender) !== false;
54606
+ var gender = genderEnforced ? inContextMatchUp.gender : undefined;
54607
+ var allParticipants = (_g = inContextMatchUp.sides) === null || _g === void 0 ? void 0 : _g.flatMap(function (side) { var _a; return ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants) || side.participant; }).filter(Boolean);
54608
+ var allParticipantIds = allParticipants === null || allParticipants === void 0 ? void 0 : allParticipants.map(xa('participantId'));
54609
+ var existingParticipants = (_h = inContextMatchUp.sides) === null || _h === void 0 ? void 0 : _h.filter(function (side) { return !sideNumber || side.sideNumber === sideNumber; }).flatMap(function (side) { var _a; return ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants) || side.participant; }).filter(Boolean);
54610
+ var existingParticipantIds = existingParticipants === null || existingParticipants === void 0 ? void 0 : existingParticipants.map(xa('participantId'));
54611
+ var inContextDualMatchUp = inContextDrawMatchUps === null || inContextDrawMatchUps === void 0 ? void 0 : inContextDrawMatchUps.find(function (drawMatchUp) { return drawMatchUp.matchUpId === inContextMatchUp.matchUpTieId; });
54612
+ var availableIndividualParticipants = (_j = inContextDualMatchUp === null || inContextDualMatchUp === void 0 ? void 0 : inContextDualMatchUp.sides) === null || _j === void 0 ? void 0 : _j.map(function (side) {
54613
+ var _a;
54614
+ return (_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants.filter(function (_a) {
54615
+ var participantId = _a.participantId, person = _a.person;
54616
+ return !(existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.includes(participantId)) &&
54617
+ (!gender ||
54618
+ gender === ANY ||
54619
+ person.sex === gender ||
54620
+ // case where one gendered member has been assigned
54621
+ (gender === MIXED && !assignedGender) ||
54622
+ (assignedGender && person.sex !== assignedGender));
54623
+ });
54624
+ });
54625
+ // if no sideNumber is provided, segregate available by sideNumber and specify sideNumber
54626
+ var availableParticipants = sideNumber
54627
+ ? availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants[sideNumber - 1]
54628
+ : availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants.map(function (available, i) { return ({
54629
+ participants: available,
54630
+ sideNumber: i + 1,
54631
+ }); });
54632
+ var availableParticipantIds = sideNumber
54633
+ ? (_k = availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants[sideNumber - 1]) === null || _k === void 0 ? void 0 : _k.map(getParticipantId)
54634
+ : availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants.map(function (available, i) { return ({
54635
+ participants: available === null || available === void 0 ? void 0 : available.map(getParticipantId),
54636
+ sideNumber: i + 1,
54637
+ }); });
54638
+ var assignmentAvailable = (sideNumber &&
54639
+ ((matchUpType === SINGLES_MATCHUP && !(existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length)) ||
54640
+ (matchUpType === DOUBLES_MATCHUP && ((_l = existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length) !== null && _l !== void 0 ? _l : 0) < 2))) ||
54641
+ (!sideNumber &&
54642
+ ((matchUpType === SINGLES_MATCHUP && ((_m = existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length) !== null && _m !== void 0 ? _m : 0) < 2) ||
54643
+ (matchUpType === DOUBLES_MATCHUP && ((_o = existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length) !== null && _o !== void 0 ? _o : 0) < 4)));
54644
+ // extra step to avoid edge case where individual participant is part of both teams
54645
+ var availableIds = availableParticipantIds === null || availableParticipantIds === void 0 ? void 0 : availableParticipantIds.filter(function (id) { return !(allParticipantIds === null || allParticipantIds === void 0 ? void 0 : allParticipantIds.includes(id)); });
54646
+ var available = availableParticipants === null || availableParticipants === void 0 ? void 0 : availableParticipants.filter(function (_a) {
54647
+ var participantId = _a.participantId;
54648
+ return availableIds.includes(participantId);
54649
+ });
54650
+ if (assignmentAvailable && (availableIds === null || availableIds === void 0 ? void 0 : availableIds.length)) {
54651
+ validActions.push({
54652
+ availableParticipantIds: availableIds,
54653
+ method: ASSIGN_TEAM_POSITION_METHOD,
54654
+ availableParticipants: available,
54655
+ type: ASSIGN_PARTICIPANT,
54656
+ payload: {
54657
+ participantId: undefined,
54658
+ tieMatchUpId: matchUpId,
54659
+ sideNumber: sideNumber,
54660
+ drawId: drawId,
54661
+ },
54662
+ });
54663
+ }
54664
+ if ((existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length) && (!checkScoreHasValue(matchUp) || ((_p = side === null || side === void 0 ? void 0 : side.substitutions) === null || _p === void 0 ? void 0 : _p.length))) {
54665
+ validActions.push({
54666
+ method: REMOVE_TEAM_POSITION_METHOD,
54667
+ type: REMOVE_PARTICIPANT,
54668
+ existingParticipantIds: existingParticipantIds,
54669
+ payload: {
54670
+ participantId: undefined,
54671
+ tieMatchUpId: matchUpId,
54672
+ drawId: drawId,
54673
+ },
54674
+ });
54675
+ }
54676
+ if ((available === null || available === void 0 ? void 0 : available.length) && ((!sideNumber && (existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length)) || (sideNumber && (side === null || side === void 0 ? void 0 : side.participant)))) {
54677
+ validActions.push({
54678
+ availableParticipantIds: availableIds,
54679
+ method: REPLACE_TEAM_POSITION_METHOD,
54680
+ availableParticipants: available,
54681
+ type: REPLACE_PARTICIPANT,
54682
+ existingParticipantIds: existingParticipantIds,
54683
+ payload: {
54684
+ existingParticipantId: undefined,
54685
+ participantId: undefined,
54686
+ tieMatchUpId: matchUpId,
54687
+ drawId: drawId,
54688
+ },
54689
+ });
54690
+ }
54691
+ if (isAvailableAction({ policyActions: policyActions, action: REMOVE_SUBSTITUTION }) && ((_q = side === null || side === void 0 ? void 0 : side.substitutions) === null || _q === void 0 ? void 0 : _q.length)) {
54692
+ var sideIndividualParticipantIds_1 = (((_r = side.participant) === null || _r === void 0 ? void 0 : _r.participantType) === INDIVIDUAL && [side.participantId]) ||
54693
+ (((_s = side.participant) === null || _s === void 0 ? void 0 : _s.participantType) === PAIR && side.participant.individualParticipantIds) ||
54694
+ [];
54695
+ var substitutedParticipantIds = side.substitutions
54696
+ .map(function (sub) { return sub.participantId; })
54697
+ .filter(function (id) { return sideIndividualParticipantIds_1.includes(id); });
54698
+ if (!participantId || substitutedParticipantIds.includes(participantId)) {
54699
+ validActions.push({
54700
+ method: REMOVE_TEAM_POSITION_METHOD,
54701
+ type: REMOVE_SUBSTITUTION,
54702
+ substitutedParticipantIds: substitutedParticipantIds,
54703
+ payload: {
54704
+ participantId: undefined,
54705
+ tieMatchUpId: matchUpId,
54706
+ drawId: drawId,
54707
+ },
54708
+ });
54709
+ }
54710
+ }
54711
+ var matchUpActionPolicy = specifiedPolicyDefinitions === null || specifiedPolicyDefinitions === void 0 ? void 0 : specifiedPolicyDefinitions[POLICY_TYPE_MATCHUP_ACTIONS];
54712
+ var substituteWithoutScore = matchUpActionPolicy === null || matchUpActionPolicy === void 0 ? void 0 : matchUpActionPolicy.substituteWithoutScore;
54713
+ var substituteAfterCompleted = matchUpActionPolicy === null || matchUpActionPolicy === void 0 ? void 0 : matchUpActionPolicy.substituteAfterCompleted;
54714
+ // SUBSTITUTION
54715
+ // substitution is only possible when both sides are present; otherwise => nonsensical
54716
+ if (isAvailableAction({ policyActions: policyActions, action: SUBSTITUTION }) &&
54717
+ matchUpParticipantIds.length === 2 &&
54718
+ ((!sideNumber && (existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length)) || (sideNumber && (side === null || side === void 0 ? void 0 : side.participant))) &&
54719
+ (substituteWithoutScore || checkScoreHasValue(matchUp)) &&
54720
+ (substituteAfterCompleted ||
54721
+ (matchUp.matchUpStatus && !completedMatchUpStatuses.includes(matchUp.matchUpStatus))) &&
54722
+ (existingParticipants === null || existingParticipants === void 0 ? void 0 : existingParticipants.length) &&
54723
+ availableParticipants.length) {
54724
+ // action is not valid if there are no existing assignments or no available substitutions
54725
+ var existingParticipantIds_1 = existingParticipants.map(getParticipantId);
54726
+ validActions.push({
54727
+ info: 'list of team players available for substitution',
54728
+ method: SUBSTITUTION_METHOD,
54729
+ availableParticipantIds: availableParticipantIds,
54730
+ existingParticipantIds: existingParticipantIds_1,
54731
+ availableParticipants: availableParticipants,
54732
+ existingParticipants: existingParticipants,
54733
+ type: SUBSTITUTION,
54734
+ payload: {
54735
+ substituteParticipantId: undefined,
54736
+ existingParticipantId: undefined,
54737
+ sideNumber: sideNumber,
54738
+ matchUpId: matchUpId,
54739
+ drawId: drawId,
54740
+ },
54741
+ });
54742
+ }
54743
+ return validActions;
54744
+ }
54745
+
54746
+ function getEventAlternateParticipantIds(_a) {
54747
+ var eventEntries = _a.eventEntries, structure = _a.structure;
54748
+ var eligibleAlternate = function (entry) { return entry.entryStatus === ALTERNATE && eligibleEntryStage({ structure: structure, entry: entry }); };
54749
+ var entryPositionSort = function (a, b) { return (a.entryPosition || Infinity) - (b.entryPosition || Infinity); };
54750
+ return eventEntries.filter(eligibleAlternate).sort(entryPositionSort).map(xa('participantId'));
54751
+ }
54752
+
54753
+ function adHocMatchUpActions(_a) {
54754
+ var _b, _c, _d, _e, _f, _g;
54755
+ var restrictAdHocRoundParticipants = _a.restrictAdHocRoundParticipants, tournamentParticipants = _a.tournamentParticipants, matchUpParticipantIds = _a.matchUpParticipantIds, otherFlightEntries = _a.otherFlightEntries, drawDefinition = _a.drawDefinition, structureId = _a.structureId, sideNumber = _a.sideNumber, matchUpId = _a.matchUpId, structure = _a.structure, matchUp = _a.matchUp, drawId = _a.drawId, event = _a.event;
54756
+ var validActions = [];
54757
+ var roundMatchUps = ((_b = structure === null || structure === void 0 ? void 0 : structure.matchUps) !== null && _b !== void 0 ? _b : []).filter(function (_a) {
54758
+ var roundNumber = _a.roundNumber;
54759
+ return roundNumber === matchUp.roundNumber;
54760
+ });
54761
+ var enteredParticipantIds = (_d = (_c = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) === null || _c === void 0 ? void 0 : _c.filter(function (_a) {
54762
+ var entryStatus = _a.entryStatus;
54763
+ return entryStatus && DIRECT_ENTRY_STATUSES.includes(entryStatus);
54764
+ }).map(xa('participantId'))) !== null && _d !== void 0 ? _d : [];
54765
+ var roundAssignedParticipantIds = roundMatchUps
54766
+ .map(function (matchUp) { var _a; return ((_a = matchUp.sides) !== null && _a !== void 0 ? _a : []).flatMap(xa('participantId')); })
54767
+ .flat()
54768
+ .filter(Boolean);
54769
+ var availableParticipantIds = enteredParticipantIds.filter(function (participantId) {
54770
+ return !matchUpParticipantIds.includes(participantId) &&
54771
+ (!restrictAdHocRoundParticipants || !roundAssignedParticipantIds.includes(participantId));
54772
+ });
54773
+ var participantsAvailable = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) { return availableParticipantIds === null || availableParticipantIds === void 0 ? void 0 : availableParticipantIds.includes(participant.participantId); }).map(function (participant) { return makeDeepCopy(participant, undefined, true); });
54774
+ participantsAvailable === null || participantsAvailable === void 0 ? void 0 : participantsAvailable.forEach(function (participant) {
54775
+ var _a;
54776
+ var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === participant.participantId; });
54777
+ // used to sort available participants
54778
+ participant.entryPosition = entry === null || entry === void 0 ? void 0 : entry.entryPosition;
54779
+ });
54780
+ if (availableParticipantIds.length) {
54781
+ validActions.push({
54782
+ payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54783
+ method: ASSIGN_SIDE_METHOD,
54784
+ type: ASSIGN_PARTICIPANT,
54785
+ availableParticipantIds: availableParticipantIds,
54786
+ participantsAvailable: participantsAvailable,
54787
+ });
54788
+ }
54789
+ var eventEntries = (_e = event === null || event === void 0 ? void 0 : event.entries) !== null && _e !== void 0 ? _e : [];
54790
+ var availableEventAlternatesParticipantIds = getEventAlternateParticipantIds({ eventEntries: eventEntries, structure: structure });
54791
+ var availableAlternatesParticipantIds = unique(enteredParticipantIds.concat(availableEventAlternatesParticipantIds));
54792
+ if (otherFlightEntries) {
54793
+ var flightProfile = event ? getFlightProfile({ event: event }) : undefined;
54794
+ var otherFlightEnteredParticipantIds = (_f = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _f === void 0 ? void 0 : _f.filter(function (flight) { return flight.drawId !== drawId; }).flatMap(function (flight) {
54795
+ return flight.drawEntries
54796
+ .filter(function (entry) { return entry.participantId && ![WITHDRAWN, UNGROUPED, UNPAIRED].includes(entry.entryStatus); })
54797
+ .map(function (_a) {
54798
+ var participantId = _a.participantId;
54799
+ return participantId;
54800
+ });
54801
+ }).filter(Boolean);
54802
+ if (otherFlightEnteredParticipantIds === null || otherFlightEnteredParticipantIds === void 0 ? void 0 : otherFlightEnteredParticipantIds.length) {
54803
+ // include direct acceptance participants from other flights
54804
+ availableAlternatesParticipantIds.push.apply(availableAlternatesParticipantIds, __spreadArray([], __read(otherFlightEnteredParticipantIds), false));
54805
+ }
54806
+ }
54807
+ availableAlternatesParticipantIds = availableAlternatesParticipantIds.filter(function (participantId) {
54808
+ return !matchUpParticipantIds.includes(participantId) &&
54809
+ !availableParticipantIds.includes(participantId) &&
54810
+ (!restrictAdHocRoundParticipants || !roundAssignedParticipantIds.includes(participantId));
54811
+ });
54812
+ var availableAlternates = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) { return availableAlternatesParticipantIds.includes(participant.participantId); }).map(function (participant) { return makeDeepCopy(participant, undefined, true); });
54813
+ availableAlternates === null || availableAlternates === void 0 ? void 0 : availableAlternates.forEach(function (alternate) {
54814
+ var _a;
54815
+ var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === alternate.participantId; });
54816
+ alternate.entryPosition = entry === null || entry === void 0 ? void 0 : entry.entryPosition;
54817
+ });
54818
+ availableAlternates === null || availableAlternates === void 0 ? void 0 : availableAlternates.sort(function (a, b) { return (a.entryPosition || Infinity) - (b.entryPosition || Infinity); });
54819
+ if (availableAlternatesParticipantIds.length) {
54820
+ validActions.push({
54821
+ payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54822
+ availableParticipantIds: availableAlternatesParticipantIds,
54823
+ participantsAvailable: availableAlternates,
54824
+ method: ASSIGN_SIDE_METHOD,
54825
+ type: ALTERNATE,
54826
+ });
54827
+ }
54828
+ if (!checkScoreHasValue(matchUp) && sideNumber) {
54829
+ var side = (_g = matchUp.sides) === null || _g === void 0 ? void 0 : _g.find(function (side) { return side.sideNumber === sideNumber; });
54830
+ if (side === null || side === void 0 ? void 0 : side.participantId) {
54831
+ validActions.push({
54832
+ payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54833
+ method: REMOVE_SIDE_METHOD,
54834
+ type: REMOVE_PARTICIPANT,
54835
+ });
54836
+ }
54837
+ }
54838
+ return validActions;
54839
+ }
54840
+
54781
54841
  function matchUpActions(params) {
54782
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
54842
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
54783
54843
  if (!params)
54784
54844
  return { error: INVALID_VALUES };
54785
54845
  var drawDefinition, event;
54786
- var _16 = params.restrictAdHocRoundParticipants, restrictAdHocRoundParticipants = _16 === void 0 ? true : _16, // disallow the same participant being in the same round multiple times
54846
+ var _u = params.restrictAdHocRoundParticipants, restrictAdHocRoundParticipants = _u === void 0 ? true : _u, // disallow the same participant being in the same round multiple times
54787
54847
  specifiedPolicyDefinitions = params.policyDefinitions, enforceGender = params.enforceGender, participantId = params.participantId, sideNumber = params.sideNumber, matchUpId = params.matchUpId;
54788
- var tournamentRecord = (_a = params.tournamentRecord) !== null && _a !== void 0 ? _a : (params.tournamentId &&
54789
- isString(params.tournamentId) &&
54790
- ((_b = params.tournamentRecords) === null || _b === void 0 ? void 0 : _b[params.tournamentId]));
54848
+ var tournamentRecord = (_a = params.tournamentRecord) !== null && _a !== void 0 ? _a : (params.tournamentId && isString(params.tournamentId) && ((_b = params.tournamentRecords) === null || _b === void 0 ? void 0 : _b[params.tournamentId]));
54791
54849
  if (!tournamentRecord)
54792
54850
  return { error: MISSING_TOURNAMENT_RECORD };
54793
54851
  if (!matchUpId || !isString(matchUpId))
@@ -54811,11 +54869,11 @@ function matchUpActions(params) {
54811
54869
  withIndividualParticipants: true,
54812
54870
  }).participants;
54813
54871
  var drawId = drawDefinition.drawId;
54814
- var _17 = findDrawMatchUp({
54872
+ var _v = findDrawMatchUp({
54815
54873
  drawDefinition: drawDefinition,
54816
54874
  matchUpId: matchUpId,
54817
54875
  event: event,
54818
- }), matchUp = _17.matchUp, structure = _17.structure;
54876
+ }), matchUp = _v.matchUp, structure = _v.structure;
54819
54877
  if (!matchUp)
54820
54878
  return { error: MATCHUP_NOT_FOUND };
54821
54879
  var appliedPolicies = (_f = getAppliedPolicies({
@@ -54827,7 +54885,6 @@ function matchUpActions(params) {
54827
54885
  Object.assign(appliedPolicies, specifiedPolicyDefinitions !== null && specifiedPolicyDefinitions !== void 0 ? specifiedPolicyDefinitions : {});
54828
54886
  var otherFlightEntries = (_g = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_POSITION_ACTIONS]) === null || _g === void 0 ? void 0 : _g.otherFlightEntries;
54829
54887
  var matchUpActionsPolicy = (_h = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_MATCHUP_ACTIONS]) !== null && _h !== void 0 ? _h : POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
54830
- var isAdHocMatchUp = isAdHoc({ drawDefinition: drawDefinition, structure: structure });
54831
54888
  var enabledStructures = getEnabledStructures({
54832
54889
  actionType: MATCHUP_ACTION,
54833
54890
  appliedPolicies: appliedPolicies,
@@ -54848,108 +54905,31 @@ function matchUpActions(params) {
54848
54905
  event: event,
54849
54906
  }).matchUps;
54850
54907
  var inContextMatchUp = inContextDrawMatchUps === null || inContextDrawMatchUps === void 0 ? void 0 : inContextDrawMatchUps.find(function (drawMatchUp) { return drawMatchUp.matchUpId === matchUpId; });
54851
- var side = sideNumber &&
54852
- ((_l = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.sides) === null || _l === void 0 ? void 0 : _l.find(function (side) { return side.sideNumber === sideNumber; }));
54908
+ var side = sideNumber && ((_l = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.sides) === null || _l === void 0 ? void 0 : _l.find(function (side) { return side.sideNumber === sideNumber; }));
54853
54909
  var matchUpParticipantIds = (_o = (_m = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.sides) === null || _m === void 0 ? void 0 : _m.map(function (side) { var _a; return side.participantId || ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.participantid); }).filter(Boolean)) !== null && _o !== void 0 ? _o : [];
54854
- var _18 = structureAssignedDrawPositions({ structure: structure }), assignedPositions = _18.assignedPositions, allPositionsAssigned = _18.allPositionsAssigned;
54910
+ var _w = structureAssignedDrawPositions({ structure: structure }), assignedPositions = _w.assignedPositions, allPositionsAssigned = _w.allPositionsAssigned;
54855
54911
  var structureId = (structure !== null && structure !== void 0 ? structure : {}).structureId;
54856
54912
  var validActions = [];
54857
54913
  if (!structureId)
54858
54914
  return { validActions: validActions };
54859
- if (isAdHocMatchUp) {
54860
- var roundMatchUps = ((_p = structure === null || structure === void 0 ? void 0 : structure.matchUps) !== null && _p !== void 0 ? _p : []).filter(function (_a) {
54861
- var roundNumber = _a.roundNumber;
54862
- return roundNumber === matchUp.roundNumber;
54863
- });
54864
- var enteredParticipantIds = (_r = (_q = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) === null || _q === void 0 ? void 0 : _q.filter(function (_a) {
54865
- var entryStatus = _a.entryStatus;
54866
- return entryStatus && DIRECT_ENTRY_STATUSES.includes(entryStatus);
54867
- }).map(getParticipantId)) !== null && _r !== void 0 ? _r : [];
54868
- var roundAssignedParticipantIds_1 = roundMatchUps
54869
- .map(function (matchUp) { var _a; return ((_a = matchUp.sides) !== null && _a !== void 0 ? _a : []).flatMap(getParticipantId); })
54870
- .flat()
54871
- .filter(Boolean);
54872
- var availableParticipantIds_1 = enteredParticipantIds.filter(function (participantId) {
54873
- return !matchUpParticipantIds.includes(participantId) &&
54874
- (!restrictAdHocRoundParticipants ||
54875
- !roundAssignedParticipantIds_1.includes(participantId));
54876
- });
54877
- var participantsAvailable = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) {
54878
- return availableParticipantIds_1 === null || availableParticipantIds_1 === void 0 ? void 0 : availableParticipantIds_1.includes(participant.participantId);
54879
- }).map(function (participant) { return makeDeepCopy(participant, undefined, true); });
54880
- participantsAvailable === null || participantsAvailable === void 0 ? void 0 : participantsAvailable.forEach(function (participant) {
54881
- var _a;
54882
- var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === participant.participantId; });
54883
- // used to sort available participants
54884
- participant.entryPosition = entry === null || entry === void 0 ? void 0 : entry.entryPosition;
54885
- });
54886
- if (availableParticipantIds_1.length) {
54887
- validActions.push({
54888
- payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54889
- method: ASSIGN_SIDE_METHOD,
54890
- type: ASSIGN_PARTICIPANT,
54891
- availableParticipantIds: availableParticipantIds_1,
54892
- participantsAvailable: participantsAvailable,
54893
- });
54894
- }
54895
- var eventEntries = (_s = event === null || event === void 0 ? void 0 : event.entries) !== null && _s !== void 0 ? _s : [];
54896
- var availableEventAlternatesParticipantIds = getEventAlternateParticipantIds({ eventEntries: eventEntries, structure: structure });
54897
- var availableAlternatesParticipantIds_1 = unique(enteredParticipantIds.concat(availableEventAlternatesParticipantIds));
54898
- if (otherFlightEntries) {
54899
- var flightProfile = event
54900
- ? getFlightProfile({ event: event })
54901
- : undefined;
54902
- var otherFlightEnteredParticipantIds = (_t = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _t === void 0 ? void 0 : _t.filter(function (flight) { return flight.drawId !== drawId; }).flatMap(function (flight) {
54903
- return flight.drawEntries
54904
- .filter(function (entry) {
54905
- return entry.participantId &&
54906
- ![WITHDRAWN, UNGROUPED, UNPAIRED].includes(entry.entryStatus);
54907
- })
54908
- .map(function (_a) {
54909
- var participantId = _a.participantId;
54910
- return participantId;
54911
- });
54912
- }).filter(Boolean);
54913
- if (otherFlightEnteredParticipantIds === null || otherFlightEnteredParticipantIds === void 0 ? void 0 : otherFlightEnteredParticipantIds.length) {
54914
- // include direct acceptance participants from other flights
54915
- availableAlternatesParticipantIds_1.push.apply(availableAlternatesParticipantIds_1, __spreadArray([], __read(otherFlightEnteredParticipantIds), false));
54916
- }
54917
- }
54918
- availableAlternatesParticipantIds_1 =
54919
- availableAlternatesParticipantIds_1.filter(function (participantId) {
54920
- return !matchUpParticipantIds.includes(participantId) &&
54921
- !availableParticipantIds_1.includes(participantId) &&
54922
- (!restrictAdHocRoundParticipants ||
54923
- !roundAssignedParticipantIds_1.includes(participantId));
54924
- });
54925
- var availableAlternates = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) {
54926
- return availableAlternatesParticipantIds_1.includes(participant.participantId);
54927
- }).map(function (participant) { return makeDeepCopy(participant, undefined, true); });
54928
- availableAlternates === null || availableAlternates === void 0 ? void 0 : availableAlternates.forEach(function (alternate) {
54929
- var _a;
54930
- var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === alternate.participantId; });
54931
- alternate.entryPosition = entry === null || entry === void 0 ? void 0 : entry.entryPosition;
54915
+ var isAdHocMatchUp = isAdHoc({ drawDefinition: drawDefinition, structure: structure });
54916
+ var isCollectionMatchUp = matchUp.collectionId;
54917
+ if (isAdHocMatchUp && !isCollectionMatchUp) {
54918
+ var adHocValidActions = adHocMatchUpActions({
54919
+ restrictAdHocRoundParticipants: restrictAdHocRoundParticipants,
54920
+ tournamentParticipants: tournamentParticipants,
54921
+ matchUpParticipantIds: matchUpParticipantIds,
54922
+ otherFlightEntries: otherFlightEntries,
54923
+ drawDefinition: drawDefinition,
54924
+ structureId: structureId,
54925
+ sideNumber: sideNumber,
54926
+ matchUpId: matchUpId,
54927
+ structure: structure,
54928
+ matchUp: matchUp,
54929
+ drawId: drawId,
54930
+ event: event,
54932
54931
  });
54933
- availableAlternates === null || availableAlternates === void 0 ? void 0 : availableAlternates.sort(function (a, b) { return (a.entryPosition || Infinity) - (b.entryPosition || Infinity); });
54934
- if (availableAlternatesParticipantIds_1.length) {
54935
- validActions.push({
54936
- payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54937
- availableParticipantIds: availableAlternatesParticipantIds_1,
54938
- participantsAvailable: availableAlternates,
54939
- method: ASSIGN_SIDE_METHOD,
54940
- type: ALTERNATE,
54941
- });
54942
- }
54943
- if (!checkScoreHasValue(matchUp) && sideNumber) {
54944
- var side_1 = (_u = matchUp.sides) === null || _u === void 0 ? void 0 : _u.find(function (side) { return side.sideNumber === sideNumber; });
54945
- if (side_1 === null || side_1 === void 0 ? void 0 : side_1.participantId) {
54946
- validActions.push({
54947
- payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54948
- method: REMOVE_SIDE_METHOD,
54949
- type: REMOVE_PARTICIPANT,
54950
- });
54951
- }
54952
- }
54932
+ validActions.push.apply(validActions, __spreadArray([], __read(adHocValidActions), false));
54953
54933
  }
54954
54934
  var structureIsComplete = isCompletedStructure({
54955
54935
  drawDefinition: drawDefinition,
@@ -54957,10 +54937,9 @@ function matchUpActions(params) {
54957
54937
  });
54958
54938
  var participantAssignedDrawPositions = assignedPositions === null || assignedPositions === void 0 ? void 0 : assignedPositions.filter(function (assignment) { return assignment.participantId; }).map(function (assignment) { return assignment.drawPosition; });
54959
54939
  var byeAssignedDrawPositions = assignedPositions === null || assignedPositions === void 0 ? void 0 : assignedPositions.filter(function (assignment) { return assignment.bye; }).map(function (assignment) { return assignment.drawPosition; });
54960
- var isCollectionMatchUp = matchUp.collectionId;
54961
54940
  var isByeMatchUp = matchUp.matchUpStatus === BYE ||
54962
54941
  (!isCollectionMatchUp &&
54963
- ((_v = matchUp.drawPositions) === null || _v === void 0 ? void 0 : _v.reduce(function (isByeMatchUp, drawPosition) {
54942
+ ((_p = matchUp.drawPositions) === null || _p === void 0 ? void 0 : _p.reduce(function (isByeMatchUp, drawPosition) {
54964
54943
  return (byeAssignedDrawPositions === null || byeAssignedDrawPositions === void 0 ? void 0 : byeAssignedDrawPositions.includes(drawPosition)) || isByeMatchUp;
54965
54944
  }, false)));
54966
54945
  if (isByeMatchUp)
@@ -54972,21 +54951,17 @@ function matchUpActions(params) {
54972
54951
  var isInComplete = !isDirectingMatchUpStatus({
54973
54952
  matchUpStatus: matchUp.matchUpStatus,
54974
54953
  });
54975
- var structureScoringPolicies = (_w = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.scoring) === null || _w === void 0 ? void 0 : _w.structures;
54976
- var stageSpecificPolicies = (structure === null || structure === void 0 ? void 0 : structure.stage) &&
54977
- (structureScoringPolicies === null || structureScoringPolicies === void 0 ? void 0 : structureScoringPolicies.stage) &&
54978
- (structureScoringPolicies === null || structureScoringPolicies === void 0 ? void 0 : structureScoringPolicies.stage[structure.stage]);
54954
+ var structureScoringPolicies = (_q = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.scoring) === null || _q === void 0 ? void 0 : _q.structures;
54955
+ var stageSpecificPolicies = (structure === null || structure === void 0 ? void 0 : structure.stage) && (structureScoringPolicies === null || structureScoringPolicies === void 0 ? void 0 : structureScoringPolicies.stage) && (structureScoringPolicies === null || structureScoringPolicies === void 0 ? void 0 : structureScoringPolicies.stage[structure.stage]);
54979
54956
  var sequenceSpecificPolicies = (structure === null || structure === void 0 ? void 0 : structure.stageSequence) &&
54980
54957
  (stageSpecificPolicies === null || stageSpecificPolicies === void 0 ? void 0 : stageSpecificPolicies.stageSequence) &&
54981
54958
  stageSpecificPolicies.stageSequence[structure.stageSequence];
54982
- var requireAllPositionsAssigned = ((_x = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.scoring) === null || _x === void 0 ? void 0 : _x.requireAllPositionsAssigned) ||
54959
+ var requireAllPositionsAssigned = ((_r = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.scoring) === null || _r === void 0 ? void 0 : _r.requireAllPositionsAssigned) ||
54983
54960
  (stageSpecificPolicies === null || stageSpecificPolicies === void 0 ? void 0 : stageSpecificPolicies.requireAllPositionsAssigned) ||
54984
54961
  (sequenceSpecificPolicies === null || sequenceSpecificPolicies === void 0 ? void 0 : sequenceSpecificPolicies.requireAllPositionsAssigned);
54985
54962
  var scoringActive = !requireAllPositionsAssigned || allPositionsAssigned;
54986
- var hasParticipants = matchUp.sides &&
54987
- matchUp.sides.filter(function (side) { return side === null || side === void 0 ? void 0 : side.participantId; }).length === 2;
54988
- var isDoubleExit = matchUp.matchUpStatus &&
54989
- [DOUBLE_WALKOVER, DOUBLE_DEFAULT].includes(matchUp.matchUpStatus);
54963
+ var hasParticipants = matchUp.sides && matchUp.sides.filter(function (side) { return side === null || side === void 0 ? void 0 : side.participantId; }).length === 2;
54964
+ var isDoubleExit = matchUp.matchUpStatus && [DOUBLE_WALKOVER, DOUBLE_DEFAULT].includes(matchUp.matchUpStatus);
54990
54965
  var targetData = positionTargets({
54991
54966
  inContextDrawMatchUps: inContextDrawMatchUps,
54992
54967
  drawDefinition: drawDefinition,
@@ -54997,15 +54972,14 @@ function matchUpActions(params) {
54997
54972
  drawDefinition: drawDefinition,
54998
54973
  targetData: targetData,
54999
54974
  });
55000
- var matchUpDrawPositionsAreAssigned = ((_y = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.drawPositions) === null || _y === void 0 ? void 0 : _y.length) === 2 &&
54975
+ var matchUpDrawPositionsAreAssigned = ((_s = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.drawPositions) === null || _s === void 0 ? void 0 : _s.length) === 2 &&
55001
54976
  inContextMatchUp.drawPositions.every(function (drawPosition) { return participantAssignedDrawPositions === null || participantAssignedDrawPositions === void 0 ? void 0 : participantAssignedDrawPositions.includes(drawPosition); }) &&
55002
- ((_z = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.sides) === null || _z === void 0 ? void 0 : _z.length) === 2 &&
54977
+ ((_t = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.sides) === null || _t === void 0 ? void 0 : _t.length) === 2 &&
55003
54978
  inContextMatchUp.sides.every(function (_a) {
55004
54979
  var participantId = _a.participantId;
55005
54980
  return participantId;
55006
54981
  });
55007
- var readyToScore = (matchUpDrawPositionsAreAssigned || hasParticipants) &&
55008
- !(isDoubleExit && activeDownstream);
54982
+ var readyToScore = (matchUpDrawPositionsAreAssigned || hasParticipants) && !(isDoubleExit && activeDownstream);
55009
54983
  var addPenaltyAction = {
55010
54984
  method: ADD_PENALTY_METHOD,
55011
54985
  type: ADD_PENALTY,
@@ -55058,162 +55032,22 @@ function matchUpActions(params) {
55058
55032
  }
55059
55033
  }
55060
55034
  if (isCollectionMatchUp && inContextMatchUp) {
55061
- var firstFoundSide = (_0 = inContextMatchUp.sides) === null || _0 === void 0 ? void 0 : _0.find(function (side) { return side.participant; });
55062
- var assignedGender_1 = inContextMatchUp.gender === MIXED &&
55063
- inContextMatchUp.sideNumber &&
55064
- ((_1 = inContextMatchUp.sides) === null || _1 === void 0 ? void 0 : _1.filter(function (side) { return side.particiapntId; }).length) === 1 &&
55065
- ((_3 = (_2 = firstFoundSide === null || firstFoundSide === void 0 ? void 0 : firstFoundSide.participant) === null || _2 === void 0 ? void 0 : _2.person) === null || _3 === void 0 ? void 0 : _3.sex);
55066
- var matchUpType = inContextMatchUp.matchUpType;
55067
- var genderEnforced = (enforceGender !== null && enforceGender !== void 0 ? enforceGender : (_4 = matchUpActionsPolicy === null || matchUpActionsPolicy === void 0 ? void 0 : matchUpActionsPolicy.participants) === null || _4 === void 0 ? void 0 : _4.enforceGender) !==
55068
- false;
55069
- var gender_1 = genderEnforced ? inContextMatchUp.gender : undefined;
55070
- var allParticipants = (_5 = inContextMatchUp.sides) === null || _5 === void 0 ? void 0 : _5.flatMap(function (side) { var _a; return ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants) || side.participant; }).filter(Boolean);
55071
- var allParticipantIds_1 = allParticipants === null || allParticipants === void 0 ? void 0 : allParticipants.map(getParticipantId);
55072
- var existingParticipants = (_6 = inContextMatchUp.sides) === null || _6 === void 0 ? void 0 : _6.filter(function (side) { return !sideNumber || side.sideNumber === sideNumber; }).flatMap(function (side) { var _a; return ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants) || side.participant; }).filter(Boolean);
55073
- var existingParticipantIds_1 = existingParticipants === null || existingParticipants === void 0 ? void 0 : existingParticipants.map(getParticipantId);
55074
- var inContextDualMatchUp = inContextDrawMatchUps === null || inContextDrawMatchUps === void 0 ? void 0 : inContextDrawMatchUps.find(function (drawMatchUp) { return drawMatchUp.matchUpId === inContextMatchUp.matchUpTieId; });
55075
- var availableIndividualParticipants = (_7 = inContextDualMatchUp === null || inContextDualMatchUp === void 0 ? void 0 : inContextDualMatchUp.sides) === null || _7 === void 0 ? void 0 : _7.map(function (side) {
55076
- var _a;
55077
- return (_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants.filter(function (_a) {
55078
- var participantId = _a.participantId, person = _a.person;
55079
- return !(existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.includes(participantId)) &&
55080
- (!gender_1 ||
55081
- gender_1 === ANY ||
55082
- person.sex === gender_1 ||
55083
- // case where one gendered member has been assigned
55084
- (gender_1 === MIXED && !assignedGender_1) ||
55085
- (assignedGender_1 && person.sex !== assignedGender_1));
55086
- });
55087
- });
55088
- // if no sideNumber is provided, segregate available by sideNumber and specify sideNumber
55089
- var availableParticipants = sideNumber
55090
- ? availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants[sideNumber - 1]
55091
- : availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants.map(function (available, i) { return ({
55092
- participants: available,
55093
- sideNumber: i + 1,
55094
- }); });
55095
- var availableParticipantIds = sideNumber
55096
- ? (_8 = availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants[sideNumber - 1]) === null || _8 === void 0 ? void 0 : _8.map(getParticipantId)
55097
- : availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants.map(function (available, i) { return ({
55098
- participants: available === null || available === void 0 ? void 0 : available.map(getParticipantId),
55099
- sideNumber: i + 1,
55100
- }); });
55101
- var assignmentAvailable = (sideNumber &&
55102
- ((matchUpType === SINGLES_MATCHUP && !(existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length)) ||
55103
- (matchUpType === DOUBLES_MATCHUP &&
55104
- ((_9 = existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length) !== null && _9 !== void 0 ? _9 : 0) < 2))) ||
55105
- (!sideNumber &&
55106
- ((matchUpType === SINGLES_MATCHUP &&
55107
- ((_10 = existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length) !== null && _10 !== void 0 ? _10 : 0) < 2) ||
55108
- (matchUpType === DOUBLES_MATCHUP &&
55109
- ((_11 = existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length) !== null && _11 !== void 0 ? _11 : 0) < 4)));
55110
- // extra step to avoid edge case where individual participant is part of both teams
55111
- var availableIds_1 = availableParticipantIds === null || availableParticipantIds === void 0 ? void 0 : availableParticipantIds.filter(function (id) { return !(allParticipantIds_1 === null || allParticipantIds_1 === void 0 ? void 0 : allParticipantIds_1.includes(id)); });
55112
- var available = availableParticipants === null || availableParticipants === void 0 ? void 0 : availableParticipants.filter(function (_a) {
55113
- var participantId = _a.participantId;
55114
- return availableIds_1.includes(participantId);
55035
+ var collectionValidActions = collectionMatchUpActions({
55036
+ specifiedPolicyDefinitions: specifiedPolicyDefinitions,
55037
+ inContextDrawMatchUps: inContextDrawMatchUps,
55038
+ matchUpParticipantIds: matchUpParticipantIds,
55039
+ matchUpActionsPolicy: matchUpActionsPolicy,
55040
+ inContextMatchUp: inContextMatchUp,
55041
+ policyActions: policyActions,
55042
+ enforceGender: enforceGender,
55043
+ participantId: participantId,
55044
+ sideNumber: sideNumber,
55045
+ matchUpId: matchUpId,
55046
+ matchUp: matchUp,
55047
+ drawId: drawId,
55048
+ side: side,
55115
55049
  });
55116
- if (assignmentAvailable && (availableIds_1 === null || availableIds_1 === void 0 ? void 0 : availableIds_1.length)) {
55117
- validActions.push({
55118
- availableParticipantIds: availableIds_1,
55119
- method: ASSIGN_TEAM_POSITION_METHOD,
55120
- availableParticipants: available,
55121
- type: ASSIGN_PARTICIPANT,
55122
- payload: {
55123
- participantId: undefined,
55124
- tieMatchUpId: matchUpId,
55125
- drawId: drawId,
55126
- },
55127
- });
55128
- }
55129
- if ((existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length) &&
55130
- (!checkScoreHasValue(matchUp) || ((_12 = side === null || side === void 0 ? void 0 : side.substitutions) === null || _12 === void 0 ? void 0 : _12.length))) {
55131
- validActions.push({
55132
- method: REMOVE_TEAM_POSITION_METHOD,
55133
- type: REMOVE_PARTICIPANT,
55134
- existingParticipantIds: existingParticipantIds_1,
55135
- payload: {
55136
- participantId: undefined,
55137
- tieMatchUpId: matchUpId,
55138
- drawId: drawId,
55139
- },
55140
- });
55141
- }
55142
- if ((available === null || available === void 0 ? void 0 : available.length) &&
55143
- ((!sideNumber && (existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length)) ||
55144
- (sideNumber && (side === null || side === void 0 ? void 0 : side.participant)))) {
55145
- validActions.push({
55146
- availableParticipantIds: availableIds_1,
55147
- method: REPLACE_TEAM_POSITION_METHOD,
55148
- availableParticipants: available,
55149
- type: REPLACE_PARTICIPANT,
55150
- existingParticipantIds: existingParticipantIds_1,
55151
- payload: {
55152
- existingParticipantId: undefined,
55153
- participantId: undefined,
55154
- tieMatchUpId: matchUpId,
55155
- drawId: drawId,
55156
- },
55157
- });
55158
- }
55159
- if (isAvailableAction({ policyActions: policyActions, action: REMOVE_SUBSTITUTION }) &&
55160
- ((_13 = side === null || side === void 0 ? void 0 : side.substitutions) === null || _13 === void 0 ? void 0 : _13.length)) {
55161
- var sideIndividualParticipantIds_1 = (((_14 = side.participant) === null || _14 === void 0 ? void 0 : _14.participantType) === INDIVIDUAL && [
55162
- side.participantId,
55163
- ]) ||
55164
- (((_15 = side.participant) === null || _15 === void 0 ? void 0 : _15.participantType) === PAIR &&
55165
- side.participant.individualParticipantIds) ||
55166
- [];
55167
- var substitutedParticipantIds = side.substitutions
55168
- .map(function (sub) { return sub.participantId; })
55169
- .filter(function (id) { return sideIndividualParticipantIds_1.includes(id); });
55170
- if (!participantId || substitutedParticipantIds.includes(participantId)) {
55171
- validActions.push({
55172
- method: REMOVE_TEAM_POSITION_METHOD,
55173
- type: REMOVE_SUBSTITUTION,
55174
- substitutedParticipantIds: substitutedParticipantIds,
55175
- payload: {
55176
- participantId: undefined,
55177
- tieMatchUpId: matchUpId,
55178
- drawId: drawId,
55179
- },
55180
- });
55181
- }
55182
- }
55183
- var matchUpActionPolicy = specifiedPolicyDefinitions === null || specifiedPolicyDefinitions === void 0 ? void 0 : specifiedPolicyDefinitions[POLICY_TYPE_MATCHUP_ACTIONS];
55184
- var substituteWithoutScore = matchUpActionPolicy === null || matchUpActionPolicy === void 0 ? void 0 : matchUpActionPolicy.substituteWithoutScore;
55185
- var substituteAfterCompleted = matchUpActionPolicy === null || matchUpActionPolicy === void 0 ? void 0 : matchUpActionPolicy.substituteAfterCompleted;
55186
- // SUBSTITUTION
55187
- // substitution is only possible when both sides are present; otherwise => nonsensical
55188
- if (isAvailableAction({ policyActions: policyActions, action: SUBSTITUTION }) &&
55189
- matchUpParticipantIds.length === 2 &&
55190
- ((!sideNumber && (existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length)) ||
55191
- (sideNumber && (side === null || side === void 0 ? void 0 : side.participant))) &&
55192
- (substituteWithoutScore || checkScoreHasValue(matchUp)) &&
55193
- (substituteAfterCompleted ||
55194
- (matchUp.matchUpStatus &&
55195
- !completedMatchUpStatuses.includes(matchUp.matchUpStatus))) &&
55196
- (existingParticipants === null || existingParticipants === void 0 ? void 0 : existingParticipants.length) &&
55197
- availableParticipants.length) {
55198
- // action is not valid if there are no existing assignments or no available substitutions
55199
- var existingParticipantIds_2 = existingParticipants.map(getParticipantId);
55200
- validActions.push({
55201
- info: 'list of team players available for substitution',
55202
- method: SUBSTITUTION_METHOD,
55203
- availableParticipantIds: availableParticipantIds,
55204
- existingParticipantIds: existingParticipantIds_2,
55205
- availableParticipants: availableParticipants,
55206
- existingParticipants: existingParticipants,
55207
- type: SUBSTITUTION,
55208
- payload: {
55209
- substituteParticipantId: undefined,
55210
- existingParticipantId: undefined,
55211
- sideNumber: sideNumber,
55212
- matchUpId: matchUpId,
55213
- drawId: drawId,
55214
- },
55215
- });
55216
- }
55050
+ validActions.push.apply(validActions, __spreadArray([], __read(collectionValidActions), false));
55217
55051
  }
55218
55052
  return {
55219
55053
  structureIsComplete: structureIsComplete,
@@ -55221,19 +55055,6 @@ function matchUpActions(params) {
55221
55055
  isDoubleExit: isDoubleExit,
55222
55056
  };
55223
55057
  }
55224
- function getEventAlternateParticipantIds(_a) {
55225
- var eventEntries = _a.eventEntries, structure = _a.structure;
55226
- var eligibleAlternate = function (entry) {
55227
- return entry.entryStatus === ALTERNATE && eligibleEntryStage({ structure: structure, entry: entry });
55228
- };
55229
- var entryPositionSort = function (a, b) {
55230
- return (a.entryPosition || Infinity) - (b.entryPosition || Infinity);
55231
- };
55232
- return eventEntries
55233
- .filter(eligibleAlternate)
55234
- .sort(entryPositionSort)
55235
- .map(getParticipantId);
55236
- }
55237
55058
 
55238
55059
  /**
55239
55060
  * Calculates the valid actions for a draw position based on the provided parameters.
@@ -55319,8 +55140,7 @@ function positionActions(params) {
55319
55140
  drawDefinition: drawDefinition,
55320
55141
  structure: structure,
55321
55142
  }).policyActions;
55322
- var possiblyDisablingAction = ![QUALIFYING, MAIN].includes(structure.stage) ||
55323
- structure.stageSequence !== 1;
55143
+ var possiblyDisablingAction = ![QUALIFYING, MAIN].includes(structure.stage) || structure.stageSequence !== 1;
55324
55144
  var drawId = drawDefinition.drawId;
55325
55145
  var validActions = [];
55326
55146
  var _j = structureAssignedDrawPositions({ structure: structure }), assignedPositions = _j.assignedPositions, positionAssignments = _j.positionAssignments;
@@ -55398,11 +55218,9 @@ function positionActions(params) {
55398
55218
  validAssignmentActions === null || validAssignmentActions === void 0 ? void 0 : validAssignmentActions.forEach(function (action) { return validActions.push(action); });
55399
55219
  }
55400
55220
  var participantId = (positionAssignment || {}).participantId;
55401
- var participant = participantId &&
55402
- tournamentParticipants.find(function (participant) { return participant.participantId === participantId; });
55221
+ var participant = participantId && tournamentParticipants.find(function (participant) { return participant.participantId === participantId; });
55403
55222
  if (positionAssignment) {
55404
- if (isAvailableAction({ policyActions: policyActions, action: REMOVE_ASSIGNMENT }) &&
55405
- !isActiveDrawPosition) {
55223
+ if (isAvailableAction({ policyActions: policyActions, action: REMOVE_ASSIGNMENT }) && !isActiveDrawPosition) {
55406
55224
  validActions.push({
55407
55225
  type: REMOVE_ASSIGNMENT,
55408
55226
  method: REMOVE_ASSIGNMENT_METHOD,
@@ -55419,8 +55237,7 @@ function positionActions(params) {
55419
55237
  }
55420
55238
  // in this case the ASSIGN_BYE_METHOD is called after removing assigned participant
55421
55239
  // option should not be available if exising assignment is a bye
55422
- if (isAvailableAction({ policyActions: policyActions, action: ASSIGN_BYE }) &&
55423
- !isByePosition) {
55240
+ if (isAvailableAction({ policyActions: policyActions, action: ASSIGN_BYE }) && !isByePosition) {
55424
55241
  validActions.push({
55425
55242
  type: ASSIGN_BYE,
55426
55243
  method: REMOVE_ASSIGNMENT_METHOD,
@@ -55429,8 +55246,7 @@ function positionActions(params) {
55429
55246
  });
55430
55247
  }
55431
55248
  }
55432
- var validToAssignSeed = structure.stage === QUALIFYING ||
55433
- (structure.stage === MAIN && structure.stageSequence === 1);
55249
+ var validToAssignSeed = structure.stage === QUALIFYING || (structure.stage === MAIN && structure.stageSequence === 1);
55434
55250
  if (!isByePosition &&
55435
55251
  // if any drawPositions are active, action is disabled unless override in policy
55436
55252
  activePositionsCheck({
@@ -55537,8 +55353,7 @@ function positionActions(params) {
55537
55353
  validActions.push(validSwapAction);
55538
55354
  }
55539
55355
  }
55540
- if (isAvailableAction({ policyActions: policyActions, action: ALTERNATE_PARTICIPANT }) &&
55541
- !disablePlacementActions) {
55356
+ if (isAvailableAction({ policyActions: policyActions, action: ALTERNATE_PARTICIPANT }) && !disablePlacementActions) {
55542
55357
  var validAlternatesAction = getValidAlternatesAction({
55543
55358
  possiblyDisablingAction: possiblyDisablingAction,
55544
55359
  tournamentParticipants: tournamentParticipants,
@@ -55576,8 +55391,7 @@ function positionActions(params) {
55576
55391
  if (validLuckyLosersAction)
55577
55392
  validActions.push(validLuckyLosersAction);
55578
55393
  }
55579
- if ((participant === null || participant === void 0 ? void 0 : participant.participantType) === PAIR &&
55580
- isAvailableAction({ policyActions: policyActions, action: MODIFY_PAIR_ASSIGNMENT })) {
55394
+ if ((participant === null || participant === void 0 ? void 0 : participant.participantType) === PAIR && isAvailableAction({ policyActions: policyActions, action: MODIFY_PAIR_ASSIGNMENT })) {
55581
55395
  var validModifyAssignedPairAction = getValidModifyAssignedPairAction({
55582
55396
  tournamentParticipants: tournamentParticipants,
55583
55397
  returnParticipants: returnParticipants,
@@ -56908,7 +56722,7 @@ function getEvents(_a) {
56908
56722
  })
56909
56723
  .map(function (event) {
56910
56724
  var _a;
56911
- var eventDrawIds = (_a = event.drawDefinitions) === null || _a === void 0 ? void 0 : _a.map(extractAttributes('drawId'));
56725
+ var eventDrawIds = (_a = event.drawDefinitions) === null || _a === void 0 ? void 0 : _a.map(xa('drawId'));
56912
56726
  if ((drawIds === null || drawIds === void 0 ? void 0 : drawIds.length) && !intersection(drawIds, eventDrawIds).length)
56913
56727
  return;
56914
56728
  var eventCopy = makeDeepCopy(event);
@@ -56925,9 +56739,7 @@ function getEvents(_a) {
56925
56739
  withScaleValues: true,
56926
56740
  tournamentRecord: tournamentRecord,
56927
56741
  }).participantMap;
56928
- var sum = function (values) {
56929
- return values.reduce(function (total, value) { return total + parseFloat(value); }, 0);
56930
- };
56742
+ var sum = function (values) { return values.reduce(function (total, value) { return total + parseFloat(value); }, 0); };
56931
56743
  var _loop_1 = function (event_1) {
56932
56744
  var e_2, _o, e_3, _p, e_4, _q, e_5, _r, e_6, _s, e_7, _t, e_8, _u;
56933
56745
  var eventType = scaleEventType !== null && scaleEventType !== void 0 ? scaleEventType : event_1.eventType;
@@ -56943,7 +56755,7 @@ function getEvents(_a) {
56943
56755
  var entryStatus = _a.entryStatus;
56944
56756
  return STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
56945
56757
  });
56946
- var participantIds = selectedEntries.map(extractAttributes(PARTICIPANT_ID));
56758
+ var participantIds = selectedEntries.map(xa(PARTICIPANT_ID));
56947
56759
  var processParticipant = function (participant) {
56948
56760
  var e_9, _a, e_10, _b;
56949
56761
  var _c, _d, _e, _f, _g, _h, _j, _k;
@@ -57052,8 +56864,7 @@ function getEvents(_a) {
57052
56864
  var processParticipant = function (participant) {
57053
56865
  var e_13, _a, e_14, _b;
57054
56866
  var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
57055
- if (((_c = eventsMap[eventId].draws) === null || _c === void 0 ? void 0 : _c[drawId]) &&
57056
- ((_d = participant === null || participant === void 0 ? void 0 : participant.ratings) === null || _d === void 0 ? void 0 : _d[eventType])) {
56867
+ if (((_c = eventsMap[eventId].draws) === null || _c === void 0 ? void 0 : _c[drawId]) && ((_d = participant === null || participant === void 0 ? void 0 : participant.ratings) === null || _d === void 0 ? void 0 : _d[eventType])) {
57057
56868
  try {
57058
56869
  for (var _q = (e_13 = void 0, __values((_f = (_e = participant === null || participant === void 0 ? void 0 : participant.ratings) === null || _e === void 0 ? void 0 : _e[eventType]) !== null && _f !== void 0 ? _f : [])), _r = _q.next(); !_r.done; _r = _q.next()) {
57059
56870
  var rating = _r.value;
@@ -57077,8 +56888,7 @@ function getEvents(_a) {
57077
56888
  finally { if (e_13) throw e_13.error; }
57078
56889
  }
57079
56890
  }
57080
- if (((_k = eventsMap[eventId].draws) === null || _k === void 0 ? void 0 : _k[drawId]) &&
57081
- ((_l = participant === null || participant === void 0 ? void 0 : participant.rankings) === null || _l === void 0 ? void 0 : _l[eventType])) {
56891
+ if (((_k = eventsMap[eventId].draws) === null || _k === void 0 ? void 0 : _k[drawId]) && ((_l = participant === null || participant === void 0 ? void 0 : participant.rankings) === null || _l === void 0 ? void 0 : _l[eventType])) {
57082
56892
  try {
57083
56893
  for (var _s = (e_14 = void 0, __values((_o = (_m = participant === null || participant === void 0 ? void 0 : participant.rankings) === null || _m === void 0 ? void 0 : _m[eventType]) !== null && _o !== void 0 ? _o : [])), _t = _s.next(); !_t.done; _t = _s.next()) {
57084
56894
  var ranking = _t.value;
@@ -57135,8 +56945,7 @@ function getEvents(_a) {
57135
56945
  };
57136
56946
  var processedDrawIds = [];
57137
56947
  var ignoreDrawId = function (drawId) {
57138
- return ((drawIds === null || drawIds === void 0 ? void 0 : drawIds.length) && drawIds.includes(drawId)) ||
57139
- processedDrawIds.includes(drawId);
56948
+ return ((drawIds === null || drawIds === void 0 ? void 0 : drawIds.length) && drawIds.includes(drawId)) || processedDrawIds.includes(drawId);
57140
56949
  };
57141
56950
  try {
57142
56951
  for (var _z = (e_5 = void 0, __values((_j = event_1.drawDefinitions) !== null && _j !== void 0 ? _j : [])), _0 = _z.next(); !_0.done; _0 = _z.next()) {
@@ -57171,7 +56980,7 @@ function getEvents(_a) {
57171
56980
  var drawId = flight.drawId;
57172
56981
  if (ignoreDrawId(drawId))
57173
56982
  continue;
57174
- var participantIds_3 = flight.drawEntries.map(extractAttributes(PARTICIPANT_ID));
56983
+ var participantIds_3 = flight.drawEntries.map(xa(PARTICIPANT_ID));
57175
56984
  processFlight(drawId, participantIds_3);
57176
56985
  }
57177
56986
  }
@@ -57610,8 +57419,7 @@ function getParticipantStats(_a) {
57610
57419
  if (matchUps && !Array.isArray(matchUps))
57611
57420
  return { error: INVALID_MATCHUP };
57612
57421
  var participantsProfile = withScaleValues ? { withScaleValues: withScaleValues } : undefined;
57613
- matchUps =
57614
- matchUps !== null && matchUps !== void 0 ? matchUps : allTournamentMatchUps({ tournamentRecord: tournamentRecord, participantsProfile: participantsProfile }).matchUps;
57422
+ matchUps = matchUps !== null && matchUps !== void 0 ? matchUps : allTournamentMatchUps({ tournamentRecord: tournamentRecord, participantsProfile: participantsProfile }).matchUps;
57615
57423
  if (!(matchUps === null || matchUps === void 0 ? void 0 : matchUps.length))
57616
57424
  return { error: MISSING_MATCHUPS };
57617
57425
  var teamParticipantIds = [];
@@ -57630,7 +57438,7 @@ function getParticipantStats(_a) {
57630
57438
  return { error: INVALID_PARTICIPANT_IDS };
57631
57439
  }
57632
57440
  if (!teamParticipantIds.length)
57633
- teamParticipantIds.push.apply(teamParticipantIds, __spreadArray([], __read(teamParticipants.map(extractAttributes('participantId'))), false));
57441
+ teamParticipantIds.push.apply(teamParticipantIds, __spreadArray([], __read(teamParticipants.map(xa('participantId'))), false));
57634
57442
  var participantDetails = new Map();
57635
57443
  var participantStats = new Map();
57636
57444
  var participating = new Map();
@@ -57707,13 +57515,13 @@ function getParticipantStats(_a) {
57707
57515
  var _b, _c, _d, _e, _f;
57708
57516
  var side = _a.side, individualParticipantIds = _a.individualParticipantIds;
57709
57517
  return ((side.participantId &&
57710
- (!(individualParticipantIds === null || individualParticipantIds === void 0 ? void 0 : individualParticipantIds.length) ||
57711
- individualParticipantIds.includes(side.participantId)) && [
57518
+ (!(individualParticipantIds === null || individualParticipantIds === void 0 ? void 0 : individualParticipantIds.length) || individualParticipantIds.includes(side.participantId)) && [
57712
57519
  side.participantId,
57713
57520
  ]) ||
57714
57521
  (((_c = (_b = side.participant) === null || _b === void 0 ? void 0 : _b.individualParticipantIds) === null || _c === void 0 ? void 0 : _c.length) &&
57715
57522
  (!(individualParticipantIds === null || individualParticipantIds === void 0 ? void 0 : individualParticipantIds.length) ||
57716
- intersection(individualParticipantIds, (_d = side.participant) === null || _d === void 0 ? void 0 : _d.individualParticipantIds).length === ((_f = (_e = side.participant) === null || _e === void 0 ? void 0 : _e.individualParticipantIds) === null || _f === void 0 ? void 0 : _f.length)) &&
57523
+ intersection(individualParticipantIds, (_d = side.participant) === null || _d === void 0 ? void 0 : _d.individualParticipantIds).length ===
57524
+ ((_f = (_e = side.participant) === null || _e === void 0 ? void 0 : _e.individualParticipantIds) === null || _f === void 0 ? void 0 : _f.length)) &&
57717
57525
  side.participant.individualParticipantIds));
57718
57526
  };
57719
57527
  if (teamMap.size) {
@@ -57826,17 +57634,12 @@ function getParticipantStats(_a) {
57826
57634
  if (!isObject(matchUp))
57827
57635
  return { value: { error: INVALID_MATCHUP } };
57828
57636
  var matchUpStatus = matchUp.matchUpStatus, matchUpFormat = matchUp.matchUpFormat, matchUpType = matchUp.matchUpType, winningSide = matchUp.winningSide, score = matchUp.score, sides = matchUp.sides;
57829
- if (!sides ||
57830
- !score ||
57831
- matchUpType === TEAM_MATCHUP ||
57832
- matchUpStatus === BYE)
57637
+ if (!sides || !score || matchUpType === TEAM_MATCHUP || matchUpStatus === BYE)
57833
57638
  return "continue";
57834
57639
  var sideParticipantIds = getSideParticipantIds(sides);
57835
57640
  if (!sideParticipantIds.filter(Boolean).length)
57836
57641
  return "continue";
57837
- var competitiveness = withCompetitiveProfiles &&
57838
- winningSide &&
57839
- ((_k = getMatchUpCompetitiveProfile({ matchUp: matchUp })) === null || _k === void 0 ? void 0 : _k.competitiveness);
57642
+ var competitiveness = withCompetitiveProfiles && winningSide && ((_k = getMatchUpCompetitiveProfile({ matchUp: matchUp })) === null || _k === void 0 ? void 0 : _k.competitiveness);
57840
57643
  relevantMatchUps.push(matchUp);
57841
57644
  var setsTally = countSets({
57842
57645
  matchUpStatus: matchUpStatus,
@@ -57863,12 +57666,8 @@ function getParticipantStats(_a) {
57863
57666
  var participantName = (_b = participantDetails.get(id)) === null || _b === void 0 ? void 0 : _b.participantName;
57864
57667
  var stats = initStats(id, participantName);
57865
57668
  if (stats) {
57866
- var teamSumTally = function (stat, tally) {
57867
- return tally.forEach(function (t, i) { return (stats[stat][i] += t); });
57868
- };
57869
- var tiebreaks = index
57870
- ? __spreadArray([], __read(tiebreaksTally), false).reverse()
57871
- : tiebreaksTally;
57669
+ var teamSumTally = function (stat, tally) { return tally.forEach(function (t, i) { return (stats[stat][i] += t); }); };
57670
+ var tiebreaks = index ? __spreadArray([], __read(tiebreaksTally), false).reverse() : tiebreaksTally;
57872
57671
  var points = index ? __spreadArray([], __read(pointsTally), false).reverse() : pointsTally;
57873
57672
  var games = index ? __spreadArray([], __read(gamesTally), false).reverse() : gamesTally;
57874
57673
  var sets = index ? __spreadArray([], __read(setsTally), false).reverse() : setsTally;
@@ -57993,8 +57792,7 @@ function getParticipantStats(_a) {
57993
57792
  // now rank each team by their ratio on each attribute
57994
57793
  var accessor = "".concat(attr, "Ratio");
57995
57794
  if (typeof stats[accessor] === 'number') {
57996
- var index = (_p = ratio
57997
- .get(accessor)) === null || _p === void 0 ? void 0 : _p.sort(highLowSort).indexOf(stats[accessor]);
57795
+ var index = (_p = ratio.get(accessor)) === null || _p === void 0 ? void 0 : _p.sort(highLowSort).indexOf(stats[accessor]);
57998
57796
  if (typeof index === 'number' && index >= 0) {
57999
57797
  var rankAccessor = "".concat(attr, "Rank");
58000
57798
  stats[rankAccessor] = index + 1;
@@ -65187,11 +64985,15 @@ function venueModify(_a) {
65187
64985
  var venue = result.venue;
65188
64986
  // not valid to modify a venueId
65189
64987
  var validAttributes = Object.keys(venueTemplate()).filter(function (attribute) { return attribute !== 'venueId'; });
65190
- var validModificationAttributes = Object.keys(modifications).filter(function (attribute) { return validAttributes.includes(attribute); });
64988
+ var validModificationAttributes = Object.keys(modifications).filter(function (attribute) {
64989
+ return validAttributes.includes(attribute);
64990
+ });
65191
64991
  if (!validModificationAttributes.length)
65192
64992
  return { error: NO_VALID_ATTRIBUTES };
65193
64993
  var validReplacements = validAttributes.filter(function (attribute) { return !['courts', 'onlineResources'].includes(attribute); });
65194
- var validReplacementAttributes = Object.keys(modifications).filter(function (attribute) { return validReplacements.includes(attribute); });
64994
+ var validReplacementAttributes = Object.keys(modifications).filter(function (attribute) {
64995
+ return validReplacements.includes(attribute);
64996
+ });
65195
64997
  venue &&
65196
64998
  validReplacementAttributes.forEach(function (attribute) {
65197
64999
  var _a;
@@ -65199,12 +65001,10 @@ function venueModify(_a) {
65199
65001
  });
65200
65002
  var existingCourtIds = (_g = (_f = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _f === void 0 ? void 0 : _f.map(function (court) { return court.courtId; })) !== null && _g !== void 0 ? _g : [];
65201
65003
  var courtIdsToModify = ((_h = modifications.courts) === null || _h === void 0 ? void 0 : _h.map(function (court) { return court.courtId; })) || [];
65202
- var courtIdsToDelete = existingCourtIds.filter(function (courtId) { return !courtIdsToModify.includes(courtId); });
65004
+ var courtIdsToDelete = courtIdsToModify.length && existingCourtIds.filter(function (courtId) { return !courtIdsToModify.includes(courtId); });
65203
65005
  var matchUpsWithCourtId = [];
65204
65006
  if (courtIdsToDelete.length) {
65205
- var courtsToDelete = (_j = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _j === void 0 ? void 0 : _j.filter(function (court) {
65206
- return courtIdsToDelete.includes(court.courtId);
65207
- });
65007
+ var courtsToDelete = (_j = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _j === void 0 ? void 0 : _j.filter(function (court) { return courtIdsToDelete.includes(court.courtId); });
65208
65008
  var scheduleDeletionsCount = courtsToDelete === null || courtsToDelete === void 0 ? void 0 : courtsToDelete.map(function (court) {
65209
65009
  var e_3, _a;
65210
65010
  var _b, _c, _d;
@@ -65232,11 +65032,9 @@ function venueModify(_a) {
65232
65032
  }
65233
65033
  return (_d = (_c = result.matchUps) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0;
65234
65034
  }).reduce(function (a, b) { return a + b; });
65235
- if (venue &&
65236
- (!scheduleDeletionsCount || allowModificationWhenMatchUpsScheduled)) {
65237
- venue.courts = (_k = venue.courts) === null || _k === void 0 ? void 0 : _k.filter(function (court) {
65238
- return courtIdsToModify.includes(court.courtId);
65239
- });
65035
+ console.log({ scheduleDeletionsCount: scheduleDeletionsCount });
65036
+ if (venue && (!scheduleDeletionsCount || allowModificationWhenMatchUpsScheduled)) {
65037
+ venue.courts = (_k = venue.courts) === null || _k === void 0 ? void 0 : _k.filter(function (court) { return courtIdsToModify.includes(court.courtId); });
65240
65038
  bulkScheduleTournamentMatchUps({
65241
65039
  schedule: { courtId: '', scheduledDate: '' },
65242
65040
  matchUpDetails: matchUpsWithCourtId,