Skip to content

Commit

Permalink
API Return Types
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathund committed Aug 12, 2024
1 parent ea6e546 commit 32101ec
Show file tree
Hide file tree
Showing 30 changed files with 56 additions and 28 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"eamodio.gitlens",
"aaron-bond.better-comments"
]
}
2 changes: 1 addition & 1 deletion src/API/getAchievements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getAchievements extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<Achievements> {
const res = await this.client.requests.request('/resources/achievements');
if (res.raw) return res;
return new Achievements(res);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getActiveHouses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getActiveHouses extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<House[]> {
const res = await this.client.requests.request('/housing/active');
if (res.raw) return res;
return res.length ? res.map((b: any) => new House(b)) : [];
Expand Down
2 changes: 1 addition & 1 deletion src/API/getBoosters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getBoosters extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<Booster[]> {
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() : [];
Expand Down
2 changes: 1 addition & 1 deletion src/API/getChallenges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getChallenges extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<Challenges> {
const res = await this.client.requests.request('/resources/challenges');
if (res.raw) return res;
return new Challenges(res);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getGameCounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getGameCounts extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<GameCounts> {
const res = await this.client.requests.request('/counts');
if (res.raw) return res;
return new GameCounts(res);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getGuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Guild | null> {
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;
Expand Down
2 changes: 1 addition & 1 deletion src/API/getGuildAchievements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getGuildAchievements extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<GuildAchievements> {
const res = await this.client.requests.request('/resources/guilds/achievements');
if (res.raw) return res;
return new GuildAchievements(res);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getHouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class getHouse extends Endpoint {
this.client = client;
}

async execute(query: string) {
async execute(query: string): Promise<House> {
if (!query) throw new Error(Errors.NO_UUID);
const res = await this.client.requests.request(`/housing/house?house=${query}`);
if (res.raw) return res;
Expand Down
2 changes: 1 addition & 1 deletion src/API/getLeaderboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class getLeaderboards extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<any> {
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.'));
Expand Down
2 changes: 1 addition & 1 deletion src/API/getPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class getPlayer extends Endpoint {
this.client = client;
}

async execute(query: string) {
async execute(query: string): Promise<Player> {
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
query = await toUuid(query);
const res = await this.client.requests.request(`/player?uuid=${query}`);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getPlayerHouses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class getPlayerHouses extends Endpoint {
this.client = client;
}

async execute(query: string): Promise<House[] | { raw: any }> {
async execute(query: string): Promise<House[]> {
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
query = await toUuid(query);
const res = await this.client.requests.request(`/housing/houses?player=${query}`);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getQuests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getQuests extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<Quests> {
const res = await this.client.requests.request('/resources/quests');
if (res.raw) return res;
return new Quests(res);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getRecentGames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class getRecentGames extends Endpoint {
this.client = client;
}

async execute(query: string) {
async execute(query: string): Promise<RecentGame[]> {
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
query = await toUuid(query);
const res = await this.client.requests.request(`/recentgames?uuid=${query}`);
Expand Down
6 changes: 5 additions & 1 deletion src/API/getSkyblockAuction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Auction[]> {
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
let filter;
if ('PROFILE' === type) {
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockAuctionsByPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Auction[]> {
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
query = await toUuid(query);
const res = await this.client.requests.request(`/skyblock/auction?player=${query}`);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockBazaar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getSkyblockBazaar extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<Product[]> {
const res = await this.client.requests.request('/skyblock/bazaar');
if (res.raw) return res;
const productsKeys = Object.keys(res.products);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockBingo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getSkyblockBingo extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<BingoData> {
const res = await this.client.requests.request('/resources/skyblock/bingo');
if (res.raw) return res;
return new BingoData(res);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockBingoByPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class getBingoByPlayer extends Endpoint {
this.client = client;
}

async execute(query: string) {
async execute(query: string): Promise<PlayerBingo> {
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
query = await toUuid(query);
const res = await this.client.requests.request(`/skyblock/uuid?player=${query}`);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockEndedAuctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class getSkyblockEndedAuctions extends Endpoint {
this.client = client;
}

async execute(includeItemBytes: any): Promise<any> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockFireSales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getSkyblockFireSales extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<FireSale[]> {
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)) : [];
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockGarden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getSkyblockGarden extends Endpoint {
this.client = client;
}

async execute(profileId: string) {
async execute(profileId: string): Promise<SkyblockGarden> {
const res = await this.client.requests.request(`/skyblock/garden?profile=${profileId}`);
if (res.raw) return res;
return new SkyblockGarden(res);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockGovernment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getSkyblockGovernment extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<GovernmentData> {
const res = await this.client.requests.request('/resources/skyblock/election');
if (res.raw) return res;
return new GovernmentData(res);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class getSkyblockMember extends Endpoint {
this.client = client;
}

async execute(query: string) {
async execute(query: string): Promise<Map<string, SkyblockMember>> {
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
query = await toUuid(query);
const res = await this.client.requests.request(`/skyblock/profiles?uuid=${query}`);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockMuseum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SkyblockMuseum> {
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}`);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockNews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getSkyblockNews extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<SkyblockNews[]> {
const res = await this.client.requests.request('/skyblock/news');
if (res.raw) return res;
return res.items.map((i: any) => new SkyblockNews(i));
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class getSkyblockProfiles extends Endpoint {
this.client = client;
}

async execute(query: string) {
async execute(query: string): Promise<SkyblockProfile[]> {
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
query = await toUuid(query);
const res = await this.client.requests.request(`/skyblock/profiles?uuid=${query}`);
Expand Down
2 changes: 1 addition & 1 deletion src/API/getWatchdogStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class getWatchdogStatsEndpoint extends Endpoint {
this.client = client;
}

async execute() {
async execute(): Promise<WatchdogStats> {
const res = await this.client.requests.request('/punishmentstats');
if (res.raw) return res;
return new WatchdogStats(res);
Expand Down
5 changes: 4 additions & 1 deletion src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down

0 comments on commit 32101ec

Please sign in to comment.