From 0bfebaf5b9d9c2cc63e1ec3f27172257b6269cb7 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Mon, 14 Apr 2025 18:06:29 +0000 Subject: [PATCH] fix(cursor, doc): Add explicit return types and casts to SmartdataDbCursor methods and update getCursorExtended signature in SmartDataDbDoc. --- changelog.md | 7 +++++++ ts/00_commitinfo_data.ts | 2 +- ts/classes.cursor.ts | 8 ++++---- ts/classes.doc.ts | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 63dea7f..23f8396 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-04-14 - 5.8.1 - fix(cursor, doc) +Add explicit return types and casts to SmartdataDbCursor methods and update getCursorExtended signature in SmartDataDbDoc. + +- Specify Promise as return type for next() in SmartdataDbCursor and cast return value to T. +- Specify Promise as return type for toArray() in SmartdataDbCursor and cast return value to T[]. +- Update getCursorExtended to return Promise> for clearer type safety. + ## 2025-04-14 - 5.8.0 - feat(cursor) Add toArray method to SmartdataDbCursor to convert raw MongoDB documents into initialized class instances diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 3aa7281..238d6dd 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartdata', - version: '5.8.0', + version: '5.8.1', description: 'An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.' } diff --git a/ts/classes.cursor.ts b/ts/classes.cursor.ts index 7719232..a18fcbb 100644 --- a/ts/classes.cursor.ts +++ b/ts/classes.cursor.ts @@ -15,14 +15,14 @@ export class SmartdataDbCursor { this.smartdataDbDoc = dbDocArg; } - public async next(closeAtEnd = true) { + public async next(closeAtEnd = true): Promise { 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, closeCursorAtEnd = true) { @@ -40,9 +40,9 @@ export class SmartdataDbCursor { } } - public async toArray() { + public async toArray(): Promise { 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() { diff --git a/ts/classes.doc.ts b/ts/classes.doc.ts index 9f048fe..530b006 100644 --- a/ts/classes.doc.ts +++ b/ts/classes.doc.ts @@ -253,7 +253,7 @@ export class SmartDataDbDoc, filterArg: plugins.tsclass.typeFest.PartialDeep, modifierFunction = (cursorArg: plugins.mongodb.FindCursor>) => cursorArg, - ) { + ): Promise> { const collection: SmartdataCollection = (this as any).collection; let cursor: plugins.mongodb.FindCursor = collection.mongoDbCollection.find( convertFilterForMongoDb(filterArg),