refactor(dto): centralize backend schema defaults

This commit is contained in:
2026-07-06 11:14:56 +08:00
parent 2d736f00ba
commit 473f6a3726
40 changed files with 513 additions and 231 deletions
+37 -23
View File
@@ -3,30 +3,44 @@
*/
import { z } from "zod";
export const ChatImageSchema = z
.object({
type: z.string().nullable().default(null),
url: z.string().nullable().default(null),
})
.default({ type: null, url: null });
import {
booleanOrFalse,
booleanOrTrue,
schemaOr,
stringOrNull,
unknownRecordOrNull,
} from "../nullable-defaults";
export const ChatLockDetailSchema = z
.object({
locked: z.boolean().default(false),
showContent: z.boolean().default(true),
showUpgrade: z.boolean().default(false),
reason: z.string().nullable().default(null),
hint: z.string().nullable().default(null),
detail: z.record(z.string(), z.unknown()).nullable().default(null),
})
.default({
locked: false,
showContent: true,
showUpgrade: false,
reason: null,
hint: null,
detail: null,
});
const CHAT_IMAGE_DEFAULTS = { type: null, url: null } as const;
const CHAT_LOCK_DETAIL_DEFAULTS = {
locked: false,
showContent: true,
showUpgrade: false,
reason: null,
hint: null,
detail: null,
} as const;
export const ChatImageSchema = schemaOr(
z.object({
type: stringOrNull,
url: stringOrNull,
}),
CHAT_IMAGE_DEFAULTS,
);
export const ChatLockDetailSchema = schemaOr(
z.object({
locked: booleanOrFalse,
showContent: booleanOrTrue,
showUpgrade: booleanOrFalse,
reason: stringOrNull,
hint: stringOrNull,
detail: unknownRecordOrNull,
}),
CHAT_LOCK_DETAIL_DEFAULTS,
);
export type ChatImageInput = z.input<typeof ChatImageSchema>;
export type ChatImageData = z.output<typeof ChatImageSchema>;