@kyvrixon/utils 1.0.10 → 1.0.11

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/README.md CHANGED
@@ -4,6 +4,4 @@ General utility files I use for alot of projects! Designed for use with the [bun
4
4
 
5
5
  ```bash
6
6
  bun install @kyvrixon/utils
7
- # or
8
- bun install github:kyvrixon/utils#1.0.10
9
- ```
7
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kyvrixon/utils",
3
3
  "main": "./src/index.ts",
4
- "version": "1.0.10",
4
+ "version": "1.0.11",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "license": "MIT",
@@ -9,20 +9,20 @@
9
9
  "src"
10
10
  ],
11
11
  "engines": {
12
- "bun": "1.3.10"
12
+ "bun": "1.3.11"
13
13
  },
14
14
  "repository": {
15
15
  "url": "https://github.com/kyvrixon/utils"
16
16
  },
17
17
  "scripts": {
18
- "pub": "bun prebuild.ts && bun publish --access public",
18
+ "pub": "bun publish --access public",
19
19
  "pretty": "bun biome format --write ."
20
20
  },
21
21
  "packageManager": "bun@1.3.10",
22
22
  "types": "./src/index.ts",
23
23
  "devDependencies": {
24
24
  "@biomejs/biome": "2.4.6",
25
- "@types/bun": "1.3.10",
25
+ "@types/bun": "1.3.11",
26
26
  "typescript": "5.9.3"
27
27
  },
28
28
  "dependencies": {
package/src/index.ts CHANGED
@@ -3,4 +3,4 @@ export * from "./lib/toOrdinal";
3
3
  export * from "./lib/discord-utils/Command";
4
4
  export * from "./lib/discord-utils/createPagination";
5
5
  export * from "./lib/discord-utils/Event";
6
- export * from "./lib/modules/LoggerModule";
6
+ export * from "./lib/modules/LoggerModule";
@@ -3,59 +3,53 @@ import type { Client, ClientEvents, RestEvents } from "discord.js";
3
3
 
4
4
  // biome-ignore lint/suspicious/noEmptyInterface: Its fine
5
5
  export interface DiscordEventCustomType {}
6
+
7
+ /** Maps an event type discriminant to its corresponding event map. */
8
+ type EventMap<T extends "client" | "rest" | "custom"> = T extends "client"
9
+ ? ClientEvents
10
+ : T extends "rest"
11
+ ? RestEvents
12
+ : keyof DiscordEventCustomType extends never
13
+ ? { "sooo.. there's no custom events..": [] }
14
+ : DiscordEventCustomType;
15
+
16
+ /** Resolves the argument tuple for a given event type + key pair. */
17
+ type EventArgs<
18
+ T extends "client" | "rest" | "custom",
19
+ K extends keyof EventMap<T>,
20
+ > = Extract<EventMap<T>[K], any[]>;
21
+
6
22
  /**
7
23
  * To define custom types:
8
24
  * @example
9
25
  * declare module "@kyvrixon/utils" {
10
- * interface DiscordEventCustomType {
11
- * myEventName: [data: string];
12
- * }
13
- * }
14
- * // You can also add these to `ClientEvents` if you wish for better typing like so:
15
- * declare module "discord.js" {
16
- * interface ClientEvents extends DiscordEventCustomType {}
26
+ * interface DiscordEventCustomType {
27
+ * myEventName: [data: string];
28
+ * }
17
29
  * }
18
30
  */
19
31
  export class DiscordEvent<
20
32
  V extends Client,
21
- T extends "client" | "custom" | "rest" = "client",
22
- K extends T extends "custom"
23
- ? keyof DiscordEventCustomType
24
- : T extends "client"
25
- ? keyof ClientEvents
26
- : keyof RestEvents = T extends "custom"
27
- ? keyof DiscordEventCustomType
28
- : T extends "client"
29
- ? keyof ClientEvents
30
- : keyof RestEvents,
33
+ T extends "client" | "rest" | "custom",
34
+ K extends keyof EventMap<T> = keyof EventMap<T>,
31
35
  > {
32
36
  public readonly type: T;
33
37
  public readonly name: K;
34
38
  public readonly once: boolean;
35
39
  public readonly method: (
36
40
  client: V,
37
- ...args: T extends "client"
38
- ? K extends keyof ClientEvents
39
- ? ClientEvents[K]
40
- : any[]
41
- : T extends "rest"
42
- ? K extends keyof RestEvents
43
- ? RestEvents[K]
44
- : any[]
45
- : K extends keyof DiscordEventCustomType
46
- ? DiscordEventCustomType[K]
47
- : any[]
48
- ) => Promise<void>;
41
+ ...args: EventArgs<T, K>
42
+ ) => void | Promise<void>;
49
43
 
50
44
  constructor(opts: {
51
45
  type: T;
52
46
  name: K;
53
- once?: boolean;
47
+ once: boolean;
54
48
  method: DiscordEvent<V, T, K>["method"];
55
49
  }) {
56
50
  this.type = opts.type;
57
51
  this.name = opts.name;
58
- this.once = opts.once ?? false;
52
+ this.once = opts.once;
59
53
  this.method = opts.method;
60
54
  }
61
55
  }
@@ -324,4 +324,4 @@ export async function createPagination(
324
324
  ended = true;
325
325
  await render();
326
326
  });
327
- }
327
+ }