implement config
This commit is contained in:
+17
-7
@@ -1,17 +1,27 @@
|
||||
import logger from 'log'
|
||||
import * as yup from 'yup'
|
||||
|
||||
import {Ok} from './helpers'
|
||||
import * as parsing from './parsing'
|
||||
import type {Ok} from './helpers'
|
||||
|
||||
// TODO : re-export types used to describe schema
|
||||
export * as yup from 'yup'
|
||||
|
||||
const log = logger('config')
|
||||
|
||||
export async function parse<S>(schema: S): Promise<Ok<unknown>> {
|
||||
log.info("Parse configuration from env")
|
||||
export async function parse<S extends yup.Maybe<yup.AnyObject>>(schema: yup.ObjectSchema<S>): Promise<Ok<S>> {
|
||||
log.info("Parse from env")
|
||||
|
||||
// TODO : Read config from env
|
||||
log.trace("Start parsing")
|
||||
const config = await parsing.object(schema)
|
||||
if (!config.ok) return config
|
||||
|
||||
// TODO : maybe double check config
|
||||
log.trace("double-check")
|
||||
const res = await schema.isValid(config.data, {strict: true})
|
||||
if (!res) {
|
||||
log.error("Double-check failed")
|
||||
log.debug('Config', config.data)
|
||||
return {ok: false}
|
||||
}
|
||||
|
||||
return {ok: false}
|
||||
return config
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user