@sleeperhq/mini-core 1.1.0 → 1.2.1

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.
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+
3
+ const os = require('os');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+
7
+ const isWindows = os.platform() === 'win32';
8
+
9
+ const printError = (error) => {
10
+ console.error("\n\033[91m" + error + "\033[0m");
11
+ };
12
+
13
+ const printInfo = (message) => {
14
+ console.log("\n\033[96m" + message + "\033[0m");
15
+ };
16
+
17
+ const printComplete = (message) => {
18
+ console.log("\033[92m" + message + "\033[0m");
19
+ };
20
+
21
+ const main = async () => {
22
+ // Load the package.json
23
+ const packageJsonPath = path.join('package.json');
24
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
25
+
26
+ // Get the dependencies
27
+ const dependencies = packageJson.dependencies;
28
+
29
+ // Write a ./package_list.js file that imports all dependencies
30
+ const packageListPath = path.join('package_list.js');
31
+ const packageList = Object.keys(dependencies).map(
32
+ (packageName) => `import '${packageName}';`
33
+ ).join('\n');
34
+
35
+ let output = `/*
36
+ This file is automatically generated when you
37
+ add a package to your package.json and run yarn.
38
+ Please do not edit manually.
39
+ */
40
+
41
+ ${packageList}
42
+ `;
43
+
44
+ fs.writeFileSync(packageListPath, output);
45
+ process.exit(0);
46
+ };
47
+
48
+ main();
@@ -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,11 +1,12 @@
1
1
  {
2
2
  "name": "@sleeperhq/mini-core",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Core library frameworks for developing Sleeper Mini Apps.",
5
5
  "main": "index.ts",
6
6
  "types": "index.d.ts",
7
7
  "bin": {
8
- "build-mini": "./bin/build_mini.js"
8
+ "build-mini": "./bin/build_mini.js",
9
+ "preload-packages": "./bin/preload_packages.js"
9
10
  },
10
11
  "scripts": {
11
12
  "test": "jest",
@@ -12,6 +12,8 @@ const RETRY_TIMER = 5000;
12
12
  const DevServer = props => {
13
13
  const connection = useRef<TcpSocket.Socket>();
14
14
  const partialMessage = useRef('');
15
+ const messageLength = useRef(0);
16
+ const messageType = useRef('');
15
17
  const _retryTimer = useRef<NodeJS.Timeout>();
16
18
 
17
19
  const [data, setData] = useState({
@@ -28,36 +30,87 @@ const DevServer = props => {
28
30
  };
29
31
 
30
32
  const onSocket = (handler) => msg => {
31
- let json;
32
- try {
33
- json = JSON.parse(msg);
34
- } catch(e) {
35
- partialMessage.current += msg;
36
- }
33
+ let msgString: string = msg.toString();
34
+ while (msgString.length > 0) {
35
+ if (messageLength.current === 0) {
36
+ const delimit = msgString.indexOf('\n');
37
+ if (delimit === -1) {
38
+ console.log("[Sleeper] Message header not found, throwing out message.");
39
+ return;
40
+ }
41
+
42
+ const header = msgString.substring(0, delimit);
43
+ try {
44
+ const headerObject = JSON.parse(header);
45
+ messageType.current = headerObject.type;
46
+ messageLength.current = headerObject.size;
47
+ } catch (e) {
48
+ console.log("[Sleeper] Message header malformed, throwing out message.");
49
+ messageLength.current = 0;
50
+ messageType.current = '';
51
+ return;
52
+ }
53
+
54
+ msgString = msgString.substring(delimit + 1);
55
+ }
56
+
57
+ const partialLength = messageLength.current - partialMessage.current.length;
58
+ if (partialLength < 0) {
59
+ // We need to wait for more data
60
+ partialMessage.current += msgString;
61
+ return;
62
+ }
63
+
64
+ const remainingLength = msgString.length - partialLength;
65
+ if (remainingLength === 0) {
66
+ // We have the full message
67
+ partialMessage.current += msgString;
68
+ msgString = '';
69
+ if (config.logsEnabled) console.log("[Sleeper] Message built.", partialMessage.current.length);
70
+
71
+ } else {
72
+ // We have more than the full message
73
+ partialMessage.current += msgString.substring(0, partialLength);
74
+ msgString = msgString.substring(partialLength);
75
+
76
+ if (remainingLength <= 0) {
77
+ // We have less than the full message
78
+ if (config.logsEnabled) console.log("[Sleeper] Building message: ", partialMessage.current.length, messageLength.current, remainingLength);
79
+ return;
80
+ }
81
+ }
37
82
 
38
- if (partialMessage.current.length > 0) {
39
83
  try {
40
- json = JSON.parse(partialMessage.current);
84
+ const json = JSON.parse(partialMessage.current);
41
85
  partialMessage.current = '';
86
+ messageLength.current = 0;
87
+
88
+ // Set connection data
89
+ if (json._platform || json._binaryVersion || json._dist || json._isStaging) {
90
+ if (config.logsEnabled) console.log("[Sleeper] Processing context data:", json._platform, json._binaryVersion, json._dist, json._isStaging);
91
+ setData({
92
+ platform: json._platform,
93
+ binaryVersion: json._binaryVersion,
94
+ dist: json._dist,
95
+ isStaging: json._isStaging,
96
+ });
97
+ }
98
+
99
+ if (messageType.current === 'context') {
100
+ // We should have a context object now
101
+ const context = new Proxy(json, handler);
102
+ props.onContextChanged(context);
103
+ } else if (messageType.current === `partialContext`) {
104
+ // We are updating a partial Context
105
+ props.onContextUpdated(json)
106
+ }
107
+
108
+ messageType.current = '';
42
109
  } catch (e) {
110
+ console.log("[Sleeper] Failed to parse message: ", e);
43
111
  return;
44
112
  }
45
113
  }
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
114
  };
62
115
 
63
116
  const sendContextRequest = (socket, propertyPath) => {
@@ -103,6 +156,7 @@ const DevServer = props => {
103
156
 
104
157
  // If the value is undefined, we need to request it from the server
105
158
  if (value === undefined && isLeaf) {
159
+ if (config.logsEnabled) console.log("[Sleeper] Requesting context value: ", fullPropertyPath);
106
160
  sendContextRequest(socket, fullPropertyPath);
107
161
  }
108
162
 
@@ -224,7 +278,7 @@ const DevServer = props => {
224
278
  });
225
279
  const query = config.dev ? {platform: Platform.OS} : undefined;
226
280
 
227
- console.log('[Sleeper] load script:', scriptId, caller, url);
281
+ if (config.logsEnabled) console.log('[Sleeper] load script:', scriptId, caller, url);
228
282
  return {url, query};
229
283
  }
230
284
 
@@ -8,4 +8,5 @@ export type Config = {
8
8
  remoteIP: string,
9
9
  remoteSocketPort?: number,
10
10
  dev?: boolean,
11
+ logsEnabled?: boolean,
11
12
  };