Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
table: TableName,
query: LokiRawQuery,
originalConditions: Where[], // Needed for column comparisons
mapKey: ColumnName,
joinKey: ColumnName,
}>
export type LokiQuery = $Exact<{
table: TableName,
query: LokiRawQuery,
joins: LokiJoin[],
}>
const getComparisonRight: ComparisonRight => CompoundValue = (cond([
[has('value'), prop('value')],
[has('values'), prop('values')],
[has('column'), () => invariant(false, 'Column comparisons unimplemented!')], // TODO: !!
]): any)
// TODO: It's probably possible to improve performance of those operators by making them
// binary-search compatible (i.e. don't use $and, $not)
// TODO: We might be able to use $jgt, $jbetween, etc. — but ensure the semantics are right
// and it won't break indexing
type OperatorFunction = CompoundValue => LokiRawQuery
const weakNotEqual: OperatorFunction = value => ({ $not: { $aeq: value } })
const noNullComparisons: OperatorFunction => OperatorFunction = operator => value => ({
$and: [operator(value), weakNotEqual(null)],
})
export type LokiJoin = $Exact<{
table: TableName,
query: LokiRawQuery,
originalConditions: Where[], // Needed for column comparisons
mapKey: ColumnName,
joinKey: ColumnName,
}>
export type LokiQuery = $Exact<{
table: TableName,
query: LokiRawQuery,
joins: LokiJoin[],
}>
const getComparisonRight: ComparisonRight => CompoundValue = (cond([
[has('value'), prop('value')],
[has('values'), prop('values')],
[has('column'), () => invariant(false, 'Column comparisons unimplemented!')], // TODO: !!
]): any)
// TODO: It's probably possible to improve performance of those operators by making them
// binary-search compatible (i.e. don't use $and, $not)
// TODO: We might be able to use $jgt, $jbetween, etc. — but ensure the semantics are right
// and it won't break indexing
type OperatorFunction = CompoundValue => LokiRawQuery
const weakNotEqual: OperatorFunction = value => ({ $not: { $aeq: value } })
const noNullComparisons: OperatorFunction => OperatorFunction = operator => value => ({
$and: [operator(value), weakNotEqual(null)],
})
export function queryWithoutDeleted(query: QueryDescription): QueryDescription {
const { join, where: whereConditions } = query
return {
join: [...join, ...joinsWithoutDeleted(join)],
where: [...whereConditions, whereNotDeleted],
}
}
const isNotObject = complement(isObject)
const searchForColumnComparisons: any => boolean = cond([
[is(Array), any(value => searchForColumnComparisons(value))], // dig deeper into arrays
[isNotObject, F], // bail if primitive value
[has('column'), T], // bingo!
[
T,
pipe(
// dig deeper into objects
getValues,
any(value => searchForColumnComparisons(value)),
),
],
])
export function hasColumnComparisons(conditions: Where[]): boolean {
return searchForColumnComparisons(conditions)
}
query: LokiRawQuery,
originalConditions: Where[], // Needed for column comparisons
mapKey: ColumnName,
joinKey: ColumnName,
}>
export type LokiQuery = $Exact<{
table: TableName,
query: LokiRawQuery,
joins: LokiJoin[],
}>
const getComparisonRight: ComparisonRight => CompoundValue = (cond([
[has('value'), prop('value')],
[has('values'), prop('values')],
[has('column'), () => invariant(false, 'Column comparisons unimplemented!')], // TODO: !!
]): any)
// TODO: It's probably possible to improve performance of those operators by making them
// binary-search compatible (i.e. don't use $and, $not)
// TODO: We might be able to use $jgt, $jbetween, etc. — but ensure the semantics are right
// and it won't break indexing
type OperatorFunction = CompoundValue => LokiRawQuery
const weakNotEqual: OperatorFunction = value => ({ $not: { $aeq: value } })
const noNullComparisons: OperatorFunction => OperatorFunction = operator => value => ({
$and: [operator(value), weakNotEqual(null)],
})
const like: OperatorFunction = value => {
const encodeWhereDescription: (WhereDescription | On) => LokiRawQuery = ({ left, comparison }) =>
// HACK: If this is a column comparison condition, ignore it (assume it evaluates to true)
// The column comparison will actually be performed during the refining pass with a matcher func
has('column', comparison.right)
? hackAlwaysTrueCondition
: objOf(left, encodeComparison(comparison))
) => $FlowFixMe = element =>
cond([
[has('value'), prop('value')],
[has('values'), prop('values')],
[has('column'), arg => element._raw[arg.column]],
])
) => $FlowFixMe = element =>
cond([
[has('value'), prop('value')],
[has('values'), prop('values')],
[has('column'), arg => element._raw[arg.column]],
])
) => $FlowFixMe = element =>
cond([
[has('value'), prop('value')],
[has('values'), prop('values')],
[has('column'), arg => element._raw[arg.column]],
])