tods-competition-factory 1.6.29 → 1.7.0

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
@@ -329,7 +329,7 @@ const matchUpFormatCode = {
329
329
  };
330
330
 
331
331
  function factoryVersion() {
332
- return "1.6.29";
332
+ return "1.7.0";
333
333
  }
334
334
 
335
335
  function getObjectTieFormat(obj) {
@@ -1425,7 +1425,8 @@ var syncGlobalState$1 = {
1425
1425
  setSubscriptions: setSubscriptions$1,
1426
1426
  setTournamentId: setTournamentId$1,
1427
1427
  setTournamentRecord: setTournamentRecord$2,
1428
- setTournamentRecords: setTournamentRecords$1
1428
+ setTournamentRecords: setTournamentRecords$1,
1429
+ handleCaughtError: handleCaughtError$1
1429
1430
  };
1430
1431
  function disableNotifications$1() {
1431
1432
  syncGlobalState.disableNotifications = true;
@@ -1531,6 +1532,26 @@ function callListener$1({ topic, notices }) {
1531
1532
  method(notices);
1532
1533
  }
1533
1534
  }
1535
+ function handleCaughtError$1({
1536
+ engineName,
1537
+ methodName,
1538
+ params,
1539
+ err
1540
+ }) {
1541
+ let error;
1542
+ if (typeof err === "string") {
1543
+ error = err.toUpperCase();
1544
+ } else if (err instanceof Error) {
1545
+ error = err.message;
1546
+ }
1547
+ console.log("ERROR", {
1548
+ tournamentId: getTournamentId$1(),
1549
+ params: JSON.stringify(params),
1550
+ engine: engineName,
1551
+ methodName,
1552
+ error
1553
+ });
1554
+ }
1534
1555
 
1535
1556
  const globalState = {
1536
1557
  tournamentFactoryVersion: "0.0.0",
@@ -1550,6 +1571,8 @@ const requiredStateProviderMethods = [
1550
1571
  "cycleMutationStatus",
1551
1572
  "deleteNotice",
1552
1573
  "deleteNotices",
1574
+ "disableNotifications",
1575
+ "enableNotifications",
1553
1576
  "getNotices",
1554
1577
  "getTopics",
1555
1578
  "getTournamentId",
@@ -1649,8 +1672,8 @@ function cycleMutationStatus() {
1649
1672
  function addNotice(notice) {
1650
1673
  return _globalStateProvider.addNotice(notice);
1651
1674
  }
1652
- function getNotices(topic) {
1653
- return _globalStateProvider.getNotices(topic);
1675
+ function getNotices(params) {
1676
+ return _globalStateProvider.getNotices(params);
1654
1677
  }
1655
1678
  function deleteNotice({ key, topic }) {
1656
1679
  return _globalStateProvider.deleteNotice({ key, topic });
@@ -1685,6 +1708,20 @@ function setTournamentId(tournamentId) {
1685
1708
  function removeTournamentRecord(tournamentId) {
1686
1709
  return _globalStateProvider.removeTournamentRecord(tournamentId);
1687
1710
  }
1711
+ function handleCaughtError({
1712
+ engineName,
1713
+ methodName,
1714
+ params,
1715
+ err
1716
+ }) {
1717
+ const caughtErrorHandler = typeof _globalStateProvider.handleCaughtError === "function" && _globalStateProvider.handleCaughtError || syncGlobalState$1.handleCaughtError;
1718
+ return caughtErrorHandler({
1719
+ engineName,
1720
+ methodName,
1721
+ params,
1722
+ err
1723
+ });
1724
+ }
1688
1725
 
1689
1726
  function isObject(obj) {
1690
1727
  return typeof obj === "object";
@@ -38377,18 +38414,11 @@ const competitionEngine = function() {
38377
38414
  try {
38378
38415
  return engineInvoke(governor[methodName], params, methodName);
38379
38416
  } catch (err) {
38380
- const activeTournamentId = getTournamentId();
38381
- let error;
38382
- if (typeof err === "string") {
38383
- error = err.toUpperCase();
38384
- } else if (err instanceof Error) {
38385
- error = err.message;
38386
- }
38387
- console.log("ERROR", {
38388
- params: JSON.stringify(params),
38389
- activeTournamentId,
38417
+ handleCaughtError({
38418
+ engineName: "competitionEngine",
38390
38419
  methodName,
38391
- error
38420
+ params,
38421
+ err
38392
38422
  });
38393
38423
  }
38394
38424
  }
@@ -38545,26 +38575,19 @@ function competitionEngineAsync(test) {
38545
38575
  async function importGovernors(governors) {
38546
38576
  for (const governor of governors) {
38547
38577
  const govKeys = Object.keys(governor);
38548
- for (const method of govKeys) {
38549
- engine[method] = async function(params) {
38578
+ for (const methodName of govKeys) {
38579
+ engine[methodName] = async function(params) {
38550
38580
  if (getDevContext()) {
38551
- return await engineInvoke(governor[method], params);
38581
+ return await engineInvoke(governor[methodName], params);
38552
38582
  } else {
38553
38583
  try {
38554
- return await engineInvoke(governor[method], params);
38584
+ return await engineInvoke(governor[methodName], params);
38555
38585
  } catch (err) {
38556
- const activeTournamentId = getTournamentId();
38557
- let error;
38558
- if (typeof err === "string") {
38559
- error = err.toUpperCase();
38560
- } else if (err instanceof Error) {
38561
- error = err.message;
38562
- }
38563
- console.log("ERROR", {
38564
- params: JSON.stringify(params),
38565
- activeTournamentId,
38566
- method,
38567
- error
38586
+ handleCaughtError({
38587
+ engineName: "competitionEngine",
38588
+ methodName,
38589
+ params,
38590
+ err
38568
38591
  });
38569
38592
  }
38570
38593
  }
@@ -40570,8 +40593,6 @@ function getGenerators(params) {
40570
40593
  function generateDrawStructuresAndLinks$1(params) {
40571
40594
  const {
40572
40595
  enforceMinimumDrawSize = true,
40573
- drawTypeCoercion = true,
40574
- // coerce to SINGLE_ELIMINATION for drawSize: 2
40575
40596
  overwriteExisting,
40576
40597
  appliedPolicies,
40577
40598
  staggeredEntry,
@@ -40582,6 +40603,7 @@ function generateDrawStructuresAndLinks$1(params) {
40582
40603
  isMock,
40583
40604
  uuids
40584
40605
  } = params || {};
40606
+ const drawTypeCoercion = params.drawTypeCoercion ?? appliedPolicies?.[POLICY_TYPE_DRAWS]?.drawTypeCoercion ?? true;
40585
40607
  const stack = "generateDrawStructuresAndLinks";
40586
40608
  let drawType = drawTypeCoercion && params.drawSize === 2 && DrawTypeEnum.SingleElimination || params.drawType || DrawTypeEnum.SingleElimination;
40587
40609
  const structures = [], links = [];
@@ -48690,25 +48712,19 @@ const drawEngine = function() {
48690
48712
  return engine;
48691
48713
  function importGovernors(governors) {
48692
48714
  governors.forEach((governor) => {
48693
- Object.keys(governor).forEach((governorMethod) => {
48694
- engine[governorMethod] = (params) => {
48715
+ Object.keys(governor).forEach((methodName) => {
48716
+ engine[methodName] = (params) => {
48695
48717
  if (getDevContext()) {
48696
- return invoke({ params, governor, governorMethod });
48718
+ return invoke({ params, governor, methodName });
48697
48719
  } else {
48698
48720
  try {
48699
- return invoke({ params, governor, governorMethod });
48721
+ return invoke({ params, governor, methodName });
48700
48722
  } catch (err) {
48701
- let error;
48702
- if (typeof err === "string") {
48703
- error = err.toUpperCase();
48704
- } else if (err instanceof Error) {
48705
- error = err.message;
48706
- }
48707
- console.log("ERROR", {
48708
- params: JSON.stringify(params),
48709
- drawId: drawDefinition$1?.drawId,
48710
- method: governorMethod,
48711
- error
48723
+ handleCaughtError({
48724
+ engineName: "drawEngine",
48725
+ methodName,
48726
+ params,
48727
+ err
48712
48728
  });
48713
48729
  }
48714
48730
  }
@@ -48716,7 +48732,7 @@ const drawEngine = function() {
48716
48732
  });
48717
48733
  });
48718
48734
  }
48719
- function invoke({ params, governor, governorMethod }) {
48735
+ function invoke({ params, governor, methodName }) {
48720
48736
  delete engine.success;
48721
48737
  delete engine.error;
48722
48738
  const snapshot = params?.rollbackOnError && makeDeepCopy(drawDefinition$1, false, true);
@@ -48727,7 +48743,7 @@ const drawEngine = function() {
48727
48743
  tournamentParticipants: tournamentParticipants$1,
48728
48744
  drawDefinition: drawDefinition$1
48729
48745
  };
48730
- const result = governor[governorMethod](params);
48746
+ const result = governor[methodName](params);
48731
48747
  if (result?.error) {
48732
48748
  if (snapshot)
48733
48749
  setState$3(snapshot);
@@ -48820,25 +48836,19 @@ function drawEngineAsync(test) {
48820
48836
  async function importGovernors(governors) {
48821
48837
  for (const governor of governors) {
48822
48838
  const governorMethods = Object.keys(governor);
48823
- for (const governorMethod of governorMethods) {
48824
- engine[governorMethod] = async (params) => {
48839
+ for (const methodName of governorMethods) {
48840
+ engine[methodName] = async (params) => {
48825
48841
  if (getDevContext()) {
48826
- return await invoke({ params, governor, governorMethod });
48842
+ return await invoke({ params, governor, methodName });
48827
48843
  } else {
48828
48844
  try {
48829
- return await invoke({ params, governor, governorMethod });
48845
+ return await invoke({ params, governor, methodName });
48830
48846
  } catch (err) {
48831
- let error;
48832
- if (typeof err === "string") {
48833
- error = err.toUpperCase();
48834
- } else if (err instanceof Error) {
48835
- error = err.message;
48836
- }
48837
- console.log("ERROR", {
48838
- params: JSON.stringify(params),
48839
- drawId: drawDefinition?.drawId,
48840
- method: governorMethod,
48841
- error
48847
+ handleCaughtError({
48848
+ engineName: "drawEngine",
48849
+ methodName,
48850
+ params,
48851
+ err
48842
48852
  });
48843
48853
  }
48844
48854
  }
@@ -48846,7 +48856,7 @@ function drawEngineAsync(test) {
48846
48856
  }
48847
48857
  }
48848
48858
  }
48849
- async function invoke({ params, governor, governorMethod }) {
48859
+ async function invoke({ params, governor, methodName }) {
48850
48860
  delete engine.success;
48851
48861
  delete engine.error;
48852
48862
  const snapshot = params?.rollbackOnError && makeDeepCopy(drawDefinition, false, true);
@@ -48857,7 +48867,7 @@ function drawEngineAsync(test) {
48857
48867
  tournamentParticipants,
48858
48868
  drawDefinition
48859
48869
  };
48860
- const result2 = governor[governorMethod](params);
48870
+ const result2 = governor[methodName](params);
48861
48871
  if (result2?.error) {
48862
48872
  if (snapshot)
48863
48873
  setState$3(snapshot);
@@ -49355,24 +49365,19 @@ const matchUpEngine = (() => {
49355
49365
  return engine;
49356
49366
  function importGovernors(governors) {
49357
49367
  governors.forEach((governor) => {
49358
- Object.keys(governor).forEach((governorMethod) => {
49359
- engine[governorMethod] = (params) => {
49368
+ Object.keys(governor).forEach((methodName) => {
49369
+ engine[methodName] = (params) => {
49360
49370
  if (getDevContext()) {
49361
- return invoke({ params, governor, governorMethod });
49371
+ return invoke({ params, governor, methodName });
49362
49372
  } else {
49363
49373
  try {
49364
- return invoke({ params, governor, governorMethod });
49374
+ return invoke({ params, governor, methodName });
49365
49375
  } catch (err) {
49366
- let error;
49367
- if (typeof err === "string") {
49368
- error = err.toUpperCase();
49369
- } else if (err instanceof Error) {
49370
- error = err.message;
49371
- }
49372
- console.log("ERROR", {
49373
- params: JSON.stringify(params),
49374
- method: governorMethod,
49375
- error
49376
+ handleCaughtError({
49377
+ engineName: "matchUpEngine",
49378
+ methodName,
49379
+ params,
49380
+ err
49376
49381
  });
49377
49382
  }
49378
49383
  }
@@ -49380,7 +49385,7 @@ const matchUpEngine = (() => {
49380
49385
  });
49381
49386
  });
49382
49387
  }
49383
- function invoke({ params, governor, governorMethod }) {
49388
+ function invoke({ params, governor, methodName }) {
49384
49389
  engine.error = void 0;
49385
49390
  engine.success = false;
49386
49391
  const matchUp = params?.matchUp || getMatchUp();
@@ -49392,7 +49397,7 @@ const matchUpEngine = (() => {
49392
49397
  matchUps,
49393
49398
  matchUp
49394
49399
  };
49395
- const result = governor[governorMethod](params);
49400
+ const result = governor[methodName](params);
49396
49401
  if (result?.error) {
49397
49402
  if (snapshot)
49398
49403
  setState$2(snapshot);
@@ -49452,24 +49457,19 @@ function matchUpEngineAsync(test) {
49452
49457
  async function importGovernors(governors) {
49453
49458
  for (const governor of governors) {
49454
49459
  const governorMethods = Object.keys(governor);
49455
- for (const governorMethod of governorMethods) {
49456
- engine[governorMethod] = async (params) => {
49460
+ for (const methodName of governorMethods) {
49461
+ engine[methodName] = async (params) => {
49457
49462
  if (getDevContext()) {
49458
- return await invoke({ params, governor, governorMethod });
49463
+ return await invoke({ params, governor, methodName });
49459
49464
  } else {
49460
49465
  try {
49461
- return await invoke({ params, governor, governorMethod });
49466
+ return await invoke({ params, governor, methodName });
49462
49467
  } catch (err) {
49463
- let error;
49464
- if (typeof err === "string") {
49465
- error = err.toUpperCase();
49466
- } else if (err instanceof Error) {
49467
- error = err.message;
49468
- }
49469
- console.log("ERROR", {
49470
- params: JSON.stringify(params),
49471
- method: governorMethod,
49472
- error
49468
+ handleCaughtError({
49469
+ engineName: "matchUpEngine",
49470
+ methodName,
49471
+ params,
49472
+ err
49473
49473
  });
49474
49474
  }
49475
49475
  }
@@ -49477,7 +49477,7 @@ function matchUpEngineAsync(test) {
49477
49477
  }
49478
49478
  }
49479
49479
  }
49480
- async function invoke({ params, governor, governorMethod }) {
49480
+ async function invoke({ params, governor, methodName }) {
49481
49481
  engine.success = false;
49482
49482
  engine.error = void 0;
49483
49483
  const matchUp = params?.matchUp || getMatchUp();
@@ -49489,7 +49489,7 @@ function matchUpEngineAsync(test) {
49489
49489
  matchUps,
49490
49490
  matchUp
49491
49491
  };
49492
- const result2 = governor[governorMethod](params);
49492
+ const result2 = governor[methodName](params);
49493
49493
  if (result2?.error) {
49494
49494
  if (snapshot)
49495
49495
  setState$2(snapshot);
@@ -54724,7 +54724,10 @@ function addEventEntryPairs({
54724
54724
  event
54725
54725
  });
54726
54726
  if (newParticipants.length) {
54727
- addNotice({ topic: ADD_PARTICIPANTS, participants: newParticipants });
54727
+ addNotice({
54728
+ payload: { participants: newParticipants },
54729
+ topic: ADD_PARTICIPANTS
54730
+ });
54728
54731
  }
54729
54732
  const newParticipantIds = newParticipants.map(getParticipantId);
54730
54733
  return { ...result, info, newParticipantIds };
@@ -57343,7 +57346,6 @@ function generateDrawDefinition(params) {
57343
57346
  const {
57344
57347
  considerEventEntries = true,
57345
57348
  // in the absence of drawSize and drawEntries, look to event.entries
57346
- drawTypeCoercion = true,
57347
57349
  ignoreAllowedDrawTypes,
57348
57350
  voluntaryConsolation,
57349
57351
  hydrateCollections,
@@ -57357,15 +57359,16 @@ function generateDrawDefinition(params) {
57357
57359
  placeByes,
57358
57360
  event
57359
57361
  } = params;
57362
+ const appliedPolicies = getAppliedPolicies({
57363
+ tournamentRecord,
57364
+ event
57365
+ }).appliedPolicies ?? {};
57366
+ const drawTypeCoercion = params.drawTypeCoercion ?? appliedPolicies?.[POLICY_TYPE_DRAWS]?.drawTypeCoercion ?? true;
57360
57367
  const drawType = drawTypeCoercion && params.drawSize === 2 && DrawTypeEnum.SingleElimination || params.drawType || DrawTypeEnum.SingleElimination;
57361
57368
  const { tournamentParticipants: participants } = getTournamentParticipants({
57362
57369
  tournamentRecord,
57363
57370
  inContext: true
57364
57371
  });
57365
- const appliedPolicies = getAppliedPolicies({
57366
- tournamentRecord,
57367
- event
57368
- }).appliedPolicies ?? {};
57369
57372
  const enforceGender = params.enforceGender ?? policyDefinitions?.[POLICY_TYPE_MATCHUP_ACTIONS]?.participants?.enforceGender ?? appliedPolicies?.[POLICY_TYPE_MATCHUP_ACTIONS]?.participants?.enforceGender;
57370
57373
  const allowedDrawTypes = !ignoreAllowedDrawTypes && tournamentRecord && getAllowedDrawTypes({
57371
57374
  tournamentRecord,
@@ -58744,17 +58747,11 @@ const tournamentEngine = (() => {
58744
58747
  try {
58745
58748
  return engineInvoke(governor[methodName], params, methodName);
58746
58749
  } catch (err) {
58747
- let error;
58748
- if (typeof err === "string") {
58749
- error = err.toUpperCase();
58750
- } else if (err instanceof Error) {
58751
- error = err.message;
58752
- }
58753
- console.log("ERROR", {
58754
- tournamentId: getTournamentId(),
58755
- params: JSON.stringify(params),
58750
+ handleCaughtError({
58751
+ engineName: "tournamentEngine",
58756
58752
  methodName,
58757
- error
58753
+ params,
58754
+ err
58758
58755
  });
58759
58756
  }
58760
58757
  }
@@ -58915,26 +58912,19 @@ function tournamentEngineAsync(test) {
58915
58912
  function importGovernors(governors) {
58916
58913
  for (const governor of governors) {
58917
58914
  const governorMethods = Object.keys(governor);
58918
- for (const method of governorMethods) {
58919
- engine[method] = async (params) => {
58915
+ for (const methodName of governorMethods) {
58916
+ engine[methodName] = async (params) => {
58920
58917
  if (getDevContext()) {
58921
- return await engineInvoke(governor[method], params);
58918
+ return await engineInvoke(governor[methodName], params);
58922
58919
  } else {
58923
58920
  try {
58924
- return await engineInvoke(governor[method], params);
58921
+ return await engineInvoke(governor[methodName], params);
58925
58922
  } catch (err) {
58926
- const tournamentId = getTournamentId();
58927
- let error;
58928
- if (typeof err === "string") {
58929
- error = err.toUpperCase();
58930
- } else if (err instanceof Error) {
58931
- error = err.message;
58932
- }
58933
- console.log("ERROR", {
58934
- params: JSON.stringify(params),
58935
- tournamentId,
58936
- method,
58937
- error
58923
+ handleCaughtError({
58924
+ engineName: "tournamentEngine",
58925
+ methodName,
58926
+ params,
58927
+ err
58938
58928
  });
58939
58929
  }
58940
58930
  }
@@ -59633,24 +59623,19 @@ const scaleEngine = (() => {
59633
59623
  }
59634
59624
  function importGovernors(governors) {
59635
59625
  governors.forEach((governor) => {
59636
- Object.keys(governor).forEach((method) => {
59637
- engine[method] = (params) => {
59626
+ Object.keys(governor).forEach((methodName) => {
59627
+ engine[methodName] = (params) => {
59638
59628
  if (getDevContext()) {
59639
- return engineInvoke(governor[method], params);
59629
+ return engineInvoke(governor[methodName], params);
59640
59630
  } else {
59641
59631
  try {
59642
- return engineInvoke(governor[method], params);
59632
+ return engineInvoke(governor[methodName], params);
59643
59633
  } catch (err) {
59644
- let error;
59645
- if (typeof err === "string") {
59646
- error = err.toUpperCase();
59647
- } else if (err instanceof Error) {
59648
- error = err.message;
59649
- }
59650
- console.log("ERROR", {
59651
- error,
59652
- method,
59653
- params: JSON.stringify(params)
59634
+ handleCaughtError({
59635
+ engineName: "scaleEngine",
59636
+ methodName,
59637
+ params,
59638
+ err
59654
59639
  });
59655
59640
  }
59656
59641
  }
@@ -59722,9 +59707,22 @@ function scaleEngineAsync(test) {
59722
59707
  function importGovernors(governors) {
59723
59708
  for (const governor of governors) {
59724
59709
  const governorMethods = Object.keys(governor);
59725
- for (const governorMethod of governorMethods) {
59726
- engine[governorMethod] = async (params) => {
59727
- return await engineInvoke(governor[governorMethod], params);
59710
+ for (const methodName of governorMethods) {
59711
+ engine[methodName] = async (params) => {
59712
+ if (getDevContext()) {
59713
+ return await engineInvoke(governor[methodName], params);
59714
+ } else {
59715
+ try {
59716
+ return await engineInvoke(governor[methodName], params);
59717
+ } catch (err) {
59718
+ handleCaughtError({
59719
+ engineName: "scaleEngine",
59720
+ methodName,
59721
+ params,
59722
+ err
59723
+ });
59724
+ }
59725
+ }
59728
59726
  };
59729
59727
  }
59730
59728
  }