feat(config): add MosaicConfig schema + loader with tier auto-detection
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
import { Global, Inject, Module, type OnApplicationShutdown } from '@nestjs/common';
|
||||
import { createDb, type Db, type DbHandle } from '@mosaic/db';
|
||||
import { createStorageAdapter, type StorageAdapter } from '@mosaic/storage';
|
||||
import type { MosaicConfig } from '@mosaic/config';
|
||||
import { MOSAIC_CONFIG } from '../config/config.module.js';
|
||||
|
||||
export const DB_HANDLE = 'DB_HANDLE';
|
||||
export const DB = 'DB';
|
||||
export const STORAGE_ADAPTER = 'STORAGE_ADAPTER';
|
||||
|
||||
const DEFAULT_DATABASE_URL = 'postgresql://mosaic:mosaic@localhost:5432/mosaic';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [
|
||||
{
|
||||
provide: DB_HANDLE,
|
||||
useFactory: (): DbHandle => createDb(),
|
||||
useFactory: (config: MosaicConfig): DbHandle =>
|
||||
createDb(config.storage.type === 'postgres' ? config.storage.url : undefined),
|
||||
inject: [MOSAIC_CONFIG],
|
||||
},
|
||||
{
|
||||
provide: DB,
|
||||
@@ -22,11 +24,8 @@ const DEFAULT_DATABASE_URL = 'postgresql://mosaic:mosaic@localhost:5432/mosaic';
|
||||
},
|
||||
{
|
||||
provide: STORAGE_ADAPTER,
|
||||
useFactory: (): StorageAdapter =>
|
||||
createStorageAdapter({
|
||||
type: 'postgres',
|
||||
url: process.env['DATABASE_URL'] ?? DEFAULT_DATABASE_URL,
|
||||
}),
|
||||
useFactory: (config: MosaicConfig): StorageAdapter => createStorageAdapter(config.storage),
|
||||
inject: [MOSAIC_CONFIG],
|
||||
},
|
||||
],
|
||||
exports: [DB, STORAGE_ADAPTER],
|
||||
|
||||
Reference in New Issue
Block a user