-
Notifications
You must be signed in to change notification settings - Fork 20
/
types.ts
78 lines (68 loc) · 1.86 KB
/
types.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 { StoreObject } from 'brewblox-proto/ts';
export type ChangeCb<T> = (obj: T) => unknown;
export type DeleteCb = (id: string) => unknown;
export interface EventHandler<T = StoreObject> {
namespace: string;
onChanged: ChangeCb<T>;
onDeleted: DeleteCb;
}
export interface BrewbloxDatabase {
/**
* Connect to actual database.
* Is called by App.vue during create
*/
connect(): Awaitable<void>;
/**
* Be notified of external changes to a collection.
*
* @param handler Object containing callbacks
*/
subscribe(handler: EventHandler): void;
/**
* Fetch all documents from the collection with matching namespace.
*
* @param namespace collection identifier.
*/
fetchAll<T extends StoreObject>(namespace: string): Promise<T[]>;
/**
* Fetch a single document.
*
* @param namespace collection ID.
* @param objId unique document ID.
*/
fetchById<T extends StoreObject>(
namespace: string,
objId: string,
): Promise<T | null>;
/**
* Save a new document to the store.
*
* @param namespace collection ID.
* @param obj document. Its ID should be unique.
*/
create<T extends StoreObject>(namespace: string, obj: T): Promise<T>;
/**
* Save an already created document.
*
* @param namespace collection ID.
* @param obj existing document in the database.
*/
persist<T extends StoreObject>(namespace: string, obj: T): Promise<T>;
/**
* Save multiple documents
*
* @param namespace collection ID
* @param objs existing documents in the database
*/
persistMult<T extends StoreObject>(
namespace: string,
objs: T[],
): Promise<T[]>;
/**
* Remove an existing document from the store.
*
* @param namespace collection ID.
* @param obj existing document in the database.
*/
remove<T extends StoreObject>(namespace: string, obj: T): Promise<T>;
}