@woltz/rich-domain 1.7.0 → 1.8.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 (204) hide show
  1. package/dist/cjs/core/aggregate-changes.d.ts +206 -0
  2. package/dist/cjs/core/aggregate-changes.d.ts.map +1 -0
  3. package/dist/cjs/core/aggregate-changes.js +365 -0
  4. package/dist/cjs/core/aggregate-changes.js.map +1 -0
  5. package/dist/cjs/core/base-entity.d.ts +88 -0
  6. package/dist/cjs/core/base-entity.d.ts.map +1 -0
  7. package/dist/cjs/core/base-entity.js +329 -0
  8. package/dist/cjs/core/base-entity.js.map +1 -0
  9. package/dist/cjs/core/change-tracker.d.ts +96 -0
  10. package/dist/cjs/core/change-tracker.d.ts.map +1 -0
  11. package/dist/cjs/core/change-tracker.js +789 -0
  12. package/dist/cjs/core/change-tracker.js.map +1 -0
  13. package/dist/cjs/core/domain-event.d.ts +23 -0
  14. package/dist/cjs/core/domain-event.d.ts.map +1 -0
  15. package/dist/cjs/core/domain-event.js +36 -0
  16. package/dist/cjs/core/domain-event.js.map +1 -0
  17. package/dist/cjs/core/entity-changes.d.ts +84 -0
  18. package/dist/cjs/core/entity-changes.d.ts.map +1 -0
  19. package/dist/cjs/core/entity-changes.js +136 -0
  20. package/dist/cjs/core/entity-changes.js.map +1 -0
  21. package/dist/cjs/core/entity.d.ts +7 -0
  22. package/dist/cjs/core/entity.d.ts.map +1 -0
  23. package/dist/cjs/core/entity.js +11 -0
  24. package/dist/cjs/core/entity.js.map +1 -0
  25. package/dist/cjs/core/id.d.ts +59 -0
  26. package/dist/cjs/core/id.d.ts.map +1 -0
  27. package/dist/cjs/core/id.js +92 -0
  28. package/dist/cjs/core/id.js.map +1 -0
  29. package/dist/cjs/core/index.d.ts +9 -0
  30. package/dist/cjs/core/index.d.ts.map +1 -0
  31. package/dist/cjs/core/index.js +25 -0
  32. package/dist/cjs/core/index.js.map +1 -0
  33. package/dist/cjs/core/value-object.d.ts +49 -0
  34. package/dist/cjs/core/value-object.d.ts.map +1 -0
  35. package/dist/cjs/core/value-object.js +129 -0
  36. package/dist/cjs/core/value-object.js.map +1 -0
  37. package/dist/cjs/index.d.ts +5 -11
  38. package/dist/cjs/index.d.ts.map +1 -1
  39. package/dist/cjs/index.js +21 -19
  40. package/dist/cjs/index.js.map +1 -1
  41. package/dist/cjs/repository/base-repository.d.ts +49 -3
  42. package/dist/cjs/repository/base-repository.d.ts.map +1 -1
  43. package/dist/cjs/repository/base-repository.js.map +1 -1
  44. package/dist/cjs/repository/entity-schema-registry.d.ts +281 -0
  45. package/dist/cjs/repository/entity-schema-registry.d.ts.map +1 -0
  46. package/dist/cjs/repository/entity-schema-registry.js +370 -0
  47. package/dist/cjs/repository/entity-schema-registry.js.map +1 -0
  48. package/dist/cjs/repository/index.d.ts +4 -2
  49. package/dist/cjs/repository/index.d.ts.map +1 -1
  50. package/dist/cjs/repository/index.js +4 -6
  51. package/dist/cjs/repository/index.js.map +1 -1
  52. package/dist/cjs/repository/mapper.d.ts +4 -0
  53. package/dist/cjs/repository/mapper.d.ts.map +1 -0
  54. package/dist/cjs/repository/mapper.js +7 -0
  55. package/dist/cjs/repository/mapper.js.map +1 -0
  56. package/dist/cjs/repository/paginated-result.d.ts +54 -0
  57. package/dist/cjs/repository/paginated-result.d.ts.map +1 -0
  58. package/dist/cjs/repository/paginated-result.js +197 -0
  59. package/dist/cjs/repository/paginated-result.js.map +1 -0
  60. package/dist/cjs/types/change-tracker.d.ts +1 -2
  61. package/dist/cjs/types/change-tracker.d.ts.map +1 -1
  62. package/dist/cjs/types/criteria.d.ts +13 -5
  63. package/dist/cjs/types/criteria.d.ts.map +1 -1
  64. package/dist/cjs/types/criteria.js +2 -2
  65. package/dist/cjs/types/criteria.js.map +1 -1
  66. package/dist/cjs/types/domain.d.ts +1 -1
  67. package/dist/cjs/types/domain.d.ts.map +1 -1
  68. package/dist/cjs/types/unit-of-work.d.ts +1 -1
  69. package/dist/cjs/types/unit-of-work.d.ts.map +1 -1
  70. package/dist/cjs/types/utils.d.ts +1 -2
  71. package/dist/cjs/types/utils.d.ts.map +1 -1
  72. package/dist/cjs/utils/criteria-operator-validation.d.ts.map +1 -1
  73. package/dist/cjs/utils/criteria-operator-validation.js +1 -1
  74. package/dist/cjs/utils/criteria-operator-validation.js.map +1 -1
  75. package/dist/cjs/utils/crypto.d.ts +3 -0
  76. package/dist/cjs/utils/crypto.d.ts.map +1 -0
  77. package/dist/cjs/utils/crypto.js +32 -0
  78. package/dist/cjs/utils/crypto.js.map +1 -0
  79. package/dist/esm/core/aggregate-changes.d.ts +206 -0
  80. package/dist/esm/core/aggregate-changes.d.ts.map +1 -0
  81. package/dist/esm/core/aggregate-changes.js +361 -0
  82. package/dist/esm/core/aggregate-changes.js.map +1 -0
  83. package/dist/esm/core/base-entity.d.ts +88 -0
  84. package/dist/esm/core/base-entity.d.ts.map +1 -0
  85. package/dist/esm/core/base-entity.js +325 -0
  86. package/dist/esm/core/base-entity.js.map +1 -0
  87. package/dist/esm/core/change-tracker.d.ts +96 -0
  88. package/dist/esm/core/change-tracker.d.ts.map +1 -0
  89. package/dist/esm/core/change-tracker.js +785 -0
  90. package/dist/esm/core/change-tracker.js.map +1 -0
  91. package/dist/esm/core/domain-event.d.ts +23 -0
  92. package/dist/esm/core/domain-event.d.ts.map +1 -0
  93. package/dist/esm/core/domain-event.js +32 -0
  94. package/dist/esm/core/domain-event.js.map +1 -0
  95. package/dist/esm/core/entity-changes.d.ts +84 -0
  96. package/dist/esm/core/entity-changes.d.ts.map +1 -0
  97. package/dist/esm/core/entity-changes.js +132 -0
  98. package/dist/esm/core/entity-changes.js.map +1 -0
  99. package/dist/esm/core/entity.d.ts +7 -0
  100. package/dist/esm/core/entity.d.ts.map +1 -0
  101. package/dist/esm/core/entity.js +6 -0
  102. package/dist/esm/core/entity.js.map +1 -0
  103. package/dist/esm/core/id.d.ts +59 -0
  104. package/dist/esm/core/id.d.ts.map +1 -0
  105. package/dist/esm/core/id.js +85 -0
  106. package/dist/esm/core/id.js.map +1 -0
  107. package/dist/esm/core/index.d.ts +9 -0
  108. package/dist/esm/core/index.d.ts.map +1 -0
  109. package/dist/esm/core/index.js +9 -0
  110. package/dist/esm/core/index.js.map +1 -0
  111. package/dist/esm/core/value-object.d.ts +49 -0
  112. package/dist/esm/core/value-object.d.ts.map +1 -0
  113. package/dist/esm/core/value-object.js +125 -0
  114. package/dist/esm/core/value-object.js.map +1 -0
  115. package/dist/esm/index.d.ts +5 -11
  116. package/dist/esm/index.d.ts.map +1 -1
  117. package/dist/esm/index.js +4 -10
  118. package/dist/esm/index.js.map +1 -1
  119. package/dist/esm/repository/base-repository.d.ts +49 -3
  120. package/dist/esm/repository/base-repository.d.ts.map +1 -1
  121. package/dist/esm/repository/base-repository.js.map +1 -1
  122. package/dist/esm/repository/entity-schema-registry.d.ts +281 -0
  123. package/dist/esm/repository/entity-schema-registry.d.ts.map +1 -0
  124. package/dist/esm/repository/entity-schema-registry.js +366 -0
  125. package/dist/esm/repository/entity-schema-registry.js.map +1 -0
  126. package/dist/esm/repository/index.d.ts +4 -2
  127. package/dist/esm/repository/index.d.ts.map +1 -1
  128. package/dist/esm/repository/index.js +4 -2
  129. package/dist/esm/repository/index.js.map +1 -1
  130. package/dist/esm/repository/mapper.d.ts +4 -0
  131. package/dist/esm/repository/mapper.d.ts.map +1 -0
  132. package/dist/esm/repository/mapper.js +3 -0
  133. package/dist/esm/repository/mapper.js.map +1 -0
  134. package/dist/esm/repository/paginated-result.d.ts +54 -0
  135. package/dist/esm/repository/paginated-result.d.ts.map +1 -0
  136. package/dist/esm/repository/paginated-result.js +193 -0
  137. package/dist/esm/repository/paginated-result.js.map +1 -0
  138. package/dist/esm/types/change-tracker.d.ts +1 -2
  139. package/dist/esm/types/change-tracker.d.ts.map +1 -1
  140. package/dist/esm/types/criteria.d.ts +13 -5
  141. package/dist/esm/types/criteria.d.ts.map +1 -1
  142. package/dist/esm/types/criteria.js +3 -1
  143. package/dist/esm/types/criteria.js.map +1 -1
  144. package/dist/esm/types/domain.d.ts +1 -1
  145. package/dist/esm/types/domain.d.ts.map +1 -1
  146. package/dist/esm/types/unit-of-work.d.ts +1 -1
  147. package/dist/esm/types/unit-of-work.d.ts.map +1 -1
  148. package/dist/esm/types/utils.d.ts +1 -2
  149. package/dist/esm/types/utils.d.ts.map +1 -1
  150. package/dist/esm/utils/criteria-operator-validation.d.ts.map +1 -1
  151. package/dist/esm/utils/criteria-operator-validation.js +1 -1
  152. package/dist/esm/utils/criteria-operator-validation.js.map +1 -1
  153. package/dist/esm/utils/crypto.d.ts +3 -0
  154. package/dist/esm/utils/crypto.d.ts.map +1 -0
  155. package/dist/esm/utils/crypto.js +29 -0
  156. package/dist/esm/utils/crypto.js.map +1 -0
  157. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  158. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  159. package/dist/tsconfig.types.tsbuildinfo +1 -1
  160. package/dist/types/core/aggregate-changes.d.ts +206 -0
  161. package/dist/types/core/aggregate-changes.d.ts.map +1 -0
  162. package/dist/types/core/base-entity.d.ts +88 -0
  163. package/dist/types/core/base-entity.d.ts.map +1 -0
  164. package/dist/types/core/change-tracker.d.ts +96 -0
  165. package/dist/types/core/change-tracker.d.ts.map +1 -0
  166. package/dist/types/core/domain-event.d.ts +23 -0
  167. package/dist/types/core/domain-event.d.ts.map +1 -0
  168. package/dist/types/core/entity-changes.d.ts +84 -0
  169. package/dist/types/core/entity-changes.d.ts.map +1 -0
  170. package/dist/types/core/entity.d.ts +7 -0
  171. package/dist/types/core/entity.d.ts.map +1 -0
  172. package/dist/types/core/id.d.ts +59 -0
  173. package/dist/types/core/id.d.ts.map +1 -0
  174. package/dist/types/core/index.d.ts +9 -0
  175. package/dist/types/core/index.d.ts.map +1 -0
  176. package/dist/types/core/value-object.d.ts +49 -0
  177. package/dist/types/core/value-object.d.ts.map +1 -0
  178. package/dist/types/index.d.ts +5 -11
  179. package/dist/types/index.d.ts.map +1 -1
  180. package/dist/types/paginated-result.d.ts +54 -46
  181. package/dist/types/repository/base-repository.d.ts +49 -3
  182. package/dist/types/repository/base-repository.d.ts.map +1 -1
  183. package/dist/types/repository/entity-schema-registry.d.ts +281 -0
  184. package/dist/types/repository/entity-schema-registry.d.ts.map +1 -0
  185. package/dist/types/repository/index.d.ts +4 -2
  186. package/dist/types/repository/index.d.ts.map +1 -1
  187. package/dist/types/repository/mapper.d.ts +4 -0
  188. package/dist/types/repository/mapper.d.ts.map +1 -0
  189. package/dist/types/repository/paginated-result.d.ts +54 -0
  190. package/dist/types/repository/paginated-result.d.ts.map +1 -0
  191. package/dist/types/types/change-tracker.d.ts +1 -2
  192. package/dist/types/types/change-tracker.d.ts.map +1 -1
  193. package/dist/types/types/criteria.d.ts +13 -5
  194. package/dist/types/types/criteria.d.ts.map +1 -1
  195. package/dist/types/types/domain.d.ts +1 -1
  196. package/dist/types/types/domain.d.ts.map +1 -1
  197. package/dist/types/types/unit-of-work.d.ts +1 -1
  198. package/dist/types/types/unit-of-work.d.ts.map +1 -1
  199. package/dist/types/types/utils.d.ts +1 -2
  200. package/dist/types/types/utils.d.ts.map +1 -1
  201. package/dist/types/utils/criteria-operator-validation.d.ts.map +1 -1
  202. package/dist/types/utils/crypto.d.ts +3 -0
  203. package/dist/types/utils/crypto.d.ts.map +1 -0
  204. package/package.json +1 -1
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValueObject = void 0;
4
+ const validation_error_js_1 = require("../validation-error.js");
5
+ const constants_js_1 = require("../constants.js");
6
+ const exceptions_js_1 = require("../exceptions.js");
7
+ function getStaticProperty(instance, propertyName) {
8
+ return instance.constructor[propertyName];
9
+ }
10
+ class ValueObject {
11
+ value;
12
+ validationConfig;
13
+ // @ts-expect-error - This is a private property
14
+ domainHooks;
15
+ domainSchema;
16
+ domainEvents = [];
17
+ static validation;
18
+ static hooks;
19
+ constructor(value) {
20
+ const validation = getStaticProperty(this, "validation");
21
+ const hooks = getStaticProperty(this, "hooks");
22
+ if (hooks?.onBeforeCreate) {
23
+ hooks.onBeforeCreate(value);
24
+ }
25
+ this.domainHooks = hooks;
26
+ if (validation?.schema) {
27
+ this.domainSchema = validation.schema;
28
+ }
29
+ this.validationConfig = {
30
+ ...constants_js_1.DEFAULT_VALIDATION_CONFIG,
31
+ ...validation?.config,
32
+ };
33
+ if (this.domainSchema && this.validationConfig.onCreate) {
34
+ this.validateValue(value);
35
+ }
36
+ this.value = value;
37
+ if (hooks?.rules) {
38
+ hooks.rules(this);
39
+ }
40
+ Object.freeze(this);
41
+ }
42
+ validateValue(value) {
43
+ if (!this.domainSchema)
44
+ return;
45
+ const result = this.domainSchema["~standard"].validate(value);
46
+ if (result instanceof Promise) {
47
+ throw new exceptions_js_1.DomainError("Async validation not supported in constructor. Use sync validation schema.");
48
+ }
49
+ if (result.issues && result.issues.length > 0) {
50
+ const validationError = new validation_error_js_1.ValidationError(result.issues.map((issue) => ({
51
+ path: issue.path?.map((p) => this.extractPathKey(p)) || [],
52
+ message: issue.message,
53
+ })));
54
+ if (this.validationConfig.throwOnError) {
55
+ throw validationError;
56
+ }
57
+ this._validationError = validationError;
58
+ }
59
+ }
60
+ extractPathKey(pathSegment) {
61
+ if (pathSegment === null || pathSegment === undefined) {
62
+ return "";
63
+ }
64
+ if (typeof pathSegment === "string" || typeof pathSegment === "number") {
65
+ return String(pathSegment);
66
+ }
67
+ if (typeof pathSegment === "symbol") {
68
+ return pathSegment.toString();
69
+ }
70
+ if (typeof pathSegment === "object" && "key" in pathSegment) {
71
+ return String(pathSegment.key);
72
+ }
73
+ return String(pathSegment);
74
+ }
75
+ /**
76
+ * Returns true if the value object has validation errors (when throwOnError is false).
77
+ */
78
+ get hasValidationErrors() {
79
+ return !!this._validationError;
80
+ }
81
+ /**
82
+ * Returns the validation errors (when throwOnError is false).
83
+ */
84
+ get validationErrors() {
85
+ return this._validationError;
86
+ }
87
+ /**
88
+ * Compare this ValueObject with another for equality based on their properties.
89
+ */
90
+ equals(other) {
91
+ if (!other || !(other instanceof ValueObject))
92
+ return false;
93
+ return this.value === other.value;
94
+ }
95
+ /**
96
+ * Adds a domain event to this value object.
97
+ */
98
+ addDomainEvent(event) {
99
+ this.domainEvents.push(event);
100
+ }
101
+ /**
102
+ * Returns all uncommitted domain events.
103
+ */
104
+ getUncommittedEvents() {
105
+ return [...this.domainEvents];
106
+ }
107
+ /**
108
+ * Clears all domain events (call after publishing).
109
+ */
110
+ clearEvents() {
111
+ this.domainEvents = [];
112
+ }
113
+ /**
114
+ * Returns true if the value object has uncommitted events.
115
+ */
116
+ hasUncommittedEvents() {
117
+ return this.domainEvents.length > 0;
118
+ }
119
+ /**
120
+ * Creates a new ValueObject with updated value.
121
+ * ValueObjects are immutable, so this returns a new instance.
122
+ */
123
+ clone(value) {
124
+ const Constructor = this.constructor;
125
+ return new Constructor(value);
126
+ }
127
+ }
128
+ exports.ValueObject = ValueObject;
129
+ //# sourceMappingURL=value-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-object.js","sourceRoot":"","sources":["../../../src/core/value-object.ts"],"names":[],"mappings":";;;AAAA,gEAAyD;AASzD,kDAA4D;AAC5D,oDAA+C;AAE/C,SAAS,iBAAiB,CACxB,QAAa,EACb,YAAoB;IAEpB,OAAO,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC;AAED,MAAsB,WAAW;IACf,KAAK,CAAK;IAClB,gBAAgB,CAA6B;IACrD,gDAAgD;IACxC,WAAW,CAAmB;IAC9B,YAAY,CAAqB;IACjC,YAAY,GAAmB,EAAE,CAAC;IAEhC,MAAM,CAAC,UAAU,CAAyB;IAC1C,MAAM,CAAC,KAAK,CAAqB;IAE3C,YAAY,KAAQ;QAClB,MAAM,UAAU,GAAG,iBAAiB,CAClC,IAAI,EACJ,YAAY,CACb,CAAC;QACF,MAAM,KAAK,GAAG,iBAAiB,CAAkB,IAAI,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AI,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC;IACpC,CAAC;IAED;;OAEG;IACO,cAAc,CAAC,KAAmB;QAC1C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,OAAO,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,WAAW;QACT,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;IACtC,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,KAAQ;QACtB,MAAM,WAAW,GAAG,IAAI,CAAC,WAAqC,CAAC;QAC/D,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACF;AAnJD,kCAmJC"}
@@ -1,16 +1,10 @@
1
1
  export * from "./validation-error.js";
2
- export * from "./domain-event.js";
2
+ export * from "./core/domain-event.js";
3
3
  export * from "./exceptions.js";
4
4
  export * from "./criteria.js";
5
- export * from "./paginated-result.js";
6
- export * from "./repository/index.js";
7
- export { Id } from "./id.js";
8
- export { Entity, Aggregate } from "./entity.js";
9
- export { ValueObject } from "./value-object.js";
10
- export { Mapper } from "./mapper.js";
11
- export { EntitySchemaRegistry } from "./entity-schema-registry.js";
12
- export { AggregateChanges } from "./aggregate-changes.js";
13
- export type { EntityHooks, Filter, EntityValidation, IDomainEvent, VOValidation, VOHooks, ValidationConfig, Primitive, TransactionContext, PaginationMeta, Pagination, OrderDirection, Order, IUnitOfWork, FieldPath, FilterOperator, Search, FilterValueFor, PathValue, OperatorsForType, DateOperators, NumberOperators, StringOperators, BooleanOperators, ArrayOperators, CriteriaOptions, DeepJsonResult, IDomainEventBus, } from "./types/index.js";
14
- export { ARRAY_OPERATORS, BOOLEAN_OPERATORS, DATE_OPERATORS, NUMBER_OPERATORS, STRING_OPERATORS, FILTER_OPERATORS, } from "./constants.js";
15
5
  export { isValidOperatorForType } from "./utils/criteria-operator-validation.js";
6
+ export { ARRAY_OPERATORS, BOOLEAN_OPERATORS, DATE_OPERATORS, NUMBER_OPERATORS, STRING_OPERATORS, FILTER_OPERATORS, } from "./constants.js";
7
+ export { Id, Entity, Aggregate, ValueObject, AggregateChanges, DomainEvent, } from "./core/index.js";
8
+ export { type PaginatedJsonResult, type CollectionConfig, Repository, Mapper, UnitOfWork, PaginatedResult, ReadRepository, WriteAndRead, WriteRepository, BaseTransactionContext, EntitySchemaRegistry, } from "./repository/index.js";
9
+ export type { EntityHooks, Filter, EntityValidation, IDomainEvent, VOValidation, VOHooks, ValidationConfig, Primitive, TransactionContext, PaginationMeta, Pagination, OrderDirection, Order, IUnitOfWork, FieldPath, FilterOperator, Search, FilterValueFor, PathValue, OperatorsForType, DateOperators, NumberOperators, StringOperators, BooleanOperators, ArrayOperators, CriteriaOptions, IDomainEventBus, } from "./types/index.js";
16
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EACV,WAAW,EACX,MAAM,EACN,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,cAAc,EACd,KAAK,EACL,WAAW,EACX,SAAS,EACT,cAAc,EACd,MAAM,EACN,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,EAAE,EACF,MAAM,EACN,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,UAAU,EACV,MAAM,EACN,UAAU,EACV,eAAe,EACf,cAAc,EACd,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,WAAW,EACX,MAAM,EACN,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,cAAc,EACd,KAAK,EACL,WAAW,EACX,SAAS,EACT,cAAc,EACd,MAAM,EACN,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,eAAe,GAChB,MAAM,kBAAkB,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -14,26 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.isValidOperatorForType = exports.FILTER_OPERATORS = exports.STRING_OPERATORS = exports.NUMBER_OPERATORS = exports.DATE_OPERATORS = exports.BOOLEAN_OPERATORS = exports.ARRAY_OPERATORS = exports.AggregateChanges = exports.EntitySchemaRegistry = exports.Mapper = exports.ValueObject = exports.Aggregate = exports.Entity = exports.Id = void 0;
17
+ exports.EntitySchemaRegistry = exports.BaseTransactionContext = exports.WriteRepository = exports.WriteAndRead = exports.ReadRepository = exports.PaginatedResult = exports.UnitOfWork = exports.Mapper = exports.Repository = exports.DomainEvent = exports.AggregateChanges = exports.ValueObject = exports.Aggregate = exports.Entity = exports.Id = exports.FILTER_OPERATORS = exports.STRING_OPERATORS = exports.NUMBER_OPERATORS = exports.DATE_OPERATORS = exports.BOOLEAN_OPERATORS = exports.ARRAY_OPERATORS = exports.isValidOperatorForType = void 0;
18
18
  __exportStar(require("./validation-error.js"), exports);
19
- __exportStar(require("./domain-event.js"), exports);
19
+ __exportStar(require("./core/domain-event.js"), exports);
20
20
  __exportStar(require("./exceptions.js"), exports);
21
21
  __exportStar(require("./criteria.js"), exports);
22
- __exportStar(require("./paginated-result.js"), exports);
23
- __exportStar(require("./repository/index.js"), exports);
24
- var id_js_1 = require("./id.js");
25
- Object.defineProperty(exports, "Id", { enumerable: true, get: function () { return id_js_1.Id; } });
26
- var entity_js_1 = require("./entity.js");
27
- Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return entity_js_1.Entity; } });
28
- Object.defineProperty(exports, "Aggregate", { enumerable: true, get: function () { return entity_js_1.Aggregate; } });
29
- var value_object_js_1 = require("./value-object.js");
30
- Object.defineProperty(exports, "ValueObject", { enumerable: true, get: function () { return value_object_js_1.ValueObject; } });
31
- var mapper_js_1 = require("./mapper.js");
32
- Object.defineProperty(exports, "Mapper", { enumerable: true, get: function () { return mapper_js_1.Mapper; } });
33
- var entity_schema_registry_js_1 = require("./entity-schema-registry.js");
34
- Object.defineProperty(exports, "EntitySchemaRegistry", { enumerable: true, get: function () { return entity_schema_registry_js_1.EntitySchemaRegistry; } });
35
- var aggregate_changes_js_1 = require("./aggregate-changes.js");
36
- Object.defineProperty(exports, "AggregateChanges", { enumerable: true, get: function () { return aggregate_changes_js_1.AggregateChanges; } });
22
+ var criteria_operator_validation_js_1 = require("./utils/criteria-operator-validation.js");
23
+ Object.defineProperty(exports, "isValidOperatorForType", { enumerable: true, get: function () { return criteria_operator_validation_js_1.isValidOperatorForType; } });
37
24
  var constants_js_1 = require("./constants.js");
38
25
  Object.defineProperty(exports, "ARRAY_OPERATORS", { enumerable: true, get: function () { return constants_js_1.ARRAY_OPERATORS; } });
39
26
  Object.defineProperty(exports, "BOOLEAN_OPERATORS", { enumerable: true, get: function () { return constants_js_1.BOOLEAN_OPERATORS; } });
@@ -41,6 +28,21 @@ Object.defineProperty(exports, "DATE_OPERATORS", { enumerable: true, get: functi
41
28
  Object.defineProperty(exports, "NUMBER_OPERATORS", { enumerable: true, get: function () { return constants_js_1.NUMBER_OPERATORS; } });
42
29
  Object.defineProperty(exports, "STRING_OPERATORS", { enumerable: true, get: function () { return constants_js_1.STRING_OPERATORS; } });
43
30
  Object.defineProperty(exports, "FILTER_OPERATORS", { enumerable: true, get: function () { return constants_js_1.FILTER_OPERATORS; } });
44
- var criteria_operator_validation_js_1 = require("./utils/criteria-operator-validation.js");
45
- Object.defineProperty(exports, "isValidOperatorForType", { enumerable: true, get: function () { return criteria_operator_validation_js_1.isValidOperatorForType; } });
31
+ var index_js_1 = require("./core/index.js");
32
+ Object.defineProperty(exports, "Id", { enumerable: true, get: function () { return index_js_1.Id; } });
33
+ Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return index_js_1.Entity; } });
34
+ Object.defineProperty(exports, "Aggregate", { enumerable: true, get: function () { return index_js_1.Aggregate; } });
35
+ Object.defineProperty(exports, "ValueObject", { enumerable: true, get: function () { return index_js_1.ValueObject; } });
36
+ Object.defineProperty(exports, "AggregateChanges", { enumerable: true, get: function () { return index_js_1.AggregateChanges; } });
37
+ Object.defineProperty(exports, "DomainEvent", { enumerable: true, get: function () { return index_js_1.DomainEvent; } });
38
+ var index_js_2 = require("./repository/index.js");
39
+ Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return index_js_2.Repository; } });
40
+ Object.defineProperty(exports, "Mapper", { enumerable: true, get: function () { return index_js_2.Mapper; } });
41
+ Object.defineProperty(exports, "UnitOfWork", { enumerable: true, get: function () { return index_js_2.UnitOfWork; } });
42
+ Object.defineProperty(exports, "PaginatedResult", { enumerable: true, get: function () { return index_js_2.PaginatedResult; } });
43
+ Object.defineProperty(exports, "ReadRepository", { enumerable: true, get: function () { return index_js_2.ReadRepository; } });
44
+ Object.defineProperty(exports, "WriteAndRead", { enumerable: true, get: function () { return index_js_2.WriteAndRead; } });
45
+ Object.defineProperty(exports, "WriteRepository", { enumerable: true, get: function () { return index_js_2.WriteRepository; } });
46
+ Object.defineProperty(exports, "BaseTransactionContext", { enumerable: true, get: function () { return index_js_2.BaseTransactionContext; } });
47
+ Object.defineProperty(exports, "EntitySchemaRegistry", { enumerable: true, get: function () { return index_js_2.EntitySchemaRegistry; } });
46
48
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,oDAAkC;AAClC,kDAAgC;AAChC,gDAA8B;AAC9B,wDAAsC;AACtC,wDAAsC;AACtC,iCAA6B;AAApB,2FAAA,EAAE,OAAA;AACX,yCAAgD;AAAvC,mGAAA,MAAM,OAAA;AAAE,sGAAA,SAAS,OAAA;AAC1B,qDAAgD;AAAvC,8GAAA,WAAW,OAAA;AACpB,yCAAqC;AAA5B,mGAAA,MAAM,OAAA;AACf,yEAAmE;AAA1D,iIAAA,oBAAoB,OAAA;AAC7B,+DAA0D;AAAjD,wHAAA,gBAAgB,OAAA;AA+BzB,+CAOwB;AANtB,+GAAA,eAAe,OAAA;AACf,iHAAA,iBAAiB,OAAA;AACjB,8GAAA,cAAc,OAAA;AACd,gHAAA,gBAAgB,OAAA;AAChB,gHAAA,gBAAgB,OAAA;AAChB,gHAAA,gBAAgB,OAAA;AAElB,2FAAiF;AAAxE,yIAAA,sBAAsB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,yDAAuC;AACvC,kDAAgC;AAChC,gDAA8B;AAC9B,2FAAiF;AAAxE,yIAAA,sBAAsB,OAAA;AAC/B,+CAOwB;AANtB,+GAAA,eAAe,OAAA;AACf,iHAAA,iBAAiB,OAAA;AACjB,8GAAA,cAAc,OAAA;AACd,gHAAA,gBAAgB,OAAA;AAChB,gHAAA,gBAAgB,OAAA;AAChB,gHAAA,gBAAgB,OAAA;AAElB,4CAOyB;AANvB,8FAAA,EAAE,OAAA;AACF,kGAAA,MAAM,OAAA;AACN,qGAAA,SAAS,OAAA;AACT,uGAAA,WAAW,OAAA;AACX,4GAAA,gBAAgB,OAAA;AAChB,uGAAA,WAAW,OAAA;AAEb,kDAY+B;AAT7B,sGAAA,UAAU,OAAA;AACV,kGAAA,MAAM,OAAA;AACN,sGAAA,UAAU,OAAA;AACV,2GAAA,eAAe,OAAA;AACf,0GAAA,cAAc,OAAA;AACd,wGAAA,YAAY,OAAA;AACZ,2GAAA,eAAe,OAAA;AACf,kHAAA,sBAAsB,OAAA;AACtB,gHAAA,oBAAoB,OAAA"}
@@ -1,28 +1,74 @@
1
- import type { Aggregate } from "../entity.js";
1
+ import type { Aggregate } from "../core/entity.js";
2
2
  import type { Criteria } from "../criteria.js";
3
- import { PaginatedResult } from "../paginated-result.js";
4
- import { Mapper } from "../mapper.js";
3
+ import { PaginatedResult } from "./paginated-result.js";
4
+ import { Mapper } from "./mapper.js";
5
5
  export declare abstract class ReadRepository<Agg extends Aggregate<any>> {
6
+ /**
7
+ * Find entities based on criteria.
8
+ * @param criteria - The criteria to use for the search. If not provided, all entities will be returned. (optional)
9
+ * @returns A promise that resolves to a paginated result of entities.
10
+ */
6
11
  abstract find(criteria?: Criteria<Agg>): Promise<PaginatedResult<Agg>>;
7
12
  abstract findById(id: string): Promise<Agg | null>;
13
+ /**
14
+ * Count the number of entities based on criteria.
15
+ * @param criteria - The criteria to use for the count. If not provided, all entities will be counted. (optional)
16
+ * @returns A promise that resolves to the number of entities.
17
+ */
8
18
  abstract count(criteria?: Criteria<Agg>): Promise<number>;
19
+ /**
20
+ * Check if an entity exists based on its identifier.
21
+ * @param id - The identifier of the entity to check.
22
+ * @returns A promise that resolves to a boolean.
23
+ */
9
24
  abstract exists(id: string): Promise<boolean>;
10
25
  }
11
26
  export declare abstract class WriteRepository<Agg extends Aggregate<any>> {
27
+ /**
28
+ *
29
+ * Save or update an entity.
30
+ * @param entity - The entity to save.
31
+ * @returns void
32
+ */
12
33
  abstract save(entity: Agg): Promise<void>;
13
34
  abstract delete(entity: Agg): Promise<void>;
14
35
  }
15
36
  export declare abstract class WriteAndRead<Agg extends Aggregate<any>> {
37
+ /**
38
+ * Find entities based on criteria.
39
+ * @param criteria - The criteria to use for the search. If not provided, all entities will be returned. (optional)
40
+ * @returns A promise that resolves to a paginated result of entities.
41
+ */
16
42
  abstract find(criteria?: Criteria<Agg>): Promise<PaginatedResult<Agg>>;
17
43
  abstract findById(id: string): Promise<Agg | null>;
44
+ /**
45
+ *
46
+ * Save or update an entity.
47
+ * @param entity - The entity to save.
48
+ * @returns void
49
+ */
18
50
  abstract save(entity: Agg): Promise<void>;
19
51
  abstract delete(entity: Agg): Promise<void>;
52
+ /**
53
+ * Count the number of entities based on criteria.
54
+ * @param criteria - The criteria to use for the count. If not provided, all entities will be counted. (optional)
55
+ * @returns A promise that resolves to the number of entities.
56
+ */
20
57
  abstract count(criteria?: Criteria<Agg>): Promise<number>;
58
+ /**
59
+ * Check if an entity exists based on its identifier.
60
+ * @param id - The identifier of the entity to check.
61
+ * @returns A promise that resolves to a boolean.
62
+ */
21
63
  abstract exists(id: string): Promise<boolean>;
22
64
  }
23
65
  export declare abstract class Repository<TDomain extends Aggregate<any>> extends WriteAndRead<TDomain> {
24
66
  protected abstract readonly toDomainMapper: Mapper<unknown, TDomain>;
25
67
  protected abstract readonly toPersistenceMapper: Mapper<TDomain, unknown>;
68
+ /**
69
+ * Provide the model name of the repository. Usually the table name in the database.
70
+ * @returns The model name of the repository.
71
+ */
26
72
  protected abstract get model(): any;
27
73
  }
28
74
  //# sourceMappingURL=base-repository.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base-repository.d.ts","sourceRoot":"","sources":["../../../src/repository/base-repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,8BAAsB,cAAc,CAAC,GAAG,SAAS,SAAS,CAAC,GAAG,CAAC;IAC7D,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,CA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"}
@@ -1 +1 @@
1
- {"version":3,"file":"base-repository.js","sourceRoot":"","sources":["../../../src/repository/base-repository.ts"],"names":[],"mappings":";;;AAKA,MAAsB,cAAc;CAKnC;AALD,wCAKC;AAED,MAAsB,eAAe;CAGpC;AAHD,0CAGC;AAED,MAAsB,YAAY;CAOjC;AAPD,oCAOC;AAED,MAAsB,UAEpB,SAAQ,YAAqB;CAI9B;AAND,gCAMC"}
1
+ {"version":3,"file":"base-repository.js","sourceRoot":"","sources":["../../../src/repository/base-repository.ts"],"names":[],"mappings":";;;AAKA,MAAsB,cAAc;CAoBnC;AApBD,wCAoBC;AAED,MAAsB,eAAe;CASpC;AATD,0CASC;AAED,MAAsB,YAAY;CA4BjC;AA5BD,oCA4BC;AAED,MAAsB,UAEpB,SAAQ,YAAqB;CAQ9B;AAVD,gCAUC"}
@@ -0,0 +1,281 @@
1
+ import { Entity, ValueObject } from "../core/index";
2
+ /**
3
+ * Type of collection relationship.
4
+ * - 'owned': Parent owns the children (1:N). Delete parent = delete children.
5
+ * - 'reference': Parent references existing entities (N:N). Delete parent = unlink only.
6
+ */
7
+ export type CollectionType = "owned" | "reference";
8
+ /**
9
+ * Configuration for a collection (1:N or N:N relationship).
10
+ */
11
+ export interface CollectionConfig {
12
+ /**
13
+ * Type of relationship.
14
+ * - 'owned': Children are created/deleted with the parent (default for 1:N)
15
+ * - 'reference': Only the link is created/removed (for N:N)
16
+ * @default 'owned'
17
+ */
18
+ type: CollectionType;
19
+ /**
20
+ * Target entity name (required for 'reference' type).
21
+ * @example 'Tag'
22
+ */
23
+ entity?: string;
24
+ /**
25
+ * Junction table configuration (optional, for ORMs that need it like Drizzle).
26
+ * Prisma handles this automatically, so it's optional.
27
+ */
28
+ junction?: {
29
+ /** Junction table name (e.g., 'post_tags', '_PostToTag') */
30
+ table: string;
31
+ /** FK field pointing to the source entity (e.g., 'post_id') */
32
+ sourceKey: string;
33
+ /** FK field pointing to the target entity (e.g., 'tag_id') */
34
+ targetKey: string;
35
+ };
36
+ }
37
+ /**
38
+ * Mapping schema for a domain entity.
39
+ */
40
+ export interface EntitySchema {
41
+ /** Entity name in the domain (e.g., 'User', 'Post') */
42
+ entity: string;
43
+ /** Table name in the database (e.g., 'users', 'blog_posts') */
44
+ table: string;
45
+ /**
46
+ * Field mapping: domain → database.
47
+ * Only include fields with different names.
48
+ * @example { email: 'user_email', createdAt: 'created_at' }
49
+ */
50
+ fields?: Record<string, string>;
51
+ /**
52
+ * FK configuration for parent relation (1:N owned).
53
+ */
54
+ parentFk?: {
55
+ /** Name of the FK field in the database (e.g., 'author_id') */
56
+ field: string;
57
+ /** Name of the parent entity (e.g., 'User') */
58
+ parentEntity: string;
59
+ };
60
+ /**
61
+ * Collection configurations for this entity's relations.
62
+ * Key is the property name in the domain entity.
63
+ * @example
64
+ * ```typescript
65
+ * collections: {
66
+ * comments: { type: 'owned' },
67
+ * tags: { type: 'reference', entity: 'Tag' }
68
+ * }
69
+ * ```
70
+ */
71
+ collections?: Record<string, CollectionConfig>;
72
+ }
73
+ /**
74
+ * Result of entity mapping.
75
+ */
76
+ export interface MappedEntityData {
77
+ [key: string]: any;
78
+ }
79
+ /**
80
+ * Registry for mapping domain entities to database tables and fields.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const registry = new EntitySchemaRegistry()
85
+ * .register({
86
+ * entity: 'User',
87
+ * table: 'users',
88
+ * fields: { email: 'user_email', name: 'user_name' },
89
+ * })
90
+ * .register({
91
+ * entity: 'Post',
92
+ * table: 'blog_posts',
93
+ * fields: { content: 'post_content' },
94
+ * parentFk: { field: 'author_id', parentEntity: 'User' },
95
+ * collections: {
96
+ * comments: { type: 'owned' },
97
+ * tags: { type: 'reference', entity: 'Tag' }
98
+ * }
99
+ * });
100
+ *
101
+ * const table = registry.getTable('Post'); // 'blog_posts'
102
+ * const tagConfig = registry.getCollectionConfig('Post', 'tags');
103
+ * // { type: 'reference', entity: 'Tag' }
104
+ * ```
105
+ */
106
+ export declare class EntitySchemaRegistry {
107
+ private schemas;
108
+ /**
109
+ * Registers an entity schema.
110
+ * @param schema - Schema to be registered.
111
+ * @returns this (for chaining)
112
+ */
113
+ register(schema: EntitySchema): this;
114
+ /**
115
+ * Registers multiple schemas at once.
116
+ * @param schemas - Array of schemas.
117
+ * @returns this (for chaining)
118
+ */
119
+ registerAll(schemas: EntitySchema[]): this;
120
+ /**
121
+ * Gets the schema of an entity.
122
+ * @param entity - Entity name.
123
+ * @throws Error if the entity is not registered.
124
+ */
125
+ getSchema(entity: string): EntitySchema;
126
+ /**
127
+ * Gets all registered schemas.
128
+ */
129
+ getAllSchemas(): EntitySchema[];
130
+ /**
131
+ * Tries to get the schema of an entity, returns null if not found.
132
+ * @param entity - Entity name.
133
+ */
134
+ tryGetSchema(entity: string): EntitySchema | null;
135
+ /**
136
+ * Checks if an entity is registered.
137
+ * @param entity - Entity name.
138
+ */
139
+ has(entity: string): boolean;
140
+ /**
141
+ * Gets the table name for an entity.
142
+ * @param entity - Entity name.
143
+ */
144
+ getTable(entity: string): string;
145
+ /**
146
+ * Gets the field mapping for an entity.
147
+ * @param entity - Entity name.
148
+ */
149
+ getFieldsMap(entity: string): Record<string, string>;
150
+ /**
151
+ * Maps a domain field name to the database field name.
152
+ * @param entity - Entity name.
153
+ * @param fieldName - Domain field name.
154
+ */
155
+ mapFieldName(entity: string, fieldName: string): string;
156
+ /**
157
+ * Maps fields of a domain object to database field names.
158
+ * Ignores values that are Entity, ValueObject, or Arrays.
159
+ *
160
+ * @param entity - Entity name.
161
+ * @param data - Data to be mapped.
162
+ */
163
+ mapFields(entity: string, data: Record<string, any>): MappedEntityData;
164
+ /**
165
+ * Maps a complete domain entity to database data.
166
+ * Used for CREATE operations.
167
+ *
168
+ * @param entity - Entity name.
169
+ * @param domainEntity - Domain entity instance.
170
+ */
171
+ mapEntity(entity: string, domainEntity: Entity<any> | ValueObject<any>): MappedEntityData;
172
+ /**
173
+ * Gets the FK object to relate with the parent.
174
+ *
175
+ * @param entity - Entity name.
176
+ * @param parentId - Parent ID.
177
+ * @returns Object with the FK field or null if there is no parent.
178
+ */
179
+ getParentFk(entity: string, parentId: string): Record<string, string> | null;
180
+ /**
181
+ * Gets the name of the parent entity.
182
+ * @param entity - Entity name.
183
+ */
184
+ getParentEntity(entity: string): string | null;
185
+ /**
186
+ * Gets the FK field name.
187
+ * @param entity - Entity name.
188
+ */
189
+ getParentFkField(entity: string): string | null;
190
+ /**
191
+ * Gets the collection configuration for a specific field.
192
+ *
193
+ * @param entity - Parent entity name (e.g., 'Post')
194
+ * @param fieldName - Collection field name (e.g., 'tags')
195
+ * @returns CollectionConfig or null if not configured
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * const config = registry.getCollectionConfig('Post', 'tags');
200
+ * if (config?.type === 'reference') {
201
+ * // Handle N:N relation - use connect/disconnect
202
+ * } else {
203
+ * // Handle 1:N relation - use create/delete
204
+ * }
205
+ * ```
206
+ */
207
+ getCollectionConfig(entity: string, fieldName: string): CollectionConfig | null;
208
+ /**
209
+ * Checks if a collection is a reference type (N:N).
210
+ *
211
+ * @param entity - Parent entity name
212
+ * @param fieldName - Collection field name
213
+ * @returns true if the collection is a reference (N:N), false otherwise
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * if (registry.isReferenceCollection('Post', 'tags')) {
218
+ * // Use connect/disconnect instead of create/delete
219
+ * }
220
+ * ```
221
+ */
222
+ isReferenceCollection(entity: string, fieldName: string): boolean;
223
+ /**
224
+ * Checks if a collection is owned (1:N).
225
+ * Returns true if explicitly configured as 'owned' or if not configured at all.
226
+ *
227
+ * @param entity - Parent entity name
228
+ * @param fieldName - Collection field name
229
+ * @returns true if the collection is owned (1:N), false if reference
230
+ */
231
+ isOwnedCollection(entity: string, fieldName: string): boolean;
232
+ /**
233
+ * Gets all collections configured for an entity.
234
+ *
235
+ * @param entity - Entity name
236
+ * @returns Record of field names to collection configs, or empty object
237
+ */
238
+ getCollections(entity: string): Record<string, CollectionConfig>;
239
+ /**
240
+ * Gets all reference (N:N) collections for an entity.
241
+ *
242
+ * @param entity - Entity name
243
+ * @returns Array of field names that are reference collections
244
+ */
245
+ getReferenceCollections(entity: string): string[];
246
+ /**
247
+ * Gets the junction table configuration for a reference collection.
248
+ *
249
+ * @param entity - Parent entity name
250
+ * @param fieldName - Collection field name
251
+ * @returns Junction config or null
252
+ */
253
+ getJunctionConfig(entity: string, fieldName: string): CollectionConfig["junction"] | null;
254
+ /**
255
+ * Lists all registered entities.
256
+ */
257
+ getRegisteredEntities(): string[];
258
+ /**
259
+ * Clears all registered schemas.
260
+ */
261
+ clear(): void;
262
+ /**
263
+ * Checks if a value is Entity, ValueObject, or Array.
264
+ */
265
+ private isEntityOrCollection;
266
+ /**
267
+ * Normalizes a value for persistence.
268
+ */
269
+ private normalizeValue;
270
+ /**
271
+ * Validates that a relation field exists in the entity's collections.
272
+ *
273
+ * @param entity - Parent entity name
274
+ * @param relationField - Relation field to validate
275
+ * @throws ConfigurationError if the field doesn't exist
276
+ *
277
+ */
278
+ validateRelationField(entity: string, relationField: string): void;
279
+ private findSimilarNames;
280
+ }
281
+ //# sourceMappingURL=entity-schema-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-schema-registry.d.ts","sourceRoot":"","sources":["../../../src/repository/entity-schema-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAM,MAAM,eAAe,CAAC;AAIxD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,WAAW,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,IAAI,EAAE,cAAc,CAAC;IAErB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE;QACT,4DAA4D;QAC5D,KAAK,EAAE,MAAM,CAAC;QACd,+DAA+D;QAC/D,SAAS,EAAE,MAAM,CAAC;QAClB,8DAA8D;QAC9D,SAAS,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