-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgetter.ts
59 lines (47 loc) · 1.34 KB
/
getter.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
import Connection from "../connection";
import {ObjectsPath} from "./path";
import {CommandBase} from "../validation/commandBase";
export default class Getter extends CommandBase {
private additionals: any[];
private after?: string
private className?: string;
private limit?: number;
private objectsPath: ObjectsPath;
constructor(client: Connection, objectsPath: ObjectsPath) {
super(client)
this.objectsPath = objectsPath;
this.additionals = [];
}
withClassName = (className: string) => {
this.className = className;
return this;
};
withAfter = (id: string) => {
this.after = id;
return this;
};
withLimit = (limit: number) => {
this.limit = limit;
return this;
};
extendAdditionals = (prop: any) => {
this.additionals = [...this.additionals, prop];
return this;
};
withAdditional = (additionalFlag: any) => this.extendAdditionals(additionalFlag);
withVector = () => this.extendAdditionals("vector");
validate() {
// nothing to validate
}
do = () => {
if (this.errors.length > 0) {
return Promise.reject(
new Error("invalid usage: " + this.errors.join(", "))
);
}
return this.objectsPath.buildGet(this.className, this.limit, this.additionals!, this.after!)
.then((path: string) => {
return this.client.get(path)
})
};
}