commandkit 0.1.11-dev.20250214040728 → 0.1.11-dev.20250215105847

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
@@ -1187,6 +1187,7 @@ interface ContextParameters<T extends CommandExecutionMode> {
1187
1187
  message: T extends 'message' ? Message : never;
1188
1188
  forwarded?: boolean;
1189
1189
  messageCommandParser?: T extends 'message' ? MessageCommandParser : never;
1190
+ store?: Map<string, any>;
1190
1191
  }
1191
1192
  type MessageCommandContext = Context<'message'>;
1192
1193
  type InteractionCommandContext = Context<'autocomplete' | 'chatInput' | 'messageContextMenu' | 'userContextMenu'>;
@@ -1202,6 +1203,7 @@ type UserContextMenuCommandContext = Context<'userContextMenu'>;
1202
1203
  type UserContextMenuCommandMiddlewareContext = MiddlewareContext<'userContextMenu'>;
1203
1204
  type CommandContextOptions<T extends CommandExecutionMode> = T extends 'message' ? MessageCommandOptions : T extends 'chatInput' ? ChatInputCommandInteraction['options'] : T extends 'autocomplete' ? AutocompleteInteraction['options'] : T extends 'messageContextMenu' ? MessageContextMenuCommandInteraction['options'] : T extends 'userContextMenu' ? UserContextMenuCommandInteraction['options'] : never;
1204
1205
  declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecutionMode> {
1206
+ #private;
1205
1207
  readonly commandkit: CommandKit;
1206
1208
  private readonly config;
1207
1209
  /**
@@ -1219,6 +1221,11 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
1219
1221
  * @param config The context parameters.
1220
1222
  */
1221
1223
  constructor(commandkit: CommandKit, config: ContextParameters<ExecutionMode>);
1224
+ /**
1225
+ * The shared key-value store for this context. This can be used to store data that needs to be shared between middlewares or commands.
1226
+ * This store is shared across all contexts in the same command execution, including the cloned contexts and middleware contexts.
1227
+ */
1228
+ get store(): Map<string, any>;
1222
1229
  get commandName(): string;
1223
1230
  get options(): CommandContextOptions<ExecutionMode>;
1224
1231
  /**
@@ -1292,6 +1299,29 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
1292
1299
  clone(config?: Partial<ContextParameters<ExecutionMode>>): Context<ExecutionMode>;
1293
1300
  isMiddleware(): this is MiddlewareContext<ExecutionMode>;
1294
1301
  args(): string[];
1302
+ /**
1303
+ * Stops upcoming middleware or current command execution.
1304
+ * If this is called inside pre-stage middleware, the next run will be the actual command, skipping all other pre-stage middlewares.
1305
+ * If this is called inside a command itself, it will skip all post-stage middlewares.
1306
+ * If this is called inside post-stage middleware, it will skip all other post-stage middlewares.
1307
+ */
1308
+ exit(): void;
1309
+ /**
1310
+ * Defers the given function to be executed after this command's execution.
1311
+ * @param fn The function to defer.
1312
+ * @returns A unique identifier for the deferred function.
1313
+ */
1314
+ defer(fn: GenericFunction<[CommandKitEnvironment]>): string;
1315
+ /**
1316
+ * Cancels the deferred function with the given identifier.
1317
+ * @param id The identifier of the deferred function.
1318
+ */
1319
+ cancelDeferred(id: string): void;
1320
+ /**
1321
+ * Validates if the given function is a cached function.
1322
+ * @param fn The function to validate.
1323
+ */
1324
+ isCached(fn: GenericFunction): boolean;
1295
1325
  }
1296
1326
  declare class MiddlewareContext<T extends CommandExecutionMode = CommandExecutionMode> extends Context<T> {
1297
1327
  #private;
@@ -1364,6 +1394,15 @@ declare class CommandKit extends EventEmitter {
1364
1394
  * @see {@link https://commandkit.js.org/docs/guide/commandkit-setup}
1365
1395
  */
1366
1396
  constructor(options: CommandKitOptions);
1397
+ /**
1398
+ * Starts the commandkit application.
1399
+ * @param token The application token to connect to the discord gateway. If not provided, it will use the `TOKEN` or `DISCORD_TOKEN` environment variable. If set to `false`, it will not login.
1400
+ */
1401
+ start(token?: string | false): Promise<void>;
1402
+ /**
1403
+ * Whether or not the commandkit application has started.
1404
+ */
1405
+ get started(): boolean;
1367
1406
  /**
1368
1407
  * Sets the prefix resolver for the command handler.
1369
1408
  * @param resolver The resolver function.
@@ -1515,58 +1554,114 @@ declare class MemoryCache extends CacheProvider {
1515
1554
  expire(key: string, ttl: number): Promise<void>;
1516
1555
  }
1517
1556
 
1518
- type AsyncFunction<R extends any[] = any[], T = any> = (...args: R) => Promise<T>;
1519
- interface CacheTag {
1520
- tag: string;
1521
- ttl: number | string;
1522
- }
1523
- interface CacheParams extends CacheTag {
1524
- target: GenericFunction;
1525
- memo: GenericFunction;
1557
+ /**
1558
+ * Context for managing cache operations within an async scope
1559
+ */
1560
+ interface CacheContext {
1561
+ params: {
1562
+ /** Custom name for the cache entry */
1563
+ name?: string;
1564
+ /** Time-to-live in milliseconds */
1565
+ ttl?: number;
1566
+ };
1526
1567
  }
1527
1568
  /**
1528
- * Cache a function with a specific tag and time-to-live.
1529
- * @param fn The function to cache.
1530
- * @param params The cache tag and time-to-live.
1531
- * @returns The memoized function.
1569
+ * Represents an async function that can be cached
1570
+ * @template R - Array of argument types
1571
+ * @template T - Return type
1572
+ */
1573
+ type AsyncFunction<R extends any[] = any[], T = any> = (...args: R) => Promise<T>;
1574
+ /**
1575
+ * Configuration options for cache behavior
1532
1576
  */
1533
- declare function cache<R extends any[], F extends AsyncFunction<R>>(fn: F, params?: Partial<CacheTag>): F;
1577
+ interface CacheMetadata {
1578
+ /** Time-to-live duration in milliseconds or as a string (e.g., '1h', '5m') */
1579
+ ttl?: number | string;
1580
+ /** Custom name for the cache entry */
1581
+ name?: string;
1582
+ }
1534
1583
  /**
1535
- * **DO NOT USE THIS FUNCTION DIRECTLY**
1584
+ * Internal cache implementation
1536
1585
  * @internal
1537
1586
  * @private
1538
1587
  */
1539
- declare function useCache<R extends any[], F extends AsyncFunction<R>>(fn: F, id?: string, tag?: CacheTag): F;
1588
+ declare function useCache<R extends any[], F extends AsyncFunction<R>>(fn: F, id?: string, params?: CacheMetadata): F;
1540
1589
  /**
1541
- * Tags the current function with the given cache tag name
1542
- * @param tag The cache tag name.
1590
+ * Wraps an async function with caching capability
1591
+ * @template R - Array of argument types
1592
+ * @template F - Type of the async function
1593
+ * @param fn - The async function to cache
1594
+ * @param params - Optional cache configuration
1595
+ * @returns The wrapped function with caching behavior
1596
+ * @example
1597
+ * ```ts
1598
+ * const cachedFetch = cache(async (id: string) => {
1599
+ * return await db.findOne(id);
1600
+ * }, { ttl: '1h' });
1601
+ * ```
1543
1602
  */
1544
- declare function cacheTag(tag: string): void;
1603
+ declare function cache<R extends any[], F extends AsyncFunction<R>>(fn: F, params?: CacheMetadata): F;
1545
1604
  /**
1546
- * Tags the current function with the given cache tag parameters.
1547
- * @param tag The cache tag parameters.
1605
+ * Sets a custom identifier for the current cache operation
1606
+ * @param tag - The custom cache tag
1607
+ * @throws {Error} When called outside a cached function or without a tag
1608
+ * @example
1609
+ * ```ts
1610
+ * const fetchUser = cache(async (id: string) => {
1611
+ * cacheTag(`user:${id}`);
1612
+ * return await db.users.findOne(id);
1613
+ * });
1614
+ * ```
1548
1615
  */
1549
- declare function cacheTag(tag: CacheTag): void;
1616
+ declare function cacheTag(tag: string): void;
1550
1617
  /**
1551
- * Sets the time-to-live for the current cache tag.
1552
- * @param life The time-to-live value in milliseconds or a string.
1618
+ * Sets the TTL for the current cache operation
1619
+ * @param ttl - Time-to-live in milliseconds or as a string (e.g., '1h', '5m')
1620
+ * @throws {Error} When called outside a cached function or with invalid TTL
1621
+ * @example
1622
+ * ```ts
1623
+ * const fetchData = cache(async () => {
1624
+ * cacheLife('30m');
1625
+ * return await expensiveOperation();
1626
+ * });
1627
+ * ```
1553
1628
  */
1554
- declare function cacheLife(life: string): void;
1555
- declare function cacheLife(life: number): void;
1629
+ declare function cacheLife(ttl: number | string): void;
1556
1630
  /**
1557
- * Invalidates the cache with the given tag.
1558
- * This will immediately remove the cache entry. The next time cache is requested, it will be re-fetched.
1559
- * @param tag The cache tag to invalidate.
1631
+ * Removes a cached value by its tag
1632
+ * @param tag - The cache tag to invalidate
1633
+ * @throws {Error} When the cache key is not found
1634
+ * @example
1635
+ * ```ts
1636
+ * await invalidate('user:123');
1637
+ * ```
1560
1638
  */
1561
1639
  declare function invalidate(tag: string): Promise<void>;
1562
1640
  /**
1563
- * Revalidates the cache with the given tag.
1564
- * This will immediately remove the cache entry and re-fetch the value.
1565
- * @param tag The cache tag to revalidate.
1566
- * @param args The arguments to pass to the memoized function (if any).
1567
- * @returns The new value of the cache.
1641
+ * Forces a refresh of cached data by its tag (on-demand revalidation)
1642
+ * @template T - Type of the cached value
1643
+ * @param tag - The cache tag to revalidate
1644
+ * @param args - Arguments to pass to the cached function
1645
+ * @returns Fresh data from the cached function
1646
+ * @throws {Error} When the cache key or function is not found
1647
+ * @example
1648
+ * ```ts
1649
+ * const freshData = await revalidate('user:123');
1650
+ * ```
1568
1651
  */
1569
- declare function revalidate<R = any>(tag: string, ...args: any[]): Promise<R | undefined>;
1652
+ declare function revalidate<T = unknown>(tag: string, ...args: any[]): Promise<T>;
1653
+ /**
1654
+ * Checks if a function is wrapped with cache functionality
1655
+ * @param fn - Function to check
1656
+ * @returns True if the function is cached
1657
+ * @example
1658
+ * ```ts
1659
+ * if (isCachedFunction(myFunction)) {
1660
+ * console.log('Function is cached');
1661
+ * }
1662
+ * ```
1663
+ */
1664
+ declare function isCachedFunction(fn: GenericFunction): boolean;
1570
1665
 
1571
1666
  declare class DefaultLocalizationStrategy implements LocalizationStrategy {
1572
1667
  private readonly commandkit;
@@ -1591,6 +1686,53 @@ declare function exitMiddleware(): never;
1591
1686
  * @param error The error to rethrow.
1592
1687
  */
1593
1688
  declare function rethrow(error: unknown): void;
1689
+ /**
1690
+ * Stops current command assuming it has been redirected to another command.
1691
+ */
1692
+ declare function redirect(): never;
1693
+
1694
+ interface ILogger {
1695
+ log(...args: any[]): void;
1696
+ error(...args: any[]): void;
1697
+ warn(...args: any[]): void;
1698
+ info(...args: any[]): void;
1699
+ debug(...args: any[]): void;
1700
+ }
1701
+
1702
+ declare class DefaultLogger implements ILogger {
1703
+ stdout: NodeJS.WriteStream & {
1704
+ fd: 1;
1705
+ };
1706
+ stderr: NodeJS.WriteStream & {
1707
+ fd: 2;
1708
+ };
1709
+ private logger;
1710
+ constructor(stdout?: NodeJS.WriteStream & {
1711
+ fd: 1;
1712
+ }, stderr?: NodeJS.WriteStream & {
1713
+ fd: 2;
1714
+ });
1715
+ private _getContext;
1716
+ private _getPrefix;
1717
+ private _log;
1718
+ debug(...args: any[]): void;
1719
+ error(...args: any[]): void;
1720
+ log(...args: any[]): void;
1721
+ info(...args: any[]): void;
1722
+ warn(...args: any[]): void;
1723
+ }
1724
+
1725
+ interface CommandKitLoggerOptions {
1726
+ /**
1727
+ * The logger provider to use.
1728
+ */
1729
+ provider: ILogger;
1730
+ }
1731
+ interface LoggerImpl extends ILogger {
1732
+ configure(options: CommandKitLoggerOptions): void;
1733
+ }
1734
+ declare function createLogger(options: CommandKitLoggerOptions): LoggerImpl;
1735
+ declare const Logger: LoggerImpl;
1594
1736
 
1595
1737
  /**
1596
1738
  * Creates a command line interface for CommandKit.
@@ -1604,4 +1746,4 @@ declare function bootstrapCommandkitCLI(argv: string[], options?: commander.Pars
1604
1746
  */
1605
1747
  declare const version: string;
1606
1748
 
1607
- export { ActionRow, type ActionRowProps, type AnyCommandKitElement, AppCommandHandler, type AsyncFunction, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, type AutocompleteProps, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheEntry, type CacheParams, CacheProvider, type CacheTag, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, type CommandFileObject, CommandKit, type CommandKitButtonBuilderInteractionCollectorDispatch, type CommandKitButtonBuilderInteractionCollectorDispatchContextData, type CommandKitButtonBuilderOnEnd, type CommandKitConfig, type CommandKitConfiguration, type CommandKitData, type CommandKitElement, type CommandKitElementData, CommandKitEnvironment, type CommandKitEnvironmentInternalData, CommandKitEnvironmentType, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandObject, type CommandOptions, type CommandProps, Context, type ContextMenuCommandProps, type ContextParameters, DefaultLocalizationStrategy, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, Fragment, type FragmentElementProps, type GenericFunction, type InteractionCommandContext, type InteractionCommandMiddlewareContext, Localization, type LocalizationConfig, type LocalizationStrategy, type LocalizationTranslationRequest, type MaybeArray, MemoryCache, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type MessageContextMenuCommandProps, MiddlewareContext, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnModalKitEnd, type OnModalKitSubmit, ParagraphInput, type ParsedMessageCommand, type PreparedAppCommandExecution, type ReloadOptions, ReloadType, ShortInput, type SlashCommandContext, type SlashCommandMiddlewareContext, type SlashCommandProps, TextInput, type TextInputProps, type TranslatableArguments, type TranslatableCommand, type TranslatableCommandOptions, type Translation, type TranslationResult, type Translator, type UserContextMenuCommandContext, type UserContextMenuCommandMiddlewareContext, type UserContextMenuCommandProps, type ValidationProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, createElement, CommandKit as default, defineConfig, dmOnly, exitContext, exitMiddleware, getCommandKit, getConfig, getContext, getElement, guildOnly, invalidate, isCommandKitElement, makeContextAwareFunction, 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 };
1749
+ export { ActionRow, type ActionRowProps, type AnyCommandKitElement, AppCommandHandler, type AsyncFunction, 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 CommandKitConfig, type CommandKitConfiguration, type CommandKitData, 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, Localization, type LocalizationConfig, type LocalizationStrategy, type LocalizationTranslationRequest, Logger, type LoggerImpl, type MaybeArray, MemoryCache, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, 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 SlashCommandContext, type SlashCommandMiddlewareContext, type SlashCommandProps, TextInput, type TextInputProps, type TranslatableArguments, type TranslatableCommand, type TranslatableCommandOptions, type Translation, type TranslationResult, type Translator, 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 };
package/dist/index.d.ts CHANGED
@@ -1187,6 +1187,7 @@ interface ContextParameters<T extends CommandExecutionMode> {
1187
1187
  message: T extends 'message' ? Message : never;
1188
1188
  forwarded?: boolean;
1189
1189
  messageCommandParser?: T extends 'message' ? MessageCommandParser : never;
1190
+ store?: Map<string, any>;
1190
1191
  }
1191
1192
  type MessageCommandContext = Context<'message'>;
1192
1193
  type InteractionCommandContext = Context<'autocomplete' | 'chatInput' | 'messageContextMenu' | 'userContextMenu'>;
@@ -1202,6 +1203,7 @@ type UserContextMenuCommandContext = Context<'userContextMenu'>;
1202
1203
  type UserContextMenuCommandMiddlewareContext = MiddlewareContext<'userContextMenu'>;
1203
1204
  type CommandContextOptions<T extends CommandExecutionMode> = T extends 'message' ? MessageCommandOptions : T extends 'chatInput' ? ChatInputCommandInteraction['options'] : T extends 'autocomplete' ? AutocompleteInteraction['options'] : T extends 'messageContextMenu' ? MessageContextMenuCommandInteraction['options'] : T extends 'userContextMenu' ? UserContextMenuCommandInteraction['options'] : never;
1204
1205
  declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecutionMode> {
1206
+ #private;
1205
1207
  readonly commandkit: CommandKit;
1206
1208
  private readonly config;
1207
1209
  /**
@@ -1219,6 +1221,11 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
1219
1221
  * @param config The context parameters.
1220
1222
  */
1221
1223
  constructor(commandkit: CommandKit, config: ContextParameters<ExecutionMode>);
1224
+ /**
1225
+ * The shared key-value store for this context. This can be used to store data that needs to be shared between middlewares or commands.
1226
+ * This store is shared across all contexts in the same command execution, including the cloned contexts and middleware contexts.
1227
+ */
1228
+ get store(): Map<string, any>;
1222
1229
  get commandName(): string;
1223
1230
  get options(): CommandContextOptions<ExecutionMode>;
1224
1231
  /**
@@ -1292,6 +1299,29 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
1292
1299
  clone(config?: Partial<ContextParameters<ExecutionMode>>): Context<ExecutionMode>;
1293
1300
  isMiddleware(): this is MiddlewareContext<ExecutionMode>;
1294
1301
  args(): string[];
1302
+ /**
1303
+ * Stops upcoming middleware or current command execution.
1304
+ * If this is called inside pre-stage middleware, the next run will be the actual command, skipping all other pre-stage middlewares.
1305
+ * If this is called inside a command itself, it will skip all post-stage middlewares.
1306
+ * If this is called inside post-stage middleware, it will skip all other post-stage middlewares.
1307
+ */
1308
+ exit(): void;
1309
+ /**
1310
+ * Defers the given function to be executed after this command's execution.
1311
+ * @param fn The function to defer.
1312
+ * @returns A unique identifier for the deferred function.
1313
+ */
1314
+ defer(fn: GenericFunction<[CommandKitEnvironment]>): string;
1315
+ /**
1316
+ * Cancels the deferred function with the given identifier.
1317
+ * @param id The identifier of the deferred function.
1318
+ */
1319
+ cancelDeferred(id: string): void;
1320
+ /**
1321
+ * Validates if the given function is a cached function.
1322
+ * @param fn The function to validate.
1323
+ */
1324
+ isCached(fn: GenericFunction): boolean;
1295
1325
  }
1296
1326
  declare class MiddlewareContext<T extends CommandExecutionMode = CommandExecutionMode> extends Context<T> {
1297
1327
  #private;
@@ -1364,6 +1394,15 @@ declare class CommandKit extends EventEmitter {
1364
1394
  * @see {@link https://commandkit.js.org/docs/guide/commandkit-setup}
1365
1395
  */
1366
1396
  constructor(options: CommandKitOptions);
1397
+ /**
1398
+ * Starts the commandkit application.
1399
+ * @param token The application token to connect to the discord gateway. If not provided, it will use the `TOKEN` or `DISCORD_TOKEN` environment variable. If set to `false`, it will not login.
1400
+ */
1401
+ start(token?: string | false): Promise<void>;
1402
+ /**
1403
+ * Whether or not the commandkit application has started.
1404
+ */
1405
+ get started(): boolean;
1367
1406
  /**
1368
1407
  * Sets the prefix resolver for the command handler.
1369
1408
  * @param resolver The resolver function.
@@ -1515,58 +1554,114 @@ declare class MemoryCache extends CacheProvider {
1515
1554
  expire(key: string, ttl: number): Promise<void>;
1516
1555
  }
1517
1556
 
1518
- type AsyncFunction<R extends any[] = any[], T = any> = (...args: R) => Promise<T>;
1519
- interface CacheTag {
1520
- tag: string;
1521
- ttl: number | string;
1522
- }
1523
- interface CacheParams extends CacheTag {
1524
- target: GenericFunction;
1525
- memo: GenericFunction;
1557
+ /**
1558
+ * Context for managing cache operations within an async scope
1559
+ */
1560
+ interface CacheContext {
1561
+ params: {
1562
+ /** Custom name for the cache entry */
1563
+ name?: string;
1564
+ /** Time-to-live in milliseconds */
1565
+ ttl?: number;
1566
+ };
1526
1567
  }
1527
1568
  /**
1528
- * Cache a function with a specific tag and time-to-live.
1529
- * @param fn The function to cache.
1530
- * @param params The cache tag and time-to-live.
1531
- * @returns The memoized function.
1569
+ * Represents an async function that can be cached
1570
+ * @template R - Array of argument types
1571
+ * @template T - Return type
1572
+ */
1573
+ type AsyncFunction<R extends any[] = any[], T = any> = (...args: R) => Promise<T>;
1574
+ /**
1575
+ * Configuration options for cache behavior
1532
1576
  */
1533
- declare function cache<R extends any[], F extends AsyncFunction<R>>(fn: F, params?: Partial<CacheTag>): F;
1577
+ interface CacheMetadata {
1578
+ /** Time-to-live duration in milliseconds or as a string (e.g., '1h', '5m') */
1579
+ ttl?: number | string;
1580
+ /** Custom name for the cache entry */
1581
+ name?: string;
1582
+ }
1534
1583
  /**
1535
- * **DO NOT USE THIS FUNCTION DIRECTLY**
1584
+ * Internal cache implementation
1536
1585
  * @internal
1537
1586
  * @private
1538
1587
  */
1539
- declare function useCache<R extends any[], F extends AsyncFunction<R>>(fn: F, id?: string, tag?: CacheTag): F;
1588
+ declare function useCache<R extends any[], F extends AsyncFunction<R>>(fn: F, id?: string, params?: CacheMetadata): F;
1540
1589
  /**
1541
- * Tags the current function with the given cache tag name
1542
- * @param tag The cache tag name.
1590
+ * Wraps an async function with caching capability
1591
+ * @template R - Array of argument types
1592
+ * @template F - Type of the async function
1593
+ * @param fn - The async function to cache
1594
+ * @param params - Optional cache configuration
1595
+ * @returns The wrapped function with caching behavior
1596
+ * @example
1597
+ * ```ts
1598
+ * const cachedFetch = cache(async (id: string) => {
1599
+ * return await db.findOne(id);
1600
+ * }, { ttl: '1h' });
1601
+ * ```
1543
1602
  */
1544
- declare function cacheTag(tag: string): void;
1603
+ declare function cache<R extends any[], F extends AsyncFunction<R>>(fn: F, params?: CacheMetadata): F;
1545
1604
  /**
1546
- * Tags the current function with the given cache tag parameters.
1547
- * @param tag The cache tag parameters.
1605
+ * Sets a custom identifier for the current cache operation
1606
+ * @param tag - The custom cache tag
1607
+ * @throws {Error} When called outside a cached function or without a tag
1608
+ * @example
1609
+ * ```ts
1610
+ * const fetchUser = cache(async (id: string) => {
1611
+ * cacheTag(`user:${id}`);
1612
+ * return await db.users.findOne(id);
1613
+ * });
1614
+ * ```
1548
1615
  */
1549
- declare function cacheTag(tag: CacheTag): void;
1616
+ declare function cacheTag(tag: string): void;
1550
1617
  /**
1551
- * Sets the time-to-live for the current cache tag.
1552
- * @param life The time-to-live value in milliseconds or a string.
1618
+ * Sets the TTL for the current cache operation
1619
+ * @param ttl - Time-to-live in milliseconds or as a string (e.g., '1h', '5m')
1620
+ * @throws {Error} When called outside a cached function or with invalid TTL
1621
+ * @example
1622
+ * ```ts
1623
+ * const fetchData = cache(async () => {
1624
+ * cacheLife('30m');
1625
+ * return await expensiveOperation();
1626
+ * });
1627
+ * ```
1553
1628
  */
1554
- declare function cacheLife(life: string): void;
1555
- declare function cacheLife(life: number): void;
1629
+ declare function cacheLife(ttl: number | string): void;
1556
1630
  /**
1557
- * Invalidates the cache with the given tag.
1558
- * This will immediately remove the cache entry. The next time cache is requested, it will be re-fetched.
1559
- * @param tag The cache tag to invalidate.
1631
+ * Removes a cached value by its tag
1632
+ * @param tag - The cache tag to invalidate
1633
+ * @throws {Error} When the cache key is not found
1634
+ * @example
1635
+ * ```ts
1636
+ * await invalidate('user:123');
1637
+ * ```
1560
1638
  */
1561
1639
  declare function invalidate(tag: string): Promise<void>;
1562
1640
  /**
1563
- * Revalidates the cache with the given tag.
1564
- * This will immediately remove the cache entry and re-fetch the value.
1565
- * @param tag The cache tag to revalidate.
1566
- * @param args The arguments to pass to the memoized function (if any).
1567
- * @returns The new value of the cache.
1641
+ * Forces a refresh of cached data by its tag (on-demand revalidation)
1642
+ * @template T - Type of the cached value
1643
+ * @param tag - The cache tag to revalidate
1644
+ * @param args - Arguments to pass to the cached function
1645
+ * @returns Fresh data from the cached function
1646
+ * @throws {Error} When the cache key or function is not found
1647
+ * @example
1648
+ * ```ts
1649
+ * const freshData = await revalidate('user:123');
1650
+ * ```
1568
1651
  */
1569
- declare function revalidate<R = any>(tag: string, ...args: any[]): Promise<R | undefined>;
1652
+ declare function revalidate<T = unknown>(tag: string, ...args: any[]): Promise<T>;
1653
+ /**
1654
+ * Checks if a function is wrapped with cache functionality
1655
+ * @param fn - Function to check
1656
+ * @returns True if the function is cached
1657
+ * @example
1658
+ * ```ts
1659
+ * if (isCachedFunction(myFunction)) {
1660
+ * console.log('Function is cached');
1661
+ * }
1662
+ * ```
1663
+ */
1664
+ declare function isCachedFunction(fn: GenericFunction): boolean;
1570
1665
 
1571
1666
  declare class DefaultLocalizationStrategy implements LocalizationStrategy {
1572
1667
  private readonly commandkit;
@@ -1591,6 +1686,53 @@ declare function exitMiddleware(): never;
1591
1686
  * @param error The error to rethrow.
1592
1687
  */
1593
1688
  declare function rethrow(error: unknown): void;
1689
+ /**
1690
+ * Stops current command assuming it has been redirected to another command.
1691
+ */
1692
+ declare function redirect(): never;
1693
+
1694
+ interface ILogger {
1695
+ log(...args: any[]): void;
1696
+ error(...args: any[]): void;
1697
+ warn(...args: any[]): void;
1698
+ info(...args: any[]): void;
1699
+ debug(...args: any[]): void;
1700
+ }
1701
+
1702
+ declare class DefaultLogger implements ILogger {
1703
+ stdout: NodeJS.WriteStream & {
1704
+ fd: 1;
1705
+ };
1706
+ stderr: NodeJS.WriteStream & {
1707
+ fd: 2;
1708
+ };
1709
+ private logger;
1710
+ constructor(stdout?: NodeJS.WriteStream & {
1711
+ fd: 1;
1712
+ }, stderr?: NodeJS.WriteStream & {
1713
+ fd: 2;
1714
+ });
1715
+ private _getContext;
1716
+ private _getPrefix;
1717
+ private _log;
1718
+ debug(...args: any[]): void;
1719
+ error(...args: any[]): void;
1720
+ log(...args: any[]): void;
1721
+ info(...args: any[]): void;
1722
+ warn(...args: any[]): void;
1723
+ }
1724
+
1725
+ interface CommandKitLoggerOptions {
1726
+ /**
1727
+ * The logger provider to use.
1728
+ */
1729
+ provider: ILogger;
1730
+ }
1731
+ interface LoggerImpl extends ILogger {
1732
+ configure(options: CommandKitLoggerOptions): void;
1733
+ }
1734
+ declare function createLogger(options: CommandKitLoggerOptions): LoggerImpl;
1735
+ declare const Logger: LoggerImpl;
1594
1736
 
1595
1737
  /**
1596
1738
  * Creates a command line interface for CommandKit.
@@ -1604,4 +1746,4 @@ declare function bootstrapCommandkitCLI(argv: string[], options?: commander.Pars
1604
1746
  */
1605
1747
  declare const version: string;
1606
1748
 
1607
- export { ActionRow, type ActionRowProps, type AnyCommandKitElement, AppCommandHandler, type AsyncFunction, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, type AutocompleteProps, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheEntry, type CacheParams, CacheProvider, type CacheTag, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, type CommandFileObject, CommandKit, type CommandKitButtonBuilderInteractionCollectorDispatch, type CommandKitButtonBuilderInteractionCollectorDispatchContextData, type CommandKitButtonBuilderOnEnd, type CommandKitConfig, type CommandKitConfiguration, type CommandKitData, type CommandKitElement, type CommandKitElementData, CommandKitEnvironment, type CommandKitEnvironmentInternalData, CommandKitEnvironmentType, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandObject, type CommandOptions, type CommandProps, Context, type ContextMenuCommandProps, type ContextParameters, DefaultLocalizationStrategy, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, Fragment, type FragmentElementProps, type GenericFunction, type InteractionCommandContext, type InteractionCommandMiddlewareContext, Localization, type LocalizationConfig, type LocalizationStrategy, type LocalizationTranslationRequest, type MaybeArray, MemoryCache, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type MessageContextMenuCommandProps, MiddlewareContext, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnModalKitEnd, type OnModalKitSubmit, ParagraphInput, type ParsedMessageCommand, type PreparedAppCommandExecution, type ReloadOptions, ReloadType, ShortInput, type SlashCommandContext, type SlashCommandMiddlewareContext, type SlashCommandProps, TextInput, type TextInputProps, type TranslatableArguments, type TranslatableCommand, type TranslatableCommandOptions, type Translation, type TranslationResult, type Translator, type UserContextMenuCommandContext, type UserContextMenuCommandMiddlewareContext, type UserContextMenuCommandProps, type ValidationProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, createElement, CommandKit as default, defineConfig, dmOnly, exitContext, exitMiddleware, getCommandKit, getConfig, getContext, getElement, guildOnly, invalidate, isCommandKitElement, makeContextAwareFunction, 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 };
1749
+ export { ActionRow, type ActionRowProps, type AnyCommandKitElement, AppCommandHandler, type AsyncFunction, 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 CommandKitConfig, type CommandKitConfiguration, type CommandKitData, 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, Localization, type LocalizationConfig, type LocalizationStrategy, type LocalizationTranslationRequest, Logger, type LoggerImpl, type MaybeArray, MemoryCache, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, 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 SlashCommandContext, type SlashCommandMiddlewareContext, type SlashCommandProps, TextInput, type TextInputProps, type TranslatableArguments, type TranslatableCommand, type TranslatableCommandOptions, type Translation, type TranslationResult, type Translator, 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 };