UNPKG

breeze2-odata4

Version:

Library to allow OData 4 support for breezejs 2

37 lines 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var breeze_client_1 = require("breeze-client"); var utilities_1 = require("../utilities"); var CustomDecorator = (function () { function CustomDecorator() { this.annotation = 'Custom'; } CustomDecorator.prototype.decorate = function (expression, annotation) { var keys = Object.keys(annotation); breeze_client_1.core.arrayRemoveItem(keys, 'term', false); var valueKey = keys[0]; var value = annotation[valueKey]; var termParts = annotation.term.split('.'); var startIndex = termParts.indexOf(this.annotation); var customPath = termParts.slice(startIndex + 1); if (!customPath.length) { return; } var dataType = utilities_1.getDataType(valueKey); var customValue = dataType.parse(value, 'string'); expression.custom = expression.custom instanceof Object ? expression.custom : {}; customPath.reduce(function (prev, curr, index, arr) { if (index < arr.length - 1) { prev[curr] = prev[curr] instanceof Object ? prev[curr] : {}; return prev[curr]; } else { prev[curr] = customValue; return prev; } }, expression.custom); }; return CustomDecorator; }()); exports.CustomDecorator = CustomDecorator; //# sourceMappingURL=custom-decorator.js.map