Skip to content

feat(core): add readonly() property builder#7315

Open
B4nan wants to merge 1 commit intomasterfrom
feat/readonly-property
Open

feat(core): add readonly() property builder#7315
B4nan wants to merge 1 commit intomasterfrom
feat/readonly-property

Conversation

@B4nan
Copy link
Member

@B4nan B4nan commented Mar 15, 2026

Summary

  • Adds readonly() method to the defineEntity property builder that marks properties as readonly on the inferred entity type
  • Purely TypeScript — prevents assignment outside the constructor, no runtime ORM effect
  • Uses ReadonlyBuilderKeys type parameter on InferEntityFromProperties with a [RK] extends [never] fast-path

Type performance

  • Main defineEntity benchmarks: 0.00% (fast-path when no readonly() used)
  • Entity extends benchmarks: +5.8% (+85 instantiations, from ReadonlyBuilderKeys evaluation)
  • Embeddable extends benchmarks: +33% in percentage terms, but only +303 absolute instantiations on a low 914 baseline (2 tiny embeddables with 1 property each)
  • Non-defineEntity benchmarks: 0.00%

Test plan

  • Type assertion verifies readonly modifier on inferred entity type
  • Metadata matches non-readonly equivalent (no runtime effect)
  • yarn bench:types — all benchmarks at 0.00% delta after baseline updates
  • yarn tsc-check-tests — no new errors
  • defineEntity.test.ts passes with new readonly test case

🤖 Generated with Claude Code

@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@102243d). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #7315   +/-   ##
=========================================
  Coverage          ?   99.65%           
=========================================
  Files             ?      262           
  Lines             ?    25721           
  Branches          ?     6622           
=========================================
  Hits              ?    25631           
  Misses            ?       84           
  Partials          ?        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…bility

Adds a `readonly()` method to the `defineEntity` property builder that marks
properties as `readonly` on the inferred entity type. This is purely a
TypeScript feature — it prevents assignment outside the constructor but has
no runtime effect on ORM behavior.

The implementation uses a `ReadonlyBuilderKeys` type parameter on
`InferEntityFromProperties` with a `[RK] extends [never]` fast-path that
avoids overhead when no properties use `readonly()`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@B4nan B4nan force-pushed the feat/readonly-property branch from 4724c6b to c816faa Compare March 15, 2026 21:25
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