-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntryList.js
45 lines (42 loc) · 1.52 KB
/
EntryList.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
import halfred from 'halfred';
import { getSchema } from '../../helper';
import ListResource from '../ListResource';
import EntryResource from './EntryResource';
/**
* Entry list class
*
* @class
*/
export default class EntryList extends ListResource {
/**
* Creates a new {@link EntryList}.
*
* @param {object} resource resource loaded from the API.
* @param {string} environment the environment this resource is associated to.
* @param {string} name name of the embedded items.
* @param {object} schema JSON Schema for list items.
* @param {object?} traversal traversal from which traverson can continue.
*/
constructor(resource, environment, traversal, name, schema) {
super(resource, environment, traversal, name, schema, EntryList, EntryResource);
}
}
/**
* Asynchronously create a new {@link EntryList}. This can be used when the schema is not known
* before creating the EntryList.
*
* @param {object} resource loaded resource
* @param {environment} environment the environment of this resource
* @param {object?} traversal traversal for continuing
* @param {string} name name of the embedded items
* @returns {Promise<EntryResource>} {@link Promise} resolving to the newly created {@link
* EntryResource}
*/
export function createList(resource, environment, traversal, name) {
return Promise.resolve()
.then(() => {
const res = halfred.parse(resource);
return getSchema(res.link('self').profile);
})
.then(schema => new EntryList(resource, environment, traversal, name, schema));
}