79 lines
No EOL
2.5 KiB
TypeScript
79 lines
No EOL
2.5 KiB
TypeScript
/**
|
|
* Service interfaces for type-safe dependency injection
|
|
*/
|
|
|
|
import type { Logger } from '@stock-bot/logger';
|
|
import type { CacheProvider } from '@stock-bot/cache';
|
|
import type { QueueManager } from '@stock-bot/queue';
|
|
|
|
// Core database client interfaces
|
|
export interface IMongoDBClient {
|
|
collection(name: string): any;
|
|
getDatabase(): any;
|
|
connect(): Promise<void>;
|
|
disconnect(): Promise<void>;
|
|
getPoolMetrics(): any;
|
|
warmupPool?(): Promise<void>;
|
|
setDynamicPoolConfig?(config: any): void;
|
|
}
|
|
|
|
export interface IPostgreSQLClient {
|
|
query(sql: string, params?: any[]): Promise<any>;
|
|
connect(): Promise<void>;
|
|
disconnect(): Promise<void>;
|
|
getPoolMetrics(): any;
|
|
warmupPool?(): Promise<void>;
|
|
setDynamicPoolConfig?(config: any): void;
|
|
connected: boolean;
|
|
}
|
|
|
|
export interface IConnectionFactory {
|
|
createMongoDB(config: any): Promise<{ client: IMongoDBClient; [key: string]: any }>;
|
|
createPostgreSQL(config: any): Promise<{ client: IPostgreSQLClient; [key: string]: any }>;
|
|
createCache(config: any): Promise<{ client: CacheProvider; [key: string]: any }>;
|
|
createQueue(config: any): Promise<{ client: QueueManager; [key: string]: any }>;
|
|
disposeAll(): Promise<void>;
|
|
getPool(type: string, name: string): any;
|
|
listPools(): any[];
|
|
}
|
|
|
|
// Main service interface for data ingestion
|
|
export interface IDataIngestionServices {
|
|
readonly mongodb: IMongoDBClient;
|
|
readonly postgres: IPostgreSQLClient;
|
|
readonly cache: CacheProvider;
|
|
readonly queue: QueueManager;
|
|
readonly logger: Logger;
|
|
readonly connectionFactory: IConnectionFactory;
|
|
}
|
|
|
|
// Operation context interface (simplified)
|
|
export interface IOperationContext {
|
|
readonly logger: Logger;
|
|
readonly traceId: string;
|
|
readonly metadata: Record<string, any>;
|
|
readonly services: IDataIngestionServices;
|
|
}
|
|
|
|
// Handler execution context
|
|
export interface IExecutionContext {
|
|
readonly type: 'http' | 'queue' | 'scheduled';
|
|
readonly services: IDataIngestionServices;
|
|
readonly metadata: Record<string, any>;
|
|
readonly traceId?: string;
|
|
}
|
|
|
|
// Service factory interface
|
|
export interface IServiceFactory {
|
|
create(config: any): Promise<IDataIngestionServices>;
|
|
dispose(services: IDataIngestionServices): Promise<void>;
|
|
}
|
|
|
|
// For backwards compatibility during migration
|
|
export interface LegacyServiceContainer {
|
|
resolve<T>(name: string): T;
|
|
resolveAsync<T>(name: string): Promise<T>;
|
|
register(registration: any): void;
|
|
createScope(): any;
|
|
dispose(): Promise<void>;
|
|
} |