Skip to content

feat: add unique template transformation - #493

Open
danielo515 wants to merge 1 commit into
masterfrom
claude/stoic-allen-i6ggsm
Open

danielo515 wants to merge 1 commit into
masterfrom
claude/stoic-allen-i6ggsm

Conversation

@danielo515

Copy link
Copy Markdown
Owner

Summary

Adds a new unique transformation to template variables and a matching unique getter on ResultValue that deduplicates array items while preserving the order of first occurrence.

{{ tags | unique }}
  • Arrays: duplicates are removed, order-of-first-occurrence is preserved (["foo", "bar", "foo", "baz"] → foo,bar,baz).
  • Non-array values (strings, numbers, booleans, FileProxy, records): returned unchanged, since a single value is trivially unique. This keeps the transformation safe to drop on any field.
  • Chainable: result.getValue('tags').lower.unique.bullets works as expected.

Fits alongside the existing slug / snake / capitalize transformations and follows the same shape (single-word, no arguments, applies to both templates and ResultValue).

Motivation: multiselect and tag fields can end up with the same option repeated. Without unique, cleaning that up required a map(...) callback or Templater glue.

Changes

  • src/core/template/templateSchema.ts — add unique to the transformations valibot union.
  • src/core/template/templateParser.ts — handle the unique case in executeTransformation; extract a uniqueValues helper.
  • src/core/ResultValue.ts — add a unique getter that delegates to uniqueValues for arrays.
  • src/core/template/templateParser.test.ts / src/core/ResultValue.test.ts — cover arrays, dedup ordering, non-array pass-through, empty arrays, and chaining.
  • docs/templates.md / docs/ResultValue.md — document the new transformation and shortcut.

Test plan

  • npm run test — all 220 tests pass, including the new unique cases.
  • npm run build — lint, svelte-check, and production bundle all succeed (only pre-existing unused-CSS warnings remain).

Generated by Claude Code

Adds a `unique` transformation to template variables and a matching
`unique` getter on `ResultValue` that deduplicates array items while
preserving the order of first occurrence. Non-array values are returned
unchanged so the transformation is safe to use on any field, and it
composes with the other shortcuts (e.g. `result.getValue('tags').lower.unique`).

Useful for cleaning up multiselect or tag fields where the same option
might have been picked more than once, without extra template glue.
@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Greptile Summary

Adds a unique transformation that removes duplicate array entries while preserving their first-seen order.

  • Extends template parsing and validation to support unique.
  • Adds a chainable ResultValue.unique getter.
  • Covers array deduplication, scalar pass-through, empty arrays, ordering, and shortcut chaining.
  • Documents the new template transformation and ResultValue shortcut.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete functional, security, or compatibility defects identified.

The new transformation matches the repository’s string-array value model, preserves first-occurrence ordering, leaves non-array values unchanged, and is covered across both supported APIs.

Important Files Changed

Filename Overview
src/core/template/templateParser.ts Adds a reusable Set-based deduplication helper and exposes it through the template transformation executor.
src/core/template/templateSchema.ts Extends the validated transformation union with the new unique keyword.
src/core/ResultValue.ts Adds a non-mutating, chainable getter that deduplicates array values and passes scalar values through unchanged.
src/core/template/templateParser.test.ts Tests ordering, unchanged unique arrays, scalar pass-through, and empty-array rendering for templates.
src/core/ResultValue.test.ts Tests primitive deduplication, rendering, empty arrays, scalar pass-through, and shortcut chaining.

Reviews (1): Last reviewed commit: "feat: add `unique` template transformati..." | Re-trigger Greptile

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant