forked from castore-dev/castore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storageAdapter.ts
56 lines (48 loc) · 1.33 KB
/
storageAdapter.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
import { EventDetail } from 'event/eventDetail';
import type { Aggregate } from '~/aggregate';
export type EventsQueryOptions = {
minVersion?: number;
maxVersion?: number;
limit?: number;
reverse?: boolean;
};
export type PushEventContext = { eventStoreId?: string };
export type ListAggregateIdsOptions = {
limit?: number;
pageToken?: string;
};
export type ListAggregateIdsOutput = {
aggregateIds: string[];
nextPageToken?: string;
};
export type GetLastSnapshotOptions = {
maxVersion?: number;
};
export type ListSnapshotsOptions = {
minVersion?: number;
maxVersion?: number;
limit?: number;
reverse?: boolean;
};
export interface StorageAdapter {
getEvents: (
aggregateId: string,
options?: EventsQueryOptions,
) => Promise<{ events: EventDetail[] }>;
pushEvent: (
eventDetail: Omit<EventDetail, 'timestamp'>,
context: PushEventContext,
) => Promise<{ event: EventDetail }>;
listAggregateIds: (
options?: ListAggregateIdsOptions,
) => Promise<ListAggregateIdsOutput>;
putSnapshot: (aggregate: Aggregate) => Promise<void>;
getLastSnapshot: (
aggregateId: string,
options?: GetLastSnapshotOptions,
) => Promise<{ snapshot: Aggregate | undefined }>;
listSnapshots: (
aggregateId: string,
options?: ListSnapshotsOptions,
) => Promise<{ snapshots: Aggregate[] }>;
}