import { Contracts } from '../../contracts' ; import { IDeliveryClientConfig } from '../../config' ; import { Responses , IElementQueryConfig , IDeliveryNetworkResponse } from '../../models' ; import { QueryService } from '../../services' ; import { BaseQuery } from '../common/base-query.class' ; export class ElementQuery extends BaseQuery < Responses . IViewContentTypeElementResponse , IElementQueryConfig , Contracts . IViewContentTypeElementContract > { constructor ( protected config , protected queryService , private typeCodename , private elementCodename ) { super ( config , queryService ) ; if ( ! typeCodename ) { throw Error ( `Codename of the type has to be provided` ) ; } if ( ! elementCodename ) { throw Error ( `Codename of the element has to be provided` ) ; } } toPromise ( ) { return this . queryService . getElementAsync ( this . getUrl ( ) , this . _queryConfig ?? { } ) ; } getUrl ( ) { const action = '/types/' + this . typeCodename + '/elements/' + this . elementCodename ; return super . resolveUrlInternal ( action ) ; } map ( json ) { return this . queryService . mappingService . viewContentTypeElementResponse ( json ) ; } }