-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(food): add explicit return types to repository helpers #1456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(food): add explicit return types to repository helpers #1456
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…ories Co-authored-by: marcuscastelo <27441558+marcuscastelo@users.noreply.github.com>
6b5c7b8
into
marcuscastelo/issue1447-remove-shims
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances type safety in the diet/food infrastructure by adding explicit Promise<readonly Food[]> return types to two previously untyped helper functions in supabaseFoodRepository.ts. These changes align with the broader encapsulation refactoring effort where repository implementations use factory functions and keep helpers file-local.
Key changes:
- Added explicit return type annotations to
fetchFoodsByNameandfetchFoodshelper functions - Return types correctly specify
Promise<readonly Food[]>, matching the actual implementation and interface contract
| async function fetchFoodsByName( | ||
| name: Required<Food>['name'], | ||
| params: FoodSearchParams = {}, | ||
| ) { | ||
| ): Promise<readonly Food[]> { |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fetchFoodsByName function lacks JSDoc documentation, creating inconsistency with other repository helper functions like fetchFoodById, fetchFoodByEan, and fetchFoodsByIds which all have comprehensive JSDoc. Consider adding documentation following the same pattern:
/**
* Fetches Foods by name using enhanced search with scoring.
* Supports both regular search and favorites-only search.
* @param name - The food name to search for
* @param params - Optional search parameters (userId, isFavoritesSearch, limit)
* @returns Array of matching Foods
* @throws Error on API/validation error
*/
async function fetchFoodsByName(
name: Required<Food>['name'],
params: FoodSearchParams = {},
): Promise<readonly Food[]> {| throw err | ||
| } | ||
| } | ||
|
|
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fetchFoods function lacks JSDoc documentation, creating inconsistency with other repository helper functions. Consider adding documentation following the pattern used elsewhere in this file:
/**
* Fetches all Foods with optional filtering.
* @param params - Optional search parameters (limit, allowedFoods, etc.)
* @returns Array of Foods
* @throws Error on API/validation error
*/
async function fetchFoods(
params: FoodSearchParams = {},
): Promise<readonly Food[]> {| /** | |
| * Fetches all Foods with optional filtering. | |
| * @param params - Optional search parameters (limit, allowedFoods, etc.) | |
| * @returns Array of Foods | |
| * @throws Error on API/validation error | |
| */ |
The
diet/foodinfrastructure already encapsulated helper functions correctly—all were file-local with only factory functions exported. Added missing explicit return types for type safety.Changes
Promise<readonly Food[]>return types tofetchFoodsandfetchFoodsByNameBefore:
After:
All repository consumers correctly use factory-returned instances.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.