feat(documents): zod validators for folder CRUD
createFolderSchema, renameFolderSchema, moveFolderSchema, moveDocumentToFolderSchema. Names: 1–200 chars, non-whitespace. parentId/folderId nullable to allow root. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
28
src/lib/validators/document-folders.ts
Normal file
28
src/lib/validators/document-folders.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const folderName = z
|
||||
.string()
|
||||
.min(1, 'Folder name is required')
|
||||
.max(200, 'Folder name cannot exceed 200 characters')
|
||||
.refine((s) => s.trim().length > 0, 'Folder name cannot be only whitespace');
|
||||
|
||||
export const createFolderSchema = z.object({
|
||||
name: folderName,
|
||||
parentId: z.string().nullable(),
|
||||
});
|
||||
export type CreateFolderInput = z.infer<typeof createFolderSchema>;
|
||||
|
||||
export const renameFolderSchema = z.object({
|
||||
name: folderName,
|
||||
});
|
||||
export type RenameFolderInput = z.infer<typeof renameFolderSchema>;
|
||||
|
||||
export const moveFolderSchema = z.object({
|
||||
parentId: z.string().nullable(),
|
||||
});
|
||||
export type MoveFolderInput = z.infer<typeof moveFolderSchema>;
|
||||
|
||||
export const moveDocumentToFolderSchema = z.object({
|
||||
folderId: z.string().nullable(),
|
||||
});
|
||||
export type MoveDocumentToFolderInput = z.infer<typeof moveDocumentToFolderSchema>;
|
||||
Reference in New Issue
Block a user