bakit 1.0.0-beta.3 → 1.0.0-beta.4

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.
@@ -201,4 +201,4 @@ declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready>
201
201
  private createHookRecord;
202
202
  }
203
203
 
204
- export { Arg as A, type BakitClientOptions as B, CommandHookExecutionState as C, CommandSyntaxErrorType as D, type CommandSyntaxErrorOptions as E, CommandSyntaxError as F, type GetSyntaxErrorMessageFunction as G, HOOKS_KEY as H, type IntegerArgumentOptions as I, type MemberArgumentOptions as M, type NumberArgumentOptions as N, RootCommandEntry as R, type StringArgumentOptions as S, type UserArgumentOptions as U, BakitClient as a, ArgumentType as b, type BaseArgumentOptions as c, type ArgumentOptions as d, type CommandHookMethod as e, type CommandHook as f, type BaseCommandEntryOptions as g, type CreateCommandOptions as h, BaseCommandEntry as i, BaseCommandGroupEntry as j, CommandGroupEntry as k, SubcommandEntry as l, type CommandEntry as m, type CommandConstructor as n, getRoot as o, CommandFactory as p, Command as q, CommandRegistry as r, type ChatInputContextSendOptions as s, type MessageContextSendOptions as t, use as u, type ContextSendOptions as v, BaseContext as w, ChatInputContext as x, MessageContext as y, type Context as z };
204
+ export { Arg as A, BakitClient as B, CommandHookExecutionState as C, CommandSyntaxError as D, type GetSyntaxErrorMessageFunction as G, HOOKS_KEY as H, type IntegerArgumentOptions as I, type MemberArgumentOptions as M, type NumberArgumentOptions as N, RootCommandEntry as R, type StringArgumentOptions as S, type UserArgumentOptions as U, type BakitClientOptions as a, ArgumentType as b, type BaseArgumentOptions as c, type ArgumentOptions as d, type CommandHookMethod as e, type CommandHook as f, type BaseCommandEntryOptions as g, type CreateCommandOptions as h, BaseCommandEntry as i, BaseCommandGroupEntry as j, CommandGroupEntry as k, SubcommandEntry as l, type CommandEntry as m, type CommandConstructor as n, CommandFactory as o, Command as p, CommandRegistry as q, type ChatInputContextSendOptions as r, type MessageContextSendOptions as s, type ContextSendOptions as t, BaseContext as u, ChatInputContext as v, MessageContext as w, type Context as x, CommandSyntaxErrorType as y, type CommandSyntaxErrorOptions as z };
@@ -1,3 +1,3 @@
1
- export { A as Arg, d as ArgumentOptions, b as ArgumentType, c as BaseArgumentOptions, i as BaseCommandEntry, g as BaseCommandEntryOptions, j as BaseCommandGroupEntry, w as BaseContext, x as ChatInputContext, s as ChatInputContextSendOptions, q as Command, n as CommandConstructor, m as CommandEntry, p as CommandFactory, k as CommandGroupEntry, f as CommandHook, C as CommandHookExecutionState, e as CommandHookMethod, r as CommandRegistry, z as Context, v as ContextSendOptions, h as CreateCommandOptions, H as HOOKS_KEY, I as IntegerArgumentOptions, M as MemberArgumentOptions, y as MessageContext, t as MessageContextSendOptions, N as NumberArgumentOptions, R as RootCommandEntry, S as StringArgumentOptions, l as SubcommandEntry, U as UserArgumentOptions, o as getRoot, u as use } from '../BakitClient-BWs93qO-.js';
1
+ export { A as Arg, d as ArgumentOptions, b as ArgumentType, 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, x as Context, t as ContextSendOptions, h as CreateCommandOptions, 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';
2
2
  import 'discord.js';
3
3
  import 'type-fest';
@@ -472,7 +472,5 @@ export {
472
472
  HOOKS_KEY,
473
473
  MessageContext,
474
474
  RootCommandEntry,
475
- SubcommandEntry,
476
- getRoot,
477
- use
475
+ SubcommandEntry
478
476
  };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- export { A as Arg, d as ArgumentOptions, b as ArgumentType, a as BakitClient, B as BakitClientOptions, c as BaseArgumentOptions, i as BaseCommandEntry, g as BaseCommandEntryOptions, j as BaseCommandGroupEntry, w as BaseContext, x as ChatInputContext, s as ChatInputContextSendOptions, q as Command, n as CommandConstructor, m as CommandEntry, p as CommandFactory, k as CommandGroupEntry, f as CommandHook, C as CommandHookExecutionState, e as CommandHookMethod, r as CommandRegistry, F as CommandSyntaxError, E as CommandSyntaxErrorOptions, D as CommandSyntaxErrorType, z as Context, v as ContextSendOptions, h as CreateCommandOptions, G as GetSyntaxErrorMessageFunction, H as HOOKS_KEY, I as IntegerArgumentOptions, M as MemberArgumentOptions, y as MessageContext, t as MessageContextSendOptions, N as NumberArgumentOptions, R as RootCommandEntry, S as StringArgumentOptions, l as SubcommandEntry, U as UserArgumentOptions, o as getRoot, u as use } from './BakitClient-BWs93qO-.js';
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';
2
3
  import { AsyncLocalStorage } from 'node:async_hooks';
3
- import 'discord.js';
4
- import 'type-fest';
4
+ import { SetOptional } from 'type-fest';
5
+ import { Awaitable, ClientEvents } from 'discord.js';
6
+ import EventEmitter from 'node:events';
5
7
 
6
8
  declare function extractId(value: string): string | null;
7
9
 
@@ -15,4 +17,69 @@ declare class StateBox {
15
17
  static use<T extends object>(defaultValue?: unknown): (target: T, key: keyof T) => void;
16
18
  }
17
19
 
18
- export { StateBox, type States, extractId };
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>;
34
+ }
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>> {
42
+ name: K;
43
+ once: boolean;
44
+ emitter?: EventEmitter;
45
+ }
46
+ declare class ListenerEntry<E extends EventsLike, K extends EventKey<E>> {
47
+ 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
+ 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
+ }
61
+
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
+ };
71
+
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
+
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 };
package/dist/index.js CHANGED
@@ -813,22 +813,29 @@ var StateBox = class _StateBox {
813
813
  };
814
814
 
815
815
  // src/listener/ListenerEntry.ts
816
- var HOOKS_KEY2 = Symbol("hooks");
816
+ var ListenerHookExecutionState = /* @__PURE__ */ ((ListenerHookExecutionState2) => {
817
+ ListenerHookExecutionState2["Main"] = "main";
818
+ ListenerHookExecutionState2["Pre"] = "pre";
819
+ ListenerHookExecutionState2["Post"] = "post";
820
+ ListenerHookExecutionState2["Error"] = "error";
821
+ return ListenerHookExecutionState2;
822
+ })(ListenerHookExecutionState || {});
817
823
  var ListenerEntry = class _ListenerEntry {
818
824
  constructor(options) {
819
825
  this.options = options;
820
826
  }
827
+ static hooksKey = Symbol("hooks");
821
828
  static cache = /* @__PURE__ */ new WeakMap();
822
829
  main = _ListenerEntry.createMainHookDecorator("main" /* Main */, this);
823
830
  pre = _ListenerEntry.createMainHookDecorator("pre" /* Pre */, this);
824
831
  post = _ListenerEntry.createMainHookDecorator("post" /* Post */, this);
825
832
  error = _ListenerEntry.createErrorHookDecorator("error" /* Error */, this);
826
833
  static getHooks(constructor, init = false) {
827
- let hooks = this.cache.get(constructor) ?? Reflect.getMetadata(HOOKS_KEY2, constructor);
834
+ let hooks = this.cache.get(constructor) ?? Reflect.getMetadata(this.hooksKey, constructor);
828
835
  if (!hooks) {
829
836
  hooks = [];
830
837
  if (init) {
831
- Reflect.defineMetadata(HOOKS_KEY2, hooks, constructor);
838
+ Reflect.defineMetadata(this.hooksKey, hooks, constructor);
832
839
  this.cache.set(constructor, hooks);
833
840
  }
834
841
  }
@@ -1152,11 +1159,14 @@ export {
1152
1159
  CommandSyntaxError,
1153
1160
  CommandSyntaxErrorType,
1154
1161
  HOOKS_KEY,
1162
+ Listener,
1163
+ ListenerEntry,
1164
+ ListenerFactory,
1165
+ ListenerHookExecutionState,
1166
+ ListenerRegistry,
1155
1167
  MessageContext,
1156
1168
  RootCommandEntry,
1157
1169
  StateBox,
1158
1170
  SubcommandEntry,
1159
- extractId,
1160
- getRoot,
1161
- use
1171
+ extractId
1162
1172
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bakit",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.4",
4
4
  "description": "A framework for discord.js",
5
5
  "type": "module",
6
6
  "exports": {