mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
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:
committed by
Ammar Ahmed
parent
d55a6a6fc0
commit
a25d21038a
@@ -72,7 +72,9 @@ export async function* exportNotes(
|
||||
const pathTree = new PathTree();
|
||||
const notePathMap: Map<string, string[]> = new Map();
|
||||
|
||||
for await (const note of notes.fields(["notes.id", "notes.title"])) {
|
||||
for await (const note of notes
|
||||
.fields(["notes.id", "notes.title"])
|
||||
.iterate()) {
|
||||
const filename = `${sanitizeFilename(note.title || "Untitled", {
|
||||
replacement: "-"
|
||||
})}.${FORMAT_TO_EXT[format]}`;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user