Skip to content

fix: preserve Blob values with files preserve#79

Merged
samlaycock merged 2 commits into
mainfrom
fix/preserve-blob-values
May 19, 2026
Merged

fix: preserve Blob values with files preserve#79
samlaycock merged 2 commits into
mainfrom
fix/preserve-blob-values

Conversation

@samlaycock

Copy link
Copy Markdown
Owner

Summary

Fixes #66.

This updates plain-object encoding so Blob values are handled consistently with File values:

  • preserves plain object Blob values when { files: "preserve" } is passed
  • keeps the default behavior explicit by throwing for plain object File and Blob values unless preservation is enabled
  • widens the preserved encode entry type to [string, string | File | Blob][]
  • updates README API/docs to describe the Blob support
  • adds a patch changeset for the behavior fix

Verification

  • bun fmt
  • bun lint:fix
  • bun test
  • bun typecheck

Treat Blob values like File values during plain-object encoding so callers can opt into preserving binary fields with files: preserve. Update the preserved entry type, docs, regression tests, and changeset for issue #66.
@samlaycock samlaycock marked this pull request as ready for review May 19, 2026 19:52
@greptile-apps

greptile-apps Bot commented May 19, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes issue #66 by extending the files: "preserve" option to handle plain-object Blob values alongside File values. It also closes the previously reported type mismatch by widening decode's parameter from Iterable<[string, FormDataEntryValue]> to Iterable<DecodableEntry> (where DecodableEntry = [string, string | File | Blob]).

  • isFileValue in encode.ts now detects Blob in addition to File, with the same environment guard (typeof Blob !== \"undefined\"), and the walk-time error message is updated accordingly.
  • DecodableEntry / DecodableEntryValue are introduced in decode.ts and exported from both core.ts and index.ts, making the widened decode signature part of the public API.
  • Tests cover the new encode-preserve, encode-throw, and reserved-key error cases for Blob; a compile-time assertion in types.test.ts confirms the encode → decode type round-trip now type-checks.

Confidence Score: 5/5

Safe to merge - the change is additive and well-scoped with no impact on existing encode/decode behavior for non-Blob inputs.

The Blob preservation path follows the exact same pattern as the pre-existing File preservation path, the type widening is correct in both directions, and the only gap is a minor decode error-message inconsistency that does not affect runtime behavior.

No files require special attention beyond the minor error-message inconsistency in src/decode.ts.

Important Files Changed

Filename Overview
src/encode.ts Widens PreservedFileEntry to include Blob, updates isFileValue to detect Blob, updates error message, and broadens encodeStringEntries parameter type - all changes are correct and consistent.
src/decode.ts Adds DecodableEntry/DecodableEntryValue types and widens the decode parameter to accept Blob entries; the thrown error message still reads 'File entries are not supported' instead of 'File and Blob entries'.
test/roundtrip.test.ts Adds encode-side tests for Blob preserve and throw cases.
test/types.test.ts Adds a compile-time assertion verifying encode output with Blob entries is assignable to the decode parameter type.
src/core.ts Re-exports the new DecodableEntry and DecodableEntryValue types - straightforward additive change.
src/index.ts Adds DecodableEntry and DecodableEntryValue to the public API surface.
README.md Updates docs to mention Blob alongside File throughout and corrects the API signature table.

Reviews (2): Last reviewed commit: "fix: accept blob entries in decode types" | Re-trigger Greptile

Comment thread src/encode.ts
Widen the public decode input type so encode output containing preserved Blob values can be passed directly to decode. Export the new entry aliases and add type coverage for the Blob encode-to-decode path.
@samlaycock samlaycock merged commit 05b2b23 into main May 19, 2026
3 checks passed
@samlaycock samlaycock deleted the fix/preserve-blob-values branch May 19, 2026 20:09
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.

[P1] Preserve Blob values when files: preserve is enabled or narrow the documented support

1 participant