tods-competition-factory 1.7.12 → 1.7.13

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.7.12';
365
+ return '1.7.13';
366
366
  }
367
367
 
368
368
  /******************************************************************************
@@ -31969,9 +31969,10 @@ function getCompetitionPenalties(_a) {
31969
31969
  }
31970
31970
 
31971
31971
  function getTieFormat$1(_a) {
31972
- var _b, _c;
31972
+ var _b, _c, _d;
31973
31973
  var drawDefinition = _a.drawDefinition, structureId = _a.structureId, matchUpId = _a.matchUpId, structure = _a.structure, matchUp = _a.matchUp, eventId = _a.eventId, // optional - if an eventId is present only return tieFormat for event
31974
31974
  event = _a.event;
31975
+ var stack = 'getTieFormat';
31975
31976
  var tieFormat;
31976
31977
  structureId = (_b = structure === null || structure === void 0 ? void 0 : structure.structureId) !== null && _b !== void 0 ? _b : structureId;
31977
31978
  matchUpId = (_c = matchUp === null || matchUp === void 0 ? void 0 : matchUp.matchUpId) !== null && _c !== void 0 ? _c : matchUpId;
@@ -31989,6 +31990,9 @@ function getTieFormat$1(_a) {
31989
31990
  });
31990
31991
  if (result.error)
31991
31992
  return result;
31993
+ if (((_d = result.matchUp) === null || _d === void 0 ? void 0 : _d.matchUpType) !== TEAM_MATCHUP) {
31994
+ return decorateResult({ result: { error: INVALID_MATCHUP }, stack: stack });
31995
+ }
31992
31996
  if (!structure)
31993
31997
  structure = result.structure;
31994
31998
  if (!matchUp)
@@ -32031,7 +32035,7 @@ function getTieFormat$1(_a) {
32031
32035
  tieFormat = getObjectTieFormat(drawDefinition) || getObjectTieFormat(event);
32032
32036
  }
32033
32037
  if (!tieFormat)
32034
- return decorateResult({ result: { error: MISSING_TIE_FORMAT } });
32038
+ return decorateResult({ result: { error: MISSING_TIE_FORMAT }, stack: stack });
32035
32039
  return __assign(__assign({}, SUCCESS), { tieFormat: tieFormat, matchUp: matchUp, structure: structure });
32036
32040
  }
32037
32041
 
@@ -32267,23 +32271,39 @@ function updateTieFormat(_a) {
32267
32271
 
32268
32272
  // all child matchUps need to be checked for collectionAssignments / collectionPositions which need to be removed when collectionDefinition.collectionIds are removed
32269
32273
  function modifyCollectionDefinition$1(_a) {
32270
- var _b;
32271
- var _c = _a.updateInProgressMatchUps, updateInProgressMatchUps = _c === void 0 ? false : _c, tournamentRecord = _a.tournamentRecord, collectionOrder = _a.collectionOrder, collectionName = _a.collectionName, drawDefinition = _a.drawDefinition, matchUpFormat = _a.matchUpFormat, tieFormatName = _a.tieFormatName, matchUpCount = _a.matchUpCount, collectionId = _a.collectionId, matchUpType = _a.matchUpType, structureId = _a.structureId, matchUpId = _a.matchUpId, category = _a.category, eventId = _a.eventId, gender = _a.gender, event = _a.event,
32274
+ var _b, _c, _d;
32275
+ var _e = _a.updateInProgressMatchUps, updateInProgressMatchUps = _e === void 0 ? false : _e, tournamentRecord = _a.tournamentRecord, collectionOrder = _a.collectionOrder, collectionName = _a.collectionName, tieFormatName = _a.tieFormatName, drawDefinition = _a.drawDefinition, matchUpFormat = _a.matchUpFormat, matchUpCount = _a.matchUpCount, collectionId = _a.collectionId, matchUpType = _a.matchUpType, structureId = _a.structureId, matchUpId = _a.matchUpId, category = _a.category, eventId = _a.eventId, gender = _a.gender, event = _a.event,
32272
32276
  // value assignment, only one is allowed to have a value
32273
32277
  collectionValueProfiles = _a.collectionValueProfiles, collectionValue = _a.collectionValue, matchUpValue = _a.matchUpValue, scoreValue = _a.scoreValue, setValue = _a.setValue;
32278
+ var stack = 'modifyCollectionDefinition';
32274
32279
  if (matchUpFormat && !isValid(matchUpFormat)) {
32275
- return { error: INVALID_VALUES };
32280
+ return decorateResult({
32281
+ result: { error: INVALID_VALUES },
32282
+ context: { matchUpFormat: matchUpFormat },
32283
+ stack: stack,
32284
+ });
32276
32285
  }
32277
32286
  if (collectionName && typeof collectionName !== 'string') {
32278
- return { error: INVALID_VALUES };
32287
+ return decorateResult({
32288
+ result: { error: INVALID_VALUES },
32289
+ context: { collectionName: collectionName },
32290
+ stack: stack,
32291
+ });
32279
32292
  }
32280
32293
  if (gender && !Object.values(genderConstants).includes(gender)) {
32281
- return { error: INVALID_VALUES };
32294
+ return decorateResult({
32295
+ result: { error: INVALID_VALUES },
32296
+ context: { gender: gender },
32297
+ stack: stack,
32298
+ });
32282
32299
  }
32283
32300
  if (category && typeof category !== 'object') {
32284
- return { error: INVALID_VALUES };
32301
+ return decorateResult({
32302
+ result: { error: INVALID_VALUES },
32303
+ context: { category: category },
32304
+ stack: stack,
32305
+ });
32285
32306
  }
32286
- var stack = 'modifyCollectionDefinition';
32287
32307
  var valueAssignments = {
32288
32308
  collectionValueProfiles: collectionValueProfiles,
32289
32309
  collectionValue: collectionValue,
@@ -32299,10 +32319,8 @@ function modifyCollectionDefinition$1(_a) {
32299
32319
  return decorateResult({ result: { error: MISSING_VALUE }, stack: stack });
32300
32320
  if (Object.values(valueAssignments).filter(Boolean).length > 1)
32301
32321
  return decorateResult({
32302
- result: {
32303
- info: 'Only one value assignment allowed per collectionDefinition',
32304
- error: INVALID_VALUES,
32305
- },
32322
+ info: 'Only one value assignment allowed per collectionDefinition',
32323
+ result: { error: INVALID_VALUES },
32306
32324
  stack: stack,
32307
32325
  });
32308
32326
  var result = getTieFormat$1({
@@ -32312,42 +32330,73 @@ function modifyCollectionDefinition$1(_a) {
32312
32330
  eventId: eventId,
32313
32331
  event: event,
32314
32332
  });
32315
- if (result.error)
32333
+ if (result.error) {
32316
32334
  return decorateResult({ result: result, stack: stack });
32335
+ }
32317
32336
  var matchUp = result.matchUp, structure = result.structure, existingTieFormat = result.tieFormat;
32318
32337
  var tieFormat = copyTieFormat(existingTieFormat);
32319
- var collectionDefinition = tieFormat.collectionDefinitions.find(function (collectionDefinition) { return collectionDefinition.collectionId === collectionId; });
32320
- if (!collectionDefinition)
32338
+ var sourceCollectionDefinition = existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.collectionDefinitions.find(function (collectionDefinition) {
32339
+ return collectionDefinition.collectionId === collectionId;
32340
+ });
32341
+ var targetCollectionDefinition = tieFormat === null || tieFormat === void 0 ? void 0 : tieFormat.collectionDefinitions.find(function (collectionDefinition) { return collectionDefinition.collectionId === collectionId; });
32342
+ if (!sourceCollectionDefinition)
32321
32343
  return decorateResult({ result: { error: NOT_FOUND }, stack: stack });
32322
- var value = collectionValue || matchUpValue || scoreValue || setValue;
32323
- if (value || collectionValueProfiles) {
32324
- if (value) {
32325
- if (!isConvertableInteger(value))
32326
- return decorateResult({ result: { error: INVALID_VALUES, value: value } });
32327
- }
32328
- else if (collectionValueProfiles) {
32329
- var result_1 = validateCollectionValueProfile({
32330
- matchUpCount: collectionDefinition.matchUpCount,
32331
- collectionValueProfiles: collectionValueProfiles,
32344
+ var value = (_c = (_b = collectionValue !== null && collectionValue !== void 0 ? collectionValue : matchUpValue) !== null && _b !== void 0 ? _b : scoreValue) !== null && _c !== void 0 ? _c : setValue;
32345
+ if (collectionValueProfiles) {
32346
+ var result_1 = validateCollectionValueProfile({
32347
+ matchUpCount: matchUpCount || (sourceCollectionDefinition === null || sourceCollectionDefinition === void 0 ? void 0 : sourceCollectionDefinition.matchUpCount),
32348
+ collectionValueProfiles: collectionValueProfiles,
32349
+ });
32350
+ if (result_1.errors) {
32351
+ return decorateResult({
32352
+ result: { error: INVALID_VALUES },
32353
+ info: result_1.errors,
32354
+ stack: stack,
32332
32355
  });
32333
- if (result_1.errors) {
32334
- return decorateResult({
32335
- result: { error: INVALID_VALUES, info: result_1.errors },
32336
- stack: stack,
32337
- });
32338
- }
32339
32356
  }
32357
+ }
32358
+ else if (value && !isConvertableInteger(value)) {
32359
+ return decorateResult({
32360
+ result: { error: INVALID_VALUES },
32361
+ info: 'value is not an integer',
32362
+ context: { value: value },
32363
+ stack: stack,
32364
+ });
32365
+ }
32366
+ var equivalentValueProfiles = function (a, b) {
32367
+ return intersection(Object.keys(a), Object.keys(b)).length ===
32368
+ Object.keys(a).length &&
32369
+ intersection(Object.values(a), Object.values(b)).length ===
32370
+ Object.values(a).length;
32371
+ };
32372
+ var valueProfileModified = collectionValueProfiles &&
32373
+ (!sourceCollectionDefinition.collectionValueProfiles ||
32374
+ !equivalentValueProfiles(sourceCollectionDefinition.collectionValueProfiles, collectionValueProfiles));
32375
+ var valueModified = (isConvertableInteger(collectionValue) &&
32376
+ sourceCollectionDefinition.collectionValue !== collectionValue) ||
32377
+ (isConvertableInteger(matchUpValue) &&
32378
+ sourceCollectionDefinition.matchUpValue !== matchUpValue) ||
32379
+ (isConvertableInteger(scoreValue) &&
32380
+ sourceCollectionDefinition.scoreValue !== scoreValue) ||
32381
+ (isConvertableInteger(setValue) &&
32382
+ sourceCollectionDefinition.setValue !== setValue) ||
32383
+ valueProfileModified;
32384
+ var modifications = [];
32385
+ if (valueModified) {
32340
32386
  // cleanup any previously existing value assignment
32341
- collectionDefinition.collectionValue = undefined;
32342
- collectionDefinition.matchUpValue = undefined;
32343
- collectionDefinition.scoreValue = undefined;
32344
- collectionDefinition.setValue = undefined;
32387
+ targetCollectionDefinition.collectionValueProfiles = undefined;
32388
+ targetCollectionDefinition.collectionValue = undefined;
32389
+ targetCollectionDefinition.matchUpValue = undefined;
32390
+ targetCollectionDefinition.scoreValue = undefined;
32391
+ targetCollectionDefinition.setValue = undefined;
32345
32392
  // add new value assignment
32346
- Object.assign(collectionDefinition, valueAssignments);
32393
+ Object.assign(targetCollectionDefinition, valueAssignments);
32394
+ modifications.push(__assign({ collectionId: collectionId }, definedAttributes(valueAssignments)));
32347
32395
  }
32348
32396
  // must remove all collectionGroups which contain the collection which has been modified
32349
- if ((scoreValue || setValue) && collectionDefinition.collectionGroupNumber) {
32350
- var targetCollectionGroupNumber_1 = collectionDefinition.collectionGroupNumber;
32397
+ if ((isConvertableInteger(scoreValue) || isConvertableInteger(setValue)) &&
32398
+ targetCollectionDefinition.collectionGroupNumber) {
32399
+ var targetCollectionGroupNumber_1 = targetCollectionDefinition.collectionGroupNumber;
32351
32400
  tieFormat.collectionDefinitions = tieFormat.collectionDefinitions.map(function (collectionDefinition) {
32352
32401
  var collectionGroupNumber = collectionDefinition.collectionGroupNumber, rest = __rest(collectionDefinition, ["collectionGroupNumber"]);
32353
32402
  if (collectionGroupNumber === targetCollectionGroupNumber_1) {
@@ -32361,37 +32410,85 @@ function modifyCollectionDefinition$1(_a) {
32361
32410
  var groupNumber = _a.groupNumber;
32362
32411
  return groupNumber !== targetCollectionGroupNumber_1;
32363
32412
  });
32413
+ modifications.push({
32414
+ collectionId: collectionId,
32415
+ change: 'collectionGroupNumber removed',
32416
+ });
32364
32417
  }
32365
32418
  // calculate new winCriteria for tieFormat
32366
32419
  // if existing winCriteria is aggregateValue, retain
32367
- var _d = calculateWinCriteria(tieFormat), aggregateValue = _d.aggregateValue, valueGoal = _d.valueGoal;
32368
- tieFormat.winCriteria = definedAttributes({ aggregateValue: aggregateValue, valueGoal: valueGoal });
32369
- // if valueGoal has changed, force renaming of the tieFormat
32370
- var originalValueGoal = existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.winCriteria.valueGoal;
32371
- var wasAggregateValue = existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.winCriteria.aggregateValue;
32372
- if ((originalValueGoal && originalValueGoal !== valueGoal) ||
32373
- (aggregateValue && !wasAggregateValue)) {
32374
- delete tieFormat.tieFormatName;
32375
- }
32376
- if (tieFormatName)
32377
- tieFormat.tieFormatName = tieFormatName;
32378
- if (collectionOrder)
32379
- collectionDefinition.collectionOrder = collectionOrder;
32380
- if (collectionName)
32381
- collectionDefinition.collectionName = collectionName;
32382
- if (matchUpFormat)
32383
- collectionDefinition.matchUpFormat = matchUpFormat;
32384
- // if (matchUpCount) collectionDefinition.matchUpCount = matchUpCount; // TODO: need to calculate tieMatchUp additions/deletions
32385
- if (matchUpType)
32386
- collectionDefinition.matchUpType = matchUpType;
32387
- if (category)
32388
- collectionDefinition.category = category;
32389
- if (gender)
32390
- collectionDefinition.gender = gender; // TODO: remove all inappropriately gendered participants
32420
+ var _f = calculateWinCriteria(tieFormat), aggregateValue = _f.aggregateValue, valueGoal = _f.valueGoal;
32421
+ var winCriteria = definedAttributes({ aggregateValue: aggregateValue, valueGoal: valueGoal });
32422
+ if (winCriteria.aggregateValue !==
32423
+ (existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.winCriteria.aggregateValue) ||
32424
+ winCriteria.valueGoal !== (existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.winCriteria.valueGoal)) {
32425
+ tieFormat.winCriteria = winCriteria;
32426
+ modifications.push({ collectionId: collectionId, winCriteria: winCriteria });
32427
+ }
32428
+ if (isConvertableInteger(collectionOrder) &&
32429
+ sourceCollectionDefinition.collectionOrder !== collectionOrder) {
32430
+ targetCollectionDefinition.collectionOrder = collectionOrder;
32431
+ modifications.push({ collectionId: collectionId, collectionOrder: collectionOrder });
32432
+ }
32433
+ if (collectionName &&
32434
+ sourceCollectionDefinition.collectionName !== collectionName) {
32435
+ targetCollectionDefinition.collectionName = collectionName;
32436
+ modifications.push({ collectionId: collectionId, collectionName: collectionName });
32437
+ }
32438
+ if (matchUpFormat &&
32439
+ sourceCollectionDefinition.matchUpFormat !== matchUpFormat) {
32440
+ targetCollectionDefinition.matchUpFormat = matchUpFormat;
32441
+ modifications.push({ collectionId: collectionId, matchUpFormat: matchUpFormat });
32442
+ }
32443
+ if (isConvertableInteger(matchUpCount) &&
32444
+ sourceCollectionDefinition.matchUpCount !== matchUpCount) {
32445
+ // TODO: need to calculate tieMatchUp additions/deletions
32446
+ // targetCollectionDefinition.matchUpCount = matchUpCount;
32447
+ // modifications.push({ structureId, matchUpCount });
32448
+ return decorateResult({
32449
+ result: { error: NOT_IMPLEMENTED },
32450
+ context: { matchUpCount: matchUpCount },
32451
+ stack: stack,
32452
+ });
32453
+ }
32454
+ if (matchUpType && sourceCollectionDefinition.matchUpType !== matchUpType) {
32455
+ // targetCollectionDefinition.matchUpType = matchUpType;
32456
+ // modifications.push({ collectionId, matchUpType });
32457
+ return decorateResult({
32458
+ result: { error: NOT_IMPLEMENTED },
32459
+ context: { matchUpType: matchUpType },
32460
+ stack: stack,
32461
+ });
32462
+ }
32463
+ if (category && sourceCollectionDefinition.category !== category) {
32464
+ targetCollectionDefinition.category = category;
32465
+ modifications.push({ collectionId: collectionId, category: category });
32466
+ }
32467
+ if (gender && sourceCollectionDefinition.gender !== gender) {
32468
+ // TODO: remove all inappropriately gendered participants
32469
+ targetCollectionDefinition.gender = gender;
32470
+ modifications.push({ collectionId: collectionId, gender: gender });
32471
+ }
32391
32472
  var prunedTieFormat = definedAttributes(tieFormat);
32392
32473
  result = validateTieFormat({ tieFormat: prunedTieFormat });
32393
- if (result.error)
32474
+ if (result.error) {
32394
32475
  return decorateResult({ result: result, stack: stack });
32476
+ }
32477
+ if (!modifications.length) {
32478
+ return decorateResult({ result: __assign(__assign({}, SUCCESS), { modifications: modifications }) });
32479
+ }
32480
+ // Note: this logic needs to exist both here and in `modifyTieFormat`
32481
+ // it is duplicated because this method can be called independently
32482
+ var changedTieFormatName = (existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.tieFormatName) !== tieFormatName;
32483
+ // if tieFormat has changed, force renaming of the tieFormat
32484
+ if (changedTieFormatName) {
32485
+ prunedTieFormat.tieFormatName = tieFormatName;
32486
+ modifications.push({ tieFormatName: tieFormatName });
32487
+ }
32488
+ else if (modifications.length) {
32489
+ delete prunedTieFormat.tieFormatName;
32490
+ modifications.push('tieFormatName removed: modifications without new tieFormatName');
32491
+ }
32395
32492
  result = updateTieFormat({
32396
32493
  tieFormat: prunedTieFormat,
32397
32494
  updateInProgressMatchUps: updateInProgressMatchUps,
@@ -32404,10 +32501,10 @@ function modifyCollectionDefinition$1(_a) {
32404
32501
  });
32405
32502
  if (!result.error) {
32406
32503
  var appliedPolicies = getAppliedPolicies({ tournamentRecord: tournamentRecord }).appliedPolicies;
32407
- if ((_b = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.audit) === null || _b === void 0 ? void 0 : _b[TIE_FORMAT_MODIFICATIONS]) {
32504
+ if ((_d = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.audit) === null || _d === void 0 ? void 0 : _d[TIE_FORMAT_MODIFICATIONS]) {
32408
32505
  var auditData = definedAttributes({
32506
+ collectionDefinition: targetCollectionDefinition,
32409
32507
  drawId: drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.drawId,
32410
- collectionDefinition: collectionDefinition,
32411
32508
  action: stack,
32412
32509
  structureId: structureId,
32413
32510
  matchUpId: matchUpId,
@@ -32416,7 +32513,7 @@ function modifyCollectionDefinition$1(_a) {
32416
32513
  tieFormatTelemetry({ drawDefinition: drawDefinition, auditData: auditData });
32417
32514
  }
32418
32515
  }
32419
- return decorateResult({ result: result, stack: stack });
32516
+ return decorateResult({ result: __assign(__assign({}, result), { modifications: modifications }), stack: stack });
32420
32517
  }
32421
32518
 
32422
32519
  function resolveTournamentRecord(params) {
@@ -32976,10 +33073,10 @@ function addCollectionDefinition$1(_a) {
32976
33073
  return collectionId;
32977
33074
  });
32978
33075
  if (collectionIds.includes(collectionDefinition.collectionId))
32979
- return {
32980
- collectionId: collectionDefinition.collectionId,
32981
- error: DUPLICATE_VALUE,
32982
- };
33076
+ return decorateResult({
33077
+ context: { collectionId: collectionDefinition.collectionId },
33078
+ result: { error: DUPLICATE_VALUE },
33079
+ });
32983
33080
  }
32984
33081
  tieFormat.collectionDefinitions.push(collectionDefinition);
32985
33082
  tieFormat.collectionDefinitions
@@ -33082,7 +33179,10 @@ function addCollectionDefinition$1(_a) {
33082
33179
  }
33083
33180
  else if (matchUpId && matchUp) {
33084
33181
  if (!validUpdate({ matchUp: matchUp, updateInProgressMatchUps: updateInProgressMatchUps }))
33085
- return { error: CANNOT_MODIFY_TIEFORMAT };
33182
+ return decorateResult({
33183
+ result: { error: CANNOT_MODIFY_TIEFORMAT },
33184
+ stack: stack,
33185
+ });
33086
33186
  matchUp.tieFormat = prunedTieFormat;
33087
33187
  var newMatchUps = generateCollectionMatchUps({
33088
33188
  collectionDefinition: collectionDefinition,
@@ -33149,7 +33249,7 @@ function addCollectionDefinition$1(_a) {
33149
33249
  });
33150
33250
  tieFormatTelemetry({ drawDefinition: drawDefinition, auditData: auditData });
33151
33251
  }
33152
- return __assign(__assign({}, SUCCESS), { tieFormat: prunedTieFormat, targetMatchUps: targetMatchUps, addedMatchUps: addedMatchUps });
33252
+ return __assign({ tieFormat: prunedTieFormat, targetMatchUps: targetMatchUps, addedMatchUps: addedMatchUps }, SUCCESS);
33153
33253
  }
33154
33254
  function updateStructureMatchUps(_a) {
33155
33255
  var e_4, _b, _c;
@@ -33637,7 +33737,8 @@ function addCollectionGroup(params) {
33637
33737
 
33638
33738
  function modifyTieFormat$1(_a) {
33639
33739
  var e_1, _b, e_2, _c, e_3, _d;
33640
- var _e = _a.updateInProgressMatchUps, updateInProgressMatchUps = _e === void 0 ? false : _e, tieFormatComparison = _a.tieFormatComparison, modifiedTieFormat = _a.modifiedTieFormat, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, structureId = _a.structureId, matchUpId = _a.matchUpId, eventId = _a.eventId, uuids = _a.uuids, event = _a.event;
33740
+ var _e;
33741
+ var _f = _a.updateInProgressMatchUps, updateInProgressMatchUps = _f === void 0 ? false : _f, tieFormatComparison = _a.tieFormatComparison, modifiedTieFormat = _a.modifiedTieFormat, tournamentRecord = _a.tournamentRecord, drawDefinition = _a.drawDefinition, structureId = _a.structureId, matchUpId = _a.matchUpId, eventId = _a.eventId, uuids = _a.uuids, event = _a.event;
33641
33742
  var stack = 'updateTieFormat';
33642
33743
  if (!validateTieFormat(modifiedTieFormat))
33643
33744
  return { error: INVALID_TIE_FORMAT };
@@ -33652,35 +33753,32 @@ function modifyTieFormat$1(_a) {
33652
33753
  return decorateResult({ result: result, stack: stack });
33653
33754
  var matchUp = result.matchUp, existingTieFormat = result.tieFormat;
33654
33755
  var tieFormat = copyTieFormat(existingTieFormat);
33756
+ if (!((_e = compareTieFormats({ ancestor: tieFormat, descendant: modifiedTieFormat })) === null || _e === void 0 ? void 0 : _e.different)) {
33757
+ return __assign({}, SUCCESS);
33758
+ }
33655
33759
  var existingCollectionIds = tieFormat.collectionDefinitions.map(function (_a) {
33656
33760
  var collectionId = _a.collectionId;
33657
33761
  return collectionId;
33658
33762
  });
33659
- var modifiedCollectionDefinitions = [];
33660
- var addedCollectionDefinitions = [];
33661
- var updatedCollectionIds = [];
33662
- modifiedTieFormat.collectionDefinitions.forEach(function (def) {
33663
- var _a;
33664
- updatedCollectionIds.push(def.collectionId);
33665
- if (modifiedTieFormat && existingCollectionIds.includes(def.collectionId)) {
33666
- ((_a = compareTieFormats({
33667
- descendant: modifiedTieFormat,
33668
- ancestor: tieFormat,
33669
- })) === null || _a === void 0 ? void 0 : _a.different) && modifiedCollectionDefinitions.push(def);
33670
- }
33671
- else {
33672
- addedCollectionDefinitions.push(def);
33673
- }
33763
+ var updatedCollectionIds = modifiedTieFormat.collectionDefinitions.map(function (_a) {
33764
+ var collectionId = _a.collectionId;
33765
+ return collectionId;
33674
33766
  });
33675
33767
  var removedCollectionIds = existingCollectionIds.filter(function (collectionId) { return !updatedCollectionIds.includes(collectionId); });
33676
- var tieFormatName = modifiedTieFormat.tieFormatName;
33768
+ var addedCollectionDefinitions = modifiedTieFormat.collectionDefinitions.filter(function (_a) {
33769
+ var collectionId = _a.collectionId;
33770
+ return !existingCollectionIds.includes(collectionId);
33771
+ });
33772
+ var modifications = [];
33677
33773
  var processedTieFormat;
33678
33774
  try {
33679
33775
  // TODO: if matchUpCount is changing pre-check for cmopleted tieMatchUps
33680
33776
  // TODO: if gender is changing pre-check for misgendered collectionAssignments
33681
- for (var modifiedCollectionDefinitions_1 = __values(modifiedCollectionDefinitions), modifiedCollectionDefinitions_1_1 = modifiedCollectionDefinitions_1.next(); !modifiedCollectionDefinitions_1_1.done; modifiedCollectionDefinitions_1_1 = modifiedCollectionDefinitions_1.next()) {
33682
- var collectionDefinition = modifiedCollectionDefinitions_1_1.value;
33683
- var result_1 = modifyCollectionDefinition$1(__assign(__assign({ updateInProgressMatchUps: updateInProgressMatchUps }, collectionDefinition), { tournamentRecord: tournamentRecord, drawDefinition: drawDefinition, tieFormatName: tieFormatName, structureId: structureId, matchUpId: matchUpId, eventId: eventId, event: event }));
33777
+ for (var _g = __values(modifiedTieFormat.collectionDefinitions), _h = _g.next(); !_h.done; _h = _g.next()) {
33778
+ var collectionDefinition = _h.value;
33779
+ var result_1 = modifyCollectionDefinition$1(__assign(__assign({ updateInProgressMatchUps: updateInProgressMatchUps }, collectionDefinition), { tournamentRecord: tournamentRecord, drawDefinition: drawDefinition, structureId: structureId, matchUpId: matchUpId, eventId: eventId, event: event }));
33780
+ if (result_1.modifications)
33781
+ modifications.push.apply(modifications, __spreadArray([], __read(result_1.modifications), false));
33684
33782
  if (result_1.error)
33685
33783
  return decorateResult({ result: result_1, stack: stack });
33686
33784
  if (result_1.tieFormat)
@@ -33690,10 +33788,11 @@ function modifyTieFormat$1(_a) {
33690
33788
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
33691
33789
  finally {
33692
33790
  try {
33693
- if (modifiedCollectionDefinitions_1_1 && !modifiedCollectionDefinitions_1_1.done && (_b = modifiedCollectionDefinitions_1.return)) _b.call(modifiedCollectionDefinitions_1);
33791
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
33694
33792
  }
33695
33793
  finally { if (e_1) throw e_1.error; }
33696
33794
  }
33795
+ var tieFormatName = modifiedTieFormat.tieFormatName;
33697
33796
  try {
33698
33797
  for (var addedCollectionDefinitions_1 = __values(addedCollectionDefinitions), addedCollectionDefinitions_1_1 = addedCollectionDefinitions_1.next(); !addedCollectionDefinitions_1_1.done; addedCollectionDefinitions_1_1 = addedCollectionDefinitions_1.next()) {
33699
33798
  var collectionDefinition = addedCollectionDefinitions_1_1.value;
@@ -33752,6 +33851,16 @@ function modifyTieFormat$1(_a) {
33752
33851
  }
33753
33852
  finally { if (e_3) throw e_3.error; }
33754
33853
  }
33854
+ var changedTieFormatName = (existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.tieFormatName) !== tieFormatName;
33855
+ // if tieFormat has changed, force renaming of the tieFormat
33856
+ if (changedTieFormatName) {
33857
+ processedTieFormat.tieFormatName = tieFormatName;
33858
+ modifications.push({ tieFormatName: tieFormatName });
33859
+ }
33860
+ else if (modifications.length) {
33861
+ delete processedTieFormat.tieFormatName;
33862
+ modifications.push('tieFormatName removed: modifications without new tieFormatName');
33863
+ }
33755
33864
  processedTieFormat.collectionDefinitions =
33756
33865
  processedTieFormat.collectionDefinitions
33757
33866
  .sort(function (a, b) {
@@ -33759,7 +33868,7 @@ function modifyTieFormat$1(_a) {
33759
33868
  numericSortValue(b.collectionOrder);
33760
33869
  })
33761
33870
  .map(function (def, i) { return (__assign(__assign({}, def), { collectionOrder: i + 1 })); });
33762
- return __assign(__assign({}, SUCCESS), { processedTieFormat: processedTieFormat });
33871
+ return __assign(__assign({}, SUCCESS), { processedTieFormat: processedTieFormat, modifications: modifications });
33763
33872
  }
33764
33873
 
33765
33874
  function modifyTieFormat(params) {