mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
* feat: experimental plugin changes * more refactors and name changes * feat: update name usage and update dispatchers.ts * fix:naming * feat: slightly safer typings than any[] * fix: forgot to destructure arguments * feat: add special function * fix: typings * feat: SUPER SIMPLIFY!!! * refactor: move promisifiedPlugins closer to call site * refactor: typings * refactor: typings * refactor: consolidate resolving initplugins into one function * refactor: better types * revert: remove unneeded function * revert: remove unneeded function * feat: dispatch work, simplify * feat: move some observableHandling function to operators for clarity * feat: simplify and document * feat: simplifying sern and docs * fix: typings * docs: clarity of function name * docs: add documentation for executeModule * feat: contextArgs overloads * docs: found out why * fix: typings * feat: shorten operators signature * refactor: switch to correct convention * refactor: take(1) -> first() * refactor: revert * refactor: safer typings (less any) and more accurate typings * style: prettier and short type aliases * fix: typings * fix: typings * docs: add deprecations * refactor: organization and moving stuff * pretty: prettey * docs: describe file * chore: update dependencies and version * docs: fix link for docasaurus * refactor: using a more appropriate operator function for closing an observable on crash * fix!: changing single and many * refactor: typings and simplifying composeRoot * fix: re-add logger into handleError * docs: comment * docs: new section * feat: help mitigate breaking changes * feat: help mitigate breaking changes * feat: help mitigate breaking changes and function overloads * feat: deprecate instead of remove * feat: partial remove and deprecate old symbols * revert: trying to accommodate old plugins is too difficult * docs: add many as deprecated * docs: update * feat: partial backwards compatability * refactor: renaming, docs, and exports more clean * refactor: context got a lot simpler * refactor: imports * docs: explain methods
69 lines
2.9 KiB
TypeScript
69 lines
2.9 KiB
TypeScript
import type { CommandInteractionOptionResolver } from 'discord.js';
|
|
import type { PayloadType } from '../handler/structures/enums';
|
|
import type { InteractionReplyOptions, MessageReplyOptions } from 'discord.js';
|
|
import type { EventEmitter } from 'events';
|
|
import type { CommandModule, EventModule, AnyModule } from './module';
|
|
import type { UnpackFunction } from 'iti';
|
|
import type { ErrorHandling, Logging, ModuleManager } from '../handler/contracts';
|
|
import type { ModuleStore } from '../handler/structures/moduleStore';
|
|
import type SernEmitter from '../handler/sernEmitter';
|
|
import type { Container } from 'iti';
|
|
// Thanks to @kelsny
|
|
export type ParseType<T> = {
|
|
[K in keyof T]: T[K] extends unknown ? [k: K, args: T[K]] : never;
|
|
}[keyof T];
|
|
|
|
export type Args = ParseType<{ text: string[]; slash: SlashOptions }>;
|
|
|
|
export type SlashOptions = Omit<CommandInteractionOptionResolver, 'getMessage' | 'getFocused'>;
|
|
|
|
/**
|
|
* After modules are transformed, name and description are given default values if none
|
|
* are provided to Module. This type represents that transformation
|
|
*/
|
|
export type AnyDefinedModule = Processed<CommandModule | EventModule>;
|
|
export type Payload =
|
|
| { type: PayloadType.Success; module: AnyModule }
|
|
| { type: PayloadType.Failure; module?: AnyModule; reason: string | Error }
|
|
| { type: PayloadType.Warning; reason: string };
|
|
export type SernEventsMapping = {
|
|
'module.register': [Payload];
|
|
'module.activate': [Payload];
|
|
error: [Payload];
|
|
warning: [Payload];
|
|
};
|
|
export type LogPayload<T = unknown> = { message: T };
|
|
export type Singleton<T> = () => T;
|
|
export type Transient<T> = () => () => T;
|
|
|
|
export interface Dependencies {
|
|
'@sern/client': Singleton<EventEmitter>;
|
|
'@sern/logger'?: Singleton<Logging>;
|
|
'@sern/emitter': Singleton<SernEmitter>;
|
|
'@sern/store': Singleton<ModuleStore>;
|
|
'@sern/modules': Singleton<ModuleManager>;
|
|
'@sern/errors': Singleton<ErrorHandling>;
|
|
}
|
|
|
|
export type ReplyOptions =
|
|
| string
|
|
| Omit<InteractionReplyOptions, 'fetchReply'>
|
|
| MessageReplyOptions;
|
|
//prettier-ignore
|
|
export type MapDeps<Deps extends Dependencies, T extends readonly unknown[]> = T extends [
|
|
infer First extends keyof Deps,
|
|
...infer Rest extends readonly unknown[],
|
|
]
|
|
? [
|
|
UnpackFunction<Deps[First]>,
|
|
...(MapDeps<Deps, Rest> extends [never] ? [] : MapDeps<Deps, Rest>),
|
|
]
|
|
: [never];
|
|
//Basically, '@sern/client' | '@sern/store' | '@sern/modules' | '@sern/error' | '@sern/emitter' will be provided defaults, and you can exclude the rest
|
|
export type OptionalDependencies = '@sern/logger';
|
|
export type Processed<T> = T & { name: string; description: string };
|
|
export type Deprecated<Message extends string> = [never, Message]
|
|
export interface DependencyConfiguration<T extends Dependencies> {
|
|
exclude?: Set<OptionalDependencies>;
|
|
build: (root: Container<Omit<Dependencies, '@sern/client'>, {}>) => Container<T, {}>
|
|
} |