diff --git a/data/converter/raw-foreign-value-to-object-converter.js b/data/converter/raw-foreign-value-to-object-converter.js index 12c43ea69..7c60e0e4e 100644 --- a/data/converter/raw-foreign-value-to-object-converter.js +++ b/data/converter/raw-foreign-value-to-object-converter.js @@ -877,10 +877,14 @@ exports.RawForeignValueToObjectConverter = RawValueToObjectConverter.specialize( //forEach skipps over holes of a sparse array v.forEach(function(value) { /* - Make sure we have a valid data object anf not null nor undefined before trying to get their primary key + Make sure we have a valid data object anf not null nor undefined before trying to get their primary key */ if(value) { result.push(service.dataIdentifierForObject(value).primaryKey); + } else { + //TODO: Is this safe? It was added because, in some cases, you may want to preserve a sparse array. E.g. The + //array has a fixed length, but not all values are defined + result.push(value); } }); currentRule = null; diff --git a/data/service/data-operation.js b/data/service/data-operation.js index d09654f73..6fc8f5345 100644 --- a/data/service/data-operation.js +++ b/data/service/data-operation.js @@ -201,7 +201,7 @@ var Montage = require("../../core/core").Montage, exports.DataOperationType = DataOperationType = new Enum().initWithMembersAndValues(dataOperationTypes,dataOperationTypes); -var dataOperationErrorNames = ["DatabaseMissing", "ObjectDescriptorStoreMissing", "PropertyDescriptorStoreMissing", "InvalidInput", "SyntaxError", "PropertyDescriptorNotFound", "PropertyMappingNotFound", "TransactionDeadlock"]; +var dataOperationErrorNames = ["DatabaseMissing", "ObjectDescriptorStoreMissing", "PropertyDescriptorStoreMissing", "InvalidInput", "SyntaxError", "PropertyDescriptorNotFound", "PropertyMappingNotFound", "TransactionDeadlock", "FunctionMissing"]; exports.DataOperationErrorNames = DataOperationErrorNames = new Enum().initWithMembersAndValues(dataOperationErrorNames,dataOperationErrorNames); // exports.DataOperationError.ObjectDescriptorStoreMissingError = Error.specialize({ diff --git a/data/service/data-service.js b/data/service/data-service.js index 55c3c9170..14b7efcde 100644 --- a/data/service/data-service.js +++ b/data/service/data-service.js @@ -4661,6 +4661,7 @@ DataService.addClassProperties( if (!manyChanges) { manyChanges = {}; + manyChanges.index = changeEvent.index; changesForDataObject.set(key, manyChanges); } @@ -4692,7 +4693,8 @@ DataService.addClassProperties( var registeredRemovedValues = manyChanges.removedValues; if (!registeredRemovedValues) { if (!isDataObjectBeingMapped) { - manyChanges.removedValues = registeredRemovedValues = new Set(removedValues); + manyChanges.removedValues = removedValues; + manyChanges.removedValuesSet = registeredRemovedValues = new Set(removedValues); } self._removeDataObjectPropertyDescriptorValuesForInversePropertyDescriptor( dataObject, @@ -4752,11 +4754,13 @@ DataService.addClassProperties( */ if (Array.isArray(manyChanges) && manyChanges.equals(addedValues)) { manyChanges = {}; + manyChanges.index = changeEvent.index; changesForDataObject.set(key, manyChanges); } if (!isDataObjectBeingMapped) { - manyChanges.addedValues = registeredAddedValues = new Set(addedValues); + manyChanges.addedValues = addedValues; + manyChanges.addedValuesSet = registeredAddedValues = new Set(addedValues); } self._addDataObjectPropertyDescriptorValuesForInversePropertyDescriptor( dataObject, diff --git a/data/service/expression-data-mapping.js b/data/service/expression-data-mapping.js index ec0f29a7d..8ebc6b69a 100644 --- a/data/service/expression-data-mapping.js +++ b/data/service/expression-data-mapping.js @@ -2011,7 +2011,7 @@ exports.ExpressionDataMapping = DataMapping.specialize(/** @lends ExpressionData _mapObjectPropertyToRawDataProperty: { value: function(object, propertyName, data, rawPropertyName, added, removed, _rule, lastReadSnapshot, rawDataSnapshot) { - if((added && added.size > 0) || (removed && removed.size > 0 )) { + if((added && added.length > 0) || (removed && removed.length > 0 )) { var tmpExtendObject, //We derived object so we can pretend the value of the property is alternatively added, then removed, to get the mapping done. //tmpExtendObject = Object.create(object), @@ -2026,7 +2026,7 @@ exports.ExpressionDataMapping = DataMapping.specialize(/** @lends ExpressionData data[rawPropertyName] = aPropertyChanges; - if(added && added.size > 0) { + if(added && added.length > 0) { /* Here we have a situation where in the most common case object[propertyName] is not equal to the content of added, like if there were pre-exising values. @@ -2038,7 +2038,7 @@ exports.ExpressionDataMapping = DataMapping.specialize(/** @lends ExpressionData tmpExtendObject = {}; for(i=0, countI = requirements.length; ( i 0 ) { + if(removed && removed.length > 0 ) { requirements = (requirements || _rule.requirements); // tmpExtendObject[propertyName] = Array.from(result); @@ -2062,7 +2062,7 @@ exports.ExpressionDataMapping = DataMapping.specialize(/** @lends ExpressionData for(i=0, countI = requirements.length; ( i { + let mapping = this.mappingForObject(object), + rawRules = mapping.rawDataMappingRulesForObjectPropertyName(aProperty), + rawDataProperty; + + if(rawRules) { + var iterator = rawRules.values(); + + while((rule = iterator.next().value)) { + rawDataProperty = rule.targetPath; + if (operationData[rawDataProperty]) { + operationData[rawDataProperty].index = aPropertyChanges.index; + } + if (operationData[rawDataProperty] && operationData[rawDataProperty].removedValues) { + operationData[rawDataProperty].removedValues.index = aPropertyChanges.index; + } + } + } + + return output; + }) + } else { + return result; + } + + // return this._mapObjectPropertyToRawData(object, aProperty, operationData, undefined/*context*/, aPropertyChanges.addedValues, aPropertyChanges.removedValues, lastReadSnapshot, rawDataSnapshot); } else { @@ -4958,15 +5005,17 @@ RawDataService.addClassProperties({ self.rootService.registerUniqueObjectWithDataIdentifier(iObject, iDataIdentifier); } self.recordSnapshot(iDataIdentifier, iOperation.data); - + self.removePendingSnapshot(iDataIdentifier); } else if (iOperation.type === UpdateOperation || iOperation.type === NoOpOperation) { iDataIdentifier = self.dataIdentifierForObject(iObject); self.recordSnapshot(iDataIdentifier, iOperation.data, true); + self.removePendingSnapshot(iDataIdentifier); } else if (iOperation.type === DeleteOperation) { iDataIdentifier = self.dataIdentifierForObject(iObject); //Removes the snapshot we have for iDataIdentifier self.removeSnapshot(iDataIdentifier); + self.removePendingSnapshot(iDataIdentifier); } }