Transform data by applying a set of changes.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
src
.babelrc
.codeclimate.yml
.eslintrc
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
esdoc.json
package.json
publish-docs.js

README.md

schema-mapper-transformer

Transform an Item or Metadata by applying Changes to it.

build status Docs status Code Climate Dependencies License

Installation

npm install --save schema-mapper-transformer

Usage

Transforming an item

Items can be transformed by applying changes to it. The following table shows how the item object is modified by each type of change

  • column.rename - Renames the key in the item object, keeping it's value
  • column.create - Adds the key to the item object with a null value
  • column.remove - Removes the key from the item object
  • column.typechange - Nulls the value
  • schema.remove - Nulls the item object
  • project.remove - Nulls the item object
var transformer = require('schema-mapper-transformer');
var item = {
  user_id: 1,
  name: 'Koen'
};
var changes = [
  {
    change: 'column.rename',
    projectId: '1',
    schemaId: '1',
    columnId: '1',
    name: 'id',
    oldName: 'user_id'
  },
  {
    change: 'column.create',
    projectId: '1',
    schemaId: '1',
    columnId: '3',
    column: {
      name: 'email',
      type: 'string'
    }
  },
  {
    change: 'column.remove',
    projectId: '1',
    schemaId: '1',
    columnId: '2'
  }
];
var result = transformer.transformItem(item, changes);
console.log(result);
{
  id: 1,
  email: null
}

Transforming metadata

Metadata can be transformed by applying changes to it. The following table shows how the metadata object is modified by each type of change

  • project.rename - Updates the projectName property
  • project.tag - Updates the projectVersion property
  • schema.remame - Updates the schemaName property
var metadata = {
  projectName: 'demo',
  projectVersion: 1,
  schemaName: 'users'
};
var changes = [
  {
    change: 'project.rename',
    projectId: '1',
    name: 'demoproject'
  },
  {
    change: 'project.tag',
    projectId: '1',
    version: 2
  },
  {
    change: 'schema.rename',
    projectId: '1',
    schemaId: '1',
    name: 'users'
  }
];

var result = transformer.transformMetadata(metadata, changes);
console.log(result);
{
  projectName: 'demoproject',
  projectVersion: 2,
  schemaName: 'users'
}

API docs

API Docs

Licence

MIT