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.
package/dist/index.mjs CHANGED
@@ -2375,7 +2375,7 @@ const matchUpFormatCode = {
2375
2375
  };
2376
2376
 
2377
2377
  function factoryVersion() {
2378
- return "1.8.6";
2378
+ return "1.8.7";
2379
2379
  }
2380
2380
 
2381
2381
  function getObjectTieFormat(obj) {
@@ -35135,326 +35135,6 @@ function getMatchUpDailyLimitsUpdate$1({ tournamentRecords }) {
35135
35135
  });
35136
35136
  }
35137
35137
 
35138
- const { stageOrder } = drawDefinitionConstants;
35139
- function getProfileRounds({
35140
- tournamentRecords,
35141
- schedulingProfile,
35142
- tournamentRecord,
35143
- withRoundId
35144
- }) {
35145
- if (tournamentRecord && !tournamentRecords) {
35146
- if (typeof tournamentRecord !== "object") {
35147
- return { error: INVALID_TOURNAMENT_RECORD };
35148
- } else {
35149
- tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
35150
- }
35151
- }
35152
- if (schedulingProfile) {
35153
- const profileValidity = validateSchedulingProfile({
35154
- tournamentRecords,
35155
- schedulingProfile
35156
- });
35157
- if (profileValidity.error)
35158
- return profileValidity;
35159
- }
35160
- if (!schedulingProfile && tournamentRecords) {
35161
- const result = getSchedulingProfile$1({ tournamentRecords });
35162
- if (result.error)
35163
- return result;
35164
- schedulingProfile = result.schedulingProfile;
35165
- }
35166
- if (!schedulingProfile)
35167
- return { error: NOT_FOUND };
35168
- const segmentedRounds = {};
35169
- const profileRounds = schedulingProfile.map(
35170
- ({ venues, scheduleDate }) => venues.map(
35171
- ({ rounds }) => rounds.map((round) => {
35172
- const roundRef = getRoundId(round);
35173
- if (roundRef.roundSegment?.segmentsCount) {
35174
- segmentedRounds[roundRef.id] = roundRef.roundSegment.segmentsCount;
35175
- }
35176
- return definedAttributes({
35177
- id: withRoundId ? roundRef.id : void 0,
35178
- scheduleDate,
35179
- ...roundRef
35180
- });
35181
- })
35182
- )
35183
- ).flat(Infinity);
35184
- return { profileRounds, segmentedRounds };
35185
- }
35186
- function getRoundId(obj) {
35187
- const {
35188
- containerStructureId,
35189
- roundSegment,
35190
- isRoundRobin,
35191
- tournamentId,
35192
- roundNumber,
35193
- structureId,
35194
- eventId,
35195
- drawId
35196
- } = obj;
35197
- const relevantStructureId = isRoundRobin ? containerStructureId : structureId;
35198
- const id = [
35199
- tournamentId,
35200
- // 1
35201
- eventId,
35202
- // 2
35203
- drawId,
35204
- // 3
35205
- relevantStructureId,
35206
- // 4
35207
- roundNumber
35208
- // 5
35209
- ].join("|");
35210
- return definedAttributes({
35211
- id,
35212
- roundSegment,
35213
- tournamentId,
35214
- eventId,
35215
- drawId,
35216
- structureId: relevantStructureId,
35217
- roundNumber
35218
- });
35219
- }
35220
- function getRoundProfile(matchUps) {
35221
- const matchUpsCount = matchUps.length;
35222
- const byeCount = matchUps.filter(({ sides }) => sides?.some(({ bye }) => bye)).length || 0;
35223
- const completedCount = matchUps.filter(
35224
- ({ winningSide, matchUpStatus }) => winningSide || completedMatchUpStatuses.includes(matchUpStatus)
35225
- ).length || 0;
35226
- const scheduledCount = matchUps.filter(
35227
- ({ schedule }) => schedule?.scheduledDate && schedule?.scheduledTime
35228
- ).length || 0;
35229
- const consideredCount = matchUpsCount - byeCount;
35230
- const isComplete = consideredCount === completedCount;
35231
- const unscheduledCount = consideredCount - scheduledCount;
35232
- const incompleteCount = consideredCount - scheduledCount;
35233
- const isScheduled = consideredCount === scheduledCount;
35234
- return {
35235
- unscheduledCount,
35236
- incompleteCount,
35237
- scheduledCount,
35238
- completedCount,
35239
- matchUpsCount,
35240
- isScheduled,
35241
- isComplete,
35242
- byeCount
35243
- };
35244
- }
35245
- function getRounds({
35246
- excludeScheduleDateProfileRounds,
35247
- excludeScheduledRounds,
35248
- excludeCompletedRounds,
35249
- inContextMatchUps,
35250
- tournamentRecords,
35251
- schedulingProfile,
35252
- tournamentRecord,
35253
- withSplitRounds,
35254
- matchUpFilters,
35255
- withRoundId,
35256
- context
35257
- }) {
35258
- if (inContextMatchUps && !Array.isArray(
35259
- inContextMatchUps || typeof inContextMatchUps[0] !== "object"
35260
- )) {
35261
- return { error: INVALID_VALUES, inContextMatchUps };
35262
- }
35263
- if (tournamentRecord && !tournamentRecords) {
35264
- if (typeof tournamentRecord !== "object") {
35265
- return { error: INVALID_TOURNAMENT_RECORD };
35266
- } else {
35267
- tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
35268
- }
35269
- }
35270
- const noTournamentRecords = typeof tournamentRecords !== "object" || !Object.keys(tournamentRecords).length;
35271
- const needsTournamentRecords = !inContextMatchUps || !schedulingProfile && (excludeScheduleDateProfileRounds || excludeCompletedRounds || schedulingProfile || withSplitRounds);
35272
- if (needsTournamentRecords && noTournamentRecords)
35273
- return { error: MISSING_TOURNAMENT_RECORDS };
35274
- const events = Object.values(tournamentRecords ?? {}).map(({ events: events2 }) => events2).flat();
35275
- const { segmentedRounds, profileRounds } = tournamentRecords && (excludeScheduleDateProfileRounds || excludeCompletedRounds || schedulingProfile || withSplitRounds) && getProfileRounds({ tournamentRecords, schedulingProfile }) || {};
35276
- const profileRoundsMap = excludeScheduleDateProfileRounds && Object.assign(
35277
- {},
35278
- ...profileRounds.map((profile) => ({ [profile.id]: profile }))
35279
- );
35280
- const consideredMatchUps = inContextMatchUps || tournamentRecords && allCompetitionMatchUps({ tournamentRecords, matchUpFilters })?.matchUps || [];
35281
- const excludedRounds = [];
35282
- const rounds = consideredMatchUps && Object.values(
35283
- consideredMatchUps.reduce((rounds2, matchUp) => {
35284
- const id = getRoundId(matchUp).id;
35285
- const segmentsCount = segmentedRounds?.[id];
35286
- const matchUps = [...rounds2[id]?.matchUps ?? [], matchUp];
35287
- const {
35288
- containerStructureId,
35289
- stageSequence,
35290
- structureName,
35291
- tournamentId,
35292
- isRoundRobin,
35293
- matchUpType,
35294
- roundNumber,
35295
- roundOffset,
35296
- structureId,
35297
- eventName,
35298
- roundName,
35299
- drawName,
35300
- eventId,
35301
- drawId
35302
- } = matchUp;
35303
- const relevantStructureId = isRoundRobin ? containerStructureId : structureId;
35304
- return {
35305
- ...rounds2,
35306
- [id]: {
35307
- id: withRoundId ? id : void 0,
35308
- structureId: relevantStructureId,
35309
- stageSequence,
35310
- segmentsCount,
35311
- structureName,
35312
- tournamentId,
35313
- matchUpType,
35314
- roundNumber,
35315
- roundOffset,
35316
- eventName,
35317
- roundName,
35318
- drawName,
35319
- matchUps,
35320
- eventId,
35321
- drawId
35322
- }
35323
- };
35324
- }, {})
35325
- ).map((round) => {
35326
- const { minFinishingSum, winnerFinishingPositionRange } = getFinishingPositionDetails(round.matchUps);
35327
- const segmentsCount = round.segmentsCount;
35328
- if (segmentsCount) {
35329
- const chunkSize = round.matchUps.length / segmentsCount;
35330
- const sortedMatchUps = chunkArray(
35331
- round.matchUps.sort((a, b) => a.roundPosition - b.roundPosition),
35332
- chunkSize
35333
- );
35334
- return sortedMatchUps.map((matchUps, i) => {
35335
- const {
35336
- unscheduledCount: unscheduledCount2,
35337
- incompleteCount: incompleteCount2,
35338
- matchUpsCount: matchUpsCount2,
35339
- isScheduled: isScheduled2,
35340
- isComplete: isComplete2,
35341
- byeCount: byeCount2
35342
- } = getRoundProfile(matchUps);
35343
- const roundTiming2 = getRoundTiming({
35344
- matchUps: round.matchUps,
35345
- tournamentRecords,
35346
- events,
35347
- round
35348
- });
35349
- return definedAttributes({
35350
- ...round,
35351
- ...context,
35352
- roundSegment: { segmentsCount, segmentNumber: i + 1 },
35353
- winnerFinishingPositionRange,
35354
- unscheduledCount: unscheduledCount2,
35355
- incompleteCount: incompleteCount2,
35356
- minFinishingSum,
35357
- matchUpsCount: matchUpsCount2,
35358
- isScheduled: isScheduled2,
35359
- roundTiming: roundTiming2,
35360
- isComplete: isComplete2,
35361
- byeCount: byeCount2,
35362
- matchUps
35363
- });
35364
- });
35365
- }
35366
- const {
35367
- unscheduledCount,
35368
- incompleteCount,
35369
- matchUpsCount,
35370
- isScheduled,
35371
- isComplete,
35372
- byeCount
35373
- } = getRoundProfile(round.matchUps);
35374
- const roundTiming = getRoundTiming({
35375
- matchUps: round.matchUps,
35376
- tournamentRecords,
35377
- events,
35378
- round
35379
- });
35380
- return definedAttributes({
35381
- ...round,
35382
- ...context,
35383
- winnerFinishingPositionRange,
35384
- unscheduledCount,
35385
- incompleteCount,
35386
- minFinishingSum,
35387
- matchUpsCount,
35388
- isScheduled,
35389
- roundTiming,
35390
- isComplete,
35391
- byeCount
35392
- });
35393
- }).flat().filter((round) => {
35394
- if (excludeScheduleDateProfileRounds) {
35395
- const scheduleDate = extractDate(excludeScheduleDateProfileRounds);
35396
- const roundId = withRoundId ? round.id : getRoundId(round).id;
35397
- if (scheduleDate && profileRoundsMap[roundId] && extractDate(profileRoundsMap[roundId].scheduleDate) === scheduleDate) {
35398
- return false;
35399
- }
35400
- }
35401
- const { isComplete, isScheduled } = round;
35402
- const keepComplete = !excludeCompletedRounds || !isComplete;
35403
- const keepScheduled = !excludeScheduledRounds || !isScheduled;
35404
- const keepRound = keepComplete && keepScheduled;
35405
- if (!keepRound)
35406
- excludedRounds.push(round);
35407
- return keepRound;
35408
- }).sort(roundSort) || [];
35409
- return { ...SUCCESS, rounds, excludedRounds };
35410
- }
35411
- function getRoundTiming({ round, matchUps, events, tournamentRecords }) {
35412
- const event = events.find((event2) => event2.eventId === round.eventId);
35413
- const { eventType, category, categoryType } = event || {};
35414
- const { categoryName, ageCategoryCode } = category || {};
35415
- const formatCounts = instanceCount(
35416
- matchUps.map(({ matchUpFormat }) => matchUpFormat)
35417
- );
35418
- let roundMinutes = 0;
35419
- Object.keys(formatCounts).forEach((matchUpFormat) => {
35420
- const formatCount = formatCounts[matchUpFormat];
35421
- const result = findMatchUpFormatTiming({
35422
- categoryName: categoryName || ageCategoryCode,
35423
- tournamentId: round.tournamentId,
35424
- eventId: round.eventId,
35425
- tournamentRecords,
35426
- matchUpFormat,
35427
- categoryType,
35428
- eventType
35429
- });
35430
- if (result.error)
35431
- return result;
35432
- const formatMinutes = result.averageMinutes * formatCount;
35433
- if (!isNaN(roundMinutes))
35434
- roundMinutes += formatMinutes;
35435
- return void 0;
35436
- });
35437
- return { roundMinutes };
35438
- }
35439
- function roundSort(a, b) {
35440
- return a.eventName.localeCompare(b.eventName) || a.eventId.localeCompare(b.eventId) || (stageOrder[a?.stage] || 0) - (stageOrder[b?.stage] || 0) || b.matchUpsCount - a.matchUpsCount || `${a.stageSequence}-${a.roundNumber}-${a.minFinishingSum}`.localeCompare(
35441
- `${b.stageSequence}-${b.roundNumber}-${b.minFinishingSum}`
35442
- );
35443
- }
35444
- function getFinishingPositionDetails(matchUps) {
35445
- return (matchUps || []).reduce(
35446
- (foo, matchUp) => {
35447
- const sum = (matchUp.finishingPositionRange?.winner || []).reduce(
35448
- (a, b) => a + b,
35449
- 0
35450
- );
35451
- const winnerFinishingPositionRange = (matchUp.finishingPositionRange?.winner || []).join("-") || "";
35452
- return !foo.minFinishingSum || sum < foo.minFinishingSum ? { minFinishingSum: sum, winnerFinishingPositionRange } : foo;
35453
- },
35454
- { minFinishingSum: 0, winnerFinishingPositionRange: "" }
35455
- );
35456
- }
35457
-
35458
35138
  function bulkUpdateCourtAssignments({
35459
35139
  tournamentRecords,
35460
35140
  courtAssignments,
@@ -35885,6 +35565,155 @@ function reorderUpcomingMatchUps(params) {
35885
35565
  }
35886
35566
  }
35887
35567
 
35568
+ function getRoundId(obj) {
35569
+ const {
35570
+ containerStructureId,
35571
+ roundSegment,
35572
+ isRoundRobin,
35573
+ tournamentId,
35574
+ roundNumber,
35575
+ structureId,
35576
+ eventId,
35577
+ drawId
35578
+ } = obj;
35579
+ const relevantStructureId = isRoundRobin ? containerStructureId : structureId;
35580
+ const id = [
35581
+ tournamentId,
35582
+ // 1
35583
+ eventId,
35584
+ // 2
35585
+ drawId,
35586
+ // 3
35587
+ relevantStructureId,
35588
+ // 4
35589
+ roundNumber
35590
+ // 5
35591
+ ].join("|");
35592
+ return definedAttributes({
35593
+ structureId: relevantStructureId,
35594
+ roundSegment,
35595
+ tournamentId,
35596
+ roundNumber,
35597
+ eventId,
35598
+ drawId,
35599
+ id
35600
+ });
35601
+ }
35602
+ function getRoundTiming({ round, matchUps, events, tournamentRecords }) {
35603
+ const event = events.find((event2) => event2.eventId === round.eventId);
35604
+ const { eventType, category, categoryType } = event || {};
35605
+ const { categoryName, ageCategoryCode } = category || {};
35606
+ const formatCounts = instanceCount(
35607
+ matchUps.map(({ matchUpFormat }) => matchUpFormat)
35608
+ );
35609
+ let roundMinutes = 0;
35610
+ Object.keys(formatCounts).forEach((matchUpFormat) => {
35611
+ const formatCount = formatCounts[matchUpFormat];
35612
+ const result = findMatchUpFormatTiming({
35613
+ categoryName: categoryName || ageCategoryCode,
35614
+ tournamentId: round.tournamentId,
35615
+ eventId: round.eventId,
35616
+ tournamentRecords,
35617
+ matchUpFormat,
35618
+ categoryType,
35619
+ eventType
35620
+ });
35621
+ if (result.error)
35622
+ return result;
35623
+ const formatMinutes = result.averageMinutes * formatCount;
35624
+ if (!isNaN(roundMinutes))
35625
+ roundMinutes += formatMinutes;
35626
+ return void 0;
35627
+ });
35628
+ return { roundMinutes };
35629
+ }
35630
+ function getFinishingPositionDetails(matchUps) {
35631
+ return (matchUps || []).reduce(
35632
+ (foo, matchUp) => {
35633
+ const sum = (matchUp.finishingPositionRange?.winner || []).reduce(
35634
+ (a, b) => a + b,
35635
+ 0
35636
+ );
35637
+ const winnerFinishingPositionRange = (matchUp.finishingPositionRange?.winner || []).join("-") || "";
35638
+ return !foo.minFinishingSum || sum < foo.minFinishingSum ? { minFinishingSum: sum, winnerFinishingPositionRange } : foo;
35639
+ },
35640
+ { minFinishingSum: 0, winnerFinishingPositionRange: "" }
35641
+ );
35642
+ }
35643
+ function getRoundProfile(matchUps) {
35644
+ const matchUpsCount = matchUps.length;
35645
+ const byeCount = matchUps.filter(({ sides }) => sides?.some(({ bye }) => bye)).length || 0;
35646
+ const completedCount = matchUps.filter(
35647
+ ({ winningSide, matchUpStatus }) => winningSide || completedMatchUpStatuses.includes(matchUpStatus)
35648
+ ).length || 0;
35649
+ const scheduledCount = matchUps.filter(
35650
+ ({ schedule }) => schedule?.scheduledDate && schedule?.scheduledTime
35651
+ ).length || 0;
35652
+ const consideredCount = matchUpsCount - byeCount;
35653
+ const isComplete = consideredCount === completedCount;
35654
+ const unscheduledCount = consideredCount - scheduledCount;
35655
+ const incompleteCount = consideredCount - scheduledCount;
35656
+ const isScheduled = consideredCount === scheduledCount;
35657
+ return {
35658
+ unscheduledCount,
35659
+ incompleteCount,
35660
+ scheduledCount,
35661
+ completedCount,
35662
+ matchUpsCount,
35663
+ isScheduled,
35664
+ isComplete,
35665
+ byeCount
35666
+ };
35667
+ }
35668
+
35669
+ function getProfileRounds({
35670
+ tournamentRecords,
35671
+ schedulingProfile,
35672
+ tournamentRecord,
35673
+ withRoundId
35674
+ }) {
35675
+ if (tournamentRecord && !tournamentRecords) {
35676
+ if (typeof tournamentRecord !== "object") {
35677
+ return { error: INVALID_TOURNAMENT_RECORD };
35678
+ } else {
35679
+ tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
35680
+ }
35681
+ }
35682
+ if (schedulingProfile) {
35683
+ const profileValidity = validateSchedulingProfile({
35684
+ tournamentRecords,
35685
+ schedulingProfile
35686
+ });
35687
+ if (profileValidity.error)
35688
+ return profileValidity;
35689
+ }
35690
+ if (!schedulingProfile && tournamentRecords) {
35691
+ const result = getSchedulingProfile$1({ tournamentRecords });
35692
+ if (result.error)
35693
+ return result;
35694
+ schedulingProfile = result.schedulingProfile;
35695
+ }
35696
+ if (!schedulingProfile)
35697
+ return { error: NOT_FOUND };
35698
+ const segmentedRounds = {};
35699
+ const profileRounds = schedulingProfile.map(
35700
+ ({ venues, scheduleDate }) => venues.map(
35701
+ ({ rounds }) => rounds.map((round) => {
35702
+ const roundRef = getRoundId(round);
35703
+ if (roundRef.roundSegment?.segmentsCount) {
35704
+ segmentedRounds[roundRef.id] = roundRef.roundSegment.segmentsCount;
35705
+ }
35706
+ return definedAttributes({
35707
+ id: withRoundId ? roundRef.id : void 0,
35708
+ scheduleDate,
35709
+ ...roundRef
35710
+ });
35711
+ })
35712
+ )
35713
+ ).flat(Infinity);
35714
+ return { profileRounds, segmentedRounds };
35715
+ }
35716
+
35888
35717
  function addMatchUpScheduleItems$1(params) {
35889
35718
  return addMatchUpScheduleItems$2(params);
35890
35719
  }
@@ -36502,6 +36331,200 @@ function matchUpScheduleChange(params) {
36502
36331
  }
36503
36332
  }
36504
36333
 
36334
+ const { stageOrder } = drawDefinitionConstants;
36335
+ function roundSort(a, b) {
36336
+ return a.eventName.localeCompare(b.eventName) || a.eventId.localeCompare(b.eventId) || (stageOrder[a?.stage] || 0) - (stageOrder[b?.stage] || 0) || b.matchUpsCount - a.matchUpsCount || `${a.stageSequence}-${a.roundNumber}-${a.minFinishingSum}`.localeCompare(
36337
+ `${b.stageSequence}-${b.roundNumber}-${b.minFinishingSum}`
36338
+ );
36339
+ }
36340
+
36341
+ function getRounds({
36342
+ excludeScheduleDateProfileRounds,
36343
+ excludeScheduledRounds,
36344
+ excludeCompletedRounds,
36345
+ inContextMatchUps,
36346
+ tournamentRecords,
36347
+ schedulingProfile,
36348
+ tournamentRecord,
36349
+ withSplitRounds,
36350
+ matchUpFilters,
36351
+ scheduleDate,
36352
+ withRoundId,
36353
+ venueId,
36354
+ context
36355
+ }) {
36356
+ if (inContextMatchUps && !Array.isArray(
36357
+ inContextMatchUps || typeof inContextMatchUps[0] !== "object"
36358
+ )) {
36359
+ return { error: INVALID_VALUES, inContextMatchUps };
36360
+ }
36361
+ if (tournamentRecord && !tournamentRecords) {
36362
+ if (typeof tournamentRecord !== "object") {
36363
+ return { error: INVALID_TOURNAMENT_RECORD };
36364
+ } else {
36365
+ tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
36366
+ }
36367
+ }
36368
+ const noTournamentRecords = typeof tournamentRecords !== "object" || !Object.keys(tournamentRecords).length;
36369
+ const needsTournamentRecords = venueId || scheduleDate || !inContextMatchUps || !schedulingProfile && (excludeScheduleDateProfileRounds || excludeCompletedRounds || schedulingProfile || withSplitRounds);
36370
+ if (needsTournamentRecords && noTournamentRecords)
36371
+ return { error: MISSING_TOURNAMENT_RECORDS };
36372
+ const tournamentVenueIds = Object.assign(
36373
+ {},
36374
+ ...Object.values(tournamentRecords ?? {}).map(
36375
+ ({ venues = [], tournamentId }) => ({
36376
+ [tournamentId]: venues?.map(({ venueId: venueId2 }) => venueId2)
36377
+ })
36378
+ )
36379
+ );
36380
+ const events = Object.values(tournamentRecords ?? {}).map(
36381
+ ({ events: events2 = [], tournamentId, startDate, endDate }) => events2.map((event) => ({
36382
+ ...event,
36383
+ validVenueIds: tournamentVenueIds[tournamentId],
36384
+ startDate: event.startDate ?? startDate,
36385
+ endDate: event.endDate ?? endDate
36386
+ }))
36387
+ ).flat();
36388
+ const { segmentedRounds, profileRounds } = tournamentRecords && (excludeScheduleDateProfileRounds || excludeCompletedRounds || schedulingProfile || withSplitRounds) && getProfileRounds({ tournamentRecords, schedulingProfile }) || {};
36389
+ const profileRoundsMap = excludeScheduleDateProfileRounds && Object.assign(
36390
+ {},
36391
+ ...profileRounds.map((profile) => ({ [profile.id]: profile }))
36392
+ );
36393
+ const consideredMatchUps = inContextMatchUps || tournamentRecords && allCompetitionMatchUps({ tournamentRecords, matchUpFilters })?.matchUps || [];
36394
+ const excludedRounds = [];
36395
+ const rounds = consideredMatchUps && Object.values(
36396
+ consideredMatchUps.reduce((rounds2, matchUp) => {
36397
+ const id = getRoundId(matchUp).id;
36398
+ const segmentsCount = segmentedRounds?.[id];
36399
+ const matchUps = [...rounds2[id]?.matchUps ?? [], matchUp];
36400
+ const {
36401
+ containerStructureId,
36402
+ stageSequence,
36403
+ structureName,
36404
+ tournamentId,
36405
+ isRoundRobin,
36406
+ matchUpType,
36407
+ roundNumber,
36408
+ roundOffset,
36409
+ structureId,
36410
+ eventName,
36411
+ roundName,
36412
+ drawName,
36413
+ eventId,
36414
+ drawId
36415
+ } = matchUp;
36416
+ const relevantStructureId = isRoundRobin ? containerStructureId : structureId;
36417
+ return {
36418
+ ...rounds2,
36419
+ [id]: {
36420
+ id: withRoundId ? id : void 0,
36421
+ structureId: relevantStructureId,
36422
+ stageSequence,
36423
+ segmentsCount,
36424
+ structureName,
36425
+ tournamentId,
36426
+ matchUpType,
36427
+ roundNumber,
36428
+ roundOffset,
36429
+ eventName,
36430
+ roundName,
36431
+ drawName,
36432
+ matchUps,
36433
+ eventId,
36434
+ drawId
36435
+ }
36436
+ };
36437
+ }, {})
36438
+ ).map((round) => {
36439
+ const { minFinishingSum, winnerFinishingPositionRange } = getFinishingPositionDetails(round.matchUps);
36440
+ const segmentsCount = round.segmentsCount;
36441
+ if (segmentsCount) {
36442
+ const chunkSize = round.matchUps.length / segmentsCount;
36443
+ const sortedMatchUps = chunkArray(
36444
+ round.matchUps.sort((a, b) => a.roundPosition - b.roundPosition),
36445
+ chunkSize
36446
+ );
36447
+ return sortedMatchUps.map((matchUps, i) => {
36448
+ const {
36449
+ unscheduledCount: unscheduledCount2,
36450
+ incompleteCount: incompleteCount2,
36451
+ matchUpsCount: matchUpsCount2,
36452
+ isScheduled: isScheduled2,
36453
+ isComplete: isComplete2,
36454
+ byeCount: byeCount2
36455
+ } = getRoundProfile(matchUps);
36456
+ const roundTiming2 = getRoundTiming({
36457
+ matchUps: round.matchUps,
36458
+ tournamentRecords,
36459
+ events,
36460
+ round
36461
+ });
36462
+ return definedAttributes({
36463
+ ...round,
36464
+ ...context,
36465
+ roundSegment: { segmentsCount, segmentNumber: i + 1 },
36466
+ winnerFinishingPositionRange,
36467
+ unscheduledCount: unscheduledCount2,
36468
+ incompleteCount: incompleteCount2,
36469
+ minFinishingSum,
36470
+ matchUpsCount: matchUpsCount2,
36471
+ isScheduled: isScheduled2,
36472
+ roundTiming: roundTiming2,
36473
+ isComplete: isComplete2,
36474
+ byeCount: byeCount2,
36475
+ matchUps
36476
+ });
36477
+ });
36478
+ }
36479
+ const {
36480
+ unscheduledCount,
36481
+ incompleteCount,
36482
+ matchUpsCount,
36483
+ isScheduled,
36484
+ isComplete,
36485
+ byeCount
36486
+ } = getRoundProfile(round.matchUps);
36487
+ const roundTiming = getRoundTiming({
36488
+ matchUps: round.matchUps,
36489
+ tournamentRecords,
36490
+ events,
36491
+ round
36492
+ });
36493
+ return definedAttributes({
36494
+ ...round,
36495
+ ...context,
36496
+ winnerFinishingPositionRange,
36497
+ unscheduledCount,
36498
+ incompleteCount,
36499
+ minFinishingSum,
36500
+ matchUpsCount,
36501
+ isScheduled,
36502
+ roundTiming,
36503
+ isComplete,
36504
+ byeCount
36505
+ });
36506
+ }).flat().filter((round) => {
36507
+ if (excludeScheduleDateProfileRounds) {
36508
+ const scheduleDate2 = extractDate(excludeScheduleDateProfileRounds);
36509
+ const roundId = withRoundId ? round.id : getRoundId(round).id;
36510
+ if (scheduleDate2 && profileRoundsMap[roundId] && extractDate(profileRoundsMap[roundId].scheduleDate) === scheduleDate2) {
36511
+ return false;
36512
+ }
36513
+ }
36514
+ const { isComplete, isScheduled } = round;
36515
+ const keepComplete = !excludeCompletedRounds || !isComplete;
36516
+ const keepScheduled = !excludeScheduledRounds || !isScheduled;
36517
+ const event = venueId || scheduleDate ? events?.find(({ eventId }) => eventId === round.eventId) : void 0;
36518
+ const validDate = !scheduleDate || event?.startDate && event?.endDate && new Date(scheduleDate) >= new Date(event?.startDate) && new Date(scheduleDate) <= new Date(event?.endDate);
36519
+ const validVenue = !venueId || event?.validVenueIds.includes(venueId);
36520
+ const keepRound = keepComplete && keepScheduled && validVenue && validDate;
36521
+ if (!keepRound)
36522
+ excludedRounds.push(round);
36523
+ return keepRound;
36524
+ }).sort(roundSort) || [];
36525
+ return { ...SUCCESS, rounds, excludedRounds };
36526
+ }
36527
+
36505
36528
  function addMatchUpScheduleItems(params) {
36506
36529
  const result = getDrawDefinition$1(params);
36507
36530
  if (result.error)
@@ -39107,13 +39130,14 @@ const competitionEngine = function() {
39107
39130
  const elapsed = Date.now() - start;
39108
39131
  const devContext = getDevContext();
39109
39132
  const log = { method: methodName };
39110
- const logErrors = typeof devContext.result === "object" && devContext.result.error;
39111
- if (![void 0, false].includes(devContext.perf) && (isNaN(devContext.perf) || elapsed > devContext.perf))
39133
+ const logError = result.error && (devContext.errors === true || Array.isArray(devContext.errors) && devContext.errors.includes(methodName));
39134
+ const exclude = Array.isArray(devContext.exclude) && devContext.exclude.includes(methodName);
39135
+ if (!exclude && ![void 0, false].includes(devContext.perf) && (isNaN(devContext.perf) || elapsed > devContext.perf))
39112
39136
  log.elapsed = elapsed;
39113
- if (logErrors || devContext.params && !Array.isArray(devContext.params) || Array.isArray(devContext.params) && devContext.params?.includes(methodName)) {
39137
+ if (!exclude && (logError || devContext.params && !Array.isArray(devContext.params) || Array.isArray(devContext.params) && devContext.params?.includes(methodName))) {
39114
39138
  log.params = params;
39115
39139
  }
39116
- if (logErrors || !logErrors && devContext.result && !Array.isArray(devContext.result) || Array.isArray(devContext.result) && devContext.result?.includes(methodName)) {
39140
+ if (!exclude && (logError || devContext.result && !Array.isArray(devContext.result) || Array.isArray(devContext.result) && devContext.result?.includes(methodName))) {
39117
39141
  log.result = result;
39118
39142
  }
39119
39143
  if (Object.keys(log).length > 1)
@@ -59981,13 +60005,14 @@ const tournamentEngine = (() => {
59981
60005
  const elapsed = Date.now() - start;
59982
60006
  const devContext = getDevContext();
59983
60007
  const log = { method: methodName };
59984
- const logErrors = typeof devContext.result === "object" && devContext.result.error;
59985
- if (![void 0, false].includes(devContext.perf) && (isNaN(devContext.perf) || elapsed > devContext.perf))
60008
+ const logError = result.error && (devContext.errors === true || Array.isArray(devContext.errors) && devContext.errors.includes(methodName));
60009
+ const exclude = Array.isArray(devContext.exclude) && devContext.exclude.includes(methodName);
60010
+ if (!exclude && ![void 0, false].includes(devContext.perf) && (isNaN(devContext.perf) || elapsed > devContext.perf))
59986
60011
  log.elapsed = elapsed;
59987
- if (logErrors || devContext.params && !Array.isArray(devContext.params) || Array.isArray(devContext.params) && devContext.params?.includes(methodName)) {
60012
+ if (!exclude && (logError || devContext.params && !Array.isArray(devContext.params) || Array.isArray(devContext.params) && devContext.params?.includes(methodName))) {
59988
60013
  log.params = params;
59989
60014
  }
59990
- if (logErrors || !logErrors && devContext.result && !Array.isArray(devContext.result) || Array.isArray(devContext.result) && devContext.result?.includes(methodName)) {
60015
+ if (!exclude && (logError || devContext.result && !Array.isArray(devContext.result) || Array.isArray(devContext.result) && devContext.result?.includes(methodName))) {
59991
60016
  log.result = result;
59992
60017
  }
59993
60018
  if (Object.keys(log).length > 1)