Skip to content

Conversation

@fracek
Copy link
Contributor

@fracek fracek commented Nov 6, 2024

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented Nov 6, 2024

📝 Walkthrough

Walkthrough

The pull request introduces a prerelease configuration for the @apibara/protocol package, updating its public API by exporting the ClientError and Status entities. Additionally, it modifies the Client interface to include a new method streamData, which utilizes a newly defined StreamDataOptions interface. A new class, StreamDataIterable, is added to facilitate asynchronous data streaming, enhancing the control flow while maintaining existing functionality.

Changes

File Path Change Summary
change/@apibara-protocol-42597b08... Introduced prerelease configuration; exported ClientError and Status entities.
packages/protocol/src/client.ts Added export for ClientError and Status; updated Client interface with streamData method; defined StreamDataOptions; introduced StreamDataIterable class for streaming data.

Possibly related PRs

  • protocol: make client options configurable #108: The changes in this PR also modify the createClient function in packages/protocol/src/client.ts, which is relevant to the main PR's updates to the same function, indicating a direct connection in the codebase.

Poem

🐇 In the meadow where data flows,
A new stream of options now brightly glows.
With ClientError and Status in sight,
Our protocol dances, oh what a delight!
Hopping through code, we celebrate cheer,
For every new feature brings us all near! 🌼


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

@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: 0

🧹 Outside diff range and nitpick comments (3)
packages/protocol/src/client.ts (3)

Line range hint 29-32: Add JSDoc comments for StreamDataOptions interface

The interface is well-designed, but could benefit from additional documentation explaining the endingCursor behavior.

 export interface StreamDataOptions extends ClientCallOptions {
-  /** Stop at the specified cursor (inclusive) */
+  /**
+   * When specified, the stream will stop after processing the message at this cursor (inclusive).
+   * The cursor is matched based on orderKey and optionally uniqueKey.
+   */
   endingCursor?: Cursor;
 }

Line range hint 124-141: Extract cursor comparison logic for better maintainability

The cursor comparison logic in the next() method could be extracted into a separate method for better readability and maintainability.

 export class StreamDataIterable<TBlock> {
+  private shouldStopAtCursor(
+    endingCursor: Cursor,
+    messageCursor: { orderKey: string; uniqueKey?: string }
+  ): boolean {
+    if (endingCursor.orderKey !== messageCursor.orderKey) {
+      return false;
+    }
+    return !endingCursor.uniqueKey || endingCursor.uniqueKey === messageCursor.uniqueKey;
+  }
+
   [Symbol.asyncIterator](): AsyncIterator<StreamDataResponse<TBlock>> {
     // ... existing code ...
     
     if (endingCursor) {
       assert(value.message.$case === "data");
       assert(decodedMessage._tag === "data");
       
-      const { orderKey, uniqueKey } = endingCursor;
       const endCursor = decodedMessage.data.endCursor;
-      if (orderKey === endCursor?.orderKey) {
-        if (!uniqueKey || uniqueKey === endCursor.uniqueKey) {
-          shouldStop = true;
-          return { done: false, value: decodedMessage };
-        }
+      if (endCursor && this.shouldStopAtCursor(endingCursor, endCursor)) {
+        shouldStop = true;
+        return { done: false, value: decodedMessage };
       }
     }

Line range hint 119-120: Improve assertion messages for better debugging

The type assertions would benefit from more descriptive error messages to aid in debugging.

-          assert(value.message.$case === "data");
-          assert(decodedMessage._tag === "data");
+          assert(value.message.$case === "data", "Expected a data message for cursor comparison");
+          assert(decodedMessage._tag === "data", "Expected a decoded data message for cursor comparison");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 18c0ce7 and b0292cf.

📒 Files selected for processing (2)
  • change/@apibara-protocol-42597b08-e136-432f-a70c-25ba0ba86244.json (1 hunks)
  • packages/protocol/src/client.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • change/@apibara-protocol-42597b08-e136-432f-a70c-25ba0ba86244.json
🔇 Additional comments (1)
packages/protocol/src/client.ts (1)

24-24: LGTM: Type exports align with PR objectives

The export of ClientError and Status types from nice-grpc is correctly implemented, making these essential types available to package consumers.

@fracek fracek merged commit eba73eb into apibara:main Nov 6, 2024
2 checks passed
@fracek fracek deleted the export-client-error branch November 6, 2024 20:30
@coderabbitai coderabbitai bot mentioned this pull request Mar 21, 2025
4 tasks
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