tods-competition-factory 1.8.5 → 1.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2898,7 +2898,7 @@ var matchUpFormatCode = {
2898
2898
  };
2899
2899
 
2900
2900
  function factoryVersion() {
2901
- return '1.8.5';
2901
+ return '1.8.7';
2902
2902
  }
2903
2903
 
2904
2904
  function getObjectTieFormat(obj) {
@@ -21910,31 +21910,23 @@ function getMatchUpContextIds(_a) {
21910
21910
  }
21911
21911
 
21912
21912
  function addMatchUpScheduledTime$2(params) {
21913
+ var stack = 'addMatchUpScheduledTime';
21913
21914
  var matchUp = params.matchUp;
21914
21915
  var removePriorValues = params.removePriorValues, tournamentRecord = params.tournamentRecord, drawDefinition = params.drawDefinition, disableNotice = params.disableNotice, scheduledTime = params.scheduledTime, matchUpId = params.matchUpId;
21915
21916
  if (!matchUpId)
21916
- return { error: MISSING_MATCHUP_ID };
21917
+ return decorateResult({ result: { error: MISSING_MATCHUP_ID }, stack: stack });
21917
21918
  // must support undefined as a value so that scheduledTime can be cleared
21918
21919
  if (!validTimeValue(scheduledTime))
21919
- return { error: INVALID_TIME };
21920
+ return decorateResult({ result: { error: INVALID_TIME }, stack: stack });
21920
21921
  if (!matchUp) {
21921
21922
  var result = findMatchUp$1({ drawDefinition: drawDefinition, matchUpId: matchUpId });
21922
21923
  if (result.error)
21923
- return result;
21924
+ return decorateResult({ result: result, stack: stack });
21924
21925
  matchUp = result.matchUp;
21925
21926
  }
21926
21927
  var timeDate = extractDate(scheduledTime);
21927
- var stack = 'addMatchUpScheduledTime';
21928
- if (timeDate) {
21929
- var scheduledDate = scheduledMatchUpDate({ matchUp: matchUp }).scheduledDate;
21930
- if (scheduledDate && scheduledDate !== timeDate) {
21931
- return decorateResult({
21932
- info: "date in time: ".concat(timeDate, " does not corresponde to scheduledDate: ").concat(scheduledDate),
21933
- result: { error: INVALID_TIME },
21934
- stack: stack,
21935
- });
21936
- }
21937
- }
21928
+ var scheduledDate = scheduledMatchUpDate({ matchUp: matchUp }).scheduledDate;
21929
+ var keepDate = timeDate && !scheduledDate;
21938
21930
  var existingTimeModifiers = matchUpTimeModifiers({ matchUp: matchUp }).timeModifiers || [];
21939
21931
  if (existingTimeModifiers === null || existingTimeModifiers === void 0 ? void 0 : existingTimeModifiers.length) {
21940
21932
  var result = addMatchUpTimeModifiers({
@@ -21947,10 +21939,10 @@ function addMatchUpScheduledTime$2(params) {
21947
21939
  matchUp: matchUp,
21948
21940
  });
21949
21941
  if (result === null || result === void 0 ? void 0 : result.error)
21950
- return result;
21942
+ return decorateResult({ result: result, stack: stack });
21951
21943
  }
21952
21944
  // All times stored as military time
21953
- var militaryTime = convertTime(scheduledTime, true, true);
21945
+ var militaryTime = convertTime(scheduledTime, true, keepDate);
21954
21946
  var itemValue = militaryTime;
21955
21947
  var timeItem = {
21956
21948
  itemType: SCHEDULED_TIME,
@@ -21968,14 +21960,19 @@ function addMatchUpScheduledTime$2(params) {
21968
21960
  }
21969
21961
  function addMatchUpTimeModifiers(_a) {
21970
21962
  var removePriorValues = _a.removePriorValues, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, disableNotice = _a.disableNotice, timeModifiers = _a.timeModifiers, matchUpId = _a.matchUpId, matchUp = _a.matchUp;
21963
+ var stack = 'addMatchUpTimeModifiers';
21971
21964
  if (!matchUpId)
21972
- return { error: MISSING_MATCHUP_ID };
21965
+ return decorateResult({ result: { error: MISSING_MATCHUP_ID }, stack: stack });
21973
21966
  if (timeModifiers !== undefined && !Array.isArray(timeModifiers))
21974
- return { error: INVALID_VALUES, info: mustBeAnArray('timeModifiers') };
21967
+ return decorateResult({
21968
+ info: mustBeAnArray('timeModifiers'),
21969
+ result: { error: INVALID_VALUES },
21970
+ stack: stack,
21971
+ });
21975
21972
  if (!matchUp) {
21976
21973
  var result = findMatchUp$1({ drawDefinition: drawDefinition, matchUpId: matchUpId });
21977
21974
  if (result.error)
21978
- return result;
21975
+ return decorateResult({ result: result, stack: stack });
21979
21976
  matchUp = result.matchUp;
21980
21977
  }
21981
21978
  var existingTimeModifiers = matchUpTimeModifiers({ matchUp: matchUp }).timeModifiers || [];
@@ -21998,7 +21995,7 @@ function addMatchUpTimeModifiers(_a) {
21998
21995
  matchUpId: matchUpId,
21999
21996
  });
22000
21997
  if (result.error)
22001
- return result;
21998
+ return decorateResult({ result: result, stack: stack });
22002
21999
  }
22003
22000
  // undefined value when array is empty;
22004
22001
  var itemValue = !(timeModifiers === null || timeModifiers === void 0 ? void 0 : timeModifiers.length)
@@ -38136,283 +38133,6 @@ function getMatchUpDailyLimitsUpdate$1(_a) {
38136
38133
  });
38137
38134
  }
38138
38135
 
38139
- var stageOrder = drawDefinitionConstants.stageOrder;
38140
- function getProfileRounds(_a) {
38141
- var _b;
38142
- var tournamentRecords = _a.tournamentRecords, schedulingProfile = _a.schedulingProfile, tournamentRecord = _a.tournamentRecord, withRoundId = _a.withRoundId;
38143
- if (tournamentRecord && !tournamentRecords) {
38144
- if (typeof tournamentRecord !== 'object') {
38145
- return { error: INVALID_TOURNAMENT_RECORD };
38146
- }
38147
- else {
38148
- tournamentRecords = (_b = {}, _b[tournamentRecord.tournamentId] = tournamentRecord, _b);
38149
- }
38150
- }
38151
- if (schedulingProfile) {
38152
- var profileValidity = validateSchedulingProfile({
38153
- tournamentRecords: tournamentRecords,
38154
- schedulingProfile: schedulingProfile,
38155
- });
38156
- if (profileValidity.error)
38157
- return profileValidity;
38158
- }
38159
- if (!schedulingProfile && tournamentRecords) {
38160
- var result = getSchedulingProfile$1({ tournamentRecords: tournamentRecords });
38161
- if (result.error)
38162
- return result;
38163
- schedulingProfile = result.schedulingProfile;
38164
- }
38165
- if (!schedulingProfile)
38166
- return { error: NOT_FOUND };
38167
- var segmentedRounds = {};
38168
- var profileRounds = schedulingProfile
38169
- .map(function (_a) {
38170
- var venues = _a.venues, scheduleDate = _a.scheduleDate;
38171
- return venues.map(function (_a) {
38172
- var rounds = _a.rounds;
38173
- return rounds.map(function (round) {
38174
- var _a;
38175
- var roundRef = getRoundId(round);
38176
- if ((_a = roundRef.roundSegment) === null || _a === void 0 ? void 0 : _a.segmentsCount) {
38177
- segmentedRounds[roundRef.id] = roundRef.roundSegment.segmentsCount;
38178
- }
38179
- return definedAttributes(__assign({ id: withRoundId ? roundRef.id : undefined, scheduleDate: scheduleDate }, roundRef));
38180
- });
38181
- });
38182
- })
38183
- .flat(Infinity);
38184
- return { profileRounds: profileRounds, segmentedRounds: segmentedRounds };
38185
- }
38186
- function getRoundId(obj) {
38187
- var containerStructureId = obj.containerStructureId, roundSegment = obj.roundSegment, isRoundRobin = obj.isRoundRobin, tournamentId = obj.tournamentId, roundNumber = obj.roundNumber, structureId = obj.structureId, eventId = obj.eventId, drawId = obj.drawId;
38188
- var relevantStructureId = isRoundRobin ? containerStructureId : structureId;
38189
- // retain order
38190
- var id = [
38191
- tournamentId,
38192
- eventId,
38193
- drawId,
38194
- relevantStructureId,
38195
- roundNumber, // 5
38196
- ].join('|');
38197
- return definedAttributes({
38198
- id: id,
38199
- roundSegment: roundSegment,
38200
- tournamentId: tournamentId,
38201
- eventId: eventId,
38202
- drawId: drawId,
38203
- structureId: relevantStructureId,
38204
- roundNumber: roundNumber,
38205
- });
38206
- }
38207
- function getRoundProfile(matchUps) {
38208
- var matchUpsCount = matchUps.length;
38209
- var byeCount = matchUps.filter(function (_a) {
38210
- var sides = _a.sides;
38211
- return sides === null || sides === void 0 ? void 0 : sides.some(function (_a) {
38212
- var bye = _a.bye;
38213
- return bye;
38214
- });
38215
- }).length || 0;
38216
- var completedCount = matchUps.filter(function (_a) {
38217
- var winningSide = _a.winningSide, matchUpStatus = _a.matchUpStatus;
38218
- return winningSide || completedMatchUpStatuses.includes(matchUpStatus);
38219
- }).length || 0;
38220
- var scheduledCount = matchUps.filter(function (_a) {
38221
- var schedule = _a.schedule;
38222
- return (schedule === null || schedule === void 0 ? void 0 : schedule.scheduledDate) && (schedule === null || schedule === void 0 ? void 0 : schedule.scheduledTime);
38223
- }).length || 0;
38224
- var consideredCount = matchUpsCount - byeCount;
38225
- var isComplete = consideredCount === completedCount;
38226
- var unscheduledCount = consideredCount - scheduledCount;
38227
- var incompleteCount = consideredCount - scheduledCount;
38228
- var isScheduled = consideredCount === scheduledCount;
38229
- return {
38230
- unscheduledCount: unscheduledCount,
38231
- incompleteCount: incompleteCount,
38232
- scheduledCount: scheduledCount,
38233
- completedCount: completedCount,
38234
- matchUpsCount: matchUpsCount,
38235
- isScheduled: isScheduled,
38236
- isComplete: isComplete,
38237
- byeCount: byeCount,
38238
- };
38239
- }
38240
- function getRounds(_a) {
38241
- var _b;
38242
- var _c;
38243
- var excludeScheduleDateProfileRounds = _a.excludeScheduleDateProfileRounds, excludeScheduledRounds = _a.excludeScheduledRounds, excludeCompletedRounds = _a.excludeCompletedRounds, inContextMatchUps = _a.inContextMatchUps, tournamentRecords = _a.tournamentRecords, schedulingProfile = _a.schedulingProfile, tournamentRecord = _a.tournamentRecord, withSplitRounds = _a.withSplitRounds, matchUpFilters = _a.matchUpFilters, withRoundId = _a.withRoundId, context = _a.context;
38244
- if (inContextMatchUps &&
38245
- !Array.isArray(inContextMatchUps || typeof inContextMatchUps[0] !== 'object')) {
38246
- return { error: INVALID_VALUES, inContextMatchUps: inContextMatchUps };
38247
- }
38248
- if (tournamentRecord && !tournamentRecords) {
38249
- if (typeof tournamentRecord !== 'object') {
38250
- return { error: INVALID_TOURNAMENT_RECORD };
38251
- }
38252
- else {
38253
- tournamentRecords = (_b = {}, _b[tournamentRecord.tournamentId] = tournamentRecord, _b);
38254
- }
38255
- }
38256
- var noTournamentRecords = typeof tournamentRecords !== 'object' ||
38257
- !Object.keys(tournamentRecords).length;
38258
- var needsTournamentRecords = !inContextMatchUps ||
38259
- (!schedulingProfile &&
38260
- (excludeScheduleDateProfileRounds ||
38261
- excludeCompletedRounds ||
38262
- schedulingProfile ||
38263
- withSplitRounds));
38264
- if (needsTournamentRecords && noTournamentRecords)
38265
- return { error: MISSING_TOURNAMENT_RECORDS };
38266
- var events = Object.values(tournamentRecords !== null && tournamentRecords !== void 0 ? tournamentRecords : {})
38267
- .map(function (_a) {
38268
- var events = _a.events;
38269
- return events;
38270
- })
38271
- .flat();
38272
- var _d = (tournamentRecords &&
38273
- (excludeScheduleDateProfileRounds ||
38274
- excludeCompletedRounds ||
38275
- schedulingProfile ||
38276
- withSplitRounds) &&
38277
- getProfileRounds({ tournamentRecords: tournamentRecords, schedulingProfile: schedulingProfile })) ||
38278
- {}, segmentedRounds = _d.segmentedRounds, profileRounds = _d.profileRounds;
38279
- var profileRoundsMap = excludeScheduleDateProfileRounds && Object.assign.apply(Object, __spreadArray([{}], __read(profileRounds.map(function (profile) {
38280
- var _a;
38281
- return (_a = {}, _a[profile.id] = profile, _a);
38282
- })), false));
38283
- var consideredMatchUps = inContextMatchUps ||
38284
- (tournamentRecords &&
38285
- ((_c = allCompetitionMatchUps({ tournamentRecords: tournamentRecords, matchUpFilters: matchUpFilters })) === null || _c === void 0 ? void 0 : _c.matchUps)) ||
38286
- [];
38287
- var excludedRounds = [];
38288
- var rounds = (consideredMatchUps &&
38289
- Object.values(consideredMatchUps.reduce(function (rounds, matchUp) {
38290
- var _a;
38291
- var _b, _c;
38292
- var id = getRoundId(matchUp).id;
38293
- var segmentsCount = segmentedRounds === null || segmentedRounds === void 0 ? void 0 : segmentedRounds[id];
38294
- var matchUps = __spreadArray(__spreadArray([], __read(((_c = (_b = rounds[id]) === null || _b === void 0 ? void 0 : _b.matchUps) !== null && _c !== void 0 ? _c : [])), false), [matchUp], false);
38295
- var containerStructureId = matchUp.containerStructureId, stageSequence = matchUp.stageSequence, structureName = matchUp.structureName, tournamentId = matchUp.tournamentId, isRoundRobin = matchUp.isRoundRobin, matchUpType = matchUp.matchUpType, roundNumber = matchUp.roundNumber, roundOffset = matchUp.roundOffset, structureId = matchUp.structureId, eventName = matchUp.eventName, roundName = matchUp.roundName, drawName = matchUp.drawName, eventId = matchUp.eventId, drawId = matchUp.drawId;
38296
- var relevantStructureId = isRoundRobin
38297
- ? containerStructureId
38298
- : structureId;
38299
- return __assign(__assign({}, rounds), (_a = {}, _a[id] = {
38300
- id: withRoundId ? id : undefined,
38301
- structureId: relevantStructureId,
38302
- stageSequence: stageSequence,
38303
- segmentsCount: segmentsCount,
38304
- structureName: structureName,
38305
- tournamentId: tournamentId,
38306
- matchUpType: matchUpType,
38307
- roundNumber: roundNumber,
38308
- roundOffset: roundOffset,
38309
- eventName: eventName,
38310
- roundName: roundName,
38311
- drawName: drawName,
38312
- matchUps: matchUps,
38313
- eventId: eventId,
38314
- drawId: drawId,
38315
- }, _a));
38316
- }, {}))
38317
- .map(function (round) {
38318
- var _a = getFinishingPositionDetails(round.matchUps), minFinishingSum = _a.minFinishingSum, winnerFinishingPositionRange = _a.winnerFinishingPositionRange;
38319
- var segmentsCount = round.segmentsCount;
38320
- if (segmentsCount) {
38321
- var chunkSize = round.matchUps.length / segmentsCount;
38322
- var sortedMatchUps = chunkArray(round.matchUps.sort(function (a, b) { return a.roundPosition - b.roundPosition; }), chunkSize);
38323
- return sortedMatchUps.map(function (matchUps, i) {
38324
- var _a = getRoundProfile(matchUps), unscheduledCount = _a.unscheduledCount, incompleteCount = _a.incompleteCount, matchUpsCount = _a.matchUpsCount, isScheduled = _a.isScheduled, isComplete = _a.isComplete, byeCount = _a.byeCount;
38325
- var roundTiming = getRoundTiming({
38326
- matchUps: round.matchUps,
38327
- tournamentRecords: tournamentRecords,
38328
- events: events,
38329
- round: round,
38330
- });
38331
- return definedAttributes(__assign(__assign(__assign({}, round), context), { roundSegment: { segmentsCount: segmentsCount, segmentNumber: i + 1 }, winnerFinishingPositionRange: winnerFinishingPositionRange, unscheduledCount: unscheduledCount, incompleteCount: incompleteCount, minFinishingSum: minFinishingSum, matchUpsCount: matchUpsCount, isScheduled: isScheduled, roundTiming: roundTiming, isComplete: isComplete, byeCount: byeCount, matchUps: matchUps }));
38332
- });
38333
- }
38334
- var _b = getRoundProfile(round.matchUps), unscheduledCount = _b.unscheduledCount, incompleteCount = _b.incompleteCount, matchUpsCount = _b.matchUpsCount, isScheduled = _b.isScheduled, isComplete = _b.isComplete, byeCount = _b.byeCount;
38335
- var roundTiming = getRoundTiming({
38336
- matchUps: round.matchUps,
38337
- tournamentRecords: tournamentRecords,
38338
- events: events,
38339
- round: round,
38340
- });
38341
- return definedAttributes(__assign(__assign(__assign({}, round), context), { winnerFinishingPositionRange: winnerFinishingPositionRange, unscheduledCount: unscheduledCount, incompleteCount: incompleteCount, minFinishingSum: minFinishingSum, matchUpsCount: matchUpsCount, isScheduled: isScheduled, roundTiming: roundTiming, isComplete: isComplete, byeCount: byeCount }));
38342
- })
38343
- .flat()
38344
- .filter(function (round) {
38345
- if (excludeScheduleDateProfileRounds) {
38346
- var scheduleDate = extractDate(excludeScheduleDateProfileRounds);
38347
- var roundId = withRoundId ? round.id : getRoundId(round).id;
38348
- if (scheduleDate &&
38349
- profileRoundsMap[roundId] &&
38350
- extractDate(profileRoundsMap[roundId].scheduleDate) ===
38351
- scheduleDate) {
38352
- return false;
38353
- }
38354
- }
38355
- var isComplete = round.isComplete, isScheduled = round.isScheduled;
38356
- var keepComplete = !excludeCompletedRounds || !isComplete;
38357
- var keepScheduled = !excludeScheduledRounds || !isScheduled;
38358
- var keepRound = keepComplete && keepScheduled;
38359
- if (!keepRound)
38360
- excludedRounds.push(round);
38361
- return keepRound;
38362
- })
38363
- .sort(roundSort)) ||
38364
- [];
38365
- return __assign(__assign({}, SUCCESS), { rounds: rounds, excludedRounds: excludedRounds });
38366
- }
38367
- function getRoundTiming(_a) {
38368
- var round = _a.round, matchUps = _a.matchUps, events = _a.events, tournamentRecords = _a.tournamentRecords;
38369
- var event = events.find(function (event) { return event.eventId === round.eventId; });
38370
- var _b = event || {}, eventType = _b.eventType, category = _b.category, categoryType = _b.categoryType;
38371
- var _c = category || {}, categoryName = _c.categoryName, ageCategoryCode = _c.ageCategoryCode;
38372
- var formatCounts = instanceCount(matchUps.map(function (_a) {
38373
- var matchUpFormat = _a.matchUpFormat;
38374
- return matchUpFormat;
38375
- }));
38376
- var roundMinutes = 0;
38377
- Object.keys(formatCounts).forEach(function (matchUpFormat) {
38378
- var formatCount = formatCounts[matchUpFormat];
38379
- var result = findMatchUpFormatTiming({
38380
- categoryName: categoryName || ageCategoryCode,
38381
- tournamentId: round.tournamentId,
38382
- eventId: round.eventId,
38383
- tournamentRecords: tournamentRecords,
38384
- matchUpFormat: matchUpFormat,
38385
- categoryType: categoryType,
38386
- eventType: eventType,
38387
- });
38388
- if (result.error)
38389
- return result;
38390
- var formatMinutes = result.averageMinutes * formatCount;
38391
- if (!isNaN(roundMinutes))
38392
- roundMinutes += formatMinutes;
38393
- return undefined;
38394
- });
38395
- return { roundMinutes: roundMinutes };
38396
- }
38397
- // Sort rounds by order in which they will be played
38398
- function roundSort(a, b) {
38399
- return (a.eventName.localeCompare(b.eventName) ||
38400
- a.eventId.localeCompare(b.eventId) ||
38401
- (stageOrder[a === null || a === void 0 ? void 0 : a.stage] || 0) - (stageOrder[b === null || b === void 0 ? void 0 : b.stage] || 0) ||
38402
- b.matchUpsCount - a.matchUpsCount ||
38403
- "".concat(a.stageSequence, "-").concat(a.roundNumber, "-").concat(a.minFinishingSum).localeCompare("".concat(b.stageSequence, "-").concat(b.roundNumber, "-").concat(b.minFinishingSum)));
38404
- }
38405
- function getFinishingPositionDetails(matchUps) {
38406
- return (matchUps || []).reduce(function (foo, matchUp) {
38407
- var _a, _b;
38408
- var sum = (((_a = matchUp.finishingPositionRange) === null || _a === void 0 ? void 0 : _a.winner) || []).reduce(function (a, b) { return a + b; }, 0);
38409
- var winnerFinishingPositionRange = (((_b = matchUp.finishingPositionRange) === null || _b === void 0 ? void 0 : _b.winner) || []).join('-') || '';
38410
- return !foo.minFinishingSum || sum < foo.minFinishingSum
38411
- ? { minFinishingSum: sum, winnerFinishingPositionRange: winnerFinishingPositionRange }
38412
- : foo;
38413
- }, { minFinishingSum: 0, winnerFinishingPositionRange: '' });
38414
- }
38415
-
38416
38136
  function bulkUpdateCourtAssignments(_a) {
38417
38137
  var tournamentRecords = _a.tournamentRecords, courtAssignments = _a.courtAssignments, courtDayDate = _a.courtDayDate;
38418
38138
  if (!tournamentRecords)
@@ -38858,6 +38578,148 @@ function reorderUpcomingMatchUps(params) {
38858
38578
  }
38859
38579
  }
38860
38580
 
38581
+ function getRoundId(obj) {
38582
+ var containerStructureId = obj.containerStructureId, roundSegment = obj.roundSegment, isRoundRobin = obj.isRoundRobin, tournamentId = obj.tournamentId, roundNumber = obj.roundNumber, structureId = obj.structureId, eventId = obj.eventId, drawId = obj.drawId;
38583
+ var relevantStructureId = isRoundRobin ? containerStructureId : structureId;
38584
+ // retain order
38585
+ var id = [
38586
+ tournamentId,
38587
+ eventId,
38588
+ drawId,
38589
+ relevantStructureId,
38590
+ roundNumber, // 5
38591
+ ].join('|');
38592
+ return definedAttributes({
38593
+ structureId: relevantStructureId,
38594
+ roundSegment: roundSegment,
38595
+ tournamentId: tournamentId,
38596
+ roundNumber: roundNumber,
38597
+ eventId: eventId,
38598
+ drawId: drawId,
38599
+ id: id,
38600
+ });
38601
+ }
38602
+ function getRoundTiming(_a) {
38603
+ var round = _a.round, matchUps = _a.matchUps, events = _a.events, tournamentRecords = _a.tournamentRecords;
38604
+ var event = events.find(function (event) { return event.eventId === round.eventId; });
38605
+ var _b = event || {}, eventType = _b.eventType, category = _b.category, categoryType = _b.categoryType;
38606
+ var _c = category || {}, categoryName = _c.categoryName, ageCategoryCode = _c.ageCategoryCode;
38607
+ var formatCounts = instanceCount(matchUps.map(function (_a) {
38608
+ var matchUpFormat = _a.matchUpFormat;
38609
+ return matchUpFormat;
38610
+ }));
38611
+ var roundMinutes = 0;
38612
+ Object.keys(formatCounts).forEach(function (matchUpFormat) {
38613
+ var formatCount = formatCounts[matchUpFormat];
38614
+ var result = findMatchUpFormatTiming({
38615
+ categoryName: categoryName || ageCategoryCode,
38616
+ tournamentId: round.tournamentId,
38617
+ eventId: round.eventId,
38618
+ tournamentRecords: tournamentRecords,
38619
+ matchUpFormat: matchUpFormat,
38620
+ categoryType: categoryType,
38621
+ eventType: eventType,
38622
+ });
38623
+ if (result.error)
38624
+ return result;
38625
+ var formatMinutes = result.averageMinutes * formatCount;
38626
+ if (!isNaN(roundMinutes))
38627
+ roundMinutes += formatMinutes;
38628
+ return undefined;
38629
+ });
38630
+ return { roundMinutes: roundMinutes };
38631
+ }
38632
+ function getFinishingPositionDetails(matchUps) {
38633
+ return (matchUps || []).reduce(function (foo, matchUp) {
38634
+ var _a, _b;
38635
+ var sum = (((_a = matchUp.finishingPositionRange) === null || _a === void 0 ? void 0 : _a.winner) || []).reduce(function (a, b) { return a + b; }, 0);
38636
+ var winnerFinishingPositionRange = (((_b = matchUp.finishingPositionRange) === null || _b === void 0 ? void 0 : _b.winner) || []).join('-') || '';
38637
+ return !foo.minFinishingSum || sum < foo.minFinishingSum
38638
+ ? { minFinishingSum: sum, winnerFinishingPositionRange: winnerFinishingPositionRange }
38639
+ : foo;
38640
+ }, { minFinishingSum: 0, winnerFinishingPositionRange: '' });
38641
+ }
38642
+ function getRoundProfile(matchUps) {
38643
+ var matchUpsCount = matchUps.length;
38644
+ var byeCount = matchUps.filter(function (_a) {
38645
+ var sides = _a.sides;
38646
+ return sides === null || sides === void 0 ? void 0 : sides.some(function (_a) {
38647
+ var bye = _a.bye;
38648
+ return bye;
38649
+ });
38650
+ }).length || 0;
38651
+ var completedCount = matchUps.filter(function (_a) {
38652
+ var winningSide = _a.winningSide, matchUpStatus = _a.matchUpStatus;
38653
+ return winningSide || completedMatchUpStatuses.includes(matchUpStatus);
38654
+ }).length || 0;
38655
+ var scheduledCount = matchUps.filter(function (_a) {
38656
+ var schedule = _a.schedule;
38657
+ return (schedule === null || schedule === void 0 ? void 0 : schedule.scheduledDate) && (schedule === null || schedule === void 0 ? void 0 : schedule.scheduledTime);
38658
+ }).length || 0;
38659
+ var consideredCount = matchUpsCount - byeCount;
38660
+ var isComplete = consideredCount === completedCount;
38661
+ var unscheduledCount = consideredCount - scheduledCount;
38662
+ var incompleteCount = consideredCount - scheduledCount;
38663
+ var isScheduled = consideredCount === scheduledCount;
38664
+ return {
38665
+ unscheduledCount: unscheduledCount,
38666
+ incompleteCount: incompleteCount,
38667
+ scheduledCount: scheduledCount,
38668
+ completedCount: completedCount,
38669
+ matchUpsCount: matchUpsCount,
38670
+ isScheduled: isScheduled,
38671
+ isComplete: isComplete,
38672
+ byeCount: byeCount,
38673
+ };
38674
+ }
38675
+
38676
+ function getProfileRounds(_a) {
38677
+ var _b;
38678
+ var tournamentRecords = _a.tournamentRecords, schedulingProfile = _a.schedulingProfile, tournamentRecord = _a.tournamentRecord, withRoundId = _a.withRoundId;
38679
+ if (tournamentRecord && !tournamentRecords) {
38680
+ if (typeof tournamentRecord !== 'object') {
38681
+ return { error: INVALID_TOURNAMENT_RECORD };
38682
+ }
38683
+ else {
38684
+ tournamentRecords = (_b = {}, _b[tournamentRecord.tournamentId] = tournamentRecord, _b);
38685
+ }
38686
+ }
38687
+ if (schedulingProfile) {
38688
+ var profileValidity = validateSchedulingProfile({
38689
+ tournamentRecords: tournamentRecords,
38690
+ schedulingProfile: schedulingProfile,
38691
+ });
38692
+ if (profileValidity.error)
38693
+ return profileValidity;
38694
+ }
38695
+ if (!schedulingProfile && tournamentRecords) {
38696
+ var result = getSchedulingProfile$1({ tournamentRecords: tournamentRecords });
38697
+ if (result.error)
38698
+ return result;
38699
+ schedulingProfile = result.schedulingProfile;
38700
+ }
38701
+ if (!schedulingProfile)
38702
+ return { error: NOT_FOUND };
38703
+ var segmentedRounds = {};
38704
+ var profileRounds = schedulingProfile
38705
+ .map(function (_a) {
38706
+ var venues = _a.venues, scheduleDate = _a.scheduleDate;
38707
+ return venues.map(function (_a) {
38708
+ var rounds = _a.rounds;
38709
+ return rounds.map(function (round) {
38710
+ var _a;
38711
+ var roundRef = getRoundId(round);
38712
+ if ((_a = roundRef.roundSegment) === null || _a === void 0 ? void 0 : _a.segmentsCount) {
38713
+ segmentedRounds[roundRef.id] = roundRef.roundSegment.segmentsCount;
38714
+ }
38715
+ return definedAttributes(__assign({ id: withRoundId ? roundRef.id : undefined, scheduleDate: scheduleDate }, roundRef));
38716
+ });
38717
+ });
38718
+ })
38719
+ .flat(Infinity);
38720
+ return { profileRounds: profileRounds, segmentedRounds: segmentedRounds };
38721
+ }
38722
+
38861
38723
  function addMatchUpScheduleItems$1(params) {
38862
38724
  return addMatchUpScheduleItems$2(params);
38863
38725
  }
@@ -39498,6 +39360,171 @@ function matchUpScheduleChange(params) {
39498
39360
  }
39499
39361
  }
39500
39362
 
39363
+ var stageOrder = drawDefinitionConstants.stageOrder;
39364
+ // Sort rounds by order in which they will be played
39365
+ function roundSort(a, b) {
39366
+ return (a.eventName.localeCompare(b.eventName) ||
39367
+ a.eventId.localeCompare(b.eventId) ||
39368
+ (stageOrder[a === null || a === void 0 ? void 0 : a.stage] || 0) - (stageOrder[b === null || b === void 0 ? void 0 : b.stage] || 0) ||
39369
+ b.matchUpsCount - a.matchUpsCount ||
39370
+ "".concat(a.stageSequence, "-").concat(a.roundNumber, "-").concat(a.minFinishingSum).localeCompare("".concat(b.stageSequence, "-").concat(b.roundNumber, "-").concat(b.minFinishingSum)));
39371
+ }
39372
+
39373
+ function getRounds(_a) {
39374
+ var _b;
39375
+ var _c;
39376
+ var excludeScheduleDateProfileRounds = _a.excludeScheduleDateProfileRounds, excludeScheduledRounds = _a.excludeScheduledRounds, excludeCompletedRounds = _a.excludeCompletedRounds, inContextMatchUps = _a.inContextMatchUps, tournamentRecords = _a.tournamentRecords, schedulingProfile = _a.schedulingProfile, tournamentRecord = _a.tournamentRecord, withSplitRounds = _a.withSplitRounds, matchUpFilters = _a.matchUpFilters, scheduleDate = _a.scheduleDate, withRoundId = _a.withRoundId, venueId = _a.venueId, context = _a.context;
39377
+ if (inContextMatchUps &&
39378
+ !Array.isArray(inContextMatchUps || typeof inContextMatchUps[0] !== 'object')) {
39379
+ return { error: INVALID_VALUES, inContextMatchUps: inContextMatchUps };
39380
+ }
39381
+ if (tournamentRecord && !tournamentRecords) {
39382
+ if (typeof tournamentRecord !== 'object') {
39383
+ return { error: INVALID_TOURNAMENT_RECORD };
39384
+ }
39385
+ else {
39386
+ tournamentRecords = (_b = {}, _b[tournamentRecord.tournamentId] = tournamentRecord, _b);
39387
+ }
39388
+ }
39389
+ var noTournamentRecords = typeof tournamentRecords !== 'object' ||
39390
+ !Object.keys(tournamentRecords).length;
39391
+ var needsTournamentRecords = venueId ||
39392
+ scheduleDate ||
39393
+ !inContextMatchUps ||
39394
+ (!schedulingProfile &&
39395
+ (excludeScheduleDateProfileRounds ||
39396
+ excludeCompletedRounds ||
39397
+ schedulingProfile ||
39398
+ withSplitRounds));
39399
+ if (needsTournamentRecords && noTournamentRecords)
39400
+ return { error: MISSING_TOURNAMENT_RECORDS };
39401
+ var tournamentVenueIds = Object.assign.apply(Object, __spreadArray([{}], __read(Object.values(tournamentRecords !== null && tournamentRecords !== void 0 ? tournamentRecords : {}).map(function (_a) {
39402
+ var _b;
39403
+ var _c = _a.venues, venues = _c === void 0 ? [] : _c, tournamentId = _a.tournamentId;
39404
+ return (_b = {},
39405
+ _b[tournamentId] = venues === null || venues === void 0 ? void 0 : venues.map(function (_a) {
39406
+ var venueId = _a.venueId;
39407
+ return venueId;
39408
+ }),
39409
+ _b);
39410
+ })), false));
39411
+ var events = Object.values(tournamentRecords !== null && tournamentRecords !== void 0 ? tournamentRecords : {})
39412
+ .map(function (_a) {
39413
+ var _b = _a.events, events = _b === void 0 ? [] : _b, tournamentId = _a.tournamentId, startDate = _a.startDate, endDate = _a.endDate;
39414
+ return events.map(function (event) {
39415
+ var _a, _b;
39416
+ return (__assign(__assign({}, event), { validVenueIds: tournamentVenueIds[tournamentId], startDate: (_a = event.startDate) !== null && _a !== void 0 ? _a : startDate, endDate: (_b = event.endDate) !== null && _b !== void 0 ? _b : endDate }));
39417
+ });
39418
+ })
39419
+ .flat();
39420
+ var _d = (tournamentRecords &&
39421
+ (excludeScheduleDateProfileRounds ||
39422
+ excludeCompletedRounds ||
39423
+ schedulingProfile ||
39424
+ withSplitRounds) &&
39425
+ getProfileRounds({ tournamentRecords: tournamentRecords, schedulingProfile: schedulingProfile })) ||
39426
+ {}, segmentedRounds = _d.segmentedRounds, profileRounds = _d.profileRounds;
39427
+ var profileRoundsMap = excludeScheduleDateProfileRounds && Object.assign.apply(Object, __spreadArray([{}], __read(profileRounds.map(function (profile) {
39428
+ var _a;
39429
+ return (_a = {}, _a[profile.id] = profile, _a);
39430
+ })), false));
39431
+ var consideredMatchUps = inContextMatchUps ||
39432
+ (tournamentRecords &&
39433
+ ((_c = allCompetitionMatchUps({ tournamentRecords: tournamentRecords, matchUpFilters: matchUpFilters })) === null || _c === void 0 ? void 0 : _c.matchUps)) ||
39434
+ [];
39435
+ var excludedRounds = [];
39436
+ var rounds = (consideredMatchUps &&
39437
+ Object.values(consideredMatchUps.reduce(function (rounds, matchUp) {
39438
+ var _a;
39439
+ var _b, _c;
39440
+ var id = getRoundId(matchUp).id;
39441
+ var segmentsCount = segmentedRounds === null || segmentedRounds === void 0 ? void 0 : segmentedRounds[id];
39442
+ var matchUps = __spreadArray(__spreadArray([], __read(((_c = (_b = rounds[id]) === null || _b === void 0 ? void 0 : _b.matchUps) !== null && _c !== void 0 ? _c : [])), false), [matchUp], false);
39443
+ var containerStructureId = matchUp.containerStructureId, stageSequence = matchUp.stageSequence, structureName = matchUp.structureName, tournamentId = matchUp.tournamentId, isRoundRobin = matchUp.isRoundRobin, matchUpType = matchUp.matchUpType, roundNumber = matchUp.roundNumber, roundOffset = matchUp.roundOffset, structureId = matchUp.structureId, eventName = matchUp.eventName, roundName = matchUp.roundName, drawName = matchUp.drawName, eventId = matchUp.eventId, drawId = matchUp.drawId;
39444
+ var relevantStructureId = isRoundRobin
39445
+ ? containerStructureId
39446
+ : structureId;
39447
+ return __assign(__assign({}, rounds), (_a = {}, _a[id] = {
39448
+ id: withRoundId ? id : undefined,
39449
+ structureId: relevantStructureId,
39450
+ stageSequence: stageSequence,
39451
+ segmentsCount: segmentsCount,
39452
+ structureName: structureName,
39453
+ tournamentId: tournamentId,
39454
+ matchUpType: matchUpType,
39455
+ roundNumber: roundNumber,
39456
+ roundOffset: roundOffset,
39457
+ eventName: eventName,
39458
+ roundName: roundName,
39459
+ drawName: drawName,
39460
+ matchUps: matchUps,
39461
+ eventId: eventId,
39462
+ drawId: drawId,
39463
+ }, _a));
39464
+ }, {}))
39465
+ .map(function (round) {
39466
+ var _a = getFinishingPositionDetails(round.matchUps), minFinishingSum = _a.minFinishingSum, winnerFinishingPositionRange = _a.winnerFinishingPositionRange;
39467
+ var segmentsCount = round.segmentsCount;
39468
+ if (segmentsCount) {
39469
+ var chunkSize = round.matchUps.length / segmentsCount;
39470
+ var sortedMatchUps = chunkArray(round.matchUps.sort(function (a, b) { return a.roundPosition - b.roundPosition; }), chunkSize);
39471
+ return sortedMatchUps.map(function (matchUps, i) {
39472
+ var _a = getRoundProfile(matchUps), unscheduledCount = _a.unscheduledCount, incompleteCount = _a.incompleteCount, matchUpsCount = _a.matchUpsCount, isScheduled = _a.isScheduled, isComplete = _a.isComplete, byeCount = _a.byeCount;
39473
+ var roundTiming = getRoundTiming({
39474
+ matchUps: round.matchUps,
39475
+ tournamentRecords: tournamentRecords,
39476
+ events: events,
39477
+ round: round,
39478
+ });
39479
+ return definedAttributes(__assign(__assign(__assign({}, round), context), { roundSegment: { segmentsCount: segmentsCount, segmentNumber: i + 1 }, winnerFinishingPositionRange: winnerFinishingPositionRange, unscheduledCount: unscheduledCount, incompleteCount: incompleteCount, minFinishingSum: minFinishingSum, matchUpsCount: matchUpsCount, isScheduled: isScheduled, roundTiming: roundTiming, isComplete: isComplete, byeCount: byeCount, matchUps: matchUps }));
39480
+ });
39481
+ }
39482
+ var _b = getRoundProfile(round.matchUps), unscheduledCount = _b.unscheduledCount, incompleteCount = _b.incompleteCount, matchUpsCount = _b.matchUpsCount, isScheduled = _b.isScheduled, isComplete = _b.isComplete, byeCount = _b.byeCount;
39483
+ var roundTiming = getRoundTiming({
39484
+ matchUps: round.matchUps,
39485
+ tournamentRecords: tournamentRecords,
39486
+ events: events,
39487
+ round: round,
39488
+ });
39489
+ return definedAttributes(__assign(__assign(__assign({}, round), context), { winnerFinishingPositionRange: winnerFinishingPositionRange, unscheduledCount: unscheduledCount, incompleteCount: incompleteCount, minFinishingSum: minFinishingSum, matchUpsCount: matchUpsCount, isScheduled: isScheduled, roundTiming: roundTiming, isComplete: isComplete, byeCount: byeCount }));
39490
+ })
39491
+ .flat()
39492
+ .filter(function (round) {
39493
+ if (excludeScheduleDateProfileRounds) {
39494
+ var scheduleDate_1 = extractDate(excludeScheduleDateProfileRounds);
39495
+ var roundId = withRoundId ? round.id : getRoundId(round).id;
39496
+ if (scheduleDate_1 &&
39497
+ profileRoundsMap[roundId] &&
39498
+ extractDate(profileRoundsMap[roundId].scheduleDate) ===
39499
+ scheduleDate_1) {
39500
+ return false;
39501
+ }
39502
+ }
39503
+ var isComplete = round.isComplete, isScheduled = round.isScheduled;
39504
+ var keepComplete = !excludeCompletedRounds || !isComplete;
39505
+ var keepScheduled = !excludeScheduledRounds || !isScheduled;
39506
+ var event = venueId || scheduleDate
39507
+ ? events === null || events === void 0 ? void 0 : events.find(function (_a) {
39508
+ var eventId = _a.eventId;
39509
+ return eventId === round.eventId;
39510
+ })
39511
+ : undefined;
39512
+ var validDate = !scheduleDate ||
39513
+ ((event === null || event === void 0 ? void 0 : event.startDate) &&
39514
+ (event === null || event === void 0 ? void 0 : event.endDate) &&
39515
+ new Date(scheduleDate) >= new Date(event === null || event === void 0 ? void 0 : event.startDate) &&
39516
+ new Date(scheduleDate) <= new Date(event === null || event === void 0 ? void 0 : event.endDate));
39517
+ var validVenue = !venueId || (event === null || event === void 0 ? void 0 : event.validVenueIds.includes(venueId));
39518
+ var keepRound = keepComplete && keepScheduled && validVenue && validDate;
39519
+ if (!keepRound)
39520
+ excludedRounds.push(round);
39521
+ return keepRound;
39522
+ })
39523
+ .sort(roundSort)) ||
39524
+ [];
39525
+ return __assign(__assign({}, SUCCESS), { rounds: rounds, excludedRounds: excludedRounds });
39526
+ }
39527
+
39501
39528
  function addMatchUpScheduleItems(params) {
39502
39529
  var result = getDrawDefinition$1(params);
39503
39530
  if (result.error)
@@ -42378,20 +42405,28 @@ var competitionEngine = (function () {
42378
42405
  var elapsed = Date.now() - start;
42379
42406
  var devContext = getDevContext();
42380
42407
  var log = { method: methodName };
42381
- var logErrors = typeof devContext.result === 'object' && devContext.result.error;
42382
- if (![undefined, false].includes(devContext.perf) &&
42408
+ var logError = result.error &&
42409
+ (devContext.errors === true ||
42410
+ (Array.isArray(devContext.errors) &&
42411
+ devContext.errors.includes(methodName)));
42412
+ var exclude = Array.isArray(devContext.exclude) &&
42413
+ devContext.exclude.includes(methodName);
42414
+ if (!exclude &&
42415
+ ![undefined, false].includes(devContext.perf) &&
42383
42416
  (isNaN(devContext.perf) || elapsed > devContext.perf))
42384
42417
  log.elapsed = elapsed;
42385
- if (logErrors ||
42386
- (devContext.params && !Array.isArray(devContext.params)) ||
42387
- (Array.isArray(devContext.params) &&
42388
- ((_a = devContext.params) === null || _a === void 0 ? void 0 : _a.includes(methodName)))) {
42418
+ if (!exclude &&
42419
+ (logError ||
42420
+ (devContext.params && !Array.isArray(devContext.params)) ||
42421
+ (Array.isArray(devContext.params) &&
42422
+ ((_a = devContext.params) === null || _a === void 0 ? void 0 : _a.includes(methodName))))) {
42389
42423
  log.params = params;
42390
42424
  }
42391
- if (logErrors ||
42392
- (!logErrors && devContext.result && !Array.isArray(devContext.result)) ||
42393
- (Array.isArray(devContext.result) &&
42394
- ((_b = devContext.result) === null || _b === void 0 ? void 0 : _b.includes(methodName)))) {
42425
+ if (!exclude &&
42426
+ (logError ||
42427
+ (devContext.result && !Array.isArray(devContext.result)) ||
42428
+ (Array.isArray(devContext.result) &&
42429
+ ((_b = devContext.result) === null || _b === void 0 ? void 0 : _b.includes(methodName))))) {
42395
42430
  log.result = result;
42396
42431
  }
42397
42432
  if (Object.keys(log).length > 1)
@@ -65000,20 +65035,28 @@ var tournamentEngine = (function () {
65000
65035
  var elapsed = Date.now() - start;
65001
65036
  var devContext = getDevContext();
65002
65037
  var log = { method: methodName };
65003
- var logErrors = typeof devContext.result === 'object' && devContext.result.error;
65004
- if (![undefined, false].includes(devContext.perf) &&
65038
+ var logError = result.error &&
65039
+ (devContext.errors === true ||
65040
+ (Array.isArray(devContext.errors) &&
65041
+ devContext.errors.includes(methodName)));
65042
+ var exclude = Array.isArray(devContext.exclude) &&
65043
+ devContext.exclude.includes(methodName);
65044
+ if (!exclude &&
65045
+ ![undefined, false].includes(devContext.perf) &&
65005
65046
  (isNaN(devContext.perf) || elapsed > devContext.perf))
65006
65047
  log.elapsed = elapsed;
65007
- if (logErrors ||
65008
- (devContext.params && !Array.isArray(devContext.params)) ||
65009
- (Array.isArray(devContext.params) &&
65010
- ((_a = devContext.params) === null || _a === void 0 ? void 0 : _a.includes(methodName)))) {
65048
+ if (!exclude &&
65049
+ (logError ||
65050
+ (devContext.params && !Array.isArray(devContext.params)) ||
65051
+ (Array.isArray(devContext.params) &&
65052
+ ((_a = devContext.params) === null || _a === void 0 ? void 0 : _a.includes(methodName))))) {
65011
65053
  log.params = params;
65012
65054
  }
65013
- if (logErrors ||
65014
- (!logErrors && devContext.result && !Array.isArray(devContext.result)) ||
65015
- (Array.isArray(devContext.result) &&
65016
- ((_b = devContext.result) === null || _b === void 0 ? void 0 : _b.includes(methodName)))) {
65055
+ if (!exclude &&
65056
+ (logError ||
65057
+ (devContext.result && !Array.isArray(devContext.result)) ||
65058
+ (Array.isArray(devContext.result) &&
65059
+ ((_b = devContext.result) === null || _b === void 0 ? void 0 : _b.includes(methodName))))) {
65017
65060
  log.result = result;
65018
65061
  }
65019
65062
  if (Object.keys(log).length > 1)