fixed lint in di
This commit is contained in:
parent
26ebc77fe6
commit
3ac274705e
4 changed files with 21 additions and 65 deletions
Binary file not shown.
|
|
@ -3,72 +3,21 @@
|
||||||
* Creates a decoupled, reusable dependency injection container
|
* Creates a decoupled, reusable dependency injection container
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Browser } from '@stock-bot/browser';
|
import type { Browser } from '@stock-bot/browser';
|
||||||
import { type CacheProvider } from '@stock-bot/cache';
|
import type { CacheProvider } from '@stock-bot/cache';
|
||||||
import type { AppConfig as StockBotAppConfig } from '@stock-bot/config';
|
import type { AppConfig as StockBotAppConfig } from '@stock-bot/config';
|
||||||
import type { IServiceContainer } from '@stock-bot/handlers';
|
import type { IServiceContainer } from '@stock-bot/handlers';
|
||||||
import { type Logger } from '@stock-bot/logger';
|
import type { Logger } from '@stock-bot/logger';
|
||||||
import { MongoDBClient } from '@stock-bot/mongodb';
|
import type { MongoDBClient } from '@stock-bot/mongodb';
|
||||||
import { PostgreSQLClient } from '@stock-bot/postgres';
|
import type { PostgreSQLClient } from '@stock-bot/postgres';
|
||||||
import { ProxyManager } from '@stock-bot/proxy';
|
import type { ProxyManager } from '@stock-bot/proxy';
|
||||||
import { QuestDBClient } from '@stock-bot/questdb';
|
import type { QuestDBClient } from '@stock-bot/questdb';
|
||||||
import { type QueueManager } from '@stock-bot/queue';
|
import type { QueueManager } from '@stock-bot/queue';
|
||||||
import { type AwilixContainer } from 'awilix';
|
import { type AwilixContainer } from 'awilix';
|
||||||
import { z } from 'zod';
|
import type { AppConfig } from './config/schemas';
|
||||||
|
|
||||||
// Configuration schema with validation
|
// Re-export for backward compatibility
|
||||||
const appConfigSchema = z.object({
|
export type { AppConfig };
|
||||||
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<typeof appConfigSchema>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service type definitions for type-safe resolution
|
* Service type definitions for type-safe resolution
|
||||||
|
|
|
||||||
|
|
@ -94,9 +94,16 @@ export class ServiceContainerBuilder {
|
||||||
user: config.postgres?.user || '',
|
user: config.postgres?.user || '',
|
||||||
password: config.postgres?.password || '',
|
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,
|
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,
|
queue: this.options.enableQueue ? { enabled: this.options.enableQueue } : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ export function registerDatabaseServices(
|
||||||
container.register({
|
container.register({
|
||||||
mongoClient: asFunction(({ logger }) => {
|
mongoClient: asFunction(({ logger }) => {
|
||||||
// Parse MongoDB URI to extract components
|
// 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 = {
|
const mongoConfig = {
|
||||||
host: uriMatch?.[3] || 'localhost',
|
host: uriMatch?.[3] || 'localhost',
|
||||||
port: parseInt(uriMatch?.[4] || '27017'),
|
port: parseInt(uriMatch?.[4] || '27017'),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue