import {type Static, type TObject, type TProperties} from '@sinclair/typebox' import {Value} from '@sinclair/typebox/value' import logger from 'log' import {read_object} from './src/read_type' const log = logger('config') export {Type} from '@sinclair/typebox' // Re-export Type so users can describe config export async function parse(scheme: TObject): Promise> | null> { log.info("Parse configuration from env") log.debug("Read configuration from env") const config = await read_object(scheme) if (!config.ok) return null // This check is kind of a duplicate, is it useful ? log.debug("Validate config against scheme") const config_parsed = Value.Check(scheme, config.data) if (config_parsed) { log.trace("Config is valid") return config.data } else { log.warn("Invalid config, check failed") return null } }