tods-competition-factory 1.8.6 → 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.6';
2901
+ return '1.8.7';
2902
2902
  }
2903
2903
 
2904
2904
  function getObjectTieFormat(obj) {
@@ -38133,283 +38133,6 @@ function getMatchUpDailyLimitsUpdate$1(_a) {
38133
38133
  });
38134
38134
  }
38135
38135
 
38136
- var stageOrder = drawDefinitionConstants.stageOrder;
38137
- function getProfileRounds(_a) {
38138
- var _b;
38139
- var tournamentRecords = _a.tournamentRecords, schedulingProfile = _a.schedulingProfile, tournamentRecord = _a.tournamentRecord, withRoundId = _a.withRoundId;
38140
- if (tournamentRecord && !tournamentRecords) {
38141
- if (typeof tournamentRecord !== 'object') {
38142
- return { error: INVALID_TOURNAMENT_RECORD };
38143
- }
38144
- else {
38145
- tournamentRecords = (_b = {}, _b[tournamentRecord.tournamentId] = tournamentRecord, _b);
38146
- }
38147
- }
38148
- if (schedulingProfile) {
38149
- var profileValidity = validateSchedulingProfile({
38150
- tournamentRecords: tournamentRecords,
38151
- schedulingProfile: schedulingProfile,
38152
- });
38153
- if (profileValidity.error)
38154
- return profileValidity;
38155
- }
38156
- if (!schedulingProfile && tournamentRecords) {
38157
- var result = getSchedulingProfile$1({ tournamentRecords: tournamentRecords });
38158
- if (result.error)
38159
- return result;
38160
- schedulingProfile = result.schedulingProfile;
38161
- }
38162
- if (!schedulingProfile)
38163
- return { error: NOT_FOUND };
38164
- var segmentedRounds = {};
38165
- var profileRounds = schedulingProfile
38166
- .map(function (_a) {
38167
- var venues = _a.venues, scheduleDate = _a.scheduleDate;
38168
- return venues.map(function (_a) {
38169
- var rounds = _a.rounds;
38170
- return rounds.map(function (round) {
38171
- var _a;
38172
- var roundRef = getRoundId(round);
38173
- if ((_a = roundRef.roundSegment) === null || _a === void 0 ? void 0 : _a.segmentsCount) {
38174
- segmentedRounds[roundRef.id] = roundRef.roundSegment.segmentsCount;
38175
- }
38176
- return definedAttributes(__assign({ id: withRoundId ? roundRef.id : undefined, scheduleDate: scheduleDate }, roundRef));
38177
- });
38178
- });
38179
- })
38180
- .flat(Infinity);
38181
- return { profileRounds: profileRounds, segmentedRounds: segmentedRounds };
38182
- }
38183
- function getRoundId(obj) {
38184
- 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;
38185
- var relevantStructureId = isRoundRobin ? containerStructureId : structureId;
38186
- // retain order
38187
- var id = [
38188
- tournamentId,
38189
- eventId,
38190
- drawId,
38191
- relevantStructureId,
38192
- roundNumber, // 5
38193
- ].join('|');
38194
- return definedAttributes({
38195
- id: id,
38196
- roundSegment: roundSegment,
38197
- tournamentId: tournamentId,
38198
- eventId: eventId,
38199
- drawId: drawId,
38200
- structureId: relevantStructureId,
38201
- roundNumber: roundNumber,
38202
- });
38203
- }
38204
- function getRoundProfile(matchUps) {
38205
- var matchUpsCount = matchUps.length;
38206
- var byeCount = matchUps.filter(function (_a) {
38207
- var sides = _a.sides;
38208
- return sides === null || sides === void 0 ? void 0 : sides.some(function (_a) {
38209
- var bye = _a.bye;
38210
- return bye;
38211
- });
38212
- }).length || 0;
38213
- var completedCount = matchUps.filter(function (_a) {
38214
- var winningSide = _a.winningSide, matchUpStatus = _a.matchUpStatus;
38215
- return winningSide || completedMatchUpStatuses.includes(matchUpStatus);
38216
- }).length || 0;
38217
- var scheduledCount = matchUps.filter(function (_a) {
38218
- var schedule = _a.schedule;
38219
- return (schedule === null || schedule === void 0 ? void 0 : schedule.scheduledDate) && (schedule === null || schedule === void 0 ? void 0 : schedule.scheduledTime);
38220
- }).length || 0;
38221
- var consideredCount = matchUpsCount - byeCount;
38222
- var isComplete = consideredCount === completedCount;
38223
- var unscheduledCount = consideredCount - scheduledCount;
38224
- var incompleteCount = consideredCount - scheduledCount;
38225
- var isScheduled = consideredCount === scheduledCount;
38226
- return {
38227
- unscheduledCount: unscheduledCount,
38228
- incompleteCount: incompleteCount,
38229
- scheduledCount: scheduledCount,
38230
- completedCount: completedCount,
38231
- matchUpsCount: matchUpsCount,
38232
- isScheduled: isScheduled,
38233
- isComplete: isComplete,
38234
- byeCount: byeCount,
38235
- };
38236
- }
38237
- function getRounds(_a) {
38238
- var _b;
38239
- var _c;
38240
- 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;
38241
- if (inContextMatchUps &&
38242
- !Array.isArray(inContextMatchUps || typeof inContextMatchUps[0] !== 'object')) {
38243
- return { error: INVALID_VALUES, inContextMatchUps: inContextMatchUps };
38244
- }
38245
- if (tournamentRecord && !tournamentRecords) {
38246
- if (typeof tournamentRecord !== 'object') {
38247
- return { error: INVALID_TOURNAMENT_RECORD };
38248
- }
38249
- else {
38250
- tournamentRecords = (_b = {}, _b[tournamentRecord.tournamentId] = tournamentRecord, _b);
38251
- }
38252
- }
38253
- var noTournamentRecords = typeof tournamentRecords !== 'object' ||
38254
- !Object.keys(tournamentRecords).length;
38255
- var needsTournamentRecords = !inContextMatchUps ||
38256
- (!schedulingProfile &&
38257
- (excludeScheduleDateProfileRounds ||
38258
- excludeCompletedRounds ||
38259
- schedulingProfile ||
38260
- withSplitRounds));
38261
- if (needsTournamentRecords && noTournamentRecords)
38262
- return { error: MISSING_TOURNAMENT_RECORDS };
38263
- var events = Object.values(tournamentRecords !== null && tournamentRecords !== void 0 ? tournamentRecords : {})
38264
- .map(function (_a) {
38265
- var events = _a.events;
38266
- return events;
38267
- })
38268
- .flat();
38269
- var _d = (tournamentRecords &&
38270
- (excludeScheduleDateProfileRounds ||
38271
- excludeCompletedRounds ||
38272
- schedulingProfile ||
38273
- withSplitRounds) &&
38274
- getProfileRounds({ tournamentRecords: tournamentRecords, schedulingProfile: schedulingProfile })) ||
38275
- {}, segmentedRounds = _d.segmentedRounds, profileRounds = _d.profileRounds;
38276
- var profileRoundsMap = excludeScheduleDateProfileRounds && Object.assign.apply(Object, __spreadArray([{}], __read(profileRounds.map(function (profile) {
38277
- var _a;
38278
- return (_a = {}, _a[profile.id] = profile, _a);
38279
- })), false));
38280
- var consideredMatchUps = inContextMatchUps ||
38281
- (tournamentRecords &&
38282
- ((_c = allCompetitionMatchUps({ tournamentRecords: tournamentRecords, matchUpFilters: matchUpFilters })) === null || _c === void 0 ? void 0 : _c.matchUps)) ||
38283
- [];
38284
- var excludedRounds = [];
38285
- var rounds = (consideredMatchUps &&
38286
- Object.values(consideredMatchUps.reduce(function (rounds, matchUp) {
38287
- var _a;
38288
- var _b, _c;
38289
- var id = getRoundId(matchUp).id;
38290
- var segmentsCount = segmentedRounds === null || segmentedRounds === void 0 ? void 0 : segmentedRounds[id];
38291
- 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);
38292
- 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;
38293
- var relevantStructureId = isRoundRobin
38294
- ? containerStructureId
38295
- : structureId;
38296
- return __assign(__assign({}, rounds), (_a = {}, _a[id] = {
38297
- id: withRoundId ? id : undefined,
38298
- structureId: relevantStructureId,
38299
- stageSequence: stageSequence,
38300
- segmentsCount: segmentsCount,
38301
- structureName: structureName,
38302
- tournamentId: tournamentId,
38303
- matchUpType: matchUpType,
38304
- roundNumber: roundNumber,
38305
- roundOffset: roundOffset,
38306
- eventName: eventName,
38307
- roundName: roundName,
38308
- drawName: drawName,
38309
- matchUps: matchUps,
38310
- eventId: eventId,
38311
- drawId: drawId,
38312
- }, _a));
38313
- }, {}))
38314
- .map(function (round) {
38315
- var _a = getFinishingPositionDetails(round.matchUps), minFinishingSum = _a.minFinishingSum, winnerFinishingPositionRange = _a.winnerFinishingPositionRange;
38316
- var segmentsCount = round.segmentsCount;
38317
- if (segmentsCount) {
38318
- var chunkSize = round.matchUps.length / segmentsCount;
38319
- var sortedMatchUps = chunkArray(round.matchUps.sort(function (a, b) { return a.roundPosition - b.roundPosition; }), chunkSize);
38320
- return sortedMatchUps.map(function (matchUps, i) {
38321
- var _a = getRoundProfile(matchUps), unscheduledCount = _a.unscheduledCount, incompleteCount = _a.incompleteCount, matchUpsCount = _a.matchUpsCount, isScheduled = _a.isScheduled, isComplete = _a.isComplete, byeCount = _a.byeCount;
38322
- var roundTiming = getRoundTiming({
38323
- matchUps: round.matchUps,
38324
- tournamentRecords: tournamentRecords,
38325
- events: events,
38326
- round: round,
38327
- });
38328
- 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 }));
38329
- });
38330
- }
38331
- var _b = getRoundProfile(round.matchUps), unscheduledCount = _b.unscheduledCount, incompleteCount = _b.incompleteCount, matchUpsCount = _b.matchUpsCount, isScheduled = _b.isScheduled, isComplete = _b.isComplete, byeCount = _b.byeCount;
38332
- var roundTiming = getRoundTiming({
38333
- matchUps: round.matchUps,
38334
- tournamentRecords: tournamentRecords,
38335
- events: events,
38336
- round: round,
38337
- });
38338
- 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 }));
38339
- })
38340
- .flat()
38341
- .filter(function (round) {
38342
- if (excludeScheduleDateProfileRounds) {
38343
- var scheduleDate = extractDate(excludeScheduleDateProfileRounds);
38344
- var roundId = withRoundId ? round.id : getRoundId(round).id;
38345
- if (scheduleDate &&
38346
- profileRoundsMap[roundId] &&
38347
- extractDate(profileRoundsMap[roundId].scheduleDate) ===
38348
- scheduleDate) {
38349
- return false;
38350
- }
38351
- }
38352
- var isComplete = round.isComplete, isScheduled = round.isScheduled;
38353
- var keepComplete = !excludeCompletedRounds || !isComplete;
38354
- var keepScheduled = !excludeScheduledRounds || !isScheduled;
38355
- var keepRound = keepComplete && keepScheduled;
38356
- if (!keepRound)
38357
- excludedRounds.push(round);
38358
- return keepRound;
38359
- })
38360
- .sort(roundSort)) ||
38361
- [];
38362
- return __assign(__assign({}, SUCCESS), { rounds: rounds, excludedRounds: excludedRounds });
38363
- }
38364
- function getRoundTiming(_a) {
38365
- var round = _a.round, matchUps = _a.matchUps, events = _a.events, tournamentRecords = _a.tournamentRecords;
38366
- var event = events.find(function (event) { return event.eventId === round.eventId; });
38367
- var _b = event || {}, eventType = _b.eventType, category = _b.category, categoryType = _b.categoryType;
38368
- var _c = category || {}, categoryName = _c.categoryName, ageCategoryCode = _c.ageCategoryCode;
38369
- var formatCounts = instanceCount(matchUps.map(function (_a) {
38370
- var matchUpFormat = _a.matchUpFormat;
38371
- return matchUpFormat;
38372
- }));
38373
- var roundMinutes = 0;
38374
- Object.keys(formatCounts).forEach(function (matchUpFormat) {
38375
- var formatCount = formatCounts[matchUpFormat];
38376
- var result = findMatchUpFormatTiming({
38377
- categoryName: categoryName || ageCategoryCode,
38378
- tournamentId: round.tournamentId,
38379
- eventId: round.eventId,
38380
- tournamentRecords: tournamentRecords,
38381
- matchUpFormat: matchUpFormat,
38382
- categoryType: categoryType,
38383
- eventType: eventType,
38384
- });
38385
- if (result.error)
38386
- return result;
38387
- var formatMinutes = result.averageMinutes * formatCount;
38388
- if (!isNaN(roundMinutes))
38389
- roundMinutes += formatMinutes;
38390
- return undefined;
38391
- });
38392
- return { roundMinutes: roundMinutes };
38393
- }
38394
- // Sort rounds by order in which they will be played
38395
- function roundSort(a, b) {
38396
- return (a.eventName.localeCompare(b.eventName) ||
38397
- a.eventId.localeCompare(b.eventId) ||
38398
- (stageOrder[a === null || a === void 0 ? void 0 : a.stage] || 0) - (stageOrder[b === null || b === void 0 ? void 0 : b.stage] || 0) ||
38399
- b.matchUpsCount - a.matchUpsCount ||
38400
- "".concat(a.stageSequence, "-").concat(a.roundNumber, "-").concat(a.minFinishingSum).localeCompare("".concat(b.stageSequence, "-").concat(b.roundNumber, "-").concat(b.minFinishingSum)));
38401
- }
38402
- function getFinishingPositionDetails(matchUps) {
38403
- return (matchUps || []).reduce(function (foo, matchUp) {
38404
- var _a, _b;
38405
- var sum = (((_a = matchUp.finishingPositionRange) === null || _a === void 0 ? void 0 : _a.winner) || []).reduce(function (a, b) { return a + b; }, 0);
38406
- var winnerFinishingPositionRange = (((_b = matchUp.finishingPositionRange) === null || _b === void 0 ? void 0 : _b.winner) || []).join('-') || '';
38407
- return !foo.minFinishingSum || sum < foo.minFinishingSum
38408
- ? { minFinishingSum: sum, winnerFinishingPositionRange: winnerFinishingPositionRange }
38409
- : foo;
38410
- }, { minFinishingSum: 0, winnerFinishingPositionRange: '' });
38411
- }
38412
-
38413
38136
  function bulkUpdateCourtAssignments(_a) {
38414
38137
  var tournamentRecords = _a.tournamentRecords, courtAssignments = _a.courtAssignments, courtDayDate = _a.courtDayDate;
38415
38138
  if (!tournamentRecords)
@@ -38855,6 +38578,148 @@ function reorderUpcomingMatchUps(params) {
38855
38578
  }
38856
38579
  }
38857
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
+
38858
38723
  function addMatchUpScheduleItems$1(params) {
38859
38724
  return addMatchUpScheduleItems$2(params);
38860
38725
  }
@@ -39495,6 +39360,171 @@ function matchUpScheduleChange(params) {
39495
39360
  }
39496
39361
  }
39497
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
+
39498
39528
  function addMatchUpScheduleItems(params) {
39499
39529
  var result = getDrawDefinition$1(params);
39500
39530
  if (result.error)
@@ -42375,20 +42405,28 @@ var competitionEngine = (function () {
42375
42405
  var elapsed = Date.now() - start;
42376
42406
  var devContext = getDevContext();
42377
42407
  var log = { method: methodName };
42378
- var logErrors = typeof devContext.result === 'object' && devContext.result.error;
42379
- 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) &&
42380
42416
  (isNaN(devContext.perf) || elapsed > devContext.perf))
42381
42417
  log.elapsed = elapsed;
42382
- if (logErrors ||
42383
- (devContext.params && !Array.isArray(devContext.params)) ||
42384
- (Array.isArray(devContext.params) &&
42385
- ((_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))))) {
42386
42423
  log.params = params;
42387
42424
  }
42388
- if (logErrors ||
42389
- (!logErrors && devContext.result && !Array.isArray(devContext.result)) ||
42390
- (Array.isArray(devContext.result) &&
42391
- ((_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))))) {
42392
42430
  log.result = result;
42393
42431
  }
42394
42432
  if (Object.keys(log).length > 1)
@@ -64997,20 +65035,28 @@ var tournamentEngine = (function () {
64997
65035
  var elapsed = Date.now() - start;
64998
65036
  var devContext = getDevContext();
64999
65037
  var log = { method: methodName };
65000
- var logErrors = typeof devContext.result === 'object' && devContext.result.error;
65001
- 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) &&
65002
65046
  (isNaN(devContext.perf) || elapsed > devContext.perf))
65003
65047
  log.elapsed = elapsed;
65004
- if (logErrors ||
65005
- (devContext.params && !Array.isArray(devContext.params)) ||
65006
- (Array.isArray(devContext.params) &&
65007
- ((_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))))) {
65008
65053
  log.params = params;
65009
65054
  }
65010
- if (logErrors ||
65011
- (!logErrors && devContext.result && !Array.isArray(devContext.result)) ||
65012
- (Array.isArray(devContext.result) &&
65013
- ((_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))))) {
65014
65060
  log.result = result;
65015
65061
  }
65016
65062
  if (Object.keys(log).length > 1)