1 |
|
2 | import { toPlainObject } from 'contentful-sdk-core';
|
3 | import copy from 'fast-copy';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export 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));
|
15 |
|
16 | collectionData.items = collectionData.items.map(function (entity) {
|
17 | return fn.apply(void 0, [makeRequest, entity].concat(rest));
|
18 | });
|
19 |
|
20 | return collectionData;
|
21 | };
|
22 | };
|
23 | export 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));
|
30 |
|
31 | collectionData.items = collectionData.items.map(function (entity) {
|
32 | return fn.apply(void 0, [makeRequest, entity].concat(rest));
|
33 | });
|
34 |
|
35 | return collectionData;
|
36 | };
|
37 | }; |
\ | No newline at end of file |