From 9658773fa23f674dd3d36b9655e03ad6de06ee50 Mon Sep 17 00:00:00 2001 From: CPTProgrammer <46586216+CPTProgrammer@users.noreply.github.com> Date: Mon, 13 Jul 2026 19:07:32 +0800 Subject: [PATCH] Make nullable fields optional in CurseForge schemas --- src/types/curseforge/files.ts | 2 +- src/types/curseforge/game.ts | 2 +- src/types/curseforge/mod.ts | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/types/curseforge/files.ts b/src/types/curseforge/files.ts index b802119..a8a770d 100644 --- a/src/types/curseforge/files.ts +++ b/src/types/curseforge/files.ts @@ -139,7 +139,7 @@ export const CurseForgeFileSchema = z.object({ /** 父项目文件 ID,无则为 null 或被省略 */ parentProjectFileId: z.number().int().nullable().optional(), /** 替代文件 ID,无则为 null */ - alternateFileId: z.number().int().nullable(), + alternateFileId: z.number().int().nullable().optional(), /** 是否为服务端整合包 */ isServerPack: z.boolean().nullable().optional(), /** 服务端整合包文件 ID,无则为 null 或被省略 */ diff --git a/src/types/curseforge/game.ts b/src/types/curseforge/game.ts index 986a948..2f4fc5b 100644 --- a/src/types/curseforge/game.ts +++ b/src/types/curseforge/game.ts @@ -23,7 +23,7 @@ export const GameVersionSchema = z.object({ /** 版本标识,如 "1-21-5" */ slug: z.string(), /** API 版本号,无则为 null 或空字符串 */ - apiVersion: z.string().nullable(), + apiVersion: z.string().nullable().optional(), }); export type GameVersion = z.infer; // endregion diff --git a/src/types/curseforge/mod.ts b/src/types/curseforge/mod.ts index d422f22..4ef30ad 100644 --- a/src/types/curseforge/mod.ts +++ b/src/types/curseforge/mod.ts @@ -2,6 +2,7 @@ import { z } from "zod"; import { FileReleaseTypeSchema, CurseForgeFileSchema, + ModLoaderTypeSchema, } from "./files"; // region ModStatus — 项目状态 @@ -81,11 +82,11 @@ export const CategorySchema = z.object({ /** 最后修改时间(ISO-8601) */ dateModified: z.string(), /** 是否为顶层分类 */ - isClass: z.boolean().nullable(), + isClass: z.boolean().nullable().optional(), /** 所属 class ID */ - classId: z.number().int().nullable(), + classId: z.number().int().nullable().optional(), /** 父分类 ID */ - parentCategoryId: z.number().int().nullable(), + parentCategoryId: z.number().int().nullable().optional(), /** 显示排序索引 */ displayIndex: z.number().int().nullable().optional(), }); @@ -103,9 +104,9 @@ export const FileIndexSchema = z.object({ /** 发布类型 */ releaseType: FileReleaseTypeSchema, /** 版本类型 ID */ - gameVersionTypeId: z.number().int().nullable(), + gameVersionTypeId: z.number().int().nullable().optional(), /** Mod Loader 类型(数值,API 可能返回未在文档中列出的值,也可能省略) */ - modLoader: z.number().int().optional(), + modLoader: ModLoaderTypeSchema.optional(), }); export type FileIndex = z.infer; // endregion @@ -135,7 +136,7 @@ export const ModSchema = z.object({ /** 分类列表 */ categories: z.array(CategorySchema), /** 所属 class ID,无则为 null */ - classId: z.number().int().nullable(), + classId: z.number().int().nullable().optional(), /** 作者列表 */ authors: z.array(ModAuthorSchema), /** Logo 资源 */ @@ -157,7 +158,7 @@ export const ModSchema = z.object({ /** 发布时间(ISO-8601) */ dateReleased: z.string(), /** 是否允许分发 */ - allowModDistribution: z.boolean().nullable(), + allowModDistribution: z.boolean().nullable().optional(), /** 游戏内热门排名 */ gamePopularityRank: z.number().int(), /** 是否可被搜索到 */