Skip to content

Helpers

This page summarizes the helper utilities exported by the manager library and the convenient Get and Find APIs to retrieve information from the database.

Get APIs

Use manager.get methods to retrieve data that is commonly needed by UIs or automation scripts.

Helper utilities (exported)

A non‑exhaustive list of helpers exposed for advanced flows:

  • Round/Match status and utilities: getMatchStatus, isMatchOngoing, isMatchCompleted, isMatchUpdateLocked, hasBye, getWinner, getLoser, getNextSide, getOtherSide, getNextSideLoserBracket, etc.
  • Array helpers: splitBy, splitByParity, makePairs, setArraySize, uniqueBy, getNonNull.
  • Round‑robin: makeRoundRobinDistribution, makeRoundRobinMatches, assertRoundRobin.
  • Seeding: balanceByes, convertMatchesToSeeding, sortSeeding, mapParticipants* utilities.
  • Lower‑bracket math: isMajorRound, isMinorRound, getUpperBracketRoundCount, getLowerBracketRoundCount, getRoundPairCount, findLoserMatchNumber, etc.

Finding the “current” entities

Common flow to get the current stage and round:

const currentStage = await manager.get.currentStage(tournamentId);
if (!currentStage) {
  // Tournament completed
}

const currentRound = await manager.get.currentRound(currentStage.id);

You can combine this with helpers.isRoundCompleted(roundMatches) to know if a round is completed.

Getting all matches for the next round

To schedule upcoming games, fetch the next round by number and its matches:

// Given a current round, load the next round and its matches
const nextRound = await storage.selectFirst('round', {
  stage_id: currentRound.stage_id,
  number: currentRound.number + 1,
});

if (nextRound) {
  const nextMatches = await storage.select('match', { round_id: nextRound.id });
  // nextMatches contains every match to prepare for the next round
}

Notes:

  • The final of single elimination and the grand final of double elimination are in dedicated groups; make sure you filter by the proper group_id if needed.
  • For parallelization concerns (e.g., only ready matches), combine with helpers.isMatchOngoing(match) or helpers.getMatchStatus(match).