@woltz/rich-domain 0.2.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -75
- package/LICENSE +20 -20
- package/README.md +37 -20
- package/dist/base-entity.d.ts +2 -2
- package/dist/base-entity.d.ts.map +1 -1
- package/dist/base-entity.js +6 -4
- package/dist/base-entity.js.map +1 -1
- package/dist/criteria.d.ts +5 -11
- package/dist/criteria.d.ts.map +1 -1
- package/dist/criteria.js +4 -3
- package/dist/criteria.js.map +1 -1
- package/dist/deep-proxy.d.ts +3 -1
- package/dist/deep-proxy.d.ts.map +1 -1
- package/dist/deep-proxy.js +116 -29
- package/dist/deep-proxy.js.map +1 -1
- package/dist/domain-event-bus.d.ts +5 -6
- package/dist/domain-event-bus.d.ts.map +1 -1
- package/dist/domain-event-bus.js +3 -11
- package/dist/domain-event-bus.js.map +1 -1
- package/dist/domain-event.d.ts +1 -31
- package/dist/domain-event.d.ts.map +1 -1
- package/dist/domain-event.js +2 -1
- package/dist/domain-event.js.map +1 -1
- package/dist/entity.d.ts +2 -2
- package/dist/entity.js +1 -1
- package/dist/exceptions.d.ts +251 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +321 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/id.d.ts +3 -3
- package/dist/id.d.ts.map +1 -1
- package/dist/id.js +15 -4
- package/dist/id.js.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -8
- package/dist/index.js.map +1 -1
- package/dist/paginated-result.d.ts.map +1 -1
- package/dist/paginated-result.js +12 -1
- package/dist/paginated-result.js.map +1 -1
- package/dist/repository/index.d.ts +2 -39
- package/dist/repository/index.d.ts.map +1 -1
- package/dist/repository/index.js +2 -39
- package/dist/repository/index.js.map +1 -1
- package/dist/repository/unit-of-work.d.ts +0 -11
- package/dist/repository/unit-of-work.d.ts.map +1 -1
- package/dist/repository/unit-of-work.js +0 -35
- package/dist/repository/unit-of-work.js.map +1 -1
- package/dist/types/criteria.d.ts +6 -2
- package/dist/types/criteria.d.ts.map +1 -1
- package/dist/types/criteria.js +1 -1
- package/dist/types/criteria.js.map +1 -1
- package/dist/types/domain-event.d.ts +32 -0
- package/dist/types/domain-event.d.ts.map +1 -0
- package/dist/types/domain-event.js +2 -0
- package/dist/types/domain-event.js.map +1 -0
- package/dist/types/domain.d.ts +2 -2
- package/dist/types/domain.d.ts.map +1 -1
- package/dist/types/history-tracker.d.ts +1 -1
- package/dist/types/history-tracker.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/value-object.d.ts +1 -1
- package/dist/value-object.d.ts.map +1 -1
- package/dist/value-object.js +2 -5
- package/dist/value-object.js.map +1 -1
- package/eslint.config.js +3 -3
- package/jest.config.js +1 -1
- package/package.json +14 -20
- package/src/base-entity.ts +6 -5
- package/src/criteria.ts +11 -11
- package/src/deep-proxy.ts +447 -339
- package/src/domain-event-bus.ts +152 -166
- package/src/domain-event.ts +53 -90
- package/src/entity.ts +16 -16
- package/src/exceptions.ts +435 -0
- package/src/id.ts +107 -94
- package/src/index.ts +26 -9
- package/src/paginated-result.ts +14 -1
- package/src/repository/index.ts +2 -44
- package/src/repository/unit-of-work.ts +1 -44
- package/src/types/criteria.ts +7 -2
- package/src/types/domain-event.ts +38 -0
- package/src/types/domain.ts +2 -3
- package/src/types/history-tracker.ts +1 -1
- package/src/types/index.ts +1 -0
- package/src/validation-error.ts +97 -97
- package/src/value-object.ts +3 -6
- package/tests/criteria.test.ts +8 -0
- package/tests/domain-events.test.ts +431 -445
- package/tests/entity-validation.test.ts +2 -2
- package/tests/entity.test.ts +33 -33
- package/tests/history-tracker.spec.ts +57 -17
- package/tests/id.test.ts +341 -341
- package/tests/repository.test.ts +8 -4
- package/tests/to-json.test.ts +103 -91
- package/tests/utils.ts +254 -151
- package/tests/value-object-validation.test.ts +0 -9
- package/tests/value-objects.test.ts +52 -52
- package/tsconfig.json +2 -24
- package/.github/workflows/ci.yml +0 -40
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.vscode/settings.json +0 -3
- package/commitlint.config.js +0 -23
- package/dist/filtering.d.ts +0 -107
- package/dist/filtering.d.ts.map +0 -1
- package/dist/filtering.js +0 -202
- package/dist/filtering.js.map +0 -1
- package/dist/ordering.d.ts +0 -93
- package/dist/ordering.d.ts.map +0 -1
- package/dist/ordering.js +0 -154
- package/dist/ordering.js.map +0 -1
- package/dist/pagination.d.ts +0 -218
- package/dist/pagination.d.ts.map +0 -1
- package/dist/pagination.js +0 -281
- package/dist/pagination.js.map +0 -1
- package/dist/repository/in-memory-repository.d.ts +0 -50
- package/dist/repository/in-memory-repository.d.ts.map +0 -1
- package/dist/repository/in-memory-repository.js +0 -93
- package/dist/repository/in-memory-repository.js.map +0 -1
- package/dist/repository/mapper.d.ts +0 -56
- package/dist/repository/mapper.d.ts.map +0 -1
- package/dist/repository/mapper.js +0 -15
- package/dist/repository/mapper.js.map +0 -1
- package/dist/repository/types.d.ts +0 -87
- package/dist/repository/types.d.ts.map +0 -1
- package/dist/repository/types.js +0 -6
- package/dist/repository/types.js.map +0 -1
- package/dist/repository.d.ts +0 -2
- package/dist/repository.d.ts.map +0 -1
- package/dist/repository.js +0 -21
- package/dist/repository.js.map +0 -1
- package/dist/specification.d.ts +0 -102
- package/dist/specification.d.ts.map +0 -1
- package/dist/specification.js +0 -187
- package/dist/specification.js.map +0 -1
- package/dist/types/repository.d.ts +0 -43
- package/dist/types/repository.d.ts.map +0 -1
- package/dist/types/repository.js +0 -2
- package/dist/types/repository.js.map +0 -1
- package/dist/types.d.ts +0 -88
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -12
- package/dist/types.js.map +0 -1
- package/src/repository/in-memory-repository.ts +0 -116
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
|
package/dist/ordering.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
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OAAO,CAAC,CAAI,EAAE,CAAI,EAAU,EAAE;YAC5B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACvC,MAAM,UAAU,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC9C,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;oBACrB,OAAO,UAAU,CAAC;gBACpB,CAAC;YACH,CAAC;YACD,OAAO,CAAC,CAAC;QACX,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAuB,EAAE,YAA4B,KAAK;QAC/D,MAAM,UAAU,GAAG,IAAI,OAAO,CAAI,KAAK,EAAE,SAAS,CAAC,CAAC;QACpD,OAAO,IAAI,YAAY,CAAI,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;IAC/D,CAAC;CACF;AA/CD,oCA+CC"}
|
package/dist/pagination.d.ts
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type of pagination strategy
|
|
3
|
-
*/
|
|
4
|
-
export type PaginationType = "offset" | "cursor";
|
|
5
|
-
/**
|
|
6
|
-
* Configuration for offset-based pagination
|
|
7
|
-
*/
|
|
8
|
-
export interface OffsetPaginationConfig {
|
|
9
|
-
type: "offset";
|
|
10
|
-
page: number;
|
|
11
|
-
pageSize: number;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Configuration for cursor-based pagination
|
|
15
|
-
*/
|
|
16
|
-
export interface CursorPaginationConfig {
|
|
17
|
-
type: "cursor";
|
|
18
|
-
cursor?: string;
|
|
19
|
-
pageSize: number;
|
|
20
|
-
direction?: "forward" | "backward";
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Union type for all pagination configurations
|
|
24
|
-
*/
|
|
25
|
-
export type PaginationConfig = OffsetPaginationConfig | CursorPaginationConfig;
|
|
26
|
-
/**
|
|
27
|
-
* Represents offset-based pagination (traditional page-based pagination)
|
|
28
|
-
* Uses page number and page size to calculate offset
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* const pagination = new OffsetPagination(1, 20); // page 1, 20 items per page
|
|
33
|
-
* const { skip, take } = pagination.getSkipTake();
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare class OffsetPagination {
|
|
37
|
-
private readonly _page;
|
|
38
|
-
private readonly _pageSize;
|
|
39
|
-
constructor(page: number, pageSize: number);
|
|
40
|
-
/**
|
|
41
|
-
* Gets the current page number (1-indexed)
|
|
42
|
-
*/
|
|
43
|
-
get page(): number;
|
|
44
|
-
/**
|
|
45
|
-
* Gets the page size
|
|
46
|
-
*/
|
|
47
|
-
get pageSize(): number;
|
|
48
|
-
/**
|
|
49
|
-
* Gets the type of pagination
|
|
50
|
-
*/
|
|
51
|
-
get type(): PaginationType;
|
|
52
|
-
/**
|
|
53
|
-
* Calculates skip and take values for database queries
|
|
54
|
-
*/
|
|
55
|
-
getSkipTake(): {
|
|
56
|
-
skip: number;
|
|
57
|
-
take: number;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Returns configuration object for serialization
|
|
61
|
-
*/
|
|
62
|
-
toConfig(): OffsetPaginationConfig;
|
|
63
|
-
/**
|
|
64
|
-
* Applies pagination to an in-memory array
|
|
65
|
-
*/
|
|
66
|
-
apply<T>(items: T[]): T[];
|
|
67
|
-
/**
|
|
68
|
-
* Creates a new OffsetPagination for the next page
|
|
69
|
-
*/
|
|
70
|
-
nextPage(): OffsetPagination;
|
|
71
|
-
/**
|
|
72
|
-
* Creates a new OffsetPagination for the previous page
|
|
73
|
-
*/
|
|
74
|
-
previousPage(): OffsetPagination;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Represents cursor-based pagination
|
|
78
|
-
* Uses a cursor (typically an encoded string) to determine the starting point
|
|
79
|
-
* More efficient for large datasets and real-time data
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* const pagination = new CursorPagination('cursor_abc123', 20);
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
export declare class CursorPagination {
|
|
87
|
-
private readonly _cursor?;
|
|
88
|
-
private readonly _pageSize;
|
|
89
|
-
private readonly _direction;
|
|
90
|
-
constructor(cursor: string | undefined, pageSize: number, direction?: "forward" | "backward");
|
|
91
|
-
/**
|
|
92
|
-
* Gets the cursor (undefined for first page)
|
|
93
|
-
*/
|
|
94
|
-
get cursor(): string | undefined;
|
|
95
|
-
/**
|
|
96
|
-
* Gets the page size
|
|
97
|
-
*/
|
|
98
|
-
get pageSize(): number;
|
|
99
|
-
/**
|
|
100
|
-
* Gets the pagination direction
|
|
101
|
-
*/
|
|
102
|
-
get direction(): "forward" | "backward";
|
|
103
|
-
/**
|
|
104
|
-
* Gets the type of pagination
|
|
105
|
-
*/
|
|
106
|
-
get type(): PaginationType;
|
|
107
|
-
/**
|
|
108
|
-
* Checks if this is the first page (no cursor)
|
|
109
|
-
*/
|
|
110
|
-
isFirstPage(): boolean;
|
|
111
|
-
/**
|
|
112
|
-
* Returns configuration object for serialization
|
|
113
|
-
*/
|
|
114
|
-
toConfig(): CursorPaginationConfig;
|
|
115
|
-
/**
|
|
116
|
-
* Creates a new CursorPagination with a different cursor
|
|
117
|
-
*/
|
|
118
|
-
withCursor(cursor: string | undefined): CursorPagination;
|
|
119
|
-
/**
|
|
120
|
-
* Creates a new CursorPagination for backward navigation
|
|
121
|
-
*/
|
|
122
|
-
backward(): CursorPagination;
|
|
123
|
-
/**
|
|
124
|
-
* Creates a new CursorPagination for forward navigation
|
|
125
|
-
*/
|
|
126
|
-
forward(): CursorPagination;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Metadata for offset-based pagination results
|
|
130
|
-
*/
|
|
131
|
-
export interface OffsetPaginationMeta {
|
|
132
|
-
type: "offset";
|
|
133
|
-
page: number;
|
|
134
|
-
pageSize: number;
|
|
135
|
-
total: number;
|
|
136
|
-
totalPages: number;
|
|
137
|
-
hasNextPage: boolean;
|
|
138
|
-
hasPreviousPage: boolean;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Metadata for cursor-based pagination results
|
|
142
|
-
*/
|
|
143
|
-
export interface CursorPaginationMeta {
|
|
144
|
-
type: "cursor";
|
|
145
|
-
pageSize: number;
|
|
146
|
-
hasNextPage: boolean;
|
|
147
|
-
hasPreviousPage: boolean;
|
|
148
|
-
nextCursor?: string;
|
|
149
|
-
previousCursor?: string;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Union type for pagination metadata
|
|
153
|
-
*/
|
|
154
|
-
export type PaginationMeta = OffsetPaginationMeta | CursorPaginationMeta;
|
|
155
|
-
/**
|
|
156
|
-
* Represents a paginated result set
|
|
157
|
-
* Contains the data items and metadata about the pagination
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```typescript
|
|
161
|
-
* const result = new PaginatedResult(users, {
|
|
162
|
-
* type: 'offset',
|
|
163
|
-
* page: 1,
|
|
164
|
-
* pageSize: 20,
|
|
165
|
-
* total: 100,
|
|
166
|
-
* totalPages: 5,
|
|
167
|
-
* hasNextPage: true,
|
|
168
|
-
* hasPreviousPage: false
|
|
169
|
-
* });
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
export declare class PaginatedResult<T> {
|
|
173
|
-
private readonly _data;
|
|
174
|
-
private readonly _meta;
|
|
175
|
-
constructor(data: T[], meta: PaginationMeta);
|
|
176
|
-
/**
|
|
177
|
-
* Gets the data items
|
|
178
|
-
*/
|
|
179
|
-
get data(): readonly T[];
|
|
180
|
-
/**
|
|
181
|
-
* Gets the pagination metadata
|
|
182
|
-
*/
|
|
183
|
-
get meta(): PaginationMeta;
|
|
184
|
-
/**
|
|
185
|
-
* Gets the count of items in current page
|
|
186
|
-
*/
|
|
187
|
-
get count(): number;
|
|
188
|
-
/**
|
|
189
|
-
* Checks if there is a next page
|
|
190
|
-
*/
|
|
191
|
-
hasNextPage(): boolean;
|
|
192
|
-
/**
|
|
193
|
-
* Checks if there is a previous page
|
|
194
|
-
*/
|
|
195
|
-
hasPreviousPage(): boolean;
|
|
196
|
-
/**
|
|
197
|
-
* Maps the data items to a new type
|
|
198
|
-
*/
|
|
199
|
-
map<U>(fn: (item: T) => U): PaginatedResult<U>;
|
|
200
|
-
/**
|
|
201
|
-
* Converts to plain object for serialization
|
|
202
|
-
*/
|
|
203
|
-
toJson(): {
|
|
204
|
-
data: T[];
|
|
205
|
-
meta: PaginationMeta;
|
|
206
|
-
};
|
|
207
|
-
/**
|
|
208
|
-
* Creates an offset-based paginated result from an array and pagination config
|
|
209
|
-
* Automatically calculates metadata
|
|
210
|
-
*/
|
|
211
|
-
static fromArray<T>(allItems: T[], pagination: OffsetPagination): PaginatedResult<T>;
|
|
212
|
-
/**
|
|
213
|
-
* Creates a cursor-based paginated result
|
|
214
|
-
* Requires cursors to be calculated externally
|
|
215
|
-
*/
|
|
216
|
-
static fromCursor<T>(data: T[], pagination: CursorPagination, nextCursor?: string, previousCursor?: string): PaginatedResult<T>;
|
|
217
|
-
}
|
|
218
|
-
//# sourceMappingURL=pagination.d.ts.map
|
package/dist/pagination.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,Q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IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACH,eAAe,IAAI,OAAO;IAI1B;;OAEG;IACH,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC;IAI9C;;OAEG;IACH,MAAM,IAAI;QAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAAC,IAAI,EAAE,cAAc,CAAA;KAAE;IAO7C;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,EAChB,QAAQ,EAAE,CAAC,EAAE,EACb,UAAU,EAAE,gBAAgB,GAC3B,eAAe,CAAC,CAAC,CAAC;IAmBrB;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,CAAC,EACjB,IAAI,EAAE,CAAC,EAAE,EACT,UAAU,EAAE,gBAAgB,EAC5B,UAAU,CAAC,EAAE,MAAM,EACnB,cAAc,CAAC,EAAE,MAAM,GACtB,eAAe,CAAC,CAAC,CAAC;CAYtB"}
|
package/dist/pagination.js
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// ============================================================================
|
|
3
|
-
// Pagination System
|
|
4
|
-
// ============================================================================
|
|
5
|
-
// Provides offset-based and cursor-based pagination capabilities
|
|
6
|
-
// Can be used for in-memory pagination or converted to database-specific queries
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.PaginatedResult = exports.CursorPagination = exports.OffsetPagination = void 0;
|
|
9
|
-
// ============================================================================
|
|
10
|
-
// OffsetPagination Class
|
|
11
|
-
// ============================================================================
|
|
12
|
-
/**
|
|
13
|
-
* Represents offset-based pagination (traditional page-based pagination)
|
|
14
|
-
* Uses page number and page size to calculate offset
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const pagination = new OffsetPagination(1, 20); // page 1, 20 items per page
|
|
19
|
-
* const { skip, take } = pagination.getSkipTake();
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
class OffsetPagination {
|
|
23
|
-
constructor(page, pageSize) {
|
|
24
|
-
if (page < 1) {
|
|
25
|
-
throw new Error("Page must be greater than or equal to 1");
|
|
26
|
-
}
|
|
27
|
-
if (pageSize < 1) {
|
|
28
|
-
throw new Error("Page size must be greater than or equal to 1");
|
|
29
|
-
}
|
|
30
|
-
this._page = page;
|
|
31
|
-
this._pageSize = pageSize;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Gets the current page number (1-indexed)
|
|
35
|
-
*/
|
|
36
|
-
get page() {
|
|
37
|
-
return this._page;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Gets the page size
|
|
41
|
-
*/
|
|
42
|
-
get pageSize() {
|
|
43
|
-
return this._pageSize;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Gets the type of pagination
|
|
47
|
-
*/
|
|
48
|
-
get type() {
|
|
49
|
-
return "offset";
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Calculates skip and take values for database queries
|
|
53
|
-
*/
|
|
54
|
-
getSkipTake() {
|
|
55
|
-
return {
|
|
56
|
-
skip: (this._page - 1) * this._pageSize,
|
|
57
|
-
take: this._pageSize,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Returns configuration object for serialization
|
|
62
|
-
*/
|
|
63
|
-
toConfig() {
|
|
64
|
-
return {
|
|
65
|
-
type: "offset",
|
|
66
|
-
page: this._page,
|
|
67
|
-
pageSize: this._pageSize,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Applies pagination to an in-memory array
|
|
72
|
-
*/
|
|
73
|
-
apply(items) {
|
|
74
|
-
const { skip, take } = this.getSkipTake();
|
|
75
|
-
return items.slice(skip, skip + take);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Creates a new OffsetPagination for the next page
|
|
79
|
-
*/
|
|
80
|
-
nextPage() {
|
|
81
|
-
return new OffsetPagination(this._page + 1, this._pageSize);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Creates a new OffsetPagination for the previous page
|
|
85
|
-
*/
|
|
86
|
-
previousPage() {
|
|
87
|
-
if (this._page <= 1) {
|
|
88
|
-
throw new Error("Already on first page");
|
|
89
|
-
}
|
|
90
|
-
return new OffsetPagination(this._page - 1, this._pageSize);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.OffsetPagination = OffsetPagination;
|
|
94
|
-
// ============================================================================
|
|
95
|
-
// CursorPagination Class
|
|
96
|
-
// ============================================================================
|
|
97
|
-
/**
|
|
98
|
-
* Represents cursor-based pagination
|
|
99
|
-
* Uses a cursor (typically an encoded string) to determine the starting point
|
|
100
|
-
* More efficient for large datasets and real-time data
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* const pagination = new CursorPagination('cursor_abc123', 20);
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
class CursorPagination {
|
|
108
|
-
constructor(cursor, pageSize, direction = "forward") {
|
|
109
|
-
if (pageSize < 1) {
|
|
110
|
-
throw new Error("Page size must be greater than or equal to 1");
|
|
111
|
-
}
|
|
112
|
-
this._cursor = cursor;
|
|
113
|
-
this._pageSize = pageSize;
|
|
114
|
-
this._direction = direction;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Gets the cursor (undefined for first page)
|
|
118
|
-
*/
|
|
119
|
-
get cursor() {
|
|
120
|
-
return this._cursor;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Gets the page size
|
|
124
|
-
*/
|
|
125
|
-
get pageSize() {
|
|
126
|
-
return this._pageSize;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Gets the pagination direction
|
|
130
|
-
*/
|
|
131
|
-
get direction() {
|
|
132
|
-
return this._direction;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Gets the type of pagination
|
|
136
|
-
*/
|
|
137
|
-
get type() {
|
|
138
|
-
return "cursor";
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Checks if this is the first page (no cursor)
|
|
142
|
-
*/
|
|
143
|
-
isFirstPage() {
|
|
144
|
-
return this._cursor === undefined;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Returns configuration object for serialization
|
|
148
|
-
*/
|
|
149
|
-
toConfig() {
|
|
150
|
-
return {
|
|
151
|
-
type: "cursor",
|
|
152
|
-
cursor: this._cursor,
|
|
153
|
-
pageSize: this._pageSize,
|
|
154
|
-
direction: this._direction,
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Creates a new CursorPagination with a different cursor
|
|
159
|
-
*/
|
|
160
|
-
withCursor(cursor) {
|
|
161
|
-
return new CursorPagination(cursor, this._pageSize, this._direction);
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Creates a new CursorPagination for backward navigation
|
|
165
|
-
*/
|
|
166
|
-
backward() {
|
|
167
|
-
return new CursorPagination(this._cursor, this._pageSize, "backward");
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Creates a new CursorPagination for forward navigation
|
|
171
|
-
*/
|
|
172
|
-
forward() {
|
|
173
|
-
return new CursorPagination(this._cursor, this._pageSize, "forward");
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
exports.CursorPagination = CursorPagination;
|
|
177
|
-
/**
|
|
178
|
-
* Represents a paginated result set
|
|
179
|
-
* Contains the data items and metadata about the pagination
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* ```typescript
|
|
183
|
-
* const result = new PaginatedResult(users, {
|
|
184
|
-
* type: 'offset',
|
|
185
|
-
* page: 1,
|
|
186
|
-
* pageSize: 20,
|
|
187
|
-
* total: 100,
|
|
188
|
-
* totalPages: 5,
|
|
189
|
-
* hasNextPage: true,
|
|
190
|
-
* hasPreviousPage: false
|
|
191
|
-
* });
|
|
192
|
-
* ```
|
|
193
|
-
*/
|
|
194
|
-
class PaginatedResult {
|
|
195
|
-
constructor(data, meta) {
|
|
196
|
-
this._data = data;
|
|
197
|
-
this._meta = meta;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Gets the data items
|
|
201
|
-
*/
|
|
202
|
-
get data() {
|
|
203
|
-
return this._data;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Gets the pagination metadata
|
|
207
|
-
*/
|
|
208
|
-
get meta() {
|
|
209
|
-
return this._meta;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Gets the count of items in current page
|
|
213
|
-
*/
|
|
214
|
-
get count() {
|
|
215
|
-
return this._data.length;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Checks if there is a next page
|
|
219
|
-
*/
|
|
220
|
-
hasNextPage() {
|
|
221
|
-
return this._meta.hasNextPage;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Checks if there is a previous page
|
|
225
|
-
*/
|
|
226
|
-
hasPreviousPage() {
|
|
227
|
-
return this._meta.hasPreviousPage;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Maps the data items to a new type
|
|
231
|
-
*/
|
|
232
|
-
map(fn) {
|
|
233
|
-
return new PaginatedResult(this._data.map(fn), this._meta);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Converts to plain object for serialization
|
|
237
|
-
*/
|
|
238
|
-
toJson() {
|
|
239
|
-
return {
|
|
240
|
-
data: this._data,
|
|
241
|
-
meta: this._meta,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Creates an offset-based paginated result from an array and pagination config
|
|
246
|
-
* Automatically calculates metadata
|
|
247
|
-
*/
|
|
248
|
-
static fromArray(allItems, pagination) {
|
|
249
|
-
const { skip, take } = pagination.getSkipTake();
|
|
250
|
-
const data = allItems.slice(skip, skip + take);
|
|
251
|
-
const total = allItems.length;
|
|
252
|
-
const totalPages = Math.ceil(total / pagination.pageSize);
|
|
253
|
-
const meta = {
|
|
254
|
-
type: "offset",
|
|
255
|
-
page: pagination.page,
|
|
256
|
-
pageSize: pagination.pageSize,
|
|
257
|
-
total,
|
|
258
|
-
totalPages,
|
|
259
|
-
hasNextPage: pagination.page < totalPages,
|
|
260
|
-
hasPreviousPage: pagination.page > 1,
|
|
261
|
-
};
|
|
262
|
-
return new PaginatedResult(data, meta);
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Creates a cursor-based paginated result
|
|
266
|
-
* Requires cursors to be calculated externally
|
|
267
|
-
*/
|
|
268
|
-
static fromCursor(data, pagination, nextCursor, previousCursor) {
|
|
269
|
-
const meta = {
|
|
270
|
-
type: "cursor",
|
|
271
|
-
pageSize: pagination.pageSize,
|
|
272
|
-
hasNextPage: nextCursor !== undefined,
|
|
273
|
-
hasPreviousPage: previousCursor !== undefined,
|
|
274
|
-
nextCursor,
|
|
275
|
-
previousCursor,
|
|
276
|
-
};
|
|
277
|
-
return new PaginatedResult(data, meta);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
exports.PaginatedResult = PaginatedResult;
|
|
281
|
-
//# sourceMappingURL=pagination.js.map
|
package/dist/pagination.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAC/E,iEAAiE;AACjE,iFAAiF;;;AA+BjF,+EAA+E;AAC/E,yBAAyB;AACzB,+EAA+E;AAE/E;;;;;;;;;GASG;AACH,MAAa,gBAAgB;IAI3B,YAAY,IAAY,EAAE,QAAgB;QACxC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;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