Skip to content

chore: qol improvements and fixes #160

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

Merged
merged 10 commits into from
Mar 21, 2025

Conversation

jaipaljadeja
Copy link
Member

@jaipaljadeja jaipaljadeja commented Mar 20, 2025

  • internal indexer related tables would go in separate pg schema
  • bump consola package to fix proper console of error cause traces
  • improve runtimeConfiguration and production builds
  • set authentication token based on the DNA_TOKEN environment variable

Copy link

coderabbitai bot commented Mar 20, 2025

📝 Walkthrough

Walkthrough

This pull request introduces several new JSON metadata files for prerelease changes across various packages, along with dependency upgrades for the “consola” package in multiple package manifests. Configuration files, environment examples, and indexer implementations have been updated to streamline connection handling and runtime configuration management. The CLI tooling has been refactored to support an authenticated client creation flow with enhanced error checking and logging. Additionally, database schema definitions for the drizzle persistence layer have been restructured, and some legacy helper functions have been removed.

Changes

Files Change Summary
change/@apibara-indexer-*.json, change/@apibara-plugin-drizzle-*.json, change/@apibara-protocol-*.json, change/apibara-*.json, change/@apibara-plugin-mongo-*.json Added new JSON files that define prerelease metadata, package details, comments (e.g., upgrade to consola), email contacts, and a dependent change type set to patch.
examples/beaconchain-client/package.json, examples/evm-client/package.json, examples/starknet-client/package.json, packages/cli/package.json, packages/indexer/package.json Upgraded the version of the consola dependency from ^3.2.3 to ^3.4.2.
examples/cli-drizzle/.env.example, examples/cli-drizzle/apibara.config.ts Updated environment configuration: added new variables (APIBARA_RUNTIME_CONFIG, DNA_TOKEN), modified startingBlock values, and removed connectionString and presets from config.
examples/cli-drizzle/indexers/1-evm.indexer.ts, examples/cli-drizzle/indexers/2-starknet.indexer.ts Removed destructuring of connectionString and enforced explicit conversion of startingBlock to BigInt; added filtering logic for transaction hashes in the Starknet indexer.
examples/cli-drizzle/test/ethereum.test.ts, examples/cli-drizzle/test/starknet.test.ts Removed the connectionString variable and changed startingBlock representations from BigInt literals to numeric literals in test invocations.
packages/cli/src/cli/commands/dev.ts, packages/cli/src/cli/commands/start.ts Enhanced child process event handling by updating function signatures and logging exit statuses with colorized output.
packages/cli/src/core/config/*, packages/cli/src/hooks/useRuntimeConfig.ts, packages/cli/src/rolldown/* Streamlined configuration resolution and serialization: reduced resolvers, added runtimeConfig error handling, replaced custom (de)serialization with standard JSON methods, and removed unused files.
packages/cli/src/runtime/dev.ts, packages/cli/src/runtime/internal/app.ts, packages/cli/src/runtime/start.ts, packages/cli/src/runtime/internal/helper.ts Refactored client creation: replaced createClient with createAuthenticatedClient, added a new authentication flow, and introduced getProcessedRuntimeConfig to consolidate runtime configurations.
packages/cli/src/utils/helper.ts Removed legacy helper functions (deserialize and serialize) for handling BigInt values.
packages/plugin-drizzle/src/constants.ts, packages/plugin-drizzle/src/helper.ts, packages/plugin-drizzle/src/persistence.ts, packages/plugin-drizzle/src/storage.ts Updated plugin-drizzle: added a new SCHEMA_NAME constant, modified default connectionString behavior to read from the environment, and restructured table definitions to use schema-qualified names with simplified table names.
packages/protocol/src/client.ts Modified the export statement to include Metadata alongside ClientError and Status from the nice-grpc package.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant S as startCommand (CLI)
    participant A as createAuthenticatedClient
    participant H as getProcessedRuntimeConfig
    participant C as createClient (protocol)

    U->>S: Invoke start command
    S->>A: Call createAuthenticatedClient with config & streamUrl
    A->>H: Process runtime configuration
    H-->>A: Return merged runtimeConfig
    A->>A: Check for DNA_TOKEN in env
    A->>C: Call createClient with Authorization header
    C-->>A: Return authenticated client instance
    A-->>S: Return client instance to CLI
Loading

Possibly related PRs

  • Fix build if indexer has no exports #151: The changes in the main PR involve adding a new JSON file for the @apibara/indexer package, which is related to the changes in the retrieved PR that also introduces a new JSON file for the apibara package, as both pertain to metadata for prerelease versions.
  • indexer: add hooks for each message type #112: The changes in the main PR involve adding a new JSON file for the @apibara/indexer package, which is related to the retrieved PR that also introduces a new JSON file for the same package, indicating a prerelease with different comments.
  • Add startingBlock option #138: The changes in the main PR involve adding a new JSON file for the @apibara/indexer package, which is related to the retrieved PR that also introduces a new configuration for the @apibara/indexer package, specifically regarding the startingBlock option.

Suggested reviewers

  • fracek

Poem

I'm a little bunny with code so spry,
Hopping through changes under the sky.
JSON files new and configs refined,
With schemas and clients all perfectly aligned.
Cheers to updates, a joyful delight –
May our code run smooth both day and night!
🐰🌟


📜 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 5d5407e and 625b1cd.

📒 Files selected for processing (4)
  • change/@apibara-plugin-mongo-63eb6fa1-cb73-4c3d-a9a2-d1eda15c982c.json (1 hunks)
  • examples/cli-drizzle/package.json (1 hunks)
  • packages/cli/src/core/config/loader.ts (1 hunks)
  • packages/plugin-mongo/src/mongo.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • change/@apibara-plugin-mongo-63eb6fa1-cb73-4c3d-a9a2-d1eda15c982c.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • examples/cli-drizzle/package.json
  • packages/cli/src/core/config/loader.ts
🧰 Additional context used
🧬 Code Definitions (1)
packages/plugin-mongo/src/mongo.ts (1)
packages/plugin-mongo/src/storage.ts (1) (1)
  • collection (32-43)
🔇 Additional comments (1)
packages/plugin-mongo/src/mongo.ts (1)

63-65: Improved error handling with error cause chaining.

This change enhances error transparency by utilizing the Error constructor's cause property instead of message concatenation. This allows preservation of the original error context (including stack traces) and better error debugging, especially when working with the updated consola package mentioned in the PR objectives.

✨ 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 @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.
  • @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.

@jaipaljadeja jaipaljadeja force-pushed the feat/qol-improvements-fixes branch from 70188d0 to 657f08f Compare March 20, 2025 17:12
@jaipaljadeja jaipaljadeja force-pushed the feat/qol-improvements-fixes branch from 7e5af17 to 5d5407e Compare March 21, 2025 10:24
@jaipaljadeja jaipaljadeja marked this pull request as ready for review March 21, 2025 10:27
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: 1

🧹 Nitpick comments (2)
change/@apibara-plugin-drizzle-8378f0ae-ad6a-4f2d-bf17-777c9e20e4b1.json (1)

3-3: Minor typo in comment

There's a small typo in the comment.

-  "comment": "plugin-drizzle: use seperate schema and default connectionString to env",
+  "comment": "plugin-drizzle: use separate schema and default connectionString to env",
packages/cli/src/runtime/internal/helper.ts (1)

1-55: Well-structured configuration handler with clear priority logic

This new utility function properly merges runtime configurations from multiple sources with a clear priority order (env vars > presets > defaults). The error handling is robust and includes helpful error messages with proper cause chaining.

One suggestion to improve robustness:

 export function getProcessedRuntimeConfig({
   preset,
   presets,
   runtimeConfig,
 }: {
   preset?: string;
   presets?: Record<string, unknown>;
   runtimeConfig?: Record<string, unknown>;
+}) {
-}) {
+  // Ensure runtimeConfig is always an object
+  runtimeConfig = runtimeConfig || {};
   let _runtimeConfig: Record<string, unknown> = { ...runtimeConfig };
   const envRuntimeConfig = process.env.APIBARA_RUNTIME_CONFIG;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a04692e and 5d5407e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (34)
  • change/@apibara-indexer-3f5398ba-95bd-4752-abed-e779ea496399.json (1 hunks)
  • change/@apibara-plugin-drizzle-8378f0ae-ad6a-4f2d-bf17-777c9e20e4b1.json (1 hunks)
  • change/@apibara-protocol-a188449c-6a23-4c55-8e4b-1eebcb28f947.json (1 hunks)
  • change/apibara-d3198897-bb32-4e69-a1de-117791352c44.json (1 hunks)
  • examples/beaconchain-client/package.json (1 hunks)
  • examples/cli-drizzle/.env.example (1 hunks)
  • examples/cli-drizzle/apibara.config.ts (1 hunks)
  • examples/cli-drizzle/indexers/1-evm.indexer.ts (1 hunks)
  • examples/cli-drizzle/indexers/2-starknet.indexer.ts (2 hunks)
  • examples/cli-drizzle/package.json (1 hunks)
  • examples/cli-drizzle/test/ethereum.test.ts (1 hunks)
  • examples/cli-drizzle/test/starknet.test.ts (1 hunks)
  • examples/evm-client/package.json (1 hunks)
  • examples/starknet-client/package.json (1 hunks)
  • packages/cli/package.json (1 hunks)
  • packages/cli/src/cli/commands/dev.ts (1 hunks)
  • packages/cli/src/cli/commands/start.ts (2 hunks)
  • packages/cli/src/core/config/loader.ts (1 hunks)
  • packages/cli/src/core/config/resolvers/preset.resolver.ts (1 hunks)
  • packages/cli/src/core/config/resolvers/runtime-config.resolver.ts (0 hunks)
  • packages/cli/src/hooks/useRuntimeConfig.ts (1 hunks)
  • packages/cli/src/rolldown/config.ts (1 hunks)
  • packages/cli/src/rolldown/plugins/config.ts (1 hunks)
  • packages/cli/src/runtime/dev.ts (2 hunks)
  • packages/cli/src/runtime/internal/app.ts (2 hunks)
  • packages/cli/src/runtime/internal/helper.ts (1 hunks)
  • packages/cli/src/runtime/start.ts (2 hunks)
  • packages/cli/src/utils/helper.ts (0 hunks)
  • packages/indexer/package.json (1 hunks)
  • packages/plugin-drizzle/src/constants.ts (1 hunks)
  • packages/plugin-drizzle/src/helper.ts (3 hunks)
  • packages/plugin-drizzle/src/persistence.ts (4 hunks)
  • packages/plugin-drizzle/src/storage.ts (9 hunks)
  • packages/protocol/src/client.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/cli/src/core/config/resolvers/runtime-config.resolver.ts
  • packages/cli/src/utils/helper.ts
🧰 Additional context used
🧬 Code Definitions (5)
packages/cli/src/runtime/dev.ts (1)
packages/cli/src/runtime/internal/app.ts (1) (1)
  • createAuthenticatedClient (94-116)
packages/cli/src/runtime/start.ts (1)
packages/cli/src/runtime/internal/app.ts (1) (1)
  • createAuthenticatedClient (94-116)
packages/plugin-drizzle/src/storage.ts (1)
packages/plugin-drizzle/src/constants.ts (1) (1)
  • SCHEMA_NAME (3-3)
packages/cli/src/runtime/internal/app.ts (4)
packages/cli/src/types/virtual/indexers.d.ts (1) (1)
  • indexers (10-13)
packages/cli/src/runtime/internal/helper.ts (1) (1)
  • getProcessedRuntimeConfig (10-55)
packages/cli/src/types/virtual/config.d.ts (1) (1)
  • config (3-6)
packages/protocol/src/client.ts (2) (2)
  • CreateClientOptions (62-68)
  • createClient (71-89)
packages/plugin-drizzle/src/persistence.ts (1)
packages/plugin-drizzle/src/constants.ts (1) (1)
  • SCHEMA_NAME (3-3)
🔇 Additional comments (70)
examples/beaconchain-client/package.json (1)

16-16: Updated "consola" Dependency Version:
The "consola" dependency has been upgraded to "^3.4.2", which brings it in line with similar updates across the project. Please verify that this new version does not introduce any breaking changes for logging or error handling in the client.

packages/indexer/package.json (1)

76-76: Ensure Consistency with "consola" Upgrade:
The "consola" dependency is now set to "^3.4.2". This update is consistent with other parts of the codebase. Please review the release notes to confirm that there are no incompatible changes that would affect the indexer functionality.

change/@apibara-indexer-3f5398ba-95bd-4752-abed-e779ea496399.json (1)

1-7: Metadata File for Pre-release Update:
This new JSON file correctly documents the prerelease change related to the "consola" upgrade for the "@apibara/indexer" package. Please double-check that the contact email ("[email protected]") is accurate for release notifications.

examples/evm-client/package.json (1)

16-16: Consistent "consola" Version Across Examples:
The "consola" dependency in the EVM client has been updated to "^3.4.2". This change aligns with other example packages. It is recommended to review documentation for any behavioral changes between versions "^3.2.3" and "^3.4.2".

examples/starknet-client/package.json (1)

16-16: "consola" Version Upgrade Verification:
The update to "^3.4.2" for the "consola" dependency in the Starknet client ensures uniformity with the project's dependency versions. Please verify via the release notes that the new version meets all logging and error display expectations.

packages/cli/package.json (1)

99-99: Dependency update for consola looks good.

This update from version ^3.2.3 to ^3.4.2 aligns with the PR objectives to address issues related to proper console output of error cause traces.

packages/cli/src/cli/commands/start.ts (3)

4-4: Good addition of colors utility.

Importing the colors utility from consola will help improve error message formatting.


59-62: Proper child process reference.

Good change to capture the spawned process in a variable, which allows for proper event handling.


63-71: Improved error handling and exit code propagation.

This enhancement properly handles process termination with improved user feedback by:

  1. Displaying a clear exit message
  2. Using color highlighting for error codes
  3. Ensuring the parent process exits with the same code as the child process

This change improves developer experience when running indexers.

packages/protocol/src/client.ts (1)

24-24: Added Metadata export supports authentication improvements.

Exporting the Metadata class from nice-grpc enables the authentication token improvements mentioned in the PR objectives. This will allow passing authentication tokens and other metadata in gRPC calls.

packages/plugin-drizzle/src/constants.ts (1)

3-3: Good addition of schema constant.

Adding the SCHEMA_NAME constant directly supports the PR objective of organizing indexer-related tables into a separate PostgreSQL schema. Using a named constant ensures consistency across the codebase and makes future changes easier.

packages/cli/src/core/config/resolvers/preset.resolver.ts (1)

4-6: Added clarification comment is helpful.

The added comment clearly documents that this resolver is not currently in use, which is valuable information for developers working with the codebase. This aligns with the PR objective of improving quality of life for developers.

change/@apibara-protocol-a188449c-6a23-4c55-8e4b-1eebcb28f947.json (1)

1-7: New prerelease metadata looks good.

This new JSON file properly defines the prerelease metadata for exporting the nice-grpc MetaData class from the @apibara/protocol package. The format is correct and includes all necessary fields for version management.

change/apibara-d3198897-bb32-4e69-a1de-117791352c44.json (1)

1-7: New prerelease metadata correctly tracks CLI improvements.

This JSON file properly documents the prerelease changes related to adding the createAuthenticatedClient function and improving runtimeConfig, which aligns with the PR objective of streamlining the authentication process mentioned in the PR summary.

packages/cli/src/hooks/useRuntimeConfig.ts (1)

4-4: Simplified runtime config retrieval.

The implementation has been improved by:

  1. Replacing a custom deserialize function with standard JSON.parse
  2. Using the new environment variable APIBARA_RUNTIME_CONFIG_HOOK_DATA which is set by the new createAuthenticatedClient function

This change aligns with the PR objectives of enhancing runtime configuration and improving codebase functionality.

examples/cli-drizzle/test/starknet.test.ts (1)

14-15: Good change to standardize numeric representation

Removing the BigInt literals (n suffix) aligns with the broader refactoring effort to simplify configuration handling across the codebase. The change maintains consistency as the test still uses BigInt literals for fromBlock and toBlock parameters.

packages/cli/src/rolldown/plugins/config.ts (1)

14-14: Simplification of configuration parsing

Replacing the custom deserialize function with standard JSON.parse improves code maintainability and aligns with the runtime configuration enhancements mentioned in the PR objectives. This change standardizes configuration parsing across the codebase.

Be aware that if any configurations previously contained strings with 'n' suffix to represent BigInt values, they would need to be updated as they will no longer be automatically converted to BigInt objects.

change/@apibara-plugin-drizzle-8378f0ae-ad6a-4f2d-bf17-777c9e20e4b1.json (1)

1-7: Well-structured change entry for plugin-drizzle

This change entry correctly documents the modifications to the plugin-drizzle package, which now uses a separate schema for indexer-related tables and sources the connection string from environment variables. This aligns with the PR objective of organizing internal indexer-related tables in a separate PostgreSQL schema.

examples/cli-drizzle/.env.example (2)

2-7: Clear and helpful configuration documentation

The comments provide excellent documentation on the configuration priority order, making it clear how the different configuration sources are merged. This enhances developer experience by making the system behavior more predictable.


7-8: Good implementation of runtime config and authentication

These new environment variables align perfectly with the PR objectives:

  1. APIBARA_RUNTIME_CONFIG supports the runtime configuration enhancements
  2. DNA_TOKEN implements the authentication token setting as mentioned in the PR description

The JSON structure in APIBARA_RUNTIME_CONFIG matches the changes in the test files where BigInt notation was removed.

packages/cli/src/runtime/dev.ts (2)

3-7: Authentication integration improves connection security

The import statement has been updated to include createAuthenticatedClient from the internal app module, which now handles authentication through environment variables.


47-50: Successfully implemented token-based authentication

The client creation now uses createAuthenticatedClient instead of directly using createClient. This change aligns with the PR objective of streamlining authentication by leveraging the DNA_TOKEN environment variable.

packages/cli/src/cli/commands/dev.ts (1)

121-129: Improved process exit handling

The handler now properly captures both exit code and signal parameters, adds a visual separator with a blank line, and ensures the process exits with the appropriate status code. This is a good improvement for developer experience.

Good practice to use the nullish coalescing operator (??) to default to exit code 0 when the code is null.

examples/cli-drizzle/package.json (1)

11-11: Added convenient PostgreSQL configuration script

This new start:pg script provides an easy way to launch the application with a predefined PostgreSQL connection and runtime configuration. It aligns with the PR objective of organizing indexer-related tables in a separate PostgreSQL schema.

The script effectively demonstrates how to configure both the database connection and runtime parameters via environment variables, which is valuable for documentation purposes.

packages/cli/src/rolldown/config.ts (2)

99-103: Simplified serialization of runtime config

The code now uses standard JSON.stringify instead of a custom serialization function, which improves maintainability and reduces complexity.


105-108: Improved error message clarity

The error message has been simplified to clearly communicate that all values in the runtime configuration must be JSON serializable, making it more straightforward for developers to understand and fix serialization issues.

packages/cli/src/runtime/start.ts (2)

5-5: Good update to use authenticated client

The change to import createAuthenticatedClient aligns with the PR objective of setting authentication tokens based on the DNA_TOKEN environment variable.


32-35: Improved security with authenticated client connection

Replacing createClient with createAuthenticatedClient ensures proper authentication when connecting to the stream service. This implementation maintains backward compatibility by falling back to unauthenticated connections when no token is present.

packages/cli/src/core/config/loader.ts (2)

11-11: Simplified configuration resolver list

The configuration resolver list has been streamlined to only include resolvePathOptions. This simplification suggests that runtime configuration handling has been refactored elsewhere.


20-27: Good addition of runtime config validation

Adding validation for serializable runtime configuration is a sensible enhancement. This check prevents potential issues that could arise when the configuration needs to be serialized later in the application lifecycle.

examples/cli-drizzle/indexers/1-evm.indexer.ts (2)

22-23: Improved database connection handling

The code now relies on environment variables for database connections instead of explicit parameters. The added comment clearly explains the fallback behavior.


32-32: Enhanced type safety with explicit BigInt conversion

Explicitly converting startingBlock to BigInt ensures proper handling of block numbers, especially for large values that might exceed JavaScript's safe integer range.

examples/cli-drizzle/test/ethereum.test.ts (1)

13-14: Consistent approach to handling block numbers

Using regular number literals for configuration while maintaining BigInt types for actual block handling in the test execution is a good approach. This makes the configuration more portable and easier to serialize/deserialize.

examples/cli-drizzle/apibara.config.ts (1)

6-6: Type consistency improvement for block numbers

The removal of the n suffix changes these values from BigInt literals to regular number literals. This is a positive change as it aligns with how these values are handled in the indexers, where they're explicitly converted to BigInt when needed (as seen in the starknet indexer).

Also applies to: 9-9

examples/cli-drizzle/indexers/2-starknet.indexer.ts (3)

17-17: Clear documentation of default behavior

Good addition of a comment explaining the default connection string behavior, which helps developers understand where the database connection is configured.


27-27: Explicit type conversion ensures consistency

Explicitly converting the startingBlock to BigInt ensures that the value is always treated as a BigInt regardless of its source format, which aligns with the changes in the configuration file where the BigInt literals were replaced with regular numbers.


69-76: Improved data validation for database operations

The filter operation ensures that only valid entries with defined and non-NaN numbers are inserted into the database, which improves data integrity and prevents potential errors.

packages/plugin-drizzle/src/helper.ts (2)

61-61: Updated documentation to reflect new default behavior

The JSDoc now correctly indicates that the default connection string comes from an environment variable with a fallback.


105-107: Enhanced function documentation

Good addition of important usage information to the function documentation, making it clear how the connection string defaults are determined.

packages/plugin-drizzle/src/storage.ts (16)

14-14: Importing pgSchema is appropriate

This new import is necessary to define a proper namespaced schema.


18-18: Shared schema name

Referencing SCHEMA_NAME from a constants file ensures consistency across the codebase.


21-21: Introducing ROLLBACK_TABLE_NAME

Using a dedicated constant for the rollback table name is a clear, maintainable approach.


23-23: Defining the schema instance

Creating schema via pgSchema(SCHEMA_NAME) helps keep table definitions under the correct namespace.


31-32: Schema-scoped rollback table

Replacing direct pgTable calls with schema.table keeps tables neatly namespaced, simplifying future management.


51-54: Safeguard schema creation

Using “IF NOT EXISTS” is good. However, concurrency might still pose edge cases (e.g., two transactions simultaneously creating the same schema). Usually this is safe, but consider verifying.

Would you like a script to search for other points in the codebase where schema creation might conflict under parallel operations?


58-58: Qualified table creation

Employing fully qualified paths (${SCHEMA_NAME}.${ROLLBACK_TABLE_NAME}) is a robust pattern for multi-schema setups.


72-73: Index creation

Using “IF NOT EXISTS” prevents errors when the index is already present. This is a best practice for incremental deployments.


85-85: Creating the trigger function in the schema

“CREATE OR REPLACE FUNCTION” within the schema neatly organizes custom triggers and avoids name collisions.


95-96: Capture DELETE operations

Inserting old row data on deletion is essential for rollback. Implementation looks correct.


98-99: Handle UPDATE operations

Properly logging updated rows enables fine-grained rollback. No issues found.


102-103: Handle INSERT operations

Only the newly inserted row’s ID is needed because there is no prior row state. This is consistent with reorg logic.


143-143: Trigger for each row

Associating the row-level trigger with reorg_checkpoint ensures robust reorg tracking.


195-197: Invalidate rollback entries past the target cursor

Helps revert problematic blocks beyond the specified cursor. Implementation is logical.


318-321: Finalize rollback entries

Cleaning out older rollback entries once the chain state is deemed final is standard reorg procedure.


351-353: Complete storage cleanup

Dropping leftover rollback data by indexer_id prevents orphaned records and stale triggers.

packages/cli/src/runtime/internal/app.ts (5)

11-16: Extended imports for client creation

Pulling CreateClientOptions, Metadata, StreamConfig, and createClient supports both standard and authenticated usage scenarios.


21-21: Importing getProcessedRuntimeConfig

Centralizing config resolution in one helper function reduces code duplication and improves maintainability.


27-32: Consolidating runtime config

Merging preset and environment-based configurations into _runtimeConfig ensures consistent settings. This approach is clear and robust.


34-34: Exposing runtime config

Storing the serialized config in process.env.APIBARA_RUNTIME_CONFIG_HOOK_DATA helps unify config usage across modules.


94-116: createAuthenticatedClient for token-based auth

This addition seamlessly injects Bearer tokens into RPC metadata. Consider handling expired or invalid tokens gracefully, but for now, this is a straightforward approach.

packages/plugin-drizzle/src/persistence.ts (10)

2-2: Added imports for multi-conditional queries

Pulling in and, eq, gt, isNull, lt, and sql is appropriate for advanced query logic.


8-8: Importing pgSchema, primaryKey, text, and integer

This allows transitioning to schema-based table definitions, ensuring flexible DB organization.


9-9: Referencing SCHEMA_NAME

Consistently placing tables within the defined schema fosters better DB structure.


12-14: Renaming table name constants

Using simpler “checkpoints”, “filters”, and “schema_version” clarifies their purpose and moves away from underscored prefixes.


16-16: Instantiate main schema

const schema = pgSchema(SCHEMA_NAME) organizes table definitions under the shared namespace.


18-19: Define the checkpoints table

Marking it as “not used for migrations” clarifies the table’s ephemeral or internal use case.


25-26: Define the filters table

Using the namespaced schema.table approach for partial indexing or block-based filters is consistent with the new structure.


41-42: Define the schemaVersion table

Similarly applying schema.table to track versioning. Good for aligning all internal tables under one schema.


62-66: Creating the schema if absent

Launching “CREATE SCHEMA IF NOT EXISTS” ensures the code can run on fresh databases without manual setup.


70-76: Creating the schema_version table

Explicitly scoping the table to ${SCHEMA_NAME} fosters clarity for version control.

Copy link
Contributor

@fracek fracek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a couple of small changes and we're good

@jaipaljadeja jaipaljadeja force-pushed the feat/qol-improvements-fixes branch from 380c272 to 625b1cd Compare March 21, 2025 10:44
@fracek
Copy link
Contributor

fracek commented Mar 21, 2025

Looks good now!

@fracek fracek merged commit 7834780 into apibara:main Mar 21, 2025
2 checks passed
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.

2 participants