Skip to content

Add a flat case-key mapper for the gift-links codec and serializer#28811

Draft
rob-ghost wants to merge 1 commit into
chore/gift-links-colocate-serializersfrom
chore/gift-links-codec-case-convert
Draft

Add a flat case-key mapper for the gift-links codec and serializer#28811
rob-ghost wants to merge 1 commit into
chore/gift-links-colocate-serializersfrom
chore/gift-links-codec-case-convert

Conversation

@rob-ghost

@rob-ghost rob-ghost commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Problem

The gift-links codec (database row to domain) and the response serializer (domain to API) each mapped fields with hand-written snake_case to camelCase object literals. The field list was repeated across the row schema, the domain schema, and the literal bodies, and it was hard to tell the deliberate, type-checked projection from incidental boilerplate.

Solution

Replace the literals in both places with a small in-house flat key mapper. It renames top-level keys only and copies values by reference, so the branded token, dates and nulls pass through untouched. The codec and the response schema still check the result, so adding, removing, or retyping any field - the token included - is a compile error, not a runtime surprise or a silent pass-through.

A deep third-party case-convert library was evaluated and rejected: it recurses into value types and mangles the branded token type, so it could not type-check the serializer at all.

Stacked on #28809. Retargets to main once that merges.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately describes the main change: replacing hand-written case mappers with the ts-case-convert library in the gift-links codec.
Description check ✅ Passed The description provides clear context about the problem (field duplication), solution (using ts-case-convert), and rationale (type safety and clarity).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/gift-links-codec-case-convert

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nx-cloud

nx-cloud Bot commented Jun 22, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 6923141

Command Status Duration Result
nx run ghost:test:ci:integration:no-coverage ✅ Succeeded 2m 20s View ↗
nx run ghost:test:ci:integration ✅ Succeeded 2m 3s View ↗
nx run ghost:test:ci:e2e ✅ Succeeded 7m 30s View ↗
nx run ghost:test:ci:e2e:no-coverage ✅ Succeeded 7m 6s View ↗
nx build @tryghost/activitypub ✅ Succeeded 3s View ↗
nx build @tryghost/sodo-search ✅ Succeeded <1s View ↗
nx build @tryghost/comments-ui ✅ Succeeded <1s View ↗
nx build @tryghost/portal ✅ Succeeded <1s View ↗
Additional runs (10) ✅ Succeeded ... View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-23 00:27:38 UTC

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (chore/gift-links-colocate-db-concerns@77a8b3b). Learn more about missing BASE report.

Additional details and impacted files
@@                           Coverage Diff                            @@
##             chore/gift-links-colocate-db-concerns   #28811   +/-   ##
========================================================================
  Coverage                                         ?   73.83%           
========================================================================
  Files                                            ?     1558           
  Lines                                            ?   134537           
  Branches                                         ?    16175           
========================================================================
  Hits                                             ?    99331           
  Misses                                           ?    34197           
  Partials                                         ?     1009           
Flag Coverage Δ
admin-tests 55.16% <ø> (?)
e2e-tests 75.93% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rob-ghost rob-ghost force-pushed the chore/gift-links-codec-case-convert branch from 1b3fd5e to fed7436 Compare June 23, 2026 00:10
no ref

Replaces the hand-written snake_case to camelCase object literals in the codec (decode/encode) and the serializer with camelKeys/snakeKeys from a small in-house mapper. It renames top-level keys only and copies values by reference, so the branded token, Date and null pass through untouched. z.codec and the response schema still check the result, so adding, removing or retyping any field (the token included) is a compile error. No third-party dependency: a deep case-convert library recurses into the branded token type and mangles it.
@rob-ghost rob-ghost changed the title Derive the gift-links codec case mapping from ts-case-convert Add a flat case-key mapper for the gift-links codec and serializer Jun 23, 2026
@rob-ghost rob-ghost changed the base branch from chore/gift-links-colocate-db-concerns to chore/gift-links-colocate-serializers June 23, 2026 00:12
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