Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions packages/datastore/src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,14 @@ function entityToEntityProto(entityObject) {
var hasEntityPath = entityIndex > -1;

if (!hasArrayPath && !hasEntityPath) {
if (entity.properties[path]) {
// This is the property to exclude!
entity.properties[path].excludeFromIndexes = true;
if (entity.properties) {
if (entity.properties[path]) {
// This is the property to exclude!
entity.properties[path].excludeFromIndexes = true;
}
} else if (!path) {
// This is a primitive that should be excluded.
entity.excludeFromIndexes = true;
}
return;
}
Expand All @@ -482,15 +487,19 @@ function entityToEntityProto(entityObject) {
var firstPathPart = splitPath.shift();
var remainderPath = splitPath.join(delimiter).replace(/^(\.|[])/, '');

if (!entity.properties[firstPathPart]) {
if (!(entity.properties && entity.properties[firstPathPart])) {
// Either a primitive or an entity for which this path doesn't apply.
return;
}

if (firstPathPartIsArray) {
var array = entity.properties[firstPathPart].arrayValue;

array.values.forEach(function(arrayValue) {
excludePathFromEntity(arrayValue.entityValue, remainderPath);
var memberEntity = arrayValue.entityValue || arrayValue;
excludePathFromEntity(memberEntity, remainderPath);
});

} else if (firstPathPartIsEntity) {
var parentEntity = entity.properties[firstPathPart].entityValue;
excludePathFromEntity(parentEntity, remainderPath);
Expand Down
4 changes: 4 additions & 0 deletions packages/datastore/system-test/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ describe('Datastore', function() {
var data = {
longString: longString,
notMetadata: true,
longStringArray: [
longString,
],
metadata: {
longString: longString,
otherProperty: 'value',
Expand Down Expand Up @@ -130,6 +133,7 @@ describe('Datastore', function() {
data: data,
excludeFromIndexes: [
'longString',
'longStringArray[]',
'metadata.obj.longString',
'metadata.obj.longStringArray[].longString',
'metadata.obj.longStringArray[].nestedLongStringArray[].longString',
Expand Down
62 changes: 61 additions & 1 deletion packages/datastore/test/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,13 @@ describe('entity', function() {
excludeFromIndexes: [
'name',
'entity.name',
'array[]',
'array[].name',
'array[].entity.name',
'array[].entity.array[].name',
'array[].array[].entity.name'
'array[].array[].entity.name',
'entityExcluded[].name',
'primitiveExcluded[]'
],

data: {
Expand All @@ -601,7 +604,22 @@ describe('entity', function() {
name: value
},

entityExcluded: [
value,
{
name: value
}
],

primitiveExcluded: [
value,
{
name: value
}
],

array: [
value,
{
name: value
},
Expand Down Expand Up @@ -645,9 +663,51 @@ describe('entity', function() {
}
}
},
entityExcluded: {
arrayValue: {
values: [
{
stringValue: value
},
{
entityValue: {
properties: {
name: {
stringValue: value,
excludeFromIndexes: true
}
}
}
}
]
}
},
primitiveExcluded: {
arrayValue: {
values: [
{
stringValue: value,
excludeFromIndexes: true
},
{
entityValue: {
properties: {
name: {
stringValue: value
}
}
}
}
]
}
},
array: {
arrayValue: {
values: [
{
stringValue: value,
excludeFromIndexes: true
},
{
entityValue: {
properties: {
Expand Down