commandkit 1.0.0-dev.20250613125159 → 1.0.0-dev.20250614015940

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.
Files changed (115) hide show
  1. package/dist/{CommandKit-BWzWBBGf.d.ts → CommandKit-BSXFD1Tt.d.ts} +359 -342
  2. package/dist/{CommandKit-BwxIJqBr.js → CommandKit-CT3K-Cac.js} +178 -174
  3. package/dist/CommandKit-CT3K-Cac.js.map +1 -0
  4. package/dist/CommandKit.d.ts +1 -1
  5. package/dist/CommandKit.js +4 -4
  6. package/dist/{EventWorkerContext-DdzSorsU.d.ts → EventWorkerContext-BnghX_KV.d.ts} +2 -2
  7. package/dist/{MessageCommandParser-Cz-3I-wL.js → MessageCommandParser-ClkDMI8g.js} +1 -1
  8. package/dist/{MessageCommandParser-Cz-3I-wL.js.map → MessageCommandParser-ClkDMI8g.js.map} +1 -1
  9. package/dist/analytics/analytics-engine.d.ts +1 -1
  10. package/dist/analytics/analytics-engine.js +4 -4
  11. package/dist/analytics/analytics-provider.d.ts +1 -1
  12. package/dist/analytics/utils.js +4 -4
  13. package/dist/app/commands/AppCommandRunner.d.ts +1 -1
  14. package/dist/app/commands/AppCommandRunner.js +4 -4
  15. package/dist/app/commands/Context.d.ts +1 -1
  16. package/dist/app/commands/Context.js +4 -4
  17. package/dist/app/commands/MessageCommandParser.js +1 -1
  18. package/dist/app/events/EventWorkerContext.d.ts +2 -2
  19. package/dist/app/handlers/AppCommandHandler.d.ts +2 -2
  20. package/dist/app/handlers/AppCommandHandler.js +4 -4
  21. package/dist/app/handlers/AppEventsHandler.d.ts +1 -1
  22. package/dist/app/handlers/AppEventsHandler.js +4 -4
  23. package/dist/app/index.d.ts +2 -2
  24. package/dist/app/index.js +4 -4
  25. package/dist/app/register/CommandRegistrar.d.ts +1 -1
  26. package/dist/app/register/CommandRegistrar.js +4 -4
  27. package/dist/{app-process-Bo-LedP8.js → app-process-DKNuvPMz.js} +2 -2
  28. package/dist/{app-process-Bo-LedP8.js.map → app-process-DKNuvPMz.js.map} +1 -1
  29. package/dist/{build-m0yxcs2c.js → build-CpZp-wxh.js} +4 -4
  30. package/dist/{build-m0yxcs2c.js.map → build-CpZp-wxh.js.map} +1 -1
  31. package/dist/cli/app-process.d.ts +2 -2
  32. package/dist/cli/app-process.js +3 -3
  33. package/dist/cli/build.d.ts +1 -1
  34. package/dist/cli/build.js +6 -6
  35. package/dist/cli/common.d.ts +5 -5
  36. package/dist/cli/common.js +2 -2
  37. package/dist/cli/development.js +7 -7
  38. package/dist/cli/generators.js +2 -2
  39. package/dist/cli/information.js +1 -1
  40. package/dist/cli/init.d.ts +1 -1
  41. package/dist/cli/init.js +5 -5
  42. package/dist/cli/production.d.ts +2 -2
  43. package/dist/cli/production.js +7 -7
  44. package/dist/cli/type-checker.js +3 -3
  45. package/dist/{common-Dasi9oKU.js → common-D11Ax__S.js} +2 -2
  46. package/dist/{common-Dasi9oKU.js.map → common-D11Ax__S.js.map} +1 -1
  47. package/dist/components/index.js +4 -4
  48. package/dist/components/v1/button/Button.js +4 -4
  49. package/dist/components/v1/button/ButtonKit.js +4 -4
  50. package/dist/components/v1/modal/Modal.js +4 -4
  51. package/dist/components/v1/modal/ModalKit.js +4 -4
  52. package/dist/components/v1/select-menu/ChannelSelectMenuKit.js +4 -4
  53. package/dist/components/v1/select-menu/MentionableSelectMenuKit.js +4 -4
  54. package/dist/components/v1/select-menu/RoleSelectMenuKit.js +4 -4
  55. package/dist/components/v1/select-menu/SelectMenu.js +4 -4
  56. package/dist/components/v1/select-menu/StringSelectMenuKit.js +4 -4
  57. package/dist/components/v1/select-menu/UserSelectMenuKit.js +4 -4
  58. package/dist/config/config.d.ts +4 -4
  59. package/dist/config/config.js +4 -4
  60. package/dist/config/default.d.ts +3 -3
  61. package/dist/config/default.js +4 -4
  62. package/dist/config/loader.d.ts +3 -3
  63. package/dist/config/loader.js +4 -4
  64. package/dist/config/types.d.ts +2 -2
  65. package/dist/config/utils.d.ts +3 -3
  66. package/dist/{config-BEl-UW2l.d.ts → config-CRU_9adq.d.ts} +3 -3
  67. package/dist/context/async-context.d.ts +1 -1
  68. package/dist/context/async-context.js +4 -4
  69. package/dist/context/environment.d.ts +1 -1
  70. package/dist/context/environment.js +4 -4
  71. package/dist/events/CommandKitEventsChannel.d.ts +1 -1
  72. package/dist/{feature-flags-DG5Ozd1p.js → feature-flags-B1rI-fjI.js} +2 -2
  73. package/dist/{feature-flags-DG5Ozd1p.js.map → feature-flags-B1rI-fjI.js.map} +1 -1
  74. package/dist/flags/FlagProvider.d.ts +1 -1
  75. package/dist/flags/feature-flags.d.ts +1 -1
  76. package/dist/flags/feature-flags.js +5 -5
  77. package/dist/flags/store.d.ts +1 -1
  78. package/dist/index.d.ts +7 -7
  79. package/dist/index.js +7 -7
  80. package/dist/{init-CpYlmrSy.d.ts → init-CEa28dgv.d.ts} +3 -3
  81. package/dist/{init-8cDqgA8y.js → init-Da3dcKxi.js} +4 -4
  82. package/dist/{init-8cDqgA8y.js.map → init-Da3dcKxi.js.map} +1 -1
  83. package/dist/logger/DefaultLogger.js +4 -4
  84. package/dist/logger/Logger.js +4 -4
  85. package/dist/plugins/CompilerPlugin.d.ts +1 -1
  86. package/dist/plugins/PluginCommon.d.ts +1 -1
  87. package/dist/plugins/RuntimePlugin.d.ts +1 -1
  88. package/dist/plugins/index.d.ts +1 -1
  89. package/dist/plugins/index.js +4 -4
  90. package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.d.ts +1 -1
  91. package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.js +4 -4
  92. package/dist/plugins/plugin-runtime/CompilerPluginRuntime.d.ts +1 -1
  93. package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.d.ts +1 -1
  94. package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.js +4 -4
  95. package/dist/plugins/plugin-runtime/builtin/MacroPlugin.d.ts +1 -1
  96. package/dist/plugins/plugin-runtime/builtin/MacroPlugin.js +4 -4
  97. package/dist/plugins/plugin-runtime/runtime.d.ts +1 -1
  98. package/dist/plugins/types.d.ts +1 -1
  99. package/dist/{type-checker-P8oyY259.js → type-checker-BgT1Ukbb.js} +2 -2
  100. package/dist/{type-checker-P8oyY259.js.map → type-checker-BgT1Ukbb.js.map} +1 -1
  101. package/dist/{types-C8GYFCIt.d.ts → types-CY8KcUfk.d.ts} +2 -2
  102. package/dist/{types-package-BpY3acyl.js → types-package-TSiYacaj.js} +1 -1
  103. package/dist/{types-package-BpY3acyl.js.map → types-package-TSiYacaj.js.map} +1 -1
  104. package/dist/types.d.ts +1 -1
  105. package/dist/utils/colors.d.ts +2 -2
  106. package/dist/utils/dev-hooks.d.ts +1 -1
  107. package/dist/utils/dev-hooks.js +4 -4
  108. package/dist/utils/types-package.js +1 -1
  109. package/dist/utils/utilities.js +4 -4
  110. package/dist/{utils-BjK-2R7h.d.ts → utils-PsznLC5X.d.ts} +2 -2
  111. package/dist/{version-rxKNvLPW.js → version-DiuoSTyi.js} +2 -2
  112. package/dist/{version-rxKNvLPW.js.map → version-DiuoSTyi.js.map} +1 -1
  113. package/dist/version.js +1 -1
  114. package/package.json +2 -2
  115. package/dist/CommandKit-BwxIJqBr.js.map +0 -1
@@ -9,6 +9,7 @@ import { AutocompleteInteraction, Awaitable, CacheType, ChatInputCommandInteract
9
9
  import { DirectiveTransformerOptions } from "directive-to-hof";
10
10
 
11
11
  //#region src/types.d.ts
12
+ type Prettify<T> = { [K in keyof T]: T[K] } & {};
12
13
  /**
13
14
  * Options for instantiating a CommandKit handler.
14
15
  */
@@ -38,271 +39,10 @@ interface CommandContext<T extends Interaction, Cached extends CacheType> {
38
39
  /**
39
40
  * Represents a command that can be executed by CommandKit.
40
41
  */
41
- type CommandData = RESTPostAPIApplicationCommandsJSONBody & {
42
+ type CommandData = Prettify<Omit<RESTPostAPIApplicationCommandsJSONBody, 'description'> & {
43
+ description?: string;
42
44
  guilds?: string[];
43
- };
44
- //#endregion
45
- //#region src/context/async-context.d.ts
46
- /**
47
- * Represents a generic function type that can accept any number of arguments.
48
- */
49
- type GenericFunction<A extends any[] = any[]> = (...args: A) => any;
50
- /**
51
- * Checks if the given worker is a CommandKit worker context.
52
- * @param worker The worker to check.
53
- * @returns True if the worker is a CommandKit worker context, false otherwise.
54
- */
55
- declare function isCommandWorkerContext(worker: any): worker is CommandKitEnvironment;
56
- /**
57
- * Represents an async function that can be cached
58
- * @template R - Array of argument types
59
- * @template T - Return type
60
- */
61
- type AsyncFunction<R extends any[] = any[], T = any> = (...args: R) => Promise<T>;
62
- declare function exitContext<T>(fn: () => T): T;
63
- /**
64
- * Executes the provided function within a CommandKit context.
65
- * @param value The CommandKit environment to use for the context.
66
- * @param receiver The function to execute within the context.
67
- * @returns The result of the receiver function.
68
- */
69
- declare function provideContext<R>(value: CommandKitEnvironment, receiver: () => R): R;
70
- /**
71
- * Returns a context-aware version of the given function.
72
- * @param env - The commandkit environment data.
73
- * @param fn - The target function.
74
- * @param finalizer - An optional finalizer function to run after the target function. This function will be context-aware.
75
- * @internal
76
- */
77
- declare function makeContextAwareFunction<R extends GenericFunction, F extends GenericFunction>(env: CommandKitEnvironment, fn: R, finalizer?: F): R;
78
- /**
79
- * Retrieves commandkit
80
- * @private
81
- * @internal
82
- */
83
- declare function getCommandKit(): CommandKit | undefined;
84
- declare function getCommandKit(strict: true): CommandKit;
85
- declare function getCommandKit(strict: false): CommandKit | undefined;
86
- /**
87
- * Get the current commandkit context.
88
- * @internal
89
- */
90
- declare function getContext(): CommandKitEnvironment | undefined;
91
- /**
92
- * Use current commandkit context. Throws an error if no context is found.
93
- */
94
- declare function useEnvironment(): CommandKitEnvironment;
95
- //#endregion
96
- //#region src/app/register/CommandRegistrar.d.ts
97
- /**
98
- * Event object passed to plugins before command registration.
99
- */
100
- interface PreRegisterCommandsEvent {
101
- preventDefault(): void;
102
- commands: CommandData[];
103
- }
104
- /**
105
- * Handles registration of Discord application commands (slash commands, context menus).
106
- */
107
- declare class CommandRegistrar {
108
- readonly commandkit: CommandKit;
109
- /**
110
- * @private
111
- * @internal
112
- */
113
- private api;
114
- /**
115
- * Creates an instance of CommandRegistrar.
116
- * @param commandkit The commandkit instance.
117
- */
118
- constructor(commandkit: CommandKit);
119
- /**
120
- * Gets the commands data.
121
- */
122
- getCommandsData(): CommandData[];
123
- /**
124
- * Registers loaded commands.
125
- */
126
- register(): Promise<void>;
127
- /**
128
- * Updates the global commands.
129
- */
130
- updateGlobalCommands(commands: CommandData[]): Promise<void>;
131
- /**
132
- * Updates the guild commands.
133
- */
134
- updateGuildCommands(commands: CommandData[]): Promise<void>;
135
- }
136
- //#endregion
137
- //#region src/context/environment.d.ts
138
- /**
139
- * Represents the internal data structure for the CommandKit environment.
140
- */
141
- interface CommandKitEnvironmentInternalData {
142
- /**
143
- * The error that occurred during command execution, if any.
144
- * This is set when an error occurs during the execution of a command.
145
- */
146
- executionError: Error | null;
147
- /**
148
- * The type of the environment, which can be used to differentiate between
149
- * different execution contexts (e.g., command handler, event handler, etc.).
150
- */
151
- type: CommandKitEnvironmentType | null;
152
- /**
153
- * A map of variables that can be used to store and retrieve data during command execution.
154
- * This allows for sharing data between different parts of the command execution process.
155
- */
156
- variables: Map<string, any>;
157
- /**
158
- * A map of deferred functions that will be executed after the command has finished executing.
159
- * This is useful for running cleanup tasks or additional processing after the main command logic.
160
- */
161
- deferredFunctions: Map<string, GenericFunction<[CommandKitEnvironment]>>;
162
- /**
163
- * A marker string that can be used to identify the command execution.
164
- * This is useful for logging and debugging purposes.
165
- */
166
- marker: string;
167
- /**
168
- * The start time of the command execution.
169
- */
170
- markStart: number;
171
- /**
172
- * The end time of the command execution.
173
- */
174
- markEnd: number;
175
- /**
176
- * The context associated with the command execution.
177
- * This can be used to access request-specific data or application state.
178
- */
179
- context: Context | null;
180
- }
181
- /**
182
- * Represents the execution environment for CommandKit commands.
183
- */
184
- declare class CommandKitEnvironment {
185
- #private;
186
- readonly commandkit: CommandKit;
187
- /**
188
- * Creates the commandkit execution environment.
189
- * @param commandkit - The commandkit instance.
190
- */
191
- constructor(commandkit: CommandKit);
192
- /**
193
- * Set the context.
194
- * @param context - The context to set.
195
- */
196
- setContext(context: Context): void;
197
- /**
198
- * Get the context. `null` if not set.
199
- * @internal
200
- */
201
- get context(): Context | null;
202
- /**
203
- * Get the execution error.
204
- * @internal
205
- */
206
- getExecutionError(): Error | null;
207
- /**
208
- * Set the execution error.
209
- * @param error - The error to set.
210
- * @internal
211
- */
212
- setExecutionError(error: Error): void;
213
- /**
214
- * Get the environment type.
215
- */
216
- getType(): CommandKitEnvironmentType;
217
- /**
218
- * Set the environment type.
219
- * @param type - The environment type to set.
220
- * @internal
221
- */
222
- setType(type: CommandKitEnvironmentType): void;
223
- /**
224
- * The variables store for this environment.
225
- */
226
- get variables(): Map<string, any>;
227
- /**
228
- * Register a deferred function.
229
- * @param fn - The deferred function to register.
230
- * @returns The deferred function id.
231
- * @internal
232
- */
233
- registerDeferredFunction(fn: GenericFunction<[CommandKitEnvironment]>): string;
234
- /**
235
- * Clear a deferred function by id.
236
- * @param id - The deferred function id to clear.
237
- * @internal
238
- */
239
- clearDeferredFunction(id: string): void;
240
- /**
241
- * Run all deferred functions sequentially.
242
- * @internal
243
- */
244
- runDeferredFunctions(): Promise<void>;
245
- /**
246
- * Clear all deferred functions.
247
- * @internal
248
- */
249
- clearAllDeferredFunctions(): void;
250
- /**
251
- * Mark the start of a command execution.
252
- * @param marker - The marker to set.
253
- * @internal
254
- */
255
- markStart(marker: string): void;
256
- /**
257
- * Mark the end of a command execution.
258
- * @internal
259
- */
260
- markEnd(): void;
261
- /**
262
- * Get the marker.
263
- * @internal
264
- */
265
- getMarker(): string;
266
- /**
267
- * Get the execution time in milliseconds.
268
- * @internal
269
- */
270
- getExecutionTime(): number;
271
- }
272
- declare enum CommandKitEnvironmentType {
273
- CommandHandler = "COMMAND_HANDLER",
274
- }
275
- /**
276
- * Schedules the given function to run after the current command has finished executing.
277
- * @param fn The function to run after the current command.
278
- * @returns The deferred function id. This can be used to cancel the deferred function.
279
- * @example import { after } from 'commandkit';
280
- *
281
- * // inside a command
282
- * export const chatInput: ChatInputCommand = async (ctx) => {
283
- * after(() => {
284
- * console.log('This will run after the command has finished executing.');
285
- * });
286
- *
287
- * // ... command logic
288
- * }
289
- */
290
- declare function after(fn: GenericFunction<[CommandKitEnvironment]>): string;
291
- /**
292
- * Cancels a deferred function registered with `after`.
293
- * @param id The deferred function id to cancel.
294
- * @example import { cancelAfter } from 'commandkit';
295
- * // inside a command
296
- * export const chatInput: ChatInputCommand = async (ctx) => {
297
- * const id = after(() => {
298
- * console.log('This will run after the command has finished executing.');
299
- * });
300
- *
301
- * // cancel the deferred function if needed
302
- * if (something) cancelAfter(id);
303
- * }
304
- */
305
- declare function cancelAfter(id: string): void;
45
+ }>;
306
46
  //#endregion
307
47
  //#region src/app/commands/Context.d.ts
308
48
  /**
@@ -459,132 +199,394 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
459
199
  * @private
460
200
  * @internal
461
201
  */
462
- private _locale;
202
+ private _locale;
203
+ /**
204
+ * Creates a new command context.
205
+ * @param commandkit The command kit instance.
206
+ * @param config The context parameters.
207
+ */
208
+ constructor(commandkit: CommandKit, config: ContextParameters<ExecutionMode, Args>);
209
+ /**
210
+ * The shared key-value store for this context. This can be used to store data that needs to be shared between middlewares or commands.
211
+ * This store is shared across all contexts in the same command execution, including the cloned contexts and middleware contexts.
212
+ */
213
+ get store(): Map<string, any>;
214
+ /**
215
+ * Gets the name of the current command.
216
+ */
217
+ get commandName(): string;
218
+ /**
219
+ * Gets the command options based on the execution mode.
220
+ */
221
+ get options(): CommandContextOptions<ExecutionMode>;
222
+ /**
223
+ * Whether this context was forwarded from another context. This happens when a command forwards its context to another command.
224
+ */
225
+ get forwarded(): boolean;
226
+ /**
227
+ * Forwards the context to another command. The target handler will be the same as current handler.
228
+ * @param command The command to forward to.
229
+ */
230
+ forwardCommand<C extends ResolvableCommand>(command: C): Promise<never>;
231
+ /**
232
+ * The execution mode of the command.
233
+ */
234
+ get executionMode(): ExecutionMode;
235
+ /**
236
+ * Whether the command was triggered by an interaction.
237
+ */
238
+ isInteraction(): this is InteractionCommandContext;
239
+ /**
240
+ * Whether the command was triggered by a slash command interaction.
241
+ */
242
+ isChatInputCommand(): this is ChatInputCommandContext;
243
+ /**
244
+ * Whether the command was triggered by an autocomplete interaction.
245
+ */
246
+ isAutocomplete(): this is AutocompleteCommandContext;
247
+ /**
248
+ * Whether the command was triggered by a message context menu interaction.
249
+ */
250
+ isMessageContextMenu(): this is MessageContextMenuCommandContext;
251
+ /**
252
+ * Whether the command was triggered by a user context menu interaction.
253
+ */
254
+ isUserContextMenu(): this is UserContextMenuCommandContext;
255
+ /**
256
+ * Whether the command was triggered by a message.
257
+ */
258
+ isMessage(): this is Context<'message'>;
259
+ /**
260
+ * Returns the command identifier.
261
+ */
262
+ getCommandIdentifier(): string;
263
+ /**
264
+ * Returns the locale of the guild where this command was triggered.
265
+ */
266
+ getGuildLocale(): Locale | null;
267
+ /**
268
+ * Returns the locale of the user who triggered this command.
269
+ */
270
+ getUserLocale(): Locale | null;
271
+ /**
272
+ * Returns the locale for this command.
273
+ * @param preferUser Whether to prefer the user's locale over the guild's locale.
274
+ * @returns The locale for this command. If no locale is found, the default locale is returned.
275
+ */
276
+ getLocale(preferUser?: boolean): Locale;
277
+ /**
278
+ * Sets the locale for this command.
279
+ * @param locale The locale to set.
280
+ */
281
+ setLocale(locale: Locale | null): void;
282
+ /**
283
+ * Creates a clone of this context
284
+ * @param config - Optional partial config to override in the clone
285
+ */
286
+ clone(config?: Partial<ContextParameters<ExecutionMode>>): Context<ExecutionMode>;
287
+ /**
288
+ * Checks if this context is a middleware context.
289
+ */
290
+ isMiddleware(): this is MiddlewareContext<ExecutionMode>;
291
+ /**
292
+ * Gets the command arguments (only available for message commands).
293
+ * @returns Array of command arguments
294
+ */
295
+ args(): string[];
296
+ /**
297
+ * Stops upcoming middleware or current command execution.
298
+ * If this is called inside pre-stage middleware, the next run will be the actual command, skipping all other pre-stage middlewares.
299
+ * If this is called inside a command itself, it will skip all post-stage middlewares.
300
+ * If this is called inside post-stage middleware, it will skip all other post-stage middlewares.
301
+ */
302
+ exit(): never;
303
+ }
304
+ /**
305
+ * Extended context class for middleware execution with additional control methods.
306
+ */
307
+ declare class MiddlewareContext<T extends CommandExecutionMode = CommandExecutionMode> extends Context<T, MiddlewareContextArgs> {
308
+ #private;
309
+ /**
310
+ * Whether the command execution was cancelled.
311
+ */
312
+ get cancelled(): boolean;
313
+ /**
314
+ * Cancels the command execution.
315
+ */
316
+ cancel(): void;
317
+ /**
318
+ * Sets command runner function to wrap the command execution.
319
+ * @param fn The function to set.
320
+ * @example ctx.setCommandRunner(async (execute) => {
321
+ * // do something before command execution
322
+ * await execute();
323
+ * // do something after command execution
324
+ * })
325
+ */
326
+ setCommandRunner(fn: RunCommand): void;
327
+ }
328
+ //#endregion
329
+ //#region src/app/register/CommandRegistrar.d.ts
330
+ /**
331
+ * Event object passed to plugins before command registration.
332
+ */
333
+ interface PreRegisterCommandsEvent {
334
+ preventDefault(): void;
335
+ commands: CommandData[];
336
+ }
337
+ /**
338
+ * Handles registration of Discord application commands (slash commands, context menus).
339
+ */
340
+ declare class CommandRegistrar {
341
+ readonly commandkit: CommandKit;
342
+ /**
343
+ * @private
344
+ * @internal
345
+ */
346
+ private api;
347
+ /**
348
+ * Creates an instance of CommandRegistrar.
349
+ * @param commandkit The commandkit instance.
350
+ */
351
+ constructor(commandkit: CommandKit);
352
+ /**
353
+ * Gets the commands data.
354
+ */
355
+ getCommandsData(): CommandData[];
356
+ /**
357
+ * Registers loaded commands.
358
+ */
359
+ register(): Promise<void>;
360
+ /**
361
+ * Updates the global commands.
362
+ */
363
+ updateGlobalCommands(commands: CommandData[]): Promise<void>;
463
364
  /**
464
- * Creates a new command context.
465
- * @param commandkit The command kit instance.
466
- * @param config The context parameters.
365
+ * Updates the guild commands.
467
366
  */
468
- constructor(commandkit: CommandKit, config: ContextParameters<ExecutionMode, Args>);
367
+ updateGuildCommands(commands: CommandData[]): Promise<void>;
368
+ }
369
+ //#endregion
370
+ //#region src/context/environment.d.ts
371
+ /**
372
+ * Represents the internal data structure for the CommandKit environment.
373
+ */
374
+ interface CommandKitEnvironmentInternalData {
469
375
  /**
470
- * The shared key-value store for this context. This can be used to store data that needs to be shared between middlewares or commands.
471
- * This store is shared across all contexts in the same command execution, including the cloned contexts and middleware contexts.
376
+ * The error that occurred during command execution, if any.
377
+ * This is set when an error occurs during the execution of a command.
472
378
  */
473
- get store(): Map<string, any>;
379
+ executionError: Error | null;
474
380
  /**
475
- * Gets the name of the current command.
381
+ * The type of the environment, which can be used to differentiate between
382
+ * different execution contexts (e.g., command handler, event handler, etc.).
476
383
  */
477
- get commandName(): string;
384
+ type: CommandKitEnvironmentType | null;
478
385
  /**
479
- * Gets the command options based on the execution mode.
386
+ * A map of variables that can be used to store and retrieve data during command execution.
387
+ * This allows for sharing data between different parts of the command execution process.
480
388
  */
481
- get options(): CommandContextOptions<ExecutionMode>;
389
+ variables: Map<string, any>;
482
390
  /**
483
- * Whether this context was forwarded from another context. This happens when a command forwards its context to another command.
391
+ * A map of deferred functions that will be executed after the command has finished executing.
392
+ * This is useful for running cleanup tasks or additional processing after the main command logic.
484
393
  */
485
- get forwarded(): boolean;
394
+ deferredFunctions: Map<string, GenericFunction<[CommandKitEnvironment]>>;
486
395
  /**
487
- * Forwards the context to another command. The target handler will be the same as current handler.
488
- * @param command The command to forward to.
396
+ * A marker string that can be used to identify the command execution.
397
+ * This is useful for logging and debugging purposes.
489
398
  */
490
- forwardCommand<C extends ResolvableCommand>(command: C): Promise<never>;
399
+ marker: string;
491
400
  /**
492
- * The execution mode of the command.
401
+ * The start time of the command execution.
493
402
  */
494
- get executionMode(): ExecutionMode;
403
+ markStart: number;
495
404
  /**
496
- * Whether the command was triggered by an interaction.
405
+ * The end time of the command execution.
497
406
  */
498
- isInteraction(): this is InteractionCommandContext;
407
+ markEnd: number;
499
408
  /**
500
- * Whether the command was triggered by a slash command interaction.
409
+ * The context associated with the command execution.
410
+ * This can be used to access request-specific data or application state.
501
411
  */
502
- isChatInputCommand(): this is ChatInputCommandContext;
412
+ context: Context | null;
413
+ }
414
+ /**
415
+ * Represents the execution environment for CommandKit commands.
416
+ */
417
+ declare class CommandKitEnvironment {
418
+ #private;
419
+ readonly commandkit: CommandKit;
503
420
  /**
504
- * Whether the command was triggered by an autocomplete interaction.
421
+ * Creates the commandkit execution environment.
422
+ * @param commandkit - The commandkit instance.
505
423
  */
506
- isAutocomplete(): this is AutocompleteCommandContext;
424
+ constructor(commandkit: CommandKit);
507
425
  /**
508
- * Whether the command was triggered by a message context menu interaction.
426
+ * Set the context.
427
+ * @param context - The context to set.
509
428
  */
510
- isMessageContextMenu(): this is MessageContextMenuCommandContext;
429
+ setContext(context: Context): void;
511
430
  /**
512
- * Whether the command was triggered by a user context menu interaction.
431
+ * Get the context. `null` if not set.
432
+ * @internal
513
433
  */
514
- isUserContextMenu(): this is UserContextMenuCommandContext;
434
+ get context(): Context | null;
515
435
  /**
516
- * Whether the command was triggered by a message.
436
+ * Get the execution error.
437
+ * @internal
517
438
  */
518
- isMessage(): this is Context<'message'>;
439
+ getExecutionError(): Error | null;
519
440
  /**
520
- * Returns the command identifier.
441
+ * Set the execution error.
442
+ * @param error - The error to set.
443
+ * @internal
521
444
  */
522
- getCommandIdentifier(): string;
445
+ setExecutionError(error: Error): void;
523
446
  /**
524
- * Returns the locale of the guild where this command was triggered.
447
+ * Get the environment type.
525
448
  */
526
- getGuildLocale(): Locale | null;
449
+ getType(): CommandKitEnvironmentType;
527
450
  /**
528
- * Returns the locale of the user who triggered this command.
451
+ * Set the environment type.
452
+ * @param type - The environment type to set.
453
+ * @internal
529
454
  */
530
- getUserLocale(): Locale | null;
455
+ setType(type: CommandKitEnvironmentType): void;
531
456
  /**
532
- * Returns the locale for this command.
533
- * @param preferUser Whether to prefer the user's locale over the guild's locale.
534
- * @returns The locale for this command. If no locale is found, the default locale is returned.
457
+ * The variables store for this environment.
535
458
  */
536
- getLocale(preferUser?: boolean): Locale;
459
+ get variables(): Map<string, any>;
537
460
  /**
538
- * Sets the locale for this command.
539
- * @param locale The locale to set.
461
+ * Register a deferred function.
462
+ * @param fn - The deferred function to register.
463
+ * @returns The deferred function id.
464
+ * @internal
540
465
  */
541
- setLocale(locale: Locale | null): void;
466
+ registerDeferredFunction(fn: GenericFunction<[CommandKitEnvironment]>): string;
542
467
  /**
543
- * Creates a clone of this context
544
- * @param config - Optional partial config to override in the clone
468
+ * Clear a deferred function by id.
469
+ * @param id - The deferred function id to clear.
470
+ * @internal
545
471
  */
546
- clone(config?: Partial<ContextParameters<ExecutionMode>>): Context<ExecutionMode>;
472
+ clearDeferredFunction(id: string): void;
547
473
  /**
548
- * Checks if this context is a middleware context.
474
+ * Run all deferred functions sequentially.
475
+ * @internal
549
476
  */
550
- isMiddleware(): this is MiddlewareContext<ExecutionMode>;
477
+ runDeferredFunctions(): Promise<void>;
551
478
  /**
552
- * Gets the command arguments (only available for message commands).
553
- * @returns Array of command arguments
479
+ * Clear all deferred functions.
480
+ * @internal
554
481
  */
555
- args(): string[];
482
+ clearAllDeferredFunctions(): void;
556
483
  /**
557
- * Stops upcoming middleware or current command execution.
558
- * If this is called inside pre-stage middleware, the next run will be the actual command, skipping all other pre-stage middlewares.
559
- * If this is called inside a command itself, it will skip all post-stage middlewares.
560
- * If this is called inside post-stage middleware, it will skip all other post-stage middlewares.
484
+ * Mark the start of a command execution.
485
+ * @param marker - The marker to set.
486
+ * @internal
561
487
  */
562
- exit(): never;
563
- }
564
- /**
565
- * Extended context class for middleware execution with additional control methods.
566
- */
567
- declare class MiddlewareContext<T extends CommandExecutionMode = CommandExecutionMode> extends Context<T, MiddlewareContextArgs> {
568
- #private;
488
+ markStart(marker: string): void;
569
489
  /**
570
- * Whether the command execution was cancelled.
490
+ * Mark the end of a command execution.
491
+ * @internal
571
492
  */
572
- get cancelled(): boolean;
493
+ markEnd(): void;
573
494
  /**
574
- * Cancels the command execution.
495
+ * Get the marker.
496
+ * @internal
575
497
  */
576
- cancel(): void;
498
+ getMarker(): string;
577
499
  /**
578
- * Sets command runner function to wrap the command execution.
579
- * @param fn The function to set.
580
- * @example ctx.setCommandRunner(async (execute) => {
581
- * // do something before command execution
582
- * await execute();
583
- * // do something after command execution
584
- * })
500
+ * Get the execution time in milliseconds.
501
+ * @internal
585
502
  */
586
- setCommandRunner(fn: RunCommand): void;
503
+ getExecutionTime(): number;
504
+ }
505
+ declare enum CommandKitEnvironmentType {
506
+ CommandHandler = "COMMAND_HANDLER",
587
507
  }
508
+ /**
509
+ * Schedules the given function to run after the current command has finished executing.
510
+ * @param fn The function to run after the current command.
511
+ * @returns The deferred function id. This can be used to cancel the deferred function.
512
+ * @example import { after } from 'commandkit';
513
+ *
514
+ * // inside a command
515
+ * export const chatInput: ChatInputCommand = async (ctx) => {
516
+ * after(() => {
517
+ * console.log('This will run after the command has finished executing.');
518
+ * });
519
+ *
520
+ * // ... command logic
521
+ * }
522
+ */
523
+ declare function after(fn: GenericFunction<[CommandKitEnvironment]>): string;
524
+ /**
525
+ * Cancels a deferred function registered with `after`.
526
+ * @param id The deferred function id to cancel.
527
+ * @example import { cancelAfter } from 'commandkit';
528
+ * // inside a command
529
+ * export const chatInput: ChatInputCommand = async (ctx) => {
530
+ * const id = after(() => {
531
+ * console.log('This will run after the command has finished executing.');
532
+ * });
533
+ *
534
+ * // cancel the deferred function if needed
535
+ * if (something) cancelAfter(id);
536
+ * }
537
+ */
538
+ declare function cancelAfter(id: string): void;
539
+ //#endregion
540
+ //#region src/context/async-context.d.ts
541
+ /**
542
+ * Represents a generic function type that can accept any number of arguments.
543
+ */
544
+ type GenericFunction<A extends any[] = any[]> = (...args: A) => any;
545
+ /**
546
+ * Checks if the given worker is a CommandKit worker context.
547
+ * @param worker The worker to check.
548
+ * @returns True if the worker is a CommandKit worker context, false otherwise.
549
+ */
550
+ declare function isCommandWorkerContext(worker: any): worker is CommandKitEnvironment;
551
+ /**
552
+ * Represents an async function that can be cached
553
+ * @template R - Array of argument types
554
+ * @template T - Return type
555
+ */
556
+ type AsyncFunction<R extends any[] = any[], T = any> = (...args: R) => Promise<T>;
557
+ declare function exitContext<T>(fn: () => T): T;
558
+ /**
559
+ * Executes the provided function within a CommandKit context.
560
+ * @param value The CommandKit environment to use for the context.
561
+ * @param receiver The function to execute within the context.
562
+ * @returns The result of the receiver function.
563
+ */
564
+ declare function provideContext<R>(value: CommandKitEnvironment, receiver: () => R): R;
565
+ /**
566
+ * Returns a context-aware version of the given function.
567
+ * @param env - The commandkit environment data.
568
+ * @param fn - The target function.
569
+ * @param finalizer - An optional finalizer function to run after the target function. This function will be context-aware.
570
+ * @internal
571
+ */
572
+ declare function makeContextAwareFunction<R extends GenericFunction, F extends GenericFunction>(env: CommandKitEnvironment, fn: R, finalizer?: F): R;
573
+ /**
574
+ * Retrieves commandkit
575
+ * @private
576
+ * @internal
577
+ */
578
+ declare function getCommandKit(): CommandKit | undefined;
579
+ declare function getCommandKit(strict: true): CommandKit;
580
+ declare function getCommandKit(strict: false): CommandKit | undefined;
581
+ /**
582
+ * Get the current commandkit context.
583
+ * @internal
584
+ */
585
+ declare function getContext(): CommandKitEnvironment | undefined;
586
+ /**
587
+ * Use current commandkit context. Throws an error if no context is found.
588
+ */
589
+ declare function useEnvironment(): CommandKitEnvironment;
588
590
  //#endregion
589
591
  //#region src/app/commands/AppCommandRunner.d.ts
590
592
  /**
@@ -643,7 +645,7 @@ type RunCommand = <T extends AsyncFunction>(fn: T) => T;
643
645
  * It can be used to define slash commands, context menu commands, and message commands.
644
646
  */
645
647
  interface AppCommandNative {
646
- command: SlashCommandBuilder | Record<string, any>;
648
+ command: CommandData | Record<string, any>;
647
649
  chatInput?: (ctx: Context) => Awaitable<unknown>;
648
650
  autocomplete?: (ctx: Context) => Awaitable<unknown>;
649
651
  message?: (ctx: Context) => Awaitable<unknown>;
@@ -706,6 +708,21 @@ interface PreparedAppCommandExecution {
706
708
  * Type representing command builder objects supported by CommandKit.
707
709
  */
708
710
  type CommandBuilderLike = SlashCommandBuilder | ContextMenuCommandBuilder | Record<string, any>;
711
+ /**
712
+ * @private
713
+ * @internal
714
+ */
715
+ declare const commandDataSchema: {
716
+ command: (c: unknown) => unknown;
717
+ chatInput: (c: unknown) => c is Function;
718
+ autocomplete: (c: unknown) => c is Function;
719
+ message: (c: unknown) => c is Function;
720
+ messageContextMenu: (c: unknown) => c is Function;
721
+ userContextMenu: (c: unknown) => c is Function;
722
+ };
723
+ type CommandDataSchema = typeof commandDataSchema;
724
+ type CommandDataSchemaKey = keyof CommandDataSchema;
725
+ type CommandDataSchemaValue = CommandDataSchema[CommandDataSchemaKey];
709
726
  /**
710
727
  * Handles application commands for CommandKit, including loading, registration, and execution.
711
728
  * Manages both slash commands and message commands with middleware support.
@@ -2024,5 +2041,5 @@ declare class CommandKit extends EventEmitter {
2024
2041
  */
2025
2042
  declare const commandkit: CommandKit;
2026
2043
  //#endregion
2027
- export { AnalyticsEngine, AnalyticsEvent, AnalyticsProvider, AnyCommandExecute, AppCommand, AppCommandHandler, AppCommandNative, AppCommandRunner, AppEventsHandler, AppEventsHandlerLoadedData, AsyncFunction, AutocompleteCommand, AutocompleteCommandContext, AutocompleteCommandMiddlewareContext, BootstrapFunction, ChatInputCommand, ChatInputCommandContext, CommandBuilderLike, CommandContext, CommandContextOptions, CommandData, CommandExecutionMode, CommandFlagContext, CommandKit, CommandKitConfiguration, CommandKitEnvironment, CommandKitEnvironmentInternalData, CommandKitEnvironmentType, CommandKitEventDispatch, CommandKitEventsChannel, CommandKitHMREvent, CommandKitOptions, CommandKitPlugin, CommandKitPluginRuntime, CommandRegistrar, CommandTypeData, CommonDirectiveTransformer, CommonDirectiveTransformerOptions, CommonPluginRuntime, CompilerPlugin, CompilerPluginRuntime, Context, ContextParameters, CustomAppCommandProps, CustomEvaluationContext, CustomEvaluationFunction, DecideFunction, EvaluationContext, EventFlagContext, EventListener, FeatureFlag, FeatureFlagDefinition, FilterFunction, FlagConfiguration, FlagProvider, FlagRunner, FlagStore, GenericFunction, IdentifyEvent, IdentifyFunction, InteractionCommandContext, InteractionCommandMiddlewareContext, IpcMessageCommand, JsonFlagProvider, ListenerFunction, LoadedCommand, LoadedEvent, MaybeFalsey, MaybePromise, MessageCommand, MessageCommandContext, MessageCommandMiddlewareContext, MessageContextMenuCommand, MessageContextMenuCommandContext, MessageContextMenuCommandMiddlewareContext, MiddlewareContext, MiddlewareContextArgs, PluginCommon, PluginOptions, PluginTransformParameters, PluginType, PreRegisterCommandsEvent, PreparedAppCommandExecution, ResolvableCommand, RunCommand, RunCommandOptions, RuntimePlugin, SlashCommandMiddlewareContext, TemplateHandler, TransformedResult, UserContextMenuCommand, UserContextMenuCommandContext, UserContextMenuCommandMiddlewareContext, after, cancelAfter, commandkit, exitContext, flag, getCommandKit, getContext, isCommandWorkerContext, isCompilerPlugin, isPlugin, isRuntimePlugin, makeContextAwareFunction, onApplicationBootstrap, onBootstrap, provideContext, registerDevHooks, setFlagProvider, useEnvironment };
2028
- //# sourceMappingURL=CommandKit-BWzWBBGf.d.ts.map
2044
+ export { AnalyticsEngine, AnalyticsEvent, AnalyticsProvider, AnyCommandExecute, AppCommand, AppCommandHandler, AppCommandNative, AppCommandRunner, AppEventsHandler, AppEventsHandlerLoadedData, AsyncFunction, AutocompleteCommand, AutocompleteCommandContext, AutocompleteCommandMiddlewareContext, BootstrapFunction, ChatInputCommand, ChatInputCommandContext, CommandBuilderLike, CommandContext, CommandContextOptions, CommandData, CommandDataSchema, CommandDataSchemaKey, CommandDataSchemaValue, CommandExecutionMode, CommandFlagContext, CommandKit, CommandKitConfiguration, CommandKitEnvironment, CommandKitEnvironmentInternalData, CommandKitEnvironmentType, CommandKitEventDispatch, CommandKitEventsChannel, CommandKitHMREvent, CommandKitOptions, CommandKitPlugin, CommandKitPluginRuntime, CommandRegistrar, CommandTypeData, CommonDirectiveTransformer, CommonDirectiveTransformerOptions, CommonPluginRuntime, CompilerPlugin, CompilerPluginRuntime, Context, ContextParameters, CustomAppCommandProps, CustomEvaluationContext, CustomEvaluationFunction, DecideFunction, EvaluationContext, EventFlagContext, EventListener, FeatureFlag, FeatureFlagDefinition, FilterFunction, FlagConfiguration, FlagProvider, FlagRunner, FlagStore, GenericFunction, IdentifyEvent, IdentifyFunction, InteractionCommandContext, InteractionCommandMiddlewareContext, IpcMessageCommand, JsonFlagProvider, ListenerFunction, LoadedCommand, LoadedEvent, MaybeFalsey, MaybePromise, MessageCommand, MessageCommandContext, MessageCommandMiddlewareContext, MessageContextMenuCommand, MessageContextMenuCommandContext, MessageContextMenuCommandMiddlewareContext, MiddlewareContext, MiddlewareContextArgs, PluginCommon, PluginOptions, PluginTransformParameters, PluginType, PreRegisterCommandsEvent, PreparedAppCommandExecution, ResolvableCommand, RunCommand, RunCommandOptions, RuntimePlugin, SlashCommandMiddlewareContext, TemplateHandler, TransformedResult, UserContextMenuCommand, UserContextMenuCommandContext, UserContextMenuCommandMiddlewareContext, after, cancelAfter, commandkit, exitContext, flag, getCommandKit, getContext, isCommandWorkerContext, isCompilerPlugin, isPlugin, isRuntimePlugin, makeContextAwareFunction, onApplicationBootstrap, onBootstrap, provideContext, registerDevHooks, setFlagProvider, useEnvironment };
2045
+ //# sourceMappingURL=CommandKit-BSXFD1Tt.d.ts.map