Skip to content

feat(rules): add template and copy rules over several paths - #54

Merged
Mearman merged 2 commits into
mainfrom
feat/multi-path-rules
Oct 21, 2026
Merged

Mearman merged 2 commits into
mainfrom
feat/multi-path-rules

Conversation

@Mearman

@Mearman Mearman commented Oct 20, 2026

Copy link
Copy Markdown
Member

Adds two two-way rules that touch more than one path: template, which renders several string fields into one text and splits it back, and copy, which writes one value to several places.

A template is { op: "template", from: { given: "people[].given", family: "people[].family" }, to: "names[]", template: "{family}, {given}" }, with {{ and }} for literal braces. The schema refuses a template that cannot be inverted (a field used twice or not at all, a placeholder naming no field, adjacent placeholders). Decode strips the leading and trailing literals and cuts each field at the first occurrence of the literal after it. Encode splits its own rendering back before returning it and throws for a value that contains the literal following its placeholder, so the round trip holds for everything encode accepts.

copy takes two or more to paths. Decode reads every copy and throws unless they are deeply equal, since copies edited apart have no single preimage. Before this, one value could not be written to two places at all: validateCrosswalk rejects two rules reading the same from.

The executor now reads every read-side path of a rule, pairs the matches element by element (throwing when the paths address different elements), and writes each result to its write-side path. ruleSides lists a rule's paths for the executor and for validateCrosswalk, which applies the wildcard, uniqueness and array-feeding checks to every path and requires a template's fields to come from the same element. The single-path ops go through the same loop unchanged.

Stacked on #53. The new tests were checked to discriminate by reverting the render check, the copy equality check, the element pairing check, the shared-array validation, the adjacency check and the empty-array materialisation on every write path. pnpm run prepublishOnly passes locally.

Fixes #36
Fixes #45

A template rule renders several string fields into one text through a
template of {name} placeholders and splits it back on decode. The
schema refuses a template without a unique inverse (a field used twice
or not at all, an unknown placeholder, adjacent placeholders), and
encode splits its own rendering back and throws for a value holding
the literal that follows its placeholder.

A copy rule writes one value to two or more paths; decode reads every
copy and throws unless they are deeply equal.

The executor reads every read-side path of a rule, pairs their matches
element by element (throwing when they address different elements),
and writes each result to its write-side path. ruleSides lists a
rule's paths for the executor and validateCrosswalk, which checks the
wildcard count, uniqueness and array feeding of every path and that a
template's fields come from the same element.
Adds both rules to the two-way table with the condition under which
each inverts, an example of each, and drops templates and one rule
writing several targets from "Not in this version".
@Mearman
Mearman changed the base branch from feat/element-when to main October 21, 2026 04:47
@Mearman
Mearman force-pushed the feat/multi-path-rules branch from 7ee9125 to d992670 Compare October 21, 2026 04:50
@Mearman
Mearman marked this pull request as ready for review October 21, 2026 05:54
@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 ⚠️ Failed 2026-10-21T06:59:31.712564Z
We couldn’t complete this review. Comment @codex security review to try again.
d992670 Manual request
ℹ️ 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 commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex security review

@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 1958a9e into main Oct 21, 2026
10 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Mearman
Mearman deleted the feat/multi-path-rules branch October 21, 2026 23:54
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 one rule writing several targets Support templates or concatenation of several fields into one

1 participant