Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Dec 5, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for filtering on typed JSON fields in ORM queries.
    • Generated comprehensive type definitions for ORM operations across test schemas.
  • Chores

    • Centralized test schema generation script to streamline build process.
    • Updated test infrastructure to use unified generation approach.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings December 5, 2025 07:18
@coderabbitai
Copy link

coderabbitai bot commented Dec 5, 2025

Walkthrough

This PR centralizes test schema generation infrastructure by consolidating per-directory generate.ts scripts into a single root scripts/test-generate.ts. It simultaneously introduces typed JSON field filtering support in the ORM by adding helper functions and extending where-filter construction logic. Generated TypeScript models and input-type files are added for multiple e2e test schemas, and several redundant test files are removed.

Changes

Cohort / File(s) Change Summary
Test generation infrastructure centralization
packages/clients/tanstack-query/package.json, tests/e2e/package.json, tests/regression/package.json, tests/runtimes/bun/package.json, tests/runtimes/edge-runtime/package.json
Updated test:generate script paths from local scripts/generate.ts to centralized ../../../scripts/test-generate.ts or equivalent relative path.
New centralized test-generate script
scripts/test-generate.ts
Added new cross-project test generation script that discovers schema.zmodel files recursively, logs generation progress, and invokes CLI generation command via execSync. Supports environment RUNTIME variable for runtime selection.
Removed local generate scripts
packages/clients/tanstack-query/scripts/generate.ts, tests/e2e/scripts/generate.ts, tests/runtimes/bun/scripts/generate.ts, tests/runtimes/edge-runtime/scripts/generate.ts, tests/regression/generate.ts
Deleted per-directory schema generation scripts that performed file discovery, document loading, and code generation orchestration.
ORM TypeDef filtering support
packages/orm/src/client/crud-types.ts, packages/orm/src/client/crud/dialects/base-dialect.ts, packages/orm/src/client/crud/validator/index.ts, packages/orm/src/client/query-utils.ts
Added TypedJsonFilter type export, isTypeDef helper function, and conditional routing logic in base-dialect to handle type-def fields via JSON filtering instead of primitive filtering. Updated validator to detect and apply typed JSON filter schemas.
Generated e2e test types for cal.com
tests/e2e/github-repos/cal.com/models.ts
Added auto-generated file exporting 80+ ModelResult-based type aliases and 30+ enum constants/types derived from schema.
Generated e2e test types for formbricks
tests/e2e/github-repos/formbricks/input.ts, tests/e2e/github-repos/formbricks/models.ts
Added auto-generated input and model files exporting ORM argument/payload type aliases and model result types for 30+ entities.
Generated e2e test types for trigger.dev
tests/e2e/github-repos/trigger.dev/input.ts, tests/e2e/github-repos/trigger.dev/models.ts
Added auto-generated input and model files exporting ORM argument/payload types and model result types for 40+ entities.
New typed-JSON e2e test schema
tests/e2e/orm/schemas/typed-json/schema.zmodel, tests/e2e/orm/schemas/typed-json/schema.ts, tests/e2e/orm/schemas/typed-json/models.ts, tests/e2e/orm/schemas/typed-json/input.ts
Added new test schema with User model, Profile/Address/Job type definitions, and JSON-typed relations. Includes generated schema, model, and input TypeScript files.
Added typed-JSON filtering e2e test
tests/e2e/orm/client-api/json-filter.test.ts
Added test case validating typed JSON field filtering with equals and not conditions.
Removed redundant e2e test files
tests/e2e/github-repos/cal.com/cal-com.test.ts, tests/e2e/github-repos/formbricks/formbricks.test.ts, tests/e2e/github-repos/trigger.dev/trigger-dev.test.ts
Deleted standalone e2e test files that invoked generateTsSchema directly; replaced by centralized test generation and schema-based tests.
Schema cleanups
tests/e2e/orm/schemas/basic/schema.zmodel, tests/e2e/orm/schemas/petstore/schema.zmodel, tests/e2e/orm/schemas/todo/todo.zmodel, tests/e2e/github-repos/formbricks/schema.zmodel, tests/regression/test/v2-migrated/issue-*.test.ts
Removed Prisma client generator blocks and/or Zod plugin blocks. Updated plugin provider paths to centralized package locations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

  • Areas requiring extra attention:
    • packages/orm/src/client/crud/dialects/base-dialect.ts: New branching logic for isTypeDef() check; verify routing of type-def fields to buildJsonFilter is correct and does not break existing primitive filtering.
    • packages/orm/src/client/crud/validator/index.ts: Changes to schema generation flow and introduction of makeTypedJsonFilterSchema; confirm validation behavior and caching strategy are sound.
    • packages/orm/src/client/crud-types.ts: TypedJsonFilter conditional type logic in WhereInput; verify type inference and distribution work correctly.
    • scripts/test-generate.ts: New centralization point; verify file discovery, environment handling, and CLI invocation work across all affected test directories.
    • Generated files in tests/e2e/github-repos/*: Large number of auto-generated exports; spot-check a few model/input types for correctness of generic parameterization.

Possibly related PRs

Poem

🐰 Scripts now hop in one central place,
From many scattered to a unified space,
TypeDef JSON fields get their filtering dance,
Generated types bloom—the schemas advance!
One script to rule them, fast and so clean.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly describes the two main changes: enabling JSON filtering for typed-json fields in the ORM and consolidating generation scripts across the codebase.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/typedef-filter

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 Dec 5, 2025

Claude finished @ymc9's task —— View job


Comprehensive Code Review

I've thoroughly reviewed this PR that enables JSON filtering for typed-json fields and consolidates generation scripts. Here's my complete assessment:

Review Tasks:

  • Analyze core ORM changes for JSON filtering
  • Review script consolidation approach
  • Examine test coverage and new test cases
  • Check for security and performance considerations
  • Assess code quality and best practices
  • Provide final recommendations

📋 Summary

This is a well-structured PR that adds JSON filtering capabilities for typed JSON fields while consolidating scattered generation scripts. The implementation is incremental, maintaining backward compatibility while laying groundwork for future enhancements.

🔍 Detailed Analysis

Code Quality & Best Practices

Strengths:

  • Progressive Enhancement: The implementation follows an incremental approach, aliasing TypedJsonFilter to JsonFilter initially
  • Consistent Architecture: New functionality follows existing patterns in the codebase
  • Type Safety: Proper TypeScript integration with clear type definitions
  • Documentation: TODO comments clearly mark future enhancement areas

Areas of Excellence:

  • Clean separation of concerns between validation, dialect handling, and type definitions
  • Proper error handling in the validation layer
  • Consistent coding style matching existing codebase

🧪 Test Coverage

Comprehensive Testing:

  • New Test Schema: tests/e2e/orm/schemas/typed-json/ provides complete test coverage
  • JSON Filter Tests: tests/e2e/orm/client-api/json-filter.test.ts includes new typed JSON test cases (lines 236-251)
  • Edge Cases: Tests cover null handling, nested objects, arrays, and various data types
  • Validation Testing: Proper testing of input validation for different null types (JsonNull, DbNull, AnyNull)

Test Quality:

  • Tests are well-structured with clear expectations
  • Good coverage of positive and negative scenarios
  • Proper use of type assertions for validation testing

🛡️ Security Considerations

Robust Security:

  • Input Validation: Comprehensive validation using Zod schemas prevents malformed JSON input
  • Type Safety: TypeScript ensures compile-time safety for typed JSON fields
  • SQL Injection Protection: Uses parameterized queries through Kysely's expression builder
  • Null Handling: Proper distinction between DB NULL, JSON null, and undefined prevents data corruption

Security Best Practices:

  • No direct SQL concatenation
  • Proper escaping handled by underlying Kysely library
  • Validation layer prevents invalid data structures

Performance Considerations

Performance Optimizations:

  • Schema Caching: packages/orm/src/client/crud/validator/index.ts uses WeakMap caching for validation schemas
  • Lazy Evaluation: Proper use of z.lazy() for recursive schema definitions
  • Query Optimization: JSON filtering delegates to existing optimized JSON filter logic

Potential Optimizations:

  • Current implementation may generate larger SQL queries for complex JSON filters
  • Future typed JSON filtering could enable more targeted database operations

🔧 Script Consolidation

Excellent Refactoring:

  • DRY Principle: Eliminates 5+ duplicate generation scripts across test directories
  • Maintainability: Single source of truth in scripts/test-generate.ts
  • Flexibility: Supports different runtimes via RUNTIME environment variable
  • Glob Pattern: Efficiently finds all schema files using robust file matching

Implementation Quality:

  • Clean, readable code with proper error handling
  • Compatible with both CommonJS and ESM modules
  • Proper path resolution across different environments

🎯 Technical Recommendations

Immediate (Current PR):

  1. Implementation is ready - No blocking issues identified
  2. Tests are comprehensive - Good coverage of core functionality
  3. Security is sound - Proper validation and escaping

Future Enhancements:

  1. Strong Typed JSON Filtering - The TODO at packages/orm/src/client/crud/validator/index.ts:618 could enable more sophisticated filtering
  2. Performance Optimization - Consider caching compiled typedef schemas for repeated queries
  3. Enhanced Type Inference - Could improve TypeScript inference for nested typed JSON properties

Minor Suggestions:

  1. Documentation: Consider adding JSDoc comments for the new TypedJsonFilter type
  2. Error Messages: Could enhance error messages in makeTypeDefFilterSchema when strong filtering is implemented

💡 Notable Innovations

  • Unified JSON Handling: Elegant approach to handle both regular JSON and typed JSON through the same interface
  • Incremental Development: Smart strategy to enable basic functionality immediately while planning for advanced features
  • Build Tool Consolidation: Significant improvement to developer experience with centralized script management

🚀 Conclusion

This is a high-quality PR that delivers meaningful functionality while improving codebase maintainability. The implementation is:

  • Safe to merge - No security or performance concerns
  • Well-tested - Comprehensive test coverage
  • Future-proof - Clear path for enhancements
  • Developer-friendly - Improved tooling experience

The changes successfully enable JSON filtering for typed JSON fields and provide a solid foundation for future enhancements. The script consolidation is a welcome improvement that reduces maintenance overhead.

Recommendation: APPROVE - This PR is ready for merge and represents quality software development practices.


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 consolidates test generation scripts across multiple test directories and adds JSON filter support for typed-json fields. The main changes include:

  • Consolidates generation scripts: Removes duplicate generation scripts from tests/runtimes/edge-runtime, tests/runtimes/bun, tests/regression, and tests/e2e directories and replaces them with a single shared script at scripts/test-generate.ts
  • Enables JSON filter for typed-json fields: Adds a new test schema and test case demonstrating JSON filtering on typed-json fields
  • Removes generator blocks: Cleans up unnecessary Prisma generator blocks from test schemas

Reviewed changes

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

Show a summary per file
File Description
scripts/test-generate.ts New centralized test generation script that can scan for all schemas and handle runtime-specific generation
tests/runtimes/*/package.json Updated to reference the new centralized generation script
tests/runtimes/*/scripts/generate.ts Deleted - replaced by centralized script
tests/regression/generate.ts Deleted - replaced by centralized script
tests/e2e/scripts/generate.ts Deleted - replaced by centralized script
tests/e2e/orm/schemas/typed-json/* New schema and generated files for typed-json field testing
tests/e2e/orm/client-api/json-filter.test.ts Added test demonstrating JSON filtering on typed-json fields
tests/e2e/orm/schemas/*/schema.zmodel Removed unnecessary generator blocks and updated plugin paths
tests/e2e/github-repos/*/schema.zmodel Removed generator blocks from test schemas
tests/e2e/github-repos/*/*.test.ts Removed redundant test files that only verified schema generation
tests/e2e/github-repos/*/{models,input}.ts New generated TypeScript files for GitHub repo test schemas
tests/regression/test/v2-migrated/*.test.ts Removed generator blocks from embedded test schemas

💡 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

🧹 Nitpick comments (7)
packages/orm/src/client/query-utils.ts (1)

193-195: New isTypeDef helper is consistent with existing schema utilities

Implementation is straightforward and mirrors the existing getTypeDef/isEnum patterns; no functional issues. If you ever want to reduce duplication, you could have isTypeDef delegate to getTypeDef, but that’s purely optional.

tests/e2e/orm/client-api/json-filter.test.ts (1)

4-4: Good coverage for typed-JSON field filtering

The new test that uses typedJsonSchema and exercises equals and not filters on the profile typed-JSON field is a solid end-to-end check that the new filter path works as intended and returns the full user record. This aligns well with the goal of validating ORM behavior on realistic schemas. Based on learnings, this fits the e2e testing guidance.

If CI log noise becomes an issue, you might consider dropping debug: true here once the feature stabilizes.

Also applies to: 236-251

tests/runtimes/bun/package.json (1)

8-8: Bun runtime tests now delegate to shared generator with runtime override

Using RUNTIME=bun tsx ../../../scripts/test-generate.ts cleanly reuses the centralized generator while signaling the desired runtime via process.env.RUNTIME. This keeps Bun’s behavior aligned with other runtimes without duplicating generation logic.

If Windows support becomes a priority, consider wrapping this in a cross-platform env helper (e.g., cross-env) to avoid RUNTIME=... shell syntax issues.

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

31-32: Narrow isTypeDef usage to typed-JSON fields and update TODO

Routing TypeDef-backed fields through buildJsonFilter is the right direction for typed-JSON support, but isTypeDef(this.schema, fieldDef.type) currently matches all typeDefs. If you ever define non-JSON typeDefs (e.g., string/int aliases), their filters will now be treated as JSON equality/not-only filters, which is likely not what you want and differs from previous behavior where such filters were effectively unsupported.

Consider tightening this condition to only apply to typeDefs whose underlying scalar is Json (or whatever constraint defines “typed JSON” in your schema model), e.g. by:

  • Inspecting the referenced typeDef’s base type, or
  • Introducing a dedicated helper like isTypedJsonField(schema, fieldDef) and using that here.

Also, the // TODO: type-def field filtering comment is now outdated or at least too vague—either remove it or clarify what remains (e.g., “TODO: support non-JSON typeDef filters”).

Also applies to: 504-507

scripts/test-generate.ts (1)

1-24: Centralized test generator works; consider simplifying async/sync and ergonomics

The script correctly discovers schema.zmodel files under the provided baseDir, computes the CLI path relative to scripts/, and invokes packages/cli/dist/index.js with the requested RUNTIME. That matches how the updated package.json scripts are calling it.

A couple of small cleanups you might consider:

  • main and generate don’t actually perform any async work (everything is sync via glob.sync and execSync), so they don’t need to be async, and the await generate(file) is redundant. Making these functions synchronous will simplify control flow and avoid dangling Promises from the top-level main() call.
  • Optionally, wrapping execSync in a try/catch to print a clearer error (e.g., when dist/index.js hasn’t been built yet) could make failures easier to diagnose in CI, but current behavior is functionally correct.

For example, you could refactor along these lines:

-async function main() {
+function main() {
     const baseDir = process.argv[2] || '.';

     const zmodelFiles = [...glob.sync(path.resolve(baseDir, '**/schema.zmodel'), { ignore: '**/node_modules/**' })];
     for (const file of zmodelFiles) {
         console.log(`Generating TS schema for: ${file}`);
-        await generate(file);
+        generate(file);
     }
 }

-async function generate(schemaPath: string) {
+function generate(schemaPath: string) {
     const cliPath = path.join(_dirname, '../packages/cli/dist/index.js');
     const RUNTIME = process.env.RUNTIME ?? 'node';
     execSync(`${RUNTIME} ${cliPath} generate --schema ${schemaPath}`, { cwd: path.dirname(schemaPath) });
 }
packages/orm/src/client/crud/validator/index.ts (2)

381-387: Consider preserving validation error details in the custom schema.

Using z.custom((v) => schema!.safeParse(v).success) loses the detailed validation error messages from the original schema. When validation fails, users will only see a generic error rather than which specific field failed validation.

Consider using z.custom with an error message or superRefine to propagate the actual validation errors:

-        const finalSchema = z.custom((v) => schema!.safeParse(v).success);
+        const finalSchema = z.custom((v) => {
+            const result = schema!.safeParse(v);
+            return result.success;
+        }, { message: 'Invalid typed JSON object' });

Alternatively, if detailed errors are important, consider using transform or superRefine to preserve error details while still returning the original input.


538-545: Placeholder implementation acknowledged with TODO.

The makeTypedJsonFilterSchema currently delegates to the generic JSON filter schema, which is a reasonable incremental approach. The TODO comment makes it clear this is intended for future enhancement with direct typed JSON filtering capabilities.

Do you want me to open an issue to track the "direct typed JSON filtering" TODO, or help design the typed filter schema when you're ready to implement it?

📜 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 e129278 and c7118fd.

📒 Files selected for processing (35)
  • packages/clients/tanstack-query/package.json (1 hunks)
  • packages/clients/tanstack-query/scripts/generate.ts (0 hunks)
  • packages/orm/src/client/crud-types.ts (2 hunks)
  • packages/orm/src/client/crud/dialects/base-dialect.ts (2 hunks)
  • packages/orm/src/client/crud/validator/index.ts (3 hunks)
  • packages/orm/src/client/query-utils.ts (1 hunks)
  • scripts/test-generate.ts (1 hunks)
  • tests/e2e/github-repos/cal.com/cal-com.test.ts (0 hunks)
  • tests/e2e/github-repos/cal.com/models.ts (1 hunks)
  • tests/e2e/github-repos/formbricks/formbricks.test.ts (0 hunks)
  • tests/e2e/github-repos/formbricks/input.ts (1 hunks)
  • tests/e2e/github-repos/formbricks/models.ts (1 hunks)
  • tests/e2e/github-repos/formbricks/schema.zmodel (0 hunks)
  • tests/e2e/github-repos/trigger.dev/input.ts (1 hunks)
  • tests/e2e/github-repos/trigger.dev/models.ts (1 hunks)
  • tests/e2e/github-repos/trigger.dev/trigger-dev.test.ts (0 hunks)
  • tests/e2e/orm/client-api/json-filter.test.ts (2 hunks)
  • tests/e2e/orm/schemas/basic/schema.zmodel (1 hunks)
  • tests/e2e/orm/schemas/petstore/schema.zmodel (1 hunks)
  • tests/e2e/orm/schemas/todo/todo.zmodel (1 hunks)
  • tests/e2e/orm/schemas/typed-json/input.ts (1 hunks)
  • tests/e2e/orm/schemas/typed-json/models.ts (1 hunks)
  • tests/e2e/orm/schemas/typed-json/schema.ts (1 hunks)
  • tests/e2e/orm/schemas/typed-json/schema.zmodel (1 hunks)
  • tests/e2e/package.json (1 hunks)
  • tests/e2e/scripts/generate.ts (0 hunks)
  • tests/regression/generate.ts (0 hunks)
  • tests/regression/package.json (1 hunks)
  • tests/regression/test/v2-migrated/issue-1647.test.ts (0 hunks)
  • tests/regression/test/v2-migrated/issue-756.test.ts (0 hunks)
  • tests/regression/test/v2-migrated/issue-804.test.ts (0 hunks)
  • tests/runtimes/bun/package.json (1 hunks)
  • tests/runtimes/bun/scripts/generate.ts (0 hunks)
  • tests/runtimes/edge-runtime/package.json (1 hunks)
  • tests/runtimes/edge-runtime/scripts/generate.ts (0 hunks)
💤 Files with no reviewable changes (12)
  • tests/e2e/github-repos/formbricks/formbricks.test.ts
  • tests/e2e/github-repos/formbricks/schema.zmodel
  • tests/e2e/scripts/generate.ts
  • tests/regression/generate.ts
  • tests/e2e/github-repos/cal.com/cal-com.test.ts
  • tests/regression/test/v2-migrated/issue-756.test.ts
  • tests/e2e/github-repos/trigger.dev/trigger-dev.test.ts
  • tests/regression/test/v2-migrated/issue-804.test.ts
  • tests/runtimes/bun/scripts/generate.ts
  • packages/clients/tanstack-query/scripts/generate.ts
  • tests/regression/test/v2-migrated/issue-1647.test.ts
  • tests/runtimes/edge-runtime/scripts/generate.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.zmodel

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.zmodel: Always run zenstack generate after modifying ZModel schemas
ZModel schema files should define database structure and policies that compile to TypeScript via zenstack generate

Files:

  • tests/e2e/orm/schemas/basic/schema.zmodel
  • tests/e2e/orm/schemas/petstore/schema.zmodel
  • tests/e2e/orm/schemas/todo/todo.zmodel
  • tests/e2e/orm/schemas/typed-json/schema.zmodel
tests/e2e/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

E2E tests should validate real-world schema compatibility with established projects

Files:

  • tests/e2e/orm/schemas/typed-json/models.ts
  • tests/e2e/orm/client-api/json-filter.test.ts
  • tests/e2e/github-repos/formbricks/input.ts
  • tests/e2e/orm/schemas/typed-json/schema.ts
  • tests/e2e/github-repos/formbricks/models.ts
  • tests/e2e/github-repos/trigger.dev/input.ts
  • tests/e2e/orm/schemas/typed-json/input.ts
  • tests/e2e/github-repos/cal.com/models.ts
  • tests/e2e/github-repos/trigger.dev/models.ts
🧠 Learnings (12)
📓 Common learnings
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/e2e/**/*.{ts,tsx} : E2E tests should validate real-world schema compatibility with established projects
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to **/*.zmodel : ZModel schema files should define database structure and policies that compile to TypeScript via `zenstack generate`
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.test.{ts,tsx} : ORM package tests should include comprehensive client API tests and policy tests
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.{ts,tsx} : Implement plugin hooks at ORM, Kysely, and entity mutation levels for query interception and customization
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/**/type*.{ts,tsx} : Ensure TypeScript inference and type coverage are validated through type coverage tests
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/**/type*.{ts,tsx} : Ensure TypeScript inference and type coverage are validated through type coverage tests

Applied to files:

  • tests/regression/package.json
  • scripts/test-generate.ts
  • packages/clients/tanstack-query/package.json
  • tests/e2e/orm/client-api/json-filter.test.ts
  • tests/runtimes/edge-runtime/package.json
  • tests/e2e/github-repos/trigger.dev/input.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/e2e/**/*.{ts,tsx} : E2E tests should validate real-world schema compatibility with established projects

Applied to files:

  • tests/regression/package.json
  • tests/e2e/orm/schemas/basic/schema.zmodel
  • tests/e2e/package.json
  • scripts/test-generate.ts
  • tests/e2e/orm/schemas/typed-json/models.ts
  • tests/e2e/orm/client-api/json-filter.test.ts
  • tests/runtimes/edge-runtime/package.json
  • tests/e2e/github-repos/formbricks/input.ts
  • tests/e2e/orm/schemas/typed-json/schema.ts
  • tests/e2e/github-repos/formbricks/models.ts
  • packages/orm/src/client/crud/validator/index.ts
  • tests/e2e/github-repos/trigger.dev/input.ts
  • tests/e2e/orm/schemas/typed-json/input.ts
  • tests/e2e/github-repos/cal.com/models.ts
  • tests/e2e/github-repos/trigger.dev/models.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/cli/**/*.test.{ts,tsx} : CLI package tests should focus on action-specific tests for each command

Applied to files:

  • tests/regression/package.json
  • tests/e2e/package.json
  • scripts/test-generate.ts
  • packages/clients/tanstack-query/package.json
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Use Turbo for build orchestration and run `pnpm build`, `pnpm watch`, `pnpm lint`, and `pnpm test` for development tasks

Applied to files:

  • tests/regression/package.json
  • tests/e2e/package.json
  • packages/clients/tanstack-query/package.json
  • tests/runtimes/bun/package.json
  • tests/runtimes/edge-runtime/package.json
📚 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:

  • packages/orm/src/client/query-utils.ts
  • packages/orm/src/client/crud/dialects/base-dialect.ts
  • tests/e2e/orm/schemas/typed-json/schema.ts
  • packages/orm/src/client/crud/validator/index.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to **/*.zmodel : ZModel schema files should define database structure and policies that compile to TypeScript via `zenstack generate`

Applied to files:

  • tests/e2e/orm/schemas/basic/schema.zmodel
  • tests/e2e/orm/schemas/petstore/schema.zmodel
  • tests/e2e/orm/schemas/todo/todo.zmodel
  • scripts/test-generate.ts
  • tests/e2e/orm/schemas/typed-json/models.ts
  • tests/e2e/orm/schemas/typed-json/schema.zmodel
  • tests/e2e/github-repos/formbricks/input.ts
  • tests/e2e/orm/schemas/typed-json/schema.ts
  • tests/e2e/github-repos/formbricks/models.ts
  • tests/e2e/github-repos/trigger.dev/input.ts
  • tests/e2e/orm/schemas/typed-json/input.ts
  • tests/e2e/github-repos/cal.com/models.ts
  • tests/e2e/github-repos/trigger.dev/models.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.{ts,tsx} : Implement plugin hooks at ORM, Kysely, and entity mutation levels for query interception and customization

Applied to files:

  • tests/e2e/orm/schemas/basic/schema.zmodel
  • tests/e2e/orm/schemas/petstore/schema.zmodel
  • tests/e2e/orm/schemas/todo/todo.zmodel
  • packages/orm/src/client/crud/dialects/base-dialect.ts
  • tests/e2e/orm/schemas/typed-json/models.ts
  • tests/e2e/github-repos/formbricks/input.ts
  • packages/orm/src/client/crud-types.ts
  • tests/e2e/orm/schemas/typed-json/schema.ts
  • packages/orm/src/client/crud/validator/index.ts
  • tests/e2e/github-repos/trigger.dev/input.ts
  • tests/e2e/orm/schemas/typed-json/input.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to **/*.zmodel : Always run `zenstack generate` after modifying ZModel schemas

Applied to files:

  • tests/e2e/orm/schemas/petstore/schema.zmodel
  • scripts/test-generate.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.test.{ts,tsx} : ORM package tests should include comprehensive client API tests and policy tests

Applied to files:

  • tests/e2e/orm/schemas/petstore/schema.zmodel
  • tests/e2e/orm/schemas/todo/todo.zmodel
  • tests/e2e/orm/client-api/json-filter.test.ts
  • tests/e2e/github-repos/formbricks/input.ts
  • packages/orm/src/client/crud/validator/index.ts
  • tests/e2e/github-repos/trigger.dev/input.ts
  • tests/e2e/orm/schemas/typed-json/input.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
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.{ts,tsx} : Use Kysely as the query builder interface for low-level database queries, avoiding raw SQL when possible

Applied to files:

  • packages/orm/src/client/crud/dialects/base-dialect.ts
  • tests/e2e/orm/schemas/typed-json/models.ts
  • tests/e2e/github-repos/formbricks/input.ts
  • packages/orm/src/client/crud-types.ts
  • tests/e2e/orm/schemas/typed-json/schema.ts
  • packages/orm/src/client/crud/validator/index.ts
  • tests/e2e/orm/schemas/typed-json/input.ts
🧬 Code graph analysis (8)
packages/orm/src/client/query-utils.ts (1)
packages/schema/src/schema.ts (1)
  • SchemaDef (11-19)
packages/orm/src/client/crud/dialects/base-dialect.ts (1)
packages/orm/src/client/query-utils.ts (1)
  • isTypeDef (193-195)
scripts/test-generate.ts (1)
packages/cli/src/utils/exec-utils.ts (1)
  • execSync (7-16)
tests/e2e/orm/schemas/typed-json/models.ts (3)
tests/e2e/github-repos/cal.com/models.ts (2)
  • User (17-17)
  • Profile (19-19)
tests/e2e/github-repos/formbricks/models.ts (1)
  • User (313-313)
tests/e2e/github-repos/trigger.dev/models.ts (1)
  • User (10-10)
packages/orm/src/client/crud-types.ts (1)
packages/schema/src/schema.ts (3)
  • GetModelFieldType (166-170)
  • GetTypeDefs (142-142)
  • ModelFieldIsOptional (232-236)
tests/e2e/orm/schemas/typed-json/schema.ts (3)
packages/schema/src/expression-utils.ts (1)
  • ExpressionUtils (19-123)
packages/schema/src/schema.ts (1)
  • SchemaDef (11-19)
tests/e2e/github-repos/formbricks/schema.ts (1)
  • schema (3028-3028)
tests/e2e/github-repos/formbricks/models.ts (3)
tests/e2e/github-repos/cal.com/models.ts (10)
  • Webhook (39-39)
  • Membership (25-25)
  • ApiKey (41-41)
  • Account (44-44)
  • User (17-17)
  • MembershipRole (119-119)
  • MembershipRole (120-120)
  • IdentityProvider (113-113)
  • IdentityProvider (114-114)
  • Role (105-105)
tests/e2e/github-repos/trigger.dev/models.ts (4)
  • DataMigration (24-24)
  • Project (21-21)
  • Organization (17-17)
  • User (10-10)
tests/e2e/orm/schemas/typed-json/models.ts (1)
  • User (10-10)
tests/e2e/orm/schemas/typed-json/input.ts (2)
tests/e2e/github-repos/formbricks/input.ts (20)
  • UserFindManyArgs (491-491)
  • UserFindUniqueArgs (492-492)
  • UserFindFirstArgs (493-493)
  • UserCreateArgs (494-494)
  • UserCreateManyArgs (495-495)
  • UserCreateManyAndReturnArgs (496-496)
  • UserUpdateArgs (497-497)
  • UserUpdateManyArgs (498-498)
  • UserUpdateManyAndReturnArgs (499-499)
  • UserUpsertArgs (500-500)
  • UserDeleteArgs (501-501)
  • UserDeleteManyArgs (502-502)
  • UserCountArgs (503-503)
  • UserAggregateArgs (504-504)
  • UserGroupByArgs (505-505)
  • UserWhereInput (506-506)
  • UserSelect (507-507)
  • UserInclude (508-508)
  • UserOmit (509-509)
  • UserGetPayload (510-510)
tests/e2e/github-repos/cal.com/input.ts (20)
  • UserFindManyArgs (151-151)
  • UserFindUniqueArgs (152-152)
  • UserFindFirstArgs (153-153)
  • UserCreateArgs (154-154)
  • UserCreateManyArgs (155-155)
  • UserCreateManyAndReturnArgs (156-156)
  • UserUpdateArgs (157-157)
  • UserUpdateManyArgs (158-158)
  • UserUpdateManyAndReturnArgs (159-159)
  • UserUpsertArgs (160-160)
  • UserDeleteArgs (161-161)
  • UserDeleteManyArgs (162-162)
  • UserCountArgs (163-163)
  • UserAggregateArgs (164-164)
  • UserGroupByArgs (165-165)
  • UserWhereInput (166-166)
  • UserSelect (167-167)
  • UserInclude (168-168)
  • UserOmit (169-169)
  • UserGetPayload (170-170)
⏰ 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). (4)
  • GitHub Check: Agent
  • GitHub Check: build-test (20.x, postgresql)
  • GitHub Check: build-test (20.x, sqlite)
  • GitHub Check: claude-review
🔇 Additional comments (18)
tests/e2e/orm/schemas/basic/schema.zmodel (1)

7-7: Policy plugin path alignment looks good—ensure generation was rerun

Pointing the policy plugin to ../../../../../packages/plugins/policy/plugin.zmodel brings this schema in line with the shared plugin location. Please just confirm zenstack generate / the test generation script has been rerun so the generated TS for this schema is up to date. As per coding guidelines, ZModel changes should always be followed by regeneration.

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

308-315: Typed JSON filter wiring for typedef-backed fields looks correct—just double‑check non‑JSON typedef usage

Routing WhereInput through:

GetModelFieldType<Schema, Model, Key> extends GetTypeDefs<Schema>
    ? TypedJsonFilter
    : PrimitiveFilter<...>

makes previously unfilterable typedef-typed fields JSON‑filterable, and TypedJsonFilter = JsonFilter keeps their semantics aligned with plain Json fields, which matches the intent of enabling JSON filters for typed‑json.

One nuance to validate: this condition will apply to any field whose type name is a typedef, regardless of whether it’s stored as JSON (e.g., via @json). If you ever have typedef‑typed fields that are not JSON‑backed, they would now accept JSON‑style filters as well; in that case you might want to gate this branch by a field‑level “json” flag instead of relying solely on the type name. Based on learnings, TypeDefs are reused in multiple ways, so it’s worth a quick scan of existing typedef usages to confirm this matches expectations.

Also applies to: 465-467

tests/e2e/orm/schemas/todo/todo.zmodel (1)

10-12: Todo schema now uses shared policy plugin—confirm regeneration

Switching to plugin policy with provider ../../../../../packages/plugins/policy/plugin.zmodel aligns this schema with the centralized policy plugin configuration. Please confirm you’ve rerun zenstack generate / the e2e generation script so all derived TS for this schema reflects the new plugin wiring. As per coding guidelines, ZModel edits should always be followed by regeneration.

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

6-8: Petstore schema policy plugin configuration is consistent—ensure outputs are regenerated

Using the shared policy plugin at ../../../../../packages/plugins/policy/plugin.zmodel brings this schema in line with the rest of the e2e suite. Please just double‑check that zenstack generate / the updated test generation pipeline has been run so the generated client/types for this schema are synchronized. As per coding guidelines, ZModel schemas should always be regenerated after edits.

tests/e2e/orm/schemas/typed-json/schema.zmodel (1)

1-30: Typed‑JSON test schema is well‑structured—just confirm generated artifacts are synced

The User.profile: Profile @json plus nested Profile/Job/Address typedefs and Gender enum give a clean surface for exercising typed‑json filtering, including nested arrays and optionals. No issues spotted in the schema itself; please just confirm you’ve rerun the generation step so the corresponding schema.ts/models.ts/input.ts files used by the e2e tests are in sync with this definition. As per coding guidelines, ZModel changes should always be followed by zenstack generate.

tests/e2e/github-repos/cal.com/models.ts (1)

1-174: Generated Cal.com model typings look consistent

This file follows the usual generated pattern (ModelResult‑based model aliases plus enum value/union exports) and matches the schema‑driven structure; nothing to change here.

tests/e2e/github-repos/trigger.dev/models.ts (1)

1-172: Generated Trigger.dev model typings look consistent

The ModelResult aliases and enum constant/union exports follow the expected generated pattern and line up with the schema; no issues from a code-review standpoint.

tests/e2e/package.json (1)

8-8: Centralized e2e test generation script wiring looks correct

test:generate now points to ../../scripts/test-generate.ts, which resolves from tests/e2e to the new shared generator at the repo root and uses the default baseDir='.' to scope generation to this package. No issues from a path or workflow perspective.

tests/runtimes/edge-runtime/package.json (1)

8-8: Edge-runtime test generator correctly points to shared script

The new test:generate path (tsx ../../../scripts/test-generate.ts) correctly resolves from tests/runtimes/edge-runtime to the centralized generator and keeps runtime defaulting to node. This is consistent with the broader consolidation.

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

13-13: TanStack Query tests now use centralized generator with scoped baseDir

test:generate now invokes tsx ../../../scripts/test-generate.ts tests, correctly resolving to the root generator and limiting discovery to the local tests folder. This keeps the workflow consistent with other packages while avoiding cross-package schema discovery.

tests/regression/package.json (1)

7-7: Regression tests correctly migrated to shared generator

The generate script now calls tsx ../../scripts/test-generate.ts ./test, which resolves to the root generator and confines schema discovery to the test subdirectory of the regression suite. This keeps the existing pnpm generate && tsc && vitest run flow intact while removing the per-suite generator.

packages/orm/src/client/crud/validator/index.ts (1)

442-443: LGTM!

The new type-def type check is correctly placed in the filter schema construction logic, routing typed JSON fields to the appropriate filter schema while maintaining the existing enum and array field handling.

tests/e2e/orm/schemas/typed-json/schema.ts (1)

1-99: Generated schema file looks correct.

The generated schema properly defines the typed JSON test case with a User model containing a profile field of type Profile (a TypeDef), along with nested type definitions (Address, Job) and the Gender enum. The structure aligns with the PR's objective of enabling JSON filter for typed-json fields. Based on learnings, E2E tests should validate real-world schema compatibility, and this schema provides a good test fixture for the new typed JSON filtering feature.

tests/e2e/orm/schemas/typed-json/models.ts (1)

1-15: Generated models file follows established patterns.

The type exports correctly differentiate between $ModelResult for the User model and $TypeDefResult for the TypeDef types (Profile, Address, Job). The Gender enum export pattern (both const and type) matches the established code generation conventions.

tests/e2e/github-repos/formbricks/input.ts (1)

1-710: Generated input types file validates Formbricks schema compatibility.

This comprehensive generated type file covers all 35 models from the Formbricks schema, providing strongly-typed ORM argument and payload types. The consistent generation pattern (FindManyArgs, CreateArgs, WhereInput, GetPayload, etc.) for each model enables type-safe ORM operations. Based on learnings, this validates real-world schema compatibility with Formbricks, an established project.

tests/e2e/github-repos/trigger.dev/input.ts (1)

1-1030: Generated input types file validates Trigger.dev schema compatibility.

This generated type file covers 51 models from the Trigger.dev schema with the same consistent typing pattern. Based on learnings, this validates real-world schema compatibility with Trigger.dev, an established project, ensuring the ORM type generation works correctly for complex, production-grade schemas.

tests/e2e/orm/schemas/typed-json/input.ts (1)

1-30: LGTM! Generated file follows established patterns.

The generated type definitions correctly follow the same structure as other input files in the codebase (e.g., tests/e2e/github-repos/formbricks/input.ts and tests/e2e/github-repos/cal.com/input.ts). All standard ORM operation types for the User entity are properly exported with correct generic parameterization.

tests/e2e/github-repos/formbricks/models.ts (1)

1-468: LGTM! Comprehensive generated model definitions.

The generated models correctly follow established patterns from other e2e test schemas (e.g., tests/e2e/github-repos/cal.com/models.ts). The file includes:

  • 32 properly typed model exports using the $ModelResult pattern
  • Comprehensive JSDoc documentation for each entity
  • Consistent enum constant and type declarations
  • Real-world schema validation for Formbricks compatibility

This aligns with the coding guideline that E2E tests should validate real-world schema compatibility with established projects.

@ymc9 ymc9 merged commit 02dec0c into dev Dec 6, 2025
12 checks passed
@ymc9 ymc9 deleted the feat/typedef-filter branch December 6, 2025 07:25
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