Skip to content

feat(when): gate a wildcard rule per element - #53

Merged
Mearman merged 2 commits into
mainfrom
feat/element-when
Oct 21, 2026
Merged

Mearman merged 2 commits into
mainfrom
feat/element-when

Conversation

@Mearman

@Mearman Mearman commented Oct 20, 2026

Copy link
Copy Markdown
Member

Lets a rule that iterates an array be gated on a field of the element it is visiting, for example applying items[].radius to shapes[].r only where items[].kind is circle.

A when reference with wildcards is written against the rule's from side. Its part through its last wildcard must be the array from iterates at that depth (so it cannot point into an unrelated array), and it may have fewer wildcards than the rule, which gates every inner element on a field of the outer one. While decoding, that part is rebased onto the to side's array, so the same element is read in the target document. The field below it still has to keep its name in both shapes, the same constraint every gate already has.

readLocus takes the gate and drops a refused element before reading anything below it, so an element that lacks the rule's path is skipped rather than reported absent. Collection references (some, every) bind the same way. If every rule writing into an element skips it, the output array has a gap, which surfaces through the gap check added in the base PR.

Stacked on #52. The new tests were checked to discriminate by reverting the reader gate, the decode rebase and each validation branch. pnpm run prepublishOnly passes locally.

Fixes #40

A when reference with wildcards now names a field of the element the
rule is visiting. It is written against the rule's from side, its part
through its last wildcard must be the array from iterates at that
depth, and it may have fewer wildcards than the rule. While decoding,
that part is rebased onto the to side's array, so the gate reads the
same element in the target document.

readLocus takes an element gate and drops a refused element before
reading anything below it, so an element lacking the rule's path is
skipped rather than absent. Collection references bind the same way.
validateCrosswalk rejects a wildcard reference into another array,
one with more wildcards than its rule, and any on a one-way rule.
Describes how a wildcard reference binds to the visited element, how
decode rebases it onto the target array, and that an element every
rule skips is a gap error; drops the item from "Not in this version".
@Mearman
Mearman changed the base branch from feat/path-grammar to main October 21, 2026 00:09
@Mearman
Mearman marked this pull request as ready for review October 21, 2026 04:38
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

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 ✅ Completed 2026-10-21T04:44:40.390361Z 0512e9e 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.

@Mearman
Mearman merged commit 0b9c6f8 into main Oct 21, 2026
10 checks passed
@Mearman
Mearman deleted the feat/element-when branch October 21, 2026 04:51
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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 per-element when gating inside a wildcard

1 participant