slonik-interceptor-preset
Version:
Slonik interceptor preset.
54 lines (41 loc) • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _slonikInterceptorFieldNameTransformation = require("slonik-interceptor-field-name-transformation");
var _slonikInterceptorQueryNormalisation = require("slonik-interceptor-query-normalisation");
var _slonikInterceptorQueryBenchmarking = require("slonik-interceptor-query-benchmarking");
var _slonikInterceptorQueryLogging = require("slonik-interceptor-query-logging");
const defaultConfiguration = {
benchmarkQueries: false,
logQueries: true,
normaliseQueries: true,
transformFieldNames: true
};
const createInterceptors = (userConfiguration = defaultConfiguration) => {
const configuration = { ...defaultConfiguration,
...userConfiguration
};
const interceptors = [];
if (configuration.transformFieldNames) {
interceptors.push((0, _slonikInterceptorFieldNameTransformation.createFieldNameTransformationInterceptor)({
format: 'CAMEL_CASE'
}));
}
if (configuration.normaliseQueries) {
interceptors.push((0, _slonikInterceptorQueryNormalisation.createQueryNormalisationInterceptor)({
stripComments: true
}));
}
if (configuration.benchmarkQueries) {
interceptors.push((0, _slonikInterceptorQueryBenchmarking.createQueryBenchmarkingInterceptor)());
}
if (configuration.logQueries) {
interceptors.push((0, _slonikInterceptorQueryLogging.createQueryLoggingInterceptor)());
}
return interceptors;
};
var _default = createInterceptors;
exports.default = _default;
//# sourceMappingURL=createInterceptors.js.map