refactor(schemas): group network schemas by direction
Move request and response schemas into matching subdirectories, extract the shared chat lock type, and update barrels and imports without changing wire formats.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* 聊天历史响应
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
arrayOrEmpty,
|
||||
booleanOrFalse,
|
||||
numberOrZero,
|
||||
} from "../../nullable-defaults";
|
||||
import { ChatMessageSchema } from "../chat_message";
|
||||
|
||||
export const ChatHistoryResponseSchema = z.object({
|
||||
messages: arrayOrEmpty(ChatMessageSchema),
|
||||
total: numberOrZero,
|
||||
limit: numberOrZero,
|
||||
offset: numberOrZero,
|
||||
isVip: booleanOrFalse,
|
||||
privateFreeLimit: numberOrZero,
|
||||
privateUsedToday: numberOrZero,
|
||||
privateCanViewFree: booleanOrFalse,
|
||||
});
|
||||
|
||||
export type ChatHistoryResponseInput = z.input<typeof ChatHistoryResponseSchema>;
|
||||
export type ChatHistoryResponseData = z.output<typeof ChatHistoryResponseSchema>;
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 发送消息响应
|
||||
*
|
||||
*/
|
||||
import { z } from "zod";
|
||||
import {
|
||||
booleanOrFalse,
|
||||
booleanOrTrue,
|
||||
numberOrLazy,
|
||||
numberOrZero,
|
||||
stringOrEmpty,
|
||||
} from "../../nullable-defaults";
|
||||
import { ChatImageSchema, ChatLockDetailSchema } from "../chat_payloads";
|
||||
|
||||
export const ChatSendResponseSchema = z.object({
|
||||
reply: stringOrEmpty,
|
||||
audioUrl: stringOrEmpty,
|
||||
messageId: stringOrEmpty,
|
||||
isGuest: booleanOrFalse,
|
||||
// 函数式 default —— 每次 parse 时重新调 Date.now()(后端不返回 timestamp 时用当下时间)
|
||||
timestamp: numberOrLazy(() => Date.now()),
|
||||
image: ChatImageSchema,
|
||||
lockDetail: ChatLockDetailSchema,
|
||||
canSendMessage: booleanOrTrue,
|
||||
creditBalance: numberOrZero,
|
||||
creditsCharged: numberOrZero,
|
||||
requiredCredits: numberOrZero,
|
||||
shortfallCredits: numberOrZero,
|
||||
});
|
||||
|
||||
export type ChatSendResponseInput = z.input<typeof ChatSendResponseSchema>;
|
||||
export type ChatSendResponseData = z.output<typeof ChatSendResponseSchema>;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* @file Automatically generated by barrelsby.
|
||||
*/
|
||||
|
||||
export * from "./chat_history_response";
|
||||
export * from "./chat_send_response";
|
||||
export * from "./unlock_history_response";
|
||||
export * from "./unlock_private_response";
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 一键解锁历史锁定消息响应
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
arrayOrEmpty,
|
||||
booleanOrFalse,
|
||||
numberOrZero,
|
||||
recordOrEmpty,
|
||||
} from "../../nullable-defaults";
|
||||
|
||||
export const UnlockHistoryCostsByMessageSchema = recordOrEmpty(z.number());
|
||||
|
||||
export const UnlockHistoryReasonSchema = z.enum([
|
||||
"ok",
|
||||
"insufficient_balance",
|
||||
"no_locked_messages",
|
||||
]);
|
||||
|
||||
export const UnlockHistoryResponseSchema = z.object({
|
||||
unlocked: booleanOrFalse,
|
||||
reason: UnlockHistoryReasonSchema,
|
||||
totalLocked: numberOrZero,
|
||||
unlockedCount: numberOrZero,
|
||||
privateCount: numberOrZero,
|
||||
imageCount: numberOrZero,
|
||||
voiceCount: numberOrZero,
|
||||
requiredCredits: numberOrZero,
|
||||
currentCredits: numberOrZero,
|
||||
remainingCredits: numberOrZero,
|
||||
shortfallCredits: numberOrZero,
|
||||
costsByMessage: UnlockHistoryCostsByMessageSchema,
|
||||
messageIds: arrayOrEmpty(z.string()),
|
||||
});
|
||||
|
||||
export type UnlockHistoryReason = z.output<typeof UnlockHistoryReasonSchema>;
|
||||
export type UnlockHistoryResponseInput = z.input<
|
||||
typeof UnlockHistoryResponseSchema
|
||||
>;
|
||||
export type UnlockHistoryResponseData = z.output<
|
||||
typeof UnlockHistoryResponseSchema
|
||||
>;
|
||||
@@ -0,0 +1,49 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
booleanOrFalse,
|
||||
numberOrZero,
|
||||
stringOrEmpty,
|
||||
stringOrNull,
|
||||
} from "../../nullable-defaults";
|
||||
import { ChatImageSchema, ChatLockDetailSchema } from "../chat_payloads";
|
||||
import { ChatLockTypeSchema } from "../chat_lock_type";
|
||||
|
||||
/**
|
||||
* 单条历史付费 / 私密消息解锁响应。
|
||||
*/
|
||||
export const UnlockPrivateReasonSchema = stringOrEmpty;
|
||||
|
||||
export const UnlockPrivateResponseSchema = z
|
||||
.object({
|
||||
unlocked: booleanOrFalse,
|
||||
content: stringOrEmpty,
|
||||
reply: stringOrEmpty,
|
||||
messageId: stringOrEmpty,
|
||||
message_id: stringOrEmpty,
|
||||
clientLockId: stringOrNull,
|
||||
lockType: ChatLockTypeSchema.nullable().default(null),
|
||||
audioUrl: stringOrEmpty,
|
||||
audio_url: stringOrEmpty,
|
||||
image: ChatImageSchema,
|
||||
reason: UnlockPrivateReasonSchema,
|
||||
creditBalance: numberOrZero,
|
||||
creditsCharged: numberOrZero,
|
||||
requiredCredits: numberOrZero,
|
||||
shortfallCredits: numberOrZero,
|
||||
lockDetail: ChatLockDetailSchema,
|
||||
})
|
||||
.transform(({ reply, message_id, audio_url, ...data }) => ({
|
||||
...data,
|
||||
content: data.content || reply,
|
||||
messageId: data.messageId || message_id,
|
||||
audioUrl: data.audioUrl || audio_url,
|
||||
}));
|
||||
|
||||
export type UnlockPrivateReason = z.output<typeof UnlockPrivateReasonSchema>;
|
||||
export type UnlockPrivateResponseInput = z.input<
|
||||
typeof UnlockPrivateResponseSchema
|
||||
>;
|
||||
export type UnlockPrivateResponseData = z.output<
|
||||
typeof UnlockPrivateResponseSchema
|
||||
>;
|
||||
Reference in New Issue
Block a user