tods-competition-factory 1.8.29 → 1.8.31

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
@@ -2404,7 +2404,7 @@ const matchUpFormatCode = {
2404
2404
  };
2405
2405
 
2406
2406
  function factoryVersion() {
2407
- return "1.8.29";
2407
+ return "1.8.31";
2408
2408
  }
2409
2409
 
2410
2410
  function getObjectTieFormat(obj) {
@@ -2623,7 +2623,7 @@ function genderValidityCheck({
2623
2623
  gender
2624
2624
  }) {
2625
2625
  const stack = "genderValidityCheck";
2626
- if (referenceGender && gender && [GenderEnum.Male, GenderEnum.Female].includes(referenceGender) && [GenderEnum.Male, GenderEnum.Female].includes(gender)) {
2626
+ if (referenceGender && gender && [GenderEnum.Male, GenderEnum.Female].includes(referenceGender)) {
2627
2627
  const valid = gender === referenceGender;
2628
2628
  return valid ? { valid: true } : decorateResult({
2629
2629
  result: { valid: false, error: INVALID_GENDER },
@@ -9240,13 +9240,12 @@ function updateAssignmentParticipantResults({
9240
9240
 
9241
9241
  function addParticipantGroupings({
9242
9242
  participantsProfile,
9243
- participants = []
9243
+ participants = [],
9244
+ deepCopy
9245
+ // will skip deepCopy only if false
9244
9246
  }) {
9245
- const participantsWithGroupings = makeDeepCopy(
9246
- participants,
9247
- participantsProfile?.convertExtensions,
9248
- true
9249
- );
9247
+ const groupMap = /* @__PURE__ */ new Map();
9248
+ const participantsWithGroupings = deepCopy !== false ? makeDeepCopy(participants, participantsProfile?.convertExtensions, true) : participants;
9250
9249
  const teamParticipants = participantsWithGroupings.filter(
9251
9250
  (participant) => participant.participantType === TEAM
9252
9251
  );
@@ -9269,6 +9268,11 @@ function addParticipantGroupings({
9269
9268
  (individualParticipantId) => {
9270
9269
  if (individualParticipantId === participantId && !participant.teamParticipantIds?.includes(team.participantId)) {
9271
9270
  participant.teamParticipantIds.push(team.participantId);
9271
+ if (!groupMap.get(team.participantId))
9272
+ groupMap.set(team.participantId, {
9273
+ participantName: team.participantName,
9274
+ participantId: team.participantId
9275
+ });
9272
9276
  participant.teams.push({
9273
9277
  participantRoleResponsibilities: team.participantRoleResponsibilities,
9274
9278
  participantOtherName: team.participantOtherName,
@@ -9306,7 +9310,7 @@ function addParticipantGroupings({
9306
9310
  });
9307
9311
  }
9308
9312
  });
9309
- return participantsWithGroupings;
9313
+ return { participantsWithGroupings, groupInfo: Object.fromEntries(groupMap) };
9310
9314
  }
9311
9315
 
9312
9316
  const extractor = (object) => (attr) => object[attr];
@@ -10002,13 +10006,14 @@ function getDrawMatchUps(params) {
10002
10006
  event
10003
10007
  });
10004
10008
  }
10009
+ let groupInfo;
10005
10010
  if (!tournamentParticipants?.length && tournamentRecord) {
10006
10011
  tournamentParticipants = tournamentRecord?.participants;
10007
10012
  if ((inContext || participantsProfile?.withGroupings) && tournamentParticipants?.length) {
10008
- tournamentParticipants = addParticipantGroupings({
10013
+ ({ participantsWithGroupings: tournamentParticipants, groupInfo } = addParticipantGroupings({
10009
10014
  participants: tournamentParticipants,
10010
10015
  participantsProfile
10011
- });
10016
+ }));
10012
10017
  }
10013
10018
  }
10014
10019
  const { structures } = getDrawStructures({ drawDefinition });
@@ -10069,14 +10074,15 @@ function getDrawMatchUps(params) {
10069
10074
  }
10070
10075
  return matchUps;
10071
10076
  };
10072
- const matchUpGroups = {
10077
+ const drawMatchUpsResult = {
10073
10078
  abandonedMatchUps: applyFilter(allAbandonedMatchUps),
10074
10079
  completedMatchUps: applyFilter(allCompletedMatchUps),
10075
10080
  upcomingMatchUps: applyFilter(allUpcomingMatchUps),
10076
10081
  pendingMatchUps: applyFilter(allPendingMatchUps),
10077
10082
  byeMatchUps: applyFilter(allByeMatchUps),
10078
10083
  matchUpsMap,
10079
- ...SUCCESS
10084
+ ...SUCCESS,
10085
+ groupInfo
10080
10086
  };
10081
10087
  if (nextMatchUps) {
10082
10088
  const nextFilter = typeof nextMatchUps === "object" || {
@@ -10099,7 +10105,7 @@ function getDrawMatchUps(params) {
10099
10105
  drawDefinition
10100
10106
  });
10101
10107
  }
10102
- return matchUpGroups;
10108
+ return drawMatchUpsResult;
10103
10109
  }
10104
10110
 
10105
10111
  const toBePlayed = {
@@ -16068,11 +16074,13 @@ function hydrateParticipants({
16068
16074
  participants.forEach(
16069
16075
  (participant) => addNationalityCode({ participant, ...participantsProfile })
16070
16076
  );
16077
+ let groupInfo;
16071
16078
  if ((inContext || participantsProfile?.withGroupings) && participants?.length) {
16072
- participants = addParticipantGroupings({
16079
+ ({ participantsWithGroupings: participants, groupInfo } = addParticipantGroupings({
16073
16080
  participantsProfile,
16081
+ deepCopy: false,
16074
16082
  participants
16075
- });
16083
+ }));
16076
16084
  }
16077
16085
  if (participantsProfile?.withScaleValues && participants?.length) {
16078
16086
  for (const participant of participants) {
@@ -16081,7 +16089,7 @@ function hydrateParticipants({
16081
16089
  participant.ratings = ratings;
16082
16090
  }
16083
16091
  }
16084
- return { participants };
16092
+ return { participants, groupInfo };
16085
16093
  }
16086
16094
 
16087
16095
  function allTournamentMatchUps(params) {
@@ -16189,8 +16197,13 @@ function allDrawMatchUps$1(params) {
16189
16197
  surfaceCategory: event?.surfaceCategory ?? tournamentRecord?.surfaceCategory,
16190
16198
  endDate: event?.endDate
16191
16199
  };
16200
+ let groupInfo;
16192
16201
  if (!tournamentParticipants?.length && !participantMap && tournamentRecord) {
16193
- ({ participants: tournamentParticipants = [], participantMap } = hydrateParticipants({
16202
+ ({
16203
+ participants: tournamentParticipants = [],
16204
+ participantMap,
16205
+ groupInfo
16206
+ } = hydrateParticipants({
16194
16207
  participantsProfile,
16195
16208
  useParticipantMap,
16196
16209
  policyDefinitions,
@@ -16208,7 +16221,7 @@ function allDrawMatchUps$1(params) {
16208
16221
  event
16209
16222
  });
16210
16223
  }
16211
- return getAllDrawMatchUps({
16224
+ const allDrawMatchUpsResult = getAllDrawMatchUps({
16212
16225
  context: additionalContext,
16213
16226
  tournamentAppliedPolicies,
16214
16227
  scheduleVisibilityFilters,
@@ -16227,6 +16240,7 @@ function allDrawMatchUps$1(params) {
16227
16240
  inContext,
16228
16241
  event
16229
16242
  });
16243
+ return { ...allDrawMatchUpsResult, groupInfo };
16230
16244
  }
16231
16245
  function allEventMatchUps(params) {
16232
16246
  let { participants = [], contextContent, participantMap } = params;
@@ -16273,6 +16287,7 @@ function allEventMatchUps(params) {
16273
16287
  event
16274
16288
  });
16275
16289
  }
16290
+ let groupInfo;
16276
16291
  if (!participants?.length && !participantMap && tournamentRecord) {
16277
16292
  const hydratedParticipantResult = hydrateParticipants({
16278
16293
  participantsProfile,
@@ -16284,6 +16299,7 @@ function allEventMatchUps(params) {
16284
16299
  });
16285
16300
  participantMap = hydratedParticipantResult.participantMap;
16286
16301
  participants = hydratedParticipantResult.participants ?? [];
16302
+ groupInfo = hydratedParticipantResult.groupInfo;
16287
16303
  }
16288
16304
  const drawDefinitions = event.drawDefinitions ?? [];
16289
16305
  const scheduleTiming = getScheduleTiming({
@@ -16315,7 +16331,7 @@ function allEventMatchUps(params) {
16315
16331
  return matchUps2 ?? [];
16316
16332
  }
16317
16333
  );
16318
- return { matchUps };
16334
+ return { matchUps, groupInfo };
16319
16335
  }
16320
16336
  function tournamentMatchUps(params) {
16321
16337
  if (!params?.tournamentRecord)
@@ -16337,7 +16353,7 @@ function tournamentMatchUps(params) {
16337
16353
  } = params;
16338
16354
  const tournamentId = params.tournamentId ?? tournamentRecord.tournamentId;
16339
16355
  const events = tournamentRecord?.events ?? [];
16340
- const { participants, participantMap } = hydrateParticipants({
16356
+ const { participants, participantMap, groupInfo } = hydrateParticipants({
16341
16357
  participantsProfile,
16342
16358
  policyDefinitions,
16343
16359
  useParticipantMap,
@@ -16381,21 +16397,24 @@ function tournamentMatchUps(params) {
16381
16397
  event
16382
16398
  });
16383
16399
  });
16384
- return eventsDrawsMatchUps.reduce(
16400
+ const eventsDrawMatchUpsResult = eventsDrawsMatchUps.reduce(
16385
16401
  (matchUps, eventMatchUps2) => {
16386
16402
  const keys = eventMatchUps2 && Object.keys(eventMatchUps2).filter(
16387
16403
  (key) => !["success", "matchUpsMap"].includes(key)
16388
16404
  );
16389
16405
  keys?.forEach((key) => {
16390
- if (!matchUps[key])
16391
- matchUps[key] = [];
16392
- matchUps[key] = matchUps[key].concat(eventMatchUps2[key]);
16393
- matchUps.matchUpsCount += eventMatchUps2[key].length;
16406
+ if (Array.isArray(eventMatchUps2[key])) {
16407
+ if (!matchUps[key])
16408
+ matchUps[key] = [];
16409
+ matchUps[key] = matchUps[key].concat(eventMatchUps2[key]);
16410
+ matchUps.matchUpsCount += eventMatchUps2[key].length;
16411
+ }
16394
16412
  });
16395
16413
  return matchUps;
16396
16414
  },
16397
16415
  { matchUpsCount: 0 }
16398
16416
  );
16417
+ return { ...eventsDrawMatchUpsResult, groupInfo };
16399
16418
  }
16400
16419
  function eventMatchUps(params) {
16401
16420
  let {
@@ -16434,8 +16453,13 @@ function eventMatchUps(params) {
16434
16453
  surfaceCategory: event.surfaceCategory ?? tournamentRecord?.surfaceCategory
16435
16454
  })
16436
16455
  };
16456
+ let groupInfo;
16437
16457
  if (!tournamentParticipants && tournamentRecord) {
16438
- ({ participants: tournamentParticipants, participantMap } = hydrateParticipants({
16458
+ ({
16459
+ participants: tournamentParticipants,
16460
+ participantMap,
16461
+ groupInfo
16462
+ } = hydrateParticipants({
16439
16463
  participantsProfile,
16440
16464
  policyDefinitions,
16441
16465
  useParticipantMap,
@@ -16452,8 +16476,8 @@ function eventMatchUps(params) {
16452
16476
  event
16453
16477
  });
16454
16478
  const drawDefinitions = event.drawDefinitions ?? [];
16455
- return drawDefinitions.reduce((matchUps, drawDefinition) => {
16456
- const drawMatchUps2 = getDrawMatchUps({
16479
+ const eventResult = drawDefinitions.reduce((results, drawDefinition) => {
16480
+ const drawMatchUpsResult = getDrawMatchUps({
16457
16481
  context: additionalContext,
16458
16482
  tournamentAppliedPolicies,
16459
16483
  scheduleVisibilityFilters,
@@ -16472,14 +16496,17 @@ function eventMatchUps(params) {
16472
16496
  inContext,
16473
16497
  event
16474
16498
  });
16475
- const keys = Object.keys(drawMatchUps2);
16499
+ const keys = Object.keys(drawMatchUpsResult);
16476
16500
  keys?.forEach((key) => {
16477
- if (!matchUps[key])
16478
- matchUps[key] = [];
16479
- matchUps[key] = matchUps[key].concat(drawMatchUps2[key]);
16501
+ if (Array.isArray(drawMatchUpsResult[key])) {
16502
+ if (!results[key])
16503
+ results[key] = [];
16504
+ results[key] = results[key].concat(drawMatchUpsResult[key]);
16505
+ }
16480
16506
  });
16481
- return matchUps;
16507
+ return results;
16482
16508
  }, {});
16509
+ return { ...eventResult, ...SUCCESS, groupInfo };
16483
16510
  }
16484
16511
  function drawMatchUps$1({
16485
16512
  participants: tournamentParticipants,
@@ -16514,8 +16541,13 @@ function drawMatchUps$1({
16514
16541
  surfaceCategory: event?.surfaceCategory ?? tournamentRecord?.surfaceCategory
16515
16542
  })
16516
16543
  };
16544
+ let groupInfo;
16517
16545
  if (!tournamentParticipants?.length && tournamentRecord) {
16518
- ({ participants: tournamentParticipants, participantMap } = hydrateParticipants({
16546
+ ({
16547
+ participants: tournamentParticipants,
16548
+ participantMap,
16549
+ groupInfo
16550
+ } = hydrateParticipants({
16519
16551
  participantsProfile,
16520
16552
  policyDefinitions,
16521
16553
  useParticipantMap,
@@ -16532,7 +16564,7 @@ function drawMatchUps$1({
16532
16564
  drawDefinition,
16533
16565
  event
16534
16566
  });
16535
- return getDrawMatchUps({
16567
+ const drawMatchUpsResult = getDrawMatchUps({
16536
16568
  context: additionalContext,
16537
16569
  tournamentAppliedPolicies,
16538
16570
  scheduleVisibilityFilters,
@@ -16551,6 +16583,7 @@ function drawMatchUps$1({
16551
16583
  inContext,
16552
16584
  event
16553
16585
  });
16586
+ return { ...drawMatchUpsResult, groupInfo };
16554
16587
  }
16555
16588
 
16556
16589
  function addFinishingRounds({
@@ -16758,15 +16791,25 @@ function competitionMatchUps({
16758
16791
  inContext
16759
16792
  });
16760
16793
  });
16761
- return tournamentsMatchUps.reduce((groupings, matchUpGroupings) => {
16762
- const keys = Object.keys(matchUpGroupings);
16763
- keys.forEach((key) => {
16764
- if (!groupings[key])
16765
- groupings[key] = [];
16766
- groupings[key] = groupings[key].concat(matchUpGroupings[key]);
16767
- });
16768
- return groupings;
16769
- }, {});
16794
+ const groupInfo = {};
16795
+ const competitionMatchUpsResult = tournamentsMatchUps.reduce(
16796
+ (groupings, matchUpGroupings) => {
16797
+ const keys = Object.keys(matchUpGroupings);
16798
+ keys.forEach((key) => {
16799
+ if (Array.isArray(matchUpGroupings[key])) {
16800
+ if (!groupings[key])
16801
+ groupings[key] = [];
16802
+ groupings[key] = groupings[key].concat(matchUpGroupings[key]);
16803
+ }
16804
+ if (key === "groupInfo") {
16805
+ Object.assign(groupInfo, matchUpGroupings[key]);
16806
+ }
16807
+ });
16808
+ return groupings;
16809
+ },
16810
+ {}
16811
+ );
16812
+ return { ...competitionMatchUpsResult, groupInfo };
16770
16813
  }
16771
16814
 
16772
16815
  function matchUpSort(a, b) {
@@ -30319,10 +30362,10 @@ function findMatchUp({
30319
30362
  return { error: MISSING_TOURNAMENT_RECORD };
30320
30363
  if (typeof matchUpId !== "string")
30321
30364
  return { error: MISSING_MATCHUP_ID };
30322
- if (!drawDefinition || !event || nextMatchUps) {
30365
+ if (!drawDefinition || !event) {
30323
30366
  const matchUps = allTournamentMatchUps({ tournamentRecord, nextMatchUps }).matchUps ?? [];
30324
30367
  const inContextMatchUp = matchUps.find(
30325
- (matchUp2) => matchUp2.matchUpId === matchUpId
30368
+ (matchUp) => matchUp.matchUpId === matchUpId
30326
30369
  );
30327
30370
  if (!inContextMatchUp)
30328
30371
  return { error: MATCHUP_NOT_FOUND };
@@ -30351,18 +30394,41 @@ function findMatchUp({
30351
30394
  contextProfile,
30352
30395
  inContext
30353
30396
  });
30354
- const { matchUp, structure } = findDrawMatchUp({
30355
- context: inContext ? additionalContext : void 0,
30356
- tournamentParticipants,
30357
- afterRecoveryTimes,
30358
- contextContent,
30359
- drawDefinition,
30360
- contextProfile,
30361
- matchUpId,
30362
- inContext,
30363
- event
30364
- });
30365
- return { matchUp, structure, drawDefinition };
30397
+ if (nextMatchUps) {
30398
+ const matchUps = allDrawMatchUps$1({
30399
+ context: inContext ? additionalContext : void 0,
30400
+ participants: tournamentParticipants,
30401
+ afterRecoveryTimes,
30402
+ contextContent,
30403
+ contextProfile,
30404
+ drawDefinition,
30405
+ nextMatchUps,
30406
+ inContext,
30407
+ event
30408
+ }).matchUps ?? [];
30409
+ const inContextMatchUp = matchUps.find(
30410
+ (matchUp) => matchUp.matchUpId === matchUpId
30411
+ );
30412
+ if (!inContextMatchUp)
30413
+ return { error: MATCHUP_NOT_FOUND };
30414
+ const structure = drawDefinition?.structures?.find(
30415
+ (structure2) => structure2.structureId === inContextMatchUp.structureId
30416
+ );
30417
+ return { drawDefinition, structure, matchUp: inContextMatchUp };
30418
+ } else {
30419
+ const { matchUp, structure } = findDrawMatchUp({
30420
+ context: inContext ? additionalContext : void 0,
30421
+ tournamentParticipants,
30422
+ afterRecoveryTimes,
30423
+ contextContent,
30424
+ drawDefinition,
30425
+ contextProfile,
30426
+ matchUpId,
30427
+ inContext,
30428
+ event
30429
+ });
30430
+ return { matchUp, structure, drawDefinition };
30431
+ }
30366
30432
  }
30367
30433
 
30368
30434
  function resetTieFormat$1({
@@ -31869,7 +31935,7 @@ function competitionScheduleMatchUps(params) {
31869
31935
  params.matchUpFilters.excludeMatchUpStatuses = [COMPLETED$1];
31870
31936
  }
31871
31937
  }
31872
- const { completedMatchUps, upcomingMatchUps, pendingMatchUps } = competitionMatchUps({
31938
+ const { completedMatchUps, upcomingMatchUps, pendingMatchUps, groupInfo } = competitionMatchUps({
31873
31939
  ...params,
31874
31940
  matchUpFilters: params.matchUpFilters,
31875
31941
  contextFilters: params.contextFilters
@@ -31893,6 +31959,7 @@ function competitionScheduleMatchUps(params) {
31893
31959
  // completed matchUps for the filter date
31894
31960
  dateMatchUps,
31895
31961
  // all incomplete matchUps for the filter date
31962
+ groupInfo,
31896
31963
  venues
31897
31964
  };
31898
31965
  if (withCourtGridRows) {
@@ -31903,7 +31970,7 @@ function competitionScheduleMatchUps(params) {
31903
31970
  result.courtPrefix = courtPrefix;
31904
31971
  result.rows = rows;
31905
31972
  }
31906
- return result;
31973
+ return { ...result, ...SUCCESS };
31907
31974
  function getCourtMatchUps({ courtId }) {
31908
31975
  const matchUpsToConsider = courtCompletedMatchUps ? dateMatchUps.concat(completedMatchUps ?? []) : dateMatchUps;
31909
31976
  const courtMatchUps = matchUpsToConsider.filter(
@@ -41691,8 +41758,9 @@ function randomUnseededSeparation({
41691
41758
  const { positionAssignments } = structureAssignedDrawPositions({ structure });
41692
41759
  const participantsWithGroupings = addParticipantGroupings({
41693
41760
  participantsProfile: { convertExtensions: true },
41761
+ deepCopy: false,
41694
41762
  participants
41695
- });
41763
+ }).participantsWithGroupings;
41696
41764
  const unassignedPositions = positionAssignments?.filter(
41697
41765
  (assignment) => !assignment.participantId
41698
41766
  );