Skip to content

Conversation

@fracek
Copy link
Contributor

@fracek fracek commented Oct 20, 2024

Update to the latest drizzle version to solve type issues on new projects.

@coderabbitai
Copy link

coderabbitai bot commented Oct 20, 2024

📝 Walkthrough

Walkthrough

A new JSON file has been added for the @apibara/indexer package, indicating a prerelease update related to drizzle components. The package.json files for both example-indexer and example-starknet-indexer projects have updated their drizzle-orm dependency from version ^0.33.0 to ^0.35.0. The package.json for apibara-typescript-sdk modified the typecheck script by removing the --parallel flag. Additionally, the @apibara/indexer package's package.json updated its version to 2.0.0-beta.8 and modified the drizzle-orm dependency in both devDependencies and peerDependencies to ^0.35.2. Changes were also made to type definitions in insert.ts and utils.ts.

Changes

File Path Change Summary
change/@apibara-indexer-eae11f64-2203-4964-a273-9c1536b8fcdd.json New JSON file added for @apibara/indexer, specifying a prerelease update.
examples/indexer/package.json Updated drizzle-orm dependency version from ^0.33.0 to ^0.35.0.
examples/starknet-indexer/package.json Updated drizzle-orm dependency version from ^0.33.0 to ^0.35.0.
package.json Modified typecheck script by removing --parallel flag.
packages/indexer/package.json Updated version to 2.0.0-beta.8 and drizzle-orm version in devDependencies and peerDependencies to ^0.35.2.
packages/indexer/src/sinks/drizzle/insert.ts Renamed type alias from PgInsertValue to DrizzleInsertValue and updated method return type.
packages/indexer/src/sinks/drizzle/utils.ts Added new types CursorColumnBuilder, PgTableWithCursorFn, and modified PgInsertValue type; updated pgTable function.

Possibly related PRs

Poem

🐇 In the meadow where code does bloom,
New types and versions chase away gloom.
Drizzle flows with a fresh, bright hue,
Scripts run smoother, all thanks to you!
With each change, our project takes flight,
Hopping along, everything feels right! 🌼


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 (4)
packages/indexer/src/sinks/drizzle/insert.ts (2)

7-7: LGTM! Consider consolidating type imports.

The renaming of PgInsertValue to DrizzleInsertValue and the separate type import for PgInsertValue look good. These changes align well with the PR objective of updating drizzle and resolving type issues.

For better code organization, consider consolidating all type imports at the top of the file. You could move the PgInsertValue type import to be with the other type imports from 'drizzle-orm/pg-core'.

Also applies to: 12-12


38-40: LGTM! Consider using a type guard for improved type safety.

The changes look good. The use of DrizzleInsertValue is consistent with the import changes, and the multi-line format improves readability.

To improve type safety, consider using a type guard function instead of a type assertion. This would ensure that the _cursor property is correctly added to all values at runtime. Here's an example:

function addCursor<T extends object>(value: T, cursor: string | undefined): T & { _cursor: string | undefined } {
  return { ...value, _cursor: cursor };
}

// In the values method:
const cursoredValues = (Array.isArray(values) ? values : [values]).map(
  (v) => addCursor(v, getDrizzleCursor(this.endCursor?.orderKey))
);

return originalInsert.values(cursoredValues);

This approach eliminates the need for the type assertion and provides better runtime type checking.

packages/indexer/package.json (1)

Line range hint 1-105: Summary: drizzle-orm version update

The changes in this file are focused on updating the drizzle-orm dependency from version ^0.33.0 to ^0.35.2 in both devDependencies and peerDependencies. These updates are consistent with the PR objective to resolve type issues in new projects using the drizzle library.

Key points:

  1. The updates maintain consistency across different dependency sections.
  2. The minor version update (0.33 to 0.35) suggests new features and backwards-compatible changes.

Consider the following to ensure a smooth transition:

  1. Review the changelog for any new features or deprecations that might affect your codebase.
  2. Update any internal documentation or guides that reference the drizzle-orm version.
  3. Consider running a comprehensive test suite to catch any potential compatibility issues early.
packages/indexer/src/sinks/drizzle/utils.ts (1)

Line range hint 69-75: Consider renaming the custom pgTable function to avoid confusion

Redefining the pgTable function name may cause confusion with the original pgTable imported from drizzle-orm/pg-core. To enhance clarity and maintainability, consider renaming the custom function to something like pgTableWithCursor.

Apply this diff to rename the function:

-export const pgTable: PgTableWithCursorFn = (name, columns, extraConfig?) => {
+export const pgTableWithCursor: PgTableWithCursorFn = (name, columns, extraConfig?) => {
   return drizzlePgTable(
     name,
     {
       ...columns,
       _cursor: int8range("_cursor").notNull(),
     },
     extraConfig,
   );
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0ba1f8b and 68700fe.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • change/@apibara-indexer-eae11f64-2203-4964-a273-9c1536b8fcdd.json (1 hunks)
  • examples/indexer/package.json (1 hunks)
  • examples/starknet-indexer/package.json (1 hunks)
  • package.json (1 hunks)
  • packages/indexer/package.json (2 hunks)
  • packages/indexer/src/sinks/drizzle/insert.ts (2 hunks)
  • packages/indexer/src/sinks/drizzle/utils.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • change/@apibara-indexer-eae11f64-2203-4964-a273-9c1536b8fcdd.json
  • examples/indexer/package.json
🧰 Additional context used
🔇 Additional comments (8)
examples/starknet-indexer/package.json (1)

25-25: LGTM! Verify consistency and test the update.

The update of drizzle-orm to version ^0.35.0 aligns with the PR objectives and should help resolve the type issues mentioned in the PR summary.

To ensure consistency across the project, please run the following script:

After verifying consistency, please ensure to:

  1. Run the project's test suite to confirm there are no breaking changes.
  2. If there are no tests, manually test the key functionalities that depend on drizzle-orm.
  3. Review the changelog for drizzle-orm between versions 0.33.0 and 0.35.0 for any breaking changes or new features that might affect the project.
packages/indexer/src/sinks/drizzle/insert.ts (1)

Line range hint 1-41: Overall, the changes look good and align with the PR objectives.

The updates to type imports and usage, particularly the renaming of PgInsertValue to DrizzleInsertValue, contribute to resolving type issues as mentioned in the PR objectives. The code structure has been improved, enhancing readability and maintainability.

A few minor suggestions have been provided to further improve type safety and code organization. These changes, if implemented, would further enhance the quality of the code without significantly altering its functionality.

package.json (1)

8-8: Verify the impact of removing the --parallel flag from the typecheck script.

The --parallel flag has been removed from the typecheck script, changing it from parallel to sequential execution. While this change might be intentional to address type-related issues, it's important to consider its implications:

  1. This could potentially increase the time taken for the typecheck process, especially in a large monorepo with multiple packages.
  2. On the other hand, sequential execution might provide more reliable results by avoiding potential race conditions.

Could you please clarify the reasoning behind this change? Also, it would be beneficial to monitor the impact on typecheck performance after this change.

To help assess the impact, you can run the following script to compare the execution times of the old and new typecheck commands:

packages/indexer/package.json (2)

101-101: Approved: drizzle-orm version update in peerDependencies

The update of drizzle-orm from ^0.33.0 to ^0.35.2 in peerDependencies is consistent with the change in devDependencies and maintains package configuration consistency.

Please ensure that any documentation or README files mentioning the required drizzle-orm version are updated accordingly. Run the following command to check for any mentions of the old version:

✅ Verification successful

Verified: No references to drizzle-orm version 0.33.0 found in documentation

All documentation files have been checked and there are no mentions of the old drizzle-orm version 0.33.0. Documentation updates related to this version change are confirmed to be complete.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for mentions of the old drizzle-orm version in documentation

# Test: Search for mentions of the old version in README and documentation files
rg -i '0\.33\.0' $(fd -e md -e txt)

Length of output: 397


83-83: Approved: drizzle-orm version update in devDependencies

The update of drizzle-orm from ^0.33.0 to ^0.35.2 in devDependencies aligns with the PR objective to update to the latest release. This minor version update should include new features and backwards-compatible changes.

To ensure compatibility, please verify that all tests pass with this new version. Run the following command to check for any breaking changes or deprecations:

packages/indexer/src/sinks/drizzle/utils.ts (3)

19-29: Definition of CursorColumnBuilder correctly configures the _cursor column

The CursorColumnBuilder type is appropriately defined with the necessary properties, ensuring that the _cursor column is accurately represented as a non-null custom column of type Int8Range.


31-55: PgTableWithCursorFn successfully extends pgTable to include _cursor

The custom PgTableWithCursorFn type correctly extends the pgTable function, adding the _cursor column to the table schema. This ensures that all tables created using this function will consistently include the _cursor column.


57-65: PgInsertValue type correctly omits _cursor to prevent manual insertion

By omitting the _cursor column from the PgInsertValue type, the code prevents direct insertion into the _cursor column, which is appropriate if the _cursor value is managed internally by the system.

@fracek fracek merged commit 5cd8d6f into apibara:main Oct 20, 2024
1 check passed
@fracek fracek deleted the update-drizzle branch October 20, 2024 20:28
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