-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat: generate input types #94
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
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis update introduces a new auto-generated Changes
Poem
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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/$Schemaaliases and added a generatedinput.tswith all CRUD argument types. - Generator: extended
TsSchemaGeneratorwithgenerateInputTypesand abstracted schema imports. - Runtime: added
JsonObject/JsonValuesupport, refinedBaseOperationHandlerchecks, and renamed many CRUD types (Select→SelectInput,Include→IncludeInput,OmitFields→OmitInput).
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
exportmodifier has been removed fromMapFieldType, making this previously public type internal. If consumers rely on it, re-addexportor provide a new public alias.
type MapFieldType<
packages/runtime/src/client/crud-types.ts:359
- Previously
CommonPrimitiveFilterwas 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
toImportto its ownts.factory.createImportSpecifierso the printer generates separate specifiers.
ts.factory.createIdentifier(toImport.join(', ')),
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this 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
📒 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
JsonObjectandJsonValueto_Preserveensures 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
inoperator 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
trimResultandneedReturnRelationsmethods 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
SimplifiedModelResultimproves type inference for complex model results- Support for
Bytestype in filters fills a gap in the type system- Renaming types to have
Inputsuffix creates clearer naming conventions- Exporting
FindManyArgsandFindFirstArgsprovides convenient aliases for common operationsAlso applies to: 227-231, 336-338, 354-363, 377-391, 536-537
Summary by CodeRabbit
New Features
Refactor
Chores