chore: integration example for tm websocket
Summary by CodeRabbit
-
New Features
- Introduced a new integration for CometBFT (Tendermint) event indexing, including block and transaction event handlers.
- Added a WebSocket client with automatic failover and reconnection for robust event streaming.
- Provided a sample usage script and comprehensive TypeScript type definitions for event handling.
-
Chores
- Added configuration files for environment variables, TypeScript, Jest, and npm packaging.
- Included a README with support and licensing information, and an Apache 2.0 license file.
-
Refactor
- Updated build configuration to exclude the new integrations directory from the main TypeScript build.
Walkthrough
A new integration module for CometBFT (Tendermint) event indexing was added under integrations/tm. This includes configuration files, TypeScript source code for handling and subscribing to block and transaction events, a logger, type definitions, an example usage script, and package metadata. The build configuration was also updated to exclude the integrations directory.
Changes
| File(s) | Change Summary |
|---|---|
| integrations/tm/.env.example | Added example environment variable file with LOG_LEVEL=info. |
| integrations/tm/.npmignore | Added .npmignore to include only built JS and type declaration files in npm package. |
| integrations/tm/LICENSE | Added Apache License 2.0 text. |
| integrations/tm/README.md | Added README with installation, support links, and license info. |
| integrations/tm/jest.config.js | Added Jest config extending base config and specifying TypeScript config for tests. |
| integrations/tm/package.json | Added package manifest with metadata, entry points, exports, scripts, and dependencies. |
| integrations/tm/tsconfig.json | Added TypeScript config targeting ES2020, module settings, and environment types. |
| integrations/tm/src/logger.ts | Added Winston logger setup, exporting configured logger based on environment variable. |
| integrations/tm/src/types.ts | Added TypeScript interfaces/types for CometBFT block and transaction events, message handlers. |
| integrations/tm/src/client/ws.ts | Added WebSocketClient class for robust connection/reconnection to multiple endpoints and message handling. |
| integrations/tm/src/client/handlers/blocks.ts | Added handleNewBlock async function to process new block events and log indexing activity. |
| integrations/tm/src/client/handlers/txs.ts | Added handleNewTx async function to process new transaction events and log indexing activity. |
| integrations/tm/src/client/indexer.ts | Added CometBFTIndexer class to manage event subscription, message dispatching, and handler invocation for block and transaction events. |
| integrations/tm/src/example.ts | Added example script instantiating indexer, subscribing to events, and setting up a periodic timer. |
| tsconfig.build.json | Updated to exclude the "integrations" directory from the build process. |
Sequence Diagram(s)
sequenceDiagram
participant ExampleScript
participant CometBFTIndexer
participant WebSocketClient
participant CometBFTNode
participant BlockHandler
participant TxHandler
ExampleScript->>CometBFTIndexer: new CometBFTIndexer(endpoints)
ExampleScript->>CometBFTIndexer: subscribe()
CometBFTIndexer->>WebSocketClient: send subscription for NewBlock and Tx
WebSocketClient->>CometBFTNode: Connect and subscribe
CometBFTNode-->>WebSocketClient: Event message (NewBlock or Tx)
WebSocketClient->>CometBFTIndexer: onMessage(msg)
CometBFTIndexer->>BlockHandler: handleNewBlock(data) (if NewBlock)
CometBFTIndexer->>TxHandler: handleNewTx(data) (if Tx)
Poem
🐇
New blocks and transactions, events in the air,
WebSockets connect with resilient flair.
Logging each moment, with Winston’s delight,
TypeScript ensures everything’s typed just right.
With configs and licenses, the groundwork is laid—
Hopping through code, integrations are made!
[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
🔧 ESLint
If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
integrations/tm/src/example.ts
Oops! Something went wrong! :(
ESLint: 7.32.0
Error: Error while loading rule 'jest/unbound-method': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser. Occurred while linting /integrations/tm/src/example.ts at throwError (/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:39:11) at getParserServices (/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:31:9) at create (/node_modules/@typescript-eslint/eslint-plugin/dist/rules/unbound-method.js:116:55) at Object.create (/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:38:20) at create (/node_modules/eslint-plugin-jest/lib/rules/unbound-method.js:47:88) at Object.create (/node_modules/eslint-plugin-jest/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:41:20) at createRuleListeners (/node_modules/eslint/lib/linter/linter.js:765:21) at /node_modules/eslint/lib/linter/linter.js:937:31 at Array.forEach (
) at runRules (/node_modules/eslint/lib/linter/linter.js:882:34) integrations/tm/jest.config.js
Oops! Something went wrong! :(
ESLint: 7.32.0
Error: Error while loading rule 'jest/unbound-method': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser. Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward "parserOptions.project" to @typescript-eslint/parser. Occurred while linting /integrations/tm/jest.config.js at throwError (/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:39:11) at getParserServices (/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:23:9) at create (/node_modules/@typescript-eslint/eslint-plugin/dist/rules/unbound-method.js:116:55) at Object.create (/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:38:20) at create (/node_modules/eslint-plugin-jest/lib/rules/unbound-method.js:47:88) at Object.create (/node_modules/eslint-plugin-jest/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:41:20) at createRuleListeners (/node_modules/eslint/lib/linter/linter.js:765:21) at /node_modules/eslint/lib/linter/linter.js:937:31 at Array.forEach (
) at runRules (/node_modules/eslint/lib/linter/linter.js:882:34) integrations/tm/src/logger.ts
Oops! Something went wrong! :(
ESLint: 7.32.0
Error: Error while loading rule 'jest/unbound-method': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser. Occurred while linting /integrations/tm/src/logger.ts at throwError (/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:39:11) at getParserServices (/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:31:9) at create (/node_modules/@typescript-eslint/eslint-plugin/dist/rules/unbound-method.js:116:55) at Object.create (/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:38:20) at create (/node_modules/eslint-plugin-jest/lib/rules/unbound-method.js:47:88) at Object.create (/node_modules/eslint-plugin-jest/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:41:20) at createRuleListeners (/node_modules/eslint/lib/linter/linter.js:765:21) at /node_modules/eslint/lib/linter/linter.js:937:31 at Array.forEach (
) at runRules (/node_modules/eslint/lib/linter/linter.js:882:34)
- 5 others
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
🪧 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
@coderabbitaiin 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
@coderabbitaiin 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.
-
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
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 pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.