UNPKG

weaviate-client

Version:
48 lines (47 loc) • 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const commandBase_js_1 = require("../validation/commandBase.js"); class ExtensionCreator extends commandBase_js_1.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()); }; } exports.default = ExtensionCreator;