tods-competition-factory 0.67.3 → 0.69.0

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.
@@ -249,7 +249,7 @@ const matchUpFormatCode = {
249
249
  };
250
250
 
251
251
  function factoryVersion() {
252
- return '0.67.3';
252
+ return '0.69.0';
253
253
  }
254
254
 
255
255
  const FORMAT_STANDARD = 'SET3-S:6/TB7'; // Best of 3 Tiebreak Sets to 6
@@ -7516,7 +7516,8 @@ const drawDefinitionConstants = {
7516
7516
  WIN_RATIO,
7517
7517
  ROUND_OUTCOME,
7518
7518
  MULTI_STRUCTURE_DRAWS,
7519
- generatedDrawTypes
7519
+ generatedDrawTypes,
7520
+ stageOrder
7520
7521
  };
7521
7522
 
7522
7523
  const WITHDRAW_PARTICIPANT_METHOD = 'withdrawParticipantAtDrawPosition';
@@ -9403,7 +9404,10 @@ function getAppliedPolicies({
9403
9404
  function getRoundMatchUps$1({
9404
9405
  matchUps = []
9405
9406
  }) {
9406
- // create an array of arrays of matchUps grouped by roundNumber
9407
+ if (!Array.isArray(matchUps)) return {
9408
+ error: INVALID_VALUES
9409
+ }; // create an array of arrays of matchUps grouped by roundNumber
9410
+
9407
9411
  const roundMatchUpsArray = matchUps.reduce((roundNumbers, matchUp) => {
9408
9412
  return !matchUp.roundNumber || roundNumbers.includes(matchUp.roundNumber) ? roundNumbers : roundNumbers.concat(parseInt(matchUp.roundNumber));
9409
9413
  }, []).sort(numericSort).map(roundNumber => {
@@ -9439,13 +9443,21 @@ function getRoundMatchUps$1({
9439
9443
  // - finishingRound: reverse count of rounds. Final is finishingRound #1
9440
9444
 
9441
9445
  const roundProfile = Object.assign({}, ...Object.keys(roundMatchUps).map(roundNumber => {
9442
- var _roundMatchUps$roundN;
9446
+ var _roundMatchUps$roundN, _roundMatchUps$roundN2, _roundMatchUps$roundN3;
9443
9447
 
9444
9448
  const matchUpsCount = (_roundMatchUps$roundN = roundMatchUps[roundNumber]) === null || _roundMatchUps$roundN === void 0 ? void 0 : _roundMatchUps$roundN.length;
9449
+ const inactiveCount = (_roundMatchUps$roundN2 = roundMatchUps[roundNumber]) === null || _roundMatchUps$roundN2 === void 0 ? void 0 : (_roundMatchUps$roundN3 = _roundMatchUps$roundN2.filter(matchUp => {
9450
+ var _matchUp$score;
9451
+
9452
+ return !completedMatchUpStatuses.includes(matchUp.matchUpStatus) && !((_matchUp$score = matchUp.score) !== null && _matchUp$score !== void 0 && _matchUp$score.scoreStringSide1);
9453
+ })) === null || _roundMatchUps$roundN3 === void 0 ? void 0 : _roundMatchUps$roundN3.length;
9454
+ const inactiveRound = matchUpsCount && matchUpsCount === inactiveCount;
9445
9455
  maxMatchUpsCount = Math.max(maxMatchUpsCount, matchUpsCount);
9446
9456
  return {
9447
9457
  [roundNumber]: {
9448
- matchUpsCount
9458
+ matchUpsCount,
9459
+ inactiveCount,
9460
+ inactiveRound
9449
9461
  }
9450
9462
  };
9451
9463
  }));
@@ -9598,6 +9610,7 @@ function getMappedStructureMatchUps({
9598
9610
 
9599
9611
  if (inContext) {
9600
9612
  return matchUps.map(matchUp => Object.assign(makeDeepCopy(matchUp, true, true), {
9613
+ containerStructureId: structureId,
9601
9614
  structureId: itemStructureId,
9602
9615
  structureName
9603
9616
  }));
@@ -9630,7 +9643,7 @@ function findStructure({
9630
9643
  };
9631
9644
  const {
9632
9645
  structures
9633
- } = getDrawStructures$1({
9646
+ } = getDrawStructures({
9634
9647
  drawDefinition
9635
9648
  });
9636
9649
  const allStructures = structures.map(structure => {
@@ -9648,7 +9661,7 @@ function findStructure({
9648
9661
  TESTS: structureGetter.test.js
9649
9662
  */
9650
9663
 
9651
- function getDrawStructures$1({
9664
+ function getDrawStructures({
9652
9665
  stage,
9653
9666
  stageSequence,
9654
9667
  drawDefinition
@@ -9857,8 +9870,8 @@ function modifyEntryProfile({
9857
9870
  let {
9858
9871
  extension
9859
9872
  } = findDrawDefinitionExtension({
9860
- drawDefinition,
9861
- name: ENTRY_PROFILE
9873
+ name: ENTRY_PROFILE,
9874
+ drawDefinition
9862
9875
  });
9863
9876
  const entryProfile = ((_extension = extension) === null || _extension === void 0 ? void 0 : _extension.value) || drawDefinition.entryProfile || {};
9864
9877
  attributes.forEach(attribute => {
@@ -11207,10 +11220,10 @@ function getAllStructureMatchUps({
11207
11220
 
11208
11221
  if (!structure) {
11209
11222
  return {
11210
- matchUps: [],
11211
11223
  collectionPositionMatchUps,
11224
+ error: MISSING_STRUCTURE,
11212
11225
  roundMatchUps,
11213
- error: MISSING_STRUCTURE
11226
+ matchUps: []
11214
11227
  };
11215
11228
  }
11216
11229
 
@@ -11397,7 +11410,7 @@ function getAllStructureMatchUps({
11397
11410
  }) {
11398
11411
  var _roundNamingProfile$r, _roundNamingProfile$r2, _roundProfile$roundNu, _roundProfile$roundNu2, _roundProfile$roundNu3;
11399
11412
 
11400
- const tieFormat = matchUp.tieFormat || structure.tieFormat || (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.tieFormat) || (event === null || event === void 0 ? void 0 : event.tieFormat);
11413
+ const tieFormat = matchUp.tieFormat || structure.tieFormat || (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.tieFormat) || (event === null || event === void 0 ? void 0 : event.tieFormat) || undefined;
11401
11414
  const collectionDefinitions = tieFormat === null || tieFormat === void 0 ? void 0 : tieFormat.collectionDefinitions;
11402
11415
  const collectionDefinition = matchUp.collectionId && (collectionDefinitions === null || collectionDefinitions === void 0 ? void 0 : collectionDefinitions.find(definition => definition.collectionId === matchUp.collectionId));
11403
11416
  const matchUpFormat = matchUp.matchUpFormat || matchUp.collectionId ? collectionDefinition && collectionDefinition.matchUpFormat : structure.matchUpFormat || (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.matchUpFormat) || (event === null || event === void 0 ? void 0 : event.matchUpFormat);
@@ -11670,7 +11683,7 @@ function findMatchUp$1({
11670
11683
  };
11671
11684
  const {
11672
11685
  structures
11673
- } = getDrawStructures$1({
11686
+ } = getDrawStructures({
11674
11687
  drawDefinition
11675
11688
  });
11676
11689
 
@@ -13376,7 +13389,7 @@ function getDrawMatchUps({
13376
13389
 
13377
13390
  const {
13378
13391
  structures
13379
- } = getDrawStructures$1({
13392
+ } = getDrawStructures({
13380
13393
  drawDefinition
13381
13394
  });
13382
13395
 
@@ -14380,7 +14393,11 @@ function validateSchedulingProfile({
14380
14393
  });
14381
14394
  return validVenues;
14382
14395
  });
14383
- if (!isValid && !error) error = INVALID_VALUES;
14396
+
14397
+ if (!isValid && !error) {
14398
+ error = INVALID_VALUES;
14399
+ }
14400
+
14384
14401
  return {
14385
14402
  valid: !!isValid,
14386
14403
  error,
@@ -14416,12 +14433,13 @@ function tournamentRelevantSchedulingIds({
14416
14433
  tournamentMap[tournamentId][eventId][drawId] = {};
14417
14434
  const {
14418
14435
  structures
14419
- } = getDrawStructures$1({
14436
+ } = getDrawStructures({
14420
14437
  drawDefinition
14421
14438
  });
14422
14439
  (structures || []).forEach(structure => {
14440
+ var _structure$structures;
14441
+
14423
14442
  const structureId = structure.structureId;
14424
- structureIds.push(structureId);
14425
14443
  const {
14426
14444
  matchUps
14427
14445
  } = getAllStructureMatchUps({
@@ -14434,6 +14452,14 @@ function tournamentRelevantSchedulingIds({
14434
14452
  });
14435
14453
  const rounds = roundMatchUps && Object.keys(roundMatchUps).map(roundNumber => parseInt(roundNumber));
14436
14454
  tournamentMap[tournamentId][eventId][drawId][structureId] = rounds;
14455
+ structureIds.push(structureId);
14456
+
14457
+ if ((_structure$structures = structure.structures) !== null && _structure$structures !== void 0 && _structure$structures.length) {
14458
+ structure.structures.forEach(itemStructure => {
14459
+ structureIds.push(itemStructure.structureId);
14460
+ tournamentMap[tournamentId][eventId][drawId][itemStructure.structureId] = rounds;
14461
+ });
14462
+ }
14437
14463
  });
14438
14464
  });
14439
14465
  });
@@ -15396,23 +15422,24 @@ function isActiveMatchUp({
15396
15422
 
15397
15423
  function structureActiveDrawPositions({
15398
15424
  drawDefinition,
15399
- structureId
15425
+ structureId,
15426
+ structure
15400
15427
  }) {
15401
15428
  const matchUpFilters = {
15402
15429
  isCollectionMatchUp: false
15403
15430
  };
15431
+
15432
+ if (!structure) {
15433
+ const result = findStructure({
15434
+ drawDefinition,
15435
+ structureId
15436
+ });
15437
+ if (result.error) return result;
15438
+ structure = result.structure;
15439
+ }
15440
+
15404
15441
  const {
15405
- structure,
15406
- error
15407
- } = findStructure({
15408
- drawDefinition,
15409
- structureId
15410
- });
15411
- if (error) return {
15412
- error
15413
- };
15414
- const {
15415
- matchUps
15442
+ matchUps: inContextStructureMatchUps
15416
15443
  } = getAllStructureMatchUps({
15417
15444
  inContext: true,
15418
15445
  drawDefinition,
@@ -15420,24 +15447,24 @@ function structureActiveDrawPositions({
15420
15447
  structure
15421
15448
  }); // first collect all drawPositions for the structure
15422
15449
 
15423
- const drawPositions = unique([].concat(...matchUps.map(matchUp => matchUp.drawPositions || [])).filter(Boolean)).sort(numericSort); // get a mapping of all matchUpIds to dependent matchUpIds
15450
+ const drawPositions = unique([].concat(...inContextStructureMatchUps.map(matchUp => matchUp.drawPositions || [])).filter(Boolean)).sort(numericSort); // get a mapping of all matchUpIds to dependent matchUpIds
15424
15451
 
15425
15452
  const {
15426
15453
  matchUpDependencies
15427
15454
  } = getMatchUpDependencies({
15455
+ matchUps: inContextStructureMatchUps,
15428
15456
  drawIds: [drawDefinition.drawId],
15429
- drawDefinition,
15430
- matchUps
15457
+ drawDefinition
15431
15458
  }); // determine which matchUps are active
15432
15459
 
15433
- const activeMatchUps = matchUps.filter(isActiveMatchUp); // create an array of all matchUpIds active because they are dependent
15460
+ const activeMatchUps = inContextStructureMatchUps.filter(isActiveMatchUp); // create an array of all matchUpIds active because they are dependent
15434
15461
 
15435
15462
  const activeDependentMatchUpIds = unique(activeMatchUps.map(matchUp => {
15436
15463
  var _matchUpDependencies$;
15437
15464
 
15438
15465
  return [].concat(...(((_matchUpDependencies$ = matchUpDependencies[matchUp.matchUpId]) === null || _matchUpDependencies$ === void 0 ? void 0 : _matchUpDependencies$.matchUpIds) || []), matchUp.matchUpId);
15439
15466
  }).flat());
15440
- const activeDrawPositions = unique(matchUps.map(({
15467
+ const activeDrawPositions = unique(inContextStructureMatchUps.map(({
15441
15468
  matchUpId,
15442
15469
  drawPositions
15443
15470
  }) => activeDependentMatchUpIds.includes(matchUpId) ? drawPositions : []).flat().filter(Boolean)).sort(numericSort);
@@ -15452,6 +15479,8 @@ function structureActiveDrawPositions({
15452
15479
  const inactiveDrawPositions = (drawPositions === null || drawPositions === void 0 ? void 0 : drawPositions.filter(drawPosition => !activeDrawPositions.includes(drawPosition))) || [];
15453
15480
  return {
15454
15481
  allDrawPositions: drawPositions,
15482
+ inContextStructureMatchUps,
15483
+ activeDependentMatchUpIds,
15455
15484
  inactiveDrawPositions,
15456
15485
  positionAssignments,
15457
15486
  activeDrawPositions,
@@ -22278,7 +22307,7 @@ function addParticipantContext(params) {
22278
22307
  [entry.participantId]: entry
22279
22308
  })));
22280
22309
  const drawEntries = Object.values(entriesMap);
22281
- const mainStructure = getDrawStructures$1({
22310
+ const mainStructure = getDrawStructures({
22282
22311
  stageSequence: 1,
22283
22312
  drawDefinition,
22284
22313
  stage: MAIN
@@ -22286,7 +22315,7 @@ function addParticipantContext(params) {
22286
22315
  const drawSize = mainStructure && ((_getPositionAssignmen = getPositionAssignments$1({
22287
22316
  structure: mainStructure
22288
22317
  })) === null || _getPositionAssignmen === void 0 ? void 0 : (_getPositionAssignmen2 = _getPositionAssignmen.positionAssignments) === null || _getPositionAssignmen2 === void 0 ? void 0 : _getPositionAssignmen2.length);
22289
- const qualifyingStructure = getDrawStructures$1({
22318
+ const qualifyingStructure = getDrawStructures({
22290
22319
  stageSequence: 1,
22291
22320
  drawDefinition,
22292
22321
  stage: QUALIFYING
@@ -25997,8 +26026,8 @@ function jinnScheduler({
25997
26026
  orderedMatchUpIds,
25998
26027
  minutesMap
25999
26028
  } = getScheduledRoundsDetails({
26000
- tournamentRecords,
26001
26029
  containedStructureIds,
26030
+ tournamentRecords,
26002
26031
  periodLength,
26003
26032
  matchUps,
26004
26033
  rounds
@@ -31002,34 +31031,32 @@ function automatedPositioning$1({
31002
31031
  }
31003
31032
 
31004
31033
  const structureTemplate = ({
31005
- stage,
31006
- structureId,
31007
- matchUps = [],
31008
- structures,
31009
- stageOrder,
31010
- roundLimit,
31011
- roundOffset,
31012
- exitProfile,
31013
- // matchUpType, // unnecessary; factory propagates to this point in case it is ever necessary
31034
+ finishingPosition = ROUND_OUTCOME,
31035
+ structureAbbreviation,
31036
+ seedAssignments = [],
31037
+ stageSequence = 1,
31038
+ qualifyingRoundNumber,
31039
+ seedingProfile,
31014
31040
  matchUpFormat,
31015
31041
  structureType,
31016
- structureAbbreviation,
31017
31042
  structureName,
31018
- seedingProfile,
31019
- qualifyingRound,
31020
- stageSequence = 1,
31021
- seedAssignments = [],
31022
- finishingPosition = ROUND_OUTCOME
31043
+ matchUps = [],
31044
+ structureId,
31045
+ exitProfile,
31046
+ roundOffset,
31047
+ roundLimit,
31048
+ stageOrder,
31049
+ structures,
31050
+ stage
31023
31051
  }) => {
31024
31052
  const structure = {
31053
+ structureId: structureId || UUID(),
31025
31054
  structureAbbreviation,
31026
- structureName,
31027
- // matchUpType,
31028
- matchUpFormat,
31029
- stageSequence,
31030
31055
  finishingPosition,
31031
31056
  seedAssignments,
31032
- structureId: structureId || UUID()
31057
+ matchUpFormat,
31058
+ stageSequence,
31059
+ structureName
31033
31060
  };
31034
31061
  if (stage) structure.stage = stage;
31035
31062
  if (stageOrder) structure.stageOrder = stageOrder;
@@ -31037,7 +31064,7 @@ const structureTemplate = ({
31037
31064
  if (roundOffset) structure.roundOffset = roundOffset;
31038
31065
  if (structureType) structure.structureType = structureType;
31039
31066
  if (seedingProfile) structure.seedingProfile = seedingProfile;
31040
- if (qualifyingRound) structure.qualifyingRound = qualifyingRound;
31067
+ if (qualifyingRoundNumber) structure.qualifyingRoundNumber = qualifyingRoundNumber;
31041
31068
  if (exitProfile) structure.exitProfile = exitProfile;
31042
31069
  const positionAssignments = [].concat(...matchUps.map(matchUp => matchUp.drawPositions)).filter(Boolean);
31043
31070
 
@@ -31054,10 +31081,11 @@ const structureTemplate = ({
31054
31081
  };
31055
31082
 
31056
31083
  function treeMatchUps({
31057
- qualifyingRound,
31084
+ qualifyingRoundNumber,
31058
31085
  // round at which participants qualify
31059
31086
  finishingPositionOffset,
31060
31087
  qualifyingPositions,
31088
+ // number of positions which qualify
31061
31089
  matchUpType,
31062
31090
  roundLimit,
31063
31091
  idPrefix,
@@ -31091,7 +31119,7 @@ function treeMatchUps({
31091
31119
  uuids
31092
31120
  }));
31093
31121
  roundNumber++;
31094
- roundLimit = roundLimit || qualifyingRound;
31122
+ roundLimit = roundLimit || qualifyingRoundNumber;
31095
31123
 
31096
31124
  while (roundNodes.length > 1) {
31097
31125
  if (qualifyingPositions && roundNodes.length === qualifyingPositions) roundLimit = roundNumber - 1;
@@ -31469,24 +31497,21 @@ function getMatchUpId({
31469
31497
  }
31470
31498
 
31471
31499
  function generateVoluntaryConsolationStructure$1({
31500
+ structureName = VOLUNTARY_CONSOLATION,
31501
+ structureAbbreviation,
31472
31502
  drawDefinition,
31473
31503
  participants,
31474
31504
  matchUpType,
31475
- event,
31476
- structureName = VOLUNTARY_CONSOLATION,
31477
- structureAbbreviation,
31478
31505
  structureId,
31479
- automated
31506
+ automated,
31507
+ drawSize,
31508
+ event
31480
31509
  }) {
31481
31510
  const stage = VOLUNTARY_CONSOLATION;
31482
31511
  if (!drawDefinition) return {
31483
31512
  error: MISSING_DRAW_DEFINITION
31484
31513
  };
31485
31514
  matchUpType = matchUpType || drawDefinition.matchUpType;
31486
- const drawSize = getStageDrawPositionsCount({
31487
- stage,
31488
- drawDefinition
31489
- });
31490
31515
  const {
31491
31516
  matchUps
31492
31517
  } = treeMatchUps({
@@ -31521,6 +31546,34 @@ function generateVoluntaryConsolationStructure$1({
31521
31546
  };
31522
31547
  }
31523
31548
 
31549
+ function generateQualifyingLink$1({
31550
+ targetEntryRound = 1,
31551
+ sourceRoundNumber,
31552
+ sourceStructureId,
31553
+ targetStructureId,
31554
+ drawDefinition
31555
+ }) {
31556
+ if (!drawDefinition) return {
31557
+ error: MISSING_DRAW_DEFINITION
31558
+ };
31559
+ const link = {
31560
+ linkType: WINNER,
31561
+ source: {
31562
+ roundNumber: sourceRoundNumber,
31563
+ structureId: sourceStructureId
31564
+ },
31565
+ target: {
31566
+ feedProfile: DRAW,
31567
+ roundNumber: targetEntryRound,
31568
+ structureId: targetStructureId
31569
+ }
31570
+ };
31571
+ drawDefinition.links.push(link);
31572
+ modifyDrawNotice({
31573
+ drawDefinition
31574
+ });
31575
+ }
31576
+
31524
31577
  /**
31525
31578
  *
31526
31579
  * @param {string} drawId - required - tournamentEngine discovers and passes { drawDefinition }
@@ -31729,12 +31782,12 @@ function setStageDrawSize({
31729
31782
  const {
31730
31783
  entryProfile
31731
31784
  } = modifyEntryProfile({
31732
- drawDefinition,
31733
31785
  attributes: [{
31734
31786
  [stage]: {
31735
31787
  drawSize
31736
31788
  }
31737
- }]
31789
+ }],
31790
+ drawDefinition
31738
31791
  });
31739
31792
  modifyDrawNotice({
31740
31793
  drawDefinition
@@ -31762,12 +31815,12 @@ function setStageAlternatesCount({
31762
31815
  }
31763
31816
 
31764
31817
  modifyEntryProfile({
31765
- drawDefinition,
31766
31818
  attributes: [{
31767
31819
  [stage]: {
31768
31820
  alternates: alternatesCount
31769
31821
  }
31770
- }]
31822
+ }],
31823
+ drawDefinition
31771
31824
  });
31772
31825
 
31773
31826
  if (!alternatesCount) {
@@ -31834,12 +31887,12 @@ function setStageWildcardsCount({
31834
31887
  }
31835
31888
 
31836
31889
  modifyEntryProfile({
31837
- drawDefinition,
31838
31890
  attributes: [{
31839
31891
  [stage]: {
31840
31892
  wildcardsCount
31841
31893
  }
31842
- }]
31894
+ }],
31895
+ drawDefinition
31843
31896
  });
31844
31897
  modifyDrawNotice({
31845
31898
  drawDefinition
@@ -31848,9 +31901,9 @@ function setStageWildcardsCount({
31848
31901
  };
31849
31902
  }
31850
31903
  function setStageQualifiersCount({
31904
+ qualifiersCount = 0,
31851
31905
  drawDefinition,
31852
- stage,
31853
- qualifiersCount = 0
31906
+ stage
31854
31907
  }) {
31855
31908
  if (!drawDefinition) return {
31856
31909
  error: MISSING_DRAW_DEFINITION
@@ -31885,12 +31938,12 @@ function setStageQualifiersCount({
31885
31938
  error: 'Total stage Entries cannot be greater than drawPositions'
31886
31939
  };
31887
31940
  modifyEntryProfile({
31888
- drawDefinition,
31889
31941
  attributes: [{
31890
31942
  [stage]: {
31891
31943
  qualifiersCount
31892
31944
  }
31893
- }]
31945
+ }],
31946
+ drawDefinition
31894
31947
  });
31895
31948
  modifyDrawNotice({
31896
31949
  drawDefinition
@@ -31918,6 +31971,45 @@ function addVoluntaryConsolationStage$1({
31918
31971
  return SUCCESS;
31919
31972
  }
31920
31973
 
31974
+ function getStructureQualifiersCount({
31975
+ drawDefinition,
31976
+ structure,
31977
+ structureId
31978
+ }) {
31979
+ let error, qualifiersCount;
31980
+
31981
+ if (!structure) {
31982
+ ({
31983
+ structure,
31984
+ error
31985
+ } = findStructure({
31986
+ drawDefinition,
31987
+ structureId
31988
+ }));
31989
+ }
31990
+
31991
+ if (!error) {
31992
+ if (structure.stage !== QUALIFYING) {
31993
+ error = 'Structure is not Qualifying';
31994
+ } else {
31995
+ const {
31996
+ matchUps
31997
+ } = getAllStructureMatchUps({
31998
+ drawDefinition,
31999
+ structure
32000
+ });
32001
+ qualifiersCount = matchUps.reduce((count, matchUp) => {
32002
+ return count + (matchUp.finishingRound === 1 ? 1 : 0);
32003
+ }, 0);
32004
+ }
32005
+ }
32006
+
32007
+ return {
32008
+ qualifiersCount,
32009
+ error
32010
+ };
32011
+ }
32012
+
31921
32013
  function getStructureRoundProfile({
31922
32014
  drawDefinition,
31923
32015
  structureId
@@ -32121,7 +32213,7 @@ function getAvailablePlayoffRounds$1({
32121
32213
  };
32122
32214
  let {
32123
32215
  structures
32124
- } = getDrawStructures$1({
32216
+ } = getDrawStructures({
32125
32217
  stageSeqence: 1,
32126
32218
  drawDefinition,
32127
32219
  stage: MAIN
@@ -32135,7 +32227,7 @@ function getAvailablePlayoffRounds$1({
32135
32227
  });
32136
32228
  ({
32137
32229
  structures
32138
- } = getDrawStructures$1({
32230
+ } = getDrawStructures({
32139
32231
  drawDefinition
32140
32232
  }));
32141
32233
  const filteredStructures = structures.filter(structure => !structureId || structure.structureId === structureId);
@@ -32560,7 +32652,8 @@ function playoffStructures({
32560
32652
  };
32561
32653
  const {
32562
32654
  matchUps
32563
- } = staggeredEntry ? feedInMatchUps(mainParams) : treeMatchUps(mainParams);
32655
+ } = staggeredEntry ? feedInMatchUps(mainParams) // TODO: is this ever valid?
32656
+ : treeMatchUps(mainParams);
32564
32657
  const structure = structureTemplate({
32565
32658
  structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
32566
32659
  structureAbbreviation,
@@ -32935,10 +33028,6 @@ function deleteAdHocMatchUps$1({
32935
33028
  }
32936
33029
 
32937
33030
  function firstRoundLoserConsolation(params) {
32938
- let {
32939
- drawSize,
32940
- consolationStructureName
32941
- } = params;
32942
33031
  const {
32943
33032
  finishingPositionOffset = 0,
32944
33033
  stageSequence = 1,
@@ -32948,13 +33037,10 @@ function firstRoundLoserConsolation(params) {
32948
33037
  stage = MAIN,
32949
33038
  matchUpType,
32950
33039
  idPrefix,
33040
+ drawSize,
32951
33041
  isMock,
32952
33042
  uuids
32953
33043
  } = params;
32954
- drawSize = drawSize || getStageDrawPositionsCount({
32955
- stage,
32956
- drawDefinition
32957
- });
32958
33044
  const mainParams = {
32959
33045
  finishingPositionOffset,
32960
33046
  matchUpType,
@@ -32967,12 +33053,12 @@ function firstRoundLoserConsolation(params) {
32967
33053
  matchUps
32968
33054
  } = staggeredEntry ? feedInMatchUps(mainParams) : treeMatchUps(mainParams);
32969
33055
  const mainStructure = structureTemplate({
32970
- stage,
32971
- matchUps,
32972
- matchUpType,
32973
- stageSequence,
33056
+ structureName: structureName || MAIN,
32974
33057
  structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
32975
- structureName: structureName || MAIN
33058
+ stageSequence,
33059
+ matchUpType,
33060
+ matchUps,
33061
+ stage
32976
33062
  });
32977
33063
 
32978
33064
  if (drawDefinition) {
@@ -32984,19 +33070,19 @@ function firstRoundLoserConsolation(params) {
32984
33070
  matchUps: consolationMatchUps
32985
33071
  } = treeMatchUps({
32986
33072
  finishingPositionOffset: finishingPositionOffset + consolationDrawPositions,
32987
- drawSize: consolationDrawPositions,
32988
33073
  idPrefix: idPrefix && `${idPrefix}-c`,
33074
+ drawSize: consolationDrawPositions,
32989
33075
  matchUpType,
32990
33076
  isMock
32991
33077
  });
32992
- consolationStructureName = consolationStructureName || (structureName ? `${structureName} ${CONSOLATION}` : CONSOLATION);
33078
+ const consolationStructureName = params.consolationStructureName || (structureName ? `${structureName} ${CONSOLATION}` : CONSOLATION);
32993
33079
  const consolationStructure = structureTemplate({
32994
- matchUpType,
32995
- stageSequence: 1,
32996
- stage: CONSOLATION,
32997
- structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
33080
+ structureName: consolationStructureName,
32998
33081
  matchUps: consolationMatchUps,
32999
- structureName: consolationStructureName
33082
+ structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
33083
+ stage: CONSOLATION,
33084
+ stageSequence: 1,
33085
+ matchUpType
33000
33086
  });
33001
33087
 
33002
33088
  if (drawDefinition) {
@@ -33021,9 +33107,7 @@ function firstRoundLoserConsolation(params) {
33021
33107
  }
33022
33108
 
33023
33109
  return Object.assign({
33024
- link,
33025
- mainStructure,
33026
- consolationStructure,
33110
+ structures: [mainStructure, consolationStructure],
33027
33111
  links: drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.links
33028
33112
  }, SUCCESS);
33029
33113
  }
@@ -33201,10 +33285,10 @@ function generateDoubleElimination({
33201
33285
  }
33202
33286
 
33203
33287
  function feedInLinks({
33204
- mainStructure,
33205
33288
  consolationStructure,
33206
- roundsCount,
33207
33289
  roundOffset = 0,
33290
+ mainStructure,
33291
+ roundsCount,
33208
33292
  feedPolicy,
33209
33293
  fmlc
33210
33294
  }) {
@@ -33258,13 +33342,10 @@ function generateCurtisConsolation({
33258
33342
  drawDefinition,
33259
33343
  matchUpType,
33260
33344
  idPrefix,
33345
+ drawSize,
33261
33346
  isMock,
33262
33347
  uuids
33263
33348
  }) {
33264
- const drawSize = getStageDrawPositionsCount({
33265
- stage: MAIN,
33266
- drawDefinition
33267
- });
33268
33349
  const mainParams = {
33269
33350
  finishingPositionOffset,
33270
33351
  matchUpType,
@@ -33400,27 +33481,107 @@ function consolationFeedStructure({
33400
33481
  };
33401
33482
  }
33402
33483
 
33484
+ function generateQualifyingStructures({
33485
+ qualifyingProfiles,
33486
+ drawDefinition,
33487
+ matchUpType,
33488
+ idPrefix,
33489
+ isMock,
33490
+ uuids
33491
+ }) {
33492
+ const structures = [];
33493
+
33494
+ const sequenceSort = (a, b) => a.stageSequence - b.stageSequence;
33495
+
33496
+ let qualifyingDrawPositionsCount = 0,
33497
+ finalQualifyingRoundNumber,
33498
+ finalQualifyingStructureId,
33499
+ qualifiersCount = 0,
33500
+ stageSequence = 0;
33501
+
33502
+ for (const qualifyingProfile of qualifyingProfiles.sort(sequenceSort)) {
33503
+ var _matchUps$filter;
33504
+
33505
+ const {
33506
+ drawSize,
33507
+ qualifyingRoundNumber,
33508
+ qualifyingPositions,
33509
+ structureName
33510
+ } = qualifyingProfile;
33511
+ if (!drawSize || !isConvertableInteger(drawSize)) return {
33512
+ error: MISSING_DRAW_SIZE
33513
+ };
33514
+ const {
33515
+ matchUps,
33516
+ roundLimit
33517
+ } = treeMatchUps({
33518
+ qualifyingPositions,
33519
+ qualifyingRoundNumber,
33520
+ idPrefix,
33521
+ drawSize,
33522
+ isMock,
33523
+ uuids
33524
+ });
33525
+ stageSequence += 1;
33526
+ const qualifyingStructureName = structureName || (qualifyingProfiles.length > 1 ? `${QUALIFYING} ${stageSequence}` : QUALIFYING);
33527
+ const structure = structureTemplate({
33528
+ structureName: qualifyingStructureName,
33529
+ qualifyingRoundNumber: roundLimit,
33530
+ structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
33531
+ stage: QUALIFYING,
33532
+ stageSequence,
33533
+ matchUpType,
33534
+ roundLimit,
33535
+ // redundant
33536
+ matchUps
33537
+ }); // order of operations is important here!! finalyQualifier positions is not yet updated when this step occurs
33538
+
33539
+ if (stageSequence > 1) {
33540
+ generateQualifyingLink$1({
33541
+ sourceStructureId: finalQualifyingStructureId,
33542
+ targetStructureId: structure.structureId,
33543
+ sourceRoundNumber: finalQualifyingRoundNumber,
33544
+ drawDefinition
33545
+ }); // if more than one qualifying stageSequence, remove last stageSequence qualifier positions from count
33546
+
33547
+ qualifyingDrawPositionsCount += drawSize - qualifiersCount;
33548
+ } else {
33549
+ qualifyingDrawPositionsCount += drawSize;
33550
+ }
33551
+
33552
+ qualifiersCount = (_matchUps$filter = matchUps.filter(matchUp => matchUp.roundNumber === roundLimit)) === null || _matchUps$filter === void 0 ? void 0 : _matchUps$filter.length;
33553
+ finalQualifyingStructureId = structure.structureId;
33554
+ finalQualifyingRoundNumber = roundLimit;
33555
+ structures.push(structure);
33556
+ }
33557
+
33558
+ return {
33559
+ qualifyingDrawPositionsCount,
33560
+ finalQualifyingRoundNumber,
33561
+ finalQualifyingStructureId,
33562
+ qualifiersCount,
33563
+ structures,
33564
+ ...SUCCESS
33565
+ };
33566
+ }
33567
+
33403
33568
  function feedInChampionship(params = {}) {
33404
33569
  const {
33405
- uuids,
33406
- feedRounds,
33407
- matchUpType,
33408
- stage = MAIN,
33409
- structureName,
33410
- drawDefinition,
33411
- feedsFromFinal,
33412
- stageSequence = 1,
33413
33570
  finishingPositionOffset,
33571
+ stageSequence = 1,
33572
+ feedsFromFinal,
33414
33573
  staggeredEntry,
33574
+ drawDefinition,
33575
+ structureName,
33576
+ matchUpType,
33415
33577
  feedPolicy,
33578
+ feedRounds,
33416
33579
  idPrefix,
33580
+ drawSize,
33417
33581
  isMock,
33582
+ uuids,
33418
33583
  fmlc
33419
33584
  } = params;
33420
- const drawSize = getStageDrawPositionsCount({
33421
- stage,
33422
- drawDefinition
33423
- });
33424
33585
  const mainParams = {
33425
33586
  finishingPositionOffset,
33426
33587
  matchUpType,
@@ -33447,98 +33608,38 @@ function feedInChampionship(params = {}) {
33447
33608
  roundsCount
33448
33609
  } = feedInMatchUps({
33449
33610
  finishingPositionOffset: baseDrawSize,
33611
+ idPrefix: idPrefix && `${idPrefix}-c`,
33450
33612
  isConsolation: true,
33451
33613
  feedsFromFinal,
33452
33614
  baseDrawSize,
33453
33615
  matchUpType,
33454
33616
  feedRounds,
33455
- idPrefix: idPrefix && `${idPrefix}-c`,
33456
33617
  isMock,
33457
33618
  uuids,
33458
33619
  fmlc
33459
33620
  });
33460
33621
  const consolationStructure = structureTemplate({
33461
- matchUpType,
33462
- stageSequence: 1,
33463
- stage: CONSOLATION,
33622
+ matchUps: consolationMatchUps,
33464
33623
  structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
33465
33624
  structureName: CONSOLATION,
33466
- matchUps: consolationMatchUps
33625
+ stage: CONSOLATION,
33626
+ stageSequence: 1,
33627
+ matchUpType
33467
33628
  });
33468
33629
  drawDefinition.structures.push(consolationStructure);
33469
33630
  const links = feedInLinks({
33470
- mainStructure,
33471
33631
  consolationStructure,
33632
+ mainStructure,
33472
33633
  roundsCount,
33473
33634
  feedPolicy,
33474
33635
  fmlc
33475
33636
  });
33476
33637
  drawDefinition.links = drawDefinition.links.concat(...links);
33477
33638
  return Object.assign({
33478
- mainStructure,
33479
- consolationStructure,
33639
+ structures: [mainStructure, consolationStructure],
33480
33640
  links: drawDefinition.links
33481
- }, SUCCESS);
33482
- }
33483
-
33484
- function getDrawStructures({
33485
- stage,
33486
- stageSequence,
33487
- drawDefinition
33488
- } = {}) {
33489
- if (!drawDefinition) return {
33490
- error: MISSING_DRAW_DEFINITION
33491
- };
33492
- const stageStructures = drawDefinition.structures.filter(isStage).filter(isStageSequence);
33493
- return {
33494
- structures: stageStructures
33495
- };
33496
-
33497
- function isStage(structure) {
33498
- return structure.stage === stage;
33499
- }
33500
-
33501
- function isStageSequence(structure) {
33502
- return !stageSequence || structure.stageSequence === stageSequence;
33503
- }
33504
- }
33505
- function getStructureQualifiersCount({
33506
- drawDefinition,
33507
- structure,
33508
- structureId
33509
- }) {
33510
- let error, qualifiersCount;
33511
-
33512
- if (!structure) {
33513
- ({
33514
- structure,
33515
- error
33516
- } = findStructure({
33517
- drawDefinition,
33518
- structureId
33519
- }));
33520
- }
33521
-
33522
- if (!error) {
33523
- if (structure.stage !== QUALIFYING) {
33524
- error = 'Structure is not Qualifying';
33525
- } else {
33526
- const {
33527
- matchUps
33528
- } = getAllStructureMatchUps({
33529
- drawDefinition,
33530
- structure
33531
- });
33532
- qualifiersCount = matchUps.reduce((count, matchUp) => {
33533
- return count + (matchUp.finishingRound === 1 ? 1 : 0);
33534
- }, 0);
33535
- }
33536
- }
33537
-
33538
- return {
33539
- qualifiersCount,
33540
- error
33541
- };
33641
+ }, { ...SUCCESS
33642
+ });
33542
33643
  }
33543
33644
 
33544
33645
  function generateRoundRobin({
@@ -33549,14 +33650,10 @@ function generateRoundRobin({
33549
33650
  drawDefinition,
33550
33651
  stage = MAIN,
33551
33652
  matchUpType,
33653
+ drawSize,
33552
33654
  idPrefix,
33553
33655
  uuids
33554
33656
  }) {
33555
- const finishingPosition = WIN_RATIO;
33556
- const drawSize = getStageDrawPositionsCount({
33557
- stage,
33558
- drawDefinition
33559
- });
33560
33657
  const {
33561
33658
  groupCount,
33562
33659
  groupSize
@@ -33564,6 +33661,7 @@ function generateRoundRobin({
33564
33661
  structureOptions,
33565
33662
  drawSize
33566
33663
  });
33664
+ const finishingPosition = WIN_RATIO;
33567
33665
  const structures = generateRange(1, groupCount + 1).map(structureOrder => structureTemplate({
33568
33666
  structureName: `Group ${structureOrder}`,
33569
33667
  matchUps: roundRobinMatchUps({
@@ -33592,10 +33690,11 @@ function generateRoundRobin({
33592
33690
  });
33593
33691
  drawDefinition.structures.push(structure);
33594
33692
  return Object.assign({
33595
- structure,
33693
+ structures: [structure],
33596
33694
  groupCount,
33597
33695
  groupSize
33598
- }, SUCCESS);
33696
+ }, { ...SUCCESS
33697
+ });
33599
33698
  } // first iteration only links to a single playoff structure
33600
33699
  // future iteration should allow structureOptions to specify
33601
33700
  // groups of finishing drawPositions which playoff
@@ -33617,7 +33716,7 @@ function generateRoundRobinWithPlayOff(params) {
33617
33716
  stage: MAIN
33618
33717
  });
33619
33718
  const {
33620
- structure: mainStructure,
33719
+ structures: [mainStructure],
33621
33720
  groupCount,
33622
33721
  groupSize
33623
33722
  } = generateRoundRobin(mainDrawProperties); // TODO: test for and handle this situation
@@ -33712,13 +33811,12 @@ function generateRoundRobinWithPlayOff(params) {
33712
33811
  }
33713
33812
 
33714
33813
  return undefined;
33715
- }).filter(Boolean); // mainStructure, playoffStructures and links are only returned for tests
33716
-
33814
+ }).filter(Boolean);
33717
33815
  return Object.assign({
33718
- mainStructure,
33719
- playoffStructures,
33816
+ structures: [mainStructure, ...playoffStructures],
33720
33817
  links: drawDefinition.links
33721
- }, SUCCESS);
33818
+ }, { ...SUCCESS
33819
+ });
33722
33820
  }
33723
33821
 
33724
33822
  function generatePlayoffLink({
@@ -33889,19 +33987,18 @@ function groupRounds({
33889
33987
  // TODO: consider refactoring to return structures rather than pushing them into drawDefinition
33890
33988
 
33891
33989
  function generateDrawType(params = {}) {
33990
+ var _params$qualifyingPro, _qualifyingResult$str;
33991
+
33892
33992
  const {
33893
33993
  drawType = SINGLE_ELIMINATION,
33894
33994
  stageSequence = 1,
33895
33995
  drawDefinition,
33896
33996
  staggeredEntry,
33997
+ // optional - specifies main structure FEED_IN for drawTypes CURTIS_CONSOLATION, FEED_IN_CHAMPIONSHIPS, FMLC
33897
33998
  structureName,
33898
33999
  goesTo = true,
33899
- stage = MAIN,
33900
34000
  isMock,
33901
- uuids // qualifyingPositions, => passed through in params to treeMatchUps
33902
- // qualifyingRound, => passed through in params to treeMatchUps
33903
- // TODO: description => is this passed on?
33904
-
34001
+ uuids
33905
34002
  } = params;
33906
34003
  if (!drawDefinition) return {
33907
34004
  error: MISSING_DRAW_DEFINITION
@@ -33912,10 +34009,59 @@ function generateDrawType(params = {}) {
33912
34009
  } = params;
33913
34010
  tieFormat = tieFormat || drawDefinition.tieFormat || undefined;
33914
34011
  matchUpType = matchUpType || drawDefinition.matchUpType || SINGLES$1;
33915
- const drawSize = getStageDrawPositionsCount({
33916
- stage,
33917
- drawDefinition
34012
+ const mainStageDrawPositionsCount = getStageDrawPositionsCount({
34013
+ drawDefinition,
34014
+ stage: MAIN
34015
+ });
34016
+
34017
+ if (!mainStageDrawPositionsCount) {
34018
+ setStageDrawSize({
34019
+ drawSize: params.drawSize,
34020
+ drawDefinition,
34021
+ stage: MAIN
34022
+ });
34023
+ } // first generate any qualifying structures
34024
+
34025
+
34026
+ const qualifyingResult = ((_params$qualifyingPro = params.qualifyingProfiles) === null || _params$qualifyingPro === void 0 ? void 0 : _params$qualifyingPro.length) && generateQualifyingStructures({
34027
+ qualifyingProfiles: params.qualifyingProfiles,
34028
+ idPrefix: params.idPrefix,
34029
+ drawDefinition,
34030
+ matchUpType,
34031
+ isMock,
34032
+ uuids
33918
34033
  });
34034
+ if (qualifyingResult !== null && qualifyingResult !== void 0 && qualifyingResult.error) return qualifyingResult;
34035
+ const {
34036
+ qualifiersCount = 0,
34037
+ qualifyingDrawPositionsCount
34038
+ } = qualifyingResult || {};
34039
+
34040
+ if (qualifyingDrawPositionsCount) {
34041
+ drawDefinition.structures.push(...qualifyingResult.structures);
34042
+ const qualifyingStageDrawPositionsCount = getStageDrawPositionsCount({
34043
+ stage: QUALIFYING,
34044
+ drawDefinition
34045
+ });
34046
+
34047
+ if (!qualifyingStageDrawPositionsCount) {
34048
+ const result = setStageDrawSize({
34049
+ drawSize: qualifyingDrawPositionsCount,
34050
+ stage: QUALIFYING,
34051
+ drawDefinition
34052
+ });
34053
+ if (result.error) return result;
34054
+ }
34055
+
34056
+ const result = setStageQualifiersCount({
34057
+ drawDefinition,
34058
+ qualifiersCount,
34059
+ stage: MAIN
34060
+ });
34061
+ if (result.error) return result;
34062
+ }
34063
+
34064
+ const drawSize = params.drawSize || mainStageDrawPositionsCount;
33919
34065
  Object.assign(params, definedAttributes({
33920
34066
  drawSize,
33921
34067
  matchUpType,
@@ -33947,7 +34093,7 @@ function generateDrawType(params = {}) {
33947
34093
  } = getDrawStructures({
33948
34094
  drawDefinition,
33949
34095
  stageSequence,
33950
- stage
34096
+ stage: MAIN
33951
34097
  });
33952
34098
  const structureCount = stageStructures.length;
33953
34099
  if (structureCount >= sequenceLimit) return {
@@ -33956,38 +34102,34 @@ function generateDrawType(params = {}) {
33956
34102
  const generators = {
33957
34103
  [AD_HOC]: () => {
33958
34104
  const structure = structureTemplate({
33959
- structureName: structureName || stage,
34105
+ structureName: structureName || MAIN,
33960
34106
  finishingPosition: WIN_RATIO,
33961
34107
  structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
33962
34108
  stageSequence,
33963
34109
  matchUps: [],
33964
34110
  matchUpType,
33965
- stage
34111
+ stage: MAIN
33966
34112
  });
33967
34113
  drawDefinition.structures.push(structure);
33968
34114
  return Object.assign({
33969
- structure
34115
+ structures: [structure]
33970
34116
  }, SUCCESS);
33971
34117
  },
33972
34118
  [SINGLE_ELIMINATION]: () => {
33973
34119
  const {
33974
- matchUps,
33975
- roundLimit: derivedRoundLimit
34120
+ matchUps
33976
34121
  } = treeMatchUps(params);
33977
- const qualifyingRound = stage === QUALIFYING && derivedRoundLimit;
33978
34122
  const structure = structureTemplate({
33979
- structureName: structureName || stage,
33980
- roundLimit: derivedRoundLimit,
34123
+ structureName: structureName || MAIN,
33981
34124
  structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
33982
- qualifyingRound,
33983
34125
  stageSequence,
33984
34126
  matchUpType,
33985
- matchUps,
33986
- stage
34127
+ stage: MAIN,
34128
+ matchUps
33987
34129
  });
33988
34130
  drawDefinition.structures.push(structure);
33989
34131
  return Object.assign({
33990
- structure
34132
+ structures: [structure]
33991
34133
  }, SUCCESS);
33992
34134
  },
33993
34135
  [DOUBLE_ELIMINATION]: () => generateDoubleElimination(params),
@@ -34009,16 +34151,16 @@ function generateDrawType(params = {}) {
34009
34151
  matchUpType
34010
34152
  });
34011
34153
  const structure = structureTemplate({
34012
- structureName: structureName || stage,
34154
+ structureName: structureName || MAIN,
34013
34155
  structureId: uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
34014
34156
  stageSequence,
34015
34157
  matchUpType,
34016
- matchUps,
34017
- stage
34158
+ stage: MAIN,
34159
+ matchUps
34018
34160
  });
34019
34161
  drawDefinition.structures.push(structure);
34020
34162
  return Object.assign({
34021
- structure
34163
+ structures: [structure]
34022
34164
  }, SUCCESS);
34023
34165
  },
34024
34166
  [FIRST_ROUND_LOSER_CONSOLATION]: () => firstRoundLoserConsolation(params),
@@ -34052,6 +34194,23 @@ function generateDrawType(params = {}) {
34052
34194
  };
34053
34195
  }
34054
34196
 
34197
+ if (qualifyingResult !== null && qualifyingResult !== void 0 && (_qualifyingResult$str = qualifyingResult.structures) !== null && _qualifyingResult$str !== void 0 && _qualifyingResult$str.length) {
34198
+ const {
34199
+ finalQualifyingRoundNumber: qualifyingRoundNumber,
34200
+ finalQualifyingStructureId: qualifyingStructureId
34201
+ } = qualifyingResult;
34202
+ const mainStructure = generatorResult.structures.find(({
34203
+ stage,
34204
+ stageSequence
34205
+ }) => stage === MAIN && stageSequence === 1);
34206
+ generateQualifyingLink$1({
34207
+ sourceStructureId: qualifyingStructureId,
34208
+ sourceRoundNumber: qualifyingRoundNumber,
34209
+ targetStructureId: mainStructure.structureId,
34210
+ drawDefinition
34211
+ });
34212
+ }
34213
+
34055
34214
  const {
34056
34215
  matchUps,
34057
34216
  matchUpsMap
@@ -34081,17 +34240,17 @@ function generateDrawType(params = {}) {
34081
34240
  drawDefinition,
34082
34241
  matchUpsMap
34083
34242
  }));
34084
- const result = { ...SUCCESS,
34085
- matchUps
34086
- };
34087
- Object.assign(result, generatorResult, {
34088
- inContextDrawMatchUps,
34089
- matchUpsMap
34090
- });
34091
34243
  modifyDrawNotice({
34092
34244
  drawDefinition
34093
34245
  });
34094
- return result;
34246
+ return {
34247
+ structures: drawDefinition.structures,
34248
+ links: drawDefinition.links,
34249
+ inContextDrawMatchUps,
34250
+ matchUpsMap,
34251
+ ...SUCCESS,
34252
+ matchUps
34253
+ };
34095
34254
  }
34096
34255
 
34097
34256
  function removeStructure({
@@ -34181,6 +34340,7 @@ const structureGovernor = {
34181
34340
  getAvailablePlayoffRounds: getAvailablePlayoffRounds$1,
34182
34341
  addPlayoffStructures: addPlayoffStructures$1,
34183
34342
  removeStructure,
34343
+ generateQualifyingLink: generateQualifyingLink$1,
34184
34344
  generateAdHocMatchUps: generateAdHocMatchUps$1,
34185
34345
  deleteAdHocMatchUps: deleteAdHocMatchUps$1,
34186
34346
  structureSort,
@@ -38484,7 +38644,7 @@ const entryGovernor = {
38484
38644
  function generateQualifyingLink({
38485
38645
  qualifyingStructureId,
38486
38646
  mainStructureId,
38487
- qualifyingRound,
38647
+ qualifyingRoundNumber,
38488
38648
  mainEntryRound = 1,
38489
38649
  drawDefinition
38490
38650
  }) {
@@ -38494,7 +38654,7 @@ function generateQualifyingLink({
38494
38654
  const link = {
38495
38655
  linkType: WINNER,
38496
38656
  source: {
38497
- roundNumber: qualifyingRound,
38657
+ roundNumber: qualifyingRoundNumber,
38498
38658
  structureId: qualifyingStructureId
38499
38659
  },
38500
38660
  target: {
@@ -41227,11 +41387,11 @@ function getEventData({
41227
41387
  }
41228
41388
 
41229
41389
  function publishEvent({
41230
- tournamentRecord,
41231
41390
  policyDefinitions,
41232
- status = PUBLIC,
41233
41391
  structureIds = [],
41392
+ tournamentRecord,
41234
41393
  drawIdsToRemove,
41394
+ status = PUBLIC,
41235
41395
  drawIdsToAdd,
41236
41396
  drawIds,
41237
41397
  event
@@ -41469,6 +41629,118 @@ const publishingGovernor = {
41469
41629
  unPublishEvent
41470
41630
  };
41471
41631
 
41632
+ function analyzeDraws(tournamentRecord) {
41633
+ var _tournamentRecord$eve;
41634
+
41635
+ const drawsAnalysis = {
41636
+ noPositionsAssigned: 0,
41637
+ // no positions assigned
41638
+ positionsNoOutcomes: 0,
41639
+ // all positions assigned and no outcomes
41640
+ matchPlayDraws: 0,
41641
+ // only first round has active matchUps; some unassigned positions
41642
+ canBePruned: 0,
41643
+ // partially assigned positions with outcomes => drawSizes can be reduced
41644
+ draws: []
41645
+ };
41646
+ const drawDefinitions = (_tournamentRecord$eve = tournamentRecord.events) === null || _tournamentRecord$eve === void 0 ? void 0 : _tournamentRecord$eve.map(event => event === null || event === void 0 ? void 0 : event.drawDefinitions).flat().filter(Boolean);
41647
+ drawDefinitions.forEach(drawDefinition => {
41648
+ const structures = (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) || [];
41649
+ const structureData = structures.map(structure => {
41650
+ const {
41651
+ stage,
41652
+ stageSequence,
41653
+ structureId
41654
+ } = structure;
41655
+ const orderNumber = stageOrder[stage];
41656
+ const {
41657
+ inContextStructureMatchUps
41658
+ } = structureActiveDrawPositions({
41659
+ drawDefinition,
41660
+ structure
41661
+ });
41662
+ const {
41663
+ positionAssignments
41664
+ } = getPositionAssignments$1({
41665
+ structure
41666
+ });
41667
+ const positionsAssigned = positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.filter(({
41668
+ participantId
41669
+ }) => participantId);
41670
+ const unassignedPositionsCount = ((positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.length) || 0) - ((positionsAssigned === null || positionsAssigned === void 0 ? void 0 : positionsAssigned.length) || 0);
41671
+ const {
41672
+ roundMatchUps,
41673
+ roundProfile,
41674
+ roundNumbers,
41675
+ maxMatchUpsCount
41676
+ } = getRoundMatchUps$1({
41677
+ matchUps: inContextStructureMatchUps
41678
+ });
41679
+ const activeRounds = Object.keys(roundProfile).filter(roundNumber => !roundProfile[roundNumber].inactiveRound);
41680
+ const inactiveStructure = Object.values(roundProfile).every(profile => profile.inactiveRound);
41681
+ return {
41682
+ positionsAssignedCount: (positionsAssigned === null || positionsAssigned === void 0 ? void 0 : positionsAssigned.length) || 0,
41683
+ unassignedPositionsCount,
41684
+ inactiveStructure,
41685
+ maxMatchUpsCount,
41686
+ roundMatchUps,
41687
+ activeRounds,
41688
+ roundNumbers,
41689
+ roundProfile,
41690
+ structureId,
41691
+ stageSequence,
41692
+ orderNumber,
41693
+ stage
41694
+ };
41695
+ });
41696
+ const mainStructure = structureData.find(data => data.orderNumber === 2 && data.stageSequence === 1);
41697
+ const isMatchPlay = mainStructure.activeRounds.length === 1 && parseInt(mainStructure.activeRounds[0]) === 1;
41698
+ const canBePruned = mainStructure.activeRounds.length && mainStructure.roundProfile[1].inActiveCount;
41699
+ if (isMatchPlay) drawsAnalysis.matchPlayDraws += 1;
41700
+ if (canBePruned) drawsAnalysis.canBePruned += 1;
41701
+ drawsAnalysis.draws.push({
41702
+ drawId: drawDefinition.drawId,
41703
+ structureData,
41704
+ isMatchPlay
41705
+ });
41706
+ });
41707
+ return { ...SUCCESS,
41708
+ drawsAnalysis
41709
+ };
41710
+ }
41711
+
41712
+ function checkIsDual(tournamentRecord) {
41713
+ var _tournamentRecord$par, _tournamentRecord$eve, _event$drawDefinition, _drawDefinition$struc, _structure$positionAs;
41714
+
41715
+ const teamParticipants = (_tournamentRecord$par = tournamentRecord.participants) === null || _tournamentRecord$par === void 0 ? void 0 : _tournamentRecord$par.filter(({
41716
+ participantType
41717
+ }) => participantType === TEAM$1);
41718
+ const twoTeams = (teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.length) === 2;
41719
+ const event = ((_tournamentRecord$eve = tournamentRecord.events) === null || _tournamentRecord$eve === void 0 ? void 0 : _tournamentRecord$eve.length) === 1 && tournamentRecord.events[0];
41720
+ const drawDefinition = (event === null || event === void 0 ? void 0 : (_event$drawDefinition = event.drawDefinitions) === null || _event$drawDefinition === void 0 ? void 0 : _event$drawDefinition.length) === 1 && event.drawDefinitions[0];
41721
+ const structure = (drawDefinition === null || drawDefinition === void 0 ? void 0 : (_drawDefinition$struc = drawDefinition.structures) === null || _drawDefinition$struc === void 0 ? void 0 : _drawDefinition$struc.length) === 1 && drawDefinition.structures[0];
41722
+ const twoDrawPositions = (structure === null || structure === void 0 ? void 0 : (_structure$positionAs = structure.positionAssignments) === null || _structure$positionAs === void 0 ? void 0 : _structure$positionAs.length) === 2;
41723
+ return event.tieFormat && twoTeams && twoDrawPositions;
41724
+ }
41725
+
41726
+ function analyzeTournament({
41727
+ tournamentRecord
41728
+ }) {
41729
+ if (!tournamentRecord) return {
41730
+ error: MISSING_TOURNAMENT_RECORD
41731
+ };
41732
+ const {
41733
+ drawsAnalysis
41734
+ } = analyzeDraws(tournamentRecord);
41735
+ const analysis = {
41736
+ isDual: checkIsDual(tournamentRecord),
41737
+ drawsAnalysis
41738
+ };
41739
+ return { ...SUCCESS,
41740
+ analysis
41741
+ };
41742
+ }
41743
+
41472
41744
  function setTournamentName({
41473
41745
  tournamentRecord,
41474
41746
  tournamentName,
@@ -41565,6 +41837,7 @@ function setTournamentCategories({
41565
41837
  const tournamentGovernor = {
41566
41838
  addNotes,
41567
41839
  removeNotes,
41840
+ analyzeTournament,
41568
41841
  setTournamentName,
41569
41842
  setTournamentNotes,
41570
41843
  setTournamentEndDate,
@@ -43894,17 +44167,15 @@ function generateDrawDefinition(params) {
43894
44167
  // mainly used by mocksEngine for scenario testing
43895
44168
  playoffMatchUpFormat,
43896
44169
  seedByRanking = true,
43897
- qualifyingPositions,
44170
+ qualifyingProfiles,
43898
44171
  seededParticipants,
43899
44172
  policyDefinitions,
43900
44173
  seedingScaleName,
43901
44174
  assignSeedsCount,
43902
44175
  // used for testing bye placement next to seeds
43903
44176
  automated = true,
43904
- qualifyingRound,
43905
44177
  seedingProfile,
43906
44178
  tieFormatName,
43907
- stage = MAIN,
43908
44179
  drawEntries,
43909
44180
  feedPolicy,
43910
44181
  idPrefix,
@@ -43971,7 +44242,7 @@ function generateDrawDefinition(params) {
43971
44242
  }
43972
44243
 
43973
44244
  const entries = drawEntries || (event === null || event === void 0 ? void 0 : event.entries) || [];
43974
- const stageEntries = entries.filter(entry => (!entry.entryStage || entry.entryStage === stage) && STRUCTURE_SELECTED_STATUSES.includes(entry.entryStatus)); // the reason for this needs to be clarified
44245
+ const stageEntries = entries.filter(entry => (!entry.entryStage || entry.entryStage === MAIN) && STRUCTURE_SELECTED_STATUSES.includes(entry.entryStatus)); // the reason for this needs to be clarified
43975
44246
 
43976
44247
  if ([ROUND_ROBIN].includes(drawType)) {
43977
44248
  drawSize = stageEntries.length || drawSize;
@@ -43981,17 +44252,6 @@ function generateDrawDefinition(params) {
43981
44252
  drawType,
43982
44253
  drawId
43983
44254
  });
43984
- setStageDrawSize({
43985
- drawDefinition,
43986
- stage,
43987
- drawSize
43988
- });
43989
-
43990
- if (drawEntries) {
43991
- const drawEntryStages = drawEntries.reduce((stages, entry) => stages.includes(entry.entryStage) ? stages : stages.concat(entry.entryStage), []).filter(entryStage => entryStage !== stage).filter(Boolean); // if (drawEntryStages.length) console.log({ drawEntryStages, drawEntries });
43992
-
43993
- if (drawEntryStages.length) console.log('drawEntryStages');
43994
- }
43995
44255
 
43996
44256
  if (matchUpFormat || tieFormat) {
43997
44257
  let equivalentInScope = matchUpFormat && (event === null || event === void 0 ? void 0 : event.matchUpFormat) === matchUpFormat || (event === null || event === void 0 ? void 0 : event.tieFormat) && tieFormat && JSON.stringify(event.tieFormat) === JSON.stringify(tieFormat); // if an equivalent matchUpFormat or tieFormat is attached to the event
@@ -44020,19 +44280,18 @@ function generateDrawDefinition(params) {
44020
44280
  finishingPositionNaming,
44021
44281
  goesTo: params.goesTo,
44022
44282
  playoffMatchUpFormat,
44023
- qualifyingPositions,
44283
+ qualifyingProfiles,
44024
44284
  structureOptions,
44025
- qualifyingRound,
44026
44285
  drawDefinition,
44027
44286
  seedingProfile,
44028
44287
  matchUpFormat,
44029
44288
  matchUpType,
44030
44289
  feedPolicy,
44031
44290
  tieFormat,
44291
+ drawSize,
44032
44292
  drawType,
44033
44293
  idPrefix,
44034
44294
  isMock,
44035
- stage,
44036
44295
  uuids
44037
44296
  });
44038
44297
  if (result.error) return result;
@@ -44045,7 +44304,7 @@ function generateDrawDefinition(params) {
44045
44304
  } = getDrawStructures({
44046
44305
  drawDefinition,
44047
44306
  stageSequence: 1,
44048
- stage
44307
+ stage: MAIN
44049
44308
  });
44050
44309
  const [structure] = structures;
44051
44310
  const {
@@ -44170,8 +44429,8 @@ function generateDrawDefinition(params) {
44170
44429
  } = getScaledEntries({
44171
44430
  scaleAttributes: seedingScaleAttributes,
44172
44431
  tournamentRecord,
44173
- entries,
44174
- stage
44432
+ stage: MAIN,
44433
+ entries
44175
44434
  });
44176
44435
 
44177
44436
  if (!((_scaledEntries = scaledEntries) !== null && _scaledEntries !== void 0 && _scaledEntries.length) && seedByRanking) {
@@ -44185,8 +44444,8 @@ function generateDrawDefinition(params) {
44185
44444
  } = getScaledEntries({
44186
44445
  scaleAttributes: rankingScaleAttributes,
44187
44446
  tournamentRecord,
44188
- entries,
44189
- stage
44447
+ stage: MAIN,
44448
+ entries
44190
44449
  }));
44191
44450
  }
44192
44451
 
@@ -48796,6 +49055,7 @@ function generatePersons({
48796
49055
  error: INVALID_VALUES
48797
49056
  };
48798
49057
  let validPersonData = defaultPersonData.filter(person => !sex || person.sex === sex);
49058
+ let nationalityCodes = [];
48799
49059
 
48800
49060
  if (Array.isArray(personData)) {
48801
49061
  const validatedPersonData = personData.filter(person => {
@@ -48806,6 +49066,7 @@ function generatePersons({
48806
49066
  iso,
48807
49067
  ioc
48808
49068
  }) => [iso, ioc].includes(person.nationalityCode)))) return false;
49069
+ if (person.nationalityCode) nationalityCodes.push(person.nationalityCode);
48809
49070
  return true;
48810
49071
  });
48811
49072
 
@@ -48890,7 +49151,8 @@ function generatePersons({
48890
49151
  }), person);
48891
49152
  });
48892
49153
  return {
48893
- persons: persons.length && persons || shuffledPersons[0]
49154
+ persons: persons.length && persons || shuffledPersons[0],
49155
+ nationalityCodes
48894
49156
  };
48895
49157
  }
48896
49158
 
@@ -50332,6 +50594,7 @@ function generateParticipants({
50332
50594
  const team = participantType === TEAM$1 || matchUpType === TEAM$1;
50333
50595
  const individualParticipantsCount = participantsCount * (doubles ? 2 : team ? 8 : 1);
50334
50596
  const {
50597
+ nationalityCodes: personNationalityCodes,
50335
50598
  persons: mockedPersons,
50336
50599
  error
50337
50600
  } = generatePersons({
@@ -50481,7 +50744,7 @@ function generateParticipants({
50481
50744
  const standardFamilyName = lastName || 'FamilyName';
50482
50745
  const participantName = `${standardGivenName} ${standardFamilyName}`;
50483
50746
  const country = countriesList[participantIndex];
50484
- const nationalityCode = country && (nationalityCodeType === 'ISO' ? country.iso : country.ioc || country.iso) || personNationalityCode;
50747
+ const nationalityCode = (personNationalityCodes === null || personNationalityCodes === void 0 ? void 0 : personNationalityCodes.length) && personNationalityCode || country && (nationalityCodeType === 'ISO' ? country.iso : country.ioc || country.iso) || personNationalityCode;
50485
50748
 
50486
50749
  if (countriesList !== null && countriesList !== void 0 && countriesList.length && !nationalityCode && !personNationalityCode) {
50487
50750
  console.log('%c Invalid Nationality Code', {
@@ -50513,7 +50776,7 @@ function generateParticipants({
50513
50776
  standardGivenName,
50514
50777
  nationalityCode,
50515
50778
  extensions,
50516
- birthDate,
50779
+ birthDate: isValidDateString(birthDate) ? birthDate : undefined,
50517
50780
  sex
50518
50781
  }
50519
50782
  });
@@ -51041,6 +51304,7 @@ function generateEventWithFlights({
51041
51304
  tournamentRecord,
51042
51305
  eventProfile,
51043
51306
  eventIndex,
51307
+ publish,
51044
51308
  uuids
51045
51309
  }) {
51046
51310
  let gender = eventProfile.gender;
@@ -51170,6 +51434,14 @@ function generateEventWithFlights({
51170
51434
  });
51171
51435
  if (result.error) return result;
51172
51436
  const drawIds = result.drawIds;
51437
+
51438
+ if (publish) {
51439
+ publishEvent({
51440
+ tournamentRecord,
51441
+ event
51442
+ });
51443
+ }
51444
+
51173
51445
  return {
51174
51446
  drawIds,
51175
51447
  eventId,
@@ -51198,6 +51470,7 @@ function generateEventWithDraw({
51198
51470
  excessParticipantAlternates = true,
51199
51471
  matchUpFormat = FORMAT_STANDARD,
51200
51472
  drawType = SINGLE_ELIMINATION,
51473
+ tournamentAlternates = 0,
51201
51474
  alternatesCount = 0,
51202
51475
  generate = true,
51203
51476
  eventExtensions,
@@ -51207,6 +51480,7 @@ function generateEventWithDraw({
51207
51480
  seedsCount,
51208
51481
  category,
51209
51482
  idPrefix,
51483
+ publish,
51210
51484
  gender,
51211
51485
  stage
51212
51486
  } = drawProfile;
@@ -51351,7 +51625,7 @@ function generateEventWithDraw({
51351
51625
 
51352
51626
  const alternatesParticipantIds = excessParticipantAlternates && (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : (_tournamentRecord$par = tournamentRecord.participants) === null || _tournamentRecord$par === void 0 ? void 0 : _tournamentRecord$par.filter(({
51353
51627
  participantId
51354
- }) => !participantIds.includes(participantId)).filter(isEventParticipantType).filter(isEventGender).slice(0, alternatesCount || drawSize - participantsCount).map(p => p.participantId));
51628
+ }) => !participantIds.includes(participantId)).filter(isEventParticipantType).filter(isEventGender).slice(0, alternatesCount || drawSize - participantsCount || tournamentAlternates).map(p => p.participantId));
51355
51629
 
51356
51630
  if (alternatesParticipantIds !== null && alternatesParticipantIds !== void 0 && alternatesParticipantIds.length) {
51357
51631
  const result = addEventEntries({
@@ -51539,6 +51813,13 @@ function generateEventWithDraw({
51539
51813
 
51540
51814
  }
51541
51815
  }
51816
+
51817
+ if (publish) {
51818
+ publishEvent({
51819
+ tournamentRecord,
51820
+ event
51821
+ });
51822
+ }
51542
51823
  }
51543
51824
 
51544
51825
  return { ...SUCCESS,