tods-competition-factory 1.8.24 → 1.8.25

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
@@ -1021,6 +1021,10 @@ const SCHEDULED_MATCHUPS = {
1021
1021
  message: "Scheduled matchUps",
1022
1022
  code: "ERR_SCHEDULED_MATCHUPS"
1023
1023
  };
1024
+ const SCORES_PRESENT = {
1025
+ message: "Scores present",
1026
+ code: "ERR_SCORES_PRESENT"
1027
+ };
1024
1028
  const errorConditionConstants = {
1025
1029
  ANACHRONISM,
1026
1030
  CANNOT_CHANGE_WINNING_SIDE,
@@ -1183,6 +1187,7 @@ const errorConditionConstants = {
1183
1187
  POLICY_NOT_FOUND,
1184
1188
  SCHEDULE_NOT_CLEARED,
1185
1189
  SCHEDULED_MATCHUPS,
1190
+ SCORES_PRESENT,
1186
1191
  SEEDSCOUNT_GREATER_THAN_DRAW_SIZE,
1187
1192
  STAGE_SEQUENCE_LIMIT,
1188
1193
  STRUCTURE_NOT_FOUND,
@@ -2382,7 +2387,7 @@ const matchUpFormatCode = {
2382
2387
  };
2383
2388
 
2384
2389
  function factoryVersion() {
2385
- return "1.8.24";
2390
+ return "1.8.25";
2386
2391
  }
2387
2392
 
2388
2393
  function getObjectTieFormat(obj) {
@@ -43650,6 +43655,19 @@ function generateQualifyingStructure$1(params) {
43650
43655
  };
43651
43656
  }
43652
43657
 
43658
+ function resequenceStructures({ drawDefinition }) {
43659
+ const { maxQualifyingDepth, structureProfiles } = getStructureGroups({
43660
+ drawDefinition
43661
+ });
43662
+ for (const structure of drawDefinition.structures) {
43663
+ const profile = structureProfiles[structure.structureId];
43664
+ if (profile.distanceFromMain) {
43665
+ structure.stageSequence = maxQualifyingDepth + 1 - profile.distanceFromMain;
43666
+ }
43667
+ }
43668
+ return { ...SUCCESS };
43669
+ }
43670
+
43653
43671
  function attachQualifyingStructure$1({
43654
43672
  drawDefinition,
43655
43673
  tournamentId,
@@ -43680,15 +43698,7 @@ function attachQualifyingStructure$1({
43680
43698
  drawDefinition.links = [];
43681
43699
  drawDefinition.structures.push(structure);
43682
43700
  drawDefinition.links.push(link);
43683
- const { maxQualifyingDepth, structureProfiles } = getStructureGroups({
43684
- drawDefinition
43685
- });
43686
- for (const structure2 of drawDefinition.structures) {
43687
- const profile = structureProfiles[structure2.structureId];
43688
- if (profile.distanceFromMain) {
43689
- structure2.stageSequence = maxQualifyingDepth + 1 - profile.distanceFromMain;
43690
- }
43691
- }
43701
+ resequenceStructures({ drawDefinition });
43692
43702
  const matchUps = getAllStructureMatchUps({ structure })?.matchUps || [];
43693
43703
  addMatchUpsNotice({
43694
43704
  drawDefinition,
@@ -44199,7 +44209,8 @@ function removeStructure({
44199
44209
  tournamentRecord,
44200
44210
  drawDefinition,
44201
44211
  structureId,
44202
- event
44212
+ event,
44213
+ force
44203
44214
  }) {
44204
44215
  if (typeof structureId !== "string")
44205
44216
  return { error: INVALID_VALUES };
@@ -44209,10 +44220,21 @@ function removeStructure({
44209
44220
  return { error: MISSING_STRUCTURE_ID };
44210
44221
  const structures = drawDefinition.structures || [];
44211
44222
  const removedStructureIds = [];
44223
+ const structure = structures.find(
44224
+ (structure2) => structure2.structureId === structureId
44225
+ );
44226
+ if (!structure)
44227
+ return { error: STRUCTURE_NOT_FOUND };
44228
+ const structureMatchUps = getAllStructureMatchUps({ structure }).matchUps;
44229
+ const scoresPresent = structureMatchUps.some(
44230
+ ({ score }) => scoreHasValue({ score })
44231
+ );
44232
+ if (scoresPresent && !force)
44233
+ return { error: SCORES_PRESENT };
44212
44234
  const mainStageSequence1 = structures.find(
44213
44235
  ({ stage, stageSequence }) => stage === MAIN && stageSequence === 1
44214
44236
  );
44215
- const isMainStageSequence1 = structureId === mainStageSequence1.structureId;
44237
+ const isMainStageSequence1 = structureId === mainStageSequence1?.structureId;
44216
44238
  const qualifyingStructureIds = structures.filter(({ stage }) => stage === QUALIFYING).map(extractAttributes("structureId"));
44217
44239
  if (isMainStageSequence1 && !qualifyingStructureIds.length) {
44218
44240
  return { error: CANNOT_REMOVE_MAIN_STRUCTURE };
@@ -44221,11 +44243,11 @@ function removeStructure({
44221
44243
  const removedMatchUpIds = [];
44222
44244
  const idsToRemove = [structureId];
44223
44245
  const getTargetedStructureIds = (structureId2) => drawDefinition.links?.map(
44224
- (link) => link.source.structureId === structureId2 && link.target.structureId !== mainStageSequence1.structureId && link.target.structureId
44225
- ).filter(Boolean);
44246
+ (link) => link.source.structureId === structureId2 && link.target.structureId !== mainStageSequence1?.structureId && link.target.structureId
44247
+ ).filter(Boolean) ?? [];
44226
44248
  const getQualifyingSourceStructureIds = (structureId2) => drawDefinition.links?.map(
44227
44249
  (link) => qualifyingStructureIds.includes(link.source.structureId) && link.target.structureId === structureId2 && link.source.structureId
44228
- ).filter(Boolean);
44250
+ ).filter(Boolean) ?? [];
44229
44251
  const isQualifyingStructure = qualifyingStructureIds.includes(structureId);
44230
44252
  const relatedStructureIdsMap = /* @__PURE__ */ new Map();
44231
44253
  structureIds.forEach(
@@ -44236,11 +44258,11 @@ function removeStructure({
44236
44258
  );
44237
44259
  while (idsToRemove.length) {
44238
44260
  const idBeingRemoved = idsToRemove.pop();
44239
- const { structure } = findStructure({
44261
+ const { structure: structure2 } = findStructure({
44240
44262
  structureId: idBeingRemoved,
44241
44263
  drawDefinition
44242
44264
  });
44243
- const { matchUps: matchUps2 } = getAllStructureMatchUps({ structure });
44265
+ const { matchUps: matchUps2 } = getAllStructureMatchUps({ structure: structure2 });
44244
44266
  const matchUpIds = getMatchUpIds(matchUps2);
44245
44267
  removedMatchUpIds.push(...matchUpIds);
44246
44268
  drawDefinition.links = drawDefinition.links?.filter(
@@ -44248,10 +44270,10 @@ function removeStructure({
44248
44270
  ) || [];
44249
44271
  if (!isMainStageSequence1 || idBeingRemoved !== structureId) {
44250
44272
  drawDefinition.structures = (drawDefinition.structures ?? []).filter(
44251
- (structure2) => {
44252
- if (idBeingRemoved && idBeingRemoved === structure2.structureId)
44273
+ (structure3) => {
44274
+ if (idBeingRemoved && idBeingRemoved === structure3.structureId)
44253
44275
  removedStructureIds.push(idBeingRemoved);
44254
- return structure2.structureId !== idBeingRemoved;
44276
+ return structure3.structureId !== idBeingRemoved;
44255
44277
  }
44256
44278
  );
44257
44279
  }
@@ -44259,7 +44281,7 @@ function removeStructure({
44259
44281
  relatedStructureIdsMap.get(idBeingRemoved)?.filter(
44260
44282
  (id) => (
44261
44283
  // IMPORTANT: only delete MAIN stageSequence: 1 if specified to protect against DOUBLE_ELIMINATION scenario
44262
- id !== mainStageSequence1.structureId || structureId === mainStageSequence1.structureId
44284
+ id !== mainStageSequence1?.structureId || structureId === mainStageSequence1.structureId
44263
44285
  )
44264
44286
  );
44265
44287
  if (targetedStructureIds?.length)
@@ -44282,6 +44304,7 @@ function removeStructure({
44282
44304
  mainStageSequence1.extensions = [];
44283
44305
  }
44284
44306
  }
44307
+ isQualifyingStructure && resequenceStructures({ drawDefinition });
44285
44308
  deleteMatchUpsNotice({
44286
44309
  tournamentId: tournamentRecord?.tournamentId,
44287
44310
  matchUpIds: removedMatchUpIds,