cleanup
This commit is contained in:
parent
c353ddbe01
commit
ce9e2df67c
310 changed files with 2550 additions and 36861 deletions
|
|
@ -189,6 +189,8 @@ export class ConfigManager<T = Record<string, unknown>> {
|
|||
case 'production':
|
||||
case 'prod':
|
||||
return 'production';
|
||||
case 'qa':
|
||||
return 'qa';
|
||||
case 'test':
|
||||
return 'test';
|
||||
case 'development':
|
||||
|
|
|
|||
|
|
@ -133,13 +133,43 @@ export class EnvLoader implements ConfigLoader {
|
|||
|
||||
private shouldPreserveStringForKey(key: string): boolean {
|
||||
// Keys that should preserve string values even if they look like numbers
|
||||
const preserveStringKeys = ['QM_WEBMASTER_ID', 'IB_MARKET_DATA_TYPE'];
|
||||
const preserveStringKeys = [
|
||||
'QM_WEBMASTER_ID',
|
||||
'IB_MARKET_DATA_TYPE',
|
||||
'MONGODB_URI',
|
||||
'MONGODB_READ_URI',
|
||||
'MONGODB_PASSWORD',
|
||||
'POSTGRES_PASSWORD',
|
||||
'DRAGONFLY_PASSWORD',
|
||||
'QUESTDB_PASSWORD',
|
||||
];
|
||||
return preserveStringKeys.includes(key);
|
||||
}
|
||||
|
||||
private getProviderMapping(envKey: string): { path: string[] } | null {
|
||||
// Provider-specific and special environment variable mappings
|
||||
const providerMappings: Record<string, string[]> = {
|
||||
// Database mappings
|
||||
MONGODB_URI: ['database', 'mongodb', 'uri'],
|
||||
MONGODB_READ_URI: ['database', 'mongodb', 'readUri'],
|
||||
MONGODB_READ_ONLY: ['database', 'mongodb', 'readOnly'],
|
||||
MONGODB_DATABASE: ['database', 'mongodb', 'database'],
|
||||
MONGODB_HOST: ['database', 'mongodb', 'host'],
|
||||
MONGODB_PORT: ['database', 'mongodb', 'port'],
|
||||
MONGODB_USERNAME: ['database', 'mongodb', 'user'],
|
||||
MONGODB_PASSWORD: ['database', 'mongodb', 'password'],
|
||||
POSTGRES_HOST: ['database', 'postgres', 'host'],
|
||||
POSTGRES_PORT: ['database', 'postgres', 'port'],
|
||||
POSTGRES_DATABASE: ['database', 'postgres', 'database'],
|
||||
POSTGRES_USERNAME: ['database', 'postgres', 'user'],
|
||||
POSTGRES_PASSWORD: ['database', 'postgres', 'password'],
|
||||
POSTGRES_SSL: ['database', 'postgres', 'ssl'],
|
||||
DRAGONFLY_HOST: ['database', 'dragonfly', 'host'],
|
||||
DRAGONFLY_PORT: ['database', 'dragonfly', 'port'],
|
||||
DRAGONFLY_PASSWORD: ['database', 'dragonfly', 'password'],
|
||||
QUESTDB_HOST: ['database', 'questdb', 'host'],
|
||||
QUESTDB_PORT: ['database', 'questdb', 'httpPort'],
|
||||
|
||||
// WebShare provider mappings
|
||||
WEBSHARE_API_KEY: ['webshare', 'apiKey'],
|
||||
WEBSHARE_API_URL: ['webshare', 'apiUrl'],
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { z } from 'zod';
|
||||
|
||||
export const environmentSchema = z.enum(['development', 'test', 'production']);
|
||||
export const environmentSchema = z.enum(['development', 'qa', 'test', 'production']);
|
||||
|
||||
export const baseConfigSchema = z.object({
|
||||
environment: environmentSchema.optional(),
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ export const questdbConfigSchema = z.object({
|
|||
export const mongodbConfigSchema = z.object({
|
||||
enabled: z.boolean().default(true),
|
||||
uri: z.string().url(), // URI is required and contains all connection info
|
||||
readUri: z.string().url().optional(), // Optional read-only URI (e.g. dev data-pipeline reading QA MongoDB)
|
||||
readOnly: z.boolean().default(false).optional(),
|
||||
database: z.string(), // Database name for reference
|
||||
poolSize: z.number().min(1).max(100).default(10),
|
||||
// Optional fields for cases where URI parsing might fail
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { z } from 'zod';
|
||||
|
||||
export type Environment = 'development' | 'test' | 'production';
|
||||
export type Environment = 'development' | 'qa' | 'test' | 'production';
|
||||
|
||||
export interface ConfigLoader {
|
||||
load(): Record<string, unknown>;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ describe('Config Schemas', () => {
|
|||
describe('environmentSchema', () => {
|
||||
it('should accept valid environments', () => {
|
||||
expect(environmentSchema.parse('development')).toBe('development');
|
||||
expect(environmentSchema.parse('qa')).toBe('qa');
|
||||
expect(environmentSchema.parse('test')).toBe('test');
|
||||
expect(environmentSchema.parse('production')).toBe('production');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -14,6 +14,16 @@ import { HandlerScanner } from '../scanner';
|
|||
import { ServiceLifecycleManager } from '../utils/lifecycle';
|
||||
import type { ContainerBuildOptions, ServiceDefinitions } from './types';
|
||||
|
||||
function extractMongoDatabaseFromUri(uri?: string): string | undefined {
|
||||
if (!uri) return undefined;
|
||||
try {
|
||||
const db = new URL(uri).pathname.replace(/^\/+/, '').split('/')[0];
|
||||
return db || undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function getInfluxPort(config: { influxPort?: number; ilpPort?: number }): number {
|
||||
return config.influxPort ?? config.ilpPort ?? 9009;
|
||||
}
|
||||
|
|
@ -133,6 +143,16 @@ export class ServiceContainerBuilder {
|
|||
uri: 'mongodb://localhost:27017',
|
||||
database: '',
|
||||
}),
|
||||
...(this.options.mongoReadOnly
|
||||
? {
|
||||
uri: config.mongodb?.readUri ?? config.mongodb?.uri ?? 'mongodb://localhost:27017',
|
||||
database:
|
||||
extractMongoDatabaseFromUri(config.mongodb?.readUri) ??
|
||||
config.mongodb?.database ??
|
||||
'',
|
||||
readOnly: true,
|
||||
}
|
||||
: {}),
|
||||
enabled: this.options.enableMongoDB !== false && (config.mongodb?.enabled ?? true),
|
||||
},
|
||||
postgres: {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ export type ServiceCradle = ServiceDefinitions;
|
|||
export interface ServiceContainerOptions {
|
||||
enableQuestDB?: boolean;
|
||||
enableMongoDB?: boolean;
|
||||
mongoReadOnly?: boolean;
|
||||
enablePostgres?: boolean;
|
||||
enableCache?: boolean;
|
||||
enableQueue?: boolean;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export function registerDatabaseServices(
|
|||
password: config.mongodb.password,
|
||||
authSource: config.mongodb.authSource,
|
||||
uri: config.mongodb.uri,
|
||||
readOnly: config.mongodb.readOnly ?? false,
|
||||
poolSettings: {
|
||||
maxPoolSize: config.mongodb.poolSize,
|
||||
minPoolSize: 1,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ export interface QueuePoolConfig extends ConnectionPoolConfig {
|
|||
|
||||
export interface ConnectionFactoryConfig {
|
||||
service: string;
|
||||
environment: 'development' | 'production' | 'test';
|
||||
environment: 'development' | 'qa' | 'production' | 'test';
|
||||
pools?: {
|
||||
mongodb?: Partial<MongoDBPoolConfig>;
|
||||
postgres?: Partial<PostgreSQLPoolConfig>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue