lunibee 0.1.5 → 0.1.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/README.md +13 -24
- package/dist/builders/commands.d.ts +37 -0
- package/dist/builders/components.d.ts +127 -12
- package/dist/builders/embed.d.ts +3 -1
- package/dist/builders/index.d.ts +2 -2
- package/dist/builders/index.js +319 -16
- package/dist/builders/index.js.map +8 -7
- package/dist/collection/index.d.ts +36 -0
- package/dist/collection/index.js +110 -6
- package/dist/collection/index.js.map +4 -4
- package/dist/core/events.d.ts +69 -3
- package/dist/core/index.d.ts +158 -90
- package/dist/core/index.js +1543 -1169
- package/dist/core/index.js.map +24 -23
- package/dist/core/permissions.d.ts +112 -53
- package/dist/formatters/index.d.ts +43 -3
- package/dist/formatters/index.js +64 -1
- package/dist/formatters/index.js.map +3 -3
- package/dist/handlers/index.js.map +2 -2
- package/dist/index.d.ts +5 -4
- package/dist/index.js +3882 -1588
- package/dist/index.js.map +43 -35
- package/dist/managers/emoji.d.ts +38 -0
- package/dist/managers/guild.d.ts +141 -0
- package/dist/managers/index.d.ts +86 -75
- package/dist/managers/index.js +1084 -67
- package/dist/managers/index.js.map +21 -16
- package/dist/managers/message.d.ts +7 -12
- package/dist/managers/user.d.ts +20 -0
- package/dist/rest/index.d.ts +173 -1
- package/dist/rest/index.js +343 -47
- package/dist/rest/index.js.map +8 -6
- package/dist/rest/redis.d.ts +37 -0
- package/dist/rest/routes.d.ts +26 -1
- package/dist/rest/store.d.ts +38 -0
- package/dist/rest/webhook.d.ts +2 -2
- package/dist/sharding/cluster.d.ts +61 -0
- package/dist/sharding/index.d.ts +8 -0
- package/dist/sharding/index.js +289 -18
- package/dist/sharding/index.js.map +8 -7
- package/dist/structures/audit-log.d.ts +26 -0
- package/dist/structures/base.d.ts +131 -48
- package/dist/structures/embed.d.ts +65 -0
- package/dist/structures/index.d.ts +74 -26
- package/dist/structures/index.js +1528 -59
- package/dist/structures/index.js.map +14 -8
- package/dist/structures/interactions.d.ts +72 -17
- package/dist/structures/resources.d.ts +199 -7
- package/dist/types/index.d.ts +605 -84
- package/dist/types/index.js +71 -1
- package/dist/types/index.js.map +3 -3
- package/dist/utils/index.js.map +2 -2
- package/dist/voice/index.d.ts +88 -0
- package/dist/voice/index.js +204 -5
- package/dist/voice/index.js.map +3 -3
- package/dist/ws/index.d.ts +40 -1
- package/dist/ws/index.js +105 -18
- package/dist/ws/index.js.map +4 -4
- package/package.json +16 -16
- package/dist/structures/permissions.d.ts +0 -73
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import { Collection } from "@lunibee/collection";
|
|
2
2
|
import { REST } from "@lunibee/rest";
|
|
3
3
|
import { Message, type ResourceContext } from "@lunibee/structures";
|
|
4
|
-
|
|
4
|
+
export type MessageCreateOptions = Record<string, unknown> & {
|
|
5
|
+
content?: string;
|
|
6
|
+
};
|
|
7
|
+
export type MessageEditOptions = Record<string, unknown> & {
|
|
8
|
+
content?: string;
|
|
9
|
+
};
|
|
5
10
|
export declare class MessageManager {
|
|
6
11
|
#private;
|
|
7
|
-
/** Canonical message cache for this channel. */
|
|
8
12
|
readonly cache: Collection<string, Message>;
|
|
9
|
-
/** Creates a message manager. @param rest REST transport. @param context Structure resource context. @param channelId Channel identifier. @throws {TypeError} If channelId is empty. */
|
|
10
13
|
constructor(rest: REST, context: ResourceContext, channelId: string);
|
|
11
|
-
/** Resolves a message from cache or REST. @param messageId Message identifier. @returns Canonical message. */
|
|
12
14
|
resolve(messageId: string): Promise<Message>;
|
|
13
|
-
|
|
14
|
-
send(options: {
|
|
15
|
-
content?: string;
|
|
16
|
-
}): Promise<Message>;
|
|
17
|
-
/** Fetches one message and caches it canonically. @param messageId Message identifier. @returns Canonical message. */
|
|
15
|
+
send(options: MessageCreateOptions): Promise<Message>;
|
|
18
16
|
fetch(messageId: string): Promise<Message>;
|
|
19
|
-
/** Fetches several messages by ID. @param messageIds Message identifiers. @returns Canonical messages. */
|
|
20
17
|
fetchMany(messageIds: Iterable<string>): Promise<Message[]>;
|
|
21
|
-
/** Inserts or updates a message through the shared hydration path. @param data Discord message payload. @returns Canonical message. */
|
|
22
18
|
upsert(data: ConstructorParameters<typeof Message>[0]): Message;
|
|
23
|
-
/** Removes a message from cache. @param messageId Message identifier. @returns Whether a cached message was removed. */
|
|
24
19
|
delete(messageId: string): boolean;
|
|
25
20
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ResourceManager } from "./base.js";
|
|
2
|
+
import { User } from "@lunibee/structures";
|
|
3
|
+
import { type REST } from "@lunibee/rest";
|
|
4
|
+
import type { APIChannel } from "@lunibee/types";
|
|
5
|
+
export interface UserEditOptions {
|
|
6
|
+
username?: string;
|
|
7
|
+
avatar?: string | null;
|
|
8
|
+
}
|
|
9
|
+
export declare class UserManager extends ResourceManager<string, User> {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(rest: REST);
|
|
12
|
+
/** Gets the currently logged-in bot user. */
|
|
13
|
+
fetchMe(): Promise<User>;
|
|
14
|
+
/** Modifies the currently logged-in bot user. */
|
|
15
|
+
editMe(options: UserEditOptions): Promise<User>;
|
|
16
|
+
/** Leaves a guild. */
|
|
17
|
+
leaveGuild(guildId: string): Promise<void>;
|
|
18
|
+
/** Creates a DM channel with a user. */
|
|
19
|
+
createDM(userId: string): Promise<APIChannel>;
|
|
20
|
+
}
|
package/dist/rest/index.d.ts
CHANGED
|
@@ -1 +1,173 @@
|
|
|
1
|
-
|
|
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
|
+
import { type RateLimitStore } from "./store.js";
|
|
16
|
+
/** A file attachment sent as part of a multipart REST request. */
|
|
17
|
+
export interface RESTFileAttachment {
|
|
18
|
+
name: string;
|
|
19
|
+
data: Blob | Uint8Array | ArrayBuffer;
|
|
20
|
+
contentType?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Query-string value accepted by {@link RESTRequestOptions.query}. */
|
|
23
|
+
export type RESTQuery = URLSearchParams | Record<string, string | number | boolean | null | undefined> | string;
|
|
24
|
+
/**
|
|
25
|
+
* Options controlling an individual REST request.
|
|
26
|
+
*
|
|
27
|
+
* Lunibee's canonical call shape is positional (`post(path, body)`); these options
|
|
28
|
+
* add the Discord.js-`@discordjs/rest`-familiar per-request knobs (`query`, `headers`,
|
|
29
|
+
* `reason`, `auth`) additively without changing that positional default.
|
|
30
|
+
*/
|
|
31
|
+
export interface RESTRequestOptions {
|
|
32
|
+
/** Abort signal used to cancel the request and any queued wait. */ signal?: AbortSignal;
|
|
33
|
+
/** Query-string appended to the path (`URLSearchParams`, a record, or a raw string). */ query?: RESTQuery;
|
|
34
|
+
/** Extra request headers merged in (library headers such as `Authorization` win). */ headers?: Record<string, string>;
|
|
35
|
+
/** Audit-log reason, sent as the `X-Audit-Log-Reason` header. */ reason?: string;
|
|
36
|
+
/** Set `false` to omit the `Authorization` header for this request. Defaults to `true`. */ auth?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Discord.js-familiar request payload. Superset of {@link RESTRequestOptions} that also
|
|
40
|
+
* carries the `body` and `files`, matching `@discordjs/rest`'s `RequestData`. It powers the
|
|
41
|
+
* additive `method(path, { body })` overloads without breaking the positional signature.
|
|
42
|
+
*/
|
|
43
|
+
export interface RequestData extends RESTRequestOptions {
|
|
44
|
+
/** Request body. Encoded as JSON unless `files` are present (then multipart). */ body?: unknown;
|
|
45
|
+
/** File attachments; presence upgrades the request to `multipart/form-data`. */ files?: RESTFileAttachment[];
|
|
46
|
+
}
|
|
47
|
+
/** Context passed to `RESTHooks.onRequest`. */
|
|
48
|
+
export interface RESTRequestContext {
|
|
49
|
+
method: string;
|
|
50
|
+
path: string;
|
|
51
|
+
attempt: number;
|
|
52
|
+
}
|
|
53
|
+
/** Context passed to `RESTHooks.onResponse`. */
|
|
54
|
+
export interface RESTResponseContext {
|
|
55
|
+
method: string;
|
|
56
|
+
path: string;
|
|
57
|
+
status: number;
|
|
58
|
+
durationMs: number;
|
|
59
|
+
}
|
|
60
|
+
/** Context passed to `RESTHooks.onRateLimit`. */
|
|
61
|
+
export interface RESTRateLimitContext {
|
|
62
|
+
method: string;
|
|
63
|
+
path: string;
|
|
64
|
+
retryAfterMs: number;
|
|
65
|
+
global: boolean;
|
|
66
|
+
bucket?: string;
|
|
67
|
+
}
|
|
68
|
+
/** Context passed to `RESTHooks.onRetry`. */
|
|
69
|
+
export interface RESTRetryContext {
|
|
70
|
+
method: string;
|
|
71
|
+
path: string;
|
|
72
|
+
attempt: number;
|
|
73
|
+
status: number;
|
|
74
|
+
delayMs: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Lightweight callback hooks for REST request lifecycle events.
|
|
78
|
+
*
|
|
79
|
+
* All callbacks are optional. They are dispatched in isolation from the request
|
|
80
|
+
* path (deferred to a microtask, and any thrown error is swallowed), so a hook
|
|
81
|
+
* cannot break or reject a request. Even so, hooks **must** be fast and
|
|
82
|
+
* non-blocking: heavy synchronous work in a hook still steals event-loop time
|
|
83
|
+
* from in-flight requests. Offload anything expensive to your own queue.
|
|
84
|
+
*/
|
|
85
|
+
export interface RESTHooks {
|
|
86
|
+
/** Called just before every HTTP attempt. */
|
|
87
|
+
onRequest?(ctx: RESTRequestContext): void;
|
|
88
|
+
/** Called after a successful or failed response is received. */
|
|
89
|
+
onResponse?(ctx: RESTResponseContext): void;
|
|
90
|
+
/** Called when a rate limit is encountered and the client is about to wait. */
|
|
91
|
+
onRateLimit?(ctx: RESTRateLimitContext): void;
|
|
92
|
+
/** Called when a failed request is about to be retried. */
|
|
93
|
+
onRetry?(ctx: RESTRetryContext): void;
|
|
94
|
+
}
|
|
95
|
+
/** Configures which REST failures may be retried. */
|
|
96
|
+
export interface RetryPolicy {
|
|
97
|
+
/** Maximum retry attempts. */ maxRetries: number;
|
|
98
|
+
/** Determines whether a request may be retried. @param method HTTP method. @param status HTTP status, or zero for transport errors. @returns True when retrying is safe under the policy. */ shouldRetry(method: string, status: number): boolean;
|
|
99
|
+
/** Calculates delay before the next attempt. @param attempt Zero-based retry number. @param retryAfter Server-provided delay, when available. @returns Delay in milliseconds. */ getDelay(attempt: number, retryAfter?: number): number;
|
|
100
|
+
}
|
|
101
|
+
/** Creates the default conservative REST retry policy. @param maxRetries Maximum retries. @returns Retry policy that retries rate limits and idempotent transient failures. @throws {TypeError} If maxRetries is negative or not finite. */
|
|
102
|
+
export declare function createRetryPolicy(maxRetries?: number): RetryPolicy;
|
|
103
|
+
/** Bun-native REST transport with Discord bucket-aware rate limiting, retries, and cancellation. */
|
|
104
|
+
export declare class REST {
|
|
105
|
+
#private;
|
|
106
|
+
/** Creates a REST transport. @param options Transport configuration. @throws {TypeError} If retry configuration is invalid. */
|
|
107
|
+
constructor(options?: {
|
|
108
|
+
token?: string;
|
|
109
|
+
timeout?: number;
|
|
110
|
+
retries?: number;
|
|
111
|
+
retryPolicy?: RetryPolicy;
|
|
112
|
+
baseURL?: string;
|
|
113
|
+
hooks?: RESTHooks;
|
|
114
|
+
store?: RateLimitStore;
|
|
115
|
+
});
|
|
116
|
+
/** Replaces the current hook set. Pass an empty object to clear all hooks. */
|
|
117
|
+
setHooks(hooks: RESTHooks): this;
|
|
118
|
+
/** Sets the authentication token. @param token Discord bot token. @returns Nothing. @throws {TypeError} If token is empty. */
|
|
119
|
+
setToken(token: string): void;
|
|
120
|
+
/** Executes an HTTP request with Discord bucket/global rate limits, retry handling, and AbortSignal support.
|
|
121
|
+
* Accepts a JSON body, a FormData body (for file uploads), or undefined.
|
|
122
|
+
* @param method HTTP method.
|
|
123
|
+
* @param path API path.
|
|
124
|
+
* @param body Optional JSON body, FormData for file uploads, or undefined.
|
|
125
|
+
* @param options Request options: cancellation `signal` plus the Discord.js-familiar
|
|
126
|
+
* `query`, `headers`, `reason`, `auth`, and `files` (which upgrade to multipart).
|
|
127
|
+
* @returns Decoded response body.
|
|
128
|
+
* @throws {RESTError} If Discord or transport rejects the request.
|
|
129
|
+
*/
|
|
130
|
+
request<T>(method: string, path: string, body?: unknown, options?: RequestData): Promise<T>;
|
|
131
|
+
/** Sends a GET request. @param path API path. @param options Request options (`query`, `headers`, `signal`, …). @returns Decoded response. @throws {RESTError} When the request fails. */ get<T>(path: string, options?: RequestData): Promise<T>;
|
|
132
|
+
/** Sends a POST request. Accepts a raw body (`post(path, body)`) or a Discord.js-familiar `post(path, { body })`. @param path API path. @param body Optional JSON body, or a `RequestData` wrapper. @param options Request options. @returns Decoded response. @throws {RESTError} When the request fails. */
|
|
133
|
+
post<T>(path: string, options: RequestData): Promise<T>;
|
|
134
|
+
post<T>(path: string, body?: unknown, options?: RequestData): Promise<T>;
|
|
135
|
+
/** Sends a PATCH request. Accepts a raw body (`patch(path, body)`) or a Discord.js-familiar `patch(path, { body })`. @param path API path. @param body Optional JSON body, or a `RequestData` wrapper. @param options Request options. @returns Decoded response. @throws {RESTError} When the request fails. */
|
|
136
|
+
patch<T>(path: string, options: RequestData): Promise<T>;
|
|
137
|
+
patch<T>(path: string, body?: unknown, options?: RequestData): Promise<T>;
|
|
138
|
+
/** Sends a PUT request. Accepts a raw body (`put(path, body)`) or a Discord.js-familiar `put(path, { body })`. @param path API path. @param body Optional JSON body, or a `RequestData` wrapper. @param options Request options. @returns Decoded response. @throws {RESTError} When the request fails. */
|
|
139
|
+
put<T>(path: string, options: RequestData): Promise<T>;
|
|
140
|
+
put<T>(path: string, body?: unknown, options?: RequestData): Promise<T>;
|
|
141
|
+
/** Sends a DELETE request. @param path API path. @param options Request options (`reason`, `headers`, `signal`, …). @returns Decoded response. @throws {RESTError} When the request fails. */ delete<T>(path: string, options?: RequestData): Promise<T>;
|
|
142
|
+
/**
|
|
143
|
+
* Sends a multipart/form-data POST request for file uploads.
|
|
144
|
+
* Attaches a JSON payload as `payload_json` and files as additional fields.
|
|
145
|
+
* @param path API path.
|
|
146
|
+
* @param payload JSON payload (e.g. message content, embeds).
|
|
147
|
+
* @param files Array of file attachments.
|
|
148
|
+
* @param options Cancellation options.
|
|
149
|
+
* @returns Decoded response.
|
|
150
|
+
* @throws {RESTError} When the request fails.
|
|
151
|
+
*/
|
|
152
|
+
postWithFiles<T>(path: string, payload: unknown, files: RESTFileAttachment[], options?: RESTRequestOptions): Promise<T>;
|
|
153
|
+
/**
|
|
154
|
+
* Sends a multipart/form-data PATCH request for editing messages with files.
|
|
155
|
+
* @param path API path.
|
|
156
|
+
* @param payload JSON payload.
|
|
157
|
+
* @param files Array of file attachments.
|
|
158
|
+
* @param options Cancellation options.
|
|
159
|
+
* @returns Decoded response.
|
|
160
|
+
* @throws {RESTError} When the request fails.
|
|
161
|
+
*/
|
|
162
|
+
patchWithFiles<T>(path: string, payload: unknown, files: RESTFileAttachment[], options?: RESTRequestOptions): Promise<T>;
|
|
163
|
+
}
|
|
164
|
+
export { Routes } from "./routes.js";
|
|
165
|
+
export { type RateLimitStore, type BucketState, MemoryRateLimitStore, } from "./store.js";
|
|
166
|
+
export { RedisRateLimitStore, type RedisRateLimitStoreOptions, type MinimalRedisClient, } from "./redis.js";
|
|
167
|
+
export { WebhookClient, type WebhookClientOptions, type WebhookMessageOptions, } from "./webhook.js";
|
|
168
|
+
/**
|
|
169
|
+
* Discord.js-familiar alias for {@link RESTError}. `@discordjs/rest` throws `DiscordAPIError`
|
|
170
|
+
* on a Discord-rejected request; Lunibee keeps `RESTError` as the canonical class and exports
|
|
171
|
+
* this alias so Discord.js-shaped `catch (err) { if (err instanceof DiscordAPIError) … }` works.
|
|
172
|
+
*/
|
|
173
|
+
export { RESTError as DiscordAPIError };
|