From ea8908b0a32095099e0e7666d7d97dd669b1f39a Mon Sep 17 00:00:00 2001 From: tejaede Date: Tue, 25 Nov 2025 22:08:31 -0600 Subject: [PATCH 1/2] Move --- .../raw-hierarchy-to-object-converter.js | 239 ++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 data/converter/raw-hierarchy-to-object-converter.js diff --git a/data/converter/raw-hierarchy-to-object-converter.js b/data/converter/raw-hierarchy-to-object-converter.js new file mode 100644 index 000000000..7aa9e9792 --- /dev/null +++ b/data/converter/raw-hierarchy-to-object-converter.js @@ -0,0 +1,239 @@ +var RawValueToObjectConverter = require("./raw-value-to-object-converter").RawValueToObjectConverter, + Promise = require("../../core/promise").Promise, + assign = require("core/frb/assign"); +; +/** + * @class RawHierarchyToObjectConverter + * @classdesc Converts a property value of raw data to the referenced object. + * @extends RawValueToObjectConverter + */ +exports.RawHierarchyToObjectConverter = RawValueToObjectConverter.specialize( /** @lends RawEmbeddedValueToObjectConverter# */ { + + /********************************************************************* + * Serialization + */ + + serializeSelf: { + value: function (serializer) { + + this.super(serializer); + + serializer.setProperty("hierarchyExpressions", this.hierarchyExpressions); + } + }, + + deserializeSelf: { + value: function (deserializer) { + + this.super(deserializer); + + value = deserializer.getProperty("hierarchyExpressions"); + if (value) { + this.hierarchyExpressions = value; + } + } + }, + + /********************************************************************* + * Properties + */ + + /********************************************************************* + * Public API + */ + + /** + * This is a unique clientId (per tab), that's given by the backend to the + * client's OperationService. This clientId needs then to be passed per + * operation to allow the server side to leverage it + * + * @type {Array} + */ + + hierarchyExpressions: { + value: undefined + }, + + + /** + * Converts an array of raw data that are the raw data of ancestors of an object. + * Returns the value converted to object of the first, which is the "parent" of the object being mapped, + * and loop on the rest of the array to create those objects and assign them as "parent" of the previous + * one using the expression at the corresponding index in the "hierarchyExpressions" property + * @param {Property} v The value to format. + * @returns {Promise} A promise for the referenced object. The promise is + * fulfilled after the object is successfully fetched. + */ + convert: { + value: function (v) { + var self = this, + convertedValue, + result; + + /* + besides returning a default value, or a shared "Missing value" singleton, a feature we don't have, there's not much we can do here: + */ + if(v === null) { + return Promise.resolveNull; + } else if( v === undefined) { + return Promise.resolveUndefined; + } else return Promise.all([this._descriptorToFetch, this.service]).then(function (values) { + var typeToFetch = values[0], + returnedValue, + service = values[1]; + + if(Array.isArray(v)) { + if(v.length) { + let hierarchyExpressions = self.hierarchyExpressions; + for(var i=0, countI=v.length, promises, iExpression, previousResult;(i { + let previousDataObject = allResults[0], + dataObject = allResults[1]; + + if(previousDataObject) { + /* Stitch hierarchy as instructed */ + assign(previousDataObject, hierarchyExpression, dataObject); + } + + return dataObject; + }); + } + else { + result = Promise.resolve(); + } + return result; + } + }, + + /** + * Reverts the relationship back to raw data. + * @function + * @param {Scope} v The value to revert. + * @returns {string} v + */ + revert: { + value: function (v) { + + throw "RawHierarchyToObjectConverter revert() is not implemented" + + var self = this; + + if(!v) { + return v; + } else { + return Promise.all([this._descriptorToFetch, this.service]).then(function (values) { + var revertedValue, + result, + revertedValuePromise; + + + var objectDescriptor = values[0], + service = values[1]; + + if(Array.isArray(v)) { + if(v.length) { + revertedValue = []; + for(var i=0, countI=v.length, promises;(i Date: Wed, 26 Nov 2025 09:07:53 -0600 Subject: [PATCH 2/2] Add raw-hierarchy-to-object-converter and spec --- .../raw-hierarchy-to-object-converter.js | 52 +++++++++++-------- .../raw-hierarchy-to-object-converter-spec.js | 45 ++++++++++++++++ 2 files changed, 75 insertions(+), 22 deletions(-) create mode 100644 test/spec/data/raw-hierarchy-to-object-converter-spec.js diff --git a/data/converter/raw-hierarchy-to-object-converter.js b/data/converter/raw-hierarchy-to-object-converter.js index 7aa9e9792..76a9ac497 100644 --- a/data/converter/raw-hierarchy-to-object-converter.js +++ b/data/converter/raw-hierarchy-to-object-converter.js @@ -9,38 +9,46 @@ var RawValueToObjectConverter = require("./raw-value-to-object-converter").RawVa */ exports.RawHierarchyToObjectConverter = RawValueToObjectConverter.specialize( /** @lends RawEmbeddedValueToObjectConverter# */ { - /********************************************************************* + /********************************************************************* * Serialization */ - serializeSelf: { - value: function (serializer) { - - this.super(serializer); - - serializer.setProperty("hierarchyExpressions", this.hierarchyExpressions); - } - }, + serializeSelf: { + value: function (serializer) { + + this.super(serializer); - deserializeSelf: { - value: function (deserializer) { + serializer.setProperty("hierarchyExpression", this.hierarchyExpression); + } + }, + + deserializeSelf: { + value: function (deserializer) { + + this.super(deserializer); - this.super(deserializer); - - value = deserializer.getProperty("hierarchyExpressions"); - if (value) { - this.hierarchyExpressions = value; - } + value = deserializer.getProperty("hierarchyExpression"); + if (value) { + this.hierarchyExpression = value; } - }, + } + }, /********************************************************************* * Properties */ + /********************************************************************* * Public API */ + + initWithHierarchyExpression: { + value: function (expression) { + this.hierarchyExpression = expression; + return this; + } + }, /** * This is a unique clientId (per tab), that's given by the backend to the @@ -50,7 +58,7 @@ exports.RawHierarchyToObjectConverter = RawValueToObjectConverter.specialize( /* * @type {Array} */ - hierarchyExpressions: { + hierarchyExpression: { value: undefined }, @@ -59,7 +67,7 @@ exports.RawHierarchyToObjectConverter = RawValueToObjectConverter.specialize( /* * Converts an array of raw data that are the raw data of ancestors of an object. * Returns the value converted to object of the first, which is the "parent" of the object being mapped, * and loop on the rest of the array to create those objects and assign them as "parent" of the previous - * one using the expression at the corresponding index in the "hierarchyExpressions" property + * one using the expression at the corresponding index in the "hierarchyExpression" property * @param {Property} v The value to format. * @returns {Promise} A promise for the referenced object. The promise is * fulfilled after the object is successfully fetched. @@ -84,9 +92,9 @@ exports.RawHierarchyToObjectConverter = RawValueToObjectConverter.specialize( /* if(Array.isArray(v)) { if(v.length) { - let hierarchyExpressions = self.hierarchyExpressions; + let hierarchyExpression = self.hierarchyExpression; for(var i=0, countI=v.length, promises, iExpression, previousResult;(i { + rawData = { + name: "John Doe", + child: { + name: "Jane Doe", + child: { + name: "Jean Doe", + child: { + name: "Joan Doe" + } + } + } + }; + objectDescriptor = new ObjectDescriptor().initWithName("Person"); + propertyDescriptor = new PropertyDescriptor().initWithNameObjectDescriptorAndCardinality("name", objectDescriptor, 1); + objectDescriptor.addPropertyDescriptor(propertyDescriptor); + + propertyDescriptor = new PropertyDescriptor().initWithNameObjectDescriptorAndCardinality("child", objectDescriptor, 1); + objectDescriptor.addPropertyDescriptor(propertyDescriptor); + }) + + it("can be created", function () { + expect(new RawHierarchyToObjectConverter()).toBeDefined(); + }); + + + it("can map a hierarchy", function () { + var converter = new RawHierarchyToObjectConverter().initWithHierarchyExpression("child"); + + //TODO + }); + + it("can deserializeSelf", function () { + //TODO + }); +});