Skip to content
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

fix: added missing params to getEventMessages() #373

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

rsodre
Copy link
Contributor

@rsodre rsodre commented Jan 13, 2025

Introduced changes

  • added missing params to getEventMessages(): dont_include_hashed_keys, entity_updated_after
  • refactored params of internal functions getEventMessages() and getEntities() extending GetParams<T>
  • refactored params of internal funcitons subscribeEntityQuery() and subscribeEventQuery() reusing SubscribeParams<T>

example, from...

export async function getEventMessages<T extends SchemaType>(
    client: torii.ToriiClient,
    query: QueryType<T>,
    schema: T,
    callback: (response: {
        data?: StandardizedQueryResult<T> | StandardizedQueryResult<T>[];
        error?: Error;
    }) => void,
    orderBy: torii.OrderBy[] = [],
    entityModels: string[] = [],
    limit: number = 100, // Default limit
    offset: number = 0, // Default offset
    options?: { logging?: boolean }, // Logging option
    historical?: boolean
)

to...

export async function getEventMessages<T extends SchemaType>({
    client,
    schema,
    query,
    callback,
    orderBy = [],
    entityModels = [],
    limit = 100, // Default limit
    offset = 0, // Default offset
    options = { logging: false }, // Logging option
    historical = true,
    dontIncludeHashedKeys = true,
    entityUpdatedAfter = 0,
}: GetParams<T> & {
    client: torii.ToriiClient;
    schema: T;
})

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Add a dedicated CI job for new examples
  • Performed self-review of the code

Summary by CodeRabbit

  • New Features

    • Enhanced SDK query functionality with new optional parameters for filtering entities
    • Added ability to exclude hashed keys and filter entities by update timestamp
    • Improved parameter handling across multiple SDK functions
  • Refactor

    • Restructured function signatures to use object-based parameter passing
    • Simplified parameter management in SDK functions
    • Updated type definitions to support more flexible querying
  • Chores

    • Improved code readability and maintainability
    • Standardized parameter handling across SDK functions

dont_include_hashed_keys, entity_updated_after
Copy link

coderabbitai bot commented Jan 13, 2025

Walkthrough

The pull request introduces a comprehensive refactoring of parameter handling across multiple SDK functions. The primary change involves transforming function signatures from traditional parameter lists to destructured object formats. This modification affects functions like getEntities, getEventMessages, subscribeEntityQuery, and subscribeEventQuery. Two new optional parameters, dontIncludeHashedKeys and entityUpdatedAfter, have been added to enhance query flexibility. The changes improve code readability and maintainability while preserving the existing functionality of the SDK.

Changes

File Change Summary
packages/sdk/src/getEntities.ts Updated function signature to use destructured object parameters, added dontIncludeHashedKeys and entityUpdatedAfter
packages/sdk/src/getEventMessages.ts Restructured parameters into a single object, added dontIncludeHashedKeys and entityUpdatedAfter
packages/sdk/src/index.ts Updated function calls to pass parameters as objects with new parameters
packages/sdk/src/subscribeEntityQuery.ts Transformed function signature to use destructured object parameters
packages/sdk/src/subscribeEventQuery.ts Restructured parameters into a single object with default values
packages/sdk/src/types.ts Added dontIncludeHashedKeys and entityUpdatedAfter to GetParams interface

Possibly related PRs

Poem

🐰 Hop, hop, through the code we go,
Refactoring params with a rabbit's glow
Objects replace lists, so clean and bright
Parameters dance with newfound might
SDK magic, smooth as can be! 🌟

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

🧹 Nitpick comments (6)
packages/sdk/src/subscribeEventQuery.ts (1)

Line range hint 8-26: Update JSDoc to reflect new parameter structure.

The JSDoc comments need to be updated to match the new destructured object parameter format. This will help maintain accurate documentation for SDK users.

packages/sdk/src/subscribeEntityQuery.ts (2)

Line range hint 8-26: Update JSDoc to reflect new parameter structure.

The JSDoc comments need to be updated to match the new destructured object parameter format.


Line range hint 37-43: Remove duplicate logging of convertQueryToEntityKeyClauses.

The same query conversion is being logged twice. Consider removing the second logging instance to avoid redundancy.

    if (options?.logging) {
        console.log("Query:", query);
        console.log(
            "convertQueryToEntityKeyClauses:",
            convertQueryToEntityKeyClauses(query, schema)
        );
    }
    return client.onEntityUpdated(
        convertQueryToEntityKeyClauses(query, schema),
        (entityId: string, entityData: any) => {
            try {
                if (callback) {
                    const parsedData = parseEntities<T>({
                        [entityId]: entityData,
                    });
                    if (options?.logging) {
-                       console.log(
-                           "Converted query to entity key clauses:",
-                           convertQueryToEntityKeyClauses(query, schema)
-                       );
                        console.log("Parsed entity data:", parsedData);
                    }

Also applies to: 51-53

packages/sdk/src/getEntities.ts (1)

Line range hint 8-28: Update JSDoc to reflect new parameter structure and document new parameters.

The JSDoc needs to be updated to:

  1. Match the new destructured object parameter format
  2. Document the new dontIncludeHashedKeys and entityUpdatedAfter parameters
packages/sdk/src/getEventMessages.ts (1)

Line range hint 8-29: Update JSDoc to reflect new parameter structure.

The JSDoc comments need to be updated to match the new destructured object parameter format and document all parameters, including historical, dontIncludeHashedKeys, and entityUpdatedAfter.

packages/sdk/src/types.ts (1)

419-422: Add JSDoc comments and consider renaming the parameter.

  1. Add JSDoc comments for the new parameters to maintain consistency with other parameters in the interface.
  2. Consider renaming dontIncludeHashedKeys to includeHashedKeys for better clarity, as positive naming is generally preferred.
    // historical events
    historical?: boolean;
-   // hashed keys on events
-   dontIncludeHashedKeys?: boolean;
-   // entity updated after
-   entityUpdatedAfter?: number;
+   /**
+    * Whether to include hashed keys in the event data.
+    * Default is true.
+    */
+   includeHashedKeys?: boolean;
+   /**
+    * Filter entities to only include those updated after this timestamp.
+    * Timestamp should be in milliseconds since epoch.
+    */
+   entityUpdatedAfter?: number;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a50c3d1 and 194bee2.

📒 Files selected for processing (6)
  • packages/sdk/src/getEntities.ts (3 hunks)
  • packages/sdk/src/getEventMessages.ts (5 hunks)
  • packages/sdk/src/index.ts (3 hunks)
  • packages/sdk/src/subscribeEntityQuery.ts (2 hunks)
  • packages/sdk/src/subscribeEventQuery.ts (2 hunks)
  • packages/sdk/src/types.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: check
  • GitHub Check: build
🔇 Additional comments (6)
packages/sdk/src/subscribeEventQuery.ts (1)

28-38: LGTM! Clean parameter restructuring.

The transition to a destructured object format with proper typing and default values improves code maintainability while maintaining backward compatibility.

packages/sdk/src/getEntities.ts (1)

29-44: LGTM! Well-structured parameter enhancement.

The addition of dontIncludeHashedKeys and entityUpdatedAfter parameters with proper default values enhances query flexibility while maintaining backward compatibility.

Also applies to: 58-59

packages/sdk/src/getEventMessages.ts (2)

76-78: LGTM! Improved historical data handling.

The simplified historical data handling with direct use of the historical parameter improves code readability.

Also applies to: 100-102


41-42: Consider aligning default values across functions.

dontIncludeHashedKeys defaults to true here but false in getEntities. Consider aligning these defaults to maintain consistency across the SDK.

Run this script to verify the impact of this inconsistency:

packages/sdk/src/index.ts (2)

49-49: LGTM! Parameter restructuring is consistent.

The changes maintain a consistent pattern across all functions, improving code readability and maintainability.

Also applies to: 57-64, 82-94, 113-126


82-94: Verify the default behavior for the new parameters.

Please ensure that the default behavior when dontIncludeHashedKeys and entityUpdatedAfter are not provided maintains backward compatibility.

Also applies to: 113-126

✅ Verification successful

Default behavior for new parameters maintains backward compatibility

The new parameters dontIncludeHashedKeys and entityUpdatedAfter are properly implemented with safe defaults:

  • dontIncludeHashedKeys defaults to false
  • entityUpdatedAfter defaults to 0

These defaults ensure that existing code continues to work without modification, maintaining the original behavior when parameters are not provided.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing usages of getEntities and getEventMessages to verify impact
echo "Searching for getEntities usage..."
rg "getEntities\(" -A 5

echo "Searching for getEventMessages usage..."
rg "getEventMessages\(" -A 5

Length of output: 12428


Script:

#!/bin/bash
# Find getEntities function implementation and type definitions
echo "Searching for getEntities function definition..."
ast-grep --pattern 'export $_ function getEntities($_) {
  $$$
}'

echo "Searching for getEntities interface/type definitions..."
rg "interface.*getEntities|type.*getEntities" -A 10

Length of output: 349


Script:

#!/bin/bash
# Search for getEntities implementation and type definitions with refined patterns
echo "Searching for getEntities implementation file..."
fd "getEntities.ts" packages/sdk/src

echo "Searching for getEntities function definition..."
ast-grep --pattern 'export const getEntities = $_'

echo "Searching for type definitions..."
rg "type.*Get.*Entities|interface.*Get.*Entities" -A 10

echo "Showing content of getEntities implementation..."
cat packages/sdk/src/getEntities.ts

Length of output: 7389

@MartianGreed MartianGreed merged commit 3bf693c into dojoengine:main Jan 14, 2025
6 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