tods-competition-factory 1.8.17 → 1.8.19

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
@@ -2382,7 +2382,7 @@ const matchUpFormatCode = {
2382
2382
  };
2383
2383
 
2384
2384
  function factoryVersion() {
2385
- return "1.8.17";
2385
+ return "1.8.19";
2386
2386
  }
2387
2387
 
2388
2388
  function getObjectTieFormat(obj) {
@@ -2616,28 +2616,76 @@ function getCategoryAgeDetails(params) {
2616
2616
  return result;
2617
2617
  }
2618
2618
 
2619
+ function decorateResult({
2620
+ context,
2621
+ result,
2622
+ stack,
2623
+ info
2624
+ }) {
2625
+ if (result && !Array.isArray(result?.stack))
2626
+ result.stack = [];
2627
+ if (result && Array.isArray(result?.stack) && typeof stack === "string") {
2628
+ result.stack.push(stack);
2629
+ }
2630
+ if (result && info) {
2631
+ result.info = info;
2632
+ }
2633
+ if (result && typeof context === "object" && Object.keys(context).length) {
2634
+ Object.assign(result, definedAttributes(context));
2635
+ }
2636
+ if (result && !result?.error && !result?.success) {
2637
+ Object.assign(result, { ...SUCCESS });
2638
+ }
2639
+ return result ?? { success: true };
2640
+ }
2641
+
2642
+ function validateCategory({ category }) {
2643
+ if (!isObject(category))
2644
+ return { error: INVALID_VALUES };
2645
+ const categoryDetails = getCategoryAgeDetails({ category });
2646
+ if (categoryDetails.error)
2647
+ return { error: categoryDetails };
2648
+ const { ratingMax, ratingMin } = category;
2649
+ if (ratingMax && !isNumeric(ratingMax))
2650
+ return decorateResult({
2651
+ result: { error: INVALID_VALUES },
2652
+ context: { ratingMax }
2653
+ });
2654
+ if (ratingMin && !isNumeric(ratingMin))
2655
+ return decorateResult({
2656
+ result: { error: INVALID_VALUES },
2657
+ context: { ratingMin }
2658
+ });
2659
+ return { ...categoryDetails };
2660
+ }
2661
+
2619
2662
  function categoryCanContain({
2620
2663
  childCategory,
2621
2664
  withDetails,
2622
2665
  category
2623
2666
  }) {
2624
- const categoryDetails = getCategoryAgeDetails({ category });
2625
- const childCategoryDetails = getCategoryAgeDetails({
2667
+ const categoryDetails = validateCategory({ category });
2668
+ const childCategoryDetails = validateCategory({
2626
2669
  category: childCategory
2627
2670
  });
2628
2671
  const invalidAgeMin = childCategoryDetails.ageMin && (categoryDetails.ageMin && childCategoryDetails.ageMin < categoryDetails.ageMin || categoryDetails.ageMax && childCategoryDetails.ageMin > categoryDetails.ageMax);
2629
2672
  const invalidAgeMax = childCategoryDetails.ageMax && (categoryDetails.ageMax && childCategoryDetails.ageMax > categoryDetails.ageMax || categoryDetails.ageMin && childCategoryDetails.ageMax < categoryDetails.ageMin);
2630
2673
  const invalidAgeMinDate = childCategoryDetails.ageMinDate && categoryDetails.ageMaxDate && new Date(childCategoryDetails.ageMinDate) > new Date(categoryDetails.ageMaxDate);
2631
2674
  const invalidAgeMaxDate = childCategoryDetails.ageMaxDate && categoryDetails.ageMinDate && new Date(childCategoryDetails.ageMaxDate) < new Date(categoryDetails.ageMinDate);
2632
- const valid = !invalidAgeMax && !invalidAgeMin && !invalidAgeMinDate && !invalidAgeMaxDate;
2675
+ const ratingComparison = category.ratingType && childCategory.ratingType && category.ratingType === childCategory.ratingType;
2676
+ const invalidRatingRange = ratingComparison && (category.ratingMin && childCategory.ratingMin && childCategory.ratingMin < category.ratingMin || category.ratingMax && childCategory.ratingMax && childCategory.ratingMax > category.ratingMax || category.ratingMin && childCategory.ratingMax && childCategory.ratingMax < category.ratingMin || category.ratingMax && childCategory.ratingMin && childCategory.ratingMin > category.ratingMax);
2677
+ const invalidBallType = category.ballType && childCategory.ballType && category.ballType !== childCategory.ballType;
2678
+ const valid = !invalidRatingRange && !invalidAgeMinDate && !invalidAgeMaxDate && !invalidBallType && !invalidAgeMax && !invalidAgeMin;
2633
2679
  const ignoreFalse = true;
2634
2680
  const result = definedAttributes(
2635
2681
  {
2636
- valid,
2682
+ invalidRatingRange,
2683
+ invalidAgeMinDate,
2684
+ invalidAgeMaxDate,
2685
+ invalidBallType,
2637
2686
  invalidAgeMax,
2638
2687
  invalidAgeMin,
2639
- invalidAgeMinDate,
2640
- invalidAgeMaxDate
2688
+ valid
2641
2689
  },
2642
2690
  ignoreFalse
2643
2691
  );
@@ -2651,29 +2699,6 @@ function mustBeAnArray(value) {
2651
2699
  return `${value} must be an array`;
2652
2700
  }
2653
2701
 
2654
- function decorateResult({
2655
- context,
2656
- result,
2657
- stack,
2658
- info
2659
- }) {
2660
- if (result && !Array.isArray(result?.stack))
2661
- result.stack = [];
2662
- if (result && Array.isArray(result?.stack) && typeof stack === "string") {
2663
- result.stack.push(stack);
2664
- }
2665
- if (result && info) {
2666
- result.info = info;
2667
- }
2668
- if (result && typeof context === "object" && Object.keys(context).length) {
2669
- Object.assign(result, definedAttributes(context));
2670
- }
2671
- if (result && !result?.error && !result?.success) {
2672
- Object.assign(result, { ...SUCCESS });
2673
- }
2674
- return result ?? { success: true };
2675
- }
2676
-
2677
2702
  var DrawTypeEnum = /* @__PURE__ */ ((DrawTypeEnum2) => {
2678
2703
  DrawTypeEnum2["AdHoc"] = "AD_HOC";
2679
2704
  DrawTypeEnum2["Compass"] = "COMPASS";
@@ -4206,142 +4231,6 @@ function tallyParticipantResults({
4206
4231
  return result;
4207
4232
  }
4208
4233
 
4209
- function evaluateCollectionResult({
4210
- collectionDefinition,
4211
- groupValueNumbers,
4212
- groupValueGroups,
4213
- sideTieValues,
4214
- tieMatchUps
4215
- }) {
4216
- const collectionMatchUps = tieMatchUps.filter(
4217
- (matchUp) => matchUp.collectionId === collectionDefinition.collectionId
4218
- );
4219
- const sideMatchUpValues = [0, 0];
4220
- let sideCollectionValues = [0, 0];
4221
- const allCollectionMatchUpsCompleted = collectionMatchUps.every(
4222
- (matchUp) => completedMatchUpStatuses.includes(matchUp.matchUpStatus)
4223
- );
4224
- const {
4225
- collectionValueProfiles,
4226
- collectionGroupNumber,
4227
- collectionValue,
4228
- matchUpValue,
4229
- winCriteria,
4230
- scoreValue,
4231
- setValue
4232
- } = collectionDefinition;
4233
- const belongsToValueGroup = collectionGroupNumber && groupValueNumbers.includes(collectionGroupNumber);
4234
- const sideWins = [0, 0];
4235
- collectionMatchUps.forEach((matchUp) => {
4236
- if (matchUp.winningSide)
4237
- sideWins[matchUp.winningSide - 1] += 1;
4238
- });
4239
- if (isConvertableInteger(matchUpValue)) {
4240
- collectionMatchUps.forEach((matchUp) => {
4241
- if (matchUp.winningSide) {
4242
- sideMatchUpValues[matchUp.winningSide - 1] += matchUpValue;
4243
- }
4244
- });
4245
- } else if (isConvertableInteger(setValue)) {
4246
- collectionMatchUps.forEach((matchUp) => {
4247
- matchUp.score?.sets?.forEach((set) => {
4248
- if (set.winningSide)
4249
- sideMatchUpValues[set.winningSide - 1] += setValue;
4250
- });
4251
- });
4252
- } else if (isConvertableInteger(scoreValue)) {
4253
- collectionMatchUps.forEach((matchUp) => {
4254
- matchUp.score?.sets?.forEach((set) => {
4255
- const {
4256
- side1TiebreakScore = 0,
4257
- side2TiebreakScore = 0,
4258
- side1Score = 0,
4259
- side2Score = 0
4260
- } = set;
4261
- if (matchUp.matchUpStatus === COMPLETED$1 || matchUp.winningSide || set.winningSide) {
4262
- if (side1Score || side2Score) {
4263
- sideMatchUpValues[0] += side1Score;
4264
- sideMatchUpValues[1] += side2Score;
4265
- } else if ((side1TiebreakScore || side2TiebreakScore) && set.winningSide) {
4266
- sideMatchUpValues[set.winningSide - 1] += 1;
4267
- }
4268
- }
4269
- });
4270
- });
4271
- } else if (Array.isArray(collectionValueProfiles)) {
4272
- collectionMatchUps.forEach((matchUp) => {
4273
- if (matchUp.winningSide) {
4274
- const collectionPosition = matchUp.collectionPosition;
4275
- const matchUpValue2 = getCollectionPositionValue({
4276
- collectionDefinition,
4277
- collectionPosition
4278
- });
4279
- if (isConvertableInteger(matchUpValue2)) {
4280
- sideMatchUpValues[matchUp.winningSide - 1] += matchUpValue2;
4281
- }
4282
- }
4283
- });
4284
- }
4285
- if (isConvertableInteger(collectionValue)) {
4286
- let collectionWinningSide;
4287
- if (winCriteria?.aggregateValue) {
4288
- if (allCollectionMatchUpsCompleted) {
4289
- if (isConvertableInteger(matchUpValue || setValue || scoreValue) && sideMatchUpValues[0] !== sideMatchUpValues[1]) {
4290
- collectionWinningSide = sideMatchUpValues[0] > sideMatchUpValues[1] ? 1 : 2;
4291
- } else if (sideWins[0] !== sideWins[1]) {
4292
- collectionWinningSide = sideWins[0] > sideWins[1] ? 1 : 2;
4293
- }
4294
- }
4295
- } else if (winCriteria?.valueGoal) {
4296
- collectionWinningSide = sideMatchUpValues.reduce(
4297
- (winningSide, side, i) => {
4298
- return side >= winCriteria.valueGoal ? i + 1 : winningSide;
4299
- },
4300
- 0
4301
- );
4302
- } else {
4303
- const winGoal = Math.floor(collectionDefinition.matchUpCount / 2) + 1;
4304
- collectionWinningSide = sideWins.reduce((winningSide, side, i) => {
4305
- return side >= winGoal ? i + 1 : winningSide;
4306
- }, 0);
4307
- }
4308
- if (collectionWinningSide) {
4309
- if (belongsToValueGroup) {
4310
- groupValueGroups[collectionGroupNumber].values[collectionWinningSide - 1] += collectionValue;
4311
- } else {
4312
- sideCollectionValues[collectionWinningSide - 1] += collectionValue;
4313
- }
4314
- }
4315
- } else {
4316
- if (belongsToValueGroup) {
4317
- groupValueGroups[collectionGroupNumber].values[0] += sideMatchUpValues[0] || 0;
4318
- groupValueGroups[collectionGroupNumber].values[1] += sideMatchUpValues[1] || 0;
4319
- } else {
4320
- sideCollectionValues = sideMatchUpValues;
4321
- }
4322
- }
4323
- if (!belongsToValueGroup) {
4324
- sideCollectionValues.forEach(
4325
- (sideCollectionValue, i) => sideTieValues[i] += sideCollectionValue || 0
4326
- );
4327
- } else {
4328
- groupValueGroups[collectionGroupNumber].sideWins[0] += sideWins[0] || 0;
4329
- groupValueGroups[collectionGroupNumber].sideWins[1] += sideWins[1] || 0;
4330
- groupValueGroups[collectionGroupNumber].allGroupMatchUpsCompleted = groupValueGroups[collectionGroupNumber].allGroupMatchUpsCompleted && allCollectionMatchUpsCompleted;
4331
- groupValueGroups[collectionGroupNumber].matchUpsCount += collectionMatchUps.length;
4332
- }
4333
- }
4334
- function getCollectionPositionValue({
4335
- collectionDefinition,
4336
- collectionPosition
4337
- }) {
4338
- const collectionValueProfiles = collectionDefinition.collectionValueProfiles || [];
4339
- const profile = collectionValueProfiles?.find(
4340
- (profile2) => profile2.collectionPosition === collectionPosition
4341
- );
4342
- return profile?.matchUpValue;
4343
- }
4344
-
4345
4234
  const APPLIED_POLICIES = "appliedPolicies";
4346
4235
  const AUDIT_POSITION_ACTIONS = "positionActions";
4347
4236
  const CONTEXT = "context";
@@ -8534,11 +8423,13 @@ function getAllStructureMatchUps({
8534
8423
  }
8535
8424
  }
8536
8425
 
8537
- function publicFindMatchUp$1(params) {
8426
+ function publicFindDrawMatchUp(params) {
8538
8427
  Object.assign(params, { inContext: true });
8539
- return { matchUp: makeDeepCopy(findMatchUp$1(params).matchUp, false, true) };
8428
+ return {
8429
+ matchUp: makeDeepCopy(findDrawMatchUp(params).matchUp, false, true)
8430
+ };
8540
8431
  }
8541
- function findMatchUp$1({
8432
+ function findDrawMatchUp({
8542
8433
  tournamentParticipants,
8543
8434
  afterRecoveryTimes,
8544
8435
  contextContent,
@@ -8579,6 +8470,142 @@ function findMatchUp$1({
8579
8470
  return { error: MATCHUP_NOT_FOUND };
8580
8471
  }
8581
8472
 
8473
+ function evaluateCollectionResult({
8474
+ collectionDefinition,
8475
+ groupValueNumbers,
8476
+ groupValueGroups,
8477
+ sideTieValues,
8478
+ tieMatchUps
8479
+ }) {
8480
+ const collectionMatchUps = tieMatchUps.filter(
8481
+ (matchUp) => matchUp.collectionId === collectionDefinition.collectionId
8482
+ );
8483
+ const sideMatchUpValues = [0, 0];
8484
+ let sideCollectionValues = [0, 0];
8485
+ const allCollectionMatchUpsCompleted = collectionMatchUps.every(
8486
+ (matchUp) => completedMatchUpStatuses.includes(matchUp.matchUpStatus)
8487
+ );
8488
+ const {
8489
+ collectionValueProfiles,
8490
+ collectionGroupNumber,
8491
+ collectionValue,
8492
+ matchUpValue,
8493
+ winCriteria,
8494
+ scoreValue,
8495
+ setValue
8496
+ } = collectionDefinition;
8497
+ const belongsToValueGroup = collectionGroupNumber && groupValueNumbers.includes(collectionGroupNumber);
8498
+ const sideWins = [0, 0];
8499
+ collectionMatchUps.forEach((matchUp) => {
8500
+ if (matchUp.winningSide)
8501
+ sideWins[matchUp.winningSide - 1] += 1;
8502
+ });
8503
+ if (isConvertableInteger(matchUpValue)) {
8504
+ collectionMatchUps.forEach((matchUp) => {
8505
+ if (matchUp.winningSide) {
8506
+ sideMatchUpValues[matchUp.winningSide - 1] += matchUpValue;
8507
+ }
8508
+ });
8509
+ } else if (isConvertableInteger(setValue)) {
8510
+ collectionMatchUps.forEach((matchUp) => {
8511
+ matchUp.score?.sets?.forEach((set) => {
8512
+ if (set.winningSide)
8513
+ sideMatchUpValues[set.winningSide - 1] += setValue;
8514
+ });
8515
+ });
8516
+ } else if (isConvertableInteger(scoreValue)) {
8517
+ collectionMatchUps.forEach((matchUp) => {
8518
+ matchUp.score?.sets?.forEach((set) => {
8519
+ const {
8520
+ side1TiebreakScore = 0,
8521
+ side2TiebreakScore = 0,
8522
+ side1Score = 0,
8523
+ side2Score = 0
8524
+ } = set;
8525
+ if (matchUp.matchUpStatus === COMPLETED$1 || matchUp.winningSide || set.winningSide) {
8526
+ if (side1Score || side2Score) {
8527
+ sideMatchUpValues[0] += side1Score;
8528
+ sideMatchUpValues[1] += side2Score;
8529
+ } else if ((side1TiebreakScore || side2TiebreakScore) && set.winningSide) {
8530
+ sideMatchUpValues[set.winningSide - 1] += 1;
8531
+ }
8532
+ }
8533
+ });
8534
+ });
8535
+ } else if (Array.isArray(collectionValueProfiles)) {
8536
+ collectionMatchUps.forEach((matchUp) => {
8537
+ if (matchUp.winningSide) {
8538
+ const collectionPosition = matchUp.collectionPosition;
8539
+ const matchUpValue2 = getCollectionPositionValue({
8540
+ collectionDefinition,
8541
+ collectionPosition
8542
+ });
8543
+ if (isConvertableInteger(matchUpValue2)) {
8544
+ sideMatchUpValues[matchUp.winningSide - 1] += matchUpValue2;
8545
+ }
8546
+ }
8547
+ });
8548
+ }
8549
+ if (isConvertableInteger(collectionValue)) {
8550
+ let collectionWinningSide;
8551
+ if (winCriteria?.aggregateValue) {
8552
+ if (allCollectionMatchUpsCompleted) {
8553
+ if (isConvertableInteger(matchUpValue || setValue || scoreValue) && sideMatchUpValues[0] !== sideMatchUpValues[1]) {
8554
+ collectionWinningSide = sideMatchUpValues[0] > sideMatchUpValues[1] ? 1 : 2;
8555
+ } else if (sideWins[0] !== sideWins[1]) {
8556
+ collectionWinningSide = sideWins[0] > sideWins[1] ? 1 : 2;
8557
+ }
8558
+ }
8559
+ } else if (winCriteria?.valueGoal) {
8560
+ collectionWinningSide = sideMatchUpValues.reduce(
8561
+ (winningSide, side, i) => {
8562
+ return side >= winCriteria.valueGoal ? i + 1 : winningSide;
8563
+ },
8564
+ 0
8565
+ );
8566
+ } else {
8567
+ const winGoal = Math.floor(collectionDefinition.matchUpCount / 2) + 1;
8568
+ collectionWinningSide = sideWins.reduce((winningSide, side, i) => {
8569
+ return side >= winGoal ? i + 1 : winningSide;
8570
+ }, 0);
8571
+ }
8572
+ if (collectionWinningSide) {
8573
+ if (belongsToValueGroup) {
8574
+ groupValueGroups[collectionGroupNumber].values[collectionWinningSide - 1] += collectionValue;
8575
+ } else {
8576
+ sideCollectionValues[collectionWinningSide - 1] += collectionValue;
8577
+ }
8578
+ }
8579
+ } else {
8580
+ if (belongsToValueGroup) {
8581
+ groupValueGroups[collectionGroupNumber].values[0] += sideMatchUpValues[0] || 0;
8582
+ groupValueGroups[collectionGroupNumber].values[1] += sideMatchUpValues[1] || 0;
8583
+ } else {
8584
+ sideCollectionValues = sideMatchUpValues;
8585
+ }
8586
+ }
8587
+ if (!belongsToValueGroup) {
8588
+ sideCollectionValues.forEach(
8589
+ (sideCollectionValue, i) => sideTieValues[i] += sideCollectionValue || 0
8590
+ );
8591
+ } else {
8592
+ groupValueGroups[collectionGroupNumber].sideWins[0] += sideWins[0] || 0;
8593
+ groupValueGroups[collectionGroupNumber].sideWins[1] += sideWins[1] || 0;
8594
+ groupValueGroups[collectionGroupNumber].allGroupMatchUpsCompleted = groupValueGroups[collectionGroupNumber].allGroupMatchUpsCompleted && allCollectionMatchUpsCompleted;
8595
+ groupValueGroups[collectionGroupNumber].matchUpsCount += collectionMatchUps.length;
8596
+ }
8597
+ }
8598
+ function getCollectionPositionValue({
8599
+ collectionDefinition,
8600
+ collectionPosition
8601
+ }) {
8602
+ const collectionValueProfiles = collectionDefinition.collectionValueProfiles || [];
8603
+ const profile = collectionValueProfiles?.find(
8604
+ (profile2) => profile2.collectionPosition === collectionPosition
8605
+ );
8606
+ return profile?.matchUpValue;
8607
+ }
8608
+
8582
8609
  function getGroupValueGroups({
8583
8610
  collectionGroups = []
8584
8611
  }) {
@@ -8692,7 +8719,7 @@ function generateTieMatchUpScore(params) {
8692
8719
  }
8693
8720
  if (!winningSide && tallyDirectives) {
8694
8721
  const matchUpId = matchUp.matchUpId;
8695
- const inContextMatchUp = matchUp.hasContext ? matchUp : matchUpsMap?.drawMatchUps?.[matchUpId] || drawDefinition && findMatchUp$1({
8722
+ const inContextMatchUp = matchUp.hasContext ? matchUp : matchUpsMap?.drawMatchUps?.[matchUpId] || drawDefinition && findDrawMatchUp({
8696
8723
  inContext: true,
8697
8724
  drawDefinition,
8698
8725
  matchUpId
@@ -8720,79 +8747,6 @@ function generateTieMatchUpScore(params) {
8720
8747
  };
8721
8748
  }
8722
8749
 
8723
- function copyTieFormat(tieFormat) {
8724
- if (!tieFormat)
8725
- return void 0;
8726
- return makeDeepCopy(tieFormat, false, true);
8727
- }
8728
-
8729
- function scoreHasValue(params) {
8730
- const matchUp = params?.matchUp;
8731
- const score = params?.score || matchUp?.score;
8732
- const firstSet = score?.sets?.[0];
8733
- const {
8734
- side1Score,
8735
- side2Score,
8736
- side1TiebreakScore,
8737
- side2TiebreakScore,
8738
- side1PointScore,
8739
- side2PointScore
8740
- } = firstSet || {};
8741
- const firstSetScore = side1Score || side2Score || side1TiebreakScore || side2TiebreakScore || side1PointScore || side2PointScore;
8742
- const hasValue = score?.sets?.length > 1 || firstSetScore;
8743
- return !!hasValue;
8744
- }
8745
-
8746
- function isDirectingMatchUpStatus({ matchUpStatus }) {
8747
- return directingMatchUpStatuses.includes(matchUpStatus);
8748
- }
8749
- function isActiveMatchUpStatus({ matchUpStatus }) {
8750
- return activeMatchUpStatuses.includes(matchUpStatus);
8751
- }
8752
- function isNonDirectingMatchUpStatus({
8753
- matchUpStatus
8754
- }) {
8755
- return nonDirectingMatchUpStatuses.includes(matchUpStatus);
8756
- }
8757
-
8758
- function isActiveMatchUp({
8759
- matchUpStatus,
8760
- winningSide,
8761
- tieMatchUps,
8762
- sides,
8763
- score
8764
- }) {
8765
- const participantAssigned = sides?.find(({ participantId }) => participantId);
8766
- const activeTieMatchUps = tieMatchUps?.filter(isActiveMatchUp)?.length;
8767
- const scoreExists = scoreHasValue({ score });
8768
- return scoreExists || activeTieMatchUps || winningSide && participantAssigned || // if winningSide and no participant assigned => "produced" WALKOVER
8769
- // must exclude IN_PROGRESS as this is automatically set by updateTieMatchUpScore
8770
- // must exclude WALKOVER and DEFAULTED as "produced" scenarios do not imply a winningSide
8771
- matchUpStatus && isActiveMatchUpStatus({ matchUpStatus }) && ![DEFAULTED, WALKOVER$2, IN_PROGRESS$1].includes(matchUpStatus);
8772
- }
8773
-
8774
- function addNotes(params) {
8775
- if (typeof params !== "object")
8776
- return { error: MISSING_VALUE };
8777
- if (typeof params.element !== "object")
8778
- return { error: INVALID_VALUES };
8779
- if (!params.notes)
8780
- return { error: MISSING_VALUE };
8781
- if (typeof params.notes !== "string" && !params.notes?.testing)
8782
- return { error: INVALID_VALUES };
8783
- Object.assign(params.element, { notes: params.notes });
8784
- return { ...SUCCESS };
8785
- }
8786
- function removeNotes(params) {
8787
- if (typeof params !== "object")
8788
- return { error: MISSING_VALUE };
8789
- if (typeof params.element !== "object")
8790
- return { error: INVALID_VALUES };
8791
- if (params.element.notes)
8792
- delete params.element.notes;
8793
- return { ...SUCCESS };
8794
- }
8795
-
8796
8750
  function drawUpdatedAt(drawDefinition, structureIds) {
8797
8751
  if (!drawDefinition)
8798
8752
  return { error: MISSING_DRAW_DEFINITION };
@@ -8879,8 +8833,8 @@ function updateInContextMatchUp({ tournamentId, inContextMatchUp }) {
8879
8833
  return { error: MISSING_MATCHUP };
8880
8834
  }
8881
8835
  addNotice({
8882
- topic: UPDATE_INCONTEXT_MATCHUP,
8883
8836
  payload: { inContextMatchUp, tournamentId },
8837
+ topic: UPDATE_INCONTEXT_MATCHUP,
8884
8838
  key: inContextMatchUp.matchUpId
8885
8839
  });
8886
8840
  return { ...SUCCESS };
@@ -8992,6 +8946,121 @@ function modifyPositionAssignmentsNotice({
8992
8946
  return { ...SUCCESS };
8993
8947
  }
8994
8948
 
8949
+ function ensureSideLineUps({
8950
+ inContextDualMatchUp,
8951
+ drawDefinition,
8952
+ tournamentId,
8953
+ dualMatchUp,
8954
+ eventId
8955
+ }) {
8956
+ if (dualMatchUp && !dualMatchUp?.sides?.length) {
8957
+ if (!inContextDualMatchUp) {
8958
+ inContextDualMatchUp = findDrawMatchUp({
8959
+ matchUpId: dualMatchUp.matchUpId,
8960
+ inContext: true,
8961
+ drawDefinition
8962
+ })?.matchUp;
8963
+ }
8964
+ const { extension } = findExtension$2({
8965
+ element: drawDefinition,
8966
+ name: LINEUPS
8967
+ });
8968
+ const lineUps = makeDeepCopy(extension?.value || {}, false, true);
8969
+ const extractSideDetail = ({
8970
+ displaySideNumber,
8971
+ drawPosition,
8972
+ sideNumber
8973
+ }) => ({ drawPosition, sideNumber, displaySideNumber });
8974
+ dualMatchUp.sides = inContextDualMatchUp?.sides?.map((side) => {
8975
+ const participantId = side.participantId;
8976
+ return {
8977
+ ...extractSideDetail(side),
8978
+ lineUp: participantId && lineUps[participantId] || []
8979
+ };
8980
+ });
8981
+ modifyMatchUpNotice({
8982
+ context: "ensureSidLineUps",
8983
+ matchUp: dualMatchUp,
8984
+ drawDefinition,
8985
+ tournamentId,
8986
+ eventId
8987
+ });
8988
+ }
8989
+ }
8990
+
8991
+ function copyTieFormat(tieFormat) {
8992
+ if (!tieFormat)
8993
+ return void 0;
8994
+ return makeDeepCopy(tieFormat, false, true);
8995
+ }
8996
+
8997
+ function scoreHasValue(params) {
8998
+ const matchUp = params?.matchUp;
8999
+ const score = params?.score || matchUp?.score;
9000
+ const firstSet = score?.sets?.[0];
9001
+ const {
9002
+ side1Score,
9003
+ side2Score,
9004
+ side1TiebreakScore,
9005
+ side2TiebreakScore,
9006
+ side1PointScore,
9007
+ side2PointScore
9008
+ } = firstSet || {};
9009
+ const firstSetScore = side1Score || side2Score || side1TiebreakScore || side2TiebreakScore || side1PointScore || side2PointScore;
9010
+ const hasValue = score?.sets?.length > 1 || firstSetScore;
9011
+ return !!hasValue;
9012
+ }
9013
+
9014
+ function isDirectingMatchUpStatus({ matchUpStatus }) {
9015
+ return directingMatchUpStatuses.includes(matchUpStatus);
9016
+ }
9017
+ function isActiveMatchUpStatus({ matchUpStatus }) {
9018
+ return activeMatchUpStatuses.includes(matchUpStatus);
9019
+ }
9020
+ function isNonDirectingMatchUpStatus({
9021
+ matchUpStatus
9022
+ }) {
9023
+ return nonDirectingMatchUpStatuses.includes(matchUpStatus);
9024
+ }
9025
+
9026
+ function isActiveMatchUp({
9027
+ matchUpStatus,
9028
+ winningSide,
9029
+ tieMatchUps,
9030
+ sides,
9031
+ score
9032
+ }) {
9033
+ const participantAssigned = sides?.find(({ participantId }) => participantId);
9034
+ const activeTieMatchUps = tieMatchUps?.filter(isActiveMatchUp)?.length;
9035
+ const scoreExists = scoreHasValue({ score });
9036
+ return scoreExists || activeTieMatchUps || winningSide && participantAssigned || // if winningSide and no participant assigned => "produced" WALKOVER
9037
+ // must exclude IN_PROGRESS as this is automatically set by updateTieMatchUpScore
9038
+ // must exclude WALKOVER and DEFAULTED as "produced" scenarios do not imply a winningSide
9039
+ matchUpStatus && isActiveMatchUpStatus({ matchUpStatus }) && ![DEFAULTED, WALKOVER$2, IN_PROGRESS$1].includes(matchUpStatus);
9040
+ }
9041
+
9042
+ function addNotes(params) {
9043
+ if (typeof params !== "object")
9044
+ return { error: MISSING_VALUE };
9045
+ if (typeof params.element !== "object")
9046
+ return { error: INVALID_VALUES };
9047
+ if (!params.notes)
9048
+ return { error: MISSING_VALUE };
9049
+ if (typeof params.notes !== "string" && !params.notes?.testing)
9050
+ return { error: INVALID_VALUES };
9051
+ Object.assign(params.element, { notes: params.notes });
9052
+ return { ...SUCCESS };
9053
+ }
9054
+ function removeNotes(params) {
9055
+ if (typeof params !== "object")
9056
+ return { error: MISSING_VALUE };
9057
+ if (typeof params.element !== "object")
9058
+ return { error: INVALID_VALUES };
9059
+ if (params.element.notes)
9060
+ delete params.element.notes;
9061
+ return { ...SUCCESS };
9062
+ }
9063
+
8995
9064
  const hasParticipantId = (o) => o?.participantId;
8996
9065
 
8997
9066
  function createSubOrderMap({ positionAssignments }) {
@@ -9975,7 +10044,7 @@ function modifyMatchUpScore({
9975
10044
  const isDualMatchUp = matchUp.matchUpType === TEAM$2;
9976
10045
  if (isDualMatchUp && drawDefinition) {
9977
10046
  if (matchUpId && matchUp.matchUpId !== matchUpId) {
9978
- const findResult = findMatchUp$1({
10047
+ const findResult = findDrawMatchUp({
9979
10048
  drawDefinition,
9980
10049
  matchUpId,
9981
10050
  event
@@ -10004,7 +10073,7 @@ function modifyMatchUpScore({
10004
10073
  if (removeWinningSide)
10005
10074
  matchUp.winningSide = void 0;
10006
10075
  if (!structure && drawDefinition) {
10007
- ({ structure } = findMatchUp$1({
10076
+ ({ structure } = findDrawMatchUp({
10008
10077
  drawDefinition,
10009
10078
  matchUpId,
10010
10079
  event
@@ -10120,7 +10189,7 @@ function updateTieMatchUpScore$1({
10120
10189
  matchUpId,
10121
10190
  event
10122
10191
  }) {
10123
- const result = findMatchUp$1({ drawDefinition, event, matchUpId });
10192
+ const result = findDrawMatchUp({ drawDefinition, event, matchUpId });
10124
10193
  if (result.error)
10125
10194
  return result;
10126
10195
  if (!result.matchUp)
@@ -10128,6 +10197,12 @@ function updateTieMatchUpScore$1({
10128
10197
  const { matchUp, structure } = result;
10129
10198
  if (!matchUp.tieMatchUps)
10130
10199
  return { error: INVALID_MATCHUP };
10200
+ ensureSideLineUps({
10201
+ tournamentId: tournamentRecord?.tournamentId,
10202
+ eventId: event?.eventId,
10203
+ dualMatchUp: matchUp,
10204
+ drawDefinition
10205
+ });
10131
10206
  const { extension } = findExtension({
10132
10207
  name: DISABLE_AUTO_CALC,
10133
10208
  element: matchUp
@@ -15940,8 +16015,8 @@ function allTournamentMatchUps(params) {
15940
16015
  if (!participants) {
15941
16016
  ({ participants, participantMap } = hydrateParticipants({
15942
16017
  participantsProfile,
15943
- policyDefinitions,
15944
16018
  useParticipantMap,
16019
+ policyDefinitions,
15945
16020
  tournamentRecord,
15946
16021
  contextProfile,
15947
16022
  inContext
@@ -19625,7 +19700,7 @@ function addMatchUpTimeItem({
19625
19700
  timeItem,
19626
19701
  event
19627
19702
  }) {
19628
- const { matchUp } = findMatchUp$1({ drawDefinition, event, matchUpId });
19703
+ const { matchUp } = findDrawMatchUp({ drawDefinition, event, matchUpId });
19629
19704
  if (!matchUp)
19630
19705
  return { error: MATCHUP_NOT_FOUND };
19631
19706
  const result = addTimeItem({
@@ -19651,7 +19726,7 @@ function resetMatchUpTimeItems({
19651
19726
  matchUpId,
19652
19727
  event
19653
19728
  }) {
19654
- const { matchUp } = findMatchUp$1({ drawDefinition, event, matchUpId });
19729
+ const { matchUp } = findDrawMatchUp({ drawDefinition, event, matchUpId });
19655
19730
  if (!matchUp)
19656
19731
  return { error: MATCHUP_NOT_FOUND };
19657
19732
  matchUp.timeItems = [];
@@ -19679,7 +19754,7 @@ function allocateTeamMatchUpCourts$1({
19679
19754
  return { error: MISSING_TOURNAMENT_RECORD };
19680
19755
  if (!matchUpId)
19681
19756
  return { error: MISSING_MATCHUP_ID };
19682
- const result = findMatchUp$1({
19757
+ const result = findDrawMatchUp({
19683
19758
  drawDefinition,
19684
19759
  matchUpId
19685
19760
  });
@@ -19837,7 +19912,7 @@ function addMatchUpScheduledTime$2(params) {
19837
19912
  if (!validTimeValue(scheduledTime))
19838
19913
  return decorateResult({ result: { error: INVALID_TIME }, stack });
19839
19914
  if (!matchUp) {
19840
- const result = findMatchUp$1({ drawDefinition, matchUpId });
19915
+ const result = findDrawMatchUp({ drawDefinition, matchUpId });
19841
19916
  if (result.error)
19842
19917
  return decorateResult({ result, stack });
19843
19918
  matchUp = result.matchUp;
@@ -19894,7 +19969,7 @@ function addMatchUpTimeModifiers({
19894
19969
  stack
19895
19970
  });
19896
19971
  if (!matchUp) {
19897
- const result = findMatchUp$1({ drawDefinition, matchUpId });
19972
+ const result = findDrawMatchUp({ drawDefinition, matchUpId });
19898
19973
  if (result.error)
19899
19974
  return decorateResult({ result, stack });
19900
19975
  matchUp = result.matchUp;
@@ -19968,7 +20043,7 @@ function addMatchUpScheduleItems$2({
19968
20043
  const stack = "drawEngine.addMatchUpScheduleItems";
19969
20044
  let matchUp, warning;
19970
20045
  if (!drawMatchUps) {
19971
- const result = findMatchUp$1({ drawDefinition, event, matchUpId });
20046
+ const result = findDrawMatchUp({ drawDefinition, event, matchUpId });
19972
20047
  if (result.error)
19973
20048
  return result;
19974
20049
  matchUp = result.matchUp;
@@ -20263,7 +20338,7 @@ function addMatchUpStartTime$2({
20263
20338
  return { error: MISSING_MATCHUP_ID };
20264
20339
  if (!validTimeValue(startTime))
20265
20340
  return { error: INVALID_TIME };
20266
- const { matchUp } = findMatchUp$1({ drawDefinition, event, matchUpId });
20341
+ const { matchUp } = findDrawMatchUp({ drawDefinition, event, matchUpId });
20267
20342
  const { scheduledDate } = scheduledMatchUpDate({ matchUp });
20268
20343
  const timeItems = matchUp?.timeItems ?? [];
20269
20344
  const earliestRelevantTimeValue = timeItems.filter(
@@ -20307,7 +20382,7 @@ function addMatchUpEndTime$2({
20307
20382
  return { error: MISSING_MATCHUP_ID };
20308
20383
  if (!validTimeValue(endTime))
20309
20384
  return { error: INVALID_TIME };
20310
- const { matchUp } = findMatchUp$1({ drawDefinition, event, matchUpId });
20385
+ const { matchUp } = findDrawMatchUp({ drawDefinition, event, matchUpId });
20311
20386
  const { scheduledDate } = scheduledMatchUpDate({ matchUp });
20312
20387
  const timeItems = matchUp?.timeItems ?? [];
20313
20388
  const latestRelevantTimeValue = timeItems.filter(
@@ -20350,7 +20425,7 @@ function addMatchUpStopTime$2({
20350
20425
  return { error: MISSING_MATCHUP_ID };
20351
20426
  if (!validTimeValue(stopTime))
20352
20427
  return { error: INVALID_TIME };
20353
- const { matchUp } = findMatchUp$1({ drawDefinition, event, matchUpId });
20428
+ const { matchUp } = findDrawMatchUp({ drawDefinition, event, matchUpId });
20354
20429
  const { scheduledDate } = scheduledMatchUpDate({ matchUp });
20355
20430
  const timeItems = matchUp?.timeItems ?? [];
20356
20431
  const hasEndTime = timeItems.reduce((hasEndTime2, timeItem) => {
@@ -20409,7 +20484,7 @@ function addMatchUpResumeTime$2({
20409
20484
  return { error: MISSING_MATCHUP_ID };
20410
20485
  if (!validTimeValue(resumeTime))
20411
20486
  return { error: INVALID_TIME };
20412
- const { matchUp } = findMatchUp$1({ drawDefinition, event, matchUpId });
20487
+ const { matchUp } = findDrawMatchUp({ drawDefinition, event, matchUpId });
20413
20488
  const { scheduledDate } = scheduledMatchUpDate({ matchUp });
20414
20489
  const timeItems = matchUp?.timeItems ?? [];
20415
20490
  const hasEndTime = timeItems.reduce((hasEndTime2, timeItem) => {
@@ -22254,8 +22329,8 @@ function updateSideLineUp({
22254
22329
  element: drawDefinition,
22255
22330
  name: LINEUPS
22256
22331
  });
22257
- const value = existingExtension?.value || {};
22258
- const lineUp = value[teamParticipantId];
22332
+ const lineUps = existingExtension?.value || {};
22333
+ const lineUp = makeDeepCopy(lineUps[teamParticipantId], false, true);
22259
22334
  if (sideExists) {
22260
22335
  matchUp?.sides?.forEach((side) => {
22261
22336
  if (side.sideNumber === drawPositionSideNumber) {
@@ -22270,13 +22345,12 @@ function updateSideLineUp({
22270
22345
  const targetSide = matchUp.sides.find(
22271
22346
  (side) => side.sideNumber === drawPositionSideNumber
22272
22347
  );
22273
- if (targetSide) {
22348
+ if (targetSide)
22274
22349
  targetSide.lineUp = lineUp;
22275
- }
22276
22350
  }
22277
22351
  modifyMatchUpNotice({
22278
22352
  tournamentId: tournamentRecord?.tournamentId,
22279
- context: "updateSidLineUps",
22353
+ context: "updateSidLineUp",
22280
22354
  eventId: event?.eventId,
22281
22355
  drawDefinition,
22282
22356
  matchUp
@@ -23213,10 +23287,10 @@ function removeLineUpSubstitutions({ lineUp }) {
23213
23287
  const participantAssignments = {};
23214
23288
  const permutations = unique(
23215
23289
  lineUp.flatMap(
23216
- ({ collectionAssignments }) => collectionAssignments.map(
23290
+ ({ collectionAssignments }) => collectionAssignments?.map(
23217
23291
  ({ collectionId, collectionPosition }) => [collectionId, collectionPosition].join("|")
23218
23292
  )
23219
- )
23293
+ ).filter(Boolean)
23220
23294
  );
23221
23295
  permutations.forEach((permutation) => {
23222
23296
  const [collectionId, position] = permutation.split("|");
@@ -25821,7 +25895,7 @@ function setMatchUpStatus$2(params) {
25821
25895
  matchUp
25822
25896
  });
25823
25897
  if (matchUpTieId) {
25824
- const { matchUp: dualMatchUp } = findMatchUp$1({
25898
+ const { matchUp: dualMatchUp } = findDrawMatchUp({
25825
25899
  matchUpId: matchUpTieId,
25826
25900
  inContext: true,
25827
25901
  drawDefinition,
@@ -25967,7 +26041,7 @@ function setMatchUpFormat$1(params) {
25967
26041
  return { error: UNRECOGNIZED_MATCHUP_FORMAT };
25968
26042
  const stack = "setMatchUpFormat";
25969
26043
  if (matchUpId) {
25970
- const result = findMatchUp$1({
26044
+ const result = findDrawMatchUp({
25971
26045
  drawDefinition,
25972
26046
  matchUpId,
25973
26047
  event
@@ -28374,7 +28448,7 @@ function getTieFormat$1({
28374
28448
  tieFormat = getObjectTieFormat(event);
28375
28449
  } else if (matchUpId) {
28376
28450
  if (drawDefinition && (!matchUp || !structure)) {
28377
- const result = findMatchUp$1({
28451
+ const result = findDrawMatchUp({
28378
28452
  drawDefinition,
28379
28453
  matchUpId
28380
28454
  });
@@ -29048,7 +29122,7 @@ function orderCollectionDefinitions$1({
29048
29122
  if (eventId && event?.tieFormat) {
29049
29123
  updateEventTieFormat({ tournamentRecord, event, orderMap });
29050
29124
  } else if (matchUpId) {
29051
- const result = drawDefinition && findMatchUp$1({
29125
+ const result = drawDefinition && findDrawMatchUp({
29052
29126
  drawDefinition,
29053
29127
  matchUpId
29054
29128
  });
@@ -29312,7 +29386,7 @@ function removeCollectionDefinition$1({
29312
29386
  });
29313
29387
  if (result2.error)
29314
29388
  return result2;
29315
- result2 = findMatchUp$1({
29389
+ result2 = findDrawMatchUp({
29316
29390
  drawDefinition,
29317
29391
  matchUpId
29318
29392
  });
@@ -30171,7 +30245,7 @@ function findMatchUp({
30171
30245
  contextProfile,
30172
30246
  inContext
30173
30247
  });
30174
- const { matchUp, structure } = findMatchUp$1({
30248
+ const { matchUp, structure } = findDrawMatchUp({
30175
30249
  context: inContext ? additionalContext : void 0,
30176
30250
  tournamentParticipants,
30177
30251
  afterRecoveryTimes,
@@ -33879,7 +33953,7 @@ function checkInParticipant$1({
33879
33953
  tournamentParticipants = tournamentParticipants ?? tournamentRecord?.participants;
33880
33954
  if (tournamentParticipants?.length) {
33881
33955
  if (!matchUp && drawDefinition) {
33882
- const result2 = findMatchUp$1({
33956
+ const result2 = findDrawMatchUp({
33883
33957
  tournamentParticipants,
33884
33958
  inContext: true,
33885
33959
  drawDefinition,
@@ -33928,7 +34002,7 @@ function checkOutParticipant$1({
33928
34002
  return { error: MISSING_MATCHUP_ID };
33929
34003
  tournamentParticipants = tournamentParticipants ?? tournamentRecord?.participants;
33930
34004
  if (!matchUp) {
33931
- const result = findMatchUp$1({
34005
+ const result = findDrawMatchUp({
33932
34006
  tournamentParticipants,
33933
34007
  inContext: true,
33934
34008
  drawDefinition,
@@ -34052,7 +34126,7 @@ function removeMatchUpCourtAssignment$1(params) {
34052
34126
  });
34053
34127
  if (!drawDefinition)
34054
34128
  return { error: MISSING_DRAW_DEFINITION };
34055
- const result = findMatchUp$1({ drawDefinition, event, matchUpId });
34129
+ const result = findDrawMatchUp({ drawDefinition, event, matchUpId });
34056
34130
  if (result.error)
34057
34131
  return result;
34058
34132
  if (result?.matchUp?.matchUpType === TEAM_MATCHUP) {
@@ -36251,7 +36325,7 @@ function matchUpActions$2({
36251
36325
  });
36252
36326
  const otherFlightEntries = specifiedPolicyDefinitions?.[POLICY_TYPE_POSITION_ACTIONS]?.otherFlightEntries;
36253
36327
  const { drawId } = drawDefinition;
36254
- const { matchUp, structure } = findMatchUp$1({
36328
+ const { matchUp, structure } = findDrawMatchUp({
36255
36329
  drawDefinition,
36256
36330
  matchUpId,
36257
36331
  event
@@ -36959,7 +37033,7 @@ function removeCourtAssignment({
36959
37033
  ({ drawDefinition } = findEvent({ tournamentRecord, drawId }));
36960
37034
  }
36961
37035
  if (drawDefinition) {
36962
- ({ matchUp } = findMatchUp$1({ drawDefinition, matchUpId }));
37036
+ ({ matchUp } = findDrawMatchUp({ drawDefinition, matchUpId }));
36963
37037
  } else {
36964
37038
  if (!tournamentRecord)
36965
37039
  return { error: MISSING_TOURNAMENT_RECORD };
@@ -46308,13 +46382,13 @@ function resetMatchUpLineUps$1({
46308
46382
  }) {
46309
46383
  if (!drawDefinition)
46310
46384
  return { error: MISSING_DRAW_DEFINITION };
46311
- const matchUp = findMatchUp$1({
46385
+ const matchUp = findDrawMatchUp({
46312
46386
  drawDefinition,
46313
46387
  matchUpId
46314
46388
  })?.matchUp;
46315
46389
  if (!matchUp?.tieMatchUps)
46316
46390
  return { error: INVALID_MATCHUP };
46317
- const inContextMatchUp = findMatchUp$1({
46391
+ const inContextMatchUp = findDrawMatchUp({
46318
46392
  inContext: true,
46319
46393
  drawDefinition,
46320
46394
  matchUpId,
@@ -46427,7 +46501,7 @@ function removeDelegatedOutcome$1({ drawDefinition, event, matchUpId }) {
46427
46501
  return { error: MISSING_DRAW_DEFINITION };
46428
46502
  if (!matchUpId)
46429
46503
  return { error: MISSING_MATCHUP_ID };
46430
- const { matchUp } = findMatchUp$1({ drawDefinition, event, matchUpId });
46504
+ const { matchUp } = findDrawMatchUp({ drawDefinition, event, matchUpId });
46431
46505
  if (!matchUp)
46432
46506
  return { error: MATCHUP_NOT_FOUND };
46433
46507
  return removeExtension$1({
@@ -46941,7 +47015,7 @@ function setDelegatedOutcome$1({
46941
47015
  if (!matchUp && !matchUpId)
46942
47016
  return { error: MISSING_MATCHUP };
46943
47017
  if (!matchUp) {
46944
- const result = findMatchUp$1({
47018
+ const result = findDrawMatchUp({
46945
47019
  drawDefinition,
46946
47020
  matchUpId
46947
47021
  });
@@ -46989,7 +47063,7 @@ function validDrawPosition(drawPosition) {
46989
47063
  function disableTieAutoCalc$1({ drawDefinition, matchUpId, event }) {
46990
47064
  if (!drawDefinition)
46991
47065
  return { error: MISSING_DRAW_DEFINITION };
46992
- const { matchUp } = findMatchUp$1({
47066
+ const { matchUp } = findDrawMatchUp({
46993
47067
  drawDefinition,
46994
47068
  matchUpId,
46995
47069
  event
@@ -47008,7 +47082,7 @@ function enableTieAutoCalc$1({
47008
47082
  }) {
47009
47083
  if (!drawDefinition)
47010
47084
  return { error: MISSING_DRAW_DEFINITION };
47011
- const { matchUp } = findMatchUp$1({
47085
+ const { matchUp } = findDrawMatchUp({
47012
47086
  drawDefinition,
47013
47087
  matchUpId,
47014
47088
  event
@@ -47158,7 +47232,7 @@ const matchUpGovernor = {
47158
47232
  removeDelegatedOutcome: removeDelegatedOutcome$1,
47159
47233
  drawMatic: drawMatic$1,
47160
47234
  addMatchUpOfficial: addMatchUpOfficial$2,
47161
- findMatchUp: publicFindMatchUp$1,
47235
+ findMatchUp: publicFindDrawMatchUp,
47162
47236
  getRoundMatchUps: getRoundMatchUps$1,
47163
47237
  validDrawPositions,
47164
47238
  validateScore
@@ -52715,14 +52789,14 @@ function getTieMatchUpContext({
52715
52789
  if (!event)
52716
52790
  return { error: EVENT_NOT_FOUND };
52717
52791
  const matchUpsMap = getMatchUpsMap({ drawDefinition });
52718
- const { matchUp: tieMatchUp } = findMatchUp$1({
52792
+ const { matchUp: tieMatchUp } = findDrawMatchUp({
52719
52793
  matchUpId: tieMatchUpId,
52720
52794
  drawDefinition,
52721
52795
  matchUpsMap
52722
52796
  });
52723
52797
  if (!tieMatchUp)
52724
52798
  return { error: MATCHUP_NOT_FOUND };
52725
- const { matchUp: inContextTieMatchUp, structure } = findMatchUp$1({
52799
+ const { matchUp: inContextTieMatchUp, structure } = findDrawMatchUp({
52726
52800
  tournamentParticipants: tournamentRecord.participants,
52727
52801
  matchUpId: tieMatchUpId,
52728
52802
  inContext: true,
@@ -52755,12 +52829,12 @@ function getTieMatchUpContext({
52755
52829
  participantIds
52756
52830
  }
52757
52831
  });
52758
- const { matchUp: dualMatchUp } = findMatchUp$1({
52832
+ const { matchUp: dualMatchUp } = findDrawMatchUp({
52759
52833
  matchUpId: matchUpTieId,
52760
52834
  drawDefinition,
52761
52835
  matchUpsMap
52762
52836
  });
52763
- const { matchUp: inContextDualMatchUp } = findMatchUp$1({
52837
+ const { matchUp: inContextDualMatchUp } = findDrawMatchUp({
52764
52838
  matchUpId: matchUpTieId,
52765
52839
  inContext: true,
52766
52840
  drawDefinition,
@@ -52818,9 +52892,9 @@ function assignTieMatchUpParticipantId(params) {
52818
52892
  if (allTieIndividualParticipantIds?.includes(participantId)) {
52819
52893
  return decorateResult({ result: { ...SUCCESS }, stack });
52820
52894
  }
52821
- teamParticipantId = teamParticipantId || params.sideNumber && inContextDualMatchUp?.sides?.find(
52895
+ teamParticipantId = teamParticipantId || (params.sideNumber ? inContextDualMatchUp?.sides?.find(
52822
52896
  (side) => side.sideNumber === params.sideNumber
52823
- )?.participantId;
52897
+ )?.participantId : void 0);
52824
52898
  const participantToAssign = getParticipants$1({
52825
52899
  participantFilters: { participantIds: [participantId] },
52826
52900
  tournamentRecord
@@ -52870,27 +52944,13 @@ function assignTieMatchUpParticipantId(params) {
52870
52944
  );
52871
52945
  if (!collectionDefinition)
52872
52946
  return { error: MISSING_COLLECTION_DEFINITION };
52873
- if (!dualMatchUp?.sides?.length) {
52874
- const { extension } = findExtension$2({
52875
- element: drawDefinition,
52876
- name: LINEUPS
52877
- });
52878
- const lineUps = makeDeepCopy(extension?.value || {}, false, true);
52879
- const extractSideDetail = ({
52880
- displaySideNumber,
52881
- drawPosition,
52882
- sideNumber: sideNumber2
52883
- }) => ({ drawPosition, sideNumber: sideNumber2, displaySideNumber });
52884
- if (dualMatchUp) {
52885
- dualMatchUp.sides = inContextDualMatchUp?.sides?.map((side) => {
52886
- const participantId2 = side.participantId;
52887
- return {
52888
- ...extractSideDetail(side),
52889
- lineUp: participantId2 && lineUps[participantId2] || []
52890
- };
52891
- });
52892
- }
52893
- }
52947
+ ensureSideLineUps({
52948
+ tournamentId: tournamentRecord.tournamentId,
52949
+ eventId: event.eventId,
52950
+ inContextDualMatchUp,
52951
+ drawDefinition,
52952
+ dualMatchUp
52953
+ });
52894
52954
  const dualMatchUpSide = dualMatchUp?.sides?.find(
52895
52955
  (side) => side.sideNumber === sideNumber
52896
52956
  );
@@ -52921,7 +52981,7 @@ function assignTieMatchUpParticipantId(params) {
52921
52981
  if (removeResult.error)
52922
52982
  return decorateResult({ result: removeResult, stack });
52923
52983
  const { modifiedLineUp } = removeResult;
52924
- let deleteParticipantId;
52984
+ let deletedParticipantId;
52925
52985
  if (matchUpType === DOUBLES$1) {
52926
52986
  if (participantType !== PAIR) {
52927
52987
  let result = updateLineUp({
@@ -52940,7 +53000,7 @@ function assignTieMatchUpParticipantId(params) {
52940
53000
  });
52941
53001
  if (result.error)
52942
53002
  return result;
52943
- deleteParticipantId = result.deleteParticipantId;
53003
+ deletedParticipantId = result.deletedParticipantId;
52944
53004
  if (dualMatchUpSide)
52945
53005
  dualMatchUpSide.lineUp = modifiedLineUp;
52946
53006
  if (dualMatchUp) {
@@ -52986,9 +53046,9 @@ function assignTieMatchUpParticipantId(params) {
52986
53046
  context: stack,
52987
53047
  drawDefinition
52988
53048
  });
52989
- if (deleteParticipantId) {
53049
+ if (deletedParticipantId) {
52990
53050
  const { error } = deleteParticipants({
52991
- participantIds: [deleteParticipantId],
53051
+ participantIds: [deletedParticipantId],
52992
53052
  tournamentRecord
52993
53053
  });
52994
53054
  if (error)
@@ -52996,7 +53056,7 @@ function assignTieMatchUpParticipantId(params) {
52996
53056
  }
52997
53057
  return { ...SUCCESS, modifiedLineUp };
52998
53058
  function addParticipantId2Pair({ side }) {
52999
- let deleteParticipantId2;
53059
+ let deletedParticipantId2;
53000
53060
  if (!side.participant) {
53001
53061
  const newPairParticipant = {
53002
53062
  individualParticipantIds: [participantId],
@@ -53033,11 +53093,11 @@ function assignTieMatchUpParticipantId(params) {
53033
53093
  if (result.error)
53034
53094
  return result;
53035
53095
  } else {
53036
- deleteParticipantId2 = participant?.participantId;
53096
+ deletedParticipantId2 = participant?.participantId;
53037
53097
  }
53038
53098
  }
53039
53099
  }
53040
- return { ...SUCCESS, deleteParticipantId: deleteParticipantId2 };
53100
+ return { ...SUCCESS, deletedParticipantId: deletedParticipantId2 };
53041
53101
  }
53042
53102
  }
53043
53103
  function updateLineUp({
@@ -53182,10 +53242,12 @@ function generateLineUps(params) {
53182
53242
  participantIdPairs.push(participantIds2);
53183
53243
  });
53184
53244
  }
53185
- const lineUp = Object.keys(participantAssignments).map((participantId) => ({
53186
- collectionAssignments: participantAssignments[participantId],
53187
- participantId
53188
- }));
53245
+ const lineUp = Object.keys(participantAssignments).map(
53246
+ (participantId) => ({
53247
+ collectionAssignments: participantAssignments[participantId],
53248
+ participantId
53249
+ })
53250
+ );
53189
53251
  lineUps[teamParticipant.participantId] = lineUp;
53190
53252
  }
53191
53253
  const participantsToAdd = [];
@@ -53554,7 +53616,7 @@ function completeDrawMatchUps(params) {
53554
53616
  );
53555
53617
  if (teamParticipant) {
53556
53618
  const individualParticipantId = teamParticipant.individualParticipantIds?.[i];
53557
- assignTieMatchUpParticipantId({
53619
+ individualParticipantId && assignTieMatchUpParticipantId({
53558
53620
  teamParticipantId: teamParticipant.participantId,
53559
53621
  participantId: individualParticipantId,
53560
53622
  tournamentRecord,
@@ -54623,6 +54685,7 @@ function getParticipantStats({
54623
54685
  withIndividualStats,
54624
54686
  teamParticipantId,
54625
54687
  tournamentRecord,
54688
+ withScaleValues,
54626
54689
  tallyPolicy,
54627
54690
  matchUps
54628
54691
  }) {
@@ -54630,7 +54693,8 @@ function getParticipantStats({
54630
54693
  return { error: MISSING_TOURNAMENT_RECORD };
54631
54694
  if (matchUps && !Array.isArray(matchUps))
54632
54695
  return { error: INVALID_MATCHUP };
54633
- matchUps = matchUps || allTournamentMatchUps({ tournamentRecord }).matchUps;
54696
+ const participantsProfile = withScaleValues ? { withScaleValues } : void 0;
54697
+ matchUps = matchUps || allTournamentMatchUps({ tournamentRecord, participantsProfile }).matchUps;
54634
54698
  if (!matchUps?.length)
54635
54699
  return { error: MISSING_MATCHUPS };
54636
54700
  const teamParticipantIds = [];
@@ -54647,8 +54711,8 @@ function getParticipantStats({
54647
54711
  }
54648
54712
  if (!teamParticipantIds.length)
54649
54713
  teamParticipantIds.push(...teamParticipants.map(extractAttributes("participantId")));
54714
+ const participantDetails = /* @__PURE__ */ new Map();
54650
54715
  const participantStats = /* @__PURE__ */ new Map();
54651
- const participantNameMap = /* @__PURE__ */ new Map();
54652
54716
  const participating = /* @__PURE__ */ new Map();
54653
54717
  const teamMap = /* @__PURE__ */ new Map();
54654
54718
  const initStats = (participantId, participantName = "") => participantStats.get(participantId) || participantStats.set(participantId, {
@@ -54682,11 +54746,13 @@ function getParticipantStats({
54682
54746
  const getSideParticipantIds = (sides) => {
54683
54747
  const sideParticipantIds = [[], []];
54684
54748
  for (const side of sides) {
54685
- if (side.participant?.participantName)
54686
- participantNameMap.set(
54687
- side.participant.participantId,
54688
- side.participant.participantName
54689
- );
54749
+ const participant = side.participant;
54750
+ if (participant?.participantName) {
54751
+ participantDetails.set(participant.participantId, {
54752
+ participantName: participant.participantName,
54753
+ ratings: participant.ratings
54754
+ });
54755
+ }
54690
54756
  }
54691
54757
  const getCompetitorIds = ({ side, individualParticipantIds }) => {
54692
54758
  return side.participantId && (!individualParticipantIds?.length || individualParticipantIds.includes(side.participantId)) && [
@@ -54792,7 +54858,8 @@ function getParticipantStats({
54792
54858
  });
54793
54859
  sideParticipantIds.forEach((ids, index) => {
54794
54860
  for (const id of ids) {
54795
- const stats = initStats(id, participantNameMap.get(id));
54861
+ const participantName = participantDetails.get(id)?.participantName;
54862
+ const stats = initStats(id, participantName);
54796
54863
  if (stats) {
54797
54864
  const teamSumTally = (stat, tally) => tally.forEach((t, i) => stats[stat][i] += t);
54798
54865
  const tiebreaks = index ? [...tiebreaksTally].reverse() : tiebreaksTally;
@@ -55184,8 +55251,10 @@ function assignMatchUpSideParticipant({
55184
55251
  if (noSideNumberProvided)
55185
55252
  sideNumber = 1;
55186
55253
  if (![1, 2].includes(sideNumber))
55187
- return { error: INVALID_VALUES, sideNumber };
55188
- const { matchUp, structure } = findMatchUp$1({
55254
+ return decorateResult({
55255
+ result: { error: INVALID_VALUES, context: { sideNumber } }
55256
+ });
55257
+ const { matchUp, structure } = findDrawMatchUp({
55189
55258
  drawDefinition,
55190
55259
  matchUpId,
55191
55260
  event
@@ -55240,7 +55309,7 @@ function removeMatchUpSideParticipant({
55240
55309
  return { error: MISSING_VALUE };
55241
55310
  if (![1, 2].includes(sideNumber))
55242
55311
  return { error: INVALID_VALUES, sideNumber };
55243
- const { matchUp, structure } = findMatchUp$1({
55312
+ const { matchUp, structure } = findDrawMatchUp({
55244
55313
  drawDefinition,
55245
55314
  matchUpId,
55246
55315
  event
@@ -55323,27 +55392,13 @@ function replaceTieMatchUpParticipantId(params) {
55323
55392
  return { error: INVALID_PARTICIPANT, info: "Gender mismatch" };
55324
55393
  }
55325
55394
  const substitutionProcessCodes = matchUpActionsPolicy?.processCodes?.substitution;
55326
- const { extension } = findExtension$2({
55327
- element: drawDefinition,
55328
- name: LINEUPS
55395
+ ensureSideLineUps({
55396
+ tournamentId: tournamentRecord.tournamentId,
55397
+ eventId: event.eventId,
55398
+ inContextDualMatchUp,
55399
+ drawDefinition,
55400
+ dualMatchUp
55329
55401
  });
55330
- const lineUps = extension?.value || {};
55331
- if (!dualMatchUp?.sides?.length) {
55332
- const extractSideDetail = ({
55333
- displaySideNumber,
55334
- drawPosition,
55335
- sideNumber
55336
- }) => ({ drawPosition, sideNumber, displaySideNumber });
55337
- if (dualMatchUp) {
55338
- dualMatchUp.sides = inContextDualMatchUp?.sides?.map((side2) => {
55339
- const participantId = side2.participantId;
55340
- return {
55341
- ...extractSideDetail(side2),
55342
- lineUp: participantId && lineUps[participantId] || []
55343
- };
55344
- });
55345
- }
55346
- }
55347
55402
  const dualMatchUpSide = dualMatchUp?.sides?.find(
55348
55403
  ({ sideNumber }) => sideNumber === side.sideNumber
55349
55404
  );
@@ -55568,25 +55623,13 @@ function removeTieMatchUpParticipantId(params) {
55568
55623
  return decorateResult({ result: { error: INVALID_PARTICIPANT }, stack });
55569
55624
  }
55570
55625
  const participantIds = participantToRemove.participantType === INDIVIDUAL ? [participantId] : participantToRemove.individualParticipantIds;
55571
- if (!dualMatchUp?.sides?.length) {
55572
- const { extension } = findExtension$2({
55573
- element: drawDefinition,
55574
- name: LINEUPS
55575
- });
55576
- const lineUps = extension?.value || {};
55577
- const extractSideDetail = ({
55578
- displaySideNumber,
55579
- drawPosition,
55580
- sideNumber
55581
- }) => ({ drawPosition, sideNumber, displaySideNumber });
55582
- dualMatchUp.sides = inContextDualMatchUp?.sides?.map((side2) => {
55583
- const participantId2 = side2.participantId;
55584
- return {
55585
- ...extractSideDetail(side2),
55586
- lineUp: participantId2 && lineUps[participantId2] || []
55587
- };
55588
- });
55589
- }
55626
+ ensureSideLineUps({
55627
+ tournamentId: tournamentRecord.tournamentId,
55628
+ eventId: event.eventId,
55629
+ inContextDualMatchUp,
55630
+ drawDefinition,
55631
+ dualMatchUp
55632
+ });
55590
55633
  let dualMatchUpSide = dualMatchUp.sides?.find(
55591
55634
  ({ sideNumber }) => sideNumber === side.sideNumber
55592
55635
  );
@@ -55606,8 +55649,9 @@ function removeTieMatchUpParticipantId(params) {
55606
55649
  );
55607
55650
  }
55608
55651
  if (!dualMatchUpSide) {
55609
- console.log({ teamParticipantId, teamParticipants });
55610
- return { error: PARTICIPANT_NOT_FOUND, participantId };
55652
+ return decorateResult({
55653
+ result: { error: PARTICIPANT_NOT_FOUND, context: { participantId } }
55654
+ });
55611
55655
  }
55612
55656
  const { modifiedLineUp, previousParticipantIds } = removeCollectionAssignments({
55613
55657
  collectionPosition,
@@ -57819,7 +57863,7 @@ function substituteParticipant$1({
57819
57863
  return { error: MISSING_MATCHUP_ID };
57820
57864
  if (!existingParticipantId || !substituteParticipantId)
57821
57865
  return decorateResult({ result: { error: MISSING_PARTICIPANT_ID }, stack });
57822
- const { matchUp } = findMatchUp$1({
57866
+ const { matchUp } = findDrawMatchUp({
57823
57867
  drawDefinition,
57824
57868
  matchUpId,
57825
57869
  event
@@ -58437,7 +58481,7 @@ function applyLineUps({
58437
58481
  return { error: INVALID_VALUES, lineUps };
58438
58482
  const stack = "applyLineUps";
58439
58483
  const tournamentParticipants = tournamentRecord.participants || [];
58440
- let result = findMatchUp$1({
58484
+ let result = findDrawMatchUp({
58441
58485
  tournamentParticipants,
58442
58486
  inContext: true,
58443
58487
  drawDefinition,
@@ -58542,7 +58586,7 @@ function applyLineUps({
58542
58586
  }
58543
58587
  if (!Object.keys(sideAssignments).length)
58544
58588
  return { error: VALUE_UNCHANGED };
58545
- result = findMatchUp$1({ drawDefinition, matchUpId });
58589
+ result = findDrawMatchUp({ drawDefinition, matchUpId });
58546
58590
  if (result.error)
58547
58591
  return result;
58548
58592
  if (!result.matchUp)
@@ -60143,10 +60187,10 @@ function getEvents({
60143
60187
  }
60144
60188
  const processFlight = (drawId, participantIds2) => {
60145
60189
  const processParticipant2 = (participant) => {
60146
- if (participant?.ratings?.[eventType]) {
60190
+ if (eventsMap[eventId].draws?.[drawId] && participant?.ratings?.[eventType]) {
60147
60191
  for (const rating of participant?.ratings?.[eventType] ?? []) {
60148
60192
  const scaleName = rating.scaleName;
60149
- if (!eventsMap[eventId].draws[drawId].ratings[scaleName])
60193
+ if (!eventsMap[eventId].draws[drawId]?.ratings[scaleName])
60150
60194
  eventsMap[eventId].draws[drawId].ratings[scaleName] = [];
60151
60195
  const accessor = ratingsParameters[scaleName]?.accessor;
60152
60196
  if (accessor) {
@@ -64866,6 +64910,7 @@ const utilities = {
64866
64910
  unique,
64867
64911
  UUID,
64868
64912
  UUIDS,
64913
+ validateCategory,
64869
64914
  validateTieFormat,
64870
64915
  visualizeScheduledMatchUps
64871
64916
  };