All files adapter.js

86.67% Statements 13/15
83.33% Branches 5/6
100% Functions 4/4
85.71% Lines 12/14
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      4x   1x 13x       13x 13x 12x         1x 1x 1x     1x 3x   3x                
import { del, hget, hset, hdel } from './redisApi';
import createMeta from '../src/meta';
 
const hgetCommand = async ({ client, meta }, key, field) => await hget(client, key, field);
 
const hsetCommand = async ({ client, meta }, key, field, value) => {
    Iif (value === null || value === undefined) {
        await hdel(client, key, field);
        await meta.del(key);
    } else {
        await hset(client, key, field, value);
        if (!await meta.exists(key)) {
            await meta.create(key);
        }
    }
};
 
const delCommand = async ({ client, meta }, key) => {
    await del(client, key);
    await meta.del(key);
};
 
const adapter = async (repository) => {
    repository.meta = await createMeta(repository);
 
    return Object.freeze({
        hget: hgetCommand.bind(null, repository),
        hset: hsetCommand.bind(null, repository),
        del: delCommand.bind(null, repository)
    });
};
 
export default adapter;