-
Notifications
You must be signed in to change notification settings - Fork 6
/
CosmosProjectorStore.ts
68 lines (59 loc) · 1.7 KB
/
CosmosProjectorStore.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
import type { AggQuery, ProjectorStore, State } from "@rotorsoft/eventually";
import { dispose, log } from "@rotorsoft/eventually";
export const CosmosProjectorStore = <S extends State>(
table: string
): ProjectorStore<S> => {
const store: ProjectorStore<S> = {
name: `CosmosProjectorStore:${table}`,
dispose: () => {
// TODO await dispose resources
throw Error("Not implemented");
},
seed: (schema, indexes) => {
// TODO await seed store
console.log({ schema, indexes });
throw Error("Not implemented");
},
drop: () => {
// TODO await drop store
throw Error("Not implemented");
},
load: (ids) => {
// TODO await loading records by id
console.log({ ids });
throw Error("Not implemented");
},
commit: (map, watermark) => {
// TODO await steps
// - handle filtered deletes
// - handle filtered updates
// - prepare patched records (upserts and deletes)
// - connect
// - open transaction
// - apply patches
// - commit or rollback transaction
// - release connection
console.log({ map, watermark });
throw Error("Not implemented");
},
query: (query) => {
// TODO await query results
console.log({ query });
throw Error("Not implemented");
},
agg: (query: AggQuery<S>) => {
// TODO await query results
console.log({ query });
throw Error("Not implemented");
}
};
log().info(`[${process.pid}] ✨ ${store.name}`);
dispose(() => {
if (store.dispose) {
log().info(`[${process.pid}] ♻️ ${store.name}`);
return store.dispose();
}
return Promise.resolve();
});
return store;
};