Skip to content

feat(rules): add a one-way aggregate rule - #55

Merged
Mearman merged 2 commits into
mainfrom
feat/aggregates
Oct 21, 2026
Merged

Mearman merged 2 commits into
mainfrom
feat/aggregates

Conversation

@Mearman

@Mearman Mearman commented Oct 20, 2026

Copy link
Copy Markdown
Member

Adds a one-way aggregate rule: count, sum, min or max of the elements a wildcard path reaches, written at to when running the direction it names.

{ op: "aggregate", fn: "sum", from: "orders[].lines[].qty", to: "sales[].units", direction: "encode" } writes one total per order: to keeps fewer wildcards than from, and the matches are grouped by their indexes at the kept wildcards. Groups are enumerated from the arrays themselves, so an order with no lines gets 0 rather than no field. min and max of an empty group throw, a non-numeric value under sum, min or max throws, and so does a sum that overflows.

validateCrosswalk requires more wildcards in from than in to and checks that an encode-direction aggregate's kept arrays pair with the same source arrays the two-way rules use (the reverse pairing for a decode-direction one). It also now compares a decode-direction one-way write (a default or an aggregate) with the source-side from paths instead of the target-side to paths: a decode default named like a two-way to was rejected, and one named like a two-way from, which really does collide, was let through. The duplicate-from message reads "use" instead of "read" because a decode-direction write is now among the paths it compares.

Stacked on #54. The new tests were checked to discriminate by dropping empty groups, filing decode writes on the target side, removing the wildcard and pairing checks, and writing only the first group. pnpm run prepublishOnly passes locally.

Fixes #38

@Mearman
Mearman force-pushed the feat/multi-path-rules branch 2 times, most recently from 5757339 to 7ee9125 Compare October 21, 2026 00:09
@Mearman
Mearman force-pushed the feat/aggregates branch 2 times, most recently from 2bd4798 to 9cf94df Compare October 21, 2026 04:50
@Mearman
Mearman force-pushed the feat/multi-path-rules branch from 7ee9125 to d992670 Compare October 21, 2026 04:50
An aggregate rule writes the count, sum, minimum or maximum of the
elements a wildcard path reaches in the input document, in the
direction it names. Its to path keeps fewer wildcards than from, and
the matches are grouped by their indexes at the kept wildcards; groups
are enumerated from the arrays, so an empty group counts and sums to
0, while min and max of an empty group throw.

validateCrosswalk checks the wildcard counts and that the arrays to
keeps pair with the source arrays the two-way rules use. A
decode-direction one-way write, default or aggregate, is now compared
with the source-side from paths rather than the target-side to paths,
since that is the document it writes into.
Adds aggregate to the one-way table, notes that assertRoundTrip leaves
out a decode-direction aggregate's path, and drops aggregates from
"Not in this version".
@Mearman
Mearman changed the base branch from feat/multi-path-rules to main October 21, 2026 07:03
@Mearman
Mearman marked this pull request as ready for review October 21, 2026 07:16
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ⚠️ Failed 2026-10-21T07:16:14.100002Z
We couldn’t complete this review. Comment @codex security review to try again.
4cbd748 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins.

@Mearman
Mearman merged commit 38ae3af into main Oct 21, 2026
10 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Mearman
Mearman deleted the feat/aggregates branch October 21, 2026 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support aggregates and folds over arrays

1 participant