@seedcord/gateway 0.8.0-next.0 → 0.9.0-next.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.
package/dist/index.d.mts CHANGED
@@ -1,21 +1,21 @@
1
1
  import "reflect-metadata";
2
+ import { InFlight } from "@seedcord/core/node/internal";
2
3
  import { WinstonConsoleSink, WinstonFileSink } from "@seedcord/logger/node";
3
4
  import { AutocompletableNames, AutocompleteRouteBrand, CacheFor, ChoiceValueOf, CommandRegistry, ComponentDefsBrand, ComponentKindBrand, ContextMenuKindBrand, ContextMenuLeaves, ContextMenuNamesBrand, EntryFor, FixedScope, FocusedField, GateFitsWith, HasComponentDefs, Initializeable, MatchArms, MenuCacheFor, MiddlewareKindsBrand, NamesFor, PageCursor, SingleParams, SlashOptions as SlashOptions$1, SlashRouteBrand } from "@seedcord/core/internal";
4
5
  import { ArraySourceBase, AutocompleteOptions, BaseHandler as BaseHandler$1, BaseReplySender, Bus, CoreBase, CursorSourceBase, DispatchContext, DispatchOutcome, DispatchResult, EventDispatchResult, Gate, GateContextBase, GateNoticeOptions, GuildPermissionsContext, HandlerOutcome, InteractionKind, MiddlewareKind, ModalLike, Notice, PageSourceBase, PaginatorBase, PaginatorConfig, PermissionNoticeOverrides, PermissionScope, RepliableHandler as RepliableHandler$1, RequiredOf, ResolvedEmoji, SlashRegistry, Subscriber as Subscriber$1, SubscriptionKey, WebhookLog as WebhookLog$1 } from "@seedcord/core";
5
6
  import { Logger } from "@seedcord/logger";
6
7
  import { APIInteractionGuildMember, APIModalInteractionResponseCallbackData, AnySelectMenuInteraction, ApplicationCommandOptionChoiceData, ApplicationCommandType, ApplicationEmoji, AutocompleteInteraction, BaseMessageOptions, BooleanCache, ButtonInteraction, ButtonStyle, CacheType, CacheTypeReducer, ChannelSelectMenuInteraction, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, CommandInteractionOption, ContextMenuCommandInteraction, Events, Guild, GuildEmoji, GuildMember, Interaction, MentionableSelectMenuInteraction, Message, MessageContextMenuCommandInteraction, ModalSubmitFields, ModalSubmitInteraction, Role, RoleSelectMenuInteraction, StringSelectMenuInteraction, TextChannel, User, UserContextMenuCommandInteraction, UserSelectMenuInteraction } from "discord.js";
7
8
  import { Plugin as Plugin$1, PluginLifecycleSpec, PluginOptions, PluginOptions as PluginOptions$1 } from "@seedcord/core/plugin";
8
- import { CoordinatedShutdown, CoordinatedStartup, ServerHost } from "@seedcord/core/node";
9
+ import { ServerHost, ShutdownTasks, StartupTasks } from "@seedcord/core/node";
9
10
  import { HostAugmentTarget, HostVersion, SeedcordBrand, SeedcordInstance } from "@seedcord/types/internal";
10
11
  import { HmrModuleHandler } from "@seedcord/core/hmr";
11
12
  import { AnyCustomId } from "@seedcord/custom-id";
12
- import { BotConfig, Config, DeferOpts, EmojiMap, EventFrequency, HealthCheckOption, HmrAware, HmrUpdateEvent, IRateLimiter, ReplyResponse, SendOpts, TypedOmit } from "@seedcord/types";
13
+ import { BotConfig, Config, DeferOpts, EmojiMap, EventFrequency, HealthCheckOption, HmrAware, HmrUpdateEvent, ReplyResponse, SendOpts, TypedOmit } from "@seedcord/types";
13
14
  import { Constructor, IsUnion, NonEmptyTuple, Promisable } from "type-fest";
14
15
  import { REST } from "@discordjs/rest";
15
16
  export * from "@seedcord/errors";
16
17
  export * from "@seedcord/core";
17
18
  export * from "@seedcord/logger";
18
- export * from "@seedcord/rate-limiter";
19
19
  export * from "@seedcord/utils";
20
20
  export * from "@seedcord/event-emitter";
21
21
  export type * from "@seedcord/types";
@@ -33,11 +33,11 @@ declare module '@seedcord/core/internal' {
33
33
  args: ClientEvents[Name];
34
34
  }; }[keyof ClientEvents];
35
35
  /**
36
- * Triggered once an event's handlers settle, pairing with `eventDispatching`. A fire that runs no
37
- * handler triggers neither.
36
+ * Published once an event's handlers settle, pairing with `eventDispatching`. When no handlers
37
+ * are registered, neither key is published.
38
38
  */
39
39
  eventDispatched: {
40
- /** The same id `eventDispatching` published for this fire. */
40
+ /** The same id `eventDispatching` published for this dispatch. */
41
41
  dispatchId: string;
42
42
  name: keyof ClientEvents;
43
43
  /** How the middleware chain ended. A chain that refused the event leaves `handlers` empty. */
@@ -102,18 +102,18 @@ interface GatewayConfig extends Config {
102
102
  */
103
103
  declare class EventDispatcher implements Initializeable, HmrAware {
104
104
  protected core: Core;
105
+ private readonly inFlight;
105
106
  private readonly logger;
106
107
  private isInitialized;
107
108
  private readonly eventMap;
108
109
  private readonly middlewares;
109
- private readonly executedOnceHandlers;
110
+ private readonly onceRuns;
110
111
  private readonly attachedEvents;
111
- private readonly inFlight;
112
112
  private loading;
113
113
  private readonly loadedHandlers;
114
114
  private readonly loadedMiddlewares;
115
115
  private readonly hmrHandler?;
116
- constructor(core: Core);
116
+ constructor(core: Core, inFlight: InFlight);
117
117
  private getArtifacts;
118
118
  init(): Promise<void>;
119
119
  private reportLoad;
@@ -130,8 +130,7 @@ declare class EventDispatcher implements Initializeable, HmrAware {
130
130
  private registerHandler;
131
131
  private attachToClient;
132
132
  private attachListener;
133
- stopAccepting(): void;
134
- drain(timeoutMs: number): Promise<void>;
133
+ private reportUnhandled;
135
134
  private processEvent;
136
135
  private processHandler;
137
136
  }
@@ -139,18 +138,18 @@ declare class EventDispatcher implements Initializeable, HmrAware {
139
138
  //#region src/bot/controllers/InteractionDispatcher.d.ts
140
139
  declare class InteractionDispatcher implements Initializeable, HmrAware {
141
140
  protected core: Core;
141
+ private readonly inFlight;
142
142
  private readonly logger;
143
143
  private isInitialized;
144
144
  private readonly maps;
145
145
  private readonly handlerFiles;
146
146
  private readonly keysToIgnore;
147
147
  private readonly middlewares;
148
- private readonly inFlight;
149
148
  private loading;
150
149
  private readonly loadedHandlers;
151
150
  private readonly loadedMiddlewares;
152
151
  private readonly hmrHandler?;
153
- constructor(core: Core);
152
+ constructor(core: Core, inFlight: InFlight);
154
153
  warnUnhandledRoutes(commandLeaves: Iterable<string>): void;
155
154
  warnUnhandledContextMenuRoutes(leaves: ContextMenuLeaves): void;
156
155
  private getArtifacts;
@@ -166,8 +165,6 @@ declare class InteractionDispatcher implements Initializeable, HmrAware {
166
165
  private unregisterHandler;
167
166
  private unregisterMiddleware;
168
167
  private attachToClient;
169
- stopAccepting(): void;
170
- drain(timeoutMs: number): Promise<void>;
171
168
  private handleCustomIdInteraction;
172
169
  private processInteraction;
173
170
  private answer;
@@ -236,8 +233,8 @@ declare class Bot implements HmrAware {
236
233
  * ```
237
234
  * */
238
235
  interface Core extends CoreBase {
239
- readonly shutdown: Pick<CoordinatedShutdown, 'addTask'>;
240
- readonly startup: Pick<CoordinatedStartup, 'addTask'>;
236
+ readonly shutdown: ShutdownTasks;
237
+ readonly startup: StartupTasks;
241
238
  readonly bot: Bot;
242
239
  readonly config: GatewayConfig;
243
240
  }
@@ -313,7 +310,7 @@ export declare abstract class EventHandler<in out Names extends ValidNonInteract
313
310
  constructor(event: ClientEvents[Names], core: Core, dispatch: DispatchContext, eventName?: Names);
314
311
  protected readonly event: SingleEventPayload<Names>;
315
312
  /**
316
- * Run the arm for whichever event fired. Use this only when the handler is registered for several
313
+ * Run the arm for the current event. Use this only when the handler is registered for several
317
314
  * events. A single-event handler reads `this.event` directly. On a multi-event handler `this.event` is
318
315
  * `never`, so match is the only way to read the payload.
319
316
  *
@@ -357,7 +354,7 @@ export declare abstract class EventMiddleware<in out EventName extends ValidNonI
357
354
  constructor(event: ClientEvents[EventName], core: Core, dispatch: DispatchContext, eventName?: EventName);
358
355
  protected readonly event: SingleEventPayload<EventName>;
359
356
  /**
360
- * The event that fired this middleware. Read it on a catchall or multi-event middleware, where `this.event`
357
+ * The name of the event being processed. Read it on a catchall or multi-event middleware, where `this.event`
361
358
  * is `never`, to do work that does not depend on the payload shape. A single-event middleware reads
362
359
  * `this.event` directly and does not need this.
363
360
  */
@@ -536,7 +533,7 @@ interface InteractionGateContext<Repliable extends Repliables = Repliables> exte
536
533
  * annotation, so a gate that reads one event's `payload` is rejected on a handler for a different
537
534
  * event. The default supports every event.
538
535
  *
539
- * @typeParam Names - The event name or names the gate reads, typing `payload` to that event's args tuple.
536
+ * @typeParam Names - One event or a union of the events the gate reads. `payload` gets that event's args tuple.
540
537
  *
541
538
  * @example
542
539
  * ```ts
@@ -600,7 +597,7 @@ type FitAll<TCtor extends AnyHandlerCtor, Gates extends readonly Gate<GateContex
600
597
  * Attaches gates to a handler. The gates run before `execute`, and a gate refusing stops the handler with
601
598
  * the reply or drop the gate threw. Multiple gates are ANDed, so each must pass. A gate that requires a
602
599
  * context the handler does not provide (a button gate on a slash handler, an interaction gate on an event
603
- * handler) is a compile error at this line, and the error names the gate and the handler kind. Place it
600
+ * handler) is a compile error at this line, and the error message shows the gate and the handler kind. Place it
604
601
  * above the route decorator.
605
602
  *
606
603
  * Combine gates with {@link and} or {@link or} to build a single gate from multiple arms.
@@ -1094,6 +1091,8 @@ type SlashMatchArms<Route extends keyof SlashRegistry, Cache extends CacheType,
1094
1091
  export declare abstract class SlashHandler<Route extends keyof SlashRegistry, Cache extends CacheType = CacheFor<Route>> extends InteractionHandler<ChatInputCommandInteraction<Cache>> {
1095
1092
  /** @internal */
1096
1093
  readonly [SlashRouteBrand]?: Route;
1094
+ /** The selected command's path, such as `search/docs`. */
1095
+ protected get route(): Route;
1097
1096
  /**
1098
1097
  * The typed options for this command's route. Only the getters for kinds this command declares appear.
1099
1098
  * Each getter's name argument is restricted to that command's options of its kind.
@@ -1109,7 +1108,7 @@ export declare abstract class SlashHandler<Route extends keyof SlashRegistry, Ca
1109
1108
  */
1110
1109
  protected get options(): SlashOptions<Route, Cache>;
1111
1110
  /**
1112
- * Run the arm for whichever command fired. Use this only when the handler is registered for several
1111
+ * Run the arm for the selected command. Use this only when the handler is registered for several
1113
1112
  * routes.
1114
1113
  *
1115
1114
  * Provide one arm per registered route, keyed by its route string, and each arm receives that route's
@@ -1165,10 +1164,10 @@ export declare abstract class UserContextMenuHandler<Names extends NamesFor<Appl
1165
1164
  protected get target(): User;
1166
1165
  /** The right-clicked user's guild member, null outside a guild. */
1167
1166
  protected get targetMember(): CacheTypeReducer<Cache, GuildMember, APIInteractionGuildMember> | null;
1168
- /** Which of the registered commands fired. */
1169
- protected get commandName(): Names;
1167
+ /** The selected context-menu command's name, without the interaction-kind prefix. */
1168
+ protected get route(): Names;
1170
1169
  /**
1171
- * Run the arm for whichever command fired. Use this only when the handler is registered for several
1170
+ * Run the arm for the selected command. Use this only when the handler is registered for several
1172
1171
  * names.
1173
1172
  *
1174
1173
  * Provide one arm per registered name, keyed by the name Discord shows in the right-click menu. Each
@@ -1219,10 +1218,10 @@ export declare abstract class MessageContextMenuHandler<Names extends NamesFor<A
1219
1218
  /** @internal */
1220
1219
  readonly [ContextMenuNamesBrand]?: Names;
1221
1220
  protected get target(): Message<BooleanCache<Cache>>;
1222
- /** Which of the registered commands fired. */
1223
- protected get commandName(): Names;
1221
+ /** The selected context-menu command's name, without the interaction-kind prefix. */
1222
+ protected get route(): Names;
1224
1223
  /**
1225
- * Run the arm for whichever command fired. Use this only when the handler is registered for several
1224
+ * Run the arm for the selected command. Use this only when the handler is registered for several
1226
1225
  * names.
1227
1226
  *
1228
1227
  * Provide one arm per registered name, keyed by the name Discord shows in the right-click menu. Each
@@ -1255,7 +1254,7 @@ type FocusedArms<Route extends keyof SlashRegistry, Ret> = { [Name in Autocomple
1255
1254
  *
1256
1255
  * Pass the command route(s) from the generated registry as the generic, the same string(s) as
1257
1256
  * `@AutocompleteRoute`. Branch on the focused field with `this.match`, read already-entered sibling options
1258
- * with `this.options`, and find which command fired with `this.route`.
1257
+ * with `this.options`, and read the selected command's path from `this.route`.
1259
1258
  *
1260
1259
  * @typeParam Route - One or more route keys from {@link SlashRegistry}, e.g. `'search'` or `'search' | 'find'`.
1261
1260
  * @typeParam Cache - The interaction cache state. The command's contexts set it.
@@ -1310,7 +1309,7 @@ export declare abstract class AutocompleteHandler<Route extends keyof SlashRegis
1310
1309
  protected match<Ret>(arms: FocusedArms<Route, Ret>): Promise<Ret>;
1311
1310
  /** Send autocomplete suggestions, callback type 8. Prefer {@link match}, which restricts each field's choices to its declared type. */
1312
1311
  protected respond(choices: readonly ApplicationCommandOptionChoiceData[]): Promise<void>;
1313
- /** The firing command route, for a field whose completion differs per registered command. */
1312
+ /** The selected command's path, such as `search/docs`, without the interaction-kind prefix. */
1314
1313
  protected get route(): Route;
1315
1314
  /**
1316
1315
  * The already-entered options on this command, restricted to the kinds Discord resolves during autocomplete
@@ -1339,7 +1338,14 @@ export declare abstract class ComponentHandler<Event extends ComponentInteractio
1339
1338
  /** Acknowledge the component without changing the source message. */
1340
1339
  protected deferUpdate(): Promise<void>;
1341
1340
  private decoded?;
1342
- private get route();
1341
+ private get decodedRoute();
1342
+ /**
1343
+ * The matched custom-ID prefix, such as `approve`, without encoded params.
1344
+ *
1345
+ * @throws A **StaleCustomId** when the wire was encoded under an older shape.
1346
+ * @throws An **InvalidCustomId** when the wire is corrupt.
1347
+ */
1348
+ protected get route(): Defs[number]['prefix'];
1343
1349
  /**
1344
1350
  * The decoded params of the single route this handler is registered for.
1345
1351
  *
@@ -1738,16 +1744,12 @@ export declare class Seedcord extends ServerHost<'gateway'> implements SeedcordI
1738
1744
  readonly [HostAugmentTarget] = "@seedcord/gateway";
1739
1745
  /** @internal */
1740
1746
  readonly [HostVersion]: string;
1741
- /** @see {@link Bus} */
1742
- readonly bus: Bus;
1743
1747
  /** @see {@link Bot} */
1744
1748
  readonly bot: Bot;
1745
1749
  /** The discord.js client's REST client. Its token is set during the Login phase. */
1746
1750
  readonly rest: REST;
1747
1751
  /** The bot's Discord application id. Throws if you read it before login. */
1748
1752
  get applicationId(): string;
1749
- /** @see {@link IRateLimiter} */
1750
- readonly rateLimiter: IRateLimiter;
1751
1753
  /**
1752
1754
  * @param config - Bot configuration including paths and Discord client options
1753
1755
  * @throws A **SeedcordError** when another `Seedcord` exists in this process and has not shut down.