Skip to main content
The adapter-commons package provides shared utilities, base classes, and types used by all Feathers database adapters. This is typically used when building custom database adapters.

Installation

AdapterBase

Abstract base class that all database adapters extend from.

Constructor

AdapterServiceOptions
required
Base adapter options
string
default:"id"
Name of the id field property
PaginationParams
Pagination configuration with default and max values
boolean | string[]
Allow multiple updates. true, false, or array of method names
string[]
Custom event names (deprecated, use service registration events option)
FilterSettings
Custom query filters with converter functions
string[]
Additional query operators to allow

Properties

id

The name of the id property.

events

List of custom event names.

options

The full adapter options object.

Methods

getOptions

Get the merged options for a service call, combining base options with params.
ServiceParams
required
Service call parameters
Options
Merged options including params.adapter overrides

allowsMulti

Check if a method allows multiple updates.
string
required
The method name (e.g., ‘create’, ‘patch’, ‘remove’)
ServiceParams
Service call parameters
boolean
Whether multiple updates are allowed for this method

sanitizeQuery

Convert and validate query parameters.
ServiceParams
Service call parameters with query
Query
Sanitized query with converted values

Abstract Methods

These methods must be implemented by the adapter:

Query Filtering

filterQuery

Separate special query parameters from regular query.
Query
required
The incoming query object
FilterQueryOptions
FilterSettings
Custom filter definitions
string[]
Allowed query operators
PaginationParams
Pagination configuration
{ query: Query, filters: object }
Separated query and filters object
Query
Query without special parameters
object
Object with $limit, $skip, $sort, $select, $or, $and

getLimit

Calculate the appropriate limit based on pagination settings.
any
required
The requested limit value
PaginationParams
Pagination configuration
number
The calculated limit (respecting max if set)

OPERATORS

Default query operators allowed by adapters.

FILTERS

Default special query parameter converters.

Sorting

sorter

Create an in-memory sorting function from a $sort object.
{ [key: string]: 1 | -1 }
required
Sort specification object
(a: any, b: any) => number
Comparator function for Array.sort()

compare

Compare two values with proper type handling.
any
required
First value
any
required
Second value
(a, b) => -1 | 0 | 1
Custom string comparison function
-1 | 0 | 1
Comparison result

Selection

select

Create a function that picks only selected fields from results.
Params
required
Service parameters with query.$select
string[]
Additional fields to always include
(data: any) => any
Function that filters data to selected fields

Types

AdapterServiceOptions

Base options interface for all adapters.

AdapterParams

Extended params interface with adapter-specific options.

AdapterQuery

Query interface with standard filter parameters.

PaginationParams

Pagination configuration.

FilterSettings

Custom filter converter functions.

InternalServiceMethods

Interface for hook-less internal methods (prefixed with _).

VALIDATED Symbol

Symbol to mark queries as already validated.

Example: Custom Adapter