tods-competition-factory 1.7.13 → 1.7.15

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.
package/dist/index.mjs CHANGED
@@ -333,7 +333,7 @@ const matchUpFormatCode = {
333
333
  };
334
334
 
335
335
  function factoryVersion() {
336
- return "1.7.13";
336
+ return "1.7.15";
337
337
  }
338
338
 
339
339
  function getObjectTieFormat(obj) {
@@ -2426,8 +2426,9 @@ function decorateResult({
2426
2426
  if (result && Array.isArray(result?.stack) && typeof stack === "string") {
2427
2427
  result.stack.push(stack);
2428
2428
  }
2429
- if (info && result?.error)
2430
- result.error.info = info;
2429
+ if (result && info) {
2430
+ result.info = info;
2431
+ }
2431
2432
  if (result && typeof context === "object" && Object.keys(context).length) {
2432
2433
  Object.assign(result, definedAttributes(context));
2433
2434
  }
@@ -2557,34 +2558,28 @@ function validateTieFormat(params) {
2557
2558
  const tieFormat = params?.tieFormat;
2558
2559
  const stack = "validateTieFormat";
2559
2560
  const errors = [];
2560
- if (typeof tieFormat !== "object") {
2561
+ if (!params || !tieFormat || typeof tieFormat !== "object") {
2561
2562
  errors.push("tieFormat must be an object");
2562
2563
  return decorateResult({
2563
- result: {
2564
- context: { tieFormat, errors },
2565
- error: INVALID_TIE_FORMAT,
2566
- stack
2567
- }
2564
+ result: { error: INVALID_TIE_FORMAT },
2565
+ context: { tieFormat, errors },
2566
+ stack
2568
2567
  });
2569
2568
  }
2570
2569
  if (typeof tieFormat.winCriteria !== "object") {
2571
2570
  errors.push("tieFormat.winCriteria must be an object");
2572
2571
  return decorateResult({
2573
- result: {
2574
- context: { tieFormat, errors },
2575
- error: INVALID_TIE_FORMAT,
2576
- stack
2577
- }
2572
+ result: { error: INVALID_TIE_FORMAT },
2573
+ context: { tieFormat, errors },
2574
+ stack
2578
2575
  });
2579
2576
  }
2580
2577
  if (!Array.isArray(tieFormat.collectionDefinitions)) {
2581
2578
  errors.push(mustBeAnArray("tieFormat.collectionDefinitions"));
2582
2579
  return decorateResult({
2583
- result: {
2584
- context: { tieFormat, errors },
2585
- error: INVALID_TIE_FORMAT,
2586
- stack
2587
- }
2580
+ result: { error: INVALID_TIE_FORMAT },
2581
+ context: { tieFormat, errors },
2582
+ stack
2588
2583
  });
2589
2584
  }
2590
2585
  let aggregateValueImperative;
@@ -2617,11 +2612,9 @@ function validateTieFormat(params) {
2617
2612
  );
2618
2613
  }
2619
2614
  return decorateResult({
2620
- result: {
2621
- context: { tieFormat, errors, aggregateValueImperative },
2622
- error: INVALID_TIE_FORMAT,
2623
- stack
2624
- }
2615
+ context: { tieFormat, errors, aggregateValueImperative },
2616
+ result: { error: INVALID_TIE_FORMAT },
2617
+ stack
2625
2618
  });
2626
2619
  }
2627
2620
  const collectionIds = tieFormat.collectionDefinitions.map(
@@ -2632,11 +2625,9 @@ function validateTieFormat(params) {
2632
2625
  const result = { valid, errors };
2633
2626
  if (!valid) {
2634
2627
  return decorateResult({
2635
- result: {
2636
- context: { tieFormat, errors },
2637
- error: INVALID_TIE_FORMAT,
2638
- stack
2639
- }
2628
+ result: { error: INVALID_TIE_FORMAT },
2629
+ context: { tieFormat, errors },
2630
+ stack
2640
2631
  });
2641
2632
  }
2642
2633
  return result;
@@ -2695,7 +2686,7 @@ function validateCollectionDefinition({
2695
2686
  errors.push(`collectionValue is not type number: ${collectionValue}`);
2696
2687
  }
2697
2688
  if (collectionValueProfiles) {
2698
- const result = validateCollectionValueProfile({
2689
+ const result = validateCollectionValueProfiles({
2699
2690
  collectionValueProfiles,
2700
2691
  matchUpCount
2701
2692
  });
@@ -2726,7 +2717,7 @@ function checkTieFormat(tieFormat) {
2726
2717
  }
2727
2718
  return { tieFormat };
2728
2719
  }
2729
- function validateCollectionValueProfile({
2720
+ function validateCollectionValueProfiles({
2730
2721
  collectionValueProfiles,
2731
2722
  matchUpCount
2732
2723
  }) {
@@ -4813,19 +4804,15 @@ function findEvent({
4813
4804
  }) {
4814
4805
  const stack = "findEvent";
4815
4806
  if (!tournamentRecord)
4816
- return {
4817
- event: void 0,
4818
- drawDefinition: void 0,
4819
- ...decorateResult({
4820
- result: { error: MISSING_TOURNAMENT_RECORD },
4821
- stack
4822
- })
4823
- };
4824
- const events = tournamentRecord?.events || [];
4807
+ return decorateResult({
4808
+ result: { error: MISSING_TOURNAMENT_RECORD },
4809
+ stack
4810
+ });
4811
+ const events = tournamentRecord?.events ?? [];
4825
4812
  if (drawId) {
4826
4813
  let drawDefinition;
4827
4814
  const event = events.find((event2) => {
4828
- const drawDefinitions = event2?.drawDefinitions || [];
4815
+ const drawDefinitions = event2?.drawDefinitions ?? [];
4829
4816
  const targetDrawDefinition = drawDefinitions.find(
4830
4817
  (drawDefinition2) => drawDefinition2.drawId === drawId
4831
4818
  );
@@ -4904,7 +4891,7 @@ function addExtension$1(params) {
4904
4891
  });
4905
4892
  if (!params.element.extensions)
4906
4893
  params.element.extensions = [];
4907
- const creationTime = params.creationTime !== void 0 ? params.creationTime : true;
4894
+ const creationTime = params?.creationTime ?? true;
4908
4895
  if (creationTime) {
4909
4896
  const createdAt = (/* @__PURE__ */ new Date()).toISOString();
4910
4897
  Object.assign(params.extension, { createdAt });
@@ -5455,7 +5442,7 @@ function findCourt({
5455
5442
  } else if (tournamentRecords) {
5456
5443
  const linkedTournamentIds = getLinkedTournamentIds({
5457
5444
  tournamentRecords
5458
- }).linkedTournamentIds || [];
5445
+ }).linkedTournamentIds ?? [];
5459
5446
  const relevantIds = linkedTournamentIds[tournamentRecord.tournamentId];
5460
5447
  for (const tournamentId of relevantIds) {
5461
5448
  const record = tournamentRecords[tournamentId];
@@ -16570,6 +16557,10 @@ function proConflicts({
16570
16557
  return { courtIssues, rowIssues };
16571
16558
  }
16572
16559
 
16560
+ function stringSort(a, b) {
16561
+ return (a || "").localeCompare(b || "");
16562
+ }
16563
+
16573
16564
  function getTieFormatDesc(tieFormat) {
16574
16565
  if (!tieFormat)
16575
16566
  return {};
@@ -16652,7 +16643,30 @@ function compareTieFormats({
16652
16643
  ancestorDifferences.groupsCount = descendantDifferences.groupsCount ? -1 * descendantDifferences.groupsCount : 0;
16653
16644
  const valueDifference = descendantDifferences.collectionsValue.totalValue - ancestorDifferences.collectionsValue.totalValue;
16654
16645
  const matchUpCountDifference = descendantDifferences.collectionsValue.totalMatchUps - ancestorDifferences.collectionsValue.totalMatchUps;
16655
- const different = nameDifference || orderDifference || ancestorDesc !== descendantDesc || valueDifference !== 0;
16646
+ const assignmentValuesCountDifference = ancestorDifferences.collectionsValue.assignmentValues.length !== descendantDifferences.collectionsValue.assignmentValues.length;
16647
+ const assignmentValuesDifference = ancestorDifferences.collectionsValue.assignmentValues.some(
16648
+ (assignment, i) => {
16649
+ const comparisonAssignment = descendantDifferences.collectionsValue.assignmentValues[i];
16650
+ if (!comparisonAssignment)
16651
+ return true;
16652
+ if (assignment.valueKey !== comparisonAssignment.valueKey)
16653
+ return true;
16654
+ if (assignment.value !== comparisonAssignment.value)
16655
+ return true;
16656
+ if (Array.isArray(assignment.value)) {
16657
+ return assignment.value.every(
16658
+ (value, i2) => comparisonAssignment.value[i2] === value
16659
+ );
16660
+ }
16661
+ return false;
16662
+ }
16663
+ );
16664
+ const different = nameDifference || orderDifference || ancestorDesc !== descendantDesc || assignmentValuesCountDifference || assignmentValuesDifference || valueDifference !== 0;
16665
+ const invalidValues = [
16666
+ ...ancestorDifferences.collectionsValue.invalidValues,
16667
+ ...descendantDifferences.collectionsValue.invalidValues
16668
+ ];
16669
+ const invalid = invalidValues.length && invalidValues;
16656
16670
  return {
16657
16671
  matchUpFormatDifferences,
16658
16672
  matchUpCountDifference,
@@ -16664,12 +16678,15 @@ function compareTieFormats({
16664
16678
  descendantDesc,
16665
16679
  ancestorDesc,
16666
16680
  ...SUCCESS,
16667
- different
16681
+ different,
16682
+ invalid
16668
16683
  };
16669
16684
  }
16670
16685
  function getCollectionsValue(definitions) {
16686
+ const invalidValues = [];
16687
+ const assignmentValues = [];
16671
16688
  let totalMatchUps = 0;
16672
- const collectionIds = Object.keys(definitions);
16689
+ const collectionIds = Object.keys(definitions).sort(stringSort);
16673
16690
  const totalValue = collectionIds.reduce((total, collectionId) => {
16674
16691
  const collectionDefinition = definitions[collectionId];
16675
16692
  const {
@@ -16680,6 +16697,24 @@ function getCollectionsValue(definitions) {
16680
16697
  scoreValue,
16681
16698
  setValue
16682
16699
  } = collectionDefinition;
16700
+ const valueAssignments = {
16701
+ collectionValueProfiles,
16702
+ collectionValue,
16703
+ matchUpValue,
16704
+ scoreValue,
16705
+ setValue
16706
+ };
16707
+ const valueKeys = Object.keys(valueAssignments).filter(
16708
+ (key) => ![void 0, null].includes(valueAssignments[key])
16709
+ );
16710
+ if (valueKeys.length !== 1) {
16711
+ invalidValues.push({ collectionId });
16712
+ }
16713
+ const valueKey = valueKeys[0];
16714
+ if (valueKey) {
16715
+ const value = valueKey === "collectionValueProfiles" ? Object.values(collectionValueProfiles) : valueAssignments[valueKey];
16716
+ assignmentValues.push({ valueKey, value });
16717
+ }
16683
16718
  totalMatchUps += matchUpCount;
16684
16719
  if (collectionValueProfiles)
16685
16720
  return total + collectionValueProfiles.reduce(
@@ -16697,7 +16732,7 @@ function getCollectionsValue(definitions) {
16697
16732
  }
16698
16733
  return total;
16699
16734
  }, 0);
16700
- return { totalValue, totalMatchUps };
16735
+ return { totalValue, totalMatchUps, invalidValues, assignmentValues };
16701
16736
  }
16702
16737
 
16703
16738
  function dehydrateMatchUps({ tournamentRecord }) {
@@ -20759,7 +20794,7 @@ function removeSubsequentRoundsParticipant({
20759
20794
  const positionAssignments = getPositionAssignments$1({
20760
20795
  drawDefinition,
20761
20796
  structureId
20762
- }).positionAssignments || [];
20797
+ }).positionAssignments ?? [];
20763
20798
  relevantMatchUps?.forEach(
20764
20799
  (matchUp) => removeDrawPosition({
20765
20800
  drawPosition: targetDrawPosition,
@@ -20789,7 +20824,7 @@ function removeDrawPosition({
20789
20824
  const initialDrawPositions = targetMatchUp.drawPositions?.slice();
20790
20825
  const initialMatchUpStatus = targetMatchUp.matchUpStatus;
20791
20826
  const initialWinningSide = targetMatchUp.winningSide;
20792
- matchUpsMap = matchUpsMap || getMatchUpsMap({ drawDefinition });
20827
+ matchUpsMap = matchUpsMap ?? getMatchUpsMap({ drawDefinition });
20793
20828
  const mappedMatchUps = matchUpsMap.mappedMatchUps;
20794
20829
  const matchUps = mappedMatchUps[structure.structureId].matchUps;
20795
20830
  const { initialRoundNumber } = getInitialRoundNumber({
@@ -20797,7 +20832,7 @@ function removeDrawPosition({
20797
20832
  matchUps
20798
20833
  });
20799
20834
  if (targetMatchUp.roundNumber && initialRoundNumber && targetMatchUp.roundNumber > initialRoundNumber) {
20800
- const drawPositions = (targetMatchUp.drawPositions || []).map(
20835
+ const drawPositions = (targetMatchUp.drawPositions ?? []).map(
20801
20836
  (currentDrawPosition) => currentDrawPosition === drawPosition ? void 0 : currentDrawPosition
20802
20837
  );
20803
20838
  targetMatchUp.drawPositions = drawPositions;
@@ -20806,7 +20841,7 @@ function removeDrawPosition({
20806
20841
  const inContextTargetMatchUp = inContextDrawMatchUps?.find(
20807
20842
  (matchUp) => matchUp.matchUpId === targetMatchUp.matchUpId
20808
20843
  );
20809
- const sides = inContextTargetMatchUp?.sides || [];
20844
+ const sides = inContextTargetMatchUp?.sides ?? [];
20810
20845
  const drawPositionSideIndex = sides.reduce(
20811
20846
  (index, side, i) => side.drawPosition === drawPosition ? i : index,
20812
20847
  void 0
@@ -22025,9 +22060,7 @@ function assignMatchUpDrawPosition({
22025
22060
  return { ...SUCCESS };
22026
22061
  } else {
22027
22062
  return decorateResult({
22028
- result: {
22029
- error: DRAW_POSITION_ASSIGNED
22030
- },
22063
+ result: { error: DRAW_POSITION_ASSIGNED },
22031
22064
  context: { drawPosition },
22032
22065
  stack
22033
22066
  });
@@ -23104,8 +23137,8 @@ function getSeedGroups({
23104
23137
  return {
23105
23138
  seedGroups: void 0,
23106
23139
  ...decorateResult({
23107
- result: { error: INVALID_VALUES },
23108
23140
  context: { roundRobinGroupsCount },
23141
+ result: { error: INVALID_VALUES },
23109
23142
  stack
23110
23143
  })
23111
23144
  };
@@ -23149,8 +23182,8 @@ function getSeedingThresholds({
23149
23182
  const invalid = !validGroupsCounts?.includes(roundRobinGroupsCount);
23150
23183
  if (invalid) {
23151
23184
  return decorateResult({
23152
- result: { error: INVALID_VALUES },
23153
- context: { roundRobinGroupsCount }
23185
+ context: { roundRobinGroupsCount },
23186
+ result: { error: INVALID_VALUES }
23154
23187
  });
23155
23188
  }
23156
23189
  }
@@ -24257,7 +24290,8 @@ function directLoser(params) {
24257
24290
  if (result.error)
24258
24291
  return decorateResult({ result, stack });
24259
24292
  } else if (loserParticipantId && isFeedRound) {
24260
- const fedDrawPosition = unfilledTargetMatchUpDrawPositions.sort(numericSort)[0];
24293
+ unfilledTargetMatchUpDrawPositions.sort(numericSort);
24294
+ const fedDrawPosition = unfilledTargetMatchUpDrawPositions[0];
24261
24295
  const result = assignDrawPosition$1({
24262
24296
  participantId: loserParticipantId,
24263
24297
  structureId: targetStructureId,
@@ -25244,7 +25278,7 @@ function setMatchUpStatus$2(params) {
25244
25278
  drawDefinition
25245
25279
  });
25246
25280
  if (score && matchUp.matchUpType !== TEAM$2 && !disableScoreValidation) {
25247
- const matchUpFormat = matchUp.matchUpFormat || structure?.matchUpFormat || drawDefinition?.matchUpFormat || event?.matchUpFormat;
25281
+ const matchUpFormat = matchUp.matchUpFormat ?? structure?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
25248
25282
  const result2 = validateScore({
25249
25283
  existingMatchUpStatus: matchUp.matchUpStatus,
25250
25284
  matchUpFormat,
@@ -25265,9 +25299,9 @@ function setMatchUpStatus$2(params) {
25265
25299
  ).every((assignment) => assignment.participantId);
25266
25300
  if (matchUpStatus && particicipantsRequiredMatchUpStatuses.includes(matchUpStatus) && !bothSideParticipants) {
25267
25301
  return decorateResult({
25268
- result: { error: INVALID_MATCHUP_STATUS },
25269
25302
  info: "present in participantRequiredMatchUpStatuses",
25270
- context: { matchUpStatus, bothSideParticipants }
25303
+ context: { matchUpStatus, bothSideParticipants },
25304
+ result: { error: INVALID_MATCHUP_STATUS }
25271
25305
  });
25272
25306
  }
25273
25307
  const appliedPolicies = getAppliedPolicies({
@@ -25390,8 +25424,8 @@ function winningSideWithDownstreamDependencies(params) {
25390
25424
  return applyMatchUpValues(params);
25391
25425
  } else {
25392
25426
  return decorateResult({
25393
- result: { error: CANNOT_CHANGE_WINNING_SIDE },
25394
25427
  stack: "winningSideWithDownstreamDependencies",
25428
+ result: { error: CANNOT_CHANGE_WINNING_SIDE },
25395
25429
  context: { winningSide, matchUp }
25396
25430
  });
25397
25431
  }
@@ -25795,14 +25829,14 @@ function addDrawDefinition$1(params) {
25795
25829
  if (relevantFlight && !drawEntriesPresentInFlight) {
25796
25830
  return decorateResult({
25797
25831
  result: {
25798
- error: INVALID_DRAW_DEFINITION,
25799
- context: {
25800
- drawEntriesPresentInFlight,
25801
- matchingEventEntries,
25802
- relevantFlight
25803
- },
25804
- info: "Draw entries are not present in flight or do not match entryStatuses"
25805
- }
25832
+ error: INVALID_DRAW_DEFINITION
25833
+ },
25834
+ context: {
25835
+ drawEntriesPresentInFlight,
25836
+ matchingEventEntries,
25837
+ relevantFlight
25838
+ },
25839
+ info: "Draw entries are not present in flight or do not match entryStatuses"
25806
25840
  });
25807
25841
  }
25808
25842
  if (modifyEventEntries) {
@@ -25821,9 +25855,9 @@ function addDrawDefinition$1(params) {
25821
25855
  if (eventEntries && !matchingEventEntries)
25822
25856
  return decorateResult({
25823
25857
  result: {
25824
- error: INVALID_DRAW_DEFINITION,
25858
+ info: "Draw entries do not match event entryStatuses",
25825
25859
  context: { matchingEventEntries, eventEntries },
25826
- info: "Draw entries do not match event entryStatuses"
25860
+ error: INVALID_DRAW_DEFINITION
25827
25861
  }
25828
25862
  });
25829
25863
  const flightNumbers = flightProfile?.flights?.map(
@@ -26002,10 +26036,8 @@ function addParticipant$1({
26002
26036
  });
26003
26037
  } else if (participant.individualParticipantIds.length !== 2 && !pairOverride) {
26004
26038
  return decorateResult({
26005
- result: {
26006
- error: INVALID_PARTICIPANT_IDS,
26007
- info: "PAIR must be 2 individualParticipantIds"
26008
- },
26039
+ info: "PAIR must be 2 individualParticipantIds",
26040
+ result: { error: INVALID_PARTICIPANT_IDS },
26009
26041
  stack
26010
26042
  });
26011
26043
  } else {
@@ -29622,7 +29654,12 @@ function getTieFormat$1({
29622
29654
  }
29623
29655
  if (!tieFormat)
29624
29656
  return decorateResult({ result: { error: MISSING_TIE_FORMAT }, stack });
29625
- return { ...SUCCESS, tieFormat, matchUp, structure };
29657
+ return {
29658
+ ...SUCCESS,
29659
+ structure,
29660
+ tieFormat,
29661
+ matchUp
29662
+ };
29626
29663
  }
29627
29664
 
29628
29665
  function tieFormatTelemetry({ drawDefinition, auditData }) {
@@ -29637,13 +29674,59 @@ function tieFormatTelemetry({ drawDefinition, auditData }) {
29637
29674
  addExtension$1({ element: drawDefinition, extension: updatedExtension });
29638
29675
  }
29639
29676
 
29677
+ function generateTieMatchUps({
29678
+ tieFormat,
29679
+ isMock,
29680
+ uuids
29681
+ }) {
29682
+ const { collectionDefinitions } = tieFormat ?? {};
29683
+ const tieMatchUps = (collectionDefinitions ?? []).map(
29684
+ (collectionDefinition) => generateCollectionMatchUps({ collectionDefinition, uuids, isMock })
29685
+ ).filter(Boolean).flat();
29686
+ return { tieMatchUps };
29687
+ }
29688
+ function generateCollectionMatchUps({
29689
+ collectionPositionOffset = 0,
29690
+ collectionDefinition,
29691
+ matchUpsLimit,
29692
+ // internal use allows generation of missing matchUps on "reset"
29693
+ isMock,
29694
+ uuids
29695
+ }) {
29696
+ const { matchUpCount, matchUpType, collectionId, processCodes } = collectionDefinition || {};
29697
+ const numberToGenerate = matchUpsLimit ?? matchUpCount ?? 0;
29698
+ return generateRange(0, numberToGenerate).map((index) => {
29699
+ const collectionPosition = collectionPositionOffset + index + 1;
29700
+ return {
29701
+ sides: [{ sideNumber: 1 }, { sideNumber: 2 }],
29702
+ matchUpId: uuids?.pop() || UUID(),
29703
+ matchUpStatus: MatchUpStatusEnum.ToBePlayed,
29704
+ collectionPosition,
29705
+ collectionId,
29706
+ processCodes,
29707
+ matchUpType,
29708
+ isMock
29709
+ };
29710
+ });
29711
+ }
29712
+
29640
29713
  function validUpdate({ matchUp, updateInProgressMatchUps }) {
29641
29714
  return !matchUp.winningSide && ![completedMatchUpStatuses].includes(matchUp.matchUpStatus) && (updateInProgressMatchUps || matchUp.matchUpStatus !== IN_PROGRESS$1 && !scoreHasValue(matchUp));
29642
29715
  }
29643
29716
 
29644
- function mapsCheck(map1, map2) {
29645
- const referenceKeys = Object.keys(map1);
29646
- return intersection(referenceKeys, Object.keys(map2)).length === referenceKeys.length;
29717
+ function checkStructureMatchUpCounts({ from, to }) {
29718
+ const referenceKeys = Object.keys(from);
29719
+ const sameKeys = intersection(referenceKeys, Object.keys(to)).length === referenceKeys.length;
29720
+ const differentMatchUpsCount = referenceKeys.filter(
29721
+ (collectionId) => from[collectionId] !== to[collectionId]
29722
+ );
29723
+ const matchUpsCountChanges = differentMatchUpsCount.map((collectionId) => ({
29724
+ countChange: to[collectionId] - from[collectionId],
29725
+ collectionId
29726
+ }));
29727
+ const sameMatchUpsCount = referenceKeys.every((key) => from[key] === to[key]);
29728
+ const equivalent = sameKeys && sameMatchUpsCount;
29729
+ return { equivalent, matchUpsCountChanges };
29647
29730
  }
29648
29731
  function updateTieFormat({
29649
29732
  updateInProgressMatchUps,
@@ -29653,10 +29736,15 @@ function updateTieFormat({
29653
29736
  tieFormat,
29654
29737
  eventId,
29655
29738
  matchUp,
29656
- event
29739
+ event,
29740
+ uuids
29657
29741
  }) {
29742
+ console.log("booo", { matchUp });
29658
29743
  const stack = "updateTieFormat";
29744
+ const tournamentId = tournamentRecord?.tournamentId;
29659
29745
  let modifiedStructuresCount = 0;
29746
+ let modifiedMatchUpsCount = 0;
29747
+ let addedMatchUpsCount = 0;
29660
29748
  let modifiedCount = 0;
29661
29749
  const collectionMap = tieFormat?.collectionDefinitions.reduce(
29662
29750
  (instanceMap, def) => {
@@ -29670,7 +29758,7 @@ function updateTieFormat({
29670
29758
  instanceMap[def.collectionId] = (instanceMap[def.collectionId] || 0) + def.matchUpCount;
29671
29759
  return instanceMap;
29672
29760
  }, {});
29673
- return mapsCheck(collectionMap, cMap);
29761
+ return checkStructureMatchUpCounts({ from: cMap, to: collectionMap }).equivalent;
29674
29762
  };
29675
29763
  const drawDefaultTieFormat = getTieFormat$1({ drawDefinition })?.tieFormat;
29676
29764
  const eventDefaultTieFormat = getTieFormat$1({ event })?.tieFormat;
@@ -29678,7 +29766,7 @@ function updateTieFormat({
29678
29766
  for (const drawDefinition2 of event.drawDefinitions ?? []) {
29679
29767
  processDrawDefinition({ drawDefinition: drawDefinition2 });
29680
29768
  }
29681
- event.tieFormat = tieFormat;
29769
+ event.tieFormat = copyTieFormat(tieFormat);
29682
29770
  modifiedCount += 1;
29683
29771
  } else if (matchUp) {
29684
29772
  if (!matchUp.tieMatchUps) {
@@ -29687,54 +29775,83 @@ function updateTieFormat({
29687
29775
  const matchUpMap = instanceCount(
29688
29776
  matchUp.tieMatchUps?.map(({ collectionId }) => collectionId)
29689
29777
  );
29690
- if (mapsCheck(collectionMap, matchUpMap)) {
29778
+ const check = checkStructureMatchUpCounts({
29779
+ to: collectionMap,
29780
+ from: matchUpMap
29781
+ });
29782
+ const { changes, changesArePossible, cannotChangeReaon } = getMatchUpChangesArePossible({
29783
+ matchUp,
29784
+ check
29785
+ });
29786
+ if (check.equivalent) {
29691
29787
  if (validUpdate({ matchUp, updateInProgressMatchUps })) {
29692
- matchUp.tieFormat = tieFormat;
29788
+ matchUp.tieFormat = copyTieFormat(tieFormat);
29693
29789
  modifiedCount += 1;
29694
29790
  } else {
29695
29791
  return decorateResult({
29696
29792
  result: { error: CANNOT_MODIFY_TIEFORMAT },
29697
- info: "matchUp is IN_PROGRESS or COMPLETE"
29793
+ info: "matchUp is IN_PROGRESS or COMPLETE",
29794
+ stack
29698
29795
  });
29699
29796
  }
29797
+ } else if (changesArePossible) {
29798
+ makeChanges({ tieFormat, matchUp, changes, uuids });
29700
29799
  } else {
29701
29800
  return decorateResult({
29702
29801
  context: { collectionMap, matchUpMap },
29703
29802
  result: { error: INVALID_TIE_FORMAT },
29704
- info: "on matchUp",
29803
+ info: cannotChangeReaon || "specified changes not possible",
29705
29804
  stack
29706
29805
  });
29707
29806
  }
29807
+ modifiedMatchUpsCount += 1;
29708
29808
  modifyMatchUpNotice({
29709
- tournamentId: tournamentRecord?.tournamentId,
29710
29809
  eventId: event?.eventId,
29711
29810
  context: stack,
29712
29811
  drawDefinition,
29812
+ tournamentId,
29713
29813
  matchUp
29714
29814
  });
29715
29815
  } else if (structure) {
29716
- const inheritedTieFormat = drawDefaultTieFormat || eventDefaultTieFormat;
29816
+ const inheritedTieFormat = drawDefaultTieFormat ?? eventDefaultTieFormat;
29717
29817
  const modified = processStructure({
29718
29818
  inheritedTieFormat,
29719
29819
  structure
29720
- })?.modifiedCount;
29721
- if (modified)
29722
- modifiedStructuresCount += modified;
29723
- structure.tieFormat = tieFormat;
29724
- modifiedCount += 1;
29725
- modifyDrawNotice({
29820
+ })?.modifiedMatchUpsCount;
29821
+ if (modified) {
29822
+ modifiedMatchUpsCount += modified;
29823
+ modifiedStructuresCount += 1;
29824
+ modifiedCount += 1;
29825
+ }
29826
+ const different = !structure.tieFormat || compareTieFormats({
29827
+ ancestor: structure.tieFormat,
29828
+ descendant: tieFormat
29829
+ }).different;
29830
+ if (different) {
29831
+ structure.tieFormat = copyTieFormat(tieFormat);
29832
+ modifiedStructuresCount += 1;
29833
+ modifiedCount += 1;
29834
+ }
29835
+ (modified || different) && drawDefinition && modifyDrawNotice({
29726
29836
  structureIds: [structure.structureId],
29727
29837
  eventId: event?.eventId,
29728
29838
  drawDefinition
29729
29839
  });
29730
29840
  } else if (drawDefinition) {
29731
29841
  processDrawDefinition({ drawDefinition });
29732
- drawDefinition.tieFormat = tieFormat;
29842
+ drawDefinition.tieFormat = copyTieFormat(tieFormat);
29733
29843
  modifiedCount += 1;
29734
29844
  } else {
29735
29845
  return { error: MISSING_DRAW_DEFINITION };
29736
29846
  }
29737
- return { ...SUCCESS, modifiedCount, modifiedStructuresCount, tieFormat };
29847
+ return {
29848
+ modifiedStructuresCount,
29849
+ modifiedMatchUpsCount,
29850
+ addedMatchUpsCount,
29851
+ modifiedCount,
29852
+ ...SUCCESS,
29853
+ tieFormat
29854
+ };
29738
29855
  function processDrawDefinition({ drawDefinition: drawDefinition2 }) {
29739
29856
  const structures = drawDefinition2.structures || [];
29740
29857
  const modifiedStructureIds = [];
@@ -29745,9 +29862,10 @@ function updateTieFormat({
29745
29862
  const modifiedCount2 = processStructure({
29746
29863
  inheritedTieFormat,
29747
29864
  structure: structure2
29748
- })?.modifiedCount;
29865
+ })?.modifiedMatchUpsCount;
29749
29866
  if (modifiedCount2) {
29750
- modifiedStructuresCount += modifiedCount2;
29867
+ modifiedStructuresCount += 1;
29868
+ modifiedMatchUpsCount += modifiedCount2;
29751
29869
  const structureId = structure2.structureId;
29752
29870
  modifiedStructureIds.push(structureId);
29753
29871
  }
@@ -29760,32 +29878,49 @@ function updateTieFormat({
29760
29878
  return modifiedStructureIds.length;
29761
29879
  }
29762
29880
  function processStructure({ inheritedTieFormat, structure: structure2 }) {
29763
- let modifiedCount2 = 0;
29881
+ let modifiedMatchUpsCount2 = 0;
29764
29882
  const structureMatchUps = getAllStructureMatchUps({
29765
29883
  matchUpFilters: { matchUpTypes: [TEAM$2] },
29766
29884
  structure: structure2
29767
29885
  })?.matchUps || [];
29768
29886
  for (const matchUp2 of structureMatchUps) {
29887
+ const validToUpdate = validUpdate({ matchUp: matchUp2, updateInProgressMatchUps });
29769
29888
  let modified = false;
29770
29889
  const tieMatchUpsMap = instanceCount(
29771
29890
  matchUp2.tieMatchUps?.map(({ collectionId }) => collectionId)
29772
29891
  );
29773
- if (!mapsCheck(collectionMap, tieMatchUpsMap)) {
29774
- if (inheritedTieFormat) {
29775
- matchUp2.tieFormat = inheritedTieFormat;
29776
- modified = true;
29892
+ const check = checkStructureMatchUpCounts({
29893
+ from: tieMatchUpsMap,
29894
+ to: collectionMap
29895
+ });
29896
+ if (!check.equivalent) {
29897
+ const { changes, changesArePossible } = getMatchUpChangesArePossible({
29898
+ matchUp: matchUp2,
29899
+ check
29900
+ });
29901
+ if (changesArePossible && !matchUp2.tieFormat) {
29902
+ makeChanges({ changes, matchUp: matchUp2, tieFormat, uuids });
29903
+ } else if (inheritedTieFormat) {
29904
+ const different = !matchUp2.tieFormat || compareTieFormats({
29905
+ ancestor: inheritedTieFormat,
29906
+ descendant: matchUp2.tieFormat
29907
+ }).different;
29908
+ if (different) {
29909
+ matchUp2.tieFormat = inheritedTieFormat;
29910
+ modified = true;
29911
+ }
29777
29912
  } else {
29778
29913
  return decorateResult({
29779
29914
  result: { error: MISSING_TIE_FORMAT },
29780
29915
  stack
29781
29916
  });
29782
29917
  }
29783
- } else if (matchUp2.tieFormat && matchingCollections(matchUp2) && validUpdate({ matchUp: matchUp2, updateInProgressMatchUps })) {
29918
+ } else if (matchUp2.tieFormat && matchingCollections(matchUp2) && validToUpdate) {
29784
29919
  matchUp2.tieFormat = copyTieFormat(tieFormat);
29785
29920
  modified = true;
29786
29921
  }
29787
29922
  if (modified) {
29788
- modifiedCount2 += 1;
29923
+ modifiedMatchUpsCount2 += 1;
29789
29924
  modifyMatchUpNotice({
29790
29925
  tournamentId: tournamentRecord?.tournamentId,
29791
29926
  drawDefinition,
@@ -29795,8 +29930,80 @@ function updateTieFormat({
29795
29930
  });
29796
29931
  }
29797
29932
  }
29798
- return { modifiedCount: modifiedCount2 };
29933
+ return { modifiedMatchUpsCount: modifiedMatchUpsCount2 };
29799
29934
  }
29935
+ function makeChanges({ uuids: uuids2, matchUp: matchUp2, tieFormat: tieFormat2, changes }) {
29936
+ matchUp2.tieFormat = copyTieFormat(tieFormat2);
29937
+ const matchUpIdsRemoved = [];
29938
+ const matchUpsAdded = [];
29939
+ changes.forEach((change) => {
29940
+ if (change.countChange > 0) {
29941
+ const collectionPositionOffset = Math.max(
29942
+ 0,
29943
+ ...matchUp2.tieMatchUps.filter(
29944
+ (tieMatchUp) => tieMatchUp.collectionId === change.collectionId
29945
+ ).map(extractAttributes("collectionPosition"))
29946
+ );
29947
+ const collectionDefinition = tieFormat2.collectionDefinitions.find(
29948
+ (def) => def.collectionId === change.collectionId
29949
+ );
29950
+ const newMatchUps = generateCollectionMatchUps({
29951
+ matchUpsLimit: change.countChange,
29952
+ collectionPositionOffset,
29953
+ collectionDefinition,
29954
+ uuids: uuids2
29955
+ });
29956
+ matchUpsAdded.push(...makeDeepCopy(newMatchUps, false, true));
29957
+ addedMatchUpsCount += matchUpsAdded.length;
29958
+ matchUp2.tieMatchUps.push(...newMatchUps);
29959
+ } else {
29960
+ const tieMatchUpIdsToRemove = change.toBePlayedTieMatchUpIds.slice(
29961
+ 0,
29962
+ Math.abs(change.countChange)
29963
+ );
29964
+ console.log("remove", tieMatchUpIdsToRemove.length);
29965
+ matchUpIdsRemoved.push(...tieMatchUpIdsToRemove);
29966
+ matchUp2.tieMatchUps = matchUp2.tieMatchUps.filter(
29967
+ ({ matchUpId }) => !tieMatchUpIdsToRemove.includes(matchUpId)
29968
+ );
29969
+ }
29970
+ });
29971
+ matchUpsAdded.length && addMatchUpsNotice({
29972
+ matchUps: matchUpsAdded,
29973
+ drawDefinition,
29974
+ tournamentId,
29975
+ eventId
29976
+ });
29977
+ matchUpIdsRemoved.length && deleteMatchUpsNotice({
29978
+ matchUpIds: matchUpIdsRemoved,
29979
+ action: "updateTieFormat",
29980
+ drawDefinition,
29981
+ tournamentId,
29982
+ eventId
29983
+ });
29984
+ return { matchUpIdsRemoved, matchUpsAdded };
29985
+ }
29986
+ }
29987
+ function getMatchUpChangesArePossible({ check, matchUp }) {
29988
+ let cannotChangeReaon = "";
29989
+ const changes = [];
29990
+ const changesArePossible = check.matchUpsCountChanges.every(
29991
+ ({ collectionId, countChange }) => {
29992
+ const toBePlayedTieMatchUpIds = matchUp.tieMatchUps.filter(
29993
+ (tieMatchUp) => tieMatchUp.collectionId === collectionId && tieMatchUp.matchUpStatus === TO_BE_PLAYED
29994
+ ).map(extractAttributes("matchUpId"));
29995
+ const possibleToChange = toBePlayedTieMatchUpIds.length + countChange >= 0 || countChange > 0;
29996
+ if (!possibleToChange && countChange < 0)
29997
+ cannotChangeReaon = "Insufficient TO_BE_PLAYED matchUps";
29998
+ changes.push({
29999
+ toBePlayedTieMatchUpIds,
30000
+ collectionId,
30001
+ countChange
30002
+ });
30003
+ return possibleToChange;
30004
+ }
30005
+ );
30006
+ return { changesArePossible, changes, cannotChangeReaon };
29800
30007
  }
29801
30008
 
29802
30009
  function modifyCollectionDefinition$1({
@@ -29859,7 +30066,7 @@ function modifyCollectionDefinition$1({
29859
30066
  scoreValue,
29860
30067
  setValue
29861
30068
  };
29862
- if (!Object.values(valueAssignments).filter(Boolean).length && !collectionOrder && !collectionName && !matchUpCount && !matchUpFormat)
30069
+ if (!Object.values(valueAssignments).filter(Boolean).length && !collectionOrder && !collectionName && !matchUpFormat && !matchUpCount && !matchUpType)
29863
30070
  return decorateResult({ result: { error: MISSING_VALUE }, stack });
29864
30071
  if (Object.values(valueAssignments).filter(Boolean).length > 1)
29865
30072
  return decorateResult({
@@ -29886,11 +30093,16 @@ function modifyCollectionDefinition$1({
29886
30093
  (collectionDefinition) => collectionDefinition.collectionId === collectionId
29887
30094
  );
29888
30095
  if (!sourceCollectionDefinition)
29889
- return decorateResult({ result: { error: NOT_FOUND }, stack });
30096
+ return decorateResult({
30097
+ info: "source collectionDefinition",
30098
+ result: { error: NOT_FOUND },
30099
+ context: { collectionId },
30100
+ stack
30101
+ });
29890
30102
  const value = collectionValue ?? matchUpValue ?? scoreValue ?? setValue;
29891
30103
  if (collectionValueProfiles) {
29892
- const result2 = validateCollectionValueProfile({
29893
- matchUpCount: matchUpCount || sourceCollectionDefinition?.matchUpCount,
30104
+ const result2 = validateCollectionValueProfiles({
30105
+ matchUpCount: matchUpCount ?? sourceCollectionDefinition?.matchUpCount,
29894
30106
  collectionValueProfiles
29895
30107
  });
29896
30108
  if (result2.errors) {
@@ -29966,11 +30178,8 @@ function modifyCollectionDefinition$1({
29966
30178
  modifications.push({ collectionId, matchUpFormat });
29967
30179
  }
29968
30180
  if (isConvertableInteger(matchUpCount) && sourceCollectionDefinition.matchUpCount !== matchUpCount) {
29969
- return decorateResult({
29970
- result: { error: NOT_IMPLEMENTED },
29971
- context: { matchUpCount },
29972
- stack
29973
- });
30181
+ targetCollectionDefinition.matchUpCount = matchUpCount;
30182
+ modifications.push({ collectionId, matchUpCount });
29974
30183
  }
29975
30184
  if (matchUpType && sourceCollectionDefinition.matchUpType !== matchUpType) {
29976
30185
  return decorateResult({
@@ -29987,8 +30196,8 @@ function modifyCollectionDefinition$1({
29987
30196
  targetCollectionDefinition.gender = gender;
29988
30197
  modifications.push({ collectionId, gender });
29989
30198
  }
29990
- const prunedTieFormat = definedAttributes(tieFormat);
29991
- result = validateTieFormat({ tieFormat: prunedTieFormat });
30199
+ const modifiedTieFormat = definedAttributes(tieFormat);
30200
+ result = validateTieFormat({ tieFormat: modifiedTieFormat });
29992
30201
  if (result.error) {
29993
30202
  return decorateResult({ result, stack });
29994
30203
  }
@@ -29997,16 +30206,16 @@ function modifyCollectionDefinition$1({
29997
30206
  }
29998
30207
  const changedTieFormatName = existingTieFormat?.tieFormatName !== tieFormatName;
29999
30208
  if (changedTieFormatName) {
30000
- prunedTieFormat.tieFormatName = tieFormatName;
30209
+ modifiedTieFormat.tieFormatName = tieFormatName;
30001
30210
  modifications.push({ tieFormatName });
30002
30211
  } else if (modifications.length) {
30003
- delete prunedTieFormat.tieFormatName;
30212
+ delete modifiedTieFormat.tieFormatName;
30004
30213
  modifications.push(
30005
30214
  "tieFormatName removed: modifications without new tieFormatName"
30006
30215
  );
30007
30216
  }
30008
30217
  result = updateTieFormat({
30009
- tieFormat: prunedTieFormat,
30218
+ tieFormat: modifiedTieFormat,
30010
30219
  updateInProgressMatchUps,
30011
30220
  tournamentRecord,
30012
30221
  drawDefinition,
@@ -30299,17 +30508,17 @@ function removeCollectionDefinition$1({
30299
30508
  matchUps = getAllStructureMatchUps({
30300
30509
  matchUpFilters: { matchUpTypes: [TEAM$2] },
30301
30510
  structure
30302
- })?.matchUps || [];
30511
+ })?.matchUps ?? [];
30303
30512
  } else if (drawDefinition) {
30304
30513
  matchUps = allDrawMatchUps$1({
30305
30514
  matchUpFilters: { matchUpTypes: [TEAM$2] },
30306
30515
  drawDefinition
30307
- })?.matchUps || [];
30516
+ })?.matchUps ?? [];
30308
30517
  } else if (event) {
30309
30518
  matchUps = allEventMatchUps({
30310
30519
  matchUpFilters: { matchUpTypes: [TEAM$2] },
30311
30520
  drawDefinition
30312
- })?.matchUps || [];
30521
+ })?.matchUps ?? [];
30313
30522
  }
30314
30523
  const targetMatchUps = (matchUps || []).filter((matchUp2) => {
30315
30524
  const collectionMatchUps = matchUp2.tieMatchUps?.filter(
@@ -30435,41 +30644,6 @@ function removeCollectionDefinition(params) {
30435
30644
  return resolveTournamentRecord({ ...params, method: removeCollectionDefinition$1 });
30436
30645
  }
30437
30646
 
30438
- function generateTieMatchUps({
30439
- tieFormat,
30440
- isMock,
30441
- uuids
30442
- }) {
30443
- const { collectionDefinitions } = tieFormat || {};
30444
- const tieMatchUps = (collectionDefinitions || []).map(
30445
- (collectionDefinition) => generateCollectionMatchUps({ collectionDefinition, uuids, isMock })
30446
- ).filter(Boolean).flat();
30447
- return { tieMatchUps };
30448
- }
30449
- function generateCollectionMatchUps({
30450
- collectionDefinition,
30451
- matchUpsLimit,
30452
- // internal use allows generation of missing matchUps on "reset"
30453
- isMock,
30454
- uuids
30455
- }) {
30456
- const { matchUpCount, matchUpType, collectionId, processCodes } = collectionDefinition || {};
30457
- const numberToGenerate = matchUpsLimit || matchUpCount || 0;
30458
- return generateRange(0, numberToGenerate).map((index) => {
30459
- const collectionPosition = index + 1;
30460
- return {
30461
- sides: [{ sideNumber: 1 }, { sideNumber: 2 }],
30462
- matchUpId: uuids?.pop() || UUID(),
30463
- matchUpStatus: MatchUpStatusEnum.ToBePlayed,
30464
- collectionPosition,
30465
- collectionId,
30466
- processCodes,
30467
- matchUpType,
30468
- isMock
30469
- };
30470
- });
30471
- }
30472
-
30473
30647
  function addCollectionDefinition$1({
30474
30648
  updateInProgressMatchUps = true,
30475
30649
  collectionDefinition,
@@ -30485,6 +30659,7 @@ function addCollectionDefinition$1({
30485
30659
  uuids,
30486
30660
  event
30487
30661
  }) {
30662
+ const stack = "addCollectionDefinition";
30488
30663
  const appliedPolicies = getAppliedPolicies({
30489
30664
  tournamentRecord,
30490
30665
  drawDefinition,
@@ -30498,10 +30673,10 @@ function addCollectionDefinition$1({
30498
30673
  checkGender,
30499
30674
  event
30500
30675
  });
30501
- if (!valid)
30502
- return { error: INVALID_VALUES, errors };
30503
- const stack = "addCollectionDefinition";
30504
- let result = !matchUp ? getTieFormat$1({
30676
+ if (!valid) {
30677
+ return decorateResult({ result: { error: INVALID_VALUES, errors }, stack });
30678
+ }
30679
+ let result = !matchUp?.tieFormat ? getTieFormat$1({
30505
30680
  drawDefinition,
30506
30681
  structureId,
30507
30682
  matchUpId,
@@ -30509,14 +30684,15 @@ function addCollectionDefinition$1({
30509
30684
  event
30510
30685
  }) : void 0;
30511
30686
  if (result?.error)
30512
- return { error: result.error };
30687
+ return decorateResult({ result: { error: result.error }, stack });
30513
30688
  const structure = result?.structure;
30514
30689
  matchUp = matchUp ?? result?.matchUp;
30515
- const existingTieFormat = result?.tieFormat;
30690
+ const existingTieFormat = matchUp?.tieFormat ?? result?.tieFormat;
30516
30691
  const tieFormat = copyTieFormat(existingTieFormat);
30517
30692
  result = validateTieFormat({ tieFormat });
30518
- if (result?.error)
30519
- return { error: result.error };
30693
+ if (result?.error) {
30694
+ return decorateResult({ result: { error: result.error }, stack });
30695
+ }
30520
30696
  if (!collectionDefinition.collectionId) {
30521
30697
  collectionDefinition.collectionId = UUID();
30522
30698
  } else {
@@ -30549,8 +30725,9 @@ function addCollectionDefinition$1({
30549
30725
  let targetMatchUps = [];
30550
30726
  const prunedTieFormat = definedAttributes(tieFormat);
30551
30727
  result = validateTieFormat({ tieFormat: prunedTieFormat });
30552
- if (result?.error)
30553
- return { error: result.error };
30728
+ if (result?.error) {
30729
+ return decorateResult({ result: { error: result.error }, stack });
30730
+ }
30554
30731
  if (eventId && event) {
30555
30732
  event.tieFormat = prunedTieFormat;
30556
30733
  for (const drawDefinition2 of event.drawDefinitions ?? []) {
@@ -30631,7 +30808,7 @@ function addCollectionDefinition$1({
30631
30808
  structure: structure2,
30632
30809
  uuids
30633
30810
  });
30634
- modifiedStructureIds.push(structureId);
30811
+ modifiedStructureIds.push(structure2.structureId);
30635
30812
  addedMatchUps.push(...result2.newMatchUps);
30636
30813
  targetMatchUps.push(...result2.targetMatchUps);
30637
30814
  }
@@ -30725,146 +30902,6 @@ function addCollectionDefinition(params) {
30725
30902
  return resolveTournamentRecord({ ...params, method: addCollectionDefinition$1 });
30726
30903
  }
30727
30904
 
30728
- function publicFindMatchUp(params) {
30729
- Object.assign(params, { inContext: true });
30730
- const { matchUp, error } = findMatchUp(params);
30731
- return { matchUp: makeDeepCopy(matchUp, true, true), error };
30732
- }
30733
- function findMatchUp({
30734
- participantsProfile,
30735
- afterRecoveryTimes,
30736
- tournamentRecord,
30737
- contextContent,
30738
- contextProfile,
30739
- drawDefinition,
30740
- matchUpId,
30741
- inContext,
30742
- eventId,
30743
- drawId,
30744
- event
30745
- }) {
30746
- if (!tournamentRecord)
30747
- return { error: MISSING_TOURNAMENT_RECORD };
30748
- if (typeof matchUpId !== "string")
30749
- return { error: MISSING_MATCHUP_ID };
30750
- if (!drawDefinition || !event) {
30751
- const matchUps = allTournamentMatchUps({ tournamentRecord }).matchUps || [];
30752
- const inContextMatchUp = matchUps.find(
30753
- (matchUp2) => matchUp2.matchUpId === matchUpId
30754
- );
30755
- if (!inContextMatchUp)
30756
- return { error: MATCHUP_NOT_FOUND };
30757
- ({ eventId, drawId } = inContextMatchUp);
30758
- ({ event, drawDefinition } = findEvent({
30759
- tournamentRecord,
30760
- eventId,
30761
- drawId
30762
- }));
30763
- }
30764
- if (!drawDefinition)
30765
- return { error: DRAW_DEFINITION_NOT_FOUND };
30766
- if (contextProfile && !contextContent)
30767
- contextContent = getContextContent({ tournamentRecord, contextProfile });
30768
- const additionalContext = {
30769
- surfaceCategory: event?.surfaceCategory || tournamentRecord.surfaceCategory,
30770
- indoorOutDoor: event?.indoorOutdoor || tournamentRecord.indoorOutdoor,
30771
- endDate: event?.endDate || tournamentRecord.endDate,
30772
- tournamentId: tournamentRecord.tournamentId,
30773
- eventId: eventId || event?.eventId,
30774
- drawId
30775
- };
30776
- const { participants: tournamentParticipants = [] } = hydrateParticipants({
30777
- participantsProfile,
30778
- tournamentRecord,
30779
- contextProfile,
30780
- inContext
30781
- });
30782
- const { matchUp, structure } = findMatchUp$1({
30783
- context: inContext ? additionalContext : void 0,
30784
- tournamentParticipants,
30785
- afterRecoveryTimes,
30786
- contextContent,
30787
- drawDefinition,
30788
- contextProfile,
30789
- matchUpId,
30790
- inContext,
30791
- event
30792
- });
30793
- return { matchUp, structure, drawDefinition };
30794
- }
30795
-
30796
- function getTieFormat({
30797
- tournamentRecord,
30798
- // passed in automatically by tournamentEngine
30799
- drawDefinition,
30800
- // passed in automatically by tournamentEngine when drawId provided
30801
- structureId,
30802
- // optional - if only the default matchUpFormat for a structure is required
30803
- matchUpId,
30804
- // id of matchUp for which the scoped matchUpFormat(s) are desired
30805
- structure,
30806
- // optional optimization - when structure already known
30807
- eventId,
30808
- // optional - if only the default matchUpFormat for an event is required
30809
- drawId,
30810
- // avoid brute force search for matchUp
30811
- event
30812
- // passed in automatically by tournamentEngine when drawId or eventId provided
30813
- }) {
30814
- if (!tournamentRecord)
30815
- return { error: MISSING_TOURNAMENT_RECORD };
30816
- if (!drawId && !event && !structureId && !matchUpId)
30817
- return decorateResult({
30818
- result: { error: MISSING_VALUE },
30819
- stack: "getTieFormat"
30820
- });
30821
- if (eventId && !event) {
30822
- event = tournamentRecord.events?.find((event2) => event2.eventId === eventId);
30823
- }
30824
- const matchUpResult = findMatchUp({
30825
- tournamentRecord,
30826
- drawDefinition,
30827
- matchUpId,
30828
- drawId,
30829
- event
30830
- });
30831
- if (matchUpId && matchUpResult?.error) {
30832
- return matchUpResult;
30833
- } else if (!drawDefinition && matchUpResult?.drawDefinition) {
30834
- drawDefinition = matchUpResult?.drawDefinition;
30835
- }
30836
- structure = structure ?? matchUpResult?.structure;
30837
- if (!structure && structureId && !matchUpId) {
30838
- if (!drawDefinition)
30839
- return { error: MISSING_DRAW_ID };
30840
- const structureResult = findStructure({ drawDefinition, structureId });
30841
- if (structureResult.error)
30842
- return structureResult;
30843
- structure = structureResult.structure;
30844
- }
30845
- const structureDefaultTieFormat = (structure?.tieFormat || structure?.tieFormatId) && resolveTieFormat({ structure, drawDefinition, event })?.tieFormat;
30846
- const drawDefaultTieFormat = (drawDefinition?.tieFormat || drawDefinition?.tieFormatId) && resolveTieFormat({
30847
- drawDefinition,
30848
- event
30849
- })?.tieFormat;
30850
- const eventDefaultTieFormat = resolveTieFormat({ event })?.tieFormat;
30851
- const tieFormat = resolveTieFormat({
30852
- matchUp: matchUpResult?.matchUp,
30853
- drawDefinition,
30854
- structure,
30855
- event
30856
- })?.tieFormat;
30857
- return {
30858
- ...SUCCESS,
30859
- matchUp: matchUpResult?.matchUp,
30860
- structureDefaultTieFormat,
30861
- eventDefaultTieFormat,
30862
- drawDefaultTieFormat,
30863
- tieFormat,
30864
- structure
30865
- };
30866
- }
30867
-
30868
30905
  function updateTargetTeamMatchUps({
30869
30906
  updateInProgressMatchUps,
30870
30907
  tournamentRecord,
@@ -31010,8 +31047,7 @@ function removeCollectionGroup$1({
31010
31047
  if (isNaN(collectionGroupNumber))
31011
31048
  return { error: INVALID_VALUES };
31012
31049
  const stack = "removeCollectionGroup";
31013
- let result = !matchUp ? getTieFormat({
31014
- tournamentRecord,
31050
+ let result = !matchUp ? getTieFormat$1({
31015
31051
  drawDefinition,
31016
31052
  structureId,
31017
31053
  matchUpId,
@@ -31120,10 +31156,8 @@ function addCollectionGroup$1({
31120
31156
  const { collectionId, collectionGroupNumber: collectionGroupNumber2 } = collectionDefinition;
31121
31157
  if (collectionGroupNumber2 && collectionIds.includes(collectionId))
31122
31158
  return decorateResult({
31123
- result: {
31124
- error: INVALID_VALUES,
31125
- info: "collectionIds cannot be part of other collectionGroups"
31126
- },
31159
+ info: "collectionIds cannot be part of other collectionGroups",
31160
+ result: { error: INVALID_VALUES },
31127
31161
  stack
31128
31162
  });
31129
31163
  }
@@ -31178,9 +31212,14 @@ function modifyTieFormat$1({
31178
31212
  uuids,
31179
31213
  event
31180
31214
  }) {
31181
- const stack = "updateTieFormat";
31182
- if (!validateTieFormat(modifiedTieFormat))
31183
- return { error: INVALID_TIE_FORMAT };
31215
+ const stack = "modifyTieFormat";
31216
+ if (!validateTieFormat({ tieFormat: modifiedTieFormat }).valid) {
31217
+ return decorateResult({
31218
+ result: { error: INVALID_TIE_FORMAT },
31219
+ info: "falied validation",
31220
+ stack
31221
+ });
31222
+ }
31184
31223
  const result = getTieFormat$1({
31185
31224
  drawDefinition,
31186
31225
  structureId,
@@ -31192,8 +31231,23 @@ function modifyTieFormat$1({
31192
31231
  return decorateResult({ result, stack });
31193
31232
  const { matchUp, tieFormat: existingTieFormat } = result;
31194
31233
  const tieFormat = copyTieFormat(existingTieFormat);
31195
- if (!compareTieFormats({ ancestor: tieFormat, descendant: modifiedTieFormat })?.different) {
31196
- return { ...SUCCESS };
31234
+ const comparison = compareTieFormats({
31235
+ descendant: modifiedTieFormat,
31236
+ ancestor: tieFormat
31237
+ });
31238
+ if (comparison.invalid) {
31239
+ return decorateResult({
31240
+ context: { invalid: comparison.invalid },
31241
+ result: { error: INVALID_TIE_FORMAT },
31242
+ stack
31243
+ });
31244
+ }
31245
+ if (!comparison?.different) {
31246
+ return decorateResult({
31247
+ result: { ...SUCCESS },
31248
+ info: "Nothing to do",
31249
+ stack
31250
+ });
31197
31251
  }
31198
31252
  const existingCollectionIds = tieFormat.collectionDefinitions.map(
31199
31253
  ({ collectionId }) => collectionId
@@ -31207,13 +31261,18 @@ function modifyTieFormat$1({
31207
31261
  const addedCollectionDefinitions = modifiedTieFormat.collectionDefinitions.filter(
31208
31262
  ({ collectionId }) => !existingCollectionIds.includes(collectionId)
31209
31263
  );
31264
+ const addedCollectionIds = addedCollectionDefinitions.map(extractAttributes("collectionId"));
31210
31265
  const modifications = [];
31211
31266
  let processedTieFormat;
31267
+ const tieFormatName = modifiedTieFormat.tieFormatName;
31212
31268
  for (const collectionDefinition of modifiedTieFormat.collectionDefinitions) {
31269
+ if (addedCollectionIds.includes(collectionDefinition.collectionId))
31270
+ continue;
31213
31271
  const result2 = modifyCollectionDefinition$1({
31214
31272
  updateInProgressMatchUps,
31215
31273
  ...collectionDefinition,
31216
31274
  tournamentRecord,
31275
+ tieFormatName,
31217
31276
  drawDefinition,
31218
31277
  structureId,
31219
31278
  matchUpId,
@@ -31227,7 +31286,6 @@ function modifyTieFormat$1({
31227
31286
  if (result2.tieFormat)
31228
31287
  processedTieFormat = result2.tieFormat;
31229
31288
  }
31230
- const tieFormatName = modifiedTieFormat.tieFormatName;
31231
31289
  for (const collectionDefinition of addedCollectionDefinitions) {
31232
31290
  const result2 = addCollectionDefinition$1({
31233
31291
  updateInProgressMatchUps,
@@ -31270,7 +31328,7 @@ function modifyTieFormat$1({
31270
31328
  if (changedTieFormatName) {
31271
31329
  processedTieFormat.tieFormatName = tieFormatName;
31272
31330
  modifications.push({ tieFormatName });
31273
- } else if (modifications.length) {
31331
+ } else if (modifications.length || addedCollectionIds.length || removedCollectionIds.length) {
31274
31332
  delete processedTieFormat.tieFormatName;
31275
31333
  modifications.push(
31276
31334
  "tieFormatName removed: modifications without new tieFormatName"
@@ -31279,13 +31337,85 @@ function modifyTieFormat$1({
31279
31337
  processedTieFormat.collectionDefinitions = processedTieFormat.collectionDefinitions.sort(
31280
31338
  (a, b) => numericSortValue(a.collectionOrder) - numericSortValue(b.collectionOrder)
31281
31339
  ).map((def, i) => ({ ...def, collectionOrder: i + 1 }));
31282
- return { ...SUCCESS, processedTieFormat, modifications };
31340
+ return {
31341
+ processedTieFormat: copyTieFormat(processedTieFormat),
31342
+ modifications,
31343
+ ...SUCCESS
31344
+ };
31283
31345
  }
31284
31346
 
31285
31347
  function modifyTieFormat(params) {
31286
31348
  return resolveTournamentRecord({ ...params, method: modifyTieFormat$1 });
31287
31349
  }
31288
31350
 
31351
+ function publicFindMatchUp(params) {
31352
+ Object.assign(params, { inContext: true });
31353
+ const { matchUp, error } = findMatchUp(params);
31354
+ return { matchUp: makeDeepCopy(matchUp, true, true), error };
31355
+ }
31356
+ function findMatchUp({
31357
+ participantsProfile,
31358
+ afterRecoveryTimes,
31359
+ tournamentRecord,
31360
+ contextContent,
31361
+ contextProfile,
31362
+ drawDefinition,
31363
+ matchUpId,
31364
+ inContext,
31365
+ eventId,
31366
+ drawId,
31367
+ event
31368
+ }) {
31369
+ if (!tournamentRecord)
31370
+ return { error: MISSING_TOURNAMENT_RECORD };
31371
+ if (typeof matchUpId !== "string")
31372
+ return { error: MISSING_MATCHUP_ID };
31373
+ if (!drawDefinition || !event) {
31374
+ const matchUps = allTournamentMatchUps({ tournamentRecord }).matchUps ?? [];
31375
+ const inContextMatchUp = matchUps.find(
31376
+ (matchUp2) => matchUp2.matchUpId === matchUpId
31377
+ );
31378
+ if (!inContextMatchUp)
31379
+ return { error: MATCHUP_NOT_FOUND };
31380
+ ({ eventId, drawId } = inContextMatchUp);
31381
+ ({ event, drawDefinition } = findEvent({
31382
+ tournamentRecord,
31383
+ eventId,
31384
+ drawId
31385
+ }));
31386
+ }
31387
+ if (!drawDefinition)
31388
+ return { error: DRAW_DEFINITION_NOT_FOUND };
31389
+ if (contextProfile && !contextContent)
31390
+ contextContent = getContextContent({ tournamentRecord, contextProfile });
31391
+ const additionalContext = {
31392
+ surfaceCategory: event?.surfaceCategory ?? tournamentRecord.surfaceCategory,
31393
+ indoorOutDoor: event?.indoorOutdoor ?? tournamentRecord.indoorOutdoor,
31394
+ endDate: event?.endDate ?? tournamentRecord.endDate,
31395
+ tournamentId: tournamentRecord.tournamentId,
31396
+ eventId: eventId ?? event?.eventId,
31397
+ drawId
31398
+ };
31399
+ const { participants: tournamentParticipants = [] } = hydrateParticipants({
31400
+ participantsProfile,
31401
+ tournamentRecord,
31402
+ contextProfile,
31403
+ inContext
31404
+ });
31405
+ const { matchUp, structure } = findMatchUp$1({
31406
+ context: inContext ? additionalContext : void 0,
31407
+ tournamentParticipants,
31408
+ afterRecoveryTimes,
31409
+ contextContent,
31410
+ drawDefinition,
31411
+ contextProfile,
31412
+ matchUpId,
31413
+ inContext,
31414
+ event
31415
+ });
31416
+ return { matchUp, structure, drawDefinition };
31417
+ }
31418
+
31289
31419
  function resetTieFormat$1({
31290
31420
  tournamentRecord,
31291
31421
  drawDefinition,
@@ -42689,11 +42819,7 @@ function positionByes({
42689
42819
  }
42690
42820
 
42691
42821
  function positionQualifiers(params) {
42692
- let { structure, structureId } = params;
42693
- if (!structure)
42694
- ({ structure } = findStructure(params));
42695
- if (!structureId)
42696
- ({ structureId } = structure);
42822
+ const structure = params.structure ?? findStructure(params).structure;
42697
42823
  const stack = "positionQualifiers";
42698
42824
  const qualifierDrawPositions = [];
42699
42825
  if (structure.stage === CONSOLATION) {
@@ -43337,7 +43463,7 @@ function generateAndPopulatePlayoffStructures(params) {
43337
43463
  drawDefinition
43338
43464
  });
43339
43465
  if (!structure)
43340
- return decorateResult({ result: { error: STRUCTURE_NOT_FOUND } });
43466
+ return decorateResult({ result: { error: STRUCTURE_NOT_FOUND }, stack });
43341
43467
  if (structure.structureType === CONTAINER || structure.structures) {
43342
43468
  return generateAndPopulateRRplayoffStructures({
43343
43469
  sourceStructureId: structure.structureId,
@@ -44151,11 +44277,11 @@ function attachStructures$1({
44151
44277
  links = [],
44152
44278
  event
44153
44279
  }) {
44280
+ const stack = "attachStructures";
44154
44281
  if (!drawDefinition)
44155
44282
  return { error: MISSING_DRAW_DEFINITION };
44156
44283
  if (!Array.isArray(structures) || !Array.isArray(links))
44157
- return decorateResult({ result: { error: INVALID_VALUES } });
44158
- const stack = "attachStructures";
44284
+ return decorateResult({ result: { error: INVALID_VALUES }, stack });
44159
44285
  const linkHash = (link) => [
44160
44286
  link.source.structureId,
44161
44287
  link.source.roundNumber || link.source.finishingPositions?.join("|"),
@@ -45058,7 +45184,9 @@ function positionParticipantAction(params) {
45058
45184
  };
45059
45185
  addPositionActionTelemetry({ drawDefinition, positionAction });
45060
45186
  return decorateResult({
45061
- result: { ...SUCCESS, context: { removedParticipantId: removedParticipantId2 }, stack }
45187
+ context: { removedParticipantId: removedParticipantId2 },
45188
+ result: { ...SUCCESS },
45189
+ stack
45062
45190
  });
45063
45191
  }
45064
45192
  }
@@ -45826,8 +45954,8 @@ function addEventEntries(params) {
45826
45954
  const removedEntries = [];
45827
45955
  if (extensions && (!Array.isArray(extensions) || !extensions.every(isValidExtension)) || extension && !isValidExtension({ extension })) {
45828
45956
  return decorateResult({
45829
- result: { error: INVALID_VALUES },
45830
45957
  context: definedAttributes({ extension, extensions }),
45958
+ result: { error: INVALID_VALUES },
45831
45959
  info: "Invalid extension(s)",
45832
45960
  stack
45833
45961
  });
@@ -45932,8 +46060,8 @@ function addEventEntries(params) {
45932
46060
  const invalidParticipantIds = validParticipantIds.length !== participantIds.length;
45933
46061
  if (invalidParticipantIds)
45934
46062
  return decorateResult({
45935
- result: { error: INVALID_PARTICIPANT_IDS },
45936
46063
  context: { misMatchedGender, gender: event.gender },
46064
+ result: { error: INVALID_PARTICIPANT_IDS },
45937
46065
  stack
45938
46066
  });
45939
46067
  if (autoEntryPositions) {
@@ -46891,10 +47019,6 @@ function removeDelegatedOutcome$1({ drawDefinition, event, matchUpId }) {
46891
47019
  });
46892
47020
  }
46893
47021
 
46894
- function stringSort(a, b) {
46895
- return (a || "").localeCompare(b || "");
46896
- }
46897
-
46898
47022
  function generateCandidate({
46899
47023
  maxIterations = 4e3,
46900
47024
  // cap the processing intensity of the candidate generator
@@ -47492,19 +47616,17 @@ function setOrderOfFinish$1({
47492
47616
  const stack = "setOrderOfFinish";
47493
47617
  if (!Array.isArray(finishingOrder))
47494
47618
  return decorateResult({
47495
- result: {
47496
- error: INVALID_VALUES
47497
- },
47498
47619
  info: mustBeAnArray("finishingOrder"),
47620
+ result: { error: INVALID_VALUES },
47499
47621
  stack
47500
47622
  });
47501
47623
  const { completedMatchUps, matchUpsMap } = getDrawMatchUps({
47502
47624
  inContext: true,
47503
47625
  drawDefinition
47504
47626
  });
47505
- const matchUpIds = completedMatchUps?.map(getMatchUpId) || [];
47627
+ const matchUpIds = completedMatchUps?.map(getMatchUpId) ?? [];
47506
47628
  const targetMatchUpIds = finishingOrder.map(getMatchUpId);
47507
- const { matchUpTypes, roundNumbers, structureIds, matchUpTieIds } = (completedMatchUps || []).filter(({ matchUpId }) => targetMatchUpIds.includes(matchUpId)).reduce(
47629
+ const { matchUpTypes, roundNumbers, structureIds, matchUpTieIds } = (completedMatchUps ?? []).filter(({ matchUpId }) => targetMatchUpIds.includes(matchUpId)).reduce(
47508
47630
  (aggregator, matchUp) => {
47509
47631
  const { matchUpTieId, matchUpType, roundNumber, structureId } = matchUp;
47510
47632
  if (!aggregator.matchUpTypes.includes(matchUpType))
@@ -47526,10 +47648,8 @@ function setOrderOfFinish$1({
47526
47648
  );
47527
47649
  if (matchUpTypes.length > 1 || matchUpTieIds.length > 1 || roundNumbers.length > 1 || structureIds.length > 1) {
47528
47650
  return decorateResult({
47529
- result: {
47530
- error: INVALID_VALUES
47531
- },
47532
47651
  info: "matchUpType, structureId and roundNumber must be equivalent",
47652
+ result: { error: INVALID_VALUES },
47533
47653
  stack
47534
47654
  });
47535
47655
  }
@@ -47558,7 +47678,7 @@ function setOrderOfFinish$1({
47558
47678
  const otherCohortMatchUps = completedMatchUps?.filter(
47559
47679
  (matchUp) => matchUp.structureId === structureIds[0] && matchUp.roundNumber === roundNumbers[0] && matchUp.matchUpType === matchUpTypes[0] && matchUp.matchUpTieId === matchUpTieIds[0] && !targetedMatchUpIds.includes(matchUp.matchUpId)
47560
47680
  );
47561
- for (const matchUp of otherCohortMatchUps || []) {
47681
+ for (const matchUp of otherCohortMatchUps ?? []) {
47562
47682
  const { orderOfFinish } = matchUp || {};
47563
47683
  if (orderOfFinish) {
47564
47684
  if (!isConvertableInteger(orderOfFinish))
@@ -47572,10 +47692,8 @@ function setOrderOfFinish$1({
47572
47692
  }
47573
47693
  if (uniqueValues(orderOfFinishValues).length !== orderOfFinishValues.length || Math.max(...orderOfFinishValues) > orderOfFinishValues.length) {
47574
47694
  return decorateResult({
47575
- result: {
47576
- error: INVALID_VALUES
47577
- },
47578
47695
  info: "Values not unique or greater than expected number of values",
47696
+ result: { error: INVALID_VALUES },
47579
47697
  stack
47580
47698
  });
47581
47699
  }
@@ -50208,10 +50326,8 @@ function addIndividualParticipantIds({
50208
50326
  return decorateResult({ result: { error: PARTICIPANT_NOT_FOUND }, stack });
50209
50327
  if (groupingParticipant?.participantType && ![TEAM, GROUP].includes(groupingParticipant.participantType)) {
50210
50328
  return decorateResult({
50211
- result: {
50212
- error: INVALID_PARTICIPANT_TYPE
50213
- },
50214
50329
  context: { participantType: groupingParticipant.participantType },
50330
+ result: { error: INVALID_PARTICIPANT_TYPE },
50215
50331
  stack
50216
50332
  });
50217
50333
  }
@@ -52241,7 +52357,7 @@ function assignTieMatchUpParticipantId(params) {
52241
52357
  const tieMatchUpSide = inContextTieMatchUp?.sides?.find(
52242
52358
  (side) => side.sideNumber === sideNumber
52243
52359
  );
52244
- const lineUp = dualMatchUpSide?.lineUp || getTeamLineUp({
52360
+ const lineUp = dualMatchUpSide?.lineUp ?? getTeamLineUp({
52245
52361
  participantId: teamParticipantId,
52246
52362
  drawDefinition
52247
52363
  })?.lineUp;
@@ -54791,8 +54907,8 @@ function deleteDrawDefinitions({
54791
54907
  const auditTrail = [];
54792
54908
  if (!event?.drawDefinitions)
54793
54909
  return decorateResult({
54794
- result: { ...SUCCESS },
54795
54910
  info: "event has no drawDefinition",
54911
+ result: { ...SUCCESS },
54796
54912
  stack
54797
54913
  });
54798
54914
  const eventDrawIds = event.drawDefinitions.map(({ drawId: drawId2 }) => drawId2);
@@ -54801,8 +54917,8 @@ function deleteDrawDefinitions({
54801
54917
  drawIds = drawIds.filter((drawId2) => eventDrawIds.includes(drawId2));
54802
54918
  if (!drawIds.length)
54803
54919
  return decorateResult({
54804
- result: { ...SUCCESS },
54805
54920
  info: "nothing to do; no matching drawIds in event.",
54921
+ result: { ...SUCCESS },
54806
54922
  stack
54807
54923
  });
54808
54924
  const flightProfile = makeDeepCopy(
@@ -57656,6 +57772,7 @@ function addVoluntaryConsolationStructure(params) {
57656
57772
  }
57657
57773
 
57658
57774
  function prepareStage(params) {
57775
+ const stack = "prepareStage";
57659
57776
  let { seedsCount } = params;
57660
57777
  const preparedStructureIds = params.preparedStructureIds || [];
57661
57778
  const {
@@ -57711,7 +57828,7 @@ function prepareStage(params) {
57711
57828
  ({ structureId: structureId2 }) => !preparedStructureIds.includes(structureId2)
57712
57829
  );
57713
57830
  if (!structure)
57714
- return decorateResult({ result: { error: STRUCTURE_NOT_FOUND } });
57831
+ return decorateResult({ result: { error: STRUCTURE_NOT_FOUND }, stack });
57715
57832
  const structureId = structure?.structureId;
57716
57833
  const seedBlockInfo = structure ? getValidSeedBlocks({
57717
57834
  provisionalPositioning,
@@ -57834,7 +57951,7 @@ function prepareStage(params) {
57834
57951
  positionAssignments = result?.positionAssignments;
57835
57952
  positioningReport = result?.positioningReport;
57836
57953
  if (result.error) {
57837
- return decorateResult({ result, stack: "prepareStage" });
57954
+ return decorateResult({ result, stack });
57838
57955
  }
57839
57956
  }
57840
57957
  return {
@@ -57980,10 +58097,8 @@ function generateDrawDefinition(params) {
57980
58097
  if (policyDefinitions) {
57981
58098
  if (typeof policyDefinitions !== "object") {
57982
58099
  return decorateResult({
57983
- result: {
57984
- info: "policyDefinitions must be an object",
57985
- error: INVALID_VALUES
57986
- },
58100
+ info: "policyDefinitions must be an object",
58101
+ result: { error: INVALID_VALUES },
57987
58102
  stack
57988
58103
  });
57989
58104
  } else {
@@ -58212,8 +58327,9 @@ function generateDrawDefinition(params) {
58212
58327
  for (const roundTargetProfile of params.qualifyingProfiles) {
58213
58328
  if (!Array.isArray(roundTargetProfile.structureProfiles))
58214
58329
  return decorateResult({
58330
+ info: mustBeAnArray("structureProfiles"),
58215
58331
  result: { error: MISSING_VALUE },
58216
- info: mustBeAnArray("structureProfiles")
58332
+ stack
58217
58333
  });
58218
58334
  roundTarget = roundTargetProfile.roundTarget || roundTarget;
58219
58335
  const sortedStructureProfiles = roundTargetProfile.structureProfiles?.sort(sequenceSort) || [];
@@ -58444,12 +58560,12 @@ function modifyEvent({
58444
58560
  const enteredParticipantIds = event?.entries?.filter(({ entryStatus }) => {
58445
58561
  const status = entryStatus;
58446
58562
  return [...STRUCTURE_SELECTED_STATUSES, ALTERNATE].includes(status);
58447
- }).map(({ participantId }) => participantId) || [];
58563
+ }).map(({ participantId }) => participantId) ?? [];
58448
58564
  const enteredParticipants = enteredParticipantIds ? getParticipants$1({
58449
58565
  participantFilters: { participantIds: enteredParticipantIds },
58450
58566
  withIndividualParticipants: true,
58451
58567
  tournamentRecord
58452
- }).participants || [] : [];
58568
+ }).participants ?? [] : [];
58453
58569
  const genderAccumulator = [];
58454
58570
  const enteredParticipantTypes = enteredParticipants.reduce(
58455
58571
  (types, participant) => {
@@ -58460,7 +58576,7 @@ function modifyEvent({
58460
58576
  []
58461
58577
  );
58462
58578
  const enteredParticipantGenders = unique(genderAccumulator);
58463
- const validGender = !enteredParticipantGenders.length || [MIXED, ANY].includes(eventUpdates.gender || "") || enteredParticipantGenders.length === 1 && enteredParticipantGenders[0] === eventUpdates.gender;
58579
+ const validGender = !enteredParticipantGenders.length || [MIXED, ANY].includes(eventUpdates.gender ?? "") || enteredParticipantGenders.length === 1 && enteredParticipantGenders[0] === eventUpdates.gender;
58464
58580
  if (eventUpdates.gender && !validGender)
58465
58581
  return decorateResult({
58466
58582
  context: { gender: eventUpdates.gender },
@@ -58471,14 +58587,14 @@ function modifyEvent({
58471
58587
  SINGLES,
58472
58588
  TEAM$1
58473
58589
  ];
58474
- const validEventType = validEventTypes.includes(eventUpdates.eventType || "");
58590
+ const validEventType = validEventTypes.includes(eventUpdates.eventType ?? "");
58475
58591
  if (eventUpdates.eventType && !validEventType)
58476
58592
  return decorateResult({
58477
58593
  context: { participantType: eventUpdates.eventType },
58478
58594
  result: { error: INVALID_VALUES }
58479
58595
  });
58480
58596
  if (eventUpdates.eventType)
58481
- event.eventType === eventUpdates.eventType;
58597
+ event.eventType = eventUpdates.eventType;
58482
58598
  if (eventUpdates.eventName)
58483
58599
  event.eventName = eventUpdates.eventName;
58484
58600
  if (eventUpdates.gender)
@@ -59052,6 +59168,78 @@ function getParticipantSignInStatus({
59052
59168
  return timeItem && timeItem.itemValue === SIGNED_IN && SIGNED_IN;
59053
59169
  }
59054
59170
 
59171
+ function getTieFormat({
59172
+ tournamentRecord,
59173
+ // passed in automatically by tournamentEngine
59174
+ drawDefinition,
59175
+ // passed in automatically by tournamentEngine when drawId provided
59176
+ structureId,
59177
+ // optional - if only the default matchUpFormat for a structure is required
59178
+ matchUpId,
59179
+ // id of matchUp for which the scoped matchUpFormat(s) are desired
59180
+ structure,
59181
+ // optional optimization - when structure already known
59182
+ eventId,
59183
+ // optional - if only the default matchUpFormat for an event is required
59184
+ drawId,
59185
+ // avoid brute force search for matchUp
59186
+ event
59187
+ // passed in automatically by tournamentEngine when drawId or eventId provided
59188
+ }) {
59189
+ if (!tournamentRecord)
59190
+ return { error: MISSING_TOURNAMENT_RECORD };
59191
+ if (!drawId && !event && !structureId && !matchUpId)
59192
+ return decorateResult({
59193
+ result: { error: MISSING_VALUE },
59194
+ stack: "getTieFormat"
59195
+ });
59196
+ if (eventId && !event) {
59197
+ event = tournamentRecord.events?.find((event2) => event2.eventId === eventId);
59198
+ }
59199
+ const matchUpResult = publicFindMatchUp({
59200
+ tournamentRecord,
59201
+ drawDefinition,
59202
+ matchUpId,
59203
+ drawId,
59204
+ event
59205
+ });
59206
+ if (matchUpId && matchUpResult?.error) {
59207
+ return matchUpResult;
59208
+ } else if (!drawDefinition && matchUpResult?.drawDefinition) {
59209
+ drawDefinition = matchUpResult?.drawDefinition;
59210
+ }
59211
+ structure = structure ?? matchUpResult?.structure;
59212
+ if (!structure && structureId && !matchUpId) {
59213
+ if (!drawDefinition)
59214
+ return { error: MISSING_DRAW_ID };
59215
+ const structureResult = findStructure({ drawDefinition, structureId });
59216
+ if (structureResult.error)
59217
+ return structureResult;
59218
+ structure = structureResult.structure;
59219
+ }
59220
+ const structureDefaultTieFormat = (structure?.tieFormat || structure?.tieFormatId) && resolveTieFormat({ structure, drawDefinition, event })?.tieFormat;
59221
+ const drawDefaultTieFormat = (drawDefinition?.tieFormat || drawDefinition?.tieFormatId) && resolveTieFormat({
59222
+ drawDefinition,
59223
+ event
59224
+ })?.tieFormat;
59225
+ const eventDefaultTieFormat = resolveTieFormat({ event })?.tieFormat;
59226
+ const tieFormat = resolveTieFormat({
59227
+ matchUp: matchUpResult?.matchUp,
59228
+ drawDefinition,
59229
+ structure,
59230
+ event
59231
+ })?.tieFormat;
59232
+ return {
59233
+ ...SUCCESS,
59234
+ matchUp: matchUpResult?.matchUp,
59235
+ structureDefaultTieFormat: copyTieFormat(structureDefaultTieFormat),
59236
+ eventDefaultTieFormat: copyTieFormat(eventDefaultTieFormat),
59237
+ drawDefaultTieFormat: copyTieFormat(drawDefaultTieFormat),
59238
+ tieFormat: copyTieFormat(tieFormat),
59239
+ structure
59240
+ };
59241
+ }
59242
+
59055
59243
  function getEventProperties({ tournamentRecord, event }) {
59056
59244
  if (!tournamentRecord)
59057
59245
  return { error: MISSING_TOURNAMENT_RECORD };