tods-competition-factory 1.9.0 → 1.9.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
@@ -1360,7 +1360,6 @@ function handleCaughtError$1({
1360
1360
  const globalState = {
1361
1361
  tournamentFactoryVersion: "0.0.0",
1362
1362
  timers: { default: { elapsedTime: 0 } },
1363
- iterators: { makeDeepCopy: 0 },
1364
1363
  deepCopyAttributes: {
1365
1364
  stringify: [],
1366
1365
  ignore: [],
@@ -1437,12 +1436,6 @@ function setGlobalLog(loggingFx) {
1437
1436
  function setDevContext(value) {
1438
1437
  globalState.devContext = value;
1439
1438
  }
1440
- function setDeepCopyIterations(value) {
1441
- globalState.iterators.makeDeepCopy = value;
1442
- }
1443
- function getDeepCopyIterations() {
1444
- return globalState.iterators.makeDeepCopy;
1445
- }
1446
1439
  function disableNotifications() {
1447
1440
  _globalStateProvider.disableNotifications();
1448
1441
  }
@@ -1538,7 +1531,13 @@ function handleCaughtError({
1538
1531
  }
1539
1532
  function globalLog$1(engine, log) {
1540
1533
  if (globalState.globalLog) {
1541
- return globalState.globalLog(engine, log);
1534
+ try {
1535
+ globalState.globalLog(engine, log);
1536
+ } catch (error) {
1537
+ console.log("globalLog error", error);
1538
+ console.log(engine, log);
1539
+ setGlobalLog();
1540
+ }
1542
1541
  } else {
1543
1542
  console.log(engine, log);
1544
1543
  }
@@ -1869,13 +1868,6 @@ function makeDeepCopy(sourceObject, convertExtensions, internalUse, removeExtens
1869
1868
  if (!deepCopy?.enabled && !internalUse || typeof sourceObject !== "object" || typeof sourceObject === "function" || sourceObject === null || typeof deepCopy?.threshold === "number" && iteration >= deepCopy.threshold) {
1870
1869
  return sourceObject;
1871
1870
  }
1872
- const devContext = getDevContext({ makeDeepCopy: true });
1873
- if (devContext) {
1874
- setDeepCopyIterations(iteration);
1875
- if (typeof devContext === "object" && (iteration > (devContext.iterationThreshold || 15) || devContext.firstIteration && iteration === 0) && devContext.log && (!devContext.notInternalUse || devContext.notInternalUse && !internalUse)) {
1876
- console.log({ devContext, iteration, internalUse }, sourceObject);
1877
- }
1878
- }
1879
1871
  const targetObject = Array.isArray(sourceObject) ? [] : {};
1880
1872
  const sourceObjectKeys = Object.keys(sourceObject).filter(
1881
1873
  (key) => !internalUse || !ignore || Array.isArray(ignore) && !ignore.includes(key) || typeof ignore === "function" && !ignore(key)
@@ -2015,6 +2007,11 @@ const extractAttributes = (accessor) => (element) => !accessor || typeof element
2015
2007
  })) || typeof accessor === "object" && Object.keys(accessor).map((key) => ({
2016
2008
  [key]: getAccessorValue({ element, accessor: key })?.value
2017
2009
  })) || (typeof accessor === "string" && getAccessorValue({ element, accessor }))?.value;
2010
+ function getDefinedKeys(obj, ignoreValues, ignoreEmptyArrays) {
2011
+ return Object.keys(obj).filter(
2012
+ (key) => !ignoreValues.includes(obj[key]) && (!ignoreEmptyArrays || (Array.isArray(obj[key]) ? obj[key].length : true))
2013
+ );
2014
+ }
2018
2015
  function definedAttributes(obj, ignoreFalse, ignoreEmptyArrays, shallow) {
2019
2016
  if (typeof obj !== "object" || obj === null)
2020
2017
  return obj;
@@ -2024,9 +2021,7 @@ function definedAttributes(obj, ignoreFalse, ignoreEmptyArrays, shallow) {
2024
2021
  const ignoreValues = ["", void 0, null];
2025
2022
  if (ignoreFalse)
2026
2023
  ignoreValues.push(false);
2027
- const definedKeys = Object.keys(obj).filter(
2028
- (key) => !ignoreValues.includes(obj[key]) && (!ignoreEmptyArrays || (Array.isArray(obj[key]) ? obj[key].length : true))
2029
- );
2024
+ const definedKeys = getDefinedKeys(obj, ignoreValues, ignoreEmptyArrays);
2030
2025
  return Object.assign(
2031
2026
  {},
2032
2027
  ...definedKeys.map((key) => {
@@ -2419,7 +2414,7 @@ const matchUpFormatCode = {
2419
2414
  };
2420
2415
 
2421
2416
  function factoryVersion() {
2422
- return "1.9.0";
2417
+ return "1.9.2";
2423
2418
  }
2424
2419
 
2425
2420
  function getObjectTieFormat(obj) {
@@ -10333,11 +10328,10 @@ function modifyMatchUpScore({
10333
10328
  }
10334
10329
  if (Array.isArray(defaultedProcessCodes) && inContextMatchUp && !inContextMatchUp.sides?.every(({ participantId }) => participantId)) {
10335
10330
  if (matchUpStatus === DEFAULTED) {
10336
- if (matchUp.processCodes) {
10337
- matchUp.processCodes.push(...defaultedProcessCodes);
10338
- } else {
10339
- matchUp.processCodes = defaultedProcessCodes;
10340
- }
10331
+ matchUp.processCodes = unique([
10332
+ ...matchUp.processCodes ?? [],
10333
+ ...defaultedProcessCodes
10334
+ ]);
10341
10335
  } else {
10342
10336
  for (const processCode of defaultedProcessCodes || []) {
10343
10337
  const codeIndex = processCode && matchUp?.processCodes?.lastIndexOf(processCode);
@@ -25811,12 +25805,12 @@ function positionActions$1(params) {
25811
25805
  const isActiveDrawPosition = activeDrawPositions.includes(drawPosition);
25812
25806
  if (actionsDisabled)
25813
25807
  return {
25808
+ hasPositionAssigned: !!positionAssignment,
25814
25809
  info: "Actions Disabled for structure",
25815
- isByePosition,
25816
25810
  isActiveDrawPosition,
25817
25811
  isDrawPosition: true,
25818
- hasPositionAssigned: !!positionAssignment,
25819
- validActions: []
25812
+ validActions: [],
25813
+ isByePosition
25820
25814
  };
25821
25815
  if (isAvailableAction({ policyActions, action: ASSIGN_PARTICIPANT }) && !isActiveDrawPosition && positionAssignments && !disablePlacementActions && (!positionAssignment || isByePosition)) {
25822
25816
  const { validAssignmentActions } = getValidAssignmentActions({
@@ -26535,6 +26529,34 @@ function updateFactoryExtension({ tournamentRecord, value }) {
26535
26529
  addExtension$1({ element: tournamentRecord, extension: updatedExtension });
26536
26530
  }
26537
26531
 
26532
+ function engineLogging({
26533
+ methodName,
26534
+ elapsed,
26535
+ engine,
26536
+ params,
26537
+ result
26538
+ }) {
26539
+ const devContext = getDevContext();
26540
+ if (typeof devContext !== "object")
26541
+ return;
26542
+ const log = { method: methodName };
26543
+ const logError = result?.error && (devContext.errors === true || Array.isArray(devContext.errors) && devContext.errors.includes(methodName));
26544
+ const specifiedMethodParams = Array.isArray(devContext.params) && devContext.params?.includes(methodName);
26545
+ const logParams = devContext.params && !Array.isArray(devContext.params) || specifiedMethodParams;
26546
+ const exclude = Array.isArray(devContext.exclude) && devContext.exclude.includes(methodName);
26547
+ if (!exclude && ![void 0, false].includes(devContext.perf) && (isNaN(devContext.perf) || elapsed > devContext.perf)) {
26548
+ log.elapsed = elapsed;
26549
+ }
26550
+ if (!exclude && (logError || logParams)) {
26551
+ log.params = params;
26552
+ }
26553
+ if (!exclude && (logError || devContext.result && !Array.isArray(devContext.result) && (!Array.isArray(devContext.params) || specifiedMethodParams) || Array.isArray(devContext.result) && devContext.result?.includes(methodName))) {
26554
+ log.result = result;
26555
+ }
26556
+ if (Object.keys(log).length > 1)
26557
+ globalLog$1(engine, log);
26558
+ }
26559
+
26538
26560
  function notifySubscribers(params) {
26539
26561
  const { mutationStatus, tournamentId, directives, timeStamp } = params || {};
26540
26562
  const { topics } = getTopics();
@@ -29591,18 +29613,14 @@ function conditionallyAdvanceDrawPosition(params) {
29591
29613
  } else {
29592
29614
  sourceSideNumber = 2;
29593
29615
  }
29594
- } else {
29595
- if (targetMatchUp.feedRound) {
29596
- if (sourceMatchUp.structureId === targetMatchUp.structureId) {
29597
- sourceSideNumber = 2;
29598
- } else {
29599
- sourceSideNumber = 1;
29600
- }
29616
+ } else if (targetMatchUp.feedRound) {
29617
+ if (sourceMatchUp.structureId === targetMatchUp.structureId) {
29618
+ sourceSideNumber = 2;
29601
29619
  } else {
29602
- if (walkoverWinningSide)
29603
- sourceSideNumber = 3 - walkoverWinningSide;
29620
+ sourceSideNumber = 1;
29604
29621
  }
29605
- }
29622
+ } else if (walkoverWinningSide)
29623
+ sourceSideNumber = 3 - walkoverWinningSide;
29606
29624
  }
29607
29625
  const sourceMatchUpStatus = params.matchUpStatus;
29608
29626
  const pairedMatchUpStatus = pairedPreviousMatchUp?.matchUpStatus;
@@ -40665,27 +40683,6 @@ function setState$4(records, deepCopyOption = true) {
40665
40683
  return setTournamentRecords(deepCopyOption ? makeDeepCopy(records) : records);
40666
40684
  }
40667
40685
 
40668
- function engineLogging({ result, methodName, elapsed, params, engine }) {
40669
- const devContext = getDevContext();
40670
- const log = { method: methodName };
40671
- const logError = result?.error && (devContext.errors === true || Array.isArray(devContext.errors) && devContext.errors.includes(methodName));
40672
- const specifiedMethodParams = Array.isArray(devContext.params) && devContext.params?.includes(methodName);
40673
- const logParams = devContext.params && !Array.isArray(devContext.params) || specifiedMethodParams;
40674
- const exclude = Array.isArray(devContext.exclude) && devContext.exclude.includes(methodName);
40675
- if (!exclude && ![void 0, false].includes(devContext.perf) && (isNaN(devContext.perf) || elapsed > devContext.perf))
40676
- log.elapsed = elapsed;
40677
- if (!exclude && (logError || logParams)) {
40678
- log.params = params;
40679
- }
40680
- if (!exclude && (logError || devContext.result && !Array.isArray(devContext.result) && (!Array.isArray(devContext.params) || specifiedMethodParams) || Array.isArray(devContext.result) && devContext.result?.includes(methodName))) {
40681
- log.result = result;
40682
- }
40683
- if (Object.keys(log).length > 1)
40684
- globalLog$1(engine, log);
40685
- if (result && devContext.makeDeepCopy)
40686
- result.deepCopyIterations = getDeepCopyIterations();
40687
- }
40688
-
40689
40686
  const competitionEngine = function() {
40690
40687
  const engine = {
40691
40688
  getState: (params) => getState$3({
@@ -40817,6 +40814,7 @@ const competitionEngine = function() {
40817
40814
  return { error: INVALID_VALUES };
40818
40815
  const tournamentRecords = getTournamentRecords();
40819
40816
  const activeTournamentId = getTournamentId();
40817
+ const start = Date.now();
40820
40818
  const snapshot = rollbackOnError && makeDeepCopy(tournamentRecords, false, true);
40821
40819
  let timeStamp;
40822
40820
  const results = [];
@@ -40826,10 +40824,8 @@ const competitionEngine = function() {
40826
40824
  const { method: methodName, params } = directive;
40827
40825
  if (!engine[methodName]) {
40828
40826
  const result3 = { error: METHOD_NOT_FOUND, methodName };
40829
- const devContext = getDevContext();
40830
- if (devContext.result && !Array.isArray(devContext.result) || Array.isArray(devContext.result) && devContext.result?.includes(methodName)) {
40831
- console.log("ce:", result3);
40832
- }
40827
+ const elapsed = Date.now() - start;
40828
+ engineLogging({ result: result3, methodName, elapsed, params, engine: "ce:" });
40833
40829
  return result3;
40834
40830
  }
40835
40831
  const result2 = executeFunction(
@@ -41237,10 +41233,11 @@ function generateQualifyingStructures({
41237
41233
  for (const structureProfile of (structureProfiles || []).sort(
41238
41234
  sequenceSort
41239
41235
  )) {
41240
- let drawSize = structureProfile.drawSize || coerceEven(structureProfile.participantsCount);
41236
+ let drawSize = coerceEven(
41237
+ structureProfile.drawSize || structureProfile.participantsCount
41238
+ );
41241
41239
  const {
41242
41240
  qualifyingRoundNumber,
41243
- qualifyingPositions,
41244
41241
  structureOptions,
41245
41242
  matchUpFormat,
41246
41243
  structureName,
@@ -41248,6 +41245,7 @@ function generateQualifyingStructures({
41248
41245
  drawType
41249
41246
  } = structureProfile;
41250
41247
  const matchUpType = structureProfile.matchUpType;
41248
+ const qualifyingPositions = structureProfile.qualifyingPositions || deriveQualifyingPositions({ drawSize, qualifyingRoundNumber });
41251
41249
  let roundLimit, structure, matchUps;
41252
41250
  if (!isConvertableInteger(drawSize)) {
41253
41251
  return decorateResult({
@@ -41354,6 +41352,15 @@ function generateQualifyingStructures({
41354
41352
  links
41355
41353
  };
41356
41354
  }
41355
+ function deriveQualifyingPositions({ drawSize, qualifyingRoundNumber }) {
41356
+ let qualifyingPositions = drawSize;
41357
+ let divisionsCount = 0;
41358
+ while (divisionsCount < qualifyingRoundNumber) {
41359
+ qualifyingPositions = Math.floor(qualifyingPositions / 2);
41360
+ divisionsCount += 1;
41361
+ }
41362
+ return qualifyingPositions;
41363
+ }
41357
41364
 
41358
41365
  function getPositionRangeMap({
41359
41366
  playoffGroups,
@@ -56503,11 +56510,12 @@ function replaceTieMatchUpParticipantId(params) {
56503
56510
  }
56504
56511
  if (substitution || side.substitutions?.length === 1) {
56505
56512
  if (substitution) {
56506
- const processCodes = tieMatchUp?.processCodes ?? [];
56507
- if (substitutionProcessCodes)
56508
- processCodes.push(...substitutionProcessCodes);
56509
- if (tieMatchUp)
56510
- tieMatchUp.processCodes = processCodes;
56513
+ if (substitutionProcessCodes && tieMatchUp) {
56514
+ tieMatchUp.processCodes = unique([
56515
+ ...tieMatchUp?.processCodes ?? [],
56516
+ ...substitutionProcessCodes
56517
+ ]);
56518
+ }
56511
56519
  } else {
56512
56520
  for (const substitutionProcessCode of substitutionProcessCodes || []) {
56513
56521
  const codeIndex = tieMatchUp?.processCodes?.lastIndexOf(
@@ -61661,6 +61669,7 @@ const tournamentEngine = (() => {
61661
61669
  function executionQueue(directives, rollbackOnError) {
61662
61670
  if (!Array.isArray(directives))
61663
61671
  return { error: INVALID_VALUES };
61672
+ const start = Date.now();
61664
61673
  const tournamentId = getTournamentId();
61665
61674
  const tournamentRecord = getTournamentRecord(tournamentId);
61666
61675
  const snapshot = rollbackOnError && makeDeepCopy(tournamentRecord, false, true);
@@ -61671,10 +61680,8 @@ const tournamentEngine = (() => {
61671
61680
  const { method: methodName, params } = directive;
61672
61681
  if (!engine[methodName]) {
61673
61682
  const result3 = { error: METHOD_NOT_FOUND, methodName };
61674
- const devContext = getDevContext();
61675
- if (devContext.result && !Array.isArray(devContext.result) || Array.isArray(devContext.result) && devContext.result?.includes(methodName)) {
61676
- console.log("te:", result3);
61677
- }
61683
+ const elapsed = Date.now() - start;
61684
+ engineLogging({ result: result3, methodName, elapsed, params, engine: "te:" });
61678
61685
  return result3;
61679
61686
  }
61680
61687
  const result2 = executeFunction(