tods-competition-factory 1.7.11 → 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.11';
365
+ return '1.7.13';
366
366
  }
367
367
 
368
368
  /******************************************************************************
@@ -18241,7 +18241,6 @@ function compareTieFormats(_a) {
18241
18241
  return collectionOrder;
18242
18242
  })
18243
18243
  .join('|'));
18244
- var different = nameDifference || orderDifference || ancestorDesc !== descendantDesc;
18245
18244
  var descendantCollectionDefinitions = Object.assign.apply(Object, __spreadArray([{}], __read(((descendant === null || descendant === void 0 ? void 0 : descendant.collectionDefinitions) || []).map(function (collectionDefinition) {
18246
18245
  var _a;
18247
18246
  return (_a = {},
@@ -18256,8 +18255,8 @@ function compareTieFormats(_a) {
18256
18255
  })), false));
18257
18256
  descendantDifferences.collectionIds = difference(Object.keys(descendantCollectionDefinitions), Object.keys(ancestorCollectionDefinitions));
18258
18257
  ancestorDifferences.collectionIds = difference(Object.keys(ancestorCollectionDefinitions), Object.keys(descendantCollectionDefinitions));
18259
- descendantDifferences.collectionsValue = getCollectionsValue(descendantCollectionDefinitions, descendantDifferences);
18260
- ancestorDifferences.collectionsValue = getCollectionsValue(ancestorCollectionDefinitions, ancestorDifferences);
18258
+ descendantDifferences.collectionsValue = getCollectionsValue(descendantCollectionDefinitions);
18259
+ ancestorDifferences.collectionsValue = getCollectionsValue(ancestorCollectionDefinitions);
18261
18260
  descendantDifferences.groupsCount =
18262
18261
  (_c = (_b = ancestor === null || ancestor === void 0 ? void 0 : ancestor.collectionGroups) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : (0 - ((_e = (_d = descendant === null || descendant === void 0 ? void 0 : descendant.collectionGroups) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) || 0);
18263
18262
  ancestorDifferences.groupsCount = descendantDifferences.groupsCount
@@ -18267,20 +18266,32 @@ function compareTieFormats(_a) {
18267
18266
  ancestorDifferences.collectionsValue.totalValue;
18268
18267
  var matchUpCountDifference = descendantDifferences.collectionsValue.totalMatchUps -
18269
18268
  ancestorDifferences.collectionsValue.totalMatchUps;
18269
+ var different = nameDifference ||
18270
+ orderDifference ||
18271
+ ancestorDesc !== descendantDesc ||
18272
+ valueDifference !== 0;
18270
18273
  return __assign(__assign({ matchUpFormatDifferences: matchUpFormatDifferences, matchUpCountDifference: matchUpCountDifference, descendantDifferences: descendantDifferences, ancestorDifferences: ancestorDifferences, orderDifference: orderDifference, valueDifference: valueDifference, nameDifference: nameDifference, descendantDesc: descendantDesc, ancestorDesc: ancestorDesc }, SUCCESS), { different: different });
18271
18274
  }
18272
- function getCollectionsValue(definitions, aggregator) {
18275
+ function getCollectionsValue(definitions) {
18273
18276
  var totalMatchUps = 0;
18274
- var totalValue = aggregator.collectionIds.reduce(function (total, collectionId) {
18277
+ var collectionIds = Object.keys(definitions);
18278
+ var totalValue = collectionIds.reduce(function (total, collectionId) {
18275
18279
  var collectionDefinition = definitions[collectionId];
18276
- var collectionValueProfiles = collectionDefinition.collectionValueProfiles, collectionValue = collectionDefinition.collectionValue, matchUpCount = collectionDefinition.matchUpCount, matchUpValue = collectionDefinition.matchUpValue;
18280
+ var collectionValueProfiles = collectionDefinition.collectionValueProfiles, collectionValue = collectionDefinition.collectionValue, matchUpCount = collectionDefinition.matchUpCount, matchUpValue = collectionDefinition.matchUpValue, scoreValue = collectionDefinition.scoreValue, setValue = collectionDefinition.setValue;
18277
18281
  totalMatchUps += matchUpCount;
18278
18282
  if (collectionValueProfiles)
18279
18283
  return (total +
18280
18284
  collectionValueProfiles.reduce(function (total, profile) { return total + profile.value; }, 0));
18281
- if (matchUpValue && matchUpCount)
18282
- return total + matchUpValue * matchUpCount;
18283
- return total + collectionValue;
18285
+ if (matchUpCount) {
18286
+ if (isConvertableInteger(matchUpValue))
18287
+ return total + matchUpValue * matchUpCount;
18288
+ if (isConvertableInteger(scoreValue))
18289
+ return total + scoreValue * matchUpCount;
18290
+ if (isConvertableInteger(setValue))
18291
+ return total + setValue * matchUpCount;
18292
+ return total + collectionValue;
18293
+ }
18294
+ return total;
18284
18295
  }, 0);
18285
18296
  return { totalValue: totalValue, totalMatchUps: totalMatchUps };
18286
18297
  }
@@ -31958,9 +31969,10 @@ function getCompetitionPenalties(_a) {
31958
31969
  }
31959
31970
 
31960
31971
  function getTieFormat$1(_a) {
31961
- var _b, _c;
31972
+ var _b, _c, _d;
31962
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
31963
31974
  event = _a.event;
31975
+ var stack = 'getTieFormat';
31964
31976
  var tieFormat;
31965
31977
  structureId = (_b = structure === null || structure === void 0 ? void 0 : structure.structureId) !== null && _b !== void 0 ? _b : structureId;
31966
31978
  matchUpId = (_c = matchUp === null || matchUp === void 0 ? void 0 : matchUp.matchUpId) !== null && _c !== void 0 ? _c : matchUpId;
@@ -31978,6 +31990,9 @@ function getTieFormat$1(_a) {
31978
31990
  });
31979
31991
  if (result.error)
31980
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
+ }
31981
31996
  if (!structure)
31982
31997
  structure = result.structure;
31983
31998
  if (!matchUp)
@@ -32020,7 +32035,7 @@ function getTieFormat$1(_a) {
32020
32035
  tieFormat = getObjectTieFormat(drawDefinition) || getObjectTieFormat(event);
32021
32036
  }
32022
32037
  if (!tieFormat)
32023
- return decorateResult({ result: { error: MISSING_TIE_FORMAT } });
32038
+ return decorateResult({ result: { error: MISSING_TIE_FORMAT }, stack: stack });
32024
32039
  return __assign(__assign({}, SUCCESS), { tieFormat: tieFormat, matchUp: matchUp, structure: structure });
32025
32040
  }
32026
32041
 
@@ -32256,23 +32271,39 @@ function updateTieFormat(_a) {
32256
32271
 
32257
32272
  // all child matchUps need to be checked for collectionAssignments / collectionPositions which need to be removed when collectionDefinition.collectionIds are removed
32258
32273
  function modifyCollectionDefinition$1(_a) {
32259
- var _b;
32260
- 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,
32261
32276
  // value assignment, only one is allowed to have a value
32262
32277
  collectionValueProfiles = _a.collectionValueProfiles, collectionValue = _a.collectionValue, matchUpValue = _a.matchUpValue, scoreValue = _a.scoreValue, setValue = _a.setValue;
32278
+ var stack = 'modifyCollectionDefinition';
32263
32279
  if (matchUpFormat && !isValid(matchUpFormat)) {
32264
- return { error: INVALID_VALUES };
32280
+ return decorateResult({
32281
+ result: { error: INVALID_VALUES },
32282
+ context: { matchUpFormat: matchUpFormat },
32283
+ stack: stack,
32284
+ });
32265
32285
  }
32266
32286
  if (collectionName && typeof collectionName !== 'string') {
32267
- return { error: INVALID_VALUES };
32287
+ return decorateResult({
32288
+ result: { error: INVALID_VALUES },
32289
+ context: { collectionName: collectionName },
32290
+ stack: stack,
32291
+ });
32268
32292
  }
32269
32293
  if (gender && !Object.values(genderConstants).includes(gender)) {
32270
- return { error: INVALID_VALUES };
32294
+ return decorateResult({
32295
+ result: { error: INVALID_VALUES },
32296
+ context: { gender: gender },
32297
+ stack: stack,
32298
+ });
32271
32299
  }
32272
32300
  if (category && typeof category !== 'object') {
32273
- return { error: INVALID_VALUES };
32301
+ return decorateResult({
32302
+ result: { error: INVALID_VALUES },
32303
+ context: { category: category },
32304
+ stack: stack,
32305
+ });
32274
32306
  }
32275
- var stack = 'modifyCollectionDefinition';
32276
32307
  var valueAssignments = {
32277
32308
  collectionValueProfiles: collectionValueProfiles,
32278
32309
  collectionValue: collectionValue,
@@ -32288,10 +32319,8 @@ function modifyCollectionDefinition$1(_a) {
32288
32319
  return decorateResult({ result: { error: MISSING_VALUE }, stack: stack });
32289
32320
  if (Object.values(valueAssignments).filter(Boolean).length > 1)
32290
32321
  return decorateResult({
32291
- result: {
32292
- info: 'Only one value assignment allowed per collectionDefinition',
32293
- error: INVALID_VALUES,
32294
- },
32322
+ info: 'Only one value assignment allowed per collectionDefinition',
32323
+ result: { error: INVALID_VALUES },
32295
32324
  stack: stack,
32296
32325
  });
32297
32326
  var result = getTieFormat$1({
@@ -32301,42 +32330,73 @@ function modifyCollectionDefinition$1(_a) {
32301
32330
  eventId: eventId,
32302
32331
  event: event,
32303
32332
  });
32304
- if (result.error)
32333
+ if (result.error) {
32305
32334
  return decorateResult({ result: result, stack: stack });
32335
+ }
32306
32336
  var matchUp = result.matchUp, structure = result.structure, existingTieFormat = result.tieFormat;
32307
32337
  var tieFormat = copyTieFormat(existingTieFormat);
32308
- var collectionDefinition = tieFormat.collectionDefinitions.find(function (collectionDefinition) { return collectionDefinition.collectionId === collectionId; });
32309
- 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)
32310
32343
  return decorateResult({ result: { error: NOT_FOUND }, stack: stack });
32311
- var value = collectionValue || matchUpValue || scoreValue || setValue;
32312
- if (value || collectionValueProfiles) {
32313
- if (value) {
32314
- if (!isConvertableInteger(value))
32315
- return decorateResult({ result: { error: INVALID_VALUES, value: value } });
32316
- }
32317
- else if (collectionValueProfiles) {
32318
- var result_1 = validateCollectionValueProfile({
32319
- matchUpCount: collectionDefinition.matchUpCount,
32320
- 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,
32321
32355
  });
32322
- if (result_1.errors) {
32323
- return decorateResult({
32324
- result: { error: INVALID_VALUES, info: result_1.errors },
32325
- stack: stack,
32326
- });
32327
- }
32328
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) {
32329
32386
  // cleanup any previously existing value assignment
32330
- collectionDefinition.collectionValue = undefined;
32331
- collectionDefinition.matchUpValue = undefined;
32332
- collectionDefinition.scoreValue = undefined;
32333
- collectionDefinition.setValue = undefined;
32387
+ targetCollectionDefinition.collectionValueProfiles = undefined;
32388
+ targetCollectionDefinition.collectionValue = undefined;
32389
+ targetCollectionDefinition.matchUpValue = undefined;
32390
+ targetCollectionDefinition.scoreValue = undefined;
32391
+ targetCollectionDefinition.setValue = undefined;
32334
32392
  // add new value assignment
32335
- Object.assign(collectionDefinition, valueAssignments);
32393
+ Object.assign(targetCollectionDefinition, valueAssignments);
32394
+ modifications.push(__assign({ collectionId: collectionId }, definedAttributes(valueAssignments)));
32336
32395
  }
32337
32396
  // must remove all collectionGroups which contain the collection which has been modified
32338
- if ((scoreValue || setValue) && collectionDefinition.collectionGroupNumber) {
32339
- var targetCollectionGroupNumber_1 = collectionDefinition.collectionGroupNumber;
32397
+ if ((isConvertableInteger(scoreValue) || isConvertableInteger(setValue)) &&
32398
+ targetCollectionDefinition.collectionGroupNumber) {
32399
+ var targetCollectionGroupNumber_1 = targetCollectionDefinition.collectionGroupNumber;
32340
32400
  tieFormat.collectionDefinitions = tieFormat.collectionDefinitions.map(function (collectionDefinition) {
32341
32401
  var collectionGroupNumber = collectionDefinition.collectionGroupNumber, rest = __rest(collectionDefinition, ["collectionGroupNumber"]);
32342
32402
  if (collectionGroupNumber === targetCollectionGroupNumber_1) {
@@ -32350,37 +32410,85 @@ function modifyCollectionDefinition$1(_a) {
32350
32410
  var groupNumber = _a.groupNumber;
32351
32411
  return groupNumber !== targetCollectionGroupNumber_1;
32352
32412
  });
32413
+ modifications.push({
32414
+ collectionId: collectionId,
32415
+ change: 'collectionGroupNumber removed',
32416
+ });
32353
32417
  }
32354
32418
  // calculate new winCriteria for tieFormat
32355
32419
  // if existing winCriteria is aggregateValue, retain
32356
- var _d = calculateWinCriteria(tieFormat), aggregateValue = _d.aggregateValue, valueGoal = _d.valueGoal;
32357
- tieFormat.winCriteria = definedAttributes({ aggregateValue: aggregateValue, valueGoal: valueGoal });
32358
- // if valueGoal has changed, force renaming of the tieFormat
32359
- var originalValueGoal = existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.winCriteria.valueGoal;
32360
- var wasAggregateValue = existingTieFormat === null || existingTieFormat === void 0 ? void 0 : existingTieFormat.winCriteria.aggregateValue;
32361
- if ((originalValueGoal && originalValueGoal !== valueGoal) ||
32362
- (aggregateValue && !wasAggregateValue)) {
32363
- delete tieFormat.tieFormatName;
32364
- }
32365
- if (tieFormatName)
32366
- tieFormat.tieFormatName = tieFormatName;
32367
- if (collectionOrder)
32368
- collectionDefinition.collectionOrder = collectionOrder;
32369
- if (collectionName)
32370
- collectionDefinition.collectionName = collectionName;
32371
- if (matchUpFormat)
32372
- collectionDefinition.matchUpFormat = matchUpFormat;
32373
- // if (matchUpCount) collectionDefinition.matchUpCount = matchUpCount; // TODO: need to calculate tieMatchUp additions/deletions
32374
- if (matchUpType)
32375
- collectionDefinition.matchUpType = matchUpType;
32376
- if (category)
32377
- collectionDefinition.category = category;
32378
- if (gender)
32379
- 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
+ }
32380
32472
  var prunedTieFormat = definedAttributes(tieFormat);
32381
32473
  result = validateTieFormat({ tieFormat: prunedTieFormat });
32382
- if (result.error)
32474
+ if (result.error) {
32383
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
+ }
32384
32492
  result = updateTieFormat({
32385
32493
  tieFormat: prunedTieFormat,
32386
32494
  updateInProgressMatchUps: updateInProgressMatchUps,
@@ -32393,10 +32501,10 @@ function modifyCollectionDefinition$1(_a) {
32393
32501
  });
32394
32502
  if (!result.error) {
32395
32503
  var appliedPolicies = getAppliedPolicies({ tournamentRecord: tournamentRecord }).appliedPolicies;
32396
- 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]) {
32397
32505
  var auditData = definedAttributes({
32506
+ collectionDefinition: targetCollectionDefinition,
32398
32507
  drawId: drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.drawId,
32399
- collectionDefinition: collectionDefinition,
32400
32508
  action: stack,
32401
32509
  structureId: structureId,
32402
32510
  matchUpId: matchUpId,
@@ -32405,7 +32513,7 @@ function modifyCollectionDefinition$1(_a) {
32405
32513
  tieFormatTelemetry({ drawDefinition: drawDefinition, auditData: auditData });
32406
32514
  }
32407
32515
  }
32408
- return decorateResult({ result: result, stack: stack });
32516
+ return decorateResult({ result: __assign(__assign({}, result), { modifications: modifications }), stack: stack });
32409
32517
  }
32410
32518
 
32411
32519
  function resolveTournamentRecord(params) {
@@ -32965,10 +33073,10 @@ function addCollectionDefinition$1(_a) {
32965
33073
  return collectionId;
32966
33074
  });
32967
33075
  if (collectionIds.includes(collectionDefinition.collectionId))
32968
- return {
32969
- collectionId: collectionDefinition.collectionId,
32970
- error: DUPLICATE_VALUE,
32971
- };
33076
+ return decorateResult({
33077
+ context: { collectionId: collectionDefinition.collectionId },
33078
+ result: { error: DUPLICATE_VALUE },
33079
+ });
32972
33080
  }
32973
33081
  tieFormat.collectionDefinitions.push(collectionDefinition);
32974
33082
  tieFormat.collectionDefinitions
@@ -33071,7 +33179,10 @@ function addCollectionDefinition$1(_a) {
33071
33179
  }
33072
33180
  else if (matchUpId && matchUp) {
33073
33181
  if (!validUpdate({ matchUp: matchUp, updateInProgressMatchUps: updateInProgressMatchUps }))
33074
- return { error: CANNOT_MODIFY_TIEFORMAT };
33182
+ return decorateResult({
33183
+ result: { error: CANNOT_MODIFY_TIEFORMAT },
33184
+ stack: stack,
33185
+ });
33075
33186
  matchUp.tieFormat = prunedTieFormat;
33076
33187
  var newMatchUps = generateCollectionMatchUps({
33077
33188
  collectionDefinition: collectionDefinition,
@@ -33138,7 +33249,7 @@ function addCollectionDefinition$1(_a) {
33138
33249
  });
33139
33250
  tieFormatTelemetry({ drawDefinition: drawDefinition, auditData: auditData });
33140
33251
  }
33141
- return __assign(__assign({}, SUCCESS), { tieFormat: prunedTieFormat, targetMatchUps: targetMatchUps, addedMatchUps: addedMatchUps });
33252
+ return __assign({ tieFormat: prunedTieFormat, targetMatchUps: targetMatchUps, addedMatchUps: addedMatchUps }, SUCCESS);
33142
33253
  }
33143
33254
  function updateStructureMatchUps(_a) {
33144
33255
  var e_4, _b, _c;
@@ -33626,7 +33737,8 @@ function addCollectionGroup(params) {
33626
33737
 
33627
33738
  function modifyTieFormat$1(_a) {
33628
33739
  var e_1, _b, e_2, _c, e_3, _d;
33629
- 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;
33630
33742
  var stack = 'updateTieFormat';
33631
33743
  if (!validateTieFormat(modifiedTieFormat))
33632
33744
  return { error: INVALID_TIE_FORMAT };
@@ -33641,35 +33753,32 @@ function modifyTieFormat$1(_a) {
33641
33753
  return decorateResult({ result: result, stack: stack });
33642
33754
  var matchUp = result.matchUp, existingTieFormat = result.tieFormat;
33643
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
+ }
33644
33759
  var existingCollectionIds = tieFormat.collectionDefinitions.map(function (_a) {
33645
33760
  var collectionId = _a.collectionId;
33646
33761
  return collectionId;
33647
33762
  });
33648
- var modifiedCollectionDefinitions = [];
33649
- var addedCollectionDefinitions = [];
33650
- var updatedCollectionIds = [];
33651
- modifiedTieFormat.collectionDefinitions.forEach(function (def) {
33652
- var _a;
33653
- updatedCollectionIds.push(def.collectionId);
33654
- if (modifiedTieFormat && existingCollectionIds.includes(def.collectionId)) {
33655
- ((_a = compareTieFormats({
33656
- descendant: modifiedTieFormat,
33657
- ancestor: tieFormat,
33658
- })) === null || _a === void 0 ? void 0 : _a.different) && modifiedCollectionDefinitions.push(def);
33659
- }
33660
- else {
33661
- addedCollectionDefinitions.push(def);
33662
- }
33763
+ var updatedCollectionIds = modifiedTieFormat.collectionDefinitions.map(function (_a) {
33764
+ var collectionId = _a.collectionId;
33765
+ return collectionId;
33663
33766
  });
33664
33767
  var removedCollectionIds = existingCollectionIds.filter(function (collectionId) { return !updatedCollectionIds.includes(collectionId); });
33665
- 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 = [];
33666
33773
  var processedTieFormat;
33667
33774
  try {
33668
33775
  // TODO: if matchUpCount is changing pre-check for cmopleted tieMatchUps
33669
33776
  // TODO: if gender is changing pre-check for misgendered collectionAssignments
33670
- for (var modifiedCollectionDefinitions_1 = __values(modifiedCollectionDefinitions), modifiedCollectionDefinitions_1_1 = modifiedCollectionDefinitions_1.next(); !modifiedCollectionDefinitions_1_1.done; modifiedCollectionDefinitions_1_1 = modifiedCollectionDefinitions_1.next()) {
33671
- var collectionDefinition = modifiedCollectionDefinitions_1_1.value;
33672
- 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));
33673
33782
  if (result_1.error)
33674
33783
  return decorateResult({ result: result_1, stack: stack });
33675
33784
  if (result_1.tieFormat)
@@ -33679,10 +33788,11 @@ function modifyTieFormat$1(_a) {
33679
33788
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
33680
33789
  finally {
33681
33790
  try {
33682
- 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);
33683
33792
  }
33684
33793
  finally { if (e_1) throw e_1.error; }
33685
33794
  }
33795
+ var tieFormatName = modifiedTieFormat.tieFormatName;
33686
33796
  try {
33687
33797
  for (var addedCollectionDefinitions_1 = __values(addedCollectionDefinitions), addedCollectionDefinitions_1_1 = addedCollectionDefinitions_1.next(); !addedCollectionDefinitions_1_1.done; addedCollectionDefinitions_1_1 = addedCollectionDefinitions_1.next()) {
33688
33798
  var collectionDefinition = addedCollectionDefinitions_1_1.value;
@@ -33741,6 +33851,16 @@ function modifyTieFormat$1(_a) {
33741
33851
  }
33742
33852
  finally { if (e_3) throw e_3.error; }
33743
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
+ }
33744
33864
  processedTieFormat.collectionDefinitions =
33745
33865
  processedTieFormat.collectionDefinitions
33746
33866
  .sort(function (a, b) {
@@ -33748,7 +33868,7 @@ function modifyTieFormat$1(_a) {
33748
33868
  numericSortValue(b.collectionOrder);
33749
33869
  })
33750
33870
  .map(function (def, i) { return (__assign(__assign({}, def), { collectionOrder: i + 1 })); });
33751
- return __assign(__assign({}, SUCCESS), { processedTieFormat: processedTieFormat });
33871
+ return __assign(__assign({}, SUCCESS), { processedTieFormat: processedTieFormat, modifications: modifications });
33752
33872
  }
33753
33873
 
33754
33874
  function modifyTieFormat(params) {
@@ -65533,6 +65653,7 @@ var lastNames = [
65533
65653
  "Dallas",
65534
65654
  "Diamond",
65535
65655
  "Deckard",
65656
+ "Dunbar",
65536
65657
  "Earhart",
65537
65658
  "Eisenstein",
65538
65659
  "Eldritch",