Add ConfigureJsonOptions and rename CrdtConfig to Harmony#87
Conversation
Let clients register JSON customizations before options freeze, and expose change type discriminators alongside CLR types. Co-authored-by: Cursor <cursoragent@cursor.com>
Replace JsonDerivedType with RegisteredChangeType and expose Types via IReadOnlyList to prevent external mutation. Co-authored-by: Cursor <cursoragent@cursor.com>
Split builders into separate files under SIL.Harmony.Config and update all references. Co-authored-by: Cursor <cursoragent@cursor.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughChangesHarmony configuration modernization
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Application
participant CrdtKernel
participant HarmonyConfig
participant JsonOptionsBuilder
participant DataModel
Application->>CrdtKernel: register Harmony services
CrdtKernel->>HarmonyConfig: apply configuration delegate
HarmonyConfig->>JsonOptionsBuilder: queue JSON option callbacks
CrdtKernel->>DataModel: resolve IOptions<HarmonyConfig>
JsonOptionsBuilder-->>CrdtKernel: apply options and freeze
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/SIL.Harmony/Config/ChangeTypeListBuilder.cs (1)
28-34: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd validation for duplicate discriminators.
Add<TDerived>only dedupes byType(Line 31), not byDiscriminator. If two different change types resolve to the sameTypeName, both get registered, and the collision only surfaces later as a genericDictionary.Addduplicate-keyArgumentExceptioninHarmonyConfig.BuildChangeDiscriminatorMaps, with no indication of which types collided. The prior explicit discriminator-type validation was reportedly removed in this refactor — worth restoring with a clearer error at registration time.💡 Proposed fix
public ChangeTypeListBuilder Add<TDerived>() where TDerived : IChange, IPolyType { CheckFrozen(); if (_types.Any(t => t.Type == typeof(TDerived))) return this; - _types.Add(new RegisteredChangeType(typeof(TDerived), TDerived.TypeName)); + var discriminator = TDerived.TypeName; + if (_types.Any(t => t.Discriminator == discriminator)) + throw new InvalidOperationException( + $"A change type with discriminator '{discriminator}' has already been registered."); + _types.Add(new RegisteredChangeType(typeof(TDerived), discriminator)); return this; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/SIL.Harmony/Config/ChangeTypeListBuilder.cs` around lines 28 - 34, Update ChangeTypeListBuilder.Add<TDerived> to validate TDerived.TypeName against existing RegisteredChangeType entries before adding; retain the existing type-based deduplication, but throw a clear error identifying both conflicting change types when a discriminator collision is found, so HarmonyConfig.BuildChangeDiscriminatorMaps is not reached with duplicate discriminators.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/SIL.Harmony/Config/ChangeTypeListBuilder.cs`:
- Around line 28-34: Update ChangeTypeListBuilder.Add<TDerived> to validate
TDerived.TypeName against existing RegisteredChangeType entries before adding;
retain the existing type-based deduplication, but throw a clear error
identifying both conflicting change types when a discriminator collision is
found, so HarmonyConfig.BuildChangeDiscriminatorMaps is not reached with
duplicate discriminators.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4ca1bb35-abbc-48ab-9fb6-91e3b3e80ffc
📒 Files selected for processing (20)
src/SIL.Harmony.Sample/SampleDbContext.cssrc/SIL.Harmony.Tests/Adapter/CustomObjectAdapterTests.cssrc/SIL.Harmony.Tests/ConfigTests.cssrc/SIL.Harmony.Tests/DataModelTestBase.cssrc/SIL.Harmony.Tests/PersistExtraDataTests.cssrc/SIL.Harmony/Adapters/CustomAdapterProvider.cssrc/SIL.Harmony/Adapters/DefaultAdapterProvider.cssrc/SIL.Harmony/Changes/Change.cssrc/SIL.Harmony/Changes/ChangeContext.cssrc/SIL.Harmony/Changes/PeekThenConcreteChangeConverter.cssrc/SIL.Harmony/Config/ChangeTypeListBuilder.cssrc/SIL.Harmony/Config/HarmonyConfig.cssrc/SIL.Harmony/Config/JsonOptionsBuilder.cssrc/SIL.Harmony/Config/ObjectTypeListBuilder.cssrc/SIL.Harmony/CrdtKernel.cssrc/SIL.Harmony/DataModel.cssrc/SIL.Harmony/Db/CrdtDbContextOptionsExtensions.cssrc/SIL.Harmony/Db/CrdtRepository.cssrc/SIL.Harmony/ResourceService.cssrc/SIL.Harmony/SnapshotWorker.cs
myieye
left a comment
There was a problem hiding this comment.
I think the Freeze methods should both be internal. I didn't check what they were before.
But everything looks good 👍
Co-authored-by: Tim Haasdyk <myieye@gmail.com>
Now clients don't need to do any weird workarounds to tweak json options. HarmonyConfig now exposes
RegisteredChangeTypefor types so clients can easily get the change discriminator without hacking around using reflection and stuff.Summary by CodeRabbit
ConfigureJsonOptionsfor polymorphic JSON behavior, with cumulative callbacks and a safe “frozen” enforcement.HarmonyConfig(replacing the prior configuration model) across database, repository, snapshots, and resources.