speedruncom.js 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.
@@ -2,6 +2,26 @@ import { Project } from 'ts-morph';
2
2
  const project = new Project({
3
3
  tsConfigFilePath: "tsconfig.json",
4
4
  });
5
+ const isInterfaceEmpty = (interfaceName, sourceFile) => {
6
+ const declarations = sourceFile.getExportedDeclarations().get(interfaceName);
7
+ if (!declarations || declarations.length === 0)
8
+ return false;
9
+ const decl = declarations[0];
10
+ if (!decl || !decl.getKindName || decl.getKindName() !== "InterfaceDeclaration")
11
+ return false;
12
+ const props = decl.getProperties();
13
+ return props.length === 0;
14
+ };
15
+ const isInterfaceAllOptional = (name, sourceFile) => {
16
+ const iface = sourceFile.getInterface(name);
17
+ if (iface) {
18
+ return iface.getProperties().some(p => !p.hasQuestionToken());
19
+ }
20
+ const typeNode = sourceFile.getTypeAliasOrThrow(name).getType();
21
+ return typeNode
22
+ .getProperties()
23
+ .some(p => !p.isOptional());
24
+ };
5
25
  const baseClient = project.getSourceFileOrThrow('src/BaseClient.ts');
6
26
  const clientFile = project.createSourceFile('src/Client.ts', baseClient.getFullText(), { overwrite: true });
7
27
  const clientClass = clientFile.getClasses()[1];
@@ -11,32 +31,33 @@ const responsesFile = project.getSourceFileOrThrow('src/responses.ts');
11
31
  const getEndpointNames = Array.from(getEndpointsFile.getExportedDeclarations().keys());
12
32
  const postEndpointNames = Array.from(postEndpointsFile.getExportedDeclarations().keys());
13
33
  const responseNames = new Set(Array.from(responsesFile.getExportedDeclarations().keys()));
14
- for (const endpointName of getEndpointNames) {
15
- const returnType = responseNames.has(endpointName) ? `Promise<Responses.${endpointName}>` : 'Promise<void>';
16
- clientClass.addMethod({
17
- name: endpointName,
18
- isAsync: true,
19
- parameters: [{ name: 'params', type: `GetEndpoints.${endpointName}` }],
20
- returnType,
21
- statements: [`return await this.request('${endpointName}', params, 'post');`]
22
- });
23
- clientClass.addMethod({
24
- name: endpointName,
25
- isStatic: true,
34
+ const makeMethod = (name, isStatic, returnType, isEmpty, interfaces, isOptional) => {
35
+ const method = {
36
+ name,
37
+ isStatic,
26
38
  isAsync: true,
27
- parameters: [{ name: 'params', type: `GetEndpoints.${endpointName}` }],
28
39
  returnType,
29
- statements: [`return await this.request('${endpointName}', params, 'get');`]
30
- });
40
+ statements: [`return await this.request('${name}'${!isEmpty ? ', params' : ''});`]
41
+ };
42
+ if (!isEmpty)
43
+ method.parameters = [{
44
+ name: 'params',
45
+ type: `${interfaces}.${name}`,
46
+ hasQuestionToken: isOptional
47
+ }];
48
+ clientClass.addMethod(method);
49
+ };
50
+ for (const endpointName of getEndpointNames) {
51
+ const returnType = responseNames.has(endpointName) ? `Promise<Readonly<Responses.${endpointName}>>` : 'Promise<void>';
52
+ const isEmpty = isInterfaceEmpty(endpointName, getEndpointsFile);
53
+ const isAllOptional = isInterfaceAllOptional(endpointName, getEndpointsFile);
54
+ makeMethod(endpointName, false, returnType, isEmpty, 'GetEndpoints', isAllOptional);
55
+ makeMethod(endpointName, true, returnType, isEmpty, 'GetEndpoints', isAllOptional);
31
56
  }
32
57
  for (const endpointName of postEndpointNames) {
33
- const returnType = responseNames.has(endpointName) ? `Promise<Responses.${endpointName}>` : 'Promise<void>';
34
- clientClass.addMethod({
35
- name: endpointName,
36
- isAsync: true,
37
- parameters: [{ name: 'params', type: `PostEndpoints.${endpointName}` }],
38
- returnType,
39
- statements: [`return await this.request('${endpointName}', params, 'post');`]
40
- });
58
+ const returnType = responseNames.has(endpointName) ? `Promise<Readonly<Responses.${endpointName}>>` : 'Promise<void>';
59
+ const isEmpty = isInterfaceEmpty(endpointName, postEndpointsFile);
60
+ const isAllOptional = isInterfaceAllOptional(endpointName, postEndpointsFile);
61
+ makeMethod(endpointName, false, returnType, isEmpty, 'PostEndpoints', isAllOptional);
41
62
  }
42
63
  clientFile.saveSync();
@@ -3,46 +3,51 @@ import * as Interfaces from '../interfaces.js';
3
3
  import { AtLeastOne } from '../types.js';
4
4
  /**
5
5
  * Gets a leaderboard, with Players included.
6
+ *
6
7
  * `GetGameLeaderboard` can fetch twice as many runs, and also fetches Games, Platforms, Regions, Values, and Variables.
7
8
  */
8
9
  export interface GetGameLeaderboard2 {
9
10
  /**
10
- * Filtering parameters.
11
+ * The leaderboard to fetch.
11
12
  */
12
13
  params: Interfaces.LeaderboardParams;
13
14
  /**
14
- * The leaderboard page, in relation to `limit`.
15
- */
16
- page?: number;
17
- /**
18
- * The limit of Runs per page.
19
- * Max: 100
15
+ * The maximum amount of `Run`s per page.
16
+ *
17
+ * @max 100
20
18
  * @default 100
21
19
  */
22
20
  limit?: number;
21
+ /**
22
+ * The leaderboard page, in relation to `limit`.
23
+ */
24
+ page?: number;
23
25
  }
24
26
  /**
25
27
  * Gets a leaderboard, with all relevant items included.
28
+ *
26
29
  * `GetGameLeaderboard2` only includes Runs and Players, and has half the maximum `limit`.
27
30
  */
28
31
  export interface GetGameLeaderboard {
29
32
  /**
30
- * Filtering parameters.
33
+ * The leaderboard to fetch.
31
34
  */
32
35
  params: Interfaces.LeaderboardParams;
33
- /**
34
- * The leaderboard page, in relation to `limit`.
35
- */
36
- page?: number;
37
36
  /**
38
37
  * The limit of Runs per page.
39
- * Max: 200
38
+ *
39
+ * @max 200
40
40
  * @default 100
41
41
  */
42
42
  limit?: number;
43
+ /**
44
+ * The leaderboard page, in relation to `limit`.
45
+ */
46
+ page?: number;
43
47
  }
44
48
  /**
45
49
  * Gets mostly leaderboard-related data of a game.
50
+ *
46
51
  * Both parameters function the same. If both are included, `gameId` will override.
47
52
  */
48
53
  interface GetGameData_Base {
@@ -57,7 +62,8 @@ interface GetGameData_Base {
57
62
  }
58
63
  export type GetGameData = AtLeastOne<GetGameData_Base, 'gameId' | 'gameUrl'>;
59
64
  /**
60
- * Gets miscellaneous data of a game.
65
+ * Gets mostly miscellaneous data of a game.
66
+ *
61
67
  * Both parameters function the same. If both are included, `gameId` will override.
62
68
  */
63
69
  interface GetGameSummary_Base {
@@ -66,7 +72,7 @@ interface GetGameSummary_Base {
66
72
  */
67
73
  gameId?: string;
68
74
  /**
69
- * Game page URL.
75
+ * Subpath URL of the game.
70
76
  */
71
77
  gameUrl?: string;
72
78
  }
@@ -75,14 +81,63 @@ export type GetGameSummary = AtLeastOne<GetGameSummary_Base, 'gameId' | 'gameUrl
75
81
  * Gets the world record history of a game leaderboard.
76
82
  */
77
83
  export interface GetGameRecordHistory {
84
+ params?: {
85
+ /**
86
+ * ID of the leaderboard's category.
87
+ */
88
+ categoryId?: string;
89
+ /**
90
+ * `EmulatorFilter` to filter the leaderboard by.
91
+ */
92
+ emulator?: Enums.EmulatorFilter;
93
+ /**
94
+ * ID of the game. When exempted, the lists will be empty arrays.
95
+ */
96
+ gameId?: string;
97
+ /**
98
+ * `ObsoleteFilter` to filter the leaderboard by.
99
+ */
100
+ obsolete?: Enums.ObsoleteFilter;
101
+ /**
102
+ * IDs of platforms to filter the leaderboard by.
103
+ *
104
+ * All Platforms can be fetched with `GetPlatformList`.
105
+ */
106
+ platformIds?: string[];
107
+ /**
108
+ * IDs of regions to filter the leaderboard by.
109
+ *
110
+ * All Regions can be fetched with `GetStaticData.regionList`.
111
+ */
112
+ regionIds?: string[];
113
+ /**
114
+ * `TimingMethod` to filter the leaderboard by.
115
+ */
116
+ timer?: Enums.TimingMethod;
117
+ /**
118
+ * `RunStatus` to filter the leaderboard by.
119
+ */
120
+ verified?: Enums.RunStatus;
121
+ /**
122
+ * `VariableValues` to filter the leaderboard by.
123
+ */
124
+ values?: Interfaces.VariableValues[];
125
+ /**
126
+ * `VideoState` of runs to filter the leaderboard by.
127
+ */
128
+ video?: Enums.VideoState;
129
+ };
130
+ /**
131
+ * The limit of Runs per page.
132
+ *
133
+ * @max 200
134
+ * @default 100
135
+ */
136
+ limit?: number;
78
137
  /**
79
- * ID of the game. When exempted, both properties will be empty arrays.
138
+ * The leaderboard page, in relation to `limit`.
80
139
  */
81
- gameId?: string;
82
- categoryId?: string;
83
- values?: Interfaces.VariableValues[];
84
- emulator?: Enums.EmulatorFilter;
85
- obsolete?: Enums.ObsoleteFilter;
140
+ page?: number;
86
141
  }
87
142
  /**
88
143
  * Searches for site items with a query.
@@ -93,7 +148,7 @@ export interface GetSearch {
93
148
  */
94
149
  query?: string;
95
150
  /**
96
- * todo
151
+ * Useless parameter, there is no affect on what is fetched based on the value.
97
152
  */
98
153
  favorExactMatches?: boolean;
99
154
  /**
@@ -121,32 +176,47 @@ export interface GetSearch {
121
176
  */
122
177
  includeChallenges?: boolean;
123
178
  /**
124
- * The maximum amount of elements in each array.
179
+ * The maximum amount of items to fetch in each `[item]List` array.
180
+ *
181
+ * @max 100
125
182
  * @default 100
126
- * Max: 100
127
183
  */
128
184
  limit?: number;
185
+ /**
186
+ * The leaderboard page, in relation to `limit`.
187
+ */
188
+ page?: number;
129
189
  }
130
190
  /**
131
- * Gets non-obsolete latest runs.
191
+ * Gets non-obsolete latest runs of a game.
192
+ *
193
+ * When `seriesId` and `gameId` are exempted,
132
194
  */
133
195
  export interface GetLatestLeaderboard {
196
+ /**
197
+ * ID of the game.
198
+ *
199
+ * When exempted, lists in the responses will be empty.
200
+ */
134
201
  gameId?: string;
202
+ /**
203
+ * ID of a series
204
+ */
135
205
  seriesId?: string;
136
206
  /**
137
- * The maximum amount of `runs` there will be in the response.
207
+ * The maximum amount of Runs to fetch.
138
208
  *
139
209
  * Warning: Obsolete runs are not included, but still count to the limit.
140
210
  *
141
211
  * If this is `20` and 5 out of the 20 latest runs are obsolete, it will only return the 15 non-obsolete runs.
142
212
  *
213
+ * @max Around 99999, however it varies with caching-related factors.
143
214
  * @default 25
144
- * Max: 99999
145
215
  */
146
216
  limit?: number;
147
217
  }
148
218
  /**
149
- * Gets a run.
219
+ * Gets a single run.
150
220
  */
151
221
  export interface GetRun {
152
222
  /**
@@ -159,7 +229,7 @@ export interface GetRun {
159
229
  */
160
230
  export interface GetUserSummary {
161
231
  /**
162
- * Page URL of the user.
232
+ * Subpath URL of the user.
163
233
  */
164
234
  url: string;
165
235
  }
@@ -172,7 +242,13 @@ export interface GetUserComments {
172
242
  */
173
243
  userId: string;
174
244
  }
245
+ /**
246
+ * Gets threads created by a specific user.
247
+ */
175
248
  export interface GetUserThreads {
249
+ /**
250
+ * ID of the user.
251
+ */
176
252
  userId: string;
177
253
  }
178
254
  /**
@@ -190,7 +266,7 @@ export interface GetUserPopoverData {
190
266
  export interface GetTitleList {
191
267
  }
192
268
  /**
193
- * Gets a Title.
269
+ * Gets a specific Title.
194
270
  */
195
271
  export interface GetTitle {
196
272
  /**
@@ -199,7 +275,7 @@ export interface GetTitle {
199
275
  titleId: string;
200
276
  }
201
277
  /**
202
- * Gets articles on the site.
278
+ * Gets site articles.
203
279
  */
204
280
  export interface GetArticleList {
205
281
  /**
@@ -219,36 +295,63 @@ export interface GetArticleList {
219
295
  */
220
296
  tags?: string[];
221
297
  /**
222
- * The target of an article, either being `news` or a page URL for site information articles.
298
+ * The target of an article, either being `news` or a path URL for site information articles.
223
299
  */
224
300
  target?: string;
225
301
  /**
226
- * The maximum amount of articles included in the response.
302
+ * The maximum amount of Articles to fetch.
227
303
  *
304
+ * @max 500
228
305
  * @default 500
229
- * Max: 500
230
306
  */
231
307
  limit?: number;
308
+ /**
309
+ * The article list page, in relation to `limit`.
310
+ */
311
+ page?: number;
232
312
  }
233
313
  /**
234
- * Gets a specific article from the site.
314
+ * Gets a specific site article.
235
315
  */
236
316
  export interface GetArticle {
237
317
  id?: string;
238
318
  slug?: string;
239
319
  }
240
320
  /**
241
- * Gets a list of all games on the site.
321
+ * Gets a list of games.
242
322
  */
243
323
  export interface GetGameList {
324
+ /**
325
+ * ID of a series to filter by.
326
+ */
244
327
  seriesId?: string;
328
+ /**
329
+ * ID of a platform to filter by.
330
+ */
245
331
  platformId?: string;
332
+ /**
333
+ * Search query for game names or game subpath URLs.
334
+ */
246
335
  search?: string;
247
- orderType?: 1;
336
+ /**
337
+ * `GameOrderType` to filter games by.
338
+ */
339
+ orderType?: Enums.GameOrderType;
340
+ /**
341
+ * The maximum amount of Games to fetch.
342
+ *
343
+ * @max 500
344
+ * @default 500
345
+ */
248
346
  limit?: number;
249
347
  }
250
348
  /**
251
- * Gets information for the home page. Often empty.
349
+ * Gets a list of Platforms in the site.
350
+ */
351
+ export interface GetPlatformList {
352
+ }
353
+ /**
354
+ * Gets information for the home page.
252
355
  */
253
356
  export interface GetHomeSummary {
254
357
  }
@@ -256,40 +359,48 @@ export interface GetHomeSummary {
256
359
  * Gets a list of series on the site.
257
360
  */
258
361
  export interface GetSeriesList {
362
+ /**
363
+ * A query to search for, of series names or subpath URLs.
364
+ */
259
365
  search?: string;
260
- orderType?: 1;
366
+ orderType?: Enums.GameOrderType;
367
+ /**
368
+ * The maximum amount of Series to fetch.
369
+ *
370
+ * @max 500
371
+ * @default 500
372
+ */
261
373
  limit?: number;
262
374
  }
263
375
  /**
264
376
  * Gets most information pertinent to a series.
265
377
  */
266
378
  export interface GetSeriesSummary {
267
- seriesUrl?: string;
379
+ /**
380
+ * Subpath URL of the series.
381
+ */
382
+ seriesUrl: string;
268
383
  }
269
384
  /**
270
385
  * Gets the top 3 runs from all levels under a level category.
271
386
  */
272
387
  export interface GetGameLevelSummary {
273
- gameId: string;
274
- categoryId: string;
275
- dateFrom?: string;
276
- dateTo?: string;
277
- emulator?: Enums.EmulatorFilter;
278
388
  /**
279
- * If `categoryId: string` refers to a level category.
389
+ * The game leaderboard to fetch level summaries from.
390
+ *
391
+ * When not included, `runList[]` will be empty.
280
392
  */
281
- levelId?: string;
282
- obsolete?: Enums.ObsoleteFilter;
283
- platformId?: string;
284
- regionId?: string;
285
- timer?: Enums.TimingMethod;
393
+ params?: Interfaces.LeaderboardParams;
286
394
  /**
287
- * If runs other than verified should be included.
395
+ * The leaderboard page, in relation to `limit`.
288
396
  */
289
- verified?: Enums.RunStatus;
290
- values?: Interfaces.VariableValues[];
291
- video?: Enums.VideoFilter;
292
397
  page?: number;
398
+ /**
399
+ * The limit of Runs per page.
400
+ *
401
+ * @max Unknown - likely around 99999.
402
+ * @default Unknown - likely around 99999.
403
+ */
293
404
  limit?: number;
294
405
  }
295
406
  /**
@@ -301,24 +412,36 @@ export interface GetGameRandom {
301
412
  * Gets all guides on a game.
302
413
  */
303
414
  export interface GetGuideList {
415
+ /**
416
+ * ID of the game.
417
+ */
304
418
  gameId: string;
305
419
  }
306
420
  /**
307
- * Get a specific guide by id.
421
+ * Get a specific guide.
308
422
  */
309
423
  export interface GetGuide {
424
+ /**
425
+ * ID of the guide.
426
+ */
310
427
  id: string;
311
428
  }
312
429
  /**
313
- * Get a list of game news articles.
430
+ * Gets news posts in a game.
314
431
  */
315
432
  export interface GetNewsList {
433
+ /**
434
+ * ID of the game.
435
+ */
316
436
  gameId: string;
317
437
  }
318
438
  /**
319
- * Get a game news article.
439
+ * Gets a specific game news post.
320
440
  */
321
441
  export interface GetNews {
442
+ /**
443
+ * ID of the news post.
444
+ */
322
445
  id: string;
323
446
  }
324
447
  /**
@@ -328,22 +451,36 @@ export interface GetResourceList {
328
451
  gameId: string;
329
452
  }
330
453
  /**
331
- * Gets a list of live runners.
454
+ * Gets a list of live streams on twitch that have the `Speedrun` tag.
455
+ *
456
+ * A stream is assigned to a game when the Twitch game is the Game's `GameSettings.twitchName`.
332
457
  */
333
458
  export interface GetStreamList {
459
+ /**
460
+ * ID of a series.
461
+ */
334
462
  seriesId?: string;
463
+ /**
464
+ * ID of a game.
465
+ */
335
466
  gameId?: string;
336
467
  }
337
468
  /**
338
469
  * Get threads on a forum.
339
470
  */
340
471
  export interface GetThreadList {
472
+ /**
473
+ * ID of the forum.
474
+ */
341
475
  forumId: string;
342
476
  }
343
477
  /**
344
- * Gets a comment post's Thread and Forum.
478
+ * Gets a comment post's Thread and Forum by `commentId`.
345
479
  */
346
480
  export interface GetThreadStateByCommentId {
481
+ /**
482
+ * ID of the comment.
483
+ */
347
484
  commentId: string;
348
485
  }
349
486
  /**
@@ -356,6 +493,9 @@ export interface GetChallenge {
356
493
  * Get runs from a Challenge board.
357
494
  */
358
495
  export interface GetChallengeLeaderboard {
496
+ /**
497
+ * ID of the challenge you are getting the leaderboard from.
498
+ */
359
499
  challengeId: string;
360
500
  }
361
501
  /**
@@ -367,18 +507,27 @@ export interface GetChallengeGlobalRankingList {
367
507
  * Get a specific Challenge run (not the same as a normal run!)
368
508
  */
369
509
  export interface GetChallengeRun {
510
+ /**
511
+ * ID of the challenge.
512
+ */
370
513
  id: string;
371
514
  }
372
515
  /**
373
516
  * Get a user's runs for display on their profile.
374
517
  */
375
518
  export interface GetUserLeaderboard {
519
+ /**
520
+ * ID of the user.
521
+ */
376
522
  userId: string;
377
523
  }
378
524
  /**
379
525
  * Gets game and series moderation stats for any user.
380
526
  */
381
527
  export interface GetUserModeration {
528
+ /**
529
+ * ID of the user.
530
+ */
382
531
  userId: string;
383
532
  }
384
533
  /**
@@ -387,7 +536,7 @@ export interface GetUserModeration {
387
536
  export interface GetCommentList {
388
537
  itemId: string;
389
538
  /**
390
- * ItemType of the above `itemId: string;`
539
+ * `ItemType` of the item referenced in `itemId`.
391
540
  */
392
541
  itemType: Enums.ItemType;
393
542
  }
@@ -395,10 +544,13 @@ export interface GetCommentList {
395
544
  * Get a specific thread.
396
545
  */
397
546
  export interface GetThread {
547
+ /**
548
+ * ID of the thread.
549
+ */
398
550
  id: string;
399
551
  }
400
552
  /**
401
- * Get static data for the site. Including all areas, colors, gameTypes, platforms, etc.
553
+ * Get static data for the site.
402
554
  */
403
555
  export interface GetStaticData {
404
556
  }