UNPKG

@botonic/plugin-contentful

Version:

## What Does This Plugin Do?

50 lines 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContentsDelivery = void 0; const tslib_1 = require("tslib"); const cms_1 = require("../../cms"); const content_delivery_1 = require("../content-delivery"); const delivery_utils_1 = require("../delivery-utils"); const handoff_1 = require("./handoff"); const queue_1 = require("./queue"); const schedule_1 = require("./schedule"); /** * Retrieve multiple contents in a single call */ class ContentsDelivery extends content_delivery_1.ResourceDelivery { contents(contentType, context, factory, paging) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const entryCollection = yield this.delivery.getEntries(context, this.query(contentType, paging)); return this.asyncMap(context, entryCollection.items, entry => factory(entry, context)); }); } topContents(model, context, factory, filter, paging) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const entryCollection = yield this.delivery.getEntries(context, this.query(model, paging)); let entries = entryCollection.items; if (entryCollection.total > paging.limit) { const paging2 = new cms_1.PagingOptions(1000, 1000); const entryCollection2 = yield this.delivery.getEntries(context, this.query(model, paging2)); entries.push(...entryCollection2.items); } if (filter) { entries = entries.filter(entry => filter(delivery_utils_1.ContentfulEntryUtils.commonFieldsFromEntry(entry))); } return this.asyncMap(context, entries, entry => factory(entry, context)); }); } maxReferencesInclude() { return Math.max(handoff_1.HandoffDelivery.REFERENCES_INCLUDE, queue_1.QueueDelivery.REFERENCES_INCLUDE, schedule_1.ScheduleDelivery.REFERENCES_INCLUDE); } query(contentType, paging) { return { // eslint-disable-next-line @typescript-eslint/naming-convention content_type: contentType, include: this.maxReferencesInclude(), limit: paging.limit, skip: paging.skip, }; } } exports.ContentsDelivery = ContentsDelivery; //# sourceMappingURL=contents.js.map