Repository navigation
feat: add unique template transformation - #493
Open
danielo515 wants to merge 1 commit into
Open
danielo515 wants to merge 1 commit into
danielo515 wants to merge 1 commit into
Conversation
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 SummaryAdds a
Confidence Score: 5/5The 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.
|
| 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
uniquetransformation to template variables and a matchinguniquegetter onResultValuethat deduplicates array items while preserving the order of first occurrence.["foo", "bar", "foo", "baz"]→foo,bar,baz).FileProxy, records): returned unchanged, since a single value is trivially unique. This keeps the transformation safe to drop on any field.result.getValue('tags').lower.unique.bulletsworks as expected.Fits alongside the existing
slug/snake/capitalizetransformations and follows the same shape (single-word, no arguments, applies to both templates andResultValue).Motivation: multiselect and tag fields can end up with the same option repeated. Without
unique, cleaning that up required amap(...)callback or Templater glue.Changes
src/core/template/templateSchema.ts— adduniqueto thetransformationsvalibot union.src/core/template/templateParser.ts— handle theuniquecase inexecuteTransformation; extract auniqueValueshelper.src/core/ResultValue.ts— add auniquegetter that delegates touniqueValuesfor 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 newuniquecases.npm run build— lint,svelte-check, and production bundle all succeed (only pre-existing unused-CSS warnings remain).Generated by Claude Code