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