Skip to content

v3.0.0

Latest

Choose a tag to compare

@yuriizee yuriizee released this 27 Nov 15:45
b32f022

3.0 changes how input is validated and coerced. Each change makes the library reject input that 2.x accepted silently or turned into something else. No public API is removed. Most applications need no code changes, only a check of the classes each section of UPGRADE-3.0.md names. The migrate-from-v2-to-v3 skill walks a codebase through it with Claude Code.

Changed (breaking)

  • Nested #[Rules] apply without #[InferRules] (#22). The rules of a nested data class, and of a #[DataCollection] item class, apply when the parent is validated. Rules for nullable, defaulted or Optional nested values apply only when the value is present.
  • Pipes run before validation (#23). fromValidated(), validate() and fromValidatedResult() validate the piped values and hydrate from them without running the pipes again. A pipe that throws becomes a validation error.
  • Scalar properties are coerced without loss (#24). An int, float, string or bool property without a cast takes "3" and 3.0 into int, and "false" into bool as false. Lossy input such as "1.9" into int throws DataHydrationException naming the field. Union types are checked in strict mode and are not converted.
  • Invalid enum values on nullable properties throw (#25) instead of becoming null. EnumCast keeps the old behaviour.
  • Cast failures are DataHydrationException (#26). The exception names the field and keeps the original as getPrevious(). Built-in casts check the input type before using it.
  • FloatCast rejects INF and NAN by default (#27). Pass finite: false to accept them.
  • Weak legacy EncryptedCast keys are rejected (#28) when they are the only key. Next to keyring: they are still accepted for reading and raise a deprecation notice.

The metadata cache format is sdo-cache-5; caches written by 2.x are rebuilt on first use.

Performance

Local benchmarks against 2.9.0, best of 7 rounds, ops/s. Hydration (flat, nested, collection) and serialization are within ±2%. The casts scenario is about 5% slower (cold 985k → 938k, warm 984k → 933k), the cost of the type checks the casts now do before using their input.

Documentation

The 3.x docs are at the site root, and the 2.x docs moved to /v2/. New page: Upgrading from 2.x.

2.x keeps receiving fixes on the v2 branch.