-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: check property existence for excludeFromIndexes with wildcard #788
Changes from all commits
67261f6
a5b30d3
06f9249
de98ad1
cfa33e9
76639d1
96a4c11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -857,6 +857,7 @@ export namespace entity { | |
if ( | ||
firstPathPartIsArray && | ||
// check also if the property in question is actually an array value. | ||
entity.properties![firstPathPart] && | ||
entity.properties![firstPathPart].arrayValue && | ||
// check if wildcard is not applied | ||
!hasWildCard | ||
|
@@ -882,15 +883,17 @@ export namespace entity { | |
} | ||
}); | ||
} else if (firstPathPartIsArray && hasWildCard && remainderPath === '*') { | ||
const array = entity.properties![firstPathPart].arrayValue; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
array.values.forEach((value: any) => { | ||
if (value.entityValue) { | ||
excludePathFromEntity(value.entityValue, '.*'); | ||
} else { | ||
excludePathFromEntity(value, ''); | ||
} | ||
}); | ||
if (entity.properties![firstPathPart]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we just check to see that this property is defined before we move further as that prevents the error from being thrown. Makes sense. There seems to be no value in further traversing a path that the entity will not have any corresponding properties for. |
||
const array = entity.properties![firstPathPart].arrayValue; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
array.values.forEach((value: any) => { | ||
if (value.entityValue) { | ||
excludePathFromEntity(value.entityValue, '.*'); | ||
} else { | ||
excludePathFromEntity(value, ''); | ||
} | ||
}); | ||
} | ||
} else if (firstPathPartIsEntity) { | ||
if (firstPathPart === '') { | ||
Object.keys(entity.properties!).forEach(path => { | ||
|
@@ -901,17 +904,19 @@ export namespace entity { | |
}); | ||
} else { | ||
if (hasWildCard && remainderPath === '*') { | ||
const parentEntity = entity.properties![firstPathPart].entityValue; | ||
|
||
if (parentEntity) { | ||
Object.keys(parentEntity.properties).forEach(path => { | ||
const newPath = parentEntity.properties[path].arrayValue | ||
? path + '[].*' | ||
: path + '.*'; | ||
excludePathFromEntity(parentEntity, newPath); | ||
}); | ||
} else { | ||
excludePathFromEntity(entity, firstPathPart); | ||
if (entity.properties![firstPathPart]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we just check to see that this property is defined before we move further as that prevents the error from being thrown. Makes sense. There seems to be no value in further traversing a path that the entity will not have any corresponding properties for. |
||
const parentEntity = | ||
entity.properties![firstPathPart].entityValue; | ||
if (parentEntity) { | ||
Object.keys(parentEntity.properties).forEach(path => { | ||
const newPath = parentEntity.properties[path].arrayValue | ||
? path + '[].*' | ||
: path + '.*'; | ||
excludePathFromEntity(parentEntity, newPath); | ||
}); | ||
} else { | ||
excludePathFromEntity(entity, firstPathPart); | ||
} | ||
} | ||
} else { | ||
const parentEntity = entity.properties![firstPathPart].entityValue; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1677,6 +1677,8 @@ describe('Datastore', () => { | |
'metadata.otherProperty', | ||
'metadata.obj.*', | ||
'metadata.longStringArray[].*', | ||
'undefinedData.*', | ||
'undefinedArray[].*', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't modify the existing test. We should make a new test that tests for these specific values so we don't lose any existing test coverage. |
||
], | ||
}, | ||
assert.ifError | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no harm in this. If we don't check for this and
entity.properties![firstPathPart]
ever happens to be undefined then this will throw an error and I can't imagine that being desirable.