tods-competition-factory 1.6.26 → 1.6.28
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.d.ts +1 -0
- package/dist/forge/generate.mjs +39 -31
- package/dist/forge/generate.mjs.map +1 -1
- package/dist/forge/query.mjs +2 -1
- package/dist/forge/query.mjs.map +1 -1
- package/dist/forge/transform.mjs +28 -19
- package/dist/forge/transform.mjs.map +1 -1
- package/dist/index.mjs +60 -39
- package/dist/index.mjs.map +1 -1
- package/dist/tods-competition-factory.development.cjs.js +113 -86
- 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 +8 -8
package/dist/index.mjs
CHANGED
|
@@ -329,7 +329,7 @@ const matchUpFormatCode = {
|
|
|
329
329
|
};
|
|
330
330
|
|
|
331
331
|
function factoryVersion() {
|
|
332
|
-
return "1.6.
|
|
332
|
+
return "1.6.28";
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
function getObjectTieFormat(obj) {
|
|
@@ -2445,6 +2445,7 @@ var ParticipantTypeEnum = /* @__PURE__ */ ((ParticipantTypeEnum2) => {
|
|
|
2445
2445
|
})(ParticipantTypeEnum || {});
|
|
2446
2446
|
|
|
2447
2447
|
function validateTieFormat(params) {
|
|
2448
|
+
const checkGender = !!(params?.enforceGender !== false && params?.gender);
|
|
2448
2449
|
const checkCollectionIds = params?.checkCollectionIds;
|
|
2449
2450
|
const tieFormat = params?.tieFormat;
|
|
2450
2451
|
const stack = "validateTieFormat";
|
|
@@ -2453,9 +2454,9 @@ function validateTieFormat(params) {
|
|
|
2453
2454
|
errors.push("tieFormat must be an object");
|
|
2454
2455
|
return decorateResult({
|
|
2455
2456
|
result: {
|
|
2457
|
+
context: { tieFormat, errors },
|
|
2456
2458
|
error: INVALID_TIE_FORMAT,
|
|
2457
|
-
stack
|
|
2458
|
-
context: { tieFormat, errors }
|
|
2459
|
+
stack
|
|
2459
2460
|
}
|
|
2460
2461
|
});
|
|
2461
2462
|
}
|
|
@@ -2463,9 +2464,9 @@ function validateTieFormat(params) {
|
|
|
2463
2464
|
errors.push("tieFormat.winCriteria must be an object");
|
|
2464
2465
|
return decorateResult({
|
|
2465
2466
|
result: {
|
|
2467
|
+
context: { tieFormat, errors },
|
|
2466
2468
|
error: INVALID_TIE_FORMAT,
|
|
2467
|
-
stack
|
|
2468
|
-
context: { tieFormat, errors }
|
|
2469
|
+
stack
|
|
2469
2470
|
}
|
|
2470
2471
|
});
|
|
2471
2472
|
}
|
|
@@ -2473,9 +2474,9 @@ function validateTieFormat(params) {
|
|
|
2473
2474
|
errors.push(mustBeAnArray("tieFormat.collectionDefinitions"));
|
|
2474
2475
|
return decorateResult({
|
|
2475
2476
|
result: {
|
|
2477
|
+
context: { tieFormat, errors },
|
|
2476
2478
|
error: INVALID_TIE_FORMAT,
|
|
2477
|
-
stack
|
|
2478
|
-
context: { tieFormat, errors }
|
|
2479
|
+
stack
|
|
2479
2480
|
}
|
|
2480
2481
|
});
|
|
2481
2482
|
}
|
|
@@ -2486,8 +2487,10 @@ function validateTieFormat(params) {
|
|
|
2486
2487
|
if ((setValue || scoreValue) && !collectionValue)
|
|
2487
2488
|
aggregateValueImperative = true;
|
|
2488
2489
|
const { valid: valid2, errors: collectionDefinitionErrors } = validateCollectionDefinition({
|
|
2490
|
+
referenceGender: params.gender,
|
|
2489
2491
|
collectionDefinition,
|
|
2490
|
-
checkCollectionIds
|
|
2492
|
+
checkCollectionIds,
|
|
2493
|
+
checkGender
|
|
2491
2494
|
});
|
|
2492
2495
|
if (valid2) {
|
|
2493
2496
|
return true;
|
|
@@ -2533,7 +2536,9 @@ function validateTieFormat(params) {
|
|
|
2533
2536
|
}
|
|
2534
2537
|
function validateCollectionDefinition({
|
|
2535
2538
|
collectionDefinition,
|
|
2536
|
-
checkCollectionIds
|
|
2539
|
+
checkCollectionIds,
|
|
2540
|
+
referenceGender,
|
|
2541
|
+
checkGender
|
|
2537
2542
|
}) {
|
|
2538
2543
|
const errors = [];
|
|
2539
2544
|
if (typeof collectionDefinition !== "object") {
|
|
@@ -2552,19 +2557,17 @@ function validateCollectionDefinition({
|
|
|
2552
2557
|
matchUpValue,
|
|
2553
2558
|
matchUpType,
|
|
2554
2559
|
scoreValue,
|
|
2555
|
-
setValue
|
|
2560
|
+
setValue,
|
|
2561
|
+
gender
|
|
2556
2562
|
} = collectionDefinition;
|
|
2557
2563
|
if (checkCollectionIds && typeof collectionId !== "string") {
|
|
2558
2564
|
errors.push(`collectionId is not type string: ${collectionId}`);
|
|
2559
|
-
return { errors };
|
|
2560
2565
|
}
|
|
2561
2566
|
if (typeof matchUpCount !== "number") {
|
|
2562
2567
|
errors.push(`matchUpCount is not type number: ${matchUpCount}`);
|
|
2563
|
-
return { errors };
|
|
2564
2568
|
}
|
|
2565
2569
|
if (matchUpType && ![TypeEnum.Singles, TypeEnum.Doubles].includes(matchUpType)) {
|
|
2566
2570
|
errors.push(`matchUpType must be SINGLES or DOUBLES: ${matchUpType}`);
|
|
2567
|
-
return { errors };
|
|
2568
2571
|
}
|
|
2569
2572
|
const valueDeclarations = [!!collectionValueProfiles?.length].concat(
|
|
2570
2573
|
[matchUpValue, collectionValue, scoreValue, setValue].map(
|
|
@@ -2575,15 +2578,12 @@ function validateCollectionDefinition({
|
|
|
2575
2578
|
errors.push(
|
|
2576
2579
|
"Missing value definition for matchUps: matchUpValue, collectionValue, or collectionValueProfiles"
|
|
2577
2580
|
);
|
|
2578
|
-
return { errors };
|
|
2579
2581
|
}
|
|
2580
2582
|
if (matchUpValue && typeof matchUpValue !== "number") {
|
|
2581
2583
|
errors.push(`matchUpValue is not type number: ${matchUpValue}`);
|
|
2582
|
-
return { errors };
|
|
2583
2584
|
}
|
|
2584
2585
|
if (collectionValue && typeof collectionValue !== "number") {
|
|
2585
2586
|
errors.push(`collectionValue is not type number: ${collectionValue}`);
|
|
2586
|
-
return { errors };
|
|
2587
2587
|
}
|
|
2588
2588
|
if (collectionValueProfiles) {
|
|
2589
2589
|
const result = validateCollectionValueProfile({
|
|
@@ -2592,17 +2592,19 @@ function validateCollectionDefinition({
|
|
|
2592
2592
|
});
|
|
2593
2593
|
if (result.errors) {
|
|
2594
2594
|
errors.push(...result.errors);
|
|
2595
|
-
return { errors };
|
|
2596
2595
|
}
|
|
2597
2596
|
}
|
|
2598
2597
|
if (collectionGroupNumber && typeof collectionGroupNumber !== "number") {
|
|
2599
|
-
errors.push(`
|
|
2600
|
-
return { errors };
|
|
2598
|
+
errors.push(`collectionGroupNumber is not type number: ${collectionValue}`);
|
|
2601
2599
|
}
|
|
2602
2600
|
if (matchUpFormat && !matchUpFormatCode.isValid(matchUpFormat)) {
|
|
2603
2601
|
errors.push(`Invalid matchUpFormat: ${matchUpFormat}`);
|
|
2604
|
-
return { errors };
|
|
2605
2602
|
}
|
|
2603
|
+
if (checkGender && referenceGender && gender && [GenderEnum.Male, GenderEnum.Female].includes(referenceGender) && referenceGender !== gender) {
|
|
2604
|
+
errors.push(`Invalid gender: ${gender}`);
|
|
2605
|
+
}
|
|
2606
|
+
if (errors.length)
|
|
2607
|
+
return { errors };
|
|
2606
2608
|
return { valid: true };
|
|
2607
2609
|
}
|
|
2608
2610
|
function checkTieFormat(tieFormat) {
|
|
@@ -51389,6 +51391,7 @@ function getEventData(params) {
|
|
|
51389
51391
|
// order is important!!
|
|
51390
51392
|
tournamentRecord
|
|
51391
51393
|
});
|
|
51394
|
+
const stageFilter = ({ stage }) => !usePublishState || !publishStatus?.stages?.length || publishStatus.stages.includes(stage);
|
|
51392
51395
|
const structureFilter = ({ structureId }) => !usePublishState || !publishStatus?.structureIds?.length || publishStatus.structureIds.includes(structureId);
|
|
51393
51396
|
const drawFilter = ({ drawId }) => !usePublishState || !publishStatus?.drawIds?.length || publishStatus.drawIds.includes(drawId);
|
|
51394
51397
|
const drawDefinitions = event.drawDefinitions || [];
|
|
@@ -51411,7 +51414,7 @@ function getEventData(params) {
|
|
|
51411
51414
|
)
|
|
51412
51415
|
).map(({ structures, ...drawData }) => ({
|
|
51413
51416
|
...drawData,
|
|
51414
|
-
structures: structures?.filter(structureFilter)
|
|
51417
|
+
structures: structures?.filter(structureFilter)?.filter(stageFilter)
|
|
51415
51418
|
})).filter((drawData) => drawData.structures?.length);
|
|
51416
51419
|
const { tournamentInfo } = getTournamentInfo({ tournamentRecord });
|
|
51417
51420
|
const venues = tournamentRecord.venues || [];
|
|
@@ -51466,15 +51469,17 @@ function getEventData(params) {
|
|
|
51466
51469
|
}
|
|
51467
51470
|
|
|
51468
51471
|
function publishEvent(params) {
|
|
51469
|
-
let { policyDefinitions, drawIds, structureIds } = params;
|
|
51472
|
+
let { policyDefinitions, drawIds, structureIds, stages } = params;
|
|
51470
51473
|
const {
|
|
51474
|
+
includePositionAssignments,
|
|
51471
51475
|
removePriorValues,
|
|
51472
51476
|
tournamentRecord,
|
|
51473
51477
|
status = PUBLIC,
|
|
51474
51478
|
event,
|
|
51475
51479
|
drawIdsToRemove,
|
|
51476
51480
|
drawIdsToAdd,
|
|
51477
|
-
|
|
51481
|
+
stagesToRemove,
|
|
51482
|
+
stagesToAdd,
|
|
51478
51483
|
structureIdsToRemove,
|
|
51479
51484
|
structureIdsToAdd
|
|
51480
51485
|
} = params;
|
|
@@ -51508,25 +51513,36 @@ function publishEvent(params) {
|
|
|
51508
51513
|
);
|
|
51509
51514
|
}
|
|
51510
51515
|
if (!structureIds && (structureIdsToAdd?.length || structureIdsToRemove?.length)) {
|
|
51511
|
-
structureIds = timeItem?.itemValue?.PUBLIC?.
|
|
51516
|
+
structureIds = timeItem?.itemValue?.PUBLIC?.structureIds || [];
|
|
51512
51517
|
}
|
|
51513
51518
|
structureIds = (structureIds || []).filter(
|
|
51514
51519
|
(structureId) => !structureIdsToRemove?.length || !structureIdsToRemove.includes(structureId)
|
|
51515
51520
|
);
|
|
51516
51521
|
if (structureIdsToAdd?.length) {
|
|
51517
|
-
structureIds = unique(structureIds.
|
|
51522
|
+
structureIds = unique(structureIds.concat(...structureIdsToAdd));
|
|
51523
|
+
}
|
|
51524
|
+
if (!stages && (stagesToAdd?.length || stagesToRemove?.length)) {
|
|
51525
|
+
stages = timeItem?.itemValue?.PUBLIC?.stages || [];
|
|
51526
|
+
}
|
|
51527
|
+
stages = (stages || []).filter(
|
|
51528
|
+
(stage) => !stagesToRemove?.length || !stagesToRemove.includes(stage)
|
|
51529
|
+
);
|
|
51530
|
+
if (stagesToAdd?.length) {
|
|
51531
|
+
stages = unique(stages.concat(...stagesToAdd));
|
|
51518
51532
|
}
|
|
51519
51533
|
const existingStatusValue = timeItem?.itemValue?.[status];
|
|
51520
51534
|
const updatedTimeItem = {
|
|
51521
|
-
itemValue: {
|
|
51535
|
+
itemValue: {
|
|
51536
|
+
[status]: { ...existingStatusValue, drawIds, structureIds, stages }
|
|
51537
|
+
},
|
|
51522
51538
|
itemType
|
|
51523
51539
|
};
|
|
51524
51540
|
addEventTimeItem({ event, timeItem: updatedTimeItem, removePriorValues });
|
|
51525
51541
|
const { eventData } = getEventData({
|
|
51526
51542
|
includePositionAssignments,
|
|
51527
51543
|
usePublishState: true,
|
|
51528
|
-
policyDefinitions,
|
|
51529
51544
|
tournamentRecord,
|
|
51545
|
+
policyDefinitions,
|
|
51530
51546
|
event
|
|
51531
51547
|
});
|
|
51532
51548
|
const publishState = eventData?.eventInfo?.publish?.state;
|
|
@@ -54715,8 +54731,8 @@ function addEventEntryPairs({
|
|
|
54715
54731
|
}
|
|
54716
54732
|
|
|
54717
54733
|
function checkValidEntries({
|
|
54734
|
+
enforceGender = true,
|
|
54718
54735
|
participants,
|
|
54719
|
-
ignoreGender,
|
|
54720
54736
|
event
|
|
54721
54737
|
}) {
|
|
54722
54738
|
if (!participants)
|
|
@@ -54742,7 +54758,7 @@ function checkValidEntries({
|
|
|
54742
54758
|
const ungroupedParticipant = eventType && [TypeEnum.Doubles, TypeEnum.Team].includes(eventType) && participant.participantType === INDIVIDUAL && (isUngrouped(entryStatus) || entryStatus === WITHDRAWN);
|
|
54743
54759
|
const mismatch = participant.participantType !== participantType && !ungroupedParticipant;
|
|
54744
54760
|
const personGender = participant?.person?.sex;
|
|
54745
|
-
const wrongGender =
|
|
54761
|
+
const wrongGender = enforceGender && eventGender && eventType === TypeEnum.Singles && [GenderEnum.Male, GenderEnum.Female].includes(eventGender) && personGender !== eventGender;
|
|
54746
54762
|
return mismatch || wrongGender;
|
|
54747
54763
|
});
|
|
54748
54764
|
if (invalidEntries.length) {
|
|
@@ -57342,7 +57358,12 @@ function generateDrawDefinition(params) {
|
|
|
57342
57358
|
tournamentRecord,
|
|
57343
57359
|
inContext: true
|
|
57344
57360
|
});
|
|
57345
|
-
const
|
|
57361
|
+
const appliedPolicies = getAppliedPolicies({
|
|
57362
|
+
tournamentRecord,
|
|
57363
|
+
event
|
|
57364
|
+
}).appliedPolicies ?? {};
|
|
57365
|
+
const enforceGender = params.enforceGender ?? policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS]?.participants?.enforceGender ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS]?.participants?.enforceGender;
|
|
57366
|
+
const validEntriesResult = event && participants && checkValidEntries({ event, participants, enforceGender });
|
|
57346
57367
|
if (validEntriesResult?.error)
|
|
57347
57368
|
return decorateResult({ result: validEntriesResult, stack });
|
|
57348
57369
|
const allowedDrawTypes = !ignoreAllowedDrawTypes && tournamentRecord && getAllowedDrawTypes({
|
|
@@ -57378,11 +57399,6 @@ function generateDrawDefinition(params) {
|
|
|
57378
57399
|
(d) => d.drawId === params.drawId
|
|
57379
57400
|
) : void 0;
|
|
57380
57401
|
let { tieFormat, matchUpFormat } = params;
|
|
57381
|
-
if (tieFormat) {
|
|
57382
|
-
const result = validateTieFormat({ tieFormat });
|
|
57383
|
-
if (result.error)
|
|
57384
|
-
return decorateResult({ result, stack });
|
|
57385
|
-
}
|
|
57386
57402
|
if (matchUpType === TEAM$2 && eventType === TEAM$2) {
|
|
57387
57403
|
const existingMainTieFormat = existingDrawDefinition?.structures?.find(
|
|
57388
57404
|
({ stage }) => stage === MAIN
|
|
@@ -57402,6 +57418,15 @@ function generateDrawDefinition(params) {
|
|
|
57402
57418
|
matchUpFormat = FORMAT_STANDARD;
|
|
57403
57419
|
}
|
|
57404
57420
|
}
|
|
57421
|
+
if (tieFormat) {
|
|
57422
|
+
const result = validateTieFormat({
|
|
57423
|
+
gender: event?.gender,
|
|
57424
|
+
enforceGender,
|
|
57425
|
+
tieFormat
|
|
57426
|
+
});
|
|
57427
|
+
if (result.error)
|
|
57428
|
+
return decorateResult({ result, stack });
|
|
57429
|
+
}
|
|
57405
57430
|
const invalidDrawId = params.drawId && typeof params.drawId !== "string";
|
|
57406
57431
|
if (invalidDrawId)
|
|
57407
57432
|
return decorateResult({ result: { error: INVALID_VALUES }, stack });
|
|
@@ -57434,10 +57459,6 @@ function generateDrawDefinition(params) {
|
|
|
57434
57459
|
drawDefinition.matchUpType = matchUpType;
|
|
57435
57460
|
}
|
|
57436
57461
|
}
|
|
57437
|
-
const appliedPolicies = getAppliedPolicies({
|
|
57438
|
-
tournamentRecord,
|
|
57439
|
-
event
|
|
57440
|
-
}).appliedPolicies ?? {};
|
|
57441
57462
|
if (policyDefinitions) {
|
|
57442
57463
|
if (typeof policyDefinitions !== "object") {
|
|
57443
57464
|
return decorateResult({
|