Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x | // src/types/ai.ts
import { z } from 'zod';
// Helper for consistent required string validation (handles missing/null/empty)
// This is moved here as it's directly related to the schemas.
export const requiredString = (message: string) =>
z.preprocess((val) => val ?? '', z.string().min(1, message));
// --- Zod Schemas for AI Response Validation ---
// These schemas define the expected structure of data returned by the AI.
// They are used for validation and type inference across multiple services.
// Note: These schemas use snake_case to match the database columns and AI prompt instructions,
// distinguishing them from internal camelCase application variables.
export const ExtractedFlyerItemSchema = z.object({
item: z.string().nullish(),
price_display: z.string().nullish(),
price_in_cents: z.number().nullish(),
quantity: z.string().nullish(),
category_name: z.string().nullish(),
master_item_id: z.number().nullish(), // .nullish() allows null or undefined
});
export const AiFlyerDataSchema = z.object({
store_name: z.string().nullable(),
valid_from: z.string().nullable(),
valid_to: z.string().nullable(),
store_address: z.string().nullable(),
items: z.array(ExtractedFlyerItemSchema),
}); |