Skip to content

Commit

Permalink
fix: typings and cleanup (#356)
Browse files Browse the repository at this point in the history
* fix typings and cleanup

* import type

* rm unused import
  • Loading branch information
jacoobes authored Feb 18, 2024
1 parent e89b918 commit ce8c4bf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
16 changes: 9 additions & 7 deletions src/core/ioc/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 type { UnpackFunction } from 'iti';
//SIDE EFFECT: GLOBAL DI
let containerSubject: CoreContainer<Partial<Dependencies>>;

Expand Down Expand Up @@ -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(
Expand All @@ -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<Dependencies[K]>
}
type Insertable =
| ((container: CoreContainer<Dependencies>) => unknown)
| ((container: UnpackedDependencies) => unknown)
| object
const dependencyBuilder = (container: any, excluded: string[] ) => {
return {
Expand All @@ -64,7 +67,7 @@ const dependencyBuilder = (container: any, excluded: string[] ) => {
.expect("Failed to add " + key);
} else {
Result.wrap(() =>
container.add((cntr: CoreContainer<Dependencies>) => ({ [key]: v(cntr)} )))
container.add((cntr: UnpackedDependencies) => ({ [key]: v(cntr)} )))
.expect("Failed to add " + key);
}
},
Expand All @@ -87,7 +90,7 @@ const dependencyBuilder = (container: any, excluded: string[] ) => {
.expect("Failed to update " + key);
} else {
Result.wrap(() =>
container.upsert((cntr: CoreContainer<Dependencies>) => ({ [key]: v(cntr)})))
container.upsert((cntr: UnpackedDependencies) => ({ [key]: v(cntr)})))
.expect("Failed to update " + key);
}
},
Expand All @@ -107,10 +110,9 @@ const dependencyBuilder = (container: any, excluded: string[] ) => {
};
};

type CallbackBuilder = (c: ReturnType<typeof dependencyBuilder>) => any

type ValidDependencyConfig =
| CallbackBuilder
| ((c: ReturnType<typeof dependencyBuilder>) => any)
| DependencyConfiguration;


Expand Down
7 changes: 2 additions & 5 deletions src/core/module-loading.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Result } from 'ts-results-es';
import { type Observable, from, mergeMap, ObservableInput } from 'rxjs';
import { readdir, stat } from 'fs/promises';
import { basename, extname, join, resolve, parse, dirname } from 'path';
Expand Down Expand Up @@ -42,9 +41,7 @@ export async function importModule<T>(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<T extends Module>(absPath: string): ModuleResult<T> {
Expand Down Expand Up @@ -106,7 +103,7 @@ async function* readPaths(dir: string): AsyncGenerator<string> {
}
}

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') {
Expand Down
6 changes: 2 additions & 4 deletions src/core/presences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ export type Config <T extends (keyof Dependencies)[]> =
* 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<T extends (keyof Dependencies)[]>
(conf: Config<T>) {
return conf;
}
export function module<T extends (keyof Dependencies)[]>(conf: Config<T>)
{ return conf; }


/**
Expand Down

0 comments on commit ce8c4bf

Please sign in to comment.