Home Reference Source
import {ListResource} from '@fnndsc/chrisapi'
public class | source

ListResource

Extends:

Resource → ListResource

API abstract list resource class.

Constructor Summary

Public Constructor
public

constructor(url: string, auth: Object)

Constructor

Member Summary

Public Members
public
public get

Get the list of item data objects (REST API descriptors).

public get

Return true if the list resource object has a next list page in the paginated REST API.

public get

Return true if the list resource object has a previous list page in the paginated REST API.

public
public
public
public get

Get the total count of items of the entire collection across pages in the paginated REST API.

Method Summary

Public Methods
public

get(searchParams: Object, timeout: number): Promise<this>

Fetch this list resource from the REST API based on search parameters.

public

Get an item resource object given its id from the list of items in this list resource object.

public

Get an array of item resource objects corresponding to the items in this list resource object.

public

Get an array of parameter names that can be used as properties of the data object in POST requests.

public

Get an array of search parameter names that can be used as properties of the searchParams argument to the get method.

Private Methods
private

_getResource(linkRelation: string, ResourceClass: Object, searchParams: Object, timeout: number): Promise<ResourceClass>

Internal method to fetch a related resource from the REST API that is referenced by a link relation within this list resource's collection object.

private

_post(data: Object, uploadFileObj: Object, timeout: number): Promise<this>

Internal helper method to make a POST request to this list resource through the REST API.

Inherited Summary

From class Resource
public static

cloneObj(obj: Object): *

Helper method to make a deep copy clone of the passed object resource.

public get

Return true if the resource object contains any data.

public
public
public
public
public

Make a deep copy clone of this object resource.

Public Constructors

public constructor(url: string, auth: Object) source

Constructor

Override:

Resource#constructor

Params:

NameTypeAttributeDescription
url string

url of the list resource

auth Object
  • optional
  • default: null

authentication object

auth.token string
  • optional

authentication token

Public Members

public collection: * source

Override:

Resource#collection

public get data: Object[] source

Get the list of item data objects (REST API descriptors).

public get hasNextPage: boolean source

Return true if the list resource object has a next list page in the paginated REST API.

public get hasPreviousPage: boolean source

Return true if the list resource object has a previous list page in the paginated REST API.

public itemClass: Object source

public queryUrl: string source

public searchParams: Object source

public get totalCount: number source

Get the total count of items of the entire collection across pages in the paginated REST API. Return -1 if no data has been fetched or the total number of items info is not available from the fetched data.

Public Methods

public get(searchParams: Object, timeout: number): Promise<this> source

Fetch this list resource from the REST API based on search parameters. If no search parameters then get the default first page.

Params:

NameTypeAttributeDescription
searchParams Object
  • optional
  • default: null

search parameters object which is resource-specific, the getSearchParameters method can be used to get a list of possible search parameters

searchParams.limit number
  • optional

page limit

searchParams.offset number
  • optional

page offset

timeout number
  • optional
  • default: 30000

request timeout

Return:

Promise<this>

JS Promise, resolves to this object

public getItem(id: number): Object source

Get an item resource object given its id from the list of items in this list resource object.

Params:

NameTypeAttributeDescription
id number

item id

Return:

Object

an instance of this.itemClass

public getItems(): Object[] source

Get an array of item resource objects corresponding to the items in this list resource object.

Return:

Object[] (nullable: true)

public getPOSTParameters(): string[] source

Get an array of parameter names that can be used as properties of the data object in POST requests.

Return:

string[] (nullable: true)

array of POST data properties or null if this list resource's data has not been fetched from the API yet or it doesn't support POST requests.

public getSearchParameters(): string[] source

Get an array of search parameter names that can be used as properties of the searchParams argument to the get method.

Return:

string[] (nullable: true)

array of search parameter names or null if this list resource's data has not been fetched from the API yet.

Private Methods

private _getResource(linkRelation: string, ResourceClass: Object, searchParams: Object, timeout: number): Promise<ResourceClass> source

Internal method to fetch a related resource from the REST API that is referenced by a link relation within this list resource's collection object.

Params:

NameTypeAttributeDescription
linkRelation string
ResourceClass Object
searchParams Object
  • optional
  • default: null

search parameters object which is resource-specific

searchParams.limit number
  • optional

page limit

searchParams.offset number
  • optional

page offset

timeout number
  • optional
  • default: 30000

request timeout

Return:

Promise<ResourceClass>

JS Promise, resolves to a ResourceClass object

Throw:

RequestException

throw error if this list resource has not yet been fetched from the REST API

RequestException

throw error when the link relation is not found

private _post(data: Object, uploadFileObj: Object, timeout: number): Promise<this> source

Internal helper method to make a POST request to this list resource through the REST API.

Params:

NameTypeAttributeDescription
data Object

request JSON data object

uploadFileObj Object
  • nullable: true

custom file object

uploadFileObj.fname Object

file blob

timeout number
  • optional
  • default: 30000

request timeout

Return:

Promise<this>

JS Promise, resolves to this object