tods-competition-factory 1.6.26 → 1.6.28

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.
@@ -1463,6 +1463,7 @@ type GenerateDrawDefinitionArgs = {
1463
1463
  qualifyingProfiles?: any[];
1464
1464
  qualifyingOnly?: boolean;
1465
1465
  drawType?: DrawTypeEnum;
1466
+ enforceGender?: boolean;
1466
1467
  matchUpFormat?: string;
1467
1468
  matchUpType?: TypeEnum;
1468
1469
  tieFormatName?: string;
@@ -1382,6 +1382,7 @@ function findPolicy({
1382
1382
 
1383
1383
  const POLICY_TYPE_COMPETITIVE_BANDS = "competitiveBands";
1384
1384
  const POLICY_TYPE_ROUND_ROBIN_TALLY = "roundRobinTally";
1385
+ const POLICY_TYPE_MATCHUP_ACTIONS = "matchUpActions";
1385
1386
  const POLICY_TYPE_ROUND_NAMING = "roundNaming";
1386
1387
  const POLICY_TYPE_PARTICIPANT = "participant";
1387
1388
  const POLICY_TYPE_SCHEDULING = "scheduling";
@@ -16224,6 +16225,7 @@ const matchUpFormatCode = {
16224
16225
  };
16225
16226
 
16226
16227
  function validateTieFormat(params) {
16228
+ const checkGender = !!(params?.enforceGender !== false && params?.gender);
16227
16229
  const checkCollectionIds = params?.checkCollectionIds;
16228
16230
  const tieFormat = params?.tieFormat;
16229
16231
  const stack = "validateTieFormat";
@@ -16232,9 +16234,9 @@ function validateTieFormat(params) {
16232
16234
  errors.push("tieFormat must be an object");
16233
16235
  return decorateResult({
16234
16236
  result: {
16237
+ context: { tieFormat, errors },
16235
16238
  error: INVALID_TIE_FORMAT,
16236
- stack,
16237
- context: { tieFormat, errors }
16239
+ stack
16238
16240
  }
16239
16241
  });
16240
16242
  }
@@ -16242,9 +16244,9 @@ function validateTieFormat(params) {
16242
16244
  errors.push("tieFormat.winCriteria must be an object");
16243
16245
  return decorateResult({
16244
16246
  result: {
16247
+ context: { tieFormat, errors },
16245
16248
  error: INVALID_TIE_FORMAT,
16246
- stack,
16247
- context: { tieFormat, errors }
16249
+ stack
16248
16250
  }
16249
16251
  });
16250
16252
  }
@@ -16252,9 +16254,9 @@ function validateTieFormat(params) {
16252
16254
  errors.push(mustBeAnArray("tieFormat.collectionDefinitions"));
16253
16255
  return decorateResult({
16254
16256
  result: {
16257
+ context: { tieFormat, errors },
16255
16258
  error: INVALID_TIE_FORMAT,
16256
- stack,
16257
- context: { tieFormat, errors }
16259
+ stack
16258
16260
  }
16259
16261
  });
16260
16262
  }
@@ -16265,8 +16267,10 @@ function validateTieFormat(params) {
16265
16267
  if ((setValue || scoreValue) && !collectionValue)
16266
16268
  aggregateValueImperative = true;
16267
16269
  const { valid: valid2, errors: collectionDefinitionErrors } = validateCollectionDefinition({
16270
+ referenceGender: params.gender,
16268
16271
  collectionDefinition,
16269
- checkCollectionIds
16272
+ checkCollectionIds,
16273
+ checkGender
16270
16274
  });
16271
16275
  if (valid2) {
16272
16276
  return true;
@@ -16312,7 +16316,9 @@ function validateTieFormat(params) {
16312
16316
  }
16313
16317
  function validateCollectionDefinition({
16314
16318
  collectionDefinition,
16315
- checkCollectionIds
16319
+ checkCollectionIds,
16320
+ referenceGender,
16321
+ checkGender
16316
16322
  }) {
16317
16323
  const errors = [];
16318
16324
  if (typeof collectionDefinition !== "object") {
@@ -16331,19 +16337,17 @@ function validateCollectionDefinition({
16331
16337
  matchUpValue,
16332
16338
  matchUpType,
16333
16339
  scoreValue,
16334
- setValue
16340
+ setValue,
16341
+ gender
16335
16342
  } = collectionDefinition;
16336
16343
  if (checkCollectionIds && typeof collectionId !== "string") {
16337
16344
  errors.push(`collectionId is not type string: ${collectionId}`);
16338
- return { errors };
16339
16345
  }
16340
16346
  if (typeof matchUpCount !== "number") {
16341
16347
  errors.push(`matchUpCount is not type number: ${matchUpCount}`);
16342
- return { errors };
16343
16348
  }
16344
16349
  if (matchUpType && ![TypeEnum.Singles, TypeEnum.Doubles].includes(matchUpType)) {
16345
16350
  errors.push(`matchUpType must be SINGLES or DOUBLES: ${matchUpType}`);
16346
- return { errors };
16347
16351
  }
16348
16352
  const valueDeclarations = [!!collectionValueProfiles?.length].concat(
16349
16353
  [matchUpValue, collectionValue, scoreValue, setValue].map(
@@ -16354,15 +16358,12 @@ function validateCollectionDefinition({
16354
16358
  errors.push(
16355
16359
  "Missing value definition for matchUps: matchUpValue, collectionValue, or collectionValueProfiles"
16356
16360
  );
16357
- return { errors };
16358
16361
  }
16359
16362
  if (matchUpValue && typeof matchUpValue !== "number") {
16360
16363
  errors.push(`matchUpValue is not type number: ${matchUpValue}`);
16361
- return { errors };
16362
16364
  }
16363
16365
  if (collectionValue && typeof collectionValue !== "number") {
16364
16366
  errors.push(`collectionValue is not type number: ${collectionValue}`);
16365
- return { errors };
16366
16367
  }
16367
16368
  if (collectionValueProfiles) {
16368
16369
  const result = validateCollectionValueProfile({
@@ -16371,17 +16372,19 @@ function validateCollectionDefinition({
16371
16372
  });
16372
16373
  if (result.errors) {
16373
16374
  errors.push(...result.errors);
16374
- return { errors };
16375
16375
  }
16376
16376
  }
16377
16377
  if (collectionGroupNumber && typeof collectionGroupNumber !== "number") {
16378
- errors.push(`collectionValue is not type number: ${collectionValue}`);
16379
- return { errors };
16378
+ errors.push(`collectionGroupNumber is not type number: ${collectionValue}`);
16380
16379
  }
16381
16380
  if (matchUpFormat && !matchUpFormatCode.isValid(matchUpFormat)) {
16382
16381
  errors.push(`Invalid matchUpFormat: ${matchUpFormat}`);
16383
- return { errors };
16384
16382
  }
16383
+ if (checkGender && referenceGender && gender && [GenderEnum.Male, GenderEnum.Female].includes(referenceGender) && referenceGender !== gender) {
16384
+ errors.push(`Invalid gender: ${gender}`);
16385
+ }
16386
+ if (errors.length)
16387
+ return { errors };
16385
16388
  return { valid: true };
16386
16389
  }
16387
16390
  function checkTieFormat(tieFormat) {
@@ -20856,8 +20859,8 @@ function isUngrouped(entryStatus) {
20856
20859
  }
20857
20860
 
20858
20861
  function checkValidEntries({
20862
+ enforceGender = true,
20859
20863
  participants,
20860
- ignoreGender,
20861
20864
  event
20862
20865
  }) {
20863
20866
  if (!participants)
@@ -20883,7 +20886,7 @@ function checkValidEntries({
20883
20886
  const ungroupedParticipant = eventType && [TypeEnum.Doubles, TypeEnum.Team].includes(eventType) && participant.participantType === INDIVIDUAL && (isUngrouped(entryStatus) || entryStatus === WITHDRAWN);
20884
20887
  const mismatch = participant.participantType !== participantType && !ungroupedParticipant;
20885
20888
  const personGender = participant?.person?.sex;
20886
- const wrongGender = !ignoreGender && eventGender && eventType === TypeEnum.Singles && [GenderEnum.Male, GenderEnum.Female].includes(eventGender) && personGender !== eventGender;
20889
+ const wrongGender = enforceGender && eventGender && eventType === TypeEnum.Singles && [GenderEnum.Male, GenderEnum.Female].includes(eventGender) && personGender !== eventGender;
20887
20890
  return mismatch || wrongGender;
20888
20891
  });
20889
20892
  if (invalidEntries.length) {
@@ -22664,7 +22667,12 @@ function generateDrawDefinition(params) {
22664
22667
  tournamentRecord,
22665
22668
  inContext: true
22666
22669
  });
22667
- const validEntriesResult = event && participants && checkValidEntries({ event, participants });
22670
+ const appliedPolicies = getAppliedPolicies({
22671
+ tournamentRecord,
22672
+ event
22673
+ }).appliedPolicies ?? {};
22674
+ const enforceGender = params.enforceGender ?? policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS]?.participants?.enforceGender ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS]?.participants?.enforceGender;
22675
+ const validEntriesResult = event && participants && checkValidEntries({ event, participants, enforceGender });
22668
22676
  if (validEntriesResult?.error)
22669
22677
  return decorateResult({ result: validEntriesResult, stack });
22670
22678
  const allowedDrawTypes = !ignoreAllowedDrawTypes && tournamentRecord && getAllowedDrawTypes({
@@ -22700,11 +22708,6 @@ function generateDrawDefinition(params) {
22700
22708
  (d) => d.drawId === params.drawId
22701
22709
  ) : void 0;
22702
22710
  let { tieFormat, matchUpFormat } = params;
22703
- if (tieFormat) {
22704
- const result = validateTieFormat({ tieFormat });
22705
- if (result.error)
22706
- return decorateResult({ result, stack });
22707
- }
22708
22711
  if (matchUpType === TEAM$2 && eventType === TEAM$2) {
22709
22712
  const existingMainTieFormat = existingDrawDefinition?.structures?.find(
22710
22713
  ({ stage }) => stage === MAIN
@@ -22724,6 +22727,15 @@ function generateDrawDefinition(params) {
22724
22727
  matchUpFormat = FORMAT_STANDARD;
22725
22728
  }
22726
22729
  }
22730
+ if (tieFormat) {
22731
+ const result = validateTieFormat({
22732
+ gender: event?.gender,
22733
+ enforceGender,
22734
+ tieFormat
22735
+ });
22736
+ if (result.error)
22737
+ return decorateResult({ result, stack });
22738
+ }
22727
22739
  const invalidDrawId = params.drawId && typeof params.drawId !== "string";
22728
22740
  if (invalidDrawId)
22729
22741
  return decorateResult({ result: { error: INVALID_VALUES }, stack });
@@ -22756,10 +22768,6 @@ function generateDrawDefinition(params) {
22756
22768
  drawDefinition.matchUpType = matchUpType;
22757
22769
  }
22758
22770
  }
22759
- const appliedPolicies = getAppliedPolicies({
22760
- tournamentRecord,
22761
- event
22762
- }).appliedPolicies ?? {};
22763
22771
  if (policyDefinitions) {
22764
22772
  if (typeof policyDefinitions !== "object") {
22765
22773
  return decorateResult({