feat(core): Auto-initialise customFields for entities that support them#4965
Conversation
Relates to OSS-408
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…o-initialise-configcustomfields-for-plugin-entities
Relates to OSS-408
CI fix:
|
Summary
Auto-initialises an empty
customFieldsarray for every entity that supports custom fields, so a plugin'sconfigurationcallback can extend any such entity (core or plugin-defined) without the defensive guard:Resolves OSS-408.
How
getEntityNamesWithCustomFields()(register-custom-entity-fields.ts) detects custom-field-capable entities from the TypeORM metadata (they declare acustomFieldsembedded column) — aHasCustomFieldsimplementscheck isn't available at runtime.runPluginConfigurations()(bootstrap.ts) pre-seedsconfig.customFields[EntityName] = []for each of those before the pluginconfigurationcallbacks run, only where an entry doesn't already exist (never overwrites configured fields).Empty arrays are ignored by
registerCustomEntityFields(it already skips zero-length configs), so this is inert for entities nobody extends — no schema/column changes.The TypeScript half of the original issue (the
as anyfootgun) is already resolved onmain:CustomFieldsnow carries a& { [entity: string]: CustomFieldConfig[] }index signature, soconfig.customFields.CompanyRoleis typed without a cast. This PR adds the matching runtime guarantee.Tests
bootstrap.spec.ts— custom-field-capable entities get[]initialised; existing entries are preserved; and a@VendurePlugin({ configuration })canpushto another entity's custom fields without a guard. Source typechecks clean; related entity specs pass.Relates to OSS-408
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.