Skip to content

Commit

Permalink
fix: object mappings nested filters
Browse files Browse the repository at this point in the history
  • Loading branch information
koladilip committed Jun 15, 2024
1 parent 3eafe0b commit c7126ae
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions src/utils/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,28 +146,40 @@ function handleNextPart(
flatMapping: FlatMappingAST,
partNum: number,
currentOutputPropAST: ObjectPropExpression,
): Expression | undefined {
const nextOutputPart = flatMapping.outputExpr.parts[partNum];
if (nextOutputPart.filter?.type === SyntaxType.ALL_FILTER_EXPR) {
return processAllFilter(flatMapping.inputExpr, currentOutputPropAST);
}
if (nextOutputPart.filter?.type === SyntaxType.ARRAY_INDEX_FILTER_EXPR) {
return processArrayIndexFilter(
currentOutputPropAST,
nextOutputPart.filter as IndexFilterExpression,
);
}
if (isWildcardSelector(nextOutputPart)) {
return processWildCardSelector(
flatMapping,
currentOutputPropAST,
partNum === flatMapping.outputExpr.parts.length - 1,
);
}
}

function handleNextParts(
flatMapping: FlatMappingAST,
partNum: number,
currentOutputPropAST: ObjectPropExpression,
): Expression {
let objectExpr = currentOutputPropAST.value;
let newPartNum = partNum;
while (newPartNum < flatMapping.outputExpr.parts.length) {
const nextOutputPart = flatMapping.outputExpr.parts[newPartNum];
if (nextOutputPart.filter?.type === SyntaxType.ALL_FILTER_EXPR) {
objectExpr = processAllFilter(flatMapping.inputExpr, currentOutputPropAST);
} else if (nextOutputPart.filter?.type === SyntaxType.ARRAY_INDEX_FILTER_EXPR) {
objectExpr = processArrayIndexFilter(
currentOutputPropAST,
nextOutputPart.filter as IndexFilterExpression,
);
} else if (isWildcardSelector(nextOutputPart)) {
objectExpr = processWildCardSelector(
flatMapping,
currentOutputPropAST,
newPartNum === flatMapping.outputExpr.parts.length - 1,
);
} else {
const nextObjectExpr = handleNextPart(flatMapping, newPartNum, currentOutputPropAST);
if (!nextObjectExpr) {
break;
}
newPartNum++;
objectExpr = nextObjectExpr;
}
return objectExpr;
}
Expand Down Expand Up @@ -198,7 +210,7 @@ function processFlatMappingPart(
}

const currentOutputPropAST = findOrCreateObjectPropExpression(currentOutputPropsAST, key);
const objectExpr = handleNextPart(flatMapping, partNum + 1, currentOutputPropAST);
const objectExpr = handleNextParts(flatMapping, partNum + 1, currentOutputPropAST);
if (
objectExpr.type !== SyntaxType.OBJECT_EXPR ||
!objectExpr.props ||
Expand Down

0 comments on commit c7126ae

Please sign in to comment.