stock-bot/libs/core/services/src/index.ts
Boki 4cd6038063 refactor: pre-M0 cleanup, core library hardening, and isolated dev/QA Docker stack
- Remove ~44k LOC of dead code, legacy v1 TS simulator/strategy stack, event-bus, analytics FastAPI prototype, legacy calculation archives, and unused deps (data-ingestion provider API handlers untouched)
- Extract @stock-bot/di/http-security and isolate @stock-bot/browser to data-ingestion via ServiceContainerBuilder.withRegistrations()
- Harden @stock-bot/mongodb read-only proxies, flatten @stock-bot/postgres with unified master+research migrations, and fix @stock-bot/config EnvLoader, ServiceApplication worker lifecycle, NamespacedCache.clear(), and BatchProcessor error propagation
- Flatten workspace root (remove apps/stock/package.json) and collapse orchestrator re-export shims
- Pin all Docker image versions, add shm_size/nofile/RAM caps and docker-compose.quant.yml, fix 05-add-visible-column.sql view recreation, and decouple dev/QA Compose project names for side-by-side execution
- Update PLATFORM-PLAN, DATA-CONTRACTS (bars_1m PARTITION BY MONTH, Rust bulk ETL, DuckDB limits), MILESTONES, and servers docs
2026-11-27 00:11:50 -05:00

56 lines
2.3 KiB
TypeScript

import type { Browser as BrowserImplementation } from '@stock-bot/browser';
import type { CacheProvider } from '@stock-bot/cache';
import type { Logger as LoggerImplementation } from '@stock-bot/logger';
import type { MongoDBClient as MongoDBImplementation } from '@stock-bot/mongodb';
import type { PostgreSQLClient as PostgresImplementation } from '@stock-bot/postgres';
import type { ProxyManager as ProxyImplementation } from '@stock-bot/proxy';
import type { QuestDBClient as QuestDBImplementation } from '@stock-bot/questdb';
import type {
Queue as QueueImplementation,
QueueManager as QueueManagerImplementation,
} from '@stock-bot/queue';
/** Public capabilities, derived from the owning adapter instead of copied signatures. */
type Public<T> = Pick<T, keyof T>;
export type Logger = Public<LoggerImplementation>;
export type Queue = Public<QueueImplementation>;
export type QueueManager = Public<QueueManagerImplementation>;
export type MongoDBClient = Public<MongoDBImplementation>;
export type PostgresClient = Public<PostgresImplementation>;
export type QuestDBClient = Public<QuestDBImplementation>;
export type Browser = Public<BrowserImplementation>;
export type ProxyManager = Public<ProxyImplementation>;
export type { CacheProvider, CacheStats } from '@stock-bot/cache';
export type { ProxyInfo, ProxyStats } from '@stock-bot/proxy';
/** Disabled adapters are null; omitted capabilities are undefined. */
export interface ServiceTypes {
logger: Logger;
cache?: CacheProvider | null;
globalCache?: CacheProvider | null;
queueManager?: QueueManager | null;
queue?: Queue | null;
proxy?: ProxyManager | null;
browser?: Browser | null;
mongodb?: MongoDBClient | null;
postgres?: PostgresClient | null;
questdb?: QuestDBClient | null;
}
export interface IServiceContainer extends ServiceTypes {
readonly custom?: Record<string, unknown>;
}
/** Validate required capabilities at the boundary before starting any work. */
export function requireServices<T extends ServiceTypes, K extends keyof ServiceTypes>(
services: T,
...keys: K[]
): T & { [P in K]-?: NonNullable<ServiceTypes[P]> } {
for (const key of keys) {
if (services[key] === null || services[key] === undefined) {
throw new Error(`Required service '${key}' is unavailable`);
}
}
return services as T & { [P in K]-?: NonNullable<ServiceTypes[P]> };
}