Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 6, 2025

The diet/food infrastructure already encapsulated helper functions correctly—all were file-local with only factory functions exported. Added missing explicit return types for type safety.

Changes

  • supabaseFoodRepository.ts: Added explicit Promise<readonly Food[]> return types to fetchFoods and fetchFoodsByName

Before:

async function fetchFoodsByName(
  name: Required<Food>['name'],
  params: FoodSearchParams = {},
) {
  // ...
}

After:

async function fetchFoodsByName(
  name: Required<Food>['name'],
  params: FoodSearchParams = {},
): Promise<readonly Food[]> {
  // ...
}
  • apiFoodRepository.ts: No changes—already correct

All repository consumers correctly use factory-returned instances.

Original prompt

This section details on the original issue you should resolve

<issue_title>diet/food: Encapsulate infra exports — export only factories</issue_title>
<issue_description>## Summary

Refactor the diet/food module infrastructure to encapsulate implementation details: export only factory functions and keep helper functions file-local.

Part of #1403

Scope / Representative files

  • src/modules/diet/food/infrastructure/supabase/supabaseFoodRepository.ts
  • src/modules/diet/food/infrastructure/api/infrastructure/supabase/supabaseFoodRepository.ts
  • src/modules/diet/food/infrastructure/api/infrastructure/api/apiFoodRepository.ts
  • src/modules/diet/food/infrastructure/api/domain/apiFoodRepository.ts

Deliverables

  • Export only factories (e.g., createSupabaseFoodRepository, createApiFoodRepository).
  • Update call-sites to use repository instances.
  • Fix TypeScript/lint/test issues.

Acceptance Criteria

  • Internal helpers are not exported.
  • All calling code imports only factories and uses returned instances.
    </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel
Copy link

vercel bot commented Dec 6, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
macroflows Ready Ready Preview Comment Dec 6, 2025 6:41pm

…ories

Co-authored-by: marcuscastelo <27441558+marcuscastelo@users.noreply.github.com>
Copilot AI changed the title [WIP] Encapsulate infra exports by exporting only factories refactor(food): add explicit return types to repository helpers Dec 6, 2025
Copilot AI requested a review from marcuscastelo December 6, 2025 18:42
@marcuscastelo marcuscastelo linked an issue Dec 6, 2025 that may be closed by this pull request
@marcuscastelo marcuscastelo marked this pull request as ready for review December 6, 2025 18:59
Copilot AI review requested due to automatic review settings December 6, 2025 18:59
@marcuscastelo marcuscastelo added complexity-medium Medium implementation complexity refactor Code refactoring required backend Backend-specific issue or change labels Dec 6, 2025
@marcuscastelo marcuscastelo merged commit 6b5c7b8 into marcuscastelo/issue1447-remove-shims Dec 6, 2025
10 checks passed
@marcuscastelo marcuscastelo deleted the copilot/refactor-food-module-exports branch December 6, 2025 19:00
Copy link
Contributor

Copilot AI left a 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 fetchFoodsByName and fetchFoods helper functions
  • Return types correctly specify Promise<readonly Food[]>, matching the actual implementation and interface contract

Comment on lines 133 to +136
async function fetchFoodsByName(
name: Required<Food>['name'],
params: FoodSearchParams = {},
) {
): Promise<readonly Food[]> {
Copy link

Copilot AI Dec 6, 2025

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[]> {

Copilot uses AI. Check for mistakes.
throw err
}
}

Copy link

Copilot AI Dec 6, 2025

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[]> {
Suggested change
/**
* Fetches all Foods with optional filtering.
* @param params - Optional search parameters (limit, allowedFoods, etc.)
* @returns Array of Foods
* @throws Error on API/validation error
*/

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend-specific issue or change complexity-medium Medium implementation complexity refactor Code refactoring required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

diet/food: Encapsulate infra exports — export only factories

2 participants