weaviate-client
Version:
JS/TS client for Weaviate
44 lines (43 loc) • 1.24 kB
JavaScript
import { CommandBase } from '../validation/commandBase.js';
import { isValidStringProperty } from '../validation/string.js';
export default class Validator extends CommandBase {
className;
id;
properties;
constructor(client) {
super(client);
}
withClassName = (className) => {
this.className = className;
return this;
};
withProperties = (properties) => {
this.properties = properties;
return this;
};
withId = (id) => {
this.id = id;
return this;
};
validateClassName = () => {
if (!isValidStringProperty(this.className)) {
this.addError('className must be set - set with .withClassName(className)');
}
};
payload = () => ({
properties: this.properties,
class: this.className,
id: this.id,
});
validate = () => {
this.validateClassName();
};
do = () => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
}
const path = `/objects/validate`;
return this.client.postEmpty(path, this.payload()).then(() => true);
};
}