Skip to content

fix(drivers): avoid mutating caller input options in fs-lite and db0 - #788

Merged
pi0 merged 7 commits into
unjs:mainfrom
LeSingh1:fix/drivers-mutate-input-options
Aug 14, 2026
Merged

fix(drivers): avoid mutating caller input options in fs-lite and db0#788
pi0 merged 7 commits into
unjs:mainfrom
LeSingh1:fix/drivers-mutate-input-options

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #566

Two drivers were mutating the caller's input options object, which can cause unexpected side-effects when the same options object is reused or inspected after driver creation.

fs-lite driver

// Before — mutates caller's opts
opts.base = resolve(opts.base);

The fs-lite driver overwrote opts.base with resolve(opts.base), modifying the original object passed in by the caller.

db0 driver

// Before — mutates caller's opts
opts.tableName = opts.tableName || DEFAULT_TABLE_NAME;

The db0 driver wrote a default value back into opts.tableName, modifying the original object passed in by the caller.

Fix

In both cases, the mutation is replaced with a local const that holds the resolved/defaulted value, leaving the caller's object untouched:

// fs-lite — after
const base = resolve(opts.base);

// db0 — after
const tableName = opts.tableName || DEFAULT_TABLE_NAME;

For db0, tableName is also passed as an explicit argument to setupTable() instead of reading it from the options object inside that function.

Note: the fs.ts driver already handles this correctly by using const base = resolve(userOptions.base) without touching userOptions.

Changes

  • src/drivers/fs-lite.ts: replace opts.base = resolve(opts.base) with const base = resolve(opts.base) and update all usages
  • src/drivers/db0.ts: replace opts.tableName = opts.tableName || DEFAULT_TABLE_NAME with const tableName = ... and thread it through to setupTable()

Summary by CodeRabbit

  • Bug Fixes

    • Improved driver configuration handling so supplied options remain unchanged.
    • Improved consistency when resolving database tables and filesystem paths.
    • Ensured default table and path settings are applied reliably across supported drivers.
  • Reliability

    • Added safeguards and regression coverage to preserve application configuration during driver setup.
    • Improved consistency across database, filesystem, and PlanetScale storage operations.

LeSingh1 added 2 commits June 20, 2026 12:04
Instead of overwriting opts.base with resolve(opts.base), create a
local const to hold the resolved base path. This prevents unexpected
mutation of the caller's options object.

Fixes unjs#566
Instead of overwriting opts.tableName with the default value, create a
local const to hold the resolved table name. This prevents unexpected
mutation of the caller's options object. Also thread tableName through
to setupTable() as a parameter instead of relying on the options object.

Fixes unjs#566
@LeSingh1
LeSingh1 requested a review from pi0 as a code owner June 20, 2026 19:05
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@pi0x, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 250de1dc-7e3c-48a2-9187-024788d9dcfb

📥 Commits

Reviewing files that changed from the base of the PR and between 8de7325 and 3364e49.

📒 Files selected for processing (2)
  • src/drivers/db0.ts
  • src/drivers/planetscale.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 66247540-b3ce-456d-8e40-f735a23d6cca

📥 Commits

Reviewing files that changed from the base of the PR and between 01e1de9 and 8de7325.

📒 Files selected for processing (6)
  • src/drivers/db0.ts
  • src/drivers/fs-lite.ts
  • src/drivers/planetscale.ts
  • test/drivers/db0.test.ts
  • test/drivers/fs-lite.test.ts
  • test/drivers/planetscale.test.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • test/drivers/fs-lite.test.ts
  • test/drivers/db0.test.ts
  • src/drivers/fs-lite.ts
  • test/drivers/planetscale.test.ts
  • src/drivers/planetscale.ts
  • src/drivers/db0.ts

📝 Walkthrough

Walkthrough

The db0, fs-lite, and PlanetScale drivers now resolve configuration values locally instead of mutating input options. db0 passes resolved database and table values to table setup. Regression tests verify option preservation.

Changes

Opts mutation removal

Layer / File(s) Summary
db0 local table configuration
src/drivers/db0.ts, test/drivers/db0.test.ts
Resolves tableName locally, passes database and table name to setupTable, and uses the resolved values across SQL operations and dialect-specific table creation. The test verifies that driver creation does not mutate input options.
fs-lite local base path
src/drivers/fs-lite.ts, test/drivers/fs-lite.test.ts
Resolves opts.base locally for path construction and returns copied options with the resolved base path. The test verifies that driver creation preserves input options.
PlanetScale local table configuration
src/drivers/planetscale.ts, test/drivers/planetscale.test.ts
Resolves the configured or default table locally and uses it across CRUD, metadata, key listing, and clearing queries. The test verifies that driver creation does not mutate input options.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 8de73

This localized change prevents two drivers from mutating caller-provided options without indicating a new user or production impact; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: pi0

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: preventing caller input option mutation in the fs-lite and db0 drivers.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch fix/drivers-mutate-input-options
🧪 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.

pi0 and others added 4 commits August 14, 2026 13:02
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ions

Keeps `driver.options` (used by tracing) reporting the resolved base and
default table name, without mutating the caller's object.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…tate-input-options

# Conflicts:
#	src/drivers/planetscale.ts
@pi0
pi0 merged commit cffa9c5 into unjs:main Aug 14, 2026
1 check passed
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.

Make sure drivers don't modify input options object

2 participants