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,6 +1,6 @@
/**
* 发送消息请求
*
*
*/
import { z } from "zod";
@@ -10,48 +10,22 @@ import {
stringOrEmpty,
} from "../../nullable-defaults";
export const SendMessageRequestSchema = z.object({
characterId: z.string().min(1),
message: stringOrEmpty,
image: stringOrEmpty,
imageId: stringOrEmpty,
imageThumbUrl: stringOrEmpty,
imageMediumUrl: stringOrEmpty,
imageOriginalUrl: stringOrEmpty,
imageWidth: numberOrZero,
imageHeight: numberOrZero,
useWebSocket: booleanOrFalse,
});
export const SendMessageRequestSchema = z
.object({
characterId: z.string().min(1),
message: stringOrEmpty,
image: stringOrEmpty,
imageId: stringOrEmpty,
imageThumbUrl: stringOrEmpty,
imageMediumUrl: stringOrEmpty,
imageOriginalUrl: stringOrEmpty,
imageWidth: numberOrZero,
imageHeight: numberOrZero,
useWebSocket: booleanOrFalse,
})
.readonly();
export type SendMessageRequestInput = z.input<typeof SendMessageRequestSchema>;
export type SendMessageRequestData = z.output<typeof SendMessageRequestSchema>;
export class SendMessageRequest {
declare readonly characterId: string;
declare readonly message: string;
declare readonly image: string;
declare readonly imageId: string;
declare readonly imageThumbUrl: string;
declare readonly imageMediumUrl: string;
declare readonly imageOriginalUrl: string;
declare readonly imageWidth: number;
declare readonly imageHeight: number;
private constructor(input: SendMessageRequestInput) {
const data = SendMessageRequestSchema.parse(input);
Object.assign(this, data);
Object.freeze(this);
}
static from(input: SendMessageRequestInput): SendMessageRequest {
return new SendMessageRequest(input);
}
static fromJson(json: unknown): SendMessageRequest {
return SendMessageRequest.from(json as SendMessageRequestInput);
}
toJson(): SendMessageRequestData {
return SendMessageRequestSchema.parse(this);
}
}
export type SendMessageRequest = SendMessageRequestData;