tods-competition-factory 1.8.18 → 1.8.20

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.18";
2385
+ return "1.8.20";
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";
@@ -2946,8 +2971,8 @@ function validateCollectionDefinition({
2946
2971
  if (checkGender && referenceGender && gender && [GenderEnum.Male, GenderEnum.Female].includes(referenceGender) && referenceGender !== gender) {
2947
2972
  errors.push(`Invalid gender: ${gender}`);
2948
2973
  return decorateResult({
2974
+ result: { error: INVALID_GENDER, errors },
2949
2975
  context: { referenceGender, gender },
2950
- result: { error: INVALID_GENDER },
2951
2976
  stack
2952
2977
  });
2953
2978
  }
@@ -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
@@ -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
  });
@@ -29411,6 +29485,7 @@ function addCollectionDefinition$1({
29411
29485
  collectionDefinition,
29412
29486
  referenceCategory,
29413
29487
  tournamentRecord,
29488
+ policyDefinitions,
29414
29489
  enforceCategory,
29415
29490
  referenceGender,
29416
29491
  drawDefinition,
@@ -29429,11 +29504,11 @@ function addCollectionDefinition$1({
29429
29504
  drawDefinition,
29430
29505
  event
29431
29506
  }).appliedPolicies ?? {};
29432
- const matchUpActionsPolicy = appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS];
29507
+ const matchUpActionsPolicy = policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS];
29433
29508
  enforceCategory = enforceCategory ?? matchUpActionsPolicy?.participants?.enforceCategory;
29434
- enforceGender = enforceGender ?? matchUpActionsPolicy?.participants?.enforceGender;
29509
+ const genderEnforced = (enforceGender ?? matchUpActionsPolicy?.participants?.enforceGender) !== false;
29435
29510
  const checkCategory = !!((referenceCategory ?? event?.category) && enforceCategory !== false);
29436
- const checkGender = !!((referenceGender ?? event?.gender) && enforceGender !== false);
29511
+ const checkGender = !!((referenceGender ?? event?.gender) && genderEnforced);
29437
29512
  const validationResult = validateCollectionDefinition({
29438
29513
  referenceCategory: referenceCategory ?? event?.category,
29439
29514
  collectionDefinition,
@@ -30171,7 +30246,7 @@ function findMatchUp({
30171
30246
  contextProfile,
30172
30247
  inContext
30173
30248
  });
30174
- const { matchUp, structure } = findMatchUp$1({
30249
+ const { matchUp, structure } = findDrawMatchUp({
30175
30250
  context: inContext ? additionalContext : void 0,
30176
30251
  tournamentParticipants,
30177
30252
  afterRecoveryTimes,
@@ -33879,7 +33954,7 @@ function checkInParticipant$1({
33879
33954
  tournamentParticipants = tournamentParticipants ?? tournamentRecord?.participants;
33880
33955
  if (tournamentParticipants?.length) {
33881
33956
  if (!matchUp && drawDefinition) {
33882
- const result2 = findMatchUp$1({
33957
+ const result2 = findDrawMatchUp({
33883
33958
  tournamentParticipants,
33884
33959
  inContext: true,
33885
33960
  drawDefinition,
@@ -33928,7 +34003,7 @@ function checkOutParticipant$1({
33928
34003
  return { error: MISSING_MATCHUP_ID };
33929
34004
  tournamentParticipants = tournamentParticipants ?? tournamentRecord?.participants;
33930
34005
  if (!matchUp) {
33931
- const result = findMatchUp$1({
34006
+ const result = findDrawMatchUp({
33932
34007
  tournamentParticipants,
33933
34008
  inContext: true,
33934
34009
  drawDefinition,
@@ -34052,7 +34127,7 @@ function removeMatchUpCourtAssignment$1(params) {
34052
34127
  });
34053
34128
  if (!drawDefinition)
34054
34129
  return { error: MISSING_DRAW_DEFINITION };
34055
- const result = findMatchUp$1({ drawDefinition, event, matchUpId });
34130
+ const result = findDrawMatchUp({ drawDefinition, event, matchUpId });
34056
34131
  if (result.error)
34057
34132
  return result;
34058
34133
  if (result?.matchUp?.matchUpType === TEAM_MATCHUP) {
@@ -36234,6 +36309,7 @@ function matchUpActions$2({
36234
36309
  inContextDrawMatchUps,
36235
36310
  tournamentRecord,
36236
36311
  drawDefinition,
36312
+ enforceGender,
36237
36313
  participantId,
36238
36314
  matchUpsMap,
36239
36315
  sideNumber,
@@ -36251,7 +36327,7 @@ function matchUpActions$2({
36251
36327
  });
36252
36328
  const otherFlightEntries = specifiedPolicyDefinitions?.[POLICY_TYPE_POSITION_ACTIONS]?.otherFlightEntries;
36253
36329
  const { drawId } = drawDefinition;
36254
- const { matchUp, structure } = findMatchUp$1({
36330
+ const { matchUp, structure } = findDrawMatchUp({
36255
36331
  drawDefinition,
36256
36332
  matchUpId,
36257
36333
  event
@@ -36265,8 +36341,8 @@ function matchUpActions$2({
36265
36341
  event
36266
36342
  }).appliedPolicies ?? {};
36267
36343
  Object.assign(appliedPolicies, specifiedPolicyDefinitions ?? {});
36268
- const isAdHocMatchUp = isAdHoc({ drawDefinition, structure });
36269
36344
  const matchUpActionsPolicy = appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
36345
+ const isAdHocMatchUp = isAdHoc({ drawDefinition, structure });
36270
36346
  const { enabledStructures } = getEnabledStructures({
36271
36347
  actionType: MATCHUP_ACTION,
36272
36348
  appliedPolicies,
@@ -36480,7 +36556,8 @@ function matchUpActions$2({
36480
36556
  );
36481
36557
  const assignedGender = inContextMatchUp.gender === MIXED && inContextMatchUp.sideNumber && inContextMatchUp.sides?.filter((side2) => side2.particiapntId).length === 1 && firstFoundSide?.participant?.person?.sex;
36482
36558
  const matchUpType = inContextMatchUp.matchUpType;
36483
- const gender = matchUpActionsPolicy?.participants?.enforceGender ? inContextMatchUp.gender : void 0;
36559
+ const genderEnforced = (enforceGender ?? matchUpActionsPolicy?.participants?.enforceGender) !== false;
36560
+ const gender = genderEnforced ? inContextMatchUp.gender : void 0;
36484
36561
  const allParticipants = inContextMatchUp.sides?.flatMap(
36485
36562
  (side2) => side2.participant?.individualParticipants || side2.participant
36486
36563
  ).filter(Boolean);
@@ -36610,6 +36687,7 @@ function matchUpActions$1({
36610
36687
  policyDefinitions,
36611
36688
  tournamentRecord,
36612
36689
  drawDefinition,
36690
+ enforceGender,
36613
36691
  participantId,
36614
36692
  sideNumber,
36615
36693
  matchUpId,
@@ -36644,6 +36722,7 @@ function matchUpActions$1({
36644
36722
  tournamentParticipants: tournamentRecord.participants,
36645
36723
  policyDefinitions,
36646
36724
  drawDefinition,
36725
+ enforceGender,
36647
36726
  participantId,
36648
36727
  sideNumber,
36649
36728
  matchUpId,
@@ -36657,6 +36736,8 @@ function matchUpActions$1({
36657
36736
  function matchUpActions(params) {
36658
36737
  const {
36659
36738
  tournamentRecords,
36739
+ policyDefinitions,
36740
+ enforceGender,
36660
36741
  participantId,
36661
36742
  tournamentId,
36662
36743
  sideNumber,
@@ -36678,7 +36759,9 @@ function matchUpActions(params) {
36678
36759
  return result;
36679
36760
  return matchUpActions$1({
36680
36761
  drawDefinition: result.drawDefinition,
36762
+ policyDefinitions,
36681
36763
  tournamentRecord,
36764
+ enforceGender,
36682
36765
  participantId,
36683
36766
  sideNumber,
36684
36767
  matchUpId,
@@ -36959,7 +37042,7 @@ function removeCourtAssignment({
36959
37042
  ({ drawDefinition } = findEvent({ tournamentRecord, drawId }));
36960
37043
  }
36961
37044
  if (drawDefinition) {
36962
- ({ matchUp } = findMatchUp$1({ drawDefinition, matchUpId }));
37045
+ ({ matchUp } = findDrawMatchUp({ drawDefinition, matchUpId }));
36963
37046
  } else {
36964
37047
  if (!tournamentRecord)
36965
37048
  return { error: MISSING_TOURNAMENT_RECORD };
@@ -45343,9 +45426,10 @@ function addEventEntries(params) {
45343
45426
  const {
45344
45427
  entryStatus = DIRECT_ACCEPTANCE,
45345
45428
  autoEntryPositions = true,
45429
+ enforceGender = true,
45346
45430
  participantIds = [],
45347
45431
  entryStageSequence,
45348
- ignoreEventGender,
45432
+ policyDefinitions,
45349
45433
  entryStage = MAIN,
45350
45434
  tournamentRecord,
45351
45435
  ignoreStageSpace,
@@ -45367,6 +45451,9 @@ function addEventEntries(params) {
45367
45451
  }
45368
45452
  if (!event?.eventId)
45369
45453
  return { error: EVENT_NOT_FOUND };
45454
+ const appliedPolicies = getAppliedPolicies({ tournamentRecord, event }).appliedPolicies ?? {};
45455
+ const matchUpActionsPolicy = policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
45456
+ const genderEnforced = (enforceGender ?? matchUpActionsPolicy?.participants?.enforceGender) !== false;
45370
45457
  const addedParticipantIdEntries = [];
45371
45458
  const removedEntries = [];
45372
45459
  if (extensions && (!Array.isArray(extensions) || !extensions.every(isValidExtension)) || extension && !isValidExtension({ extension })) {
@@ -45378,14 +45465,14 @@ function addEventEntries(params) {
45378
45465
  });
45379
45466
  }
45380
45467
  const checkTypedParticipants = !!tournamentRecord;
45381
- const misMatchedGender = [];
45468
+ const mismatchedGender = [];
45382
45469
  let info;
45383
45470
  const typedParticipantIds = tournamentRecord?.participants?.filter((participant) => {
45384
45471
  if (!participantIds.includes(participant.participantId))
45385
45472
  return false;
45386
45473
  const validSingles = event.eventType === SINGLES$1 && participant.participantType === INDIVIDUAL && !isUngrouped(entryStatus);
45387
45474
  const validDoubles = event.eventType === DOUBLES$1 && participant.participantType === PAIR;
45388
- if (validSingles && (!event.gender || ignoreEventGender || [MIXED, ANY].includes(event.gender) || event.gender === participant.person?.sex)) {
45475
+ if (validSingles && (!event.gender || !genderEnforced || [MIXED, ANY].includes(event.gender) || event.gender === participant.person?.sex)) {
45389
45476
  return true;
45390
45477
  }
45391
45478
  if (validDoubles && !isUngrouped(entryStatus)) {
@@ -45394,8 +45481,8 @@ function addEventEntries(params) {
45394
45481
  if (event.eventType === DOUBLES$1 && participant.participantType === INDIVIDUAL && isUngrouped(entryStatus)) {
45395
45482
  return true;
45396
45483
  }
45397
- if (validSingles && event.gender && !ignoreEventGender && ![MIXED, ANY].includes(event.gender) && event.gender !== participant.person?.sex) {
45398
- misMatchedGender.push({
45484
+ if (validSingles && event.gender && genderEnforced && ![MIXED, ANY].includes(event.gender) && event.gender !== participant.person?.sex) {
45485
+ mismatchedGender.push({
45399
45486
  participantId: participant.participantId,
45400
45487
  sex: participant.person?.sex
45401
45488
  });
@@ -45477,7 +45564,7 @@ function addEventEntries(params) {
45477
45564
  const invalidParticipantIds = validParticipantIds.length !== participantIds.length;
45478
45565
  if (invalidParticipantIds)
45479
45566
  return decorateResult({
45480
- context: { misMatchedGender, gender: event.gender },
45567
+ context: { mismatchedGender, gender: event.gender },
45481
45568
  result: { error: INVALID_PARTICIPANT_IDS },
45482
45569
  stack
45483
45570
  });
@@ -46308,13 +46395,13 @@ function resetMatchUpLineUps$1({
46308
46395
  }) {
46309
46396
  if (!drawDefinition)
46310
46397
  return { error: MISSING_DRAW_DEFINITION };
46311
- const matchUp = findMatchUp$1({
46398
+ const matchUp = findDrawMatchUp({
46312
46399
  drawDefinition,
46313
46400
  matchUpId
46314
46401
  })?.matchUp;
46315
46402
  if (!matchUp?.tieMatchUps)
46316
46403
  return { error: INVALID_MATCHUP };
46317
- const inContextMatchUp = findMatchUp$1({
46404
+ const inContextMatchUp = findDrawMatchUp({
46318
46405
  inContext: true,
46319
46406
  drawDefinition,
46320
46407
  matchUpId,
@@ -46427,7 +46514,7 @@ function removeDelegatedOutcome$1({ drawDefinition, event, matchUpId }) {
46427
46514
  return { error: MISSING_DRAW_DEFINITION };
46428
46515
  if (!matchUpId)
46429
46516
  return { error: MISSING_MATCHUP_ID };
46430
- const { matchUp } = findMatchUp$1({ drawDefinition, event, matchUpId });
46517
+ const { matchUp } = findDrawMatchUp({ drawDefinition, event, matchUpId });
46431
46518
  if (!matchUp)
46432
46519
  return { error: MATCHUP_NOT_FOUND };
46433
46520
  return removeExtension$1({
@@ -46941,7 +47028,7 @@ function setDelegatedOutcome$1({
46941
47028
  if (!matchUp && !matchUpId)
46942
47029
  return { error: MISSING_MATCHUP };
46943
47030
  if (!matchUp) {
46944
- const result = findMatchUp$1({
47031
+ const result = findDrawMatchUp({
46945
47032
  drawDefinition,
46946
47033
  matchUpId
46947
47034
  });
@@ -46989,7 +47076,7 @@ function validDrawPosition(drawPosition) {
46989
47076
  function disableTieAutoCalc$1({ drawDefinition, matchUpId, event }) {
46990
47077
  if (!drawDefinition)
46991
47078
  return { error: MISSING_DRAW_DEFINITION };
46992
- const { matchUp } = findMatchUp$1({
47079
+ const { matchUp } = findDrawMatchUp({
46993
47080
  drawDefinition,
46994
47081
  matchUpId,
46995
47082
  event
@@ -47008,7 +47095,7 @@ function enableTieAutoCalc$1({
47008
47095
  }) {
47009
47096
  if (!drawDefinition)
47010
47097
  return { error: MISSING_DRAW_DEFINITION };
47011
- const { matchUp } = findMatchUp$1({
47098
+ const { matchUp } = findDrawMatchUp({
47012
47099
  drawDefinition,
47013
47100
  matchUpId,
47014
47101
  event
@@ -47158,7 +47245,7 @@ const matchUpGovernor = {
47158
47245
  removeDelegatedOutcome: removeDelegatedOutcome$1,
47159
47246
  drawMatic: drawMatic$1,
47160
47247
  addMatchUpOfficial: addMatchUpOfficial$2,
47161
- findMatchUp: publicFindMatchUp$1,
47248
+ findMatchUp: publicFindDrawMatchUp,
47162
47249
  getRoundMatchUps: getRoundMatchUps$1,
47163
47250
  validDrawPositions,
47164
47251
  validateScore
@@ -52715,14 +52802,14 @@ function getTieMatchUpContext({
52715
52802
  if (!event)
52716
52803
  return { error: EVENT_NOT_FOUND };
52717
52804
  const matchUpsMap = getMatchUpsMap({ drawDefinition });
52718
- const { matchUp: tieMatchUp } = findMatchUp$1({
52805
+ const { matchUp: tieMatchUp } = findDrawMatchUp({
52719
52806
  matchUpId: tieMatchUpId,
52720
52807
  drawDefinition,
52721
52808
  matchUpsMap
52722
52809
  });
52723
52810
  if (!tieMatchUp)
52724
52811
  return { error: MATCHUP_NOT_FOUND };
52725
- const { matchUp: inContextTieMatchUp, structure } = findMatchUp$1({
52812
+ const { matchUp: inContextTieMatchUp, structure } = findDrawMatchUp({
52726
52813
  tournamentParticipants: tournamentRecord.participants,
52727
52814
  matchUpId: tieMatchUpId,
52728
52815
  inContext: true,
@@ -52755,12 +52842,12 @@ function getTieMatchUpContext({
52755
52842
  participantIds
52756
52843
  }
52757
52844
  });
52758
- const { matchUp: dualMatchUp } = findMatchUp$1({
52845
+ const { matchUp: dualMatchUp } = findDrawMatchUp({
52759
52846
  matchUpId: matchUpTieId,
52760
52847
  drawDefinition,
52761
52848
  matchUpsMap
52762
52849
  });
52763
- const { matchUp: inContextDualMatchUp } = findMatchUp$1({
52850
+ const { matchUp: inContextDualMatchUp } = findDrawMatchUp({
52764
52851
  matchUpId: matchUpTieId,
52765
52852
  inContext: true,
52766
52853
  drawDefinition,
@@ -52818,9 +52905,9 @@ function assignTieMatchUpParticipantId(params) {
52818
52905
  if (allTieIndividualParticipantIds?.includes(participantId)) {
52819
52906
  return decorateResult({ result: { ...SUCCESS }, stack });
52820
52907
  }
52821
- teamParticipantId = teamParticipantId || params.sideNumber && inContextDualMatchUp?.sides?.find(
52908
+ teamParticipantId = teamParticipantId ?? (params.sideNumber ? inContextDualMatchUp?.sides?.find(
52822
52909
  (side) => side.sideNumber === params.sideNumber
52823
- )?.participantId;
52910
+ )?.participantId : void 0);
52824
52911
  const participantToAssign = getParticipants$1({
52825
52912
  participantFilters: { participantIds: [participantId] },
52826
52913
  tournamentRecord
@@ -52833,8 +52920,9 @@ function assignTieMatchUpParticipantId(params) {
52833
52920
  drawDefinition,
52834
52921
  event
52835
52922
  });
52836
- const matchUpActionsPolicy = params.policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS] || appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS] || POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
52837
- if (matchUpActionsPolicy?.participants?.enforceGender && [MALE, FEMALE].includes(inContextTieMatchUp?.gender) && inContextTieMatchUp?.gender !== participantToAssign.person?.sex) {
52923
+ const matchUpActionsPolicy = params.policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
52924
+ const genderEnforced = (params.enforceGender ?? matchUpActionsPolicy?.participants?.enforceGender) !== false;
52925
+ if (genderEnforced && [MALE, FEMALE].includes(inContextTieMatchUp?.gender) && inContextTieMatchUp?.gender !== participantToAssign.person?.sex) {
52838
52926
  return { error: INVALID_PARTICIPANT, info: "Gender mismatch" };
52839
52927
  }
52840
52928
  const { individualParticipantIds, participantType } = participantToAssign;
@@ -52861,7 +52949,7 @@ function assignTieMatchUpParticipantId(params) {
52861
52949
  const teamSide = inContextTieMatchUp?.sides?.find(
52862
52950
  (side) => side.drawPosition === teamDrawPosition
52863
52951
  );
52864
- const sideNumber = params.sideNumber || teamSide?.sideNumber;
52952
+ const sideNumber = params.sideNumber ?? teamSide?.sideNumber;
52865
52953
  if (!tieFormat) {
52866
52954
  return { error: MISSING_TIE_FORMAT };
52867
52955
  }
@@ -52870,27 +52958,13 @@ function assignTieMatchUpParticipantId(params) {
52870
52958
  );
52871
52959
  if (!collectionDefinition)
52872
52960
  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
- }
52961
+ ensureSideLineUps({
52962
+ tournamentId: tournamentRecord.tournamentId,
52963
+ eventId: event.eventId,
52964
+ inContextDualMatchUp,
52965
+ drawDefinition,
52966
+ dualMatchUp
52967
+ });
52894
52968
  const dualMatchUpSide = dualMatchUp?.sides?.find(
52895
52969
  (side) => side.sideNumber === sideNumber
52896
52970
  );
@@ -52921,7 +52995,7 @@ function assignTieMatchUpParticipantId(params) {
52921
52995
  if (removeResult.error)
52922
52996
  return decorateResult({ result: removeResult, stack });
52923
52997
  const { modifiedLineUp } = removeResult;
52924
- let deleteParticipantId;
52998
+ let deletedParticipantId;
52925
52999
  if (matchUpType === DOUBLES$1) {
52926
53000
  if (participantType !== PAIR) {
52927
53001
  let result = updateLineUp({
@@ -52940,7 +53014,7 @@ function assignTieMatchUpParticipantId(params) {
52940
53014
  });
52941
53015
  if (result.error)
52942
53016
  return result;
52943
- deleteParticipantId = result.deleteParticipantId;
53017
+ deletedParticipantId = result.deletedParticipantId;
52944
53018
  if (dualMatchUpSide)
52945
53019
  dualMatchUpSide.lineUp = modifiedLineUp;
52946
53020
  if (dualMatchUp) {
@@ -52986,9 +53060,9 @@ function assignTieMatchUpParticipantId(params) {
52986
53060
  context: stack,
52987
53061
  drawDefinition
52988
53062
  });
52989
- if (deleteParticipantId) {
53063
+ if (deletedParticipantId) {
52990
53064
  const { error } = deleteParticipants({
52991
- participantIds: [deleteParticipantId],
53065
+ participantIds: [deletedParticipantId],
52992
53066
  tournamentRecord
52993
53067
  });
52994
53068
  if (error)
@@ -52996,7 +53070,7 @@ function assignTieMatchUpParticipantId(params) {
52996
53070
  }
52997
53071
  return { ...SUCCESS, modifiedLineUp };
52998
53072
  function addParticipantId2Pair({ side }) {
52999
- let deleteParticipantId2;
53073
+ let deletedParticipantId2;
53000
53074
  if (!side.participant) {
53001
53075
  const newPairParticipant = {
53002
53076
  individualParticipantIds: [participantId],
@@ -53033,11 +53107,11 @@ function assignTieMatchUpParticipantId(params) {
53033
53107
  if (result.error)
53034
53108
  return result;
53035
53109
  } else {
53036
- deleteParticipantId2 = participant?.participantId;
53110
+ deletedParticipantId2 = participant?.participantId;
53037
53111
  }
53038
53112
  }
53039
53113
  }
53040
- return { ...SUCCESS, deleteParticipantId: deleteParticipantId2 };
53114
+ return { ...SUCCESS, deletedParticipantId: deletedParticipantId2 };
53041
53115
  }
53042
53116
  }
53043
53117
  function updateLineUp({
@@ -53182,10 +53256,12 @@ function generateLineUps(params) {
53182
53256
  participantIdPairs.push(participantIds2);
53183
53257
  });
53184
53258
  }
53185
- const lineUp = Object.keys(participantAssignments).map((participantId) => ({
53186
- collectionAssignments: participantAssignments[participantId],
53187
- participantId
53188
- }));
53259
+ const lineUp = Object.keys(participantAssignments).map(
53260
+ (participantId) => ({
53261
+ collectionAssignments: participantAssignments[participantId],
53262
+ participantId
53263
+ })
53264
+ );
53189
53265
  lineUps[teamParticipant.participantId] = lineUp;
53190
53266
  }
53191
53267
  const participantsToAdd = [];
@@ -53554,7 +53630,7 @@ function completeDrawMatchUps(params) {
53554
53630
  );
53555
53631
  if (teamParticipant) {
53556
53632
  const individualParticipantId = teamParticipant.individualParticipantIds?.[i];
53557
- assignTieMatchUpParticipantId({
53633
+ individualParticipantId && assignTieMatchUpParticipantId({
53558
53634
  teamParticipantId: teamParticipant.participantId,
53559
53635
  participantId: individualParticipantId,
53560
53636
  tournamentRecord,
@@ -55189,8 +55265,10 @@ function assignMatchUpSideParticipant({
55189
55265
  if (noSideNumberProvided)
55190
55266
  sideNumber = 1;
55191
55267
  if (![1, 2].includes(sideNumber))
55192
- return { error: INVALID_VALUES, sideNumber };
55193
- const { matchUp, structure } = findMatchUp$1({
55268
+ return decorateResult({
55269
+ result: { error: INVALID_VALUES, context: { sideNumber } }
55270
+ });
55271
+ const { matchUp, structure } = findDrawMatchUp({
55194
55272
  drawDefinition,
55195
55273
  matchUpId,
55196
55274
  event
@@ -55245,7 +55323,7 @@ function removeMatchUpSideParticipant({
55245
55323
  return { error: MISSING_VALUE };
55246
55324
  if (![1, 2].includes(sideNumber))
55247
55325
  return { error: INVALID_VALUES, sideNumber };
55248
- const { matchUp, structure } = findMatchUp$1({
55326
+ const { matchUp, structure } = findDrawMatchUp({
55249
55327
  drawDefinition,
55250
55328
  matchUpId,
55251
55329
  event
@@ -55320,35 +55398,22 @@ function replaceTieMatchUpParticipantId(params) {
55320
55398
  drawDefinition,
55321
55399
  event
55322
55400
  });
55323
- const matchUpActionsPolicy = appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS] || POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
55401
+ const matchUpActionsPolicy = params.policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
55324
55402
  const newParticipant = targetParticipants.find(
55325
55403
  ({ participantId }) => participantId === newParticipantId
55326
55404
  );
55327
- if (matchUpActionsPolicy?.participants?.enforceGender && [MALE, FEMALE].includes(inContextTieMatchUp?.gender) && inContextTieMatchUp?.gender !== newParticipant?.person?.sex) {
55405
+ const genderEnforced = (params.enforceGender ?? matchUpActionsPolicy?.participants?.enforceGender) !== false;
55406
+ if (genderEnforced && [MALE, FEMALE].includes(inContextTieMatchUp?.gender) && inContextTieMatchUp?.gender !== newParticipant?.person?.sex) {
55328
55407
  return { error: INVALID_PARTICIPANT, info: "Gender mismatch" };
55329
55408
  }
55330
55409
  const substitutionProcessCodes = matchUpActionsPolicy?.processCodes?.substitution;
55331
- const { extension } = findExtension$2({
55332
- element: drawDefinition,
55333
- name: LINEUPS
55410
+ ensureSideLineUps({
55411
+ tournamentId: tournamentRecord.tournamentId,
55412
+ eventId: event.eventId,
55413
+ inContextDualMatchUp,
55414
+ drawDefinition,
55415
+ dualMatchUp
55334
55416
  });
55335
- const lineUps = extension?.value || {};
55336
- if (!dualMatchUp?.sides?.length) {
55337
- const extractSideDetail = ({
55338
- displaySideNumber,
55339
- drawPosition,
55340
- sideNumber
55341
- }) => ({ drawPosition, sideNumber, displaySideNumber });
55342
- if (dualMatchUp) {
55343
- dualMatchUp.sides = inContextDualMatchUp?.sides?.map((side2) => {
55344
- const participantId = side2.participantId;
55345
- return {
55346
- ...extractSideDetail(side2),
55347
- lineUp: participantId && lineUps[participantId] || []
55348
- };
55349
- });
55350
- }
55351
- }
55352
55417
  const dualMatchUpSide = dualMatchUp?.sides?.find(
55353
55418
  ({ sideNumber }) => sideNumber === side.sideNumber
55354
55419
  );
@@ -55407,16 +55472,16 @@ function replaceTieMatchUpParticipantId(params) {
55407
55472
  const assignment = { collectionId, collectionPosition };
55408
55473
  if (substitution) {
55409
55474
  assignment.previousParticipantId = existingParticipantId;
55410
- assignment.substitutionOrder = (substitutionOrder || 0) + 1;
55475
+ assignment.substitutionOrder = (substitutionOrder ?? 0) + 1;
55411
55476
  }
55412
55477
  modifiedCompetitor.collectionAssignments.push(assignment);
55413
55478
  }
55414
55479
  return modifiedCompetitor;
55415
- }) || [];
55480
+ }) ?? [];
55416
55481
  if (!newParticipantIdInLineUp) {
55417
55482
  const collectionAssignment = { collectionId, collectionPosition };
55418
55483
  if (substitution) {
55419
- collectionAssignment.substitutionOrder = (substitutionOrder || 0) + 1;
55484
+ collectionAssignment.substitutionOrder = (substitutionOrder ?? 0) + 1;
55420
55485
  collectionAssignment.previousParticipantId = existingParticipantId;
55421
55486
  }
55422
55487
  const assignment = {
@@ -55488,7 +55553,7 @@ function replaceTieMatchUpParticipantId(params) {
55488
55553
  }
55489
55554
  if (substitution || side.substitutions?.length === 1) {
55490
55555
  if (substitution) {
55491
- const processCodes = tieMatchUp?.processCodes || [];
55556
+ const processCodes = tieMatchUp?.processCodes ?? [];
55492
55557
  if (substitutionProcessCodes)
55493
55558
  processCodes.push(...substitutionProcessCodes);
55494
55559
  if (tieMatchUp)
@@ -55534,7 +55599,7 @@ function removeTieMatchUpParticipantId(params) {
55534
55599
  drawDefinition,
55535
55600
  event
55536
55601
  });
55537
- const matchUpActionsPolicy = appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS] || POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
55602
+ const matchUpActionsPolicy = params.policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
55538
55603
  const substitutionProcessCodes = matchUpActionsPolicy?.processCodes?.substitution;
55539
55604
  const {
55540
55605
  inContextDualMatchUp,
@@ -55573,25 +55638,13 @@ function removeTieMatchUpParticipantId(params) {
55573
55638
  return decorateResult({ result: { error: INVALID_PARTICIPANT }, stack });
55574
55639
  }
55575
55640
  const participantIds = participantToRemove.participantType === INDIVIDUAL ? [participantId] : participantToRemove.individualParticipantIds;
55576
- if (!dualMatchUp?.sides?.length) {
55577
- const { extension } = findExtension$2({
55578
- element: drawDefinition,
55579
- name: LINEUPS
55580
- });
55581
- const lineUps = extension?.value || {};
55582
- const extractSideDetail = ({
55583
- displaySideNumber,
55584
- drawPosition,
55585
- sideNumber
55586
- }) => ({ drawPosition, sideNumber, displaySideNumber });
55587
- dualMatchUp.sides = inContextDualMatchUp?.sides?.map((side2) => {
55588
- const participantId2 = side2.participantId;
55589
- return {
55590
- ...extractSideDetail(side2),
55591
- lineUp: participantId2 && lineUps[participantId2] || []
55592
- };
55593
- });
55594
- }
55641
+ ensureSideLineUps({
55642
+ tournamentId: tournamentRecord.tournamentId,
55643
+ eventId: event.eventId,
55644
+ inContextDualMatchUp,
55645
+ drawDefinition,
55646
+ dualMatchUp
55647
+ });
55595
55648
  let dualMatchUpSide = dualMatchUp.sides?.find(
55596
55649
  ({ sideNumber }) => sideNumber === side.sideNumber
55597
55650
  );
@@ -55611,8 +55664,9 @@ function removeTieMatchUpParticipantId(params) {
55611
55664
  );
55612
55665
  }
55613
55666
  if (!dualMatchUpSide) {
55614
- console.log({ teamParticipantId, teamParticipants });
55615
- return { error: PARTICIPANT_NOT_FOUND, participantId };
55667
+ return decorateResult({
55668
+ result: { error: PARTICIPANT_NOT_FOUND, context: { participantId } }
55669
+ });
55616
55670
  }
55617
55671
  const { modifiedLineUp, previousParticipantIds } = removeCollectionAssignments({
55618
55672
  collectionPosition,
@@ -56169,24 +56223,34 @@ function addEventEntryPairs({
56169
56223
  }
56170
56224
 
56171
56225
  function checkValidEntries({
56172
- enforceGender = true,
56173
56226
  consideredEntries,
56227
+ policyDefinitions,
56174
56228
  tournamentRecord,
56229
+ appliedPolicies,
56230
+ participantMap,
56231
+ enforceGender,
56175
56232
  participants,
56176
56233
  event
56177
56234
  }) {
56178
- participants = participants || tournamentRecord?.participants;
56235
+ if ((!participants || !participantMap) && tournamentRecord) {
56236
+ ({ participants, participantMap } = getParticipants$1({
56237
+ tournamentRecord
56238
+ }));
56239
+ }
56179
56240
  if (!participants)
56180
56241
  return { error: MISSING_PARTICIPANTS };
56181
56242
  if (!Array.isArray(participants))
56182
56243
  return { error: INVALID_VALUES };
56183
56244
  if (!event)
56184
56245
  return { error: MISSING_EVENT };
56246
+ const matchUpActionsPolicy = policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
56247
+ const genderEnforced = (enforceGender ?? matchUpActionsPolicy?.participants?.enforceGender) !== false;
56185
56248
  const { eventType, gender: eventGender } = event;
56186
- const participantType = eventType === TEAM_EVENT && TEAM || eventType === DOUBLES_EVENT && PAIR || INDIVIDUAL;
56249
+ const isDoubles = eventType === DOUBLES_EVENT;
56250
+ const participantType = eventType === TEAM_EVENT && TEAM || isDoubles && PAIR || INDIVIDUAL;
56187
56251
  const entryStatusMap = Object.assign(
56188
56252
  {},
56189
- ...(consideredEntries || event.entries || []).map((entry) => ({
56253
+ ...(consideredEntries ?? event.entries ?? []).map((entry) => ({
56190
56254
  [entry.participantId]: entry.entryStatus
56191
56255
  }))
56192
56256
  );
@@ -56198,9 +56262,14 @@ function checkValidEntries({
56198
56262
  const entryStatus = entryStatusMap[participant.participantId];
56199
56263
  const ungroupedParticipant = eventType && [TypeEnum.Doubles, TypeEnum.Team].includes(eventType) && participant.participantType === INDIVIDUAL && (isUngrouped(entryStatus) || entryStatus === WITHDRAWN);
56200
56264
  const mismatch = participant.participantType !== participantType && !ungroupedParticipant;
56265
+ const pairGender = !mismatch && isDoubles && unique(
56266
+ participant?.individualParticipantIds?.map((id) => participantMap?.[id]?.participant?.person?.sex).filter(Boolean) ?? []
56267
+ );
56268
+ const validPairGender = !eventGender || !pairGender?.length || GenderEnum.Any === eventGender || [GenderEnum.Male, GenderEnum.Female].includes(eventGender) && pairGender[0] === eventGender || GenderEnum.Mixed === eventGender && (pairGender.length == 1 && participant.individualParticipantIds?.length === 1 || pairGender.length === 2);
56201
56269
  const personGender = participant?.person?.sex;
56202
- const wrongGender = enforceGender && eventGender && eventType === TypeEnum.Singles && [GenderEnum.Male, GenderEnum.Female].includes(eventGender) && personGender !== eventGender;
56203
- return mismatch || wrongGender;
56270
+ const validPersonGender = !participant?.person || !eventGender || [GenderEnum.Any, GenderEnum.Mixed].includes(eventGender) || [GenderEnum.Male, GenderEnum.Female].includes(eventGender) && personGender === eventGender;
56271
+ const validGender = !genderEnforced || validPairGender && validPersonGender;
56272
+ return mismatch || !validGender;
56204
56273
  });
56205
56274
  if (invalidEntries.length) {
56206
56275
  const invalidParticipantIds = invalidEntries.map(
@@ -56208,7 +56277,7 @@ function checkValidEntries({
56208
56277
  );
56209
56278
  return { error: INVALID_ENTRIES, invalidParticipantIds };
56210
56279
  }
56211
- return { ...SUCCESS };
56280
+ return { ...SUCCESS, valid: true };
56212
56281
  }
56213
56282
 
56214
56283
  function assignSeedPositions(params) {
@@ -57824,7 +57893,7 @@ function substituteParticipant$1({
57824
57893
  return { error: MISSING_MATCHUP_ID };
57825
57894
  if (!existingParticipantId || !substituteParticipantId)
57826
57895
  return decorateResult({ result: { error: MISSING_PARTICIPANT_ID }, stack });
57827
- const { matchUp } = findMatchUp$1({
57896
+ const { matchUp } = findDrawMatchUp({
57828
57897
  drawDefinition,
57829
57898
  matchUpId,
57830
57899
  event
@@ -58442,7 +58511,7 @@ function applyLineUps({
58442
58511
  return { error: INVALID_VALUES, lineUps };
58443
58512
  const stack = "applyLineUps";
58444
58513
  const tournamentParticipants = tournamentRecord.participants || [];
58445
- let result = findMatchUp$1({
58514
+ let result = findDrawMatchUp({
58446
58515
  tournamentParticipants,
58447
58516
  inContext: true,
58448
58517
  drawDefinition,
@@ -58547,7 +58616,7 @@ function applyLineUps({
58547
58616
  }
58548
58617
  if (!Object.keys(sideAssignments).length)
58549
58618
  return { error: VALUE_UNCHANGED };
58550
- result = findMatchUp$1({ drawDefinition, matchUpId });
58619
+ result = findDrawMatchUp({ drawDefinition, matchUpId });
58551
58620
  if (result.error)
58552
58621
  return result;
58553
58622
  if (!result.matchUp)
@@ -58888,7 +58957,7 @@ function generateDrawDefinition(params) {
58888
58957
  }).appliedPolicies ?? {};
58889
58958
  const drawTypeCoercion = params.drawTypeCoercion ?? appliedPolicies?.[POLICY_TYPE_DRAWS]?.drawTypeCoercion ?? true;
58890
58959
  const drawType = drawTypeCoercion && params.drawSize === 2 && DrawTypeEnum.SingleElimination || params.drawType || DrawTypeEnum.SingleElimination;
58891
- const { participants } = getParticipants$1({
58960
+ const { participants, participantMap } = getParticipants$1({
58892
58961
  withIndividualParticipants: true,
58893
58962
  tournamentRecord
58894
58963
  });
@@ -58907,6 +58976,8 @@ function generateDrawDefinition(params) {
58907
58976
  const consideredEntries = (qualifyingOnly && [] || drawEntries || (considerEventEntries ? eventEntries : [])).filter(({ entryStage }) => !entryStage || entryStage === MAIN);
58908
58977
  const validEntriesResult = event && participants && checkValidEntries({
58909
58978
  consideredEntries,
58979
+ appliedPolicies,
58980
+ participantMap,
58910
58981
  enforceGender,
58911
58982
  participants,
58912
58983
  event
@@ -64871,6 +64942,7 @@ const utilities = {
64871
64942
  unique,
64872
64943
  UUID,
64873
64944
  UUIDS,
64945
+ validateCategory,
64874
64946
  validateTieFormat,
64875
64947
  visualizeScheduledMatchUps
64876
64948
  };