Skip to content

Commit ce8c4bf

Browse files
authored
fix: typings and cleanup (#356)
* fix typings and cleanup * import type * rm unused import
1 parent e89b918 commit ce8c4bf

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

src/core/ioc/base.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Result } from 'ts-results-es';
66
import { __Services } from '../_internal';
77
import { AnyFunction } from '../../types/utility';
88
import type { Logging } from '../contracts/logging';
9-
9+
import type { UnpackFunction } from 'iti';
1010
//SIDE EFFECT: GLOBAL DI
1111
let containerSubject: CoreContainer<Partial<Dependencies>>;
1212

@@ -34,7 +34,7 @@ export function __add_container(key: string,v : Insertable) {
3434
/**
3535
* Returns the underlying data structure holding all dependencies.
3636
* Exposes methods from iti
37-
* Use the Service API. The container should be readonly
37+
* Use the Service API. The container should be readonly from the consumer side
3838
*/
3939
export function useContainerRaw() {
4040
assert.ok(
@@ -49,8 +49,11 @@ export function disposeAll(logger: Logging|undefined) {
4949
?.disposeAll()
5050
.then(() => logger?.info({ message: 'Cleaning container and crashing' }));
5151
}
52+
type UnpackedDependencies = {
53+
[K in keyof Dependencies]: UnpackFunction<Dependencies[K]>
54+
}
5255
type Insertable =
53-
| ((container: CoreContainer<Dependencies>) => unknown)
56+
| ((container: UnpackedDependencies) => unknown)
5457
| object
5558
const dependencyBuilder = (container: any, excluded: string[] ) => {
5659
return {
@@ -64,7 +67,7 @@ const dependencyBuilder = (container: any, excluded: string[] ) => {
6467
.expect("Failed to add " + key);
6568
} else {
6669
Result.wrap(() =>
67-
container.add((cntr: CoreContainer<Dependencies>) => ({ [key]: v(cntr)} )))
70+
container.add((cntr: UnpackedDependencies) => ({ [key]: v(cntr)} )))
6871
.expect("Failed to add " + key);
6972
}
7073
},
@@ -87,7 +90,7 @@ const dependencyBuilder = (container: any, excluded: string[] ) => {
8790
.expect("Failed to update " + key);
8891
} else {
8992
Result.wrap(() =>
90-
container.upsert((cntr: CoreContainer<Dependencies>) => ({ [key]: v(cntr)})))
93+
container.upsert((cntr: UnpackedDependencies) => ({ [key]: v(cntr)})))
9194
.expect("Failed to update " + key);
9295
}
9396
},
@@ -107,10 +110,9 @@ const dependencyBuilder = (container: any, excluded: string[] ) => {
107110
};
108111
};
109112

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

112114
type ValidDependencyConfig =
113-
| CallbackBuilder
115+
| ((c: ReturnType<typeof dependencyBuilder>) => any)
114116
| DependencyConfiguration;
115117

116118

src/core/module-loading.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Result } from 'ts-results-es';
21
import { type Observable, from, mergeMap, ObservableInput } from 'rxjs';
32
import { readdir, stat } from 'fs/promises';
43
import { basename, extname, join, resolve, parse, dirname } from 'path';
@@ -42,9 +41,7 @@ export async function importModule<T>(absPath: string) {
4241
if ('default' in commandModule ) {
4342
commandModule = commandModule.default;
4443
}
45-
return Result
46-
.wrap(() => ({ module: commandModule.getInstance() }))
47-
.unwrapOr({ module: commandModule }) as T;
44+
return { module: commandModule } as T;
4845
}
4946

5047
export async function defaultModuleLoader<T extends Module>(absPath: string): ModuleResult<T> {
@@ -106,7 +103,7 @@ async function* readPaths(dir: string): AsyncGenerator<string> {
106103
}
107104
}
108105

109-
export const requir = createRequire(import.meta.url);
106+
const requir = createRequire(import.meta.url);
110107

111108
export function loadConfig(wrapper: Wrapper | 'file', log: Logging | undefined): Wrapper {
112109
if (wrapper !== 'file') {

src/core/presences.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ export type Config <T extends (keyof Dependencies)[]> =
2525
* Create a Presence module which **MUST** be put in a file called presence.(language-extension)
2626
* adjacent to the file where **Sern.init** is CALLED.
2727
*/
28-
export function module<T extends (keyof Dependencies)[]>
29-
(conf: Config<T>) {
30-
return conf;
31-
}
28+
export function module<T extends (keyof Dependencies)[]>(conf: Config<T>)
29+
{ return conf; }
3230

3331

3432
/**

0 commit comments

Comments
 (0)