Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Oct 29, 2025

Summary by CodeRabbit

  • New Features

    • Hono adapter support is now available for ZenStack server configurations.
  • Tests

    • Comprehensive test suite added for the Hono adapter covering create, read, update, delete, aggregation and relation scenarios.
    • Test descriptions updated for improved clarity.
  • Improvements

    • Standardized internal error logging across adapter implementations.

Copilot AI review requested due to automatic review settings October 29, 2025 22:00
@coderabbitai
Copy link

coderabbitai bot commented Oct 29, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a Hono adapter and tests, centralizes internal error logging via a new logInternalError utility, and updates existing adapters and package manifest to include the hono dependency and optional peer metadata.

Changes

Cohort / File(s) Summary
Package manifest
packages/server/package.json
Added hono as a dependency (^4.6.3), devDependency (^4.6.3), and an optional peerDependency (^4.6.0) (peerDependenciesMeta updated).
Common utilities
packages/server/src/adapter/common.ts
Added exported `logInternalError(logger: LogConfig
Adapter logging updates
packages/server/src/adapter/elysia/handler.ts, packages/server/src/adapter/express/middleware.ts, packages/server/src/adapter/fastify/plugin.ts
Replaced direct logging calls with logInternalError(...) and updated imports to use CommonAdapterOptions types where applicable.
Hono adapter implementation
packages/server/src/adapter/hono/handler.ts, packages/server/src/adapter/hono/index.ts
Added HonoOptions<Schema> interface and createHonoHandler<Schema>(options) middleware; re-exported handler from index.
Tests — descriptions updated
packages/server/test/adapter/express.test.ts, packages/server/test/adapter/fastify.test.ts
Renamed test descriptions for clarity; no behavioral changes.
Tests — Hono adapter
packages/server/test/adapter/hono.test.ts
Added comprehensive Hono adapter test suite exercising RPC and REST flows (CRUD, filtering, aggregation, relations).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review focus: packages/server/src/adapter/hono/handler.ts (client resolution, request parsing, route derivation, error paths).
  • Verify logInternalError signature/behavior and its replacement usage in elysia/express/fastify adapters.
  • Inspect new Hono tests for correctness and possible flakiness.

Possibly related PRs

Poem

🐰 I hopped in code and found a way,
To serve with Hono, bright as day.
Errors tucked in one small nest,
Adapters humming at their best.
Hop on — the tests all passed, hooray!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat(server): migrate hono adapter" directly corresponds to the primary changes in the changeset. The main addition is a new Hono adapter implementation (packages/server/src/adapter/hono/handler.ts and hono/index.ts) along with corresponding test coverage. The title clearly identifies this as the key feature being introduced. Supporting changes—such as extracting a common logInternalError function and applying it across existing adapters (elysia, express, fastify), plus updating test descriptions—are secondary refactoring activities that logically accompany the new adapter but are not the primary focus. The title is specific, concise, and would clearly communicate the PR's main intent to someone scanning commit history.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/hono

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2966a0b and 4a01e51.

📒 Files selected for processing (1)
  • packages/server/test/adapter/hono.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/server/test/adapter/hono.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: claude-review
  • GitHub Check: build-test (20.x, postgresql)
  • GitHub Check: build-test (20.x, sqlite)

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 and usage tips.

@claude
Copy link

claude bot commented Oct 29, 2025

Claude finished @ymc9's task —— View job


Code Review for Hono Adapter Migration

I've completed a comprehensive review of the Hono adapter implementation. Here's my feedback:

Code Quality & Best Practices

Excellent consistency with existing patterns:

  • The Hono adapter follows the same architectural patterns as Express, Fastify, and Elysia adapters
  • Proper TypeScript typing with generic Schema extends SchemaDef
  • Consistent error handling and logging via logInternalError function
  • Clean separation of concerns with createHonoHandler factory function

Good refactoring in common.ts:

  • Moved logInternalError to shared common.ts reducing code duplication across all adapters
  • Proper error logging with stack traces when available

🧪 Test Coverage

Comprehensive test suite:

  • Tests both RPC and REST API handlers (lines 9-80 and 82-145 in hono.test.ts)
  • Covers all CRUD operations: create, read, update, delete, count, aggregate, groupBy
  • Tests error scenarios (404 responses, missing data)
  • Follows same test patterns as other adapters for consistency

🔧 Technical Implementation

Proper Hono integration:

  • Correctly uses Hono's Context type and MiddlewareHandler
  • Proper path extraction using routePath(ctx) (line 28 in handler.ts:28)
  • Appropriate use of Hono's ctx.json() for responses
  • Handles both query parameters and request body parsing

Request handling:

  • URL parsing and query parameter extraction matches other adapters
  • Graceful JSON parsing with try/catch (lines 35-40 in handler.ts:35-40)
  • Proper path manipulation to remove route prefix

📦 Dependencies

Package.json changes look good:

  • Hono added as both devDependency and optional peerDependency (consistent with other adapters)
  • Version constraint ^4.6.0 is appropriate
  • Keywords updated to include "hono"

⚠️ Minor Issues Found

  1. Test inconsistency (line 89 in hono.test.ts:89): The REST handler test section uses RPCApiHandler instead of RestApiHandler:

    apiHandler: new RPCApiHandler({ schema: client.$schema }),

    Should probably be:

    apiHandler: new RestApiHandler({ schema: client.$schema }),
  2. Error message consistency: The Hono adapter uses different error messages than other adapters in some places, though this is minor.

🔒 Security & Performance

No security concerns identified:

  • Proper error handling prevents information leakage
  • No direct SQL injection vectors
  • Follows same security patterns as existing adapters

Performance considerations:

  • Efficient request processing with minimal overhead
  • Appropriate use of async/await
  • No performance bottlenecks identified

📋 Summary

This is a high-quality implementation that successfully migrates the Hono adapter following established patterns. The code is well-structured, properly tested, and maintains consistency with the existing codebase. The only notable issue is the minor test inconsistency mentioned above.

Recommendation:Approve with minor fix suggested

Copy link
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

This PR adds support for the Hono web framework as a new adapter, extending ZenStack's multi-framework compatibility alongside existing Express, Fastify, and Elysia adapters.

  • Implements a Hono adapter with middleware handler following the same pattern as other framework adapters
  • Refactors error logging into a shared utility function (logInternalError) to reduce code duplication across adapters
  • Adds comprehensive test coverage for both RPC and REST API handlers

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pnpm-lock.yaml Added [email protected] dependency to the lock file
packages/server/package.json Added hono as an optional peer dependency (^4.6.0) and dev dependency (^4.6.3)
packages/server/src/adapter/hono/index.ts Barrel export for the Hono adapter
packages/server/src/adapter/hono/handler.ts Core Hono middleware handler implementation with request processing logic
packages/server/src/adapter/common.ts Extracted shared logInternalError utility function
packages/server/src/adapter/express/middleware.ts Refactored to use shared logInternalError function
packages/server/src/adapter/fastify/plugin.ts Refactored to use shared logInternalError function
packages/server/src/adapter/elysia/handler.ts Refactored to use shared logInternalError function
packages/server/test/adapter/hono.test.ts Test suite for Hono adapter covering RPC and REST handlers
packages/server/test/adapter/express.test.ts Updated test descriptions for consistency
packages/server/test/adapter/fastify.test.ts Updated test descriptions for consistency
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2525ef3 and 2966a0b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (10)
  • packages/server/package.json (3 hunks)
  • packages/server/src/adapter/common.ts (2 hunks)
  • packages/server/src/adapter/elysia/handler.ts (2 hunks)
  • packages/server/src/adapter/express/middleware.ts (2 hunks)
  • packages/server/src/adapter/fastify/plugin.ts (2 hunks)
  • packages/server/src/adapter/hono/handler.ts (1 hunks)
  • packages/server/src/adapter/hono/index.ts (1 hunks)
  • packages/server/test/adapter/express.test.ts (2 hunks)
  • packages/server/test/adapter/fastify.test.ts (3 hunks)
  • packages/server/test/adapter/hono.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
{packages,samples,tests}/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place packages only under packages/, samples/, or tests/

Files:

  • packages/server/test/adapter/express.test.ts
  • packages/server/test/adapter/fastify.test.ts
  • packages/server/src/adapter/hono/handler.ts
  • packages/server/src/adapter/hono/index.ts
  • packages/server/src/adapter/elysia/handler.ts
  • packages/server/test/adapter/hono.test.ts
  • packages/server/src/adapter/express/middleware.ts
  • packages/server/src/adapter/fastify/plugin.ts
  • packages/server/src/adapter/common.ts
  • packages/server/package.json
🧬 Code graph analysis (6)
packages/server/src/adapter/hono/handler.ts (3)
packages/sdk/src/schema/schema.ts (1)
  • SchemaDef (10-18)
packages/server/src/adapter/common.ts (2)
  • CommonAdapterOptions (8-13)
  • logInternalError (15-17)
packages/orm/src/client/contract.ts (1)
  • ClientContract (50-170)
packages/server/src/adapter/elysia/handler.ts (1)
packages/server/src/adapter/common.ts (1)
  • logInternalError (15-17)
packages/server/test/adapter/hono.test.ts (4)
packages/testtools/src/client.ts (1)
  • createTestClient (52-169)
packages/server/src/adapter/hono/handler.ts (1)
  • createHonoHandler (18-56)
packages/server/test/utils.ts (1)
  • makeUrl (31-33)
packages/server/src/types.ts (1)
  • Response (52-62)
packages/server/src/adapter/express/middleware.ts (1)
packages/server/src/adapter/common.ts (1)
  • logInternalError (15-17)
packages/server/src/adapter/fastify/plugin.ts (1)
packages/server/src/adapter/common.ts (1)
  • logInternalError (15-17)
packages/server/src/adapter/common.ts (1)
packages/server/src/types.ts (1)
  • LogConfig (17-17)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: CodeQL analysis (javascript-typescript)
  • GitHub Check: build-test (20.x, postgresql)
  • GitHub Check: build-test (20.x, sqlite)
  • GitHub Check: claude-review
🔇 Additional comments (15)
packages/server/test/adapter/express.test.ts (1)

12-12: LGTM! Test descriptions improved for consistency.

The test descriptions have been updated to use consistent terminology across the test suite.

Also applies to: 151-151

packages/server/test/adapter/fastify.test.ts (1)

9-9: LGTM! Test descriptions improved for consistency.

The test descriptions have been updated to align with the naming conventions used across other adapter test suites.

Also applies to: 111-111, 142-142

packages/server/test/adapter/hono.test.ts (2)

147-163: LGTM! Helper functions are well-structured.

The test helper functions (makeRequest, unmarshal, createHonoApp) are clean and appropriately scoped for the test suite.


106-106: Verify type casing for consistency.

The type is specified as lowercase 'user', while the Express and Fastify REST tests use capitalized 'User'. Ensure this casing is intentional and consistent with the REST API handler's expectations.

packages/server/package.json (1)

77-77: LGTM! Hono dependency properly configured.

The Hono dependency has been correctly added as:

  • Development dependency for testing
  • Optional peer dependency for consumers

Also applies to: 87-87, 106-108

packages/server/src/adapter/elysia/handler.ts (1)

4-4: LGTM! Centralized error logging adopted.

The error handling now uses the shared logInternalError utility for consistent error logging across adapters.

Also applies to: 68-68

packages/server/src/adapter/hono/index.ts (1)

1-1: LGTM! Standard barrel export pattern.

The re-export follows the established pattern used by other adapters in the codebase.

packages/server/src/adapter/express/middleware.ts (1)

4-4: LGTM! Centralized error logging adopted.

The error handling now uses the shared logInternalError utility, aligning with the consistent error logging approach across all adapters.

Also applies to: 73-73

packages/server/src/adapter/fastify/plugin.ts (1)

5-5: LGTM! Centralized error logging adopted.

The error handling now uses the shared logInternalError utility, completing the consistent error logging refactor across all adapters.

Also applies to: 46-46

packages/server/src/adapter/common.ts (2)

2-3: LGTM! Imports are correct.

The imports support the new logInternalError function and follow proper conventions.


15-17: LGTM! Centralized error logging is well-designed.

The function appropriately handles optional logger configuration and includes stack traces when available. This provides a consistent error logging approach across adapters.

packages/server/src/adapter/hono/handler.ts (4)

1-6: LGTM! Imports are appropriate.

All necessary types and utilities are imported correctly for the Hono adapter implementation.


8-16: LGTM! Interface design is clean and flexible.

The interface properly extends CommonAdapterOptions and the getClient callback signature allows both synchronous and asynchronous client retrieval, which provides implementation flexibility.

Note: The return type doesn't include null or undefined, but line 21 checks for a falsy client. Consider whether getClient should return ClientContract<Schema> | null to match the runtime validation, or if the null check is defensive programming against implementation errors.


33-40: Body parsing logic is pragmatic.

The implementation gracefully handles request bodies by attempting to parse JSON when a body is present and silently ignoring parse failures. This permissive approach works well for an adapter.

Note: No HTTP method or Content-Type validation is performed, which means the adapter will attempt to parse any request body as JSON regardless of the method or declared content type.


42-54: Error handling and response handling are correct; no issues found.

The type assertions on line 50 are unnecessary but harmless. After verifying the API handlers (REST and RPC implementations), they guarantee that responses always have valid HTTP status codes (200, 201, 400, 404, 403, 422, 500) and JSON object bodies. Since 204/205 No Content responses and null/undefined bodies are never produced by the handlers, the assertions don't mask any runtime risks.

For consistency, consider removing the as object and as ContentfulStatusCode assertions, as all other adapters (Express, Fastify, Next.js, Elysia) pass the values directly without assertions. The code functions correctly as-is, but this would align the implementation pattern across adapters.

@claude
Copy link

claude bot commented Oct 30, 2025

Claude finished @ymc9's task —— View job


Code Review for Hono Adapter Migration

I've completed a comprehensive review of the Hono adapter implementation. Here's my detailed analysis:

Review Tasks

  • Read repository guidelines (CLAUDE.md)
  • Analyze Hono adapter implementation
  • Review test coverage and quality
  • Check error logging refactoring
  • Examine dependency changes
  • Identify potential issues and provide feedback

Code Quality & Best Practices

Excellent consistency with existing patterns:

  • The Hono adapter follows the same architectural patterns as Express, Fastify, and Elysia adapters
  • Proper TypeScript typing with generic Schema extends SchemaDef
  • Consistent error handling and logging via logInternalError function
  • Clean separation of concerns with createHonoHandler factory function

Good refactoring in common.ts:

  • Moved logInternalError to shared common.ts reducing code duplication across all adapters
  • Proper error logging with stack traces when available

🧪 Test Coverage

Comprehensive test suite:

  • Tests both RPC and REST API handlers (lines 9-80 and 82-145 in hono.test.ts)
  • Covers all CRUD operations: create, read, update, delete, count, aggregate, groupBy
  • Tests error scenarios (404 responses, missing data)
  • Follows same test patterns as other adapters for consistency

🔧 Technical Implementation

Proper Hono integration:

  • Correctly uses Hono's Context type and MiddlewareHandler
  • Proper path extraction using routePath(ctx) (line 28 in handler.ts:28)
  • Appropriate use of Hono's ctx.json() for responses
  • Handles both query parameters and request body parsing

Request handling:

  • URL parsing and query parameter extraction matches other adapters
  • Graceful JSON parsing with try/catch (lines 35-40 in handler.ts:35-40)
  • Proper path manipulation to remove route prefix

📦 Dependencies

Package.json changes look good:

  • Hono added as both devDependency and optional peerDependency (consistent with other adapters)
  • Version constraint ^4.6.0 is appropriate
  • Keywords updated to include "hono"

⚠️ Critical Issues Found

  1. 🚨 Test Bug (line 89 in hono.test.ts:89): The REST handler test section uses RPCApiHandler instead of RestApiHandler:

    apiHandler: new RPCApiHandler({ schema: client.$schema }),

    Should be:

    apiHandler: new RestApiHandler({ schema: client.$schema, endpoint: 'http://localhost/api' }),
  2. 🚨 Path Calculation Bug (line 28 in handler.ts:28): The substring calculation uses routePath(ctx).length - 1, which includes an extra character from the route path. Should be:

    const path = ctx.req.path.substring(routePath(ctx).length);

🔒 Security & Performance

No security concerns identified:

  • Proper error handling prevents information leakage
  • No direct SQL injection vectors
  • Follows same security patterns as existing adapters

Performance considerations:

  • Efficient request processing with minimal overhead
  • Appropriate use of async/await
  • No performance bottlenecks identified

📋 Summary

This is a high-quality implementation that successfully adds Hono adapter support following established patterns. The code is well-structured, properly tested, and maintains consistency with the existing codebase. The main issues are the test configuration bug and path calculation error, both of which should be fixed before merging.

Recommendation: ⚠️ Approve with critical fixes required

The implementation is solid but needs the two critical bugs fixed to ensure proper functionality and test coverage.


@ymc9 ymc9 merged commit 8119298 into dev Oct 30, 2025
5 checks 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.

2 participants