Skip to content

refactor!: drop the class-level ~standard, leaving instance as the entry point - #16

Merged
btravers merged 1 commit into
mainfrom
refactor/drop-class-standard-schema
Aug 7, 2026
Merged

refactor!: drop the class-level ~standard, leaving instance as the entry point#16
btravers merged 1 commit into
mainfrom
refactor/drop-class-standard-schema

Conversation

@btravers

@btravers btravers commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
// before
fromSchema(Organization);
// after
fromSchema(Organization.instance);

What it bought, measured

fromSchema(Person)          → Person
fromSchema(Person.instance) → Person        ← identical
instance has ~standard?     → true          ← zod v4 provides it already

Exactly one thing: letting you drop .instance. instance is a zod schema and
zod implements Standard Schema, so it already carries ~standard and is
accepted by anything that takes one.

What it cost

The class was a validator in some contexts and not others. The README had
to say so:

It does not make z.object({ owner: Organization }) work — zod requires a
real ZodType, so nesting always goes through Organization.instance.

Two spellings of one concept that are not interchangeable, and you had to know
which context takes which. That is the same shape of problem that removed
encode() and collapsed decode/make.

#14 sharpened it further: .instance is now a valid entity field, so it is
unambiguously the composable surface. The class-level shortcut was the odd one
out.

Changes

  • attachInstance loses its second accessor; its comment no longer has to
    explain rebuilding "the schema (and its ~standard)"
  • EntityStatic loses the member
  • instance.spec.ts keeps the same coverage against instance, and gains an
    explicit assertion that instance is a Standard Schema — which is the fact
    this change relies on
  • README, package README and CLAUDE.md updated; CLAUDE.md also gains the
    union.ts entry it was missing from feat: add union(), a union of entities that is itself entity-like #15

Gate

format --check, lint, typecheck (three passes), test (108, 10 files),
knip, build — all green.

Copilot AI lite review requested due to automatic review settings August 7, 2026 00:32

Copilot AI left a comment

Copy link
Copy Markdown

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 removes the entity class-level Standard Schema entry point (~standard) so that Entity.instance is the sole composable/Standard-Schema surface, aligning with how zod v4 already implements Standard Schema on schemas and avoiding having two non-interchangeable spellings of “the validator”.

Changes:

  • Dropped ~standard from the entity static type surface (EntityStatic) and from runtime attachment (attachInstance).
  • Updated docs and examples to consistently use fromSchema(Organization.instance).
  • Updated tests to assert instance remains the Standard Schema entry point and that instance stays non-enumerable and cached.

Reviewed changes

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

Show a summary per file
File Description
README.md Updates Standard Schema guidance/examples to route through Organization.instance.
packages/entity/src/types.ts Removes ~standard from the EntityStatic type surface.
packages/entity/src/instance.ts Removes runtime definition of class-level ~standard; keeps lazy, cached instance.
packages/entity/src/instance.spec.ts Adjusts tests to validate instance as Standard Schema entry point and removes class-level ~standard expectations.
packages/entity/README.md Removes ~standard from the documented statics table; reinforces instance as the composable surface.
CLAUDE.md Updates module documentation for instance.ts and adds the missing union.ts entry.
.changeset/drop-class-standard-schema.md Adds a breaking-change note and migration guidance (fromSchema(X)fromSchema(X.instance)).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@btravers
btravers merged commit 0702730 into main Aug 7, 2026
14 checks passed
@btravers
btravers deleted the refactor/drop-class-standard-schema branch August 7, 2026 00:35
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