tods-competition-factory 2.0.5 → 2.0.6

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.5';
6
+ return '2.0.6';
7
7
  }
8
8
 
9
9
  /******************************************************************************
@@ -3377,7 +3377,7 @@ var getMatchUpIds = function (o) {
3377
3377
  if (o === void 0) { o = []; }
3378
3378
  return o.map(getMatchUpId).filter(Boolean);
3379
3379
  };
3380
- var getParticipantIds = function (o) {
3380
+ var getParticipantIds$1 = function (o) {
3381
3381
  if (o === void 0) { o = []; }
3382
3382
  return o.map(getParticipantId).filter(Boolean);
3383
3383
  };
@@ -3400,7 +3400,7 @@ function setDrawParticipantRepresentativeIds(_a) {
3400
3400
  return { error: DRAW_DEFINITION_NOT_FOUND };
3401
3401
  if (!Array.isArray(representativeParticipantIds))
3402
3402
  return { error: INVALID_VALUES };
3403
- var enteredParticipantIds = getParticipantIds((drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) || []);
3403
+ var enteredParticipantIds = getParticipantIds$1((drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) || []);
3404
3404
  // An empty array is valid; if ids provided...
3405
3405
  // check that all representativeParticipantIds are enteredParticipantIds
3406
3406
  if (representativeParticipantIds.length &&
@@ -5096,8 +5096,8 @@ function addUpcomingMatchUps(_a) {
5096
5096
  var firstMatchUp = (loserTargetLink === null || loserTargetLink === void 0 ? void 0 : loserTargetLink.linkCondition) === FIRST_MATCHUP;
5097
5097
  var participants = getMatchUpParticipants(inContextMatchUp);
5098
5098
  if (participants.length) {
5099
- var winnerParticipantIds_1 = getParticipantIds(winnerMatchUp_1 === null || winnerMatchUp_1 === void 0 ? void 0 : winnerMatchUp_1.sides);
5100
- var loserParticipantIds_1 = getParticipantIds(loserMatchUp_1 === null || loserMatchUp_1 === void 0 ? void 0 : loserMatchUp_1.sides);
5099
+ var winnerParticipantIds_1 = getParticipantIds$1(winnerMatchUp_1 === null || winnerMatchUp_1 === void 0 ? void 0 : winnerMatchUp_1.sides);
5100
+ var loserParticipantIds_1 = getParticipantIds$1(loserMatchUp_1 === null || loserMatchUp_1 === void 0 ? void 0 : loserMatchUp_1.sides);
5101
5101
  var winnerDetermined = participants.find(function (_a) {
5102
5102
  var participantId = _a.participantId;
5103
5103
  return winnerParticipantIds_1.includes(participantId);
@@ -5637,7 +5637,7 @@ function getStageEntryTypeCount(_a) {
5637
5637
  var stage = _a.stage, drawDefinition = _a.drawDefinition, entryStatus = _a.entryStatus;
5638
5638
  return drawDefinition.entries.reduce(function (p, c) { return (c.entryStage === stage && c.entryStatus === entryStatus ? p + 1 : p); }, 0);
5639
5639
  }
5640
- function getStageEntries$1(_a) {
5640
+ function getStageEntries$2(_a) {
5641
5641
  var _b, _c;
5642
5642
  var provisionalPositioning = _a.provisionalPositioning, placementGroup = _a.placementGroup, drawDefinition = _a.drawDefinition, stageSequence = _a.stageSequence, entryStatuses = _a.entryStatuses, structureId = _a.structureId, roundTarget = _a.roundTarget, stages = _a.stages, stage = _a.stage;
5643
5643
  var entries = (_c = (_b = drawDefinition.entries) === null || _b === void 0 ? void 0 : _b.reduce(function (entries, entry) {
@@ -5770,7 +5770,7 @@ function getStructureSeedAssignments(_a) {
5770
5770
  var isPlayoffStructure = stage === PLAY_OFF;
5771
5771
  var entries = isPlayoffStructure &&
5772
5772
  drawDefinition &&
5773
- getStageEntries$1({
5773
+ getStageEntries$2({
5774
5774
  provisionalPositioning: provisionalPositioning,
5775
5775
  drawDefinition: drawDefinition,
5776
5776
  stageSequence: stageSequence,
@@ -15372,7 +15372,7 @@ function deleteParticipants(params) {
15372
15372
  return participantsRemovedCount ? __assign(__assign({}, SUCCESS), { participantsRemovedCount: participantsRemovedCount }) : { error: CANNOT_REMOVE_PARTICIPANTS };
15373
15373
  }
15374
15374
 
15375
- function getStageEntries(_a) {
15375
+ function getStageEntries$1(_a) {
15376
15376
  var _b, _c;
15377
15377
  var _d = _a.selected, selected = _d === void 0 ? true : _d, drawDefinition = _a.drawDefinition, entryStatuses = _a.entryStatuses, drawId = _a.drawId, event = _a.event, stage = _a.stage;
15378
15378
  var entries = (_b = event.entries) !== null && _b !== void 0 ? _b : [];
@@ -15426,7 +15426,7 @@ function destroyGroupEntry(_a) {
15426
15426
  var entry = eventEntries.find(function (entry) { return entry.participantId === participantId; });
15427
15427
  if (!entry)
15428
15428
  return { error: PARTICIPANT_ENTRY_NOT_FOUND };
15429
- var stageEntries = getStageEntries({
15429
+ var stageEntries = getStageEntries$1({
15430
15430
  selected: false,
15431
15431
  drawDefinition: drawDefinition,
15432
15432
  drawId: drawId,
@@ -19049,7 +19049,7 @@ function positionUnseededParticipants(_a) {
19049
19049
  var stage = structure.stage, stageSequence = structure.stageSequence;
19050
19050
  var roundTarget = stage === QUALIFYING ? (_c = (_b = findExtension({ element: structure, name: ROUND_TARGET })) === null || _b === void 0 ? void 0 : _b.extension) === null || _c === void 0 ? void 0 : _c.value : undefined;
19051
19051
  var entryStatuses = DIRECT_ENTRY_STATUSES;
19052
- var entries = getStageEntries$1({
19052
+ var entries = getStageEntries$2({
19053
19053
  provisionalPositioning: provisionalPositioning,
19054
19054
  drawDefinition: drawDefinition,
19055
19055
  stageSequence: stageSequence,
@@ -19294,7 +19294,7 @@ function getByesData(_a) {
19294
19294
  : matchUps.length;
19295
19295
  // get stage/stageSequence Entries and qualifiers
19296
19296
  var structureId = structure.structureId, stage = structure.stage, stageSequence = structure.stageSequence;
19297
- var entries = getStageEntries$1({
19297
+ var entries = getStageEntries$2({
19298
19298
  entryStatuses: STRUCTURE_SELECTED_STATUSES,
19299
19299
  provisionalPositioning: provisionalPositioning,
19300
19300
  drawDefinition: drawDefinition,
@@ -19918,7 +19918,7 @@ function automatedPositioning(_a) {
19918
19918
  structureId: structureId,
19919
19919
  }).qualifiersCount;
19920
19920
  var entryStatuses = DIRECT_ENTRY_STATUSES;
19921
- var entries = getStageEntries$1({
19921
+ var entries = getStageEntries$2({
19922
19922
  stageSequence: structure.stageSequence,
19923
19923
  provisionalPositioning: provisionalPositioning,
19924
19924
  stage: structure.stage,
@@ -26909,7 +26909,7 @@ function getEntriesAndSeedsCount(_a) {
26909
26909
  var policyDefinitions = _a.policyDefinitions, drawDefinition = _a.drawDefinition, drawSize = _a.drawSize, drawId = _a.drawId, event = _a.event, stage = _a.stage;
26910
26910
  if (!event)
26911
26911
  return { error: MISSING_EVENT };
26912
- var _b = getStageEntries({
26912
+ var _b = getStageEntries$1({
26913
26913
  drawDefinition: drawDefinition,
26914
26914
  drawId: drawId,
26915
26915
  stage: stage,
@@ -27100,7 +27100,7 @@ function getEligibleVoluntaryConsolationParticipants(_a) {
27100
27100
  inContext: true,
27101
27101
  drawDefinition: drawDefinition,
27102
27102
  })) === null || _e === void 0 ? void 0 : _e.matchUps) !== null && _f !== void 0 ? _f : [];
27103
- var voluntaryConsolationEntries = getStageEntries$1({
27103
+ var voluntaryConsolationEntries = getStageEntries$2({
27104
27104
  stage: VOLUNTARY_CONSOLATION,
27105
27105
  drawDefinition: drawDefinition,
27106
27106
  });
@@ -28878,7 +28878,7 @@ function positionActions(params) {
28878
28878
  stages.push(MAIN);
28879
28879
  if (stage === MAIN)
28880
28880
  stages.push(CONSOLATION);
28881
- var stageEntries = getStageEntries$1({
28881
+ var stageEntries = getStageEntries$2({
28882
28882
  entryStatuses: DIRECT_ENTRY_STATUSES,
28883
28883
  provisionalPositioning: provisionalPositioning,
28884
28884
  drawDefinition: drawDefinition,
@@ -30139,7 +30139,7 @@ function generateVoluntaryConsolation(params) {
30139
30139
  if (!drawDefinition)
30140
30140
  return { error: MISSING_DRAW_DEFINITION };
30141
30141
  var stage = VOLUNTARY_CONSOLATION;
30142
- var entries = getStageEntries$1({
30142
+ var entries = getStageEntries$2({
30143
30143
  stageSequence: 1,
30144
30144
  drawDefinition: drawDefinition,
30145
30145
  stage: stage,
@@ -30701,9 +30701,9 @@ var ENCOUNTER_VALUE = 100;
30701
30701
  var SAME_TEAM_VALUE = 100;
30702
30702
  var MAX_ITERATIONS = 4000;
30703
30703
  function generateDrawMaticRound(_a) {
30704
- var e_1, _b, e_2, _c, e_3, _d;
30705
- var _e, _f;
30706
- var _g = _a.encounterValue, encounterValue = _g === void 0 ? ENCOUNTER_VALUE : _g, _h = _a.sameTeamValue, sameTeamValue = _h === void 0 ? SAME_TEAM_VALUE : _h, _j = _a.maxIterations, maxIterations = _j === void 0 ? MAX_ITERATIONS : _j, _k = _a.generateMatchUps, generateMatchUps = _k === void 0 ? true : _k, tournamentParticipants = _a.tournamentParticipants, ignoreLastRoundNumber = _a.ignoreLastRoundNumber, participantIds = _a.participantIds, drawDefinition = _a.drawDefinition, adHocRatings = _a.adHocRatings, _l = _a.salted, salted = _l === void 0 ? 0.5 : _l, roundNumber = _a.roundNumber, structureId = _a.structureId, matchUpIds = _a.matchUpIds, eventType = _a.eventType, structure = _a.structure, scaleName = _a.scaleName, idPrefix = _a.idPrefix, isMock = _a.isMock, event = _a.event;
30704
+ var _b, _c;
30705
+ var _d = _a.encounterValue, encounterValue = _d === void 0 ? ENCOUNTER_VALUE : _d, _e = _a.sameTeamValue, sameTeamValue = _e === void 0 ? SAME_TEAM_VALUE : _e, _f = _a.maxIterations, maxIterations = _f === void 0 ? MAX_ITERATIONS : _f, _g = _a.generateMatchUps, generateMatchUps = _g === void 0 ? true : _g, ignoreLastRoundNumber = _a.ignoreLastRoundNumber, iterationMatchUps = _a.iterationMatchUps, // necessary when called iteratively and matchUps are not yet added to structure
30706
+ tournamentRecord = _a.tournamentRecord, participantIds = _a.participantIds, drawDefinition = _a.drawDefinition, adHocRatings = _a.adHocRatings, _h = _a.salted, salted = _h === void 0 ? 0.5 : _h, roundNumber = _a.roundNumber, structureId = _a.structureId, matchUpIds = _a.matchUpIds, eventType = _a.eventType, structure = _a.structure, scaleName = _a.scaleName, idPrefix = _a.idPrefix, isMock = _a.isMock, event = _a.event;
30707
30707
  if (!drawDefinition)
30708
30708
  return { error: MISSING_DRAW_DEFINITION };
30709
30709
  if (!structure && !structureId)
@@ -30717,74 +30717,24 @@ function generateDrawMaticRound(_a) {
30717
30717
  return { error: MISSING_PARTICIPANT_IDS };
30718
30718
  }
30719
30719
  // create valueObject for each previous encounter within the structure
30720
- var encounters = getEncounters({ matchUps: (_e = structure === null || structure === void 0 ? void 0 : structure.matchUps) !== null && _e !== void 0 ? _e : [] }).encounters;
30721
- // valueObjects provide "weighting" to each possible pairing of participants
30722
- // {
30723
- // 'P-I-0|P-I-1': 1,
30724
- // 'P-I-0|P-I-2': 1,
30725
- // 'P-I-0|P-I-3': 1
30726
- // }
30727
- var valueObjects = {};
30728
- try {
30729
- for (var encounters_1 = __values(encounters), encounters_1_1 = encounters_1.next(); !encounters_1_1.done; encounters_1_1 = encounters_1.next()) {
30730
- var pairing = encounters_1_1.value;
30731
- if (!valueObjects[pairing])
30732
- valueObjects[pairing] = 0;
30733
- valueObjects[pairing] += encounterValue;
30734
- }
30735
- }
30736
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
30737
- finally {
30738
- try {
30739
- if (encounters_1_1 && !encounters_1_1.done && (_b = encounters_1.return)) _b.call(encounters_1);
30740
- }
30741
- finally { if (e_1) throw e_1.error; }
30742
- }
30743
- var teamParticipants = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (_a) {
30744
- var participantType = _a.participantType;
30745
- return participantType === TEAM;
30746
- });
30747
- if (teamParticipants) {
30748
- try {
30749
- // add SAME_TEAM_VALUE for participants who appear on the same team
30750
- for (var teamParticipants_1 = __values(teamParticipants), teamParticipants_1_1 = teamParticipants_1.next(); !teamParticipants_1_1.done; teamParticipants_1_1 = teamParticipants_1.next()) {
30751
- var teamParticipant = teamParticipants_1_1.value;
30752
- var participantIds_1 = (_f = teamParticipant.individualParticipantIds) !== null && _f !== void 0 ? _f : [];
30753
- var uniquePairings_2 = getPairingsData({ participantIds: participantIds_1 }).uniquePairings;
30754
- try {
30755
- for (var uniquePairings_1 = (e_3 = void 0, __values(uniquePairings_2)), uniquePairings_1_1 = uniquePairings_1.next(); !uniquePairings_1_1.done; uniquePairings_1_1 = uniquePairings_1.next()) {
30756
- var pairing = uniquePairings_1_1.value;
30757
- if (!valueObjects[pairing])
30758
- valueObjects[pairing] = 0;
30759
- valueObjects[pairing] += sameTeamValue;
30760
- }
30761
- }
30762
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
30763
- finally {
30764
- try {
30765
- if (uniquePairings_1_1 && !uniquePairings_1_1.done && (_d = uniquePairings_1.return)) _d.call(uniquePairings_1);
30766
- }
30767
- finally { if (e_3) throw e_3.error; }
30768
- }
30769
- }
30770
- }
30771
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
30772
- finally {
30773
- try {
30774
- if (teamParticipants_1_1 && !teamParticipants_1_1.done && (_c = teamParticipants_1.return)) _c.call(teamParticipants_1);
30775
- }
30776
- finally { if (e_2) throw e_2.error; }
30777
- }
30778
- }
30720
+ var consideredMatchUps = __spreadArray(__spreadArray([], __read((iterationMatchUps !== null && iterationMatchUps !== void 0 ? iterationMatchUps : [])), false), __read(((_b = structure === null || structure === void 0 ? void 0 : structure.matchUps) !== null && _b !== void 0 ? _b : [])), false);
30721
+ var encounters = getEncounters({ matchUps: consideredMatchUps }).encounters;
30722
+ var tournamentParticipants = (_c = tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) !== null && _c !== void 0 ? _c : [];
30723
+ var valueObjects = getValueObjects({
30724
+ tournamentParticipants: tournamentParticipants,
30725
+ encounterValue: encounterValue,
30726
+ sameTeamValue: sameTeamValue,
30727
+ encounters: encounters,
30728
+ }).valueObjects;
30779
30729
  // deltaObjects contain the difference in ratings between two participants
30780
30730
  // {
30781
30731
  // 'P-I-0|P-I-1': 0,
30782
30732
  // 'P-I-0|P-I-2': 0,
30783
30733
  // 'P-I-0|P-I-3': 0
30784
30734
  // }
30785
- var _m = getPairingsData({
30735
+ var _j = getPairingsData({
30786
30736
  participantIds: participantIds,
30787
- }), uniquePairings = _m.uniquePairings, possiblePairings = _m.possiblePairings, deltaObjects = _m.deltaObjects;
30737
+ }), uniquePairings = _j.uniquePairings, possiblePairings = _j.possiblePairings, deltaObjects = _j.deltaObjects;
30788
30738
  var params = {
30789
30739
  tournamentParticipants: tournamentParticipants,
30790
30740
  possiblePairings: possiblePairings,
@@ -30800,7 +30750,7 @@ function generateDrawMaticRound(_a) {
30800
30750
  structure: structure,
30801
30751
  salted: salted,
30802
30752
  };
30803
- var _o = getPairings(params), candidatesCount = _o.candidatesCount, participantIdPairings = _o.participantIdPairings, iterations = _o.iterations, candidate = _o.candidate;
30753
+ var _k = getPairings(params), candidatesCount = _k.candidatesCount, participantIdPairings = _k.participantIdPairings, iterations = _k.iterations, candidate = _k.candidate;
30804
30754
  if (!candidatesCount)
30805
30755
  return { error: NO_CANDIDATES };
30806
30756
  var generatedRoundNumber;
@@ -30826,88 +30776,69 @@ function generateDrawMaticRound(_a) {
30826
30776
  var maxDelta = candidate.maxDelta, maxDiff = candidate.maxDiff;
30827
30777
  return __assign(__assign({ roundNumber: generatedRoundNumber, participantIdPairings: participantIdPairings, candidatesCount: candidatesCount }, SUCCESS), { iterations: iterations, matchUps: matchUps, maxDelta: maxDelta, maxDiff: maxDiff });
30828
30778
  }
30829
-
30830
- // internal use only; set matchUpFormat for a matchUp or structure
30831
- function setMatchUpMatchUpFormat(params) {
30832
- var e_1, _a;
30833
- var structureIds = params.structureIds;
30834
- var tournamentRecord = params.tournamentRecord, drawDefinition = params.drawDefinition, matchUpFormat = params.matchUpFormat, structureId = params.structureId, matchUpId = params.matchUpId, event = params.event;
30835
- if (!drawDefinition)
30836
- return { error: MISSING_DRAW_DEFINITION };
30837
- if (!matchUpFormat)
30838
- return { error: MISSING_MATCHUP_FORMAT };
30839
- if (!isValidMatchUpFormat({ matchUpFormat: matchUpFormat }))
30840
- return { error: UNRECOGNIZED_MATCHUP_FORMAT };
30841
- var stack = 'setMatchUpFormat';
30842
- if (matchUpId) {
30843
- var result = findDrawMatchUp({
30844
- drawDefinition: drawDefinition,
30845
- matchUpId: matchUpId,
30846
- event: event,
30847
- });
30848
- if (result.error)
30849
- return result;
30850
- if (!result.matchUp)
30851
- return { error: MATCHUP_NOT_FOUND };
30852
- var matchUp = result.matchUp;
30853
- if ((matchUp === null || matchUp === void 0 ? void 0 : matchUp.matchUpType) === TEAM$2)
30854
- return {
30855
- error: INVALID_MATCHUP,
30856
- info: 'Cannot set matchUpFormat when { matchUpType: TEAM }',
30857
- };
30858
- matchUp.matchUpFormat = matchUpFormat;
30859
- modifyMatchUpNotice({
30860
- tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
30861
- eventId: event === null || event === void 0 ? void 0 : event.eventId,
30862
- context: stack,
30863
- drawDefinition: drawDefinition,
30864
- matchUp: matchUp,
30865
- });
30779
+ function getValueObjects(_a) {
30780
+ // valueObjects provide "weighting" to each possible pairing of participants
30781
+ // {
30782
+ // 'P-I-0|P-I-1': 1,
30783
+ // 'P-I-0|P-I-2': 1,
30784
+ // 'P-I-0|P-I-3': 1
30785
+ // }
30786
+ var e_1, _b, e_2, _c, e_3, _d;
30787
+ var _e;
30788
+ var encounters = _a.encounters, tournamentParticipants = _a.tournamentParticipants, encounterValue = _a.encounterValue, sameTeamValue = _a.sameTeamValue;
30789
+ var valueObjects = {};
30790
+ try {
30791
+ for (var encounters_1 = __values(encounters), encounters_1_1 = encounters_1.next(); !encounters_1_1.done; encounters_1_1 = encounters_1.next()) {
30792
+ var pairing = encounters_1_1.value;
30793
+ if (!valueObjects[pairing])
30794
+ valueObjects[pairing] = 0;
30795
+ valueObjects[pairing] += encounterValue;
30796
+ }
30866
30797
  }
30867
- else if (Array.isArray(structureIds)) {
30868
- if ((event === null || event === void 0 ? void 0 : event.eventType) === TEAM$2)
30869
- return { error: INVALID_EVENT_TYPE };
30798
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
30799
+ finally {
30870
30800
  try {
30871
- for (var structureIds_1 = __values(structureIds), structureIds_1_1 = structureIds_1.next(); !structureIds_1_1.done; structureIds_1_1 = structureIds_1.next()) {
30872
- var structureId_1 = structureIds_1_1.value;
30873
- var result = findStructure({ drawDefinition: drawDefinition, structureId: structureId_1 });
30874
- if (result.error)
30875
- return result;
30876
- if (!result.structure) {
30877
- return { error: STRUCTURE_NOT_FOUND };
30801
+ if (encounters_1_1 && !encounters_1_1.done && (_b = encounters_1.return)) _b.call(encounters_1);
30802
+ }
30803
+ finally { if (e_1) throw e_1.error; }
30804
+ }
30805
+ var teamParticipants = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (_a) {
30806
+ var participantType = _a.participantType;
30807
+ return participantType === TEAM;
30808
+ });
30809
+ if (teamParticipants) {
30810
+ try {
30811
+ // add SAME_TEAM_VALUE for participants who appear on the same team
30812
+ for (var teamParticipants_1 = __values(teamParticipants), teamParticipants_1_1 = teamParticipants_1.next(); !teamParticipants_1_1.done; teamParticipants_1_1 = teamParticipants_1.next()) {
30813
+ var teamParticipant = teamParticipants_1_1.value;
30814
+ var participantIds = (_e = teamParticipant.individualParticipantIds) !== null && _e !== void 0 ? _e : [];
30815
+ var uniquePairings = getPairingsData({ participantIds: participantIds }).uniquePairings;
30816
+ try {
30817
+ for (var uniquePairings_1 = (e_3 = void 0, __values(uniquePairings)), uniquePairings_1_1 = uniquePairings_1.next(); !uniquePairings_1_1.done; uniquePairings_1_1 = uniquePairings_1.next()) {
30818
+ var pairing = uniquePairings_1_1.value;
30819
+ if (!valueObjects[pairing])
30820
+ valueObjects[pairing] = 0;
30821
+ valueObjects[pairing] += sameTeamValue;
30822
+ }
30878
30823
  }
30879
- else {
30880
- result.structure.matchUpFormat = matchUpFormat;
30824
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
30825
+ finally {
30826
+ try {
30827
+ if (uniquePairings_1_1 && !uniquePairings_1_1.done && (_d = uniquePairings_1.return)) _d.call(uniquePairings_1);
30828
+ }
30829
+ finally { if (e_3) throw e_3.error; }
30881
30830
  }
30882
30831
  }
30883
30832
  }
30884
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
30833
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
30885
30834
  finally {
30886
30835
  try {
30887
- if (structureIds_1_1 && !structureIds_1_1.done && (_a = structureIds_1.return)) _a.call(structureIds_1);
30836
+ if (teamParticipants_1_1 && !teamParticipants_1_1.done && (_c = teamParticipants_1.return)) _c.call(teamParticipants_1);
30888
30837
  }
30889
- finally { if (e_1) throw e_1.error; }
30890
- }
30891
- }
30892
- else if (structureId) {
30893
- if ((event === null || event === void 0 ? void 0 : event.eventType) === TEAM$2)
30894
- return { error: INVALID_EVENT_TYPE };
30895
- var result = findStructure({ drawDefinition: drawDefinition, structureId: structureId });
30896
- if (result.error)
30897
- return result;
30898
- if (!result.structure) {
30899
- return { error: STRUCTURE_NOT_FOUND };
30900
- }
30901
- else {
30902
- result.structure.matchUpFormat = matchUpFormat;
30838
+ finally { if (e_2) throw e_2.error; }
30903
30839
  }
30904
30840
  }
30905
- else if (drawDefinition) {
30906
- drawDefinition.matchUpFormat = matchUpFormat;
30907
- }
30908
- structureIds = structureIds !== null && structureIds !== void 0 ? structureIds : (structureId ? [structureId] : undefined);
30909
- modifyDrawNotice({ drawDefinition: drawDefinition, structureIds: structureIds });
30910
- return __assign({}, SUCCESS);
30841
+ return { valueObjects: valueObjects };
30911
30842
  }
30912
30843
 
30913
30844
  function credits() {
@@ -35913,7 +35844,7 @@ function validateAndDeriveDrawValues(params) {
35913
35844
  });
35914
35845
  }
35915
35846
  var seedingPolicy = (_a = policyDefinitions === null || policyDefinitions === void 0 ? void 0 : policyDefinitions[POLICY_TYPE_SEEDING]) !== null && _a !== void 0 ? _a : appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_SEEDING];
35916
- var seedingProfile = (_e = (_b = params.seedingProfile) !== null && _b !== void 0 ? _b : (_d = (_c = seedingPolicy === null || seedingPolicy === void 0 ? void 0 : seedingPolicy.seedingProfile) === null || _c === void 0 ? void 0 : _c.drawTypes) === null || _d === void 0 ? void 0 : _d[drawType]) !== null && _e !== void 0 ? _e : seedingPolicy === null || seedingPolicy === void 0 ? void 0 : seedingPolicy.seedingProfile;
35847
+ var seedingProfile = (_e = (_b = params.seedingProfile) !== null && _b !== void 0 ? _b : (_d = (_c = seedingPolicy === null || seedingPolicy === void 0 ? void 0 : seedingPolicy.seedingProfile) === null || _c === void 0 ? void 0 : _c.drawTypes) === null || _d === void 0 ? void 0 : _d[drawType !== null && drawType !== void 0 ? drawType : '']) !== null && _e !== void 0 ? _e : seedingPolicy === null || seedingPolicy === void 0 ? void 0 : seedingPolicy.seedingProfile;
35917
35848
  // extend policyDefinitions only if a seedingProfile was specified in params
35918
35849
  if (params.seedingProfile) {
35919
35850
  if (!policyDefinitions[POLICY_TYPE_SEEDING]) {
@@ -36007,110 +35938,194 @@ function checkDrawTypeIsAllowed(params) {
36007
35938
  return __assign({}, SUCCESS);
36008
35939
  }
36009
35940
 
36010
- // add collectionIds if missing
36011
- function checkTieFormat(_a) {
36012
- var e_1, _b;
36013
- var tieFormat = _a.tieFormat;
36014
- var result = validateTieFormat({
36015
- checkCollectionIds: false,
36016
- tieFormat: tieFormat,
35941
+ function processExistingDrawDefinition(params) {
35942
+ var _a, _b, _c, _d, _e;
35943
+ var drawDefinition = params.drawDefinition;
35944
+ var existingQualifyingPlaceholderStructureId = params.existingQualifyingPlaceholderStructureId, drawEntries = params.drawEntries, appliedPolicies = params.appliedPolicies, structureId = params.structureId, idPrefix = params.idPrefix, isMock = params.isMock;
35945
+ var qualifyingProfiles = params.qualifyingProfiles;
35946
+ var qualifyingResult = (qualifyingProfiles === null || qualifyingProfiles === void 0 ? void 0 : qualifyingProfiles.length)
35947
+ ? generateQualifyingStructures({
35948
+ uuids: params.uuids,
35949
+ qualifyingProfiles: qualifyingProfiles,
35950
+ appliedPolicies: appliedPolicies,
35951
+ idPrefix: idPrefix,
35952
+ isMock: isMock,
35953
+ })
35954
+ : undefined;
35955
+ if (qualifyingResult === null || qualifyingResult === void 0 ? void 0 : qualifyingResult.error) {
35956
+ return qualifyingResult;
35957
+ }
35958
+ drawDefinition.structures = (_a = drawDefinition.structures) === null || _a === void 0 ? void 0 : _a.filter(function (_a) {
35959
+ var structureId = _a.structureId;
35960
+ return structureId !== existingQualifyingPlaceholderStructureId;
35961
+ });
35962
+ drawDefinition.links = (_b = drawDefinition.links) === null || _b === void 0 ? void 0 : _b.filter(function (_a) {
35963
+ var source = _a.source;
35964
+ return source.structureId !== existingQualifyingPlaceholderStructureId;
35965
+ });
35966
+ var _f = qualifyingResult !== null && qualifyingResult !== void 0 ? qualifyingResult : {}, qualifiersCount = _f.qualifiersCount, qualifyingDrawPositionsCount = _f.qualifyingDrawPositionsCount, qualifyingDetails = _f.qualifyingDetails;
35967
+ if (qualifyingDrawPositionsCount) {
35968
+ if (qualifyingResult === null || qualifyingResult === void 0 ? void 0 : qualifyingResult.structures) {
35969
+ (_c = drawDefinition.structures) === null || _c === void 0 ? void 0 : _c.push.apply(_c, __spreadArray([], __read(qualifyingResult.structures), false));
35970
+ }
35971
+ if (qualifyingResult === null || qualifyingResult === void 0 ? void 0 : qualifyingResult.links) {
35972
+ (_d = drawDefinition.links) === null || _d === void 0 ? void 0 : _d.push.apply(_d, __spreadArray([], __read(qualifyingResult.links), false));
35973
+ }
35974
+ }
35975
+ var mainStructure = (_e = drawDefinition.structures) === null || _e === void 0 ? void 0 : _e.find(function (_a) {
35976
+ var stage = _a.stage, stageSequence = _a.stageSequence;
35977
+ return stage === MAIN && stageSequence === 1;
35978
+ });
35979
+ var existingQualifiersCount = getQualifiersCount({
35980
+ stageSequence: 1,
35981
+ drawDefinition: drawDefinition,
35982
+ structureId: structureId,
35983
+ stage: MAIN,
35984
+ }).qualifiersCount;
35985
+ var derivedQualifiersCount = Math.max(qualifiersCount !== null && qualifiersCount !== void 0 ? qualifiersCount : 0, existingQualifiersCount !== null && existingQualifiersCount !== void 0 ? existingQualifiersCount : 0);
35986
+ var result = setStageQualifiersCount({
35987
+ qualifiersCount: derivedQualifiersCount,
35988
+ drawDefinition: drawDefinition,
35989
+ stage: MAIN,
35990
+ });
35991
+ if (result.error)
35992
+ return result;
35993
+ result = setStageDrawSize({
35994
+ drawSize: qualifyingDrawPositionsCount,
35995
+ stage: QUALIFYING,
35996
+ drawDefinition: drawDefinition,
36017
35997
  });
36018
35998
  if (result.error)
36019
35999
  return result;
36000
+ addEntries$1({ drawDefinition: drawDefinition, drawEntries: drawEntries });
36001
+ var qResult = processQualifyingDetails({ mainStructure: mainStructure, qualifyingDetails: qualifyingDetails, drawDefinition: drawDefinition });
36002
+ if (qResult.error)
36003
+ return qResult;
36004
+ return { drawDefinition: drawDefinition, structureId: structureId };
36005
+ }
36006
+ function addEntries$1(_a) {
36007
+ var e_1, _b;
36008
+ var _c;
36009
+ var drawDefinition = _a.drawDefinition, drawEntries = _a.drawEntries;
36020
36010
  try {
36021
- for (var _c = __values(tieFormat.collectionDefinitions), _d = _c.next(); !_d.done; _d = _c.next()) {
36022
- var collectionDefinition = _d.value;
36023
- if (!collectionDefinition.collectionId)
36024
- collectionDefinition.collectionId = UUID();
36011
+ for (var _d = __values((drawEntries !== null && drawEntries !== void 0 ? drawEntries : []).filter(function (_a) {
36012
+ var entryStage = _a.entryStage;
36013
+ return entryStage === QUALIFYING;
36014
+ })), _e = _d.next(); !_e.done; _e = _d.next()) {
36015
+ var entry = _e.value;
36016
+ var entryData = __assign(__assign({}, entry), { entryStage: (_c = entry.entryStage) !== null && _c !== void 0 ? _c : MAIN, drawDefinition: drawDefinition });
36017
+ // ignore errors (EXITING_PARTICIPANT)
36018
+ addDrawEntry(entryData);
36025
36019
  }
36026
36020
  }
36027
36021
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
36028
36022
  finally {
36029
36023
  try {
36030
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
36024
+ if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
36031
36025
  }
36032
36026
  finally { if (e_1) throw e_1.error; }
36033
36027
  }
36034
- return { tieFormat: tieFormat };
36035
36028
  }
36036
-
36037
- var definitionTemplate = function () { return ({
36038
- matchUpType: undefined,
36039
- drawName: undefined,
36040
- drawId: undefined,
36041
- structures: [],
36042
- entries: [],
36043
- links: [],
36044
- }); };
36045
-
36046
- function newDrawDefinition(params) {
36047
- var _a = params !== null && params !== void 0 ? params : {}, _b = _a.drawId, drawId = _b === void 0 ? UUID() : _b, processCodes = _a.processCodes, matchUpType = _a.matchUpType, drawType = _a.drawType;
36048
- var drawDefinition = definitionTemplate();
36049
- return Object.assign(drawDefinition, {
36050
- processCodes: processCodes,
36051
- matchUpType: matchUpType,
36052
- drawType: drawType,
36053
- drawId: drawId,
36054
- });
36029
+ function processQualifyingDetails(_a) {
36030
+ var e_2, _b;
36031
+ var _c;
36032
+ var mainStructure = _a.mainStructure, qualifyingDetails = _a.qualifyingDetails, drawDefinition = _a.drawDefinition;
36033
+ try {
36034
+ for (var _d = __values(qualifyingDetails || []), _e = _d.next(); !_e.done; _e = _d.next()) {
36035
+ var qualifyingDetail = _e.value;
36036
+ var qualifyingRoundNumber = qualifyingDetail.finalQualifyingRoundNumber, qualifyingStructureId = qualifyingDetail.finalQualifyingStructureId, targetEntryRound = qualifyingDetail.roundTarget, finishingPositions = qualifyingDetail.finishingPositions, linkType = qualifyingDetail.linkType;
36037
+ var link = mainStructure &&
36038
+ ((_c = generateQualifyingLink({
36039
+ targetStructureId: mainStructure.structureId,
36040
+ sourceStructureId: qualifyingStructureId,
36041
+ sourceRoundNumber: qualifyingRoundNumber,
36042
+ finishingPositions: finishingPositions,
36043
+ targetEntryRound: targetEntryRound,
36044
+ linkType: linkType,
36045
+ })) === null || _c === void 0 ? void 0 : _c.link);
36046
+ if (link === null || link === void 0 ? void 0 : link.error)
36047
+ return link;
36048
+ if (link) {
36049
+ if (!drawDefinition.links)
36050
+ drawDefinition.links = [];
36051
+ drawDefinition.links.push(link);
36052
+ }
36053
+ }
36054
+ }
36055
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
36056
+ finally {
36057
+ try {
36058
+ if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
36059
+ }
36060
+ finally { if (e_2) throw e_2.error; }
36061
+ }
36062
+ return { error: undefined };
36055
36063
  }
36056
36064
 
36057
36065
  function drawMatic(params) {
36058
- var e_1, _a, e_2, _b;
36059
- var _c, _d, _e, _f, _g, _h, _j, _k, _l;
36060
- var restrictEntryStatus = params.restrictEntryStatus, enableDoubleRobin = params.enableDoubleRobin, _m = params.adHocRatings, adHocRatings = _m === void 0 ? {} : _m, generateMatchUps = params.generateMatchUps, tournamentRecord = params.tournamentRecord, encounterValue = params.encounterValue, sameTeamValue = params.sameTeamValue, drawDefinition = params.drawDefinition, scaleAccessor = params.scaleAccessor, maxIterations = params.maxIterations, roundsCount = params.roundsCount, matchUpIds = params.matchUpIds, scaleName = params.scaleName, // custom rating name to seed dynamic ratings
36061
- idPrefix = params.idPrefix, salted = params.salted, event = params.event;
36062
- if (roundsCount && typeof roundsCount !== 'number') {
36063
- return { error: INVALID_VALUES, info: 'roundsCount must be a number' };
36064
- }
36065
- if (typeof drawDefinition !== 'object' || (drawDefinition.drawType && drawDefinition.drawType !== AD_HOC)) {
36066
- return { error: INVALID_DRAW_DEFINITION };
36067
- }
36068
- var participantIds = params.participantIds, structureId = params.structureId;
36069
- var isMock = (_c = tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.isMock) !== null && _c !== void 0 ? _c : params.isMock;
36070
- if (!Array.isArray(drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) && participantIds && !Array.isArray(participantIds)) {
36071
- return { error: INVALID_VALUES, info: 'Missing Entries' };
36072
- }
36073
- var eventType = (_d = params.eventType) !== null && _d !== void 0 ? _d : event === null || event === void 0 ? void 0 : event.eventType;
36074
- var enteredParticipantIds = (_f = (_e = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) === null || _e === void 0 ? void 0 : _e.filter(function (entry) {
36075
- var entryStatus = entry.entryStatus;
36076
- return !restrictEntryStatus || STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
36077
- }).map(getParticipantId)) !== null && _f !== void 0 ? _f : [];
36078
- if (participantIds) {
36079
- // ensure all participantIds are in drawDefinition.entries
36080
- var invalidParticipantIds = participantIds.filter(function (participantId) { return !(enteredParticipantIds === null || enteredParticipantIds === void 0 ? void 0 : enteredParticipantIds.includes(participantId)); });
36081
- if (invalidParticipantIds === null || invalidParticipantIds === void 0 ? void 0 : invalidParticipantIds.length)
36082
- return decorateResult({
36083
- result: { error: INVALID_PARTICIPANT_ID },
36084
- info: { invalidParticipantIds: invalidParticipantIds },
36085
- });
36086
- }
36087
- else {
36088
- participantIds = enteredParticipantIds;
36089
- }
36090
- if (roundsCount &&
36091
- roundsCount > participantIds.length - 1 &&
36092
- (!enableDoubleRobin || roundsCount > (participantIds.length - 1) * 2)) {
36093
- return { error: INVALID_VALUES, info: 'Not enough participants for roundsCount' };
36066
+ var e_1, _a;
36067
+ var _b, _c, _d, _e, _f, _g;
36068
+ var paramsCheck = checkParams(params);
36069
+ if (paramsCheck === null || paramsCheck === void 0 ? void 0 : paramsCheck.error)
36070
+ return paramsCheck;
36071
+ var idsResult = getParticipantIds(params);
36072
+ if (idsResult.error)
36073
+ return idsResult;
36074
+ var structureResult = getStructure(params);
36075
+ if (structureResult.error)
36076
+ return structureResult;
36077
+ var adHocRatings = getAdHocRatings(params);
36078
+ // TODO: update dynamic ratings based on matchUps present from last played round
36079
+ // use scaleEngine.generateDynamicRatings(); see dynamicCalculations.test.ts
36080
+ var isMock = (_c = (_b = params.tournamentRecord) === null || _b === void 0 ? void 0 : _b.isMock) !== null && _c !== void 0 ? _c : params.isMock;
36081
+ var eventType = (_d = params.eventType) !== null && _d !== void 0 ? _d : (_e = params.event) === null || _e === void 0 ? void 0 : _e.eventType;
36082
+ var matchUps = [];
36083
+ var roundResults = [];
36084
+ var roundNumber;
36085
+ try {
36086
+ for (var _h = __values(generateRange(1, ((_f = params.roundsCount) !== null && _f !== void 0 ? _f : 1) + 1)), _j = _h.next(); !_j.done; _j = _h.next()) {
36087
+ var iteration = _j.value;
36088
+ var result = generateDrawMaticRound(__assign(__assign({}, params), { participantIds: idsResult.participantIds, structure: structureResult.structure, ignoreLastRoundNumber: true, iterationMatchUps: matchUps, adHocRatings: adHocRatings, roundNumber: roundNumber, eventType: eventType, isMock: isMock }));
36089
+ if (result.error)
36090
+ return result;
36091
+ var roundMatchUps = result.matchUps, roundResult = __rest(result, ["matchUps"]);
36092
+ roundResults.push(__assign(__assign({}, roundResult), { iteration: iteration, matchUpsCount: roundMatchUps === null || roundMatchUps === void 0 ? void 0 : roundMatchUps.length }));
36093
+ roundNumber = ((_g = roundResult === null || roundResult === void 0 ? void 0 : roundResult.roundNumber) !== null && _g !== void 0 ? _g : 1) + 1;
36094
+ if (roundMatchUps === null || roundMatchUps === void 0 ? void 0 : roundMatchUps.length) {
36095
+ matchUps.push.apply(matchUps, __spreadArray([], __read(roundMatchUps), false));
36096
+ }
36097
+ }
36094
36098
  }
36095
- // if no structureId is specified find the latest AD_HOC stage which has matchUps
36096
- if (!structureId) {
36097
- var targetStructure = (_h = (_g = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) === null || _g === void 0 ? void 0 : _g.filter(function (structure) { return structure.stageSequence === 1; })) === null || _h === void 0 ? void 0 : _h.reduce(function (targetStructure, structure) {
36098
- var orderNumber = structure.stage && stageOrder$1[structure.stage];
36099
- var structureIsAdHoc = isAdHoc({ drawDefinition: drawDefinition, structure: structure });
36100
- return structureIsAdHoc && orderNumber > (stageOrder$1[targetStructure === null || targetStructure === void 0 ? void 0 : targetStructure.stage] || 1)
36101
- ? structure
36102
- : targetStructure;
36103
- }, undefined);
36104
- structureId = targetStructure === null || targetStructure === void 0 ? void 0 : targetStructure.structureId;
36099
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
36100
+ finally {
36101
+ try {
36102
+ if (_j && !_j.done && (_a = _h.return)) _a.call(_h);
36103
+ }
36104
+ finally { if (e_1) throw e_1.error; }
36105
36105
  }
36106
- var structure = (_j = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) === null || _j === void 0 ? void 0 : _j.find(function (structure) { return structure.structureId === structureId; });
36107
- if (!structure)
36108
- return { error: STRUCTURE_NOT_FOUND };
36109
- // an AD_HOC structure is one that has no child structures and in which no matchUps have roundPosition
36110
- var structureIsAdHoc = isAdHoc({ drawDefinition: drawDefinition, structure: structure });
36111
- if (!structureIsAdHoc)
36112
- return { error: INVALID_DRAW_DEFINITION };
36113
- var tournamentParticipants = (_k = tournamentRecord.participants) !== null && _k !== void 0 ? _k : [];
36106
+ return __assign(__assign({}, SUCCESS), { matchUps: matchUps, roundResults: roundResults });
36107
+ }
36108
+ function getScaleValue(_a) {
36109
+ var _b;
36110
+ var _c = _a.scaleType, scaleType = _c === void 0 ? RATING$1 : _c, scaleAccessor = _a.scaleAccessor, participant = _a.participant, scaleName = _a.scaleName, eventType = _a.eventType;
36111
+ var scaleAttributes = {
36112
+ eventType: eventType !== null && eventType !== void 0 ? eventType : SINGLES_EVENT,
36113
+ scaleType: scaleType,
36114
+ scaleName: scaleName,
36115
+ };
36116
+ var result = participant &&
36117
+ participantScaleItem({
36118
+ scaleAttributes: scaleAttributes,
36119
+ participant: participant,
36120
+ });
36121
+ var scaleValue = (_b = result === null || result === void 0 ? void 0 : result.scaleItem) === null || _b === void 0 ? void 0 : _b.scaleValue;
36122
+ return scaleAccessor && isObject(scaleValue) ? scaleValue[scaleAccessor] : scaleValue;
36123
+ }
36124
+ function getAdHocRatings(params) {
36125
+ var e_2, _a;
36126
+ var _b;
36127
+ var tournamentRecord = params.tournamentRecord, participantIds = params.participantIds, scaleAccessor = params.scaleAccessor, scaleName = params.scaleName, eventType = params.eventType, _c = params.adHocRatings, adHocRatings = _c === void 0 ? {} : _c;
36128
+ var tournamentParticipants = (_b = tournamentRecord.participants) !== null && _b !== void 0 ? _b : [];
36114
36129
  var _loop_1 = function (participantId) {
36115
36130
  var participant = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.find(function (participant) { return participant.participantId === participantId; });
36116
36131
  // first see if there is already a dynamic value
@@ -36133,79 +36148,130 @@ function drawMatic(params) {
36133
36148
  adHocRatings[participantId] = scaleValue;
36134
36149
  };
36135
36150
  try {
36136
- for (var _o = __values(participantIds !== null && participantIds !== void 0 ? participantIds : []), _p = _o.next(); !_p.done; _p = _o.next()) {
36137
- var participantId = _p.value;
36151
+ for (var _d = __values(participantIds !== null && participantIds !== void 0 ? participantIds : []), _e = _d.next(); !_e.done; _e = _d.next()) {
36152
+ var participantId = _e.value;
36138
36153
  _loop_1(participantId);
36139
36154
  }
36140
36155
  }
36141
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
36156
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
36142
36157
  finally {
36143
36158
  try {
36144
- if (_p && !_p.done && (_a = _o.return)) _a.call(_o);
36159
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
36145
36160
  }
36146
- finally { if (e_1) throw e_1.error; }
36161
+ finally { if (e_2) throw e_2.error; }
36147
36162
  }
36148
- // TODO: update dynamic ratings based on matchUps present from last played round
36149
- // use scaleEngine.generateDynamicRatings(); see dynamicCalculations.test.ts
36150
- var matchUps = [];
36151
- var roundResults = [];
36152
- var roundNumber;
36153
- try {
36154
- for (var _q = __values(generateRange(1, (roundsCount !== null && roundsCount !== void 0 ? roundsCount : 1) + 1)), _r = _q.next(); !_r.done; _r = _q.next()) {
36155
- var iteration = _r.value;
36156
- var result = generateDrawMaticRound({
36157
- ignoreLastRoundNumber: true,
36158
- tournamentParticipants: tournamentParticipants,
36159
- generateMatchUps: generateMatchUps,
36160
- participantIds: participantIds,
36161
- encounterValue: encounterValue,
36162
- sameTeamValue: sameTeamValue,
36163
+ return adHocRatings;
36164
+ }
36165
+ function getStructure(params) {
36166
+ var _a, _b, _c;
36167
+ if (params.structureId)
36168
+ return params.structureId;
36169
+ var drawDefinition = params.drawDefinition;
36170
+ // if no structureId is specified find the latest AD_HOC stage which has matchUps
36171
+ var targetStructure = (_b = (_a = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) === null || _a === void 0 ? void 0 : _a.filter(function (structure) { return structure.stageSequence === 1; })) === null || _b === void 0 ? void 0 : _b.reduce(function (targetStructure, structure) {
36172
+ var orderNumber = structure.stage && stageOrder$1[structure.stage];
36173
+ var structureIsAdHoc = isAdHoc({ drawDefinition: drawDefinition, structure: structure });
36174
+ return structureIsAdHoc && orderNumber > (stageOrder$1[targetStructure === null || targetStructure === void 0 ? void 0 : targetStructure.stage] || 1) ? structure : targetStructure;
36175
+ }, undefined);
36176
+ var structure = (_c = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) === null || _c === void 0 ? void 0 : _c.find(function (structure) { return structure.structureId === (targetStructure === null || targetStructure === void 0 ? void 0 : targetStructure.structureId); });
36177
+ if (!structure)
36178
+ return { error: STRUCTURE_NOT_FOUND };
36179
+ // an AD_HOC structure is one that has no child structures and in which no matchUps have roundPosition
36180
+ var structureIsAdHoc = isAdHoc({ drawDefinition: drawDefinition, structure: structure });
36181
+ if (!structureIsAdHoc)
36182
+ return { error: INVALID_DRAW_DEFINITION };
36183
+ return { structure: structure };
36184
+ }
36185
+ function getParticipantIds(params) {
36186
+ var _a, _b, _c;
36187
+ var participantIds = params.participantIds;
36188
+ var enteredParticipantIds = (_c = (_b = (_a = params.drawDefinition) === null || _a === void 0 ? void 0 : _a.entries) === null || _b === void 0 ? void 0 : _b.filter(function (entry) {
36189
+ var entryStatus = entry.entryStatus;
36190
+ return !params.restrictEntryStatus || STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
36191
+ }).map(getParticipantId)) !== null && _c !== void 0 ? _c : [];
36192
+ if (participantIds) {
36193
+ // ensure all participantIds are in drawDefinition.entries
36194
+ var invalidParticipantIds = participantIds.filter(function (participantId) { return !(enteredParticipantIds === null || enteredParticipantIds === void 0 ? void 0 : enteredParticipantIds.includes(participantId)); });
36195
+ if (invalidParticipantIds === null || invalidParticipantIds === void 0 ? void 0 : invalidParticipantIds.length)
36196
+ return decorateResult({
36197
+ result: { error: INVALID_PARTICIPANT_ID },
36198
+ info: { invalidParticipantIds: invalidParticipantIds },
36199
+ });
36200
+ }
36201
+ else {
36202
+ participantIds = enteredParticipantIds;
36203
+ }
36204
+ if (params.roundsCount &&
36205
+ params.roundsCount > participantIds.length - 1 &&
36206
+ (!params.enableDoubleRobin || params.roundsCount > (participantIds.length - 1) * 2)) {
36207
+ return { error: INVALID_VALUES, info: 'Not enough participants for roundsCount' };
36208
+ }
36209
+ return { participantIds: participantIds };
36210
+ }
36211
+ function checkParams(params) {
36212
+ var _a;
36213
+ if (params.roundsCount && typeof params.roundsCount !== 'number') {
36214
+ return { error: INVALID_VALUES, info: 'roundsCount must be a number' };
36215
+ }
36216
+ if (typeof params.drawDefinition !== 'object' ||
36217
+ (params.drawDefinition.drawType && params.drawDefinition.drawType !== AD_HOC)) {
36218
+ return { error: INVALID_DRAW_DEFINITION };
36219
+ }
36220
+ if (!Array.isArray((_a = params.drawDefinition) === null || _a === void 0 ? void 0 : _a.entries) &&
36221
+ params.participantIds &&
36222
+ !Array.isArray(params.participantIds)) {
36223
+ return { error: INVALID_VALUES, info: 'Missing Entries' };
36224
+ }
36225
+ return { error: undefined };
36226
+ }
36227
+
36228
+ function generateAdHoc(params) {
36229
+ var _a;
36230
+ var tournamentRecord = params.tournamentRecord, drawDefinition = params.drawDefinition, structureId = params.structureId, idPrefix = params.idPrefix, isMock = params.isMock, event = params.event;
36231
+ var entries = (_a = event === null || event === void 0 ? void 0 : event.entries) === null || _a === void 0 ? void 0 : _a.filter(function (_a) {
36232
+ var entryStage = _a.entryStage, entryStatus = _a.entryStatus;
36233
+ return (!entryStage || entryStage === MAIN) && entryStatus && STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
36234
+ });
36235
+ var participantIds = entries === null || entries === void 0 ? void 0 : entries.map(getParticipantId);
36236
+ var matchUpsCount = entries ? Math.floor(entries.length / 2) : 0;
36237
+ if (params.automated) {
36238
+ automateAdHoc(__assign(__assign({}, params), { participantIds: participantIds }));
36239
+ }
36240
+ else {
36241
+ generateRange(1, params.roundsCount + 1).forEach(function () {
36242
+ var matchUps = generateAdHocMatchUps({
36243
+ newRound: true,
36163
36244
  drawDefinition: drawDefinition,
36164
- maxIterations: maxIterations,
36165
- adHocRatings: adHocRatings,
36166
- roundNumber: roundNumber,
36167
- matchUpIds: matchUpIds,
36168
- structure: structure,
36169
- eventType: eventType,
36245
+ matchUpsCount: matchUpsCount,
36170
36246
  idPrefix: idPrefix,
36171
- salted: salted,
36172
36247
  isMock: isMock,
36173
36248
  event: event,
36174
- });
36175
- if (result.error)
36176
- return result;
36177
- var roundMatchUps = result.matchUps, roundResult = __rest(result, ["matchUps"]);
36178
- roundResults.push(__assign(__assign({}, roundResult), { iteration: iteration, matchUpsCount: roundMatchUps === null || roundMatchUps === void 0 ? void 0 : roundMatchUps.length }));
36179
- roundNumber = ((_l = roundResult === null || roundResult === void 0 ? void 0 : roundResult.roundNumber) !== null && _l !== void 0 ? _l : 1) + 1;
36180
- if (roundMatchUps === null || roundMatchUps === void 0 ? void 0 : roundMatchUps.length) {
36181
- matchUps.push.apply(matchUps, __spreadArray([], __read(roundMatchUps), false));
36182
- }
36183
- }
36184
- }
36185
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
36186
- finally {
36187
- try {
36188
- if (_r && !_r.done && (_b = _q.return)) _b.call(_q);
36189
- }
36190
- finally { if (e_2) throw e_2.error; }
36249
+ }).matchUps;
36250
+ (matchUps === null || matchUps === void 0 ? void 0 : matchUps.length) &&
36251
+ addAdHocMatchUps({
36252
+ suppressNotifications: true,
36253
+ tournamentRecord: tournamentRecord,
36254
+ drawDefinition: drawDefinition,
36255
+ structureId: structureId,
36256
+ matchUps: matchUps,
36257
+ event: event,
36258
+ });
36259
+ });
36191
36260
  }
36192
- return __assign(__assign({}, SUCCESS), { matchUps: matchUps, roundResults: roundResults });
36193
36261
  }
36194
- function getScaleValue(_a) {
36195
- var _b;
36196
- var _c = _a.scaleType, scaleType = _c === void 0 ? RATING$1 : _c, scaleAccessor = _a.scaleAccessor, participant = _a.participant, scaleName = _a.scaleName, eventType = _a.eventType;
36197
- var scaleAttributes = {
36198
- eventType: eventType !== null && eventType !== void 0 ? eventType : SINGLES_EVENT,
36199
- scaleType: scaleType,
36200
- scaleName: scaleName,
36201
- };
36202
- var result = participant &&
36203
- participantScaleItem({
36204
- scaleAttributes: scaleAttributes,
36205
- participant: participant,
36262
+ function automateAdHoc(params) {
36263
+ var _a, _b, _c, _d;
36264
+ var _e = (_a = params.drawMatic) !== null && _a !== void 0 ? _a : {}, restrictEntryStatus = _e.restrictEntryStatus, generateMatchUps = _e.generateMatchUps, structureId = _e.structureId, matchUpIds = _e.matchUpIds, scaleName = _e.scaleName;
36265
+ var result = drawMatic(__assign(__assign({}, params), { eventType: (_c = (_b = params.drawMatic) === null || _b === void 0 ? void 0 : _b.eventType) !== null && _c !== void 0 ? _c : params.matchUpType, generateMatchUps: generateMatchUps !== null && generateMatchUps !== void 0 ? generateMatchUps : true, participantIds: params.participantIds, roundsCount: params.roundsCount, restrictEntryStatus: restrictEntryStatus, structureId: structureId, matchUpIds: matchUpIds, scaleName: scaleName }));
36266
+ ((_d = result === null || result === void 0 ? void 0 : result.matchUps) === null || _d === void 0 ? void 0 : _d.length) &&
36267
+ addAdHocMatchUps({
36268
+ tournamentRecord: params.tournamentRecord,
36269
+ drawDefinition: params.drawDefinition,
36270
+ suppressNotifications: true,
36271
+ matchUps: result.matchUps,
36272
+ event: params.event,
36273
+ structureId: structureId,
36206
36274
  });
36207
- var scaleValue = (_b = result === null || result === void 0 ? void 0 : result.scaleItem) === null || _b === void 0 ? void 0 : _b.scaleValue;
36208
- return scaleAccessor && isObject(scaleValue) ? scaleValue[scaleAccessor] : scaleValue;
36209
36275
  }
36210
36276
 
36211
36277
  function initializeStructureSeedAssignments(_a) {
@@ -36254,41 +36320,15 @@ function initializeStructureSeedAssignments(_a) {
36254
36320
  }
36255
36321
 
36256
36322
  function prepareStage(params) {
36257
- var _a;
36258
36323
  var stack = 'prepareStage';
36259
- var seedsCount = params.seedsCount;
36260
- var preparedStructureIds = params.preparedStructureIds || [];
36261
- var provisionalPositioning = params.provisionalPositioning, inContextDrawMatchUps = params.inContextDrawMatchUps, tournamentRecord = params.tournamentRecord, appliedPolicies = params.appliedPolicies, qualifyingOnly = params.qualifyingOnly, drawDefinition = params.drawDefinition, seedingProfile = params.seedingProfile, matchUpsMap = params.matchUpsMap, automated = params.automated, placeByes = params.placeByes, drawType = params.drawType, drawSize = params.drawSize, entries = params.entries, event = params.event, _b = params.enforcePolicyLimits, enforcePolicyLimits = _b === void 0 ? true : _b, seedAssignmentProfile = params.seedAssignmentProfile, // mainly used by mocksEngine for scenario testing
36262
- _c = params.seedByRanking, // mainly used by mocksEngine for scenario testing
36263
- seedByRanking = _c === void 0 ? true : _c, seededParticipants = params.seededParticipants, assignSeedsCount = params.assignSeedsCount, // used for testing bye placement next to seeds
36264
- seedingScaleName = params.seedingScaleName, _d = params.stageSequence, stageSequence = _d === void 0 ? 1 : _d, roundTarget = params.roundTarget, stage = params.stage;
36265
- var eventType = event === null || event === void 0 ? void 0 : event.eventType;
36266
- var stageEntries = entries.filter(function (entry) {
36267
- var _a, _b;
36268
- var entryRoundTarget = (_b = (_a = findExtension({
36269
- name: ROUND_TARGET,
36270
- element: entry,
36271
- })) === null || _a === void 0 ? void 0 : _a.extension) === null || _b === void 0 ? void 0 : _b.value;
36272
- return ((!entry.entryStage || entry.entryStage === stage) &&
36273
- (!stageSequence ||
36274
- !entry.entryStageSequence ||
36275
- entry.entryStageSequence === stageSequence) &&
36276
- (!roundTarget || !entryRoundTarget || entryRoundTarget === roundTarget) &&
36277
- DIRECT_ENTRY_STATUSES.includes(entry.entryStatus));
36278
- });
36279
- if (seededParticipants)
36280
- seedsCount = seededParticipants.length;
36281
- if (seedsCount > drawSize)
36282
- seedsCount = drawSize;
36283
- if (seedsCount > stageEntries.length)
36284
- seedsCount = stageEntries.length;
36324
+ var drawDefinition = params.drawDefinition;
36285
36325
  var structures = getDrawStructures({
36326
+ stageSequence: params.stageSequence || 1,
36327
+ roundTarget: params.roundTarget,
36328
+ stage: params.stage,
36286
36329
  drawDefinition: drawDefinition,
36287
- stageSequence: stageSequence,
36288
- roundTarget: roundTarget,
36289
- stage: stage,
36290
36330
  }).structures;
36291
- var multipleStructures = ((structures === null || structures === void 0 ? void 0 : structures.length) || 0) > 1;
36331
+ var preparedStructureIds = params.preparedStructureIds || [];
36292
36332
  var structure = structures === null || structures === void 0 ? void 0 : structures.find(function (_a) {
36293
36333
  var structureId = _a.structureId;
36294
36334
  return !preparedStructureIds.includes(structureId);
@@ -36296,6 +36336,54 @@ function prepareStage(params) {
36296
36336
  if (!structure)
36297
36337
  return decorateResult({ result: { error: STRUCTURE_NOT_FOUND }, stack: stack });
36298
36338
  var structureId = structure === null || structure === void 0 ? void 0 : structure.structureId;
36339
+ var _a = getSeedsCountAndStageEntries(__assign(__assign({}, params), { structureId: structureId })), seedsCount = _a.seedsCount, stageEntries = _a.stageEntries, seedLimit = _a.seedLimit;
36340
+ if (params.seededParticipants || params.event || params.seedingScaleName) {
36341
+ seeding(__assign(__assign({}, params), { seedsCount: seedsCount, structure: structure, structureId: structureId }));
36342
+ }
36343
+ var doPositioning = params.automated !== false && params.drawType !== AD_HOC && !(params.qualifyingOnly && params.stage !== QUALIFYING);
36344
+ var multipleStructures = ((structures === null || structures === void 0 ? void 0 : structures.length) || 0) > 1;
36345
+ var positioningResult = doPositioning ? positioning(__assign(__assign({}, params), { multipleStructures: multipleStructures, seedLimit: seedLimit, structureId: structureId })) : {};
36346
+ if (positioningResult === null || positioningResult === void 0 ? void 0 : positioningResult.error)
36347
+ return decorateResult({ result: positioningResult, stack: stack });
36348
+ return __assign(__assign({}, positioningResult), { stageEntries: stageEntries, structureId: structureId, seedsCount: seedsCount });
36349
+ }
36350
+ function getStageEntries(_a) {
36351
+ var entries = _a.entries, stage = _a.stage, stageSequence = _a.stageSequence, roundTarget = _a.roundTarget;
36352
+ return entries.filter(function (entry) {
36353
+ var _a, _b;
36354
+ var entryRoundTarget = (_b = (_a = findExtension({
36355
+ name: ROUND_TARGET,
36356
+ element: entry,
36357
+ })) === null || _a === void 0 ? void 0 : _a.extension) === null || _b === void 0 ? void 0 : _b.value;
36358
+ return ((!entry.entryStage || entry.entryStage === stage) &&
36359
+ (!stageSequence || !entry.entryStageSequence || entry.entryStageSequence === stageSequence) &&
36360
+ (!roundTarget || !entryRoundTarget || entryRoundTarget === roundTarget) &&
36361
+ DIRECT_ENTRY_STATUSES.includes(entry.entryStatus));
36362
+ });
36363
+ }
36364
+ function positioning(params) {
36365
+ var seedsOnly = typeof params.automated === 'object' && params.automated.seedsOnly;
36366
+ // if { seedsOnly: true } then only seeds and an Byes releated to seeded positions are placed
36367
+ var result = automatedPositioning(__assign(__assign({}, params), { seedsOnly: seedsOnly }));
36368
+ if (result.error)
36369
+ return result;
36370
+ var positionAssignments = result === null || result === void 0 ? void 0 : result.positionAssignments;
36371
+ var positioningReport = result === null || result === void 0 ? void 0 : result.positioningReport;
36372
+ return { conflicts: result.conflicts, positionAssignments: positionAssignments, positioningReport: positioningReport };
36373
+ }
36374
+ function seeding(params) {
36375
+ var seededParticipants = params.seededParticipants, seedingScaleName = params.seedingScaleName, entries = params.entries, event = params.event;
36376
+ var enteredParticipantIds = entries.map(getParticipantId);
36377
+ if (seededParticipants) {
36378
+ processSeededParticipants(__assign(__assign({}, params), { enteredParticipantIds: enteredParticipantIds }));
36379
+ }
36380
+ else if (event || seedingScaleName) {
36381
+ // if no seededParticipants have been defined, seed by seeding scale or ranking scale, if present
36382
+ scaledEntriesSeeding(__assign(__assign({}, params), { enteredParticipantIds: enteredParticipantIds }));
36383
+ }
36384
+ }
36385
+ function processSeededParticipants(params) {
36386
+ var provisionalPositioning = params.provisionalPositioning, enteredParticipantIds = params.enteredParticipantIds, seededParticipants = params.seededParticipants, tournamentRecord = params.tournamentRecord, appliedPolicies = params.appliedPolicies, drawDefinition = params.drawDefinition, seedingProfile = params.seedingProfile, structureId = params.structureId, structure = params.structure, event = params.event;
36299
36387
  var seedBlockInfo = structure
36300
36388
  ? getValidSeedBlocks({
36301
36389
  provisionalPositioning: provisionalPositioning,
@@ -36305,145 +36393,660 @@ function prepareStage(params) {
36305
36393
  structure: structure,
36306
36394
  })
36307
36395
  : undefined;
36396
+ seededParticipants
36397
+ .filter(function (_a) {
36398
+ var participantId = _a.participantId;
36399
+ return enteredParticipantIds.includes(participantId);
36400
+ })
36401
+ .filter(function (seededParticipant) { return !seededParticipant.seedNumber || seededParticipant.seedNumber <= seededParticipants.length; })
36402
+ .sort(function (a, b) {
36403
+ if (a.seedNumber < b.seedNumber)
36404
+ return -1;
36405
+ if (a.seedNumber < b.seedNumber)
36406
+ return 1;
36407
+ return 0;
36408
+ })
36409
+ .forEach(function (seededParticipant) {
36410
+ var participantId = seededParticipant.participantId, seedNumber = seededParticipant.seedNumber, seedValue = seededParticipant.seedValue;
36411
+ assignSeed({
36412
+ provisionalPositioning: provisionalPositioning,
36413
+ tournamentRecord: tournamentRecord,
36414
+ drawDefinition: drawDefinition,
36415
+ seedingProfile: seedingProfile,
36416
+ participantId: participantId,
36417
+ seedBlockInfo: seedBlockInfo,
36418
+ structureId: structureId,
36419
+ seedNumber: seedNumber,
36420
+ seedValue: seedValue,
36421
+ event: event,
36422
+ });
36423
+ });
36424
+ }
36425
+ function scaledEntriesSeeding(params) {
36426
+ var _a;
36427
+ var seedsCount = params.seedsCount;
36428
+ var provisionalPositioning = params.provisionalPositioning, enteredParticipantIds = params.enteredParticipantIds, seedAssignmentProfile = params.seedAssignmentProfile, // mainly used by mocksEngine for scenario testing
36429
+ assignSeedsCount = params.assignSeedsCount, // used for testing bye placement next to seeds
36430
+ tournamentRecord = params.tournamentRecord, drawDefinition = params.drawDefinition, seedByRanking = params.seedByRanking, seedingProfile = params.seedingProfile, structureId = params.structureId, event = params.event;
36431
+ var _b = (event === null || event === void 0 ? void 0 : event.category) || {}, categoryName = _b.categoryName, ageCategoryCode = _b.ageCategoryCode;
36432
+ var eventType = event === null || event === void 0 ? void 0 : event.eventType;
36433
+ var scaledEntries = getSeedingScaleEntries(__assign(__assign({}, params), { ageCategoryCode: ageCategoryCode, categoryName: categoryName, eventType: eventType })) ||
36434
+ (seedByRanking && getRankingScaleEntries(__assign(__assign({}, params), { ageCategoryCode: ageCategoryCode, categoryName: categoryName, eventType: eventType })));
36435
+ var scaledEntriesCount = (_a = scaledEntries === null || scaledEntries === void 0 ? void 0 : scaledEntries.length) !== null && _a !== void 0 ? _a : 0;
36436
+ if (scaledEntriesCount < seedsCount)
36437
+ seedsCount = scaledEntriesCount;
36438
+ scaledEntries === null || scaledEntries === void 0 ? void 0 : scaledEntries.filter(function (_a) {
36439
+ var participantId = _a.participantId;
36440
+ return enteredParticipantIds.includes(participantId);
36441
+ }).slice(0, assignSeedsCount || seedsCount).forEach(function (scaledEntry, index) {
36442
+ var seedNumber = index + 1;
36443
+ var participantId = scaledEntry.participantId, scaleValue = scaledEntry.scaleValue;
36444
+ var seedValue = (seedAssignmentProfile === null || seedAssignmentProfile === void 0 ? void 0 : seedAssignmentProfile[seedNumber]) || scaleValue || seedNumber;
36445
+ assignSeed({
36446
+ provisionalPositioning: provisionalPositioning,
36447
+ tournamentRecord: tournamentRecord,
36448
+ drawDefinition: drawDefinition,
36449
+ seedingProfile: seedingProfile,
36450
+ participantId: participantId,
36451
+ structureId: structureId,
36452
+ seedNumber: seedNumber,
36453
+ seedValue: seedValue,
36454
+ event: event,
36455
+ });
36456
+ });
36457
+ }
36458
+ function getSeedingScaleEntries(params) {
36459
+ var tournamentRecord = params.tournamentRecord, seedingScaleName = params.seedingScaleName, stageSequence = params.stageSequence, entries = params.entries, stage = params.stage, event = params.event;
36460
+ var _a = (event === null || event === void 0 ? void 0 : event.category) || {}, categoryName = _a.categoryName, ageCategoryCode = _a.ageCategoryCode;
36461
+ var eventType = event === null || event === void 0 ? void 0 : event.eventType;
36462
+ var seedingScaleAttributes = {
36463
+ scaleName: seedingScaleName || categoryName || ageCategoryCode || event.eventId,
36464
+ scaleType: SEEDING$1,
36465
+ eventType: eventType,
36466
+ };
36467
+ return getScaledEntries({
36468
+ scaleAttributes: seedingScaleAttributes,
36469
+ tournamentRecord: tournamentRecord,
36470
+ stageSequence: stageSequence,
36471
+ entries: entries,
36472
+ stage: stage,
36473
+ }).scaledEntries;
36474
+ }
36475
+ function getRankingScaleEntries(params) {
36476
+ var tournamentRecord = params.tournamentRecord, stageSequence = params.stageSequence, event = params.event, entries = params.entries, stage = params.stage;
36477
+ var _a = (event === null || event === void 0 ? void 0 : event.category) || {}, categoryName = _a.categoryName, ageCategoryCode = _a.ageCategoryCode;
36478
+ var eventType = event === null || event === void 0 ? void 0 : event.eventType;
36479
+ var rankingScaleAttributes = {
36480
+ scaleName: categoryName || ageCategoryCode,
36481
+ scaleType: RANKING$1,
36482
+ eventType: eventType,
36483
+ };
36484
+ return getScaledEntries({
36485
+ scaleAttributes: rankingScaleAttributes,
36486
+ tournamentRecord: tournamentRecord,
36487
+ stageSequence: stageSequence,
36488
+ entries: entries,
36489
+ stage: stage,
36490
+ }).scaledEntries;
36491
+ }
36492
+ function getSeedsCountAndStageEntries(params) {
36493
+ var _a;
36494
+ var seedsCount = params.seedsCount;
36495
+ if (params.seededParticipants)
36496
+ seedsCount = params.seededParticipants.length;
36497
+ if (seedsCount > params.drawSize)
36498
+ seedsCount = params.drawSize;
36499
+ var stageEntries = getStageEntries(params);
36500
+ if (seedsCount > stageEntries.length)
36501
+ seedsCount = stageEntries.length;
36308
36502
  var seedLimit = initializeStructureSeedAssignments({
36503
+ enforcePolicyLimits: (_a = params.enforcePolicyLimits) !== null && _a !== void 0 ? _a : true,
36504
+ appliedPolicies: params.appliedPolicies,
36309
36505
  participantsCount: stageEntries.length,
36310
- enforcePolicyLimits: enforcePolicyLimits,
36311
- appliedPolicies: appliedPolicies,
36312
- drawDefinition: drawDefinition,
36313
- seedingProfile: seedingProfile,
36314
- structureId: structureId,
36506
+ seedingProfile: params.seedingProfile,
36507
+ drawDefinition: params.drawDefinition,
36508
+ structureId: params.structureId,
36315
36509
  seedsCount: seedsCount,
36316
36510
  }).seedLimit;
36317
36511
  if (seedLimit && seedLimit < seedsCount)
36318
36512
  seedsCount = seedLimit;
36319
- var enteredParticipantIds = entries.map(getParticipantId);
36320
- if (seededParticipants) {
36321
- seededParticipants
36322
- .filter(function (_a) {
36323
- var participantId = _a.participantId;
36324
- return enteredParticipantIds.includes(participantId);
36325
- })
36326
- .filter(function (seededParticipant) {
36327
- return !seededParticipant.seedNumber ||
36328
- seededParticipant.seedNumber <= seededParticipants.length;
36329
- })
36330
- .sort(function (a, b) {
36331
- if (a.seedNumber < b.seedNumber)
36332
- return -1;
36333
- if (a.seedNumber < b.seedNumber)
36334
- return 1;
36335
- return 0;
36336
- })
36337
- .forEach(function (seededParticipant) {
36338
- var participantId = seededParticipant.participantId, seedNumber = seededParticipant.seedNumber, seedValue = seededParticipant.seedValue;
36339
- assignSeed({
36340
- provisionalPositioning: provisionalPositioning,
36341
- tournamentRecord: tournamentRecord,
36342
- drawDefinition: drawDefinition,
36343
- seedingProfile: seedingProfile,
36344
- participantId: participantId,
36345
- seedBlockInfo: seedBlockInfo,
36346
- structureId: structureId,
36347
- seedNumber: seedNumber,
36348
- seedValue: seedValue,
36349
- event: event,
36350
- });
36351
- });
36513
+ return { seedsCount: seedsCount, stageEntries: stageEntries, seedLimit: seedLimit };
36514
+ }
36515
+
36516
+ function generateNewDrawDefinition(params) {
36517
+ var _a;
36518
+ var _b, _c;
36519
+ var drawTypeResult = generateDrawTypeAndModifyDrawDefinition(__assign(__assign({}, params), { modifyOriginal: false }));
36520
+ if (drawTypeResult.error)
36521
+ return drawTypeResult;
36522
+ var drawDefinition = drawTypeResult.drawDefinition;
36523
+ var ignoreStageSpace = params.ignoreStageSpace, appliedPolicies = params.appliedPolicies, qualifyingOnly = params.qualifyingOnly, seedingProfile = params.seedingProfile, participants = params.participants, drawEntries = params.drawEntries, placeByes = params.placeByes, drawSize = params.drawSize, drawType = params.drawType, entries = params.entries;
36524
+ var positioningReports = [];
36525
+ var conflicts = [];
36526
+ var addResult = addEntries({ ignoreStageSpace: ignoreStageSpace, drawDefinition: drawDefinition, drawEntries: drawEntries, drawType: drawType, entries: entries });
36527
+ if (addResult.error)
36528
+ return addResult;
36529
+ // temporary until seeding is supported in LUCKY_DRAW
36530
+ var seedsCount = drawType === LUCKY_DRAW ? 0 : ensureInt((_b = params.seedsCount) !== null && _b !== void 0 ? _b : 0);
36531
+ var structureResult = prepareStage(__assign(__assign({}, params), { qualifyingOnly: !drawSize || qualifyingOnly, // ooo!! If there is no drawSize then MAIN is not being generated
36532
+ appliedPolicies: appliedPolicies, drawDefinition: drawDefinition, seedingProfile: seedingProfile, participants: participants, stage: MAIN, seedsCount: seedsCount, placeByes: placeByes, drawSize: drawSize, entries: entries }));
36533
+ if (structureResult.error && !structureResult.conflicts)
36534
+ return structureResult;
36535
+ if ((_c = structureResult.positioningReport) === null || _c === void 0 ? void 0 : _c.length)
36536
+ positioningReports.push((_a = {}, _a[MAIN] = structureResult.positioningReport, _a));
36537
+ var structureId = structureResult.structureId;
36538
+ if (structureResult.conflicts)
36539
+ conflicts = structureResult.conflicts;
36540
+ if (drawType === AD_HOC && params.roundsCount) {
36541
+ generateAdHoc(__assign(__assign({}, params), { drawDefinition: drawDefinition, structureId: structureId }));
36352
36542
  }
36353
- else if (event || seedingScaleName) {
36354
- // if no seededParticipants have been defined, seed by seeding scale or ranking scale, if present
36355
- var _e = (event === null || event === void 0 ? void 0 : event.category) || {}, categoryName = _e.categoryName, ageCategoryCode = _e.ageCategoryCode;
36356
- var seedingScaleAttributes = {
36357
- scaleType: SEEDING$1,
36358
- scaleName: seedingScaleName || categoryName || ageCategoryCode || event.eventId,
36359
- eventType: eventType,
36360
- };
36361
- var scaledEntries = getScaledEntries({
36362
- scaleAttributes: seedingScaleAttributes,
36363
- tournamentRecord: tournamentRecord,
36364
- stageSequence: stageSequence,
36365
- entries: entries,
36366
- stage: stage,
36367
- }).scaledEntries;
36368
- if (!(scaledEntries === null || scaledEntries === void 0 ? void 0 : scaledEntries.length) && seedByRanking) {
36369
- var rankingScaleAttributes = {
36370
- scaleName: categoryName || ageCategoryCode,
36371
- scaleType: RANKING$1,
36372
- eventType: eventType,
36543
+ return { drawDefinition: drawDefinition, positioningReports: positioningReports, conflicts: conflicts, structureId: structureId };
36544
+ }
36545
+ function addEntries(params) {
36546
+ var e_1, _a;
36547
+ var _b;
36548
+ var ignoreStageSpace = params.ignoreStageSpace, drawDefinition = params.drawDefinition, drawEntries = params.drawEntries, drawType = params.drawType, entries = params.entries;
36549
+ try {
36550
+ // add all entries to the draw
36551
+ for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
36552
+ var entry = entries_1_1.value;
36553
+ // if drawEntries and entryStage !== stage ignore
36554
+ if (drawEntries && entry.entryStage && entry.entryStage !== MAIN)
36555
+ continue;
36556
+ var entryData = __assign(__assign({}, entry), { ignoreStageSpace: ignoreStageSpace !== null && ignoreStageSpace !== void 0 ? ignoreStageSpace : drawType === AD_HOC, entryStage: (_b = entry.entryStage) !== null && _b !== void 0 ? _b : MAIN, drawDefinition: drawDefinition, drawType: drawType });
36557
+ var result = addDrawEntry(entryData);
36558
+ if (drawEntries && result.error) {
36559
+ // only report errors with drawEntries
36560
+ // if entries are taken from event.entries assume stageSpace is not available
36561
+ return result;
36562
+ }
36563
+ }
36564
+ }
36565
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
36566
+ finally {
36567
+ try {
36568
+ if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1);
36569
+ }
36570
+ finally { if (e_1) throw e_1.error; }
36571
+ }
36572
+ return { error: undefined };
36573
+ }
36574
+
36575
+ // internal use only; set matchUpFormat for a matchUp or structure
36576
+ function setMatchUpMatchUpFormat(params) {
36577
+ var e_1, _a;
36578
+ var structureIds = params.structureIds;
36579
+ var tournamentRecord = params.tournamentRecord, drawDefinition = params.drawDefinition, matchUpFormat = params.matchUpFormat, structureId = params.structureId, matchUpId = params.matchUpId, event = params.event;
36580
+ if (!drawDefinition)
36581
+ return { error: MISSING_DRAW_DEFINITION };
36582
+ if (!matchUpFormat)
36583
+ return { error: MISSING_MATCHUP_FORMAT };
36584
+ if (!isValidMatchUpFormat({ matchUpFormat: matchUpFormat }))
36585
+ return { error: UNRECOGNIZED_MATCHUP_FORMAT };
36586
+ var stack = 'setMatchUpFormat';
36587
+ if (matchUpId) {
36588
+ var result = findDrawMatchUp({
36589
+ drawDefinition: drawDefinition,
36590
+ matchUpId: matchUpId,
36591
+ event: event,
36592
+ });
36593
+ if (result.error)
36594
+ return result;
36595
+ if (!result.matchUp)
36596
+ return { error: MATCHUP_NOT_FOUND };
36597
+ var matchUp = result.matchUp;
36598
+ if ((matchUp === null || matchUp === void 0 ? void 0 : matchUp.matchUpType) === TEAM$2)
36599
+ return {
36600
+ error: INVALID_MATCHUP,
36601
+ info: 'Cannot set matchUpFormat when { matchUpType: TEAM }',
36373
36602
  };
36374
- (scaledEntries = getScaledEntries({
36375
- scaleAttributes: rankingScaleAttributes,
36376
- tournamentRecord: tournamentRecord,
36377
- stageSequence: stageSequence,
36378
- entries: entries,
36379
- stage: stage,
36380
- }).scaledEntries);
36603
+ matchUp.matchUpFormat = matchUpFormat;
36604
+ modifyMatchUpNotice({
36605
+ tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
36606
+ eventId: event === null || event === void 0 ? void 0 : event.eventId,
36607
+ context: stack,
36608
+ drawDefinition: drawDefinition,
36609
+ matchUp: matchUp,
36610
+ });
36611
+ }
36612
+ else if (Array.isArray(structureIds)) {
36613
+ if ((event === null || event === void 0 ? void 0 : event.eventType) === TEAM$2)
36614
+ return { error: INVALID_EVENT_TYPE };
36615
+ try {
36616
+ for (var structureIds_1 = __values(structureIds), structureIds_1_1 = structureIds_1.next(); !structureIds_1_1.done; structureIds_1_1 = structureIds_1.next()) {
36617
+ var structureId_1 = structureIds_1_1.value;
36618
+ var result = findStructure({ drawDefinition: drawDefinition, structureId: structureId_1 });
36619
+ if (result.error)
36620
+ return result;
36621
+ if (!result.structure) {
36622
+ return { error: STRUCTURE_NOT_FOUND };
36623
+ }
36624
+ else {
36625
+ result.structure.matchUpFormat = matchUpFormat;
36626
+ }
36627
+ }
36381
36628
  }
36382
- var scaledEntriesCount = (_a = scaledEntries === null || scaledEntries === void 0 ? void 0 : scaledEntries.length) !== null && _a !== void 0 ? _a : 0;
36383
- if (scaledEntriesCount < seedsCount)
36384
- seedsCount = scaledEntriesCount;
36385
- scaledEntries === null || scaledEntries === void 0 ? void 0 : scaledEntries.filter(function (_a) {
36386
- var participantId = _a.participantId;
36387
- return enteredParticipantIds.includes(participantId);
36388
- }).slice(0, assignSeedsCount || seedsCount).forEach(function (scaledEntry, index) {
36389
- var seedNumber = index + 1;
36390
- var participantId = scaledEntry.participantId, scaleValue = scaledEntry.scaleValue;
36391
- var seedValue = (seedAssignmentProfile === null || seedAssignmentProfile === void 0 ? void 0 : seedAssignmentProfile[seedNumber]) || scaleValue || seedNumber;
36392
- assignSeed({
36393
- provisionalPositioning: provisionalPositioning,
36394
- tournamentRecord: tournamentRecord,
36395
- drawDefinition: drawDefinition,
36396
- seedingProfile: seedingProfile,
36397
- participantId: participantId,
36398
- structureId: structureId,
36399
- seedNumber: seedNumber,
36400
- seedValue: seedValue,
36401
- event: event,
36402
- });
36629
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
36630
+ finally {
36631
+ try {
36632
+ if (structureIds_1_1 && !structureIds_1_1.done && (_a = structureIds_1.return)) _a.call(structureIds_1);
36633
+ }
36634
+ finally { if (e_1) throw e_1.error; }
36635
+ }
36636
+ }
36637
+ else if (structureId) {
36638
+ if ((event === null || event === void 0 ? void 0 : event.eventType) === TEAM$2)
36639
+ return { error: INVALID_EVENT_TYPE };
36640
+ var result = findStructure({ drawDefinition: drawDefinition, structureId: structureId });
36641
+ if (result.error)
36642
+ return result;
36643
+ if (!result.structure) {
36644
+ return { error: STRUCTURE_NOT_FOUND };
36645
+ }
36646
+ else {
36647
+ result.structure.matchUpFormat = matchUpFormat;
36648
+ }
36649
+ }
36650
+ else if (drawDefinition) {
36651
+ drawDefinition.matchUpFormat = matchUpFormat;
36652
+ }
36653
+ structureIds = structureIds !== null && structureIds !== void 0 ? structureIds : (structureId ? [structureId] : undefined);
36654
+ modifyDrawNotice({ drawDefinition: drawDefinition, structureIds: structureIds });
36655
+ return __assign({}, SUCCESS);
36656
+ }
36657
+
36658
+ // add collectionIds if missing
36659
+ function checkTieFormat(_a) {
36660
+ var e_1, _b;
36661
+ var tieFormat = _a.tieFormat;
36662
+ var result = validateTieFormat({
36663
+ checkCollectionIds: false,
36664
+ tieFormat: tieFormat,
36665
+ });
36666
+ if (result.error)
36667
+ return result;
36668
+ try {
36669
+ for (var _c = __values(tieFormat.collectionDefinitions), _d = _c.next(); !_d.done; _d = _c.next()) {
36670
+ var collectionDefinition = _d.value;
36671
+ if (!collectionDefinition.collectionId)
36672
+ collectionDefinition.collectionId = UUID();
36673
+ }
36674
+ }
36675
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
36676
+ finally {
36677
+ try {
36678
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
36679
+ }
36680
+ finally { if (e_1) throw e_1.error; }
36681
+ }
36682
+ return { tieFormat: tieFormat };
36683
+ }
36684
+
36685
+ function checkFormatScopeEquivalence(_a) {
36686
+ var _b;
36687
+ var tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, matchUpFormat = _a.matchUpFormat, matchUpType = _a.matchUpType, tieFormat = _a.tieFormat, event = _a.event;
36688
+ // if there is a defined matchUpFormat/tieFormat only attach to drawDefinition...
36689
+ // ...when there is not an equivalent definition on the parent event
36690
+ if (matchUpFormat || tieFormat) {
36691
+ var equivalentInScope = (matchUpFormat && (event === null || event === void 0 ? void 0 : event.matchUpFormat) === matchUpFormat) ||
36692
+ ((event === null || event === void 0 ? void 0 : event.tieFormat) && tieFormat && JSON.stringify(event.tieFormat) === JSON.stringify(tieFormat));
36693
+ // if an equivalent matchUpFormat or tieFormat is attached to the event
36694
+ // there is no need to attach to the drawDefinition
36695
+ if (!equivalentInScope) {
36696
+ if (tieFormat) {
36697
+ var result = checkTieFormat({ tieFormat: tieFormat });
36698
+ if (result.error)
36699
+ return result;
36700
+ drawDefinition.tieFormat = (_b = result.tieFormat) !== null && _b !== void 0 ? _b : tieFormat;
36701
+ }
36702
+ else if (matchUpFormat) {
36703
+ var result = setMatchUpMatchUpFormat({
36704
+ tournamentRecord: tournamentRecord,
36705
+ drawDefinition: drawDefinition,
36706
+ matchUpFormat: matchUpFormat,
36707
+ event: event,
36708
+ });
36709
+ if (result.error) {
36710
+ return {
36711
+ info: 'matchUpFormat or tieFormat error',
36712
+ error: result.error,
36713
+ };
36714
+ }
36715
+ }
36716
+ if (matchUpType)
36717
+ drawDefinition.matchUpType = matchUpType;
36718
+ }
36719
+ }
36720
+ return { error: undefined };
36721
+ }
36722
+
36723
+ function removePolicy(params) {
36724
+ var _a, _b, e_1, _c;
36725
+ var _d, _e;
36726
+ var checkParams = checkRequiredParameters(params, [
36727
+ (_a = {},
36728
+ _a[POLICY_TYPE] = true,
36729
+ _a._anyOf = (_b = {},
36730
+ _b[TOURNAMENT_RECORDS] = false,
36731
+ _b[TOURNAMENT_RECORD] = false,
36732
+ _b[DRAW_DEFINITION] = false,
36733
+ _b[EVENT] = false,
36734
+ _b),
36735
+ _a),
36736
+ ]);
36737
+ if (checkParams.error)
36738
+ return checkParams;
36739
+ var policyRemoved;
36740
+ var element = (_e = (_d = params.drawDefinition) !== null && _d !== void 0 ? _d : params.event) !== null && _e !== void 0 ? _e : ((params.tournamentId || !params.tournamentRecords) && params.tournamentRecord);
36741
+ if (element) {
36742
+ return policyDeletion(params, element);
36743
+ }
36744
+ else if (params.tournamentRecords) {
36745
+ var tournamentIds = Object.keys(params.tournamentRecords);
36746
+ if (!tournamentIds.length)
36747
+ return { error: MISSING_TOURNAMENT_RECORD };
36748
+ try {
36749
+ for (var tournamentIds_1 = __values(tournamentIds), tournamentIds_1_1 = tournamentIds_1.next(); !tournamentIds_1_1.done; tournamentIds_1_1 = tournamentIds_1.next()) {
36750
+ var tournamentId = tournamentIds_1_1.value;
36751
+ var tournamentRecord = params.tournamentRecords[tournamentId];
36752
+ var result = policyDeletion(params, tournamentRecord);
36753
+ if (result.error)
36754
+ return result;
36755
+ policyRemoved = true;
36756
+ }
36757
+ }
36758
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
36759
+ finally {
36760
+ try {
36761
+ if (tournamentIds_1_1 && !tournamentIds_1_1.done && (_c = tournamentIds_1.return)) _c.call(tournamentIds_1);
36762
+ }
36763
+ finally { if (e_1) throw e_1.error; }
36764
+ }
36765
+ }
36766
+ else {
36767
+ return { error: MISSING_TOURNAMENT_RECORD };
36768
+ }
36769
+ return policyRemoved ? __assign({}, SUCCESS) : { error: POLICY_NOT_FOUND };
36770
+ }
36771
+ function policyDeletion(params, element) {
36772
+ var _a;
36773
+ var appliedPolicies = (_a = getAppliedPolicies(params).appliedPolicies) !== null && _a !== void 0 ? _a : {};
36774
+ if (appliedPolicies[params.policyType]) {
36775
+ delete appliedPolicies[params.policyType];
36776
+ if (Object.keys(appliedPolicies).length) {
36777
+ var extension = { name: APPLIED_POLICIES, value: appliedPolicies };
36778
+ addExtension({ element: element, extension: extension });
36779
+ }
36780
+ else {
36781
+ removeExtension({ element: element, name: APPLIED_POLICIES });
36782
+ }
36783
+ return __assign({}, SUCCESS);
36784
+ }
36785
+ return { error: POLICY_NOT_FOUND };
36786
+ }
36787
+
36788
+ var mutate$a = {
36789
+ __proto__: null,
36790
+ attachPolicies: attachPolicies,
36791
+ removePolicy: removePolicy
36792
+ };
36793
+
36794
+ var query$1 = {
36795
+ __proto__: null,
36796
+ findPolicy: findPolicy,
36797
+ getAppliedPolicies: getAppliedPolicies,
36798
+ getPolicyDefinitions: getPolicyDefinitions
36799
+ };
36800
+
36801
+ var index$e = {
36802
+ __proto__: null,
36803
+ attachPolicies: attachPolicies,
36804
+ findPolicy: findPolicy,
36805
+ getAppliedPolicies: getAppliedPolicies,
36806
+ getPolicyDefinitions: getPolicyDefinitions,
36807
+ mutate: mutate$a,
36808
+ query: query$1,
36809
+ removePolicy: removePolicy
36810
+ };
36811
+
36812
+ function policyAttachment(_a) {
36813
+ // ---------------------------------------------------------------------------
36814
+ // Attach policies to the drawDefinition
36815
+ // if there is an avoidance policy on the event, it must be preserved in the drawDefinition
36816
+ // if there is an avoidance policy in policyDefinitions, it will override
36817
+ // avoidance policies on the event can be changed (if location used for UI)
36818
+ var _b;
36819
+ var appliedPolicies = _a.appliedPolicies, policyDefinitions = _a.policyDefinitions, drawDefinition = _a.drawDefinition, stack = _a.stack;
36820
+ if (policyDefinitions && typeof policyDefinitions !== 'object')
36821
+ return decorateResult({
36822
+ info: 'policyDefinitions must be an object',
36823
+ result: { error: INVALID_VALUES },
36824
+ stack: stack,
36403
36825
  });
36826
+ var policiesToAttach = (_b = {},
36827
+ _b[POLICY_TYPE_AVOIDANCE] = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_AVOIDANCE],
36828
+ _b);
36829
+ if (policyDefinitions) {
36830
+ existingPolicyDefinitions({ policyDefinitions: policyDefinitions, appliedPolicies: appliedPolicies, policiesToAttach: policiesToAttach, drawDefinition: drawDefinition });
36404
36831
  }
36405
- var conflicts = [];
36406
- var positionAssignments;
36407
- var positioningReport;
36408
- if (automated !== false &&
36409
- drawType !== AD_HOC &&
36410
- !(qualifyingOnly && stage !== QUALIFYING)) {
36411
- var seedsOnly = typeof automated === 'object' && automated.seedsOnly;
36412
- // if { seedsOnly: true } then only seeds and an Byes releated to seeded positions are placed
36413
- var result = automatedPositioning({
36414
- inContextDrawMatchUps: inContextDrawMatchUps,
36415
- multipleStructures: multipleStructures,
36416
- tournamentRecord: tournamentRecord,
36417
- appliedPolicies: appliedPolicies,
36832
+ else if (policiesToAttach.avoidance) {
36833
+ attachPolicies({ drawDefinition: drawDefinition, policyDefinitions: policiesToAttach });
36834
+ }
36835
+ if (!(appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_SEEDING]) && !(policyDefinitions === null || policyDefinitions === void 0 ? void 0 : policyDefinitions[POLICY_TYPE_SEEDING])) {
36836
+ attachPolicies({
36837
+ policyDefinitions: POLICY_SEEDING_DEFAULT,
36418
36838
  drawDefinition: drawDefinition,
36419
- seedingProfile: seedingProfile,
36420
- structureId: structureId,
36421
- matchUpsMap: matchUpsMap,
36422
- placeByes: placeByes,
36423
- seedLimit: seedLimit,
36424
- seedsOnly: seedsOnly,
36425
- drawSize: drawSize,
36426
- drawType: drawType,
36427
- event: event,
36428
36839
  });
36429
- if (result.conflicts)
36430
- conflicts = result === null || result === void 0 ? void 0 : result.conflicts;
36431
- positionAssignments = result === null || result === void 0 ? void 0 : result.positionAssignments;
36432
- positioningReport = result === null || result === void 0 ? void 0 : result.positioningReport;
36433
- if (result.error) {
36434
- return decorateResult({ result: result, stack: stack });
36840
+ if (appliedPolicies)
36841
+ Object.assign(appliedPolicies, POLICY_SEEDING_DEFAULT);
36842
+ }
36843
+ return { error: undefined };
36844
+ }
36845
+ function existingPolicyDefinitions(_a) {
36846
+ var e_1, _b;
36847
+ var policyDefinitions = _a.policyDefinitions, appliedPolicies = _a.appliedPolicies, policiesToAttach = _a.policiesToAttach, drawDefinition = _a.drawDefinition;
36848
+ try {
36849
+ for (var _c = __values(Object.keys(policyDefinitions)), _d = _c.next(); !_d.done; _d = _c.next()) {
36850
+ var key = _d.value;
36851
+ if (JSON.stringify(appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[key]) !== JSON.stringify(policyDefinitions[key])) {
36852
+ policiesToAttach[key] = policyDefinitions[key];
36853
+ }
36435
36854
  }
36436
36855
  }
36856
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
36857
+ finally {
36858
+ try {
36859
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
36860
+ }
36861
+ finally { if (e_1) throw e_1.error; }
36862
+ }
36863
+ if (Object.keys(policiesToAttach).length) {
36864
+ // attach any policyDefinitions which have been provided and are not already present
36865
+ attachPolicies({
36866
+ policyDefinitions: policiesToAttach,
36867
+ drawDefinition: drawDefinition,
36868
+ });
36869
+ if (appliedPolicies)
36870
+ Object.assign(appliedPolicies, policiesToAttach);
36871
+ }
36872
+ }
36873
+
36874
+ var definitionTemplate = function () { return ({
36875
+ matchUpType: undefined,
36876
+ drawName: undefined,
36877
+ drawId: undefined,
36878
+ structures: [],
36879
+ entries: [],
36880
+ links: [],
36881
+ }); };
36882
+
36883
+ function newDrawDefinition(params) {
36884
+ var _a = params !== null && params !== void 0 ? params : {}, _b = _a.drawId, drawId = _b === void 0 ? UUID() : _b, processCodes = _a.processCodes, matchUpType = _a.matchUpType, drawType = _a.drawType;
36885
+ var drawDefinition = definitionTemplate();
36886
+ return Object.assign(drawDefinition, {
36887
+ processCodes: processCodes,
36888
+ matchUpType: matchUpType,
36889
+ drawType: drawType,
36890
+ drawId: drawId,
36891
+ });
36892
+ }
36893
+
36894
+ function setUpDrawGeneration(params) {
36895
+ var _a, _b, _c, _d, _e;
36896
+ var tournamentRecord = params.tournamentRecord, matchUpFormat = params.matchUpFormat, appliedPolicies = params.appliedPolicies, policyDefinitions = params.policyDefinitions, matchUpType = params.matchUpType, tieFormat = params.tieFormat, drawType = params.drawType, stack = params.stack, event = params.event;
36897
+ var existingDrawDefinition = params.drawId
36898
+ ? (_a = event === null || event === void 0 ? void 0 : event.drawDefinitions) === null || _a === void 0 ? void 0 : _a.find(function (d) { return d.drawId === params.drawId; })
36899
+ : undefined;
36900
+ if (existingDrawDefinition && drawType !== existingDrawDefinition.drawType)
36901
+ existingDrawDefinition.drawType = drawType;
36902
+ var drawDefinition = existingDrawDefinition !== null && existingDrawDefinition !== void 0 ? existingDrawDefinition : newDrawDefinition({
36903
+ processCodes: params.processCodes,
36904
+ drawId: params.drawId,
36905
+ drawType: drawType,
36906
+ });
36907
+ var equivalenceResult = checkFormatScopeEquivalence({
36908
+ tournamentRecord: tournamentRecord,
36909
+ drawDefinition: drawDefinition,
36910
+ matchUpFormat: matchUpFormat,
36911
+ matchUpType: matchUpType,
36912
+ tieFormat: tieFormat,
36913
+ event: event,
36914
+ });
36915
+ if (equivalenceResult.error)
36916
+ return decorateResult({ result: equivalenceResult, stack: stack });
36917
+ var attachmentResult = policyAttachment({ appliedPolicies: appliedPolicies, policyDefinitions: policyDefinitions, drawDefinition: drawDefinition, stack: stack });
36918
+ if (attachmentResult.error)
36919
+ return attachmentResult;
36920
+ // find existing MAIN structureId if existingDrawDefinition
36921
+ var structureId = (_c = (_b = existingDrawDefinition === null || existingDrawDefinition === void 0 ? void 0 : existingDrawDefinition.structures) === null || _b === void 0 ? void 0 : _b.find(function (structure) { return structure.stage === MAIN && structure.stageSequence === 1; })) === null || _c === void 0 ? void 0 : _c.structureId;
36922
+ var existingQualifyingStructures = existingDrawDefinition
36923
+ ? (_d = existingDrawDefinition.structures) === null || _d === void 0 ? void 0 : _d.filter(function (structure) { return structure.stage === QUALIFYING; })
36924
+ : [];
36925
+ var existingQualifyingPlaceholderStructureId = (existingQualifyingStructures === null || existingQualifyingStructures === void 0 ? void 0 : existingQualifyingStructures.length) === 1 &&
36926
+ !((_e = existingQualifyingStructures[0].matchUps) === null || _e === void 0 ? void 0 : _e.length) &&
36927
+ existingQualifyingStructures[0].structureId;
36928
+ return { drawDefinition: drawDefinition, structureId: structureId, existingDrawDefinition: existingDrawDefinition, existingQualifyingPlaceholderStructureId: existingQualifyingPlaceholderStructureId };
36929
+ }
36930
+
36931
+ function generateOrGetExisting(params) {
36932
+ var _a, _b, _c, _d, _e, _f, _g;
36933
+ var stack = 'generateOrGetExisting';
36934
+ var positioningReports = [];
36935
+ var conflicts = [];
36936
+ var setUpResult = setUpDrawGeneration(params);
36937
+ if (setUpResult.error)
36938
+ return decorateResult({ result: setUpResult, stack: stack });
36939
+ var existingDrawDefinition = setUpResult.existingDrawDefinition;
36940
+ var drawDefinition = (_a = setUpResult.drawDefinition) !== null && _a !== void 0 ? _a : {};
36941
+ var structureId = setUpResult.structureId;
36942
+ var entries = (_c = (_b = params.drawEntries) !== null && _b !== void 0 ? _b : params.eventEntries) !== null && _c !== void 0 ? _c : [];
36943
+ var genResult = (setUpResult.existingQualifyingPlaceholderStructureId &&
36944
+ processExistingDrawDefinition(__assign(__assign({}, params), setUpResult))) ||
36945
+ generateNewDrawDefinition(__assign(__assign(__assign({}, params), setUpResult), { entries: entries }));
36946
+ if (genResult.error)
36947
+ return decorateResult({ result: genResult, stack: stack });
36948
+ if ((_d = genResult.positioningReports) === null || _d === void 0 ? void 0 : _d.length)
36949
+ positioningReports.push.apply(positioningReports, __spreadArray([], __read(((_e = genResult.positioningReports) !== null && _e !== void 0 ? _e : [])), false));
36950
+ if ((_f = genResult.conflicts) === null || _f === void 0 ? void 0 : _f.length)
36951
+ conflicts.push.apply(conflicts, __spreadArray([], __read(((_g = genResult.conflicts) !== null && _g !== void 0 ? _g : [])), false));
36952
+ drawDefinition = genResult.drawDefinition;
36953
+ structureId = genResult.structureId;
36437
36954
  return {
36438
- positionAssignments: positionAssignments,
36439
- positioningReport: positioningReport,
36440
- stageEntries: stageEntries,
36955
+ existingDrawDefinition: existingDrawDefinition,
36956
+ positioningReports: positioningReports,
36957
+ drawDefinition: drawDefinition,
36441
36958
  structureId: structureId,
36442
- seedsCount: seedsCount,
36443
36959
  conflicts: conflicts,
36960
+ entries: entries,
36444
36961
  };
36445
36962
  }
36446
36963
 
36964
+ function qualifyingGeneration(params) {
36965
+ var e_1, _a, e_2, _b, _c;
36966
+ var _d, _e, _f, _g;
36967
+ var qualifyingPlaceholder = params.qualifyingPlaceholder, qualifyingProfiles = params.qualifyingProfiles, existingDrawDefinition = params.existingDrawDefinition, positioningReports = params.positioningReports, appliedPolicies = params.appliedPolicies, qualifyingOnly = params.qualifyingOnly, drawDefinition = params.drawDefinition, seedingProfile = params.seedingProfile, participants = params.participants, structureId = params.structureId, entries = params.entries, stack = params.stack;
36968
+ // generate qualifying structures
36969
+ var generateQualifyingPlaceholder = qualifyingPlaceholder && !(qualifyingProfiles === null || qualifyingProfiles === void 0 ? void 0 : qualifyingProfiles.length) && !existingDrawDefinition;
36970
+ var qualifyingConflicts = [];
36971
+ if (qualifyingProfiles) {
36972
+ var sequenceSort = function (a, b) { return a.stageSequence - b.stageSequence; };
36973
+ var roundTargetSort = function (a, b) { return a.roundTarget - b.roundTarget; };
36974
+ // keep track of structures already prepared in case of multiple matching structures
36975
+ var preparedStructureIds = [];
36976
+ var roundTarget = 1;
36977
+ qualifyingProfiles.sort(roundTargetSort);
36978
+ try {
36979
+ for (var qualifyingProfiles_1 = __values(qualifyingProfiles), qualifyingProfiles_1_1 = qualifyingProfiles_1.next(); !qualifyingProfiles_1_1.done; qualifyingProfiles_1_1 = qualifyingProfiles_1.next()) {
36980
+ var roundTargetProfile = qualifyingProfiles_1_1.value;
36981
+ if (!Array.isArray(roundTargetProfile.structureProfiles))
36982
+ return decorateResult({
36983
+ info: mustBeAnArray('structureProfiles'),
36984
+ result: { error: MISSING_VALUE },
36985
+ stack: stack,
36986
+ });
36987
+ roundTarget = roundTargetProfile.roundTarget || roundTarget;
36988
+ var sortedStructureProfiles = ((_d = roundTargetProfile.structureProfiles) === null || _d === void 0 ? void 0 : _d.sort(sequenceSort)) || [];
36989
+ var sequence = 1;
36990
+ try {
36991
+ for (var sortedStructureProfiles_1 = (e_2 = void 0, __values(sortedStructureProfiles)), sortedStructureProfiles_1_1 = sortedStructureProfiles_1.next(); !sortedStructureProfiles_1_1.done; sortedStructureProfiles_1_1 = sortedStructureProfiles_1.next()) {
36992
+ var structureProfile = sortedStructureProfiles_1_1.value;
36993
+ var qualifyingRoundNumber = structureProfile.qualifyingRoundNumber, qualifyingPositions = structureProfile.qualifyingPositions, seededParticipants = structureProfile.seededParticipants, seedingScaleName = structureProfile.seedingScaleName, _h = structureProfile.seedsCount, seedsCount = _h === void 0 ? 0 : _h, seedByRanking = structureProfile.seedByRanking, placeByes = structureProfile.placeByes, drawSize = structureProfile.drawSize;
36994
+ var qualifyingStageResult = prepareStage(__assign(__assign({}, params), { seedingProfile: (_e = structureProfile.seedingProfile) !== null && _e !== void 0 ? _e : seedingProfile, stageSequence: sequence, qualifyingRoundNumber: qualifyingRoundNumber, preparedStructureIds: preparedStructureIds, qualifyingPositions: qualifyingPositions, seededParticipants: seededParticipants, stage: QUALIFYING, seedingScaleName: seedingScaleName, appliedPolicies: appliedPolicies, drawDefinition: drawDefinition, qualifyingOnly: qualifyingOnly, seedByRanking: seedByRanking, participants: participants, roundTarget: roundTarget, seedsCount: seedsCount, placeByes: placeByes, drawSize: drawSize, entries: entries }));
36995
+ if (qualifyingStageResult.error) {
36996
+ return qualifyingStageResult;
36997
+ }
36998
+ if (qualifyingStageResult.structureId) {
36999
+ preparedStructureIds.push(qualifyingStageResult.structureId);
37000
+ }
37001
+ sequence += 1;
37002
+ if ((_f = qualifyingStageResult.conflicts) === null || _f === void 0 ? void 0 : _f.length)
37003
+ qualifyingConflicts.push.apply(qualifyingConflicts, __spreadArray([], __read(qualifyingStageResult.conflicts), false));
37004
+ if ((_g = qualifyingStageResult.positioningReport) === null || _g === void 0 ? void 0 : _g.length)
37005
+ positioningReports.push((_c = {},
37006
+ _c[QUALIFYING] = qualifyingStageResult.positioningReport,
37007
+ _c));
37008
+ }
37009
+ }
37010
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
37011
+ finally {
37012
+ try {
37013
+ if (sortedStructureProfiles_1_1 && !sortedStructureProfiles_1_1.done && (_b = sortedStructureProfiles_1.return)) _b.call(sortedStructureProfiles_1);
37014
+ }
37015
+ finally { if (e_2) throw e_2.error; }
37016
+ }
37017
+ roundTarget += 1;
37018
+ }
37019
+ }
37020
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
37021
+ finally {
37022
+ try {
37023
+ if (qualifyingProfiles_1_1 && !qualifyingProfiles_1_1.done && (_a = qualifyingProfiles_1.return)) _a.call(qualifyingProfiles_1);
37024
+ }
37025
+ finally { if (e_1) throw e_1.error; }
37026
+ }
37027
+ }
37028
+ else if (structureId && generateQualifyingPlaceholder) {
37029
+ var qualifyingStructure = structureTemplate({
37030
+ structureName: constantToString(QUALIFYING),
37031
+ stage: QUALIFYING,
37032
+ });
37033
+ var link = generateQualifyingLink({
37034
+ sourceStructureId: qualifyingStructure.structureId,
37035
+ targetStructureId: structureId,
37036
+ sourceRoundNumber: 0,
37037
+ linkType: POSITION,
37038
+ }).link;
37039
+ if (!drawDefinition.structures)
37040
+ drawDefinition.structures = [];
37041
+ drawDefinition.structures.push(qualifyingStructure);
37042
+ if (!drawDefinition.links)
37043
+ drawDefinition.links = [];
37044
+ drawDefinition.links.push(link);
37045
+ }
37046
+ // complete qualifying generation
37047
+ return { qualifyingConflicts: qualifyingConflicts, error: undefined };
37048
+ }
37049
+
36447
37050
  function generateScoreString(params) {
36448
37051
  var _a = params.winnerFirst, winnerFirst = _a === void 0 ? true : _a, addOutcomeString = params.addOutcomeString, _b = params.reversed, reversed = _b === void 0 ? false : _b, matchUpStatus = params.matchUpStatus, matchUpFormat = params.matchUpFormat, autoComplete = params.autoComplete, winningSide = params.winningSide, sets = params.sets;
36449
37052
  if (!sets)
@@ -41259,31 +41862,25 @@ function getDrawFormat(params) {
41259
41862
  }
41260
41863
 
41261
41864
  function generateDrawDefinition(params) {
41262
- var _a, e_1, _b, e_2, _c, e_3, _d, e_4, _e, _f, e_5, _g, e_6, _h, _j;
41263
- var _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;
41865
+ var _a, _b, _c, _d, _e;
41866
+ var voluntaryConsolation = params.voluntaryConsolation, tournamentRecord = params.tournamentRecord, event = params.event;
41264
41867
  var stack = 'generateDrawDefinition';
41265
- var voluntaryConsolation = params.voluntaryConsolation, ignoreStageSpace = params.ignoreStageSpace, tournamentRecord = params.tournamentRecord, qualifyingOnly = params.qualifyingOnly, drawEntries = params.drawEntries, placeByes = params.placeByes, event = params.event;
41266
- var isMock = (_k = params.isMock) !== null && _k !== void 0 ? _k : true;
41267
- var idPrefix = params.idPrefix;
41268
41868
  // get participants both for entry validation and for automated placement
41269
41869
  // automated placement requires them to be "inContext" for avoidance policies to work
41270
- var _16 = getParticipants({
41870
+ var _f = getParticipants({
41271
41871
  withIndividualParticipants: true,
41272
41872
  convertExtensions: true,
41273
41873
  internalUse: true,
41274
41874
  tournamentRecord: tournamentRecord,
41275
- }), participants = _16.participants, participantMap = _16.participantMap;
41276
- var eventEntries = (_m = (_l = event === null || event === void 0 ? void 0 : event.entries) === null || _l === void 0 ? void 0 : _l.filter(function (entry) { return entry.entryStatus && __spreadArray(__spreadArray([], __read(STRUCTURE_SELECTED_STATUSES), false), [QUALIFIER], false).includes(entry.entryStatus); })) !== null && _m !== void 0 ? _m : [];
41875
+ }), participants = _f.participants, participantMap = _f.participantMap;
41876
+ var eventEntries = (_b = (_a = event === null || event === void 0 ? void 0 : event.entries) === null || _a === void 0 ? void 0 : _a.filter(function (entry) { return entry.entryStatus && __spreadArray(__spreadArray([], __read(STRUCTURE_SELECTED_STATUSES), false), [QUALIFIER], false).includes(entry.entryStatus); })) !== null && _b !== void 0 ? _b : [];
41277
41877
  var validDerivedResult = validateAndDeriveDrawValues(__assign(__assign({}, params), { // order is important here
41278
41878
  participantMap: participantMap, participants: participants, eventEntries: eventEntries }));
41279
41879
  if (validDerivedResult.error)
41280
41880
  return decorateResult({ result: validDerivedResult, stack: stack });
41281
41881
  var appliedPolicies = validDerivedResult.appliedPolicies, policyDefinitions = validDerivedResult.policyDefinitions, drawSize = validDerivedResult.drawSize, drawType = validDerivedResult.drawType, enforceGender = validDerivedResult.enforceGender, seedingProfile = validDerivedResult.seedingProfile;
41282
41882
  var eventType = event === null || event === void 0 ? void 0 : event.eventType;
41283
- var matchUpType = (_o = params.matchUpType) !== null && _o !== void 0 ? _o : eventType;
41284
- var existingDrawDefinition = params.drawId
41285
- ? (_p = event === null || event === void 0 ? void 0 : event.drawDefinitions) === null || _p === void 0 ? void 0 : _p.find(function (d) { return d.drawId === params.drawId; })
41286
- : undefined;
41883
+ var matchUpType = (_c = params.matchUpType) !== null && _c !== void 0 ? _c : eventType;
41287
41884
  var drawFormatResult = getDrawFormat(__assign(__assign({}, params), { enforceGender: enforceGender, eventType: eventType, matchUpType: matchUpType }));
41288
41885
  if (drawFormatResult.error)
41289
41886
  return decorateResult({ result: drawFormatResult, stack: stack });
@@ -41291,402 +41888,25 @@ function generateDrawDefinition(params) {
41291
41888
  var invalidDrawId = params.drawId && typeof params.drawId !== 'string';
41292
41889
  if (invalidDrawId)
41293
41890
  return decorateResult({ result: { error: INVALID_VALUES }, stack: stack });
41294
- // ---------------------------------------------------------------------------
41295
- // Begin construction of drawDefinition
41296
- if (existingDrawDefinition && drawType !== existingDrawDefinition.drawType)
41297
- existingDrawDefinition.drawType = drawType;
41298
- var drawDefinition = existingDrawDefinition !== null && existingDrawDefinition !== void 0 ? existingDrawDefinition : newDrawDefinition({
41299
- drawType: drawType,
41300
- drawId: params.drawId,
41301
- processCodes: params.processCodes,
41302
- });
41303
- // if there is a defined matchUpFormat/tieFormat only attach to drawDefinition...
41304
- // ...when there is not an equivalent definition on the parent event
41305
- if (matchUpFormat || tieFormat) {
41306
- var equivalentInScope = (matchUpFormat && (event === null || event === void 0 ? void 0 : event.matchUpFormat) === matchUpFormat) ||
41307
- ((event === null || event === void 0 ? void 0 : event.tieFormat) && tieFormat && JSON.stringify(event.tieFormat) === JSON.stringify(tieFormat));
41308
- // if an equivalent matchUpFormat or tieFormat is attached to the event
41309
- // there is no need to attach to the drawDefinition
41310
- if (!equivalentInScope) {
41311
- if (tieFormat) {
41312
- var result = checkTieFormat({ tieFormat: tieFormat });
41313
- if (result.error)
41314
- return decorateResult({ result: result, stack: stack });
41315
- drawDefinition.tieFormat = (_q = result.tieFormat) !== null && _q !== void 0 ? _q : tieFormat;
41316
- }
41317
- else if (matchUpFormat) {
41318
- var result = setMatchUpMatchUpFormat({
41319
- tournamentRecord: tournamentRecord,
41320
- drawDefinition: drawDefinition,
41321
- matchUpFormat: matchUpFormat,
41322
- event: event,
41323
- });
41324
- if (result.error) {
41325
- return {
41326
- error: result.error,
41327
- info: 'matchUpFormat or tieFormat error',
41328
- };
41329
- }
41330
- }
41331
- if (matchUpType)
41332
- drawDefinition.matchUpType = matchUpType;
41333
- }
41334
- }
41335
- // ---------------------------------------------------------------------------
41336
- // Attach policies to the drawDefinition
41337
- // if there is an avoidance policy on the event, it must be preserved in the drawDefinition
41338
- // if there is an avoidance policy in policyDefinitions, it will override
41339
- // avoidance policies on the event can be changed (if location used for UI)
41340
- var policiesToAttach = (_a = {},
41341
- _a[POLICY_TYPE_AVOIDANCE] = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_AVOIDANCE],
41342
- _a);
41343
- if (policyDefinitions) {
41344
- if (typeof policyDefinitions !== 'object') {
41345
- return decorateResult({
41346
- info: 'policyDefinitions must be an object',
41347
- result: { error: INVALID_VALUES },
41348
- stack: stack,
41349
- });
41350
- }
41351
- else {
41352
- try {
41353
- for (var _17 = __values(Object.keys(policyDefinitions)), _18 = _17.next(); !_18.done; _18 = _17.next()) {
41354
- var key = _18.value;
41355
- if (JSON.stringify(appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[key]) !== JSON.stringify(policyDefinitions[key])) {
41356
- policiesToAttach[key] = policyDefinitions[key];
41357
- }
41358
- }
41359
- }
41360
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
41361
- finally {
41362
- try {
41363
- if (_18 && !_18.done && (_b = _17.return)) _b.call(_17);
41364
- }
41365
- finally { if (e_1) throw e_1.error; }
41366
- }
41367
- if (Object.keys(policiesToAttach).length) {
41368
- // attach any policyDefinitions which have been provided and are not already present
41369
- attachPolicies({
41370
- policyDefinitions: policiesToAttach,
41371
- drawDefinition: drawDefinition,
41372
- });
41373
- if (appliedPolicies)
41374
- Object.assign(appliedPolicies, policiesToAttach);
41375
- }
41376
- }
41377
- }
41378
- else if (policiesToAttach.avoidance) {
41379
- attachPolicies({ drawDefinition: drawDefinition, policyDefinitions: policiesToAttach });
41380
- }
41381
- if (!(appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_SEEDING]) && !(policyDefinitions === null || policyDefinitions === void 0 ? void 0 : policyDefinitions[POLICY_TYPE_SEEDING])) {
41382
- attachPolicies({
41383
- policyDefinitions: POLICY_SEEDING_DEFAULT,
41384
- drawDefinition: drawDefinition,
41385
- });
41386
- if (appliedPolicies)
41387
- Object.assign(appliedPolicies, POLICY_SEEDING_DEFAULT);
41388
- }
41389
- // ---------------------------------------------------------------------------
41390
- // find existing MAIN structureId if existingDrawDefinition
41391
- var structureId = (_s = (_r = existingDrawDefinition === null || existingDrawDefinition === void 0 ? void 0 : existingDrawDefinition.structures) === null || _r === void 0 ? void 0 : _r.find(function (structure) { return structure.stage === MAIN && structure.stageSequence === 1; })) === null || _s === void 0 ? void 0 : _s.structureId;
41392
- var entries = drawEntries !== null && drawEntries !== void 0 ? drawEntries : eventEntries;
41393
- var positioningReports = [];
41394
- var drawTypeResult;
41395
- var conflicts = [];
41396
- var generateQualifyingPlaceholder = params.qualifyingPlaceholder && !((_t = params.qualifyingProfiles) === null || _t === void 0 ? void 0 : _t.length) && !existingDrawDefinition;
41397
- var existingQualifyingStructures = existingDrawDefinition
41398
- ? (_u = existingDrawDefinition.structures) === null || _u === void 0 ? void 0 : _u.filter(function (structure) { return structure.stage === QUALIFYING; })
41399
- : [];
41400
- var existingQualifyingPlaceholderStructureId = (existingQualifyingStructures === null || existingQualifyingStructures === void 0 ? void 0 : existingQualifyingStructures.length) === 1 &&
41401
- !((_v = existingQualifyingStructures[0].matchUps) === null || _v === void 0 ? void 0 : _v.length) &&
41402
- existingQualifyingStructures[0].structureId;
41403
- if (existingQualifyingPlaceholderStructureId) {
41404
- var qualifyingProfiles = params.qualifyingProfiles;
41405
- var qualifyingResult = (qualifyingProfiles === null || qualifyingProfiles === void 0 ? void 0 : qualifyingProfiles.length)
41406
- ? generateQualifyingStructures({
41407
- uuids: params.uuids,
41408
- qualifyingProfiles: qualifyingProfiles,
41409
- appliedPolicies: appliedPolicies,
41410
- idPrefix: idPrefix,
41411
- isMock: isMock,
41412
- })
41413
- : undefined;
41414
- if (qualifyingResult === null || qualifyingResult === void 0 ? void 0 : qualifyingResult.error) {
41415
- return qualifyingResult;
41416
- }
41417
- drawDefinition.structures = (_w = drawDefinition.structures) === null || _w === void 0 ? void 0 : _w.filter(function (_a) {
41418
- var structureId = _a.structureId;
41419
- return structureId !== existingQualifyingPlaceholderStructureId;
41420
- });
41421
- drawDefinition.links = (_x = drawDefinition.links) === null || _x === void 0 ? void 0 : _x.filter(function (_a) {
41422
- var source = _a.source;
41423
- return source.structureId !== existingQualifyingPlaceholderStructureId;
41424
- });
41425
- var _19 = qualifyingResult !== null && qualifyingResult !== void 0 ? qualifyingResult : {}, qualifiersCount = _19.qualifiersCount, qualifyingDrawPositionsCount = _19.qualifyingDrawPositionsCount, qualifyingDetails = _19.qualifyingDetails;
41426
- if (qualifyingDrawPositionsCount) {
41427
- if (qualifyingResult === null || qualifyingResult === void 0 ? void 0 : qualifyingResult.structures) {
41428
- (_y = drawDefinition.structures) === null || _y === void 0 ? void 0 : _y.push.apply(_y, __spreadArray([], __read(qualifyingResult.structures), false));
41429
- }
41430
- if (qualifyingResult === null || qualifyingResult === void 0 ? void 0 : qualifyingResult.links) {
41431
- (_z = drawDefinition.links) === null || _z === void 0 ? void 0 : _z.push.apply(_z, __spreadArray([], __read(qualifyingResult.links), false));
41432
- }
41433
- }
41434
- var mainStructure = (_0 = drawDefinition.structures) === null || _0 === void 0 ? void 0 : _0.find(function (_a) {
41435
- var stage = _a.stage, stageSequence = _a.stageSequence;
41436
- return stage === MAIN && stageSequence === 1;
41437
- });
41438
- var existingQualifiersCount = getQualifiersCount({
41439
- stageSequence: 1,
41440
- drawDefinition: drawDefinition,
41441
- structureId: structureId,
41442
- stage: MAIN,
41443
- }).qualifiersCount;
41444
- var derivedQualifiersCount = Math.max(qualifiersCount !== null && qualifiersCount !== void 0 ? qualifiersCount : 0, existingQualifiersCount !== null && existingQualifiersCount !== void 0 ? existingQualifiersCount : 0);
41445
- var result = setStageQualifiersCount({
41446
- qualifiersCount: derivedQualifiersCount,
41447
- drawDefinition: drawDefinition,
41448
- stage: MAIN,
41449
- });
41450
- if (result.error)
41451
- return result;
41452
- result = setStageDrawSize({
41453
- drawSize: qualifyingDrawPositionsCount,
41454
- stage: QUALIFYING,
41455
- drawDefinition: drawDefinition,
41456
- });
41457
- if (result.error)
41458
- return result;
41459
- try {
41460
- for (var _20 = __values((drawEntries !== null && drawEntries !== void 0 ? drawEntries : []).filter(function (_a) {
41461
- var entryStage = _a.entryStage;
41462
- return entryStage === QUALIFYING;
41463
- })), _21 = _20.next(); !_21.done; _21 = _20.next()) {
41464
- var entry = _21.value;
41465
- var entryData = __assign(__assign({}, entry), { entryStage: (_1 = entry.entryStage) !== null && _1 !== void 0 ? _1 : MAIN, drawDefinition: drawDefinition });
41466
- // ignore errors (EXITING_PARTICIPANT)
41467
- addDrawEntry(entryData);
41468
- }
41469
- }
41470
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
41471
- finally {
41472
- try {
41473
- if (_21 && !_21.done && (_c = _20.return)) _c.call(_20);
41474
- }
41475
- finally { if (e_2) throw e_2.error; }
41476
- }
41477
- try {
41478
- for (var _22 = __values(qualifyingDetails || []), _23 = _22.next(); !_23.done; _23 = _22.next()) {
41479
- var qualifyingDetail = _23.value;
41480
- var qualifyingRoundNumber = qualifyingDetail.finalQualifyingRoundNumber, qualifyingStructureId = qualifyingDetail.finalQualifyingStructureId, targetEntryRound = qualifyingDetail.roundTarget, finishingPositions = qualifyingDetail.finishingPositions, linkType = qualifyingDetail.linkType;
41481
- var link = mainStructure &&
41482
- ((_2 = generateQualifyingLink({
41483
- targetStructureId: mainStructure.structureId,
41484
- sourceStructureId: qualifyingStructureId,
41485
- sourceRoundNumber: qualifyingRoundNumber,
41486
- finishingPositions: finishingPositions,
41487
- targetEntryRound: targetEntryRound,
41488
- linkType: linkType,
41489
- })) === null || _2 === void 0 ? void 0 : _2.link);
41490
- if (link === null || link === void 0 ? void 0 : link.error)
41491
- return link;
41492
- if (link) {
41493
- if (!drawDefinition.links)
41494
- drawDefinition.links = [];
41495
- drawDefinition.links.push(link);
41496
- }
41497
- }
41498
- }
41499
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
41500
- finally {
41501
- try {
41502
- if (_23 && !_23.done && (_d = _22.return)) _d.call(_22);
41503
- }
41504
- finally { if (e_3) throw e_3.error; }
41505
- }
41506
- drawTypeResult = { drawDefinition: drawDefinition };
41507
- }
41508
- else {
41509
- drawTypeResult = generateDrawTypeAndModifyDrawDefinition(__assign(__assign({}, params), { modifyOriginal: false, tournamentRecord: tournamentRecord, appliedPolicies: appliedPolicies, drawDefinition: drawDefinition, matchUpFormat: matchUpFormat, matchUpType: matchUpType, tieFormat: tieFormat, drawSize: drawSize, isMock: isMock }));
41510
- if (drawTypeResult.error) {
41511
- return decorateResult({ result: drawTypeResult, stack: stack });
41512
- }
41513
- drawDefinition = drawTypeResult.drawDefinition;
41514
- try {
41515
- // add all entries to the draw
41516
- for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
41517
- var entry = entries_1_1.value;
41518
- // if drawEntries and entryStage !== stage ignore
41519
- if (drawEntries && entry.entryStage && entry.entryStage !== MAIN)
41520
- continue;
41521
- var entryData = __assign(__assign({}, entry), { ignoreStageSpace: ignoreStageSpace !== null && ignoreStageSpace !== void 0 ? ignoreStageSpace : drawType === AD_HOC, entryStage: (_3 = entry.entryStage) !== null && _3 !== void 0 ? _3 : MAIN, drawDefinition: drawDefinition, drawType: drawType });
41522
- var result = addDrawEntry(entryData);
41523
- if (drawEntries && result.error) {
41524
- // only report errors with drawEntries
41525
- // if entries are taken from event.entries assume stageSpace is not available
41526
- return decorateResult({ result: result, stack: stack });
41527
- }
41528
- }
41529
- }
41530
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
41531
- finally {
41532
- try {
41533
- if (entries_1_1 && !entries_1_1.done && (_e = entries_1.return)) _e.call(entries_1);
41534
- }
41535
- finally { if (e_4) throw e_4.error; }
41536
- }
41537
- // temporary until seeding is supported in LUCKY_DRAW
41538
- var seedsCount = drawType === LUCKY_DRAW ? 0 : ensureInt((_4 = params.seedsCount) !== null && _4 !== void 0 ? _4 : 0);
41539
- var structureResult = prepareStage(__assign(__assign(__assign({}, drawTypeResult), params), { qualifyingOnly: !drawSize || qualifyingOnly, // ooo!! If there is no drawSize then MAIN is not being generated
41540
- appliedPolicies: appliedPolicies, drawDefinition: drawDefinition, seedingProfile: seedingProfile, participants: participants, stage: MAIN, seedsCount: seedsCount, placeByes: placeByes, drawSize: drawSize, entries: entries }));
41541
- if (structureResult.error && !structureResult.conflicts) {
41542
- return structureResult;
41543
- }
41544
- if ((_5 = structureResult.positioningReport) === null || _5 === void 0 ? void 0 : _5.length)
41545
- positioningReports.push((_f = {}, _f[MAIN] = structureResult.positioningReport, _f));
41546
- structureId = structureResult.structureId;
41547
- if (structureResult.conflicts)
41548
- conflicts = structureResult.conflicts;
41549
- if (drawType === AD_HOC && params.roundsCount) {
41550
- var entries_2 = (_6 = event === null || event === void 0 ? void 0 : event.entries) === null || _6 === void 0 ? void 0 : _6.filter(function (_a) {
41551
- var entryStage = _a.entryStage, entryStatus = _a.entryStatus;
41552
- return (!entryStage || entryStage === MAIN) && entryStatus && STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
41553
- });
41554
- var participantIds = entries_2 === null || entries_2 === void 0 ? void 0 : entries_2.map(getParticipantId);
41555
- var matchUpsCount_1 = entries_2 ? Math.floor(entries_2.length / 2) : 0;
41556
- if (params.automated) {
41557
- var _24 = (_7 = params.drawMatic) !== null && _7 !== void 0 ? _7 : {}, restrictEntryStatus = _24.restrictEntryStatus, generateMatchUps = _24.generateMatchUps, structureId_1 = _24.structureId, matchUpIds = _24.matchUpIds, scaleName = _24.scaleName;
41558
- var result = drawMatic({
41559
- eventType: (_9 = (_8 = params.drawMatic) === null || _8 === void 0 ? void 0 : _8.eventType) !== null && _9 !== void 0 ? _9 : matchUpType,
41560
- generateMatchUps: generateMatchUps !== null && generateMatchUps !== void 0 ? generateMatchUps : true,
41561
- roundsCount: params.roundsCount,
41562
- restrictEntryStatus: restrictEntryStatus,
41563
- tournamentRecord: tournamentRecord,
41564
- participantIds: participantIds,
41565
- drawDefinition: drawDefinition,
41566
- structureId: structureId_1,
41567
- matchUpIds: matchUpIds,
41568
- scaleName: scaleName, // custom rating name to seed dynamic ratings
41569
- idPrefix: idPrefix,
41570
- isMock: isMock,
41571
- event: event,
41572
- });
41573
- ((_10 = result === null || result === void 0 ? void 0 : result.matchUps) === null || _10 === void 0 ? void 0 : _10.length) &&
41574
- addAdHocMatchUps({
41575
- suppressNotifications: true,
41576
- matchUps: result.matchUps,
41577
- tournamentRecord: tournamentRecord,
41578
- drawDefinition: drawDefinition,
41579
- structureId: structureId_1,
41580
- event: event,
41581
- });
41582
- }
41583
- else {
41584
- generateRange(1, params.roundsCount + 1).forEach(function () {
41585
- var matchUps = generateAdHocMatchUps({
41586
- newRound: true,
41587
- drawDefinition: drawDefinition,
41588
- matchUpsCount: matchUpsCount_1,
41589
- idPrefix: idPrefix,
41590
- isMock: isMock,
41591
- event: event,
41592
- }).matchUps;
41593
- (matchUps === null || matchUps === void 0 ? void 0 : matchUps.length) &&
41594
- addAdHocMatchUps({
41595
- suppressNotifications: true,
41596
- tournamentRecord: tournamentRecord,
41597
- drawDefinition: drawDefinition,
41598
- structureId: structureId,
41599
- matchUps: matchUps,
41600
- event: event,
41601
- });
41602
- });
41603
- }
41604
- }
41605
- }
41606
- var qualifyingConflicts = [];
41607
- if (params.qualifyingProfiles) {
41608
- var sequenceSort = function (a, b) { return a.stageSequence - b.stageSequence; };
41609
- var roundTargetSort = function (a, b) { return a.roundTarget - b.roundTarget; };
41610
- // keep track of structures already prepared in case of multiple matching structures
41611
- var preparedStructureIds = [];
41612
- var roundTarget = 1;
41613
- params.qualifyingProfiles.sort(roundTargetSort);
41614
- try {
41615
- for (var _25 = __values(params.qualifyingProfiles), _26 = _25.next(); !_26.done; _26 = _25.next()) {
41616
- var roundTargetProfile = _26.value;
41617
- if (!Array.isArray(roundTargetProfile.structureProfiles))
41618
- return decorateResult({
41619
- info: mustBeAnArray('structureProfiles'),
41620
- result: { error: MISSING_VALUE },
41621
- stack: stack,
41622
- });
41623
- roundTarget = roundTargetProfile.roundTarget || roundTarget;
41624
- var sortedStructureProfiles = ((_11 = roundTargetProfile.structureProfiles) === null || _11 === void 0 ? void 0 : _11.sort(sequenceSort)) || [];
41625
- var sequence = 1;
41626
- try {
41627
- for (var sortedStructureProfiles_1 = (e_6 = void 0, __values(sortedStructureProfiles)), sortedStructureProfiles_1_1 = sortedStructureProfiles_1.next(); !sortedStructureProfiles_1_1.done; sortedStructureProfiles_1_1 = sortedStructureProfiles_1.next()) {
41628
- var structureProfile = sortedStructureProfiles_1_1.value;
41629
- var qualifyingRoundNumber = structureProfile.qualifyingRoundNumber, qualifyingPositions = structureProfile.qualifyingPositions, seededParticipants = structureProfile.seededParticipants, seedingScaleName = structureProfile.seedingScaleName, _27 = structureProfile.seedsCount, seedsCount = _27 === void 0 ? 0 : _27, seedByRanking = structureProfile.seedByRanking, placeByes_1 = structureProfile.placeByes, drawSize_1 = structureProfile.drawSize;
41630
- var qualifyingStageResult = prepareStage(__assign(__assign(__assign({}, drawTypeResult), params), { seedingProfile: (_12 = structureProfile.seedingProfile) !== null && _12 !== void 0 ? _12 : seedingProfile, stageSequence: sequence, qualifyingRoundNumber: qualifyingRoundNumber, preparedStructureIds: preparedStructureIds, qualifyingPositions: qualifyingPositions, seededParticipants: seededParticipants, stage: QUALIFYING, seedingScaleName: seedingScaleName, appliedPolicies: appliedPolicies, drawDefinition: drawDefinition, qualifyingOnly: qualifyingOnly, seedByRanking: seedByRanking, participants: participants, roundTarget: roundTarget, seedsCount: seedsCount, placeByes: placeByes_1, drawSize: drawSize_1, entries: entries }));
41631
- if (qualifyingStageResult.error) {
41632
- return qualifyingStageResult;
41633
- }
41634
- if (qualifyingStageResult.structureId) {
41635
- preparedStructureIds.push(qualifyingStageResult.structureId);
41636
- }
41637
- sequence += 1;
41638
- if ((_13 = qualifyingStageResult.conflicts) === null || _13 === void 0 ? void 0 : _13.length)
41639
- qualifyingConflicts.push.apply(qualifyingConflicts, __spreadArray([], __read(qualifyingStageResult.conflicts), false));
41640
- if ((_14 = qualifyingStageResult.positioningReport) === null || _14 === void 0 ? void 0 : _14.length)
41641
- positioningReports.push((_j = {},
41642
- _j[QUALIFYING] = qualifyingStageResult.positioningReport,
41643
- _j));
41644
- }
41645
- }
41646
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
41647
- finally {
41648
- try {
41649
- if (sortedStructureProfiles_1_1 && !sortedStructureProfiles_1_1.done && (_h = sortedStructureProfiles_1.return)) _h.call(sortedStructureProfiles_1);
41650
- }
41651
- finally { if (e_6) throw e_6.error; }
41652
- }
41653
- roundTarget += 1;
41654
- }
41655
- }
41656
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
41657
- finally {
41658
- try {
41659
- if (_26 && !_26.done && (_g = _25.return)) _g.call(_25);
41660
- }
41661
- finally { if (e_5) throw e_5.error; }
41662
- }
41663
- }
41664
- else if (structureId && generateQualifyingPlaceholder) {
41665
- var qualifyingStructure = structureTemplate({
41666
- structureName: constantToString(QUALIFYING),
41667
- stage: QUALIFYING,
41668
- });
41669
- var link = generateQualifyingLink({
41670
- sourceStructureId: qualifyingStructure.structureId,
41671
- targetStructureId: structureId,
41672
- sourceRoundNumber: 0,
41673
- linkType: POSITION,
41674
- }).link;
41675
- if (!drawDefinition.structures)
41676
- drawDefinition.structures = [];
41677
- drawDefinition.structures.push(qualifyingStructure);
41678
- if (!drawDefinition.links)
41679
- drawDefinition.links = [];
41680
- drawDefinition.links.push(link);
41681
- }
41682
- drawDefinition.drawName = (_15 = params.drawName) !== null && _15 !== void 0 ? _15 : (drawType && constantToString(drawType));
41891
+ var genResult = generateOrGetExisting(__assign(__assign({}, params), { isMock: (_d = params.isMock) !== null && _d !== void 0 ? _d : true, policyDefinitions: policyDefinitions, tournamentRecord: tournamentRecord, appliedPolicies: appliedPolicies, matchUpFormat: matchUpFormat, seedingProfile: seedingProfile, participants: participants, eventEntries: eventEntries, matchUpType: matchUpType, tieFormat: tieFormat, drawSize: drawSize, drawType: drawType, event: event }));
41892
+ if (genResult.error)
41893
+ return decorateResult({ result: genResult, stack: stack });
41894
+ var existingDrawDefinition = genResult.existingDrawDefinition, positioningReports = genResult.positioningReports, drawDefinition = genResult.drawDefinition, structureId = genResult.structureId, conflicts = genResult.conflicts, entries = genResult.entries;
41895
+ if (!drawDefinition)
41896
+ return decorateResult({ result: { error: INVALID_VALUES }, stack: stack });
41897
+ // generate qualifying structures
41898
+ var qGenResult = qualifyingGeneration(__assign(__assign({}, params), { existingDrawDefinition: existingDrawDefinition, positioningReports: positioningReports, appliedPolicies: appliedPolicies, drawDefinition: drawDefinition, seedingProfile: seedingProfile, participants: participants, structureId: structureId, entries: entries, params: params, stack: stack }));
41899
+ if (qGenResult.error)
41900
+ return qGenResult;
41901
+ var qualifyingConflicts = qGenResult.qualifyingConflicts;
41902
+ drawDefinition.drawName = (_e = params.drawName) !== null && _e !== void 0 ? _e : (drawType && constantToString(drawType));
41683
41903
  if (drawSize && typeof voluntaryConsolation === 'object' && drawSize >= 4) {
41684
41904
  addVoluntaryConsolationStructure(__assign(__assign({}, voluntaryConsolation), { drawDefinition: drawDefinition, matchUpType: matchUpType }));
41685
41905
  }
41686
41906
  return __assign(__assign({ existingDrawDefinition: !!existingDrawDefinition, qualifyingConflicts: qualifyingConflicts, positioningReports: positioningReports, drawDefinition: drawDefinition, structureId: structureId }, SUCCESS), { conflicts: conflicts });
41687
41907
  }
41688
41908
 
41689
- var index$e = {
41909
+ var index$d = {
41690
41910
  __proto__: null,
41691
41911
  addAdHocMatchUps: addAdHocMatchUps,
41692
41912
  addDrawDefinitionTimeItem: addDrawDefinitionTimeItem,
@@ -42399,7 +42619,7 @@ function modifyEventEntries(_a) {
42399
42619
  return __assign({}, SUCCESS);
42400
42620
  }
42401
42621
 
42402
- var mutate$a = {
42622
+ var mutate$9 = {
42403
42623
  __proto__: null,
42404
42624
  addDrawEntries: addDrawEntries,
42405
42625
  addEventEntries: addEventEntries,
@@ -42416,7 +42636,7 @@ var mutate$a = {
42416
42636
  setEntryPositions: setEntryPositions
42417
42637
  };
42418
42638
 
42419
- var index$d = {
42639
+ var index$c = {
42420
42640
  __proto__: null,
42421
42641
  addDrawEntries: addDrawEntries,
42422
42642
  addEventEntries: addEventEntries,
@@ -42427,7 +42647,7 @@ var index$d = {
42427
42647
  getMaxEntryPosition: getMaxEntryPosition,
42428
42648
  modifyEntriesStatus: modifyEntriesStatus,
42429
42649
  modifyEventEntries: modifyEventEntries,
42430
- mutate: mutate$a,
42650
+ mutate: mutate$9,
42431
42651
  promoteAlternate: promoteAlternate,
42432
42652
  promoteAlternates: promoteAlternates,
42433
42653
  query: query$5,
@@ -44577,7 +44797,7 @@ function addEvent(_a) {
44577
44797
  }
44578
44798
  }
44579
44799
 
44580
- var mutate$9 = {
44800
+ var mutate$8 = {
44581
44801
  __proto__: null,
44582
44802
  addDrawDefinition: addDrawDefinition,
44583
44803
  addEvent: addEvent,
@@ -44603,7 +44823,7 @@ var mutate$9 = {
44603
44823
  validateCategory: validateCategory
44604
44824
  };
44605
44825
 
44606
- var index$c = {
44826
+ var index$b = {
44607
44827
  __proto__: null,
44608
44828
  addDrawDefinition: addDrawDefinition,
44609
44829
  addEvent: addEvent,
@@ -44627,7 +44847,7 @@ var index$c = {
44627
44847
  modifyEvent: modifyEvent,
44628
44848
  modifyEventMatchUpFormatTiming: modifyEventMatchUpFormatTiming,
44629
44849
  modifyPairAssignment: modifyPairAssignment,
44630
- mutate: mutate$9,
44850
+ mutate: mutate$8,
44631
44851
  query: query$2,
44632
44852
  refreshEventDrawOrder: refreshEventDrawOrder,
44633
44853
  removeEventMatchUpFormatTiming: removeEventMatchUpFormatTiming,
@@ -45376,7 +45596,7 @@ var garman$1 = {
45376
45596
  garman: garman
45377
45597
  };
45378
45598
 
45379
- var index$b = {
45599
+ var index$a = {
45380
45600
  __proto__: null,
45381
45601
  drawMatic: drawMatic,
45382
45602
  garman: garman$1,
@@ -45395,7 +45615,7 @@ var index$b = {
45395
45615
  roundRobinGroups: roundRobinGroups
45396
45616
  };
45397
45617
 
45398
- var index$a = {
45618
+ var index$9 = {
45399
45619
  __proto__: null,
45400
45620
  isValid: isValidMatchUpFormat,
45401
45621
  isValidMatchUpFormat: isValidMatchUpFormat,
@@ -50534,7 +50754,7 @@ function resetScorecard(params) {
50534
50754
  return __assign({}, SUCCESS);
50535
50755
  }
50536
50756
 
50537
- var mutate$8 = {
50757
+ var mutate$7 = {
50538
50758
  __proto__: null,
50539
50759
  applyLineUps: applyLineUps,
50540
50760
  assignMatchUpSideParticipant: assignMatchUpSideParticipant,
@@ -50561,7 +50781,7 @@ var mutate$8 = {
50561
50781
  updateTieMatchUpScore: updateTieMatchUpScore
50562
50782
  };
50563
50783
 
50564
- var index$9 = {
50784
+ var index$8 = {
50565
50785
  __proto__: null,
50566
50786
  allCompetitionMatchUps: allCompetitionMatchUps,
50567
50787
  allDrawMatchUps: allDrawMatchUps,
@@ -50603,7 +50823,7 @@ var index$9 = {
50603
50823
  getRounds: getRounds,
50604
50824
  isValidMatchUpFormat: isValidMatchUpFormat,
50605
50825
  matchUpActions: matchUpActions,
50606
- mutate: mutate$8,
50826
+ mutate: mutate$7,
50607
50827
  participantScheduledMatchUps: participantScheduledMatchUps,
50608
50828
  query: query$4,
50609
50829
  removeDelegatedOutcome: removeDelegatedOutcome,
@@ -53240,6 +53460,7 @@ var lastNames = [
53240
53460
  "Le Guin",
53241
53461
  "Lem",
53242
53462
  "Lovelace",
53463
+ "Mander",
53243
53464
  "Midgely",
53244
53465
  "Mond",
53245
53466
  "Montoya",
@@ -53386,6 +53607,7 @@ var firstMale = [
53386
53607
  "Ivan",
53387
53608
  "James",
53388
53609
  "Jared",
53610
+ "Jerry",
53389
53611
  "Joe",
53390
53612
  "Johann",
53391
53613
  "Julian",
@@ -57153,7 +57375,7 @@ function modifyTournamentRecord(params) {
57153
57375
  return __assign(__assign({ totalParticipantsCount: totalParticipantsCount, scheduledRounds: scheduledRounds, schedulerResult: schedulerResult }, SUCCESS), { eventIds: eventIds, venueIds: venueIds, drawIds: drawIds });
57154
57376
  }
57155
57377
 
57156
- var mutate$7 = {
57378
+ var mutate$6 = {
57157
57379
  __proto__: null,
57158
57380
  anonymizeTournamentRecord: anonymizeTournamentRecord,
57159
57381
  modifyTournamentRecord: modifyTournamentRecord
@@ -57169,7 +57391,7 @@ var mocksGovernor = {
57169
57391
  generateParticipants: generateParticipants,
57170
57392
  generateTournamentRecord: generateTournamentRecord,
57171
57393
  modifyTournamentRecord: modifyTournamentRecord,
57172
- mutate: mutate$7
57394
+ mutate: mutate$6
57173
57395
  };
57174
57396
 
57175
57397
  // check whether there is a request for the date with overlapping times
@@ -58459,7 +58681,7 @@ function addPersons(_a) {
58459
58681
  return __assign(__assign({}, SUCCESS), { addedCount: addedCount, newPersonIds: newPersonIds });
58460
58682
  }
58461
58683
 
58462
- var mutate$6 = {
58684
+ var mutate$5 = {
58463
58685
  __proto__: null,
58464
58686
  addIndividualParticipantIds: addIndividualParticipantIds,
58465
58687
  addParticipant: addParticipant,
@@ -58489,7 +58711,7 @@ var mutate$6 = {
58489
58711
  setParticipantScaleItems: setParticipantScaleItems
58490
58712
  };
58491
58713
 
58492
- var index$8 = {
58714
+ var index$7 = {
58493
58715
  __proto__: null,
58494
58716
  addIndividualParticipantIds: addIndividualParticipantIds,
58495
58717
  addParticipant: addParticipant,
@@ -58520,7 +58742,7 @@ var index$8 = {
58520
58742
  modifyParticipantsSignInStatus: modifyParticipantsSignInStatus,
58521
58743
  modifyPenalty: modifyPenalty,
58522
58744
  modifyPersonRequests: modifyPersonRequests,
58523
- mutate: mutate$6,
58745
+ mutate: mutate$5,
58524
58746
  participantScaleItem: participantScaleItem,
58525
58747
  query: query$9,
58526
58748
  regenerateParticipantNames: regenerateParticipantNames,
@@ -58534,95 +58756,6 @@ var index$8 = {
58534
58756
  validateLineUp: validateLineUp
58535
58757
  };
58536
58758
 
58537
- function removePolicy(params) {
58538
- var _a, _b, e_1, _c;
58539
- var _d, _e;
58540
- var checkParams = checkRequiredParameters(params, [
58541
- (_a = {},
58542
- _a[POLICY_TYPE] = true,
58543
- _a._anyOf = (_b = {},
58544
- _b[TOURNAMENT_RECORDS] = false,
58545
- _b[TOURNAMENT_RECORD] = false,
58546
- _b[DRAW_DEFINITION] = false,
58547
- _b[EVENT] = false,
58548
- _b),
58549
- _a),
58550
- ]);
58551
- if (checkParams.error)
58552
- return checkParams;
58553
- var policyRemoved;
58554
- var element = (_e = (_d = params.drawDefinition) !== null && _d !== void 0 ? _d : params.event) !== null && _e !== void 0 ? _e : ((params.tournamentId || !params.tournamentRecords) && params.tournamentRecord);
58555
- if (element) {
58556
- return policyDeletion(params, element);
58557
- }
58558
- else if (params.tournamentRecords) {
58559
- var tournamentIds = Object.keys(params.tournamentRecords);
58560
- if (!tournamentIds.length)
58561
- return { error: MISSING_TOURNAMENT_RECORD };
58562
- try {
58563
- for (var tournamentIds_1 = __values(tournamentIds), tournamentIds_1_1 = tournamentIds_1.next(); !tournamentIds_1_1.done; tournamentIds_1_1 = tournamentIds_1.next()) {
58564
- var tournamentId = tournamentIds_1_1.value;
58565
- var tournamentRecord = params.tournamentRecords[tournamentId];
58566
- var result = policyDeletion(params, tournamentRecord);
58567
- if (result.error)
58568
- return result;
58569
- policyRemoved = true;
58570
- }
58571
- }
58572
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
58573
- finally {
58574
- try {
58575
- if (tournamentIds_1_1 && !tournamentIds_1_1.done && (_c = tournamentIds_1.return)) _c.call(tournamentIds_1);
58576
- }
58577
- finally { if (e_1) throw e_1.error; }
58578
- }
58579
- }
58580
- else {
58581
- return { error: MISSING_TOURNAMENT_RECORD };
58582
- }
58583
- return policyRemoved ? __assign({}, SUCCESS) : { error: POLICY_NOT_FOUND };
58584
- }
58585
- function policyDeletion(params, element) {
58586
- var _a;
58587
- var appliedPolicies = (_a = getAppliedPolicies(params).appliedPolicies) !== null && _a !== void 0 ? _a : {};
58588
- if (appliedPolicies[params.policyType]) {
58589
- delete appliedPolicies[params.policyType];
58590
- if (Object.keys(appliedPolicies).length) {
58591
- var extension = { name: APPLIED_POLICIES, value: appliedPolicies };
58592
- addExtension({ element: element, extension: extension });
58593
- }
58594
- else {
58595
- removeExtension({ element: element, name: APPLIED_POLICIES });
58596
- }
58597
- return __assign({}, SUCCESS);
58598
- }
58599
- return { error: POLICY_NOT_FOUND };
58600
- }
58601
-
58602
- var mutate$5 = {
58603
- __proto__: null,
58604
- attachPolicies: attachPolicies,
58605
- removePolicy: removePolicy
58606
- };
58607
-
58608
- var query$1 = {
58609
- __proto__: null,
58610
- findPolicy: findPolicy,
58611
- getAppliedPolicies: getAppliedPolicies,
58612
- getPolicyDefinitions: getPolicyDefinitions
58613
- };
58614
-
58615
- var index$7 = {
58616
- __proto__: null,
58617
- attachPolicies: attachPolicies,
58618
- findPolicy: findPolicy,
58619
- getAppliedPolicies: getAppliedPolicies,
58620
- getPolicyDefinitions: getPolicyDefinitions,
58621
- mutate: mutate$5,
58622
- query: query$1,
58623
- removePolicy: removePolicy
58624
- };
58625
-
58626
58759
  function publishEventSeeding(_a) {
58627
58760
  var _b, _c, _d, _e;
58628
58761
  var _f = _a.removePriorValues, removePriorValues = _f === void 0 ? true : _f, stageSeedingScaleNames = _a.stageSeedingScaleNames, seedingScaleNames = _a.seedingScaleNames, tournamentRecord = _a.tournamentRecord, _g = _a.status, status = _g === void 0 ? PUBLIC : _g, _h = _a.drawIds, drawIds = _h === void 0 ? [] : _h, event = _a.event;
@@ -64702,15 +64835,15 @@ var index$1 = {
64702
64835
  var governors = {
64703
64836
  __proto__: null,
64704
64837
  competitionGovernor: index$h,
64705
- drawsGovernor: index$e,
64706
- entriesGovernor: index$d,
64707
- eventGovernor: index$c,
64708
- generationGovernor: index$b,
64709
- matchUpFormatGovernor: index$a,
64710
- matchUpGovernor: index$9,
64838
+ drawsGovernor: index$d,
64839
+ entriesGovernor: index$c,
64840
+ eventGovernor: index$b,
64841
+ generationGovernor: index$a,
64842
+ matchUpFormatGovernor: index$9,
64843
+ matchUpGovernor: index$8,
64711
64844
  mocksGovernor: mocksGovernor,
64712
- participantGovernor: index$8,
64713
- policyGovernor: index$7,
64845
+ participantGovernor: index$7,
64846
+ policyGovernor: index$e,
64714
64847
  publishingGovernor: index$6,
64715
64848
  queryGovernor: index$g,
64716
64849
  reportGovernor: index$5,
@@ -66735,27 +66868,27 @@ exports.competitionGovernor = index$h;
66735
66868
  exports.completedMatchUpStatuses = completedMatchUpStatuses;
66736
66869
  exports.directingMatchUpStatuses = directingMatchUpStatuses;
66737
66870
  exports.drawDefinitionConstants = drawDefinitionConstants;
66738
- exports.drawsGovernor = index$e;
66739
- exports.entriesGovernor = index$d;
66871
+ exports.drawsGovernor = index$d;
66872
+ exports.entriesGovernor = index$c;
66740
66873
  exports.entryStatusConstants = entryStatusConstants;
66741
66874
  exports.errorConditionConstants = errorConditionConstants;
66742
66875
  exports.eventConstants = eventConstants;
66743
- exports.eventGovernor = index$c;
66876
+ exports.eventGovernor = index$b;
66744
66877
  exports.extensionConstants = extensionConstants;
66745
66878
  exports.factoryConstants = index;
66746
66879
  exports.fixtures = fixtures;
66747
66880
  exports.flightConstants = flightConstants;
66748
66881
  exports.forge = forge;
66749
66882
  exports.genderConstants = genderConstants;
66750
- exports.generationGovernor = index$b;
66883
+ exports.generationGovernor = index$a;
66751
66884
  exports.globalState = globalState$1;
66752
66885
  exports.governors = governors;
66753
66886
  exports.keyValueConstants = keyValueConstants;
66754
66887
  exports.matchUpActionConstants = matchUpActionConstants;
66755
66888
  exports.matchUpEngine = matchUpEngine;
66756
- exports.matchUpFormatCode = index$a;
66757
- exports.matchUpFormatGovernor = index$a;
66758
- exports.matchUpGovernor = index$9;
66889
+ exports.matchUpFormatCode = index$9;
66890
+ exports.matchUpFormatGovernor = index$9;
66891
+ exports.matchUpGovernor = index$8;
66759
66892
  exports.matchUpStatusConstants = matchUpStatusConstants;
66760
66893
  exports.matchUpTypes = matchUpTypes;
66761
66894
  exports.mocksEngine = mocksEngine;
@@ -66763,12 +66896,12 @@ exports.mocksGovernor = mocksGovernor;
66763
66896
  exports.nonDirectingMatchUpStatuses = nonDirectingMatchUpStatuses;
66764
66897
  exports.particicipantsRequiredMatchUpStatuses = particicipantsRequiredMatchUpStatuses;
66765
66898
  exports.participantConstants = participantConstants;
66766
- exports.participantGovernor = index$8;
66899
+ exports.participantGovernor = index$7;
66767
66900
  exports.participantRoles = participantRoles;
66768
66901
  exports.participantTypes = participantTypes;
66769
66902
  exports.penaltyConstants = penaltyConstants;
66770
66903
  exports.policyConstants = policyConstants;
66771
- exports.policyGovernor = index$7;
66904
+ exports.policyGovernor = index$e;
66772
66905
  exports.positionActionConstants = positionActionConstants;
66773
66906
  exports.publishingGovernor = index$6;
66774
66907
  exports.queryGovernor = index$g;