@bunito/config
v0.0.27
Published
Configuration module with environment parsing, typed config factories, secret lookup, and test helpers.
Maintainers
Readme
@bunito/config
Configuration module for bunito applications.
It provides typed config factories, environment parsing, value formatting, runtime flags, and secret lookup through pluggable readers.
Installation 📦
bun add @bunito/configUsage ✨
import { ConfigModule, defineConfig } from '@bunito/config';
import { Module } from '@bunito/container';
const AppConfig = defineConfig(function AppConfig({ getEnv }) {
return {
port: getEnv('PORT', 'port') ?? 3000,
};
});
@Module({
imports: [ConfigModule],
configs: [AppConfig],
})
class AppModule {}Testing 🧪
Importing @bunito/config registers config test factories on the shared
@bunito/testing Test context:
Test.ConfigModule: aConfigModulereplacement exporting a mockedConfigService.Test.configService: a mockedConfigServicecreated withmockClass().Test.defineConfig: a helper for replacing config providers with fixed test values.
import { ConfigService, defineConfig } from '@bunito/config';
import { App } from '@bunito/bunito';
import { Test } from '@bunito/testing';
const AppConfig = defineConfig(function AppConfig() {
return {
port: 3000,
};
});
const app = await App.start({
imports: [Test.ConfigModule],
configs: [
Test.defineConfig(AppConfig, {
port: 53100,
}),
],
});
const config = await app.resolve(ConfigService);
expect(config).toBe(Test.configService);Use Test.defineConfig() when a module expects a typed config provider but the
test should avoid real environment or secret reads.
License
MIT
