feat: Add Jmespath expression function in frontend#19028
Conversation
📝 WalkthroughWalkthroughThis PR adds JMESPath expression function support to the expression evaluator system. It introduces a base evaluator class for standardised error handling, implements a JMESPath-specific evaluator, defines the schema contract, integrates the new function into the expression registry, refactors an existing evaluator to use the new base class, and includes comprehensive test fixtures. ChangesJMESPath Expression Function Implementation
Sequence DiagramsequenceDiagram
participant ExprFunction as Expression Function
participant Evaluator as JmespathFunctionEvaluator
participant JMESPath as jmespath.search()
participant Validation as assertValidValue
ExprFunction->>Evaluator: new(context, [data, query])
Evaluator->>JMESPath: search(data, query)
JMESPath-->>Evaluator: result
Evaluator->>Validation: assertValidValue(result)
Validation-->>Evaluator: validated
Evaluator-->>ExprFunction: return ValidValue
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
6d67237 to
0eaa66e
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/App/frontend/schemas/json/layout/expression.schema.v1.json`:
- Around line 53-54: The func-jmespath JSON schema currently allows extra array
items and doesn't reflect the function's Any return type; update the
func-jmespath definition so the parameters array uses fixed arity by adding
"additionalItems": false and ensure the function's return schema references the
ExprVal.Any equivalent (i.e., include the same union that represents Any/strict
scalar union used elsewhere) so the schema matches the runtime in
src/App/frontend/src/features/expressions/expression-functions.ts (jmespath) and
the expectations in schema.test.ts; specifically modify the "func-jmespath"
definition to enforce no extra args and to include the Any scalar union in its
return type/allowed scalars.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 62626568-a49a-499d-b837-5bd8f4c0d857
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (9)
src/App/frontend/package.jsonsrc/App/frontend/schemas/json/layout/expression.schema.v1.jsonsrc/App/frontend/src/features/expressions/expression-functions.tssrc/App/frontend/src/features/expressions/function-evaluators/FunctionEvaluator.tssrc/App/frontend/src/features/expressions/function-evaluators/JmespathFunctionEvaluator.tssrc/App/frontend/src/features/expressions/function-evaluators/ObjectFunctionEvaluator.tssrc/App/frontend/src/features/expressions/shared-tests/functions/jmespath/jmespath.jsonsrc/App/frontend/src/features/expressions/validation.test.tssrc/App/frontend/src/features/expressions/validation.ts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## support-objects-in-expressions #19028 +/- ##
=================================================================
Coverage ? 95.84%
=================================================================
Files ? 3026
Lines ? 39790
Branches ? 4906
=================================================================
Hits ? 38137
Misses ? 1235
Partials ? 418 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
This pull request adds support for Jmespath queries in our expression language. This includes a new dependnecy; Jmespath JS.
This also includes a new function evaluator class;
JmespathFunctionEvaluator. Since it follows the same pattern asObjectFunctionEvaluator, I have also added an abstract class that both of them extend and moved them into a separate folder. In the future, we may consider refactoring more of the functions the same way in order to makeexpression-functions.tseasier to navigate.Here is the corresponding implementation in backend: Altinn/app-lib-dotnet#1790
Verification
Summary by CodeRabbit