refactor: nested $json/$select syntax, migrate stored queries

This commit is contained in:
M1
2026-03-16 13:14:22 +04:00
parent ab2cbaa5cc
commit fe7a0bf19b
3 changed files with 46 additions and 55 deletions
+14 -10
View File
@@ -48,10 +48,10 @@ class QueryBuilder {
return { [field]: { [operator]: parsedVal } };
}
if (field === '$select') {
return { '$select': rule.selectorValue || '', [operator]: parsedVal };
return { '$select': { [rule.selectorValue || '*']: { [operator]: parsedVal } } };
}
if (field === '$json') {
return { '$json': rule.jsonPath || '', [operator]: parsedVal };
return { '$json': { [rule.jsonPath || '$']: { [operator]: parsedVal } } };
}
if (field === 'headers.*') {
const headerField = `headers.${rule.headerName || 'content-type'}`;
@@ -117,19 +117,23 @@ class QueryBuilder {
}
if ('$select' in clause) {
const selectorValue = clause.$select;
for (const [op, val] of Object.entries(clause)) {
if (op !== '$select') {
return { field: '$select', operator: op, value: String(val), headerName: '', selectorValue, jsonPath: '' };
const selMap = clause.$select;
if (selMap && typeof selMap === 'object') {
const [selectorValue, condition] = Object.entries(selMap)[0] || ['*', {}];
if (condition && typeof condition === 'object') {
const [operator, value] = Object.entries(condition)[0] || ['$eq', ''];
return { field: '$select', operator, value: String(value), headerName: '', selectorValue, jsonPath: '' };
}
}
}
if ('$json' in clause) {
const jsonPath = clause.$json;
for (const [op, val] of Object.entries(clause)) {
if (op !== '$json') {
return { field: '$json', operator: op, value: String(val), headerName: '', selectorValue: '', jsonPath };
const pathMap = clause.$json;
if (pathMap && typeof pathMap === 'object') {
const [jsonPath, condition] = Object.entries(pathMap)[0] || ['$', {}];
if (condition && typeof condition === 'object') {
const [operator, value] = Object.entries(condition)[0] || ['$eq', ''];
return { field: '$json', operator, value: String(value), headerName: '', selectorValue: '', jsonPath };
}
}
}