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-evolution

v0.0.5

Published

SchemaEvolution is a schema migration library that focuses on facilitating the evolution of schemas over time. It provides a set of tools and utilities to manage and transition between different versions of schemas within JavaScript applications.

Downloads

6

Readme

schema-revolution

schema-revolution is a schema migration library that focuses on facilitating the evolution of schemas over time. It provides a set of tools and utilities to manage and transition between different versions of schemas within JavaScript applications.

With schema-revolution, you can define schema objects that represent different versions or stages of your data structure. Each schema object includes a version identifier and a parse function that converts incoming data to the corresponding schema version.

The library allows you to create update paths that define the transitions between different schema versions. An update path consists of a source schema, a target schema, and an update function that transforms data from the source schema to the target schema.

Using these update paths, schema-revolution enables you to convert data from one schema version to another. It automatically determines the shortest path between two schema versions, considering the available update paths, and applies the necessary transformations to migrate the data.

schema-revolution provides flexibility and extensibility, allowing you to define and manage complex schema evolution scenarios. It helps ensure data compatibility and consistency when evolving your application's data structures over time.

By leveraging schema-revolution, you can handle schema changes, data migrations, and backward compatibility in a structured and manageable way, making it easier to adapt and evolve your application as requirements evolve.

Installation

To install the schema-revolution library, you can use your preferred package manager:

npm install schema-revolution

or

yarn add schema-revolution

Key Concepts

Schema

A schema represents the structure and behavior of a node in the graph. It consists of a unique identifier (v) of type Key and a parse method that converts raw data into a parsed representation based on the schema.

Edge

An edge represents a connection between two schemas in the graph. It defines the source (from) and target (to) schemas and provides an update method to transform data from the source schema to the target schema.

Graph Compilation

The compileGraph function takes an array of edges and builds a compiled graph. It validates the graph for loops and duplicate edges, and creates an adjacency map representing the connections between schemas.

Data Migration

The migrate function allows for seamless data migration between different schema versions. Given a compiled graph, a source schema, a target schema, and the data to migrate, it finds the shortest path between the source and target schemas and applies the necessary updates along the path to transform the data to the target schema.

Usage

Here's an example of how you can use the schema-revolution library:

import { createEdge, compileGraph, migrate, Schema } from 'schema-revolution';

// Define your schemas
interface User {
  id: number;
  name: string;
}

const schema1: Schema<User> = {
  v: 'base',
  parse(data: any) {
    return {
      v: 'base',
      id: data.id || 0,
      name: data.name || 'Unknown',
    } as const;
  },
};

interface UserV2 extends User {
  age: number;
}

const schema2: Schema<UserV2> = {
  v: 2,
  parse(data: any) {
    return {
      v: 2,
      id: data.id || 0,
      name: data.name || 'Unknown',
      age: data.age || 0,
    } as const;
  },
};

// Create edges between schemas
const edge1 = createEdge(schema1, schema2, (data) => ({
  ...data,
  v: schema2.v,
  age: 25, // Set a default age during migration
}));

// Compile the graph
const compiledGraph = compileGraph([edge1]);

// Migrate data from schema1 to schema2
const inputData = { id: 1, name: 'John' };
const migratedData = migrate(compiledGraph, schema1.v, schema2.v, schema1.parse(inputData));

console.log(migratedData);
// Output: { v: 2, id: 1, name: 'John', age: 25 }

In this example, we define two schemas (schema1 and schema2) representing different versions of a data structure. We create an edge between the schemas using the createEdge function. Then, we compile the graph using compileGraph, passing in an array of edges.

Finally, we can use the migrate function to migrate data from schema1 to schema2. We provide the compiled graph, the source schema identifier, the target schema identifier, and the input data to migrate. The function performs the necessary updates along the shortest path between the schemas and returns the migrated data.

Contributing

Contributions to schema-revolution are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

License

schema-revolution is released under the MIT License. See the LICENSE file for more details.