-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathobjectsBatchDeleter.ts
84 lines (72 loc) · 1.88 KB
/
objectsBatchDeleter.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
79
80
81
82
83
84
import { isValidStringProperty } from "../validation/string";
import { buildObjectsPath } from "./path"
import Connection from "../connection";
import {CommandBase} from "../validation/commandBase";
export default class ObjectsBatchDeleter extends CommandBase {
private className?: string;
private consistencyLevel?: string
private dryRun?: boolean;
private output?: any;
private whereFilter?: any;
constructor(client: Connection) {
super(client)
}
withClassName(className: string) {
this.className = className;
return this;
}
withWhere(whereFilter: any) {
this.whereFilter = whereFilter;
return this;
}
withOutput(output: any) {
this.output = output;
return this;
}
withDryRun(dryRun: boolean) {
this.dryRun = dryRun;
return this;
}
withConsistencyLevel = (cl: string) => {
this.consistencyLevel = cl;
return this;
};
payload() {
return {
match: {
class: this.className,
where: this.whereFilter,
},
output: this.output,
dryRun: this.dryRun,
}
}
validateClassName() {
if (!isValidStringProperty(this.className)) {
this.addError("string className must be set - set with .withClassName(className)")
}
}
validateWhereFilter() {
if (typeof this.whereFilter != "object") {
this.addError("object where must be set - set with .withWhere(whereFilter)")
}
}
validate() {
this.validateClassName();
this.validateWhereFilter();
};
do() {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(
new Error("invalid usage: " + this.errors.join(", "))
);
}
let params = new URLSearchParams()
if (this.consistencyLevel) {
params.set("consistency_level", this.consistencyLevel)
}
const path = buildObjectsPath(params);
return this.client.delete(path, this.payload(), true);
};
}