Skip to content

feat(Handler)!: Signature changed - #76

Merged
nielsenko merged 5 commits into
mainfrom
serverpod-integration
May 26, 2025
Merged

nielsenko merged 5 commits into
mainfrom
serverpod-integration

Conversation

@nielsenko

@nielsenko nielsenko commented May 22, 2025 •

Copy link
Copy Markdown
Collaborator

Description

This PR address issues discovered while integrating relic into serverpod

Handler Signature Refactor

  • The Handler typedef has been changed from FutureOr<RequestContext> Function(RequestContext ctx) to FutureOr<HandledContext> Function(NewContext ctx).
  • The RequestContext hierarchy has been modified:
    • HandledContext is now a sealed class that extends RequestContext.
    • ResponseContext and HijackContext now extend HandledContext.
  • This change aims to narrow down the handler function's responsibility to produce a HandledContext.
  • Code across project has been updated to align with this new signature and context types.

Exports Changed

  • Missing exports added.
  • New public file lib/io_adapter.dart introduced. Code dependend on HttpServer from dart:io will only be imported to your project if you import this file.

Related Issues

  • Closes: ?

Pre-Launch Checklist

Please ensure that your PR meets the following requirements before submitting:

  • This update focuses on a single feature or bug fix. (For multiple fixes, please submit separate PRs.)
  • I have read and followed the Dart Style Guide and formatted the code using dart format.
  • I have referenced at least one issue this PR fixes or is related to.
  • I have updated/added relevant documentation (doc comments with ///), ensuring consistency with existing project documentation.
  • I have added new tests to verify the changes.
  • All existing and new tests pass successfully.
  • I have documented any breaking changes below.

Breaking Changes

Handler signature has changed

Summary by CodeRabbit

  • New Features

    • Expanded public API with new context, header extension, and routing middleware capabilities.
    • Introduced a unified adapter for I/O operations.
  • Refactor

    • Streamlined context and handler abstractions for improved clarity and consistency.
    • Simplified error handling and middleware logic.
  • Chores

    • Updated and cleaned up import statements across source and test files.
    • Added a new version header to the changelog.
  • Tests

    • Updated test utilities and handler signatures to align with new context types.
    • Removed unused imports from test files.

@coderabbitai

coderabbitai Bot commented May 22, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This update refactors context handling and handler signatures throughout the codebase. It introduces a sealed HandledContext class, updates the Handler typedef to use new context types, and simplifies type checks in middleware and handlers. Public exports are adjusted, a new io_adapter.dart library is added, and numerous redundant imports are removed.

Changes

File(s) Change Summary
CHANGELOG.md Added version header "0.4.0" at the top.
example/example.dart, example/multi_isolate.dart Updated imports to use new public io_adapter.dart, removed internal imports.
lib/io_adapter.dart New file re-exporting src/adapter/io/io_adapter.dart and src/adapter/io/io_serve.dart.
lib/relic.dart Added exports for context.dart, standard_headers_extensions.dart, routing_middleware.dart; removed io_serve.dart export.
lib/src/adapter/context.dart Refactored HandledContext from interface to sealed class; updated ResponseContext and HijackContext inheritance.
lib/src/adapter/io/http_response_extension.dart Removed import of standard_headers_extensions.dart.
lib/src/adapter/io/io_serve.dart Reordered and updated import paths for consistency; no logic changes.
lib/src/handler/handler.dart Changed Handler typedef to use NewContext and HandledContext; simplified respondWith by removing runtime type checks.
lib/src/middleware/middleware.dart, lib/src/middleware/middleware_logger.dart Removed explicit type checks and casts in middleware; updated parameter names and variable usage for clarity.
lib/src/relic_server.dart Simplified error handling and middleware wrapping; removed fallback 404 case; updated variable names.
test/handler/pipeline_test.dart, test/hijack/relic_hijack_test.dart, test/util/test_util.dart Updated handler signatures to use NewContext and HandledContext; removed internal imports; simplified handler logic in tests.
test/middleware/routing_middleware_test.dart Specified generic type for Router; removed unused internal imports.
test/relic_server_serve_test.dart, test/static/test_util.dart, test/message/request_test.dart, ... Removed unused imports of internal modules, especially standard_headers_extensions.dart and context.dart, across many test files.
test/util/test_util.dart Updated typedefs and functions to use new context types and signatures; replaced internal import with io_adapter.dart.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant Middleware
    participant Handler

    Client->>Server: Sends HTTP Request
    Server->>Middleware: Wraps request in NewContext
    Middleware->>Handler: Passes NewContext
    Handler-->>Middleware: Returns HandledContext
    Middleware-->>Server: Returns HandledContext
    Server-->>Client: Sends HTTP Response
Loading

Possibly related PRs

  • feat: Router middleware #68: Updates imports and handler signatures in example/example.dart and restructures context classes, closely matching the changes in context handling and routing middleware integration.
  • refactor!: Avoid using exceptions for control-flow #48: Refactors request handling to use new RequestContext variants and updates handler signatures, directly relating to the main PR's context and handler abstraction changes.

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov

codecov Bot commented May 22, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.59%. Comparing base (1730a54) to head (b253b4f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #76      +/-   ##
==========================================
+ Coverage   82.42%   82.59%   +0.17%     
==========================================
  Files          80       80              
  Lines        2429     2425       -4     
  Branches     1362     1356       -6     
==========================================
+ Hits         2002     2003       +1     
+ Misses        427      422       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nielsenko nielsenko changed the title serverpod integration feat(Handler)!: Signature changed May 22, 2025
@nielsenko nielsenko self-assigned this May 22, 2025
@nielsenko

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 22, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
example/example.dart (1)

29-35: ⚠️ Potential issue

Update handler function signature and context types
Since the Handler typedef now takes a NewContext and must return a HandledContext, the example’s hello(final RequestContext ctx) should be updated to something like:

HandledContext hello(final NewContext ctx) { … }

Also, adjust the cast to use the new context hierarchy (e.g. ctx as RespondableContext may no longer be needed or should target the new sealed subtypes).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1730a54 and 4dd30a2.

📒 Files selected for processing (93)
  • CHANGELOG.md (1 hunks)
  • example/example.dart (1 hunks)
  • example/multi_isolate.dart (1 hunks)
  • lib/io_adapter.dart (1 hunks)
  • lib/relic.dart (2 hunks)
  • lib/src/adapter/context.dart (2 hunks)
  • lib/src/adapter/io/http_response_extension.dart (0 hunks)
  • lib/src/adapter/io/io_serve.dart (1 hunks)
  • lib/src/handler/handler.dart (2 hunks)
  • lib/src/middleware/middleware.dart (1 hunks)
  • lib/src/middleware/middleware_logger.dart (1 hunks)
  • lib/src/relic_server.dart (2 hunks)
  • test/handler/pipeline_test.dart (1 hunks)
  • test/headers/basic/access_control_allow_credentials_header_test.dart (0 hunks)
  • test/headers/basic/access_control_max_age_header_test.dart (0 hunks)
  • test/headers/basic/access_control_request_headers_heder_test.dart (0 hunks)
  • test/headers/basic/age_header_test.dart (0 hunks)
  • test/headers/basic/allow_header_test.dart (0 hunks)
  • test/headers/basic/content_location_header_test.dart (0 hunks)
  • test/headers/basic/date_header_test.dart (0 hunks)
  • test/headers/basic/expires_header_test.dart (0 hunks)
  • test/headers/basic/host_header_test.dart (0 hunks)
  • test/headers/basic/if_modified_since_header_test.dart (0 hunks)
  • test/headers/basic/if_unmodified_since_header_test.dart (0 hunks)
  • test/headers/basic/last_modified_header.dart (0 hunks)
  • test/headers/basic/location_header_test.dart (0 hunks)
  • test/headers/basic/max_forwards_header_test.dart (0 hunks)
  • test/headers/basic/origin_header_test.dart (0 hunks)
  • test/headers/basic/referer_header_test.dart (0 hunks)
  • test/headers/basic/server_header_test.dart (0 hunks)
  • test/headers/basic/trailer_header_test.dart (0 hunks)
  • test/headers/basic/user_agent_header_test.dart (0 hunks)
  • test/headers/basic/via_header_test.dart (0 hunks)
  • test/headers/basic/x_powered_by_header_test.dart (0 hunks)
  • test/headers/header_test.dart (0 hunks)
  • test/headers/typed_headers/accept_encoding_header_test.dart (0 hunks)
  • test/headers/typed_headers/accept_header_test.dart (0 hunks)
  • test/headers/typed_headers/accept_language_test.dart (0 hunks)
  • test/headers/typed_headers/accept_ranges_header_test.dart (0 hunks)
  • test/headers/typed_headers/access_control_allow_headers_header_test.dart (0 hunks)
  • test/headers/typed_headers/access_control_allow_methods_header_test.dart (0 hunks)
  • test/headers/typed_headers/access_control_allow_origin_header_test.dart (0 hunks)
  • test/headers/typed_headers/access_control_expose_headers_header_test.dart (0 hunks)
  • test/headers/typed_headers/access_control_request_method_header_test.dart (0 hunks)
  • test/headers/typed_headers/authorization_header_test.dart (0 hunks)
  • test/headers/typed_headers/cache_control_header_test.dart (0 hunks)
  • test/headers/typed_headers/clear_site_data_header_test.dart (0 hunks)
  • test/headers/typed_headers/connection_header_test.dart (0 hunks)
  • test/headers/typed_headers/content_disposition_header_test.dart (0 hunks)
  • test/headers/typed_headers/content_encoding_header_test.dart (0 hunks)
  • test/headers/typed_headers/content_language_header_test.dart (0 hunks)
  • test/headers/typed_headers/content_range_header_test.dart (0 hunks)
  • test/headers/typed_headers/content_security_policy_header_test.dart (0 hunks)
  • test/headers/typed_headers/cookie_header_test.dart (0 hunks)
  • test/headers/typed_headers/cross_origin_embedder_policy_header_test.dart (0 hunks)
  • test/headers/typed_headers/cross_origin_opener_policy_header_test.dart (0 hunks)
  • test/headers/typed_headers/cross_origin_resource_policy_header_test.dart (0 hunks)
  • test/headers/typed_headers/etag_header_test.dart (0 hunks)
  • test/headers/typed_headers/expect_header_test.dart (0 hunks)
  • test/headers/typed_headers/from_header_test.dart (0 hunks)
  • test/headers/typed_headers/if_match_header_test.dart (0 hunks)
  • test/headers/typed_headers/if_none_match_header_test.dart (0 hunks)
  • test/headers/typed_headers/if_range_header_test.dart (0 hunks)
  • test/headers/typed_headers/permissions_policy_header_test.dart (0 hunks)
  • test/headers/typed_headers/proxy_authenticate_header_test.dart (0 hunks)
  • test/headers/typed_headers/proxy_authorization_header_test.dart (0 hunks)
  • test/headers/typed_headers/range_header_test.dart (0 hunks)
  • test/headers/typed_headers/referrer_policy_header_test.dart (0 hunks)
  • test/headers/typed_headers/retry_after_header_test.dart (0 hunks)
  • test/headers/typed_headers/sec_fetch_dest_header_test.dart (0 hunks)
  • test/headers/typed_headers/sec_fetch_mode_header_test.dart (0 hunks)
  • test/headers/typed_headers/sec_fetch_site_header_test.dart (0 hunks)
  • test/headers/typed_headers/set_cookie_header_test.dart (0 hunks)
  • test/headers/typed_headers/strict_transport_security_header_test.dart (0 hunks)
  • test/headers/typed_headers/te_header_test.dart (0 hunks)
  • test/headers/typed_headers/transfer_encoding_header_test.dart (0 hunks)
  • test/headers/typed_headers/upgrade_header_test.dart (0 hunks)
  • test/headers/typed_headers/vary_header_test.dart (0 hunks)
  • test/headers/typed_headers/www_authenticate_header_test.dart (0 hunks)
  • test/hijack/relic_hijack_test.dart (0 hunks)
  • test/message/apply_headers_test.dart (0 hunks)
  • test/message/message_test.dart (0 hunks)
  • test/message/request_test.dart (0 hunks)
  • test/message/response_test.dart (0 hunks)
  • test/middleware/create_middleware_test.dart (0 hunks)
  • test/middleware/routing_middleware_test.dart (1 hunks)
  • test/relic_server_serve_test.dart (0 hunks)
  • test/static/basic_file_test.dart (0 hunks)
  • test/static/create_file_handler_test.dart (0 hunks)
  • test/static/default_document_test.dart (0 hunks)
  • test/static/directory_listing_test.dart (0 hunks)
  • test/static/test_util.dart (0 hunks)
  • test/util/test_util.dart (1 hunks)
💤 Files with no reviewable changes (79)
  • test/headers/basic/date_header_test.dart
  • test/headers/typed_headers/expect_header_test.dart
  • test/headers/basic/last_modified_header.dart
  • test/headers/typed_headers/cross_origin_resource_policy_header_test.dart
  • test/headers/basic/origin_header_test.dart
  • test/headers/basic/allow_header_test.dart
  • test/headers/basic/age_header_test.dart
  • test/headers/typed_headers/access_control_expose_headers_header_test.dart
  • test/message/apply_headers_test.dart
  • test/headers/typed_headers/accept_header_test.dart
  • test/headers/basic/user_agent_header_test.dart
  • test/headers/typed_headers/accept_ranges_header_test.dart
  • test/headers/typed_headers/transfer_encoding_header_test.dart
  • test/headers/typed_headers/sec_fetch_dest_header_test.dart
  • test/headers/basic/access_control_max_age_header_test.dart
  • test/headers/typed_headers/content_language_header_test.dart
  • test/headers/typed_headers/sec_fetch_mode_header_test.dart
  • test/headers/typed_headers/access_control_allow_headers_header_test.dart
  • test/headers/typed_headers/content_encoding_header_test.dart
  • test/headers/basic/access_control_allow_credentials_header_test.dart
  • test/headers/typed_headers/access_control_allow_origin_header_test.dart
  • test/headers/typed_headers/set_cookie_header_test.dart
  • test/headers/typed_headers/content_disposition_header_test.dart
  • test/headers/typed_headers/accept_encoding_header_test.dart
  • test/headers/typed_headers/sec_fetch_site_header_test.dart
  • lib/src/adapter/io/http_response_extension.dart
  • test/headers/basic/expires_header_test.dart
  • test/headers/typed_headers/proxy_authenticate_header_test.dart
  • test/headers/typed_headers/connection_header_test.dart
  • test/headers/typed_headers/content_security_policy_header_test.dart
  • test/headers/basic/max_forwards_header_test.dart
  • test/static/basic_file_test.dart
  • test/headers/typed_headers/cookie_header_test.dart
  • test/headers/typed_headers/etag_header_test.dart
  • test/headers/typed_headers/cross_origin_embedder_policy_header_test.dart
  • test/static/default_document_test.dart
  • test/headers/basic/if_modified_since_header_test.dart
  • test/middleware/create_middleware_test.dart
  • test/headers/typed_headers/access_control_allow_methods_header_test.dart
  • test/headers/typed_headers/permissions_policy_header_test.dart
  • test/headers/typed_headers/if_none_match_header_test.dart
  • test/headers/typed_headers/cache_control_header_test.dart
  • test/headers/basic/location_header_test.dart
  • test/headers/typed_headers/authorization_header_test.dart
  • test/headers/basic/trailer_header_test.dart
  • test/headers/typed_headers/accept_language_test.dart
  • test/headers/typed_headers/range_header_test.dart
  • test/headers/typed_headers/from_header_test.dart
  • test/headers/basic/host_header_test.dart
  • test/headers/basic/content_location_header_test.dart
  • test/headers/typed_headers/strict_transport_security_header_test.dart
  • test/headers/typed_headers/retry_after_header_test.dart
  • test/headers/typed_headers/vary_header_test.dart
  • test/headers/typed_headers/te_header_test.dart
  • test/headers/basic/via_header_test.dart
  • test/headers/typed_headers/www_authenticate_header_test.dart
  • test/message/response_test.dart
  • test/headers/typed_headers/content_range_header_test.dart
  • test/static/test_util.dart
  • test/headers/basic/server_header_test.dart
  • test/headers/basic/if_unmodified_since_header_test.dart
  • test/headers/typed_headers/if_match_header_test.dart
  • test/headers/typed_headers/clear_site_data_header_test.dart
  • test/headers/typed_headers/access_control_request_method_header_test.dart
  • test/headers/typed_headers/upgrade_header_test.dart
  • test/message/message_test.dart
  • test/headers/basic/referer_header_test.dart
  • test/headers/typed_headers/referrer_policy_header_test.dart
  • test/headers/typed_headers/if_range_header_test.dart
  • test/message/request_test.dart
  • test/headers/typed_headers/proxy_authorization_header_test.dart
  • test/static/create_file_handler_test.dart
  • test/relic_server_serve_test.dart
  • test/static/directory_listing_test.dart
  • test/headers/basic/access_control_request_headers_heder_test.dart
  • test/headers/typed_headers/cross_origin_opener_policy_header_test.dart
  • test/headers/header_test.dart
  • test/headers/basic/x_powered_by_header_test.dart
  • test/hijack/relic_hijack_test.dart
🔇 Additional comments (26)
example/example.dart (1)

3-3: Import of io_adapter.dart is correct
Switching to package:relic/io_adapter.dart aligns with the new public I/O adapter entry point.

example/multi_isolate.dart (1)

5-6: Import consolidation is correct
Adding package:relic/io_adapter.dart and keeping package:relic/relic.dart ensures that serve and related I/O functions resolve through the new public API.

lib/src/adapter/io/io_serve.dart (1)

4-8: Relative imports adjusted properly
Changing to import '../../handler/handler.dart'; and import '../../relic_server.dart'; correctly targets the project’s lib/src layout. No functional changes or regressions appear.

lib/io_adapter.dart (1)

1-3: New io_adapter.dart exports look good
Consolidating exports of src/adapter/io/io_adapter.dart and src/adapter/io/io_serve.dart under a single public library simplifies imports for consumers.

test/handler/pipeline_test.dart (1)

31-31: Signature updated to align with new Handler typedef

The function signature has been correctly updated to use NewContext and HandledContext types, which aligns with the refactored Handler typedef in the core library.

test/middleware/routing_middleware_test.dart (1)

351-351: Explicitly specified generic type parameter for Router

The Router instantiation now correctly includes the explicit <Handler> type parameter, ensuring type safety and consistency with the updated Handler typedef.

lib/src/middleware/middleware.dart (2)

54-55: Parameter name change improves clarity

Changed parameter name from requestCtx to ctx for better clarity, consistent with the broader refactoring in the codebase.


59-59: Updated innerHandler invocation

Updated to use the new parameter name ctx instead of requestCtx, ensuring consistency with the parameter name change.

lib/relic.dart (3)

4-4: Added export for context types

Added export for src/adapter/context.dart, making the refactored context types available in the public API. This is essential for the breaking change in the handler signature.


15-15: Added export for standard headers extensions

Added export for src/headers/standard_headers_extensions.dart, centralizing access to standard header extensions in the public API.


24-24: Added export for routing middleware

Added export for src/middleware/routing_middleware.dart, making routing functionality available in the public API. This aligns with the reorganization of the package's public API surface.

lib/src/middleware/middleware_logger.dart (4)

20-20: Improved parameter naming for clarity

The parameter name change from request to ctx better reflects that this is a context object containing the request, not just the request itself.


25-26: Renamed variable improves code clarity

Renaming newCtx to handledCtx better reflects the nature of the variable as the result of handling a request context. This aligns with the new HandledContext type in the updated architecture.


30-32: Simplified logging call with improved context handling

The updated code properly uses the renamed variables and accesses request data through the context hierarchy, which is more consistent with the new context model where HandledContext is a sealed class.


35-35: Improved error logging with proper context access

Error logging now correctly uses ctx.request instead of a potentially redundant request.request, making the code more maintainable and consistent with the context architecture changes.

lib/src/relic_server.dart (3)

117-118: Improved parameter naming for clarity

The parameter name change from request to ctx better reflects that this is a context object containing the request, not just the request itself. This is consistent with the naming conventions in other parts of the codebase.


119-132: Refined context handling with sealed class

The variable rename from newCtx to handledCtx and the updated switch expression make the code more readable and correctly handle the sealed HandledContext class hierarchy. The use of wildcard pattern _ on line 131 is a clean simplification since you're just returning the context without modification.


136-142: Improved error handling with simplified context response

Error handling now correctly uses ctx.request for logging and ctx.withResponse() to create a response context, which is more direct and consistent with the new context model. This approach removes unnecessary type checking while maintaining type safety through the sealed class hierarchy.

lib/src/handler/handler.dart (1)

61-61: Removed unnecessary type checking

The respondWith function now directly calls ctx.withResponse without runtime type checking. This simplification is made possible by the new context type hierarchy where the input context is expected to be a NewContext which guarantees the availability of the withResponse method.

test/util/test_util.dart (4)

6-6: Updated import to use public adapter API

The import has been changed from an internal implementation file to the new public io_adapter.dart. This is in line with the PR's goal of ensuring that code dependent on HttpServer from dart:io is only imported when explicitly requested by the user.


14-14: Updated SyncHandler typedef to match new Handler signature

The SyncHandler typedef has been updated to reflect the new Handler signature, accepting a NewContext and returning a HandledContext. This ensures consistency between the test utilities and the main codebase.


20-32: Simplified handler creation with direct context response

The createSyncHandler function has been updated to work with the new context types. It now directly calls ctx.withResponse() without type checking, which is more concise and aligns with the sealed class hierarchy where NewContext guarantees the availability of this method.


38-38: Updated asyncHandler signature for type consistency

The asyncHandler function has been updated to accept a NewContext and return a Future<HandledContext>, maintaining consistency with the synchronous handler and the updated Handler typedef.

lib/src/adapter/context.dart (3)

61-66: LGTM: Clean introduction of sealed class HandledContext

The addition of the sealed class HandledContext creates a clear type hierarchy for handled requests. This matches the PR's objective of restructuring the RequestContext class hierarchy.


68-69: LGTM: Updated ResponseContext inheritance

Changed ResponseContext to extend HandledContext rather than implementing it as an interface, consistent with the new type hierarchy. The class still correctly implements RespondableContext to maintain its interface contract.


79-79: LGTM: Updated HijackContext inheritance

The HijackContext is now a proper subclass of HandledContext, completing the context hierarchy refactoring described in the PR objectives.

Comment thread CHANGELOG.md Resolved
Comment thread lib/src/handler/handler.dart Resolved
@nielsenko
nielsenko force-pushed the serverpod-integration branch 3 times, most recently from 82d9a81 to 4ac1893 Compare May 23, 2025 04:38
nielsenko added 5 commits May 23, 2025 06:41
Also move io_serve.dart under adapter/io/, but export from lib/io_adapter.dart

Changes are related to serverpod integration.
@nielsenko
nielsenko force-pushed the serverpod-integration branch from 4ac1893 to b253b4f Compare May 23, 2025 04:41
@nielsenko
nielsenko requested a review from SandPod May 23, 2025 04:42
@nielsenko
nielsenko marked this pull request as ready for review May 23, 2025 04:42

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should maybe add a check for dart fix && dart apply to the CI pipe?

LGMT! 👍

@nielsenko
nielsenko merged commit cb8e1aa into main May 26, 2025
@nielsenko
nielsenko deleted the serverpod-integration branch May 26, 2025 05:27
@coderabbitai coderabbitai Bot mentioned this pull request Aug 22, 2025
7 tasks done
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