commandkit 1.0.0-dev.20250511124349 → 1.0.0-dev.20250512141520
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 +26 -156
- package/dist/index.js +33 -354
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,22 +2,10 @@ import * as discord_js from 'discord.js';
|
|
|
2
2
|
import { RESTPostAPIApplicationCommandsJSONBody, Client, Interaction, CacheType, ClientEvents, Awaitable, ButtonBuilder, ButtonInteraction, Events, ModalBuilder, ModalSubmitInteraction, ActionRowBuilder, TextInputBuilder, ButtonStyle, ComponentEmojiResolvable, TextInputStyle, StringSelectMenuInteraction, StringSelectMenuBuilder, ChannelSelectMenuInteraction, ChannelSelectMenuBuilder, MentionableSelectMenuInteraction, MentionableSelectMenuBuilder, UserSelectMenuInteraction, UserSelectMenuBuilder, RoleSelectMenuInteraction, RoleSelectMenuBuilder, BaseSelectMenuComponentData, StringSelectMenuOptionBuilder, SelectMenuComponentOptionData, APISelectMenuOption, UserSelectMenuComponentData, RoleSelectMenuComponentData, MentionableSelectMenuComponentData, ChannelSelectMenuComponentData, ContainerComponentData, ComponentBuilder, ContainerBuilder, FileComponentData, FileBuilder, MediaGalleryItemBuilder, MediaGalleryBuilder, ThumbnailBuilder, TextDisplayBuilder, SectionBuilder, SeparatorComponentData, SeparatorBuilder, TextDisplayComponentData, Message as Message$1, ApplicationCommandOptionType, GuildMember, Attachment, User, Role, CommandInteractionOption, ChatInputCommandInteraction, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, AutocompleteInteraction, Guild, TextBasedChannel, Locale, Collection, SlashCommandBuilder, ContextMenuCommandBuilder } from 'discord.js';
|
|
3
3
|
import EventEmitter from 'node:events';
|
|
4
4
|
import { Channel } from 'diagnostics_channel';
|
|
5
|
+
import { DirectiveTransformerOptions } from 'directive-to-hof';
|
|
5
6
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
7
|
import * as commander from 'commander';
|
|
7
8
|
|
|
8
|
-
interface CacheEntry<T = unknown> {
|
|
9
|
-
value: T;
|
|
10
|
-
ttl?: number;
|
|
11
|
-
}
|
|
12
|
-
declare abstract class CacheProvider {
|
|
13
|
-
abstract get<T>(key: string): Promise<CacheEntry<T> | undefined>;
|
|
14
|
-
abstract set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
15
|
-
abstract exists(key: string): Promise<boolean>;
|
|
16
|
-
abstract delete(key: string): Promise<void>;
|
|
17
|
-
abstract clear(): Promise<void>;
|
|
18
|
-
abstract expire(key: string, ttl: number): Promise<void>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
9
|
/**
|
|
22
10
|
* Options for instantiating a CommandKit handler.
|
|
23
11
|
*/
|
|
@@ -26,11 +14,6 @@ interface CommandKitOptions {
|
|
|
26
14
|
* The Discord.js client object to use with CommandKit.
|
|
27
15
|
*/
|
|
28
16
|
client: Client;
|
|
29
|
-
/**
|
|
30
|
-
* The cache provider to use with CommandKit. Defaults to MemoryCache provider.
|
|
31
|
-
* Set this to `null` to not use any cache provider.
|
|
32
|
-
*/
|
|
33
|
-
cacheProvider?: CacheProvider | null;
|
|
34
17
|
}
|
|
35
18
|
/**
|
|
36
19
|
* Represents a command context.
|
|
@@ -730,6 +713,12 @@ declare class MessageCommandOptions {
|
|
|
730
713
|
}
|
|
731
714
|
|
|
732
715
|
type GenericFunction<A extends any[] = any[]> = (...args: A) => any;
|
|
716
|
+
/**
|
|
717
|
+
* Represents an async function that can be cached
|
|
718
|
+
* @template R - Array of argument types
|
|
719
|
+
* @template T - Return type
|
|
720
|
+
*/
|
|
721
|
+
type AsyncFunction<R extends any[] = any[], T = any> = (...args: R) => Promise<T>;
|
|
733
722
|
declare function exitContext<T>(fn: () => T): T;
|
|
734
723
|
declare function provideContext<R>(value: CommandKitEnvironment, receiver: () => R): R;
|
|
735
724
|
/**
|
|
@@ -1109,124 +1098,6 @@ declare class MiddlewareContext<T extends CommandExecutionMode = CommandExecutio
|
|
|
1109
1098
|
setCommandRunner(fn: RunCommand): void;
|
|
1110
1099
|
}
|
|
1111
1100
|
|
|
1112
|
-
declare class MemoryCache extends CacheProvider {
|
|
1113
|
-
#private;
|
|
1114
|
-
get<T>(key: string): Promise<CacheEntry<T> | undefined>;
|
|
1115
|
-
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
1116
|
-
exists(key: string): Promise<boolean>;
|
|
1117
|
-
delete(key: string): Promise<void>;
|
|
1118
|
-
clear(): Promise<void>;
|
|
1119
|
-
expire(key: string, ttl: number): Promise<void>;
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
/**
|
|
1123
|
-
* Context for managing cache operations within an async scope
|
|
1124
|
-
*/
|
|
1125
|
-
interface CacheContext {
|
|
1126
|
-
params: {
|
|
1127
|
-
/** Custom name for the cache entry */
|
|
1128
|
-
name?: string;
|
|
1129
|
-
/** Time-to-live in milliseconds */
|
|
1130
|
-
ttl?: number;
|
|
1131
|
-
};
|
|
1132
|
-
}
|
|
1133
|
-
/**
|
|
1134
|
-
* Represents an async function that can be cached
|
|
1135
|
-
* @template R - Array of argument types
|
|
1136
|
-
* @template T - Return type
|
|
1137
|
-
*/
|
|
1138
|
-
type AsyncFunction<R extends any[] = any[], T = any> = (...args: R) => Promise<T>;
|
|
1139
|
-
/**
|
|
1140
|
-
* Configuration options for cache behavior
|
|
1141
|
-
*/
|
|
1142
|
-
interface CacheMetadata {
|
|
1143
|
-
/** Time-to-live duration in milliseconds or as a string (e.g., '1h', '5m') */
|
|
1144
|
-
ttl?: number | string;
|
|
1145
|
-
/** Custom name for the cache entry */
|
|
1146
|
-
name?: string;
|
|
1147
|
-
}
|
|
1148
|
-
/**
|
|
1149
|
-
* Wraps an async function with caching capability
|
|
1150
|
-
* @template R - Array of argument types
|
|
1151
|
-
* @template F - Type of the async function
|
|
1152
|
-
* @param fn - The async function to cache
|
|
1153
|
-
* @param params - Optional cache configuration
|
|
1154
|
-
* @returns The wrapped function with caching behavior
|
|
1155
|
-
* @example
|
|
1156
|
-
* ```ts
|
|
1157
|
-
* const cachedFetch = cache(async (id: string) => {
|
|
1158
|
-
* return await db.findOne(id);
|
|
1159
|
-
* }, { ttl: '1h' });
|
|
1160
|
-
* ```
|
|
1161
|
-
*/
|
|
1162
|
-
declare function cache<R extends any[], F extends AsyncFunction<R>>(fn: F, params?: CacheMetadata): F;
|
|
1163
|
-
/**
|
|
1164
|
-
* Sets a custom identifier for the current cache operation
|
|
1165
|
-
* @param tag - The custom cache tag
|
|
1166
|
-
* @throws {Error} When called outside a cached function or without a tag
|
|
1167
|
-
* @example
|
|
1168
|
-
* ```ts
|
|
1169
|
-
* const fetchUser = cache(async (id: string) => {
|
|
1170
|
-
* cacheTag(`user:${id}`);
|
|
1171
|
-
* return await db.users.findOne(id);
|
|
1172
|
-
* });
|
|
1173
|
-
* ```
|
|
1174
|
-
*/
|
|
1175
|
-
declare function cacheTag(tag: string): void;
|
|
1176
|
-
/**
|
|
1177
|
-
* Sets the TTL for the current cache operation
|
|
1178
|
-
* @param ttl - Time-to-live in milliseconds or as a string (e.g., '1h', '5m')
|
|
1179
|
-
* @throws {Error} When called outside a cached function or with invalid TTL
|
|
1180
|
-
* @example
|
|
1181
|
-
* ```ts
|
|
1182
|
-
* const fetchData = cache(async () => {
|
|
1183
|
-
* cacheLife('30m');
|
|
1184
|
-
* return await expensiveOperation();
|
|
1185
|
-
* });
|
|
1186
|
-
* ```
|
|
1187
|
-
*/
|
|
1188
|
-
declare function cacheLife(ttl: number | string): void;
|
|
1189
|
-
/**
|
|
1190
|
-
* Removes a cached value by its tag
|
|
1191
|
-
* @param tag - The cache tag to invalidate
|
|
1192
|
-
* @throws {Error} When the cache key is not found
|
|
1193
|
-
* @example
|
|
1194
|
-
* ```ts
|
|
1195
|
-
* await invalidate('user:123');
|
|
1196
|
-
* ```
|
|
1197
|
-
*/
|
|
1198
|
-
declare function invalidate(tag: string): Promise<void>;
|
|
1199
|
-
/**
|
|
1200
|
-
* Forces a refresh of cached data by its tag (on-demand revalidation)
|
|
1201
|
-
* @template T - Type of the cached value
|
|
1202
|
-
* @param tag - The cache tag to revalidate
|
|
1203
|
-
* @param args - Arguments to pass to the cached function
|
|
1204
|
-
* @returns Fresh data from the cached function
|
|
1205
|
-
* @throws {Error} When the cache key or function is not found
|
|
1206
|
-
* @example
|
|
1207
|
-
* ```ts
|
|
1208
|
-
* const freshData = await revalidate('user:123');
|
|
1209
|
-
* ```
|
|
1210
|
-
*/
|
|
1211
|
-
declare function revalidate<T = unknown>(tag: string, ...args: any[]): Promise<T>;
|
|
1212
|
-
/**
|
|
1213
|
-
* Checks if a function is wrapped with cache functionality
|
|
1214
|
-
* @param fn - Function to check
|
|
1215
|
-
* @returns True if the function is cached
|
|
1216
|
-
* @example
|
|
1217
|
-
* ```ts
|
|
1218
|
-
* if (isCachedFunction(myFunction)) {
|
|
1219
|
-
* console.log('Function is cached');
|
|
1220
|
-
* }
|
|
1221
|
-
* ```
|
|
1222
|
-
*/
|
|
1223
|
-
declare function isCachedFunction(fn: GenericFunction): boolean;
|
|
1224
|
-
/**
|
|
1225
|
-
* @private
|
|
1226
|
-
* @internal
|
|
1227
|
-
*/
|
|
1228
|
-
declare const __SECRET_USE_CACHE_INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: any;
|
|
1229
|
-
|
|
1230
1101
|
interface Command {
|
|
1231
1102
|
id: string;
|
|
1232
1103
|
name: string;
|
|
@@ -1573,6 +1444,7 @@ interface CommandKitHMREvent {
|
|
|
1573
1444
|
}
|
|
1574
1445
|
|
|
1575
1446
|
declare abstract class RuntimePlugin<T extends PluginOptions = PluginOptions> extends PluginCommon<T, CommandKitPluginRuntime> {
|
|
1447
|
+
readonly type = PluginType.Runtime;
|
|
1576
1448
|
/**
|
|
1577
1449
|
* Called before commands are loaded
|
|
1578
1450
|
*/
|
|
@@ -1690,6 +1562,7 @@ interface ResolveResult {
|
|
|
1690
1562
|
external?: boolean;
|
|
1691
1563
|
}
|
|
1692
1564
|
declare abstract class CompilerPlugin<T extends PluginOptions = PluginOptions> extends PluginCommon<T, CompilerPluginRuntime> {
|
|
1565
|
+
readonly type = PluginType.Compiler;
|
|
1693
1566
|
/**
|
|
1694
1567
|
* Called when transformation is requested to this plugin
|
|
1695
1568
|
* @param params The parameters for the transformation
|
|
@@ -1713,6 +1586,16 @@ declare abstract class CompilerPlugin<T extends PluginOptions = PluginOptions> e
|
|
|
1713
1586
|
}
|
|
1714
1587
|
declare function isCompilerPlugin(plugin: unknown): plugin is CompilerPlugin;
|
|
1715
1588
|
|
|
1589
|
+
type CommonDirectiveTransformerOptions = DirectiveTransformerOptions & {
|
|
1590
|
+
enabled?: boolean;
|
|
1591
|
+
};
|
|
1592
|
+
declare abstract class CommonDirectiveTransformer extends CompilerPlugin<CommonDirectiveTransformerOptions> {
|
|
1593
|
+
private transformer;
|
|
1594
|
+
activate(ctx: CompilerPluginRuntime): Promise<void>;
|
|
1595
|
+
deactivate(ctx: CompilerPluginRuntime): Promise<void>;
|
|
1596
|
+
transform(params: PluginTransformParameters): Promise<MaybeFalsey<TransformedResult>>;
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1716
1599
|
declare class CompilerPluginRuntime {
|
|
1717
1600
|
private readonly plugins;
|
|
1718
1601
|
readonly name = "CompilerPluginRuntime";
|
|
@@ -1737,8 +1620,13 @@ declare function fromEsbuildPlugin(plugin: any): typeof CompilerPlugin;
|
|
|
1737
1620
|
type CommonPluginRuntime = CommandKitPluginRuntime | CompilerPluginRuntime;
|
|
1738
1621
|
|
|
1739
1622
|
type PluginOptions = Record<string, any>;
|
|
1623
|
+
declare enum PluginType {
|
|
1624
|
+
Compiler = "compiler",
|
|
1625
|
+
Runtime = "runtime"
|
|
1626
|
+
}
|
|
1740
1627
|
declare abstract class PluginCommon<T extends PluginOptions = PluginOptions, C extends CommonPluginRuntime = CommonPluginRuntime> {
|
|
1741
1628
|
protected readonly options: T;
|
|
1629
|
+
abstract readonly type: PluginType;
|
|
1742
1630
|
readonly id: `${string}-${string}-${string}-${string}-${string}`;
|
|
1743
1631
|
readonly loadedAt: number;
|
|
1744
1632
|
abstract readonly name: string;
|
|
@@ -1846,15 +1734,6 @@ declare class CommandKit extends EventEmitter {
|
|
|
1846
1734
|
* @param locale The default locale.
|
|
1847
1735
|
*/
|
|
1848
1736
|
setDefaultLocale(locale: Locale): this;
|
|
1849
|
-
/**
|
|
1850
|
-
* Sets the cache provider.
|
|
1851
|
-
* @param provider The cache provider.
|
|
1852
|
-
*/
|
|
1853
|
-
setCacheProvider(provider: CacheProvider): this;
|
|
1854
|
-
/**
|
|
1855
|
-
* Resolves the current cache provider.
|
|
1856
|
-
*/
|
|
1857
|
-
getCacheProvider(): CacheProvider | null;
|
|
1858
1737
|
/**
|
|
1859
1738
|
* Get the client attached to this CommandKit instance.
|
|
1860
1739
|
*/
|
|
@@ -1889,7 +1768,7 @@ interface CommandKitConfig {
|
|
|
1889
1768
|
/**
|
|
1890
1769
|
* The plugins to use with CommandKit.
|
|
1891
1770
|
*/
|
|
1892
|
-
plugins?:
|
|
1771
|
+
plugins?: CommandKitPlugin[] | Array<CommandKitPlugin[]>;
|
|
1893
1772
|
/**
|
|
1894
1773
|
* The esbuild plugins to use with CommandKit.
|
|
1895
1774
|
*/
|
|
@@ -1908,15 +1787,6 @@ interface CommandKitConfig {
|
|
|
1908
1787
|
*/
|
|
1909
1788
|
development?: boolean;
|
|
1910
1789
|
};
|
|
1911
|
-
/**
|
|
1912
|
-
* Cached function compiler configuration.
|
|
1913
|
-
*/
|
|
1914
|
-
cache?: {
|
|
1915
|
-
/**
|
|
1916
|
-
* Whether to enable caching of compiled functions in development mode.
|
|
1917
|
-
*/
|
|
1918
|
-
development?: boolean;
|
|
1919
|
-
};
|
|
1920
1790
|
};
|
|
1921
1791
|
/**
|
|
1922
1792
|
* The typescript configuration to use with CommandKit.
|
|
@@ -2076,4 +1946,4 @@ declare function getEventWorkerContext(): EventWorkerContext;
|
|
|
2076
1946
|
*/
|
|
2077
1947
|
declare function bootstrapCommandkitCLI(argv: string[], options?: commander.ParseOptions | undefined): Promise<void>;
|
|
2078
1948
|
|
|
2079
|
-
export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, type BootstrapFunction, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, COMMANDKIT_BOOTSTRAP_MODE, COMMANDKIT_CACHE_TAG, COMMANDKIT_IS_DEV, COMMANDKIT_IS_TEST,
|
|
1949
|
+
export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, type BootstrapFunction, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, COMMANDKIT_BOOTSTRAP_MODE, COMMANDKIT_CACHE_TAG, COMMANDKIT_IS_DEV, COMMANDKIT_IS_TEST, ChannelSelectMenu, ChannelSelectMenuKit, type ChannelSelectMenuKitPredicate, type ChannelSelectMenuProps, type ChatInputCommand, type ChatInputCommandContext, type Command, type CommandBuilderLike, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, CommandKit, type CommandKitButtonBuilderInteractionCollectorDispatch, type CommandKitButtonBuilderInteractionCollectorDispatchContextData, type CommandKitButtonBuilderOnEnd, type CommandKitConfiguration, type CommandKitElement, type CommandKitElementData, CommandKitEnvironment, type CommandKitEnvironmentInternalData, CommandKitEnvironmentType, type CommandKitHMREvent, type CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandKitPlugin, CommandKitPluginRuntime, type CommandKitSelectMenuBuilderInteractionCollectorDispatch, type CommandKitSelectMenuBuilderInteractionCollectorDispatchContextData, type CommandKitSelectMenuBuilderOnEnd, CommandRegistrar, type CommandSource, type CommandTypeData, CommandsRouter, type CommandsRouterOptions, type CommonBuilderKit, CommonDirectiveTransformer, type CommonDirectiveTransformerOptions, type CommonPluginRuntime, type CommonSelectMenuProps, CompilerPlugin, CompilerPluginRuntime, Container, type ContainerProps, Context, type ContextParameters, DefaultLogger, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, type EventWorkerContext, EventsRouter, type EventsRouterOptions, type EventsTree, File, type FileProps, Fragment, type FragmentElementProps, type GenericFunction, HMREventType, type ILogger, type InteractionCommandContext, type InteractionCommandMiddlewareContext, type LoadedCommand, type Loader, type Location, Logger, type LoggerImpl, type MaybeArray, type MaybeFalsey, MediaGallery, MediaGalleryItem, type MediaGalleryItemProps, type MediaGalleryProps, MentionableSelectMenu, MentionableSelectMenuKit, type MentionableSelectMenuKitPredicate, type MentionableSelectMenuProps, type Message, type MessageCommand, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommand, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type Middleware, MiddlewareContext, type MiddlewareContextArgs, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnChannelSelectMenuKitSubmit, type OnLoadArgs, type OnLoadOptions, type OnLoadResult, type OnMentionableSelectMenuKitSubmit, type OnModalKitEnd, type OnModalKitSubmit, type OnResolveArgs, type OnResolveOptions, type OnResolveResult, type OnRoleSelectMenuKitSubmit, type OnSelectMenuKitEnd, type OnSelectMenuKitSubmit, type OnStringSelectMenuKitSubmit, type OnUserSelectMenuKitSubmit, ParagraphInput, type ParsedCommandData, type ParsedEvent, type ParsedMessageCommand, type PluginTransformParameters, type PreRegisterCommandsEvent, type PreparedAppCommandExecution, type ResolvableCommand, type ResolveBuilderInteraction, type ResolveKind, type ResolveResult, RoleSelectMenu, RoleSelectMenuKit, type RoleSelectMenuKitPredicate, type RoleSelectMenuProps, type RunCommand, RuntimePlugin, Section, type SectionProps, type SelectMenuKitPredicate, type SelectMenuProps, Separator, type SeparatorProps, type Setup, ShortInput, type SlashCommandMiddlewareContext, StopEventPropagationError, StringSelectMenu, StringSelectMenuKit, type StringSelectMenuKitPredicate, StringSelectMenuOption, type StringSelectMenuOptionProps, type StringSelectMenuProps, TextDisplay, type TextDisplayProps, TextInput, type TextInputProps, Thumbnail, type ThumbnailProps, type TransformedResult, type UserContextMenuCommand, type UserContextMenuCommandContext, type UserContextMenuCommandMiddlewareContext, UserSelectMenu, UserSelectMenuKit, type UserSelectMenuKitPredicate, type UserSelectMenuProps, after, bootstrapCommandkitCLI, cancelAfter, commandkit, createElement, createLogger, debounce, CommandKit as default, defineConfig, devOnly, eventWorkerContext, exitContext, exitMiddleware, fromEsbuildPlugin, getCommandKit, getConfig, getContext, getCurrentDirectory, getElement, getEventWorkerContext, getSourceDirectories, isCommandKitElement, isCompilerPlugin, isInteractionSource, isMessageSource, isRuntimePlugin, makeContextAwareFunction, onApplicationBootstrap, onBootstrap, provideContext, redirect, rethrow, runInEventWorkerContext, stopEvents, useEnvironment, version };
|