refactor(data): replace schema classes with readonly models

This commit is contained in:
2026-07-17 13:21:40 +08:00
parent 3437312167
commit ae97366a4a
103 changed files with 1220 additions and 2117 deletions
@@ -1,12 +1,15 @@
import { fromCallback, fromPromise } from "xstate";
import {
ChatSendResponse,
UnlockPrivateResponse,
} from "@/data/schemas/chat";
import { DEFAULT_CHARACTER_ID } from "@/data/constants/character";
import { chatMachine } from "@/stores/chat/chat-machine";
import {
ChatSendResponseSchema,
UnlockPrivateResponseSchema,
type ChatSendResponse,
type UnlockPrivateResponse,
type UnlockPrivateResponseInput,
} from "@/data/schemas/chat";
import type { ChatEvent } from "@/stores/chat/chat-events";
import { chatMachine } from "@/stores/chat/chat-machine";
import type {
UnlockMessageOutput as MachineUnlockMessageOutput,
UnlockMessageRequest,
@@ -36,7 +39,7 @@ export const TEST_CHAT_MACHINE_INPUT = {
};
export function makeChatSendResponse(): ChatSendResponse {
return ChatSendResponse.from({
return ChatSendResponseSchema.parse({
reply: "",
audioUrl: "",
messageId: "msg-1",
@@ -51,9 +54,9 @@ export function makeChatSendResponse(): ChatSendResponse {
}
export function makeUnlockPrivateResponse(
overrides: Partial<Parameters<typeof UnlockPrivateResponse.from>[0]> = {},
overrides: Partial<UnlockPrivateResponseInput> = {},
): UnlockPrivateResponse {
return UnlockPrivateResponse.from({
return UnlockPrivateResponseSchema.parse({
unlocked: true,
content: "unlocked content",
audioUrl: "",
@@ -106,21 +109,20 @@ export function createTestChatMachine(
return () => undefined;
},
),
unlockHistory: fromPromise<
UnlockHistoryOutput,
{ characterId: string }
>(async () => {
if (options.unlockHistoryError) {
throw options.unlockHistoryError;
}
return {
unlocked: true,
reason: "ok",
shortfallCredits: 0,
messages: [],
...options.unlockHistoryOutput,
};
}),
unlockHistory: fromPromise<UnlockHistoryOutput, { characterId: string }>(
async () => {
if (options.unlockHistoryError) {
throw options.unlockHistoryError;
}
return {
unlocked: true,
reason: "ok",
shortfallCredits: 0,
messages: [],
...options.unlockHistoryOutput,
};
},
),
unlockMessage: fromPromise<
MachineUnlockMessageOutput,
UnlockMessageRequest & { characterId: string }