From 1741d28045bb198aea4dfcc92d2ce855159bb9aa Mon Sep 17 00:00:00 2001 From: "Goebel, Lukas" Date: Wed, 31 Mar 2021 09:19:28 +0200 Subject: [PATCH] feat(custom mapper): simplify custom mapper usage --- src/modules/CaaSMapper.ts | 13 +++++++------ src/types.ts | 7 ++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/modules/CaaSMapper.ts b/src/modules/CaaSMapper.ts index 5eaece6..0a3ae01 100644 --- a/src/modules/CaaSMapper.ts +++ b/src/modules/CaaSMapper.ts @@ -1,4 +1,3 @@ -import set from 'lodash.set' import { FSXAApi, ComparisonQueryOperatorEnum } from './' import { CaaSApi_Body, @@ -30,7 +29,7 @@ import { Section } from '../types' import { parseISO } from 'date-fns' -import { chunk } from 'lodash' +import { set, chunk } from 'lodash' import XMLParser from './XMLParser' import { Logger } from './Logger' @@ -76,9 +75,12 @@ export class CaaSMapper { async mapDataEntry(entry: CaaSApi_DataEntry, path: NestedPath): Promise { if (this.customMapper) { - const result = await this.customMapper(entry, { - registerReferencedItem: this.registerReferencedItem, - api: this.api + const result = await this.customMapper(entry, path, { + api: this.api, + xmlParser: this.xmlParser, + registerReferencedItem: this.registerReferencedItem.bind(this), + buildPreviewId: this.buildPreviewId.bind(this), + mapDataEntries: this.mapDataEntries.bind(this) }) if (typeof result !== 'undefined') return result } @@ -241,7 +243,6 @@ export class CaaSMapper { case 'Content2Section': return await this.mapContent2Section(content) case 'Section': - return await this.mapSection(content, path) case 'SectionReference': return await this.mapSection(content, path) default: diff --git a/src/types.ts b/src/types.ts index a185406..1fdc7c3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,6 +4,7 @@ import { ComparisonQueryOperatorEnum, LogicalQueryOperatorEnum } from './modules/QueryBuilder' +import XMLParser from './modules/XMLParser' export interface CaaSApi_Template { fsType: 'PageTemplate' | 'SectionTemplate' | 'LinkTemplate' @@ -510,11 +511,15 @@ export type NestedPath = (string | number)[] export type CustomMapper = ( entry: CaaSApi_DataEntry, + entryPath: NestedPath, utils: { api: FSXAApi + xmlParser: XMLParser registerReferencedItem: (identifier: string, path: NestedPath) => string + buildPreviewId: (identifier: string) => string + mapDataEntries: (entries: CaaSApi_DataEntries, path: NestedPath) => Promise } -) => Promise +) => Promise export type FSXAApiParams = | {