refactor(data): merge DTO models into schemas

This commit is contained in:
2026-07-17 12:47:18 +08:00
parent 2796010971
commit eac3d8f0a7
274 changed files with 1466 additions and 1956 deletions
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { DEFAULT_CHARACTER_ID } from "@/data/constants/character";
import { ChatSendResponse } from "@/data/dto/chat";
import { ChatSendResponse } from "@/data/schemas/chat";
import type { ChatState } from "@/stores/chat/chat-state";
import {
applyNetworkHistoryLoadedOutput,
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { createActor, fromCallback, waitFor } from "xstate";
import type { UiMessage } from "@/data/dto/chat";
import type { UiMessage } from "@/stores/chat/ui-message";
import type { ChatEvent } from "@/stores/chat/chat-events";
import { chatMachine } from "@/stores/chat/chat-machine";
import type { LoadMoreHistoryActorEvent } from "@/stores/chat/machine/actors/history";
@@ -3,8 +3,7 @@ import { fromCallback, fromPromise } from "xstate";
import {
ChatSendResponse,
UnlockPrivateResponse,
type UiMessage,
} from "@/data/dto/chat";
} from "@/data/schemas/chat";
import { DEFAULT_CHARACTER_ID } from "@/data/constants/character";
import { chatMachine } from "@/stores/chat/chat-machine";
import type { ChatEvent } from "@/stores/chat/chat-events";
@@ -13,6 +12,7 @@ import type {
UnlockMessageRequest,
} from "@/stores/chat/helper/unlock";
import type { ChatHistoryActorInput } from "@/stores/chat/machine/actors/history";
import type { UiMessage } from "@/stores/chat/ui-message";
export interface SendMessageHttpOutput {
response: ChatSendResponse;
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { UnlockPrivateResponse } from "@/data/dto/chat";
import { UnlockPrivateResponse } from "@/data/schemas/chat";
import type { PendingChatPromotion } from "@/data/storage/navigation";
import {
appendPromotionMessage,
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { createActor, fromPromise, waitFor } from "xstate";
import { ChatSendResponse } from "@/data/dto/chat";
import { ChatSendResponse } from "@/data/schemas/chat";
import type {
UnlockMessageOutput,
UnlockMessageRequest,
+1 -1
View File
@@ -1,4 +1,4 @@
import type { UiMessage } from "@/data/dto/chat";
import type { UiMessage } from "@/stores/chat/ui-message";
import { resolveChatConversationKey } from "@/data/repositories/chat_cache_identity";
import { loadChatRepository } from "@/data/repositories/chat_repository_loader";
import { Logger } from "@/utils/logger";
+1 -1
View File
@@ -1,4 +1,4 @@
import type { UiMessage } from "@/data/dto/chat";
import type { UiMessage } from "@/stores/chat/ui-message";
import type { PendingChatUnlockKind } from "@/lib/navigation/chat_unlock_session";
import type { ChatLockType } from "@/data/schemas/chat";
import type { PendingChatPromotion } from "@/data/storage/navigation";
+1 -1
View File
@@ -1,4 +1,4 @@
import type { UiMessage } from "@/data/dto/chat";
import type { UiMessage } from "@/stores/chat/ui-message";
import type { ChatState } from "../chat-state";
+5 -2
View File
@@ -1,5 +1,8 @@
import { type ChatSendResponse, type UiMessage } from "@/data/dto/chat";
import type { ChatLockDetailData } from "@/data/schemas/chat";
import type {
ChatLockDetailData,
ChatSendResponse,
} from "@/data/schemas/chat";
import type { UiMessage } from "@/stores/chat/ui-message";
import { todayString } from "@/utils/date";
/**
+1 -1
View File
@@ -1,4 +1,4 @@
import type { UiMessage } from "@/data/dto/chat";
import type { UiMessage } from "@/stores/chat/ui-message";
import type { PendingChatPromotion } from "@/data/storage/navigation";
import { todayString } from "@/utils/date";
+2 -1
View File
@@ -1,4 +1,5 @@
import { type ChatSendResponse, type UiMessage } from "@/data/dto/chat";
import type { ChatSendResponse } from "@/data/schemas/chat";
import type { UiMessage } from "@/stores/chat/ui-message";
import type { ChatState, ChatUpgradeReason } from "../chat-state";
+5 -2
View File
@@ -1,5 +1,8 @@
import type { UiMessage, UnlockPrivateResponse } from "@/data/dto/chat";
import type { ChatLockType } from "@/data/schemas/chat";
import type {
ChatLockType,
UnlockPrivateResponse,
} from "@/data/schemas/chat";
import type { UiMessage } from "@/stores/chat/ui-message";
export interface UnlockMessageRequest {
displayMessageId: string;
+1
View File
@@ -5,3 +5,4 @@ export * from "./chat-events";
export * from "./helper";
export * from "./chat-machine";
export * from "./chat-state";
export * from "./ui-message";
+1 -1
View File
@@ -1,6 +1,6 @@
import { fromCallback } from "xstate";
import type { UiMessage } from "@/data/dto/chat";
import type { UiMessage } from "@/stores/chat/ui-message";
import { loadChatRepository } from "@/data/repositories/chat_repository_loader";
import { Logger } from "@/utils/logger";
import { Result } from "@/utils/result";
+2 -2
View File
@@ -2,7 +2,7 @@ import { fromCallback, fromPromise } from "xstate";
import { ExceptionHandler } from "@/core/errors";
import { MessageQueue } from "@/core/net/message-queue";
import type { ChatSendResponse } from "@/data/dto/chat";
import type { ChatSendResponse } from "@/data/schemas/chat";
import { loadChatRepository } from "@/data/repositories/chat_repository_loader";
import { resolveChatConversationKey } from "@/data/repositories/chat_cache_identity";
import { Logger } from "@/utils/logger";
@@ -13,7 +13,7 @@ import { sendResponseToUiMessage } from "../../helper/message-mappers";
const log = new Logger("StoresChatChatSendFlow");
type UiMessage = import("@/data/dto/chat").UiMessage;
type UiMessage = import("@/stores/chat/ui-message").UiMessage;
export const sendMessageHttpActor = fromPromise<
{ response: ChatSendResponse; reply: UiMessage | null },
+1 -1
View File
@@ -13,7 +13,7 @@ import {
const log = new Logger("StoresChatChatUnlockFlow");
type UiMessage = import("@/data/dto/chat").UiMessage;
type UiMessage = import("@/stores/chat/ui-message").UiMessage;
export interface UnlockHistoryOutput {
unlocked: boolean;
+33
View File
@@ -0,0 +1,33 @@
import { z } from "zod";
export const UiMessageSchema = z.object({
id: z.string().optional(),
content: z.string(),
isFromAI: z.boolean(),
date: z.string(),
isSynthetic: z.boolean().optional(),
imageUrl: z.string().optional(),
imagePaywalled: z.boolean().optional(),
audioUrl: z.string().optional(),
locked: z.boolean().nullable().optional(),
lockReason: z.string().nullable().optional(),
isPrivate: z.boolean().nullable().optional(),
lockedPrivate: z.boolean().nullable().optional(),
privateMessageHint: z.string().nullable().optional(),
});
export type UiMessage = z.infer<typeof UiMessageSchema>;
export const UiMessage = {
create(input: Omit<UiMessage, "date"> & { date?: string }): UiMessage {
return UiMessageSchema.parse({
...input,
date:
input.date ??
new Date().toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
}),
});
},
};