Skip to content

Exclude Unsupported type fields from ORM client typing and runtime validation#2448

Closed
Copilot wants to merge 3 commits into
devfrom
copilot/fix-unsupported-type-fields
Closed

Exclude Unsupported type fields from ORM client typing and runtime validation#2448
Copilot wants to merge 3 commits into
devfrom
copilot/fix-unsupported-type-fields

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 5, 2026

  • Modify packages/schema/src/schema.ts to exclude Unsupported type fields from ScalarFields and NonRelationFields TypeScript utility types
  • Modify packages/orm/src/client/zod/factory.ts to skip Unsupported type fields in makeCreateDataSchema, makeUpdateDataSchema, makeSelectSchema, makeOmitSchema, makeOrderBySchema, and makeDistinctSchema
  • Add tests in tests/e2e/orm/client-api/zod.test.ts to verify that Unsupported fields are excluded from create/update/select/orderBy Zod schemas
  • Fix TypeScript error in test schema (missing plugins: {} required by SchemaDef)
  • Run existing tests to verify no regressions (175 tests pass)
Original prompt

This section details on the original issue you should resolve

<issue_title>Unsupported type fields should be excluded from the ORM client</issue_title>
<issue_description></issue_description>

<agent_instructions>Make a fix to this issue.

For ZModel fields with Unsupported type, the ORM client should ignore them both on typing and runtime (reject during validation).</agent_instructions>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…lidation

Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix exclusion of unsupported type fields from ORM client Exclude Unsupported type fields from ORM client typing and runtime validation Mar 5, 2026
Copilot finished work on behalf of ymc9 March 5, 2026 01:17
@ymc9
Copy link
Copy Markdown
Member

ymc9 commented Mar 5, 2026

@copilot , zod tests are failing

…lugins property)

Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 5, 2026

@copilot , zod tests are failing

Fixed in 0f6a1ea. The test schema was missing the plugins property required by SchemaDef. Added plugins: {} to resolve the TypeScript type error.

Copilot finished work on behalf of ymc9 March 5, 2026 02:22
@ymc9
Copy link
Copy Markdown
Member

ymc9 commented Mar 5, 2026

@claude review

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Mar 5, 2026

Claude finished @ymc9's task —— View job


Code Review - Excluding Unsupported Type Fields

Reviewing the PR changes to exclude Unsupported type fields from ORM client typing and runtime validation.

Tasks:

  • Read and analyze changed files
  • Review implementation against requirements
  • Check for potential issues and improvements
  • Provide comprehensive feedback

Review Summary

The implementation correctly excludes Unsupported type fields from both TypeScript utility types and runtime Zod schema validation. The changes are well-implemented and comprehensive.

Strengths

  1. Complete Type System Integration - packages/schema/src/schema.ts:204-205, 226-227

    • Properly excludes Unsupported fields from ScalarFields and NonRelationFields utility types
    • Ensures type-level exclusion that prevents compilation errors
  2. Comprehensive Runtime Validation - packages/orm/src/client/zod/factory.ts

    • Correctly excludes Unsupported fields from all relevant schema generation methods:
      • makeCreateDataSchema (lines 1194-1196, 1553-1555)
      • makeSelectSchema (line 892)
      • makeOmitSchema (line 999)
      • makeOrderBySchema (lines 1070, 1103)
      • makeDistinctSchema (line 1103)
      • makePrimitiveFilterSchema returns z.never() (line 657)
  3. Consistent Pattern - All exclusions follow the same pattern: fieldDef.type !== 'Unsupported' or fieldDef.type === 'Unsupported'

  4. Comprehensive Test Coverage - tests/e2e/orm/client-api/zod.test.ts:1379-1439

    • Tests all major schema types (create, update, select, orderBy)
    • Verifies both positive and negative cases
    • Uses dedicated test schema with Unsupported field for isolation

🔍 Technical Analysis

Type System Changes: The utility type modifications in schema.ts ensure compile-time safety by excluding Unsupported fields from TypeScript type inference.

Runtime Schema Generation: The Zod factory changes ensure runtime validation rejects any attempts to use Unsupported fields in operations.

Filter Handling: Line 657 returns z.never() for Unsupported types in primitive filters, which correctly prevents any filter operations on these fields.

🟡 Minor Observations

  1. Consistent Exclusion Logic: The implementation correctly handles Unsupported fields across all contexts where they should be excluded - no gaps identified.

  2. Test Schema Structure: The test schema at lines 1382-1398 properly defines an Unsupported field for comprehensive testing.

Requirements Compliance

  • Typing exclusion: ScalarFields and NonRelationFields utility types properly exclude Unsupported fields
  • Runtime validation: All relevant Zod schema methods exclude Unsupported fields
  • Comprehensive coverage: Create, update, select, orderBy, distinct, and omit schemas all handle exclusion
  • Test coverage: Tests verify exclusion works for all major operation types

Verdict: APPROVED ✅

This is a well-implemented solution that correctly addresses the requirement to exclude Unsupported type fields from both the type system and runtime validation. The changes are comprehensive, consistent, and properly tested.


Copy link
Copy Markdown
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

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

Also, add a separate e2e test file for "Unsupported" field behavior under "tests/e2e/orm/client-api". Verify ORM runtime behavior and input/output typing.

fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
}
} else {
} else if (fieldDef.type !== 'Unsupported') {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

instead of adding a condition here, filter the fields used on the loop. Consider if you should extract a helper method for such filtering.

@ymc9 ymc9 closed this Mar 5, 2026
@ymc9 ymc9 deleted the copilot/fix-unsupported-type-fields branch March 9, 2026 17:52
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.

Unsupported type fields should be excluded from the ORM client

2 participants