diff --git a/Lib/README.md b/Lib/README.md index e6ceac9..d711ebc 100644 --- a/Lib/README.md +++ b/Lib/README.md @@ -6,4 +6,9 @@ A simple, yet useful RESTful API for Minecraft utilizing Springboot. ## NPM View this package on the [NPM Registry](https://www.npmjs.com/package/restfulmc-lib). -![NPM Logo](https://avatars.githubusercontent.com/u/6078720?s=74) +### Installation +```bash +npm install restfulmc-lib +``` + +![NPM Logo](https://avatars.githubusercontent.com/u/6078720?s=74) \ No newline at end of file diff --git a/Lib/src/index.d.ts b/Lib/src/index.d.ts index dd0d3c1..f5b9bc2 100644 --- a/Lib/src/index.d.ts +++ b/Lib/src/index.d.ts @@ -1 +1,5 @@ +export * from "./types/dns"; +export * from "./types/generic"; +export * from "./types/mojang"; export * from "./types/player"; +export * from "./types/server"; diff --git a/Lib/src/index.ts b/Lib/src/index.ts index d0ed23a..cd141a2 100644 --- a/Lib/src/index.ts +++ b/Lib/src/index.ts @@ -1 +1 @@ -export * from "./lib/restfulmc"; +export * from "@/lib/restfulmc"; diff --git a/Lib/src/lib/restfulmc.ts b/Lib/src/lib/restfulmc.ts index de46679..1b21582 100644 --- a/Lib/src/lib/restfulmc.ts +++ b/Lib/src/lib/restfulmc.ts @@ -1,9 +1,9 @@ -import { MojangServerStatus } from "../types/mojang"; -import type { CachedPlayer } from "../types/player"; -import { Platform } from "../types/server"; -import { CachedBedrockMinecraftServer } from "../types/server/bedrock-server"; -import { CachedJavaMinecraftServer } from "../types/server/java-server"; -import { makeWebRequest } from "./webRequest"; +import { makeWebRequest } from "@/lib/webRequest"; +import { MojangServerStatus } from "@/types/mojang"; +import type { CachedPlayer } from "@/types/player"; +import { Platform } from "@/types/server"; +import { CachedBedrockMinecraftServer } from "@/types/server/bedrock-server"; +import { CachedJavaMinecraftServer } from "@/types/server/java-server"; /** * Get a player by their username or UUID. diff --git a/Lib/src/lib/webRequest.ts b/Lib/src/lib/webRequest.ts index fb186cb..7ff68c6 100644 --- a/Lib/src/lib/webRequest.ts +++ b/Lib/src/lib/webRequest.ts @@ -1,4 +1,4 @@ -import { ErrorResponse } from "../types/generic"; +import { ErrorResponse } from "@/types/generic"; const ENDPOINT = "https://mc.rainnny.club"; // The API endpoint to use diff --git a/Lib/src/types/dns.d.ts b/Lib/src/types/dns.d.ts index 27ee19d..d08e28a 100644 --- a/Lib/src/types/dns.d.ts +++ b/Lib/src/types/dns.d.ts @@ -1,7 +1,7 @@ /** * An A record. */ -interface ARecord extends DNSRecord { +export interface ARecord extends DNSRecord { /** * The address of this record, undefined if unresolved. */ @@ -11,7 +11,7 @@ interface ARecord extends DNSRecord { /** * An SRV record. */ -interface SRVRecord extends DNSRecord { +export interface SRVRecord extends DNSRecord { /** * The priority of this record. */ @@ -36,7 +36,7 @@ interface SRVRecord extends DNSRecord { /** * A representation of a DNS record. */ -type DNSRecord = { +export type DNSRecord = { /** * The type of this record. */ diff --git a/Lib/src/types/player.d.ts b/Lib/src/types/player.d.ts index 36261e7..95e84a5 100644 --- a/Lib/src/types/player.d.ts +++ b/Lib/src/types/player.d.ts @@ -12,7 +12,7 @@ export interface CachedPlayer extends Player { /** * A Minecraft player. */ -type Player = { +export type Player = { /** * The unique id of this player. */ @@ -57,7 +57,7 @@ type Player = { /** * A skin for a {@link Player}. */ -type Skin = { +export type Skin = { /** * The texture URL of this skin. */ @@ -88,12 +88,12 @@ type Skin = { /** * Possible models for a skin. */ -type SkinModel = "default" | "slim"; +export type SkinModel = "default" | "slim"; /** * A cape for a {@link Player}. */ -type Cape = { +export type Cape = { /** * The texture URL of this cape. */ @@ -103,7 +103,7 @@ type Cape = { /** * A property of a Mojang profile. */ -type ProfileProperty = { +export type ProfileProperty = { /** * The name of this property. */ @@ -124,4 +124,4 @@ type ProfileProperty = { /** * Profile actions that can */ -type ProfileAction = "FORCED_NAME_CHANGE" | "USING_BANNED_SKIN"; +export type ProfileAction = "FORCED_NAME_CHANGE" | "USING_BANNED_SKIN"; diff --git a/Lib/src/types/server.d.ts b/Lib/src/types/server.d.ts index 4381fa6..6034030 100644 --- a/Lib/src/types/server.d.ts +++ b/Lib/src/types/server.d.ts @@ -1,7 +1,7 @@ /** * A model representing a Minecraft server. */ -type MinecraftServer = { +export type MinecraftServer = { /** * The hostname of this server. */ @@ -36,7 +36,7 @@ type MinecraftServer = { /** * Player count data for a server. */ -type Players = { +export type Players = { /** * The online players on this server. */ @@ -56,7 +56,7 @@ type Players = { /** * A sample player. */ -type PlayerSample = { +export type PlayerSample = { /** * The ID of this player. */ @@ -71,7 +71,7 @@ type PlayerSample = { /** * The name of a sample player. */ -type PlayerSampleName = { +export type PlayerSampleName = { /** * The raw name. */ @@ -91,7 +91,7 @@ type PlayerSampleName = { /** * The MOTD for a server. */ -type MOTD = { +export type MOTD = { /** * The raw MOTD lines. */ @@ -117,4 +117,4 @@ export type Platform = "java" | "bedrock"; /** * Types of a DNS record. */ -type RecordType = "A" | "SRV"; +export type RecordType = "A" | "SRV"; diff --git a/Lib/src/types/server/bedrock-server.d.ts b/Lib/src/types/server/bedrock-server.d.ts index 7136e8a..ea966df 100644 --- a/Lib/src/types/server/bedrock-server.d.ts +++ b/Lib/src/types/server/bedrock-server.d.ts @@ -1,4 +1,4 @@ -import { MinecraftServer } from "../server"; +import { MinecraftServer } from "@/types/server"; /** * A cacheable {@link BedrockMinecraftServer}. @@ -14,7 +14,7 @@ export interface CachedBedrockMinecraftServer extends BedrockMinecraftServer { /** * A Bedrock edition {@link MinecraftServer}. */ -interface BedrockMinecraftServer extends MinecraftServer { +export interface BedrockMinecraftServer extends MinecraftServer { /** * The ID of this server. */ @@ -39,12 +39,12 @@ interface BedrockMinecraftServer extends MinecraftServer { /** * The edition of a Bedrock server. */ -type Edition = "MCPE" | "MCEE"; +export type Edition = "MCPE" | "MCEE"; /** * Version information for a server. */ -type Version = { +export type Version = { /** * The protocol version of the server. */ @@ -59,7 +59,7 @@ type Version = { /** * The gamemode of a server. */ -type GameMode = { +export type GameMode = { /** * The name of this gamemode. */ diff --git a/Lib/src/types/server/java-server.d.ts b/Lib/src/types/server/java-server.d.ts index 080951f..69d0bf1 100644 --- a/Lib/src/types/server/java-server.d.ts +++ b/Lib/src/types/server/java-server.d.ts @@ -1,4 +1,4 @@ -import { MinecraftServer } from "../server"; +import { MinecraftServer } from "@/types/server"; /** * A cacheable {@link JavaMinecraftServer}. @@ -14,7 +14,7 @@ export interface CachedJavaMinecraftServer extends JavaMinecraftServer { /** * A Java edition {@link MinecraftServer}. */ -interface JavaMinecraftServer extends MinecraftServer { +export interface JavaMinecraftServer extends MinecraftServer { /** * The version information of this server. */ @@ -70,7 +70,7 @@ interface JavaMinecraftServer extends MinecraftServer { /** * Version information for a server. */ -type Version = { +export type Version = { /** * The version name of the server. */ @@ -100,7 +100,7 @@ type Version = { /** * The favicon for a server. */ -type Favicon = { +export type Favicon = { /** * The raw Base64 encoded favicon. */ @@ -118,7 +118,7 @@ type Favicon = { * This is for servers on 1.12 or below. *

*/ -type ModInfo = { +export type ModInfo = { /** * The type of modded server this is. */ @@ -133,7 +133,7 @@ type ModInfo = { /** * A legacy Forge mod for a server. */ -type LegacyForgeMod = { +export type LegacyForgeMod = { /** * The name of this mod. */ @@ -151,7 +151,7 @@ type LegacyForgeMod = { * This is for servers on 1.13 and above. *

*/ -type ForgeData = { +export type ForgeData = { /** * The list of channels on this server, empty if none. */ @@ -180,7 +180,7 @@ type ForgeData = { /** * A Forge channel for a server. */ -type ForgeChannel = { +export type ForgeChannel = { /** * The name of this channel. */ @@ -200,7 +200,7 @@ type ForgeChannel = { /** * A modern Forge mod for a server. */ -type ModernForgeMod = { +export type ModernForgeMod = { /** * The name of this mod. */ diff --git a/Lib/test/index.test.ts b/Lib/test/index.test.ts index 332a90b..f446d23 100644 --- a/Lib/test/index.test.ts +++ b/Lib/test/index.test.ts @@ -1,24 +1,35 @@ -// describe("player", () => { -// it("Rainnny", async () => { -// const player: CachedPlayer = await getPlayer("Rainnny"); -// console.log("player found", player.cached); -// }); -// }); +import { describe, it } from "bun:test"; +import { getMinecraftServer, getMojangServerStatus, getPlayer } from "../src"; +import { ErrorResponse } from "../src/types/generic"; +import { MojangServerStatus } from "../src/types/mojang"; +import { CachedPlayer } from "../src/types/player"; +import { CachedBedrockMinecraftServer } from "../src/types/server/bedrock-server"; +import { CachedJavaMinecraftServer } from "../src/types/server/java-server"; -// describe("server", () => { -// it("java", async () => { -// const server: JavaMinecraftServer | BedrockMinecraftServer = -// await getMinecraftServer("java", "play.wildnetwork.net"); +describe("player", () => { + it("Rainnny", async () => { + try { + const player: CachedPlayer = await getPlayer("Rainnny"); + console.log(`Hello ${player.username}, your UUID is ${player.uniqueId}!`); + } catch (err) { + if ((err as ErrorResponse).code == 404) { + console.error("Player with UUID or username not found."); + } + } + }); +}); -// if ((server as BedrockMinecraftServer).id) { -// } -// console.log(server.ip); -// }); -// }); +describe("server", () => { + it("java", async () => { + const server: CachedJavaMinecraftServer | CachedBedrockMinecraftServer = + await getMinecraftServer("java", "play.wildnetwork.net"); + console.log(server.ip); + }); +}); -// describe("mojang", () => { -// it("status", async () => { -// const status: MojangServerStatus = await getMojangServerStatus(); -// console.log(status["https://sessionserver.mojang.com"]); -// }); -// }); +describe("mojang", () => { + it("status", async () => { + const status: MojangServerStatus = await getMojangServerStatus(); + console.log(status["https://sessionserver.mojang.com"]); + }); +}); diff --git a/Lib/tsconfig.json b/Lib/tsconfig.json index 90f2f8f..a9beb5d 100644 --- a/Lib/tsconfig.json +++ b/Lib/tsconfig.json @@ -11,6 +11,11 @@ "allowJs": true, "noEmit": true, "outDir": "dist", - "resolveJsonModule": true + "resolveJsonModule": true, + "paths": { + "@/*": ["./*"], + "@/lib/*": ["./src/lib/*"], + "@/types/*": ["./src/types/*"] + } } }