@pokertools/types 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 PokerTools
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # @pokertools/types
2
+
3
+ Pure TypeScript type definitions for poker game engine. This package contains zero runtime code - only type definitions.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @pokertools/types
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import {
15
+ Action,
16
+ GameState,
17
+ Player,
18
+ Pot,
19
+ ActionType,
20
+ PlayerStatus,
21
+ Street,
22
+ } from "@pokertools/types";
23
+
24
+ // Use types in your application
25
+ const player: Player = {
26
+ id: "player1",
27
+ name: "Alice",
28
+ seat: 0,
29
+ stack: 1000,
30
+ hand: null,
31
+ shownCards: null, // New: tracks which cards are visible at showdown
32
+ status: PlayerStatus.WAITING,
33
+ betThisStreet: 0,
34
+ totalInvestedThisHand: 0,
35
+ isSittingOut: false,
36
+ timeBank: 30,
37
+ };
38
+
39
+ const action: Action = {
40
+ type: ActionType.RAISE,
41
+ playerId: "player1",
42
+ amount: 100,
43
+ timestamp: Date.now(),
44
+ };
45
+ ```
46
+
47
+ ## Type Exports
48
+
49
+ ### Core Types
50
+
51
+ - `Action` - Player actions (fold, check, call, bet, raise, etc.)
52
+ - `GameState` - Complete game state
53
+ - `Player` - Player information
54
+ - `Pot` - Pot information (main and side pots)
55
+ - `Config` - Game configuration
56
+ - `PublicState` - Masked state for public view
57
+ - `HandHistory` - Hand history information
58
+
59
+ ### Enums
60
+
61
+ - `ActionType` - All possible action types
62
+ - `PlayerStatus` - Player statuses (active, folded, all-in, etc.)
63
+ - `Street` - Betting rounds (preflop, flop, turn, river, showdown)
64
+
65
+ ### Interfaces
66
+
67
+ All types are readonly and immutable by design.
68
+
69
+ ## Philosophy
70
+
71
+ This package follows these principles:
72
+
73
+ 1. **Pure Types Only** - No runtime code, no validation, no logic
74
+ 2. **Immutable by Design** - All fields are readonly
75
+ 3. **Zero Dependencies** - Lightweight for frontend use
76
+ 4. **Single Source of Truth** - Used by engine, API, and SDK
77
+
78
+ ## Related Packages
79
+
80
+ - `@pokertools/engine` - Game engine (depends on this package)
81
+ - `@pokertools/api` - REST/WebSocket API (depends on this package)
82
+ - `@pokertools/sdk` - Frontend SDK (depends on this package)
83
+
84
+ ## License
85
+
86
+ MIT
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Action types that can be performed in the game
3
+ */
4
+ export declare const enum ActionType {
5
+ SIT = "SIT",
6
+ STAND = "STAND",
7
+ DEAL = "DEAL",
8
+ FOLD = "FOLD",
9
+ CHECK = "CHECK",
10
+ CALL = "CALL",
11
+ BET = "BET",
12
+ RAISE = "RAISE",
13
+ SHOW = "SHOW",
14
+ MUCK = "MUCK",
15
+ TIMEOUT = "TIMEOUT",
16
+ TIME_BANK = "TIME_BANK",
17
+ UNCALLED_BET_RETURNED = "UNCALLED_BET_RETURNED",
18
+ NEXT_BLIND_LEVEL = "NEXT_BLIND_LEVEL"
19
+ }
20
+ /**
21
+ * Base interface for all actions
22
+ */
23
+ export interface BaseAction {
24
+ readonly type: ActionType;
25
+ readonly timestamp?: number;
26
+ }
27
+ /**
28
+ * Sit at table
29
+ */
30
+ export interface SitAction extends BaseAction {
31
+ readonly type: ActionType.SIT;
32
+ readonly playerId: string;
33
+ readonly playerName: string;
34
+ readonly seat: number;
35
+ readonly stack: number;
36
+ }
37
+ /**
38
+ * Stand from table
39
+ */
40
+ export interface StandAction extends BaseAction {
41
+ readonly type: ActionType.STAND;
42
+ readonly playerId: string;
43
+ }
44
+ /**
45
+ * Deal new hand
46
+ */
47
+ export interface DealAction extends BaseAction {
48
+ readonly type: ActionType.DEAL;
49
+ }
50
+ /**
51
+ * Fold hand
52
+ */
53
+ export interface FoldAction extends BaseAction {
54
+ readonly type: ActionType.FOLD;
55
+ readonly playerId: string;
56
+ }
57
+ /**
58
+ * Check (no bet to call)
59
+ */
60
+ export interface CheckAction extends BaseAction {
61
+ readonly type: ActionType.CHECK;
62
+ readonly playerId: string;
63
+ }
64
+ /**
65
+ * Call current bet
66
+ */
67
+ export interface CallAction extends BaseAction {
68
+ readonly type: ActionType.CALL;
69
+ readonly playerId: string;
70
+ }
71
+ /**
72
+ * Bet (opening bet)
73
+ */
74
+ export interface BetAction extends BaseAction {
75
+ readonly type: ActionType.BET;
76
+ readonly playerId: string;
77
+ readonly amount: number;
78
+ }
79
+ /**
80
+ * Raise existing bet
81
+ */
82
+ export interface RaiseAction extends BaseAction {
83
+ readonly type: ActionType.RAISE;
84
+ readonly playerId: string;
85
+ readonly amount: number;
86
+ }
87
+ /**
88
+ * Show cards at showdown
89
+ */
90
+ export interface ShowAction extends BaseAction {
91
+ readonly type: ActionType.SHOW;
92
+ readonly playerId: string;
93
+ readonly cardIndices?: readonly number[];
94
+ }
95
+ /**
96
+ * Muck cards at showdown (hide cards)
97
+ */
98
+ export interface MuckAction extends BaseAction {
99
+ readonly type: ActionType.MUCK;
100
+ readonly playerId: string;
101
+ }
102
+ /**
103
+ * Player timeout
104
+ */
105
+ export interface TimeoutAction extends BaseAction {
106
+ readonly type: ActionType.TIMEOUT;
107
+ readonly playerId: string;
108
+ }
109
+ /**
110
+ * Activate time bank
111
+ */
112
+ export interface TimeBankAction extends BaseAction {
113
+ readonly type: ActionType.TIME_BANK;
114
+ readonly playerId: string;
115
+ }
116
+ /**
117
+ * Uncalled bet returned to player
118
+ */
119
+ export interface UncalledBetReturnedAction extends BaseAction {
120
+ readonly type: ActionType.UNCALLED_BET_RETURNED;
121
+ readonly playerId: string;
122
+ readonly amount: number;
123
+ }
124
+ /**
125
+ * Advance blind level (tournament)
126
+ */
127
+ export interface NextBlindLevelAction extends BaseAction {
128
+ readonly type: ActionType.NEXT_BLIND_LEVEL;
129
+ }
130
+ /**
131
+ * Union type of all possible actions
132
+ */
133
+ export type Action = SitAction | StandAction | DealAction | FoldAction | CheckAction | CallAction | BetAction | RaiseAction | ShowAction | MuckAction | TimeoutAction | TimeBankAction | UncalledBetReturnedAction | NextBlindLevelAction;
134
+ /**
135
+ * Action record for history tracking
136
+ */
137
+ export interface ActionRecord {
138
+ readonly action: Action;
139
+ readonly seat: number | null;
140
+ readonly resultingPot: number;
141
+ readonly resultingStack: number;
142
+ readonly street?: string;
143
+ }
package/dist/Action.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ActionType = void 0;
4
+ /**
5
+ * Action types that can be performed in the game
6
+ */
7
+ var ActionType;
8
+ (function (ActionType) {
9
+ // Management
10
+ ActionType["SIT"] = "SIT";
11
+ ActionType["STAND"] = "STAND";
12
+ // Dealing
13
+ ActionType["DEAL"] = "DEAL";
14
+ // Betting
15
+ ActionType["FOLD"] = "FOLD";
16
+ ActionType["CHECK"] = "CHECK";
17
+ ActionType["CALL"] = "CALL";
18
+ ActionType["BET"] = "BET";
19
+ ActionType["RAISE"] = "RAISE";
20
+ // Showdown
21
+ ActionType["SHOW"] = "SHOW";
22
+ ActionType["MUCK"] = "MUCK";
23
+ // Special
24
+ ActionType["TIMEOUT"] = "TIMEOUT";
25
+ ActionType["TIME_BANK"] = "TIME_BANK";
26
+ ActionType["UNCALLED_BET_RETURNED"] = "UNCALLED_BET_RETURNED";
27
+ // Tournament
28
+ ActionType["NEXT_BLIND_LEVEL"] = "NEXT_BLIND_LEVEL";
29
+ })(ActionType || (exports.ActionType = ActionType = {}));
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Blind level for tournament play
3
+ */
4
+ export interface BlindLevel {
5
+ readonly smallBlind: number;
6
+ readonly bigBlind: number;
7
+ readonly ante: number;
8
+ }
9
+ /**
10
+ * Table configuration
11
+ */
12
+ export interface TableConfig {
13
+ readonly smallBlind: number;
14
+ readonly bigBlind: number;
15
+ readonly ante?: number;
16
+ readonly maxPlayers?: number;
17
+ readonly initialStack?: number;
18
+ readonly blindStructure?: readonly BlindLevel[];
19
+ readonly timeBankSeconds?: number;
20
+ readonly timeBankDeductionSeconds?: number;
21
+ readonly randomProvider?: () => number;
22
+ readonly rakePercent?: number;
23
+ readonly rakeCap?: number;
24
+ readonly noFlopNoDrop?: boolean;
25
+ readonly validateIntegrity?: boolean;
26
+ }
package/dist/Config.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,54 @@
1
+ import { Player } from "./Player";
2
+ import { Pot } from "./Pot";
3
+ import { TableConfig } from "./Config";
4
+ import { ActionRecord } from "./Action";
5
+ /**
6
+ * Street in the hand
7
+ */
8
+ export declare const enum Street {
9
+ PREFLOP = "PREFLOP",
10
+ FLOP = "FLOP",
11
+ TURN = "TURN",
12
+ RIVER = "RIVER",
13
+ SHOWDOWN = "SHOWDOWN"
14
+ }
15
+ /**
16
+ * Winner of a pot
17
+ */
18
+ export interface Winner {
19
+ readonly seat: number;
20
+ readonly amount: number;
21
+ readonly hand: readonly string[] | null;
22
+ readonly handRank: string | null;
23
+ }
24
+ /**
25
+ * Central immutable game state
26
+ */
27
+ export interface GameState {
28
+ readonly config: TableConfig;
29
+ readonly players: ReadonlyArray<Player | null>;
30
+ readonly maxPlayers: number;
31
+ readonly handNumber: number;
32
+ readonly buttonSeat: number | null;
33
+ readonly deck: readonly number[];
34
+ readonly board: readonly string[];
35
+ readonly street: Street;
36
+ readonly pots: readonly Pot[];
37
+ readonly currentBets: ReadonlyMap<number, number>;
38
+ readonly minRaise: number;
39
+ readonly lastRaiseAmount: number;
40
+ readonly actionTo: number | null;
41
+ readonly lastAggressorSeat: number | null;
42
+ readonly activePlayers: readonly number[];
43
+ readonly winners: readonly Winner[] | null;
44
+ readonly rakeThisHand: number;
45
+ readonly smallBlind: number;
46
+ readonly bigBlind: number;
47
+ readonly ante: number;
48
+ readonly blindLevel: number;
49
+ readonly timeBanks: ReadonlyMap<number, number>;
50
+ readonly actionHistory: readonly ActionRecord[];
51
+ readonly previousStates: readonly GameState[];
52
+ readonly timestamp: number;
53
+ readonly handId: string;
54
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Street = void 0;
4
+ /**
5
+ * Street in the hand
6
+ */
7
+ var Street;
8
+ (function (Street) {
9
+ Street["PREFLOP"] = "PREFLOP";
10
+ Street["FLOP"] = "FLOP";
11
+ Street["TURN"] = "TURN";
12
+ Street["RIVER"] = "RIVER";
13
+ Street["SHOWDOWN"] = "SHOWDOWN";
14
+ })(Street || (exports.Street = Street = {}));
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Hand history data for export
3
+ */
4
+ export interface HandHistoryData {
5
+ readonly handId: string;
6
+ readonly timestamp: number;
7
+ readonly tableName: string;
8
+ readonly buttonSeat: number;
9
+ readonly smallBlind: number;
10
+ readonly bigBlind: number;
11
+ readonly ante: number;
12
+ readonly players: ReadonlyArray<{
13
+ readonly seat: number;
14
+ readonly name: string;
15
+ readonly startingStack: number;
16
+ readonly hand: readonly string[] | null;
17
+ }>;
18
+ readonly board: readonly string[];
19
+ readonly actions: readonly string[];
20
+ readonly winners: ReadonlyArray<{
21
+ readonly seat: number;
22
+ readonly amount: number;
23
+ readonly hand: readonly string[] | null;
24
+ }>;
25
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Player status within a hand
3
+ */
4
+ export declare const enum PlayerStatus {
5
+ ACTIVE = "ACTIVE",// In hand, can act
6
+ FOLDED = "FOLDED",// Folded this hand
7
+ ALL_IN = "ALL_IN",// No more chips to bet
8
+ SITTING_OUT = "SITTING_OUT",// Not playing
9
+ WAITING = "WAITING",// At table but not in hand yet
10
+ BUSTED = "BUSTED"
11
+ }
12
+ /**
13
+ * Represents a player seated at the table
14
+ */
15
+ export interface Player {
16
+ readonly id: string;
17
+ readonly name: string;
18
+ readonly seat: number;
19
+ readonly stack: number;
20
+ readonly hand: readonly string[] | null;
21
+ readonly shownCards: readonly number[] | null;
22
+ readonly status: PlayerStatus;
23
+ readonly betThisStreet: number;
24
+ readonly totalInvestedThisHand: number;
25
+ readonly isSittingOut: boolean;
26
+ readonly timeBank: number;
27
+ }
package/dist/Player.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlayerStatus = void 0;
4
+ /**
5
+ * Player status within a hand
6
+ */
7
+ var PlayerStatus;
8
+ (function (PlayerStatus) {
9
+ PlayerStatus["ACTIVE"] = "ACTIVE";
10
+ PlayerStatus["FOLDED"] = "FOLDED";
11
+ PlayerStatus["ALL_IN"] = "ALL_IN";
12
+ PlayerStatus["SITTING_OUT"] = "SITTING_OUT";
13
+ PlayerStatus["WAITING"] = "WAITING";
14
+ PlayerStatus["BUSTED"] = "BUSTED";
15
+ })(PlayerStatus || (exports.PlayerStatus = PlayerStatus = {}));
package/dist/Pot.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Pot type (main pot or side pot)
3
+ */
4
+ export type PotType = "MAIN" | "SIDE";
5
+ /**
6
+ * Represents a pot (main or side) in the game
7
+ */
8
+ export interface Pot {
9
+ readonly amount: number;
10
+ readonly eligibleSeats: readonly number[];
11
+ readonly type: PotType;
12
+ readonly capPerPlayer: number;
13
+ }
package/dist/Pot.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,23 @@
1
+ import { GameState } from "./GameState";
2
+ import { Player } from "./Player";
3
+ /**
4
+ * Public player with potentially masked cards
5
+ * In public views, hand can have null elements to preserve positional context
6
+ * Examples:
7
+ * - ["As", "Kd"] - both cards visible
8
+ * - [null, "Kd"] - only right card visible
9
+ * - ["As", null] - only left card visible
10
+ * - null - all cards hidden (mucked or pre-showdown)
11
+ */
12
+ export interface PublicPlayer extends Omit<Player, "hand"> {
13
+ readonly hand: ReadonlyArray<string | null> | null;
14
+ }
15
+ /**
16
+ * Public view of game state with hidden information masked
17
+ * Used to send to clients to prevent cheating
18
+ */
19
+ export interface PublicState extends Omit<GameState, "deck" | "players"> {
20
+ readonly deck: readonly number[];
21
+ readonly players: ReadonlyArray<PublicPlayer | null>;
22
+ readonly viewingPlayerId: string | null;
23
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export * from "./Player";
2
+ export * from "./Pot";
3
+ export * from "./Config";
4
+ export * from "./Action";
5
+ export * from "./GameState";
6
+ export * from "./PublicState";
7
+ export * from "./HandHistory";
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Export all types
18
+ __exportStar(require("./Player"), exports);
19
+ __exportStar(require("./Pot"), exports);
20
+ __exportStar(require("./Config"), exports);
21
+ __exportStar(require("./Action"), exports);
22
+ __exportStar(require("./GameState"), exports);
23
+ __exportStar(require("./PublicState"), exports);
24
+ __exportStar(require("./HandHistory"), exports);
@@ -0,0 +1 @@
1
+ {"root":["../src/Action.ts","../src/Config.ts","../src/GameState.ts","../src/HandHistory.ts","../src/Player.ts","../src/Pot.ts","../src/PublicState.ts","../src/index.ts"],"version":"5.9.3"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@pokertools/types",
3
+ "version": "1.0.0",
4
+ "description": "TypeScript type definitions for poker game engine",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "require": "./dist/index.js",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "clean": "rm -rf dist",
23
+ "test": "echo \"No tests for types package (types only)\" && exit 0"
24
+ },
25
+ "keywords": [
26
+ "poker",
27
+ "types",
28
+ "typescript",
29
+ "texas-holdem"
30
+ ],
31
+ "author": "A.Aurelius",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/aaurelions/pokertools.git",
36
+ "directory": "packages/types"
37
+ },
38
+ "homepage": "https://github.com/aaurelions/pokertools/tree/main/packages/types#readme",
39
+ "bugs": {
40
+ "url": "https://github.com/aaurelions/pokertools/issues"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "devDependencies": {
46
+ "typescript": "^5.9.3"
47
+ }
48
+ }