68 lines
2.8 KiB
TypeScript
68 lines
2.8 KiB
TypeScript
import type { components } from '@/api/types'
|
|
|
|
// Utility mapped types
|
|
export type Replace<T, M> = Omit<T, keyof M> & M
|
|
export type WithDates<T, K extends keyof T> = Replace<T, { [P in K]: Date | null }>
|
|
|
|
// Common helpers (intentionally minimal to avoid unused exports)
|
|
export type Lookup<T> = Record<string, T>
|
|
// Refs are optional and may be attached later by mappers (e.g., in sdk)
|
|
export type WithRefs<T, Refs extends object> = T & { [K in keyof Refs]?: Refs[K] | undefined }
|
|
|
|
// Domain type aliases
|
|
export type RecipeOut = components['schemas']['Recipe-Output']
|
|
export type MealOut = components['schemas']['Meal-Output']
|
|
export type Ingredient = components['schemas']['Ingredient']
|
|
export type Product = components['schemas']['Product']
|
|
export type Person = components['schemas']['Person']
|
|
export type RecipeInput = components['schemas']['Recipe-Input']
|
|
export type MealInput = components['schemas']['Meal-Input']
|
|
export type MealRecipeOut = components['schemas']['MealRecipe-Output']
|
|
|
|
// Domain shapes: only adjust where UI needs Dates
|
|
export type Recipe = WithDates<RecipeOut, 'dateCreated' | 'dateHidden'>
|
|
|
|
// MealRecipe with decoded recipe dates
|
|
export type MealRecipe = Replace<MealRecipeOut, { recipe: Recipe | null }>
|
|
|
|
// Meal with decoded dates and nested MealRecipe with decoded recipe dates
|
|
// Arrays (chefs, consumers, cleanup, recipes, extraIngredients) are non-nullable per OpenAPI spec
|
|
export type Meal = Replace<
|
|
WithDates<MealOut, 'suggestedDate' | 'consumedDate' | 'purchaseDate'>,
|
|
{
|
|
recipes: MealRecipe[]
|
|
chefs: Person[]
|
|
consumers: Person[]
|
|
cleanup: Person[]
|
|
extraIngredients: Ingredient[]
|
|
}
|
|
>
|
|
|
|
// Shopping domain shapes with dates normalized
|
|
export type ShoppingListItem = WithDates<components['schemas']['ShoppingListItem'], 'createdDate'>
|
|
type ShoppingListBase = WithDates<components['schemas']['ShoppingList'], 'createdDate'>
|
|
export type ShoppingList = Replace<ShoppingListBase, { items?: ShoppingListItem[] | undefined }>
|
|
|
|
// Refs attached to shopping list items
|
|
export type ShoppingListItemWithRefs = WithRefs<ShoppingListItem, { ingredient: Ingredient; recipe: Recipe; meal: Meal; list: ShoppingList }>
|
|
|
|
export type ShoppingListWithRefs = Replace<ShoppingList, { items?: ShoppingListItemWithRefs[] }>
|
|
|
|
// Lookup maps used by shopping mappings (all optional; mappers may omit absent ones)
|
|
export type ShoppingLookups = {
|
|
ingredientsLookup?: Lookup<Ingredient>
|
|
mealsLookup?: Lookup<Meal>
|
|
recipesLookup?: Lookup<Recipe>
|
|
shoppingListLookup?: Lookup<ShoppingList>
|
|
}
|
|
|
|
// DTO shapes returned by SDK for shopping pages
|
|
export type CurrentShoppingListDTO = {
|
|
outstandingItems: ShoppingListItemWithRefs[]
|
|
requestedMeals: ShoppingListItemWithRefs[]
|
|
purchasedItems: ShoppingListItemWithRefs[]
|
|
} & ShoppingLookups
|
|
|
|
export type PurchasedShoppingListDTO = ShoppingLookups & {
|
|
list?: (ShoppingList & { items?: ShoppingListItemWithRefs[] }) | undefined
|
|
}
|