tods-competition-factory 1.6.22 → 1.6.24

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.22";
332
+ return "1.6.24";
333
333
  }
334
334
 
335
335
  function getObjectTieFormat(obj) {
@@ -402,6 +402,9 @@ function unique(arr) {
402
402
  function shuffleArray(arr) {
403
403
  return arr.map((a) => [Math.random(), a]).sort((a, b) => a[0] - b[0]).map((a) => a[1]);
404
404
  }
405
+ function numericSortValue(v) {
406
+ return isConvertableInteger(v) ? v : Infinity;
407
+ }
405
408
  function instanceCount(values) {
406
409
  return values.reduce((a, c) => {
407
410
  if (!a[c])
@@ -3700,6 +3703,7 @@ const POLICY_TYPE_PARTICIPANT = "participant";
3700
3703
  const POLICY_TYPE_PROGRESSION = "progression";
3701
3704
  const POLICY_TYPE_SCHEDULING = "scheduling";
3702
3705
  const POLICY_TYPE_AVOIDANCE = "avoidance";
3706
+ const POLICY_TYPE_DISPLAY = "display";
3703
3707
  const POLICY_TYPE_SCORING = "scoring";
3704
3708
  const POLICY_TYPE_SEEDING = "seeding";
3705
3709
  const POLICY_TYPE_FEED_IN = "feedIn";
@@ -3717,6 +3721,7 @@ const policyConstants = {
3717
3721
  POLICY_TYPE_PROGRESSION,
3718
3722
  POLICY_TYPE_SCHEDULING,
3719
3723
  POLICY_TYPE_AVOIDANCE,
3724
+ POLICY_TYPE_DISPLAY,
3720
3725
  POLICY_TYPE_FEED_IN,
3721
3726
  POLICY_TYPE_SCORING,
3722
3727
  POLICY_TYPE_SEEDING,
@@ -9144,25 +9149,25 @@ function targetByRoundOutcome({
9144
9149
  matchUp,
9145
9150
  targetLinks: { loserTargetLink, winnerTargetLink, byeTargetLink },
9146
9151
  targetMatchUps: {
9147
- byeMatchUp,
9148
- loserMatchUp,
9149
- winnerMatchUp,
9150
- byeTargetDrawPosition,
9151
- loserTargetDrawPosition,
9152
- winnerTargetDrawPosition,
9153
- byeMatchUpDrawPositionIndex,
9152
+ winnerMatchUpDrawPositionIndex,
9154
9153
  loserMatchUpDrawPositionIndex,
9155
- winnerMatchUpDrawPositionIndex
9154
+ byeMatchUpDrawPositionIndex,
9155
+ winnerTargetDrawPosition,
9156
+ loserTargetDrawPosition,
9157
+ byeTargetDrawPosition,
9158
+ winnerMatchUp,
9159
+ loserMatchUp,
9160
+ byeMatchUp
9156
9161
  },
9157
9162
  targetMatchUpIds: !!(winnerMatchUpId || loserMatchUpId)
9158
9163
  });
9159
9164
  }
9160
9165
  function targetByWinRatio({ matchUp }) {
9161
9166
  return {
9162
- matchUp,
9163
9167
  targetLinks: { loserTargetLink: void 0, winnerTargetLink: void 0 },
9164
9168
  // returned for testing
9165
- targetMatchUps: { loserMatchUp: void 0, winnerMatchUp: void 0 }
9169
+ targetMatchUps: { loserMatchUp: void 0, winnerMatchUp: void 0 },
9170
+ matchUp
9166
9171
  };
9167
9172
  }
9168
9173
 
@@ -36250,7 +36255,7 @@ function modifyVenue$1({
36250
36255
  venue && validReplacementAttributes.forEach(
36251
36256
  (attribute) => Object.assign(venue, { [attribute]: modifications[attribute] })
36252
36257
  );
36253
- const existingCourtIds = venue?.courts?.map((court) => court.courtId) || [];
36258
+ const existingCourtIds = venue?.courts?.map((court) => court.courtId) ?? [];
36254
36259
  const courtIdsToModify = modifications.courts?.map((court) => court.courtId) || [];
36255
36260
  const courtIdsToDelete = existingCourtIds.filter(
36256
36261
  (courtId) => !courtIdsToModify.includes(courtId)
@@ -36265,7 +36270,7 @@ function modifyVenue$1({
36265
36270
  tournamentRecord,
36266
36271
  venueMatchUps
36267
36272
  });
36268
- return result2.matchUps?.length || 0;
36273
+ return result2.matchUps?.length ?? 0;
36269
36274
  }).reduce((a, b) => a + b);
36270
36275
  if (venue && (!scheduleDeletionsCount || force)) {
36271
36276
  venue.courts = venue.courts?.filter(
@@ -41522,6 +41527,36 @@ function generateAndPopulatePlayoffStructures(params) {
41522
41527
  if (result.error)
41523
41528
  console.log(result.error);
41524
41529
  });
41530
+ const byeMatchUps = inContextDrawMatchUps?.filter(
41531
+ (matchUp) => matchUp.matchUpStatus === BYE && matchUp.structureId === sourceStructureId
41532
+ );
41533
+ byeMatchUps?.forEach((matchUp) => {
41534
+ const { matchUpId } = matchUp;
41535
+ const targetData = positionTargets({
41536
+ inContextDrawMatchUps,
41537
+ drawDefinition,
41538
+ matchUpId
41539
+ });
41540
+ const {
41541
+ targetLinks: { loserTargetLink },
41542
+ targetMatchUps: {
41543
+ loserMatchUpDrawPositionIndex,
41544
+ // only present when positionTargets found without loserMatchUpId
41545
+ loserMatchUp
41546
+ }
41547
+ } = targetData;
41548
+ const targetStructureId = loserTargetLink.target.structureId;
41549
+ const targetDrawPosition = loserMatchUp.drawPositions[loserMatchUpDrawPositionIndex];
41550
+ const result = assignDrawPositionBye$1({
41551
+ drawPosition: targetDrawPosition,
41552
+ structureId: targetStructureId,
41553
+ tournamentRecord,
41554
+ drawDefinition,
41555
+ event
41556
+ });
41557
+ if (result.error)
41558
+ console.log(result.error);
41559
+ });
41525
41560
  const matchUpModifications = [];
41526
41561
  const goesToMap = addGoesTo({
41527
41562
  inContextDrawMatchUps,
@@ -42140,7 +42175,7 @@ function attachStructures$1({
42140
42175
  if (!drawDefinition)
42141
42176
  return { error: MISSING_DRAW_DEFINITION };
42142
42177
  if (!Array.isArray(structures) || !Array.isArray(links))
42143
- return { error: INVALID_VALUES };
42178
+ return decorateResult({ result: { error: INVALID_VALUES } });
42144
42179
  const stack = "attachStructures";
42145
42180
  const linkHash = (link) => [
42146
42181
  link.source.structureId,
@@ -42311,6 +42346,27 @@ function deleteAdHocMatchUps$1({
42311
42346
  return { ...SUCCESS };
42312
42347
  }
42313
42348
 
42349
+ function setStructureOrder({ drawDefinition, orderMap }) {
42350
+ if (!drawDefinition)
42351
+ return { error: MISSING_DRAW_DEFINITION };
42352
+ if (typeof orderMap !== "object" || !Object.values(orderMap).every((val) => isConvertableInteger(val)))
42353
+ decorateResult({
42354
+ result: { error: INVALID_VALUES },
42355
+ context: { orderMap }
42356
+ });
42357
+ if (!drawDefinition.structures)
42358
+ drawDefinition.structures = [];
42359
+ drawDefinition.structures.forEach((structure) => {
42360
+ const structureOrder = orderMap[structure.structureId];
42361
+ if (structureOrder)
42362
+ structure.structureOrder = structureOrder;
42363
+ });
42364
+ drawDefinition.structures.sort(
42365
+ (a, b) => numericSortValue(a.structureOrder) - numericSortValue(b.structureOrder)
42366
+ );
42367
+ return { ...SUCCESS };
42368
+ }
42369
+
42314
42370
  function renameStructures$1({ drawDefinition, structureDetails }) {
42315
42371
  if (!isObject(structureDetails))
42316
42372
  return { error: INVALID_VALUES };
@@ -42555,6 +42611,7 @@ const structureGovernor = {
42555
42611
  generateAndPopulatePlayoffStructures,
42556
42612
  attachPlayoffStructures: attachPlayoffStructures$1,
42557
42613
  addPlayoffStructures: addPlayoffStructures$1,
42614
+ setStructureOrder,
42558
42615
  renameStructures: renameStructures$1,
42559
42616
  generateQualifyingStructure: generateQualifyingStructure$1,
42560
42617
  attachQualifyingStructure: attachQualifyingStructure$1,
@@ -44507,8 +44564,9 @@ function eliminationSwap({
44507
44564
  return { ...SUCCESS };
44508
44565
  if (assignments.filter(({ qualifier }) => qualifier).length === 2)
44509
44566
  return { ...SUCCESS };
44567
+ const isQualifierSwap = assignments.some(({ qualifier }) => qualifier);
44510
44568
  const isByeSwap = assignments.some(({ bye }) => bye);
44511
- if (isByeSwap) {
44569
+ if (isByeSwap && !isQualifierSwap) {
44512
44570
  return swapParticipantIdWithBYE({
44513
44571
  inContextDrawMatchUps,
44514
44572
  tournamentRecord,
@@ -44519,7 +44577,7 @@ function eliminationSwap({
44519
44577
  event
44520
44578
  });
44521
44579
  } else {
44522
- return eliminationParticipantSwap({
44580
+ return eliminationPosiitonSwap({
44523
44581
  inContextDrawMatchUps,
44524
44582
  tournamentRecord,
44525
44583
  drawDefinition,
@@ -44588,7 +44646,7 @@ function swapParticipantIdWithBYE({
44588
44646
  return result;
44589
44647
  return { ...SUCCESS };
44590
44648
  }
44591
- function eliminationParticipantSwap({
44649
+ function eliminationPosiitonSwap({
44592
44650
  inContextDrawMatchUps,
44593
44651
  tournamentRecord,
44594
44652
  drawDefinition,
@@ -44649,8 +44707,9 @@ function roundRobinSwap({
44649
44707
  structure,
44650
44708
  event
44651
44709
  });
44710
+ const isQualifierSwap = assignments.some(({ qualifier }) => qualifier);
44652
44711
  const isByeSwap = assignments.some(({ bye }) => bye);
44653
- if (isByeSwap) {
44712
+ if (isByeSwap && !isQualifierSwap) {
44654
44713
  swapParticipantIdWithBYE({
44655
44714
  inContextDrawMatchUps,
44656
44715
  tournamentRecord,
@@ -44918,10 +44977,19 @@ function generateDrawMaticRound({
44918
44977
  eventType,
44919
44978
  structure
44920
44979
  }) {
44980
+ if (!drawDefinition)
44981
+ return { error: MISSING_DRAW_DEFINITION };
44982
+ if (!structure && !structureId)
44983
+ return { error: STRUCTURE_NOT_FOUND };
44984
+ if (!structure) {
44985
+ structure = findStructure({ drawDefinition, structureId }).structure;
44986
+ }
44987
+ if (!isObject(structure))
44988
+ return { error: MISSING_STRUCTURE };
44921
44989
  if (!participantIds?.length) {
44922
44990
  return { error: MISSING_PARTICIPANT_IDS };
44923
44991
  }
44924
- const { encounters } = getEncounters({ matchUps: structure.matchUps });
44992
+ const { encounters } = getEncounters({ matchUps: structure?.matchUps ?? [] });
44925
44993
  const valueObjects = {};
44926
44994
  for (const pairing of encounters) {
44927
44995
  if (!valueObjects[pairing])
@@ -44933,7 +45001,7 @@ function generateDrawMaticRound({
44933
45001
  );
44934
45002
  if (teamParticipants) {
44935
45003
  for (const teamParticipant of teamParticipants) {
44936
- const participantIds2 = teamParticipant.individualParticipantIds || [];
45004
+ const participantIds2 = teamParticipant.individualParticipantIds ?? [];
44937
45005
  const { uniquePairings: uniquePairings2 } = getPairingsData({ participantIds: participantIds2 });
44938
45006
  for (const pairing of uniquePairings2) {
44939
45007
  if (!valueObjects[pairing])
@@ -44964,12 +45032,12 @@ function generateDrawMaticRound({
44964
45032
  let matchUps;
44965
45033
  if (generateMatchUps) {
44966
45034
  const result = generateAdHocMatchUps$1({
45035
+ structureId: structure?.structureId,
44967
45036
  participantIdPairings,
44968
45037
  tournamentRecord,
44969
45038
  addToStructure,
44970
45039
  newRound: true,
44971
45040
  drawDefinition,
44972
- structureId,
44973
45041
  matchUpIds
44974
45042
  });
44975
45043
  if (result.error)
@@ -45101,6 +45169,7 @@ function drawMatic$1({
45101
45169
  addToStructure,
45102
45170
  participantIds,
45103
45171
  drawDefinition,
45172
+ scaleAccessor,
45104
45173
  maxIterations,
45105
45174
  structureId,
45106
45175
  matchUpIds,
@@ -45148,6 +45217,7 @@ function drawMatic$1({
45148
45217
  const structureIsAdHoc = isAdHoc({ drawDefinition, structure });
45149
45218
  if (!structureIsAdHoc)
45150
45219
  return { error: INVALID_DRAW_DEFINITION };
45220
+ tournamentParticipants = tournamentParticipants ?? tournamentRecord.participants ?? [];
45151
45221
  const adHocRatings = {};
45152
45222
  for (const participantId of participantIds ?? []) {
45153
45223
  const participant = tournamentParticipants?.find(
@@ -45155,7 +45225,12 @@ function drawMatic$1({
45155
45225
  );
45156
45226
  let scaleValue = getScaleValue({ eventType, participant });
45157
45227
  if (!scaleValue && scaleName) {
45158
- scaleValue = getScaleValue({ scaleName, eventType, participant });
45228
+ scaleValue = getScaleValue({
45229
+ scaleAccessor,
45230
+ participant,
45231
+ scaleName,
45232
+ eventType
45233
+ });
45159
45234
  }
45160
45235
  if (scaleValue)
45161
45236
  adHocRatings[participantId] = scaleValue;
@@ -45169,13 +45244,17 @@ function drawMatic$1({
45169
45244
  drawDefinition,
45170
45245
  maxIterations,
45171
45246
  adHocRatings,
45172
- structureId,
45173
45247
  matchUpIds,
45174
45248
  structure,
45175
45249
  eventType
45176
45250
  });
45177
45251
  }
45178
- function getScaleValue({ scaleName = "dynamic", eventType, participant }) {
45252
+ function getScaleValue({
45253
+ eventType = TypeEnum.Singles,
45254
+ scaleName = "dynamic",
45255
+ scaleAccessor,
45256
+ participant
45257
+ }) {
45179
45258
  const scaleAttributes = {
45180
45259
  eventType: eventType || TypeEnum.Singles,
45181
45260
  scaleType: RATING$2,
@@ -45185,7 +45264,8 @@ function getScaleValue({ scaleName = "dynamic", eventType, participant }) {
45185
45264
  scaleAttributes,
45186
45265
  participant
45187
45266
  });
45188
- return result?.scaleItem?.scaleValue;
45267
+ const scaleValue = result?.scaleItem?.scaleValue;
45268
+ return scaleAccessor && isObject(scaleValue) ? scaleValue[scaleAccessor] : scaleValue;
45189
45269
  }
45190
45270
 
45191
45271
  function setDelegatedOutcome$1({
@@ -47254,7 +47334,7 @@ function getOrderedTieFormat({ tieFormat, orderMap }) {
47254
47334
  collectionDefinition.collectionOrder = collectionOrder;
47255
47335
  });
47256
47336
  orderedTieFormat.collectionDefinitions.sort(
47257
- (a, b) => a.collectionOrder - b.collectionOrder
47337
+ (a, b) => numericSortValue(a.collectionOrder) - numericSortValue(b.collectionOrder)
47258
47338
  );
47259
47339
  return orderedTieFormat;
47260
47340
  }
@@ -47268,8 +47348,11 @@ function orderCollectionDefinitions({
47268
47348
  matchUp,
47269
47349
  event
47270
47350
  }) {
47271
- if (typeof orderMap !== "object")
47272
- return { error: INVALID_VALUES, orderMap };
47351
+ if (typeof orderMap !== "object" || !Object.values(orderMap).every((val) => isConvertableInteger(val)))
47352
+ return decorateResult({
47353
+ result: { error: INVALID_VALUES },
47354
+ context: { orderMap }
47355
+ });
47273
47356
  if (eventId && event?.tieFormat) {
47274
47357
  updateEventTieFormat({ tournamentRecord, event, orderMap });
47275
47358
  } else if (matchUpId) {
@@ -48726,7 +48809,7 @@ function modifyTieFormat({
48726
48809
  processedTieFormat = result2.tieFormat;
48727
48810
  }
48728
48811
  processedTieFormat.collectionDefinitions = processedTieFormat.collectionDefinitions.sort(
48729
- (a, b) => (a.collectionOrder || Infinity) - (b.collectionOrder || Infinity)
48812
+ (a, b) => numericSortValue(a.collectionOrder) - numericSortValue(b.collectionOrder)
48730
48813
  ).map((def, i) => ({ ...def, collectionOrder: i + 1 }));
48731
48814
  return { ...SUCCESS, processedTieFormat };
48732
48815
  }
@@ -54138,6 +54221,7 @@ function removeTieMatchUpParticipantId(params) {
54138
54221
  function getPositionAssignments({
54139
54222
  tournamentRecord,
54140
54223
  drawDefinition,
54224
+ stage = MAIN,
54141
54225
  structureId,
54142
54226
  structure
54143
54227
  }) {
@@ -54145,6 +54229,11 @@ function getPositionAssignments({
54145
54229
  return { error: MISSING_TOURNAMENT_RECORD };
54146
54230
  if (!structure && !drawDefinition)
54147
54231
  return { error: MISSING_DRAW_DEFINITION };
54232
+ if (!structure && !structureId && drawDefinition?.structures?.filter((structure2) => structure2.stage === stage).length === 1) {
54233
+ structure = drawDefinition.structures.find(
54234
+ (structure2) => structure2.stage === stage
54235
+ );
54236
+ }
54148
54237
  if (!structure && !structureId)
54149
54238
  return { error: MISSING_STRUCTURE_ID };
54150
54239
  const { error, positionAssignments: assignments } = getPositionAssignments$1({
@@ -54152,7 +54241,11 @@ function getPositionAssignments({
54152
54241
  structureId,
54153
54242
  structure
54154
54243
  });
54155
- return { error, positionAssignments: assignments || [] };
54244
+ return {
54245
+ error,
54246
+ positionAssignments: assignments || [],
54247
+ structureId: structure?.structureId
54248
+ };
54156
54249
  }
54157
54250
 
54158
54251
  function deleteDrawDefinitions({
@@ -57107,7 +57200,7 @@ function prepareStage(params) {
57107
57200
  stage
57108
57201
  }));
57109
57202
  }
57110
- const scaledEntriesCount = scaledEntries?.length || 0;
57203
+ const scaledEntriesCount = scaledEntries?.length ?? 0;
57111
57204
  if (scaledEntriesCount < seedsCount)
57112
57205
  seedsCount = scaledEntriesCount;
57113
57206
  scaledEntries?.filter(
@@ -57478,12 +57571,28 @@ function generateDrawDefinition(params) {
57478
57571
  const matchUpsCount = entries2 ? Math.floor(entries2.length / 2) : 0;
57479
57572
  generateRange(1, params.roundsCount + 1).forEach(() => {
57480
57573
  if (params.automated) {
57574
+ const {
57575
+ restrictEntryStatus,
57576
+ generateMatchUps,
57577
+ addToStructure,
57578
+ maxIterations,
57579
+ structureId: structureId2,
57580
+ matchUpIds,
57581
+ scaleName
57582
+ } = params.drawMatic ?? {};
57481
57583
  drawMatic$1({
57482
- generateMatchUps: true,
57483
- eventType: matchUpType,
57484
57584
  tournamentRecord,
57485
57585
  participantIds,
57486
- drawDefinition
57586
+ drawDefinition,
57587
+ eventType: params.drawMatic?.eventType ?? matchUpType,
57588
+ generateMatchUps: generateMatchUps ?? true,
57589
+ restrictEntryStatus,
57590
+ addToStructure,
57591
+ maxIterations,
57592
+ structureId: structureId2,
57593
+ matchUpIds,
57594
+ scaleName
57595
+ // custom rating name to seed dynamic ratings
57487
57596
  });
57488
57597
  } else {
57489
57598
  generateAdHocMatchUps$1({
@@ -57609,6 +57718,12 @@ function renameStructures(params) {
57609
57718
  return renameStructures$1(params);
57610
57719
  }
57611
57720
 
57721
+ function resetMatchUpLineUps(params) {
57722
+ if (!params.tournamentRecord)
57723
+ return { error: MISSING_TOURNAMENT_RECORD };
57724
+ return resetMatchUpLineUps$1(params);
57725
+ }
57726
+
57612
57727
  function aggregateTieFormats({
57613
57728
  tournamentRecord
57614
57729
  }) {
@@ -57720,18 +57835,13 @@ function enableTieAutoCalc(params) {
57720
57835
  return enableTieAutoCalc$1(params);
57721
57836
  }
57722
57837
 
57723
- function resetMatchUpLineUps(params) {
57724
- if (!params.tournamentRecord)
57725
- return { error: MISSING_TOURNAMENT_RECORD };
57726
- return resetMatchUpLineUps$1(params);
57727
- }
57728
-
57729
57838
  const eventGovernor = {
57730
57839
  generateQualifyingStructure,
57731
57840
  attachQualifyingStructure,
57732
57841
  attachPlayoffStructures,
57733
- attachStructures,
57734
57842
  addQualifyingStructure,
57843
+ setStructureOrder,
57844
+ attachStructures,
57735
57845
  renameStructures,
57736
57846
  disableTieAutoCalc,
57737
57847
  enableTieAutoCalc,
@@ -57831,9 +57941,10 @@ const eventGovernor = {
57831
57941
  checkOutParticipant,
57832
57942
  toggleParticipantCheckInState: toggleParticipantCheckInState$1,
57833
57943
  addDrawDefinitionTimeItem,
57834
- generateDrawDefinition,
57835
- generateDrawStructuresAndLinks,
57836
57944
  generateDrawTypeAndModifyDrawDefinition,
57945
+ generateDrawStructuresAndLinks,
57946
+ generateDrawMaticRound,
57947
+ generateDrawDefinition,
57837
57948
  applyLineUps,
57838
57949
  assignTieMatchUpParticipantId,
57839
57950
  removeTieMatchUpParticipantId,