From 32101ec9ebc7ff155e711b75bf2f1b52fdcf32f7 Mon Sep 17 00:00:00 2001 From: Jacob Date: Mon, 12 Aug 2024 09:23:09 +0800 Subject: [PATCH] API Return Types --- .editorconfig | 12 ++++++++++++ .vscode/extensions.json | 9 +++++++++ src/API/getAchievements.ts | 2 +- src/API/getActiveHouses.ts | 2 +- src/API/getBoosters.ts | 2 +- src/API/getChallenges.ts | 2 +- src/API/getGameCounts.ts | 2 +- src/API/getGuild.ts | 2 +- src/API/getGuildAchievements.ts | 2 +- src/API/getHouse.ts | 2 +- src/API/getLeaderboards.ts | 2 +- src/API/getPlayer.ts | 2 +- src/API/getPlayerHouses.ts | 2 +- src/API/getQuests.ts | 2 +- src/API/getRecentGames.ts | 2 +- src/API/getSkyblockAuction.ts | 6 +++++- src/API/getSkyblockAuctionsByPlayer.ts | 2 +- src/API/getSkyblockBazaar.ts | 2 +- src/API/getSkyblockBingo.ts | 2 +- src/API/getSkyblockBingoByPlayer.ts | 2 +- src/API/getSkyblockEndedAuctions.ts | 2 +- src/API/getSkyblockFireSales.ts | 2 +- src/API/getSkyblockGarden.ts | 2 +- src/API/getSkyblockGovernment.ts | 2 +- src/API/getSkyblockMember.ts | 2 +- src/API/getSkyblockMuseum.ts | 2 +- src/API/getSkyblockNews.ts | 2 +- src/API/getSkyblockProfiles.ts | 2 +- src/API/getWatchdogStats.ts | 2 +- src/Client.ts | 5 ++++- 30 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 .editorconfig create mode 100644 .vscode/extensions.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..88bf97c5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = crlf +charset = utf-8 +trim_trailing_whitespace = false +insert_final_newline = false \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..714920c9 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,9 @@ +{ + "recommendations": [ + "editorconfig.editorconfig", + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode", + "eamodio.gitlens", + "aaron-bond.better-comments" + ] +} \ No newline at end of file diff --git a/src/API/getAchievements.ts b/src/API/getAchievements.ts index 97fc6ec4..3487ba37 100644 --- a/src/API/getAchievements.ts +++ b/src/API/getAchievements.ts @@ -9,7 +9,7 @@ export default class getAchievements extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/resources/achievements'); if (res.raw) return res; return new Achievements(res); diff --git a/src/API/getActiveHouses.ts b/src/API/getActiveHouses.ts index 3ded977d..bd467b39 100644 --- a/src/API/getActiveHouses.ts +++ b/src/API/getActiveHouses.ts @@ -9,7 +9,7 @@ export default class getActiveHouses extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/housing/active'); if (res.raw) return res; return res.length ? res.map((b: any) => new House(b)) : []; diff --git a/src/API/getBoosters.ts b/src/API/getBoosters.ts index 61ad7539..2d43f5a4 100644 --- a/src/API/getBoosters.ts +++ b/src/API/getBoosters.ts @@ -9,7 +9,7 @@ export default class getBoosters extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/boosters'); if (res.raw) return res; return res.boosters.length ? res.boosters.map((b: any) => new Booster(b)).reverse() : []; diff --git a/src/API/getChallenges.ts b/src/API/getChallenges.ts index 60fe1ad9..ca8c4056 100644 --- a/src/API/getChallenges.ts +++ b/src/API/getChallenges.ts @@ -9,7 +9,7 @@ export default class getChallenges extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/resources/challenges'); if (res.raw) return res; return new Challenges(res); diff --git a/src/API/getGameCounts.ts b/src/API/getGameCounts.ts index db9250db..ac69205a 100644 --- a/src/API/getGameCounts.ts +++ b/src/API/getGameCounts.ts @@ -9,7 +9,7 @@ export default class getGameCounts extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/counts'); if (res.raw) return res; return new GameCounts(res); diff --git a/src/API/getGuild.ts b/src/API/getGuild.ts index 4cbd474f..15c5cec8 100644 --- a/src/API/getGuild.ts +++ b/src/API/getGuild.ts @@ -12,7 +12,7 @@ export default class getGuild extends Endpoint { this.client = client; } - async execute(searchParameter: 'id' | 'name' | 'player', query: string) { + async execute(searchParameter: 'id' | 'name' | 'player', query: string): Promise { if (!query) throw new Error(Errors.NO_GUILD_QUERY); if ('id' === searchParameter && !isGuildID(query)) throw new Error(Errors.INVALID_GUILD_ID); const isPlayerQuery = 'player' === searchParameter; diff --git a/src/API/getGuildAchievements.ts b/src/API/getGuildAchievements.ts index 1abb178b..5b4b40eb 100644 --- a/src/API/getGuildAchievements.ts +++ b/src/API/getGuildAchievements.ts @@ -9,7 +9,7 @@ export default class getGuildAchievements extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/resources/guilds/achievements'); if (res.raw) return res; return new GuildAchievements(res); diff --git a/src/API/getHouse.ts b/src/API/getHouse.ts index 9e0dec4b..1e7fabc5 100644 --- a/src/API/getHouse.ts +++ b/src/API/getHouse.ts @@ -10,7 +10,7 @@ export default class getHouse extends Endpoint { this.client = client; } - async execute(query: string) { + async execute(query: string): Promise { if (!query) throw new Error(Errors.NO_UUID); const res = await this.client.requests.request(`/housing/house?house=${query}`); if (res.raw) return res; diff --git a/src/API/getLeaderboards.ts b/src/API/getLeaderboards.ts index 4a320ccb..11f757ca 100644 --- a/src/API/getLeaderboards.ts +++ b/src/API/getLeaderboards.ts @@ -11,7 +11,7 @@ export default class getLeaderboards extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/leaderboards'); if (res.raw) return res; if (!res.leaderboards) throw new Error(Errors.SOMETHING_WENT_WRONG.replace(/{cause}/, 'Try again.')); diff --git a/src/API/getPlayer.ts b/src/API/getPlayer.ts index e038634e..2651af23 100644 --- a/src/API/getPlayer.ts +++ b/src/API/getPlayer.ts @@ -11,7 +11,7 @@ export default class getPlayer extends Endpoint { this.client = client; } - async execute(query: string) { + async execute(query: string): Promise { if (!query) throw new Error(Errors.NO_NICKNAME_UUID); query = await toUuid(query); const res = await this.client.requests.request(`/player?uuid=${query}`); diff --git a/src/API/getPlayerHouses.ts b/src/API/getPlayerHouses.ts index e245c604..fa8cd275 100644 --- a/src/API/getPlayerHouses.ts +++ b/src/API/getPlayerHouses.ts @@ -11,7 +11,7 @@ export default class getPlayerHouses extends Endpoint { this.client = client; } - async execute(query: string): Promise { + async execute(query: string): Promise { if (!query) throw new Error(Errors.NO_NICKNAME_UUID); query = await toUuid(query); const res = await this.client.requests.request(`/housing/houses?player=${query}`); diff --git a/src/API/getQuests.ts b/src/API/getQuests.ts index 70c476c9..b3a09e18 100644 --- a/src/API/getQuests.ts +++ b/src/API/getQuests.ts @@ -9,7 +9,7 @@ export default class getQuests extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/resources/quests'); if (res.raw) return res; return new Quests(res); diff --git a/src/API/getRecentGames.ts b/src/API/getRecentGames.ts index 7ad3b716..6ea63eb7 100644 --- a/src/API/getRecentGames.ts +++ b/src/API/getRecentGames.ts @@ -11,7 +11,7 @@ export default class getRecentGames extends Endpoint { this.client = client; } - async execute(query: string) { + async execute(query: string): Promise { if (!query) throw new Error(Errors.NO_NICKNAME_UUID); query = await toUuid(query); const res = await this.client.requests.request(`/recentgames?uuid=${query}`); diff --git a/src/API/getSkyblockAuction.ts b/src/API/getSkyblockAuction.ts index b6d01da1..e7c9a735 100644 --- a/src/API/getSkyblockAuction.ts +++ b/src/API/getSkyblockAuction.ts @@ -11,7 +11,11 @@ export default class getSkyblockAction extends Endpoint { this.client = client; } - async execute(query: string, type: 'PROFILE' | 'PLAYER' | 'AUCTION', includeItemBytes: boolean = false) { + async execute( + query: string, + type: 'PROFILE' | 'PLAYER' | 'AUCTION', + includeItemBytes: boolean = false + ): Promise { if (!query) throw new Error(Errors.NO_NICKNAME_UUID); let filter; if ('PROFILE' === type) { diff --git a/src/API/getSkyblockAuctionsByPlayer.ts b/src/API/getSkyblockAuctionsByPlayer.ts index 82d797cd..7939cf6f 100644 --- a/src/API/getSkyblockAuctionsByPlayer.ts +++ b/src/API/getSkyblockAuctionsByPlayer.ts @@ -11,7 +11,7 @@ export default class getSkyblockActionsByPlayer extends Endpoint { this.client = client; } - async execute(query: string, includeItemBytes: boolean) { + async execute(query: string, includeItemBytes: boolean): Promise { if (!query) throw new Error(Errors.NO_NICKNAME_UUID); query = await toUuid(query); const res = await this.client.requests.request(`/skyblock/auction?player=${query}`); diff --git a/src/API/getSkyblockBazaar.ts b/src/API/getSkyblockBazaar.ts index 28e6b52d..b360560a 100644 --- a/src/API/getSkyblockBazaar.ts +++ b/src/API/getSkyblockBazaar.ts @@ -9,7 +9,7 @@ export default class getSkyblockBazaar extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/skyblock/bazaar'); if (res.raw) return res; const productsKeys = Object.keys(res.products); diff --git a/src/API/getSkyblockBingo.ts b/src/API/getSkyblockBingo.ts index 4e17f773..b52a5896 100644 --- a/src/API/getSkyblockBingo.ts +++ b/src/API/getSkyblockBingo.ts @@ -9,7 +9,7 @@ export default class getSkyblockBingo extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/resources/skyblock/bingo'); if (res.raw) return res; return new BingoData(res); diff --git a/src/API/getSkyblockBingoByPlayer.ts b/src/API/getSkyblockBingoByPlayer.ts index 03c071f6..421d4434 100644 --- a/src/API/getSkyblockBingoByPlayer.ts +++ b/src/API/getSkyblockBingoByPlayer.ts @@ -11,7 +11,7 @@ export default class getBingoByPlayer extends Endpoint { this.client = client; } - async execute(query: string) { + async execute(query: string): Promise { if (!query) throw new Error(Errors.NO_NICKNAME_UUID); query = await toUuid(query); const res = await this.client.requests.request(`/skyblock/uuid?player=${query}`); diff --git a/src/API/getSkyblockEndedAuctions.ts b/src/API/getSkyblockEndedAuctions.ts index e5b59519..29161131 100644 --- a/src/API/getSkyblockEndedAuctions.ts +++ b/src/API/getSkyblockEndedAuctions.ts @@ -10,7 +10,7 @@ export default class getSkyblockEndedAuctions extends Endpoint { this.client = client; } - async execute(includeItemBytes: any): Promise { + async execute(includeItemBytes: any): Promise<{ info: AuctionInfo; auctions: PartialAuction[] }> { const res = await this.client.requests.request('/skyblock/auctions_ended'); if (res.raw) return res; return { diff --git a/src/API/getSkyblockFireSales.ts b/src/API/getSkyblockFireSales.ts index 43ed4275..d1fe0151 100644 --- a/src/API/getSkyblockFireSales.ts +++ b/src/API/getSkyblockFireSales.ts @@ -9,7 +9,7 @@ export default class getSkyblockFireSales extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/skyblock/firesales'); if (res.raw) return res; return res.sales.length ? res.sales.map((a: any) => new FireSale(a)) : []; diff --git a/src/API/getSkyblockGarden.ts b/src/API/getSkyblockGarden.ts index 40c3022b..19debbd2 100644 --- a/src/API/getSkyblockGarden.ts +++ b/src/API/getSkyblockGarden.ts @@ -9,7 +9,7 @@ export default class getSkyblockGarden extends Endpoint { this.client = client; } - async execute(profileId: string) { + async execute(profileId: string): Promise { const res = await this.client.requests.request(`/skyblock/garden?profile=${profileId}`); if (res.raw) return res; return new SkyblockGarden(res); diff --git a/src/API/getSkyblockGovernment.ts b/src/API/getSkyblockGovernment.ts index ebd6fc3e..2bd24434 100644 --- a/src/API/getSkyblockGovernment.ts +++ b/src/API/getSkyblockGovernment.ts @@ -9,7 +9,7 @@ export default class getSkyblockGovernment extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/resources/skyblock/election'); if (res.raw) return res; return new GovernmentData(res); diff --git a/src/API/getSkyblockMember.ts b/src/API/getSkyblockMember.ts index c39f8264..efa813b0 100644 --- a/src/API/getSkyblockMember.ts +++ b/src/API/getSkyblockMember.ts @@ -11,7 +11,7 @@ export default class getSkyblockMember extends Endpoint { this.client = client; } - async execute(query: string) { + async execute(query: string): Promise> { if (!query) throw new Error(Errors.NO_NICKNAME_UUID); query = await toUuid(query); const res = await this.client.requests.request(`/skyblock/profiles?uuid=${query}`); diff --git a/src/API/getSkyblockMuseum.ts b/src/API/getSkyblockMuseum.ts index 0f6889c5..b2633521 100644 --- a/src/API/getSkyblockMuseum.ts +++ b/src/API/getSkyblockMuseum.ts @@ -11,7 +11,7 @@ export default class getSkyblockMuseum extends Endpoint { this.client = client; } - async execute(query: string, profileId: string) { + async execute(query: string, profileId: string): Promise { if (!query) throw new Error(Errors.NO_NICKNAME_UUID); query = await toUuid(query); const res = await this.client.requests.request(`/skyblock/museum?uuid=${query}&profile=${profileId}`); diff --git a/src/API/getSkyblockNews.ts b/src/API/getSkyblockNews.ts index 4b56b3f5..2692ae78 100644 --- a/src/API/getSkyblockNews.ts +++ b/src/API/getSkyblockNews.ts @@ -9,7 +9,7 @@ export default class getSkyblockNews extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/skyblock/news'); if (res.raw) return res; return res.items.map((i: any) => new SkyblockNews(i)); diff --git a/src/API/getSkyblockProfiles.ts b/src/API/getSkyblockProfiles.ts index 77427004..d524ff11 100644 --- a/src/API/getSkyblockProfiles.ts +++ b/src/API/getSkyblockProfiles.ts @@ -10,7 +10,7 @@ export default class getSkyblockProfiles extends Endpoint { this.client = client; } - async execute(query: string) { + async execute(query: string): Promise { if (!query) throw new Error(Errors.NO_NICKNAME_UUID); query = await toUuid(query); const res = await this.client.requests.request(`/skyblock/profiles?uuid=${query}`); diff --git a/src/API/getWatchdogStats.ts b/src/API/getWatchdogStats.ts index 780d744f..2e42c809 100644 --- a/src/API/getWatchdogStats.ts +++ b/src/API/getWatchdogStats.ts @@ -9,7 +9,7 @@ export default class getWatchdogStatsEndpoint extends Endpoint { this.client = client; } - async execute() { + async execute(): Promise { const res = await this.client.requests.request('/punishmentstats'); if (res.raw) return res; return new WatchdogStats(res); diff --git a/src/Client.ts b/src/Client.ts index 0f4acb53..55ef4a28 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -20,7 +20,6 @@ class Client { declare rateLimit?: 'AUTO' | 'HARD' | 'NONE'; declare silent: boolean; declare checkForUpdates: boolean; - declare endpoints: any; constructor(key: string, options?: ClientOptions) { this.key = key; @@ -37,7 +36,11 @@ class Client { this.cacheHandler = new CacheHandler(this); for (const func in API) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error const endpoint = new API[func](this); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error this[func] = endpoint.execute.bind(endpoint); }