Home Reference Source Test
import Collection from 'kinto-http/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, options: Object)

Constructor.

Member Summary

Public Members
public

name: String

The collection name.

Private Members
private

_headers: {...undefined: Object}

private

_safe: *

Method Summary

Public Methods
public

async addAttachment(dataURL: String, record: Object, options: Object): Promise<Object, Error>

Adds an attachment to a record, creating the record when it doesn't exist.

public

async addPermissions(permissions: Object, options: Object): Promise<Object, Error>

Append principals to the collection permissions.

public

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

Performs batch operations at the current collection level.

public

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

Creates a record in current collection.

public

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

Deletes a record from the current collection.

public

async getData(options: Object): Promise<Object, Error>

Retrieves collection data.

public

async getPermissions(options: Object): Promise<Object, Error>

Retrieves the list of permissions for this collection.

public

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

Retrieves a record from the current collection.

public

async getTotalRecords(options: Object): Promise<Number, Error>

Retrieves the total number of records in this collection.

public

async listRecords(options: Object): Promise<Object, Error>

Lists records from the current collection.

public

async removeAttachment(recordId: Object, options: Object): *

Removes an attachment from a given record.

public

async removePermissions(permissions: Object, options: Object): Promise<Object, Error>

Remove principals from the collection permissions.

public

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

Set collection data.

public

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

Replaces all existing collection permissions with the ones provided.

public

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

Updates a record in current collection.

Private Methods
private

_getHeaders(options: *): {...undefined: Object}

Get the value of "headers" for a given request, merging the per-request headers with our own "default" headers.

private

_getRetry(options: *): *

As _getSafe, but for "retry".

private

_getSafe(options: Object): Boolean

Get the value of "safe" for a given request, using the per-request option if present or falling back to our default otherwise.

private

async getSnapshot(at: *): {"last_modified": *, "data": *, "next": *, "hasNextPage": *, "totalRecords": *}

private

async isHistoryComplete(): *

private

async listChangesBackTo(at: *): *

Public Constructors

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

Constructor.

Params:

NameTypeAttributeDescription
client KintoClient

The client instance.

bucket Bucket

The bucket instance.

name String

The collection name.

options Object
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.safe Boolean
  • optional

The safe option.

options.retry Number
  • optional

The retry option.

options.batch Boolean
  • optional

(Private) Whether this Collection is operating as part of a batch.

Public Members

public name: String source

The collection name.

Private Members

private _headers: {...undefined: Object} source

private _safe: * source

Public Methods

public async addAttachment(dataURL: String, record: Object, options: Object): Promise<Object, Error> source

Adds an attachment to a record, creating the record when it doesn't exist.

Params:

NameTypeAttributeDescription
dataURL String

The data url.

record Object
  • optional
  • default: {}

The record data.

options Object
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

options.safe Boolean
  • optional

The safe option.

options.last_modified Number
  • optional

The last_modified option.

options.permissions Object
  • optional

The permissions option.

options.filename String
  • optional

Force the attachment filename.

options.gzipped String
  • optional

Force the attachment to be gzipped or not.

Return:

Promise<Object, Error>

Decorators:

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

Append principals to the collection permissions.

Params:

NameTypeAttributeDescription
permissions Object

The permissions object.

options Object
  • optional
  • default: {}

The options object

options.safe Boolean
  • optional

The safe option.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

options.last_modified Object
  • optional

The last_modified option.

Return:

Promise<Object, Error>

Test:

public async 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
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.safe Boolean
  • optional

The safe option.

options.retry Number
  • optional

The retry option.

options.aggregate Boolean
  • optional

Produces a grouped result object.

Return:

Promise<Object, Error>

Test:

public async 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
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

options.safe Boolean
  • optional

The safe option.

options.permissions Object
  • optional

The permissions option.

Return:

Promise<Object, Error>

Test:

public async 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
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

options.safe Boolean
  • optional

The safe option.

options.last_modified Number
  • optional

The last_modified option.

Return:

Promise<Object, Error>

Test:

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

Retrieves collection data.

Params:

NameTypeAttributeDescription
options Object
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

Return:

Promise<Object, Error>

Test:

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

Retrieves the list of permissions for this collection.

Params:

NameTypeAttributeDescription
options Object
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

Return:

Promise<Object, Error>

Test:

public async 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
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

Return:

Promise<Object, Error>

Test:

public async getTotalRecords(options: Object): Promise<Number, Error> source

Retrieves the total number of records in this collection.

Params:

NameTypeAttributeDescription
options Object
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

Return:

Promise<Number, Error>

Test:

public async 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
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

options.filters Object
  • optional
  • default: []

The filters object.

options.sort String
  • optional
  • default: "-last_modified"

The sort field.

options.at String
  • optional

The timestamp to get a snapshot at.

options.limit String
  • optional
  • default: null

The limit field.

options.pages String
  • optional
  • default: 1

The number of result pages to aggregate.

options.since Number
  • optional
  • default: null

Only retrieve records modified since the provided timestamp.

Return:

Promise<Object, Error>

Test:

See:

public async removeAttachment(recordId: Object, options: Object): * source

Removes an attachment from a given record.

Params:

NameTypeAttributeDescription
recordId Object

The record id.

options Object
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

options.safe Boolean
  • optional

The safe option.

options.last_modified Number
  • optional

The last_modified option.

Return:

*

Decorators:

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

Remove principals from the collection permissions.

Params:

NameTypeAttributeDescription
permissions Object

The permissions object.

options Object
  • optional
  • default: {}

The options object

options.safe Boolean
  • optional

The safe option.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

options.last_modified Object
  • optional

The last_modified option.

Return:

Promise<Object, Error>

Test:

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

Set collection data.

Params:

NameTypeAttributeDescription
data Object

The collection data object.

options Object
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

options.safe Boolean
  • optional

The safe option.

options.patch Boolean
  • optional

The patch option.

options.last_modified Number
  • optional

The last_modified option.

Return:

Promise<Object, Error>

Test:

public async 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
  • optional
  • default: {}

The options object

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

options.safe Boolean
  • optional

The safe option.

options.last_modified Number
  • optional

The last_modified option.

Return:

Promise<Object, Error>

Test:

public async 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
  • optional
  • default: {}

The options object.

options.headers Object
  • optional

The headers object option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

options.safe Boolean
  • optional

The safe option.

options.last_modified Number
  • optional

The last_modified option.

options.permissions Object
  • optional

The permissions option.

Return:

Promise<Object, Error>

Test:

Private Methods

private _getHeaders(options: *): {...undefined: Object} source

Get the value of "headers" for a given request, merging the per-request headers with our own "default" headers.

Params:

NameTypeAttributeDescription
options *

Return:

{...undefined: Object}

private _getRetry(options: *): * source

As _getSafe, but for "retry".

Params:

NameTypeAttributeDescription
options *

Return:

*

private _getSafe(options: Object): Boolean source

Get the value of "safe" for a given request, using the per-request option if present or falling back to our default otherwise.

Params:

NameTypeAttributeDescription
options Object

The options for a request.

Return:

Boolean

private async getSnapshot(at: *): {"last_modified": *, "data": *, "next": *, "hasNextPage": *, "totalRecords": *} source

Params:

NameTypeAttributeDescription
at *

Return:

{"last_modified": *, "data": *, "next": *, "hasNextPage": *, "totalRecords": *}

Decorators:

private async isHistoryComplete(): * source

Return:

*

private async listChangesBackTo(at: *): * source

Params:

NameTypeAttributeDescription
at *

Return:

*