UNPKG

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