diff --git a/src/_lib/Context.ts b/src/_lib/Context.ts index f532e65..c0aa080 100644 --- a/src/_lib/Context.ts +++ b/src/_lib/Context.ts @@ -1,39 +1,35 @@ import { Application, HookFn, makeApp } from '@/_lib/Application'; -type EntrypointFn> = (arg: Context) => Promise; +type RecordAny = Record -type BootFn> = (arg: Context) => Promise; +type EntrypointFn = (arg: Context) => Promise; -type Module, F extends BootFn = BootFn> = { +type BootFn = (arg: Context) => Promise; + +type Module = BootFn> = { name: string; fn: F; }; -type Context> = { +type Context = { app: Omit; bootstrap: []>(...modules: M) => Promise; } & T; -type ContextProvider> = { +type ContextProvider = { makeModule: , M extends Module>(name: string, fn: F) => M; withContext: >(fn: F) => () => Promise; }; type ContextOptions = { - shutdownTimeout: number; - logger: Pick; -}; - -const defaultOptions: ContextOptions = { - shutdownTimeout: 5000, - logger: console, + shutdownTimeout?: number; + logger?: Pick; }; -const makeContext = >( +const makeContext = ( localContext: T, - opts: Partial = {} + { logger = console, shutdownTimeout = 5000 }: ContextOptions ): ContextProvider => { - const { shutdownTimeout, logger } = { ...defaultOptions, ...opts }; const moduleKey = Symbol(); const app = makeApp({ shutdownTimeout, logger });