tods-competition-factory 2.2.30 → 2.2.32-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.32-beta.0';
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 });
@@ -1878,38 +1880,85 @@ function decorateResult({ context, result, stack, info }) {
1878
1880
  return result ?? { success: true };
1879
1881
  }
1880
1882
 
1881
- const ANY = 'ANY';
1882
- const MALE = 'MALE';
1883
- const MIXED = 'MIXED';
1884
- const OTHER$3 = 'OTHER';
1883
+ const FEMALE_ABBR = 'F';
1884
+ const OTHER_ABBR = 'O';
1885
+ const MIXED_ABBR = 'X';
1886
+ const MALE_ABBR = 'M';
1887
+ const ANY_ABBR = 'A';
1885
1888
  const FEMALE = 'FEMALE';
1889
+ const OTHER$3 = 'OTHER';
1890
+ const MIXED = 'MIXED';
1891
+ const MALE = 'MALE';
1892
+ const ANY = 'ANY';
1886
1893
  const genderConstants = {
1887
- ANY,
1888
- MALE,
1894
+ FEMALE_ABBR,
1895
+ OTHER_ABBR,
1896
+ MIXED_ABBR,
1897
+ MALE_ABBR,
1898
+ ANY_ABBR,
1889
1899
  FEMALE,
1890
1900
  MIXED,
1891
1901
  OTHER: OTHER$3,
1902
+ MALE,
1903
+ ANY,
1892
1904
  };
1893
1905
 
1906
+ function isFemale(gender) {
1907
+ return [FEMALE, FEMALE_ABBR].includes(gender);
1908
+ }
1909
+
1910
+ function isMale(gender) {
1911
+ return [MALE, MALE_ABBR].includes(gender);
1912
+ }
1913
+
1914
+ function isMixed(gender) {
1915
+ return [MIXED, MIXED_ABBR].includes(gender);
1916
+ }
1917
+
1918
+ function isAny(gender) {
1919
+ return [ANY, ANY_ABBR].includes(gender);
1920
+ }
1921
+
1922
+ function coercedGender(gender) {
1923
+ if (gender) {
1924
+ if (isFemale(gender))
1925
+ return FEMALE;
1926
+ if (isMixed(gender))
1927
+ return MIXED;
1928
+ if (isMale(gender))
1929
+ return MALE;
1930
+ if (isAny(gender))
1931
+ return ANY;
1932
+ }
1933
+ return OTHER$3;
1934
+ }
1935
+
1936
+ function isGendered(gender) {
1937
+ return isFemale(gender) || isMale(gender);
1938
+ }
1939
+
1894
1940
  const mixedGenderError = 'MIXED events can not contain mixed singles or { gender: ANY } collections';
1895
1941
  const anyMixedError = 'events with { gender: ANY } can not contain MIXED singles collections';
1896
1942
  function tieFormatGenderValidityCheck(params) {
1897
1943
  const stack = 'tieFormatGenderValidityCheck';
1898
1944
  const { referenceGender, matchUpType, gender } = params;
1899
- if (referenceGender && gender && [MALE, FEMALE].includes(referenceGender) && referenceGender !== gender)
1945
+ if (referenceGender &&
1946
+ gender &&
1947
+ isGendered(referenceGender) &&
1948
+ coercedGender(referenceGender) !== coercedGender(gender))
1900
1949
  return decorateResult({
1901
1950
  result: { valid: false, error: INVALID_GENDER },
1902
1951
  context: { gender },
1903
1952
  stack,
1904
1953
  });
1905
- if (referenceGender === MIXED && (gender === ANY || (gender === MIXED && matchUpType !== DOUBLES$1))) {
1954
+ if (isMixed(referenceGender) && (isAny(gender) || (isMixed(gender) && matchUpType !== DOUBLES$1))) {
1906
1955
  return decorateResult({
1907
1956
  result: { error: INVALID_GENDER, valid: false },
1908
1957
  info: mixedGenderError,
1909
1958
  stack,
1910
1959
  });
1911
1960
  }
1912
- if (referenceGender === ANY && gender === MIXED && matchUpType !== DOUBLES$1)
1961
+ if (isAny(referenceGender) && isMixed(gender) && matchUpType !== DOUBLES$1)
1913
1962
  return decorateResult({
1914
1963
  result: { error: INVALID_GENDER, valid: false },
1915
1964
  info: anyMixedError,
@@ -12291,7 +12340,7 @@ function purgeGlobalLog() {
12291
12340
  globalLog.length = 0;
12292
12341
  }
12293
12342
 
12294
- function assignDrawPositionBye({ provisionalPositioning, isPositionAction, tournamentRecord, drawDefinition, drawPosition, matchUpsMap, structureId, structure, event, }) {
12343
+ function assignDrawPositionBye({ provisionalPositioning, isPositionAction, tournamentRecord, drawDefinition, drawPosition, loserMatchUp, matchUpsMap, structureId, structure, event, }) {
12295
12344
  if (!drawDefinition)
12296
12345
  return { error: MISSING_DRAW_DEFINITION };
12297
12346
  if (!structure)
@@ -12314,8 +12363,9 @@ function assignDrawPositionBye({ provisionalPositioning, isPositionAction, tourn
12314
12363
  if (currentAssignment?.bye) {
12315
12364
  return { ...SUCCESS };
12316
12365
  }
12366
+ const hasPropagatedStatus = !!(loserMatchUp && matchUpsMap.drawMatchUps.find((m) => m.loserMatchUpId === loserMatchUp?.matchUpId && [DEFAULTED, WALKOVER$2].includes(m.matchUpStatus)));
12317
12367
  const drawPositionIsActive = activeDrawPositions?.includes(drawPosition);
12318
- if (drawPositionIsActive) {
12368
+ if (drawPositionIsActive && !hasPropagatedStatus) {
12319
12369
  return { error: DRAW_POSITION_ACTIVE };
12320
12370
  }
12321
12371
  const positionAssignment = positionAssignments?.find((assignment) => assignment.drawPosition === drawPosition);
@@ -12324,7 +12374,7 @@ function assignDrawPositionBye({ provisionalPositioning, isPositionAction, tourn
12324
12374
  const { filled, containsBye, assignedParticipantId } = drawPositionFilled(positionAssignment);
12325
12375
  if (containsBye)
12326
12376
  return { ...SUCCESS };
12327
- if (filled && !containsBye) {
12377
+ if (filled && !containsBye && !hasPropagatedStatus) {
12328
12378
  return decorateResult({ result: { error: DRAW_POSITION_ASSIGNED }, stack });
12329
12379
  }
12330
12380
  const appliedPolicies = getAppliedPolicies({
@@ -12348,6 +12398,9 @@ function assignDrawPositionBye({ provisionalPositioning, isPositionAction, tourn
12348
12398
  positionAssignments?.forEach((assignment) => {
12349
12399
  if (assignment.drawPosition === drawPosition) {
12350
12400
  assignment.bye = true;
12401
+ if (hasPropagatedStatus) {
12402
+ assignment.participantId = undefined;
12403
+ }
12351
12404
  }
12352
12405
  });
12353
12406
  if (structure.structureType === CONTAINER) {
@@ -14982,21 +15035,32 @@ function addEventEntries(params) {
14982
15035
  if (validSingles &&
14983
15036
  (!event.gender ||
14984
15037
  !genderEnforced ||
14985
- [MIXED, ANY].includes(event.gender) ||
14986
- event.gender === participant.person?.sex)) {
15038
+ isMixed(event.gender) ||
15039
+ isAny(event.gender) ||
15040
+ coercedGender(event.gender) === coercedGender(participant.person?.sex))) {
14987
15041
  return true;
14988
15042
  }
14989
15043
  if (validDoubles && !isUngrouped(entryStatus)) {
14990
15044
  return true;
14991
15045
  }
14992
15046
  if (event.eventType === DOUBLES$1 && participant.participantType === INDIVIDUAL && isUngrouped(entryStatus)) {
15047
+ if (event.gender &&
15048
+ genderEnforced &&
15049
+ !(isMixed(event.gender) || isAny(event.gender)) &&
15050
+ coercedGender(event.gender) !== coercedGender(participant.person?.sex)) {
15051
+ mismatchedGender.push({
15052
+ participantId: participant.participantId,
15053
+ sex: participant.person?.sex,
15054
+ });
15055
+ return false;
15056
+ }
14993
15057
  return true;
14994
15058
  }
14995
15059
  if (validSingles &&
14996
15060
  event.gender &&
14997
15061
  genderEnforced &&
14998
- ![MIXED, ANY].includes(event.gender) &&
14999
- event.gender !== participant.person?.sex) {
15062
+ !(isMixed(event.gender) || isAny(event.gender)) &&
15063
+ coercedGender(event.gender) !== coercedGender(participant.person?.sex)) {
15000
15064
  mismatchedGender.push({
15001
15065
  participantId: participant.participantId,
15002
15066
  sex: participant.person?.sex,
@@ -16646,6 +16710,7 @@ function assignMatchUpDrawPosition({ inContextDrawMatchUps, sourceMatchUpStatus,
16646
16710
  [DOUBLE_WALKOVER, DOUBLE_DEFAULT].includes(matchUp.matchUpStatus) &&
16647
16711
  matchUp.matchUpStatus) ||
16648
16712
  TO_BE_PLAYED;
16713
+ const isWalkover = !!([WALKOVER$2, DEFAULTED].includes(matchUp?.matchUpStatus) && matchUp?.winningSide);
16649
16714
  if (matchUp && positionAdded) {
16650
16715
  inContextDrawMatchUps =
16651
16716
  getAllDrawMatchUps({
@@ -16658,8 +16723,9 @@ function assignMatchUpDrawPosition({ inContextDrawMatchUps, sourceMatchUpStatus,
16658
16723
  inContextDrawMatchUps,
16659
16724
  drawPosition,
16660
16725
  matchUpId,
16661
- })) ||
16662
- undefined;
16726
+ }))
16727
+ || (isWalkover && matchUp.winningSide)
16728
+ || undefined;
16663
16729
  if (matchUp?.matchUpStatusCodes) {
16664
16730
  updateMatchUpStatusCodes({
16665
16731
  inContextDrawMatchUps,
@@ -16672,7 +16738,7 @@ function assignMatchUpDrawPosition({ inContextDrawMatchUps, sourceMatchUpStatus,
16672
16738
  Object.assign(matchUp, {
16673
16739
  drawPositions: updatedDrawPositions,
16674
16740
  winningSide: exitWinningSide,
16675
- matchUpStatus,
16741
+ matchUpStatus: isWalkover ? matchUp?.matchUpStatus : matchUpStatus,
16676
16742
  });
16677
16743
  modifyMatchUpNotice({
16678
16744
  tournamentId: tournamentRecord?.tournamentId,
@@ -16715,6 +16781,20 @@ function assignMatchUpDrawPosition({ inContextDrawMatchUps, sourceMatchUpStatus,
16715
16781
  }
16716
16782
  }
16717
16783
  }
16784
+ else if (positionAssigned && isWalkover) {
16785
+ if (winnerMatchUp) {
16786
+ const result = assignMatchUpDrawPosition({
16787
+ matchUpId: winnerMatchUp.matchUpId,
16788
+ inContextDrawMatchUps,
16789
+ tournamentRecord,
16790
+ drawDefinition,
16791
+ drawPosition,
16792
+ matchUpsMap,
16793
+ });
16794
+ if (result.error)
16795
+ return result;
16796
+ }
16797
+ }
16718
16798
  else if (winnerMatchUp && inContextMatchUp && !inContextMatchUp.feedRound) {
16719
16799
  const { pairedPreviousMatchUpIsDoubleExit } = getPairedPreviousMatchUpIsDoubleExit({
16720
16800
  targetMatchUp: matchUp,
@@ -23192,7 +23272,7 @@ function modifyMatchUpScore(params) {
23192
23272
  }
23193
23273
 
23194
23274
  function attemptToModifyScore(params) {
23195
- const { matchUpStatusCodes, matchUpStatus, structure, matchUp, dualMatchUp, inContextMatchUp, autoCalcDisabled } = params;
23275
+ const { propagateExitStatus, matchUpStatusCodes, autoCalcDisabled, inContextMatchUp, matchUpStatus, dualMatchUp, structure, matchUp, } = params;
23196
23276
  const matchUpStatusIsValid = isDirectingMatchUpStatus({ matchUpStatus }) ||
23197
23277
  ([CANCELLED$1, ABANDONED$1].includes(matchUpStatus) && dualMatchUp) ||
23198
23278
  autoCalcDisabled;
@@ -23202,13 +23282,15 @@ function attemptToModifyScore(params) {
23202
23282
  const hasAdHocSides = (isAdHoc({ structure }) && participantsCount === 1) || (matchUpStatus === DEFAULTED && participantsCount);
23203
23283
  const validToScore = hasAdHocSides ||
23204
23284
  drawPositionsAssignedParticipantIds({ structure, matchUp, inContextMatchUp }) ||
23205
- params.appliedPolicies?.[POLICY_TYPE_SCORING]?.requireParticipantsForScoring === false;
23285
+ params.appliedPolicies?.[POLICY_TYPE_SCORING]?.requireParticipantsForScoring === false ||
23286
+ ([WALKOVER$2, DEFAULTED].includes(matchUpStatus) && participantsCount === 1 && propagateExitStatus);
23206
23287
  if (!validToScore)
23207
23288
  return decorateResult({ result: { error: MISSING_ASSIGNMENTS }, stack });
23208
23289
  const removeScore = [WALKOVER$2].includes(matchUpStatus);
23209
23290
  const updatedMatchUpStatus = matchUpStatusIsValid ? matchUpStatus : (params.winningSide && COMPLETED$1) || INCOMPLETE;
23210
23291
  const result = modifyMatchUpScore({
23211
23292
  ...params,
23293
+ winningSide: params.winningSide,
23212
23294
  matchUpStatusCodes: (matchUpStatusIsValid && matchUpStatusCodes) || [],
23213
23295
  matchUpStatus: updatedMatchUpStatus,
23214
23296
  removeScore,
@@ -23724,7 +23806,7 @@ function directWinner({ winnerMatchUpDrawPositionIndex, inContextDrawMatchUps, p
23724
23806
  if (structure?.stage !== QUALIFYING) {
23725
23807
  const error = 'winner target position unavaiallble';
23726
23808
  console.log(error);
23727
- return { error };
23809
+ decorateResult({ stack, result: { error } });
23728
23810
  }
23729
23811
  }
23730
23812
  if (structure?.seedAssignments && structure.structureId !== targetStructureId) {
@@ -23788,7 +23870,7 @@ function directWinner({ winnerMatchUpDrawPositionIndex, inContextDrawMatchUps, p
23788
23870
  }
23789
23871
 
23790
23872
  function directLoser(params) {
23791
- const { loserMatchUpDrawPositionIndex, inContextDrawMatchUps, projectedWinningSide, sourceMatchUpStatus, loserDrawPosition, tournamentRecord, loserTargetLink, drawDefinition, loserMatchUp, dualMatchUp, matchUpsMap, event, } = params;
23873
+ const { loserMatchUpDrawPositionIndex, inContextDrawMatchUps, projectedWinningSide, propagateExitStatus, sourceMatchUpStatus, loserDrawPosition, tournamentRecord, loserTargetLink, drawDefinition, loserMatchUp, dualMatchUp, matchUpsMap, event, } = params;
23792
23874
  const stack = 'directLoser';
23793
23875
  const loserLinkCondition = loserTargetLink.linkCondition;
23794
23876
  const targetMatchUpDrawPositions = loserMatchUp.drawPositions || [];
@@ -23822,15 +23904,17 @@ function directLoser(params) {
23822
23904
  });
23823
23905
  const relevantAssignment = sourcePositionAssignments?.find((assignment) => assignment.drawPosition === loserDrawPosition);
23824
23906
  const loserParticipantId = relevantAssignment?.participantId;
23907
+ const context = { loserParticipantId };
23825
23908
  const targetStructureId = loserTargetLink.target.structureId;
23826
23909
  const { positionAssignments: targetPositionAssignments } = structureAssignedDrawPositions({
23827
23910
  structureId: targetStructureId,
23828
23911
  drawDefinition,
23829
23912
  });
23830
23913
  const targetMatchUpPositionAssignments = targetPositionAssignments?.filter(({ drawPosition }) => targetMatchUpDrawPositions.includes(drawPosition));
23831
- const loserAlreadyDirected = targetMatchUpPositionAssignments?.some((assignment) => assignment.participantId === loserParticipantId);
23914
+ const loserAlreadyDirected = targetMatchUpPositionAssignments?.some((assignment) => assignment.participantId && loserParticipantId && assignment.participantId === loserParticipantId);
23915
+ const validExitToPropagate = propagateExitStatus && [RETIRED$1, WALKOVER$2, DEFAULTED].includes(sourceMatchUpStatus || '');
23832
23916
  if (loserAlreadyDirected) {
23833
- return { ...SUCCESS };
23917
+ return { ...SUCCESS, stack };
23834
23918
  }
23835
23919
  const unfilledTargetMatchUpDrawPositions = targetMatchUpPositionAssignments
23836
23920
  ?.filter((assignment) => {
@@ -23844,11 +23928,15 @@ function directLoser(params) {
23844
23928
  const isFirstRoundValidDrawPosition = loserTargetLink.target.roundNumber === 1 && targetDrawPositionIsUnfilled;
23845
23929
  if (fedDrawPositionFMLC) {
23846
23930
  const result = loserLinkFedFMLC();
23931
+ if (result.context)
23932
+ Object.assign(context, result.context);
23847
23933
  if (result.error)
23848
23934
  return decorateResult({ result, stack });
23849
23935
  }
23850
23936
  else if (isFirstRoundValidDrawPosition) {
23851
23937
  const result = asssignLoserDrawPosition();
23938
+ if (result.context)
23939
+ Object.assign(context, result.context);
23852
23940
  if (result.error)
23853
23941
  return decorateResult({ result, stack });
23854
23942
  }
@@ -23868,6 +23956,9 @@ function directLoser(params) {
23868
23956
  });
23869
23957
  if (result.error)
23870
23958
  return decorateResult({ result, stack });
23959
+ if (!result.error && validExitToPropagate && propagateExitStatus) {
23960
+ return { stack, context: { progressExitStatus: true, loserParticipantId } };
23961
+ }
23871
23962
  }
23872
23963
  else {
23873
23964
  const error = !targetDrawPositionIsUnfilled ? DRAW_POSITION_OCCUPIED : INVALID_DRAW_POSITION;
@@ -23916,7 +24007,7 @@ function directLoser(params) {
23916
24007
  }
23917
24008
  }
23918
24009
  }
23919
- return { ...SUCCESS };
24010
+ return decorateResult({ result: { ...SUCCESS }, stack, context });
23920
24011
  function loserLinkFedFMLC() {
23921
24012
  const stack = 'loserLinkFedFMLC';
23922
24013
  if (validForConsolation) {
@@ -23950,6 +24041,9 @@ function directLoser(params) {
23950
24041
  event,
23951
24042
  })
23952
24043
  : { error: MISSING_PARTICIPANT_ID };
24044
+ if (!result.error && validExitToPropagate && propagateExitStatus) {
24045
+ return { stack, context: { progressExitStatus: true } };
24046
+ }
23953
24047
  return decorateResult({ result, stack: 'assignLoserDrawPosition' });
23954
24048
  }
23955
24049
  }
@@ -23962,7 +24056,7 @@ function directParticipants(params) {
23962
24056
  const matchUpStatusIsValid = isDirectingMatchUpStatus({
23963
24057
  matchUpStatus: params.matchUpStatus,
23964
24058
  });
23965
- const { dualWinningSideChange, projectedWinningSide, inContextDrawMatchUps, tournamentRecord, drawDefinition, matchUpStatus, dualMatchUp, matchUpsMap, winningSide, targetData, matchUpId, structure, matchUp, event, } = params;
24059
+ const { dualWinningSideChange, inContextDrawMatchUps, projectedWinningSide, propagateExitStatus, matchUpStatusCodes, tournamentRecord, drawDefinition, matchUpStatus, dualMatchUp, matchUpsMap, winningSide, targetData, matchUpId, structure, matchUp, event, } = params;
23966
24060
  const isCollectionMatchUp = Boolean(matchUp.collectionId);
23967
24061
  const isAdHocMatchUp = isAdHoc({ structure });
23968
24062
  let drawPositions = matchUp.drawPositions;
@@ -23992,6 +24086,7 @@ function directParticipants(params) {
23992
24086
  const losingIndex = 1 - winningIndex;
23993
24087
  const winningDrawPosition = drawPositions[winningIndex];
23994
24088
  const loserDrawPosition = drawPositions[losingIndex];
24089
+ const context = {};
23995
24090
  const { targetLinks: { loserTargetLink, winnerTargetLink, byeTargetLink }, targetMatchUps: { winnerMatchUpDrawPositionIndex, loserMatchUpDrawPositionIndex, winnerMatchUp, loserMatchUp, byeMatchUp, }, } = targetData;
23996
24091
  if (winnerMatchUp) {
23997
24092
  const result = directWinner({
@@ -24018,6 +24113,7 @@ function directParticipants(params) {
24018
24113
  loserMatchUpDrawPositionIndex,
24019
24114
  inContextDrawMatchUps,
24020
24115
  projectedWinningSide,
24116
+ propagateExitStatus,
24021
24117
  loserDrawPosition,
24022
24118
  tournamentRecord,
24023
24119
  loserTargetLink,
@@ -24027,6 +24123,14 @@ function directParticipants(params) {
24027
24123
  dualMatchUp,
24028
24124
  event,
24029
24125
  });
24126
+ if (result.context?.progressExitStatus) {
24127
+ Object.assign(context, result.context, {
24128
+ sourceMatchUpStatus: (matchUpStatusIsValid && matchUpStatus) || COMPLETED$1,
24129
+ sourceMatchUpStatusCodes: matchUpStatusCodes || [],
24130
+ loserMatchUp,
24131
+ matchUpsMap,
24132
+ });
24133
+ }
24030
24134
  if (result.error)
24031
24135
  return decorateResult({ result, stack });
24032
24136
  }
@@ -24044,11 +24148,11 @@ function directParticipants(params) {
24044
24148
  if (result.error)
24045
24149
  return decorateResult({ result, stack });
24046
24150
  }
24151
+ return decorateResult({ result: { ...SUCCESS, ...annotate }, stack, context });
24047
24152
  }
24048
24153
  else {
24049
24154
  return decorateResult({ result: { error: MISSING_DRAW_POSITIONS }, stack });
24050
24155
  }
24051
- return decorateResult({ result: { ...SUCCESS, ...annotate }, stack });
24052
24156
  }
24053
24157
 
24054
24158
  function generateAndPopulatePlayoffStructures(params) {
@@ -25600,7 +25704,7 @@ function getValidModifyAssignedPairAction({ tournamentParticipants, returnPartic
25600
25704
  }
25601
25705
 
25602
25706
  function isActiveDownstream(params) {
25603
- const { inContextDrawMatchUps, targetData, drawDefinition, relevantLink } = params;
25707
+ const { inContextDrawMatchUps, targetData, drawDefinition, relevantLink, matchUpStatus, score, winningSide, matchUpsMap } = params;
25604
25708
  const fmlcBYE = relevantLink?.linkCondition === FIRST_MATCHUP && targetData?.matchUp?.matchUpStatus === BYE;
25605
25709
  if (fmlcBYE)
25606
25710
  return false;
@@ -25615,11 +25719,19 @@ function isActiveDownstream(params) {
25615
25719
  const loserIndex = loserTargetData?.targetMatchUps?.loserMatchUpDrawPositionIndex;
25616
25720
  const propagatedLoserParticipant = loserExitPropagation?.sides[loserIndex]?.participant;
25617
25721
  const loserMatchUpExit = [DEFAULTED, WALKOVER$2].includes(loserMatchUp?.matchUpStatus) && !propagatedLoserParticipant;
25722
+ const isLoserMatchUpWO = [DEFAULTED, WALKOVER$2].includes(loserMatchUp?.matchUpStatus);
25723
+ const hasLoserMatchUpUpstreamWOMatches = !!matchUpsMap?.drawMatchUps.find((m) => m.loserMatchUpId === loserMatchUp?.matchUpId && [DEFAULTED, WALKOVER$2, WITHDRAWN].includes(m.matchUpStatus));
25724
+ const loserMatchUpParticipantsCount = loserMatchUp?.sides?.reduce((acc, current) => (current?.participant ? ++acc : acc), 0) ?? 0;
25725
+ const isLoserMatchUpWalkoverWithOnePlayer = loserMatchUp?.winningSide && isLoserMatchUpWO && loserMatchUpParticipantsCount === 1;
25726
+ const isClearScore = matchUpStatus === TO_BE_PLAYED && score?.scoreStringSide1 === '' && score?.scoreStringSide2 === '' && !winningSide;
25618
25727
  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)))) {
25728
+ if ((hasLoserMatchUpUpstreamWOMatches && loserMatchUp?.matchUpStatus === DOUBLE_WALKOVER && isClearScore) ||
25729
+ (hasLoserMatchUpUpstreamWOMatches && isLoserMatchUpWO && isClearScore) ||
25730
+ (!isLoserMatchUpWalkoverWithOnePlayer &&
25731
+ ((loserMatchUp?.winningSide && !loserMatchUpExit) ||
25732
+ (winnerMatchUp?.winningSide &&
25733
+ winnerDrawPositionsCount === 2 &&
25734
+ (!winnerMatchUp.feedRound || ![WALKOVER$2, DEFAULTED].includes(winnerMatchUp?.matchUpStatus)))))) {
25623
25735
  return true;
25624
25736
  }
25625
25737
  const winnerTargetData = winnerMatchUp &&
@@ -25763,7 +25875,7 @@ const matchUpActionConstants = {
25763
25875
  function collectionMatchUpActions({ specifiedPolicyDefinitions, inContextDrawMatchUps, matchUpParticipantIds, matchUpActionsPolicy, inContextMatchUp, policyActions, enforceGender, participantId, sideNumber, matchUpId, matchUp, drawId, side, }) {
25764
25876
  const validActions = [];
25765
25877
  const firstFoundSide = inContextMatchUp.sides?.find((side) => side.participant);
25766
- const assignedGender = inContextMatchUp.gender === MIXED &&
25878
+ const assignedGender = isMixed(inContextMatchUp.gender) &&
25767
25879
  inContextMatchUp.sideNumber &&
25768
25880
  inContextMatchUp.sides?.filter((side) => side.particiapntId).length === 1 &&
25769
25881
  firstFoundSide?.participant?.person?.sex;
@@ -25782,9 +25894,9 @@ function collectionMatchUpActions({ specifiedPolicyDefinitions, inContextDrawMat
25782
25894
  const inContextDualMatchUp = inContextDrawMatchUps?.find((drawMatchUp) => drawMatchUp.matchUpId === inContextMatchUp.matchUpTieId);
25783
25895
  const availableIndividualParticipants = inContextDualMatchUp?.sides?.map((side) => side?.participant?.individualParticipants?.filter(({ participantId, person }) => !existingParticipantIds?.includes(participantId) &&
25784
25896
  (!gender ||
25785
- gender === ANY ||
25897
+ isAny(gender) ||
25786
25898
  person.sex === gender ||
25787
- (gender === MIXED && !assignedGender) ||
25899
+ (isMixed(gender) && !assignedGender) ||
25788
25900
  (assignedGender && person.sex !== assignedGender))));
25789
25901
  const availableParticipants = sideNumber
25790
25902
  ? availableIndividualParticipants?.[sideNumber - 1]
@@ -27179,15 +27291,16 @@ function getValidGender(params) {
27179
27291
  [];
27180
27292
  const validPairGender = !eventGender ||
27181
27293
  !pairGender?.length ||
27182
- ANY === eventGender ||
27183
- ([MALE, FEMALE].includes(eventGender) && pairGender[0] === eventGender) ||
27184
- (MIXED === eventGender &&
27294
+ isAny(eventGender) ||
27295
+ (isGendered(eventGender) && coercedGender(pairGender[0]) === coercedGender(eventGender)) ||
27296
+ (isMixed(eventGender) &&
27185
27297
  ((pairGender.length === 1 && participant.individualParticipantIds?.length === 1) || pairGender.length === 2));
27186
27298
  const personGender = participant?.person?.sex;
27187
27299
  const validPersonGender = !participant?.person ||
27188
27300
  !eventGender ||
27189
- [ANY, MIXED].includes(eventGender) ||
27190
- ([MALE, FEMALE].includes(eventGender) && personGender === eventGender);
27301
+ isMixed(eventGender) ||
27302
+ isAny(eventGender) ||
27303
+ (isGendered(eventGender) && coercedGender(personGender) === coercedGender(eventGender));
27191
27304
  return !genderEnforced || (validPairGender && validPersonGender);
27192
27305
  }
27193
27306
 
@@ -39015,16 +39128,16 @@ function addEventEntryPairs(params) {
39015
39128
  const invalidParticipantIdPairs = participantIdPairs.filter((pair) => {
39016
39129
  if (pair.length !== 2)
39017
39130
  return true;
39018
- if (!event.gender || event.gender === ANY)
39131
+ if (!event.gender || isAny(event.gender))
39019
39132
  return false;
39020
39133
  if (!genderMap.has(pair[0]) || !genderMap.has(pair[1]))
39021
39134
  return true;
39022
39135
  const participantGenders = pair.map((id) => genderMap.get(id));
39023
- let invalidParticiapntGenders = (event.gender === MALE && (participantGenders[0] !== MALE || participantGenders[1] !== MALE)) ||
39024
- (event.gender === FEMALE && (participantGenders[0] !== FEMALE || participantGenders[1] !== FEMALE));
39025
- if (event.gender === MIXED) {
39136
+ let invalidParticiapntGenders = (isMale(event.gender) && (!isMale(participantGenders[0]) || !isMale(participantGenders[1]))) ||
39137
+ (isFemale(event.gender) && (!isFemale(participantGenders[0]) || !isFemale(participantGenders[1])));
39138
+ if (isMixed(event.gender)) {
39026
39139
  participantGenders.sort(stringSort);
39027
- if (participantGenders[0] !== FEMALE || participantGenders[1] !== MALE)
39140
+ if (!isFemale(participantGenders[0]) || !isMale(participantGenders[1]))
39028
39141
  invalidParticiapntGenders = true;
39029
39142
  }
39030
39143
  return invalidParticiapntGenders;
@@ -39386,8 +39499,10 @@ function generateEventsFromTieFormat(params) {
39386
39499
  for (const participant of params.tournamentRecord.participants ?? []) {
39387
39500
  if (individualParticipantIds?.includes(participant.participantId)) {
39388
39501
  const gender = participant.person?.sex;
39389
- if (gender && [MALE, FEMALE].includes(gender)) {
39390
- genderedParticipants[gender].push(participant.participantId);
39502
+ if (gender && isGendered(gender)) {
39503
+ const coerced = coercedGender(gender);
39504
+ if (coerced)
39505
+ genderedParticipants[coerced].push(participant.participantId);
39391
39506
  }
39392
39507
  }
39393
39508
  }
@@ -39407,9 +39522,9 @@ function generateEventsFromTieFormat(params) {
39407
39522
  };
39408
39523
  if (params.addEntriesFromTeams) {
39409
39524
  const entryStatus = eventType === DOUBLES_EVENT ? UNGROUPED : params.entryStatus || DIRECT_ACCEPTANCE;
39410
- const participantIds = eventGender === MIXED
39525
+ const participantIds = isMixed(eventGender)
39411
39526
  ? [...genderedParticipants[MALE], ...genderedParticipants[FEMALE]]
39412
- : (genderedParticipants[eventGender] ?? []);
39527
+ : (genderedParticipants[coercedGender(eventGender) || OTHER$3] ?? []);
39413
39528
  if (participantIds.length) {
39414
39529
  const result = addEventEntries({
39415
39530
  participantIds,
@@ -40876,9 +40991,9 @@ function getParticipantsProfile({ enteredParticipants }) {
40876
40991
  function checkGenderUpdates({ noFlightsNoDraws, enteredParticipantGenders, eventUpdates, stack }) {
40877
40992
  const validGender = !enteredParticipantGenders.length ||
40878
40993
  !eventUpdates.gender ||
40879
- eventUpdates.gender === ANY ||
40994
+ isAny(eventUpdates.gender) ||
40880
40995
  (enteredParticipantGenders.length === 1 && enteredParticipantGenders[0] === eventUpdates.gender) ||
40881
- (noFlightsNoDraws && eventUpdates.gender === MIXED);
40996
+ (noFlightsNoDraws && isMixed(eventUpdates.gender));
40882
40997
  return eventUpdates.gender && !validGender
40883
40998
  ? decorateResult({
40884
40999
  context: { gender: eventUpdates.gender, validGender },
@@ -41400,7 +41515,8 @@ function generateLineUps(params) {
41400
41515
  const participantIds = [];
41401
41516
  generateRange(0, singlesMatchUp ? 1 : 2).forEach((i) => {
41402
41517
  const nextParticipantId = typeSort?.find((participant) => {
41403
- const targetGender = gender && (([MALE, FEMALE].includes(gender) && gender) || (gender === MIXED && [MALE, FEMALE][i]));
41518
+ const coerced = coercedGender(gender);
41519
+ const targetGender = coerced && ((isGendered(gender) && coerced) || (isMixed(gender) && [MALE, FEMALE][i]));
41404
41520
  return ((!targetGender || targetGender === participant.person?.sex) &&
41405
41521
  !collectionParticipantIds.includes(participant.participantId));
41406
41522
  })?.participantId;
@@ -42203,8 +42319,8 @@ function replaceTieMatchUpParticipantId(params) {
42203
42319
  const newParticipant = targetParticipants.find(({ participantId }) => participantId === newParticipantId);
42204
42320
  const genderEnforced = (params.enforceGender ?? matchUpActionsPolicy?.participants?.enforceGender) !== false;
42205
42321
  if (genderEnforced &&
42206
- [MALE, FEMALE].includes(inContextTieMatchUp?.gender) &&
42207
- inContextTieMatchUp?.gender !== newParticipant?.person?.sex) {
42322
+ isGendered(inContextTieMatchUp?.gender) &&
42323
+ coercedGender(inContextTieMatchUp?.gender) !== coercedGender(newParticipant?.person?.sex)) {
42208
42324
  return { error: INVALID_PARTICIPANT, info: 'Gender mismatch' };
42209
42325
  }
42210
42326
  const substitutionProcessCodes = matchUpActionsPolicy?.processCodes?.substitution;
@@ -42664,8 +42780,8 @@ function assignTieMatchUpParticipantId(params) {
42664
42780
  POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
42665
42781
  const genderEnforced = (params.enforceGender ?? matchUpActionsPolicy?.participants?.enforceGender) !== false;
42666
42782
  if (genderEnforced &&
42667
- [MALE, FEMALE].includes(inContextTieMatchUp?.gender) &&
42668
- inContextTieMatchUp?.gender !== participantToAssign.person?.sex) {
42783
+ isGendered(inContextTieMatchUp?.gender) &&
42784
+ coercedGender(inContextTieMatchUp?.gender) !== coercedGender(participantToAssign.person?.sex)) {
42669
42785
  return { error: INVALID_PARTICIPANT, info: 'Gender mismatch' };
42670
42786
  }
42671
42787
  const { individualParticipantIds, participantType } = participantToAssign;
@@ -43362,6 +43478,10 @@ function removeDirectedLoser({ sourceMatchUpStatus, loserParticipantId, tourname
43362
43478
  delete assignment.participantId;
43363
43479
  }
43364
43480
  });
43481
+ if (sourceMatchUpId && sourceMatchUpStatus) {
43482
+ const targetMatchUp = matchUpsMap?.drawMatchUps?.find(({ matchUpId }) => matchUpId === loserMatchUp.matchUpId);
43483
+ targetMatchUp.matchUpStatusCodes = sourceMatchUpStatus === DOUBLE_WALKOVER ? ['WO', 'WO'] : [];
43484
+ }
43365
43485
  structure.seedAssignments = (structure.seedAssignments ?? []).filter((assignment) => assignment.participantId !== loserParticipantId);
43366
43486
  if (dualMatchUp) {
43367
43487
  const drawPositionSideIndex = loserMatchUp?.sides.reduce((sideIndex, side, i) => (side.drawPosition === relevantDrawPosition ? i : sideIndex), undefined);
@@ -43455,23 +43575,27 @@ function doubleExitAdvancement(params) {
43455
43575
  const { loserMatchUp, winnerMatchUp, loserTargetDrawPosition } = targetMatchUps;
43456
43576
  const loserMatchUpIsEmptyExit = [WALKOVER$2, DEFAULTED].includes(loserMatchUp?.matchUpStatus) &&
43457
43577
  !loserMatchUp.sides?.map((side) => side.participantId ?? side.participant).filter(Boolean).length;
43578
+ const loserMatchUpIsDoubleExit = loserMatchUp?.matchUpStatus === DOUBLE_WALKOVER;
43458
43579
  if (loserMatchUp && loserMatchUp.matchUpStatus !== BYE) {
43459
43580
  const { loserTargetLink } = targetLinks;
43460
- if (appliedPolicies?.progression?.doubleExitPropagateBye) {
43581
+ if (appliedPolicies?.progression?.doubleExitPropagateBye ||
43582
+ (loserMatchUp.feedRound && loserMatchUp.sides?.[0]?.participantFed)) {
43461
43583
  const result = advanceByeToLoserMatchUp({
43462
43584
  loserTargetDrawPosition,
43463
43585
  tournamentRecord,
43464
43586
  loserTargetLink,
43465
43587
  drawDefinition,
43588
+ loserMatchUp,
43466
43589
  matchUpsMap,
43467
43590
  event,
43468
43591
  });
43469
43592
  if (result.error)
43470
43593
  return decorateResult({ result, stack });
43471
43594
  }
43472
- else if (!loserMatchUpIsEmptyExit) {
43595
+ else if (!loserMatchUpIsDoubleExit) {
43473
43596
  const { feedRound, drawPositions, matchUpId } = loserMatchUp;
43474
- const walkoverWinningSide = feedRound ? 2 : 2 - drawPositions.indexOf(loserTargetDrawPosition);
43597
+ let walkoverWinningSide = feedRound ? 2 : 2 - drawPositions.indexOf(loserTargetDrawPosition);
43598
+ walkoverWinningSide = loserMatchUpIsEmptyExit ? loserMatchUp.winningSide : walkoverWinningSide;
43475
43599
  const result = conditionallyAdvanceDrawPosition({
43476
43600
  ...params,
43477
43601
  targetMatchUp: loserMatchUp,
@@ -43526,6 +43650,7 @@ function conditionallyAdvanceDrawPosition(params) {
43526
43650
  const { loserTargetLink } = targetLinks;
43527
43651
  const result = advanceByeToLoserMatchUp({
43528
43652
  loserTargetDrawPosition: nextLoserTargetDrawPosition,
43653
+ loserMatchUp: nextLoserMatchUp,
43529
43654
  tournamentRecord,
43530
43655
  loserTargetLink,
43531
43656
  drawDefinition,
@@ -43721,7 +43846,7 @@ function conditionallyAdvanceDrawPosition(params) {
43721
43846
  return decorateResult({ result: { ...SUCCESS }, stack });
43722
43847
  }
43723
43848
  function advanceByeToLoserMatchUp(params) {
43724
- const { loserTargetDrawPosition, tournamentRecord, loserTargetLink, drawDefinition, matchUpsMap, event } = params;
43849
+ const { loserTargetDrawPosition, tournamentRecord, loserTargetLink, drawDefinition, matchUpsMap, event, loserMatchUp, } = params;
43725
43850
  const structureId = loserTargetLink?.target?.structureId;
43726
43851
  const { structure } = findStructure({ drawDefinition, structureId });
43727
43852
  if (!structure)
@@ -43732,6 +43857,7 @@ function advanceByeToLoserMatchUp(params) {
43732
43857
  drawDefinition,
43733
43858
  structureId,
43734
43859
  matchUpsMap,
43860
+ loserMatchUp,
43735
43861
  event,
43736
43862
  });
43737
43863
  }
@@ -43777,8 +43903,9 @@ function attemptToSetMatchUpStatus(params) {
43777
43903
  (!directing && { error: UNRECOGNIZED_MATCHUP_STATUS }) ||
43778
43904
  (isDoubleExit && modifyScoreAndAdvanceDoubleExit(params)) ||
43779
43905
  (teamRoundRobinContext && scoreModification$1(params)) ||
43906
+ (params.propagateExitStatus && scoreModification$1(params)) ||
43780
43907
  decorateResult({
43781
- result: { error: INVALID_MATCHUP_STATUS },
43908
+ result: { error: INVALID_MATCHUP_STATUS, info: 'matchUpStatus: ' + matchUpStatus },
43782
43909
  stack,
43783
43910
  }));
43784
43911
  }
@@ -43990,6 +44117,7 @@ function placeQualifier(params) {
43990
44117
  function attemptToSetWinningSide(params) {
43991
44118
  const stack = 'attemptToSetWinningSide';
43992
44119
  let connectedStructures;
44120
+ const context = {};
43993
44121
  const { appliedPolicies, disableAutoCalc, drawDefinition, dualMatchUp, winningSide, structure, matchUp } = params;
43994
44122
  if (dualMatchUp?._disableAutoCalc && disableAutoCalc !== false) {
43995
44123
  return attemptToModifyScore(params);
@@ -44009,6 +44137,8 @@ function attemptToSetWinningSide(params) {
44009
44137
  return result;
44010
44138
  }
44011
44139
  const result = directParticipants(params);
44140
+ if (result.context?.progressExitStatus)
44141
+ Object.assign(context, result.context);
44012
44142
  if (result.error)
44013
44143
  return decorateResult({ result, stack });
44014
44144
  let qualifierReplaced, qualifierPlaced;
@@ -44025,6 +44155,7 @@ function attemptToSetWinningSide(params) {
44025
44155
  connectedStructures,
44026
44156
  qualifierReplaced,
44027
44157
  qualifierPlaced,
44158
+ context,
44028
44159
  }),
44029
44160
  stack,
44030
44161
  });
@@ -44299,7 +44430,6 @@ function noDownstreamDependencies(params) {
44299
44430
  const removeScore = params.removeScore || (!timedTieMatchUp && ![INCOMPLETE, ABANDONED$1].includes(matchUpStatus || INCOMPLETE));
44300
44431
  const removeWinningSide = (params.isCollectionMatchUp && params.dualMatchUp.winningSide && !params.projectedWinningSide) ||
44301
44432
  (matchUp.winningSide && !winningSide && !checkScoreHasValue({ score }));
44302
- const statusNotTBP = matchUpStatus && matchUpStatus !== TO_BE_PLAYED;
44303
44433
  const removeDirected = (removeScore) => {
44304
44434
  let connectedStructures;
44305
44435
  const { structure, drawDefinition, dualMatchUp, disableAutoCalc } = params;
@@ -44329,9 +44459,11 @@ function noDownstreamDependencies(params) {
44329
44459
  return scoreModification(params);
44330
44460
  }
44331
44461
  const triggerDualWinningSide = [CANCELLED$1, ABANDONED$1].includes(matchUpStatus) && params.dualWinningSideChange;
44332
- const result = ((winningSide || triggerDualWinningSide) && attemptToSetWinningSide(params)) ||
44462
+ const statusNotToBePlayed = matchUpStatus && matchUpStatus !== TO_BE_PLAYED;
44463
+ const propagateExitStatus = params.propagateExitStatus && [WALKOVER$2, DEFAULTED].includes(matchUpStatus);
44464
+ const result = ((winningSide || triggerDualWinningSide || propagateExitStatus) && attemptToSetWinningSide(params)) ||
44333
44465
  (scoreWithNoWinningSide && removeDirected(removeScore)) ||
44334
- (statusNotTBP && attemptToSetMatchUpStatus(params)) ||
44466
+ (statusNotToBePlayed && attemptToSetMatchUpStatus(params)) ||
44335
44467
  (removeWinningSide && removeDirected(removeScore)) ||
44336
44468
  (matchUp && scoreModification({ ...params, removeScore: true })) || {
44337
44469
  ...SUCCESS,
@@ -45161,7 +45293,7 @@ function setMatchUpState(params) {
45161
45293
  const stack = 'setMatchUpStatus';
45162
45294
  if (params.matchUpStatus && [WALKOVER$2, DOUBLE_WALKOVER].includes(params.matchUpStatus))
45163
45295
  params.score = undefined;
45164
- const { allowChangePropagation, disableScoreValidation, tournamentRecords, tournamentRecord, disableAutoCalc, enableAutoCalc, drawDefinition, matchUpStatus, winningSide, matchUpId, event, score, } = params;
45296
+ const { allowChangePropagation, disableScoreValidation, propagateExitStatus, tournamentRecords, tournamentRecord, disableAutoCalc, enableAutoCalc, drawDefinition, matchUpStatus, winningSide, matchUpId, event, score, } = params;
45165
45297
  if (!drawDefinition)
45166
45298
  return { error: MISSING_DRAW_DEFINITION };
45167
45299
  if (matchUpStatus && [CANCELLED$1, INCOMPLETE, ABANDONED$1, TO_BE_PLAYED].includes(matchUpStatus) && winningSide)
@@ -45291,6 +45423,7 @@ function setMatchUpState(params) {
45291
45423
  Object.assign(appliedPolicies, params.policyDefinitions);
45292
45424
  const participantCheck = checkParticipants({
45293
45425
  assignedDrawPositions,
45426
+ propagateExitStatus,
45294
45427
  inContextMatchUp,
45295
45428
  appliedPolicies,
45296
45429
  drawDefinition,
@@ -45464,7 +45597,7 @@ function applyMatchUpValues(params) {
45464
45597
  }
45465
45598
  return result;
45466
45599
  }
45467
- function checkParticipants({ assignedDrawPositions, inContextMatchUp, appliedPolicies, drawDefinition, matchUpStatus, structure, matchUp, }) {
45600
+ function checkParticipants({ assignedDrawPositions, propagateExitStatus, inContextMatchUp, appliedPolicies, drawDefinition, matchUpStatus, structure, matchUp, }) {
45468
45601
  if (appliedPolicies?.[POLICY_TYPE_SCORING]?.requireParticipantsForScoring === false)
45469
45602
  return { ...SUCCESS };
45470
45603
  const participantsCount = inContextMatchUp?.sides?.map((side) => side.participantId).filter(Boolean).length;
@@ -45480,6 +45613,12 @@ function checkParticipants({ assignedDrawPositions, inContextMatchUp, appliedPol
45480
45613
  positionAssignments
45481
45614
  ?.filter((assignment) => assignedDrawPositions.includes(assignment.drawPosition))
45482
45615
  .every((assignment) => assignment.participantId));
45616
+ if (matchUpStatus &&
45617
+ [WALKOVER$2, DEFAULTED, DOUBLE_WALKOVER].includes(matchUpStatus) &&
45618
+ participantsCount === 1 &&
45619
+ propagateExitStatus) {
45620
+ return { ...SUCCESS };
45621
+ }
45483
45622
  if (matchUpStatus && particicipantsRequiredMatchUpStatuses.includes(matchUpStatus) && !requiredParticipants) {
45484
45623
  return decorateResult({
45485
45624
  info: 'matchUpStatus requires assigned participants',
@@ -45785,10 +45924,70 @@ function matchUpScore(params) {
45785
45924
  return { score: { sets, scoreStringSide1, scoreStringSide2 } };
45786
45925
  }
45787
45926
 
45927
+ function progressExitStatus({ sourceMatchUpStatusCodes, propagateExitStatus, sourceMatchUpStatus, loserParticipantId, tournamentRecord, drawDefinition, loserMatchUp, matchUpsMap, event, }) {
45928
+ const stack = 'progressExitStatus';
45929
+ pushGlobalLog({
45930
+ matchUpId: loserMatchUp?.matchUpId,
45931
+ matchUpStatus: sourceMatchUpStatus,
45932
+ color: 'magenta',
45933
+ method: stack,
45934
+ });
45935
+ const carryOverMatchUpStatus = ([WALKOVER$2, DEFAULTED].includes(sourceMatchUpStatus) && sourceMatchUpStatus) || WALKOVER$2;
45936
+ const inContextMatchUps = getAllDrawMatchUps({
45937
+ inContext: true,
45938
+ drawDefinition,
45939
+ matchUpsMap,
45940
+ })?.matchUps;
45941
+ let loserMatchUpStatus = carryOverMatchUpStatus;
45942
+ const updatedLoserMatchUp = inContextMatchUps?.find((m) => m.matchUpId === loserMatchUp?.matchUpId);
45943
+ if (updatedLoserMatchUp?.matchUpId && loserMatchUpStatus) {
45944
+ let winningSide = undefined;
45945
+ const statusCodes = updatedLoserMatchUp.matchUpStatusCodes?.map((sc) => (typeof sc === 'string' ? sc : OUTCOME_WALKOVER)) ?? [];
45946
+ const loserParticipantSide = updatedLoserMatchUp.sides?.find((s) => s.participantId === loserParticipantId);
45947
+ if (loserParticipantSide?.sideNumber) {
45948
+ const participantsCount = updatedLoserMatchUp?.sides?.reduce((count, current) => {
45949
+ return current?.participantId ? count + 1 : count;
45950
+ }, 0);
45951
+ if (participantsCount === 1 && statusCodes.length === 0) {
45952
+ winningSide = loserParticipantSide.sideNumber === 1 ? 2 : 1;
45953
+ statusCodes[0] = sourceMatchUpStatusCodes[0];
45954
+ }
45955
+ else {
45956
+ if (![WALKOVER$2, DEFAULTED].includes(loserMatchUp.matchUpStatus)) {
45957
+ winningSide = loserParticipantSide.sideNumber === 1 ? 2 : 1;
45958
+ statusCodes[0] = sourceMatchUpStatusCodes[0];
45959
+ }
45960
+ else {
45961
+ const currentStatusCode = statusCodes[0];
45962
+ statusCodes[loserParticipantSide.sideNumber - 1] = sourceMatchUpStatusCodes[0];
45963
+ const otherSide = loserParticipantSide.sideNumber === 1 ? 2 : 1;
45964
+ statusCodes[otherSide - 1] = currentStatusCode;
45965
+ loserMatchUpStatus = DOUBLE_WALKOVER;
45966
+ winningSide = undefined;
45967
+ }
45968
+ }
45969
+ }
45970
+ const result = setMatchUpState({
45971
+ matchUpStatus: loserMatchUpStatus,
45972
+ matchUpId: loserMatchUp.matchUpId,
45973
+ matchUpStatusCodes: statusCodes,
45974
+ allowChangePropagation: true,
45975
+ propagateExitStatus,
45976
+ tournamentRecord,
45977
+ drawDefinition,
45978
+ winningSide,
45979
+ event,
45980
+ });
45981
+ return decorateResult({ result, stack, context: { progressExitStatus: true } });
45982
+ }
45983
+ return decorateResult({ result: { error: MISSING_MATCHUP }, stack });
45984
+ }
45985
+
45788
45986
  function setMatchUpStatus(params) {
45789
45987
  const paramsCheck = checkRequiredParameters(params, [{ [MATCHUP_ID]: true, [DRAW_DEFINITION]: true }]);
45790
45988
  if (paramsCheck.error)
45791
45989
  return paramsCheck;
45990
+ const stack = 'setMatchUpStatus';
45792
45991
  const tournamentRecords = resolveTournamentRecords(params);
45793
45992
  if (!params.drawDefinition) {
45794
45993
  const tournamentRecord = params.tournamentRecord ?? (params.tournamentId && tournamentRecords[params.tournamentId]);
@@ -45805,7 +46004,7 @@ function setMatchUpStatus(params) {
45805
46004
  params.drawDefinition = result.drawDefinition;
45806
46005
  params.event = result.event;
45807
46006
  }
45808
- const { disableScoreValidation, policyDefinitions, tournamentRecord, disableAutoCalc, enableAutoCalc, drawDefinition, matchUpId, schedule, event, notes, } = params;
46007
+ const { disableScoreValidation, propagateExitStatus, policyDefinitions, tournamentRecord, disableAutoCalc, enableAutoCalc, drawDefinition, matchUpId, schedule, event, notes, } = params;
45809
46008
  const matchUpFormat = params.matchUpFormat || params.outcome?.matchUpFormat;
45810
46009
  const { policy } = findPolicy({
45811
46010
  policyType: POLICY_TYPE_SCORING,
@@ -45835,13 +46034,14 @@ function setMatchUpStatus(params) {
45835
46034
  outcome.score = scoreObject;
45836
46035
  outcome.score.sets = outcome.score.sets.filter((set) => set.side1Score || set.side2Score || set.side1TiebreakScore || set.side2TiebreakScore);
45837
46036
  }
45838
- return setMatchUpState({
46037
+ const result = setMatchUpState({
45839
46038
  matchUpStatusCodes: outcome?.matchUpStatusCodes,
45840
46039
  matchUpStatus: outcome?.matchUpStatus,
45841
46040
  winningSide: outcome?.winningSide,
45842
46041
  allowChangePropagation,
45843
46042
  disableScoreValidation,
45844
46043
  score: outcome?.score,
46044
+ propagateExitStatus,
45845
46045
  tournamentRecords,
45846
46046
  policyDefinitions,
45847
46047
  tournamentRecord,
@@ -45854,6 +46054,30 @@ function setMatchUpStatus(params) {
45854
46054
  event,
45855
46055
  notes,
45856
46056
  });
46057
+ if (result.context?.progressExitStatus) {
46058
+ let iterate = true;
46059
+ let failsafe = 0;
46060
+ while (iterate && failsafe < 10) {
46061
+ iterate = false;
46062
+ failsafe += 1;
46063
+ const progressResult = progressExitStatus({
46064
+ sourceMatchUpStatusCodes: result.context.sourceMatchUpStatusCodes,
46065
+ sourceMatchUpStatus: result.context.sourceMatchUpStatus,
46066
+ loserParticipantId: result.context.loserParticipantId,
46067
+ propagateExitStatus: params.propagateExitStatus,
46068
+ tournamentRecord: params.tournamentRecord,
46069
+ loserMatchUp: result.context.loserMatchUp,
46070
+ matchUpsMap: result.context.matchUpsMap,
46071
+ drawDefinition: params.drawDefinition,
46072
+ event: params.event,
46073
+ });
46074
+ if (progressResult.context?.loserMatchUp) {
46075
+ Object.assign(result.context, progressResult.context);
46076
+ iterate = true;
46077
+ }
46078
+ }
46079
+ }
46080
+ return decorateResult({ result, stack });
45857
46081
  }
45858
46082
 
45859
46083
  function bulkMatchUpStatusUpdate(params) {
@@ -48847,7 +49071,7 @@ var namesData$1 = {
48847
49071
 
48848
49072
  function generatePersonData(params) {
48849
49073
  const { count = 100, sex } = params || {};
48850
- if (!count || (sex && ![MALE, FEMALE].includes(sex)))
49074
+ if (!count || (sex && !isGendered(sex)))
48851
49075
  return { personData: [], error: INVALID_VALUES };
48852
49076
  const buffer = Math.ceil(count * 1.3);
48853
49077
  const { lastNames, firstFemale, firstMale } = namesData$1;
@@ -48889,8 +49113,8 @@ function generatePersons(params) {
48889
49113
  const { personExtensions, consideredDate, isMock = true, gendersCount, personData, category, sex } = params || {};
48890
49114
  if (isNaN(count))
48891
49115
  return { error: INVALID_VALUES };
48892
- const maleCount = gendersCount?.[MALE] || (sex === MALE && count) || 0;
48893
- const femaleCount = gendersCount?.[FEMALE] || (sex === FEMALE && count) || 0;
49116
+ const maleCount = gendersCount?.[MALE] || (isMale(sex) && count) || 0;
49117
+ const femaleCount = gendersCount?.[FEMALE] || (isFemale(sex) && count) || 0;
48894
49118
  count = Math.max(count, maleCount + femaleCount);
48895
49119
  const defaultCount = count - (maleCount + femaleCount);
48896
49120
  const defaultMalePersonData = (maleCount &&
@@ -49373,12 +49597,13 @@ function processTieFormat(params) {
49373
49597
  const tieFormat = isObject(params.tieFormat) ? params.tieFormat : tieFormatDefaults({ namedFormat: tieFormatName });
49374
49598
  tieFormat?.collectionDefinitions?.filter(Boolean).forEach((collectionDefinition) => {
49375
49599
  const { category, collectionId, matchUpType, matchUpCount, gender } = collectionDefinition;
49376
- if ([MALE, FEMALE].includes(gender)) {
49600
+ if (isGendered(gender)) {
49601
+ const coerced = coercedGender(gender);
49377
49602
  const required = matchUpCount * (matchUpType === DOUBLES$1 ? 2 : 1);
49378
- if (genders[gender] < required)
49379
- genders[gender] = required;
49603
+ if (coerced && genders[coerced] < required)
49604
+ genders[coerced] = required;
49380
49605
  }
49381
- else if (gender === MIXED) {
49606
+ else if (isMixed(gender)) {
49382
49607
  if (genders[MALE] < matchUpCount)
49383
49608
  genders[MALE] = matchUpCount;
49384
49609
  if (genders[FEMALE] < matchUpCount)
@@ -50177,7 +50402,7 @@ function generateEventParticipants(params) {
50177
50402
  const participantsCount = eventProfile.drawProfiles?.length
50178
50403
  ? mainParticipantsCount + qualifyingParticipantsCount
50179
50404
  : (eventProfile.participantsProfile?.participantsCount ?? 0);
50180
- const sex = [MALE, FEMALE].includes(gender) ? gender : undefined;
50405
+ const sex = isGendered(gender) ? gender : undefined;
50181
50406
  const idPrefix = participantsProfile?.idPrefix ? `E-${eventIndex}-${participantsProfile?.idPrefix}` : undefined;
50182
50407
  const { participants: uniqueFlightParticipants } = generateParticipants({
50183
50408
  uuids: eventProfile.uuids || uuids,
@@ -50576,8 +50801,9 @@ function generateEventWithDraw(params) {
50576
50801
  drawSize,
50577
50802
  }));
50578
50803
  Object.keys(genders).forEach((key) => {
50579
- if ([MALE, FEMALE].includes(key) && genders[key]) {
50580
- gendersCount[key] = drawSize * genders[key];
50804
+ const coerced = coercedGender(key);
50805
+ if (coerced && isGendered(key) && genders[coerced]) {
50806
+ gendersCount[coerced] = drawSize * genders[coerced];
50581
50807
  }
50582
50808
  });
50583
50809
  individualParticipantCount = teamSize * ((drawSize || 0) + qualifyingParticipantsCount);
@@ -50618,7 +50844,7 @@ function generateEventWithDraw(params) {
50618
50844
  : [];
50619
50845
  const femaleIndividualParticipantIds = genders[FEMALE]
50620
50846
  ? unique
50621
- .filter(({ participantType, person }) => participantType === INDIVIDUAL && person?.sex === FEMALE)
50847
+ .filter(({ participantType, person }) => participantType === INDIVIDUAL && isFemale(person?.sex))
50622
50848
  .map(getParticipantId)
50623
50849
  : [];
50624
50850
  const remainingParticipantIds = unique
@@ -51652,8 +51878,9 @@ function anonymizeTournamentRecord({ keepExtensions = [], anonymizeParticipantNa
51652
51878
  const individualParticipants = (tournamentRecord.participants || []).filter(({ participantType }) => participantType === INDIVIDUAL);
51653
51879
  const gendersCount = individualParticipants.reduce((counts, participant) => {
51654
51880
  const gender = participant.person?.sex;
51655
- if ([MALE, FEMALE].includes(gender)) {
51656
- counts[gender] += 1;
51881
+ const coerced = coercedGender(gender);
51882
+ if (coerced && isGendered(gender)) {
51883
+ counts[coerced] += 1;
51657
51884
  }
51658
51885
  else {
51659
51886
  counts[OTHER$3] += 1;