Skip to content

feat: rebuild a stored wrapper element without its Parse (IStoredValueRebuild, #488) - #644

Merged
CaffeinatedCoder merged 6 commits into
mainfrom
design/488-unvalidated-rebuild
Nov 30, 2026
Merged

CaffeinatedCoder merged 6 commits into
mainfrom
design/488-unvalidated-rebuild

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Closes #488.

Problem

A wrapper value set (StringSet<PermissionKey>, Int32Set<OrderId>, …) rebuilt every stored element through TElement.Parse. Tighten a rule in Parse and every row holding an older element stopped loading. Saving it threw too, and so did Contains(oldElement), because the write's round-trip check (#53) and a bound element went through the same Parse.

Change

As decided on #488 (option 2, the design this PR held as a draft):

  • IStoredValueRebuild<TSelf, TPrimitive> in CodoMetis.ValueRanges.Core: static abstract TSelf FromStored(TPrimitive stored). TPrimitive is the primitive the family wraps (string, int, DateOnly, …, YearMonth for YearMonthSet<T>). Over another primitive it is ignored.
  • EF column path only. StringBridgedSetTypeDefinition and BridgedSetTypeDefinition find the interface when their closed definition is built (StoredRebuild.For, an interface lookup, then a helper closed over the element type for the static abstract call). With it, FromPrimitive rebuilds through FromStored, and the read, the write's round-trip check and the element mapping (a bound Contains operand) all go through FromPrimitive, so they agree. The round-trip check stays, rebuilt through FromStored: an element that formats as other text than it holds is still refused on both legs.
  • Input keeps Parse: the array literal, Parse/TryParse, JSON, and a set inside a JSON document. ValueSetTypeMapping.ParseStoreText gets its own strict leg (fromStoreText), which matters for YearMonthSet<T>, the one family that reads its store text through fromPrimitive.
  • YearMonthSet<T> stores a first-of-month LocalDate while its element wraps a YearMonth, so it registers through SetTypeRegistry.BridgedVia<LocalDate, YearMonth>, which hands FromStored the month. The clone sweep reads BridgedVia as Bridged, with a waiver for the extra storedValue argument.
  • Output stays strict (maintainer's decision, 2026-11-30): ToString and JSON of a loaded set still check each element through Parse, so a set holding an element Parse now refuses throws InvalidOperationException when formatted. It can be loaded, changed and saved. The live test found this and the docs state it as a limit; making output use FromStored would need a static abstract call from the core's generic sets, which is AOT-hostile.
  • Docs: value-sets.md#load-stored-values-after-a-rule-tightens (new) and a sentence in efcore.md. Fragment changes/488.md (Added; core, efcore, efcore-nodatime). No answer changes for an element type that doesn't implement the interface.

Tests

  • StoredRebuildBridgeTests (EF, no database; 15 tests): the read, the write check and a bound element, for the string, integer and date families; an element without the interface and one implementing it over the wrong primitive still run Parse; a decorating element is refused on both legs; the literal, JSON and a set inside a JSON document still refuse the element. The probe elements refuse old values in Parse, and FromStored builds them, so there is no shared switch.
  • NodaStoredRebuildTests (NodaTime EF, no database): YearMonthSet<T> is handed the month; the literal and its store text stay strict.
  • StoredRebuildIntegrationTests (live): writes {old:key}, {-7} and {1999-12-01} with SQL, then loads the row, saves it with a new element added, and finds it with Contains of each old element. The literal and JSON still refuse. It uses one database and drops it WITH (FORCE). Not run locally (no Docker for this lane); CI is the authority.
  • Oracle StoredRebuildBridgeTests registered, with three seeds, one per place, each CAUGHT by its own tests: stored-rebuild-read-runs-parse (3 Read tests), stored-rebuild-write-check-runs-parse (2 Write tests + the 2 Bind tests, which share the leg), stored-rebuild-bound-element-runs-parse (2 Bind tests).
  • Claim V99-stored-value-rebuild-column-only, held by the three classes.
  • Local: core, NodaTime, EF and NodaTime EF unit projects and the conventions project, all green.
  • AOT consumer: not added. The interface has no code in the AOT-compiled packages. Its only caller is the EF package, which isn't AOT-compiled and already closes definitions with MakeGenericType. A case would only test the runtime's static abstract dispatch.
  • TypeKit emitting FromStored from IValueObjectMaterializer is a separate TypeKit issue (not filed here).

🤖 Generated with Claude Code

Design only, for the maintainer's decision; no code yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 30, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request area/value-sets Value set families and wrapper arities package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/core Affects CodoMetis.ValueRanges labels Nov 30, 2026
@CaffeinatedCoder

Copy link
Copy Markdown
Owner Author

Design approved (maintainer, 2026-11-30) as proposed; TypeKit emitting the interface is a separate TypeKit issue.

CaffeinatedCoder and others added 3 commits November 30, 2026 18:40
…redValueRebuild (#488)

A wrapper element that implements IStoredValueRebuild<TSelf, TPrimitive> over the
primitive its family wraps is rebuilt through FromStored wherever the EF Core
package rebuilds a stored value: the read of an array column, the write's
round-trip check (#53) and a bound element. All three go through the same
FromPrimitive, so whatever loads also saves and binds. The round-trip check stays,
rebuilt through FromStored. Input keeps Parse: the literal, Parse/TryParse, JSON,
and a set inside a JSON document (YearMonthSet<T>'s store text is parsed strictly).

YearMonthSet<T> stores a date and its element wraps a YearMonth, so it registers
through BridgedVia, which hands the element the month.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t through FromStored (#488)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CaffeinatedCoder CaffeinatedCoder added the package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime label Nov 30, 2026
@CaffeinatedCoder CaffeinatedCoder changed the title design: rebuild a stored wrapper element without its Parse (#488) feat: rebuild a stored wrapper element without its Parse (IStoredValueRebuild, #488) Nov 30, 2026
@CaffeinatedCoder
CaffeinatedCoder marked this pull request as ready for review November 30, 2026 17:50
…ugh Parse (#488)

The live run showed that ToString of a loaded set holding an old element throws:
the core's FormatValue round-trips every element through Parse. The docs say so;
whether output should use the rebuild too is the maintainer's call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CaffeinatedCoder

Copy link
Copy Markdown
Owner Author

Maintainer decision recorded on #488: output (ToString/JSON) stays strict, as implemented and documented here.

@CaffeinatedCoder
CaffeinatedCoder merged commit d9d3277 into main Nov 30, 2026
17 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the design/488-unvalidated-rebuild branch November 30, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/value-sets Value set families and wrapper arities enhancement New feature or request package/core Affects CodoMetis.ValueRanges package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime

Projects

None yet

1 participant