Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Jul 13, 2025

Summary by CodeRabbit

  • New Features

    • Added auto-generated input type definitions for all data models, enabling type-safe operations such as find, create, update, and delete.
    • Introduced a simplified model result type for easier type handling.
    • Added support for the 'Bytes' type in query filters.
  • Refactor

    • Standardized and renamed input argument types for improved consistency and clarity.
    • Updated codebase to use unified schema and model type aliases.
  • Chores

    • Enhanced type exports for JSON-related types.
    • Updated internal type preservation logic for JSON types.
    • Added a new checklist item to documentation tasks.

Copilot AI review requested due to automatic review settings July 13, 2025 12:01
@coderabbitai
Copy link

coderabbitai bot commented Jul 13, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update introduces a new auto-generated input.ts file for model operation input types, refactors type naming conventions for consistency, and enhances type safety in runtime and SDK code. It also improves type import patterns, adds support for the 'Bytes' type in filters, and updates type simplification logic to preserve JSON types.

Changes

Files/Groups Change Summary
samples/blog/zenstack/input.ts New auto-generated file defining specialized input and argument types for User, Profile, and Post models.
samples/blog/zenstack/models.ts Updated type and value imports to use $schema, $Schema, and $ModelResult aliases; internal references updated.
TODO.md Added incomplete checklist item: "DbNull vs JsonNull" under ORM tasks.
packages/runtime/src/client/crud-types.ts Added SimplifiedModelResult type, support for 'Bytes' in filters, renamed input types for consistency, updated exports.
packages/runtime/src/client/crud/operations/base.ts Refined checks for select/include keys in argument objects to use explicit property existence checks.
packages/runtime/src/index.ts Re-exported JsonArray, JsonObject, and JsonValue types from type-utils.
packages/runtime/src/utils/type-utils.ts Updated _Preserve type to include JsonObject and JsonValue for type simplification logic.
packages/sdk/src/ts-schema-generator.ts Refactored schema/model type imports, added generateInputTypes to emit input types, adjusted code generation accordingly.

Poem

🐇
In the meadow of types, new seeds are sown,
With input.ts sprouting, all models are grown.
Bytes now filter, JSON stays neat,
Aliased imports make the code complete.
Checklist bunnies hop—one more to go,
As type-safe carrots in the garden grow!
🌱✨


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.

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
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the TypeScript schema generator to produce strongly-typed input definitions alongside models and updates the runtime library to support JSON types and refined CRUD type names.

  • Samples: updated model imports to use $schema/$Schema aliases and added a generated input.ts with all CRUD argument types.
  • Generator: extended TsSchemaGenerator with generateInputTypes and abstracted schema imports.
  • Runtime: added JsonObject/JsonValue support, refined BaseOperationHandler checks, and renamed many CRUD types (SelectSelectInput, IncludeIncludeInput, OmitFieldsOmitInput).

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
samples/blog/zenstack/models.ts Switched to $schema/$Schema and $ModelResult aliases
samples/blog/zenstack/input.ts Added generated CRUD input types for User, Profile, Post
packages/sdk/src/ts-schema-generator.ts Added generateInputTypes, refactored schema import generation
packages/runtime/src/utils/type-utils.ts Extended _Preserve union to include JsonObject/JsonValue
packages/runtime/src/index.ts Re-exported JSON types from type-utils.ts
packages/runtime/src/client/crud/operations/base.ts Updated args checks to use 'prop' in args guard
packages/runtime/src/client/crud-types.ts Renamed and reorganized many CRUD-related type definitions
TODO.md Added DbNull vs JsonNull item
Comments suppressed due to low confidence (3)

packages/runtime/src/client/crud-types.ts:446

  • The export modifier has been removed from MapFieldType, making this previously public type internal. If consumers rely on it, re-add export or provide a new public alias.
type MapFieldType<

packages/runtime/src/client/crud-types.ts:359

  • Previously CommonPrimitiveFilter was exported but now is internal. Consider restoring its export if it's part of the public CRUD type API or updating downstream code to use the new patterns.
> = {

packages/sdk/src/ts-schema-generator.ts:1083

  • The generateSchemaTypeImport helper creates a single ImportSpecifier with a comma-separated string, which leads to invalid import syntax. Instead, map each entry in toImport to its own ts.factory.createImportSpecifier so the printer generates separate specifiers.
                        ts.factory.createIdentifier(toImport.join(', ')),

@ymc9
Copy link
Member Author

ymc9 commented Jul 13, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jul 13, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

🧹 Nitpick comments (1)
TODO.md (1)

75-75: Fix markdown indentation formatting.

The indentation for this list item should be 4 spaces to match the expected markdown format.

Apply this diff to fix the indentation:

-        - [ ] DbNull vs JsonNull
+    - [ ] DbNull vs JsonNull
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a84a1ca and 5a46974.

📒 Files selected for processing (8)
  • TODO.md (1 hunks)
  • packages/runtime/src/client/crud-types.ts (21 hunks)
  • packages/runtime/src/client/crud/operations/base.ts (3 hunks)
  • packages/runtime/src/index.ts (1 hunks)
  • packages/runtime/src/utils/type-utils.ts (1 hunks)
  • packages/sdk/src/ts-schema-generator.ts (6 hunks)
  • samples/blog/zenstack/input.ts (1 hunks)
  • samples/blog/zenstack/models.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/runtime/src/client/crud-types.ts (3)
packages/runtime/test/typing/models.ts (1)
  • Schema (10-10)
packages/sdk/src/schema/schema.ts (6)
  • SchemaDef (10-17)
  • GetModels (94-94)
  • BuiltinType (76-86)
  • NonRelationFields (141-143)
  • GetFields (102-105)
  • RelationInfo (45-52)
packages/runtime/src/utils/type-utils.ts (4)
  • Optional (3-3)
  • Simplify (11-17)
  • OrArray (52-52)
  • XOR (70-70)
packages/sdk/src/ts-schema-generator.ts (2)
packages/language/src/generated/ast.ts (1)
  • isDataModel (354-356)
packages/sdk/src/prisma/prisma-builder.ts (1)
  • Model (115-164)
🪛 markdownlint-cli2 (0.17.2)
TODO.md

75-75: Unordered list indentation
Expected: 4; Actual: 8

(MD007, ul-indent)

🪛 Biome (1.9.4)
packages/runtime/src/utils/type-utils.ts

[error] 9-9: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

packages/runtime/src/client/crud-types.ts

[error] 361-361: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🔇 Additional comments (8)
packages/runtime/src/index.ts (1)

2-2: LGTM! Clean API enhancement for JSON type exports.

This export makes JSON-related types publicly available from the runtime package, supporting the input type generation feature. The type-only export syntax is appropriate here.

samples/blog/zenstack/models.ts (2)

8-9: LGTM! Consistent import naming with $ prefixes.

The systematic renaming to use $ prefixes for schema-related imports improves naming consistency across generated files.


15-27: LGTM! Type references correctly updated.

All type aliases and constant references have been properly updated to use the new prefixed imports, maintaining consistency with the import changes.

packages/runtime/src/utils/type-utils.ts (1)

9-9: LGTM! Appropriate preservation of JSON types during simplification.

Adding JsonObject and JsonValue to _Preserve ensures these JSON-related types maintain their semantic meaning and are not unwantedly simplified during type processing. This aligns well with the JSON type system improvements.

packages/runtime/src/client/crud/operations/base.ts (2)

184-196: LGTM! Improved property existence checks for better type safety.

The explicit checks using the in operator are more robust than optional chaining, as they properly distinguish between undefined properties and properties with falsy values. This ensures correct handling of selection and inclusion arguments.


1882-1896: LGTM! Consistent property existence validation.

The explicit property existence checks in trimResult and needReturnRelations methods maintain consistency with the pattern established in the field selection logic, improving overall robustness.

samples/blog/zenstack/input.ts (1)

1-71: LGTM!

The auto-generated input types file is well-structured with consistent naming conventions and proper TypeScript type definitions. The use of $-prefixed aliases for imports helps avoid potential naming conflicts.

packages/runtime/src/client/crud-types.ts (1)

161-167: Good improvements to type consistency and functionality.

The changes enhance the codebase in several ways:

  • Adding SimplifiedModelResult improves type inference for complex model results
  • Support for Bytes type in filters fills a gap in the type system
  • Renaming types to have Input suffix creates clearer naming conventions
  • Exporting FindManyArgs and FindFirstArgs provides convenient aliases for common operations

Also applies to: 227-231, 336-338, 354-363, 377-391, 536-537

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