tods-competition-factory 1.8.19 → 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.19";
2385
+ return "1.8.20";
2386
2386
  }
2387
2387
 
2388
2388
  function getObjectTieFormat(obj) {
@@ -2971,8 +2971,8 @@ function validateCollectionDefinition({
2971
2971
  if (checkGender && referenceGender && gender && [GenderEnum.Male, GenderEnum.Female].includes(referenceGender) && referenceGender !== gender) {
2972
2972
  errors.push(`Invalid gender: ${gender}`);
2973
2973
  return decorateResult({
2974
+ result: { error: INVALID_GENDER, errors },
2974
2975
  context: { referenceGender, gender },
2975
- result: { error: INVALID_GENDER },
2976
2976
  stack
2977
2977
  });
2978
2978
  }
@@ -29485,6 +29485,7 @@ function addCollectionDefinition$1({
29485
29485
  collectionDefinition,
29486
29486
  referenceCategory,
29487
29487
  tournamentRecord,
29488
+ policyDefinitions,
29488
29489
  enforceCategory,
29489
29490
  referenceGender,
29490
29491
  drawDefinition,
@@ -29503,11 +29504,11 @@ function addCollectionDefinition$1({
29503
29504
  drawDefinition,
29504
29505
  event
29505
29506
  }).appliedPolicies ?? {};
29506
- const matchUpActionsPolicy = appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS];
29507
+ const matchUpActionsPolicy = policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS];
29507
29508
  enforceCategory = enforceCategory ?? matchUpActionsPolicy?.participants?.enforceCategory;
29508
- enforceGender = enforceGender ?? matchUpActionsPolicy?.participants?.enforceGender;
29509
+ const genderEnforced = (enforceGender ?? matchUpActionsPolicy?.participants?.enforceGender) !== false;
29509
29510
  const checkCategory = !!((referenceCategory ?? event?.category) && enforceCategory !== false);
29510
- const checkGender = !!((referenceGender ?? event?.gender) && enforceGender !== false);
29511
+ const checkGender = !!((referenceGender ?? event?.gender) && genderEnforced);
29511
29512
  const validationResult = validateCollectionDefinition({
29512
29513
  referenceCategory: referenceCategory ?? event?.category,
29513
29514
  collectionDefinition,
@@ -36308,6 +36309,7 @@ function matchUpActions$2({
36308
36309
  inContextDrawMatchUps,
36309
36310
  tournamentRecord,
36310
36311
  drawDefinition,
36312
+ enforceGender,
36311
36313
  participantId,
36312
36314
  matchUpsMap,
36313
36315
  sideNumber,
@@ -36339,8 +36341,8 @@ function matchUpActions$2({
36339
36341
  event
36340
36342
  }).appliedPolicies ?? {};
36341
36343
  Object.assign(appliedPolicies, specifiedPolicyDefinitions ?? {});
36342
- const isAdHocMatchUp = isAdHoc({ drawDefinition, structure });
36343
36344
  const matchUpActionsPolicy = appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS] ?? POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
36345
+ const isAdHocMatchUp = isAdHoc({ drawDefinition, structure });
36344
36346
  const { enabledStructures } = getEnabledStructures({
36345
36347
  actionType: MATCHUP_ACTION,
36346
36348
  appliedPolicies,
@@ -36554,7 +36556,8 @@ function matchUpActions$2({
36554
36556
  );
36555
36557
  const assignedGender = inContextMatchUp.gender === MIXED && inContextMatchUp.sideNumber && inContextMatchUp.sides?.filter((side2) => side2.particiapntId).length === 1 && firstFoundSide?.participant?.person?.sex;
36556
36558
  const matchUpType = inContextMatchUp.matchUpType;
36557
- 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;
36558
36561
  const allParticipants = inContextMatchUp.sides?.flatMap(
36559
36562
  (side2) => side2.participant?.individualParticipants || side2.participant
36560
36563
  ).filter(Boolean);
@@ -36684,6 +36687,7 @@ function matchUpActions$1({
36684
36687
  policyDefinitions,
36685
36688
  tournamentRecord,
36686
36689
  drawDefinition,
36690
+ enforceGender,
36687
36691
  participantId,
36688
36692
  sideNumber,
36689
36693
  matchUpId,
@@ -36718,6 +36722,7 @@ function matchUpActions$1({
36718
36722
  tournamentParticipants: tournamentRecord.participants,
36719
36723
  policyDefinitions,
36720
36724
  drawDefinition,
36725
+ enforceGender,
36721
36726
  participantId,
36722
36727
  sideNumber,
36723
36728
  matchUpId,
@@ -36731,6 +36736,8 @@ function matchUpActions$1({
36731
36736
  function matchUpActions(params) {
36732
36737
  const {
36733
36738
  tournamentRecords,
36739
+ policyDefinitions,
36740
+ enforceGender,
36734
36741
  participantId,
36735
36742
  tournamentId,
36736
36743
  sideNumber,
@@ -36752,7 +36759,9 @@ function matchUpActions(params) {
36752
36759
  return result;
36753
36760
  return matchUpActions$1({
36754
36761
  drawDefinition: result.drawDefinition,
36762
+ policyDefinitions,
36755
36763
  tournamentRecord,
36764
+ enforceGender,
36756
36765
  participantId,
36757
36766
  sideNumber,
36758
36767
  matchUpId,
@@ -45417,9 +45426,10 @@ function addEventEntries(params) {
45417
45426
  const {
45418
45427
  entryStatus = DIRECT_ACCEPTANCE,
45419
45428
  autoEntryPositions = true,
45429
+ enforceGender = true,
45420
45430
  participantIds = [],
45421
45431
  entryStageSequence,
45422
- ignoreEventGender,
45432
+ policyDefinitions,
45423
45433
  entryStage = MAIN,
45424
45434
  tournamentRecord,
45425
45435
  ignoreStageSpace,
@@ -45441,6 +45451,9 @@ function addEventEntries(params) {
45441
45451
  }
45442
45452
  if (!event?.eventId)
45443
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;
45444
45457
  const addedParticipantIdEntries = [];
45445
45458
  const removedEntries = [];
45446
45459
  if (extensions && (!Array.isArray(extensions) || !extensions.every(isValidExtension)) || extension && !isValidExtension({ extension })) {
@@ -45452,14 +45465,14 @@ function addEventEntries(params) {
45452
45465
  });
45453
45466
  }
45454
45467
  const checkTypedParticipants = !!tournamentRecord;
45455
- const misMatchedGender = [];
45468
+ const mismatchedGender = [];
45456
45469
  let info;
45457
45470
  const typedParticipantIds = tournamentRecord?.participants?.filter((participant) => {
45458
45471
  if (!participantIds.includes(participant.participantId))
45459
45472
  return false;
45460
45473
  const validSingles = event.eventType === SINGLES$1 && participant.participantType === INDIVIDUAL && !isUngrouped(entryStatus);
45461
45474
  const validDoubles = event.eventType === DOUBLES$1 && participant.participantType === PAIR;
45462
- 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)) {
45463
45476
  return true;
45464
45477
  }
45465
45478
  if (validDoubles && !isUngrouped(entryStatus)) {
@@ -45468,8 +45481,8 @@ function addEventEntries(params) {
45468
45481
  if (event.eventType === DOUBLES$1 && participant.participantType === INDIVIDUAL && isUngrouped(entryStatus)) {
45469
45482
  return true;
45470
45483
  }
45471
- if (validSingles && event.gender && !ignoreEventGender && ![MIXED, ANY].includes(event.gender) && event.gender !== participant.person?.sex) {
45472
- misMatchedGender.push({
45484
+ if (validSingles && event.gender && genderEnforced && ![MIXED, ANY].includes(event.gender) && event.gender !== participant.person?.sex) {
45485
+ mismatchedGender.push({
45473
45486
  participantId: participant.participantId,
45474
45487
  sex: participant.person?.sex
45475
45488
  });
@@ -45551,7 +45564,7 @@ function addEventEntries(params) {
45551
45564
  const invalidParticipantIds = validParticipantIds.length !== participantIds.length;
45552
45565
  if (invalidParticipantIds)
45553
45566
  return decorateResult({
45554
- context: { misMatchedGender, gender: event.gender },
45567
+ context: { mismatchedGender, gender: event.gender },
45555
45568
  result: { error: INVALID_PARTICIPANT_IDS },
45556
45569
  stack
45557
45570
  });
@@ -52892,7 +52905,7 @@ function assignTieMatchUpParticipantId(params) {
52892
52905
  if (allTieIndividualParticipantIds?.includes(participantId)) {
52893
52906
  return decorateResult({ result: { ...SUCCESS }, stack });
52894
52907
  }
52895
- teamParticipantId = teamParticipantId || (params.sideNumber ? inContextDualMatchUp?.sides?.find(
52908
+ teamParticipantId = teamParticipantId ?? (params.sideNumber ? inContextDualMatchUp?.sides?.find(
52896
52909
  (side) => side.sideNumber === params.sideNumber
52897
52910
  )?.participantId : void 0);
52898
52911
  const participantToAssign = getParticipants$1({
@@ -52907,8 +52920,9 @@ function assignTieMatchUpParticipantId(params) {
52907
52920
  drawDefinition,
52908
52921
  event
52909
52922
  });
52910
- const matchUpActionsPolicy = params.policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS] || appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS] || POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
52911
- 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) {
52912
52926
  return { error: INVALID_PARTICIPANT, info: "Gender mismatch" };
52913
52927
  }
52914
52928
  const { individualParticipantIds, participantType } = participantToAssign;
@@ -52935,7 +52949,7 @@ function assignTieMatchUpParticipantId(params) {
52935
52949
  const teamSide = inContextTieMatchUp?.sides?.find(
52936
52950
  (side) => side.drawPosition === teamDrawPosition
52937
52951
  );
52938
- const sideNumber = params.sideNumber || teamSide?.sideNumber;
52952
+ const sideNumber = params.sideNumber ?? teamSide?.sideNumber;
52939
52953
  if (!tieFormat) {
52940
52954
  return { error: MISSING_TIE_FORMAT };
52941
52955
  }
@@ -55384,11 +55398,12 @@ function replaceTieMatchUpParticipantId(params) {
55384
55398
  drawDefinition,
55385
55399
  event
55386
55400
  });
55387
- 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];
55388
55402
  const newParticipant = targetParticipants.find(
55389
55403
  ({ participantId }) => participantId === newParticipantId
55390
55404
  );
55391
- 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) {
55392
55407
  return { error: INVALID_PARTICIPANT, info: "Gender mismatch" };
55393
55408
  }
55394
55409
  const substitutionProcessCodes = matchUpActionsPolicy?.processCodes?.substitution;
@@ -55457,16 +55472,16 @@ function replaceTieMatchUpParticipantId(params) {
55457
55472
  const assignment = { collectionId, collectionPosition };
55458
55473
  if (substitution) {
55459
55474
  assignment.previousParticipantId = existingParticipantId;
55460
- assignment.substitutionOrder = (substitutionOrder || 0) + 1;
55475
+ assignment.substitutionOrder = (substitutionOrder ?? 0) + 1;
55461
55476
  }
55462
55477
  modifiedCompetitor.collectionAssignments.push(assignment);
55463
55478
  }
55464
55479
  return modifiedCompetitor;
55465
- }) || [];
55480
+ }) ?? [];
55466
55481
  if (!newParticipantIdInLineUp) {
55467
55482
  const collectionAssignment = { collectionId, collectionPosition };
55468
55483
  if (substitution) {
55469
- collectionAssignment.substitutionOrder = (substitutionOrder || 0) + 1;
55484
+ collectionAssignment.substitutionOrder = (substitutionOrder ?? 0) + 1;
55470
55485
  collectionAssignment.previousParticipantId = existingParticipantId;
55471
55486
  }
55472
55487
  const assignment = {
@@ -55538,7 +55553,7 @@ function replaceTieMatchUpParticipantId(params) {
55538
55553
  }
55539
55554
  if (substitution || side.substitutions?.length === 1) {
55540
55555
  if (substitution) {
55541
- const processCodes = tieMatchUp?.processCodes || [];
55556
+ const processCodes = tieMatchUp?.processCodes ?? [];
55542
55557
  if (substitutionProcessCodes)
55543
55558
  processCodes.push(...substitutionProcessCodes);
55544
55559
  if (tieMatchUp)
@@ -55584,7 +55599,7 @@ function removeTieMatchUpParticipantId(params) {
55584
55599
  drawDefinition,
55585
55600
  event
55586
55601
  });
55587
- 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];
55588
55603
  const substitutionProcessCodes = matchUpActionsPolicy?.processCodes?.substitution;
55589
55604
  const {
55590
55605
  inContextDualMatchUp,
@@ -56208,24 +56223,34 @@ function addEventEntryPairs({
56208
56223
  }
56209
56224
 
56210
56225
  function checkValidEntries({
56211
- enforceGender = true,
56212
56226
  consideredEntries,
56227
+ policyDefinitions,
56213
56228
  tournamentRecord,
56229
+ appliedPolicies,
56230
+ participantMap,
56231
+ enforceGender,
56214
56232
  participants,
56215
56233
  event
56216
56234
  }) {
56217
- participants = participants || tournamentRecord?.participants;
56235
+ if ((!participants || !participantMap) && tournamentRecord) {
56236
+ ({ participants, participantMap } = getParticipants$1({
56237
+ tournamentRecord
56238
+ }));
56239
+ }
56218
56240
  if (!participants)
56219
56241
  return { error: MISSING_PARTICIPANTS };
56220
56242
  if (!Array.isArray(participants))
56221
56243
  return { error: INVALID_VALUES };
56222
56244
  if (!event)
56223
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;
56224
56248
  const { eventType, gender: eventGender } = event;
56225
- 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;
56226
56251
  const entryStatusMap = Object.assign(
56227
56252
  {},
56228
- ...(consideredEntries || event.entries || []).map((entry) => ({
56253
+ ...(consideredEntries ?? event.entries ?? []).map((entry) => ({
56229
56254
  [entry.participantId]: entry.entryStatus
56230
56255
  }))
56231
56256
  );
@@ -56237,9 +56262,14 @@ function checkValidEntries({
56237
56262
  const entryStatus = entryStatusMap[participant.participantId];
56238
56263
  const ungroupedParticipant = eventType && [TypeEnum.Doubles, TypeEnum.Team].includes(eventType) && participant.participantType === INDIVIDUAL && (isUngrouped(entryStatus) || entryStatus === WITHDRAWN);
56239
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);
56240
56269
  const personGender = participant?.person?.sex;
56241
- const wrongGender = enforceGender && eventGender && eventType === TypeEnum.Singles && [GenderEnum.Male, GenderEnum.Female].includes(eventGender) && personGender !== eventGender;
56242
- 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;
56243
56273
  });
56244
56274
  if (invalidEntries.length) {
56245
56275
  const invalidParticipantIds = invalidEntries.map(
@@ -56247,7 +56277,7 @@ function checkValidEntries({
56247
56277
  );
56248
56278
  return { error: INVALID_ENTRIES, invalidParticipantIds };
56249
56279
  }
56250
- return { ...SUCCESS };
56280
+ return { ...SUCCESS, valid: true };
56251
56281
  }
56252
56282
 
56253
56283
  function assignSeedPositions(params) {
@@ -58927,7 +58957,7 @@ function generateDrawDefinition(params) {
58927
58957
  }).appliedPolicies ?? {};
58928
58958
  const drawTypeCoercion = params.drawTypeCoercion ?? appliedPolicies?.[POLICY_TYPE_DRAWS]?.drawTypeCoercion ?? true;
58929
58959
  const drawType = drawTypeCoercion && params.drawSize === 2 && DrawTypeEnum.SingleElimination || params.drawType || DrawTypeEnum.SingleElimination;
58930
- const { participants } = getParticipants$1({
58960
+ const { participants, participantMap } = getParticipants$1({
58931
58961
  withIndividualParticipants: true,
58932
58962
  tournamentRecord
58933
58963
  });
@@ -58946,6 +58976,8 @@ function generateDrawDefinition(params) {
58946
58976
  const consideredEntries = (qualifyingOnly && [] || drawEntries || (considerEventEntries ? eventEntries : [])).filter(({ entryStage }) => !entryStage || entryStage === MAIN);
58947
58977
  const validEntriesResult = event && participants && checkValidEntries({
58948
58978
  consideredEntries,
58979
+ appliedPolicies,
58980
+ participantMap,
58949
58981
  enforceGender,
58950
58982
  participants,
58951
58983
  event