tods-competition-factory 2.1.4 → 2.1.6

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.
@@ -2679,13 +2679,6 @@ declare function luckyLoserDrawPositionAssignment(params: any): ResultType | {
2679
2679
  };
2680
2680
  };
2681
2681
 
2682
- declare function alternateDrawPositionAssignment(params: any): ResultType | {
2683
- error: {
2684
- message: string;
2685
- code: string;
2686
- };
2687
- };
2688
-
2689
2682
  type ShiftRoundsArgs = {
2690
2683
  drawDefinition: DrawDefinition;
2691
2684
  targetRoundNumber: number;
@@ -2718,6 +2711,19 @@ declare function qualifierDrawPositionAssignment(params: any): ResultType | {
2718
2711
  };
2719
2712
  };
2720
2713
 
2714
+ declare function alternateDrawPositionAssignment({ alternateParticipantId, tournamentRecord, drawDefinition, drawPosition, structureId, }: {
2715
+ alternateParticipantId: any;
2716
+ tournamentRecord: any;
2717
+ drawDefinition: any;
2718
+ drawPosition: any;
2719
+ structureId: any;
2720
+ }): ResultType | {
2721
+ error: {
2722
+ message: string;
2723
+ code: string;
2724
+ };
2725
+ };
2726
+
2721
2727
  declare function removeDrawPositionAssignment(params: any): ResultType & {
2722
2728
  participantId?: string;
2723
2729
  };
@@ -4951,6 +4957,13 @@ declare function generateFlightProfile(params: GenerateFlightProfileArgs): {
4951
4957
  error?: ErrorType;
4952
4958
  };
4953
4959
 
4960
+ declare function generateStatCrew(params: any): (ResultType & {
4961
+ valid?: boolean | undefined;
4962
+ }) | {
4963
+ success: boolean;
4964
+ xml: any;
4965
+ };
4966
+
4954
4967
  type GenerateLineUpsArgs = {
4955
4968
  useDefaultEventRanking?: boolean;
4956
4969
  tournamentRecord: Tournament;
@@ -5048,10 +5061,11 @@ declare const index$g_generateFlightProfile: typeof generateFlightProfile;
5048
5061
  declare const index$g_generateLineUps: typeof generateLineUps;
5049
5062
  declare const index$g_generateQualifyingStructure: typeof generateQualifyingStructure;
5050
5063
  declare const index$g_generateSeedingScaleItems: typeof generateSeedingScaleItems;
5064
+ declare const index$g_generateStatCrew: typeof generateStatCrew;
5051
5065
  declare const index$g_generateVoluntaryConsolation: typeof generateVoluntaryConsolation;
5052
5066
  declare const index$g_roundRobinGroups: typeof roundRobinGroups;
5053
5067
  declare namespace index$g {
5054
- export { index$g_drawMatic as drawMatic, garman$1 as garman, index$g_generateAdHocMatchUps as generateAdHocMatchUps, index$g_generateAdHocRounds as generateAdHocRounds, index$g_generateAndPopulatePlayoffStructures as generateAndPopulatePlayoffStructures, index$g_generateCourts as generateCourts, index$g_generateDrawDefinition as generateDrawDefinition, index$g_generateDrawMaticRound as generateDrawMaticRound, index$g_generateDrawStructuresAndLinks as generateDrawStructuresAndLinks, index$g_generateDrawTypeAndModifyDrawDefinition as generateDrawTypeAndModifyDrawDefinition, index$g_generateFlightProfile as generateFlightProfile, index$g_generateLineUps as generateLineUps, index$g_generateQualifyingStructure as generateQualifyingStructure, index$g_generateSeedingScaleItems as generateSeedingScaleItems, index$g_generateVoluntaryConsolation as generateVoluntaryConsolation, index$g_roundRobinGroups as roundRobinGroups };
5068
+ export { index$g_drawMatic as drawMatic, garman$1 as garman, index$g_generateAdHocMatchUps as generateAdHocMatchUps, index$g_generateAdHocRounds as generateAdHocRounds, index$g_generateAndPopulatePlayoffStructures as generateAndPopulatePlayoffStructures, index$g_generateCourts as generateCourts, index$g_generateDrawDefinition as generateDrawDefinition, index$g_generateDrawMaticRound as generateDrawMaticRound, index$g_generateDrawStructuresAndLinks as generateDrawStructuresAndLinks, index$g_generateDrawTypeAndModifyDrawDefinition as generateDrawTypeAndModifyDrawDefinition, index$g_generateFlightProfile as generateFlightProfile, index$g_generateLineUps as generateLineUps, index$g_generateQualifyingStructure as generateQualifyingStructure, index$g_generateSeedingScaleItems as generateSeedingScaleItems, index$g_generateStatCrew as generateStatCrew, index$g_generateVoluntaryConsolation as generateVoluntaryConsolation, index$g_roundRobinGroups as roundRobinGroups };
5055
5069
  }
5056
5070
 
5057
5071
  declare function isValidMatchUpFormat({ matchUpFormat }: {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.1.4';
6
+ return '2.1.6';
7
7
  }
8
8
 
9
9
  function isFunction(obj) {
@@ -5790,6 +5790,10 @@ function getParticipantMap({ withIndividualParticipants, convertExtensions, tour
5790
5790
  for (const participant of tournamentRecord.participants ?? []) {
5791
5791
  const participantCopy = makeDeepCopy(participant, convertExtensions, internalUse);
5792
5792
  const { participantId, individualParticipantIds, participantType } = participantCopy;
5793
+ if (!participantMap[participantId]) {
5794
+ missingParticipantIds.push(participantId);
5795
+ continue;
5796
+ }
5793
5797
  Object.assign(participantMap[participantId].participant, participantCopy);
5794
5798
  if (individualParticipantIds) {
5795
5799
  const result = processIndividualParticipantIds({
@@ -10435,7 +10439,7 @@ const logColors = {
10435
10439
 
10436
10440
  const globalLog = [];
10437
10441
  function pushGlobalLog(value, devContextOverride) {
10438
- if (typeof value === 'string')
10442
+ if (isString(value))
10439
10443
  value = { method: value };
10440
10444
  if (devContextOverride || getDevContext())
10441
10445
  globalLog.push(value);
@@ -12903,7 +12907,7 @@ function addDrawEntries$1(params) {
12903
12907
  }
12904
12908
  return notAdded;
12905
12909
  }, []);
12906
- if (duplicateEntries.length && suppressDuplicateEntries) {
12910
+ if (duplicateEntries.length && !suppressDuplicateEntries) {
12907
12911
  return decorateResult({
12908
12912
  context: { eventId, drawId, duplicateEntries },
12909
12913
  result: { error: DUPLICATE_ENTRY },
@@ -15415,22 +15419,6 @@ function luckyLoserDrawPositionAssignment(params) {
15415
15419
  return luckyLoserDrawPositionAssignment$1(params);
15416
15420
  }
15417
15421
 
15418
- function alternateDrawPositionAssignment$1({ alternateParticipantId, tournamentRecord, drawDefinition, drawPosition, structureId, }) {
15419
- return positionParticipantAction({
15420
- positionActionName: 'alternateDrawPositionAssignment',
15421
- participantIdAttributeName: 'alternateParticipantid',
15422
- participantId: alternateParticipantId,
15423
- tournamentRecord,
15424
- drawDefinition,
15425
- drawPosition,
15426
- structureId,
15427
- });
15428
- }
15429
-
15430
- function alternateDrawPositionAssignment(params) {
15431
- return alternateDrawPositionAssignment$1(params);
15432
- }
15433
-
15434
15422
  function modifyMappedMatchUps({ params, modMap, structure }) {
15435
15423
  const { tournamentRecord, drawDefinition, event } = params;
15436
15424
  for (const matchUp of structure.matchUps) {
@@ -15616,6 +15604,18 @@ function qualifierDrawPositionAssignment(params) {
15616
15604
  return qualifierDrawPositionAssignment$1(params);
15617
15605
  }
15618
15606
 
15607
+ function alternateDrawPositionAssignment({ alternateParticipantId, tournamentRecord, drawDefinition, drawPosition, structureId, }) {
15608
+ return positionParticipantAction({
15609
+ positionActionName: 'alternateDrawPositionAssignment',
15610
+ participantIdAttributeName: 'alternateParticipantid',
15611
+ participantId: alternateParticipantId,
15612
+ tournamentRecord,
15613
+ drawDefinition,
15614
+ drawPosition,
15615
+ structureId,
15616
+ });
15617
+ }
15618
+
15619
15619
  function modifySeedAssignment({ validation = true, tournamentRecord, drawDefinition, participantId, structureId, seedValue, event, }) {
15620
15620
  if (!drawDefinition)
15621
15621
  return { error: MISSING_DRAW_DEFINITION };
@@ -40182,6 +40182,114 @@ function generateFlightProfile(params) {
40182
40182
  }
40183
40183
  }
40184
40184
 
40185
+ function jsonToXml({ json, tagName }) {
40186
+ const childArrays = Object.keys(json)
40187
+ .filter((key) => Array.isArray(json[key]))
40188
+ .map((key) => ({ key, value: json[key].filter((v) => typeof v === 'object' && Object.keys(v).length === 1) }));
40189
+ const childObjects = Object.keys(json)
40190
+ .filter((key) => typeof json[key] === 'object' && !Array.isArray(json[key]))
40191
+ .map((key) => ({ key, value: json[key] }));
40192
+ const attributes = Object.keys(json)
40193
+ .filter((key) => ['string', 'number'].includes(typeof json[key]))
40194
+ .map((key) => ({ key, value: json[key] }));
40195
+ return generateTag({ tagName, attributes, childArrays, childObjects });
40196
+ }
40197
+ function generateTag(params) {
40198
+ const { tagName, attributes = [], childArrays = [], childObjects } = params;
40199
+ const carriageReturn = '\r\n';
40200
+ const arrayChild = (v) => {
40201
+ const key = Object.keys(v)[0];
40202
+ const value = v[key];
40203
+ return { key, value };
40204
+ };
40205
+ const arrayValues = childArrays
40206
+ ?.map(({ key, value }) => generateTag({ tagName: key, childObjects: value.map(arrayChild) }))
40207
+ .join('\r\n');
40208
+ const childValues = childObjects
40209
+ ?.map(({ key, value }) => jsonToXml({ tagName: key, json: value ?? [] }))
40210
+ .join('\r\n');
40211
+ const attributeString = attributes?.map(({ key, value }) => `${key}="${value}"`).join(' ');
40212
+ const attributeValue = attributeString ? ` ${attributeString}` : '';
40213
+ if (tagName === 'childArray')
40214
+ return childValues;
40215
+ const objectsTag = childValues?.length ? `${carriageReturn}${childValues}${carriageReturn}` : '';
40216
+ const arraysTag = arrayValues?.length ? `${carriageReturn}${arrayValues}${carriageReturn}` : '';
40217
+ return `<${tagName}${attributeValue}>${objectsTag}${arraysTag}</${tagName}>`;
40218
+ }
40219
+
40220
+ function generateStatCrew(params) {
40221
+ const paramsCheck = checkRequiredParameters(params, [{ [TOURNAMENT_RECORD]: true }]);
40222
+ if (paramsCheck.error)
40223
+ return paramsCheck;
40224
+ const { tournamentRecord } = params;
40225
+ const { startDate, tournamentId, tournamentName } = tournamentRecord;
40226
+ const teamParticipants = tournamentRecord.participants.filter((participant) => participant.participantType === TEAM);
40227
+ const homeTeam = teamParticipants?.find((team) => team.participantRoleResponsibilities?.includes('Home'));
40228
+ const awayTeams = teamParticipants?.filter((team) => team.participantId !== homeTeam?.participantId);
40229
+ const date = formatDate(startDate, '/', 'MDY');
40230
+ const homename = homeTeam?.participantName || awayTeams?.[1]?.participantName;
40231
+ const homeid = homeTeam?.participantId || awayTeams?.[1]?.participantId;
40232
+ const visname = awayTeams?.[0]?.participantName;
40233
+ const visid = awayTeams?.[0]?.participantId;
40234
+ const matchUps = allTournamentMatchUps({ tournamentRecord }).matchUps;
40235
+ const singles = matchUps?.filter((matchUp) => matchUp.matchUpType === SINGLES);
40236
+ const doubles = matchUps?.filter((matchUp) => matchUp.matchUpType === DOUBLES);
40237
+ const getScoreAttributes = ({ sets, sideNumber }) => Object.assign({}, ...(sets?.map((set) => {
40238
+ const { setNumber, side1Score, side2Score, side1TiebreakScore, side2TiebreakScore } = set;
40239
+ const setKey = `set_${setNumber}`;
40240
+ const tbKey = `tie_${setNumber}`;
40241
+ const setValue = sideNumber === 1 ? side1Score : side2Score;
40242
+ const tieValue = sideNumber === 1 ? side1TiebreakScore : side2TiebreakScore;
40243
+ return { [setKey]: setValue, [tbKey]: tieValue };
40244
+ }) ?? []));
40245
+ const getParticipantAttibutes = ({ participant }) => {
40246
+ const pair = participant.individualParticipants?.length === 2;
40247
+ const pairTeamParticipantIds = pair
40248
+ ? unique(participant.individualParticipants?.map((p) => p.teams?.[0]?.participantId))
40249
+ : [];
40250
+ const pairTeamIds = pair ? unique(participant.individualParticipants?.map((p) => p.teams?.[0]?.teamId)) : [];
40251
+ const teamParticipantId = (!pair && participant.teams?.[0]?.participantId) ||
40252
+ (pairTeamParticipantIds?.length === 1 && pairTeamParticipantIds[0]) ||
40253
+ undefined;
40254
+ const team = (!pair && participant.teams?.[0]?.teamId) || (pairTeamIds?.length === 1 && pairTeamIds[0]) || teamParticipantId;
40255
+ const name = !pair ? participant.participantName : undefined;
40256
+ const name_1 = participant.individualParticipants?.[0]?.participantName;
40257
+ const name_2 = participant.individualParticipants?.[1]?.participantName;
40258
+ const vh = (homeid && (teamParticipantId === homeid ? 'H' : 'V')) || '';
40259
+ return definedAttributes({ vh, team, name, name_1, name_2 });
40260
+ };
40261
+ const mapMatchUp = (matchUp) => {
40262
+ const { collectionPosition: match, orderOfFinish: order, matchUpType, sides } = matchUp;
40263
+ const childArray = sides?.map((side) => {
40264
+ const { sideNumber, participant } = side;
40265
+ const scoreAttributes = getScoreAttributes({ sets: matchUp.score?.sets, sideNumber });
40266
+ const scoreType = matchUpType === SINGLES ? 'singles_score' : 'doubles_score';
40267
+ return { [scoreType]: { ...getParticipantAttibutes({ participant }), ...scoreAttributes } };
40268
+ });
40269
+ const matchType = matchUpType === SINGLES ? 'singles_match' : 'doubles_match';
40270
+ return { [matchType]: { match, order, childArray } };
40271
+ };
40272
+ const json = {
40273
+ venue: {
40274
+ tournament: teamParticipants?.length > 2 ? 'Y' : 'N',
40275
+ neutralgame: !homeTeam ? 'Y' : 'N',
40276
+ tournamentname: tournamentName,
40277
+ gameid: tournamentId,
40278
+ officials: {},
40279
+ rules: {},
40280
+ homename,
40281
+ visname,
40282
+ homeid,
40283
+ visid,
40284
+ date,
40285
+ },
40286
+ singles_matches: singles?.map(mapMatchUp),
40287
+ doubles_matches: doubles?.map(mapMatchUp),
40288
+ };
40289
+ const xml = jsonToXml({ json, tagName: 'tngame' });
40290
+ return { xml, ...SUCCESS };
40291
+ }
40292
+
40185
40293
  const ASC = 'ASC';
40186
40294
  const ASCENDING = 'ASC';
40187
40295
  const DESC = 'DESC';
@@ -40717,6 +40825,7 @@ var index$b = {
40717
40825
  generateLineUps: generateLineUps,
40718
40826
  generateQualifyingStructure: generateQualifyingStructure,
40719
40827
  generateSeedingScaleItems: generateSeedingScaleItems,
40828
+ generateStatCrew: generateStatCrew,
40720
40829
  generateVoluntaryConsolation: generateVoluntaryConsolation,
40721
40830
  roundRobinGroups: roundRobinGroups
40722
40831
  };
@@ -42237,7 +42346,13 @@ function removeDirectedLoser({ sourceMatchUpStatus, loserParticipantId, tourname
42237
42346
  }
42238
42347
  function removeDirectedBye({ inContextDrawMatchUps, tournamentRecord, drawDefinition, drawPosition, matchUpsMap, targetLink, event, }) {
42239
42348
  const structureId = targetLink.target.structureId;
42240
- clearDrawPosition({
42349
+ const stack = 'removeDirectedBye';
42350
+ pushGlobalLog({
42351
+ color: 'brightyellow',
42352
+ method: stack,
42353
+ drawPosition,
42354
+ });
42355
+ const result = clearDrawPosition({
42241
42356
  inContextDrawMatchUps,
42242
42357
  tournamentRecord,
42243
42358
  drawDefinition,
@@ -42246,7 +42361,7 @@ function removeDirectedBye({ inContextDrawMatchUps, tournamentRecord, drawDefini
42246
42361
  structureId,
42247
42362
  event,
42248
42363
  });
42249
- return { ...SUCCESS };
42364
+ return decorateResult({ result, stack });
42250
42365
  }
42251
42366
 
42252
42367
  function lastSetFormatIsTimed(inContextMatchUp) {
@@ -42890,24 +43005,27 @@ const keyColors = {
42890
43005
  };
42891
43006
  function removeDoubleExit(params) {
42892
43007
  const { inContextDrawMatchUps, appliedPolicies, drawDefinition, matchUpsMap, targetData, matchUp } = params;
43008
+ const { matchUpId } = matchUp;
42893
43009
  let { iteration = 0 } = params;
42894
43010
  iteration += 1;
42895
43011
  const stack = 'removeDoubleExit';
42896
43012
  pushGlobalLog({
42897
- method: stack,
42898
43013
  color: 'brightyellow',
43014
+ method: stack,
43015
+ matchUpId,
42899
43016
  iteration,
42900
43017
  keyColors,
42901
43018
  });
42902
- const { targetLinks: { loserTargetLink }, targetMatchUps: { loserMatchUp, winnerMatchUp, loserTargetDrawPosition }, } = targetData;
43019
+ const { targetMatchUps: { loserMatchUp, winnerMatchUp, loserTargetDrawPosition }, targetLinks: { loserTargetLink }, } = targetData;
42903
43020
  if (winnerMatchUp && winnerMatchUp.matchUpStatus !== BYE) {
42904
- const { stage, roundNumber, roundPosition } = winnerMatchUp;
43021
+ const { stage, roundNumber, roundPosition, structureName } = winnerMatchUp;
42905
43022
  pushGlobalLog({
42906
43023
  winner: 'winner',
42907
- stage,
42908
- roundNumber,
42909
43024
  roundPosition,
43025
+ structureName,
43026
+ roundNumber,
42910
43027
  keyColors,
43028
+ stage,
42911
43029
  });
42912
43030
  conditionallyRemoveDrawPosition({
42913
43031
  ...params,
@@ -42916,22 +43034,24 @@ function removeDoubleExit(params) {
42916
43034
  iteration,
42917
43035
  });
42918
43036
  }
42919
- if (loserMatchUp && loserMatchUp.matchUpStatus !== BYE) {
43037
+ const byePropagatedToLoserMatchUp = loserMatchUp?.matchUpStatus === BYE && (loserMatchUp?.feedRound || loserMatchUp?.roundNumber === 1);
43038
+ if (loserMatchUp && (loserMatchUp.matchUpStatus !== BYE || byePropagatedToLoserMatchUp)) {
42920
43039
  const inContextLoserMatchUp = inContextDrawMatchUps.find(({ matchUpId }) => matchUpId === loserMatchUp.matchUpId);
42921
43040
  const { structure: loserStructure } = findStructure({
42922
43041
  drawDefinition,
42923
43042
  structureId: inContextLoserMatchUp.structureId,
42924
43043
  });
42925
- const { stage, roundNumber, roundPosition, feedRound } = loserMatchUp;
43044
+ const { stage, roundNumber, roundPosition, feedRound, structureName } = loserMatchUp;
42926
43045
  pushGlobalLog({
42927
43046
  loser: 'loser',
42928
- stage,
42929
- roundNumber,
42930
43047
  roundPosition,
43048
+ structureName,
43049
+ roundNumber,
42931
43050
  keyColors,
42932
43051
  feedRound,
43052
+ stage,
42933
43053
  });
42934
- if (appliedPolicies?.progression?.doubleExitPropagateBye) {
43054
+ if (appliedPolicies?.progression?.doubleExitPropagateBye || byePropagatedToLoserMatchUp) {
42935
43055
  removeDirectedBye({
42936
43056
  drawPosition: loserTargetDrawPosition,
42937
43057
  targetLink: loserTargetLink,
@@ -42943,8 +43063,8 @@ function removeDoubleExit(params) {
42943
43063
  else {
42944
43064
  const result = conditionallyRemoveDrawPosition({
42945
43065
  ...params,
42946
- structure: loserStructure,
42947
43066
  targetMatchUp: loserMatchUp,
43067
+ structure: loserStructure,
42948
43068
  iteration,
42949
43069
  });
42950
43070
  if (result.error)
@@ -42956,7 +43076,7 @@ function removeDoubleExit(params) {
42956
43076
  function conditionallyRemoveDrawPosition(params) {
42957
43077
  const { inContextDrawMatchUps, appliedPolicies, drawDefinition, sourceMatchUp, targetMatchUp, matchUpsMap, structure, iteration, } = params;
42958
43078
  const stack = 'conditionallyRemoveDrawPosition';
42959
- pushGlobalLog({ method: stack });
43079
+ pushGlobalLog({ method: stack, structureName: structure?.structureName, iteration });
42960
43080
  const nextTargetData = positionTargets({
42961
43081
  matchUpId: targetMatchUp.matchUpId,
42962
43082
  inContextDrawMatchUps,
@@ -42996,15 +43116,16 @@ function conditionallyRemoveDrawPosition(params) {
42996
43116
  }
42997
43117
  }
42998
43118
  if (nextWinnerMatchUp && drawPositionToRemove) {
42999
- const { stage, roundNumber, roundPosition } = nextWinnerMatchUp;
43119
+ const { stage, roundNumber, roundPosition, structureName } = nextWinnerMatchUp;
43000
43120
  pushGlobalLog({
43001
43121
  method: 'removeDirectedWinner',
43002
43122
  drawPositionToRemove,
43003
- keyColors,
43004
43123
  color: 'brightgreen',
43005
- stage,
43006
- roundNumber,
43007
43124
  roundPosition,
43125
+ structureName,
43126
+ roundNumber,
43127
+ keyColors,
43128
+ stage,
43008
43129
  });
43009
43130
  removeDirectedWinner({
43010
43131
  winningDrawPosition: drawPositionToRemove,
@@ -45024,7 +45145,7 @@ function resetAdHocMatchUps(params) {
45024
45145
  return { ...SUCCESS };
45025
45146
  }
45026
45147
 
45027
- function setOrderOfFinish$1({ drawDefinition, finishingOrder }) {
45148
+ function setOrderOfFinish$1({ tournamentRecord, drawDefinition, finishingOrder }) {
45028
45149
  if (!drawDefinition)
45029
45150
  return { error: MISSING_DRAW_DEFINITION };
45030
45151
  const stack = 'setOrderOfFinish';
@@ -45125,7 +45246,15 @@ function setOrderOfFinish$1({ drawDefinition, finishingOrder }) {
45125
45246
  });
45126
45247
  if (result.error)
45127
45248
  return decorateResult({ result, stack });
45128
- result.completedMatchUps?.forEach((matchUp) => (matchUp.orderOfFinish = valuesMap[matchUp.matchUpId]));
45249
+ result.completedMatchUps?.forEach((matchUp) => {
45250
+ matchUp.orderOfFinish = valuesMap[matchUp.matchUpId];
45251
+ modifyMatchUpNotice({
45252
+ tournamentId: tournamentRecord.tournamentId,
45253
+ context: 'setOrderOfFinish',
45254
+ drawDefinition,
45255
+ matchUp,
45256
+ });
45257
+ });
45129
45258
  }
45130
45259
  return { ...SUCCESS };
45131
45260
  }