fix(cursor, doc): Add explicit return types and casts to SmartdataDbCursor methods and update getCursorExtended signature in SmartDataDbDoc.
This commit is contained in:
parent
4733982d03
commit
0bfebaf5b9
@ -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<T> as return type for next() in SmartdataDbCursor and cast return value to T.
|
||||
- Specify Promise<T[]> as return type for toArray() in SmartdataDbCursor and cast return value to T[].
|
||||
- Update getCursorExtended to return Promise<SmartdataDbCursor<T>> 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
|
||||
|
||||
|
@ -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.'
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -253,7 +253,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
|
||||
this: plugins.tsclass.typeFest.Class<T>,
|
||||
filterArg: plugins.tsclass.typeFest.PartialDeep<T>,
|
||||
modifierFunction = (cursorArg: plugins.mongodb.FindCursor<plugins.mongodb.WithId<plugins.mongodb.BSON.Document>>) => cursorArg,
|
||||
) {
|
||||
): Promise<SmartdataDbCursor<T>> {
|
||||
const collection: SmartdataCollection<T> = (this as any).collection;
|
||||
let cursor: plugins.mongodb.FindCursor<any> = collection.mongoDbCollection.find(
|
||||
convertFilterForMongoDb(filterArg),
|
||||
|
Loading…
x
Reference in New Issue
Block a user