-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcontentstackCollection.js
More file actions
40 lines (39 loc) · 1.16 KB
/
contentstackCollection.js
File metadata and controls
40 lines (39 loc) · 1.16 KB
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
/**
* @namespace ContentstackCollection
*/
export default class ContentstackCollection {
/**
* Creates a ContentstackCollection instance.
* @param {Object} response - HTTP response object.
* @param {Object} http - HTTP client instance.
* @param {Object=} stackHeaders - Stack headers to include in data.
* @param {Function=} wrapperCollection - Collection wrapper function to transform items.
*/
constructor (response, http, stackHeaders = null, wrapperCollection) {
const data = response.data || {}
if (stackHeaders) {
data.stackHeaders = stackHeaders
}
if (http?.httpClientParams?.headers?.includeResHeaders === true) {
data.stackHeaders = {
...data.stackHeaders,
responseHeaders: response.headers
}
}
if (wrapperCollection) {
this.items = wrapperCollection(http, data)
}
if (data.schema !== undefined) {
this.schema = data.schema
}
if (data.content_type !== undefined) {
this.content_type = data.content_type
}
if (data.count !== undefined) {
this.count = data.count
}
if (data.notice !== undefined) {
this.notice = data.notice
}
}
}