Drop .cursor rules and npm lockfile; standardize on Bun; remove v1 migration code
- Delete .cursor/rules/boardui.mdc (rules live in AGENTS.md) and package-lock.json; README now uses bun install/dev/test/build - Remove migrateV1Slots, the v1 localStorage key, the legacy "asian" cuisine expansion, the ownsPantryStaples fallback, and the pre-BoardUI theme-key carryover in the layout init script; drop their tests Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
df5dd3a70e
commit
2cd683e64a
7 changed files with 14 additions and 6904 deletions
|
|
@ -8,9 +8,7 @@ import { RECIPES_BY_ID } from "./recipes";
|
|||
//
|
||||
// Used by:
|
||||
// - the Server Action (input from the network is untrusted)
|
||||
// - the localStorage loader (old versions of the app saved older shapes)
|
||||
//
|
||||
// Old-shape migrations live here too, so components never see legacy data.
|
||||
// - the localStorage loader (saved data is untrusted too)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export const DEFAULT_STATE: MealPlanState = {
|
||||
|
|
@ -26,11 +24,6 @@ export const DEFAULT_STATE: MealPlanState = {
|
|||
slots: {},
|
||||
};
|
||||
|
||||
/** v1 had a single "asian" cuisine; it was split into four. */
|
||||
const LEGACY_CUISINES: Record<string, Cuisine[]> = {
|
||||
asian: ["chinese", "japanese", "korean", "thai"],
|
||||
};
|
||||
|
||||
const VALID_APPLIANCES = new Set<string>(APPLIANCES.map((a) => a.id));
|
||||
const VALID_CUISINES = new Set<string>(CUISINES.map((c) => c.id));
|
||||
const VALID_STYLES = new Set<string>(STYLES.map((s) => s.id));
|
||||
|
|
@ -53,17 +46,10 @@ export function sanitizeState(input: unknown): MealPlanState {
|
|||
if (/^[0-6]-[1-3]$/.test(key) && typeof recipeId === "string" && RECIPES_BY_ID.has(recipeId)) slots[key] = recipeId;
|
||||
}
|
||||
|
||||
// Cuisines, with the legacy "asian" expanded.
|
||||
const cuisinesIn = Array.isArray(raw.preferredCuisines) ? raw.preferredCuisines.flatMap((c) => LEGACY_CUISINES[c as string] ?? [c]) : [];
|
||||
|
||||
// Items. v1 had `ownsPantryStaples: boolean` instead of an on-hand list.
|
||||
// Items.
|
||||
const isItem = (id: string) => CATALOG_BY_ID.has(id);
|
||||
const avoidedItems = onlyValid<ItemId>(raw.avoidedItems, isItem);
|
||||
const onHandItems = Array.isArray(raw.onHandItems)
|
||||
? onlyValid<ItemId>(raw.onHandItems, isItem)
|
||||
: raw.ownsPantryStaples === false
|
||||
? []
|
||||
: PANTRY_STAPLE_IDS;
|
||||
const onHandItems = Array.isArray(raw.onHandItems) ? onlyValid<ItemId>(raw.onHandItems, isItem) : PANTRY_STAPLE_IDS;
|
||||
|
||||
return {
|
||||
targetBudget: clamp(raw.targetBudget, 10, 1000, DEFAULT_STATE.targetBudget),
|
||||
|
|
@ -73,7 +59,7 @@ export function sanitizeState(input: unknown): MealPlanState {
|
|||
selectedAppliances: Array.isArray(raw.selectedAppliances)
|
||||
? onlyValid<Appliance>(raw.selectedAppliances, (v) => VALID_APPLIANCES.has(v))
|
||||
: DEFAULT_STATE.selectedAppliances,
|
||||
preferredCuisines: onlyValid<Cuisine>(cuisinesIn, (v) => VALID_CUISINES.has(v)),
|
||||
preferredCuisines: onlyValid<Cuisine>(raw.preferredCuisines, (v) => VALID_CUISINES.has(v)),
|
||||
preferredStyles: onlyValid<CookingStyle>(raw.preferredStyles, (v) => VALID_STYLES.has(v)),
|
||||
avoidedItems,
|
||||
// An item can't be both avoided and on hand; "avoid" wins.
|
||||
|
|
@ -81,26 +67,3 @@ export function sanitizeState(input: unknown): MealPlanState {
|
|||
slots,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Plans saved before meal numbers were fixed counted from the first VISIBLE
|
||||
* meal: with 2 meals a day, "1" meant Lunch. Today "1" is always Breakfast,
|
||||
* so shift each meal up by the number of meals that were hidden in front of it.
|
||||
* 2 meals/day: 1 (Lunch) → 2, 2 (Dinner) → 3
|
||||
* 1 meal/day: 1 (Dinner) → 3
|
||||
* Anything that lands past Dinner was already hidden and is dropped.
|
||||
*/
|
||||
export function migrateV1Slots(input: unknown): unknown {
|
||||
if (typeof input !== "object" || input === null) return input;
|
||||
const raw = input as Record<string, unknown>;
|
||||
const mealsPerDay = Math.round(clamp(raw.mealsPerDay, 1, 3, DEFAULT_STATE.mealsPerDay));
|
||||
const offset = 3 - mealsPerDay;
|
||||
|
||||
const slots: Record<string, unknown> = {};
|
||||
for (const [key, recipeId] of Object.entries((raw.slots as Record<string, unknown>) ?? {})) {
|
||||
const [day, meal] = key.split("-").map(Number);
|
||||
const fixedMeal = meal + offset;
|
||||
if (fixedMeal >= 1 && fixedMeal <= 3) slots[`${day}-${fixedMeal}`] = recipeId;
|
||||
}
|
||||
return { ...raw, slots };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue