Skip to content

feat: add helper to register TypeBox string formats#265

Merged
Eomm merged 10 commits into
fastify:mainfrom
drewnetic:feat/register-typebox-formats
Jul 5, 2026
Merged

feat: add helper to register TypeBox string formats#265
Eomm merged 10 commits into
fastify:mainfrom
drewnetic:feat/register-typebox-formats

Conversation

@drewnetic

@drewnetic drewnetic commented Jan 3, 2026

Copy link
Copy Markdown
Contributor

What’s changed

This PR adds an official helper to register common string formats
(date, date-time, email, uuid, etc.) when using
TypeBoxValidatorCompiler.

Why

Fastify’s default AJV setup enables ajv-formats out of the box,
but TypeBox does not register formats automatically.
This helper avoids copy/paste workarounds and keeps behavior explicit,
without introducing breaking changes.

Notes

  • Formats are registered only when the helper is called
  • Works for both CJS and ESM builds
  • Includes runtime and type tests

Closes #84

Checklist

Comment thread formats.ts Outdated
Comment thread index.mts Outdated
Comment thread test/index.js Outdated
@drewnetic
drewnetic requested a review from ilteoood January 20, 2026 01:29
@drewnetic
drewnetic force-pushed the feat/register-typebox-formats branch from 9e77c88 to 6692ace Compare March 5, 2026 17:46
@drewnetic

Copy link
Copy Markdown
Contributor Author

Hi @ilteoood, just a gentle ping on this since it's been a few weeks!

As mentioned below, I had already addressed all your feedback. I just pushed a tiny commit today to fix a small typo in the tests (uri to url) and clean up a stray semicolon.

Everything should be good to go now! Let me know if you need anything else.

Comment thread README.md Outdated
@ilteoood
ilteoood self-requested a review March 6, 2026 16:36
@drewnetic
drewnetic force-pushed the feat/register-typebox-formats branch from 45c8ded to 5231040 Compare March 9, 2026 14:29
@drewnetic

Copy link
Copy Markdown
Contributor Author

Hi @ilteoood, just a quick update: I noticed the recent architectural changes for TS 5.9, so I went ahead and rebased this branch to resolve the merge conflicts. Everything is properly migrated to the new .ts setup and all tests are green again. Ready whenever you are! 🚀

drewnetic and others added 4 commits May 17, 2026 12:22
Co-authored-by: Matteo Pietro Dazzi <matteopietro.dazzi@gmail.com>
Signed-off-by: Andrew Gouvêa Gonçalves de Souza  <103960552+drewnetic@users.noreply.github.com>
@drewnetic
drewnetic force-pushed the feat/register-typebox-formats branch from 5231040 to a3a2b08 Compare May 18, 2026 00:39
@drewnetic

Copy link
Copy Markdown
Contributor Author

Hi @ilteoood! Just a gentle ping on this since it's been a while.

I've just rebased the branch to keep it fully up to date with the latest main. During the rebase, I took the opportunity to unify the formats helper directly inside index.ts instead of keeping it in a separate file. This simplifies the CJS/ESM post-build output, removes any extra export overhead, and keeps the package footprint minimal.

All previous feedback has been addressed, and everything is green and ready for another look whenever you have some time. Thank you!

@mcollina

Copy link
Copy Markdown
Member

CI is very red

Comment thread index.ts Outdated
Comment thread README.md Outdated
Comment thread index.ts Outdated
@drewnetic

Copy link
Copy Markdown
Contributor Author

As a side note for the team: while testing locally on Windows (and also via WSL/Ubuntu), npm test consistently failed during the build:test step with the following generic ATTW error:

Cannot read properties of undefined (reading 'filename')

I spent some time debugging this and the package output itself looks correct (npm pack contains all expected files and exports). test:node also passes successfully.

At the moment this seems to be related to attw@0.18.2 behavior in certain local environments rather than the actual package structure/runtime output, although I haven't isolated a minimal reproduction yet.

Just leaving this note here in case someone else hits the same issue locally while reviewing/testing the PR.

@drewnetic
drewnetic requested a review from ilteoood June 29, 2026 22:09
Comment thread package.json
@drewnetic
drewnetic requested review from Eomm and ilteoood July 3, 2026 23:07
@Eomm
Eomm merged commit 569fb67 into fastify:main Jul 5, 2026
14 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.

Type.String({ format: "date" }) doesn't work in body validator

4 participants