mirror of
https://github.com/sern-handler/handler
synced 2026-06-27 02:02:14 +00:00
chore: modularize and split typings
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
import type { CommandInteractionOptionResolver } from 'discord.js';
|
||||
import type { PayloadType } from '../core/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 { InteractionReplyOptions, MessageReplyOptions, CommandInteractionOptionResolver } from 'discord.js';
|
||||
import type { EventEmitter } from 'node:events';
|
||||
import type { ErrorHandling, Logging, ModuleManager } from '../core/contracts';
|
||||
import type { ModuleStore } from '../core/structures/moduleStore';
|
||||
import type SernEmitter from '../core/sernEmitter';
|
||||
import type { Container } from 'iti';
|
||||
import type { SernEmitter } from '../core/sernEmitter';
|
||||
import { Processed } from './core';
|
||||
import { AnyModule, CommandModule, EventModule } from './module';
|
||||
import { PayloadType } from '../core';
|
||||
|
||||
export type Awaitable<T> = PromiseLike<T> | T;
|
||||
|
||||
@@ -20,69 +17,22 @@ 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 CoreDependencies {
|
||||
'@sern/logger'?: Singleton<Logging>;
|
||||
'@sern/emitter': Singleton<SernEmitter>;
|
||||
'@sern/store': Singleton<ModuleStore>;
|
||||
'@sern/modules': Singleton<ModuleManager>;
|
||||
'@sern/errors': Singleton<ErrorHandling>;
|
||||
}
|
||||
/**
|
||||
* To support older versions. Type alias for WebsocketDependencies
|
||||
* @deprecated
|
||||
*/
|
||||
export type Dependencies = WebsocketDependencies
|
||||
export interface ServerlessDependencies extends CoreDependencies {
|
||||
'@sern/client': never
|
||||
}
|
||||
|
||||
export interface WebsocketDependencies extends CoreDependencies {
|
||||
'@sern/client': Singleton<EventEmitter>;
|
||||
}
|
||||
export type AnyDependencies =
|
||||
| ServerlessDependencies
|
||||
| WebsocketDependencies;
|
||||
|
||||
export type ReplyOptions =
|
||||
| string
|
||||
| Omit<InteractionReplyOptions, 'fetchReply'>
|
||||
| MessageReplyOptions;
|
||||
//prettier-ignore
|
||||
export type MapDeps<Deps extends AnyDependencies, 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 AnyDependencies> {
|
||||
exclude?: Set<OptionalDependencies>;
|
||||
build: (root: Container<Omit<AnyDependencies, '@sern/client'>, {}>) => Container<T, {}>;
|
||||
}
|
||||
|
||||
export type ImportPayload<T> = { module: T; absPath: string };
|
||||
|
||||
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 interface SernEventsMapping {
|
||||
'module.register': [Payload];
|
||||
'module.activate': [Payload];
|
||||
error: [Payload];
|
||||
warning: [Payload];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user