Skip to content

fix: types #304

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 1 commit into from
Oct 18, 2024
Merged

fix: types #304

merged 1 commit into from
Oct 18, 2024

Conversation

ponderingdemocritus
Copy link
Contributor

@ponderingdemocritus ponderingdemocritus commented Oct 17, 2024

  • fixes types with sdk

Summary by CodeRabbit

  • New Features

    • Enhanced getEntities function with a new required parameter for improved entity fetching control.
    • Updated getEventMessages function to modify query behavior with a new property for data structure adjustments.
  • Bug Fixes

    • Adjusted handling of hashed keys in queries for both getEntities and getEventMessages functions.

Copy link

coderabbitai bot commented Oct 17, 2024

Walkthrough

The pull request introduces modifications to the getEntities and getEventMessages functions within the SDK. The getEntities function now requires a new schema parameter and includes a conditional property, dont_include_hashed_keys, in the toriiQuery object. The getEventMessages function also adds the dont_include_hashed_keys property, set to true. These changes enhance the control over entity fetching and the behavior of queries sent to the Torii client.

Changes

File Path Change Summary
packages/sdk/src/getEntities.ts Updated getEntities method signature to include a required schema parameter and added dont_include_hashed_keys to toriiQuery.
packages/sdk/src/getEventMessages.ts Added dont_include_hashed_keys property set to true in toriiQuery within getEventMessages.

Possibly related PRs

  • fix: prettier #298: The changes in this PR involve renaming the db parameter to sdk in the App component, which directly relates to the modifications made in the getEntities function regarding the handling of the SDK and its parameters.

Poem

In the land of code where rabbits play,
New keys and schemas brighten the day.
Fetching entities with a hop and a skip,
With dont_include_hashed_keys, we take a trip!
So let’s dance in the fields of data so bright,
With changes that make our queries just 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: 1

🧹 Outside diff range and nitpick comments (1)
packages/sdk/src/getEntities.ts (1)

52-52: Approve: Enhanced query control with dont_include_hashed_keys

The addition of the dont_include_hashed_keys property to the toriiQuery object is a valuable enhancement. It provides more granular control over the query behavior, allowing hashed keys to be included only when specific entity IDs are provided in the query. This change aligns well with the function's purpose and increases its flexibility.

However, the boolean logic can be simplified for better readability:

Consider simplifying the boolean expression:

-dont_include_hashed_keys: query.entityIds ? false : true,
+dont_include_hashed_keys: !query.entityIds,

This change maintains the same logic while making it more concise and easier to understand at a glance.

🧰 Tools
🪛 Biome

[error] 52-52: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b3339ce and 3539312.

📒 Files selected for processing (2)
  • packages/sdk/src/getEntities.ts (1 hunks)
  • packages/sdk/src/getEventMessages.ts (1 hunks)
🧰 Additional context used
🪛 Biome
packages/sdk/src/getEntities.ts

[error] 52-52: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

🔇 Additional comments (2)
packages/sdk/src/getEntities.ts (2)

Line range hint 1-51: LGTM: Addition of schema parameter enhances type safety

The addition of the schema parameter of type T to the getEntities function signature is a positive change. It allows for more type-safe operations within the function, particularly when converting the query to a clause using convertQueryToClause(query, schema). This modification aligns well with the function's TypeScript generic constraint T extends SchemaType and enhances the overall type safety of the function.

Also applies to: 53-89

🧰 Tools
🪛 Biome

[error] 52-52: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


Line range hint 1-89: Verify: Impact of changes on function usage and behavior

The modifications to the getEntities function introduce some important changes that may impact its usage and behavior:

  1. The addition of the schema parameter is a breaking change. All existing calls to this function will need to be updated to include the schema argument.
  2. The new dont_include_hashed_keys property in the query may alter the results returned by the function, potentially affecting dependent code.

To mitigate risks associated with these changes:

  1. Ensure all calls to getEntities across the codebase are updated to include the schema parameter.
  2. Review and test any code that depends on the results of getEntities to verify it handles the potential inclusion/exclusion of hashed keys correctly.
  3. Consider updating the function's documentation to clearly explain the new schema parameter and the behavior of dont_include_hashed_keys.

To help identify potential issues, you can run the following script:

This script will help identify calls to getEntities that may need updating and code that processes the results of getEntities, which might be affected by the changes in hashed key handling.

🧰 Tools
🪛 Biome

[error] 52-52: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

@@ -49,6 +49,7 @@ export async function getEventMessages<T extends SchemaType>(
limit: limit,
offset: cursor,
clause,
dont_include_hashed_keys: true,
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Update torii.Query type definition to include dont_include_hashed_keys

The property dont_include_hashed_keys: true is being used in several instances of getEventMessages, but it is not defined in the torii.Query type. This inconsistency can lead to type errors and unexpected behaviors across the codebase.

Action Items:

  1. Update Type Definitions:

    • Add dont_include_hashed_keys?: boolean to the torii.Query type to ensure it is recognized across all usages.
  2. Ensure Consistency:

    • Verify that all instances of getEventMessages either include this property or handle its absence appropriately.
  3. Update Documentation:

    • Reflect the addition of dont_include_hashed_keys in the JSDoc comments and any relevant documentation to inform users of its purpose and usage.
  4. Review Usage:

    • Check for any conditional logic that relies on the presence or absence of dont_include_hashed_keys to ensure consistent behavior.

Category:

🔗 Analysis chain

Update documentation and consider backwards compatibility for dont_include_hashed_keys

The addition of dont_include_hashed_keys: true to the toriiQuery object modifies the behavior of the query sent to the Torii client. While this change may improve performance by reducing the amount of data returned, it raises several concerns:

  1. The function's JSDoc comments don't mention this new behavior, which could lead to confusion for users of the SDK.
  2. This change might break existing code that expects hashed keys to be present in the query results.
  3. The type definition for torii.Query may need to be updated to include this new property.

To address these issues, consider the following:

  1. Update the function's JSDoc comments to explain the purpose and impact of dont_include_hashed_keys.
  2. Consider making this behavior optional by adding a parameter to the function, allowing users to choose whether to include hashed keys or not.
  3. Update the torii.Query type definition if necessary.
  4. If this is a breaking change, consider versioning the SDK appropriately and documenting the change in the changelog.

To verify the impact of this change, we can search for other usages of getEventMessages in the codebase:

This will help us understand if other parts of the codebase might be affected by this change.


[/run_scripts]


[/run_scripts]

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of getEventMessages
rg --type typescript 'getEventMessages\(' -A 10

Length of output: 84


Script:

#!/bin/bash
# Search for usages of getEventMessages in TypeScript files using correct file type
rg --type ts 'getEventMessages\(' -A 10

# If the above does not work, search using file extensions directly
rg 'getEventMessages\(' --glob '*.ts' --glob '*.tsx' -A 10

Length of output: 5598


Script:

#!/bin/bash
# Search for the definition of torii.Query type
ast-grep --lang typescript --pattern 'type torii\.Query {$$$}' packages/sdk/src/**/*.ts

# Alternatively, search for interfaces named torii.Query
rg 'interface\s+torii\.Query' --glob '*.ts' 

# Check for occurrences of dont_include_hashed_keys in type definitions
rg 'dont_include_hashed_keys' --glob '*.ts' 

Length of output: 1374

@ponderingdemocritus ponderingdemocritus merged commit a7ca781 into main Oct 18, 2024
3 checks passed
@ponderingdemocritus ponderingdemocritus deleted the fix/sdk branch October 18, 2024 00:02
This was referenced Oct 23, 2024
@coderabbitai coderabbitai bot mentioned this pull request Nov 1, 2024
@coderabbitai coderabbitai bot mentioned this pull request Mar 14, 2025
5 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