@shirudo/ddd-kit 0.9.8 → 0.10.0

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 CHANGED
@@ -37,9 +37,9 @@ pnpm add @shirudo/ddd-kit
37
37
  Here's a minimal example showing how to create and use a Value Object:
38
38
 
39
39
  ```typescript
40
- import { vo, type ValueObject } from "@shirudo/ddd-kit";
40
+ import { vo, type VO } from "@shirudo/ddd-kit";
41
41
 
42
- type EmailAddress = ValueObject<{
42
+ type EmailAddress = VO<{
43
43
  value: string;
44
44
  }>;
45
45
 
@@ -125,10 +125,10 @@ 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, voEqualsExcept, voWithValidation, type ValueObject } from "@shirudo/ddd-kit";
128
+ import { vo, voEquals, voEqualsExcept, voWithValidation, type VO } from "@shirudo/ddd-kit";
129
129
 
130
- // Simple value object
131
- type Money = ValueObject<{
130
+ // Simple value object (Functional Style)
131
+ type Money = VO<{
132
132
  amount: number;
133
133
  currency: string;
134
134
  }>;
@@ -136,6 +136,22 @@ type Money = ValueObject<{
136
136
  const price = vo({ amount: 99.99, currency: "USD" });
137
137
  // price is deeply immutable - nested objects and arrays are also frozen
138
138
 
139
+ // Class-based Value Object (OOP Style)
140
+ import { ValueObject } from "@shirudo/ddd-kit";
141
+
142
+ class Address extends ValueObject<{ street: string; city: string }> {
143
+ constructor(props: { street: string; city: string }) {
144
+ super(props);
145
+ }
146
+
147
+ get street(): string {
148
+ return this.props.street;
149
+ }
150
+ }
151
+
152
+ const address = new Address({ street: "Main St", city: "New York" });
153
+ // address.props is immutable
154
+
139
155
  // Value object with validation (returns Result)
140
156
  const result = voWithValidation(
141
157
  { amount: 100, currency: "USD" },
@@ -0,0 +1,57 @@
1
+ type Key = string | symbol;
2
+ type PathSegment = string | number | symbol;
3
+ interface DeepOmitOptions {
4
+ /**
5
+ * Keys to ignore everywhere in the object tree.
6
+ * Only applies to object properties, not Map/Set/TypedArray contents.
7
+ */
8
+ readonly ignoreKeys?: readonly Key[];
9
+ /**
10
+ * Fine-grained control: Key + path (without current key).
11
+ * Example path: ["user", "meta", 0, "data"]
12
+ */
13
+ readonly ignoreKeyPredicate?: (key: Key, path: readonly PathSegment[]) => boolean;
14
+ }
15
+ /**
16
+ * Creates a deep copy of `value` with certain keys removed according to the provided rules.
17
+ *
18
+ * This function recursively traverses the object tree and removes keys that match
19
+ * the criteria specified in `options`. Built-in types (Date, Map, Set, TypedArrays, etc.)
20
+ * are treated atomically and not modified.
21
+ *
22
+ * @param value - The value to create a deep copy from
23
+ * @param options - Options specifying which keys to ignore
24
+ * @returns A deep copy of `value` with specified keys removed
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const obj = { a: 1, b: { c: 2, d: 3 } };
29
+ * const result = deepOmit(obj, { ignoreKeys: ['d'] });
30
+ * // result: { a: 1, b: { c: 2 } }
31
+ * ```
32
+ */
33
+ declare function deepOmit<T>(value: T, options: DeepOmitOptions): T;
34
+
35
+ type DeepEqualExceptOptions = DeepOmitOptions;
36
+ /**
37
+ * Performs a deep equality comparison between two values after omitting specified keys.
38
+ *
39
+ * This function first removes the specified keys from both values using `deepOmit`,
40
+ * then performs a deep equality check using `deepEqual`.
41
+ *
42
+ * @param a - The first value to compare
43
+ * @param b - The second value to compare
44
+ * @param options - Options specifying which keys to omit before comparison
45
+ * @returns `true` if the values are deeply equal after omitting specified keys, `false` otherwise
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const obj1 = { id: 1, name: "Alice", updatedAt: "2024-01-01" };
50
+ * const obj2 = { id: 2, name: "Alice", updatedAt: "2024-01-02" };
51
+ *
52
+ * deepEqualExcept(obj1, obj2, { ignoreKeys: ["id", "updatedAt"] }); // true
53
+ * ```
54
+ */
55
+ declare function deepEqualExcept(a: unknown, b: unknown, options: DeepEqualExceptOptions): boolean;
56
+
57
+ export { type DeepOmitOptions as D, type Key as K, type PathSegment as P, type DeepEqualExceptOptions as a, deepEqualExcept as b, deepOmit as d };