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