Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Jul 13, 2025

Summary by CodeRabbit

  • New Features

    • Generated TypeScript types for models and input arguments are now split into separate files for improved modularity and clarity.
    • CLI commands for migrations now support a new --migrations <path> option to specify a migrations path.
    • TypeScript types for JSON values are now exported from the runtime package.
  • Enhancements

    • Improved type inference and simplification for model operation results.
    • Expanded enum and relation support in generated types and schema.
    • Added support for the Bytes type in filters and improved checked/unchecked input handling.
  • Bug Fixes

    • Fixed issues with type handling for nested selects, includes, and mutually exclusive relation updates.
  • Documentation

    • Added descriptive comments to schema files and generated model/type files for better clarity.
  • Chores

    • Updated package versions to 3.0.0-alpha.11 across all packages.

ymc9 and others added 6 commits July 11, 2025 15:08
* feat(cli): add --migrations option to migration commands

* update

* update
…ion (#90)

* fix: make helpers package browser-compatible, fix update args validation

* update
…92)

* fix: nested select result typing, simplifying ORM query result types

* Update packages/runtime/src/utils/type-utils.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* update

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* feat: generate input types

* adopting cr comments
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 13, 2025 12:20
@coderabbitai
Copy link

coderabbitai bot commented Jul 13, 2025

Walkthrough

This update introduces recursive type simplification, refines model result and input typings, and modularizes TypeScript schema generation into multiple files. It adds enum support, enhances CLI migration options, and moves the findUp utility locally within the CLI. Numerous package versions are incremented, and new auto-generated typings are produced for models and inputs.

Changes

Files/Paths Change Summary
package.json, packages/*/package.json, samples/blog/package.json, tests/e2e/package.json Bumped version from 3.0.0-alpha.10 to 3.0.0-alpha.11.
TODO.md Added two new TODOs under ORM: strict typing for checked/unchecked input and DbNull vs JsonNull handling.
packages/cli/src/actions/action-utils.ts Removed external findUp import; added local findUp implementation; updated generateTempPrismaSchema to accept optional folder.
packages/cli/src/actions/generate.ts, packages/runtime/test/typing/generate.ts, packages/testtools/src/schema.ts Changed code generation to use output directory instead of file path.
packages/cli/src/actions/migrate.ts, packages/cli/src/index.ts Added --migrations CLI option and passed migrations path to schema generator.
packages/common-helpers/src/find-up.ts, packages/common-helpers/src/index.ts Removed findUp utility and its export.
packages/runtime/src/client/contract.ts Wrapped all ModelOperations return types with recursive Simplify.
packages/runtime/src/client/crud-types.ts Added recursive SimplifiedModelResult; refined relation select logic; renamed input types; added bytes filter; limited some type exports.
packages/runtime/src/client/crud/operations/base.ts Made explicit checks for select/include keys in arguments.
packages/runtime/src/client/crud/operations/find.ts Renamed normalizeArgs variable to normalizedArgs.
packages/runtime/src/client/crud/validator.ts Refactored internal schema separation for checked/unchecked update variants.
packages/runtime/src/index.ts Re-exported JsonArray, JsonObject, JsonValue types.
packages/runtime/src/utils/type-utils.ts Introduced recursive Simplify type; added bytes mapping; removed shallow Simplify.
packages/runtime/test/client-api/update.test.ts Added test for checked/unchecked update typing and foreign key/relation exclusivity.
packages/runtime/test/typing/models.ts, samples/blog/zenstack/models.ts Added auto-generated model typings and enum exports.
packages/runtime/test/typing/schema.ts, packages/runtime/test/typing/typing-test.zmodel, samples/blog/zenstack/schema.zmodel Added Role enum and role field to User; added documentation comments.
packages/runtime/test/typing/verify-typing.ts Added enum usage tests and complex nested select/omit typing checks.
packages/runtime/tsconfig.test.json Set rootDir to "." in test TypeScript config.
packages/sdk/src/ts-schema-generator.ts Refactored to generate schema, models, and input types into separate files; added JSDoc comments and improved import handling.
samples/blog/zenstack/input.ts Added auto-generated input type aliases for models, queries, and mutations.

Possibly related PRs

  • zenstackhq/zenstack-v3#94: Refactors model result typing and introduces SimplifiedModelResult, directly related to this PR's deep type simplification and input type renaming.
  • zenstackhq/zenstack-v3#84: Originally adds the findUp utility to @zenstackhq/common-helpers, which this PR removes and moves locally, showing a direct code relationship.
  • zenstackhq/zenstack-v3#66: Introduces the generateTempPrismaSchema function, which is further refactored in this PR to accept an optional folder parameter.

Poem

🐇
Hopping through the code so neat,
Types now simplified, recursion complete!
Enums and roles in models appear,
CLI migrations made crystal clear.
Input and output, all tidy and bright—
This bunny’s code brings much delight!
🥕✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/cli/src/actions/migrate.ts

Oops! Something went wrong! :(

ESLint: 9.29.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

packages/cli/src/actions/action-utils.ts

Oops! Something went wrong! :(

ESLint: 9.29.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

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

Oops! Something went wrong! :(

ESLint: 9.29.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

  • 17 others
✨ 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.

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

Merge dev into main, bumping versions to 3.0.0-alpha.11 and refactoring core generators, CLI commands, and runtime type handling.

  • Version bump to 3.0.0-alpha.11 across all packages.
  • Refactor TsSchemaGenerator to write separate schema.ts, models.ts, and input.ts files into an output directory, and update CLI and test tooling to match.
  • Add a --migrations option to the CLI’s migrate commands and adjust Prisma schema generation; introduce a deep Simplify type and refine argument normalization/validation in the runtime.

Reviewed Changes

Copilot reviewed 41 out of 41 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/e2e/package.json E2E suite version bump
samples/blog/zenstack/schema.zmodel Add documentation comments for Role enum and models
samples/blog/zenstack/models.ts Update generated model types to include Role and docs
samples/blog/zenstack/input.ts Update generated input type definitions
samples/blog/package.json Sample app version bump
packages/zod/package.json Zod adapter version bump
packages/typescript-config/package.json TypeScript config version bump
packages/testtools/src/schema.ts Update testtools generator call to accept outputDir
packages/testtools/package.json Test tools version bump
packages/tanstack-query/package.json TanStack Query adapter version bump
packages/sdk/src/ts-schema-generator.ts Refactor generate to produce multiple files in a directory
packages/sdk/package.json SDK version bump
packages/runtime/tsconfig.test.json Add rootDir for test compilation
packages/runtime/test/typing/verify-typing.ts Import Role and add enum‐related tests
packages/runtime/test/typing/typing-test.zmodel Define Role enum and default role in test schema
packages/runtime/test/typing/schema.ts Extend test schema object with Role enum metadata
packages/runtime/test/typing/models.ts Update generated runtime test models to include Role
packages/runtime/test/typing/generate.ts Adjust test generator call to use directory output
packages/runtime/test/client-api/update.test.ts Add checked/unchecked typing tests
packages/runtime/src/utils/type-utils.ts Introduce recursive Simplify and extend base type mapping
packages/runtime/src/index.ts Export JSON utilities from type-utils
packages/runtime/src/client/crud/validator.ts Split checked vs. unchecked update schemas
packages/runtime/src/client/crud/operations/find.ts Rename normalizeArgs variable for clarity
packages/runtime/src/client/crud/operations/base.ts Refine argument presence checks for select/include/omit
packages/runtime/src/client/crud-types.ts Rename and export SelectInput/IncludeInput/OmitInput; add SimplifiedModelResult
packages/runtime/src/client/contract.ts Update CRUD return types to use Simplify<>
packages/runtime/package.json Runtime version bump
packages/language/package.json Language spec version bump
packages/ide/vscode/package.json VSCode extension version bump
packages/eslint-config/package.json ESLint config version bump
packages/create-zenstack/package.json Project scaffold version bump
packages/common-helpers/src/index.ts Remove find-up export
packages/common-helpers/src/find-up.ts Delete unused findUp implementation
packages/common-helpers/package.json Common helpers version bump
packages/cli/src/index.ts Add --migrations option to all migrate subcommands
packages/cli/src/actions/migrate.ts Use migrations path when generating temporary Prisma schema
packages/cli/src/actions/generate.ts Update generator invocation to use output directory
packages/cli/src/actions/action-utils.ts Inline findUp and extend temp Prisma schema generator
packages/cli/package.json CLI version bump
package.json Root version bump
TODO.md Add new checklist items for strict typing and DbNull handling
Comments suppressed due to low confidence (2)

packages/runtime/test/typing/verify-typing.ts:188

  • To correctly suppress the expected TypeScript error, replace // TODO: @ts-expect-error with // @ts-expect-error directly above the statement.
    console.log(u.posts[0]?.author?.email);

samples/blog/zenstack/models.ts:28

  • [nitpick] The doc comment for the second Role declaration duplicates the first. Consider updating it to clarify it documents the union type of role values (e.g. User role values).
/**

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: 2

🧹 Nitpick comments (3)
packages/runtime/src/utils/type-utils.ts (1)

9-9: Consider using a more specific function type.

The static analysis tool correctly identifies that using the generic Function type can be a source of bugs. Consider using a more specific function signature if possible.

-type _Preserve = Date | Function | Decimal | Uint8Array | JsonObject | JsonValue;
+type _Preserve = Date | ((...args: any[]) => any) | Decimal | Uint8Array | JsonObject | JsonValue;

Alternatively, if you need to preserve all function-like objects including constructors:

-type _Preserve = Date | Function | Decimal | Uint8Array | JsonObject | JsonValue;
+type _Preserve = Date | ((...args: any[]) => any) | (new (...args: any[]) => any) | Decimal | Uint8Array | JsonObject | JsonValue;
TODO.md (2)

47-47: Fix markdown indentation and good addition to the roadmap.

The TODO item for strict typing is relevant to the type safety improvements in this release. However, the indentation should be corrected.

Apply this diff to fix the markdown indentation:

-        - [ ] Strict typing for checked/unchecked input
+    - [ ] Strict typing for checked/unchecked input

75-75: Fix markdown indentation and valuable addition for null handling.

The TODO item for DbNull vs JsonNull distinction is important for proper null value handling. The indentation needs correction for consistency.

Apply this diff to fix the markdown 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 8398575 and 64cfad0.

📒 Files selected for processing (41)
  • TODO.md (2 hunks)
  • package.json (1 hunks)
  • packages/cli/package.json (1 hunks)
  • packages/cli/src/actions/action-utils.ts (2 hunks)
  • packages/cli/src/actions/generate.ts (1 hunks)
  • packages/cli/src/actions/migrate.ts (2 hunks)
  • packages/cli/src/index.ts (1 hunks)
  • packages/common-helpers/package.json (1 hunks)
  • packages/common-helpers/src/find-up.ts (0 hunks)
  • packages/common-helpers/src/index.ts (0 hunks)
  • packages/create-zenstack/package.json (1 hunks)
  • packages/eslint-config/package.json (1 hunks)
  • packages/ide/vscode/package.json (1 hunks)
  • packages/language/package.json (1 hunks)
  • packages/runtime/package.json (1 hunks)
  • packages/runtime/src/client/contract.ts (15 hunks)
  • packages/runtime/src/client/crud-types.ts (22 hunks)
  • packages/runtime/src/client/crud/operations/base.ts (3 hunks)
  • packages/runtime/src/client/crud/operations/find.ts (1 hunks)
  • packages/runtime/src/client/crud/validator.ts (3 hunks)
  • packages/runtime/src/index.ts (1 hunks)
  • packages/runtime/src/utils/type-utils.ts (2 hunks)
  • packages/runtime/test/client-api/update.test.ts (1 hunks)
  • packages/runtime/test/typing/generate.ts (1 hunks)
  • packages/runtime/test/typing/models.ts (1 hunks)
  • packages/runtime/test/typing/schema.ts (2 hunks)
  • packages/runtime/test/typing/typing-test.zmodel (1 hunks)
  • packages/runtime/test/typing/verify-typing.ts (4 hunks)
  • packages/runtime/tsconfig.test.json (1 hunks)
  • packages/sdk/package.json (1 hunks)
  • packages/sdk/src/ts-schema-generator.ts (2 hunks)
  • packages/tanstack-query/package.json (1 hunks)
  • packages/testtools/package.json (1 hunks)
  • packages/testtools/src/schema.ts (1 hunks)
  • packages/typescript-config/package.json (1 hunks)
  • packages/zod/package.json (1 hunks)
  • samples/blog/package.json (1 hunks)
  • samples/blog/zenstack/input.ts (1 hunks)
  • samples/blog/zenstack/models.ts (1 hunks)
  • samples/blog/zenstack/schema.zmodel (3 hunks)
  • tests/e2e/package.json (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/common-helpers/src/index.ts
  • packages/common-helpers/src/find-up.ts
🧰 Additional context used
🧬 Code Graph Analysis (6)
packages/cli/src/actions/generate.ts (1)
packages/sdk/src/ts-schema-generator.ts (1)
  • TsSchemaGenerator (44-1244)
packages/cli/src/actions/migrate.ts (1)
packages/cli/src/actions/action-utils.ts (1)
  • generateTempPrismaSchema (55-64)
packages/runtime/test/typing/schema.ts (1)
packages/runtime/src/schema/expression.ts (1)
  • ExpressionUtils (16-112)
packages/runtime/test/typing/verify-typing.ts (1)
packages/runtime/test/typing/models.ts (2)
  • Role (17-17)
  • Role (18-18)
packages/runtime/src/client/crud-types.ts (3)
packages/runtime/test/typing/models.ts (1)
  • Schema (10-10)
packages/sdk/src/schema/schema.ts (9)
  • RelationFieldType (155-159)
  • FieldIsOptional (161-165)
  • FieldIsArray (173-177)
  • 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/runtime/src/client/contract.ts (3)
packages/runtime/src/client/promise.ts (1)
  • ZenStackPromise (7-13)
packages/runtime/src/utils/type-utils.ts (1)
  • Simplify (11-17)
packages/runtime/src/client/crud-types.ts (1)
  • ModelResult (115-159)
🪛 markdownlint-cli2 (0.17.2)
TODO.md

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

(MD007, ul-indent)


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)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-test (20.x)
🔇 Additional comments (59)
package.json (1)

3-3: Version bump looks good and consistent with repo-wide update
No further action needed.

tests/e2e/package.json (1)

3-3: E2E package version aligned with root – LGTM
Everything remains coherent across workspaces.

packages/eslint-config/package.json (1)

3-3: eslint-config package version updated correctly
No additional changes required.

packages/typescript-config/package.json (1)

3-3: typescript-config version bump verified
Change is straightforward and consistent.

packages/runtime/package.json (1)

3-3: Runtime package version increment acknowledged
All good; make sure changelog/release notes reflect the coordinated release.

packages/cli/package.json (1)

6-6: Version bump to 3.0.0-alpha.11 looks correct and consistent with the monorepo release cycle
No further action required.

packages/testtools/package.json (1)

3-3: Version updated to 3.0.0-alpha.11 – change is straightforward
All good here.

packages/tanstack-query/package.json (1)

3-3: Package version bump accepted
Matches the coordinated release.

packages/create-zenstack/package.json (1)

3-3: create-zenstack version increment confirmed
Nothing else to note.

packages/ide/vscode/package.json (1)

4-4: VSCode extension version aligns with other packages
Looks good.

packages/runtime/tsconfig.test.json (1)

5-6: LGTM! Appropriate test configuration settings.

The noImplicitAny: false setting provides flexibility for test files, and explicitly setting rootDir improves build consistency.

packages/language/package.json (1)

4-4: LGTM! Standard version bump.

Version increment aligns with the coordinated monorepo release.

packages/zod/package.json (1)

3-3: LGTM! Standard version bump.

Version increment aligns with the coordinated monorepo release.

samples/blog/zenstack/schema.zmodel (1)

6-6: LGTM! Excellent documentation improvements.

The added comments enhance schema readability and provide valuable context for the models and enum.

Also applies to: 12-14, 27-27, 36-36

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

9-17: Excellent recursive type simplification implementation.

The new recursive Simplify type with depth control is a significant improvement that will provide better type safety and performance. The depth limiting mechanism prevents infinite recursion while preserving important types.


37-41: LGTM! Consistent base type mapping extension.

Adding Bytes mapping to Uint8Array properly extends the supported base types.

packages/sdk/package.json (1)

3-3: LGTM: Version bump aligns with coordinated monorepo release.

The alpha version increment is consistent with the broader release updates across all packages.

samples/blog/package.json (1)

3-3: LGTM: Sample application version synchronized with core packages.

The version update maintains consistency across the monorepo.

packages/common-helpers/package.json (1)

3-3: LGTM: Version update supports package restructuring.

The version bump aligns with the removal of the findUp utility from this package, as mentioned in the AI summary.

packages/runtime/test/typing/typing-test.zmodel (2)

6-9: LGTM: Well-structured enum definition.

The Role enum with ADMIN and USER values follows proper ZModel syntax and provides a clear role hierarchy.


17-17: LGTM: Sensible default role assignment.

Adding the role field with a default value of USER is a non-breaking change that provides a reasonable default for new users.

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

11-11: schema.ts is generated correctly; file operations are valid

The fd check confirms that schema.ts is indeed created under packages/runtime/test/typing/, so reading and writing it via tsPath continues to work as expected. No changes needed here.

packages/runtime/src/client/crud/operations/find.ts (1)

8-13: LGTM: Improved variable naming.

The variable renaming from normalizeArgs to normalizedArgs better reflects that it contains the normalized arguments rather than the normalization function. This improves code readability and consistency.

packages/runtime/src/index.ts (1)

2-2: LGTM: Enhanced public API with JSON types.

Adding explicit exports for JsonArray, JsonObject, and JsonValue types improves the public API by making these foundational JSON-related types available to consumers of the runtime package. This enhances type safety and developer experience.

packages/cli/src/actions/generate.ts (1)

27-27: LGTM: Correctly aligns with updated TsSchemaGenerator API.

The change from tsSchemaFile to outputPath correctly aligns with the updated TsSchemaGenerator.generate() method signature, which now expects an output directory and generates multiple files (schema.ts, models.ts, input.ts) within that directory rather than a single output file.

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

40-44: LGTM: Well-formed enum field addition.

The new role field is correctly defined with proper type reference to the Role enum, appropriate default value using ExpressionUtils.literal("USER"), and correct attribute structure.


249-254: LGTM: Properly structured enum definition.

The Role enum is correctly defined with the expected structure, mapping enum values to their string representations. This aligns with the standard enum pattern used throughout the schema.

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

63-63: LGTM: Well-structured reusable CLI option.

The migrationsOption is properly defined as a reusable Option instance, following the existing pattern used for schemaOption.


70-70: LGTM: Consistent option addition across migrate subcommands.

The migrationsOption is correctly added to all relevant migrate subcommands (dev, reset, deploy, status), ensuring consistent CLI interface.

Also applies to: 78-78, 85-85, 92-92

packages/testtools/src/schema.ts (1)

47-47: LGTM: Correct adaptation to modularized schema generation.

The change from passing a specific file path to a directory path aligns with the updated TsSchemaGenerator.generate method that now outputs multiple files (schema.ts, models.ts, input.ts) instead of a single file.

packages/cli/src/actions/migrate.ts (2)

2-2: LGTM: Proper imports and type extension.

The path import is correctly added for directory operations, and the CommonOptions type is appropriately extended with the optional migrations property.

Also applies to: 8-8


29-30: LGTM: Correct implementation of migrations directory handling.

The logic properly extracts the directory from the migrations path using path.dirname and passes it to generateTempPrismaSchema. This aligns with the function signature shown in the relevant code snippets, where the folder parameter defaults to the schema file directory if not provided.

packages/runtime/test/client-api/update.test.ts (1)

174-216: LGTM: Comprehensive test for Prisma typing constraints.

This test case effectively validates the TypeScript typing system for mutually exclusive relation updates and foreign key usage. It correctly tests both the constraint violation (foreign key + owned relation) and the valid usage (foreign key + non-owned relation).

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

1-1: LGTM: Clean import organization and enum support.

Moving the SQLite import to the top improves readability, and the Role import from the new models.ts file correctly supports the modularized type generation.

Also applies to: 3-3


37-37: LGTM: Proper enum usage in query filters.

Using Role.USER in the filter demonstrates correct enum integration with the query API.


151-188: LGTM: Comprehensive nested relation type testing.

These complex nested queries thoroughly test the type system's handling of deep relation traversal, select/include/omit combinations, and proper TypeScript error detection for invalid field access.


607-613: LGTM: Thorough enum type validation.

The enums() function effectively tests enum type safety by validating string-to-enum assignments, enum member usage, and cross-assignments between enum types and string literals.

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

1-32: LGTM! Well-structured auto-generated file.

The auto-generated models file follows good practices with:

  • Clear warning headers about manual modification
  • Proper ESLint disabling
  • Clean type exports using generic $ModelResult type
  • Good documentation comments for each model
packages/runtime/src/client/crud/operations/base.ts (2)

184-196: Improved defensive programming with explicit property checks.

The changes from optional chaining to explicit 'property' in object checks provide better runtime safety by ensuring properties exist before accessing their values. This is particularly important for CRUD operations where args structure may vary.


1882-1902: Consistent defensive programming pattern applied.

The explicit property existence checks in trimResult and needReturnRelations methods follow the same defensive pattern as the earlier changes, improving runtime reliability.

packages/cli/src/actions/action-utils.ts (2)

55-64: Good enhancement with proper parameter handling.

The optional folder parameter adds flexibility while maintaining backward compatibility by defaulting to the zmodelPath directory. The implementation correctly handles the parameter and constructs the output path.


89-112: Well-implemented local findUp utility.

The local implementation correctly handles:

  • Generic typing for single vs multiple results
  • Proper recursion with termination conditions
  • Multiple file name support
  • Path resolution and existence checking

This replaces the external dependency appropriately.

packages/runtime/src/client/crud/validator.ts (1)

927-928: Excellent refactoring for checked/unchecked variant clarity!

The renaming from regularAndFkFields/regularAndRelationFields to uncheckedVariantFields/checkedVariantFields with explicit typing significantly improves code readability. The logic now clearly distinguishes between:

  • Unchecked variants: Can include foreign keys and non-owned relations
  • Checked variants: Exclude foreign keys but include owned relations

This aligns well with Prisma's checked/unchecked input pattern for type safety.

Also applies to: 960-964, 1007-1011, 1016-1019

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

1-19: Well-structured auto-generated typing file!

The file follows best practices for generated code:

  • Clear header warning against manual modifications
  • Proper ESLint disable directive
  • Clean type exports for models and enums
  • Appropriate use of ModelResult generic type
packages/runtime/src/client/crud-types.ts (4)

161-167: Good addition of SimplifiedModelResult type!

The new SimplifiedModelResult type provides a cleaner developer experience by recursively simplifying complex nested types, making them more readable in IDE tooltips and error messages.


81-95: Smart conditional type refinement for nested selections!

The updated logic correctly handles the mutual exclusivity of select and include properties by conditionally passing only the relevant properties to nested ModelResult types. This prevents type conflicts and improves type safety.


227-231: Complete implementation of Bytes filter support!

Good addition of BytesFilter to support filtering on byte array fields, maintaining consistency with other primitive filter types.

Also applies to: 261-268


336-343: Consistent naming convention for input types!

The renaming from Select/Include/OmitFields to SelectInput/IncludeInput/OmitInput creates a more consistent API surface. The addition of specialized FindManyArgs and FindFirstArgs type aliases improves usability.

Also applies to: 354-354, 377-377, 536-538

packages/sdk/src/ts-schema-generator.ts (4)

45-63: Excellent modularization of TypeScript generation!

The refactoring from single-file to multi-file generation is a significant architectural improvement that:

  • Separates concerns into schema.ts, models.ts, and input.ts
  • Reduces file size for better IDE performance
  • Makes generated code more navigable
  • Maintains clean separation between runtime schema and type definitions

967-1066: Well-structured model and enum type generation!

The generateModels method properly:

  • Uses aliased imports to avoid naming conflicts
  • Generates both const and type exports for enums
  • Preserves JSDoc comments from the source schema
  • Follows TypeScript best practices for type aliases

1110-1243: Comprehensive input type generation with good naming strategy!

The generateInputTypes method effectively:

  • Generates all necessary CRUD operation input types
  • Implements a naming fix mapping for better API consistency
  • Includes the generic GetPayload type for flexible result typing
  • Properly uses type-only imports where appropriate

1098-1108: Clean implementation of documentation preservation!

The generateDocs helper method correctly formats multi-line comments into proper JSDoc format, ensuring that schema documentation is preserved in the generated TypeScript code.

packages/runtime/src/client/contract.ts (6)

4-4: LGTM: Proper import of the Simplify utility type.

The import correctly brings in the Simplify utility type that will be used throughout the interface.


302-302: Excellent: Type simplification applied to find operations.

The Simplify wrapper will make the return types more readable and easier to work with in IDEs by flattening complex nested mapped types.

Also applies to: 312-312, 322-322, 332-332, 342-342


398-398: LGTM: Consistent type simplification for create operations.

The type simplification is consistently applied to both create and createManyAndReturn methods.

Also applies to: 449-449


570-570: Approved: Type simplification for update and upsert operations.

The systematic application of Simplify across all update operations maintains consistency in the type experience.

Also applies to: 620-620, 644-644


667-667: LGTM: Type simplification for delete operations.

Note that the delete operation doesn't include the generic T parameter in the Simplify wrapper, which appears correct since it always returns the full model result.


712-712: Great: Type simplification for aggregation operations.

The Simplify wrapper is appropriately applied to count, aggregate, and groupBy operations, ensuring consistent type experience across all model operations.

Also applies to: 733-733, 769-769

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

1-71: LGTM: Well-structured auto-generated input types.

This auto-generated file provides comprehensive type coverage for all CRUD operations across the three models. The use of SimplifiedModelResult in the GetPayload types (lines 30, 50, 70) aligns perfectly with the type simplification improvements introduced in the runtime contract. The consistent naming patterns and proper imports make this a solid foundation for type-safe database operations.

@ymc9 ymc9 added this pull request to the merge queue Jul 13, 2025
Merged via the queue into main with commit 8f8d6de Jul 13, 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