# Class: BaseAdapter

## undercomplicate.BaseAdapter()

#### new BaseAdapter()

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`config.cache_enabled` | boolean | <optional> | true | Whether to enable the LRU cache, and store a copy of the normalized and parsed response data. Turned on by default for most remote requests; turn off if you are using another datastore (like Vuex) or if the response body uses too much memory.
`config.cache_size` | number | <optional> | 3 | How many requests to cache. Track-dependent annotations like LD might benefit from caching more items, while very large payloads (like, um, TOPMED LD) might benefit from a smaller cache size. For most LocusZoom usages, the cache is "region aware": zooming in will use cached data, not a separate request

Source:
  - data/undercomplicate/adapter.js, line 13

### 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 |

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.

Source:
  - data/undercomplicate/adapter.js, line 32

##### Returns:

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

Type
  *

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

Determine how this request is uniquely identified in cache. Usually this is an exact match for the same key, but it doesn't have to be. The LRU cache implements a `find` method, which means that a cache item can optionally be identified by its node `metadata` (instead of exact key match). This is useful for situations where the user zooms in to a smaller region and wants the original request to count as a cache hit. See subclasses for example.

##### Parameters:

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

Source:
  - data/undercomplicate/adapter.js, line 49

##### Returns:

This is often a string concatenating unique values for a compound cache key, like `chr_start_end`. If null, it is treated as a cache miss.

Type
  *

#### _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.

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`

Source:
  - data/undercomplicate/adapter.js, line 63

##### Returns:

Type
  Promise

#### _postProcessResponse(records, options)

A hook to transform the response after all operations are done. For example, this can be used to prefix fields with a namespace unique to the request, like `log_pvalue` -> `assoc:log_pvalue`. (by applying namespace prefixes to field names last, annotations and validation can happen on the actual API payload, without having to guess what the fields were renamed to).

##### Parameters:

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

Source:
  - data/undercomplicate/adapter.js, line 103

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

Source:
  - data/undercomplicate/adapter.js, line 114

##### Returns:

Type
  Promise.<*>