fixed all libs to be buildiable and dependency hell from removing some

This commit is contained in:
Bojan Kucera 2025-06-04 16:07:08 -04:00
parent 5c64b1ccf8
commit a282dac6cd
40 changed files with 4050 additions and 8219 deletions

View file

@ -1,4 +1,4 @@
import { MongoClient, Db, Collection, MongoClientOptions } from 'mongodb';
import { MongoClient, Db, Collection, MongoClientOptions, Document, WithId, OptionalUnlessRequiredId } from 'mongodb';
import { mongodbConfig } from '@stock-bot/config';
import { Logger } from '@stock-bot/logger';
import type {
@ -144,12 +144,10 @@ export class MongoDBClient {
...document,
created_at: document.created_at || now,
updated_at: now
} as T;
// Validate document if schema exists
if (schemaMap[collectionName]) {
} as T; // Validate document if schema exists
if (collectionName in schemaMap) {
try {
schemaMap[collectionName].parse(docWithTimestamps);
(schemaMap as any)[collectionName].parse(docWithTimestamps);
} catch (error) {
if (error instanceof z.ZodError) {
this.logger.error(`Document validation failed for ${collectionName}:`, error.errors);
@ -157,9 +155,7 @@ export class MongoDBClient {
}
throw error;
}
}
const result = await collection.insertOne(docWithTimestamps);
} const result = await collection.insertOne(docWithTimestamps as OptionalUnlessRequiredId<T>);
return { ...docWithTimestamps, _id: result.insertedId } as T;
}
@ -182,7 +178,6 @@ export class MongoDBClient {
const result = await collection.updateOne(filter, { $set: updateWithTimestamp });
return result.modifiedCount > 0;
}
/**
* Find documents with optional validation
*/
@ -192,7 +187,7 @@ export class MongoDBClient {
options: any = {}
): Promise<T[]> {
const collection = this.getCollection<T>(collectionName);
return await collection.find(filter, options).toArray();
return await collection.find(filter, options).toArray() as T[];
}
/**
@ -203,7 +198,7 @@ export class MongoDBClient {
filter: any
): Promise<T | null> {
const collection = this.getCollection<T>(collectionName);
return await collection.findOne(filter);
return await collection.findOne(filter) as T | null;
}
/**
@ -259,11 +254,12 @@ export class MongoDBClient {
{ key: { filing_type: 1 } },
{ key: { cik: 1 } },
{ key: { created_at: -1 } }
]);
// Raw documents indexes
]); // Raw documents indexes
await this.db.collection('raw_documents').createIndex(
{ content_hash: 1 },
{ unique: true }
);
await this.db.collection('raw_documents').createIndexes([
{ key: { content_hash: 1 }, options: { unique: true } },
{ key: { processing_status: 1 } },
{ key: { document_type: 1 } },
{ key: { created_at: -1 } }
@ -366,8 +362,11 @@ export class MongoDBClient {
serverSelectionTimeoutMS: this.config.timeouts?.serverSelectionTimeout,
retryWrites: this.config.options?.retryWrites,
journal: this.config.options?.journal,
readPreference: this.config.options?.readPreference,
writeConcern: { w: this.config.options?.writeConcern },
readPreference: this.config.options?.readPreference, writeConcern: this.config.options?.writeConcern ? {
w: this.config.options.writeConcern === 'majority'
? 'majority' as const
: parseInt(this.config.options.writeConcern, 10) || 1
} : undefined,
tls: this.config.tls?.enabled,
tlsInsecure: this.config.tls?.insecure,
tlsCAFile: this.config.tls?.caFile