@goldwasserexchange/aws-lenses
Version:
Ramda lenses for AWS Lambda events
22 lines (20 loc) • 1.04 kB
JavaScript
import _identity from "ramda/es/identity";
import _toString from "ramda/es/toString";
import _assoc from "ramda/es/assoc";
import _path from "ramda/es/path";
import _lens from "ramda/es/lens";
import _compose from "ramda/es/compose";
import _lensProp from "ramda/es/lensProp";
import { json } from './common';
export const messageId = _lensProp('messageId');
export const body = _lensProp('body');
export const bodyJson = _compose(body, json);
export const messageAttributes = _lensProp('messageAttributes');
const messageAttribute = (type, valueKey, transform) => name => _compose( // eslint-disable-line ramda/compose-pipe-style
messageAttributes, _lens(_path([name, valueKey]), (v, obj) => _assoc(name, {
dataType: type,
[valueKey]: transform(v)
}, obj)));
export const messageAttributeString = messageAttribute('String', 'stringValue', _toString);
export const messageAttributeNumber = messageAttribute('Number', 'stringValue', _toString);
export const messageAttributeBinary = messageAttribute('Binary', 'binaryValue', _identity);