UNPKG

weaviate-client

Version:
64 lines (63 loc) • 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const commandBase_js_1 = require("../validation/commandBase.js"); const string_js_1 = require("../validation/string.js"); class ReferencesBatcher extends commandBase_js_1.CommandBase { fromClassName; fromId; fromRefProp; toClassName; toId; constructor(client) { super(client); } withFromId = (id) => { this.fromId = id; return this; }; withToId = (id) => { this.toId = id; return this; }; withFromClassName = (className) => { this.fromClassName = className; return this; }; withFromRefProp = (refProp) => { this.fromRefProp = refProp; return this; }; withToClassName(className) { this.toClassName = className; 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.fromId, 'fromId', '.withFromId(id)'); this.validateIsSet(this.toId, 'toId', '.withToId(id)'); this.validateIsSet(this.fromClassName, 'fromClassName', '.withFromClassName(className)'); this.validateIsSet(this.fromRefProp, 'fromRefProp', '.withFromRefProp(refProp)'); }; payload = () => { this.validate(); if (this.errors.length > 0) { throw new Error(this.errors.join(', ')); } let beaconTo = `weaviate://localhost`; if ((0, string_js_1.isValidStringProperty)(this.toClassName)) { beaconTo = `${beaconTo}/${this.toClassName}`; } return { from: `weaviate://localhost/${this.fromClassName}/${this.fromId}/${this.fromRefProp}`, to: `${beaconTo}/${this.toId}`, }; }; do = () => { return Promise.reject(new Error('Should never be called')); }; } exports.default = ReferencesBatcher;