diff --git a/.serena/cache/typescript/document_symbols_cache_v20-05-25.pkl b/.serena/cache/typescript/document_symbols_cache_v20-05-25.pkl index 3e4099f..93ce2e3 100644 Binary files a/.serena/cache/typescript/document_symbols_cache_v20-05-25.pkl and b/.serena/cache/typescript/document_symbols_cache_v20-05-25.pkl differ diff --git a/libs/core/di/src/awilix-container.ts b/libs/core/di/src/awilix-container.ts index ca1318b..168f00c 100644 --- a/libs/core/di/src/awilix-container.ts +++ b/libs/core/di/src/awilix-container.ts @@ -3,72 +3,21 @@ * Creates a decoupled, reusable dependency injection container */ -import { Browser } from '@stock-bot/browser'; -import { type CacheProvider } from '@stock-bot/cache'; +import type { Browser } from '@stock-bot/browser'; +import type { CacheProvider } from '@stock-bot/cache'; import type { AppConfig as StockBotAppConfig } from '@stock-bot/config'; import type { IServiceContainer } from '@stock-bot/handlers'; -import { type Logger } from '@stock-bot/logger'; -import { MongoDBClient } from '@stock-bot/mongodb'; -import { PostgreSQLClient } from '@stock-bot/postgres'; -import { ProxyManager } from '@stock-bot/proxy'; -import { QuestDBClient } from '@stock-bot/questdb'; -import { type QueueManager } from '@stock-bot/queue'; +import type { Logger } from '@stock-bot/logger'; +import type { MongoDBClient } from '@stock-bot/mongodb'; +import type { PostgreSQLClient } from '@stock-bot/postgres'; +import type { ProxyManager } from '@stock-bot/proxy'; +import type { QuestDBClient } from '@stock-bot/questdb'; +import type { QueueManager } from '@stock-bot/queue'; import { type AwilixContainer } from 'awilix'; -import { z } from 'zod'; +import type { AppConfig } from './config/schemas'; -// Configuration schema with validation -const appConfigSchema = z.object({ - redis: z.object({ - enabled: z.boolean().optional(), - host: z.string(), - port: z.number(), - password: z.string().optional(), - username: z.string().optional(), - db: z.number().optional(), - }), - mongodb: z.object({ - enabled: z.boolean().optional(), - uri: z.string(), - database: z.string(), - }), - postgres: z.object({ - enabled: z.boolean().optional(), - host: z.string(), - port: z.number(), - database: z.string(), - user: z.string(), - password: z.string(), - }), - questdb: z - .object({ - enabled: z.boolean().optional(), - host: z.string(), - httpPort: z.number().optional(), - pgPort: z.number().optional(), - influxPort: z.number().optional(), - database: z.string().optional(), - }) - .optional(), - proxy: z - .object({ - cachePrefix: z.string().optional(), - ttl: z.number().optional(), - }) - .optional(), - browser: z - .object({ - headless: z.boolean().optional(), - timeout: z.number().optional(), - }) - .optional(), - queue: z - .object({ - enabled: z.boolean().optional(), - }) - .optional(), -}); - -export type AppConfig = z.infer; +// Re-export for backward compatibility +export type { AppConfig }; /** * Service type definitions for type-safe resolution diff --git a/libs/core/di/src/container/builder.ts b/libs/core/di/src/container/builder.ts index c086f97..8376979 100644 --- a/libs/core/di/src/container/builder.ts +++ b/libs/core/di/src/container/builder.ts @@ -94,9 +94,16 @@ export class ServiceContainerBuilder { user: config.postgres?.user || '', password: config.postgres?.password || '', }, - questdb: this.options.enableQuestDB ? config.questdb : undefined, + questdb: this.options.enableQuestDB ? (config.questdb || { + enabled: true, + host: 'localhost', + httpPort: 9000, + pgPort: 8812, + influxPort: 9009, + database: 'questdb', + }) : undefined, proxy: this.options.enableProxy ? (config.proxy || { cachePrefix: 'proxy:', ttl: 3600 }) : undefined, - browser: this.options.enableBrowser ? config.browser : undefined, + browser: this.options.enableBrowser ? (config.browser || { headless: true, timeout: 30000 }) : undefined, queue: this.options.enableQueue ? { enabled: this.options.enableQueue } : undefined, }; } diff --git a/libs/core/di/src/registrations/database.registration.ts b/libs/core/di/src/registrations/database.registration.ts index 68386cd..5e900ab 100644 --- a/libs/core/di/src/registrations/database.registration.ts +++ b/libs/core/di/src/registrations/database.registration.ts @@ -14,7 +14,7 @@ export function registerDatabaseServices( container.register({ mongoClient: asFunction(({ logger }) => { // Parse MongoDB URI to extract components - const uriMatch = config.mongodb.uri.match(/mongodb:\/\/(?:([^:]+):([^@]+)@)?([^:\/]+):(\d+)\/([^?]+)(?:\?authSource=(.+))?/); + const uriMatch = config.mongodb.uri.match(/mongodb:\/\/(?:([^:]+):([^@]+)@)?([^:/]+):(\d+)\/([^?]+)(?:\?authSource=(.+))?/); const mongoConfig = { host: uriMatch?.[3] || 'localhost', port: parseInt(uriMatch?.[4] || '27017'),