From fd1cf33f3b4f17c9aae3230b1403d34bd0e97af3 Mon Sep 17 00:00:00 2001 From: jacob Date: Sun, 18 Feb 2024 01:27:06 -0600 Subject: [PATCH] fix typings and cleanup --- src/core/ioc/base.ts | 16 +++++++++------- src/core/module-loading.ts | 6 ++---- src/core/presences.ts | 6 ++---- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/core/ioc/base.ts b/src/core/ioc/base.ts index d55538de..8b5a32c4 100644 --- a/src/core/ioc/base.ts +++ b/src/core/ioc/base.ts @@ -6,7 +6,7 @@ import { Result } from 'ts-results-es'; import { __Services } from '../_internal'; import { AnyFunction } from '../../types/utility'; import type { Logging } from '../contracts/logging'; - +import { UnpackFunction } from 'iti'; //SIDE EFFECT: GLOBAL DI let containerSubject: CoreContainer>; @@ -34,7 +34,7 @@ export function __add_container(key: string,v : Insertable) { /** * Returns the underlying data structure holding all dependencies. * Exposes methods from iti - * Use the Service API. The container should be readonly + * Use the Service API. The container should be readonly from the consumer side */ export function useContainerRaw() { assert.ok( @@ -49,8 +49,11 @@ export function disposeAll(logger: Logging|undefined) { ?.disposeAll() .then(() => logger?.info({ message: 'Cleaning container and crashing' })); } +type UnpackedDependencies = { + [K in keyof Dependencies]: UnpackFunction +} type Insertable = - | ((container: CoreContainer) => unknown) + | ((container: UnpackedDependencies) => unknown) | object const dependencyBuilder = (container: any, excluded: string[] ) => { return { @@ -64,7 +67,7 @@ const dependencyBuilder = (container: any, excluded: string[] ) => { .expect("Failed to add " + key); } else { Result.wrap(() => - container.add((cntr: CoreContainer) => ({ [key]: v(cntr)} ))) + container.add((cntr: UnpackedDependencies) => ({ [key]: v(cntr)} ))) .expect("Failed to add " + key); } }, @@ -87,7 +90,7 @@ const dependencyBuilder = (container: any, excluded: string[] ) => { .expect("Failed to update " + key); } else { Result.wrap(() => - container.upsert((cntr: CoreContainer) => ({ [key]: v(cntr)}))) + container.upsert((cntr: UnpackedDependencies) => ({ [key]: v(cntr)}))) .expect("Failed to update " + key); } }, @@ -107,10 +110,9 @@ const dependencyBuilder = (container: any, excluded: string[] ) => { }; }; -type CallbackBuilder = (c: ReturnType) => any type ValidDependencyConfig = - | CallbackBuilder + | ((c: ReturnType) => any) | DependencyConfiguration; diff --git a/src/core/module-loading.ts b/src/core/module-loading.ts index a5e89690..b02b2b18 100644 --- a/src/core/module-loading.ts +++ b/src/core/module-loading.ts @@ -42,9 +42,7 @@ export async function importModule(absPath: string) { if ('default' in commandModule ) { commandModule = commandModule.default; } - return Result - .wrap(() => ({ module: commandModule.getInstance() })) - .unwrapOr({ module: commandModule }) as T; + return { module: commandModule } as T; } export async function defaultModuleLoader(absPath: string): ModuleResult { @@ -106,7 +104,7 @@ async function* readPaths(dir: string): AsyncGenerator { } } -export const requir = createRequire(import.meta.url); +const requir = createRequire(import.meta.url); export function loadConfig(wrapper: Wrapper | 'file', log: Logging | undefined): Wrapper { if (wrapper !== 'file') { diff --git a/src/core/presences.ts b/src/core/presences.ts index c587575e..594c836f 100644 --- a/src/core/presences.ts +++ b/src/core/presences.ts @@ -25,10 +25,8 @@ export type Config = * Create a Presence module which **MUST** be put in a file called presence.(language-extension) * adjacent to the file where **Sern.init** is CALLED. */ -export function module -(conf: Config) { - return conf; -} +export function module(conf: Config) +{ return conf; } /**