-
Notifications
You must be signed in to change notification settings - Fork 11
protocol: export ClientError and Status #113
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
📝 WalkthroughWalkthroughThe pull request introduces a prerelease configuration for the Changes
Possibly related PRs
Poem
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 (
|
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
🧹 Outside diff range and nitpick comments (3)
packages/protocol/src/client.ts (3)
Line range hint
29-32: Add JSDoc comments for StreamDataOptions interfaceThe 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 maintainabilityThe 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 debuggingThe 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
📒 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.
No description provided.