apollo-client-code-first-request
Version:
34 lines • 1.66 kB
JavaScript
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
exports.__esModule = true;
exports.parseObjectByScalar = void 0;
var metadata_util_1 = require("./metadata.util");
function parseObjectByScalar(classRef, object) {
var propertyNames = metadata_util_1.Metadata.getPropertyNames(classRef.prototype);
if (!propertyNames.length)
return object;
var parsedObject = new classRef();
propertyNames.forEach(function (propertyName) {
var _a = metadata_util_1.Metadata.getFieldInfo(classRef.prototype, propertyName), type = _a.type, isArray = _a.isArray, scalar = _a.scalar;
var propertyValue = object === null || object === void 0 ? void 0 : object[propertyName];
var propertyValues = isArray ? __spreadArray([], (propertyValue || []), true) : propertyValue ? [propertyValue] : [];
propertyValues.forEach(function (value, index) {
propertyValues[index] = parseObjectByScalar(type, value);
if (value && scalar) {
propertyValues[index] = new scalar().parseValue(propertyValues[index]);
}
});
parsedObject[propertyName] = isArray ? propertyValues : propertyValues[0];
});
return parsedObject;
}
exports.parseObjectByScalar = parseObjectByScalar;
//# sourceMappingURL=parse-object-by-scalar.util.js.map
;