Phase3
This commit is contained in:
14
packages/contracts/src/console.ts
Normal file
14
packages/contracts/src/console.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const consoleTokenResponseSchema = z.object({
|
||||
token: z.string(),
|
||||
expiresAt: z.string().datetime(),
|
||||
wsUrl: z.string(),
|
||||
});
|
||||
|
||||
export const consoleCommandSchema = z.object({
|
||||
command: z.string().min(1).max(256),
|
||||
});
|
||||
|
||||
export type ConsoleTokenResponse = z.infer<typeof consoleTokenResponseSchema>;
|
||||
export type ConsoleCommand = z.infer<typeof consoleCommandSchema>;
|
||||
41
packages/contracts/src/files.ts
Normal file
41
packages/contracts/src/files.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const listFilesQuerySchema = z.object({
|
||||
path: z.string().default('.'),
|
||||
});
|
||||
|
||||
export const fileEntrySchema = z.object({
|
||||
name: z.string(),
|
||||
path: z.string(),
|
||||
type: z.enum(['file', 'directory']),
|
||||
size: z.number().int().nonnegative().optional(),
|
||||
modifiedAt: z.string().datetime().optional(),
|
||||
});
|
||||
|
||||
export const fileListResponseSchema = z.object({
|
||||
path: z.string(),
|
||||
entries: z.array(fileEntrySchema),
|
||||
});
|
||||
|
||||
export const fileContentSchema = z.object({
|
||||
path: z.string(),
|
||||
content: z.string(),
|
||||
encoding: z.enum(['utf-8', 'base64']).default('utf-8'),
|
||||
});
|
||||
|
||||
export const readFileContentQuerySchema = z.object({
|
||||
path: z.string().min(1),
|
||||
});
|
||||
|
||||
export const updateFileContentSchema = z.object({
|
||||
path: z.string().min(1),
|
||||
content: z.string(),
|
||||
encoding: z.enum(['utf-8', 'base64']).default('utf-8'),
|
||||
});
|
||||
|
||||
export type ListFilesQuery = z.infer<typeof listFilesQuerySchema>;
|
||||
export type FileEntry = z.infer<typeof fileEntrySchema>;
|
||||
export type FileListResponse = z.infer<typeof fileListResponseSchema>;
|
||||
export type FileContent = z.infer<typeof fileContentSchema>;
|
||||
export type ReadFileContentQuery = z.infer<typeof readFileContentQuerySchema>;
|
||||
export type UpdateFileContent = z.infer<typeof updateFileContentSchema>;
|
||||
@@ -71,3 +71,45 @@ export {
|
||||
type ServerListResponse,
|
||||
type ServerActionResponse,
|
||||
} from './servers';
|
||||
|
||||
export {
|
||||
listFilesQuerySchema,
|
||||
fileEntrySchema,
|
||||
fileListResponseSchema,
|
||||
fileContentSchema,
|
||||
readFileContentQuerySchema,
|
||||
updateFileContentSchema,
|
||||
type ListFilesQuery,
|
||||
type FileEntry,
|
||||
type FileListResponse,
|
||||
type FileContent,
|
||||
type ReadFileContentQuery,
|
||||
type UpdateFileContent,
|
||||
} from './files';
|
||||
|
||||
export {
|
||||
consoleTokenResponseSchema,
|
||||
consoleCommandSchema,
|
||||
type ConsoleTokenResponse,
|
||||
type ConsoleCommand,
|
||||
} from './console';
|
||||
|
||||
export {
|
||||
serverPropertiesSchema,
|
||||
updateServerPropertiesSchema,
|
||||
serverPropertiesResponseSchema,
|
||||
type ServerProperties,
|
||||
type UpdateServerProperties,
|
||||
type ServerPropertiesResponse,
|
||||
} from './properties';
|
||||
|
||||
export {
|
||||
onlinePlayerSchema,
|
||||
whitelistEntrySchema,
|
||||
operatorEntrySchema,
|
||||
playerListResponseSchema,
|
||||
type OnlinePlayer,
|
||||
type WhitelistEntry,
|
||||
type OperatorEntry,
|
||||
type PlayerListResponse,
|
||||
} from './players';
|
||||
|
||||
29
packages/contracts/src/players.ts
Normal file
29
packages/contracts/src/players.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const onlinePlayerSchema = z.object({
|
||||
name: z.string(),
|
||||
uuid: z.string().uuid().optional(),
|
||||
});
|
||||
|
||||
export const whitelistEntrySchema = z.object({
|
||||
uuid: z.string().uuid(),
|
||||
name: z.string(),
|
||||
});
|
||||
|
||||
export const operatorEntrySchema = z.object({
|
||||
uuid: z.string().uuid(),
|
||||
name: z.string(),
|
||||
level: z.number().int().min(0).max(4).optional(),
|
||||
bypassesPlayerLimit: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const playerListResponseSchema = z.object({
|
||||
online: z.array(onlinePlayerSchema),
|
||||
whitelist: z.array(whitelistEntrySchema),
|
||||
operators: z.array(operatorEntrySchema),
|
||||
});
|
||||
|
||||
export type OnlinePlayer = z.infer<typeof onlinePlayerSchema>;
|
||||
export type WhitelistEntry = z.infer<typeof whitelistEntrySchema>;
|
||||
export type OperatorEntry = z.infer<typeof operatorEntrySchema>;
|
||||
export type PlayerListResponse = z.infer<typeof playerListResponseSchema>;
|
||||
41
packages/contracts/src/properties.ts
Normal file
41
packages/contracts/src/properties.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const serverPropertiesSchema = z
|
||||
.object({
|
||||
'motd': z.string().max(256).optional(),
|
||||
'gamemode': z
|
||||
.enum(['survival', 'creative', 'adventure', 'spectator'])
|
||||
.optional(),
|
||||
'difficulty': z.enum(['peaceful', 'easy', 'normal', 'hard']).optional(),
|
||||
'hardcore': z.boolean().optional(),
|
||||
'max-players': z.number().int().min(1).max(1000).optional(),
|
||||
'pvp': z.boolean().optional(),
|
||||
'white-list': z.boolean().optional(),
|
||||
'enable-command-block': z.boolean().optional(),
|
||||
'view-distance': z.number().int().min(3).max(32).optional(),
|
||||
'simulation-distance': z.number().int().min(3).max(32).optional(),
|
||||
'spawn-protection': z.number().int().min(0).optional(),
|
||||
'allow-flight': z.boolean().optional(),
|
||||
'online-mode': z.boolean().optional(),
|
||||
'enable-query': z.boolean().optional(),
|
||||
'enable-rcon': z.boolean().optional(),
|
||||
'level-seed': z.string().max(64).optional(),
|
||||
'level-name': z.string().max(64).optional(),
|
||||
'resource-pack': z.string().url().optional().or(z.literal('')),
|
||||
'resource-pack-sha1': z.string().max(64).optional(),
|
||||
'allow-nether': z.boolean().optional(),
|
||||
})
|
||||
.catchall(z.union([z.string(), z.number(), z.boolean()]));
|
||||
|
||||
export const updateServerPropertiesSchema = serverPropertiesSchema.partial();
|
||||
|
||||
export const serverPropertiesResponseSchema = z.object({
|
||||
properties: serverPropertiesSchema,
|
||||
raw: z.string(),
|
||||
});
|
||||
|
||||
export type ServerProperties = z.infer<typeof serverPropertiesSchema>;
|
||||
export type UpdateServerProperties = z.infer<typeof updateServerPropertiesSchema>;
|
||||
export type ServerPropertiesResponse = z.infer<
|
||||
typeof serverPropertiesResponseSchema
|
||||
>;
|
||||
Reference in New Issue
Block a user