Bridge Training
Bridge Core

Schemas

Zod validation schemas for bids, cards, players, hands, auction state, play state, vulnerability, scoring, and game parameters.

Schemas use wildcard exports -- import each schema file individually.

import { bidSchema } from '@workspace/bridge-core/schemas/bid';
import { cardSchema } from '@workspace/bridge-core/schemas/card';
import { playerSchema } from '@workspace/bridge-core/schemas/player';

All schemas are built with Zod and export inferred TypeScript types alongside the schema objects.

Card Schemas

import { suitSchema, rankSchema, cardSchema } from '@workspace/bridge-core/schemas/card';

suitSchema.parse('S');     // 'S'
rankSchema.parse('A');     // 'A'
cardSchema.parse('SA');    // 'SA' (Ace of Spades)
cardSchema.parse('ZZ');    // throws ZodError
SchemaValidatesExample
suitSchema'S' | 'H' | 'D' | 'C''H'
rankSchema'A' | 'K' | ... | '2''K'
cardSchemaSuit + Rank string (regex)'SA', 'HK'

Player Schemas

import { playerSchema, partnershipSchema } from '@workspace/bridge-core/schemas/player';

playerSchema.parse('N');       // 'N'
partnershipSchema.parse('NS'); // 'NS'
SchemaValidatesExample
playerSchema'N' | 'E' | 'S' | 'W''N'
partnershipSchema'NS' | 'EW''EW'

Bid Schemas

import {
  bidSchema,
  regularBidSchema,
  specialBidSchema,
  bidLevelSchema,
  bidSuitSchema,
  counterStatusSchema,
  contractSchema,
} from '@workspace/bridge-core/schemas/bid';

bidSchema.parse('3NT');         // '3NT'
bidSchema.parse('Pass');        // 'Pass'
regularBidSchema.parse('4S');   // '4S'
specialBidSchema.parse('X');    // 'X'
bidLevelSchema.parse(7);        // 7
bidSuitSchema.parse('NT');      // 'NT'
counterStatusSchema.parse('X'); // 'X'
SchemaValidates
bidSchemaAny valid bid (regular or special)
regularBidSchemaLevel + suit bids ('1C' through '7NT')
specialBidSchema'Pass' | 'X' | 'XX' | 'Alert'
bidLevelSchema1 | 2 | 3 | 4 | 5 | 6 | 7
bidSuitSchema'C' | 'D' | 'H' | 'S' | 'NT'
counterStatusSchema'none' | 'X' | 'XX'
contractSchemaObject with level, suit, declarer, doubled
regularBidCompositeSchemaDetailed regular bid with player, index
specialBidCompositeSchemaDetailed special bid with player, index
bidCompositeSchemaUnion of regular and special composite schemas

Hands Schemas

import { handSchema, handsSchema, handDataSchema, handsDataSchema } from '@workspace/bridge-core/schemas/hands';

// Strict: validates card format (e.g. 'SA', 'HK')
handsSchema.parse({
  N: { S: ['SA'], H: ['HK'], D: [], C: [] },
  E: { S: [], H: [], D: ['DA'], C: [] },
  S: { S: [], H: [], D: [], C: ['CA'] },
  W: { S: [], H: [], D: [], C: [] },
});

// Generic: accepts any string as a card value
handsDataSchema.parse({ N: { S: ['A'], H: [], D: [], C: [] } });
SchemaValidates
handSchemaSingle hand: { S: Card[], H: Card[], D: Card[], C: Card[] }
handsSchemaAll four hands with strict card validation
handDataSchemaSingle hand with loose string arrays
handsDataSchemaAll four hands with loose string arrays

Auction State Schema

import { auctionStateSchema, bidInfoSchema } from '@workspace/bridge-core/schemas/auction';

auctionStateSchema.parse({
  dealer: 'N',
  sequence: [{ bid: '1H', player: 'N', position: 0 }],
  lastBid: '1H',
});
SchemaValidates
bidInfoSchema{ bid, player, position, comment?, isAlerted? }
auctionStateSchema{ dealer, sequence, lastBid }

Play State Schema

import { playStateSchema, trickSchema, playEntrySchema } from '@workspace/bridge-core/schemas/play';

playStateSchema.parse({
  tricks: [{ lead: 'W', cards: [{ card: 'SA', player: 'W' }], winner: null }],
  currentTrick: [],
});
SchemaValidates
playEntrySchema{ card, player }
trickSchema{ lead, cards, winner? }
playStateSchema{ tricks, currentTrick }

Vulnerability & Scoring Schemas

import { vulnerabilitySchema } from '@workspace/bridge-core/schemas/vulnerability';
import { scoringModeSchema } from '@workspace/bridge-core/schemas/scoring';

vulnerabilitySchema.parse('NS');    // 'NS'
vulnerabilitySchema.parse('UNSET'); // 'UNSET'
scoringModeSchema.parse('IMP');     // 'IMP'
SchemaValidates
vulnerabilitySchema'NONE' | 'NS' | 'EW' | 'ALL' | 'UNSET'
scoringModeSchema'UNSET' | 'TPP' | 'IMP'

Game & Teaching Parameters

import { gameParamsSchema } from '@workspace/bridge-core/schemas/game-params';
import { teachParamsSchema, auctionModeSchema } from '@workspace/bridge-core/schemas/teach-params';

gameParamsSchema.parse({});
// { vulnerability: 'UNSET', scoringMode: 'UNSET', resultExpected: null }

teachParamsSchema.parse({});
// { auctionMode: 'auction', teachDummy: true }
SchemaValidates
gameParamsSchema{ vulnerability, scoringMode, resultExpected } with defaults
teachParamsSchema{ auctionMode, teachDummy } with defaults
auctionModeSchemaValid teaching/auction mode string

On this page