-
Notifications
You must be signed in to change notification settings - Fork 1
/
Adapter.ts
74 lines (56 loc) · 2.14 KB
/
Adapter.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
import {EventEmitter} from 'nomatic-events';
import Query from '../Query';
import {RecordData} from '../Record';
export interface AdapterOptions {
name: string;
maxListeners?: number;
}
export abstract class Adapter extends EventEmitter {
private _name: string;
constructor (options: AdapterOptions) {
super(options.maxListeners || 0);
this.name = options.name;
}
public get name() {
return this._name;
}
public set name(name: string) {
this._name = name;
}
/**
* Create a collection to store records.
*/
public abstract createCollection (name: string): Promise<boolean>;
/**
* Ensure that a collection exists. This method must be guaranteed not to throw if the collection already
* exists.
*/
public abstract ensureCollectionExists (name: string): Promise<boolean>;
/**
* Drop a collection.
*/
public abstract dropCollection (name: string): Promise<boolean>;
public abstract get (collection: string, id: string): Promise<RecordData>;
/**
* Get the name of each collection already defined.
*/
public abstract getCollectionNames (): Promise<string[]>;
public abstract findAll (collection: string, query?: Query): Promise<RecordData[]>;
public abstract insert (collection: string, data: RecordData): Promise<RecordData>;
public abstract insertAll (collection: string, data: RecordData[]): Promise<RecordData[]>;
/**
* Establish a connection and/or do anything needed in order to accept queries.
*/
public load (): Promise<boolean> {
return Promise.resolve(true);
}
public abstract remove (collection: string, id: string): Promise<RecordData>;
public abstract replace(collection: string, id: string, data: RecordData, rev?: string): Promise<RecordData>;
/**
* Remove all records from the collection, but keep the collection itself and all
* related settings.
*/
public abstract truncateCollection (name: string): Promise<boolean>;
public abstract update (collection: string, id: string, data: RecordData): Promise<RecordData>;
}
export default Adapter;