diff --git a/src/core/ioc.ts b/src/core/ioc.ts index ad32f31..0f0a7b1 100644 --- a/src/core/ioc.ts +++ b/src/core/ioc.ts @@ -1,10 +1,13 @@ -import type { IntoDependencies } from '../types/ioc'; import { Service as $Service, Services as $Services } from '@sern/ioc/global' import { Container } from '@sern/ioc'; +import * as Contracts from './interfaces'; import * as __Services from './structures/default-services'; import type { Logging } from './interfaces'; import { __init_container, useContainerRaw } from '@sern/ioc/global'; import { EventEmitter } from 'node:events'; +import { Client } from 'discord.js'; +import { Module } from '../types/core-modules'; +import { UnpackFunction } from '../types/utility'; export function disposeAll(logger: Logging|undefined) { useContainerRaw() @@ -117,3 +120,37 @@ export function transient(cb: () => () => T) { return cb()(); } +export type DependencyFromKey = Dependencies[T]; + + + +export type IntoDependencies = { + [Index in keyof Tuple]: UnpackFunction>>; //Unpack and make NonNullable +} & { length: Tuple['length'] }; + +export interface CoreDependencies { + /** + * discord.js client. + */ + '@sern/client': Client; + /** + * sern emitter listens to events that happen throughout + * the handler. some include module.register, module.activate. + */ + '@sern/emitter': Contracts.Emitter; + /** + * An error handler which is the final step before + * the sern process actually crashes. + */ + '@sern/errors': Contracts.ErrorHandling; + /** + * Optional logger. Performs ... logging + */ + '@sern/logger'?: Contracts.Logging; + /** + * Readonly module store. sern stores these + * by module.meta.id -> Module + */ + '@sern/modules': Map; +} + diff --git a/src/core/create-plugins.ts b/src/core/plugin.ts similarity index 96% rename from src/core/create-plugins.ts rename to src/core/plugin.ts index 9006b09..65c49cf 100644 --- a/src/core/create-plugins.ts +++ b/src/core/plugin.ts @@ -40,3 +40,6 @@ export const controller = { next: (val?: Record) => Ok(val), stop: (val?: string) => Err(val), }; + + +export type Controller = typeof controller; diff --git a/src/core/presences.ts b/src/core/presences.ts index 78b1024..4060fbc 100644 --- a/src/core/presences.ts +++ b/src/core/presences.ts @@ -1,5 +1,5 @@ import type { ActivitiesOptions } from "discord.js"; -import type { IntoDependencies } from "../types/ioc"; +import type { IntoDependencies } from "./ioc"; import type { Emitter } from "./interfaces"; type Status = 'online' | 'idle' | 'invisible' | 'dnd' diff --git a/src/index.ts b/src/index.ts index 7639692..183cb63 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,7 +38,6 @@ export type { export type { Payload, SernEventsMapping } from './types/utility'; -export type { CoreDependencies } from './types/ioc'; export { commandModule, @@ -48,12 +47,23 @@ export { export * from './core/presences' export * from './core/interfaces' -import type { controller } from './core/create-plugins'; -export type Controller = typeof controller -export * from './core/create-plugins'; +export * from './core/plugin'; export { CommandType, PluginType, PayloadType, EventType } from './core/structures/enums'; export { Context } from './core/structures/context'; -export { makeDependencies, single, transient, Service, Services } from './core/ioc'; +export { type CoreDependencies, makeDependencies, single, transient, Service, Services } from './core/ioc'; +import type { Container } from '@sern/ioc'; +/** + * @deprecated This old signature will be incompatible with future versions of sern. + * ```ts + * To switch your old code: + await makeDependencies(({ add }) => { + add('@sern/client', new Client()) + }) + * ``` + */ +export interface DependencyConfiguration { + build: (root: Container) => Container; +} diff --git a/src/types/dependencies.d.ts b/src/types/dependencies.d.ts index a66dedd..55db727 100644 --- a/src/types/dependencies.d.ts +++ b/src/types/dependencies.d.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ -import { CoreDependencies } from './ioc'; +import { CoreDependencies } from '../core/ioc'; declare global { /** diff --git a/src/types/ioc.ts b/src/types/ioc.ts deleted file mode 100644 index d9095c3..0000000 --- a/src/types/ioc.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { Container } from '@sern/ioc'; -import * as Contracts from '../core/interfaces'; -import type { UnpackFunction } from './utility' -import type { Client } from 'discord.js' -import { Module } from './core-modules'; - - -export interface CoreDependencies { - /** - * discord.js client. - */ - '@sern/client': Client; - /** - * sern emitter listens to events that happen throughout - * the handler. some include module.register, module.activate. - */ - '@sern/emitter': Contracts.Emitter; - /** - * An error handler which is the final step before - * the sern process actually crashes. - */ - '@sern/errors': Contracts.ErrorHandling; - /** - * Optional logger. Performs ... logging - */ - '@sern/logger'?: Contracts.Logging; - /** - * Readonly module store. sern stores these - * by module.meta.id -> Module - */ - '@sern/modules': Map; -} - -export type DependencyFromKey = Dependencies[T]; - -export type IntoDependencies = { - [Index in keyof Tuple]: UnpackFunction>>; //Unpack and make NonNullable -} & { length: Tuple['length'] }; - -/** - * @deprecated This old signature will be incompatible with future versions of sern. - * ```ts - * To switch your old code: - await makeDependencies(({ add }) => { - add('@sern/client', new Client()) - }) - * ``` - */ -export interface DependencyConfiguration { - build: (root: Container) => Container; -} diff --git a/test/core/create-plugin.test.ts b/test/core/create-plugin.test.ts index 5236a61..3aaa806 100644 --- a/test/core/create-plugin.test.ts +++ b/test/core/create-plugin.test.ts @@ -3,7 +3,7 @@ import { CommandControlPlugin, CommandInitPlugin, EventInitPlugin, -} from '../../src/core/create-plugins'; +} from '../../src'; import { PluginType, controller } from '../../src'; describe('create-plugins', () => { diff --git a/test/handlers.test.ts b/test/handlers.test.ts index 2428df7..e066ec9 100644 --- a/test/handlers.test.ts +++ b/test/handlers.test.ts @@ -7,7 +7,7 @@ import { faker } from '@faker-js/faker'; import { Module } from '../src/types/core-modules'; import { Processed } from '../src/types/core-modules'; import { EventEmitter } from 'events'; -import { EventType } from '../dist/core/structures/enums'; +import { EventType } from '../src/core/structures/enums'; import { CommandControlPlugin, CommandInitPlugin, CommandType, controller } from '../src'; vi.mock('discord.js', async (importOriginal) => {