AbstractBeAdapter


title: AbstractBeAdapter

Classes

AbstractBeAdapterAbstract
AbstractBeAdapter

AbstractBeAdapter ⇐ Abstract

Kind: global abstract class
Extends: Abstract
Singleton:
Properties

NameTypeDefaultDescription
xhrServiceXhrService

A reference on the AJAX Xhr manager.

baseUrlString

Rest server url (only used for _buildRestRequest)

timeoutNumber5000

Request timeout

AbstractBeAdapter()

Abstract class dealing with Back-End transactions as an adapter.

AbstractBeAdapter()

Create clean empty fields inside this adapter at startup.

_buildRestRequest(action, parameters) ⇒ String

create an url with baseUrl+action

     action="rest/model/{modelId}"
     parameters={modelId: 123}

     return "http://baseUrl/rest/model/123"

Kind: instance method of AbstractBeAdapter
Returns: String - rest url
Access: protected

ParamTypeDescription
actionString

Rest api

parametersObject

Rest parameters

_buildRequestId(url, params, config) ⇒ String

Create an id with url+params

Kind: instance method of AbstractBeAdapter
Returns: String - id
Access: protected

ParamTypeDescription
urlString

url of request

paramsObject

parameters of request

configobject

_getCommonParameters() ⇒ Promise.<Object>

Should return a promise with the common query to all GET requests Promise result will be cached through _getMergedParams (this method will only be called once)

Kind: instance method of AbstractBeAdapter
Access: protected

_getMergedParams(query) ⇒ Promise.<Object>

Merge on-call query with common query (retrieved from _getCommonParameters). This function also cache common query result.

Kind: instance method of AbstractBeAdapter
Access: protected

ParamTypeDescription
queryObject

on-call query

_getCommonRequestQuery() ⇒ Promise.<Object>

Should return a promise with the common query (applied as query string for HEAD/GET/PATCH/PUT/POST/DELETE) Promise result wont be cached unlike the one in _getCommonParameters

Kind: instance method of AbstractBeAdapter
Access: protected

_getCommonRequestData() ⇒ Promise.<Object>

Should return a promise with the common “data” (applied as query string for HEAD/GETs or request payload for PATCH/PUT/POST/DELETE) Promise result wont be cached unlike the one in _getCommonParameters

Kind: instance method of AbstractBeAdapter
Access: protected

_getXhrHeaders() ⇒ Promise.<Object>

Return xhr headers, by default a copy of static REQUEST_HEADERS

Kind: instance method of AbstractBeAdapter
Access: protected

_getXhrConfiguration() ⇒ Promise.<Object>

Generate Xhr configuration with headers

Kind: instance method of AbstractBeAdapter
Access: protected

_head(url, [query], [config]) ⇒ Promise.<object>

Make a HEAD request to the specified URL

Kind: instance method of AbstractBeAdapter
Returns: Promise.<object> - The promise resolves with an object similar to the XHR object, or rejects with an error object.
See: AbstractXhrService#head

Will invoke _getCommonRequestQuery, _getCommonRequestData and _getXhrConfiguration. Might invoke _manageXhrResponse or _manageXhrError or both (in case first one returns a rejected promise)

ParamTypeDescription
urlstring

Request URL (w/o fragment nor query if query arg is defined)

[query]object

Request URL query (as an object)

[config]object

Request extra XHR config

_get(url, [query], [config], [force]) ⇒ Promise.<object>

Make a (optionally debounced) GET request to the specified URL

Kind: instance method of AbstractBeAdapter
Returns: Promise.<object> - The promise resolves with an object similar to the XHR object, or rejects with an error object.
See: AbstractXhrService#get

Will invoke _getMergedParams, _getCommonRequestQuery, _getCommonRequestData and _getXhrConfiguration Might invoke _manageXhrResponse or _manageXhrError or both (in case first one returns a rejected promise)

ParamTypeDefaultDescription
urlstring

Request URL (w/o fragment nor query if query arg is defined)

[query]object

Request URL query (as an object)

[config]object

Request extra XHR config

[force]booleanfalse

If true, will execute the request outside of debouncing

_post(url, [jsonPayload], [config], [query]) ⇒ Promise.<object>

Make a POST request to the specified URL

Kind: instance method of AbstractBeAdapter
Returns: Promise.<object> - The promise resolves with an object similar to the XHR object, or rejects with an error object.
See: AbstractXhrService#post

Will invoke _getCommonRequestQuery, _getCommonRequestData and _getXhrConfiguration. Might invoke _manageXhrResponse or _manageXhrError or both (in case first one returns a rejected promise)

ParamTypeDescription
urlstring

Request URL (w/o fragment nor query if query arg is defined)

[jsonPayload]*

Payload to send as application/json

[config]object

Request extra XHR config

[query]object

Request URL query (as an object)

_put(url, [jsonPayload], [config], [query]) ⇒ Promise.<object>

Make a PUT request to the specified URL

Kind: instance method of AbstractBeAdapter
Returns: Promise.<object> - The promise resolves with an object similar to the XHR object, or rejects with an error object.
See: AbstractXhrService#put

Will invoke _getCommonRequestQuery, _getCommonRequestData and _getXhrConfiguration. Might invoke _manageXhrResponse or _manageXhrError or both (in case first one returns a rejected promise)

ParamTypeDescription
urlstring

Request URL (w/o fragment nor query if query arg is defined)

[jsonPayload]*

Payload to send as application/json

[config]object

Request extra XHR config

[query]object

Request URL query (as an object)

_patch(url, [jsonPayload], [config], [query]) ⇒ Promise.<object>

Make a PATCH request to the specified URL

Kind: instance method of AbstractBeAdapter
Returns: Promise.<object> - The promise resolves with an object similar to the XHR object, or rejects with an error object.
See: AbstractXhrService#patch

Will invoke _getCommonRequestQuery, _getCommonRequestData and _getXhrConfiguration. Might invoke _manageXhrResponse or _manageXhrError or both (in case first one returns a rejected promise)

ParamTypeDescription
urlstring

Request URL (w/o fragment nor query if query arg is defined)

[jsonPayload]*

Payload to send as application/json

[config]object

Request extra XHR config

[query]object

Request URL query (as an object)

_delete(url, [query], [config]) ⇒ Promise.<object>

Make a DELETE request to the specified URL

Kind: instance method of AbstractBeAdapter
Returns: Promise.<object> - The promise resolves with an object similar to the XHR object, or rejects with an error object.
See: AbstractXhrService#del

Will invoke _getCommonRequestQuery, _getCommonRequestData and _getXhrConfiguration. Might invoke _manageXhrResponse or _manageXhrError or both (in case first one returns a rejected promise)
Todo

  • Add the jsonPayload parameter. In the meanwhile, you can set config to {json: [jsonPayload]}}.
ParamTypeDescription
urlstring

Request URL (w/o fragment nor query if query arg is defined)

[query]object

Request URL query (as an object)

[config]object

Request extra XHR config

_manageXhrResponse(xhrResponse) ⇒ Promise.<Object>

Method dealing by default with the current XHR request response.

Kind: instance method of AbstractBeAdapter
Returns: Promise.<Object> - A promise properly handling previous XHR response
Access: protected

ParamTypeDescription
xhrResponseObject

Needed AJAX Xhr response

_manageXhrError(error)

Method dealing by default with current XHR error response.

Kind: instance method of AbstractBeAdapter
Access: protected

ParamTypeDescription
errorstring

Needed AJAX Xhr error field

REQUEST_HEADERS : Object

Request Headers

Kind: static property of AbstractBeAdapter

AbstractBeAdapter

Kind: global class

AbstractBeAdapter()

Abstract class dealing with Back-End transactions as an adapter.

AbstractBeAdapter()

Create clean empty fields inside this adapter at startup.

_buildRestRequest(action, parameters) ⇒ String

create an url with baseUrl+action

     action="rest/model/{modelId}"
     parameters={modelId: 123}

     return "http://baseUrl/rest/model/123"

Kind: instance method of AbstractBeAdapter
Returns: String - rest url
Access: protected

ParamTypeDescription
actionString

Rest api

parametersObject

Rest parameters

_buildRequestId(url, params, config) ⇒ String

Create an id with url+params

Kind: instance method of AbstractBeAdapter
Returns: String - id
Access: protected

ParamTypeDescription
urlString

url of request

paramsObject

parameters of request

configobject

_getCommonParameters() ⇒ Promise.<Object>

Should return a promise with the common query to all GET requests Promise result will be cached through _getMergedParams (this method will only be called once)

Kind: instance method of AbstractBeAdapter
Access: protected

_getMergedParams(query) ⇒ Promise.<Object>

Merge on-call query with common query (retrieved from _getCommonParameters). This function also cache common query result.

Kind: instance method of AbstractBeAdapter
Access: protected

ParamTypeDescription
queryObject

on-call query

_getCommonRequestQuery() ⇒ Promise.<Object>

Should return a promise with the common query (applied as query string for HEAD/GET/PATCH/PUT/POST/DELETE) Promise result wont be cached unlike the one in _getCommonParameters

Kind: instance method of AbstractBeAdapter
Access: protected

_getCommonRequestData() ⇒ Promise.<Object>

Should return a promise with the common “data” (applied as query string for HEAD/GETs or request payload for PATCH/PUT/POST/DELETE) Promise result wont be cached unlike the one in _getCommonParameters

Kind: instance method of AbstractBeAdapter
Access: protected

_getXhrHeaders() ⇒ Promise.<Object>

Return xhr headers, by default a copy of static REQUEST_HEADERS

Kind: instance method of AbstractBeAdapter
Access: protected

_getXhrConfiguration() ⇒ Promise.<Object>

Generate Xhr configuration with headers

Kind: instance method of AbstractBeAdapter
Access: protected

_head(url, [query], [config]) ⇒ Promise.<object>

Make a HEAD request to the specified URL

Kind: instance method of AbstractBeAdapter
Returns: Promise.<object> - The promise resolves with an object similar to the XHR object, or rejects with an error object.
See: AbstractXhrService#head

Will invoke _getCommonRequestQuery, _getCommonRequestData and _getXhrConfiguration. Might invoke _manageXhrResponse or _manageXhrError or both (in case first one returns a rejected promise)

ParamTypeDescription
urlstring

Request URL (w/o fragment nor query if query arg is defined)

[query]object

Request URL query (as an object)

[config]object

Request extra XHR config

_get(url, [query], [config], [force]) ⇒ Promise.<object>

Make a (optionally debounced) GET request to the specified URL

Kind: instance method of AbstractBeAdapter
Returns: Promise.<object> - The promise resolves with an object similar to the XHR object, or rejects with an error object.
See: AbstractXhrService#get

Will invoke _getMergedParams, _getCommonRequestQuery, _getCommonRequestData and _getXhrConfiguration Might invoke _manageXhrResponse or _manageXhrError or both (in case first one returns a rejected promise)

ParamTypeDefaultDescription
urlstring

Request URL (w/o fragment nor query if query arg is defined)

[query]object

Request URL query (as an object)

[config]object

Request extra XHR config

[force]booleanfalse

If true, will execute the request outside of debouncing

_post(url, [jsonPayload], [config], [query]) ⇒ Promise.<object>

Make a POST request to the specified URL

Kind: instance method of AbstractBeAdapter
Returns: Promise.<object> - The promise resolves with an object similar to the XHR object, or rejects with an error object.
See: AbstractXhrService#post

Will invoke _getCommonRequestQuery, _getCommonRequestData and _getXhrConfiguration. Might invoke _manageXhrResponse or _manageXhrError or both (in case first one returns a rejected promise)

ParamTypeDescription
urlstring

Request URL (w/o fragment nor query if query arg is defined)

[jsonPayload]*

Payload to send as application/json

[config]object

Request extra XHR config

[query]object

Request URL query (as an object)

_put(url, [jsonPayload], [config], [query]) ⇒ Promise.<object>

Make a PUT request to the specified URL

Kind: instance method of AbstractBeAdapter
Returns: Promise.<object> - The promise resolves with an object similar to the XHR object, or rejects with an error object.
See: AbstractXhrService#put

Will invoke _getCommonRequestQuery, _getCommonRequestData and _getXhrConfiguration. Might invoke _manageXhrResponse or _manageXhrError or both (in case first one returns a rejected promise)

ParamTypeDescription
urlstring

Request URL (w/o fragment nor query if query arg is defined)

[jsonPayload]*

Payload to send as application/json

[config]object

Request extra XHR config

[query]object

Request URL query (as an object)

_patch(url, [jsonPayload], [config], [query]) ⇒ Promise.<object>

Make a PATCH request to the specified URL

Kind: instance method of AbstractBeAdapter
Returns: Promise.<object> - The promise resolves with an object similar to the XHR object, or rejects with an error object.
See: AbstractXhrService#patch

Will invoke _getCommonRequestQuery, _getCommonRequestData and _getXhrConfiguration. Might invoke _manageXhrResponse or _manageXhrError or both (in case first one returns a rejected promise)

ParamTypeDescription
urlstring

Request URL (w/o fragment nor query if query arg is defined)

[jsonPayload]*

Payload to send as application/json

[config]object

Request extra XHR config

[query]object

Request URL query (as an object)

_delete(url, [query], [config]) ⇒ Promise.<object>

Make a DELETE request to the specified URL

Kind: instance method of AbstractBeAdapter
Returns: Promise.<object> - The promise resolves with an object similar to the XHR object, or rejects with an error object.
See: AbstractXhrService#del

Will invoke _getCommonRequestQuery, _getCommonRequestData and _getXhrConfiguration. Might invoke _manageXhrResponse or _manageXhrError or both (in case first one returns a rejected promise)
Todo

  • Add the jsonPayload parameter. In the meanwhile, you can set config to {json: [jsonPayload]}}.
ParamTypeDescription
urlstring

Request URL (w/o fragment nor query if query arg is defined)

[query]object

Request URL query (as an object)

[config]object

Request extra XHR config

_manageXhrResponse(xhrResponse) ⇒ Promise.<Object>

Method dealing by default with the current XHR request response.

Kind: instance method of AbstractBeAdapter
Returns: Promise.<Object> - A promise properly handling previous XHR response
Access: protected

ParamTypeDescription
xhrResponseObject

Needed AJAX Xhr response

_manageXhrError(error)

Method dealing by default with current XHR error response.

Kind: instance method of AbstractBeAdapter
Access: protected

ParamTypeDescription
errorstring

Needed AJAX Xhr error field

REQUEST_HEADERS : Object

Request Headers

Kind: static property of AbstractBeAdapter