Preview: sharing types/validatoin#853
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request initiates a significant architectural change by establishing a monorepo setup. The primary goal is to centralize common type definitions and their corresponding validation schemas into a dedicated shared package. This move aims to enhance code reusability, maintain consistency across different application parts, and streamline future development by providing a single source of truth for data structures. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request sets up a shared package for types and validation using Zod, refactoring Goals and DayData types out of the frontend application. This is a great step towards a monorepo architecture. My review includes a few suggestions to improve the new pnpm workspace configuration and refine one of the Zod schemas for better type safety and clarity. Specifically, I've pointed out a potential issue with the package manager lock files and a path in the workspace configuration, and suggested a cleaner way to define the goalsSchema.
| @@ -0,0 +1,1069 @@ | |||
| { | |||
There was a problem hiding this comment.
| @@ -0,0 +1,4 @@ | |||
| packages: | |||
| - "frontend" | |||
There was a problem hiding this comment.
The path for the frontend package seems to be incorrect. Based on the file paths in this pull request (e.g., SparkyFitnessFrontend/src/api/Diary/foodEntryService.ts), the package directory is SparkyFitnessFrontend, not frontend. Please update this path to match the directory name to ensure the pnpm workspace is configured correctly.
- "SparkyFitnessFrontend"| export const goalsSchema = z.record(z.union([z.number(), z.undefined()])).and( | ||
| z.object({ | ||
| calories: z.number(), | ||
| protein: z.number(), | ||
| carbs: z.number(), | ||
| fat: z.number(), | ||
| water_goal_ml: z.number(), | ||
| dietary_fiber: z.number().optional(), | ||
| }), | ||
| ); |
There was a problem hiding this comment.
The generated goalsSchema is a bit complex and allows custom nutrient properties to be undefined, which differs from the original [key: string]: number index signature. You can define this schema more concisely and accurately using .catchall(z.number()). This will enforce that any extra properties are numbers, aligning with the original intent and improving type safety.
export const goalsSchema = z.object({
calories: z.number(),
protein: z.number(),
carbs: z.number(),
fat: z.number(),
water_goal_ml: z.number(),
dietary_fiber: z.number().optional(),
}).catchall(z.number());
Description
Preview for sharing types/schemas