All files storeInterface.js

86.67% Statements 13/15
100% Branches 2/2
66.67% Functions 4/6
86.67% Lines 13/15
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 4x 4x     1x 13x 13x     1x 1x 1x     1x 6x 3x             3x                        
import messages from './messages';
 
const hget = async ({ nativeAdapter, connectionPromise }, key, field) => {
    await connectionPromise;
    return await nativeAdapter.hget(key, field);
};
 
const hset = async ({ nativeAdapter, connectionPromise }, key, field, value) => {
    await connectionPromise;
    return await nativeAdapter.hset(key, field, value);
};
 
const del = async ({ nativeAdapter, connectionPromise }, key) => {
    await connectionPromise;
    return await nativeAdapter.del(key);
};
 
const getStoreInterface = (repository, isWriteable) => {
    if (isWriteable) {
        return Object.freeze({
            hget: hget.bind(null, repository),
            hset: hset.bind(null, repository),
            del: del.bind(null, repository)
        });
    }
 
    return Object.freeze({
        hget: hget.bind(null, repository),
        hset: async () => {
            throw new Error(messages.readSideForbiddenOperation('hset'));
        },
        del: async () => {
            throw new Error(messages.readSideForbiddenOperation('del'));
        }
    });
};
 
export default getStoreInterface;