lunibee 0.1.7 → 0.1.8

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 (71) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +223 -223
  3. package/dist/builders/commands.d.ts +6 -4
  4. package/dist/builders/components.d.ts +18 -0
  5. package/dist/builders/index.d.ts +2 -2
  6. package/dist/builders/index.js +49 -13
  7. package/dist/builders/index.js.map +9 -8
  8. package/dist/collection/index.js +2 -1
  9. package/dist/collection/index.js.map +4 -4
  10. package/dist/core/events.d.ts +86 -2
  11. package/dist/core/index.d.ts +10 -87
  12. package/dist/core/index.js +1752 -725
  13. package/dist/core/index.js.map +44 -24
  14. package/dist/formatters/index.js.map +1 -1
  15. package/dist/handlers/index.js.map +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +2103 -800
  18. package/dist/index.js.map +63 -43
  19. package/dist/managers/guild-resources.d.ts +109 -0
  20. package/dist/managers/guild.d.ts +5 -0
  21. package/dist/managers/index.d.ts +7 -1
  22. package/dist/managers/index.js +330 -12
  23. package/dist/managers/index.js.map +25 -21
  24. package/dist/rest/decoder.d.ts +23 -0
  25. package/dist/rest/errors.d.ts +20 -0
  26. package/dist/rest/index.d.ts +21 -17
  27. package/dist/rest/index.js +479 -263
  28. package/dist/rest/index.js.map +14 -8
  29. package/dist/rest/limiter.d.ts +42 -0
  30. package/dist/rest/redis.d.ts +18 -1
  31. package/dist/rest/route.d.ts +31 -0
  32. package/dist/rest/routes.d.ts +2 -0
  33. package/dist/rest/scheduler.d.ts +42 -0
  34. package/dist/rest/store.d.ts +29 -0
  35. package/dist/rest/transport.d.ts +40 -0
  36. package/dist/sharding/bus.d.ts +31 -0
  37. package/dist/sharding/cluster.d.ts +10 -0
  38. package/dist/sharding/index.d.ts +10 -2
  39. package/dist/sharding/index.js +1011 -394
  40. package/dist/sharding/index.js.map +18 -8
  41. package/dist/structures/base.d.ts +8 -0
  42. package/dist/structures/channels.d.ts +56 -0
  43. package/dist/structures/index.d.ts +1 -0
  44. package/dist/structures/index.js +211 -271
  45. package/dist/structures/index.js.map +17 -14
  46. package/dist/structures/interactions.d.ts +12 -52
  47. package/dist/structures/options.d.ts +55 -0
  48. package/dist/structures/resources.d.ts +3 -3
  49. package/dist/types/gateway-events.d.ts +132 -0
  50. package/dist/types/gateway.d.ts +181 -0
  51. package/dist/types/index.d.ts +2 -263
  52. package/dist/types/index.js +44 -2
  53. package/dist/types/index.js.map +5 -4
  54. package/dist/utils/index.js.map +1 -1
  55. package/dist/voice/index.d.ts +29 -1
  56. package/dist/voice/index.js +59 -7
  57. package/dist/voice/index.js.map +3 -3
  58. package/dist/ws/close-codes.d.ts +23 -0
  59. package/dist/ws/decoder.d.ts +58 -0
  60. package/dist/ws/heartbeat.d.ts +87 -0
  61. package/dist/ws/index.d.ts +18 -65
  62. package/dist/ws/index.js +903 -385
  63. package/dist/ws/index.js.map +15 -5
  64. package/dist/ws/opcodes.d.ts +14 -0
  65. package/dist/ws/protocol.d.ts +110 -0
  66. package/dist/ws/reconnect.d.ts +108 -0
  67. package/dist/ws/send-budget.d.ts +17 -0
  68. package/dist/ws/session.d.ts +100 -0
  69. package/dist/ws/state.d.ts +27 -0
  70. package/dist/ws/transport.d.ts +80 -0
  71. package/package.json +21 -20
@@ -0,0 +1,23 @@
1
+ /** Normalised shape of a Discord error payload. */
2
+ export interface DecodedError {
3
+ message?: string;
4
+ code?: number;
5
+ retry_after?: number;
6
+ global?: boolean;
7
+ }
8
+ /** Turns a raw {@link Response} into a payload and the error metadata retries need. */
9
+ export declare class ResponseDecoder {
10
+ /** Reads a Discord response payload as JSON, text, or nothing for 204. */
11
+ read(response: Response): Promise<unknown>;
12
+ /** Extracts Discord's error metadata from a decoded payload. */
13
+ errorData(payload: unknown): DecodedError;
14
+ /**
15
+ * Resolves Retry-After (seconds) from the payload, falling back to the
16
+ * header and finally to one second.
17
+ *
18
+ * An absent header is explicitly *not* a zero delay: `Number(null)` is 0,
19
+ * which is finite, so reading it directly would answer a 429 that carries
20
+ * no Retry-After by retrying immediately — exactly when backing off matters.
21
+ */
22
+ retryAfter(response: Response, data: DecodedError): number;
23
+ }
@@ -0,0 +1,20 @@
1
+ /** Error thrown when Discord rejects a REST request. */
2
+ export declare class RESTError extends Error {
3
+ /** HTTP status returned by Discord. */ readonly status: number;
4
+ /** Discord API error code, when provided. */ readonly code?: number;
5
+ /** Raw Discord validation/error payload. */ readonly errors?: unknown;
6
+ /** HTTP method used for the failed request. */ readonly method?: string;
7
+ /** API path used for the failed request. */ readonly path?: string;
8
+ /** Creates a REST error with request context. @param message Error message. @param status HTTP status. @param code Discord error code. @param errors Raw error payload. @param options Request context and cause. */
9
+ constructor(message: string, status: number, code?: number, errors?: unknown, options?: {
10
+ method?: string;
11
+ path?: string;
12
+ cause?: unknown;
13
+ });
14
+ }
15
+ /** Creates the cancellation error shared by every stage of the request pipeline. */
16
+ export declare function abortError(path: string, reason: unknown): RESTError;
17
+ /** Waits for a delay, rejecting early if the signal aborts. */
18
+ export declare function sleep(delay: number, signal: AbortSignal | undefined, path: string): Promise<void>;
19
+ /** Awaits a promise, rejecting early if the signal aborts. */
20
+ export declare function abortable(promise: Promise<void>, signal: AbortSignal | undefined, path: string): Promise<void>;
@@ -1,26 +1,13 @@
1
- /** Error thrown when Discord rejects a REST request. */
2
- export declare class RESTError extends Error {
3
- /** HTTP status returned by Discord. */ readonly status: number;
4
- /** Discord API error code, when provided. */ readonly code?: number;
5
- /** Raw Discord validation/error payload. */ readonly errors?: unknown;
6
- /** HTTP method used for the failed request. */ readonly method?: string;
7
- /** API path used for the failed request. */ readonly path?: string;
8
- /** Creates a REST error with request context. @param message Error message. @param status HTTP status. @param code Discord error code. @param errors Raw error payload. @param options Request context and cause. */
9
- constructor(message: string, status: number, code?: number, errors?: unknown, options?: {
10
- method?: string;
11
- path?: string;
12
- cause?: unknown;
13
- });
14
- }
15
1
  import { type RateLimitStore } from "./store.js";
2
+ import { RESTError } from "./errors.js";
3
+ import { type RESTQuery } from "./route.js";
4
+ import { HttpTransport } from "./transport.js";
16
5
  /** A file attachment sent as part of a multipart REST request. */
17
6
  export interface RESTFileAttachment {
18
7
  name: string;
19
8
  data: Blob | Uint8Array | ArrayBuffer;
20
9
  contentType?: string;
21
10
  }
22
- /** Query-string value accepted by {@link RESTRequestOptions.query}. */
23
- export type RESTQuery = URLSearchParams | Record<string, string | number | boolean | null | undefined> | string;
24
11
  /**
25
12
  * Options controlling an individual REST request.
26
13
  *
@@ -112,7 +99,18 @@ export declare class REST {
112
99
  baseURL?: string;
113
100
  hooks?: RESTHooks;
114
101
  store?: RateLimitStore;
102
+ /** Replaces the HTTP stage, e.g. with a recording transport in tests. */
103
+ transport?: HttpTransport;
104
+ /**
105
+ * Lets requests on a bucket whose limit is known run concurrently, up
106
+ * to its `remaining` allowance, instead of one at a time. Requires a
107
+ * store with `reserve`. Requests on one bucket may then complete out
108
+ * of order (e.g. messages to one channel). Defaults to `false`.
109
+ */
110
+ concurrentBuckets?: boolean;
115
111
  });
112
+ /** The rate-limit store backing this transport. */
113
+ get store(): RateLimitStore;
116
114
  /** Replaces the current hook set. Pass an empty object to clear all hooks. */
117
115
  setHooks(hooks: RESTHooks): this;
118
116
  /** Sets the authentication token. @param token Discord bot token. @returns Nothing. @throws {TypeError} If token is empty. */
@@ -162,7 +160,13 @@ export declare class REST {
162
160
  patchWithFiles<T>(path: string, payload: unknown, files: RESTFileAttachment[], options?: RESTRequestOptions): Promise<T>;
163
161
  }
164
162
  export { Routes } from "./routes.js";
165
- export { type RateLimitStore, type BucketState, MemoryRateLimitStore, } from "./store.js";
163
+ export { RESTError, abortError } from "./errors.js";
164
+ export { createRouteKey, normalizeRoutePath, majorParameter, scopeBucket, serializeQuery, type RouteKey, type RESTQuery, } from "./route.js";
165
+ export { RequestScheduler } from "./scheduler.js";
166
+ export { RateLimiter } from "./limiter.js";
167
+ export { HttpTransport, TransportError, type TransportRequest, type FetchLike, } from "./transport.js";
168
+ export { ResponseDecoder, type DecodedError } from "./decoder.js";
169
+ export { type RateLimitStore, type BucketState, type Reservation, MemoryRateLimitStore, } from "./store.js";
166
170
  export { RedisRateLimitStore, type RedisRateLimitStoreOptions, type MinimalRedisClient, } from "./redis.js";
167
171
  export { WebhookClient, type WebhookClientOptions, type WebhookMessageOptions, } from "./webhook.js";
168
172
  /**