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.
@@ -362,7 +362,7 @@ var matchUpFormatCode = {
362
362
  };
363
363
 
364
364
  function factoryVersion() {
365
- return '1.6.26';
365
+ return '1.6.28';
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) &&
@@ -62159,9 +62179,9 @@ function prepareStage(params) {
62159
62179
 
62160
62180
  function generateDrawDefinition(params) {
62161
62181
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d, _e, e_5, _f, e_6, _g, _h;
62162
- 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;
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, _16, _17, _18, _19, _20, _21;
62163
62183
  var stack = 'generateDrawDefinition';
62164
- 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
62184
+ var _22 = params.drawType, drawType = _22 === void 0 ? DrawTypeEnum.SingleElimination : _22, _23 = params.considerEventEntries, considerEventEntries = _23 === void 0 ? true : _23, // in the absence of drawSize and drawEntries, look to event.entries
62165
62185
  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;
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
@@ -62169,9 +62189,16 @@ function generateDrawDefinition(params) {
62169
62189
  tournamentRecord: tournamentRecord,
62170
62190
  inContext: true,
62171
62191
  }).tournamentParticipants;
62192
+ var appliedPolicies = (_j = getAppliedPolicies({
62193
+ tournamentRecord: tournamentRecord,
62194
+ event: event,
62195
+ }).appliedPolicies) !== null && _j !== void 0 ? _j : {};
62196
+ var enforceGender = (_o = (_k = params.enforceGender) !== null && _k !== void 0 ? _k : (_m = (_l = policyDefinitions === null || policyDefinitions === void 0 ? void 0 : policyDefinitions[POLICY_TYPE_MATCHUP_ACTIONS]) === null || _l === void 0 ? void 0 : _l.participants) === null || _m === void 0 ? void 0 : _m.enforceGender) !== null && _o !== void 0 ? _o : (_q = (_p = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_MATCHUP_ACTIONS]) === null || _p === void 0 ? void 0 : _p.participants) === null || _q === void 0 ? void 0 : _q.enforceGender;
62172
62197
  // entries participantTypes must correspond with eventType
62173
62198
  // this is only possible if the event is provided
62174
- var validEntriesResult = event && participants && checkValidEntries({ event: event, participants: participants });
62199
+ var validEntriesResult = event &&
62200
+ participants &&
62201
+ checkValidEntries({ event: event, participants: participants, enforceGender: enforceGender });
62175
62202
  if (validEntriesResult === null || validEntriesResult === void 0 ? void 0 : validEntriesResult.error)
62176
62203
  return decorateResult({ result: validEntriesResult, stack: stack });
62177
62204
  // if tournamentRecord is provided, and unless instructed to ignore valid types,
@@ -62180,16 +62207,16 @@ function generateDrawDefinition(params) {
62180
62207
  tournamentRecord &&
62181
62208
  getAllowedDrawTypes({
62182
62209
  tournamentRecord: tournamentRecord,
62183
- categoryType: (_j = event === null || event === void 0 ? void 0 : event.category) === null || _j === void 0 ? void 0 : _j.categoryType,
62184
- categoryName: (_k = event === null || event === void 0 ? void 0 : event.category) === null || _k === void 0 ? void 0 : _k.categoryName,
62210
+ categoryType: (_r = event === null || event === void 0 ? void 0 : event.category) === null || _r === void 0 ? void 0 : _r.categoryType,
62211
+ categoryName: (_s = event === null || event === void 0 ? void 0 : event.category) === null || _s === void 0 ? void 0 : _s.categoryName,
62185
62212
  });
62186
62213
  if ((allowedDrawTypes === null || allowedDrawTypes === void 0 ? void 0 : allowedDrawTypes.length) && !allowedDrawTypes.includes(drawType)) {
62187
62214
  return decorateResult({ result: { error: INVALID_DRAW_TYPE }, stack: stack });
62188
62215
  }
62189
- var eventEntries = (_m = (_l = event === null || event === void 0 ? void 0 : event.entries) === null || _l === void 0 ? void 0 : _l.filter(function (entry) {
62216
+ var eventEntries = (_u = (_t = event === null || event === void 0 ? void 0 : event.entries) === null || _t === void 0 ? void 0 : _t.filter(function (entry) {
62190
62217
  return entry.entryStatus &&
62191
62218
  __spreadArray(__spreadArray([], __read(STRUCTURE_ENTERED_TYPES), false), [QUALIFIER], false).includes(entry.entryStatus);
62192
- })) !== null && _m !== void 0 ? _m : [];
62219
+ })) !== null && _u !== void 0 ? _u : [];
62193
62220
  var consideredEntries = ((qualifyingOnly && []) ||
62194
62221
  drawEntries ||
62195
62222
  (considerEventEntries ? eventEntries : [])).filter(function (_a) {
@@ -62219,34 +62246,29 @@ function generateDrawDefinition(params) {
62219
62246
  });
62220
62247
  }
62221
62248
  var seedsCount = typeof params.seedsCount !== 'number'
62222
- ? ensureInt((_o = params.seedsCount) !== null && _o !== void 0 ? _o : 0)
62223
- : (_p = params.seedsCount) !== null && _p !== void 0 ? _p : 0;
62249
+ ? ensureInt((_v = params.seedsCount) !== null && _v !== void 0 ? _v : 0)
62250
+ : (_w = params.seedsCount) !== null && _w !== void 0 ? _w : 0;
62224
62251
  var eventType = event === null || event === void 0 ? void 0 : event.eventType;
62225
- var matchUpType = (_q = params.matchUpType) !== null && _q !== void 0 ? _q : eventType;
62252
+ var matchUpType = (_x = params.matchUpType) !== null && _x !== void 0 ? _x : eventType;
62226
62253
  var existingDrawDefinition = params.drawId
62227
- ? (_r = event === null || event === void 0 ? void 0 : event.drawDefinitions) === null || _r === void 0 ? void 0 : _r.find(function (d) { return d.drawId === params.drawId; })
62254
+ ? (_y = event === null || event === void 0 ? void 0 : event.drawDefinitions) === null || _y === void 0 ? void 0 : _y.find(function (d) { return d.drawId === params.drawId; })
62228
62255
  : undefined;
62229
62256
  // drawDefinition cannot have both tieFormat and matchUpFormat
62230
62257
  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
62258
  // TODO: implement use of tieFormatId and tieFormats array
62237
62259
  if (matchUpType === TEAM$2 && eventType === TEAM$2) {
62238
62260
  // if there is an existingDrawDefinition which has a tieFormat on MAIN structure
62239
62261
  // use this tieFormat ONLY when no tieFormat is specified in params
62240
- var existingMainTieFormat = (_t = (_s = existingDrawDefinition === null || existingDrawDefinition === void 0 ? void 0 : existingDrawDefinition.structures) === null || _s === void 0 ? void 0 : _s.find(function (_a) {
62262
+ var existingMainTieFormat = (_0 = (_z = existingDrawDefinition === null || existingDrawDefinition === void 0 ? void 0 : existingDrawDefinition.structures) === null || _z === void 0 ? void 0 : _z.find(function (_a) {
62241
62263
  var stage = _a.stage;
62242
62264
  return stage === MAIN;
62243
- })) === null || _t === void 0 ? void 0 : _t.tieFormat;
62265
+ })) === null || _0 === void 0 ? void 0 : _0.tieFormat;
62244
62266
  tieFormat =
62245
62267
  tieFormat ||
62246
62268
  existingMainTieFormat ||
62247
62269
  // if tieFormatName is provided and it matches the name of the tieFormat attached to parent event...
62248
62270
  (tieFormatName &&
62249
- ((_u = event === null || event === void 0 ? void 0 : event.tieFormat) === null || _u === void 0 ? void 0 : _u.tieFormatName) === tieFormatName &&
62271
+ ((_1 = event === null || event === void 0 ? void 0 : event.tieFormat) === null || _1 === void 0 ? void 0 : _1.tieFormatName) === tieFormatName &&
62250
62272
  event.tieFormat) ||
62251
62273
  // if the tieFormatName is not found in the factory then will use default
62252
62274
  (tieFormatName &&
@@ -62267,6 +62289,15 @@ function generateDrawDefinition(params) {
62267
62289
  matchUpFormat = FORMAT_STANDARD;
62268
62290
  }
62269
62291
  }
62292
+ if (tieFormat) {
62293
+ var result = validateTieFormat({
62294
+ gender: event === null || event === void 0 ? void 0 : event.gender,
62295
+ enforceGender: enforceGender,
62296
+ tieFormat: tieFormat,
62297
+ });
62298
+ if (result.error)
62299
+ return decorateResult({ result: result, stack: stack });
62300
+ }
62270
62301
  var invalidDrawId = params.drawId && typeof params.drawId !== 'string';
62271
62302
  if (invalidDrawId)
62272
62303
  return decorateResult({ result: { error: INVALID_VALUES }, stack: stack });
@@ -62289,7 +62320,7 @@ function generateDrawDefinition(params) {
62289
62320
  var result = checkTieFormat(tieFormat);
62290
62321
  if (result.error)
62291
62322
  return decorateResult({ result: result, stack: stack });
62292
- drawDefinition.tieFormat = (_v = result.tieFormat) !== null && _v !== void 0 ? _v : tieFormat;
62323
+ drawDefinition.tieFormat = (_2 = result.tieFormat) !== null && _2 !== void 0 ? _2 : tieFormat;
62293
62324
  }
62294
62325
  else if (matchUpFormat) {
62295
62326
  var result = setMatchUpFormat$1({
@@ -62309,10 +62340,6 @@ function generateDrawDefinition(params) {
62309
62340
  drawDefinition.matchUpType = matchUpType;
62310
62341
  }
62311
62342
  }
62312
- var appliedPolicies = (_w = getAppliedPolicies({
62313
- tournamentRecord: tournamentRecord,
62314
- event: event,
62315
- }).appliedPolicies) !== null && _w !== void 0 ? _w : {};
62316
62343
  if (policyDefinitions) {
62317
62344
  if (typeof policyDefinitions !== 'object') {
62318
62345
  return decorateResult({
@@ -62326,8 +62353,8 @@ function generateDrawDefinition(params) {
62326
62353
  else {
62327
62354
  var policiesToAttach = {};
62328
62355
  try {
62329
- for (var _18 = __values(Object.keys(policyDefinitions)), _19 = _18.next(); !_19.done; _19 = _18.next()) {
62330
- var key = _19.value;
62356
+ for (var _24 = __values(Object.keys(policyDefinitions)), _25 = _24.next(); !_25.done; _25 = _24.next()) {
62357
+ var key = _25.value;
62331
62358
  if (JSON.stringify(appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[key]) !==
62332
62359
  JSON.stringify(policyDefinitions[key])) {
62333
62360
  policiesToAttach[key] = policyDefinitions[key];
@@ -62337,7 +62364,7 @@ function generateDrawDefinition(params) {
62337
62364
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
62338
62365
  finally {
62339
62366
  try {
62340
- if (_19 && !_19.done && (_a = _18.return)) _a.call(_18);
62367
+ if (_25 && !_25.done && (_a = _24.return)) _a.call(_24);
62341
62368
  }
62342
62369
  finally { if (e_1) throw e_1.error; }
62343
62370
  }
@@ -62353,19 +62380,19 @@ function generateDrawDefinition(params) {
62353
62380
  Object.assign(appliedPolicies, POLICY_SEEDING_USTA);
62354
62381
  }
62355
62382
  // find existing MAIN structureId if existingDrawDefinition
62356
- var structureId = (_y = (_x = existingDrawDefinition === null || existingDrawDefinition === void 0 ? void 0 : existingDrawDefinition.structures) === null || _x === void 0 ? void 0 : _x.find(function (structure) { return structure.stage === MAIN && structure.stageSequence === 1; })) === null || _y === void 0 ? void 0 : _y.structureId;
62383
+ var structureId = (_4 = (_3 = existingDrawDefinition === null || existingDrawDefinition === void 0 ? void 0 : existingDrawDefinition.structures) === null || _3 === void 0 ? void 0 : _3.find(function (structure) { return structure.stage === MAIN && structure.stageSequence === 1; })) === null || _4 === void 0 ? void 0 : _4.structureId;
62357
62384
  var entries = drawEntries !== null && drawEntries !== void 0 ? drawEntries : eventEntries;
62358
62385
  var positioningReports = [];
62359
62386
  var drawTypeResult;
62360
62387
  var conflicts = [];
62361
62388
  var generateQualifyingPlaceholder = params.qualifyingPlaceholder &&
62362
- !((_z = params.qualifyingProfiles) === null || _z === void 0 ? void 0 : _z.length) &&
62389
+ !((_5 = params.qualifyingProfiles) === null || _5 === void 0 ? void 0 : _5.length) &&
62363
62390
  !existingDrawDefinition;
62364
62391
  var existingQualifyingStructures = existingDrawDefinition
62365
- ? (_0 = existingDrawDefinition.structures) === null || _0 === void 0 ? void 0 : _0.filter(function (structure) { return structure.stage === QUALIFYING; })
62392
+ ? (_6 = existingDrawDefinition.structures) === null || _6 === void 0 ? void 0 : _6.filter(function (structure) { return structure.stage === QUALIFYING; })
62366
62393
  : [];
62367
62394
  var existingQualifyingPlaceholderStructureId = (existingQualifyingStructures === null || existingQualifyingStructures === void 0 ? void 0 : existingQualifyingStructures.length) === 1 &&
62368
- !((_1 = existingQualifyingStructures[0].matchUps) === null || _1 === void 0 ? void 0 : _1.length) &&
62395
+ !((_7 = existingQualifyingStructures[0].matchUps) === null || _7 === void 0 ? void 0 : _7.length) &&
62369
62396
  existingQualifyingStructures[0].structureId;
62370
62397
  if (existingQualifyingPlaceholderStructureId) {
62371
62398
  var qualifyingProfiles = params.qualifyingProfiles;
@@ -62381,24 +62408,24 @@ function generateDrawDefinition(params) {
62381
62408
  if (qualifyingResult === null || qualifyingResult === void 0 ? void 0 : qualifyingResult.error) {
62382
62409
  return qualifyingResult;
62383
62410
  }
62384
- drawDefinition.structures = (_2 = drawDefinition.structures) === null || _2 === void 0 ? void 0 : _2.filter(function (_a) {
62411
+ drawDefinition.structures = (_8 = drawDefinition.structures) === null || _8 === void 0 ? void 0 : _8.filter(function (_a) {
62385
62412
  var structureId = _a.structureId;
62386
62413
  return structureId !== existingQualifyingPlaceholderStructureId;
62387
62414
  });
62388
- drawDefinition.links = (_3 = drawDefinition.links) === null || _3 === void 0 ? void 0 : _3.filter(function (_a) {
62415
+ drawDefinition.links = (_9 = drawDefinition.links) === null || _9 === void 0 ? void 0 : _9.filter(function (_a) {
62389
62416
  var source = _a.source;
62390
62417
  return source.structureId !== existingQualifyingPlaceholderStructureId;
62391
62418
  });
62392
- var _20 = qualifyingResult !== null && qualifyingResult !== void 0 ? qualifyingResult : {}, qualifiersCount = _20.qualifiersCount, qualifyingDrawPositionsCount = _20.qualifyingDrawPositionsCount, qualifyingDetails = _20.qualifyingDetails;
62419
+ var _26 = qualifyingResult !== null && qualifyingResult !== void 0 ? qualifyingResult : {}, qualifiersCount = _26.qualifiersCount, qualifyingDrawPositionsCount = _26.qualifyingDrawPositionsCount, qualifyingDetails = _26.qualifyingDetails;
62393
62420
  if (qualifyingDrawPositionsCount) {
62394
62421
  if (qualifyingResult === null || qualifyingResult === void 0 ? void 0 : qualifyingResult.structures) {
62395
- (_4 = drawDefinition.structures) === null || _4 === void 0 ? void 0 : _4.push.apply(_4, __spreadArray([], __read(qualifyingResult.structures), false));
62422
+ (_10 = drawDefinition.structures) === null || _10 === void 0 ? void 0 : _10.push.apply(_10, __spreadArray([], __read(qualifyingResult.structures), false));
62396
62423
  }
62397
62424
  if (qualifyingResult === null || qualifyingResult === void 0 ? void 0 : qualifyingResult.links) {
62398
- (_5 = drawDefinition.links) === null || _5 === void 0 ? void 0 : _5.push.apply(_5, __spreadArray([], __read(qualifyingResult.links), false));
62425
+ (_11 = drawDefinition.links) === null || _11 === void 0 ? void 0 : _11.push.apply(_11, __spreadArray([], __read(qualifyingResult.links), false));
62399
62426
  }
62400
62427
  }
62401
- var mainStructure = (_6 = drawDefinition.structures) === null || _6 === void 0 ? void 0 : _6.find(function (_a) {
62428
+ var mainStructure = (_12 = drawDefinition.structures) === null || _12 === void 0 ? void 0 : _12.find(function (_a) {
62402
62429
  var stage = _a.stage, stageSequence = _a.stageSequence;
62403
62430
  return stage === MAIN && stageSequence === 1;
62404
62431
  });
@@ -62424,12 +62451,12 @@ function generateDrawDefinition(params) {
62424
62451
  if (result.error)
62425
62452
  return result;
62426
62453
  try {
62427
- for (var _21 = __values((drawEntries !== null && drawEntries !== void 0 ? drawEntries : []).filter(function (_a) {
62454
+ for (var _27 = __values((drawEntries !== null && drawEntries !== void 0 ? drawEntries : []).filter(function (_a) {
62428
62455
  var entryStage = _a.entryStage;
62429
62456
  return entryStage === StageTypeEnum.Qualifying;
62430
- })), _22 = _21.next(); !_22.done; _22 = _21.next()) {
62431
- var entry = _22.value;
62432
- var entryData = __assign(__assign({}, entry), { entryStage: (_7 = entry.entryStage) !== null && _7 !== void 0 ? _7 : StageTypeEnum.Main, drawDefinition: drawDefinition });
62457
+ })), _28 = _27.next(); !_28.done; _28 = _27.next()) {
62458
+ var entry = _28.value;
62459
+ var entryData = __assign(__assign({}, entry), { entryStage: (_13 = entry.entryStage) !== null && _13 !== void 0 ? _13 : StageTypeEnum.Main, drawDefinition: drawDefinition });
62433
62460
  // ignore errors (EXITING_PARTICIPANT)
62434
62461
  addDrawEntry(entryData);
62435
62462
  }
@@ -62437,23 +62464,23 @@ function generateDrawDefinition(params) {
62437
62464
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
62438
62465
  finally {
62439
62466
  try {
62440
- if (_22 && !_22.done && (_b = _21.return)) _b.call(_21);
62467
+ if (_28 && !_28.done && (_b = _27.return)) _b.call(_27);
62441
62468
  }
62442
62469
  finally { if (e_2) throw e_2.error; }
62443
62470
  }
62444
62471
  try {
62445
- for (var _23 = __values(qualifyingDetails || []), _24 = _23.next(); !_24.done; _24 = _23.next()) {
62446
- var qualifyingDetail = _24.value;
62472
+ for (var _29 = __values(qualifyingDetails || []), _30 = _29.next(); !_30.done; _30 = _29.next()) {
62473
+ var qualifyingDetail = _30.value;
62447
62474
  var qualifyingRoundNumber = qualifyingDetail.finalQualifyingRoundNumber, qualifyingStructureId = qualifyingDetail.finalQualifyingStructureId, targetEntryRound = qualifyingDetail.roundTarget, finishingPositions = qualifyingDetail.finishingPositions, linkType = qualifyingDetail.linkType;
62448
62475
  var link = mainStructure &&
62449
- ((_8 = generateQualifyingLink({
62476
+ ((_14 = generateQualifyingLink({
62450
62477
  targetStructureId: mainStructure.structureId,
62451
62478
  sourceStructureId: qualifyingStructureId,
62452
62479
  sourceRoundNumber: qualifyingRoundNumber,
62453
62480
  finishingPositions: finishingPositions,
62454
62481
  targetEntryRound: targetEntryRound,
62455
62482
  linkType: linkType,
62456
- })) === null || _8 === void 0 ? void 0 : _8.link);
62483
+ })) === null || _14 === void 0 ? void 0 : _14.link);
62457
62484
  if (link === null || link === void 0 ? void 0 : link.error)
62458
62485
  return link;
62459
62486
  if (link) {
@@ -62466,7 +62493,7 @@ function generateDrawDefinition(params) {
62466
62493
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
62467
62494
  finally {
62468
62495
  try {
62469
- if (_24 && !_24.done && (_c = _23.return)) _c.call(_23);
62496
+ if (_30 && !_30.done && (_c = _29.return)) _c.call(_29);
62470
62497
  }
62471
62498
  finally { if (e_3) throw e_3.error; }
62472
62499
  }
@@ -62487,7 +62514,7 @@ function generateDrawDefinition(params) {
62487
62514
  entry.entryStage &&
62488
62515
  entry.entryStage !== StageTypeEnum.Main)
62489
62516
  continue;
62490
- var entryData = __assign(__assign({}, entry), { ignoreStageSpace: ignoreStageSpace !== null && ignoreStageSpace !== void 0 ? ignoreStageSpace : drawType === AD_HOC, entryStage: (_9 = entry.entryStage) !== null && _9 !== void 0 ? _9 : StageTypeEnum.Main, drawDefinition: drawDefinition, drawType: drawType });
62517
+ var entryData = __assign(__assign({}, entry), { ignoreStageSpace: ignoreStageSpace !== null && ignoreStageSpace !== void 0 ? ignoreStageSpace : drawType === AD_HOC, entryStage: (_15 = entry.entryStage) !== null && _15 !== void 0 ? _15 : StageTypeEnum.Main, drawDefinition: drawDefinition, drawType: drawType });
62491
62518
  var result = addDrawEntry(entryData);
62492
62519
  if (drawEntries && result.error) {
62493
62520
  // only report errors with drawEntries
@@ -62511,13 +62538,13 @@ function generateDrawDefinition(params) {
62511
62538
  if (structureResult.error && !structureResult.conflicts) {
62512
62539
  return structureResult;
62513
62540
  }
62514
- if ((_10 = structureResult.positioningReport) === null || _10 === void 0 ? void 0 : _10.length)
62541
+ if ((_16 = structureResult.positioningReport) === null || _16 === void 0 ? void 0 : _16.length)
62515
62542
  positioningReports.push((_e = {}, _e[MAIN] = structureResult.positioningReport, _e));
62516
62543
  structureId = structureResult.structureId;
62517
62544
  if (structureResult.conflicts)
62518
62545
  conflicts = structureResult.conflicts;
62519
62546
  if (drawType === AD_HOC && params.roundsCount) {
62520
- var entries_2 = (_11 = event === null || event === void 0 ? void 0 : event.entries) === null || _11 === void 0 ? void 0 : _11.filter(function (_a) {
62547
+ var entries_2 = (_17 = event === null || event === void 0 ? void 0 : event.entries) === null || _17 === void 0 ? void 0 : _17.filter(function (_a) {
62521
62548
  var entryStage = _a.entryStage, entryStatus = _a.entryStatus;
62522
62549
  return (!entryStage || entryStage === MAIN) &&
62523
62550
  entryStatus &&
@@ -62564,20 +62591,20 @@ function generateDrawDefinition(params) {
62564
62591
  var roundTarget = 1;
62565
62592
  params.qualifyingProfiles.sort(roundTargetSort);
62566
62593
  try {
62567
- for (var _25 = __values(params.qualifyingProfiles), _26 = _25.next(); !_26.done; _26 = _25.next()) {
62568
- var roundTargetProfile = _26.value;
62594
+ for (var _31 = __values(params.qualifyingProfiles), _32 = _31.next(); !_32.done; _32 = _31.next()) {
62595
+ var roundTargetProfile = _32.value;
62569
62596
  if (!Array.isArray(roundTargetProfile.structureProfiles))
62570
62597
  return decorateResult({
62571
62598
  result: { error: MISSING_VALUE },
62572
62599
  info: mustBeAnArray('structureProfiles'),
62573
62600
  });
62574
62601
  roundTarget = roundTargetProfile.roundTarget || roundTarget;
62575
- var sortedStructureProfiles = ((_12 = roundTargetProfile.structureProfiles) === null || _12 === void 0 ? void 0 : _12.sort(sequenceSort)) || [];
62602
+ var sortedStructureProfiles = ((_18 = roundTargetProfile.structureProfiles) === null || _18 === void 0 ? void 0 : _18.sort(sequenceSort)) || [];
62576
62603
  var sequence = 1;
62577
62604
  try {
62578
62605
  for (var sortedStructureProfiles_1 = (e_6 = void 0, __values(sortedStructureProfiles)), sortedStructureProfiles_1_1 = sortedStructureProfiles_1.next(); !sortedStructureProfiles_1_1.done; sortedStructureProfiles_1_1 = sortedStructureProfiles_1.next()) {
62579
62606
  var structureProfile = sortedStructureProfiles_1_1.value;
62580
- var qualifyingRoundNumber = structureProfile.qualifyingRoundNumber, qualifyingPositions = structureProfile.qualifyingPositions, seededParticipants = structureProfile.seededParticipants, seedingScaleName = structureProfile.seedingScaleName, _27 = structureProfile.seedsCount, seedsCount_1 = _27 === void 0 ? 0 : _27, seedingProfile = structureProfile.seedingProfile, seedByRanking = structureProfile.seedByRanking, placeByes_1 = structureProfile.placeByes, drawSize_1 = structureProfile.drawSize;
62607
+ var qualifyingRoundNumber = structureProfile.qualifyingRoundNumber, qualifyingPositions = structureProfile.qualifyingPositions, seededParticipants = structureProfile.seededParticipants, seedingScaleName = structureProfile.seedingScaleName, _33 = structureProfile.seedsCount, seedsCount_1 = _33 === void 0 ? 0 : _33, seedingProfile = structureProfile.seedingProfile, seedByRanking = structureProfile.seedByRanking, placeByes_1 = structureProfile.placeByes, drawSize_1 = structureProfile.drawSize;
62581
62608
  var qualifyingStageResult = prepareStage(__assign(__assign(__assign({}, drawTypeResult), params), { stageSequence: sequence, qualifyingRoundNumber: qualifyingRoundNumber, preparedStructureIds: preparedStructureIds, qualifyingPositions: qualifyingPositions, seededParticipants: seededParticipants, stage: QUALIFYING, seedingScaleName: seedingScaleName, appliedPolicies: appliedPolicies, drawDefinition: drawDefinition, qualifyingOnly: qualifyingOnly, seedingProfile: seedingProfile, seedByRanking: seedByRanking, participants: participants, roundTarget: roundTarget, seedsCount: seedsCount_1, placeByes: placeByes_1, drawSize: drawSize_1, entries: entries }));
62582
62609
  if (qualifyingStageResult.error) {
62583
62610
  return qualifyingStageResult;
@@ -62586,9 +62613,9 @@ function generateDrawDefinition(params) {
62586
62613
  preparedStructureIds.push(qualifyingStageResult.structureId);
62587
62614
  }
62588
62615
  sequence += 1;
62589
- if ((_13 = qualifyingStageResult.conflicts) === null || _13 === void 0 ? void 0 : _13.length)
62616
+ if ((_19 = qualifyingStageResult.conflicts) === null || _19 === void 0 ? void 0 : _19.length)
62590
62617
  qualifyingConflicts.push.apply(qualifyingConflicts, __spreadArray([], __read(qualifyingStageResult.conflicts), false));
62591
- if ((_14 = qualifyingStageResult.positioningReport) === null || _14 === void 0 ? void 0 : _14.length)
62618
+ if ((_20 = qualifyingStageResult.positioningReport) === null || _20 === void 0 ? void 0 : _20.length)
62592
62619
  positioningReports.push((_h = {},
62593
62620
  _h[QUALIFYING] = qualifyingStageResult.positioningReport,
62594
62621
  _h));
@@ -62607,7 +62634,7 @@ function generateDrawDefinition(params) {
62607
62634
  catch (e_5_1) { e_5 = { error: e_5_1 }; }
62608
62635
  finally {
62609
62636
  try {
62610
- if (_26 && !_26.done && (_f = _25.return)) _f.call(_25);
62637
+ if (_32 && !_32.done && (_f = _31.return)) _f.call(_31);
62611
62638
  }
62612
62639
  finally { if (e_5) throw e_5.error; }
62613
62640
  }
@@ -62630,7 +62657,7 @@ function generateDrawDefinition(params) {
62630
62657
  drawDefinition.links = [];
62631
62658
  drawDefinition.links.push(link);
62632
62659
  }
62633
- drawDefinition.drawName = (_15 = params.drawName) !== null && _15 !== void 0 ? _15 : drawType;
62660
+ drawDefinition.drawName = (_21 = params.drawName) !== null && _21 !== void 0 ? _21 : drawType;
62634
62661
  if (typeof voluntaryConsolation === 'object') {
62635
62662
  addVoluntaryConsolationStructure(__assign(__assign({}, voluntaryConsolation), { tournamentRecord: tournamentRecord, appliedPolicies: appliedPolicies, drawDefinition: drawDefinition, matchUpType: matchUpType }));
62636
62663
  }