tods-competition-factory 1.7.13 → 1.7.15

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.
@@ -1708,8 +1708,9 @@ function decorateResult({
1708
1708
  if (result && Array.isArray(result?.stack) && typeof stack === "string") {
1709
1709
  result.stack.push(stack);
1710
1710
  }
1711
- if (info && result?.error)
1712
- result.error.info = info;
1711
+ if (result && info) {
1712
+ result.info = info;
1713
+ }
1713
1714
  if (result && typeof context === "object" && Object.keys(context).length) {
1714
1715
  Object.assign(result, definedAttributes(context));
1715
1716
  }
@@ -1863,19 +1864,15 @@ function findEvent({
1863
1864
  }) {
1864
1865
  const stack = "findEvent";
1865
1866
  if (!tournamentRecord)
1866
- return {
1867
- event: void 0,
1868
- drawDefinition: void 0,
1869
- ...decorateResult({
1870
- result: { error: MISSING_TOURNAMENT_RECORD },
1871
- stack
1872
- })
1873
- };
1874
- const events = tournamentRecord?.events || [];
1867
+ return decorateResult({
1868
+ result: { error: MISSING_TOURNAMENT_RECORD },
1869
+ stack
1870
+ });
1871
+ const events = tournamentRecord?.events ?? [];
1875
1872
  if (drawId) {
1876
1873
  let drawDefinition;
1877
1874
  const event = events.find((event2) => {
1878
- const drawDefinitions = event2?.drawDefinitions || [];
1875
+ const drawDefinitions = event2?.drawDefinitions ?? [];
1879
1876
  const targetDrawDefinition = drawDefinitions.find(
1880
1877
  (drawDefinition2) => drawDefinition2.drawId === drawId
1881
1878
  );
@@ -1934,7 +1931,7 @@ function addExtension(params) {
1934
1931
  });
1935
1932
  if (!params.element.extensions)
1936
1933
  params.element.extensions = [];
1937
- const creationTime = params.creationTime !== void 0 ? params.creationTime : true;
1934
+ const creationTime = params?.creationTime ?? true;
1938
1935
  if (creationTime) {
1939
1936
  const createdAt = (/* @__PURE__ */ new Date()).toISOString();
1940
1937
  Object.assign(params.extension, { createdAt });
@@ -2139,7 +2136,7 @@ function findCourt({
2139
2136
  } else if (tournamentRecords) {
2140
2137
  const linkedTournamentIds = getLinkedTournamentIds({
2141
2138
  tournamentRecords
2142
- }).linkedTournamentIds || [];
2139
+ }).linkedTournamentIds ?? [];
2143
2140
  const relevantIds = linkedTournamentIds[tournamentRecord.tournamentId];
2144
2141
  for (const tournamentId of relevantIds) {
2145
2142
  const record = tournamentRecords[tournamentId];
@@ -5351,8 +5348,8 @@ function getSeedGroups({
5351
5348
  return {
5352
5349
  seedGroups: void 0,
5353
5350
  ...decorateResult({
5354
- result: { error: INVALID_VALUES },
5355
5351
  context: { roundRobinGroupsCount },
5352
+ result: { error: INVALID_VALUES },
5356
5353
  stack
5357
5354
  })
5358
5355
  };
@@ -11005,9 +11002,7 @@ function assignMatchUpDrawPosition({
11005
11002
  return { ...SUCCESS };
11006
11003
  } else {
11007
11004
  return decorateResult({
11008
- result: {
11009
- error: DRAW_POSITION_ASSIGNED
11010
- },
11005
+ result: { error: DRAW_POSITION_ASSIGNED },
11011
11006
  context: { drawPosition },
11012
11007
  stack
11013
11008
  });
@@ -11346,7 +11341,7 @@ function removeSubsequentRoundsParticipant({
11346
11341
  const positionAssignments = getPositionAssignments({
11347
11342
  drawDefinition,
11348
11343
  structureId
11349
- }).positionAssignments || [];
11344
+ }).positionAssignments ?? [];
11350
11345
  relevantMatchUps?.forEach(
11351
11346
  (matchUp) => removeDrawPosition({
11352
11347
  drawPosition: targetDrawPosition,
@@ -11376,7 +11371,7 @@ function removeDrawPosition({
11376
11371
  const initialDrawPositions = targetMatchUp.drawPositions?.slice();
11377
11372
  const initialMatchUpStatus = targetMatchUp.matchUpStatus;
11378
11373
  const initialWinningSide = targetMatchUp.winningSide;
11379
- matchUpsMap = matchUpsMap || getMatchUpsMap({ drawDefinition });
11374
+ matchUpsMap = matchUpsMap ?? getMatchUpsMap({ drawDefinition });
11380
11375
  const mappedMatchUps = matchUpsMap.mappedMatchUps;
11381
11376
  const matchUps = mappedMatchUps[structure.structureId].matchUps;
11382
11377
  const { initialRoundNumber } = getInitialRoundNumber({
@@ -11384,7 +11379,7 @@ function removeDrawPosition({
11384
11379
  matchUps
11385
11380
  });
11386
11381
  if (targetMatchUp.roundNumber && initialRoundNumber && targetMatchUp.roundNumber > initialRoundNumber) {
11387
- const drawPositions = (targetMatchUp.drawPositions || []).map(
11382
+ const drawPositions = (targetMatchUp.drawPositions ?? []).map(
11388
11383
  (currentDrawPosition) => currentDrawPosition === drawPosition ? void 0 : currentDrawPosition
11389
11384
  );
11390
11385
  targetMatchUp.drawPositions = drawPositions;
@@ -11393,7 +11388,7 @@ function removeDrawPosition({
11393
11388
  const inContextTargetMatchUp = inContextDrawMatchUps?.find(
11394
11389
  (matchUp) => matchUp.matchUpId === targetMatchUp.matchUpId
11395
11390
  );
11396
- const sides = inContextTargetMatchUp?.sides || [];
11391
+ const sides = inContextTargetMatchUp?.sides ?? [];
11397
11392
  const drawPositionSideIndex = sides.reduce(
11398
11393
  (index, side, i) => side.drawPosition === drawPosition ? i : index,
11399
11394
  void 0
@@ -12822,11 +12817,7 @@ function positionByes({
12822
12817
  }
12823
12818
 
12824
12819
  function positionQualifiers(params) {
12825
- let { structure, structureId } = params;
12826
- if (!structure)
12827
- ({ structure } = findStructure(params));
12828
- if (!structureId)
12829
- ({ structureId } = structure);
12820
+ const structure = params.structure ?? findStructure(params).structure;
12830
12821
  const stack = "positionQualifiers";
12831
12822
  const qualifierDrawPositions = [];
12832
12823
  if (structure.stage === CONSOLATION) {
@@ -14791,13 +14782,14 @@ function generateTieMatchUps({
14791
14782
  isMock,
14792
14783
  uuids
14793
14784
  }) {
14794
- const { collectionDefinitions } = tieFormat || {};
14795
- const tieMatchUps = (collectionDefinitions || []).map(
14785
+ const { collectionDefinitions } = tieFormat ?? {};
14786
+ const tieMatchUps = (collectionDefinitions ?? []).map(
14796
14787
  (collectionDefinition) => generateCollectionMatchUps({ collectionDefinition, uuids, isMock })
14797
14788
  ).filter(Boolean).flat();
14798
14789
  return { tieMatchUps };
14799
14790
  }
14800
14791
  function generateCollectionMatchUps({
14792
+ collectionPositionOffset = 0,
14801
14793
  collectionDefinition,
14802
14794
  matchUpsLimit,
14803
14795
  // internal use allows generation of missing matchUps on "reset"
@@ -14805,9 +14797,9 @@ function generateCollectionMatchUps({
14805
14797
  uuids
14806
14798
  }) {
14807
14799
  const { matchUpCount, matchUpType, collectionId, processCodes } = collectionDefinition || {};
14808
- const numberToGenerate = matchUpsLimit || matchUpCount || 0;
14800
+ const numberToGenerate = matchUpsLimit ?? matchUpCount ?? 0;
14809
14801
  return generateRange(0, numberToGenerate).map((index) => {
14810
- const collectionPosition = index + 1;
14802
+ const collectionPosition = collectionPositionOffset + index + 1;
14811
14803
  return {
14812
14804
  sides: [{ sideNumber: 1 }, { sideNumber: 2 }],
14813
14805
  matchUpId: uuids?.pop() || UUID(),
@@ -16358,34 +16350,28 @@ function validateTieFormat(params) {
16358
16350
  const tieFormat = params?.tieFormat;
16359
16351
  const stack = "validateTieFormat";
16360
16352
  const errors = [];
16361
- if (typeof tieFormat !== "object") {
16353
+ if (!params || !tieFormat || typeof tieFormat !== "object") {
16362
16354
  errors.push("tieFormat must be an object");
16363
16355
  return decorateResult({
16364
- result: {
16365
- context: { tieFormat, errors },
16366
- error: INVALID_TIE_FORMAT,
16367
- stack
16368
- }
16356
+ result: { error: INVALID_TIE_FORMAT },
16357
+ context: { tieFormat, errors },
16358
+ stack
16369
16359
  });
16370
16360
  }
16371
16361
  if (typeof tieFormat.winCriteria !== "object") {
16372
16362
  errors.push("tieFormat.winCriteria must be an object");
16373
16363
  return decorateResult({
16374
- result: {
16375
- context: { tieFormat, errors },
16376
- error: INVALID_TIE_FORMAT,
16377
- stack
16378
- }
16364
+ result: { error: INVALID_TIE_FORMAT },
16365
+ context: { tieFormat, errors },
16366
+ stack
16379
16367
  });
16380
16368
  }
16381
16369
  if (!Array.isArray(tieFormat.collectionDefinitions)) {
16382
16370
  errors.push(mustBeAnArray("tieFormat.collectionDefinitions"));
16383
16371
  return decorateResult({
16384
- result: {
16385
- context: { tieFormat, errors },
16386
- error: INVALID_TIE_FORMAT,
16387
- stack
16388
- }
16372
+ result: { error: INVALID_TIE_FORMAT },
16373
+ context: { tieFormat, errors },
16374
+ stack
16389
16375
  });
16390
16376
  }
16391
16377
  let aggregateValueImperative;
@@ -16418,11 +16404,9 @@ function validateTieFormat(params) {
16418
16404
  );
16419
16405
  }
16420
16406
  return decorateResult({
16421
- result: {
16422
- context: { tieFormat, errors, aggregateValueImperative },
16423
- error: INVALID_TIE_FORMAT,
16424
- stack
16425
- }
16407
+ context: { tieFormat, errors, aggregateValueImperative },
16408
+ result: { error: INVALID_TIE_FORMAT },
16409
+ stack
16426
16410
  });
16427
16411
  }
16428
16412
  const collectionIds = tieFormat.collectionDefinitions.map(
@@ -16433,11 +16417,9 @@ function validateTieFormat(params) {
16433
16417
  const result = { valid, errors };
16434
16418
  if (!valid) {
16435
16419
  return decorateResult({
16436
- result: {
16437
- context: { tieFormat, errors },
16438
- error: INVALID_TIE_FORMAT,
16439
- stack
16440
- }
16420
+ result: { error: INVALID_TIE_FORMAT },
16421
+ context: { tieFormat, errors },
16422
+ stack
16441
16423
  });
16442
16424
  }
16443
16425
  return result;
@@ -16496,7 +16478,7 @@ function validateCollectionDefinition({
16496
16478
  errors.push(`collectionValue is not type number: ${collectionValue}`);
16497
16479
  }
16498
16480
  if (collectionValueProfiles) {
16499
- const result = validateCollectionValueProfile({
16481
+ const result = validateCollectionValueProfiles({
16500
16482
  collectionValueProfiles,
16501
16483
  matchUpCount
16502
16484
  });
@@ -16527,7 +16509,7 @@ function checkTieFormat(tieFormat) {
16527
16509
  }
16528
16510
  return { tieFormat };
16529
16511
  }
16530
- function validateCollectionValueProfile({
16512
+ function validateCollectionValueProfiles({
16531
16513
  collectionValueProfiles,
16532
16514
  matchUpCount
16533
16515
  }) {
@@ -17197,7 +17179,8 @@ function directLoser(params) {
17197
17179
  if (result.error)
17198
17180
  return decorateResult({ result, stack });
17199
17181
  } else if (loserParticipantId && isFeedRound) {
17200
- const fedDrawPosition = unfilledTargetMatchUpDrawPositions.sort(numericSort)[0];
17182
+ unfilledTargetMatchUpDrawPositions.sort(numericSort);
17183
+ const fedDrawPosition = unfilledTargetMatchUpDrawPositions[0];
17201
17184
  const result = assignDrawPosition({
17202
17185
  participantId: loserParticipantId,
17203
17186
  structureId: targetStructureId,
@@ -17462,7 +17445,7 @@ function generateAndPopulatePlayoffStructures(params) {
17462
17445
  drawDefinition
17463
17446
  });
17464
17447
  if (!structure)
17465
- return decorateResult({ result: { error: STRUCTURE_NOT_FOUND } });
17448
+ return decorateResult({ result: { error: STRUCTURE_NOT_FOUND }, stack });
17466
17449
  if (structure.structureType === CONTAINER || structure.structures) {
17467
17450
  return generateAndPopulateRRplayoffStructures({
17468
17451
  sourceStructureId: structure.structureId,
@@ -19012,10 +18995,8 @@ function addParticipant({
19012
18995
  });
19013
18996
  } else if (participant.individualParticipantIds.length !== 2 && !pairOverride) {
19014
18997
  return decorateResult({
19015
- result: {
19016
- error: INVALID_PARTICIPANT_IDS,
19017
- info: "PAIR must be 2 individualParticipantIds"
19018
- },
18998
+ info: "PAIR must be 2 individualParticipantIds",
18999
+ result: { error: INVALID_PARTICIPANT_IDS },
19019
19000
  stack
19020
19001
  });
19021
19002
  } else {
@@ -20931,14 +20912,14 @@ function addDrawDefinition(params) {
20931
20912
  if (relevantFlight && !drawEntriesPresentInFlight) {
20932
20913
  return decorateResult({
20933
20914
  result: {
20934
- error: INVALID_DRAW_DEFINITION,
20935
- context: {
20936
- drawEntriesPresentInFlight,
20937
- matchingEventEntries,
20938
- relevantFlight
20939
- },
20940
- info: "Draw entries are not present in flight or do not match entryStatuses"
20941
- }
20915
+ error: INVALID_DRAW_DEFINITION
20916
+ },
20917
+ context: {
20918
+ drawEntriesPresentInFlight,
20919
+ matchingEventEntries,
20920
+ relevantFlight
20921
+ },
20922
+ info: "Draw entries are not present in flight or do not match entryStatuses"
20942
20923
  });
20943
20924
  }
20944
20925
  if (modifyEventEntries) {
@@ -20957,9 +20938,9 @@ function addDrawDefinition(params) {
20957
20938
  if (eventEntries && !matchingEventEntries)
20958
20939
  return decorateResult({
20959
20940
  result: {
20960
- error: INVALID_DRAW_DEFINITION,
20941
+ info: "Draw entries do not match event entryStatuses",
20961
20942
  context: { matchingEventEntries, eventEntries },
20962
- info: "Draw entries do not match event entryStatuses"
20943
+ error: INVALID_DRAW_DEFINITION
20963
20944
  }
20964
20945
  });
20965
20946
  const flightNumbers = flightProfile?.flights?.map(
@@ -22572,6 +22553,7 @@ function getScaledEntries({
22572
22553
  }
22573
22554
 
22574
22555
  function prepareStage(params) {
22556
+ const stack = "prepareStage";
22575
22557
  let { seedsCount } = params;
22576
22558
  const preparedStructureIds = params.preparedStructureIds || [];
22577
22559
  const {
@@ -22627,7 +22609,7 @@ function prepareStage(params) {
22627
22609
  ({ structureId: structureId2 }) => !preparedStructureIds.includes(structureId2)
22628
22610
  );
22629
22611
  if (!structure)
22630
- return decorateResult({ result: { error: STRUCTURE_NOT_FOUND } });
22612
+ return decorateResult({ result: { error: STRUCTURE_NOT_FOUND }, stack });
22631
22613
  const structureId = structure?.structureId;
22632
22614
  const seedBlockInfo = structure ? getValidSeedBlocks({
22633
22615
  provisionalPositioning,
@@ -22750,7 +22732,7 @@ function prepareStage(params) {
22750
22732
  positionAssignments = result?.positionAssignments;
22751
22733
  positioningReport = result?.positioningReport;
22752
22734
  if (result.error) {
22753
- return decorateResult({ result, stack: "prepareStage" });
22735
+ return decorateResult({ result, stack });
22754
22736
  }
22755
22737
  }
22756
22738
  return {
@@ -23033,10 +23015,8 @@ function generateDrawDefinition(params) {
23033
23015
  if (policyDefinitions) {
23034
23016
  if (typeof policyDefinitions !== "object") {
23035
23017
  return decorateResult({
23036
- result: {
23037
- info: "policyDefinitions must be an object",
23038
- error: INVALID_VALUES
23039
- },
23018
+ info: "policyDefinitions must be an object",
23019
+ result: { error: INVALID_VALUES },
23040
23020
  stack
23041
23021
  });
23042
23022
  } else {
@@ -23265,8 +23245,9 @@ function generateDrawDefinition(params) {
23265
23245
  for (const roundTargetProfile of params.qualifyingProfiles) {
23266
23246
  if (!Array.isArray(roundTargetProfile.structureProfiles))
23267
23247
  return decorateResult({
23248
+ info: mustBeAnArray("structureProfiles"),
23268
23249
  result: { error: MISSING_VALUE },
23269
- info: mustBeAnArray("structureProfiles")
23250
+ stack
23270
23251
  });
23271
23252
  roundTarget = roundTargetProfile.roundTarget || roundTarget;
23272
23253
  const sortedStructureProfiles = roundTargetProfile.structureProfiles?.sort(sequenceSort) || [];