Skip to content

Add new auto builders - #7

Merged
vethman merged 2 commits into
mainfrom
autobuilders
Jul 20, 2026
Merged

vethman merged 2 commits into
mainfrom
autobuilders

Conversation

@vethman

@vethman vethman commented Jul 19, 2026

Copy link
Copy Markdown
Member

Auto builders, deprecation of the hand-written builders, and a large round of fixes

New: auto builders

  • CeriosAutoBuilder<T>() and CeriosClassAutoBuilder(Class) — base-class factories that generate a bare-name setter for every property, so hand-written setProperty wrappers are no longer needed. Custom methods mix freely with the generated setters, and the existing compile-time required-property tracking is kept: calling build() before all required properties are set is a compiler error.
  • Nested-builder composition — BuilderComposerFromFactory / ClassBuilderComposerFromFactory now accept auto-builder factories, so custom methods can hand callers a preconfigured child builder with full type safety.
  • Base types & shared builder logic — shared custom methods can be written once as a base-builder function (constrained on AutoBuilderBase<TBase> / ClassAutoBuilderBase<TBase>) and applied to each concrete auto builder via BuilderExtension, replacing the old generic base-builder-class pattern.
  • BuilderWith / ClassBuilderWith — ergonomic types for explicit return-type annotations, and one unified constructor shape new Builder(data, { requiredFields, validators }) for both factories.

Deprecations

  • CeriosBuilder and CeriosClassBuilder are deprecated and will be removed in the next major version. See MIGRATION.md for a per-feature before/after guide.
  • An all-optional type can now build() immediately — the compile-time gate dissolves when there are no required properties (all four base classes).

Fixes (highlights)

  • Builders no longer hand out or freeze their live internal state — build(), buildUnsafe(), buildFrozen(), buildSealed(), and buildPartial() all return proper copies, so mutating a result can no longer corrupt the builder.
  • Deep clone preserves Date, Map, Set, RegExp, and class prototypes, and handles circular references.
  • Prototype-pollution hardening: __proto__ is rejected as a key/path in all setters and is no longer a generated setter name.
  • Proxy edge cases fixed: properties named after inherited members (e.g. hasOwnProperty) can no longer silently invoke the real method, and copy-on-write preserves subclass instance fields, validators, and required fields.
  • Validation errors are now a typed CeriosBuilderError with missingFields / validationErrors, and failing validators are identified by index and name.

Packaging

  • Published artifacts are now explicit dual CJS/ESM with per-condition type declarations (.d.cts / .d.mts), built with tsdown (was tsup) and validated with @arethetypeswrong/cli in CI. Entry-point imports are unaffected.

@vethman vethman self-assigned this Jul 19, 2026
@vethman
vethman merged commit d659f04 into main Jul 20, 2026
1 check passed
@vethman
vethman deleted the autobuilders branch July 20, 2026 08:12
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