1 |
|
2 |
|
3 | import { toPlainObject } from 'contentful-sdk-core';
|
4 | import copy from 'fast-copy';
|
5 |
|
6 |
|
7 |
|
8 | export const wrapCollection = fn => (makeRequest, data, ...rest) => {
|
9 | const collectionData = toPlainObject(copy(data));
|
10 |
|
11 | collectionData.items = collectionData.items.map(entity => fn(makeRequest, entity, ...rest));
|
12 |
|
13 | return collectionData;
|
14 | };
|
15 | export const wrapCursorPaginatedCollection = fn => (makeRequest, data, ...rest) => {
|
16 | const collectionData = toPlainObject(copy(data));
|
17 |
|
18 | collectionData.items = collectionData.items.map(entity => fn(makeRequest, entity, ...rest));
|
19 |
|
20 | return collectionData;
|
21 | };
|
22 | export function isSuccessful(statusCode) {
|
23 | return statusCode < 300;
|
24 | }
|
25 | export function shouldRePoll(statusCode) {
|
26 | return [404, 422, 429, 400].includes(statusCode);
|
27 | }
|
28 | export async function waitFor(ms = 1000) {
|
29 | return new Promise(resolve => setTimeout(resolve, ms));
|
30 | } |
\ | No newline at end of file |