Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Nov 15, 2025

Summary by CodeRabbit

  • Refactor

    • Simplified type signatures across client hooks and ORM operations to streamline developer-facing APIs; no runtime behavior changes.
    • Reworked schema exports to use a private backing value with a branded public type for clearer public typings.
  • Type Improvements

    • Reduced generic complexity and removed extraneous type parameters, improving IDE ergonomics and type inference while maintaining compatibility.

Copilot AI review requested due to automatic review settings November 15, 2025 06:37
@coderabbitai
Copy link

coderabbitai bot commented Nov 15, 2025

Caution

Review failed

The pull request is closed.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This PR removes the trailing boolean generic (the true flag) from many ORM argument type generics across client hooks and core CRUD type aliases, and introduces a branded schema export pattern (private _schema + export const schema: Schema = _schema) in multiple schema files. Runtime behavior is unchanged.

Changes

Cohort / File(s) Summary
TanStack Query Hook Signatures
packages/clients/tanstack-query/src/react.ts, packages/clients/tanstack-query/src/svelte.ts, packages/clients/tanstack-query/src/vue.ts
Removed the trailing true generic from hook type constraints (e.g., FindUniqueArgs<Schema, Model, true>FindUniqueArgs<Schema, Model>) across find/create/update/delete/aggregate/groupBy hooks and their Suspense/infinite variants.
ORM Client Contract
packages/orm/src/client/contract.ts
Updated AllModelOperations method signatures to drop the third generic from Arg types (findMany/findUnique/findFirst/create/update/upsert/delete/count/aggregate/groupBy).
CRUD Type Aliases & Filters
packages/orm/src/client/crud-types.ts
Removed Schema parameter from primitive filter types and removed the extra Simplify boolean; refactored Find*/Create*/Update*/Delete*/Count/Aggregate/GroupBy type aliases to concrete forms without the trailing boolean. Removed ProviderSupportsCaseSensitivity.
Base Dialect Filter Builders
packages/orm/src/client/crud/dialects/base-dialect.ts
Adjusted private filter builder signatures and recursive casts to the simplified filter types (e.g., StringFilter<true, boolean>), and updated a buildBytesFilter return to this.and(...conditions.conditions) to align with the new shape.
Schema Generator & Branded Schema Exports
packages/sdk/src/ts-schema-generator.ts, packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts, samples/next.js/zenstack/schema*.ts, samples/orm/zenstack/schema.ts, tests/e2e/**/schema.ts (multiple files)
Replaced direct export const schema = { ... } with an internal const _schema = { ... }, added type Schema = typeof _schema & { __brand?: "schema" }, and re-exported export const schema: Schema = _schema; updated SchemaType to alias Schema.
Sample & Test Schemas (many)
tests/e2e/orm/schemas/*/schema.ts, tests/e2e/apps/rally/zenstack/schema.ts, samples/...
Applied the same branded _schemaschema: Schema pattern across numerous sample and test schema files, preserving runtime values but changing exported typing.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Areas that may need extra attention:

  • packages/orm/src/client/crud-types.ts — dense, high-impact type refactor; verify inference and downstream usages.
  • packages/orm/src/client/crud/dialects/base-dialect.ts — check recursive casts and the changed buildBytesFilter return shape.
  • packages/sdk/src/ts-schema-generator.ts and all schema files — ensure generated/consumed schema typings align with tooling and imports.

Possibly related PRs

Poem

🐰 I hopped through generics, small and true,

I trimmed the extra flag to two,
I boxed the schema, _schema snug,
And gifted types a tiny hug.
A rabbit's nibble on stray generics—chew!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: removing a third generic parameter from ORM type definitions to simplify type display, which is the central theme across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04dc3ca and 9f20e3b.

📒 Files selected for processing (1)
  • packages/orm/src/client/crud-types.ts (8 hunks)

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude
Copy link

claude bot commented Nov 15, 2025

Claude finished @ymc9's task —— View job


PR Review: TypeScript Type Display Simplification

I've completed my review of this pull request focusing on code quality, potential issues, performance, and security considerations.

Todo List:

  • Analyze core type system changes in crud-types.ts
  • Review type generation changes in ts-schema-generator.ts
  • Check contract interface updates in contract.ts
  • Review client integration changes in tanstack-query packages
  • Examine schema file updates across samples and tests
  • Assess overall code quality and best practices
  • Check for potential bugs or breaking changes
  • Evaluate performance implications
  • Review security considerations
  • Provide comprehensive feedback

Analysis Summary

This PR implements a well-architected TypeScript type simplification that should significantly improve developer experience by making generated types more readable and reducing TypeScript compiler overhead.


Strengths

Type System Improvements

  • Reduced generic parameter bloat: Removed unnecessary Schema parameter from filter types (PrimitiveFilter, StringFilter, etc.) - this is a smart optimization
  • Schema branding pattern: Added branded types Schema & { __brand?: "schema" } to prevent TypeScript from expanding complex schema types in IntelliSense
  • Consistent simplification: New SimplifiedModelResult wrapper provides consistent type simplification across the API
  • Clean migration: All tanstack-query hooks properly updated to use simplified types

Code Quality

  • Generator improvements: The ts-schema-generator.ts changes show good engineering - conditional imports, proper tracking of expression utilities
  • Consistent patterns: Schema generation consistently applies the branding pattern across all generated files
  • Backward compatibility: Changes appear to maintain API compatibility while improving type display

⚠️ Areas of Concern

Potential Breaking Changes

  1. Generic parameter removal: Removing the Schema parameter from filter types could be breaking if external libraries depend on the full type signature
    • Recommendation: Verify no downstream packages use these internal types directly

Type Safety Verification Needed

  1. Provider-specific type features: The removal of ProviderSupportsCaseSensitivity<Schema> logic in StringFilter needs verification:

    // Before: Conditional mode based on provider
    ProviderSupportsCaseSensitivity<Schema> extends true ? { mode?: ... } : {}
    // After: Always available
    mode?: 'default' | 'insensitive';
    • Recommendation: Ensure this doesn't enable unsupported features for SQLite
  2. Schema parameter usage: Need to verify the Schema parameter wasn't providing essential type constraints in edge cases


🚀 Performance Benefits

Compilation Performance

  • Reduced type complexity: Fewer generic parameters = faster TypeScript compilation
  • Type display optimization: Branded schema types prevent expensive type expansion in IDEs
  • IntelliSense improvements: Developers should see cleaner, more readable type hints

Bundle Size

  • Type erasure: These changes are compile-time only and won't affect runtime bundle size

🔒 Security Assessment

No Security Risks Identified

  • Type-only changes: All modifications are at the TypeScript type level
  • No runtime changes: Generated JavaScript remains the same
  • Schema validation preserved: Core validation logic appears unaffected

📋 Specific File Analysis

crud-types.ts - packages/orm/src/client/crud-types.ts:230-320

  • Good: Simplified filter type hierarchy
  • Concern: Verify provider-specific features still work correctly

ts-schema-generator.ts - packages/sdk/src/ts-schema-generator.ts:172-189

  • Excellent: Schema branding implementation is clean and well-documented
  • Good: Conditional import handling shows attention to detail

Generated schemas - tests/e2e/orm/schemas/*/schema.ts

  • Good: Consistent application of branding pattern
  • Good: Proper TypeScript satisfaction with satisfies SchemaDef

🎯 Recommendations

Pre-merge Testing

  1. Run comprehensive type tests: Ensure all existing type tests pass
  2. Provider compatibility: Test with both SQLite and PostgreSQL to verify provider-specific features
  3. Integration testing: Test with real-world usage patterns in samples

Documentation

  1. Update type documentation: If any public types changed, update relevant documentation
  2. Migration notes: Consider adding notes about any breaking changes to CHANGELOG

Future Considerations

  1. Monitor TypeScript performance: Track compilation time improvements
  2. Developer feedback: Monitor developer reports about type display quality

🏆 Overall Assessment

Rating: ⭐⭐⭐⭐⭐ Excellent

This is a high-quality improvement that addresses a real developer pain point. The implementation is thoughtful, consistent, and should provide measurable benefits to TypeScript compilation performance and developer experience.

The changes demonstrate good engineering practices:

  • Systematic approach to type simplification
  • Preservation of type safety where possible
  • Consistent application across the codebase
  • Proper handling of generated code patterns

Recommendation: ✅ Approve with testing

This PR should be merged after verifying that:

  1. All existing tests pass
  2. Provider-specific features work correctly
  3. No breaking changes in downstream usage

Copilot finished reviewing on behalf of ymc9 November 15, 2025 06:38
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 reimplements TypeScript type display simplification by introducing a branded type pattern for schema definitions and removing the Simplify boolean generic parameter from various type definitions. The goal is to prevent TypeScript from expanding complex types while maintaining type safety.

Key changes:

  • Introduces a branded type pattern for schema objects using type Schema = typeof _schema & { __brand?: 'schema' }
  • Removes the Simplify boolean parameter from all Args types (FindManyArgs, CreateArgs, etc.)
  • Removes the Schema generic parameter from primitive filter types (StringFilter, NumberFilter, etc.)

Reviewed Changes

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

Show a summary per file
File Description
packages/sdk/src/ts-schema-generator.ts Implements the schema generation logic with branded types
packages/orm/src/client/crud-types.ts Removes Simplify parameters and Schema generic from filter types; removes SimplifyIf import and ProviderSupportsCaseSensitivity helper
packages/orm/src/client/crud/dialects/base-dialect.ts Updates filter method signatures to match new type definitions
packages/orm/src/client/contract.ts Updates all model operation signatures to remove Simplify parameter
packages/clients/tanstack-query/src/*.ts Updates hook signatures for react, vue, and svelte to remove Simplify parameter
tests/e2e/orm/schemas/*/schema.ts Regenerated schema files following the new branded type pattern
tests/e2e/apps/rally/zenstack/schema.ts Regenerated schema file
samples//zenstack/schema.ts Regenerated schema files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/orm/src/client/crud-types.ts (2)

207-242: Thread WithAggregations through recursive AND/OR/NOT branches to preserve nested aggregate filters in GroupByHaving

Verification confirms the bug: GroupByHaving passes WhereInput<Schema, Model, true, true> with WithAggregations=true, but the recursive AND/OR/NOT at lines 239–241 drop this parameter entirely. This breaks access to aggregate-aware filters (like _count, _avg, _sum) in nested logical conditions, since all filter types conditionally include these fields only when WithAggregations is true.

Fix by threading WithAggregations through:

} & {
-    AND?: OrArray<WhereInput<Schema, Model, ScalarOnly>>;
-    OR?: WhereInput<Schema, Model, ScalarOnly>[];
-    NOT?: OrArray<WhereInput<Schema, Model, ScalarOnly>>;
+    AND?: OrArray<WhereInput<Schema, Model, ScalarOnly, WithAggregations>>;
+    OR?: WhereInput<Schema, Model, ScalarOnly, WithAggregations>[];
+    NOT?: OrArray<WhereInput<Schema, Model, ScalarOnly, WithAggregations>>;
};

244-263: String filter mode field lacks provider-specific TypeScript gating; runtime validation is insufficient

The StringFilter type now unconditionally permits mode?: 'default' | 'insensitive' regardless of provider, but runtime validation only allows this field for PostgreSQL (via providerSupportsCaseSensitivity check in validator/index.ts:1534-1535). When clients provide mode on unsupported providers, Zod rejects it as an unrecognized key with a generic validation error rather than signaling provider incompatibility.

This is a legitimate behavior change: compile-time protection has been removed. While runtime validation catches the issue, the developer experience is poor—valid TypeScript code fails at runtime with an unclear error message.

Recommendation: Either restore provider-specific TypeScript-level gating (e.g., ProviderSupportsCaseSensitivity<Schema> helper similar to ProviderSupportsDistinct<Schema>) or enhance error messaging to explicitly state "mode 'insensitive' is not supported for this provider."

🧹 Nitpick comments (2)
packages/orm/src/client/crud/dialects/base-dialect.ts (2)

607-619: Consider loosening StringFilter generics for consistency

The change to payload: StringFilter<true, boolean> and the recursive cast keeps behavior the same, but it’s more specific than the other helpers (BooleanFilter<boolean, boolean>, etc.). For symmetry with the crud-types definitions and to avoid over-constraining future call sites, consider changing this to StringFilter<boolean, boolean> (and the recursive cast likewise), unless Nullable=true is intentionally required here.


711-721: Bytes filter bugfix is correct; minor naming cleanup possible

Switching to BytesFilter<boolean, boolean> and returning this.and(...conditions.conditions) correctly uses the object returned by buildStandardFilter and fixes the prior misuse of the entire result object as a condition list. For readability and consistency with nearby helpers, you could destructure as:

-    private buildBytesFilter(fieldRef: Expression<any>, payload: BytesFilter<boolean, boolean>) {
-        const conditions = this.buildStandardFilter(
+    private buildBytesFilter(fieldRef: Expression<any>, payload: BytesFilter<boolean, boolean>) {
+        const { conditions } = this.buildStandardFilter(
             'Bytes',
             payload,
             fieldRef,
             (value) => this.transformPrimitive(value, 'Bytes', false),
             (value) => this.buildBytesFilter(fieldRef, value as BytesFilter<boolean, boolean>),
             true,
             ['equals', 'in', 'notIn', 'not'],
         );
-        return this.and(...conditions.conditions);
+        return this.and(...conditions);
     }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 769473c and 04dc3ca.

📒 Files selected for processing (19)
  • packages/clients/tanstack-query/src/react.ts (1 hunks)
  • packages/clients/tanstack-query/src/svelte.ts (1 hunks)
  • packages/clients/tanstack-query/src/vue.ts (1 hunks)
  • packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (2 hunks)
  • packages/orm/src/client/contract.ts (17 hunks)
  • packages/orm/src/client/crud-types.ts (8 hunks)
  • packages/orm/src/client/crud/dialects/base-dialect.ts (3 hunks)
  • packages/sdk/src/ts-schema-generator.ts (2 hunks)
  • samples/next.js/zenstack/schema-lite.ts (2 hunks)
  • samples/next.js/zenstack/schema.ts (2 hunks)
  • samples/orm/zenstack/schema.ts (2 hunks)
  • tests/e2e/apps/rally/zenstack/schema.ts (2 hunks)
  • tests/e2e/orm/schemas/basic/schema.ts (2 hunks)
  • tests/e2e/orm/schemas/default-auth/schema.ts (2 hunks)
  • tests/e2e/orm/schemas/delegate/schema.ts (2 hunks)
  • tests/e2e/orm/schemas/name-mapping/schema.ts (2 hunks)
  • tests/e2e/orm/schemas/petstore/schema.ts (2 hunks)
  • tests/e2e/orm/schemas/todo/schema.ts (2 hunks)
  • tests/e2e/orm/schemas/typing/schema.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-10-21T16:09:31.218Z
Learnt from: ymc9
Repo: zenstackhq/zenstack-v3 PR: 319
File: packages/runtime/src/client/executor/zenstack-query-executor.ts:63-72
Timestamp: 2025-10-21T16:09:31.218Z
Learning: In ZenStack, TypeDefs can be inherited by models. When a TypeDef contains fields with `map` attributes, those mapped field names need to be processed by the QueryNameMapper since they become part of the inheriting model's schema. Therefore, when checking if a schema has mapped names (e.g., in `schemaHasMappedNames`), both `schema.models` and `schema.typeDefs` must be inspected for `@map` and `map` attributes.

Applied to files:

  • tests/e2e/apps/rally/zenstack/schema.ts
  • samples/orm/zenstack/schema.ts
  • samples/next.js/zenstack/schema-lite.ts
  • samples/next.js/zenstack/schema.ts
📚 Learning: 2025-10-21T16:04:56.292Z
Learnt from: ymc9
Repo: zenstackhq/zenstack-v3 PR: 319
File: packages/runtime/src/client/crud/dialects/base-dialect.ts:745-747
Timestamp: 2025-10-21T16:04:56.292Z
Learning: In packages/runtime/src/client/crud/dialects/base-dialect.ts, it's intentional that buildCursorFilter applies default ordering (via makeDefaultOrderBy fallback) while buildOrderBy does not. This ensures cursor-based pagination always has stable ordering for correctness, while regular queries remain unordered unless explicitly specified. This design is to be consistent with Prisma's pagination requirements.

Applied to files:

  • packages/orm/src/client/crud/dialects/base-dialect.ts
  • packages/orm/src/client/crud-types.ts
🧬 Code graph analysis (18)
tests/e2e/orm/schemas/typing/schema.ts (4)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (2)
  • schema (175-175)
  • SchemaType (176-176)
samples/next.js/zenstack/schema.ts (2)
  • schema (118-118)
  • SchemaType (119-119)
packages/orm/src/client/crud/validator/index.ts (1)
  • schema (60-62)
packages/plugins/policy/src/expression-transformer.ts (1)
  • schema (81-83)
tests/e2e/orm/schemas/basic/schema.ts (4)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (2)
  • schema (175-175)
  • SchemaType (176-176)
samples/next.js/zenstack/schema.ts (2)
  • schema (118-118)
  • SchemaType (119-119)
packages/orm/src/client/crud/validator/index.ts (1)
  • schema (60-62)
packages/plugins/policy/src/expression-transformer.ts (1)
  • schema (81-83)
tests/e2e/orm/schemas/name-mapping/schema.ts (3)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (2)
  • schema (175-175)
  • SchemaType (176-176)
packages/orm/src/client/crud/validator/index.ts (1)
  • schema (60-62)
packages/plugins/policy/src/expression-transformer.ts (1)
  • schema (81-83)
tests/e2e/orm/schemas/todo/schema.ts (3)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (2)
  • schema (175-175)
  • SchemaType (176-176)
packages/orm/src/client/crud/validator/index.ts (1)
  • schema (60-62)
packages/plugins/policy/src/expression-transformer.ts (1)
  • schema (81-83)
tests/e2e/apps/rally/zenstack/schema.ts (3)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (2)
  • schema (175-175)
  • SchemaType (176-176)
samples/next.js/zenstack/schema.ts (2)
  • schema (118-118)
  • SchemaType (119-119)
tests/e2e/orm/schemas/basic/schema.ts (2)
  • schema (290-290)
  • SchemaType (291-291)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (11)
samples/next.js/zenstack/schema-lite.ts (2)
  • schema (109-109)
  • SchemaType (110-110)
samples/next.js/zenstack/schema.ts (2)
  • schema (118-118)
  • SchemaType (119-119)
samples/orm/zenstack/schema.ts (2)
  • schema (247-247)
  • SchemaType (248-248)
tests/e2e/apps/rally/zenstack/schema.ts (2)
  • schema (2526-2526)
  • SchemaType (2527-2527)
tests/e2e/orm/schemas/basic/schema.ts (2)
  • schema (290-290)
  • SchemaType (291-291)
tests/e2e/orm/schemas/default-auth/schema.ts (2)
  • schema (125-125)
  • SchemaType (126-126)
tests/e2e/orm/schemas/delegate/schema.ts (2)
  • schema (468-468)
  • SchemaType (469-469)
tests/e2e/orm/schemas/name-mapping/schema.ts (2)
  • schema (126-126)
  • SchemaType (127-127)
tests/e2e/orm/schemas/petstore/schema.ts (2)
  • schema (160-160)
  • SchemaType (161-161)
tests/e2e/orm/schemas/todo/schema.ts (2)
  • schema (399-399)
  • SchemaType (400-400)
tests/e2e/orm/schemas/typing/schema.ts (2)
  • schema (350-350)
  • SchemaType (351-351)
tests/e2e/orm/schemas/default-auth/schema.ts (5)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (2)
  • schema (175-175)
  • SchemaType (176-176)
samples/next.js/zenstack/schema-lite.ts (2)
  • schema (109-109)
  • SchemaType (110-110)
samples/next.js/zenstack/schema.ts (2)
  • schema (118-118)
  • SchemaType (119-119)
samples/orm/zenstack/schema.ts (2)
  • schema (247-247)
  • SchemaType (248-248)
tests/e2e/orm/schemas/basic/schema.ts (2)
  • schema (290-290)
  • SchemaType (291-291)
tests/e2e/orm/schemas/petstore/schema.ts (5)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (2)
  • schema (175-175)
  • SchemaType (176-176)
samples/next.js/zenstack/schema-lite.ts (2)
  • schema (109-109)
  • SchemaType (110-110)
samples/next.js/zenstack/schema.ts (2)
  • schema (118-118)
  • SchemaType (119-119)
packages/orm/src/client/crud/validator/index.ts (1)
  • schema (60-62)
packages/plugins/policy/src/expression-transformer.ts (1)
  • schema (81-83)
samples/orm/zenstack/schema.ts (4)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (2)
  • schema (175-175)
  • SchemaType (176-176)
samples/next.js/zenstack/schema.ts (2)
  • schema (118-118)
  • SchemaType (119-119)
tests/e2e/orm/schemas/todo/schema.ts (2)
  • schema (399-399)
  • SchemaType (400-400)
packages/orm/src/client/crud/validator/index.ts (1)
  • schema (60-62)
samples/next.js/zenstack/schema-lite.ts (3)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (2)
  • schema (175-175)
  • SchemaType (176-176)
samples/next.js/zenstack/schema.ts (2)
  • schema (118-118)
  • SchemaType (119-119)
samples/orm/zenstack/schema.ts (2)
  • schema (247-247)
  • SchemaType (248-248)
packages/clients/tanstack-query/src/svelte.ts (1)
packages/orm/src/client/crud-types.ts (18)
  • FindUniqueArgs (663-665)
  • SelectSubset (502-508)
  • SimplifiedModelResult (181-187)
  • FindFirstArgs (661-661)
  • FindManyArgs (659-659)
  • CreateArgs (671-673)
  • CreateManyArgs (675-675)
  • CreateManyAndReturnArgs (677-681)
  • UpdateArgs (807-810)
  • UpdateManyArgs (812-815)
  • UpdateManyAndReturnArgs (817-821)
  • UpsertArgs (829-833)
  • DeleteArgs (945-947)
  • DeleteManyArgs (949-952)
  • CountArgs (958-963)
  • Subset (498-500)
  • AggregateArgs (983-997)
  • GroupByArgs (1068-1085)
packages/clients/tanstack-query/src/vue.ts (1)
packages/orm/src/client/crud-types.ts (13)
  • FindUniqueArgs (663-665)
  • SelectSubset (502-508)
  • SimplifiedModelResult (181-187)
  • FindFirstArgs (661-661)
  • FindManyArgs (659-659)
  • CreateArgs (671-673)
  • UpdateArgs (807-810)
  • UpsertArgs (829-833)
  • DeleteArgs (945-947)
  • CountArgs (958-963)
  • Subset (498-500)
  • AggregateArgs (983-997)
  • GroupByArgs (1068-1085)
packages/orm/src/client/contract.ts (1)
packages/orm/src/client/crud-types.ts (15)
  • FindManyArgs (659-659)
  • FindUniqueArgs (663-665)
  • FindFirstArgs (661-661)
  • CreateArgs (671-673)
  • CreateManyArgs (675-675)
  • CreateManyAndReturnArgs (677-681)
  • UpdateArgs (807-810)
  • UpdateManyArgs (812-815)
  • UpdateManyAndReturnArgs (817-821)
  • UpsertArgs (829-833)
  • DeleteArgs (945-947)
  • DeleteManyArgs (949-952)
  • CountArgs (958-963)
  • AggregateArgs (983-997)
  • GroupByArgs (1068-1085)
packages/clients/tanstack-query/src/react.ts (1)
packages/orm/src/client/crud-types.ts (18)
  • FindUniqueArgs (663-665)
  • SelectSubset (502-508)
  • SimplifiedModelResult (181-187)
  • FindFirstArgs (661-661)
  • FindManyArgs (659-659)
  • CreateArgs (671-673)
  • CreateManyArgs (675-675)
  • CreateManyAndReturnArgs (677-681)
  • UpdateArgs (807-810)
  • UpdateManyArgs (812-815)
  • UpdateManyAndReturnArgs (817-821)
  • UpsertArgs (829-833)
  • DeleteArgs (945-947)
  • DeleteManyArgs (949-952)
  • CountArgs (958-963)
  • Subset (498-500)
  • AggregateArgs (983-997)
  • GroupByArgs (1068-1085)
tests/e2e/orm/schemas/delegate/schema.ts (5)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (2)
  • schema (175-175)
  • SchemaType (176-176)
samples/next.js/zenstack/schema-lite.ts (2)
  • schema (109-109)
  • SchemaType (110-110)
samples/next.js/zenstack/schema.ts (2)
  • schema (118-118)
  • SchemaType (119-119)
packages/orm/src/client/crud/validator/index.ts (1)
  • schema (60-62)
packages/plugins/policy/src/expression-transformer.ts (1)
  • schema (81-83)
packages/orm/src/client/crud/dialects/base-dialect.ts (1)
packages/orm/src/client/crud-types.ts (4)
  • StringFilter (306-319)
  • BooleanFilter (364-375)
  • DateTimeFilter (338-347)
  • BytesFilter (349-362)
samples/next.js/zenstack/schema.ts (2)
packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (2)
  • schema (175-175)
  • SchemaType (176-176)
samples/next.js/zenstack/schema-lite.ts (2)
  • schema (109-109)
  • SchemaType (110-110)
packages/orm/src/client/crud-types.ts (2)
packages/orm/src/utils/type-utils.ts (3)
  • NullableIf (5-5)
  • OrArray (52-52)
  • NonEmptyArray (54-54)
packages/schema/src/schema.ts (3)
  • SchemaDef (11-19)
  • GetModels (120-120)
  • NonRelationFields (204-208)
⏰ 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). (3)
  • GitHub Check: build-test (20.x, sqlite)
  • GitHub Check: build-test (20.x, postgresql)
  • GitHub Check: claude-review
🔇 Additional comments (23)
samples/next.js/zenstack/schema-lite.ts (4)

9-9: LGTM! Internal constant extraction supports branding pattern.

The refactor to an internal _schema constant enables the branded type export pattern while maintaining identical runtime behavior. This is a clean separation of concerns between the data structure and its public type interface.


106-108: LGTM! Well-implemented branded type pattern.

The branded Schema type using an optional __brand field is a standard TypeScript technique for nominal typing. This provides type-level distinction without runtime overhead, since the optional field doesn't need to exist at runtime. The pattern is consistent with other schema files in the codebase.


109-109: LGTM! Public export correctly applies branded type.

The export statement correctly assigns the internal _schema to the public schema export with the branded Schema type. This maintains the same runtime value while applying type-level branding for enhanced type safety.


110-110: LGTM! Type alias correctly updated for consistency.

The SchemaType export now directly references the Schema branded type instead of inferring from typeof schema. This is clearer and maintains consistency with the branding pattern implemented throughout the codebase.

packages/orm/src/client/crud/dialects/base-dialect.ts (2)

686-693: Boolean filter generic update looks correct

Using BooleanFilter<boolean, boolean> and recursing with the same type aligns with the updated BooleanFilter definition and keeps runtime behavior unchanged. Restricting keys to ['equals', 'not'] still matches the intended non-aggregate boolean where filters.


699-706: DateTime filter generic update looks correct

The new signature DateTimeFilter<boolean, boolean> and recursive cast are consistent with the new DateTimeFilter type and mirror the number filter behavior. No functional changes introduced.

samples/orm/zenstack/schema.ts (1)

9-9: Branded schema pattern looks consistent and safe

Using an internal _schema with as const satisfies SchemaDef, a branded Schema type, and exporting schema: Schema / SchemaType = Schema matches the new pattern elsewhere and keeps runtime shape unchanged while improving type identity. No issues spotted here.

Also applies to: 244-248

samples/next.js/zenstack/schema.ts (1)

9-9: Next.js schema branding matches the shared pattern

The introduction of _schema, branded Schema, and the schema: Schema / SchemaType = Schema exports is consistent with other generated schemas and should preserve all existing consumers while avoiding type expansion.

Also applies to: 115-119

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

151-216: AST generation correctly updated for branded schema exports

The new statements (_schema declaration with as const satisfies SchemaDef, branded Schema alias, schema: Schema = _schema, and SchemaType = Schema) accurately generate the desired TS pattern and align with the hand-written schema files, without changing runtime behavior.

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

658-683: CRUD arg type simplification is consistent with updated API surface

The simplification of FindManyArgs/FindFirstArgs/FindUniqueArgs, create/update/delete args, and CountArgs/AggregateArgs/GroupByArgs to drop the extra generic parameter and rely on the more direct shapes in this file aligns with the updated method signatures in contract.ts. The use of SelectIncludeOmit<Schema, Model, ...> and the new CreateManyAndReturnArgs / UpdateManyAndReturnArgs shapes also looks internally consistent.

I’d just recommend running a full tsc over the repo to ensure no remaining references to the old 3‑parameter arg types (e.g., <Schema, Model, true>) remain in downstream code.

Also applies to: 806-834, 945-952, 958-963, 983-997, 1068-1085

packages/orm/src/client/contract.ts (1)

246-799: Client contract generics are correctly aligned with the new CRUD arg types

All model operation methods now constrain T against the simplified arg aliases (FindManyArgs<Schema, Model>, CreateArgs<Schema, Model>, etc.) and still use SelectSubset/Subset plus SimplifiedModelResult for results, which matches the refactored definitions in crud-types.ts. The transactional and plugin-related parts remain untouched.

Looks coherent and should be backward compatible at the call‑site level as long as everything compiles after the arg type changes.

tests/e2e/orm/schemas/typing/schema.ts (1)

9-351: Schema branding and re-export pattern looks correct

Rebinding the schema object to _schema, introducing the branded Schema type, and exporting schema: Schema / SchemaType = Schema keeps the runtime shape intact and matches the new standardized pattern used elsewhere. I don’t see any issues here.

Please rerun TypeScript type-checks for the typing E2E suite to confirm there are no unexpected type incompatibilities with consumers of schema / SchemaType.

tests/e2e/apps/rally/zenstack/schema.ts (1)

9-2527: Rally schema branding change is consistent and non-breaking

The switch to an internal _schema, branded Schema type, and schema: Schema / SchemaType = Schema export is consistent with other schema files and shouldn’t affect runtime behavior or callers importing schema / SchemaType.

Given how widely this schema is used in the rally E2E app, please run the rally test suite or at least a type-check over its usages to ensure everything still compiles cleanly.

tests/e2e/orm/schemas/basic/schema.ts (1)

9-291: Basic ORM schema branding matches the new standard

Using _schema plus the internal branded Schema type and exporting schema: Schema and SchemaType = Schema is consistent with the rest of the codebase and keeps the existing runtime/data shape. No issues spotted.

Please ensure the ORM “basic” E2E tests and type-checks are run so any accidental breakage in downstream SchemaType consumers is caught.

tests/e2e/orm/schemas/petstore/schema.ts (1)

9-161: Petstore schema branding refactor looks good

The refactor to _schema with a branded Schema type and the schema / SchemaType exports follows the same pattern as other schemas and should be a pure typing-surface change without runtime impact.

As this schema participates in authorization rules, please run the petstore-related E2E tests to confirm policy logic still type-checks and behaves as expected.

tests/e2e/orm/schemas/name-mapping/schema.ts (1)

9-127: Name‑mapping schema branding aligns with prior pattern

The move to an internal _schema plus branded Schema type, and exporting schema: Schema / SchemaType = Schema, is consistent with the rest of the PR and keeps the mapped-name structure untouched.

Because this schema is specifically about name-mapping, please rerun the corresponding E2E/name-mapping tests to verify that any tooling relying on mapped names still works correctly with the branded SchemaType.

tests/e2e/orm/schemas/delegate/schema.ts (1)

9-469: Branded Schema surface looks correct and preserves runtime behavior

Using an internal _schema that satisfies SchemaDef and exporting schema: Schema = _schema with type Schema = typeof _schema & { __brand?: 'schema' } keeps the runtime object unchanged while giving you a stable, branded schema type. This stays structurally compatible with SchemaDef and matches the pattern used in other schema files.

packages/clients/tanstack-query/test/schemas/basic/schema-lite.ts (1)

9-176: Consistent schema branding for test schema-lite

This file follows the same _schema + branded Schema + SchemaType = Schema pattern as the other generated schemas, keeping the runtime shape and SchemaDef compatibility intact while stabilizing the exported type.

tests/e2e/orm/schemas/default-auth/schema.ts (1)

9-126: Default-auth schema branding matches new pattern

The introduction of _schema, the branded Schema type, and exporting schema: Schema = _schema cleanly updates the type surface while leaving the generated schema data and SchemaDef compatibility unchanged.

tests/e2e/orm/schemas/todo/schema.ts (1)

9-400: Todo schema export now correctly uses branded Schema

Wrapping the existing literal in _schema and exposing schema: Schema = _schema with SchemaType = Schema is consistent with the rest of the codebase and should simplify typing without affecting E2E behavior.

packages/clients/tanstack-query/src/svelte.ts (1)

141-211: Approve: hook generics updated to two-parameter arg types and verified
All tanstack-query hook signatures use XxxArgs<Schema, Model>; crud-types.ts exposes matching two-parameter aliases and a repo scan found no remaining true 3‑arity usages (delete.ts hits were nested-generic false positives).

packages/clients/tanstack-query/src/vue.ts (1)

125-195: Vue ModelQueryHooks generics now correctly mirror updated ORM arg types

The removal of the third generic parameter from all *Args<Schema, Model> constraints is consistent with the updated ORM type aliases and keeps the SimplifiedModelResult<Schema, Model, T, ...> flow intact. No runtime paths are impacted, and the Vue hooks surface stays aligned with React/Svelte.

packages/clients/tanstack-query/src/react.ts (1)

148-253: React ModelQueryHooks type simplification is consistent and non-breaking

All hook generics now use the simplified *Args<Schema, Model> aliases (including suspense/infinite variants), matching the ORM definitions and other clients. This is a clean type-only change with no runtime impact and keeps the React hooks surface consistent across the SDK.

@ymc9 ymc9 merged commit ed931da into dev Nov 15, 2025
4 of 5 checks passed
@claude
Copy link

claude bot commented Nov 15, 2025

Claude finished @ymc9's task —— View job


PR Review: TypeScript Type Display Simplification

I've completed my review of this pull request focusing on code quality, potential issues, performance, and security considerations.

Todo List:

  • Analyze core type system changes in crud-types.ts
  • Review type generation changes in ts-schema-generator.ts
  • Check contract interface updates in contract.ts
  • Review client integration changes in tanstack-query packages
  • Examine schema file updates across samples and tests
  • Assess overall code quality and best practices
  • Check for potential bugs or breaking changes
  • Evaluate performance implications
  • Review security considerations
  • Provide comprehensive feedback

Analysis Summary

This PR implements a well-architected TypeScript type simplification that should significantly improve developer experience by making generated types more readable and reducing TypeScript compiler overhead.


Strengths

Type System Improvements

  • Reduced generic parameter bloat: Removed unnecessary Schema parameter from filter types (PrimitiveFilter, StringFilter, etc.) - this is a smart optimization
  • Schema branding pattern: Added branded types Schema & { __brand?: "schema" } to prevent TypeScript from expanding complex schema types in IntelliSense
  • Consistent simplification: New SimplifiedModelResult wrapper provides consistent type simplification across the API
  • Clean migration: All tanstack-query hooks properly updated to use simplified types

Code Quality

  • Generator improvements: The ts-schema-generator.ts changes show good engineering - conditional imports, proper tracking of expression utilities
  • Consistent patterns: Schema generation consistently applies the branding pattern across all generated files
  • Backward compatibility: Changes appear to maintain API compatibility while improving type display

⚠️ Areas of Concern

Potential Breaking Changes

  1. Generic parameter removal: Removing the Schema parameter from filter types could be breaking if external libraries depend on the full type signature
    • Recommendation: Verify no downstream packages use these internal types directly

Type Safety Verification Needed

  1. Provider-specific type features: The removal of ProviderSupportsCaseSensitivity<Schema> logic in StringFilter needs verification:

    // Before: Conditional mode based on provider
    ProviderSupportsCaseSensitivity<Schema> extends true ? { mode?: ... } : {}
    // After: Always available
    mode?: 'default' | 'insensitive';
    • Recommendation: Ensure this doesn't enable unsupported features for SQLite
  2. Schema parameter usage: Need to verify the Schema parameter wasn't providing essential type constraints in edge cases


🚀 Performance Benefits

Compilation Performance

  • Reduced type complexity: Fewer generic parameters = faster TypeScript compilation
  • Type display optimization: Branded schema types prevent expensive type expansion in IDEs
  • IntelliSense improvements: Developers should see cleaner, more readable type hints

Bundle Size

  • Type erasure: These changes are compile-time only and won't affect runtime bundle size

🔒 Security Assessment

No Security Risks Identified

  • Type-only changes: All modifications are at the TypeScript type level
  • No runtime changes: Generated JavaScript remains the same
  • Schema validation preserved: Core validation logic appears unaffected

📋 Specific File Analysis

crud-types.ts - packages/orm/src/client/crud-types.ts:230-320

  • Good: Simplified filter type hierarchy
  • Concern: Verify provider-specific features still work correctly

ts-schema-generator.ts - packages/sdk/src/ts-schema-generator.ts:172-189

  • Excellent: Schema branding implementation is clean and well-documented
  • Good: Conditional import handling shows attention to detail

Generated schemas - tests/e2e/orm/schemas/*/schema.ts

  • Good: Consistent application of branding pattern
  • Good: Proper TypeScript satisfaction with satisfies SchemaDef

🎯 Recommendations

Pre-merge Testing

  1. Run comprehensive type tests: Ensure all existing type tests pass
  2. Provider compatibility: Test with both SQLite and PostgreSQL to verify provider-specific features
  3. Integration testing: Test with real-world usage patterns in samples

Documentation

  1. Update type documentation: If any public types changed, update relevant documentation
  2. Migration notes: Consider adding notes about any breaking changes to CHANGELOG

Future Considerations

  1. Monitor TypeScript performance: Track compilation time improvements
  2. Developer feedback: Monitor developer reports about type display quality

🏆 Overall Assessment

Rating: ⭐⭐⭐⭐⭐ Excellent

This is a high-quality improvement that addresses a real developer pain point. The implementation is thoughtful, consistent, and should provide measurable benefits to TypeScript compilation performance and developer experience.

The changes demonstrate good engineering practices:

  • Systematic approach to type simplification
  • Preservation of type safety where possible
  • Consistent application across the codebase
  • Proper handling of generated code patterns

Recommendation: ✅ Approve with testing

This PR should be merged after verifying that:

  1. All existing tests pass
  2. Provider-specific features work correctly
  3. No breaking changes in downstream usage

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