@woltz/rich-domain 0.2.1 → 1.0.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 (128) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +37 -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 +21 -15
  6. package/dist/base-entity.js.map +1 -1
  7. package/dist/constants.js +4 -1
  8. package/dist/constants.js.map +1 -1
  9. package/dist/criteria.d.ts.map +1 -1
  10. package/dist/criteria.js +7 -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 +110 -33
  15. package/dist/deep-proxy.js.map +1 -1
  16. package/dist/domain-event-bus.js +7 -2
  17. package/dist/domain-event-bus.js.map +1 -1
  18. package/dist/domain-event.js +7 -3
  19. package/dist/domain-event.js.map +1 -1
  20. package/dist/entity.js +8 -3
  21. package/dist/entity.js.map +1 -1
  22. package/dist/id.d.ts +3 -3
  23. package/dist/id.d.ts.map +1 -1
  24. package/dist/id.js +10 -6
  25. package/dist/id.js.map +1 -1
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +39 -16
  29. package/dist/index.js.map +1 -1
  30. package/dist/mapper.d.ts +4 -0
  31. package/dist/mapper.d.ts.map +1 -0
  32. package/dist/mapper.js +7 -0
  33. package/dist/mapper.js.map +1 -0
  34. package/dist/paginated-result.d.ts.map +1 -1
  35. package/dist/paginated-result.js +7 -6
  36. package/dist/paginated-result.js.map +1 -1
  37. package/dist/repository/base-repository.d.ts +25 -48
  38. package/dist/repository/base-repository.d.ts.map +1 -1
  39. package/dist/repository/base-repository.js +14 -51
  40. package/dist/repository/base-repository.js.map +1 -1
  41. package/dist/repository/in-memory-repository.d.ts +12 -8
  42. package/dist/repository/in-memory-repository.d.ts.map +1 -1
  43. package/dist/repository/in-memory-repository.js +24 -12
  44. package/dist/repository/in-memory-repository.js.map +1 -1
  45. package/dist/repository/index.d.ts +2 -39
  46. package/dist/repository/index.d.ts.map +1 -1
  47. package/dist/repository/index.js +26 -40
  48. package/dist/repository/index.js.map +1 -1
  49. package/dist/repository/unit-of-work.js +9 -3
  50. package/dist/repository/unit-of-work.js.map +1 -1
  51. package/dist/types/criteria.d.ts +2 -2
  52. package/dist/types/criteria.d.ts.map +1 -1
  53. package/dist/types/criteria.js +4 -1
  54. package/dist/types/criteria.js.map +1 -1
  55. package/dist/types/domain.js +2 -1
  56. package/dist/types/history-tracker.js +2 -1
  57. package/dist/types/index.d.ts +0 -1
  58. package/dist/types/index.d.ts.map +1 -1
  59. package/dist/types/index.js +22 -7
  60. package/dist/types/index.js.map +1 -1
  61. package/dist/types/standard-schema.js +2 -1
  62. package/dist/types/unit-of-work.d.ts +2 -2
  63. package/dist/types/unit-of-work.d.ts.map +1 -1
  64. package/dist/types/unit-of-work.js +2 -1
  65. package/dist/types/utils.js +2 -1
  66. package/dist/validation-error.js +9 -3
  67. package/dist/validation-error.js.map +1 -1
  68. package/dist/value-object.js +9 -5
  69. package/dist/value-object.js.map +1 -1
  70. package/package.json +1 -1
  71. package/src/base-entity.ts +3 -2
  72. package/src/criteria.ts +2 -2
  73. package/src/deep-proxy.ts +435 -339
  74. package/src/id.ts +4 -4
  75. package/src/index.ts +2 -3
  76. package/src/mapper.ts +3 -0
  77. package/src/paginated-result.ts +1 -8
  78. package/src/repository/base-repository.ts +27 -115
  79. package/src/repository/in-memory-repository.ts +28 -16
  80. package/src/repository/index.ts +2 -40
  81. package/src/types/criteria.ts +2 -2
  82. package/src/types/index.ts +0 -1
  83. package/src/types/unit-of-work.ts +3 -3
  84. package/tests/entity-validation.test.ts +1 -1
  85. package/tests/history-tracker.spec.ts +57 -17
  86. package/tests/id.test.ts +341 -341
  87. package/tests/repository.test.ts +95 -79
  88. package/tests/to-json.test.ts +103 -91
  89. package/tests/value-objects.test.ts +52 -52
  90. package/tsconfig.json +2 -2
  91. package/dist/filtering.d.ts +0 -107
  92. package/dist/filtering.d.ts.map +0 -1
  93. package/dist/filtering.js +0 -202
  94. package/dist/filtering.js.map +0 -1
  95. package/dist/ordering.d.ts +0 -93
  96. package/dist/ordering.d.ts.map +0 -1
  97. package/dist/ordering.js +0 -154
  98. package/dist/ordering.js.map +0 -1
  99. package/dist/pagination.d.ts +0 -218
  100. package/dist/pagination.d.ts.map +0 -1
  101. package/dist/pagination.js +0 -281
  102. package/dist/pagination.js.map +0 -1
  103. package/dist/repository/mapper.d.ts +0 -56
  104. package/dist/repository/mapper.d.ts.map +0 -1
  105. package/dist/repository/mapper.js +0 -15
  106. package/dist/repository/mapper.js.map +0 -1
  107. package/dist/repository/types.d.ts +0 -87
  108. package/dist/repository/types.d.ts.map +0 -1
  109. package/dist/repository/types.js +0 -6
  110. package/dist/repository/types.js.map +0 -1
  111. package/dist/repository.d.ts +0 -2
  112. package/dist/repository.d.ts.map +0 -1
  113. package/dist/repository.js +0 -21
  114. package/dist/repository.js.map +0 -1
  115. package/dist/specification.d.ts +0 -102
  116. package/dist/specification.d.ts.map +0 -1
  117. package/dist/specification.js +0 -187
  118. package/dist/specification.js.map +0 -1
  119. package/dist/types/repository.d.ts +0 -43
  120. package/dist/types/repository.d.ts.map +0 -1
  121. package/dist/types/repository.js +0 -2
  122. package/dist/types/repository.js.map +0 -1
  123. package/dist/types.d.ts +0 -88
  124. package/dist/types.d.ts.map +0 -1
  125. package/dist/types.js +0 -12
  126. package/dist/types.js.map +0 -1
  127. package/src/repository/mapper.ts +0 -74
  128. package/src/types/repository.ts +0 -51
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2020",
4
- "module": "esnext",
4
+ "module": "commonjs",
5
5
  "lib": ["ES2020"],
6
6
  "declaration": true,
7
7
  "declarationMap": true,
@@ -20,7 +20,7 @@
20
20
  "noUnusedParameters": false,
21
21
  "noImplicitReturns": true,
22
22
  "noFallthroughCasesInSwitch": true,
23
- "moduleResolution": "bundler",
23
+ "moduleResolution": "node",
24
24
  "esModuleInterop": true,
25
25
  "skipLibCheck": true,
26
26
  "forceConsistentCasingInFileNames": true,
@@ -1,107 +0,0 @@
1
- /**
2
- * Supported filter operators
3
- */
4
- export type FilterOperator = "equals" | "notEquals" | "greaterThan" | "greaterThanOrEquals" | "lessThan" | "lessThanOrEquals" | "in" | "notIn" | "contains" | "startsWith" | "endsWith" | "isNull" | "isNotNull";
5
- /**
6
- * Configuration for a single filter
7
- */
8
- export interface FilterConfig<T> {
9
- field: keyof T | string;
10
- operator: FilterOperator;
11
- value?: any;
12
- }
13
- /**
14
- * Represents a single filter condition
15
- * Can be used for in-memory filtering or converted to database-specific queries
16
- *
17
- * @example
18
- * ```typescript
19
- * const filter = new Filter('age', 'greaterThan', 18);
20
- * const adults = users.filter(filter.predicateFn());
21
- * ```
22
- */
23
- export declare class Filter<T> {
24
- private readonly _field;
25
- private readonly _operator;
26
- private readonly _value?;
27
- constructor(field: keyof T | string, operator: FilterOperator, value?: any);
28
- /**
29
- * Gets the field to filter
30
- */
31
- get field(): keyof T | string;
32
- /**
33
- * Gets the filter operator
34
- */
35
- get operator(): FilterOperator;
36
- /**
37
- * Gets the filter value
38
- */
39
- get value(): any;
40
- /**
41
- * Returns configuration object for serialization
42
- */
43
- toConfig(): FilterConfig<T>;
44
- /**
45
- * Checks if the operator requires a value
46
- * @private
47
- */
48
- private requiresValue;
49
- /**
50
- * Creates a predicate function for in-memory filtering
51
- * Handles nested properties using dot notation (e.g., "address.city")
52
- *
53
- * @example
54
- * ```typescript
55
- * const filter = new Filter<User>('age', 'greaterThan', 18);
56
- * const adults = users.filter(filter.predicateFn());
57
- * ```
58
- */
59
- predicateFn(): (item: T) => boolean;
60
- /**
61
- * Gets nested property value using dot notation
62
- * @private
63
- */
64
- private getNestedValue;
65
- }
66
- /**
67
- * Logical operator for combining filters
68
- */
69
- export type LogicalOperator = "and" | "or";
70
- /**
71
- * Represents a composite filter that combines multiple filters with AND/OR logic
72
- *
73
- * @example
74
- * ```typescript
75
- * const composite = new CompositeFilter<User>('and', [
76
- * new Filter('age', 'greaterThan', 18),
77
- * new Filter('status', 'equals', 'active')
78
- * ]);
79
- * const filtered = users.filter(composite.predicateFn());
80
- * ```
81
- */
82
- export declare class CompositeFilter<T> {
83
- private readonly _operator;
84
- private readonly _filters;
85
- constructor(operator: LogicalOperator, filters: (Filter<T> | CompositeFilter<T>)[]);
86
- /**
87
- * Gets the logical operator
88
- */
89
- get operator(): LogicalOperator;
90
- /**
91
- * Gets all filters
92
- */
93
- get filters(): readonly (Filter<T> | CompositeFilter<T>)[];
94
- /**
95
- * Creates a predicate function that applies the logical operator
96
- */
97
- predicateFn(): (item: T) => boolean;
98
- /**
99
- * Adds another filter with AND logic
100
- */
101
- and(filter: Filter<T> | CompositeFilter<T>): CompositeFilter<T>;
102
- /**
103
- * Adds another filter with OR logic
104
- */
105
- or(filter: Filter<T> | CompositeFilter<T>): CompositeFilter<T>;
106
- }
107
- //# sourceMappingURL=filtering.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../src/filtering.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,QAAQ,GACR,WAAW,GACX,aAAa,GACb,qBAAqB,GACrB,UAAU,GACV,kBAAkB,GAClB,IAAI,GACJ,OAAO,GACP,UAAU,GACV,YAAY,GACZ,UAAU,GACV,QAAQ,GACR,WAAW,CAAC;AAEhB;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;IACxB,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAMD;;;;;;;;;GASG;AACH,qBAAa,MAAM,CAAC,CAAC;IACnB,OAAO,CAA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,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC;IAU/D;;OAEG;IACH,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC;CAS/D"}
package/dist/filtering.js DELETED
@@ -1,202 +0,0 @@
1
- "use strict";
2
- // ============================================================================
3
- // Filtering System
4
- // ============================================================================
5
- // Provides filtering/where clause capabilities for queries and in-memory collections
6
- // Supports common comparison operators and can be extended for custom operators
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.CompositeFilter = exports.Filter = void 0;
9
- // ============================================================================
10
- // Filter Class
11
- // ============================================================================
12
- /**
13
- * Represents a single filter condition
14
- * Can be used for in-memory filtering or converted to database-specific queries
15
- *
16
- * @example
17
- * ```typescript
18
- * const filter = new Filter('age', 'greaterThan', 18);
19
- * const adults = users.filter(filter.predicateFn());
20
- * ```
21
- */
22
- class Filter {
23
- constructor(field, operator, value) {
24
- this._field = field;
25
- this._operator = operator;
26
- this._value = value;
27
- // Validate that value is provided when required
28
- if (this.requiresValue() && value === undefined) {
29
- throw new Error(`Filter operator '${operator}' requires a value`);
30
- }
31
- }
32
- /**
33
- * Gets the field to filter
34
- */
35
- get field() {
36
- return this._field;
37
- }
38
- /**
39
- * Gets the filter operator
40
- */
41
- get operator() {
42
- return this._operator;
43
- }
44
- /**
45
- * Gets the filter value
46
- */
47
- get value() {
48
- return this._value;
49
- }
50
- /**
51
- * Returns configuration object for serialization
52
- */
53
- toConfig() {
54
- return {
55
- field: this._field,
56
- operator: this._operator,
57
- value: this._value,
58
- };
59
- }
60
- /**
61
- * Checks if the operator requires a value
62
- * @private
63
- */
64
- requiresValue() {
65
- return this._operator !== "isNull" && this._operator !== "isNotNull";
66
- }
67
- /**
68
- * Creates a predicate function for in-memory filtering
69
- * Handles nested properties using dot notation (e.g., "address.city")
70
- *
71
- * @example
72
- * ```typescript
73
- * const filter = new Filter<User>('age', 'greaterThan', 18);
74
- * const adults = users.filter(filter.predicateFn());
75
- * ```
76
- */
77
- predicateFn() {
78
- return (item) => {
79
- const fieldValue = this.getNestedValue(item, this._field);
80
- switch (this._operator) {
81
- case "equals":
82
- return fieldValue === this._value;
83
- case "notEquals":
84
- return fieldValue !== this._value;
85
- case "greaterThan":
86
- return fieldValue > this._value;
87
- case "greaterThanOrEquals":
88
- return fieldValue >= this._value;
89
- case "lessThan":
90
- return fieldValue < this._value;
91
- case "lessThanOrEquals":
92
- return fieldValue <= this._value;
93
- case "in":
94
- return Array.isArray(this._value) && this._value.includes(fieldValue);
95
- case "notIn":
96
- return Array.isArray(this._value) && !this._value.includes(fieldValue);
97
- case "contains":
98
- return (typeof fieldValue === "string" &&
99
- typeof this._value === "string" &&
100
- fieldValue.includes(this._value));
101
- case "startsWith":
102
- return (typeof fieldValue === "string" &&
103
- typeof this._value === "string" &&
104
- fieldValue.startsWith(this._value));
105
- case "endsWith":
106
- return (typeof fieldValue === "string" &&
107
- typeof this._value === "string" &&
108
- fieldValue.endsWith(this._value));
109
- case "isNull":
110
- return fieldValue === null || fieldValue === undefined;
111
- case "isNotNull":
112
- return fieldValue !== null && fieldValue !== undefined;
113
- default:
114
- // This should never happen with proper typing
115
- throw new Error(`Unknown filter operator: ${this._operator}`);
116
- }
117
- };
118
- }
119
- /**
120
- * Gets nested property value using dot notation
121
- * @private
122
- */
123
- getNestedValue(obj, path) {
124
- return path.split(".").reduce((current, prop) => current?.[prop], obj);
125
- }
126
- }
127
- exports.Filter = Filter;
128
- /**
129
- * Represents a composite filter that combines multiple filters with AND/OR logic
130
- *
131
- * @example
132
- * ```typescript
133
- * const composite = new CompositeFilter<User>('and', [
134
- * new Filter('age', 'greaterThan', 18),
135
- * new Filter('status', 'equals', 'active')
136
- * ]);
137
- * const filtered = users.filter(composite.predicateFn());
138
- * ```
139
- */
140
- class CompositeFilter {
141
- constructor(operator, filters) {
142
- if (filters.length === 0) {
143
- throw new Error("At least one filter is required");
144
- }
145
- this._operator = operator;
146
- this._filters = filters;
147
- }
148
- /**
149
- * Gets the logical operator
150
- */
151
- get operator() {
152
- return this._operator;
153
- }
154
- /**
155
- * Gets all filters
156
- */
157
- get filters() {
158
- return this._filters;
159
- }
160
- /**
161
- * Creates a predicate function that applies the logical operator
162
- */
163
- predicateFn() {
164
- return (item) => {
165
- if (this._operator === "and") {
166
- return this._filters.every((filter) => filter.predicateFn()(item));
167
- }
168
- else {
169
- // OR
170
- return this._filters.some((filter) => filter.predicateFn()(item));
171
- }
172
- };
173
- }
174
- /**
175
- * Adds another filter with AND logic
176
- */
177
- and(filter) {
178
- if (this._operator === "and") {
179
- // Flatten if already AND
180
- return new CompositeFilter("and", [...this._filters, filter]);
181
- }
182
- else {
183
- // Wrap in new AND
184
- return new CompositeFilter("and", [this, filter]);
185
- }
186
- }
187
- /**
188
- * Adds another filter with OR logic
189
- */
190
- or(filter) {
191
- if (this._operator === "or") {
192
- // Flatten if already OR
193
- return new CompositeFilter("or", [...this._filters, filter]);
194
- }
195
- else {
196
- // Wrap in new OR
197
- return new CompositeFilter("or", [this, filter]);
198
- }
199
- }
200
- }
201
- exports.CompositeFilter = CompositeFilter;
202
- //# sourceMappingURL=filtering.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filtering.js","sourceRoot":"","sources":["../src/filtering.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAC/E,qFAAqF;AACrF,gFAAgF;;;AA6BhF,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E;;;;;;;;;GASG;AACH,MAAa,MAAM;IAKjB,YAAY,KAAuB,EAAE,QAAwB,EAAE,KAAW;QACxE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEpB,gDAAgD;QAChD,IAAI,IAAI,CAA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AE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;QACnE,CAAC;aAAM,CAAC;YACN,kBAAkB;YAClB,OAAO,IAAI,eAAe,CAAI,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,EAAE,CAAC,MAAsC;QACvC,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC5B,wBAAwB;YACxB,OAAO,IAAI,eAAe,CAAI,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;QAClE,CAAC;aAAM,CAAC;YACN,iBAAiB;YACjB,OAAO,IAAI,eAAe,CAAI,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;CACF;AAjED,0CAiEC"}
@@ -1,93 +0,0 @@
1
- /**
2
- * Direction for ordering
3
- */
4
- export type OrderDirection = "asc" | "desc";
5
- /**
6
- * Configuration for a single field ordering
7
- */
8
- export interface OrderByConfig<T> {
9
- field: keyof T | string;
10
- direction: OrderDirection;
11
- }
12
- /**
13
- * Represents ordering configuration for a specific field
14
- * Can be used for in-memory sorting or converted to database-specific queries
15
- *
16
- * @example
17
- * ```typescript
18
- * const orderBy = new OrderBy('name', 'asc');
19
- * const items = users.sort(orderBy.compareFn());
20
- * ```
21
- */
22
- export declare class OrderBy<T> {
23
- private readonly _field;
24
- private readonly _direction;
25
- constructor(field: keyof T | string, direction?: OrderDirection);
26
- /**
27
- * Gets the field to order by
28
- */
29
- get field(): keyof T | string;
30
- /**
31
- * Gets the order direction
32
- */
33
- get direction(): OrderDirection;
34
- /**
35
- * Returns configuration object for serialization
36
- */
37
- toConfig(): OrderByConfig<T>;
38
- /**
39
- * Creates a comparison function for in-memory sorting
40
- * Handles nested properties using dot notation (e.g., "address.city")
41
- *
42
- * @example
43
- * ```typescript
44
- * const orderBy = new OrderBy<User>('name', 'asc');
45
- * const sorted = users.sort(orderBy.compareFn());
46
- * ```
47
- */
48
- compareFn(): (a: T, b: T) => number;
49
- /**
50
- * Gets nested property value using dot notation
51
- * @private
52
- */
53
- private getNestedValue;
54
- /**
55
- * Creates a new OrderBy with reversed direction
56
- */
57
- reverse(): OrderBy<T>;
58
- }
59
- /**
60
- * Represents multiple ordering configurations
61
- * Allows sorting by multiple fields with different directions
62
- *
63
- * @example
64
- * ```typescript
65
- * const multiOrder = new MultiOrderBy<User>([
66
- * new OrderBy('status', 'asc'),
67
- * new OrderBy('name', 'asc')
68
- * ]);
69
- * const sorted = users.sort(multiOrder.compareFn());
70
- * ```
71
- */
72
- export declare class MultiOrderBy<T> {
73
- private readonly _orderings;
74
- constructor(orderings: OrderBy<T>[]);
75
- /**
76
- * Gets all ordering configurations
77
- */
78
- get orderings(): readonly OrderBy<T>[];
79
- /**
80
- * Returns array of configuration objects for serialization
81
- */
82
- toConfig(): OrderByConfig<T>[];
83
- /**
84
- * Creates a comparison function that applies all orderings in sequence
85
- * If first ordering produces a tie, moves to next ordering, and so on
86
- */
87
- compareFn(): (a: T, b: T) => number;
88
- /**
89
- * Adds another ordering to the end of the list
90
- */
91
- thenBy(field: keyof T | string, direction?: OrderDirection): MultiOrderBy<T>;
92
- }
93
- //# sourceMappingURL=ordering.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ordering.d.ts","sourceRoot":"","sources":["../src/ordering.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;IACxB,SAAS,EAAE,cAAc,CAAC;CAC3B;AAMD;;;;;;;;;GASG;AACH,qBAAa,OAAO,CAAC,CAAC;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;gBAEhC,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,EAAE,SAAS,GAAE,cAAsB;IAKtE;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAAC,GAAG,MAAM,CAE5B;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,cAAc,CAE9B;IAED;;OAEG;IACH,QAAQ,IAAI,aAAa,CAAC,CAAC,CAAC;IAO5B;;;;;;;;;OASG;IACH,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM;IAsBnC;;;OAGG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC;CAItB;AAMD;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAY,CAAC,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;gBAE9B,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE;IAOnC;;OAEG;IACH,IAAI,SAAS,IAAI,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,CAErC;IAED;;OAEG;IACH,QAAQ,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE;IAI9B;;;OAGG;IACH,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM;IAYnC;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,EAAE,SAAS,GAAE,cAAsB,GAAG,YAAY,CAAC,CAAC,CAAC;CAIpF"}
package/dist/ordering.js DELETED
@@ -1,154 +0,0 @@
1
- "use strict";
2
- // ============================================================================
3
- // Ordering System
4
- // ============================================================================
5
- // Provides ordering/sorting capabilities for queries and in-memory collections
6
- // Compatible with Entity, Aggregate, and ValueObject types
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.MultiOrderBy = exports.OrderBy = void 0;
9
- // ============================================================================
10
- // OrderBy Class
11
- // ============================================================================
12
- /**
13
- * Represents ordering configuration for a specific field
14
- * Can be used for in-memory sorting or converted to database-specific queries
15
- *
16
- * @example
17
- * ```typescript
18
- * const orderBy = new OrderBy('name', 'asc');
19
- * const items = users.sort(orderBy.compareFn());
20
- * ```
21
- */
22
- class OrderBy {
23
- constructor(field, direction = "asc") {
24
- this._field = field;
25
- this._direction = direction;
26
- }
27
- /**
28
- * Gets the field to order by
29
- */
30
- get field() {
31
- return this._field;
32
- }
33
- /**
34
- * Gets the order direction
35
- */
36
- get direction() {
37
- return this._direction;
38
- }
39
- /**
40
- * Returns configuration object for serialization
41
- */
42
- toConfig() {
43
- return {
44
- field: this._field,
45
- direction: this._direction,
46
- };
47
- }
48
- /**
49
- * Creates a comparison function for in-memory sorting
50
- * Handles nested properties using dot notation (e.g., "address.city")
51
- *
52
- * @example
53
- * ```typescript
54
- * const orderBy = new OrderBy<User>('name', 'asc');
55
- * const sorted = users.sort(orderBy.compareFn());
56
- * ```
57
- */
58
- compareFn() {
59
- return (a, b) => {
60
- const aValue = this.getNestedValue(a, this._field);
61
- const bValue = this.getNestedValue(b, this._field);
62
- // Handle null/undefined values
63
- if (aValue === null || aValue === undefined)
64
- return 1;
65
- if (bValue === null || bValue === undefined)
66
- return -1;
67
- // Compare values
68
- let comparison = 0;
69
- if (aValue > bValue) {
70
- comparison = 1;
71
- }
72
- else if (aValue < bValue) {
73
- comparison = -1;
74
- }
75
- // Apply direction
76
- return this._direction === "asc" ? comparison : -comparison;
77
- };
78
- }
79
- /**
80
- * Gets nested property value using dot notation
81
- * @private
82
- */
83
- getNestedValue(obj, path) {
84
- return path.split(".").reduce((current, prop) => current?.[prop], obj);
85
- }
86
- /**
87
- * Creates a new OrderBy with reversed direction
88
- */
89
- reverse() {
90
- const newDirection = this._direction === "asc" ? "desc" : "asc";
91
- return new OrderBy(this._field, newDirection);
92
- }
93
- }
94
- exports.OrderBy = OrderBy;
95
- // ============================================================================
96
- // MultiOrderBy Class
97
- // ============================================================================
98
- /**
99
- * Represents multiple ordering configurations
100
- * Allows sorting by multiple fields with different directions
101
- *
102
- * @example
103
- * ```typescript
104
- * const multiOrder = new MultiOrderBy<User>([
105
- * new OrderBy('status', 'asc'),
106
- * new OrderBy('name', 'asc')
107
- * ]);
108
- * const sorted = users.sort(multiOrder.compareFn());
109
- * ```
110
- */
111
- class MultiOrderBy {
112
- constructor(orderings) {
113
- if (orderings.length === 0) {
114
- throw new Error("At least one OrderBy is required");
115
- }
116
- this._orderings = orderings;
117
- }
118
- /**
119
- * Gets all ordering configurations
120
- */
121
- get orderings() {
122
- return this._orderings;
123
- }
124
- /**
125
- * Returns array of configuration objects for serialization
126
- */
127
- toConfig() {
128
- return this._orderings.map((o) => o.toConfig());
129
- }
130
- /**
131
- * Creates a comparison function that applies all orderings in sequence
132
- * If first ordering produces a tie, moves to next ordering, and so on
133
- */
134
- compareFn() {
135
- return (a, b) => {
136
- for (const ordering of this._orderings) {
137
- const comparison = ordering.compareFn()(a, b);
138
- if (comparison !== 0) {
139
- return comparison;
140
- }
141
- }
142
- return 0;
143
- };
144
- }
145
- /**
146
- * Adds another ordering to the end of the list
147
- */
148
- thenBy(field, direction = "asc") {
149
- const newOrderBy = new OrderBy(field, direction);
150
- return new MultiOrderBy([...this._orderings, newOrderBy]);
151
- }
152
- }
153
- exports.MultiOrderBy = MultiOrderBy;
154
- //# sourceMappingURL=ordering.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ordering.js","sourceRoot":"","sources":["../src/ordering.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAC/E,+EAA+E;AAC/E,2DAA2D;;;AAe3D,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E;;;;;;;;;GASG;AACH,MAAa,OAAO;IAIlB,YAAY,KAAuB,EAAE,YAA4B,KAAK;QACpE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,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