All files build_projection.js

50% Statements 7/14
100% Branches 4/4
66.67% Functions 2/3
50% Lines 7/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    1x 3x 6x 3x 3x     3x                       3x          
import 'regenerator-runtime/runtime';
 
const buildProjection = (repository, inputProjection) => {
    return Object.keys(inputProjection).reduce((projection, eventType) => {
        if (eventType === 'Init' && typeof inputProjection[eventType] === 'function') {
            repository.initHandler = inputProjection[eventType];
            return projection;
        }
 
        projection[eventType] = async (event, onDemandOptions) => {
            await repository.initDonePromise;
            const writeInterface = repository.writeInterface;
            const handler = inputProjection[eventType];
            repository.lastTimestamp = event.timestamp;
 
            try {
                await handler(writeInterface, event);
            } catch (error) {
                repository.internalError = error;
            }
        };
        return projection;
    }, {});
};
 
export default buildProjection;