weaviate-client
Version:
JS/TS client for Weaviate
42 lines (41 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Iterator = void 0;
const errors_js_1 = require("../../errors.js");
const ITERATOR_CACHE_SIZE = 100;
class Iterator {
query;
cache = [];
last = undefined;
constructor(query) {
this.query = query;
this.query = query;
}
[Symbol.asyncIterator]() {
return {
next: async () => {
const objects = await this.query(ITERATOR_CACHE_SIZE, this.last);
this.cache = objects;
if (this.cache.length == 0) {
return {
done: true,
value: undefined,
};
}
const obj = this.cache.shift();
if (obj === undefined) {
throw new errors_js_1.WeaviateDeserializationError('Object iterator returned an object that is undefined');
}
this.last = obj?.uuid;
if (this.last === undefined) {
throw new errors_js_1.WeaviateDeserializationError('Object iterator returned an object without a UUID');
}
return {
done: false,
value: obj,
};
},
};
}
}
exports.Iterator = Iterator;