Skip to content

refactor: reduce duplication with shared Env type, renderPage helper, and email helper#160

Merged
mahata merged 1 commit intomainfrom
opencode/mighty-meadow
Mar 30, 2026
Merged

refactor: reduce duplication with shared Env type, renderPage helper, and email helper#160
mahata merged 1 commit intomainfrom
opencode/mighty-meadow

Conversation

@mahata
Copy link
Copy Markdown
Owner

@mahata mahata commented Mar 30, 2026

Summary

  • Shared Env type: Export type Env = { Bindings: Bindings; Variables: Variables } from hono/types.ts, replacing the inline { Bindings: Bindings; Variables: Variables } pattern across 10 files
  • renderPage() helper: New hono/helpers/renderPage.ts eliminates the repeated c.html(${await Page(...)}) pattern used in ~25 call sites across emailAuth.ts and index.tsx
  • sendOrLogVerificationEmail() helper: Consolidates duplicate email-sending logic in emailAuth.ts (dev-mode logging vs production Resend API) into a single function
  • Remove dead code: Removed redundant .trim() call in ChatRoom.ts where the value was already trimmed on the previous line

Net change: -2 lines across 13 files. All 98 tests pass, lint clean, build succeeds.

… and email helper

- Export shared Env type alias from types.ts, replacing inline { Bindings; Variables } across 10 files
- Extract renderPage() helper to eliminate repeated c.html/DOCTYPE pattern (~25 call sites)
- Extract sendOrLogVerificationEmail() in emailAuth.ts to consolidate duplicate email-sending logic
- Remove redundant trim check in ChatRoom.ts (value was already trimmed)
Copilot AI review requested due to automatic review settings March 30, 2026 02:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the Hono app to reduce repeated type boilerplate and duplicated HTML/email helper patterns, centralizing common logic in shared types/helpers.

Changes:

  • Added a shared exported Env type in hono/types.ts and updated routes/middleware to use it.
  • Introduced renderPage() helper to standardize <!DOCTYPE html>... rendering for JSX pages.
  • Consolidated email verification sending/logging logic into sendOrLogVerificationEmail().

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
hono/types.ts Exports shared Env type used across the app.
hono/testApp.ts Updates test middleware typing to use Env.
hono/routes/ws.ts Uses Hono<Env> and simplifies imports.
hono/routes/testAuth.ts Uses Hono<Env> for consistent typing.
hono/routes/messages.ts Uses Hono<Env> for consistent typing.
hono/routes/index.tsx Uses renderPage() and Env to reduce duplication.
hono/routes/emailAuth.ts Uses renderPage(), introduces sendOrLogVerificationEmail(), and switches to Env.
hono/routes/channels.ts Uses Hono<Env> for consistent typing.
hono/routes/auth.ts Replaces local Env alias with shared Env type.
hono/helpers/renderPage.ts Adds helper to render pages with a <!DOCTYPE html> prefix.
hono/durableObjects/ChatRoom.ts Removes redundant empty-message guard after earlier validation already trims/validates.
hono/auth/requireUser.ts Uses createMiddleware<Env> for consistent typing.
hono/app.tsx Updates app/middleware generics to use shared Env.

@mahata mahata merged commit 4000e45 into main Mar 30, 2026
7 checks passed
@mahata mahata deleted the opencode/mighty-meadow branch March 30, 2026 02:55
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.

2 participants