From ca5f09c4595d546cf3e6cc09237e531075d58d3b Mon Sep 17 00:00:00 2001 From: Boki Date: Mon, 23 Jun 2025 21:39:04 -0400 Subject: [PATCH] removed deprecated code --- .../data-ingestion/test-ceo-operations.ts | 103 ------------------ libs/core/config/src/cli.ts | 8 +- libs/core/config/src/index.ts | 49 ++------- libs/core/config/src/schemas/index.ts | 11 -- libs/core/di/src/awilix-container.ts | 32 +----- libs/core/di/src/container/builder.ts | 2 +- libs/core/di/src/container/factory.ts | 81 +------------- libs/core/di/src/index.ts | 9 +- libs/core/di/src/service-application.ts | 2 +- .../queue/src/service-registry.deprecated.ts | 98 ----------------- 10 files changed, 18 insertions(+), 377 deletions(-) delete mode 100755 apps/stock/data-ingestion/test-ceo-operations.ts delete mode 100644 libs/core/queue/src/service-registry.deprecated.ts diff --git a/apps/stock/data-ingestion/test-ceo-operations.ts b/apps/stock/data-ingestion/test-ceo-operations.ts deleted file mode 100755 index 7a46724..0000000 --- a/apps/stock/data-ingestion/test-ceo-operations.ts +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env bun - -/** - * Test script for CEO handler operations - */ -import { initializeServiceConfig } from '@stock-bot/config'; -import { createServiceContainer, initializeServices } from '@stock-bot/di'; -import { getLogger } from '@stock-bot/logger'; - -const logger = getLogger('test-ceo-operations'); - -async function testCeoOperations() { - logger.info('Testing CEO handler operations...'); - - try { - // Initialize config - const config = initializeServiceConfig(); - - // Create Awilix container - const awilixConfig = { - redis: { - host: config.database.dragonfly.host, - port: config.database.dragonfly.port, - db: config.database.dragonfly.db, - }, - mongodb: { - uri: config.database.mongodb.uri, - database: config.database.mongodb.database, - }, - postgres: { - host: config.database.postgres.host, - port: config.database.postgres.port, - database: config.database.postgres.database, - user: config.database.postgres.user, - password: config.database.postgres.password, - }, - questdb: { - enabled: false, - host: config.database.questdb.host, - httpPort: config.database.questdb.httpPort, - pgPort: config.database.questdb.pgPort, - influxPort: config.database.questdb.ilpPort, - database: config.database.questdb.database, - }, - }; - - const container = createServiceContainer(awilixConfig); - await initializeServices(container); - - const serviceContainer = container.resolve('serviceContainer'); - - // Import and create CEO handler - const { CeoHandler } = await import('./src/handlers/ceo/ceo.handler'); - const ceoHandler = new CeoHandler(serviceContainer); - - // Test 1: Check if there are any CEO symbols in the database - logger.info('Checking for existing CEO symbols...'); - const collection = serviceContainer.mongodb.collection('ceoSymbols'); - const count = await collection.countDocuments(); - logger.info(`Found ${count} CEO symbols in database`); - - if (count > 0) { - // Test 2: Run process-unique-symbols operation - logger.info('Testing process-unique-symbols operation...'); - const result = await ceoHandler.updateUniqueSymbols(undefined, {}); - logger.info('Process unique symbols result:', result); - - // Test 3: Test individual symbol processing - logger.info('Testing process-individual-symbol operation...'); - const sampleSymbol = await collection.findOne({}); - if (sampleSymbol) { - const individualResult = await ceoHandler.processIndividualSymbol( - { - ceoId: sampleSymbol.ceoId, - symbol: sampleSymbol.symbol, - exchange: sampleSymbol.exchange, - name: sampleSymbol.name, - }, - {} - ); - logger.info('Process individual symbol result:', individualResult); - } - } else { - logger.warn('No CEO symbols found. Run the service to populate data first.'); - } - - // Clean up - await serviceContainer.mongodb.disconnect(); - await serviceContainer.postgres.disconnect(); - if (serviceContainer.cache) { - await serviceContainer.cache.disconnect(); - } - - logger.info('Test completed successfully!'); - process.exit(0); - } catch (error) { - logger.error('Test failed:', error); - process.exit(1); - } -} - -// Run the test -testCeoOperations(); diff --git a/libs/core/config/src/cli.ts b/libs/core/config/src/cli.ts index 8abebef..d4fcae5 100644 --- a/libs/core/config/src/cli.ts +++ b/libs/core/config/src/cli.ts @@ -11,7 +11,7 @@ import { validateConfig, } from './utils/validation'; import { ConfigManager } from './config-manager'; -import { appConfigSchema } from './schemas'; +import { baseAppSchema } from './schemas'; import type { Environment } from './types'; interface CliOptions { @@ -103,10 +103,10 @@ async function main() { environment, }); - const config = await manager.initialize(appConfigSchema); + const config = await manager.initialize(baseAppSchema); if (values.validate) { - const result = validateConfig(config, appConfigSchema); + const result = validateConfig(config, baseAppSchema); if (values.json) { console.log(JSON.stringify(result, null, 2)); @@ -133,7 +133,7 @@ async function main() { // Schema validation console.log('1. Schema Validation:'); - const schemaResult = validateConfig(config, appConfigSchema); + const schemaResult = validateConfig(config, baseAppSchema); console.log(formatValidationResult(schemaResult)); console.log(); diff --git a/libs/core/config/src/index.ts b/libs/core/config/src/index.ts index ebf46c5..ecf9268 100644 --- a/libs/core/config/src/index.ts +++ b/libs/core/config/src/index.ts @@ -2,12 +2,12 @@ import { EnvLoader } from './loaders/env.loader'; import { FileLoader } from './loaders/file.loader'; import { ConfigManager } from './config-manager'; -import type { AppConfig } from './schemas'; -import { appConfigSchema } from './schemas'; +import type { BaseAppConfig } from './schemas'; +import { baseAppSchema } from './schemas'; import { z } from 'zod'; // Legacy singleton instance for backward compatibility -let configInstance: ConfigManager | null = null; +let configInstance: ConfigManager | null = null; // Synchronously load critical env vars for early initialization function loadCriticalEnvVarsSync(): void { @@ -56,25 +56,6 @@ function loadCriticalEnvVarsSync(): void { // Load critical env vars immediately loadCriticalEnvVarsSync(); -/** - * Initialize the global configuration synchronously. - * @deprecated Use initializeAppConfig with your own schema instead - * - * This loads configuration from all sources in the correct hierarchy: - * 1. Schema defaults (lowest priority) - * 2. default.json - * 3. [environment].json (e.g., development.json) - * 4. .env file values - * 5. process.env values (highest priority) - */ -export function initializeConfig(configPath?: string): AppConfig { - if (!configInstance) { - configInstance = new ConfigManager({ - configPath, - }); - } - return configInstance.initialize(appConfigSchema); -} /** * Initialize configuration for a service in a monorepo. @@ -83,10 +64,10 @@ export function initializeConfig(configPath?: string): AppConfig { * 2. Service-specific config directory (./config) * 3. Environment variables */ -export function initializeServiceConfig(): AppConfig { +export function initializeServiceConfig(): BaseAppConfig { if (!configInstance) { const environment = process.env.NODE_ENV || 'development'; - configInstance = new ConfigManager({ + configInstance = new ConfigManager({ loaders: [ new FileLoader('../../config', environment), // Root config new FileLoader('./config', environment), // Service config @@ -94,13 +75,13 @@ export function initializeServiceConfig(): AppConfig { ], }); } - return configInstance.initialize(appConfigSchema); + return configInstance.initialize(baseAppSchema); } /** * Get the current configuration */ -export function getConfig(): AppConfig { +export function getConfig(): BaseAppConfig { if (!configInstance) { throw new Error('Configuration not initialized. Call initializeConfig() first.'); } @@ -110,7 +91,7 @@ export function getConfig(): AppConfig { /** * Get configuration manager instance */ -export function getConfigManager(): ConfigManager { +export function getConfigManager(): ConfigManager { if (!configInstance) { throw new Error('Configuration not initialized. Call initializeConfig() first.'); } @@ -140,21 +121,7 @@ export function getLogConfig() { return getConfig().log; } -// Deprecated alias for backward compatibility -export function getLoggingConfig() { - return getConfig().log; -} -// Deprecated - provider configs should be app-specific -// @deprecated Move provider configs to your app-specific config -export function getProviderConfig(_provider: string) { - const config = getConfig() as any; - const providers = config.providers; - if (!providers || !(_provider in providers)) { - throw new Error(`Provider configuration not found: ${_provider}`); - } - return (providers as Record)[_provider]; -} export function getQueueConfig() { return getConfig().queue; diff --git a/libs/core/config/src/schemas/index.ts b/libs/core/config/src/schemas/index.ts index ab1a1b6..23cf90d 100644 --- a/libs/core/config/src/schemas/index.ts +++ b/libs/core/config/src/schemas/index.ts @@ -16,14 +16,3 @@ export type { BaseAppConfig } from './base-app.schema'; export { unifiedAppSchema, toUnifiedConfig, getStandardServiceName } from './unified-app.schema'; export type { UnifiedAppConfig } from './unified-app.schema'; -// Keep AppConfig for backward compatibility (deprecated) -// @deprecated Use baseAppSchema and extend it for your specific app -import { z } from 'zod'; -import { baseAppSchema } from './base-app.schema'; -import { providerConfigSchema } from './provider.schema'; - -export const appConfigSchema = baseAppSchema.extend({ - providers: providerConfigSchema.optional(), -}); - -export type AppConfig = z.infer; diff --git a/libs/core/di/src/awilix-container.ts b/libs/core/di/src/awilix-container.ts index 224b7cb..21ba2a5 100644 --- a/libs/core/di/src/awilix-container.ts +++ b/libs/core/di/src/awilix-container.ts @@ -5,7 +5,7 @@ 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 { BaseAppConfig as StockBotAppConfig } from '@stock-bot/config'; import type { IServiceContainer } from '@stock-bot/types'; import type { Logger } from '@stock-bot/logger'; import type { MongoDBClient } from '@stock-bot/mongodb'; @@ -42,24 +42,6 @@ export interface ServiceDefinitions { serviceContainer: IServiceContainer; } -/** - * Create and configure the DI container with type safety - */ -export function createServiceContainer(rawConfig: unknown): AwilixContainer { - // Deprecated - use the new modular structure - const { createServiceContainer: newCreateServiceContainer } = require('./container/factory'); - return newCreateServiceContainer(rawConfig); -} - - -/** - * Initialize async services after container creation - */ -export async function initializeServices(container: AwilixContainer): Promise { - // Deprecated - use the new modular structure - const { initializeServices: newInitializeServices } = await import('./container/factory'); - return newInitializeServices(container as any); -} // Export typed container @@ -79,16 +61,4 @@ export interface ServiceContainerOptions { enableProxy?: boolean; } -/** - * Create service container directly from AppConfig - * This eliminates the need for manual config mapping in each service - */ -export function createServiceContainerFromConfig( - appConfig: StockBotAppConfig, - options: ServiceContainerOptions = {} -): AwilixContainer { - // Deprecated - use the new modular structure - const { createServiceContainerFromConfig: newCreateServiceContainerFromConfig } = require('./container/factory'); - return newCreateServiceContainerFromConfig(appConfig, options); -} diff --git a/libs/core/di/src/container/builder.ts b/libs/core/di/src/container/builder.ts index 74e387a..abb20e3 100644 --- a/libs/core/di/src/container/builder.ts +++ b/libs/core/di/src/container/builder.ts @@ -1,5 +1,5 @@ import { createContainer, InjectionMode, asFunction, type AwilixContainer } from 'awilix'; -import type { AppConfig as StockBotAppConfig, UnifiedAppConfig } from '@stock-bot/config'; +import type { BaseAppConfig as StockBotAppConfig, UnifiedAppConfig } from '@stock-bot/config'; import { appConfigSchema, type AppConfig } from '../config/schemas'; import { toUnifiedConfig } from '@stock-bot/config'; import { diff --git a/libs/core/di/src/container/factory.ts b/libs/core/di/src/container/factory.ts index 0182cd1..d045742 100644 --- a/libs/core/di/src/container/factory.ts +++ b/libs/core/di/src/container/factory.ts @@ -1,76 +1,8 @@ import type { AwilixContainer } from 'awilix'; -import type { AppConfig as StockBotAppConfig } from '@stock-bot/config'; +import type { BaseAppConfig as StockBotAppConfig } from '@stock-bot/config'; import { ServiceContainerBuilder } from './builder'; import type { ServiceDefinitions, ServiceContainerOptions } from './types'; -/** - * Creates a service container from raw configuration - * @deprecated Use ServiceContainerBuilder instead - */ -export function createServiceContainer(rawConfig: unknown): AwilixContainer { - // For backward compatibility, we need to create the container synchronously - // This means we'll use the original implementation pattern - const { createContainer, InjectionMode, asValue: _asValue, asFunction } = require('awilix'); - const { appConfigSchema } = require('../config/schemas'); - const config = appConfigSchema.parse(rawConfig); - - const container = createContainer({ - injectionMode: InjectionMode.PROXY, - strict: true, - }); - - // Register all services synchronously - const { - registerCoreServices, - registerCacheServices, - registerDatabaseServices, - registerApplicationServices - } = require('../registrations'); - - registerCoreServices(container, config); - registerCacheServices(container, config); - registerDatabaseServices(container, config); - registerApplicationServices(container, config); - - // Register service container aggregate - container.register({ - serviceContainer: asFunction((cradle: ServiceDefinitions) => ({ - logger: cradle.logger, - cache: cradle.cache, - proxy: cradle.proxyManager, // Map proxyManager to proxy - browser: cradle.browser, - queue: cradle.queueManager, // Map queueManager to queue - mongodb: cradle.mongoClient, // Map mongoClient to mongodb - postgres: cradle.postgresClient, // Map postgresClient to postgres - questdb: cradle.questdbClient, // Map questdbClient to questdb - })).singleton(), - }); - - return container; -} - - -/** - * Creates a service container from StockBotAppConfig - * @deprecated Use ServiceContainerBuilder instead - */ -export function createServiceContainerFromConfig( - appConfig: StockBotAppConfig, - options: ServiceContainerOptions = {} -): AwilixContainer { - const builder = new ServiceContainerBuilder(); - return builder - .withConfig(appConfig) - .withOptions({ - ...options, - skipInitialization: true, // Legacy behavior - }) - .build() - .then(container => container) - .catch(error => { - throw error; - }) as any; // Sync interface for backward compatibility -} /** * Modern async factory for creating service containers @@ -86,14 +18,3 @@ export async function createServiceContainerAsync( .build(); } -/** - * Initialize services in an existing container - * @deprecated Handled automatically by ServiceContainerBuilder - */ -export async function initializeServices( - container: AwilixContainer -): Promise { - const { ServiceLifecycleManager } = await import('../utils/lifecycle'); - const lifecycleManager = new ServiceLifecycleManager(); - await lifecycleManager.initializeServices(container); -} \ No newline at end of file diff --git a/libs/core/di/src/index.ts b/libs/core/di/src/index.ts index 67fdd0e..a00bf2d 100644 --- a/libs/core/di/src/index.ts +++ b/libs/core/di/src/index.ts @@ -6,11 +6,8 @@ export * from './types'; // Re-export IServiceContainer from types for convenience export type { IServiceContainer } from '@stock-bot/types'; -// Legacy exports for backward compatibility +// Type exports from awilix-container export { - createServiceContainer, - createServiceContainerFromConfig, - initializeServices, type AppConfig, type ServiceCradle, type ServiceContainer, @@ -21,9 +18,7 @@ export { export * from './container/types'; export { ServiceContainerBuilder } from './container/builder'; export { - createServiceContainerAsync, - createServiceContainer as createServiceContainerNew, - createServiceContainerFromConfig as createServiceContainerFromConfigNew + createServiceContainerAsync } from './container/factory'; // Configuration exports diff --git a/libs/core/di/src/service-application.ts b/libs/core/di/src/service-application.ts index 289c92d..1b2ce3c 100644 --- a/libs/core/di/src/service-application.ts +++ b/libs/core/di/src/service-application.ts @@ -7,7 +7,7 @@ import { Hono } from 'hono'; import { cors } from 'hono/cors'; import { getLogger, setLoggerConfig, shutdownLoggers, type Logger } from '@stock-bot/logger'; import { Shutdown } from '@stock-bot/shutdown'; -import type { AppConfig as StockBotAppConfig, UnifiedAppConfig } from '@stock-bot/config'; +import type { BaseAppConfig as StockBotAppConfig, UnifiedAppConfig } from '@stock-bot/config'; import { toUnifiedConfig } from '@stock-bot/config'; import type { IServiceContainer } from '@stock-bot/types'; import type { ServiceContainer } from './awilix-container'; diff --git a/libs/core/queue/src/service-registry.deprecated.ts b/libs/core/queue/src/service-registry.deprecated.ts deleted file mode 100644 index 176d624..0000000 --- a/libs/core/queue/src/service-registry.deprecated.ts +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Service Registry Configuration - * Maps services to their Redis databases and configurations - * - * @deprecated This static service registry has been replaced by runtime discovery - * using the handler registry. Service ownership is now tracked when handlers are - * registered, eliminating the need for static configuration. - * - * Migration: - * - Service names are auto-discovered from handler registration - * - Cache prefixes are generated using generateCachePrefix() - * - Queue names use getFullQueueName() from service-utils - * - Handler ownership is tracked by handlerRegistry.getHandlerService() - */ - -export interface ServiceConfig { - /** Prefix for cache keys (e.g., 'cache:data-ingestion') */ - cachePrefix: string; - /** List of handlers this service owns (auto-discovered if not provided) */ - handlers?: string[]; -} - -/** - * Central registry of all services and their configurations - * - * Database assignments: - * - db:0 = All queues (unified queue database) - * - db:1 = Global shared cache + service-specific caches - */ -export const SERVICE_REGISTRY: Record = { - 'data-ingestion': { - cachePrefix: 'cache:data-ingestion', - handlers: ['ceo', 'qm', 'webshare', 'ib', 'proxy'], - }, - 'data-pipeline': { - cachePrefix: 'cache:data-pipeline', - handlers: ['exchanges', 'symbols'], - }, - 'web-api': { - cachePrefix: 'cache:web-api', - }, - // Add aliases for services with different naming conventions - 'webApi': { - cachePrefix: 'cache:web-api', - }, - 'dataIngestion': { - cachePrefix: 'cache:data-ingestion', - handlers: ['ceo', 'qm', 'webshare', 'ib', 'proxy'], - }, - 'dataPipeline': { - cachePrefix: 'cache:data-pipeline', - handlers: ['exchanges', 'symbols'], - }, -}; - -/** - * Get service configuration - */ -export function getServiceConfig(serviceName: string): ServiceConfig | undefined { - return SERVICE_REGISTRY[serviceName]; -} - -/** - * Find which service owns a handler - */ -export function findServiceForHandler(handlerName: string): string | undefined { - for (const [serviceName, config] of Object.entries(SERVICE_REGISTRY)) { - if (config.handlers?.includes(handlerName)) { - return serviceName; - } - } - return undefined; -} - -/** - * Get full queue name with service namespace - */ -export function getFullQueueName(serviceName: string, handlerName: string): string { - // Use {service_handler} format for Dragonfly optimization and BullMQ compatibility - return `{${serviceName}_${handlerName}}`; -} - -/** - * Parse a full queue name into service and handler - */ -export function parseQueueName(fullQueueName: string): { service: string; handler: string } | null { - // Match pattern {service_handler} - const match = fullQueueName.match(/^\{([^_]+)_([^}]+)\}$/); - - if (!match || !match[1] || !match[2]) { - return null; - } - - return { - service: match[1], - handler: match[2], - }; -} \ No newline at end of file