UNPKG

weaviate-client

Version:
50 lines (49 loc) • 1.44 kB
import { CommandBase } from '../validation/commandBase.js'; export default class Checker extends CommandBase { className; consistencyLevel; id; tenant; objectsPath; constructor(client, objectsPath) { super(client); this.objectsPath = objectsPath; } withId = (id) => { this.id = id; return this; }; withClassName = (className) => { this.className = className; return this; }; withTenant = (tenant) => { this.tenant = tenant; return this; }; withConsistencyLevel = (consistencyLevel) => { this.consistencyLevel = consistencyLevel; return this; }; buildPath = () => { return this.objectsPath.buildCheck(this.id, this.className, this.consistencyLevel, this.tenant); }; validateIsSet = (prop, name, setter) => { if (prop == undefined || prop == null || prop.length == 0) { this.addError(`${name} must be set - set with ${setter}`); } }; validateId = () => { this.validateIsSet(this.id, 'id', '.withId(id)'); }; validate = () => { this.validateId(); }; do = () => { if (this.errors.length > 0) { return Promise.reject(new Error('invalid usage: ' + this.errors.join(', '))); } this.validate(); return this.buildPath().then((path) => this.client.head(path, undefined)); }; }