Home Reference Source Test
import Bucket from 'kinto-http/lib/bucket.js'
public class | source

Bucket

Abstract representation of a selected bucket.

Test:

Constructor Summary

Public Constructor
public

constructor(client: KintoClient, name: String, options: Object)

Constructor.

Member Summary

Public Members
public

name: String

The bucket name.

Private Members
private

_retry: *

private

_safe: *

Method Summary

Public Methods
public

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

Append principals to the bucket permissions.

public

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

Performs batch operations at the current bucket level.

public

collection(name: String, options: Object): Collection

Selects a collection.

public

async createCollection(id: String | undefined, options: Object): Promise<Object, Error>

Creates a new collection in current bucket.

public

async createGroup(id: String | undefined, members: Array<String>, options: Object): Promise<Object, Error>

Creates a new group in current bucket.

public

async deleteCollection(collection: Object | String, options: Object): Promise<Object, Error>

Deletes a collection from the current bucket.

public

async deleteGroup(group: Object | String, options: Object): Promise<Object, Error>

Deletes a group from the current bucket.

public

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

Retrieves bucket data.

public

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

Creates a new group in current bucket.

public

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

Retrieves the list of permissions for this bucket.

public

async listCollections(options: Object): Promise<Array<Object>, Error>

Retrieves the list of collections in the current bucket.

public

async listGroups(options: Object): Promise<Array<Object>, Error>

Retrieves the list of groups in the current bucket.

public

async listHistory(options: Object): Promise<Array<Object>, Error>

Retrieves the list of history entries in the current bucket.

public

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

Remove principals from the bucket permissions.

public

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

Set bucket data.

public

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

Replaces all existing bucket permissions with the ones provided.

public

async updateGroup(group: Object, options: Object): Promise<Object, Error>

Updates an existing group in current bucket.

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.

Public Constructors

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

Constructor.

Params:

NameTypeAttributeDescription
client KintoClient

The client instance.

name String

The bucket name.

options Object
  • optional
  • default: {}

The headers object option.

options.headers Object
  • optional

The headers object option.

options.safe Boolean
  • optional

The safe option.

options.retry Number
  • optional

The retry option.

Public Members

public name: String source

The bucket name.

Private Members

private _retry: * source

private _safe: * source

Public Methods

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

Append principals to the bucket 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 bucket 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
  • default: 0

The retry option.

options.aggregate Boolean
  • optional

Produces a grouped result object.

Return:

Promise<Object, Error>

Test:

public collection(name: String, options: Object): Collection source

Selects a collection.

Params:

NameTypeAttributeDescription
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.

Return:

Collection

Test:

public async createCollection(id: String | undefined, options: Object): Promise<Object, Error> source

Creates a new collection in current bucket.

Params:

NameTypeAttributeDescription
id String | undefined

The collection id.

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.permissions Object
  • optional

The permissions object.

options.data Object
  • optional

The data object.

Return:

Promise<Object, Error>

Test:

public async createGroup(id: String | undefined, members: Array<String>, options: Object): Promise<Object, Error> source

Creates a new group in current bucket.

Params:

NameTypeAttributeDescription
id String | undefined

The group id.

members Array<String>
  • optional
  • default: []

The list of principals.

options Object
  • optional
  • default: {}

The options object.

options.data Object
  • optional

The data object.

options.permissions Object
  • optional

The permissions 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.

Return:

Promise<Object, Error>

Test:

public async deleteCollection(collection: Object | String, options: Object): Promise<Object, Error> source

Deletes a collection from the current bucket.

Params:

NameTypeAttributeDescription
collection Object | String

The collection 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 deleteGroup(group: Object | String, options: Object): Promise<Object, Error> source

Deletes a group from the current bucket.

Params:

NameTypeAttributeDescription
group Object | String

The group 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>

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

Retrieves bucket 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 getGroup(id: String, options: Object): Promise<Object, Error> source

Creates a new group in current bucket.

Params:

NameTypeAttributeDescription
id String

The group 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.

Return:

Promise<Object, Error>

Test:

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

Retrieves the list of permissions for this bucket.

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 listCollections(options: Object): Promise<Array<Object>, Error> source

Retrieves the list of collections in the current bucket.

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<Array<Object>, Error>

Test:

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

Retrieves the list of groups in the current bucket.

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<Array<Object>, Error>

Test:

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

Retrieves the list of history entries in the current bucket.

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<Array<Object>, Error>

Decorators:

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

Remove principals from the bucket 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 bucket data.

Params:

NameTypeAttributeDescription
data Object

The bucket data object.

options Object
  • optional
  • default: {}

The options object.

options.headers Object
  • optional
  • default: {}

The headers object option.

options.safe Boolean
  • optional

The safe option.

options.retry Number
  • optional
  • default: 0

Number of retries to make when faced with transient errors.

options.patch Boolean
  • optional

The patch option.

options.last_modified Number
  • optional

The last_modified option.

Return:

Promise<Object, Error>

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

Replaces all existing bucket permissions with the ones provided.

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

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 updateGroup(group: Object, options: Object): Promise<Object, Error> source

Updates an existing group in current bucket.

Params:

NameTypeAttributeDescription
group Object

The group object.

options Object
  • optional
  • default: {}

The options object.

options.data Object
  • optional

The data object.

options.permissions Object
  • optional

The permissions 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 Number
  • optional

The last_modified 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