Lib cleanup
Some checks failed
Deploy Lib / docker (push) Failing after 19s

This commit is contained in:
Braydon 2024-04-15 07:16:06 -04:00
parent 49a6e9b7b0
commit 1c1ea04cf0
12 changed files with 85 additions and 60 deletions

@ -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)

4
Lib/src/index.d.ts vendored

@ -1 +1,5 @@
export * from "./types/dns";
export * from "./types/generic";
export * from "./types/mojang";
export * from "./types/player";
export * from "./types/server";

@ -1 +1 @@
export * from "./lib/restfulmc";
export * from "@/lib/restfulmc";

@ -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.

@ -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

@ -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.
*/

@ -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";

@ -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";

@ -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.
*/

@ -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.
* </p>
*/
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.
* </p>
*/
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.
*/

@ -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"]);
});
});

@ -11,6 +11,11 @@
"allowJs": true,
"noEmit": true,
"outDir": "dist",
"resolveJsonModule": true
"resolveJsonModule": true,
"paths": {
"@/*": ["./*"],
"@/lib/*": ["./src/lib/*"],
"@/types/*": ["./src/types/*"]
}
}
}