feat(store)!: make json feature additive — repository() returns NeedsCodec unconditionally (#211)#298
Merged
Merged
Conversation
…Codec unconditionally (#211) Under Cargo feature unification, a transitive dep enabling `json` must not change any public signature for crates that don't. Two builder methods violated this by returning different types per `#[cfg]`: - `Store::repository()` returned `RepositoryBuilder<S, JsonCodec, A>` with `json`, `RepositoryBuilder<S, NeedsCodec, A>` without. - `RepositoryBuilder::snapshot_store()` took a byte-level store and auto-wrapped `JsonCodec` with `snapshot-json`, but a pre-composed typed store without it. Make both additive: - `repository()` is now unconditional and always returns `NeedsCodec`. Enabling `json` adds a `.json()` builder convenience (sugar for `.codec(JsonCodec::default())`) instead of flipping the return type. `NeedsCodec::new()` loses its `#[cfg(not(json))]` gate. - `snapshot_store()` is now the always-available typed-store form; the byte-level auto-JSON-wrap moves to a new `snapshot-json`-gated `snapshot_store_json()`. Migrate call sites that relied on the hidden JSON default (fjall example, serde/snapshot integration + builder tests) to the explicit `.json()` / `snapshot_store_json()` surface. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Closes #211. Makes the
json(andsnapshot-json) feature purely additive so that Cargo feature unification can never flip a public signature out from under a crate that didn't ask for it.Two builder methods previously returned different public types depending on
#[cfg]:Store::repository()→RepositoryBuilder<S, JsonCodec, A>withjson,RepositoryBuilder<S, NeedsCodec, A>without.RepositoryBuilder::snapshot_store()→ byte-level store + auto-JsonCodecwrap withsnapshot-json, pre-composed typed store without.Under feature unification, a transitive dep enabling
jsonwould silently change these signatures for everyone — code written againstNeedsCodec/ a typed snapshot store would fail to compile on certain dependency graphs. Latent breakage, exactly the kind the 1.0 freeze audit (cross-cutting I4) flags.Changes
repository()is now unconditional and always returnsRepositoryBuilder<S, NeedsCodec, A>.NeedsCodec::new()drops its#[cfg(not(json))]gate..json()builder method (#[cfg(json)]) — sugar for.codec(JsonCodec::default()). Enablingjsononly adds this method.snapshot_store()split: always-available typed-store form (undersnapshot), and a new#[cfg(snapshot-json)] snapshot_store_json()for the byte-level auto-JSON-wrap convenience.fjall-end-to-endexample (7),serde_codec_tests(1),snapshot_integration_tests(16),snapshot_tests(3).Before → after
The two
jsons in the snapshot form are two distinct codecs — one for the event stream, one for the aggregate-state snapshot; both were previously silent defaults.Verification
cargo build -p nexus-store(default features, json off) —repository()compiles asNeedsCodeccargo test -p nexus-store --no-run(json on via dev-dep) —.json()/snapshot_store_json()exercisedcargo build -p nexus-example-fjall-end-to-endnix flake check(clippy, fmt, doc, deny, audit, hakari, nextest) greenBoth feature states are covered by the existing CI matrix (empty default features = json off; test dev-dep pulls
snapshot-json= json on), so the additivity property is verified without a bespoke test.Breaking change
Marked
feat(store)!. Callers relying on the implicit JSON default must add.json();snapshot-jsonusers pass byte-level stores tosnapshot_store_json()instead ofsnapshot_store(). Pre-1.0 experimental API.🤖 Generated with Claude Code