UNPKG

1.27 kBJavaScriptView Raw
1/* eslint-disable @typescript-eslint/ban-ts-comment */
2import { toPlainObject } from 'contentful-sdk-core';
3import copy from 'fast-copy';
4
5/**
6 * @private
7 */
8export var wrapCollection = function wrapCollection(fn) {
9 return function (makeRequest, data) {
10 for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
11 rest[_key - 2] = arguments[_key];
12 }
13
14 var collectionData = toPlainObject(copy(data)); // @ts-expect-error
15
16 collectionData.items = collectionData.items.map(function (entity) {
17 return fn.apply(void 0, [makeRequest, entity].concat(rest));
18 }); // @ts-expect-error
19
20 return collectionData;
21 };
22};
23export var wrapCursorPaginatedCollection = function wrapCursorPaginatedCollection(fn) {
24 return function (makeRequest, data) {
25 for (var _len2 = arguments.length, rest = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
26 rest[_key2 - 2] = arguments[_key2];
27 }
28
29 var collectionData = toPlainObject(copy(data)); // @ts-expect-error
30
31 collectionData.items = collectionData.items.map(function (entity) {
32 return fn.apply(void 0, [makeRequest, entity].concat(rest));
33 }); // @ts-expect-error
34
35 return collectionData;
36 };
37};
\No newline at end of file