refactor(data): merge DTO models into schemas
This commit is contained in:
@@ -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,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,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,4 +1,4 @@
|
||||
import type { UiMessage } from "@/data/dto/chat";
|
||||
import type { UiMessage } from "@/stores/chat/ui-message";
|
||||
|
||||
import type { ChatState } from "../chat-state";
|
||||
|
||||
|
||||
@@ -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,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";
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,3 +5,4 @@ export * from "./chat-events";
|
||||
export * from "./helper";
|
||||
export * from "./chat-machine";
|
||||
export * from "./chat-state";
|
||||
export * from "./ui-message";
|
||||
|
||||
@@ -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,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 },
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
}),
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user