diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index ec846e1..f614930 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "csharpier": { - "version": "1.4.0", + "version": "1.4.1", "commands": [ "csharpier" ], diff --git a/.config/lefthook.yml b/.config/lefthook.yml index 97949c3..1a4201c 100644 --- a/.config/lefthook.yml +++ b/.config/lefthook.yml @@ -1,9 +1,4 @@ -pre-commit: - jobs: - - name: lint staged - run: just lint-check - commit-msg: jobs: - name: conventional commits - run: bun x commitlint --edit {1} + run: bun x --bun commitlint --edit {1} diff --git a/.gitattributes b/.gitattributes index ee62874..e2f6fb7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -49,6 +49,10 @@ *.jsx text *.ts text *.tsx text +*.mjs text +*.mts text +*.cjs text +*.cts text *.html text diff=html *.css text *.scss text @@ -68,8 +72,16 @@ Dockerfile text eol=lf *.dockerfile text eol=lf justfile text eol=lf +Justfile text eol=lf +*.just text eol=lf Makefile text eol=lf +# Lockfiles -- text (bun.lock is JSONC) but generated, so collapse them in diffs/PRs. +bun.lock text eol=lf -diff linguist-generated +package-lock.json text eol=lf -diff linguist-generated +pnpm-lock.yaml text eol=lf -diff linguist-generated +yarn.lock text eol=lf -diff linguist-generated + # Patches carry their own endings -- never touch them. *.patch -text @@ -105,4 +117,4 @@ Makefile text eol=lf # --------------------------------------------------------------------------- .gitattributes export-ignore .gitignore export-ignore -.github/ export-ignore \ No newline at end of file +.github/ export-ignore diff --git a/AGENTS.md b/AGENTS.md index 738a579..c5b1000 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,7 +18,7 @@ a diagnostic analyzer, a code fix, tests, samples, and documentation for scalar | Path | Purpose | | --- | --- | | `src/ValueObjects.slnx` | Canonical solution for restore, build, test, and pack | -| `src/src/ValueObjects` | Runtime contracts (`[Scalar]`, `[ValueObject]`, `IValueObject`, `ScalarJsonConverterFactory`) | +| `src/src/ValueObjects` | Runtime contracts (`[Scalar]`, `[ValueObject]`, `IValueObject`, `ScalarJsonConverterFactory`, `ValueObjectEquality`) | | `src/src/SourceGenerator` | Roslyn incremental generator and analyzer metadata | | `src/src/SourceGenerator.Refactorings` | Code fixes (add `partial` modifier) | | `src/tests` | Unit and source-generator tests, plus the multi-framework Entity Framework Core compatibility project | diff --git a/CHANGELOG.md b/CHANGELOG.md index a592594..7263a11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,42 @@ Released versions correspond to `v` GitHub releases. `package.json` is newest heading below is the version in development. Earlier releases are listed under [releases](https://github.com/purview-dev/value-objects/releases). +## 2.0.1 + +### Fixed + +- **A complex value object compares a collection member by its contents, not by its reference.** The generated + `Equals`, `==`, `!=`, `GetHashCode` and `CompareTo` now route an array or `IEnumerable` member through + `ValueObjectEquality` instead of `EqualityComparer.Default` and `Comparer.Default`. Two instances built + from equal contents are now equal and hash equally, so `HashSet`, `Dictionary`, `Assert` and + record-style comparison behave as a value object should. Ordered sequences compare order-sensitively; an + `ISet`/`IReadOnlySet` compares without regard to order, as does an + `IDictionary`/`IReadOnlyDictionary`. A `null` collection equals `null` but not an + empty one, a collection of collections recurses, and a dictionary whose value is a collection compares that value + structurally. +- **A `record` complex value object now gets the generated `Equals(TSelf)`.** The C# compiler's synthesized record + `Equals` compared collection members by reference and could not be fixed from outside; the generated member + suppresses it (and is `virtual` for a non-sealed record class). A record and a non-record now agree. +- **A derived record's base members are part of its identity and its serialized shape.** The generated equality + calls `base.Equals` and the hash includes `base.GetHashCode()`, instead of silently dropping the base record's + state. The generated `Create`, `Hydrate`, hooks, constructor and JSON converter now include the inherited public + record members (base first), so a derived record round-trips through JSON and reconstructs its base state. +- **`CompareTo` no longer throws `ArgumentException` for a collection member.** Collections have a defined total + order: `null` first, then `Count`, then the elements (ordered sequences) or an order-insensitive content hash + (sets and dictionaries). +- **A complex value object with a single value-type member no longer fails to compile.** The generated + parameterless constructor emitted a bare `default` argument, which was ambiguous between the record's copy + constructor and the member constructor (`CS0121`); it now spells the type. + +This is a behaviour change: instances that compared unequal now compare equal, and their hash codes change. + +### Added + +- **C# 15 constructs are supported where they make sense.** A concrete case of a `closed` hierarchy can be a + `[ValueObject]` (its equality delegates to the base), and a `union` can be a value-object member and keeps its + own generated equality. Marking a `closed`/abstract type (`VO1032`) or a union declaration (`VO1033`) as a value + object is now a clear error rather than a compiler error in generated code. + ## 2.0.0 A major release for the .NET 11 GA. It drops the two out-of-support target frameworks and modernises the build; diff --git a/README.md b/README.md index 885c43b..4895882 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ incremental source generator produces: - `Create` / `Hydrate` / `TryCreate` factories with `OnNormalize` normalization and `OnValidate` validation - `Empty` instances, `HasValue` for null-capable scalars, equality, comparison, `CompareTo`, `ToString` (including the underlying value's `IFormattable` and format overloads), implicit conversions (with explicit extraction for nullable scalars) +- Value semantics for collection members: arrays and sequences compare in order, sets and dictionaries compare without regard to order, and a collection of collections recurses - The underlying value's standard interfaces — `IEquatable`, `ISpanFormattable`, `IUtf8SpanFormattable`, `IParsable`, `ISpanParsable`, and `IUtf8SpanParsable` — mirrored per type - JSON converters (scalar value objects serialize as their underlying value) - Contextual creation via `IContextualValueObject<,>` + `ValueObjectContext` diff --git a/bun.lock b/bun.lock new file mode 100644 index 0000000..16fc145 --- /dev/null +++ b/bun.lock @@ -0,0 +1,96 @@ +{ + "lockfileVersion": 2, + "configVersion": 1, + "workspaces": { + "": { + "name": "value-objects", + "devDependencies": { + "oxfmt": "^0.79.0", + "oxlint": "^1.94.0", + }, + }, + }, + "packages": { + "@oxfmt/binding-android-arm-eabi": ["@oxfmt/binding-android-arm-eabi@0.79.0", "", { "os": "android", "cpu": "arm" }, "sha512-xOCQ/rvokUXs8SxOQY5Wy2ukPaZJZ0PmdJovN0ryB1c8DVEtbcvliLdYtINUYh8QOTpmBOctIisSJk9tvh+J6w=="], + + "@oxfmt/binding-android-arm64": ["@oxfmt/binding-android-arm64@0.79.0", "", { "os": "android", "cpu": "arm64" }, "sha512-WMLDvCjjchUYtI6zXKOdzTDGm72BaYZiz1/VhB1rrxdakUZRlJh1aMr3CT6ui51uHcWVBycULIXSZHpw6u2pTQ=="], + + "@oxfmt/binding-darwin-arm64": ["@oxfmt/binding-darwin-arm64@0.79.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-+LzSN7w7tULz96ntS1Uqe5oI00XZ0o/m/t3+eSfiQp3aTPnj2eGUafqEWryMLk84j7x9NiF+GEP2YT4/BfClgA=="], + + "@oxfmt/binding-darwin-x64": ["@oxfmt/binding-darwin-x64@0.79.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-KFiMRhKeiiooaS1dKc4r8AZgOrfOhwVe1yf/aRef+8BajJwtVjMtlsQl/BNRxtkFbq13GjEo/4Q+9YhFGU4o6g=="], + + "@oxfmt/binding-freebsd-x64": ["@oxfmt/binding-freebsd-x64@0.79.0", "", { "os": "freebsd", "cpu": "x64" }, "sha512-lHVIp0g8ZOFKiqVscvttp+3HJkkRH6XkGgfAA0lVexIlE1mMFVp4V7RBdxz/P9p7T8pSNsYdapFWvdT21Mib9w=="], + + "@oxfmt/binding-linux-arm-gnueabihf": ["@oxfmt/binding-linux-arm-gnueabihf@0.79.0", "", { "os": "linux", "cpu": "arm" }, "sha512-Pt35GoxiMUfnr+23cuzk07XQVvISDFxxPcp/aFVB87+RQvJoQaBo/XN7Re9XxgElvbELdyxTLnV9XM2aTfJeUA=="], + + "@oxfmt/binding-linux-arm-musleabihf": ["@oxfmt/binding-linux-arm-musleabihf@0.79.0", "", { "os": "linux", "cpu": "arm" }, "sha512-zPi9Dni58VKp3r1QUcFvnbJNfBr49qyecq0vlM4SaX/MSjmguq77VngirghDua5tyhIDfqdUMTCK2KRlnZFp/g=="], + + "@oxfmt/binding-linux-arm64-gnu": ["@oxfmt/binding-linux-arm64-gnu@0.79.0", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-XhRehATEWjwX7VVEgDUD+7pfHYncQIJaEU0qsHvEKtu9XX0QYzcKvXhU9+URfiGX9WRh3wy2Ow+YCc3EeHtImg=="], + + "@oxfmt/binding-linux-arm64-musl": ["@oxfmt/binding-linux-arm64-musl@0.79.0", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-gbVjFZYug0MEyqvuTAzXGNxFJmBqBO32o1Fud1lG8bGs6oVz48ZtNQyEcAzqrOwaaG+Sxtv4gVzcsfht9aqmkg=="], + + "@oxfmt/binding-linux-ppc64-gnu": ["@oxfmt/binding-linux-ppc64-gnu@0.79.0", "", { "os": "linux", "cpu": "ppc64", "libc": "glibc" }, "sha512-0N0sD3vnllyuiNh1r6zKvNXWE/CakcPKJAespg7XE2+sfvxpz5Q1iFah8sF5aedsOmVvbZaOPZcSHVmMosT1fA=="], + + "@oxfmt/binding-linux-riscv64-gnu": ["@oxfmt/binding-linux-riscv64-gnu@0.79.0", "", { "os": "linux", "cpu": "none", "libc": "glibc" }, "sha512-YtjqUHolcX6cv0ZMZuKQCM4H0ae/okcowy0wGcPHJk4O+8zjy3TvNhzDQ1/KGCkMJO8Fwulm1JcPJsraVJ3p+w=="], + + "@oxfmt/binding-linux-riscv64-musl": ["@oxfmt/binding-linux-riscv64-musl@0.79.0", "", { "os": "linux", "cpu": "none", "libc": "musl" }, "sha512-H2gb9bEBr5tcdP5FU8JYTfgOavXDorWcAAlwci/zEKF2jzgh/oEr/SAw6aHB9n3FLEvnKvOh0A1fjku+vgYoUA=="], + + "@oxfmt/binding-linux-s390x-gnu": ["@oxfmt/binding-linux-s390x-gnu@0.79.0", "", { "os": "linux", "cpu": "s390x", "libc": "glibc" }, "sha512-aZUbyWW5dSOxT/u6suWc4S9GVDt7YPPNMKQon+z79M8dpXmosadcFHAb7jBhpU7Hdsd2GN6/y3nd0JFTsGddZw=="], + + "@oxfmt/binding-linux-x64-gnu": ["@oxfmt/binding-linux-x64-gnu@0.79.0", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-5pW/ZHYfjjQ71gQR+EKzDz8ZzWIDHlTUtWtxVFNgZbKxVZnRxiSXVrllbjpJtx1q8VtSPZ+Lyg9BLny3yw+PTA=="], + + "@oxfmt/binding-linux-x64-musl": ["@oxfmt/binding-linux-x64-musl@0.79.0", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-3IVUerTDB7Dvd90c1EurAzlVnlE9Azl7Wn8e33qX3wL/IqnslF+P7HvwkD+VeMbHxRtuw0EEBGSArZFXpUAZrQ=="], + + "@oxfmt/binding-openharmony-arm64": ["@oxfmt/binding-openharmony-arm64@0.79.0", "", { "os": "none", "cpu": "arm64" }, "sha512-C5QDgJBtu9+/2BQScoP7ynv54PLOqfoSqhRWwI0D0RPOwYD4tYj0TUdJbXMO1fNegL/5zJiSOxkq6II2xvttWg=="], + + "@oxfmt/binding-win32-arm64-msvc": ["@oxfmt/binding-win32-arm64-msvc@0.79.0", "", { "os": "win32", "cpu": "arm64" }, "sha512-zlW1m8M49vNGgqQF/ze80KW8pZMicnW2XDZGBHuYtXTRYn4ewvgpqN9wwoqb6uLZZfb1R1zaQWKEB8cs7KYjwA=="], + + "@oxfmt/binding-win32-ia32-msvc": ["@oxfmt/binding-win32-ia32-msvc@0.79.0", "", { "os": "win32", "cpu": "ia32" }, "sha512-wbb7hFv2wK3SCTfu8dl1ydNsXM5dmH+PJMU3sojCkfKcG29VDpITL5/AtouCzXjkOc90QRkcAZcg36gP0KqoHA=="], + + "@oxfmt/binding-win32-x64-msvc": ["@oxfmt/binding-win32-x64-msvc@0.79.0", "", { "os": "win32", "cpu": "x64" }, "sha512-JLaeaQ+4LkQiVXY06JIV1dBFEDJzssvDieK/3Poi6CsY+c4UxghZVrrsfcKGJ5R/0F2Sw3C5Lf5Hu0sM5qJfPw=="], + + "@oxlint/binding-android-arm-eabi": ["@oxlint/binding-android-arm-eabi@1.94.0", "", { "os": "android", "cpu": "arm" }, "sha512-730FKSBsKg/NawYnpI3gXRroXptOVqY32iYBPLUZaSx0vgYzOeiNtwojZL4gJdzo9wDvHUlstShmGRHrWcbRYg=="], + + "@oxlint/binding-android-arm64": ["@oxlint/binding-android-arm64@1.94.0", "", { "os": "android", "cpu": "arm64" }, "sha512-8v8TICIiZpXLot1HSq5+vsG9NEKQ5czQBYlUqJR75OVfFDr3cGOmRU/CtHDWnS4tm8nW+Z4Y357qGToSfYqFvA=="], + + "@oxlint/binding-darwin-arm64": ["@oxlint/binding-darwin-arm64@1.94.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-NePcRMO/ltt1Pnytohl6pl0bd/QyRX8HbpptuDz9LK7FTsFD4lKxDMBt7di9k6IFLO0J05jO2nm7wGqIh6dRHA=="], + + "@oxlint/binding-darwin-x64": ["@oxlint/binding-darwin-x64@1.94.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-QV+m+OaEgLmYyillvP1wKXhMm6tDZEWx3vG7Wjmx9ybg15+6YMfqzvp6e+uPukC6zNywuule0vMn0fZgihZzZA=="], + + "@oxlint/binding-freebsd-x64": ["@oxlint/binding-freebsd-x64@1.94.0", "", { "os": "freebsd", "cpu": "x64" }, "sha512-KVZjca581nrV6P71kZ9M1otBib9LH0IMn9rr4mrnbRp18V0HiZhBHbU26gji/Ieq2G34qMacnMc3zrmKmvWqWA=="], + + "@oxlint/binding-linux-arm-gnueabihf": ["@oxlint/binding-linux-arm-gnueabihf@1.94.0", "", { "os": "linux", "cpu": "arm" }, "sha512-AMQtgQJk8DgdIV+qaQ5sFoHAko4iKa8zo+gYqELy2grtU8hXWB08DAGB3u90aQL1YSxbd3zqHjgcODBHDFyzBQ=="], + + "@oxlint/binding-linux-arm-musleabihf": ["@oxlint/binding-linux-arm-musleabihf@1.94.0", "", { "os": "linux", "cpu": "arm" }, "sha512-ZLzoGVGAmQkp9leeB5rNxAXLcvlmkmd/GY71LKd5uikk+28NEApY3S2FB3pq6MkfOCFFnFg6QgD9lJIjd07D0Q=="], + + "@oxlint/binding-linux-arm64-gnu": ["@oxlint/binding-linux-arm64-gnu@1.94.0", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-N1dW6o7cY90hLVkDsvz8nWIFOwbO+n272pvW7uLYB7u47HagJVnLChfK6QA9dWFdiPudud9zfksVUOciHc5PNA=="], + + "@oxlint/binding-linux-arm64-musl": ["@oxlint/binding-linux-arm64-musl@1.94.0", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-7tCF4OV/bGDQ2xxgb+sDI97SpmmDrUII4JxTG553voJVA9cnkbXSGSXzo78Ax73BuhEOPoQc2Qi6VrfT0cDG2A=="], + + "@oxlint/binding-linux-ppc64-gnu": ["@oxlint/binding-linux-ppc64-gnu@1.94.0", "", { "os": "linux", "cpu": "ppc64", "libc": "glibc" }, "sha512-B5vUHE4wNisVEuaYxwFUn6tY+vw7A+9APxxqGKI+UmP3yKLpkhnt0qsaCrzjpX55F8rCRHBaTvIDdYo32NE36g=="], + + "@oxlint/binding-linux-riscv64-gnu": ["@oxlint/binding-linux-riscv64-gnu@1.94.0", "", { "os": "linux", "cpu": "none", "libc": "glibc" }, "sha512-/U0b15+c4hTodo8YhEqDlQ6OjnGKvc8igjM/mh23ukqqCUBKiBCaxqUV8bcaofK9uZ+f8wCygkyXLS6LN25YSA=="], + + "@oxlint/binding-linux-riscv64-musl": ["@oxlint/binding-linux-riscv64-musl@1.94.0", "", { "os": "linux", "cpu": "none", "libc": "musl" }, "sha512-ba94Vwl0qOnwXIXNDR33AEbLXuX++ckM74t+9Te7CiPSPAHivhOYyeEkUAicrvOEei1pxXkWggLbFeBFFBTuHA=="], + + "@oxlint/binding-linux-s390x-gnu": ["@oxlint/binding-linux-s390x-gnu@1.94.0", "", { "os": "linux", "cpu": "s390x", "libc": "glibc" }, "sha512-GVwwwms3O8pdgbCiPavwq2vltyB4661GkDz6kJduZ0E5nsSJUDJ0svaP+ePYpuDVYi4+K1qhCKnWa/Ec8I4LUA=="], + + "@oxlint/binding-linux-x64-gnu": ["@oxlint/binding-linux-x64-gnu@1.94.0", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-iUfCFJN8ZIresSnpTfiIkhF3s8X+XA4I9KJ249QwR2QYTMwh0+pla1pj1xaFi+HtR9McjM4Jaemf70HzX7ilOQ=="], + + "@oxlint/binding-linux-x64-musl": ["@oxlint/binding-linux-x64-musl@1.94.0", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-RqWVeWpDACS4Oh0m21OBmy+CQ50CbbhuHFmNNPVS2P/4R3d188MjEuEuV7So82/tAM8UAT+UuMDtRDESd9NJ7g=="], + + "@oxlint/binding-openharmony-arm64": ["@oxlint/binding-openharmony-arm64@1.94.0", "", { "os": "none", "cpu": "arm64" }, "sha512-K/2DHOUoypwYVqzxJMRPdMuBKjAetZEAsGPP7rHimd+2+5J1TxM+17pG8kw+ayH4+rqBXiPd+H9wgPcU+fF77A=="], + + "@oxlint/binding-win32-arm64-msvc": ["@oxlint/binding-win32-arm64-msvc@1.94.0", "", { "os": "win32", "cpu": "arm64" }, "sha512-hYOCaOJiB4ZCGswBWKl3JQrhqu6mnC5DCUw/1UMNzRXgsHIJ0V226J43LAVICVIDGlhFUZTYShFW+wHWpt6qCQ=="], + + "@oxlint/binding-win32-ia32-msvc": ["@oxlint/binding-win32-ia32-msvc@1.94.0", "", { "os": "win32", "cpu": "ia32" }, "sha512-1l1FDlzbPmAeDoZ8UGspOE2dOmz1ZL6SlDsvOmRCmWSQjCdTy5LzUepS8mO/SGpAoz4D6WAt/yNZAUyHqbkmkQ=="], + + "@oxlint/binding-win32-x64-msvc": ["@oxlint/binding-win32-x64-msvc@1.94.0", "", { "os": "win32", "cpu": "x64" }, "sha512-I3eZdd4bemIJQDNv9XDV/FEofDxIoN32tzCv98wIgLdW05EqxZb5hF4AwPrRzHD/dQhl0n7KgPy5AQPfM0HWrA=="], + + "oxfmt": ["oxfmt@0.79.0", "", { "dependencies": { "tinypool": "2.2.0" }, "optionalDependencies": { "@oxfmt/binding-android-arm-eabi": "0.79.0", "@oxfmt/binding-android-arm64": "0.79.0", "@oxfmt/binding-darwin-arm64": "0.79.0", "@oxfmt/binding-darwin-x64": "0.79.0", "@oxfmt/binding-freebsd-x64": "0.79.0", "@oxfmt/binding-linux-arm-gnueabihf": "0.79.0", "@oxfmt/binding-linux-arm-musleabihf": "0.79.0", "@oxfmt/binding-linux-arm64-gnu": "0.79.0", "@oxfmt/binding-linux-arm64-musl": "0.79.0", "@oxfmt/binding-linux-ppc64-gnu": "0.79.0", "@oxfmt/binding-linux-riscv64-gnu": "0.79.0", "@oxfmt/binding-linux-riscv64-musl": "0.79.0", "@oxfmt/binding-linux-s390x-gnu": "0.79.0", "@oxfmt/binding-linux-x64-gnu": "0.79.0", "@oxfmt/binding-linux-x64-musl": "0.79.0", "@oxfmt/binding-openharmony-arm64": "0.79.0", "@oxfmt/binding-win32-arm64-msvc": "0.79.0", "@oxfmt/binding-win32-ia32-msvc": "0.79.0", "@oxfmt/binding-win32-x64-msvc": "0.79.0" }, "peerDependencies": { "@astrojs/compiler-rs": "^0.5.0", "svelte": "^5.0.0", "vite-plus": "*" }, "optionalPeers": ["@astrojs/compiler-rs", "svelte", "vite-plus"], "bin": { "oxfmt": "bin/oxfmt" } }, "sha512-92iLHGxAgtYk6jLp/1ZBnEeABveNduHZgMDQj7tyqO9iafuJG3q+YHJq0R5Aa4YT+E6xswMQXdmPZYMwynS8ig=="], + + "oxlint": ["oxlint@1.94.0", "", { "optionalDependencies": { "@oxlint/binding-android-arm-eabi": "1.94.0", "@oxlint/binding-android-arm64": "1.94.0", "@oxlint/binding-darwin-arm64": "1.94.0", "@oxlint/binding-darwin-x64": "1.94.0", "@oxlint/binding-freebsd-x64": "1.94.0", "@oxlint/binding-linux-arm-gnueabihf": "1.94.0", "@oxlint/binding-linux-arm-musleabihf": "1.94.0", "@oxlint/binding-linux-arm64-gnu": "1.94.0", "@oxlint/binding-linux-arm64-musl": "1.94.0", "@oxlint/binding-linux-ppc64-gnu": "1.94.0", "@oxlint/binding-linux-riscv64-gnu": "1.94.0", "@oxlint/binding-linux-riscv64-musl": "1.94.0", "@oxlint/binding-linux-s390x-gnu": "1.94.0", "@oxlint/binding-linux-x64-gnu": "1.94.0", "@oxlint/binding-linux-x64-musl": "1.94.0", "@oxlint/binding-openharmony-arm64": "1.94.0", "@oxlint/binding-win32-arm64-msvc": "1.94.0", "@oxlint/binding-win32-ia32-msvc": "1.94.0", "@oxlint/binding-win32-x64-msvc": "1.94.0" }, "peerDependencies": { "oxlint-tsgolint": ">=7.0.2007", "vite-plus": "*" }, "optionalPeers": ["oxlint-tsgolint", "vite-plus"], "bin": { "oxlint": "bin/oxlint" } }, "sha512-Fnt+3wSKRhtLmvgRfxgRX0excSPCoyiXRol4eWKZLtXxWMQtwQ3KjKQUYXOw5loyinfnZfGzh4RCYf7opfL0vw=="], + + "tinypool": ["tinypool@2.2.0", "", {}, "sha512-jBrmx4lYmaC9k/mgPbylxs7kBUxHtD8256up+HjLaDFfXScKJQyil+SWXSvhAtT7XHo+yTVlpB81PGmHP8oLSQ=="], + } +} diff --git a/bunfig.toml b/bunfig.toml new file mode 100644 index 0000000..cfbd095 --- /dev/null +++ b/bunfig.toml @@ -0,0 +1,25 @@ +# Project-level Bun configuration. +# Mirrors the user-level .bunfig.toml installed by the profile; keys set here win. + +# Disable anonymous crash reporting and analytics. +telemetry = false + +[run] +# Prefer Bun over Node.js when launching scripts and shebang binaries. +bun = true + +# Cross-platform shell execution. +shell = "bun" + +# Don't echo each script command before executing it. +silent = true + +# Terminate descendant processes when the parent exits. +noOrphans = true + +[install] +# Prefer cached package metadata to network staleness checks. +prefer = "offline" + +# Still reach the registry when a package isn't cached. +offline = false diff --git a/commitlint.config.mts b/commitlint.config.mts index 00420ab..29384ce 100644 --- a/commitlint.config.mts +++ b/commitlint.config.mts @@ -1,9 +1,15 @@ +// Conventional Commits, plus `qol` (quality of life) for developer-experience changes: +// tooling, scripts, editor config, DX tweaks that are neither a feature nor a fix. +// Keep the type-enum array inline and comment-free so Show-CommitTypes can parse it. export default { + helpUrl: 'https://www.conventionalcommits.org/en/v1.0.0/', rules: { 'body-leading-blank': [1, 'always'], - 'body-max-line-length': [2, 'always', 100], + // Warn rather than fail: URLs, stack traces and pasted output legitimately run long. + 'body-max-line-length': [1, 'always', 100], 'footer-leading-blank': [1, 'always'], - 'footer-max-line-length': [2, 'always', 100], + // Warn rather than fail: Co-authored-by and issue-link trailers are often long. + 'footer-max-line-length': [1, 'always', 100], 'header-max-length': [2, 'always', 100], 'header-trim': [2, 'always'], 'subject-case': [2, 'never', ['sentence-case', 'start-case', 'pascal-case', 'upper-case']], @@ -14,7 +20,7 @@ export default { 'type-enum': [ 2, 'always', - ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test', 'qol'], + ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'qol', 'refactor', 'revert', 'style', 'test'], ], }, -}; \ No newline at end of file +}; diff --git a/docs/Diagnostics.md b/docs/Diagnostics.md index f25d815..e4cdde6 100644 --- a/docs/Diagnostics.md +++ b/docs/Diagnostics.md @@ -25,6 +25,8 @@ These govern the declaration shape a value object must have for the generator to | `VO1028` | Error | `[Scalar(Nullable = true)]` is combined with a declared `Value` property, so nullability has two sources. | Remove the declared `Value`; convert to the manual `[Scalar]` form; or remove `Nullable = true`. The code fix offers all three. | | `VO1029` | Error | Explicit `Nullable = false` contradicts a declared nullable `Value` property. | Remove the declared `Value`, or use the manual `[Scalar]` form and own the property. | | `VO1030` | Error | The automatic form's declared `Value` has a type that does not match the scalar's underlying type. | Remove the declaration, or use the manual `[Scalar]` form with a matching type. | +| `VO1032` | Error | A `closed` or `abstract` type is marked `[Scalar]`/`[ValueObject]`. A closed type is implicitly abstract, so the generated `Create`/`Hydrate` cannot instantiate it. | Mark a concrete derived type as the value object instead. | +| `VO1033` | Error | A C# 15 `union` declaration is marked `[Scalar]`/`[ValueObject]`. A union already provides its own `value`/`HasValue`/`TryGetValue` and equality members and cannot carry a partial value-object declaration. | Use the union as a member type; mark a record or class as the value object instead. | ## ZodSharp validation rules diff --git a/docs/Getting-Started.md b/docs/Getting-Started.md index 5337c88..0f5a223 100644 --- a/docs/Getting-Started.md +++ b/docs/Getting-Started.md @@ -267,6 +267,20 @@ public readonly partial record struct Money } ``` +A collection member participates in equality and hashing by its **contents**. An array or `IEnumerable` +member compares element by element in order; an `ISet`/`IReadOnlySet` compares without regard to +order, and so does an `IDictionary`/`IReadOnlyDictionary` (including a +collection value). `null` equals `null` but not an empty collection, and a collection of collections +compares recursively. Elements use `EqualityComparer.Default`, so a nested value object keeps its own +generated equality. `CompareTo` orders a collection member by its count and then its contents rather than +throwing. + +A derived record's inherited public members are part of its identity **and** its generated `Create`, +`Hydrate`, hooks, constructor and JSON shape (base members first), so a derived record round-trips with its +base state. A concrete case of a C# 15 `closed` hierarchy can be a `[ValueObject]`; a closed or abstract type +itself cannot (`VO1032`), because it cannot be instantiated. A C# 15 `union` can be a member and keeps its own +generated equality, but a union declaration cannot itself be a value object (`VO1033`). + ## 4. Contextual value objects When validity depends on the owning instance, implement `IContextualValueObject`: diff --git a/docs/Trimming-AOT-and-Blazor.md b/docs/Trimming-AOT-and-Blazor.md index 46ebc42..6ca5b94 100644 --- a/docs/Trimming-AOT-and-Blazor.md +++ b/docs/Trimming-AOT-and-Blazor.md @@ -72,6 +72,10 @@ Inside a generated converter: - anything else - an enum, or a custom underlying type - needs metadata, so add `[JsonSerializable(typeof(T))]` to the context. The `NotSupportedException` thrown otherwise names the type. +Generated collection equality is reflection-free too: `Equals`, `GetHashCode` and `CompareTo` call the generic +`ValueObjectEquality` helpers, which use only `EqualityComparer.Default`, interfaces and enumerators, so an array +or collection member stays trimming- and Native AOT-safe. + ## ZodSharp packages A Native AOT minimal API with `[Scalar]` + `[ZodSchema]` value objects in `Strict` mode, built against ZodSharp diff --git a/docs/Value-Object-Design.md b/docs/Value-Object-Design.md index 6814bfc..4d9837e 100644 --- a/docs/Value-Object-Design.md +++ b/docs/Value-Object-Design.md @@ -121,6 +121,43 @@ The value object always implements `IComparable` and `IComparable` (and a `CompareTo(TValue)`) because the value-object contract requires it. Numeric and arithmetic interfaces, `IConvertible`, and collection interfaces are intentionally not mirrored. +## Equality and hashing + +A complex value object's identity includes its collection members by **contents**. The generated `Equals`, +`==`, `!=` and `GetHashCode` route an array or `IEnumerable` member through `ValueObjectEquality` rather +than `EqualityComparer.Default`, whose collection implementation is reference identity: + +| Member shape | Equality | Hash | +| --- | --- | --- | +| array or other `IEnumerable` | ordered sequence, element by element | order-sensitive | +| `ISet` / `IReadOnlySet` | set contents, order-insensitive | order-insensitive | +| `IDictionary` / `IReadOnlyDictionary` | same keys mapped to equal values, order-insensitive | order-insensitive | + +Elements compare through `EqualityComparer.Default`, so a nested value object keeps its own generated +equality, a collection of collections recurses, and a dictionary whose value is a collection compares that +value structurally. `null` equals `null` but not an empty collection; a nullable collection member never +throws. A custom `ISet`/`IDictionary` comparer is not observed, because using it for +equality while hashing with `EqualityComparer.Default` would let equal values produce different hashes; +a dictionary key that is itself a collection is likewise not recursed. + +This applies to records and non-records alike: the generator declares `Equals(TSelf)` on a record (the +compiler-synthesized record member compares fields by reference), marking it `virtual` on a non-sealed +record class. A derived record's base members are included through `base.Equals` and `base.GetHashCode()`, +and its inherited public record members are included (base first) in the generated `Create`, `Hydrate`, +hooks, constructor and JSON converter — so the serialized shape and the factories agree with identity. +`CompareTo` gives a collection member a defined total order — `null` first, then `Count`, then the elements +(ordered sequences) or an order-insensitive content hash (sets and dictionaries) — so it no longer throws +`ArgumentException` ("At least one object must implement IComparable"). + +### C# 15 constructs + +A concrete case of a `closed` hierarchy can be a `[ValueObject]` (for example a positional record deriving +from a `closed` base); equality delegates to the base as above. A `closed` type is implicitly abstract, so +marking the closed type itself is `VO1032`; mark a concrete derived type instead. A `union` can be a value +object member and takes part in equality through its own generated equality, but a union declaration cannot +itself be a `[ValueObject]` (`VO1033`) — it already provides its own value, equality and `TryGetValue` +members and cannot carry a partial value-object declaration. + ## Contextual value objects `IContextualValueObject` lets a value object validate against the owning instance: diff --git a/package.json b/package.json index 68c2616..87a35f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "value-objects", - "version": "2.0.0", + "version": "2.0.1", "license": "MIT", "author": { "name": "Kieron Lanning", @@ -13,5 +13,9 @@ "repository": { "type": "git", "url": "git+https://github.com/purview-dev/value-objects.git" + }, + "devDependencies": { + "oxfmt": "^0.79.0", + "oxlint": "^1.94.0" } } \ No newline at end of file diff --git a/skills-lock.json b/skills-lock.json index d8f4457..c7f16bd 100644 --- a/skills-lock.json +++ b/skills-lock.json @@ -17,13 +17,13 @@ "source": "purview-dev/build-sdk", "sourceType": "github", "skillPath": "skills/purview-buildsdk-adoption/SKILL.md", - "computedHash": "ed38157d532c45582bc3f768ca6605c4cbc1339fbbb6a45e34a8badee06af06f" + "computedHash": "5380ee60e34197a8af5ba8ec32e13ef84e541d014fe143ca0d815fff30a1b758" }, "purview-buildsdk-configuration": { "source": "purview-dev/build-sdk", "sourceType": "github", "skillPath": "skills/purview-buildsdk-configuration/SKILL.md", - "computedHash": "7f33e4fee919a7e67033763f76f8e99e585ef128c937c6df58ebdae823949934" + "computedHash": "6eb2359d0c6acba80c5ea548c28e0e4df52ea5157435ba4372fde7e42981a577" }, "purview-buildsdk-docs-sync": { "source": "purview-dev/build-sdk", @@ -47,7 +47,7 @@ "source": "purview-dev/build-sdk", "sourceType": "github", "skillPath": "skills/purview-buildsdk-project-detection/SKILL.md", - "computedHash": "8b39fdeba80cad1cfd19d394209affc95d2dbc3e6a2e0358d14dc54ba6892ed7" + "computedHash": "219f323ebd77536fa3424957798b88b89ae119cecef6d801d3101ab7981d6828" }, "purview-buildsdk-project-layout": { "source": "purview-dev/build-sdk", @@ -59,7 +59,7 @@ "source": "purview-dev/build-sdk", "sourceType": "github", "skillPath": "skills/purview-buildsdk-repository-review/SKILL.md", - "computedHash": "08a5b7a34511959b72702ae8107c15ece77a27a7ef58c0b6b08e25a206f76c25" + "computedHash": "e09488299f61af4292be2a64c90622a826fd9a7df2640a73ddcc953216c07836" }, "purview-buildsdk-settings-docs-sync": { "source": "purview-dev/build-sdk", @@ -71,7 +71,7 @@ "source": "purview-dev/build-sdk", "sourceType": "github", "skillPath": "skills/purview-buildsdk-skill-installation/SKILL.md", - "computedHash": "5a8cffd36dc696ec86276ddd089e9f859d4571b7606b46c0b82a5c52d5935e16" + "computedHash": "e00f5a1b4c1ab728338c9ccbfaf59dd0c2d228be4a30149d16699b2dce86fe8e" }, "purview-buildsdk-skill-tests": { "source": "purview-dev/build-sdk", diff --git a/skills/purview-value-objects-diagnostics/SKILL.md b/skills/purview-value-objects-diagnostics/SKILL.md index 7f6b150..ea9a121 100644 --- a/skills/purview-value-objects-diagnostics/SKILL.md +++ b/skills/purview-value-objects-diagnostics/SKILL.md @@ -35,6 +35,8 @@ failure to the missing member. | `VO1028` | Error | `[Scalar(Nullable = true)]` is combined with a declared `Value`, so nullability has two sources. | Remove the declared property; convert to the manual `[Scalar]` form; or remove `Nullable = true`. The code fix offers all three. | | `VO1029` | Error | Explicit `Nullable = false` contradicts a declared nullable `Value`. | Remove the declared `Value`, or use the manual `[Scalar]` form. | | `VO1030` | Error | The automatic form's declared `Value` type does not match the underlying type. | Remove the declaration, or use the manual `[Scalar]` form with a matching type. | +| `VO1032` | Error | A `closed` or `abstract` type is marked `[Scalar]`/`[ValueObject]`. A closed type is implicitly abstract, so the generated `Create`/`Hydrate` cannot instantiate it. | Mark a concrete derived type as the value object instead. | +| `VO1033` | Error | A C# 15 `union` declaration is marked `[Scalar]`/`[ValueObject]`. A union already provides its own value/equality members and cannot be a partial value object. | Use the union as a member type and mark a record or class as the value object instead. | ## String normalization rules diff --git a/skills/purview-value-objects/SKILL.md b/skills/purview-value-objects/SKILL.md index a42b1fa..f8390cf 100644 --- a/skills/purview-value-objects/SKILL.md +++ b/skills/purview-value-objects/SKILL.md @@ -140,6 +140,18 @@ Keep members `readonly`/`init`-only — a mutable member is `VO1016` and makes e `struct`, declare `OnValidate` as `readonly` when it does not mutate; the generator mirrors the modifier. +A collection member takes part in identity by its contents: arrays and other sequences compare in order, +`ISet`/`IReadOnlySet` and `IDictionary`/`IReadOnlyDictionary` compare +without regard to order, and a collection of collections or a collection-valued dictionary entry recurses. +`null` equals `null` but not an empty collection, and `CompareTo` orders by count then contents instead of +throwing. Records and non-records behave the same; a derived record includes its base members through +`base.Equals`/`base.GetHashCode()`, and the inherited public record members are part of `Create`/`Hydrate`, +the hooks, the constructor and the JSON shape (base first). + +A concrete case of a C# 15 `closed` hierarchy can be `[ValueObject]`, but the closed type itself is +implicitly abstract (`VO1032`). A `union` can be a member, but a union declaration cannot be a value object +(`VO1033`). + ## Contextual value objects When validity depends on the owning instance's current state — a state machine, a cross-field rule diff --git a/src/Directory.Build.props b/src/Directory.Build.props index b8c8a45..7b2117e 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -9,19 +9,6 @@ were dropped alongside the .NET 11 GA. Roslyn components are excluded by the SDK, which targets them at netstandard2.0. --> Supported - - true - 0