0.4.2 • Published 9 years ago

schema-mapper-transformer v0.4.2

Weekly downloads
9
License
MIT
Repository
github
Last release
9 years ago

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

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago