Bridge Training
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 CodeWhen CheckedCondition
HANDS_INCOMPLETEAlwaysOne or more hands do not have the correct number of cards
DUPLICATE_CARDSAlwaysA card appears in more than one hand
CONTRACT_MISSINGAuctions enabledNo contract candidate exists
DECLARER_NOT_SOUTHAuctions enabledThe 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

On this page