tods-competition-factory 1.6.19 → 1.6.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/forge/generate.mjs +161 -87
- package/dist/forge/generate.mjs.map +1 -1
- package/dist/forge/query.d.ts +1 -1
- package/dist/forge/query.mjs +33 -36
- package/dist/forge/query.mjs.map +1 -1
- package/dist/forge/transform.mjs +132 -40
- package/dist/forge/transform.mjs.map +1 -1
- package/dist/index.mjs +149 -126
- package/dist/index.mjs.map +1 -1
- package/dist/tods-competition-factory.development.cjs.js +149 -132
- package/dist/tods-competition-factory.development.cjs.js.map +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js.map +1 -1
- package/package.json +1 -1
package/dist/forge/transform.mjs
CHANGED
|
@@ -3617,6 +3617,7 @@ function getInContextCourt({
|
|
|
3617
3617
|
return { inContextCourt };
|
|
3618
3618
|
}
|
|
3619
3619
|
|
|
3620
|
+
const ADD_DRAW_DEFINITION = "addDrawDefinition";
|
|
3620
3621
|
const ADD_VENUE = "addVenue";
|
|
3621
3622
|
const MODIFY_DRAW_DEFINITION = "modifyDrawDefinition";
|
|
3622
3623
|
const MODIFY_MATCHUP = "modifyMatchUp";
|
|
@@ -4470,15 +4471,15 @@ function getRoundMatchUps({
|
|
|
4470
4471
|
roundIndex += 1;
|
|
4471
4472
|
}
|
|
4472
4473
|
});
|
|
4473
|
-
const
|
|
4474
|
+
const roundsNotPowerOf2 = !!Object.values(roundProfile).find(
|
|
4474
4475
|
({ matchUpsCount }) => !isPowerOf2(matchUpsCount)
|
|
4475
4476
|
);
|
|
4476
4477
|
const hasNoRoundPositions = matchUps.some(
|
|
4477
4478
|
(matchUp) => !matchUp.roundPosition
|
|
4478
4479
|
);
|
|
4479
4480
|
return {
|
|
4480
|
-
isNotEliminationStructure,
|
|
4481
4481
|
hasNoRoundPositions,
|
|
4482
|
+
roundsNotPowerOf2,
|
|
4482
4483
|
maxMatchUpsCount,
|
|
4483
4484
|
roundMatchUps,
|
|
4484
4485
|
roundNumbers,
|
|
@@ -5505,31 +5506,28 @@ function filterMatchUps(params) {
|
|
|
5505
5506
|
}
|
|
5506
5507
|
|
|
5507
5508
|
function isLucky({
|
|
5508
|
-
|
|
5509
|
+
roundsNotPowerOf2,
|
|
5509
5510
|
drawDefinition,
|
|
5510
|
-
|
|
5511
|
-
|
|
5511
|
+
structure,
|
|
5512
|
+
matchUps
|
|
5512
5513
|
}) {
|
|
5513
5514
|
if (!structure)
|
|
5514
5515
|
return false;
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
}
|
|
5520
|
-
const hasFirstRoundDrawPositions = !!roundMatchUps?.[1]?.find(
|
|
5521
|
-
({ drawPositions }) => drawPositions
|
|
5522
|
-
);
|
|
5523
|
-
const noSecondRoundDrawPositions = !roundMatchUps?.[2]?.find(
|
|
5524
|
-
({ drawPositions }) => drawPositions
|
|
5525
|
-
);
|
|
5526
|
-
return isNotEliminationStructure && !structure?.structures && hasFirstRoundDrawPositions && noSecondRoundDrawPositions && !(drawDefinition?.drawType && drawDefinition.drawType !== LUCKY_DRAW);
|
|
5516
|
+
matchUps = matchUps ?? structure.matchUps ?? [];
|
|
5517
|
+
roundsNotPowerOf2 = roundsNotPowerOf2 ?? getRoundMatchUps({ matchUps }).roundsNotPowerOf2;
|
|
5518
|
+
const hasDrawPositions = !!structure.positionAssignments?.find(({ drawPosition }) => drawPosition) || !!matchUps?.find(({ drawPositions }) => drawPositions?.length);
|
|
5519
|
+
return (!drawDefinition?.drawType || drawDefinition.drawType !== LUCKY_DRAW) && !structure?.structures && roundsNotPowerOf2 && hasDrawPositions;
|
|
5527
5520
|
}
|
|
5528
5521
|
|
|
5529
5522
|
function isAdHoc({ drawDefinition, structure }) {
|
|
5530
5523
|
if (!structure)
|
|
5531
5524
|
return false;
|
|
5532
|
-
|
|
5525
|
+
const matchUps = structure.matchUps || structure.roundMatchUps && Object.values(structure.roundMatchUps).flat();
|
|
5526
|
+
const hasRoundPosition = matchUps?.find((matchUp) => matchUp?.roundPosition);
|
|
5527
|
+
const hasDrawPosition = matchUps?.find(
|
|
5528
|
+
(matchUp) => matchUp?.drawPositions?.length
|
|
5529
|
+
);
|
|
5530
|
+
return !structure?.structures && !(drawDefinition?.drawType && drawDefinition.drawType !== AD_HOC) && !hasRoundPosition && !hasDrawPosition;
|
|
5533
5531
|
}
|
|
5534
5532
|
|
|
5535
5533
|
const POLICY_ROUND_NAMING_DEFAULT = {
|
|
@@ -5564,14 +5562,10 @@ function getRoundContextProfile({
|
|
|
5564
5562
|
structure,
|
|
5565
5563
|
matchUps
|
|
5566
5564
|
}) {
|
|
5567
|
-
const {
|
|
5565
|
+
const { roundProfile, roundMatchUps } = getRoundMatchUps({ matchUps });
|
|
5568
5566
|
const { structureAbbreviation, stage } = structure;
|
|
5569
5567
|
const isAdHocStructure = isAdHoc({ structure });
|
|
5570
|
-
const isLuckyStructure = isLucky({
|
|
5571
|
-
isNotEliminationStructure,
|
|
5572
|
-
roundMatchUps,
|
|
5573
|
-
structure
|
|
5574
|
-
});
|
|
5568
|
+
const isLuckyStructure = isLucky({ structure });
|
|
5575
5569
|
const isRoundRobin = structure.structures;
|
|
5576
5570
|
const roundNamingProfile = {};
|
|
5577
5571
|
const defaultRoundNamingPolicy = POLICY_ROUND_NAMING_DEFAULT[POLICY_TYPE_ROUND_NAMING];
|
|
@@ -5805,8 +5799,8 @@ function getAllStructureMatchUps({
|
|
|
5805
5799
|
matchUpsMap,
|
|
5806
5800
|
structureId
|
|
5807
5801
|
}).drawPositionsRanges : void 0;
|
|
5808
|
-
matchUps = matchUps.map(
|
|
5809
|
-
|
|
5802
|
+
matchUps = matchUps.map((matchUp) => {
|
|
5803
|
+
return addMatchUpContext({
|
|
5810
5804
|
scheduleVisibilityFilters,
|
|
5811
5805
|
sourceDrawPositionRanges,
|
|
5812
5806
|
drawPositionsRanges,
|
|
@@ -5817,8 +5811,8 @@ function getAllStructureMatchUps({
|
|
|
5817
5811
|
roundProfile,
|
|
5818
5812
|
matchUp,
|
|
5819
5813
|
event
|
|
5820
|
-
})
|
|
5821
|
-
);
|
|
5814
|
+
});
|
|
5815
|
+
});
|
|
5822
5816
|
const matchUpTies = matchUps?.filter(
|
|
5823
5817
|
(matchUp) => Array.isArray(matchUp.tieMatchUps)
|
|
5824
5818
|
);
|
|
@@ -7480,6 +7474,23 @@ function updateInContextMatchUp({ tournamentId, inContextMatchUp }) {
|
|
|
7480
7474
|
});
|
|
7481
7475
|
return { ...SUCCESS };
|
|
7482
7476
|
}
|
|
7477
|
+
function addDrawNotice({
|
|
7478
|
+
tournamentId,
|
|
7479
|
+
eventId,
|
|
7480
|
+
drawDefinition
|
|
7481
|
+
}) {
|
|
7482
|
+
if (!drawDefinition) {
|
|
7483
|
+
console.log(MISSING_DRAW_DEFINITION);
|
|
7484
|
+
return { error: MISSING_DRAW_DEFINITION };
|
|
7485
|
+
}
|
|
7486
|
+
drawUpdatedAt(drawDefinition);
|
|
7487
|
+
addNotice({
|
|
7488
|
+
payload: { drawDefinition, tournamentId, eventId },
|
|
7489
|
+
topic: ADD_DRAW_DEFINITION,
|
|
7490
|
+
key: drawDefinition.drawId
|
|
7491
|
+
});
|
|
7492
|
+
return { ...SUCCESS };
|
|
7493
|
+
}
|
|
7483
7494
|
function modifyDrawNotice({
|
|
7484
7495
|
drawDefinition,
|
|
7485
7496
|
tournamentId,
|
|
@@ -13097,7 +13108,7 @@ function getValidSeedBlocks({
|
|
|
13097
13108
|
let validSeedBlocks = [];
|
|
13098
13109
|
if (!structure)
|
|
13099
13110
|
return { error: MISSING_STRUCTURE };
|
|
13100
|
-
const { roundMatchUps } = getAllStructureMatchUps({
|
|
13111
|
+
const { matchUps, roundMatchUps } = getAllStructureMatchUps({
|
|
13101
13112
|
matchUpFilters: { roundNumbers: [1] },
|
|
13102
13113
|
provisionalPositioning,
|
|
13103
13114
|
structure
|
|
@@ -13130,12 +13141,16 @@ function getValidSeedBlocks({
|
|
|
13130
13141
|
const { stage, structureType, roundLimit } = structure;
|
|
13131
13142
|
const isContainer = structureType === CONTAINER;
|
|
13132
13143
|
const isFeedIn = !isContainer && uniqueDrawPositionsByRound?.length;
|
|
13133
|
-
const isLucky = firstRoundDrawPositions?.length && !isPowerOf2(baseDrawSize);
|
|
13134
13144
|
const qualifyingBlocks = !isContainer && stage === QUALIFYING && roundLimit;
|
|
13135
13145
|
const fedSeedBlockPositions = seedRangeDrawPositionBlocks.flat(Infinity);
|
|
13136
13146
|
const fedSeedNumberOffset = isFeedIn ? fedSeedBlockPositions?.length : 0;
|
|
13137
13147
|
const countLimit = allPositions ? positionsCount : seedsCount;
|
|
13138
|
-
const
|
|
13148
|
+
const isLuckyStructure = isLucky({
|
|
13149
|
+
drawDefinition,
|
|
13150
|
+
structure,
|
|
13151
|
+
matchUps
|
|
13152
|
+
});
|
|
13153
|
+
const firstRoundSeedsCount = isLuckyStructure ? 0 : !isFeedIn && countLimit || countLimit && fedSeedBlockPositions.length < countLimit && countLimit - fedSeedBlockPositions.length || 0;
|
|
13139
13154
|
if (qualifyingBlocks) {
|
|
13140
13155
|
const seedingBlocksCount = structure?.matchUps ? structure.matchUps.filter(
|
|
13141
13156
|
({ roundNumber }) => roundNumber === structure.roundLimit
|
|
@@ -13171,14 +13186,14 @@ function getValidSeedBlocks({
|
|
|
13171
13186
|
validSeedBlocks = seedRangeDrawPositionBlocks.map((block) => {
|
|
13172
13187
|
return { seedNumbers: block, drawPositions: block };
|
|
13173
13188
|
});
|
|
13174
|
-
} else if (
|
|
13189
|
+
} else if (isLuckyStructure) {
|
|
13175
13190
|
const blocks = chunkArray(firstRoundDrawPositions, 2).map((block, i) => ({
|
|
13176
13191
|
drawPositions: [block[0]],
|
|
13177
13192
|
seedNumbers: [i + 1]
|
|
13178
13193
|
}));
|
|
13179
13194
|
blocks.forEach((block) => validSeedBlocks.push(block));
|
|
13180
13195
|
}
|
|
13181
|
-
if (!isContainer && !
|
|
13196
|
+
if (!isContainer && !isLuckyStructure && !qualifyingBlocks) {
|
|
13182
13197
|
const { blocks } = constructPower2Blocks({
|
|
13183
13198
|
drawPositionOffset: firstRoundDrawPositionOffset,
|
|
13184
13199
|
seedNumberOffset: fedSeedNumberOffset,
|
|
@@ -13197,7 +13212,7 @@ function getValidSeedBlocks({
|
|
|
13197
13212
|
},
|
|
13198
13213
|
true
|
|
13199
13214
|
);
|
|
13200
|
-
if (!
|
|
13215
|
+
if (!isLuckyStructure && !isFeedIn && !isContainer && !validSeedPositions) {
|
|
13201
13216
|
return {
|
|
13202
13217
|
error: INVALID_SEED_POSITION,
|
|
13203
13218
|
validSeedBlocks: [],
|
|
@@ -13206,10 +13221,10 @@ function getValidSeedBlocks({
|
|
|
13206
13221
|
};
|
|
13207
13222
|
}
|
|
13208
13223
|
return {
|
|
13224
|
+
isLuckyStructure,
|
|
13209
13225
|
validSeedBlocks,
|
|
13210
13226
|
isContainer,
|
|
13211
|
-
isFeedIn
|
|
13212
|
-
isLucky
|
|
13227
|
+
isFeedIn
|
|
13213
13228
|
};
|
|
13214
13229
|
}
|
|
13215
13230
|
function getContainerBlocks({ seedingProfile, structure }) {
|
|
@@ -13453,6 +13468,75 @@ function getTargetMatchUps({
|
|
|
13453
13468
|
return { drawPositions, matchUps, targetMatchUps };
|
|
13454
13469
|
}
|
|
13455
13470
|
|
|
13471
|
+
function validateLineUp({ lineUp, tieFormat }) {
|
|
13472
|
+
const errors = [];
|
|
13473
|
+
if (!Array.isArray(lineUp)) {
|
|
13474
|
+
errors.push(mustBeAnArray("lineUp"));
|
|
13475
|
+
return { valid: false, errors, error: INVALID_VALUES };
|
|
13476
|
+
}
|
|
13477
|
+
const validItems = lineUp.every((item) => {
|
|
13478
|
+
if (typeof item !== "object") {
|
|
13479
|
+
errors.push(`lineUp entries must be objects`);
|
|
13480
|
+
return false;
|
|
13481
|
+
}
|
|
13482
|
+
const { participantId, collectionAssignments } = item;
|
|
13483
|
+
if (!participantId) {
|
|
13484
|
+
errors.push("Missing participantId");
|
|
13485
|
+
return false;
|
|
13486
|
+
}
|
|
13487
|
+
if (typeof participantId !== "string") {
|
|
13488
|
+
errors.push("participantIds must be strings");
|
|
13489
|
+
return false;
|
|
13490
|
+
}
|
|
13491
|
+
if (!Array.isArray(collectionAssignments)) {
|
|
13492
|
+
errors.push(mustBeAnArray("collectionAssignments"));
|
|
13493
|
+
return false;
|
|
13494
|
+
}
|
|
13495
|
+
return collectionAssignments.every((collectionAssignment) => {
|
|
13496
|
+
if (typeof collectionAssignment !== "object") {
|
|
13497
|
+
errors.push("collectionAssignments must be objects");
|
|
13498
|
+
return false;
|
|
13499
|
+
}
|
|
13500
|
+
const { collectionPosition } = collectionAssignment;
|
|
13501
|
+
if (typeof collectionPosition !== "number") {
|
|
13502
|
+
errors.push("collectionPosition must be a number");
|
|
13503
|
+
return false;
|
|
13504
|
+
}
|
|
13505
|
+
return true;
|
|
13506
|
+
});
|
|
13507
|
+
});
|
|
13508
|
+
const noDuplicates = unique(lineUp.map(getParticipantId)).length === lineUp.length;
|
|
13509
|
+
if (!noDuplicates)
|
|
13510
|
+
errors.push("Duplicated participantId(s)");
|
|
13511
|
+
const valid = validItems && noDuplicates;
|
|
13512
|
+
return { valid, errors, error: errors.length ? INVALID_VALUES : void 0 };
|
|
13513
|
+
}
|
|
13514
|
+
|
|
13515
|
+
function updateTeamLineUp({
|
|
13516
|
+
drawDefinition,
|
|
13517
|
+
participantId,
|
|
13518
|
+
tieFormat,
|
|
13519
|
+
lineUp
|
|
13520
|
+
}) {
|
|
13521
|
+
if (typeof drawDefinition !== "object")
|
|
13522
|
+
return { error: MISSING_DRAW_DEFINITION };
|
|
13523
|
+
if (typeof participantId !== "string")
|
|
13524
|
+
return { error: MISSING_PARTICIPANT_ID };
|
|
13525
|
+
const validation = validateLineUp({ lineUp, tieFormat });
|
|
13526
|
+
if (!validation.valid)
|
|
13527
|
+
return validation;
|
|
13528
|
+
const { extension: existingExtension } = findExtension({
|
|
13529
|
+
element: drawDefinition,
|
|
13530
|
+
name: LINEUPS
|
|
13531
|
+
});
|
|
13532
|
+
const value = existingExtension?.value || {};
|
|
13533
|
+
value[participantId] = removeLineUpSubstitutions({ lineUp });
|
|
13534
|
+
const extension = { name: LINEUPS, value };
|
|
13535
|
+
addExtension$1({ element: drawDefinition, extension });
|
|
13536
|
+
addDrawNotice({ drawDefinition });
|
|
13537
|
+
return { ...SUCCESS };
|
|
13538
|
+
}
|
|
13539
|
+
|
|
13456
13540
|
function resetLineUps({
|
|
13457
13541
|
inContextDrawMatchUps,
|
|
13458
13542
|
inheritance = true,
|
|
@@ -13480,10 +13564,18 @@ function resetLineUps({
|
|
|
13480
13564
|
({ matchUpId }) => matchUpId === inContextMatchUp.matchUpId
|
|
13481
13565
|
);
|
|
13482
13566
|
if (matchUp?.sides?.[sideIndex]) {
|
|
13483
|
-
|
|
13484
|
-
|
|
13485
|
-
|
|
13486
|
-
|
|
13567
|
+
delete matchUp.sides[sideIndex].lineUp;
|
|
13568
|
+
if (inheritance === false) {
|
|
13569
|
+
const tieFormat = inContextMatchUp.tieFormat;
|
|
13570
|
+
const participantId = side.participantId;
|
|
13571
|
+
if (tieFormat && participantId) {
|
|
13572
|
+
updateTeamLineUp({
|
|
13573
|
+
drawDefinition,
|
|
13574
|
+
participantId,
|
|
13575
|
+
lineUp: [],
|
|
13576
|
+
tieFormat
|
|
13577
|
+
});
|
|
13578
|
+
}
|
|
13487
13579
|
}
|
|
13488
13580
|
modifyMatchUpNotice({
|
|
13489
13581
|
tournamentId: tournamentRecord?.tournamentId,
|