strapi/packages/core/utils/lib/operators.js
Nathan Pichon b4ac2f90d8
feat(review-workflows): remove deleted content-types in assigned workflows (#17053)
* feat(review-workflows): migrate old to new stage attribute name

* feat(reviewWorkflows): remove ct from workflows when deleted

* fix(operators): re-add $jsonSupersetOf to available operators
2023-06-23 17:18:32 +02:00

76 lines
1.3 KiB
JavaScript

'use strict';
const GROUP_OPERATORS = ['$and', '$or'];
const WHERE_OPERATORS = [
'$not',
'$in',
'$notIn',
'$eq',
'$eqi',
'$ne',
'$gt',
'$gte',
'$lt',
'$lte',
'$null',
'$notNull',
'$between',
'$startsWith',
'$endsWith',
'$startsWithi',
'$endsWithi',
'$contains',
'$notContains',
'$containsi',
'$notContainsi',
'$jsonSupersetOf',
];
const CAST_OPERATORS = [
'$not',
'$in',
'$notIn',
'$eq',
'$ne',
'$gt',
'$gte',
'$lt',
'$lte',
'$between',
];
const ARRAY_OPERATORS = ['$in', '$notIn', '$between'];
const OPERATORS = {
where: WHERE_OPERATORS,
cast: CAST_OPERATORS,
group: GROUP_OPERATORS,
array: ARRAY_OPERATORS,
};
// for performance, cache all operators in lowercase
const OPERATORS_LOWERCASE = Object.fromEntries(
Object.entries(OPERATORS).map(([key, values]) => [
key,
values.map((value) => value.toLowerCase()),
])
);
const isOperatorOfType = (type, key, ignoreCase = false) => {
if (ignoreCase) {
return OPERATORS_LOWERCASE[type]?.includes(key.toLowerCase()) ?? false;
}
return OPERATORS[type]?.includes(key) ?? false;
};
const isOperator = (key, ignoreCase = false) => {
return Object.keys(OPERATORS).some((type) => isOperatorOfType(type, key, ignoreCase));
};
module.exports = {
isOperator,
isOperatorOfType,
OPERATORS,
};