add zod schemas & inferences

This commit is contained in:
thierryverse 2025-11-14 00:25:08 +02:00
parent 0c41e487d8
commit 77d49ca11c
10 changed files with 143 additions and 92 deletions

View file

@ -0,0 +1,35 @@
import { z } from "zod";
export const loginRequest = z.object({
email: z.string().email(),
password: z.string().min(1),
grant_type: z.string().optional(),
});
export const loginResponse = z.object({
access_token: z.string(),
token_type: z.string(),
});
export const registerRequest = z.object({
email: z.string().email(),
password: z.string().min(1),
is_active: z.boolean().optional(),
is_superuser: z.boolean().optional(),
is_verified: z.boolean().optional(),
});
export const registerResponse = z.object({
id: z.number(),
email: z.string().email(),
is_active: z.boolean(),
is_superuser: z.boolean(),
is_verified: z.boolean(),
pages_limit: z.number(),
pages_used: z.number(),
});
export type LoginRequest = z.infer<typeof loginRequest>;
export type LoginResponse = z.infer<typeof loginResponse>;
export type RegisterRequest = z.infer<typeof registerRequest>;
export type RegisterResponse = z.infer<typeof registerResponse>;

View file

@ -0,0 +1,48 @@
import { z } from "zod";
import { type Message } from "@ai-sdk/react";
import { paginationQueryParams } from ".";
export const chatTypeEnum = z.enum(["QNA"]);
export const chatSummary = z.object({
created_at: z.string(),
id: z.number(),
type: chatTypeEnum,
title: z.string(),
search_space_id: z.number(),
state_version: z.number(),
});
export const chatDetails = chatSummary.extend({
initial_connectors: z.array(z.string()),
messages: z.array(z.any()),
});
export const getChatDetailsRequest = chatSummary.pick({ id: true });
export const getChatsBySearchSpaceRequest = chatSummary.pick({
search_space_id: true,
}).merge(paginationQueryParams);
export const deleteChatResponse = z.object({
message: z.literal("Chat deleted successfully"),
});
export const deleteChatRequest = chatSummary.pick({ id: true });
export const createChatRequest = chatDetails
.omit({ created_at: true, id: true, state_version: true });
export const updateChatRequest = chatDetails
.omit({ created_at: true, state_version: true });
export type ChatSummary = z.infer<typeof chatSummary>;
export type ChatDetails = z.infer<typeof chatDetails> & { messages: Message[] };
export type GetChatDetailsRequest = z.infer<typeof getChatDetailsRequest>;
export type GetChatsBySearchSpaceRequest = z.infer<
typeof getChatsBySearchSpaceRequest
>;
export type DeleteChatResponse = z.infer<typeof deleteChatResponse>;
export type DeleteChatRequest = z.infer<typeof deleteChatRequest>;
export type CreateChatRequest = z.infer<typeof createChatRequest>;
export type UpdateChatRequest = z.infer<typeof updateChatRequest>;

View file

@ -0,0 +1,8 @@
import { z } from "zod";
export const paginationQueryParams = z.object({
limit: z.number().optional(),
skip: z.number().optional(),
});
export type PaginationQueryParams = z.infer<typeof paginationQueryParams>;