tods-competition-factory 1.6.18 → 1.6.20

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
@@ -329,7 +329,7 @@ const matchUpFormatCode = {
329
329
  };
330
330
 
331
331
  function factoryVersion() {
332
- return "1.6.18";
332
+ return "1.6.20";
333
333
  }
334
334
 
335
335
  function getObjectTieFormat(obj) {
@@ -6195,15 +6195,15 @@ function getRoundMatchUps$1({
6195
6195
  roundIndex += 1;
6196
6196
  }
6197
6197
  });
6198
- const isNotEliminationStructure = !!Object.values(roundProfile).find(
6198
+ const roundsNotPowerOf2 = !!Object.values(roundProfile).find(
6199
6199
  ({ matchUpsCount }) => !isPowerOf2(matchUpsCount)
6200
6200
  );
6201
6201
  const hasNoRoundPositions = matchUps.some(
6202
6202
  (matchUp) => !matchUp.roundPosition
6203
6203
  );
6204
6204
  return {
6205
- isNotEliminationStructure,
6206
6205
  hasNoRoundPositions,
6206
+ roundsNotPowerOf2,
6207
6207
  maxMatchUpsCount,
6208
6208
  roundMatchUps,
6209
6209
  roundNumbers,
@@ -7527,31 +7527,29 @@ function filterMatchUps(params) {
7527
7527
  }
7528
7528
 
7529
7529
  function isLucky({
7530
- isNotEliminationStructure,
7530
+ roundsNotPowerOf2,
7531
7531
  drawDefinition,
7532
- roundMatchUps,
7533
- structure
7532
+ structure,
7533
+ matchUps
7534
7534
  }) {
7535
7535
  if (!structure)
7536
7536
  return false;
7537
- if (!roundMatchUps) {
7538
- ({ isNotEliminationStructure, roundMatchUps } = getRoundMatchUps$1({
7539
- matchUps: structure.matchUps ?? []
7540
- }));
7541
- }
7542
- const hasFirstRoundDrawPositions = !!roundMatchUps?.[1]?.find(
7543
- ({ drawPositions }) => drawPositions
7544
- );
7545
- const noSecondRoundDrawPositions = !roundMatchUps?.[2]?.find(
7546
- ({ drawPositions }) => drawPositions
7547
- );
7548
- return isNotEliminationStructure && !structure?.structures && hasFirstRoundDrawPositions && noSecondRoundDrawPositions && !(drawDefinition?.drawType && drawDefinition.drawType !== LUCKY_DRAW);
7537
+ matchUps = matchUps ?? structure.matchUps ?? [];
7538
+ roundsNotPowerOf2 = roundsNotPowerOf2 ?? getRoundMatchUps$1({ matchUps }).roundsNotPowerOf2;
7539
+ const hasDrawPositions = !!structure.positionAssignments?.find(({ drawPosition }) => drawPosition) || !!matchUps?.find(({ drawPositions }) => drawPositions?.length);
7540
+ return (!drawDefinition?.drawType || drawDefinition.drawType !== LUCKY_DRAW) && !structure?.structures && roundsNotPowerOf2 && hasDrawPositions;
7549
7541
  }
7550
7542
 
7551
7543
  function isAdHoc({ drawDefinition, structure }) {
7552
7544
  if (!structure)
7553
7545
  return false;
7554
- return !structure?.structures && !(drawDefinition?.drawType && drawDefinition.drawType !== AD_HOC) && !structure?.matchUps?.find(({ roundPosition }) => !!roundPosition);
7546
+ const hasRoundPosition = structure?.matchUps?.find(
7547
+ (matchUp) => matchUp?.roundPosition
7548
+ );
7549
+ const hasDrawPosition = structure?.matchUps?.find(
7550
+ (matchUp) => matchUp?.drawPositions?.length
7551
+ );
7552
+ return !structure?.structures && !(drawDefinition?.drawType && drawDefinition.drawType !== AD_HOC) && !hasRoundPosition && !hasDrawPosition;
7555
7553
  }
7556
7554
 
7557
7555
  const POLICY_ROUND_NAMING_DEFAULT = {
@@ -7586,14 +7584,10 @@ function getRoundContextProfile({
7586
7584
  structure,
7587
7585
  matchUps
7588
7586
  }) {
7589
- const { isNotEliminationStructure, roundProfile, roundMatchUps } = getRoundMatchUps$1({ matchUps });
7587
+ const { roundProfile, roundMatchUps } = getRoundMatchUps$1({ matchUps });
7590
7588
  const { structureAbbreviation, stage } = structure;
7591
7589
  const isAdHocStructure = isAdHoc({ structure });
7592
- const isLuckyStructure = isLucky({
7593
- isNotEliminationStructure,
7594
- roundMatchUps,
7595
- structure
7596
- });
7590
+ const isLuckyStructure = isLucky({ structure });
7597
7591
  const isRoundRobin = structure.structures;
7598
7592
  const roundNamingProfile = {};
7599
7593
  const defaultRoundNamingPolicy = POLICY_ROUND_NAMING_DEFAULT[POLICY_TYPE_ROUND_NAMING];
@@ -23020,7 +23014,7 @@ function getValidSeedBlocks({
23020
23014
  let validSeedBlocks = [];
23021
23015
  if (!structure)
23022
23016
  return { error: MISSING_STRUCTURE };
23023
- const { roundMatchUps } = getAllStructureMatchUps({
23017
+ const { matchUps, roundMatchUps } = getAllStructureMatchUps({
23024
23018
  matchUpFilters: { roundNumbers: [1] },
23025
23019
  provisionalPositioning,
23026
23020
  structure
@@ -23053,12 +23047,16 @@ function getValidSeedBlocks({
23053
23047
  const { stage, structureType, roundLimit } = structure;
23054
23048
  const isContainer = structureType === CONTAINER;
23055
23049
  const isFeedIn = !isContainer && uniqueDrawPositionsByRound?.length;
23056
- const isLucky = firstRoundDrawPositions?.length && !isPowerOf2(baseDrawSize);
23057
23050
  const qualifyingBlocks = !isContainer && stage === QUALIFYING && roundLimit;
23058
23051
  const fedSeedBlockPositions = seedRangeDrawPositionBlocks.flat(Infinity);
23059
23052
  const fedSeedNumberOffset = isFeedIn ? fedSeedBlockPositions?.length : 0;
23060
23053
  const countLimit = allPositions ? positionsCount : seedsCount;
23061
- const firstRoundSeedsCount = isLucky ? 0 : !isFeedIn && countLimit || countLimit && fedSeedBlockPositions.length < countLimit && countLimit - fedSeedBlockPositions.length || 0;
23054
+ const isLuckyStructure = isLucky({
23055
+ drawDefinition,
23056
+ structure,
23057
+ matchUps
23058
+ });
23059
+ const firstRoundSeedsCount = isLuckyStructure ? 0 : !isFeedIn && countLimit || countLimit && fedSeedBlockPositions.length < countLimit && countLimit - fedSeedBlockPositions.length || 0;
23062
23060
  if (qualifyingBlocks) {
23063
23061
  const seedingBlocksCount = structure?.matchUps ? structure.matchUps.filter(
23064
23062
  ({ roundNumber }) => roundNumber === structure.roundLimit
@@ -23094,14 +23092,14 @@ function getValidSeedBlocks({
23094
23092
  validSeedBlocks = seedRangeDrawPositionBlocks.map((block) => {
23095
23093
  return { seedNumbers: block, drawPositions: block };
23096
23094
  });
23097
- } else if (isLucky) {
23095
+ } else if (isLuckyStructure) {
23098
23096
  const blocks = chunkArray(firstRoundDrawPositions, 2).map((block, i) => ({
23099
23097
  drawPositions: [block[0]],
23100
23098
  seedNumbers: [i + 1]
23101
23099
  }));
23102
23100
  blocks.forEach((block) => validSeedBlocks.push(block));
23103
23101
  }
23104
- if (!isContainer && !isLucky && !qualifyingBlocks) {
23102
+ if (!isContainer && !isLuckyStructure && !qualifyingBlocks) {
23105
23103
  const { blocks } = constructPower2Blocks({
23106
23104
  drawPositionOffset: firstRoundDrawPositionOffset,
23107
23105
  seedNumberOffset: fedSeedNumberOffset,
@@ -23120,7 +23118,7 @@ function getValidSeedBlocks({
23120
23118
  },
23121
23119
  true
23122
23120
  );
23123
- if (!isLucky && !isFeedIn && !isContainer && !validSeedPositions) {
23121
+ if (!isLuckyStructure && !isFeedIn && !isContainer && !validSeedPositions) {
23124
23122
  return {
23125
23123
  error: INVALID_SEED_POSITION,
23126
23124
  validSeedBlocks: [],
@@ -23129,10 +23127,10 @@ function getValidSeedBlocks({
23129
23127
  };
23130
23128
  }
23131
23129
  return {
23130
+ isLuckyStructure,
23132
23131
  validSeedBlocks,
23133
23132
  isContainer,
23134
- isFeedIn,
23135
- isLucky
23133
+ isFeedIn
23136
23134
  };
23137
23135
  }
23138
23136
  function getContainerBlocks({ seedingProfile, structure }) {
@@ -23475,6 +23473,75 @@ function getTargetMatchUps({
23475
23473
  return { drawPositions, matchUps, targetMatchUps };
23476
23474
  }
23477
23475
 
23476
+ function validateLineUp({ lineUp, tieFormat }) {
23477
+ const errors = [];
23478
+ if (!Array.isArray(lineUp)) {
23479
+ errors.push(mustBeAnArray("lineUp"));
23480
+ return { valid: false, errors, error: INVALID_VALUES };
23481
+ }
23482
+ const validItems = lineUp.every((item) => {
23483
+ if (typeof item !== "object") {
23484
+ errors.push(`lineUp entries must be objects`);
23485
+ return false;
23486
+ }
23487
+ const { participantId, collectionAssignments } = item;
23488
+ if (!participantId) {
23489
+ errors.push("Missing participantId");
23490
+ return false;
23491
+ }
23492
+ if (typeof participantId !== "string") {
23493
+ errors.push("participantIds must be strings");
23494
+ return false;
23495
+ }
23496
+ if (!Array.isArray(collectionAssignments)) {
23497
+ errors.push(mustBeAnArray("collectionAssignments"));
23498
+ return false;
23499
+ }
23500
+ return collectionAssignments.every((collectionAssignment) => {
23501
+ if (typeof collectionAssignment !== "object") {
23502
+ errors.push("collectionAssignments must be objects");
23503
+ return false;
23504
+ }
23505
+ const { collectionPosition } = collectionAssignment;
23506
+ if (typeof collectionPosition !== "number") {
23507
+ errors.push("collectionPosition must be a number");
23508
+ return false;
23509
+ }
23510
+ return true;
23511
+ });
23512
+ });
23513
+ const noDuplicates = unique(lineUp.map(getParticipantId)).length === lineUp.length;
23514
+ if (!noDuplicates)
23515
+ errors.push("Duplicated participantId(s)");
23516
+ const valid = validItems && noDuplicates;
23517
+ return { valid, errors, error: errors.length ? INVALID_VALUES : void 0 };
23518
+ }
23519
+
23520
+ function updateTeamLineUp({
23521
+ drawDefinition,
23522
+ participantId,
23523
+ tieFormat,
23524
+ lineUp
23525
+ }) {
23526
+ if (typeof drawDefinition !== "object")
23527
+ return { error: MISSING_DRAW_DEFINITION };
23528
+ if (typeof participantId !== "string")
23529
+ return { error: MISSING_PARTICIPANT_ID };
23530
+ const validation = validateLineUp({ lineUp, tieFormat });
23531
+ if (!validation.valid)
23532
+ return validation;
23533
+ const { extension: existingExtension } = findExtension({
23534
+ element: drawDefinition,
23535
+ name: LINEUPS
23536
+ });
23537
+ const value = existingExtension?.value || {};
23538
+ value[participantId] = removeLineUpSubstitutions({ lineUp });
23539
+ const extension = { name: LINEUPS, value };
23540
+ addExtension$1({ element: drawDefinition, extension });
23541
+ addDrawNotice({ drawDefinition });
23542
+ return { ...SUCCESS };
23543
+ }
23544
+
23478
23545
  function resetLineUps({
23479
23546
  inContextDrawMatchUps,
23480
23547
  inheritance = true,
@@ -23502,10 +23569,18 @@ function resetLineUps({
23502
23569
  ({ matchUpId }) => matchUpId === inContextMatchUp.matchUpId
23503
23570
  );
23504
23571
  if (matchUp?.sides?.[sideIndex]) {
23505
- if (inheritance) {
23506
- delete matchUp.sides[sideIndex].lineUp;
23507
- } else {
23508
- matchUp.sides[sideIndex].lineUp = [];
23572
+ delete matchUp.sides[sideIndex].lineUp;
23573
+ if (inheritance === false) {
23574
+ const tieFormat = inContextMatchUp.tieFormat;
23575
+ const participantId = side.participantId;
23576
+ if (tieFormat && participantId) {
23577
+ updateTeamLineUp({
23578
+ drawDefinition,
23579
+ participantId,
23580
+ lineUp: [],
23581
+ tieFormat
23582
+ });
23583
+ }
23509
23584
  }
23510
23585
  modifyMatchUpNotice({
23511
23586
  tournamentId: tournamentRecord?.tournamentId,
@@ -40274,7 +40349,7 @@ function getSeedOrderByePositions({
40274
40349
  structure
40275
40350
  });
40276
40351
  }
40277
- const { isFeedIn, isLucky, isContainer } = seedBlockInfo;
40352
+ const { isFeedIn, isLuckyStructure, isContainer } = seedBlockInfo;
40278
40353
  let { validSeedBlocks } = seedBlockInfo;
40279
40354
  if (appliedPolicies?.seeding?.containerByesIgnoreSeeding)
40280
40355
  validSeedBlocks = [];
@@ -40318,10 +40393,10 @@ function getSeedOrderByePositions({
40318
40393
  return {
40319
40394
  strictSeedOrderByePositions,
40320
40395
  blockSeedOrderByePositions,
40396
+ isLuckyStructure,
40321
40397
  positionedSeeds,
40322
40398
  isContainer,
40323
- isFeedIn,
40324
- isLucky
40399
+ isFeedIn
40325
40400
  };
40326
40401
  }
40327
40402
  function getOrderedByePositions({
@@ -40348,12 +40423,12 @@ function getOrderedByePositions({
40348
40423
  function getUnseededByePositions({
40349
40424
  provisionalPositioning,
40350
40425
  seedOrderByePositions,
40426
+ isLuckyStructure,
40351
40427
  appliedPolicies,
40352
40428
  drawDefinition,
40353
40429
  seedLimit,
40354
40430
  structure,
40355
- isFeedIn,
40356
- isLucky
40431
+ isFeedIn
40357
40432
  }) {
40358
40433
  const seedingProfile = appliedPolicies?.seeding?.seedingProfile;
40359
40434
  const isQualifying = structure.stage === QUALIFYING;
@@ -40571,8 +40646,8 @@ function positionByes({
40571
40646
  const {
40572
40647
  strictSeedOrderByePositions,
40573
40648
  blockSeedOrderByePositions,
40574
- isFeedIn,
40575
- isLucky
40649
+ isLuckyStructure,
40650
+ isFeedIn
40576
40651
  } = getSeedOrderByePositions({
40577
40652
  provisionalPositioning,
40578
40653
  relevantMatchUps,
@@ -40587,12 +40662,12 @@ function positionByes({
40587
40662
  let { unseededByePositions } = getUnseededByePositions({
40588
40663
  provisionalPositioning,
40589
40664
  seedOrderByePositions,
40665
+ isLuckyStructure,
40590
40666
  appliedPolicies,
40591
40667
  drawDefinition,
40592
40668
  seedLimit,
40593
40669
  structure,
40594
- isFeedIn,
40595
- isLucky
40670
+ isFeedIn
40596
40671
  });
40597
40672
  const isOdd = (x) => x % 2;
40598
40673
  const isNotPaired = (arr, c) => (arr || []).every((a) => isOdd(a) ? c !== a + 1 : c !== a - 1);
@@ -44598,28 +44673,40 @@ function roundRobinSwap({
44598
44673
  }
44599
44674
 
44600
44675
  function resetMatchUpLineUps$1({
44676
+ inheritance = true,
44601
44677
  tournamentRecord,
44602
44678
  drawDefinition,
44603
- inheritance,
44604
44679
  matchUpId,
44605
44680
  event
44606
44681
  }) {
44607
44682
  if (!drawDefinition)
44608
44683
  return { error: MISSING_DRAW_DEFINITION };
44609
44684
  const matchUp = findMatchUp$1({
44610
- inContext: true,
44611
44685
  drawDefinition,
44612
44686
  matchUpId
44613
44687
  })?.matchUp;
44614
- if (matchUp?.matchUpType !== TEAM_MATCHUP)
44688
+ if (!matchUp?.tieMatchUps)
44615
44689
  return { error: INVALID_MATCHUP };
44616
44690
  let modificationsCount = 0;
44617
44691
  (matchUp.sides || []).forEach((side) => {
44618
44692
  modificationsCount += 1;
44619
- if (inheritance) {
44620
- delete side.lineUp;
44621
- } else {
44622
- side.lineUp = [];
44693
+ delete side.lineUp;
44694
+ if (inheritance === false) {
44695
+ const inContextMatchUp = findMatchUp$1({
44696
+ inContext: true,
44697
+ drawDefinition,
44698
+ matchUpId
44699
+ })?.matchUp;
44700
+ const tieFormat = inContextMatchUp?.tieFormat;
44701
+ const participantId = side.participantId;
44702
+ if (tieFormat && participantId) {
44703
+ updateTeamLineUp({
44704
+ drawDefinition,
44705
+ participantId,
44706
+ lineUp: [],
44707
+ tieFormat
44708
+ });
44709
+ }
44623
44710
  }
44624
44711
  modifyMatchUpNotice({
44625
44712
  tournamentId: tournamentRecord?.tournamentId,
@@ -51369,75 +51456,6 @@ function removeCollectionAssignments({
51369
51456
  return { modifiedLineUp, assignmentsRemoved, previousParticipantIds };
51370
51457
  }
51371
51458
 
51372
- function validateLineUp({ lineUp, tieFormat }) {
51373
- const errors = [];
51374
- if (!Array.isArray(lineUp)) {
51375
- errors.push(mustBeAnArray("lineUp"));
51376
- return { valid: false, errors, error: INVALID_VALUES };
51377
- }
51378
- const validItems = lineUp.every((item) => {
51379
- if (typeof item !== "object") {
51380
- errors.push(`lineUp entries must be objects`);
51381
- return false;
51382
- }
51383
- const { participantId, collectionAssignments } = item;
51384
- if (!participantId) {
51385
- errors.push("Missing participantId");
51386
- return false;
51387
- }
51388
- if (typeof participantId !== "string") {
51389
- errors.push("participantIds must be strings");
51390
- return false;
51391
- }
51392
- if (!Array.isArray(collectionAssignments)) {
51393
- errors.push(mustBeAnArray("collectionAssignments"));
51394
- return false;
51395
- }
51396
- return collectionAssignments.every((collectionAssignment) => {
51397
- if (typeof collectionAssignment !== "object") {
51398
- errors.push("collectionAssignments must be objects");
51399
- return false;
51400
- }
51401
- const { collectionPosition } = collectionAssignment;
51402
- if (typeof collectionPosition !== "number") {
51403
- errors.push("collectionPosition must be a number");
51404
- return false;
51405
- }
51406
- return true;
51407
- });
51408
- });
51409
- const noDuplicates = unique(lineUp.map(getParticipantId)).length === lineUp.length;
51410
- if (!noDuplicates)
51411
- errors.push("Duplicated participantId(s)");
51412
- const valid = validItems && noDuplicates;
51413
- return { valid, errors, error: errors.length ? INVALID_VALUES : void 0 };
51414
- }
51415
-
51416
- function updateTeamLineUp({
51417
- drawDefinition,
51418
- participantId,
51419
- tieFormat,
51420
- lineUp
51421
- }) {
51422
- if (typeof drawDefinition !== "object")
51423
- return { error: MISSING_DRAW_DEFINITION };
51424
- if (typeof participantId !== "string")
51425
- return { error: MISSING_PARTICIPANT_ID };
51426
- const validation = validateLineUp({ lineUp, tieFormat });
51427
- if (!validation.valid)
51428
- return validation;
51429
- const { extension: existingExtension } = findExtension({
51430
- element: drawDefinition,
51431
- name: LINEUPS
51432
- });
51433
- const value = existingExtension?.value || {};
51434
- value[participantId] = removeLineUpSubstitutions({ lineUp });
51435
- const extension = { name: LINEUPS, value };
51436
- addExtension$1({ element: drawDefinition, extension });
51437
- addDrawNotice({ drawDefinition });
51438
- return { ...SUCCESS };
51439
- }
51440
-
51441
51459
  function getTieMatchUpContext({
51442
51460
  tournamentRecord,
51443
51461
  drawDefinition,