Skip to content

Morph Transformer

Defining a Morph section

The Morph Transformer can make any number of changes to the object that is passed in. It's intent is to handle situations where multiple changes will need to be made at a time or the key for the data value is variable.

Property Slug Description
processor 'MORPH'
functionTransformersKey The key to the object with the morph changes. The object can have multiple morph functions. And the order of processing will follow that of JavaScript Object.entries() which follows 'for...in'.

Here is an example of the morph processor TransformTask

direction: {
  transformOrder: [
    {processor: ProcessorKeys.MORPH, functionTransformersKey: 'morphTransform' }],
  morphTransform: {
    morph1: (row/*, dependencies*/) =>{
      const category = row['category'];
      const key = ('footwear' === category)
        ? 'footOwner'
        : 'apparelOwner';
      row[key] = row['productOwner'];
      delete row['productOwner'];
    }
  }
}

const data = [{
  name: 'Bob',
  itemNumber: 1045,
  category: 'footwear',
  productOwner: {
    email: 'bob@vibeiq.com'
  }
}, {
  name: 'Joe',
  itemNumber: 1046,
  category: 'apparel',
  productOwner: {
    email: 'joe@vibeiq.com'
  }

}];

//... transform data

//Expected results
//[{
//  name: 'Bob',
//  vibeIQIdentifier: 1045
//  category: 'footwear',
//  footOwner: { email: 'bob@gmail.com'}
//},{
//  name: 'Joe',
//  vibeIQIdentifier: 1046
//  category: 'footwear',
//  apparelOwner: { email: 'joe@gmail.com'}
//}]