weaviate-client
Version:
JS/TS client for Weaviate
81 lines (80 loc) • 2.33 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const commandBase_js_1 = require("../validation/commandBase.js");
const string_js_1 = require("../validation/string.js");
const path_js_1 = require("./path.js");
class ObjectsBatchDeleter extends commandBase_js_1.CommandBase {
className;
consistencyLevel;
dryRun;
output;
whereFilter;
tenant;
constructor(client) {
super(client);
}
withClassName(className) {
this.className = className;
return this;
}
withWhere(whereFilter) {
this.whereFilter = whereFilter;
return this;
}
withOutput(output) {
this.output = output;
return this;
}
withDryRun(dryRun) {
this.dryRun = dryRun;
return this;
}
withConsistencyLevel = (cl) => {
this.consistencyLevel = cl;
return this;
};
withTenant(tenant) {
this.tenant = tenant;
return this;
}
payload = () => {
return {
match: {
class: this.className,
where: this.whereFilter,
},
output: this.output,
dryRun: this.dryRun,
};
};
validateClassName = () => {
if (!(0, string_js_1.isValidStringProperty)(this.className)) {
this.addError('string className must be set - set with .withClassName(className)');
}
};
validateWhereFilter = () => {
if (typeof this.whereFilter != 'object') {
this.addError('object where must be set - set with .withWhere(whereFilter)');
}
};
validate = () => {
this.validateClassName();
this.validateWhereFilter();
};
do = () => {
this.validate();
if (this.errors.length > 0) {
return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
}
const params = new URLSearchParams();
if (this.consistencyLevel) {
params.set('consistency_level', this.consistencyLevel);
}
if (this.tenant) {
params.set('tenant', this.tenant);
}
const path = (0, path_js_1.buildObjectsPath)(params);
return this.client.delete(path, this.payload(), true);
};
}
exports.default = ObjectsBatchDeleter;