Skip to content

fix: recs update fix type #436

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
May 8, 2025
Merged

fix: recs update fix type #436

merged 1 commit into from
May 8, 2025

Conversation

ponderingdemocritus
Copy link
Contributor

@ponderingdemocritus ponderingdemocritus commented May 8, 2025

  • type mismatch in torii client

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of entity and event data handling, ensuring accurate display and pagination of fetched items.

Copy link

coderabbitai bot commented May 8, 2025

Walkthrough

All references to the items property on response objects from client.getEntities and client.getEventMessages have been replaced with models. The updated code now casts these responses to any and updates all usages accordingly within three functions: getEntities, getEvents, and getEntitiesQuery. No other logic or exported declarations are changed.

Changes

Files/Paths Change Summary
packages/state/src/recs/index.ts Replaced all references to items with models on response objects from client methods; updated related logic

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Client
    participant LocalState

    Caller->>Client: getEntities / getEventMessages
    Client-->>Caller: Response with models[]
    Caller->>LocalState: Insert models into DB / set models in state
    Caller->>Caller: Check models.length for pagination
Loading

Possibly related PRs

  • feat: Torii upgrade #303: Modifies the same functions to add a new parameter (dont_include_hashed_keys) to client calls, indicating both PRs update how API responses are handled in these functions.

Poem

In the fields of code, a rabbit hops,
Swapping items for models—no stops!
With every fetch, the models grow,
In local state, their numbers show.
The code is clean, the logic tight,
Another hop—everything’s right! 🐇

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.

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 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 generate sequence diagram to generate a sequence diagram of the changes in 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.

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 comments (3)
packages/state/src/recs/index.ts (3)

225-236: 🛠️ Refactor suggestion

Type cast to any should be improved with a proper type definition.

Similar to the earlier instance, using any type for the response from getEventMessages bypasses TypeScript's type checking system. Consider defining a proper interface for the response structure.

-const entities = (await client.getEventMessages({
+interface ToriiResponse {
+  models: Record<string, any>;
+  next_cursor: string;
+}
+
+const entities = (await client.getEventMessages({
  pagination: {
    limit,
    cursor,
    direction: "Forward",
    order_by: orderBy,
  },
  clause: clause || undefined,
  no_hashed_keys: false,
  models: entityModels,
  historical,
-})) as any;
+})) as ToriiResponse;
🧰 Tools
🪛 Biome (1.9.4)

[error] 236-236: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


285-296: 🛠️ Refactor suggestion

Type cast to any should be improved with a proper type definition.

Using any bypasses TypeScript's type safety. Consider using the same interface type suggested earlier for all Torii client responses.

If you implement the ToriiResponse interface suggested earlier, you can use it here as well:

-const fetchedEntities = (await client.getEntities({
+const fetchedEntities = (await client.getEntities({
  pagination: {
    limit,
    cursor,
    direction: "Forward",
    order_by: orderBy,
  },
  clause: entityKeyClause,
  no_hashed_keys: false,
  models: entityModels,
  historical,
-})) as any;
+})) as ToriiResponse;
🧰 Tools
🪛 Biome (1.9.4)

[error] 296-296: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


164-175: 💡 Verification agent

🧩 Analysis chain

Type cast to any should be improved with a proper type definition.

The change from items to models in the response structure is good, but using any type bypasses TypeScript's type checking system, which could lead to potential runtime errors. Consider defining an interface for the response structure instead.


🏁 Script executed:

#!/bin/bash
# Check if there's a type definition for the Torii client response
grep -r "interface.*Response" --include="*.ts" .
# Alternatively, check if there are any existing typings for models property
grep -r "models:.*\[\]" --include="*.ts" .

Length of output: 768


Define a proper response type instead of any

You should replace the as any cast with a real TypeScript interface so you get full type-checking on the response. For example, in packages/state/src/recs/index.ts (around lines 164–175):

  1. Add a response interface (e.g. in a new or existing packages/state/src/types.ts):

    export interface GetEntitiesResponse<TModel> {
      items: TModel[];              // or `models: TModel[]` if the API really returns “models”
      pagination: {
        limit: number;
        cursor: string | null;
        direction: "Forward" | "Backward";
        order_by: keyof TModel;
      };
      no_hashed_keys: boolean;
      historical: boolean;
    }
  2. Update the call to use a generic:

        // Old:
  •  const entities = (await client.getEntities({
    
  •  const entities = await client.getEntities<GetEntitiesResponse<MyEntityModel>>({
        pagination: { … },
        clause: clause || undefined,
        no_hashed_keys: false,
        models: entityModels,
        historical,
    });
    
    
    
  1. Replace MyEntityModel with the actual model interface you’re querying.

This way you avoid any, get proper type safety on the API response, and catch potential mismatches at compile time.

🧰 Tools
🪛 Biome (1.9.4)

[error] 175-175: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)

🧹 Nitpick comments (2)
packages/state/src/recs/index.ts (2)

181-181: Template literal can be simplified.

While the property update from items to models is good, the template literal is unnecessary when no interpolation is needed in the first part of the string.

-if (logging) console.log(`Fetched entities`, entities.models);
+if (logging) console.log("Fetched entities", entities.models);
🧰 Tools
🪛 Biome (1.9.4)

[error] 181-181: Do not use template literals if interpolation and special-character handling are not needed.

Unsafe fix: Replace with string literal

(lint/style/noUnusedTemplateLiteral)


164-306: Overall assessment of type property change from items to models.

The PR correctly updates all references from items to models property in the Torii client responses, which aligns with the API changes. However, I recommend defining proper interface types instead of using any type assertions to maintain type safety.

Consider creating a shared type definition file for Torii client responses to ensure consistency across the codebase and improve type safety. This would eliminate the need for any type assertions and provide better IntelliSense support and compile-time checks.

🧰 Tools
🪛 Biome (1.9.4)

[error] 175-175: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 181-181: Do not use template literals if interpolation and special-character handling are not needed.

Unsafe fix: Replace with string literal

(lint/style/noUnusedTemplateLiteral)


[error] 212-212: This default parameter should follow the last required parameter or should be a required parameter.

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.

(lint/style/useDefaultParameterLast)


[error] 213-213: This default parameter should follow the last required parameter or should be a required parameter.

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.

(lint/style/useDefaultParameterLast)


[error] 214-214: This default parameter should follow the last required parameter or should be a required parameter.

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.

(lint/style/useDefaultParameterLast)


[error] 214-214: This type annotation is trivially inferred from its initialization.

Safe fix: Remove the type annotation.

(lint/style/noInferrableTypes)


[error] 216-216: This type annotation is trivially inferred from its initialization.

Safe fix: Remove the type annotation.

(lint/style/noInferrableTypes)


[error] 217-217: This type annotation is trivially inferred from its initialization.

Safe fix: Remove the type annotation.

(lint/style/noInferrableTypes)


[error] 236-236: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 249-249: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 277-277: This type annotation is trivially inferred from its initialization.

Safe fix: Remove the type annotation.

(lint/style/noInferrableTypes)


[error] 278-278: This type annotation is trivially inferred from its initialization.

Safe fix: Remove the type annotation.

(lint/style/noInferrableTypes)


[error] 279-279: This type annotation is trivially inferred from its initialization.

Safe fix: Remove the type annotation.

(lint/style/noInferrableTypes)


[error] 296-296: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c4958b and b392fb6.

⛔ Files ignored due to path filters (2)
  • examples/example-vite-svelte-recs/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • packages/state/src/recs/index.ts (6 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/state/src/recs/index.ts

[error] 175-175: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 181-181: Do not use template literals if interpolation and special-character handling are not needed.

Unsafe fix: Replace with string literal

(lint/style/noUnusedTemplateLiteral)


[error] 236-236: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 296-296: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: check
  • GitHub Check: build
🔇 Additional comments (4)
packages/state/src/recs/index.ts (4)

178-178: Consistent property update from items to models.

Good update to reflect the new API response structure.


183-183: Consistent property updates from items to models.

These updates correctly align with the new API response structure.

Also applies to: 185-185


238-242: Consistent property updates from items to models.

These updates correctly adapt to the new API response structure.


301-301: Consistent property updates from items to models.

These updates correctly align with the new API response structure.

Also applies to: 304-304, 306-306

@ponderingdemocritus ponderingdemocritus merged commit ef79afc into main May 8, 2025
5 checks passed
@ponderingdemocritus ponderingdemocritus deleted the recs-update branch May 8, 2025 01:12
@coderabbitai coderabbitai bot mentioned this pull request May 13, 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