objectypes
Version:
A type-safe library to transform and validate objects
16 lines (15 loc) • 743 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyReductionsToObject = void 0;
const reduction_1 = require("../metadata/reduction");
function applyReductionsToObject(targetClass, targetObject, jsonObject, { propertyKey }) {
const reductions = (0, reduction_1.findClassReductionMetadata)(targetClass);
const reductionMetada = reductions === null || reductions === void 0 ? void 0 : reductions.find(metadata => metadata.propertyKey === propertyKey);
if (!reductionMetada) {
return false;
}
const value = reductionMetada.reducer.reduce(jsonObject);
Reflect.set(targetObject, propertyKey, value);
return true;
}
exports.applyReductionsToObject = applyReductionsToObject;