Skip to content

Preview: sharing types/validatoin#853

Closed
Sim-sat wants to merge 1 commit intoCodeWithCJ:mainfrom
Sim-sat:zod-preview
Closed

Preview: sharing types/validatoin#853
Sim-sat wants to merge 1 commit intoCodeWithCJ:mainfrom
Sim-sat:zod-preview

Conversation

@Sim-sat
Copy link
Copy Markdown
Contributor

@Sim-sat Sim-sat commented Mar 6, 2026

Description

Preview for sharing types/schemas

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Monorepo Setup: A new monorepo structure was introduced using pnpm, defining 'frontend', 'mobile', and 'shared' packages to centralize common code.
  • Shared Types and Schemas: Core type definitions, specifically DayData and Goals, were extracted from the frontend application into a new @workspace/shared package. These types now include Zod schemas for validation.
  • Frontend Type Migration: The frontend application was updated to import DayData and Goals from the new @workspace/shared package, replacing previous local definitions.
  • TypeScript Configuration Updates: TypeScript configuration files (tsconfig.json and tsconfig.app.json) were modified to include path aliases and references to the new shared workspace.
Changelog
  • SparkyFitnessFrontend/src/api/Diary/foodEntryService.ts
    • Updated the import path for DayData and Goals to reference the new shared workspace.
  • SparkyFitnessFrontend/src/pages/Diary/DiaryTopControls.tsx
    • Updated the import path for Goals to reference the new shared workspace.
  • SparkyFitnessFrontend/src/pages/Diary/MiniNutritionTrends.tsx
    • Updated the import path for DayData to reference the new shared workspace.
  • SparkyFitnessFrontend/src/types/diary.ts
    • Removed the local definitions for Goals and DayData interfaces.
  • SparkyFitnessFrontend/src/utils/nutritionCalculations.ts
    • Updated the import path for Goals to reference the new shared workspace.
  • SparkyFitnessFrontend/tsconfig.app.json
    • Added a path alias for @workspace/shared and included the shared source directory in the compilation scope.
  • SparkyFitnessFrontend/tsconfig.json
    • Added a path alias for @workspace/shared.
  • package-lock.json
    • Added a new package-lock.json file, reflecting updated dependencies.
  • pnpm-lock.yaml
    • Added a new pnpm-lock.yaml file, indicating the adoption of pnpm for package management within the monorepo.
  • pnpm-workspace.yaml
    • Added a new pnpm-workspace.yaml file to define the monorepo structure, including 'frontend', 'mobile', and 'shared' packages.
  • shared/package.json
    • Added a new package.json for the @workspace/shared package, including zod for schema validation and ts-to-zod for schema generation.
  • shared/src/index.ts
    • Added an index file to export the diary schemas.
  • shared/src/schemas/diary.ts
    • Added Goals and DayData type definitions along with their corresponding Zod schemas.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread package-lock.json
@@ -0,0 +1,1069 @@
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This pull request introduces pnpm-lock.yaml, indicating a move to pnpm for package management. To avoid confusion and potential dependency conflicts, it's best to remove this package-lock.json file and rely solely on pnpm-lock.yaml as the single source of truth for locked dependency versions.

Comment thread pnpm-workspace.yaml
@@ -0,0 +1,4 @@
packages:
- "frontend"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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"

Comment on lines +6 to +15
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(),
}),
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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());

@Sim-sat Sim-sat closed this Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant