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.
- Node.js v12 or higher
- Support both
add
andremove
action.
Replace is not supported because it's considered dangerous and a bad practices to update keys!
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
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));
Schema and payload should be plain JavaScript object.
{} || Object.create(null);
Create a new Configuration migrator.
Migrate a given payload. The payload will be cloned deep (the original copy shall not be updated).
Name | Refactoring | Security Risk | Usage |
---|---|---|---|
@slimio/is | Minor | Low | Type checker |
fast-json-patch | 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 |
MIT