fix(nuxthub): handle object form of hub.db - #3822
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe NuxtHub preset adds database mapping that validates PostgreSQL URLs and SQLite filenames before producing Nuxt Content configuration. Both Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/presets/nuxthub.ts`:
- Around line 25-26: Update the database config mapper around the driver
allowlist to normalize aliases before returning ContentDatabaseConfig: map
postgres to postgresql, and map sqlite by converting connection.url to filename
instead of emitting url. Add or update mapper coverage for both sqlite and
postgres aliases while preserving existing handling for the other drivers.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 20d8f438-ef48-4cbd-af04-0793edbf2f4a
📒 Files selected for processing (2)
src/presets/nuxthub.tstest/unit/nuxthubPreset.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/presets/nuxthub.ts`:
- Around line 19-23: Update the PostgreSQL and SQLite mapping branches in the
hub database preset to validate required connection values before returning a
config: require a non-empty URL for PostgreSQL and a non-empty filename or
URL-derived path for SQLite. Return undefined when validation fails so malformed
object-form hub.db values reach the existing warning/default fallback instead of
being accepted.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f978a619-27fb-495f-92e2-37e28999c299
📒 Files selected for processing (2)
src/presets/nuxthub.tstest/unit/nuxthubPreset.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/presets/nuxthub.ts`:
- Around line 19-24: Update the PostgreSQL and SQLite branches around
hubDb.connection to validate runtime types before constructing the config:
accept url only when typeof value is "string", and for SQLite only use filename
when it is a string, otherwise use url.replace only when url is a string. Return
undefined when neither valid string value is available.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8558e52c-5413-4940-8f0d-90830695976a
📒 Files selected for processing (2)
src/presets/nuxthub.tstest/unit/nuxthubPreset.test.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/unit/nuxthubPreset.test.ts (1)
111-115: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAssert the unsupported-driver warning.
This test verifies only that
options.databaseremains unset. Also spy on the warning path and assert it is called, so silent fallback regressions cannot pass. Per the PR objective, unsupported drivers must warn before falling back.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/unit/nuxthubPreset.test.ts` around lines 111 - 115, Update the unsupported-driver test around nuxthubPreset.setup to spy on the warning/logging path used for unsupported database drivers, then assert it is called during setup before retaining the existing options.database undefined assertion. Use the existing warning symbol and verify the fallback emits a warning for the MySQL configuration.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@test/unit/nuxthubPreset.test.ts`:
- Around line 111-115: Update the unsupported-driver test around
nuxthubPreset.setup to spy on the warning/logging path used for unsupported
database drivers, then assert it is called during setup before retaining the
existing options.database undefined assertion. Use the existing warning symbol
and verify the fallback emits a warning for the MySQL configuration.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: bfed1549-ec5d-4de8-ac7b-4b3d2893b5a3
📒 Files selected for processing (2)
src/presets/nuxthub.tstest/unit/nuxthubPreset.test.ts
hub.db
🔗 Linked issue
Resolves #3821
❓ Type of change
📚 Description
The nuxthub preset only mapped the NuxtHub database config into
content.databasewhenhub.dbwas a string. With@nuxthub/core>= 0.10 the config can also be an object, in that case the check failed andcontent.databasesilently fell back to the default sqlite config, which picksbetter-sqlite3at runtime and breaks every query endpoint on Vercel withERR_DLOPEN_FAILED.Both
setup()andsetupNitro()now gate onhub.dbbeing truthy and read the resolved config fromruntimeConfig.hub.db, which is always an object withdriverandconnectiononce NuxtHub has run (both hooks fire aftermodules:done).The duplicated driver mapping is extracted into
hubDatabaseToContentDatabaseand now covers the driver names NuxtHub 0.10 actually resolves to:postgres-jsandneon-httpmap topostgresql(the old fallthrough produced an invalidtype: 'postgres-js'),better-sqlite3maps tosqlite, and unsupported drivers (mysql2,d1-http) warn and fall back to the default database instead of producing an invalid config.Added unit tests for the mapping, both
hub.dbforms, and the/tmplibsql rewrite insetupNitro.📝 Checklist