tods-competition-factory 2.2.17 → 2.2.18

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.
@@ -3790,16 +3790,19 @@ declare function generateDrawDefinition(params: GenerateDrawDefinitionArgs): Res
3790
3790
  };
3791
3791
 
3792
3792
  type GenerateQualifyingStructureArgs = {
3793
+ hasExistingDrawDefinition?: boolean;
3793
3794
  appliedPolicies?: PolicyDefinitions;
3794
3795
  qualifyingRoundNumber: number;
3795
3796
  drawDefinition: DrawDefinition;
3796
3797
  qualifyingPositions?: number;
3797
3798
  participantsCount?: number;
3798
3799
  targetStructureId: string;
3800
+ qualifyingOnly?: boolean;
3799
3801
  drawType?: DrawTypeUnion;
3800
3802
  structureOptions?: any;
3801
3803
  matchUpFormat?: string;
3802
3804
  structureName?: string;
3805
+ tieFormat?: TieFormat;
3803
3806
  structureId?: string;
3804
3807
  roundTarget: number;
3805
3808
  drawSize?: number;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.2.17';
6
+ return '2.2.18';
7
7
  }
8
8
 
9
9
  const SINGLES_MATCHUP = 'SINGLES';
@@ -15719,7 +15719,7 @@ const roundRobinGroups = {
15719
15719
  };
15720
15720
 
15721
15721
  function generateRoundRobin(params) {
15722
- const { groupNameBase = 'Group', playoffAttributes, stageSequence = 1, structureOptions, appliedPolicies, seedingProfile, stage = MAIN, matchUpType, roundTarget, structureId, groupNames, drawSize, idPrefix, isMock, uuids, } = params;
15722
+ const { hasExistingDrawDefinition, groupNameBase = 'Group', playoffAttributes, stageSequence = 1, structureOptions, appliedPolicies, qualifyingOnly, seedingProfile, stage = MAIN, matchUpType, roundTarget, structureId, groupNames, tieFormat, drawSize, idPrefix, isMock, uuids, } = params;
15723
15723
  const structureName = params.structureName ?? playoffAttributes?.['0']?.name ?? constantToString(MAIN);
15724
15724
  const { groupCount, groupSize } = deriveGroups({
15725
15725
  structureOptions,
@@ -15741,21 +15741,26 @@ function generateRoundRobin(params) {
15741
15741
  const structureName = groupNames?.[structureOrder - 1] ?? `${groupNameBase} ${structureOrder}`;
15742
15742
  return structureTemplate({
15743
15743
  structureId: uuids?.pop(),
15744
+ hasExistingDrawDefinition,
15744
15745
  structureType: ITEM,
15745
15746
  finishingPosition,
15747
+ qualifyingOnly,
15746
15748
  structureOrder,
15747
15749
  structureName,
15750
+ tieFormat,
15748
15751
  matchUps,
15749
15752
  });
15750
15753
  });
15751
15754
  const structure = structureTemplate({
15752
15755
  structureId: structureId ?? uuids?.pop(),
15756
+ hasExistingDrawDefinition,
15753
15757
  structureType: CONTAINER,
15754
15758
  finishingPosition,
15755
15759
  seedingProfile,
15756
15760
  structureName,
15757
15761
  stageSequence,
15758
15762
  structures,
15763
+ tieFormat,
15759
15764
  stage,
15760
15765
  });
15761
15766
  if (roundTarget)
@@ -20078,6 +20083,38 @@ function generateQualifyingLink({ targetEntryRound = 1, finishingPositions, sour
20078
20083
  return { link };
20079
20084
  }
20080
20085
 
20086
+ function generateTieMatchUps({ matchUp, tieFormat, isMock, uuids }) {
20087
+ const { collectionDefinitions } = tieFormat ?? {};
20088
+ const tieMatchUps = (collectionDefinitions ?? [])
20089
+ .map((collectionDefinition) => generateCollectionMatchUps({ matchUp, collectionDefinition, uuids, isMock }))
20090
+ .filter(Boolean)
20091
+ .flat();
20092
+ return { tieMatchUps };
20093
+ }
20094
+ function generateCollectionMatchUps({ collectionPositionOffset = 0, collectionDefinition, matchUpsLimit, matchUp, isMock, uuids, }) {
20095
+ const { matchUpCount, matchUpType, collectionId, processCodes } = collectionDefinition || {};
20096
+ const numberToGenerate = matchUpsLimit ?? matchUpCount ?? 0;
20097
+ const getMatchUpId = (index) => {
20098
+ if (!isMock && !matchUp?.isMock)
20099
+ return uuids?.pop() ?? UUID();
20100
+ const collectionId = collectionDefinition?.collectionId;
20101
+ return uuids?.pop() ?? `${matchUp?.matchUpId}-${collectionId}-TMU-${index + 1}`;
20102
+ };
20103
+ return generateRange(0, numberToGenerate).map((index) => {
20104
+ const collectionPosition = collectionPositionOffset + index + 1;
20105
+ return {
20106
+ sides: [{ sideNumber: 1 }, { sideNumber: 2 }],
20107
+ matchUpId: getMatchUpId(index),
20108
+ matchUpStatus: TO_BE_PLAYED,
20109
+ collectionPosition,
20110
+ collectionId,
20111
+ processCodes,
20112
+ matchUpType,
20113
+ isMock,
20114
+ };
20115
+ });
20116
+ }
20117
+
20081
20118
  function generateMatchUpId({ roundPosition, roundNumber, idPrefix, uuids }) {
20082
20119
  return idPrefix ? `${idPrefix}-${roundNumber}-${roundPosition}` : uuids?.pop() || UUID();
20083
20120
  }
@@ -20205,7 +20242,7 @@ function generateQualifyingStructure(params) {
20205
20242
  return decorateResult({ result: { error: INVALID_VALUES }, stack });
20206
20243
  }
20207
20244
  let drawSize = params.drawSize ?? coerceEven(params.participantsCount);
20208
- const { qualifyingRoundNumber, qualifyingPositions, targetStructureId, structureOptions, appliedPolicies, drawDefinition, matchUpFormat, structureName, structureId, roundTarget, drawType, idPrefix, isMock, uuids, } = params;
20245
+ const { hasExistingDrawDefinition, qualifyingRoundNumber, qualifyingPositions, targetStructureId, structureOptions, appliedPolicies, qualifyingOnly, drawDefinition, matchUpFormat, structureName, structureId, roundTarget, tieFormat, drawType, idPrefix, isMock, uuids, } = params;
20209
20246
  if (!params.drawSize)
20210
20247
  return decorateResult({
20211
20248
  result: { error: MISSING_DRAW_SIZE },
@@ -20245,12 +20282,15 @@ function generateQualifyingStructure(params) {
20245
20282
  const { maxRoundNumber, structures, groupCount } = generateRoundRobin({
20246
20283
  structureName: structureName ?? qualifyingStructureName,
20247
20284
  structureId: structureId ?? uuids?.pop(),
20285
+ hasExistingDrawDefinition,
20248
20286
  stage: QUALIFYING,
20249
20287
  structureOptions,
20250
20288
  appliedPolicies,
20289
+ qualifyingOnly,
20251
20290
  stageSequence,
20252
20291
  matchUpType,
20253
20292
  roundTarget,
20293
+ tieFormat,
20254
20294
  idPrefix,
20255
20295
  drawSize,
20256
20296
  isMock,
@@ -20302,6 +20342,13 @@ function generateQualifyingStructure(params) {
20302
20342
  finishingPositions,
20303
20343
  linkType,
20304
20344
  })?.link;
20345
+ if (tieFormat) {
20346
+ matchUps = getAllStructureMatchUps({ structure })?.matchUps || [];
20347
+ matchUps?.forEach((matchUp) => {
20348
+ const { tieMatchUps } = generateTieMatchUps({ tieFormat, matchUp, isMock });
20349
+ Object.assign(matchUp, { tieMatchUps, matchUpType });
20350
+ });
20351
+ }
20305
20352
  return {
20306
20353
  qualifyingDrawPositionsCount: drawSize,
20307
20354
  qualifiersCount,
@@ -21518,38 +21565,6 @@ function generatePlayoffLink({ playoffStructureId, finishingPositions, sourceStr
21518
21565
  };
21519
21566
  }
21520
21567
 
21521
- function generateTieMatchUps({ matchUp, tieFormat, isMock, uuids }) {
21522
- const { collectionDefinitions } = tieFormat ?? {};
21523
- const tieMatchUps = (collectionDefinitions ?? [])
21524
- .map((collectionDefinition) => generateCollectionMatchUps({ matchUp, collectionDefinition, uuids, isMock }))
21525
- .filter(Boolean)
21526
- .flat();
21527
- return { tieMatchUps };
21528
- }
21529
- function generateCollectionMatchUps({ collectionPositionOffset = 0, collectionDefinition, matchUpsLimit, matchUp, isMock, uuids, }) {
21530
- const { matchUpCount, matchUpType, collectionId, processCodes } = collectionDefinition || {};
21531
- const numberToGenerate = matchUpsLimit ?? matchUpCount ?? 0;
21532
- const getMatchUpId = (index) => {
21533
- if (!isMock && !matchUp?.isMock)
21534
- return uuids?.pop() ?? UUID();
21535
- const collectionId = collectionDefinition?.collectionId;
21536
- return uuids?.pop() ?? `${matchUp?.matchUpId}-${collectionId}-TMU-${index + 1}`;
21537
- };
21538
- return generateRange(0, numberToGenerate).map((index) => {
21539
- const collectionPosition = collectionPositionOffset + index + 1;
21540
- return {
21541
- sides: [{ sideNumber: 1 }, { sideNumber: 2 }],
21542
- matchUpId: getMatchUpId(index),
21543
- matchUpStatus: TO_BE_PLAYED,
21544
- collectionPosition,
21545
- collectionId,
21546
- processCodes,
21547
- matchUpType,
21548
- isMock,
21549
- };
21550
- });
21551
- }
21552
-
21553
21568
  function generateAndPopulateRRplayoffStructures(params) {
21554
21569
  const stack = 'generateAndPopulateRRplayoffStructures';
21555
21570
  if (!params.playoffGroups) {
@@ -21591,11 +21606,7 @@ function generateAndPopulateRRplayoffStructures(params) {
21591
21606
  const tieFormat = resolveTieFormat({ drawDefinition, event })?.tieFormat;
21592
21607
  if (tieFormat) {
21593
21608
  addedMatchUps.forEach((matchUp) => {
21594
- const { tieMatchUps } = generateTieMatchUps({
21595
- isMock: params.isMock,
21596
- tieFormat,
21597
- matchUp,
21598
- });
21609
+ const { tieMatchUps } = generateTieMatchUps({ isMock: params.isMock, tieFormat, matchUp });
21599
21610
  Object.assign(matchUp, { tieMatchUps, matchUpType: TEAM_MATCHUP });
21600
21611
  });
21601
21612
  }
@@ -27091,12 +27102,15 @@ function generateQualifyingStructures({ hasExistingDrawDefinition, qualifyingPro
27091
27102
  const { structures, groupCount, maxRoundNumber } = generateRoundRobin({
27092
27103
  structureName: structureProfile.structureName || qualifyingStructureName,
27093
27104
  structureId: structureId || uuids?.pop(),
27105
+ hasExistingDrawDefinition,
27094
27106
  stage: QUALIFYING,
27095
27107
  structureOptions,
27096
27108
  appliedPolicies,
27109
+ qualifyingOnly,
27097
27110
  stageSequence,
27098
27111
  matchUpType,
27099
27112
  roundTarget,
27113
+ tieFormat,
27100
27114
  drawSize,
27101
27115
  idPrefix,
27102
27116
  isMock,
@@ -27156,6 +27170,13 @@ function generateQualifyingStructures({ hasExistingDrawDefinition, qualifyingPro
27156
27170
  linkType = drawType === ROUND_ROBIN ? POSITION : WINNER;
27157
27171
  finalQualifyingStructureId = structure.structureId;
27158
27172
  finalQualifyingRoundNumber = roundLimit;
27173
+ if (tieFormat) {
27174
+ matchUps = getAllStructureMatchUps({ structure })?.matchUps || [];
27175
+ matchUps?.forEach((matchUp) => {
27176
+ const { tieMatchUps } = generateTieMatchUps({ tieFormat, matchUp, isMock });
27177
+ Object.assign(matchUp, { tieMatchUps, matchUpType });
27178
+ });
27179
+ }
27159
27180
  structures.push(structure);
27160
27181
  stageSequence += 1;
27161
27182
  }
@@ -27800,11 +27821,7 @@ function generateDrawTypeAndModifyDrawDefinition(params) {
27800
27821
  if (tieFormat) {
27801
27822
  matchUps?.forEach((matchUp) => {
27802
27823
  if (!existingMatchUpIds.includes(matchUp.matchUpId)) {
27803
- const { tieMatchUps } = generateTieMatchUps({
27804
- tieFormat,
27805
- matchUp,
27806
- isMock,
27807
- });
27824
+ const { tieMatchUps } = generateTieMatchUps({ tieFormat, matchUp, isMock });
27808
27825
  Object.assign(matchUp, { tieMatchUps, matchUpType });
27809
27826
  }
27810
27827
  });
@@ -33146,7 +33163,7 @@ function checkTieFormat({ tieFormat }) {
33146
33163
  return { tieFormat };
33147
33164
  }
33148
33165
 
33149
- function checkFormatScopeEquivalence({ tournamentRecord, drawDefinition, matchUpFormat, matchUpType, tieFormat, event, }) {
33166
+ function checkFormatScopeEquivalence({ existingQualifyingStructures, tournamentRecord, drawDefinition, matchUpFormat, matchUpType, tieFormat, event, }) {
33150
33167
  if (matchUpFormat || tieFormat) {
33151
33168
  const equivalentInScope = (matchUpFormat && event?.matchUpFormat === matchUpFormat) ||
33152
33169
  (event?.tieFormat && tieFormat && JSON.stringify(event.tieFormat) === JSON.stringify(tieFormat));
@@ -33155,7 +33172,10 @@ function checkFormatScopeEquivalence({ tournamentRecord, drawDefinition, matchUp
33155
33172
  const result = checkTieFormat({ tieFormat });
33156
33173
  if (result.error)
33157
33174
  return result;
33158
- drawDefinition.tieFormat = result.tieFormat ?? tieFormat;
33175
+ const existingQualifyingTieFormats = existingQualifyingStructures?.every((structure) => structure.tieFormat);
33176
+ if (!existingQualifyingStructures?.length || existingQualifyingTieFormats) {
33177
+ drawDefinition.tieFormat = result.tieFormat ?? tieFormat;
33178
+ }
33159
33179
  }
33160
33180
  else if (matchUpFormat) {
33161
33181
  const result = setMatchUpMatchUpFormat({
@@ -33323,10 +33343,17 @@ function existingPolicyDefinitions({ policyDefinitions, appliedPolicies, policie
33323
33343
  }
33324
33344
 
33325
33345
  function setUpDrawGeneration(params) {
33326
- const { tournamentRecord, matchUpFormat, appliedPolicies, policyDefinitions, matchUpType, tieFormat, drawType, stack, event, } = params;
33346
+ const { tournamentRecord, policyDefinitions, appliedPolicies, matchUpFormat, matchUpType, tieFormat, drawType, stack, event, } = params;
33327
33347
  const existingDrawDefinition = params.drawId
33328
33348
  ? event?.drawDefinitions?.find((d) => d.drawId === params.drawId)
33329
33349
  : undefined;
33350
+ const structureId = existingDrawDefinition?.structures?.find((structure) => structure.stage === MAIN && structure.stageSequence === 1)?.structureId;
33351
+ const existingQualifyingStructures = existingDrawDefinition
33352
+ ? existingDrawDefinition.structures?.filter((structure) => structure.stage === QUALIFYING)
33353
+ : [];
33354
+ const existingQualifyingPlaceholderStructureId = existingQualifyingStructures?.length === 1 &&
33355
+ !existingQualifyingStructures[0].matchUps?.length &&
33356
+ existingQualifyingStructures[0].structureId;
33330
33357
  if (existingDrawDefinition && drawType !== existingDrawDefinition.drawType)
33331
33358
  existingDrawDefinition.drawType = drawType;
33332
33359
  const drawDefinition = existingDrawDefinition ??
@@ -33336,6 +33363,7 @@ function setUpDrawGeneration(params) {
33336
33363
  drawType,
33337
33364
  });
33338
33365
  const equivalenceResult = checkFormatScopeEquivalence({
33366
+ existingQualifyingStructures,
33339
33367
  tournamentRecord,
33340
33368
  drawDefinition,
33341
33369
  matchUpFormat,
@@ -33348,13 +33376,6 @@ function setUpDrawGeneration(params) {
33348
33376
  const attachmentResult = policyAttachment({ appliedPolicies, policyDefinitions, drawDefinition, stack });
33349
33377
  if (attachmentResult.error)
33350
33378
  return attachmentResult;
33351
- const structureId = existingDrawDefinition?.structures?.find((structure) => structure.stage === MAIN && structure.stageSequence === 1)?.structureId;
33352
- const existingQualifyingStructures = existingDrawDefinition
33353
- ? existingDrawDefinition.structures?.filter((structure) => structure.stage === QUALIFYING)
33354
- : [];
33355
- const existingQualifyingPlaceholderStructureId = existingQualifyingStructures?.length === 1 &&
33356
- !existingQualifyingStructures[0].matchUps?.length &&
33357
- existingQualifyingStructures[0].structureId;
33358
33379
  return { drawDefinition, structureId, existingDrawDefinition, existingQualifyingPlaceholderStructureId };
33359
33380
  }
33360
33381