Introduction
Using the Transform Data library¶
The Transform Data library is for converting data so it can be used in another system. Sometimes this may be as simple as changing a property's key. Other times the data itself needs to change formats, or even have complex manipulation done on the data. This documentation is intended to show how these data changes can be made using the transform data library.
Calling Transformation Code¶
The intent of this library is to use the TransformProcessor class to process all the transformations following the transformOrder. The processors while they can be called independently; that is not the intent. The following documentation is to show how the different processors are used; so the correct one can be identified for a given situation. The Map File Utility Class has helper functions for transforming the data. The most useful will be getMapKey() and applyTransformMap(); which will handle most of the work you will need to do.
getMapKey function¶
Returns the mapKey based on the 'typeConversion' section of the map file. If the map file doesn't have a section for the type in question, 'undefined' is returned. If this returns undefined; then when calling the applyTransformMap(), you will use the default entity / object class for the given entity / object.
const entity = {
typePath: 'custom-entity:pack',
entityType: 'custom-entity'
}
const mapFileUtil = new MapFileUtil(new Entities());
const mapSection = mapFileUtil.getMapKey(
this.transformMapFile, entity.entityType, 'vibe2flex');
applyTransformMap function¶
Gettings the mapping section, converts the TransformTasks, then transforms data using those tasks.
///map file data
packaging: {
vibe2flex: {
transformOrder: [
{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
rekey: {
retailPackType: 'packType',
retailIntroDate: 'introDate'
},
getSoftType: () => 'Revisable Entity\\packaging',
getClass: () => 'LCSRevisableEntity'
},
}
///end map file data
const mapFileUtil = new MapFileUtil(new Entities());
const packType = 'packType1';
const introDate = '2023-10-17T20:15:35.512Z';
const data = {
packType,
introDate
};
const mapKey = 'packaging';
const direction = 'vibe2flex';
const results = await mapFileUtil.applyTransformMap(fileId,
data, mapKey, direction);
//Expected results
//{ "typePath":"custom-entity:pack",
// "retailPackType":"packType1",
// "retailIntroDate":"2023-10-17T20:15:35.512Z"}
Base file format¶
This is the minimum needed for the file to be loaded by the mapping utility.
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
exports.mapping = {
typeConversion: { },
mapping1: { }
}