tods-competition-factory 1.8.44 → 1.8.46

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
@@ -2404,7 +2404,7 @@ const matchUpFormatCode = {
2404
2404
  };
2405
2405
 
2406
2406
  function factoryVersion() {
2407
- return "1.8.44";
2407
+ return "1.8.46";
2408
2408
  }
2409
2409
 
2410
2410
  function getObjectTieFormat(obj) {
@@ -2634,20 +2634,17 @@ var ParticipantTypeEnum = /* @__PURE__ */ ((ParticipantTypeEnum2) => {
2634
2634
 
2635
2635
  const mixedGenderError = "MIXED events can not contain mixed singles or { gender: ANY } collections";
2636
2636
  const anyMixedError = "events with { gender: ANY } can not contain MIXED singles collections";
2637
- function tieFormatGenderValidityCheck({
2638
- referenceEvent,
2639
- referenceGender,
2640
- matchUpType,
2641
- gender
2642
- }) {
2637
+ function tieFormatGenderValidityCheck(params) {
2643
2638
  const stack = "tieFormatGenderValidityCheck";
2639
+ const { referenceGender, matchUpType, gender } = params;
2644
2640
  if (referenceGender && gender && [GenderEnum.Male, GenderEnum.Female].includes(referenceGender) && referenceGender !== gender)
2645
2641
  return decorateResult({
2646
2642
  result: { valid: false, error: INVALID_GENDER },
2647
2643
  context: { gender },
2648
2644
  stack
2649
2645
  });
2650
- if (referenceGender === MIXED && (referenceEvent?.eventType !== TEAM$2 || gender === ANY || gender === MIXED && matchUpType !== TypeEnum.Doubles)) {
2646
+ const eventType = params.eventType ?? params.referenceEvent?.eventType;
2647
+ if (referenceGender === MIXED && (eventType !== TEAM$2 || gender === ANY || gender === MIXED && matchUpType !== TypeEnum.Doubles)) {
2651
2648
  return decorateResult({
2652
2649
  result: { error: INVALID_GENDER, valid: false },
2653
2650
  info: mixedGenderError,
@@ -2899,6 +2896,7 @@ function validateTieFormat(params) {
2899
2896
  const checkGender = !!(params?.enforceGender !== false && params?.gender);
2900
2897
  const checkCollectionIds = params?.checkCollectionIds;
2901
2898
  const tieFormat = params?.tieFormat;
2899
+ const event = params?.event;
2902
2900
  const stack = "validateTieFormat";
2903
2901
  const errors = [];
2904
2902
  if (!params || !tieFormat || typeof tieFormat !== "object") {
@@ -2934,10 +2932,12 @@ function validateTieFormat(params) {
2934
2932
  const { valid: valid2, errors: collectionDefinitionErrors } = validateCollectionDefinition({
2935
2933
  referenceCategory: params.category,
2936
2934
  referenceGender: params.gender,
2935
+ eventType: params.eventType,
2937
2936
  collectionDefinition,
2938
2937
  checkCollectionIds,
2939
2938
  checkCategory,
2940
- checkGender
2939
+ checkGender,
2940
+ event
2941
2941
  });
2942
2942
  if (valid2) {
2943
2943
  return true;
@@ -2984,6 +2984,7 @@ function validateCollectionDefinition({
2984
2984
  checkGender = true,
2985
2985
  referenceCategory,
2986
2986
  referenceGender,
2987
+ eventType,
2987
2988
  event
2988
2989
  }) {
2989
2990
  referenceGender = referenceGender ?? event?.gender;
@@ -3051,7 +3052,7 @@ function validateCollectionDefinition({
3051
3052
  }
3052
3053
  if (checkGender) {
3053
3054
  const result = tieFormatGenderValidityCheck({
3054
- referenceEvent: event,
3055
+ eventType: eventType ?? event?.eventType,
3055
3056
  referenceGender,
3056
3057
  matchUpType,
3057
3058
  gender
@@ -3083,8 +3084,15 @@ function validateCollectionDefinition({
3083
3084
  });
3084
3085
  return { valid: true };
3085
3086
  }
3086
- function checkTieFormat(tieFormat) {
3087
- const result = validateTieFormat({ tieFormat, checkCollectionIds: false });
3087
+ function checkTieFormat({
3088
+ tieFormat,
3089
+ eventType
3090
+ }) {
3091
+ const result = validateTieFormat({
3092
+ checkCollectionIds: false,
3093
+ eventType,
3094
+ tieFormat
3095
+ });
3088
3096
  if (result.error)
3089
3097
  return result;
3090
3098
  for (const collectionDefinition of tieFormat.collectionDefinitions) {
@@ -8748,7 +8756,7 @@ function generateTieMatchUpScore(params) {
8748
8756
  const tieFormat = resolveTieFormat({ matchUp, drawDefinition, structure, event })?.tieFormat || params?.tieFormat;
8749
8757
  if (!tieFormat)
8750
8758
  return { error: MISSING_TIE_FORMAT };
8751
- const result = validateTieFormat({ tieFormat });
8759
+ const result = validateTieFormat({ tieFormat, eventType: event?.eventType });
8752
8760
  if (result.error)
8753
8761
  return result;
8754
8762
  const collectionDefinitions = tieFormat?.collectionDefinitions || [];
@@ -9053,7 +9061,7 @@ function ensureSideLineUps({
9053
9061
  dualMatchUp,
9054
9062
  eventId
9055
9063
  }) {
9056
- if (dualMatchUp && !dualMatchUp?.sides?.length) {
9064
+ if (dualMatchUp) {
9057
9065
  if (!inContextDualMatchUp) {
9058
9066
  inContextDualMatchUp = findDrawMatchUp({
9059
9067
  matchUpId: dualMatchUp.matchUpId,
@@ -9071,11 +9079,17 @@ function ensureSideLineUps({
9071
9079
  drawPosition,
9072
9080
  sideNumber
9073
9081
  }) => ({ drawPosition, sideNumber, displaySideNumber });
9074
- dualMatchUp.sides = inContextDualMatchUp?.sides?.map((side) => {
9075
- const participantId = side.participantId;
9082
+ dualMatchUp.sides = inContextDualMatchUp?.sides?.map((contextSide) => {
9083
+ const participantId = contextSide.participantId;
9084
+ const referenceLineUp = participantId && lineUps[participantId] || void 0;
9085
+ const { lineUp: noContextLineUp, ...noContextSideDetail } = dualMatchUp.sides?.find(
9086
+ ({ sideNumber }) => sideNumber === contextSide.sideNumber
9087
+ ) ?? {};
9088
+ const lineUp = noContextLineUp?.length ? noContextLineUp : referenceLineUp;
9076
9089
  return {
9077
- ...extractSideDetail(side),
9078
- lineUp: participantId && lineUps[participantId] || []
9090
+ ...extractSideDetail(contextSide),
9091
+ ...noContextSideDetail,
9092
+ lineUp
9079
9093
  };
9080
9094
  });
9081
9095
  modifyMatchUpNotice({
@@ -23853,6 +23867,15 @@ function getParticipantEntries(params) {
23853
23867
  individualParticipantIds?.forEach(addDrawEntry);
23854
23868
  }
23855
23869
  }
23870
+ const stages = (drawDefinition?.structures ?? []).reduce(
23871
+ (stages2, structure) => {
23872
+ if (!stages2.includes(structure.stage))
23873
+ stages2.push(structure.stage);
23874
+ return stages2;
23875
+ },
23876
+ []
23877
+ );
23878
+ const linksCount = (drawDefinition?.links ?? []).length;
23856
23879
  derivedDrawInfo[drawId] = {
23857
23880
  qualifyingPositionAssignments,
23858
23881
  qualifyingSeedAssignments,
@@ -23862,11 +23885,13 @@ function getParticipantEntries(params) {
23862
23885
  orderedStructureIds,
23863
23886
  mainSeedingMap,
23864
23887
  flightNumber,
23888
+ linksCount,
23865
23889
  drawOrder,
23866
23890
  drawName,
23867
23891
  drawType,
23868
23892
  drawSize,
23869
- drawId
23893
+ drawId,
23894
+ stages
23870
23895
  // qualifyingDrawSize,
23871
23896
  };
23872
23897
  }
@@ -31555,6 +31580,13 @@ function setMatchUpStatus$2(params) {
31555
31580
  score: score2
31556
31581
  });
31557
31582
  }
31583
+ ensureSideLineUps({
31584
+ tournamentId: tournamentRecord?.tournamentId,
31585
+ inContextDualMatchUp: inContextMatchUp,
31586
+ eventId: event?.eventId,
31587
+ drawDefinition,
31588
+ dualMatchUp: matchUp
31589
+ });
31558
31590
  }
31559
31591
  if (matchUp.matchUpType === TEAM$2 && matchUpStatus && [
31560
31592
  AWAITING_RESULT
@@ -33316,7 +33348,10 @@ function modifyCollectionDefinition$1({
33316
33348
  modifications.push({ collectionId, gender });
33317
33349
  }
33318
33350
  const modifiedTieFormat = definedAttributes(tieFormat);
33319
- result = validateTieFormat({ tieFormat: modifiedTieFormat });
33351
+ result = validateTieFormat({
33352
+ tieFormat: modifiedTieFormat,
33353
+ eventType: event?.eventType
33354
+ });
33320
33355
  if (result.error) {
33321
33356
  return decorateResult({ result, stack });
33322
33357
  }
@@ -33587,7 +33622,8 @@ function removeCollectionDefinition$1({
33587
33622
  matchUp = matchUp ?? result?.matchUp;
33588
33623
  const existingTieFormat = result?.tieFormat;
33589
33624
  const tieFormat = copyTieFormat(existingTieFormat);
33590
- result = validateTieFormat({ tieFormat });
33625
+ const eventType = event?.eventType;
33626
+ result = validateTieFormat({ tieFormat, eventType });
33591
33627
  if (result.error)
33592
33628
  return decorateResult({ result, stack });
33593
33629
  const targetCollection = tieFormat?.collectionDefinitions?.find(
@@ -33724,7 +33760,7 @@ function removeCollectionDefinition$1({
33724
33760
  });
33725
33761
  }
33726
33762
  const prunedTieFormat = definedAttributes(tieFormat);
33727
- result = validateTieFormat({ tieFormat: prunedTieFormat });
33763
+ result = validateTieFormat({ tieFormat: prunedTieFormat, eventType });
33728
33764
  if (result.error)
33729
33765
  return decorateResult({ result, stack });
33730
33766
  if (eventId && event) {
@@ -33816,7 +33852,8 @@ function addCollectionDefinition$1({
33816
33852
  matchUp = matchUp ?? result?.matchUp;
33817
33853
  const existingTieFormat = matchUp?.tieFormat ?? result?.tieFormat;
33818
33854
  const tieFormat = copyTieFormat(existingTieFormat);
33819
- result = validateTieFormat({ tieFormat });
33855
+ const eventType = event?.eventType;
33856
+ result = validateTieFormat({ tieFormat, eventType });
33820
33857
  if (result?.error) {
33821
33858
  return decorateResult({ result: { error: result.error }, stack });
33822
33859
  }
@@ -33851,7 +33888,7 @@ function addCollectionDefinition$1({
33851
33888
  const addedMatchUps = [];
33852
33889
  let targetMatchUps = [];
33853
33890
  const prunedTieFormat = definedAttributes(tieFormat);
33854
- result = validateTieFormat({ tieFormat: prunedTieFormat });
33891
+ result = validateTieFormat({ tieFormat: prunedTieFormat, eventType });
33855
33892
  if (result?.error) {
33856
33893
  return decorateResult({ result: { error: result.error }, stack });
33857
33894
  }
@@ -34139,7 +34176,10 @@ function collectionGroupUpdate({
34139
34176
  event
34140
34177
  });
34141
34178
  const prunedTieFormat = definedAttributes(tieFormat);
34142
- const result = validateTieFormat({ tieFormat: prunedTieFormat });
34179
+ const result = validateTieFormat({
34180
+ eventType: event?.eventType,
34181
+ tieFormat: prunedTieFormat
34182
+ });
34143
34183
  if (result.error)
34144
34184
  return result;
34145
34185
  if (eventId && event) {
@@ -34189,7 +34229,7 @@ function removeCollectionGroup$1({
34189
34229
  const originalValueGoal = existingTieFormat?.winCriteria.valueGoal;
34190
34230
  const wasAggregateValue = existingTieFormat?.winCriteria.aggregateValue;
34191
34231
  const tieFormat = copyTieFormat(existingTieFormat);
34192
- result = validateTieFormat({ tieFormat });
34232
+ result = validateTieFormat({ tieFormat, eventType: event?.eventType });
34193
34233
  if (result.error)
34194
34234
  return decorateResult({ result, stack });
34195
34235
  const modifiedCollectionIds = [];
@@ -34276,7 +34316,7 @@ function addCollectionGroup$1({
34276
34316
  const existingTieFormat = result?.tieFormat;
34277
34317
  const originalValueGoal = existingTieFormat?.winCriteria.valueGoal;
34278
34318
  const tieFormat = copyTieFormat(existingTieFormat);
34279
- result = validateTieFormat({ tieFormat });
34319
+ result = validateTieFormat({ tieFormat, eventType: event.eventType });
34280
34320
  if (result.error)
34281
34321
  return decorateResult({ result, stack });
34282
34322
  for (const collectionDefinition of tieFormat.collectionDefinitions) {
@@ -34340,7 +34380,10 @@ function modifyTieFormat$1({
34340
34380
  event
34341
34381
  }) {
34342
34382
  const stack = "modifyTieFormat";
34343
- if (!validateTieFormat({ tieFormat: modifiedTieFormat }).valid) {
34383
+ if (!validateTieFormat({
34384
+ tieFormat: modifiedTieFormat,
34385
+ eventType: event?.eventType
34386
+ }).valid) {
34344
34387
  return decorateResult({
34345
34388
  result: { error: INVALID_TIE_FORMAT },
34346
34389
  info: "falied validation",
@@ -42902,7 +42945,8 @@ function generateDrawTypeAndModifyDrawDefinition$1(params) {
42902
42945
  const drawDefinition = modifyOriginal ? params.drawDefinition : makeDeepCopy(params.drawDefinition, false, true);
42903
42946
  let { tieFormat, matchUpType } = params;
42904
42947
  if (tieFormat) {
42905
- const result2 = validateTieFormat({ tieFormat });
42948
+ const eventType = params.event?.eventType;
42949
+ const result2 = validateTieFormat({ tieFormat, eventType });
42906
42950
  if (result2.error)
42907
42951
  return result2;
42908
42952
  }
@@ -45369,7 +45413,8 @@ function generateVoluntaryConsolation$1(params) {
45369
45413
  return { error: INVALID_DRAW_SIZE };
45370
45414
  let { tieFormat, matchUpType } = params;
45371
45415
  if (tieFormat) {
45372
- const result2 = validateTieFormat({ tieFormat });
45416
+ const eventType = params.event?.eventType;
45417
+ const result2 = validateTieFormat({ tieFormat, eventType });
45373
45418
  if (result2.error)
45374
45419
  return result2;
45375
45420
  }
@@ -53818,15 +53863,13 @@ function generateLineUps(params) {
53818
53863
  return { error: MISSING_TOURNAMENT_RECORD };
53819
53864
  if (!tieFormat && !drawDefinition)
53820
53865
  return { error: DRAW_DEFINITION_NOT_FOUND };
53821
- tieFormat = tieFormat || resolveTieFormat({ drawDefinition, event })?.tieFormat;
53822
- if (validateTieFormat({ tieFormat }).error)
53866
+ tieFormat = tieFormat ?? resolveTieFormat({ drawDefinition, event })?.tieFormat;
53867
+ if (validateTieFormat({ tieFormat, eventType: params.event?.eventType }).error)
53823
53868
  return { error: INVALID_TIE_FORMAT };
53824
53869
  if (typeof scaleAccessor !== "object" && !useDefaultEventRanking)
53825
53870
  return { error: INVALID_VALUES, context: { scaleAccessor } };
53826
53871
  const lineUps = {};
53827
- const targetEntries = (drawDefinition?.entries || event.entries).filter(
53828
- (entry) => entry?.entryStatus === DIRECT_ACCEPTANCE
53829
- );
53872
+ const targetEntries = (drawDefinition?.entries ?? event?.entries ?? []).filter((entry) => entry?.entryStatus === DIRECT_ACCEPTANCE);
53830
53873
  const participantIds = targetEntries.map(getParticipantId);
53831
53874
  const { participants = [] } = getParticipants$1({
53832
53875
  withIndividualParticipants: true,
@@ -53837,7 +53880,7 @@ function generateLineUps(params) {
53837
53880
  ({ participantId }) => participantIds.includes(participantId)
53838
53881
  );
53839
53882
  const formatScaleType = (type) => type === RANKING$1 ? "rankings" : "ratings";
53840
- const defaultScaleName = event?.category?.categoryName || event?.category?.ageCategoryCode;
53883
+ const defaultScaleName = event?.category?.categoryName ?? event?.category?.ageCategoryCode;
53841
53884
  const {
53842
53885
  scaleName = defaultScaleName,
53843
53886
  scaleType = RANKING$1,
@@ -53869,7 +53912,7 @@ function generateLineUps(params) {
53869
53912
  const singlesScaleSort = (a, b) => sortMethod(a, b, SINGLES_MATCHUP);
53870
53913
  const doublesScaleSort = (a, b) => sortMethod(a, b, DOUBLES_MATCHUP);
53871
53914
  const participantIdPairs = [];
53872
- const collectionDefinitions = tieFormat.collectionDefinitions || [];
53915
+ const collectionDefinitions = tieFormat?.collectionDefinitions ?? [];
53873
53916
  for (const teamParticipant of teamParticipants) {
53874
53917
  const singlesSort = teamParticipant.individualParticipants.sort(singlesScaleSort);
53875
53918
  const doublesSort = singlesOnly ? singlesSort : teamParticipant.individualParticipants.sort(doublesScaleSort);
@@ -53884,7 +53927,7 @@ function generateLineUps(params) {
53884
53927
  const participantIds2 = [];
53885
53928
  generateRange(0, singlesMatchUp ? 1 : 2).forEach((i2) => {
53886
53929
  const nextParticipantId = typeSort.find((participant) => {
53887
- const targetGender = [MALE, FEMALE].includes(gender) && gender || gender === MIXED && [MALE, FEMALE][i2];
53930
+ const targetGender = gender && ([MALE, FEMALE].includes(gender) && gender || gender === MIXED && [MALE, FEMALE][i2]);
53888
53931
  return (!targetGender || targetGender === participant.person.sex) && !collectionParticipantIds.includes(participant.participantId);
53889
53932
  }).participantId;
53890
53933
  if (nextParticipantId) {
@@ -57248,7 +57291,10 @@ function addEvent({
57248
57291
  };
57249
57292
  if (event.eventType === TypeEnum.Team) {
57250
57293
  if (event.tieFormat) {
57251
- const result = validateTieFormat({ tieFormat: event.tieFormat });
57294
+ const result = validateTieFormat({
57295
+ tieFormat: event.tieFormat,
57296
+ eventType: event.eventType
57297
+ });
57252
57298
  if (result.error)
57253
57299
  return result;
57254
57300
  } else if (event.tieFormatName) {
@@ -59659,7 +59705,8 @@ function generateDrawDefinition(params) {
59659
59705
  const result = validateTieFormat({
59660
59706
  gender: event?.gender,
59661
59707
  enforceGender,
59662
- tieFormat
59708
+ tieFormat,
59709
+ event
59663
59710
  });
59664
59711
  if (result.error)
59665
59712
  return decorateResult({ result, stack });
@@ -59678,7 +59725,10 @@ function generateDrawDefinition(params) {
59678
59725
  const equivalentInScope = matchUpFormat && event?.matchUpFormat === matchUpFormat || event?.tieFormat && tieFormat && JSON.stringify(event.tieFormat) === JSON.stringify(tieFormat);
59679
59726
  if (!equivalentInScope) {
59680
59727
  if (tieFormat) {
59681
- const result = checkTieFormat(tieFormat);
59728
+ const result = checkTieFormat({
59729
+ eventType: event.eventType,
59730
+ tieFormat
59731
+ });
59682
59732
  if (result.error)
59683
59733
  return decorateResult({ result, stack });
59684
59734
  drawDefinition.tieFormat = result.tieFormat ?? tieFormat;
@@ -60094,11 +60144,12 @@ function aggregateTieFormats({
60094
60144
  addedCount += 1;
60095
60145
  }
60096
60146
  };
60097
- checkTieFormat(event);
60147
+ const eventType = event.eventType;
60148
+ checkTieFormat({ tieFormat: event.tieFormat, eventType });
60098
60149
  for (const drawDefinition of event.drawDefinitions ?? []) {
60099
- checkTieFormat(drawDefinition);
60150
+ checkTieFormat({ tieFormat: drawDefinition.tieFormat, eventType });
60100
60151
  for (const structure of drawDefinition.structures ?? []) {
60101
- checkTieFormat(structure);
60152
+ checkTieFormat({ tieFormat: structure.tieFormat, eventType });
60102
60153
  }
60103
60154
  }
60104
60155
  const setTieFormatId = (matchUpId, tieFormatId) => {