fix(cursor, doc): Add explicit return types and casts to SmartdataDbCursor methods and update getCursorExtended signature in SmartDataDbDoc.

This commit is contained in:
2025-04-14 18:06:29 +00:00
parent 4733982d03
commit 0bfebaf5b9
4 changed files with 13 additions and 6 deletions

View File

@@ -15,14 +15,14 @@ export class SmartdataDbCursor<T = any> {
this.smartdataDbDoc = dbDocArg;
}
public async next(closeAtEnd = true) {
public async next(closeAtEnd = true): Promise<T> {
const result = this.smartdataDbDoc.createInstanceFromMongoDbNativeDoc(
await this.mongodbCursor.next(),
);
if (!result && closeAtEnd) {
await this.close();
}
return result;
return result as T;
}
public async forEach(forEachFuncArg: (itemArg: T) => Promise<any>, closeCursorAtEnd = true) {
@@ -40,9 +40,9 @@ export class SmartdataDbCursor<T = any> {
}
}
public async toArray() {
public async toArray(): Promise<T[]> {
const result = await this.mongodbCursor.toArray();
return result.map((itemArg) => this.smartdataDbDoc.createInstanceFromMongoDbNativeDoc(itemArg));
return result.map((itemArg) => this.smartdataDbDoc.createInstanceFromMongoDbNativeDoc(itemArg)) as T[];
}
public async close() {