@need-code/nc-ddd 0.2.3 → 0.3.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 +3 -3
- package/dist/core/{agregate-root.d.ts → aggregate-root.d.ts} +7 -7
- package/dist/core/aggregate-root.d.ts.map +1 -0
- package/dist/core/{agregate-root.js → aggregate-root.js} +4 -4
- package/dist/core/aggregate-root.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/core/agregate-root.d.ts.map +0 -1
- package/dist/core/agregate-root.js.map +0 -1
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ export class Employee extends Entity<EmployeeProps> {
|
|
|
112
112
|
|
|
113
113
|
An Aggregate Root is a specific type of Entity that acts as a gateway to a cluster of associated objects.
|
|
114
114
|
|
|
115
|
-
The `
|
|
115
|
+
The `AggregateRoot` base class extends the `Entity` class and allows for more complex properties, including other Entities.
|
|
116
116
|
|
|
117
117
|
**Example: `Company` Aggregate Root**
|
|
118
118
|
```typescript
|
|
@@ -120,7 +120,7 @@ The `AgregateRoot` base class extends the `Entity` class and allows for more com
|
|
|
120
120
|
import { left, merge } from "@sweet-monads/either";
|
|
121
121
|
import { flatten, safeParse } from "valibot";
|
|
122
122
|
|
|
123
|
-
import {
|
|
123
|
+
import { AggregateRoot } from "@/core/aggregate-root";
|
|
124
124
|
import { CreateCompanyDTOSchema } from "../dtos/create-company.dto";
|
|
125
125
|
import { Employee } from "../entities/employee.entity";
|
|
126
126
|
import { CompanyNameVO } from "../value-objects/company/company-name.vo";
|
|
@@ -132,7 +132,7 @@ export interface CompanyProps {
|
|
|
132
132
|
employees: Employee[];
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
export class Company extends
|
|
135
|
+
export class Company extends AggregateRoot<CompanyProps> {
|
|
136
136
|
private constructor(props: CompanyProps) {
|
|
137
137
|
super(props);
|
|
138
138
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type * as v from "valibot";
|
|
2
2
|
import { Entity, type IEntityProps, type InferEntityProps } from "./entity.js";
|
|
3
3
|
import { VO } from "./vo.js";
|
|
4
|
-
type
|
|
4
|
+
type AllowedAggregateRootPropValue = VO<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>> | Array<VO<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>>> | Entity<IEntityProps> | Array<Entity<IEntityProps>>;
|
|
5
5
|
export type InferPropType<T> = T extends ReadonlyArray<infer U> ? InferPropType<U>[] : T extends VO<infer S> ? v.InferInput<S> : T extends Entity<infer P> ? InferEntityProps<P> : never;
|
|
6
|
-
export type
|
|
6
|
+
export type InferAggregateRootProps<T> = {
|
|
7
7
|
[K in keyof T]: InferPropType<T[K]>;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
|
-
* @class
|
|
10
|
+
* @class AggregateRoot
|
|
11
11
|
* @description Base class for aggregate roots in DDD. An aggregate root is a specific type of entity that acts as a gateway to a cluster of associated objects.
|
|
12
12
|
* @template Props - The properties of the aggregate root. Must include an 'id' property which is a Value Object.
|
|
13
13
|
*/
|
|
14
|
-
export declare abstract class
|
|
14
|
+
export declare abstract class AggregateRoot<Props extends IEntityProps & Record<keyof Props, AllowedAggregateRootPropValue>> {
|
|
15
15
|
readonly props: Props;
|
|
16
16
|
/**
|
|
17
17
|
* The constructor is protected to enforce creation through factory methods in subclasses.
|
|
@@ -23,14 +23,14 @@ export declare abstract class AgregateRoot<Props extends IEntityProps & Record<k
|
|
|
23
23
|
* @returns {Props["id"]} The unique identifier of the aggregate root.
|
|
24
24
|
*/
|
|
25
25
|
get id(): Props["id"];
|
|
26
|
-
get primitive():
|
|
26
|
+
get primitive(): InferAggregateRootProps<Props>;
|
|
27
27
|
/**
|
|
28
28
|
* Compares this aggregate root with another for equality.
|
|
29
29
|
* Aggregate roots are considered equal if they have the same identifier.
|
|
30
30
|
* @param other The other aggregate root to compare with.
|
|
31
31
|
* @returns {boolean} `true` if they are equal, `false` otherwise.
|
|
32
32
|
*/
|
|
33
|
-
isEqual(other?:
|
|
33
|
+
isEqual(other?: AggregateRoot<Props>): boolean;
|
|
34
34
|
}
|
|
35
35
|
export {};
|
|
36
|
-
//# sourceMappingURL=
|
|
36
|
+
//# sourceMappingURL=aggregate-root.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate-root.d.ts","sourceRoot":"","sources":["../../src/core/aggregate-root.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,KAAK,6BAA6B,GAC9B,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,GACxD,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAC/D,MAAM,CAAC,YAAY,CAAC,GACpB,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;AAEhC,MAAM,MAAM,aAAa,CAAC,CAAC,IACzB,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAC5B,aAAa,CAAC,CAAC,CAAC,EAAE,GAClB,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC,GACnB,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GACf,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,CAAC,GACvB,gBAAgB,CAAC,CAAC,CAAC,GACnB,KAAK,CAAC;AAEhB,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI;KACtC,CAAC,IAAI,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACpC,CAAC;AAEF;;;;GAIG;AACH,8BAAsB,aAAa,CACjC,KAAK,SAAS,YAAY,GAAG,MAAM,CAAC,MAAM,KAAK,EAAE,6BAA6B,CAAC;IAE/E,SAAgB,KAAK,EAAE,KAAK,CAAC;IAE7B;;;OAGG;IACH,SAAS,aAAa,KAAK,EAAE,KAAK;IAIlC;;;OAGG;IACH,IAAI,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC,CAEpB;IAED,IAAI,SAAS,IAAI,uBAAuB,CAAC,KAAK,CAAC,CAmB9C;IAED;;;;;OAKG;IACI,OAAO,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG,OAAO;CAetD"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Entity } from "./entity.js";
|
|
2
2
|
import { VO } from "./vo.js";
|
|
3
3
|
/**
|
|
4
|
-
* @class
|
|
4
|
+
* @class AggregateRoot
|
|
5
5
|
* @description Base class for aggregate roots in DDD. An aggregate root is a specific type of entity that acts as a gateway to a cluster of associated objects.
|
|
6
6
|
* @template Props - The properties of the aggregate root. Must include an 'id' property which is a Value Object.
|
|
7
7
|
*/
|
|
8
|
-
export class
|
|
8
|
+
export class AggregateRoot {
|
|
9
9
|
props;
|
|
10
10
|
/**
|
|
11
11
|
* The constructor is protected to enforce creation through factory methods in subclasses.
|
|
@@ -51,10 +51,10 @@ export class AgregateRoot {
|
|
|
51
51
|
if (this === other) {
|
|
52
52
|
return true;
|
|
53
53
|
}
|
|
54
|
-
if (!(other instanceof
|
|
54
|
+
if (!(other instanceof AggregateRoot)) {
|
|
55
55
|
return false;
|
|
56
56
|
}
|
|
57
57
|
return this.id.isEqual(other.id);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
//# sourceMappingURL=
|
|
60
|
+
//# sourceMappingUR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IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC1C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,CAAC,KAAK,YAAY,aAAa,CAAC,EAAE,CAAC;YACtC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACnC,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agregate-root.d.ts","sourceRoot":"","sources":["../../src/core/agregate-root.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAA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