@woltz/rich-domain 1.9.2 → 1.9.3

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 (122) hide show
  1. package/dist/cjs/constants.d.ts +1 -1
  2. package/dist/cjs/constants.d.ts.map +1 -1
  3. package/dist/cjs/core/base-entity.d.ts +2 -1
  4. package/dist/cjs/core/base-entity.d.ts.map +1 -1
  5. package/dist/cjs/core/base-entity.js +9 -7
  6. package/dist/cjs/core/base-entity.js.map +1 -1
  7. package/dist/cjs/core/change-tracker.d.ts +1 -0
  8. package/dist/cjs/core/change-tracker.d.ts.map +1 -1
  9. package/dist/cjs/core/change-tracker.js +24 -15
  10. package/dist/cjs/core/change-tracker.js.map +1 -1
  11. package/dist/cjs/core/domain-event.d.ts +1 -1
  12. package/dist/cjs/core/domain-event.d.ts.map +1 -1
  13. package/dist/cjs/core/domain-event.js +2 -2
  14. package/dist/cjs/core/domain-event.js.map +1 -1
  15. package/dist/cjs/core/entities.d.ts +8 -0
  16. package/dist/cjs/core/entities.d.ts.map +1 -0
  17. package/dist/cjs/core/entities.js +12 -0
  18. package/dist/cjs/core/entities.js.map +1 -0
  19. package/dist/cjs/core/index.d.ts +9 -9
  20. package/dist/cjs/core/index.d.ts.map +1 -1
  21. package/dist/cjs/core/index.js +9 -9
  22. package/dist/cjs/core/index.js.map +1 -1
  23. package/dist/cjs/repository/base-repository.d.ts +1 -1
  24. package/dist/cjs/repository/base-repository.d.ts.map +1 -1
  25. package/dist/cjs/repository/entity-schema-registry.d.ts +1 -1
  26. package/dist/cjs/repository/entity-schema-registry.d.ts.map +1 -1
  27. package/dist/cjs/repository/entity-schema-registry.js +5 -5
  28. package/dist/cjs/repository/entity-schema-registry.js.map +1 -1
  29. package/dist/cjs/types/change-tracker.d.ts +1 -1
  30. package/dist/cjs/types/change-tracker.d.ts.map +1 -1
  31. package/dist/cjs/types/domain.d.ts +1 -1
  32. package/dist/cjs/types/domain.d.ts.map +1 -1
  33. package/dist/cjs/types/event-bus.d.ts +1 -1
  34. package/dist/cjs/types/event-bus.d.ts.map +1 -1
  35. package/dist/cjs/types/unit-of-work.d.ts +2 -2
  36. package/dist/cjs/types/unit-of-work.d.ts.map +1 -1
  37. package/dist/cjs/types/utils.d.ts +1 -1
  38. package/dist/cjs/types/utils.d.ts.map +1 -1
  39. package/dist/esm/constants.d.ts +1 -1
  40. package/dist/esm/constants.d.ts.map +1 -1
  41. package/dist/esm/core/base-entity.d.ts +2 -1
  42. package/dist/esm/core/base-entity.d.ts.map +1 -1
  43. package/dist/esm/core/base-entity.js +3 -1
  44. package/dist/esm/core/base-entity.js.map +1 -1
  45. package/dist/esm/core/change-tracker.d.ts +1 -0
  46. package/dist/esm/core/change-tracker.d.ts.map +1 -1
  47. package/dist/esm/core/change-tracker.js +24 -15
  48. package/dist/esm/core/change-tracker.js.map +1 -1
  49. package/dist/esm/core/domain-event.d.ts +1 -1
  50. package/dist/esm/core/domain-event.d.ts.map +1 -1
  51. package/dist/esm/core/domain-event.js +1 -1
  52. package/dist/esm/core/domain-event.js.map +1 -1
  53. package/dist/esm/core/entities.d.ts +8 -0
  54. package/dist/esm/core/entities.d.ts.map +1 -0
  55. package/dist/esm/core/entities.js +7 -0
  56. package/dist/esm/core/entities.js.map +1 -0
  57. package/dist/esm/core/index.d.ts +9 -9
  58. package/dist/esm/core/index.d.ts.map +1 -1
  59. package/dist/esm/core/index.js +9 -9
  60. package/dist/esm/core/index.js.map +1 -1
  61. package/dist/esm/repository/base-repository.d.ts +1 -1
  62. package/dist/esm/repository/base-repository.d.ts.map +1 -1
  63. package/dist/esm/repository/entity-schema-registry.d.ts +1 -1
  64. package/dist/esm/repository/entity-schema-registry.d.ts.map +1 -1
  65. package/dist/esm/repository/entity-schema-registry.js +1 -1
  66. package/dist/esm/repository/entity-schema-registry.js.map +1 -1
  67. package/dist/esm/types/change-tracker.d.ts +1 -1
  68. package/dist/esm/types/change-tracker.d.ts.map +1 -1
  69. package/dist/esm/types/domain.d.ts +1 -1
  70. package/dist/esm/types/domain.d.ts.map +1 -1
  71. package/dist/esm/types/event-bus.d.ts +1 -1
  72. package/dist/esm/types/event-bus.d.ts.map +1 -1
  73. package/dist/esm/types/unit-of-work.d.ts +2 -2
  74. package/dist/esm/types/unit-of-work.d.ts.map +1 -1
  75. package/dist/esm/types/utils.d.ts +1 -1
  76. package/dist/esm/types/utils.d.ts.map +1 -1
  77. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  78. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  79. package/dist/tsconfig.types.tsbuildinfo +1 -1
  80. package/dist/types/constants.d.ts +1 -1
  81. package/dist/types/constants.d.ts.map +1 -1
  82. package/dist/types/core/base-entity.d.ts +2 -1
  83. package/dist/types/core/base-entity.d.ts.map +1 -1
  84. package/dist/types/core/change-tracker.d.ts +1 -0
  85. package/dist/types/core/change-tracker.d.ts.map +1 -1
  86. package/dist/types/core/domain-event.d.ts +1 -1
  87. package/dist/types/core/domain-event.d.ts.map +1 -1
  88. package/dist/types/core/entities.d.ts +8 -0
  89. package/dist/types/core/entities.d.ts.map +1 -0
  90. package/dist/types/core/index.d.ts +9 -9
  91. package/dist/types/core/index.d.ts.map +1 -1
  92. package/dist/types/repository/base-repository.d.ts +1 -1
  93. package/dist/types/repository/base-repository.d.ts.map +1 -1
  94. package/dist/types/repository/entity-schema-registry.d.ts +1 -1
  95. package/dist/types/repository/entity-schema-registry.d.ts.map +1 -1
  96. package/dist/types/types/change-tracker.d.ts +1 -1
  97. package/dist/types/types/change-tracker.d.ts.map +1 -1
  98. package/dist/types/types/domain.d.ts +1 -1
  99. package/dist/types/types/domain.d.ts.map +1 -1
  100. package/dist/types/types/event-bus.d.ts +1 -1
  101. package/dist/types/types/event-bus.d.ts.map +1 -1
  102. package/dist/types/types/unit-of-work.d.ts +2 -2
  103. package/dist/types/types/unit-of-work.d.ts.map +1 -1
  104. package/dist/types/types/utils.d.ts +1 -1
  105. package/dist/types/types/utils.d.ts.map +1 -1
  106. package/package.json +68 -68
  107. package/src/constants.ts +82 -82
  108. package/src/core/aggregate-changes.ts +466 -466
  109. package/src/core/base-entity.ts +4 -1
  110. package/src/core/change-tracker.ts +30 -16
  111. package/src/core/domain-event.ts +41 -41
  112. package/src/core/{entity.ts → entities.ts} +13 -13
  113. package/src/core/index.ts +9 -9
  114. package/src/core/value-object.ts +179 -179
  115. package/src/repository/base-repository.ts +81 -81
  116. package/src/repository/entity-schema-registry.ts +1 -1
  117. package/src/types/change-tracker.ts +268 -268
  118. package/src/types/domain.ts +41 -41
  119. package/src/types/event-bus.ts +17 -17
  120. package/src/types/unit-of-work.ts +46 -46
  121. package/src/types/utils.ts +24 -24
  122. package/src/utils/helpers.ts +50 -50
@@ -1,268 +1,268 @@
1
- import { Entity, ValueObject } from "../core/index";
2
-
3
- /**
4
- * Base operation with common information.
5
- */
6
- export interface BaseOperation {
7
- /** Entity name in the domain (e.g., 'User', 'Post', 'Comment') */
8
- entity: string;
9
- /** Depth in the aggregate tree (0 = root, 1 = direct children, etc.) */
10
- depth: number;
11
- /** Name of the relation field in the parent entity (e.g., 'tags', 'comments') */
12
- relationField?: string;
13
- }
14
-
15
- /**
16
- * Create operation.
17
- */
18
- export interface CreateOperation<T = any> extends BaseOperation {
19
- type: "create";
20
- /** Entity data to be created */
21
- data: T;
22
- /** Parent ID (for FK) */
23
- parentId?: string;
24
- /** Parent entity name */
25
- parentEntity?: string;
26
- }
27
-
28
- /**
29
- * Update operation.
30
- */
31
- export interface UpdateOperation<T = any> extends BaseOperation {
32
- type: "update";
33
- /** Entity ID */
34
- id: string;
35
- /** Current entity instance */
36
- data: T;
37
- /** Only fields that have changed */
38
- changedFields: Record<string, any>;
39
- }
40
-
41
- /**
42
- * Delete operation.
43
- */
44
- export interface DeleteOperation<T = any> extends BaseOperation {
45
- type: "delete";
46
- /** Entity ID to be deleted */
47
- id: string;
48
- /** Entity data (for reference) */
49
- data: T;
50
- /** Parent entity name */
51
- parentEntity?: string;
52
- /** Parent ID */
53
- parentId?: string;
54
- }
55
-
56
- /**
57
- * Union of all possible operations.
58
- */
59
- export type Operation<T = any> =
60
- | CreateOperation<T>
61
- | UpdateOperation<T>
62
- | DeleteOperation<T>;
63
-
64
- /**
65
- * Item for batch creation.
66
- */
67
- export interface BatchCreateItem<T = any> {
68
- /** Entity data */
69
- data: T;
70
- /** Parent ID (for FK) */
71
- parentId?: string;
72
- /** Parent entity name */
73
- parentEntity?: string;
74
- /** Relation field name */
75
- relationField?: string;
76
- }
77
-
78
- /**
79
- * Item for batch update.
80
- */
81
- export interface BatchUpdateItem {
82
- /** Entity ID */
83
- id: string;
84
- /** Fields that have changed */
85
- changedFields: Record<string, any>;
86
- }
87
-
88
- /**
89
- * Item for batch delete.
90
- */
91
- export interface BatchDeleteItem {
92
- /** Entity ID */
93
- id: string;
94
- /** Relation field name */
95
- relationField?: string;
96
- }
97
-
98
- export interface BatchDeleteOperation {
99
- entity: string;
100
- depth: number;
101
- ids: string[];
102
- parentId?: string;
103
- /** Relation field name (for determining owned vs reference) */
104
- relationField?: string;
105
- /** Parent entity name */
106
- parentEntity?: string;
107
- /** Individual items with their relation fields (when mixed) */
108
- items?: BatchDeleteItem[];
109
- }
110
-
111
- export interface BatchCreateOperation {
112
- entity: string;
113
- depth: number;
114
- items: BatchCreateItem[];
115
- /** Relation field name (for determining owned vs reference) */
116
- relationField?: string;
117
- /** Parent entity name */
118
- parentEntity?: string;
119
- }
120
-
121
- export interface BatchUpdateOperation {
122
- entity: string;
123
- items: BatchUpdateItem[];
124
- }
125
-
126
- /**
127
- * Grouped and ordered operations for batch execution.
128
- */
129
- export interface BatchOperations {
130
- /**
131
- * Deletes grouped by entity, ordered by depth descending (leaf → root).
132
- */
133
- deletes: Array<BatchDeleteOperation>;
134
-
135
- /**
136
- * Creates grouped by entity, ordered by depth ascending (root → leaf).
137
- */
138
- creates: Array<BatchCreateOperation>;
139
-
140
- /**
141
- * Updates grouped by entity.
142
- */
143
- updates: Array<BatchUpdateOperation>;
144
- }
145
-
146
- /**
147
- * Changes detected in a collection (1:N).
148
- */
149
- export interface CollectionChanges<T = any> {
150
- /** Created items */
151
- created: T[];
152
- /** Updated items with their changes */
153
- updated: Array<{
154
- entity: T;
155
- changes: Record<string, { from: any; to: any }>;
156
- }>;
157
- /** Deleted items */
158
- deleted: T[];
159
- }
160
-
161
- /**
162
- * Possible states for a 1:1 relationship.
163
- */
164
- export type EntityChangeState =
165
- | "created" // null → Entity
166
- | "updated" // Entity(id:1) → Entity(id:1) with changes
167
- | "deleted" // Entity → null
168
- | "replaced" // Entity(id:1) → Entity(id:2)
169
- | "unchanged"; // No changes
170
-
171
- /**
172
- * Change in a 1:1 entity relationship.
173
- */
174
- export interface EntityChange<T = any> {
175
- /** State of the change */
176
- state: EntityChangeState;
177
- /** Current entity (null if deleted) */
178
- current: T | null;
179
- /** Previous entity (null if created) */
180
- previous: T | null;
181
- /** Field changes (if state === 'updated') */
182
- changes?: Record<string, { from: any; to: any }>;
183
- }
184
-
185
- /**
186
- * Change in a primitive field.
187
- */
188
- export interface FieldChange<T = any> {
189
- from: T;
190
- to: T;
191
- }
192
-
193
- /**
194
- * Extracts the props type from an Entity or ValueObject.
195
- */
196
- export type ExtractProps<T> =
197
- T extends Entity<infer P> ? P : T extends ValueObject<infer P> ? P : never;
198
-
199
- /**
200
- * Keys of primitive properties (not Entity, ValueObject or Array).
201
- */
202
- export type PrimitiveKeys<T> = {
203
- [K in keyof T]: T[K] extends
204
- | Entity<any>
205
- | ValueObject<any>
206
- | Array<any>
207
- | undefined
208
- ? never
209
- : K;
210
- }[keyof T];
211
-
212
- /**
213
- * Keys of collections (arrays).
214
- */
215
- export type CollectionKeys<T> = {
216
- [K in keyof T]: T[K] extends Array<any> ? K : never;
217
- }[keyof T];
218
-
219
- /**
220
- * Keys of single entities (1:1).
221
- */
222
- export type SingleEntityKeys<T> = {
223
- [K in keyof T]: T[K] extends Entity<any> | ValueObject<any> | null | undefined
224
- ? T[K] extends Array<any>
225
- ? never
226
- : K
227
- : never;
228
- }[keyof T];
229
-
230
- /**
231
- * Change history entry.
232
- */
233
- export interface HistoryEntry {
234
- path: string;
235
- previousValue: any;
236
- currentValue: any;
237
- timestamp: number;
238
- }
239
-
240
- /**
241
- * Metadata from a tracked entity/VO.
242
- */
243
- export interface TrackedEntityMetadata {
244
- /** Entity name */
245
- entityName: string;
246
- /** Depth in the tree */
247
- depth: number;
248
- /** Parent ID */
249
- parentId?: string;
250
- /** Parent entity name */
251
- parentEntity?: string;
252
- /** Path in the object (e.g., 'posts[0].comments[1]') */
253
- path: string;
254
- }
255
-
256
- export interface TrackedItem {
257
- entity: any;
258
- metadata: TrackedEntityMetadata;
259
- originalState: any;
260
- }
261
-
262
- export interface ArrayState {
263
- cloned: any[];
264
- original: any[];
265
- metadata: TrackedEntityMetadata;
266
- /** Indicates if array contains only primitive values (string, number, boolean, etc.) */
267
- isPrimitiveArray?: boolean;
268
- }
1
+ import { Entity, ValueObject } from "../core/index.js";
2
+
3
+ /**
4
+ * Base operation with common information.
5
+ */
6
+ export interface BaseOperation {
7
+ /** Entity name in the domain (e.g., 'User', 'Post', 'Comment') */
8
+ entity: string;
9
+ /** Depth in the aggregate tree (0 = root, 1 = direct children, etc.) */
10
+ depth: number;
11
+ /** Name of the relation field in the parent entity (e.g., 'tags', 'comments') */
12
+ relationField?: string;
13
+ }
14
+
15
+ /**
16
+ * Create operation.
17
+ */
18
+ export interface CreateOperation<T = any> extends BaseOperation {
19
+ type: "create";
20
+ /** Entity data to be created */
21
+ data: T;
22
+ /** Parent ID (for FK) */
23
+ parentId?: string;
24
+ /** Parent entity name */
25
+ parentEntity?: string;
26
+ }
27
+
28
+ /**
29
+ * Update operation.
30
+ */
31
+ export interface UpdateOperation<T = any> extends BaseOperation {
32
+ type: "update";
33
+ /** Entity ID */
34
+ id: string;
35
+ /** Current entity instance */
36
+ data: T;
37
+ /** Only fields that have changed */
38
+ changedFields: Record<string, any>;
39
+ }
40
+
41
+ /**
42
+ * Delete operation.
43
+ */
44
+ export interface DeleteOperation<T = any> extends BaseOperation {
45
+ type: "delete";
46
+ /** Entity ID to be deleted */
47
+ id: string;
48
+ /** Entity data (for reference) */
49
+ data: T;
50
+ /** Parent entity name */
51
+ parentEntity?: string;
52
+ /** Parent ID */
53
+ parentId?: string;
54
+ }
55
+
56
+ /**
57
+ * Union of all possible operations.
58
+ */
59
+ export type Operation<T = any> =
60
+ | CreateOperation<T>
61
+ | UpdateOperation<T>
62
+ | DeleteOperation<T>;
63
+
64
+ /**
65
+ * Item for batch creation.
66
+ */
67
+ export interface BatchCreateItem<T = any> {
68
+ /** Entity data */
69
+ data: T;
70
+ /** Parent ID (for FK) */
71
+ parentId?: string;
72
+ /** Parent entity name */
73
+ parentEntity?: string;
74
+ /** Relation field name */
75
+ relationField?: string;
76
+ }
77
+
78
+ /**
79
+ * Item for batch update.
80
+ */
81
+ export interface BatchUpdateItem {
82
+ /** Entity ID */
83
+ id: string;
84
+ /** Fields that have changed */
85
+ changedFields: Record<string, any>;
86
+ }
87
+
88
+ /**
89
+ * Item for batch delete.
90
+ */
91
+ export interface BatchDeleteItem {
92
+ /** Entity ID */
93
+ id: string;
94
+ /** Relation field name */
95
+ relationField?: string;
96
+ }
97
+
98
+ export interface BatchDeleteOperation {
99
+ entity: string;
100
+ depth: number;
101
+ ids: string[];
102
+ parentId?: string;
103
+ /** Relation field name (for determining owned vs reference) */
104
+ relationField?: string;
105
+ /** Parent entity name */
106
+ parentEntity?: string;
107
+ /** Individual items with their relation fields (when mixed) */
108
+ items?: BatchDeleteItem[];
109
+ }
110
+
111
+ export interface BatchCreateOperation {
112
+ entity: string;
113
+ depth: number;
114
+ items: BatchCreateItem[];
115
+ /** Relation field name (for determining owned vs reference) */
116
+ relationField?: string;
117
+ /** Parent entity name */
118
+ parentEntity?: string;
119
+ }
120
+
121
+ export interface BatchUpdateOperation {
122
+ entity: string;
123
+ items: BatchUpdateItem[];
124
+ }
125
+
126
+ /**
127
+ * Grouped and ordered operations for batch execution.
128
+ */
129
+ export interface BatchOperations {
130
+ /**
131
+ * Deletes grouped by entity, ordered by depth descending (leaf → root).
132
+ */
133
+ deletes: Array<BatchDeleteOperation>;
134
+
135
+ /**
136
+ * Creates grouped by entity, ordered by depth ascending (root → leaf).
137
+ */
138
+ creates: Array<BatchCreateOperation>;
139
+
140
+ /**
141
+ * Updates grouped by entity.
142
+ */
143
+ updates: Array<BatchUpdateOperation>;
144
+ }
145
+
146
+ /**
147
+ * Changes detected in a collection (1:N).
148
+ */
149
+ export interface CollectionChanges<T = any> {
150
+ /** Created items */
151
+ created: T[];
152
+ /** Updated items with their changes */
153
+ updated: Array<{
154
+ entity: T;
155
+ changes: Record<string, { from: any; to: any }>;
156
+ }>;
157
+ /** Deleted items */
158
+ deleted: T[];
159
+ }
160
+
161
+ /**
162
+ * Possible states for a 1:1 relationship.
163
+ */
164
+ export type EntityChangeState =
165
+ | "created" // null → Entity
166
+ | "updated" // Entity(id:1) → Entity(id:1) with changes
167
+ | "deleted" // Entity → null
168
+ | "replaced" // Entity(id:1) → Entity(id:2)
169
+ | "unchanged"; // No changes
170
+
171
+ /**
172
+ * Change in a 1:1 entity relationship.
173
+ */
174
+ export interface EntityChange<T = any> {
175
+ /** State of the change */
176
+ state: EntityChangeState;
177
+ /** Current entity (null if deleted) */
178
+ current: T | null;
179
+ /** Previous entity (null if created) */
180
+ previous: T | null;
181
+ /** Field changes (if state === 'updated') */
182
+ changes?: Record<string, { from: any; to: any }>;
183
+ }
184
+
185
+ /**
186
+ * Change in a primitive field.
187
+ */
188
+ export interface FieldChange<T = any> {
189
+ from: T;
190
+ to: T;
191
+ }
192
+
193
+ /**
194
+ * Extracts the props type from an Entity or ValueObject.
195
+ */
196
+ export type ExtractProps<T> =
197
+ T extends Entity<infer P> ? P : T extends ValueObject<infer P> ? P : never;
198
+
199
+ /**
200
+ * Keys of primitive properties (not Entity, ValueObject or Array).
201
+ */
202
+ export type PrimitiveKeys<T> = {
203
+ [K in keyof T]: T[K] extends
204
+ | Entity<any>
205
+ | ValueObject<any>
206
+ | Array<any>
207
+ | undefined
208
+ ? never
209
+ : K;
210
+ }[keyof T];
211
+
212
+ /**
213
+ * Keys of collections (arrays).
214
+ */
215
+ export type CollectionKeys<T> = {
216
+ [K in keyof T]: T[K] extends Array<any> ? K : never;
217
+ }[keyof T];
218
+
219
+ /**
220
+ * Keys of single entities (1:1).
221
+ */
222
+ export type SingleEntityKeys<T> = {
223
+ [K in keyof T]: T[K] extends Entity<any> | ValueObject<any> | null | undefined
224
+ ? T[K] extends Array<any>
225
+ ? never
226
+ : K
227
+ : never;
228
+ }[keyof T];
229
+
230
+ /**
231
+ * Change history entry.
232
+ */
233
+ export interface HistoryEntry {
234
+ path: string;
235
+ previousValue: any;
236
+ currentValue: any;
237
+ timestamp: number;
238
+ }
239
+
240
+ /**
241
+ * Metadata from a tracked entity/VO.
242
+ */
243
+ export interface TrackedEntityMetadata {
244
+ /** Entity name */
245
+ entityName: string;
246
+ /** Depth in the tree */
247
+ depth: number;
248
+ /** Parent ID */
249
+ parentId?: string;
250
+ /** Parent entity name */
251
+ parentEntity?: string;
252
+ /** Path in the object (e.g., 'posts[0].comments[1]') */
253
+ path: string;
254
+ }
255
+
256
+ export interface TrackedItem {
257
+ entity: any;
258
+ metadata: TrackedEntityMetadata;
259
+ originalState: any;
260
+ }
261
+
262
+ export interface ArrayState {
263
+ cloned: any[];
264
+ original: any[];
265
+ metadata: TrackedEntityMetadata;
266
+ /** Indicates if array contains only primitive values (string, number, boolean, etc.) */
267
+ isPrimitiveArray?: boolean;
268
+ }
@@ -1,41 +1,41 @@
1
- import { Id } from "../core/index";
2
- import { StandardSchema } from "./standard-schema.js";
3
-
4
- export interface BaseProps {
5
- id: Id;
6
- }
7
-
8
- interface DomainValidation<T> {
9
- schema: StandardSchema<T>;
10
- config?: ValidationConfig;
11
- }
12
-
13
- export type EntityValidation<T> = DomainValidation<T>;
14
- export type VOValidation<T> = DomainValidation<T>;
15
-
16
- export interface VOHooks<V, VO> {
17
- onBeforeCreate?: (value: V) => void;
18
- rules?: (valueObject: VO) => void;
19
- }
20
-
21
- export interface EntityHooks<T extends BaseProps, E> {
22
- onBeforeCreate?: (props: T) => void;
23
- onBeforeUpdate?: (entity: E, snapshot: T) => boolean;
24
- onCreate?: (entity: E) => void;
25
- rules?: (entity: E) => void;
26
- }
27
-
28
- export interface ValidationConfig {
29
- /** When true, validates the entity on creation. Default: true */
30
- onCreate?: boolean;
31
- /** When true, validates the entity on update. Default: true */
32
- onUpdate?: boolean;
33
- /** When true, throws a ValidationError when validation fails. Default: true */
34
- throwOnError?: boolean;
35
- /**
36
- * When `throwOnError` is `false`, controls whether invalid updates are kept on the entity.
37
- * - `true` (default): apply mutations and refresh `validationErrors` (dirty / form mode).
38
- * - `false`: block mutations when errors already exist, and revert updates that fail validation.
39
- */
40
- persistInvalidMutations?: boolean;
41
- }
1
+ import { Id } from "../core/index.js";
2
+ import { StandardSchema } from "./standard-schema.js";
3
+
4
+ export interface BaseProps {
5
+ id: Id;
6
+ }
7
+
8
+ interface DomainValidation<T> {
9
+ schema: StandardSchema<T>;
10
+ config?: ValidationConfig;
11
+ }
12
+
13
+ export type EntityValidation<T> = DomainValidation<T>;
14
+ export type VOValidation<T> = DomainValidation<T>;
15
+
16
+ export interface VOHooks<V, VO> {
17
+ onBeforeCreate?: (value: V) => void;
18
+ rules?: (valueObject: VO) => void;
19
+ }
20
+
21
+ export interface EntityHooks<T extends BaseProps, E> {
22
+ onBeforeCreate?: (props: T) => void;
23
+ onBeforeUpdate?: (entity: E, snapshot: T) => boolean;
24
+ onCreate?: (entity: E) => void;
25
+ rules?: (entity: E) => void;
26
+ }
27
+
28
+ export interface ValidationConfig {
29
+ /** When true, validates the entity on creation. Default: true */
30
+ onCreate?: boolean;
31
+ /** When true, validates the entity on update. Default: true */
32
+ onUpdate?: boolean;
33
+ /** When true, throws a ValidationError when validation fails. Default: true */
34
+ throwOnError?: boolean;
35
+ /**
36
+ * When `throwOnError` is `false`, controls whether invalid updates are kept on the entity.
37
+ * - `true` (default): apply mutations and refresh `validationErrors` (dirty / form mode).
38
+ * - `false`: block mutations when errors already exist, and revert updates that fail validation.
39
+ */
40
+ persistInvalidMutations?: boolean;
41
+ }
@@ -1,17 +1,17 @@
1
- import { IDomainEvent } from "./domain-event";
2
-
3
- export interface IDomainEventBus {
4
- /**
5
- * Publish a single domain event.
6
- *
7
- * @param event - The domain event to publish
8
- */
9
- publish(event: IDomainEvent): Promise<void>;
10
-
11
- /**
12
- * Publish multiple domain events.
13
- *
14
- * @param events - Array of domain events to publish
15
- */
16
- publishAll(events: IDomainEvent[]): Promise<void>;
17
- }
1
+ import type { IDomainEvent } from "./domain-event.js";
2
+
3
+ export interface IDomainEventBus {
4
+ /**
5
+ * Publish a single domain event.
6
+ *
7
+ * @param event - The domain event to publish
8
+ */
9
+ publish(event: IDomainEvent): Promise<void>;
10
+
11
+ /**
12
+ * Publish multiple domain events.
13
+ *
14
+ * @param events - Array of domain events to publish
15
+ */
16
+ publishAll(events: IDomainEvent[]): Promise<void>;
17
+ }