mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
fix: typings and cleanup (#356)
* fix typings and cleanup * import type * rm unused import
This commit is contained in:
@@ -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>>;
|
||||
|
||||
@@ -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<Dependencies[K]>
|
||||
}
|
||||
type Insertable =
|
||||
| ((container: CoreContainer<Dependencies>) => 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<Dependencies>) => ({ [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<Dependencies>) => ({ [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<typeof dependencyBuilder>) => any
|
||||
|
||||
type ValidDependencyConfig =
|
||||
| CallbackBuilder
|
||||
| ((c: ReturnType<typeof dependencyBuilder>) => any)
|
||||
| DependencyConfiguration;
|
||||
|
||||
|
||||
|
||||
@@ -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';
|
||||
@@ -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> {
|
||||
@@ -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') {
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user