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.
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
| Schema | Validates | Example |
|---|
suitSchema | 'S' | 'H' | 'D' | 'C' | 'H' |
rankSchema | 'A' | 'K' | ... | '2' | 'K' |
cardSchema | Suit + Rank string (regex) | 'SA', 'HK' |
import { playerSchema, partnershipSchema } from '@workspace/bridge-core/schemas/player';
playerSchema.parse('N'); // 'N'
partnershipSchema.parse('NS'); // 'NS'
| Schema | Validates | Example |
|---|
playerSchema | 'N' | 'E' | 'S' | 'W' | 'N' |
partnershipSchema | 'NS' | 'EW' | 'EW' |
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'
| Schema | Validates |
|---|
bidSchema | Any valid bid (regular or special) |
regularBidSchema | Level + suit bids ('1C' through '7NT') |
specialBidSchema | 'Pass' | 'X' | 'XX' | 'Alert' |
bidLevelSchema | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
bidSuitSchema | 'C' | 'D' | 'H' | 'S' | 'NT' |
counterStatusSchema | 'none' | 'X' | 'XX' |
contractSchema | Object with level, suit, declarer, doubled |
regularBidCompositeSchema | Detailed regular bid with player, index |
specialBidCompositeSchema | Detailed special bid with player, index |
bidCompositeSchema | Union of regular and special composite 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: [] } });
| Schema | Validates |
|---|
handSchema | Single hand: { S: Card[], H: Card[], D: Card[], C: Card[] } |
handsSchema | All four hands with strict card validation |
handDataSchema | Single hand with loose string arrays |
handsDataSchema | All four hands with loose string arrays |
import { auctionStateSchema, bidInfoSchema } from '@workspace/bridge-core/schemas/auction';
auctionStateSchema.parse({
dealer: 'N',
sequence: [{ bid: '1H', player: 'N', position: 0 }],
lastBid: '1H',
});
| Schema | Validates |
|---|
bidInfoSchema | { bid, player, position, comment?, isAlerted? } |
auctionStateSchema | { dealer, sequence, lastBid } |
import { playStateSchema, trickSchema, playEntrySchema } from '@workspace/bridge-core/schemas/play';
playStateSchema.parse({
tricks: [{ lead: 'W', cards: [{ card: 'SA', player: 'W' }], winner: null }],
currentTrick: [],
});
| Schema | Validates |
|---|
playEntrySchema | { card, player } |
trickSchema | { lead, cards, winner? } |
playStateSchema | { tricks, currentTrick } |
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'
| Schema | Validates |
|---|
vulnerabilitySchema | 'NONE' | 'NS' | 'EW' | 'ALL' | 'UNSET' |
scoringModeSchema | 'UNSET' | 'TPP' | 'IMP' |
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 }
| Schema | Validates |
|---|
gameParamsSchema | { vulnerability, scoringMode, resultExpected } with defaults |
teachParamsSchema | { auctionMode, teachDummy } with defaults |
auctionModeSchema | Valid teaching/auction mode string |