tods-competition-factory 1.7.10 → 1.7.12

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
@@ -333,7 +333,7 @@ const matchUpFormatCode = {
333
333
  };
334
334
 
335
335
  function factoryVersion() {
336
- return "1.7.10";
336
+ return "1.7.12";
337
337
  }
338
338
 
339
339
  function getObjectTieFormat(obj) {
@@ -16620,7 +16620,6 @@ function compareTieFormats({
16620
16620
  );
16621
16621
  const nameDifference = !!(considerations?.collectionName && descendant.collectionDefinitions.map(({ collectionName }) => collectionName).join("|") !== ancestor.collectionDefinitions.map(({ collectionName }) => collectionName).join("|"));
16622
16622
  const orderDifference = !!(considerations?.collectionOrder && descendant.collectionDefinitions.map(({ collectionOrder }) => collectionOrder).join("|") !== ancestor.collectionDefinitions.map(({ collectionOrder }) => collectionOrder).join("|"));
16623
- const different = nameDifference || orderDifference || ancestorDesc !== descendantDesc;
16624
16623
  const descendantCollectionDefinitions = Object.assign(
16625
16624
  {},
16626
16625
  ...(descendant?.collectionDefinitions || []).map(
@@ -16644,17 +16643,16 @@ function compareTieFormats({
16644
16643
  Object.keys(descendantCollectionDefinitions)
16645
16644
  );
16646
16645
  descendantDifferences.collectionsValue = getCollectionsValue(
16647
- descendantCollectionDefinitions,
16648
- descendantDifferences
16646
+ descendantCollectionDefinitions
16649
16647
  );
16650
16648
  ancestorDifferences.collectionsValue = getCollectionsValue(
16651
- ancestorCollectionDefinitions,
16652
- ancestorDifferences
16649
+ ancestorCollectionDefinitions
16653
16650
  );
16654
16651
  descendantDifferences.groupsCount = ancestor?.collectionGroups?.length ?? (0 - (descendant?.collectionGroups?.length ?? 0) || 0);
16655
16652
  ancestorDifferences.groupsCount = descendantDifferences.groupsCount ? -1 * descendantDifferences.groupsCount : 0;
16656
16653
  const valueDifference = descendantDifferences.collectionsValue.totalValue - ancestorDifferences.collectionsValue.totalValue;
16657
16654
  const matchUpCountDifference = descendantDifferences.collectionsValue.totalMatchUps - ancestorDifferences.collectionsValue.totalMatchUps;
16655
+ const different = nameDifference || orderDifference || ancestorDesc !== descendantDesc || valueDifference !== 0;
16658
16656
  return {
16659
16657
  matchUpFormatDifferences,
16660
16658
  matchUpCountDifference,
@@ -16669,15 +16667,18 @@ function compareTieFormats({
16669
16667
  different
16670
16668
  };
16671
16669
  }
16672
- function getCollectionsValue(definitions, aggregator) {
16670
+ function getCollectionsValue(definitions) {
16673
16671
  let totalMatchUps = 0;
16674
- const totalValue = aggregator.collectionIds.reduce((total, collectionId) => {
16672
+ const collectionIds = Object.keys(definitions);
16673
+ const totalValue = collectionIds.reduce((total, collectionId) => {
16675
16674
  const collectionDefinition = definitions[collectionId];
16676
16675
  const {
16677
16676
  collectionValueProfiles,
16678
16677
  collectionValue,
16679
16678
  matchUpCount,
16680
- matchUpValue
16679
+ matchUpValue,
16680
+ scoreValue,
16681
+ setValue
16681
16682
  } = collectionDefinition;
16682
16683
  totalMatchUps += matchUpCount;
16683
16684
  if (collectionValueProfiles)
@@ -16685,9 +16686,16 @@ function getCollectionsValue(definitions, aggregator) {
16685
16686
  (total2, profile) => total2 + profile.value,
16686
16687
  0
16687
16688
  );
16688
- if (matchUpValue && matchUpCount)
16689
- return total + matchUpValue * matchUpCount;
16690
- return total + collectionValue;
16689
+ if (matchUpCount) {
16690
+ if (isConvertableInteger(matchUpValue))
16691
+ return total + matchUpValue * matchUpCount;
16692
+ if (isConvertableInteger(scoreValue))
16693
+ return total + scoreValue * matchUpCount;
16694
+ if (isConvertableInteger(setValue))
16695
+ return total + setValue * matchUpCount;
16696
+ return total + collectionValue;
16697
+ }
16698
+ return total;
16691
16699
  }, 0);
16692
16700
  return { totalValue, totalMatchUps };
16693
16701
  }
@@ -44424,6 +44432,16 @@ function generateAdHocMatchUps$1({
44424
44432
  );
44425
44433
  if (!structure)
44426
44434
  return { error: STRUCTURE_NOT_FOUND };
44435
+ let structureHasRoundPositions;
44436
+ const existingMatchUps = structure.matchUps ?? [];
44437
+ const lastRoundNumber = existingMatchUps?.reduce(
44438
+ (roundNumber2, matchUp) => {
44439
+ if (matchUp.roundPosition)
44440
+ structureHasRoundPositions = true;
44441
+ return (matchUp?.roundNumber || 0) > roundNumber2 ? matchUp.roundNumber : roundNumber2;
44442
+ },
44443
+ 0
44444
+ );
44427
44445
  if (!matchUpsCount) {
44428
44446
  const selectedEntries = drawDefinition?.entries?.filter((entry) => {
44429
44447
  const entryStatus = entry.entryStatus;
@@ -44433,7 +44451,11 @@ function generateAdHocMatchUps$1({
44433
44451
  if (newRound) {
44434
44452
  matchUpsCount = roundMatchUpsCount;
44435
44453
  } else {
44436
- const maxRemaining = roundMatchUpsCount - (structure.matchUps?.length || 0);
44454
+ const targetRoundNumber = roundNumber || lastRoundNumber || 1;
44455
+ const existingRoundMatchUps = structure.matchUps?.filter(
44456
+ (matchUp) => matchUp.roundNumber === targetRoundNumber
44457
+ )?.length || 0;
44458
+ const maxRemaining = roundMatchUpsCount - existingRoundMatchUps;
44437
44459
  if (maxRemaining > 0)
44438
44460
  matchUpsCount = maxRemaining;
44439
44461
  }
@@ -44441,16 +44463,6 @@ function generateAdHocMatchUps$1({
44441
44463
  if (participantIdPairings && !Array.isArray(participantIdPairings) || matchUpsCount && !isConvertableInteger(matchUpsCount) || matchUpIds && !Array.isArray(matchUpIds) || !participantIdPairings && !matchUpsCount) {
44442
44464
  return { error: INVALID_VALUES, info: "matchUpsCount or pairings error" };
44443
44465
  }
44444
- let structureHasRoundPositions;
44445
- const existingMatchUps = structure.matchUps ?? [];
44446
- const lastRoundNumber = existingMatchUps?.reduce(
44447
- (roundNumber2, matchUp) => {
44448
- if (matchUp.roundPosition)
44449
- structureHasRoundPositions = true;
44450
- return (matchUp?.roundNumber || 0) > roundNumber2 ? matchUp.roundNumber : roundNumber2;
44451
- },
44452
- 0
44453
- );
44454
44466
  if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
44455
44467
  return { error: INVALID_STRUCTURE };
44456
44468
  }
@@ -45081,9 +45093,12 @@ function setPositionAssignments$1({
45081
45093
  return { ...SUCCESS };
45082
45094
  }
45083
45095
 
45084
- function getAssignedParticipantIds({ drawDefinition, stages }) {
45096
+ function getAssignedParticipantIds({
45097
+ drawDefinition,
45098
+ stages
45099
+ }) {
45085
45100
  const stageStructures = (drawDefinition?.structures || []).filter(
45086
- (structure) => !stages?.length || stages.includes(structure.stage)
45101
+ (structure) => !stages?.length || structure.stage && stages.includes(structure.stage)
45087
45102
  );
45088
45103
  return stageStructures.map((structure) => {
45089
45104
  const { positionAssignments } = getPositionAssignments$1({
@@ -45626,49 +45641,47 @@ function participantInFlightEntries({
45626
45641
 
45627
45642
  function removeEventEntries({
45628
45643
  autoEntryPositions = true,
45629
- tournamentParticipants,
45630
- tournamentRecord,
45631
- participantIds,
45644
+ participantIds = [],
45645
+ entryStatuses,
45646
+ stage,
45632
45647
  event
45633
45648
  }) {
45634
45649
  const stack = "removeEventEntries";
45635
45650
  if (!event?.eventId)
45636
45651
  return { error: MISSING_EVENT };
45637
- if (!Array.isArray(participantIds))
45638
- return decorateResult({
45639
- result: { error: MISSING_PARTICIPANT_IDS },
45640
- stack
45641
- });
45642
- participantIds = participantIds?.filter(Boolean);
45643
- if (!participantIds?.length)
45644
- return decorateResult({
45645
- result: { error: MISSING_PARTICIPANT_IDS },
45646
- stack
45647
- });
45648
- const { eventId } = event;
45649
- if (!tournamentParticipants) {
45650
- tournamentParticipants = getTournamentParticipants({
45651
- participantFilters: { participantIds },
45652
- tournamentRecord,
45653
- withEvents: true,
45654
- withDraws: true
45655
- }).tournamentParticipants;
45652
+ if (!Array.isArray(participantIds) || participantIds.some((participantId) => !isString(participantId))) {
45653
+ return decorateResult({ result: { error: INVALID_PARTICIPANT_ID }, stack });
45656
45654
  }
45657
- const enteredParticipantIds = tournamentParticipants?.every((participant) => {
45658
- const eventObject = participant.events.find(
45659
- (event2) => event2.eventId === eventId
45660
- );
45661
- const drawIds = eventObject?.drawIds || [];
45662
- return participant.draws.filter(
45663
- (drawInfo) => drawIds.includes(drawInfo.drawId) && drawInfo.positionAssignments
45664
- ).length;
45665
- });
45666
- if (enteredParticipantIds) {
45655
+ const assignedParticipantIds = (event.drawDefinitions ?? []).flatMap(
45656
+ (drawDefinition) => getAssignedParticipantIds({ drawDefinition })
45657
+ );
45658
+ const statusParticipantIds = (entryStatuses?.length && event.entries?.filter(
45659
+ (entry) => entry.entryStatus && entryStatuses.includes(entry.entryStatus)
45660
+ ) || []).map(extractAttributes("participantId")).filter((participantId) => !assignedParticipantIds.includes(participantId));
45661
+ const stageParticipantIds = (stage && event.entries?.filter(
45662
+ (entry) => entry.entryStage && entry.entryStage === stage
45663
+ ) || []).map(extractAttributes("participantId")).filter((participantId) => !assignedParticipantIds.includes(participantId));
45664
+ if (participantIds.length) {
45665
+ participantIds = participantIds.filter(
45666
+ (participantId) => (!entryStatuses?.length || statusParticipantIds.includes(participantId)) && (!stage || stageParticipantIds.includes(participantId))
45667
+ );
45668
+ } else if (statusParticipantIds.length && stageParticipantIds.length) {
45669
+ participantIds = intersection(statusParticipantIds, stageParticipantIds);
45670
+ } else if (statusParticipantIds.length) {
45671
+ participantIds = statusParticipantIds;
45672
+ } else if (stageParticipantIds.length) {
45673
+ participantIds = stageParticipantIds;
45674
+ }
45675
+ if (participantIds?.length && assignedParticipantIds.some(
45676
+ (participantId) => participantIds.includes(participantId)
45677
+ )) {
45667
45678
  return decorateResult({
45668
45679
  result: { error: EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT },
45669
45680
  stack
45670
45681
  });
45671
45682
  }
45683
+ if (!participantIds?.length)
45684
+ return { ...SUCCESS, participantIdsRemoved: [] };
45672
45685
  const participantIdsRemoved = [];
45673
45686
  event.entries = (event.entries || []).filter((entry) => {
45674
45687
  const keepEntry = !participantIds.includes(entry?.participantId);
@@ -45826,7 +45839,6 @@ function addEventEntries(params) {
45826
45839
  participantIds: ungroupedParticipantIdsToRemove,
45827
45840
  autoEntryPositions: false,
45828
45841
  // because the method will be called below if necessary
45829
- tournamentRecord,
45830
45842
  event
45831
45843
  });
45832
45844
  }
@@ -46083,8 +46095,6 @@ function deleteParticipants(params) {
46083
46095
  const mappedIndividualParticipantIdsToAdd = {};
46084
46096
  for (const event of tournamentRecord.events || []) {
46085
46097
  const result = removeEventEntries({
46086
- tournamentParticipants,
46087
- tournamentRecord,
46088
46098
  participantIds,
46089
46099
  event
46090
46100
  });
@@ -46225,7 +46235,6 @@ function destroyGroupEntry({
46225
46235
  );
46226
46236
  let result = removeEventEntries({
46227
46237
  participantIds: [participantId],
46228
- tournamentRecord,
46229
46238
  event
46230
46239
  });
46231
46240
  if (result.error)
@@ -60245,6 +60254,7 @@ var lastNames = [
60245
60254
  "Dallas",
60246
60255
  "Diamond",
60247
60256
  "Deckard",
60257
+ "Dunbar",
60248
60258
  "Earhart",
60249
60259
  "Eisenstein",
60250
60260
  "Eldritch",