@sportsbroker/firebase-structure 7.1.0 → 8.1.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.
@@ -17,9 +17,19 @@ export type ResultsData = EventResultsData;
17
17
 
18
18
  export enum GameEngineEnum {
19
19
  MATCH_PREDICTOR = "match-predictor",
20
- EDGE = "edge"
20
+ EDGE = "edge",
21
+ /** Golden Coin: an in-play table game, settled once at full time. Question-less. */
22
+ COIN_PASS = "coin-pass"
21
23
  }
22
24
 
25
+ /**
26
+ * The engines whose documents are question-and-prediction shaped. Golden Coin is deliberately not one
27
+ * of them: its event document is a separate type, discriminated by `engine`.
28
+ */
29
+ export type PredictionFamilyEngine =
30
+ | GameEngineEnum.MATCH_PREDICTOR
31
+ | GameEngineEnum.EDGE;
32
+
23
33
  export type BetEventBettingStatusType = "locked" | "unlocked" | "settled";
24
34
 
25
35
  export type BetEventStatusType =
@@ -2,15 +2,23 @@ import type {
2
2
  BetEventBettingStatusType,
3
3
  BetEventStatusType,
4
4
  GameEngineEnum,
5
+ PredictionFamilyEngine,
5
6
  } from "../bet-events";
6
7
  import type { ISODate, UUID } from "../common";
7
8
 
9
+ /**
10
+ * An event document, in whichever shape its engine projects. Narrow on `engine` before reading:
11
+ * a Golden Coin event carries no questions and a prediction event carries no coin state.
12
+ */
13
+ export type AnyEvent = Event | CoinEvent;
14
+
8
15
  export type Event = {
9
16
  id: UUID;
10
17
  startDate: ISODate;
11
18
  status: BetEventStatusType;
12
19
  bettingStatus: BetEventBettingStatusType;
13
- engine: GameEngineEnum;
20
+ /** Pinned to the prediction family so `AnyEvent` narrows on this field. */
21
+ engine: PredictionFamilyEngine;
14
22
  questionSetId: UUID;
15
23
  name: string;
16
24
  questions: EventQuestion[];
@@ -19,6 +27,46 @@ export type Event = {
19
27
  matchIds?: UUID[];
20
28
  };
21
29
 
30
+ /**
31
+ * A Golden Coin event document. The coin is a MATCH-level fact: every table of the match advances on
32
+ * the same pass count, each from its own starting seat, so this document carries the counts and the
33
+ * config in force while the per-table seating lives on the pool document (`Pool.coin`).
34
+ */
35
+ export type CoinEvent = {
36
+ id: UUID;
37
+ startDate: ISODate;
38
+ status: BetEventStatusType;
39
+ bettingStatus: BetEventBettingStatusType;
40
+ engine: GameEngineEnum.COIN_PASS;
41
+ name: string;
42
+ resultsUpdateReason: string | null;
43
+ matchIds?: UUID[];
44
+ coin: CoinEventState;
45
+ };
46
+
47
+ export type CoinEventState = {
48
+ /** Seats per table. A full table opens the next one. */
49
+ tableSize: number;
50
+ /**
51
+ * Fewest occupied seats for a table to be played. A table that stays below it when the match ends
52
+ * refunds every stake in full instead of paying a coin holder, so a player can see the threshold
53
+ * before paying. Together with `tableSize` this is the min and max of a table.
54
+ */
55
+ minTableSize: number;
56
+ /** The live stats that pass the coin. Any confirmed increment across them advances it. */
57
+ triggerStats: string[];
58
+ /** Seats the coin advances per confirmed trigger. */
59
+ advanceStep: number;
60
+ /** Percent of the pot the half-time holder takes; the full-time holder takes the remainder. */
61
+ halfTimeSplitPercent: number;
62
+ /** Confirmed triggers so far in the match. */
63
+ passCount: number;
64
+ /** The count captured at half time, or null until the half-time fact arrives. */
65
+ halfTimePassCount: number | null;
66
+ /** The count captured at full time, or null until the match finishes. */
67
+ fullTimePassCount: number | null;
68
+ };
69
+
22
70
  export type EventQuestion = {
23
71
  eventQuestionId: UUID;
24
72
  questionType: QuestionTypeEnum;
@@ -17,7 +17,8 @@ export enum PrizeDistributionStrategyEnum {
17
17
  }
18
18
 
19
19
  export type PoolEvent = {
20
- questionSetId: UUID;
20
+ /** Absent for engines that carry no question set (Golden Coin). */
21
+ questionSetId?: UUID;
21
22
  status: BetEventStatusType;
22
23
  engine: GameEngineEnum;
23
24
  /** Slug of the game this pool's event belongs to (sports-games `games.slug`). */
@@ -38,6 +39,63 @@ export type PoolLeaderboard = {
38
39
  }[];
39
40
  };
40
41
 
42
+ /**
43
+ * A pool document, in whichever shape its engine projects. Narrow on `event.engine` before reading an
44
+ * engine's own block: `Pool` carries only what EVERY engine has.
45
+ */
46
+ export type AnyPool = Pool | CoinPool;
47
+
48
+ /** A Golden Coin pool: the generic pool plus the table state, which only this engine has. */
49
+ export type CoinPool = Pool & { coin: CoinTable };
50
+
51
+ /**
52
+ * A Golden Coin table. The pool IS the table: seats are taken in join order, the coin starts on a seat
53
+ * drawn from the table's own seed, and each confirmed trigger advances it. Present only on pools of the
54
+ * `coin-pass` engine.
55
+ *
56
+ * How many tables an operator has open on an event, and how many players sit at them across all of
57
+ * them, is read from these documents: query `Pools` by `betEventId` and `operatorId`, and the result
58
+ * count is the number of tables while the sum of `participants` is the number of players. Every join
59
+ * reprojects the pool document, so both stay live and can never disagree with the seats a player is
60
+ * shown on a table.
61
+ */
62
+ export type CoinTable = {
63
+ /** Which table of this operator and event this is, counting from 1. */
64
+ tableNumber: number;
65
+ tableSize: number;
66
+ /** Fewest occupied seats for this table to pay a holder; below it every stake is refunded in full. */
67
+ minTableSize: number;
68
+ /**
69
+ * Does the table meet `minTableSize` right now? Decided by the engine, not by the client, so every
70
+ * screen states the same verdict: false means that as things stand this table refunds instead of
71
+ * paying a coin holder.
72
+ */
73
+ meetsMinimum: boolean;
74
+ /** Confirmed triggers so far in the match, mirrored from the event for a self-contained table view. */
75
+ passCount: number;
76
+ /** Occupied seats in join order. Seat numbers count from 1 and never leave a gap. */
77
+ seats: CoinSeat[];
78
+ /** The seat holding the coin right now, or null while the table has no bet. */
79
+ holdingSeatNumber: number | null;
80
+ /** Who held the coin at half time, or null until the half-time fact arrives. */
81
+ halfTimeHolder: CoinHolder | null;
82
+ /** Who held the coin at full time, or null until the match finishes. */
83
+ fullTimeHolder: CoinHolder | null;
84
+ };
85
+
86
+ export type CoinSeat = {
87
+ seatNumber: number;
88
+ betId: UUID;
89
+ userId: UUID;
90
+ displayName: string;
91
+ };
92
+
93
+ export type CoinHolder = {
94
+ seatNumber: number;
95
+ betId: UUID;
96
+ userId: UUID;
97
+ };
98
+
41
99
  export type Pool = {
42
100
  id: UUID;
43
101
  betEventId: UUID;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sportsbroker/firebase-structure",
3
- "version": "7.1.0",
3
+ "version": "8.1.0",
4
4
  "description": "Firebase structure typings",
5
5
  "main": "index.d.ts",
6
6
  "repository": {
@@ -1,34 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npx standard-version *)",
5
- "Bash(npm view *)",
6
- "Bash(git checkout *)",
7
- "Bash(npx tsc *)",
8
- "Bash(echo \"exit: $?\")",
9
- "Bash(git --no-pager diff)",
10
- "Bash(git add *)",
11
- "Bash(git commit *)",
12
- "Bash(git --no-pager log --oneline -2)",
13
- "Bash(echo \"tsc exit: $?\")",
14
- "Bash(git --no-pager show --stat --oneline HEAD)",
15
- "Bash(npm pack *)",
16
- "Bash(git --no-pager log --oneline --decorate -3)",
17
- "Bash(node -p \"require\\('./package.json'\\).version\")",
18
- "Bash(node -p \"require\\('./package-lock.json'\\).version\")",
19
- "Bash(gh auth *)",
20
- "Bash(git --no-pager log --oneline -1 origin/master)",
21
- "Bash(git fetch *)",
22
- "Bash(git ls-remote *)",
23
- "Bash(git --no-pager log --oneline --decorate -1)",
24
- "Bash(git --no-pager log --oneline --decorate --graph -6)",
25
- "Bash(git --no-pager reflog -12)",
26
- "Bash(git --no-pager log -1 --format='%H%n parent: %p%n author: %an %ad%n committer: %cn %cd%n subject: %s' 5c39828)",
27
- "Bash(git --no-pager log -1 --format='%H%n parent: %p%n committer: %cn %cd%n subject: %s' 0d7cbf5)",
28
- "Bash(git --no-pager log -1 --format='%H%n parent: %p%n committer: %cn %cd%n subject: %s' master)",
29
- "Bash(git tag *)",
30
- "Bash(git check-ignore *)",
31
- "Bash(git --no-pager log --oneline -- .claude/)"
32
- ]
33
- }
34
- }