tods-competition-factory 1.6.19 → 1.6.21

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.19";
332
+ return "1.6.21";
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,28 @@ 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 matchUps = structure.matchUps || structure.roundMatchUps && Object.values(structure.roundMatchUps).flat();
7547
+ const hasRoundPosition = matchUps?.find((matchUp) => matchUp?.roundPosition);
7548
+ const hasDrawPosition = matchUps?.find(
7549
+ (matchUp) => matchUp?.drawPositions?.length
7550
+ );
7551
+ return !structure?.structures && !(drawDefinition?.drawType && drawDefinition.drawType !== AD_HOC) && !hasRoundPosition && !hasDrawPosition;
7555
7552
  }
7556
7553
 
7557
7554
  const POLICY_ROUND_NAMING_DEFAULT = {
@@ -7586,14 +7583,10 @@ function getRoundContextProfile({
7586
7583
  structure,
7587
7584
  matchUps
7588
7585
  }) {
7589
- const { isNotEliminationStructure, roundProfile, roundMatchUps } = getRoundMatchUps$1({ matchUps });
7586
+ const { roundProfile, roundMatchUps } = getRoundMatchUps$1({ matchUps });
7590
7587
  const { structureAbbreviation, stage } = structure;
7591
7588
  const isAdHocStructure = isAdHoc({ structure });
7592
- const isLuckyStructure = isLucky({
7593
- isNotEliminationStructure,
7594
- roundMatchUps,
7595
- structure
7596
- });
7589
+ const isLuckyStructure = isLucky({ structure });
7597
7590
  const isRoundRobin = structure.structures;
7598
7591
  const roundNamingProfile = {};
7599
7592
  const defaultRoundNamingPolicy = POLICY_ROUND_NAMING_DEFAULT[POLICY_TYPE_ROUND_NAMING];
@@ -7838,8 +7831,8 @@ function getAllStructureMatchUps({
7838
7831
  matchUpsMap,
7839
7832
  structureId
7840
7833
  }).drawPositionsRanges : void 0;
7841
- matchUps = matchUps.map(
7842
- (matchUp) => addMatchUpContext({
7834
+ matchUps = matchUps.map((matchUp) => {
7835
+ return addMatchUpContext({
7843
7836
  scheduleVisibilityFilters,
7844
7837
  sourceDrawPositionRanges,
7845
7838
  drawPositionsRanges,
@@ -7850,8 +7843,8 @@ function getAllStructureMatchUps({
7850
7843
  roundProfile,
7851
7844
  matchUp,
7852
7845
  event
7853
- })
7854
- );
7846
+ });
7847
+ });
7855
7848
  const matchUpTies = matchUps?.filter(
7856
7849
  (matchUp) => Array.isArray(matchUp.tieMatchUps)
7857
7850
  );
@@ -23020,7 +23013,7 @@ function getValidSeedBlocks({
23020
23013
  let validSeedBlocks = [];
23021
23014
  if (!structure)
23022
23015
  return { error: MISSING_STRUCTURE };
23023
- const { roundMatchUps } = getAllStructureMatchUps({
23016
+ const { matchUps, roundMatchUps } = getAllStructureMatchUps({
23024
23017
  matchUpFilters: { roundNumbers: [1] },
23025
23018
  provisionalPositioning,
23026
23019
  structure
@@ -23053,12 +23046,16 @@ function getValidSeedBlocks({
23053
23046
  const { stage, structureType, roundLimit } = structure;
23054
23047
  const isContainer = structureType === CONTAINER;
23055
23048
  const isFeedIn = !isContainer && uniqueDrawPositionsByRound?.length;
23056
- const isLucky = firstRoundDrawPositions?.length && !isPowerOf2(baseDrawSize);
23057
23049
  const qualifyingBlocks = !isContainer && stage === QUALIFYING && roundLimit;
23058
23050
  const fedSeedBlockPositions = seedRangeDrawPositionBlocks.flat(Infinity);
23059
23051
  const fedSeedNumberOffset = isFeedIn ? fedSeedBlockPositions?.length : 0;
23060
23052
  const countLimit = allPositions ? positionsCount : seedsCount;
23061
- const firstRoundSeedsCount = isLucky ? 0 : !isFeedIn && countLimit || countLimit && fedSeedBlockPositions.length < countLimit && countLimit - fedSeedBlockPositions.length || 0;
23053
+ const isLuckyStructure = isLucky({
23054
+ drawDefinition,
23055
+ structure,
23056
+ matchUps
23057
+ });
23058
+ const firstRoundSeedsCount = isLuckyStructure ? 0 : !isFeedIn && countLimit || countLimit && fedSeedBlockPositions.length < countLimit && countLimit - fedSeedBlockPositions.length || 0;
23062
23059
  if (qualifyingBlocks) {
23063
23060
  const seedingBlocksCount = structure?.matchUps ? structure.matchUps.filter(
23064
23061
  ({ roundNumber }) => roundNumber === structure.roundLimit
@@ -23094,14 +23091,14 @@ function getValidSeedBlocks({
23094
23091
  validSeedBlocks = seedRangeDrawPositionBlocks.map((block) => {
23095
23092
  return { seedNumbers: block, drawPositions: block };
23096
23093
  });
23097
- } else if (isLucky) {
23094
+ } else if (isLuckyStructure) {
23098
23095
  const blocks = chunkArray(firstRoundDrawPositions, 2).map((block, i) => ({
23099
23096
  drawPositions: [block[0]],
23100
23097
  seedNumbers: [i + 1]
23101
23098
  }));
23102
23099
  blocks.forEach((block) => validSeedBlocks.push(block));
23103
23100
  }
23104
- if (!isContainer && !isLucky && !qualifyingBlocks) {
23101
+ if (!isContainer && !isLuckyStructure && !qualifyingBlocks) {
23105
23102
  const { blocks } = constructPower2Blocks({
23106
23103
  drawPositionOffset: firstRoundDrawPositionOffset,
23107
23104
  seedNumberOffset: fedSeedNumberOffset,
@@ -23120,7 +23117,7 @@ function getValidSeedBlocks({
23120
23117
  },
23121
23118
  true
23122
23119
  );
23123
- if (!isLucky && !isFeedIn && !isContainer && !validSeedPositions) {
23120
+ if (!isLuckyStructure && !isFeedIn && !isContainer && !validSeedPositions) {
23124
23121
  return {
23125
23122
  error: INVALID_SEED_POSITION,
23126
23123
  validSeedBlocks: [],
@@ -23129,10 +23126,10 @@ function getValidSeedBlocks({
23129
23126
  };
23130
23127
  }
23131
23128
  return {
23129
+ isLuckyStructure,
23132
23130
  validSeedBlocks,
23133
23131
  isContainer,
23134
- isFeedIn,
23135
- isLucky
23132
+ isFeedIn
23136
23133
  };
23137
23134
  }
23138
23135
  function getContainerBlocks({ seedingProfile, structure }) {
@@ -23475,6 +23472,75 @@ function getTargetMatchUps({
23475
23472
  return { drawPositions, matchUps, targetMatchUps };
23476
23473
  }
23477
23474
 
23475
+ function validateLineUp({ lineUp, tieFormat }) {
23476
+ const errors = [];
23477
+ if (!Array.isArray(lineUp)) {
23478
+ errors.push(mustBeAnArray("lineUp"));
23479
+ return { valid: false, errors, error: INVALID_VALUES };
23480
+ }
23481
+ const validItems = lineUp.every((item) => {
23482
+ if (typeof item !== "object") {
23483
+ errors.push(`lineUp entries must be objects`);
23484
+ return false;
23485
+ }
23486
+ const { participantId, collectionAssignments } = item;
23487
+ if (!participantId) {
23488
+ errors.push("Missing participantId");
23489
+ return false;
23490
+ }
23491
+ if (typeof participantId !== "string") {
23492
+ errors.push("participantIds must be strings");
23493
+ return false;
23494
+ }
23495
+ if (!Array.isArray(collectionAssignments)) {
23496
+ errors.push(mustBeAnArray("collectionAssignments"));
23497
+ return false;
23498
+ }
23499
+ return collectionAssignments.every((collectionAssignment) => {
23500
+ if (typeof collectionAssignment !== "object") {
23501
+ errors.push("collectionAssignments must be objects");
23502
+ return false;
23503
+ }
23504
+ const { collectionPosition } = collectionAssignment;
23505
+ if (typeof collectionPosition !== "number") {
23506
+ errors.push("collectionPosition must be a number");
23507
+ return false;
23508
+ }
23509
+ return true;
23510
+ });
23511
+ });
23512
+ const noDuplicates = unique(lineUp.map(getParticipantId)).length === lineUp.length;
23513
+ if (!noDuplicates)
23514
+ errors.push("Duplicated participantId(s)");
23515
+ const valid = validItems && noDuplicates;
23516
+ return { valid, errors, error: errors.length ? INVALID_VALUES : void 0 };
23517
+ }
23518
+
23519
+ function updateTeamLineUp({
23520
+ drawDefinition,
23521
+ participantId,
23522
+ tieFormat,
23523
+ lineUp
23524
+ }) {
23525
+ if (typeof drawDefinition !== "object")
23526
+ return { error: MISSING_DRAW_DEFINITION };
23527
+ if (typeof participantId !== "string")
23528
+ return { error: MISSING_PARTICIPANT_ID };
23529
+ const validation = validateLineUp({ lineUp, tieFormat });
23530
+ if (!validation.valid)
23531
+ return validation;
23532
+ const { extension: existingExtension } = findExtension({
23533
+ element: drawDefinition,
23534
+ name: LINEUPS
23535
+ });
23536
+ const value = existingExtension?.value || {};
23537
+ value[participantId] = removeLineUpSubstitutions({ lineUp });
23538
+ const extension = { name: LINEUPS, value };
23539
+ addExtension$1({ element: drawDefinition, extension });
23540
+ addDrawNotice({ drawDefinition });
23541
+ return { ...SUCCESS };
23542
+ }
23543
+
23478
23544
  function resetLineUps({
23479
23545
  inContextDrawMatchUps,
23480
23546
  inheritance = true,
@@ -23502,10 +23568,18 @@ function resetLineUps({
23502
23568
  ({ matchUpId }) => matchUpId === inContextMatchUp.matchUpId
23503
23569
  );
23504
23570
  if (matchUp?.sides?.[sideIndex]) {
23505
- if (inheritance) {
23506
- delete matchUp.sides[sideIndex].lineUp;
23507
- } else {
23508
- matchUp.sides[sideIndex].lineUp = [];
23571
+ delete matchUp.sides[sideIndex].lineUp;
23572
+ if (inheritance === false) {
23573
+ const tieFormat = inContextMatchUp.tieFormat;
23574
+ const participantId = side.participantId;
23575
+ if (tieFormat && participantId) {
23576
+ updateTeamLineUp({
23577
+ drawDefinition,
23578
+ participantId,
23579
+ lineUp: [],
23580
+ tieFormat
23581
+ });
23582
+ }
23509
23583
  }
23510
23584
  modifyMatchUpNotice({
23511
23585
  tournamentId: tournamentRecord?.tournamentId,
@@ -40274,7 +40348,7 @@ function getSeedOrderByePositions({
40274
40348
  structure
40275
40349
  });
40276
40350
  }
40277
- const { isFeedIn, isLucky, isContainer } = seedBlockInfo;
40351
+ const { isFeedIn, isLuckyStructure, isContainer } = seedBlockInfo;
40278
40352
  let { validSeedBlocks } = seedBlockInfo;
40279
40353
  if (appliedPolicies?.seeding?.containerByesIgnoreSeeding)
40280
40354
  validSeedBlocks = [];
@@ -40318,10 +40392,10 @@ function getSeedOrderByePositions({
40318
40392
  return {
40319
40393
  strictSeedOrderByePositions,
40320
40394
  blockSeedOrderByePositions,
40395
+ isLuckyStructure,
40321
40396
  positionedSeeds,
40322
40397
  isContainer,
40323
- isFeedIn,
40324
- isLucky
40398
+ isFeedIn
40325
40399
  };
40326
40400
  }
40327
40401
  function getOrderedByePositions({
@@ -40348,12 +40422,12 @@ function getOrderedByePositions({
40348
40422
  function getUnseededByePositions({
40349
40423
  provisionalPositioning,
40350
40424
  seedOrderByePositions,
40425
+ isLuckyStructure,
40351
40426
  appliedPolicies,
40352
40427
  drawDefinition,
40353
40428
  seedLimit,
40354
40429
  structure,
40355
- isFeedIn,
40356
- isLucky
40430
+ isFeedIn
40357
40431
  }) {
40358
40432
  const seedingProfile = appliedPolicies?.seeding?.seedingProfile;
40359
40433
  const isQualifying = structure.stage === QUALIFYING;
@@ -40571,8 +40645,8 @@ function positionByes({
40571
40645
  const {
40572
40646
  strictSeedOrderByePositions,
40573
40647
  blockSeedOrderByePositions,
40574
- isFeedIn,
40575
- isLucky
40648
+ isLuckyStructure,
40649
+ isFeedIn
40576
40650
  } = getSeedOrderByePositions({
40577
40651
  provisionalPositioning,
40578
40652
  relevantMatchUps,
@@ -40587,12 +40661,12 @@ function positionByes({
40587
40661
  let { unseededByePositions } = getUnseededByePositions({
40588
40662
  provisionalPositioning,
40589
40663
  seedOrderByePositions,
40664
+ isLuckyStructure,
40590
40665
  appliedPolicies,
40591
40666
  drawDefinition,
40592
40667
  seedLimit,
40593
40668
  structure,
40594
- isFeedIn,
40595
- isLucky
40669
+ isFeedIn
40596
40670
  });
40597
40671
  const isOdd = (x) => x % 2;
40598
40672
  const isNotPaired = (arr, c) => (arr || []).every((a) => isOdd(a) ? c !== a + 1 : c !== a - 1);
@@ -44598,9 +44672,9 @@ function roundRobinSwap({
44598
44672
  }
44599
44673
 
44600
44674
  function resetMatchUpLineUps$1({
44675
+ inheritance = true,
44601
44676
  tournamentRecord,
44602
44677
  drawDefinition,
44603
- inheritance,
44604
44678
  matchUpId,
44605
44679
  event
44606
44680
  }) {
@@ -44612,17 +44686,34 @@ function resetMatchUpLineUps$1({
44612
44686
  })?.matchUp;
44613
44687
  if (!matchUp?.tieMatchUps)
44614
44688
  return { error: INVALID_MATCHUP };
44689
+ const inContextMatchUp = findMatchUp$1({
44690
+ inContext: true,
44691
+ drawDefinition,
44692
+ matchUpId,
44693
+ event
44694
+ })?.matchUp;
44615
44695
  let modificationsCount = 0;
44616
- (matchUp.sides || []).forEach((side) => {
44617
- modificationsCount += 1;
44618
- if (inheritance) {
44696
+ (matchUp?.sides || []).forEach((side) => {
44697
+ if (side.lineUp)
44619
44698
  delete side.lineUp;
44620
- } else {
44621
- side.lineUp = [];
44699
+ });
44700
+ (inContextMatchUp?.sides || []).forEach((side) => {
44701
+ modificationsCount += 1;
44702
+ if (inheritance === false) {
44703
+ const tieFormat = inContextMatchUp?.tieFormat;
44704
+ const participantId = side.participantId;
44705
+ if (tieFormat && participantId) {
44706
+ updateTeamLineUp({
44707
+ drawDefinition,
44708
+ participantId,
44709
+ lineUp: [],
44710
+ tieFormat
44711
+ });
44712
+ }
44622
44713
  }
44623
44714
  modifyMatchUpNotice({
44624
44715
  tournamentId: tournamentRecord?.tournamentId,
44625
- context: "resetLineUps",
44716
+ context: "resetMatchUpLineUps",
44626
44717
  eventId: event?.eventId,
44627
44718
  drawDefinition,
44628
44719
  matchUp
@@ -51368,75 +51459,6 @@ function removeCollectionAssignments({
51368
51459
  return { modifiedLineUp, assignmentsRemoved, previousParticipantIds };
51369
51460
  }
51370
51461
 
51371
- function validateLineUp({ lineUp, tieFormat }) {
51372
- const errors = [];
51373
- if (!Array.isArray(lineUp)) {
51374
- errors.push(mustBeAnArray("lineUp"));
51375
- return { valid: false, errors, error: INVALID_VALUES };
51376
- }
51377
- const validItems = lineUp.every((item) => {
51378
- if (typeof item !== "object") {
51379
- errors.push(`lineUp entries must be objects`);
51380
- return false;
51381
- }
51382
- const { participantId, collectionAssignments } = item;
51383
- if (!participantId) {
51384
- errors.push("Missing participantId");
51385
- return false;
51386
- }
51387
- if (typeof participantId !== "string") {
51388
- errors.push("participantIds must be strings");
51389
- return false;
51390
- }
51391
- if (!Array.isArray(collectionAssignments)) {
51392
- errors.push(mustBeAnArray("collectionAssignments"));
51393
- return false;
51394
- }
51395
- return collectionAssignments.every((collectionAssignment) => {
51396
- if (typeof collectionAssignment !== "object") {
51397
- errors.push("collectionAssignments must be objects");
51398
- return false;
51399
- }
51400
- const { collectionPosition } = collectionAssignment;
51401
- if (typeof collectionPosition !== "number") {
51402
- errors.push("collectionPosition must be a number");
51403
- return false;
51404
- }
51405
- return true;
51406
- });
51407
- });
51408
- const noDuplicates = unique(lineUp.map(getParticipantId)).length === lineUp.length;
51409
- if (!noDuplicates)
51410
- errors.push("Duplicated participantId(s)");
51411
- const valid = validItems && noDuplicates;
51412
- return { valid, errors, error: errors.length ? INVALID_VALUES : void 0 };
51413
- }
51414
-
51415
- function updateTeamLineUp({
51416
- drawDefinition,
51417
- participantId,
51418
- tieFormat,
51419
- lineUp
51420
- }) {
51421
- if (typeof drawDefinition !== "object")
51422
- return { error: MISSING_DRAW_DEFINITION };
51423
- if (typeof participantId !== "string")
51424
- return { error: MISSING_PARTICIPANT_ID };
51425
- const validation = validateLineUp({ lineUp, tieFormat });
51426
- if (!validation.valid)
51427
- return validation;
51428
- const { extension: existingExtension } = findExtension({
51429
- element: drawDefinition,
51430
- name: LINEUPS
51431
- });
51432
- const value = existingExtension?.value || {};
51433
- value[participantId] = removeLineUpSubstitutions({ lineUp });
51434
- const extension = { name: LINEUPS, value };
51435
- addExtension$1({ element: drawDefinition, extension });
51436
- addDrawNotice({ drawDefinition });
51437
- return { ...SUCCESS };
51438
- }
51439
-
51440
51462
  function getTieMatchUpContext({
51441
51463
  tournamentRecord,
51442
51464
  drawDefinition,
@@ -59533,6 +59555,7 @@ var lastNames = [
59533
59555
  "Catton",
59534
59556
  "Calvino",
59535
59557
  "Carson",
59558
+ "Chip",
59536
59559
  "Constant",
59537
59560
  "Crane",
59538
59561
  "Crowne",