core: fix Object is not iterable error on some platforms

This happened due to [Symbol.asyncIterable] not getting
transformed when it was a method of a class. Moving it inside
another method fixes the issue.
This commit is contained in:
Abdullah Atta
2025-02-03 11:36:05 +05:00
committed by Ammar Ahmed
parent d55a6a6fc0
commit a25d21038a
5 changed files with 42 additions and 34 deletions

View File

@@ -184,7 +184,7 @@ export default class Lookup {
) {
const results: Map<string, number> = new Map();
const columns = fields.map((f) => f.column);
for await (const item of selector.fields(columns)) {
for await (const item of selector.fields(columns).iterate()) {
if (limit && results.size >= limit) break;
for (const field of fields) {

View File

@@ -422,7 +422,7 @@ export class Attachments implements ICollection {
async cleanup() {
const now = dayjs().unix();
const ids: string[] = [];
for await (const attachment of this.deleted) {
for await (const attachment of this.deleted.iterate()) {
if (dayjs(attachment.dateDeleted).add(7, "days").unix() < now) continue;
const isDeleted = await this.db.fs().deleteFile(attachment.hash);

View File

@@ -361,7 +361,7 @@ export default class Backup {
};
let current = 0;
for await (const attachment of this.db.attachments.all) {
for await (const attachment of this.db.attachments.all.iterate()) {
current++;
if (
!(await this.db

View File

@@ -476,7 +476,7 @@ export class FilteredSelector<T extends Item> {
async *map<TReturnType>(
fn: (item: T) => TReturnType
): AsyncIterableIterator<TReturnType> {
for await (const item of this) {
for await (const item of this.iterate()) {
yield fn(item);
}
}
@@ -567,37 +567,43 @@ export class FilteredSelector<T extends Item> {
);
}
async *[Symbol.asyncIterator]() {
let lastRow: any | null = null;
const fields = this._fields.slice();
if (fields.length > 0) {
if (!fields.find((f) => f.includes(".dateCreated")))
fields.push("dateCreated");
if (!fields.find((f) => f.includes(".id"))) fields.push("id");
}
iterate() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const thisArg = this;
return {
async *[Symbol.asyncIterator]() {
let lastRow: any | null = null;
const fields = thisArg._fields.slice();
if (fields.length > 0) {
if (!fields.find((f) => f.includes(".dateCreated")))
fields.push("dateCreated");
if (!fields.find((f) => f.includes(".id"))) fields.push("id");
}
while (true) {
const rows = await this.filter
.orderBy("dateCreated asc")
.orderBy("id asc")
.$if(lastRow !== null, (qb) =>
qb.where(
(eb) => eb.refTuple("dateCreated", "id"),
">",
(eb) => eb.tuple(lastRow.dateCreated, lastRow.id)
)
)
.limit(this.batchSize)
.$if(fields.length === 0, (eb) => eb.selectAll())
.$if(fields.length > 0, (eb) => eb.select(fields))
.execute();
if (rows.length === 0) break;
for (const row of rows) {
yield row as T;
while (true) {
const rows = await thisArg.filter
.orderBy("dateCreated asc")
.orderBy("id asc")
.$if(lastRow !== null, (qb) =>
qb.where(
(eb) => eb.refTuple("dateCreated", "id"),
">",
(eb) => eb.tuple(lastRow.dateCreated, lastRow.id)
)
)
.limit(thisArg.batchSize)
.$if(fields.length === 0, (eb) => eb.selectAll())
.$if(fields.length > 0, (eb) => eb.select(fields))
.execute();
if (rows.length === 0) break;
for (const row of rows) {
yield row as T;
}
lastRow = rows[rows.length - 1];
}
}
lastRow = rows[rows.length - 1];
}
};
}
private buildSortExpression(options: GroupOptions, hasDueDate?: boolean) {