tods-competition-factory 1.6.26 → 1.6.27

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.
@@ -362,7 +362,7 @@ var matchUpFormatCode = {
362
362
  };
363
363
 
364
364
  function factoryVersion() {
365
- return '1.6.26';
365
+ return '1.6.27';
366
366
  }
367
367
 
368
368
  /******************************************************************************
@@ -3408,6 +3408,7 @@ var SexEnum;
3408
3408
 
3409
3409
  function validateTieFormat(params) {
3410
3410
  var _a, _b, _c, _d;
3411
+ var checkGender = !!((params === null || params === void 0 ? void 0 : params.enforceGender) !== false && (params === null || params === void 0 ? void 0 : params.gender));
3411
3412
  var checkCollectionIds = params === null || params === void 0 ? void 0 : params.checkCollectionIds;
3412
3413
  var tieFormat = params === null || params === void 0 ? void 0 : params.tieFormat;
3413
3414
  var stack = 'validateTieFormat';
@@ -3416,9 +3417,9 @@ function validateTieFormat(params) {
3416
3417
  errors.push('tieFormat must be an object');
3417
3418
  return decorateResult({
3418
3419
  result: {
3420
+ context: { tieFormat: tieFormat, errors: errors },
3419
3421
  error: INVALID_TIE_FORMAT,
3420
3422
  stack: stack,
3421
- context: { tieFormat: tieFormat, errors: errors },
3422
3423
  },
3423
3424
  });
3424
3425
  }
@@ -3426,9 +3427,9 @@ function validateTieFormat(params) {
3426
3427
  errors.push('tieFormat.winCriteria must be an object');
3427
3428
  return decorateResult({
3428
3429
  result: {
3430
+ context: { tieFormat: tieFormat, errors: errors },
3429
3431
  error: INVALID_TIE_FORMAT,
3430
3432
  stack: stack,
3431
- context: { tieFormat: tieFormat, errors: errors },
3432
3433
  },
3433
3434
  });
3434
3435
  }
@@ -3436,9 +3437,9 @@ function validateTieFormat(params) {
3436
3437
  errors.push(mustBeAnArray('tieFormat.collectionDefinitions'));
3437
3438
  return decorateResult({
3438
3439
  result: {
3440
+ context: { tieFormat: tieFormat, errors: errors },
3439
3441
  error: INVALID_TIE_FORMAT,
3440
3442
  stack: stack,
3441
- context: { tieFormat: tieFormat, errors: errors },
3442
3443
  },
3443
3444
  });
3444
3445
  }
@@ -3448,8 +3449,10 @@ function validateTieFormat(params) {
3448
3449
  if ((setValue || scoreValue) && !collectionValue)
3449
3450
  aggregateValueImperative = true;
3450
3451
  var _a = validateCollectionDefinition({
3452
+ referenceGender: params.gender,
3451
3453
  collectionDefinition: collectionDefinition,
3452
3454
  checkCollectionIds: checkCollectionIds,
3455
+ checkGender: checkGender,
3453
3456
  }), valid = _a.valid, collectionDefinitionErrors = _a.errors;
3454
3457
  if (valid) {
3455
3458
  return true;
@@ -3498,40 +3501,34 @@ function validateTieFormat(params) {
3498
3501
  return result;
3499
3502
  }
3500
3503
  function validateCollectionDefinition(_a) {
3501
- var collectionDefinition = _a.collectionDefinition, checkCollectionIds = _a.checkCollectionIds;
3504
+ var collectionDefinition = _a.collectionDefinition, checkCollectionIds = _a.checkCollectionIds, referenceGender = _a.referenceGender, checkGender = _a.checkGender;
3502
3505
  var errors = [];
3503
3506
  if (typeof collectionDefinition !== 'object') {
3504
3507
  errors.push("collectionDefinition must be an object: ".concat(collectionDefinition));
3505
3508
  return { errors: errors };
3506
3509
  }
3507
- var collectionValueProfiles = collectionDefinition.collectionValueProfiles, collectionGroupNumber = collectionDefinition.collectionGroupNumber, collectionValue = collectionDefinition.collectionValue, collectionId = collectionDefinition.collectionId, matchUpCount = collectionDefinition.matchUpCount, matchUpFormat = collectionDefinition.matchUpFormat, matchUpValue = collectionDefinition.matchUpValue, matchUpType = collectionDefinition.matchUpType, scoreValue = collectionDefinition.scoreValue, setValue = collectionDefinition.setValue;
3510
+ var collectionValueProfiles = collectionDefinition.collectionValueProfiles, collectionGroupNumber = collectionDefinition.collectionGroupNumber, collectionValue = collectionDefinition.collectionValue, collectionId = collectionDefinition.collectionId, matchUpCount = collectionDefinition.matchUpCount, matchUpFormat = collectionDefinition.matchUpFormat, matchUpValue = collectionDefinition.matchUpValue, matchUpType = collectionDefinition.matchUpType, scoreValue = collectionDefinition.scoreValue, setValue = collectionDefinition.setValue, gender = collectionDefinition.gender;
3508
3511
  if (checkCollectionIds && typeof collectionId !== 'string') {
3509
3512
  errors.push("collectionId is not type string: ".concat(collectionId));
3510
- return { errors: errors };
3511
3513
  }
3512
3514
  if (typeof matchUpCount !== 'number') {
3513
3515
  errors.push("matchUpCount is not type number: ".concat(matchUpCount));
3514
- return { errors: errors };
3515
3516
  }
3516
3517
  if (matchUpType &&
3517
3518
  ![TypeEnum.Singles, TypeEnum.Doubles].includes(matchUpType)) {
3518
3519
  errors.push("matchUpType must be SINGLES or DOUBLES: ".concat(matchUpType));
3519
- return { errors: errors };
3520
3520
  }
3521
3521
  var valueDeclarations = [!!(collectionValueProfiles === null || collectionValueProfiles === void 0 ? void 0 : collectionValueProfiles.length)]
3522
3522
  .concat([matchUpValue, collectionValue, scoreValue, setValue].map(isConvertableInteger))
3523
3523
  .filter(Boolean);
3524
3524
  if (valueDeclarations.length !== 1) {
3525
3525
  errors.push('Missing value definition for matchUps: matchUpValue, collectionValue, or collectionValueProfiles');
3526
- return { errors: errors };
3527
3526
  }
3528
3527
  if (matchUpValue && typeof matchUpValue !== 'number') {
3529
3528
  errors.push("matchUpValue is not type number: ".concat(matchUpValue));
3530
- return { errors: errors };
3531
3529
  }
3532
3530
  if (collectionValue && typeof collectionValue !== 'number') {
3533
3531
  errors.push("collectionValue is not type number: ".concat(collectionValue));
3534
- return { errors: errors };
3535
3532
  }
3536
3533
  if (collectionValueProfiles) {
3537
3534
  var result = validateCollectionValueProfile({
@@ -3540,17 +3537,23 @@ function validateCollectionDefinition(_a) {
3540
3537
  });
3541
3538
  if (result.errors) {
3542
3539
  errors.push.apply(errors, __spreadArray([], __read(result.errors), false));
3543
- return { errors: errors };
3544
3540
  }
3545
3541
  }
3546
3542
  if (collectionGroupNumber && typeof collectionGroupNumber !== 'number') {
3547
- errors.push("collectionValue is not type number: ".concat(collectionValue));
3548
- return { errors: errors };
3543
+ errors.push("collectionGroupNumber is not type number: ".concat(collectionValue));
3549
3544
  }
3550
3545
  if (matchUpFormat && !matchUpFormatCode.isValid(matchUpFormat)) {
3551
3546
  errors.push("Invalid matchUpFormat: ".concat(matchUpFormat));
3552
- return { errors: errors };
3553
3547
  }
3548
+ if (checkGender &&
3549
+ referenceGender &&
3550
+ gender &&
3551
+ [GenderEnum.Male, GenderEnum.Female].includes(referenceGender) &&
3552
+ referenceGender !== gender) {
3553
+ errors.push("Invalid gender: ".concat(gender));
3554
+ }
3555
+ if (errors.length)
3556
+ return { errors: errors };
3554
3557
  return { valid: true };
3555
3558
  }
3556
3559
  // add collectionIds if missing
@@ -55774,6 +55777,13 @@ function getEventData(params) {
55774
55777
  var publishStatus = (_a = timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemValue) === null || _a === void 0 ? void 0 : _a[status];
55775
55778
  var tournamentParticipants = getTournamentParticipants(__assign(__assign({ withGroupings: true, withEvents: false, withDraws: false }, participantsProfile), { // order is important!!
55776
55779
  tournamentRecord: tournamentRecord })).tournamentParticipants;
55780
+ var stageFilter = function (_a) {
55781
+ var _b;
55782
+ var stage = _a.stage;
55783
+ return !usePublishState ||
55784
+ !((_b = publishStatus === null || publishStatus === void 0 ? void 0 : publishStatus.stages) === null || _b === void 0 ? void 0 : _b.length) ||
55785
+ publishStatus.stages.includes(stage);
55786
+ };
55777
55787
  var structureFilter = function (_a) {
55778
55788
  var _b;
55779
55789
  var structureId = _a.structureId;
@@ -55808,8 +55818,9 @@ function getEventData(params) {
55808
55818
  }));
55809
55819
  })
55810
55820
  .map(function (_a) {
55821
+ var _b;
55811
55822
  var structures = _a.structures, drawData = __rest(_a, ["structures"]);
55812
- return (__assign(__assign({}, drawData), { structures: structures === null || structures === void 0 ? void 0 : structures.filter(structureFilter) }));
55823
+ return (__assign(__assign({}, drawData), { structures: (_b = structures === null || structures === void 0 ? void 0 : structures.filter(structureFilter)) === null || _b === void 0 ? void 0 : _b.filter(stageFilter) }));
55813
55824
  })
55814
55825
  .filter(function (drawData) { var _a; return (_a = drawData.structures) === null || _a === void 0 ? void 0 : _a.length; });
55815
55826
  var tournamentInfo = getTournamentInfo({ tournamentRecord: tournamentRecord }).tournamentInfo;
@@ -55855,9 +55866,9 @@ function getEventData(params) {
55855
55866
 
55856
55867
  function publishEvent(params) {
55857
55868
  var _a;
55858
- var _b, _c, _d, _e, _f, _g, _h, _j;
55859
- var policyDefinitions = params.policyDefinitions, drawIds = params.drawIds, structureIds = params.structureIds;
55860
- var removePriorValues = params.removePriorValues, tournamentRecord = params.tournamentRecord, _k = params.status, status = _k === void 0 ? PUBLIC : _k, event = params.event, drawIdsToRemove = params.drawIdsToRemove, drawIdsToAdd = params.drawIdsToAdd, includePositionAssignments = params.includePositionAssignments, structureIdsToRemove = params.structureIdsToRemove, structureIdsToAdd = params.structureIdsToAdd;
55869
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
55870
+ var policyDefinitions = params.policyDefinitions, drawIds = params.drawIds, structureIds = params.structureIds, stages = params.stages;
55871
+ var includePositionAssignments = params.includePositionAssignments, removePriorValues = params.removePriorValues, tournamentRecord = params.tournamentRecord, _m = params.status, status = _m === void 0 ? PUBLIC : _m, event = params.event, drawIdsToRemove = params.drawIdsToRemove, drawIdsToAdd = params.drawIdsToAdd, stagesToRemove = params.stagesToRemove, stagesToAdd = params.stagesToAdd, structureIdsToRemove = params.structureIdsToRemove, structureIdsToAdd = params.structureIdsToAdd;
55861
55872
  if (!tournamentRecord)
55862
55873
  return { error: MISSING_TOURNAMENT_RECORD };
55863
55874
  if (!event)
@@ -55888,30 +55899,39 @@ function publishEvent(params) {
55888
55899
  }
55889
55900
  if (!structureIds &&
55890
55901
  ((structureIdsToAdd === null || structureIdsToAdd === void 0 ? void 0 : structureIdsToAdd.length) || (structureIdsToRemove === null || structureIdsToRemove === void 0 ? void 0 : structureIdsToRemove.length))) {
55891
- structureIds = ((_f = (_e = timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemValue) === null || _e === void 0 ? void 0 : _e.PUBLIC) === null || _f === void 0 ? void 0 : _f.drawIds) || [];
55902
+ structureIds = ((_f = (_e = timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemValue) === null || _e === void 0 ? void 0 : _e.PUBLIC) === null || _f === void 0 ? void 0 : _f.structureIds) || [];
55892
55903
  }
55893
55904
  structureIds = (structureIds || []).filter(function (structureId) {
55894
55905
  return !(structureIdsToRemove === null || structureIdsToRemove === void 0 ? void 0 : structureIdsToRemove.length) ||
55895
55906
  !structureIdsToRemove.includes(structureId);
55896
55907
  });
55897
55908
  if (structureIdsToAdd === null || structureIdsToAdd === void 0 ? void 0 : structureIdsToAdd.length) {
55898
- structureIds = unique(structureIds.push.apply(structureIds, __spreadArray([], __read(structureIdsToAdd), false)));
55909
+ structureIds = unique(structureIds.concat.apply(structureIds, __spreadArray([], __read(structureIdsToAdd), false)));
55899
55910
  }
55900
- var existingStatusValue = (_g = timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemValue) === null || _g === void 0 ? void 0 : _g[status];
55911
+ if (!stages && ((stagesToAdd === null || stagesToAdd === void 0 ? void 0 : stagesToAdd.length) || (stagesToRemove === null || stagesToRemove === void 0 ? void 0 : stagesToRemove.length))) {
55912
+ stages = ((_h = (_g = timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemValue) === null || _g === void 0 ? void 0 : _g.PUBLIC) === null || _h === void 0 ? void 0 : _h.stages) || [];
55913
+ }
55914
+ stages = (stages || []).filter(function (stage) { return !(stagesToRemove === null || stagesToRemove === void 0 ? void 0 : stagesToRemove.length) || !stagesToRemove.includes(stage); });
55915
+ if (stagesToAdd === null || stagesToAdd === void 0 ? void 0 : stagesToAdd.length) {
55916
+ stages = unique(stages.concat.apply(stages, __spreadArray([], __read(stagesToAdd), false)));
55917
+ }
55918
+ var existingStatusValue = (_j = timeItem === null || timeItem === void 0 ? void 0 : timeItem.itemValue) === null || _j === void 0 ? void 0 : _j[status];
55901
55919
  var updatedTimeItem = {
55902
- itemValue: (_a = {}, _a[status] = __assign(__assign({}, existingStatusValue), { drawIds: drawIds, structureIds: structureIds }), _a),
55920
+ itemValue: (_a = {},
55921
+ _a[status] = __assign(__assign({}, existingStatusValue), { drawIds: drawIds, structureIds: structureIds, stages: stages }),
55922
+ _a),
55903
55923
  itemType: itemType,
55904
55924
  };
55905
55925
  addEventTimeItem({ event: event, timeItem: updatedTimeItem, removePriorValues: removePriorValues });
55906
55926
  var eventData = getEventData({
55907
55927
  includePositionAssignments: includePositionAssignments,
55908
55928
  usePublishState: true,
55909
- policyDefinitions: policyDefinitions,
55910
55929
  tournamentRecord: tournamentRecord,
55930
+ policyDefinitions: policyDefinitions,
55911
55931
  event: event,
55912
55932
  }).eventData;
55913
55933
  // filter out drawData for unPublished draws
55914
- var publishState = (_j = (_h = eventData === null || eventData === void 0 ? void 0 : eventData.eventInfo) === null || _h === void 0 ? void 0 : _h.publish) === null || _j === void 0 ? void 0 : _j.state;
55934
+ var publishState = (_l = (_k = eventData === null || eventData === void 0 ? void 0 : eventData.eventInfo) === null || _k === void 0 ? void 0 : _k.publish) === null || _l === void 0 ? void 0 : _l.state;
55915
55935
  eventData.drawsData = eventData.drawsData.filter(function (_a) {
55916
55936
  var _b;
55917
55937
  var drawId = _a.drawId;
@@ -59336,7 +59356,7 @@ function addEventEntryPairs(_a) {
59336
59356
  }
59337
59357
 
59338
59358
  function checkValidEntries(_a) {
59339
- var participants = _a.participants, ignoreGender = _a.ignoreGender, event = _a.event;
59359
+ var _b = _a.enforceGender, enforceGender = _b === void 0 ? true : _b, participants = _a.participants, event = _a.event;
59340
59360
  if (!participants)
59341
59361
  return { error: MISSING_PARTICIPANTS };
59342
59362
  if (!Array.isArray(participants))
@@ -59367,7 +59387,7 @@ function checkValidEntries(_a) {
59367
59387
  var mismatch = participant.participantType !== participantType && !ungroupedParticipant;
59368
59388
  // TODO: implement gender checking for teams & pairs
59369
59389
  var personGender = (_a = participant === null || participant === void 0 ? void 0 : participant.person) === null || _a === void 0 ? void 0 : _a.sex;
59370
- var wrongGender = !ignoreGender &&
59390
+ var wrongGender = enforceGender &&
59371
59391
  eventGender &&
59372
59392
  eventType === TypeEnum.Singles &&
59373
59393
  [GenderEnum.Male, GenderEnum.Female].includes(eventGender) &&
@@ -62162,7 +62182,7 @@ function generateDrawDefinition(params) {
62162
62182
  var _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
62163
62183
  var stack = 'generateDrawDefinition';
62164
62184
  var _16 = params.drawType, drawType = _16 === void 0 ? DrawTypeEnum.SingleElimination : _16, _17 = params.considerEventEntries, considerEventEntries = _17 === void 0 ? true : _17, // in the absence of drawSize and drawEntries, look to event.entries
62165
- ignoreAllowedDrawTypes = params.ignoreAllowedDrawTypes, voluntaryConsolation = params.voluntaryConsolation, hydrateCollections = params.hydrateCollections, policyDefinitions = params.policyDefinitions, ignoreStageSpace = params.ignoreStageSpace, tournamentRecord = params.tournamentRecord, qualifyingOnly = params.qualifyingOnly, tieFormatName = params.tieFormatName, drawEntries = params.drawEntries, addToEvent = params.addToEvent, placeByes = params.placeByes, event = params.event;
62185
+ ignoreAllowedDrawTypes = params.ignoreAllowedDrawTypes, voluntaryConsolation = params.voluntaryConsolation, hydrateCollections = params.hydrateCollections, policyDefinitions = params.policyDefinitions, ignoreStageSpace = params.ignoreStageSpace, tournamentRecord = params.tournamentRecord, qualifyingOnly = params.qualifyingOnly, enforceGender = params.enforceGender, tieFormatName = params.tieFormatName, drawEntries = params.drawEntries, addToEvent = params.addToEvent, placeByes = params.placeByes, event = params.event;
62166
62186
  // get participants both for entry validation and for automated placement
62167
62187
  // automated placement requires them to be "inContext" for avoidance policies to work
62168
62188
  var participants = getTournamentParticipants({
@@ -62171,7 +62191,9 @@ function generateDrawDefinition(params) {
62171
62191
  }).tournamentParticipants;
62172
62192
  // entries participantTypes must correspond with eventType
62173
62193
  // this is only possible if the event is provided
62174
- var validEntriesResult = event && participants && checkValidEntries({ event: event, participants: participants });
62194
+ var validEntriesResult = event &&
62195
+ participants &&
62196
+ checkValidEntries({ event: event, participants: participants, enforceGender: enforceGender });
62175
62197
  if (validEntriesResult === null || validEntriesResult === void 0 ? void 0 : validEntriesResult.error)
62176
62198
  return decorateResult({ result: validEntriesResult, stack: stack });
62177
62199
  // if tournamentRecord is provided, and unless instructed to ignore valid types,
@@ -62228,11 +62250,6 @@ function generateDrawDefinition(params) {
62228
62250
  : undefined;
62229
62251
  // drawDefinition cannot have both tieFormat and matchUpFormat
62230
62252
  var tieFormat = params.tieFormat, matchUpFormat = params.matchUpFormat;
62231
- if (tieFormat) {
62232
- var result = validateTieFormat({ tieFormat: tieFormat });
62233
- if (result.error)
62234
- return decorateResult({ result: result, stack: stack });
62235
- }
62236
62253
  // TODO: implement use of tieFormatId and tieFormats array
62237
62254
  if (matchUpType === TEAM$2 && eventType === TEAM$2) {
62238
62255
  // if there is an existingDrawDefinition which has a tieFormat on MAIN structure
@@ -62267,6 +62284,15 @@ function generateDrawDefinition(params) {
62267
62284
  matchUpFormat = FORMAT_STANDARD;
62268
62285
  }
62269
62286
  }
62287
+ if (tieFormat) {
62288
+ var result = validateTieFormat({
62289
+ gender: event === null || event === void 0 ? void 0 : event.gender,
62290
+ enforceGender: enforceGender,
62291
+ tieFormat: tieFormat,
62292
+ });
62293
+ if (result.error)
62294
+ return decorateResult({ result: result, stack: stack });
62295
+ }
62270
62296
  var invalidDrawId = params.drawId && typeof params.drawId !== 'string';
62271
62297
  if (invalidDrawId)
62272
62298
  return decorateResult({ result: { error: INVALID_VALUES }, stack: stack });