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:
Name | Type | Attribute | Description |
client | KintoClient | The client instance. |
|
bucket | Bucket | The bucket instance. |
|
name | String | The collection name. |
|
options | Object |
|
The options object. |
options.headers | Object |
|
The headers object option. |
options.safe | Boolean |
|
The safe option. |
options.retry | Number |
|
The retry option. |
options.batch | Boolean |
|
(Private) Whether this Collection is operating as part of a batch. |
Public Members
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:
Name | Type | Attribute | Description |
dataURL | String | The data url. |
|
record | Object |
|
The record data. |
options | Object |
|
The options object. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
options.safe | Boolean |
|
The safe option. |
options.last_modified | Number |
|
The last_modified option. |
options.permissions | Object |
|
The permissions option. |
options.filename | String |
|
Force the attachment filename. |
options.gzipped | String |
|
Force the attachment to be gzipped or not. |
Return:
Promise<Object, Error> |
Decorators:
- capable(["attachments"])
public async addPermissions(permissions: Object, options: Object): Promise<Object, Error> source
Append principals to the collection permissions.
Params:
Name | Type | Attribute | Description |
permissions | Object | The permissions object. |
|
options | Object |
|
The options object |
options.safe | Boolean |
|
The safe option. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
options.last_modified | Object |
|
The last_modified option. |
Return:
Promise<Object, Error> |
public async batch(fn: Function, options: Object): Promise<Object, Error> source
Performs batch operations at the current collection level.
Params:
Name | Type | Attribute | Description |
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.retry | Number |
|
The retry option. |
options.aggregate | Boolean |
|
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:
Name | Type | Attribute | Description |
record | Object | The record to create. |
|
options | Object |
|
The options object. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
options.safe | Boolean |
|
The safe option. |
options.permissions | Object |
|
The permissions option. |
Return:
Promise<Object, Error> |
public async deleteRecord(record: Object | String, options: Object): Promise<Object, Error> source
Deletes a record from the current collection.
Params:
Name | Type | Attribute | Description |
record | Object | String | The record to delete. |
|
options | Object |
|
The options object. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
options.safe | Boolean |
|
The safe option. |
options.last_modified | Number |
|
The last_modified option. |
Return:
Promise<Object, Error> |
public async getData(options: Object): Promise<Object, Error> source
Retrieves collection data.
Params:
Name | Type | Attribute | Description |
options | Object |
|
The options object. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
Return:
Promise<Object, Error> |
public async getPermissions(options: Object): Promise<Object, Error> source
Retrieves the list of permissions for this collection.
Params:
Name | Type | Attribute | Description |
options | Object |
|
The options object. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
Return:
Promise<Object, Error> |
public async getRecord(id: String, options: Object): Promise<Object, Error> source
Retrieves a record from the current collection.
Params:
Name | Type | Attribute | Description |
id | String | The record id to retrieve. |
|
options | Object |
|
The options object. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
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:
Name | Type | Attribute | Description |
options | Object |
|
The options object. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
Return:
Promise<Number, Error> |
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:
Name | Type | Attribute | Description |
options | Object |
|
The options object. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
options.filters | Object |
|
The filters object. |
options.sort | String |
|
The sort field. |
options.at | String |
|
The timestamp to get a snapshot at. |
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> |
See:
- http://kinto.readthedocs.io/en/stable/api/1.x/sorting.html Filtering is done by passing a `filters` option object: - `{fieldname: "value"}` - `{min_fieldname: 4000}` - `{in_fieldname: "1,2,3"}` - `{not_fieldname: 0}` - `{exclude_fieldname: "0,1"}`
- http://kinto.readthedocs.io/en/stable/api/1.x/filtering.html Paginating is done by passing a `limit` option, then calling the `next()` method from the resolved result object to fetch the next page, if any.
public async removeAttachment(recordId: Object, options: Object): * source
Removes an attachment from a given record.
Params:
Name | Type | Attribute | Description |
recordId | Object | The record id. |
|
options | Object |
|
The options object. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
options.safe | Boolean |
|
The safe option. |
options.last_modified | Number |
|
The last_modified option. |
Return:
* |
Decorators:
- capable(["attachments"])
public async removePermissions(permissions: Object, options: Object): Promise<Object, Error> source
Remove principals from the collection permissions.
Params:
Name | Type | Attribute | Description |
permissions | Object | The permissions object. |
|
options | Object |
|
The options object |
options.safe | Boolean |
|
The safe option. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
options.last_modified | Object |
|
The last_modified option. |
Return:
Promise<Object, Error> |
public async setData(data: Object, options: Object): Promise<Object, Error> source
Set collection data.
Params:
Name | Type | Attribute | Description |
data | Object | The collection data object. |
|
options | Object |
|
The options object. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
options.safe | Boolean |
|
The safe option. |
options.patch | Boolean |
|
The patch option. |
options.last_modified | Number |
|
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:
Name | Type | Attribute | Description |
permissions | Object | The permissions object. |
|
options | Object |
|
The options object |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
options.safe | Boolean |
|
The safe option. |
options.last_modified | Number |
|
The last_modified option. |
Return:
Promise<Object, Error> |
public async updateRecord(record: Object, options: Object): Promise<Object, Error> source
Updates a record in current collection.
Params:
Name | Type | Attribute | Description |
record | Object | The record to update. |
|
options | Object |
|
The options object. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
options.safe | Boolean |
|
The safe option. |
options.last_modified | Number |
|
The last_modified option. |
options.permissions | Object |
|
The permissions option. |
Return:
Promise<Object, Error> |
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:
Name | Type | Attribute | Description |
options | * |
Return:
{...undefined: Object} |
private _getRetry(options: *): * source
As _getSafe, but for "retry".
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
options | Object | The options for a request. |
Return:
Boolean |
private async getSnapshot(at: *): {"last_modified": *, "data": *, "next": *, "hasNextPage": *, "totalRecords": *} source
Params:
Name | Type | Attribute | Description |
at | * |
Return:
{"last_modified": *, "data": *, "next": *, "hasNextPage": *, "totalRecords": *} |
Decorators:
- capable(["history"])
private async listChangesBackTo(at: *): * source
Params:
Name | Type | Attribute | Description |
at | * |
Return:
* |