schema-mapper-transformer
v0.4.2
Published
Transform data from one schema to another.
Downloads
10
Readme
schema-mapper-transformer
Transform an Item or Metadata by applying Changes to it.
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
Licence
MIT