diff --git a/src/core/ioc/base.ts b/src/core/ioc/base.ts index 8796864..31b173d 100644 --- a/src/core/ioc/base.ts +++ b/src/core/ioc/base.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; import { composeRoot, useContainer } from './dependency-injection'; -import { Dependencies, DependencyConfiguration } from './types'; +import { DependencyConfiguration } from './types'; import { CoreContainer } from '../structures/container'; //SIDE EFFECT: GLOBAL DI diff --git a/src/core/ioc/dependencies.d.ts b/src/core/ioc/dependencies.d.ts new file mode 100644 index 0000000..e0aba1c --- /dev/null +++ b/src/core/ioc/dependencies.d.ts @@ -0,0 +1,10 @@ +import { CoreDependencies } from './types' + +declare global { + + interface Dependencies extends CoreDependencies {} +} + + + + diff --git a/src/core/ioc/dependency-injection.ts b/src/core/ioc/dependency-injection.ts index 23485cc..3bef787 100644 --- a/src/core/ioc/dependency-injection.ts +++ b/src/core/ioc/dependency-injection.ts @@ -1,9 +1,7 @@ import type { - DependencyConfiguration, - MapDeps, - IntoDependencies, - Dependencies, CoreDependencies, + DependencyConfiguration, + IntoDependencies, } from './types'; import { DefaultLogging } from '../structures'; import { SernError } from '../structures/errors'; @@ -57,7 +55,7 @@ export async function composeRoot( }); } //Build the container based on the callback provided by the user - conf.build(container as CoreContainer); + conf.build(container as CoreContainer>); try { container.get('@sern/client'); } catch { @@ -78,5 +76,5 @@ export function useContainer() { Use the new Service(s) api function instead. `); return (...keys: [...V]) => - keys.map(key => useContainerRaw().get(key as keyof Dependencies)) as MapDeps; + keys.map(key => useContainerRaw().get(key as keyof Dependencies)) as IntoDependencies; } diff --git a/src/core/ioc/index.ts b/src/core/ioc/index.ts index 747385d..f3f82cd 100644 --- a/src/core/ioc/index.ts +++ b/src/core/ioc/index.ts @@ -1,3 +1,3 @@ export { useContainerRaw, makeDependencies } from './base'; export { Service, Services, single, transient } from './dependency-injection'; -export type { Singleton, Transient } from './types'; +export type { Singleton, Transient, CoreDependencies } from './types'; diff --git a/src/core/ioc/types.ts b/src/core/ioc/types.ts index 0a1788b..31e6bd7 100644 --- a/src/core/ioc/types.ts +++ b/src/core/ioc/types.ts @@ -1,19 +1,17 @@ +import { EventEmitter } from 'node:events'; import { Container, UnpackFunction } from 'iti'; -import * as Contract from '../contracts'; export type Singleton = () => T; export type Transient = () => () => T; export interface CoreDependencies { - '@sern/logger'?: Singleton; - '@sern/emitter': Singleton; - '@sern/store': Singleton; - '@sern/modules': Singleton; - '@sern/errors': Singleton; + '@sern/client': () => EventEmitter + '@sern/logger'?: () => import('../contracts').Logging; + '@sern/emitter': () => import('../structures/sern-emitter').SernEmitter; + '@sern/store': () => import('../contracts').CoreModuleStore; + '@sern/modules': () => import('../contracts').ModuleManager; + '@sern/errors': () => import('../contracts').ErrorHandling; } -export interface Dependencies extends CoreDependencies { - '@sern/client': Singleton; -} export type DependencyFromKey = Dependencies[T]; export type IntoDependencies = { @@ -23,17 +21,6 @@ export type IntoDependencies = { export interface DependencyConfiguration { //@deprecated. Loggers will always be included in the future exclude?: Set<'@sern/logger'>; - build: (root: Container) => Container; + build: (root: Container, {}>) => Container; } -//To be removed in future -//prettier-ignore -export type MapDeps = T extends [ - infer First extends keyof Deps, - ...infer Rest extends readonly unknown[], -] - ? [ - UnpackFunction, - ...(MapDeps extends [never] ? [] : MapDeps), - ] - : [never]; diff --git a/src/core/structures/container.ts b/src/core/structures/container.ts index 82a22fd..65cc41a 100644 --- a/src/core/structures/container.ts +++ b/src/core/structures/container.ts @@ -4,7 +4,6 @@ import { isAsyncFunction } from 'node:util/types'; import * as assert from 'node:assert'; import { Subject } from 'rxjs'; import { ModuleStore } from './module-store'; -import { Dependencies } from '../ioc/types'; /** * Provides all the defaults for sern to function properly. @@ -41,7 +40,8 @@ export class CoreContainer> extends Container(mod: { }); } -function prepareClassPlugins(c: Module) { +function preparePlugins(c: Module) { const [onEvent, initPlugins] = partitionPlugins(c.plugins); c.plugins = initPlugins as InitPlugin[]; c.onEvent = onEvent as ControlPlugin[]; @@ -83,7 +83,7 @@ export abstract class CommandExecutable { - const endTime = performance.now(); + const time = ((performance.now() - startTime) / 1000).toFixed(2); logger?.info({ - message: `sern: registered all modules in ${((endTime - startTime) / 1000).toFixed( - 2, - )} s`, + message: `sern: registered all modules in ${time} s`, }); }); diff --git a/src/handler/types.ts b/src/handler/types.ts index 756e67c..5b0c2d4 100644 --- a/src/handler/types.ts +++ b/src/handler/types.ts @@ -1,5 +1,5 @@ import { ErrorHandling, Logging, ModuleManager, SernEmitter } from '../core'; -import EventEmitter from 'node:events'; +import { EventEmitter } from 'node:events'; import { Module } from '../core/types/modules'; export type Processed = T & { name: string; description: string }; diff --git a/src/shared.ts b/src/shared.ts index 5b1d818..aec7fb9 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -5,7 +5,6 @@ import type { } from 'discord.js'; import { PayloadType } from './core'; import { AnyModule } from './core/types/modules'; -import { Dependencies } from './core/ioc/types'; export type ReplyOptions = | string diff --git a/tsconfig-base.json b/tsconfig-base.json index a33b061..e145f2d 100644 --- a/tsconfig-base.json +++ b/tsconfig-base.json @@ -15,5 +15,5 @@ "isolatedModules": true }, "exclude": ["node_modules", "dist"], - "include": ["src", "**/*.d.ts"] + "include": ["./src", "./src/**/*.d.ts"] }