-
Notifications
You must be signed in to change notification settings - Fork 28
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
support open-ended datetime intervals, fix camelcase violations #180
Conversation
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.
LGTM other than the failing test that is still using the old snake case function create_indices
@@ -43,20 +43,28 @@ function buildDatetimeQuery(parameters) { | |||
let dateQuery | |||
const { datetime } = parameters | |||
if (datetime) { | |||
const dataRange = datetime.split('/') | |||
if (dataRange.length === 2) { | |||
if (!datetime.includes('/')) { |
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.
Rather than negating this and then having an else clause, it would be a bit easier to read if it said if (datetime.includes('/')) {
and then the conditional orders were swapped.
src/lib/esClient.js
Outdated
const client = await esClient() | ||
const exists = await client.indices.exists({ index }) | ||
const mapping = (index === 'collections' ? collections_mapping : items_mapping) | ||
const mapping = (index === 'collections' ? collectionsMapping : itemsMapping) |
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.
const mapping = (index === 'collections' ? collectionsMapping : itemsMapping) | |
const mapping = index === 'collections' ? collectionsMapping : itemsMapping |
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.
Looks like this change was already made?
@@ -43,20 +43,28 @@ function buildDatetimeQuery(parameters) { | |||
let dateQuery | |||
const { datetime } = parameters | |||
if (datetime) { | |||
const dataRange = datetime.split('/') | |||
if (dataRange.length === 2) { | |||
if (!datetime.includes('/')) { |
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.
It's more verbose, but consider breaking this function apart into something like this. I think it makes it easier to understand what's going on.
/**
* @param {string} datetime
* @returns {unknown}
*/
const buildDatetimeRange = (datetime) => {
const [start, end, ...rest] = datetime.split('/')
if (rest.length > 0) {
return new Error('datetime value is invalid, contains more than one forward slash')
}
if (!start && !end) {
return new Error(
'datetime value is invalid, at least one end of the interval must be closed'
)
}
if (start === '..' && end === '..') {
return new Error(
'datetime value is invalid, at least one end of the interval must be closed'
)
}
let range
if (start && end) range = { gte: start, lte: end }
else if (start) range = { gte: start }
else range = { lte: end }
return {
range: {
'properties.datetime': range
}
}
}
/**
* @param {string} datetime
* @returns {unknown}
*/
const buildDatetimeTerm = (datetime) => ({
term: {
'properties.datetime': datetime
}
})
/**
* @param {string} datetime
* @returns {boolean}
*/
const isExactDatetime = (datetime) => !datetime.includes('/')
/**
* @param {Object} params
* @param {string} params.datetime
* @returns {unknown|Error|undefined}
*/
const buildDatetimeQuery = ({ datetime }) => {
if (!datetime) return undefined
return isExactDatetime(datetime)
? buildDatetimeTerm(datetime)
: buildDatetimeRange(datetime)
}
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 chose not to do too much work on this right now because we need to significantly improve the datetime validation #175
Co-authored-by: Marc <[email protected]>
Closes #137 |
Co-authored-by: Marc <[email protected]> Co-authored-by: Marc Huffnagle <[email protected]>
Related Issue(s): #137
Proposed Changes:
PR Checklist: