tods-competition-factory 1.7.8 → 1.7.9

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.8";
336
+ return "1.7.9";
337
337
  }
338
338
 
339
339
  function getObjectTieFormat(obj) {
@@ -22764,6 +22764,15 @@ function getNumericSeedValue(seedValue) {
22764
22764
  return Infinity;
22765
22765
  }
22766
22766
 
22767
+ function capitalizeFirst(str) {
22768
+ return !isString(str) ? str : str.split(" ").map(
22769
+ (name) => name.split("").map((c, i) => i ? c.toLowerCase() : c.toUpperCase()).join("")
22770
+ ).join(" ");
22771
+ }
22772
+ function constantToString(str) {
22773
+ return !isString(str) ? str : capitalizeFirst(str.replace(/_/g, " "));
22774
+ }
22775
+
22767
22776
  const structureTemplate = ({
22768
22777
  finishingPosition = ROUND_OUTCOME,
22769
22778
  qualifyingRoundNumber,
@@ -22827,7 +22836,7 @@ const structureTemplate = ({
22827
22836
  };
22828
22837
 
22829
22838
  function generateRoundRobin({
22830
- structureName = MAIN,
22839
+ structureName = constantToString(MAIN),
22831
22840
  stageSequence = 1,
22832
22841
  structureOptions,
22833
22842
  appliedPolicies,
@@ -28755,10 +28764,12 @@ function getParticipantEntries(params) {
28755
28764
  seedAssignments[MAIN] = mainSeeding;
28756
28765
  if (seedAssignments && qualifyingSeeding)
28757
28766
  seedAssignments[QUALIFYING] = mainSeeding;
28758
- if (withEvents || withRankingProfile) {
28767
+ if ((withEvents || withRankingProfile) && participantMap[id] && eventId) {
28768
+ if (!participantMap[id].events[eventId])
28769
+ participantMap[id].events[eventId] = {};
28759
28770
  if (includeSeeding) {
28760
28771
  participantMap[id].events[eventId].seedValue = mainSeeding || qualifyingSeeding;
28761
- } else if (participantMap[id].events[eventId]?.seedValue) {
28772
+ } else if (participantMap[id].events[eventId].seedValue) {
28762
28773
  participantMap[id].events[eventId].seedValue = void 0;
28763
28774
  }
28764
28775
  }
@@ -39597,8 +39608,8 @@ function firstRoundLoserConsolation(params) {
39597
39608
  };
39598
39609
  const { matchUps } = staggeredEntry ? feedInMatchUps(mainParams) : treeMatchUps(mainParams);
39599
39610
  const mainStructure = structureTemplate({
39611
+ structureName: structureName || constantToString(MAIN),
39600
39612
  structureId: structureId || uuids?.pop(),
39601
- structureName: structureName || MAIN,
39602
39613
  stageSequence,
39603
39614
  matchUpType,
39604
39615
  matchUps,
@@ -39615,7 +39626,8 @@ function firstRoundLoserConsolation(params) {
39615
39626
  matchUpType,
39616
39627
  isMock
39617
39628
  });
39618
- const consolationStructureName = params.consolationStructureName || (structureName ? `${structureName} ${CONSOLATION}` : CONSOLATION);
39629
+ const consolation = constantToString(CONSOLATION);
39630
+ const consolationStructureName = params.consolationStructureName || (structureName ? `${structureName} ${consolation}` : consolation);
39619
39631
  const consolationStructure = structureTemplate({
39620
39632
  structureName: consolationStructureName,
39621
39633
  matchUps: consolationMatchUps,
@@ -39693,8 +39705,9 @@ function feedInLinks({
39693
39705
 
39694
39706
  function generateCurtisConsolation(params) {
39695
39707
  const {
39708
+ structureName = constantToString(MAIN),
39709
+ playoffStructureNameBase,
39696
39710
  finishingPositionOffset,
39697
- structureName = MAIN,
39698
39711
  stageSequence = 1,
39699
39712
  structureNameMap,
39700
39713
  staggeredEntry,
@@ -39732,6 +39745,7 @@ function generateCurtisConsolation(params) {
39732
39745
  const { consolationStructure } = consolationFeedStructure({
39733
39746
  idPrefix: idPrefix && `${idPrefix}-c${index}`,
39734
39747
  structureId: uuids?.pop(),
39748
+ playoffStructureNameBase,
39735
39749
  structureNameMap,
39736
39750
  stageSequence: stageSequence2,
39737
39751
  roundOffset,
@@ -39760,12 +39774,15 @@ function generateCurtisConsolation(params) {
39760
39774
  matchUpType,
39761
39775
  isMock
39762
39776
  });
39777
+ const defaultName = constantToString(PLAY_OFF);
39778
+ const mappedStructureName = structureNameMap?.[defaultName] || defaultName;
39779
+ const structureName2 = playoffStructureNameBase ? `${playoffStructureNameBase} ${mappedStructureName}` : mappedStructureName;
39763
39780
  const playoffStructure = structureTemplate({
39764
- structureName: structureNameMap?.[PLAY_OFF] || PLAY_OFF,
39765
39781
  structureId: uuids?.pop(),
39766
39782
  matchUps: playoffMatchUps,
39767
39783
  stageSequence: 2,
39768
39784
  stage: PLAY_OFF,
39785
+ structureName: structureName2,
39769
39786
  matchUpType
39770
39787
  });
39771
39788
  const playoffLink = {
@@ -39787,6 +39804,7 @@ function generateCurtisConsolation(params) {
39787
39804
  return { structures, links, ...SUCCESS };
39788
39805
  }
39789
39806
  function consolationFeedStructure({
39807
+ playoffStructureNameBase,
39790
39808
  stageSequence = 1,
39791
39809
  structureNameMap,
39792
39810
  roundOffset = 0,
@@ -39809,8 +39827,9 @@ function consolationFeedStructure({
39809
39827
  isMock,
39810
39828
  uuids
39811
39829
  });
39812
- const defaultName = `${CONSOLATION} ${index + 1}`;
39813
- const structureName = structureNameMap?.[defaultName] || defaultName;
39830
+ const defaultName = `${constantToString(CONSOLATION)} ${index + 1}`;
39831
+ const mappedStructureName = structureNameMap?.[defaultName] || defaultName;
39832
+ const structureName = playoffStructureNameBase ? `${playoffStructureNameBase} ${mappedStructureName}` : mappedStructureName;
39814
39833
  const consolationStructure = structureTemplate({
39815
39834
  matchUps: consolationMatchUps,
39816
39835
  stage: CONSOLATION,
@@ -39823,7 +39842,6 @@ function consolationFeedStructure({
39823
39842
  }
39824
39843
 
39825
39844
  function generatePlayoffStructures(params) {
39826
- let { matchUpType } = params;
39827
39845
  const {
39828
39846
  finishingPositionOffset = 0,
39829
39847
  addNameBaseToAttributeName,
@@ -39853,7 +39871,7 @@ function generatePlayoffStructures(params) {
39853
39871
  const allMatchUps = [];
39854
39872
  const structures = [];
39855
39873
  const links = [];
39856
- matchUpType = matchUpType || drawDefinition?.matchUpType;
39874
+ const matchUpType = params.matchUpType || drawDefinition?.matchUpType;
39857
39875
  const finishingPositionsFrom = finishingPositionOffset + 1;
39858
39876
  const finishingPositionsTo = finishingPositionOffset + drawSize;
39859
39877
  const finishingPositionRange = `${finishingPositionsFrom}-${finishingPositionsTo}`;
@@ -39903,7 +39921,7 @@ function generatePlayoffStructures(params) {
39903
39921
  if (playoffDrawPositions < 2)
39904
39922
  return;
39905
39923
  const childFinishingPositionOffset = drawSize / Math.pow(2, roundNumber) + finishingPositionOffset;
39906
- if (childFinishingPositionOffset + 1 > finishingPositionLimit)
39924
+ if (finishingPositionLimit && childFinishingPositionOffset + 1 > finishingPositionLimit)
39907
39925
  return;
39908
39926
  const {
39909
39927
  structures: childStructures,
@@ -39991,8 +40009,8 @@ function feedInChampionship(params) {
39991
40009
  };
39992
40010
  const { matchUps } = staggeredEntry ? feedInMatchUps(mainParams) : treeMatchUps(mainParams);
39993
40011
  const mainStructure = structureTemplate({
40012
+ structureName: structureName || constantToString(MAIN),
39994
40013
  structureId: structureId || uuids?.pop(),
39995
- structureName: structureName || MAIN,
39996
40014
  stageSequence,
39997
40015
  matchUpType,
39998
40016
  matchUps,
@@ -40016,9 +40034,9 @@ function feedInChampionship(params) {
40016
40034
  });
40017
40035
  if (drawSize > 2) {
40018
40036
  const consolationStructure = structureTemplate({
40037
+ structureName: constantToString(CONSOLATION),
40019
40038
  matchUps: consolationMatchUps,
40020
40039
  structureId: uuids?.pop(),
40021
- structureName: CONSOLATION,
40022
40040
  stage: CONSOLATION,
40023
40041
  stageSequence: 1,
40024
40042
  matchUpType
@@ -40093,10 +40111,19 @@ function processPlayoffGroups({
40093
40111
  if (positionsPlayedOff) {
40094
40112
  finishingPositionOffset = Math.min(...positionsPlayedOff) - 1;
40095
40113
  }
40096
- const params = {
40114
+ const playoffGroupParams = {
40115
+ addNameBaseToAttributeName: playoffGroup.addNameBaseToAttributeName,
40116
+ playoffStructureNameBase: playoffGroup.playoffStructureNameBase,
40117
+ finishingPositionNaming: playoffGroup.finishingPositionNaming,
40118
+ finishingPositionLimit: playoffGroup.finishingPositionLimit,
40097
40119
  structureId: playoffGroup.structureId ?? uuids?.pop(),
40120
+ playoffAttributes: playoffGroup.playoffAttributes,
40098
40121
  structureNameMap: playoffGroup.structureNameMap,
40099
40122
  structureName: playoffGroup.structureName,
40123
+ sequenceLimit: playoffGroup.sequenceLimit
40124
+ };
40125
+ const params = {
40126
+ ...playoffGroupParams,
40100
40127
  idPrefix: idPrefix && `${idPrefix}-po`,
40101
40128
  appliedPolicies: policyDefinitions,
40102
40129
  finishingPositionOffset,
@@ -40294,13 +40321,17 @@ function generatePlayoffLink({
40294
40321
 
40295
40322
  function generateRoundRobinWithPlayOff(params) {
40296
40323
  const { drawDefinition, structureOptions, requireSequential } = params;
40297
- const mainDrawProperties = { structureName: MAIN, ...params, stage: MAIN };
40324
+ const mainDrawProperties = {
40325
+ structureName: constantToString(MAIN),
40326
+ ...params,
40327
+ stage: MAIN
40328
+ };
40298
40329
  const { structures, groupCount, groupSize } = generateRoundRobin(mainDrawProperties);
40299
40330
  if (groupCount < 1) {
40300
40331
  console.log(INVALID_CONFIGURATION);
40301
40332
  }
40302
40333
  const playoffGroups = structureOptions?.playoffGroups || [
40303
- { finishingPositions: [1], structureName: PLAY_OFF }
40334
+ { finishingPositions: [1], structureName: constantToString(PLAY_OFF) }
40304
40335
  ];
40305
40336
  const [mainStructure] = structures;
40306
40337
  const { structures: playoffStructures, links } = processPlayoffGroups({
@@ -40418,7 +40449,7 @@ function generateDoubleElimination({
40418
40449
  isMock
40419
40450
  });
40420
40451
  const mainStructure = structureTemplate({
40421
- structureName: structureName || MAIN,
40452
+ structureName: structureName || constantToString(MAIN),
40422
40453
  structureId: uuids?.pop(),
40423
40454
  stageSequence: 1,
40424
40455
  stage: MAIN,
@@ -40437,9 +40468,9 @@ function generateDoubleElimination({
40437
40468
  uuids
40438
40469
  });
40439
40470
  const consolationStructure = structureTemplate({
40471
+ structureName: constantToString(BACKDRAW),
40440
40472
  matchUps: consolationMatchUps,
40441
40473
  structureId: uuids?.pop(),
40442
- structureName: BACKDRAW,
40443
40474
  stage: CONSOLATION,
40444
40475
  stageSequence: 2,
40445
40476
  matchUpType
@@ -40452,9 +40483,9 @@ function generateDoubleElimination({
40452
40483
  isMock
40453
40484
  });
40454
40485
  const deciderStructure = structureTemplate({
40486
+ structureName: constantToString(DECIDER),
40455
40487
  matchUps: deciderMatchUps,
40456
40488
  structureId: uuids?.pop(),
40457
- structureName: DECIDER,
40458
40489
  stageSequence: 3,
40459
40490
  stage: PLAY_OFF,
40460
40491
  matchUpType
@@ -40576,11 +40607,12 @@ function getGenerators(params) {
40576
40607
  const { appliedPolicies } = getAppliedPolicies(params);
40577
40608
  const feedPolicy = params.policyDefinitions?.[POLICY_TYPE_FEED_IN] || appliedPolicies?.[POLICY_TYPE_FEED_IN];
40578
40609
  params.skipRounds = params.skipRounds || drawSize <= 4 && (feedPolicy?.feedMainFinal ? 0 : 1) || 0;
40610
+ const main = constantToString(MAIN);
40579
40611
  const singleElimination = () => {
40580
40612
  const { matchUps } = treeMatchUps(params);
40581
40613
  const structure = structureTemplate({
40582
- structureName: structureName || MAIN,
40583
40614
  structureId: structureId || uuids?.pop(),
40615
+ structureName: structureName || main,
40584
40616
  stageSequence,
40585
40617
  matchUpType,
40586
40618
  matchUps,
@@ -40591,8 +40623,8 @@ function getGenerators(params) {
40591
40623
  const generators = {
40592
40624
  [AD_HOC]: () => {
40593
40625
  const structure = structureTemplate({
40594
- structureName: structureName || MAIN,
40595
40626
  structureId: structureId || uuids?.pop(),
40627
+ structureName: structureName || main,
40596
40628
  finishingPosition: WIN_RATIO,
40597
40629
  stageSequence,
40598
40630
  matchUps: [],
@@ -40604,8 +40636,8 @@ function getGenerators(params) {
40604
40636
  [LUCKY_DRAW]: () => {
40605
40637
  const { matchUps } = luckyDraw(params);
40606
40638
  const structure = structureTemplate({
40607
- structureName: structureName || MAIN,
40608
40639
  structureId: structureId || uuids?.pop(),
40640
+ structureName: structureName || main,
40609
40641
  stageSequence,
40610
40642
  matchUpType,
40611
40643
  matchUps,
@@ -40631,8 +40663,8 @@ function getGenerators(params) {
40631
40663
  [FEED_IN$1]: () => {
40632
40664
  const { matchUps } = feedInMatchUps({ drawSize, uuids, matchUpType });
40633
40665
  const structure = structureTemplate({
40634
- structureName: structureName || MAIN,
40635
40666
  structureId: structureId || uuids?.pop(),
40667
+ structureName: structureName || main,
40636
40668
  stageSequence,
40637
40669
  matchUpType,
40638
40670
  stage: MAIN,
@@ -43189,8 +43221,11 @@ function generateAndPopulatePlayoffStructures(params) {
43189
43221
  structureId: sourceStructureId,
43190
43222
  addNameBaseToAttributeName,
43191
43223
  playoffStructureNameBase,
43224
+ finishingPositionNaming,
43225
+ finishingPositionLimit,
43192
43226
  playoffAttributes,
43193
43227
  playoffPositions,
43228
+ roundOffsetLimit,
43194
43229
  tournamentRecord,
43195
43230
  exitProfileLimit,
43196
43231
  roundProfiles,
@@ -43295,7 +43330,10 @@ function generateAndPopulatePlayoffStructures(params) {
43295
43330
  drawSize,
43296
43331
  idPrefix,
43297
43332
  isMock,
43298
- uuids
43333
+ uuids,
43334
+ finishingPositionNaming,
43335
+ finishingPositionLimit,
43336
+ roundOffsetLimit
43299
43337
  });
43300
43338
  if (result.error)
43301
43339
  return decorateResult({ result, stack });
@@ -43503,9 +43541,9 @@ function generateVoluntaryConsolation$1(params) {
43503
43541
  return result2;
43504
43542
  }
43505
43543
  tieFormat = copyTieFormat(
43506
- tieFormat || resolveTieFormat({ drawDefinition })?.tieFormat
43544
+ tieFormat ?? resolveTieFormat({ drawDefinition })?.tieFormat
43507
43545
  );
43508
- matchUpType = matchUpType || drawDefinition.matchUpType || TypeEnum.Singles;
43546
+ matchUpType = matchUpType ?? drawDefinition.matchUpType ?? TypeEnum.Singles;
43509
43547
  const { structures: stageStructures } = getDrawStructures({
43510
43548
  stageSequence: 1,
43511
43549
  drawDefinition,
@@ -43513,14 +43551,14 @@ function generateVoluntaryConsolation$1(params) {
43513
43551
  });
43514
43552
  const structureCount = stageStructures.length;
43515
43553
  if (structureCount > 1)
43516
- return { error: INVALID_STRUCTURE };
43554
+ return { error: STAGE_SEQUENCE_LIMIT };
43517
43555
  if (stageStructures?.[0]?.matchUps?.length)
43518
- return { error: INVALID_STRUCTURE };
43556
+ return { error: EXISTING_STRUCTURE };
43519
43557
  const structureId = stageStructures?.[0]?.structureId;
43520
43558
  Object.assign(
43521
43559
  params,
43522
43560
  definedAttributes({
43523
- structureName: params.structureName || VOLUNTARY_CONSOLATION,
43561
+ structureName: params.structureName ?? constantToString(VOLUNTARY_CONSOLATION),
43524
43562
  structureId,
43525
43563
  matchUpType,
43526
43564
  tieFormat,
@@ -50633,9 +50671,6 @@ function formatPersonName({
50633
50671
  if (!person)
50634
50672
  return;
50635
50673
  const spacer = hasSpacing(personFormat) ? " " : "";
50636
- const capitalizeFirst = (str) => str.split(" ").map(
50637
- (name) => name.split("").map((c, i) => i ? c.toLowerCase() : c.toUpperCase()).join("")
50638
- ).join(" ");
50639
50674
  let firstName = capitalizeFirst(person?.standardGivenName ?? "");
50640
50675
  let lastName = capitalizeFirst(person?.standardFamilyName ?? "");
50641
50676
  if (!personFormat)
@@ -58138,7 +58173,7 @@ function generateDrawDefinition(params) {
58138
58173
  }
58139
58174
  } else if (structureId && generateQualifyingPlaceholder) {
58140
58175
  const qualifyingStructure = structureTemplate({
58141
- structureName: QUALIFYING,
58176
+ structureName: constantToString(QUALIFYING),
58142
58177
  stage: QUALIFYING
58143
58178
  });
58144
58179
  const { link } = generateQualifyingLink({
@@ -63392,6 +63427,7 @@ const utilities = {
63392
63427
  structureSort,
63393
63428
  matchUpSort,
63394
63429
  tidyScore,
63430
+ createMap,
63395
63431
  generateScoreString,
63396
63432
  calculateWinCriteria,
63397
63433
  compareTieFormats,