Skip to content

Enhance camel-datasonnet with utility functions and standard library#22156

Open
gnodet wants to merge 2 commits intoapache:mainfrom
gnodet:datasonnet-enhancements
Open

Enhance camel-datasonnet with utility functions and standard library#22156
gnodet wants to merge 2 commits intoapache:mainfrom
gnodet:datasonnet-enhancements

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Mar 20, 2026

Summary

Improve the DataSonnet language integration to make it more ergonomic for Camel users:

  • New CML functions — null handling (cml.defaultVal, cml.isEmpty), type coercion (cml.toInteger, cml.toDecimal, cml.toBoolean), date/time (cml.now, cml.nowFmt, cml.formatDate, cml.parseDate), and utilities (cml.uuid, cml.typeOf)
  • camel.libsonnet standard library — auto-discovered helper functions for strings (capitalize, trim, split, join, contains, startsWith, endsWith, replace, lower, upper), collections (sum, sumBy, first, last, count, distinct, flatMap, sortBy, groupBy, min, max, take, drop, zip), and objects (pick, omit, merge, keys, values, entries, fromEntries)
  • Documentation — full reference for all new functions and the standard library in the component docs

All new functions are implemented through DataSonnet's existing Library SPI — no parser or grammar changes required.

Test plan

  • CmlFunctionsTest — 28 tests covering all new CML functions (null handling, type coercion, date/time, utilities, combined usage with body data)
  • CamelLibsonnetTest — 11 tests covering the camel.libsonnet standard library (string ops, collection ops, object ops, combined transformation with body data)
  • All 65 existing + new tests pass locally

gnodet and others added 2 commits March 20, 2026 13:03
Add inbound filtering of Camel-prefixed headers to prevent external
mail headers from injecting internal Camel headers (e.g. CamelFileName).
The outbound filter was already in place; this adds the same protection
for inbound messages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add new CML functions for null handling (defaultVal, isEmpty), type
coercion (toInteger, toDecimal, toBoolean), date/time (now, nowFmt,
formatDate, parseDate), and utilities (uuid, typeOf).

Ship a camel.libsonnet standard library with string helpers (capitalize,
trim, split, join, contains, startsWith, endsWith, replace, lower, upper),
collection helpers (sum, sumBy, first, last, count, distinct, flatMap,
sortBy, groupBy, min, max, take, drop, zip), and object helpers (pick,
omit, merge, keys, values, entries, fromEntries).

Update documentation with full reference for all new functions and the
standard library.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@gnodet
Copy link
Contributor Author

gnodet commented Mar 20, 2026

Related: the ?? (null coalescing) and ?. (optional chaining) operators are being tracked upstream at datasonnet/datasonnet-mapper#154. Once available, they would complement the cml.defaultVal() function added here with native syntax support.

Claude Code on behalf of Guillaume Nodet

gnodet added a commit that referenced this pull request Mar 20, 2026
Add a `camel transform dataweave` CLI command that converts MuleSoft
DataWeave 2.0 scripts into equivalent DataSonnet .ds files, enabling
easier migration of Mule integrations to Apache Camel.

The transpiler includes:
- Hand-written recursive descent parser for DataWeave 2.0 syntax
- AST-based conversion to DataSonnet with Camel CML functions
- Support for field access, operators, type coercion, null handling,
  collection operations (map/filter/reduce/flatMap/groupBy/orderBy),
  string operations, if/else, var/fun declarations
- Unsupported constructs flagged with TODO comments
- 43 unit tests covering all conversion patterns

CLI usage:
  camel transform dataweave --input flow.dwl --output flow.ds
  camel transform dataweave --input src/mule/ --output src/resources/
  camel transform dataweave -e 'payload.name default "unknown"'

Depends on PR #22156 (camel-datasonnet CML enhancements).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet marked this pull request as ready for review March 21, 2026 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants