@woltz/rich-domain 0.2.2 → 1.1.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/CHANGELOG.md +23 -75
- package/LICENSE +20 -20
- package/README.md +37 -20
- package/dist/base-entity.d.ts +2 -2
- package/dist/base-entity.d.ts.map +1 -1
- package/dist/base-entity.js +6 -4
- package/dist/base-entity.js.map +1 -1
- package/dist/criteria.d.ts +5 -11
- package/dist/criteria.d.ts.map +1 -1
- package/dist/criteria.js +4 -3
- package/dist/criteria.js.map +1 -1
- package/dist/deep-proxy.d.ts +3 -1
- package/dist/deep-proxy.d.ts.map +1 -1
- package/dist/deep-proxy.js +116 -29
- package/dist/deep-proxy.js.map +1 -1
- package/dist/domain-event-bus.d.ts +5 -6
- package/dist/domain-event-bus.d.ts.map +1 -1
- package/dist/domain-event-bus.js +3 -11
- package/dist/domain-event-bus.js.map +1 -1
- package/dist/domain-event.d.ts +1 -31
- package/dist/domain-event.d.ts.map +1 -1
- package/dist/domain-event.js +2 -1
- package/dist/domain-event.js.map +1 -1
- package/dist/entity.d.ts +2 -2
- package/dist/entity.js +1 -1
- package/dist/exceptions.d.ts +251 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +321 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/id.d.ts +3 -3
- package/dist/id.d.ts.map +1 -1
- package/dist/id.js +15 -4
- package/dist/id.js.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -8
- package/dist/index.js.map +1 -1
- package/dist/paginated-result.d.ts.map +1 -1
- package/dist/paginated-result.js +12 -1
- package/dist/paginated-result.js.map +1 -1
- package/dist/repository/index.d.ts +2 -39
- package/dist/repository/index.d.ts.map +1 -1
- package/dist/repository/index.js +2 -39
- package/dist/repository/index.js.map +1 -1
- package/dist/repository/unit-of-work.d.ts +0 -11
- package/dist/repository/unit-of-work.d.ts.map +1 -1
- package/dist/repository/unit-of-work.js +0 -35
- package/dist/repository/unit-of-work.js.map +1 -1
- package/dist/types/criteria.d.ts +6 -2
- package/dist/types/criteria.d.ts.map +1 -1
- package/dist/types/criteria.js +1 -1
- package/dist/types/criteria.js.map +1 -1
- package/dist/types/domain-event.d.ts +32 -0
- package/dist/types/domain-event.d.ts.map +1 -0
- package/dist/types/domain-event.js +2 -0
- package/dist/types/domain-event.js.map +1 -0
- package/dist/types/domain.d.ts +2 -2
- package/dist/types/domain.d.ts.map +1 -1
- package/dist/types/history-tracker.d.ts +1 -1
- package/dist/types/history-tracker.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/value-object.d.ts +1 -1
- package/dist/value-object.d.ts.map +1 -1
- package/dist/value-object.js +2 -5
- package/dist/value-object.js.map +1 -1
- package/eslint.config.js +3 -3
- package/jest.config.js +1 -1
- package/package.json +14 -20
- package/src/base-entity.ts +6 -5
- package/src/criteria.ts +11 -11
- package/src/deep-proxy.ts +447 -339
- package/src/domain-event-bus.ts +152 -166
- package/src/domain-event.ts +53 -90
- package/src/entity.ts +16 -16
- package/src/exceptions.ts +435 -0
- package/src/id.ts +107 -94
- package/src/index.ts +26 -9
- package/src/paginated-result.ts +14 -1
- package/src/repository/index.ts +2 -44
- package/src/repository/unit-of-work.ts +1 -44
- package/src/types/criteria.ts +7 -2
- package/src/types/domain-event.ts +38 -0
- package/src/types/domain.ts +2 -3
- package/src/types/history-tracker.ts +1 -1
- package/src/types/index.ts +1 -0
- package/src/validation-error.ts +97 -97
- package/src/value-object.ts +3 -6
- package/tests/criteria.test.ts +8 -0
- package/tests/domain-events.test.ts +431 -445
- package/tests/entity-validation.test.ts +2 -2
- package/tests/entity.test.ts +33 -33
- package/tests/history-tracker.spec.ts +57 -17
- package/tests/id.test.ts +341 -341
- package/tests/repository.test.ts +8 -4
- package/tests/to-json.test.ts +103 -91
- package/tests/utils.ts +254 -151
- package/tests/value-object-validation.test.ts +0 -9
- package/tests/value-objects.test.ts +52 -52
- package/tsconfig.json +2 -24
- package/.github/workflows/ci.yml +0 -40
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.vscode/settings.json +0 -3
- package/commitlint.config.js +0 -23
- package/dist/filtering.d.ts +0 -107
- package/dist/filtering.d.ts.map +0 -1
- package/dist/filtering.js +0 -202
- package/dist/filtering.js.map +0 -1
- package/dist/ordering.d.ts +0 -93
- package/dist/ordering.d.ts.map +0 -1
- package/dist/ordering.js +0 -154
- package/dist/ordering.js.map +0 -1
- package/dist/pagination.d.ts +0 -218
- package/dist/pagination.d.ts.map +0 -1
- package/dist/pagination.js +0 -281
- package/dist/pagination.js.map +0 -1
- package/dist/repository/in-memory-repository.d.ts +0 -50
- package/dist/repository/in-memory-repository.d.ts.map +0 -1
- package/dist/repository/in-memory-repository.js +0 -93
- package/dist/repository/in-memory-repository.js.map +0 -1
- package/dist/repository/mapper.d.ts +0 -56
- package/dist/repository/mapper.d.ts.map +0 -1
- package/dist/repository/mapper.js +0 -15
- package/dist/repository/mapper.js.map +0 -1
- package/dist/repository/types.d.ts +0 -87
- package/dist/repository/types.d.ts.map +0 -1
- package/dist/repository/types.js +0 -6
- package/dist/repository/types.js.map +0 -1
- package/dist/repository.d.ts +0 -2
- package/dist/repository.d.ts.map +0 -1
- package/dist/repository.js +0 -21
- package/dist/repository.js.map +0 -1
- package/dist/specification.d.ts +0 -102
- package/dist/specification.d.ts.map +0 -1
- package/dist/specification.js +0 -187
- package/dist/specification.js.map +0 -1
- package/dist/types/repository.d.ts +0 -43
- package/dist/types/repository.d.ts.map +0 -1
- package/dist/types/repository.js +0 -2
- package/dist/types/repository.js.map +0 -1
- package/dist/types.d.ts +0 -88
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -12
- package/dist/types.js.map +0 -1
- package/src/repository/in-memory-repository.ts +0 -116
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import {
|
|
7
7
|
Id,
|
|
8
|
-
BaseProps,
|
|
9
8
|
Aggregate,
|
|
10
9
|
EntityValidation,
|
|
11
10
|
EntityHooks,
|
|
12
11
|
ValidationError,
|
|
13
12
|
} from "../src";
|
|
14
13
|
import { Address } from "./utils";
|
|
14
|
+
import { BaseProps } from "../src/types";
|
|
15
15
|
|
|
16
16
|
interface UserProps extends BaseProps {
|
|
17
17
|
id: Id;
|
|
@@ -134,7 +134,7 @@ describe("Rich Domain with Standard Schema Validation", () => {
|
|
|
134
134
|
expect(user.name).toBe("John Doe");
|
|
135
135
|
expect(user.email).toBe("john@example.com");
|
|
136
136
|
expect(user.age).toBe(25);
|
|
137
|
-
expect(user.isNew).toBe(true);
|
|
137
|
+
expect(user.isNew()).toBe(true);
|
|
138
138
|
});
|
|
139
139
|
|
|
140
140
|
it("should throw on invalid email", () => {
|
package/tests/entity.test.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
// ==========================================================================
|
|
2
|
-
// Basic Entity Tests
|
|
3
|
-
// ==========================================================================
|
|
4
|
-
|
|
5
|
-
import { Id } from "../src";
|
|
6
|
-
import { Post } from "./utils";
|
|
7
|
-
|
|
8
|
-
describe("Entity Basic Functionality", () => {
|
|
9
|
-
it("should create an entity with id", () => {
|
|
10
|
-
const id = new Id("1");
|
|
11
|
-
const post = new Post({
|
|
12
|
-
id,
|
|
13
|
-
title: "First Post",
|
|
14
|
-
content: "Hello World",
|
|
15
|
-
likes: 0,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
expect(post.id.value).toBe("1");
|
|
19
|
-
expect(post.title).toBe("First Post");
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should allow property modification", () => {
|
|
23
|
-
const post = new Post({
|
|
24
|
-
id: new Id("1"),
|
|
25
|
-
title: "First Post",
|
|
26
|
-
content: "Hello World",
|
|
27
|
-
likes: 0,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
post.title = "Updated Title";
|
|
31
|
-
expect(post.title).toBe("Updated Title");
|
|
32
|
-
});
|
|
33
|
-
});
|
|
1
|
+
// ==========================================================================
|
|
2
|
+
// Basic Entity Tests
|
|
3
|
+
// ==========================================================================
|
|
4
|
+
|
|
5
|
+
import { Id } from "../src";
|
|
6
|
+
import { Post } from "./utils";
|
|
7
|
+
|
|
8
|
+
describe("Entity Basic Functionality", () => {
|
|
9
|
+
it("should create an entity with id", () => {
|
|
10
|
+
const id = new Id("1");
|
|
11
|
+
const post = new Post({
|
|
12
|
+
id,
|
|
13
|
+
title: "First Post",
|
|
14
|
+
content: "Hello World",
|
|
15
|
+
likes: 0,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
expect(post.id.value).toBe("1");
|
|
19
|
+
expect(post.title).toBe("First Post");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should allow property modification", () => {
|
|
23
|
+
const post = new Post({
|
|
24
|
+
id: new Id("1"),
|
|
25
|
+
title: "First Post",
|
|
26
|
+
content: "Hello World",
|
|
27
|
+
likes: 0,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
post.title = "Updated Title";
|
|
31
|
+
expect(post.title).toBe("Updated Title");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -4,28 +4,68 @@ import { Post, User, Address, Comment } from "./utils";
|
|
|
4
4
|
describe("History Tracker Tests", () => {
|
|
5
5
|
describe("Simple Property Changes", () => {
|
|
6
6
|
it("should track simple property changes", (done) => {
|
|
7
|
-
const
|
|
7
|
+
const user = new User({
|
|
8
8
|
id: new Id("1"),
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
name: "John Doe",
|
|
10
|
+
email: "john@example.com",
|
|
11
|
+
posts: [
|
|
12
|
+
new Post({
|
|
13
|
+
id: new Id("1"),
|
|
14
|
+
title: "First Post",
|
|
15
|
+
content: "Hello World",
|
|
16
|
+
likes: 0,
|
|
17
|
+
}),
|
|
18
|
+
],
|
|
19
|
+
address: new Address({
|
|
20
|
+
street: "Main St",
|
|
21
|
+
city: "NYC",
|
|
22
|
+
zipCode: "10001",
|
|
23
|
+
}),
|
|
24
|
+
comments: [],
|
|
12
25
|
});
|
|
13
26
|
|
|
14
|
-
|
|
27
|
+
user.changeEmail("new@example.com");
|
|
28
|
+
user.name = "New Name";
|
|
29
|
+
user.addPost(
|
|
30
|
+
new Post({
|
|
31
|
+
id: new Id("2"),
|
|
32
|
+
title: "Second Post",
|
|
33
|
+
content: "Hello World 2",
|
|
34
|
+
likes: 0,
|
|
35
|
+
})
|
|
36
|
+
);
|
|
15
37
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
function dispatch(entity: User) {
|
|
39
|
+
entity.subscribe({
|
|
40
|
+
email: {
|
|
41
|
+
onChange: ({ previous, current, path }) => {
|
|
42
|
+
expect(previous).toBe("john@example.com");
|
|
43
|
+
expect(current).toBe("new@example.com");
|
|
44
|
+
expect(path).toBe("email");
|
|
45
|
+
},
|
|
24
46
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
47
|
+
posts: {
|
|
48
|
+
onChange: ({ toCreate, toUpdate, toDelete }) => {
|
|
49
|
+
expect(toCreate).toHaveLength(1);
|
|
50
|
+
expect(toUpdate).toHaveLength(1);
|
|
51
|
+
expect(toDelete).toHaveLength(0);
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
name: {
|
|
55
|
+
onChange: ({ previous, current, path }) => {
|
|
56
|
+
expect(previous).toBe("John Doe");
|
|
57
|
+
expect(current).toBe("New Name");
|
|
58
|
+
expect(path).toBe("name");
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
user.posts[0].title = "Updated Title";
|
|
64
|
+
dispatch(user);
|
|
65
|
+
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
done();
|
|
68
|
+
}, 100);
|
|
29
69
|
});
|
|
30
70
|
|
|
31
71
|
it("should track multiple property changes", () => {
|