Skip to content

feat(directus): add Sharp transforms & key modifier.#2207

Open
kheiner wants to merge 8 commits intonuxt:mainfrom
kheiner:feat/add-directus-transform-types
Open

feat(directus): add Sharp transforms & key modifier.#2207
kheiner wants to merge 8 commits intonuxt:mainfrom
kheiner:feat/add-directus-transform-types

Conversation

@kheiner
Copy link
Copy Markdown
Contributor

@kheiner kheiner commented Apr 9, 2026

🔗 Linked issue

fixes #2194

📚 Description

  • (feature): Support for Keyed Transforms using the key string, stripping all other transforms supported by Nuxt/Image
    • (test): Ensure that key if present is not paired with other modifiers.
    • (playground): Identify Directus instance that has pre-configured keys in the public space for better explanation to developers.
  • (feature): Transforms should have typing for Image Operations, Color Manipulation, and Channel Manipulation as supported by Sharp.
  • (fix): The current transforms are typed as string[] which is not valid. Transforms should fallback to a tuple of type [string, ...any[]][] to prevent errors with using transforms not typed explicitly. (Future proofing for new transforms added to Sharp & supported by Directus.)
  • (docs): Update Docs ->
    • Explain key modifier.
    • Explicitly name Sharp Transforms that are supported (and link to details in Sharp Library)

kheiner and others added 7 commits April 7, 2026 15:10
Intentionally omitting Resizing operations at the moment due to coverage in Nuxt/Image and abstraction available to Directus.

TODO: Fix duplication of transform object.
Updated Directus playground/e2e_snapshots to use the Directus Sandbox.
…orms

Fixes nuxt#2194

* Implements the ability to use a `key` to use a preconfigured Directus
Transform set.
* Adds Types for Sharp Transforms [intentionally omitted resizing since
the basic functionality is abstracted in the nuxt/image module]
* Fixes issue of incorrect typing for transforms to allow for `[string,
...any[]]` (was incorrectly typed as `string[]`)
Whitespace was causing tests to fail;
* Sort import for `providers.test.ts` (NOTE: PR nuxt#2193 greatly improves
test and readability)
* Add E2E snapshot for `key` modifier.
* Fix missing test in `providers.test.ts`
* Add `key` test for `providers.test.ts`
Updated Docs to include:
* `key` :modifier
* Explain Sharp Transforms and provide examples.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 9, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/image@2207

commit: 7693343

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 32.52%. Comparing base (e3ce805) to head (7693343).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2207   +/-   ##
=======================================
  Coverage   32.52%   32.52%           
=======================================
  Files           7        7           
  Lines         372      372           
  Branches      131      131           
=======================================
  Hits          121      121           
  Misses        194      194           
  Partials       57       57           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why the tests specifically care about the order, nor did I do extensive research on why I needed to put the requests in a different order than the sources for a successful test. If I'm hiding a problem here, I'd like to know about it but as far as I can tell the order has no meaning outside of the test.

Remove unnecessary comments
Copy link
Copy Markdown
Contributor Author

@kheiner kheiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking forward to the feedback.

@kheiner kheiner marked this pull request as ready for review April 9, 2026 11:57
@kheiner kheiner requested a review from danielroe as a code owner April 9, 2026 11:57
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

📝 Walkthrough

Walkthrough

This pull request implements typed Sharp operation support and keyed transform functionality for the Directus image provider. The core provider implementation adds type-safe Sharp operation definitions, supports mutually-exclusive keyed transforms via modifiers.key, introduces optional top-level image parameters (width, height, quality, format, fit), and refactors URL generation logic. Documentation is expanded with Directus-specific modifier guidance and tabbed examples. The playground configuration and test fixtures are updated to reference a hosted sandbox instance, and new test cases validate both standard and keyed transform behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description is directly related to the changeset, detailing feature additions, test coverage, playground updates, and documentation changes for Directus transforms.
Linked Issues check ✅ Passed The pull request fully implements all coding requirements from issue #2194: keyed transforms support with validation, Sharp operation typing, tuple fallback for transforms, comprehensive tests, playground configuration, and documentation updates.
Out of Scope Changes check ✅ Passed All changes are directly related to the Directus provider enhancements specified in issue #2194; no unrelated modifications were introduced.
Title check ✅ Passed The title directly describes the main feature being added: Sharp transforms support and the key modifier for the Directus provider.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/runtime/providers/directus.ts (1)

102-114: Transforms deduplication approach works but has a minor inefficiency.

The JSON stringify/parse approach for deduplication is functional but performs redundant parsing. Consider using a Map or filtering duplicates in a single pass for better performance, though this is a minor concern given typical transform array sizes.

♻️ Alternative deduplication approach
 const operationsGenerator = createOperationsGenerator({
   valueMap: {
     transforms(value: SharpOperation[]) {
-      return value.length > 0
-        ? JSON.stringify(
-            Array.from(new Set(value.map(v => JSON.stringify(v))))
-              .map(v => JSON.parse(v)),
-          )
-        : undefined
+      if (value.length === 0) return undefined
+      const seen = new Set<string>()
+      const unique = value.filter((v) => {
+        const key = JSON.stringify(v)
+        if (seen.has(key)) return false
+        seen.add(key)
+        return true
+      })
+      return JSON.stringify(unique)
     },
   },
 })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/runtime/providers/directus.ts` around lines 102 - 114, The transforms
valueMap currently deduplicates by JSON.stringify/parse which works but does
extra parsing; update the transforms function inside createOperationsGenerator
(the operationsGenerator/valueMap/transforms handler for SharpOperation[]) to
deduplicate in a single pass (e.g., use a Map or Set of serialized entries to
filter duplicates while building the resulting array) and then JSON.stringify
that deduplicated array (return undefined for empty), keeping the same return
shape and types as before.
docs/content/3.providers/directus.md (1)

41-41: Minor: Use hyphen for compound adjective.

For grammatical correctness, "Directus specific" should be "Directus-specific" when used as a compound adjective.

📝 Proposed fix
-The `modifiers` object is used for Directus specific features. All modifiers are optional.
+The `modifiers` object is used for Directus-specific features. All modifiers are optional.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/content/3.providers/directus.md` at line 41, Update the sentence
describing the "modifiers" object to use a hyphenated compound adjective: change
"Directus specific features" to "Directus-specific features" so the phrase
correctly reads "The `modifiers` object is used for Directus-specific features.
All modifiers are optional." Ensure the `modifiers` symbol remains unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@docs/content/3.providers/directus.md`:
- Line 41: Update the sentence describing the "modifiers" object to use a
hyphenated compound adjective: change "Directus specific features" to
"Directus-specific features" so the phrase correctly reads "The `modifiers`
object is used for Directus-specific features. All modifiers are optional."
Ensure the `modifiers` symbol remains unchanged.

In `@src/runtime/providers/directus.ts`:
- Around line 102-114: The transforms valueMap currently deduplicates by
JSON.stringify/parse which works but does extra parsing; update the transforms
function inside createOperationsGenerator (the
operationsGenerator/valueMap/transforms handler for SharpOperation[]) to
deduplicate in a single pass (e.g., use a Map or Set of serialized entries to
filter duplicates while building the resulting array) and then JSON.stringify
that deduplicated array (return undefined for empty), keeping the same return
shape and types as before.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6c8abb98-16cf-45a3-8906-78b5a8da1ec5

📥 Commits

Reviewing files that changed from the base of the PR and between e3ce805 and 7693343.

📒 Files selected for processing (7)
  • docs/content/3.providers/directus.md
  • playground/app/providers.ts
  • playground/nuxt.config.ts
  • src/runtime/providers/directus.ts
  • test/e2e/__snapshots__/directus.json5
  • test/nuxt/providers.test.ts
  • test/providers.ts

@kheiner kheiner changed the title feat: add directus transform types feat(directus): add Sharp transforms & key modifier. Apr 11, 2026
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.

[feature] (provider/directus) Add Sharp transforms to modifiers, add support for keyed transforms

2 participants