tods-competition-factory 0.167.0 → 0.170.0

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.
@@ -249,7 +249,7 @@ const matchUpFormatCode = {
249
249
  };
250
250
 
251
251
  function factoryVersion() {
252
- return '0.167.0';
252
+ return '0.170.0';
253
253
  }
254
254
 
255
255
  function isPowerOf2(n) {
@@ -9032,7 +9032,7 @@ function modifyDrawNotice({
9032
9032
  });
9033
9033
  }
9034
9034
 
9035
- function copyTieFormat$3(tieFormat) {
9035
+ function copyTieFormat$2(tieFormat) {
9036
9036
  return makeDeepCopy(tieFormat, false, true);
9037
9037
  }
9038
9038
 
@@ -9040,7 +9040,7 @@ function getOrderedTieFormat({
9040
9040
  tieFormat,
9041
9041
  orderMap
9042
9042
  }) {
9043
- const orderedTieFormat = copyTieFormat$3(tieFormat);
9043
+ const orderedTieFormat = copyTieFormat$2(tieFormat);
9044
9044
  orderedTieFormat.collectionDefinitions.forEach(collectionDefinition => {
9045
9045
  const collectionOrder = orderMap[collectionDefinition.collectionId];
9046
9046
  if (collectionOrder) collectionDefinition.collectionOrder = collectionOrder;
@@ -9064,8 +9064,9 @@ function orderCollectionDefinitions({
9064
9064
  };
9065
9065
 
9066
9066
  if (eventId && event !== null && event !== void 0 && event.tieFormat) {
9067
- event.tieFormat = getOrderedTieFormat({
9068
- tieFormat: event.tieFormat,
9067
+ updateEventTieFormat({
9068
+ tournamentRecord,
9069
+ event,
9069
9070
  orderMap
9070
9071
  });
9071
9072
  } else if (matchUpId) {
@@ -9118,32 +9119,30 @@ function orderCollectionDefinitions({
9118
9119
  drawDefinition,
9119
9120
  structureIds: [structure.structureId]
9120
9121
  });
9121
- }
9122
- } else if (drawDefinition !== null && drawDefinition !== void 0 && drawDefinition.tieFormat) {
9123
- const updatedFormat = getOrderedTieFormat({
9124
- tieFormat: drawDefinition.tieFormat,
9125
- orderMap
9126
- });
9127
- drawDefinition.tieFormat = updatedFormat;
9128
- const modifiedStructureIds = [];
9129
-
9130
- for (const structure of drawDefinition.structures || []) {
9131
- if (structure.tieFormat) structure.tieFormat = getOrderedTieFormat({
9132
- tieFormat: structure.tieFormat,
9122
+ } else if (drawDefinition.tieFormat) {
9123
+ updateDrawTieFormat({
9124
+ structureIds: [structureId],
9125
+ tournamentRecord,
9126
+ drawDefinition,
9133
9127
  orderMap
9134
9128
  });
9135
- updateStructureMatchUps$2({
9129
+ } else if (event !== null && event !== void 0 && event.tieFormat) {
9130
+ updateEventTieFormat({
9131
+ structureIds: [structureId],
9136
9132
  tournamentRecord,
9137
- drawDefinition,
9138
- structure,
9133
+ event,
9139
9134
  orderMap
9140
9135
  });
9141
- modifiedStructureIds.push(structure.structureId);
9136
+ } else {
9137
+ return {
9138
+ error: NOT_FOUND
9139
+ };
9142
9140
  }
9143
-
9144
- modifyDrawNotice({
9141
+ } else if (drawDefinition !== null && drawDefinition !== void 0 && drawDefinition.tieFormat) {
9142
+ updateDrawTieFormat({
9143
+ tournamentRecord,
9145
9144
  drawDefinition,
9146
- structureIds: modifiedStructureIds
9145
+ orderMap
9147
9146
  });
9148
9147
  } else {
9149
9148
  return {
@@ -9155,6 +9154,66 @@ function orderCollectionDefinitions({
9155
9154
  };
9156
9155
  }
9157
9156
 
9157
+ function updateEventTieFormat({
9158
+ tournamentRecord,
9159
+ structureIds,
9160
+ // allow scoping to only specific structureIds
9161
+ orderMap,
9162
+ event
9163
+ }) {
9164
+ const updatedFormat = getOrderedTieFormat({
9165
+ tieFormat: event.tieFormat,
9166
+ orderMap
9167
+ });
9168
+ if (!(structureIds !== null && structureIds !== void 0 && structureIds.length)) event.tieFormat = updatedFormat;
9169
+
9170
+ for (const drawDefinition of event.drawDefinitions || []) {
9171
+ updateDrawTieFormat({
9172
+ tournamentRecord,
9173
+ drawDefinition,
9174
+ structureIds,
9175
+ orderMap,
9176
+ event
9177
+ });
9178
+ }
9179
+ }
9180
+
9181
+ function updateDrawTieFormat({
9182
+ tournamentRecord,
9183
+ drawDefinition,
9184
+ structureIds,
9185
+ orderMap,
9186
+ event
9187
+ }) {
9188
+ const updatedFormat = getOrderedTieFormat({
9189
+ tieFormat: drawDefinition.tieFormat,
9190
+ orderMap
9191
+ });
9192
+ if (!(structureIds !== null && structureIds !== void 0 && structureIds.length)) drawDefinition.tieFormat = updatedFormat;
9193
+ const modifiedStructureIds = [];
9194
+
9195
+ for (const structure of drawDefinition.structures || []) {
9196
+ // if structureIds is present, only modify referenced structures
9197
+ if (structureIds !== null && structureIds !== void 0 && structureIds.length && !structureIds.includes(structure.structureId)) continue;
9198
+ if (structure.tieFormat || structureIds !== null && structureIds !== void 0 && structureIds.includes(structure.structureId)) structure.tieFormat = getOrderedTieFormat({
9199
+ tieFormat: structure.tieFormat || drawDefinition.tieFormat || event.tieFormat,
9200
+ orderMap
9201
+ });
9202
+ updateStructureMatchUps$2({
9203
+ tournamentRecord,
9204
+ drawDefinition,
9205
+ structure,
9206
+ orderMap
9207
+ });
9208
+ modifiedStructureIds.push(structure.structureId);
9209
+ }
9210
+
9211
+ modifyDrawNotice({
9212
+ drawDefinition,
9213
+ structureIds: modifiedStructureIds
9214
+ });
9215
+ }
9216
+
9158
9217
  function updateStructureMatchUps$2({
9159
9218
  tournamentRecord,
9160
9219
  drawDefinition,
@@ -12158,7 +12217,7 @@ function getTieFormat$1({
12158
12217
 
12159
12218
  // all child matchUps need to be checked for collectionAssignments which need to be removed when collectionDefinition.collectionIds are removed
12160
12219
 
12161
- function copyTieFormat$2(tieFormat) {
12220
+ function copyTieFormat$1(tieFormat) {
12162
12221
  return makeDeepCopy(tieFormat, false, true);
12163
12222
  }
12164
12223
  /*
@@ -12196,7 +12255,7 @@ function removeCollectionDefinition({
12196
12255
  tieFormat: existingTieFormat
12197
12256
  } = result;
12198
12257
  const originalValueGoal = existingTieFormat.winCriteria.valueGoal;
12199
- const tieFormat = copyTieFormat$2(existingTieFormat);
12258
+ const tieFormat = copyTieFormat$1(existingTieFormat);
12200
12259
  result = validateTieFormat({
12201
12260
  tieFormat
12202
12261
  });
@@ -12275,7 +12334,7 @@ function removeCollectionDefinition({
12275
12334
  if (deleteTarget) deletedMatchUpIds.push(matchUp.matchUpId);
12276
12335
  return !deleteTarget;
12277
12336
  });
12278
- if (matchUp.tieFormat) matchUp.tieFormat = copyTieFormat$2(tieFormat);
12337
+ if (matchUp.tieFormat) matchUp.tieFormat = copyTieFormat$1(tieFormat);
12279
12338
  modifyMatchUpNotice({
12280
12339
  tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
12281
12340
  drawDefinition,
@@ -12322,11 +12381,8 @@ function validUpdate({
12322
12381
  return ![COMPLETED, IN_PROGRESS].includes(matchUp.matchUpStatus) && !matchUp.winningSide && !(!updateInProgressMatchUps && scoreHasValue(matchUp));
12323
12382
  }
12324
12383
 
12325
- function copyTieFormat$1(tieFormat) {
12326
- return makeDeepCopy(tieFormat, false, true);
12327
- }
12328
-
12329
12384
  function updateTieFormat({
12385
+ updateInProgressMatchUps,
12330
12386
  tournamentRecord,
12331
12387
  drawDefinition,
12332
12388
  structure,
@@ -12347,6 +12403,7 @@ function updateTieFormat({
12347
12403
  } else if (structure) {
12348
12404
  structure.tieFormat = tieFormat;
12349
12405
  updateStructureMatchUps$1({
12406
+ updateInProgressMatchUps,
12350
12407
  tournamentRecord,
12351
12408
  drawDefinition,
12352
12409
  structure,
@@ -12362,6 +12419,7 @@ function updateTieFormat({
12362
12419
 
12363
12420
  for (const structure of drawDefinition.structures || []) {
12364
12421
  updateStructureMatchUps$1({
12422
+ updateInProgressMatchUps,
12365
12423
  tournamentRecord,
12366
12424
  drawDefinition,
12367
12425
  structure,
@@ -12385,6 +12443,7 @@ function updateTieFormat({
12385
12443
  }
12386
12444
 
12387
12445
  function updateStructureMatchUps$1({
12446
+ updateInProgressMatchUps,
12388
12447
  tournamentRecord,
12389
12448
  drawDefinition,
12390
12449
  structure,
@@ -12400,20 +12459,38 @@ function updateStructureMatchUps$1({
12400
12459
  })) === null || _getAllStructureMatch === void 0 ? void 0 : _getAllStructureMatch.matchUps; // all team matchUps in the structure which are not completed and which have no score value should have matchUps added
12401
12460
 
12402
12461
  const targetMatchUps = matchUps.filter(matchUp => validUpdate({
12403
- matchUp
12462
+ matchUp,
12463
+ updateInProgressMatchUps
12404
12464
  }) && matchUp.tieFormat);
12405
12465
 
12406
12466
  for (const matchUp of targetMatchUps) {
12407
- matchUp.tieFormat = copyTieFormat$1(tieFormat);
12408
- modifyMatchUpNotice({
12409
- tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
12410
- drawDefinition,
12411
- matchUp
12412
- });
12467
+ var _matchUp$tieFormat;
12468
+
12469
+ if ((_matchUp$tieFormat = matchUp.tieFormat) !== null && _matchUp$tieFormat !== void 0 && _matchUp$tieFormat.collectionDefinitions) {
12470
+ matchUp.tieFormat.collectionDefinitions.forEach(collectionDefinition => {
12471
+ const updatedDefinition = tieFormat.collectionDefinitions.find(({
12472
+ collectionId
12473
+ }) => collectionId === collectionDefinition.collectionId);
12474
+
12475
+ if (updatedDefinition !== null && updatedDefinition !== void 0 && updatedDefinition.collectionName) {
12476
+ collectionDefinition.collectionName = updatedDefinition.collectionName;
12477
+ }
12478
+
12479
+ if (updatedDefinition !== null && updatedDefinition !== void 0 && updatedDefinition.matchUpFormat) {
12480
+ collectionDefinition.matchUpFormat = updatedDefinition.matchUpFormat;
12481
+ }
12482
+ });
12483
+ modifyMatchUpNotice({
12484
+ tournamentId: tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.tournamentId,
12485
+ drawDefinition,
12486
+ matchUp
12487
+ });
12488
+ }
12413
12489
  }
12414
12490
  }
12415
12491
 
12416
12492
  function modifyCollectionDefinition({
12493
+ updateInProgressMatchUps = false,
12417
12494
  tournamentRecord,
12418
12495
  collectionOrder,
12419
12496
  collectionName,
@@ -12456,6 +12533,7 @@ function modifyCollectionDefinition({
12456
12533
  if (matchUpFormat) collectionDefinition.matchUpFormat = matchUpFormat;
12457
12534
  if (collectionOrder) collectionDefinition.collectionOrder = collectionOrder;
12458
12535
  return updateTieFormat({
12536
+ updateInProgressMatchUps,
12459
12537
  tournamentRecord,
12460
12538
  drawDefinition,
12461
12539
  structureId,
@@ -20910,41 +20988,35 @@ function assignSeed({
20910
20988
  };
20911
20989
  }
20912
20990
 
20913
- if (seedNumbers.includes(seedNumber) || [CONSOLATION, PLAY_OFF].includes(structure === null || structure === void 0 ? void 0 : structure.stage)) {
20914
- const seedNumbers = seedAssignments.map(({
20915
- seedNumber
20916
- }) => seedNumber);
20991
+ if (!seedNumbers.includes(seedNumber)) {
20992
+ seedAssignments.push({
20993
+ seedNumber,
20994
+ seedValue
20995
+ });
20996
+ }
20917
20997
 
20918
- if (!seedNumbers.includes(seedNumber)) {
20919
- seedAssignments.push({
20920
- seedNumber,
20921
- seedValue
20922
- });
20923
- }
20998
+ let success;
20999
+ seedAssignments.forEach(assignment => {
21000
+ // ensure that this participantId is not assigned to any other seedNumber
21001
+ if (assignment.participantId === participantId && assignment.seedNumber !== seedNumber) {
21002
+ assignment.participantId = undefined;
21003
+ } // assign participantId to target seedNumber
20924
21004
 
20925
- let success;
20926
- seedAssignments.forEach(assignment => {
20927
- // ensure that this participantId is not assigned to any other seedNumber
20928
- if (assignment.participantId === participantId && assignment.seedNumber !== seedNumber) {
20929
- assignment.participantId = undefined;
20930
- } // assign participantId to target seedNumber
20931
21005
 
21006
+ if (assignment.seedNumber === seedNumber) {
21007
+ assignment.participantId = participantId;
21008
+ assignment.seedValue = seedValue || seedNumber;
21009
+ success = true;
21010
+ }
21011
+ });
20932
21012
 
20933
- if (assignment.seedNumber === seedNumber) {
20934
- assignment.participantId = participantId;
20935
- assignment.seedValue = seedValue || seedNumber;
20936
- success = true;
20937
- }
21013
+ if (success) {
21014
+ modifyDrawNotice({
21015
+ drawDefinition,
21016
+ structureIds: [structureId]
20938
21017
  });
20939
-
20940
- if (success) {
20941
- modifyDrawNotice({
20942
- drawDefinition,
20943
- structureIds: [structureId]
20944
- });
20945
- return { ...SUCCESS
20946
- };
20947
- }
21018
+ return { ...SUCCESS
21019
+ };
20948
21020
  }
20949
21021
 
20950
21022
  return {
@@ -21531,8 +21603,8 @@ function directLoser(params) {
21531
21603
  const {
21532
21604
  positionAssignments: sourcePositionAssignments
21533
21605
  } = structureAssignedDrawPositions({
21534
- drawDefinition,
21535
- structureId: sourceStructureId
21606
+ structureId: sourceStructureId,
21607
+ drawDefinition
21536
21608
  });
21537
21609
  const relevantAssignment = sourcePositionAssignments.find(assignment => assignment.drawPosition === loserDrawPosition);
21538
21610
  const loserParticipantId = relevantAssignment === null || relevantAssignment === void 0 ? void 0 : relevantAssignment.participantId;
@@ -22558,7 +22630,7 @@ function applyMatchUpValues(params) {
22558
22630
  score: params.score
22559
22631
  });
22560
22632
  const newMatchUpStatus = params.isCollectionMatchUp ? params.machUpStatus || removeWinningSide && TO_BE_PLAYED : params.matchUpStatus || COMPLETED;
22561
- const removeScore = [CANCELLED, WALKOVER$1].includes(newMatchUpStatus) && ![INCOMPLETE, ABANDONED].includes(newMatchUpStatus);
22633
+ const removeScore = params.removeScore || [CANCELLED, WALKOVER$1].includes(newMatchUpStatus) && ![INCOMPLETE, ABANDONED].includes(newMatchUpStatus);
22562
22634
  const result = modifyMatchUpScore({ ...params,
22563
22635
  matchUpStatus: newMatchUpStatus,
22564
22636
  removeWinningSide,
@@ -40840,11 +40912,12 @@ function resetScorecard$1(params) {
40840
40912
  };
40841
40913
 
40842
40914
  for (const tieMatchUp of matchUp.tieMatchUps) {
40843
- const result = modifyMatchUpScore({
40915
+ const result = setMatchUpStatus$2({
40844
40916
  matchUpId: tieMatchUp.matchUpId,
40845
- matchUp: tieMatchUp,
40846
- removeWinningSide: true,
40917
+ matchUpTieId: matchUpId,
40918
+ winningSide: undefined,
40847
40919
  removeScore: true,
40920
+ tournamentRecord,
40848
40921
  drawDefinition
40849
40922
  });
40850
40923
  if (result.error) return result;