tods-competition-factory 1.8.9 → 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.
@@ -1185,10 +1185,6 @@ var INVALID_SCALE_ITEM = {
1185
1185
  message: 'Invalid scaleItem',
1186
1186
  code: 'ERR_INVALID_SCALE_ITEM',
1187
1187
  };
1188
- var SCALE_ITEM_NOT_FOUND = {
1189
- message: 'No scaleItem found',
1190
- code: 'ERR_NOT_FOUND_SCALE_ITEM',
1191
- };
1192
1188
  var MODIFICATIONS_FAILED = {
1193
1189
  message: 'Modifications failed',
1194
1190
  code: 'ERR_FAILURE_MODIFICATIONS',
@@ -1446,7 +1442,6 @@ var errorConditionConstants = {
1446
1442
  PENALTY_NOT_FOUND: PENALTY_NOT_FOUND,
1447
1443
  POLICY_NOT_ATTACHED: POLICY_NOT_ATTACHED,
1448
1444
  POLICY_NOT_FOUND: POLICY_NOT_FOUND,
1449
- SCALE_ITEM_NOT_FOUND: SCALE_ITEM_NOT_FOUND,
1450
1445
  SCHEDULE_NOT_CLEARED: SCHEDULE_NOT_CLEARED,
1451
1446
  SCHEDULED_MATCHUPS: SCHEDULED_MATCHUPS,
1452
1447
  SEEDSCOUNT_GREATER_THAN_DRAW_SIZE: SEEDSCOUNT_GREATER_THAN_DRAW_SIZE,
@@ -2903,7 +2898,7 @@ var matchUpFormatCode = {
2903
2898
  };
2904
2899
 
2905
2900
  function factoryVersion() {
2906
- return '1.8.9';
2901
+ return '1.8.11';
2907
2902
  }
2908
2903
 
2909
2904
  function getObjectTieFormat(obj) {
@@ -5640,7 +5635,7 @@ function getPolicyDefinitions(_a) {
5640
5635
  }
5641
5636
  return Object.keys(policyDefinitions).length
5642
5637
  ? { policyDefinitions: policyDefinitions }
5643
- : { error: POLICY_NOT_FOUND };
5638
+ : { info: POLICY_NOT_FOUND.message };
5644
5639
  }
5645
5640
 
5646
5641
  var WALKOVER$1 = 'WALKOVER';
@@ -5755,7 +5750,7 @@ function findPolicy(_a) {
5755
5750
  }).appliedPolicies;
5756
5751
  return (appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[policyType])
5757
5752
  ? { policy: appliedPolicies[policyType] }
5758
- : { error: POLICY_NOT_FOUND };
5753
+ : { info: POLICY_NOT_FOUND === null || POLICY_NOT_FOUND === void 0 ? void 0 : POLICY_NOT_FOUND.message };
5759
5754
  }
5760
5755
 
5761
5756
  function getMatchUpCompetitiveProfile(_a) {
@@ -11384,7 +11379,7 @@ function getDrawMatchUps(params) {
11384
11379
  event: event,
11385
11380
  });
11386
11381
  }
11387
- // getTournamentParticipants() calls getDrawMatchUps()
11382
+ // getParticipants() calls allEventMatchUps()
11388
11383
  // ...so participants must be sourced directly from tournamentRecord
11389
11384
  // ...and groupings must be added independent of that
11390
11385
  if (!(tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.length) && tournamentRecord) {
@@ -16705,7 +16700,7 @@ var WHEELCHAIR = 'WHEELCHAIR';
16705
16700
  /**
16706
16701
  *
16707
16702
  */
16708
- var POLICY_SCHEDULING_USTA = (_a$9 = {},
16703
+ var POLICY_SCHEDULING_DEFAULT = (_a$9 = {},
16709
16704
  _a$9[POLICY_TYPE_SCHEDULING] = {
16710
16705
  defaultTimes: {
16711
16706
  averageTimes: [{ categoryNames: [], minutes: { default: 90 } }],
@@ -17045,7 +17040,7 @@ var policies = {
17045
17040
  POLICY_POSITION_ACTIONS_UNRESTRICTED: POLICY_POSITION_ACTIONS_UNRESTRICTED,
17046
17041
  POLICY_PRIVACY_DEFAULT: POLICY_PRIVACY_DEFAULT,
17047
17042
  POLICY_ROUND_NAMING_DEFAULT: POLICY_ROUND_NAMING_DEFAULT,
17048
- POLICY_SCHEDULING_USTA: POLICY_SCHEDULING_USTA,
17043
+ POLICY_SCHEDULING_DEFAULT: POLICY_SCHEDULING_DEFAULT,
17049
17044
  POLICY_SCORING_DEFAULT: POLICY_SCORING_DEFAULT,
17050
17045
  POLICY_SCORING_USTA: POLICY_SCORING_USTA,
17051
17046
  POLICY_SEEDING_ITF: POLICY_SEEDING_ITF,
@@ -28898,7 +28893,7 @@ function participantScaleItem(_a) {
28898
28893
  return { error: INVALID_VALUES };
28899
28894
  if (!participant.timeItems)
28900
28895
  participant.timeItems = [];
28901
- if (participant && Array.isArray(participant.timeItems)) {
28896
+ if (Array.isArray(participant.timeItems)) {
28902
28897
  var accessor = scaleAttributes.accessor, scaleType = scaleAttributes.scaleType, eventType = scaleAttributes.eventType, scaleName = scaleAttributes.scaleName;
28903
28898
  var filterType_1 = [SCALE$1, scaleType, eventType, scaleName].join('.');
28904
28899
  var filteredTimeItems = participant.timeItems
@@ -28922,13 +28917,10 @@ function participantScaleItem(_a) {
28922
28917
  scaleName: scaleName_1,
28923
28918
  scaleType: scaleType_1,
28924
28919
  };
28925
- return { scaleItem: scaleItem };
28926
- }
28927
- else {
28928
- return { error: SCALE_ITEM_NOT_FOUND };
28920
+ return __assign(__assign({}, SUCCESS), { scaleItem: scaleItem });
28929
28921
  }
28930
28922
  }
28931
- return { error: MISSING_PARTICIPANT };
28923
+ return __assign(__assign({}, SUCCESS), { scaleItem: undefined });
28932
28924
  }
28933
28925
 
28934
28926
  function getEventSeedAssignments(_a) {
@@ -29116,7 +29108,7 @@ function addStructureParticipation(_a) {
29116
29108
  function processSides(params) {
29117
29109
  var e_1, _a;
29118
29110
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
29119
- 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;
29120
29112
  var opponents = withOpponents &&
29121
29113
  (sides === null || sides === void 0 ? void 0 : sides.length) === 2 && Object.assign.apply(Object, __spreadArray([{}], __read(sides
29122
29114
  .map(function (_a, i) {
@@ -29210,7 +29202,7 @@ function processSides(params) {
29210
29202
  stage: stage,
29211
29203
  });
29212
29204
  }
29213
- if (scheduleAnalysis || withScheduleTimes) {
29205
+ if (scheduleAnalysis || withScheduleItems) {
29214
29206
  addScheduleItem({
29215
29207
  participantMap: participantMap,
29216
29208
  participantId: participantId,
@@ -29357,9 +29349,7 @@ function processSides(params) {
29357
29349
  function getParticipantEntries(params) {
29358
29350
  var e_1, _a, e_2, _b;
29359
29351
  var _c, _d, _e, _f, _g, _h;
29360
- 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, withScheduleTimes = params.withScheduleTimes, 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;
29361
- if (withScheduleItems)
29362
- console.log({ withScheduleItems: withScheduleItems });
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;
29363
29353
  var targetParticipantIds = participantFilters === null || participantFilters === void 0 ? void 0 : participantFilters.participantIds;
29364
29354
  var getRelevantParticipantIds = function (participantId) {
29365
29355
  var _a, _b;
@@ -29381,7 +29371,7 @@ function getParticipantEntries(params) {
29381
29371
  withDraws: withDraws || withRankingProfile,
29382
29372
  withPotentialMatchUps: withPotentialMatchUps,
29383
29373
  withRankingProfile: withRankingProfile,
29384
- withScheduleTimes: withScheduleTimes,
29374
+ withScheduleItems: withScheduleItems,
29385
29375
  scheduleAnalysis: scheduleAnalysis,
29386
29376
  withTeamMatchUps: withTeamMatchUps,
29387
29377
  withStatistics: withStatistics,
@@ -29742,7 +29732,7 @@ function getParticipantEntries(params) {
29742
29732
  finally { if (e_7) throw e_7.error; }
29743
29733
  }
29744
29734
  if (Array.isArray(potentialParticipants) &&
29745
- (nextMatchUps || !!scheduleAnalysis || withScheduleTimes)) {
29735
+ (nextMatchUps || !!scheduleAnalysis || withScheduleItems)) {
29746
29736
  var potentialParticipantIds = potentialParticipants
29747
29737
  .flat()
29748
29738
  .map(extractAttributes('participantId'))
@@ -29760,7 +29750,7 @@ function getParticipantEntries(params) {
29760
29750
  drawId: drawId,
29761
29751
  });
29762
29752
  });
29763
- if (!!scheduleAnalysis || withScheduleTimes) {
29753
+ if (!!scheduleAnalysis || withScheduleItems) {
29764
29754
  addScheduleItem({
29765
29755
  potential: true,
29766
29756
  participantMap: participantMap,
@@ -29924,20 +29914,22 @@ function getParticipantEntries(params) {
29924
29914
  var sameDraw = scheduleItem.drawId === consideredItem.drawId;
29925
29915
  var bothPotential = potentialMatchUps[scheduleItem.matchUpId] &&
29926
29916
  potentialMatchUps[consideredItem.matchUpId];
29927
- var nextMinutes = timeStringMinutes(consideredItem.scheduledTime);
29928
- var minutesDifference = Math.abs(nextMinutes - scheduledMinutes);
29917
+ var consideredMinutes = timeStringMinutes(consideredItem.scheduledTime);
29918
+ var minutesDifference = Math.abs(consideredMinutes - scheduledMinutes);
29919
+ var itemIsPrior = consideredMinutes > scheduledMinutes;
29929
29920
  // Conflicts can be determined in two ways:
29930
29921
  // 1. scheduledMinutesDifference - the minutes difference between two scheduledTimes
29931
29922
  // 2. A scheduledTime occurring before a prior matchUps notBeforeTime (timeAfterRecovery)
29932
29923
  var timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference)
29933
29924
  ? minutesDifference <= scheduledMinutesDifference
29934
- : timeStringMinutes(notBeforeTime) >
29935
- timeStringMinutes(consideredItem.scheduledTime);
29925
+ : itemIsPrior &&
29926
+ timeStringMinutes(consideredItem.scheduledTime) <
29927
+ timeStringMinutes(notBeforeTime);
29936
29928
  // if there is a time overlap capture both the prior matchUpId and the conflicted matchUpId
29937
- if (timeOverlap && !(bothPotential && sameDraw)) {
29929
+ if (timeOverlap && !(bothPotential && sameDraw) && itemIsPrior) {
29938
29930
  participantAggregator.scheduleConflicts.push({
29939
- priorScheduledMatchUpId: consideredItem.matchUpId,
29940
- matchUpIdWithConflict: scheduleItem.matchUpId,
29931
+ priorScheduledMatchUpId: scheduleItem.matchUpId,
29932
+ matchUpIdWithConflict: consideredItem.matchUpId,
29941
29933
  });
29942
29934
  }
29943
29935
  }
@@ -30204,7 +30196,7 @@ function getParticipants$1(params) {
30204
30196
  participantMap = entriesResult.participantMap;
30205
30197
  var nextMatchUps = scheduleAnalysis !== null && scheduleAnalysis !== void 0 ? scheduleAnalysis : withPotentialMatchUps;
30206
30198
  var processedParticipants = Object.values(participantMap).map(function (_a) {
30207
- 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;
30208
30200
  var participantDraws = Object.values(draws);
30209
30201
  var participantOpponents = Object.values(opponents);
30210
30202
  if (withOpponents) {
@@ -30218,7 +30210,7 @@ function getParticipants$1(params) {
30218
30210
  ? Object.values(matchUps)
30219
30211
  : undefined, opponents: withOpponents ? participantOpponents : undefined, potentialMatchUps: nextMatchUps
30220
30212
  ? Object.values(potentialMatchUps)
30221
- : 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);
30222
30214
  });
30223
30215
  var participantAttributes = policyDefinitions === null || policyDefinitions === void 0 ? void 0 : policyDefinitions[POLICY_TYPE_PARTICIPANT];
30224
30216
  var template = participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.participant;
@@ -30238,1573 +30230,400 @@ function getParticipants$1(params) {
30238
30230
  return __assign(__assign({ participantIdsWithConflicts: participantIdsWithConflicts, eventsPublishStatuses: eventsPublishStatuses, derivedEventInfo: derivedEventInfo, derivedDrawInfo: derivedDrawInfo, mappedMatchUps: mappedMatchUps, participantMap: participantMap, participants: participants }, SUCCESS), { matchUps: matchUps });
30239
30231
  }
30240
30232
 
30241
- function getDerivedPositionAssignments(_a) {
30242
- var _b, _c, _d, _e;
30243
- var derivedDrawInfo = _a.derivedDrawInfo, participantId = _a.participantId, drawId = _a.drawId;
30244
- 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; });
30245
- 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; });
30246
- var positionAssignments = {};
30247
- if (mainPositionAssignment) {
30248
- var participantId_1 = mainPositionAssignment.participantId, props = __rest(mainPositionAssignment, ["participantId"]);
30249
- if (participantId_1)
30250
- positionAssignments[MAIN] = __assign({}, props);
30251
- }
30252
- if (qualifyingPositionAssignment) {
30253
- var participantId_2 = qualifyingPositionAssignment.participantId, props = __rest(qualifyingPositionAssignment, ["participantId"]);
30254
- if (participantId_2)
30255
- positionAssignments[QUALIFYING] = __assign({}, props);
30256
- }
30257
- return Object.keys(positionAssignments).length
30258
- ? positionAssignments
30259
- : undefined;
30260
- }
30261
-
30262
- function getRelevantParticipantIdsMap(_a) {
30263
- var processParticipantId = _a.processParticipantId, // optional method which is passed each participantId
30264
- tournamentRecords = _a.tournamentRecords, tournamentRecord = _a.tournamentRecord;
30265
- if (typeof tournamentRecord !== 'object' &&
30266
- typeof tournamentRecords !== 'object')
30267
- return { error: MISSING_TOURNAMENT_RECORD };
30268
- // build up a mapping of all participantIds to all of the individualParticipantIds that they reference
30269
- // this map includes the key participantId as a value of the array of relevantParticipantIds
30270
- var allParticipants = tournamentRecords
30271
- ? Object.values(tournamentRecords)
30272
- .map(function (tournamentRecord) { return (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || []; })
30273
- .flat()
30274
- : (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
30275
- var relevantParticipantIdsMap = Object.assign.apply(Object, __spreadArray([{}], __read(allParticipants.map(function (_a) {
30276
- var _b;
30277
- var participantId = _a.participantId, participantType = _a.participantType, individualParticipantIds = _a.individualParticipantIds;
30278
- typeof processParticipantId === 'function' &&
30279
- processParticipantId(participantId);
30280
- var individualParticipantIdObjects = (individualParticipantIds || []).map(function (relevantParticipantId) { return ({
30281
- participantType: INDIVIDUAL,
30282
- relevantParticipantId: relevantParticipantId,
30283
- }); });
30284
- return _b = {},
30285
- _b[participantId] = individualParticipantIdObjects.concat({
30286
- relevantParticipantId: participantId,
30287
- participantType: participantType,
30288
- }),
30289
- _b;
30290
- })), false));
30291
- return { relevantParticipantIdsMap: relevantParticipantIdsMap };
30292
- }
30293
-
30294
- function getDerivedSeedAssignments(_a) {
30295
- var _b, _c, _d, _e;
30296
- var derivedDrawInfo = _a.derivedDrawInfo, participantId = _a.participantId, drawId = _a.drawId;
30297
- 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; });
30298
- 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; });
30299
- var seedAssignments = {};
30300
- if (mainSeedAssignment) {
30301
- var participantId_1 = mainSeedAssignment.participantId, props = __rest(mainSeedAssignment, ["participantId"]);
30302
- if (participantId_1)
30303
- seedAssignments[MAIN] = __assign({}, props);
30304
- }
30305
- if (qualifyingSeedAssignment) {
30306
- var participantId_2 = qualifyingSeedAssignment.participantId, props = __rest(qualifyingSeedAssignment, ["participantId"]);
30307
- if (participantId_2)
30308
- seedAssignments[QUALIFYING] = __assign({}, props);
30309
- }
30310
- return Object.keys(seedAssignments).length ? seedAssignments : undefined;
30311
- }
30312
-
30313
- var hasSchedule = function (_a) {
30314
- var _b = _a.scheduleAttributes, scheduleAttributes = _b === void 0 ? ['scheduledDate', 'scheduledTime'] : _b, _c = _a.schedule, schedule = _c === void 0 ? {} : _c;
30315
- var matchUpScheduleKeys = Object.keys(schedule)
30316
- .filter(function (key) { return scheduleAttributes.includes(key); })
30317
- .filter(function (key) { return schedule[key]; });
30318
- return !!matchUpScheduleKeys.length;
30319
- };
30320
-
30321
- function participantScheduledMatchUps(_a) {
30322
- var _b = _a.scheduleAttributes, scheduleAttributes = _b === void 0 ? ['scheduledDate', 'scheduledTime'] : _b, _c = _a.matchUps, matchUps = _c === void 0 ? [] : _c;
30323
- if (!validMatchUps(matchUps))
30324
- return { error: MISSING_MATCHUPS };
30325
- if (!Array.isArray(scheduleAttributes))
30326
- return { error: INVALID_VALUES };
30327
- var scheduledMatchUps = matchUps
30328
- .filter(Boolean)
30329
- .filter(function (_a) {
30330
- var schedule = _a.schedule;
30331
- return hasSchedule({ schedule: schedule, scheduleAttributes: scheduleAttributes });
30332
- })
30333
- .reduce(function (dateMatchUps, matchUp) {
30334
- var schedule = matchUp.schedule;
30335
- var date = extractDate(schedule === null || schedule === void 0 ? void 0 : schedule.scheduledDate);
30336
- var time = extractTime(schedule === null || schedule === void 0 ? void 0 : schedule.scheduledTime);
30337
- if (date && time) {
30338
- if (dateMatchUps[date]) {
30339
- 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;
30340
30259
  }
30341
30260
  else {
30342
- dateMatchUps[date] = [matchUp];
30261
+ // default is to overwrite existing array with incoming
30262
+ merged[key] = incoming[key];
30343
30263
  }
30344
30264
  }
30345
- 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;
30346
30272
  }, {});
30347
- // sort all date matchUps
30348
- var dates = Object.keys(scheduledMatchUps);
30349
- dates.forEach(function (date) {
30350
- scheduledMatchUps[date].sort(function (a, b) {
30351
- var _a, _b;
30352
- 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));
30353
- });
30354
- });
30355
- return { scheduledMatchUps: scheduledMatchUps };
30356
30273
  }
30357
30274
 
30358
- function annotateParticipant(params) {
30359
- var e_1, _a, e_2, _b;
30360
- var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
30361
- 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;
30362
- var scheduleConflicts = [];
30363
- var scheduleItems = [];
30364
- if (withIOC || withISO2)
30365
- addNationalityCode({ participant: participant, withIOC: withIOC, withISO2: withISO2 });
30366
- if (withScaleValues) {
30367
- var _s = getScaleValues({ participant: participant }), ratings = _s.ratings, rankings = _s.rankings;
30368
- participant.rankings = rankings;
30369
- 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 };
30370
30281
  }
30371
- var participantId = participant === null || participant === void 0 ? void 0 : participant.participantId;
30372
- if (!participantId || !participantIdMap[participantId])
30373
- return {};
30374
- 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;
30375
- var denominator = wins + losses;
30376
- var numerator = wins;
30377
- var statValue = denominator && numerator / denominator;
30378
- var winRatioStat = {
30379
- statCode: WIN_RATIO$1,
30380
- denominator: denominator,
30381
- numerator: numerator,
30382
- statValue: statValue,
30383
- };
30384
- var participantDraws = Object.values(draws);
30385
- var participantEvents = Object.values(events);
30386
- if (withDraws && participantDraws) {
30387
- participant.draws = participantDraws;
30388
- try {
30389
- for (var participantDraws_1 = __values(participantDraws), participantDraws_1_1 = participantDraws_1.next(); !participantDraws_1_1.done; participantDraws_1_1 = participantDraws_1.next()) {
30390
- var participantDraw = participantDraws_1_1.value;
30391
- var publishedSeeding = (_c = eventsPublishStatuses[participantDraw.eventId]) === null || _c === void 0 ? void 0 : _c.publishedSeeding;
30392
- var seedingPublished = !usePublishState ||
30393
- ((publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.published) &&
30394
- (((_d = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _d === void 0 ? void 0 : _d.length) === 0 ||
30395
- ((_e = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _e === void 0 ? void 0 : _e.includes(participantDraw.drawId))));
30396
- if (seedingPublished) {
30397
- var seedAssignments = getDerivedSeedAssignments({
30398
- drawId: participantDraw.drawId,
30399
- derivedDrawInfo: derivedDrawInfo,
30400
- participantId: participantId,
30401
- });
30402
- if (seedAssignments) {
30403
- participantDraw.seedAssignments = seedAssignments;
30404
- }
30405
- }
30406
- }
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
+ });
30407
30303
  }
30408
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
30409
- finally {
30410
- try {
30411
- if (participantDraws_1_1 && !participantDraws_1_1.done && (_a = participantDraws_1.return)) _a.call(participantDraws_1);
30412
- }
30413
- 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);
30414
30309
  }
30310
+ finally { if (e_1) throw e_1.error; }
30415
30311
  }
30416
- if (withEvents && participantEvents) {
30417
- participant.events = participantEvents;
30418
- if (withSeeding) {
30419
- var seedingScales_1 = Object.assign.apply(Object, __spreadArray([{}], __read((participant.timeItems || [])
30420
- .filter(function (_a) {
30421
- var itemType = _a.itemType;
30422
- return itemType.split('.')[1] === SEEDING$1;
30423
- })
30424
- .map(function (_a) {
30425
- var _b;
30426
- var seedingScaleName = _a.itemType, seedValue = _a.itemValue;
30427
- return (_b = {},
30428
- _b[seedingScaleName] = seedValue,
30429
- _b);
30430
- })), false));
30431
- var _loop_1 = function (participantEvent) {
30432
- var e_3, _u, e_4, _v, e_5, _w;
30433
- var getScaleAccessor = function (scaleName) {
30434
- return [SCALE$1, SEEDING$1, participantEvent.eventType, scaleName].join('.');
30435
- };
30436
- var publishedSeeding = (_f = eventsPublishStatuses[participantEvent.eventId]) === null || _f === void 0 ? void 0 : _f.publishedSeeding;
30437
- var eventSeedingScaleNames = (((publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.stageSeedingScaleNames) &&
30438
- Object.values(publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.stageSeedingScaleNames)) ||
30439
- (Array.isArray(publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.seedingScaleNames) &&
30440
- publishedSeeding.seedingScaleNames) ||
30441
- []).map(getScaleAccessor);
30442
- var publishedEventSeedingScaleNames = intersection(Object.keys(seedingScales_1), eventSeedingScaleNames);
30443
- var eventSeedingPublished = !!(!usePublishState ||
30444
- (!Object.keys(seedingScales_1).length &&
30445
- !((_g = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _g === void 0 ? void 0 : _g.length)) ||
30446
- publishedEventSeedingScaleNames.length);
30447
- if (eventSeedingPublished && publishedEventSeedingScaleNames.length) {
30448
- if (publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.stageSeedingScaleNames) {
30449
- var scaleValues = Object.keys(publishedSeeding.stageSeedingScaleNames)
30450
- .map(function (key) {
30451
- var accessor = getScaleAccessor(publishedSeeding.stageSeedingScaleNames[key]);
30452
- var scaleValue = seedingScales_1[accessor];
30453
- return [key, scaleValue];
30454
- })
30455
- .filter(function (pair) { return pair[1]; })
30456
- .map(function (pair) {
30457
- var _a;
30458
- return (_a = {}, _a[pair[0]] = { seedValue: pair[1] }, _a);
30459
- });
30460
- var seedAssignments = Object.assign.apply(Object, __spreadArray([{}], __read(scaleValues), false));
30461
- participantEvent.seedAssignments = seedAssignments;
30462
- }
30463
- else if (publishedEventSeedingScaleNames) {
30464
- var seedValues = publishedEventSeedingScaleNames.map(function (scaleName) { return seedingScales_1[scaleName]; });
30465
- participantEvent.seedValue = seedValues.pop();
30466
- }
30467
- }
30468
- else if (!usePublishState && typeof withSeeding === 'object') {
30469
- var scaleValues = Object.keys(withSeeding)
30470
- .map(function (key) {
30471
- var accessor = getScaleAccessor(withSeeding[key]);
30472
- var scaleValue = seedingScales_1[accessor];
30473
- return [key, scaleValue];
30474
- })
30475
- .filter(function (pair) { return pair[1]; })
30476
- .map(function (pair) {
30477
- var _a;
30478
- return (_a = {}, _a[pair[0]] = { seedValue: pair[1] }, _a);
30479
- });
30480
- var seedAssignments = Object.assign.apply(Object, __spreadArray([{}], __read(scaleValues), false));
30481
- 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);
30482
30335
  }
30483
30336
  else {
30484
- var _x = participantEvent.category || {}, categoryName = _x.categoryName, ageCategoryCode = _x.ageCategoryCode;
30485
- var scaleItem = void 0;
30486
- try {
30487
- for (var _y = (e_3 = void 0, __values([
30488
- participantEvent.eventId,
30489
- ageCategoryCode,
30490
- categoryName,
30491
- ])), _z = _y.next(); !_z.done; _z = _y.next()) {
30492
- var scaleName = _z.value;
30493
- var scaleAttributes = {
30494
- eventType: participantEvent.eventType,
30495
- scaleType: SEEDING$1,
30496
- scaleName: scaleName,
30497
- };
30498
- var result = participantScaleItem({
30499
- scaleAttributes: scaleAttributes,
30500
- participant: participant,
30501
- });
30502
- if (result.scaleItem) {
30503
- scaleItem = result.scaleItem;
30504
- break;
30505
- }
30506
- }
30507
- }
30508
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
30509
- finally {
30510
- try {
30511
- if (_z && !_z.done && (_u = _y.return)) _u.call(_y);
30512
- }
30513
- finally { if (e_3) throw e_3.error; }
30514
- }
30515
- if (scaleItem) {
30516
- var seedValue = scaleItem.scaleValue;
30517
- var seedingPublished = !usePublishState ||
30518
- ((publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.published) &&
30519
- (((_h = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _h === void 0 ? void 0 : _h.length) === 0 ||
30520
- ((_j = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _j === void 0 ? void 0 : _j.includes(participantEvent.drawId))));
30521
- if (seedingPublished) {
30522
- participantEvent.seedValue = seedValue;
30523
- }
30524
- }
30525
- }
30526
- if ((_k = participantEvent.drawIds) === null || _k === void 0 ? void 0 : _k.length) {
30527
- try {
30528
- for (var _0 = (e_4 = void 0, __values(participantEvent.drawIds || [])), _1 = _0.next(); !_1.done; _1 = _0.next()) {
30529
- var flightDrawId = _1.value;
30530
- var drawSeedPublishingDisabled = ((_l = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _l === void 0 ? void 0 : _l.length) &&
30531
- !((_m = publishedSeeding === null || publishedSeeding === void 0 ? void 0 : publishedSeeding.drawIds) === null || _m === void 0 ? void 0 : _m.includes(flightDrawId));
30532
- if (eventSeedingPublished && !drawSeedPublishingDisabled) {
30533
- var seedAssignments = getDerivedSeedAssignments({
30534
- drawId: flightDrawId,
30535
- derivedDrawInfo: derivedDrawInfo,
30536
- participantId: participantId,
30537
- });
30538
- // preserve filtering of MAIN/QUALIFYING seedValues, if present
30539
- if (seedAssignments && participantEvent.seedAssignments) {
30540
- try {
30541
- for (var _2 = (e_5 = void 0, __values(Object.keys(participantEvent.seedAssignments))), _3 = _2.next(); !_3.done; _3 = _2.next()) {
30542
- var key = _3.value;
30543
- participantEvent.seedAssignments[key] = seedAssignments[key];
30544
- }
30545
- }
30546
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
30547
- finally {
30548
- try {
30549
- if (_3 && !_3.done && (_w = _2.return)) _w.call(_2);
30550
- }
30551
- finally { if (e_5) throw e_5.error; }
30552
- }
30553
- }
30554
- else {
30555
- participantEvent.seedAssignments = seedAssignments;
30556
- }
30557
- }
30558
- }
30559
- }
30560
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
30561
- finally {
30562
- try {
30563
- if (_1 && !_1.done && (_v = _0.return)) _v.call(_0);
30564
- }
30565
- finally { if (e_4) throw e_4.error; }
30566
- }
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
+ });
30567
30343
  }
30568
30344
  };
30569
30345
  try {
30570
- for (var participantEvents_1 = __values(participantEvents), participantEvents_1_1 = participantEvents_1.next(); !participantEvents_1_1.done; participantEvents_1_1 = participantEvents_1.next()) {
30571
- var participantEvent = participantEvents_1_1.value;
30572
- _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);
30573
30349
  }
30574
30350
  }
30575
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
30351
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
30576
30352
  finally {
30577
30353
  try {
30578
- 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);
30579
30355
  }
30580
- finally { if (e_2) throw e_2.error; }
30356
+ finally { if (e_3) throw e_3.error; }
30581
30357
  }
30358
+ idsWithConflicts === null || idsWithConflicts === void 0 ? void 0 : idsWithConflicts.forEach(function (participantId) {
30359
+ if (!participantIdsWithConflicts.includes(participantId))
30360
+ participantIdsWithConflicts.push(participantId);
30361
+ });
30582
30362
  }
30583
30363
  }
30584
- var participantOpponents = Object.values(opponents).flat();
30585
- if (withOpponents && (participantOpponents === null || participantOpponents === void 0 ? void 0 : participantOpponents.length)) {
30586
- participant.opponents = participantOpponents;
30587
- participantDraws === null || participantDraws === void 0 ? void 0 : participantDraws.forEach(function (draw) {
30588
- draw.opponents = participantOpponents.filter(function (opponent) { return opponent.drawId === draw.drawId; });
30589
- });
30590
- }
30591
- var participantPotentialMatchUps = Object.values(potentialMatchUps);
30592
- var participantMatchUps = Object.values(matchUps);
30593
- if (withMatchUps) {
30594
- participant.potentialMatchUps = participantPotentialMatchUps;
30595
- 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; }
30596
30370
  }
30597
- var allParticipantMatchUps = participantMatchUps.concat(participantPotentialMatchUps);
30598
- // scheduledMatchUps are a participant's matchUps separated by date and sorted by scheduledTime
30599
- var scheduledMatchUps = ((_o = participantScheduledMatchUps({
30600
- matchUps: allParticipantMatchUps,
30601
- })) === null || _o === void 0 ? void 0 : _o.scheduledMatchUps) || [];
30602
- var scheduledMinutesDifference = (scheduleAnalysis || {}).scheduledMinutesDifference;
30603
- var dates = Object.keys(scheduledMatchUps);
30604
- dates.forEach(function (date) {
30605
- scheduledMatchUps[date].filter(Boolean).forEach(function (matchUp, i) {
30606
- var e_6, _a;
30607
- var _b, _c, _d, _e;
30608
- 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;
30609
- 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 }));
30610
- // matchUps with { matchUpStatus: BYE } are ignored or { matchUpStatus: WALKOVER } and no score
30611
- var ignoreMatchUp = matchUpStatus === BYE ||
30612
- ([WALKOVER$2, DEFAULTED].includes(matchUpStatus) &&
30613
- !scoreHasValue({ score: score }));
30614
- if (scheduledTime && !ignoreMatchUp) {
30615
- var scheduledMinutes = timeStringMinutes(scheduledTime);
30616
- // each matchUp only considers conflicts with matchUps which occur at the same or later scheduledTime
30617
- var matchUpsToConsider = scheduledMatchUps[date].slice(i + 1);
30618
- try {
30619
- for (var matchUpsToConsider_1 = __values(matchUpsToConsider), matchUpsToConsider_1_1 = matchUpsToConsider_1.next(); !matchUpsToConsider_1_1.done; matchUpsToConsider_1_1 = matchUpsToConsider_1.next()) {
30620
- var consideredMatchUp = matchUpsToConsider_1_1.value;
30621
- // ignore { matchUpStatus: BYE } and matchUps which are unscheduled
30622
- var ignoreMatchUp_1 = consideredMatchUp.matchUpStatus === BYE ||
30623
- ([WALKOVER$2, DEFAULTED].includes(consideredMatchUp.matchUpStatus) &&
30624
- !scoreHasValue(consideredMatchUp));
30625
- if (!ignoreMatchUp_1 && ((_c = consideredMatchUp.schedule) === null || _c === void 0 ? void 0 : _c.scheduledTime)) {
30626
- // if there is a matchType change (SINGLES => DOUBLES or vice versa) then there is potentially a different timeAfterRecovery
30627
- var typeChange = matchUp.matchUpType !== consideredMatchUp.matchUpType;
30628
- var notBeforeTime = typeChange
30629
- ? typeChangeTimeAfterRecovery || timeAfterRecovery
30630
- : timeAfterRecovery;
30631
- // if two matchUps are both potentials and both part of the same draw they cannot be considered in conflict
30632
- var sameDraw = matchUp.drawId === consideredMatchUp.drawId;
30633
- var bothPotential = matchUp.potential && consideredMatchUp.potential;
30634
- var nextMinutes = timeStringMinutes((_d = consideredMatchUp.schedule) === null || _d === void 0 ? void 0 : _d.scheduledTime);
30635
- var minutesDifference = nextMinutes - scheduledMinutes;
30636
- // Conflicts can be determined in two ways:
30637
- // 1. scheduledMinutesDifference - the minutes difference between two scheduledTimes
30638
- // 2. A scheduledTime occurring before a prior matchUps notBeforeTime (timeAfterRecovery)
30639
- var timeOverlap = scheduledMinutesDifference && !isNaN(scheduledMinutesDifference)
30640
- ? minutesDifference <= scheduledMinutesDifference
30641
- : timeStringMinutes(notBeforeTime) >
30642
- timeStringMinutes((_e = consideredMatchUp.schedule) === null || _e === void 0 ? void 0 : _e.scheduledTime);
30643
- // if there is a time overlap capture both the prior matchUpId and the conflicted matchUpId
30644
- if (timeOverlap && !(bothPotential && sameDraw)) {
30645
- scheduleConflicts.push({
30646
- priorScheduledMatchUpId: consideredMatchUp.matchUpId,
30647
- matchUpIdWithConflict: matchUpId,
30648
- });
30649
- }
30650
- }
30651
- }
30652
- }
30653
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
30654
- finally {
30655
- try {
30656
- if (matchUpsToConsider_1_1 && !matchUpsToConsider_1_1.done && (_a = matchUpsToConsider_1.return)) _a.call(matchUpsToConsider_1);
30657
- }
30658
- finally { if (e_6) throw e_6.error; }
30659
- }
30660
- }
30661
- });
30662
- });
30663
- if (withStatistics)
30664
- participant.statistics = [winRatioStat];
30665
- return { scheduleConflicts: scheduleConflicts, scheduleItems: scheduleItems };
30371
+ return __assign({ competitionParticipants: competitionParticipants, participantIdsWithConflicts: participantIdsWithConflicts, mappedMatchUps: mappedMatchUps }, SUCCESS);
30666
30372
  }
30667
-
30668
- function getDrawDetails(_a) {
30669
- var _b;
30670
- var eventEntries = _a.eventEntries, sortConfig = _a.sortConfig, event = _a.event;
30671
- var derivedInfo = {};
30672
- var drawDetails = Object.assign.apply(Object, __spreadArray([{}], __read(((_b = event.drawDefinitions) !== null && _b !== void 0 ? _b : []).map(function (drawDefinition) {
30673
- var _a;
30674
- var _b, _c, _d, _e, _f, _g, _h, _j, _k;
30675
- var entriesMap = Object.assign.apply(Object, __spreadArray(__spreadArray([{}], __read((eventEntries !== null && eventEntries !== void 0 ? eventEntries : [])
30676
- .filter(function (entry) { return entry.participantId; })
30677
- .map(function (entry) {
30678
- var _a;
30679
- return (_a = {}, _a[entry.participantId] = entry, _a);
30680
- })), false), __read(drawDefinition.entries
30681
- .filter(function (entry) { return entry.participantId; })
30682
- .map(function (entry) {
30683
- var _a;
30684
- return (_a = {}, _a[entry.participantId] = entry, _a);
30685
- })), false));
30686
- var drawEntries = Object.values(entriesMap);
30687
- var mainStructure = (_c = (_b = getDrawStructures({
30688
- stageSequence: 1,
30689
- drawDefinition: drawDefinition,
30690
- stage: MAIN,
30691
- })) === null || _b === void 0 ? void 0 : _b.structures) === null || _c === void 0 ? void 0 : _c[0];
30692
- var mainPositionAssignments = mainStructure &&
30693
- ((_d = getPositionAssignments$1({
30694
- structure: mainStructure,
30695
- })) === null || _d === void 0 ? void 0 : _d.positionAssignments);
30696
- var drawSize = mainPositionAssignments === null || mainPositionAssignments === void 0 ? void 0 : mainPositionAssignments.length;
30697
- var qualifyingStructure = (_f = (_e = getDrawStructures({
30698
- stageSequence: 1,
30699
- stage: QUALIFYING,
30700
- drawDefinition: drawDefinition,
30701
- })) === null || _e === void 0 ? void 0 : _e.structures) === null || _f === void 0 ? void 0 : _f[0];
30702
- var qualifyingPositionAssignments = mainStructure &&
30703
- ((_g = getPositionAssignments$1({
30704
- structure: qualifyingStructure,
30705
- })) === null || _g === void 0 ? void 0 : _g.positionAssignments);
30706
- var qualifyingDrawSize = qualifyingPositionAssignments === null || qualifyingPositionAssignments === void 0 ? void 0 : qualifyingPositionAssignments.length;
30707
- var mainSeedAssignments = mainStructure === null || mainStructure === void 0 ? void 0 : mainStructure.seedAssignments;
30708
- var qualifyingSeedAssignments = qualifyingStructure === null || qualifyingStructure === void 0 ? void 0 : qualifyingStructure.seedAssignments;
30709
- // used in rankings pipeline.
30710
- // the structures in which a particpant particpates are ordered
30711
- // to enable differentiation for Points-per-round and points-per-win
30712
- var orderedStructureIds = (drawDefinition.structures || [])
30713
- .sort(function (a, b) { return structureSort(a, b, sortConfig); })
30714
- .map(function (_a) {
30715
- var structureId = _a.structureId, structures = _a.structures;
30716
- return __spreadArray([
30717
- structureId
30718
- ], __read((structures || []).map(function (_a) {
30719
- var structureId = _a.structureId;
30720
- return structureId;
30721
- })), false);
30722
- })
30723
- .flat(Infinity);
30724
- 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;
30725
- derivedInfo[drawDefinition.drawId] = {
30726
- qualifyingPositionAssignments: qualifyingPositionAssignments,
30727
- qualifyingSeedAssignments: qualifyingSeedAssignments,
30728
- mainPositionAssignments: mainPositionAssignments,
30729
- mainSeedAssignments: mainSeedAssignments,
30730
- orderedStructureIds: orderedStructureIds,
30731
- qualifyingDrawSize: qualifyingDrawSize,
30732
- flightNumber: flightNumber,
30733
- drawSize: drawSize,
30734
- };
30735
- return _a = {},
30736
- _a[drawDefinition.drawId] = {
30737
- drawType: drawDefinition.drawType,
30738
- drawEntries: drawEntries,
30739
- },
30740
- _a;
30741
- })), false));
30742
- 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);
30743
30410
  }
30744
30411
 
30745
- function processMatchUp(_a) {
30746
- var _b;
30747
- 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;
30748
- 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;
30749
- var targetParticipantIds = participantFilters === null || participantFilters === void 0 ? void 0 : participantFilters.participantIds;
30750
- var getRelevantParticipantIds = function (participantId) {
30751
- var relevantParticipantIds = (participantId && relevantParticipantIdsMap[participantId]) || [];
30752
- relevantParticipantIds.push(participantId);
30753
- return relevantParticipantIds.some(function (obj) {
30754
- return !targetParticipantIds ||
30755
- targetParticipantIds.includes(obj.relevantParticipantId);
30756
- })
30757
- ? relevantParticipantIds
30758
- : [];
30759
- };
30760
- var _c = finishingPositionRange || {}, winner = _c.winner, loser = _c.loser;
30761
- // doubles participants are not defined in the entries for a draw/event
30762
- // and can only be determined by interrogating inContext tieMatchUps
30763
- // because here the pairParticipantIds are derived from collectionAssignments
30764
- var doublesTieParticipants = ((tieMatchUps === null || tieMatchUps === void 0 ? void 0 : tieMatchUps.length) &&
30765
- tieMatchUps
30766
- .filter(function (_a) {
30767
- var matchUpType = _a.matchUpType;
30768
- return matchUpType === DOUBLES_MATCHUP;
30769
- })
30770
- .map(function (_a) {
30771
- var sides = _a.sides;
30772
- return sides.map(function (_a) {
30773
- var sideNumber = _a.sideNumber, participantId = _a.participantId, participant = _a.participant;
30774
- return sideNumber &&
30775
- participantId && {
30776
- sideNumber: sideNumber,
30777
- participantId: participantId,
30778
- participant: participant,
30779
- };
30780
- });
30781
- })
30782
- .flat()
30783
- .filter(Boolean)) ||
30784
- [];
30785
- if (eventType === TEAM_EVENT && matchUpType === DOUBLES_MATCHUP) {
30786
- var participants = (((_b = matchUp.sides) === null || _b === void 0 ? void 0 : _b.filter(Boolean)) || [])
30787
- .map(function (_a) {
30788
- var sideNumber = _a.sideNumber, participantId = _a.participantId, participant = _a.participant;
30789
- return sideNumber &&
30790
- participantId && {
30791
- sideNumber: sideNumber,
30792
- participantId: participantId,
30793
- participant: participant,
30794
- };
30795
- })
30796
- .filter(Boolean);
30797
- 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
+ });
30798
30456
  }
30799
- sides === null || sides === void 0 ? void 0 : sides.forEach(function (params) {
30800
- var participantId = params.participantId, sideNumber = params.sideNumber;
30801
- if (!participantId)
30802
- return;
30803
- var _a = drawDetails[drawId], drawType = _a.drawType, drawEntries = _a.drawEntries;
30804
- var participantScore = sideNumber === 1 ? score === null || score === void 0 ? void 0 : score.scoreStringSide1 : score === null || score === void 0 ? void 0 : score.scoreStringSide2;
30805
- var participantWon = winningSide && sideNumber === winningSide;
30806
- var opponent = matchUp.sides.find(function (side) { return side.sideNumber === 3 - sideNumber; });
30807
- var opponentParticipantId = opponent === null || opponent === void 0 ? void 0 : opponent.participantId;
30808
- var relevantOpponents = (opponentParticipantId &&
30809
- relevantParticipantIdsMap[opponentParticipantId]) ||
30810
- [];
30811
- var finishingPositionRange = participantWon ? winner : loser;
30812
- var drawEntry = drawEntries.find(function (entry) { return entry.participantId === participantId; });
30813
- // for all matchUps include all individual participants that are part of pairs
30814
- // this does NOT include PAIR participants in teams, because they are constructed from collectionAssignments
30815
- // if { eventType: TEAM } then only add relevant PAIR participantIds using doublesTieParticipants
30816
- // this will avoid adding a pair to all team events in which individuals appear
30817
- var relevantParticipantIds = getRelevantParticipantIds(participantId);
30818
- // for TEAM matchUps add all PAIR participants
30819
- var addedPairParticipantIds = [];
30820
- doublesTieParticipants === null || doublesTieParticipants === void 0 ? void 0 : doublesTieParticipants.filter(function (participant) { return participant.sideNumber === sideNumber; }).forEach(function (p) {
30821
- var participantId = p.participantId;
30822
- if (participantId && !addedPairParticipantIds.includes(participantId)) {
30823
- relevantParticipantIds.push({
30824
- relevantParticipantId: participantId,
30825
- participantType: PAIR,
30826
- });
30827
- 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
+ }
30828
30490
  }
30491
+ if (participantModified)
30492
+ modifiedParticipants.push(participant);
30493
+ return penalty.penaltyId !== penaltyId;
30829
30494
  });
30830
- var filteredRelevantParticipantIds = relevantParticipantIds.filter(function (opponent) {
30831
- return (eventType !== TEAM_EVENT ||
30832
- (eventType === TEAM_EVENT &&
30833
- [DOUBLES_MATCHUP, TEAM_MATCHUP].includes(matchUpType) &&
30834
- [PAIR, TEAM_PARTICIPANT].includes(opponent.participantType)) ||
30835
- (eventType === TEAM_EVENT &&
30836
- [SINGLES_MATCHUP, DOUBLES_MATCHUP].includes(matchUpType) &&
30837
- [INDIVIDUAL].includes(opponent.participantType)));
30495
+ });
30496
+ if (removedPenalty) {
30497
+ addNotice({
30498
+ topic: MODIFY_PARTICIPANTS,
30499
+ payload: {
30500
+ tournamentId: tournamentRecord.tournamentId,
30501
+ participants: modifiedParticipants,
30502
+ },
30838
30503
  });
30839
- filteredRelevantParticipantIds === null || filteredRelevantParticipantIds === void 0 ? void 0 : filteredRelevantParticipantIds.forEach(function (_a) {
30840
- var _b, _c;
30841
- var relevantParticipantId = _a.relevantParticipantId, participantType = _a.participantType;
30842
- var _d = drawEntry || {}, entryStage = _d.entryStage, entryStatus = _d.entryStatus, entryPosition = _d.entryPosition;
30843
- if (!participantIdMap[relevantParticipantId])
30844
- return;
30845
- if (!participantIdMap[relevantParticipantId].draws[drawId]) {
30846
- var positionAssignments = getDerivedPositionAssignments({
30847
- participantId: relevantParticipantId,
30848
- derivedDrawInfo: derivedDrawInfo,
30849
- drawId: drawId,
30850
- });
30851
- var seedAssignments = getDerivedSeedAssignments({
30852
- participantId: relevantParticipantId,
30853
- derivedDrawInfo: derivedDrawInfo,
30854
- drawId: drawId,
30855
- });
30856
- participantIdMap[relevantParticipantId].draws[drawId] =
30857
- definedAttributes({
30858
- qualifyingDrawSize: (_b = derivedDrawInfo[drawId]) === null || _b === void 0 ? void 0 : _b.qualifyingDrawSize,
30859
- drawSize: (_c = derivedDrawInfo[drawId]) === null || _c === void 0 ? void 0 : _c.drawSize,
30860
- partnerParticipantIds: [],
30861
- positionAssignments: positionAssignments,
30862
- seedAssignments: seedAssignments,
30863
- entryPosition: entryPosition,
30864
- entryStatus: entryStatus,
30865
- entryStage: entryStage,
30866
- drawName: drawName,
30867
- drawType: drawType,
30868
- eventId: eventId,
30869
- drawId: drawId,
30870
- });
30871
- }
30872
- if (!participantIdMap[relevantParticipantId].events[eventId]) {
30873
- participantIdMap[relevantParticipantId].events[eventId] = {
30874
- partnerParticipantIds: [],
30875
- drawIds: [],
30876
- eventName: eventName,
30877
- eventId: eventId,
30878
- };
30879
- }
30880
- var eventDrawIds = participantIdMap[relevantParticipantId].events[eventId].drawIds;
30881
- if (eventDrawIds && !(eventDrawIds === null || eventDrawIds === void 0 ? void 0 : eventDrawIds.includes(drawId))) {
30882
- 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);
30883
30519
  }
30884
- var partnerParticipantId;
30885
- if (participantType === INDIVIDUAL && matchUpType === DOUBLES_MATCHUP) {
30886
- var relevantParticipantInfo = filteredRelevantParticipantIds.find(function (participantInfo) {
30887
- return (participantInfo.relevantParticipantId !==
30888
- relevantParticipantId &&
30889
- participantInfo.participantType === INDIVIDUAL);
30890
- });
30891
- partnerParticipantId = relevantParticipantInfo === null || relevantParticipantInfo === void 0 ? void 0 : relevantParticipantInfo.relevantParticipantId;
30520
+ else {
30521
+ penalties[penaltyId] = __assign(__assign({}, penalty), { participantIds: [participantId] });
30892
30522
  }
30893
- var filteredRelevantOpponents = (relevantOpponents === null || relevantOpponents === void 0 ? void 0 : relevantOpponents.filter(function (opponent) {
30894
- return (matchUpType === TEAM_MATCHUP &&
30895
- participantType === TEAM_PARTICIPANT &&
30896
- opponent.participantType === TEAM_PARTICIPANT) ||
30897
- (matchUpType === SINGLES_MATCHUP &&
30898
- opponent.participantType === INDIVIDUAL) ||
30899
- (matchUpType === DOUBLES_MATCHUP &&
30900
- (participantType === INDIVIDUAL
30901
- ? [INDIVIDUAL, PAIR].includes(opponent.participantType)
30902
- : // for PAIR participants only show PAIR opponenents
30903
- opponent.participantType === PAIR));
30904
- })) || [];
30905
- filteredRelevantOpponents.forEach(function (_a) {
30906
- var opponentParticipantId = _a.relevantParticipantId, opponentParticipantType = _a.participantType;
30907
- if (!participantIdMap[relevantParticipantId].opponents) {
30908
- participantIdMap[relevantParticipantId].opponents = {};
30909
- }
30910
- participantIdMap[relevantParticipantId].opponents[opponentParticipantId] = {
30911
- eventId: eventId,
30912
- drawId: drawId,
30913
- matchUpId: matchUpId,
30914
- participantType: opponentParticipantType,
30915
- participantId: opponentParticipantId,
30916
- };
30917
- });
30918
- var opponentParticipantInfo = filteredRelevantOpponents.map(function (_a) {
30919
- var relevantParticipantId = _a.relevantParticipantId, participantType = _a.participantType;
30920
- return ({
30921
- participantId: relevantParticipantId,
30922
- 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));
30923
30551
  });
30924
- });
30925
- var includeMatchUp = (matchUpType !== TEAM_MATCHUP &&
30926
- [INDIVIDUAL, PAIR].includes(participantType)) ||
30927
- (matchUpType === TEAM_MATCHUP &&
30928
- participantType === TEAM_PARTICIPANT);
30929
- if (includeMatchUp)
30930
- participantIdMap[relevantParticipantId].matchUps[matchUpId] =
30931
- definedAttributes({
30932
- collectionId: collectionId,
30933
- collectionPosition: collectionPosition,
30934
- drawId: drawId,
30935
- eventId: eventId,
30936
- eventType: eventType,
30937
- eventDrawsCount: eventDrawsCount,
30938
- finishingRound: finishingRound,
30939
- finishingPositionRange: finishingPositionRange,
30940
- loserTo: loserTo,
30941
- matchUpId: matchUpId,
30942
- matchUpType: matchUpType,
30943
- matchUpFormat: matchUpFormat,
30944
- matchUpStatus: matchUpStatus,
30945
- matchUpStatusCodes: matchUpStatusCodes,
30946
- matchUpTieId: matchUpTieId,
30947
- opponentParticipantInfo: opponentParticipantInfo,
30948
- participantWon: participantWon,
30949
- partnerParticipantId: partnerParticipantId,
30950
- perspectiveScoreString: participantScore,
30951
- processCodes: processCodes,
30952
- roundName: roundName,
30953
- roundNumber: roundNumber,
30954
- roundPosition: roundPosition,
30955
- schedule: schedule,
30956
- score: score,
30957
- sides: sides,
30958
- stage: stage,
30959
- stageSequence: stageSequence,
30960
- structureName: structureName,
30961
- structureId: structureId,
30962
- tieFormat: tieFormat,
30963
- tournamentId: tournamentId,
30964
- winnerTo: winnerTo,
30965
- winningSide: winningSide,
30966
- });
30967
- if (partnerParticipantId) {
30968
- participantIdMap[relevantParticipantId].events[eventId].partnerParticipantIds.push(partnerParticipantId);
30969
- participantIdMap[relevantParticipantId].draws[drawId].partnerParticipantIds.push(partnerParticipantId);
30970
- // legacy.... deprecate when ETL updated
30971
- participantIdMap[relevantParticipantId].events[eventId].partnerParticipantId = partnerParticipantId;
30972
- participantIdMap[relevantParticipantId].draws[drawId].partnerParticipantId = partnerParticipantId;
30973
- }
30974
- if (winningSide) {
30975
- if (participantWon) {
30976
- participantIdMap[relevantParticipantId].wins++;
30977
- }
30978
- else {
30979
- participantIdMap[relevantParticipantId].losses++;
30980
- }
30552
+ if (!updatedPenalty)
30553
+ updatedPenalty = penalty;
30981
30554
  }
30555
+ return penalty;
30982
30556
  });
30557
+ if (participantModified)
30558
+ modifiedParticipants.push(participant);
30983
30559
  });
30984
- if (Array.isArray(matchUp.potentialParticipants)) {
30985
- var potentialParticipantIds = getParticipantIds(matchUp.potentialParticipants.flat());
30986
- potentialParticipantIds === null || potentialParticipantIds === void 0 ? void 0 : potentialParticipantIds.forEach(function (participantId) {
30987
- var relevantParticipantIds = getRelevantParticipantIds(participantId);
30988
- relevantParticipantIds === null || relevantParticipantIds === void 0 ? void 0 : relevantParticipantIds.forEach(function (_a) {
30989
- var relevantParticipantId = _a.relevantParticipantId;
30990
- participantIdMap[relevantParticipantId].potentialMatchUps[matchUpId] =
30991
- definedAttributes({
30992
- drawId: drawId,
30993
- eventId: eventId,
30994
- eventType: eventType,
30995
- matchUpId: matchUpId,
30996
- matchUpType: matchUpType,
30997
- matchUpFormat: matchUpFormat,
30998
- roundName: roundName,
30999
- roundNumber: roundNumber,
31000
- roundPosition: roundPosition,
31001
- schedule: schedule,
31002
- tieFormat: tieFormat,
31003
- structureName: structureName,
31004
- tournamentId: tournamentId,
31005
- potential: true,
31006
- });
31007
- });
30560
+ if (updatedPenalty) {
30561
+ addNotice({
30562
+ topic: MODIFY_PARTICIPANTS,
30563
+ payload: {
30564
+ tournamentId: tournamentRecord.tournamentId,
30565
+ participants: modifiedParticipants,
30566
+ },
31008
30567
  });
31009
30568
  }
30569
+ return updatedPenalty
30570
+ ? __assign(__assign({}, SUCCESS), { penalty: updatedPenalty }) : { error: PENALTY_NOT_FOUND };
31010
30571
  }
31011
30572
 
31012
- function addParticipantContext(params) {
31013
- var _a, _b;
31014
- var participantIdsWithConflicts = [];
31015
- var eventsPublishStatuses = {};
31016
- var derivedDrawInfo = {};
31017
- var participantIdMap = {};
31018
- var initializeParticipantId = function (participantId) {
31019
- if (!participantIdMap[participantId])
31020
- participantIdMap[participantId] = {
31021
- groupParticipantIds: [],
31022
- teamParticipantIds: [],
31023
- pairParticipantIds: [],
31024
- potentialMatchUps: {},
31025
- scheduleItems: [],
31026
- opponents: {},
31027
- matchUps: {},
31028
- events: {},
31029
- groups: [],
31030
- teams: [],
31031
- draws: {},
31032
- losses: 0,
31033
- wins: 0,
31034
- };
31035
- };
31036
- var tournamentRecord = params.tournamentRecord, participantFilters = params.participantFilters, allTournamentParticipants = params.allTournamentParticipants;
31037
- var relevantParticipantIdsMap = getRelevantParticipantIdsMap({
31038
- processParticipantId: initializeParticipantId,
31039
- tournamentRecord: tournamentRecord,
31040
- }).relevantParticipantIdsMap;
31041
- // optimize when filtering participants by participantIds
31042
- // by only returning relevantParticipantIds related to specified participantIds
31043
- var targetParticipantIds = participantFilters === null || participantFilters === void 0 ? void 0 : participantFilters.participantIds;
31044
- var getRelevantParticipantIds = function (participantId) {
31045
- var relevantParticipantIds = (participantId && relevantParticipantIdsMap[participantId]) || [];
31046
- relevantParticipantIds.push(participantId);
31047
- return relevantParticipantIds.some(function (obj) {
31048
- return !targetParticipantIds ||
31049
- targetParticipantIds.includes(obj.relevantParticipantId);
31050
- })
31051
- ? relevantParticipantIds
31052
- : [];
31053
- };
31054
- params.withGroupings &&
31055
- allTournamentParticipants.forEach(function (participant) {
31056
- var _a, _b, _c;
31057
- if (participant.participantType === GROUP) {
31058
- var groupParticipantId_1 = participant.participantId;
31059
- (_a = participant === null || participant === void 0 ? void 0 : participant.individualParticipantIds) === null || _a === void 0 ? void 0 : _a.forEach(function (participantId) {
31060
- if (!participantIdMap[participantId].groupParticipantIds.includes(groupParticipantId_1)) {
31061
- participantIdMap[participantId].groupParticipantIds.push(groupParticipantId_1);
31062
- participantIdMap[participantId].groups.push({
31063
- participantRoleResponsibilities: participant.participantRoleResponsibilities,
31064
- participantOtherName: participant.participantOtherName,
31065
- participantName: participant.participantName,
31066
- participantId: participant.participantId,
31067
- });
31068
- }
31069
- });
31070
- }
31071
- if (participant.participantType === TEAM$2) {
31072
- var teamParticipantId_1 = participant.participantId;
31073
- (_b = participant === null || participant === void 0 ? void 0 : participant.individualParticipantIds) === null || _b === void 0 ? void 0 : _b.forEach(function (participantId) {
31074
- var _a, _b, _c, _d;
31075
- if (!((_b = (_a = participantIdMap[participantId]) === null || _a === void 0 ? void 0 : _a.teamParticipantIds) === null || _b === void 0 ? void 0 : _b.includes(teamParticipantId_1))) {
31076
- (_c = participantIdMap[participantId]) === null || _c === void 0 ? void 0 : _c.teamParticipantIds.push(teamParticipantId_1);
31077
- (_d = participantIdMap[participantId]) === null || _d === void 0 ? void 0 : _d.teams.push({
31078
- participantRoleResponsibilities: participant.participantRoleResponsibilities,
31079
- participantOtherName: participant.participantOtherName,
31080
- participantName: participant.participantName,
31081
- participantId: participant.participantId,
31082
- teamId: participant.teamId,
31083
- });
31084
- }
31085
- });
31086
- }
31087
- if (participant.participantType === PAIR) {
31088
- var pairParticipantId_1 = participant.participantId;
31089
- (_c = participant === null || participant === void 0 ? void 0 : participant.individualParticipantIds) === null || _c === void 0 ? void 0 : _c.forEach(function (participantId) {
31090
- if (participantIdMap[participantId] &&
31091
- !participantIdMap[participantId].pairParticipantIds.includes(pairParticipantId_1)) {
31092
- participantIdMap[participantId].pairParticipantIds.push(pairParticipantId_1);
31093
- }
31094
- });
31095
- }
31096
- });
31097
- if (params.withMatchUps) {
31098
- getMatchUpDependencies({ tournamentRecord: tournamentRecord }); // ensure that goesTos exist
31099
- }
31100
- if (params.withScheduleItems ||
31101
- params.scheduleAnalysis ||
31102
- params.withStatistics ||
31103
- params.withOpponents ||
31104
- params.withMatchUps ||
31105
- params.withSeeding ||
31106
- params.withEvents ||
31107
- params.withDraws) {
31108
- // loop through all filtered events and capture events played
31109
- (_a = params.tournamentEvents) === null || _a === void 0 ? void 0 : _a.forEach(function (rawEvent) {
31110
- var _a, _b, _c, _d, _e, _f, _g;
31111
- var event = makeDeepCopy(rawEvent, true, true);
31112
- var flightProfile = getFlightProfile({ event: event }).flightProfile;
31113
- 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;
31114
- (event.drawDefinitions || []).forEach(function (drawDefinition, i) {
31115
- if ((event === null || event === void 0 ? void 0 : event.eventType) === TEAM$2) {
31116
- // add back lineUps extension for team resolution when { matchUpType: TEAM } is missing side.lineUps
31117
- var extension = findExtension$2({
31118
- element: rawEvent.drawDefinitions[i],
31119
- name: LINEUPS,
31120
- }).extension;
31121
- if (extension)
31122
- drawDefinition.extensions = [extension];
31123
- }
31124
- });
31125
- var eventId = event.eventId, eventName = event.eventName, eventType = event.eventType, category = event.category;
31126
- var eventInfo = { eventId: eventId, eventName: eventName, eventType: eventType, category: category };
31127
- var extensionKeys = event && Object.keys(event).filter(function (key) { return key.startsWith('_'); });
31128
- extensionKeys === null || extensionKeys === void 0 ? void 0 : extensionKeys.forEach(function (extensionKey) { return (eventInfo[extensionKey] = event[extensionKey]); });
31129
- var eventEntries = event.entries || [];
31130
- var itemType = "".concat(PUBLISH, ".").concat(STATUS$1);
31131
- var timeItem = getEventTimeItem({
31132
- itemType: itemType,
31133
- event: event,
31134
- }).timeItem;
31135
- if ((_c = timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemValue) === null || _c === void 0 ? void 0 : _c.PUBLIC) {
31136
- var _h = timeItem.itemValue.PUBLIC || {}, _j = _h.drawIds, publishedDrawIds = _j === void 0 ? [] : _j, seeding = _h.seeding;
31137
- var publishedSeeding = {
31138
- published: undefined,
31139
- seedingScaleNames: [],
31140
- drawIds: [], // seeding can be specific to drawIds
31141
- };
31142
- if (seeding)
31143
- Object.assign(publishedSeeding, timeItem.itemValue.PUBLIC.seeding);
31144
- eventsPublishStatuses[eventId] = {
31145
- publishedDrawIds: publishedDrawIds,
31146
- publishedSeeding: publishedSeeding,
31147
- };
31148
- }
31149
- // don't allow system extensions to be copied to participants
31150
- var disallowedConstants = __spreadArray([], __read(Object.values(extensionConstants)), false);
31151
- var disallowedKeys = disallowedConstants.map(function (constant) { return "_".concat(constant); });
31152
- var filteredEventInfo = eventInfo &&
31153
- Object.keys(eventInfo)
31154
- .filter(function (key) { return !disallowedKeys.includes(key); })
31155
- .reduce(function (obj, key) {
31156
- obj[key] = eventInfo[key];
31157
- return obj;
31158
- }, {});
31159
- eventEntries === null || eventEntries === void 0 ? void 0 : eventEntries.filter(function (entry) { return entry === null || entry === void 0 ? void 0 : entry.participantId; }).forEach(function (entry) {
31160
- var participantId = entry.participantId, entryStage = entry.entryStage, entryStatus = entry.entryStatus, entryPosition = entry.entryPosition;
31161
- // include all individual participants that are part of teams & pairs
31162
- // relevantParticipantId is a reference to an individual
31163
- var relevantParticipantIds = getRelevantParticipantIds(participantId);
31164
- relevantParticipantIds === null || relevantParticipantIds === void 0 ? void 0 : relevantParticipantIds.forEach(function (_a) {
31165
- var relevantParticipantId = _a.relevantParticipantId;
31166
- if (!participantIdMap[relevantParticipantId])
31167
- initializeParticipantId(relevantParticipantId);
31168
- participantIdMap[relevantParticipantId].events[eventId] = __assign(__assign({}, filteredEventInfo), { partnerParticipantIds: [], entryPosition: entryPosition, entryStatus: entryStatus, entryStage: entryStage, drawIds: [], eventId: eventId });
31169
- });
31170
- });
31171
- var addDrawData = function (_a) {
31172
- var drawEntry = _a.drawEntry, drawId = _a.drawId;
31173
- var participantId = drawEntry.participantId, entryStage = drawEntry.entryStage, entryStatus = drawEntry.entryStatus, entryPosition = drawEntry.entryPosition;
31174
- var relevantParticipantIds = getRelevantParticipantIds(participantId);
31175
- relevantParticipantIds === null || relevantParticipantIds === void 0 ? void 0 : relevantParticipantIds.forEach(function (_a) {
31176
- var _b, _c;
31177
- var relevantParticipantId = _a.relevantParticipantId;
31178
- if (!participantIdMap[relevantParticipantId].events[eventId]) {
31179
- participantIdMap[relevantParticipantId].events[eventId] = __assign(__assign({}, filteredEventInfo), { partnerParticipantIds: [], entryPosition: entryPosition, entryStatus: entryStatus, entryStage: entryStage, drawIds: [], eventId: eventId });
31180
- }
31181
- if (!participantIdMap[relevantParticipantId].draws[drawId]) {
31182
- var positionAssignments = getDerivedPositionAssignments({
31183
- participantId: relevantParticipantId,
31184
- derivedDrawInfo: derivedDrawInfo,
31185
- drawId: drawId,
31186
- });
31187
- var seedAssignments = getDerivedSeedAssignments({
31188
- participantId: relevantParticipantId,
31189
- derivedDrawInfo: derivedDrawInfo,
31190
- drawId: drawId,
31191
- });
31192
- participantIdMap[relevantParticipantId].draws[drawId] =
31193
- definedAttributes({
31194
- qualifyingDrawSize: (_b = derivedDrawInfo[drawId]) === null || _b === void 0 ? void 0 : _b.qualifyingDrawSize,
31195
- drawSize: (_c = derivedDrawInfo[drawId]) === null || _c === void 0 ? void 0 : _c.drawSize,
31196
- partnerParticipantIds: [],
31197
- positionAssignments: positionAssignments,
31198
- eventDrawsCount: eventDrawsCount,
31199
- seedAssignments: seedAssignments,
31200
- entryPosition: entryPosition,
31201
- entryStatus: entryStatus,
31202
- entryStage: entryStage,
31203
- eventId: eventId,
31204
- drawId: drawId,
31205
- });
31206
- }
31207
- var eventDrawIds = participantIdMap[relevantParticipantId].events[eventId].drawIds;
31208
- if (eventDrawIds && !(eventDrawIds === null || eventDrawIds === void 0 ? void 0 : eventDrawIds.includes(drawId))) {
31209
- participantIdMap[relevantParticipantId].events[eventId].drawIds.push(drawId);
31210
- }
31211
- });
31212
- };
31213
- // iterate through flights to ensure that draw entries are captured if drawDefinitions have not yet been generated
31214
- var drawIdsWithDefinitions = ((_d = event.drawDefinitions) === null || _d === void 0 ? void 0 : _d.map(function (_a) {
31215
- var drawId = _a.drawId;
31216
- return drawId;
31217
- })) || [];
31218
- (_f = (_e = eventInfo._flightProfile) === null || _e === void 0 ? void 0 : _e.flights) === null || _f === void 0 ? void 0 : _f.forEach(function (flight) {
31219
- var drawId = flight.drawId, drawEntries = flight.drawEntries;
31220
- if (!drawIdsWithDefinitions.includes(drawId)) {
31221
- drawEntries === null || drawEntries === void 0 ? void 0 : drawEntries.forEach(function (drawEntry) {
31222
- return addDrawData({ drawEntry: drawEntry, drawId: drawId });
31223
- });
31224
- }
31225
- });
31226
- var _k = getDrawDetails({
31227
- eventEntries: eventEntries,
31228
- event: event,
31229
- }), drawDetails = _k.drawDetails, derivedInfo = _k.derivedInfo;
31230
- Object.assign(derivedDrawInfo, derivedInfo);
31231
- if (event.eventType === TEAM$2 || // for TEAM events some individual attributes can only be derived by processing
31232
- params.withScheduleItems ||
31233
- params.scheduleAnalysis ||
31234
- params.withStatistics ||
31235
- params.withOpponents ||
31236
- params.withMatchUps ||
31237
- params.withDraws) {
31238
- var matchUps = (_g = allEventMatchUps({
31239
- afterRecoveryTimes: params.scheduleAnalysis,
31240
- participants: allTournamentParticipants,
31241
- nextMatchUps: true,
31242
- tournamentRecord: tournamentRecord,
31243
- inContext: true,
31244
- event: event,
31245
- })) === null || _g === void 0 ? void 0 : _g.matchUps;
31246
- matchUps === null || matchUps === void 0 ? void 0 : matchUps.forEach(function (matchUp) {
31247
- return processMatchUp({
31248
- relevantParticipantIdsMap: relevantParticipantIdsMap,
31249
- participantFilters: participantFilters,
31250
- participantIdMap: participantIdMap,
31251
- derivedDrawInfo: derivedDrawInfo,
31252
- eventDrawsCount: eventDrawsCount,
31253
- drawDetails: drawDetails,
31254
- eventType: eventType,
31255
- matchUp: matchUp,
31256
- });
31257
- });
31258
- }
31259
- });
31260
- }
31261
- // tournamentParticipants is an array of FILTERED participants
31262
- (_b = params.tournamentParticipants) === null || _b === void 0 ? void 0 : _b.forEach(function (participant) {
31263
- var _a = annotateParticipant(__assign(__assign({}, params), { eventsPublishStatuses: eventsPublishStatuses, participantIdMap: participantIdMap, derivedDrawInfo: derivedDrawInfo, participant: participant })), scheduleConflicts = _a.scheduleConflicts, scheduleItems = _a.scheduleItems;
31264
- if (params.withSignInStatus) {
31265
- var timeItem = getTimeItem({
31266
- itemType: SIGN_IN_STATUS,
31267
- element: participant,
31268
- }).timeItem;
31269
- participant.signedIn = (timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemValue) === SIGNED_IN;
31270
- }
31271
- if (params.withScheduleItems) {
31272
- participant.scheduleItems = scheduleItems;
31273
- }
31274
- if (params.scheduleAnalysis) {
31275
- participant.scheduleConflicts = scheduleConflicts;
31276
- if ((scheduleConflicts === null || scheduleConflicts === void 0 ? void 0 : scheduleConflicts.length) &&
31277
- !participantIdsWithConflicts.includes(participant.participantId)) {
31278
- 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;
31279
30588
  }
31280
30589
  }
31281
- if (params.withGroupings !== false) {
31282
- var participantAttributes = participantIdMap[participant.participantId];
31283
- participant.groupParticipantIds =
31284
- participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.groupParticipantIds;
31285
- participant.pairParticipantIds =
31286
- participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.pairParticipantIds;
31287
- participant.teamParticipantIds =
31288
- participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.teamParticipantIds;
31289
- participant.groups = participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.groups;
31290
- participant.teams = participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.teams;
31291
- }
31292
- if (params.withTeamMatchUps) ;
31293
- });
31294
- return { participantIdsWithConflicts: participantIdsWithConflicts, eventsPublishStatuses: eventsPublishStatuses };
31295
- }
31296
-
31297
- /**
31298
- * Returns deepCopies of tournament participants filtered by participantFilters which are arrays of desired participant attribute values
31299
- *
31300
- * @param {object} tournamentRecord - tournament object (passed automatically from tournamentEngine state)
31301
- * @param {object} participantFilters - attribute arrays with filter value strings
31302
- * @param {boolean} inContext - adds individualParticipants for all individualParticipantIds
31303
- * @param {boolean} withDraws - include all matchUps in which participant appears
31304
- * @param {boolean} withEvents - include all events in which participant appears
31305
- * @param {boolean} withMatchUps - include all matchUps in which participant appears
31306
- * @param {boolean} withStatistics - adds events: { [eventId]: eventName }, matchUps: { [matchUpId]: score }, statistics: [{ statCode: 'winRatio'}]
31307
- * @param {boolean} withScheduleItems - include schedule items; scheduled matchUps
31308
- * @param {boolean} scheduleAnalysis - analysis of conflicts
31309
- * @param {boolean} withGroupings - include teams and groups and pairs in which individual participants appear
31310
- * @param {boolean} withOpponents - include opponent participantIds
31311
- * @param {boolean} usePublishState - when hydrating participants consider publish state (currently applies to seeding)
31312
- *
31313
- */
31314
- function getTournamentParticipants(params) {
31315
- 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
31316
- 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;
31317
- if (!tournamentRecord)
31318
- return { error: MISSING_TOURNAMENT_RECORD };
31319
- if (!tournamentRecord.participants)
31320
- return { error: MISSING_PARTICIPANTS };
31321
- var allTournamentParticipants = tournamentRecord.participants.map(
31322
- // (participant) => makeDeepCopy(participant, convertExtensions, true)
31323
- function (participant) { return makeDeepCopy(participant, convertExtensions); } // removed until Mongo/Mongoose issues resolved
31324
- );
31325
- if (typeof participantFilters !== 'object')
31326
- return { error: INVALID_OBJECT, participantFilters: participantFilters };
31327
- if (inContext) {
31328
- allTournamentParticipants === null || allTournamentParticipants === void 0 ? void 0 : allTournamentParticipants.forEach(function (participant) {
31329
- var _a;
31330
- if ([PAIR, TEAM, GROUP].includes(participant.participantType)) {
31331
- participant.individualParticipants =
31332
- (_a = participant.individualParticipantIds) === null || _a === void 0 ? void 0 : _a.map(function (participantId) {
31333
- var targetParticipant = tournamentRecord.participants.find(function (p) { return p.participantId === participantId; });
31334
- var individualParticipant = makeDeepCopy(targetParticipant, convertExtensions, true);
31335
- // individualParticipants only need to be hydrated withScaleValues and nationalityCode variations
31336
- if (withScaleValues) {
31337
- var _a = getScaleValues({
31338
- participant: individualParticipant,
31339
- }), ratings = _a.ratings, rankings = _a.rankings;
31340
- individualParticipant.ratings = ratings;
31341
- individualParticipant.rankings = rankings;
31342
- }
31343
- if (withIOC || withISO2)
31344
- addNationalityCode({
31345
- participant: individualParticipant,
31346
- withISO2: withISO2,
31347
- withIOC: withIOC,
31348
- });
31349
- return individualParticipant;
31350
- });
31351
- }
31352
- });
31353
- }
31354
- var tournamentParticipants = participantFilters
31355
- ? filterParticipants({
31356
- participants: allTournamentParticipants,
31357
- participantFilters: participantFilters,
31358
- tournamentRecord: tournamentRecord,
31359
- })
31360
- : allTournamentParticipants;
31361
- var participantIdsWithConflicts, eventsPublishStatuses;
31362
- var addContext = withScheduleItems ||
31363
- withSignInStatus ||
31364
- scheduleAnalysis ||
31365
- withScaleValues ||
31366
- withStatistics ||
31367
- withGroupings ||
31368
- withOpponents ||
31369
- withMatchUps ||
31370
- withSeeding ||
31371
- withEvents ||
31372
- withDraws ||
31373
- withISO2 ||
31374
- withIOC;
31375
- if (addContext) {
31376
- var result = addParticipantContext({
31377
- tournamentEvents: tournamentRecord.events,
31378
- allTournamentParticipants: allTournamentParticipants,
31379
- tournamentParticipants: tournamentParticipants,
31380
- participantFilters: participantFilters,
31381
- withScheduleItems: withScheduleItems,
31382
- withSignInStatus: withSignInStatus,
31383
- tournamentRecord: tournamentRecord,
31384
- scheduleAnalysis: scheduleAnalysis,
31385
- withTeamMatchUps: withTeamMatchUps,
31386
- usePublishState: usePublishState,
31387
- withScaleValues: withScaleValues,
31388
- withStatistics: withStatistics,
31389
- withGroupings: withGroupings,
31390
- withOpponents: withOpponents,
31391
- withMatchUps: withMatchUps,
31392
- withSeeding: withSeeding,
31393
- withEvents: withEvents,
31394
- withDraws: withDraws,
31395
- withISO2: withISO2,
31396
- withIOC: withIOC,
31397
- });
31398
- participantIdsWithConflicts = result === null || result === void 0 ? void 0 : result.participantIdsWithConflicts;
31399
- eventsPublishStatuses = result === null || result === void 0 ? void 0 : result.eventsPublishStatuses;
31400
- }
31401
- var participantAttributes = policyDefinitions === null || policyDefinitions === void 0 ? void 0 : policyDefinitions[POLICY_TYPE_PARTICIPANT];
31402
- if (participantAttributes === null || participantAttributes === void 0 ? void 0 : participantAttributes.participant) {
31403
- tournamentParticipants = tournamentParticipants.map(function (participant) {
31404
- return attributeFilter({
31405
- template: participantAttributes.participant,
31406
- source: participant,
31407
- });
31408
- });
31409
30590
  }
31410
- return {
31411
- participantIdsWithConflicts: participantIdsWithConflicts,
31412
- tournamentParticipants: tournamentParticipants,
31413
- eventsPublishStatuses: eventsPublishStatuses,
31414
- };
31415
- }
31416
-
31417
- // arrayMerge can be boolean or an array of target attributes which are arrays to merge
31418
- function deepMerge(existing, incoming, arrayMerge) {
31419
- if (!existing && incoming)
31420
- return incoming;
31421
- if (existing && !incoming)
31422
- return existing;
31423
- if (typeof existing !== 'object' || typeof incoming !== 'object')
31424
- return existing;
31425
- var keys = unique(Object.keys(existing).concat(Object.keys(incoming)));
31426
- return keys.reduce(function (merged, key) {
31427
- if (!incoming[key]) {
31428
- merged[key] = existing[key];
31429
- }
31430
- else if (!existing[key]) {
31431
- merged[key] = incoming[key];
31432
- }
31433
- else if (typeof existing[key] !== typeof incoming[key]) {
31434
- merged[key] = incoming[key];
31435
- }
31436
- else if (Array.isArray(existing[key])) {
31437
- if (arrayMerge === true ||
31438
- (Array.isArray(arrayMerge) && arrayMerge.includes(key))) {
31439
- var mergedArrays = unique(existing[key]
31440
- .map(function (e) { return JSON.stringify(e); })
31441
- .concat(incoming[key].map(function (i) { return JSON.stringify(i); }))).map(function (u) { return JSON.parse(u); });
31442
- merged[key] = mergedArrays;
31443
- }
31444
- else {
31445
- // default is to overwrite existing array with incoming
31446
- merged[key] = incoming[key];
31447
- }
31448
- }
31449
- else if (typeof existing[key] === 'object') {
31450
- merged[key] = deepMerge(existing[key], incoming[key], arrayMerge);
31451
- }
31452
- else {
31453
- 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);
31454
30595
  }
31455
- return merged;
31456
- }, {});
30596
+ finally { if (e_1) throw e_1.error; }
30597
+ }
30598
+ return penaltyId
30599
+ ? __assign(__assign({}, SUCCESS), { penaltyId: penaltyId }) : { error: PARTICIPANT_NOT_FOUND };
31457
30600
  }
31458
-
31459
- // TODO: getTournamentParticipants migration
31460
- function getParticipants(params) {
31461
- var e_1, _a;
31462
- var tournamentRecords = (params || {}).tournamentRecords;
30601
+ function modifyPenalty(params) {
30602
+ var e_2, _a;
30603
+ var tournamentRecords = params.tournamentRecords;
31463
30604
  if (typeof tournamentRecords !== 'object' ||
31464
- !Object.keys(tournamentRecords).length) {
30605
+ !Object.keys(tournamentRecords).length)
31465
30606
  return { error: MISSING_TOURNAMENT_RECORDS };
31466
- }
31467
- var participantMap = {};
31468
- var participants = [];
31469
- var derivedEventInfo = {};
31470
- var derivedDrawInfo = {};
31471
- var matchUps = [];
31472
- var mappedMatchUps = {};
31473
- var participantIdsWithConflicts = [];
31474
30607
  try {
31475
30608
  for (var _b = __values(Object.values(tournamentRecords)), _c = _b.next(); !_c.done; _c = _b.next()) {
31476
30609
  var tournamentRecord = _c.value;
31477
- 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;
31478
- Object.assign(mappedMatchUps, tournamentMappedMatchUps);
31479
- Object.assign(participantMap, tournamentParticipantMap);
31480
- Object.assign(derivedEventInfo, eventInfo);
31481
- Object.assign(derivedDrawInfo, drawInfo);
31482
- participants.push.apply(participants, __spreadArray([], __read((tournamentParticipants !== null && tournamentParticipants !== void 0 ? tournamentParticipants : [])), false));
31483
- matchUps.push.apply(matchUps, __spreadArray([], __read((tournamentMatchUps !== null && tournamentMatchUps !== void 0 ? tournamentMatchUps : [])), false));
31484
- idsWithConflicts === null || idsWithConflicts === void 0 ? void 0 : idsWithConflicts.forEach(function (participantId) {
31485
- if (!participantIdsWithConflicts.includes(participantId))
31486
- participantIdsWithConflicts.push(participantId);
31487
- });
30610
+ var result = modifyPenalty$1(__assign({ tournamentRecord: tournamentRecord }, params));
30611
+ if (result.error && result.error !== PENALTY_NOT_FOUND)
30612
+ return result;
31488
30613
  }
31489
30614
  }
31490
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
30615
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
31491
30616
  finally {
31492
30617
  try {
31493
30618
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
31494
30619
  }
31495
- finally { if (e_1) throw e_1.error; }
30620
+ finally { if (e_2) throw e_2.error; }
31496
30621
  }
31497
- return __assign(__assign({ participantIdsWithConflicts: participantIdsWithConflicts, derivedEventInfo: derivedEventInfo, derivedDrawInfo: derivedDrawInfo, participantMap: participantMap, mappedMatchUps: mappedMatchUps, participants: participants }, SUCCESS), { matchUps: matchUps });
30622
+ return __assign({}, SUCCESS);
31498
30623
  }
31499
- function getCompetitionParticipants(params) {
31500
- var e_2, _a, e_3, _b;
31501
- var tournamentRecords = (params || {}).tournamentRecords;
31502
- if (typeof tournamentRecords !== 'object' ||
31503
- !Object.keys(tournamentRecords).length)
31504
- return { error: MISSING_TOURNAMENT_RECORDS };
31505
- var competitionParticipants = [];
31506
- var participantIdsWithConflicts = [];
31507
- var competitionParticipantIds = [];
31508
- try {
31509
- for (var _c = __values(Object.values(tournamentRecords)), _d = _c.next(); !_d.done; _d = _c.next()) {
31510
- var tournamentRecord = _d.value;
31511
- var _e = getTournamentParticipants(__assign({ tournamentRecord: tournamentRecord }, params)), tournamentParticipants = _e.tournamentParticipants, idsWithConflicts = _e.participantIdsWithConflicts;
31512
- var _loop_1 = function (tournamentParticipant) {
31513
- var participantId = tournamentParticipant.participantId;
31514
- if (!competitionParticipantIds.includes(participantId)) {
31515
- competitionParticipantIds.push(participantId);
31516
- competitionParticipants.push(tournamentParticipant);
31517
- }
31518
- else {
31519
- // merge participant record context across tournaments
31520
- competitionParticipants = competitionParticipants.map(function (participant) {
31521
- return participant.participantId !== participantId
31522
- ? participant
31523
- : deepMerge(participant, tournamentParticipant, true);
31524
- });
31525
- }
31526
- };
31527
- try {
31528
- 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()) {
31529
- var tournamentParticipant = tournamentParticipants_1_1.value;
31530
- _loop_1(tournamentParticipant);
31531
- }
31532
- }
31533
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
31534
- finally {
31535
- try {
31536
- if (tournamentParticipants_1_1 && !tournamentParticipants_1_1.done && (_b = tournamentParticipants_1.return)) _b.call(tournamentParticipants_1);
31537
- }
31538
- finally { if (e_3) throw e_3.error; }
31539
- }
31540
- idsWithConflicts === null || idsWithConflicts === void 0 ? void 0 : idsWithConflicts.forEach(function (participantId) {
31541
- if (!participantIdsWithConflicts.includes(participantId))
31542
- participantIdsWithConflicts.push(participantId);
31543
- });
31544
- }
31545
- }
31546
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
31547
- finally {
31548
- try {
31549
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
31550
- }
31551
- finally { if (e_2) throw e_2.error; }
31552
- }
31553
- return __assign({ competitionParticipants: competitionParticipants, participantIdsWithConflicts: participantIdsWithConflicts }, SUCCESS);
31554
- }
31555
- function publicFindParticipant(_a) {
31556
- var e_4, _b;
31557
- var policyDefinitions = _a.policyDefinitions, tournamentRecords = _a.tournamentRecords, participantId = _a.participantId, inContext = _a.inContext, personId = _a.personId;
31558
- if (!tournamentRecords)
31559
- return { error: MISSING_TOURNAMENT_RECORDS };
31560
- if (typeof participantId !== 'string' && typeof personId !== 'string')
31561
- return { error: MISSING_VALUE, stack: 'publicFindParticipant' };
31562
- var participant, tournamentId;
31563
- try {
31564
- for (var _c = __values(Object.values(tournamentRecords)), _d = _c.next(); !_d.done; _d = _c.next()) {
31565
- var tournamentRecord = _d.value;
31566
- tournamentId = tournamentRecord.tournamentId;
31567
- var tournamentParticipants = getTournamentParticipants({
31568
- policyDefinitions: policyDefinitions,
31569
- tournamentRecord: tournamentRecord,
31570
- inContext: inContext,
31571
- }).tournamentParticipants;
31572
- participant = findParticipant({
31573
- tournamentParticipants: tournamentParticipants,
31574
- internalUse: true,
31575
- policyDefinitions: policyDefinitions,
31576
- participantId: participantId,
31577
- personId: personId,
31578
- });
31579
- if (participant)
31580
- break;
31581
- }
31582
- }
31583
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
31584
- finally {
31585
- try {
31586
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
31587
- }
31588
- finally { if (e_4) throw e_4.error; }
31589
- }
31590
- return __assign({ participant: participant, tournamentId: tournamentId }, SUCCESS);
31591
- }
31592
-
31593
- var penaltyTemplate = function (_a) {
31594
- var _b = _a === void 0 ? {} : _a, _c = _b.penaltyId, penaltyId = _c === void 0 ? UUID() : _c;
31595
- return ({
31596
- refereeParticipantId: undefined,
31597
- penaltyCode: undefined,
31598
- penaltyType: undefined,
31599
- extensions: undefined,
31600
- matchUpId: undefined,
31601
- createdAt: undefined,
31602
- issuedAt: undefined,
31603
- notes: undefined,
31604
- penaltyId: penaltyId,
31605
- });
31606
- };
31607
-
31608
- function addPenalty$1(_a) {
31609
- 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;
31610
- if (!tournamentRecord)
31611
- return { error: MISSING_TOURNAMENT_RECORD };
31612
- if (!participantIds)
31613
- return { error: MISSING_PARTICIPANT_ID };
31614
- if (!penaltyType)
31615
- return { error: MISSING_PENALTY_TYPE };
31616
- // TODO: add penalty timeItem to matchUp.timeItems[]
31617
- var participants = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
31618
- var relevantParticipants = participants.filter(function (participant) {
31619
- return participantIds.includes(participant.participantId);
31620
- });
31621
- if (!relevantParticipants.length)
31622
- return { error: PARTICIPANT_NOT_FOUND };
31623
- var createdAt = new Date().toISOString();
31624
- var penaltyItem = Object.assign(penaltyTemplate({ penaltyId: penaltyId }), {
31625
- refereeParticipantId: refereeParticipantId,
31626
- penaltyCode: penaltyCode,
31627
- penaltyType: penaltyType,
31628
- matchUpId: matchUpId,
31629
- notes: notes,
31630
- issuedAt: issuedAt,
31631
- createdAt: createdAt,
31632
- });
31633
- if (Array.isArray(extensions)) {
31634
- extensions.forEach(function (extension) {
31635
- return addExtension$1({ element: penaltyItem, extension: extension });
31636
- });
31637
- }
31638
- relevantParticipants.forEach(function (participant) {
31639
- if (!participant.penalties)
31640
- participant.penalties = [];
31641
- participant.penalties.push(penaltyItem);
31642
- });
31643
- addNotice({
31644
- topic: MODIFY_PARTICIPANTS,
31645
- payload: {
31646
- tournamentId: tournamentRecord.tournamentId,
31647
- participants: relevantParticipants,
31648
- },
31649
- });
31650
- return __assign(__assign({}, SUCCESS), { penaltyId: penaltyItem.penaltyId });
31651
- }
31652
- function removePenalty$1(_a) {
31653
- var tournamentRecord = _a.tournamentRecord, penaltyId = _a.penaltyId;
31654
- if (!tournamentRecord)
31655
- return { error: MISSING_TOURNAMENT_RECORD };
31656
- if (!penaltyId)
31657
- return { error: MISSING_PENALTY_ID };
31658
- var participants = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
31659
- var modifiedParticipants = [];
31660
- var penaltyRemoved = false;
31661
- var removedPenalty;
31662
- participants.forEach(function (participant) {
31663
- var participantModified = false;
31664
- participant.penalties = (participant.penalties || []).filter(function (penalty) {
31665
- if (penalty.penaltyId === penaltyId) {
31666
- participantModified = true;
31667
- if (!penaltyRemoved) {
31668
- removedPenalty = penalty;
31669
- penaltyRemoved = true;
31670
- }
31671
- }
31672
- if (participantModified)
31673
- modifiedParticipants.push(participant);
31674
- return penalty.penaltyId !== penaltyId;
31675
- });
31676
- });
31677
- if (removedPenalty) {
31678
- addNotice({
31679
- topic: MODIFY_PARTICIPANTS,
31680
- payload: {
31681
- tournamentId: tournamentRecord.tournamentId,
31682
- participants: modifiedParticipants,
31683
- },
31684
- });
31685
- }
31686
- return removedPenalty
31687
- ? __assign(__assign({}, SUCCESS), { penalty: removedPenalty }) : { error: PENALTY_NOT_FOUND };
31688
- }
31689
- function getTournamentPenalties(_a) {
31690
- var tournamentRecord = _a.tournamentRecord;
31691
- if (!tournamentRecord)
31692
- return { error: MISSING_TOURNAMENT_RECORD };
31693
- var participants = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
31694
- var allPenalties = participants.reduce(function (penalties, participant) {
31695
- var participantId = participant.participantId;
31696
- (participant.penalties || []).forEach(function (penalty) {
31697
- var penaltyId = (penalty || {}).penaltyId;
31698
- if (penalties[penaltyId]) {
31699
- penalties[penaltyId].participants.push(participantId);
31700
- }
31701
- else {
31702
- penalties[penaltyId] = __assign(__assign({}, penalty), { participantIds: [participantId] });
31703
- }
31704
- });
31705
- return penalties;
31706
- }, {});
31707
- return { penalties: Object.values(allPenalties) };
31708
- }
31709
- function modifyPenalty$1(_a) {
31710
- var tournamentRecord = _a.tournamentRecord, modifications = _a.modifications, penaltyId = _a.penaltyId;
31711
- if (!tournamentRecord)
31712
- return { error: MISSING_TOURNAMENT_RECORD };
31713
- if (!modifications)
31714
- return { error: INVALID_VALUES, modifications: modifications };
31715
- if (!penaltyId)
31716
- return { error: MISSING_PENALTY_ID };
31717
- var participants = (tournamentRecord === null || tournamentRecord === void 0 ? void 0 : tournamentRecord.participants) || [];
31718
- var validAttributes = Object.keys(penaltyTemplate()).filter(function (attribute) { return attribute !== 'penaltyId'; });
31719
- var validModificationAttributes = Object.keys(modifications).filter(function (attribute) { return validAttributes.includes(attribute); });
31720
- if (!validModificationAttributes.length)
31721
- return { error: NO_VALID_ATTRIBUTES };
31722
- var updatedPenalty;
31723
- var modifiedParticipants = [];
31724
- participants.forEach(function (participant) {
31725
- var participantModified = false;
31726
- participant.penalties = (participant.penalties || []).map(function (penalty) {
31727
- if (penalty.penaltyId === penaltyId) {
31728
- participantModified = true;
31729
- validModificationAttributes.forEach(function (attribute) {
31730
- var _a;
31731
- return Object.assign(penalty, (_a = {}, _a[attribute] = modifications[attribute], _a));
31732
- });
31733
- if (!updatedPenalty)
31734
- updatedPenalty = penalty;
31735
- }
31736
- return penalty;
31737
- });
31738
- if (participantModified)
31739
- modifiedParticipants.push(participant);
31740
- });
31741
- if (updatedPenalty) {
31742
- addNotice({
31743
- topic: MODIFY_PARTICIPANTS,
31744
- payload: {
31745
- tournamentId: tournamentRecord.tournamentId,
31746
- participants: modifiedParticipants,
31747
- },
31748
- });
31749
- }
31750
- return updatedPenalty
31751
- ? __assign(__assign({}, SUCCESS), { penalty: updatedPenalty }) : { error: PENALTY_NOT_FOUND };
31752
- }
31753
-
31754
- function addPenalty(params) {
31755
- var e_1, _a;
31756
- var _b;
31757
- var tournamentRecords = params.tournamentRecords, participantIds = params.participantIds;
31758
- var penaltyId;
31759
- try {
31760
- for (var _c = __values(Object.values(tournamentRecords)), _d = _c.next(); !_d.done; _d = _c.next()) {
31761
- var tournamentRecord = _d.value;
31762
- var participants = (_b = getParticipants$1({
31763
- tournamentRecord: tournamentRecord,
31764
- }).participants) !== null && _b !== void 0 ? _b : [];
31765
- var tournamentParticipantIds = participants === null || participants === void 0 ? void 0 : participants.map(extractAttributes('participantId')).filter(function (participantId) { return participantIds.includes(participantId); });
31766
- if (tournamentParticipantIds.length) {
31767
- var result = addPenalty$1(__assign(__assign({}, params), { penaltyId: params.penaltyId || penaltyId, tournamentRecord: tournamentRecord, participantIds: tournamentParticipantIds }));
31768
- penaltyId = result.penaltyId;
31769
- }
31770
- }
31771
- }
31772
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
31773
- finally {
31774
- try {
31775
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
31776
- }
31777
- finally { if (e_1) throw e_1.error; }
31778
- }
31779
- return penaltyId
31780
- ? __assign(__assign({}, SUCCESS), { penaltyId: penaltyId }) : { error: PARTICIPANT_NOT_FOUND };
31781
- }
31782
- function modifyPenalty(params) {
31783
- var e_2, _a;
31784
- var tournamentRecords = params.tournamentRecords;
31785
- if (typeof tournamentRecords !== 'object' ||
31786
- !Object.keys(tournamentRecords).length)
31787
- return { error: MISSING_TOURNAMENT_RECORDS };
31788
- try {
31789
- for (var _b = __values(Object.values(tournamentRecords)), _c = _b.next(); !_c.done; _c = _b.next()) {
31790
- var tournamentRecord = _c.value;
31791
- var result = modifyPenalty$1(__assign({ tournamentRecord: tournamentRecord }, params));
31792
- if (result.error && result.error !== PENALTY_NOT_FOUND)
31793
- return result;
31794
- }
31795
- }
31796
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
31797
- finally {
31798
- try {
31799
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
31800
- }
31801
- finally { if (e_2) throw e_2.error; }
31802
- }
31803
- return __assign({}, SUCCESS);
31804
- }
31805
- function removePenalty(params) {
31806
- var e_3, _a;
31807
- var tournamentRecords = params.tournamentRecords;
30624
+ function removePenalty(params) {
30625
+ var e_3, _a;
30626
+ var tournamentRecords = params.tournamentRecords;
31808
30627
  if (typeof tournamentRecords !== 'object' ||
31809
30628
  !Object.keys(tournamentRecords).length)
31810
30629
  return { error: MISSING_TOURNAMENT_RECORDS };
@@ -34560,6 +33379,8 @@ function getMatchUpFormatTimingUpdate$1(_a) {
34560
33379
  }
34561
33380
 
34562
33381
  function getEventMatchUpFormatTiming$1(_a) {
33382
+ var _b, _c;
33383
+ var _d, _e;
34563
33384
  var tournamentRecord = _a.tournamentRecord, matchUpFormats = _a.matchUpFormats, // optional - can be retrieved from policy
34564
33385
  categoryType = _a.categoryType, // optional - categoryType is not part of event attributes
34565
33386
  event = _a.event;
@@ -34568,6 +33389,7 @@ function getEventMatchUpFormatTiming$1(_a) {
34568
33389
  if (!event)
34569
33390
  return { error: MISSING_EVENT };
34570
33391
  var matchUpFormatDefinitions = [];
33392
+ var info;
34571
33393
  if (!(matchUpFormats === null || matchUpFormats === void 0 ? void 0 : matchUpFormats.length)) {
34572
33394
  var policy = findPolicy({
34573
33395
  policyType: POLICY_TYPE_SCORING,
@@ -34582,12 +33404,15 @@ function getEventMatchUpFormatTiming$1(_a) {
34582
33404
  name: SCHEDULE_TIMING,
34583
33405
  event: event,
34584
33406
  }).extension;
33407
+ var matchUpAverageTimes = void 0, matchUpRecoveryTimes = void 0;
34585
33408
  if (extension === null || extension === void 0 ? void 0 : extension.value) {
34586
- 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);
34587
33410
  }
34588
33411
  else {
34589
- return { error: MISSING_SCORING_POLICY };
33412
+ (_c = POLICY_SCHEDULING_DEFAULT[POLICY_TYPE_SCHEDULING], matchUpAverageTimes = _c.matchUpAverageTimes, matchUpRecoveryTimes = _c.matchUpRecoveryTimes);
34590
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';
34591
33416
  }
34592
33417
  }
34593
33418
  else {
@@ -34607,7 +33432,7 @@ function getEventMatchUpFormatTiming$1(_a) {
34607
33432
  .filter(Boolean);
34608
33433
  }
34609
33434
  var eventType = event.eventType, eventId = event.eventId, category = event.category;
34610
- 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;
34611
33436
  if (!eventId)
34612
33437
  return { error: MISSING_EVENT };
34613
33438
  var eventMatchUpFormatTiming = matchUpFormatDefinitions.map(function (_a) {
@@ -34620,9 +33445,9 @@ function getEventMatchUpFormatTiming$1(_a) {
34620
33445
  eventType: eventType,
34621
33446
  event: event,
34622
33447
  });
34623
- return Object.assign({}, __assign(__assign({}, timing), { description: description, matchUpFormat: matchUpFormat }));
33448
+ return __assign({ matchUpFormat: matchUpFormat, description: description }, timing);
34624
33449
  });
34625
- return { eventMatchUpFormatTiming: eventMatchUpFormatTiming };
33450
+ return definedAttributes({ eventMatchUpFormatTiming: eventMatchUpFormatTiming, info: info });
34626
33451
  }
34627
33452
 
34628
33453
  function getEventMatchUpFormatTiming(_a) {
@@ -35972,6 +34797,14 @@ function modifyParticipantMatchUpsCount(_a) {
35972
34797
  });
35973
34798
  }
35974
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
+
35975
34808
  function processAlreadyScheduledMatchUps(_a) {
35976
34809
  var e_1, _b;
35977
34810
  var _c, _d;
@@ -39913,12 +38746,11 @@ var policyGovernor$2 = {
39913
38746
  };
39914
38747
 
39915
38748
  function getParticipantScaleItem$1(_a) {
39916
- 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;
39917
38750
  var result = publicFindParticipant({
39918
38751
  tournamentRecords: tournamentRecords,
39919
38752
  policyDefinitions: policyDefinitions,
39920
38753
  participantId: participantId,
39921
- inContext: inContext,
39922
38754
  personId: personId,
39923
38755
  });
39924
38756
  if (result.error)
@@ -40407,7 +39239,7 @@ function matchUpActions$2(_a) {
40407
39239
  participantsAvailable === null || participantsAvailable === void 0 ? void 0 : participantsAvailable.forEach(function (participant) {
40408
39240
  var _a;
40409
39241
  var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === participant.participantId; });
40410
- // TODO: determine if this is in fact used downstream
39242
+ // used to sort available participants
40411
39243
  participant.entryPosition = entry === null || entry === void 0 ? void 0 : entry.entryPosition;
40412
39244
  });
40413
39245
  if (availableParticipantIds_1.length) {
@@ -54460,391 +53292,1559 @@ function setState$2(value, deepCopyOption) {
54460
53292
  }
54461
53293
  }
54462
53294
  }
54463
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
54464
- finally {
54465
- try {
54466
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
54467
- }
54468
- 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;
54469
54705
  }
54470
- }
54471
- else {
54472
- try {
54473
- for (var _e = __values(Object.values(value)), _f = _e.next(); !_f.done; _f = _e.next()) {
54474
- var m = _f.value;
54475
- if (m.matchUpId) {
54476
- keyedMatchUps[m.matchUpId] = deepCopyOption ? makeDeepCopy(m) : m;
54477
- if (!matchUpId)
54478
- matchUpId = m.matchUpId;
54479
- }
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);
54480
54711
  }
54481
54712
  }
54482
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
54483
- finally {
54484
- try {
54485
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
54486
- }
54487
- 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;
54488
54723
  }
54489
- }
54490
- return deepCopyOption ? makeDeepCopy(value) : value;
54491
- }
54492
- function getMatchUp() {
54493
- return keyedMatchUps[matchUpId];
54494
- }
54495
- function getMatchUps() {
54496
- return Object.values(keyedMatchUps);
54497
- }
54498
- function reset() {
54499
- matchUpId = undefined;
54500
- keyedMatchUps = {};
54501
- }
54502
- function getState$2(params) {
54503
- 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 };
54504
54727
  }
54505
54728
 
54506
- var matchUpEngine = (function () {
54507
- var engine = {
54508
- getState: function (params) { return getState$2(params); },
54509
- version: function () { return factoryVersion(); },
54510
- reset: function () {
54511
- reset();
54512
- return __assign({}, SUCCESS);
54513
- },
54514
- drawId: undefined,
54515
- error: undefined,
54516
- success: false,
54517
- devContext: function (contextCriteria) {
54518
- setDevContext(contextCriteria);
54519
- return engine;
54520
- },
54521
- setState: function (definition, deepCopyOption, deepCopyAttributes) {
54522
- setDeepCopy(deepCopyOption, deepCopyAttributes);
54523
- var result = setState$2(definition);
54524
- return processResult(result);
54525
- },
54526
- };
54527
- function processResult(result) {
54528
- if (result === null || result === void 0 ? void 0 : result.error) {
54529
- engine.error = result.error;
54530
- engine.success = false;
54531
- }
54532
- else {
54533
- engine.error = undefined;
54534
- engine.success = true;
54535
- engine.drawId = result.drawId;
54536
- }
54537
- return engine;
54538
- }
54539
- importGovernors([
54540
- tieFormatGovernor,
54541
- historyGovernor,
54542
- queryGovernor$1,
54543
- scoreGovernor,
54544
- ]);
54545
- return engine;
54546
- function importGovernors(governors) {
54547
- governors.forEach(function (governor) {
54548
- Object.keys(governor).forEach(function (methodName) {
54549
- engine[methodName] = function (params) {
54550
- if (getDevContext()) {
54551
- return invoke({ params: params, governor: governor, methodName: methodName });
54552
- }
54553
- else {
54554
- try {
54555
- 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;
54556
54774
  }
54557
- catch (err) {
54558
- handleCaughtError({
54559
- engineName: 'matchUpEngine',
54560
- methodName: methodName,
54561
- params: params,
54562
- err: err,
54775
+ if (withIOC || withISO2)
54776
+ addNationalityCode({
54777
+ participant: individualParticipant,
54778
+ withISO2: withISO2,
54779
+ withIOC: withIOC,
54563
54780
  });
54564
- }
54565
- }
54566
- };
54567
- });
54781
+ return individualParticipant;
54782
+ });
54783
+ }
54568
54784
  });
54569
54785
  }
54570
- function invoke(_a) {
54571
- var params = _a.params, governor = _a.governor, methodName = _a.methodName;
54572
- engine.error = undefined;
54573
- engine.success = false;
54574
- var matchUp = (params === null || params === void 0 ? void 0 : params.matchUp) || getMatchUp();
54575
- var matchUps = (params === null || params === void 0 ? void 0 : params.matchUps) || getMatchUps();
54576
- var snapshot = (params === null || params === void 0 ? void 0 : params.rollbackOnError) && makeDeepCopy(matchUp, false, true);
54577
- params = __assign(__assign({}, params), { matchUpId: matchUp === null || matchUp === void 0 ? void 0 : matchUp.matchUpId, matchUps: matchUps, matchUp: matchUp });
54578
- var result = governor[methodName](params);
54579
- if (result === null || result === void 0 ? void 0 : result.error) {
54580
- if (snapshot)
54581
- setState$2(snapshot);
54582
- return __assign(__assign({}, result), { rolledBack: !!snapshot });
54583
- }
54584
- var notify = (result === null || result === void 0 ? void 0 : result.success) &&
54585
- (params === null || params === void 0 ? void 0 : params.delayNotify) !== true &&
54586
- (params === null || params === void 0 ? void 0 : params.doNotNotify) !== true;
54587
- if (notify)
54588
- notifySubscribers();
54589
- if (notify || !(result === null || result === void 0 ? void 0 : result.success) || (params === null || params === void 0 ? void 0 : params.doNotNotify))
54590
- deleteNotices();
54591
- return result;
54592
- }
54593
- })();
54594
-
54595
- function matchUpEngineAsync(test) {
54596
- var result = createInstanceState();
54597
- if (result.error && !test)
54598
- return result;
54599
- var engine = {
54600
- getState: function (params) { return getState$2(params); },
54601
- version: function () { return factoryVersion(); },
54602
- reset: function () {
54603
- reset();
54604
- return __assign({}, SUCCESS);
54605
- },
54606
- drawId: undefined,
54607
- error: undefined,
54608
- success: false,
54609
- devContext: function (contextCriteria) {
54610
- setDevContext(contextCriteria);
54611
- return engine;
54612
- },
54613
- setState: function (definition, deepCopyOption, deepCopyAttributes) {
54614
- setDeepCopy(deepCopyOption, deepCopyAttributes);
54615
- var result = setState$2(definition);
54616
- return processResult(result);
54617
- },
54618
- };
54619
- function processResult(result) {
54620
- if (result === null || result === void 0 ? void 0 : result.error) {
54621
- engine.error = result.error;
54622
- engine.success = false;
54623
- }
54624
- else {
54625
- engine.error = undefined;
54626
- engine.success = true;
54627
- engine.drawId = result.drawId;
54628
- }
54629
- return engine;
54630
- }
54631
- importGovernors([
54632
- tieFormatGovernor,
54633
- historyGovernor,
54634
- queryGovernor$1,
54635
- scoreGovernor,
54636
- ]);
54637
- return engine;
54638
- function importGovernors(governors) {
54639
- return __awaiter(this, void 0, void 0, function () {
54640
- var _loop_1, governors_1, governors_1_1, governor;
54641
- var e_1, _a;
54642
- var _this = this;
54643
- return __generator(this, function (_b) {
54644
- _loop_1 = function (governor) {
54645
- var e_2, _c;
54646
- var governorMethods = Object.keys(governor);
54647
- var _loop_2 = function (methodName) {
54648
- engine[methodName] = function (params) { return __awaiter(_this, void 0, void 0, function () {
54649
- var err_1;
54650
- return __generator(this, function (_a) {
54651
- switch (_a.label) {
54652
- case 0:
54653
- if (!getDevContext()) return [3 /*break*/, 2];
54654
- return [4 /*yield*/, invoke({ params: params, governor: governor, methodName: methodName })];
54655
- case 1: return [2 /*return*/, _a.sent()];
54656
- case 2:
54657
- _a.trys.push([2, 4, , 5]);
54658
- return [4 /*yield*/, invoke({ params: params, governor: governor, methodName: methodName })];
54659
- case 3: return [2 /*return*/, _a.sent()];
54660
- case 4:
54661
- err_1 = _a.sent();
54662
- handleCaughtError({
54663
- engineName: 'matchUpEngine',
54664
- methodName: methodName,
54665
- params: params,
54666
- err: err_1,
54667
- });
54668
- return [3 /*break*/, 5];
54669
- case 5: return [2 /*return*/];
54670
- }
54671
- });
54672
- }); };
54673
- };
54674
- try {
54675
- 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()) {
54676
- var methodName = governorMethods_1_1.value;
54677
- _loop_2(methodName);
54678
- }
54679
- }
54680
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
54681
- finally {
54682
- try {
54683
- if (governorMethods_1_1 && !governorMethods_1_1.done && (_c = governorMethods_1.return)) _c.call(governorMethods_1);
54684
- }
54685
- finally { if (e_2) throw e_2.error; }
54686
- }
54687
- };
54688
- try {
54689
- for (governors_1 = __values(governors), governors_1_1 = governors_1.next(); !governors_1_1.done; governors_1_1 = governors_1.next()) {
54690
- governor = governors_1_1.value;
54691
- _loop_1(governor);
54692
- }
54693
- }
54694
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
54695
- finally {
54696
- try {
54697
- if (governors_1_1 && !governors_1_1.done && (_a = governors_1.return)) _a.call(governors_1);
54698
- }
54699
- finally { if (e_1) throw e_1.error; }
54700
- }
54701
- return [2 /*return*/];
54702
- });
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,
54703
54829
  });
54830
+ participantIdsWithConflicts = result === null || result === void 0 ? void 0 : result.participantIdsWithConflicts;
54831
+ eventsPublishStatuses = result === null || result === void 0 ? void 0 : result.eventsPublishStatuses;
54704
54832
  }
54705
- function invoke(_a) {
54706
- var params = _a.params, governor = _a.governor, methodName = _a.methodName;
54707
- return __awaiter(this, void 0, void 0, function () {
54708
- var matchUp, matchUps, snapshot, result, notify;
54709
- return __generator(this, function (_b) {
54710
- switch (_b.label) {
54711
- case 0:
54712
- engine.success = false;
54713
- engine.error = undefined;
54714
- matchUp = (params === null || params === void 0 ? void 0 : params.matchUp) || getMatchUp();
54715
- matchUps = (params === null || params === void 0 ? void 0 : params.matchUps) || getMatchUps();
54716
- snapshot = (params === null || params === void 0 ? void 0 : params.rollbackOnError) && makeDeepCopy(matchUp, false, true);
54717
- params = __assign(__assign({}, params), { matchUpId: matchUp === null || matchUp === void 0 ? void 0 : matchUp.matchUpId, matchUps: matchUps, matchUp: matchUp });
54718
- result = governor[methodName](params);
54719
- if (result === null || result === void 0 ? void 0 : result.error) {
54720
- if (snapshot)
54721
- setState$2(snapshot);
54722
- return [2 /*return*/, __assign(__assign({}, result), { rolledBack: !!snapshot })];
54723
- }
54724
- notify = (result === null || result === void 0 ? void 0 : result.success) &&
54725
- (params === null || params === void 0 ? void 0 : params.delayNotify) !== true &&
54726
- (params === null || params === void 0 ? void 0 : params.doNotNotify) !== true;
54727
- if (!notify) return [3 /*break*/, 2];
54728
- return [4 /*yield*/, notifySubscribersAsync()];
54729
- case 1:
54730
- _b.sent();
54731
- _b.label = 2;
54732
- case 2:
54733
- if (notify || !(result === null || result === void 0 ? void 0 : result.success) || (params === null || params === void 0 ? void 0 : params.doNotNotify))
54734
- deleteNotices();
54735
- return [2 /*return*/, result];
54736
- }
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,
54737
54839
  });
54738
54840
  });
54739
54841
  }
54740
- }
54741
-
54742
- function newTournamentRecord(params) {
54743
- var attributes = params || {};
54744
- if (!attributes.tournamentId)
54745
- attributes.tournamentId = UUID();
54746
- if (attributes.startDate &&
54747
- !isISODateString(attributes.startDate) &&
54748
- !validDateString.test(attributes.startDate)) {
54749
- return { error: INVALID_DATE };
54750
- }
54751
- if (attributes.endDate &&
54752
- !isISODateString(attributes.endDate) &&
54753
- !validDateString.test(attributes.endDate)) {
54754
- return { error: INVALID_DATE };
54755
- }
54756
- if (attributes.extensions) {
54757
- attributes.extensions = attributes.extensions.filter(isValidExtension);
54758
- }
54759
- return __assign({}, attributes);
54760
- }
54761
-
54762
- function setState$1(tournament, deepCopyOption) {
54763
- var _a;
54764
- var _b;
54765
- if (typeof tournament !== 'object')
54766
- return { error: INVALID_OBJECT };
54767
- var tournamentId = ((_b = tournament.unifiedTournamentId) === null || _b === void 0 ? void 0 : _b.tournamentId) || tournament.tournamentId;
54768
- if (!tournamentId)
54769
- return { error: MISSING_TOURNAMENT_ID };
54770
- var tournamentRecord = deepCopyOption !== false ? makeDeepCopy(tournament) : tournament;
54771
- setTournamentRecords((_a = {}, _a[tournamentId] = tournamentRecord, _a));
54772
- setTournamentId(tournamentId); // must be set AFTER tournamentRecord
54773
- return tournamentRecord;
54774
- }
54775
- function getState$1(_a) {
54776
- var _b = _a.convertExtensions, convertExtensions = _b === void 0 ? false : _b, _c = _a.removeExtensions, removeExtensions = _c === void 0 ? false : _c, tournamentId = _a.tournamentId;
54777
- if (typeof tournamentId !== 'string')
54778
- return {};
54779
- var tournamentRecord = getTournamentRecord(tournamentId);
54780
54842
  return {
54781
- tournamentRecord: makeDeepCopy(tournamentRecord, convertExtensions, false, removeExtensions),
54843
+ participantIdsWithConflicts: participantIdsWithConflicts,
54844
+ tournamentParticipants: tournamentParticipants,
54845
+ eventsPublishStatuses: eventsPublishStatuses,
54782
54846
  };
54783
54847
  }
54784
- // prefetch can be triggered based on method governor, e.g. not necessary for query
54785
- function paramsMiddleware$1(tournamentRecord, params, prefetch) {
54786
- var _a;
54787
- if (params) {
54788
- var drawId = params.drawId || ((_a = params.matchUp) === null || _a === void 0 ? void 0 : _a.drawId);
54789
- if (drawId) {
54790
- var _b = findEvent({
54791
- tournamentRecord: tournamentRecord,
54792
- drawId: drawId,
54793
- }), event_1 = _b.event, drawDefinition = _b.drawDefinition;
54794
- params = __assign(__assign({}, params), { event: event_1, drawDefinition: drawDefinition });
54795
- if (prefetch) {
54796
- var matchUpsMap = getMatchUpsMap({ drawDefinition: drawDefinition });
54797
- var inContextDrawMatchUps = getAllDrawMatchUps({
54798
- inContext: true,
54799
- drawDefinition: drawDefinition,
54800
- matchUpsMap: matchUpsMap,
54801
- }).matchUps;
54802
- params.matchUpsMap = matchUpsMap;
54803
- params.inContextDrawMatchUps = inContextDrawMatchUps;
54804
- }
54805
- }
54806
- if (params.eventId && !params.event) {
54807
- var event_2 = findEvent({
54808
- eventId: params.eventId,
54809
- tournamentRecord: tournamentRecord,
54810
- }).event;
54811
- if (event_2) {
54812
- params = __assign(__assign({}, params), { event: event_2 });
54813
- }
54814
- }
54815
- }
54816
- return params;
54817
- }
54818
-
54819
- function getEligibleVoluntaryConsolationParticipants(params) {
54820
- if (!params.tournamentRecord)
54821
- return { error: MISSING_TOURNAMENT_RECORD };
54822
- return getEligibleVoluntaryConsolationParticipants$1(params);
54823
- }
54824
-
54825
- function getParticipantEventDetails(_a) {
54826
- var tournamentRecord = _a.tournamentRecord, participantId = _a.participantId;
54827
- if (!tournamentRecord)
54828
- return { error: MISSING_TOURNAMENT_RECORD };
54829
- if (!participantId)
54830
- return { error: MISSING_PARTICIPANT_ID };
54831
- // relveantParticipantIds is the target participantId along with any TEAM or PAIR participantIds to which participantId belongs
54832
- var relevantParticipantIds = [participantId].concat((tournamentRecord.participants || [])
54833
- .filter(function (participant) {
54834
- var _a;
54835
- return (participant === null || participant === void 0 ? void 0 : participant.participantType) &&
54836
- [TEAM, PAIR].includes(participant.participantType) &&
54837
- ((_a = participant.individualParticipantIds) === null || _a === void 0 ? void 0 : _a.includes(participantId));
54838
- })
54839
- .map(function (participant) { return participant.participantId; }));
54840
- var relevantEvents = (tournamentRecord.events || [])
54841
- .filter(function (event) {
54842
- var enteredParticipantIds = ((event === null || event === void 0 ? void 0 : event.entries) || []).map(function (entry) { return entry.participantId; });
54843
- return overlap(enteredParticipantIds, relevantParticipantIds);
54844
- })
54845
- .map(function (event) { return ({ eventName: event.eventName, eventId: event.eventId }); });
54846
- return { eventDetails: relevantEvents };
54847
- }
54848
54848
 
54849
54849
  function getParticipantMembership(_a) {
54850
54850
  var tournamentRecord = _a.tournamentRecord, participantId = _a.participantId;
@@ -58602,7 +58602,7 @@ function setTournamentCategories(_a) {
58602
58602
  // bulk update when tournament dates change
58603
58603
  function updateCourtAvailability(_a) {
58604
58604
  var e_1, _b, e_2, _c;
58605
- var _d;
58605
+ var _d, _e;
58606
58606
  var tournamentRecord = _a.tournamentRecord;
58607
58607
  if (!tournamentRecord)
58608
58608
  return { error: MISSING_TOURNAMENT_RECORD };
@@ -58610,8 +58610,8 @@ function updateCourtAvailability(_a) {
58610
58610
  var tournamentDates = dateRange(startDate, endDate);
58611
58611
  var courts = [];
58612
58612
  try {
58613
- for (var _e = __values(tournamentRecord.venues || []), _f = _e.next(); !_f.done; _f = _e.next()) {
58614
- var venue = _f.value;
58613
+ for (var _f = __values(tournamentRecord.venues || []), _g = _f.next(); !_g.done; _g = _f.next()) {
58614
+ var venue = _g.value;
58615
58615
  if ((_d = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _d === void 0 ? void 0 : _d.length)
58616
58616
  courts.push.apply(courts, __spreadArray([], __read(venue.courts), false));
58617
58617
  }
@@ -58619,12 +58619,12 @@ function updateCourtAvailability(_a) {
58619
58619
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
58620
58620
  finally {
58621
58621
  try {
58622
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
58622
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
58623
58623
  }
58624
58624
  finally { if (e_1) throw e_1.error; }
58625
58625
  }
58626
58626
  var _loop_1 = function (court) {
58627
- var _g = (court.dateAvailability || []).reduce(function (extents, availability) {
58627
+ var _h = (court.dateAvailability || []).reduce(function (extents, availability) {
58628
58628
  var startMinutes = timeStringMinutes(extents.startTime);
58629
58629
  var endMinutes = timeStringMinutes(extents.endTime);
58630
58630
  if (availability.startTime &&
@@ -58634,12 +58634,15 @@ function updateCourtAvailability(_a) {
58634
58634
  timeStringMinutes(availability.endTime) > endMinutes)
58635
58635
  extents.endTime = availability.endTime;
58636
58636
  return extents;
58637
- }, { 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;
58638
58638
  var updatedDateAvailability = tournamentDates.map(function (date) {
58639
58639
  var _a;
58640
58640
  var existing = (_a = court.dateAvailability) === null || _a === void 0 ? void 0 : _a.find(function (availability) { return availability.date === date; });
58641
58641
  return existing || { date: date, startTime: startTime, endTime: endTime };
58642
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);
58643
58646
  court.dateAvailability = updatedDateAvailability;
58644
58647
  };
58645
58648
  try {
@@ -58705,12 +58708,10 @@ function setTournamentDates(_a) {
58705
58708
  });
58706
58709
  return __assign(__assign({}, SUCCESS), { unscheduledMatchUpIds: unscheduledMatchUpIds });
58707
58710
  }
58708
- // TODO: check all courts in all venues for dateAvailability that is outside of tournament date range
58709
58711
  function setTournamentStartDate(_a) {
58710
58712
  var tournamentRecord = _a.tournamentRecord, startDate = _a.startDate;
58711
58713
  return setTournamentDates({ tournamentRecord: tournamentRecord, startDate: startDate });
58712
58714
  }
58713
- // TODO: check all courts in all venues for dateAvailability that is outside of tournament date range
58714
58715
  function setTournamentEndDate(_a) {
58715
58716
  var tournamentRecord = _a.tournamentRecord, endDate = _a.endDate;
58716
58717
  return setTournamentDates({ tournamentRecord: tournamentRecord, endDate: endDate });
@@ -63932,7 +63933,8 @@ function generateDrawDefinition(params) {
63932
63933
  drawDefinition.links = [];
63933
63934
  drawDefinition.links.push(link);
63934
63935
  }
63935
- 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));
63936
63938
  if (typeof voluntaryConsolation === 'object') {
63937
63939
  addVoluntaryConsolationStructure(__assign(__assign({}, voluntaryConsolation), { tournamentRecord: tournamentRecord, appliedPolicies: appliedPolicies, drawDefinition: drawDefinition, matchUpType: matchUpType }));
63938
63940
  }