UNPKG

weaviate-client

Version:
55 lines (54 loc) • 1.87 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const commandBase_js_1 = require("../validation/commandBase.js"); const string_js_1 = require("../validation/string.js"); const classGetter_js_1 = __importDefault(require("./classGetter.js")); class VectorAdder extends commandBase_js_1.CommandBase { className; vectors; constructor(client) { super(client); } withClassName = (className) => { this.className = className; return this; }; withVectors = (vectors) => { this.vectors = vectors; return this; }; validateClassName = () => { if (!(0, string_js_1.isValidStringProperty)(this.className)) { this.addError('className must be set - set with .withClassName(className)'); } }; validate = () => { this.validateClassName(); }; do = () => { this.validate(); if (this.errors.length > 0) { return Promise.reject(new Error('invalid usage: ' + this.errors.join(', '))); } return new classGetter_js_1.default(this.client) .withClassName(this.className) .do() .then(async (schema) => { if (schema.vectorConfig === undefined) { schema.vectorConfig = {}; } for (const [key, value] of Object.entries(this.vectors)) { if (schema.vectorConfig[key] !== undefined) { continue; } schema.vectorConfig[key] = { ...value }; } const path = `/schema/${this.className}`; await this.client.put(path, schema); }); }; } exports.default = VectorAdder;