lunibee 0.3.0 → 0.3.2
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/dist/builders/attachment.d.ts +1 -0
- package/dist/builders/clone.d.ts +10 -0
- package/dist/builders/commands.d.ts +1 -1
- package/dist/builders/components.d.ts +24 -5
- package/dist/builders/embed.d.ts +1 -0
- package/dist/builders/index.js +68 -17
- package/dist/builders/index.js.map +10 -9
- package/dist/collection/index.d.ts +1 -0
- package/dist/collection/index.js +297 -19
- package/dist/collection/index.js.map +5 -4
- package/dist/collection/redis.d.ts +98 -0
- package/dist/core/collector.d.ts +8 -0
- package/dist/core/events.d.ts +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +6252 -4704
- package/dist/core/index.js.map +47 -40
- package/dist/core/permissions.d.ts +3 -402
- package/dist/core/redis-cache.d.ts +85 -0
- package/dist/formatters/index.d.ts +5 -1
- package/dist/formatters/index.js +7 -3
- package/dist/formatters/index.js.map +3 -3
- package/dist/handlers/index.js +11 -2
- package/dist/handlers/index.js.map +3 -3
- package/dist/index.js +10481 -6148
- package/dist/index.js.map +70 -56
- package/dist/managers/application.d.ts +10 -6
- package/dist/managers/base.d.ts +4 -1
- package/dist/managers/guild.d.ts +3 -1
- package/dist/managers/index.d.ts +6 -1
- package/dist/managers/index.js +365 -103
- package/dist/managers/index.js.map +19 -22
- package/dist/managers/member.d.ts +3 -1
- package/dist/managers/message.d.ts +13 -4
- package/dist/managers/thread.d.ts +3 -3
- package/dist/rest/decoder.d.ts +2 -0
- package/dist/rest/errors.d.ts +13 -2
- package/dist/rest/headers.d.ts +31 -0
- package/dist/rest/identity.d.ts +31 -0
- package/dist/rest/index.d.ts +99 -6
- package/dist/rest/index.js +1412 -231
- package/dist/rest/index.js.map +16 -13
- package/dist/rest/limiter.d.ts +75 -10
- package/dist/rest/redis.d.ts +103 -22
- package/dist/rest/scheduler.d.ts +13 -0
- package/dist/rest/store.d.ts +135 -12
- package/dist/rest/telemetry.d.ts +151 -0
- package/dist/rest/transport.d.ts +9 -0
- package/dist/rest/webhook.d.ts +18 -6
- package/dist/sharding/bus.d.ts +12 -2
- package/dist/sharding/cluster.d.ts +225 -15
- package/dist/sharding/context.d.ts +41 -0
- package/dist/sharding/gateway-bot.d.ts +20 -0
- package/dist/sharding/health.d.ts +94 -0
- package/dist/sharding/host.d.ts +76 -0
- package/dist/sharding/identify.d.ts +64 -0
- package/dist/sharding/index.d.ts +62 -12
- package/dist/sharding/index.js +2459 -202
- package/dist/sharding/index.js.map +21 -13
- package/dist/sharding/protocol.d.ts +47 -0
- package/dist/sharding/remote-protocol.d.ts +100 -0
- package/dist/sharding/remote.d.ts +134 -0
- package/dist/sharding/requests.d.ts +54 -0
- package/dist/sharding/supervisor.d.ts +1 -1
- package/dist/sharding/transport.d.ts +6 -5
- package/dist/sharding/worker.d.ts +55 -0
- package/dist/structures/base.d.ts +16 -5
- package/dist/structures/index.d.ts +1 -1
- package/dist/structures/index.js +57 -91
- package/dist/structures/index.js.map +10 -18
- package/dist/structures/options.d.ts +3 -2
- package/dist/structures/permissions.d.ts +409 -0
- package/dist/structures/resources.d.ts +4 -1
- package/dist/types/gateway.d.ts +7 -0
- package/dist/types/index.d.ts +14 -4
- package/dist/types/index.js.map +3 -3
- package/dist/utils/args.d.ts +3 -1
- package/dist/utils/index.d.ts +6 -1
- package/dist/utils/index.js +17 -10
- package/dist/utils/index.js.map +4 -4
- package/dist/voice/index.d.ts +7 -1
- package/dist/voice/index.js +33 -10
- package/dist/voice/index.js.map +3 -3
- package/dist/ws/index.d.ts +3 -1
- package/dist/ws/index.js +33 -5
- package/dist/ws/index.js.map +6 -6
- package/dist/ws/send-budget.d.ts +1 -1
- package/package.json +22 -17
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Discord allows one IDENTIFY per rate-limit key every five seconds. */
|
|
2
|
+
export declare const IDENTIFY_INTERVAL = 5000;
|
|
3
|
+
/** What `/gateway/bot` says about the session budget. */
|
|
4
|
+
export interface IdentifyBudget {
|
|
5
|
+
total: number;
|
|
6
|
+
remaining: number;
|
|
7
|
+
/** Milliseconds until `remaining` resets, counted from construction. */
|
|
8
|
+
resetAfter: number;
|
|
9
|
+
/** Milliseconds between resets after that one. Discord resets the budget every 24 hours (the default). */
|
|
10
|
+
period?: number;
|
|
11
|
+
}
|
|
12
|
+
/** Options for an {@link IdentifyCoordinator}. */
|
|
13
|
+
export interface IdentifyCoordinatorOptions {
|
|
14
|
+
/** Discord's `max_concurrency`: shards with the same `id % maxConcurrency` share a key. Default 1. */
|
|
15
|
+
maxConcurrency?: number;
|
|
16
|
+
/** Milliseconds between two IDENTIFYs on one key. Default 5000. */
|
|
17
|
+
interval?: number;
|
|
18
|
+
/** The session-start budget, when known. Without it the coordinator paces but never blocks. */
|
|
19
|
+
budget?: IdentifyBudget;
|
|
20
|
+
/** A granted slot that is not released within this many ms is released for the holder. Default 60,000. */
|
|
21
|
+
holdTimeout?: number;
|
|
22
|
+
/** Clock, injectable for tests. */
|
|
23
|
+
now?: () => number;
|
|
24
|
+
/** Timer, injectable for tests. Must return a handle `cancel` understands. */
|
|
25
|
+
schedule?: (callback: () => void, ms: number) => unknown;
|
|
26
|
+
cancel?: (handle: unknown) => void;
|
|
27
|
+
/** Called when a request has to wait for the budget to reset. */
|
|
28
|
+
onBudgetWait?: (info: {
|
|
29
|
+
shardId: number;
|
|
30
|
+
waitMs: number;
|
|
31
|
+
}) => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Hands out IDENTIFY slots for a whole deployment. Every cluster asks the
|
|
35
|
+
* parent, so the limit holds across processes: one IDENTIFY per rate-limit key
|
|
36
|
+
* per interval, and no more IDENTIFYs than `session_start_limit.remaining`.
|
|
37
|
+
* It only does arithmetic on timestamps and holds one timer, so it can be
|
|
38
|
+
* tested with a fake clock.
|
|
39
|
+
*/
|
|
40
|
+
export declare class IdentifyCoordinator {
|
|
41
|
+
#private;
|
|
42
|
+
readonly maxConcurrency: number;
|
|
43
|
+
constructor(options?: IdentifyCoordinatorOptions);
|
|
44
|
+
/** Slots left in the session budget, or `undefined` when it is unknown. */
|
|
45
|
+
get remaining(): number | undefined;
|
|
46
|
+
/** Requests waiting for a slot. */
|
|
47
|
+
get waiting(): number;
|
|
48
|
+
/** Slots granted and not yet released. */
|
|
49
|
+
get holding(): number;
|
|
50
|
+
/**
|
|
51
|
+
* Waits for the shard's turn. Resolves when the shard may IDENTIFY now;
|
|
52
|
+
* call {@link release} once it has. Rejects if `owner` is dropped or the
|
|
53
|
+
* coordinator closes first.
|
|
54
|
+
*/
|
|
55
|
+
acquire(owner: number, shardId: number): Promise<void>;
|
|
56
|
+
/** The shard has sent its IDENTIFY: its key rests for one interval. Ignored unless `owner` holds the slot. */
|
|
57
|
+
release(owner: number, shardId: number): void;
|
|
58
|
+
/** A cluster is gone: forget its waiting requests and free the slots it held. */
|
|
59
|
+
drop(owner: number, reason?: string): void;
|
|
60
|
+
/** Rejects every waiter and stops the timer. */
|
|
61
|
+
close(): void;
|
|
62
|
+
/** Grants every slot that is due and arms one timer for the next. Called internally and by tests after moving the clock. */
|
|
63
|
+
pump(): void;
|
|
64
|
+
}
|
package/dist/sharding/index.d.ts
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import { type GatewayBotInfo } from "./gateway-bot.js";
|
|
2
2
|
import { Gateway } from "@lunibee/ws";
|
|
3
|
-
|
|
3
|
+
import { type ClusterContext } from "./context.js";
|
|
4
|
+
import type { ShardHealth, WorkerReport } from "./health.js";
|
|
5
|
+
import { ClusterWorker, type IdentifyGate } from "./worker.js";
|
|
6
|
+
export { MAX_GUILDS_PER_SHARD, fetchGatewayBot, fetchGuildCount, shardsForGuilds, type GatewayBotInfo, } from "./gateway-bot.js";
|
|
4
7
|
export { ShardBus } from "./bus.js";
|
|
5
8
|
export { BroadcastChannelTransport, IpcTransport, type IpcEndpoint, type ShardBusTransport, } from "./transport.js";
|
|
6
9
|
export { ShardSupervisor, type SupervisorOptions } from "./supervisor.js";
|
|
7
10
|
export type { ShardBusErrorHandler, ShardBusOptions, ShardMessage, ShardMessageHandler, ShardReply, } from "./bus.js";
|
|
8
11
|
export { ClusterManager } from "./cluster.js";
|
|
9
|
-
export type { ClusterManagerOptions, ClusterInfo } from "./cluster.js";
|
|
12
|
+
export type { ClusterManagerOptions, ClusterManagerEvents, ClusterInfo, BroadcastResult, RequestOptions, } from "./cluster.js";
|
|
13
|
+
export { allocateShards, assertCompleteAllocation, isClusterWorker, readClusterContext, validateShardIds, type ClusterContext, } from "./context.js";
|
|
14
|
+
export { ClusterWorker, type IdentifyGate } from "./worker.js";
|
|
15
|
+
export { ClusterHost, type ClusterHostEvents, type ClusterHostOptions, } from "./host.js";
|
|
16
|
+
export type { HostStatus, RemoteOptions } from "./remote.js";
|
|
17
|
+
export { RemoteClose, REMOTE_PROTOCOL_VERSION } from "./remote-protocol.js";
|
|
18
|
+
export { IdentifyCoordinator, IDENTIFY_INTERVAL, type IdentifyBudget, type IdentifyCoordinatorOptions, } from "./identify.js";
|
|
19
|
+
export { RequestTracker } from "./requests.js";
|
|
20
|
+
export type { ClusterHealth, ClusterManagerHealth, ClusterState, ShardHealth, ShardStatus, WorkerMetrics, WorkerReport, } from "./health.js";
|
|
10
21
|
/** Configuration for a sharded Gateway client. */
|
|
11
22
|
export interface ShardManagerOptions {
|
|
12
23
|
/** Bot token. */
|
|
@@ -15,6 +26,16 @@ export interface ShardManagerOptions {
|
|
|
15
26
|
intents: ConstructorParameters<typeof Gateway>[0]["intents"];
|
|
16
27
|
/** Number of shards. Use `"auto"` to request Discord's recommended count. */
|
|
17
28
|
shardCount?: number | "auto";
|
|
29
|
+
/**
|
|
30
|
+
* With `shardCount: "auto"`, size the deployment by guilds instead of
|
|
31
|
+
* Discord's recommendation: `ceil(guilds / guildsPerShard)` shards, at
|
|
32
|
+
* least one. 1 to 2500 (Discord's limit); Discord recommends about 1000.
|
|
33
|
+
* Guilds are assigned to shards by their ID, so this sets the average,
|
|
34
|
+
* not an exact split.
|
|
35
|
+
*/
|
|
36
|
+
guildsPerShard?: number;
|
|
37
|
+
/** The bot's guild count for `guildsPerShard`, instead of asking Discord for it. */
|
|
38
|
+
guildCount?: number;
|
|
18
39
|
/** Gateway reconnect behavior. */
|
|
19
40
|
reconnect?: boolean;
|
|
20
41
|
/**
|
|
@@ -35,14 +56,25 @@ export interface ShardManagerOptions {
|
|
|
35
56
|
autoScaleInterval?: number;
|
|
36
57
|
/** Optional handler invoked when a background auto-scale check fails. Receives the thrown error. */
|
|
37
58
|
onAutoScaleError?: (error: unknown) => void;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
|
|
59
|
+
/**
|
|
60
|
+
* The shards this manager runs, out of `shardCount`. Defaults to all of
|
|
61
|
+
* them, or to the cluster's own list inside a worker forked by
|
|
62
|
+
* `ClusterManager`. Must be unique integers in `[0, shardCount)`.
|
|
63
|
+
*/
|
|
64
|
+
shardIds?: number[];
|
|
65
|
+
/**
|
|
66
|
+
* The worker contract. Read from the environment inside a worker forked by
|
|
67
|
+
* `ClusterManager`; pass `false` to ignore it, or a context to override it.
|
|
68
|
+
*/
|
|
69
|
+
cluster?: ClusterContext | false;
|
|
70
|
+
/**
|
|
71
|
+
* Where to get IDENTIFY slots. Inside a coordinated cluster this is the
|
|
72
|
+
* parent, so the limit holds across all clusters. Pass `false` to pace
|
|
73
|
+
* locally with `spawnDelay` instead.
|
|
74
|
+
*/
|
|
75
|
+
identify?: IdentifyGate | false;
|
|
76
|
+
/** The worker to report to. Defaults to this process's `ClusterWorker` inside a cluster. */
|
|
77
|
+
worker?: ClusterWorker | false;
|
|
46
78
|
}
|
|
47
79
|
/** What `ShardManager` emits about its shards. */
|
|
48
80
|
export interface ShardManagerEvents {
|
|
@@ -57,6 +89,14 @@ export interface ShardManagerEvents {
|
|
|
57
89
|
shardResume: [shardId: number];
|
|
58
90
|
/** A shard reported an error. */
|
|
59
91
|
shardError: [shardId: number, error: Error];
|
|
92
|
+
/** Every shard this manager owns is ready. Emitted again after a shard drops and recovers. */
|
|
93
|
+
ready: [];
|
|
94
|
+
/**
|
|
95
|
+
* A shard's `Gateway` was created and has not connected yet: attach dispatch
|
|
96
|
+
* listeners here so none of its events are missed. Fires again for the new
|
|
97
|
+
* Gateways after `destroy()` + `connect()` or `reshard()`.
|
|
98
|
+
*/
|
|
99
|
+
shardCreate: [shardId: number, gateway: Gateway];
|
|
60
100
|
/** A shard reconnected too often too fast and is backing off (see `Gateway` `unstable`). */
|
|
61
101
|
shardUnstable: [
|
|
62
102
|
shardId: number,
|
|
@@ -80,8 +120,10 @@ export declare class ShardManager {
|
|
|
80
120
|
static readonly IDENTIFY_INTERVAL = 5000;
|
|
81
121
|
/** Active Gateway shards indexed by shard identifier. */
|
|
82
122
|
readonly shards: Map<number, Gateway>;
|
|
83
|
-
/**
|
|
123
|
+
/** Total shards in the deployment once initialized, 0 before and after `destroy()`. */
|
|
84
124
|
get shardCount(): number;
|
|
125
|
+
/** IDs of the shards this manager owns. */
|
|
126
|
+
get shardIds(): number[];
|
|
85
127
|
/** Creates a shard manager. @param options Sharding configuration. @throws {TypeError} If token or intents are invalid. @throws {RangeError} If shard count is invalid. */
|
|
86
128
|
constructor(options: ShardManagerOptions);
|
|
87
129
|
/** Retrieves Discord's recommended shard count. @returns Recommended shard count. @throws {Error} If discovery fails or returns invalid data. */
|
|
@@ -90,6 +132,12 @@ export declare class ShardManager {
|
|
|
90
132
|
fetchGatewayInfo(): Promise<GatewayBotInfo>;
|
|
91
133
|
/** Connects all shards sequentially. A destroyed manager is reinitialized before connecting. @returns A promise fulfilled after all shards connect. @throws {Error} If a shard fails to connect. */
|
|
92
134
|
connect(): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Takes over more shards of the same deployment (recovery after another
|
|
137
|
+
* cluster gave up) and connects them through the same IDENTIFY path.
|
|
138
|
+
* @throws {RangeError} If an ID is invalid, already owned, or the manager is not initialized.
|
|
139
|
+
*/
|
|
140
|
+
addShards(shardIds: readonly number[]): Promise<void>;
|
|
93
141
|
/** Checks if the recommended shard count has changed and reconnects if so. */
|
|
94
142
|
checkAutoScale(): Promise<void>;
|
|
95
143
|
/** Forces a reshard to a new shard count, replacing all active shards. @param count New shard count. */
|
|
@@ -109,8 +157,10 @@ export declare class ShardManager {
|
|
|
109
157
|
}): boolean;
|
|
110
158
|
/** Gets a shard by ID. @param id Shard identifier. @returns Gateway instance or undefined. */
|
|
111
159
|
get(id: number): Gateway | undefined;
|
|
112
|
-
/** Returns each shard's connection state and heartbeat latency. */
|
|
160
|
+
/** Returns each shard's connection state, lifecycle status and heartbeat latency. */
|
|
113
161
|
health(): ShardHealth[];
|
|
162
|
+
/** A health report for the parent: shard health and, on request, process metrics. */
|
|
163
|
+
report(metrics?: boolean): WorkerReport;
|
|
114
164
|
/** Returns information for all managed shards. @returns Shard information snapshots. */
|
|
115
165
|
values(): ShardInfo[];
|
|
116
166
|
}
|