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

@ferrow/schema-evolution

v2.0.0

Published

Versioned data migrator: register {from, to, migrate} transforms, walk any document to the latest schema version (or a target), support downgrade via revert(), batch helper, and gap/monotonicity validation at registration.

Readme

schema-evolution

CI

A versioned data migrator. Register {from, to, migrate} transforms and walk any document — by its own schemaVersion field — forward to the latest version (or a specific target), with optional downgrade support and batch migration.

This fixes the classic bug in naive migrator implementations: running every registered transform on every document regardless of its starting version (so a v2 document gets the v1→v2 transform re-applied on top of already-migrated data). Here, each transform only fires when the document's current version actually matches that transform's from.

Install

npm install schema-evolution

Quickstart

import { SchemaMigrator } from "schema-evolution";

interface UserDoc {
  schemaVersion: number;
  firstName?: string;
  lastName?: string;
  fullName?: string;
}

const migrator = new SchemaMigrator<UserDoc>();

migrator.register({
  from: 1,
  to: 2,
  migrate: (doc) => ({ ...doc, fullName: `${doc.firstName} ${doc.lastName}` }),
  revert: (doc) => {
    const [firstName, ...rest] = doc.fullName!.split(" ");
    return { schemaVersion: doc.schemaVersion, firstName, lastName: rest.join(" ") };
  },
});

const v1doc: UserDoc = { schemaVersion: 1, firstName: "Ada", lastName: "Lovelace" };
const latest = migrator.migrate(v1doc); // { schemaVersion: 2, fullName: "Ada Lovelace", ... }

API

new SchemaMigrator<T extends SchemaDoc>()

SchemaDoc is any object with a numeric schemaVersion field.

  • register(transform: Transform<T>): this Transform: { from: number, to: number, migrate(doc): doc, revert?(doc): doc }. Forward transforms must step exactly +1 (to === from + 1) — this keeps gap detection well-defined. Throws SchemaMonotonicityError on a bad step, or a plain Error on a duplicate from.
  • migrate(doc: T, options?: { toVersion?: number }): T Walks the chain from doc.schemaVersion to toVersion (default: latestVersion). Forward if toVersion is higher, backward (via revert) if lower. Throws SchemaGapError if a required step isn't registered, or a plain Error if a downgrade step has no revert.
  • migrateBatch(docs: T[], options?): { migrated: T[], errors: {index, doc, error}[] } Migrates each document independently; a failure on one doc doesn't stop the rest — failures are collected in errors instead of thrown.
  • latestVersion: number — highest version reachable by the registered chain.

Design notes

Requiring each forward transform to step by exactly +1 is a deliberate constraint: it means "is there a path from version N to version M" is always answerable by walking N, N+1, N+2, ... and checking each step exists, which is what makes gap detection precise instead of heuristic. The old unconditional-run bug is why migrate() re-checks the document's current version before every single step rather than just running through the registered transform list — a v2 document handed to a registry that also has a v1→v2 transform must never see that transform applied to it.


Sponsored by Ferrow


Part of the ferrow-toolkit collection · Sponsored by Ferrow