tods-competition-factory 1.6.22 → 1.6.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -362,7 +362,7 @@ var matchUpFormatCode = {
362
362
  };
363
363
 
364
364
  function factoryVersion() {
365
- return '1.6.22';
365
+ return '1.6.24';
366
366
  }
367
367
 
368
368
  /******************************************************************************
@@ -639,6 +639,9 @@ function shuffleArray(arr) {
639
639
  .sort(function (a, b) { return a[0] - b[0]; })
640
640
  .map(function (a) { return a[1]; });
641
641
  }
642
+ function numericSortValue(v) {
643
+ return isConvertableInteger(v) ? v : Infinity;
644
+ }
642
645
  // return an object whose attributes are values and whose values are counts for values
643
646
  // e.g. values=[1,2,2,3,4,4,5] produces { 1: 1, 2: 2, 3: 1, 4: 2, 5: 1}
644
647
  function instanceCount(values) {
@@ -4827,6 +4830,7 @@ var POLICY_TYPE_PARTICIPANT = 'participant';
4827
4830
  var POLICY_TYPE_PROGRESSION = 'progression';
4828
4831
  var POLICY_TYPE_SCHEDULING = 'scheduling';
4829
4832
  var POLICY_TYPE_AVOIDANCE = 'avoidance';
4833
+ var POLICY_TYPE_DISPLAY = 'display'; // storage for client type displays, e.g. { public: {}, admin: {} }
4830
4834
  var POLICY_TYPE_SCORING = 'scoring';
4831
4835
  var POLICY_TYPE_SEEDING = 'seeding';
4832
4836
  var POLICY_TYPE_FEED_IN = 'feedIn';
@@ -4844,6 +4848,7 @@ var policyConstants = {
4844
4848
  POLICY_TYPE_PROGRESSION: POLICY_TYPE_PROGRESSION,
4845
4849
  POLICY_TYPE_SCHEDULING: POLICY_TYPE_SCHEDULING,
4846
4850
  POLICY_TYPE_AVOIDANCE: POLICY_TYPE_AVOIDANCE,
4851
+ POLICY_TYPE_DISPLAY: POLICY_TYPE_DISPLAY,
4847
4852
  POLICY_TYPE_FEED_IN: POLICY_TYPE_FEED_IN,
4848
4853
  POLICY_TYPE_SCORING: POLICY_TYPE_SCORING,
4849
4854
  POLICY_TYPE_SEEDING: POLICY_TYPE_SEEDING,
@@ -10625,15 +10630,15 @@ function targetByRoundOutcome(_a) {
10625
10630
  matchUp: matchUp,
10626
10631
  targetLinks: { loserTargetLink: loserTargetLink, winnerTargetLink: winnerTargetLink, byeTargetLink: byeTargetLink },
10627
10632
  targetMatchUps: {
10628
- byeMatchUp: byeMatchUp,
10629
- loserMatchUp: loserMatchUp,
10630
- winnerMatchUp: winnerMatchUp,
10631
- byeTargetDrawPosition: byeTargetDrawPosition,
10632
- loserTargetDrawPosition: loserTargetDrawPosition,
10633
- winnerTargetDrawPosition: winnerTargetDrawPosition,
10634
- byeMatchUpDrawPositionIndex: byeMatchUpDrawPositionIndex,
10635
- loserMatchUpDrawPositionIndex: loserMatchUpDrawPositionIndex,
10636
10633
  winnerMatchUpDrawPositionIndex: winnerMatchUpDrawPositionIndex,
10634
+ loserMatchUpDrawPositionIndex: loserMatchUpDrawPositionIndex,
10635
+ byeMatchUpDrawPositionIndex: byeMatchUpDrawPositionIndex,
10636
+ winnerTargetDrawPosition: winnerTargetDrawPosition,
10637
+ loserTargetDrawPosition: loserTargetDrawPosition,
10638
+ byeTargetDrawPosition: byeTargetDrawPosition,
10639
+ winnerMatchUp: winnerMatchUp,
10640
+ loserMatchUp: loserMatchUp,
10641
+ byeMatchUp: byeMatchUp,
10637
10642
  },
10638
10643
  targetMatchUpIds: !!(winnerMatchUpId || loserMatchUpId),
10639
10644
  });
@@ -10641,9 +10646,9 @@ function targetByRoundOutcome(_a) {
10641
10646
  function targetByWinRatio(_a) {
10642
10647
  var matchUp = _a.matchUp;
10643
10648
  return {
10644
- matchUp: matchUp,
10645
10649
  targetLinks: { loserTargetLink: undefined, winnerTargetLink: undefined },
10646
10650
  targetMatchUps: { loserMatchUp: undefined, winnerMatchUp: undefined },
10651
+ matchUp: matchUp,
10647
10652
  };
10648
10653
  }
10649
10654
 
@@ -39197,7 +39202,7 @@ function addCourts$1(_a) {
39197
39202
 
39198
39203
  function modifyVenue$1(_a) {
39199
39204
  var e_1, _b;
39200
- var _c, _d, _e, _f;
39205
+ var _c, _d, _e, _f, _g;
39201
39206
  var tournamentRecord = _a.tournamentRecord, modifications = _a.modifications, venueId = _a.venueId, force = _a.force;
39202
39207
  if (!tournamentRecord)
39203
39208
  return { error: MISSING_TOURNAMENT_RECORD };
@@ -39225,25 +39230,25 @@ function modifyVenue$1(_a) {
39225
39230
  var _a;
39226
39231
  return Object.assign(venue, (_a = {}, _a[attribute] = modifications[attribute], _a));
39227
39232
  });
39228
- var existingCourtIds = ((_c = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _c === void 0 ? void 0 : _c.map(function (court) { return court.courtId; })) || [];
39229
- var courtIdsToModify = ((_d = modifications.courts) === null || _d === void 0 ? void 0 : _d.map(function (court) { return court.courtId; })) || [];
39233
+ var existingCourtIds = (_d = (_c = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _c === void 0 ? void 0 : _c.map(function (court) { return court.courtId; })) !== null && _d !== void 0 ? _d : [];
39234
+ var courtIdsToModify = ((_e = modifications.courts) === null || _e === void 0 ? void 0 : _e.map(function (court) { return court.courtId; })) || [];
39230
39235
  var courtIdsToDelete = existingCourtIds.filter(function (courtId) { return !courtIdsToModify.includes(courtId); });
39231
39236
  if (courtIdsToDelete.length) {
39232
- var courtsToDelete = (_e = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _e === void 0 ? void 0 : _e.filter(function (court) {
39237
+ var courtsToDelete = (_f = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _f === void 0 ? void 0 : _f.filter(function (court) {
39233
39238
  return courtIdsToDelete.includes(court.courtId);
39234
39239
  });
39235
39240
  var scheduleDeletionsCount = courtsToDelete === null || courtsToDelete === void 0 ? void 0 : courtsToDelete.map(function (court) {
39236
- var _a;
39241
+ var _a, _b;
39237
39242
  // check whether deleting court would remove schedule from any matchUps
39238
39243
  var result = getScheduledCourtMatchUps({
39239
39244
  courtId: court.courtId,
39240
39245
  tournamentRecord: tournamentRecord,
39241
39246
  venueMatchUps: venueMatchUps,
39242
39247
  });
39243
- return ((_a = result.matchUps) === null || _a === void 0 ? void 0 : _a.length) || 0;
39248
+ return (_b = (_a = result.matchUps) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
39244
39249
  }).reduce(function (a, b) { return a + b; });
39245
39250
  if (venue && (!scheduleDeletionsCount || force)) {
39246
- venue.courts = (_f = venue.courts) === null || _f === void 0 ? void 0 : _f.filter(function (court) {
39251
+ venue.courts = (_g = venue.courts) === null || _g === void 0 ? void 0 : _g.filter(function (court) {
39247
39252
  return courtIdsToModify.includes(court.courtId);
39248
39253
  });
39249
39254
  }
@@ -39255,8 +39260,8 @@ function modifyVenue$1(_a) {
39255
39260
  }
39256
39261
  if (modifications.courts) {
39257
39262
  try {
39258
- for (var _g = __values(modifications.courts), _h = _g.next(); !_h.done; _h = _g.next()) {
39259
- var court = _h.value;
39263
+ for (var _h = __values(modifications.courts), _j = _h.next(); !_j.done; _j = _h.next()) {
39264
+ var court = _j.value;
39260
39265
  var courtId = (court || {}).courtId;
39261
39266
  var result_1 = modifyCourt$1({
39262
39267
  modifications: court,
@@ -39281,7 +39286,7 @@ function modifyVenue$1(_a) {
39281
39286
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
39282
39287
  finally {
39283
39288
  try {
39284
- if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
39289
+ if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
39285
39290
  }
39286
39291
  finally { if (e_1) throw e_1.error; }
39287
39292
  }
@@ -44836,6 +44841,30 @@ function generateAndPopulatePlayoffStructures(params) {
44836
44841
  if (result.error)
44837
44842
  console.log(result.error);
44838
44843
  });
44844
+ var byeMatchUps = inContextDrawMatchUps === null || inContextDrawMatchUps === void 0 ? void 0 : inContextDrawMatchUps.filter(function (matchUp) {
44845
+ return matchUp.matchUpStatus === BYE && matchUp.structureId === sourceStructureId;
44846
+ });
44847
+ byeMatchUps === null || byeMatchUps === void 0 ? void 0 : byeMatchUps.forEach(function (matchUp) {
44848
+ var matchUpId = matchUp.matchUpId;
44849
+ var targetData = positionTargets({
44850
+ inContextDrawMatchUps: inContextDrawMatchUps,
44851
+ drawDefinition: drawDefinition,
44852
+ matchUpId: matchUpId,
44853
+ });
44854
+ var loserTargetLink = targetData.targetLinks.loserTargetLink, _a = targetData.targetMatchUps, loserMatchUpDrawPositionIndex = _a.loserMatchUpDrawPositionIndex, // only present when positionTargets found without loserMatchUpId
44855
+ loserMatchUp = _a.loserMatchUp;
44856
+ var targetStructureId = loserTargetLink.target.structureId;
44857
+ var targetDrawPosition = loserMatchUp.drawPositions[loserMatchUpDrawPositionIndex];
44858
+ var result = assignDrawPositionBye$1({
44859
+ drawPosition: targetDrawPosition,
44860
+ structureId: targetStructureId,
44861
+ tournamentRecord: tournamentRecord,
44862
+ drawDefinition: drawDefinition,
44863
+ event: event,
44864
+ });
44865
+ if (result.error)
44866
+ console.log(result.error);
44867
+ });
44839
44868
  // the matchUps in the source structure must have goesTo details added
44840
44869
  var matchUpModifications = [];
44841
44870
  var goesToMap = addGoesTo({
@@ -45424,7 +45453,7 @@ function attachStructures$1(_a) {
45424
45453
  if (!drawDefinition)
45425
45454
  return { error: MISSING_DRAW_DEFINITION };
45426
45455
  if (!Array.isArray(structures) || !Array.isArray(links))
45427
- return { error: INVALID_VALUES };
45456
+ return decorateResult({ result: { error: INVALID_VALUES } });
45428
45457
  var stack = 'attachStructures';
45429
45458
  var linkHash = function (link) {
45430
45459
  var _a;
@@ -45636,6 +45665,29 @@ function deleteAdHocMatchUps$1(_a) {
45636
45665
  return __assign({}, SUCCESS);
45637
45666
  }
45638
45667
 
45668
+ function setStructureOrder(_a) {
45669
+ var drawDefinition = _a.drawDefinition, orderMap = _a.orderMap;
45670
+ if (!drawDefinition)
45671
+ return { error: MISSING_DRAW_DEFINITION };
45672
+ if (typeof orderMap !== 'object' ||
45673
+ !Object.values(orderMap).every(function (val) { return isConvertableInteger(val); }))
45674
+ decorateResult({
45675
+ result: { error: INVALID_VALUES },
45676
+ context: { orderMap: orderMap },
45677
+ });
45678
+ if (!drawDefinition.structures)
45679
+ drawDefinition.structures = [];
45680
+ drawDefinition.structures.forEach(function (structure) {
45681
+ var structureOrder = orderMap[structure.structureId];
45682
+ if (structureOrder)
45683
+ structure.structureOrder = structureOrder;
45684
+ });
45685
+ drawDefinition.structures.sort(function (a, b) {
45686
+ return numericSortValue(a.structureOrder) - numericSortValue(b.structureOrder);
45687
+ });
45688
+ return __assign({}, SUCCESS);
45689
+ }
45690
+
45639
45691
  function renameStructures$1(_a) {
45640
45692
  var e_1, _b;
45641
45693
  var drawDefinition = _a.drawDefinition, structureDetails = _a.structureDetails;
@@ -45905,6 +45957,7 @@ var structureGovernor = {
45905
45957
  generateAndPopulatePlayoffStructures: generateAndPopulatePlayoffStructures,
45906
45958
  attachPlayoffStructures: attachPlayoffStructures$1,
45907
45959
  addPlayoffStructures: addPlayoffStructures$1,
45960
+ setStructureOrder: setStructureOrder,
45908
45961
  renameStructures: renameStructures$1,
45909
45962
  generateQualifyingStructure: generateQualifyingStructure$1,
45910
45963
  attachQualifyingStructure: attachQualifyingStructure$1,
@@ -48119,11 +48172,15 @@ function eliminationSwap(_a) {
48119
48172
  return qualifier;
48120
48173
  }).length === 2)
48121
48174
  return __assign({}, SUCCESS);
48175
+ var isQualifierSwap = assignments.some(function (_a) {
48176
+ var qualifier = _a.qualifier;
48177
+ return qualifier;
48178
+ });
48122
48179
  var isByeSwap = assignments.some(function (_a) {
48123
48180
  var bye = _a.bye;
48124
48181
  return bye;
48125
48182
  });
48126
- if (isByeSwap) {
48183
+ if (isByeSwap && !isQualifierSwap) {
48127
48184
  return swapParticipantIdWithBYE({
48128
48185
  inContextDrawMatchUps: inContextDrawMatchUps,
48129
48186
  tournamentRecord: tournamentRecord,
@@ -48135,7 +48192,7 @@ function eliminationSwap(_a) {
48135
48192
  });
48136
48193
  }
48137
48194
  else {
48138
- return eliminationParticipantSwap({
48195
+ return eliminationPosiitonSwap({
48139
48196
  inContextDrawMatchUps: inContextDrawMatchUps,
48140
48197
  tournamentRecord: tournamentRecord,
48141
48198
  drawDefinition: drawDefinition,
@@ -48204,7 +48261,7 @@ function swapParticipantIdWithBYE(_a) {
48204
48261
  return result;
48205
48262
  return __assign({}, SUCCESS);
48206
48263
  }
48207
- function eliminationParticipantSwap(_a) {
48264
+ function eliminationPosiitonSwap(_a) {
48208
48265
  var inContextDrawMatchUps = _a.inContextDrawMatchUps, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, assignments = _a.assignments, matchUpsMap = _a.matchUpsMap, structure = _a.structure, event = _a.event;
48209
48266
  // preserves order of drawPositions in original positionAssignments array
48210
48267
  // while insuring that all attributes are faithfully copied over and only drawPosition is swapped
@@ -48256,11 +48313,15 @@ function roundRobinSwap(_a) {
48256
48313
  structure: structure,
48257
48314
  event: event,
48258
48315
  });
48316
+ var isQualifierSwap = assignments.some(function (_a) {
48317
+ var qualifier = _a.qualifier;
48318
+ return qualifier;
48319
+ });
48259
48320
  var isByeSwap = assignments.some(function (_a) {
48260
48321
  var bye = _a.bye;
48261
48322
  return bye;
48262
48323
  });
48263
- if (isByeSwap) {
48324
+ if (isByeSwap && !isQualifierSwap) {
48264
48325
  swapParticipantIdWithBYE({
48265
48326
  inContextDrawMatchUps: inContextDrawMatchUps,
48266
48327
  tournamentRecord: tournamentRecord,
@@ -48517,12 +48578,22 @@ var DEFAULT_RATING = 0;
48517
48578
  var MAX_ITERATIONS = 5000;
48518
48579
  function generateDrawMaticRound(_a) {
48519
48580
  var e_1, _b, e_2, _c, e_3, _d;
48520
- var _e = _a.maxIterations, maxIterations = _e === void 0 ? MAX_ITERATIONS : _e, _f = _a.generateMatchUps, generateMatchUps = _f === void 0 ? true : _f, tournamentParticipants = _a.tournamentParticipants, tournamentRecord = _a.tournamentRecord, participantIds = _a.participantIds, addToStructure = _a.addToStructure, drawDefinition = _a.drawDefinition, adHocRatings = _a.adHocRatings, structureId = _a.structureId, matchUpIds = _a.matchUpIds, eventType = _a.eventType, structure = _a.structure;
48581
+ var _e, _f;
48582
+ var _g = _a.maxIterations, maxIterations = _g === void 0 ? MAX_ITERATIONS : _g, _h = _a.generateMatchUps, generateMatchUps = _h === void 0 ? true : _h, tournamentParticipants = _a.tournamentParticipants, tournamentRecord = _a.tournamentRecord, participantIds = _a.participantIds, addToStructure = _a.addToStructure, drawDefinition = _a.drawDefinition, adHocRatings = _a.adHocRatings, structureId = _a.structureId, matchUpIds = _a.matchUpIds, eventType = _a.eventType, structure = _a.structure;
48583
+ if (!drawDefinition)
48584
+ return { error: MISSING_DRAW_DEFINITION };
48585
+ if (!structure && !structureId)
48586
+ return { error: STRUCTURE_NOT_FOUND };
48587
+ if (!structure) {
48588
+ structure = findStructure({ drawDefinition: drawDefinition, structureId: structureId }).structure;
48589
+ }
48590
+ if (!isObject(structure))
48591
+ return { error: MISSING_STRUCTURE };
48521
48592
  if (!(participantIds === null || participantIds === void 0 ? void 0 : participantIds.length)) {
48522
48593
  return { error: MISSING_PARTICIPANT_IDS };
48523
48594
  }
48524
48595
  // create valueObject for each previous encounter within the structure
48525
- var encounters = getEncounters({ matchUps: structure.matchUps }).encounters;
48596
+ var encounters = getEncounters({ matchUps: (_e = structure === null || structure === void 0 ? void 0 : structure.matchUps) !== null && _e !== void 0 ? _e : [] }).encounters;
48526
48597
  // valueObjects provide "weighting" to each possible pairing of participants
48527
48598
  // {
48528
48599
  // 'P-I-0|P-I-1': 1,
@@ -48554,7 +48625,7 @@ function generateDrawMaticRound(_a) {
48554
48625
  // add SAME_TEAM_VALUE for participants who appear on the same team
48555
48626
  for (var teamParticipants_1 = __values(teamParticipants), teamParticipants_1_1 = teamParticipants_1.next(); !teamParticipants_1_1.done; teamParticipants_1_1 = teamParticipants_1.next()) {
48556
48627
  var teamParticipant = teamParticipants_1_1.value;
48557
- var participantIds_1 = teamParticipant.individualParticipantIds || [];
48628
+ var participantIds_1 = (_f = teamParticipant.individualParticipantIds) !== null && _f !== void 0 ? _f : [];
48558
48629
  var uniquePairings_2 = getPairingsData({ participantIds: participantIds_1 }).uniquePairings;
48559
48630
  try {
48560
48631
  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()) {
@@ -48587,9 +48658,9 @@ function generateDrawMaticRound(_a) {
48587
48658
  // 'P-I-0|P-I-2': 0,
48588
48659
  // 'P-I-0|P-I-3': 0
48589
48660
  // }
48590
- var _g = getPairingsData({
48661
+ var _j = getPairingsData({
48591
48662
  participantIds: participantIds,
48592
- }), uniquePairings = _g.uniquePairings, possiblePairings = _g.possiblePairings, deltaObjects = _g.deltaObjects;
48663
+ }), uniquePairings = _j.uniquePairings, possiblePairings = _j.possiblePairings, deltaObjects = _j.deltaObjects;
48593
48664
  var params = {
48594
48665
  tournamentParticipants: tournamentParticipants,
48595
48666
  possiblePairings: possiblePairings,
@@ -48603,18 +48674,18 @@ function generateDrawMaticRound(_a) {
48603
48674
  eventType: eventType,
48604
48675
  structure: structure,
48605
48676
  };
48606
- var _h = getPairings(params), candidatesCount = _h.candidatesCount, participantIdPairings = _h.participantIdPairings, iterations = _h.iterations;
48677
+ var _k = getPairings(params), candidatesCount = _k.candidatesCount, participantIdPairings = _k.participantIdPairings, iterations = _k.iterations;
48607
48678
  if (!candidatesCount)
48608
48679
  return { error: NO_CANDIDATES };
48609
48680
  var matchUps;
48610
48681
  if (generateMatchUps) {
48611
48682
  var result = generateAdHocMatchUps$1({
48683
+ structureId: structure === null || structure === void 0 ? void 0 : structure.structureId,
48612
48684
  participantIdPairings: participantIdPairings,
48613
48685
  tournamentRecord: tournamentRecord,
48614
48686
  addToStructure: addToStructure,
48615
48687
  newRound: true,
48616
48688
  drawDefinition: drawDefinition,
48617
- structureId: structureId,
48618
48689
  matchUpIds: matchUpIds,
48619
48690
  });
48620
48691
  if (result.error)
@@ -48759,8 +48830,8 @@ function getParticipantPairingValues(_a) {
48759
48830
 
48760
48831
  function drawMatic$1(_a) {
48761
48832
  var e_1, _b;
48762
- var _c, _d, _e, _f;
48763
- var tournamentParticipants = _a.tournamentParticipants, restrictEntryStatus = _a.restrictEntryStatus, tournamentRecord = _a.tournamentRecord, generateMatchUps = _a.generateMatchUps, addToStructure = _a.addToStructure, participantIds = _a.participantIds, drawDefinition = _a.drawDefinition, maxIterations = _a.maxIterations, structureId = _a.structureId, matchUpIds = _a.matchUpIds, scaleName = _a.scaleName, // custom rating name to seed dynamic ratings
48833
+ var _c, _d, _e, _f, _g;
48834
+ var tournamentParticipants = _a.tournamentParticipants, restrictEntryStatus = _a.restrictEntryStatus, tournamentRecord = _a.tournamentRecord, generateMatchUps = _a.generateMatchUps, addToStructure = _a.addToStructure, participantIds = _a.participantIds, drawDefinition = _a.drawDefinition, scaleAccessor = _a.scaleAccessor, maxIterations = _a.maxIterations, structureId = _a.structureId, matchUpIds = _a.matchUpIds, scaleName = _a.scaleName, // custom rating name to seed dynamic ratings
48764
48835
  eventType = _a.eventType, event = _a.event;
48765
48836
  if (typeof drawDefinition !== 'object' ||
48766
48837
  (drawDefinition.drawType && drawDefinition.drawType !== AD_HOC)) {
@@ -48808,6 +48879,8 @@ function drawMatic$1(_a) {
48808
48879
  var structureIsAdHoc = isAdHoc({ drawDefinition: drawDefinition, structure: structure });
48809
48880
  if (!structureIsAdHoc)
48810
48881
  return { error: INVALID_DRAW_DEFINITION };
48882
+ tournamentParticipants =
48883
+ (_g = tournamentParticipants !== null && tournamentParticipants !== void 0 ? tournamentParticipants : tournamentRecord.participants) !== null && _g !== void 0 ? _g : [];
48811
48884
  var adHocRatings = {};
48812
48885
  var _loop_1 = function (participantId) {
48813
48886
  var participant = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.find(function (participant) { return participant.participantId === participantId; });
@@ -48815,24 +48888,31 @@ function drawMatic$1(_a) {
48815
48888
  var scaleValue = getScaleValue({ eventType: eventType, participant: participant });
48816
48889
  // if no dynamic value found and a seeding scaleValue is provided...
48817
48890
  if (!scaleValue && scaleName) {
48818
- scaleValue = getScaleValue({ scaleName: scaleName, eventType: eventType, participant: participant });
48891
+ scaleValue = getScaleValue({
48892
+ scaleAccessor: scaleAccessor,
48893
+ participant: participant,
48894
+ scaleName: scaleName,
48895
+ eventType: eventType,
48896
+ });
48819
48897
  }
48820
48898
  if (scaleValue)
48821
48899
  adHocRatings[participantId] = scaleValue;
48822
48900
  };
48823
48901
  try {
48824
- for (var _g = __values(participantIds !== null && participantIds !== void 0 ? participantIds : []), _h = _g.next(); !_h.done; _h = _g.next()) {
48825
- var participantId = _h.value;
48902
+ for (var _h = __values(participantIds !== null && participantIds !== void 0 ? participantIds : []), _j = _h.next(); !_j.done; _j = _h.next()) {
48903
+ var participantId = _j.value;
48826
48904
  _loop_1(participantId);
48827
48905
  }
48828
48906
  }
48829
48907
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
48830
48908
  finally {
48831
48909
  try {
48832
- if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
48910
+ if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
48833
48911
  }
48834
48912
  finally { if (e_1) throw e_1.error; }
48835
48913
  }
48914
+ // TODO: update dynamic ratings based on matchUps present from last played round
48915
+ // use scaleEngine.processMatchUps(); see dynamicCalculations.test.ts
48836
48916
  return generateDrawMaticRound({
48837
48917
  tournamentParticipants: tournamentParticipants,
48838
48918
  tournamentRecord: tournamentRecord,
@@ -48842,7 +48922,6 @@ function drawMatic$1(_a) {
48842
48922
  drawDefinition: drawDefinition,
48843
48923
  maxIterations: maxIterations,
48844
48924
  adHocRatings: adHocRatings,
48845
- structureId: structureId,
48846
48925
  matchUpIds: matchUpIds,
48847
48926
  structure: structure,
48848
48927
  eventType: eventType,
@@ -48850,7 +48929,7 @@ function drawMatic$1(_a) {
48850
48929
  }
48851
48930
  function getScaleValue(_a) {
48852
48931
  var _b;
48853
- var _c = _a.scaleName, scaleName = _c === void 0 ? 'dynamic' : _c, eventType = _a.eventType, participant = _a.participant;
48932
+ var _c = _a.eventType, eventType = _c === void 0 ? TypeEnum.Singles : _c, _d = _a.scaleName, scaleName = _d === void 0 ? 'dynamic' : _d, scaleAccessor = _a.scaleAccessor, participant = _a.participant;
48854
48933
  var scaleAttributes = {
48855
48934
  eventType: eventType || TypeEnum.Singles,
48856
48935
  scaleType: RATING$2,
@@ -48861,7 +48940,10 @@ function getScaleValue(_a) {
48861
48940
  scaleAttributes: scaleAttributes,
48862
48941
  participant: participant,
48863
48942
  });
48864
- return (_b = result === null || result === void 0 ? void 0 : result.scaleItem) === null || _b === void 0 ? void 0 : _b.scaleValue;
48943
+ var scaleValue = (_b = result === null || result === void 0 ? void 0 : result.scaleItem) === null || _b === void 0 ? void 0 : _b.scaleValue;
48944
+ return scaleAccessor && isObject(scaleValue)
48945
+ ? scaleValue[scaleAccessor]
48946
+ : scaleValue;
48865
48947
  }
48866
48948
 
48867
48949
  function setDelegatedOutcome$1(_a) {
@@ -51194,13 +51276,19 @@ function getOrderedTieFormat(_a) {
51194
51276
  if (collectionOrder)
51195
51277
  collectionDefinition.collectionOrder = collectionOrder;
51196
51278
  });
51197
- orderedTieFormat.collectionDefinitions.sort(function (a, b) { return a.collectionOrder - b.collectionOrder; });
51279
+ orderedTieFormat.collectionDefinitions.sort(function (a, b) {
51280
+ return numericSortValue(a.collectionOrder) - numericSortValue(b.collectionOrder);
51281
+ });
51198
51282
  return orderedTieFormat;
51199
51283
  }
51200
51284
  function orderCollectionDefinitions(_a) {
51201
51285
  var tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, structureId = _a.structureId, matchUpId = _a.matchUpId, orderMap = _a.orderMap, eventId = _a.eventId, matchUp = _a.matchUp, event = _a.event;
51202
- if (typeof orderMap !== 'object')
51203
- return { error: INVALID_VALUES, orderMap: orderMap };
51286
+ if (typeof orderMap !== 'object' ||
51287
+ !Object.values(orderMap).every(function (val) { return isConvertableInteger(val); }))
51288
+ return decorateResult({
51289
+ result: { error: INVALID_VALUES },
51290
+ context: { orderMap: orderMap },
51291
+ });
51204
51292
  if (eventId && (event === null || event === void 0 ? void 0 : event.tieFormat)) {
51205
51293
  updateEventTieFormat({ tournamentRecord: tournamentRecord, event: event, orderMap: orderMap });
51206
51294
  }
@@ -52839,7 +52927,8 @@ function modifyTieFormat(_a) {
52839
52927
  processedTieFormat.collectionDefinitions =
52840
52928
  processedTieFormat.collectionDefinitions
52841
52929
  .sort(function (a, b) {
52842
- return (a.collectionOrder || Infinity) - (b.collectionOrder || Infinity);
52930
+ return numericSortValue(a.collectionOrder) -
52931
+ numericSortValue(b.collectionOrder);
52843
52932
  })
52844
52933
  .map(function (def, i) { return (__assign(__assign({}, def), { collectionOrder: i + 1 })); });
52845
52934
  return __assign(__assign({}, SUCCESS), { processedTieFormat: processedTieFormat });
@@ -58760,19 +58849,29 @@ function removeTieMatchUpParticipantId(params) {
58760
58849
  }
58761
58850
 
58762
58851
  function getPositionAssignments(_a) {
58763
- var tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, structureId = _a.structureId, structure = _a.structure;
58852
+ var _b;
58853
+ var tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, _c = _a.stage, stage = _c === void 0 ? MAIN : _c, structureId = _a.structureId, structure = _a.structure;
58764
58854
  if (!tournamentRecord)
58765
58855
  return { error: MISSING_TOURNAMENT_RECORD };
58766
58856
  if (!structure && !drawDefinition)
58767
58857
  return { error: MISSING_DRAW_DEFINITION };
58858
+ if (!structure &&
58859
+ !structureId &&
58860
+ ((_b = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) === null || _b === void 0 ? void 0 : _b.filter(function (structure) { return structure.stage === stage; }).length) === 1) {
58861
+ structure = drawDefinition.structures.find(function (structure) { return structure.stage === stage; });
58862
+ }
58768
58863
  if (!structure && !structureId)
58769
58864
  return { error: MISSING_STRUCTURE_ID };
58770
- var _b = getPositionAssignments$1({
58865
+ var _d = getPositionAssignments$1({
58771
58866
  drawDefinition: drawDefinition,
58772
58867
  structureId: structureId,
58773
58868
  structure: structure,
58774
- }), error = _b.error, assignments = _b.positionAssignments;
58775
- return { error: error, positionAssignments: assignments || [] };
58869
+ }), error = _d.error, assignments = _d.positionAssignments;
58870
+ return {
58871
+ error: error,
58872
+ positionAssignments: assignments || [],
58873
+ structureId: structure === null || structure === void 0 ? void 0 : structure.structureId,
58874
+ };
58776
58875
  }
58777
58876
 
58778
58877
  function deleteDrawDefinitions(_a) {
@@ -61811,12 +61910,13 @@ function addVoluntaryConsolationStructure(params) {
61811
61910
  }
61812
61911
 
61813
61912
  function prepareStage(params) {
61913
+ var _a;
61814
61914
  var seedsCount = params.seedsCount;
61815
61915
  var preparedStructureIds = params.preparedStructureIds || [];
61816
- var provisionalPositioning = params.provisionalPositioning, inContextDrawMatchUps = params.inContextDrawMatchUps, tournamentRecord = params.tournamentRecord, appliedPolicies = params.appliedPolicies, qualifyingOnly = params.qualifyingOnly, drawDefinition = params.drawDefinition, seedingProfile = params.seedingProfile, participants = params.participants, matchUpsMap = params.matchUpsMap, automated = params.automated, placeByes = params.placeByes, drawType = params.drawType, drawSize = params.drawSize, entries = params.entries, event = params.event, _a = params.enforcePolicyLimits, enforcePolicyLimits = _a === void 0 ? true : _a, seedAssignmentProfile = params.seedAssignmentProfile, // mainly used by mocksEngine for scenario testing
61817
- _b = params.seedByRanking, // mainly used by mocksEngine for scenario testing
61818
- seedByRanking = _b === void 0 ? true : _b, seededParticipants = params.seededParticipants, assignSeedsCount = params.assignSeedsCount, // used for testing bye placement next to seeds
61819
- seedingScaleName = params.seedingScaleName, _c = params.stageSequence, stageSequence = _c === void 0 ? 1 : _c, roundTarget = params.roundTarget, stage = params.stage;
61916
+ var provisionalPositioning = params.provisionalPositioning, inContextDrawMatchUps = params.inContextDrawMatchUps, tournamentRecord = params.tournamentRecord, appliedPolicies = params.appliedPolicies, qualifyingOnly = params.qualifyingOnly, drawDefinition = params.drawDefinition, seedingProfile = params.seedingProfile, participants = params.participants, matchUpsMap = params.matchUpsMap, automated = params.automated, placeByes = params.placeByes, drawType = params.drawType, drawSize = params.drawSize, entries = params.entries, event = params.event, _b = params.enforcePolicyLimits, enforcePolicyLimits = _b === void 0 ? true : _b, seedAssignmentProfile = params.seedAssignmentProfile, // mainly used by mocksEngine for scenario testing
61917
+ _c = params.seedByRanking, // mainly used by mocksEngine for scenario testing
61918
+ seedByRanking = _c === void 0 ? true : _c, seededParticipants = params.seededParticipants, assignSeedsCount = params.assignSeedsCount, // used for testing bye placement next to seeds
61919
+ seedingScaleName = params.seedingScaleName, _d = params.stageSequence, stageSequence = _d === void 0 ? 1 : _d, roundTarget = params.roundTarget, stage = params.stage;
61820
61920
  var eventType = event === null || event === void 0 ? void 0 : event.eventType;
61821
61921
  var stageEntries = entries.filter(function (entry) {
61822
61922
  var _a, _b;
@@ -61906,7 +62006,7 @@ function prepareStage(params) {
61906
62006
  }
61907
62007
  else if (event || seedingScaleName) {
61908
62008
  // if no seededParticipants have been defined, seed by seeding scale or ranking scale, if present
61909
- var _d = (event === null || event === void 0 ? void 0 : event.category) || {}, categoryName = _d.categoryName, ageCategoryCode = _d.ageCategoryCode;
62009
+ var _e = (event === null || event === void 0 ? void 0 : event.category) || {}, categoryName = _e.categoryName, ageCategoryCode = _e.ageCategoryCode;
61910
62010
  var seedingScaleAttributes = {
61911
62011
  scaleType: SEEDING$1,
61912
62012
  scaleName: seedingScaleName || categoryName || ageCategoryCode || event.eventId,
@@ -61933,7 +62033,7 @@ function prepareStage(params) {
61933
62033
  stage: stage,
61934
62034
  }).scaledEntries);
61935
62035
  }
61936
- var scaledEntriesCount = (scaledEntries === null || scaledEntries === void 0 ? void 0 : scaledEntries.length) || 0;
62036
+ var scaledEntriesCount = (_a = scaledEntries === null || scaledEntries === void 0 ? void 0 : scaledEntries.length) !== null && _a !== void 0 ? _a : 0;
61937
62037
  if (scaledEntriesCount < seedsCount)
61938
62038
  seedsCount = scaledEntriesCount;
61939
62039
  scaledEntries === null || scaledEntries === void 0 ? void 0 : scaledEntries.filter(function (_a) {
@@ -62368,13 +62468,21 @@ function generateDrawDefinition(params) {
62368
62468
  var participantIds_1 = entries_2 === null || entries_2 === void 0 ? void 0 : entries_2.map(extractAttributes('participantId'));
62369
62469
  var matchUpsCount_1 = entries_2 ? Math.floor(entries_2.length / 2) : 0;
62370
62470
  generateRange(1, params.roundsCount + 1).forEach(function () {
62471
+ var _a, _b, _c;
62371
62472
  if (params.automated) {
62473
+ var _d = (_a = params.drawMatic) !== null && _a !== void 0 ? _a : {}, restrictEntryStatus = _d.restrictEntryStatus, generateMatchUps = _d.generateMatchUps, addToStructure = _d.addToStructure, maxIterations = _d.maxIterations, structureId_1 = _d.structureId, matchUpIds = _d.matchUpIds, scaleName = _d.scaleName;
62372
62474
  drawMatic$1({
62373
- generateMatchUps: true,
62374
- eventType: matchUpType,
62375
62475
  tournamentRecord: tournamentRecord,
62376
62476
  participantIds: participantIds_1,
62377
62477
  drawDefinition: drawDefinition,
62478
+ eventType: (_c = (_b = params.drawMatic) === null || _b === void 0 ? void 0 : _b.eventType) !== null && _c !== void 0 ? _c : matchUpType,
62479
+ generateMatchUps: generateMatchUps !== null && generateMatchUps !== void 0 ? generateMatchUps : true,
62480
+ restrictEntryStatus: restrictEntryStatus,
62481
+ addToStructure: addToStructure,
62482
+ maxIterations: maxIterations,
62483
+ structureId: structureId_1,
62484
+ matchUpIds: matchUpIds,
62485
+ scaleName: scaleName,
62378
62486
  });
62379
62487
  }
62380
62488
  else {
@@ -62478,6 +62586,12 @@ function renameStructures(params) {
62478
62586
  return renameStructures$1(params);
62479
62587
  }
62480
62588
 
62589
+ function resetMatchUpLineUps(params) {
62590
+ if (!params.tournamentRecord)
62591
+ return { error: MISSING_TOURNAMENT_RECORD };
62592
+ return resetMatchUpLineUps$1(params);
62593
+ }
62594
+
62481
62595
  function aggregateTieFormats(_a) {
62482
62596
  var e_1, _b;
62483
62597
  var _c, _d, _e, _f, _g;
@@ -62653,18 +62767,13 @@ function enableTieAutoCalc(params) {
62653
62767
  return enableTieAutoCalc$1(params);
62654
62768
  }
62655
62769
 
62656
- function resetMatchUpLineUps(params) {
62657
- if (!params.tournamentRecord)
62658
- return { error: MISSING_TOURNAMENT_RECORD };
62659
- return resetMatchUpLineUps$1(params);
62660
- }
62661
-
62662
62770
  var eventGovernor = {
62663
62771
  generateQualifyingStructure: generateQualifyingStructure,
62664
62772
  attachQualifyingStructure: attachQualifyingStructure,
62665
62773
  attachPlayoffStructures: attachPlayoffStructures,
62666
- attachStructures: attachStructures,
62667
62774
  addQualifyingStructure: addQualifyingStructure,
62775
+ setStructureOrder: setStructureOrder,
62776
+ attachStructures: attachStructures,
62668
62777
  renameStructures: renameStructures,
62669
62778
  disableTieAutoCalc: disableTieAutoCalc,
62670
62779
  enableTieAutoCalc: enableTieAutoCalc,
@@ -62763,9 +62872,10 @@ var eventGovernor = {
62763
62872
  checkOutParticipant: checkOutParticipant,
62764
62873
  toggleParticipantCheckInState: toggleParticipantCheckInState$1,
62765
62874
  addDrawDefinitionTimeItem: addDrawDefinitionTimeItem,
62766
- generateDrawDefinition: generateDrawDefinition,
62767
- generateDrawStructuresAndLinks: generateDrawStructuresAndLinks,
62768
62875
  generateDrawTypeAndModifyDrawDefinition: generateDrawTypeAndModifyDrawDefinition,
62876
+ generateDrawStructuresAndLinks: generateDrawStructuresAndLinks,
62877
+ generateDrawMaticRound: generateDrawMaticRound,
62878
+ generateDrawDefinition: generateDrawDefinition,
62769
62879
  applyLineUps: applyLineUps,
62770
62880
  assignTieMatchUpParticipantId: assignTieMatchUpParticipantId,
62771
62881
  removeTieMatchUpParticipantId: removeTieMatchUpParticipantId,