@botonic/plugin-contentful
Version:
## What Does This Plugin Do?
46 lines • 2.11 kB
JavaScript
import { __awaiter } from "tslib";
import { PagingOptions, } from '../../cms';
import { ResourceDelivery } from '../content-delivery';
import { ContentfulEntryUtils } from '../delivery-utils';
import { HandoffDelivery } from './handoff';
import { QueueDelivery } from './queue';
import { ScheduleDelivery } from './schedule';
/**
* Retrieve multiple contents in a single call
*/
export class ContentsDelivery extends ResourceDelivery {
contents(contentType, context, factory, paging) {
return __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 __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 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(ContentfulEntryUtils.commonFieldsFromEntry(entry)));
}
return this.asyncMap(context, entries, entry => factory(entry, context));
});
}
maxReferencesInclude() {
return Math.max(HandoffDelivery.REFERENCES_INCLUDE, QueueDelivery.REFERENCES_INCLUDE, 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,
};
}
}
//# sourceMappingURL=contents.js.map