@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.
Files changed (148) hide show
  1. package/CHANGELOG.md +23 -75
  2. package/LICENSE +20 -20
  3. package/README.md +37 -20
  4. package/dist/base-entity.d.ts +2 -2
  5. package/dist/base-entity.d.ts.map +1 -1
  6. package/dist/base-entity.js +6 -4
  7. package/dist/base-entity.js.map +1 -1
  8. package/dist/criteria.d.ts +5 -11
  9. package/dist/criteria.d.ts.map +1 -1
  10. package/dist/criteria.js +4 -3
  11. package/dist/criteria.js.map +1 -1
  12. package/dist/deep-proxy.d.ts +3 -1
  13. package/dist/deep-proxy.d.ts.map +1 -1
  14. package/dist/deep-proxy.js +116 -29
  15. package/dist/deep-proxy.js.map +1 -1
  16. package/dist/domain-event-bus.d.ts +5 -6
  17. package/dist/domain-event-bus.d.ts.map +1 -1
  18. package/dist/domain-event-bus.js +3 -11
  19. package/dist/domain-event-bus.js.map +1 -1
  20. package/dist/domain-event.d.ts +1 -31
  21. package/dist/domain-event.d.ts.map +1 -1
  22. package/dist/domain-event.js +2 -1
  23. package/dist/domain-event.js.map +1 -1
  24. package/dist/entity.d.ts +2 -2
  25. package/dist/entity.js +1 -1
  26. package/dist/exceptions.d.ts +251 -0
  27. package/dist/exceptions.d.ts.map +1 -0
  28. package/dist/exceptions.js +321 -0
  29. package/dist/exceptions.js.map +1 -0
  30. package/dist/id.d.ts +3 -3
  31. package/dist/id.d.ts.map +1 -1
  32. package/dist/id.js +15 -4
  33. package/dist/id.js.map +1 -1
  34. package/dist/index.d.ts +2 -5
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +2 -8
  37. package/dist/index.js.map +1 -1
  38. package/dist/paginated-result.d.ts.map +1 -1
  39. package/dist/paginated-result.js +12 -1
  40. package/dist/paginated-result.js.map +1 -1
  41. package/dist/repository/index.d.ts +2 -39
  42. package/dist/repository/index.d.ts.map +1 -1
  43. package/dist/repository/index.js +2 -39
  44. package/dist/repository/index.js.map +1 -1
  45. package/dist/repository/unit-of-work.d.ts +0 -11
  46. package/dist/repository/unit-of-work.d.ts.map +1 -1
  47. package/dist/repository/unit-of-work.js +0 -35
  48. package/dist/repository/unit-of-work.js.map +1 -1
  49. package/dist/types/criteria.d.ts +6 -2
  50. package/dist/types/criteria.d.ts.map +1 -1
  51. package/dist/types/criteria.js +1 -1
  52. package/dist/types/criteria.js.map +1 -1
  53. package/dist/types/domain-event.d.ts +32 -0
  54. package/dist/types/domain-event.d.ts.map +1 -0
  55. package/dist/types/domain-event.js +2 -0
  56. package/dist/types/domain-event.js.map +1 -0
  57. package/dist/types/domain.d.ts +2 -2
  58. package/dist/types/domain.d.ts.map +1 -1
  59. package/dist/types/history-tracker.d.ts +1 -1
  60. package/dist/types/history-tracker.d.ts.map +1 -1
  61. package/dist/types/index.d.ts +1 -0
  62. package/dist/types/index.d.ts.map +1 -1
  63. package/dist/types/index.js +1 -0
  64. package/dist/types/index.js.map +1 -1
  65. package/dist/value-object.d.ts +1 -1
  66. package/dist/value-object.d.ts.map +1 -1
  67. package/dist/value-object.js +2 -5
  68. package/dist/value-object.js.map +1 -1
  69. package/eslint.config.js +3 -3
  70. package/jest.config.js +1 -1
  71. package/package.json +14 -20
  72. package/src/base-entity.ts +6 -5
  73. package/src/criteria.ts +11 -11
  74. package/src/deep-proxy.ts +447 -339
  75. package/src/domain-event-bus.ts +152 -166
  76. package/src/domain-event.ts +53 -90
  77. package/src/entity.ts +16 -16
  78. package/src/exceptions.ts +435 -0
  79. package/src/id.ts +107 -94
  80. package/src/index.ts +26 -9
  81. package/src/paginated-result.ts +14 -1
  82. package/src/repository/index.ts +2 -44
  83. package/src/repository/unit-of-work.ts +1 -44
  84. package/src/types/criteria.ts +7 -2
  85. package/src/types/domain-event.ts +38 -0
  86. package/src/types/domain.ts +2 -3
  87. package/src/types/history-tracker.ts +1 -1
  88. package/src/types/index.ts +1 -0
  89. package/src/validation-error.ts +97 -97
  90. package/src/value-object.ts +3 -6
  91. package/tests/criteria.test.ts +8 -0
  92. package/tests/domain-events.test.ts +431 -445
  93. package/tests/entity-validation.test.ts +2 -2
  94. package/tests/entity.test.ts +33 -33
  95. package/tests/history-tracker.spec.ts +57 -17
  96. package/tests/id.test.ts +341 -341
  97. package/tests/repository.test.ts +8 -4
  98. package/tests/to-json.test.ts +103 -91
  99. package/tests/utils.ts +254 -151
  100. package/tests/value-object-validation.test.ts +0 -9
  101. package/tests/value-objects.test.ts +52 -52
  102. package/tsconfig.json +2 -24
  103. package/.github/workflows/ci.yml +0 -40
  104. package/.husky/commit-msg +0 -1
  105. package/.husky/pre-commit +0 -1
  106. package/.vscode/settings.json +0 -3
  107. package/commitlint.config.js +0 -23
  108. package/dist/filtering.d.ts +0 -107
  109. package/dist/filtering.d.ts.map +0 -1
  110. package/dist/filtering.js +0 -202
  111. package/dist/filtering.js.map +0 -1
  112. package/dist/ordering.d.ts +0 -93
  113. package/dist/ordering.d.ts.map +0 -1
  114. package/dist/ordering.js +0 -154
  115. package/dist/ordering.js.map +0 -1
  116. package/dist/pagination.d.ts +0 -218
  117. package/dist/pagination.d.ts.map +0 -1
  118. package/dist/pagination.js +0 -281
  119. package/dist/pagination.js.map +0 -1
  120. package/dist/repository/in-memory-repository.d.ts +0 -50
  121. package/dist/repository/in-memory-repository.d.ts.map +0 -1
  122. package/dist/repository/in-memory-repository.js +0 -93
  123. package/dist/repository/in-memory-repository.js.map +0 -1
  124. package/dist/repository/mapper.d.ts +0 -56
  125. package/dist/repository/mapper.d.ts.map +0 -1
  126. package/dist/repository/mapper.js +0 -15
  127. package/dist/repository/mapper.js.map +0 -1
  128. package/dist/repository/types.d.ts +0 -87
  129. package/dist/repository/types.d.ts.map +0 -1
  130. package/dist/repository/types.js +0 -6
  131. package/dist/repository/types.js.map +0 -1
  132. package/dist/repository.d.ts +0 -2
  133. package/dist/repository.d.ts.map +0 -1
  134. package/dist/repository.js +0 -21
  135. package/dist/repository.js.map +0 -1
  136. package/dist/specification.d.ts +0 -102
  137. package/dist/specification.d.ts.map +0 -1
  138. package/dist/specification.js +0 -187
  139. package/dist/specification.js.map +0 -1
  140. package/dist/types/repository.d.ts +0 -43
  141. package/dist/types/repository.d.ts.map +0 -1
  142. package/dist/types/repository.js +0 -2
  143. package/dist/types/repository.js.map +0 -1
  144. package/dist/types.d.ts +0 -88
  145. package/dist/types.d.ts.map +0 -1
  146. package/dist/types.js +0 -12
  147. package/dist/types.js.map +0 -1
  148. 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", () => {
@@ -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 post = new Post({
7
+ const user = new User({
8
8
  id: new Id("1"),
9
- title: "First Post",
10
- content: "Hello World",
11
- likes: 0,
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
- let changeCount = 0;
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
- post.subscribe({
17
- title: {
18
- onChange: ({ previous, current, path }) => {
19
- changeCount++;
20
- expect(previous).toBe("First Post");
21
- expect(current).toBe("Updated Title");
22
- expect(path).toBe("title");
23
- done();
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
- post.title = "Updated Title";
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", () => {