Skip to content

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

Merged
rob-ghost merged 1 commit into
mainfrom
chore/gift-links-codec-case-convert
Jun 24, 2026
Merged

rob-ghost merged 1 commit into
mainfrom
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

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fa52b319-037a-4d5c-ba14-d84e3365a0bf

📥 Commits

Reviewing files that changed from the base of the PR and between 1b3fd5e and ce9b003.

📒 Files selected for processing (3)
  • ghost/core/core/server/services/gift-links/case-keys.ts
  • ghost/core/core/server/services/gift-links/queries.ts
  • ghost/core/core/server/services/gift-links/serializers.ts

Walkthrough

A new local module case-keys.ts is added to the gift-links service. It exports two TypeScript type mappers (CamelKeys<T>, SnakeKeys<T>) and two runtime functions (camelKeys, snakeKeys) that perform flat object-key case conversion using regex-based string transforms. queries.ts now imports these and applies them in giftLinkCodec for decode and encode, removing the prior per-field manual mapping. serializers.ts imports snakeKeys and uses it in toGiftLinksResponse to replace the equivalent manual field mapping.

Possibly related PRs

  • TryGhost/Ghost#28783: Modifies the same giftLinkCodec in gift-links/queries.ts, changing how snake_case DB fields are mapped to the GiftLink domain model.
  • TryGhost/Ghost#28809: Modifies the same gift-links/serializers.ts, centralizing the snake_case field mapping in toGiftLinksResponse.

Suggested reviewers

  • jonatansberg
🚥 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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 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 ce9b003

Command Status Duration Result
nx run ghost:test:ci:integration ✅ Succeeded 2m 42s View ↗
nx run ghost:test:ci:integration:no-coverage ✅ Succeeded 2m 37s View ↗
nx run ghost:test:ci:legacy ✅ Succeeded 2m 51s View ↗
nx run ghost:test:ci:e2e:no-coverage ✅ Succeeded 2m 15s View ↗
nx build @tryghost/comments-ui ✅ Succeeded <1s View ↗
nx build @tryghost/activitypub ✅ Succeeded 2s View ↗
nx build @tryghost/admin-toolbar ✅ Succeeded <1s View ↗
nx build @tryghost/portal ✅ Succeeded <1s View ↗
Additional runs (9) ✅ Succeeded ... View ↗

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


☁️ Nx Cloud last updated this comment at 2026-06-24 11:40:26 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
@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
@rob-ghost
rob-ghost force-pushed the chore/gift-links-colocate-serializers branch from fed7436 to 2f8214b Compare June 24, 2026 10:51
@rob-ghost
rob-ghost force-pushed the chore/gift-links-codec-case-convert branch from 6923141 to e1561e7 Compare June 24, 2026 10:52
@rob-ghost
rob-ghost force-pushed the chore/gift-links-colocate-serializers branch from 2f8214b to 3495e23 Compare June 24, 2026 11:10
@rob-ghost
rob-ghost force-pushed the chore/gift-links-codec-case-convert branch from e1561e7 to 3f5e093 Compare June 24, 2026 11:11
Base automatically changed from chore/gift-links-colocate-serializers to main June 24, 2026 11:27
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 force-pushed the chore/gift-links-codec-case-convert branch from 3f5e093 to ce9b003 Compare June 24, 2026 11:29
@rob-ghost
rob-ghost marked this pull request as ready for review June 24, 2026 12:45
@rob-ghost
rob-ghost merged commit 285eef2 into main Jun 24, 2026
49 of 75 checks passed
@rob-ghost
rob-ghost deleted the chore/gift-links-codec-case-convert branch June 24, 2026 12:45
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