Skip to content

Map File Utility Class

getMapFile function

Pulls the transform mapping file from VibeIQ using the passed in fileId. And will cache the file for subsequent calls.

  const mapFileUtil = new MapFileUtil(new Entities());
  const wholeMap = await mapFileUtil.getMapFile(this.transformMapFile);

getMappingSectionFromMap function

Takes the map from 'getMapFile()' and the mapKey and direction; and returns the correct section of the map file.

  const mapFileUtil = new MapFileUtil(new Entities());
  const wholeMap = await mapFileUtil.getMapFile(this.transformMapFile);
  const mapSection = mapFileUtil.getMappingSectionFromMap(
          wholeMap, 'color', 'vibe2flex');

getFullMapSection function

Helper function that gets the full map section for a given key. Which includes both directions; identifier and informational properties; etc.

  const mapFileUtil = new MapFileUtil(new Entities());
  const wholeMap = await mapFileUtil.getMapFile(this.transformMapFile);
  const mapSection = mapFileUtil.getFullMapSection(
          this.transformMapFile, 'color');

getMappingSection function

Passes the fileId to 'getMapFile()' to get the map file. Then uses 'getMappingSectionFromMap()' to get the correct section based on the passed in mapKey and direction.

  const mapFileUtil = new MapFileUtil(new Entities());
  const mapSection = mapFileUtil.getMappingSection(
          this.transformMapFile, 'color', 'vibe2flex');

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.

  const entity = {
    typePath: 'custom-entity:pack',
    entityType: 'custom-entity'
  }

  const mapFileUtil = new MapFileUtil(new Entities());
  const mapSection = mapFileUtil.getMapKey(
          this.transformMapFile, entity.entityType, 'vibe2flex');

getTransformTasks function

Takes the mapping section and builds an array of TransformTask objects. This will swap in the data from the map file into the task using the specified key.

///map file data
  transformOrder: [
    { processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
  rekey: {
    vibeIQIdentifier: 'itemNumber'
  }
///end map file data

  const mapFileUtil = new MapFileUtil(new Entities());
  const mapSection = mapFileUtil.getMappingSection(
          this.transformMapFile, 'color', 'vibe2flex');
  const tasks: TransformTask[] = MapFileUtil.getTransformTasks(mapSection);

//Expected results
//[{"processor":"REKEY",
//  "rekeyDelete":false,
//  "rekeyTransformers":{"vibeIQIdentifier":"itemNumber"}}]

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"}