-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathreferencePayloadBuilder.ts
84 lines (71 loc) · 1.98 KB
/
referencePayloadBuilder.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 Connection from "../connection";
import {CommandBase} from "../validation/commandBase";
export default class ReferencesBatcher extends CommandBase {
private fromClassName?: string;
private fromId?: string;
private fromRefProp?: string;
private toClassName?: string;
private toId?: string;
constructor(client: Connection) {
super(client)
}
withFromId = (id: string) => {
this.fromId = id;
return this;
};
withToId = (id: string) => {
this.toId = id;
return this;
};
withFromClassName = (className: string) => {
this.fromClassName = className;
return this;
};
withFromRefProp = (refProp: string) => {
this.fromRefProp = refProp;
return this;
};
withToClassName(className: string) {
this.toClassName = className;
return this;
}
validateIsSet = (prop: string | undefined | null, name: string, setter: string) => {
if (prop == undefined || prop == null || prop.length == 0) {
this.addError(`${name} must be set - set with ${setter}`)
}
};
validate = () => {
this.validateIsSet(this.fromId, "fromId", ".withFromId(id)");
this.validateIsSet(this.toId, "toId", ".withToId(id)");
this.validateIsSet(
this.fromClassName,
"fromClassName",
".withFromClassName(className)"
);
this.validateIsSet(
this.fromRefProp,
"fromRefProp",
".withFromRefProp(refProp)"
);
};
payload = () => {
this.validate();
if (this.errors.length > 0) {
throw new Error(this.errors.join(", "));
}
var beaconTo = `weaviate://localhost`;
if (isValidStringProperty(this.toClassName)) {
beaconTo = `${beaconTo}/${this.toClassName}`;
}
return {
from:
`weaviate://localhost/${this.fromClassName}` +
`/${this.fromId}/${this.fromRefProp}`,
to: `${beaconTo}/${this.toId}`,
};
};
do(): Promise<any> {
return Promise.reject('Should never be called');
}
}