Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Aug 6, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced string filter options with case sensitivity controls, including support for case-insensitive string matching where supported.
    • Added the ability to select relation counts (_count) only for models with to-many relations, improving query precision.
    • Improved relation counting in nested queries for supported databases.
  • Bug Fixes

    • Improved handling of distinct queries to ensure correct field selection and filtering.
  • Tests

    • Expanded test coverage for string filter behavior across different database providers.
    • Added tests for distinct queries with relation inclusion and for nested relation counting.
  • Chores

    • Updated package versions to 3.0.0-alpha.19 across all packages.
    • Updated peer dependency for better-sqlite3 to ^12.2.0.
    • Unified and modernized schema validation logic for stricter input validation.

ymc9 and others added 6 commits August 5, 2025 14:27
…ted (#144)

* fix: issue with in memory distinct when distinct fields are not selected

* addressing PR comments
…ibility with Prisma (#147)

* fix: tighten up query input validation, fixed case-sensitivity compatibility with Prisma

* update
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
* Update `better-sqlite3` version range

* update lockfile

---------

Co-authored-by: Yiming Cao <yiming@whimslab.io>
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 6, 2025 09:21
@coderabbitai
Copy link

coderabbitai bot commented Aug 6, 2025

Walkthrough

This update advances the version numbers of multiple packages from "3.0.0-alpha.18" to "3.0.0-alpha.19" and introduces significant enhancements to runtime type safety, filter logic, and validation schemas. It refines string filter behavior, count selection, and relation handling, adds provider-aware case sensitivity, and expands test coverage for filters and selection.

Changes

Cohort / File(s) Change Summary
Version Bump (Alpha.19)
package.json, samples/blog/package.json, tests/e2e/package.json, packages/cli/package.json, packages/common-helpers/package.json, packages/create-zenstack/package.json, packages/dialects/sql.js/package.json, packages/eslint-config/package.json, packages/ide/vscode/package.json, packages/language/package.json, packages/runtime/package.json, packages/sdk/package.json, packages/tanstack-query/package.json, packages/testtools/package.json, packages/typescript-config/package.json, packages/vitest-config/package.json, packages/zod/package.json
Incremented version fields from "3.0.0-alpha.18" to "3.0.0-alpha.19" in all listed package manifests. In packages/runtime/package.json, also updated the better-sqlite3 peer dependency version.
Runtime Filter Typings and Count Selection
packages/runtime/src/client/crud-types.ts, packages/runtime/src/client/crud/dialects/base.ts, packages/runtime/src/client/crud/dialects/postgresql.ts, packages/runtime/src/client/crud/dialects/sqlite.ts, packages/runtime/src/client/crud/operations/base.ts
Enhanced filter types with schema awareness, added provider-aware string filter case sensitivity, improved count selection logic, refactored dialect methods for clarity and correctness, and adjusted parameter naming for consistency.
Validation Schema Enhancements
packages/runtime/src/client/crud/validator.ts
Replaced .strict() with z.strictObject, encapsulated pagination schemas, expanded string filter schema with provider-aware case sensitivity, and improved select/include schema construction.
Query Utilities
packages/runtime/src/client/query-utils.ts
Changed field access from error-throwing to safe-optional, returning boolean for missing fields, to prevent runtime errors.
Test Suite Expansion
packages/runtime/test/client-api/filter.test.ts, packages/runtime/test/client-api/find.test.ts
Expanded and refined tests for filter case sensitivity, distinct queries, nested relation counting, and type safety in selection.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Poem

🐇✨
Version bumps and filters anew,
With stricter types and schemas too.
Counts are smarter, strings aware,
Of case and mode, with dialect care.
Tests now cover edge and nook—
This rabbit’s proud of every look!
—Hopping forward, code in stride.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

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.
  • 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate unit tests to generate unit tests for 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.

@claude
Copy link

claude bot commented Aug 6, 2025

Claude finished @ymc9's task —— View job


Pull Request Review

Reviewing this dev → main merge for code quality, potential issues, performance, and security concerns.

Todo List

  • Analyze package.json version changes
  • Review core runtime CRUD changes
  • Examine validation logic updates
  • Check test coverage additions
  • Identify potential bugs or security issues
  • Provide comprehensive feedback

Review Summary

This PR merges dev to main with 6 commits containing version bumps, dependency updates, and important bug fixes. The changes are well-structured and address specific issues while maintaining compatibility.

Key Changes Reviewed

1. Version Management ✅

  • Version bump to 3.0.0-alpha.19 across all packages
  • Consistent versioning maintained in monorepo
  • No breaking changes in package dependencies

2. Dependency Updates ✅

  • better-sqlite3 version range update: Updated to support wider range of versions
  • This addresses compatibility issues while maintaining security

3. Critical Bug Fixes 🔧

Query Input Validation & Case Sensitivity (commit 3a49973)

  • Fixed case-sensitivity compatibility with Prisma: Important for SQL portability
  • Enhanced input validation: Prevents malformed queries from reaching the database
  • Code Quality: The validation logic in packages/runtime/src/client/crud/validator.ts shows robust error handling with proper Zod schemas

In-Memory Distinct Operations (commit 6a62a2c)

  • Fixed distinct field selection issue: Prevents runtime errors when distinct fields aren't selected
  • Performance impact: Improves query execution efficiency

Relation Count Selection (commit 192cc01)

  • Fixed _count in relation selection: Critical for aggregation queries
  • Type safety: Maintains TypeScript inference correctness

4. Code Quality Assessment ✅

Strengths:

  • Comprehensive validation: The InputValidator class provides thorough input sanitization
  • Type safety: Strong TypeScript types prevent runtime errors
  • Database dialect abstraction: Clean separation between SQLite and PostgreSQL implementations
  • Test coverage: Substantial test additions covering edge cases

Architecture:

  • BaseCrudDialect: Well-designed abstract base with proper separation of concerns
  • Filter builders: Robust SQL generation with proper escaping
  • Error handling: Appropriate error types (InputValidationError, QueryError, InternalError)

5. Security Considerations 🔒

Positive aspects:

  • Input validation: All user inputs are validated through Zod schemas
  • SQL injection protection: Proper use of parameterized queries through Kysely
  • Type checking: Runtime validation matches compile-time types

No security vulnerabilities detected.

6. Performance Implications 📊

Improvements:

  • Query optimization: Better handling of distinct operations
  • Validation caching: Schema validation results are cached
  • Relation filtering: Optimized subquery generation

7. Test Coverage 📋

Strong test additions:

  • New filter tests for string operations with case sensitivity
  • Edge case testing for different database providers
  • Validation testing for malformed inputs

Potential Areas for Improvement

  1. Minor: Some complex type unions in crud-types.ts could benefit from documentation
  2. Consider: Adding integration tests for the better-sqlite3 version range update
  3. Future: The TODO comments for JSON filtering suggest planned enhancements

Recommendation

✅ APPROVE - This PR is ready for merge. The changes are:

  • Well-tested with comprehensive coverage
  • Address critical bugs affecting query functionality
  • Maintain backward compatibility
  • Follow established architectural patterns
  • Include proper error handling and validation

The bug fixes are particularly important for production stability, and the version consistency across packages ensures smooth deployment.

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 merges development branch changes to main, incrementing the version number from 3.0.0-alpha.18 to 3.0.0-alpha.19 across all packages and implementing several runtime improvements.

  • Version bump across all package.json files to alpha.19
  • Enhanced string filtering with case sensitivity support for PostgreSQL
  • Improved client API functionality for distinct queries and count operations
  • Better error handling and type safety improvements in the runtime

Reviewed Changes

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

Show a summary per file
File Description
Multiple package.json files Version increment from alpha.18 to alpha.19
packages/runtime/src/client/query-utils.ts Replace requireField with getField for safer field access
packages/runtime/src/client/crud/validator.ts Enhanced validation schemas with strictObject and string filtering improvements
packages/runtime/src/client/crud/operations/base.ts Improved distinct query handling and count JSON building
packages/runtime/src/client/crud/dialects/*.ts Database dialect improvements for relation handling and count operations
packages/runtime/src/client/crud-types.ts Enhanced type definitions for filtering with provider-specific features
packages/runtime/test/client-api/*.test.ts Extended test coverage for distinct queries and provider-specific filtering
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (3)

packages/runtime/package.json:78

  • The version ^12.2.0 for better-sqlite3 may not exist. As of my knowledge cutoff in January 2025, better-sqlite3 was at version 11.x. Please verify this version exists before merging.
        "better-sqlite3": "^12.2.0",

packages/runtime/test/client-api/find.test.ts:867

  • This test case is checking TypeScript compilation errors with @ts-expect-error but doesn't include an assertion. Consider adding an explicit test that verifies the runtime behavior or removes this if it's only for type checking.
        client.comment.findFirst({

packages/runtime/test/client-api/find.test.ts:872

  • Similar to the previous comment, this test case with @ts-expect-error doesn't include runtime assertions. Consider adding explicit verification of the expected behavior.
        client.post.findFirst({

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
package.json (1)

3-3: Root version updated correctly.
Ensure you also tag v3.0.0-alpha.19 and update the changelog before publishing.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e359fc and 12d0fa1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (26)
  • package.json (1 hunks)
  • packages/cli/package.json (1 hunks)
  • packages/common-helpers/package.json (1 hunks)
  • packages/create-zenstack/package.json (1 hunks)
  • packages/dialects/sql.js/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 (2 hunks)
  • packages/runtime/src/client/crud-types.ts (4 hunks)
  • packages/runtime/src/client/crud/dialects/base.ts (7 hunks)
  • packages/runtime/src/client/crud/dialects/postgresql.ts (3 hunks)
  • packages/runtime/src/client/crud/dialects/sqlite.ts (4 hunks)
  • packages/runtime/src/client/crud/operations/base.ts (3 hunks)
  • packages/runtime/src/client/crud/validator.ts (35 hunks)
  • packages/runtime/src/client/query-utils.ts (1 hunks)
  • packages/runtime/test/client-api/filter.test.ts (3 hunks)
  • packages/runtime/test/client-api/find.test.ts (4 hunks)
  • packages/sdk/package.json (1 hunks)
  • packages/tanstack-query/package.json (1 hunks)
  • packages/testtools/package.json (1 hunks)
  • packages/typescript-config/package.json (1 hunks)
  • packages/vitest-config/package.json (1 hunks)
  • packages/zod/package.json (1 hunks)
  • samples/blog/package.json (1 hunks)
  • tests/e2e/package.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
{packages,samples,tests}/**

📄 CodeRabbit Inference Engine (CLAUDE.md)

Packages are located in packages/, samples/, and tests/

Files:

  • packages/language/package.json
  • packages/dialects/sql.js/package.json
  • packages/zod/package.json
  • packages/testtools/package.json
  • packages/runtime/package.json
  • packages/eslint-config/package.json
  • tests/e2e/package.json
  • packages/ide/vscode/package.json
  • packages/tanstack-query/package.json
  • packages/cli/package.json
  • samples/blog/package.json
  • packages/typescript-config/package.json
  • packages/create-zenstack/package.json
  • packages/vitest-config/package.json
  • packages/sdk/package.json
  • packages/common-helpers/package.json
  • packages/runtime/test/client-api/filter.test.ts
  • packages/runtime/src/client/query-utils.ts
  • packages/runtime/src/client/crud/dialects/sqlite.ts
  • packages/runtime/test/client-api/find.test.ts
  • packages/runtime/src/client/crud-types.ts
  • packages/runtime/src/client/crud/dialects/base.ts
  • packages/runtime/src/client/crud/operations/base.ts
  • packages/runtime/src/client/crud/dialects/postgresql.ts
  • packages/runtime/src/client/crud/validator.ts
tests/e2e/**

📄 CodeRabbit Inference Engine (CLAUDE.md)

E2E tests are in tests/e2e/ directory

Files:

  • tests/e2e/package.json
🧠 Learnings (11)
📚 Learning: `zenstack generate` compiles zmodel to typescript schema (`schema.ts`)...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: `zenstack generate` compiles ZModel to TypeScript schema (`schema.ts`)

Applied to files:

  • packages/language/package.json
  • package.json
  • packages/zod/package.json
  • packages/ide/vscode/package.json
  • packages/tanstack-query/package.json
  • packages/cli/package.json
  • packages/typescript-config/package.json
  • packages/create-zenstack/package.json
  • packages/vitest-config/package.json
  • packages/sdk/package.json
  • packages/runtime/src/client/crud/validator.ts
📚 Learning: language-first design: zmodel dsl compiles to typescript, not runtime code generation...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: Language-First Design: ZModel DSL compiles to TypeScript, not runtime code generation

Applied to files:

  • packages/language/package.json
  • packages/runtime/src/client/crud/validator.ts
📚 Learning: schema-first approach with zmodel dsl extension of prisma schema language...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: Schema-first approach with ZModel DSL extension of Prisma schema language

Applied to files:

  • packages/language/package.json
  • packages/runtime/src/client/crud-types.ts
  • packages/runtime/src/client/crud/validator.ts
📚 Learning: zmodel schema (`schema.zmodel`) defines database structure and policies...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: ZModel schema (`schema.zmodel`) defines database structure and policies

Applied to files:

  • packages/language/package.json
  • packages/runtime/src/client/crud/validator.ts
📚 Learning: kysely-based orm: v3 uses kysely as query builder instead of prisma runtime dependency...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: Kysely-Based ORM: V3 uses Kysely as query builder instead of Prisma runtime dependency

Applied to files:

  • packages/dialects/sql.js/package.json
  • packages/runtime/src/client/crud/operations/base.ts
📚 Learning: no runtime dependency on @prisma/client...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: No runtime dependency on prisma/client

Applied to files:

  • packages/runtime/package.json
📚 Learning: applies to tests/e2e/** : e2e tests are in `tests/e2e/` directory...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: Applies to tests/e2e/** : E2E tests are in `tests/e2e/` directory

Applied to files:

  • tests/e2e/package.json
  • packages/runtime/test/client-api/filter.test.ts
📚 Learning: type coverage tests ensure typescript inference works correctly...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: Type coverage tests ensure TypeScript inference works correctly

Applied to files:

  • packages/runtime/test/client-api/filter.test.ts
  • packages/runtime/test/client-api/find.test.ts
📚 Learning: client provides both high-level orm api and low-level kysely query builder...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: Client provides both high-level ORM API and low-level Kysely query builder

Applied to files:

  • packages/runtime/src/client/crud/operations/base.ts
📚 Learning: kysely query builder as escape hatch instead of raw sql...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: Kysely query builder as escape hatch instead of raw SQL

Applied to files:

  • packages/runtime/src/client/crud/operations/base.ts
📚 Learning: applies to **/schema.zmodel : always run `zenstack generate` after modifying zmodel schemas...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: Applies to **/schema.zmodel : Always run `zenstack generate` after modifying ZModel schemas

Applied to files:

  • packages/runtime/src/client/crud/validator.ts
🧬 Code Graph Analysis (6)
packages/runtime/test/client-api/filter.test.ts (3)
packages/runtime/test/client-api/client-specs.ts (1)
  • createClientSpecs (6-42)
packages/runtime/src/client/crud/dialects/postgresql.ts (1)
  • provider (27-29)
packages/runtime/src/client/crud/dialects/sqlite.ts (1)
  • provider (27-29)
packages/runtime/src/client/query-utils.ts (3)
packages/runtime/src/client/crud/operations/base.ts (2)
  • getField (124-126)
  • schema (89-91)
samples/blog/zenstack/schema.ts (1)
  • schema (9-228)
packages/sdk/src/schema/schema.ts (1)
  • SchemaDef (10-18)
packages/runtime/test/client-api/find.test.ts (1)
packages/runtime/test/client-api/utils.ts (1)
  • createUser (6-21)
packages/runtime/src/client/crud-types.ts (2)
packages/sdk/src/schema/schema.ts (7)
  • GetModelFieldType (151-155)
  • ModelFieldIsOptional (217-221)
  • SchemaDef (10-18)
  • BuiltinType (84-94)
  • GetModels (108-108)
  • RelationFields (196-200)
  • FieldIsArray (235-239)
packages/runtime/src/utils/type-utils.ts (1)
  • NullableIf (5-5)
packages/runtime/src/client/crud/operations/base.ts (1)
packages/runtime/src/client/query-utils.ts (3)
  • ensureArray (267-273)
  • buildFieldRef (154-176)
  • safeJSONStringify (275-283)
packages/runtime/src/client/crud/dialects/postgresql.ts (3)
packages/sdk/src/schema/schema.ts (1)
  • GetModels (108-108)
packages/runtime/src/client/query-utils.ts (2)
  • requireField (30-36)
  • buildFieldRef (154-176)
packages/runtime/src/client/crud/operations/base.ts (1)
  • requireField (120-122)
⏰ 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: claude-review
  • GitHub Check: build-test (20.x)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (48)
packages/runtime/src/client/query-utils.ts (4)

99-102: LGTM: Safer field handling with graceful fallback.

The change from requireField to getField with optional chaining makes this function more defensive by returning false for non-existent fields instead of throwing errors. This aligns with the broader improvements mentioned in the AI summary for safer schema field handling.


104-107: LGTM: Consistent defensive pattern applied.

Similar to isScalarField, this change provides graceful handling of missing fields by returning false instead of throwing errors.


109-112: LGTM: Maintains consistency with other field checking utilities.

The defensive approach is consistently applied across all field type checking functions.


114-117: LGTM: Completes the consistent refactoring pattern.

All four field checking utilities now follow the same safe pattern of using getField with optional chaining.

packages/runtime/test/client-api/find.test.ts (4)

247-247: LGTM: Profile creation supports the enhanced distinct tests.

The addition of profile creation with bio fields supports the new distinct test cases that verify include/select behavior.

Also applies to: 256-256


273-287: LGTM: Comprehensive distinct query testing.

The new test cases properly verify that distinct queries work correctly with both include and select clauses, ensuring that related data (profile) is properly included/selected while maintaining distinct behavior on the specified fields.


852-866: LGTM: Nested relation count selection test.

This test verifies that selecting _count on nested relations (posts with their comments count) works correctly, returning the expected structure with zero comments for each post.


867-876: LGTM: TypeScript type safety validation.

The @ts-expect-error tests properly validate that TypeScript correctly prevents selecting _count on entities that don't have to-many relations (Comment model) and prevents invalid nested _count usage. This ensures type safety as mentioned in the AI summary.

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

180-196: LGTM! Solid approach for cross-dialect distinct handling.

The aliasing strategy using $distinct$ prefix ensures distinct fields are available for in-memory filtering when the dialect lacks distinctOn support. The implementation correctly uses buildFieldRef for consistent field reference building.


233-251: LGTM! Well-implemented in-memory distinct filtering.

The deduplication logic properly uses safeJSONStringify for composite key generation and cleanly removes temporary fields. The algorithm preserves insertion order while efficiently handling duplicates.


315-315: LGTM! Clean refactoring delegating to dialect implementation.

Excellent simplification that centralizes count JSON construction in the dialect layer while maintaining clean separation of concerns. This allows for dialect-specific optimizations and reduces code duplication.

packages/runtime/src/client/crud/dialects/postgresql.ts (2)

203-203: LGTM! Good consistency improvement with parameter naming.

The rename from parentName to parentAlias is more semantically accurate and aligns with similar changes across dialect implementations. All usages are updated consistently.


241-259: LGTM! Well-implemented _count field handling.

The conditional logic properly separates _count field handling from regular fields, delegating to the centralized buildCountJson method. The alias path construction is correct and maintains consistency with the existing relation handling patterns.

packages/runtime/test/client-api/filter.test.ts (3)

8-8: LGTM! Provider-aware test configuration.

The addition of the provider parameter to the test describe block enables provider-specific test logic, which aligns with the enhanced filter functionality that supports database-specific behavior.


79-189: Excellent comprehensive provider-specific test coverage!

The provider-specific string filter tests are well-structured and thorough:

SQLite tests (79-128): Correctly validate that equality operations are case-sensitive while contains, startsWith, and in operations are case-insensitive, which aligns with SQLite's documented behavior.

PostgreSQL tests (129-188): Properly test the new mode parameter functionality for case-insensitive filtering, covering equals, contains, endsWith, and in operations with both default and explicit insensitive modes.

The use of as any type assertions for the mode property is appropriate for testing new functionality during development.


326-328: LGTM! Minor formatting improvement.

The multiline formatting of the toMatchObject assertion enhances readability and maintains consistency with similar assertions in the test file.

packages/runtime/src/client/crud/dialects/sqlite.ts (4)

70-70: LGTM! Parameter naming improvement.

The rename from parentName to parentAlias provides better semantic clarity about the parameter's role in SQL alias generation.


77-147: LGTM! Consistent parameter renaming throughout.

All references to the renamed parameter have been properly updated across subquery alias naming and SQL reference strings, maintaining consistency and improving code clarity.


186-211: LGTM! Improved count handling with clear separation of concerns.

The explicit handling of the _count field before processing relation fields provides better code organization. The logic properly delegates count JSON construction to the base dialect's buildCountJson method, maintaining consistency with the broader refactoring effort.


227-227: LGTM! Consistent parameter usage in include logic.

The parentAlias parameter is correctly used in the relation JSON building for included fields, maintaining consistency with the parameter renaming.

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

226-226: LGTM! Schema-aware primitive filter integration.

The addition of the Schema generic parameter to PrimitiveFilter enables schema-aware filtering capabilities, which is essential for the provider-specific features being introduced.


252-287: Excellent schema-aware filter type design!

The enhancement of filter types to be schema-aware is well-implemented:

  1. Schema integration: All primitive filter types now accept the Schema generic parameter, enabling provider-specific behavior
  2. Conditional mode property: StringFilter conditionally includes the mode property only for providers that support case sensitivity (PostgreSQL), maintaining type safety
  3. Consistent propagation: The schema parameter is properly threaded through all filter type hierarchies including the not field

The use of conditional types with ProviderSupportsCaseSensitivity<Schema> ensures type-safe access to provider-specific features.


401-406: Smart conditional _count field inclusion!

The conditional inclusion of the _count field only when the model has to-many relations prevents meaningless count selections on models without array relations. The HasToManyRelations<Schema, Model> type correctly identifies models with array-type relation fields.


1194-1201: Well-designed utility types for feature detection!

The utility types are excellently structured:

  1. HasToManyRelations: Uses mapped types to identify models with array-type relation fields, enabling conditional _count field inclusion
  2. ProviderSupportsCaseSensitivity: Currently supports PostgreSQL with a design that's easily extensible to other providers

Both types follow TypeScript best practices for conditional type logic and provide clear semantic constraints for the type system.

packages/runtime/src/client/crud/dialects/base.ts (3)

459-478: LGTM! Good enhancement to filter flexibility.

The addition of the excludeKeys parameter alongside the existing onlyForKeys provides comprehensive control over which filter keys to process.


520-591: Well-implemented case-insensitive string filtering support.

The refactoring properly handles both 'default' and 'insensitive' modes, using appropriate SQL functions (lower, ilike) for case-insensitive comparisons. The recursive handling in prepStringCasing for arrays is correct.

Note: The ilike operator is PostgreSQL-specific, which aligns with the validator's provider-aware implementation.


865-913: Excellent implementation of relation count JSON building.

The buildCountJson method provides a clean abstraction for generating nested count queries for to-many relations. It properly handles:

  • Selective counting based on payload
  • Join conditions via buildJoinPairs
  • Optional filtering with where clauses
  • JSON object construction for the results
packages/runtime/src/client/crud/validator.ts (4)

698-703: Verify intentional use of non-strict objects at top level.

While most schemas have been refactored to use z.strictObject(), several top-level schemas in create, update, upsert, and delete operations use z.object() without strict mode. Is this intentional for flexibility, or should these also be strict for consistency?

Also applies to: 962-968, 992-999, 1104-1108


521-542: Well-designed provider-aware string filter enhancements.

The string filter schema properly:

  • Adds missing string operations (startsWith, endsWith, contains)
  • Conditionally includes the mode field only for PostgreSQL
  • Uses appropriate schema validation with literal types

The provider check ensures compatibility across different database systems.

Also applies to: 1295-1297


1261-1267: Good refactoring of skip/take schemas.

Centralizing the skip and take schema definitions improves maintainability and ensures consistent validation across all usages. The validation rules are correct:

  • skip: non-negative integers only
  • take: allows negative values for reverse limiting

564-590: Excellent conditional _count field implementation.

The schema correctly:

  • Includes _count only for models with to-many relations (optimization)
  • Supports both simple (true) and detailed count selection
  • Allows per-relation count filtering with where clauses

This aligns perfectly with the buildCountJson method in the dialect layer.

tests/e2e/package.json (1)

3-3: Version bump looks good – remember to regenerate workspace lockfile

The version update is consistent with the coordinated alpha.19 release. After merging, run your monorepo’s install/bootstrap step (e.g., pnpm install or npm install) to refresh the root lockfile and avoid mismatched workspace ranges.

samples/blog/package.json (1)

3-3: Blog sample version aligned – no issues spotted

Change is straightforward and keeps the sample in sync with the rest of the repo.

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

3-3: Helper package version updated correctly

No additional metadata changes detected; version bump is clean.

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

3-3: ESLint config version bump acknowledged

Update is in line with the overall release cadence.

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

3-3: TypeScript config package version synchronized

Looks good; nothing else to address.

packages/zod/package.json (1)

3-3: Version bump looks good and stays in sync with the monorepo.
Nothing else changed in the manifest, so no additional action required.

packages/testtools/package.json (1)

3-3: Consistent version update.
Change is straightforward and aligned with the rest of the packages.

packages/sdk/package.json (1)

3-3: SDK package version bump confirmed.
No further issues spotted.

packages/dialects/sql.js/package.json (1)

3-3: Dialect package version bump confirmed.
Looks ready to merge.

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

3-3: Version bump looks consistent; LGTM
No further action required.

packages/language/package.json (1)

4-4: Version synced with monorepo release; LGTM

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

4-4: Version update is correct; LGTM

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

3-3: Version bump aligns with broader release; LGTM

packages/cli/package.json (1)

6-6: CLI package version updated consistently; LGTM

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

4-4: Version bump is fine; ensure ancillary release assets are updated

Only the version field changed. Please double-check that:

  1. CHANGELOG.md (or equivalent) contains an entry for 3.0.0-alpha.19.
  2. The pre-release published to the VS Code Marketplace will be tagged alpha.19 so users get the correct update.

No code issues detected.

packages/runtime/package.json (2)

3-3: Runtime package version bump acknowledged

The version aligns with the monorepo’s alpha.19 release train. LGTM.


78-78: Confirm compatibility with better-sqlite3@^12.2.0

better-sqlite3 jumped a major version (11 → 12). ABI or build-time changes are common with this library.

Recommended actions:

  1. Run the full test suite against Node 18 and Node 20 to catch native-addon regressions.
  2. Verify the minimum Node version stated in project docs still satisfies better-sqlite3 ≥ 12.

No blocking issue, but please confirm before publishing.

@ymc9 ymc9 changed the title merge dev to main merge dev to main (v3.0.0-alpha.19) Aug 6, 2025
@ymc9 ymc9 added this pull request to the merge queue Aug 6, 2025
Merged via the queue into main with commit 0040e9d Aug 6, 2025
8 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.

3 participants