Skip to content

Add ShareMetadata type and fix middleware type safety#151

Merged
G4brym merged 1 commit intomainfrom
improve/share-metadata-type-safety
Mar 9, 2026
Merged

Add ShareMetadata type and fix middleware type safety#151
G4brym merged 1 commit intomainfrom
improve/share-metadata-type-safety

Conversation

@G4brym
Copy link
Copy Markdown
Owner

@G4brym G4brym commented Mar 9, 2026

Summary

  • Adds a ShareMetadata type interface to types.d.ts that defines the structure of share link metadata stored in R2
  • Replaces the untyped any in getShareLink.ts with the new ShareMetadata type, improving type safety when accessing share metadata properties (expiresAt, maxDownloads, passwordHash, etc.)
  • Types the parsed JSON in listShares.ts with ShareMetadata for consistent typing across share link modules
  • Types the metadata object in createShareLink.ts to ensure it conforms to the ShareMetadata interface at creation time
  • Fixes readOnlyMiddleware to use Hono's Next type instead of CallableFunction, which is the correct type for Hono middleware

Why

The share link metadata was being created with a well-defined structure in createShareLink.ts, but consumed as any in getShareLink.ts and implicitly untyped in listShares.ts. This meant there was no compile-time checking that the code accessing metadata properties (like expiresAt, passwordHash, currentDownloads) was correct. The new ShareMetadata type provides a single source of truth for the metadata shape.

Test plan

  • All existing tests pass (82 passed, 7 skipped — same as before)
  • pnpm lint passes with no issues
  • tsc type checking passes
  • No behavior changes — this is a type-only refactor

- Add ShareMetadata interface to types.d.ts for share link metadata
- Replace `any` type in getShareLink.ts with ShareMetadata
- Type parsed JSON in listShares.ts with ShareMetadata
- Type share metadata object in createShareLink.ts with ShareMetadata
- Fix readOnlyMiddleware to use Hono's Next type instead of CallableFunction
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
r2-explorer-docs 79e340e Commit Preview URL

Branch Preview URL
Mar 09 2026, 04:07 PM

Copy link
Copy Markdown
Owner Author

@G4brym G4brym left a comment

Choose a reason for hiding this comment

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

Automated Code Review — APPROVED ✅

Review Scores: 5/5 reviewers approved
CI Status: All checks passed ✅

Summary

Type-only refactor adding a ShareMetadata interface that replaces any across the share link modules, plus a fix to use Hono's Next type in readOnlyMiddleware. The type definition exactly matches the object shape created in createShareLink.ts, and all property accesses in getShareLink.ts and listShares.ts align correctly. No runtime behavior changes.

Review Perspectives

  1. Correctness: ✅ ShareMetadata type matches creation shape and all access patterns; optional/required fields are correct
  2. Security: ✅ No runtime changes, no new attack surfaces
  3. Performance: ✅ Types compile away, zero runtime impact
  4. Code Quality: ✅ Single source of truth for metadata shape, follows existing conventions, clean diff
  5. Testing: ✅ All 82 tests pass, no behavior changes requiring new tests

🤖 Automated review by prodboard

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.

1 participant