Skip to content

Conversation

@Newbie012
Copy link
Collaborator

@Newbie012 Newbie012 commented Nov 13, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Fixed improper transformation of JSON/JSONB fields when using the fieldTransform option. Object keys in JSON build operations are now correctly transformed to the specified case style.
  • Tests

    • Added comprehensive tests to verify fieldTransform behavior for JSONB keys. Tests validate camelCase transformations for both top-level and nested keys within JSON objects.

@changeset-bot
Copy link

changeset-bot bot commented Nov 13, 2025

🦋 Changeset detected

Latest commit: c0cb750

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@ts-safeql/eslint-plugin Patch
@ts-safeql/generate Patch
@ts-safeql-demos/basic-flat-config Patch
@ts-safeql-demos/basic-migrations-raw Patch
@ts-safeql-demos/basic-transform-type Patch
@ts-safeql-demos/basic Patch
@ts-safeql-demos/big-project Patch
@ts-safeql-demos/config-file-flat-config Patch
@ts-safeql-demos/from-config-file Patch
@ts-safeql-demos/multi-connections Patch
@ts-safeql-demos/playground Patch
@ts-safeql-demos/postgresjs-custom-types Patch
@ts-safeql-demos/postgresjs-demo Patch
@ts-safeql-demos/vercel-postgres Patch
@ts-safeql/shared Patch
@ts-safeql/sql-ast Patch
@ts-safeql/test-utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Nov 13, 2025

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

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
safeql Ignored Ignored Nov 13, 2025 10:11pm

@coderabbitai
Copy link

coderabbitai bot commented Nov 13, 2025

Walkthrough

The changes add support for the fieldTransform option to properly transform JSON/JSONB field keys when using the sql tag. This includes threading the fieldTransform configuration through AST description logic, applying case transformation to JSON build object keys, and adding comprehensive tests to verify the behavior.

Changes

Cohort / File(s) Summary
Changeset documentation
.changeset/proud-webs-see.md
Documents a patch fix for @ts-safeql/eslint-plugin and @ts-safeql/generate enabling proper transformation of json/b fields when using fieldTransform.
Test coverage
packages/eslint-plugin/src/rules/check-sql.test.ts
Adds test cases validating fieldTransform behavior for jsonb keys, including valid cases for top-level and nested jsonb_build_object key camelCase transformation, and invalid cases enforcing that incorrectTypeAnnotations errors are raised when transformed types don't match.
AST description logic
packages/generate/src/ast-describe.ts
Imports toCase and IdentiferCase from shared; adds fieldTransform option to ASTDescriptionOptions; threads fieldTransform through recursive AST description calls and applies key transformation in JSON build object function calls using toCase.
Code generation
packages/generate/src/generate.ts
Propagates fieldTransform through the getASTDescription call to enable the AST description step to apply field transformations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Changes follow a consistent, repetitive pattern of threading a configuration option through multiple layers of existing code
  • Test additions are straightforward validations of expected behavior
  • No complex logic changes; primary modification is applying an existing utility function (toCase) to JSON keys during AST description

Poem

🐰 A transformation most grand,
JSON keys now shift at command,
camelCase flows through the night,
fieldTransform makes all things right!
With whiskers and code, we expand. 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely describes the main change: fixing json/b nested fields casing behavior when using fieldTransform.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-nested-camel

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05622b1 and c0cb750.

📒 Files selected for processing (4)
  • .changeset/proud-webs-see.md (1 hunks)
  • packages/eslint-plugin/src/rules/check-sql.test.ts (2 hunks)
  • packages/generate/src/ast-describe.ts (4 hunks)
  • packages/generate/src/generate.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/generate/src/ast-describe.ts (1)
packages/shared/src/case.ts (2)
  • IdentiferCase (3-3)
  • toCase (5-20)
🪛 LanguageTool
.changeset/proud-webs-see.md

[style] ~5-~5: Consider using a different verb for a more formal wording.
Context: ...patch "@ts-safeql/generate": patch --- fixed an issue where json/b fields weren't tr...

(FIX_RESOLVE)

🔇 Additional comments (10)
.changeset/proud-webs-see.md (1)

1-6: LGTM! Changeset properly documents the fix.

The changeset correctly identifies both affected packages and clearly describes the fix. The static analysis suggestion to use "resolved" instead of "fixed" is stylistic and optional for changelog entries.

packages/generate/src/generate.ts (2)

265-275: LGTM! FieldTransform properly threaded through AST description.

The fieldTransform parameter is correctly propagated from GenerateParams to the getASTDescription call, enabling field name transformations in the AST description pipeline.


292-303: LGTM! FieldTransform correctly added to context.

The fieldTransform is properly included in the GenerateContext, making it available for downstream usage in field name resolution.

packages/eslint-plugin/src/rules/check-sql.test.ts (3)

1881-1894: LGTM! Test correctly verifies fieldTransform on top-level jsonb keys.

This test properly validates that when fieldTransform: "camel" is configured, both the column alias (candidate_locationscandidateLocations) and nested JSON object keys (is_selectedisSelected) are transformed to camelCase.


1895-1907: LGTM! Test correctly verifies fieldTransform on nested jsonb keys.

This test validates that fieldTransform is applied recursively to nested jsonb_build_object keys, ensuring that multi-level JSON structures are properly transformed (outer_keyouterKey, inner_keyinnerKey).


2027-2049: LGTM! Test correctly verifies fieldTransform enforcement.

This test ensures that when fieldTransform: "camel" is configured, incorrect type annotations using snake_case JSON keys (e.g., is_selected) are flagged with incorrectTypeAnnotations and auto-fixed to camelCase (isSelected).

packages/generate/src/ast-describe.ts (4)

1-1: LGTM! Necessary imports added for fieldTransform functionality.

The imports of toCase and IdentiferCase from @ts-safeql/shared provide the type definition and transformation function needed to support the new fieldTransform feature.


20-30: LGTM! FieldTransform properly added to options interface.

The fieldTransform: IdentiferCase | undefined field is correctly added to ASTDescriptionOptions, making it available throughout the AST description pipeline while maintaining backward compatibility through the optional type.


556-576: LGTM! FieldTransform properly propagated to nested select statements.

The fieldTransform is correctly threaded through to recursive getASTDescription calls when handling nested SelectStmt nodes, ensuring that field transformations apply consistently to subqueries and CTEs.


899-951: LGTM! JSON build object keys correctly transformed.

The core fix is implemented on line 941 where toCase(alias, context.fieldTransform) transforms JSON object keys before adding them to the type description. This ensures that jsonb_build_object keys are transformed according to the configured fieldTransform option (e.g., 'is_selected''isSelected' when using camelCase).

The transformation is applied at the right point in the pipeline, after extracting the key from the SQL AST but before building the TypeScript type representation.


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 and usage tips.

@Newbie012 Newbie012 enabled auto-merge (squash) November 13, 2025 22:12
@Newbie012 Newbie012 merged commit 6d1a7dc into main Nov 13, 2025
4 of 5 checks passed
@Newbie012 Newbie012 deleted the fix-nested-camel branch November 13, 2025 22:14
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.

2 participants