Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "1.4.0",
"version": "1.4.1",
"commands": [
"csharpier"
],
Expand Down
7 changes: 1 addition & 6 deletions .config/lefthook.yml
Original file line number Diff line number Diff line change
@@ -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}
14 changes: 13 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -105,4 +117,4 @@ Makefile text eol=lf
# ---------------------------------------------------------------------------
.gitattributes export-ignore
.gitignore export-ignore
.github/ export-ignore
.github/ export-ignore
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,42 @@ Released versions correspond to `v<version>` 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<T>` member through
`ValueObjectEquality` instead of `EqualityComparer<T>.Default` and `Comparer<T>.Default`. Two instances built
from equal contents are now equal and hash equally, so `HashSet<T>`, `Dictionary<TKey, TValue>`, `Assert` and
record-style comparison behave as a value object should. Ordered sequences compare order-sensitively; an
`ISet<T>`/`IReadOnlySet<T>` compares without regard to order, as does an
`IDictionary<TKey, TValue>`/`IReadOnlyDictionary<TKey, TValue>`. 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;
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>`, `ISpanFormattable`, `IUtf8SpanFormattable`, `IParsable<T>`, `ISpanParsable<T>`, and `IUtf8SpanParsable<T>` — mirrored per type
- JSON converters (scalar value objects serialize as their underlying value)
- Contextual creation via `IContextualValueObject<,>` + `ValueObjectContext<T>`
Expand Down
96 changes: 96 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 10 additions & 4 deletions commitlint.config.mts
Original file line number Diff line number Diff line change
@@ -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']],
Expand All @@ -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'],
],
},
};
};
Loading
Loading