@sportsbroker/firebase-structure 7.0.0 → 8.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.
@@ -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 =
@@ -36,15 +36,28 @@ export enum BetStatusEnum {
36
36
 
37
37
  export type BetPredictionType = Prediction;
38
38
 
39
- export type Prediction = {
39
+ /**
40
+ * A prediction is in exactly one of two shapes: pending or settled.
41
+ * Pending = no final result yet, or a doc projected before the settlement fields existed.
42
+ * Consumers MUST treat the pending shape as pending, never as "wrong".
43
+ */
44
+ export type Prediction = PendingPrediction | SettledPrediction;
45
+
46
+ export type BasePrediction = {
40
47
  eventQuestionId: UUID;
41
48
  predictionValue: QuestionResultValue;
42
- /**
43
- * Whether this answer was correct, set only once the bet is settled (won/lost).
44
- * Absent = pending: no final result yet, or a document projected before this field
45
- * existed. Consumers MUST treat absent as pending, never as "wrong".
46
- */
47
- correct?: boolean;
49
+ };
50
+
51
+ export type PendingPrediction = BasePrediction & {
52
+ correct?: never;
53
+ pointsAwarded?: never;
54
+ };
55
+
56
+ export type SettledPrediction = BasePrediction & {
57
+ /** Whether this answer was correct. Set only once the bet is settled (won/lost). */
58
+ correct: boolean;
59
+ /** Points this answer contributed to the bet score. */
60
+ pointsAwarded: number;
48
61
  };
49
62
 
50
63
  export enum MatchSideResultEnum {
@@ -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,40 @@ 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
+ /** The live stats that pass the coin. Any confirmed increment across them advances it. */
51
+ triggerStats: string[];
52
+ /** Seats the coin advances per confirmed trigger. */
53
+ advanceStep: number;
54
+ /** Percent of the pot the half-time holder takes; the full-time holder takes the remainder. */
55
+ halfTimeSplitPercent: number;
56
+ /** Confirmed triggers so far in the match. */
57
+ passCount: number;
58
+ /** The count captured at half time, or null until the half-time fact arrives. */
59
+ halfTimePassCount: number | null;
60
+ /** The count captured at full time, or null until the match finishes. */
61
+ fullTimePassCount: number | null;
62
+ };
63
+
22
64
  export type EventQuestion = {
23
65
  eventQuestionId: UUID;
24
66
  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,49 @@ 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
+ export type CoinTable = {
57
+ /** Which table of this operator and event this is, counting from 1. */
58
+ tableNumber: number;
59
+ tableSize: number;
60
+ /** Confirmed triggers so far in the match, mirrored from the event for a self-contained table view. */
61
+ passCount: number;
62
+ /** Occupied seats in join order. Seat numbers count from 1 and never leave a gap. */
63
+ seats: CoinSeat[];
64
+ /** The seat holding the coin right now, or null while the table has no bet. */
65
+ holdingSeatNumber: number | null;
66
+ /** Who held the coin at half time, or null until the half-time fact arrives. */
67
+ halfTimeHolder: CoinHolder | null;
68
+ /** Who held the coin at full time, or null until the match finishes. */
69
+ fullTimeHolder: CoinHolder | null;
70
+ };
71
+
72
+ export type CoinSeat = {
73
+ seatNumber: number;
74
+ betId: UUID;
75
+ userId: UUID;
76
+ displayName: string;
77
+ };
78
+
79
+ export type CoinHolder = {
80
+ seatNumber: number;
81
+ betId: UUID;
82
+ userId: UUID;
83
+ };
84
+
41
85
  export type Pool = {
42
86
  id: UUID;
43
87
  betEventId: UUID;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sportsbroker/firebase-structure",
3
- "version": "7.0.0",
3
+ "version": "8.0.0",
4
4
  "description": "Firebase structure typings",
5
5
  "main": "index.d.ts",
6
6
  "repository": {