commandkit 0.1.11-dev.20250306101654 → 0.1.11-dev.20250306152436

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.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as discord_js from 'discord.js';
2
- import { RESTPostAPIApplicationCommandsJSONBody, Client, Interaction, CacheType, PermissionsString, ChatInputCommandInteraction, ContextMenuCommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, AutocompleteInteraction, ClientEvents, Awaitable, ButtonBuilder, ButtonInteraction, Events, ModalBuilder, ModalSubmitInteraction, ActionRowBuilder, TextInputBuilder, ButtonStyle, ComponentEmojiResolvable, TextInputStyle, Locale, Message as Message$1, ApplicationCommandOptionType, GuildMember, Attachment, User, Role, CommandInteractionOption, SlashCommandBuilder, ContextMenuCommandBuilder, PartialMessage } from 'discord.js';
2
+ import { RESTPostAPIApplicationCommandsJSONBody, Client, Interaction, CacheType, PermissionsString, ChatInputCommandInteraction, ContextMenuCommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, AutocompleteInteraction, ClientEvents, Awaitable, ButtonBuilder, ButtonInteraction, Events, ModalBuilder, ModalSubmitInteraction, ActionRowBuilder, TextInputBuilder, ButtonStyle, ComponentEmojiResolvable, TextInputStyle, Locale, Message as Message$1, ApplicationCommandOptionType, GuildMember, Attachment, User, Role, CommandInteractionOption, Collection, SlashCommandBuilder, ContextMenuCommandBuilder, PartialMessage } from 'discord.js';
3
3
  import EventEmitter from 'node:events';
4
4
  import { Channel } from 'diagnostics_channel';
5
5
  import * as commander from 'commander';
@@ -1007,164 +1007,131 @@ declare class MiddlewareContext<T extends CommandExecutionMode = CommandExecutio
1007
1007
  cancel(): void;
1008
1008
  }
1009
1009
 
1010
- /**
1011
- * Matcher type for identifying command and middleware files.
1012
- * Can be a string suffix (e.g. '.cmd.js'), RegExp pattern, or custom matcher function.
1013
- */
1014
- type CommandsRouterMatcher = string | RegExp | ((path: string) => boolean);
1015
- /**
1016
- * Maps file type identifiers to their respective matchers.
1017
- * Used to identify command and middleware files in the directory structure.
1018
- */
1019
- type CommandsRouterMatchersMap = Record<'command' | 'middleware', CommandsRouterMatcher>;
1020
- /**
1021
- * Configuration options for the CommandsRouter
1022
- */
1023
- interface CommandsRouterOptions {
1010
+ interface ParsedCommand {
1024
1011
  /**
1025
- * The path to the directory containing the command files.
1012
+ * The unique identifier of this command.
1026
1013
  */
1027
- entrypoint: string;
1014
+ id: string;
1028
1015
  /**
1029
- * The path to the directory containing the middleware files.
1016
+ * The file name without the extension.
1030
1017
  */
1031
- matcher?: Partial<CommandsRouterMatchersMap>;
1032
- }
1033
- /**
1034
- * Represents a parsed command with its metadata
1035
- * @interface ParsedCommand
1036
- */
1037
- interface ParsedCommand {
1038
- /** Command name derived from the file name without extension */
1039
1018
  name: string;
1040
- /** Absolute file system path to the command file */
1041
- path: string;
1042
- /** Parent command name for nested commands, or null if root-level command */
1043
- parent: string | null;
1044
- /** Array of command segments representing the command hierarchy */
1045
- parentSegments: string[];
1046
- /** Array of middleware IDs that apply to this command */
1047
- middlewares: string[];
1048
- /** Absolute path to this command */
1049
- fullPath: string;
1050
- /** Category the command belongs to, if any */
1019
+ /**
1020
+ * The full path to the command file.
1021
+ * This can be null for directories that function as command groups but have no index file.
1022
+ */
1023
+ path: string | null;
1024
+ /**
1025
+ * The category of the command.
1026
+ */
1051
1027
  category: string | null;
1028
+ /**
1029
+ * The subcommands of this command parsed from `(category)` format, but omitting the brackets.
1030
+ */
1031
+ subcommands: string[];
1032
+ /**
1033
+ * The middlewares of this command.
1034
+ */
1035
+ middlewares: string[];
1052
1036
  }
1053
- /**
1054
- * Represents a parsed middleware with its metadata
1055
- * @interface ParsedMiddleware
1056
- */
1057
- interface ParsedMiddleware {
1058
- /** Unique identifier used to reference this middleware */
1037
+ interface ParsedSubCommand {
1038
+ /**
1039
+ * The unique identifier of this subcommand.
1040
+ */
1059
1041
  id: string;
1060
- /** Middleware name derived from the file path */
1042
+ /**
1043
+ * The file name without the extension.
1044
+ */
1061
1045
  name: string;
1062
- /** Path to the middleware file, relative to the entrypoint */
1046
+ /**
1047
+ * The full path to the subcommand file.
1048
+ */
1063
1049
  path: string;
1064
- /** Absolute path to the middleware file */
1065
- fullPath: string;
1066
- /** Category the middleware belongs to, if any */
1050
+ /**
1051
+ * The category of the subcommand parsed from `(category)` format, but omitting the brackets.
1052
+ */
1067
1053
  category: string | null;
1068
- }
1069
- /**
1070
- * Complete tree structure of all commands and middleware
1071
- * @interface CommandsTree
1072
- */
1073
- interface CommandsTree {
1074
- /** Map of command names to their parsed metadata */
1075
- commands: Record<string, ParsedCommand>;
1076
- /** Map of middleware IDs to their parsed metadata */
1077
- middleware: Record<string, ParsedMiddleware>;
1078
- }
1079
- /**
1080
- * Result of a successful command match operation
1081
- * @interface CommandMatchResult
1082
- */
1083
- interface CommandMatchResult {
1084
- /** The matched command metadata */
1085
- command: ParsedCommand;
1086
- /** Array of middleware that apply to the matched command */
1087
- middlewares: ParsedMiddleware[];
1088
- }
1089
- /**
1090
- * CommandsRouter handles the discovery and routing of commands and middleware files
1091
- * in a directory structure. It supports nested commands and middleware inheritance.
1092
- */
1093
- declare class CommandsRouter {
1094
- private readonly options;
1095
- private commands;
1096
- private middlewares;
1097
1054
  /**
1098
- * Creates a new CommandsRouter instance
1099
- * @param options - Configuration options for the router
1055
+ * The subcommand group name for this subcommand.
1100
1056
  */
1101
- constructor(options: CommandsRouterOptions);
1057
+ group: string | null;
1102
1058
  /**
1103
- * Gets the configured entrypoint directory
1059
+ * The middlewares of this subcommand.
1104
1060
  */
1105
- get entrypoint(): string;
1061
+ middlewares: string[];
1062
+ }
1063
+ interface ParsedMiddleware {
1106
1064
  /**
1107
- * Gets the configured matchers for command and middleware files
1065
+ * The file name without the extension.
1108
1066
  */
1109
- get matchers(): CommandsRouterMatchersMap;
1067
+ name: string;
1110
1068
  /**
1111
- * Returns the cached data of the commands and middleware
1069
+ * The unique identifier of this middleware.
1112
1070
  */
1113
- getData(): {
1114
- commands: Map<string, ParsedCommand>;
1115
- middleware: Map<string, ParsedMiddleware>;
1116
- };
1071
+ id: string;
1117
1072
  /**
1118
- * Checks if the entrypoint path is valid
1073
+ * The full path to this middleware file.
1119
1074
  */
1120
- isValidPath(): boolean;
1075
+ path: string;
1121
1076
  /**
1122
- * Executes a matcher against a file path
1123
- * @param matcher - The matcher to use
1124
- * @param path - The file path to test
1125
- * @returns boolean indicating if the path matches
1077
+ * The category of this middleware.
1126
1078
  */
1127
- private execMatcher;
1079
+ category: string | null;
1080
+ }
1081
+ interface CommandsTree {
1128
1082
  /**
1129
- * Converts an absolute path to a path relative to the entrypoint
1130
- * @param path - The absolute path to convert
1083
+ * The record of commands mapped by their unique identifiers.
1131
1084
  */
1132
- private resolveRelativePath;
1085
+ commands: Record<string, ParsedCommand>;
1133
1086
  /**
1134
- * Matches a command by name or path segments
1135
- * @param commandOrSegment - Command name or array of path segments
1136
- * @returns Matched command and its middlewares, or null if no match
1087
+ * The record of subcommands mapped by their unique identifiers.
1137
1088
  */
1138
- match(commandOrSegment: string | string[]): CommandMatchResult | null;
1089
+ subcommands: Record<string, ParsedSubCommand>;
1139
1090
  /**
1140
- * Reloads the commands tree by re-scanning the entrypoint directory
1091
+ * The record of middlewares mapped by their unique identifiers.
1141
1092
  */
1142
- reload(): Promise<CommandsTree>;
1093
+ middlewares: Record<string, ParsedMiddleware>;
1094
+ }
1095
+ interface ParsedCommandsData {
1143
1096
  /**
1144
- * Clears the internal commands and middleware maps
1097
+ * The collection of parsed commands.
1145
1098
  */
1146
- clear(): void;
1099
+ commands: Collection<string, ParsedCommand>;
1147
1100
  /**
1148
- * Scans the entrypoint directory for commands and middleware
1149
- * @returns Promise resolving to the complete commands tree
1101
+ * The collection of parsed subcommands.
1150
1102
  */
1151
- scan(): Promise<CommandsTree>;
1103
+ subcommands: Collection<string, ParsedSubCommand>;
1152
1104
  /**
1153
- * Converts the internal maps to a serializable object
1154
- * @returns CommandsTree containing all commands and middleware
1105
+ * The collection of parsed middlewares.
1155
1106
  */
1156
- toJSON(): CommandsTree;
1107
+ middlewares: Collection<string, ParsedMiddleware>;
1108
+ }
1109
+ interface CommandsRouterOptions {
1157
1110
  /**
1158
- * Recursively scans a directory for files
1159
- * @param dir - Directory to scan
1160
- * @param entries - Accumulator for found files
1161
- * @returns Promise resolving to array of file paths
1111
+ * The entrypoint directory to scan for commands.
1162
1112
  */
1113
+ entrypoint: string;
1114
+ }
1115
+ declare class CommandsRouter {
1116
+ private readonly options;
1117
+ private commands;
1118
+ private subcommands;
1119
+ private middlewares;
1120
+ constructor(options: CommandsRouterOptions);
1121
+ get entrypoint(): string;
1122
+ isValidPath(): boolean;
1123
+ getData(): ParsedCommandsData;
1124
+ toJSON(): CommandsTree;
1125
+ clear(): void;
1126
+ reload(): Promise<CommandsTree>;
1127
+ scan(): Promise<CommandsTree>;
1163
1128
  private scanDirectory;
1164
- private isIgnoredFile;
1165
- private isCommandFile;
1166
- private parseCategories;
1167
- private parseCommandPath;
1129
+ private processMiddlewares;
1130
+ private processCommand;
1131
+ private processCommandDirectory;
1132
+ private processSubCommand;
1133
+ private parseNameAndCategory;
1134
+ private findAssociatedMiddlewares;
1168
1135
  }
1169
1136
 
1170
1137
  /**
@@ -1261,6 +1228,10 @@ declare class CommandRegistrar {
1261
1228
  * Gets the commands data.
1262
1229
  */
1263
1230
  getCommandsData(): CommandData[];
1231
+ /**
1232
+ * Process and merge subcommands into the parent command's options
1233
+ */
1234
+ private processSubcommands;
1264
1235
  /**
1265
1236
  * Registers loaded commands.
1266
1237
  */
@@ -1290,6 +1261,7 @@ interface AppCommandMiddleware {
1290
1261
  interface LoadedCommand {
1291
1262
  command: ParsedCommand;
1292
1263
  data: AppCommand;
1264
+ subcommands?: ParsedSubCommand[];
1293
1265
  guilds?: string[];
1294
1266
  }
1295
1267
  interface LoadedMiddleware {
@@ -1298,26 +1270,41 @@ interface LoadedMiddleware {
1298
1270
  }
1299
1271
  interface PreparedAppCommandExecution {
1300
1272
  command: LoadedCommand;
1273
+ subcommand?: LoadedSubCommand | null;
1301
1274
  middlewares: LoadedMiddleware[];
1302
1275
  messageCommandParser?: MessageCommandParser;
1303
1276
  }
1277
+ interface LoadedSubCommand {
1278
+ subcommand: ParsedSubCommand;
1279
+ data: AppCommand;
1280
+ }
1304
1281
  type CommandBuilderLike = SlashCommandBuilder | ContextMenuCommandBuilder | Record<string, any>;
1305
1282
  declare class AppCommandHandler {
1306
1283
  readonly commandkit: CommandKit;
1307
1284
  private loadedCommands;
1285
+ private loadedSubCommands;
1308
1286
  private loadedMiddlewares;
1287
+ private commandNameToId;
1288
+ private subcommandPathToId;
1309
1289
  readonly registrar: CommandRegistrar;
1310
1290
  private onInteraction;
1311
1291
  private onMessageCreate;
1312
1292
  private onMessageUpdate;
1313
1293
  constructor(commandkit: CommandKit);
1314
1294
  getCommandsArray(): LoadedCommand[];
1295
+ /**
1296
+ * Get subcommand data by ID for the command registrar
1297
+ */
1298
+ getSubcommandData(id: string): any;
1315
1299
  registerCommandHandler(): void;
1316
1300
  getExecutionMode(source: Interaction | Message$1): CommandExecutionMode;
1317
- runCommand(command: PreparedAppCommandExecution, source: Interaction | Message$1): Promise<void>;
1301
+ runCommand(prepared: PreparedAppCommandExecution, source: Interaction | Message$1): Promise<void>;
1318
1302
  prepareCommandRun(source: Interaction | Message$1): Promise<PreparedAppCommandExecution | null>;
1319
1303
  reloadCommands(): Promise<void>;
1320
1304
  loadCommands(): Promise<void>;
1305
+ private loadMiddleware;
1306
+ private loadCommand;
1307
+ private loadSubcommand;
1321
1308
  applyLocalizations(command: CommandBuilderLike): Promise<discord_js.RESTPostAPIContextMenuApplicationCommandsJSONBody | CommandBuilderLike>;
1322
1309
  }
1323
1310
 
@@ -1965,4 +1952,4 @@ declare const version: string;
1965
1952
  */
1966
1953
  declare function bootstrapCommandkitCLI(argv: string[], options?: commander.ParseOptions | undefined): Promise<void>;
1967
1954
 
1968
- export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, type AutocompleteProps, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, type CommandFileObject, CommandKit, type CommandKitButtonBuilderInteractionCollectorDispatch, type CommandKitButtonBuilderInteractionCollectorDispatchContextData, type CommandKitButtonBuilderOnEnd, type CommandKitConfiguration, type CommandKitElement, type CommandKitElementData, CommandKitEnvironment, type CommandKitEnvironmentInternalData, CommandKitEnvironmentType, type CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandMatchResult, type CommandObject, type CommandOptions, type CommandProps, CommandsRouter, type CommandsRouterMatcher, type CommandsRouterMatchersMap, type CommandsRouterOptions, type CommandsTree, Context, type ContextMenuCommandProps, type ContextParameters, DefaultLocalizationStrategy, DefaultLogger, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, EventsRouter, type EventsRouterOptions, type EventsTree, Fragment, type FragmentElementProps, type GenericFunction, type ILogger, type InteractionCommandContext, type InteractionCommandMiddlewareContext, type LoadedCommand, Localization, type LocalizationConfig, type LocalizationStrategy, type LocalizationTranslationRequest, Logger, type LoggerImpl, type MaybeArray, MemoryCache, type MessageCommand, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommand, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type MessageContextMenuCommandProps, MiddlewareContext, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnModalKitEnd, type OnModalKitSubmit, ParagraphInput, type ParsedCommand, type ParsedEvent, type ParsedMessageCommand, type ParsedMiddleware, type PreparedAppCommandExecution, type ReloadOptions, ReloadType, ShortInput, type SlashCommand, type SlashCommandContext, type SlashCommandMiddlewareContext, type SlashCommandProps, TextInput, type TextInputProps, type TranslatableArguments, type TranslatableCommand, type TranslatableCommandOptions, type Translation, type TranslationResult, type Translator, type UserContextMenuCommand, type UserContextMenuCommandContext, type UserContextMenuCommandMiddlewareContext, type UserContextMenuCommandProps, type ValidationProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, createElement, createLogger, CommandKit as default, defineConfig, dmOnly, exitContext, exitMiddleware, getCommandKit, getConfig, getContext, getElement, guildOnly, invalidate, isCachedFunction, isCommandKitElement, makeContextAwareFunction, redirect, rethrow, revalidate, useCache as super_duper_secret_internal_for_use_cache_directive_of_commandkit_cli_do_not_use_it_directly_or_you_will_be_fired_from_your_job_kthxbai, useEnvironment, version };
1955
+ export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, type AutocompleteProps, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, type CommandFileObject, CommandKit, type CommandKitButtonBuilderInteractionCollectorDispatch, type CommandKitButtonBuilderInteractionCollectorDispatchContextData, type CommandKitButtonBuilderOnEnd, type CommandKitConfiguration, type CommandKitElement, type CommandKitElementData, CommandKitEnvironment, type CommandKitEnvironmentInternalData, CommandKitEnvironmentType, type CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandObject, type CommandOptions, type CommandProps, CommandsRouter, type CommandsRouterOptions, type CommandsTree, Context, type ContextMenuCommandProps, type ContextParameters, DefaultLocalizationStrategy, DefaultLogger, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, EventsRouter, type EventsRouterOptions, type EventsTree, Fragment, type FragmentElementProps, type GenericFunction, type ILogger, type InteractionCommandContext, type InteractionCommandMiddlewareContext, type LoadedCommand, Localization, type LocalizationConfig, type LocalizationStrategy, type LocalizationTranslationRequest, Logger, type LoggerImpl, type MaybeArray, MemoryCache, type MessageCommand, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommand, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type MessageContextMenuCommandProps, MiddlewareContext, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnModalKitEnd, type OnModalKitSubmit, ParagraphInput, type ParsedCommand, type ParsedCommandsData, type ParsedEvent, type ParsedMessageCommand, type ParsedMiddleware, type ParsedSubCommand, type PreparedAppCommandExecution, type ReloadOptions, ReloadType, ShortInput, type SlashCommand, type SlashCommandContext, type SlashCommandMiddlewareContext, type SlashCommandProps, TextInput, type TextInputProps, type TranslatableArguments, type TranslatableCommand, type TranslatableCommandOptions, type Translation, type TranslationResult, type Translator, type UserContextMenuCommand, type UserContextMenuCommandContext, type UserContextMenuCommandMiddlewareContext, type UserContextMenuCommandProps, type ValidationProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, createElement, createLogger, CommandKit as default, defineConfig, dmOnly, exitContext, exitMiddleware, getCommandKit, getConfig, getContext, getElement, guildOnly, invalidate, isCachedFunction, isCommandKitElement, makeContextAwareFunction, redirect, rethrow, revalidate, useCache as super_duper_secret_internal_for_use_cache_directive_of_commandkit_cli_do_not_use_it_directly_or_you_will_be_fired_from_your_job_kthxbai, useEnvironment, version };