feat(01-01): add database schema, shared Zod schemas, seed, and test infrastructure
- Create Drizzle schema with items, categories, and settings tables - Set up database connection singleton with WAL mode and foreign keys - Add seed script for default Uncategorized category - Create shared Zod validation schemas for items and categories - Export TypeScript types inferred from Zod and Drizzle schemas - Add in-memory SQLite test helper for isolated test databases - Wire seed into Hono server startup Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
25
src/shared/schemas.ts
Normal file
25
src/shared/schemas.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const createItemSchema = z.object({
|
||||
name: z.string().min(1, "Name is required"),
|
||||
weightGrams: z.number().nonnegative().optional(),
|
||||
priceCents: z.number().int().nonnegative().optional(),
|
||||
categoryId: z.number().int().positive(),
|
||||
notes: z.string().optional(),
|
||||
productUrl: z.string().url().optional().or(z.literal("")),
|
||||
});
|
||||
|
||||
export const updateItemSchema = createItemSchema.partial().extend({
|
||||
id: z.number().int().positive(),
|
||||
});
|
||||
|
||||
export const createCategorySchema = z.object({
|
||||
name: z.string().min(1, "Category name is required"),
|
||||
emoji: z.string().min(1).max(4).default("\u{1F4E6}"),
|
||||
});
|
||||
|
||||
export const updateCategorySchema = z.object({
|
||||
id: z.number().int().positive(),
|
||||
name: z.string().min(1).optional(),
|
||||
emoji: z.string().min(1).max(4).optional(),
|
||||
});
|
||||
18
src/shared/types.ts
Normal file
18
src/shared/types.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { z } from "zod";
|
||||
import type {
|
||||
createItemSchema,
|
||||
updateItemSchema,
|
||||
createCategorySchema,
|
||||
updateCategorySchema,
|
||||
} from "./schemas.ts";
|
||||
import type { items, categories } from "../db/schema.ts";
|
||||
|
||||
// Types inferred from Zod schemas
|
||||
export type CreateItem = z.infer<typeof createItemSchema>;
|
||||
export type UpdateItem = z.infer<typeof updateItemSchema>;
|
||||
export type CreateCategory = z.infer<typeof createCategorySchema>;
|
||||
export type UpdateCategory = z.infer<typeof updateCategorySchema>;
|
||||
|
||||
// Types inferred from Drizzle schema
|
||||
export type Item = typeof items.$inferSelect;
|
||||
export type Category = typeof categories.$inferSelect;
|
||||
Reference in New Issue
Block a user