refactored monorepo for more projects

This commit is contained in:
Boki 2025-06-22 23:48:01 -04:00
parent 4632c174dc
commit 9492f1b15e
180 changed files with 1438 additions and 424 deletions

View file

@ -1,11 +1,12 @@
// Import necessary types for singleton
// Import necessary types
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 { z } from 'zod';
// Create singleton instance
// Legacy singleton instance for backward compatibility
let configInstance: ConfigManager<AppConfig> | null = null;
// Synchronously load critical env vars for early initialization
@ -57,6 +58,7 @@ 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)
@ -143,8 +145,11 @@ 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 providers = getConfig().providers;
const config = getConfig() as any;
const providers = config.providers;
if (!providers || !(provider in providers)) {
throw new Error(`Provider configuration not found: ${provider}`);
}
@ -168,6 +173,39 @@ export function isTest(): boolean {
return getConfig().environment === 'test';
}
/**
* Generic config builder for creating app-specific configurations
* @param schema - Zod schema for your app config
* @param options - Config manager options
* @returns Initialized config manager instance
*/
export function createAppConfig<T extends z.ZodSchema>(
schema: T,
options?: {
configPath?: string;
environment?: 'development' | 'test' | 'production';
loaders?: any[];
}
): ConfigManager<z.infer<T>> {
const manager = new ConfigManager<z.infer<T>>(options);
return manager;
}
/**
* Create and initialize app config in one step
*/
export function initializeAppConfig<T extends z.ZodSchema>(
schema: T,
options?: {
configPath?: string;
environment?: 'development' | 'test' | 'production';
loaders?: any[];
}
): z.infer<T> {
const manager = createAppConfig(schema, options);
return manager.initialize(schema);
}
// Export all schemas
export * from './schemas';