npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@joshuaavalon/fastify-plugin-typebox

v3.0.0

Published

Typebox plugin for fastify

Readme

@joshuaavalon/fastify-plugin-typebox

It uses @sinclair/typebox to handle validation and serialization. It adds support via validatorCompiler and serializerCompiler.

Since @sinclair/typebox provides type-safe JSON schema, this plugin allows type-safe in request and response payload.

Getting Started

This is a ESM only module. You must be using ESM in order to use this.

Install the package via your package manager.

npm install @joshuaavalon/fastify-plugin-typebox

Register the plugin to fastify

import fastify from "fastify";
import typeboxPlugin from "@joshuaavalon/fastify-plugin-typebox";

const app = await fastify();
await app.register(typeboxPlugin);

Options

logBindings

Optional

logBindings set the binding for all the log in this plugin.

Default to { plugin: "@joshuaavalon/fastify-plugin-typebox" }. Set to false to disable it.

references

Optional

references is referenced schemas ($ref). It is not recommended to use because it does not support type-safe data.

useDefault

Optional

useDefault is setting if default in JSON schema should be populated automatically.

Default to true.

Serialization

The payload of the request and response payload (JSON) are considered as encoded type in terms of Typebox transform. This means the based types should be JSON type instead internal type.

For example, if you want to create use ISO8601 as date time format for you JSON but parsed DateTime internally:

import { FormatRegistry, Type } from "@sinclair/typebox";
import { DateTime } from "luxon";

FormatRegistry.Set("date-time", (value) => DateTime.fromISO(value).isValid);

export const dateTimeSchema = Type.Transform(
  Type.String({
    description: "Date time in ISO8601 format",
    example: "2000-01-01T00:00:00+00:00",
    format: "date-time"
  })
)
  .Decode((value) => DateTime.fromISO(value, { zone: "UTC" }).toJSDate())
  .Encode((value) => value.toISOString());

Usage

import fastify from "fastify";
import { DateTime } from "luxon";
import typeboxPlugin from "@joshuaavalon/fastify-plugin-typebox";
import { dateTimeSchema } from "#schema";

const app = await fastify();
await app.register(typeboxPlugin);

const payloadSchema = Type.Object({
  value: Type.Transform(Type.String())
    .Decode((v) => Number.parseInt(v))
    .Encode((v) => v.toString())
});

app.post(
  "/",
  {
    schema: {
      body: payloadSchema,
      response: {
        200: Type.Object({
          success: Type.Boolean(),
          createdAt: dateTimeSchema
        })
      }
    }
  },
  async function handler(req, res) {
    const { value } = req.body;
    res.send({
      success: Number.isInteger(value),
      createdAt: DateTime.now()
    });
  }
);

Error

When validation failed, ValidationError is thrown.