Collection is an extension of Resource. Collection is meant to easily represent lists of Resources. It comes with logic to enable paging of these collections.

Kind: global class

new Collection(name, items, options)

Collection constructor

Returns: Resource - the constructed resource

Param Type Default Description
name string   How to name the embedded items in the collection
items Array   Array of Resource instances that represent the items of the collection
options Object   Options to determine how paging is parsed
options.offset integer   Set the offset value
options.limit integer   Set the limit value
options.total integer   Set the total value
[options.pageable] boolean true Whether or not this collection supports paging

collection.assign([data]) ⇒ this

Assign new data to the collection, behaves like Object.assign

Kind: instance method of Collection

Param Type Description
[data] Object The collection’s properties
[data.offset] integer The offset value
[data.limit] integer The limit value
[data.count] integer This page’s actual size
[data.total] integer The total value
[data._embedded] Object Dictionary of embedded sets

collection.getItems() ⇒ Array

Retrieve the collection’s items

Kind: instance method of Collection
Returns: Array - the collection’s items

collection.hasNextPage() ⇒ boolean

Check whether or not the collection has a next page

Kind: instance method of Collection
Returns: boolean - whether or not the collection has a next page

collection.getNextOffset() ⇒ integer | boolean

Retrieve the offset for the next page

Kind: instance method of Collection
Returns: integer | boolean - the next page’s offset or false if no next page

collection.getNextLimit() ⇒ integer | boolean

Retrieve the limit for the next page

Kind: instance method of Collection
Returns: integer | boolean - the next page’s limit or false if no next page

collection.hasPrevPage() ⇒ boolean

Check whether or not the collection has a previous page

Kind: instance method of Collection
Returns: boolean - whether or not the collection has a previous page

collection.getPrevOffset() ⇒ integer | boolean

Retrieve the offset for the previos page

Kind: instance method of Collection
Returns: integer | boolean - the previos page’s offset or false if no previos page

collection.getPrevLimit() ⇒ integer | boolean

Retrieve the limit for the previous page

Kind: instance method of Collection
Returns: integer | boolean - the previous page’s limit or false if no previous page

collection.getType() ⇒ string

Get the collection’s type. Defaults to “Collection” if not customized.

Kind: instance method of Collection
Returns: string - The collection’s type

collection.setPageable(pageable) ⇒ this

Set whether or not this collection is pageable

Kind: instance method of Collection

Param Type
pageable boolean

collection.isPageable() ⇒ boolean

Check whether or not this collection is pageable

Kind: instance method of Collection

collection.isTranslatable() ⇒ boolean

Check whether or not the collection is translateable. Always returns false because Collection does not support translating.

Kind: instance method of Collection

Collection.fromBubobox()

Preset for fromHAL to work with responses from the BuboBox API. It pre-configures how paging information should be parsed. For other options see fromHAL.

Kind: static method of Collection

Collection.fromPersona()

Preset for fromHAL to work with responses from the Persona API. It pre-configures how paging information should be parsed. For other options see fromHAL.

Kind: static method of Collection

Collection.fromHAL(name, body, options) ⇒ Resource

Static method to create a new Collection from a HAL response body

Kind: static method of Collection
Returns: Resource - the constructed resource

Param Type Default Description
name string   How to name the embedded items in the collection
body Object   The HAL response body
options Object   Options to determine how paging is parsed
options.offset integer   Set the offset value
options.offsetKey string   Set the key at which offset can be found in HAL response. Fallback for options.offset
options.limit integer   Set the limit value
options.limitKey string   Set the key at which limit can be found in HAL response. Fallback for options.limit
options.total integer   Set the total value
options.totalKey string   Set the key at which total can be found in HAL response. Fallback for options.total
options.embeddedKey string   Set the key at which embedded items can be found in HAL response.
[options.resourceFactory] function Resource.factory Factory function to convert an embedded item from the HAL response to a Resource instance. Will be called with two arguments (item, body).

Collection.factory(name, items, options) ⇒ Resource

Static method to create a new collection using the constructor

Kind: static method of Collection
Returns: Resource - the constructed resource

Param Type Default Description
name string   How to name the embedded items in the collection
items Array   Array of Resource instances that represent the items of the collection
options Object   Options to determine how paging is parsed
options.offset integer   Set the offset value
options.limit integer   Set the limit value
options.total integer   Set the total value
[options.pageable] boolean true Whether or not this collection supports paging