bakit 1.0.0-beta.4 → 1.0.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { B as BakitClient } from './BakitClient-CgtDS6Hr.js';
2
- export { A as Arg, d as ArgumentOptions, b as ArgumentType, a as BakitClientOptions, c as BaseArgumentOptions, i as BaseCommandEntry, g as BaseCommandEntryOptions, j as BaseCommandGroupEntry, u as BaseContext, v as ChatInputContext, r as ChatInputContextSendOptions, p as Command, n as CommandConstructor, m as CommandEntry, o as CommandFactory, k as CommandGroupEntry, f as CommandHook, C as CommandHookExecutionState, e as CommandHookMethod, q as CommandRegistry, D as CommandSyntaxError, z as CommandSyntaxErrorOptions, y as CommandSyntaxErrorType, x as Context, t as ContextSendOptions, h as CreateCommandOptions, G as GetSyntaxErrorMessageFunction, H as HOOKS_KEY, I as IntegerArgumentOptions, M as MemberArgumentOptions, w as MessageContext, s as MessageContextSendOptions, N as NumberArgumentOptions, R as RootCommandEntry, S as StringArgumentOptions, l as SubcommandEntry, U as UserArgumentOptions } from './BakitClient-CgtDS6Hr.js';
1
+ import { B as BaseEntry, C as ConstructorLike, a as BaseHook, b as BaseMainHookMethod, c as BaseErrorHookMethod, d as BakitClient } from './BakitClient-CU9viQZL.js';
2
+ export { A as Arg, h as ArgumentOptions, f as ArgumentType, e as BakitClientOptions, g as BaseArgumentOptions, m as BaseCommandEntry, k as BaseCommandEntryOptions, n as BaseCommandGroupEntry, x as BaseContext, y as ChatInputContext, u as ChatInputContextSendOptions, s as Command, q as CommandAPI, r as CommandFactory, o as CommandGroupEntry, j as CommandHook, t as CommandRegistry, J as CommandSyntaxError, H as CommandSyntaxErrorOptions, F as CommandSyntaxErrorType, D as Context, w as ContextSendOptions, l as CreateCommandOptions, E as ErrorCommandHookMethod, G as GetSyntaxErrorMessageFunction, I as IntegerArgumentOptions, i as MainCommandHookMethod, M as MemberArgumentOptions, z as MessageContext, v as MessageContextSendOptions, N as NumberArgumentOptions, R as RootCommandEntry, S as StringArgumentOptions, p as SubcommandEntry, U as UserArgumentOptions } from './BakitClient-CU9viQZL.js';
3
3
  import { AsyncLocalStorage } from 'node:async_hooks';
4
- import { SetOptional } from 'type-fest';
5
- import { Awaitable, ClientEvents } from 'discord.js';
4
+ import { ClientEvents } from 'discord.js';
6
5
  import EventEmitter from 'node:events';
6
+ import { SetOptional } from 'type-fest';
7
7
 
8
8
  declare function extractId(value: string): string | null;
9
9
 
@@ -18,68 +18,79 @@ declare class StateBox {
18
18
  }
19
19
 
20
20
  type EventsLike = Record<keyof unknown, unknown[]>;
21
- type EventKey<E extends EventsLike> = keyof E;
22
- declare enum ListenerHookExecutionState {
23
- Main = "main",
24
- Pre = "pre",
25
- Post = "post",
26
- Error = "error"
27
- }
28
- type MainListenerHookMethod<E extends EventsLike, K extends EventKey<E>> = (...args: E[K] & unknown[]) => Awaitable<void>;
29
- type ErrorListenerHookMethod<E extends EventsLike, K extends EventKey<E>> = (error: unknown, ...args: E[K] & unknown[]) => Awaitable<void>;
30
- interface MainListenerHook<E extends EventsLike, K extends EventKey<E>> {
31
- state: ListenerHookExecutionState.Main | ListenerHookExecutionState.Post | ListenerHookExecutionState.Pre;
32
- method: MainListenerHookMethod<E, K>;
33
- entry: ListenerEntry<E, K>;
21
+ type MainListenerHookMethod<Args extends unknown[]> = BaseMainHookMethod<Args>;
22
+ type ErrorListenerHookMethod<Args extends unknown[]> = BaseErrorHookMethod<Args>;
23
+ interface ListenerHook<E extends EventsLike, K extends keyof E> extends BaseHook {
24
+ method: MainListenerHookMethod<E[K] & unknown[]> | ErrorListenerHookMethod<E[K] & unknown[]>;
34
25
  }
35
- interface ErrorListenerHook<E extends EventsLike, K extends EventKey<E>> {
36
- state: ListenerHookExecutionState.Error;
37
- method: ErrorListenerHookMethod<E, K>;
38
- entry: ListenerEntry<E, K>;
39
- }
40
- type ListenerHook<E extends EventsLike, K extends EventKey<E>> = MainListenerHook<E, K> | ErrorListenerHook<E, K>;
41
- interface ListenerEntryOptions<E extends EventsLike, K extends EventKey<E>> {
26
+ interface ListenerEntryOptions<E extends EventsLike, K extends keyof E> {
42
27
  name: K;
43
28
  once: boolean;
44
29
  emitter?: EventEmitter;
45
30
  }
46
- declare class ListenerEntry<E extends EventsLike, K extends EventKey<E>> {
31
+ declare class ListenerEntry<E extends EventsLike, K extends keyof E> extends BaseEntry<ConstructorLike, ListenerHook<E, K>, MainListenerHookMethod<E[K] & unknown[]>, ErrorListenerHookMethod<E[K] & unknown[]>> {
47
32
  options: ListenerEntryOptions<E, K>;
48
- static hooksKey: symbol;
49
- private static cache;
50
- main: <T extends MainListenerHookMethod<E, K>>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
51
- pre: <T extends MainListenerHookMethod<E, K>>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
52
- post: <T extends MainListenerHookMethod<E, K>>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
53
- error: <T extends ErrorListenerHookMethod<E, K>>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
54
33
  constructor(options: ListenerEntryOptions<E, K>);
55
- static getHooks<E extends EventsLike, K extends EventKey<E>>(constructor: ListenerConstructor): readonly ListenerHook<E, K>[];
56
- static getHooks<E extends EventsLike, K extends EventKey<E>>(constructor: ListenerConstructor, init: true): ListenerHook<E, K>[];
57
- private static createMainHookDecorator;
58
- private static createErrorHookDecorator;
59
- private static addHook;
60
34
  }
61
35
 
62
- type ListenerConstructor = new (...args: unknown[]) => object;
63
- type CreateListenerOptions<E extends EventsLike, K extends EventKey<E>> = SetOptional<ListenerEntryOptions<E, K>, "once"> | K;
64
- declare function ListenerFactory<E extends EventsLike = ClientEvents, K extends EventKey<E> = EventKey<E>>(options: CreateListenerOptions<E, K>): ListenerEntry<E, K>;
65
- declare function use(listener: ListenerEntry<never, never>): (target: ListenerConstructor) => void;
66
- declare function getEntry(constructor: ListenerConstructor): ListenerEntry<never, never> | undefined;
67
- declare const Listener: typeof ListenerFactory & {
68
- use: typeof use;
69
- getEntry: typeof getEntry;
70
- };
36
+ declare namespace ListenerAPI {
37
+ const ENTRY_KEY: unique symbol;
38
+ function use<E extends EventsLike, K extends keyof E>(entry: ListenerEntry<E, K>): (target: ConstructorLike) => void;
39
+ function getEntry<E extends EventsLike, K extends keyof E>(target: ConstructorLike): ListenerEntry<E, K> | undefined;
40
+ }
41
+ declare function ListenerFactory<E extends EventsLike = ClientEvents, K extends keyof E = keyof E>(options: SetOptional<ListenerEntryOptions<E, K>, "once"> | K): ListenerEntry<E, K>;
42
+ declare const Listener: typeof ListenerFactory & typeof ListenerAPI;
43
+
44
+ /**
45
+ * The global listener registry of Bakit.
46
+ */
47
+ declare abstract class ListenerRegistry {
48
+ private static client;
49
+ static constructors: Set<ConstructorLike>;
50
+ static instances: WeakMap<ConstructorLike, object>;
51
+ static executors: WeakMap<object, (...args: unknown[]) => Promise<void>>;
52
+ /**
53
+ * Add and register a listener to the registry.
54
+ * If `options.emitter` is not provided, the registry will use the base `client` by default.
55
+ * @param constructor The listener class you want to add.
56
+ */
57
+ static add(constructor: ConstructorLike): void;
58
+ /**
59
+ * Remove and unregister a listener from the registry.
60
+ * @param constructor The listener class you want to remove.
61
+ * @returns `boolean`, returns `true` if the listener is removed successfully.
62
+ */
63
+ static remove(constructor: ConstructorLike): boolean;
64
+ /**
65
+ * Remove and unregister all listeners from the registry.
66
+ * @returns Amount of removed listeners.
67
+ */
68
+ static removeAll(): number;
69
+ /**
70
+ * Set base client for the registry to fallback as default emitter. This should be used only by BakitClient and stay untouched.
71
+ * @param newClient base client to set for the registry.
72
+ */
73
+ protected static setClient(newClient: BakitClient): void;
74
+ private static createExecutor;
75
+ /**
76
+ * Load and add all listeners which matched provided glob pattern to the registry.
77
+ * @param pattern glob pattern to load.
78
+ * @param parallel load all matched results in parallel, enabled by default.
79
+ * @returns All loaded listener constructors.
80
+ */
81
+ static load(pattern: string, parallel?: boolean): Promise<ConstructorLike[]>;
82
+ }
83
+
84
+ /**
85
+ * This file is used to redeclare original client to the custom one
86
+ * Most of the structure is from Base, but some might be not
87
+ */
71
88
 
72
- declare function add(constructor: ListenerConstructor): void;
73
- declare function remove(constructor: ListenerConstructor): void;
74
- declare function removeAll(): void;
75
- declare function setClient(newClient: BakitClient): void;
76
- declare const ListenerRegistry: {
77
- constructors: Set<ListenerConstructor>;
78
- instances: WeakMap<ListenerConstructor, object>;
79
- add: typeof add;
80
- setClient: typeof setClient;
81
- remove: typeof remove;
82
- removeAll: typeof removeAll;
83
- };
84
89
 
85
- export { BakitClient, type CreateListenerOptions, type ErrorListenerHook, type ErrorListenerHookMethod, type EventKey, type EventsLike, Listener, type ListenerConstructor, ListenerEntry, type ListenerEntryOptions, ListenerFactory, type ListenerHook, ListenerHookExecutionState, ListenerRegistry, type MainListenerHook, type MainListenerHookMethod, StateBox, type States, extractId };
90
+ declare module "discord.js" {
91
+ interface Base {
92
+ client: BakitClient<true>;
93
+ }
94
+ }
95
+
96
+ export { BakitClient, type ErrorListenerHookMethod, type EventsLike, Listener, ListenerAPI, ListenerEntry, type ListenerEntryOptions, ListenerFactory, type ListenerHook, ListenerRegistry, type MainListenerHookMethod, StateBox, type States, extractId };