75e685d418
Reorganize the data layer by separating DTOs (Data Transfer Objects) from Zod validation schemas into distinct directory structures. Previously, all model types were imported from a single `@/data/models` barrel file, mixing request/response classes with validation schemas. Changes: - Update API files (auth, chat, metrics, user) to import DTOs from specific paths under `@/data/dto/*` instead of the models barrel - Move user schema to `@/data/schemas/user/user` for type-only imports - Create dedicated Zod schema files under `@/data/schemas/*` for auth and chat domain models (e.g., AppleLoginRequestSchema, SendMessageRequestSchema, SyncMessageSchema, SttDataSchema) - Improve discoverability and tree-shaking by co-locating schemas with their respective domain areas This is a non-functional refactor that lays the groundwork for clearer separation between transport-layer types and runtime validation.
35 lines
856 B
TypeScript
35 lines
856 B
TypeScript
/**
|
|
* 消息同步请求 DTO
|
|
*/
|
|
import {
|
|
ChatSyncRequestSchema,
|
|
type ChatSyncRequestInput,
|
|
type ChatSyncRequestData,
|
|
} from "@/data/schemas/chat/chat_sync_request";
|
|
import { SyncMessage } from "./sync_message";
|
|
|
|
export class ChatSyncRequest {
|
|
declare readonly messages: SyncMessage[];
|
|
|
|
private constructor(input: ChatSyncRequestInput) {
|
|
const data = ChatSyncRequestSchema.parse(input);
|
|
Object.assign(this, {
|
|
...data,
|
|
messages: data.messages.map((m) => SyncMessage.from(m)),
|
|
});
|
|
Object.freeze(this);
|
|
}
|
|
|
|
static from(input: ChatSyncRequestInput): ChatSyncRequest {
|
|
return new ChatSyncRequest(input);
|
|
}
|
|
|
|
static fromJson(json: unknown): ChatSyncRequest {
|
|
return ChatSyncRequest.from(json as ChatSyncRequestInput);
|
|
}
|
|
|
|
toJson(): ChatSyncRequestData {
|
|
return ChatSyncRequestSchema.parse(this);
|
|
}
|
|
}
|