diff --git a/src/index.ts b/src/index.ts index 2ecc5ff..1a11d85 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,18 @@ export const API_ENDPOINT = "https://api.mcutils.xyz"; +// Methods export * from "./lib/mojang"; export * from "./lib/player"; export * from "./lib/server"; + +// Types +export * from "./types/cache"; +export * from "./types/error"; +export * from "./types/player/player"; +export * from "./types/player/usernameToUuid"; +export * from "./types/server/blocked-status"; +export * from "./types/server/platform"; +export * from "./types/server/platform/bedrock-server"; +export * from "./types/server/platform/java-server"; +export * from "./types/server/server"; +export * from "./types/status"; diff --git a/src/lib/mojang.ts b/src/lib/mojang.ts index c305594..6ac441d 100644 --- a/src/lib/mojang.ts +++ b/src/lib/mojang.ts @@ -1,6 +1,6 @@ +import { CachedEndpointStatus } from "types/mojang/endpoint-status"; import { API_ENDPOINT } from ".."; import WebRequest from "../common/WebRequest"; -import { CachedEndpointStatus } from "../types/cache/cachedEndpointStatus"; const endpointStatusEndpoint = API_ENDPOINT + "/mojang/status"; diff --git a/src/lib/player.ts b/src/lib/player.ts index 922f952..7b67f6e 100644 --- a/src/lib/player.ts +++ b/src/lib/player.ts @@ -1,7 +1,5 @@ -import { API_ENDPOINT } from ".."; +import { API_ENDPOINT, CachedPlayer, CachedUsernameToUuid } from ".."; import WebRequest from "../common/WebRequest"; -import { CachedPlayer } from "../types/cache/cachedPlayer"; -import { CachedUsernameToUuid } from "../types/cache/cachedUsernameToUuid"; const playerEndpoint = API_ENDPOINT + "/player/{id}"; const playerUsernameToUuidEndpoint = API_ENDPOINT + "/player/uuid/{id}"; diff --git a/src/lib/server.ts b/src/lib/server.ts index 62781fa..6b04905 100644 --- a/src/lib/server.ts +++ b/src/lib/server.ts @@ -1,7 +1,6 @@ -import { API_ENDPOINT } from ".."; +import { API_ENDPOINT, CachedBedrockMinecraftServer, CachedJavaMinecraftServer } from ".."; import WebRequest from "../common/WebRequest"; -import { CachedMinecraftServer } from "../types/cache/cachedMinecraftServer"; -import { BlockedStatus } from "../types/server/blockedStatus"; +import { BlockedStatus } from "../types/server/blocked-status"; import { ServerPlatform } from "../types/server/platform"; const serverEndpoint = API_ENDPOINT + "/server/{platform}/{hostname}"; @@ -16,9 +15,13 @@ const blockedServerEndpoint = API_ENDPOINT + "/server/blocked/{hostname}"; * @param port the port of the server * @returns the server information, or null if the server does not exist */ -export function getServer(platform: ServerPlatform, hostname: string, port?: 25565): Promise { +export function getServer( + platform: ServerPlatform, + hostname: string, + port?: 25565 +): Promise { const ip = port ? `${hostname}:${port}` : hostname; - return WebRequest.get( + return WebRequest.get( serverEndpoint.replace("{platform}", platform).replace("{hostname}", ip) ); } diff --git a/src/types/cache/cache.ts b/src/types/cache.ts similarity index 100% rename from src/types/cache/cache.ts rename to src/types/cache.ts diff --git a/src/types/cache/cachedMinecraftServer.ts b/src/types/cache/cachedMinecraftServer.ts deleted file mode 100644 index b33dca2..0000000 --- a/src/types/cache/cachedMinecraftServer.ts +++ /dev/null @@ -1,10 +0,0 @@ -import BedrockMinecraftServer from "../server/bedrockServer"; -import JavaMinecraftServer from "../server/javaServer"; -import { Cache } from "./cache"; - -export interface CachedMinecraftServer extends Cache { - /** - * The cached server. - */ - server: JavaMinecraftServer | BedrockMinecraftServer; -} diff --git a/src/types/cache/cachedPlayer.ts b/src/types/cache/cachedPlayer.ts deleted file mode 100644 index a661b95..0000000 --- a/src/types/cache/cachedPlayer.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Player } from "../player/player"; - -export interface CachedPlayer extends Cache { - /** - * The cached player. - */ - player: Player; -} diff --git a/src/types/cache/cachedUsernameToUuid.ts b/src/types/cache/cachedUsernameToUuid.ts deleted file mode 100644 index b9c9389..0000000 --- a/src/types/cache/cachedUsernameToUuid.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { UsernameToUuid } from "../player/usernameToUuid"; - -export interface CachedUsernameToUuid extends Cache, UsernameToUuid {} diff --git a/src/types/mojang/endpoint-status.ts b/src/types/mojang/endpoint-status.ts new file mode 100644 index 0000000..1bbc4ff --- /dev/null +++ b/src/types/mojang/endpoint-status.ts @@ -0,0 +1,10 @@ +import { Status } from "../status"; + +export interface CachedEndpointStatus extends Cache, EndpointStatus {} + +export type EndpointStatus = { + /** + * The cached endpoint status. + */ + endpoints: Record; +}; diff --git a/src/types/player/player.ts b/src/types/player/player.ts index e985f71..dc91507 100644 --- a/src/types/player/player.ts +++ b/src/types/player/player.ts @@ -1,4 +1,6 @@ -export type Player = { +export interface CachedPlayer extends Cache, Player {} + +type Player = { /** * The player's unique id. */ diff --git a/src/types/player/usernameToUuid.ts b/src/types/player/usernameToUuid.ts index ce06dc7..a3732e8 100644 --- a/src/types/player/usernameToUuid.ts +++ b/src/types/player/usernameToUuid.ts @@ -1,4 +1,6 @@ -export type UsernameToUuid = { +export interface CachedUsernameToUuid extends Cache, UsernameToUuid {} + +type UsernameToUuid = { /** * The username of the player. */ diff --git a/src/types/server/blockedStatus.ts b/src/types/server/blocked-status.ts similarity index 100% rename from src/types/server/blockedStatus.ts rename to src/types/server/blocked-status.ts diff --git a/src/types/server/bedrockServer.ts b/src/types/server/platform/bedrock-server.ts similarity index 84% rename from src/types/server/bedrockServer.ts rename to src/types/server/platform/bedrock-server.ts index 1e4dc59..2892049 100644 --- a/src/types/server/bedrockServer.ts +++ b/src/types/server/platform/bedrock-server.ts @@ -1,4 +1,6 @@ -import { MinecraftServer } from "./server"; +import { MinecraftServer } from "../server"; + +export interface CachedBedrockMinecraftServer extends Cache, BedrockMinecraftServer {} export default interface BedrockMinecraftServer extends MinecraftServer { /** diff --git a/src/types/server/javaServer.ts b/src/types/server/platform/java-server.ts similarity index 88% rename from src/types/server/javaServer.ts rename to src/types/server/platform/java-server.ts index c69e97c..36558cc 100644 --- a/src/types/server/javaServer.ts +++ b/src/types/server/platform/java-server.ts @@ -1,4 +1,6 @@ -import { MinecraftServer } from "./server"; +import { MinecraftServer } from "../server"; + +export interface CachedJavaMinecraftServer extends Cache, JavaMinecraftServer {} export default interface JavaMinecraftServer extends MinecraftServer { /** diff --git a/src/types/cache/cachedEndpointStatus.ts b/src/types/status.ts similarity index 64% rename from src/types/cache/cachedEndpointStatus.ts rename to src/types/status.ts index 1e7547f..a4ec9b3 100644 --- a/src/types/cache/cachedEndpointStatus.ts +++ b/src/types/status.ts @@ -1,11 +1,4 @@ -export interface CachedEndpointStatus extends Cache { - /** - * The cached endpoint status. - */ - endpoints: Record; -} - -enum Status { +export enum Status { /** * The service is online and operational. */ diff --git a/tsconfig.json b/tsconfig.json index 22cf311..b572c13 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,12 @@ "module": "commonjs", "target": "ES2020", "declaration": true, - "outDir": "./dist" + "outDir": "./dist", + "baseUrl": "./src", + "paths": { + "@/*": ["src/*"], + "@types/*": ["src/types/*"] + } }, "include": ["src/**/*"] }