Skip to main content

getTally

getTally({ positionAssignment }) is a mode-agnostic reader for the round-robin tally stored on a PositionAssignment. Callers should never branch on schemaWriteMode — use this helper.

import { getTally } from 'tods-competition-factory';

const { tally } = getTally({ positionAssignment });
// works in both native (5.0.0 default) and legacy modes

Why it exists

CODES Phase 1 promoted the round-robin tally and subOrder to first-class attributes on PositionAssignment. Old code reads findExtension({element: positionAssignment, name: 'tally'}); new code reads positionAssignment.tally directly.

If consumers branched on the mode flag, every site would have to know whether the record was written by a native-mode or legacy-mode engine. getTally removes the branch — it tries the first-class location, falls back to the extension envelope, and returns whichever is present.

Where the value lives by mode

ModeRead path
native (5.0.0 default)positionAssignment.tally
legacy (4.x default; opt-in for v5 consumers)positionAssignment.extensions[{name: 'tally'}].value
dual (interim)Both locations carry the same value — getTally reads the first-class one

Under the hood the helper is a thin wrapper around firstClassOrExtension({ element, attribute: 'tally', name: TALLY }).

Errors

type GetTallyArgs = { positionAssignment?: any };
error.codeWhen
MISSING_POSITION_ASSIGNMENTSpositionAssignment argument was missing
NOT_FOUNDNeither positionAssignment.tally nor the legacy extension carried a value

Errors come back as the legacy { error: { code } } envelope; wrap with unwrap() if you want them as typed exceptions.

See also