UNPKG

@kontent-ai/delivery-sdk

Version:
52 lines 1.89 kB
import { continuationTokenHeaderName } from '../../models'; import { BaseQuery } from './base-query.class'; export class BaseListingQuery extends BaseQuery { constructor(config, queryService) { super(config, queryService); this.config = config; this.queryService = queryService; } /** * Sets continuation token header */ withContinuationToken(token) { var _a; // remove previous continuation token if there is any let queryHeaders = (_a = this._queryConfig.customHeaders) !== null && _a !== void 0 ? _a : []; queryHeaders = queryHeaders.filter((m) => m.header !== continuationTokenHeaderName); this._queryConfig.customHeaders = queryHeaders; this.withHeaders([ { header: continuationTokenHeaderName, value: token } ]); return this; } /** * Query to get all items. Uses paging data and may execute multiple HTTP requests depending on number of items */ toAllPromise(queryAllConfig) { return this.queryService.getListAllResponse({ page: 1, listQueryConfig: queryAllConfig, allResponseFactory: (items, responses) => { const response = this.allResponseFactory(items, responses); return { data: response, responses: responses }; }, getResponse: (nextPageUrl, continuationToken) => { if (nextPageUrl) { this.withCustomUrl(nextPageUrl); } if (continuationToken) { this.withContinuationToken(continuationToken); } return this.toPromise(); } }); } } //# sourceMappingURL=base-listing-query.class.js.map