import { Contracts } from '../../contracts' ; import { IDeliveryClientConfig } from '../../config' ; import { IContentItem , IItemQueryConfig , IDeliveryNetworkResponse , Responses , Parameters } from '../../models' ; import { QueryService } from '../../services' ; import { BaseQuery } from '../common/base-query.class' ; export class SingleItemQuery < TContentItem extends IContentItem = IContentItem > extends BaseQuery < Responses . IViewContentItemResponse < TContentItem > , IItemQueryConfig , Contracts . IViewContentItemContract > { constructor ( protected config , protected queryService , private codename ) { super ( config , queryService ) ; if ( ! codename ) { throw Error ( `'codename' has to be configured for 'SingleItemQuery' query` ) ; } } param depth depthParameter ( depth ) { this . parameters . push ( new Parameters . DepthParameter ( depth ) ) ; return this ; } param queryConfig queryConfig ( queryConfig ) { this . _queryConfig = queryConfig ; return this ; } param languageCodename languageParameter ( languageCodename ) { this . parameters . push ( new Parameters . LanguageParameter ( languageCodename ) ) ; return this ; } param elementCodenames elementsParameter ( elementCodenames ) { this . parameters . push ( new Parameters . ElementsParameter ( elementCodenames ) ) ; return this ; } toPromise ( ) { return this . queryService . getSingleItemAsync ( this . getUrl ( ) , this . _queryConfig ?? { } ) ; } getUrl ( ) { const action = '/items/' + this . codename ; this . processDefaultLanguageParameter ( ) ; return super . resolveUrlInternal ( action ) ; } map ( json ) { return this . queryService . mappingService . viewContentItemResponse ( json ) ; } }