Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Jun 16, 2025

Summary by CodeRabbit

  • New Features
    • Added a computed field postCount to the User model, allowing users to access the number of posts authored by a user.
    • Enhanced querying capabilities to filter users based on their postCount.
  • Tests
    • Updated and expanded tests to verify correct behavior and type safety of the new computed field and related query operations.

@coderabbitai
Copy link

coderabbitai bot commented Jun 16, 2025

Walkthrough

A computed field named postCount was added to the User model in both the schema and model definition files. The TypeScript test files were updated to include and verify this new computed field, adjust unique field filters, and demonstrate query builder usage with relevant type checks and error expectations.

Changes

File(s) Change Summary
.../test/typing/schema.ts, .../test/typing/typing-test.zmodel Added postCount computed field to User model; updated schema and model definitions accordingly.
.../test/typing/verify-typing.ts Updated tests to include postCount, adjusted queries and type checks, added a query builder demo.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Suite
    participant Client as ZenStackClient
    participant UserModel as User Model

    Test->>Client: Initialize with computed field postCount
    Test->>Client: find({ where: { id } })
    Client->>UserModel: Fetch user, compute postCount
    UserModel-->>Client: Return user with postCount
    Client-->>Test: Return result

    Test->>Client: findMany({ select: { id: true } })
    Client->>UserModel: Fetch users, omit postCount
    UserModel-->>Client: Return users
    Client-->>Test: Return result

    Test->>Client: queryBuilder().from('User').select(['id', 'email']).where({ name })
    Client->>UserModel: Build and execute query
    UserModel-->>Client: Return selected fields
    Client-->>Test: Return result
Loading

Poem

A field called postCount now appears,
Counting posts, to many cheers!
Computed, not stored, it’s clever and neat,
Type checks ensure it’s tough to beat.
Queries and builders, all tested anew—
Hopping forward, our models grew!
🐇✨

✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

@ymc9 ymc9 merged commit d2393b2 into dev Jun 16, 2025
5 checks passed
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 (3)
packages/runtime/test/typing/schema.ts (2)

6-6: Missing side-effect exclusion in generated import block

OperandExpression is imported only for typing.
Adding /*#__NO_SIDE_EFFECTS__*/ (or the equivalent banner your bundler recognises) prevents tree-shakers from thinking it has runtime side-effects.

-import { type SchemaDef, type OperandExpression, ExpressionUtils } from "../../dist/schema";
+import { /*#__NO_SIDE_EFFECTS__*/ type SchemaDef, /*#__NO_SIDE_EFFECTS__*/ type OperandExpression, ExpressionUtils } from "../../dist/schema";

54-58: Redundant attributes array entry

computed: true already conveys the intent; keeping @computed in attributes is harmless but noisy in the generated JSON.
If your downstream tooling reads computed: true, consider dropping the explicit attribute to keep the generated artefact minimal.

packages/runtime/test/typing/verify-typing.ts (1)

549-559: Possible ambiguity in column names when using $qb

When you select bare 'id' and 'email' without qualifying them ('User.id'), the generated SQL may become ambiguous once joins are introduced later.

-    .select(['id', 'email'])
+    .select(['User.id', 'User.email'])

This keeps the query future-proof if additional joins are appended.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c519480 and 5b85dd3.

📒 Files selected for processing (3)
  • packages/runtime/test/typing/schema.ts (2 hunks)
  • packages/runtime/test/typing/typing-test.zmodel (1 hunks)
  • packages/runtime/test/typing/verify-typing.ts (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/runtime/test/typing/verify-typing.ts (2)
packages/runtime/src/client/client-impl.ts (1)
  • ZenStackClient (41-47)
packages/runtime/test/typing/schema.ts (1)
  • schema (10-250)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build-test (20.x)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
packages/runtime/test/typing/typing-test.zmodel (1)

14-15: postCount computed field looks good

The field is correctly marked @computed, clearly signalling it won't be persisted.
No further concerns.

packages/runtime/test/typing/schema.ts (1)

65-68: ⚠️ Potential issue

Throwing stub will explode at runtime if computedFields override is forgotten

postCount() currently throws.
If someone instantiates the client without supplying the runtime computedFields override, any query that touches postCount will hard-fail.

-    postCount(): OperandExpression<number> {
-        throw new Error("This is a stub for computed field");
-    }
+    /* Returns a dummy expression to satisfy typing; never executed at runtime */
+    postCount(): OperandExpression<number> {
+        return ExpressionUtils.literal(0);
+    }

Switching to ExpressionUtils.literal(0) (or another innocuous expression) keeps type-safety without introducing a hidden runtime foot-gun.

Likely an incorrect or invalid review comment.

packages/runtime/test/typing/verify-typing.ts (2)

4-14: Great use of runtime computedFields override

The builder expression is concise and matches the schema definition. 👍
No issues spotted.


38-47: Solid negative-type tests

The extra @ts-expect-error lines correctly exercise the absence of postCount when omitted.
Nothing to change.

@coderabbitai coderabbitai bot mentioned this pull request Aug 21, 2025
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