Skip to content
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: export createAnonymousContext define #5388

Merged
merged 1 commit into from
Feb 2, 2025
Merged

fix: export createAnonymousContext define #5388

merged 1 commit into from
Feb 2, 2025

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Feb 2, 2025

Summary by CodeRabbit

  • New Features

    • Enabled dynamic reading and updating of the response status via the context interface.
    • Consolidated asynchronous execution by introducing a unified method for running operations within a controlled context.
  • Tests

    • Strengthened type validations to ensure consistent and reliable context management.

Copy link

coderabbitai bot commented Feb 2, 2025

Walkthrough

The changes update how application contexts handle a response’s realStatus. The commit adds a getter and setter for the realStatus property in the Context interface, enabling direct access through the response object. Additionally, the method runInAnonymousContextScope was removed from the Application class and reintroduced in the EggApplicationCore class with an updated signature and export in the EggCore interface. Test definitions were also updated to reflect these changes by shifting from Application to EggCore and including explicit type checks for realStatus.

Changes

File(s) Change Summary
src/app/extend/context.ts Added a getter (get realStatus(): number) and setter (set realStatus(val: number)) in the Context interface to manage the response’s realStatus property.
src/lib/application.ts
src/lib/egg.ts
Removed runInAnonymousContextScope from the Application class and added it to the EggApplicationCore class with updated logic and exported createAnonymousContext in EggCore.
test/index.test-d.ts Updated type definitions by changing the app type from Application to EggCore and added type expectations for ctx.realStatus and its assignment.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant EggAppCore as EggApplicationCore
    participant ContextCreator as createAnonymousContext
    participant Storage as ctxStorage

    Caller->>EggAppCore: runInAnonymousContextScope(scope, req)
    EggAppCore->>ContextCreator: createAnonymousContext(req)
    ContextCreator-->>EggAppCore: Return ctx
    EggAppCore->>Storage: run(ctx, async callback)
    Storage-->>EggAppCore: Execute scope within ctx
    EggAppCore-->>Caller: Return result
Loading

Possibly related PRs

Poem

I'm a little rabbit hopping through the code,
With getters and setters lightening my load.
Anonymous scopes let my functions play,
In contexts where carrots (and numbers) hold sway.
Code and hops in synchrony, hooray! 🥕🐇


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2959d79 and 17fbb4e.

📒 Files selected for processing (4)
  • src/app/extend/context.ts (1 hunks)
  • src/lib/application.ts (0 hunks)
  • src/lib/egg.ts (3 hunks)
  • test/index.test-d.ts (3 hunks)
💤 Files with no reviewable changes (1)
  • src/lib/application.ts
🧰 Additional context used
🪛 Biome (1.9.4)
test/index.test-d.ts

[error] 25-25: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: Node.js / Test (windows-latest, 22)
  • GitHub Check: Node.js / Test (ubuntu-latest, 22)
  • GitHub Check: Node.js / Test (windows-latest, 20)
  • GitHub Check: Node.js / Test (windows-latest, 18)
  • GitHub Check: Node.js / Test (ubuntu-latest, 22)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18)
  • GitHub Check: Node.js / Test (macos-latest, 22)
  • GitHub Check: Node.js / Test (windows-latest, 20)
  • GitHub Check: Node.js / Test (macos-latest, 20)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20)
  • GitHub Check: Node.js / Test (macos-latest, 18)
  • GitHub Check: Node.js / Test (windows-latest, 20)
  • GitHub Check: Node.js / Test (windows-latest, 18)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20)
  • GitHub Check: Node.js / Test (windows-latest, 18)
  • GitHub Check: Node.js / Test (windows-latest, 20)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18)
🔇 Additional comments (7)
test/index.test-d.ts (3)

2-2: LGTM!

The import change aligns with the shift to use EggCore and Context from @eggjs/core.


14-14: LGTM!

The app type change from Application to EggCore is consistent with the import change.


24-25: LGTM!

The type expectations for realStatus property correctly validate:

  • The property type as number
  • The assignment of a number value
🧰 Tools
🪛 Biome (1.9.4)

[error] 25-25: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

src/app/extend/context.ts (1)

321-322: LGTM!

The realStatus getter and setter are properly implemented:

  • Correctly typed as number
  • Properly delegate to the response object
  • Consistent with the type expectations in test/index.test-d.ts
src/lib/egg.ts (3)

18-18: LGTM!

The utils import from @eggjs/core is properly added and used for getting the callee from stack.


645-659: LGTM!

The runInAnonymousContextScope method is well-implemented:

  • Creates an anonymous context with optional request data
  • Sets the function name using the callee from stack if not defined
  • Properly runs the function within the context's storage

697-698: LGTM!

The interface exports properly expose:

  • createAnonymousContext method
  • runInAnonymousContextScope method
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

Copy link

codecov bot commented Feb 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.96%. Comparing base (b223c7a) to head (17fbb4e).
Report is 2 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5388      +/-   ##
==========================================
- Coverage   94.93%   92.96%   -1.98%     
==========================================
  Files          40       40              
  Lines        3734     3739       +5     
  Branches      354      336      -18     
==========================================
- Hits         3545     3476      -69     
- Misses        189      263      +74     

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

@fengmk2 fengmk2 merged commit 5d15623 into next Feb 2, 2025
32 of 34 checks passed
@fengmk2 fengmk2 deleted the fix-define branch February 2, 2025 15:37
fengmk2 pushed a commit that referenced this pull request Feb 2, 2025
[skip ci]

## [4.0.4](v4.0.3...v4.0.4) (2025-02-02)

### Bug Fixes

* export createAnonymousContext define ([#5388](#5388)) ([5d15623](5d15623))
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.

1 participant