tods-competition-factory 1.8.0 → 1.8.2

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.
package/dist/index.mjs CHANGED
@@ -333,7 +333,7 @@ const matchUpFormatCode = {
333
333
  };
334
334
 
335
335
  function factoryVersion() {
336
- return "1.8.0";
336
+ return "1.8.2";
337
337
  }
338
338
 
339
339
  function getObjectTieFormat(obj) {
@@ -2384,7 +2384,7 @@ function JSON2CSV(arrayOfJSON, config) {
2384
2384
  rowJoiner
2385
2385
  ) : rows.join(rowJoiner);
2386
2386
  }
2387
- function flattenJSON(obj, keyJoiner, path = []) {
2387
+ function flattenJSON(obj, keyJoiner = ".", path = []) {
2388
2388
  return typeof obj === "object" && Object.keys(obj).reduce((result, key) => {
2389
2389
  if (typeof obj[key] !== "object") {
2390
2390
  result[path.concat(key).join(keyJoiner)] = obj[key];
@@ -5067,8 +5067,8 @@ function removeExtension({
5067
5067
  }
5068
5068
  function addEventExtension({
5069
5069
  tournamentRecords,
5070
- eventId,
5071
- extension
5070
+ extension,
5071
+ eventId
5072
5072
  }) {
5073
5073
  if (typeof eventId !== "string")
5074
5074
  return { error: MISSING_EVENT };
@@ -15183,6 +15183,144 @@ const fixtures = {
15183
15183
  flagIOC
15184
15184
  };
15185
15185
 
15186
+ const logColors = {
15187
+ reset: "\x1B[0m",
15188
+ bright: "\x1B[1m",
15189
+ dim: "\x1B[2m",
15190
+ red: "\x1B[31m",
15191
+ brightred: "\x1B[91m",
15192
+ green: "\x1B[32m",
15193
+ brightgreen: "\x1B[92m",
15194
+ yellow: "\x1B[33m",
15195
+ brightyellow: "\x1B[93m",
15196
+ blue: "\x1B[34m",
15197
+ brightblue: "\x1B[94m",
15198
+ lightblue: "\x1B[105m",
15199
+ magenta: "\x1B[35m",
15200
+ brightmagenta: "\x1B[95m",
15201
+ cyan: "\x1B[36m",
15202
+ brightcyan: "\x1B[96m",
15203
+ white: "\x1B[37m",
15204
+ brightwhite: "\x1B[97m"
15205
+ };
15206
+
15207
+ const globalLog = [];
15208
+ function pushGlobalLog(value, devContextOverride) {
15209
+ if (typeof value === "string")
15210
+ value = { method: value };
15211
+ if (devContextOverride || getDevContext())
15212
+ globalLog.push(value);
15213
+ }
15214
+ function getGlobalLog(purge) {
15215
+ const globalLogCopy = globalLog.slice();
15216
+ if (purge) {
15217
+ globalLog.length = 0;
15218
+ }
15219
+ return globalLogCopy;
15220
+ }
15221
+ function printGlobalLog(purge) {
15222
+ const globalLogCopy = getGlobalLog(purge);
15223
+ const modifiedText = globalLogCopy.map((line) => {
15224
+ const { color, keyColors, method, newline } = line;
15225
+ const methodColor = Object.keys(logColors).includes(color) ? logColors[color] : logColors.cyan;
15226
+ const bodyKeys = Object.keys(line).filter(
15227
+ (key) => !["color", "keyColors", "method", "newline"].includes(key)
15228
+ );
15229
+ const body = bodyKeys.map((key) => {
15230
+ const keyColor = keyColors && Object.keys(keyColors).includes(key) && logColors[keyColors[key]] ? logColors[keyColors[key]] : logColors.brightwhite;
15231
+ return `${logColors.white}${key}: ${keyColor}${line[key]}`;
15232
+ }).join(", ");
15233
+ const tabs = method?.length < 15 ? ` ` : " ";
15234
+ return [
15235
+ newline ? "\n" : "",
15236
+ methodColor,
15237
+ method,
15238
+ tabs,
15239
+ logColors.white,
15240
+ body,
15241
+ logColors.reset,
15242
+ "\n"
15243
+ ].join("");
15244
+ });
15245
+ if (modifiedText?.length)
15246
+ console.log(...modifiedText);
15247
+ }
15248
+ function purgeGlobalLog() {
15249
+ globalLog.length = 0;
15250
+ }
15251
+
15252
+ function visualizeScheduledMatchUps({
15253
+ scheduledMatchUps,
15254
+ showGlobalLog
15255
+ }) {
15256
+ purgeGlobalLog();
15257
+ const structureIds = scheduledMatchUps?.reduce(
15258
+ (structureIds2, { structureId }) => structureIds2.includes(structureId) ? structureIds2 : structureIds2.concat(structureId),
15259
+ []
15260
+ );
15261
+ const structureNames = Object.assign(
15262
+ {},
15263
+ ...(structureIds || []).map((structureId) => {
15264
+ const { structureName, matchUpType } = scheduledMatchUps.find(
15265
+ (matchUp) => matchUp.structureId === structureId
15266
+ );
15267
+ return {
15268
+ [structureId]: `${structureName} ${matchUpType}`
15269
+ };
15270
+ })
15271
+ );
15272
+ structureIds?.forEach((structureId) => {
15273
+ pushGlobalLog(
15274
+ {
15275
+ color: "blue",
15276
+ method: "draw",
15277
+ structure: structureNames[structureId],
15278
+ keyColors: {
15279
+ structure: "magenta"
15280
+ }
15281
+ },
15282
+ true
15283
+ );
15284
+ const structureMatchUps = scheduledMatchUps.filter(
15285
+ (matchUp) => matchUp.structureId === structureId
15286
+ );
15287
+ const roundMatchUps = getRoundMatchUps$1({
15288
+ matchUps: structureMatchUps
15289
+ })?.roundMatchUps || [];
15290
+ Object.keys(roundMatchUps).forEach((roundNumber) => {
15291
+ pushGlobalLog(
15292
+ {
15293
+ roundNumber,
15294
+ keyColors: {
15295
+ roundNumber: "brightcyan"
15296
+ }
15297
+ },
15298
+ true
15299
+ );
15300
+ roundMatchUps[roundNumber].forEach(({ matchUpId, schedule }) => {
15301
+ const scheduledTime = extractTime(schedule.scheduledTime);
15302
+ pushGlobalLog(
15303
+ {
15304
+ matchUpId,
15305
+ time: scheduledTime,
15306
+ date: schedule.scheduledDate,
15307
+ venue: schedule.venueId,
15308
+ keyColors: {
15309
+ time: "brightcyan",
15310
+ date: "brightcyan",
15311
+ matchUpId: "yellow",
15312
+ venue: "magenta"
15313
+ }
15314
+ },
15315
+ true
15316
+ );
15317
+ });
15318
+ });
15319
+ });
15320
+ if (showGlobalLog)
15321
+ printGlobalLog();
15322
+ }
15323
+
15186
15324
  function calculateWinCriteria({
15187
15325
  collectionDefinitions = [],
15188
15326
  collectionGroups = []
@@ -20660,11 +20798,6 @@ function getStructureDrawPositionProfiles(params) {
20660
20798
  };
20661
20799
  }
20662
20800
 
20663
- function pushGlobalLog(value, devContextOverride) {
20664
- if (devContextOverride || getDevContext())
20665
- ;
20666
- }
20667
-
20668
20801
  function clearDrawPosition(params) {
20669
20802
  let { inContextDrawMatchUps, participantId, drawPosition } = params;
20670
20803
  const { tournamentRecord, drawDefinition, structureId, matchUpsMap, event } = params;
@@ -20968,7 +21101,11 @@ function removeDrawPosition({
20968
21101
  const noChange = initialDrawPositions?.includes(drawPosition) && initialMatchUpStatus === targetMatchUp.matchUpStatus && initialWinningSide === targetMatchUp.winningSide;
20969
21102
  if (!noChange) {
20970
21103
  if (removedDrawPosition) {
20971
- pushGlobalLog();
21104
+ pushGlobalLog({
21105
+ method: stack,
21106
+ color: "brightyellow",
21107
+ removedDrawPosition
21108
+ });
20972
21109
  }
20973
21110
  modifyMatchUpNotice({
20974
21111
  tournamentId: tournamentRecord?.tournamentId,
@@ -21012,7 +21149,11 @@ function removeDrawPosition({
21012
21149
  matchUps: loserStructureMatchUps
21013
21150
  });
21014
21151
  if (initialRoundNumber2 === 1) {
21015
- pushGlobalLog();
21152
+ pushGlobalLog({
21153
+ method: stack,
21154
+ color: "brightyellow",
21155
+ loserMatchUpDrawPosition
21156
+ });
21016
21157
  drawPositionRemovals({
21017
21158
  structureId: loserMatchUp.structureId,
21018
21159
  drawPosition: loserMatchUpDrawPosition,
@@ -21461,7 +21602,7 @@ function assignDrawPositionBye$1({
21461
21602
  if (!structureId)
21462
21603
  ({ structureId } = structure);
21463
21604
  const stack = "assignDrawPositionBye";
21464
- pushGlobalLog();
21605
+ pushGlobalLog({ method: stack, color: "cyan", drawPosition });
21465
21606
  if (!matchUpsMap) {
21466
21607
  matchUpsMap = getMatchUpsMap({ drawDefinition });
21467
21608
  }
@@ -21645,7 +21786,8 @@ function advanceDrawPosition({
21645
21786
  matchUpId,
21646
21787
  event
21647
21788
  }) {
21648
- pushGlobalLog();
21789
+ const stack = "advanceDrawPosition";
21790
+ pushGlobalLog({ method: stack, color: "cyan", drawPositionToAdvance });
21649
21791
  const matchUp = matchUpsMap.drawMatchUps.find(
21650
21792
  (matchUp2) => matchUp2.matchUpId === matchUpId
21651
21793
  );
@@ -21788,10 +21930,16 @@ function advanceWinner({
21788
21930
  winningSide: void 0,
21789
21931
  drawPositions
21790
21932
  });
21791
- noContextWinnerMatchUp.drawPositions.find(
21933
+ const changedDrawPosition = noContextWinnerMatchUp.drawPositions.find(
21792
21934
  (position) => !twoDrawPositions.includes(position)
21793
21935
  );
21794
- pushGlobalLog();
21936
+ pushGlobalLog({
21937
+ method: stack,
21938
+ color: "brightyellow",
21939
+ changedDrawPosition,
21940
+ pairedDrawPositionIsBye,
21941
+ drawPositionIsBye
21942
+ });
21795
21943
  modifyMatchUpNotice({
21796
21944
  tournamentId: tournamentRecord?.tournamentId,
21797
21945
  matchUp: noContextWinnerMatchUp,
@@ -21855,7 +22003,8 @@ function assignFedDrawPositionBye({
21855
22003
  event
21856
22004
  }) {
21857
22005
  const { roundNumber } = loserMatchUp;
21858
- pushGlobalLog();
22006
+ const stack = "assignFedDrawPositionBye";
22007
+ pushGlobalLog({ method: stack, color: "cyan", loserTargetDrawPosition });
21859
22008
  const mappedMatchUps = matchUpsMap?.mappedMatchUps || {};
21860
22009
  const loserStructureMatchUps = mappedMatchUps[loserMatchUp.structureId].matchUps;
21861
22010
  const { initialRoundNumber } = getInitialRoundNumber({
@@ -24844,6 +24993,12 @@ function attemptToSetWinningSide(params) {
24844
24993
  });
24845
24994
  }
24846
24995
 
24996
+ const keyColors = {
24997
+ drawPositionToRemove: "green",
24998
+ iteration: "brightred",
24999
+ winner: "green",
25000
+ loser: "brightred"
25001
+ };
24847
25002
  function removeDoubleExit(params) {
24848
25003
  const {
24849
25004
  inContextDrawMatchUps,
@@ -24856,13 +25011,25 @@ function removeDoubleExit(params) {
24856
25011
  let { iteration = 0 } = params;
24857
25012
  iteration += 1;
24858
25013
  const stack = "removeDoubleExit";
24859
- pushGlobalLog();
25014
+ pushGlobalLog({
25015
+ method: stack,
25016
+ color: "brightyellow",
25017
+ iteration,
25018
+ keyColors
25019
+ });
24860
25020
  const {
24861
25021
  targetLinks: { loserTargetLink },
24862
25022
  targetMatchUps: { loserMatchUp, winnerMatchUp, loserTargetDrawPosition }
24863
25023
  } = targetData;
24864
25024
  if (winnerMatchUp && winnerMatchUp.matchUpStatus !== BYE) {
24865
- pushGlobalLog();
25025
+ const { stage, roundNumber, roundPosition } = winnerMatchUp;
25026
+ pushGlobalLog({
25027
+ winner: "winner",
25028
+ stage,
25029
+ roundNumber,
25030
+ roundPosition,
25031
+ keyColors
25032
+ });
24866
25033
  conditionallyRemoveDrawPosition({
24867
25034
  ...params,
24868
25035
  targetMatchUp: winnerMatchUp,
@@ -24878,7 +25045,15 @@ function removeDoubleExit(params) {
24878
25045
  drawDefinition,
24879
25046
  structureId: inContextLoserMatchUp.structureId
24880
25047
  });
24881
- pushGlobalLog();
25048
+ const { stage, roundNumber, roundPosition, feedRound } = loserMatchUp;
25049
+ pushGlobalLog({
25050
+ loser: "loser",
25051
+ stage,
25052
+ roundNumber,
25053
+ roundPosition,
25054
+ keyColors,
25055
+ feedRound
25056
+ });
24882
25057
  if (appliedPolicies?.progression?.doubleExitPropagateBye) {
24883
25058
  removeDirectedBye({
24884
25059
  drawPosition: loserTargetDrawPosition,
@@ -24912,7 +25087,7 @@ function conditionallyRemoveDrawPosition(params) {
24912
25087
  iteration
24913
25088
  } = params;
24914
25089
  const stack = "conditionallyRemoveDrawPosition";
24915
- pushGlobalLog();
25090
+ pushGlobalLog({ method: stack });
24916
25091
  const nextTargetData = positionTargets({
24917
25092
  matchUpId: targetMatchUp.matchUpId,
24918
25093
  inContextDrawMatchUps,
@@ -24968,7 +25143,16 @@ function conditionallyRemoveDrawPosition(params) {
24968
25143
  }
24969
25144
  }
24970
25145
  if (nextWinnerMatchUp && drawPositionToRemove) {
24971
- pushGlobalLog();
25146
+ const { stage, roundNumber, roundPosition } = nextWinnerMatchUp;
25147
+ pushGlobalLog({
25148
+ method: "removeDirectedWinner",
25149
+ drawPositionToRemove,
25150
+ keyColors,
25151
+ color: "brightgreen",
25152
+ stage,
25153
+ roundNumber,
25154
+ roundPosition
25155
+ });
24972
25156
  removeDirectedWinner({
24973
25157
  winningDrawPosition: drawPositionToRemove,
24974
25158
  winnerMatchUp: nextWinnerMatchUp,
@@ -25493,7 +25677,12 @@ function setMatchUpStatus$2(params) {
25493
25677
  return swapWinnerLoser(params);
25494
25678
  }
25495
25679
  const matchUpWinner = winningSide && !matchUpTieId || params.projectedWinningSide;
25496
- pushGlobalLog();
25680
+ pushGlobalLog({
25681
+ method: stack,
25682
+ activeDownstream,
25683
+ matchUpWinner,
25684
+ winningSide
25685
+ });
25497
25686
  const result = !activeDownstream && noDownstreamDependencies(params) || matchUpWinner && winningSideWithDownstreamDependencies(params) || directingMatchUpStatus && applyMatchUpValues(params) || {
25498
25687
  error: NO_VALID_ACTIONS
25499
25688
  };
@@ -32970,14 +33159,16 @@ function getMatchUpsToSchedule({
32970
33159
  scheduleCompletedMatchUps,
32971
33160
  dateScheduledMatchUpIds,
32972
33161
  matchUpNotBeforeTimes,
33162
+ matchUpScheduleTimes,
32973
33163
  orderedMatchUpIds,
32974
33164
  clearDate,
32975
33165
  matchUps
32976
33166
  }) {
33167
+ const alreadyScheduledMatchUpIds = Object.keys(matchUpScheduleTimes);
32977
33168
  const matchUpsToSchedule = orderedMatchUpIds.map(
32978
33169
  (matchUpId) => matchUps.find((matchUp) => matchUp.matchUpId === matchUpId)
32979
33170
  ).filter(Boolean).filter((matchUp) => {
32980
- const alreadyScheduled = !clearDate && dateScheduledMatchUpIds.includes(matchUp.matchUpId);
33171
+ const alreadyScheduled = !clearDate && (dateScheduledMatchUpIds.includes(matchUp.matchUpId) || alreadyScheduledMatchUpIds.includes(matchUp.matchUpId));
32981
33172
  const doNotSchedule = [
32982
33173
  BYE,
32983
33174
  DEFAULTED,
@@ -33229,6 +33420,7 @@ function getVenueSchedulingDetails({
33229
33420
  scheduleCompletedMatchUps,
33230
33421
  dateScheduledMatchUpIds,
33231
33422
  matchUpNotBeforeTimes,
33423
+ matchUpScheduleTimes,
33232
33424
  orderedMatchUpIds,
33233
33425
  clearDate,
33234
33426
  matchUps
@@ -34482,8 +34674,7 @@ function scheduleProfileRounds({
34482
34674
  clearScheduledMatchUps({ tournamentRecords, scheduledDates });
34483
34675
  }
34484
34676
  const { courts } = getVenuesAndCourts({
34485
- dates: scheduleDates,
34486
- ignoreDisabled: true,
34677
+ ignoreDisabled: false,
34487
34678
  tournamentRecords
34488
34679
  });
34489
34680
  const { matchUps } = allCompetitionMatchUps({
@@ -36804,7 +36995,9 @@ const POLICY_MATCHUP_ACTIONS_DEFAULT = {
36804
36995
  },
36805
36996
  processCodes: {
36806
36997
  substitution: ["RANKING.IGNORE", "RATING.IGNORE"]
36807
- }
36998
+ },
36999
+ substituteAfterCompleted: false,
37000
+ substituteWithoutScore: false
36808
37001
  }
36809
37002
  };
36810
37003
 
@@ -49191,11 +49384,17 @@ function validDefinitionKeys(definition) {
49191
49384
  }
49192
49385
  function newDrawDefinition({
49193
49386
  drawId = UUID(),
49387
+ processCodes,
49194
49388
  matchUpType,
49195
49389
  drawType
49196
49390
  }) {
49197
49391
  const drawDefinition = definitionTemplate();
49198
- return Object.assign(drawDefinition, { drawId, drawType, matchUpType });
49392
+ return Object.assign(drawDefinition, {
49393
+ processCodes,
49394
+ matchUpType,
49395
+ drawType,
49396
+ drawId
49397
+ });
49199
49398
  }
49200
49399
 
49201
49400
  let drawDefinition$1;
@@ -58210,7 +58409,11 @@ function generateDrawDefinition(params) {
58210
58409
  return decorateResult({ result: { error: INVALID_VALUES }, stack });
58211
58410
  if (existingDrawDefinition && drawType !== existingDrawDefinition.drawType)
58212
58411
  existingDrawDefinition.drawType = drawType;
58213
- let drawDefinition = existingDrawDefinition ?? newDrawDefinition({ drawType, drawId: params.drawId });
58412
+ let drawDefinition = existingDrawDefinition ?? newDrawDefinition({
58413
+ drawType,
58414
+ drawId: params.drawId,
58415
+ processCodes: params.processCodes
58416
+ });
58214
58417
  if (matchUpFormat || tieFormat) {
58215
58418
  const equivalentInScope = matchUpFormat && event?.matchUpFormat === matchUpFormat || event?.tieFormat && tieFormat && JSON.stringify(event.tieFormat) === JSON.stringify(tieFormat);
58216
58419
  if (!equivalentInScope) {
@@ -58696,10 +58899,24 @@ function modifyEvent({
58696
58899
  eventId,
58697
58900
  event
58698
58901
  }) {
58902
+ const stack = "modifyEvent";
58699
58903
  if (!tournamentRecord)
58700
- return { error: MISSING_TOURNAMENT_RECORD };
58701
- if (!isString(eventId) || !isObject(eventUpdates))
58702
- return { error: INVALID_VALUES };
58904
+ return decorateResult({
58905
+ result: { error: MISSING_TOURNAMENT_RECORD },
58906
+ stack
58907
+ });
58908
+ if (!isString(eventId))
58909
+ return decorateResult({
58910
+ result: { error: MISSING_EVENT },
58911
+ context: { eventId },
58912
+ stack
58913
+ });
58914
+ if (!isObject(eventUpdates))
58915
+ return decorateResult({
58916
+ result: { error: INVALID_VALUES },
58917
+ context: { eventUpdates },
58918
+ stack
58919
+ });
58703
58920
  const enteredParticipantIds = event?.entries?.filter(({ entryStatus }) => {
58704
58921
  const status = entryStatus;
58705
58922
  return [...STRUCTURE_SELECTED_STATUSES, ALTERNATE].includes(status);
@@ -58722,8 +58939,9 @@ function modifyEvent({
58722
58939
  const validGender = !enteredParticipantGenders.length || [MIXED, ANY].includes(eventUpdates.gender ?? "") || enteredParticipantGenders.length === 1 && enteredParticipantGenders[0] === eventUpdates.gender;
58723
58940
  if (eventUpdates.gender && !validGender)
58724
58941
  return decorateResult({
58725
- context: { gender: eventUpdates.gender },
58726
- result: { error: INVALID_VALUES }
58942
+ context: { gender: eventUpdates.gender, validGender },
58943
+ result: { error: INVALID_VALUES },
58944
+ stack
58727
58945
  });
58728
58946
  const validEventTypes = enteredParticipantTypes.includes(TEAM$1) && [TEAM$1] || enteredParticipantTypes.includes(INDIVIDUAL) && [SINGLES] || enteredParticipantTypes.includes(PAIR) && [DOUBLES] || [
58729
58947
  DOUBLES,
@@ -58733,8 +58951,9 @@ function modifyEvent({
58733
58951
  const validEventType = validEventTypes.includes(eventUpdates.eventType ?? "");
58734
58952
  if (eventUpdates.eventType && !validEventType)
58735
58953
  return decorateResult({
58736
- context: { participantType: eventUpdates.eventType },
58737
- result: { error: INVALID_VALUES }
58954
+ context: { participantType: eventUpdates.eventType, validEventType },
58955
+ result: { error: INVALID_VALUES },
58956
+ stack
58738
58957
  });
58739
58958
  if (eventUpdates.eventType)
58740
58959
  event.eventType = eventUpdates.eventType;
@@ -62615,6 +62834,7 @@ function generateEventWithFlights(params) {
62615
62834
  eventExtensions,
62616
62835
  surfaceCategory,
62617
62836
  tieFormatName,
62837
+ processCodes,
62618
62838
  discipline,
62619
62839
  eventLevel,
62620
62840
  timeItems,
@@ -62660,6 +62880,7 @@ function generateEventWithFlights(params) {
62660
62880
  const newEvent = {
62661
62881
  ...eventAttributes,
62662
62882
  surfaceCategory,
62883
+ processCodes,
62663
62884
  discipline,
62664
62885
  eventLevel,
62665
62886
  eventName,
@@ -63904,7 +64125,8 @@ const utilities = {
63904
64125
  unique,
63905
64126
  UUID,
63906
64127
  UUIDS,
63907
- validateTieFormat
64128
+ validateTieFormat,
64129
+ visualizeScheduledMatchUps
63908
64130
  };
63909
64131
 
63910
64132
  export { EntryStatusEnum, competitionEngine, competitionEngineAsync, deleteNotices, drawDefinitionConstants, drawEngine, drawEngineAsync, entryStatusConstants, errorConditionConstants, eventConstants, factoryConstants, fixtures, flightConstants, genderConstants, getNotices, keyValueConstants, matchUpActionConstants, matchUpEngine, matchUpEngineAsync, matchUpFormatCode, matchUpStatusConstants, matchUpTypes, mocksEngine, participantConstants, participantRoles, participantTypes, penaltyConstants, policyConstants, positionActionConstants, resultConstants, scaleConstants, scaleEngine, scaleEngineAsync, scoreGovernor, setDeepCopy, setDevContext, setStateProvider, setSubscriptions, surfaceConstants, timeItemConstants, tournamentEngine, tournamentEngineAsync, utilities, venueConstants, factoryVersion as version };