tods-competition-factory 1.8.23 → 1.8.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.
@@ -2905,7 +2905,7 @@ var matchUpFormatCode = {
2905
2905
  };
2906
2906
 
2907
2907
  function factoryVersion() {
2908
- return '1.8.23';
2908
+ return '1.8.24';
2909
2909
  }
2910
2910
 
2911
2911
  function getObjectTieFormat(obj) {
@@ -4904,7 +4904,7 @@ function getTallyReport(_a) {
4904
4904
  var readable = [];
4905
4905
  if (Array.isArray(report)) {
4906
4906
  report.forEach(function (step, i) {
4907
- var _a;
4907
+ var _a, _b, _c;
4908
4908
  if ((_a = step.excludedDirectives) === null || _a === void 0 ? void 0 : _a.length) {
4909
4909
  var attributes = step.excludedDirectives
4910
4910
  .map(function (_a) {
@@ -4921,20 +4921,24 @@ function getTallyReport(_a) {
4921
4921
  var floatSort_1 = function (a, b) {
4922
4922
  return parseFloat(step.reversed ? a : b) - parseFloat(step.reversed ? b : a);
4923
4923
  };
4924
+ var participantsCount = step.groups
4925
+ ? Object.values(step.groups).flat(Infinity).length
4926
+ : (_c = (_b = step.participantIds) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
4924
4927
  var getExplanation = function (step) {
4925
- Object.keys(step.groups)
4926
- .sort(floatSort_1)
4927
- .forEach(function (key) {
4928
- var participantNames = step.groups[key]
4929
- .map(function (participantId) { return participants[participantId]; })
4930
- .join(', ');
4931
- var explanation = "".concat(key, " ").concat(step.attribute, ": ").concat(participantNames);
4932
- readable.push(explanation);
4933
- });
4928
+ step.groups &&
4929
+ Object.keys(step.groups)
4930
+ .sort(floatSort_1)
4931
+ .forEach(function (key) {
4932
+ var participantNames = step.groups[key]
4933
+ .map(function (participantId) { return participants[participantId]; })
4934
+ .join(', ');
4935
+ var explanation = "".concat(key, " ").concat(step.attribute, ": ").concat(participantNames);
4936
+ readable.push(explanation);
4937
+ });
4934
4938
  };
4935
4939
  var reversed = step.reversed ? ' in reverse order' : '';
4936
- var participantsCount = Object.values(step.groups).flat(Infinity).length;
4937
- var description = "Step ".concat(i + 1, ": ").concat(participantsCount, " particiants were grouped").concat(reversed, " by ").concat(step.attribute);
4940
+ var action = step.groups ? 'grouped' : 'separated';
4941
+ var description = "Step ".concat(i + 1, ": ").concat(participantsCount, " particiants were ").concat(action).concat(reversed, " by ").concat(step.attribute);
4938
4942
  readable.push(description);
4939
4943
  if (step.idsFilter) {
4940
4944
  var note = "".concat(step.attribute, " was calculated considering ONLY TIED PARTICIPANTS");
@@ -4949,7 +4953,7 @@ function getTallyReport(_a) {
4949
4953
  order.forEach(function (orderEntry) {
4950
4954
  var participantId = orderEntry.participantId, resolved = orderEntry.resolved;
4951
4955
  var pOrder = orderEntry.groupOrder || orderEntry.provisionalOrder;
4952
- readable.push("".concat(pOrder, ": ").concat(participants[participantId], " => resolved: ").concat(resolved));
4956
+ readable.push("".concat(pOrder, ": ").concat(participants[participantId], " => resolved: ").concat(!!resolved));
4953
4957
  });
4954
4958
  return readable.join('\r\n');
4955
4959
  }
@@ -5073,7 +5077,7 @@ function getGroupOrder(params) {
5073
5077
  .map(function (key) { return orderedTallyGroups[key]; })
5074
5078
  .map(function (participantIds) {
5075
5079
  var result = groupSubSort(__assign({ participantIds: participantIds }, params));
5076
- report.push(result.report);
5080
+ report.push.apply(report, __spreadArray([], __read((result.report || [])), false));
5077
5081
  return result.order;
5078
5082
  })
5079
5083
  .flat(Infinity);
@@ -5182,7 +5186,7 @@ function processAttribute(_a) {
5182
5186
  tallyPolicy: tallyPolicy,
5183
5187
  matchUps: matchUps,
5184
5188
  });
5185
- report.push(result.report);
5189
+ report.push.apply(report, __spreadArray([], __read((result.report || [])), false));
5186
5190
  return result.order;
5187
5191
  })
5188
5192
  .flat(Infinity);
@@ -5191,6 +5195,9 @@ function processAttribute(_a) {
5191
5195
  }
5192
5196
  function groupSubSort(_a) {
5193
5197
  var participantResults = _a.participantResults, disableHeadToHead = _a.disableHeadToHead, participantIds = _a.participantIds, matchUpFormat = _a.matchUpFormat, tallyPolicy = _a.tallyPolicy, matchUps = _a.matchUps;
5198
+ var excludedDirectives = [];
5199
+ var report = [];
5200
+ var result;
5194
5201
  if ((participantIds === null || participantIds === void 0 ? void 0 : participantIds.length) === 1) {
5195
5202
  var participantId = participantIds[0];
5196
5203
  return {
@@ -5201,13 +5208,13 @@ function groupSubSort(_a) {
5201
5208
  (!(tallyPolicy === null || tallyPolicy === void 0 ? void 0 : tallyPolicy.headToHead) ||
5202
5209
  (!tallyPolicy.headToHead.disabled && !disableHeadToHead))) {
5203
5210
  var result_1 = headToHeadWinner({ participantIds: participantIds, participantResults: participantResults });
5204
- if (result_1)
5205
- return { order: [result_1], headToHeadWinner: result_1[0].participantId };
5211
+ if (result_1) {
5212
+ var headToHeadWinner_1 = result_1[0].participantId;
5213
+ report.push({ attribute: 'head2Head', participantIds: participantIds, headToHeadWinner: headToHeadWinner_1 });
5214
+ return { order: [result_1], headToHeadWinner: headToHeadWinner_1, report: report };
5215
+ }
5206
5216
  }
5207
5217
  var directives = (tallyPolicy === null || tallyPolicy === void 0 ? void 0 : tallyPolicy.tallyDirectives) || headToHeadTallyDirectives;
5208
- var excludedDirectives = [];
5209
- var report = [];
5210
- var result;
5211
5218
  var filteredDirectives = directives.filter(function (directive) {
5212
5219
  // if maxParticipants is defined, filter out the rule if # of participants is greater than maxParticipants
5213
5220
  var keepDirective = isNumeric(directive.maxParticipants) &&
@@ -9241,6 +9248,7 @@ var POLICY_ROUND_NAMING_DEFAULT = (_a$h = {},
9241
9248
  policyName: 'Round Naming Default',
9242
9249
  namingConventions: {
9243
9250
  round: 'Round',
9251
+ pre: 'Pre',
9244
9252
  },
9245
9253
  qualifyingFinishMap: {
9246
9254
  1: 'Final',
@@ -9271,9 +9279,9 @@ var POLICY_ROUND_NAMING_DEFAULT = (_a$h = {},
9271
9279
  _a$h);
9272
9280
 
9273
9281
  function getRoundContextProfile(_a) {
9274
- var _b, _c, _d, _e, _f;
9282
+ var _b, _c, _d, _e, _f, _g;
9275
9283
  var roundNamingPolicy = _a.roundNamingPolicy, drawDefinition = _a.drawDefinition, structure = _a.structure, matchUps = _a.matchUps;
9276
- var _g = getRoundMatchUps$1({ matchUps: matchUps }), roundProfile = _g.roundProfile, roundMatchUps = _g.roundMatchUps;
9284
+ var _h = getRoundMatchUps$1({ matchUps: matchUps }), roundProfile = _h.roundProfile, roundMatchUps = _h.roundMatchUps;
9277
9285
  var structureAbbreviation = structure.structureAbbreviation, stage = structure.stage;
9278
9286
  var isAdHocStructure = isAdHoc({ structure: structure });
9279
9287
  var isLuckyStructure = isLucky({ structure: structure });
@@ -9281,10 +9289,6 @@ function getRoundContextProfile(_a) {
9281
9289
  var roundNamingProfile = {};
9282
9290
  var defaultRoundNamingPolicy = POLICY_ROUND_NAMING_DEFAULT[POLICY_TYPE_ROUND_NAMING];
9283
9291
  var isQualifying = structure.stage === QUALIFYING;
9284
- var qualifyingFinishgMap = isQualifying &&
9285
- ((roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.qualifyingFinishMap) ||
9286
- (defaultRoundNamingPolicy === null || defaultRoundNamingPolicy === void 0 ? void 0 : defaultRoundNamingPolicy.qualifyingFinishMap) ||
9287
- {});
9288
9292
  var qualifyingStageSequences = isQualifying
9289
9293
  ? Math.max.apply(Math, __spreadArray(__spreadArray([], __read(((_b = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) !== null && _b !== void 0 ? _b : [])
9290
9294
  .filter(function (structure) { return structure.stage === QUALIFYING; })
@@ -9292,11 +9296,11 @@ function getRoundContextProfile(_a) {
9292
9296
  var stageSequence = _a.stageSequence;
9293
9297
  return stageSequence !== null && stageSequence !== void 0 ? stageSequence : 1;
9294
9298
  })), false), [0], false)) : 0;
9295
- var preQualifyingSequence = qualifyingStageSequences
9296
- ? qualifyingStageSequences - ((_c = structure.stageSequence) !== null && _c !== void 0 ? _c : 1) || ''
9299
+ var preQualifyingSequence = ((_c = structure.stageSequence) !== null && _c !== void 0 ? _c : 1) < qualifyingStageSequences
9300
+ ? (_d = structure.stageSequence) !== null && _d !== void 0 ? _d : 1
9297
9301
  : '';
9298
9302
  var preQualifyingAffix = preQualifyingSequence
9299
- ? ((_d = roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.affixes) === null || _d === void 0 ? void 0 : _d.preQualifying) ||
9303
+ ? ((_e = roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.affixes) === null || _e === void 0 ? void 0 : _e.preQualifying) ||
9300
9304
  defaultRoundNamingPolicy.affixes.preQualifying ||
9301
9305
  ''
9302
9306
  : '';
@@ -9306,9 +9310,9 @@ function getRoundContextProfile(_a) {
9306
9310
  var abbreviatedRoundNamingMap = (roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.abbreviatedRoundNamingMap) ||
9307
9311
  defaultRoundNamingPolicy.abbreviatedRoundNamingMap ||
9308
9312
  {};
9309
- var preFeedAffix = ((_e = roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.affixes) === null || _e === void 0 ? void 0 : _e.preFeedRound) ||
9313
+ var preFeedAffix = ((_f = roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.affixes) === null || _f === void 0 ? void 0 : _f.preFeedRound) ||
9310
9314
  defaultRoundNamingPolicy.affixes.preFeedRound;
9311
- var roundNumberAffix = ((_f = roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.affixes) === null || _f === void 0 ? void 0 : _f.roundNumber) ||
9315
+ var roundNumberAffix = ((_g = roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.affixes) === null || _g === void 0 ? void 0 : _g.roundNumber) ||
9312
9316
  defaultRoundNamingPolicy.affixes.roundNumber;
9313
9317
  var namingConventions = (roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.namingConventions) ||
9314
9318
  defaultRoundNamingPolicy.namingConventions;
@@ -9331,14 +9335,18 @@ function getRoundContextProfile(_a) {
9331
9335
  })), false));
9332
9336
  }
9333
9337
  else {
9338
+ var qualifyingFinishgMap_1 = isQualifying &&
9339
+ ((roundNamingPolicy === null || roundNamingPolicy === void 0 ? void 0 : roundNamingPolicy.qualifyingFinishMap) ||
9340
+ (defaultRoundNamingPolicy === null || defaultRoundNamingPolicy === void 0 ? void 0 : defaultRoundNamingPolicy.qualifyingFinishMap) ||
9341
+ {});
9334
9342
  Object.assign.apply(Object, __spreadArray([roundNamingProfile], __read(roundProfileKeys.map(function (round) {
9335
9343
  var _a;
9336
9344
  if (!(roundProfile === null || roundProfile === void 0 ? void 0 : roundProfile[round]))
9337
9345
  return;
9338
9346
  var _b = roundProfile[round], matchUpsCount = _b.matchUpsCount, preFeedRound = _b.preFeedRound;
9339
9347
  var participantsCount = matchUpsCount * 2;
9340
- var sizedRoundName = (qualifyingFinishgMap === null || qualifyingFinishgMap === void 0 ? void 0 : qualifyingFinishgMap[roundProfile === null || roundProfile === void 0 ? void 0 : roundProfile[round].finishingRound]) ||
9341
- (qualifyingFinishgMap && "".concat(roundNumberAffix).concat(participantsCount)) ||
9348
+ var sizedRoundName = (qualifyingFinishgMap_1 === null || qualifyingFinishgMap_1 === void 0 ? void 0 : qualifyingFinishgMap_1[roundProfile === null || roundProfile === void 0 ? void 0 : roundProfile[round].finishingRound]) ||
9349
+ (qualifyingFinishgMap_1 && "".concat(roundNumberAffix).concat(participantsCount)) ||
9342
9350
  roundNamingMap[matchUpsCount] ||
9343
9351
  "".concat(roundNumberAffix).concat(participantsCount);
9344
9352
  var suffix = preFeedRound ? "-".concat(preFeedAffix) : '';
@@ -11631,8 +11639,10 @@ function modifyMatchUpScore(_a) {
11631
11639
  : undefined;
11632
11640
  var matchUps = getAllStructureMatchUps({
11633
11641
  afterRecoveryTimes: false,
11642
+ tournamentRecord: tournamentRecord,
11634
11643
  inContext: true,
11635
11644
  matchUpFilters: matchUpFilters,
11645
+ drawDefinition: drawDefinition,
11636
11646
  structure: structure,
11637
11647
  event: event,
11638
11648
  }).matchUps;
@@ -25326,7 +25336,7 @@ function allPlayoffPositionsFilled(params) {
25326
25336
  participantIdsCount++;
25327
25337
  return (assignment === null || assignment === void 0 ? void 0 : assignment.bye) || (assignment === null || assignment === void 0 ? void 0 : assignment.participantId);
25328
25338
  }).length;
25329
- return structurePositionsFilled && allFilled;
25339
+ return !!(structurePositionsFilled && allFilled);
25330
25340
  }, !!playoffStructures.length);
25331
25341
  // account for playoffStructure with only one participant
25332
25342
  var allParticipantIdsPlaced = participantIdsCount === enteredParticipantsCount;
@@ -46901,11 +46911,198 @@ function generateVoluntaryConsolation$1(params) {
46901
46911
  return __assign({ links: links, structures: structures }, SUCCESS);
46902
46912
  }
46903
46913
 
46914
+ /**
46915
+ * return an array of arrays of grouped structureIds => structureGroups
46916
+ * the expectation is that all structures within a drawDefintion are linked
46917
+ * return a boolean whether this condition is met => allSructuresLinked
46918
+ */
46919
+ function getStructureGroups(_a) {
46920
+ var e_1, _b, e_2, _c, e_3, _d;
46921
+ var _e, _f, _g, _h, _j, _k, _l, _m, _o;
46922
+ var drawDefinition = _a.drawDefinition;
46923
+ var structures = drawDefinition.structures || [];
46924
+ var links = drawDefinition.links || [];
46925
+ var structureProfiles = new Map();
46926
+ var initStructureProfile = function (structureId) {
46927
+ var profile = structureProfiles.get(structureId) ||
46928
+ (structureProfiles.set(structureId, {
46929
+ drawSources: [],
46930
+ drawTargets: [],
46931
+ progeny: [],
46932
+ sources: [],
46933
+ targets: [],
46934
+ }) &&
46935
+ structureProfiles.get(structureId));
46936
+ if (profile && !(profile === null || profile === void 0 ? void 0 : profile.stage)) {
46937
+ var structure = structures.find(function (structure) { return structure.structureId === structureId; });
46938
+ profile.stage = structure === null || structure === void 0 ? void 0 : structure.stage;
46939
+ }
46940
+ return profile;
46941
+ };
46942
+ var sourceStructureIds = {};
46943
+ var hasDrawFeedProfile = {};
46944
+ var linkedStructureIds = links.map(function (link) {
46945
+ var sourceId = link.source.structureId;
46946
+ var targetId = link.target.structureId;
46947
+ var sourceProfile = initStructureProfile(sourceId);
46948
+ var targetProfile = initStructureProfile(targetId);
46949
+ if ([BOTTOM_UP, TOP_DOWN, RANDOM, WATERFALL].includes(link.target.feedProfile)) {
46950
+ sourceProfile === null || sourceProfile === void 0 ? void 0 : sourceProfile.targets.push(targetId);
46951
+ targetProfile === null || targetProfile === void 0 ? void 0 : targetProfile.sources.push(sourceId);
46952
+ }
46953
+ else if (link.target.feedProfile === DRAW) {
46954
+ targetProfile === null || targetProfile === void 0 ? void 0 : targetProfile.drawSources.push(sourceId);
46955
+ sourceProfile === null || sourceProfile === void 0 ? void 0 : sourceProfile.drawTargets.push(targetId);
46956
+ }
46957
+ hasDrawFeedProfile[targetId] =
46958
+ hasDrawFeedProfile[targetId] || link.target.feedProfile === DRAW;
46959
+ sourceStructureIds[targetId] = unique(__spreadArray(__spreadArray([], __read((sourceStructureIds[targetId] || [])), false), [
46960
+ sourceId,
46961
+ ], false)).filter(Boolean);
46962
+ return [link.source.structureId, link.target.structureId];
46963
+ });
46964
+ try {
46965
+ for (var _p = __values(structureProfiles.keys()), _q = _p.next(); !_q.done; _q = _p.next()) {
46966
+ var structureId = _q.value;
46967
+ var profile = structureProfiles.get(structureId);
46968
+ if (profile) {
46969
+ var sourceIds = (_e = profile.targets) !== null && _e !== void 0 ? _e : [];
46970
+ while (sourceIds.length) {
46971
+ var sourceId = sourceIds.pop();
46972
+ var sourceProfile = sourceId && structureProfiles[sourceId];
46973
+ if ((_f = sourceProfile === null || sourceProfile === void 0 ? void 0 : sourceProfile.targets) === null || _f === void 0 ? void 0 : _f.length) {
46974
+ sourceIds.push.apply(sourceIds, __spreadArray([], __read(sourceProfile.targets), false));
46975
+ }
46976
+ else if (sourceProfile) {
46977
+ profile.rootStage = sourceProfile.stage;
46978
+ }
46979
+ }
46980
+ if (!profile.rootStage)
46981
+ profile.rootStage = profile.stage;
46982
+ if (!((_g = profile.targets) === null || _g === void 0 ? void 0 : _g.length)) {
46983
+ var targetIds = (_h = profile.sources) !== null && _h !== void 0 ? _h : [];
46984
+ while (targetIds.length) {
46985
+ var targetId = targetIds.pop();
46986
+ var targetProfile = targetId && structureProfiles[targetId];
46987
+ if ((_j = targetProfile === null || targetProfile === void 0 ? void 0 : targetProfile.sources) === null || _j === void 0 ? void 0 : _j.length) {
46988
+ try {
46989
+ for (var _r = (e_2 = void 0, __values(targetProfile.sources)), _s = _r.next(); !_s.done; _s = _r.next()) {
46990
+ var id = _s.value;
46991
+ if (!((_k = profile.progeny) === null || _k === void 0 ? void 0 : _k.includes(id)))
46992
+ (_l = profile.progeny) === null || _l === void 0 ? void 0 : _l.push(id);
46993
+ }
46994
+ }
46995
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
46996
+ finally {
46997
+ try {
46998
+ if (_s && !_s.done && (_c = _r.return)) _c.call(_r);
46999
+ }
47000
+ finally { if (e_2) throw e_2.error; }
47001
+ }
47002
+ targetIds.push.apply(targetIds, __spreadArray([], __read(targetProfile.sources), false));
47003
+ }
47004
+ }
47005
+ }
47006
+ }
47007
+ }
47008
+ }
47009
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
47010
+ finally {
47011
+ try {
47012
+ if (_q && !_q.done && (_b = _p.return)) _b.call(_p);
47013
+ }
47014
+ finally { if (e_1) throw e_1.error; }
47015
+ }
47016
+ var maxQualifyingDepth = 0;
47017
+ try {
47018
+ for (var _t = __values(structureProfiles.keys()), _u = _t.next(); !_u.done; _u = _t.next()) {
47019
+ var structureId = _u.value;
47020
+ var profile = structureProfiles.get(structureId);
47021
+ if (profile && profile.rootStage === QUALIFYING) {
47022
+ var drawTargets = [(_m = profile.drawTargets) === null || _m === void 0 ? void 0 : _m[0]];
47023
+ var distanceFromMain = 0;
47024
+ while (drawTargets.length) {
47025
+ distanceFromMain += 1;
47026
+ var drawTarget = drawTargets.pop();
47027
+ var targetProfile = drawTarget
47028
+ ? structureProfiles.get(drawTarget)
47029
+ : undefined;
47030
+ if ((_o = targetProfile === null || targetProfile === void 0 ? void 0 : targetProfile.drawTargets) === null || _o === void 0 ? void 0 : _o.length) {
47031
+ drawTargets.push(targetProfile.drawTargets[0]);
47032
+ }
47033
+ }
47034
+ profile.distanceFromMain = distanceFromMain;
47035
+ if (distanceFromMain > maxQualifyingDepth)
47036
+ maxQualifyingDepth = distanceFromMain;
47037
+ }
47038
+ }
47039
+ }
47040
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
47041
+ finally {
47042
+ try {
47043
+ if (_u && !_u.done && (_d = _t.return)) _d.call(_t);
47044
+ }
47045
+ finally { if (e_3) throw e_3.error; }
47046
+ }
47047
+ // iterate through all groups of structureIds to flatten tree of links between structures
47048
+ var iterations = linkedStructureIds.length;
47049
+ generateRange(0, Math.ceil(iterations / 2)).forEach(function () {
47050
+ linkedStructureIds = generateRange(0, iterations).map(function (index) {
47051
+ var structureIds = linkedStructureIds[index];
47052
+ var mergedWithOverlappingIds = linkedStructureIds.reduce(function (biggest, ids) {
47053
+ var hasOverlap = overlap(structureIds, ids);
47054
+ return hasOverlap ? biggest.concat.apply(biggest, __spreadArray([], __read(ids), false)) : biggest;
47055
+ }, []) || [];
47056
+ return unique(structureIds.concat.apply(structureIds, __spreadArray([], __read(mergedWithOverlappingIds), false)));
47057
+ });
47058
+ });
47059
+ // at this point all linkedStructureIds arrays should be equivalent
47060
+ // use the first of these as the identity array
47061
+ var groupedStructureIds = linkedStructureIds[0];
47062
+ // utility method to recognize equivalent arrays of structureIds
47063
+ var identityLink = function (a, b) { return intersection(a, b).length === a.length; };
47064
+ // check that all arrays of linkedStructureIds are equivalent to identity array
47065
+ var allLinkStructuresLinked = linkedStructureIds
47066
+ .slice(1)
47067
+ .reduce(function (allLinkStructuresLinked, ids) {
47068
+ return allLinkStructuresLinked && identityLink(ids, groupedStructureIds);
47069
+ }, true);
47070
+ // if a drawDefinition contains no links then no structure groups will exist
47071
+ // filter out undefined when there are no links in a drawDefinition
47072
+ var structureGroups = [groupedStructureIds].filter(Boolean);
47073
+ // this is the same as structureGroups, but excludes VOLUNTARY_CONSOLATION
47074
+ var linkCheck = [groupedStructureIds].filter(Boolean);
47075
+ // iterate through all structures to add missing structureIds
47076
+ structures.forEach(function (structure) {
47077
+ var structureId = structure.structureId, stage = structure.stage;
47078
+ var existingGroup = structureGroups.find(function (group) {
47079
+ return group.includes(structureId);
47080
+ });
47081
+ if (!existingGroup) {
47082
+ structureGroups.push([structureId]);
47083
+ if (stage !== VOLUNTARY_CONSOLATION)
47084
+ linkCheck.push([structureId]);
47085
+ }
47086
+ });
47087
+ var allStructuresLinked = allLinkStructuresLinked && linkCheck.length === 1;
47088
+ if (!(links === null || links === void 0 ? void 0 : links.length) && structures.length === 1) {
47089
+ initStructureProfile(structures[0].structureId);
47090
+ }
47091
+ return {
47092
+ structureProfiles: Object.fromEntries(structureProfiles),
47093
+ allStructuresLinked: allStructuresLinked,
47094
+ maxQualifyingDepth: maxQualifyingDepth,
47095
+ sourceStructureIds: sourceStructureIds,
47096
+ hasDrawFeedProfile: hasDrawFeedProfile,
47097
+ structureGroups: structureGroups,
47098
+ };
47099
+ }
47100
+
46904
47101
  // for use when adding a qualifying structure to an existing drawDefinition
46905
47102
  // not for use when generating structures from qualifyingProfiles
46906
47103
  function generateQualifyingStructure$1(params) {
46907
47104
  var _a;
46908
- var _b, _c, _d, _e, _f;
47105
+ var _b, _c, _d, _e, _f, _g, _h, _j;
46909
47106
  if (!params.drawDefinition)
46910
47107
  return { error: MISSING_DRAW_DEFINITION };
46911
47108
  var stack = 'generateQualifyingStructure';
@@ -46918,66 +47115,25 @@ function generateQualifyingStructure$1(params) {
46918
47115
  if (!isConvertableInteger(drawSize)) {
46919
47116
  return decorateResult({ result: { error: MISSING_DRAW_SIZE }, stack: stack });
46920
47117
  }
46921
- var result = findStructure({
46922
- structureId: targetStructureId,
46923
- drawDefinition: drawDefinition,
46924
- });
46925
- if (result.error) {
47118
+ var structureProfiles = getStructureGroups({ drawDefinition: drawDefinition }).structureProfiles;
47119
+ var structureProfile = structureProfiles[targetStructureId];
47120
+ if (!structureProfile) {
46926
47121
  return decorateResult({
47122
+ result: { error: STRUCTURE_NOT_FOUND },
46927
47123
  context: { targetStructureId: targetStructureId },
46928
- result: result,
46929
47124
  stack: stack,
46930
47125
  });
46931
47126
  }
46932
- if (!result.structure)
46933
- return { error: STRUCTURE_NOT_FOUND };
46934
- var targetStructure = result.structure;
46935
- var matchUpType = targetStructure.matchUpType;
46936
- if (targetStructure.stage === QUALIFYING) {
46937
- if (targetStructure.stageSequence && targetStructure.stageSequence > 1) {
46938
- stageSequence = targetStructure.stageSequence - 1;
46939
- }
46940
- else {
46941
- // stageSequence must be modified for entire qualifying chain
46942
- var nextStructureId_1 = targetStructureId;
46943
- var nextStageSequence = 2;
46944
- var chainModified = void 0;
46945
- while (!chainModified && nextStructureId_1) {
46946
- console.log('check getRoundContextProfile preqQualifyingStageSequence');
46947
- targetStructure.stageSequence = nextStageSequence;
46948
- var targetTargetStructureId = (_e = (_d = (_c = drawDefinition.links) === null || _c === void 0 ? void 0 : _c.find(function (link) { return link.source.structureId === nextStructureId_1; })) === null || _d === void 0 ? void 0 : _d.target) === null || _e === void 0 ? void 0 : _e.structureId;
46949
- nextStructureId_1 = targetTargetStructureId;
46950
- nextStageSequence += 1;
46951
- if (!targetTargetStructureId) {
46952
- chainModified = true;
46953
- }
46954
- else {
46955
- var result_1 = findStructure({
46956
- structureId: targetTargetStructureId,
46957
- drawDefinition: drawDefinition,
46958
- });
46959
- if (!result_1.structure)
46960
- return { error: STRUCTURE_NOT_FOUND };
46961
- if (result_1.error) {
46962
- return decorateResult({
46963
- context: { targetTargetStructureId: targetTargetStructureId },
46964
- result: result_1,
46965
- stack: stack,
46966
- });
46967
- }
46968
- if (result_1.structure.stage !== QUALIFYING)
46969
- chainModified = true;
46970
- }
46971
- }
46972
- }
46973
- }
47127
+ var matchUpType = drawDefinition.matchUpType;
46974
47128
  var roundTargetName = roundTarget ? "".concat(roundTarget, "-") : '';
46975
- var stageSequenceName = "".concat(stageSequence);
46976
- var qualifyingStructureName = structureName !== null && structureName !== void 0 ? structureName : (roundTargetName || stageSequenceName
46977
- ? "".concat(constantToString(QUALIFYING), " ").concat(roundTargetName).concat(stageSequenceName)
46978
- : constantToString(QUALIFYING));
47129
+ var isPreQualifying = structureProfile.stage === QUALIFYING;
47130
+ var preQualifyingNaming = (_e = (_d = (_c = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_ROUND_NAMING]) === null || _c === void 0 ? void 0 : _c.namingConventions) === null || _d === void 0 ? void 0 : _d.pre) !== null && _e !== void 0 ? _e : (_g = (_f = POLICY_ROUND_NAMING_DEFAULT[POLICY_TYPE_ROUND_NAMING]) === null || _f === void 0 ? void 0 : _f.namingConventions) === null || _g === void 0 ? void 0 : _g.pre;
47131
+ var pre = isPreQualifying && preQualifyingNaming ? "".concat(preQualifyingNaming, "-") : '';
47132
+ var qualifyingStructureName = structureName !== null && structureName !== void 0 ? structureName : (roundTargetName
47133
+ ? "".concat(pre).concat(constantToString(QUALIFYING), " ").concat(roundTargetName)
47134
+ : "".concat(pre).concat(constantToString(QUALIFYING)));
46979
47135
  if (drawType === ROUND_ROBIN) {
46980
- var _g = generateRoundRobin({
47136
+ var _k = generateRoundRobin({
46981
47137
  structureName: structureName !== null && structureName !== void 0 ? structureName : qualifyingStructureName,
46982
47138
  structureId: structureId !== null && structureId !== void 0 ? structureId : uuids === null || uuids === void 0 ? void 0 : uuids.pop(),
46983
47139
  stage: QUALIFYING,
@@ -46990,7 +47146,7 @@ function generateQualifyingStructure$1(params) {
46990
47146
  drawSize: drawSize,
46991
47147
  isMock: isMock,
46992
47148
  uuids: uuids,
46993
- }), maxRoundNumber = _g.maxRoundNumber /*, groupSize*/, structures = _g.structures, groupCount = _g.groupCount;
47149
+ }), maxRoundNumber = _k.maxRoundNumber /*, groupSize*/, structures = _k.structures, groupCount = _k.groupCount;
46994
47150
  qualifiersCount = groupCount;
46995
47151
  roundLimit = maxRoundNumber;
46996
47152
  structure = structures[0];
@@ -47025,22 +47181,25 @@ function generateQualifyingStructure$1(params) {
47025
47181
  extension: { name: ROUND_TARGET, value: roundTarget },
47026
47182
  });
47027
47183
  }
47028
- qualifiersCount = (_f = matchUps === null || matchUps === void 0 ? void 0 : matchUps.filter(function (matchUp) { return matchUp.roundNumber === roundLimit; })) === null || _f === void 0 ? void 0 : _f.length;
47184
+ qualifiersCount = (_h = matchUps === null || matchUps === void 0 ? void 0 : matchUps.filter(function (matchUp) { return matchUp.roundNumber === roundLimit; })) === null || _h === void 0 ? void 0 : _h.length;
47029
47185
  }
47030
47186
  // order of operations is important here!! finalQualifier positions is not yet updated when this step occurs
47031
47187
  var linkType = drawType === ROUND_ROBIN ? LinkTypeEnum.Position : LinkTypeEnum.Winner;
47032
- var link = generateQualifyingLink({
47033
- sourceStructureId: structure.structureId,
47034
- sourceRoundNumber: roundLimit,
47035
- targetStructureId: targetStructureId,
47036
- finishingPositions: finishingPositions,
47037
- linkType: linkType,
47038
- }).link;
47188
+ var link = structure &&
47189
+ roundLimit &&
47190
+ ((_j = generateQualifyingLink({
47191
+ sourceStructureId: structure.structureId,
47192
+ sourceRoundNumber: roundLimit,
47193
+ targetStructureId: targetStructureId,
47194
+ finishingPositions: finishingPositions,
47195
+ linkType: linkType,
47196
+ })) === null || _j === void 0 ? void 0 : _j.link);
47039
47197
  return __assign(__assign({ qualifyingDrawPositionsCount: drawSize, qualifiersCount: qualifiersCount }, SUCCESS), { structure: structure, link: link });
47040
47198
  }
47041
47199
 
47042
47200
  function attachQualifyingStructure$1(_a) {
47043
- var _b;
47201
+ var e_1, _b;
47202
+ var _c;
47044
47203
  var drawDefinition = _a.drawDefinition, tournamentId = _a.tournamentId, structure = _a.structure, eventId = _a.eventId, link = _a.link;
47045
47204
  if (!drawDefinition)
47046
47205
  return { error: MISSING_DRAW_DEFINITION };
@@ -47065,7 +47224,27 @@ function attachQualifyingStructure$1(_a) {
47065
47224
  drawDefinition.links = [];
47066
47225
  drawDefinition.structures.push(structure);
47067
47226
  drawDefinition.links.push(link);
47068
- var matchUps = ((_b = getAllStructureMatchUps({ structure: structure })) === null || _b === void 0 ? void 0 : _b.matchUps) || [];
47227
+ var _d = getStructureGroups({
47228
+ drawDefinition: drawDefinition,
47229
+ }), maxQualifyingDepth = _d.maxQualifyingDepth, structureProfiles = _d.structureProfiles;
47230
+ try {
47231
+ for (var _e = __values(drawDefinition.structures), _f = _e.next(); !_f.done; _f = _e.next()) {
47232
+ var structure_1 = _f.value;
47233
+ var profile = structureProfiles[structure_1.structureId];
47234
+ if (profile.distanceFromMain) {
47235
+ structure_1.stageSequence =
47236
+ maxQualifyingDepth + 1 - profile.distanceFromMain;
47237
+ }
47238
+ }
47239
+ }
47240
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
47241
+ finally {
47242
+ try {
47243
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
47244
+ }
47245
+ finally { if (e_1) throw e_1.error; }
47246
+ }
47247
+ var matchUps = ((_c = getAllStructureMatchUps({ structure: structure })) === null || _c === void 0 ? void 0 : _c.matchUps) || [];
47069
47248
  addMatchUpsNotice({
47070
47249
  drawDefinition: drawDefinition,
47071
47250
  tournamentId: tournamentId,
@@ -47278,6 +47457,10 @@ function getAdvancingParticipantId(matchUp) {
47278
47457
 
47279
47458
  function addQualifyingStructure$1(params) {
47280
47459
  var _a, _b;
47460
+ if (!params.drawDefinition)
47461
+ return { error: MISSING_DRAW_DEFINITION };
47462
+ if (!params.targetStructureId)
47463
+ return { error: MISSING_STRUCTURE_ID };
47281
47464
  var result = generateQualifyingStructure$1(params);
47282
47465
  if (result.error)
47283
47466
  return result;
@@ -56789,76 +56972,6 @@ function unPublishEvent(_a) {
56789
56972
  return __assign({ eventId: event.eventId }, SUCCESS);
56790
56973
  }
56791
56974
 
56792
- /**
56793
- * return an array of arrays of grouped structureIds => structureGroups
56794
- * the expectation is that all structures within a drawDefintion are linked
56795
- * return a boolean whether this condition is met => allSructuresLinked
56796
- */
56797
- function getStructureGroups(_a) {
56798
- var drawDefinition = _a.drawDefinition;
56799
- var links = drawDefinition.links || [];
56800
- var sourceStructureIds = {};
56801
- var hasDrawFeedProfile = {};
56802
- var linkedStructureIds = links.map(function (link) {
56803
- var sourceId = link.source.structureId;
56804
- var targetId = link.target.structureId;
56805
- hasDrawFeedProfile[targetId] =
56806
- hasDrawFeedProfile[targetId] || link.target.feedProfile === DRAW;
56807
- sourceStructureIds[targetId] = unique(__spreadArray(__spreadArray([], __read((sourceStructureIds[targetId] || [])), false), [
56808
- sourceId,
56809
- ], false)).filter(Boolean);
56810
- return [link.source.structureId, link.target.structureId];
56811
- });
56812
- // iterate through all groups of structureIds to flatten tree of links between structures
56813
- var iterations = linkedStructureIds.length;
56814
- generateRange(0, Math.ceil(iterations / 2)).forEach(function () {
56815
- linkedStructureIds = generateRange(0, iterations).map(function (index) {
56816
- var structureIds = linkedStructureIds[index];
56817
- var mergedWithOverlappingIds = linkedStructureIds.reduce(function (biggest, ids) {
56818
- var hasOverlap = overlap(structureIds, ids);
56819
- return hasOverlap ? biggest.concat.apply(biggest, __spreadArray([], __read(ids), false)) : biggest;
56820
- }, []) || [];
56821
- return unique(structureIds.concat.apply(structureIds, __spreadArray([], __read(mergedWithOverlappingIds), false)));
56822
- });
56823
- });
56824
- // at this point all linkedStructureIds arrays should be equivalent
56825
- // use the first of these as the identity array
56826
- var groupedStructureIds = linkedStructureIds[0];
56827
- // utility method to recognize equivalent arrays of structureIds
56828
- var identityLink = function (a, b) { return intersection(a, b).length === a.length; };
56829
- // check that all arrays of linkedStructureIds are equivalent to identity array
56830
- var allLinkStructuresLinked = linkedStructureIds
56831
- .slice(1)
56832
- .reduce(function (allLinkStructuresLinked, ids) {
56833
- return allLinkStructuresLinked && identityLink(ids, groupedStructureIds);
56834
- }, true);
56835
- // if a drawDefinition contains no links then no structure groups will exist
56836
- // filter out undefined when there are no links in a drawDefinition
56837
- var structureGroups = [groupedStructureIds].filter(Boolean);
56838
- // this is the same as structureGroups, but excludes VOLUNTARY_CONSOLATION
56839
- var linkCheck = [groupedStructureIds].filter(Boolean);
56840
- // iterate through all structures to add missing structureIds
56841
- var structures = drawDefinition.structures || [];
56842
- structures.forEach(function (structure) {
56843
- var structureId = structure.structureId, stage = structure.stage;
56844
- var existingGroup = structureGroups.find(function (group) {
56845
- return group.includes(structureId);
56846
- });
56847
- if (!existingGroup) {
56848
- structureGroups.push([structureId]);
56849
- if (stage !== VOLUNTARY_CONSOLATION)
56850
- linkCheck.push(structureId);
56851
- }
56852
- });
56853
- var allStructuresLinked = allLinkStructuresLinked && linkCheck.length === 1;
56854
- return {
56855
- allStructuresLinked: allStructuresLinked,
56856
- sourceStructureIds: sourceStructureIds,
56857
- hasDrawFeedProfile: hasDrawFeedProfile,
56858
- structureGroups: structureGroups,
56859
- };
56860
- }
56861
-
56862
56975
  function getDrawData(params) {
56863
56976
  var _a = params.tournamentParticipants, tournamentParticipants = _a === void 0 ? [] : _a, includePositionAssignments = params.includePositionAssignments, policyDefinitions = params.policyDefinitions, tournamentRecord = params.tournamentRecord, _b = params.inContext, inContext = _b === void 0 ? true : _b, drawDefinition = params.drawDefinition, noDeepCopy = params.noDeepCopy, sortConfig = params.sortConfig, context = params.context, event = params.event;
56864
56977
  if (!drawDefinition)
@@ -56903,13 +57016,20 @@ function getDrawData(params) {
56903
57016
  .sort(function (a, b) { return structureSort(a, b, sortConfig); })
56904
57017
  .map(function (structure) {
56905
57018
  var _a;
56906
- var structureId = structure.structureId;
57019
+ if (!structure)
57020
+ return;
57021
+ var structureId = structure === null || structure === void 0 ? void 0 : structure.structureId;
56907
57022
  var seedAssignments = [];
56908
57023
  // pass seedAssignments from { stageSequence: 1 } to other stages
56909
- if ([MAIN, CONSOLATION, PLAY_OFF].includes(structure.stage)) {
57024
+ if (structure.stage &&
57025
+ [
57026
+ StageTypeEnum.Main,
57027
+ StageTypeEnum.Consolation,
57028
+ StageTypeEnum.PlayOff,
57029
+ ].includes(structure.stage)) {
56910
57030
  seedAssignments = mainStageSeedAssignments;
56911
57031
  }
56912
- if (structure.stage === QUALIFYING) {
57032
+ if ((structure === null || structure === void 0 ? void 0 : structure.stage) === QUALIFYING) {
56913
57033
  seedAssignments = qualificationStageSeedAssignments;
56914
57034
  }
56915
57035
  var _b = getAllStructureMatchUps({
@@ -56942,16 +57062,18 @@ function getDrawData(params) {
56942
57062
  participantResult: extension.value,
56943
57063
  });
56944
57064
  }).filter(function (f) { return f === null || f === void 0 ? void 0 : f.participantResult; });
56945
- var structureInfo = (function (_a) {
56946
- var stageSequence = _a.stageSequence, structureName = _a.structureName, structureType = _a.structureType, matchUpFormat = _a.matchUpFormat, stage = _a.stage;
56947
- return ({
56948
- stageSequence: stageSequence,
56949
- structureName: structureName,
56950
- structureType: structureType,
56951
- matchUpFormat: matchUpFormat,
56952
- stage: stage,
56953
- });
56954
- })(structure);
57065
+ var structureInfo = structure
57066
+ ? (function (_a) {
57067
+ var stageSequence = _a.stageSequence, structureName = _a.structureName, structureType = _a.structureType, matchUpFormat = _a.matchUpFormat, stage = _a.stage;
57068
+ return ({
57069
+ stageSequence: stageSequence,
57070
+ structureName: structureName,
57071
+ structureType: structureType,
57072
+ matchUpFormat: matchUpFormat,
57073
+ stage: stage,
57074
+ });
57075
+ })(structure)
57076
+ : {};
56955
57077
  structureInfo.sourceStructureIds = sourceStructureIds[structureId];
56956
57078
  structureInfo.hasDrawFeedProfile = hasDrawFeedProfile[structureId];
56957
57079
  structureInfo.positionAssignments = positionAssignments;
@@ -59246,11 +59368,11 @@ function getEntryStatusReports(_a) {
59246
59368
  var positionAssignments = _a.positionAssignments;
59247
59369
  return positionAssignments;
59248
59370
  })
59371
+ .filter(Boolean)
59249
59372
  .map(function (_a) {
59250
59373
  var participantId = _a.participantId;
59251
59374
  return participantId;
59252
- })
59253
- .filter(Boolean);
59375
+ });
59254
59376
  var entryFilter = function (_a) {
59255
59377
  var participantId = _a.participantId;
59256
59378
  return assignedParticipantIds.includes(participantId);
@@ -64508,8 +64630,7 @@ function isValidForQualifying(_a) {
64508
64630
  var targetFeedProfiles = result.links.target
64509
64631
  .flatMap(function (t) { return t.target.feedProfile; })
64510
64632
  .filter(Boolean);
64511
- var valid = !intersection([BOTTOM_UP, TOP_DOWN, RANDOM], targetFeedProfiles)
64512
- .length;
64633
+ var valid = !intersection([BOTTOM_UP, TOP_DOWN, RANDOM, WATERFALL], targetFeedProfiles).length;
64513
64634
  return __assign(__assign({}, SUCCESS), { valid: valid });
64514
64635
  }
64515
64636