Home Reference Source Test Repository
import Collection from 'kinto-client/lib/collection.js'
public class | source

Collection

Abstract representation of a selected collection.

Test:

Constructor Summary

Public Constructor
public

constructor(client: KintoClient, bucket: Bucket, name: String)

Constructor.

Member Summary

Public Members
public

The collection name.

Method Summary

Public Methods
public

batch(fn: Function, options: Object): Promise<Object, Error>

Performs batch operations at the current collection level.

public

createRecord(record: Object, options: Object): Promise<Object, Error>

Creates a record in current collection.

public

deleteRecord(record: Object | String, options: Object): Promise<Object, Error>

Deletes a record from the current collection.

public

Retrieves collection data.

public

Retrieves the list of permissions for this collection.

public

Retrieves a record from the current collection.

public

Lists records from the current collection.

public

setData(data: Object, options: Object): Promise<Object, Error>

Set collection data.

public

setPermissions(permissions: Object, options: Object): Promise<Object, Error>

Replaces all existing collection permissions with the ones provided.

public

updateRecord(record: Object, options: Object): Promise<Object, Error>

Updates a record in current collection.

Public Constructors

public constructor(client: KintoClient, bucket: Bucket, name: String) source

Constructor.

Params:

NameTypeAttributeDescription
client KintoClient

The client instance.

bucket Bucket

The bucket instance.

name String

The collection name.

options.headers Object

The headers object option.

options.safe Boolean

The safe option.

Public Members

public name: String source

The collection name.

Public Methods

public batch(fn: Function, options: Object): Promise<Object, Error> source

Performs batch operations at the current collection level.

Params:

NameTypeAttributeDescription
fn Function

The batch operation function.

options Object

The options object.

options.headers Object

The headers object option.

options.safe Boolean

The safe option.

options.aggregate Boolean

Produces a grouped result object.

Return:

Promise<Object, Error>

Test:

public createRecord(record: Object, options: Object): Promise<Object, Error> source

Creates a record in current collection.

Params:

NameTypeAttributeDescription
record Object

The record to create.

options Object

The options object.

options.headers Object

The headers object option.

options.safe Boolean

The safe option.

Return:

Promise<Object, Error>

Test:

public deleteRecord(record: Object | String, options: Object): Promise<Object, Error> source

Deletes a record from the current collection.

Params:

NameTypeAttributeDescription
record Object | String

The record to delete.

options Object

The options object.

options.headers Object

The headers object option.

options.safe Boolean

The safe option.

options.last_modified Number

The last_modified option.

Return:

Promise<Object, Error>

Test:

public getData(options: Object): Promise<Object, Error> source

Retrieves collection data.

Params:

NameTypeAttributeDescription
options Object

The options object.

options.headers Object

The headers object option.

Return:

Promise<Object, Error>

Test:

public getPermissions(options: Object): Promise<Object, Error> source

Retrieves the list of permissions for this collection.

Params:

NameTypeAttributeDescription
options Object

The options object.

options.headers Object

The headers object option.

Return:

Promise<Object, Error>

Test:

public getRecord(id: String, options: Object): Promise<Object, Error> source

Retrieves a record from the current collection.

Params:

NameTypeAttributeDescription
id String

The record id to retrieve.

options Object

The options object.

options.headers Object

The headers object option.

Return:

Promise<Object, Error>

Test:

public listRecords(options: Object): Promise<Object, Error> source

Lists records from the current collection.

Sorting is done by passing a sort string option:

  • The field to order the results by, prefixed with - for descending. Default: -last_modified.

Params:

NameTypeAttributeDescription
options Object

The options object.

options.headers Object

The headers object option.

options.filters Object

The filters object.

options.sort String

The sort field.

options.limit String

The limit field.

options.pages String

The number of result pages to aggregate.

options.since Number

Only retrieve records modified since the provided timestamp.

Return:

Promise<Object, Error>

Test:

See:

public setData(data: Object, options: Object): Promise<Object, Error> source

Set collection data.

Params:

NameTypeAttributeDescription
data Object

The collection data object.

options Object

The options object.

options.headers Object

The headers object option.

options.safe Boolean

The safe option.

options.patch Boolean

The patch option.

Return:

Promise<Object, Error>

public setPermissions(permissions: Object, options: Object): Promise<Object, Error> source

Replaces all existing collection permissions with the ones provided.

Params:

NameTypeAttributeDescription
permissions Object

The permissions object.

options Object

The options object

options.headers Object

The headers object option.

options.safe Boolean

The safe option.

options.last_modified Number

The last_modified option.

Return:

Promise<Object, Error>

Test:

public updateRecord(record: Object, options: Object): Promise<Object, Error> source

Updates a record in current collection.

Params:

NameTypeAttributeDescription
record Object

The record to update.

options Object

The options object.

options.headers Object

The headers object option.

options.safe Boolean

The safe option.

options.last_modified Number

The last_modified option.

Return:

Promise<Object, Error>

Test: