@woltz/rich-domain 1.0.0 → 1.2.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 (129) hide show
  1. package/CHANGELOG.md +37 -86
  2. package/LICENSE +20 -20
  3. package/dist/base-entity.d.ts +1 -1
  4. package/dist/base-entity.d.ts.map +1 -1
  5. package/dist/base-entity.js +15 -19
  6. package/dist/base-entity.js.map +1 -1
  7. package/dist/constants.js +1 -4
  8. package/dist/constants.js.map +1 -1
  9. package/dist/criteria.d.ts +24 -14
  10. package/dist/criteria.d.ts.map +1 -1
  11. package/dist/criteria.js +154 -67
  12. package/dist/criteria.js.map +1 -1
  13. package/dist/deep-proxy.d.ts.map +1 -1
  14. package/dist/deep-proxy.js +19 -9
  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 +4 -17
  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 +4 -7
  23. package/dist/domain-event.js.map +1 -1
  24. package/dist/entity.d.ts +2 -2
  25. package/dist/entity.js +3 -8
  26. package/dist/entity.js.map +1 -1
  27. package/dist/exceptions.d.ts +251 -0
  28. package/dist/exceptions.d.ts.map +1 -0
  29. package/dist/exceptions.js +321 -0
  30. package/dist/exceptions.js.map +1 -0
  31. package/dist/id.d.ts.map +1 -1
  32. package/dist/id.js +14 -7
  33. package/dist/id.js.map +1 -1
  34. package/dist/index.d.ts +2 -4
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +11 -40
  37. package/dist/index.js.map +1 -1
  38. package/dist/mapper.js +1 -5
  39. package/dist/mapper.js.map +1 -1
  40. package/dist/paginated-result.d.ts.map +1 -1
  41. package/dist/paginated-result.js +17 -9
  42. package/dist/paginated-result.js.map +1 -1
  43. package/dist/repository/base-repository.js +4 -11
  44. package/dist/repository/base-repository.js.map +1 -1
  45. package/dist/repository/index.d.ts +1 -2
  46. package/dist/repository/index.d.ts.map +1 -1
  47. package/dist/repository/index.js +3 -26
  48. package/dist/repository/index.js.map +1 -1
  49. package/dist/repository/unit-of-work.d.ts +0 -11
  50. package/dist/repository/unit-of-work.d.ts.map +1 -1
  51. package/dist/repository/unit-of-work.js +2 -43
  52. package/dist/repository/unit-of-work.js.map +1 -1
  53. package/dist/types/criteria.d.ts +31 -7
  54. package/dist/types/criteria.d.ts.map +1 -1
  55. package/dist/types/criteria.js +1 -4
  56. package/dist/types/criteria.js.map +1 -1
  57. package/dist/types/domain-event.d.ts +32 -0
  58. package/dist/types/domain-event.d.ts.map +1 -0
  59. package/dist/types/domain-event.js +2 -0
  60. package/dist/types/domain-event.js.map +1 -0
  61. package/dist/types/domain.d.ts +2 -2
  62. package/dist/types/domain.d.ts.map +1 -1
  63. package/dist/types/domain.js +1 -2
  64. package/dist/types/history-tracker.d.ts +1 -1
  65. package/dist/types/history-tracker.d.ts.map +1 -1
  66. package/dist/types/history-tracker.js +1 -2
  67. package/dist/types/index.d.ts +1 -0
  68. package/dist/types/index.d.ts.map +1 -1
  69. package/dist/types/index.js +7 -22
  70. package/dist/types/index.js.map +1 -1
  71. package/dist/types/standard-schema.js +1 -2
  72. package/dist/types/unit-of-work.js +1 -2
  73. package/dist/types/utils.js +1 -2
  74. package/dist/utils/criteria-operator-validation.d.ts +5 -0
  75. package/dist/utils/criteria-operator-validation.d.ts.map +1 -0
  76. package/dist/utils/criteria-operator-validation.js +143 -0
  77. package/dist/utils/criteria-operator-validation.js.map +1 -0
  78. package/dist/utils/helpers.d.ts +2 -0
  79. package/dist/utils/helpers.d.ts.map +1 -0
  80. package/dist/utils/helpers.js +10 -0
  81. package/dist/utils/helpers.js.map +1 -0
  82. package/dist/validation-error.js +3 -9
  83. package/dist/validation-error.js.map +1 -1
  84. package/dist/value-object.d.ts +1 -1
  85. package/dist/value-object.d.ts.map +1 -1
  86. package/dist/value-object.js +7 -14
  87. package/dist/value-object.js.map +1 -1
  88. package/eslint.config.js +9 -3
  89. package/jest.config.js +1 -1
  90. package/package.json +14 -20
  91. package/src/base-entity.ts +3 -3
  92. package/src/criteria.ts +268 -87
  93. package/src/deep-proxy.ts +50 -38
  94. package/src/domain-event-bus.ts +152 -166
  95. package/src/domain-event.ts +53 -90
  96. package/src/entity.ts +16 -16
  97. package/src/exceptions.ts +435 -0
  98. package/src/id.ts +107 -94
  99. package/src/index.ts +32 -8
  100. package/src/paginated-result.ts +15 -3
  101. package/src/repository/index.ts +1 -6
  102. package/src/repository/unit-of-work.ts +1 -44
  103. package/src/types/criteria.ts +95 -17
  104. package/src/types/domain-event.ts +38 -0
  105. package/src/types/domain.ts +2 -3
  106. package/src/types/history-tracker.ts +1 -1
  107. package/src/types/index.ts +1 -0
  108. package/src/utils/criteria-operator-validation.ts +171 -0
  109. package/src/utils/helpers.ts +6 -0
  110. package/src/validation-error.ts +97 -97
  111. package/src/value-object.ts +3 -6
  112. package/tests/criteria.test.ts +324 -1
  113. package/tests/domain-events.test.ts +431 -445
  114. package/tests/entity-validation.test.ts +1 -1
  115. package/tests/entity.test.ts +33 -33
  116. package/tests/repository.test.ts +4 -2
  117. package/tests/utils.ts +254 -151
  118. package/tests/value-object-validation.test.ts +0 -9
  119. package/tsconfig.json +2 -24
  120. package/.github/workflows/ci.yml +0 -40
  121. package/.husky/commit-msg +0 -1
  122. package/.husky/pre-commit +0 -1
  123. package/.vscode/settings.json +0 -3
  124. package/commitlint.config.js +0 -23
  125. package/dist/repository/in-memory-repository.d.ts +0 -50
  126. package/dist/repository/in-memory-repository.d.ts.map +0 -1
  127. package/dist/repository/in-memory-repository.js +0 -97
  128. package/dist/repository/in-memory-repository.js.map +0 -1
  129. 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;
@@ -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
+ });
@@ -1,6 +1,8 @@
1
- import { Id, Aggregate, Criteria, BaseProps, PaginatedResult } from "../src";
2
- import { InMemoryRepository, Mapper } from "../src/repository";
1
+ import { Id, Aggregate, Criteria, PaginatedResult } from "../src";
2
+ import { Mapper } from "../src/repository";
3
3
  import { Repository } from "../src/repository/base-repository";
4
+ import { BaseProps } from "../src/types";
5
+ import { InMemoryRepository } from "./utils";
4
6
 
5
7
  // ============================================================================
6
8
  // Test Domain Models
package/tests/utils.ts CHANGED
@@ -1,151 +1,254 @@
1
- // ============================================================================
2
- // Test Entities & Value Objects
3
- // ============================================================================
4
-
5
- import { Aggregate, Entity, Id, ValueObject } from "../src";
6
-
7
- interface AddressProps {
8
- street: string;
9
- city: string;
10
- zipCode: string;
11
- }
12
-
13
- class Address extends ValueObject<AddressProps> {
14
- get street(): string {
15
- return this.props.street;
16
- }
17
-
18
- get city(): string {
19
- return this.props.city;
20
- }
21
-
22
- get zipCode(): string {
23
- return this.props.zipCode;
24
- }
25
- }
26
-
27
- interface PostProps {
28
- id: Id;
29
- title: string;
30
- content: string;
31
- likes: number;
32
- }
33
-
34
- class Post extends Entity<PostProps> {
35
- get title(): string {
36
- return this.props.title;
37
- }
38
-
39
- set title(value: string) {
40
- this.props.title = value;
41
- }
42
-
43
- get content(): string {
44
- return this.props.content;
45
- }
46
-
47
- set content(value: string) {
48
- this.props.content = value;
49
- }
50
-
51
- get likes(): number {
52
- return this.props.likes;
53
- }
54
-
55
- set likes(value: number) {
56
- this.props.likes = value;
57
- }
58
- }
59
-
60
- interface CommentProps {
61
- id: Id;
62
- text: string;
63
- author: string;
64
- }
65
-
66
- class Comment extends Entity<CommentProps> {
67
- get text(): string {
68
- return this.props.text;
69
- }
70
-
71
- set text(value: string) {
72
- this.props.text = value;
73
- }
74
-
75
- get author(): string {
76
- return this.props.author;
77
- }
78
- }
79
-
80
- interface UserProps {
81
- id: Id;
82
- name: string;
83
- email: string;
84
- posts: Post[];
85
- address: Address;
86
- comments: Comment[];
87
- extra?: {
88
- age: number;
89
- height: number;
90
- };
91
- }
92
-
93
- class User extends Aggregate<UserProps> {
94
- get name(): string {
95
- return this.props.name;
96
- }
97
-
98
- set name(value: string) {
99
- this.props.name = value;
100
- }
101
-
102
- get email(): string {
103
- return this.props.email;
104
- }
105
-
106
- get posts(): Post[] {
107
- return this.props.posts;
108
- }
109
-
110
- set posts(value: Post[]) {
111
- this.props.posts = value;
112
- }
113
-
114
- get address(): Address {
115
- return this.props.address;
116
- }
117
-
118
- set address(value: Address) {
119
- this.props.address = value;
120
- }
121
-
122
- get comments(): Comment[] {
123
- return this.props.comments;
124
- }
125
-
126
- set comments(value: Comment[]) {
127
- this.props.comments = value;
128
- }
129
-
130
- public addPost(post: Post) {
131
- this.props.posts.push(post);
132
- }
133
-
134
- public addManyPosts(posts: Post[]) {
135
- this.props.posts.push(...posts);
136
- }
137
-
138
- public removePostById(id: string) {
139
- this.props.posts = this.props.posts.filter((post) => post.id.value !== id);
140
- }
141
-
142
- public changeEmail(email: string) {
143
- this.props.email = email;
144
- }
145
-
146
- public changeExtra(extra: { age: number; height: number }) {
147
- this.props.extra = extra;
148
- }
149
- }
150
-
151
- export { User, Post, Comment, Address };
1
+ // ============================================================================
2
+ // Test Entities & Value Objects
3
+ // ============================================================================
4
+
5
+ import {
6
+ Aggregate,
7
+ Criteria,
8
+ Entity,
9
+ Id,
10
+ Mapper,
11
+ PaginatedResult,
12
+ Repository,
13
+ UnitOfWork,
14
+ ValueObject,
15
+ } from "../src";
16
+
17
+ interface AddressProps {
18
+ street: string;
19
+ city: string;
20
+ zipCode: string;
21
+ }
22
+
23
+ class Address extends ValueObject<AddressProps> {
24
+ get street(): string {
25
+ return this.props.street;
26
+ }
27
+
28
+ get city(): string {
29
+ return this.props.city;
30
+ }
31
+
32
+ get zipCode(): string {
33
+ return this.props.zipCode;
34
+ }
35
+ }
36
+
37
+ interface PostProps {
38
+ id: Id;
39
+ title: string;
40
+ content: string;
41
+ likes: number;
42
+ }
43
+
44
+ class Post extends Entity<PostProps> {
45
+ get title(): string {
46
+ return this.props.title;
47
+ }
48
+
49
+ set title(value: string) {
50
+ this.props.title = value;
51
+ }
52
+
53
+ get content(): string {
54
+ return this.props.content;
55
+ }
56
+
57
+ set content(value: string) {
58
+ this.props.content = value;
59
+ }
60
+
61
+ get likes(): number {
62
+ return this.props.likes;
63
+ }
64
+
65
+ set likes(value: number) {
66
+ this.props.likes = value;
67
+ }
68
+ }
69
+
70
+ interface CommentProps {
71
+ id: Id;
72
+ text: string;
73
+ author: string;
74
+ }
75
+
76
+ class Comment extends Entity<CommentProps> {
77
+ get text(): string {
78
+ return this.props.text;
79
+ }
80
+
81
+ set text(value: string) {
82
+ this.props.text = value;
83
+ }
84
+
85
+ get author(): string {
86
+ return this.props.author;
87
+ }
88
+ }
89
+
90
+ interface UserProps {
91
+ id: Id;
92
+ name: string;
93
+ email: string;
94
+ posts: Post[];
95
+ address: Address;
96
+ comments: Comment[];
97
+ extra?: {
98
+ age: number;
99
+ height: number;
100
+ };
101
+ }
102
+
103
+ class User extends Aggregate<UserProps> {
104
+ get name(): string {
105
+ return this.props.name;
106
+ }
107
+
108
+ set name(value: string) {
109
+ this.props.name = value;
110
+ }
111
+
112
+ get email(): string {
113
+ return this.props.email;
114
+ }
115
+
116
+ get posts(): Post[] {
117
+ return this.props.posts;
118
+ }
119
+
120
+ set posts(value: Post[]) {
121
+ this.props.posts = value;
122
+ }
123
+
124
+ get address(): Address {
125
+ return this.props.address;
126
+ }
127
+
128
+ set address(value: Address) {
129
+ this.props.address = value;
130
+ }
131
+
132
+ get comments(): Comment[] {
133
+ return this.props.comments;
134
+ }
135
+
136
+ set comments(value: Comment[]) {
137
+ this.props.comments = value;
138
+ }
139
+
140
+ public addPost(post: Post) {
141
+ this.props.posts.push(post);
142
+ }
143
+
144
+ public addManyPosts(posts: Post[]) {
145
+ this.props.posts.push(...posts);
146
+ }
147
+
148
+ public removePostById(id: string) {
149
+ this.props.posts = this.props.posts.filter((post) => post.id.value !== id);
150
+ }
151
+
152
+ public changeEmail(email: string) {
153
+ this.props.email = email;
154
+ }
155
+
156
+ public changeExtra(extra: { age: number; height: number }) {
157
+ this.props.extra = extra;
158
+ }
159
+ }
160
+
161
+ class InMemoryRepository<
162
+ TDomain extends Aggregate<any>
163
+ > extends Repository<TDomain> {
164
+ protected items: Map<string, TDomain> = new Map();
165
+ readonly uow: UnitOfWork;
166
+ constructor(
167
+ protected readonly mapperToDomain: Mapper<unknown, TDomain>,
168
+ protected readonly mapperToPersistence: Mapper<TDomain, unknown>
169
+ ) {
170
+ super();
171
+ this.uow = {} as UnitOfWork;
172
+ }
173
+
174
+ get model(): any {
175
+ // your database table name
176
+ return "inMemory";
177
+ }
178
+
179
+ async findById(id: string): Promise<TDomain | null> {
180
+ return this.items.get(id) || null;
181
+ }
182
+
183
+ async find(criteria: Criteria<TDomain>): Promise<PaginatedResult<TDomain>> {
184
+ const allItems = Array.from(this.items.values());
185
+ return PaginatedResult.fromArray(allItems, criteria);
186
+ }
187
+
188
+ async findAll(criteria?: Criteria<TDomain>): Promise<TDomain[]> {
189
+ if (criteria) {
190
+ const result = await this.find(criteria);
191
+ return result.data;
192
+ }
193
+
194
+ return Array.from(this.items.values());
195
+ }
196
+
197
+ async findOne(criteria: Criteria<TDomain>): Promise<TDomain | null> {
198
+ const result = await this.find(criteria.clone().limit(1));
199
+ return result.data.length > 0 ? result.data[0] : null;
200
+ }
201
+
202
+ async create(aggregate: TDomain): Promise<void> {
203
+ this.items.set(aggregate.id.value, aggregate);
204
+ }
205
+
206
+ async update(entity: TDomain): Promise<void> {
207
+ this.items.set(entity.id.value, entity);
208
+ }
209
+
210
+ async createMany(aggregates: TDomain[]): Promise<void> {
211
+ for (const aggregate of aggregates) {
212
+ await this.create(aggregate);
213
+ }
214
+ }
215
+
216
+ async delete(aggregate: TDomain): Promise<void> {
217
+ this.items.delete(aggregate.id.value);
218
+ }
219
+
220
+ async exists(id: string): Promise<boolean> {
221
+ return this.items.has(id);
222
+ }
223
+
224
+ async count(criteria?: Criteria<TDomain>): Promise<number> {
225
+ if (criteria) {
226
+ const result = await this.find(criteria);
227
+ return result.meta.total;
228
+ }
229
+ return this.items.size;
230
+ }
231
+
232
+ /**
233
+ * Clear all items (useful for test cleanup)
234
+ */
235
+ clear(): void {
236
+ this.items.clear();
237
+ }
238
+
239
+ /**
240
+ * Get all items as array (useful for debugging)
241
+ */
242
+ getAll(): TDomain[] {
243
+ return Array.from(this.items.values());
244
+ }
245
+
246
+ /**
247
+ * Get items count
248
+ */
249
+ size(): number {
250
+ return this.items.size;
251
+ }
252
+ }
253
+
254
+ export { User, Post, Comment, Address, InMemoryRepository };
@@ -54,9 +54,6 @@ class Money extends ValueObject<MoneyProps> {
54
54
  };
55
55
 
56
56
  protected static hooks: VOHooks<MoneyProps, Money> = {
57
- defaultValues: {
58
- currency: "USD",
59
- },
60
57
  rules: (money) => {
61
58
  if (money.amount > 1000000) {
62
59
  throwValidationError("amount", "Amount cannot exceed 1,000,000");
@@ -135,12 +132,6 @@ describe("ValueObject with Validation", () => {
135
132
  expect(money.currency).toBe("USD");
136
133
  });
137
134
 
138
- it("should apply default currency", () => {
139
- const money = new Money({ amount: 50 } as any);
140
- expect(money.amount).toBe(50);
141
- expect(money.currency).toBe("USD");
142
- });
143
-
144
135
  it("should throw on negative amount", () => {
145
136
  expect(() => {
146
137
  new Money({ amount: -10, currency: "USD" });
package/tsconfig.json CHANGED
@@ -1,30 +1,8 @@
1
1
  {
2
+ "extends": "../../tsconfig.base.json",
2
3
  "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "lib": ["ES2020"],
6
- "declaration": true,
7
- "declarationMap": true,
8
- "sourceMap": true,
9
4
  "outDir": "./dist",
10
- "rootDir": "./src",
11
- "strict": true,
12
- "noImplicitAny": true,
13
- "strictNullChecks": true,
14
- "strictFunctionTypes": true,
15
- "strictBindCallApply": true,
16
- "strictPropertyInitialization": true,
17
- "noImplicitThis": true,
18
- "alwaysStrict": true,
19
- "noUnusedLocals": false,
20
- "noUnusedParameters": false,
21
- "noImplicitReturns": true,
22
- "noFallthroughCasesInSwitch": true,
23
- "moduleResolution": "node",
24
- "esModuleInterop": true,
25
- "skipLibCheck": true,
26
- "forceConsistentCasingInFileNames": true,
27
- "resolveJsonModule": true
5
+ "rootDir": "./src"
28
6
  },
29
7
  "include": ["src/**/*"],
30
8
  "exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
@@ -1,40 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- push:
5
- branches: [ main ]
6
- pull_request:
7
- branches: [ main ]
8
-
9
- jobs:
10
- test:
11
- runs-on: ubuntu-latest
12
-
13
- strategy:
14
- matrix:
15
- node-version: [20.x]
16
-
17
- steps:
18
- - name: Checkout code
19
- uses: actions/checkout@v4
20
-
21
- - name: Setup Node.js ${{ matrix.node-version }}
22
- uses: actions/setup-node@v4
23
- with:
24
- node-version: ${{ matrix.node-version }}
25
- cache: 'npm'
26
-
27
- - name: Install dependencies
28
- run: npm ci
29
-
30
- - name: Run linter
31
- run: npm run lint
32
-
33
- - name: Run type checking
34
- run: npx tsc --noEmit
35
-
36
- - name: Run tests
37
- run: npm test
38
-
39
- - name: Build
40
- run: npm run build
package/.husky/commit-msg DELETED
@@ -1 +0,0 @@
1
- npx --no -- commitlint --edit $1
package/.husky/pre-commit DELETED
@@ -1 +0,0 @@
1
- npm test
@@ -1,3 +0,0 @@
1
- {
2
- "typescript.tsdk": "node_modules\\typescript\\lib"
3
- }
@@ -1,23 +0,0 @@
1
- module.exports = {
2
- extends: ['@commitlint/config-conventional'],
3
- rules: {
4
- 'type-enum': [
5
- 2,
6
- 'always',
7
- [
8
- 'feat',
9
- 'fix',
10
- 'docs',
11
- 'style',
12
- 'refactor',
13
- 'perf',
14
- 'test',
15
- 'chore',
16
- 'revert',
17
- 'ci',
18
- 'build'
19
- ]
20
- ],
21
- 'subject-case': [0]
22
- }
23
- };
@@ -1,50 +0,0 @@
1
- import type { Aggregate } from "../entity";
2
- import type { Criteria } from "../criteria";
3
- import { PaginatedResult } from "../paginated-result";
4
- import { Repository } from "./base-repository";
5
- import { Mapper } from "../mapper";
6
- /**
7
- * In-memory repository implementation
8
- * Perfect for unit tests and prototyping
9
- *
10
- * @example
11
- * ```ts
12
- * const userRepo = new InMemoryRepository<User>();
13
- *
14
- * await userRepo.save(user);
15
- * const found = await userRepo.findById(user.id);
16
- * const active = await userRepo.find(
17
- * Criteria.create<User>().whereEquals('status', 'active')
18
- * );
19
- * ```
20
- */
21
- export declare class InMemoryRepository<TDomain extends Aggregate<any>> extends Repository<TDomain> {
22
- protected readonly mapperToDomain: Mapper<unknown, TDomain>;
23
- protected readonly mapperToPersistence: Mapper<TDomain, unknown>;
24
- protected items: Map<string, TDomain>;
25
- constructor(mapperToDomain: Mapper<unknown, TDomain>, mapperToPersistence: Mapper<TDomain, unknown>);
26
- get model(): any;
27
- findById(id: string): Promise<TDomain | null>;
28
- find(criteria: Criteria<TDomain>): Promise<PaginatedResult<TDomain>>;
29
- findAll(criteria?: Criteria<TDomain>): Promise<TDomain[]>;
30
- findOne(criteria: Criteria<TDomain>): Promise<TDomain | null>;
31
- create(aggregate: TDomain): Promise<void>;
32
- update(entity: TDomain): Promise<void>;
33
- createMany(aggregates: TDomain[]): Promise<void>;
34
- delete(aggregate: TDomain): Promise<void>;
35
- exists(id: string): Promise<boolean>;
36
- count(criteria?: Criteria<TDomain>): Promise<number>;
37
- /**
38
- * Clear all items (useful for test cleanup)
39
- */
40
- clear(): void;
41
- /**
42
- * Get all items as array (useful for debugging)
43
- */
44
- getAll(): TDomain[];
45
- /**
46
- * Get items count
47
- */
48
- size(): number;
49
- }
50
- //# sourceMappingURL=in-memory-repository.d.ts.map