fix(core): Improve error handling and logging; enhance search query sanitization; update dependency versions and documentation

This commit is contained in:
2025-08-12 11:25:42 +00:00
parent a91fac450a
commit e58c0fd215
17 changed files with 3068 additions and 1596 deletions

View File

@@ -4,6 +4,7 @@ import { SmartdataDbCursor } from './classes.cursor.js';
import { SmartDataDbDoc, type IIndexOptions } from './classes.doc.js';
import { SmartdataDbWatcher } from './classes.watcher.js';
import { CollectionFactory } from './classes.collectionfactory.js';
import { logger } from './logging.js';
export interface IFindOptions {
limit?: number;
@@ -161,7 +162,7 @@ export class SmartdataCollection<T> {
});
if (!wantedCollection) {
await this.smartdataDb.mongoDb.createCollection(this.collectionName);
console.log(`Successfully initiated Collection ${this.collectionName}`);
logger.log('info', `Successfully initiated Collection ${this.collectionName}`);
}
this.mongoDbCollection = this.smartdataDb.mongoDb.collection(this.collectionName);
// Auto-create a compound text index on all searchable fields
@@ -182,10 +183,10 @@ export class SmartdataCollection<T> {
/**
* mark unique index
*/
public markUniqueIndexes(keyArrayArg: string[] = []) {
public async markUniqueIndexes(keyArrayArg: string[] = []) {
for (const key of keyArrayArg) {
if (!this.uniqueIndexes.includes(key)) {
this.mongoDbCollection.createIndex(key, {
await this.mongoDbCollection.createIndex({ [key]: 1 }, {
unique: true,
});
// make sure we only call this once and not for every doc we create
@@ -197,12 +198,12 @@ export class SmartdataCollection<T> {
/**
* creates regular indexes for the collection
*/
public createRegularIndexes(indexesArg: Array<{field: string, options: IIndexOptions}> = []) {
public async createRegularIndexes(indexesArg: Array<{field: string, options: IIndexOptions}> = []) {
for (const indexDef of indexesArg) {
// Check if we've already created this index
const indexKey = indexDef.field;
if (!this.regularIndexes.some(i => i.field === indexKey)) {
this.mongoDbCollection.createIndex(
await this.mongoDbCollection.createIndex(
{ [indexDef.field]: 1 }, // Simple single-field index
indexDef.options
);
@@ -275,7 +276,7 @@ export class SmartdataCollection<T> {
fullDocument:
fullDocument === undefined
? 'updateLookup'
: fullDocument === true
: (fullDocument as any) === true
? 'updateLookup'
: fullDocument,
} as any;