-
Notifications
You must be signed in to change notification settings - Fork 92
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
fix: remove ContextDelegation #283
Conversation
WalkthroughThe pull request introduces type-related changes across multiple files in the Changes
Sequence DiagramsequenceDiagram
participant Dev as Developer
participant Core as EggCore
participant Context as Context
participant Loader as ClassLoader
Dev->>Core: Initialize Application
Core->>Context: Create Context
Context->>Loader: Pass Context
Loader->>Loader: Instantiate with Generic Context
Loader-->>Dev: Return Configured Instance
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (23)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🔇 Additional comments (21)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
commit: |
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: npm/@types/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected] |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #283 +/- ##
==========================================
- Coverage 97.75% 97.74% -0.01%
==========================================
Files 10 10
Lines 3378 3376 -2
Branches 595 595
==========================================
- Hits 3302 3300 -2
Misses 76 76 ☔ View full report in Codecov by Sentry. |
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)
test/index.test.ts (1)
10-10
: Consider using a logger instead of console.log
Whileconsole.log
works, a dedicated logger would provide more structure and flexibility for debugging.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
package.json
(3 hunks)src/base_context_class.ts
(2 hunks)src/egg.ts
(2 hunks)src/loader/context_loader.ts
(2 hunks)src/loader/egg_loader.ts
(3 hunks)test/index.test.ts
(1 hunks)
🔇 Additional comments (20)
test/index.test.ts (1)
11-32
: Good addition verifying module keys
This assertion ensures that all expected exports are present onEggCore
.src/base_context_class.ts (3)
1-1
: Import statements look good
The new types being imported reflect the updated removal ofContextDelegation
, aligning well with the broader refactor.
8-12
: Generics enhance flexibility and type safety
UsingT extends Context
broadens the functionality for classes extending BaseContextClass. This is a good step toward more generic usage patterns.
Line range hint
17-37
: Consistency in constructor
The constructor properly setsctx
as well asservice
. The removal ofContextDelegation
references here is consistent with the new approach.src/loader/context_loader.ts (4)
4-4
: Switched to type import from 'egg.js'
ReplacingContextDelegation
withContext
is consistent with the goal of removingContextDelegation
references throughout.
9-9
: ClassLoaderOptions interface properly updated
Ensures thatctx
inClassLoaderOptions
is theContext
type, maintaining type consistency in loading contexts.
15-15
: Updating_ctx
toContext
This aligns with the removal ofContextDelegation
everywhere. Good to see uniform usage ofContext
.
101-101
: getInstance function aligned with the newContext
This ensures that instance creation leverages the updated context type.src/egg.ts (3)
44-44
: Re-exporting KoaMiddlewareFunc under its new type
The type re-export is appropriate and preserves backward compatibility for downstream code.
53-53
: Extending KoaResponse with generics
ReplacingKoaResponse
param withContext
is consistent with removingContextDelegation
.
66-66
: MiddlewareFunc updated to use the newContext
This simplification aligns with the overall refactor. Great job maintaining consistency across the codebase.src/loader/egg_loader.ts (5)
10-10
: Use ofKoaContext
is consistent with removal ofContextDelegation
.Good job replacing the direct
Context
import withKoaContext
from@eggjs/koa
. This aligns with the stated PR objective to removeContextDelegation
, ensuring all references now point to the updated Koa context type.
28-28
: Prototype change seems aligned with the Koa-based approach.Switching
context
toKoaContext.prototype
is a necessary step to ensure the updated Koa context is being used. This is a straightforward replacement and should not introduce functional issues, assuming the rest of the code is updated consistently.
1696-1696
: Context typing in class controller middleware.The
this: Context
type annotation for the class controller middleware clarifies thatthis
is bound to the request context, improving type safety for controller methods. Ensure the calling convention across your code does pass the correctContext
here to avoid runtime issues in certain edge cases.
1732-1732
: Object controller middleware typed withthis: Context
.Likewise, using
this: Context
in this asynchronous object controller middleware helps ensure correct references to the contextual properties. You might consider adding unit tests verifying these handlers to ensure future code refactors remain type-compliant.
18-20
: Verify external references toContextDelegation
.Since
ContextDelegation
is now replaced byContext
here, please confirm no remaining references toContextDelegation
exist in the codebase or in dependent modules (e.g.,egg.js
).Run the following script to detect references outside of the provided file:
✅ Verification successful
Based on the search results, I can see that there are no references to
ContextDelegation
in the codebase. The filesrc/loader/egg_loader.ts
shows that it's usingContext
type from the imports, and there are no other files containing any references toContextDelegation
.No remaining references to
ContextDelegation
found in the codebase.The change from
ContextDelegation
toContext
appears to be a clean replacement with no lingering references that need attention.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for any lingering references to `ContextDelegation` rg 'ContextDelegation'Length of output: 22
Script:
#!/bin/bash # Let's try a case-insensitive search and also look for potential variations rg -i "contextdeleg" # Also, let's check the egg.js file specifically since it was mentioned in the imports fd -e js -e ts "egg" --exec cat {}Length of output: 108417
package.json (4)
41-41
: Version bump for@eggjs/koa
.Upgrading to
^2.20.3
maintains compatibility with the newKoaContext
usage. Confirm that no breaking changes exist in the minor update.
[approve]
58-58
: Pinned version for@eggjs/bin
.Switching from
^7.0.0
to a pinned"7"
ensures a stable, predictable environment. This is helpful to avoid unplanned minor updates, but stay cautious about missing out on patches.
62-62
: Updated@types/node
to version 22.Using a higher version can unlock better type definitions, but verify local environment compatibility.
71-71
: Pinned version forpedding
.Pinning from
^2.0.0
to"2"
prevents unintentional version increments. Good for stability; just keep an eye out for any needed security patches.
[skip ci] ## [6.2.9](v6.2.8...v6.2.9) (2025-01-02) ### Bug Fixes * remove ContextDelegation ([#283](#283)) ([c56cf7b](c56cf7b))
Summary by CodeRabbit
Dependencies
@eggjs/koa
to version 2.20.3@eggjs/bin
to version 7@types/node
to version 22pedding
to version 2@eggjs/supertest
with version 8.1.1Type Improvements
BaseContextClass
Testing
EggCore
module propertiesrequest
andmm
modules across multiple test files