Skip to content

refactor: remove import from orm package in generated schema#2387

Merged
ymc9 merged 5 commits intodevfrom
refactor/schema-orm
Feb 20, 2026
Merged

refactor: remove import from orm package in generated schema#2387
ymc9 merged 5 commits intodevfrom
refactor/schema-orm

Conversation

@ymc9
Copy link
Copy Markdown
Member

@ymc9 ymc9 commented Feb 20, 2026

  • replace "@zenstackhq/orm" dependency with "@zenstackhq/schema"
  • add "--generate-models" and "--generate-input" switches to CLI to control what ts files are generated

Summary by CodeRabbit

  • New Features

    • CLI adds tri-state flags and new options to control generation of model and input type files.
  • Tests

    • Expanded test coverage for CLI flag interactions and generation outcomes (models, inputs, lite variants).
  • Chores

    • Standardized use of the core schema package across samples, tests, and runtime manifests.
  • Breaking Changes

    • Generated schema imports and some computed-field typings were simplified; downstream typings may be affected.

- replace "@zenstackhq/orm" dependency with "@zenstackhq/schema"
- add "--generate-models" and "--generate-input" switches to CLI to control what ts files are generated
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 20, 2026

Claude finished @ymc9's task —— View job


Code Review Analysis

Todo List

  • Analyze architectural changes from @zenstackhq/orm to @zenstackhq/schema
  • Review new CLI switches implementation
  • Check test coverage and potential breaking changes
  • Evaluate security and performance implications
  • Provide comprehensive feedback

Code Review Feedback

Positive Aspects

  1. Clean Architectural Separation: The refactoring successfully separates schema-related functionality from the ORM package, improving modularity and reducing coupling.

  2. Comprehensive CLI Implementation: The new --generate-models and --generate-input switches are well-implemented with proper:

    • Option parsing using tri-state boolean logic
    • CLI parameter merging with plugin configuration
    • Override precedence (CLI > plugin config > defaults)
  3. Excellent Test Coverage: Added 24 comprehensive test cases covering all combinations of the new CLI options and edge cases.

  4. Consistent Import Updates: All 43 files consistently updated from @zenstackhq/orm to @zenstackhq/schema.

🔍 Areas for Consideration

Breaking Change Risk

  • Impact: This is a breaking change for any code that directly imports from generated schema files
  • Mitigation: The change appears intentional and part of the v3 architectural refactoring
  • Recommendation: Ensure this is documented in migration guides

Type Safety

  • The TsSchemaGeneratorOptions interface properly handles the new options with sensible defaults:
    generateModelTypes?: boolean;   // defaults to true
    generateInputTypes?: boolean;   // defaults to true  

Dependency Management

  • Generated schema files now import from @zenstackhq/schema instead of @zenstackhq/orm
  • This appears to be part of a larger architectural refactoring to separate concerns
  • Need to ensure @zenstackhq/schema package exists and exports required types (SchemaDef, ExpressionUtils)

🏗️ Implementation Quality

CLI Integration (packages/cli/src/index.ts:97-98)

.addOption(triStateBooleanOption('--generate-models [boolean]', 'generate models.ts file, defaults to true'))
.addOption(triStateBooleanOption('--generate-input [boolean]', 'generate input.ts file, defaults to true'))
  • Proper use of tri-state boolean options
  • Clear help text with default behavior

Plugin Configuration Override (packages/cli/src/actions/generate.ts:192-197)

if (options.generateModels !== undefined) {
    pluginOptions['generateModels'] = options.generateModels;
}
if (options.generateInput !== undefined) {
    pluginOptions['generateInput'] = options.generateInput;
}
  • Correctly implements CLI precedence over plugin configuration

Schema Generator Logic (packages/sdk/src/ts-schema-generator.ts:77-84)

// the model types
if (options.generateModelTypes !== false) {
    this.generateModelsAndTypeDefs(model, options);
}

// the input types  
if (options.generateInputTypes !== false) {
    this.generateInputTypes(model, options);
}
  • Sensible default behavior (generate unless explicitly disabled)

🚨 Potential Issues

  1. Package Dependencies: Need to verify that all affected packages properly declare @zenstackhq/schema as a dependency

  2. Generated Code Compatibility: The import change in generated files is a breaking change that will require users to update their dependency declarations

📋 Summary

This is a well-executed refactoring that improves the architecture by:

  • Separating schema functionality from ORM runtime
  • Adding granular control over TypeScript file generation
  • Maintaining backward compatibility through sensible defaults
  • Providing comprehensive test coverage

The implementation follows good practices with proper option handling, precedence rules, and type safety. The breaking change appears intentional as part of the v3 architectural improvements.

Recommendation: ✅ Approve - This PR successfully implements the intended refactoring with good code quality and comprehensive testing.


@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 20, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Makes lite/liteOnly CLI flags tri-state/optional, adds --generate-models and --generate-input flags, updates TypeScript schema generator to honor these flags, removes OperandExpression from many generated computed-field types, and migrates imports from @zenstackhq/orm/schema to @zenstackhq/schema.

Changes

Cohort / File(s) Summary
CLI core & actions
packages/cli/src/index.ts, packages/cli/src/actions/generate.ts
Adds triStateBooleanOption; makes lite/liteOnly optional tri-state; adds --generate-models and --generate-input; propagates new options through CLI and plugin merge logic.
CLI TypeScript plugin
packages/cli/src/plugins/typescript.ts
Reads generateModelTypes / generateInputTypes from plugin options and passes them to the TS schema generator.
CLI tests
packages/cli/test/generate.test.ts
Adds tests for combinations and precedence of lite, liteOnly, generateModels, and generateInput (plugin defaults vs CLI overrides).
SDK generator
packages/sdk/src/ts-schema-generator.ts
Adds generateModelTypes? and generateInputTypes? options; conditionally emits model/input type files; removes OperandExpression usage from generated schema code and adjusts imports.
ORM client types
packages/orm/src/client/options.ts
Switches computed-field function signatures to use kysely's OperandExpression-wrapped return types and removes PrependParameter usage.
Import path migrations
samples/..., tests/..., packages/clients/tanstack-query/test/schemas/*
Replaces many imports from @zenstackhq/orm/schema with @zenstackhq/schema across samples, tests, and generated schema files.
Generated schema type updates
samples/orm/.../schema.ts, tests/e2e/orm/schemas/typing/schema.ts, tests/.../typing/schema.ts
Computed-field resolver return types changed (e.g., OperandExpression<T>T); updated imports and stubs accordingly.
Package manifests & tooling
samples/*/package.json, tests/runtimes/*/package.json, tests/regression/package.json, samples/orm/package.json, turbo.json
Adds @zenstackhq/schema as workspace:* dependency in multiple manifests; renames samples/orm package name; expands turbo build outputs to include .output/**.
Test tooling symlinks
packages/testtools/src/project.ts
Includes 'schema' in the set of zenstack packages symlinked into test project node_modules/@zenstackhq.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I nibbled flags both maybe and true,

Sprouted two options — models and input too.
Imports hopped houses to a simpler name,
Computed fields dropped a wrapper's claim.
Tests thumped the ground — the rabbit's game! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary refactoring objective of replacing orm package imports with schema package imports in generated files, which is the main structural change across numerous test and sample files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/schema-orm

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.

Copy link
Copy Markdown
Contributor

@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: 1

Caution

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

⚠️ Outside diff range comments (1)
packages/sdk/src/ts-schema-generator.ts (1)

124-145: ⚠️ Potential issue | 🔴 Critical

Both exports verified in @zenstackhq/schema, but migration is incomplete across the codebase.

The target package correctly exports both SchemaDef (type) and ExpressionUtils (const) via its index entry point. However, many other files still import from the old path @zenstackhq/orm/schema (packages/zod, packages/testtools, packages/server, packages/plugins/policy). Update all remaining imports to use @zenstackhq/schema for consistency.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/sdk/src/ts-schema-generator.ts` around lines 124 - 145, Search the
repo for any import declarations referencing the old module specifier
'@zenstackhq/orm/schema' and replace them with '@zenstackhq/schema'; ensure
imports bring in the type-only SchemaDef and the const ExpressionUtils the same
way as the schemaImportDecl pattern in ts-schema-generator.ts (use a type-only
import for SchemaDef and include ExpressionUtils only when used, guided by the
usedExpressionUtils flag/logic), updating import specifiers across all modules
that still reference the old path so they consistently import SchemaDef and
ExpressionUtils from '@zenstackhq/schema'.
🧹 Nitpick comments (1)
packages/cli/src/plugins/typescript.ts (1)

31-44: Naming mismatch between plugin option keys and generator option names.

The plugin reads pluginOptions['generateModels'] / pluginOptions['generateInput'] but passes them as generateModelTypes / generateInputTypes to the generator. While functionally correct, the suffix difference (Models vs ModelTypes, Input vs InputTypes) could confuse future maintainers. Consider aligning the names across the chain — either rename the TsSchemaGeneratorOptions fields to generateModels/generateInput, or use generateModelTypes/generateInputTypes consistently everywhere.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/src/plugins/typescript.ts` around lines 31 - 44, The plugin maps
pluginOptions['generateModels'] and pluginOptions['generateInput'] to local
variables named generateModelTypes and generateInputTypes and passes them into
TsSchemaGenerator.generate, causing a naming mismatch; update the code so the
option names are consistent across the chain—either rename the
TsSchemaGeneratorOptions fields to generateModels and generateInput (preferred
for minimal change in the plugin) or rename the plugin's local variables and the
pluginOptions keys to generateModelTypes and generateInputTypes (if you prefer
the more explicit “Types” suffix); make the change in the TsSchemaGenerator
class/interface (constructor/options type) and in the call site inside
TsSchemaGenerator().generate so both sides use the same identifiers (refer to
pluginOptions, generateModelTypes/generateInputTypes, and
TsSchemaGenerator.generate).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/regression/test/issue-422/schema.ts`:
- Line 8: Add the missing `@zenstackhq/schema` dependency to the regression test
package: update tests/regression/package.json by adding "@zenstackhq/schema" to
either "dependencies" or "devDependencies" (use the same version used elsewhere
in the repo or a compatible/latest version) so the imports in
tests/regression/test/issue-422/schema.ts and
tests/regression/test/issue-503/schema.ts can resolve; after adding, run
npm/yarn install for tests/regression and re-run the regression suite to confirm
compilation succeeds.

---

Outside diff comments:
In `@packages/sdk/src/ts-schema-generator.ts`:
- Around line 124-145: Search the repo for any import declarations referencing
the old module specifier '@zenstackhq/orm/schema' and replace them with
'@zenstackhq/schema'; ensure imports bring in the type-only SchemaDef and the
const ExpressionUtils the same way as the schemaImportDecl pattern in
ts-schema-generator.ts (use a type-only import for SchemaDef and include
ExpressionUtils only when used, guided by the usedExpressionUtils flag/logic),
updating import specifiers across all modules that still reference the old path
so they consistently import SchemaDef and ExpressionUtils from
'@zenstackhq/schema'.

---

Duplicate comments:
In `@tests/regression/test/issue-503/schema.ts`:
- Line 8: The test imports SchemaDef and ExpressionUtils from
"@zenstackhq/schema" but the regression test package is missing that dependency;
add "@zenstackhq/schema" to the tests/regression/package.json dependencies (or
devDependencies) so imports of SchemaDef and ExpressionUtils resolve at test
runtime, mirroring the fix applied for issue-422.

---

Nitpick comments:
In `@packages/cli/src/plugins/typescript.ts`:
- Around line 31-44: The plugin maps pluginOptions['generateModels'] and
pluginOptions['generateInput'] to local variables named generateModelTypes and
generateInputTypes and passes them into TsSchemaGenerator.generate, causing a
naming mismatch; update the code so the option names are consistent across the
chain—either rename the TsSchemaGeneratorOptions fields to generateModels and
generateInput (preferred for minimal change in the plugin) or rename the
plugin's local variables and the pluginOptions keys to generateModelTypes and
generateInputTypes (if you prefer the more explicit “Types” suffix); make the
change in the TsSchemaGenerator class/interface (constructor/options type) and
in the call site inside TsSchemaGenerator().generate so both sides use the same
identifiers (refer to pluginOptions, generateModelTypes/generateInputTypes, and
TsSchemaGenerator.generate).

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 20, 2026

Claude finished @ymc9's task —— View job


Code Review Analysis

Todo List

  • Analyze architectural changes from @zenstackhq/orm to @zenstackhq/schema
  • Review new CLI switches implementation
  • Check test coverage and potential breaking changes
  • Evaluate security and performance implications
  • Provide comprehensive feedback

Code Review Feedback

Positive Aspects

  1. Clean Architectural Separation: The refactoring successfully separates schema-related functionality from the ORM package, improving modularity and reducing coupling.

  2. Comprehensive CLI Implementation: The new --generate-models and --generate-input switches are well-implemented with proper:

    • Option parsing using tri-state boolean logic
    • CLI parameter merging with plugin configuration
    • Override precedence (CLI > plugin config > defaults)
  3. Excellent Test Coverage: Added 24 comprehensive test cases covering all combinations of the new CLI options and edge cases.

  4. Consistent Import Updates: All 43 files consistently updated from @zenstackhq/orm to @zenstackhq/schema.

🔍 Areas for Consideration

Breaking Change Risk

  • Impact: This is a breaking change for any code that directly imports from generated schema files
  • Mitigation: The change appears intentional and part of the v3 architectural refactoring
  • Recommendation: Ensure this is documented in migration guides

Type Safety

  • The TsSchemaGeneratorOptions interface properly handles the new options with sensible defaults:
    generateModelTypes?: boolean;   // defaults to true
    generateInputTypes?: boolean;   // defaults to true  

Dependency Management

  • Generated schema files now import from @zenstackhq/schema instead of @zenstackhq/orm
  • This appears to be part of a larger architectural refactoring to separate concerns
  • Need to ensure @zenstackhq/schema package exists and exports required types (SchemaDef, ExpressionUtils)

🏗️ Implementation Quality

CLI Integration (packages/cli/src/index.ts:97-98)

.addOption(triStateBooleanOption('--generate-models [boolean]', 'generate models.ts file, defaults to true'))
.addOption(triStateBooleanOption('--generate-input [boolean]', 'generate input.ts file, defaults to true'))
  • Proper use of tri-state boolean options
  • Clear help text with default behavior

Plugin Configuration Override (packages/cli/src/actions/generate.ts:192-197)

if (options.generateModels !== undefined) {
    pluginOptions['generateModels'] = options.generateModels;
}
if (options.generateInput !== undefined) {
    pluginOptions['generateInput'] = options.generateInput;
}
  • Correctly implements CLI precedence over plugin configuration

Schema Generator Logic (packages/sdk/src/ts-schema-generator.ts:77-84)

// the model types
if (options.generateModelTypes !== false) {
    this.generateModelsAndTypeDefs(model, options);
}

// the input types  
if (options.generateInputTypes !== false) {
    this.generateInputTypes(model, options);
}
  • Sensible default behavior (generate unless explicitly disabled)

🚨 Issues Identified

  1. Incomplete Migration: 36 files still import from @zenstackhq/orm/schema instead of @zenstackhq/schema, including critical packages like:

    • packages/plugins/policy/*
    • packages/server/*
    • packages/zod/*
    • packages/testtools/*
  2. Missing Dependencies: Some test packages may be missing the @zenstackhq/schema dependency (e.g., regression tests)

  3. Naming Inconsistency: Minor mismatch between plugin option names (generateModels/generateInput) and generator option names (generateModelTypes/generateInputTypes)

🔒 Security & Performance

  • Security: No security concerns identified - this is a refactoring with no functional changes to access control or data handling
  • Performance: Minimal performance impact - the changes are primarily organizational and don't affect runtime behavior
  • Generated Code: The generated schema files maintain the same structure and functionality

📋 Summary

This is a well-executed refactoring that improves the architecture by:

  • Separating schema functionality from ORM runtime
  • Adding granular control over TypeScript file generation
  • Maintaining backward compatibility through sensible defaults
  • Providing comprehensive test coverage

The implementation follows good practices with proper option handling, precedence rules, and type safety. The breaking change appears intentional as part of the v3 architectural improvements.

Recommendation: ✅ Approve with Minor Fixes - Complete the import migration for the remaining 36 files and ensure all packages have proper dependencies before merging.


@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 20, 2026

Claude finished @ymc9's task —— View job


Code Review Analysis

Todo List

  • Analyze architectural changes from @zenstackhq/orm to @zenstackhq/schema
  • Review new CLI switches implementation
  • Check test coverage and potential breaking changes
  • Evaluate security and performance implications
  • Provide comprehensive feedback

Code Review Feedback

Positive Aspects

  1. Clean Architectural Separation: The refactoring successfully separates schema-related functionality from the ORM package, improving modularity and reducing coupling.

  2. Comprehensive CLI Implementation: The new --generate-models and --generate-input switches are well-implemented with proper:

    • Option parsing using tri-state boolean logic
    • CLI parameter merging with plugin configuration
    • Override precedence (CLI > plugin config > defaults)
  3. Excellent Test Coverage: Added 24 comprehensive test cases covering all combinations of the new CLI options and edge cases.

  4. Consistent Import Updates: All 43 files consistently updated from @zenstackhq/orm to @zenstackhq/schema.

🔍 Areas for Consideration

Breaking Change Risk

  • Impact: This is a breaking change for any code that directly imports from generated schema files
  • Mitigation: The change appears intentional and part of the v3 architectural refactoring
  • Recommendation: Ensure this is documented in migration guides

Type Safety

  • The TsSchemaGeneratorOptions interface properly handles the new options with sensible defaults:
    generateModelTypes?: boolean;   // defaults to true
    generateInputTypes?: boolean;   // defaults to true  

Dependency Management

  • Generated schema files now import from @zenstackhq/schema instead of @zenstackhq/orm
  • This appears to be part of a larger architectural refactoring to separate concerns
  • Need to ensure @zenstackhq/schema package exists and exports required types (SchemaDef, ExpressionUtils)

🏗️ Implementation Quality

CLI Integration (packages/cli/src/index.ts:97-98)

.addOption(triStateBooleanOption('--generate-models [boolean]', 'generate models.ts file, defaults to true'))
.addOption(triStateBooleanOption('--generate-input [boolean]', 'generate input.ts file, defaults to true'))
  • Proper use of tri-state boolean options
  • Clear help text with default behavior

Plugin Configuration Override (packages/cli/src/actions/generate.ts:192-197)

if (options.generateModels !== undefined) {
    pluginOptions['generateModels'] = options.generateModels;
}
if (options.generateInput !== undefined) {
    pluginOptions['generateInput'] = options.generateInput;
}
  • Correctly implements CLI precedence over plugin configuration

Schema Generator Logic (packages/sdk/src/ts-schema-generator.ts:77-84)

// the model types
if (options.generateModelTypes !== false) {
    this.generateModelsAndTypeDefs(model, options);
}

// the input types  
if (options.generateInputTypes !== false) {
    this.generateInputTypes(model, options);
}
  • Sensible default behavior (generate unless explicitly disabled)

🚨 Issues Identified

  1. Incomplete Migration: 36 files still import from @zenstackhq/orm/schema instead of @zenstackhq/schema, including critical packages like:

    • packages/plugins/policy/*
    • packages/server/*
    • packages/zod/*
    • packages/testtools/*
  2. Missing Dependencies: Some test packages may be missing the @zenstackhq/schema dependency (e.g., regression tests)

  3. Naming Inconsistency: Minor mismatch between plugin option names (generateModels/generateInput) and generator option names (generateModelTypes/generateInputTypes)

🔒 Security & Performance

  • Security: No security concerns identified - this is a refactoring with no functional changes to access control or data handling
  • Performance: Minimal performance impact - the changes are primarily organizational and don't affect runtime behavior
  • Generated Code: The generated schema files maintain the same structure and functionality

📋 Summary

This is a well-executed refactoring that improves the architecture by:

  • Separating schema functionality from ORM runtime
  • Adding granular control over TypeScript file generation
  • Maintaining backward compatibility through sensible defaults
  • Providing comprehensive test coverage

The implementation follows good practices with proper option handling, precedence rules, and type safety. The breaking change appears intentional as part of the v3 architectural improvements.

Recommendation: ✅ Approve with Minor Fixes - Complete the import migration for the remaining 36 files and ensure all packages have proper dependencies before merging.


@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 20, 2026

Claude finished @ymc9's task —— View job


Code Review Analysis

Todo List

  • Read repository guidelines and understand the codebase structure
  • Analyze architectural changes from @zenstackhq/orm to @zenstackhq/schema
  • Review new CLI switches implementation
  • Check test coverage and potential breaking changes
  • Evaluate security and performance implications
  • Identify any incomplete migrations or missing dependencies
  • Provide comprehensive feedback

Code Review Feedback

Positive Aspects

  1. Clean Architectural Separation: The refactoring successfully separates schema-related functionality from the ORM package, improving modularity and reducing coupling between concerns.

  2. Comprehensive CLI Implementation: The new --generate-models and --generate-input switches are well-implemented with:

    • Proper tri-state boolean logic using the existing triStateBooleanOption helper
    • CLI parameter merging with plugin configuration in packages/cli/src/actions/generate.ts:192-197
    • Correct override precedence (CLI > plugin config > defaults)
  3. Excellent Test Coverage: Added 24 comprehensive test cases in packages/cli/test/generate.test.ts covering:

    • All combinations of the new CLI options
    • Plugin configuration defaults vs CLI overrides
    • Edge cases and precedence rules
  4. Consistent Import Updates: Successfully updated 43 files to import from @zenstackhq/schema instead of @zenstackhq/orm.

🔍 Areas for Consideration

Breaking Change Impact

  • Impact: This is an intentional breaking change for any code that directly imports from generated schema files
  • Mitigation: The change aligns with the v3 architectural refactoring mentioned in CLAUDE.md
  • Recommendation: Ensure this is properly documented in migration guides

Type Safety Implementation

The TsSchemaGeneratorOptions interface properly handles the new options with sensible defaults:

generateModelTypes?: boolean;   // defaults to true
generateInputTypes?: boolean;   // defaults to true  

🏗️ Implementation Quality Analysis

CLI Integration (packages/cli/src/index.ts:97-98)

.addOption(triStateBooleanOption('--generate-models [boolean]', 'generate models.ts file, defaults to true'))
.addOption(triStateBooleanOption('--generate-input [boolean]', 'generate input.ts file, defaults to true'))

✅ Proper use of existing tri-state boolean pattern with clear help text

Plugin Configuration Override (packages/cli/src/actions/generate.ts:192-197)

if (options.generateModels !== undefined) {
    pluginOptions['generateModels'] = options.generateModels;
}
if (options.generateInput !== undefined) {
    pluginOptions['generateInput'] = options.generateInput;
}

✅ Correctly implements CLI precedence over plugin configuration

Schema Generator Logic (packages/sdk/src/ts-schema-generator.ts:77-84)

// the model types
if (options.generateModelTypes !== false) {
    this.generateModelsAndTypeDefs(model, options);
}

// the input types  
if (options.generateInputTypes !== false) {
    this.generateInputTypes(false !== false) {
    this.generateInputTypes(model, options);
}

✅ Sensible default behavior (generate unless explicitly disabled)

🚨 Critical Issues Identified

  1. Incomplete Migration: 36+ files still import from @zenstackhq/orm/schema instead of @zenstackhq/schema, including critical packages:

    • packages/plugins/policy/*
    • packages/server/*
    • packages/zod/*
    • packages/testtools/*

    This creates inconsistency and potential runtime issues.

  2. Naming Inconsistency (packages/cli/src/plugins/typescript.ts:31-44):

    • Plugin reads pluginOptions['generateModels']/pluginOptions['generateInput']
    • But passes them as generateModelTypes/generateInputTypes to the generator
    • While functionally correct, this naming mismatch could confuse maintainers
  3. Import Declaration Correctness: The new import pattern in generated schemas is well-implemented:

    // import { type SchemaDef, ExpressionUtils } from '@zenstackhq/schema';

    Uses type-only imports for SchemaDef and conditionally includes ExpressionUtils based on usage.

🔒 Security & Performance Assessment

  • Security: ✅ No security concerns identified - this is purely organizational refactoring with no changes to access control or data handling
  • Performance: ✅ Minimal performance impact - changes are primarily organizational and don't affect runtime behavior
  • Generated Code: ✅ Maintains same structure and functionality while improving import clarity

🧪 Test Coverage Analysis

The test coverage is exemplary with 24 test cases covering:

  • Default behavior when no CLI flags are provided
  • Individual flag behavior (--generate-models, --generate-input)
  • Plugin configuration defaults
  • CLI precedence over plugin settings
  • All combinations of lite/liteOnly with new generation flags

📋 Summary & Recommendation

This is a well-executed architectural refactoring that successfully:

  • ✅ Separates schema functionality from ORM runtime concerns
  • ✅ Adds granular control over TypeScript file generation with sensible defaults
  • ✅ Maintains backward compatibility through intelligent default behavior
  • ✅ Provides comprehensive test coverage demonstrating thorough planning

Primary Issues to Address:

  1. Complete the import migration for the remaining 36 files still referencing @zenstackhq/orm/schema
  2. Consider aligning naming between plugin options and generator options for consistency

Final Recommendation: ✅ Approve with Minor Fixes Required - This PR implements valuable architectural improvements with good engineering practices. Complete the import migration before merging to ensure consistency across the codebase.


@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 20, 2026

Claude finished @ymc9's task —— View job


Code Review Analysis

Todo List

  • Read repository guidelines and understand the codebase structure
  • Analyze architectural changes from @zenstackhq/orm to @zenstackhq/schema
  • Review new CLI switches implementation
  • Check test coverage and potential breaking changes
  • Evaluate security and performance implications
  • Identify any incomplete migrations or missing dependencies
  • Provide comprehensive feedback

Code Review Feedback

Positive Aspects

  1. Clean Architectural Separation: The refactoring successfully separates schema-related functionality from the ORM package, improving modularity and reducing coupling between concerns.

  2. Comprehensive CLI Implementation: The new --generate-models and --generate-input switches are well-implemented with:

    • Proper tri-state boolean logic using the existing triStateBooleanOption helper
    • CLI parameter merging with plugin configuration in packages/cli/src/actions/generate.ts:192-197
    • Correct override precedence (CLI > plugin config > defaults)
  3. Excellent Test Coverage: Added 24 comprehensive test cases in packages/cli/test/generate.test.ts covering:

    • All combinations of the new CLI options
    • Plugin configuration defaults vs CLI overrides
    • Edge cases and precedence rules
  4. Consistent Import Updates: Successfully updated 43 files to import from @zenstackhq/schema instead of @zenstackhq/orm.

🔍 Areas for Consideration

Breaking Change Impact

  • Impact: This is an intentional breaking change for any code that directly imports from generated schema files
  • Mitigation: The change aligns with the v3 architectural refactoring mentioned in CLAUDE.md
  • Recommendation: Ensure this is properly documented in migration guides

Type Safety Implementation

The TsSchemaGeneratorOptions interface properly handles the new options with sensible defaults:

generateModelTypes?: boolean;   // defaults to true
generateInputTypes?: boolean;   // defaults to true  

🏗️ Implementation Quality Analysis

CLI Integration (packages/cli/src/index.ts:97-98)

.addOption(triStateBooleanOption('--generate-models [boolean]', 'generate models.ts file, defaults to true'))
.addOption(triStateBooleanOption('--generate-input [boolean]', 'generate input.ts file, defaults to true'))

✅ Proper use of existing tri-state boolean pattern with clear help text

Plugin Configuration Override (packages/cli/src/actions/generate.ts:192-197)

if (options.generateModels !== undefined) {
    pluginOptions['generateModels'] = options.generateModels;
}
if (options.generateInput !== undefined) {
    pluginOptions['generateInput'] = options.generateInput;
}

✅ Correctly implements CLI precedence over plugin configuration

Schema Generator Logic (packages/sdk/src/ts-schema-generator.ts:77-84)

// the model types
if (options.generateModelTypes !== false) {
    this.generateModelsAndTypeDefs(model, options);
}

// the input types  
if (options.generateInputTypes !== false) {
    this.generateInputTypes(model, options);
}

✅ Sensible default behavior (generate unless explicitly disabled)

🚨 Critical Issues Identified

  1. Incomplete Migration: 36+ files still import from @zenstackhq/orm/schema instead of @zenstackhq/schema, including critical packages:

    • packages/plugins/policy/*
    • packages/server/*
    • packages/zod/*
    • packages/testtools/*

    This creates inconsistency and potential runtime issues.

  2. Naming Inconsistency (packages/cli/src/plugins/typescript.ts:31-44):

    • Plugin reads pluginOptions['generateModels']/pluginOptions['generateInput']
    • But passes them as generateModelTypes/generateInputTypes to the generator
    • While functionally correct, this naming mismatch could confuse maintainers
  3. Import Declaration Correctness: The new import pattern in generated schemas is well-implemented:

    // import { type SchemaDef, ExpressionUtils } from '@zenstackhq/schema';

    Uses type-only imports for SchemaDef and conditionally includes ExpressionUtils based on usage.

🔒 Security & Performance Assessment

  • Security: ✅ No security concerns identified - this is purely organizational refactoring with no changes to access control or data handling
  • Performance: ✅ Minimal performance impact - changes are primarily organizational and don't affect runtime behavior
  • Generated Code: ✅ Maintains same structure and functionality while improving import clarity

🧪 Test Coverage Analysis

The test coverage is exemplary with 24 test cases covering:

  • Default behavior when no CLI flags are provided
  • Individual flag behavior (--generate-models, --generate-input)
  • Plugin configuration defaults
  • CLI precedence over plugin settings
  • All combinations of lite/liteOnly with new generation flags

📋 Summary & Recommendation

This is a well-executed architectural refactoring that successfully:

  • ✅ Separates schema functionality from ORM runtime concerns
  • ✅ Adds granular control over TypeScript file generation with sensible defaults
  • ✅ Maintains backward compatibility through intelligent default behavior
  • ✅ Provides comprehensive test coverage demonstrating thorough planning

Primary Issues to Address:

  1. Complete the import migration for the remaining 36 files still referencing @zenstackhq/orm/schema
  2. Consider aligning naming between plugin options and generator options for consistency

Final Recommendation: ✅ Approve with Minor Fixes Required - This PR implements valuable architectural improvements with good engineering practices. Complete the import migration before merging to ensure consistency across the codebase.


@ymc9 ymc9 merged commit 3e03ab1 into dev Feb 20, 2026
8 checks passed
@ymc9 ymc9 deleted the refactor/schema-orm branch February 20, 2026 02:16
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.

1 participant