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 🙏

© 2024 – Pkg Stats / Ryan Hefner

schema-version

v0.0.5

Published

A utility for managing data schema versions. Allows you to migrate between versions, migrate to latest version, and provide version maps for backwards compatibility.

Downloads

3

Readme

schema-version

A utility for managing data schema versions. Allows you to migrate between versions, migrate to latest version, and provide version maps for backwards compatibility.

The use case that inspired the library was managing items in a noSQL database that could be in the shape of various versions of their schema, migrating those items to the latest versions and providing backwards compatibility through the version map feature.

  • Supports async upgrade/downgrade migrations
  • Typescript support
  • Lightweight, no dependencies

Usage

Defining Schema Versions

  • Extend the SchemaVersion class to define and version and it's migration (up/down) methods.
  • Typically an initial version will only have an up migration, latest version will only have a down migration, and between methods will have both up and down migrations.
  • Use the SchemaVersionController to link the SchemaVersions together.
export namespace User {
 export interface V1 {
  firstName: string;
  schemaVersion: 1; // schemaVersion attribute is required in each schema
 }

 export interface V2 {
  firstName: string;
  lastName: string;
  schemaVersion: 2;
 }

 export interface V3 {
  fullName: string;
  schemaVersion: 3;
 }
}

export class UserV1 extends SchemaVersion<User.V1> {
 up = () => {
  return new UserV2({
   ...this.item,
   lastName: "lastName",
   schemaVersion: 2,
  });
 };
}

export class UserV2 extends SchemaVersion<User.V2> {
 down = () => {
  return new UserV1({
   firstName: this.item.firstName,
   schemaVersion: 1,
  });
 };

 up = async () => {
  await setTimeout(1000); // Simulating async

  return new UserV3({
   fullName: this.item.firstName + " " + this.item.lastName,
   schemaVersion: 3,
  });
 };
}

export class UserV3 extends SchemaVersion<User.V3> {
 down = async () => {
  const [firstName, lastName] = this.item.fullName.split(" ");

  await setTimeout(1000); // Simulating async

  return new UserV2({
   firstName,
   lastName,
   schemaVersion: 2,
  });
 };
}

export const User = new SchemaVersionController({
 [1]: UserV1,
 [2]: UserV2,
 [3]: UserV3,
});

Using Version Item Methods

const v1 = new User.Item({
	firstName: "firstName",
	schemaVersion: 1,
});

const itemData = v1.item; // returns the item data

const itemDataLatest = await v1.itemLatest; // returns the item data migrated to latest version (v3)

const itemDataMap = await v1.map; // returns the item data migrated to all versions and mapped by schemaVersion attribute

const v2 = await v1.vUp; // Migrated to schemaVersion 2

const v1_2 = await v2.vDown; // Migrated back to schemaVersion 1

const v3 = await v1.vMax; // Migrated through to schemaVersion 3

const v1_3 = await v3.vMin; // Migrated back through to schemaVersion 1

const vMap = await v1.vMap; // Returns a map of version items