Home Reference Source Test

Function

Static Public Summary
public

capable(capabilities: Array<String>): Function

Generates a decorator function ensuring that the specified capabilities are available on the server before executing it.

public

checkVersion(version: String, minVersion: String, maxVersion: String)

Checks if a version is within the provided range.

public

createFormData(dataURL: String, body: Object, options: Object): FormData

Creates a FormData instance from a data url and an existing JSON response body.

public

delay(ms: *): *

Returns a Promise always resolving after the specified amount in milliseconds.

public

extractFileInfo(dataURL: String): Object

Extracts file information from a data url.

public

isObject(thing: Object): bool

Returns true if the specified value is an object (i.e.

public

nobatch(message: String): Function

Generates a decorator function ensuring an operation is not performed from within a batch request.

public

parseDataURL(dataURL: String): Object

Parses a data url.

public

qsify(obj: Object): String

Transforms an object into an URL query string, stripping out any undefined values.

public

support(min: String, max: String): Function

Generates a decorator function ensuring a version check is performed against the provided requirements before executing it.

Static Private Summary
private

addAttachmentRequest(path: *, dataURI: *, objectPattern2: {"data": *, "permissions": *}, options: {}): {"method": string, "path": *, "headers": *, "body": *}

private

aggregate(responses: Array, requests: Array): Object

Exports batch responses as a result object.

private

Clones an object with all its undefined keys removed.

private

createRequest(path: *, objectPattern1: {"data": *, "permissions": *}, options: {}): {"method": *, "path": *, "headers": *, "body": *}

private

deleteRequest(path: *, options: {}): {"method": string, "path": *, "headers": *}

private

endpoint(name: String, args: ...string): String

Retrieves a server enpoint by its name.

private

jsonPatchPermissionsRequest(path: *, permissions: *, opType: *, options: {}): {"method": string, "path": *, "headers": *, "body": *}

private

omit(obj: Object, keys: ...String): Object

Takes an object and returns a copy of it with the provided keys omitted.

private

async pMap(list: Array, fn: Function): Promise

Maps a list to promises using the provided mapping function, executes them sequentially then returns a Promise resolving with ordered results obtained.

private

partition(array: Array, n: Number): Array

Chunks an array into n pieces.

private

safeHeader(safe: *, last_modified: *): {"If-None-Match": string}

private

toDataBody(resource: Object | String): Object

Always returns a resource data object from the provided argument.

private

updateRequest(path: *, objectPattern1: {"data": *, "permissions": *}, options: {}): {"method": *, "path": *, "headers": *, "body": *}

Static Public

public capable(capabilities: Array<String>): Function source

import {capable} from 'kinto-http/lib/utils.js'

Generates a decorator function ensuring that the specified capabilities are available on the server before executing it.

Params:

NameTypeAttributeDescription
capabilities Array<String>

The required capabilities.

Return:

Function

public checkVersion(version: String, minVersion: String, maxVersion: String) source

import {checkVersion} from 'kinto-http/lib/utils.js'

Checks if a version is within the provided range.

Params:

NameTypeAttributeDescription
version String

The version to check.

minVersion String

The minimum supported version (inclusive).

maxVersion String

The minimum supported version (exclusive).

Throw:

Error

If the version is outside of the provided range.

public createFormData(dataURL: String, body: Object, options: Object): FormData source

import {createFormData} from 'kinto-http/lib/utils.js'

Creates a FormData instance from a data url and an existing JSON response body.

Params:

NameTypeAttributeDescription
dataURL String

The data url.

body Object

The response body.

options Object
  • optional
  • default: {}

The options object.

options.filename Object
  • optional

Force attachment file name.

Return:

FormData

public delay(ms: *): * source

import {delay} from 'kinto-http/lib/utils.js'

Returns a Promise always resolving after the specified amount in milliseconds.

Params:

NameTypeAttributeDescription
ms *

Return:

*

Promise<void>

Test:

public extractFileInfo(dataURL: String): Object source

import {extractFileInfo} from 'kinto-http/lib/utils.js'

Extracts file information from a data url.

Params:

NameTypeAttributeDescription
dataURL String

The data url.

Return:

Object

public isObject(thing: Object): bool source

import {isObject} from 'kinto-http/lib/utils.js'

Returns true if the specified value is an object (i.e. not an array nor null).

Params:

NameTypeAttributeDescription
thing Object

The value to inspect.

Return:

bool

public nobatch(message: String): Function source

import {nobatch} from 'kinto-http/lib/utils.js'

Generates a decorator function ensuring an operation is not performed from within a batch request.

Params:

NameTypeAttributeDescription
message String

The error message to throw.

Return:

Function

public parseDataURL(dataURL: String): Object source

import {parseDataURL} from 'kinto-http/lib/utils.js'

Parses a data url.

Params:

NameTypeAttributeDescription
dataURL String

The data url.

Return:

Object

public qsify(obj: Object): String source

import {qsify} from 'kinto-http/lib/utils.js'

Transforms an object into an URL query string, stripping out any undefined values.

Params:

NameTypeAttributeDescription
obj Object

Return:

String

Test:

public support(min: String, max: String): Function source

import {support} from 'kinto-http/lib/utils.js'

Generates a decorator function ensuring a version check is performed against the provided requirements before executing it.

Params:

NameTypeAttributeDescription
min String

The required min version (inclusive).

max String

The required max version (inclusive).

Return:

Function

Static Private

private addAttachmentRequest(path: *, dataURI: *, objectPattern2: {"data": *, "permissions": *}, options: {}): {"method": string, "path": *, "headers": *, "body": *} source

import {addAttachmentRequest} from 'kinto-http/lib/requests.js'

Params:

NameTypeAttributeDescription
path *
dataURI *
objectPattern2 {"data": *, "permissions": *}
  • optional
  • default: {}
options {}
  • optional
  • default: {}

Return:

{"method": string, "path": *, "headers": *, "body": *}

private aggregate(responses: Array, requests: Array): Object source

import {aggregate} from 'kinto-http/lib/batch.js'

Exports batch responses as a result object.

Params:

NameTypeAttributeDescription
responses Array

The batch subrequest responses.

requests Array

The initial issued requests.

Return:

Object

private cleanUndefinedProperties(obj: *): * source

import {cleanUndefinedProperties} from 'kinto-http/lib/utils.js'

Clones an object with all its undefined keys removed.

Params:

NameTypeAttributeDescription
obj *

Return:

*

private createRequest(path: *, objectPattern1: {"data": *, "permissions": *}, options: {}): {"method": *, "path": *, "headers": *, "body": *} source

import {createRequest} from 'kinto-http/lib/requests.js'

Params:

NameTypeAttributeDescription
path *
objectPattern1 {"data": *, "permissions": *}
  • default: {"data":null,"permissions":null}
options {}
  • optional
  • default: {}

Return:

{"method": *, "path": *, "headers": *, "body": *}

private deleteRequest(path: *, options: {}): {"method": string, "path": *, "headers": *} source

import {deleteRequest} from 'kinto-http/lib/requests.js'

Params:

NameTypeAttributeDescription
path *
options {}
  • optional
  • default: {}

Return:

{"method": string, "path": *, "headers": *}

private endpoint(name: String, args: ...string): String source

import endpoint from 'kinto-http/lib/endpoint.js'

Retrieves a server enpoint by its name.

Params:

NameTypeAttributeDescription
name String

The endpoint name.

args ...string

The endpoint parameters.

Return:

String

Test:

private jsonPatchPermissionsRequest(path: *, permissions: *, opType: *, options: {}): {"method": string, "path": *, "headers": *, "body": *} source

import {jsonPatchPermissionsRequest} from 'kinto-http/lib/requests.js'

Params:

NameTypeAttributeDescription
path *
permissions *
opType *
options {}
  • optional
  • default: {}

Return:

{"method": string, "path": *, "headers": *, "body": *}

private omit(obj: Object, keys: ...String): Object source

import {omit} from 'kinto-http/lib/utils.js'

Takes an object and returns a copy of it with the provided keys omitted.

Params:

NameTypeAttributeDescription
obj Object

The source object.

keys ...String

The keys to omit.

Return:

Object

Test:

private async pMap(list: Array, fn: Function): Promise source

import {pMap} from 'kinto-http/lib/utils.js'

Maps a list to promises using the provided mapping function, executes them sequentially then returns a Promise resolving with ordered results obtained. Think of this as a sequential Promise.all.

Params:

NameTypeAttributeDescription
list Array

The list to map.

fn Function

The mapping function.

Return:

Promise

Test:

private partition(array: Array, n: Number): Array source

import {partition} from 'kinto-http/lib/utils.js'

Chunks an array into n pieces.

Params:

NameTypeAttributeDescription
array Array
n Number

Return:

Array

Test:

private safeHeader(safe: *, last_modified: *): {"If-None-Match": string} source

Params:

NameTypeAttributeDescription
safe *
last_modified *

Return:

{"If-None-Match": string}

private toDataBody(resource: Object | String): Object source

import {toDataBody} from 'kinto-http/lib/utils.js'

Always returns a resource data object from the provided argument.

Params:

NameTypeAttributeDescription
resource Object | String

Return:

Object

private updateRequest(path: *, objectPattern1: {"data": *, "permissions": *}, options: {}): {"method": *, "path": *, "headers": *, "body": *} source

import {updateRequest} from 'kinto-http/lib/requests.js'

Params:

NameTypeAttributeDescription
path *
objectPattern1 {"data": *, "permissions": *}
  • default: {"data":null,"permissions":null}
options {}
  • optional
  • default: {}

Return:

{"method": *, "path": *, "headers": *, "body": *}