-
Notifications
You must be signed in to change notification settings - Fork 8
feat: Add injectAt extension method on Router<T> #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughA new public method Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Router
participant Sub-Router
participant Handler
Client->>Router: injectAt('/api', handler)
Router->>Router: group('/api')
activate Router
Note over Router: Creates or reuses sub-router
deactivate Router
Router->>Sub-Router: inject(handler)
activate Sub-Router
Note over Sub-Router: Injects handler into sub-router
deactivate Sub-Router
Client->>Router: GET /api/echo
Router->>Sub-Router: Route to /echo
Sub-Router->>Handler: Handle request
Handler->>Sub-Router: Response
Sub-Router->>Router: Response
Router->>Client: 200 OK
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #261 +/- ##
=======================================
Coverage 91.48% 91.48%
=======================================
Files 89 89
Lines 3475 3477 +2
Branches 1769 1770 +1
=======================================
+ Hits 3179 3181 +2
Misses 296 296 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
lib/src/router/router.dart (1)
236-238: Consider enhancing the documentation with examples and context.The implementation is correct and follows the intended pattern of chaining
group(path).inject(injectable). However, the doc comment could be more helpful by including an example showing the equivalence to the explicit approach and clarifying behavior (e.g., that it creates a sub-router at the path if one doesn't exist).For consistency with other methods in this file (e.g.,
use,attach), consider expanding the documentation:- /// Injects [injectable] at [path] + /// Injects [injectable] at [path]. + /// + /// This is a convenience method equivalent to calling `group(path).inject(injectable)`. + /// The [path] string defines the route prefix where the injectable will be mounted. + /// + /// Example: + /// ```dart + /// final router = RelicRouter(); + /// router.injectAt('/api', userModule); + /// // Equivalent to: + /// // router.group('/api').inject(userModule); + /// ``` void injectAt(final String path, final InjectableIn<Router<T>> injectable) => group(path).inject(injectable);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
lib/src/router/router.dart(1 hunks)test/router/router_inject_test.dart(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.dart
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.dart: All Dart code must pass static analysis usingdart analyze --fatal-infoswith no issues
All Dart files must be formatted withdart format(CI enforcesdart format --set-exit-if-changed .)
Files:
lib/src/router/router.darttest/router/router_inject_test.dart
lib/**/*.dart
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
lib/**/*.dart: Use Uint8List for request/response bodies for performance; avoid List for body payloads
Use type-safe HTTP header parsing and validation when accessing headers
Use router with trie-based matching and symbol-based path parameters (e.g.,#name,#age) for routing
Ensure WebSocket handling includes proper lifecycle management (e.g., ping/pong for connection health)
Files:
lib/src/router/router.dart
test/**/*.dart
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
test/**/*.dart: Tests should follow the Given-When-Then pattern in descriptions (flexible structuring allowed)
Use Arrange-Act-Assert pattern within test bodies
Provide clear, descriptive test titles; prefer single responsibility per test unless related assertions improve clarity
Place tests in thetest/directory mirroring thelib/structure
Files:
test/router/router_inject_test.dart
🧠 Learnings (3)
📓 Common learnings
Learnt from: nielsenko
Repo: serverpod/relic PR: 48
File: lib/src/handler/handler.dart:59-67
Timestamp: 2025-04-25T07:39:38.915Z
Learning: Nielsenko prefers using switch statements with pattern matching over if statements when working with sealed classes in Dart, as they provide exhaustiveness checking at compile time and can be more concise.
📚 Learning: 2025-10-09T16:21:09.310Z
Learnt from: CR
Repo: serverpod/relic PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-09T16:21:09.310Z
Learning: Applies to lib/**/*.dart : Use router with trie-based matching and symbol-based path parameters (e.g., `#name`, `#age`) for routing
Applied to files:
lib/src/router/router.darttest/router/router_inject_test.dart
📚 Learning: 2025-05-05T14:40:00.323Z
Learnt from: nielsenko
Repo: serverpod/relic PR: 52
File: lib/src/router/router.dart:37-53
Timestamp: 2025-05-05T14:40:00.323Z
Learning: In the Router and PathTrie implementation in Dart, both static and dynamic routes consistently throw ArgumentError when attempting to add duplicate routes, despite comments suggesting dynamic routes would be overwritten with a warning.
Applied to files:
test/router/router_inject_test.dart
⏰ 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). (6)
- GitHub Check: Run Unit Tests (macos-latest, beta, downgrade)
- GitHub Check: Run Unit Tests (macos-latest, beta, upgrade)
- GitHub Check: Run Unit Tests (macos-latest, stable, upgrade)
- GitHub Check: Run Unit Tests (macos-latest, 3.7.0, upgrade)
- GitHub Check: Run Unit Tests (macos-latest, 3.7.0, downgrade)
- GitHub Check: Run Unit Tests (macos-latest, stable, downgrade)
🔇 Additional comments (1)
test/router/router_inject_test.dart (1)
46-64: LGTM! Test structure and coverage are solid.The test correctly validates the
injectAtfunctionality:
- Follows the Given-When-Then pattern as per coding guidelines
- Uses Arrange-Act-Assert structure in the test body
- Clear, descriptive test title
- Properly verifies that
injectAt('/api', handler)mounts the handler at the combined path/api/echo
SandPod
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Description
Adds a convenience method
injectAt()toRouterfor injecting injectables at a specific path. This is a shorthand for callinggroup(path).inject(injectable).Related Issues
Pre-Launch Checklist
///), ensuring consistency with existing project documentation.Breaking Changes
Additional Notes
None.
Summary by CodeRabbit
New Features
injectAt()for mounting handlers at specific base paths, enabling more flexible nested routing structures and modular application architecture.Tests