first refactor

This commit is contained in:
Boki 2026-10-20 12:39:38 -04:00
parent 1f5dac28c7
commit 588f666943
84 changed files with 996 additions and 1062 deletions

View file

@ -1,59 +1,7 @@
/**
* Awilix DI Container Setup
* Creates a decoupled, reusable dependency injection container
*/
import type { AwilixContainer } from 'awilix';
import type { ServiceDefinitions } from './container/types';
import { type AwilixContainer } from 'awilix';
import type { Browser } from '@stock-bot/browser';
import type { CacheProvider } from '@stock-bot/cache';
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 { IServiceContainer } from '@stock-bot/types';
import type { AppConfig } from './config/schemas';
// Re-export for backward compatibility
export type { AppConfig };
/**
* Service type definitions for type-safe resolution
*/
export interface ServiceDefinitions {
// Configuration
config: AppConfig;
logger: Logger;
// Core services
cache: CacheProvider | null;
proxyManager: ProxyManager | null;
browser: Browser;
queueManager: QueueManager | null;
// Database clients
mongoClient: MongoDBClient | null;
postgresClient: PostgreSQLClient | null;
questdbClient: QuestDBClient | null;
// Aggregate service container
serviceContainer: IServiceContainer;
}
// Export typed container
// Compatibility exports use the same composition contract as the active builder.
export type { AppConfig } from './config/schemas';
export type { ServiceCradle, ServiceDefinitions, ServiceContainerOptions } from './container/types';
export type ServiceContainer = AwilixContainer<ServiceDefinitions>;
export type ServiceCradle = ServiceDefinitions;
/**
* Service-specific options for container creation
*/
export interface ServiceContainerOptions {
enableQuestDB?: boolean;
enableMongoDB?: boolean;
enablePostgres?: boolean;
enableCache?: boolean;
enableQueue?: boolean;
enableBrowser?: boolean;
enableProxy?: boolean;
}

View file

@ -2,6 +2,7 @@ import { asClass, asFunction, createContainer, InjectionMode, type AwilixContain
import type { BaseAppConfig as StockBotAppConfig, UnifiedAppConfig } from '@stock-bot/config';
import { toUnifiedConfig } from '@stock-bot/config';
import { HandlerRegistry } from '@stock-bot/handler-registry';
import type { IServiceContainer } from '@stock-bot/services';
import { appConfigSchema, type AppConfig } from '../config/schemas';
import {
registerApplicationServices,
@ -163,7 +164,7 @@ export class ServiceContainerBuilder {
// Register service container aggregate
container.register({
serviceContainer: asFunction(
serviceContainer: asFunction<IServiceContainer>(
({
config: _config,
logger,
@ -175,7 +176,7 @@ export class ServiceContainerBuilder {
mongoClient,
postgresClient,
questdbClient,
}) => ({
}: ServiceDefinitions) => ({
logger,
cache,
globalCache,

View file

@ -7,7 +7,7 @@ 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 { IServiceContainer } from '@stock-bot/types';
import type { IServiceContainer } from '@stock-bot/services';
import type { AppConfig } from '../config/schemas';
import type { HandlerScanner } from '../scanner';
@ -24,7 +24,7 @@ export interface ServiceDefinitions {
cache: CacheProvider | null;
globalCache: CacheProvider | null;
proxyManager: ProxyManager | null;
browser: Browser;
browser: Browser | null;
queueManager: QueueManager | null;
// Database clients

View file

@ -5,7 +5,7 @@ export { OperationContext } from './operation-context';
export { calculatePoolSize, getServicePoolSize, getHandlerPoolSize } from './pool-size-calculator';
export { ServiceLifecycleManager } from './utils/lifecycle';
export { HandlerScanner } from './scanner/handler-scanner';
export type { IServiceContainer } from '@stock-bot/types';
export type { IServiceContainer } from '@stock-bot/services';
// Export schemas
export {

View file

@ -8,7 +8,7 @@ import { toUnifiedConfig } from '@stock-bot/config';
import type { HandlerRegistry } from '@stock-bot/handler-registry';
import { getLogger, setLoggerConfig, shutdownLoggers, type Logger } from '@stock-bot/logger';
import { Shutdown, SHUTDOWN_DEFAULTS } from '@stock-bot/shutdown';
import type { IServiceContainer } from '@stock-bot/types';
import type { IServiceContainer } from '@stock-bot/services';
import type { AwilixContainer } from 'awilix';
import { Hono } from 'hono';
import { cors } from 'hono/cors';