tods-competition-factory 1.8.1 → 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.1";
336
+ return "1.8.2";
337
337
  }
338
338
 
339
339
  function getObjectTieFormat(obj) {
@@ -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
@@ -63933,7 +64125,8 @@ const utilities = {
63933
64125
  unique,
63934
64126
  UUID,
63935
64127
  UUIDS,
63936
- validateTieFormat
64128
+ validateTieFormat,
64129
+ visualizeScheduledMatchUps
63937
64130
  };
63938
64131
 
63939
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 };