forked from Sairyss/domain-driven-hexagon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repository.ports.ts
78 lines (64 loc) · 1.92 KB
/
repository.ports.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { BaseEntityProps } from '../base-classes/entity.base';
import { DeepPartial } from '../../../types';
import { ID } from '../value-objects/id.value-object';
/* Most of repositories will probably need generic
save/find/delete operations, so it's easier
to have some shared interfaces.
More specific interfaces should be defined
in a respective module/use case.
*/
export type QueryParams<EntityProps> = DeepPartial<
BaseEntityProps & EntityProps
>;
export interface Save<Entity> {
save(entity: Entity): Promise<Entity>;
}
export interface SaveMultiple<Entity> {
saveMultiple(entities: Entity[]): Promise<Entity[]>;
}
export interface FindOne<Entity, EntityProps> {
findOneOrThrow(params: QueryParams<EntityProps>): Promise<Entity>;
}
export interface FindOneById<Entity> {
findOneByIdOrThrow(id: ID | string): Promise<Entity>;
}
export interface FindMany<Entity, EntityProps> {
findMany(params: QueryParams<EntityProps>): Promise<Entity[]>;
}
export interface OrderBy {
[key: number]: -1 | 1;
}
export interface PaginationMeta {
skip?: number;
limit?: number;
page?: number;
}
export interface FindManyPaginatedParams<EntityProps> {
params?: QueryParams<EntityProps>;
pagination?: PaginationMeta;
orderBy?: OrderBy;
}
export interface DataWithPaginationMeta<T> {
data: T;
count: number;
limit?: number;
page?: number;
}
export interface FindManyPaginated<Entity, EntityProps> {
findManyPaginated(
options: FindManyPaginatedParams<EntityProps>,
): Promise<DataWithPaginationMeta<Entity[]>>;
}
export interface DeleteOne<Entity> {
delete(entity: Entity): Promise<Entity>;
}
export interface RepositoryPort<Entity, EntityProps>
extends Save<Entity>,
FindOne<Entity, EntityProps>,
FindOneById<Entity>,
FindMany<Entity, EntityProps>,
FindManyPaginated<Entity, EntityProps>,
DeleteOne<Entity>,
SaveMultiple<Entity> {
setCorrelationId(correlationId: string): this;
}