tods-competition-factory 2.0.32 → 2.0.33

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.0.32';
6
+ return '2.0.33';
7
7
  }
8
8
 
9
9
  function isFunction(obj) {
@@ -2704,7 +2704,6 @@ function findExtension({ discover, element, name, ...params }) {
2704
2704
 
2705
2705
  const ACTIVE_SUSPENSION = 'activeSuspension';
2706
2706
  const APPLIED_POLICIES = 'appliedPolicies';
2707
- const AUDIT_POSITION_ACTIONS = 'positionActions';
2708
2707
  const CONTEXT = 'context';
2709
2708
  const DELEGATED_OUTCOME = 'delegatedOutcome';
2710
2709
  const DISABLED = 'disabled';
@@ -2723,6 +2722,7 @@ const LINKED_TOURNAMENTS = 'linkedTournamentsIds';
2723
2722
  const MATCHUP_HISTORY = 'matchUpHistory';
2724
2723
  const PARTICIPANT_REPRESENTATIVES = 'participantRepresentatives';
2725
2724
  const PERSON_REQUESTS = 'personRequests';
2725
+ const POSITION_ACTIONS = 'positionActions';
2726
2726
  const RANKING_POINTS = 'rankingPoints';
2727
2727
  const ROUND_TARGET = 'roundTarget';
2728
2728
  const SCHEDULE_LIMITS = 'scheduleLimits';
@@ -2735,7 +2735,6 @@ const TIE_FORMAT_MODIFICATIONS = 'tieFormatModification';
2735
2735
  const extensionConstants = {
2736
2736
  ACTIVE_SUSPENSION,
2737
2737
  APPLIED_POLICIES,
2738
- AUDIT_POSITION_ACTIONS,
2739
2738
  CONTEXT,
2740
2739
  DELEGATED_OUTCOME,
2741
2740
  DISABLED,
@@ -2753,6 +2752,7 @@ const extensionConstants = {
2753
2752
  MATCHUP_HISTORY,
2754
2753
  PARTICIPANT_REPRESENTATIVES,
2755
2754
  PERSON_REQUESTS,
2755
+ POSITION_ACTIONS,
2756
2756
  RANKING_POINTS,
2757
2757
  ROUND_TARGET,
2758
2758
  SCHEDULE_LIMITS,
@@ -3094,6 +3094,7 @@ const FEED_IN_CHAMPIONSHIP_TO_R16 = 'FEED_IN_CHAMPIONSHIP_TO_R16';
3094
3094
  const MFIC = 'MODIFIED_FEED_IN_CHAMPIONSHIP';
3095
3095
  const MODIFIED_FEED_IN_CHAMPIONSHIP = 'MODIFIED_FEED_IN_CHAMPIONSHIP';
3096
3096
  const FEED_IN_CHAMPIONSHIP = 'FEED_IN_CHAMPIONSHIP';
3097
+ const DOUBLE_ROUND_ROBIN = 'DOUBLE_ROUND_ROBIN';
3097
3098
  const ROUND_ROBIN = 'ROUND_ROBIN';
3098
3099
  const ROUND_ROBIN_WITH_PLAYOFF = 'ROUND_ROBIN_WITH_PLAYOFF';
3099
3100
  const DECIDER = 'DECIDER';
@@ -3618,9 +3619,12 @@ function conditionallyDisableLinkPositioning({ drawPositions, structure }) {
3618
3619
  });
3619
3620
  }
3620
3621
 
3621
- function addPositionActionTelemetry({ drawDefinition, positionAction }) {
3622
+ function addPositionActionTelemetry(params) {
3623
+ const { appliedPolicies, positionAction, drawDefinition } = params;
3624
+ if (appliedPolicies?.audit?.[POSITION_ACTIONS] === false)
3625
+ return;
3622
3626
  const { extension } = findExtension({
3623
- name: AUDIT_POSITION_ACTIONS,
3627
+ name: POSITION_ACTIONS,
3624
3628
  element: drawDefinition,
3625
3629
  });
3626
3630
  const existingValue = Array.isArray(extension?.value) ? extension?.value ?? [] : [];
@@ -3642,8 +3646,8 @@ function addPositionActionTelemetry({ drawDefinition, positionAction }) {
3642
3646
  }
3643
3647
  }
3644
3648
  const updatedExtension = {
3645
- name: AUDIT_POSITION_ACTIONS,
3646
3649
  value: existingValue.concat(positionAction),
3650
+ name: POSITION_ACTIONS,
3647
3651
  };
3648
3652
  addExtension({ element: drawDefinition, extension: updatedExtension });
3649
3653
  }
@@ -6371,6 +6375,7 @@ const ASSIGN_COURT = 'SCHEDULE.ASSIGNMENT.COURT';
6371
6375
  const COURT_ORDER = 'SCHEDULE.COURT.ORDER';
6372
6376
  const SCHEDULED_DATE = 'SCHEDULE.DATE';
6373
6377
  const COMPLETED_DATE = 'COMPLETED.DATE';
6378
+ const HOME_PARTICIPANT_ID = 'HOME_PARTICIPANT_ID';
6374
6379
  const ASSIGN_OFFICIAL = 'SCHEDULE.ASSIGN.OFFICIAL';
6375
6380
  const SCHEDULED_TIME = 'SCHEDULE.TIME.SCHEDULED';
6376
6381
  const START_TIME = 'SCHEDULE.TIME.START';
@@ -6725,7 +6730,7 @@ function matchUpAssignedCourtId({ visibilityThreshold, timeStamp, schedule, matc
6725
6730
  : schedule;
6726
6731
  }
6727
6732
 
6728
- function matchUpAssignedVenueId({ visibilityThreshold, timeStamp, schedule, matchUp, }) {
6733
+ function matchUpAssignedVenueId({ visibilityThreshold, timeStamp, schedule, matchUp }) {
6729
6734
  const { itemValue: venueId, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
6730
6735
  timeItems: matchUp?.timeItems || [],
6731
6736
  itemType: ASSIGN_VENUE,
@@ -7161,6 +7166,17 @@ function findEvent(params) {
7161
7166
  };
7162
7167
  }
7163
7168
 
7169
+ function getHomeParticipantId({ visibilityThreshold, timeStamp, schedule, matchUp }) {
7170
+ const { itemValue: homeParticipantId, timeStamp: itemTimeStamp } = latestVisibleTimeItemValue({
7171
+ timeItems: matchUp?.timeItems || [],
7172
+ itemType: HOME_PARTICIPANT_ID,
7173
+ visibilityThreshold,
7174
+ });
7175
+ return !schedule || (itemTimeStamp && timeStamp && new Date(itemTimeStamp).getTime() > new Date(timeStamp).getTime())
7176
+ ? { homeParticipantId }
7177
+ : schedule;
7178
+ }
7179
+
7164
7180
  function getMatchUpScheduleDetails(params) {
7165
7181
  let event = params.event;
7166
7182
  let matchUpType = params.matchUpType;
@@ -7194,12 +7210,13 @@ function getMatchUpScheduleDetails(params) {
7194
7210
  if ((!eventIds || eventIds.includes(matchUp.eventId)) && (!drawIds || drawIds.includes(matchUp.drawId))) {
7195
7211
  const scheduleSource = { matchUp, visibilityThreshold };
7196
7212
  const { allocatedCourts } = matchUpAllocatedCourts(scheduleSource);
7213
+ const { homeParticipantId } = getHomeParticipantId(scheduleSource);
7197
7214
  const { scheduledTime } = scheduledMatchUpTime(scheduleSource);
7215
+ const { timeModifiers } = matchUpTimeModifiers(scheduleSource);
7198
7216
  let { scheduledDate } = scheduledMatchUpDate(scheduleSource);
7199
7217
  const { venueId } = matchUpAssignedVenueId(scheduleSource);
7200
7218
  const { courtId } = matchUpAssignedCourtId(scheduleSource);
7201
7219
  const { courtOrder } = matchUpCourtOrder(scheduleSource);
7202
- const { timeModifiers } = matchUpTimeModifiers(scheduleSource);
7203
7220
  let timeAfterRecovery, averageMinutes, recoveryMinutes, typeChangeRecoveryMinutes, typeChangeTimeAfterRecovery;
7204
7221
  const eventType = matchUp.matchUpType ?? matchUpType;
7205
7222
  if (scheduleTiming && scheduledTime && afterRecoveryTimes && eventType) {
@@ -7257,6 +7274,7 @@ function getMatchUpScheduleDetails(params) {
7257
7274
  scheduledTime,
7258
7275
  isoDateString,
7259
7276
  allocatedCourts,
7277
+ homeParticipantId,
7260
7278
  timeModifiers,
7261
7279
  venueAbbreviation,
7262
7280
  venueName,
@@ -10409,6 +10427,11 @@ function assignDrawPositionBye({ provisionalPositioning, isPositionAction, tourn
10409
10427
  if (filled && !containsBye) {
10410
10428
  return decorateResult({ result: { error: DRAW_POSITION_ASSIGNED }, stack });
10411
10429
  }
10430
+ const appliedPolicies = getAppliedPolicies({
10431
+ tournamentRecord,
10432
+ drawDefinition,
10433
+ event,
10434
+ }).appliedPolicies ?? {};
10412
10435
  const inContextDrawMatchUps = getAllDrawMatchUps({
10413
10436
  inContext: true,
10414
10437
  drawDefinition,
@@ -10443,6 +10466,7 @@ function assignDrawPositionBye({ provisionalPositioning, isPositionAction, tourn
10443
10466
  return successNotice({
10444
10467
  assignedParticipantId,
10445
10468
  isPositionAction,
10469
+ appliedPolicies,
10446
10470
  drawDefinition,
10447
10471
  drawPosition,
10448
10472
  structureId,
@@ -10484,13 +10508,14 @@ function assignDrawPositionBye({ provisionalPositioning, isPositionAction, tourn
10484
10508
  return successNotice({
10485
10509
  assignedParticipantId,
10486
10510
  isPositionAction,
10511
+ appliedPolicies,
10487
10512
  drawDefinition,
10488
10513
  drawPosition,
10489
10514
  structureId,
10490
10515
  stack,
10491
10516
  });
10492
10517
  }
10493
- function successNotice({ assignedParticipantId, isPositionAction, drawDefinition, drawPosition, structureId, stack }) {
10518
+ function successNotice({ assignedParticipantId, isPositionAction, appliedPolicies, drawDefinition, drawPosition, structureId, stack, }) {
10494
10519
  if (isPositionAction) {
10495
10520
  const positionAction = {
10496
10521
  removedParticipantId: assignedParticipantId,
@@ -10498,7 +10523,7 @@ function successNotice({ assignedParticipantId, isPositionAction, drawDefinition
10498
10523
  structureId,
10499
10524
  name: stack,
10500
10525
  };
10501
- addPositionActionTelemetry({ drawDefinition, positionAction });
10526
+ addPositionActionTelemetry({ appliedPolicies, drawDefinition, positionAction });
10502
10527
  }
10503
10528
  return decorateResult({ result: { ...SUCCESS }, stack });
10504
10529
  }
@@ -13554,6 +13579,11 @@ function removeDrawPositionAssignment(params) {
13554
13579
  return decorateResult({ result, stack });
13555
13580
  const { participantId } = result;
13556
13581
  const { drawPosition, event, structureId } = params;
13582
+ const appliedPolicies = getAppliedPolicies({
13583
+ tournamentRecord,
13584
+ drawDefinition,
13585
+ event,
13586
+ }).appliedPolicies ?? {};
13557
13587
  if ([ALTERNATE, WITHDRAWN].includes(entryStatus) && participantId) {
13558
13588
  const { tournamentRecord } = params;
13559
13589
  const { participant } = findTournamentParticipant({
@@ -13615,7 +13645,7 @@ function removeDrawPositionAssignment(params) {
13615
13645
  entryStatus,
13616
13646
  structureId,
13617
13647
  };
13618
- addPositionActionTelemetry({ drawDefinition, positionAction });
13648
+ addPositionActionTelemetry({ appliedPolicies, drawDefinition, positionAction });
13619
13649
  return result;
13620
13650
  }
13621
13651
 
@@ -15192,6 +15222,11 @@ function positionParticipantAction(params) {
15192
15222
  const stack = 'positionParticipantAction';
15193
15223
  if (!drawDefinition)
15194
15224
  return { error: MISSING_DRAW_DEFINITION };
15225
+ const appliedPolicies = getAppliedPolicies({
15226
+ tournamentRecord,
15227
+ drawDefinition,
15228
+ event,
15229
+ }).appliedPolicies ?? {};
15195
15230
  let { inContextDrawMatchUps, matchUpsMap } = params;
15196
15231
  if (!matchUpsMap) {
15197
15232
  matchUpsMap = getMatchUpsMap({ drawDefinition });
@@ -15225,9 +15260,7 @@ function positionParticipantAction(params) {
15225
15260
  if (!result.success) {
15226
15261
  return decorateResult({ result, stack });
15227
15262
  }
15228
- return successNotice({
15229
- removedParticipantId,
15230
- });
15263
+ return successNotice({ appliedPolicies, removedParticipantId });
15231
15264
  }
15232
15265
  const result = clearDrawPosition({
15233
15266
  inContextDrawMatchUps,
@@ -15254,8 +15287,8 @@ function positionParticipantAction(params) {
15254
15287
  });
15255
15288
  if (!assignResult.success)
15256
15289
  return decorateResult({ result: assignResult, stack });
15257
- return successNotice({ removedParticipantId });
15258
- function successNotice({ removedParticipantId }) {
15290
+ return successNotice({ appliedPolicies, removedParticipantId });
15291
+ function successNotice({ appliedPolicies, removedParticipantId }) {
15259
15292
  const { structure } = findStructure({ drawDefinition, structureId });
15260
15293
  conditionallyDisableLinkPositioning({
15261
15294
  drawPositions: [drawPosition],
@@ -15267,7 +15300,7 @@ function positionParticipantAction(params) {
15267
15300
  drawPosition,
15268
15301
  structureId,
15269
15302
  };
15270
- addPositionActionTelemetry({ drawDefinition, positionAction });
15303
+ addPositionActionTelemetry({ appliedPolicies, drawDefinition, positionAction });
15271
15304
  return decorateResult({
15272
15305
  context: { removedParticipantId },
15273
15306
  result: { ...SUCCESS },
@@ -15503,9 +15536,8 @@ function swapDrawPositionAssignments$1({ tournamentRecord, drawDefinition, drawP
15503
15536
  return { error: MISSING_DRAW_DEFINITION };
15504
15537
  if (!structureId)
15505
15538
  return { error: MISSING_STRUCTURE_ID };
15506
- if (drawPositions?.length !== 2) {
15539
+ if (drawPositions?.length !== 2)
15507
15540
  return { error: INVALID_VALUES, drawPositions };
15508
- }
15509
15541
  const matchUpsMap = getMatchUpsMap({ drawDefinition });
15510
15542
  const { matchUps: inContextDrawMatchUps } = getAllDrawMatchUps({
15511
15543
  inContext: true,
@@ -15515,6 +15547,11 @@ function swapDrawPositionAssignments$1({ tournamentRecord, drawDefinition, drawP
15515
15547
  const { structure } = findStructure({ drawDefinition, structureId });
15516
15548
  if (!structure)
15517
15549
  return { error: STRUCTURE_NOT_FOUND };
15550
+ const appliedPolicies = getAppliedPolicies({
15551
+ tournamentRecord,
15552
+ drawDefinition,
15553
+ event,
15554
+ }).appliedPolicies ?? {};
15518
15555
  let result;
15519
15556
  if (structure.structureType === CONTAINER) {
15520
15557
  result = roundRobinSwap({
@@ -15546,7 +15583,7 @@ function swapDrawPositionAssignments$1({ tournamentRecord, drawDefinition, drawP
15546
15583
  drawPositions,
15547
15584
  structureId,
15548
15585
  };
15549
- addPositionActionTelemetry({ drawDefinition, positionAction });
15586
+ addPositionActionTelemetry({ appliedPolicies, drawDefinition, positionAction });
15550
15587
  modifyPositionAssignmentsNotice({
15551
15588
  tournamentId: tournamentRecord?.tournamentId,
15552
15589
  drawDefinition,
@@ -38237,10 +38274,8 @@ function deleteDrawDefinitions(params) {
38237
38274
  matchUpIds,
38238
38275
  });
38239
38276
  }
38240
- drawIds.forEach((drawId) => {
38241
- deleteDrawNotice({ drawId });
38242
- });
38243
- addDrawDeletionTelemetry({ event, deletedDrawsDetail, auditData });
38277
+ drawIds.forEach((drawId) => deleteDrawNotice({ drawId }));
38278
+ addDrawDeletionTelemetry({ appliedPolicies, event, deletedDrawsDetail, auditData });
38244
38279
  if (autoPublish && publishedDrawsDeleted) {
38245
38280
  const result = publishEvent({
38246
38281
  drawIdsToRemove: drawIds,
@@ -38253,15 +38288,17 @@ function deleteDrawDefinitions(params) {
38253
38288
  }
38254
38289
  return { ...SUCCESS };
38255
38290
  }
38256
- function addDrawDeletionTelemetry({ event, deletedDrawsDetail, auditData }) {
38291
+ function addDrawDeletionTelemetry({ appliedPolicies, event, deletedDrawsDetail, auditData }) {
38292
+ if (appliedPolicies?.audit?.[DRAW_DELETIONS] === false)
38293
+ return;
38257
38294
  const { extension } = findExtension({
38258
38295
  name: DRAW_DELETIONS,
38259
38296
  element: event,
38260
38297
  });
38261
38298
  const deletionData = { ...auditData, deletedDrawsDetail };
38262
38299
  const updatedExtension = {
38263
- name: DRAW_DELETIONS,
38264
38300
  value: Array.isArray(extension?.value) ? extension?.value.concat(deletionData) : [deletionData],
38301
+ name: DRAW_DELETIONS,
38265
38302
  };
38266
38303
  addExtension({ element: event, extension: updatedExtension });
38267
38304
  }
@@ -42624,30 +42661,21 @@ function scoreModification(params) {
42624
42661
  return decorateResult({ result, stack });
42625
42662
  }
42626
42663
 
42627
- function getProjectedDualWinningSide({ drawDefinition, matchUpStatus, matchUpsMap, winningSide, dualMatchUp, tieFormat, structure, matchUp, event, score, }) {
42628
- const projectedDualMatchUp = makeDeepCopy(dualMatchUp, undefined, true);
42629
- for (const tieMatchUp of projectedDualMatchUp?.tieMatchUps || []) {
42630
- if (tieMatchUp.matchUpId === matchUp.matchUpId) {
42631
- tieMatchUp.winningSide = winningSide;
42632
- tieMatchUp.score = score;
42633
- if (!checkScoreHasValue({ score }) && !matchUpStatus) {
42634
- Object.assign(tieMatchUp, { ...toBePlayed });
42635
- }
42636
- else if (matchUpStatus) {
42637
- tieMatchUp.matchUpStatus = matchUpStatus;
42638
- }
42639
- }
42640
- }
42641
- tieFormat = tieFormat ?? resolveTieFormat({ matchUp, structure, drawDefinition, event })?.tieFormat;
42642
- const { winningSide: projectedWinningSide } = generateTieMatchUpScore({
42643
- matchUp: projectedDualMatchUp,
42664
+ function setMatchUpHomeParticipantId(params) {
42665
+ const { disableNotice = true, homeParticipantId, removePriorValues, tournamentRecord, drawDefinition, matchUpId, } = params;
42666
+ const timeItem = {
42667
+ itemValue: homeParticipantId,
42668
+ itemType: HOME_PARTICIPANT_ID,
42669
+ };
42670
+ return addMatchUpTimeItem({
42671
+ duplicateValues: false,
42672
+ removePriorValues,
42673
+ tournamentRecord,
42644
42674
  drawDefinition,
42645
- matchUpsMap,
42646
- structure,
42647
- tieFormat,
42648
- event,
42675
+ disableNotice,
42676
+ matchUpId,
42677
+ timeItem,
42649
42678
  });
42650
- return { projectedWinningSide };
42651
42679
  }
42652
42680
 
42653
42681
  function addMatchUpScheduledTime(params) {
@@ -42747,6 +42775,28 @@ function addMatchUpTimeModifiers({ removePriorValues, tournamentRecord, drawDefi
42747
42775
  });
42748
42776
  }
42749
42777
 
42778
+ function addMatchUpScheduledDate({ scheduledDate: dateToSchedule, removePriorValues, tournamentRecord, drawDefinition, disableNotice, matchUpId, }) {
42779
+ if (!matchUpId)
42780
+ return { error: MISSING_MATCHUP_ID };
42781
+ const validDate = dateToSchedule && dateValidation.test(dateToSchedule);
42782
+ if (dateToSchedule && !validDate)
42783
+ return { error: INVALID_DATE };
42784
+ const scheduledDate = extractDate(dateToSchedule);
42785
+ const timeItem = {
42786
+ itemValue: scheduledDate,
42787
+ itemType: SCHEDULED_DATE,
42788
+ };
42789
+ return addMatchUpTimeItem({
42790
+ duplicateValues: false,
42791
+ removePriorValues,
42792
+ tournamentRecord,
42793
+ drawDefinition,
42794
+ disableNotice,
42795
+ matchUpId,
42796
+ timeItem,
42797
+ });
42798
+ }
42799
+
42750
42800
  function allocateTeamMatchUpCourts({ removePriorValues, tournamentRecords, tournamentRecord, drawDefinition, disableNotice, courtDayDate, matchUpId, courtIds, }) {
42751
42801
  if (!tournamentRecord && !tournamentRecords)
42752
42802
  return { error: MISSING_TOURNAMENT_RECORD };
@@ -42874,14 +42924,16 @@ function timeDate(value, scheduledDate) {
42874
42924
  const date = extractDate(value) || extractDate(scheduledDate) || formatDate(new Date());
42875
42925
  return new Date(`${date}T${time}`).getTime();
42876
42926
  }
42877
- function addMatchUpScheduleItems({ errorOnAnachronism = false, checkChronology = true, matchUpDependencies, inContextMatchUps, removePriorValues, tournamentRecords, tournamentRecord, drawDefinition, disableNotice, drawMatchUps, matchUpId, schedule, event, }) {
42878
- if (!schedule)
42879
- return { error: MISSING_VALUE, info: 'Missing schedule' };
42880
- if (!drawDefinition)
42881
- return { error: MISSING_DRAW_DEFINITION };
42882
- if (!matchUpId)
42883
- return { error: MISSING_MATCHUP_ID };
42927
+ function addMatchUpScheduleItems(params) {
42884
42928
  const stack = 'addMatchUpScheduleItems';
42929
+ const paramsCheck = checkRequiredParameters(params, [
42930
+ { drawDefinition: true, matchUpId: true },
42931
+ { schedule: true, [OF_TYPE]: OBJECT },
42932
+ ], stack);
42933
+ if (paramsCheck.error)
42934
+ return paramsCheck;
42935
+ let { matchUpDependencies, inContextMatchUps } = params;
42936
+ const { errorOnAnachronism = false, checkChronology = true, removePriorValues, tournamentRecords, tournamentRecord, drawDefinition, disableNotice, drawMatchUps, matchUpId, schedule, event, } = params;
42885
42937
  let matchUp, warning;
42886
42938
  if (!drawMatchUps) {
42887
42939
  const result = findDrawMatchUp({ drawDefinition, event, matchUpId });
@@ -42892,7 +42944,7 @@ function addMatchUpScheduleItems({ errorOnAnachronism = false, checkChronology =
42892
42944
  else {
42893
42945
  matchUp = drawMatchUps.find((drawMatchUp) => drawMatchUp.matchUpId === matchUpId);
42894
42946
  }
42895
- const { endTime, courtId, courtIds, courtOrder, resumeTime, scheduledDate, scheduledTime, startTime, stopTime, timeModifiers, venueId, } = schedule;
42947
+ const { endTime, courtId, courtIds, courtOrder, resumeTime, homeParticipantId, scheduledDate, scheduledTime, startTime, stopTime, timeModifiers, venueId, } = schedule;
42896
42948
  if (checkChronology && (!matchUpDependencies || !inContextMatchUps)) {
42897
42949
  ({ matchUpDependencies, matchUps: inContextMatchUps } = getMatchUpDependencies({
42898
42950
  drawDefinition,
@@ -43062,6 +43114,16 @@ function addMatchUpScheduleItems({ errorOnAnachronism = false, checkChronology =
43062
43114
  if (result?.error)
43063
43115
  return decorateResult({ result, stack, context: { timeModifiers } });
43064
43116
  }
43117
+ if (isString(homeParticipantId)) {
43118
+ setMatchUpHomeParticipantId({
43119
+ disableNotice: true,
43120
+ homeParticipantId,
43121
+ removePriorValues,
43122
+ tournamentRecord,
43123
+ drawDefinition,
43124
+ matchUpId,
43125
+ });
43126
+ }
43065
43127
  if (!disableNotice) {
43066
43128
  modifyMatchUpNotice({
43067
43129
  tournamentId: tournamentRecord?.tournamentId,
@@ -43073,27 +43135,6 @@ function addMatchUpScheduleItems({ errorOnAnachronism = false, checkChronology =
43073
43135
  }
43074
43136
  return warning ? { ...SUCCESS, warnings: [warning] } : { ...SUCCESS };
43075
43137
  }
43076
- function addMatchUpScheduledDate({ scheduledDate: dateToSchedule, removePriorValues, tournamentRecord, drawDefinition, disableNotice, matchUpId, }) {
43077
- if (!matchUpId)
43078
- return { error: MISSING_MATCHUP_ID };
43079
- const validDate = dateToSchedule && dateValidation.test(dateToSchedule);
43080
- if (dateToSchedule && !validDate)
43081
- return { error: INVALID_DATE };
43082
- const scheduledDate = extractDate(dateToSchedule);
43083
- const timeItem = {
43084
- itemValue: scheduledDate,
43085
- itemType: SCHEDULED_DATE,
43086
- };
43087
- return addMatchUpTimeItem({
43088
- duplicateValues: false,
43089
- removePriorValues,
43090
- tournamentRecord,
43091
- drawDefinition,
43092
- disableNotice,
43093
- matchUpId,
43094
- timeItem,
43095
- });
43096
- }
43097
43138
  function addMatchUpCourtOrder({ removePriorValues, tournamentRecord, drawDefinition, disableNotice, courtOrder, matchUpId, }) {
43098
43139
  if (!matchUpId)
43099
43140
  return { error: MISSING_MATCHUP_ID };
@@ -43307,6 +43348,32 @@ function addMatchUpResumeTime({ removePriorValues, tournamentRecord, drawDefinit
43307
43348
  }
43308
43349
  }
43309
43350
 
43351
+ function getProjectedDualWinningSide({ drawDefinition, matchUpStatus, matchUpsMap, winningSide, dualMatchUp, tieFormat, structure, matchUp, event, score, }) {
43352
+ const projectedDualMatchUp = makeDeepCopy(dualMatchUp, undefined, true);
43353
+ for (const tieMatchUp of projectedDualMatchUp?.tieMatchUps || []) {
43354
+ if (tieMatchUp.matchUpId === matchUp.matchUpId) {
43355
+ tieMatchUp.winningSide = winningSide;
43356
+ tieMatchUp.score = score;
43357
+ if (!checkScoreHasValue({ score }) && !matchUpStatus) {
43358
+ Object.assign(tieMatchUp, { ...toBePlayed });
43359
+ }
43360
+ else if (matchUpStatus) {
43361
+ tieMatchUp.matchUpStatus = matchUpStatus;
43362
+ }
43363
+ }
43364
+ }
43365
+ tieFormat = tieFormat ?? resolveTieFormat({ matchUp, structure, drawDefinition, event })?.tieFormat;
43366
+ const { winningSide: projectedWinningSide } = generateTieMatchUpScore({
43367
+ matchUp: projectedDualMatchUp,
43368
+ drawDefinition,
43369
+ matchUpsMap,
43370
+ structure,
43371
+ tieFormat,
43372
+ event,
43373
+ });
43374
+ return { projectedWinningSide };
43375
+ }
43376
+
43310
43377
  function swapWinnerLoser(params) {
43311
43378
  const { tournamentRecord, inContextMatchUp, structure, drawDefinition } = params;
43312
43379
  const matchUpRoundNumber = inContextMatchUp.roundNumber;
@@ -46805,6 +46872,11 @@ function postalCodeMocks({ count = 1, participantsCount = 32 } = {}) {
46805
46872
  return { postalCodes };
46806
46873
  }
46807
46874
 
46875
+ function genParticipantId({ idPrefix, participantType, index, uuids }) {
46876
+ const type = participantType === INDIVIDUAL ? 'I' : 'P' ;
46877
+ return idPrefix ? `${idPrefix}-${type}-${index}` : uuids?.pop() || UUID();
46878
+ }
46879
+
46808
46880
  function generateAddress(addressAttributes) {
46809
46881
  const { cities, states, postalCodes, nationalityCode, participantIndex } = addressAttributes;
46810
46882
  return {
@@ -47302,11 +47374,6 @@ function nameMocks({ nameRoot = 'TEAM', count = 1 } = {}) {
47302
47374
  return { names };
47303
47375
  }
47304
47376
 
47305
- function genParticipantId({ idPrefix, participantType, index, uuids }) {
47306
- const type = participantType === INDIVIDUAL ? 'I' : 'P' ;
47307
- return idPrefix ? `${idPrefix}-${type}-${index}` : uuids?.pop() || UUID();
47308
- }
47309
-
47310
47377
  function generateParticipants(params) {
47311
47378
  let { rankingRange, scaledParticipantsCount, } = params;
47312
47379
  const { ratingsParameters: ratingsParameters$1 = ratingsParameters, valuesInstanceLimit, consideredDate, category, nationalityCodesCount, nationalityCodeType, nationalityCodes, participantsCount = 32, participantType, personIds, idPrefix, uuids, personExtensions, addressProps, gendersCount, matchUpType, personData, sex, inContext, withISO2, withIOC, scaleAllParticipants, } = params;
@@ -47559,12 +47626,13 @@ function addScaleItem({ scaleValue: itemValue, participant, eventType, scaleType
47559
47626
  }
47560
47627
  }
47561
47628
 
47562
- function processTieFormat({ alternatesCount = 0, tieFormatName, tieFormat, drawSize }) {
47629
+ function processTieFormat(params) {
47630
+ const { alternatesCount = 0, tieFormatName, drawSize } = params;
47563
47631
  let maxDoublesCount = 0, maxSinglesCount = 0;
47564
47632
  let singlesMatchUpTotal = 0, doublesMatchUpTotal = 0;
47565
47633
  const categories = {};
47566
47634
  const genders = { [MALE]: 0, [FEMALE]: 0, [MIXED]: 0, [OTHER$2]: 0, [ANY]: 0 };
47567
- tieFormat = typeof tieFormat === 'object' ? tieFormat : tieFormatDefaults({ namedFormat: tieFormatName });
47635
+ const tieFormat = isObject(params.tieFormat) ? params.tieFormat : tieFormatDefaults({ namedFormat: tieFormatName });
47568
47636
  tieFormat?.collectionDefinitions?.filter(Boolean).forEach((collectionDefinition) => {
47569
47637
  const { category, collectionId, matchUpType, matchUpCount, gender } = collectionDefinition;
47570
47638
  if ([MALE, FEMALE].includes(gender)) {
@@ -47717,12 +47785,12 @@ function addTournamentParticipants({ participantsProfile, tournamentRecord, even
47717
47785
  });
47718
47786
  const teamKey = participantsProfile?.teamKey;
47719
47787
  const participants = generateParticipants({
47720
- uuids,
47721
- ...participantsProfile,
47722
47788
  consideredDate: startDate,
47789
+ ...participantsProfile,
47723
47790
  participantsCount,
47724
47791
  participantType,
47725
47792
  gendersCount,
47793
+ uuids,
47726
47794
  }).participants;
47727
47795
  let addedCount = 0;
47728
47796
  let result = addParticipants({ tournamentRecord, participants });
@@ -48707,7 +48775,7 @@ function generateEventWithDraw(params) {
48707
48775
  const eventId = drawProfileCopy.eventId || UUID();
48708
48776
  const eventType = drawProfile.eventType || drawProfile.matchUpType || SINGLES$1;
48709
48777
  const participantType = eventType === DOUBLES$1 ? PAIR : INDIVIDUAL;
48710
- const tieFormat = (typeof drawProfile.tieFormat === 'object' && drawProfile.tieFormat) ||
48778
+ const tieFormat = (isObject(drawProfile.tieFormat) && drawProfile.tieFormat) ||
48711
48779
  (eventType === TEAM &&
48712
48780
  tieFormatDefaults({
48713
48781
  event: { eventId, category, gender },
@@ -49361,7 +49429,7 @@ function courtsAdd({ courtNameRoot = 'Court', dateAvailability = [], venueAbbrev
49361
49429
  return { ...SUCCESS, courts: makeDeepCopy(courtRecords) };
49362
49430
  }
49363
49431
 
49364
- function generateVenues({ tournamentRecord, venueProfiles, uuids }) {
49432
+ function generateVenues({ tournamentRecord, ignoreExistingVenues, venueProfiles, uuids }) {
49365
49433
  const { startDate, endDate } = tournamentRecord;
49366
49434
  const venueIds = [];
49367
49435
  for (const [index, venueProfile] of venueProfiles.entries()) {
@@ -49372,8 +49440,11 @@ function generateVenues({ tournamentRecord, venueProfiles, uuids }) {
49372
49440
  venueId,
49373
49441
  };
49374
49442
  const result = addVenue({ tournamentRecord, venue: newVenue });
49375
- if (result.error)
49443
+ if (result.error) {
49444
+ if (ignoreExistingVenues)
49445
+ continue;
49376
49446
  return result;
49447
+ }
49377
49448
  venueIds.push(venueId);
49378
49449
  const dates = generateDateRange(startDate, endDate);
49379
49450
  const generatedDateAvailability = !Array.isArray(dateAvailability) &&
@@ -49382,39 +49453,142 @@ function generateVenues({ tournamentRecord, venueProfiles, uuids }) {
49382
49453
  startTime,
49383
49454
  endTime,
49384
49455
  })));
49385
- const addResult = addCourts({
49386
- dateAvailability: dateAvailability || generatedDateAvailability,
49387
- tournamentRecord,
49388
- courtTimings,
49389
- courtsCount,
49390
- courtNames,
49391
- startTime,
49392
- idPrefix,
49393
- courtIds,
49394
- endTime,
49395
- venueId,
49396
- dates,
49397
- });
49398
- if (addResult.error)
49399
- return addResult;
49456
+ if (courtsCount || courtNames) {
49457
+ const addResult = addCourts({
49458
+ dateAvailability: dateAvailability || generatedDateAvailability,
49459
+ tournamentRecord,
49460
+ courtTimings,
49461
+ courtsCount,
49462
+ courtNames,
49463
+ startTime,
49464
+ idPrefix,
49465
+ courtIds,
49466
+ endTime,
49467
+ venueId,
49468
+ dates,
49469
+ });
49470
+ if (addResult.error)
49471
+ return addResult;
49472
+ }
49400
49473
  }
49401
49474
  return venueIds;
49402
49475
  }
49403
49476
 
49477
+ function processLeagueProfiles(params) {
49478
+ const { tournamentRecord, leagueProfiles, eventIds, venueIds, drawIds, allUniqueParticipantIds, uuids } = params;
49479
+ let leaguesCount = 0;
49480
+ for (const leagueProfile of leagueProfiles) {
49481
+ const entries = [];
49482
+ const { tieFormatName = COLLEGE_DEFAULT$1, teamProfiles = [], teamsCount = 0, category, idPrefix, gender, } = leagueProfile;
49483
+ const eventName = leagueProfile.leagueName ?? leagueProfile.eventName ?? `League ${leaguesCount + 1}`;
49484
+ const eventId = leagueProfile.leagueId ?? leagueProfile.eventId ?? uuids?.pop() ?? UUID();
49485
+ eventIds.push(eventId);
49486
+ const tieFormat = (isObject(leagueProfile.tieFormat) && leagueProfile.tieFormat) ||
49487
+ tieFormatDefaults({
49488
+ event: { eventId, category, gender },
49489
+ namedFormat: tieFormatName,
49490
+ isMock: params.isMock,
49491
+ }) ||
49492
+ undefined;
49493
+ if (!tieFormat)
49494
+ return { error: MISSING_TIE_FORMAT };
49495
+ const drawSize = Math.max(teamsCount, teamProfiles.length);
49496
+ const teamsRange = generateRange(0, drawSize);
49497
+ const { genders, teamSize } = processTieFormat({ tieFormat, drawSize });
49498
+ const gendersCount = { [FEMALE]: 0, [MIXED]: 0, [OTHER$2]: 0, [MALE]: 0, [ANY]: 0 };
49499
+ Object.keys(genders).forEach((key) => (gendersCount[key] += genders[key]));
49500
+ for (const index of teamsRange) {
49501
+ const teamName = teamProfiles?.[index]?.teamName ?? `Team ${index + 1}`;
49502
+ const teamId = teamProfiles?.[index]?.teamId || uuids?.pop() || UUID();
49503
+ const consideredDate = leagueProfile.startDate ?? params.startDate;
49504
+ const participants = generateParticipants({
49505
+ ...leagueProfile?.participantsProfile,
49506
+ participantsCount: teamSize,
49507
+ consideredDate,
49508
+ gendersCount,
49509
+ category,
49510
+ gender,
49511
+ uuids,
49512
+ }).participants;
49513
+ const individualParticipantIds = participants.map((participant) => participant.participantId);
49514
+ const participantType = TEAM;
49515
+ const teamParticipantId = teamId ??
49516
+ genParticipantId({
49517
+ participantType,
49518
+ idPrefix,
49519
+ index,
49520
+ uuids,
49521
+ });
49522
+ entries.push({ participantId: teamParticipantId, entryStatus: DIRECT_ACCEPTANCE, entryStage: MAIN });
49523
+ const homeVenueIds = teamProfiles?.[index]?.venueIds ?? [];
49524
+ const teamParticipant = {
49525
+ participantId: teamParticipantId,
49526
+ participantRole: COMPETITOR,
49527
+ participantName: teamName,
49528
+ individualParticipantIds,
49529
+ participantType,
49530
+ homeVenueIds,
49531
+ };
49532
+ homeVenueIds.forEach((venueId) => !venueIds.includes(venueId) && venueIds.push(venueId));
49533
+ allUniqueParticipantIds.push(...individualParticipantIds);
49534
+ allUniqueParticipantIds.push(teamParticipantId);
49535
+ const result = addParticipants({
49536
+ participants: [teamParticipant, ...participants],
49537
+ tournamentRecord,
49538
+ });
49539
+ if (result.error)
49540
+ return result;
49541
+ }
49542
+ const eventType = TEAM;
49543
+ const event = { eventName, entries, eventType, tieFormat, category, eventId, gender };
49544
+ if (!tournamentRecord.events)
49545
+ tournamentRecord.events = [];
49546
+ tournamentRecord.events.push(event);
49547
+ if (entries.length) {
49548
+ const roundsCount = isNumeric(leagueProfile.roundsCount)
49549
+ ? leagueProfile.roundsCount
49550
+ : leagueProfile.roundsCount === DOUBLE_ROUND_ROBIN
49551
+ ? (drawSize - 1) * 2
49552
+ : drawSize - 1;
49553
+ const result = generateDrawDefinition({
49554
+ automated: leagueProfile.automated,
49555
+ tournamentRecord,
49556
+ drawType: AD_HOC,
49557
+ roundsCount,
49558
+ drawSize,
49559
+ event,
49560
+ });
49561
+ if (result.error)
49562
+ return result;
49563
+ const { drawDefinition } = result;
49564
+ if (drawDefinition) {
49565
+ const drawId = drawDefinition?.drawId;
49566
+ addDrawDefinition({ drawDefinition, event, suppressNotifications: true });
49567
+ drawIds.push(drawId);
49568
+ }
49569
+ }
49570
+ leaguesCount++;
49571
+ }
49572
+ const venueProfiles = venueIds.map((venueId) => ({ venueId }));
49573
+ generateVenues({ tournamentRecord, ignoreExistingVenues: true, venueProfiles, uuids });
49574
+ }
49575
+
49404
49576
  const mockTournamentNames = [
49405
- 'Mock Tournament',
49406
- 'CourtHive Challenge',
49407
- 'Racket Rally',
49408
49577
  'Generated Tournament',
49409
- 'Factory Follies',
49578
+ 'CourtHive Challenge',
49410
49579
  'Open Competition',
49580
+ 'Factory Follies',
49581
+ 'Mock Tournament',
49582
+ 'Racket Rally',
49411
49583
  ];
49412
49584
  function generateTournamentRecord(params) {
49413
- let { tournamentAttributes, startDate, endDate } = params ?? {};
49414
- const { tournamentName = randomPop(mockTournamentNames), ratingsParameters: ratingsParameters$1 = ratingsParameters, scheduleCompletedMatchUps, tournamentExtensions, matchUpStatusProfile, completeAllMatchUps, participantsProfile, autoEntryPositions, hydrateCollections, randomWinningSide, policyDefinitions, schedulingProfile, periodLength, autoSchedule, eventProfiles, venueProfiles, drawProfiles, uuids, } = params ?? {};
49585
+ let { startDate, endDate } = params ?? {};
49586
+ const { tournamentName = randomPop(mockTournamentNames), ratingsParameters: ratingsParameters$1 = ratingsParameters, tournamentExtensions, policyDefinitions, schedulingProfile, venueProfiles, uuids, } = params ?? {};
49415
49587
  if ((startDate && !isValidDateString(startDate)) || (endDate && !isValidDateString(endDate)))
49416
49588
  return { error: INVALID_DATE };
49417
- if (eventProfiles && !Array.isArray(eventProfiles))
49589
+ if ((params.leagueProfiles && !Array.isArray(params.leagueProfiles)) ||
49590
+ (params.eventProfiles && !Array.isArray(params.eventProfiles)) ||
49591
+ (params.drawProfiles && !Array.isArray(params.drawProfiles)))
49418
49592
  return { error: INVALID_VALUES };
49419
49593
  if (!startDate) {
49420
49594
  const tournamentDate = new Date();
@@ -49425,15 +49599,14 @@ function generateTournamentRecord(params) {
49425
49599
  const tournamentDate = new Date(startDate);
49426
49600
  endDate = formatDate(tournamentDate.setDate(tournamentDate.getDate() + 7));
49427
49601
  }
49428
- if (typeof tournamentAttributes !== 'object')
49429
- tournamentAttributes = {};
49430
49602
  const tournamentRecord = newTournamentRecord({
49431
- ...tournamentAttributes,
49603
+ ...(params.tournamentAttributes ?? {}),
49432
49604
  tournamentName,
49433
49605
  isMock: true,
49434
49606
  startDate,
49435
49607
  endDate,
49436
49608
  });
49609
+ const venueIds = venueProfiles?.length ? generateVenues({ tournamentRecord, venueProfiles, uuids }) : [];
49437
49610
  if (tournamentExtensions?.length && Array.isArray(tournamentExtensions)) {
49438
49611
  const extensions = tournamentExtensions.filter((extension) => isValidExtension({ extension }));
49439
49612
  if (extensions?.length)
@@ -49447,105 +49620,57 @@ function generateTournamentRecord(params) {
49447
49620
  });
49448
49621
  }
49449
49622
  }
49450
- const result = addTournamentParticipants({
49451
- participantsProfile,
49452
- tournamentRecord,
49453
- eventProfiles,
49454
- drawProfiles,
49455
- startDate,
49456
- uuids,
49457
- });
49458
- if (!result.success)
49459
- return result;
49623
+ if (!params?.leagueProfiles?.length ||
49624
+ params.eventProfiles?.length ||
49625
+ params.drawProfiles?.length ||
49626
+ params.participantsProfile) {
49627
+ const result = addTournamentParticipants({
49628
+ tournamentRecord,
49629
+ ...params,
49630
+ });
49631
+ if (!result.success)
49632
+ return result;
49633
+ }
49460
49634
  const allUniqueParticipantIds = [], eventIds = [], drawIds = [];
49461
- if (Array.isArray(drawProfiles)) {
49462
- let drawIndex = 0;
49463
- for (const drawProfile of drawProfiles) {
49464
- let result = generateEventWithDraw({
49465
- allUniqueParticipantIds,
49466
- matchUpStatusProfile,
49467
- completeAllMatchUps,
49468
- autoEntryPositions,
49469
- hydrateCollections,
49470
- participantsProfile,
49471
- randomWinningSide,
49472
- ratingsParameters: ratingsParameters$1,
49473
- tournamentRecord,
49474
- isMock: true,
49475
- drawProfile,
49476
- startDate,
49477
- drawIndex,
49478
- uuids,
49479
- });
49480
- if (result.error)
49481
- return result;
49482
- const { drawId, eventId, event, uniqueParticipantIds } = result;
49483
- result = addEvent({
49484
- suppressNotifications: false,
49485
- internalUse: true,
49486
- tournamentRecord,
49487
- event,
49488
- });
49489
- if (result.error)
49490
- return result;
49491
- if (drawId)
49492
- drawIds.push(drawId);
49493
- eventIds.push(eventId);
49494
- if (uniqueParticipantIds?.length)
49495
- allUniqueParticipantIds.push(...uniqueParticipantIds);
49496
- drawIndex += 1;
49497
- }
49635
+ if (params.leagueProfiles) {
49636
+ const result = processLeagueProfiles({
49637
+ allUniqueParticipantIds,
49638
+ tournamentRecord,
49639
+ ...params,
49640
+ eventIds,
49641
+ venueIds,
49642
+ drawIds,
49643
+ });
49644
+ if (result?.error)
49645
+ return result;
49498
49646
  }
49499
- if (eventProfiles) {
49500
- let eventIndex = 0;
49501
- for (const eventProfile of eventProfiles) {
49502
- const result = generateEventWithFlights({
49503
- allUniqueParticipantIds,
49504
- matchUpStatusProfile,
49505
- participantsProfile,
49506
- completeAllMatchUps,
49507
- autoEntryPositions,
49508
- hydrateCollections,
49509
- randomWinningSide,
49510
- ratingsParameters: ratingsParameters$1,
49511
- tournamentRecord,
49512
- eventProfile,
49513
- eventIndex,
49514
- startDate,
49515
- uuids,
49516
- });
49517
- if (result.error)
49518
- return result;
49519
- const { eventId, drawIds: generatedDrawIds, uniqueParticipantIds } = result;
49520
- if (generatedDrawIds)
49521
- drawIds.push(...generatedDrawIds);
49522
- eventIds.push(eventId);
49523
- if (uniqueParticipantIds?.length)
49524
- allUniqueParticipantIds.push(...uniqueParticipantIds);
49525
- eventIndex += 1;
49526
- }
49647
+ if (params.drawProfiles) {
49648
+ const result = processDrawProfiles({
49649
+ allUniqueParticipantIds,
49650
+ ratingsParameters: ratingsParameters$1,
49651
+ tournamentRecord,
49652
+ ...params,
49653
+ eventIds,
49654
+ drawIds,
49655
+ });
49656
+ if (result?.error)
49657
+ return result;
49527
49658
  }
49528
- const venueIds = venueProfiles?.length ? generateVenues({ tournamentRecord, venueProfiles, uuids }) : [];
49529
- let scheduledRounds;
49530
- let schedulerResult = {};
49531
- if (schedulingProfile) {
49532
- const result = generateScheduledRounds({
49533
- schedulingProfile,
49659
+ if (params.eventProfiles) {
49660
+ const result = processEventProfiles({
49661
+ allUniqueParticipantIds,
49662
+ ratingsParameters: ratingsParameters$1,
49534
49663
  tournamentRecord,
49664
+ ...params,
49665
+ eventIds,
49666
+ drawIds,
49535
49667
  });
49536
- if (result.error)
49668
+ if (result?.error)
49537
49669
  return result;
49538
- scheduledRounds = result.scheduledRounds;
49539
- if (autoSchedule) {
49540
- const { tournamentId } = tournamentRecord;
49541
- const tournamentRecords = { [tournamentId]: tournamentRecord };
49542
- schedulerResult = scheduleProfileRounds({
49543
- scheduleCompletedMatchUps,
49544
- tournamentRecords,
49545
- periodLength,
49546
- });
49547
- }
49548
49670
  }
49671
+ const { scheduledRounds = undefined, schedulerResult = {} } = schedulingProfile
49672
+ ? scheduleRounds({ ...params, tournamentRecord })
49673
+ : {};
49549
49674
  cycleMutationStatus();
49550
49675
  return definedAttributes({
49551
49676
  ...SUCCESS,
@@ -49557,6 +49682,73 @@ function generateTournamentRecord(params) {
49557
49682
  drawIds,
49558
49683
  });
49559
49684
  }
49685
+ function processDrawProfiles(params) {
49686
+ const { tournamentRecord, drawProfiles, allUniqueParticipantIds, eventIds, drawIds } = params;
49687
+ let drawIndex = 0;
49688
+ for (const drawProfile of drawProfiles) {
49689
+ let result = generateEventWithDraw({
49690
+ allUniqueParticipantIds,
49691
+ tournamentRecord,
49692
+ drawProfile,
49693
+ drawIndex,
49694
+ ...params,
49695
+ });
49696
+ if (result.error)
49697
+ return result;
49698
+ const { drawId, eventId, event, uniqueParticipantIds } = result;
49699
+ result = addEvent({
49700
+ suppressNotifications: false,
49701
+ internalUse: true,
49702
+ tournamentRecord,
49703
+ event,
49704
+ });
49705
+ if (result.error)
49706
+ return result;
49707
+ if (drawId)
49708
+ drawIds.push(drawId);
49709
+ eventIds.push(eventId);
49710
+ if (uniqueParticipantIds?.length)
49711
+ allUniqueParticipantIds.push(...uniqueParticipantIds);
49712
+ drawIndex += 1;
49713
+ }
49714
+ }
49715
+ function processEventProfiles(params) {
49716
+ const { eventProfiles, allUniqueParticipantIds, eventIds, drawIds } = params;
49717
+ let eventIndex = 0;
49718
+ for (const eventProfile of eventProfiles) {
49719
+ const result = generateEventWithFlights({ ...params, eventIndex, eventProfile });
49720
+ if (result.error)
49721
+ return result;
49722
+ const { eventId, drawIds: generatedDrawIds, uniqueParticipantIds } = result;
49723
+ if (generatedDrawIds)
49724
+ drawIds.push(...generatedDrawIds);
49725
+ eventIds.push(eventId);
49726
+ if (uniqueParticipantIds?.length)
49727
+ allUniqueParticipantIds.push(...uniqueParticipantIds);
49728
+ eventIndex += 1;
49729
+ }
49730
+ }
49731
+ function scheduleRounds(params) {
49732
+ const { schedulingProfile, tournamentRecord, autoSchedule, periodLength, scheduleCompletedMatchUps } = params;
49733
+ const result = generateScheduledRounds({
49734
+ schedulingProfile,
49735
+ tournamentRecord,
49736
+ });
49737
+ if (result.error)
49738
+ return result;
49739
+ const scheduledRounds = result.scheduledRounds;
49740
+ if (autoSchedule) {
49741
+ const { tournamentId } = tournamentRecord;
49742
+ const tournamentRecords = { [tournamentId]: tournamentRecord };
49743
+ const schedulerResult = scheduleProfileRounds({
49744
+ scheduleCompletedMatchUps,
49745
+ tournamentRecords,
49746
+ periodLength,
49747
+ });
49748
+ return { schedulerResult, scheduledRounds };
49749
+ }
49750
+ return { scheduledRounds };
49751
+ }
49560
49752
 
49561
49753
  var generate$1 = {
49562
49754
  __proto__: null,
@@ -51952,7 +52144,7 @@ function getStructureReports({ firstFlightOnly = true, extensionProfiles, tourna
51952
52144
  };
51953
52145
  }
51954
52146
  function getPositionManipulations({ extensions }) {
51955
- return extensions?.find(({ name }) => name === AUDIT_POSITION_ACTIONS)?.value?.slice(1);
52147
+ return extensions?.find(({ name }) => name === POSITION_ACTIONS)?.value?.slice(1);
51956
52148
  }
51957
52149
 
51958
52150
  function getVenuesReport({ ignoreDisabled = true, tournamentRecords, tournamentId, venueIds = [], dates = [], }) {
@@ -53127,8 +53319,8 @@ function setMatchUpDailyLimits(params) {
53127
53319
  for (const currentTournamentId of tournamentIds) {
53128
53320
  const tournamentRecord = tournamentRecords[currentTournamentId];
53129
53321
  const result = addExtension({
53130
- element: tournamentRecord,
53131
53322
  extension: { name: SCHEDULE_LIMITS, value: { dailyLimits } },
53323
+ element: tournamentRecord,
53132
53324
  });
53133
53325
  if (result.error)
53134
53326
  return result;
@@ -53174,6 +53366,7 @@ var mutate$3 = {
53174
53366
  scheduleMatchUps: scheduleMatchUps,
53175
53367
  scheduleProfileRounds: scheduleProfileRounds,
53176
53368
  setMatchUpDailyLimits: setMatchUpDailyLimits,
53369
+ setMatchUpHomeParticipantId: setMatchUpHomeParticipantId,
53177
53370
  setSchedulingProfile: setSchedulingProfile,
53178
53371
  toggleParticipantCheckInState: toggleParticipantCheckInState,
53179
53372
  validateSchedulingProfile: validateSchedulingProfile
@@ -53224,6 +53417,7 @@ var index$5 = {
53224
53417
  scheduleMatchUps: scheduleMatchUps,
53225
53418
  scheduleProfileRounds: scheduleProfileRounds,
53226
53419
  setMatchUpDailyLimits: setMatchUpDailyLimits,
53420
+ setMatchUpHomeParticipantId: setMatchUpHomeParticipantId,
53227
53421
  setSchedulingProfile: setSchedulingProfile,
53228
53422
  toggleParticipantCheckInState: toggleParticipantCheckInState,
53229
53423
  validateSchedulingProfile: validateSchedulingProfile
@@ -53585,14 +53779,16 @@ function getMatchUpChangesArePossible({ check, matchUp }) {
53585
53779
  return { changesArePossible, changes, cannotChangeReaon };
53586
53780
  }
53587
53781
 
53588
- function tieFormatTelemetry({ drawDefinition, auditData }) {
53782
+ function tieFormatTelemetry({ appliedPolicies, drawDefinition, auditData }) {
53783
+ if (!appliedPolicies?.audit?.[TIE_FORMAT_MODIFICATIONS])
53784
+ return;
53589
53785
  const { extension } = findExtension({
53590
53786
  name: TIE_FORMAT_MODIFICATIONS,
53591
53787
  element: drawDefinition,
53592
53788
  });
53593
53789
  const updatedExtension = {
53594
- name: TIE_FORMAT_MODIFICATIONS,
53595
53790
  value: Array.isArray(extension?.value) ? extension?.value.concat(auditData) : [auditData],
53791
+ name: TIE_FORMAT_MODIFICATIONS,
53596
53792
  };
53597
53793
  addExtension({ element: drawDefinition, extension: updatedExtension });
53598
53794
  }
@@ -53798,17 +53994,15 @@ function modifyCollectionDefinition({ updateInProgressMatchUps = false, tourname
53798
53994
  });
53799
53995
  if (!result.error) {
53800
53996
  const { appliedPolicies } = getAppliedPolicies({ tournamentRecord });
53801
- if (appliedPolicies?.audit?.[TIE_FORMAT_MODIFICATIONS]) {
53802
- const auditData = definedAttributes({
53803
- collectionDefinition: targetCollectionDefinition,
53804
- drawId: drawDefinition?.drawId,
53805
- action: stack,
53806
- structureId,
53807
- matchUpId,
53808
- eventId,
53809
- });
53810
- tieFormatTelemetry({ drawDefinition, auditData });
53811
- }
53997
+ const auditData = definedAttributes({
53998
+ collectionDefinition: targetCollectionDefinition,
53999
+ drawId: drawDefinition?.drawId,
54000
+ action: stack,
54001
+ structureId,
54002
+ matchUpId,
54003
+ eventId,
54004
+ });
54005
+ tieFormatTelemetry({ appliedPolicies, drawDefinition, auditData });
53812
54006
  }
53813
54007
  return decorateResult({ result: { ...result, modifications }, stack });
53814
54008
  }
@@ -53977,17 +54171,15 @@ function removeCollectionGroup({ updateInProgressMatchUps = true, collectionGrou
53977
54171
  });
53978
54172
  if (!result.error) {
53979
54173
  const { appliedPolicies } = getAppliedPolicies({ tournamentRecord });
53980
- if (appliedPolicies?.audit?.[TIE_FORMAT_MODIFICATIONS]) {
53981
- const auditData = definedAttributes({
53982
- drawId: drawDefinition?.drawId,
53983
- collectionGroupNumber,
53984
- action: stack,
53985
- structureId,
53986
- matchUpId,
53987
- eventId,
53988
- });
53989
- tieFormatTelemetry({ drawDefinition, auditData });
53990
- }
54174
+ const auditData = definedAttributes({
54175
+ drawId: drawDefinition?.drawId,
54176
+ collectionGroupNumber,
54177
+ action: stack,
54178
+ structureId,
54179
+ matchUpId,
54180
+ eventId,
54181
+ });
54182
+ tieFormatTelemetry({ appliedPolicies, drawDefinition, auditData });
53991
54183
  }
53992
54184
  return decorateResult({
53993
54185
  result: { ...result, modifiedCollectionIds },
@@ -54330,17 +54522,15 @@ function removeCollectionDefinition({ updateInProgressMatchUps = true, tieFormat
54330
54522
  return { error: MISSING_DRAW_DEFINITION };
54331
54523
  }
54332
54524
  modifyDrawNotice({ drawDefinition, eventId: event?.eventId });
54333
- if (appliedPolicies?.audit?.[TIE_FORMAT_MODIFICATIONS]) {
54334
- const auditData = definedAttributes({
54335
- drawId: drawDefinition?.drawId,
54336
- action: stack,
54337
- collectionId,
54338
- structureId,
54339
- matchUpId,
54340
- eventId,
54341
- });
54342
- tieFormatTelemetry({ drawDefinition, auditData });
54343
- }
54525
+ const auditData = definedAttributes({
54526
+ drawId: drawDefinition?.drawId,
54527
+ action: stack,
54528
+ collectionId,
54529
+ structureId,
54530
+ matchUpId,
54531
+ eventId,
54532
+ });
54533
+ tieFormatTelemetry({ appliedPolicies, drawDefinition, auditData });
54344
54534
  return {
54345
54535
  tieFormat: prunedTieFormat,
54346
54536
  deletedMatchUpIds,
@@ -54586,17 +54776,15 @@ function addCollectionDefinition({ updateInProgressMatchUps = true, collectionDe
54586
54776
  else {
54587
54777
  return { error: MISSING_DRAW_DEFINITION };
54588
54778
  }
54589
- if (appliedPolicies?.audit?.[TIE_FORMAT_MODIFICATIONS]) {
54590
- const auditData = definedAttributes({
54591
- drawId: drawDefinition?.drawId,
54592
- collectionDefinition,
54593
- action: stack,
54594
- structureId,
54595
- matchUpId,
54596
- eventId,
54597
- });
54598
- tieFormatTelemetry({ drawDefinition, auditData });
54599
- }
54779
+ const auditData = definedAttributes({
54780
+ drawId: drawDefinition?.drawId,
54781
+ collectionDefinition,
54782
+ action: stack,
54783
+ structureId,
54784
+ matchUpId,
54785
+ eventId,
54786
+ });
54787
+ tieFormatTelemetry({ appliedPolicies, drawDefinition, auditData });
54600
54788
  return {
54601
54789
  tieFormat: prunedTieFormat,
54602
54790
  targetMatchUps,
@@ -55049,9 +55237,9 @@ function setTournamentDates(params) {
55049
55237
  const paramsCheck = checkRequiredParameters(params, [
55050
55238
  { tournamentRecord: true },
55051
55239
  {
55240
+ [VALIDATE]: (value) => dateValidation.test(value),
55052
55241
  [ANY_OF]: { startDate: false, endDate: false },
55053
55242
  [INVALID]: INVALID_DATE,
55054
- [VALIDATE]: (value) => dateValidation.test(value),
55055
55243
  },
55056
55244
  ]);
55057
55245
  if (paramsCheck.error)