weaviate-client
Version:
JS/TS client for Weaviate
62 lines (61 loc) • 1.79 kB
JavaScript
import { CommandBase } from '../validation/commandBase.js';
export default class GetterById extends CommandBase {
additional;
className;
id;
consistencyLevel;
nodeName;
tenant;
objectsPath;
constructor(client, objectsPath) {
super(client);
this.objectsPath = objectsPath;
this.additional = [];
}
withId = (id) => {
this.id = id;
return this;
};
withClassName = (className) => {
this.className = className;
return this;
};
withTenant = (tenant) => {
this.tenant = tenant;
return this;
};
extendAdditional = (prop) => {
this.additional = [...this.additional, prop];
return this;
};
withAdditional = (additionalFlag) => this.extendAdditional(additionalFlag);
withVector = () => this.extendAdditional('vector');
withConsistencyLevel = (cl) => {
this.consistencyLevel = cl;
return this;
};
withNodeName = (nodeName) => {
this.nodeName = nodeName;
return this;
};
validateId = () => {
if (this.id == undefined || this.id == null || this.id.length == 0) {
this.addError('id must be set - initialize with getterById(id)');
}
};
validate = () => {
this.validateId();
};
buildPath = () => {
return this.objectsPath.buildGetOne(this.id, this.className, this.additional, this.consistencyLevel, this.nodeName, this.tenant);
};
do = () => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
}
return this.buildPath().then((path) => {
return this.client.get(path);
});
};
}