contentful-management
Version:
Client for Contentful's Content Management API
42 lines (39 loc) • 1.74 kB
JavaScript
import { toPlainObject, freezeSys } from 'contentful-sdk-core';
import copy from 'fast-copy';
import { wrapCollection } from '../common-utils.js';
import enhanceWithMethods from '../enhance-with-methods.js';
/**
* @internal
* @param makeRequest - function to make requests via an adapter
* @param data - Raw data
* @returns Normalized usage
* @deprecated Use {@link wrapAggregatedUsage} / `usage.getAggregated()` instead. Sunset: 2027-02-28.
*/
function wrapUsage(_makeRequest, data) {
const usage = toPlainObject(copy(data));
const usageWithMethods = enhanceWithMethods(usage, {});
return freezeSys(usageWithMethods);
}
/** @internal @deprecated */
const wrapUsageCollection = wrapCollection(wrapUsage);
/** @internal */
function wrapAggregatedUsage(_makeRequest, data) {
const item = toPlainObject(copy(data));
return freezeSys(enhanceWithMethods(item, {}));
}
/** @internal */
const wrapAggregatedUsageCollection = wrapCollection(wrapAggregatedUsage);
/** @internal */
function wrapAssetBandwidthUsage(_makeRequest, data) {
const item = toPlainObject(copy(data));
return freezeSys(enhanceWithMethods(item, {}));
}
/** @internal */
function wrapAssetBandwidthUsageDetailedCollection(makeRequest, data) {
const collectionData = toPlainObject(copy(data));
collectionData.items = collectionData.items.map((item) => wrapAssetBandwidthUsage(makeRequest, item));
// @ts-expect-error items is reassigned above from AssetBandwidthUsageItemProps[] to AssetBandwidthUsage[]
return collectionData;
}
export { wrapAggregatedUsage, wrapAggregatedUsageCollection, wrapAssetBandwidthUsage, wrapAssetBandwidthUsageDetailedCollection, wrapUsage, wrapUsageCollection };
//# sourceMappingURL=usage.js.map