tods-competition-factory 1.8.10 → 1.8.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.
@@ -2898,7 +2898,7 @@ var matchUpFormatCode = {
2898
2898
  };
2899
2899
 
2900
2900
  function factoryVersion() {
2901
- return '1.8.10';
2901
+ return '1.8.11';
2902
2902
  }
2903
2903
 
2904
2904
  function getObjectTieFormat(obj) {
@@ -11379,7 +11379,7 @@ function getDrawMatchUps(params) {
11379
11379
  event: event,
11380
11380
  });
11381
11381
  }
11382
- // getTournamentParticipants() calls getDrawMatchUps()
11382
+ // getParticipants() calls allEventMatchUps()
11383
11383
  // ...so participants must be sourced directly from tournamentRecord
11384
11384
  // ...and groupings must be added independent of that
11385
11385
  if (!(tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.length) && tournamentRecord) {
@@ -16700,7 +16700,7 @@ var WHEELCHAIR = 'WHEELCHAIR';
16700
16700
  /**
16701
16701
  *
16702
16702
  */
16703
- var POLICY_SCHEDULING_USTA = (_a$9 = {},
16703
+ var POLICY_SCHEDULING_DEFAULT = (_a$9 = {},
16704
16704
  _a$9[POLICY_TYPE_SCHEDULING] = {
16705
16705
  defaultTimes: {
16706
16706
  averageTimes: [{ categoryNames: [], minutes: { default: 90 } }],
@@ -17040,7 +17040,7 @@ var policies = {
17040
17040
  POLICY_POSITION_ACTIONS_UNRESTRICTED: POLICY_POSITION_ACTIONS_UNRESTRICTED,
17041
17041
  POLICY_PRIVACY_DEFAULT: POLICY_PRIVACY_DEFAULT,
17042
17042
  POLICY_ROUND_NAMING_DEFAULT: POLICY_ROUND_NAMING_DEFAULT,
17043
- POLICY_SCHEDULING_USTA: POLICY_SCHEDULING_USTA,
17043
+ POLICY_SCHEDULING_DEFAULT: POLICY_SCHEDULING_DEFAULT,
17044
17044
  POLICY_SCORING_DEFAULT: POLICY_SCORING_DEFAULT,
17045
17045
  POLICY_SCORING_USTA: POLICY_SCORING_USTA,
17046
17046
  POLICY_SEEDING_ITF: POLICY_SEEDING_ITF,
@@ -29108,7 +29108,7 @@ function addStructureParticipation(_a) {
29108
29108
  function processSides(params) {
29109
29109
  var e_1, _a;
29110
29110
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
29111
- var withScheduleTimes = params.withScheduleTimes, scheduleAnalysis = params.scheduleAnalysis, withTeamMatchUps = params.withTeamMatchUps, participantMap = params.participantMap, withOpponents = params.withOpponents, withMatchUps = params.withMatchUps, withEvents = params.withEvents, withDraws = params.withDraws, finishingPositionRange = params.finishingPositionRange, finishingRound = params.finishingRound, matchUpStatus = params.matchUpStatus, stageSequence = params.stageSequence, roundNumber = params.roundNumber, structureId = params.structureId, score = params.score, stage = params.stage, withRankingProfile = params.withRankingProfile, tieWinningSide = params.tieWinningSide, roundPosition = params.roundPosition, matchUpTieId = params.matchUpTieId, matchUpSides = params.matchUpSides, collectionId = params.collectionId, matchUpType = params.matchUpType, winningSide = params.winningSide, matchUpId = params.matchUpId, schedule = params.schedule, eventId = params.eventId, drawId = params.drawId, sides = params.sides;
29111
+ var withScheduleItems = params.withScheduleItems, scheduleAnalysis = params.scheduleAnalysis, withTeamMatchUps = params.withTeamMatchUps, participantMap = params.participantMap, withOpponents = params.withOpponents, withMatchUps = params.withMatchUps, withEvents = params.withEvents, withDraws = params.withDraws, finishingPositionRange = params.finishingPositionRange, finishingRound = params.finishingRound, matchUpStatus = params.matchUpStatus, stageSequence = params.stageSequence, roundNumber = params.roundNumber, structureId = params.structureId, score = params.score, stage = params.stage, withRankingProfile = params.withRankingProfile, tieWinningSide = params.tieWinningSide, roundPosition = params.roundPosition, matchUpTieId = params.matchUpTieId, matchUpSides = params.matchUpSides, collectionId = params.collectionId, matchUpType = params.matchUpType, winningSide = params.winningSide, matchUpId = params.matchUpId, schedule = params.schedule, eventId = params.eventId, drawId = params.drawId, sides = params.sides;
29112
29112
  var opponents = withOpponents &&
29113
29113
  (sides === null || sides === void 0 ? void 0 : sides.length) === 2 && Object.assign.apply(Object, __spreadArray([{}], __read(sides
29114
29114
  .map(function (_a, i) {
@@ -29202,7 +29202,7 @@ function processSides(params) {
29202
29202
  stage: stage,
29203
29203
  });
29204
29204
  }
29205
- if (scheduleAnalysis || withScheduleTimes) {
29205
+ if (scheduleAnalysis || withScheduleItems) {
29206
29206
  addScheduleItem({
29207
29207
  participantMap: participantMap,
29208
29208
  participantId: participantId,
@@ -29348,9 +29348,8 @@ function processSides(params) {
29348
29348
 
29349
29349
  function getParticipantEntries(params) {
29350
29350
  var e_1, _a, e_2, _b;
29351
- var _c, _d, _e, _f, _g, _h, _j;
29352
- var participantFilters = params.participantFilters, convertExtensions = params.convertExtensions, policyDefinitions = params.policyDefinitions, tournamentRecord = params.tournamentRecord, usePublishState = params.usePublishState, contextProfile = params.contextProfile, participantMap = params.participantMap, withPotentialMatchUps = params.withPotentialMatchUps, withRankingProfile = params.withRankingProfile, scheduleAnalysis = params.scheduleAnalysis, withTeamMatchUps = params.withTeamMatchUps, withStatistics = params.withStatistics, withOpponents = params.withOpponents, withMatchUps = params.withMatchUps, withSeeding = params.withSeeding, withEvents = params.withEvents, withDraws = params.withDraws;
29353
- var withScheduleTimes = (_c = params.withScheduleTimes) !== null && _c !== void 0 ? _c : params.withScheduleItems;
29351
+ var _c, _d, _e, _f, _g, _h;
29352
+ var participantFilters = params.participantFilters, convertExtensions = params.convertExtensions, policyDefinitions = params.policyDefinitions, tournamentRecord = params.tournamentRecord, usePublishState = params.usePublishState, contextProfile = params.contextProfile, participantMap = params.participantMap, withPotentialMatchUps = params.withPotentialMatchUps, withRankingProfile = params.withRankingProfile, withScheduleItems = params.withScheduleItems, scheduleAnalysis = params.scheduleAnalysis, withTeamMatchUps = params.withTeamMatchUps, withStatistics = params.withStatistics, withOpponents = params.withOpponents, withMatchUps = params.withMatchUps, withSeeding = params.withSeeding, withEvents = params.withEvents, withDraws = params.withDraws;
29354
29353
  var targetParticipantIds = participantFilters === null || participantFilters === void 0 ? void 0 : participantFilters.participantIds;
29355
29354
  var getRelevantParticipantIds = function (participantId) {
29356
29355
  var _a, _b;
@@ -29372,7 +29371,7 @@ function getParticipantEntries(params) {
29372
29371
  withDraws: withDraws || withRankingProfile,
29373
29372
  withPotentialMatchUps: withPotentialMatchUps,
29374
29373
  withRankingProfile: withRankingProfile,
29375
- withScheduleTimes: withScheduleTimes,
29374
+ withScheduleItems: withScheduleItems,
29376
29375
  scheduleAnalysis: scheduleAnalysis,
29377
29376
  withTeamMatchUps: withTeamMatchUps,
29378
29377
  withStatistics: withStatistics,
@@ -29392,13 +29391,13 @@ function getParticipantEntries(params) {
29392
29391
  return (_e = (_d = (_c = (_b = participantMap[participantId].participant) === null || _b === void 0 ? void 0 : _b.rankings) === null || _c === void 0 ? void 0 : _c[eventType]) === null || _d === void 0 ? void 0 : _d.find(function (ranking) { return scaleNames.includes(ranking.scaleName); })) === null || _e === void 0 ? void 0 : _e.scaleValue;
29393
29392
  };
29394
29393
  var _loop_1 = function (event_1) {
29395
- var e_3, _m, e_4, _o, e_5, _p;
29394
+ var e_3, _l, e_4, _m, e_5, _o;
29396
29395
  if ((participantFilters === null || participantFilters === void 0 ? void 0 : participantFilters.eventIds) &&
29397
29396
  !participantFilters.eventIds.includes(event_1.eventId))
29398
29397
  return "continue";
29399
- var _q = event_1.drawDefinitions, drawDefinitions = _q === void 0 ? [] : _q, _r = event_1.extensions, extensions = _r === void 0 ? [] : _r, eventType = event_1.eventType, eventName = event_1.eventName, category = event_1.category, entries = event_1.entries, eventId = event_1.eventId, gender = event_1.gender;
29398
+ var _p = event_1.drawDefinitions, drawDefinitions = _p === void 0 ? [] : _p, _q = event_1.extensions, extensions = _q === void 0 ? [] : _q, eventType = event_1.eventType, eventName = event_1.eventName, category = event_1.category, entries = event_1.entries, eventId = event_1.eventId, gender = event_1.gender;
29400
29399
  var flightProfile = getFlightProfile({ event: event_1 }).flightProfile;
29401
- var flights = (_d = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) !== null && _d !== void 0 ? _d : [];
29400
+ var flights = (_c = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) !== null && _c !== void 0 ? _c : [];
29402
29401
  var publishStatuses = getEventPublishStatuses({ event: event_1 });
29403
29402
  var publishedSeeding = publishStatuses === null || publishStatuses === void 0 ? void 0 : publishStatuses.publishedSeeding;
29404
29403
  if (publishStatuses)
@@ -29412,7 +29411,7 @@ function getParticipantEntries(params) {
29412
29411
  category === null || category === void 0 ? void 0 : category.ageCategoryCode,
29413
29412
  ].filter(Boolean);
29414
29413
  var _loop_3 = function (entry) {
29415
- var _s;
29414
+ var _r;
29416
29415
  var participantId = entry.participantId;
29417
29416
  if (!participantId || !participantMap[participantId])
29418
29417
  return "continue"; // handle bad data
@@ -29421,13 +29420,13 @@ function getParticipantEntries(params) {
29421
29420
  var seedAssignments, seedValue;
29422
29421
  if (withSeeding) {
29423
29422
  var participant = participantMap[participantId].participant;
29424
- (_s = getEventSeedAssignments({
29423
+ (_r = getEventSeedAssignments({
29425
29424
  publishedSeeding: publishedSeeding,
29426
29425
  usePublishState: usePublishState,
29427
29426
  withSeeding: withSeeding,
29428
29427
  participant: participant,
29429
29428
  event: event_1,
29430
- }), seedAssignments = _s.seedAssignments, seedValue = _s.seedValue);
29429
+ }), seedAssignments = _r.seedAssignments, seedValue = _r.seedValue);
29431
29430
  }
29432
29431
  // IMPORTANT NOTE!
29433
29432
  // id is the pair, team or individual participant currently being processed
@@ -29463,12 +29462,12 @@ function getParticipantEntries(params) {
29463
29462
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
29464
29463
  finally {
29465
29464
  try {
29466
- if (entries_1_1 && !entries_1_1.done && (_m = entries_1.return)) _m.call(entries_1);
29465
+ if (entries_1_1 && !entries_1_1.done && (_l = entries_1.return)) _l.call(entries_1);
29467
29466
  }
29468
29467
  finally { if (e_3) throw e_3.error; }
29469
29468
  }
29470
29469
  }
29471
- var eventPublishedSeeding = (_e = eventsPublishStatuses === null || eventsPublishStatuses === void 0 ? void 0 : eventsPublishStatuses[eventId]) === null || _e === void 0 ? void 0 : _e.publishedSeeding;
29470
+ var eventPublishedSeeding = (_d = eventsPublishStatuses === null || eventsPublishStatuses === void 0 ? void 0 : eventsPublishStatuses[eventId]) === null || _d === void 0 ? void 0 : _d.publishedSeeding;
29472
29471
  if (withDraws || withRankingProfile || withSeeding) {
29473
29472
  var getSeedingMap = function (assignments) {
29474
29473
  return assignments
@@ -29482,11 +29481,11 @@ function getParticipantEntries(params) {
29482
29481
  };
29483
29482
  var drawIds = unique(__spreadArray(__spreadArray([], __read(drawDefinitions.map(extractAttributes('drawId'))), false), __read(flights.map(extractAttributes('drawId'))), false));
29484
29483
  var _loop_4 = function (drawId) {
29485
- var e_6, _t;
29484
+ var e_6, _s;
29486
29485
  var drawDefinition = drawDefinitions.find(function (drawDefinition) { return drawDefinition.drawId === drawId; });
29487
29486
  var flight = flights === null || flights === void 0 ? void 0 : flights.find(function (flight) { return flight.drawId === drawId; });
29488
29487
  var entries_2 = (drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) || (flight === null || flight === void 0 ? void 0 : flight.drawEntries);
29489
- var _u = drawDefinition !== null && drawDefinition !== void 0 ? drawDefinition : {}, _v = _u.structures, structures = _v === void 0 ? [] : _v, drawOrder = _u.drawOrder, drawName = _u.drawName, drawType = _u.drawType;
29488
+ var _t = drawDefinition !== null && drawDefinition !== void 0 ? drawDefinition : {}, _u = _t.structures, structures = _u === void 0 ? [] : _u, drawOrder = _t.drawOrder, drawName = _t.drawName, drawType = _t.drawType;
29490
29489
  var flightNumber = flight === null || flight === void 0 ? void 0 : flight.flightNumber;
29491
29490
  var scaleNames = [
29492
29491
  category === null || category === void 0 ? void 0 : category.categoryName,
@@ -29547,8 +29546,8 @@ function getParticipantEntries(params) {
29547
29546
  });
29548
29547
  var seedingPublished = !usePublishState ||
29549
29548
  ((eventPublishedSeeding === null || eventPublishedSeeding === void 0 ? void 0 : eventPublishedSeeding.published) &&
29550
- (((_f = eventPublishedSeeding === null || eventPublishedSeeding === void 0 ? void 0 : eventPublishedSeeding.drawIds) === null || _f === void 0 ? void 0 : _f.length) === 0 ||
29551
- ((_g = eventPublishedSeeding === null || eventPublishedSeeding === void 0 ? void 0 : eventPublishedSeeding.drawIds) === null || _g === void 0 ? void 0 : _g.includes(drawId))));
29549
+ (((_e = eventPublishedSeeding === null || eventPublishedSeeding === void 0 ? void 0 : eventPublishedSeeding.drawIds) === null || _e === void 0 ? void 0 : _e.length) === 0 ||
29550
+ ((_f = eventPublishedSeeding === null || eventPublishedSeeding === void 0 ? void 0 : eventPublishedSeeding.drawIds) === null || _f === void 0 ? void 0 : _f.includes(drawId))));
29552
29551
  var _loop_6 = function (entry) {
29553
29552
  var entryStatus = entry.entryStatus, entryStage = entry.entryStage, entryPosition = entry.entryPosition, participantId = entry.participantId;
29554
29553
  // get event ranking
@@ -29646,7 +29645,7 @@ function getParticipantEntries(params) {
29646
29645
  catch (e_6_1) { e_6 = { error: e_6_1 }; }
29647
29646
  finally {
29648
29647
  try {
29649
- if (relevantEntries_1_1 && !relevantEntries_1_1.done && (_t = relevantEntries_1.return)) _t.call(relevantEntries_1);
29648
+ if (relevantEntries_1_1 && !relevantEntries_1_1.done && (_s = relevantEntries_1.return)) _s.call(relevantEntries_1);
29650
29649
  }
29651
29650
  finally { if (e_6) throw e_6.error; }
29652
29651
  }
@@ -29676,7 +29675,7 @@ function getParticipantEntries(params) {
29676
29675
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
29677
29676
  finally {
29678
29677
  try {
29679
- if (drawIds_1_1 && !drawIds_1_1.done && (_o = drawIds_1.return)) _o.call(drawIds_1);
29678
+ if (drawIds_1_1 && !drawIds_1_1.done && (_m = drawIds_1.return)) _m.call(drawIds_1);
29680
29679
  }
29681
29680
  finally { if (e_4) throw e_4.error; }
29682
29681
  }
@@ -29689,7 +29688,7 @@ function getParticipantEntries(params) {
29689
29688
  withMatchUps ||
29690
29689
  withDraws) {
29691
29690
  var nextMatchUps = !!scheduleAnalysis || withPotentialMatchUps;
29692
- var eventMatchUps = (_j = (_h = allEventMatchUps({
29691
+ var eventMatchUps = (_h = (_g = allEventMatchUps({
29693
29692
  afterRecoveryTimes: !!scheduleAnalysis,
29694
29693
  policyDefinitions: policyDefinitions,
29695
29694
  tournamentRecord: tournamentRecord,
@@ -29698,10 +29697,10 @@ function getParticipantEntries(params) {
29698
29697
  participantMap: participantMap,
29699
29698
  nextMatchUps: nextMatchUps,
29700
29699
  event: event_1,
29701
- })) === null || _h === void 0 ? void 0 : _h.matchUps) !== null && _j !== void 0 ? _j : [];
29700
+ })) === null || _g === void 0 ? void 0 : _g.matchUps) !== null && _h !== void 0 ? _h : [];
29702
29701
  var _loop_5 = function (matchUp) {
29703
- var e_7, _w;
29704
- var finishingPositionRange = matchUp.finishingPositionRange, potentialParticipants = matchUp.potentialParticipants, _x = matchUp.tieMatchUps, tieMatchUps = _x === void 0 ? [] : _x, _y = matchUp.sides, sides = _y === void 0 ? [] : _y, winningSide = matchUp.winningSide, matchUpType = matchUp.matchUpType, matchUpId = matchUp.matchUpId, eventId_1 = matchUp.eventId, drawId = matchUp.drawId, collectionId = matchUp.collectionId, stageSequence = matchUp.stageSequence, finishingRound = matchUp.finishingRound, matchUpStatus = matchUp.matchUpStatus, roundPosition = matchUp.roundPosition, roundNumber = matchUp.roundNumber, structureId = matchUp.structureId, schedule = matchUp.schedule, score = matchUp.score, stage = matchUp.stage;
29702
+ var e_7, _v;
29703
+ var finishingPositionRange = matchUp.finishingPositionRange, potentialParticipants = matchUp.potentialParticipants, _w = matchUp.tieMatchUps, tieMatchUps = _w === void 0 ? [] : _w, _x = matchUp.sides, sides = _x === void 0 ? [] : _x, winningSide = matchUp.winningSide, matchUpType = matchUp.matchUpType, matchUpId = matchUp.matchUpId, eventId_1 = matchUp.eventId, drawId = matchUp.drawId, collectionId = matchUp.collectionId, stageSequence = matchUp.stageSequence, finishingRound = matchUp.finishingRound, matchUpStatus = matchUp.matchUpStatus, roundPosition = matchUp.roundPosition, roundNumber = matchUp.roundNumber, structureId = matchUp.structureId, schedule = matchUp.schedule, score = matchUp.score, stage = matchUp.stage;
29705
29704
  mappedMatchUps[matchUpId] = matchUp;
29706
29705
  var baseAttrs = {
29707
29706
  finishingPositionRange: finishingPositionRange,
@@ -29721,19 +29720,19 @@ function getParticipantEntries(params) {
29721
29720
  try {
29722
29721
  for (var tieMatchUps_1 = (e_7 = void 0, __values(tieMatchUps)), tieMatchUps_1_1 = tieMatchUps_1.next(); !tieMatchUps_1_1.done; tieMatchUps_1_1 = tieMatchUps_1.next()) {
29723
29722
  var tieMatchUp = tieMatchUps_1_1.value;
29724
- var tieMatchUpWinningSide = tieMatchUp.winningSide, _z = tieMatchUp.sides, tieMatchUpSides = _z === void 0 ? [] : _z, tieMatchUpId = tieMatchUp.matchUpId, matchUpStatus_1 = tieMatchUp.matchUpStatus, matchUpType_1 = tieMatchUp.matchUpType;
29723
+ var tieMatchUpWinningSide = tieMatchUp.winningSide, _y = tieMatchUp.sides, tieMatchUpSides = _y === void 0 ? [] : _y, tieMatchUpId = tieMatchUp.matchUpId, matchUpStatus_1 = tieMatchUp.matchUpStatus, matchUpType_1 = tieMatchUp.matchUpType;
29725
29724
  processSides(__assign(__assign(__assign({}, baseAttrs), withOpts), { winningSide: tieMatchUpWinningSide, tieWinningSide: winningSide, matchUpTieId: matchUpId, matchUpId: tieMatchUpId, sides: tieMatchUpSides, matchUpSides: sides, matchUpStatus: matchUpStatus_1, matchUpType: matchUpType_1 }));
29726
29725
  }
29727
29726
  }
29728
29727
  catch (e_7_1) { e_7 = { error: e_7_1 }; }
29729
29728
  finally {
29730
29729
  try {
29731
- if (tieMatchUps_1_1 && !tieMatchUps_1_1.done && (_w = tieMatchUps_1.return)) _w.call(tieMatchUps_1);
29730
+ if (tieMatchUps_1_1 && !tieMatchUps_1_1.done && (_v = tieMatchUps_1.return)) _v.call(tieMatchUps_1);
29732
29731
  }
29733
29732
  finally { if (e_7) throw e_7.error; }
29734
29733
  }
29735
29734
  if (Array.isArray(potentialParticipants) &&
29736
- (nextMatchUps || !!scheduleAnalysis || withScheduleTimes)) {
29735
+ (nextMatchUps || !!scheduleAnalysis || withScheduleItems)) {
29737
29736
  var potentialParticipantIds = potentialParticipants
29738
29737
  .flat()
29739
29738
  .map(extractAttributes('participantId'))
@@ -29751,7 +29750,7 @@ function getParticipantEntries(params) {
29751
29750
  drawId: drawId,
29752
29751
  });
29753
29752
  });
29754
- if (!!scheduleAnalysis || withScheduleTimes) {
29753
+ if (!!scheduleAnalysis || withScheduleItems) {
29755
29754
  addScheduleItem({
29756
29755
  potential: true,
29757
29756
  participantMap: participantMap,
@@ -29779,7 +29778,7 @@ function getParticipantEntries(params) {
29779
29778
  catch (e_5_1) { e_5 = { error: e_5_1 }; }
29780
29779
  finally {
29781
29780
  try {
29782
- if (eventMatchUps_1_1 && !eventMatchUps_1_1.done && (_p = eventMatchUps_1.return)) _p.call(eventMatchUps_1);
29781
+ if (eventMatchUps_1_1 && !eventMatchUps_1_1.done && (_o = eventMatchUps_1.return)) _o.call(eventMatchUps_1);
29783
29782
  }
29784
29783
  finally { if (e_5) throw e_5.error; }
29785
29784
  }
@@ -29787,23 +29786,23 @@ function getParticipantEntries(params) {
29787
29786
  }
29788
29787
  };
29789
29788
  try {
29790
- for (var _k = __values((tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.events) || []), _l = _k.next(); !_l.done; _l = _k.next()) {
29791
- var event_1 = _l.value;
29789
+ for (var _j = __values((tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.events) || []), _k = _j.next(); !_k.done; _k = _j.next()) {
29790
+ var event_1 = _k.value;
29792
29791
  _loop_1(event_1);
29793
29792
  }
29794
29793
  }
29795
29794
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
29796
29795
  finally {
29797
29796
  try {
29798
- if (_l && !_l.done && (_a = _k.return)) _a.call(_k);
29797
+ if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
29799
29798
  }
29800
29799
  finally { if (e_1) throw e_1.error; }
29801
29800
  }
29802
29801
  if (withStatistics || withRankingProfile || !!scheduleAnalysis) {
29803
29802
  var aggregators = Object.values(participantMap);
29804
29803
  var _loop_2 = function (participantAggregator) {
29805
- var e_8, _0, e_9, _1, e_10, _2;
29806
- var _3 = participantAggregator.counters, wins = _3.wins, losses = _3.losses, _4 = SINGLES$1, _5 = _3[_4], singlesWins = _5.wins, singlesLosses = _5.losses, _6 = DOUBLES$1, _7 = _3[_6], doublesWins = _7.wins, doublesLosses = _7.losses;
29804
+ var e_8, _z, e_9, _0, e_10, _1;
29805
+ var _2 = participantAggregator.counters, wins = _2.wins, losses = _2.losses, _3 = SINGLES$1, _4 = _2[_3], singlesWins = _4.wins, singlesLosses = _4.losses, _5 = DOUBLES$1, _6 = _2[_5], doublesWins = _6.wins, doublesLosses = _6.losses;
29807
29806
  var addStatValue = function (statCode, wins, losses) {
29808
29807
  var denominator = wins + losses;
29809
29808
  var numerator = wins;
@@ -29826,7 +29825,7 @@ function getParticipantEntries(params) {
29826
29825
  return Math.abs(range[0] - range[1]);
29827
29826
  };
29828
29827
  var _loop_7 = function (drawId) {
29829
- var _10 = derivedDrawInfo[drawId] || {}, _11 = _10.orderedStructureIds, orderedStructureIds = _11 === void 0 ? [] : _11, flightNumber = _10.flightNumber;
29828
+ var _9 = derivedDrawInfo[drawId] || {}, _10 = _9.orderedStructureIds, orderedStructureIds = _10 === void 0 ? [] : _10, flightNumber = _9.flightNumber;
29830
29829
  if (participantAggregator.structureParticipation &&
29831
29830
  orderedStructureIds.length) {
29832
29831
  var finishingPositionRange_1;
@@ -29862,15 +29861,15 @@ function getParticipantEntries(params) {
29862
29861
  }
29863
29862
  };
29864
29863
  try {
29865
- for (var _8 = (e_8 = void 0, __values(Object.keys(participantAggregator.draws))), _9 = _8.next(); !_9.done; _9 = _8.next()) {
29866
- var drawId = _9.value;
29864
+ for (var _7 = (e_8 = void 0, __values(Object.keys(participantAggregator.draws))), _8 = _7.next(); !_8.done; _8 = _7.next()) {
29865
+ var drawId = _8.value;
29867
29866
  _loop_7(drawId);
29868
29867
  }
29869
29868
  }
29870
29869
  catch (e_8_1) { e_8 = { error: e_8_1 }; }
29871
29870
  finally {
29872
29871
  try {
29873
- if (_9 && !_9.done && (_0 = _8.return)) _0.call(_8);
29872
+ if (_8 && !_8.done && (_z = _7.return)) _z.call(_7);
29874
29873
  }
29875
29874
  finally { if (e_8) throw e_8.error; }
29876
29875
  }
@@ -29915,20 +29914,22 @@ function getParticipantEntries(params) {
29915
29914
  var sameDraw = scheduleItem.drawId === consideredItem.drawId;
29916
29915
  var bothPotential = potentialMatchUps[scheduleItem.matchUpId] &&
29917
29916
  potentialMatchUps[consideredItem.matchUpId];
29918
- var nextMinutes = timeStringMinutes(consideredItem.scheduledTime);
29919
- var minutesDifference = Math.abs(nextMinutes - scheduledMinutes);
29917
+ var consideredMinutes = timeStringMinutes(consideredItem.scheduledTime);
29918
+ var minutesDifference = Math.abs(consideredMinutes - scheduledMinutes);
29919
+ var itemIsPrior = consideredMinutes > scheduledMinutes;
29920
29920
  // Conflicts can be determined in two ways:
29921
29921
  // 1. scheduledMinutesDifference - the minutes difference between two scheduledTimes
29922
29922
  // 2. A scheduledTime occurring before a prior matchUps notBeforeTime (timeAfterRecovery)
29923
29923
  var timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference)
29924
29924
  ? minutesDifference <= scheduledMinutesDifference
29925
- : timeStringMinutes(notBeforeTime) >
29926
- timeStringMinutes(consideredItem.scheduledTime);
29925
+ : itemIsPrior &&
29926
+ timeStringMinutes(consideredItem.scheduledTime) <
29927
+ timeStringMinutes(notBeforeTime);
29927
29928
  // if there is a time overlap capture both the prior matchUpId and the conflicted matchUpId
29928
- if (timeOverlap && !(bothPotential && sameDraw)) {
29929
+ if (timeOverlap && !(bothPotential && sameDraw) && itemIsPrior) {
29929
29930
  participantAggregator.scheduleConflicts.push({
29930
- priorScheduledMatchUpId: consideredItem.matchUpId,
29931
- matchUpIdWithConflict: scheduleItem.matchUpId,
29931
+ priorScheduledMatchUpId: scheduleItem.matchUpId,
29932
+ matchUpIdWithConflict: consideredItem.matchUpId,
29932
29933
  });
29933
29934
  }
29934
29935
  }
@@ -29936,7 +29937,7 @@ function getParticipantEntries(params) {
29936
29937
  catch (e_10_1) { e_10 = { error: e_10_1 }; }
29937
29938
  finally {
29938
29939
  try {
29939
- if (scheduleItemsToConsider_1_1 && !scheduleItemsToConsider_1_1.done && (_2 = scheduleItemsToConsider_1.return)) _2.call(scheduleItemsToConsider_1);
29940
+ if (scheduleItemsToConsider_1_1 && !scheduleItemsToConsider_1_1.done && (_1 = scheduleItemsToConsider_1.return)) _1.call(scheduleItemsToConsider_1);
29940
29941
  }
29941
29942
  finally { if (e_10) throw e_10.error; }
29942
29943
  }
@@ -29945,7 +29946,7 @@ function getParticipantEntries(params) {
29945
29946
  catch (e_9_1) { e_9 = { error: e_9_1 }; }
29946
29947
  finally {
29947
29948
  try {
29948
- if (scheduleItems_1_1 && !scheduleItems_1_1.done && (_1 = scheduleItems_1.return)) _1.call(scheduleItems_1);
29949
+ if (scheduleItems_1_1 && !scheduleItems_1_1.done && (_0 = scheduleItems_1.return)) _0.call(scheduleItems_1);
29949
29950
  }
29950
29951
  finally { if (e_9) throw e_9.error; }
29951
29952
  }
@@ -30195,7 +30196,7 @@ function getParticipants$1(params) {
30195
30196
  participantMap = entriesResult.participantMap;
30196
30197
  var nextMatchUps = scheduleAnalysis !== null && scheduleAnalysis !== void 0 ? scheduleAnalysis : withPotentialMatchUps;
30197
30198
  var processedParticipants = Object.values(participantMap).map(function (_a) {
30198
- var potentialMatchUps = _a.potentialMatchUps, scheduleConflicts = _a.scheduleConflicts, participant = _a.participant, statistics = _a.statistics, opponents = _a.opponents, matchUps = _a.matchUps, events = _a.events, draws = _a.draws;
30199
+ var potentialMatchUps = _a.potentialMatchUps, scheduleConflicts = _a.scheduleConflicts, scheduleItems = _a.scheduleItems, participant = _a.participant, statistics = _a.statistics, opponents = _a.opponents, matchUps = _a.matchUps, events = _a.events, draws = _a.draws;
30199
30200
  var participantDraws = Object.values(draws);
30200
30201
  var participantOpponents = Object.values(opponents);
30201
30202
  if (withOpponents) {
@@ -30209,7 +30210,7 @@ function getParticipants$1(params) {
30209
30210
  ? Object.values(matchUps)
30210
30211
  : undefined, opponents: withOpponents ? participantOpponents : undefined, potentialMatchUps: nextMatchUps
30211
30212
  ? Object.values(potentialMatchUps)
30212
- : undefined, statistics: withStatistics ? Object.values(statistics) : undefined }), false, false, true);
30213
+ : undefined, statistics: withStatistics ? Object.values(statistics) : undefined, scheduleItems: withScheduleItems ? scheduleItems : undefined }), false, false, true);
30213
30214
  });
30214
30215
  var participantAttributes = policyDefinitions === null || policyDefinitions === void 0 ? void 0 : policyDefinitions[POLICY_TYPE_PARTICIPANT];
30215
30216
  var template = participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.participant;
@@ -30229,1573 +30230,400 @@ function getParticipants$1(params) {
30229
30230
  return __assign(__assign({ participantIdsWithConflicts: participantIdsWithConflicts, eventsPublishStatuses: eventsPublishStatuses, derivedEventInfo: derivedEventInfo, derivedDrawInfo: derivedDrawInfo, mappedMatchUps: mappedMatchUps, participantMap: participantMap, participants: participants }, SUCCESS), { matchUps: matchUps });
30230
30231
  }
30231
30232
 
30232
- function getDerivedPositionAssignments(_a) {
30233
- var _b, _c, _d, _e;
30234
- var derivedDrawInfo = _a.derivedDrawInfo, participantId = _a.participantId, drawId = _a.drawId;
30235
- var mainPositionAssignment = (_c = (_b = derivedDrawInfo[drawId]) === null || _b === void 0 ? void 0 : _b.mainPositionAssignments) === null || _c === void 0 ? void 0 : _c.find(function (assignment) { return assignment.participantId === participantId; });
30236
- var qualifyingPositionAssignment = (_e = (_d = derivedDrawInfo[drawId]) === null || _d === void 0 ? void 0 : _d.qualifyingPositionAssignments) === null || _e === void 0 ? void 0 : _e.find(function (assignment) { return assignment.participantId === participantId; });
30237
- var positionAssignments = {};
30238
- if (mainPositionAssignment) {
30239
- var participantId_1 = mainPositionAssignment.participantId, props = __rest(mainPositionAssignment, ["participantId"]);
30240
- if (participantId_1)
30241
- positionAssignments[MAIN] = __assign({}, props);
30242
- }
30243
- if (qualifyingPositionAssignment) {
30244
- var participantId_2 = qualifyingPositionAssignment.participantId, props = __rest(qualifyingPositionAssignment, ["participantId"]);
30245
- if (participantId_2)
30246
- positionAssignments[QUALIFYING] = __assign({}, props);
30247
- }
30248
- return Object.keys(positionAssignments).length
30249
- ? positionAssignments
30250
- : undefined;
30251
- }
30252
-
30253
- function getRelevantParticipantIdsMap(_a) {
30254
- var processParticipantId = _a.processParticipantId, // optional method which is passed each participantId
30255
- tournamentRecords = _a.tournamentRecords, tournamentRecord = _a.tournamentRecord;
30256
- if (typeof tournamentRecord !== 'object' &&
30257
- typeof tournamentRecords !== 'object')
30258
- return { error: MISSING_TOURNAMENT_RECORD };
30259
- // build up a mapping of all participantIds to all of the individualParticipantIds that they reference
30260
- // this map includes the key participantId as a value of the array of relevantParticipantIds
30261
- var allParticipants = tournamentRecords
30262
- ? Object.values(tournamentRecords)
30263
- .map(function (tournamentRecord) { return (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || []; })
30264
- .flat()
30265
- : (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
30266
- var relevantParticipantIdsMap = Object.assign.apply(Object, __spreadArray([{}], __read(allParticipants.map(function (_a) {
30267
- var _b;
30268
- var participantId = _a.participantId, participantType = _a.participantType, individualParticipantIds = _a.individualParticipantIds;
30269
- typeof processParticipantId === 'function' &&
30270
- processParticipantId(participantId);
30271
- var individualParticipantIdObjects = (individualParticipantIds || []).map(function (relevantParticipantId) { return ({
30272
- participantType: INDIVIDUAL,
30273
- relevantParticipantId: relevantParticipantId,
30274
- }); });
30275
- return _b = {},
30276
- _b[participantId] = individualParticipantIdObjects.concat({
30277
- relevantParticipantId: participantId,
30278
- participantType: participantType,
30279
- }),
30280
- _b;
30281
- })), false));
30282
- return { relevantParticipantIdsMap: relevantParticipantIdsMap };
30283
- }
30284
-
30285
- function getDerivedSeedAssignments(_a) {
30286
- var _b, _c, _d, _e;
30287
- var derivedDrawInfo = _a.derivedDrawInfo, participantId = _a.participantId, drawId = _a.drawId;
30288
- var mainSeedAssignment = (_c = (_b = derivedDrawInfo[drawId]) === null || _b === void 0 ? void 0 : _b.mainSeedAssignments) === null || _c === void 0 ? void 0 : _c.find(function (assignment) { return assignment.participantId === participantId; });
30289
- var qualifyingSeedAssignment = (_e = (_d = derivedDrawInfo[drawId]) === null || _d === void 0 ? void 0 : _d.qualifyingSeedAssignments) === null || _e === void 0 ? void 0 : _e.find(function (assignment) { return assignment.participantId === participantId; });
30290
- var seedAssignments = {};
30291
- if (mainSeedAssignment) {
30292
- var participantId_1 = mainSeedAssignment.participantId, props = __rest(mainSeedAssignment, ["participantId"]);
30293
- if (participantId_1)
30294
- seedAssignments[MAIN] = __assign({}, props);
30295
- }
30296
- if (qualifyingSeedAssignment) {
30297
- var participantId_2 = qualifyingSeedAssignment.participantId, props = __rest(qualifyingSeedAssignment, ["participantId"]);
30298
- if (participantId_2)
30299
- seedAssignments[QUALIFYING] = __assign({}, props);
30300
- }
30301
- return Object.keys(seedAssignments).length ? seedAssignments : undefined;
30302
- }
30303
-
30304
- var hasSchedule = function (_a) {
30305
- var _b = _a.scheduleAttributes, scheduleAttributes = _b === void 0 ? ['scheduledDate', 'scheduledTime'] : _b, _c = _a.schedule, schedule = _c === void 0 ? {} : _c;
30306
- var matchUpScheduleKeys = Object.keys(schedule)
30307
- .filter(function (key) { return scheduleAttributes.includes(key); })
30308
- .filter(function (key) { return schedule[key]; });
30309
- return !!matchUpScheduleKeys.length;
30310
- };
30311
-
30312
- function participantScheduledMatchUps(_a) {
30313
- var _b = _a.scheduleAttributes, scheduleAttributes = _b === void 0 ? ['scheduledDate', 'scheduledTime'] : _b, _c = _a.matchUps, matchUps = _c === void 0 ? [] : _c;
30314
- if (!validMatchUps(matchUps))
30315
- return { error: MISSING_MATCHUPS };
30316
- if (!Array.isArray(scheduleAttributes))
30317
- return { error: INVALID_VALUES };
30318
- var scheduledMatchUps = matchUps
30319
- .filter(Boolean)
30320
- .filter(function (_a) {
30321
- var schedule = _a.schedule;
30322
- return hasSchedule({ schedule: schedule, scheduleAttributes: scheduleAttributes });
30323
- })
30324
- .reduce(function (dateMatchUps, matchUp) {
30325
- var schedule = matchUp.schedule;
30326
- var date = extractDate(schedule === null || schedule === void 0 ? void 0 : schedule.scheduledDate);
30327
- var time = extractTime(schedule === null || schedule === void 0 ? void 0 : schedule.scheduledTime);
30328
- if (date && time) {
30329
- if (dateMatchUps[date]) {
30330
- dateMatchUps[date].push(matchUp);
30233
+ // arrayMerge can be boolean or an array of target attributes which are arrays to merge
30234
+ function deepMerge(existing, incoming, arrayMerge) {
30235
+ if (!existing && incoming)
30236
+ return incoming;
30237
+ if (existing && !incoming)
30238
+ return existing;
30239
+ if (typeof existing !== 'object' || typeof incoming !== 'object')
30240
+ return existing;
30241
+ var keys = unique(Object.keys(existing).concat(Object.keys(incoming)));
30242
+ return keys.reduce(function (merged, key) {
30243
+ if (!incoming[key]) {
30244
+ merged[key] = existing[key];
30245
+ }
30246
+ else if (!existing[key]) {
30247
+ merged[key] = incoming[key];
30248
+ }
30249
+ else if (typeof existing[key] !== typeof incoming[key]) {
30250
+ merged[key] = incoming[key];
30251
+ }
30252
+ else if (Array.isArray(existing[key])) {
30253
+ if (arrayMerge === true ||
30254
+ (Array.isArray(arrayMerge) && arrayMerge.includes(key))) {
30255
+ var mergedArrays = unique(existing[key]
30256
+ .map(function (e) { return JSON.stringify(e); })
30257
+ .concat(incoming[key].map(function (i) { return JSON.stringify(i); }))).map(function (u) { return JSON.parse(u); });
30258
+ merged[key] = mergedArrays;
30331
30259
  }
30332
30260
  else {
30333
- dateMatchUps[date] = [matchUp];
30261
+ // default is to overwrite existing array with incoming
30262
+ merged[key] = incoming[key];
30334
30263
  }
30335
30264
  }
30336
- return dateMatchUps;
30265
+ else if (typeof existing[key] === 'object') {
30266
+ merged[key] = deepMerge(existing[key], incoming[key], arrayMerge);
30267
+ }
30268
+ else {
30269
+ merged[key] = incoming[key];
30270
+ }
30271
+ return merged;
30337
30272
  }, {});
30338
- // sort all date matchUps
30339
- var dates = Object.keys(scheduledMatchUps);
30340
- dates.forEach(function (date) {
30341
- scheduledMatchUps[date].sort(function (a, b) {
30342
- var _a, _b;
30343
- return timeSort(extractTime((_a = a.schedule) === null || _a === void 0 ? void 0 : _a.scheduledTime), extractTime((_b = b.schedule) === null || _b === void 0 ? void 0 : _b.scheduledTime));
30344
- });
30345
- });
30346
- return { scheduledMatchUps: scheduledMatchUps };
30347
30273
  }
30348
30274
 
30349
- function annotateParticipant(params) {
30350
- var e_1, _a, e_2, _b;
30351
- var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
30352
- var _p = params.withScaleValues, withScaleValues = _p === void 0 ? true : _p, eventsPublishStatuses = params.eventsPublishStatuses, _q = params.withEvents, withEvents = _q === void 0 ? true : _q, _r = params.withDraws, withDraws = _r === void 0 ? true : _r, participantIdMap = params.participantIdMap, scheduleAnalysis = params.scheduleAnalysis, derivedDrawInfo = params.derivedDrawInfo, usePublishState = params.usePublishState, withStatistics = params.withStatistics, withOpponents = params.withOpponents, withMatchUps = params.withMatchUps, withSeeding = params.withSeeding, participant = params.participant, withISO2 = params.withISO2, withIOC = params.withIOC;
30353
- var scheduleConflicts = [];
30354
- var scheduleItems = [];
30355
- if (withIOC || withISO2)
30356
- addNationalityCode({ participant: participant, withIOC: withIOC, withISO2: withISO2 });
30357
- if (withScaleValues) {
30358
- var _s = getScaleValues({ participant: participant }), ratings = _s.ratings, rankings = _s.rankings;
30359
- participant.rankings = rankings;
30360
- participant.ratings = ratings;
30275
+ function getParticipants(params) {
30276
+ var e_1, _a;
30277
+ var tournamentRecords = (params || {}).tournamentRecords;
30278
+ if (typeof tournamentRecords !== 'object' ||
30279
+ !Object.keys(tournamentRecords).length) {
30280
+ return { error: MISSING_TOURNAMENT_RECORDS };
30361
30281
  }
30362
- var participantId = participant === null || participant === void 0 ? void 0 : participant.participantId;
30363
- if (!participantId || !participantIdMap[participantId])
30364
- return {};
30365
- var _t = participantIdMap[participantId], potentialMatchUps = _t.potentialMatchUps, opponents = _t.opponents, matchUps = _t.matchUps, events = _t.events, losses = _t.losses, draws = _t.draws, wins = _t.wins;
30366
- var denominator = wins + losses;
30367
- var numerator = wins;
30368
- var statValue = denominator && numerator / denominator;
30369
- var winRatioStat = {
30370
- statCode: WIN_RATIO$1,
30371
- denominator: denominator,
30372
- numerator: numerator,
30373
- statValue: statValue,
30374
- };
30375
- var participantDraws = Object.values(draws);
30376
- var participantEvents = Object.values(events);
30377
- if (withDraws && participantDraws) {
30378
- participant.draws = participantDraws;
30379
- try {
30380
- for (var participantDraws_1 = __values(participantDraws), participantDraws_1_1 = participantDraws_1.next(); !participantDraws_1_1.done; participantDraws_1_1 = participantDraws_1.next()) {
30381
- var participantDraw = participantDraws_1_1.value;
30382
- var publishedSeeding = (_c = eventsPublishStatuses[participantDraw.eventId]) === null || _c === void 0 ? void 0 : _c.publishedSeeding;
30383
- var seedingPublished = !usePublishState ||
30384
- ((publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.published) &&
30385
- (((_d = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _d === void 0 ? void 0 : _d.length) === 0 ||
30386
- ((_e = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _e === void 0 ? void 0 : _e.includes(participantDraw.drawId))));
30387
- if (seedingPublished) {
30388
- var seedAssignments = getDerivedSeedAssignments({
30389
- drawId: participantDraw.drawId,
30390
- derivedDrawInfo: derivedDrawInfo,
30391
- participantId: participantId,
30392
- });
30393
- if (seedAssignments) {
30394
- participantDraw.seedAssignments = seedAssignments;
30395
- }
30396
- }
30397
- }
30282
+ var participantMap = {};
30283
+ var participants = [];
30284
+ var derivedEventInfo = {};
30285
+ var derivedDrawInfo = {};
30286
+ var matchUps = [];
30287
+ var mappedMatchUps = {};
30288
+ var participantIdsWithConflicts = [];
30289
+ try {
30290
+ for (var _b = __values(Object.values(tournamentRecords)), _c = _b.next(); !_c.done; _c = _b.next()) {
30291
+ var tournamentRecord = _c.value;
30292
+ var _d = getParticipants$1(__assign({ tournamentRecord: tournamentRecord }, params)), idsWithConflicts = _d.participantIdsWithConflicts, tournamentMappedMatchUps = _d.mappedMatchUps, tournamentParticipantMap = _d.participantMap, tournamentParticipants = _d.participants, tournamentMatchUps = _d.matchUps, eventInfo = _d.derivedEventInfo, drawInfo = _d.derivedDrawInfo;
30293
+ Object.assign(mappedMatchUps, tournamentMappedMatchUps);
30294
+ Object.assign(participantMap, tournamentParticipantMap);
30295
+ Object.assign(derivedEventInfo, eventInfo);
30296
+ Object.assign(derivedDrawInfo, drawInfo);
30297
+ participants.push.apply(participants, __spreadArray([], __read((tournamentParticipants !== null && tournamentParticipants !== void 0 ? tournamentParticipants : [])), false));
30298
+ matchUps.push.apply(matchUps, __spreadArray([], __read((tournamentMatchUps !== null && tournamentMatchUps !== void 0 ? tournamentMatchUps : [])), false));
30299
+ idsWithConflicts === null || idsWithConflicts === void 0 ? void 0 : idsWithConflicts.forEach(function (participantId) {
30300
+ if (!participantIdsWithConflicts.includes(participantId))
30301
+ participantIdsWithConflicts.push(participantId);
30302
+ });
30398
30303
  }
30399
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
30400
- finally {
30401
- try {
30402
- if (participantDraws_1_1 && !participantDraws_1_1.done && (_a = participantDraws_1.return)) _a.call(participantDraws_1);
30403
- }
30404
- finally { if (e_1) throw e_1.error; }
30304
+ }
30305
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
30306
+ finally {
30307
+ try {
30308
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
30405
30309
  }
30310
+ finally { if (e_1) throw e_1.error; }
30406
30311
  }
30407
- if (withEvents && participantEvents) {
30408
- participant.events = participantEvents;
30409
- if (withSeeding) {
30410
- var seedingScales_1 = Object.assign.apply(Object, __spreadArray([{}], __read((participant.timeItems || [])
30411
- .filter(function (_a) {
30412
- var itemType = _a.itemType;
30413
- return itemType.split('.')[1] === SEEDING$1;
30414
- })
30415
- .map(function (_a) {
30416
- var _b;
30417
- var seedingScaleName = _a.itemType, seedValue = _a.itemValue;
30418
- return (_b = {},
30419
- _b[seedingScaleName] = seedValue,
30420
- _b);
30421
- })), false));
30422
- var _loop_1 = function (participantEvent) {
30423
- var e_3, _u, e_4, _v, e_5, _w;
30424
- var getScaleAccessor = function (scaleName) {
30425
- return [SCALE$1, SEEDING$1, participantEvent.eventType, scaleName].join('.');
30426
- };
30427
- var publishedSeeding = (_f = eventsPublishStatuses[participantEvent.eventId]) === null || _f === void 0 ? void 0 : _f.publishedSeeding;
30428
- var eventSeedingScaleNames = (((publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.stageSeedingScaleNames) &&
30429
- Object.values(publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.stageSeedingScaleNames)) ||
30430
- (Array.isArray(publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.seedingScaleNames) &&
30431
- publishedSeeding.seedingScaleNames) ||
30432
- []).map(getScaleAccessor);
30433
- var publishedEventSeedingScaleNames = intersection(Object.keys(seedingScales_1), eventSeedingScaleNames);
30434
- var eventSeedingPublished = !!(!usePublishState ||
30435
- (!Object.keys(seedingScales_1).length &&
30436
- !((_g = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _g === void 0 ? void 0 : _g.length)) ||
30437
- publishedEventSeedingScaleNames.length);
30438
- if (eventSeedingPublished && publishedEventSeedingScaleNames.length) {
30439
- if (publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.stageSeedingScaleNames) {
30440
- var scaleValues = Object.keys(publishedSeeding.stageSeedingScaleNames)
30441
- .map(function (key) {
30442
- var accessor = getScaleAccessor(publishedSeeding.stageSeedingScaleNames[key]);
30443
- var scaleValue = seedingScales_1[accessor];
30444
- return [key, scaleValue];
30445
- })
30446
- .filter(function (pair) { return pair[1]; })
30447
- .map(function (pair) {
30448
- var _a;
30449
- return (_a = {}, _a[pair[0]] = { seedValue: pair[1] }, _a);
30450
- });
30451
- var seedAssignments = Object.assign.apply(Object, __spreadArray([{}], __read(scaleValues), false));
30452
- participantEvent.seedAssignments = seedAssignments;
30453
- }
30454
- else if (publishedEventSeedingScaleNames) {
30455
- var seedValues = publishedEventSeedingScaleNames.map(function (scaleName) { return seedingScales_1[scaleName]; });
30456
- participantEvent.seedValue = seedValues.pop();
30457
- }
30458
- }
30459
- else if (!usePublishState && typeof withSeeding === 'object') {
30460
- var scaleValues = Object.keys(withSeeding)
30461
- .map(function (key) {
30462
- var accessor = getScaleAccessor(withSeeding[key]);
30463
- var scaleValue = seedingScales_1[accessor];
30464
- return [key, scaleValue];
30465
- })
30466
- .filter(function (pair) { return pair[1]; })
30467
- .map(function (pair) {
30468
- var _a;
30469
- return (_a = {}, _a[pair[0]] = { seedValue: pair[1] }, _a);
30470
- });
30471
- var seedAssignments = Object.assign.apply(Object, __spreadArray([{}], __read(scaleValues), false));
30472
- participantEvent.seedAssignments = seedAssignments;
30312
+ return __assign(__assign({ participantIdsWithConflicts: participantIdsWithConflicts, derivedEventInfo: derivedEventInfo, derivedDrawInfo: derivedDrawInfo, participantMap: participantMap, mappedMatchUps: mappedMatchUps, participants: participants }, SUCCESS), { matchUps: matchUps });
30313
+ }
30314
+ function getCompetitionParticipants(params) {
30315
+ var e_2, _a, e_3, _b;
30316
+ var tournamentRecords = (params || {}).tournamentRecords;
30317
+ if (typeof tournamentRecords !== 'object' ||
30318
+ !Object.keys(tournamentRecords).length)
30319
+ return { error: MISSING_TOURNAMENT_RECORDS };
30320
+ var competitionParticipants = [];
30321
+ var participantIdsWithConflicts = [];
30322
+ var competitionParticipantIds = [];
30323
+ var mappedMatchUps = {};
30324
+ try {
30325
+ for (var _c = __values(Object.values(tournamentRecords)), _d = _c.next(); !_d.done; _d = _c.next()) {
30326
+ var tournamentRecord = _d.value;
30327
+ var _e = getParticipants$1(__assign({ tournamentRecord: tournamentRecord }, params)), participants = _e.participants, idsWithConflicts = _e.participantIdsWithConflicts, matchUpsMap = _e.mappedMatchUps;
30328
+ if (matchUpsMap)
30329
+ Object.assign(mappedMatchUps, matchUpsMap);
30330
+ var _loop_1 = function (tournamentParticipant) {
30331
+ var participantId = tournamentParticipant.participantId;
30332
+ if (!competitionParticipantIds.includes(participantId)) {
30333
+ competitionParticipantIds.push(participantId);
30334
+ competitionParticipants.push(tournamentParticipant);
30473
30335
  }
30474
30336
  else {
30475
- var _x = participantEvent.category || {}, categoryName = _x.categoryName, ageCategoryCode = _x.ageCategoryCode;
30476
- var scaleItem = void 0;
30477
- try {
30478
- for (var _y = (e_3 = void 0, __values([
30479
- participantEvent.eventId,
30480
- ageCategoryCode,
30481
- categoryName,
30482
- ])), _z = _y.next(); !_z.done; _z = _y.next()) {
30483
- var scaleName = _z.value;
30484
- var scaleAttributes = {
30485
- eventType: participantEvent.eventType,
30486
- scaleType: SEEDING$1,
30487
- scaleName: scaleName,
30488
- };
30489
- var result = participantScaleItem({
30490
- scaleAttributes: scaleAttributes,
30491
- participant: participant,
30492
- });
30493
- if (result.scaleItem) {
30494
- scaleItem = result.scaleItem;
30495
- break;
30496
- }
30497
- }
30498
- }
30499
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
30500
- finally {
30501
- try {
30502
- if (_z && !_z.done && (_u = _y.return)) _u.call(_y);
30503
- }
30504
- finally { if (e_3) throw e_3.error; }
30505
- }
30506
- if (scaleItem) {
30507
- var seedValue = scaleItem.scaleValue;
30508
- var seedingPublished = !usePublishState ||
30509
- ((publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.published) &&
30510
- (((_h = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _h === void 0 ? void 0 : _h.length) === 0 ||
30511
- ((_j = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _j === void 0 ? void 0 : _j.includes(participantEvent.drawId))));
30512
- if (seedingPublished) {
30513
- participantEvent.seedValue = seedValue;
30514
- }
30515
- }
30516
- }
30517
- if ((_k = participantEvent.drawIds) === null || _k === void 0 ? void 0 : _k.length) {
30518
- try {
30519
- for (var _0 = (e_4 = void 0, __values(participantEvent.drawIds || [])), _1 = _0.next(); !_1.done; _1 = _0.next()) {
30520
- var flightDrawId = _1.value;
30521
- var drawSeedPublishingDisabled = ((_l = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _l === void 0 ? void 0 : _l.length) &&
30522
- !((_m = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _m === void 0 ? void 0 : _m.includes(flightDrawId));
30523
- if (eventSeedingPublished && !drawSeedPublishingDisabled) {
30524
- var seedAssignments = getDerivedSeedAssignments({
30525
- drawId: flightDrawId,
30526
- derivedDrawInfo: derivedDrawInfo,
30527
- participantId: participantId,
30528
- });
30529
- // preserve filtering of MAIN/QUALIFYING seedValues, if present
30530
- if (seedAssignments && participantEvent.seedAssignments) {
30531
- try {
30532
- for (var _2 = (e_5 = void 0, __values(Object.keys(participantEvent.seedAssignments))), _3 = _2.next(); !_3.done; _3 = _2.next()) {
30533
- var key = _3.value;
30534
- participantEvent.seedAssignments[key] = seedAssignments[key];
30535
- }
30536
- }
30537
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
30538
- finally {
30539
- try {
30540
- if (_3 && !_3.done && (_w = _2.return)) _w.call(_2);
30541
- }
30542
- finally { if (e_5) throw e_5.error; }
30543
- }
30544
- }
30545
- else {
30546
- participantEvent.seedAssignments = seedAssignments;
30547
- }
30548
- }
30549
- }
30550
- }
30551
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
30552
- finally {
30553
- try {
30554
- if (_1 && !_1.done && (_v = _0.return)) _v.call(_0);
30555
- }
30556
- finally { if (e_4) throw e_4.error; }
30557
- }
30337
+ // merge participant record context across tournaments
30338
+ competitionParticipants = competitionParticipants.map(function (participant) {
30339
+ return participant.participantId !== participantId
30340
+ ? participant
30341
+ : deepMerge(participant, tournamentParticipant, true);
30342
+ });
30558
30343
  }
30559
30344
  };
30560
30345
  try {
30561
- for (var participantEvents_1 = __values(participantEvents), participantEvents_1_1 = participantEvents_1.next(); !participantEvents_1_1.done; participantEvents_1_1 = participantEvents_1.next()) {
30562
- var participantEvent = participantEvents_1_1.value;
30563
- _loop_1(participantEvent);
30346
+ for (var _f = (e_3 = void 0, __values(participants !== null && participants !== void 0 ? participants : [])), _g = _f.next(); !_g.done; _g = _f.next()) {
30347
+ var tournamentParticipant = _g.value;
30348
+ _loop_1(tournamentParticipant);
30564
30349
  }
30565
30350
  }
30566
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
30351
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
30567
30352
  finally {
30568
30353
  try {
30569
- if (participantEvents_1_1 && !participantEvents_1_1.done && (_b = participantEvents_1.return)) _b.call(participantEvents_1);
30354
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
30570
30355
  }
30571
- finally { if (e_2) throw e_2.error; }
30356
+ finally { if (e_3) throw e_3.error; }
30572
30357
  }
30358
+ idsWithConflicts === null || idsWithConflicts === void 0 ? void 0 : idsWithConflicts.forEach(function (participantId) {
30359
+ if (!participantIdsWithConflicts.includes(participantId))
30360
+ participantIdsWithConflicts.push(participantId);
30361
+ });
30573
30362
  }
30574
30363
  }
30575
- var participantOpponents = Object.values(opponents).flat();
30576
- if (withOpponents && (participantOpponents === null || participantOpponents === void 0 ? void 0 : participantOpponents.length)) {
30577
- participant.opponents = participantOpponents;
30578
- participantDraws === null || participantDraws === void 0 ? void 0 : participantDraws.forEach(function (draw) {
30579
- draw.opponents = participantOpponents.filter(function (opponent) { return opponent.drawId === draw.drawId; });
30580
- });
30581
- }
30582
- var participantPotentialMatchUps = Object.values(potentialMatchUps);
30583
- var participantMatchUps = Object.values(matchUps);
30584
- if (withMatchUps) {
30585
- participant.potentialMatchUps = participantPotentialMatchUps;
30586
- participant.matchUps = participantMatchUps;
30364
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
30365
+ finally {
30366
+ try {
30367
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
30368
+ }
30369
+ finally { if (e_2) throw e_2.error; }
30587
30370
  }
30588
- var allParticipantMatchUps = participantMatchUps.concat(participantPotentialMatchUps);
30589
- // scheduledMatchUps are a participant's matchUps separated by date and sorted by scheduledTime
30590
- var scheduledMatchUps = ((_o = participantScheduledMatchUps({
30591
- matchUps: allParticipantMatchUps,
30592
- })) === null || _o === void 0 ? void 0 : _o.scheduledMatchUps) || [];
30593
- var scheduledMinutesDifference = (scheduleAnalysis || {}).scheduledMinutesDifference;
30594
- var dates = Object.keys(scheduledMatchUps);
30595
- dates.forEach(function (date) {
30596
- scheduledMatchUps[date].filter(Boolean).forEach(function (matchUp, i) {
30597
- var e_6, _a;
30598
- var _b, _c, _d, _e;
30599
- var _f = matchUp.schedule, scheduledTime = _f.scheduledTime, timeAfterRecovery = _f.timeAfterRecovery, typeChangeTimeAfterRecovery = _f.typeChangeTimeAfterRecovery, matchUpStatus = matchUp.matchUpStatus, roundPosition = matchUp.roundPosition, structureName = matchUp.structureName, matchUpType = matchUp.matchUpType, roundNumber = matchUp.roundNumber, matchUpId = matchUp.matchUpId, drawId = matchUp.drawId, score = matchUp.score;
30600
- scheduleItems.push(__assign(__assign({}, matchUp.schedule), { scheduledTime: extractTime((_b = matchUp.schedule) === null || _b === void 0 ? void 0 : _b.scheduledTime), roundPosition: roundPosition, structureName: structureName, matchUpType: matchUpType, roundNumber: roundNumber, matchUpId: matchUpId, drawId: drawId }));
30601
- // matchUps with { matchUpStatus: BYE } are ignored or { matchUpStatus: WALKOVER } and no score
30602
- var ignoreMatchUp = matchUpStatus === BYE ||
30603
- ([WALKOVER$2, DEFAULTED].includes(matchUpStatus) &&
30604
- !scoreHasValue({ score: score }));
30605
- if (scheduledTime && !ignoreMatchUp) {
30606
- var scheduledMinutes = timeStringMinutes(scheduledTime);
30607
- // each matchUp only considers conflicts with matchUps which occur at the same or later scheduledTime
30608
- var matchUpsToConsider = scheduledMatchUps[date].slice(i + 1);
30609
- try {
30610
- for (var matchUpsToConsider_1 = __values(matchUpsToConsider), matchUpsToConsider_1_1 = matchUpsToConsider_1.next(); !matchUpsToConsider_1_1.done; matchUpsToConsider_1_1 = matchUpsToConsider_1.next()) {
30611
- var consideredMatchUp = matchUpsToConsider_1_1.value;
30612
- // ignore { matchUpStatus: BYE } and matchUps which are unscheduled
30613
- var ignoreMatchUp_1 = consideredMatchUp.matchUpStatus === BYE ||
30614
- ([WALKOVER$2, DEFAULTED].includes(consideredMatchUp.matchUpStatus) &&
30615
- !scoreHasValue(consideredMatchUp));
30616
- if (!ignoreMatchUp_1 && ((_c = consideredMatchUp.schedule) === null || _c === void 0 ? void 0 : _c.scheduledTime)) {
30617
- // if there is a matchType change (SINGLES => DOUBLES or vice versa) then there is potentially a different timeAfterRecovery
30618
- var typeChange = matchUp.matchUpType !== consideredMatchUp.matchUpType;
30619
- var notBeforeTime = typeChange
30620
- ? typeChangeTimeAfterRecovery || timeAfterRecovery
30621
- : timeAfterRecovery;
30622
- // if two matchUps are both potentials and both part of the same draw they cannot be considered in conflict
30623
- var sameDraw = matchUp.drawId === consideredMatchUp.drawId;
30624
- var bothPotential = matchUp.potential && consideredMatchUp.potential;
30625
- var nextMinutes = timeStringMinutes((_d = consideredMatchUp.schedule) === null || _d === void 0 ? void 0 : _d.scheduledTime);
30626
- var minutesDifference = nextMinutes - scheduledMinutes;
30627
- // Conflicts can be determined in two ways:
30628
- // 1. scheduledMinutesDifference - the minutes difference between two scheduledTimes
30629
- // 2. A scheduledTime occurring before a prior matchUps notBeforeTime (timeAfterRecovery)
30630
- var timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference)
30631
- ? minutesDifference <= scheduledMinutesDifference
30632
- : timeStringMinutes(notBeforeTime) >
30633
- timeStringMinutes((_e = consideredMatchUp.schedule) === null || _e === void 0 ? void 0 : _e.scheduledTime);
30634
- // if there is a time overlap capture both the prior matchUpId and the conflicted matchUpId
30635
- if (timeOverlap && !(bothPotential && sameDraw)) {
30636
- scheduleConflicts.push({
30637
- priorScheduledMatchUpId: consideredMatchUp.matchUpId,
30638
- matchUpIdWithConflict: matchUpId,
30639
- });
30640
- }
30641
- }
30642
- }
30643
- }
30644
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
30645
- finally {
30646
- try {
30647
- if (matchUpsToConsider_1_1 && !matchUpsToConsider_1_1.done && (_a = matchUpsToConsider_1.return)) _a.call(matchUpsToConsider_1);
30648
- }
30649
- finally { if (e_6) throw e_6.error; }
30650
- }
30651
- }
30652
- });
30653
- });
30654
- if (withStatistics)
30655
- participant.statistics = [winRatioStat];
30656
- return { scheduleConflicts: scheduleConflicts, scheduleItems: scheduleItems };
30371
+ return __assign({ competitionParticipants: competitionParticipants, participantIdsWithConflicts: participantIdsWithConflicts, mappedMatchUps: mappedMatchUps }, SUCCESS);
30657
30372
  }
30658
-
30659
- function getDrawDetails(_a) {
30660
- var _b;
30661
- var eventEntries = _a.eventEntries, sortConfig = _a.sortConfig, event = _a.event;
30662
- var derivedInfo = {};
30663
- var drawDetails = Object.assign.apply(Object, __spreadArray([{}], __read(((_b = event.drawDefinitions) !== null && _b !== void 0 ? _b : []).map(function (drawDefinition) {
30664
- var _a;
30665
- var _b, _c, _d, _e, _f, _g, _h, _j, _k;
30666
- var entriesMap = Object.assign.apply(Object, __spreadArray(__spreadArray([{}], __read((eventEntries !== null && eventEntries !== void 0 ? eventEntries : [])
30667
- .filter(function (entry) { return entry.participantId; })
30668
- .map(function (entry) {
30669
- var _a;
30670
- return (_a = {}, _a[entry.participantId] = entry, _a);
30671
- })), false), __read(drawDefinition.entries
30672
- .filter(function (entry) { return entry.participantId; })
30673
- .map(function (entry) {
30674
- var _a;
30675
- return (_a = {}, _a[entry.participantId] = entry, _a);
30676
- })), false));
30677
- var drawEntries = Object.values(entriesMap);
30678
- var mainStructure = (_c = (_b = getDrawStructures({
30679
- stageSequence: 1,
30680
- drawDefinition: drawDefinition,
30681
- stage: MAIN,
30682
- })) === null || _b === void 0 ? void 0 : _b.structures) === null || _c === void 0 ? void 0 : _c[0];
30683
- var mainPositionAssignments = mainStructure &&
30684
- ((_d = getPositionAssignments$1({
30685
- structure: mainStructure,
30686
- })) === null || _d === void 0 ? void 0 : _d.positionAssignments);
30687
- var drawSize = mainPositionAssignments === null || mainPositionAssignments === void 0 ? void 0 : mainPositionAssignments.length;
30688
- var qualifyingStructure = (_f = (_e = getDrawStructures({
30689
- stageSequence: 1,
30690
- stage: QUALIFYING,
30691
- drawDefinition: drawDefinition,
30692
- })) === null || _e === void 0 ? void 0 : _e.structures) === null || _f === void 0 ? void 0 : _f[0];
30693
- var qualifyingPositionAssignments = mainStructure &&
30694
- ((_g = getPositionAssignments$1({
30695
- structure: qualifyingStructure,
30696
- })) === null || _g === void 0 ? void 0 : _g.positionAssignments);
30697
- var qualifyingDrawSize = qualifyingPositionAssignments === null || qualifyingPositionAssignments === void 0 ? void 0 : qualifyingPositionAssignments.length;
30698
- var mainSeedAssignments = mainStructure === null || mainStructure === void 0 ? void 0 : mainStructure.seedAssignments;
30699
- var qualifyingSeedAssignments = qualifyingStructure === null || qualifyingStructure === void 0 ? void 0 : qualifyingStructure.seedAssignments;
30700
- // used in rankings pipeline.
30701
- // the structures in which a particpant particpates are ordered
30702
- // to enable differentiation for Points-per-round and points-per-win
30703
- var orderedStructureIds = (drawDefinition.structures || [])
30704
- .sort(function (a, b) { return structureSort(a, b, sortConfig); })
30705
- .map(function (_a) {
30706
- var structureId = _a.structureId, structures = _a.structures;
30707
- return __spreadArray([
30708
- structureId
30709
- ], __read((structures || []).map(function (_a) {
30710
- var structureId = _a.structureId;
30711
- return structureId;
30712
- })), false);
30713
- })
30714
- .flat(Infinity);
30715
- var flightNumber = (_k = (_j = (_h = event === null || event === void 0 ? void 0 : event._flightProfile) === null || _h === void 0 ? void 0 : _h.flights) === null || _j === void 0 ? void 0 : _j.find(function (flight) { return flight.drawId === drawDefinition.drawId; })) === null || _k === void 0 ? void 0 : _k.flightNumber;
30716
- derivedInfo[drawDefinition.drawId] = {
30717
- qualifyingPositionAssignments: qualifyingPositionAssignments,
30718
- qualifyingSeedAssignments: qualifyingSeedAssignments,
30719
- mainPositionAssignments: mainPositionAssignments,
30720
- mainSeedAssignments: mainSeedAssignments,
30721
- orderedStructureIds: orderedStructureIds,
30722
- qualifyingDrawSize: qualifyingDrawSize,
30723
- flightNumber: flightNumber,
30724
- drawSize: drawSize,
30725
- };
30726
- return _a = {},
30727
- _a[drawDefinition.drawId] = {
30728
- drawType: drawDefinition.drawType,
30729
- drawEntries: drawEntries,
30730
- },
30731
- _a;
30732
- })), false));
30733
- return { derivedInfo: derivedInfo, drawDetails: drawDetails };
30373
+ function publicFindParticipant(_a) {
30374
+ var e_4, _b;
30375
+ var _c;
30376
+ var tournamentRecords = _a.tournamentRecords, policyDefinitions = _a.policyDefinitions, contextProfile = _a.contextProfile, participantId = _a.participantId, personId = _a.personId;
30377
+ if (!tournamentRecords)
30378
+ return { error: MISSING_TOURNAMENT_RECORDS };
30379
+ if (typeof participantId !== 'string' && typeof personId !== 'string')
30380
+ return { error: MISSING_VALUE, stack: 'publicFindParticipant' };
30381
+ var participant, tournamentId;
30382
+ try {
30383
+ for (var _d = __values(Object.values(tournamentRecords)), _e = _d.next(); !_e.done; _e = _d.next()) {
30384
+ var tournamentRecord = _e.value;
30385
+ tournamentId = tournamentRecord.tournamentId;
30386
+ var participants = (_c = getParticipants$1({
30387
+ policyDefinitions: policyDefinitions,
30388
+ tournamentRecord: tournamentRecord,
30389
+ }).participants) !== null && _c !== void 0 ? _c : [];
30390
+ participant = findParticipant({
30391
+ tournamentParticipants: participants,
30392
+ internalUse: true,
30393
+ policyDefinitions: policyDefinitions,
30394
+ contextProfile: contextProfile,
30395
+ participantId: participantId,
30396
+ personId: personId,
30397
+ });
30398
+ if (participant)
30399
+ break;
30400
+ }
30401
+ }
30402
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
30403
+ finally {
30404
+ try {
30405
+ if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
30406
+ }
30407
+ finally { if (e_4) throw e_4.error; }
30408
+ }
30409
+ return __assign({ participant: participant, tournamentId: tournamentId }, SUCCESS);
30734
30410
  }
30735
30411
 
30736
- function processMatchUp(_a) {
30737
- var _b;
30738
- var relevantParticipantIdsMap = _a.relevantParticipantIdsMap, participantFilters = _a.participantFilters, participantIdMap = _a.participantIdMap, derivedDrawInfo = _a.derivedDrawInfo, eventDrawsCount = _a.eventDrawsCount, drawDetails = _a.drawDetails, eventType = _a.eventType, matchUp = _a.matchUp;
30739
- var collectionId = matchUp.collectionId, collectionPosition = matchUp.collectionPosition, drawId = matchUp.drawId, drawName = matchUp.drawName, eventId = matchUp.eventId, eventName = matchUp.eventName, finishingRound = matchUp.finishingRound, finishingPositionRange = matchUp.finishingPositionRange, processCodes = matchUp.processCodes, loserTo = matchUp.loserTo, matchUpId = matchUp.matchUpId, matchUpType = matchUp.matchUpType, matchUpFormat = matchUp.matchUpFormat, matchUpStatus = matchUp.matchUpStatus, matchUpStatusCodes = matchUp.matchUpStatusCodes, matchUpTieId = matchUp.matchUpTieId, roundName = matchUp.roundName, roundNumber = matchUp.roundNumber, roundPosition = matchUp.roundPosition, score = matchUp.score, sides = matchUp.sides, stage = matchUp.stage, stageSequence = matchUp.stageSequence, schedule = matchUp.schedule, structureName = matchUp.structureName, structureId = matchUp.structureId, tieFormat = matchUp.tieFormat, tieMatchUps = matchUp.tieMatchUps, tournamentId = matchUp.tournamentId, winnerTo = matchUp.winnerTo, winningSide = matchUp.winningSide;
30740
- var targetParticipantIds = participantFilters === null || participantFilters === void 0 ? void 0 : participantFilters.participantIds;
30741
- var getRelevantParticipantIds = function (participantId) {
30742
- var relevantParticipantIds = (participantId && relevantParticipantIdsMap[participantId]) || [];
30743
- relevantParticipantIds.push(participantId);
30744
- return relevantParticipantIds.some(function (obj) {
30745
- return !targetParticipantIds ||
30746
- targetParticipantIds.includes(obj.relevantParticipantId);
30747
- })
30748
- ? relevantParticipantIds
30749
- : [];
30750
- };
30751
- var _c = finishingPositionRange || {}, winner = _c.winner, loser = _c.loser;
30752
- // doubles participants are not defined in the entries for a draw/event
30753
- // and can only be determined by interrogating inContext tieMatchUps
30754
- // because here the pairParticipantIds are derived from collectionAssignments
30755
- var doublesTieParticipants = ((tieMatchUps === null || tieMatchUps === void 0 ? void 0 : tieMatchUps.length) &&
30756
- tieMatchUps
30757
- .filter(function (_a) {
30758
- var matchUpType = _a.matchUpType;
30759
- return matchUpType === DOUBLES_MATCHUP;
30760
- })
30761
- .map(function (_a) {
30762
- var sides = _a.sides;
30763
- return sides.map(function (_a) {
30764
- var sideNumber = _a.sideNumber, participantId = _a.participantId, participant = _a.participant;
30765
- return sideNumber &&
30766
- participantId && {
30767
- sideNumber: sideNumber,
30768
- participantId: participantId,
30769
- participant: participant,
30770
- };
30771
- });
30772
- })
30773
- .flat()
30774
- .filter(Boolean)) ||
30775
- [];
30776
- if (eventType === TEAM_EVENT && matchUpType === DOUBLES_MATCHUP) {
30777
- var participants = (((_b = matchUp.sides) === null || _b === void 0 ? void 0 : _b.filter(Boolean)) || [])
30778
- .map(function (_a) {
30779
- var sideNumber = _a.sideNumber, participantId = _a.participantId, participant = _a.participant;
30780
- return sideNumber &&
30781
- participantId && {
30782
- sideNumber: sideNumber,
30783
- participantId: participantId,
30784
- participant: participant,
30785
- };
30786
- })
30787
- .filter(Boolean);
30788
- doublesTieParticipants.push.apply(doublesTieParticipants, __spreadArray([], __read(participants), false));
30412
+ var penaltyTemplate = function (_a) {
30413
+ var _b = _a === void 0 ? {} : _a, _c = _b.penaltyId, penaltyId = _c === void 0 ? UUID() : _c;
30414
+ return ({
30415
+ refereeParticipantId: undefined,
30416
+ penaltyCode: undefined,
30417
+ penaltyType: undefined,
30418
+ extensions: undefined,
30419
+ matchUpId: undefined,
30420
+ createdAt: undefined,
30421
+ issuedAt: undefined,
30422
+ notes: undefined,
30423
+ penaltyId: penaltyId,
30424
+ });
30425
+ };
30426
+
30427
+ function addPenalty$1(_a) {
30428
+ var refereeParticipantId = _a.refereeParticipantId, tournamentRecord = _a.tournamentRecord, participantIds = _a.participantIds, penaltyCode = _a.penaltyCode, penaltyType = _a.penaltyType, extensions = _a.extensions, penaltyId = _a.penaltyId, matchUpId = _a.matchUpId, issuedAt = _a.issuedAt, notes = _a.notes;
30429
+ if (!tournamentRecord)
30430
+ return { error: MISSING_TOURNAMENT_RECORD };
30431
+ if (!participantIds)
30432
+ return { error: MISSING_PARTICIPANT_ID };
30433
+ if (!penaltyType)
30434
+ return { error: MISSING_PENALTY_TYPE };
30435
+ // TODO: add penalty timeItem to matchUp.timeItems[]
30436
+ var participants = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
30437
+ var relevantParticipants = participants.filter(function (participant) {
30438
+ return participantIds.includes(participant.participantId);
30439
+ });
30440
+ if (!relevantParticipants.length)
30441
+ return { error: PARTICIPANT_NOT_FOUND };
30442
+ var createdAt = new Date().toISOString();
30443
+ var penaltyItem = Object.assign(penaltyTemplate({ penaltyId: penaltyId }), {
30444
+ refereeParticipantId: refereeParticipantId,
30445
+ penaltyCode: penaltyCode,
30446
+ penaltyType: penaltyType,
30447
+ matchUpId: matchUpId,
30448
+ notes: notes,
30449
+ issuedAt: issuedAt,
30450
+ createdAt: createdAt,
30451
+ });
30452
+ if (Array.isArray(extensions)) {
30453
+ extensions.forEach(function (extension) {
30454
+ return addExtension$1({ element: penaltyItem, extension: extension });
30455
+ });
30789
30456
  }
30790
- sides === null || sides === void 0 ? void 0 : sides.forEach(function (params) {
30791
- var participantId = params.participantId, sideNumber = params.sideNumber;
30792
- if (!participantId)
30793
- return;
30794
- var _a = drawDetails[drawId], drawType = _a.drawType, drawEntries = _a.drawEntries;
30795
- var participantScore = sideNumber === 1 ? score === null || score === void 0 ? void 0 : score.scoreStringSide1 : score === null || score === void 0 ? void 0 : score.scoreStringSide2;
30796
- var participantWon = winningSide && sideNumber === winningSide;
30797
- var opponent = matchUp.sides.find(function (side) { return side.sideNumber === 3 - sideNumber; });
30798
- var opponentParticipantId = opponent === null || opponent === void 0 ? void 0 : opponent.participantId;
30799
- var relevantOpponents = (opponentParticipantId &&
30800
- relevantParticipantIdsMap[opponentParticipantId]) ||
30801
- [];
30802
- var finishingPositionRange = participantWon ? winner : loser;
30803
- var drawEntry = drawEntries.find(function (entry) { return entry.participantId === participantId; });
30804
- // for all matchUps include all individual participants that are part of pairs
30805
- // this does NOT include PAIR participants in teams, because they are constructed from collectionAssignments
30806
- // if { eventType: TEAM } then only add relevant PAIR participantIds using doublesTieParticipants
30807
- // this will avoid adding a pair to all team events in which individuals appear
30808
- var relevantParticipantIds = getRelevantParticipantIds(participantId);
30809
- // for TEAM matchUps add all PAIR participants
30810
- var addedPairParticipantIds = [];
30811
- doublesTieParticipants === null || doublesTieParticipants === void 0 ? void 0 : doublesTieParticipants.filter(function (participant) { return participant.sideNumber === sideNumber; }).forEach(function (p) {
30812
- var participantId = p.participantId;
30813
- if (participantId && !addedPairParticipantIds.includes(participantId)) {
30814
- relevantParticipantIds.push({
30815
- relevantParticipantId: participantId,
30816
- participantType: PAIR,
30817
- });
30818
- addedPairParticipantIds.push(participantId);
30457
+ relevantParticipants.forEach(function (participant) {
30458
+ if (!participant.penalties)
30459
+ participant.penalties = [];
30460
+ participant.penalties.push(penaltyItem);
30461
+ });
30462
+ addNotice({
30463
+ topic: MODIFY_PARTICIPANTS,
30464
+ payload: {
30465
+ tournamentId: tournamentRecord.tournamentId,
30466
+ participants: relevantParticipants,
30467
+ },
30468
+ });
30469
+ return __assign(__assign({}, SUCCESS), { penaltyId: penaltyItem.penaltyId });
30470
+ }
30471
+ function removePenalty$1(_a) {
30472
+ var tournamentRecord = _a.tournamentRecord, penaltyId = _a.penaltyId;
30473
+ if (!tournamentRecord)
30474
+ return { error: MISSING_TOURNAMENT_RECORD };
30475
+ if (!penaltyId)
30476
+ return { error: MISSING_PENALTY_ID };
30477
+ var participants = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
30478
+ var modifiedParticipants = [];
30479
+ var penaltyRemoved = false;
30480
+ var removedPenalty;
30481
+ participants.forEach(function (participant) {
30482
+ var participantModified = false;
30483
+ participant.penalties = (participant.penalties || []).filter(function (penalty) {
30484
+ if (penalty.penaltyId === penaltyId) {
30485
+ participantModified = true;
30486
+ if (!penaltyRemoved) {
30487
+ removedPenalty = penalty;
30488
+ penaltyRemoved = true;
30489
+ }
30819
30490
  }
30491
+ if (participantModified)
30492
+ modifiedParticipants.push(participant);
30493
+ return penalty.penaltyId !== penaltyId;
30820
30494
  });
30821
- var filteredRelevantParticipantIds = relevantParticipantIds.filter(function (opponent) {
30822
- return (eventType !== TEAM_EVENT ||
30823
- (eventType === TEAM_EVENT &&
30824
- [DOUBLES_MATCHUP, TEAM_MATCHUP].includes(matchUpType) &&
30825
- [PAIR, TEAM_PARTICIPANT].includes(opponent.participantType)) ||
30826
- (eventType === TEAM_EVENT &&
30827
- [SINGLES_MATCHUP, DOUBLES_MATCHUP].includes(matchUpType) &&
30828
- [INDIVIDUAL].includes(opponent.participantType)));
30495
+ });
30496
+ if (removedPenalty) {
30497
+ addNotice({
30498
+ topic: MODIFY_PARTICIPANTS,
30499
+ payload: {
30500
+ tournamentId: tournamentRecord.tournamentId,
30501
+ participants: modifiedParticipants,
30502
+ },
30829
30503
  });
30830
- filteredRelevantParticipantIds === null || filteredRelevantParticipantIds === void 0 ? void 0 : filteredRelevantParticipantIds.forEach(function (_a) {
30831
- var _b, _c;
30832
- var relevantParticipantId = _a.relevantParticipantId, participantType = _a.participantType;
30833
- var _d = drawEntry || {}, entryStage = _d.entryStage, entryStatus = _d.entryStatus, entryPosition = _d.entryPosition;
30834
- if (!participantIdMap[relevantParticipantId])
30835
- return;
30836
- if (!participantIdMap[relevantParticipantId].draws[drawId]) {
30837
- var positionAssignments = getDerivedPositionAssignments({
30838
- participantId: relevantParticipantId,
30839
- derivedDrawInfo: derivedDrawInfo,
30840
- drawId: drawId,
30841
- });
30842
- var seedAssignments = getDerivedSeedAssignments({
30843
- participantId: relevantParticipantId,
30844
- derivedDrawInfo: derivedDrawInfo,
30845
- drawId: drawId,
30846
- });
30847
- participantIdMap[relevantParticipantId].draws[drawId] =
30848
- definedAttributes({
30849
- qualifyingDrawSize: (_b = derivedDrawInfo[drawId]) === null || _b === void 0 ? void 0 : _b.qualifyingDrawSize,
30850
- drawSize: (_c = derivedDrawInfo[drawId]) === null || _c === void 0 ? void 0 : _c.drawSize,
30851
- partnerParticipantIds: [],
30852
- positionAssignments: positionAssignments,
30853
- seedAssignments: seedAssignments,
30854
- entryPosition: entryPosition,
30855
- entryStatus: entryStatus,
30856
- entryStage: entryStage,
30857
- drawName: drawName,
30858
- drawType: drawType,
30859
- eventId: eventId,
30860
- drawId: drawId,
30861
- });
30862
- }
30863
- if (!participantIdMap[relevantParticipantId].events[eventId]) {
30864
- participantIdMap[relevantParticipantId].events[eventId] = {
30865
- partnerParticipantIds: [],
30866
- drawIds: [],
30867
- eventName: eventName,
30868
- eventId: eventId,
30869
- };
30870
- }
30871
- var eventDrawIds = participantIdMap[relevantParticipantId].events[eventId].drawIds;
30872
- if (eventDrawIds && !(eventDrawIds === null || eventDrawIds === void 0 ? void 0 : eventDrawIds.includes(drawId))) {
30873
- participantIdMap[relevantParticipantId].events[eventId].drawIds.push(drawId);
30504
+ }
30505
+ return removedPenalty
30506
+ ? __assign(__assign({}, SUCCESS), { penalty: removedPenalty }) : { error: PENALTY_NOT_FOUND };
30507
+ }
30508
+ function getTournamentPenalties(_a) {
30509
+ var tournamentRecord = _a.tournamentRecord;
30510
+ if (!tournamentRecord)
30511
+ return { error: MISSING_TOURNAMENT_RECORD };
30512
+ var participants = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
30513
+ var allPenalties = participants.reduce(function (penalties, participant) {
30514
+ var participantId = participant.participantId;
30515
+ (participant.penalties || []).forEach(function (penalty) {
30516
+ var penaltyId = (penalty || {}).penaltyId;
30517
+ if (penalties[penaltyId]) {
30518
+ penalties[penaltyId].participants.push(participantId);
30874
30519
  }
30875
- var partnerParticipantId;
30876
- if (participantType === INDIVIDUAL && matchUpType === DOUBLES_MATCHUP) {
30877
- var relevantParticipantInfo = filteredRelevantParticipantIds.find(function (participantInfo) {
30878
- return (participantInfo.relevantParticipantId !==
30879
- relevantParticipantId &&
30880
- participantInfo.participantType === INDIVIDUAL);
30881
- });
30882
- partnerParticipantId = relevantParticipantInfo === null || relevantParticipantInfo === void 0 ? void 0 : relevantParticipantInfo.relevantParticipantId;
30520
+ else {
30521
+ penalties[penaltyId] = __assign(__assign({}, penalty), { participantIds: [participantId] });
30883
30522
  }
30884
- var filteredRelevantOpponents = (relevantOpponents === null || relevantOpponents === void 0 ? void 0 : relevantOpponents.filter(function (opponent) {
30885
- return (matchUpType === TEAM_MATCHUP &&
30886
- participantType === TEAM_PARTICIPANT &&
30887
- opponent.participantType === TEAM_PARTICIPANT) ||
30888
- (matchUpType === SINGLES_MATCHUP &&
30889
- opponent.participantType === INDIVIDUAL) ||
30890
- (matchUpType === DOUBLES_MATCHUP &&
30891
- (participantType === INDIVIDUAL
30892
- ? [INDIVIDUAL, PAIR].includes(opponent.participantType)
30893
- : // for PAIR participants only show PAIR opponenents
30894
- opponent.participantType === PAIR));
30895
- })) || [];
30896
- filteredRelevantOpponents.forEach(function (_a) {
30897
- var opponentParticipantId = _a.relevantParticipantId, opponentParticipantType = _a.participantType;
30898
- if (!participantIdMap[relevantParticipantId].opponents) {
30899
- participantIdMap[relevantParticipantId].opponents = {};
30900
- }
30901
- participantIdMap[relevantParticipantId].opponents[opponentParticipantId] = {
30902
- eventId: eventId,
30903
- drawId: drawId,
30904
- matchUpId: matchUpId,
30905
- participantType: opponentParticipantType,
30906
- participantId: opponentParticipantId,
30907
- };
30908
- });
30909
- var opponentParticipantInfo = filteredRelevantOpponents.map(function (_a) {
30910
- var relevantParticipantId = _a.relevantParticipantId, participantType = _a.participantType;
30911
- return ({
30912
- participantId: relevantParticipantId,
30913
- participantType: participantType,
30523
+ });
30524
+ return penalties;
30525
+ }, {});
30526
+ return { penalties: Object.values(allPenalties) };
30527
+ }
30528
+ function modifyPenalty$1(_a) {
30529
+ var tournamentRecord = _a.tournamentRecord, modifications = _a.modifications, penaltyId = _a.penaltyId;
30530
+ if (!tournamentRecord)
30531
+ return { error: MISSING_TOURNAMENT_RECORD };
30532
+ if (!modifications)
30533
+ return { error: INVALID_VALUES, modifications: modifications };
30534
+ if (!penaltyId)
30535
+ return { error: MISSING_PENALTY_ID };
30536
+ var participants = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
30537
+ var validAttributes = Object.keys(penaltyTemplate()).filter(function (attribute) { return attribute !== 'penaltyId'; });
30538
+ var validModificationAttributes = Object.keys(modifications).filter(function (attribute) { return validAttributes.includes(attribute); });
30539
+ if (!validModificationAttributes.length)
30540
+ return { error: NO_VALID_ATTRIBUTES };
30541
+ var updatedPenalty;
30542
+ var modifiedParticipants = [];
30543
+ participants.forEach(function (participant) {
30544
+ var participantModified = false;
30545
+ participant.penalties = (participant.penalties || []).map(function (penalty) {
30546
+ if (penalty.penaltyId === penaltyId) {
30547
+ participantModified = true;
30548
+ validModificationAttributes.forEach(function (attribute) {
30549
+ var _a;
30550
+ return Object.assign(penalty, (_a = {}, _a[attribute] = modifications[attribute], _a));
30914
30551
  });
30915
- });
30916
- var includeMatchUp = (matchUpType !== TEAM_MATCHUP &&
30917
- [INDIVIDUAL, PAIR].includes(participantType)) ||
30918
- (matchUpType === TEAM_MATCHUP &&
30919
- participantType === TEAM_PARTICIPANT);
30920
- if (includeMatchUp)
30921
- participantIdMap[relevantParticipantId].matchUps[matchUpId] =
30922
- definedAttributes({
30923
- collectionId: collectionId,
30924
- collectionPosition: collectionPosition,
30925
- drawId: drawId,
30926
- eventId: eventId,
30927
- eventType: eventType,
30928
- eventDrawsCount: eventDrawsCount,
30929
- finishingRound: finishingRound,
30930
- finishingPositionRange: finishingPositionRange,
30931
- loserTo: loserTo,
30932
- matchUpId: matchUpId,
30933
- matchUpType: matchUpType,
30934
- matchUpFormat: matchUpFormat,
30935
- matchUpStatus: matchUpStatus,
30936
- matchUpStatusCodes: matchUpStatusCodes,
30937
- matchUpTieId: matchUpTieId,
30938
- opponentParticipantInfo: opponentParticipantInfo,
30939
- participantWon: participantWon,
30940
- partnerParticipantId: partnerParticipantId,
30941
- perspectiveScoreString: participantScore,
30942
- processCodes: processCodes,
30943
- roundName: roundName,
30944
- roundNumber: roundNumber,
30945
- roundPosition: roundPosition,
30946
- schedule: schedule,
30947
- score: score,
30948
- sides: sides,
30949
- stage: stage,
30950
- stageSequence: stageSequence,
30951
- structureName: structureName,
30952
- structureId: structureId,
30953
- tieFormat: tieFormat,
30954
- tournamentId: tournamentId,
30955
- winnerTo: winnerTo,
30956
- winningSide: winningSide,
30957
- });
30958
- if (partnerParticipantId) {
30959
- participantIdMap[relevantParticipantId].events[eventId].partnerParticipantIds.push(partnerParticipantId);
30960
- participantIdMap[relevantParticipantId].draws[drawId].partnerParticipantIds.push(partnerParticipantId);
30961
- // legacy.... deprecate when ETL updated
30962
- participantIdMap[relevantParticipantId].events[eventId].partnerParticipantId = partnerParticipantId;
30963
- participantIdMap[relevantParticipantId].draws[drawId].partnerParticipantId = partnerParticipantId;
30964
- }
30965
- if (winningSide) {
30966
- if (participantWon) {
30967
- participantIdMap[relevantParticipantId].wins++;
30968
- }
30969
- else {
30970
- participantIdMap[relevantParticipantId].losses++;
30971
- }
30552
+ if (!updatedPenalty)
30553
+ updatedPenalty = penalty;
30972
30554
  }
30555
+ return penalty;
30973
30556
  });
30557
+ if (participantModified)
30558
+ modifiedParticipants.push(participant);
30974
30559
  });
30975
- if (Array.isArray(matchUp.potentialParticipants)) {
30976
- var potentialParticipantIds = getParticipantIds(matchUp.potentialParticipants.flat());
30977
- potentialParticipantIds === null || potentialParticipantIds === void 0 ? void 0 : potentialParticipantIds.forEach(function (participantId) {
30978
- var relevantParticipantIds = getRelevantParticipantIds(participantId);
30979
- relevantParticipantIds === null || relevantParticipantIds === void 0 ? void 0 : relevantParticipantIds.forEach(function (_a) {
30980
- var relevantParticipantId = _a.relevantParticipantId;
30981
- participantIdMap[relevantParticipantId].potentialMatchUps[matchUpId] =
30982
- definedAttributes({
30983
- drawId: drawId,
30984
- eventId: eventId,
30985
- eventType: eventType,
30986
- matchUpId: matchUpId,
30987
- matchUpType: matchUpType,
30988
- matchUpFormat: matchUpFormat,
30989
- roundName: roundName,
30990
- roundNumber: roundNumber,
30991
- roundPosition: roundPosition,
30992
- schedule: schedule,
30993
- tieFormat: tieFormat,
30994
- structureName: structureName,
30995
- tournamentId: tournamentId,
30996
- potential: true,
30997
- });
30998
- });
30560
+ if (updatedPenalty) {
30561
+ addNotice({
30562
+ topic: MODIFY_PARTICIPANTS,
30563
+ payload: {
30564
+ tournamentId: tournamentRecord.tournamentId,
30565
+ participants: modifiedParticipants,
30566
+ },
30999
30567
  });
31000
30568
  }
30569
+ return updatedPenalty
30570
+ ? __assign(__assign({}, SUCCESS), { penalty: updatedPenalty }) : { error: PENALTY_NOT_FOUND };
31001
30571
  }
31002
30572
 
31003
- function addParticipantContext(params) {
31004
- var _a, _b;
31005
- var participantIdsWithConflicts = [];
31006
- var eventsPublishStatuses = {};
31007
- var derivedDrawInfo = {};
31008
- var participantIdMap = {};
31009
- var initializeParticipantId = function (participantId) {
31010
- if (!participantIdMap[participantId])
31011
- participantIdMap[participantId] = {
31012
- groupParticipantIds: [],
31013
- teamParticipantIds: [],
31014
- pairParticipantIds: [],
31015
- potentialMatchUps: {},
31016
- scheduleItems: [],
31017
- opponents: {},
31018
- matchUps: {},
31019
- events: {},
31020
- groups: [],
31021
- teams: [],
31022
- draws: {},
31023
- losses: 0,
31024
- wins: 0,
31025
- };
31026
- };
31027
- var tournamentRecord = params.tournamentRecord, participantFilters = params.participantFilters, allTournamentParticipants = params.allTournamentParticipants;
31028
- var relevantParticipantIdsMap = getRelevantParticipantIdsMap({
31029
- processParticipantId: initializeParticipantId,
31030
- tournamentRecord: tournamentRecord,
31031
- }).relevantParticipantIdsMap;
31032
- // optimize when filtering participants by participantIds
31033
- // by only returning relevantParticipantIds related to specified participantIds
31034
- var targetParticipantIds = participantFilters === null || participantFilters === void 0 ? void 0 : participantFilters.participantIds;
31035
- var getRelevantParticipantIds = function (participantId) {
31036
- var relevantParticipantIds = (participantId && relevantParticipantIdsMap[participantId]) || [];
31037
- relevantParticipantIds.push(participantId);
31038
- return relevantParticipantIds.some(function (obj) {
31039
- return !targetParticipantIds ||
31040
- targetParticipantIds.includes(obj.relevantParticipantId);
31041
- })
31042
- ? relevantParticipantIds
31043
- : [];
31044
- };
31045
- params.withGroupings &&
31046
- allTournamentParticipants.forEach(function (participant) {
31047
- var _a, _b, _c;
31048
- if (participant.participantType === GROUP) {
31049
- var groupParticipantId_1 = participant.participantId;
31050
- (_a = participant === null || participant === void 0 ? void 0 : participant.individualParticipantIds) === null || _a === void 0 ? void 0 : _a.forEach(function (participantId) {
31051
- if (!participantIdMap[participantId].groupParticipantIds.includes(groupParticipantId_1)) {
31052
- participantIdMap[participantId].groupParticipantIds.push(groupParticipantId_1);
31053
- participantIdMap[participantId].groups.push({
31054
- participantRoleResponsibilities: participant.participantRoleResponsibilities,
31055
- participantOtherName: participant.participantOtherName,
31056
- participantName: participant.participantName,
31057
- participantId: participant.participantId,
31058
- });
31059
- }
31060
- });
31061
- }
31062
- if (participant.participantType === TEAM$2) {
31063
- var teamParticipantId_1 = participant.participantId;
31064
- (_b = participant === null || participant === void 0 ? void 0 : participant.individualParticipantIds) === null || _b === void 0 ? void 0 : _b.forEach(function (participantId) {
31065
- var _a, _b, _c, _d;
31066
- if (!((_b = (_a = participantIdMap[participantId]) === null || _a === void 0 ? void 0 : _a.teamParticipantIds) === null || _b === void 0 ? void 0 : _b.includes(teamParticipantId_1))) {
31067
- (_c = participantIdMap[participantId]) === null || _c === void 0 ? void 0 : _c.teamParticipantIds.push(teamParticipantId_1);
31068
- (_d = participantIdMap[participantId]) === null || _d === void 0 ? void 0 : _d.teams.push({
31069
- participantRoleResponsibilities: participant.participantRoleResponsibilities,
31070
- participantOtherName: participant.participantOtherName,
31071
- participantName: participant.participantName,
31072
- participantId: participant.participantId,
31073
- teamId: participant.teamId,
31074
- });
31075
- }
31076
- });
31077
- }
31078
- if (participant.participantType === PAIR) {
31079
- var pairParticipantId_1 = participant.participantId;
31080
- (_c = participant === null || participant === void 0 ? void 0 : participant.individualParticipantIds) === null || _c === void 0 ? void 0 : _c.forEach(function (participantId) {
31081
- if (participantIdMap[participantId] &&
31082
- !participantIdMap[participantId].pairParticipantIds.includes(pairParticipantId_1)) {
31083
- participantIdMap[participantId].pairParticipantIds.push(pairParticipantId_1);
31084
- }
31085
- });
31086
- }
31087
- });
31088
- if (params.withMatchUps) {
31089
- getMatchUpDependencies({ tournamentRecord: tournamentRecord }); // ensure that goesTos exist
31090
- }
31091
- if (params.withScheduleItems ||
31092
- params.scheduleAnalysis ||
31093
- params.withStatistics ||
31094
- params.withOpponents ||
31095
- params.withMatchUps ||
31096
- params.withSeeding ||
31097
- params.withEvents ||
31098
- params.withDraws) {
31099
- // loop through all filtered events and capture events played
31100
- (_a = params.tournamentEvents) === null || _a === void 0 ? void 0 : _a.forEach(function (rawEvent) {
31101
- var _a, _b, _c, _d, _e, _f, _g;
31102
- var event = makeDeepCopy(rawEvent, true, true);
31103
- var flightProfile = getFlightProfile({ event: event }).flightProfile;
31104
- var eventDrawsCount = ((_a = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _a === void 0 ? void 0 : _a.length) || ((_b = event.drawDefinitions) === null || _b === void 0 ? void 0 : _b.length) || 0;
31105
- (event.drawDefinitions || []).forEach(function (drawDefinition, i) {
31106
- if ((event === null || event === void 0 ? void 0 : event.eventType) === TEAM$2) {
31107
- // add back lineUps extension for team resolution when { matchUpType: TEAM } is missing side.lineUps
31108
- var extension = findExtension$2({
31109
- element: rawEvent.drawDefinitions[i],
31110
- name: LINEUPS,
31111
- }).extension;
31112
- if (extension)
31113
- drawDefinition.extensions = [extension];
31114
- }
31115
- });
31116
- var eventId = event.eventId, eventName = event.eventName, eventType = event.eventType, category = event.category;
31117
- var eventInfo = { eventId: eventId, eventName: eventName, eventType: eventType, category: category };
31118
- var extensionKeys = event && Object.keys(event).filter(function (key) { return key.startsWith('_'); });
31119
- extensionKeys === null || extensionKeys === void 0 ? void 0 : extensionKeys.forEach(function (extensionKey) { return (eventInfo[extensionKey] = event[extensionKey]); });
31120
- var eventEntries = event.entries || [];
31121
- var itemType = "".concat(PUBLISH, ".").concat(STATUS$1);
31122
- var timeItem = getEventTimeItem({
31123
- itemType: itemType,
31124
- event: event,
31125
- }).timeItem;
31126
- if ((_c = timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemValue) === null || _c === void 0 ? void 0 : _c.PUBLIC) {
31127
- var _h = timeItem.itemValue.PUBLIC || {}, _j = _h.drawIds, publishedDrawIds = _j === void 0 ? [] : _j, seeding = _h.seeding;
31128
- var publishedSeeding = {
31129
- published: undefined,
31130
- seedingScaleNames: [],
31131
- drawIds: [], // seeding can be specific to drawIds
31132
- };
31133
- if (seeding)
31134
- Object.assign(publishedSeeding, timeItem.itemValue.PUBLIC.seeding);
31135
- eventsPublishStatuses[eventId] = {
31136
- publishedDrawIds: publishedDrawIds,
31137
- publishedSeeding: publishedSeeding,
31138
- };
31139
- }
31140
- // don't allow system extensions to be copied to participants
31141
- var disallowedConstants = __spreadArray([], __read(Object.values(extensionConstants)), false);
31142
- var disallowedKeys = disallowedConstants.map(function (constant) { return "_".concat(constant); });
31143
- var filteredEventInfo = eventInfo &&
31144
- Object.keys(eventInfo)
31145
- .filter(function (key) { return !disallowedKeys.includes(key); })
31146
- .reduce(function (obj, key) {
31147
- obj[key] = eventInfo[key];
31148
- return obj;
31149
- }, {});
31150
- eventEntries === null || eventEntries === void 0 ? void 0 : eventEntries.filter(function (entry) { return entry === null || entry === void 0 ? void 0 : entry.participantId; }).forEach(function (entry) {
31151
- var participantId = entry.participantId, entryStage = entry.entryStage, entryStatus = entry.entryStatus, entryPosition = entry.entryPosition;
31152
- // include all individual participants that are part of teams & pairs
31153
- // relevantParticipantId is a reference to an individual
31154
- var relevantParticipantIds = getRelevantParticipantIds(participantId);
31155
- relevantParticipantIds === null || relevantParticipantIds === void 0 ? void 0 : relevantParticipantIds.forEach(function (_a) {
31156
- var relevantParticipantId = _a.relevantParticipantId;
31157
- if (!participantIdMap[relevantParticipantId])
31158
- initializeParticipantId(relevantParticipantId);
31159
- participantIdMap[relevantParticipantId].events[eventId] = __assign(__assign({}, filteredEventInfo), { partnerParticipantIds: [], entryPosition: entryPosition, entryStatus: entryStatus, entryStage: entryStage, drawIds: [], eventId: eventId });
31160
- });
31161
- });
31162
- var addDrawData = function (_a) {
31163
- var drawEntry = _a.drawEntry, drawId = _a.drawId;
31164
- var participantId = drawEntry.participantId, entryStage = drawEntry.entryStage, entryStatus = drawEntry.entryStatus, entryPosition = drawEntry.entryPosition;
31165
- var relevantParticipantIds = getRelevantParticipantIds(participantId);
31166
- relevantParticipantIds === null || relevantParticipantIds === void 0 ? void 0 : relevantParticipantIds.forEach(function (_a) {
31167
- var _b, _c;
31168
- var relevantParticipantId = _a.relevantParticipantId;
31169
- if (!participantIdMap[relevantParticipantId].events[eventId]) {
31170
- participantIdMap[relevantParticipantId].events[eventId] = __assign(__assign({}, filteredEventInfo), { partnerParticipantIds: [], entryPosition: entryPosition, entryStatus: entryStatus, entryStage: entryStage, drawIds: [], eventId: eventId });
31171
- }
31172
- if (!participantIdMap[relevantParticipantId].draws[drawId]) {
31173
- var positionAssignments = getDerivedPositionAssignments({
31174
- participantId: relevantParticipantId,
31175
- derivedDrawInfo: derivedDrawInfo,
31176
- drawId: drawId,
31177
- });
31178
- var seedAssignments = getDerivedSeedAssignments({
31179
- participantId: relevantParticipantId,
31180
- derivedDrawInfo: derivedDrawInfo,
31181
- drawId: drawId,
31182
- });
31183
- participantIdMap[relevantParticipantId].draws[drawId] =
31184
- definedAttributes({
31185
- qualifyingDrawSize: (_b = derivedDrawInfo[drawId]) === null || _b === void 0 ? void 0 : _b.qualifyingDrawSize,
31186
- drawSize: (_c = derivedDrawInfo[drawId]) === null || _c === void 0 ? void 0 : _c.drawSize,
31187
- partnerParticipantIds: [],
31188
- positionAssignments: positionAssignments,
31189
- eventDrawsCount: eventDrawsCount,
31190
- seedAssignments: seedAssignments,
31191
- entryPosition: entryPosition,
31192
- entryStatus: entryStatus,
31193
- entryStage: entryStage,
31194
- eventId: eventId,
31195
- drawId: drawId,
31196
- });
31197
- }
31198
- var eventDrawIds = participantIdMap[relevantParticipantId].events[eventId].drawIds;
31199
- if (eventDrawIds && !(eventDrawIds === null || eventDrawIds === void 0 ? void 0 : eventDrawIds.includes(drawId))) {
31200
- participantIdMap[relevantParticipantId].events[eventId].drawIds.push(drawId);
31201
- }
31202
- });
31203
- };
31204
- // iterate through flights to ensure that draw entries are captured if drawDefinitions have not yet been generated
31205
- var drawIdsWithDefinitions = ((_d = event.drawDefinitions) === null || _d === void 0 ? void 0 : _d.map(function (_a) {
31206
- var drawId = _a.drawId;
31207
- return drawId;
31208
- })) || [];
31209
- (_f = (_e = eventInfo._flightProfile) === null || _e === void 0 ? void 0 : _e.flights) === null || _f === void 0 ? void 0 : _f.forEach(function (flight) {
31210
- var drawId = flight.drawId, drawEntries = flight.drawEntries;
31211
- if (!drawIdsWithDefinitions.includes(drawId)) {
31212
- drawEntries === null || drawEntries === void 0 ? void 0 : drawEntries.forEach(function (drawEntry) {
31213
- return addDrawData({ drawEntry: drawEntry, drawId: drawId });
31214
- });
31215
- }
31216
- });
31217
- var _k = getDrawDetails({
31218
- eventEntries: eventEntries,
31219
- event: event,
31220
- }), drawDetails = _k.drawDetails, derivedInfo = _k.derivedInfo;
31221
- Object.assign(derivedDrawInfo, derivedInfo);
31222
- if (event.eventType === TEAM$2 || // for TEAM events some individual attributes can only be derived by processing
31223
- params.withScheduleItems ||
31224
- params.scheduleAnalysis ||
31225
- params.withStatistics ||
31226
- params.withOpponents ||
31227
- params.withMatchUps ||
31228
- params.withDraws) {
31229
- var matchUps = (_g = allEventMatchUps({
31230
- afterRecoveryTimes: params.scheduleAnalysis,
31231
- participants: allTournamentParticipants,
31232
- nextMatchUps: true,
31233
- tournamentRecord: tournamentRecord,
31234
- inContext: true,
31235
- event: event,
31236
- })) === null || _g === void 0 ? void 0 : _g.matchUps;
31237
- matchUps === null || matchUps === void 0 ? void 0 : matchUps.forEach(function (matchUp) {
31238
- return processMatchUp({
31239
- relevantParticipantIdsMap: relevantParticipantIdsMap,
31240
- participantFilters: participantFilters,
31241
- participantIdMap: participantIdMap,
31242
- derivedDrawInfo: derivedDrawInfo,
31243
- eventDrawsCount: eventDrawsCount,
31244
- drawDetails: drawDetails,
31245
- eventType: eventType,
31246
- matchUp: matchUp,
31247
- });
31248
- });
31249
- }
31250
- });
31251
- }
31252
- // tournamentParticipants is an array of FILTERED participants
31253
- (_b = params.tournamentParticipants) === null || _b === void 0 ? void 0 : _b.forEach(function (participant) {
31254
- var _a = annotateParticipant(__assign(__assign({}, params), { eventsPublishStatuses: eventsPublishStatuses, participantIdMap: participantIdMap, derivedDrawInfo: derivedDrawInfo, participant: participant })), scheduleConflicts = _a.scheduleConflicts, scheduleItems = _a.scheduleItems;
31255
- if (params.withSignInStatus) {
31256
- var timeItem = getTimeItem({
31257
- itemType: SIGN_IN_STATUS,
31258
- element: participant,
31259
- }).timeItem;
31260
- participant.signedIn = (timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemValue) === SIGNED_IN;
31261
- }
31262
- if (params.withScheduleItems) {
31263
- participant.scheduleItems = scheduleItems;
31264
- }
31265
- if (params.scheduleAnalysis) {
31266
- participant.scheduleConflicts = scheduleConflicts;
31267
- if ((scheduleConflicts === null || scheduleConflicts === void 0 ? void 0 : scheduleConflicts.length) &&
31268
- !participantIdsWithConflicts.includes(participant.participantId)) {
31269
- participantIdsWithConflicts.push(participant.participantId);
30573
+ function addPenalty(params) {
30574
+ var e_1, _a;
30575
+ var _b;
30576
+ var tournamentRecords = params.tournamentRecords, participantIds = params.participantIds;
30577
+ var penaltyId;
30578
+ try {
30579
+ for (var _c = __values(Object.values(tournamentRecords)), _d = _c.next(); !_d.done; _d = _c.next()) {
30580
+ var tournamentRecord = _d.value;
30581
+ var participants = (_b = getParticipants$1({
30582
+ tournamentRecord: tournamentRecord,
30583
+ }).participants) !== null && _b !== void 0 ? _b : [];
30584
+ var tournamentParticipantIds = participants === null || participants === void 0 ? void 0 : participants.map(extractAttributes('participantId')).filter(function (participantId) { return participantIds.includes(participantId); });
30585
+ if (tournamentParticipantIds.length) {
30586
+ var result = addPenalty$1(__assign(__assign({}, params), { penaltyId: params.penaltyId || penaltyId, tournamentRecord: tournamentRecord, participantIds: tournamentParticipantIds }));
30587
+ penaltyId = result.penaltyId;
31270
30588
  }
31271
30589
  }
31272
- if (params.withGroupings !== false) {
31273
- var participantAttributes = participantIdMap[participant.participantId];
31274
- participant.groupParticipantIds =
31275
- participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.groupParticipantIds;
31276
- participant.pairParticipantIds =
31277
- participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.pairParticipantIds;
31278
- participant.teamParticipantIds =
31279
- participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.teamParticipantIds;
31280
- participant.groups = participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.groups;
31281
- participant.teams = participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.teams;
31282
- }
31283
- if (params.withTeamMatchUps) ;
31284
- });
31285
- return { participantIdsWithConflicts: participantIdsWithConflicts, eventsPublishStatuses: eventsPublishStatuses };
31286
- }
31287
-
31288
- /**
31289
- * Returns deepCopies of tournament participants filtered by participantFilters which are arrays of desired participant attribute values
31290
- *
31291
- * @param {object} tournamentRecord - tournament object (passed automatically from tournamentEngine state)
31292
- * @param {object} participantFilters - attribute arrays with filter value strings
31293
- * @param {boolean} inContext - adds individualParticipants for all individualParticipantIds
31294
- * @param {boolean} withDraws - include all matchUps in which participant appears
31295
- * @param {boolean} withEvents - include all events in which participant appears
31296
- * @param {boolean} withMatchUps - include all matchUps in which participant appears
31297
- * @param {boolean} withStatistics - adds events: { [eventId]: eventName }, matchUps: { [matchUpId]: score }, statistics: [{ statCode: 'winRatio'}]
31298
- * @param {boolean} withScheduleItems - include schedule items; scheduled matchUps
31299
- * @param {boolean} scheduleAnalysis - analysis of conflicts
31300
- * @param {boolean} withGroupings - include teams and groups and pairs in which individual participants appear
31301
- * @param {boolean} withOpponents - include opponent participantIds
31302
- * @param {boolean} usePublishState - when hydrating participants consider publish state (currently applies to seeding)
31303
- *
31304
- */
31305
- function getTournamentParticipants(params) {
31306
- var _a = params.participantFilters, participantFilters = _a === void 0 ? {} : _a, convertExtensions = params.convertExtensions, policyDefinitions = params.policyDefinitions, withScheduleItems = params.withScheduleItems, scheduleAnalysis = params.scheduleAnalysis, withSignInStatus = params.withSignInStatus, withTeamMatchUps = params.withTeamMatchUps, // not implemented
31307
- tournamentRecord = params.tournamentRecord, usePublishState = params.usePublishState, withScaleValues = params.withScaleValues, withStatistics = params.withStatistics, withGroupings = params.withGroupings, withOpponents = params.withOpponents, withMatchUps = params.withMatchUps, withSeeding = params.withSeeding, withEvents = params.withEvents, withDraws = params.withDraws, inContext = params.inContext, withISO2 = params.withISO2, withIOC = params.withIOC;
31308
- if (!tournamentRecord)
31309
- return { error: MISSING_TOURNAMENT_RECORD };
31310
- if (!tournamentRecord.participants)
31311
- return { error: MISSING_PARTICIPANTS };
31312
- var allTournamentParticipants = tournamentRecord.participants.map(
31313
- // (participant) => makeDeepCopy(participant, convertExtensions, true)
31314
- function (participant) { return makeDeepCopy(participant, convertExtensions); } // removed until Mongo/Mongoose issues resolved
31315
- );
31316
- if (typeof participantFilters !== 'object')
31317
- return { error: INVALID_OBJECT, participantFilters: participantFilters };
31318
- if (inContext) {
31319
- allTournamentParticipants === null || allTournamentParticipants === void 0 ? void 0 : allTournamentParticipants.forEach(function (participant) {
31320
- var _a;
31321
- if ([PAIR, TEAM, GROUP].includes(participant.participantType)) {
31322
- participant.individualParticipants =
31323
- (_a = participant.individualParticipantIds) === null || _a === void 0 ? void 0 : _a.map(function (participantId) {
31324
- var targetParticipant = tournamentRecord.participants.find(function (p) { return p.participantId === participantId; });
31325
- var individualParticipant = makeDeepCopy(targetParticipant, convertExtensions, true);
31326
- // individualParticipants only need to be hydrated withScaleValues and nationalityCode variations
31327
- if (withScaleValues) {
31328
- var _a = getScaleValues({
31329
- participant: individualParticipant,
31330
- }), ratings = _a.ratings, rankings = _a.rankings;
31331
- individualParticipant.ratings = ratings;
31332
- individualParticipant.rankings = rankings;
31333
- }
31334
- if (withIOC || withISO2)
31335
- addNationalityCode({
31336
- participant: individualParticipant,
31337
- withISO2: withISO2,
31338
- withIOC: withIOC,
31339
- });
31340
- return individualParticipant;
31341
- });
31342
- }
31343
- });
31344
- }
31345
- var tournamentParticipants = participantFilters
31346
- ? filterParticipants({
31347
- participants: allTournamentParticipants,
31348
- participantFilters: participantFilters,
31349
- tournamentRecord: tournamentRecord,
31350
- })
31351
- : allTournamentParticipants;
31352
- var participantIdsWithConflicts, eventsPublishStatuses;
31353
- var addContext = withScheduleItems ||
31354
- withSignInStatus ||
31355
- scheduleAnalysis ||
31356
- withScaleValues ||
31357
- withStatistics ||
31358
- withGroupings ||
31359
- withOpponents ||
31360
- withMatchUps ||
31361
- withSeeding ||
31362
- withEvents ||
31363
- withDraws ||
31364
- withISO2 ||
31365
- withIOC;
31366
- if (addContext) {
31367
- var result = addParticipantContext({
31368
- tournamentEvents: tournamentRecord.events,
31369
- allTournamentParticipants: allTournamentParticipants,
31370
- tournamentParticipants: tournamentParticipants,
31371
- participantFilters: participantFilters,
31372
- withScheduleItems: withScheduleItems,
31373
- withSignInStatus: withSignInStatus,
31374
- tournamentRecord: tournamentRecord,
31375
- scheduleAnalysis: scheduleAnalysis,
31376
- withTeamMatchUps: withTeamMatchUps,
31377
- usePublishState: usePublishState,
31378
- withScaleValues: withScaleValues,
31379
- withStatistics: withStatistics,
31380
- withGroupings: withGroupings,
31381
- withOpponents: withOpponents,
31382
- withMatchUps: withMatchUps,
31383
- withSeeding: withSeeding,
31384
- withEvents: withEvents,
31385
- withDraws: withDraws,
31386
- withISO2: withISO2,
31387
- withIOC: withIOC,
31388
- });
31389
- participantIdsWithConflicts = result === null || result === void 0 ? void 0 : result.participantIdsWithConflicts;
31390
- eventsPublishStatuses = result === null || result === void 0 ? void 0 : result.eventsPublishStatuses;
31391
- }
31392
- var participantAttributes = policyDefinitions === null || policyDefinitions === void 0 ? void 0 : policyDefinitions[POLICY_TYPE_PARTICIPANT];
31393
- if (participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.participant) {
31394
- tournamentParticipants = tournamentParticipants.map(function (participant) {
31395
- return attributeFilter({
31396
- template: participantAttributes.participant,
31397
- source: participant,
31398
- });
31399
- });
31400
30590
  }
31401
- return {
31402
- participantIdsWithConflicts: participantIdsWithConflicts,
31403
- tournamentParticipants: tournamentParticipants,
31404
- eventsPublishStatuses: eventsPublishStatuses,
31405
- };
31406
- }
31407
-
31408
- // arrayMerge can be boolean or an array of target attributes which are arrays to merge
31409
- function deepMerge(existing, incoming, arrayMerge) {
31410
- if (!existing && incoming)
31411
- return incoming;
31412
- if (existing && !incoming)
31413
- return existing;
31414
- if (typeof existing !== 'object' || typeof incoming !== 'object')
31415
- return existing;
31416
- var keys = unique(Object.keys(existing).concat(Object.keys(incoming)));
31417
- return keys.reduce(function (merged, key) {
31418
- if (!incoming[key]) {
31419
- merged[key] = existing[key];
31420
- }
31421
- else if (!existing[key]) {
31422
- merged[key] = incoming[key];
31423
- }
31424
- else if (typeof existing[key] !== typeof incoming[key]) {
31425
- merged[key] = incoming[key];
31426
- }
31427
- else if (Array.isArray(existing[key])) {
31428
- if (arrayMerge === true ||
31429
- (Array.isArray(arrayMerge) && arrayMerge.includes(key))) {
31430
- var mergedArrays = unique(existing[key]
31431
- .map(function (e) { return JSON.stringify(e); })
31432
- .concat(incoming[key].map(function (i) { return JSON.stringify(i); }))).map(function (u) { return JSON.parse(u); });
31433
- merged[key] = mergedArrays;
31434
- }
31435
- else {
31436
- // default is to overwrite existing array with incoming
31437
- merged[key] = incoming[key];
31438
- }
31439
- }
31440
- else if (typeof existing[key] === 'object') {
31441
- merged[key] = deepMerge(existing[key], incoming[key], arrayMerge);
31442
- }
31443
- else {
31444
- merged[key] = incoming[key];
30591
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
30592
+ finally {
30593
+ try {
30594
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
31445
30595
  }
31446
- return merged;
31447
- }, {});
30596
+ finally { if (e_1) throw e_1.error; }
30597
+ }
30598
+ return penaltyId
30599
+ ? __assign(__assign({}, SUCCESS), { penaltyId: penaltyId }) : { error: PARTICIPANT_NOT_FOUND };
31448
30600
  }
31449
-
31450
- // TODO: getTournamentParticipants migration
31451
- function getParticipants(params) {
31452
- var e_1, _a;
31453
- var tournamentRecords = (params || {}).tournamentRecords;
30601
+ function modifyPenalty(params) {
30602
+ var e_2, _a;
30603
+ var tournamentRecords = params.tournamentRecords;
31454
30604
  if (typeof tournamentRecords !== 'object' ||
31455
- !Object.keys(tournamentRecords).length) {
30605
+ !Object.keys(tournamentRecords).length)
31456
30606
  return { error: MISSING_TOURNAMENT_RECORDS };
31457
- }
31458
- var participantMap = {};
31459
- var participants = [];
31460
- var derivedEventInfo = {};
31461
- var derivedDrawInfo = {};
31462
- var matchUps = [];
31463
- var mappedMatchUps = {};
31464
- var participantIdsWithConflicts = [];
31465
30607
  try {
31466
30608
  for (var _b = __values(Object.values(tournamentRecords)), _c = _b.next(); !_c.done; _c = _b.next()) {
31467
30609
  var tournamentRecord = _c.value;
31468
- var _d = getParticipants$1(__assign({ tournamentRecord: tournamentRecord }, params)), idsWithConflicts = _d.participantIdsWithConflicts, tournamentMappedMatchUps = _d.mappedMatchUps, tournamentParticipantMap = _d.participantMap, tournamentParticipants = _d.participants, tournamentMatchUps = _d.matchUps, eventInfo = _d.derivedEventInfo, drawInfo = _d.derivedDrawInfo;
31469
- Object.assign(mappedMatchUps, tournamentMappedMatchUps);
31470
- Object.assign(participantMap, tournamentParticipantMap);
31471
- Object.assign(derivedEventInfo, eventInfo);
31472
- Object.assign(derivedDrawInfo, drawInfo);
31473
- participants.push.apply(participants, __spreadArray([], __read((tournamentParticipants !== null && tournamentParticipants !== void 0 ? tournamentParticipants : [])), false));
31474
- matchUps.push.apply(matchUps, __spreadArray([], __read((tournamentMatchUps !== null && tournamentMatchUps !== void 0 ? tournamentMatchUps : [])), false));
31475
- idsWithConflicts === null || idsWithConflicts === void 0 ? void 0 : idsWithConflicts.forEach(function (participantId) {
31476
- if (!participantIdsWithConflicts.includes(participantId))
31477
- participantIdsWithConflicts.push(participantId);
31478
- });
30610
+ var result = modifyPenalty$1(__assign({ tournamentRecord: tournamentRecord }, params));
30611
+ if (result.error && result.error !== PENALTY_NOT_FOUND)
30612
+ return result;
31479
30613
  }
31480
30614
  }
31481
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
30615
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
31482
30616
  finally {
31483
30617
  try {
31484
30618
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
31485
30619
  }
31486
- finally { if (e_1) throw e_1.error; }
30620
+ finally { if (e_2) throw e_2.error; }
31487
30621
  }
31488
- return __assign(__assign({ participantIdsWithConflicts: participantIdsWithConflicts, derivedEventInfo: derivedEventInfo, derivedDrawInfo: derivedDrawInfo, participantMap: participantMap, mappedMatchUps: mappedMatchUps, participants: participants }, SUCCESS), { matchUps: matchUps });
30622
+ return __assign({}, SUCCESS);
31489
30623
  }
31490
- function getCompetitionParticipants(params) {
31491
- var e_2, _a, e_3, _b;
31492
- var tournamentRecords = (params || {}).tournamentRecords;
31493
- if (typeof tournamentRecords !== 'object' ||
31494
- !Object.keys(tournamentRecords).length)
31495
- return { error: MISSING_TOURNAMENT_RECORDS };
31496
- var competitionParticipants = [];
31497
- var participantIdsWithConflicts = [];
31498
- var competitionParticipantIds = [];
31499
- try {
31500
- for (var _c = __values(Object.values(tournamentRecords)), _d = _c.next(); !_d.done; _d = _c.next()) {
31501
- var tournamentRecord = _d.value;
31502
- var _e = getTournamentParticipants(__assign({ tournamentRecord: tournamentRecord }, params)), tournamentParticipants = _e.tournamentParticipants, idsWithConflicts = _e.participantIdsWithConflicts;
31503
- var _loop_1 = function (tournamentParticipant) {
31504
- var participantId = tournamentParticipant.participantId;
31505
- if (!competitionParticipantIds.includes(participantId)) {
31506
- competitionParticipantIds.push(participantId);
31507
- competitionParticipants.push(tournamentParticipant);
31508
- }
31509
- else {
31510
- // merge participant record context across tournaments
31511
- competitionParticipants = competitionParticipants.map(function (participant) {
31512
- return participant.participantId !== participantId
31513
- ? participant
31514
- : deepMerge(participant, tournamentParticipant, true);
31515
- });
31516
- }
31517
- };
31518
- try {
31519
- for (var tournamentParticipants_1 = (e_3 = void 0, __values(tournamentParticipants)), tournamentParticipants_1_1 = tournamentParticipants_1.next(); !tournamentParticipants_1_1.done; tournamentParticipants_1_1 = tournamentParticipants_1.next()) {
31520
- var tournamentParticipant = tournamentParticipants_1_1.value;
31521
- _loop_1(tournamentParticipant);
31522
- }
31523
- }
31524
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
31525
- finally {
31526
- try {
31527
- if (tournamentParticipants_1_1 && !tournamentParticipants_1_1.done && (_b = tournamentParticipants_1.return)) _b.call(tournamentParticipants_1);
31528
- }
31529
- finally { if (e_3) throw e_3.error; }
31530
- }
31531
- idsWithConflicts === null || idsWithConflicts === void 0 ? void 0 : idsWithConflicts.forEach(function (participantId) {
31532
- if (!participantIdsWithConflicts.includes(participantId))
31533
- participantIdsWithConflicts.push(participantId);
31534
- });
31535
- }
31536
- }
31537
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
31538
- finally {
31539
- try {
31540
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
31541
- }
31542
- finally { if (e_2) throw e_2.error; }
31543
- }
31544
- return __assign({ competitionParticipants: competitionParticipants, participantIdsWithConflicts: participantIdsWithConflicts }, SUCCESS);
31545
- }
31546
- function publicFindParticipant(_a) {
31547
- var e_4, _b;
31548
- var policyDefinitions = _a.policyDefinitions, tournamentRecords = _a.tournamentRecords, participantId = _a.participantId, inContext = _a.inContext, personId = _a.personId;
31549
- if (!tournamentRecords)
31550
- return { error: MISSING_TOURNAMENT_RECORDS };
31551
- if (typeof participantId !== 'string' && typeof personId !== 'string')
31552
- return { error: MISSING_VALUE, stack: 'publicFindParticipant' };
31553
- var participant, tournamentId;
31554
- try {
31555
- for (var _c = __values(Object.values(tournamentRecords)), _d = _c.next(); !_d.done; _d = _c.next()) {
31556
- var tournamentRecord = _d.value;
31557
- tournamentId = tournamentRecord.tournamentId;
31558
- var tournamentParticipants = getTournamentParticipants({
31559
- policyDefinitions: policyDefinitions,
31560
- tournamentRecord: tournamentRecord,
31561
- inContext: inContext,
31562
- }).tournamentParticipants;
31563
- participant = findParticipant({
31564
- tournamentParticipants: tournamentParticipants,
31565
- internalUse: true,
31566
- policyDefinitions: policyDefinitions,
31567
- participantId: participantId,
31568
- personId: personId,
31569
- });
31570
- if (participant)
31571
- break;
31572
- }
31573
- }
31574
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
31575
- finally {
31576
- try {
31577
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
31578
- }
31579
- finally { if (e_4) throw e_4.error; }
31580
- }
31581
- return __assign({ participant: participant, tournamentId: tournamentId }, SUCCESS);
31582
- }
31583
-
31584
- var penaltyTemplate = function (_a) {
31585
- var _b = _a === void 0 ? {} : _a, _c = _b.penaltyId, penaltyId = _c === void 0 ? UUID() : _c;
31586
- return ({
31587
- refereeParticipantId: undefined,
31588
- penaltyCode: undefined,
31589
- penaltyType: undefined,
31590
- extensions: undefined,
31591
- matchUpId: undefined,
31592
- createdAt: undefined,
31593
- issuedAt: undefined,
31594
- notes: undefined,
31595
- penaltyId: penaltyId,
31596
- });
31597
- };
31598
-
31599
- function addPenalty$1(_a) {
31600
- var refereeParticipantId = _a.refereeParticipantId, tournamentRecord = _a.tournamentRecord, participantIds = _a.participantIds, penaltyCode = _a.penaltyCode, penaltyType = _a.penaltyType, extensions = _a.extensions, penaltyId = _a.penaltyId, matchUpId = _a.matchUpId, issuedAt = _a.issuedAt, notes = _a.notes;
31601
- if (!tournamentRecord)
31602
- return { error: MISSING_TOURNAMENT_RECORD };
31603
- if (!participantIds)
31604
- return { error: MISSING_PARTICIPANT_ID };
31605
- if (!penaltyType)
31606
- return { error: MISSING_PENALTY_TYPE };
31607
- // TODO: add penalty timeItem to matchUp.timeItems[]
31608
- var participants = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
31609
- var relevantParticipants = participants.filter(function (participant) {
31610
- return participantIds.includes(participant.participantId);
31611
- });
31612
- if (!relevantParticipants.length)
31613
- return { error: PARTICIPANT_NOT_FOUND };
31614
- var createdAt = new Date().toISOString();
31615
- var penaltyItem = Object.assign(penaltyTemplate({ penaltyId: penaltyId }), {
31616
- refereeParticipantId: refereeParticipantId,
31617
- penaltyCode: penaltyCode,
31618
- penaltyType: penaltyType,
31619
- matchUpId: matchUpId,
31620
- notes: notes,
31621
- issuedAt: issuedAt,
31622
- createdAt: createdAt,
31623
- });
31624
- if (Array.isArray(extensions)) {
31625
- extensions.forEach(function (extension) {
31626
- return addExtension$1({ element: penaltyItem, extension: extension });
31627
- });
31628
- }
31629
- relevantParticipants.forEach(function (participant) {
31630
- if (!participant.penalties)
31631
- participant.penalties = [];
31632
- participant.penalties.push(penaltyItem);
31633
- });
31634
- addNotice({
31635
- topic: MODIFY_PARTICIPANTS,
31636
- payload: {
31637
- tournamentId: tournamentRecord.tournamentId,
31638
- participants: relevantParticipants,
31639
- },
31640
- });
31641
- return __assign(__assign({}, SUCCESS), { penaltyId: penaltyItem.penaltyId });
31642
- }
31643
- function removePenalty$1(_a) {
31644
- var tournamentRecord = _a.tournamentRecord, penaltyId = _a.penaltyId;
31645
- if (!tournamentRecord)
31646
- return { error: MISSING_TOURNAMENT_RECORD };
31647
- if (!penaltyId)
31648
- return { error: MISSING_PENALTY_ID };
31649
- var participants = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
31650
- var modifiedParticipants = [];
31651
- var penaltyRemoved = false;
31652
- var removedPenalty;
31653
- participants.forEach(function (participant) {
31654
- var participantModified = false;
31655
- participant.penalties = (participant.penalties || []).filter(function (penalty) {
31656
- if (penalty.penaltyId === penaltyId) {
31657
- participantModified = true;
31658
- if (!penaltyRemoved) {
31659
- removedPenalty = penalty;
31660
- penaltyRemoved = true;
31661
- }
31662
- }
31663
- if (participantModified)
31664
- modifiedParticipants.push(participant);
31665
- return penalty.penaltyId !== penaltyId;
31666
- });
31667
- });
31668
- if (removedPenalty) {
31669
- addNotice({
31670
- topic: MODIFY_PARTICIPANTS,
31671
- payload: {
31672
- tournamentId: tournamentRecord.tournamentId,
31673
- participants: modifiedParticipants,
31674
- },
31675
- });
31676
- }
31677
- return removedPenalty
31678
- ? __assign(__assign({}, SUCCESS), { penalty: removedPenalty }) : { error: PENALTY_NOT_FOUND };
31679
- }
31680
- function getTournamentPenalties(_a) {
31681
- var tournamentRecord = _a.tournamentRecord;
31682
- if (!tournamentRecord)
31683
- return { error: MISSING_TOURNAMENT_RECORD };
31684
- var participants = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
31685
- var allPenalties = participants.reduce(function (penalties, participant) {
31686
- var participantId = participant.participantId;
31687
- (participant.penalties || []).forEach(function (penalty) {
31688
- var penaltyId = (penalty || {}).penaltyId;
31689
- if (penalties[penaltyId]) {
31690
- penalties[penaltyId].participants.push(participantId);
31691
- }
31692
- else {
31693
- penalties[penaltyId] = __assign(__assign({}, penalty), { participantIds: [participantId] });
31694
- }
31695
- });
31696
- return penalties;
31697
- }, {});
31698
- return { penalties: Object.values(allPenalties) };
31699
- }
31700
- function modifyPenalty$1(_a) {
31701
- var tournamentRecord = _a.tournamentRecord, modifications = _a.modifications, penaltyId = _a.penaltyId;
31702
- if (!tournamentRecord)
31703
- return { error: MISSING_TOURNAMENT_RECORD };
31704
- if (!modifications)
31705
- return { error: INVALID_VALUES, modifications: modifications };
31706
- if (!penaltyId)
31707
- return { error: MISSING_PENALTY_ID };
31708
- var participants = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
31709
- var validAttributes = Object.keys(penaltyTemplate()).filter(function (attribute) { return attribute !== 'penaltyId'; });
31710
- var validModificationAttributes = Object.keys(modifications).filter(function (attribute) { return validAttributes.includes(attribute); });
31711
- if (!validModificationAttributes.length)
31712
- return { error: NO_VALID_ATTRIBUTES };
31713
- var updatedPenalty;
31714
- var modifiedParticipants = [];
31715
- participants.forEach(function (participant) {
31716
- var participantModified = false;
31717
- participant.penalties = (participant.penalties || []).map(function (penalty) {
31718
- if (penalty.penaltyId === penaltyId) {
31719
- participantModified = true;
31720
- validModificationAttributes.forEach(function (attribute) {
31721
- var _a;
31722
- return Object.assign(penalty, (_a = {}, _a[attribute] = modifications[attribute], _a));
31723
- });
31724
- if (!updatedPenalty)
31725
- updatedPenalty = penalty;
31726
- }
31727
- return penalty;
31728
- });
31729
- if (participantModified)
31730
- modifiedParticipants.push(participant);
31731
- });
31732
- if (updatedPenalty) {
31733
- addNotice({
31734
- topic: MODIFY_PARTICIPANTS,
31735
- payload: {
31736
- tournamentId: tournamentRecord.tournamentId,
31737
- participants: modifiedParticipants,
31738
- },
31739
- });
31740
- }
31741
- return updatedPenalty
31742
- ? __assign(__assign({}, SUCCESS), { penalty: updatedPenalty }) : { error: PENALTY_NOT_FOUND };
31743
- }
31744
-
31745
- function addPenalty(params) {
31746
- var e_1, _a;
31747
- var _b;
31748
- var tournamentRecords = params.tournamentRecords, participantIds = params.participantIds;
31749
- var penaltyId;
31750
- try {
31751
- for (var _c = __values(Object.values(tournamentRecords)), _d = _c.next(); !_d.done; _d = _c.next()) {
31752
- var tournamentRecord = _d.value;
31753
- var participants = (_b = getParticipants$1({
31754
- tournamentRecord: tournamentRecord,
31755
- }).participants) !== null && _b !== void 0 ? _b : [];
31756
- var tournamentParticipantIds = participants === null || participants === void 0 ? void 0 : participants.map(extractAttributes('participantId')).filter(function (participantId) { return participantIds.includes(participantId); });
31757
- if (tournamentParticipantIds.length) {
31758
- var result = addPenalty$1(__assign(__assign({}, params), { penaltyId: params.penaltyId || penaltyId, tournamentRecord: tournamentRecord, participantIds: tournamentParticipantIds }));
31759
- penaltyId = result.penaltyId;
31760
- }
31761
- }
31762
- }
31763
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
31764
- finally {
31765
- try {
31766
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
31767
- }
31768
- finally { if (e_1) throw e_1.error; }
31769
- }
31770
- return penaltyId
31771
- ? __assign(__assign({}, SUCCESS), { penaltyId: penaltyId }) : { error: PARTICIPANT_NOT_FOUND };
31772
- }
31773
- function modifyPenalty(params) {
31774
- var e_2, _a;
31775
- var tournamentRecords = params.tournamentRecords;
31776
- if (typeof tournamentRecords !== 'object' ||
31777
- !Object.keys(tournamentRecords).length)
31778
- return { error: MISSING_TOURNAMENT_RECORDS };
31779
- try {
31780
- for (var _b = __values(Object.values(tournamentRecords)), _c = _b.next(); !_c.done; _c = _b.next()) {
31781
- var tournamentRecord = _c.value;
31782
- var result = modifyPenalty$1(__assign({ tournamentRecord: tournamentRecord }, params));
31783
- if (result.error && result.error !== PENALTY_NOT_FOUND)
31784
- return result;
31785
- }
31786
- }
31787
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
31788
- finally {
31789
- try {
31790
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
31791
- }
31792
- finally { if (e_2) throw e_2.error; }
31793
- }
31794
- return __assign({}, SUCCESS);
31795
- }
31796
- function removePenalty(params) {
31797
- var e_3, _a;
31798
- var tournamentRecords = params.tournamentRecords;
30624
+ function removePenalty(params) {
30625
+ var e_3, _a;
30626
+ var tournamentRecords = params.tournamentRecords;
31799
30627
  if (typeof tournamentRecords !== 'object' ||
31800
30628
  !Object.keys(tournamentRecords).length)
31801
30629
  return { error: MISSING_TOURNAMENT_RECORDS };
@@ -34551,6 +33379,8 @@ function getMatchUpFormatTimingUpdate$1(_a) {
34551
33379
  }
34552
33380
 
34553
33381
  function getEventMatchUpFormatTiming$1(_a) {
33382
+ var _b, _c;
33383
+ var _d, _e;
34554
33384
  var tournamentRecord = _a.tournamentRecord, matchUpFormats = _a.matchUpFormats, // optional - can be retrieved from policy
34555
33385
  categoryType = _a.categoryType, // optional - categoryType is not part of event attributes
34556
33386
  event = _a.event;
@@ -34559,6 +33389,7 @@ function getEventMatchUpFormatTiming$1(_a) {
34559
33389
  if (!event)
34560
33390
  return { error: MISSING_EVENT };
34561
33391
  var matchUpFormatDefinitions = [];
33392
+ var info;
34562
33393
  if (!(matchUpFormats === null || matchUpFormats === void 0 ? void 0 : matchUpFormats.length)) {
34563
33394
  var policy = findPolicy({
34564
33395
  policyType: POLICY_TYPE_SCORING,
@@ -34573,12 +33404,15 @@ function getEventMatchUpFormatTiming$1(_a) {
34573
33404
  name: SCHEDULE_TIMING,
34574
33405
  event: event,
34575
33406
  }).extension;
33407
+ var matchUpAverageTimes = void 0, matchUpRecoveryTimes = void 0;
34576
33408
  if (extension === null || extension === void 0 ? void 0 : extension.value) {
34577
- matchUpFormatDefinitions = unique(__spreadArray(__spreadArray([], __read((extension.value.matchUpAverageTimes || []).map(function (at) { return at.matchUpFormatCodes; })), false), __read((extension.value.matchUpRecoveryTimes || []).map(function (at) { return at.matchUpFormatCodes; })), false).flat()).map(function (matchUpFormat) { return ({ matchUpFormat: matchUpFormat }); });
33409
+ (_b = extension.value, matchUpAverageTimes = _b.matchUpAverageTimes, matchUpRecoveryTimes = _b.matchUpRecoveryTimes);
34578
33410
  }
34579
33411
  else {
34580
- return { error: MISSING_SCORING_POLICY };
33412
+ (_c = POLICY_SCHEDULING_DEFAULT[POLICY_TYPE_SCHEDULING], matchUpAverageTimes = _c.matchUpAverageTimes, matchUpRecoveryTimes = _c.matchUpRecoveryTimes);
34581
33413
  }
33414
+ matchUpFormatDefinitions = unique(__spreadArray(__spreadArray([], __read((matchUpAverageTimes || []).map(function (at) { return at.matchUpFormatCodes; })), false), __read((matchUpRecoveryTimes || []).map(function (at) { return at.matchUpFormatCodes; })), false).flat()).map(function (matchUpFormat) { return ({ matchUpFormat: matchUpFormat }); });
33415
+ info = 'default scheduling policy in use';
34582
33416
  }
34583
33417
  }
34584
33418
  else {
@@ -34598,7 +33432,7 @@ function getEventMatchUpFormatTiming$1(_a) {
34598
33432
  .filter(Boolean);
34599
33433
  }
34600
33434
  var eventType = event.eventType, eventId = event.eventId, category = event.category;
34601
- var categoryName = (category === null || category === void 0 ? void 0 : category.categoryName) || (category === null || category === void 0 ? void 0 : category.ageCategoryCode) || eventId;
33435
+ var categoryName = (_e = (_d = category === null || category === void 0 ? void 0 : category.categoryName) !== null && _d !== void 0 ? _d : category === null || category === void 0 ? void 0 : category.ageCategoryCode) !== null && _e !== void 0 ? _e : eventId;
34602
33436
  if (!eventId)
34603
33437
  return { error: MISSING_EVENT };
34604
33438
  var eventMatchUpFormatTiming = matchUpFormatDefinitions.map(function (_a) {
@@ -34611,9 +33445,9 @@ function getEventMatchUpFormatTiming$1(_a) {
34611
33445
  eventType: eventType,
34612
33446
  event: event,
34613
33447
  });
34614
- return Object.assign({}, __assign(__assign({}, timing), { description: description, matchUpFormat: matchUpFormat }));
33448
+ return __assign({ matchUpFormat: matchUpFormat, description: description }, timing);
34615
33449
  });
34616
- return { eventMatchUpFormatTiming: eventMatchUpFormatTiming };
33450
+ return definedAttributes({ eventMatchUpFormatTiming: eventMatchUpFormatTiming, info: info });
34617
33451
  }
34618
33452
 
34619
33453
  function getEventMatchUpFormatTiming(_a) {
@@ -35963,6 +34797,14 @@ function modifyParticipantMatchUpsCount(_a) {
35963
34797
  });
35964
34798
  }
35965
34799
 
34800
+ var hasSchedule = function (_a) {
34801
+ var _b = _a.scheduleAttributes, scheduleAttributes = _b === void 0 ? ['scheduledDate', 'scheduledTime'] : _b, _c = _a.schedule, schedule = _c === void 0 ? {} : _c;
34802
+ var matchUpScheduleKeys = Object.keys(schedule)
34803
+ .filter(function (key) { return scheduleAttributes.includes(key); })
34804
+ .filter(function (key) { return schedule[key]; });
34805
+ return !!matchUpScheduleKeys.length;
34806
+ };
34807
+
35966
34808
  function processAlreadyScheduledMatchUps(_a) {
35967
34809
  var e_1, _b;
35968
34810
  var _c, _d;
@@ -39904,12 +38746,11 @@ var policyGovernor$2 = {
39904
38746
  };
39905
38747
 
39906
38748
  function getParticipantScaleItem$1(_a) {
39907
- var tournamentRecords = _a.tournamentRecords, policyDefinitions = _a.policyDefinitions, scaleAttributes = _a.scaleAttributes, participantId = _a.participantId, inContext = _a.inContext, personId = _a.personId;
38749
+ var tournamentRecords = _a.tournamentRecords, policyDefinitions = _a.policyDefinitions, scaleAttributes = _a.scaleAttributes, participantId = _a.participantId, personId = _a.personId;
39908
38750
  var result = publicFindParticipant({
39909
38751
  tournamentRecords: tournamentRecords,
39910
38752
  policyDefinitions: policyDefinitions,
39911
38753
  participantId: participantId,
39912
- inContext: inContext,
39913
38754
  personId: personId,
39914
38755
  });
39915
38756
  if (result.error)
@@ -40398,7 +39239,7 @@ function matchUpActions$2(_a) {
40398
39239
  participantsAvailable === null || participantsAvailable === void 0 ? void 0 : participantsAvailable.forEach(function (participant) {
40399
39240
  var _a;
40400
39241
  var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === participant.participantId; });
40401
- // TODO: determine if this is in fact used downstream
39242
+ // used to sort available participants
40402
39243
  participant.entryPosition = entry === null || entry === void 0 ? void 0 : entry.entryPosition;
40403
39244
  });
40404
39245
  if (availableParticipantIds_1.length) {
@@ -54451,391 +53292,1559 @@ function setState$2(value, deepCopyOption) {
54451
53292
  }
54452
53293
  }
54453
53294
  }
54454
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
54455
- finally {
54456
- try {
54457
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
54458
- }
54459
- finally { if (e_1) throw e_1.error; }
53295
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
53296
+ finally {
53297
+ try {
53298
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
53299
+ }
53300
+ finally { if (e_1) throw e_1.error; }
53301
+ }
53302
+ }
53303
+ else {
53304
+ try {
53305
+ for (var _e = __values(Object.values(value)), _f = _e.next(); !_f.done; _f = _e.next()) {
53306
+ var m = _f.value;
53307
+ if (m.matchUpId) {
53308
+ keyedMatchUps[m.matchUpId] = deepCopyOption ? makeDeepCopy(m) : m;
53309
+ if (!matchUpId)
53310
+ matchUpId = m.matchUpId;
53311
+ }
53312
+ }
53313
+ }
53314
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
53315
+ finally {
53316
+ try {
53317
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
53318
+ }
53319
+ finally { if (e_2) throw e_2.error; }
53320
+ }
53321
+ }
53322
+ return deepCopyOption ? makeDeepCopy(value) : value;
53323
+ }
53324
+ function getMatchUp() {
53325
+ return keyedMatchUps[matchUpId];
53326
+ }
53327
+ function getMatchUps() {
53328
+ return Object.values(keyedMatchUps);
53329
+ }
53330
+ function reset() {
53331
+ matchUpId = undefined;
53332
+ keyedMatchUps = {};
53333
+ }
53334
+ function getState$2(params) {
53335
+ return makeDeepCopy(keyedMatchUps[matchUpId], params === null || params === void 0 ? void 0 : params.convertExtensions, false, params === null || params === void 0 ? void 0 : params.removeExtensions);
53336
+ }
53337
+
53338
+ var matchUpEngine = (function () {
53339
+ var engine = {
53340
+ getState: function (params) { return getState$2(params); },
53341
+ version: function () { return factoryVersion(); },
53342
+ reset: function () {
53343
+ reset();
53344
+ return __assign({}, SUCCESS);
53345
+ },
53346
+ drawId: undefined,
53347
+ error: undefined,
53348
+ success: false,
53349
+ devContext: function (contextCriteria) {
53350
+ setDevContext(contextCriteria);
53351
+ return engine;
53352
+ },
53353
+ setState: function (definition, deepCopyOption, deepCopyAttributes) {
53354
+ setDeepCopy(deepCopyOption, deepCopyAttributes);
53355
+ var result = setState$2(definition);
53356
+ return processResult(result);
53357
+ },
53358
+ };
53359
+ function processResult(result) {
53360
+ if (result === null || result === void 0 ? void 0 : result.error) {
53361
+ engine.error = result.error;
53362
+ engine.success = false;
53363
+ }
53364
+ else {
53365
+ engine.error = undefined;
53366
+ engine.success = true;
53367
+ engine.drawId = result.drawId;
53368
+ }
53369
+ return engine;
53370
+ }
53371
+ importGovernors([
53372
+ tieFormatGovernor,
53373
+ historyGovernor,
53374
+ queryGovernor$1,
53375
+ scoreGovernor,
53376
+ ]);
53377
+ return engine;
53378
+ function importGovernors(governors) {
53379
+ governors.forEach(function (governor) {
53380
+ Object.keys(governor).forEach(function (methodName) {
53381
+ engine[methodName] = function (params) {
53382
+ if (getDevContext()) {
53383
+ return invoke({ params: params, governor: governor, methodName: methodName });
53384
+ }
53385
+ else {
53386
+ try {
53387
+ return invoke({ params: params, governor: governor, methodName: methodName });
53388
+ }
53389
+ catch (err) {
53390
+ handleCaughtError({
53391
+ engineName: 'matchUpEngine',
53392
+ methodName: methodName,
53393
+ params: params,
53394
+ err: err,
53395
+ });
53396
+ }
53397
+ }
53398
+ };
53399
+ });
53400
+ });
53401
+ }
53402
+ function invoke(_a) {
53403
+ var params = _a.params, governor = _a.governor, methodName = _a.methodName;
53404
+ engine.error = undefined;
53405
+ engine.success = false;
53406
+ var matchUp = (params === null || params === void 0 ? void 0 : params.matchUp) || getMatchUp();
53407
+ var matchUps = (params === null || params === void 0 ? void 0 : params.matchUps) || getMatchUps();
53408
+ var snapshot = (params === null || params === void 0 ? void 0 : params.rollbackOnError) && makeDeepCopy(matchUp, false, true);
53409
+ params = __assign(__assign({}, params), { matchUpId: matchUp === null || matchUp === void 0 ? void 0 : matchUp.matchUpId, matchUps: matchUps, matchUp: matchUp });
53410
+ var result = governor[methodName](params);
53411
+ if (result === null || result === void 0 ? void 0 : result.error) {
53412
+ if (snapshot)
53413
+ setState$2(snapshot);
53414
+ return __assign(__assign({}, result), { rolledBack: !!snapshot });
53415
+ }
53416
+ var notify = (result === null || result === void 0 ? void 0 : result.success) &&
53417
+ (params === null || params === void 0 ? void 0 : params.delayNotify) !== true &&
53418
+ (params === null || params === void 0 ? void 0 : params.doNotNotify) !== true;
53419
+ if (notify)
53420
+ notifySubscribers();
53421
+ if (notify || !(result === null || result === void 0 ? void 0 : result.success) || (params === null || params === void 0 ? void 0 : params.doNotNotify))
53422
+ deleteNotices();
53423
+ return result;
53424
+ }
53425
+ })();
53426
+
53427
+ function matchUpEngineAsync(test) {
53428
+ var result = createInstanceState();
53429
+ if (result.error && !test)
53430
+ return result;
53431
+ var engine = {
53432
+ getState: function (params) { return getState$2(params); },
53433
+ version: function () { return factoryVersion(); },
53434
+ reset: function () {
53435
+ reset();
53436
+ return __assign({}, SUCCESS);
53437
+ },
53438
+ drawId: undefined,
53439
+ error: undefined,
53440
+ success: false,
53441
+ devContext: function (contextCriteria) {
53442
+ setDevContext(contextCriteria);
53443
+ return engine;
53444
+ },
53445
+ setState: function (definition, deepCopyOption, deepCopyAttributes) {
53446
+ setDeepCopy(deepCopyOption, deepCopyAttributes);
53447
+ var result = setState$2(definition);
53448
+ return processResult(result);
53449
+ },
53450
+ };
53451
+ function processResult(result) {
53452
+ if (result === null || result === void 0 ? void 0 : result.error) {
53453
+ engine.error = result.error;
53454
+ engine.success = false;
53455
+ }
53456
+ else {
53457
+ engine.error = undefined;
53458
+ engine.success = true;
53459
+ engine.drawId = result.drawId;
53460
+ }
53461
+ return engine;
53462
+ }
53463
+ importGovernors([
53464
+ tieFormatGovernor,
53465
+ historyGovernor,
53466
+ queryGovernor$1,
53467
+ scoreGovernor,
53468
+ ]);
53469
+ return engine;
53470
+ function importGovernors(governors) {
53471
+ return __awaiter(this, void 0, void 0, function () {
53472
+ var _loop_1, governors_1, governors_1_1, governor;
53473
+ var e_1, _a;
53474
+ var _this = this;
53475
+ return __generator(this, function (_b) {
53476
+ _loop_1 = function (governor) {
53477
+ var e_2, _c;
53478
+ var governorMethods = Object.keys(governor);
53479
+ var _loop_2 = function (methodName) {
53480
+ engine[methodName] = function (params) { return __awaiter(_this, void 0, void 0, function () {
53481
+ var err_1;
53482
+ return __generator(this, function (_a) {
53483
+ switch (_a.label) {
53484
+ case 0:
53485
+ if (!getDevContext()) return [3 /*break*/, 2];
53486
+ return [4 /*yield*/, invoke({ params: params, governor: governor, methodName: methodName })];
53487
+ case 1: return [2 /*return*/, _a.sent()];
53488
+ case 2:
53489
+ _a.trys.push([2, 4, , 5]);
53490
+ return [4 /*yield*/, invoke({ params: params, governor: governor, methodName: methodName })];
53491
+ case 3: return [2 /*return*/, _a.sent()];
53492
+ case 4:
53493
+ err_1 = _a.sent();
53494
+ handleCaughtError({
53495
+ engineName: 'matchUpEngine',
53496
+ methodName: methodName,
53497
+ params: params,
53498
+ err: err_1,
53499
+ });
53500
+ return [3 /*break*/, 5];
53501
+ case 5: return [2 /*return*/];
53502
+ }
53503
+ });
53504
+ }); };
53505
+ };
53506
+ try {
53507
+ for (var governorMethods_1 = (e_2 = void 0, __values(governorMethods)), governorMethods_1_1 = governorMethods_1.next(); !governorMethods_1_1.done; governorMethods_1_1 = governorMethods_1.next()) {
53508
+ var methodName = governorMethods_1_1.value;
53509
+ _loop_2(methodName);
53510
+ }
53511
+ }
53512
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
53513
+ finally {
53514
+ try {
53515
+ if (governorMethods_1_1 && !governorMethods_1_1.done && (_c = governorMethods_1.return)) _c.call(governorMethods_1);
53516
+ }
53517
+ finally { if (e_2) throw e_2.error; }
53518
+ }
53519
+ };
53520
+ try {
53521
+ for (governors_1 = __values(governors), governors_1_1 = governors_1.next(); !governors_1_1.done; governors_1_1 = governors_1.next()) {
53522
+ governor = governors_1_1.value;
53523
+ _loop_1(governor);
53524
+ }
53525
+ }
53526
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
53527
+ finally {
53528
+ try {
53529
+ if (governors_1_1 && !governors_1_1.done && (_a = governors_1.return)) _a.call(governors_1);
53530
+ }
53531
+ finally { if (e_1) throw e_1.error; }
53532
+ }
53533
+ return [2 /*return*/];
53534
+ });
53535
+ });
53536
+ }
53537
+ function invoke(_a) {
53538
+ var params = _a.params, governor = _a.governor, methodName = _a.methodName;
53539
+ return __awaiter(this, void 0, void 0, function () {
53540
+ var matchUp, matchUps, snapshot, result, notify;
53541
+ return __generator(this, function (_b) {
53542
+ switch (_b.label) {
53543
+ case 0:
53544
+ engine.success = false;
53545
+ engine.error = undefined;
53546
+ matchUp = (params === null || params === void 0 ? void 0 : params.matchUp) || getMatchUp();
53547
+ matchUps = (params === null || params === void 0 ? void 0 : params.matchUps) || getMatchUps();
53548
+ snapshot = (params === null || params === void 0 ? void 0 : params.rollbackOnError) && makeDeepCopy(matchUp, false, true);
53549
+ params = __assign(__assign({}, params), { matchUpId: matchUp === null || matchUp === void 0 ? void 0 : matchUp.matchUpId, matchUps: matchUps, matchUp: matchUp });
53550
+ result = governor[methodName](params);
53551
+ if (result === null || result === void 0 ? void 0 : result.error) {
53552
+ if (snapshot)
53553
+ setState$2(snapshot);
53554
+ return [2 /*return*/, __assign(__assign({}, result), { rolledBack: !!snapshot })];
53555
+ }
53556
+ notify = (result === null || result === void 0 ? void 0 : result.success) &&
53557
+ (params === null || params === void 0 ? void 0 : params.delayNotify) !== true &&
53558
+ (params === null || params === void 0 ? void 0 : params.doNotNotify) !== true;
53559
+ if (!notify) return [3 /*break*/, 2];
53560
+ return [4 /*yield*/, notifySubscribersAsync()];
53561
+ case 1:
53562
+ _b.sent();
53563
+ _b.label = 2;
53564
+ case 2:
53565
+ if (notify || !(result === null || result === void 0 ? void 0 : result.success) || (params === null || params === void 0 ? void 0 : params.doNotNotify))
53566
+ deleteNotices();
53567
+ return [2 /*return*/, result];
53568
+ }
53569
+ });
53570
+ });
53571
+ }
53572
+ }
53573
+
53574
+ function newTournamentRecord(params) {
53575
+ var attributes = params || {};
53576
+ if (!attributes.tournamentId)
53577
+ attributes.tournamentId = UUID();
53578
+ if (attributes.startDate &&
53579
+ !isISODateString(attributes.startDate) &&
53580
+ !validDateString.test(attributes.startDate)) {
53581
+ return { error: INVALID_DATE };
53582
+ }
53583
+ if (attributes.endDate &&
53584
+ !isISODateString(attributes.endDate) &&
53585
+ !validDateString.test(attributes.endDate)) {
53586
+ return { error: INVALID_DATE };
53587
+ }
53588
+ if (attributes.extensions) {
53589
+ attributes.extensions = attributes.extensions.filter(isValidExtension);
53590
+ }
53591
+ return __assign({}, attributes);
53592
+ }
53593
+
53594
+ function setState$1(tournament, deepCopyOption) {
53595
+ var _a;
53596
+ var _b;
53597
+ if (typeof tournament !== 'object')
53598
+ return { error: INVALID_OBJECT };
53599
+ var tournamentId = ((_b = tournament.unifiedTournamentId) === null || _b === void 0 ? void 0 : _b.tournamentId) || tournament.tournamentId;
53600
+ if (!tournamentId)
53601
+ return { error: MISSING_TOURNAMENT_ID };
53602
+ var tournamentRecord = deepCopyOption !== false ? makeDeepCopy(tournament) : tournament;
53603
+ setTournamentRecords((_a = {}, _a[tournamentId] = tournamentRecord, _a));
53604
+ setTournamentId(tournamentId); // must be set AFTER tournamentRecord
53605
+ return tournamentRecord;
53606
+ }
53607
+ function getState$1(_a) {
53608
+ var _b = _a.convertExtensions, convertExtensions = _b === void 0 ? false : _b, _c = _a.removeExtensions, removeExtensions = _c === void 0 ? false : _c, tournamentId = _a.tournamentId;
53609
+ if (typeof tournamentId !== 'string')
53610
+ return {};
53611
+ var tournamentRecord = getTournamentRecord(tournamentId);
53612
+ return {
53613
+ tournamentRecord: makeDeepCopy(tournamentRecord, convertExtensions, false, removeExtensions),
53614
+ };
53615
+ }
53616
+ // prefetch can be triggered based on method governor, e.g. not necessary for query
53617
+ function paramsMiddleware$1(tournamentRecord, params, prefetch) {
53618
+ var _a;
53619
+ if (params) {
53620
+ var drawId = params.drawId || ((_a = params.matchUp) === null || _a === void 0 ? void 0 : _a.drawId);
53621
+ if (drawId) {
53622
+ var _b = findEvent({
53623
+ tournamentRecord: tournamentRecord,
53624
+ drawId: drawId,
53625
+ }), event_1 = _b.event, drawDefinition = _b.drawDefinition;
53626
+ params = __assign(__assign({}, params), { event: event_1, drawDefinition: drawDefinition });
53627
+ if (prefetch) {
53628
+ var matchUpsMap = getMatchUpsMap({ drawDefinition: drawDefinition });
53629
+ var inContextDrawMatchUps = getAllDrawMatchUps({
53630
+ inContext: true,
53631
+ drawDefinition: drawDefinition,
53632
+ matchUpsMap: matchUpsMap,
53633
+ }).matchUps;
53634
+ params.matchUpsMap = matchUpsMap;
53635
+ params.inContextDrawMatchUps = inContextDrawMatchUps;
53636
+ }
53637
+ }
53638
+ if (params.eventId && !params.event) {
53639
+ var event_2 = findEvent({
53640
+ eventId: params.eventId,
53641
+ tournamentRecord: tournamentRecord,
53642
+ }).event;
53643
+ if (event_2) {
53644
+ params = __assign(__assign({}, params), { event: event_2 });
53645
+ }
53646
+ }
53647
+ }
53648
+ return params;
53649
+ }
53650
+
53651
+ function getEligibleVoluntaryConsolationParticipants(params) {
53652
+ if (!params.tournamentRecord)
53653
+ return { error: MISSING_TOURNAMENT_RECORD };
53654
+ return getEligibleVoluntaryConsolationParticipants$1(params);
53655
+ }
53656
+
53657
+ function getParticipantEventDetails(_a) {
53658
+ var tournamentRecord = _a.tournamentRecord, participantId = _a.participantId;
53659
+ if (!tournamentRecord)
53660
+ return { error: MISSING_TOURNAMENT_RECORD };
53661
+ if (!participantId)
53662
+ return { error: MISSING_PARTICIPANT_ID };
53663
+ // relveantParticipantIds is the target participantId along with any TEAM or PAIR participantIds to which participantId belongs
53664
+ var relevantParticipantIds = [participantId].concat((tournamentRecord.participants || [])
53665
+ .filter(function (participant) {
53666
+ var _a;
53667
+ return (participant === null || participant === void 0 ? void 0 : participant.participantType) &&
53668
+ [TEAM, PAIR].includes(participant.participantType) &&
53669
+ ((_a = participant.individualParticipantIds) === null || _a === void 0 ? void 0 : _a.includes(participantId));
53670
+ })
53671
+ .map(function (participant) { return participant.participantId; }));
53672
+ var relevantEvents = (tournamentRecord.events || [])
53673
+ .filter(function (event) {
53674
+ var enteredParticipantIds = ((event === null || event === void 0 ? void 0 : event.entries) || []).map(function (entry) { return entry.participantId; });
53675
+ return overlap(enteredParticipantIds, relevantParticipantIds);
53676
+ })
53677
+ .map(function (event) { return ({ eventName: event.eventName, eventId: event.eventId }); });
53678
+ return { eventDetails: relevantEvents };
53679
+ }
53680
+
53681
+ function getDerivedPositionAssignments(_a) {
53682
+ var _b, _c, _d, _e;
53683
+ var derivedDrawInfo = _a.derivedDrawInfo, participantId = _a.participantId, drawId = _a.drawId;
53684
+ var mainPositionAssignment = (_c = (_b = derivedDrawInfo[drawId]) === null || _b === void 0 ? void 0 : _b.mainPositionAssignments) === null || _c === void 0 ? void 0 : _c.find(function (assignment) { return assignment.participantId === participantId; });
53685
+ var qualifyingPositionAssignment = (_e = (_d = derivedDrawInfo[drawId]) === null || _d === void 0 ? void 0 : _d.qualifyingPositionAssignments) === null || _e === void 0 ? void 0 : _e.find(function (assignment) { return assignment.participantId === participantId; });
53686
+ var positionAssignments = {};
53687
+ if (mainPositionAssignment) {
53688
+ var participantId_1 = mainPositionAssignment.participantId, props = __rest(mainPositionAssignment, ["participantId"]);
53689
+ if (participantId_1)
53690
+ positionAssignments[MAIN] = __assign({}, props);
53691
+ }
53692
+ if (qualifyingPositionAssignment) {
53693
+ var participantId_2 = qualifyingPositionAssignment.participantId, props = __rest(qualifyingPositionAssignment, ["participantId"]);
53694
+ if (participantId_2)
53695
+ positionAssignments[QUALIFYING] = __assign({}, props);
53696
+ }
53697
+ return Object.keys(positionAssignments).length
53698
+ ? positionAssignments
53699
+ : undefined;
53700
+ }
53701
+
53702
+ function getRelevantParticipantIdsMap(_a) {
53703
+ var processParticipantId = _a.processParticipantId, // optional method which is passed each participantId
53704
+ tournamentRecords = _a.tournamentRecords, tournamentRecord = _a.tournamentRecord;
53705
+ if (typeof tournamentRecord !== 'object' &&
53706
+ typeof tournamentRecords !== 'object')
53707
+ return { error: MISSING_TOURNAMENT_RECORD };
53708
+ // build up a mapping of all participantIds to all of the individualParticipantIds that they reference
53709
+ // this map includes the key participantId as a value of the array of relevantParticipantIds
53710
+ var allParticipants = tournamentRecords
53711
+ ? Object.values(tournamentRecords)
53712
+ .map(function (tournamentRecord) { return (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || []; })
53713
+ .flat()
53714
+ : (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
53715
+ var relevantParticipantIdsMap = Object.assign.apply(Object, __spreadArray([{}], __read(allParticipants.map(function (_a) {
53716
+ var _b;
53717
+ var participantId = _a.participantId, participantType = _a.participantType, individualParticipantIds = _a.individualParticipantIds;
53718
+ typeof processParticipantId === 'function' &&
53719
+ processParticipantId(participantId);
53720
+ var individualParticipantIdObjects = (individualParticipantIds || []).map(function (relevantParticipantId) { return ({
53721
+ participantType: INDIVIDUAL,
53722
+ relevantParticipantId: relevantParticipantId,
53723
+ }); });
53724
+ return _b = {},
53725
+ _b[participantId] = individualParticipantIdObjects.concat({
53726
+ relevantParticipantId: participantId,
53727
+ participantType: participantType,
53728
+ }),
53729
+ _b;
53730
+ })), false));
53731
+ return { relevantParticipantIdsMap: relevantParticipantIdsMap };
53732
+ }
53733
+
53734
+ function getDerivedSeedAssignments(_a) {
53735
+ var _b, _c, _d, _e;
53736
+ var derivedDrawInfo = _a.derivedDrawInfo, participantId = _a.participantId, drawId = _a.drawId;
53737
+ var mainSeedAssignment = (_c = (_b = derivedDrawInfo[drawId]) === null || _b === void 0 ? void 0 : _b.mainSeedAssignments) === null || _c === void 0 ? void 0 : _c.find(function (assignment) { return assignment.participantId === participantId; });
53738
+ var qualifyingSeedAssignment = (_e = (_d = derivedDrawInfo[drawId]) === null || _d === void 0 ? void 0 : _d.qualifyingSeedAssignments) === null || _e === void 0 ? void 0 : _e.find(function (assignment) { return assignment.participantId === participantId; });
53739
+ var seedAssignments = {};
53740
+ if (mainSeedAssignment) {
53741
+ var participantId_1 = mainSeedAssignment.participantId, props = __rest(mainSeedAssignment, ["participantId"]);
53742
+ if (participantId_1)
53743
+ seedAssignments[MAIN] = __assign({}, props);
53744
+ }
53745
+ if (qualifyingSeedAssignment) {
53746
+ var participantId_2 = qualifyingSeedAssignment.participantId, props = __rest(qualifyingSeedAssignment, ["participantId"]);
53747
+ if (participantId_2)
53748
+ seedAssignments[QUALIFYING] = __assign({}, props);
53749
+ }
53750
+ return Object.keys(seedAssignments).length ? seedAssignments : undefined;
53751
+ }
53752
+
53753
+ function participantScheduledMatchUps(_a) {
53754
+ var _b = _a.scheduleAttributes, scheduleAttributes = _b === void 0 ? ['scheduledDate', 'scheduledTime'] : _b, _c = _a.matchUps, matchUps = _c === void 0 ? [] : _c;
53755
+ if (!validMatchUps(matchUps))
53756
+ return { error: MISSING_MATCHUPS };
53757
+ if (!Array.isArray(scheduleAttributes))
53758
+ return { error: INVALID_VALUES };
53759
+ var scheduledMatchUps = matchUps
53760
+ .filter(Boolean)
53761
+ .filter(function (_a) {
53762
+ var schedule = _a.schedule;
53763
+ return hasSchedule({ schedule: schedule, scheduleAttributes: scheduleAttributes });
53764
+ })
53765
+ .reduce(function (dateMatchUps, matchUp) {
53766
+ var schedule = matchUp.schedule;
53767
+ var date = extractDate(schedule === null || schedule === void 0 ? void 0 : schedule.scheduledDate);
53768
+ var time = extractTime(schedule === null || schedule === void 0 ? void 0 : schedule.scheduledTime);
53769
+ if (date && time) {
53770
+ if (dateMatchUps[date]) {
53771
+ dateMatchUps[date].push(matchUp);
53772
+ }
53773
+ else {
53774
+ dateMatchUps[date] = [matchUp];
53775
+ }
53776
+ }
53777
+ return dateMatchUps;
53778
+ }, {});
53779
+ // sort all date matchUps
53780
+ var dates = Object.keys(scheduledMatchUps);
53781
+ dates.forEach(function (date) {
53782
+ scheduledMatchUps[date].sort(function (a, b) {
53783
+ var _a, _b;
53784
+ return timeSort(extractTime((_a = a.schedule) === null || _a === void 0 ? void 0 : _a.scheduledTime), extractTime((_b = b.schedule) === null || _b === void 0 ? void 0 : _b.scheduledTime));
53785
+ });
53786
+ });
53787
+ return { scheduledMatchUps: scheduledMatchUps };
53788
+ }
53789
+
53790
+ function annotateParticipant(params) {
53791
+ var e_1, _a, e_2, _b;
53792
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
53793
+ var _p = params.withScaleValues, withScaleValues = _p === void 0 ? true : _p, eventsPublishStatuses = params.eventsPublishStatuses, _q = params.withEvents, withEvents = _q === void 0 ? true : _q, _r = params.withDraws, withDraws = _r === void 0 ? true : _r, participantIdMap = params.participantIdMap, scheduleAnalysis = params.scheduleAnalysis, derivedDrawInfo = params.derivedDrawInfo, usePublishState = params.usePublishState, withStatistics = params.withStatistics, withOpponents = params.withOpponents, withMatchUps = params.withMatchUps, withSeeding = params.withSeeding, participant = params.participant, withISO2 = params.withISO2, withIOC = params.withIOC;
53794
+ var scheduleConflicts = [];
53795
+ var scheduleItems = [];
53796
+ if (withIOC || withISO2)
53797
+ addNationalityCode({ participant: participant, withIOC: withIOC, withISO2: withISO2 });
53798
+ if (withScaleValues) {
53799
+ var _s = getScaleValues({ participant: participant }), ratings = _s.ratings, rankings = _s.rankings;
53800
+ participant.rankings = rankings;
53801
+ participant.ratings = ratings;
53802
+ }
53803
+ var participantId = participant === null || participant === void 0 ? void 0 : participant.participantId;
53804
+ if (!participantId || !participantIdMap[participantId])
53805
+ return {};
53806
+ var _t = participantIdMap[participantId], potentialMatchUps = _t.potentialMatchUps, opponents = _t.opponents, matchUps = _t.matchUps, events = _t.events, losses = _t.losses, draws = _t.draws, wins = _t.wins;
53807
+ var denominator = wins + losses;
53808
+ var numerator = wins;
53809
+ var statValue = denominator && numerator / denominator;
53810
+ var winRatioStat = {
53811
+ statCode: WIN_RATIO$1,
53812
+ denominator: denominator,
53813
+ numerator: numerator,
53814
+ statValue: statValue,
53815
+ };
53816
+ var participantDraws = Object.values(draws);
53817
+ var participantEvents = Object.values(events);
53818
+ if (withDraws && participantDraws) {
53819
+ participant.draws = participantDraws;
53820
+ try {
53821
+ for (var participantDraws_1 = __values(participantDraws), participantDraws_1_1 = participantDraws_1.next(); !participantDraws_1_1.done; participantDraws_1_1 = participantDraws_1.next()) {
53822
+ var participantDraw = participantDraws_1_1.value;
53823
+ var publishedSeeding = (_c = eventsPublishStatuses[participantDraw.eventId]) === null || _c === void 0 ? void 0 : _c.publishedSeeding;
53824
+ var seedingPublished = !usePublishState ||
53825
+ ((publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.published) &&
53826
+ (((_d = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _d === void 0 ? void 0 : _d.length) === 0 ||
53827
+ ((_e = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _e === void 0 ? void 0 : _e.includes(participantDraw.drawId))));
53828
+ if (seedingPublished) {
53829
+ var seedAssignments = getDerivedSeedAssignments({
53830
+ drawId: participantDraw.drawId,
53831
+ derivedDrawInfo: derivedDrawInfo,
53832
+ participantId: participantId,
53833
+ });
53834
+ if (seedAssignments) {
53835
+ participantDraw.seedAssignments = seedAssignments;
53836
+ }
53837
+ }
53838
+ }
53839
+ }
53840
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
53841
+ finally {
53842
+ try {
53843
+ if (participantDraws_1_1 && !participantDraws_1_1.done && (_a = participantDraws_1.return)) _a.call(participantDraws_1);
53844
+ }
53845
+ finally { if (e_1) throw e_1.error; }
53846
+ }
53847
+ }
53848
+ if (withEvents && participantEvents) {
53849
+ participant.events = participantEvents;
53850
+ if (withSeeding) {
53851
+ var seedingScales_1 = Object.assign.apply(Object, __spreadArray([{}], __read((participant.timeItems || [])
53852
+ .filter(function (_a) {
53853
+ var itemType = _a.itemType;
53854
+ return itemType.split('.')[1] === SEEDING$1;
53855
+ })
53856
+ .map(function (_a) {
53857
+ var _b;
53858
+ var seedingScaleName = _a.itemType, seedValue = _a.itemValue;
53859
+ return (_b = {},
53860
+ _b[seedingScaleName] = seedValue,
53861
+ _b);
53862
+ })), false));
53863
+ var _loop_1 = function (participantEvent) {
53864
+ var e_3, _u, e_4, _v, e_5, _w;
53865
+ var getScaleAccessor = function (scaleName) {
53866
+ return [SCALE$1, SEEDING$1, participantEvent.eventType, scaleName].join('.');
53867
+ };
53868
+ var publishedSeeding = (_f = eventsPublishStatuses[participantEvent.eventId]) === null || _f === void 0 ? void 0 : _f.publishedSeeding;
53869
+ var eventSeedingScaleNames = (((publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.stageSeedingScaleNames) &&
53870
+ Object.values(publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.stageSeedingScaleNames)) ||
53871
+ (Array.isArray(publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.seedingScaleNames) &&
53872
+ publishedSeeding.seedingScaleNames) ||
53873
+ []).map(getScaleAccessor);
53874
+ var publishedEventSeedingScaleNames = intersection(Object.keys(seedingScales_1), eventSeedingScaleNames);
53875
+ var eventSeedingPublished = !!(!usePublishState ||
53876
+ (!Object.keys(seedingScales_1).length &&
53877
+ !((_g = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _g === void 0 ? void 0 : _g.length)) ||
53878
+ publishedEventSeedingScaleNames.length);
53879
+ if (eventSeedingPublished && publishedEventSeedingScaleNames.length) {
53880
+ if (publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.stageSeedingScaleNames) {
53881
+ var scaleValues = Object.keys(publishedSeeding.stageSeedingScaleNames)
53882
+ .map(function (key) {
53883
+ var accessor = getScaleAccessor(publishedSeeding.stageSeedingScaleNames[key]);
53884
+ var scaleValue = seedingScales_1[accessor];
53885
+ return [key, scaleValue];
53886
+ })
53887
+ .filter(function (pair) { return pair[1]; })
53888
+ .map(function (pair) {
53889
+ var _a;
53890
+ return (_a = {}, _a[pair[0]] = { seedValue: pair[1] }, _a);
53891
+ });
53892
+ var seedAssignments = Object.assign.apply(Object, __spreadArray([{}], __read(scaleValues), false));
53893
+ participantEvent.seedAssignments = seedAssignments;
53894
+ }
53895
+ else if (publishedEventSeedingScaleNames) {
53896
+ var seedValues = publishedEventSeedingScaleNames.map(function (scaleName) { return seedingScales_1[scaleName]; });
53897
+ participantEvent.seedValue = seedValues.pop();
53898
+ }
53899
+ }
53900
+ else if (!usePublishState && typeof withSeeding === 'object') {
53901
+ var scaleValues = Object.keys(withSeeding)
53902
+ .map(function (key) {
53903
+ var accessor = getScaleAccessor(withSeeding[key]);
53904
+ var scaleValue = seedingScales_1[accessor];
53905
+ return [key, scaleValue];
53906
+ })
53907
+ .filter(function (pair) { return pair[1]; })
53908
+ .map(function (pair) {
53909
+ var _a;
53910
+ return (_a = {}, _a[pair[0]] = { seedValue: pair[1] }, _a);
53911
+ });
53912
+ var seedAssignments = Object.assign.apply(Object, __spreadArray([{}], __read(scaleValues), false));
53913
+ participantEvent.seedAssignments = seedAssignments;
53914
+ }
53915
+ else {
53916
+ var _x = participantEvent.category || {}, categoryName = _x.categoryName, ageCategoryCode = _x.ageCategoryCode;
53917
+ var scaleItem = void 0;
53918
+ try {
53919
+ for (var _y = (e_3 = void 0, __values([
53920
+ participantEvent.eventId,
53921
+ ageCategoryCode,
53922
+ categoryName,
53923
+ ])), _z = _y.next(); !_z.done; _z = _y.next()) {
53924
+ var scaleName = _z.value;
53925
+ var scaleAttributes = {
53926
+ eventType: participantEvent.eventType,
53927
+ scaleType: SEEDING$1,
53928
+ scaleName: scaleName,
53929
+ };
53930
+ var result = participantScaleItem({
53931
+ scaleAttributes: scaleAttributes,
53932
+ participant: participant,
53933
+ });
53934
+ if (result.scaleItem) {
53935
+ scaleItem = result.scaleItem;
53936
+ break;
53937
+ }
53938
+ }
53939
+ }
53940
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
53941
+ finally {
53942
+ try {
53943
+ if (_z && !_z.done && (_u = _y.return)) _u.call(_y);
53944
+ }
53945
+ finally { if (e_3) throw e_3.error; }
53946
+ }
53947
+ if (scaleItem) {
53948
+ var seedValue = scaleItem.scaleValue;
53949
+ var seedingPublished = !usePublishState ||
53950
+ ((publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.published) &&
53951
+ (((_h = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _h === void 0 ? void 0 : _h.length) === 0 ||
53952
+ ((_j = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _j === void 0 ? void 0 : _j.includes(participantEvent.drawId))));
53953
+ if (seedingPublished) {
53954
+ participantEvent.seedValue = seedValue;
53955
+ }
53956
+ }
53957
+ }
53958
+ if ((_k = participantEvent.drawIds) === null || _k === void 0 ? void 0 : _k.length) {
53959
+ try {
53960
+ for (var _0 = (e_4 = void 0, __values(participantEvent.drawIds || [])), _1 = _0.next(); !_1.done; _1 = _0.next()) {
53961
+ var flightDrawId = _1.value;
53962
+ var drawSeedPublishingDisabled = ((_l = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _l === void 0 ? void 0 : _l.length) &&
53963
+ !((_m = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _m === void 0 ? void 0 : _m.includes(flightDrawId));
53964
+ if (eventSeedingPublished && !drawSeedPublishingDisabled) {
53965
+ var seedAssignments = getDerivedSeedAssignments({
53966
+ drawId: flightDrawId,
53967
+ derivedDrawInfo: derivedDrawInfo,
53968
+ participantId: participantId,
53969
+ });
53970
+ // preserve filtering of MAIN/QUALIFYING seedValues, if present
53971
+ if (seedAssignments && participantEvent.seedAssignments) {
53972
+ try {
53973
+ for (var _2 = (e_5 = void 0, __values(Object.keys(participantEvent.seedAssignments))), _3 = _2.next(); !_3.done; _3 = _2.next()) {
53974
+ var key = _3.value;
53975
+ participantEvent.seedAssignments[key] = seedAssignments[key];
53976
+ }
53977
+ }
53978
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
53979
+ finally {
53980
+ try {
53981
+ if (_3 && !_3.done && (_w = _2.return)) _w.call(_2);
53982
+ }
53983
+ finally { if (e_5) throw e_5.error; }
53984
+ }
53985
+ }
53986
+ else {
53987
+ participantEvent.seedAssignments = seedAssignments;
53988
+ }
53989
+ }
53990
+ }
53991
+ }
53992
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
53993
+ finally {
53994
+ try {
53995
+ if (_1 && !_1.done && (_v = _0.return)) _v.call(_0);
53996
+ }
53997
+ finally { if (e_4) throw e_4.error; }
53998
+ }
53999
+ }
54000
+ };
54001
+ try {
54002
+ for (var participantEvents_1 = __values(participantEvents), participantEvents_1_1 = participantEvents_1.next(); !participantEvents_1_1.done; participantEvents_1_1 = participantEvents_1.next()) {
54003
+ var participantEvent = participantEvents_1_1.value;
54004
+ _loop_1(participantEvent);
54005
+ }
54006
+ }
54007
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
54008
+ finally {
54009
+ try {
54010
+ if (participantEvents_1_1 && !participantEvents_1_1.done && (_b = participantEvents_1.return)) _b.call(participantEvents_1);
54011
+ }
54012
+ finally { if (e_2) throw e_2.error; }
54013
+ }
54014
+ }
54015
+ }
54016
+ var participantOpponents = Object.values(opponents).flat();
54017
+ if (withOpponents && (participantOpponents === null || participantOpponents === void 0 ? void 0 : participantOpponents.length)) {
54018
+ participant.opponents = participantOpponents;
54019
+ participantDraws === null || participantDraws === void 0 ? void 0 : participantDraws.forEach(function (draw) {
54020
+ draw.opponents = participantOpponents.filter(function (opponent) { return opponent.drawId === draw.drawId; });
54021
+ });
54022
+ }
54023
+ var participantPotentialMatchUps = Object.values(potentialMatchUps);
54024
+ var participantMatchUps = Object.values(matchUps);
54025
+ if (withMatchUps) {
54026
+ participant.potentialMatchUps = participantPotentialMatchUps;
54027
+ participant.matchUps = participantMatchUps;
54028
+ }
54029
+ var allParticipantMatchUps = participantMatchUps.concat(participantPotentialMatchUps);
54030
+ // scheduledMatchUps are a participant's matchUps separated by date and sorted by scheduledTime
54031
+ var scheduledMatchUps = ((_o = participantScheduledMatchUps({
54032
+ matchUps: allParticipantMatchUps,
54033
+ })) === null || _o === void 0 ? void 0 : _o.scheduledMatchUps) || [];
54034
+ var scheduledMinutesDifference = (scheduleAnalysis || {}).scheduledMinutesDifference;
54035
+ var dates = Object.keys(scheduledMatchUps);
54036
+ dates.forEach(function (date) {
54037
+ scheduledMatchUps[date].filter(Boolean).forEach(function (matchUp, i) {
54038
+ var e_6, _a;
54039
+ var _b, _c, _d, _e;
54040
+ var _f = matchUp.schedule, scheduledTime = _f.scheduledTime, timeAfterRecovery = _f.timeAfterRecovery, typeChangeTimeAfterRecovery = _f.typeChangeTimeAfterRecovery, matchUpStatus = matchUp.matchUpStatus, roundPosition = matchUp.roundPosition, structureName = matchUp.structureName, matchUpType = matchUp.matchUpType, roundNumber = matchUp.roundNumber, matchUpId = matchUp.matchUpId, drawId = matchUp.drawId, score = matchUp.score;
54041
+ scheduleItems.push(__assign(__assign({}, matchUp.schedule), { scheduledTime: extractTime((_b = matchUp.schedule) === null || _b === void 0 ? void 0 : _b.scheduledTime), roundPosition: roundPosition, structureName: structureName, matchUpType: matchUpType, roundNumber: roundNumber, matchUpId: matchUpId, drawId: drawId }));
54042
+ // matchUps with { matchUpStatus: BYE } are ignored or { matchUpStatus: WALKOVER } and no score
54043
+ var ignoreMatchUp = matchUpStatus === BYE ||
54044
+ ([WALKOVER$2, DEFAULTED].includes(matchUpStatus) &&
54045
+ !scoreHasValue({ score: score }));
54046
+ if (scheduledTime && !ignoreMatchUp) {
54047
+ var scheduledMinutes = timeStringMinutes(scheduledTime);
54048
+ // each matchUp only considers conflicts with matchUps which occur at the same or later scheduledTime
54049
+ var matchUpsToConsider = scheduledMatchUps[date].slice(i + 1);
54050
+ try {
54051
+ for (var matchUpsToConsider_1 = __values(matchUpsToConsider), matchUpsToConsider_1_1 = matchUpsToConsider_1.next(); !matchUpsToConsider_1_1.done; matchUpsToConsider_1_1 = matchUpsToConsider_1.next()) {
54052
+ var consideredMatchUp = matchUpsToConsider_1_1.value;
54053
+ // ignore { matchUpStatus: BYE } and matchUps which are unscheduled
54054
+ var ignoreMatchUp_1 = consideredMatchUp.matchUpStatus === BYE ||
54055
+ ([WALKOVER$2, DEFAULTED].includes(consideredMatchUp.matchUpStatus) &&
54056
+ !scoreHasValue(consideredMatchUp));
54057
+ if (!ignoreMatchUp_1 && ((_c = consideredMatchUp.schedule) === null || _c === void 0 ? void 0 : _c.scheduledTime)) {
54058
+ // if there is a matchType change (SINGLES => DOUBLES or vice versa) then there is potentially a different timeAfterRecovery
54059
+ var typeChange = matchUp.matchUpType !== consideredMatchUp.matchUpType;
54060
+ var notBeforeTime = typeChange
54061
+ ? typeChangeTimeAfterRecovery || timeAfterRecovery
54062
+ : timeAfterRecovery;
54063
+ // if two matchUps are both potentials and both part of the same draw they cannot be considered in conflict
54064
+ var sameDraw = matchUp.drawId === consideredMatchUp.drawId;
54065
+ var bothPotential = matchUp.potential && consideredMatchUp.potential;
54066
+ var nextMinutes = timeStringMinutes((_d = consideredMatchUp.schedule) === null || _d === void 0 ? void 0 : _d.scheduledTime);
54067
+ var minutesDifference = nextMinutes - scheduledMinutes;
54068
+ // Conflicts can be determined in two ways:
54069
+ // 1. scheduledMinutesDifference - the minutes difference between two scheduledTimes
54070
+ // 2. A scheduledTime occurring before a prior matchUps notBeforeTime (timeAfterRecovery)
54071
+ var timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference)
54072
+ ? minutesDifference <= scheduledMinutesDifference
54073
+ : timeStringMinutes(notBeforeTime) >
54074
+ timeStringMinutes((_e = consideredMatchUp.schedule) === null || _e === void 0 ? void 0 : _e.scheduledTime);
54075
+ // if there is a time overlap capture both the prior matchUpId and the conflicted matchUpId
54076
+ if (timeOverlap && !(bothPotential && sameDraw)) {
54077
+ scheduleConflicts.push({
54078
+ priorScheduledMatchUpId: consideredMatchUp.matchUpId,
54079
+ matchUpIdWithConflict: matchUpId,
54080
+ });
54081
+ }
54082
+ }
54083
+ }
54084
+ }
54085
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
54086
+ finally {
54087
+ try {
54088
+ if (matchUpsToConsider_1_1 && !matchUpsToConsider_1_1.done && (_a = matchUpsToConsider_1.return)) _a.call(matchUpsToConsider_1);
54089
+ }
54090
+ finally { if (e_6) throw e_6.error; }
54091
+ }
54092
+ }
54093
+ });
54094
+ });
54095
+ if (withStatistics)
54096
+ participant.statistics = [winRatioStat];
54097
+ return { scheduleConflicts: scheduleConflicts, scheduleItems: scheduleItems };
54098
+ }
54099
+
54100
+ function getDrawDetails(_a) {
54101
+ var _b;
54102
+ var eventEntries = _a.eventEntries, sortConfig = _a.sortConfig, event = _a.event;
54103
+ var derivedInfo = {};
54104
+ var drawDetails = Object.assign.apply(Object, __spreadArray([{}], __read(((_b = event.drawDefinitions) !== null && _b !== void 0 ? _b : []).map(function (drawDefinition) {
54105
+ var _a;
54106
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
54107
+ var entriesMap = Object.assign.apply(Object, __spreadArray(__spreadArray([{}], __read((eventEntries !== null && eventEntries !== void 0 ? eventEntries : [])
54108
+ .filter(function (entry) { return entry.participantId; })
54109
+ .map(function (entry) {
54110
+ var _a;
54111
+ return (_a = {}, _a[entry.participantId] = entry, _a);
54112
+ })), false), __read(drawDefinition.entries
54113
+ .filter(function (entry) { return entry.participantId; })
54114
+ .map(function (entry) {
54115
+ var _a;
54116
+ return (_a = {}, _a[entry.participantId] = entry, _a);
54117
+ })), false));
54118
+ var drawEntries = Object.values(entriesMap);
54119
+ var mainStructure = (_c = (_b = getDrawStructures({
54120
+ stageSequence: 1,
54121
+ drawDefinition: drawDefinition,
54122
+ stage: MAIN,
54123
+ })) === null || _b === void 0 ? void 0 : _b.structures) === null || _c === void 0 ? void 0 : _c[0];
54124
+ var mainPositionAssignments = mainStructure &&
54125
+ ((_d = getPositionAssignments$1({
54126
+ structure: mainStructure,
54127
+ })) === null || _d === void 0 ? void 0 : _d.positionAssignments);
54128
+ var drawSize = mainPositionAssignments === null || mainPositionAssignments === void 0 ? void 0 : mainPositionAssignments.length;
54129
+ var qualifyingStructure = (_f = (_e = getDrawStructures({
54130
+ stageSequence: 1,
54131
+ stage: QUALIFYING,
54132
+ drawDefinition: drawDefinition,
54133
+ })) === null || _e === void 0 ? void 0 : _e.structures) === null || _f === void 0 ? void 0 : _f[0];
54134
+ var qualifyingPositionAssignments = mainStructure &&
54135
+ ((_g = getPositionAssignments$1({
54136
+ structure: qualifyingStructure,
54137
+ })) === null || _g === void 0 ? void 0 : _g.positionAssignments);
54138
+ var qualifyingDrawSize = qualifyingPositionAssignments === null || qualifyingPositionAssignments === void 0 ? void 0 : qualifyingPositionAssignments.length;
54139
+ var mainSeedAssignments = mainStructure === null || mainStructure === void 0 ? void 0 : mainStructure.seedAssignments;
54140
+ var qualifyingSeedAssignments = qualifyingStructure === null || qualifyingStructure === void 0 ? void 0 : qualifyingStructure.seedAssignments;
54141
+ // used in rankings pipeline.
54142
+ // the structures in which a particpant particpates are ordered
54143
+ // to enable differentiation for Points-per-round and points-per-win
54144
+ var orderedStructureIds = (drawDefinition.structures || [])
54145
+ .sort(function (a, b) { return structureSort(a, b, sortConfig); })
54146
+ .map(function (_a) {
54147
+ var structureId = _a.structureId, structures = _a.structures;
54148
+ return __spreadArray([
54149
+ structureId
54150
+ ], __read((structures || []).map(function (_a) {
54151
+ var structureId = _a.structureId;
54152
+ return structureId;
54153
+ })), false);
54154
+ })
54155
+ .flat(Infinity);
54156
+ var flightNumber = (_k = (_j = (_h = event === null || event === void 0 ? void 0 : event._flightProfile) === null || _h === void 0 ? void 0 : _h.flights) === null || _j === void 0 ? void 0 : _j.find(function (flight) { return flight.drawId === drawDefinition.drawId; })) === null || _k === void 0 ? void 0 : _k.flightNumber;
54157
+ derivedInfo[drawDefinition.drawId] = {
54158
+ qualifyingPositionAssignments: qualifyingPositionAssignments,
54159
+ qualifyingSeedAssignments: qualifyingSeedAssignments,
54160
+ mainPositionAssignments: mainPositionAssignments,
54161
+ mainSeedAssignments: mainSeedAssignments,
54162
+ orderedStructureIds: orderedStructureIds,
54163
+ qualifyingDrawSize: qualifyingDrawSize,
54164
+ flightNumber: flightNumber,
54165
+ drawSize: drawSize,
54166
+ };
54167
+ return _a = {},
54168
+ _a[drawDefinition.drawId] = {
54169
+ drawType: drawDefinition.drawType,
54170
+ drawEntries: drawEntries,
54171
+ },
54172
+ _a;
54173
+ })), false));
54174
+ return { derivedInfo: derivedInfo, drawDetails: drawDetails };
54175
+ }
54176
+
54177
+ function processMatchUp(_a) {
54178
+ var _b;
54179
+ var relevantParticipantIdsMap = _a.relevantParticipantIdsMap, participantFilters = _a.participantFilters, participantIdMap = _a.participantIdMap, derivedDrawInfo = _a.derivedDrawInfo, eventDrawsCount = _a.eventDrawsCount, drawDetails = _a.drawDetails, eventType = _a.eventType, matchUp = _a.matchUp;
54180
+ var collectionId = matchUp.collectionId, collectionPosition = matchUp.collectionPosition, drawId = matchUp.drawId, drawName = matchUp.drawName, eventId = matchUp.eventId, eventName = matchUp.eventName, finishingRound = matchUp.finishingRound, finishingPositionRange = matchUp.finishingPositionRange, processCodes = matchUp.processCodes, loserTo = matchUp.loserTo, matchUpId = matchUp.matchUpId, matchUpType = matchUp.matchUpType, matchUpFormat = matchUp.matchUpFormat, matchUpStatus = matchUp.matchUpStatus, matchUpStatusCodes = matchUp.matchUpStatusCodes, matchUpTieId = matchUp.matchUpTieId, roundName = matchUp.roundName, roundNumber = matchUp.roundNumber, roundPosition = matchUp.roundPosition, score = matchUp.score, sides = matchUp.sides, stage = matchUp.stage, stageSequence = matchUp.stageSequence, schedule = matchUp.schedule, structureName = matchUp.structureName, structureId = matchUp.structureId, tieFormat = matchUp.tieFormat, tieMatchUps = matchUp.tieMatchUps, tournamentId = matchUp.tournamentId, winnerTo = matchUp.winnerTo, winningSide = matchUp.winningSide;
54181
+ var targetParticipantIds = participantFilters === null || participantFilters === void 0 ? void 0 : participantFilters.participantIds;
54182
+ var getRelevantParticipantIds = function (participantId) {
54183
+ var relevantParticipantIds = (participantId && relevantParticipantIdsMap[participantId]) || [];
54184
+ relevantParticipantIds.push(participantId);
54185
+ return relevantParticipantIds.some(function (obj) {
54186
+ return !targetParticipantIds ||
54187
+ targetParticipantIds.includes(obj.relevantParticipantId);
54188
+ })
54189
+ ? relevantParticipantIds
54190
+ : [];
54191
+ };
54192
+ var _c = finishingPositionRange || {}, winner = _c.winner, loser = _c.loser;
54193
+ // doubles participants are not defined in the entries for a draw/event
54194
+ // and can only be determined by interrogating inContext tieMatchUps
54195
+ // because here the pairParticipantIds are derived from collectionAssignments
54196
+ var doublesTieParticipants = ((tieMatchUps === null || tieMatchUps === void 0 ? void 0 : tieMatchUps.length) &&
54197
+ tieMatchUps
54198
+ .filter(function (_a) {
54199
+ var matchUpType = _a.matchUpType;
54200
+ return matchUpType === DOUBLES_MATCHUP;
54201
+ })
54202
+ .map(function (_a) {
54203
+ var sides = _a.sides;
54204
+ return sides.map(function (_a) {
54205
+ var sideNumber = _a.sideNumber, participantId = _a.participantId, participant = _a.participant;
54206
+ return sideNumber &&
54207
+ participantId && {
54208
+ sideNumber: sideNumber,
54209
+ participantId: participantId,
54210
+ participant: participant,
54211
+ };
54212
+ });
54213
+ })
54214
+ .flat()
54215
+ .filter(Boolean)) ||
54216
+ [];
54217
+ if (eventType === TEAM_EVENT && matchUpType === DOUBLES_MATCHUP) {
54218
+ var participants = (((_b = matchUp.sides) === null || _b === void 0 ? void 0 : _b.filter(Boolean)) || [])
54219
+ .map(function (_a) {
54220
+ var sideNumber = _a.sideNumber, participantId = _a.participantId, participant = _a.participant;
54221
+ return sideNumber &&
54222
+ participantId && {
54223
+ sideNumber: sideNumber,
54224
+ participantId: participantId,
54225
+ participant: participant,
54226
+ };
54227
+ })
54228
+ .filter(Boolean);
54229
+ doublesTieParticipants.push.apply(doublesTieParticipants, __spreadArray([], __read(participants), false));
54230
+ }
54231
+ sides === null || sides === void 0 ? void 0 : sides.forEach(function (params) {
54232
+ var participantId = params.participantId, sideNumber = params.sideNumber;
54233
+ if (!participantId)
54234
+ return;
54235
+ var _a = drawDetails[drawId], drawType = _a.drawType, drawEntries = _a.drawEntries;
54236
+ var participantScore = sideNumber === 1 ? score === null || score === void 0 ? void 0 : score.scoreStringSide1 : score === null || score === void 0 ? void 0 : score.scoreStringSide2;
54237
+ var participantWon = winningSide && sideNumber === winningSide;
54238
+ var opponent = matchUp.sides.find(function (side) { return side.sideNumber === 3 - sideNumber; });
54239
+ var opponentParticipantId = opponent === null || opponent === void 0 ? void 0 : opponent.participantId;
54240
+ var relevantOpponents = (opponentParticipantId &&
54241
+ relevantParticipantIdsMap[opponentParticipantId]) ||
54242
+ [];
54243
+ var finishingPositionRange = participantWon ? winner : loser;
54244
+ var drawEntry = drawEntries.find(function (entry) { return entry.participantId === participantId; });
54245
+ // for all matchUps include all individual participants that are part of pairs
54246
+ // this does NOT include PAIR participants in teams, because they are constructed from collectionAssignments
54247
+ // if { eventType: TEAM } then only add relevant PAIR participantIds using doublesTieParticipants
54248
+ // this will avoid adding a pair to all team events in which individuals appear
54249
+ var relevantParticipantIds = getRelevantParticipantIds(participantId);
54250
+ // for TEAM matchUps add all PAIR participants
54251
+ var addedPairParticipantIds = [];
54252
+ doublesTieParticipants === null || doublesTieParticipants === void 0 ? void 0 : doublesTieParticipants.filter(function (participant) { return participant.sideNumber === sideNumber; }).forEach(function (p) {
54253
+ var participantId = p.participantId;
54254
+ if (participantId && !addedPairParticipantIds.includes(participantId)) {
54255
+ relevantParticipantIds.push({
54256
+ relevantParticipantId: participantId,
54257
+ participantType: PAIR,
54258
+ });
54259
+ addedPairParticipantIds.push(participantId);
54260
+ }
54261
+ });
54262
+ var filteredRelevantParticipantIds = relevantParticipantIds.filter(function (opponent) {
54263
+ return (eventType !== TEAM_EVENT ||
54264
+ (eventType === TEAM_EVENT &&
54265
+ [DOUBLES_MATCHUP, TEAM_MATCHUP].includes(matchUpType) &&
54266
+ [PAIR, TEAM_PARTICIPANT].includes(opponent.participantType)) ||
54267
+ (eventType === TEAM_EVENT &&
54268
+ [SINGLES_MATCHUP, DOUBLES_MATCHUP].includes(matchUpType) &&
54269
+ [INDIVIDUAL].includes(opponent.participantType)));
54270
+ });
54271
+ filteredRelevantParticipantIds === null || filteredRelevantParticipantIds === void 0 ? void 0 : filteredRelevantParticipantIds.forEach(function (_a) {
54272
+ var _b, _c;
54273
+ var relevantParticipantId = _a.relevantParticipantId, participantType = _a.participantType;
54274
+ var _d = drawEntry || {}, entryStage = _d.entryStage, entryStatus = _d.entryStatus, entryPosition = _d.entryPosition;
54275
+ if (!participantIdMap[relevantParticipantId])
54276
+ return;
54277
+ if (!participantIdMap[relevantParticipantId].draws[drawId]) {
54278
+ var positionAssignments = getDerivedPositionAssignments({
54279
+ participantId: relevantParticipantId,
54280
+ derivedDrawInfo: derivedDrawInfo,
54281
+ drawId: drawId,
54282
+ });
54283
+ var seedAssignments = getDerivedSeedAssignments({
54284
+ participantId: relevantParticipantId,
54285
+ derivedDrawInfo: derivedDrawInfo,
54286
+ drawId: drawId,
54287
+ });
54288
+ participantIdMap[relevantParticipantId].draws[drawId] =
54289
+ definedAttributes({
54290
+ qualifyingDrawSize: (_b = derivedDrawInfo[drawId]) === null || _b === void 0 ? void 0 : _b.qualifyingDrawSize,
54291
+ drawSize: (_c = derivedDrawInfo[drawId]) === null || _c === void 0 ? void 0 : _c.drawSize,
54292
+ partnerParticipantIds: [],
54293
+ positionAssignments: positionAssignments,
54294
+ seedAssignments: seedAssignments,
54295
+ entryPosition: entryPosition,
54296
+ entryStatus: entryStatus,
54297
+ entryStage: entryStage,
54298
+ drawName: drawName,
54299
+ drawType: drawType,
54300
+ eventId: eventId,
54301
+ drawId: drawId,
54302
+ });
54303
+ }
54304
+ if (!participantIdMap[relevantParticipantId].events[eventId]) {
54305
+ participantIdMap[relevantParticipantId].events[eventId] = {
54306
+ partnerParticipantIds: [],
54307
+ drawIds: [],
54308
+ eventName: eventName,
54309
+ eventId: eventId,
54310
+ };
54311
+ }
54312
+ var eventDrawIds = participantIdMap[relevantParticipantId].events[eventId].drawIds;
54313
+ if (eventDrawIds && !(eventDrawIds === null || eventDrawIds === void 0 ? void 0 : eventDrawIds.includes(drawId))) {
54314
+ participantIdMap[relevantParticipantId].events[eventId].drawIds.push(drawId);
54315
+ }
54316
+ var partnerParticipantId;
54317
+ if (participantType === INDIVIDUAL && matchUpType === DOUBLES_MATCHUP) {
54318
+ var relevantParticipantInfo = filteredRelevantParticipantIds.find(function (participantInfo) {
54319
+ return (participantInfo.relevantParticipantId !==
54320
+ relevantParticipantId &&
54321
+ participantInfo.participantType === INDIVIDUAL);
54322
+ });
54323
+ partnerParticipantId = relevantParticipantInfo === null || relevantParticipantInfo === void 0 ? void 0 : relevantParticipantInfo.relevantParticipantId;
54324
+ }
54325
+ var filteredRelevantOpponents = (relevantOpponents === null || relevantOpponents === void 0 ? void 0 : relevantOpponents.filter(function (opponent) {
54326
+ return (matchUpType === TEAM_MATCHUP &&
54327
+ participantType === TEAM_PARTICIPANT &&
54328
+ opponent.participantType === TEAM_PARTICIPANT) ||
54329
+ (matchUpType === SINGLES_MATCHUP &&
54330
+ opponent.participantType === INDIVIDUAL) ||
54331
+ (matchUpType === DOUBLES_MATCHUP &&
54332
+ (participantType === INDIVIDUAL
54333
+ ? [INDIVIDUAL, PAIR].includes(opponent.participantType)
54334
+ : // for PAIR participants only show PAIR opponenents
54335
+ opponent.participantType === PAIR));
54336
+ })) || [];
54337
+ filteredRelevantOpponents.forEach(function (_a) {
54338
+ var opponentParticipantId = _a.relevantParticipantId, opponentParticipantType = _a.participantType;
54339
+ if (!participantIdMap[relevantParticipantId].opponents) {
54340
+ participantIdMap[relevantParticipantId].opponents = {};
54341
+ }
54342
+ participantIdMap[relevantParticipantId].opponents[opponentParticipantId] = {
54343
+ eventId: eventId,
54344
+ drawId: drawId,
54345
+ matchUpId: matchUpId,
54346
+ participantType: opponentParticipantType,
54347
+ participantId: opponentParticipantId,
54348
+ };
54349
+ });
54350
+ var opponentParticipantInfo = filteredRelevantOpponents.map(function (_a) {
54351
+ var relevantParticipantId = _a.relevantParticipantId, participantType = _a.participantType;
54352
+ return ({
54353
+ participantId: relevantParticipantId,
54354
+ participantType: participantType,
54355
+ });
54356
+ });
54357
+ var includeMatchUp = (matchUpType !== TEAM_MATCHUP &&
54358
+ [INDIVIDUAL, PAIR].includes(participantType)) ||
54359
+ (matchUpType === TEAM_MATCHUP &&
54360
+ participantType === TEAM_PARTICIPANT);
54361
+ if (includeMatchUp)
54362
+ participantIdMap[relevantParticipantId].matchUps[matchUpId] =
54363
+ definedAttributes({
54364
+ collectionId: collectionId,
54365
+ collectionPosition: collectionPosition,
54366
+ drawId: drawId,
54367
+ eventId: eventId,
54368
+ eventType: eventType,
54369
+ eventDrawsCount: eventDrawsCount,
54370
+ finishingRound: finishingRound,
54371
+ finishingPositionRange: finishingPositionRange,
54372
+ loserTo: loserTo,
54373
+ matchUpId: matchUpId,
54374
+ matchUpType: matchUpType,
54375
+ matchUpFormat: matchUpFormat,
54376
+ matchUpStatus: matchUpStatus,
54377
+ matchUpStatusCodes: matchUpStatusCodes,
54378
+ matchUpTieId: matchUpTieId,
54379
+ opponentParticipantInfo: opponentParticipantInfo,
54380
+ participantWon: participantWon,
54381
+ partnerParticipantId: partnerParticipantId,
54382
+ perspectiveScoreString: participantScore,
54383
+ processCodes: processCodes,
54384
+ roundName: roundName,
54385
+ roundNumber: roundNumber,
54386
+ roundPosition: roundPosition,
54387
+ schedule: schedule,
54388
+ score: score,
54389
+ sides: sides,
54390
+ stage: stage,
54391
+ stageSequence: stageSequence,
54392
+ structureName: structureName,
54393
+ structureId: structureId,
54394
+ tieFormat: tieFormat,
54395
+ tournamentId: tournamentId,
54396
+ winnerTo: winnerTo,
54397
+ winningSide: winningSide,
54398
+ });
54399
+ if (partnerParticipantId) {
54400
+ participantIdMap[relevantParticipantId].events[eventId].partnerParticipantIds.push(partnerParticipantId);
54401
+ participantIdMap[relevantParticipantId].draws[drawId].partnerParticipantIds.push(partnerParticipantId);
54402
+ // legacy.... deprecate when ETL updated
54403
+ participantIdMap[relevantParticipantId].events[eventId].partnerParticipantId = partnerParticipantId;
54404
+ participantIdMap[relevantParticipantId].draws[drawId].partnerParticipantId = partnerParticipantId;
54405
+ }
54406
+ if (winningSide) {
54407
+ if (participantWon) {
54408
+ participantIdMap[relevantParticipantId].wins++;
54409
+ }
54410
+ else {
54411
+ participantIdMap[relevantParticipantId].losses++;
54412
+ }
54413
+ }
54414
+ });
54415
+ });
54416
+ if (Array.isArray(matchUp.potentialParticipants)) {
54417
+ var potentialParticipantIds = getParticipantIds(matchUp.potentialParticipants.flat());
54418
+ potentialParticipantIds === null || potentialParticipantIds === void 0 ? void 0 : potentialParticipantIds.forEach(function (participantId) {
54419
+ var relevantParticipantIds = getRelevantParticipantIds(participantId);
54420
+ relevantParticipantIds === null || relevantParticipantIds === void 0 ? void 0 : relevantParticipantIds.forEach(function (_a) {
54421
+ var relevantParticipantId = _a.relevantParticipantId;
54422
+ participantIdMap[relevantParticipantId].potentialMatchUps[matchUpId] =
54423
+ definedAttributes({
54424
+ drawId: drawId,
54425
+ eventId: eventId,
54426
+ eventType: eventType,
54427
+ matchUpId: matchUpId,
54428
+ matchUpType: matchUpType,
54429
+ matchUpFormat: matchUpFormat,
54430
+ roundName: roundName,
54431
+ roundNumber: roundNumber,
54432
+ roundPosition: roundPosition,
54433
+ schedule: schedule,
54434
+ tieFormat: tieFormat,
54435
+ structureName: structureName,
54436
+ tournamentId: tournamentId,
54437
+ potential: true,
54438
+ });
54439
+ });
54440
+ });
54441
+ }
54442
+ }
54443
+
54444
+ function addParticipantContext(params) {
54445
+ var _a, _b;
54446
+ var participantIdsWithConflicts = [];
54447
+ var eventsPublishStatuses = {};
54448
+ var derivedDrawInfo = {};
54449
+ var participantIdMap = {};
54450
+ var initializeParticipantId = function (participantId) {
54451
+ if (!participantIdMap[participantId])
54452
+ participantIdMap[participantId] = {
54453
+ groupParticipantIds: [],
54454
+ teamParticipantIds: [],
54455
+ pairParticipantIds: [],
54456
+ potentialMatchUps: {},
54457
+ scheduleItems: [],
54458
+ opponents: {},
54459
+ matchUps: {},
54460
+ events: {},
54461
+ groups: [],
54462
+ teams: [],
54463
+ draws: {},
54464
+ losses: 0,
54465
+ wins: 0,
54466
+ };
54467
+ };
54468
+ var tournamentRecord = params.tournamentRecord, participantFilters = params.participantFilters, allTournamentParticipants = params.allTournamentParticipants;
54469
+ var relevantParticipantIdsMap = getRelevantParticipantIdsMap({
54470
+ processParticipantId: initializeParticipantId,
54471
+ tournamentRecord: tournamentRecord,
54472
+ }).relevantParticipantIdsMap;
54473
+ // optimize when filtering participants by participantIds
54474
+ // by only returning relevantParticipantIds related to specified participantIds
54475
+ var targetParticipantIds = participantFilters === null || participantFilters === void 0 ? void 0 : participantFilters.participantIds;
54476
+ var getRelevantParticipantIds = function (participantId) {
54477
+ var relevantParticipantIds = (participantId && relevantParticipantIdsMap[participantId]) || [];
54478
+ relevantParticipantIds.push(participantId);
54479
+ return relevantParticipantIds.some(function (obj) {
54480
+ return !targetParticipantIds ||
54481
+ targetParticipantIds.includes(obj.relevantParticipantId);
54482
+ })
54483
+ ? relevantParticipantIds
54484
+ : [];
54485
+ };
54486
+ params.withGroupings &&
54487
+ allTournamentParticipants.forEach(function (participant) {
54488
+ var _a, _b, _c;
54489
+ if (participant.participantType === GROUP) {
54490
+ var groupParticipantId_1 = participant.participantId;
54491
+ (_a = participant === null || participant === void 0 ? void 0 : participant.individualParticipantIds) === null || _a === void 0 ? void 0 : _a.forEach(function (participantId) {
54492
+ if (!participantIdMap[participantId].groupParticipantIds.includes(groupParticipantId_1)) {
54493
+ participantIdMap[participantId].groupParticipantIds.push(groupParticipantId_1);
54494
+ participantIdMap[participantId].groups.push({
54495
+ participantRoleResponsibilities: participant.participantRoleResponsibilities,
54496
+ participantOtherName: participant.participantOtherName,
54497
+ participantName: participant.participantName,
54498
+ participantId: participant.participantId,
54499
+ });
54500
+ }
54501
+ });
54502
+ }
54503
+ if (participant.participantType === TEAM$2) {
54504
+ var teamParticipantId_1 = participant.participantId;
54505
+ (_b = participant === null || participant === void 0 ? void 0 : participant.individualParticipantIds) === null || _b === void 0 ? void 0 : _b.forEach(function (participantId) {
54506
+ var _a, _b, _c, _d;
54507
+ if (!((_b = (_a = participantIdMap[participantId]) === null || _a === void 0 ? void 0 : _a.teamParticipantIds) === null || _b === void 0 ? void 0 : _b.includes(teamParticipantId_1))) {
54508
+ (_c = participantIdMap[participantId]) === null || _c === void 0 ? void 0 : _c.teamParticipantIds.push(teamParticipantId_1);
54509
+ (_d = participantIdMap[participantId]) === null || _d === void 0 ? void 0 : _d.teams.push({
54510
+ participantRoleResponsibilities: participant.participantRoleResponsibilities,
54511
+ participantOtherName: participant.participantOtherName,
54512
+ participantName: participant.participantName,
54513
+ participantId: participant.participantId,
54514
+ teamId: participant.teamId,
54515
+ });
54516
+ }
54517
+ });
54518
+ }
54519
+ if (participant.participantType === PAIR) {
54520
+ var pairParticipantId_1 = participant.participantId;
54521
+ (_c = participant === null || participant === void 0 ? void 0 : participant.individualParticipantIds) === null || _c === void 0 ? void 0 : _c.forEach(function (participantId) {
54522
+ if (participantIdMap[participantId] &&
54523
+ !participantIdMap[participantId].pairParticipantIds.includes(pairParticipantId_1)) {
54524
+ participantIdMap[participantId].pairParticipantIds.push(pairParticipantId_1);
54525
+ }
54526
+ });
54527
+ }
54528
+ });
54529
+ if (params.withMatchUps) {
54530
+ getMatchUpDependencies({ tournamentRecord: tournamentRecord }); // ensure that goesTos exist
54531
+ }
54532
+ if (params.withScheduleItems ||
54533
+ params.scheduleAnalysis ||
54534
+ params.withStatistics ||
54535
+ params.withOpponents ||
54536
+ params.withMatchUps ||
54537
+ params.withSeeding ||
54538
+ params.withEvents ||
54539
+ params.withDraws) {
54540
+ // loop through all filtered events and capture events played
54541
+ (_a = params.tournamentEvents) === null || _a === void 0 ? void 0 : _a.forEach(function (rawEvent) {
54542
+ var _a, _b, _c, _d, _e, _f, _g;
54543
+ var event = makeDeepCopy(rawEvent, true, true);
54544
+ var flightProfile = getFlightProfile({ event: event }).flightProfile;
54545
+ var eventDrawsCount = ((_a = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _a === void 0 ? void 0 : _a.length) || ((_b = event.drawDefinitions) === null || _b === void 0 ? void 0 : _b.length) || 0;
54546
+ (event.drawDefinitions || []).forEach(function (drawDefinition, i) {
54547
+ if ((event === null || event === void 0 ? void 0 : event.eventType) === TEAM$2) {
54548
+ // add back lineUps extension for team resolution when { matchUpType: TEAM } is missing side.lineUps
54549
+ var extension = findExtension$2({
54550
+ element: rawEvent.drawDefinitions[i],
54551
+ name: LINEUPS,
54552
+ }).extension;
54553
+ if (extension)
54554
+ drawDefinition.extensions = [extension];
54555
+ }
54556
+ });
54557
+ var eventId = event.eventId, eventName = event.eventName, eventType = event.eventType, category = event.category;
54558
+ var eventInfo = { eventId: eventId, eventName: eventName, eventType: eventType, category: category };
54559
+ var extensionKeys = event && Object.keys(event).filter(function (key) { return key.startsWith('_'); });
54560
+ extensionKeys === null || extensionKeys === void 0 ? void 0 : extensionKeys.forEach(function (extensionKey) { return (eventInfo[extensionKey] = event[extensionKey]); });
54561
+ var eventEntries = event.entries || [];
54562
+ var itemType = "".concat(PUBLISH, ".").concat(STATUS$1);
54563
+ var timeItem = getEventTimeItem({
54564
+ itemType: itemType,
54565
+ event: event,
54566
+ }).timeItem;
54567
+ if ((_c = timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemValue) === null || _c === void 0 ? void 0 : _c.PUBLIC) {
54568
+ var _h = timeItem.itemValue.PUBLIC || {}, _j = _h.drawIds, publishedDrawIds = _j === void 0 ? [] : _j, seeding = _h.seeding;
54569
+ var publishedSeeding = {
54570
+ published: undefined,
54571
+ seedingScaleNames: [],
54572
+ drawIds: [], // seeding can be specific to drawIds
54573
+ };
54574
+ if (seeding)
54575
+ Object.assign(publishedSeeding, timeItem.itemValue.PUBLIC.seeding);
54576
+ eventsPublishStatuses[eventId] = {
54577
+ publishedDrawIds: publishedDrawIds,
54578
+ publishedSeeding: publishedSeeding,
54579
+ };
54580
+ }
54581
+ // don't allow system extensions to be copied to participants
54582
+ var disallowedConstants = __spreadArray([], __read(Object.values(extensionConstants)), false);
54583
+ var disallowedKeys = disallowedConstants.map(function (constant) { return "_".concat(constant); });
54584
+ var filteredEventInfo = eventInfo &&
54585
+ Object.keys(eventInfo)
54586
+ .filter(function (key) { return !disallowedKeys.includes(key); })
54587
+ .reduce(function (obj, key) {
54588
+ obj[key] = eventInfo[key];
54589
+ return obj;
54590
+ }, {});
54591
+ eventEntries === null || eventEntries === void 0 ? void 0 : eventEntries.filter(function (entry) { return entry === null || entry === void 0 ? void 0 : entry.participantId; }).forEach(function (entry) {
54592
+ var participantId = entry.participantId, entryStage = entry.entryStage, entryStatus = entry.entryStatus, entryPosition = entry.entryPosition;
54593
+ // include all individual participants that are part of teams & pairs
54594
+ // relevantParticipantId is a reference to an individual
54595
+ var relevantParticipantIds = getRelevantParticipantIds(participantId);
54596
+ relevantParticipantIds === null || relevantParticipantIds === void 0 ? void 0 : relevantParticipantIds.forEach(function (_a) {
54597
+ var relevantParticipantId = _a.relevantParticipantId;
54598
+ if (!participantIdMap[relevantParticipantId])
54599
+ initializeParticipantId(relevantParticipantId);
54600
+ participantIdMap[relevantParticipantId].events[eventId] = __assign(__assign({}, filteredEventInfo), { partnerParticipantIds: [], entryPosition: entryPosition, entryStatus: entryStatus, entryStage: entryStage, drawIds: [], eventId: eventId });
54601
+ });
54602
+ });
54603
+ var addDrawData = function (_a) {
54604
+ var drawEntry = _a.drawEntry, drawId = _a.drawId;
54605
+ var participantId = drawEntry.participantId, entryStage = drawEntry.entryStage, entryStatus = drawEntry.entryStatus, entryPosition = drawEntry.entryPosition;
54606
+ var relevantParticipantIds = getRelevantParticipantIds(participantId);
54607
+ relevantParticipantIds === null || relevantParticipantIds === void 0 ? void 0 : relevantParticipantIds.forEach(function (_a) {
54608
+ var _b, _c;
54609
+ var relevantParticipantId = _a.relevantParticipantId;
54610
+ if (!participantIdMap[relevantParticipantId].events[eventId]) {
54611
+ participantIdMap[relevantParticipantId].events[eventId] = __assign(__assign({}, filteredEventInfo), { partnerParticipantIds: [], entryPosition: entryPosition, entryStatus: entryStatus, entryStage: entryStage, drawIds: [], eventId: eventId });
54612
+ }
54613
+ if (!participantIdMap[relevantParticipantId].draws[drawId]) {
54614
+ var positionAssignments = getDerivedPositionAssignments({
54615
+ participantId: relevantParticipantId,
54616
+ derivedDrawInfo: derivedDrawInfo,
54617
+ drawId: drawId,
54618
+ });
54619
+ var seedAssignments = getDerivedSeedAssignments({
54620
+ participantId: relevantParticipantId,
54621
+ derivedDrawInfo: derivedDrawInfo,
54622
+ drawId: drawId,
54623
+ });
54624
+ participantIdMap[relevantParticipantId].draws[drawId] =
54625
+ definedAttributes({
54626
+ qualifyingDrawSize: (_b = derivedDrawInfo[drawId]) === null || _b === void 0 ? void 0 : _b.qualifyingDrawSize,
54627
+ drawSize: (_c = derivedDrawInfo[drawId]) === null || _c === void 0 ? void 0 : _c.drawSize,
54628
+ partnerParticipantIds: [],
54629
+ positionAssignments: positionAssignments,
54630
+ eventDrawsCount: eventDrawsCount,
54631
+ seedAssignments: seedAssignments,
54632
+ entryPosition: entryPosition,
54633
+ entryStatus: entryStatus,
54634
+ entryStage: entryStage,
54635
+ eventId: eventId,
54636
+ drawId: drawId,
54637
+ });
54638
+ }
54639
+ var eventDrawIds = participantIdMap[relevantParticipantId].events[eventId].drawIds;
54640
+ if (eventDrawIds && !(eventDrawIds === null || eventDrawIds === void 0 ? void 0 : eventDrawIds.includes(drawId))) {
54641
+ participantIdMap[relevantParticipantId].events[eventId].drawIds.push(drawId);
54642
+ }
54643
+ });
54644
+ };
54645
+ // iterate through flights to ensure that draw entries are captured if drawDefinitions have not yet been generated
54646
+ var drawIdsWithDefinitions = ((_d = event.drawDefinitions) === null || _d === void 0 ? void 0 : _d.map(function (_a) {
54647
+ var drawId = _a.drawId;
54648
+ return drawId;
54649
+ })) || [];
54650
+ (_f = (_e = eventInfo._flightProfile) === null || _e === void 0 ? void 0 : _e.flights) === null || _f === void 0 ? void 0 : _f.forEach(function (flight) {
54651
+ var drawId = flight.drawId, drawEntries = flight.drawEntries;
54652
+ if (!drawIdsWithDefinitions.includes(drawId)) {
54653
+ drawEntries === null || drawEntries === void 0 ? void 0 : drawEntries.forEach(function (drawEntry) {
54654
+ return addDrawData({ drawEntry: drawEntry, drawId: drawId });
54655
+ });
54656
+ }
54657
+ });
54658
+ var _k = getDrawDetails({
54659
+ eventEntries: eventEntries,
54660
+ event: event,
54661
+ }), drawDetails = _k.drawDetails, derivedInfo = _k.derivedInfo;
54662
+ Object.assign(derivedDrawInfo, derivedInfo);
54663
+ if (event.eventType === TEAM$2 || // for TEAM events some individual attributes can only be derived by processing
54664
+ params.withScheduleItems ||
54665
+ params.scheduleAnalysis ||
54666
+ params.withStatistics ||
54667
+ params.withOpponents ||
54668
+ params.withMatchUps ||
54669
+ params.withDraws) {
54670
+ var matchUps = (_g = allEventMatchUps({
54671
+ afterRecoveryTimes: params.scheduleAnalysis,
54672
+ participants: allTournamentParticipants,
54673
+ nextMatchUps: true,
54674
+ tournamentRecord: tournamentRecord,
54675
+ inContext: true,
54676
+ event: event,
54677
+ })) === null || _g === void 0 ? void 0 : _g.matchUps;
54678
+ matchUps === null || matchUps === void 0 ? void 0 : matchUps.forEach(function (matchUp) {
54679
+ return processMatchUp({
54680
+ relevantParticipantIdsMap: relevantParticipantIdsMap,
54681
+ participantFilters: participantFilters,
54682
+ participantIdMap: participantIdMap,
54683
+ derivedDrawInfo: derivedDrawInfo,
54684
+ eventDrawsCount: eventDrawsCount,
54685
+ drawDetails: drawDetails,
54686
+ eventType: eventType,
54687
+ matchUp: matchUp,
54688
+ });
54689
+ });
54690
+ }
54691
+ });
54692
+ }
54693
+ // tournamentParticipants is an array of FILTERED participants
54694
+ (_b = params.tournamentParticipants) === null || _b === void 0 ? void 0 : _b.forEach(function (participant) {
54695
+ var _a = annotateParticipant(__assign(__assign({}, params), { eventsPublishStatuses: eventsPublishStatuses, participantIdMap: participantIdMap, derivedDrawInfo: derivedDrawInfo, participant: participant })), scheduleConflicts = _a.scheduleConflicts, scheduleItems = _a.scheduleItems;
54696
+ if (params.withSignInStatus) {
54697
+ var timeItem = getTimeItem({
54698
+ itemType: SIGN_IN_STATUS,
54699
+ element: participant,
54700
+ }).timeItem;
54701
+ participant.signedIn = (timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemValue) === SIGNED_IN;
54702
+ }
54703
+ if (params.withScheduleItems) {
54704
+ participant.scheduleItems = scheduleItems;
54460
54705
  }
54461
- }
54462
- else {
54463
- try {
54464
- for (var _e = __values(Object.values(value)), _f = _e.next(); !_f.done; _f = _e.next()) {
54465
- var m = _f.value;
54466
- if (m.matchUpId) {
54467
- keyedMatchUps[m.matchUpId] = deepCopyOption ? makeDeepCopy(m) : m;
54468
- if (!matchUpId)
54469
- matchUpId = m.matchUpId;
54470
- }
54706
+ if (params.scheduleAnalysis) {
54707
+ participant.scheduleConflicts = scheduleConflicts;
54708
+ if ((scheduleConflicts === null || scheduleConflicts === void 0 ? void 0 : scheduleConflicts.length) &&
54709
+ !participantIdsWithConflicts.includes(participant.participantId)) {
54710
+ participantIdsWithConflicts.push(participant.participantId);
54471
54711
  }
54472
54712
  }
54473
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
54474
- finally {
54475
- try {
54476
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
54477
- }
54478
- finally { if (e_2) throw e_2.error; }
54713
+ if (params.withGroupings !== false) {
54714
+ var participantAttributes = participantIdMap[participant.participantId];
54715
+ participant.groupParticipantIds =
54716
+ participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.groupParticipantIds;
54717
+ participant.pairParticipantIds =
54718
+ participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.pairParticipantIds;
54719
+ participant.teamParticipantIds =
54720
+ participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.teamParticipantIds;
54721
+ participant.groups = participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.groups;
54722
+ participant.teams = participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.teams;
54479
54723
  }
54480
- }
54481
- return deepCopyOption ? makeDeepCopy(value) : value;
54482
- }
54483
- function getMatchUp() {
54484
- return keyedMatchUps[matchUpId];
54485
- }
54486
- function getMatchUps() {
54487
- return Object.values(keyedMatchUps);
54488
- }
54489
- function reset() {
54490
- matchUpId = undefined;
54491
- keyedMatchUps = {};
54492
- }
54493
- function getState$2(params) {
54494
- return makeDeepCopy(keyedMatchUps[matchUpId], params === null || params === void 0 ? void 0 : params.convertExtensions, false, params === null || params === void 0 ? void 0 : params.removeExtensions);
54724
+ if (params.withTeamMatchUps) ;
54725
+ });
54726
+ return { participantIdsWithConflicts: participantIdsWithConflicts, eventsPublishStatuses: eventsPublishStatuses };
54495
54727
  }
54496
54728
 
54497
- var matchUpEngine = (function () {
54498
- var engine = {
54499
- getState: function (params) { return getState$2(params); },
54500
- version: function () { return factoryVersion(); },
54501
- reset: function () {
54502
- reset();
54503
- return __assign({}, SUCCESS);
54504
- },
54505
- drawId: undefined,
54506
- error: undefined,
54507
- success: false,
54508
- devContext: function (contextCriteria) {
54509
- setDevContext(contextCriteria);
54510
- return engine;
54511
- },
54512
- setState: function (definition, deepCopyOption, deepCopyAttributes) {
54513
- setDeepCopy(deepCopyOption, deepCopyAttributes);
54514
- var result = setState$2(definition);
54515
- return processResult(result);
54516
- },
54517
- };
54518
- function processResult(result) {
54519
- if (result === null || result === void 0 ? void 0 : result.error) {
54520
- engine.error = result.error;
54521
- engine.success = false;
54522
- }
54523
- else {
54524
- engine.error = undefined;
54525
- engine.success = true;
54526
- engine.drawId = result.drawId;
54527
- }
54528
- return engine;
54529
- }
54530
- importGovernors([
54531
- tieFormatGovernor,
54532
- historyGovernor,
54533
- queryGovernor$1,
54534
- scoreGovernor,
54535
- ]);
54536
- return engine;
54537
- function importGovernors(governors) {
54538
- governors.forEach(function (governor) {
54539
- Object.keys(governor).forEach(function (methodName) {
54540
- engine[methodName] = function (params) {
54541
- if (getDevContext()) {
54542
- return invoke({ params: params, governor: governor, methodName: methodName });
54543
- }
54544
- else {
54545
- try {
54546
- return invoke({ params: params, governor: governor, methodName: methodName });
54729
+ /**
54730
+ * Returns deepCopies of tournament participants filtered by participantFilters which are arrays of desired participant attribute values
54731
+ *
54732
+ * @param {object} tournamentRecord - tournament object (passed automatically from tournamentEngine state)
54733
+ * @param {object} participantFilters - attribute arrays with filter value strings
54734
+ * @param {boolean} inContext - adds individualParticipants for all individualParticipantIds
54735
+ * @param {boolean} withDraws - include all matchUps in which participant appears
54736
+ * @param {boolean} withEvents - include all events in which participant appears
54737
+ * @param {boolean} withMatchUps - include all matchUps in which participant appears
54738
+ * @param {boolean} withStatistics - adds events: { [eventId]: eventName }, matchUps: { [matchUpId]: score }, statistics: [{ statCode: 'winRatio'}]
54739
+ * @param {boolean} withScheduleItems - include schedule items; scheduled matchUps
54740
+ * @param {boolean} scheduleAnalysis - analysis of conflicts
54741
+ * @param {boolean} withGroupings - include teams and groups and pairs in which individual participants appear
54742
+ * @param {boolean} withOpponents - include opponent participantIds
54743
+ * @param {boolean} usePublishState - when hydrating participants consider publish state (currently applies to seeding)
54744
+ *
54745
+ */
54746
+ function getTournamentParticipants(params) {
54747
+ var _a = params.participantFilters, participantFilters = _a === void 0 ? {} : _a, convertExtensions = params.convertExtensions, policyDefinitions = params.policyDefinitions, withScheduleItems = params.withScheduleItems, scheduleAnalysis = params.scheduleAnalysis, withSignInStatus = params.withSignInStatus, withTeamMatchUps = params.withTeamMatchUps, // not implemented
54748
+ tournamentRecord = params.tournamentRecord, usePublishState = params.usePublishState, withScaleValues = params.withScaleValues, withStatistics = params.withStatistics, withGroupings = params.withGroupings, withOpponents = params.withOpponents, withMatchUps = params.withMatchUps, withSeeding = params.withSeeding, withEvents = params.withEvents, withDraws = params.withDraws, inContext = params.inContext, withISO2 = params.withISO2, withIOC = params.withIOC;
54749
+ if (!tournamentRecord)
54750
+ return { error: MISSING_TOURNAMENT_RECORD };
54751
+ if (!tournamentRecord.participants)
54752
+ return { error: MISSING_PARTICIPANTS };
54753
+ var allTournamentParticipants = tournamentRecord.participants.map(
54754
+ // (participant) => makeDeepCopy(participant, convertExtensions, true)
54755
+ function (participant) { return makeDeepCopy(participant, convertExtensions); } // removed until Mongo/Mongoose issues resolved
54756
+ );
54757
+ if (typeof participantFilters !== 'object')
54758
+ return { error: INVALID_OBJECT, participantFilters: participantFilters };
54759
+ if (inContext) {
54760
+ allTournamentParticipants === null || allTournamentParticipants === void 0 ? void 0 : allTournamentParticipants.forEach(function (participant) {
54761
+ var _a;
54762
+ if ([PAIR, TEAM, GROUP].includes(participant.participantType)) {
54763
+ participant.individualParticipants =
54764
+ (_a = participant.individualParticipantIds) === null || _a === void 0 ? void 0 : _a.map(function (participantId) {
54765
+ var targetParticipant = tournamentRecord.participants.find(function (p) { return p.participantId === participantId; });
54766
+ var individualParticipant = makeDeepCopy(targetParticipant, convertExtensions, true);
54767
+ // individualParticipants only need to be hydrated withScaleValues and nationalityCode variations
54768
+ if (withScaleValues) {
54769
+ var _a = getScaleValues({
54770
+ participant: individualParticipant,
54771
+ }), ratings = _a.ratings, rankings = _a.rankings;
54772
+ individualParticipant.ratings = ratings;
54773
+ individualParticipant.rankings = rankings;
54547
54774
  }
54548
- catch (err) {
54549
- handleCaughtError({
54550
- engineName: 'matchUpEngine',
54551
- methodName: methodName,
54552
- params: params,
54553
- err: err,
54775
+ if (withIOC || withISO2)
54776
+ addNationalityCode({
54777
+ participant: individualParticipant,
54778
+ withISO2: withISO2,
54779
+ withIOC: withIOC,
54554
54780
  });
54555
- }
54556
- }
54557
- };
54558
- });
54781
+ return individualParticipant;
54782
+ });
54783
+ }
54559
54784
  });
54560
54785
  }
54561
- function invoke(_a) {
54562
- var params = _a.params, governor = _a.governor, methodName = _a.methodName;
54563
- engine.error = undefined;
54564
- engine.success = false;
54565
- var matchUp = (params === null || params === void 0 ? void 0 : params.matchUp) || getMatchUp();
54566
- var matchUps = (params === null || params === void 0 ? void 0 : params.matchUps) || getMatchUps();
54567
- var snapshot = (params === null || params === void 0 ? void 0 : params.rollbackOnError) && makeDeepCopy(matchUp, false, true);
54568
- params = __assign(__assign({}, params), { matchUpId: matchUp === null || matchUp === void 0 ? void 0 : matchUp.matchUpId, matchUps: matchUps, matchUp: matchUp });
54569
- var result = governor[methodName](params);
54570
- if (result === null || result === void 0 ? void 0 : result.error) {
54571
- if (snapshot)
54572
- setState$2(snapshot);
54573
- return __assign(__assign({}, result), { rolledBack: !!snapshot });
54574
- }
54575
- var notify = (result === null || result === void 0 ? void 0 : result.success) &&
54576
- (params === null || params === void 0 ? void 0 : params.delayNotify) !== true &&
54577
- (params === null || params === void 0 ? void 0 : params.doNotNotify) !== true;
54578
- if (notify)
54579
- notifySubscribers();
54580
- if (notify || !(result === null || result === void 0 ? void 0 : result.success) || (params === null || params === void 0 ? void 0 : params.doNotNotify))
54581
- deleteNotices();
54582
- return result;
54583
- }
54584
- })();
54585
-
54586
- function matchUpEngineAsync(test) {
54587
- var result = createInstanceState();
54588
- if (result.error && !test)
54589
- return result;
54590
- var engine = {
54591
- getState: function (params) { return getState$2(params); },
54592
- version: function () { return factoryVersion(); },
54593
- reset: function () {
54594
- reset();
54595
- return __assign({}, SUCCESS);
54596
- },
54597
- drawId: undefined,
54598
- error: undefined,
54599
- success: false,
54600
- devContext: function (contextCriteria) {
54601
- setDevContext(contextCriteria);
54602
- return engine;
54603
- },
54604
- setState: function (definition, deepCopyOption, deepCopyAttributes) {
54605
- setDeepCopy(deepCopyOption, deepCopyAttributes);
54606
- var result = setState$2(definition);
54607
- return processResult(result);
54608
- },
54609
- };
54610
- function processResult(result) {
54611
- if (result === null || result === void 0 ? void 0 : result.error) {
54612
- engine.error = result.error;
54613
- engine.success = false;
54614
- }
54615
- else {
54616
- engine.error = undefined;
54617
- engine.success = true;
54618
- engine.drawId = result.drawId;
54619
- }
54620
- return engine;
54621
- }
54622
- importGovernors([
54623
- tieFormatGovernor,
54624
- historyGovernor,
54625
- queryGovernor$1,
54626
- scoreGovernor,
54627
- ]);
54628
- return engine;
54629
- function importGovernors(governors) {
54630
- return __awaiter(this, void 0, void 0, function () {
54631
- var _loop_1, governors_1, governors_1_1, governor;
54632
- var e_1, _a;
54633
- var _this = this;
54634
- return __generator(this, function (_b) {
54635
- _loop_1 = function (governor) {
54636
- var e_2, _c;
54637
- var governorMethods = Object.keys(governor);
54638
- var _loop_2 = function (methodName) {
54639
- engine[methodName] = function (params) { return __awaiter(_this, void 0, void 0, function () {
54640
- var err_1;
54641
- return __generator(this, function (_a) {
54642
- switch (_a.label) {
54643
- case 0:
54644
- if (!getDevContext()) return [3 /*break*/, 2];
54645
- return [4 /*yield*/, invoke({ params: params, governor: governor, methodName: methodName })];
54646
- case 1: return [2 /*return*/, _a.sent()];
54647
- case 2:
54648
- _a.trys.push([2, 4, , 5]);
54649
- return [4 /*yield*/, invoke({ params: params, governor: governor, methodName: methodName })];
54650
- case 3: return [2 /*return*/, _a.sent()];
54651
- case 4:
54652
- err_1 = _a.sent();
54653
- handleCaughtError({
54654
- engineName: 'matchUpEngine',
54655
- methodName: methodName,
54656
- params: params,
54657
- err: err_1,
54658
- });
54659
- return [3 /*break*/, 5];
54660
- case 5: return [2 /*return*/];
54661
- }
54662
- });
54663
- }); };
54664
- };
54665
- try {
54666
- for (var governorMethods_1 = (e_2 = void 0, __values(governorMethods)), governorMethods_1_1 = governorMethods_1.next(); !governorMethods_1_1.done; governorMethods_1_1 = governorMethods_1.next()) {
54667
- var methodName = governorMethods_1_1.value;
54668
- _loop_2(methodName);
54669
- }
54670
- }
54671
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
54672
- finally {
54673
- try {
54674
- if (governorMethods_1_1 && !governorMethods_1_1.done && (_c = governorMethods_1.return)) _c.call(governorMethods_1);
54675
- }
54676
- finally { if (e_2) throw e_2.error; }
54677
- }
54678
- };
54679
- try {
54680
- for (governors_1 = __values(governors), governors_1_1 = governors_1.next(); !governors_1_1.done; governors_1_1 = governors_1.next()) {
54681
- governor = governors_1_1.value;
54682
- _loop_1(governor);
54683
- }
54684
- }
54685
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
54686
- finally {
54687
- try {
54688
- if (governors_1_1 && !governors_1_1.done && (_a = governors_1.return)) _a.call(governors_1);
54689
- }
54690
- finally { if (e_1) throw e_1.error; }
54691
- }
54692
- return [2 /*return*/];
54693
- });
54786
+ var tournamentParticipants = participantFilters
54787
+ ? filterParticipants({
54788
+ participants: allTournamentParticipants,
54789
+ participantFilters: participantFilters,
54790
+ tournamentRecord: tournamentRecord,
54791
+ })
54792
+ : allTournamentParticipants;
54793
+ var participantIdsWithConflicts, eventsPublishStatuses;
54794
+ var addContext = withScheduleItems ||
54795
+ withSignInStatus ||
54796
+ scheduleAnalysis ||
54797
+ withScaleValues ||
54798
+ withStatistics ||
54799
+ withGroupings ||
54800
+ withOpponents ||
54801
+ withMatchUps ||
54802
+ withSeeding ||
54803
+ withEvents ||
54804
+ withDraws ||
54805
+ withISO2 ||
54806
+ withIOC;
54807
+ if (addContext) {
54808
+ var result = addParticipantContext({
54809
+ tournamentEvents: tournamentRecord.events,
54810
+ allTournamentParticipants: allTournamentParticipants,
54811
+ tournamentParticipants: tournamentParticipants,
54812
+ participantFilters: participantFilters,
54813
+ withScheduleItems: withScheduleItems,
54814
+ withSignInStatus: withSignInStatus,
54815
+ tournamentRecord: tournamentRecord,
54816
+ scheduleAnalysis: scheduleAnalysis,
54817
+ withTeamMatchUps: withTeamMatchUps,
54818
+ usePublishState: usePublishState,
54819
+ withScaleValues: withScaleValues,
54820
+ withStatistics: withStatistics,
54821
+ withGroupings: withGroupings,
54822
+ withOpponents: withOpponents,
54823
+ withMatchUps: withMatchUps,
54824
+ withSeeding: withSeeding,
54825
+ withEvents: withEvents,
54826
+ withDraws: withDraws,
54827
+ withISO2: withISO2,
54828
+ withIOC: withIOC,
54694
54829
  });
54830
+ participantIdsWithConflicts = result === null || result === void 0 ? void 0 : result.participantIdsWithConflicts;
54831
+ eventsPublishStatuses = result === null || result === void 0 ? void 0 : result.eventsPublishStatuses;
54695
54832
  }
54696
- function invoke(_a) {
54697
- var params = _a.params, governor = _a.governor, methodName = _a.methodName;
54698
- return __awaiter(this, void 0, void 0, function () {
54699
- var matchUp, matchUps, snapshot, result, notify;
54700
- return __generator(this, function (_b) {
54701
- switch (_b.label) {
54702
- case 0:
54703
- engine.success = false;
54704
- engine.error = undefined;
54705
- matchUp = (params === null || params === void 0 ? void 0 : params.matchUp) || getMatchUp();
54706
- matchUps = (params === null || params === void 0 ? void 0 : params.matchUps) || getMatchUps();
54707
- snapshot = (params === null || params === void 0 ? void 0 : params.rollbackOnError) && makeDeepCopy(matchUp, false, true);
54708
- params = __assign(__assign({}, params), { matchUpId: matchUp === null || matchUp === void 0 ? void 0 : matchUp.matchUpId, matchUps: matchUps, matchUp: matchUp });
54709
- result = governor[methodName](params);
54710
- if (result === null || result === void 0 ? void 0 : result.error) {
54711
- if (snapshot)
54712
- setState$2(snapshot);
54713
- return [2 /*return*/, __assign(__assign({}, result), { rolledBack: !!snapshot })];
54714
- }
54715
- notify = (result === null || result === void 0 ? void 0 : result.success) &&
54716
- (params === null || params === void 0 ? void 0 : params.delayNotify) !== true &&
54717
- (params === null || params === void 0 ? void 0 : params.doNotNotify) !== true;
54718
- if (!notify) return [3 /*break*/, 2];
54719
- return [4 /*yield*/, notifySubscribersAsync()];
54720
- case 1:
54721
- _b.sent();
54722
- _b.label = 2;
54723
- case 2:
54724
- if (notify || !(result === null || result === void 0 ? void 0 : result.success) || (params === null || params === void 0 ? void 0 : params.doNotNotify))
54725
- deleteNotices();
54726
- return [2 /*return*/, result];
54727
- }
54833
+ var participantAttributes = policyDefinitions === null || policyDefinitions === void 0 ? void 0 : policyDefinitions[POLICY_TYPE_PARTICIPANT];
54834
+ if (participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.participant) {
54835
+ tournamentParticipants = tournamentParticipants.map(function (participant) {
54836
+ return attributeFilter({
54837
+ template: participantAttributes.participant,
54838
+ source: participant,
54728
54839
  });
54729
54840
  });
54730
54841
  }
54731
- }
54732
-
54733
- function newTournamentRecord(params) {
54734
- var attributes = params || {};
54735
- if (!attributes.tournamentId)
54736
- attributes.tournamentId = UUID();
54737
- if (attributes.startDate &&
54738
- !isISODateString(attributes.startDate) &&
54739
- !validDateString.test(attributes.startDate)) {
54740
- return { error: INVALID_DATE };
54741
- }
54742
- if (attributes.endDate &&
54743
- !isISODateString(attributes.endDate) &&
54744
- !validDateString.test(attributes.endDate)) {
54745
- return { error: INVALID_DATE };
54746
- }
54747
- if (attributes.extensions) {
54748
- attributes.extensions = attributes.extensions.filter(isValidExtension);
54749
- }
54750
- return __assign({}, attributes);
54751
- }
54752
-
54753
- function setState$1(tournament, deepCopyOption) {
54754
- var _a;
54755
- var _b;
54756
- if (typeof tournament !== 'object')
54757
- return { error: INVALID_OBJECT };
54758
- var tournamentId = ((_b = tournament.unifiedTournamentId) === null || _b === void 0 ? void 0 : _b.tournamentId) || tournament.tournamentId;
54759
- if (!tournamentId)
54760
- return { error: MISSING_TOURNAMENT_ID };
54761
- var tournamentRecord = deepCopyOption !== false ? makeDeepCopy(tournament) : tournament;
54762
- setTournamentRecords((_a = {}, _a[tournamentId] = tournamentRecord, _a));
54763
- setTournamentId(tournamentId); // must be set AFTER tournamentRecord
54764
- return tournamentRecord;
54765
- }
54766
- function getState$1(_a) {
54767
- var _b = _a.convertExtensions, convertExtensions = _b === void 0 ? false : _b, _c = _a.removeExtensions, removeExtensions = _c === void 0 ? false : _c, tournamentId = _a.tournamentId;
54768
- if (typeof tournamentId !== 'string')
54769
- return {};
54770
- var tournamentRecord = getTournamentRecord(tournamentId);
54771
54842
  return {
54772
- tournamentRecord: makeDeepCopy(tournamentRecord, convertExtensions, false, removeExtensions),
54843
+ participantIdsWithConflicts: participantIdsWithConflicts,
54844
+ tournamentParticipants: tournamentParticipants,
54845
+ eventsPublishStatuses: eventsPublishStatuses,
54773
54846
  };
54774
54847
  }
54775
- // prefetch can be triggered based on method governor, e.g. not necessary for query
54776
- function paramsMiddleware$1(tournamentRecord, params, prefetch) {
54777
- var _a;
54778
- if (params) {
54779
- var drawId = params.drawId || ((_a = params.matchUp) === null || _a === void 0 ? void 0 : _a.drawId);
54780
- if (drawId) {
54781
- var _b = findEvent({
54782
- tournamentRecord: tournamentRecord,
54783
- drawId: drawId,
54784
- }), event_1 = _b.event, drawDefinition = _b.drawDefinition;
54785
- params = __assign(__assign({}, params), { event: event_1, drawDefinition: drawDefinition });
54786
- if (prefetch) {
54787
- var matchUpsMap = getMatchUpsMap({ drawDefinition: drawDefinition });
54788
- var inContextDrawMatchUps = getAllDrawMatchUps({
54789
- inContext: true,
54790
- drawDefinition: drawDefinition,
54791
- matchUpsMap: matchUpsMap,
54792
- }).matchUps;
54793
- params.matchUpsMap = matchUpsMap;
54794
- params.inContextDrawMatchUps = inContextDrawMatchUps;
54795
- }
54796
- }
54797
- if (params.eventId && !params.event) {
54798
- var event_2 = findEvent({
54799
- eventId: params.eventId,
54800
- tournamentRecord: tournamentRecord,
54801
- }).event;
54802
- if (event_2) {
54803
- params = __assign(__assign({}, params), { event: event_2 });
54804
- }
54805
- }
54806
- }
54807
- return params;
54808
- }
54809
-
54810
- function getEligibleVoluntaryConsolationParticipants(params) {
54811
- if (!params.tournamentRecord)
54812
- return { error: MISSING_TOURNAMENT_RECORD };
54813
- return getEligibleVoluntaryConsolationParticipants$1(params);
54814
- }
54815
-
54816
- function getParticipantEventDetails(_a) {
54817
- var tournamentRecord = _a.tournamentRecord, participantId = _a.participantId;
54818
- if (!tournamentRecord)
54819
- return { error: MISSING_TOURNAMENT_RECORD };
54820
- if (!participantId)
54821
- return { error: MISSING_PARTICIPANT_ID };
54822
- // relveantParticipantIds is the target participantId along with any TEAM or PAIR participantIds to which participantId belongs
54823
- var relevantParticipantIds = [participantId].concat((tournamentRecord.participants || [])
54824
- .filter(function (participant) {
54825
- var _a;
54826
- return (participant === null || participant === void 0 ? void 0 : participant.participantType) &&
54827
- [TEAM, PAIR].includes(participant.participantType) &&
54828
- ((_a = participant.individualParticipantIds) === null || _a === void 0 ? void 0 : _a.includes(participantId));
54829
- })
54830
- .map(function (participant) { return participant.participantId; }));
54831
- var relevantEvents = (tournamentRecord.events || [])
54832
- .filter(function (event) {
54833
- var enteredParticipantIds = ((event === null || event === void 0 ? void 0 : event.entries) || []).map(function (entry) { return entry.participantId; });
54834
- return overlap(enteredParticipantIds, relevantParticipantIds);
54835
- })
54836
- .map(function (event) { return ({ eventName: event.eventName, eventId: event.eventId }); });
54837
- return { eventDetails: relevantEvents };
54838
- }
54839
54848
 
54840
54849
  function getParticipantMembership(_a) {
54841
54850
  var tournamentRecord = _a.tournamentRecord, participantId = _a.participantId;
@@ -58593,7 +58602,7 @@ function setTournamentCategories(_a) {
58593
58602
  // bulk update when tournament dates change
58594
58603
  function updateCourtAvailability(_a) {
58595
58604
  var e_1, _b, e_2, _c;
58596
- var _d;
58605
+ var _d, _e;
58597
58606
  var tournamentRecord = _a.tournamentRecord;
58598
58607
  if (!tournamentRecord)
58599
58608
  return { error: MISSING_TOURNAMENT_RECORD };
@@ -58601,8 +58610,8 @@ function updateCourtAvailability(_a) {
58601
58610
  var tournamentDates = dateRange(startDate, endDate);
58602
58611
  var courts = [];
58603
58612
  try {
58604
- for (var _e = __values(tournamentRecord.venues || []), _f = _e.next(); !_f.done; _f = _e.next()) {
58605
- var venue = _f.value;
58613
+ for (var _f = __values(tournamentRecord.venues || []), _g = _f.next(); !_g.done; _g = _f.next()) {
58614
+ var venue = _g.value;
58606
58615
  if ((_d = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _d === void 0 ? void 0 : _d.length)
58607
58616
  courts.push.apply(courts, __spreadArray([], __read(venue.courts), false));
58608
58617
  }
@@ -58610,12 +58619,12 @@ function updateCourtAvailability(_a) {
58610
58619
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
58611
58620
  finally {
58612
58621
  try {
58613
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
58622
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
58614
58623
  }
58615
58624
  finally { if (e_1) throw e_1.error; }
58616
58625
  }
58617
58626
  var _loop_1 = function (court) {
58618
- var _g = (court.dateAvailability || []).reduce(function (extents, availability) {
58627
+ var _h = (court.dateAvailability || []).reduce(function (extents, availability) {
58619
58628
  var startMinutes = timeStringMinutes(extents.startTime);
58620
58629
  var endMinutes = timeStringMinutes(extents.endTime);
58621
58630
  if (availability.startTime &&
@@ -58625,12 +58634,15 @@ function updateCourtAvailability(_a) {
58625
58634
  timeStringMinutes(availability.endTime) > endMinutes)
58626
58635
  extents.endTime = availability.endTime;
58627
58636
  return extents;
58628
- }, { startTime: '08:00', endTime: '18:00' }), startTime = _g.startTime, endTime = _g.endTime;
58637
+ }, { startTime: '08:00', endTime: '18:00' }), startTime = _h.startTime, endTime = _h.endTime;
58629
58638
  var updatedDateAvailability = tournamentDates.map(function (date) {
58630
58639
  var _a;
58631
58640
  var existing = (_a = court.dateAvailability) === null || _a === void 0 ? void 0 : _a.find(function (availability) { return availability.date === date; });
58632
58641
  return existing || { date: date, startTime: startTime, endTime: endTime };
58633
58642
  });
58643
+ var defaultAvailability = (_e = court.dateAvailability) === null || _e === void 0 ? void 0 : _e.find(function (availability) { return !availability.date; });
58644
+ if (defaultAvailability)
58645
+ updatedDateAvailability.unshift(defaultAvailability);
58634
58646
  court.dateAvailability = updatedDateAvailability;
58635
58647
  };
58636
58648
  try {
@@ -58696,12 +58708,10 @@ function setTournamentDates(_a) {
58696
58708
  });
58697
58709
  return __assign(__assign({}, SUCCESS), { unscheduledMatchUpIds: unscheduledMatchUpIds });
58698
58710
  }
58699
- // TODO: check all courts in all venues for dateAvailability that is outside of tournament date range
58700
58711
  function setTournamentStartDate(_a) {
58701
58712
  var tournamentRecord = _a.tournamentRecord, startDate = _a.startDate;
58702
58713
  return setTournamentDates({ tournamentRecord: tournamentRecord, startDate: startDate });
58703
58714
  }
58704
- // TODO: check all courts in all venues for dateAvailability that is outside of tournament date range
58705
58715
  function setTournamentEndDate(_a) {
58706
58716
  var tournamentRecord = _a.tournamentRecord, endDate = _a.endDate;
58707
58717
  return setTournamentDates({ tournamentRecord: tournamentRecord, endDate: endDate });
@@ -63923,7 +63933,8 @@ function generateDrawDefinition(params) {
63923
63933
  drawDefinition.links = [];
63924
63934
  drawDefinition.links.push(link);
63925
63935
  }
63926
- drawDefinition.drawName = (_24 = params.drawName) !== null && _24 !== void 0 ? _24 : drawType;
63936
+ drawDefinition.drawName =
63937
+ (_24 = params.drawName) !== null && _24 !== void 0 ? _24 : (drawType && constantToString(drawType));
63927
63938
  if (typeof voluntaryConsolation === 'object') {
63928
63939
  addVoluntaryConsolationStructure(__assign(__assign({}, voluntaryConsolation), { tournamentRecord: tournamentRecord, appliedPolicies: appliedPolicies, drawDefinition: drawDefinition, matchUpType: matchUpType }));
63929
63940
  }