import { IHeader , IQueryParameter } from '@kentico/kontent-core' ; import { IDeliveryClientConfig } from '../../config' ; import { IDeliveryNetworkResponse , IKontentResponse , IQueryConfig , Parameters } from '../../models' ; import { QueryService } from '../../services' ; export abstract class BaseQuery < TResponse extends IKontentResponse , TQueryConfig extends IQueryConfig , TContract > { protected parameters : IQueryParameter [ ] = [ ] ; protected headers : IHeader [ ] = [ ] ; protected customUrl ? : string ; protected _queryConfig ? : TQueryConfig ; constructor ( protected config , protected queryService ) { } /**
     * Gets URL of the query
     */ abstract getUrl ( ) ; /**
     * Gets promise for query execution
     */ abstract toPromise ( ) ; /**
     * Maps json data to response
     */ abstract map ( json ) ; param name param value withCustomParameter ( name , value ) { this . parameters . push ( new Parameters . QueryParameter ( name , value ) ) ; return this ; } param name param value withParameter ( parameter ) { this . parameters . push ( parameter ) ; return this ; } param parameters withParameters ( parameters ) { this . parameters . push ( ... parameters ) ; return this ; } /**
     * Gets headers used by this query
     */ getHeaders ( ) { return this . queryService . getHeaders ( this . _queryConfig ?? { } , this . headers ) ; } /**
     * Sets request headers
     */ withHeaders ( headers ) { this . headers . push ( ... headers ) ; return this ; } /**
     * Sets request header
     */ withHeader ( header ) { this . headers . push ( header ) ; return this ; } /**
     * Sets custom URL of request (overrides default URL of the query)
     */ withCustomUrl ( url ) { this . customUrl = url ; return this ; } /**
     * Gets all query parameter currently applied to query
     */ getParameters ( ) { return this . parameters ; } param queryConfig queryConfig ( queryConfig ? ) { this . _queryConfig = queryConfig ; return this ; } protected resolveUrlInternal ( action ) { if ( this . customUrl ) { return this . customUrl ; } return this . queryService . getUrl ( action , this . _queryConfig ?? { } , this . getParameters ( ) ) ; } protected processDefaultLanguageParameter ( ) { if ( this . config . defaultLanguage ) { const languageParameter = this . getParameters ( ) . find ( ( m ) => m . getParam ( ) === 'language' ) ; if ( ! languageParameter ) { this . parameters . push ( new Parameters . LanguageParameter ( this . config . defaultLanguage ) ) ; } } } }