All files index.js

100% Statements 9/9
41.67% Branches 5/12
100% Functions 2/2
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39              1x 1x   1x 3x   3x     3x         3x 3x   3x                            
import 'regenerator-runtime/runtime';
import redis from 'redis';
 
import buildProjection from './build_projection';
import init from './init';
import reset from './reset';
 
const DEFAULT_META_NAME = '__ResolveMeta__';
const DEFAULT_LAST_TIMESTAMP_KEY = '__ResolveLastTimestampKey__';
 
const createRedisAdapter = (options, { metaName, lastTimestampKey }, redisClient) => {
    const repository = Object.create(null);
 
    repository.metaName =
        metaName && metaName.constructor === String ? metaName : DEFAULT_META_NAME;
 
    repository.lastTimestampKey =
        lastTimestampKey && lastTimestampKey.constructor === String
            ? lastTimestampKey
            : DEFAULT_LAST_TIMESTAMP_KEY;
 
    repository.connectDatabase = async options =>
        redisClient ? redisClient : redis.createClient(options instanceof Object ? options : {});
 
    return Object.create(null, {
        buildProjection: {
            value: buildProjection.bind(null, repository)
        },
        init: {
            value: init.bind(null, repository)
        },
        reset: {
            value: reset.bind(null, repository)
        }
    });
};
 
export default createRedisAdapter;