Extract shared Zod schemas for dependency type and environment
This commit is contained in:
parent
cfce62195d
commit
cb05223145
@ -1,14 +1,12 @@
|
||||
import { z } from "zod";
|
||||
import { DependencyTypeSchema } from "./modrinth/version";
|
||||
import { EnvironmentSchema } from "./modrinth/create-version";
|
||||
import { RelationsSchema } from "./curseforge/upload";
|
||||
|
||||
// region ModrinthDependency — config 中的 Modrinth 依赖项(比 VersionDependency 简化)
|
||||
export const ModrinthDependencySchema = z.object({
|
||||
/** 依赖类型 */
|
||||
dependency_type: z.enum([
|
||||
"required",
|
||||
"optional",
|
||||
"incompatible",
|
||||
"embedded",
|
||||
]),
|
||||
dependency_type: DependencyTypeSchema,
|
||||
/** 依赖的项目 ID(8 位 base62) */
|
||||
project_id: z.string().min(1),
|
||||
});
|
||||
@ -26,51 +24,13 @@ export const ModrinthConfigSchema = z.object({
|
||||
/** 加载器列表 */
|
||||
loaders: z.array(z.string().min(1)),
|
||||
/** 运行环境 */
|
||||
environment: z.enum([
|
||||
"unknown",
|
||||
"client_only",
|
||||
"server_only",
|
||||
"dedicated_server_only",
|
||||
"client_and_server",
|
||||
"server_only_client_optional",
|
||||
"client_only_server_optional",
|
||||
"client_or_server_prefers_both",
|
||||
"client_or_server",
|
||||
"singleplayer_only",
|
||||
]),
|
||||
environment: EnvironmentSchema,
|
||||
/** 依赖列表,无依赖填 [] */
|
||||
dependencies: z.array(ModrinthDependencySchema),
|
||||
});
|
||||
export type ModrinthConfig = z.infer<typeof ModrinthConfigSchema>;
|
||||
// endregion
|
||||
|
||||
// region CurseForgeRelationProject — config 中 CurseForge 关联项目
|
||||
export const CurseForgeRelationProjectSchema = z.object({
|
||||
/** 关联项目的 slug */
|
||||
slug: z.string().min(1),
|
||||
/** 关联项目的 ID(精确匹配),可选 */
|
||||
projectID: z.string().optional(),
|
||||
/** 关联类型 */
|
||||
type: z.enum([
|
||||
"embeddedLibrary",
|
||||
"incompatible",
|
||||
"optionalDependency",
|
||||
"requiredDependency",
|
||||
"tool",
|
||||
]),
|
||||
});
|
||||
export type CurseForgeRelationProject = z.infer<
|
||||
typeof CurseForgeRelationProjectSchema
|
||||
>;
|
||||
// endregion
|
||||
|
||||
// region CurseForgeRelations — config 中 CurseForge 关联项目集合
|
||||
export const CurseForgeRelationsSchema = z.object({
|
||||
projects: z.array(CurseForgeRelationProjectSchema),
|
||||
});
|
||||
export type CurseForgeRelations = z.infer<typeof CurseForgeRelationsSchema>;
|
||||
// endregion
|
||||
|
||||
// region CurseForgeConfig — config 中 curseforge 字段
|
||||
export const CurseForgeConfigSchema = z.object({
|
||||
/** CurseForge 项目 ID(数字) */
|
||||
@ -82,7 +42,7 @@ export const CurseForgeConfigSchema = z.object({
|
||||
/** 加载器列表 */
|
||||
loaders: z.array(z.string().min(1)),
|
||||
/** 关联项目 */
|
||||
relations: CurseForgeRelationsSchema,
|
||||
relations: RelationsSchema,
|
||||
});
|
||||
export type CurseForgeConfig = z.infer<typeof CurseForgeConfigSchema>;
|
||||
// endregion
|
||||
@ -120,3 +80,4 @@ export const SecretsSchema = z.object({
|
||||
});
|
||||
export type Secrets = z.infer<typeof SecretsSchema>;
|
||||
// endregion
|
||||
|
||||
|
||||
@ -5,6 +5,22 @@ import {
|
||||
VersionDependencySchema,
|
||||
} from "./version";
|
||||
|
||||
// region Environment — Modrinth 运行环境枚举
|
||||
export const EnvironmentSchema = z.enum([
|
||||
"unknown",
|
||||
"client_only",
|
||||
"server_only",
|
||||
"dedicated_server_only",
|
||||
"client_and_server",
|
||||
"server_only_client_optional",
|
||||
"client_only_server_optional",
|
||||
"client_or_server_prefers_both",
|
||||
"client_or_server",
|
||||
"singleplayer_only",
|
||||
]);
|
||||
export type Environment = z.infer<typeof EnvironmentSchema>;
|
||||
// endregion
|
||||
|
||||
// region CreatableVersion — 创建版本请求中的 data JSON
|
||||
// OpenAPI CreatableVersion.required: file_parts, project_id, name, version_number,
|
||||
// game_versions, version_type, loaders, featured, dependencies
|
||||
@ -18,20 +34,7 @@ export const CreatableVersionSchema = BaseVersionSchema.extend({
|
||||
/** 主文件的 multipart 字段名;不提供时推断第一个文件为主文件 */
|
||||
primary_file: z.string().optional(),
|
||||
/** 目标环境 */
|
||||
environment: z
|
||||
.enum([
|
||||
"unknown",
|
||||
"client_only",
|
||||
"server_only",
|
||||
"dedicated_server_only",
|
||||
"client_and_server",
|
||||
"server_only_client_optional",
|
||||
"client_only_server_optional",
|
||||
"client_or_server_prefers_both",
|
||||
"client_or_server",
|
||||
"singleplayer_only",
|
||||
])
|
||||
.optional(),
|
||||
environment: EnvironmentSchema.optional(),
|
||||
/** multipart 字段名 → 文件类型的映射,用于标记 sources-jar 等附属文件 */
|
||||
file_types: z.record(z.string(), FileTypeEnumSchema).optional(),
|
||||
});
|
||||
|
||||
@ -9,12 +9,14 @@ export {
|
||||
} from "./tags";
|
||||
|
||||
export {
|
||||
DependencyTypeSchema,
|
||||
VersionDependencySchema,
|
||||
FileTypeEnumSchema,
|
||||
VersionFileHashesSchema,
|
||||
VersionFileSchema,
|
||||
BaseVersionSchema,
|
||||
VersionSchema,
|
||||
type DependencyType,
|
||||
type VersionDependency,
|
||||
type FileTypeEnum,
|
||||
type VersionFileHashes,
|
||||
@ -24,8 +26,10 @@ export {
|
||||
} from "./version";
|
||||
|
||||
export {
|
||||
EnvironmentSchema,
|
||||
CreatableVersionSchema,
|
||||
CreateVersionBodySchema,
|
||||
type Environment,
|
||||
type CreatableVersion,
|
||||
type CreateVersionBody,
|
||||
} from "./create-version";
|
||||
|
||||
@ -1,5 +1,15 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// region DependencyType — Modrinth 依赖类型枚举
|
||||
export const DependencyTypeSchema = z.enum([
|
||||
"required",
|
||||
"optional",
|
||||
"incompatible",
|
||||
"embedded",
|
||||
]);
|
||||
export type DependencyType = z.infer<typeof DependencyTypeSchema>;
|
||||
// endregion
|
||||
|
||||
// region VersionDependency — 依赖项
|
||||
export const VersionDependencySchema = z.object({
|
||||
/** 依赖的具体版本 ID;为 null 时匹配最新版 */
|
||||
@ -9,7 +19,7 @@ export const VersionDependencySchema = z.object({
|
||||
/** 依赖文件名,主要用于整合包中的外部依赖 */
|
||||
file_name: z.string().nullable(),
|
||||
/** 依赖类型 */
|
||||
dependency_type: z.enum(["required", "optional", "incompatible", "embedded"]),
|
||||
dependency_type: DependencyTypeSchema,
|
||||
});
|
||||
export type VersionDependency = z.infer<typeof VersionDependencySchema>;
|
||||
// endregion
|
||||
|
||||
Loading…
Reference in New Issue
Block a user