"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
function numberFromDb(attributeValue) {
    if (attributeValue.N) {
        const numberValue = Number.parseFloat(attributeValue.N);
        if (isNaN(numberValue)) {
            throw new Error(`value ${attributeValue.N} resolves to NaN when parsing using Number.parseFloat`);
        }
        return numberValue;
    }
    else {
        throw new Error('there is no N(umber) value defiend on given attribute value');
    }
}
function numberToDb(modelValue) {
    if (!lodash_1.isNumber(modelValue)) {
        throw new Error('this mapper only support values of type number');
    }
    if (isNaN(modelValue)) {
        return null;
    }
    return { N: modelValue.toString() };
}
exports.NumberMapper = {
    fromDb: numberFromDb,
    toDb: numberToDb,
};
//# sourceMappingURL=number.mapper.js.map