feat(pinia-orm)!: migrate to standard ECMAScript decorators#2045
Merged
Conversation
The property decorators now use the TC39 stage 3 decorator semantics shipped with TypeScript 5. Requires TypeScript >= 5.2 without the experimentalDecorators flag. BREAKING CHANGES: - decorated fields are declared with '!' instead of 'declare' (standard decorators cannot be applied to declare fields) - subclass field overrides need an initializer instead of '!' - NonEnumerable requires the accessor keyword - fields() based models keep using 'declare' for type declarations Decorators now register through decorator metadata (Symbol.metadata), which is scoped per class and inherited along the prototype chain - decorated fields of base classes are now visible on derived STI models without re-declaring them.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2045 +/- ##
==========================================
+ Coverage 99.29% 99.34% +0.05%
==========================================
Files 82 83 +1
Lines 3100 3185 +85
Branches 559 562 +3
==========================================
+ Hits 3078 3164 +86
+ Misses 16 15 -1
Partials 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Adds tests for the legacy-invocation error, programmatic setRegistry and NonEnumerable on subclasses (coverage back above baseline), the migration guide docs page and a codemod script that converts legacy decorator model definitions to the standard syntax.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What (breaking, targeted at 2.0.0)
Migrates all property decorators from the legacy
experimentalDecoratorsimplementation to the standard TC39 decorators that TypeScript supports natively since 5.0 (metadata since 5.2). With 2.0.0 being a major release, this is the right moment to require them.Requirements for users
experimentalDecoratorsremoved from tsconfig (legacy calls hit a helpful error message at runtime)Breaking changes in model definitions
@Attr('') declare name: string@Attr('') name!: string@Attr('dog') declare type: string@Attr('dog') type = 'dog'(initializer, value unused)@NonEnumerable hidden: string@NonEnumerable accessor hidden: stringfields()models typed withfield!: typedeclare field: type(a real class field would wipe the hydrated value)The docs Typescript guide is rewritten around these rules; all docs examples (37 pages), tests (38 files) and the nuxt3 playground are migrated.
How it works now
Metadata.ts: decorators write into decorator metadata (Symbol.metadata, polyfilled) — field factories, mutators, casts, hidden fields, onDelete modes.initializeSchema()consumes it.useDefineForClassFields) no longer wipe what the Model constructor filled.experimentalDecoratorsstill on) throws a descriptive error instead of failing silently.Behavior note
Extended models on the same entity (
class ExtendedUser extends Userwithout own entity) must be registered before the base class boots the entity — registration is now per class instead of leaking into a shared entity registry (adjusted in the has-many-through spec).Verification
tsc --noEmiterror count identical to baseline (53, all pre-existing)Not merged on purpose — please review, this is the biggest 2.0.0 breaking change.