import { IDeliveryClientConfig } from '../config' ; import { Contracts } from '../contracts' ; import { GenericElementMapper , ItemMapper , LanguageMapper , TaxonomyMapper , TypeMapper } from '../mappers' ; import { Responses , IContentItem , IPagination } from '../models' ; export interface IMappingService { listContentTypesResponse ( data ) : Responses . IListContentTypesResponse ; itemsFeedResponse < TContentItem extends IContentItem = IContentItem > ( data ) : Responses . IListItemsFeedResponse < TContentItem > ; viewContentTypeResponse ( data ) : Responses . IViewContentTypeResponse ; viewContentItemResponse < TContentItem extends IContentItem = IContentItem > ( data ) : Responses . IViewContentItemResponse < TContentItem > ; listContentItemsResponse < TContentItem extends IContentItem = IContentItem > ( data ) : Responses . IListContentItemsResponse < TContentItem > ; viewTaxonomyResponse ( data ) : Responses . IViewTaxonomyResponse ; listTaxonomiesResponse ( data ) : Responses . IListTaxonomiesResponse ; viewContentTypeElementResponse ( data ) : Responses . IViewContentTypeElementResponse ; listLanguagesResponse ( data ) : Responses . IListLanguagesResponse ; } export class MappingService implements IMappingService { private readonly typeMapper : TypeMapper ; private readonly languageMapper : LanguageMapper ; private readonly itemMapper : ItemMapper ; private readonly taxonomyMapper : TaxonomyMapper ; private readonly genericElementMapper : GenericElementMapper ; constructor ( readonly config ) { this . typeMapper = new TypeMapper ( ) ; this . languageMapper = new LanguageMapper ( ) ; this . itemMapper = new ItemMapper ( config ) ; this . taxonomyMapper = new TaxonomyMapper ( ) ; this . genericElementMapper = new GenericElementMapper ( ) ; } param data listLanguagesResponse ( data ) { return { items : this . languageMapper . mapMultipleLanguages ( data ) , pagination : this . mapPagination ( data . pagination ) } ; } param data listContentTypesResponse ( data ) { return { items : this . typeMapper . mapMultipleTypes ( data ) , pagination : this . mapPagination ( data . pagination ) } ; } param data param options viewContentTypeResponse ( data ) { return { type : this . typeMapper . mapSingleType ( data ) } ; } itemsFeedResponse < TContentItem extends IContentItem = IContentItem > ( data ) { const itemsResult = this . itemMapper . mapItems < TContentItem > ( { linkedItems : Object . values ( data . modular_content ) , mainItems : data . items } ) ; return { items : itemsResult . items , linkedItems : itemsResult . linkedItems } ; } param data param queryConfig viewContentItemResponse < TContentItem extends IContentItem = IContentItem > ( data ) { const itemResult = this . itemMapper . mapSingleItemFromResponse < TContentItem > ( data ) ; return { item : itemResult . item , linkedItems : itemResult . linkedItems } ; } param data param queryConfig listContentItemsResponse < TContentItem extends IContentItem = IContentItem > ( data ) { const itemsResult = this . itemMapper . mapMultipleItemsFromResponse < TContentItem > ( data ) ; return { items : itemsResult . items , pagination : this . mapPagination ( data . pagination ) , linkedItems : itemsResult . linkedItems } ; } param data viewTaxonomyResponse ( data ) { return { taxonomy : this . taxonomyMapper . mapTaxonomy ( data . system , data . terms ) } ; } param data listTaxonomiesResponse ( data ) { return { items : this . taxonomyMapper . mapTaxonomies ( data . taxonomies ) , pagination : this . mapPagination ( data . pagination ) } ; } param data viewContentTypeElementResponse ( data ) { return { element : this . genericElementMapper . mapElement ( data ) } ; } private mapPagination ( paginationContract ) { return { skip : paginationContract . skip , count : paginationContract . count , limit : paginationContract . limit , nextPage : paginationContract . next_page , totalCount : paginationContract . total_count ?? null } ; } }