commandkit 0.1.11-dev.20250214180324 → 0.1.11-dev.20250215122009

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
  /**
@@ -1212,6 +1214,10 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
1212
1214
  * The message that triggered the command.
1213
1215
  */
1214
1216
  readonly message: ContextParameters<ExecutionMode>['message'];
1217
+ /**
1218
+ * The client instance.
1219
+ */
1220
+ readonly client: Client;
1215
1221
  private _locale;
1216
1222
  /**
1217
1223
  * Creates a new command context.
@@ -1219,6 +1225,11 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
1219
1225
  * @param config The context parameters.
1220
1226
  */
1221
1227
  constructor(commandkit: CommandKit, config: ContextParameters<ExecutionMode>);
1228
+ /**
1229
+ * The shared key-value store for this context. This can be used to store data that needs to be shared between middlewares or commands.
1230
+ * This store is shared across all contexts in the same command execution, including the cloned contexts and middleware contexts.
1231
+ */
1232
+ get store(): Map<string, any>;
1222
1233
  get commandName(): string;
1223
1234
  get options(): CommandContextOptions<ExecutionMode>;
1224
1235
  /**
@@ -1292,6 +1303,29 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
1292
1303
  clone(config?: Partial<ContextParameters<ExecutionMode>>): Context<ExecutionMode>;
1293
1304
  isMiddleware(): this is MiddlewareContext<ExecutionMode>;
1294
1305
  args(): string[];
1306
+ /**
1307
+ * Stops upcoming middleware or current command execution.
1308
+ * If this is called inside pre-stage middleware, the next run will be the actual command, skipping all other pre-stage middlewares.
1309
+ * If this is called inside a command itself, it will skip all post-stage middlewares.
1310
+ * If this is called inside post-stage middleware, it will skip all other post-stage middlewares.
1311
+ */
1312
+ exit(): void;
1313
+ /**
1314
+ * Defers the given function to be executed after this command's execution.
1315
+ * @param fn The function to defer.
1316
+ * @returns A unique identifier for the deferred function.
1317
+ */
1318
+ defer(fn: GenericFunction<[CommandKitEnvironment]>): string;
1319
+ /**
1320
+ * Cancels the deferred function with the given identifier.
1321
+ * @param id The identifier of the deferred function.
1322
+ */
1323
+ cancelDeferred(id: string): void;
1324
+ /**
1325
+ * Validates if the given function is a cached function.
1326
+ * @param fn The function to validate.
1327
+ */
1328
+ isCached(fn: GenericFunction): boolean;
1295
1329
  }
1296
1330
  declare class MiddlewareContext<T extends CommandExecutionMode = CommandExecutionMode> extends Context<T> {
1297
1331
  #private;
@@ -1364,6 +1398,15 @@ declare class CommandKit extends EventEmitter {
1364
1398
  * @see {@link https://commandkit.js.org/docs/guide/commandkit-setup}
1365
1399
  */
1366
1400
  constructor(options: CommandKitOptions);
1401
+ /**
1402
+ * Starts the commandkit application.
1403
+ * @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.
1404
+ */
1405
+ start(token?: string | false): Promise<void>;
1406
+ /**
1407
+ * Whether or not the commandkit application has started.
1408
+ */
1409
+ get started(): boolean;
1367
1410
  /**
1368
1411
  * Sets the prefix resolver for the command handler.
1369
1412
  * @param resolver The resolver function.
@@ -1515,58 +1558,114 @@ declare class MemoryCache extends CacheProvider {
1515
1558
  expire(key: string, ttl: number): Promise<void>;
1516
1559
  }
1517
1560
 
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;
1561
+ /**
1562
+ * Context for managing cache operations within an async scope
1563
+ */
1564
+ interface CacheContext {
1565
+ params: {
1566
+ /** Custom name for the cache entry */
1567
+ name?: string;
1568
+ /** Time-to-live in milliseconds */
1569
+ ttl?: number;
1570
+ };
1526
1571
  }
1527
1572
  /**
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.
1573
+ * Represents an async function that can be cached
1574
+ * @template R - Array of argument types
1575
+ * @template T - Return type
1532
1576
  */
1533
- declare function cache<R extends any[], F extends AsyncFunction<R>>(fn: F, params?: Partial<CacheTag>): F;
1577
+ type AsyncFunction<R extends any[] = any[], T = any> = (...args: R) => Promise<T>;
1534
1578
  /**
1535
- * **DO NOT USE THIS FUNCTION DIRECTLY**
1579
+ * Configuration options for cache behavior
1580
+ */
1581
+ interface CacheMetadata {
1582
+ /** Time-to-live duration in milliseconds or as a string (e.g., '1h', '5m') */
1583
+ ttl?: number | string;
1584
+ /** Custom name for the cache entry */
1585
+ name?: string;
1586
+ }
1587
+ /**
1588
+ * Internal cache implementation
1536
1589
  * @internal
1537
1590
  * @private
1538
1591
  */
1539
- declare function useCache<R extends any[], F extends AsyncFunction<R>>(fn: F, id?: string, tag?: CacheTag): F;
1592
+ declare function useCache<R extends any[], F extends AsyncFunction<R>>(fn: F, id?: string, params?: CacheMetadata): F;
1540
1593
  /**
1541
- * Tags the current function with the given cache tag name
1542
- * @param tag The cache tag name.
1594
+ * Wraps an async function with caching capability
1595
+ * @template R - Array of argument types
1596
+ * @template F - Type of the async function
1597
+ * @param fn - The async function to cache
1598
+ * @param params - Optional cache configuration
1599
+ * @returns The wrapped function with caching behavior
1600
+ * @example
1601
+ * ```ts
1602
+ * const cachedFetch = cache(async (id: string) => {
1603
+ * return await db.findOne(id);
1604
+ * }, { ttl: '1h' });
1605
+ * ```
1543
1606
  */
1544
- declare function cacheTag(tag: string): void;
1607
+ declare function cache<R extends any[], F extends AsyncFunction<R>>(fn: F, params?: CacheMetadata): F;
1545
1608
  /**
1546
- * Tags the current function with the given cache tag parameters.
1547
- * @param tag The cache tag parameters.
1609
+ * Sets a custom identifier for the current cache operation
1610
+ * @param tag - The custom cache tag
1611
+ * @throws {Error} When called outside a cached function or without a tag
1612
+ * @example
1613
+ * ```ts
1614
+ * const fetchUser = cache(async (id: string) => {
1615
+ * cacheTag(`user:${id}`);
1616
+ * return await db.users.findOne(id);
1617
+ * });
1618
+ * ```
1548
1619
  */
1549
- declare function cacheTag(tag: CacheTag): void;
1620
+ declare function cacheTag(tag: string): void;
1550
1621
  /**
1551
- * Sets the time-to-live for the current cache tag.
1552
- * @param life The time-to-live value in milliseconds or a string.
1622
+ * Sets the TTL for the current cache operation
1623
+ * @param ttl - Time-to-live in milliseconds or as a string (e.g., '1h', '5m')
1624
+ * @throws {Error} When called outside a cached function or with invalid TTL
1625
+ * @example
1626
+ * ```ts
1627
+ * const fetchData = cache(async () => {
1628
+ * cacheLife('30m');
1629
+ * return await expensiveOperation();
1630
+ * });
1631
+ * ```
1553
1632
  */
1554
- declare function cacheLife(life: string): void;
1555
- declare function cacheLife(life: number): void;
1633
+ declare function cacheLife(ttl: number | string): void;
1556
1634
  /**
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.
1635
+ * Removes a cached value by its tag
1636
+ * @param tag - The cache tag to invalidate
1637
+ * @throws {Error} When the cache key is not found
1638
+ * @example
1639
+ * ```ts
1640
+ * await invalidate('user:123');
1641
+ * ```
1560
1642
  */
1561
1643
  declare function invalidate(tag: string): Promise<void>;
1562
1644
  /**
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.
1645
+ * Forces a refresh of cached data by its tag (on-demand revalidation)
1646
+ * @template T - Type of the cached value
1647
+ * @param tag - The cache tag to revalidate
1648
+ * @param args - Arguments to pass to the cached function
1649
+ * @returns Fresh data from the cached function
1650
+ * @throws {Error} When the cache key or function is not found
1651
+ * @example
1652
+ * ```ts
1653
+ * const freshData = await revalidate('user:123');
1654
+ * ```
1568
1655
  */
1569
- declare function revalidate<R = any>(tag: string, ...args: any[]): Promise<R | undefined>;
1656
+ declare function revalidate<T = unknown>(tag: string, ...args: any[]): Promise<T>;
1657
+ /**
1658
+ * Checks if a function is wrapped with cache functionality
1659
+ * @param fn - Function to check
1660
+ * @returns True if the function is cached
1661
+ * @example
1662
+ * ```ts
1663
+ * if (isCachedFunction(myFunction)) {
1664
+ * console.log('Function is cached');
1665
+ * }
1666
+ * ```
1667
+ */
1668
+ declare function isCachedFunction(fn: GenericFunction): boolean;
1570
1669
 
1571
1670
  declare class DefaultLocalizationStrategy implements LocalizationStrategy {
1572
1671
  private readonly commandkit;
@@ -1591,6 +1690,10 @@ declare function exitMiddleware(): never;
1591
1690
  * @param error The error to rethrow.
1592
1691
  */
1593
1692
  declare function rethrow(error: unknown): void;
1693
+ /**
1694
+ * Stops current command assuming it has been redirected to another command.
1695
+ */
1696
+ declare function redirect(): never;
1594
1697
 
1595
1698
  interface ILogger {
1596
1699
  log(...args: any[]): void;
@@ -1613,7 +1716,9 @@ declare class DefaultLogger implements ILogger {
1613
1716
  }, stderr?: NodeJS.WriteStream & {
1614
1717
  fd: 2;
1615
1718
  });
1719
+ private _formatTime;
1616
1720
  private _getContext;
1721
+ private _getLevelLabel;
1617
1722
  private _getPrefix;
1618
1723
  private _log;
1619
1724
  debug(...args: any[]): void;
@@ -1647,4 +1752,4 @@ declare function bootstrapCommandkitCLI(argv: string[], options?: commander.Pars
1647
1752
  */
1648
1753
  declare const version: string;
1649
1754
 
1650
- 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 CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandObject, type CommandOptions, type CommandProps, Context, type ContextMenuCommandProps, type ContextParameters, DefaultLocalizationStrategy, DefaultLogger, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, 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 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, createLogger, 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 };
1755
+ 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
  /**
@@ -1212,6 +1214,10 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
1212
1214
  * The message that triggered the command.
1213
1215
  */
1214
1216
  readonly message: ContextParameters<ExecutionMode>['message'];
1217
+ /**
1218
+ * The client instance.
1219
+ */
1220
+ readonly client: Client;
1215
1221
  private _locale;
1216
1222
  /**
1217
1223
  * Creates a new command context.
@@ -1219,6 +1225,11 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
1219
1225
  * @param config The context parameters.
1220
1226
  */
1221
1227
  constructor(commandkit: CommandKit, config: ContextParameters<ExecutionMode>);
1228
+ /**
1229
+ * The shared key-value store for this context. This can be used to store data that needs to be shared between middlewares or commands.
1230
+ * This store is shared across all contexts in the same command execution, including the cloned contexts and middleware contexts.
1231
+ */
1232
+ get store(): Map<string, any>;
1222
1233
  get commandName(): string;
1223
1234
  get options(): CommandContextOptions<ExecutionMode>;
1224
1235
  /**
@@ -1292,6 +1303,29 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
1292
1303
  clone(config?: Partial<ContextParameters<ExecutionMode>>): Context<ExecutionMode>;
1293
1304
  isMiddleware(): this is MiddlewareContext<ExecutionMode>;
1294
1305
  args(): string[];
1306
+ /**
1307
+ * Stops upcoming middleware or current command execution.
1308
+ * If this is called inside pre-stage middleware, the next run will be the actual command, skipping all other pre-stage middlewares.
1309
+ * If this is called inside a command itself, it will skip all post-stage middlewares.
1310
+ * If this is called inside post-stage middleware, it will skip all other post-stage middlewares.
1311
+ */
1312
+ exit(): void;
1313
+ /**
1314
+ * Defers the given function to be executed after this command's execution.
1315
+ * @param fn The function to defer.
1316
+ * @returns A unique identifier for the deferred function.
1317
+ */
1318
+ defer(fn: GenericFunction<[CommandKitEnvironment]>): string;
1319
+ /**
1320
+ * Cancels the deferred function with the given identifier.
1321
+ * @param id The identifier of the deferred function.
1322
+ */
1323
+ cancelDeferred(id: string): void;
1324
+ /**
1325
+ * Validates if the given function is a cached function.
1326
+ * @param fn The function to validate.
1327
+ */
1328
+ isCached(fn: GenericFunction): boolean;
1295
1329
  }
1296
1330
  declare class MiddlewareContext<T extends CommandExecutionMode = CommandExecutionMode> extends Context<T> {
1297
1331
  #private;
@@ -1364,6 +1398,15 @@ declare class CommandKit extends EventEmitter {
1364
1398
  * @see {@link https://commandkit.js.org/docs/guide/commandkit-setup}
1365
1399
  */
1366
1400
  constructor(options: CommandKitOptions);
1401
+ /**
1402
+ * Starts the commandkit application.
1403
+ * @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.
1404
+ */
1405
+ start(token?: string | false): Promise<void>;
1406
+ /**
1407
+ * Whether or not the commandkit application has started.
1408
+ */
1409
+ get started(): boolean;
1367
1410
  /**
1368
1411
  * Sets the prefix resolver for the command handler.
1369
1412
  * @param resolver The resolver function.
@@ -1515,58 +1558,114 @@ declare class MemoryCache extends CacheProvider {
1515
1558
  expire(key: string, ttl: number): Promise<void>;
1516
1559
  }
1517
1560
 
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;
1561
+ /**
1562
+ * Context for managing cache operations within an async scope
1563
+ */
1564
+ interface CacheContext {
1565
+ params: {
1566
+ /** Custom name for the cache entry */
1567
+ name?: string;
1568
+ /** Time-to-live in milliseconds */
1569
+ ttl?: number;
1570
+ };
1526
1571
  }
1527
1572
  /**
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.
1573
+ * Represents an async function that can be cached
1574
+ * @template R - Array of argument types
1575
+ * @template T - Return type
1532
1576
  */
1533
- declare function cache<R extends any[], F extends AsyncFunction<R>>(fn: F, params?: Partial<CacheTag>): F;
1577
+ type AsyncFunction<R extends any[] = any[], T = any> = (...args: R) => Promise<T>;
1534
1578
  /**
1535
- * **DO NOT USE THIS FUNCTION DIRECTLY**
1579
+ * Configuration options for cache behavior
1580
+ */
1581
+ interface CacheMetadata {
1582
+ /** Time-to-live duration in milliseconds or as a string (e.g., '1h', '5m') */
1583
+ ttl?: number | string;
1584
+ /** Custom name for the cache entry */
1585
+ name?: string;
1586
+ }
1587
+ /**
1588
+ * Internal cache implementation
1536
1589
  * @internal
1537
1590
  * @private
1538
1591
  */
1539
- declare function useCache<R extends any[], F extends AsyncFunction<R>>(fn: F, id?: string, tag?: CacheTag): F;
1592
+ declare function useCache<R extends any[], F extends AsyncFunction<R>>(fn: F, id?: string, params?: CacheMetadata): F;
1540
1593
  /**
1541
- * Tags the current function with the given cache tag name
1542
- * @param tag The cache tag name.
1594
+ * Wraps an async function with caching capability
1595
+ * @template R - Array of argument types
1596
+ * @template F - Type of the async function
1597
+ * @param fn - The async function to cache
1598
+ * @param params - Optional cache configuration
1599
+ * @returns The wrapped function with caching behavior
1600
+ * @example
1601
+ * ```ts
1602
+ * const cachedFetch = cache(async (id: string) => {
1603
+ * return await db.findOne(id);
1604
+ * }, { ttl: '1h' });
1605
+ * ```
1543
1606
  */
1544
- declare function cacheTag(tag: string): void;
1607
+ declare function cache<R extends any[], F extends AsyncFunction<R>>(fn: F, params?: CacheMetadata): F;
1545
1608
  /**
1546
- * Tags the current function with the given cache tag parameters.
1547
- * @param tag The cache tag parameters.
1609
+ * Sets a custom identifier for the current cache operation
1610
+ * @param tag - The custom cache tag
1611
+ * @throws {Error} When called outside a cached function or without a tag
1612
+ * @example
1613
+ * ```ts
1614
+ * const fetchUser = cache(async (id: string) => {
1615
+ * cacheTag(`user:${id}`);
1616
+ * return await db.users.findOne(id);
1617
+ * });
1618
+ * ```
1548
1619
  */
1549
- declare function cacheTag(tag: CacheTag): void;
1620
+ declare function cacheTag(tag: string): void;
1550
1621
  /**
1551
- * Sets the time-to-live for the current cache tag.
1552
- * @param life The time-to-live value in milliseconds or a string.
1622
+ * Sets the TTL for the current cache operation
1623
+ * @param ttl - Time-to-live in milliseconds or as a string (e.g., '1h', '5m')
1624
+ * @throws {Error} When called outside a cached function or with invalid TTL
1625
+ * @example
1626
+ * ```ts
1627
+ * const fetchData = cache(async () => {
1628
+ * cacheLife('30m');
1629
+ * return await expensiveOperation();
1630
+ * });
1631
+ * ```
1553
1632
  */
1554
- declare function cacheLife(life: string): void;
1555
- declare function cacheLife(life: number): void;
1633
+ declare function cacheLife(ttl: number | string): void;
1556
1634
  /**
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.
1635
+ * Removes a cached value by its tag
1636
+ * @param tag - The cache tag to invalidate
1637
+ * @throws {Error} When the cache key is not found
1638
+ * @example
1639
+ * ```ts
1640
+ * await invalidate('user:123');
1641
+ * ```
1560
1642
  */
1561
1643
  declare function invalidate(tag: string): Promise<void>;
1562
1644
  /**
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.
1645
+ * Forces a refresh of cached data by its tag (on-demand revalidation)
1646
+ * @template T - Type of the cached value
1647
+ * @param tag - The cache tag to revalidate
1648
+ * @param args - Arguments to pass to the cached function
1649
+ * @returns Fresh data from the cached function
1650
+ * @throws {Error} When the cache key or function is not found
1651
+ * @example
1652
+ * ```ts
1653
+ * const freshData = await revalidate('user:123');
1654
+ * ```
1568
1655
  */
1569
- declare function revalidate<R = any>(tag: string, ...args: any[]): Promise<R | undefined>;
1656
+ declare function revalidate<T = unknown>(tag: string, ...args: any[]): Promise<T>;
1657
+ /**
1658
+ * Checks if a function is wrapped with cache functionality
1659
+ * @param fn - Function to check
1660
+ * @returns True if the function is cached
1661
+ * @example
1662
+ * ```ts
1663
+ * if (isCachedFunction(myFunction)) {
1664
+ * console.log('Function is cached');
1665
+ * }
1666
+ * ```
1667
+ */
1668
+ declare function isCachedFunction(fn: GenericFunction): boolean;
1570
1669
 
1571
1670
  declare class DefaultLocalizationStrategy implements LocalizationStrategy {
1572
1671
  private readonly commandkit;
@@ -1591,6 +1690,10 @@ declare function exitMiddleware(): never;
1591
1690
  * @param error The error to rethrow.
1592
1691
  */
1593
1692
  declare function rethrow(error: unknown): void;
1693
+ /**
1694
+ * Stops current command assuming it has been redirected to another command.
1695
+ */
1696
+ declare function redirect(): never;
1594
1697
 
1595
1698
  interface ILogger {
1596
1699
  log(...args: any[]): void;
@@ -1613,7 +1716,9 @@ declare class DefaultLogger implements ILogger {
1613
1716
  }, stderr?: NodeJS.WriteStream & {
1614
1717
  fd: 2;
1615
1718
  });
1719
+ private _formatTime;
1616
1720
  private _getContext;
1721
+ private _getLevelLabel;
1617
1722
  private _getPrefix;
1618
1723
  private _log;
1619
1724
  debug(...args: any[]): void;
@@ -1647,4 +1752,4 @@ declare function bootstrapCommandkitCLI(argv: string[], options?: commander.Pars
1647
1752
  */
1648
1753
  declare const version: string;
1649
1754
 
1650
- 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 CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandObject, type CommandOptions, type CommandProps, Context, type ContextMenuCommandProps, type ContextParameters, DefaultLocalizationStrategy, DefaultLogger, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, 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 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, createLogger, 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 };
1755
+ 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 };