Skip to content

SlimIO/Config-Migration

Repository files navigation

ConfigMigration

version Maintenance MIT size dep Known Vulnerabilities Build Status

SlimIO Configuration Migration. This package is used in SlimIO when addon Schema has been updated, so we need to migrate the Configuration Content to not break the startup.

Requirements

Features

  • Support both add and remove action.

Replace is not supported because it's considered dangerous and a bad practices to update keys!

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @slimio/config-migration
# or
$ yarn add @slimio/config-migration

Usage example

const { strictEqual } = require("assert");
const ConfigMigrator = require("@slimio/config-migration");

// Original Schema
const originalSchema = {
    properties: {
        hostname: { type: "string" },
        release: { type: "string" }
    }
};

// Migrated Schema (remove >> release, add >> version)
const migratedSchema = {
    properties: {
        hostname: { type: "string" },
        version: {
            type: "string",
            default: "v1.0.0"
        }
    }
}

const cfgMigrator = new ConfigMigrator(originalSchema, migratedSchema);
const migratedPayload = cfgMigrator.migrate({
    hostname: "localhost",
    release: "v1.0.0"
});

const expected = { hostname: "localhost", version: "v1.0.0" };
strictEqual(JSON.stringify(migratedPayload), JSON.stringify(expected));

API

Schema and payload should be plain JavaScript object.

{} || Object.create(null);

constructor(originalSchema: Object, migrateSchema: Object);

Create a new Configuration migrator.

migrate(payload: Object): Object

Migrate a given payload. The payload will be cloned deep (the original copy shall not be updated).

Dependencies

Name Refactoring Security Risk Usage
@slimio/is Minor Low Type checker
fast-json-patch ⚠️Major High Interact with JSON file
lodash.clonedeep Minor Low Clone deep Objects
lodash.get Minor Low Get deep a value
lodash.set Minor Low Set deep a value

License

MIT

About

SlimIO JSON Schema Migration (Payload Migration)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •