Bridge Core
Validation
Deal validation with structured error reporting.
Import from @workspace/bridge-core/validation.
validateDeal
Validates a deal based on pre-calculated input. Returns a structured result with error codes suitable for translation.
import { validateDeal } from '@workspace/bridge-core/validation';
const result = validateDeal({
handsComplete: true,
incompletePlayers: [],
duplicatedCards: [],
contractCandidate: { level: 3, suit: 'NT', declarer: 'S', doubled: 'none' },
declarer: 'S',
areAuctionsEnabled: true,
});
result.isValid; // true
result.errors; // []Validation Rules
| Error Code | When Checked | Condition |
|---|---|---|
HANDS_INCOMPLETE | Always | One or more hands do not have the correct number of cards |
DUPLICATE_CARDS | Always | A card appears in more than one hand |
CONTRACT_MISSING | Auctions enabled | No contract candidate exists |
DECLARER_NOT_SOUTH | Auctions enabled | The declarer is not South |
Error Example
const result = validateDeal({
handsComplete: false,
incompletePlayers: ['N', 'E'],
duplicatedCards: ['SA'],
contractCandidate: null,
declarer: null,
areAuctionsEnabled: true,
});
result.isValid; // false
result.errors;
// [
// { code: 'HANDS_INCOMPLETE', params: { players: 'N, E' } },
// { code: 'DUPLICATE_CARDS', params: { cards: 'SA' } },
// { code: 'CONTRACT_MISSING' },
// ]Types
Prop
Type
Prop
Type
Prop
Type