tods-competition-factory 1.7.9 → 1.7.11

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.
@@ -362,7 +362,7 @@ var matchUpFormatCode = {
362
362
  };
363
363
 
364
364
  function factoryVersion() {
365
- return '1.7.9';
365
+ return '1.7.11';
366
366
  }
367
367
 
368
368
  /******************************************************************************
@@ -5095,7 +5095,7 @@ function evaluateCollectionResult(_a) {
5095
5095
  if (matchUp.winningSide)
5096
5096
  sideWins[matchUp.winningSide - 1] += 1;
5097
5097
  });
5098
- if (matchUpValue) {
5098
+ if (isConvertableInteger(matchUpValue)) {
5099
5099
  // if tiebreak set count as set value and game value
5100
5100
  collectionMatchUps.forEach(function (matchUp) {
5101
5101
  if (matchUp.winningSide) {
@@ -5103,7 +5103,7 @@ function evaluateCollectionResult(_a) {
5103
5103
  }
5104
5104
  });
5105
5105
  }
5106
- else if (setValue) {
5106
+ else if (isConvertableInteger(setValue)) {
5107
5107
  collectionMatchUps.forEach(function (matchUp) {
5108
5108
  var _a, _b;
5109
5109
  (_b = (_a = matchUp.score) === null || _a === void 0 ? void 0 : _a.sets) === null || _b === void 0 ? void 0 : _b.forEach(function (set) {
@@ -5112,7 +5112,7 @@ function evaluateCollectionResult(_a) {
5112
5112
  });
5113
5113
  });
5114
5114
  }
5115
- else if (scoreValue) {
5115
+ else if (isConvertableInteger(scoreValue)) {
5116
5116
  collectionMatchUps.forEach(function (matchUp) {
5117
5117
  var _a, _b;
5118
5118
  (_b = (_a = matchUp.score) === null || _a === void 0 ? void 0 : _a.sets) === null || _b === void 0 ? void 0 : _b.forEach(function (set) {
@@ -5141,16 +5141,18 @@ function evaluateCollectionResult(_a) {
5141
5141
  collectionDefinition: collectionDefinition,
5142
5142
  collectionPosition: collectionPosition,
5143
5143
  });
5144
- sideMatchUpValues[matchUp.winningSide - 1] += matchUpValue_1;
5144
+ if (isConvertableInteger(matchUpValue_1)) {
5145
+ sideMatchUpValues[matchUp.winningSide - 1] += matchUpValue_1;
5146
+ }
5145
5147
  }
5146
5148
  });
5147
5149
  }
5148
5150
  // processed separately so that setValue, scoreValue and collecitonValueProfile can be used in conjunction with collectionValue
5149
- if (collectionValue) {
5151
+ if (isConvertableInteger(collectionValue)) {
5150
5152
  var collectionWinningSide = void 0;
5151
5153
  if (winCriteria === null || winCriteria === void 0 ? void 0 : winCriteria.aggregateValue) {
5152
5154
  if (allCollectionMatchUpsCompleted) {
5153
- if ((matchUpValue || setValue || scoreValue) &&
5155
+ if (isConvertableInteger(matchUpValue || setValue || scoreValue) &&
5154
5156
  sideMatchUpValues[0] !== sideMatchUpValues[1]) {
5155
5157
  collectionWinningSide =
5156
5158
  sideMatchUpValues[0] > sideMatchUpValues[1] ? 1 : 2;
@@ -5192,7 +5194,7 @@ function evaluateCollectionResult(_a) {
5192
5194
  }
5193
5195
  }
5194
5196
  if (!belongsToValueGroup) {
5195
- sideCollectionValues.forEach(function (sideCollectionValue, i) { return (sideTieValues[i] += sideCollectionValue); });
5197
+ sideCollectionValues.forEach(function (sideCollectionValue, i) { return (sideTieValues[i] += sideCollectionValue || 0); });
5196
5198
  }
5197
5199
  else {
5198
5200
  groupValueGroups[collectionGroupNumber].sideWins[0] += sideWins[0] || 0;
@@ -9830,7 +9832,9 @@ function getGroupValueGroups(_a) {
9830
9832
  var _b = _a.collectionGroups, collectionGroups = _b === void 0 ? [] : _b;
9831
9833
  // set up to handle groupValue
9832
9834
  var groupValueGroups = Object.assign.apply(Object, __spreadArray([{}], __read(collectionGroups
9833
- .filter(function (group) { return (group === null || group === void 0 ? void 0 : group.groupValue) && (group === null || group === void 0 ? void 0 : group.groupNumber); })
9835
+ .filter(function (group) {
9836
+ return isConvertableInteger(group === null || group === void 0 ? void 0 : group.groupValue) && (group === null || group === void 0 ? void 0 : group.groupNumber);
9837
+ })
9834
9838
  .map(function (group) {
9835
9839
  var _a;
9836
9840
  return (_a = {},
@@ -9907,7 +9911,7 @@ function generateTieMatchUpScore(params) {
9907
9911
  }, undefined);
9908
9912
  }
9909
9913
  if (groupWinningSide) {
9910
- sideTieValues[groupWinningSide - 1] += groupValue;
9914
+ sideTieValues[groupWinningSide - 1] += groupValue || 0;
9911
9915
  }
9912
9916
  };
9913
9917
  try {
@@ -9924,7 +9928,7 @@ function generateTieMatchUpScore(params) {
9924
9928
  }
9925
9929
  finally { if (e_2) throw e_2.error; }
9926
9930
  }
9927
- var sideScores = sideTieValues.map(function (sideTieValue, i) { return sideTieValue + sideAdjustments[i]; });
9931
+ var sideScores = sideTieValues.map(function (sideTieValue, i) { return (sideTieValue || 0) + sideAdjustments[i]; });
9928
9932
  var set = {
9929
9933
  side1Score: sideScores[0],
9930
9934
  side2Score: sideScores[1],
@@ -16697,7 +16701,7 @@ function calculateWinCriteria(_a) {
16697
16701
  var collectionValueProfiles = collectionDefinition.collectionValueProfiles, collectionGroupNumber = collectionDefinition.collectionGroupNumber, collectionValue = collectionDefinition.collectionValue, matchUpCount = collectionDefinition.matchUpCount, matchUpValue = collectionDefinition.matchUpValue, scoreValue = collectionDefinition.scoreValue, setValue = collectionDefinition.setValue;
16698
16702
  var belongsToValueGroup = collectionGroupNumber &&
16699
16703
  groupValueNumbers.includes(collectionGroupNumber);
16700
- if (setValue || scoreValue) {
16704
+ if (isConvertableInteger(setValue || scoreValue)) {
16701
16705
  // because setValues and scoreValues are unpredictable,
16702
16706
  // any collectionDefintion that has either of these two values without a collectionValue forces the tieFormat to aggregateValue
16703
16707
  aggregateValueImperative = true;
@@ -16705,7 +16709,8 @@ function calculateWinCriteria(_a) {
16705
16709
  else if (belongsToValueGroup) {
16706
16710
  continue;
16707
16711
  }
16708
- else if (collectionValue) {
16712
+ else if (typeof collectionValue === 'number' &&
16713
+ isConvertableInteger(collectionValue)) {
16709
16714
  valueTotal += collectionValue;
16710
16715
  }
16711
16716
  else if (collectionValueProfiles === null || collectionValueProfiles === void 0 ? void 0 : collectionValueProfiles.length) {
@@ -16723,13 +16728,10 @@ function calculateWinCriteria(_a) {
16723
16728
  finally { if (e_2) throw e_2.error; }
16724
16729
  }
16725
16730
  }
16726
- else if (matchUpValue) {
16731
+ else if (typeof matchUpValue === 'number' &&
16732
+ isConvertableInteger(matchUpValue)) {
16727
16733
  valueTotal += (matchUpCount || 0) * matchUpValue;
16728
16734
  }
16729
- else {
16730
- // default is to give each matchUp a value of 1
16731
- valueTotal += matchUpCount || 0;
16732
- }
16733
16735
  }
16734
16736
  }
16735
16737
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -47937,8 +47939,8 @@ function removeStructure(_a) {
47937
47939
  }
47938
47940
 
47939
47941
  function generateAdHocMatchUps$1(_a) {
47940
- var _b, _c, _d, _e, _f, _g, _h, _j;
47941
- var participantIdPairings = _a.participantIdPairings, _k = _a.addToStructure, addToStructure = _k === void 0 ? true : _k, tournamentRecord = _a.tournamentRecord, _l = _a.matchUpIds, matchUpIds = _l === void 0 ? [] : _l, drawDefinition = _a.drawDefinition, matchUpsCount = _a.matchUpsCount, roundNumber = _a.roundNumber, structureId = _a.structureId, newRound = _a.newRound;
47942
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
47943
+ var participantIdPairings = _a.participantIdPairings, _l = _a.addToStructure, addToStructure = _l === void 0 ? true : _l, tournamentRecord = _a.tournamentRecord, _m = _a.matchUpIds, matchUpIds = _m === void 0 ? [] : _m, drawDefinition = _a.drawDefinition, matchUpsCount = _a.matchUpsCount, roundNumber = _a.roundNumber, structureId = _a.structureId, newRound = _a.newRound;
47942
47944
  if (typeof drawDefinition !== 'object')
47943
47945
  return { error: MISSING_DRAW_DEFINITION };
47944
47946
  if (!structureId && ((_b = drawDefinition.structures) === null || _b === void 0 ? void 0 : _b.length) === 1)
@@ -47949,17 +47951,28 @@ function generateAdHocMatchUps$1(_a) {
47949
47951
  var structure = (_e = drawDefinition.structures) === null || _e === void 0 ? void 0 : _e.find(function (structure) { return structure.structureId === structureId; });
47950
47952
  if (!structure)
47951
47953
  return { error: STRUCTURE_NOT_FOUND };
47954
+ var structureHasRoundPositions;
47955
+ var existingMatchUps = (_f = structure.matchUps) !== null && _f !== void 0 ? _f : [];
47956
+ var lastRoundNumber = existingMatchUps === null || existingMatchUps === void 0 ? void 0 : existingMatchUps.reduce(function (roundNumber, matchUp) {
47957
+ if (matchUp.roundPosition)
47958
+ structureHasRoundPositions = true;
47959
+ return ((matchUp === null || matchUp === void 0 ? void 0 : matchUp.roundNumber) || 0) > roundNumber
47960
+ ? matchUp.roundNumber
47961
+ : roundNumber;
47962
+ }, 0);
47952
47963
  if (!matchUpsCount) {
47953
- var selectedEntries = (_g = (_f = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) === null || _f === void 0 ? void 0 : _f.filter(function (entry) {
47964
+ var selectedEntries = (_h = (_g = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) === null || _g === void 0 ? void 0 : _g.filter(function (entry) {
47954
47965
  var entryStatus = entry.entryStatus;
47955
47966
  return STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
47956
- })) !== null && _g !== void 0 ? _g : [];
47967
+ })) !== null && _h !== void 0 ? _h : [];
47957
47968
  var roundMatchUpsCount = Math.floor((selectedEntries === null || selectedEntries === void 0 ? void 0 : selectedEntries.length) / 2) || 1;
47958
47969
  if (newRound) {
47959
47970
  matchUpsCount = roundMatchUpsCount;
47960
47971
  }
47961
47972
  else {
47962
- var maxRemaining = roundMatchUpsCount - (((_h = structure.matchUps) === null || _h === void 0 ? void 0 : _h.length) || 0); // TODO: minus the number of existing matchUps in roundNumber
47973
+ var targetRoundNumber_1 = roundNumber || lastRoundNumber || 1;
47974
+ var existingRoundMatchUps = ((_k = (_j = structure.matchUps) === null || _j === void 0 ? void 0 : _j.filter(function (matchUp) { return matchUp.roundNumber === targetRoundNumber_1; })) === null || _k === void 0 ? void 0 : _k.length) || 0;
47975
+ var maxRemaining = roundMatchUpsCount - existingRoundMatchUps;
47963
47976
  if (maxRemaining > 0)
47964
47977
  matchUpsCount = maxRemaining;
47965
47978
  }
@@ -47970,15 +47983,6 @@ function generateAdHocMatchUps$1(_a) {
47970
47983
  (!participantIdPairings && !matchUpsCount)) {
47971
47984
  return { error: INVALID_VALUES, info: 'matchUpsCount or pairings error' };
47972
47985
  }
47973
- var structureHasRoundPositions;
47974
- var existingMatchUps = (_j = structure.matchUps) !== null && _j !== void 0 ? _j : [];
47975
- var lastRoundNumber = existingMatchUps === null || existingMatchUps === void 0 ? void 0 : existingMatchUps.reduce(function (roundNumber, matchUp) {
47976
- if (matchUp.roundPosition)
47977
- structureHasRoundPositions = true;
47978
- return ((matchUp === null || matchUp === void 0 ? void 0 : matchUp.roundNumber) || 0) > roundNumber
47979
- ? matchUp.roundNumber
47980
- : roundNumber;
47981
- }, 0);
47982
47986
  // structure must not be a container of other structures
47983
47987
  // structure must not contain matchUps with roundPosition
47984
47988
  // structure must not determine finishingPosition by ROUND_OUTCOME
@@ -48680,11 +48684,11 @@ function setPositionAssignments$1(_a) {
48680
48684
  return __assign({}, SUCCESS);
48681
48685
  }
48682
48686
 
48683
- // build up an array of participantIds which are assigned positions in structures
48684
- // optionally filter to included only specified stages
48685
48687
  function getAssignedParticipantIds(_a) {
48686
48688
  var drawDefinition = _a.drawDefinition, stages = _a.stages;
48687
- var stageStructures = ((drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) || []).filter(function (structure) { return !(stages === null || stages === void 0 ? void 0 : stages.length) || stages.includes(structure.stage); });
48689
+ var stageStructures = ((drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.structures) || []).filter(function (structure) {
48690
+ return !(stages === null || stages === void 0 ? void 0 : stages.length) || (structure.stage && stages.includes(structure.stage));
48691
+ });
48688
48692
  return stageStructures
48689
48693
  .map(function (structure) {
48690
48694
  var positionAssignments = getPositionAssignments$1({
@@ -49279,45 +49283,56 @@ function participantInFlightEntries(_a) {
49279
49283
  }
49280
49284
 
49281
49285
  function removeEventEntries(_a) {
49282
- var _b, _c;
49283
- var _d = _a.autoEntryPositions, autoEntryPositions = _d === void 0 ? true : _d, tournamentParticipants = _a.tournamentParticipants, tournamentRecord = _a.tournamentRecord, participantIds = _a.participantIds, event = _a.event;
49286
+ var _b, _c, _d, _e, _f;
49287
+ var _g = _a.autoEntryPositions, autoEntryPositions = _g === void 0 ? true : _g, _h = _a.participantIds, participantIds = _h === void 0 ? [] : _h, entryStatuses = _a.entryStatuses, stage = _a.stage, event = _a.event;
49284
49288
  var stack = 'removeEventEntries';
49285
49289
  if (!(event === null || event === void 0 ? void 0 : event.eventId))
49286
49290
  return { error: MISSING_EVENT };
49287
- if (!Array.isArray(participantIds))
49288
- return decorateResult({
49289
- result: { error: MISSING_PARTICIPANT_IDS },
49290
- stack: stack,
49291
- });
49292
- participantIds = participantIds === null || participantIds === void 0 ? void 0 : participantIds.filter(Boolean);
49293
- if (!(participantIds === null || participantIds === void 0 ? void 0 : participantIds.length))
49294
- return decorateResult({
49295
- result: { error: MISSING_PARTICIPANT_IDS },
49296
- stack: stack,
49297
- });
49298
- var eventId = event.eventId;
49299
- if (!tournamentParticipants) {
49300
- // cannot use getParticipants() because event objects don't have drawIds array
49301
- tournamentParticipants = getTournamentParticipants({
49302
- participantFilters: { participantIds: participantIds },
49303
- tournamentRecord: tournamentRecord,
49304
- withEvents: true,
49305
- withDraws: true,
49306
- }).tournamentParticipants;
49291
+ if (!Array.isArray(participantIds) ||
49292
+ participantIds.some(function (participantId) { return !isString(participantId); })) {
49293
+ return decorateResult({ result: { error: INVALID_PARTICIPANT_ID }, stack: stack });
49307
49294
  }
49308
- var enteredParticipantIds = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.every(function (participant) {
49309
- var eventObject = participant.events.find(function (event) { return event.eventId === eventId; });
49310
- var drawIds = (eventObject === null || eventObject === void 0 ? void 0 : eventObject.drawIds) || [];
49311
- return participant.draws.filter(function (drawInfo) {
49312
- return drawIds.includes(drawInfo.drawId) && drawInfo.positionAssignments;
49313
- }).length;
49314
- });
49315
- if (enteredParticipantIds) {
49295
+ // do not filter by stages; must kmow all participantIds assigned to any stage!
49296
+ var assignedParticipantIds = ((_b = event.drawDefinitions) !== null && _b !== void 0 ? _b : []).flatMap(function (drawDefinition) { return getAssignedParticipantIds({ drawDefinition: drawDefinition }); });
49297
+ var statusParticipantIds = (((entryStatuses === null || entryStatuses === void 0 ? void 0 : entryStatuses.length) &&
49298
+ ((_c = event.entries) === null || _c === void 0 ? void 0 : _c.filter(function (entry) {
49299
+ return entry.entryStatus && entryStatuses.includes(entry.entryStatus);
49300
+ }))) ||
49301
+ [])
49302
+ .map(extractAttributes('participantId'))
49303
+ .filter(function (participantId) { return !assignedParticipantIds.includes(participantId); });
49304
+ var stageParticipantIds = ((stage &&
49305
+ ((_d = event.entries) === null || _d === void 0 ? void 0 : _d.filter(function (entry) { return entry.entryStage && entry.entryStage === stage; }))) ||
49306
+ [])
49307
+ .map(extractAttributes('participantId'))
49308
+ .filter(function (participantId) { return !assignedParticipantIds.includes(participantId); });
49309
+ if (participantIds.length) {
49310
+ participantIds = participantIds.filter(function (participantId) {
49311
+ return (!(entryStatuses === null || entryStatuses === void 0 ? void 0 : entryStatuses.length) ||
49312
+ statusParticipantIds.includes(participantId)) &&
49313
+ (!stage || stageParticipantIds.includes(participantId));
49314
+ });
49315
+ }
49316
+ else if (statusParticipantIds.length && stageParticipantIds.length) {
49317
+ participantIds = intersection(statusParticipantIds, stageParticipantIds);
49318
+ }
49319
+ else if (statusParticipantIds.length) {
49320
+ participantIds = statusParticipantIds;
49321
+ }
49322
+ else if (stageParticipantIds.length) {
49323
+ participantIds = stageParticipantIds;
49324
+ }
49325
+ if ((participantIds === null || participantIds === void 0 ? void 0 : participantIds.length) &&
49326
+ assignedParticipantIds.some(function (participantId) {
49327
+ return participantIds.includes(participantId);
49328
+ })) {
49316
49329
  return decorateResult({
49317
49330
  result: { error: EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT },
49318
49331
  stack: stack,
49319
49332
  });
49320
49333
  }
49334
+ if (!(participantIds === null || participantIds === void 0 ? void 0 : participantIds.length))
49335
+ return __assign(__assign({}, SUCCESS), { participantIdsRemoved: [] });
49321
49336
  var participantIdsRemoved = [];
49322
49337
  event.entries = (event.entries || []).filter(function (entry) {
49323
49338
  var keepEntry = !participantIds.includes(entry === null || entry === void 0 ? void 0 : entry.participantId);
@@ -49332,10 +49347,10 @@ function removeEventEntries(_a) {
49332
49347
  }
49333
49348
  // also remove entry from all flights and drawDefinitions
49334
49349
  var flightProfile = getFlightProfile({ event: event }).flightProfile;
49335
- (_b = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _b === void 0 ? void 0 : _b.forEach(function (flight) {
49350
+ (_e = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _e === void 0 ? void 0 : _e.forEach(function (flight) {
49336
49351
  flight.drawEntries = (flight.drawEntries || []).filter(function (entry) { return !participantIds.includes(entry.participantId); });
49337
49352
  });
49338
- (_c = event.drawDefinitions) === null || _c === void 0 ? void 0 : _c.forEach(function (drawDefinition) {
49353
+ (_f = event.drawDefinitions) === null || _f === void 0 ? void 0 : _f.forEach(function (drawDefinition) {
49339
49354
  drawDefinition.entries = (drawDefinition.entries || []).filter(function (entry) { return !participantIds.includes(entry.participantId); });
49340
49355
  });
49341
49356
  return __assign(__assign({}, SUCCESS), { participantIdsRemoved: participantIdsRemoved });
@@ -49492,7 +49507,6 @@ function addEventEntries(params) {
49492
49507
  removeEventEntries({
49493
49508
  participantIds: ungroupedParticipantIdsToRemove,
49494
49509
  autoEntryPositions: false,
49495
- tournamentRecord: tournamentRecord,
49496
49510
  event: event,
49497
49511
  });
49498
49512
  }
@@ -49828,8 +49842,6 @@ function deleteParticipants(params) {
49828
49842
  for (var _f = __values(tournamentRecord.events || []), _g = _f.next(); !_g.done; _g = _f.next()) {
49829
49843
  var event_1 = _g.value;
49830
49844
  var result = removeEventEntries({
49831
- tournamentParticipants: tournamentParticipants,
49832
- tournamentRecord: tournamentRecord,
49833
49845
  participantIds: participantIds,
49834
49846
  event: event_1,
49835
49847
  });
@@ -50010,7 +50022,6 @@ function destroyGroupEntry(_a) {
50010
50022
  // remove the group participant from event entries
50011
50023
  var result = removeEventEntries({
50012
50024
  participantIds: [participantId],
50013
- tournamentRecord: tournamentRecord,
50014
50025
  event: event,
50015
50026
  });
50016
50027
  if (result.error)