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

migratype

v0.0.1

Published

> πŸ”’β–ΆπŸ”’ Safe runtime type migrations for TypeScript. Stay safe! πŸ™

Readme

migratype

πŸ”’β–ΆπŸ”’ Safe runtime type migrations for TypeScript. Stay safe! πŸ™

🀝 Change your payload types with confidence

πŸ”’ Built on top of the amazing io-ts library

Why?

TypeScript and static types in general provide great developer experience, ensuring type assertions on compile time. This, however, have no guarantee that a 3rd party, like a user or a database of some sort, will provide the exact data structure as your software expects. This is an accident waiting to happen. This is where io-ts gets into the picture, and provide a runtime mechanism to decode any values to your types, safely.

But this is not enough too.

Type definitions tend to change, as we add more features. Our schema change, and there might be some incompatibility between our server and our client. It can be a service worker that cached an older version of your front-end, or it can be a CLI tool that a project hasn't updated yet. It can even be a MongoDB database that stores an old version of your payload.

Right now, the way of handling these changes is to guard against malformed data directly in your code. You can use io-ts to verify that the input and expected type definition are aligned, but if you want to migrate between older to newer schema versions, well, you're out of luck, and you have to do it manually.

This is where migratype comes to play.

Usage

migratype is a runtime library that allow you to stack io-ts declarations on top of each other to declare a relationship of migrations between types:

import { migratype } from "migratype";
import * as t from "io-ts";
import { right, left } from "fp-ts/lib/Either";

const User = migratable("User", t.string) // Let's say we declare a user by it's full name
  .extend({
    type: t.type({ name: t.string }), // then we understand that we may want to have something more than just a string
    migrate: name => right({ name }) // now, we have to provide a migration function between the types
  })
  .extend({
    type: t.type({
      // now we want to split first and last name
      firstName: t.string,
      lastName: t.string
    }),
    migrate: ({ name }) => {
      const [firstName, lastName] = name.split(" ", 2); // split the name into 2 strings

      if (!lastName && firstName === "Madonna") {
        return right({ firstName: "Madonna", lastName: "⭐🌟✨" }); // Madonna is an exception
      } else if (!lastName) {
        return left({
          // use `Either.left` to tell that a migration failed
          key: "name",
          message: "Name doesn't have any spaces, therefore can't be migrated"
        });
      }

      return right({ firstName, lastName }); // Either.right is for successful migration
    }
  });

User.decode("Scott Pilgrim"); // right({ firstName: "Scott", lastName: "Pilgrim" })
User.decode({ name: "Scott Pilgrim" }); // right({ firstName: "Scott", lastName: "Pilgrim" })
User.decode("Scott"); // left(...)
User.decode("Madonna"); // right({ firstName: "Madonna", lastName: "⭐🌟✨" })

More thoughts πŸ€”

The only reference I found for migratable types in any language, is Milk. Milk is a layer on top of multiple ReasonML JSON parsers, and has the notion of type migrations.

I think it would be very nice to have a "lockfile" of some sort that will be generated in a build step, to reduce the verboseness of the type definitions (migratable.extend.extend.extend...). This, however, makes another build step and it is kinda error-prone, but I think it's an area worth exploring.

Stay safe.