Skip to content

feat: Add Jmespath expression function in frontend#19028

Open
TomasEng wants to merge 2 commits into
support-objects-in-expressionsfrom
add-jmespath-function
Open

feat: Add Jmespath expression function in frontend#19028
TomasEng wants to merge 2 commits into
support-objects-in-expressionsfrom
add-jmespath-function

Conversation

@TomasEng

@TomasEng TomasEng commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

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 as ObjectFunctionEvaluator, 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 make expression-functions.ts easier to navigate.

Here is the corresponding implementation in backend: Altinn/app-lib-dotnet#1790

Verification

Summary by CodeRabbit

  • New Features
    • Introduced JMESPath query expressions to the expression system. Users can now perform advanced data querying and transformation using standard JMESPath syntax, including filtering, projecting data across lists, selecting properties, and evaluating built-in functions on complex data structures.

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This 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.

Changes

JMESPath Expression Function Implementation

Layer / File(s) Summary
Validation and base evaluator infrastructure
src/App/frontend/src/features/expressions/validation.ts, src/App/frontend/src/features/expressions/function-evaluators/FunctionEvaluator.ts
Adds assertValidValue() assertion helper to enforce runtime validation of expression values, and introduces abstract FunctionEvaluator<Arguments, ReturnValue> base class that centralises evaluation context, argument storage, and exception handling via throwRuntimeException() method.
Validation assertion tests
src/App/frontend/src/features/expressions/validation.test.ts
Test suite for assertValidValue covering rejection of invalid types (BigInt) and acceptance of valid values (numbers and other primitives).
Expression schema definition
src/App/frontend/schemas/json/layout/expression.schema.v1.json
Adds func-jmespath JSON schema definition specifying the array-form expression ["jmespath", <data>, <query>] with exactly two parameters, and registers it in the definitions.any.anyOf union to enable schema validation.
JMESPath evaluator implementation
src/App/frontend/package.json, src/App/frontend/src/features/expressions/function-evaluators/JmespathFunctionEvaluator.ts
Adds jmespath v0.16.0 runtime dependency and implements JmespathFunctionEvaluator that executes JMESPath queries via jmespath.search(), validates results with assertValidValue, and propagates errors using the base class exception mechanism with type checking for the query parameter.
Expression function registration and wiring
src/App/frontend/src/features/expressions/expression-functions.ts
Registers the jmespath function in ExprFunctionDefinitions with (Any, String) parameters and Any return type, updates imports to reference JmespathFunctionEvaluator, and implements the runtime instantiation in ExprFunctionImplementations.
ObjectFunctionEvaluator base class migration
src/App/frontend/src/features/expressions/function-evaluators/ObjectFunctionEvaluator.ts
Refactors ObjectFunctionEvaluator to extend FunctionEvaluator<ValidValue[], ValidObject> base class, replacing private field storage with protected getters, and replacing direct ExprRuntimeError construction with throwRuntimeException() helper calls whilst preserving key validation and even/odd argument filtering logic.
JMESPath test fixture
src/App/frontend/src/features/expressions/shared-tests/functions/jmespath/jmespath.json
Comprehensive test fixture covering JMESPath operations: property selection, object and list returns, list projections, filtering, literal expressions, built-in functions (abs), and error cases validating expected exception messages for invalid queries, missing arguments, and type mismatches.

Sequence Diagram

sequenceDiagram
  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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

frontend, squad/data

Suggested reviewers

  • ivarne
  • olavsorl

🐰 A query language hops into the system,
JMESPath expressions now we can list 'em,
Base classes shared, no more duplication,
Validation firm, safe computation!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding JMESPath expression function support to the frontend.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description covers the main changes, references linked issues and includes verification checklist items completed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-jmespath-function

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added skip-releasenotes Issues that do not make sense to list in our release notes kind/dependencies Used for issues or pull requests that are dependency updates labels Jun 2, 2026
@TomasEng TomasEng force-pushed the add-jmespath-function branch from 6d67237 to 0eaa66e Compare June 3, 2026 13:01
@TomasEng

TomasEng commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between c0b6c76 and 0eaa66e.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (9)
  • src/App/frontend/package.json
  • src/App/frontend/schemas/json/layout/expression.schema.v1.json
  • src/App/frontend/src/features/expressions/expression-functions.ts
  • src/App/frontend/src/features/expressions/function-evaluators/FunctionEvaluator.ts
  • src/App/frontend/src/features/expressions/function-evaluators/JmespathFunctionEvaluator.ts
  • src/App/frontend/src/features/expressions/function-evaluators/ObjectFunctionEvaluator.ts
  • src/App/frontend/src/features/expressions/shared-tests/functions/jmespath/jmespath.json
  • src/App/frontend/src/features/expressions/validation.test.ts
  • src/App/frontend/src/features/expressions/validation.ts

Comment thread src/App/frontend/schemas/json/layout/expression.schema.v1.json
@TomasEng TomasEng marked this pull request as ready for review June 4, 2026 08:54
@TomasEng TomasEng requested a review from a team as a code owner June 4, 2026 08:54
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (support-objects-in-expressions@c0b6c76). Learn more about missing BASE report.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TomasEng TomasEng added squad/data Issues that belongs to the named squad. frontend labels Jun 4, 2026
@TomasEng TomasEng moved this to 🔎 In review in Team Altinn Studio Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend kind/dependencies Used for issues or pull requests that are dependency updates skip-releasenotes Issues that do not make sense to list in our release notes squad/data Issues that belongs to the named squad.

Projects

Status: 🔎 In review

Development

Successfully merging this pull request may close these issues.

1 participant