Home

Awesome

slonik-interceptor-preset

Travis build status NPM version Canonical Code Style Twitter Follow

Slonik interceptor preset.

Motivation

Slonik functionality is extendable using interceptors. Each interceptor is contained in a separate package. Installing and configuring each interceptor becomes a tedious task when using Slonik across multiple projects. slonik-interceptor-preset provides a factory function (createInterceptors) for constructing a collection of selected interceptors.

slonik-interceptor-preset installs these presets:

NameDescription
slonik-interceptor-field-name-transformationTransforms Slonik query result field names.
slonik-interceptor-query-benchmarkingBenchmarks Slonik queries.
slonik-interceptor-query-loggingLogs Slonik queries.
slonik-interceptor-query-normalisationNormalises Slonik queries.

Each interceptor can be selectively enabled/ disabled (see API).

API

import {
  createInterceptors
} from 'slonik-interceptor-preset';

/**
 * @property benchmarkQueries Dictates whether to enable the [query benchmarking interceptor](https://github.com/gajus/slonik-interceptor-query-benchmarking). (Default: false)
 * @property logQueries Dictates whether to enable the [query logging interceptor](https://github.com/gajus/slonik-interceptor-query-logging). (Default: true)
 * @property normaliseQueries Dictates whether to enable the [query normalisation interceptor](https://github.com/gajus/slonik-interceptor-query-normalisation). (Default: true)
 * @property transformFieldNames Dictates whether to enable the [field name transformation interceptor](https://github.com/gajus/slonik-interceptor-field-name-transformation). (Default: true)
 */
type UserConfigurationType = {|
  +benchmarkQueries: boolean,
  +logQueries: boolean,
  +normaliseQueries: boolean,
  +transformFieldNames: boolean
|};

(userConfiguration: UserConfigurationType) => $ReadOnlyArray<InterceptorType>;

Example usage

import {
  createPool
} from 'slonik';
import {
  createInterceptors
} from 'slonik-interceptor-preset';

const connection = createPool('postgres://', {
  interceptors: [
    ...createInterceptors()
  ]
});