Skip to content

feat(types): export ProductObjectSchema and extractObjectSchema to restore .extend() on intersection schemas#1971

Draft
bokelley wants to merge 2 commits into
mainfrom
claude/issue-1970-product-schema-extract-helper
Draft

feat(types): export ProductObjectSchema and extractObjectSchema to restore .extend() on intersection schemas#1971
bokelley wants to merge 2 commits into
mainfrom
claude/issue-1970-product-schema-extract-helper

Conversation

@bokelley
Copy link
Copy Markdown
Contributor

Closes #1970

Summary

ProductSchema changed from ZodObject to ZodIntersection in 8.1.0-beta.* to accommodate V1/V2 format variants, silently breaking any downstream that called .extend(), .omit(), or .pick() on it directly. This PR restores the ergonomics via two additive, non-breaking exports and fixes two broken examples in the docs.

New exports:

  • ProductObjectSchema — concrete ZodObject for the most common case (ProductSchema.extend(...)ProductObjectSchema.extend(...)). Directly replaces the documented pattern.
  • extractObjectSchema(schema) — generic helper that extracts the right-side ZodObject from any ZodIntersection<L, ZodObject<R>> produced by the codegen, for the other 96 intersection-shaped schemas in 8.1+.

Docs fixed:

  • docs/ZOD-SCHEMAS.md — corrected the broken ProductSchema.extend(...) example in the Advanced Usage section.
  • docs/ZOD-SCHEMAS.md — corrected the broken ProductSchema.passthrough() example in the Troubleshooting section (.passthrough() is also ZodObject-only).

Both exports include JSDoc examples and are available at import { ProductObjectSchema, extractObjectSchema } from '@adcp/sdk'.

What was tested

  • tsc --project tsconfig.lib.json --noEmit — clean (pre-existing deprecation warnings only, unrelated to this change)
  • prettier --check — clean on all changed files
  • Canary tests added to test/lib/zod-schemas.test.js verifying:
    • ProductObjectSchema has .extend, .omit, .pick
    • ProductObjectSchema.extend({ _test_field: z.string() }).safeParse(...) succeeds on a valid product
    • extractObjectSchema(ProductSchema) returns a ZodObject with .extend
    • The canary explicitly asserts ProductSchema._def.right exists, so a future codegen shape change surfaces as a readable test failure rather than a silent runtime error
  • Minor changeset included

Pre-PR review

  • code-reviewer: approved — export chain verified intact (schema-helpers.ts → named export in types/index.tsexport * from './types' in index.ts); runtime instanceof guard added per review feedback; canary test strengthened with _def.right pre-assertion.
  • dx-expert: approved — naming follows *Schema conventions; doc examples corrected including the passthrough() case that was equally broken; TS2339 → ProductObjectSchema mapping added.

Notes (not blocking)

  • A migration-8.0-to-8.1.md doc doesn't exist yet. Developers upgrading from 8.0 will find the fix via the corrected ZOD-SCHEMAS.md example, but a migration doc would be a useful follow-up.
  • extractObjectSchema does not handle chained intersections (.and().and()) — TypeScript's type system will surface this at compile time since the argument type won't match ZodIntersection<L, ZodObject<R>>.

Triage-managed PR. This bot does not currently iterate on
review comments or PR conversation threads (only on the source
issue). To unblock:

  • Push fixup commits directly: gh pr checkout <num>
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See adcp#3121
for context.

Session: https://claude.ai/code/session_01A2Thvmn8bFTS5gvJixQS2P


Generated by Claude Code

…store .extend() on intersection schemas

ProductSchema changed from ZodObject to ZodIntersection in 8.1.0-beta.* to
accommodate V1/V2 format variants, silently breaking .extend()/.omit()/.pick()
callers. Adds two additive non-breaking exports:

- ProductObjectSchema: concrete ZodObject export for the documented use case
- extractObjectSchema(): generic helper for any ZodIntersection<L, ZodObject<R>>

Includes a runtime guard that throws a readable error if the codegen ever
changes the intersection side that holds the ZodObject, and a canary test in
test/lib/zod-schemas.test.js.

Also fixes two broken examples in docs/ZOD-SCHEMAS.md (ProductSchema.extend()
and ProductSchema.passthrough() both fail on ZodIntersection in 8.1+).

Closes #1970

https://claude.ai/code/session_01A2Thvmn8bFTS5gvJixQS2P
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DX: ProductSchema shape change in 8.1 silently breaks .extend()/.omit()/.pick() consumers

2 participants