UNPKG

@kontent-ai/delivery-sdk

Version:
130 lines 4.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MultipleItemsQuery = void 0; const models_1 = require("../../models"); const base_item_listing_query_class_1 = require("../common/base-item-listing-query.class"); class MultipleItemsQuery extends base_item_listing_query_class_1.BaseItemListingQuery { constructor(config, queryService) { super(config, queryService); this.config = config; this.queryService = queryService; this._queryConfig = {}; } /** * Adds information about the total number of content items matching your query. * When set to true, the pagination object returned in the API response contains * an additional total_count property. */ includeTotalCountParameter() { this.parameters.push(new models_1.Parameters.IncludeTotalCountParameter()); return this; } /** * Gets only item of given type * @param type Codename of type to get */ type(type) { this.parameters.push(new models_1.Filters.TypeFilter(type)); return this; } /** * Gets items of given types (logical or) * I.e. get items of either 'Actor' or 'Movie' type * @param types Types to get */ types(types) { this.parameters.push(new models_1.Filters.TypeFilter(types)); return this; } /** * Gets only item from given collection * @param collection Codename of collection to get */ collection(collection) { this.parameters.push(new models_1.Filters.CollectionFilter(collection)); return this; } /** * Gets items from given collections (logical or) * I.e. get items of either 'default' or 'christmas-campaign' collection * @param collections Collections to get */ collections(collections) { this.parameters.push(new models_1.Filters.CollectionFilter(collections)); return this; } /** * Indicates depth of query that affects loading of nested linked items. * @param depth Depth of the query (> 0) */ depthParameter(depth) { this.parameters.push(new models_1.Parameters.DepthParameter(depth)); return this; } /** * Language codename * @param languageCodename Codename of the language */ languageParameter(languageCodename) { this.parameters.push(new models_1.Parameters.LanguageParameter(languageCodename)); return this; } /** * Used to limit the number of elements returned by query. * @param elementCodenames Array of element codenames to fetch */ elementsParameter(elementCodenames) { this.parameters.push(new models_1.Parameters.ElementsParameter(elementCodenames)); return this; } /** * Used to exclude elements returned by query. * @param elementCodenames Array of element codenames to exclude */ excludeElementsParameter(elementCodenames) { this.parameters.push(new models_1.Parameters.ExcludeElementsParameter(elementCodenames)); return this; } toPromise() { var _a; return this.queryService.getMultipleItems(this.getUrl(), (_a = this._queryConfig) !== null && _a !== void 0 ? _a : {}); } getUrl() { const action = '/items'; // handle default language this.processDefaultLanguageParameter(); // handle archived items this.processExcludeArchivedItemsParameter(); return super.resolveUrlInternal(action); } map(json) { return this.queryService.mappingService.listContentItemsResponse(json); } allResponseFactory(items, responses) { this.linkItems(items, responses); return { items: items, responses: responses }; } linkItems(items, responses) { // prepare all available items (including components) for linking const allContentItems = []; // process linked items (modular_content part of the response) for (const response of responses) { allContentItems.push(...Object.values(response.data.linkedItems) .filter((m) => m !== undefined) .map((m) => m)); } // add standard items for (const item of items) { if (!allContentItems.find((m) => m.system.codename.toLowerCase() === item.system.codename.toLowerCase())) { allContentItems.push(item); } } // process main items this.linkItemsInRte(allContentItems); } } exports.MultipleItemsQuery = MultipleItemsQuery; //# sourceMappingURL=multiple-items-query.class.js.map