lunibee 0.2.3 → 0.3.0

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.
Files changed (86) hide show
  1. package/README.md +3 -3
  2. package/dist/builders/attachment.d.ts +8 -4
  3. package/dist/builders/commands.d.ts +122 -149
  4. package/dist/builders/components.d.ts +10 -150
  5. package/dist/builders/embed.d.ts +66 -37
  6. package/dist/builders/index.d.ts +0 -4
  7. package/dist/builders/index.js +112 -221
  8. package/dist/builders/index.js.map +10 -9
  9. package/dist/collection/cache.d.ts +15 -6
  10. package/dist/collection/index.d.ts +92 -17
  11. package/dist/collection/index.js +471 -279
  12. package/dist/collection/index.js.map +4 -4
  13. package/dist/core/api.d.ts +130 -0
  14. package/dist/core/channel-create.d.ts +72 -0
  15. package/dist/core/commands.d.ts +232 -0
  16. package/dist/core/events.d.ts +24 -7
  17. package/dist/core/handles.d.ts +157 -0
  18. package/dist/core/index.d.ts +68 -4
  19. package/dist/core/index.js +2639 -493
  20. package/dist/core/index.js.map +47 -37
  21. package/dist/core/permissions.d.ts +7 -7
  22. package/dist/formatters/index.js +9 -5
  23. package/dist/formatters/index.js.map +3 -3
  24. package/dist/handlers/index.js +5 -10
  25. package/dist/handlers/index.js.map +3 -3
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.js +9527 -7809
  28. package/dist/index.js.map +63 -53
  29. package/dist/managers/advanced.d.ts +29 -1
  30. package/dist/managers/base.d.ts +22 -14
  31. package/dist/managers/emoji.d.ts +0 -2
  32. package/dist/managers/guild-resources.d.ts +13 -5
  33. package/dist/managers/guild.d.ts +40 -4
  34. package/dist/managers/index.d.ts +21 -13
  35. package/dist/managers/index.js +969 -386
  36. package/dist/managers/index.js.map +30 -25
  37. package/dist/managers/member.d.ts +9 -2
  38. package/dist/managers/message.d.ts +10 -15
  39. package/dist/managers/role.d.ts +18 -10
  40. package/dist/managers/thread.d.ts +68 -0
  41. package/dist/managers/user.d.ts +18 -0
  42. package/dist/rest/errors.d.ts +14 -7
  43. package/dist/rest/index.d.ts +24 -12
  44. package/dist/rest/index.js +70 -20
  45. package/dist/rest/index.js.map +9 -9
  46. package/dist/rest/redis.d.ts +1 -1
  47. package/dist/rest/route.d.ts +8 -4
  48. package/dist/rest/routes.d.ts +122 -48
  49. package/dist/rest/transport.d.ts +10 -5
  50. package/dist/rest/webhook.d.ts +9 -5
  51. package/dist/sharding/bus.d.ts +47 -19
  52. package/dist/sharding/cluster.d.ts +11 -0
  53. package/dist/sharding/gateway-bot.d.ts +18 -0
  54. package/dist/sharding/index.d.ts +64 -25
  55. package/dist/sharding/index.js +439 -124
  56. package/dist/sharding/index.js.map +19 -14
  57. package/dist/sharding/supervisor.d.ts +32 -0
  58. package/dist/sharding/transport.d.ts +45 -0
  59. package/dist/structures/audit-log.d.ts +99 -2
  60. package/dist/structures/base.d.ts +40 -23
  61. package/dist/structures/channels.d.ts +45 -14
  62. package/dist/structures/index.d.ts +8 -12
  63. package/dist/structures/index.js +280 -132
  64. package/dist/structures/index.js.map +21 -15
  65. package/dist/structures/interactions.d.ts +91 -63
  66. package/dist/structures/resources.d.ts +99 -52
  67. package/dist/structures/sticker.d.ts +33 -0
  68. package/dist/types/channel-kind.d.ts +26 -0
  69. package/dist/types/gateway.d.ts +24 -12
  70. package/dist/types/index.d.ts +115 -113
  71. package/dist/types/index.js +53 -48
  72. package/dist/types/index.js.map +6 -5
  73. package/dist/voice/index.d.ts +12 -4
  74. package/dist/voice/index.js +14 -18
  75. package/dist/voice/index.js.map +3 -3
  76. package/dist/ws/decoder.d.ts +6 -2
  77. package/dist/ws/dispatcher.d.ts +19 -0
  78. package/dist/ws/index.d.ts +61 -15
  79. package/dist/ws/index.js +194 -77
  80. package/dist/ws/index.js.map +13 -11
  81. package/dist/ws/protocol.d.ts +10 -2
  82. package/dist/ws/reconnect.d.ts +10 -0
  83. package/dist/ws/send-budget.d.ts +6 -2
  84. package/dist/ws/session.d.ts +14 -4
  85. package/dist/ws/state.d.ts +22 -11
  86. package/package.json +20 -16
@@ -91,7 +91,7 @@ export interface IdentifyProperties {
91
91
  os?: string;
92
92
  browser?: string;
93
93
  device?: string;
94
- [key: string]: unknown;
94
+ [key: string]: string | undefined;
95
95
  }
96
96
  /** Everything IDENTIFY needs. */
97
97
  export interface IdentifyOptions {
@@ -102,8 +102,16 @@ export interface IdentifyOptions {
102
102
  properties?: IdentifyProperties;
103
103
  presence?: GatewayPresence;
104
104
  }
105
+ /** The `d` field of an IDENTIFY payload. */
106
+ export interface IdentifyData {
107
+ token: string;
108
+ intents: number;
109
+ properties: IdentifyProperties;
110
+ presence: Required<GatewayPresence>;
111
+ shard: [shardId: number, shardCount: number];
112
+ }
105
113
  /** Builds an IDENTIFY payload. */
106
- export declare function identifyPayload(options: IdentifyOptions): GatewayPayload;
114
+ export declare function identifyPayload(options: IdentifyOptions): GatewayPayload<IdentifyData>;
107
115
  /** Builds a RESUME payload from the session's resume material. */
108
116
  export declare function resumePayload(token: string, resume: ResumeInfo): GatewayPayload;
109
117
  /** Builds a heartbeat payload carrying the last sequence seen. */
@@ -44,6 +44,10 @@ export type ScheduleResult = {
44
44
  scheduled: true;
45
45
  delayMs: number;
46
46
  attempt: number;
47
+ /** Set when reconnects are coming too fast: the delay was raised. */
48
+ unstable?: {
49
+ reconnects: number;
50
+ };
47
51
  } | {
48
52
  scheduled: false;
49
53
  reason: ScheduleRefusal;
@@ -60,6 +64,12 @@ export interface ReconnectOptions {
60
64
  maxDelay: number;
61
65
  /** Randomness source for jitter; injected in tests. */
62
66
  random?: () => number;
67
+ /** Reconnects inside `stormWindow` before the link counts as unstable (default 5). */
68
+ stormLimit?: number;
69
+ /** The span over which reconnects are counted, in ms (default 60,000). */
70
+ stormWindow?: number;
71
+ /** Clock in ms; injected in tests. */
72
+ now?: () => number;
63
73
  }
64
74
  /** Reconnect scheduling, backoff and attempt coordination. */
65
75
  export declare class GatewayReconnect {
@@ -1,11 +1,13 @@
1
1
  /**
2
- * Sliding-window budget for outgoing Gateway payloads.
2
+ * Sliding-window budget for outgoing Gateway payloads. Heartbeats, IDENTIFY and
3
+ * RESUME are privileged: they always go out (and are still counted), so
4
+ * application traffic can never starve them.
3
5
  *
4
6
  * Discord allows 120 sends per 60 seconds. Application traffic is capped at
5
7
  * 115 so the remaining headroom is reserved for privileged sends (heartbeats),
6
8
  * which are still recorded so the true total stays under Discord's limit.
7
9
  */
8
- export declare class SendBudget {
10
+ export declare class GatewaySendLimiter {
9
11
  #private;
10
12
  constructor(limit?: number, windowMs?: number);
11
13
  /** Sends recorded within the current window. */
@@ -15,3 +17,5 @@ export declare class SendBudget {
15
17
  /** Records a send that went out. */
16
18
  record(now?: number): void;
17
19
  }
20
+ /** The limiter's name before 0.3.0. */
21
+ export declare const SendBudget: typeof GatewaySendLimiter;
@@ -9,9 +9,12 @@
9
9
  */
10
10
  /** Everything needed to send a RESUME, or nothing when one is impossible. */
11
11
  export interface ResumeInfo {
12
- /** Discord's session identifier from READY. */ sessionId: string;
13
- /** Last sequence number observed on this session. */ sequence: number;
14
- /** Host READY nominated for resuming this session. */ resumeURL: string;
12
+ /** Discord's session identifier from READY. */
13
+ sessionId: string;
14
+ /** Last sequence number observed on this session. */
15
+ sequence: number;
16
+ /** Host READY nominated for resuming this session. */
17
+ resumeURL: string;
15
18
  }
16
19
  /**
17
20
  * What the next connection must do.
@@ -95,6 +98,13 @@ export declare class GatewaySession {
95
98
  resumeInfo(): ResumeInfo | undefined;
96
99
  /** What the next connection must send: RESUME with material, or IDENTIFY. */
97
100
  handshake(): HandshakeIntent;
98
- /** Host the next connection should dial: the resume host, else `fallback`. */
101
+ /**
102
+ * Host the next connection should dial: the resume host, else `fallback`.
103
+ * The resume host comes from READY, so it is used only when it is a `wss:`
104
+ * URL on discord.gg (or a subdomain), or on the fallback's own host; any
105
+ * other host would receive the bot token in the RESUME frame.
106
+ */
99
107
  connectURL(fallback: string): string;
100
108
  }
109
+ /** Whether `url` is a `wss:` URL on discord.gg (or a subdomain) or on `fallback`'s host. */
110
+ export declare function isTrustedGatewayURL(url: string, fallback: string): boolean;
@@ -1,14 +1,23 @@
1
1
  /** Gateway connection lifecycle states. */
2
2
  export declare enum GatewayState {
3
- /** Initial connection state. */ Connect = "CONNECT",
4
- /** Gateway HELLO received state. */ Hello = "HELLO",
5
- /** IDENTIFY operation in progress. */ Identify = "IDENTIFY",
6
- /** RESUME operation in progress. */ Resume = "RESUME",
7
- /** Gateway READY state. */ Ready = "READY",
8
- /** Gateway dispatch processing state. */ Dispatch = "DISPATCH",
9
- /** Heartbeat processing state. */ Heartbeat = "HEARTBEAT",
10
- /** Reconnect in progress. */ Reconnect = "RECONNECT",
11
- /** Gateway is permanently closed. */ Closed = "CLOSED"
3
+ /** Initial connection state. */
4
+ Connect = "CONNECT",
5
+ /** Gateway HELLO received state. */
6
+ Hello = "HELLO",
7
+ /** IDENTIFY operation in progress. */
8
+ Identify = "IDENTIFY",
9
+ /** RESUME operation in progress. */
10
+ Resume = "RESUME",
11
+ /** Gateway READY state. */
12
+ Ready = "READY",
13
+ /** Gateway dispatch processing state. */
14
+ Dispatch = "DISPATCH",
15
+ /** Heartbeat processing state. */
16
+ Heartbeat = "HEARTBEAT",
17
+ /** Reconnect in progress. */
18
+ Reconnect = "RECONNECT",
19
+ /** Gateway is permanently closed. */
20
+ Closed = "CLOSED"
12
21
  }
13
22
  /**
14
23
  * Discord.js-familiar alias for {@link GatewayState}.
@@ -22,6 +31,8 @@ export declare enum GatewayState {
22
31
  export { GatewayState as Status };
23
32
  /** Gateway protocol error. */
24
33
  export declare class GatewayError extends Error {
25
- /** Gateway close/error code. */ readonly code?: number;
26
- /** Creates a Gateway error. @param message Error message. @param code Optional Gateway code. @param options Optional error metadata. */ constructor(message: string, code?: number, options?: ErrorOptions);
34
+ /** Gateway close/error code. */
35
+ readonly code?: number;
36
+ /** Creates a Gateway error. @param message Error message. @param code Optional Gateway code. @param options Optional error metadata. */
37
+ constructor(message: string, code?: number, options?: ErrorOptions);
27
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lunibee",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "A lightweight, Bun-first Discord API library.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -92,38 +92,42 @@
92
92
  "format:check": "prettier --check \"packages/*/src/**/*.ts\" \"tests/**/*.ts\"",
93
93
  "check:deps": "bun scripts/check-dependency-graph.ts",
94
94
  "audit:api": "bun scripts/api-audit.ts",
95
+ "audit:coverage": "bun scripts/api-coverage.ts --check",
95
96
  "typecheck": "bunx tsc --noEmit --project tsconfig.json && bunx tsc --noEmit --project tsconfig.strict.json",
96
97
  "ci:install": "bun install --frozen-lockfile",
97
98
  "ci:deps": "bun run check:deps",
98
99
  "ci:typecheck": "bun run typecheck",
99
100
  "ci:test": "bun test --coverage && bun test ./packages/testing/src",
100
- "ci": "bun run ci:deps && bun run audit:api && bun run format:check && bun run ci:typecheck && bun run ci:test",
101
+ "ci": "bun run ci:deps && bun run audit:api && bun run audit:coverage && bun run format:check && bun run ci:typecheck && bun run ci:test",
101
102
  "bench": "bun benchmarks/parity.ts",
103
+ "bench:rest": "bun benchmarks/rest-buckets.ts",
104
+ "bench:compare": "bun scripts/bench-compare.mjs",
102
105
  "build:all": "bun run build && bun run build:dts",
103
106
  "publish:all": "bun run scripts/publish.ts"
104
107
  },
105
108
  "dependencies": {
106
- "@lunibee/builders": "^0.2.3",
107
- "@lunibee/collection": "^0.2.3",
108
- "@lunibee/core": "^0.2.3",
109
- "@lunibee/formatters": "^0.2.3",
110
- "@lunibee/handlers": "^0.2.3",
111
- "@lunibee/managers": "^0.2.3",
112
- "@lunibee/rest": "^0.2.3",
113
- "@lunibee/sharding": "^0.2.3",
114
- "@lunibee/structures": "^0.2.3",
115
- "@lunibee/types": "^0.2.3",
116
- "@lunibee/utils": "^0.2.3",
117
- "@lunibee/voice": "^0.2.3",
118
- "@lunibee/ws": "^0.2.3"
109
+ "@lunibee/builders": "^0.3.0",
110
+ "@lunibee/collection": "^0.3.0",
111
+ "@lunibee/core": "^0.3.0",
112
+ "@lunibee/formatters": "^0.3.0",
113
+ "@lunibee/handlers": "^0.3.0",
114
+ "@lunibee/managers": "^0.3.0",
115
+ "@lunibee/rest": "^0.3.0",
116
+ "@lunibee/sharding": "^0.3.0",
117
+ "@lunibee/structures": "^0.3.0",
118
+ "@lunibee/types": "^0.3.0",
119
+ "@lunibee/utils": "^0.3.0",
120
+ "@lunibee/voice": "^0.3.0",
121
+ "@lunibee/ws": "^0.3.0"
119
122
  },
120
123
  "devDependencies": {
124
+ "@discordjs/collection": "^2.1.1",
121
125
  "@types/bun": "^1.4.1",
122
126
  "prettier": "^3.9.9",
123
127
  "typescript": "^7.0.2"
124
128
  },
125
129
  "engines": {
126
- "bun": ">=1.2.0"
130
+ "bun": ">=1.4.0"
127
131
  },
128
132
  "license": "MIT"
129
133
  }