@sleeperhq/mini-core 1.1.0 → 1.2.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.
@@ -1,4 +1,4 @@
1
- import { User, Navigation, League, LeaguesMap, RostersInLeagueMap, UserMap, MatchupsInLeagueMap } from './types';
1
+ import { User, Navigation, League, LeaguesMap, RostersInLeagueMap, UserMap, MatchupsInLeagueMap, UsersInLeagueMap, PlayoffsInLeagueMap, TransactionsInLeagueMap, TransactionsMap, SportInfoMap, DraftsInLeagueMap, DraftPickTradesInLeagueMap, DraftPicksInDraftMap, PlayersInSportMap } from './types';
2
2
  import SleeperActions from './sleeper_actions';
3
3
  declare class SleeperContext {
4
4
  static apiLevel: string;
@@ -10,6 +10,15 @@ declare class SleeperContext {
10
10
  rostersInLeagueMap: RostersInLeagueMap;
11
11
  userMap: UserMap;
12
12
  matchupsInLeagueMap: MatchupsInLeagueMap;
13
+ usersInLeagueMap: UsersInLeagueMap;
14
+ playoffsInLeagueMap: PlayoffsInLeagueMap;
15
+ transactionsInLeagueMap: TransactionsInLeagueMap;
16
+ transactionsMap: TransactionsMap;
17
+ sportInfoMap: SportInfoMap;
18
+ draftsInLeagueMap: DraftsInLeagueMap;
19
+ draftPickTradesInLeagueMap: DraftPickTradesInLeagueMap;
20
+ draftPicksInDraftMap: DraftPicksInDraftMap;
21
+ playersInSportMap: PlayersInSportMap;
13
22
  actions: SleeperActions;
14
23
  constructor();
15
24
  }
@@ -1,5 +1,5 @@
1
1
  import { NAVIGATION_ID, NAVIGATION_TYPE } from './redux/native_nav/constants.d';
2
- import { League, Roster, User, MatchupLeg } from './shared/graphql.d';
2
+ import { League, Roster, User, MatchupLeg, LeagueTransaction, Draft, DraftPick, RosterDraftPick, Player } from './shared/graphql.d';
3
3
  export type NavigationType = typeof NAVIGATION_TYPE[keyof typeof NAVIGATION_TYPE];
4
4
  export type NavigationTypeId = typeof NAVIGATION_ID[keyof typeof NAVIGATION_ID];
5
5
  export * from './shared/graphql.d';
@@ -12,9 +12,54 @@ export type LeagueId = string;
12
12
  export type RosterId = string;
13
13
  export type UserId = string;
14
14
  export type MatchupWeek = number;
15
+ export type MatchId = string;
16
+ export type TransactionId = string;
17
+ export type SportType = string;
18
+ export type DraftId = string;
19
+ export type PlayerId = string;
20
+ export type BracketFrom = {
21
+ w?: RosterId;
22
+ l?: RosterId;
23
+ };
24
+ export type Bracket = {
25
+ round: number;
26
+ matchId: MatchId;
27
+ t1: RosterId;
28
+ t2: RosterId;
29
+ w: RosterId;
30
+ l: RosterId;
31
+ t1_from: BracketFrom;
32
+ t2_from: BracketFrom;
33
+ };
34
+ export type BracketSet = {
35
+ bracket: Bracket[];
36
+ loserBracket: Bracket[];
37
+ }
38
+ export type SportInfo = {
39
+ season_type: string;
40
+ season: string;
41
+ week: number;
42
+ display_week: number;
43
+ leg: number;
44
+ league_season: string;
45
+ league_create_season: string;
46
+ previous_season: string;
47
+ season_start_date: string;
48
+ season_end_date: string;
49
+ };
15
50
  export type LeaguesMap = Record<LeagueId, League>;
16
51
  export type RostersMap = Record<RosterId, Roster>;
17
52
  export type RostersInLeagueMap = Record<LeagueId, RostersMap>;
18
53
  export type UserMap = Record<UserId, User>;
19
54
  export type MathchupWeekMap = Record<MatchupWeek, MatchupLeg>;
20
55
  export type MatchupsInLeagueMap = Record<LeagueId, MathchupWeekMap>;
56
+ export type UsersInLeagueMap = Record<LeagueId, UserId[]>;
57
+ export type PlayoffsInLeagueMap = Record<LeagueId, BracketSet>;
58
+ export type TransactionsInLeagueMap = Record<LeagueId, TransactionId[]>;
59
+ export type TransactionsMap = Record<TransactionId, LeagueTransaction>;
60
+ export type SportInfoMap = Record<SportType, SportInfo>;
61
+ export type DraftsInLeagueMap = Record<LeagueId, Draft[]>;
62
+ export type DraftPickTradesInLeagueMap = Record<LeagueId, RosterDraftPick[]>;
63
+ export type DraftPicksInDraftMap = Record<DraftId, DraftPick[]>;
64
+ export type PlayersMap = Record<PlayerId, Player>;
65
+ export type PlayersInSportMap = Record<SportType, PlayersMap>;
@@ -38,6 +38,34 @@ export type Scalars = {
38
38
  SnowflakeList: string[];
39
39
  SnowflakeSet: string[];
40
40
  };
41
+ export type Draft = {
42
+ __typename?: 'Draft';
43
+ created?: Maybe<Scalars['Int']>;
44
+ creators?: Maybe<Scalars['SnowflakeList']>;
45
+ draft_id?: Maybe<Scalars['Snowflake']>;
46
+ draft_order?: Maybe<Scalars['MapWithSnowflakeKey']>;
47
+ last_message_id?: Maybe<Scalars['Snowflake']>;
48
+ last_message_time?: Maybe<Scalars['Int']>;
49
+ last_picked?: Maybe<Scalars['Int']>;
50
+ league_id?: Maybe<Scalars['Snowflake']>;
51
+ metadata?: Maybe<Scalars['Map']>;
52
+ season?: Maybe<Scalars['String']>;
53
+ season_type?: Maybe<Scalars['String']>;
54
+ settings?: Maybe<Scalars['Map']>;
55
+ sport?: Maybe<Scalars['String']>;
56
+ start_time?: Maybe<Scalars['Int']>;
57
+ status?: Maybe<Scalars['String']>;
58
+ type?: Maybe<Scalars['String']>;
59
+ };
60
+ export type DraftPick = {
61
+ __typename?: 'DraftPick';
62
+ draft_id?: Maybe<Scalars['Snowflake']>;
63
+ is_keeper?: Maybe<Scalars['Boolean']>;
64
+ metadata?: Maybe<Scalars['Map']>;
65
+ pick_no?: Maybe<Scalars['Int']>;
66
+ picked_by?: Maybe<Scalars['Snowflake']>;
67
+ player_id?: Maybe<Scalars['String']>;
68
+ };
41
69
  export type League = {
42
70
  __typename?: 'League';
43
71
  avatar?: Maybe<Scalars['String']>;
@@ -71,6 +99,26 @@ export type League = {
71
99
  status?: Maybe<Scalars['String']>;
72
100
  total_rosters?: Maybe<Scalars['Int']>;
73
101
  };
102
+ export type LeagueTransaction = {
103
+ __typename?: 'LeagueTransaction';
104
+ adds?: Maybe<Scalars['Map']>;
105
+ consenter_ids?: Maybe<Scalars['List']>;
106
+ created?: Maybe<Scalars['Int']>;
107
+ creator?: Maybe<Scalars['Snowflake']>;
108
+ draft_picks?: Maybe<Scalars['List']>;
109
+ drops?: Maybe<Scalars['Map']>;
110
+ league_id?: Maybe<Scalars['Snowflake']>;
111
+ leg?: Maybe<Scalars['Int']>;
112
+ metadata?: Maybe<Scalars['Map']>;
113
+ player_map?: Maybe<Scalars['Map']>;
114
+ roster_ids?: Maybe<Scalars['List']>;
115
+ settings?: Maybe<Scalars['Map']>;
116
+ status?: Maybe<Scalars['String']>;
117
+ status_updated?: Maybe<Scalars['Int']>;
118
+ transaction_id?: Maybe<Scalars['Snowflake']>;
119
+ type?: Maybe<Scalars['String']>;
120
+ waiver_budget?: Maybe<Scalars['List']>;
121
+ };
74
122
  export type MatchupLeg = {
75
123
  __typename?: 'MatchupLeg';
76
124
  bans?: Maybe<Scalars['Map']>;
@@ -89,6 +137,47 @@ export type MatchupLeg = {
89
137
  starters?: Maybe<Scalars['List']>;
90
138
  starters_games?: Maybe<Scalars['Map']>;
91
139
  };
140
+ export type Player = {
141
+ __typename?: 'Player';
142
+ active?: Maybe<Scalars['Boolean']>;
143
+ age?: Maybe<Scalars['Int']>;
144
+ birth_city?: Maybe<Scalars['String']>;
145
+ birth_country?: Maybe<Scalars['String']>;
146
+ birth_date?: Maybe<Scalars['String']>;
147
+ birth_state?: Maybe<Scalars['String']>;
148
+ college?: Maybe<Scalars['String']>;
149
+ depth_chart_order?: Maybe<Scalars['Int']>;
150
+ depth_chart_position?: Maybe<Scalars['String']>;
151
+ espn_id?: Maybe<Scalars['Int']>;
152
+ fantasy_data_id?: Maybe<Scalars['Int']>;
153
+ fantasy_positions?: Maybe<Scalars['Set']>;
154
+ first_name?: Maybe<Scalars['String']>;
155
+ hashtag?: Maybe<Scalars['String']>;
156
+ height?: Maybe<Scalars['String']>;
157
+ high_school?: Maybe<Scalars['String']>;
158
+ injury_body_part?: Maybe<Scalars['String']>;
159
+ injury_notes?: Maybe<Scalars['String']>;
160
+ injury_start_date?: Maybe<Scalars['String']>;
161
+ injury_status?: Maybe<Scalars['String']>;
162
+ last_name?: Maybe<Scalars['String']>;
163
+ metadata?: Maybe<Scalars['Map']>;
164
+ number?: Maybe<Scalars['Int']>;
165
+ player_id?: Maybe<Scalars['String']>;
166
+ position?: Maybe<Scalars['String']>;
167
+ practice_description?: Maybe<Scalars['String']>;
168
+ practice_participation?: Maybe<Scalars['String']>;
169
+ rotowire_id?: Maybe<Scalars['Int']>;
170
+ rotoworld_id?: Maybe<Scalars['Int']>;
171
+ sport?: Maybe<Scalars['String']>;
172
+ sportradar_id?: Maybe<Scalars['String']>;
173
+ stats_id?: Maybe<Scalars['Int']>;
174
+ status?: Maybe<Scalars['String']>;
175
+ swish_id?: Maybe<Scalars['Int']>;
176
+ team?: Maybe<Scalars['String']>;
177
+ weight?: Maybe<Scalars['String']>;
178
+ yahoo_id?: Maybe<Scalars['Int']>;
179
+ years_exp?: Maybe<Scalars['Int']>;
180
+ };
92
181
  export type Roster = {
93
182
  __typename?: 'Roster';
94
183
  co_owners?: Maybe<Scalars['SnowflakeSet']>;
@@ -104,6 +193,15 @@ export type Roster = {
104
193
  starters?: Maybe<Scalars['List']>;
105
194
  taxi?: Maybe<Scalars['Set']>;
106
195
  };
196
+ export type RosterDraftPick = {
197
+ __typename?: 'RosterDraftPick';
198
+ league_id?: Maybe<Scalars['Snowflake']>;
199
+ owner_id?: Maybe<Scalars['Int']>;
200
+ previous_owner_id?: Maybe<Scalars['Int']>;
201
+ roster_id?: Maybe<Scalars['Int']>;
202
+ round?: Maybe<Scalars['Int']>;
203
+ season?: Maybe<Scalars['String']>;
204
+ };
107
205
  export type User = {
108
206
  __typename?: 'User';
109
207
  async_bundles?: Maybe<Scalars['List']>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleeperhq/mini-core",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Core library frameworks for developing Sleeper Mini Apps.",
5
5
  "main": "index.ts",
6
6
  "types": "index.d.ts",
@@ -8,10 +8,13 @@ import { fetchMainVersionMap, getMainUrl } from './url_resolver';
8
8
 
9
9
  let config: Config;
10
10
  const RETRY_TIMER = 5000;
11
+ const LOGS_ENABLED = false;
11
12
 
12
13
  const DevServer = props => {
13
14
  const connection = useRef<TcpSocket.Socket>();
14
15
  const partialMessage = useRef('');
16
+ const messageLength = useRef(0);
17
+ const messageType = useRef('');
15
18
  const _retryTimer = useRef<NodeJS.Timeout>();
16
19
 
17
20
  const [data, setData] = useState({
@@ -28,36 +31,87 @@ const DevServer = props => {
28
31
  };
29
32
 
30
33
  const onSocket = (handler) => msg => {
31
- let json;
32
- try {
33
- json = JSON.parse(msg);
34
- } catch(e) {
35
- partialMessage.current += msg;
36
- }
34
+ let msgString: string = msg.toString();
35
+ while (msgString.length > 0) {
36
+ if (messageLength.current === 0) {
37
+ const delimit = msgString.indexOf('\n');
38
+ if (delimit === -1) {
39
+ console.log("[Sleeper] Message header not found, throwing out message.");
40
+ return;
41
+ }
42
+
43
+ const header = msgString.substring(0, delimit);
44
+ try {
45
+ const headerObject = JSON.parse(header);
46
+ messageType.current = headerObject.type;
47
+ messageLength.current = headerObject.size;
48
+ } catch (e) {
49
+ console.log("[Sleeper] Message header malformed, throwing out message.");
50
+ messageLength.current = 0;
51
+ messageType.current = '';
52
+ return;
53
+ }
54
+
55
+ msgString = msgString.substring(delimit + 1);
56
+ }
57
+
58
+ const partialLength = messageLength.current - partialMessage.current.length;
59
+ if (partialLength < 0) {
60
+ // We need to wait for more data
61
+ partialMessage.current += msgString;
62
+ return;
63
+ }
64
+
65
+ const remainingLength = msgString.length - partialLength;
66
+ if (remainingLength === 0) {
67
+ // We have the full message
68
+ partialMessage.current += msgString;
69
+ msgString = '';
70
+ if (LOGS_ENABLED) console.log("[Sleeper] Message built.", partialMessage.current.length);
71
+
72
+ } else {
73
+ // We have more than the full message
74
+ partialMessage.current += msgString.substring(0, partialLength);
75
+ msgString = msgString.substring(partialLength);
76
+
77
+ if (remainingLength <= 0) {
78
+ // We have less than the full message
79
+ if (LOGS_ENABLED) console.log("[Sleeper] Building message: ", partialMessage.current.length, messageLength.current, remainingLength);
80
+ return;
81
+ }
82
+ }
37
83
 
38
- if (partialMessage.current.length > 0) {
39
84
  try {
40
- json = JSON.parse(partialMessage.current);
85
+ const json = JSON.parse(partialMessage.current);
41
86
  partialMessage.current = '';
87
+ messageLength.current = 0;
88
+
89
+ // Set connection data
90
+ if (json._platform || json._binaryVersion || json._dist || json._isStaging) {
91
+ console.log("[Sleeper] Processing context data:", json._platform, json._binaryVersion, json._dist, json._isStaging);
92
+ setData({
93
+ platform: json._platform,
94
+ binaryVersion: json._binaryVersion,
95
+ dist: json._dist,
96
+ isStaging: json._isStaging,
97
+ });
98
+ }
99
+
100
+ if (messageType.current === 'context') {
101
+ // We should have a context object now
102
+ const context = new Proxy(json, handler);
103
+ props.onContextChanged(context);
104
+ } else if (messageType.current === `partialContext`) {
105
+ // We are updating a partial Context
106
+ props.onContextUpdated(json)
107
+ }
108
+
109
+ messageType.current = '';
42
110
  } catch (e) {
111
+ console.log("[Sleeper] Failed to parse message: ", e);
43
112
  return;
44
113
  }
45
114
  }
46
-
47
- // Set connection data
48
- if (json._platform || json._binaryVersion || json._dist || json._isStaging) {
49
- console.log("[Sleeper] Received context data:", json._platform, json._binaryVersion, json._dist, json._isStaging);
50
- setData({
51
- platform: json._platform,
52
- binaryVersion: json._binaryVersion,
53
- dist: json._dist,
54
- isStaging: json._isStaging,
55
- });
56
- }
57
-
58
- // We should have a context object now
59
- const context = new Proxy(json, handler);
60
- props.onContextChanged(context);
61
115
  };
62
116
 
63
117
  const sendContextRequest = (socket, propertyPath) => {
@@ -103,6 +157,7 @@ const DevServer = props => {
103
157
 
104
158
  // If the value is undefined, we need to request it from the server
105
159
  if (value === undefined && isLeaf) {
160
+ console.log("[Sleeper] Requesting context value: ", fullPropertyPath);
106
161
  sendContextRequest(socket, fullPropertyPath);
107
162
  }
108
163