UNPKG

weaviate-client

Version:
58 lines (57 loc) • 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateShard = updateShard; const commandBase_js_1 = require("../validation/commandBase.js"); const string_js_1 = require("../validation/string.js"); class ShardUpdater extends commandBase_js_1.CommandBase { className; shardName; status; constructor(client) { super(client); } withClassName = (className) => { this.className = className; return this; }; validateClassName = () => { if (!(0, string_js_1.isValidStringProperty)(this.className)) { this.addError('className must be set - set with .withClassName(className)'); } }; withShardName = (shardName) => { this.shardName = shardName; return this; }; validateShardName = () => { if (!(0, string_js_1.isValidStringProperty)(this.shardName)) { this.addError('shardName must be set - set with .withShardName(shardName)'); } }; withStatus = (status) => { this.status = status; return this; }; validateStatus = () => { if (!(0, string_js_1.isValidStringProperty)(this.status)) { this.addError('status must be set - set with .withStatus(status)'); } }; validate = () => { this.validateClassName(); this.validateShardName(); this.validateStatus(); }; do = () => { this.validate(); if (this.errors.length > 0) { return Promise.reject(new Error(`invalid usage: ${this.errors.join(', ')}`)); } return updateShard(this.client, this.className, this.shardName, this.status); }; } exports.default = ShardUpdater; function updateShard(client, className, shardName, status) { const path = `/schema/${className}/shards/${shardName}`; return client.put(path, { status: status }, true); }