tods-competition-factory 2.2.30 → 2.2.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.2.30';
6
+ return '2.2.31';
7
7
  }
8
8
 
9
9
  const SINGLES_MATCHUP = 'SINGLES';
@@ -1870,7 +1870,9 @@ function decorateResult({ context, result, stack, info }) {
1870
1870
  result.info = info;
1871
1871
  }
1872
1872
  if (result && typeof context === 'object' && Object.keys(context).length) {
1873
- Object.assign(result, definedAttributes(context));
1873
+ if (!result.context)
1874
+ result.context = {};
1875
+ Object.assign(result.context, definedAttributes(context));
1874
1876
  }
1875
1877
  if (result && !result?.error && !result?.success) {
1876
1878
  Object.assign(result, { ...SUCCESS });
@@ -12235,62 +12237,6 @@ function getInitialRoundNumber({ drawPosition, matchUps = [] }) {
12235
12237
  return { initialRoundNumber };
12236
12238
  }
12237
12239
 
12238
- const logColors = {
12239
- reset: '\x1b[0m',
12240
- bright: '\x1b[1m',
12241
- dim: '\x1b[2m',
12242
- red: '\x1b[31m',
12243
- brightred: '\x1b[91m',
12244
- green: '\x1b[32m',
12245
- brightgreen: '\x1b[92m',
12246
- yellow: '\x1b[33m',
12247
- brightyellow: '\x1b[93m',
12248
- blue: '\x1b[34m',
12249
- brightblue: '\x1b[94m',
12250
- lightblue: '\x1b[105m',
12251
- magenta: '\x1b[35m',
12252
- brightmagenta: '\x1b[95m',
12253
- cyan: '\x1b[36m',
12254
- brightcyan: '\x1b[96m',
12255
- white: '\x1b[37m',
12256
- brightwhite: '\x1b[97m',
12257
- };
12258
-
12259
- const globalLog = [];
12260
- function pushGlobalLog(value, devContextOverride) {
12261
- if (isString(value))
12262
- value = { method: value };
12263
- if (devContextOverride || getDevContext())
12264
- globalLog.push(value);
12265
- }
12266
- function getGlobalLog(purge) {
12267
- const globalLogCopy = globalLog.slice();
12268
- return globalLogCopy;
12269
- }
12270
- function printGlobalLog(purge) {
12271
- const globalLogCopy = getGlobalLog();
12272
- const modifiedText = globalLogCopy.map((line) => {
12273
- const { color, keyColors, method, newline } = line;
12274
- const methodColor = Object.keys(logColors).includes(color) ? logColors[color] : logColors.cyan;
12275
- const bodyKeys = Object.keys(line).filter((key) => !['color', 'keyColors', 'method', 'newline'].includes(key));
12276
- const body = bodyKeys
12277
- .map((key) => {
12278
- const keyColor = keyColors && Object.keys(keyColors).includes(key) && logColors[keyColors[key]]
12279
- ? logColors[keyColors[key]]
12280
- : logColors.brightwhite;
12281
- return `${logColors.white}${key}: ${keyColor}${line[key]}`;
12282
- })
12283
- .join(', ');
12284
- const tabs = method?.length < 15 ? `\t\t` : '\t';
12285
- return [newline ? '\n' : '', methodColor, method, tabs, logColors.white, body, logColors.reset, '\n'].join('');
12286
- });
12287
- if (modifiedText?.length)
12288
- console.log(...modifiedText);
12289
- }
12290
- function purgeGlobalLog() {
12291
- globalLog.length = 0;
12292
- }
12293
-
12294
12240
  function assignDrawPositionBye({ provisionalPositioning, isPositionAction, tournamentRecord, drawDefinition, drawPosition, matchUpsMap, structureId, structure, event, }) {
12295
12241
  if (!drawDefinition)
12296
12242
  return { error: MISSING_DRAW_DEFINITION };
@@ -12301,7 +12247,6 @@ function assignDrawPositionBye({ provisionalPositioning, isPositionAction, tourn
12301
12247
  if (!structureId)
12302
12248
  ({ structureId } = structure);
12303
12249
  const stack = 'assignDrawPositionBye';
12304
- pushGlobalLog({ method: stack, color: 'cyan', drawPosition });
12305
12250
  if (!matchUpsMap) {
12306
12251
  matchUpsMap = getMatchUpsMap({ drawDefinition });
12307
12252
  }
@@ -12461,8 +12406,6 @@ function assignRoundRobinBYE({ tournamentRecord, drawDefinition, drawPosition, m
12461
12406
  });
12462
12407
  }
12463
12408
  function advanceDrawPosition({ drawPositionToAdvance, inContextDrawMatchUps, sourceDrawPositions, tournamentRecord, drawDefinition, matchUpsMap, matchUpId, event, }) {
12464
- const stack = 'advanceDrawPosition';
12465
- pushGlobalLog({ method: stack, color: 'cyan', drawPositionToAdvance });
12466
12409
  const matchUp = matchUpsMap.drawMatchUps.find((matchUp) => matchUp.matchUpId === matchUpId);
12467
12410
  const inContextMatchUp = inContextDrawMatchUps.find((matchUp) => matchUp.matchUpId === matchUpId);
12468
12411
  const structureId = inContextMatchUp?.structureId;
@@ -12575,14 +12518,6 @@ function advanceWinner({ drawPositionToAdvance, inContextDrawMatchUps, sourceDra
12575
12518
  winningSide: undefined,
12576
12519
  drawPositions,
12577
12520
  });
12578
- const changedDrawPosition = noContextWinnerMatchUp.drawPositions.find((position) => !twoDrawPositions.includes(position));
12579
- pushGlobalLog({
12580
- method: stack,
12581
- color: 'brightyellow',
12582
- changedDrawPosition,
12583
- pairedDrawPositionIsBye,
12584
- drawPositionIsBye,
12585
- });
12586
12521
  modifyMatchUpNotice({
12587
12522
  tournamentId: tournamentRecord?.tournamentId,
12588
12523
  matchUp: noContextWinnerMatchUp,
@@ -12637,8 +12572,6 @@ function advanceWinner({ drawPositionToAdvance, inContextDrawMatchUps, sourceDra
12637
12572
  }
12638
12573
  function assignFedDrawPositionBye({ loserTargetDrawPosition, tournamentRecord, loserTargetLink, drawDefinition, loserMatchUp, matchUpsMap, event, }) {
12639
12574
  const { roundNumber } = loserMatchUp;
12640
- const stack = 'assignFedDrawPositionBye';
12641
- pushGlobalLog({ method: stack, color: 'cyan', loserTargetDrawPosition });
12642
12575
  const mappedMatchUps = matchUpsMap?.mappedMatchUps || {};
12643
12576
  const loserStructureMatchUps = mappedMatchUps[loserMatchUp.structureId].matchUps;
12644
12577
  const { initialRoundNumber } = getInitialRoundNumber({
@@ -12682,6 +12615,65 @@ function modifyRoundRobinMatchUpsStatus({ positionAssignments, tournamentRecord,
12682
12615
  });
12683
12616
  }
12684
12617
 
12618
+ const logColors = {
12619
+ reset: '\x1b[0m',
12620
+ bright: '\x1b[1m',
12621
+ dim: '\x1b[2m',
12622
+ red: '\x1b[31m',
12623
+ brightred: '\x1b[91m',
12624
+ green: '\x1b[32m',
12625
+ brightgreen: '\x1b[92m',
12626
+ yellow: '\x1b[33m',
12627
+ brightyellow: '\x1b[93m',
12628
+ blue: '\x1b[34m',
12629
+ brightblue: '\x1b[94m',
12630
+ pinkbackground: '\x1b[105m',
12631
+ magenta: '\x1b[35m',
12632
+ brightmagenta: '\x1b[95m',
12633
+ cyan: '\x1b[36m',
12634
+ brightcyan: '\x1b[96m',
12635
+ white: '\x1b[37m',
12636
+ brightwhite: '\x1b[97m',
12637
+ };
12638
+
12639
+ const globalLog = [];
12640
+ function pushGlobalLog(value, devContextOverride) {
12641
+ if (isString(value))
12642
+ value = { method: value };
12643
+ if (devContextOverride || getDevContext())
12644
+ globalLog.push(value);
12645
+ }
12646
+ function getGlobalLog(purge) {
12647
+ const globalLogCopy = globalLog.slice();
12648
+ return globalLogCopy;
12649
+ }
12650
+ function printGlobalLog(purge) {
12651
+ const globalLogCopy = getGlobalLog();
12652
+ const modifiedText = globalLogCopy.map((line) => {
12653
+ const { color, keyColors, method, newline } = line;
12654
+ const methodColor = Object.keys(logColors).includes(color) ? logColors[color] : logColors.cyan;
12655
+ const bodyKeys = Object.keys(line).filter((key) => !['color', 'keyColors', 'method', 'newline'].includes(key));
12656
+ const body = bodyKeys
12657
+ .map((key) => {
12658
+ const keyColor = (line[key] === undefined && logColors.red) ||
12659
+ (keyColors &&
12660
+ Object.keys(keyColors).includes(key) &&
12661
+ logColors[keyColors[key]] &&
12662
+ logColors[keyColors[key]]) ||
12663
+ logColors.brightwhite;
12664
+ return `${logColors.white}${key}: ${keyColor}${line[key]}`;
12665
+ })
12666
+ .join(', ');
12667
+ const tabs = (method?.length <= 12 && '\t\t\t') || (method?.length <= 20 && `\t\t`) || '\t';
12668
+ return [newline ? '\n' : '', methodColor, method, tabs, logColors.white, body, logColors.reset, '\n'].join('');
12669
+ });
12670
+ if (modifiedText?.length)
12671
+ console.log(...modifiedText);
12672
+ }
12673
+ function purgeGlobalLog() {
12674
+ globalLog.length = 0;
12675
+ }
12676
+
12685
12677
  function clearDrawPosition(params) {
12686
12678
  let { inContextDrawMatchUps, participantId, drawPosition } = params;
12687
12679
  const { tournamentRecord, drawDefinition, structureId, matchUpsMap, event } = params;
@@ -16646,6 +16638,7 @@ function assignMatchUpDrawPosition({ inContextDrawMatchUps, sourceMatchUpStatus,
16646
16638
  [DOUBLE_WALKOVER, DOUBLE_DEFAULT].includes(matchUp.matchUpStatus) &&
16647
16639
  matchUp.matchUpStatus) ||
16648
16640
  TO_BE_PLAYED;
16641
+ const isWalkover = !!([WALKOVER$2, DEFAULTED].includes(matchUp?.matchUpStatus) && matchUp?.winningSide);
16649
16642
  if (matchUp && positionAdded) {
16650
16643
  inContextDrawMatchUps =
16651
16644
  getAllDrawMatchUps({
@@ -16658,8 +16651,9 @@ function assignMatchUpDrawPosition({ inContextDrawMatchUps, sourceMatchUpStatus,
16658
16651
  inContextDrawMatchUps,
16659
16652
  drawPosition,
16660
16653
  matchUpId,
16661
- })) ||
16662
- undefined;
16654
+ }))
16655
+ || (isWalkover && matchUp.winningSide)
16656
+ || undefined;
16663
16657
  if (matchUp?.matchUpStatusCodes) {
16664
16658
  updateMatchUpStatusCodes({
16665
16659
  inContextDrawMatchUps,
@@ -16672,7 +16666,7 @@ function assignMatchUpDrawPosition({ inContextDrawMatchUps, sourceMatchUpStatus,
16672
16666
  Object.assign(matchUp, {
16673
16667
  drawPositions: updatedDrawPositions,
16674
16668
  winningSide: exitWinningSide,
16675
- matchUpStatus,
16669
+ matchUpStatus: isWalkover ? matchUp?.matchUpStatus : matchUpStatus,
16676
16670
  });
16677
16671
  modifyMatchUpNotice({
16678
16672
  tournamentId: tournamentRecord?.tournamentId,
@@ -16715,6 +16709,20 @@ function assignMatchUpDrawPosition({ inContextDrawMatchUps, sourceMatchUpStatus,
16715
16709
  }
16716
16710
  }
16717
16711
  }
16712
+ else if (positionAssigned && isWalkover) {
16713
+ if (winnerMatchUp) {
16714
+ const result = assignMatchUpDrawPosition({
16715
+ matchUpId: winnerMatchUp.matchUpId,
16716
+ inContextDrawMatchUps,
16717
+ tournamentRecord,
16718
+ drawDefinition,
16719
+ drawPosition,
16720
+ matchUpsMap,
16721
+ });
16722
+ if (result.error)
16723
+ return result;
16724
+ }
16725
+ }
16718
16726
  else if (winnerMatchUp && inContextMatchUp && !inContextMatchUp.feedRound) {
16719
16727
  const { pairedPreviousMatchUpIsDoubleExit } = getPairedPreviousMatchUpIsDoubleExit({
16720
16728
  targetMatchUp: matchUp,
@@ -23192,7 +23200,7 @@ function modifyMatchUpScore(params) {
23192
23200
  }
23193
23201
 
23194
23202
  function attemptToModifyScore(params) {
23195
- const { matchUpStatusCodes, matchUpStatus, structure, matchUp, dualMatchUp, inContextMatchUp, autoCalcDisabled } = params;
23203
+ const { matchUpStatusCodes, matchUpStatus, structure, matchUp, dualMatchUp, inContextMatchUp, autoCalcDisabled, propagateExitStatus, } = params;
23196
23204
  const matchUpStatusIsValid = isDirectingMatchUpStatus({ matchUpStatus }) ||
23197
23205
  ([CANCELLED$1, ABANDONED$1].includes(matchUpStatus) && dualMatchUp) ||
23198
23206
  autoCalcDisabled;
@@ -23202,13 +23210,15 @@ function attemptToModifyScore(params) {
23202
23210
  const hasAdHocSides = (isAdHoc({ structure }) && participantsCount === 1) || (matchUpStatus === DEFAULTED && participantsCount);
23203
23211
  const validToScore = hasAdHocSides ||
23204
23212
  drawPositionsAssignedParticipantIds({ structure, matchUp, inContextMatchUp }) ||
23205
- params.appliedPolicies?.[POLICY_TYPE_SCORING]?.requireParticipantsForScoring === false;
23213
+ params.appliedPolicies?.[POLICY_TYPE_SCORING]?.requireParticipantsForScoring === false ||
23214
+ ([WALKOVER$2, DEFAULTED].includes(matchUpStatus) && participantsCount === 1 && propagateExitStatus);
23206
23215
  if (!validToScore)
23207
23216
  return decorateResult({ result: { error: MISSING_ASSIGNMENTS }, stack });
23208
23217
  const removeScore = [WALKOVER$2].includes(matchUpStatus);
23209
23218
  const updatedMatchUpStatus = matchUpStatusIsValid ? matchUpStatus : (params.winningSide && COMPLETED$1) || INCOMPLETE;
23210
23219
  const result = modifyMatchUpScore({
23211
23220
  ...params,
23221
+ winningSide: params.winningSide,
23212
23222
  matchUpStatusCodes: (matchUpStatusIsValid && matchUpStatusCodes) || [],
23213
23223
  matchUpStatus: updatedMatchUpStatus,
23214
23224
  removeScore,
@@ -23724,7 +23734,7 @@ function directWinner({ winnerMatchUpDrawPositionIndex, inContextDrawMatchUps, p
23724
23734
  if (structure?.stage !== QUALIFYING) {
23725
23735
  const error = 'winner target position unavaiallble';
23726
23736
  console.log(error);
23727
- return { error };
23737
+ decorateResult({ stack, result: { error } });
23728
23738
  }
23729
23739
  }
23730
23740
  if (structure?.seedAssignments && structure.structureId !== targetStructureId) {
@@ -23788,7 +23798,7 @@ function directWinner({ winnerMatchUpDrawPositionIndex, inContextDrawMatchUps, p
23788
23798
  }
23789
23799
 
23790
23800
  function directLoser(params) {
23791
- const { loserMatchUpDrawPositionIndex, inContextDrawMatchUps, projectedWinningSide, sourceMatchUpStatus, loserDrawPosition, tournamentRecord, loserTargetLink, drawDefinition, loserMatchUp, dualMatchUp, matchUpsMap, event, } = params;
23801
+ const { loserMatchUpDrawPositionIndex, inContextDrawMatchUps, projectedWinningSide, propagateExitStatus, sourceMatchUpStatus, loserDrawPosition, tournamentRecord, loserTargetLink, drawDefinition, loserMatchUp, dualMatchUp, matchUpsMap, event, } = params;
23792
23802
  const stack = 'directLoser';
23793
23803
  const loserLinkCondition = loserTargetLink.linkCondition;
23794
23804
  const targetMatchUpDrawPositions = loserMatchUp.drawPositions || [];
@@ -23822,15 +23832,17 @@ function directLoser(params) {
23822
23832
  });
23823
23833
  const relevantAssignment = sourcePositionAssignments?.find((assignment) => assignment.drawPosition === loserDrawPosition);
23824
23834
  const loserParticipantId = relevantAssignment?.participantId;
23835
+ const context = { loserParticipantId };
23825
23836
  const targetStructureId = loserTargetLink.target.structureId;
23826
23837
  const { positionAssignments: targetPositionAssignments } = structureAssignedDrawPositions({
23827
23838
  structureId: targetStructureId,
23828
23839
  drawDefinition,
23829
23840
  });
23830
23841
  const targetMatchUpPositionAssignments = targetPositionAssignments?.filter(({ drawPosition }) => targetMatchUpDrawPositions.includes(drawPosition));
23831
- const loserAlreadyDirected = targetMatchUpPositionAssignments?.some((assignment) => assignment.participantId === loserParticipantId);
23842
+ const loserAlreadyDirected = targetMatchUpPositionAssignments?.some((assignment) => assignment.participantId && loserParticipantId && assignment.participantId === loserParticipantId);
23843
+ const validExitToPropagate = propagateExitStatus && [RETIRED$1, WALKOVER$2, DEFAULTED].includes(sourceMatchUpStatus || '');
23832
23844
  if (loserAlreadyDirected) {
23833
- return { ...SUCCESS };
23845
+ return { ...SUCCESS, stack };
23834
23846
  }
23835
23847
  const unfilledTargetMatchUpDrawPositions = targetMatchUpPositionAssignments
23836
23848
  ?.filter((assignment) => {
@@ -23844,11 +23856,15 @@ function directLoser(params) {
23844
23856
  const isFirstRoundValidDrawPosition = loserTargetLink.target.roundNumber === 1 && targetDrawPositionIsUnfilled;
23845
23857
  if (fedDrawPositionFMLC) {
23846
23858
  const result = loserLinkFedFMLC();
23859
+ if (result.context)
23860
+ Object.assign(context, result.context);
23847
23861
  if (result.error)
23848
23862
  return decorateResult({ result, stack });
23849
23863
  }
23850
23864
  else if (isFirstRoundValidDrawPosition) {
23851
23865
  const result = asssignLoserDrawPosition();
23866
+ if (result.context)
23867
+ Object.assign(context, result.context);
23852
23868
  if (result.error)
23853
23869
  return decorateResult({ result, stack });
23854
23870
  }
@@ -23868,6 +23884,9 @@ function directLoser(params) {
23868
23884
  });
23869
23885
  if (result.error)
23870
23886
  return decorateResult({ result, stack });
23887
+ if (!result.error && validExitToPropagate && propagateExitStatus) {
23888
+ return { stack, context: { progressExitStatus: true, loserParticipantId } };
23889
+ }
23871
23890
  }
23872
23891
  else {
23873
23892
  const error = !targetDrawPositionIsUnfilled ? DRAW_POSITION_OCCUPIED : INVALID_DRAW_POSITION;
@@ -23916,7 +23935,7 @@ function directLoser(params) {
23916
23935
  }
23917
23936
  }
23918
23937
  }
23919
- return { ...SUCCESS };
23938
+ return { ...SUCCESS, stack, context };
23920
23939
  function loserLinkFedFMLC() {
23921
23940
  const stack = 'loserLinkFedFMLC';
23922
23941
  if (validForConsolation) {
@@ -23950,6 +23969,9 @@ function directLoser(params) {
23950
23969
  event,
23951
23970
  })
23952
23971
  : { error: MISSING_PARTICIPANT_ID };
23972
+ if (!result.error && validExitToPropagate && propagateExitStatus) {
23973
+ return { stack, context: { progressExitStatus: true } };
23974
+ }
23953
23975
  return decorateResult({ result, stack: 'assignLoserDrawPosition' });
23954
23976
  }
23955
23977
  }
@@ -23962,7 +23984,7 @@ function directParticipants(params) {
23962
23984
  const matchUpStatusIsValid = isDirectingMatchUpStatus({
23963
23985
  matchUpStatus: params.matchUpStatus,
23964
23986
  });
23965
- const { dualWinningSideChange, projectedWinningSide, inContextDrawMatchUps, tournamentRecord, drawDefinition, matchUpStatus, dualMatchUp, matchUpsMap, winningSide, targetData, matchUpId, structure, matchUp, event, } = params;
23987
+ const { dualWinningSideChange, inContextDrawMatchUps, projectedWinningSide, propagateExitStatus, matchUpStatusCodes, tournamentRecord, drawDefinition, matchUpStatus, dualMatchUp, matchUpsMap, winningSide, targetData, matchUpId, structure, matchUp, event, } = params;
23966
23988
  const isCollectionMatchUp = Boolean(matchUp.collectionId);
23967
23989
  const isAdHocMatchUp = isAdHoc({ structure });
23968
23990
  let drawPositions = matchUp.drawPositions;
@@ -23992,6 +24014,7 @@ function directParticipants(params) {
23992
24014
  const losingIndex = 1 - winningIndex;
23993
24015
  const winningDrawPosition = drawPositions[winningIndex];
23994
24016
  const loserDrawPosition = drawPositions[losingIndex];
24017
+ const context = {};
23995
24018
  const { targetLinks: { loserTargetLink, winnerTargetLink, byeTargetLink }, targetMatchUps: { winnerMatchUpDrawPositionIndex, loserMatchUpDrawPositionIndex, winnerMatchUp, loserMatchUp, byeMatchUp, }, } = targetData;
23996
24019
  if (winnerMatchUp) {
23997
24020
  const result = directWinner({
@@ -24018,6 +24041,7 @@ function directParticipants(params) {
24018
24041
  loserMatchUpDrawPositionIndex,
24019
24042
  inContextDrawMatchUps,
24020
24043
  projectedWinningSide,
24044
+ propagateExitStatus,
24021
24045
  loserDrawPosition,
24022
24046
  tournamentRecord,
24023
24047
  loserTargetLink,
@@ -24027,6 +24051,14 @@ function directParticipants(params) {
24027
24051
  dualMatchUp,
24028
24052
  event,
24029
24053
  });
24054
+ if (result.context?.progressExitStatus) {
24055
+ Object.assign(context, result.context, {
24056
+ sourceMatchUpStatus: (matchUpStatusIsValid && matchUpStatus) || COMPLETED$1,
24057
+ sourceMatchUpStatusCodes: matchUpStatusCodes || [],
24058
+ loserMatchUp,
24059
+ matchUpsMap,
24060
+ });
24061
+ }
24030
24062
  if (result.error)
24031
24063
  return decorateResult({ result, stack });
24032
24064
  }
@@ -24044,11 +24076,11 @@ function directParticipants(params) {
24044
24076
  if (result.error)
24045
24077
  return decorateResult({ result, stack });
24046
24078
  }
24079
+ return decorateResult({ result: { ...SUCCESS, ...annotate }, stack, context });
24047
24080
  }
24048
24081
  else {
24049
24082
  return decorateResult({ result: { error: MISSING_DRAW_POSITIONS }, stack });
24050
24083
  }
24051
- return decorateResult({ result: { ...SUCCESS, ...annotate }, stack });
24052
24084
  }
24053
24085
 
24054
24086
  function generateAndPopulatePlayoffStructures(params) {
@@ -25600,7 +25632,7 @@ function getValidModifyAssignedPairAction({ tournamentParticipants, returnPartic
25600
25632
  }
25601
25633
 
25602
25634
  function isActiveDownstream(params) {
25603
- const { inContextDrawMatchUps, targetData, drawDefinition, relevantLink } = params;
25635
+ const { inContextDrawMatchUps, targetData, drawDefinition, relevantLink, matchUpStatus, score, winningSide } = params;
25604
25636
  const fmlcBYE = relevantLink?.linkCondition === FIRST_MATCHUP && targetData?.matchUp?.matchUpStatus === BYE;
25605
25637
  if (fmlcBYE)
25606
25638
  return false;
@@ -25615,11 +25647,19 @@ function isActiveDownstream(params) {
25615
25647
  const loserIndex = loserTargetData?.targetMatchUps?.loserMatchUpDrawPositionIndex;
25616
25648
  const propagatedLoserParticipant = loserExitPropagation?.sides[loserIndex]?.participant;
25617
25649
  const loserMatchUpExit = [DEFAULTED, WALKOVER$2].includes(loserMatchUp?.matchUpStatus) && !propagatedLoserParticipant;
25650
+ const loserMatchUpParticipantsCount = loserMatchUp?.sides?.reduce((acc, current) => (current?.participant ? ++acc : acc), 0) ?? 0;
25651
+ const isLoserMatchUpAPropagatedExitStatus = loserMatchUp?.winningSide &&
25652
+ [DEFAULTED, WALKOVER$2].includes(loserMatchUp?.matchUpStatus) &&
25653
+ propagatedLoserParticipant &&
25654
+ loserMatchUpParticipantsCount === 1;
25655
+ const isClearScore = matchUpStatus === TO_BE_PLAYED && score?.scoreStringSide1 === '' && score?.scoreStringSide2 === '' && !winningSide;
25618
25656
  const winnerDrawPositionsCount = winnerMatchUp?.drawPositions?.filter(Boolean).length || 0;
25619
- if ((loserMatchUp?.winningSide && !loserMatchUpExit) ||
25620
- (winnerMatchUp?.winningSide &&
25621
- winnerDrawPositionsCount === 2 &&
25622
- (!winnerMatchUp.feedRound || ![WALKOVER$2, DEFAULTED].includes(winnerMatchUp?.matchUpStatus)))) {
25657
+ if ((isLoserMatchUpAPropagatedExitStatus && isClearScore) ||
25658
+ (!isLoserMatchUpAPropagatedExitStatus &&
25659
+ ((loserMatchUp?.winningSide && !loserMatchUpExit) ||
25660
+ (winnerMatchUp?.winningSide &&
25661
+ winnerDrawPositionsCount === 2 &&
25662
+ (!winnerMatchUp.feedRound || ![WALKOVER$2, DEFAULTED].includes(winnerMatchUp?.matchUpStatus)))))) {
25623
25663
  return true;
25624
25664
  }
25625
25665
  const winnerTargetData = winnerMatchUp &&
@@ -43383,11 +43423,6 @@ function removeDirectedLoser({ sourceMatchUpStatus, loserParticipantId, tourname
43383
43423
  function removeDirectedBye({ inContextDrawMatchUps, tournamentRecord, drawDefinition, drawPosition, matchUpsMap, targetLink, event, }) {
43384
43424
  const structureId = targetLink.target.structureId;
43385
43425
  const stack = 'removeDirectedBye';
43386
- pushGlobalLog({
43387
- color: 'brightyellow',
43388
- method: stack,
43389
- drawPosition,
43390
- });
43391
43426
  const result = clearDrawPosition({
43392
43427
  inContextDrawMatchUps,
43393
43428
  tournamentRecord,
@@ -43457,7 +43492,8 @@ function doubleExitAdvancement(params) {
43457
43492
  !loserMatchUp.sides?.map((side) => side.participantId ?? side.participant).filter(Boolean).length;
43458
43493
  if (loserMatchUp && loserMatchUp.matchUpStatus !== BYE) {
43459
43494
  const { loserTargetLink } = targetLinks;
43460
- if (appliedPolicies?.progression?.doubleExitPropagateBye) {
43495
+ if (appliedPolicies?.progression?.doubleExitPropagateBye ||
43496
+ (loserMatchUp.feedRound && loserMatchUp.sides?.[0]?.participantFed)) {
43461
43497
  const result = advanceByeToLoserMatchUp({
43462
43498
  loserTargetDrawPosition,
43463
43499
  tournamentRecord,
@@ -43777,8 +43813,9 @@ function attemptToSetMatchUpStatus(params) {
43777
43813
  (!directing && { error: UNRECOGNIZED_MATCHUP_STATUS }) ||
43778
43814
  (isDoubleExit && modifyScoreAndAdvanceDoubleExit(params)) ||
43779
43815
  (teamRoundRobinContext && scoreModification$1(params)) ||
43816
+ (params.propagateExitStatus && scoreModification$1(params)) ||
43780
43817
  decorateResult({
43781
- result: { error: INVALID_MATCHUP_STATUS },
43818
+ result: { error: INVALID_MATCHUP_STATUS, info: 'matchUpStatus: ' + matchUpStatus },
43782
43819
  stack,
43783
43820
  }));
43784
43821
  }
@@ -43990,6 +44027,7 @@ function placeQualifier(params) {
43990
44027
  function attemptToSetWinningSide(params) {
43991
44028
  const stack = 'attemptToSetWinningSide';
43992
44029
  let connectedStructures;
44030
+ const context = {};
43993
44031
  const { appliedPolicies, disableAutoCalc, drawDefinition, dualMatchUp, winningSide, structure, matchUp } = params;
43994
44032
  if (dualMatchUp?._disableAutoCalc && disableAutoCalc !== false) {
43995
44033
  return attemptToModifyScore(params);
@@ -44009,6 +44047,8 @@ function attemptToSetWinningSide(params) {
44009
44047
  return result;
44010
44048
  }
44011
44049
  const result = directParticipants(params);
44050
+ if (result.context?.progressExitStatus)
44051
+ Object.assign(context, result.context);
44012
44052
  if (result.error)
44013
44053
  return decorateResult({ result, stack });
44014
44054
  let qualifierReplaced, qualifierPlaced;
@@ -44025,41 +44065,19 @@ function attemptToSetWinningSide(params) {
44025
44065
  connectedStructures,
44026
44066
  qualifierReplaced,
44027
44067
  qualifierPlaced,
44068
+ context,
44028
44069
  }),
44029
44070
  stack,
44030
44071
  });
44031
44072
  }
44032
44073
 
44033
- const keyColors = {
44034
- drawPositionToRemove: 'green',
44035
- iteration: 'brightred',
44036
- winner: 'green',
44037
- loser: 'brightred',
44038
- };
44039
44074
  function removeDoubleExit(params) {
44040
44075
  const { inContextDrawMatchUps, appliedPolicies, drawDefinition, matchUpsMap, targetData, matchUp } = params;
44041
- const { matchUpId } = matchUp;
44042
44076
  let { iteration = 0 } = params;
44043
44077
  iteration += 1;
44044
44078
  const stack = 'removeDoubleExit';
44045
- pushGlobalLog({
44046
- color: 'brightyellow',
44047
- method: stack,
44048
- matchUpId,
44049
- iteration,
44050
- keyColors,
44051
- });
44052
44079
  const { targetMatchUps: { loserMatchUp, winnerMatchUp, loserTargetDrawPosition }, targetLinks: { loserTargetLink }, } = targetData;
44053
44080
  if (winnerMatchUp && winnerMatchUp.matchUpStatus !== BYE) {
44054
- const { stage, roundNumber, roundPosition, structureName } = winnerMatchUp;
44055
- pushGlobalLog({
44056
- winner: 'winner',
44057
- roundPosition,
44058
- structureName,
44059
- roundNumber,
44060
- keyColors,
44061
- stage,
44062
- });
44063
44081
  conditionallyRemoveDrawPosition({
44064
44082
  ...params,
44065
44083
  targetMatchUp: winnerMatchUp,
@@ -44087,16 +44105,6 @@ function removeDoubleExit(params) {
44087
44105
  drawDefinition,
44088
44106
  structureId: inContextLoserMatchUp.structureId,
44089
44107
  });
44090
- const { stage, roundNumber, roundPosition, feedRound, structureName } = loserMatchUp;
44091
- pushGlobalLog({
44092
- loser: 'loser',
44093
- roundPosition,
44094
- structureName,
44095
- roundNumber,
44096
- keyColors,
44097
- feedRound,
44098
- stage,
44099
- });
44100
44108
  if (appliedPolicies?.progression?.doubleExitPropagateBye || byePropagatedToLoserMatchUp) {
44101
44109
  removeDirectedBye({
44102
44110
  drawPosition: loserTargetDrawPosition,
@@ -44122,7 +44130,6 @@ function removeDoubleExit(params) {
44122
44130
  function conditionallyRemoveDrawPosition(params) {
44123
44131
  const { inContextDrawMatchUps, appliedPolicies, drawDefinition, sourceMatchUp, targetMatchUp, matchUpsMap, structure, iteration, } = params;
44124
44132
  const stack = 'conditionallyRemoveDrawPosition';
44125
- pushGlobalLog({ method: stack, structureName: structure?.structureName, iteration });
44126
44133
  const nextTargetData = positionTargets({
44127
44134
  matchUpId: targetMatchUp.matchUpId,
44128
44135
  inContextDrawMatchUps,
@@ -44162,17 +44169,6 @@ function conditionallyRemoveDrawPosition(params) {
44162
44169
  }
44163
44170
  }
44164
44171
  if (nextWinnerMatchUp && drawPositionToRemove) {
44165
- const { stage, roundNumber, roundPosition, structureName } = nextWinnerMatchUp;
44166
- pushGlobalLog({
44167
- method: 'removeDirectedWinner',
44168
- drawPositionToRemove,
44169
- color: 'brightgreen',
44170
- roundPosition,
44171
- structureName,
44172
- roundNumber,
44173
- keyColors,
44174
- stage,
44175
- });
44176
44172
  removeDirectedWinner({
44177
44173
  winningDrawPosition: drawPositionToRemove,
44178
44174
  winnerMatchUp: nextWinnerMatchUp,
@@ -44299,7 +44295,6 @@ function noDownstreamDependencies(params) {
44299
44295
  const removeScore = params.removeScore || (!timedTieMatchUp && ![INCOMPLETE, ABANDONED$1].includes(matchUpStatus || INCOMPLETE));
44300
44296
  const removeWinningSide = (params.isCollectionMatchUp && params.dualMatchUp.winningSide && !params.projectedWinningSide) ||
44301
44297
  (matchUp.winningSide && !winningSide && !checkScoreHasValue({ score }));
44302
- const statusNotTBP = matchUpStatus && matchUpStatus !== TO_BE_PLAYED;
44303
44298
  const removeDirected = (removeScore) => {
44304
44299
  let connectedStructures;
44305
44300
  const { structure, drawDefinition, dualMatchUp, disableAutoCalc } = params;
@@ -44329,9 +44324,11 @@ function noDownstreamDependencies(params) {
44329
44324
  return scoreModification(params);
44330
44325
  }
44331
44326
  const triggerDualWinningSide = [CANCELLED$1, ABANDONED$1].includes(matchUpStatus) && params.dualWinningSideChange;
44332
- const result = ((winningSide || triggerDualWinningSide) && attemptToSetWinningSide(params)) ||
44327
+ const statusNotToBePlayed = matchUpStatus && matchUpStatus !== TO_BE_PLAYED;
44328
+ const propagateExitStatus = params.propagateExitStatus && [WALKOVER$2, DEFAULTED].includes(matchUpStatus);
44329
+ const result = ((winningSide || triggerDualWinningSide || propagateExitStatus) && attemptToSetWinningSide(params)) ||
44333
44330
  (scoreWithNoWinningSide && removeDirected(removeScore)) ||
44334
- (statusNotTBP && attemptToSetMatchUpStatus(params)) ||
44331
+ (statusNotToBePlayed && attemptToSetMatchUpStatus(params)) ||
44335
44332
  (removeWinningSide && removeDirected(removeScore)) ||
44336
44333
  (matchUp && scoreModification({ ...params, removeScore: true })) || {
44337
44334
  ...SUCCESS,
@@ -45158,10 +45155,10 @@ function swapWinnerLoser(params) {
45158
45155
  }
45159
45156
 
45160
45157
  function setMatchUpState(params) {
45161
- const stack = 'setMatchUpStatus';
45158
+ const stack = 'setMatchUpState';
45162
45159
  if (params.matchUpStatus && [WALKOVER$2, DOUBLE_WALKOVER].includes(params.matchUpStatus))
45163
45160
  params.score = undefined;
45164
- const { allowChangePropagation, disableScoreValidation, tournamentRecords, tournamentRecord, disableAutoCalc, enableAutoCalc, drawDefinition, matchUpStatus, winningSide, matchUpId, event, score, } = params;
45161
+ const { allowChangePropagation, disableScoreValidation, propagateExitStatus, tournamentRecords, tournamentRecord, disableAutoCalc, enableAutoCalc, drawDefinition, matchUpStatus, winningSide, matchUpId, event, score, } = params;
45165
45162
  if (!drawDefinition)
45166
45163
  return { error: MISSING_DRAW_DEFINITION };
45167
45164
  if (matchUpStatus && [CANCELLED$1, INCOMPLETE, ABANDONED$1, TO_BE_PLAYED].includes(matchUpStatus) && winningSide)
@@ -45291,6 +45288,7 @@ function setMatchUpState(params) {
45291
45288
  Object.assign(appliedPolicies, params.policyDefinitions);
45292
45289
  const participantCheck = checkParticipants({
45293
45290
  assignedDrawPositions,
45291
+ propagateExitStatus,
45294
45292
  inContextMatchUp,
45295
45293
  appliedPolicies,
45296
45294
  drawDefinition,
@@ -45403,12 +45401,6 @@ function setMatchUpState(params) {
45403
45401
  return swapWinnerLoser(params);
45404
45402
  }
45405
45403
  const matchUpWinner = (winningSide && !matchUpTieId) || params.projectedWinningSide;
45406
- pushGlobalLog({
45407
- activeDownstream,
45408
- matchUpWinner,
45409
- method: stack,
45410
- winningSide,
45411
- });
45412
45404
  const result = (!activeDownstream && noDownstreamDependencies(params)) ||
45413
45405
  (matchUpWinner && winningSideWithDownstreamDependencies(params)) ||
45414
45406
  ((directingMatchUpStatus || params.autoCalcDisabled) && applyMatchUpValues(params)) || {
@@ -45464,7 +45456,7 @@ function applyMatchUpValues(params) {
45464
45456
  }
45465
45457
  return result;
45466
45458
  }
45467
- function checkParticipants({ assignedDrawPositions, inContextMatchUp, appliedPolicies, drawDefinition, matchUpStatus, structure, matchUp, }) {
45459
+ function checkParticipants({ assignedDrawPositions, propagateExitStatus, inContextMatchUp, appliedPolicies, drawDefinition, matchUpStatus, structure, matchUp, }) {
45468
45460
  if (appliedPolicies?.[POLICY_TYPE_SCORING]?.requireParticipantsForScoring === false)
45469
45461
  return { ...SUCCESS };
45470
45462
  const participantsCount = inContextMatchUp?.sides?.map((side) => side.participantId).filter(Boolean).length;
@@ -45480,10 +45472,16 @@ function checkParticipants({ assignedDrawPositions, inContextMatchUp, appliedPol
45480
45472
  positionAssignments
45481
45473
  ?.filter((assignment) => assignedDrawPositions.includes(assignment.drawPosition))
45482
45474
  .every((assignment) => assignment.participantId));
45475
+ if (matchUpStatus &&
45476
+ [WALKOVER$2, DEFAULTED, DOUBLE_WALKOVER].includes(matchUpStatus) &&
45477
+ participantsCount === 1 &&
45478
+ propagateExitStatus) {
45479
+ return { ...SUCCESS };
45480
+ }
45483
45481
  if (matchUpStatus && particicipantsRequiredMatchUpStatuses.includes(matchUpStatus) && !requiredParticipants) {
45484
45482
  return decorateResult({
45485
45483
  info: 'matchUpStatus requires assigned participants',
45486
- context: { matchUpStatus, requiredParticipants },
45484
+ context: { matchUpStatus, requiredParticipants, propagateExitStatus: propagateExitStatus, participantsCount },
45487
45485
  result: { error: INVALID_MATCHUP_STATUS },
45488
45486
  });
45489
45487
  }
@@ -45785,10 +45783,64 @@ function matchUpScore(params) {
45785
45783
  return { score: { sets, scoreStringSide1, scoreStringSide2 } };
45786
45784
  }
45787
45785
 
45786
+ function progressExitStatus({ sourceMatchUpStatusCodes, propagateExitStatus, sourceMatchUpStatus, loserParticipantId, tournamentRecord, drawDefinition, loserMatchUp, matchUpsMap, event, }) {
45787
+ const stack = 'progressExitStatus';
45788
+ const carryOverMatchUpStatus = ([WALKOVER$2, DEFAULTED].includes(sourceMatchUpStatus) && sourceMatchUpStatus) || WALKOVER$2;
45789
+ const inContextMatchUps = getAllDrawMatchUps({
45790
+ inContext: true,
45791
+ drawDefinition,
45792
+ matchUpsMap,
45793
+ })?.matchUps;
45794
+ let loserMatchUpStatus = carryOverMatchUpStatus;
45795
+ const updatedLoserMatchUp = inContextMatchUps?.find((m) => m.matchUpId === loserMatchUp?.matchUpId);
45796
+ if (updatedLoserMatchUp?.matchUpId && loserMatchUpStatus) {
45797
+ let winningSide = undefined;
45798
+ const statusCodes = updatedLoserMatchUp.matchUpStatusCodes?.map((sc) => (typeof sc === 'string' ? sc : 'WO')) ?? [];
45799
+ const loserParticipantSide = updatedLoserMatchUp.sides?.find((s) => s.participantId === loserParticipantId);
45800
+ if (loserParticipantSide?.sideNumber) {
45801
+ const participantsCount = updatedLoserMatchUp?.sides?.reduce((count, current) => {
45802
+ return current?.participantId ? count + 1 : count;
45803
+ }, 0);
45804
+ if (participantsCount === 1 && statusCodes.length === 0) {
45805
+ winningSide = loserParticipantSide.sideNumber === 1 ? 2 : 1;
45806
+ statusCodes[0] = sourceMatchUpStatusCodes[0];
45807
+ }
45808
+ else {
45809
+ if (![WALKOVER$2, DEFAULTED].includes(loserMatchUp.matchUpStatus)) {
45810
+ winningSide = loserParticipantSide.sideNumber === 1 ? 2 : 1;
45811
+ statusCodes[0] = sourceMatchUpStatusCodes[0];
45812
+ }
45813
+ else {
45814
+ const currentStatusCode = statusCodes[0];
45815
+ statusCodes[loserParticipantSide.sideNumber - 1] = sourceMatchUpStatusCodes[0];
45816
+ const otherSide = loserParticipantSide.sideNumber === 1 ? 2 : 1;
45817
+ statusCodes[otherSide - 1] = currentStatusCode;
45818
+ loserMatchUpStatus = DOUBLE_WALKOVER;
45819
+ winningSide = undefined;
45820
+ }
45821
+ }
45822
+ }
45823
+ const result = setMatchUpState({
45824
+ matchUpStatus: loserMatchUpStatus,
45825
+ matchUpId: loserMatchUp.matchUpId,
45826
+ matchUpStatusCodes: statusCodes,
45827
+ allowChangePropagation: true,
45828
+ propagateExitStatus,
45829
+ tournamentRecord,
45830
+ drawDefinition,
45831
+ winningSide,
45832
+ event,
45833
+ });
45834
+ return decorateResult({ result, stack, context: { progressExitStatus: true } });
45835
+ }
45836
+ return decorateResult({ result: { error: MISSING_MATCHUP }, stack });
45837
+ }
45838
+
45788
45839
  function setMatchUpStatus(params) {
45789
45840
  const paramsCheck = checkRequiredParameters(params, [{ [MATCHUP_ID]: true, [DRAW_DEFINITION]: true }]);
45790
45841
  if (paramsCheck.error)
45791
45842
  return paramsCheck;
45843
+ const stack = 'setMatchUpStatus';
45792
45844
  const tournamentRecords = resolveTournamentRecords(params);
45793
45845
  if (!params.drawDefinition) {
45794
45846
  const tournamentRecord = params.tournamentRecord ?? (params.tournamentId && tournamentRecords[params.tournamentId]);
@@ -45800,12 +45852,12 @@ function setMatchUpStatus(params) {
45800
45852
  tournamentRecord,
45801
45853
  });
45802
45854
  if (result.error)
45803
- return result;
45855
+ return decorateResult({ stack, result });
45804
45856
  if (result.drawDefinition)
45805
45857
  params.drawDefinition = result.drawDefinition;
45806
45858
  params.event = result.event;
45807
45859
  }
45808
- const { disableScoreValidation, policyDefinitions, tournamentRecord, disableAutoCalc, enableAutoCalc, drawDefinition, matchUpId, schedule, event, notes, } = params;
45860
+ const { disableScoreValidation, propagateExitStatus, policyDefinitions, tournamentRecord, disableAutoCalc, enableAutoCalc, drawDefinition, matchUpId, schedule, event, notes, } = params;
45809
45861
  const matchUpFormat = params.matchUpFormat || params.outcome?.matchUpFormat;
45810
45862
  const { policy } = findPolicy({
45811
45863
  policyType: POLICY_TYPE_SCORING,
@@ -45817,7 +45869,7 @@ function setMatchUpStatus(params) {
45817
45869
  undefined;
45818
45870
  const { outcome, setTBlast } = params;
45819
45871
  if (outcome?.winningSide && ![1, 2].includes(outcome.winningSide)) {
45820
- return { error: INVALID_WINNING_SIDE };
45872
+ return decorateResult({ result: { error: INVALID_WINNING_SIDE }, stack });
45821
45873
  }
45822
45874
  if (matchUpFormat) {
45823
45875
  const result = setMatchUpMatchUpFormat({
@@ -45828,20 +45880,21 @@ function setMatchUpStatus(params) {
45828
45880
  event,
45829
45881
  });
45830
45882
  if (result.error)
45831
- return result;
45883
+ return decorateResult({ stack, result });
45832
45884
  }
45833
45885
  if (outcome?.score?.sets && !outcome.score.scoreStringSide1) {
45834
45886
  const { score: scoreObject } = matchUpScore({ ...outcome, setTBlast });
45835
45887
  outcome.score = scoreObject;
45836
45888
  outcome.score.sets = outcome.score.sets.filter((set) => set.side1Score || set.side2Score || set.side1TiebreakScore || set.side2TiebreakScore);
45837
45889
  }
45838
- return setMatchUpState({
45890
+ const result = setMatchUpState({
45839
45891
  matchUpStatusCodes: outcome?.matchUpStatusCodes,
45840
45892
  matchUpStatus: outcome?.matchUpStatus,
45841
45893
  winningSide: outcome?.winningSide,
45842
45894
  allowChangePropagation,
45843
45895
  disableScoreValidation,
45844
45896
  score: outcome?.score,
45897
+ propagateExitStatus,
45845
45898
  tournamentRecords,
45846
45899
  policyDefinitions,
45847
45900
  tournamentRecord,
@@ -45854,6 +45907,30 @@ function setMatchUpStatus(params) {
45854
45907
  event,
45855
45908
  notes,
45856
45909
  });
45910
+ if (result.context?.progressExitStatus) {
45911
+ let iterate = true;
45912
+ let failsafe = 0;
45913
+ while (iterate && failsafe < 10) {
45914
+ iterate = false;
45915
+ failsafe += 1;
45916
+ const progressResult = progressExitStatus({
45917
+ sourceMatchUpStatusCodes: result.context.sourceMatchUpStatusCodes,
45918
+ sourceMatchUpStatus: result.context.sourceMatchUpStatus,
45919
+ loserParticipantId: result.context.loserParticipantId,
45920
+ propagateExitStatus: params.propagateExitStatus,
45921
+ tournamentRecord: params.tournamentRecord,
45922
+ loserMatchUp: result.context.loserMatchUp,
45923
+ matchUpsMap: result.context.matchUpsMap,
45924
+ drawDefinition: params.drawDefinition,
45925
+ event: params.event,
45926
+ });
45927
+ if (progressResult.context?.loserMatchUp) {
45928
+ Object.assign(result.context, progressResult.context);
45929
+ iterate = true;
45930
+ }
45931
+ }
45932
+ }
45933
+ return decorateResult({ result, stack });
45857
45934
  }
45858
45935
 
45859
45936
  function bulkMatchUpStatusUpdate(params) {