tods-competition-factory 7.0.0 → 7.1.0

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.
Files changed (43) hide show
  1. package/dist/esm/assemblies/generators/mocks/applyScenarioProfile.mjs +115 -0
  2. package/dist/esm/assemblies/generators/mocks/completeDrawMatchUps.mjs +6 -1
  3. package/dist/esm/assemblies/generators/mocks/generateTournamentRecord.mjs +7 -0
  4. package/dist/esm/assemblies/governors/drawsGovernor/index.mjs +1 -0
  5. package/dist/esm/assemblies/governors/drawsGovernor/query.mjs +1 -0
  6. package/dist/esm/assemblies/governors/eventGovernor/index.mjs +1 -0
  7. package/dist/esm/assemblies/governors/eventGovernor/mutate.mjs +1 -0
  8. package/dist/esm/assemblies/governors/publishingGovernor/index.mjs +2 -0
  9. package/dist/esm/assemblies/governors/publishingGovernor/query.mjs +2 -0
  10. package/dist/esm/assemblies/governors/queryGovernor/index.mjs +3 -0
  11. package/dist/esm/constants/errorConditionConstants.mjs +6 -1
  12. package/dist/esm/constants/index.mjs +1 -0
  13. package/dist/esm/constants/seedingBasisValues.mjs +6 -0
  14. package/dist/esm/constants/seedingConstants.mjs +11 -0
  15. package/dist/esm/index.mjs +2 -1
  16. package/dist/esm/mutate/drawDefinitions/entryGovernor/addAdditionalSeed.mjs +62 -0
  17. package/dist/esm/mutate/drawDefinitions/entryGovernor/seedAssignment.mjs +4 -2
  18. package/dist/esm/mutate/drawDefinitions/positionGovernor/initializeSeedAssignments.mjs +4 -3
  19. package/dist/esm/mutate/matchUps/drawPositions/drawPositionPlacement.mjs +3 -2
  20. package/dist/esm/mutate/matchUps/matchUpFormat/applyMatchUpFormat.mjs +20 -15
  21. package/dist/esm/mutate/matchUps/matchUpStatus/setMatchUpState.mjs +28 -7
  22. package/dist/esm/mutate/matchUps/matchUpStatus/setMatchUpStatus.mjs +4 -10
  23. package/dist/esm/mutate/matchUps/schedule/scheduleItems/scheduleItems.mjs +70 -18
  24. package/dist/esm/mutate/matchUps/schedule/setMatchUpCalledAt.mjs +1 -1
  25. package/dist/esm/mutate/timeItems/publishTournamentInfo.mjs +7 -1
  26. package/dist/esm/mutate/venues/addCourt.mjs +1 -1
  27. package/dist/esm/package.json.mjs +1 -1
  28. package/dist/esm/query/drawDefinition/getAdditionalSeedsAllowance.mjs +49 -0
  29. package/dist/esm/query/drawDefinition/getSeedsCount.mjs +3 -1
  30. package/dist/esm/query/publishing/getPublishState.mjs +7 -0
  31. package/dist/esm/query/publishing/tournamentVisibility.mjs +60 -0
  32. package/dist/esm/query/readModel/readModelColumns.mjs +1 -0
  33. package/dist/esm/query/readModel/readModelRows.mjs +2 -0
  34. package/dist/esm/tools/plainTime.mjs +2 -0
  35. package/dist/esm/types/tournamentTypes.mjs +8 -1
  36. package/dist/tods-competition-factory.d.cts +151 -9
  37. package/dist/tods-competition-factory.d.mts +151 -9
  38. package/dist/tods-competition-factory.d.ts +151 -9
  39. package/dist/tods-competition-factory.development.cjs.js +840 -439
  40. package/dist/tods-competition-factory.development.cjs.js.map +1 -1
  41. package/dist/tods-competition-factory.production.cjs.min.js +1 -1
  42. package/dist/tods-competition-factory.production.cjs.min.js.map +1 -1
  43. package/package.json +1 -1
@@ -0,0 +1,115 @@
1
+ import { addMatchUpScheduledDate } from '../../../mutate/matchUps/schedule/scheduleItems/addMatchUpScheduledDate.mjs';
2
+ import { addMatchUpScheduledTime } from '../../../mutate/matchUps/schedule/scheduledTime.mjs';
3
+ import { scheduleProfileGrid } from '../../../mutate/matchUps/schedule/scheduleProfileGrid.mjs';
4
+ import { decorateResult } from '../../../functions/global/decorateResult.mjs';
5
+ import { extractDate } from '../../../tools/plainDate.mjs';
6
+ import { allTournamentMatchUps } from '../../../query/matchUps/getAllTournamentMatchUps.mjs';
7
+ import { INVALID_VALUES, INVALID_DATE } from '../../../constants/errorConditionConstants.mjs';
8
+ import { SUCCESS } from '../../../constants/resultConstants.mjs';
9
+
10
+ function isoMinute(date) {
11
+ const p = (n) => String(n).padStart(2, '0');
12
+ return `${date.getFullYear()}-${p(date.getMonth() + 1)}-${p(date.getDate())}T${p(date.getHours())}:${p(date.getMinutes())}`;
13
+ }
14
+ function scheduledInstant(matchUp) {
15
+ const { scheduledDate, scheduledTime } = matchUp?.schedule ?? {};
16
+ if (!scheduledTime)
17
+ return undefined;
18
+ const time = scheduledTime.includes('T') ? scheduledTime.split('T')[1] : scheduledTime;
19
+ const [h, m] = String(time).split(':');
20
+ if (h === undefined || m === undefined)
21
+ return undefined;
22
+ const datePart = scheduledDate ? String(scheduledDate).split('T')[0] : undefined;
23
+ if (!datePart)
24
+ return undefined;
25
+ const [y, mo, d] = datePart.split('-').map(Number);
26
+ const instant = new Date(y, (mo ?? 1) - 1, d ?? 1, Number(h), Number(m));
27
+ return isNaN(instant.getTime()) ? undefined : instant;
28
+ }
29
+ function applyScenarioProfile({ tournamentRecord, scenarioProfile }) {
30
+ if (typeof scenarioProfile !== 'object' || scenarioProfile === null)
31
+ return { error: INVALID_VALUES };
32
+ const { anchor = 'NOW', minutesBeforeAnchor = 0, assignCourts } = scenarioProfile;
33
+ if (typeof minutesBeforeAnchor !== 'number' || !isFinite(minutesBeforeAnchor))
34
+ return { error: INVALID_VALUES };
35
+ const anchorDate = anchor === 'NOW' ? new Date() : new Date(anchor);
36
+ if (isNaN(anchorDate.getTime()))
37
+ return { error: INVALID_VALUES };
38
+ if (assignCourts) {
39
+ const tournamentRecords = { [tournamentRecord.tournamentId]: tournamentRecord };
40
+ const scheduleDates = [
41
+ ...new Set((allTournamentMatchUps({ tournamentRecord }).matchUps ?? [])
42
+ .map((m) => m.schedule?.scheduledDate)
43
+ .filter(Boolean)
44
+ .map((d) => String(d).split('T')[0])),
45
+ ];
46
+ if (scheduleDates.length)
47
+ scheduleProfileGrid({ tournamentRecords, scheduleDates });
48
+ }
49
+ const matchUps = allTournamentMatchUps({ tournamentRecord }).matchUps ?? [];
50
+ const scheduled = matchUps
51
+ .map((matchUp) => ({ matchUp, instant: scheduledInstant(matchUp) }))
52
+ .filter((entry) => !!entry.instant);
53
+ if (!scheduled.length)
54
+ return { ...SUCCESS, shiftedCount: 0, anchoredTo: anchorDate.toISOString() };
55
+ const earliest = Math.min(...scheduled.map((entry) => entry.instant.getTime()));
56
+ const target = anchorDate.getTime() - minutesBeforeAnchor * 60_000;
57
+ const deltaMs = target - earliest;
58
+ const drawMap = {};
59
+ for (const event of tournamentRecord.events ?? []) {
60
+ for (const drawDefinition of event.drawDefinitions ?? [])
61
+ drawMap[drawDefinition.drawId] = drawDefinition;
62
+ }
63
+ const shifts = scheduled
64
+ .filter(({ matchUp }) => drawMap[matchUp.drawId])
65
+ .map(({ matchUp, instant }) => ({ matchUp, shifted: new Date(instant.getTime() + deltaMs) }));
66
+ const startBound = tournamentRecord?.startDate && new Date(extractDate(tournamentRecord.startDate) ?? '').getTime();
67
+ const endBound = tournamentRecord?.endDate && new Date(extractDate(tournamentRecord.endDate) ?? '').getTime();
68
+ if (startBound && endBound) {
69
+ const outside = shifts.find(({ shifted }) => {
70
+ const dayMs = new Date(isoMinute(shifted).split('T')[0]).getTime();
71
+ return dayMs < startBound || dayMs > endBound;
72
+ });
73
+ if (outside) {
74
+ return decorateResult({
75
+ result: { error: INVALID_DATE },
76
+ info: `anchoring would move a matchUp to ${isoMinute(outside.shifted).split('T')[0]}, outside the tournament's dates`,
77
+ stack: 'applyScenarioProfile',
78
+ });
79
+ }
80
+ }
81
+ let shiftedCount = 0;
82
+ for (const { matchUp, shifted } of shifts) {
83
+ const drawDefinition = drawMap[matchUp.drawId];
84
+ const isoShifted = isoMinute(shifted);
85
+ const targetDate = isoShifted.split('T')[0];
86
+ if (targetDate !== String(matchUp.schedule?.scheduledDate ?? '').split('T')[0]) {
87
+ const dateResult = addMatchUpScheduledDate({
88
+ scheduledDate: targetDate,
89
+ matchUpId: matchUp.matchUpId,
90
+ disableNotice: true,
91
+ tournamentRecord,
92
+ drawDefinition,
93
+ });
94
+ if (dateResult?.error)
95
+ return decorateResult({ result: dateResult, stack: 'applyScenarioProfile' });
96
+ }
97
+ const result = addMatchUpScheduledTime({
98
+ scheduledTime: isoShifted,
99
+ matchUpId: matchUp.matchUpId,
100
+ disableNotice: true,
101
+ tournamentRecord,
102
+ drawDefinition,
103
+ });
104
+ if (!result?.error)
105
+ shiftedCount += 1;
106
+ }
107
+ return {
108
+ ...SUCCESS,
109
+ anchoredTo: anchorDate.toISOString(),
110
+ shiftMinutes: Math.round(deltaMs / 60_000),
111
+ shiftedCount,
112
+ };
113
+ }
114
+
115
+ export { applyScenarioProfile };
@@ -196,7 +196,12 @@ function completeDrawMatchUps(params) {
196
196
  const isRoundRobinWithPlayoff = sortedStructures.length === 2 &&
197
197
  sortedStructures[0].finishingPosition === WIN_RATIO &&
198
198
  intersection(sortedStructures.map(({ stage }) => stage), [MAIN, PLAY_OFF]).length === 2;
199
- const structureIds = sortedStructures.map(({ structureId }) => structureId);
199
+ const requestedStructureIds = params.structureIds;
200
+ const structureIds = sortedStructures
201
+ .filter((structure) => !requestedStructureIds?.length ||
202
+ requestedStructureIds.includes(structure.structureId) ||
203
+ (structure.structures ?? []).some((child) => requestedStructureIds.includes(child.structureId)))
204
+ .map(({ structureId }) => structureId);
200
205
  const maxPasses = 10;
201
206
  let passCount = 0;
202
207
  let previousCompleted = -1;
@@ -5,6 +5,7 @@ import { addTournamentParticipants } from './addTournamentParticipants.mjs';
5
5
  import { addParticipants } from '../../../mutate/participants/addParticipants.mjs';
6
6
  import { generateEventWithFlights } from './generateEventWithFlights.mjs';
7
7
  import { generateScheduledRounds } from './generateScheduledRounds.mjs';
8
+ import { applyScenarioProfile } from './applyScenarioProfile.mjs';
8
9
  import { generateEventWithDraw } from './generateEventWithDraw.mjs';
9
10
  import { processLeagueProfiles } from './processLeagueProfiles.mjs';
10
11
  import { cycleMutationStatus } from '../../../global/state/globalState.mjs';
@@ -92,12 +93,18 @@ function generateTournamentRecord(params) {
92
93
  const { scheduledRounds = undefined, schedulerResult = {} } = schedulingProfile
93
94
  ? scheduleRounds({ ...params, tournamentRecord })
94
95
  : {};
96
+ const scenarioResult = params?.scenarioProfile
97
+ ? applyScenarioProfile({ tournamentRecord, scenarioProfile: params.scenarioProfile })
98
+ : undefined;
99
+ if (scenarioResult?.error)
100
+ return scenarioResult;
95
101
  cycleMutationStatus();
96
102
  return definedAttributes({
97
103
  ...SUCCESS,
98
104
  tournamentRecord,
99
105
  scheduledRounds,
100
106
  schedulerResult,
107
+ scenarioResult,
101
108
  eventIds,
102
109
  venueIds,
103
110
  drawIds,
@@ -35,6 +35,7 @@ export { automatedPositioning } from '../../../mutate/drawDefinitions/automatedP
35
35
  export { checkValidEntries } from '../../../validators/checkValidEntries.mjs';
36
36
  export { deleteAdHocMatchUps } from '../../../mutate/structures/deleteAdHocMatchUps.mjs';
37
37
  export { publicFindDrawDefinition as findDrawDefinition } from '../../../acquire/findDrawDefinition.mjs';
38
+ export { getAdditionalSeedsAllowance } from '../../../query/drawDefinition/getAdditionalSeedsAllowance.mjs';
38
39
  export { getAssignedParticipantIds } from '../../../query/drawDefinition/getAssignedParticipantIds.mjs';
39
40
  export { getAvailableMatchUpsCount } from '../../generators/drawDefinitions/drawTypes/adHoc/getAvailableMatchUpsCount.mjs';
40
41
  export { getAvailablePlayoffProfiles } from '../../../query/drawDefinition/getAvailablePlayoffProfiles.mjs';
@@ -27,6 +27,7 @@ export { isValidSeedPosition } from '../../../query/drawDefinition/seedGetter.mj
27
27
  export { getSwissChart } from '../../../query/drawDefinitions/swiss/getSwissChart.mjs';
28
28
  export { validatePlayoffGroups } from '../../../validators/validatePlayoffGroups.mjs';
29
29
  export { getDraftState } from '../../../query/drawDefinition/draft/getDraftState.mjs';
30
+ export { getAdditionalSeedsAllowance } from '../../../query/drawDefinition/getAdditionalSeedsAllowance.mjs';
30
31
  export { getSeedsCount } from '../../../query/drawDefinition/getSeedsCount.mjs';
31
32
  export { getTeamLineUp } from '../../../query/drawDefinition/getTeamLineUp.mjs';
32
33
  export { checkValidEntries } from '../../../validators/checkValidEntries.mjs';
@@ -4,6 +4,7 @@ import * as mutate from './mutate.mjs';
4
4
  export { mutate };
5
5
  import * as query from './query.mjs';
6
6
  export { query };
7
+ export { addAdditionalSeed } from '../../../mutate/drawDefinitions/entryGovernor/addAdditionalSeed.mjs';
7
8
  export { addDrawDefinition } from '../../../mutate/drawDefinitions/addDrawDefinition.mjs';
8
9
  export { addEvent } from '../../../mutate/events/addEvent.mjs';
9
10
  export { addFlight } from '../../../mutate/events/addFlight.mjs';
@@ -8,6 +8,7 @@ export { modifyPairAssignment } from '../../../mutate/drawDefinitions/modifyPair
8
8
  export { updateDrawIdsOrder } from '../../../mutate/events/updateDrawIdsOrder.mjs';
9
9
  export { addDrawDefinition } from '../../../mutate/drawDefinitions/addDrawDefinition.mjs';
10
10
  export { deleteDrawDefinitions } from '../../../mutate/events/deleteDrawDefinitions.mjs';
11
+ export { addAdditionalSeed } from '../../../mutate/drawDefinitions/entryGovernor/addAdditionalSeed.mjs';
11
12
  export { assignSeedPositions } from '../../../mutate/events/assignSeedPositions.mjs';
12
13
  export { attachFlightProfile } from '../../../mutate/events/attachFlightProfile.mjs';
13
14
  export { removeScaleValues } from '../../../mutate/entries/removeScaleValues.mjs';
@@ -12,8 +12,10 @@ export { getPublishState } from '../../../query/publishing/getPublishState.mjs';
12
12
  export { getRoundVisibilityState } from '../../../query/publishing/getRoundVisibilityState.mjs';
13
13
  export { getStructureData } from '../../../query/drawDefinition/getStructureData.mjs';
14
14
  export { getTournamentPublishStatus } from '../../../query/tournaments/getTournamentPublishStatus.mjs';
15
+ export { getTournamentVisibleFrom, isTournamentVisible } from '../../../query/publishing/tournamentVisibility.mjs';
15
16
  export { getVenueData } from '../../../query/venues/getVenueData.mjs';
16
17
  export { isEmbargoed, isVisiblyPublished } from '../../../query/publishing/isEmbargoed.mjs';
18
+ export { isTournamentPublished } from '../../../query/publishing/isTournamentPublished.mjs';
17
19
  export { publishEvent } from '../../../mutate/publishing/publishEvent.mjs';
18
20
  export { publishEventSeeding, unPublishEventSeeding } from '../../../mutate/publishing/eventSeeding.mjs';
19
21
  export { publishOrderOfPlay } from '../../../mutate/timeItems/publishOrderOfPlay.mjs';
@@ -1,6 +1,8 @@
1
1
  export { getTournamentPublishStatus } from '../../../query/tournaments/getTournamentPublishStatus.mjs';
2
2
  export { bulkUpdatePublishedEventIds } from '../../../query/event/bulkUpdatePublishedEventIds.mjs';
3
+ export { getTournamentVisibleFrom, isTournamentVisible } from '../../../query/publishing/tournamentVisibility.mjs';
3
4
  export { getRoundVisibilityState } from '../../../query/publishing/getRoundVisibilityState.mjs';
5
+ export { isTournamentPublished } from '../../../query/publishing/isTournamentPublished.mjs';
4
6
  export { isEmbargoed, isVisiblyPublished } from '../../../query/publishing/isEmbargoed.mjs';
5
7
  export { getEventPublishStatus } from '../../../query/event/getEventPublishStatus.mjs';
6
8
  export { getPublishState } from '../../../query/publishing/getPublishState.mjs';
@@ -55,7 +55,9 @@ export { compareTieFormats } from '../../../query/hierarchical/tieFormats/compar
55
55
  export { getTieFormat } from '../../../query/hierarchical/getTieFormat.mjs';
56
56
  export { getTournamentPublishStatus } from '../../../query/tournaments/getTournamentPublishStatus.mjs';
57
57
  export { bulkUpdatePublishedEventIds } from '../../../query/event/bulkUpdatePublishedEventIds.mjs';
58
+ export { getTournamentVisibleFrom, isTournamentVisible } from '../../../query/publishing/tournamentVisibility.mjs';
58
59
  export { getRoundVisibilityState } from '../../../query/publishing/getRoundVisibilityState.mjs';
60
+ export { isTournamentPublished } from '../../../query/publishing/isTournamentPublished.mjs';
59
61
  export { isEmbargoed, isVisiblyPublished } from '../../../query/publishing/isEmbargoed.mjs';
60
62
  export { getEventPublishStatus } from '../../../query/event/getEventPublishStatus.mjs';
61
63
  export { getPublishState } from '../../../query/publishing/getPublishState.mjs';
@@ -162,6 +164,7 @@ export { isValidSeedPosition } from '../../../query/drawDefinition/seedGetter.mj
162
164
  export { getSwissChart } from '../../../query/drawDefinitions/swiss/getSwissChart.mjs';
163
165
  export { validatePlayoffGroups } from '../../../validators/validatePlayoffGroups.mjs';
164
166
  export { getDraftState } from '../../../query/drawDefinition/draft/getDraftState.mjs';
167
+ export { getAdditionalSeedsAllowance } from '../../../query/drawDefinition/getAdditionalSeedsAllowance.mjs';
165
168
  export { getSeedsCount } from '../../../query/drawDefinition/getSeedsCount.mjs';
166
169
  export { getTeamLineUp } from '../../../query/drawDefinition/getTeamLineUp.mjs';
167
170
  export { checkValidEntries } from '../../../validators/checkValidEntries.mjs';
@@ -162,6 +162,10 @@ const MISSING_SEEDCOUNT_THRESHOLDS = {
162
162
  message: 'Missing seedCountThresholds',
163
163
  code: 'ERR_MISSING_SEED_COUNT_THRESHOLD',
164
164
  };
165
+ const ADDITIONAL_SEEDS_EXHAUSTED = {
166
+ message: 'seeding policy allows no further additional seeds',
167
+ code: 'ERR_ADDITIONAL_SEEDS_EXHAUSTED',
168
+ };
165
169
  const INVALID_ACTION = {
166
170
  message: 'Invalid action',
167
171
  code: 'ERR_INVALID_ACTION',
@@ -1075,6 +1079,7 @@ const errorConditionConstants = {
1075
1079
  SCHEDULED_MATCHUPS,
1076
1080
  SCORES_PRESENT,
1077
1081
  SEEDSCOUNT_GREATER_THAN_DRAW_SIZE,
1082
+ ADDITIONAL_SEEDS_EXHAUSTED,
1078
1083
  STAGE_SEQUENCE_LIMIT,
1079
1084
  STRUCTURE_NOT_FOUND,
1080
1085
  TEAM_NOT_FOUND,
@@ -1088,4 +1093,4 @@ const errorConditionConstants = {
1088
1093
  VENUE_EXISTS,
1089
1094
  };
1090
1095
 
1091
- export { ANACHRONISM, BOOKING_NOT_FOUND, CANNOT_CHANGE_FEED_ELIGIBILITY, CANNOT_CHANGE_OUTCOME, CANNOT_CHANGE_WINNING_SIDE, CANNOT_MODIFY_PARTICIPANT_TYPE, CANNOT_MODIFY_TIEFORMAT, CANNOT_REMOVE_MAIN_STRUCTURE, CANNOT_REMOVE_PARTICIPANTS, CAPACITY_EXCEEDED, CATEGORY_MISMATCH, CONFLICTING_TIME_ZONES, COURT_EXISTS, COURT_NOT_FOUND, DRAW_DEFINITION_NOT_FOUND, DRAW_ID_EXISTS, DRAW_POSITION_ACTIVE, DRAW_POSITION_ASSIGNED, DRAW_POSITION_NOT_CLEARED, DRAW_POSITION_NOT_FOUND, DRAW_POSITION_OCCUPIED, DRAW_SIZE_MISMATCH, DUPLICATE_ENTRY, DUPLICATE_VALUE, ENTRY_STATUS_NOT_ALLOWED_FOR_EVENT, ENTRY_STATUS_NOT_ALLOWED_IN_STAGE, EVENT_EXISTS, EVENT_NOT_FOUND, EXISTING_DRAFT, EXISTING_DRAW_DEFINITIONS, EXISTING_END_TIME, EXISTING_FLIGHT, EXISTING_MATCHUPS, EXISTING_MATCHUP_ID, EXISTING_OUTCOME, EXISTING_PARTICIPANT, EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT, EXISTING_POLICY_TYPE, EXISTING_PROFILE, EXISTING_ROUND, EXISTING_ROUND_PARTICIPANT, EXISTING_STAGE, EXISTING_STRUCTURE, INCOMPATIBLE_MATCHUP_STATUS, INCOMPLETE_SOURCE_STRUCTURE, INSUFFICIENT_DRAW_POSITIONS, INSUFFICIENT_UUIDS, INVALID_ACTION, INVALID_ASSIGNMENT, INVALID_ATTESTATION_SUBJECT, INVALID_ATTRIBUTION, INVALID_BOOKINGS, INVALID_CATEGORY, INVALID_COLLECTION_DEFINITION, INVALID_CONFIGURATION, INVALID_DATE, INVALID_DATE_AVAILABILITY, INVALID_DRAW_DEFINITION, INVALID_DRAW_POSITION, INVALID_DRAW_POSITION_FOR_SEEDING, INVALID_DRAW_SIZE, INVALID_DRAW_TYPE, INVALID_EMBARGO, INVALID_END_TIME, INVALID_ENTRIES, INVALID_ENTRY_STATUS, INVALID_EVENT_TYPE, INVALID_GAME_SCORES, INVALID_GENDER, INVALID_MATCHUP, INVALID_MATCHUP_FORMAT, INVALID_MATCHUP_STATUS, INVALID_MATCHUP_STATUS_BYE, INVALID_OBJECT, INVALID_PARTICIPANT, INVALID_PARTICIPANT_ID, INVALID_PARTICIPANT_IDS, INVALID_PARTICIPANT_ROLE, INVALID_PARTICIPANT_SEEDING, INVALID_PARTICIPANT_TYPE, INVALID_POLICY_DEFINITION, INVALID_RECORDS, INVALID_RESUME_TIME, INVALID_SCALE_ITEM, INVALID_SCORE, INVALID_SEED_NUMBER, INVALID_SEED_POSITION, INVALID_SET_NUMBER, INVALID_SIDE_NUMBER, INVALID_STAGE, INVALID_START_TIME, INVALID_STOP_TIME, INVALID_STRUCTURE, INVALID_TIE_FORMAT, INVALID_TIME, INVALID_TIME_ITEM, INVALID_TIME_ZONE, INVALID_TOURNAMENT_DATES, INVALID_TOURNAMENT_RECORD, INVALID_VALUES, INVALID_WINNING_SIDE, LUCKY_DRAW_BYE_LIMIT, MATCHUPS_COMPLETED_OUTSIDE_DATES, MATCHUPS_SCHEDULED_OUTSIDE_DATES, MATCHUP_HAS_SCHEDULING, MATCHUP_NOT_FOUND, MATCHUP_STATUS_OUT_OF_SCOPE, METHOD_NOT_FOUND, MISSING_ASSIGNMENTS, MISSING_ASYNC_STATE_PROVIDER, MISSING_AVOIDANCE_POLICY, MISSING_BIRTH_DATE, MISSING_COLLECTION_DEFINITION, MISSING_CONTEXT, MISSING_COURTS_INFO, MISSING_COURT_ID, MISSING_DATE, MISSING_DATE_AVAILABILITY, MISSING_DATE_RANGE, MISSING_DRAW_DEFINITION, MISSING_DRAW_ID, MISSING_DRAW_POSITION, MISSING_DRAW_POSITIONS, MISSING_DRAW_SIZE, MISSING_ENTRIES, MISSING_EVENT, MISSING_MAIN_STRUCTURE, MISSING_MATCHUP, MISSING_MATCHUPS, MISSING_MATCHUP_FORMAT, MISSING_MATCHUP_ID, MISSING_MATCHUP_IDS, MISSING_PARTICIPANT, MISSING_PARTICIPANTS, MISSING_PARTICIPANT_COUNT, MISSING_PARTICIPANT_ID, MISSING_PARTICIPANT_IDS, MISSING_PARTICIPANT_ROLE, MISSING_PENALTY_ID, MISSING_PENALTY_TYPE, MISSING_PERSON_DETAILS, MISSING_POLICY_ATTRIBUTES, MISSING_POLICY_DEFINITION, MISSING_POLICY_TYPE, MISSING_POSITION_ASSIGNMENTS, MISSING_QUALIFIED_PARTICIPANTS, MISSING_ROUND_NUMBER, MISSING_SCHEDULE, MISSING_SCORING_POLICY, MISSING_SEEDCOUNT_THRESHOLDS, MISSING_SEEDING_POLICY, MISSING_SEED_ASSIGNMENTS, MISSING_SET_NUMBER, MISSING_SET_OBJECT, MISSING_SIDE_NUMBER, MISSING_STAGE, MISSING_STRUCTURE, MISSING_STRUCTURES, MISSING_STRUCTURE_ID, MISSING_TARGET_LINK, MISSING_TIE_FORMAT, MISSING_TIME_ITEM, MISSING_TIME_ITEMS, MISSING_TOURNAMENT_ID, MISSING_TOURNAMENT_RECORD, MISSING_TOURNAMENT_RECORDS, MISSING_VALUE, MISSING_VENUE_ID, MODIFICATIONS_FAILED, MUTATION_LOCKED, MUTATION_LOCK_EXISTS, MUTATION_LOCK_NOT_FOUND, NOT_FOUND, NOT_IMPLEMENTED, NO_CANDIDATES, NO_DRAW_POSITIONS_AVAILABLE_FOR_QUALIFIERS, NO_MODIFICATIONS_APPLIED, NO_PARTICIPANTS_GENERATED, NO_PARTICIPANT_REMOVED, NO_STAGE_SPACE_AVAILABLE_FOR_ENTRY_STATUS, NO_VALID_ACTIONS, NO_VALID_ATTRIBUTES, NO_VALID_DATES, PARTICIPANT_COUNT_EXCEEDS_DRAW_SIZE, PARTICIPANT_ENTRY_NOT_FOUND, PARTICIPANT_ID_EXISTS, PARTICIPANT_NOT_CHECKED_IN, PARTICIPANT_NOT_ENTERED_IN_STAGE, PARTICIPANT_NOT_FOUND, PARTICIPANT_NOT_FOUND_IN_STAGE, PARTICIPANT_PAIR_EXISTS, PENALTY_NOT_FOUND, POLICY_NOT_ATTACHED, POLICY_NOT_FOUND, PROPAGATED_EXITS_DOWNSTREAM, REGISTRATION_NOT_FOUND, RESULT_NOT_VALIDATED, SCHEDULED_MATCHUPS, SCHEDULE_CONFLICT_COURT_UNAVAILABLE, SCHEDULE_CONFLICT_DOUBLE_BOOKING, SCHEDULE_LOCKED, SCHEDULE_NOT_CLEARED, SCHEDULE_SCENARIO_EXISTS, SCHEDULE_SCENARIO_NOT_FOUND, SCORES_PRESENT, SEEDSCOUNT_GREATER_THAN_DRAW_SIZE, SHARED_INDIVIDUAL_PARTICIPANT, STAGE_SEQUENCE_LIMIT, STRUCTURE_NOT_FOUND, TEAM_NOT_FOUND, TOURNAMENT_CATEGORY_IN_USE, UNABLE_TO_ASSIGN_COURT, UNAUTHORIZED_LOCK_OPERATION, UNLINKED_STRUCTURES, UNRECOGNIZED_DRAW_TYPE, UNRECOGNIZED_MATCHUP_FORMAT, UNRECOGNIZED_MATCHUP_STATUS, UNSUPPORTED_IN_LEGACY_MODE, UNWRITABLE_SCHEDULE_ATTRIBUTES, VALUE_UNCHANGED, VENUE_EXISTS, VENUE_NOT_FOUND, errorConditionConstants };
1096
+ export { ADDITIONAL_SEEDS_EXHAUSTED, ANACHRONISM, BOOKING_NOT_FOUND, CANNOT_CHANGE_FEED_ELIGIBILITY, CANNOT_CHANGE_OUTCOME, CANNOT_CHANGE_WINNING_SIDE, CANNOT_MODIFY_PARTICIPANT_TYPE, CANNOT_MODIFY_TIEFORMAT, CANNOT_REMOVE_MAIN_STRUCTURE, CANNOT_REMOVE_PARTICIPANTS, CAPACITY_EXCEEDED, CATEGORY_MISMATCH, CONFLICTING_TIME_ZONES, COURT_EXISTS, COURT_NOT_FOUND, DRAW_DEFINITION_NOT_FOUND, DRAW_ID_EXISTS, DRAW_POSITION_ACTIVE, DRAW_POSITION_ASSIGNED, DRAW_POSITION_NOT_CLEARED, DRAW_POSITION_NOT_FOUND, DRAW_POSITION_OCCUPIED, DRAW_SIZE_MISMATCH, DUPLICATE_ENTRY, DUPLICATE_VALUE, ENTRY_STATUS_NOT_ALLOWED_FOR_EVENT, ENTRY_STATUS_NOT_ALLOWED_IN_STAGE, EVENT_EXISTS, EVENT_NOT_FOUND, EXISTING_DRAFT, EXISTING_DRAW_DEFINITIONS, EXISTING_END_TIME, EXISTING_FLIGHT, EXISTING_MATCHUPS, EXISTING_MATCHUP_ID, EXISTING_OUTCOME, EXISTING_PARTICIPANT, EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT, EXISTING_POLICY_TYPE, EXISTING_PROFILE, EXISTING_ROUND, EXISTING_ROUND_PARTICIPANT, EXISTING_STAGE, EXISTING_STRUCTURE, INCOMPATIBLE_MATCHUP_STATUS, INCOMPLETE_SOURCE_STRUCTURE, INSUFFICIENT_DRAW_POSITIONS, INSUFFICIENT_UUIDS, INVALID_ACTION, INVALID_ASSIGNMENT, INVALID_ATTESTATION_SUBJECT, INVALID_ATTRIBUTION, INVALID_BOOKINGS, INVALID_CATEGORY, INVALID_COLLECTION_DEFINITION, INVALID_CONFIGURATION, INVALID_DATE, INVALID_DATE_AVAILABILITY, INVALID_DRAW_DEFINITION, INVALID_DRAW_POSITION, INVALID_DRAW_POSITION_FOR_SEEDING, INVALID_DRAW_SIZE, INVALID_DRAW_TYPE, INVALID_EMBARGO, INVALID_END_TIME, INVALID_ENTRIES, INVALID_ENTRY_STATUS, INVALID_EVENT_TYPE, INVALID_GAME_SCORES, INVALID_GENDER, INVALID_MATCHUP, INVALID_MATCHUP_FORMAT, INVALID_MATCHUP_STATUS, INVALID_MATCHUP_STATUS_BYE, INVALID_OBJECT, INVALID_PARTICIPANT, INVALID_PARTICIPANT_ID, INVALID_PARTICIPANT_IDS, INVALID_PARTICIPANT_ROLE, INVALID_PARTICIPANT_SEEDING, INVALID_PARTICIPANT_TYPE, INVALID_POLICY_DEFINITION, INVALID_RECORDS, INVALID_RESUME_TIME, INVALID_SCALE_ITEM, INVALID_SCORE, INVALID_SEED_NUMBER, INVALID_SEED_POSITION, INVALID_SET_NUMBER, INVALID_SIDE_NUMBER, INVALID_STAGE, INVALID_START_TIME, INVALID_STOP_TIME, INVALID_STRUCTURE, INVALID_TIE_FORMAT, INVALID_TIME, INVALID_TIME_ITEM, INVALID_TIME_ZONE, INVALID_TOURNAMENT_DATES, INVALID_TOURNAMENT_RECORD, INVALID_VALUES, INVALID_WINNING_SIDE, LUCKY_DRAW_BYE_LIMIT, MATCHUPS_COMPLETED_OUTSIDE_DATES, MATCHUPS_SCHEDULED_OUTSIDE_DATES, MATCHUP_HAS_SCHEDULING, MATCHUP_NOT_FOUND, MATCHUP_STATUS_OUT_OF_SCOPE, METHOD_NOT_FOUND, MISSING_ASSIGNMENTS, MISSING_ASYNC_STATE_PROVIDER, MISSING_AVOIDANCE_POLICY, MISSING_BIRTH_DATE, MISSING_COLLECTION_DEFINITION, MISSING_CONTEXT, MISSING_COURTS_INFO, MISSING_COURT_ID, MISSING_DATE, MISSING_DATE_AVAILABILITY, MISSING_DATE_RANGE, MISSING_DRAW_DEFINITION, MISSING_DRAW_ID, MISSING_DRAW_POSITION, MISSING_DRAW_POSITIONS, MISSING_DRAW_SIZE, MISSING_ENTRIES, MISSING_EVENT, MISSING_MAIN_STRUCTURE, MISSING_MATCHUP, MISSING_MATCHUPS, MISSING_MATCHUP_FORMAT, MISSING_MATCHUP_ID, MISSING_MATCHUP_IDS, MISSING_PARTICIPANT, MISSING_PARTICIPANTS, MISSING_PARTICIPANT_COUNT, MISSING_PARTICIPANT_ID, MISSING_PARTICIPANT_IDS, MISSING_PARTICIPANT_ROLE, MISSING_PENALTY_ID, MISSING_PENALTY_TYPE, MISSING_PERSON_DETAILS, MISSING_POLICY_ATTRIBUTES, MISSING_POLICY_DEFINITION, MISSING_POLICY_TYPE, MISSING_POSITION_ASSIGNMENTS, MISSING_QUALIFIED_PARTICIPANTS, MISSING_ROUND_NUMBER, MISSING_SCHEDULE, MISSING_SCORING_POLICY, MISSING_SEEDCOUNT_THRESHOLDS, MISSING_SEEDING_POLICY, MISSING_SEED_ASSIGNMENTS, MISSING_SET_NUMBER, MISSING_SET_OBJECT, MISSING_SIDE_NUMBER, MISSING_STAGE, MISSING_STRUCTURE, MISSING_STRUCTURES, MISSING_STRUCTURE_ID, MISSING_TARGET_LINK, MISSING_TIE_FORMAT, MISSING_TIME_ITEM, MISSING_TIME_ITEMS, MISSING_TOURNAMENT_ID, MISSING_TOURNAMENT_RECORD, MISSING_TOURNAMENT_RECORDS, MISSING_VALUE, MISSING_VENUE_ID, MODIFICATIONS_FAILED, MUTATION_LOCKED, MUTATION_LOCK_EXISTS, MUTATION_LOCK_NOT_FOUND, NOT_FOUND, NOT_IMPLEMENTED, NO_CANDIDATES, NO_DRAW_POSITIONS_AVAILABLE_FOR_QUALIFIERS, NO_MODIFICATIONS_APPLIED, NO_PARTICIPANTS_GENERATED, NO_PARTICIPANT_REMOVED, NO_STAGE_SPACE_AVAILABLE_FOR_ENTRY_STATUS, NO_VALID_ACTIONS, NO_VALID_ATTRIBUTES, NO_VALID_DATES, PARTICIPANT_COUNT_EXCEEDS_DRAW_SIZE, PARTICIPANT_ENTRY_NOT_FOUND, PARTICIPANT_ID_EXISTS, PARTICIPANT_NOT_CHECKED_IN, PARTICIPANT_NOT_ENTERED_IN_STAGE, PARTICIPANT_NOT_FOUND, PARTICIPANT_NOT_FOUND_IN_STAGE, PARTICIPANT_PAIR_EXISTS, PENALTY_NOT_FOUND, POLICY_NOT_ATTACHED, POLICY_NOT_FOUND, PROPAGATED_EXITS_DOWNSTREAM, REGISTRATION_NOT_FOUND, RESULT_NOT_VALIDATED, SCHEDULED_MATCHUPS, SCHEDULE_CONFLICT_COURT_UNAVAILABLE, SCHEDULE_CONFLICT_DOUBLE_BOOKING, SCHEDULE_LOCKED, SCHEDULE_NOT_CLEARED, SCHEDULE_SCENARIO_EXISTS, SCHEDULE_SCENARIO_NOT_FOUND, SCORES_PRESENT, SEEDSCOUNT_GREATER_THAN_DRAW_SIZE, SHARED_INDIVIDUAL_PARTICIPANT, STAGE_SEQUENCE_LIMIT, STRUCTURE_NOT_FOUND, TEAM_NOT_FOUND, TOURNAMENT_CATEGORY_IN_USE, UNABLE_TO_ASSIGN_COURT, UNAUTHORIZED_LOCK_OPERATION, UNLINKED_STRUCTURES, UNRECOGNIZED_DRAW_TYPE, UNRECOGNIZED_MATCHUP_FORMAT, UNRECOGNIZED_MATCHUP_STATUS, UNSUPPORTED_IN_LEGACY_MODE, UNWRITABLE_SCHEDULE_ATTRIBUTES, VALUE_UNCHANGED, VENUE_EXISTS, VENUE_NOT_FOUND, errorConditionConstants };
@@ -24,6 +24,7 @@ export { requestConstants } from './requestConstants.mjs';
24
24
  export { availabilityConstants, dayStateConstants } from './dayStateConstants.mjs';
25
25
  export { resourceContants } from './resourceConstants.mjs';
26
26
  export { resultConstants } from './resultConstants.mjs';
27
+ export { ADDITIONAL_SEED_BASES, seedingBasisConstants } from './seedingConstants.mjs';
27
28
  export { actionMethodConstants } from './actionMethodConstants.mjs';
28
29
  export { bookingTypeConstants } from './bookingTypeConstants.mjs';
29
30
  export { scaleConstants } from './scaleConstants.mjs';
@@ -0,0 +1,6 @@
1
+ const ORGANISER_DISCRETION = 'ORGANISER_DISCRETION';
2
+ const PROTECTED_RANKING = 'PROTECTED_RANKING';
3
+ const RANKING = 'RANKING';
4
+ const RATING = 'RATING';
5
+
6
+ export { ORGANISER_DISCRETION, PROTECTED_RANKING, RANKING, RATING };
@@ -0,0 +1,11 @@
1
+ import { ORGANISER_DISCRETION, PROTECTED_RANKING, RATING, RANKING } from './seedingBasisValues.mjs';
2
+
3
+ const seedingBasisConstants = {
4
+ ORGANISER_DISCRETION,
5
+ PROTECTED_RANKING,
6
+ RANKING,
7
+ RATING,
8
+ };
9
+ const ADDITIONAL_SEED_BASES = [ORGANISER_DISCRETION, PROTECTED_RANKING];
10
+
11
+ export { ADDITIONAL_SEED_BASES, ORGANISER_DISCRETION, PROTECTED_RANKING, RANKING, RATING, seedingBasisConstants };
@@ -38,9 +38,10 @@ export { index$7 as factoryConstants };
38
38
  export { SportEnum } from './types/competitionFormat.mjs';
39
39
  export { AssignmentStatusEnum, CertificationFamilyEnum, CertificationLevelEnum, CertificationStatusEnum, ConflictSeverityEnum, ConflictTypeEnum, EvaluationStatusEnum, OfficialRoleSubtypeEnum, ScoringMethodEnum, ScoringTypeEnum } from './types/officiatingTypes.mjs';
40
40
  export { AmendmentSeverityEnum, AmendmentStatusEnum, ComplianceItemStatusEnum, ComplianceItemTypeEnum, ComplianceStatusEnum, EndorsementStatusEnum, SanctioningRelationshipEnum, SanctioningStatusEnum } from './types/sanctioningTypes.mjs';
41
- export { AddressTypeEnum, AuthorityRoleEnum, BallTypeEnum, BookingTypeEnum, CategoryEnum, ContactRelationshipEnum, CountryCodeEnum, CourtPositionEnum, CurrencyUnitEnum, DisciplineEnum, DrawStatusEnum, DrawTypeEnum, EntryRestrictionEnum, EntryStatusEnum, EventTypeEnum, FinishingPositionEnum, GenderEnum, IndoorOutdoorEnum, LengthUnitEnum, LinkTypeEnum, MatchUpStatusEnum, OnlineResourceTypeEnum, OrganisationTypeEnum, ParticipantRoleEnum, ParticipantStatusEnum, ParticipantTypeEnum, PayloadProfileEnum, PenaltyTypeEnum, PlayingDoubleHandCodeEnum, PlayingHandCodeEnum, PositioningProfileEnum, PracticeRegistrationStatusEnum, RecognitionEnum, SanctionDecisionEnum, SanctionEnforcementEnum, SanctionFeeKindEnum, SeedingProfileEnum, SelectionProcessEnum, SexEnum, ShotDetailEnum, ShotOutcomeEnum, ShotTypeEnum, StageTypeEnum, StructureTypeEnum, SurfaceCategoryEnum, TieScoreSourceEnum, TierMovementEnum, TournamentLevelEnum, TournamentStatusEnum, WeekdayEnum, WeightUnitEnum, WheelchairClassEnum, WinReasonEnum } from './types/tournamentTypes.mjs';
41
+ export { AddressTypeEnum, AuthorityRoleEnum, BallTypeEnum, BookingTypeEnum, CategoryEnum, ContactRelationshipEnum, CountryCodeEnum, CourtPositionEnum, CurrencyUnitEnum, DisciplineEnum, DrawStatusEnum, DrawTypeEnum, EntryRestrictionEnum, EntryStatusEnum, EventTypeEnum, FinishingPositionEnum, GenderEnum, IndoorOutdoorEnum, LengthUnitEnum, LinkTypeEnum, MatchUpStatusEnum, OnlineResourceTypeEnum, OrganisationTypeEnum, ParticipantRoleEnum, ParticipantStatusEnum, ParticipantTypeEnum, PayloadProfileEnum, PenaltyTypeEnum, PlayingDoubleHandCodeEnum, PlayingHandCodeEnum, PositioningProfileEnum, PracticeRegistrationStatusEnum, RecognitionEnum, SanctionDecisionEnum, SanctionEnforcementEnum, SanctionFeeKindEnum, SeedingBasisEnum, SeedingProfileEnum, SelectionProcessEnum, SexEnum, ShotDetailEnum, ShotOutcomeEnum, ShotTypeEnum, StageTypeEnum, StructureTypeEnum, SurfaceCategoryEnum, TieScoreSourceEnum, TierMovementEnum, TournamentLevelEnum, TournamentStatusEnum, WeekdayEnum, WeightUnitEnum, WheelchairClassEnum, WinReasonEnum } from './types/tournamentTypes.mjs';
42
42
  export { toStatObjects } from './query/scoring/statistics/toStatObjects.mjs';
43
43
  export { calculateMatchStatistics } from './query/scoring/statistics/standalone.mjs';
44
+ export { ADDITIONAL_SEED_BASES, seedingBasisConstants } from './constants/seedingConstants.mjs';
44
45
  export { AvailabilityEngine } from './assemblies/engines/availability/AvailabilityEngine.mjs';
45
46
  export { EventNotFoundError, InvalidDateError, InvalidValuesError, MatchUpNotFoundError, MissingDrawDefinitionError, MissingEventError, MissingOfficialRecordError, MissingSanctioningRecordError, MissingTournamentRecordError, MissingTournamentRecordsError, MissingValueError, ParticipantNotFoundError, StructureNotFoundError } from './errors/subclasses.mjs';
46
47
  export { FactoryError } from './errors/FactoryError.mjs';
@@ -0,0 +1,62 @@
1
+ import { getAdditionalSeedsAllowance } from '../../../query/drawDefinition/getAdditionalSeedsAllowance.mjs';
2
+ import { participantInEntries } from '../../../query/drawDefinition/entryGetter.mjs';
3
+ import { assignSeed } from './seedAssignment.mjs';
4
+ import { decorateResult } from '../../../functions/global/decorateResult.mjs';
5
+ import { findStructure } from '../../../acquire/findStructure.mjs';
6
+ import { SUCCESS } from '../../../constants/resultConstants.mjs';
7
+ import { STRUCTURE_NOT_FOUND, INVALID_PARTICIPANT_ID, SEEDSCOUNT_GREATER_THAN_DRAW_SIZE, ADDITIONAL_SEEDS_EXHAUSTED } from '../../../constants/errorConditionConstants.mjs';
8
+
9
+ function addAdditionalSeed(params) {
10
+ const { tournamentRecord, drawDefinition, seedingProfile, participantId, structureId, eventId, event } = params;
11
+ const stack = 'addAdditionalSeed';
12
+ const { structure } = findStructure({ drawDefinition, structureId });
13
+ if (!structure)
14
+ return { error: STRUCTURE_NOT_FOUND };
15
+ if (!participantId || !participantInEntries({ drawDefinition, participantId }))
16
+ return decorateResult({ result: { error: INVALID_PARTICIPANT_ID }, context: { participantId }, stack });
17
+ const allowance = getAdditionalSeedsAllowance({
18
+ participantsCount: params.participantsCount,
19
+ tournamentRecord,
20
+ drawDefinition,
21
+ structureId,
22
+ event,
23
+ });
24
+ if (allowance.error)
25
+ return allowance;
26
+ const { additionalSeedsRemaining = 0, thresholdSeedsCount = 0, seedLimit = 0, drawSize = 0 } = allowance;
27
+ const seedNumber = seedLimit + 1;
28
+ if (seedNumber > drawSize)
29
+ return decorateResult({
30
+ result: { error: SEEDSCOUNT_GREATER_THAN_DRAW_SIZE },
31
+ context: { seedNumber, drawSize },
32
+ stack,
33
+ });
34
+ const isAdditional = seedNumber > thresholdSeedsCount;
35
+ if (isAdditional && additionalSeedsRemaining < 1)
36
+ return decorateResult({
37
+ result: { error: ADDITIONAL_SEEDS_EXHAUSTED },
38
+ context: { seedNumber, thresholdSeedsCount, ...allowance },
39
+ stack,
40
+ });
41
+ structure.seedLimit = seedNumber;
42
+ const result = assignSeed({
43
+ seedValue: params.seedValue ?? seedNumber,
44
+ seedingBasis: params.seedingBasis,
45
+ tournamentRecord,
46
+ drawDefinition,
47
+ seedingProfile,
48
+ participantId,
49
+ structureId,
50
+ seedNumber,
51
+ eventId,
52
+ event,
53
+ });
54
+ if (result?.error) {
55
+ structure.seedLimit = seedLimit;
56
+ structure.seedAssignments = (structure.seedAssignments ?? []).filter((assignment) => assignment.seedNumber !== seedNumber);
57
+ return result;
58
+ }
59
+ return { ...SUCCESS, seedNumber };
60
+ }
61
+
62
+ export { addAdditionalSeed };
@@ -9,7 +9,7 @@ import { findStructure } from '../../../acquire/findStructure.mjs';
9
9
  import { SUCCESS } from '../../../constants/resultConstants.mjs';
10
10
  import { INVALID_PARTICIPANT_ID, INVALID_DRAW_POSITION_FOR_SEEDING, INVALID_SEED_NUMBER } from '../../../constants/errorConditionConstants.mjs';
11
11
 
12
- function assignSeed({ provisionalPositioning, tournamentRecord, drawDefinition, seedingProfile, participantId, seedBlockInfo, structureId, seedNumber, seedValue, eventId, event, }) {
12
+ function assignSeed({ provisionalPositioning, tournamentRecord, drawDefinition, seedingProfile, participantId, seedBlockInfo, structureId, seedingBasis, seedNumber, seedValue, eventId, event, }) {
13
13
  const stack = 'assignSeed';
14
14
  const { structure } = findStructure({ drawDefinition, structureId });
15
15
  const { positionAssignments } = structureAssignedDrawPositions({ structure });
@@ -50,7 +50,7 @@ function assignSeed({ provisionalPositioning, tournamentRecord, drawDefinition,
50
50
  });
51
51
  }
52
52
  if (!seedNumbers.includes(seedNumber)) {
53
- seedAssignments.push({ seedNumber, seedValue });
53
+ seedAssignments.push({ seedNumber, seedValue, seedingBasis });
54
54
  }
55
55
  let success;
56
56
  seedAssignments.forEach((assignment) => {
@@ -61,6 +61,8 @@ function assignSeed({ provisionalPositioning, tournamentRecord, drawDefinition,
61
61
  assignment.participantId = participantId;
62
62
  if (!seedingProfile?.groupSeedingThreshold && !flighted)
63
63
  assignment.seedValue = seedValue ?? seedNumber;
64
+ if (seedingBasis)
65
+ assignment.seedingBasis = seedingBasis;
64
66
  success = true;
65
67
  }
66
68
  });
@@ -27,15 +27,16 @@ function initializeStructureSeedAssignments({ requireParticipantCount = true, en
27
27
  roundRobinGroupsCount,
28
28
  drawSize,
29
29
  })?.seedGroups;
30
- const { seedsCount: maxSeedsCount } = getSeedsCount({
30
+ const { seedsCount: maxSeedsCount, additionalSeedsAllowed = 0 } = getSeedsCount({
31
31
  policyDefinitions: appliedPolicies,
32
32
  requireParticipantCount,
33
33
  drawSizeProgression,
34
34
  participantsCount,
35
35
  drawSize,
36
36
  });
37
- if (maxSeedsCount && appliedPolicies?.[POLICY_TYPE_SEEDING] && seedsCount > maxSeedsCount && enforcePolicyLimits) {
38
- seedsCount = maxSeedsCount;
37
+ const policyCeiling = maxSeedsCount ? maxSeedsCount + additionalSeedsAllowed : 0;
38
+ if (policyCeiling && appliedPolicies?.[POLICY_TYPE_SEEDING] && seedsCount > policyCeiling && enforcePolicyLimits) {
39
+ seedsCount = policyCeiling;
39
40
  }
40
41
  structure.seedLimit = seedsCount;
41
42
  structure.seedAssignments = generateRange(1, seedsCount + 1).map((seedNumber) => {
@@ -16,6 +16,7 @@ import { assignSeed } from '../../drawDefinitions/entryGovernor/seedAssignment.m
16
16
  import { getAllStructureMatchUps } from '../../../query/matchUps/getAllStructureMatchUps.mjs';
17
17
  import { getInitialRoundNumber } from '../../../query/matchUps/getInitialRoundNumber.mjs';
18
18
  import { updateSideLineUp } from '../lineUps/updateSideLineUp.mjs';
19
+ import { isUnscoredOutcome } from '../../../query/matchUp/getDrawPositionWinCount.mjs';
19
20
  import { isLuckyBasedDraw } from '../../../query/drawDefinition/isLuckyBasedDraw.mjs';
20
21
  import { getAppliedPolicies } from '../../../query/extensions/getAppliedPolicies.mjs';
21
22
  import { isValidSeedPosition } from '../../../query/drawDefinition/seedGetter.mjs';
@@ -38,7 +39,7 @@ import { isExit } from '../../../validators/isExit.mjs';
38
39
  import { overlap } from '../../../tools/arrays.mjs';
39
40
  import { CONTAINER, MAIN, CONSOLATION, PLAY_OFF, QUALIFYING, FIRST_MATCHUP } from '../../../constants/drawDefinitionConstants.mjs';
40
41
  import { MISSING_PARTICIPANT_ID, STRUCTURE_NOT_FOUND, INVALID_MATCHUP, INVALID_DRAW_POSITION_FOR_SEEDING, INVALID_DRAW_POSITION, EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT, DRAW_POSITION_ACTIVE, DRAW_POSITION_ASSIGNED } from '../../../constants/errorConditionConstants.mjs';
41
- import { BYE, TO_BE_PLAYED, DOUBLE_WALKOVER, DOUBLE_DEFAULT, COMPLETED, RETIRED } from '../../../constants/matchUpStatusValues.mjs';
42
+ import { BYE, TO_BE_PLAYED, DOUBLE_WALKOVER, DOUBLE_DEFAULT } from '../../../constants/matchUpStatusValues.mjs';
42
43
 
43
44
  function assignMatchUpDrawPosition({ inContextDrawMatchUps, sourceMatchUpStatus, tournamentRecord, sourceMatchUpId, drawDefinition, matchUpStatus, drawPosition, matchUpsMap, matchUpId, event, }) {
44
45
  const stack = 'assignMatchUpDrawPosition';
@@ -347,7 +348,7 @@ function propagateConsolationBye({ updatedDrawPositions, loserTargetDrawPosition
347
348
  matchUpsMap,
348
349
  });
349
350
  const firstRoundMatchUps = structureMatchUps.filter(({ drawPositions, roundNumber }) => roundNumber === 1 && overlap(drawPositions, updatedDrawPositions));
350
- const byePropagation = firstRoundMatchUps.every(({ matchUpStatus }) => [COMPLETED, RETIRED].includes(matchUpStatus));
351
+ const byePropagation = firstRoundMatchUps.every(({ matchUpStatus, winningSide, score }) => !!winningSide && !isUnscoredOutcome({ matchUpStatus, score }));
351
352
  if (byePropagation && loserMatchUp) {
352
353
  const { structureId } = loserMatchUp;
353
354
  const result = assignDrawPositionBye({
@@ -6,7 +6,7 @@ import { findStructure } from '../../../acquire/findStructure.mjs';
6
6
  import { MATCHUP_FORMAT, DRAW_DEFINITION } from '../../../constants/attributeConstants.mjs';
7
7
  import { SUCCESS } from '../../../constants/resultConstants.mjs';
8
8
  import { TEAM } from '../../../constants/eventConstants.mjs';
9
- import { UNRECOGNIZED_MATCHUP_FORMAT, INVALID_MATCHUP, INVALID_EVENT_TYPE } from '../../../constants/errorConditionConstants.mjs';
9
+ import { UNRECOGNIZED_MATCHUP_FORMAT, INVALID_EVENT_TYPE, INVALID_MATCHUP } from '../../../constants/errorConditionConstants.mjs';
10
10
 
11
11
  function applyMatchUpFormat(params) {
12
12
  let structureIds = params.structureIds;
@@ -18,19 +18,10 @@ function applyMatchUpFormat(params) {
18
18
  return { error: UNRECOGNIZED_MATCHUP_FORMAT };
19
19
  const stack = 'setMatchUpFormat';
20
20
  if (matchUpId) {
21
- const result = findDrawMatchUp({
22
- drawDefinition,
23
- matchUpId,
24
- event,
25
- });
26
- if (result.error)
27
- return result;
28
- const matchUp = result.matchUp;
29
- if (matchUp?.matchUpType === TEAM)
30
- return {
31
- info: 'Cannot set matchUpFormat when { matchUpType: TEAM }',
32
- error: INVALID_MATCHUP,
33
- };
21
+ const check = checkMatchUpFormatApplication({ drawDefinition, matchUpFormat, matchUpId, event });
22
+ if (check.error)
23
+ return check;
24
+ const matchUp = check.matchUp;
34
25
  if (matchUp) {
35
26
  matchUp.matchUpFormat = matchUpFormat;
36
27
  modifyMatchUpNotice({
@@ -70,5 +61,19 @@ function applyMatchUpFormat(params) {
70
61
  modifyDrawNotice({ drawDefinition, structureIds });
71
62
  return { ...SUCCESS };
72
63
  }
64
+ function checkMatchUpFormatApplication(params) {
65
+ const { drawDefinition, matchUpFormat, matchUpId, event } = params;
66
+ if (!isValidMatchUpFormat({ matchUpFormat }))
67
+ return { error: UNRECOGNIZED_MATCHUP_FORMAT };
68
+ const result = findDrawMatchUp({ drawDefinition, matchUpId, event });
69
+ if (result.error)
70
+ return { error: result.error };
71
+ if (result.matchUp?.matchUpType === TEAM)
72
+ return {
73
+ info: 'Cannot set matchUpFormat when { matchUpType: TEAM }',
74
+ error: INVALID_MATCHUP,
75
+ };
76
+ return { matchUp: result.matchUp };
77
+ }
73
78
 
74
- export { applyMatchUpFormat };
79
+ export { applyMatchUpFormat, checkMatchUpFormatApplication };
@@ -70,6 +70,7 @@ function setMatchUpState(params) {
70
70
  if (revertError)
71
71
  return revertError;
72
72
  const impliedCompletionError = checkImpliedCompletionGuard({
73
+ incomingMatchUpFormat: params.matchUpFormat,
73
74
  matchUpStatus,
74
75
  winningSide,
75
76
  score,
@@ -129,7 +130,11 @@ function setMatchUpState(params) {
129
130
  };
130
131
  }
131
132
  if (score && !isTeam && !disableScoreValidation) {
132
- const matchUpFormat = matchUp.matchUpFormat ?? structure?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
133
+ const matchUpFormat = params.matchUpFormat ??
134
+ matchUp.matchUpFormat ??
135
+ structure?.matchUpFormat ??
136
+ drawDefinition?.matchUpFormat ??
137
+ event?.matchUpFormat;
133
138
  const result = validateScore({
134
139
  existingMatchUpStatus: matchUp.matchUpStatus,
135
140
  matchUpFormat,
@@ -241,7 +246,7 @@ function checkCompletedRevertGuard({ matchUp, matchUpStatus, winningSide, score,
241
246
  stack: 'setMatchUpStatus',
242
247
  });
243
248
  }
244
- function checkImpliedCompletionGuard({ matchUpStatus, winningSide, score, isTeam, matchUp, structure, drawDefinition, event, }) {
249
+ function checkImpliedCompletionGuard({ incomingMatchUpFormat, matchUpStatus, winningSide, score, isTeam, matchUp, structure, drawDefinition, event, }) {
245
250
  if (isTeam || !matchUpStatus || !REVERT_GUARDED_STATUSES.has(matchUpStatus))
246
251
  return undefined;
247
252
  if (!winningSide && !checkScoreHasValue({ score }))
@@ -254,7 +259,11 @@ function checkImpliedCompletionGuard({ matchUpStatus, winningSide, score, isTeam
254
259
  stack: 'setMatchUpStatus',
255
260
  });
256
261
  }
257
- const matchUpFormat = matchUp?.matchUpFormat ?? structure?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event?.matchUpFormat;
262
+ const matchUpFormat = incomingMatchUpFormat ??
263
+ matchUp?.matchUpFormat ??
264
+ structure?.matchUpFormat ??
265
+ drawDefinition?.matchUpFormat ??
266
+ event?.matchUpFormat;
258
267
  if (!matchUpFormat)
259
268
  return undefined;
260
269
  const { calculatedWinningSide } = analyzeMatchUp({ matchUp: { score, matchUpFormat }, matchUpFormat });
@@ -354,17 +363,17 @@ function resolveAndApplyOutcome({ params, isTeam, dualWinningSideChange, activeD
354
363
  const { allowChangePropagation, tournamentRecords, tournamentRecord, drawDefinition, winningSide, matchUpId, matchUpTieId, matchUp, } = params;
355
364
  const { schedule } = params;
356
365
  if (schedule) {
357
- const result = addMatchUpScheduleItems({
366
+ const check = addMatchUpScheduleItems({
358
367
  disableNotice: true,
368
+ validateOnly: true,
359
369
  tournamentRecords,
360
370
  tournamentRecord,
361
371
  drawDefinition,
362
372
  matchUpId,
363
373
  schedule,
364
374
  });
365
- if (result.error) {
366
- return result;
367
- }
375
+ if (check.error)
376
+ return check;
368
377
  }
369
378
  const validWinningSideSwap = !isTeam && !dualWinningSideChange && winningSide && matchUp.winningSide && matchUp.winningSide !== winningSide;
370
379
  if (allowChangePropagation && validWinningSideSwap && matchUp.roundPosition) {
@@ -392,6 +401,18 @@ function resolveAndApplyOutcome({ params, isTeam, dualWinningSideChange, activeD
392
401
  else {
393
402
  result = { error: NO_VALID_ACTIONS };
394
403
  }
404
+ if (!result?.error && schedule) {
405
+ const scheduleResult = addMatchUpScheduleItems({
406
+ disableNotice: true,
407
+ tournamentRecords,
408
+ tournamentRecord,
409
+ drawDefinition,
410
+ matchUpId,
411
+ schedule,
412
+ });
413
+ if (scheduleResult.error)
414
+ return decorateResult({ result: scheduleResult, stack });
415
+ }
395
416
  if (!result?.error)
396
417
  applyScoredTime({ matchUp });
397
418
  return decorateResult({ result, stack });