@sern/handler
Version:
A complete, customizable, typesafe, & reactive framework for discord bots.
103 lines (102 loc) • 3.57 kB
TypeScript
import { Container } from '@sern/ioc';
import * as Contracts from './interfaces';
import * as __Services from './structures/default-services';
import type { Logging } from './interfaces';
import { Client } from 'discord.js';
import { Module } from '../types/core-modules';
import { UnpackFunction } from '../types/utility';
export declare function disposeAll(logger: Logging | undefined): void;
type Insertable = ((container: Dependencies) => object) | object;
declare const dependencyBuilder: (container: Container) => {
/**
* Insert a dependency into your container.
* Supply the correct key and dependency
*/
add(key: keyof Dependencies, v: Insertable): void;
/**
* @param key the key of the dependency
* @param v The dependency to swap out.
* Swap out a preexisting dependency.
*/
swap(key: keyof Dependencies, v: Insertable): void;
};
type ValidDependencyConfig = (c: ReturnType<typeof dependencyBuilder>) => any;
/**
* makeDependencies constructs a dependency injection container for sern handler to use.
* This is required to start the handler, and is to be called before Sern.init.
* @example
* ```ts
* await makeDependencies(({ add }) => {
* add('@sern/client', new Client({ intents, partials })
* })
* ```
*/
export declare function makeDependencies(conf: ValidDependencyConfig): Promise<void>;
/**
* The Service api, which allows users to access dependencies in places IOC cannot reach.
* To obtain intellisense, ensure a .d.ts file exists in the root of compilation.
* Our scaffolding tool takes care of this.
* Note: this method only works AFTER your container has been initiated
* @since 3.0.0
* @example
* ```ts
* const client = Service('@sern/client');
* ```
* @param key a key that corresponds to a dependency registered.
* @throws if container is absent or not present
*/
export declare function Service<const T extends keyof Dependencies>(key: T): Dependencies[T];
/**
* @since 3.0.0
* The plural version of {@link Service}
* @throws if container is absent or not present
* @returns array of dependencies, in the same order of keys provided
*
*/
export declare function Services<const T extends (keyof Dependencies)[]>(...keys: [...T]): IntoDependencies<T>;
/**
* @deprecated
* Creates a singleton object.
* @param cb
*/
export declare function single<T>(cb: () => T): T;
/**
* @deprecated
* @since 2.0.0
* Creates a transient object
* @param cb
*/
export declare function transient<T>(cb: () => () => T): T;
export type DependencyFromKey<T extends keyof Dependencies> = Dependencies[T];
export type IntoDependencies<Tuple extends [...any[]]> = {
[Index in keyof Tuple]: UnpackFunction<NonNullable<DependencyFromKey<Tuple[Index]>>>;
} & {
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<string, Module>;
'@sern/scheduler': __Services.TaskScheduler;
}
export {};