UNPKG

weaviate-client

Version:
45 lines (44 loc) • 1.44 kB
import { CommandBase } from '../validation/commandBase.js'; export default class ExtensionCreator extends CommandBase { concept; definition; weight; constructor(client) { super(client); } withConcept = (concept) => { this.concept = concept; return this; }; withDefinition = (definition) => { this.definition = definition; return this; }; withWeight = (weight) => { this.weight = weight; return this; }; validateIsSet = (prop, name, setter) => { if (prop == undefined || prop == null || prop.length == 0) { this.addError(`${name} must be set - set with ${setter}`); } }; validate = () => { this.validateIsSet(this.concept, 'concept', 'withConcept(concept)'); this.validateIsSet(this.definition, 'definition', 'withDefinition(definition)'); this.validateIsSet(this.weight?.toString() || '', 'weight', 'withWeight(weight)'); }; payload = () => ({ concept: this.concept, definition: this.definition, weight: this.weight, }); do = () => { this.validate(); if (this.errors.length > 0) { return Promise.reject(new Error('invalid usage: ' + this.errors.join(', '))); } const path = `/modules/text2vec-contextionary/extensions`; return this.client.postReturn(path, this.payload()); }; }