Skip to content

feat(data-schema): add Schema.transform()#11234

Merged
mjackson merged 4 commits intoremix-run:mainfrom
mcansh:logan/data-schema-transform
Apr 25, 2026
Merged

feat(data-schema): add Schema.transform()#11234
mjackson merged 4 commits intoremix-run:mainfrom
mcansh:logan/data-schema-transform

Conversation

@mcansh
Copy link
Copy Markdown
Contributor

@mcansh mcansh commented Apr 4, 2026

Add Schema.transform() to the data-schema chainable API so schemas can map a successfully validated output value into a new output value and type.

let Event = object({
  id: string(),
  createdAt: string()
    .refine((value) => !Number.isNaN(Date.parse(value)), 'Expected valid date')
    .transform((value) => new Date(value)),
})
  • Runs transformers after the underlying schema succeeds and leaves validation failures untouched.
  • Preserves the original input type while changing the schema output type.
  • Documents usage and adds a release note for @remix-run/data-schema.

mcansh added 2 commits April 3, 2026 23:04
…formation

Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
Copilot AI review requested due to automatic review settings April 4, 2026 03:12
@mcansh mcansh changed the title feat(data-schema): add support for .transform feat(data-schema): add support for transforming output of schema Apr 4, 2026
Copy link
Copy Markdown

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 adds a Schema.transform(...) modifier to data-schema so consumers can map a successfully-validated output value into a new output type, and introduces tests covering transform behavior and chaining with other modifiers.

Changes:

  • Added a new transform method to the Schema chainable API and its createSchema implementation.
  • Added tests for transform, including chaining order with refine.

Reviewed changes

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

File Description
packages/data-schema/src/lib/schema.ts Adds Schema.transform typing + implementation to map validated output to a new output type.
packages/data-schema/src/lib/schema.test.ts Adds test cases validating transform behavior and chaining with existing modifiers.

Comment thread packages/data-schema/src/lib/schema.test.ts Outdated
Comment thread packages/data-schema/src/lib/schema.ts Outdated
@mjackson mjackson changed the title feat(data-schema): add support for transforming output of schema feat(data-schema): add Schema.transform() Apr 25, 2026
@mjackson
Copy link
Copy Markdown
Member

thanks for the PR, @mcansh! 💪

@mjackson mjackson merged commit 8741632 into remix-run:main Apr 25, 2026
9 checks passed
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.

3 participants