-
Notifications
You must be signed in to change notification settings - Fork 198
/
asset.js
46 lines (42 loc) · 1.63 KB
/
asset.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import cloneDeep from 'lodash/cloneDeep'
import {toPlainObject, freezeSys} from 'contentful-sdk-core'
/**
* @memberof Entities
* @typedef Asset
* @prop {Entities.Sys} sys - Standard system metadata with additional entry specific properties
* @prop {string=} sys.locale - If present, indicates the locale which this asset uses
* @prop {Object} fields - Object with content for each field
* @prop {string} fields.title - Title for this asset
* @prop {string} fields.description - Description for this asset
* @prop {Object} fields.file - File object for this asset
* @prop {string} fields.file.fileName - Name for the file
* @prop {string} fields.file.contentType - Mime type for the file
* @prop {string} fields.file.url - Url where the file is available at.
* @prop {Object} fields.file.details - Details for the file, depending on file type (example: image size in bytes, etc)
* @prop {function(): Object} toPlainObject() - Returns this Asset as a plain JS object
*/
/**
* @private
* @param {Object} data - Raw asset data
* @return {Asset} Wrapped asset data
*/
export function wrapAsset (data) {
return freezeSys(toPlainObject(cloneDeep(data)))
}
/**
* @memberof Entities
* @typedef AssetCollection
* @prop {number} total
* @prop {number} skip
* @prop {number} limit
* @prop {Array<Entities.Asset>} items
* @prop {function(): Object} toPlainObject() - Returns this Asset collection as a plain JS object
*/
/**
* @private
* @param {Object} data - Raw asset collection data
* @return {AssetCollection} Wrapped asset collection data
*/
export function wrapAssetCollection (data) {
return freezeSys(toPlainObject(cloneDeep(data)))
}