tods-competition-factory 2.0.13 → 2.0.16

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.0.13';
6
+ return '2.0.16';
7
7
  }
8
8
 
9
9
  const SUCCESS = { success: true };
@@ -2197,8 +2197,9 @@ const RECOVERY_MINUTES = 'recoveryMinutes';
2197
2197
  const PERIOD_LENGTH = 'periodLength';
2198
2198
  const OBJECT = 'object';
2199
2199
  const ARRAY = 'array';
2200
- const VALIDATE = 'validate';
2201
- const INVALID = 'invalid';
2200
+ const VALIDATE = '_validate';
2201
+ const MESSAGE = '_message';
2202
+ const INVALID = '_invalid';
2202
2203
  const OF_TYPE = '_ofType';
2203
2204
  const ANY_OF = '_anyOf';
2204
2205
  const ONE_OF = '_oneOf';
@@ -2255,9 +2256,10 @@ function checkRequiredParameters(params, requiredParams, stack) {
2255
2256
  return { valid: true };
2256
2257
  const error = params?.[errorParam] === undefined
2257
2258
  ? errors[errorParam] || INVALID_VALUES
2258
- : (paramError.validate && paramError.invalid) || INVALID_VALUES;
2259
+ : (paramError[VALIDATE] && paramError[INVALID]) || INVALID_VALUES;
2260
+ const param = errorParam ?? (paramError[ONE_OF] && Object.keys(paramError[ONE_OF]).join(', '));
2259
2261
  return decorateResult({
2260
- info: { param: errorParam },
2262
+ info: { param, message: paramError[MESSAGE] },
2261
2263
  result: { error },
2262
2264
  stack,
2263
2265
  });
@@ -2284,8 +2286,8 @@ function getAnyOf(params, _anyOf) {
2284
2286
  return overlap.reduce((attr, param) => ({ ...attr, [param]: true }), {});
2285
2287
  }
2286
2288
  function findParamError(params, requiredParams) {
2287
- let errorParam;
2288
- const paramError = requiredParams.find(({ _ofType, _oneOf, _anyOf, validate, ...attrs }) => {
2289
+ let errorParam, paramInfo;
2290
+ const paramError = requiredParams.find(({ _ofType, _oneOf, _anyOf, _validate, _info, ...attrs }) => {
2289
2291
  const oneOf = _oneOf && getOneOf(params, _oneOf);
2290
2292
  if (oneOf?.error)
2291
2293
  return oneOf.error;
@@ -2296,18 +2298,20 @@ function findParamError(params, requiredParams) {
2296
2298
  anyOf && Object.assign(attrs, anyOf);
2297
2299
  const booleanParams = Object.keys(attrs).filter((key) => typeof attrs[key] === 'boolean');
2298
2300
  const invalidParam = booleanParams.find((param) => {
2299
- const invalidValidationFunction = validate && !isFunction(validate);
2300
- const faliedTypeCheck = params[param] && !validate && invalidType(params, param, _ofType);
2301
+ const invalidValidationFunction = _validate && !isFunction(_validate);
2302
+ const faliedTypeCheck = params[param] && !_validate && invalidType(params, param, _ofType);
2301
2303
  const paramNotPresent = attrs[param] && !params[param];
2302
2304
  const invalid = invalidValidationFunction || faliedTypeCheck || paramNotPresent;
2303
- const hasError = invalid || (validate && params[param] && !checkValidation(params[param], validate));
2304
- if (hasError)
2305
+ const hasError = invalid || (_validate && params[param] && !checkValidation(params[param], _validate));
2306
+ if (hasError) {
2305
2307
  errorParam = param;
2308
+ paramInfo = _info;
2309
+ }
2306
2310
  return hasError;
2307
2311
  });
2308
2312
  return !booleanParams.length || invalidParam;
2309
2313
  });
2310
- return { paramError, errorParam };
2314
+ return { paramError, errorParam, paramInfo };
2311
2315
  }
2312
2316
  function invalidType(params, param, _ofType) {
2313
2317
  _ofType = _ofType || paramTypes[param] || 'string';
@@ -3239,11 +3243,11 @@ function getMinFinishingPositionRange(structure) {
3239
3243
  }, undefined);
3240
3244
  }
3241
3245
 
3242
- function findStructure({ drawDefinition, structureId }) {
3243
- if (!drawDefinition)
3244
- return { error: MISSING_DRAW_DEFINITION };
3245
- if (!structureId)
3246
- return { error: MISSING_STRUCTURE_ID };
3246
+ function findStructure(params) {
3247
+ const paramsCheck = checkRequiredParameters(params, [{ [DRAW_DEFINITION]: true, [STRUCTURE_ID]: true }]);
3248
+ if (paramsCheck.error)
3249
+ return paramsCheck;
3250
+ const { drawDefinition, structureId } = params;
3247
3251
  const { structures } = getDrawStructures({ drawDefinition });
3248
3252
  const allStructures = structures
3249
3253
  ?.map((structure) => {
@@ -5127,6 +5131,20 @@ function getCheckedInParticipantIds({ matchUp }) {
5127
5131
  };
5128
5132
  }
5129
5133
 
5134
+ const matchUpEventTypeMap = {
5135
+ [SINGLES]: [SINGLES, 'S'],
5136
+ [DOUBLES]: [DOUBLES, 'D'],
5137
+ [TEAM$1]: [TEAM$1, 'T'],
5138
+ S: [SINGLES, 'S'],
5139
+ D: [DOUBLES, 'D'],
5140
+ T: [TEAM$1, 'T'],
5141
+ };
5142
+
5143
+ const isMatchUpEventType = (type) => (params) => {
5144
+ const matchUpEventType = (isObject(params) && params?.matchUpType) || (isString(params) && params);
5145
+ return matchUpEventType && matchUpEventTypeMap[type].includes(matchUpEventType);
5146
+ };
5147
+
5130
5148
  function findMatchupFormatAverageTimes(params) {
5131
5149
  const { matchUpAverageTimes, matchUpFormat } = params || {};
5132
5150
  const codeMatches = matchUpAverageTimes
@@ -5317,7 +5335,7 @@ function matchUpFormatTimes({ timingDetails, eventType }) {
5317
5335
  const recoveryKeys = Object.keys(recoveryTimes?.minutes || {});
5318
5336
  const recoveryMinutes = recoveryTimes?.minutes &&
5319
5337
  ((recoveryKeys?.includes(eventType) && recoveryTimes.minutes[eventType]) || recoveryTimes.minutes.default);
5320
- const formatChangeKey = eventType === SINGLES_EVENT ? SINGLES_DOUBLES : DOUBLES_SINGLES;
5338
+ const formatChangeKey = isMatchUpEventType(SINGLES_EVENT)(eventType) ? SINGLES_DOUBLES : DOUBLES_SINGLES;
5321
5339
  const typeChangeRecoveryMinutes = recoveryTimes?.minutes &&
5322
5340
  ((recoveryKeys?.includes(formatChangeKey) && recoveryTimes.minutes[formatChangeKey]) || recoveryMinutes);
5323
5341
  return { averageMinutes, recoveryMinutes, typeChangeRecoveryMinutes };
@@ -6601,10 +6619,9 @@ function isAdHoc({ structure }) {
6601
6619
  const matchUps = structure.matchUps || (structure.roundMatchUps && Object.values(structure.roundMatchUps).flat());
6602
6620
  const hasRoundPosition = !!matchUps?.find((matchUp) => matchUp?.roundPosition);
6603
6621
  const hasDrawPosition = !!matchUps?.find((matchUp) => matchUp?.drawPositions?.length);
6604
- const adHoc = !structure?.structures &&
6622
+ return (!structure?.structures &&
6605
6623
  structure?.stage !== VOLUNTARY_CONSOLATION &&
6606
- (!matchUps.length || (!hasRoundPosition && !hasDrawPosition));
6607
- return adHoc;
6624
+ (!matchUps.length || (!hasRoundPosition && !hasDrawPosition)));
6608
6625
  }
6609
6626
 
6610
6627
  const POLICY_ROUND_NAMING_DEFAULT = {
@@ -6722,6 +6739,12 @@ function getMatchUpType(params) {
6722
6739
  return { matchUpType };
6723
6740
  }
6724
6741
 
6742
+ function includesMatchUpEventType(types, matchUpEventType) {
6743
+ if (!Array.isArray(types) || !isString(matchUpEventType))
6744
+ return false;
6745
+ return intersection(types, matchUpEventTypeMap[matchUpEventType]).length;
6746
+ }
6747
+
6725
6748
  function filterMatchUps(params) {
6726
6749
  const { matchUps, isCollectionMatchUp, excludeMatchUpStatuses, matchUpStatuses, hasWinningSide, matchUpFormats, roundPositions, matchUpFormat, collectionIds, isMatchUpTie, roundNumbers, matchUpIds, roundNames, stageSequences, scheduledDates, scheduledDate, participantIds, processContext, tournamentIds, matchUpTypes, structureIds, readyToScore, courtIds, eventIds, venueIds, drawIds, stages, filterMatchUpIds = true, filterMatchUpTypes = true, } = params;
6727
6750
  const targetParticipantIds = Array.isArray(participantIds) ? participantIds.filter(Boolean) : [];
@@ -6750,7 +6773,7 @@ function filterMatchUps(params) {
6750
6773
  const targetDrawIds = Array.isArray(drawIds) ? drawIds.filter(Boolean) : [];
6751
6774
  const targetStructureIds = Array.isArray(structureIds) ? structureIds.filter(Boolean) : [];
6752
6775
  return matchUps.filter((matchUp) => {
6753
- if (readyToScore && matchUp.matchUpType !== TEAM_MATCHUP && !matchUp.readyToScore)
6776
+ if (readyToScore && !isMatchUpEventType(TEAM_MATCHUP)(matchUp) && !matchUp.readyToScore)
6754
6777
  return false;
6755
6778
  if (matchUp.winningSide && hasWinningSide && ![1, 2].includes(matchUp.winningSide))
6756
6779
  return false;
@@ -6801,7 +6824,8 @@ function filterMatchUps(params) {
6801
6824
  if (targetMatchUpIds.length && !targetMatchUpIds.includes(matchUp.matchUpId)) {
6802
6825
  return false;
6803
6826
  }
6804
- if (targetMatchUpTypes.length && (!matchUp.matchUpType || !targetMatchUpTypes.includes(matchUp.matchUpType))) {
6827
+ if (targetMatchUpTypes.length &&
6828
+ (!matchUp.matchUpType || !includesMatchUpEventType(targetMatchUpTypes, matchUp.matchUpType))) {
6805
6829
  return false;
6806
6830
  }
6807
6831
  if (targetMatchUpFormats.length &&
@@ -7319,7 +7343,7 @@ function getAllStructureMatchUps({ scheduleVisibilityFilters, tournamentAppliedP
7319
7343
  matchUpWithContext.matchUpType !== TEAM$2;
7320
7344
  if (inferGender) {
7321
7345
  const sideGenders = matchUpWithContext.sides.map((side) => {
7322
- if (matchUpWithContext.matchUpType === SINGLES)
7346
+ if (isMatchUpEventType(SINGLES)(matchUpWithContext.matchUpType))
7323
7347
  return side.participant?.person?.sex;
7324
7348
  if (side.participant?.individualParticipants?.length === 2) {
7325
7349
  const pairGenders = unique(side.participant.individualParticipants.map((participant) => participant.person?.sex)).filter(Boolean);
@@ -11389,6 +11413,11 @@ function getTournamentPublishStatus({ tournamentRecord, status = PUBLIC }) {
11389
11413
  })?.timeItem?.itemValue?.[status];
11390
11414
  }
11391
11415
 
11416
+ function isValidTournamentRecord(tournamentRecord) {
11417
+ const { tournamentId } = tournamentRecord ?? {};
11418
+ return !!tournamentId;
11419
+ }
11420
+
11392
11421
  function getEventPublishStatus({ event, status = PUBLIC }) {
11393
11422
  const itemType = `${PUBLISH}.${STATUS$1}`;
11394
11423
  return getEventTimeItem({
@@ -11402,29 +11431,28 @@ function getDrawPublishStatus({ drawDetails, drawId }) {
11402
11431
  return details?.published;
11403
11432
  }
11404
11433
 
11405
- function getPublishState({ tournamentRecord, drawDefinition, eventIds, eventId, drawIds, drawId, event, }) {
11406
- if (eventId && !event) {
11434
+ function getPublishState(params) {
11435
+ const { tournamentRecord, drawDefinition, eventIds, eventId, drawIds, drawId, event } = params ?? {};
11436
+ if (tournamentRecord && !isValidTournamentRecord(tournamentRecord))
11437
+ return { error: INVALID_VALUES };
11438
+ if (eventId && !event)
11407
11439
  return { error: EVENT_NOT_FOUND };
11408
- }
11409
- else if (Array.isArray(eventIds) && eventIds?.length) {
11440
+ if (Array.isArray(eventIds) && eventIds?.length) {
11410
11441
  const publishState = {};
11411
11442
  for (const eventId of eventIds) {
11412
11443
  if (!isString(eventId))
11413
11444
  return { error: INVALID_VALUES };
11414
- const event = findEvent({ tournamentRecord, eventId });
11445
+ const event = findEvent({ tournamentRecord, eventId })?.event;
11415
11446
  if (!event)
11416
11447
  return { error: EVENT_NOT_FOUND };
11417
11448
  const pubStatus = getPubStatus({ event });
11418
- if (pubStatus.error)
11419
- return pubStatus;
11420
11449
  publishState[eventId] = pubStatus;
11421
11450
  }
11422
11451
  return { ...SUCCESS, publishState };
11423
11452
  }
11424
- else if (event) {
11453
+ if (event) {
11425
11454
  const pubStatus = getPubStatus({ event });
11426
- if (pubStatus.error)
11427
- return pubStatus;
11455
+ let publishState = {};
11428
11456
  if (drawId) {
11429
11457
  if (!drawDefinition)
11430
11458
  return { error: DRAW_DEFINITION_NOT_FOUND };
@@ -11439,47 +11467,38 @@ function getPublishState({ tournamentRecord, drawDefinition, eventIds, eventId,
11439
11467
  };
11440
11468
  }
11441
11469
  else if (Array.isArray(drawIds) && drawIds?.length) {
11442
- const publishState = {};
11470
+ const eventDrawIds = event.drawDefinitions?.map(getDrawId) || [];
11443
11471
  for (const drawId of drawIds) {
11444
11472
  if (!isString(drawId))
11445
11473
  return { error: INVALID_VALUES };
11474
+ if (!eventDrawIds.includes(drawId))
11475
+ return { error: DRAW_DEFINITION_NOT_FOUND };
11446
11476
  publishState[drawId] = {
11447
11477
  status: {
11448
11478
  published: !!pubStatus.status.publishedDrawIds.includes(drawId),
11449
11479
  drawDetail: pubStatus.status.drawDetails?.[drawId],
11450
11480
  },
11451
11481
  };
11452
- return { ...SUCCESS, publishState };
11453
11482
  }
11454
11483
  }
11455
11484
  else {
11456
- return { publishState: pubStatus };
11485
+ publishState = pubStatus;
11457
11486
  }
11487
+ return { ...SUCCESS, publishState };
11458
11488
  }
11459
- else if (!tournamentRecord) {
11460
- return { error: MISSING_TOURNAMENT_RECORD };
11461
- }
11462
- else {
11463
- const publishState = {};
11464
- const pubStatus = getTournamentPublishStatus({ tournamentRecord });
11465
- publishState.tournament = pubStatus;
11466
- for (const event of tournamentRecord.events ?? []) {
11467
- const pubStatus = getPubStatus({ event });
11468
- publishState[event.eventId] = pubStatus;
11469
- if (pubStatus.error)
11470
- return pubStatus;
11471
- for (const { drawId } of event.drawDefinitions ?? []) {
11472
- if (!isString(drawId))
11473
- return { error: INVALID_VALUES };
11474
- const published = pubStatus.publishState?.publishedDrawIds?.includes(drawId);
11475
- if (published) {
11476
- publishState[drawId] = { status: { published } };
11477
- }
11478
- }
11489
+ const publishState = {};
11490
+ const pubStatus = getTournamentPublishStatus({ tournamentRecord });
11491
+ publishState.tournament = pubStatus;
11492
+ for (const event of tournamentRecord?.events ?? []) {
11493
+ const pubStatus = getPubStatus({ event });
11494
+ publishState[event.eventId] = pubStatus;
11495
+ for (const { drawId } of event.drawDefinitions ?? []) {
11496
+ const published = pubStatus.status?.publishedDrawIds?.includes(drawId);
11497
+ if (published)
11498
+ publishState[drawId] = { status: { published } };
11479
11499
  }
11480
- return { ...SUCCESS, publishState };
11481
11500
  }
11482
- return { error: INVALID_VALUES };
11501
+ return { ...SUCCESS, publishState };
11483
11502
  }
11484
11503
  function getPubStatus({ event }) {
11485
11504
  const eventPubStatus = getEventPublishStatus({ event });
@@ -11501,12 +11520,13 @@ function getPubStatus({ event }) {
11501
11520
  };
11502
11521
  }
11503
11522
  }
11504
- const publishedDrawIds = (drawDetails && Object.keys(drawDetails).filter((drawId) => getDrawPublishStatus({ drawDetails, drawId }))) ||
11505
- eventPubStatus.drawIds ||
11506
- [];
11523
+ const publishedDrawIds = (drawDetails &&
11524
+ Object.keys(drawDetails).length &&
11525
+ Object.keys(drawDetails).filter((drawId) => getDrawPublishStatus({ drawDetails, drawId }))) ||
11526
+ eventPubStatus.drawIds;
11507
11527
  return {
11508
11528
  status: {
11509
- published: publishedDrawIds.length > 0,
11529
+ published: publishedDrawIds && publishedDrawIds.length > 0,
11510
11530
  publishedDrawIds,
11511
11531
  publishedSeeding,
11512
11532
  drawDetails,
@@ -12276,7 +12296,7 @@ function filterParticipants({ participantFilters = {}, tournamentRecord, partici
12276
12296
  .filter((event) => eventIds.includes(event.eventId))
12277
12297
  .map((event) => {
12278
12298
  const enteredParticipantIds = (event.entries || []).map((entry) => entry.participantId);
12279
- if (event.eventType === SINGLES$1)
12299
+ if (isMatchUpEventType(SINGLES$1)(event.eventType))
12280
12300
  return enteredParticipantIds;
12281
12301
  const individualParticipantIds = (tournamentRecord?.participants ?? [])
12282
12302
  .filter((participant) => enteredParticipantIds.includes(participant.participantId))
@@ -12880,7 +12900,9 @@ function addEventEntries(params) {
12880
12900
  ?.filter((participant) => {
12881
12901
  if (!participantIds.includes(participant.participantId))
12882
12902
  return false;
12883
- const validSingles = event.eventType === SINGLES && participant.participantType === INDIVIDUAL && !isUngrouped(entryStatus);
12903
+ const validSingles = isMatchUpEventType(SINGLES)(event.eventType) &&
12904
+ participant.participantType === INDIVIDUAL &&
12905
+ !isUngrouped(entryStatus);
12884
12906
  const validDoubles = event.eventType === DOUBLES && participant.participantType === PAIR;
12885
12907
  if (validSingles &&
12886
12908
  (!event.gender ||
@@ -19621,11 +19643,11 @@ function getParticipantResults({ participantIds, matchUpFormat, tallyPolicy, per
19621
19643
  checkInitializeParticipant(participantResults, tieLosingParticipantId);
19622
19644
  participantResults[tieWinningParticipantId].tieMatchUpsWon += 1;
19623
19645
  participantResults[tieLosingParticipantId].tieMatchUpsLost += 1;
19624
- if (tieMatchUp.matchUpType === SINGLES) {
19646
+ if (isMatchUpEventType(SINGLES)(tieMatchUp.matchUpType)) {
19625
19647
  participantResults[tieWinningParticipantId].tieSinglesWon += 1;
19626
19648
  participantResults[tieLosingParticipantId].tieSinglesLost += 1;
19627
19649
  }
19628
- else if (tieMatchUp.matchUpType === DOUBLES) {
19650
+ else if (isMatchUpEventType(DOUBLES)(tieMatchUp.matchUpType)) {
19629
19651
  participantResults[tieWinningParticipantId].tieDoublesWon += 1;
19630
19652
  participantResults[tieLosingParticipantId].tieDoublesLost += 1;
19631
19653
  }
@@ -19655,8 +19677,8 @@ function getParticipantResults({ participantIds, matchUpFormat, tallyPolicy, per
19655
19677
  perPlayer = 0;
19656
19678
  for (const tieMatchUp of tieMatchUps) {
19657
19679
  const { matchUpType } = tieMatchUp;
19658
- const isDoubles = matchUpType === DOUBLES;
19659
- const isSingles = matchUpType === SINGLES;
19680
+ const isDoubles = isMatchUpEventType(DOUBLES)(matchUpType);
19681
+ const isSingles = isMatchUpEventType(SINGLES)(matchUpType);
19660
19682
  if (tieMatchUp.winningSide) {
19661
19683
  if (tieMatchUp.winningSide === winningSide) {
19662
19684
  if (winningParticipantId) {
@@ -20792,6 +20814,102 @@ function tieFormatGenderValidityCheck(params) {
20792
20814
  return { valid: true };
20793
20815
  }
20794
20816
 
20817
+ function stringify(matchUpFormatObject, preserveRedundant) {
20818
+ if ((matchUpFormatObject?.bestOf || matchUpFormatObject?.exactly) && matchUpFormatObject?.setFormat) {
20819
+ return getSetFormat(matchUpFormatObject, preserveRedundant);
20820
+ }
20821
+ return undefined;
20822
+ }
20823
+ function getNumber(formatstring) {
20824
+ return !isNaN(Number(formatstring)) && Number(formatstring);
20825
+ }
20826
+ function timedSetFormat(matchUpFormatObject) {
20827
+ let value = `T${matchUpFormatObject.minutes}`;
20828
+ if (matchUpFormatObject.based)
20829
+ value += matchUpFormatObject.based;
20830
+ if (matchUpFormatObject.modifier)
20831
+ value += `@${matchUpFormatObject.modifier}`;
20832
+ return value;
20833
+ }
20834
+ function getSetFormat(matchUpFormatObject, preserveRedundant) {
20835
+ const bestOfValue = getNumber(matchUpFormatObject.bestOf) || undefined;
20836
+ const exactly = getNumber(matchUpFormatObject.exactly) || undefined;
20837
+ const setLimit = bestOfValue || exactly;
20838
+ if (matchUpFormatObject.setFormat?.timed && matchUpFormatObject.simplified && setLimit === 1) {
20839
+ return timedSetFormat(matchUpFormatObject.setFormat);
20840
+ }
20841
+ const setLimitCode = (setLimit && `${SET}${setLimit}`) || '';
20842
+ const setCountValue = stringifySet(matchUpFormatObject.setFormat, preserveRedundant);
20843
+ const setCode = (setCountValue && `S:${setCountValue}`) || '';
20844
+ const finalSetCountValue = stringifySet(matchUpFormatObject.finalSetFormat, preserveRedundant);
20845
+ const finalSetCode = (setLimit &&
20846
+ setLimit > 1 &&
20847
+ finalSetCountValue &&
20848
+ setCountValue !== finalSetCountValue &&
20849
+ `F:${finalSetCountValue}`) ||
20850
+ '';
20851
+ const valid = setLimitCode && setCountValue;
20852
+ if (valid) {
20853
+ return [setLimitCode, setCode, finalSetCode].filter((f) => f).join('-');
20854
+ }
20855
+ return undefined;
20856
+ }
20857
+ function stringifySet(setObject, preserveRedundant) {
20858
+ if (typeof setObject === 'object' && Object.keys(setObject).length) {
20859
+ if (setObject.timed)
20860
+ return timedSetFormat(setObject);
20861
+ if (setObject.tiebreakSet)
20862
+ return tiebreakFormat(setObject.tiebreakSet);
20863
+ const setToValue = getNumber(setObject.setTo);
20864
+ if (setToValue) {
20865
+ const NoAD = (setObject.NoAD && NOAD) || '';
20866
+ const setTiebreakValue = tiebreakFormat(setObject.tiebreakFormat);
20867
+ const setTiebreakCode = (setTiebreakValue && `/${setTiebreakValue}`) || '';
20868
+ const tiebreakAtValue = getNumber(setObject.tiebreakAt);
20869
+ const tiebreakAtCode = (tiebreakAtValue && (tiebreakAtValue !== setToValue || preserveRedundant) && `@${tiebreakAtValue}`) || '';
20870
+ if (setTiebreakValue !== false) {
20871
+ return `${setToValue}${NoAD}${setTiebreakCode}${tiebreakAtCode}`;
20872
+ }
20873
+ }
20874
+ }
20875
+ return undefined;
20876
+ }
20877
+ function tiebreakFormat(tieobject) {
20878
+ if (tieobject) {
20879
+ if (typeof tieobject === 'object' && !tieobject.tiebreakTo) {
20880
+ return '';
20881
+ }
20882
+ else if (typeof tieobject === 'object' && getNumber(tieobject.tiebreakTo)) {
20883
+ let value = `TB${tieobject.tiebreakTo}${tieobject.NoAD ? NOAD : ''}`;
20884
+ if (tieobject.modifier)
20885
+ value += `@${tieobject.modifier}`;
20886
+ return value;
20887
+ }
20888
+ else {
20889
+ return false;
20890
+ }
20891
+ }
20892
+ return undefined;
20893
+ }
20894
+
20895
+ function isValidMatchUpFormat({ matchUpFormat }) {
20896
+ if (typeof matchUpFormat !== 'string')
20897
+ return false;
20898
+ const parsedFormat = parse(matchUpFormat);
20899
+ const setParts = matchUpFormat.match(/-S:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/);
20900
+ const setsTo = setParts?.[1];
20901
+ const tiebreakTo = setParts?.[2];
20902
+ const tiebreakAt = setParts?.[3];
20903
+ const finalSetParts = matchUpFormat.match(/-F:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/);
20904
+ const finalSetTo = finalSetParts?.[1];
20905
+ const finalSetTiebreakTo = finalSetParts?.[2];
20906
+ const finalTiebreakAt = finalSetParts?.[3];
20907
+ const preserveRedundant = !!((setParts && tiebreakTo && setsTo === tiebreakAt) ||
20908
+ (finalSetParts && finalSetTiebreakTo && finalSetTo === finalTiebreakAt));
20909
+ const stringified = stringify(parsedFormat, preserveRedundant);
20910
+ return stringified === matchUpFormat;
20911
+ }
20912
+
20795
20913
  const typeMatch = (arr, type) => arr.filter(Boolean).every((i) => typeof i === type);
20796
20914
  const allNumeric = (arr) => arr.filter(Boolean).every(isNumeric);
20797
20915
  function getCategoryAgeDetails(params) {
@@ -21038,102 +21156,6 @@ function categoryCanContain({ childCategory, withDetails, category }) {
21038
21156
  return result;
21039
21157
  }
21040
21158
 
21041
- function stringify(matchUpFormatObject, preserveRedundant) {
21042
- if ((matchUpFormatObject?.bestOf || matchUpFormatObject?.exactly) && matchUpFormatObject?.setFormat) {
21043
- return getSetFormat(matchUpFormatObject, preserveRedundant);
21044
- }
21045
- return undefined;
21046
- }
21047
- function getNumber(formatstring) {
21048
- return !isNaN(Number(formatstring)) && Number(formatstring);
21049
- }
21050
- function timedSetFormat(matchUpFormatObject) {
21051
- let value = `T${matchUpFormatObject.minutes}`;
21052
- if (matchUpFormatObject.based)
21053
- value += matchUpFormatObject.based;
21054
- if (matchUpFormatObject.modifier)
21055
- value += `@${matchUpFormatObject.modifier}`;
21056
- return value;
21057
- }
21058
- function getSetFormat(matchUpFormatObject, preserveRedundant) {
21059
- const bestOfValue = getNumber(matchUpFormatObject.bestOf) || undefined;
21060
- const exactly = getNumber(matchUpFormatObject.exactly) || undefined;
21061
- const setLimit = bestOfValue || exactly;
21062
- if (matchUpFormatObject.setFormat?.timed && matchUpFormatObject.simplified && setLimit === 1) {
21063
- return timedSetFormat(matchUpFormatObject.setFormat);
21064
- }
21065
- const setLimitCode = (setLimit && `${SET}${setLimit}`) || '';
21066
- const setCountValue = stringifySet(matchUpFormatObject.setFormat, preserveRedundant);
21067
- const setCode = (setCountValue && `S:${setCountValue}`) || '';
21068
- const finalSetCountValue = stringifySet(matchUpFormatObject.finalSetFormat, preserveRedundant);
21069
- const finalSetCode = (setLimit &&
21070
- setLimit > 1 &&
21071
- finalSetCountValue &&
21072
- setCountValue !== finalSetCountValue &&
21073
- `F:${finalSetCountValue}`) ||
21074
- '';
21075
- const valid = setLimitCode && setCountValue;
21076
- if (valid) {
21077
- return [setLimitCode, setCode, finalSetCode].filter((f) => f).join('-');
21078
- }
21079
- return undefined;
21080
- }
21081
- function stringifySet(setObject, preserveRedundant) {
21082
- if (typeof setObject === 'object' && Object.keys(setObject).length) {
21083
- if (setObject.timed)
21084
- return timedSetFormat(setObject);
21085
- if (setObject.tiebreakSet)
21086
- return tiebreakFormat(setObject.tiebreakSet);
21087
- const setToValue = getNumber(setObject.setTo);
21088
- if (setToValue) {
21089
- const NoAD = (setObject.NoAD && NOAD) || '';
21090
- const setTiebreakValue = tiebreakFormat(setObject.tiebreakFormat);
21091
- const setTiebreakCode = (setTiebreakValue && `/${setTiebreakValue}`) || '';
21092
- const tiebreakAtValue = getNumber(setObject.tiebreakAt);
21093
- const tiebreakAtCode = (tiebreakAtValue && (tiebreakAtValue !== setToValue || preserveRedundant) && `@${tiebreakAtValue}`) || '';
21094
- if (setTiebreakValue !== false) {
21095
- return `${setToValue}${NoAD}${setTiebreakCode}${tiebreakAtCode}`;
21096
- }
21097
- }
21098
- }
21099
- return undefined;
21100
- }
21101
- function tiebreakFormat(tieobject) {
21102
- if (tieobject) {
21103
- if (typeof tieobject === 'object' && !tieobject.tiebreakTo) {
21104
- return '';
21105
- }
21106
- else if (typeof tieobject === 'object' && getNumber(tieobject.tiebreakTo)) {
21107
- let value = `TB${tieobject.tiebreakTo}${tieobject.NoAD ? NOAD : ''}`;
21108
- if (tieobject.modifier)
21109
- value += `@${tieobject.modifier}`;
21110
- return value;
21111
- }
21112
- else {
21113
- return false;
21114
- }
21115
- }
21116
- return undefined;
21117
- }
21118
-
21119
- function isValidMatchUpFormat({ matchUpFormat }) {
21120
- if (typeof matchUpFormat !== 'string')
21121
- return false;
21122
- const parsedFormat = parse(matchUpFormat);
21123
- const setParts = matchUpFormat.match(/-S:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/);
21124
- const setsTo = setParts?.[1];
21125
- const tiebreakTo = setParts?.[2];
21126
- const tiebreakAt = setParts?.[3];
21127
- const finalSetParts = matchUpFormat.match(/-F:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/);
21128
- const finalSetTo = finalSetParts?.[1];
21129
- const finalSetTiebreakTo = finalSetParts?.[2];
21130
- const finalTiebreakAt = finalSetParts?.[3];
21131
- const preserveRedundant = !!((setParts && tiebreakTo && setsTo === tiebreakAt) ||
21132
- (finalSetParts && finalSetTiebreakTo && finalSetTo === finalTiebreakAt));
21133
- const stringified = stringify(parsedFormat, preserveRedundant);
21134
- return stringified === matchUpFormat;
21135
- }
21136
-
21137
21159
  function validateCollectionDefinition({ checkCategory = true, collectionDefinition, checkCollectionIds, checkGender = true, referenceCategory, referenceGender, event, }) {
21138
21160
  referenceGender = referenceGender ?? event?.gender;
21139
21161
  const stack = 'validateCollectionDefinition';
@@ -21149,7 +21171,7 @@ function validateCollectionDefinition({ checkCategory = true, collectionDefiniti
21149
21171
  if (typeof matchUpCount !== 'number') {
21150
21172
  errors.push(`matchUpCount is not type number: ${matchUpCount}`);
21151
21173
  }
21152
- if (matchUpType && ![SINGLES, DOUBLES].includes(matchUpType)) {
21174
+ if (matchUpType && !includesMatchUpEventType([SINGLES, DOUBLES], matchUpType)) {
21153
21175
  errors.push(`matchUpType must be SINGLES or DOUBLES: ${matchUpType}`);
21154
21176
  }
21155
21177
  const valueDeclarations = [!!collectionValueProfiles?.length]
@@ -22782,14 +22804,12 @@ function assignDrawPosition({ tournamentRecord, drawDefinition, participantId, d
22782
22804
  return { ...SUCCESS };
22783
22805
  }
22784
22806
 
22785
- function deleteAdHocMatchUps(params) {
22786
- const { tournamentRecord, matchUpIds = [], drawDefinition, event } = params;
22787
- if (typeof drawDefinition !== 'object')
22788
- return { error: MISSING_DRAW_DEFINITION };
22789
- if (!Array.isArray(matchUpIds))
22790
- return { error: INVALID_VALUES };
22807
+ function getAdHocStructureDetails(params) {
22808
+ let matchUpIds = params.matchUpIds ?? [];
22809
+ const { drawDefinition } = params;
22791
22810
  const structureId = params.structureId ??
22792
- drawDefinition?.structures?.find((structure) => structure.matchUps?.some(({ matchUpId }) => matchUpIds.includes(matchUpId)))?.structureId;
22811
+ drawDefinition?.structures?.find((structure) => structure.matchUps?.some(({ matchUpId }) => matchUpIds.includes(matchUpId)))?.structureId ??
22812
+ drawDefinition?.structures?.[0]?.structureId;
22793
22813
  if (!structureId)
22794
22814
  return { error: STRUCTURE_NOT_FOUND };
22795
22815
  const structure = drawDefinition.structures?.find((structure) => structure.structureId === structureId);
@@ -22800,11 +22820,43 @@ function deleteAdHocMatchUps(params) {
22800
22820
  if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
22801
22821
  return { error: INVALID_STRUCTURE };
22802
22822
  }
22823
+ const existingRoundMatchUpIds = existingMatchUps
22824
+ .filter(({ roundNumber }) => params.roundNumbers?.includes(roundNumber))
22825
+ .map(getMatchUpId);
22826
+ matchUpIds = matchUpIds.filter((matchUpId) => !existingRoundMatchUpIds.includes(matchUpId));
22827
+ if (params.roundNumbers && !matchUpIds.length)
22828
+ matchUpIds = existingRoundMatchUpIds;
22829
+ return { existingMatchUps, matchUpIds, structureId, structure };
22830
+ }
22831
+
22832
+ function deleteAdHocMatchUps(params) {
22833
+ const paramsCheck = checkRequiredParameters(params, [
22834
+ { [DRAW_DEFINITION]: true },
22835
+ {
22836
+ [ONE_OF]: { [MATCHUP_IDS]: false, roundNumbers: false },
22837
+ [INVALID]: INVALID_VALUES,
22838
+ [OF_TYPE]: ARRAY,
22839
+ },
22840
+ ]);
22841
+ if (paramsCheck.error)
22842
+ return paramsCheck;
22843
+ const { removeIncomplete = false, removeUnAssigned = true, removeCompleted = false, tournamentRecord, drawDefinition, event, } = params;
22844
+ const structureResult = getAdHocStructureDetails(params);
22845
+ if (structureResult.error)
22846
+ return structureResult;
22847
+ const { structure, structureId, existingMatchUps, matchUpIds } = structureResult;
22803
22848
  const matchUpIdsWithScoreValue = [];
22804
- const matchUpsToDelete = existingMatchUps?.filter(({ matchUpId, score }) => {
22805
- if (checkScoreHasValue({ score }))
22849
+ const matchUpsToDelete = existingMatchUps?.filter(({ matchUpId, score, winningSide }) => {
22850
+ if (checkScoreHasValue({ score })) {
22851
+ if (!winningSide && !removeIncomplete)
22852
+ return false;
22853
+ if (winningSide && !removeCompleted)
22854
+ return false;
22806
22855
  matchUpIdsWithScoreValue.push(matchUpId);
22807
- return matchUpIds.includes(matchUpId);
22856
+ }
22857
+ else if (!removeUnAssigned)
22858
+ return false;
22859
+ return matchUpIds?.includes(matchUpId);
22808
22860
  }) ?? [];
22809
22861
  const matchUpIdsToDelete = matchUpsToDelete.map(getMatchUpId);
22810
22862
  const tieMatchUpIdsToDelete = matchUpsToDelete
@@ -23429,6 +23481,39 @@ function getEligibleVoluntaryConsolationParticipants({ excludedMatchUpStatuses =
23429
23481
  return { eligibleParticipants, losingParticipantIds, ...SUCCESS };
23430
23482
  }
23431
23483
 
23484
+ function getAvailableMatchUpsCount(params) {
23485
+ const paramsCheck = checkRequiredParameters(params, [{ drawDefinition: true }]);
23486
+ if (paramsCheck.error)
23487
+ return paramsCheck;
23488
+ const { drawDefinition, roundNumber } = params;
23489
+ const structureId = params.structureId ?? (drawDefinition.structures?.length === 1 && drawDefinition.structures?.[0]?.structureId);
23490
+ if (typeof structureId !== 'string')
23491
+ return { error: MISSING_STRUCTURE_ID };
23492
+ const structure = drawDefinition.structures?.find((structure) => structure.structureId === structureId);
23493
+ if (!structure)
23494
+ return { error: STRUCTURE_NOT_FOUND };
23495
+ let structureHasRoundPositions;
23496
+ const existingMatchUps = structure.matchUps ?? [];
23497
+ const lastRoundNumber = existingMatchUps?.reduce((roundNumber, matchUp) => {
23498
+ if (matchUp.roundPosition)
23499
+ structureHasRoundPositions = true;
23500
+ return (matchUp?.roundNumber || 0) > roundNumber ? matchUp.roundNumber : roundNumber;
23501
+ }, 0);
23502
+ if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
23503
+ return { error: INVALID_STRUCTURE };
23504
+ }
23505
+ const selectedEntries = drawDefinition?.entries?.filter((entry) => {
23506
+ const entryStatus = entry.entryStatus;
23507
+ return STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
23508
+ }) ?? [];
23509
+ const roundMatchUpsCount = Math.floor(selectedEntries?.length / 2) || 1;
23510
+ const targetRoundNumber = roundNumber ?? lastRoundNumber ?? 1;
23511
+ const existingRoundMatchUps = structure.matchUps?.filter((matchUp) => matchUp.roundNumber === targetRoundNumber)?.length ?? 0;
23512
+ const maxRemaining = roundMatchUpsCount - existingRoundMatchUps;
23513
+ const availableMatchUpsCount = maxRemaining > 0 ? maxRemaining : 0;
23514
+ return { ...SUCCESS, availableMatchUpsCount, lastRoundNumber, roundMatchUpsCount };
23515
+ }
23516
+
23432
23517
  function getDrawParticipantRepresentativeIds({ drawDefinition }) {
23433
23518
  const result = findExtension({
23434
23519
  name: 'participantRepresentatives',
@@ -24191,11 +24276,11 @@ function collectionMatchUpActions({ specifiedPolicyDefinitions, inContextDrawMat
24191
24276
  sideNumber: i + 1,
24192
24277
  }));
24193
24278
  const assignmentAvailable = (sideNumber &&
24194
- ((matchUpType === SINGLES_MATCHUP && !existingParticipantIds?.length) ||
24195
- (matchUpType === DOUBLES_MATCHUP && (existingParticipantIds?.length ?? 0) < 2))) ||
24279
+ ((isMatchUpEventType(SINGLES_MATCHUP)(matchUpType) && !existingParticipantIds?.length) ||
24280
+ (isMatchUpEventType(DOUBLES_MATCHUP)(matchUpType) && (existingParticipantIds?.length ?? 0) < 2))) ||
24196
24281
  (!sideNumber &&
24197
- ((matchUpType === SINGLES_MATCHUP && (existingParticipantIds?.length ?? 0) < 2) ||
24198
- (matchUpType === DOUBLES_MATCHUP && (existingParticipantIds?.length ?? 0) < 4)));
24282
+ ((isMatchUpEventType(SINGLES_MATCHUP)(matchUpType) && (existingParticipantIds?.length ?? 0) < 2) ||
24283
+ (isMatchUpEventType(DOUBLES_MATCHUP)(matchUpType) && (existingParticipantIds?.length ?? 0) < 4)));
24199
24284
  const availableIds = availableParticipantIds?.filter((id) => !allParticipantIds?.includes(id));
24200
24285
  const available = availableParticipants?.filter(({ participantId }) => availableIds.includes(participantId));
24201
24286
  if (assignmentAvailable && availableIds?.length) {
@@ -25114,6 +25199,7 @@ var query$a = {
25114
25199
  checkValidEntries: checkValidEntries,
25115
25200
  findDrawDefinition: publicFindDrawDefinition,
25116
25201
  getAssignedParticipantIds: getAssignedParticipantIds,
25202
+ getAvailableMatchUpsCount: getAvailableMatchUpsCount,
25117
25203
  getAvailablePlayoffProfiles: getAvailablePlayoffProfiles,
25118
25204
  getDrawDefinitionTimeItem: getDrawDefinitionTimeItem,
25119
25205
  getDrawParticipantRepresentativeIds: getDrawParticipantRepresentativeIds,
@@ -25996,35 +26082,16 @@ function generateAdHocMatchUps(params) {
25996
26082
  if (typeof drawDefinition !== 'object')
25997
26083
  return { error: MISSING_DRAW_DEFINITION };
25998
26084
  let { participantIdPairings, matchUpsCount } = params;
25999
- const structureId = params.structureId ?? (drawDefinition.structures?.length === 1 && drawDefinition.structures?.[0]?.structureId);
26000
- if (typeof structureId !== 'string')
26001
- return { error: MISSING_STRUCTURE_ID };
26002
- const structure = drawDefinition.structures?.find((structure) => structure.structureId === structureId);
26003
- if (!structure)
26004
- return { error: STRUCTURE_NOT_FOUND };
26005
- let structureHasRoundPositions;
26006
- const existingMatchUps = structure.matchUps ?? [];
26007
- const lastRoundNumber = existingMatchUps?.reduce((roundNumber, matchUp) => {
26008
- if (matchUp.roundPosition)
26009
- structureHasRoundPositions = true;
26010
- return (matchUp?.roundNumber || 0) > roundNumber ? matchUp.roundNumber : roundNumber;
26011
- }, 0);
26012
- const selectedEntries = drawDefinition?.entries?.filter((entry) => {
26013
- const entryStatus = entry.entryStatus;
26014
- return STRUCTURE_SELECTED_STATUSES.includes(entryStatus);
26015
- }) ?? [];
26016
- const roundMatchUpsCount = Math.floor(selectedEntries?.length / 2) || 1;
26085
+ const availableResult = getAvailableMatchUpsCount(params);
26086
+ if (availableResult.error)
26087
+ return decorateResult({ result: availableResult });
26088
+ const { lastRoundNumber, availableMatchUpsCount = 0, roundMatchUpsCount = 0 } = availableResult;
26017
26089
  if (!matchUpsCount) {
26018
26090
  if (newRound) {
26019
26091
  matchUpsCount = roundMatchUpsCount;
26020
26092
  }
26021
- else {
26022
- const targetRoundNumber = roundNumber ?? lastRoundNumber ?? 1;
26023
- const existingRoundMatchUps = structure.matchUps?.filter((matchUp) => matchUp.roundNumber === targetRoundNumber)?.length ?? 0;
26024
- const maxRemaining = roundMatchUpsCount - existingRoundMatchUps;
26025
- if (maxRemaining > 0)
26026
- matchUpsCount = maxRemaining;
26027
- }
26093
+ else if (availableMatchUpsCount > 0)
26094
+ matchUpsCount = availableMatchUpsCount;
26028
26095
  }
26029
26096
  else if (matchUpsCount > roundMatchUpsCount && params.restrictMatchUpsCount !== false) {
26030
26097
  return decorateResult({
@@ -26040,9 +26107,6 @@ function generateAdHocMatchUps(params) {
26040
26107
  if (matchUpsCount && matchUpsCount > 25) {
26041
26108
  return { error: INVALID_VALUES, info: 'matchUpsCount must be less than 25' };
26042
26109
  }
26043
- if (structure.structures || structureHasRoundPositions || structure.finishingPosition === ROUND_OUTCOME) {
26044
- return { error: INVALID_STRUCTURE };
26045
- }
26046
26110
  if (roundNumber && !params.ignoreLastRoundNumber && roundNumber - 1 > (lastRoundNumber || 0)) {
26047
26111
  return { error: INVALID_VALUES, info: 'roundNumber error' };
26048
26112
  }
@@ -26053,7 +26117,7 @@ function generateAdHocMatchUps(params) {
26053
26117
  participantIds: [undefined, undefined],
26054
26118
  }));
26055
26119
  const getPrefixedId = (index) => {
26056
- if (!params.idPrefix && !isMock)
26120
+ if (!params.idPrefix)
26057
26121
  return undefined;
26058
26122
  const drawId = drawDefinition.drawId;
26059
26123
  const idPrefix = params.idPrefix ?? 'ah';
@@ -28768,7 +28832,7 @@ function getPredictiveAccuracy(params) {
28768
28832
  ascending,
28769
28833
  scaleName,
28770
28834
  });
28771
- const marginCalc = !zoneDoubling || matchUpType === SINGLES ? zoneMargin : (zoneMargin || 0) * 2;
28835
+ const marginCalc = !zoneDoubling || isMatchUpEventType(SINGLES)(matchUpType) ? zoneMargin : (zoneMargin || 0) * 2;
28772
28836
  const zoneData = zoneMargin
28773
28837
  ? relevantMatchUps
28774
28838
  .map(({ competitiveProfile, matchUpType, score, sides }) => {
@@ -30226,6 +30290,7 @@ var index$g = {
30226
30290
  getAllowedMatchUpFormats: getAllowedMatchUpFormats,
30227
30291
  getAppliedPolicies: getAppliedPolicies,
30228
30292
  getAssignedParticipantIds: getAssignedParticipantIds,
30293
+ getAvailableMatchUpsCount: getAvailableMatchUpsCount,
30229
30294
  getAvailablePlayoffProfiles: getAvailablePlayoffProfiles,
30230
30295
  getCategoryAgeDetails: getCategoryAgeDetails,
30231
30296
  getCheckedInParticipantIds: getCheckedInParticipantIds,
@@ -35540,22 +35605,22 @@ function setMatchUpMatchUpFormat(params) {
35540
35605
  });
35541
35606
  if (result.error)
35542
35607
  return result;
35543
- if (!result.matchUp)
35544
- return { error: MATCHUP_NOT_FOUND };
35545
35608
  const matchUp = result.matchUp;
35546
35609
  if (matchUp?.matchUpType === TEAM$2)
35547
35610
  return {
35548
- error: INVALID_MATCHUP,
35549
35611
  info: 'Cannot set matchUpFormat when { matchUpType: TEAM }',
35612
+ error: INVALID_MATCHUP,
35550
35613
  };
35551
- matchUp.matchUpFormat = matchUpFormat;
35552
- modifyMatchUpNotice({
35553
- tournamentId: tournamentRecord?.tournamentId,
35554
- eventId: event?.eventId,
35555
- context: stack,
35556
- drawDefinition,
35557
- matchUp,
35558
- });
35614
+ if (matchUp) {
35615
+ matchUp.matchUpFormat = matchUpFormat;
35616
+ modifyMatchUpNotice({
35617
+ tournamentId: tournamentRecord?.tournamentId,
35618
+ eventId: event?.eventId,
35619
+ context: stack,
35620
+ drawDefinition,
35621
+ matchUp,
35622
+ });
35623
+ }
35559
35624
  }
35560
35625
  else if (Array.isArray(structureIds)) {
35561
35626
  if (event?.eventType === TEAM$2)
@@ -35564,12 +35629,8 @@ function setMatchUpMatchUpFormat(params) {
35564
35629
  const result = findStructure({ drawDefinition, structureId });
35565
35630
  if (result.error)
35566
35631
  return result;
35567
- if (!result.structure) {
35568
- return { error: STRUCTURE_NOT_FOUND };
35569
- }
35570
- else {
35632
+ if (result.structure)
35571
35633
  result.structure.matchUpFormat = matchUpFormat;
35572
- }
35573
35634
  }
35574
35635
  }
35575
35636
  else if (structureId) {
@@ -35578,12 +35639,8 @@ function setMatchUpMatchUpFormat(params) {
35578
35639
  const result = findStructure({ drawDefinition, structureId });
35579
35640
  if (result.error)
35580
35641
  return result;
35581
- if (!result.structure) {
35582
- return { error: STRUCTURE_NOT_FOUND };
35583
- }
35584
- else {
35642
+ if (result.structure)
35585
35643
  result.structure.matchUpFormat = matchUpFormat;
35586
- }
35587
35644
  }
35588
35645
  else if (drawDefinition) {
35589
35646
  drawDefinition.matchUpFormat = matchUpFormat;
@@ -36027,6 +36084,7 @@ var index$e = {
36027
36084
  generateQualifyingStructure: generateQualifyingStructure,
36028
36085
  generateVoluntaryConsolation: generateVoluntaryConsolation,
36029
36086
  getAssignedParticipantIds: getAssignedParticipantIds,
36087
+ getAvailableMatchUpsCount: getAvailableMatchUpsCount,
36030
36088
  getAvailablePlayoffProfiles: getAvailablePlayoffProfiles,
36031
36089
  getDrawDefinitionTimeItem: getDrawDefinitionTimeItem,
36032
36090
  getDrawParticipantRepresentativeIds: getDrawParticipantRepresentativeIds,
@@ -38690,7 +38748,7 @@ function generateLineUps(params) {
38690
38748
  for (const collectionDefinition of collectionDefinitions) {
38691
38749
  const collectionParticipantIds = [];
38692
38750
  const { collectionId, matchUpCount, matchUpType, gender } = collectionDefinition;
38693
- const singlesMatchUp = matchUpType === SINGLES_MATCHUP;
38751
+ const singlesMatchUp = isMatchUpEventType(SINGLES_MATCHUP)(matchUpType);
38694
38752
  generateRange(0, matchUpCount).forEach((i) => {
38695
38753
  const typeSort = singlesMatchUp ? singlesSort : doublesSort ?? [];
38696
38754
  const collectionPosition = i + 1;
@@ -39409,7 +39467,7 @@ function getTieMatchUpContext({ tournamentRecord, drawDefinition, tieMatchUpId,
39409
39467
  if (!inContextTieMatchUp)
39410
39468
  return { error: MATCHUP_NOT_FOUND };
39411
39469
  const { collectionPosition, drawPositions, collectionId, matchUpTieId, matchUpType } = inContextTieMatchUp;
39412
- if (matchUpType && ![SINGLES, DOUBLES].includes(matchUpType))
39470
+ if (matchUpType && !includesMatchUpEventType([SINGLES, DOUBLES], matchUpType))
39413
39471
  return { error: INVALID_MATCHUP };
39414
39472
  const { positionAssignments } = getPositionAssignments$1({ structure });
39415
39473
  const relevantAssignments = positionAssignments?.filter((assignment) => drawPositions?.includes(assignment.drawPosition));
@@ -39957,7 +40015,7 @@ function assignTieMatchUpParticipantId(params) {
39957
40015
  return { error: INVALID_PARTICIPANT, info: 'Gender mismatch' };
39958
40016
  }
39959
40017
  const { individualParticipantIds, participantType } = participantToAssign;
39960
- if (matchUpType === SINGLES && participantType !== INDIVIDUAL) {
40018
+ if (isMatchUpEventType(SINGLES)(matchUpType) && participantType !== INDIVIDUAL) {
39961
40019
  return { error: INVALID_PARTICIPANT_TYPE };
39962
40020
  }
39963
40021
  const relevantParticipantIds = participantType === INDIVIDUAL ? [participantId] : individualParticipantIds;
@@ -40330,16 +40388,14 @@ function removeTieMatchUpParticipantId(params) {
40330
40388
  return { ...SUCCESS, modifiedLineUp };
40331
40389
  }
40332
40390
 
40333
- function removeMatchUpSideParticipant({ tournamentRecord, drawDefinition, sideNumber, matchUpId, event }) {
40334
- if (!tournamentRecord)
40335
- return { error: MISSING_TOURNAMENT_RECORD };
40336
- if (!drawDefinition)
40337
- return { error: MISSING_DRAW_DEFINITION };
40338
- if (!matchUpId)
40339
- return { error: MISSING_MATCHUP_ID };
40340
- if (!sideNumber)
40341
- return { error: MISSING_VALUE };
40342
- if (![1, 2].includes(sideNumber))
40391
+ function removeMatchUpSideParticipant(params) {
40392
+ const paramsCheck = checkRequiredParameters(params, [
40393
+ { [TOURNAMENT_RECORD]: true, [DRAW_DEFINITION]: true, [MATCHUP_ID]: true },
40394
+ ]);
40395
+ if (paramsCheck.error)
40396
+ return paramsCheck;
40397
+ const { drawDefinition, sideNumber, matchUpId, event } = params;
40398
+ if (sideNumber && ![1, 2].includes(sideNumber))
40343
40399
  return { error: INVALID_VALUES, sideNumber };
40344
40400
  const { matchUp, structure } = findDrawMatchUp({
40345
40401
  drawDefinition,
@@ -40348,17 +40404,14 @@ function removeMatchUpSideParticipant({ tournamentRecord, drawDefinition, sideNu
40348
40404
  });
40349
40405
  if (!matchUp)
40350
40406
  return { error: MATCHUP_NOT_FOUND };
40351
- const isAdHoc = !structure?.structures &&
40352
- !(drawDefinition.drawType && drawDefinition.drawType !== AD_HOC) &&
40353
- !structure?.matchUps?.find(({ roundPosition }) => !!roundPosition);
40354
- if (!isAdHoc)
40407
+ if (!isAdHoc({ structure }))
40355
40408
  return { error: INVALID_DRAW_TYPE };
40356
40409
  matchUp.sides?.forEach((side) => {
40357
- if (side.sideNumber === sideNumber)
40410
+ if (!sideNumber || side.sideNumber === sideNumber)
40358
40411
  delete side.participantId;
40359
40412
  });
40360
40413
  modifyMatchUpNotice({
40361
- tournamentId: tournamentRecord?.tournamentId,
40414
+ tournamentId: params.tournamentRecord?.tournamentId,
40362
40415
  context: 'assignSideParticipant',
40363
40416
  drawDefinition,
40364
40417
  matchUp,
@@ -42410,9 +42463,10 @@ function setMatchUpState(params) {
42410
42463
  }
42411
42464
  const structureId = inContextMatchUp?.structureId;
42412
42465
  const { structure } = findStructure({ drawDefinition, structureId });
42466
+ const isTeam = isMatchUpEventType(TEAM$1)(matchUp.matchUpType);
42413
42467
  const assignedDrawPositions = inContextMatchUp?.drawPositions?.filter(Boolean);
42414
42468
  let dualWinningSideChange;
42415
- if (matchUp.matchUpType === TEAM$1) {
42469
+ if (isTeam) {
42416
42470
  if (disableAutoCalc) {
42417
42471
  addExtension({
42418
42472
  extension: { name: DISABLE_AUTO_CALC, value: true },
@@ -42450,7 +42504,7 @@ function setMatchUpState(params) {
42450
42504
  drawDefinition,
42451
42505
  });
42452
42506
  }
42453
- if (matchUp.matchUpType === TEAM$1 &&
42507
+ if (isTeam &&
42454
42508
  matchUpStatus &&
42455
42509
  [
42456
42510
  AWAITING_RESULT,
@@ -42466,7 +42520,7 @@ function setMatchUpState(params) {
42466
42520
  inContextDrawMatchUps,
42467
42521
  drawDefinition,
42468
42522
  });
42469
- if (score && matchUp.matchUpType !== TEAM$1 && !disableScoreValidation) {
42523
+ if (score && !isTeam && !disableScoreValidation) {
42470
42524
  const matchUpFormat = matchUp.matchUpFormat ?? structure?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
42471
42525
  const result = validateScore({
42472
42526
  existingMatchUpStatus: matchUp.matchUpStatus,
@@ -42485,15 +42539,17 @@ function setMatchUpState(params) {
42485
42539
  structureId,
42486
42540
  }).positionAssignments
42487
42541
  : [];
42488
- const bothSideParticipants = inContextMatchUp?.sides?.map((side) => side.participantId).filter(Boolean).length === 2 ||
42542
+ const participantsCount = inContextMatchUp?.sides?.map((side) => side.participantId).filter(Boolean).length;
42543
+ const requiredParticipants = (participantsCount && participantsCount === 2) ||
42544
+ (isTeam && isAdHoc({ structure }) && participantsCount && participantsCount >= 1) ||
42489
42545
  (assignedDrawPositions?.length === 2 &&
42490
42546
  positionAssignments
42491
42547
  ?.filter((assignment) => assignedDrawPositions.includes(assignment.drawPosition))
42492
42548
  .every((assignment) => assignment.participantId));
42493
- if (matchUpStatus && particicipantsRequiredMatchUpStatuses.includes(matchUpStatus) && !bothSideParticipants) {
42549
+ if (matchUpStatus && particicipantsRequiredMatchUpStatuses.includes(matchUpStatus) && !requiredParticipants) {
42494
42550
  return decorateResult({
42495
42551
  info: 'present in participantRequiredMatchUpStatuses',
42496
- context: { matchUpStatus, bothSideParticipants },
42552
+ context: { matchUpStatus, requiredParticipants },
42497
42553
  result: { error: INVALID_MATCHUP_STATUS },
42498
42554
  });
42499
42555
  }
@@ -42608,11 +42664,7 @@ function setMatchUpState(params) {
42608
42664
  return result;
42609
42665
  }
42610
42666
  }
42611
- const validWinningSideSwap = matchUp.matchUpType !== TEAM$1 &&
42612
- !dualWinningSideChange &&
42613
- winningSide &&
42614
- matchUp.winningSide &&
42615
- matchUp.winningSide !== winningSide;
42667
+ const validWinningSideSwap = !isTeam && !dualWinningSideChange && winningSide && matchUp.winningSide && matchUp.winningSide !== winningSide;
42616
42668
  if (allowChangePropagation &&
42617
42669
  validWinningSideSwap &&
42618
42670
  matchUp.roundPosition) {
@@ -42780,22 +42832,23 @@ function disableTieAutoCalc({ drawDefinition, matchUpId, event }) {
42780
42832
 
42781
42833
  function setMatchUpFormat(params) {
42782
42834
  const stack = 'setMatchUpFormat';
42835
+ const paramsCheck = checkRequiredParameters(params, [
42836
+ { tournamentRecord: true },
42837
+ {
42838
+ [VALIDATE]: (value) => isValidMatchUpFormat({ matchUpFormat: value }),
42839
+ [INVALID]: UNRECOGNIZED_MATCHUP_FORMAT,
42840
+ matchUpFormat: true,
42841
+ },
42842
+ ]);
42843
+ if (paramsCheck.error)
42844
+ return decorateResult({ result: paramsCheck, stack });
42783
42845
  const { tournamentRecord, drawDefinition, scheduledDates, stageSequences, matchUpFormat, structureId, eventType, matchUpId, eventId, stages, drawId, event, force, } = params;
42784
- if (!tournamentRecord)
42785
- return { error: MISSING_TOURNAMENT_RECORD };
42786
- if (!matchUpFormat)
42787
- return { error: MISSING_MATCHUP_FORMAT };
42788
- if (matchUpFormat && !isValidMatchUpFormat({ matchUpFormat }))
42789
- return decorateResult({
42790
- result: { error: UNRECOGNIZED_MATCHUP_FORMAT, matchUpFormat },
42791
- stack,
42792
- });
42793
42846
  if (scheduledDates && !Array.isArray(scheduledDates))
42794
42847
  return decorateResult({
42795
42848
  result: { error: INVALID_VALUES, scheduledDates },
42796
42849
  stack,
42797
42850
  });
42798
- if (eventType && ![SINGLES$1, DOUBLES$1].includes(eventType))
42851
+ if (eventType && !includesMatchUpEventType([SINGLES$1, DOUBLES$1], eventType))
42799
42852
  return decorateResult({ result: { error: INVALID_EVENT_TYPE }, stack });
42800
42853
  let modificationsCount = 0;
42801
42854
  const structureIds = params.structureIds || (structureId && [structureId].filter(Boolean)) || [];
@@ -42867,7 +42920,7 @@ function setMatchUpFormat(params) {
42867
42920
  }
42868
42921
  return modifiedStructureIds;
42869
42922
  };
42870
- for (const event of tournamentRecord.events || []) {
42923
+ for (const event of tournamentRecord?.events || []) {
42871
42924
  if ((eventIds?.length && !eventIds.includes(event.eventId)) ||
42872
42925
  (eventType && eventType !== event.eventType) ||
42873
42926
  eventType === TEAM$2) {
@@ -43142,6 +43195,264 @@ function setDelegatedOutcome(params) {
43142
43195
  return setDelegatedOutcome$1(params);
43143
43196
  }
43144
43197
 
43198
+ function resetTieFormat(params) {
43199
+ const stack = 'resetTieFormat';
43200
+ const { drawDefinition, event, uuids } = params;
43201
+ const paramCheck = checkRequiredParameters(params, [{ [TOURNAMENT_RECORD]: true, [MATCHUP_ID]: true }], stack);
43202
+ if (paramCheck.error)
43203
+ return paramCheck;
43204
+ const resolutions = resolveFromParameters(params, [{ [PARAM]: MATCHUP }]);
43205
+ if (resolutions[ERROR])
43206
+ return resolutions;
43207
+ const tournamentId = params.tournamentRecord?.tournamentId;
43208
+ const { matchUp, structure } = resolutions?.matchUp ?? {};
43209
+ if (!matchUp?.tieMatchUps)
43210
+ return decorateResult({
43211
+ result: { error: INVALID_MATCHUP },
43212
+ info: 'Must be a TEAM matchUp',
43213
+ stack,
43214
+ });
43215
+ if (!matchUp.tieFormat)
43216
+ return { ...SUCCESS };
43217
+ const tieFormat = resolveTieFormat({
43218
+ structure,
43219
+ drawDefinition,
43220
+ event,
43221
+ })?.tieFormat;
43222
+ if (!tieFormat)
43223
+ return decorateResult({
43224
+ result: { error: NOT_FOUND },
43225
+ info: 'No inherited tieFormat',
43226
+ stack,
43227
+ });
43228
+ const deletedMatchUpIds = [];
43229
+ const collectionIds = [];
43230
+ const tieMatchUps = [];
43231
+ const newMatchUps = [];
43232
+ for (const collectionDefinition of tieFormat.collectionDefinitions) {
43233
+ const { matchUpCount, collectionId } = collectionDefinition;
43234
+ collectionIds.push(collectionId);
43235
+ const existingCollectionMatchUps = (matchUp.tieMatchUps || []).filter((matchUp) => matchUp.collectionId === collectionId);
43236
+ if (existingCollectionMatchUps.length > matchUpCount) {
43237
+ existingCollectionMatchUps.sort((a, b) => (a.matchUpStatus === TO_BE_PLAYED ? 1 : 0) - (b.matchUpStatus === TO_BE_PLAYED ? 1 : 0));
43238
+ tieMatchUps.push(...existingCollectionMatchUps.slice(0, matchUpCount));
43239
+ deletedMatchUpIds.push(...existingCollectionMatchUps.slice(3).map(getMatchUpId));
43240
+ }
43241
+ else {
43242
+ tieMatchUps.push(...existingCollectionMatchUps);
43243
+ if (existingCollectionMatchUps.length < matchUpCount) {
43244
+ const matchUpsLimit = matchUpCount - existingCollectionMatchUps.length;
43245
+ const matchUps = generateCollectionMatchUps({
43246
+ collectionDefinition,
43247
+ matchUpsLimit,
43248
+ matchUp,
43249
+ uuids,
43250
+ });
43251
+ newMatchUps.push(...matchUps);
43252
+ }
43253
+ }
43254
+ }
43255
+ for (const tieMatchUp of matchUp?.tieMatchUps || []) {
43256
+ if (tieMatchUp.collectionId && !collectionIds.includes(tieMatchUp.collectionId))
43257
+ deletedMatchUpIds.push(tieMatchUp.matchUpId);
43258
+ }
43259
+ if (newMatchUps.length) {
43260
+ tieMatchUps.push(...newMatchUps);
43261
+ addMatchUpsNotice({
43262
+ eventId: event?.eventId,
43263
+ matchUps: newMatchUps,
43264
+ drawDefinition,
43265
+ tournamentId,
43266
+ });
43267
+ }
43268
+ if (deletedMatchUpIds.length) {
43269
+ deleteMatchUpsNotice({
43270
+ matchUpIds: deletedMatchUpIds,
43271
+ eventId: event?.eventId,
43272
+ drawDefinition,
43273
+ tournamentId,
43274
+ });
43275
+ }
43276
+ if (matchUp) {
43277
+ matchUp.tieMatchUps = tieMatchUps;
43278
+ matchUp.tieFormatId = undefined;
43279
+ matchUp.tieFormat = undefined;
43280
+ modifyMatchUpNotice({
43281
+ structureId: structure?.structureId,
43282
+ eventId: event?.eventId,
43283
+ context: stack,
43284
+ drawDefinition,
43285
+ tournamentId,
43286
+ matchUp,
43287
+ });
43288
+ }
43289
+ return { ...SUCCESS, newMatchUps, deletedMatchUpIds };
43290
+ }
43291
+
43292
+ function resetScorecard(params) {
43293
+ const { tournamentRecord, drawDefinition, matchUpId, event } = params;
43294
+ const stack = 'resetScorecard';
43295
+ if (!drawDefinition)
43296
+ return decorateResult({
43297
+ result: { error: MISSING_DRAW_DEFINITION },
43298
+ stack,
43299
+ });
43300
+ if (!matchUpId)
43301
+ return decorateResult({ result: { error: MISSING_MATCHUP_ID }, stack });
43302
+ if (!isString(matchUpId))
43303
+ return decorateResult({
43304
+ result: { error: INVALID_VALUES, matchUpId },
43305
+ stack,
43306
+ });
43307
+ const matchUpsMap = getMatchUpsMap({ drawDefinition });
43308
+ const { matchUps: inContextDrawMatchUps } = getAllDrawMatchUps({
43309
+ nextMatchUps: true,
43310
+ inContext: true,
43311
+ drawDefinition,
43312
+ matchUpsMap,
43313
+ });
43314
+ const matchUp = matchUpsMap.drawMatchUps.find((matchUp) => matchUp.matchUpId === matchUpId);
43315
+ const inContextMatchUp = inContextDrawMatchUps?.find((matchUp) => matchUp.matchUpId === matchUpId);
43316
+ if (!matchUp || !inContextDrawMatchUps)
43317
+ return { error: MATCHUP_NOT_FOUND };
43318
+ if (matchUp.matchUpType !== TEAM_EVENT)
43319
+ return { error: INVALID_MATCHUP };
43320
+ const targetData = positionTargets({
43321
+ inContextDrawMatchUps,
43322
+ drawDefinition,
43323
+ matchUpId,
43324
+ });
43325
+ const structureId = inContextMatchUp?.structureId;
43326
+ const { structure } = findStructure({ drawDefinition, structureId });
43327
+ Object.assign(params, {
43328
+ inContextDrawMatchUps,
43329
+ inContextMatchUp,
43330
+ matchUpsMap,
43331
+ targetData,
43332
+ structure,
43333
+ matchUp,
43334
+ });
43335
+ const activeDownstream = isActiveDownstream(params);
43336
+ if (activeDownstream)
43337
+ return { error: CANNOT_CHANGE_WINNING_SIDE };
43338
+ if (matchUp.tieMatchUps?.length) {
43339
+ for (const tieMatchUp of matchUp.tieMatchUps) {
43340
+ const result = setMatchUpState({
43341
+ matchUpId: tieMatchUp.matchUpId,
43342
+ matchUpTieId: matchUpId,
43343
+ winningSide: undefined,
43344
+ removeScore: true,
43345
+ tournamentRecord,
43346
+ drawDefinition,
43347
+ event,
43348
+ });
43349
+ if (result.error)
43350
+ return decorateResult({ result, stack });
43351
+ }
43352
+ }
43353
+ const appliedPolicies = getAppliedPolicies({
43354
+ tournamentRecord,
43355
+ drawDefinition,
43356
+ event,
43357
+ })?.appliedPolicies;
43358
+ const result = updateTieMatchUpScore({
43359
+ event: params.event,
43360
+ removeScore: true,
43361
+ tournamentRecord,
43362
+ appliedPolicies,
43363
+ drawDefinition,
43364
+ matchUpsMap,
43365
+ matchUpId,
43366
+ });
43367
+ if (result.error)
43368
+ return decorateResult({ result, stack });
43369
+ if (params.tiebreakReset && !result.tieFormatRemoved) {
43370
+ const inheritedTieFormat = resolveTieFormat({
43371
+ drawDefinition,
43372
+ structure,
43373
+ event,
43374
+ })?.tieFormat;
43375
+ if (matchUp.tieFormat && inheritedTieFormat) {
43376
+ const { matchUpCountDifference, descendantDifferences, ancestorDifferences, valueDifference } = compareTieFormats({
43377
+ descendant: matchUp.tieFormat,
43378
+ ancestor: inheritedTieFormat,
43379
+ });
43380
+ if (descendantDifferences.collectionIds.length === 1 &&
43381
+ !ancestorDifferences.collectionIds.length &&
43382
+ !ancestorDifferences.groupsCount &&
43383
+ matchUpCountDifference === 1 &&
43384
+ valueDifference === 1) {
43385
+ const result = resetTieFormat({
43386
+ tournamentRecord,
43387
+ drawDefinition,
43388
+ matchUpId,
43389
+ event,
43390
+ });
43391
+ if (result.error)
43392
+ return result;
43393
+ }
43394
+ }
43395
+ }
43396
+ return { ...SUCCESS };
43397
+ }
43398
+
43399
+ function resetAdHocMatchUps(params) {
43400
+ const paramsCheck = checkRequiredParameters(params, [
43401
+ { [DRAW_DEFINITION]: true, [EVENT]: true },
43402
+ {
43403
+ [ONE_OF]: { [MATCHUP_IDS]: false, roundNumbers: false },
43404
+ [MESSAGE]: 'At least one must be provided',
43405
+ [OF_TYPE]: ARRAY,
43406
+ },
43407
+ ]);
43408
+ if (paramsCheck.error)
43409
+ return paramsCheck;
43410
+ const structureResult = getAdHocStructureDetails(params);
43411
+ if (structureResult.error)
43412
+ return structureResult;
43413
+ const { matchUpIds } = structureResult;
43414
+ const isTeam = isMatchUpEventType(TEAM_EVENT)(params.event.eventType);
43415
+ const { tournamentRecord, drawDefinition, event } = params;
43416
+ for (const matchUpId of matchUpIds) {
43417
+ if (isTeam) {
43418
+ const result = resetScorecard({
43419
+ tiebreakReset: true,
43420
+ tournamentRecord,
43421
+ drawDefinition,
43422
+ matchUpId,
43423
+ event,
43424
+ });
43425
+ if (result.error)
43426
+ return result;
43427
+ if (params.removeAssignments) {
43428
+ const resetLineUpResult = resetMatchUpLineUps({
43429
+ inheritance: false,
43430
+ drawDefinition,
43431
+ matchUpId,
43432
+ });
43433
+ if (resetLineUpResult.error)
43434
+ return result;
43435
+ }
43436
+ }
43437
+ const result = setMatchUpState({
43438
+ winningSide: undefined,
43439
+ removeScore: true,
43440
+ tournamentRecord,
43441
+ drawDefinition,
43442
+ matchUpId,
43443
+ event,
43444
+ });
43445
+ if (result.error)
43446
+ return result;
43447
+ if (params.removeAssignments) {
43448
+ const removeResult = removeMatchUpSideParticipant({ ...params, matchUpId });
43449
+ if (removeResult.error)
43450
+ return removeResult;
43451
+ }
43452
+ }
43453
+ return { ...SUCCESS };
43454
+ }
43455
+
43145
43456
  function setOrderOfFinish$1({ drawDefinition, finishingOrder }) {
43146
43457
  if (!drawDefinition)
43147
43458
  return { error: MISSING_DRAW_DEFINITION };
@@ -43317,7 +43628,7 @@ function applyLineUps({ tournamentRecord, drawDefinition, matchUpId, lineUps, ev
43317
43628
  collectionParticipantIds[aggregator] = [];
43318
43629
  }
43319
43630
  const participantsCount = collectionParticipantIds[aggregator].length;
43320
- if ((collectionDefinition.matchUpType === SINGLES && participantsCount) ||
43631
+ if ((isMatchUpEventType(SINGLES)(collectionDefinition.matchUpType) && participantsCount) ||
43321
43632
  (collectionDefinition.matchUpType === DOUBLES && participantsCount > 1)) {
43322
43633
  return {
43323
43634
  info: 'Excessive collectionPosition assignments',
@@ -43389,207 +43700,6 @@ function applyLineUps({ tournamentRecord, drawDefinition, matchUpId, lineUps, ev
43389
43700
  return { ...SUCCESS };
43390
43701
  }
43391
43702
 
43392
- function resetTieFormat(params) {
43393
- const stack = 'resetTieFormat';
43394
- const { drawDefinition, event, uuids } = params;
43395
- const paramCheck = checkRequiredParameters(params, [{ [TOURNAMENT_RECORD]: true, [MATCHUP_ID]: true }], stack);
43396
- if (paramCheck.error)
43397
- return paramCheck;
43398
- const resolutions = resolveFromParameters(params, [{ [PARAM]: MATCHUP }]);
43399
- if (resolutions[ERROR])
43400
- return resolutions;
43401
- const tournamentId = params.tournamentRecord?.tournamentId;
43402
- const { matchUp, structure } = resolutions?.matchUp ?? {};
43403
- if (!matchUp?.tieMatchUps)
43404
- return decorateResult({
43405
- result: { error: INVALID_MATCHUP },
43406
- info: 'Must be a TEAM matchUp',
43407
- stack,
43408
- });
43409
- if (!matchUp.tieFormat)
43410
- return { ...SUCCESS };
43411
- const tieFormat = resolveTieFormat({
43412
- structure,
43413
- drawDefinition,
43414
- event,
43415
- })?.tieFormat;
43416
- if (!tieFormat)
43417
- return decorateResult({
43418
- result: { error: NOT_FOUND },
43419
- info: 'No inherited tieFormat',
43420
- stack,
43421
- });
43422
- const deletedMatchUpIds = [];
43423
- const collectionIds = [];
43424
- const tieMatchUps = [];
43425
- const newMatchUps = [];
43426
- for (const collectionDefinition of tieFormat.collectionDefinitions) {
43427
- const { matchUpCount, collectionId } = collectionDefinition;
43428
- collectionIds.push(collectionId);
43429
- const existingCollectionMatchUps = (matchUp.tieMatchUps || []).filter((matchUp) => matchUp.collectionId === collectionId);
43430
- if (existingCollectionMatchUps.length > matchUpCount) {
43431
- existingCollectionMatchUps.sort((a, b) => (a.matchUpStatus === TO_BE_PLAYED ? 1 : 0) - (b.matchUpStatus === TO_BE_PLAYED ? 1 : 0));
43432
- tieMatchUps.push(...existingCollectionMatchUps.slice(0, matchUpCount));
43433
- deletedMatchUpIds.push(...existingCollectionMatchUps.slice(3).map(getMatchUpId));
43434
- }
43435
- else {
43436
- tieMatchUps.push(...existingCollectionMatchUps);
43437
- if (existingCollectionMatchUps.length < matchUpCount) {
43438
- const matchUpsLimit = matchUpCount - existingCollectionMatchUps.length;
43439
- const matchUps = generateCollectionMatchUps({
43440
- collectionDefinition,
43441
- matchUpsLimit,
43442
- matchUp,
43443
- uuids,
43444
- });
43445
- newMatchUps.push(...matchUps);
43446
- }
43447
- }
43448
- }
43449
- for (const tieMatchUp of matchUp?.tieMatchUps || []) {
43450
- if (tieMatchUp.collectionId && !collectionIds.includes(tieMatchUp.collectionId))
43451
- deletedMatchUpIds.push(tieMatchUp.matchUpId);
43452
- }
43453
- if (newMatchUps.length) {
43454
- tieMatchUps.push(...newMatchUps);
43455
- addMatchUpsNotice({
43456
- eventId: event?.eventId,
43457
- matchUps: newMatchUps,
43458
- drawDefinition,
43459
- tournamentId,
43460
- });
43461
- }
43462
- if (deletedMatchUpIds.length) {
43463
- deleteMatchUpsNotice({
43464
- matchUpIds: deletedMatchUpIds,
43465
- eventId: event?.eventId,
43466
- drawDefinition,
43467
- tournamentId,
43468
- });
43469
- }
43470
- if (matchUp) {
43471
- matchUp.tieMatchUps = tieMatchUps;
43472
- matchUp.tieFormatId = undefined;
43473
- matchUp.tieFormat = undefined;
43474
- modifyMatchUpNotice({
43475
- structureId: structure?.structureId,
43476
- eventId: event?.eventId,
43477
- context: stack,
43478
- drawDefinition,
43479
- tournamentId,
43480
- matchUp,
43481
- });
43482
- }
43483
- return { ...SUCCESS, newMatchUps, deletedMatchUpIds };
43484
- }
43485
-
43486
- function resetScorecard(params) {
43487
- const { tournamentRecord, drawDefinition, matchUpId, event } = params;
43488
- const stack = 'resetScorecard';
43489
- if (!drawDefinition)
43490
- return decorateResult({
43491
- result: { error: MISSING_DRAW_DEFINITION },
43492
- stack,
43493
- });
43494
- if (!matchUpId)
43495
- return decorateResult({ result: { error: MISSING_MATCHUP_ID }, stack });
43496
- if (!isString(matchUpId))
43497
- return decorateResult({
43498
- result: { error: INVALID_VALUES, matchUpId },
43499
- stack,
43500
- });
43501
- const matchUpsMap = getMatchUpsMap({ drawDefinition });
43502
- const { matchUps: inContextDrawMatchUps } = getAllDrawMatchUps({
43503
- nextMatchUps: true,
43504
- inContext: true,
43505
- drawDefinition,
43506
- matchUpsMap,
43507
- });
43508
- const matchUp = matchUpsMap.drawMatchUps.find((matchUp) => matchUp.matchUpId === matchUpId);
43509
- const inContextMatchUp = inContextDrawMatchUps?.find((matchUp) => matchUp.matchUpId === matchUpId);
43510
- if (!matchUp || !inContextDrawMatchUps)
43511
- return { error: MATCHUP_NOT_FOUND };
43512
- if (matchUp.matchUpType !== TEAM_EVENT)
43513
- return { error: INVALID_MATCHUP };
43514
- const targetData = positionTargets({
43515
- inContextDrawMatchUps,
43516
- drawDefinition,
43517
- matchUpId,
43518
- });
43519
- const structureId = inContextMatchUp?.structureId;
43520
- const { structure } = findStructure({ drawDefinition, structureId });
43521
- Object.assign(params, {
43522
- inContextDrawMatchUps,
43523
- inContextMatchUp,
43524
- matchUpsMap,
43525
- targetData,
43526
- structure,
43527
- matchUp,
43528
- });
43529
- const activeDownstream = isActiveDownstream(params);
43530
- if (activeDownstream)
43531
- return { error: CANNOT_CHANGE_WINNING_SIDE };
43532
- if (matchUp.tieMatchUps?.length) {
43533
- for (const tieMatchUp of matchUp.tieMatchUps) {
43534
- const result = setMatchUpState({
43535
- matchUpId: tieMatchUp.matchUpId,
43536
- matchUpTieId: matchUpId,
43537
- winningSide: undefined,
43538
- removeScore: true,
43539
- tournamentRecord,
43540
- drawDefinition,
43541
- event,
43542
- });
43543
- if (result.error)
43544
- return decorateResult({ result, stack });
43545
- }
43546
- }
43547
- const appliedPolicies = getAppliedPolicies({
43548
- tournamentRecord,
43549
- drawDefinition,
43550
- event,
43551
- })?.appliedPolicies;
43552
- const result = updateTieMatchUpScore({
43553
- event: params.event,
43554
- removeScore: true,
43555
- tournamentRecord,
43556
- appliedPolicies,
43557
- drawDefinition,
43558
- matchUpsMap,
43559
- matchUpId,
43560
- });
43561
- if (result.error)
43562
- return decorateResult({ result, stack });
43563
- if (params.tiebreakReset && !result.tieFormatRemoved) {
43564
- const inheritedTieFormat = resolveTieFormat({
43565
- drawDefinition,
43566
- structure,
43567
- event,
43568
- })?.tieFormat;
43569
- if (matchUp.tieFormat && inheritedTieFormat) {
43570
- const { matchUpCountDifference, descendantDifferences, ancestorDifferences, valueDifference } = compareTieFormats({
43571
- descendant: matchUp.tieFormat,
43572
- ancestor: inheritedTieFormat,
43573
- });
43574
- if (descendantDifferences.collectionIds.length === 1 &&
43575
- !ancestorDifferences.collectionIds.length &&
43576
- !ancestorDifferences.groupsCount &&
43577
- matchUpCountDifference === 1 &&
43578
- valueDifference === 1) {
43579
- const result = resetTieFormat({
43580
- tournamentRecord,
43581
- drawDefinition,
43582
- matchUpId,
43583
- event,
43584
- });
43585
- if (result.error)
43586
- return result;
43587
- }
43588
- }
43589
- }
43590
- return { ...SUCCESS };
43591
- }
43592
-
43593
43703
  var mutate$7 = {
43594
43704
  __proto__: null,
43595
43705
  applyLineUps: applyLineUps,
@@ -43605,6 +43715,7 @@ var mutate$7 = {
43605
43715
  removeMatchUpSideParticipant: removeMatchUpSideParticipant,
43606
43716
  removeTieMatchUpParticipantId: removeTieMatchUpParticipantId,
43607
43717
  replaceTieMatchUpParticipantId: replaceTieMatchUpParticipantId,
43718
+ resetAdHocMatchUps: resetAdHocMatchUps,
43608
43719
  resetMatchUpLineUps: resetMatchUpLineUps,
43609
43720
  resetScorecard: resetScorecard,
43610
43721
  resetTieFormat: resetTieFormat,
@@ -43668,6 +43779,7 @@ var index$9 = {
43668
43779
  removeMatchUpSideParticipant: removeMatchUpSideParticipant,
43669
43780
  removeTieMatchUpParticipantId: removeTieMatchUpParticipantId,
43670
43781
  replaceTieMatchUpParticipantId: replaceTieMatchUpParticipantId,
43782
+ resetAdHocMatchUps: resetAdHocMatchUps,
43671
43783
  resetMatchUpLineUps: resetMatchUpLineUps,
43672
43784
  resetScorecard: resetScorecard,
43673
43785
  resetTieFormat: resetTieFormat,
@@ -44339,8 +44451,8 @@ function checkRecoveryTime({ individualParticipantProfiles, matchUpNotBeforeTime
44339
44451
  }
44340
44452
 
44341
44453
  function checkDailyLimits({ individualParticipantProfiles, matchUpPotentialParticipantIds, matchUpDailyLimits = {}, matchUp, }) {
44342
- const { matchUpId, matchUpType } = matchUp;
44343
44454
  const { enteredIndividualParticipantIds } = getIndividualParticipantIds(matchUp);
44455
+ const { matchUpId, matchUpType } = matchUp;
44344
44456
  const potentialParticipantIds = ((matchUp.roundPosition && matchUpPotentialParticipantIds[matchUpId]) || []).flat();
44345
44457
  const relevantParticipantIds = unique(enteredIndividualParticipantIds.concat(...potentialParticipantIds));
44346
44458
  relevantParticipantIds.forEach((participantId) => {
@@ -46514,12 +46626,12 @@ function processTieFormat({ alternatesCount = 0, tieFormatName, tieFormat, drawS
46514
46626
  }
46515
46627
  if (!collectionId)
46516
46628
  collectionDefinition.collectionId = UUID();
46517
- if (matchUpType === DOUBLES) {
46629
+ if (isMatchUpEventType(DOUBLES)(matchUpType)) {
46518
46630
  const doublesCount = matchUpCount;
46519
46631
  doublesMatchUpTotal += matchUpCount;
46520
46632
  maxDoublesCount = Math.max(maxDoublesCount, doublesCount);
46521
46633
  }
46522
- if (matchUpType === SINGLES) {
46634
+ if (isMatchUpEventType(SINGLES)(matchUpType)) {
46523
46635
  const singlescount = matchUpCount;
46524
46636
  singlesMatchUpTotal += matchUpCount;
46525
46637
  maxSinglesCount = Math.max(maxSinglesCount, singlescount);
@@ -47470,8 +47582,8 @@ function completeDrawMatchUps(params) {
47470
47582
  tournamentRecord,
47471
47583
  });
47472
47584
  const assignParticipants = (dualMatchUp) => {
47473
- const singlesMatchUps = dualMatchUp.tieMatchUps.filter(({ matchUpType }) => matchUpType === SINGLES);
47474
- const doublesMatchUps = dualMatchUp.tieMatchUps.filter(({ matchUpType }) => matchUpType === DOUBLES);
47585
+ const singlesMatchUps = dualMatchUp.tieMatchUps.filter(isMatchUpEventType(SINGLES));
47586
+ const doublesMatchUps = dualMatchUp.tieMatchUps.filter(isMatchUpEventType(DOUBLES));
47475
47587
  singlesMatchUps.forEach((singlesMatchUp, i) => {
47476
47588
  const tieMatchUpId = singlesMatchUp.matchUpId;
47477
47589
  singlesMatchUp.sides.forEach((side) => {
@@ -47757,7 +47869,9 @@ function generateFlightDrawDefinitions({ matchUpStatusProfile, completeAllMatchU
47757
47869
  function generateEventParticipants(params) {
47758
47870
  const { participantsProfile = {}, uniqueParticipantsCount, ratingsParameters, tournamentRecord, eventProfile, eventIndex, event, uuids, } = params;
47759
47871
  const { category, gender, eventType } = event;
47760
- const eventParticipantType = (eventType === SINGLES$1 && INDIVIDUAL) || (eventType === DOUBLES$1 && PAIR) || eventType;
47872
+ const eventParticipantType = (isMatchUpEventType(SINGLES$1)(eventType) && INDIVIDUAL) ||
47873
+ (isMatchUpEventType(DOUBLES$1)(eventType) && PAIR) ||
47874
+ eventType;
47761
47875
  const mainParticipantsCount = uniqueParticipantsCount[MAIN] || 0;
47762
47876
  const qualifyingParticipantsCount = uniqueParticipantsCount[QUALIFYING] || 0;
47763
47877
  const participantsCount = eventProfile.drawProfiles?.length
@@ -47873,7 +47987,9 @@ function generateEventWithFlights(params) {
47873
47987
  category,
47874
47988
  gender,
47875
47989
  });
47876
- const eventParticipantType = (eventType === SINGLES$1 && INDIVIDUAL) || (eventType === DOUBLES$1 && PAIR) || eventType;
47990
+ const eventParticipantType = (isMatchUpEventType(SINGLES$1)(eventType) && INDIVIDUAL) ||
47991
+ (isMatchUpEventType(DOUBLES$1)(eventType) && PAIR) ||
47992
+ eventType;
47877
47993
  const { uniqueDrawParticipants = [], uniqueParticipantIds = [] } = uniqueParticipantStages
47878
47994
  ? generateEventParticipants({
47879
47995
  event: { eventType, category, gender },
@@ -48233,9 +48349,9 @@ function generateEventWithDraw(params) {
48233
48349
  }
48234
48350
  const isEventParticipantType = (participant) => {
48235
48351
  const { participantType } = participant;
48236
- if (eventType === SINGLES$1 && participantType === INDIVIDUAL)
48352
+ if (isMatchUpEventType(SINGLES$1)(eventType) && participantType === INDIVIDUAL)
48237
48353
  return true;
48238
- if (eventType === DOUBLES$1 && participantType === PAIR)
48354
+ if (isMatchUpEventType(DOUBLES$1)(eventType) && participantType === PAIR)
48239
48355
  return true;
48240
48356
  return eventType === TEAM && participantType === TEAM;
48241
48357
  };
@@ -48987,7 +49103,9 @@ function modifyTournamentRecord(params) {
48987
49103
  else {
48988
49104
  const { gender, category, eventType } = event;
48989
49105
  const { drawProfiles, publish } = eventProfile;
48990
- const eventParticipantType = (eventType === SINGLES$1 && INDIVIDUAL) || (eventType === DOUBLES$1 && PAIR) || eventType;
49106
+ const eventParticipantType = (isMatchUpEventType(SINGLES$1)(eventType) && INDIVIDUAL) ||
49107
+ (isMatchUpEventType(DOUBLES$1)(eventType) && PAIR) ||
49108
+ eventType;
48991
49109
  if (drawProfiles) {
48992
49110
  const { stageParticipantsCount, uniqueParticipantsCount, uniqueParticipantStages } = getStageParticipantsCount({
48993
49111
  drawProfiles,
@@ -54947,9 +55065,11 @@ function venueModify({ tournamentRecord, modifications, venueId, force }) {
54947
55065
  validReplacementAttributes.forEach((attribute) => Object.assign(venue, { [attribute]: modifications[attribute] }));
54948
55066
  const existingCourtIds = venue?.courts?.map((court) => court.courtId) ?? [];
54949
55067
  const courtIdsToModify = modifications.courts?.map((court) => court.courtId) || [];
54950
- const courtIdsToDelete = courtIdsToModify.length && existingCourtIds.filter((courtId) => !courtIdsToModify.includes(courtId));
55068
+ const courtIdsToDelete = courtIdsToModify.length
55069
+ ? existingCourtIds.filter((courtId) => !courtIdsToModify.includes(courtId))
55070
+ : modifications?.courts && existingCourtIds;
54951
55071
  const matchUpsWithCourtId = [];
54952
- if (courtIdsToDelete.length) {
55072
+ if (courtIdsToDelete?.length) {
54953
55073
  const courtsToDelete = venue?.courts?.filter((court) => courtIdsToDelete.includes(court.courtId));
54954
55074
  const scheduleDeletionsCount = courtsToDelete
54955
55075
  ?.map((court) => {
@@ -55372,60 +55492,6 @@ var index$1 = {
55372
55492
 
55373
55493
  const forge = {};
55374
55494
 
55375
- function notifySubscribers(params) {
55376
- const { mutationStatus, tournamentId, directives, timeStamp } = params || {};
55377
- const { topics } = getTopics();
55378
- for (const topic of [...topics].sort(topicSort)) {
55379
- const notices = getNotices({ topic });
55380
- if (notices)
55381
- callListener({ topic, notices });
55382
- }
55383
- if (mutationStatus && timeStamp && topics.includes(MUTATIONS)) {
55384
- callListener({
55385
- notices: [{ tournamentId, directives, timeStamp }],
55386
- topic: MUTATIONS,
55387
- });
55388
- }
55389
- }
55390
- async function notifySubscribersAsync(params) {
55391
- const { mutationStatus, tournamentId, directives, timeStamp } = params || {};
55392
- const { topics } = getTopics();
55393
- for (const topic of [...topics].sort(topicSort)) {
55394
- const notices = getNotices({ topic });
55395
- if (notices)
55396
- await callListener({ topic, notices });
55397
- }
55398
- if (mutationStatus && timeStamp && topics.includes(MUTATIONS)) {
55399
- callListener({
55400
- notices: [{ tournamentId, directives, timeStamp }],
55401
- topic: MUTATIONS,
55402
- });
55403
- }
55404
- }
55405
- const topicValues = {
55406
- [UNPUBLISH_EVENT_SEEDING]: 5,
55407
- [UNPUBLISH_EVENT]: 5,
55408
- [UNPUBLISH_ORDER_OF_PLAY]: 5,
55409
- [MODIFY_SEED_ASSIGNMENTS]: 5,
55410
- [MODIFY_POSITION_ASSIGNMENTS]: 5,
55411
- [MODIFY_DRAW_DEFINITION]: 5,
55412
- [MODIFY_DRAW_ENTRIES]: 5,
55413
- [MODIFY_EVENT_ENTRIES]: 5,
55414
- [MODIFY_MATCHUP]: 1,
55415
- [UPDATE_INCONTEXT_MATCHUP]: 1,
55416
- [MODIFY_PARTICIPANTS]: 5,
55417
- [MODIFY_VENUE]: 5,
55418
- [DELETED_MATCHUP_IDS]: 4,
55419
- [DELETE_PARTICIPANTS]: 4,
55420
- [DELETE_VENUE]: 4,
55421
- [DELETED_DRAW_IDS]: 4,
55422
- [ADD_MATCHUPS]: 3,
55423
- [ADD_DRAW_DEFINITION]: 2,
55424
- };
55425
- function topicSort(a, b) {
55426
- return (topicValues[b] || 0) - (topicValues[a] || 0);
55427
- }
55428
-
55429
55495
  const { FACTORY } = extensionConstants;
55430
55496
  function updateFactoryExtension({ tournamentRecord, value }) {
55431
55497
  const { extension } = findExtension({
@@ -55591,6 +55657,60 @@ function invoke({ tournamentRecords, tournamentRecord, params, methodName, metho
55591
55657
  }
55592
55658
  }
55593
55659
 
55660
+ function notifySubscribers(params) {
55661
+ const { mutationStatus, tournamentId, directives, timeStamp } = params || {};
55662
+ const { topics } = getTopics();
55663
+ for (const topic of [...topics].sort(topicSort)) {
55664
+ const notices = getNotices({ topic });
55665
+ if (notices)
55666
+ callListener({ topic, notices });
55667
+ }
55668
+ if (mutationStatus && timeStamp && topics.includes(MUTATIONS)) {
55669
+ callListener({
55670
+ notices: [{ tournamentId, directives, timeStamp }],
55671
+ topic: MUTATIONS,
55672
+ });
55673
+ }
55674
+ }
55675
+ async function notifySubscribersAsync(params) {
55676
+ const { mutationStatus, tournamentId, directives, timeStamp } = params || {};
55677
+ const { topics } = getTopics();
55678
+ for (const topic of [...topics].sort(topicSort)) {
55679
+ const notices = getNotices({ topic });
55680
+ if (notices)
55681
+ await callListener({ topic, notices });
55682
+ }
55683
+ if (mutationStatus && timeStamp && topics.includes(MUTATIONS)) {
55684
+ callListener({
55685
+ notices: [{ tournamentId, directives, timeStamp }],
55686
+ topic: MUTATIONS,
55687
+ });
55688
+ }
55689
+ }
55690
+ const topicValues = {
55691
+ [UNPUBLISH_EVENT_SEEDING]: 5,
55692
+ [UNPUBLISH_EVENT]: 5,
55693
+ [UNPUBLISH_ORDER_OF_PLAY]: 5,
55694
+ [MODIFY_SEED_ASSIGNMENTS]: 5,
55695
+ [MODIFY_POSITION_ASSIGNMENTS]: 5,
55696
+ [MODIFY_DRAW_DEFINITION]: 5,
55697
+ [MODIFY_DRAW_ENTRIES]: 5,
55698
+ [MODIFY_EVENT_ENTRIES]: 5,
55699
+ [MODIFY_MATCHUP]: 1,
55700
+ [UPDATE_INCONTEXT_MATCHUP]: 1,
55701
+ [MODIFY_PARTICIPANTS]: 5,
55702
+ [MODIFY_VENUE]: 5,
55703
+ [DELETED_MATCHUP_IDS]: 4,
55704
+ [DELETE_PARTICIPANTS]: 4,
55705
+ [DELETE_VENUE]: 4,
55706
+ [DELETED_DRAW_IDS]: 4,
55707
+ [ADD_MATCHUPS]: 3,
55708
+ [ADD_DRAW_DEFINITION]: 2,
55709
+ };
55710
+ function topicSort(a, b) {
55711
+ return (topicValues[b] || 0) - (topicValues[a] || 0);
55712
+ }
55713
+
55594
55714
  function getState$1({ convertExtensions, removeExtensions }) {
55595
55715
  const tournamentRecords = getTournamentRecords();
55596
55716
  const tournamentId = getTournamentId();