tods-competition-factory 1.8.44 → 1.8.45

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.45";
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 || [];
@@ -33316,7 +33324,10 @@ function modifyCollectionDefinition$1({
33316
33324
  modifications.push({ collectionId, gender });
33317
33325
  }
33318
33326
  const modifiedTieFormat = definedAttributes(tieFormat);
33319
- result = validateTieFormat({ tieFormat: modifiedTieFormat });
33327
+ result = validateTieFormat({
33328
+ tieFormat: modifiedTieFormat,
33329
+ eventType: event?.eventType
33330
+ });
33320
33331
  if (result.error) {
33321
33332
  return decorateResult({ result, stack });
33322
33333
  }
@@ -33587,7 +33598,8 @@ function removeCollectionDefinition$1({
33587
33598
  matchUp = matchUp ?? result?.matchUp;
33588
33599
  const existingTieFormat = result?.tieFormat;
33589
33600
  const tieFormat = copyTieFormat(existingTieFormat);
33590
- result = validateTieFormat({ tieFormat });
33601
+ const eventType = event?.eventType;
33602
+ result = validateTieFormat({ tieFormat, eventType });
33591
33603
  if (result.error)
33592
33604
  return decorateResult({ result, stack });
33593
33605
  const targetCollection = tieFormat?.collectionDefinitions?.find(
@@ -33724,7 +33736,7 @@ function removeCollectionDefinition$1({
33724
33736
  });
33725
33737
  }
33726
33738
  const prunedTieFormat = definedAttributes(tieFormat);
33727
- result = validateTieFormat({ tieFormat: prunedTieFormat });
33739
+ result = validateTieFormat({ tieFormat: prunedTieFormat, eventType });
33728
33740
  if (result.error)
33729
33741
  return decorateResult({ result, stack });
33730
33742
  if (eventId && event) {
@@ -33816,7 +33828,8 @@ function addCollectionDefinition$1({
33816
33828
  matchUp = matchUp ?? result?.matchUp;
33817
33829
  const existingTieFormat = matchUp?.tieFormat ?? result?.tieFormat;
33818
33830
  const tieFormat = copyTieFormat(existingTieFormat);
33819
- result = validateTieFormat({ tieFormat });
33831
+ const eventType = event?.eventType;
33832
+ result = validateTieFormat({ tieFormat, eventType });
33820
33833
  if (result?.error) {
33821
33834
  return decorateResult({ result: { error: result.error }, stack });
33822
33835
  }
@@ -33851,7 +33864,7 @@ function addCollectionDefinition$1({
33851
33864
  const addedMatchUps = [];
33852
33865
  let targetMatchUps = [];
33853
33866
  const prunedTieFormat = definedAttributes(tieFormat);
33854
- result = validateTieFormat({ tieFormat: prunedTieFormat });
33867
+ result = validateTieFormat({ tieFormat: prunedTieFormat, eventType });
33855
33868
  if (result?.error) {
33856
33869
  return decorateResult({ result: { error: result.error }, stack });
33857
33870
  }
@@ -34139,7 +34152,10 @@ function collectionGroupUpdate({
34139
34152
  event
34140
34153
  });
34141
34154
  const prunedTieFormat = definedAttributes(tieFormat);
34142
- const result = validateTieFormat({ tieFormat: prunedTieFormat });
34155
+ const result = validateTieFormat({
34156
+ eventType: event?.eventType,
34157
+ tieFormat: prunedTieFormat
34158
+ });
34143
34159
  if (result.error)
34144
34160
  return result;
34145
34161
  if (eventId && event) {
@@ -34189,7 +34205,7 @@ function removeCollectionGroup$1({
34189
34205
  const originalValueGoal = existingTieFormat?.winCriteria.valueGoal;
34190
34206
  const wasAggregateValue = existingTieFormat?.winCriteria.aggregateValue;
34191
34207
  const tieFormat = copyTieFormat(existingTieFormat);
34192
- result = validateTieFormat({ tieFormat });
34208
+ result = validateTieFormat({ tieFormat, eventType: event?.eventType });
34193
34209
  if (result.error)
34194
34210
  return decorateResult({ result, stack });
34195
34211
  const modifiedCollectionIds = [];
@@ -34276,7 +34292,7 @@ function addCollectionGroup$1({
34276
34292
  const existingTieFormat = result?.tieFormat;
34277
34293
  const originalValueGoal = existingTieFormat?.winCriteria.valueGoal;
34278
34294
  const tieFormat = copyTieFormat(existingTieFormat);
34279
- result = validateTieFormat({ tieFormat });
34295
+ result = validateTieFormat({ tieFormat, eventType: event.eventType });
34280
34296
  if (result.error)
34281
34297
  return decorateResult({ result, stack });
34282
34298
  for (const collectionDefinition of tieFormat.collectionDefinitions) {
@@ -34340,7 +34356,10 @@ function modifyTieFormat$1({
34340
34356
  event
34341
34357
  }) {
34342
34358
  const stack = "modifyTieFormat";
34343
- if (!validateTieFormat({ tieFormat: modifiedTieFormat }).valid) {
34359
+ if (!validateTieFormat({
34360
+ tieFormat: modifiedTieFormat,
34361
+ eventType: event?.eventType
34362
+ }).valid) {
34344
34363
  return decorateResult({
34345
34364
  result: { error: INVALID_TIE_FORMAT },
34346
34365
  info: "falied validation",
@@ -42902,7 +42921,8 @@ function generateDrawTypeAndModifyDrawDefinition$1(params) {
42902
42921
  const drawDefinition = modifyOriginal ? params.drawDefinition : makeDeepCopy(params.drawDefinition, false, true);
42903
42922
  let { tieFormat, matchUpType } = params;
42904
42923
  if (tieFormat) {
42905
- const result2 = validateTieFormat({ tieFormat });
42924
+ const eventType = params.event?.eventType;
42925
+ const result2 = validateTieFormat({ tieFormat, eventType });
42906
42926
  if (result2.error)
42907
42927
  return result2;
42908
42928
  }
@@ -45369,7 +45389,8 @@ function generateVoluntaryConsolation$1(params) {
45369
45389
  return { error: INVALID_DRAW_SIZE };
45370
45390
  let { tieFormat, matchUpType } = params;
45371
45391
  if (tieFormat) {
45372
- const result2 = validateTieFormat({ tieFormat });
45392
+ const eventType = params.event?.eventType;
45393
+ const result2 = validateTieFormat({ tieFormat, eventType });
45373
45394
  if (result2.error)
45374
45395
  return result2;
45375
45396
  }
@@ -53818,15 +53839,13 @@ function generateLineUps(params) {
53818
53839
  return { error: MISSING_TOURNAMENT_RECORD };
53819
53840
  if (!tieFormat && !drawDefinition)
53820
53841
  return { error: DRAW_DEFINITION_NOT_FOUND };
53821
- tieFormat = tieFormat || resolveTieFormat({ drawDefinition, event })?.tieFormat;
53822
- if (validateTieFormat({ tieFormat }).error)
53842
+ tieFormat = tieFormat ?? resolveTieFormat({ drawDefinition, event })?.tieFormat;
53843
+ if (validateTieFormat({ tieFormat, eventType: params.event?.eventType }).error)
53823
53844
  return { error: INVALID_TIE_FORMAT };
53824
53845
  if (typeof scaleAccessor !== "object" && !useDefaultEventRanking)
53825
53846
  return { error: INVALID_VALUES, context: { scaleAccessor } };
53826
53847
  const lineUps = {};
53827
- const targetEntries = (drawDefinition?.entries || event.entries).filter(
53828
- (entry) => entry?.entryStatus === DIRECT_ACCEPTANCE
53829
- );
53848
+ const targetEntries = (drawDefinition?.entries ?? event?.entries ?? []).filter((entry) => entry?.entryStatus === DIRECT_ACCEPTANCE);
53830
53849
  const participantIds = targetEntries.map(getParticipantId);
53831
53850
  const { participants = [] } = getParticipants$1({
53832
53851
  withIndividualParticipants: true,
@@ -53837,7 +53856,7 @@ function generateLineUps(params) {
53837
53856
  ({ participantId }) => participantIds.includes(participantId)
53838
53857
  );
53839
53858
  const formatScaleType = (type) => type === RANKING$1 ? "rankings" : "ratings";
53840
- const defaultScaleName = event?.category?.categoryName || event?.category?.ageCategoryCode;
53859
+ const defaultScaleName = event?.category?.categoryName ?? event?.category?.ageCategoryCode;
53841
53860
  const {
53842
53861
  scaleName = defaultScaleName,
53843
53862
  scaleType = RANKING$1,
@@ -53869,7 +53888,7 @@ function generateLineUps(params) {
53869
53888
  const singlesScaleSort = (a, b) => sortMethod(a, b, SINGLES_MATCHUP);
53870
53889
  const doublesScaleSort = (a, b) => sortMethod(a, b, DOUBLES_MATCHUP);
53871
53890
  const participantIdPairs = [];
53872
- const collectionDefinitions = tieFormat.collectionDefinitions || [];
53891
+ const collectionDefinitions = tieFormat?.collectionDefinitions ?? [];
53873
53892
  for (const teamParticipant of teamParticipants) {
53874
53893
  const singlesSort = teamParticipant.individualParticipants.sort(singlesScaleSort);
53875
53894
  const doublesSort = singlesOnly ? singlesSort : teamParticipant.individualParticipants.sort(doublesScaleSort);
@@ -53884,7 +53903,7 @@ function generateLineUps(params) {
53884
53903
  const participantIds2 = [];
53885
53904
  generateRange(0, singlesMatchUp ? 1 : 2).forEach((i2) => {
53886
53905
  const nextParticipantId = typeSort.find((participant) => {
53887
- const targetGender = [MALE, FEMALE].includes(gender) && gender || gender === MIXED && [MALE, FEMALE][i2];
53906
+ const targetGender = gender && ([MALE, FEMALE].includes(gender) && gender || gender === MIXED && [MALE, FEMALE][i2]);
53888
53907
  return (!targetGender || targetGender === participant.person.sex) && !collectionParticipantIds.includes(participant.participantId);
53889
53908
  }).participantId;
53890
53909
  if (nextParticipantId) {
@@ -57248,7 +57267,10 @@ function addEvent({
57248
57267
  };
57249
57268
  if (event.eventType === TypeEnum.Team) {
57250
57269
  if (event.tieFormat) {
57251
- const result = validateTieFormat({ tieFormat: event.tieFormat });
57270
+ const result = validateTieFormat({
57271
+ tieFormat: event.tieFormat,
57272
+ eventType: event.eventType
57273
+ });
57252
57274
  if (result.error)
57253
57275
  return result;
57254
57276
  } else if (event.tieFormatName) {
@@ -59659,7 +59681,8 @@ function generateDrawDefinition(params) {
59659
59681
  const result = validateTieFormat({
59660
59682
  gender: event?.gender,
59661
59683
  enforceGender,
59662
- tieFormat
59684
+ tieFormat,
59685
+ event
59663
59686
  });
59664
59687
  if (result.error)
59665
59688
  return decorateResult({ result, stack });
@@ -59678,7 +59701,10 @@ function generateDrawDefinition(params) {
59678
59701
  const equivalentInScope = matchUpFormat && event?.matchUpFormat === matchUpFormat || event?.tieFormat && tieFormat && JSON.stringify(event.tieFormat) === JSON.stringify(tieFormat);
59679
59702
  if (!equivalentInScope) {
59680
59703
  if (tieFormat) {
59681
- const result = checkTieFormat(tieFormat);
59704
+ const result = checkTieFormat({
59705
+ eventType: event.eventType,
59706
+ tieFormat
59707
+ });
59682
59708
  if (result.error)
59683
59709
  return decorateResult({ result, stack });
59684
59710
  drawDefinition.tieFormat = result.tieFormat ?? tieFormat;
@@ -60094,11 +60120,12 @@ function aggregateTieFormats({
60094
60120
  addedCount += 1;
60095
60121
  }
60096
60122
  };
60097
- checkTieFormat(event);
60123
+ const eventType = event.eventType;
60124
+ checkTieFormat({ tieFormat: event.tieFormat, eventType });
60098
60125
  for (const drawDefinition of event.drawDefinitions ?? []) {
60099
- checkTieFormat(drawDefinition);
60126
+ checkTieFormat({ tieFormat: drawDefinition.tieFormat, eventType });
60100
60127
  for (const structure of drawDefinition.structures ?? []) {
60101
- checkTieFormat(structure);
60128
+ checkTieFormat({ tieFormat: structure.tieFormat, eventType });
60102
60129
  }
60103
60130
  }
60104
60131
  const setTieFormatId = (matchUpId, tieFormatId) => {