(filter)
| 58 | |
| 59 | // 要判断一下是否是二维数组的filter |
| 60 | function isSimpleComparison(filter) { |
| 61 | if (!filter || !Array.isArray(filter)) { |
| 62 | return false; |
| 63 | } |
| 64 | const [operator, ...operands] = filter; |
| 65 | |
| 66 | const simpleOps = ['==', '!=', '>', '>=', '<', '<=', 'in', '!in', 'has', '!has']; |
| 67 | const logicalOps = ['all', 'any', 'none']; |
| 68 | if (simpleOps.includes(operator)) { |
| 69 | // has / !has:只要求一个字段名 |
| 70 | if (operator === 'has' || operator === '!has') { |
| 71 | // 排除这种: ['has', ['get', 'name']] |
| 72 | return typeof operands[0] === 'string'; |
| 73 | } |
| 74 | // in / !in:field + 至少一个值 |
| 75 | if (operator === 'in' || operator === '!in') { |
| 76 | if (typeof operands[0] !== 'string') { return false; } |
| 77 | return operands.length > 1; |
| 78 | } |
| 79 | // 普通比较:field + value |
| 80 | return operands.length === 2 && typeof operands[0] === 'string'; |
| 81 | } |
| 82 | if (logicalOps.includes(operator)) { |
| 83 | if (operands.length === 0) { return false; } |
| 84 | return operands.every((item) => isSimpleComparison(item)); |
| 85 | } |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | // 处理类似"O'Reilly"这种字符串,在SQL语句中需要转,单引号需要处理 |
| 90 | function formatValue(value) { |
no outgoing calls
no test coverage detected