UNPKG

contentful-management

Version:
27 lines (25 loc) 928 B
import { freezeSys, toPlainObject } from 'contentful-sdk-core'; import copy from 'fast-copy'; import { wrapCollection, wrapCursorPaginatedCollection } from '../common-utils'; import createEntryApi from '../create-entry-api'; import enhanceWithMethods from '../enhance-with-methods'; /** * @private * @param makeRequest - function to make requests via an adapter * @param data - Raw entry data * @return Wrapped entry data */ export function wrapEntry(makeRequest, data) { const entry = toPlainObject(copy(data)); const entryWithMethods = enhanceWithMethods(entry, createEntryApi(makeRequest)); return freezeSys(entryWithMethods); } /** * Data is also mixed in with link getters if links exist and includes were requested * @private */ export const wrapEntryCollection = wrapCollection(wrapEntry); /** * @private */ export const wrapEntryTypeCursorPaginatedCollection = wrapCursorPaginatedCollection(wrapEntry);