Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

schema-mapper-transformer

0.4.2 • Public • Published

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',
    oldColumn: {
      name: 'name',
      type: 'string'
    }
  }
];
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',
    oldName: 'demo'
  },
  {
    change: 'project.tag',
    projectId: '1',
    version: 2,
    oldVersion: 1
  },
  {
    change: 'schema.rename',
    projectId: '1',
    schemaId: '1',
    oldName: 'user',
    name: 'users'
  }
];
 
var result = transformer.transformMetadata(metadata, changes);
console.log(result);
{
  projectName: 'demoproject',
  projectVersion: 2,
  schemaName: 'users'
}

API docs

API Docs

Licence

MIT

Keywords

none

install

npm i schema-mapper-transformer

Downloadsweekly downloads

6

version

0.4.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability