@shirudo/ddd-kit 0.9.6 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ const email = createEmail("user@example.com");
|
|
|
58
58
|
|
|
59
59
|
### Value Objects
|
|
60
60
|
|
|
61
|
-
Value Objects are immutable objects that are defined by their attributes rather than identity. They ensure data integrity by preventing modification after creation. Use the `vo()` helper function to create deeply frozen value objects that cannot be mutated, even nested objects and arrays. The library provides `voEquals()` for value-based equality comparison, `voWithValidation()` for creating validated value objects (returns Result), and `voWithValidationUnsafe()` for the exception-throwing variant.
|
|
61
|
+
Value Objects are immutable objects that are defined by their attributes rather than identity. They ensure data integrity by preventing modification after creation. Use the `vo()` helper function to create deeply frozen value objects that cannot be mutated, even nested objects and arrays. The library provides `voEquals()` for value-based equality comparison, `voEqualsExcept()` for comparing while ignoring specified keys (useful for metadata), `voWithValidation()` for creating validated value objects (returns Result), and `voWithValidationUnsafe()` for the exception-throwing variant.
|
|
62
62
|
|
|
63
63
|
### Entities
|
|
64
64
|
|
|
@@ -125,7 +125,7 @@ The `Result<T, E>` type provides functional error handling without exceptions. I
|
|
|
125
125
|
### Creating a Value Object
|
|
126
126
|
|
|
127
127
|
```typescript
|
|
128
|
-
import { vo, voEquals, voWithValidation, type ValueObject } from "@shirudo/ddd-kit";
|
|
128
|
+
import { vo, voEquals, voEqualsExcept, voWithValidation, type ValueObject } from "@shirudo/ddd-kit";
|
|
129
129
|
|
|
130
130
|
// Simple value object
|
|
131
131
|
type Money = ValueObject<{
|
|
@@ -169,6 +169,22 @@ const address = vo({
|
|
|
169
169
|
const money1 = vo({ amount: 100, currency: "USD" });
|
|
170
170
|
const money2 = vo({ amount: 100, currency: "USD" });
|
|
171
171
|
voEquals(money1, money2); // true (value equality, not reference)
|
|
172
|
+
|
|
173
|
+
// Equality comparison ignoring metadata
|
|
174
|
+
const address1 = vo({
|
|
175
|
+
street: "Main St",
|
|
176
|
+
city: "Berlin",
|
|
177
|
+
metadata: { updatedAt: "2024-01-02" }
|
|
178
|
+
});
|
|
179
|
+
const address2 = vo({
|
|
180
|
+
street: "Main St",
|
|
181
|
+
city: "Berlin",
|
|
182
|
+
metadata: { updatedAt: "2024-01-03" }
|
|
183
|
+
});
|
|
184
|
+
voEquals(address1, address2); // false (different metadata)
|
|
185
|
+
voEqualsExcept(address1, address2, {
|
|
186
|
+
ignoreKeyPredicate: (key, path) => path.includes("metadata")
|
|
187
|
+
}); // true (metadata ignored)
|
|
172
188
|
```
|
|
173
189
|
|
|
174
190
|
### Creating an Aggregate WITHOUT Event Sourcing
|
|
@@ -978,7 +994,7 @@ match(result4,
|
|
|
978
994
|
This package is written in TypeScript and provides full type definitions. All types and functions are exported from the main entry point. You can explore the available APIs through your IDE's autocomplete or by examining the type definitions in `node_modules/@shirudo/ddd-kit/dist/index.d.ts`.
|
|
979
995
|
|
|
980
996
|
Key exports include:
|
|
981
|
-
- `vo()`, `voEquals()`, `voWithValidation()`, `voWithValidationUnsafe()` - Value Object utilities
|
|
997
|
+
- `vo()`, `voEquals()`, `voEqualsExcept()`, `voWithValidation()`, `voWithValidationUnsafe()` - Value Object utilities
|
|
982
998
|
- `AggregateRoot<TId>` - Marker interface for Aggregate Root Entities
|
|
983
999
|
- `AggregateBase<TState, TId>` - Base class for creating Aggregate Root Entities without Event Sourcing (implements `AggregateRoot<TId>`)
|
|
984
1000
|
- `AggregateEventSourced<TState, TEvent, TId>` - Base class for Event-Sourced Aggregate Root Entities (extends `AggregateBase`, implements `AggregateRoot<TId>`)
|