# Class: BaseLZAdapter

## LocusZoom_Adapters~BaseLZAdapter()

#### new BaseLZAdapter()

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`config.cache_enabled` |  | <optional> | true |
`config.cache_size` |  | <optional> | 3 |
`config.url` |  | <optional> |  |
`config.prefix_namespace` |  | <optional> | true | Whether to modify the API response by prepending namespace to each field name. Most adapters will do this by default, so that each field is unambiguously defined based on where it comes from. (this helps to disambiguate two providers that return similar field names, like assoc:variant and catalog:variant) Typically, this is only disabled if the response payload is very unusual
`config.limit_fields` | Array.<String> | <optional> | null | If an API returns far more data than is needed, this can be used to simplify the payload by excluding unused fields. This can help to reduce memory usage for really big server responses like LD.

Source:
  - data/adapters.js, line 65

### Extends

- module:undercomplicate.BaseUrlAdapter

### Methods

#### _annotateRecords(records, options) → {*}

Perform custom client-side operations on the retrieved data. For example, add calculated fields or perform rapid client-side filtering on cached data. Annotations are applied after cache, which means that the same network request can be dynamically annotated/filtered in different ways in response to user interactions.

This result is currently not cached, but it may become so in the future as responsibility for dynamic UI behavior moves to other layers of the application.

##### Parameters:

Name | Type | Description
--- | --- | ---
`records` | Array.<Object> |
`options` | Object |

Overrides:
  - module:undercomplicate.BaseUrlAdapter#_annotateRecords
Source:
  - data/undercomplicate/adapter.js, line 91

##### Returns:

Type
  *

#### _buildRequestOptions(options, dependent_data) → {*}

Build an object with options that control the request. This can take into account both explicit options, and prior data.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | Any global options passed in via `getData`. Eg, in locuszoom, every request is passed a copy of `plot.state` as the options object, in which case every adapter would expect certain basic information like `chr, start, end` to be available.
`dependent_data` | Array.<Object> | If the source is called with dependencies, this function will receive one argument with the fully parsed response data from each other source it depends on. Eg, `ld(assoc)` means that the LD adapter would be called with the data from an association request as a function argument. Each dependency is its own argument: there can be 0, 1, 2, ...N arguments.

Overrides:
  - module:undercomplicate.BaseUrlAdapter#_buildRequestOptions
Source:
  - data/undercomplicate/adapter.js, line 32

##### Returns:

An options object containing initial options, plus any calculated values relevant to the request.

Type
  *

#### _findPrefixedKey(a_record, fieldname)

Convenience method, manually called in LZ sources that deal with dependent data.

In the last step of fetching data, LZ adds a prefix to each field name. This means that operations like "build query based on prior data" can't just ask for "log_pvalue" because they are receiving "assoc:log_pvalue" or some such unknown prefix.

This helper lets us use dependent data more easily. Not every adapter needs to use this method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`a_record` | Object | One record (often the first one in a set of records)
`fieldname` | String | The desired fieldname, eg "log_pvalue"

Source:
  - data/adapters.js, line 165

#### _getCacheKey(options) → {string}

Determine how a particular request will be identified in cache. Most LZ requests are region based, so the default is a string concatenation of `chr_start_end`. This adapter is "region aware"- if the user zooms in, it won't trigger a network request because we alread have the data needed.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` |  | Receives plot.state plus any other request options defined by this source

Overrides:
  - module:undercomplicate.BaseUrlAdapter#_getCacheKey
Source:
  - data/adapters.js, line 103

##### Returns:

Type
  string

#### _normalizeResponse(response_text, options) → {*}

Convert the response format into a list of objects, one per datapoint. Eg split lines of a text file, or parse a blob of json.

##### Parameters:

Name | Type | Description
--- | --- | ---
`response_text` | * | The raw response from performRequest, be it text, binary, etc. For most web based APIs, it is assumed to be text, and often JSON.
`options` | Object | Request options. These are not typically used when normalizing a response, but the object is available.

Overrides:
  - module:undercomplicate.BaseUrlAdapter#_normalizeResponse
Source:
  - data/undercomplicate/adapter.js, line 75

##### Returns:

A list of objects, each object representing one row of data `{column_name: value_for_row}`

Type
  *

#### _performRequest(options) → {Promise}

Perform the act of data retrieval (eg from a URL, blob, or JSON entity)

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | object | Request options from `_buildRequestOptions`

Overrides:
  - module:undercomplicate.BaseUrlAdapter#_performRequest
Source:
  - data/undercomplicate/adapter.js, line 63

##### Returns:

Type
  Promise

#### _postProcessResponse(records, options) → {*}

Add the "local namespace" as a prefix for every field returned for this request. Eg if the association api returns a field called variant, and the source is referred to as "assoc" within a particular data layer, then the returned records will have a field called "assoc:variant"

##### Parameters:

Name | Type | Description
--- | --- | ---
`records` |  |
`options` |  |

Overrides:
  - module:undercomplicate.BaseUrlAdapter#_postProcessResponse
Source:
  - data/adapters.js, line 129

##### Returns:

Type
  *

#### getData(options, …dependent_data) → {Promise.<*>}

All adapters must implement this method to asynchronously return data. All other methods are simply internal hooks to customize the actual request for data.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`options` | object |  | Shared options for this request. In LocusZoom, this is typically a copy of `plot.state`.
`dependent_data` | Array.<Array> | <repeatable> | Zero or more recordsets corresponding to each individual adapter that this one depends on. Can be used to build a request that takes into account prior data.

Overrides:
  - module:undercomplicate.BaseUrlAdapter#getData
Source:
  - data/undercomplicate/adapter.js, line 114

##### Returns:

Type
  Promise.<*>