Skip to content

Commit 3a1ed0a

Browse files
committed
Refactor star configuration and types to use nested config object
1 parent 0e7f984 commit 3a1ed0a

File tree

5 files changed

+76
-91
lines changed

5 files changed

+76
-91
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@carbonhost/typescript",
3-
"version": "0.0.87",
3+
"version": "0.0.88",
44
"main": "dist/index.js",
55
"module": "dist/index.mjs",
66
"types": "dist/index.d.ts",

src/carbon-star.ts

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import type { Carbon } from "./carbon";
55
import { FileManager } from "./file-manager";
66
import { MinecraftManager } from "./managers/minecraft-manager";
77
import { StatManager } from "./managers/stat-manager";
8-
import { UserManager } from "./stars/users";
9-
import type { UpdateStarType } from "./types/create-star";
10-
import type { CarbonStarType, StarResources, StarStatus } from "./types/star";
118
import { PortManager } from "./ports";
9+
import { UserManager } from "./stars/users";
10+
import type { JavaVersion, UpdateStarType } from "./types/create-star";
11+
import type { CarbonStarType, StarResources } from "./types/star";
1212

1313
export class CarbonStar {
1414
// @ts-ignore
@@ -17,27 +17,38 @@ export class CarbonStar {
1717

1818
_id: string;
1919
ownerId: string;
20-
2120
name: string;
22-
type: string;
23-
customJar?: string;
24-
version: string;
25-
javaVersion: "21" | "17" | "11" | "8";
26-
startupCommand?: string;
21+
22+
config: {
23+
type: string;
24+
version: string;
25+
javaVersion: JavaVersion;
26+
customJar?: string;
27+
startupCommand?: string;
28+
maximumRamPercentage: number;
29+
additionalFlags: "None" | "Aikar's Flags" | "Velocity Flags";
30+
minehutSupport: "None" | "Velocity" | "Waterfall" | "Bukkit";
31+
overrideStartup: boolean;
32+
automaticUpdating: boolean;
33+
simdOperations: boolean;
34+
removeUpdateWarnings: boolean;
35+
malwareScan: boolean;
36+
acceptEula: boolean;
37+
};
2738

2839
serverId: number;
2940
clientId: string;
30-
galaxyId: string;
41+
galaxyId: number;
3142

3243
ip: string;
3344
subdomain?: string;
3445

3546
subUsers: {
36-
_id: string,
37-
clerkId: string,
38-
email: string,
39-
minecraftUUID: string,
40-
}[]
47+
_id: string;
48+
clerkId: string;
49+
email: string;
50+
minecraftUUID?: string;
51+
}[];
4152

4253
resources: {
4354
storage: number;
@@ -54,7 +65,6 @@ export class CarbonStar {
5465

5566
constructor(
5667
carbonClient: Carbon,
57-
// apiKey: string,
5868
carbonStar: CarbonStarType,
5969
) {
6070
this.carbonClient = carbonClient;
@@ -63,13 +73,24 @@ export class CarbonStar {
6373

6474
this._id = carbonStar._id;
6575
this.ownerId = carbonStar.ownerId;
66-
6776
this.name = carbonStar.name;
68-
this.type = carbonStar.type;
69-
this.customJar = carbonStar.customJar;
70-
this.version = carbonStar.version;
71-
this.javaVersion = carbonStar.javaVersion;
72-
this.startupCommand = carbonStar.startupCommand;
77+
78+
this.config = {
79+
type: carbonStar.config.type,
80+
version: carbonStar.config.version,
81+
javaVersion: carbonStar.config.javaVersion,
82+
customJar: carbonStar.config.customJar,
83+
startupCommand: carbonStar.config.startupCommand,
84+
maximumRamPercentage: carbonStar.config.maximumRamPercentage,
85+
additionalFlags: carbonStar.config.additionalFlags,
86+
minehutSupport: carbonStar.config.minehutSupport,
87+
overrideStartup: carbonStar.config.overrideStartup,
88+
automaticUpdating: carbonStar.config.automaticUpdating,
89+
simdOperations: carbonStar.config.simdOperations,
90+
removeUpdateWarnings: carbonStar.config.removeUpdateWarnings,
91+
malwareScan: carbonStar.config.malwareScan,
92+
acceptEula: carbonStar.config.acceptEula,
93+
};
7394

7495
this.serverId = carbonStar.serverId;
7596
this.clientId = carbonStar.clientId;
@@ -132,9 +153,9 @@ export class CarbonStar {
132153
}).then((res) => res.data);
133154
}
134155

135-
async getWebsocketInfo() {
136-
return this.axios.get
137-
}
156+
// async getWebsocketInfo() {
157+
// return this.axios.get
158+
// }
138159

139160
async getResources() {
140161
return this.axios.get<StarResources>("/resources").then((res) => res.data);

src/carbon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Carbon {
1515
constructor({ apiKey, url }: { apiKey: string, url?: string }) {
1616
this.apiKey = apiKey;
1717
this.axios = axios.create({
18-
baseURL: url || "https://staging.api.carbon.host",
18+
baseURL: url || "https://api.carbon.host",
1919
headers: {
2020
"Content-Type": "application/json",
2121
"Authorization": `Bearer ${apiKey}`,

src/types/create-star.ts

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,3 @@
1-
/*
2-
export const ZodSoftwareType = z.enum(["VANILLA", "PAPER", "PUFFERFISH", "SPIGOT", "FOLIA", "PURPUR", "WATERFALL", "VELOCITY", "FABRIC", "BUNGEECORD", "QUILT", "FORGE", "NEOFORGE", "MOHIST", "ARCLIGHT", "SPONGE", "LEAVES", "CANVAS", "ASPAPER", "LEGACY_FABRIC", "LOOHP_LIMBO", "NANOLIMBO", "CUSTOM"])
3-
4-
export const ZodJavaVersion = z.enum(["8", "11", "16", "17", "19", "21", "22", "23"])
5-
6-
export const ZodEggVariables = z.object({
7-
SERVER_JARFILE: z.string().regex(/^([\w\d._-]+)(\.[jJ][aA][rR])$/, {
8-
message: "Server jar file must be a valid jar filename"
9-
}),
10-
11-
ADDITIONAL_FLAGS: z.enum(["None", "Aikar's Flags", "Velocity Flags"], {
12-
errorMap: () => ({ message: "Invalid additional flags selection" })
13-
}),
14-
15-
MAXIMUM_RAM: z.coerce.number().int().min(50).max(100).default(90).transform(val => val.toString()),
16-
17-
MINEHUT_SUPPORT: z.enum(["None", "Velocity", "Waterfall", "Bukkit"], {
18-
errorMap: () => ({ message: "Invalid Minehut support option" })
19-
}),
20-
21-
LOG_PREFIX: z.string().optional(),
22-
23-
JAVA_AGENT: z.string().regex(/^([\w\d._-]+)(\.[jJ][aA][rR])$/, {
24-
message: "Java agent must be a valid jar filename"
25-
}).optional(),
26-
27-
OVERRIDE_STARTUP: z.boolean().default(true).describe("ADVANCED FEATURE: Override the displayed startup command to support all other variables, contact support to change."),
28-
29-
AUTOMATIC_UPDATING: z.boolean().default(false),
30-
31-
SIMD_OPERATIONS: z.boolean().default(false),
32-
33-
REMOVE_UPDATE_WARNING: z.boolean().default(true),
34-
35-
MALWARE_SCAN: z.boolean().default(false),
36-
37-
SOFTWARE: ZodSoftwareType.default("PAPER"),
38-
39-
VERSION: z.string().default("latest"),
40-
41-
BUILD: z.string().default("latest"),
42-
43-
CUSTOM_JAR_URL: z.string().optional(),
44-
45-
AUTO_ACCEPT_EULA: z.boolean().default(false),
46-
})
47-
48-
*/
49-
501
export type StarType = "VANILLA" | "PAPER" | "PUFFERFISH" | "SPIGOT" | "FOLIA" | "PURPUR" | "WATERFALL" | "VELOCITY" | "FABRIC" | "BUNGEECORD" | "QUILT" | "FORGE" | "NEOFORGE" | "MOHIST" | "ARCLIGHT" | "SPONGE" | "LEAVES" | "CANVAS" | "ASPAPER" | "LEGACY_FABRIC" | "LOOHP_LIMBO" | "NANOLIMBO" | "CUSTOM"
512
export type JavaVersion = "8" | "11" | "16" | "17" | "19" | "21" | "22" | "23"
523

src/types/star.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
1+
import type { JavaVersion } from "./create-star";
2+
13
export type CarbonStarType = {
24
_id: string;
35
ownerId: string;
4-
56
name: string;
6-
type: string;
7-
customJar?: string;
8-
version: string;
9-
javaVersion: "21" | "17" | "11" | "8";
10-
startupCommand?: string;
7+
8+
config: {
9+
type: string;
10+
version: string;
11+
javaVersion: JavaVersion
12+
customJar?: string;
13+
startupCommand?: string;
14+
maximumRamPercentage: number;
15+
additionalFlags: "None" | "Aikar's Flags" | "Velocity Flags";
16+
minehutSupport: "None" | "Velocity" | "Waterfall" | "Bukkit";
17+
overrideStartup: boolean;
18+
automaticUpdating: boolean;
19+
simdOperations: boolean;
20+
removeUpdateWarnings: boolean;
21+
malwareScan: boolean;
22+
acceptEula: boolean;
23+
};
1124

1225
clientId: string;
1326
serverId: number;
14-
galaxyId: string;
27+
galaxyId: number;
1528

1629
ip: string;
1730
subdomain?: string;
1831

1932
subUsers: {
20-
_id: string,
21-
clerkId: string,
22-
email: string,
23-
minecraftUUID: string,
24-
}[]
33+
_id: string;
34+
clerkId: string;
35+
email: string;
36+
minecraftUUID?: string;
37+
}[];
2538

2639
resources: {
27-
storage: number;
28-
memory: number;
29-
vCPU: number;
40+
storage: number;
41+
memory: number;
42+
vCPU: number;
3043
};
3144

3245
suspended: boolean;

0 commit comments

Comments
 (0)