Skip to content

refactor(measure): encapsulate infrastructure exports behind factories - #1469

Merged
marcuscastelo merged 3 commits into
rc/v0.16.0from
copilot/marcuscastelo-1403-encapsulate-infra-exports-again
Mar 24, 2026
Merged

marcuscastelo merged 3 commits into
rc/v0.16.0from
copilot/marcuscastelo-1403-encapsulate-infra-exports-again

Conversation

Copilot AI commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

The measure infrastructure was exposing implementation details beyond its intended public surface. This refactor narrows the module API so callers consume factories only, while internal helpers, DTOs, and constants remain private to the infrastructure layer.

  • Repository surface

    • measureRepository now exports only createMeasureRepository.
    • CRUD helper functions were made file-local.
  • Supabase gateway + mapper encapsulation

    • Replaced the exported mapper singleton with createSupabaseBodyMeasureMapper().
    • Kept Supabase DTO types private to the mapper module.
    • Updated the Supabase gateway to instantiate the mapper internally instead of importing implementation details.
  • Realtime cleanup

    • Kept initializeMeasureRealtime as the only public realtime entrypoint.
    • Moved the granular subscription helper to file-local scope.
  • Internal constant removal

    • Removed the standalone constants.ts export and localized the table name where it is used.
  • Export contract coverage

    • Added a focused infrastructure test that asserts the public export surface for the measure infra modules.
// before
export async function fetchUserBodyMeasures(...)
export const supabaseBodyMeasureMapper = { ... }
export function setupBodyMeasureRealtimeSubscription(...)

// after
export function createMeasureRepository() { ... }
export function createSupabaseBodyMeasureMapper() { ... }
export function initializeMeasureRealtime(...) { ... }

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • test.supabase.co
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development /home/REDACTED/work/macroflows/macroflows/node_modules/.pnpm/tinypool@1.1.1/node_modules/tinypool/dist/entry/process.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

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

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

Part of #1403

Scope / Representative files

  • src/modules/measure/infrastructure/measureRepository.ts
  • src/modules/measure/infrastructure/supabase/supabaseBodyMeasureGateway.ts

Deliverables & Acceptance Criteria

  • Only factories exported, call-sites updated, TypeScript/lint/tests pass.
    </issue_description>

<agent_instructions>pnpm check always green</agent_instructions>

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


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel

vercel Bot commented Mar 24, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
macroflows Ready Ready Preview, Comment Mar 24, 2026 9:13pm

Co-authored-by: marcuscastelo <27441558+marcuscastelo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/marcuscastelo/macroflows/sessions/7fde155e-0dd3-4a73-83c1-cf7b5e6b7899
Copilot AI changed the title [WIP] Refactor measure module to encapsulate infrastructure exports refactor(measure): encapsulate infrastructure exports behind factories Mar 24, 2026
Copilot AI requested a review from marcuscastelo March 24, 2026 20:51
@marcuscastelo
marcuscastelo marked this pull request as ready for review March 24, 2026 20:53
Copilot AI review requested due to automatic review settings March 24, 2026 20:53

Copilot AI left a comment

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.

Pull request overview

Refactors the measure module’s infrastructure layer to narrow its public API surface so consumers use factory functions only, while internal helpers/DTOs/constants remain private.

Changes:

  • Converted measure repository, Supabase gateway, and Supabase mapper to export only factory functions (helpers made file-local).
  • Simplified realtime module exports to a single public initializer and localized the table name constant where used.
  • Added an infrastructure-level test to assert the public export surface of measure infra modules.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/modules/measure/infrastructure/tests/measureInfrastructureExports.test.ts Adds a focused test asserting the infra modules export only the intended factory/initializer APIs.
src/modules/measure/infrastructure/supabase/supabaseMeasureMapper.ts Encapsulates Supabase DTO types and replaces exported singleton mapper with a factory.
src/modules/measure/infrastructure/supabase/supabaseBodyMeasureGateway.ts Stops importing exported constants/singletons; uses internal table name and internal mapper instance.
src/modules/measure/infrastructure/supabase/realtime.ts Limits exports to initializeMeasureRealtime and makes subscription helper file-local.
src/modules/measure/infrastructure/supabase/constants.ts Removes the exported table-name constant module.
src/modules/measure/infrastructure/measureRepository.ts Exports only createMeasureRepository; makes CRUD helpers file-local.

@marcuscastelo

Copy link
Copy Markdown
Owner

Encontrei um ponto que ainda ficou fora do padrao combinado do epico: o arquivo src/modules/measure/infrastructure/supabase/realtime.ts continua exportando initializeMeasureRealtime diretamente. Como esta PR ja toca o arquivo de realtime, vale encapsular tambem esse entrypoint atras de uma factory, por exemplo createMeasureRealtimeService retornando initializeMeasureRealtime, para manter a regra de a camada de infrastructure expor apenas factories. Hoje a PR fecha repository, gateway e mapper, mas deixa esse arquivo com um formato publico diferente do restante da migracao.

@marcuscastelo
marcuscastelo merged commit 3ea18e6 into rc/v0.16.0 Mar 24, 2026
5 checks passed
@marcuscastelo
marcuscastelo deleted the copilot/marcuscastelo-1403-encapsulate-infra-exports-again branch March 24, 2026 21:14

This branch was successfully deployed

1 active deployment
Preview — 9f5c459e Deployed Mar 24, 2026 by vercel[bot]
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.

measure: Encapsulate infra exports — export only factories

3 participants