@sportsbroker/firebase-structure 3.46.0-0 → 3.47.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/README.md CHANGED
@@ -35,6 +35,7 @@ Id's of objects are always held as it's keys in order to let build better querie
35
35
  ### Queries
36
36
 
37
37
  #### Path
38
+
38
39
  In order to build Firebase query it's necessary to know full path to retrieved object. There are no path queries which allow to find some node without knowing names of it's ancestor. So for such structure:
39
40
 
40
41
  ```javascript
@@ -70,13 +71,13 @@ In order to build Firebase query it's necessary to know full path to retrieved o
70
71
  }
71
72
  ```
72
73
 
73
- If there is necessity to retrieve object *matches* it's necessary to know id of its' parent node (*sportId*) and use it with full path `sportId/matches`. There is no sensible possibility though to retrieve matches from both *sportId* and *sport2Id* (the only way to do it is to retrieve full object with *teams*, *players* and all other siblings there could be)
74
+ If there is necessity to retrieve object _matches_ it's necessary to know id of its' parent node (_sportId_) and use it with full path `sportId/matches`. There is no sensible possibility though to retrieve matches from both _sportId_ and _sport2Id_ (the only way to do it is to retrieve full object with _teams_, _players_ and all other siblings there could be)
74
75
 
75
76
  ##### Finding path nodes
76
77
 
77
- Having just such structure as above it's impossible to get *sportId* and *sport2Id* without loading whole objects and getting their keys.
78
+ Having just such structure as above it's impossible to get _sportId_ and _sport2Id_ without loading whole objects and getting their keys.
78
79
 
79
- It's why to retrieve such key there is necessity to build additional object where, *sportId* will contain only lightweight sorting and querying data, such as:
80
+ It's why to retrieve such key there is necessity to build additional object where, _sportId_ will contain only lightweight sorting and querying data, such as:
80
81
 
81
82
  ```javascript
82
83
  {
@@ -153,7 +154,7 @@ Structure is divided into sections: **details**, **queries**, **snapshots**, and
153
154
 
154
155
  Every section have on some level descendants which are list of ids of objects. Subscription should always happen on the last id node in a path in order to retrieve singular object, or on last but one for retrieving lists of data.
155
156
 
156
- Most of sections contain object **overviews**. It's goal is to gather data defining its' first ancestor (such as for example *name*).
157
+ Most of sections contain object **overviews**. It's goal is to gather data defining its' first ancestor (such as for example _name_).
157
158
 
158
159
  Each of sections stores slightly different types of data:
159
160
 
@@ -169,7 +170,7 @@ If some data is duplicated between sections then it shouldn't be updated the sam
169
170
 
170
171
  #### matches
171
172
 
172
- Contains data necessary to display detailed data of a singular match. It assumes that once client app enters such detailed match screen it has to already have id of a match.
173
+ Contains data necessary to display detailed data of a singular match. It assumes that once client app enters such detailed match screen it has to already have id of a match.
173
174
 
174
175
  Important thing to notice is that once match is over no data is going to change for such match. It's why data for teams shares, venue are duplicated here (even if venue or team name changes in the future in match screen should be displayed old one). It helps to simplify logic of finding proper names depending on dates.
175
176
 
@@ -204,3 +205,7 @@ In queries section besides logical types sections level there is introduced also
204
205
  1. Run `tsc && npm pack`
205
206
  2. Copy absolute path to `sportsbroker-firebase-structure-<version>.tgz`
206
207
  3. Run `npm install <absolute-path>` on another project
208
+
209
+ ## Firestore
210
+
211
+ In **firestore** directory, we keep types for document structures that are used in **Firestore** DB which is more efficient than RealtimeDB. Convention is one file for one Firestore collection that exports types for this collection document.
@@ -0,0 +1,13 @@
1
+ export type Doc = {
2
+ docId: UUID;
3
+ createdAt: Date;
4
+ updatedAt?: Date;
5
+ };
6
+
7
+ export type ISODate = string;
8
+
9
+ export type UUID = string;
10
+
11
+ export interface Image {
12
+ default: string;
13
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./common";
2
+ export * from "./user-status";
3
+ export * from "./match";
@@ -0,0 +1,167 @@
1
+ import { ISODate, UUID, Image, Doc } from "./common";
2
+
3
+ export type MatchDoc = MatchData & Doc;
4
+
5
+ export type MatchData = {
6
+ matchId: UUID;
7
+ sport: SportEnum;
8
+ teams?: MatchSides<MatchTeam>;
9
+ score?: MatchScores;
10
+ tournamentType: TournamentType;
11
+ stage?: MatchStage;
12
+ group?: MatchGroup;
13
+ previousMatches?: MatchSides<PreviousMatch[]>;
14
+ startDate: ISODate;
15
+ roundNb: number;
16
+ eventStatus: EventStatus;
17
+ season: string;
18
+ };
19
+
20
+ export type MatchResult = "WON" | "DRAW" | "LOST";
21
+
22
+ export enum SportEnum {
23
+ SOCCER = "soccer",
24
+ }
25
+
26
+ export type TournamentType =
27
+ | "DOMESTIC_LEAGUE"
28
+ | "DOMESTIC_CUP"
29
+ | "INTERNATIONAL_CUP";
30
+
31
+ export type MatchScores = {
32
+ home: number | null;
33
+ away: number | null;
34
+ periods: {
35
+ firstHalf: MatchSides<number | null>;
36
+ secondHalf: MatchSides<number | null>;
37
+ firstOvertime: MatchSides<number | null>;
38
+ secondOvertime: MatchSides<number | null>;
39
+ shootoutPenalties: MatchSides<number | null>;
40
+ };
41
+ };
42
+
43
+ export enum MatchTeamSideEnum {
44
+ HOME = "home",
45
+ AWAY = "away",
46
+ NONE = "none",
47
+ }
48
+
49
+ export type PreviousMatch = {
50
+ playedAs: MatchTeamSideEnum;
51
+ result: MatchResult;
52
+ score: number;
53
+ opponent: Opponent;
54
+ startDate: ISODate;
55
+ };
56
+
57
+ export interface MatchSides<T> {
58
+ [MatchTeamSideEnum.HOME]?: T;
59
+ [MatchTeamSideEnum.AWAY]?: T;
60
+ }
61
+
62
+ export type MatchStage = {
63
+ stageId: UUID;
64
+ name: string;
65
+ };
66
+
67
+ export type MatchGroup = {
68
+ groupId: UUID;
69
+ name: string;
70
+ };
71
+ // TODO is seems to be used byt when and where?
72
+ export type MatchTmpTeams = {
73
+ home?: string;
74
+ away?: string;
75
+ };
76
+
77
+ export type MatchTeams = {
78
+ home?: MatchTeam;
79
+ away?: MatchTeam;
80
+ };
81
+
82
+ export type MatchTeam = {
83
+ id: UUID;
84
+ name: string;
85
+ shortName: string;
86
+ abbreviation: string;
87
+ logo?: Image;
88
+ };
89
+
90
+ export type Share = {
91
+ price: number;
92
+ openingPrice: number;
93
+ priceChangePercentage: number;
94
+ };
95
+
96
+ export type EventStatus = {
97
+ matchStatus: MatchStatusEnum;
98
+ period: MatchPeriodEnum;
99
+ isActive: boolean;
100
+ matchTime: MatchTime;
101
+ };
102
+
103
+ export enum MatchPeriodEnum {
104
+ PRE_MATCH = "PRE_MATCH",
105
+ FIRST_HALF = "FIRST_HALF",
106
+ SECOND_HALF = "SECOND_HALF",
107
+ FIRST_OVERTIME_HALF = "FIRST_OVERTIME_HALF",
108
+ SECOND_OVERTIME_HALF = "SECOND_OVERTIME_HALF",
109
+ SHOOTOUT = "SHOOTOUT",
110
+ }
111
+
112
+ export enum MatchStatusEnum {
113
+ PENDING = "PENDING",
114
+ STARTED = "STARTED",
115
+ FINISHED = "FINISHED",
116
+ POSTPONED = "POSTPONED",
117
+ }
118
+
119
+ export type MatchTime = {
120
+ minutes: number;
121
+ additionalMinutes: number;
122
+ };
123
+
124
+ export type Opponent = {
125
+ score: number;
126
+ name: string;
127
+ teamId: string;
128
+ abbreviation: string;
129
+ logo?: Image;
130
+ };
131
+
132
+ export type MatchPair = {
133
+ home?: Team;
134
+ away?: Team;
135
+ };
136
+
137
+ export type Team = {
138
+ _id: string;
139
+ teamId: string;
140
+ name: string;
141
+ displayName: string;
142
+ shortName: string;
143
+ officialName: string;
144
+ code: string;
145
+ type: TeamType;
146
+ countryId: string;
147
+ status: TeamStatus;
148
+ city: string | null;
149
+ createdAt: Date;
150
+ updatedAt: Date;
151
+ tournaments: string[];
152
+ logo: {
153
+ default: string;
154
+ };
155
+ isCurrentlyPlaying: boolean;
156
+ currentlyPlayedMatch: string | null;
157
+ };
158
+
159
+ export enum TeamType {
160
+ NATIONAL = "national",
161
+ CLUB = "club",
162
+ }
163
+
164
+ export enum TeamStatus {
165
+ ACTIVE = "active",
166
+ DEFUNCT = "defunct",
167
+ }
@@ -0,0 +1,16 @@
1
+ import { Doc, UUID } from "./common";
2
+
3
+ export type UserStatus =
4
+ | "CREATED"
5
+ | "ACTIVATED"
6
+ | "EMAIL_CONFIRMED"
7
+ | "VERIFICATION_FAILED"
8
+ | "DEACTIVATED"
9
+ | "SELF_EXCLUDED"
10
+ | "BANNED"
11
+ | "DUPLICATED";
12
+
13
+ export type UserStatusDoc = {
14
+ userId: UUID;
15
+ status: UserStatus;
16
+ } & Doc;
package/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./models/global";
2
2
  export * from "./models/_index";
3
+ export * from "./firestore";
@@ -3,7 +3,6 @@ import {Group, ISODate, MatchID, MatchPeriod, MatchStatus, SeasonID, Stage, Tour
3
3
  export interface MatchTime {
4
4
  minutes: number;
5
5
  additionalMinutes: number;
6
- periodId: number;
7
6
  }
8
7
 
9
8
  export interface EventStatus {
@@ -6,10 +6,10 @@ export interface Score {
6
6
  export interface MatchScore {
7
7
  home: number | null; // total without penalties
8
8
  away: number | null; // total without penalties
9
- periods: SoccerPeriods | NFLPeriods;
9
+ periods: MatchPeriods;
10
10
  }
11
11
 
12
- export interface SoccerPeriods {
12
+ export interface MatchPeriods {
13
13
  firstHalf?: Score;
14
14
  secondHalf?: Score;
15
15
  firstOvertime?: Score;
@@ -17,10 +17,6 @@ export interface SoccerPeriods {
17
17
  shootoutPenalties?: Score;
18
18
  }
19
19
 
20
- export interface NFLPeriods {
21
- [sequenceName: string]: Score
22
- }
23
-
24
20
  export interface Scores {
25
21
  [sportID: string]: {
26
22
  [matchID: string]: MatchScore;
@@ -6,9 +6,7 @@ export interface TeamsStats {
6
6
  /**
7
7
  * @see: https://sportsbroker.slite.com/app/channels/VOZ0prjzHu/notes/tOQ3uR_FUT
8
8
  */
9
- export type MatchStats = ISoccerStats | INFLStats;
10
-
11
- export interface ISoccerStats {
9
+ export interface MatchStats {
12
10
  // possession
13
11
  possessionPercentageLast15: TeamsStats,
14
12
  possessionPercentageLast30: TeamsStats,
@@ -79,42 +77,6 @@ export interface ISoccerStats {
79
77
  penaltyTaken: TeamsStats,
80
78
  }
81
79
 
82
- export interface INFLStats {
83
- firstDowns : TeamsStats,
84
- firstDownsPassing: TeamsStats,
85
- firstDownsRushing: TeamsStats,
86
- firstDownsFromPenalties: TeamsStats,
87
- thirdDownEfficiency: TeamsStats,
88
- fourthDownEfficiency: TeamsStats,
89
- totalPlays: TeamsStats,
90
- totalYards: TeamsStats,
91
- totalDrives: TeamsStats,
92
- yardsPerPlay: TeamsStats,
93
- passing: TeamsStats,
94
- passingCompletions: TeamsStats,
95
- passingAttempts: TeamsStats,
96
- yardsPerPass: TeamsStats,
97
- interceptionsThrown: TeamsStats,
98
- rushing: TeamsStats,
99
- rushingAttempts: TeamsStats,
100
- yardsPerRush: TeamsStats,
101
- redZone: TeamsStats,
102
- turnovers: TeamsStats,
103
- fumblesLost: TeamsStats,
104
- possession: TeamsStats,
105
- thirdDownEfficiencySuccess: TeamsStats
106
- thirdDownEfficiencyAttempts: TeamsStats
107
- fourthDownEfficiencySuccess: TeamsStats
108
- fourthDownEfficiencyAttempts: TeamsStats
109
- redZoneAttempts: TeamsStats
110
- redZoneSuccess: TeamsStats
111
- penaltiesYards: TeamsStats
112
- specialTeamsTDs: TeamsStats
113
- sackYardLostSacks: TeamsStats
114
- sackYardLostSackYards: TeamsStats
115
- penaltiesTotal: TeamsStats
116
- }
117
-
118
80
  export interface Stats {
119
81
  [sportID: string]: {
120
82
  [matchID: string]: MatchStats
@@ -1,4 +1,4 @@
1
- export interface SoccerTeamRanking {
1
+ export interface TeamRanking {
2
2
  position: number;
3
3
  positionChange: number;
4
4
  points: number;
@@ -11,44 +11,20 @@ export interface SoccerTeamRanking {
11
11
  goalsAgainst: number;
12
12
  }
13
13
 
14
- export interface NflTeamRanking {
15
- won: number;
16
- lost: number;
17
- draw: number;
18
- played: number;
19
- winningPercentage: number;
20
- position: number;
21
- lastPosition?: number;
22
- }
23
-
24
- export type TeamRanking = SoccerTeamRanking | NflTeamRanking;
25
-
26
14
  export interface Ranking {
27
15
  groups: {
28
- soccer: {
16
+ [sportID: string]: {
29
17
  [seasonID: string]: {
30
18
  [groupID: string]: {
31
- [teamID: string]: SoccerTeamRanking;
19
+ [teamID: string]: TeamRanking;
32
20
  };
33
21
  };
34
22
  };
35
- nfl: {
36
- [seasonID: string]: {
37
- [groupID: string]: {
38
- [teamID: string]: NflTeamRanking;
39
- };
40
- };
41
- }
42
23
  };
43
24
  leagues: {
44
- soccer: {
45
- [seasonID: string]: {
46
- [teamID: string]: SoccerTeamRanking;
47
- };
48
- };
49
- nfl: {
25
+ [sportID: string]: {
50
26
  [seasonID: string]: {
51
- [teamID: string]: NflTeamRanking;
27
+ [teamID: string]: TeamRanking;
52
28
  };
53
29
  };
54
30
  };
@@ -8,7 +8,6 @@ import { Transactions } from './transactions';
8
8
  import { Messages } from './messages';
9
9
  import { PromoOffers } from './promoOffers';
10
10
  import { UserVerificationStatuses } from './verificationStatus';
11
- import { Leaderboard } from './leaderboard';
12
11
 
13
12
  export interface Users {
14
13
  orders: Orders;
@@ -20,6 +19,5 @@ export interface Users {
20
19
  transactions: Transactions;
21
20
  messages: Messages;
22
21
  promoOffers?: PromoOffers;
23
- verificationStatus: UserVerificationStatuses;
24
- leaderboard: Leaderboard;
22
+ verificationStatus: UserVerificationStatuses
25
23
  }
@@ -1,4 +1,4 @@
1
- import {ISODate, TeamID, Percentage} from "../../global";
1
+ import {ISODate, SportID, TeamID, Percentage} from "../../global";
2
2
 
3
3
  export type OrderActionType = "BUY" | "SELL";
4
4
 
@@ -32,6 +32,7 @@ export interface Order {
32
32
  processedMoney: number;
33
33
  processedFee: number;
34
34
  processedTotalMoney: number; // processedMoney + processedFee
35
+ sportId: SportID;
35
36
  teamId: TeamID;
36
37
  transactionFee: Percentage;
37
38
  type: OrderTransactionType;
@@ -1,6 +1,7 @@
1
1
  import {ISODate, MatchID, SportID, TeamSide} from "../../global";
2
2
 
3
3
  export interface UserOwnedShares {
4
+ sportId: SportID;
4
5
  amount: number;
5
6
  availableAmount: number;
6
7
  invested: number;
@@ -8,7 +8,6 @@ export type NumericID = number;
8
8
  */
9
9
  export type MongoID = string;
10
10
 
11
-
12
11
  export type UUID = string;
13
12
 
14
13
  export type UserID = MongoID;
@@ -23,7 +22,7 @@ export type ISODate = string;
23
22
  /**
24
23
  * Currently support only soccer
25
24
  */
26
- export type SportID = "soccer" | "nfl" | string;
25
+ export type SportID = "soccer" | string;
27
26
 
28
27
  export type Language = "en" | "de" | string;
29
28
 
@@ -42,7 +41,7 @@ export type GroupID = string;
42
41
  */
43
42
  export type PlayerID = string;
44
43
 
45
- export type Percentage = number // 0.0-1.0
44
+ export type Percentage = number; // 0.0-1.0
46
45
 
47
46
  export interface Image {
48
47
  default: string;
@@ -69,7 +68,10 @@ export interface MatchSide<T> {
69
68
  */
70
69
  export type MatchStatus = "PENDING" | "STARTED" | "FINISHED" | "POSTPONED";
71
70
 
72
- export type TournamentType = 'DOMESTIC_LEAGUE' | 'DOMESTIC_CUP' | 'INTERNATIONAL_CUP';
71
+ export type TournamentType =
72
+ | "DOMESTIC_LEAGUE"
73
+ | "DOMESTIC_CUP"
74
+ | "INTERNATIONAL_CUP";
73
75
 
74
76
  export interface WithSeasons {
75
77
  seasons: {
@@ -79,7 +81,7 @@ export interface WithSeasons {
79
81
 
80
82
  export type MarketingOffers = "REGISTER2021";
81
83
 
82
- export type Platforms = 'IOS' | 'WEB' | 'ANDROID';
84
+ export type Platforms = "IOS" | "WEB" | "ANDROID";
83
85
 
84
86
  export interface Stage {
85
87
  id: string;
@@ -11,7 +11,6 @@ import {
11
11
  TeamSide,
12
12
  TournamentType,
13
13
  } from "../global";
14
- import {MatchTime} from "../details/matches/overviews";
15
14
 
16
15
  export interface Team {
17
16
  id: TeamID;
@@ -51,7 +50,10 @@ export interface EventStatus {
51
50
  matchStatus: MatchStatus;
52
51
  period: MatchPeriod;
53
52
  isActive: boolean;
54
- matchTime: MatchTime
53
+ matchTime: {
54
+ minutes: number;
55
+ additionalMinutes: number;
56
+ };
55
57
  }
56
58
 
57
59
  export interface MatchOverviewSnapshot {
@@ -29,27 +29,17 @@ export interface GroupTable {
29
29
 
30
30
  export interface TableSummary {
31
31
  groups: {
32
- soccer: {
32
+ [sportID: string]: {
33
33
  [seasonID: string]: {
34
34
  [groupId: string]: GroupTable;
35
35
  }
36
- },
37
- nfl: {
38
- [seasonID: string]: {
39
- [groupId: string]: GroupTable;
40
- }
41
- },
36
+ }
42
37
  };
43
38
  leagues: {
44
- soccer: {
45
- [seasonID: string]: {
46
- [teamID: string]: TeamTable;
47
- };
48
- },
49
- nfl: {
39
+ [sportID: string]: {
50
40
  [seasonID: string]: {
51
41
  [teamID: string]: TeamTable;
52
42
  };
53
- },
43
+ };
54
44
  };
55
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sportsbroker/firebase-structure",
3
- "version": "3.46.0-0",
3
+ "version": "3.47.0",
4
4
  "description": "Firebase structure typings",
5
5
  "main": "index.d.ts",
6
6
  "repository": {
@@ -1,11 +0,0 @@
1
- export interface LeaderboardValue {
2
- username: string;
3
- position: number;
4
- value: number;
5
- }
6
-
7
- export interface Leaderboard {
8
- [userId: string]: {
9
- allTime: LeaderboardValue;
10
- };
11
- }