commandkit 1.0.0-dev.20250722021811 → 1.0.0-dev.20250723021937
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/ActionRow-CmTHbo2t.js.map +1 -1
- package/dist/CommandKitEventsChannel-BSdcgY3Q.js.map +1 -1
- package/dist/CommandsRouter-Bs9UuowL.js.map +1 -1
- package/dist/EventInterceptor-CQ4PBpBJ.js.map +1 -1
- package/dist/EventWorkerContext-DxfS_0fJ.js.map +1 -1
- package/dist/EventsRouter-B7oifgM6.js.map +1 -1
- package/dist/MessageCommandParser-CGhN3xNN.js.map +1 -1
- package/dist/PluginCommon-Di1xIa8d.js.map +1 -1
- package/dist/analytics/analytics-engine.js +1 -1
- package/dist/analytics/utils.js +1 -1
- package/dist/app/commands/AppCommandRunner.js +1 -1
- package/dist/app/commands/Context.js +1 -1
- package/dist/app/handlers/AppCommandHandler.js +1 -1
- package/dist/app/handlers/AppEventsHandler.js +1 -1
- package/dist/app/index.js +1 -1
- package/dist/app/register/CommandRegistrar.js +1 -1
- package/dist/app-process-CKLJAmil.js.map +1 -1
- package/dist/{build-BylWoAy4.js → build-D8P0ENm6.js} +2 -2
- package/dist/{build-BylWoAy4.js.map → build-D8P0ENm6.js.map} +1 -1
- package/dist/cli/build.js +2 -2
- package/dist/cli/common.d.ts +2 -2
- package/dist/cli/development.js +2 -2
- package/dist/cli/development.js.map +1 -1
- package/dist/cli/generators.js.map +1 -1
- package/dist/cli/information.js +1 -1
- package/dist/cli/information.js.map +1 -1
- package/dist/cli/init.d.ts +1 -1
- package/dist/cli/init.js +2 -2
- package/dist/cli/production.d.ts +2 -2
- package/dist/cli/production.js +2 -2
- package/dist/cli/production.js.map +1 -1
- package/dist/colors-Cd4Oz-r-.js.map +1 -1
- package/dist/{commandkit-DYYj5_OH.js → commandkit-CUFTPuzm.js} +24 -24
- package/dist/{commandkit-DYYj5_OH.js.map → commandkit-CUFTPuzm.js.map} +1 -1
- package/dist/commandkit.js +1 -1
- package/dist/common-DoZjgUs0.js.map +1 -1
- package/dist/common-vnMIelAE.js.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/v1/button/Button.js +1 -1
- package/dist/components/v1/button/ButtonKit.js +1 -1
- package/dist/components/v1/modal/Modal.js +1 -1
- package/dist/components/v1/modal/ModalKit.js +1 -1
- package/dist/components/v1/select-menu/ChannelSelectMenuKit.js +1 -1
- package/dist/components/v1/select-menu/MentionableSelectMenuKit.js +1 -1
- package/dist/components/v1/select-menu/RoleSelectMenuKit.js +1 -1
- package/dist/components/v1/select-menu/SelectMenu.js +1 -1
- package/dist/components/v1/select-menu/StringSelectMenuKit.js +1 -1
- package/dist/components/v1/select-menu/UserSelectMenuKit.js +1 -1
- package/dist/config/config.js +1 -1
- package/dist/config/default.js +1 -1
- package/dist/config/loader.js +1 -1
- package/dist/config/utils.js.map +1 -1
- package/dist/constants-DYSMm0U6.js.map +1 -1
- package/dist/constants-R96vEAFD.js.map +1 -1
- package/dist/container-DCjIgp-B.js.map +1 -1
- package/dist/context/async-context.js +1 -1
- package/dist/context/environment.js +1 -1
- package/dist/dotprops-C22abhGZ.js.map +1 -1
- package/dist/element-Bak9llw_.js.map +1 -1
- package/dist/env-DakvrBzy.js.map +1 -1
- package/dist/error-codes-C-ViHyu-.js.map +1 -1
- package/dist/{feature-flags-aCvzjoPi.js → feature-flags-CNRFFY4k.js} +2 -2
- package/dist/{feature-flags-aCvzjoPi.js.map → feature-flags-CNRFFY4k.js.map} +1 -1
- package/dist/file-DVZC0QXI.js.map +1 -1
- package/dist/flags/FlagProvider.js.map +1 -1
- package/dist/flags/feature-flags.js +2 -2
- package/dist/helpers-DfV6HlgI.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/{init-DsaK1AfD.d.ts → init-DOr-Y3GQ.d.ts} +3 -3
- package/dist/{init-5BxpQb8k.js → init-Dc4Qbgpg.js} +2 -2
- package/dist/{init-5BxpQb8k.js.map → init-Dc4Qbgpg.js.map} +1 -1
- package/dist/kv/kv.d.ts +1 -1
- package/dist/kv/kv.js.map +1 -1
- package/dist/logger/DefaultLogger.js +1 -1
- package/dist/logger/Logger.js +1 -1
- package/dist/media-gallery-CIKypjbJ.js.map +1 -1
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.js +1 -1
- package/dist/plugins/plugin-runtime/CompilerPluginRuntime.js +1 -1
- package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.js +1 -1
- package/dist/plugins/plugin-runtime/builtin/MacroPlugin.js +1 -1
- package/dist/resolve-file-url-9aPt6A_n.js.map +1 -1
- package/dist/section-CuYr0Inu.js.map +1 -1
- package/dist/serde-CXY4F7OD.js.map +1 -1
- package/dist/signals-Bu7gndaS.js.map +1 -1
- package/dist/text-display--p2-BoUa.js.map +1 -1
- package/dist/type-checker-DDHZIEBi.js.map +1 -1
- package/dist/types-package-Dwub9JsW.js.map +1 -1
- package/dist/utils/colors.d.ts +2 -2
- package/dist/utils/dev-hooks.js +1 -1
- package/dist/utils/useful-stuff/async-queue.js.map +1 -1
- package/dist/utils/useful-stuff/mutex.js.map +1 -1
- package/dist/utils/useful-stuff/ratelimiter.js.map +1 -1
- package/dist/utils/useful-stuff/semaphore.js.map +1 -1
- package/dist/utils/utilities.js +1 -1
- package/dist/utils/warn-unstable.js.map +1 -1
- package/dist/utils-n4MoGDDR.js.map +1 -1
- package/dist/{version-c0OD-7y_.js → version-DrMgT0Vo.js} +2 -2
- package/dist/{version-c0OD-7y_.js.map → version-DrMgT0Vo.js.map} +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionRow-CmTHbo2t.js","names":[],"sources":["../src/components/v1/action-row/ActionRow.ts"],"sourcesContent":["import { ActionRowBuilder } from 'discord.js';\nimport { AnyCommandKitElement, CommandKitElement } from '../../common/element';\n\n/**\n * The properties for the action row component.\n */\nexport interface ActionRowProps {\n children?: AnyCommandKitElement[] | AnyCommandKitElement;\n}\n\n/**\n * The action row component.\n * @param props The action row properties.\n * @returns The commandkit element.\n * @example <ActionRow><Button label=\"Click me\" style={ButtonStyle.Primary} customId=\"click_me\" /></ActionRow>\n */\nexport function ActionRow(\n props: ActionRowProps,\n): CommandKitElement<'action-row'> {\n const row = new ActionRowBuilder();\n\n if (Array.isArray(props.children)) {\n // @ts-ignore\n row.setComponents(...props.children);\n } else if (props.children) {\n // @ts-ignore\n row.setComponents(props.children);\n }\n\n return row;\n}\n"],"mappings":";;;;;;;;;;AAgBA,SAAgB,UAChB,OACkC;CAChC,MAAM,MAAM,IAAI;AAEhB,KAAI,MAAM,QAAQ,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"ActionRow-CmTHbo2t.js","names":[],"sources":["../src/components/v1/action-row/ActionRow.ts"],"sourcesContent":["import { ActionRowBuilder } from 'discord.js';\nimport { AnyCommandKitElement, CommandKitElement } from '../../common/element';\n\n/**\n * The properties for the action row component.\n */\nexport interface ActionRowProps {\n children?: AnyCommandKitElement[] | AnyCommandKitElement;\n}\n\n/**\n * The action row component.\n * @param props The action row properties.\n * @returns The commandkit element.\n * @example <ActionRow><Button label=\"Click me\" style={ButtonStyle.Primary} customId=\"click_me\" /></ActionRow>\n */\nexport function ActionRow(\n props: ActionRowProps,\n): CommandKitElement<'action-row'> {\n const row = new ActionRowBuilder();\n\n if (Array.isArray(props.children)) {\n // @ts-ignore\n row.setComponents(...props.children);\n } else if (props.children) {\n // @ts-ignore\n row.setComponents(props.children);\n }\n\n return row;\n}\n"],"mappings":";;;;;;;;;;AAgBA,SAAgB,UAChB,OACkC;CAChC,MAAM,MAAM,IAAI;AAEhB,KAAI,MAAM,QAAQ,MAAM,SAAS,EAE/B,IAAI,cAAc,GAAG,MAAM,SAAS;UAC3B,MAAM,UAEf,IAAI,cAAc,MAAM,SAAS;AAGnC,QAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandKitEventsChannel-BSdcgY3Q.js","names":[],"sources":["../src/events/CommandKitEventsChannel.ts"],"sourcesContent":["import EventEmitter from 'node:events';\nimport type { CommandKit } from '../commandkit';\nimport type { AsyncFunction, GenericFunction } from '../context/async-context';\n\n/**\n * The function type for event listeners.\n */\nexport type ListenerFunction = GenericFunction | AsyncFunction;\n\n/**\n * Represents a channel for emitting and listening to events in CommandKit.\n * This class provides methods to manage event listeners and emit events\n * within a specific namespace.\n */\nexport class CommandKitEventsChannel {\n private emitter = new EventEmitter();\n\n /**\n * Creates a new instance of CommandKitEventsChannel.\n * @param commandkit The CommandKit instance that this channel belongs to.\n */\n public constructor(public readonly commandkit: CommandKit) {}\n\n /**\n * Creates a namespaced event channel. This allows you to manage events\n * within a specific namespace, preventing conflicts with other event channels.\n * This is useful for organizing events related to different parts of your application.\n * @param namespace The namespace for the event channel.\n * @returns An object containing methods for managing events within the namespace.\n * @example commandkit.events.to('customNamespace').emit('eventName', data);\n */\n public to(namespace: string) {\n return {\n on: this.on.bind(this, namespace),\n off: this.off.bind(this, namespace),\n once: this.once.bind(this, namespace),\n emit: this.emit.bind(this, namespace),\n removeAllListeners: this.removeAllListeners.bind(this, namespace),\n };\n }\n\n /**\n * Register an event listener for a specific event within the namespace.\n * @param namespace The namespace for the event channel.\n * @param event The name of the event to listen for.\n * @param listener The function to call when the event is emitted.\n */\n public on(namespace: string, event: string, listener: ListenerFunction) {\n this.emitter.on(`${namespace}:${event}`, listener);\n }\n\n /**\n * Unregister an event listener for a specific event within the namespace.\n * @param namespace The namespace for the event channel.\n * @param event The name of the event to stop listening for.\n * @param listener The function that was registered as the listener.\n */\n public off(namespace: string, event: string, listener: ListenerFunction) {\n this.emitter.off(`${namespace}:${event}`, listener);\n }\n\n /**\n * Register an event listener that will be called only once for a specific event\n * within the namespace.\n * @param namespace The namespace for the event channel.\n * @param event The name of the event to listen for.\n * @param listener The function to call when the event is emitted.\n */\n public once(namespace: string, event: string, listener: ListenerFunction) {\n this.emitter.once(`${namespace}:${event}`, listener);\n }\n\n /**\n * Emit an event within the specified namespace, calling all registered listeners.\n * @param namespace The namespace for the event channel.\n * @param event The name of the event to emit.\n * @param args The arguments to pass to the listeners.\n * @returns A boolean indicating whether any listeners were called.\n */\n public emit(namespace: string, event: string, ...args: any[]) {\n return this.emitter.emit(`${namespace}:${event}`, ...args);\n }\n\n /**\n * Remove all listeners for a specific event or all events within the namespace.\n * @param namespace The namespace for the event channel.\n * @param event The name of the event to remove listeners for. If not provided, all listeners for all events in the namespace will be removed.\n */\n public removeAllListeners(namespace: string): void;\n public removeAllListeners(namespace: string, event: string): void;\n public removeAllListeners(namespace: string, event?: string): void {\n if (event) {\n this.emitter.removeAllListeners(`${namespace}:${event}`);\n } else {\n this.emitter.removeAllListeners(namespace);\n }\n }\n}\n"],"mappings":";;;;;;;;;AAcA,IAAa,0BAAb,MAAqC;CACnC,AAAQ,UAAU,IAAI;;;;;CAMtB,AAAO,YAA4B,YAAwB;EAAxB;CAAyB;;;;;;;;;CAU5D,AAAO,GAAG,WAAmB;AAC3B,SAAO;GACL,IAAI,KAAK,GAAG,KAAK,MAAM,UAAU;GACjC,KAAK,KAAK,IAAI,KAAK,MAAM,UAAU;GACnC,MAAM,KAAK,KAAK,KAAK,MAAM,UAAU;GACrC,MAAM,KAAK,KAAK,KAAK,MAAM,UAAU;GACrC,oBAAoB,KAAK,mBAAmB,KAAK,MAAM,UAAU;EAClE;CACH;;;;;;;CAQA,AAAO,GAAG,WAAmB,OAAe,UAA4B;
|
|
1
|
+
{"version":3,"file":"CommandKitEventsChannel-BSdcgY3Q.js","names":[],"sources":["../src/events/CommandKitEventsChannel.ts"],"sourcesContent":["import EventEmitter from 'node:events';\nimport type { CommandKit } from '../commandkit';\nimport type { AsyncFunction, GenericFunction } from '../context/async-context';\n\n/**\n * The function type for event listeners.\n */\nexport type ListenerFunction = GenericFunction | AsyncFunction;\n\n/**\n * Represents a channel for emitting and listening to events in CommandKit.\n * This class provides methods to manage event listeners and emit events\n * within a specific namespace.\n */\nexport class CommandKitEventsChannel {\n private emitter = new EventEmitter();\n\n /**\n * Creates a new instance of CommandKitEventsChannel.\n * @param commandkit The CommandKit instance that this channel belongs to.\n */\n public constructor(public readonly commandkit: CommandKit) {}\n\n /**\n * Creates a namespaced event channel. This allows you to manage events\n * within a specific namespace, preventing conflicts with other event channels.\n * This is useful for organizing events related to different parts of your application.\n * @param namespace The namespace for the event channel.\n * @returns An object containing methods for managing events within the namespace.\n * @example commandkit.events.to('customNamespace').emit('eventName', data);\n */\n public to(namespace: string) {\n return {\n on: this.on.bind(this, namespace),\n off: this.off.bind(this, namespace),\n once: this.once.bind(this, namespace),\n emit: this.emit.bind(this, namespace),\n removeAllListeners: this.removeAllListeners.bind(this, namespace),\n };\n }\n\n /**\n * Register an event listener for a specific event within the namespace.\n * @param namespace The namespace for the event channel.\n * @param event The name of the event to listen for.\n * @param listener The function to call when the event is emitted.\n */\n public on(namespace: string, event: string, listener: ListenerFunction) {\n this.emitter.on(`${namespace}:${event}`, listener);\n }\n\n /**\n * Unregister an event listener for a specific event within the namespace.\n * @param namespace The namespace for the event channel.\n * @param event The name of the event to stop listening for.\n * @param listener The function that was registered as the listener.\n */\n public off(namespace: string, event: string, listener: ListenerFunction) {\n this.emitter.off(`${namespace}:${event}`, listener);\n }\n\n /**\n * Register an event listener that will be called only once for a specific event\n * within the namespace.\n * @param namespace The namespace for the event channel.\n * @param event The name of the event to listen for.\n * @param listener The function to call when the event is emitted.\n */\n public once(namespace: string, event: string, listener: ListenerFunction) {\n this.emitter.once(`${namespace}:${event}`, listener);\n }\n\n /**\n * Emit an event within the specified namespace, calling all registered listeners.\n * @param namespace The namespace for the event channel.\n * @param event The name of the event to emit.\n * @param args The arguments to pass to the listeners.\n * @returns A boolean indicating whether any listeners were called.\n */\n public emit(namespace: string, event: string, ...args: any[]) {\n return this.emitter.emit(`${namespace}:${event}`, ...args);\n }\n\n /**\n * Remove all listeners for a specific event or all events within the namespace.\n * @param namespace The namespace for the event channel.\n * @param event The name of the event to remove listeners for. If not provided, all listeners for all events in the namespace will be removed.\n */\n public removeAllListeners(namespace: string): void;\n public removeAllListeners(namespace: string, event: string): void;\n public removeAllListeners(namespace: string, event?: string): void {\n if (event) {\n this.emitter.removeAllListeners(`${namespace}:${event}`);\n } else {\n this.emitter.removeAllListeners(namespace);\n }\n }\n}\n"],"mappings":";;;;;;;;;AAcA,IAAa,0BAAb,MAAqC;CACnC,AAAQ,UAAU,IAAI;;;;;CAMtB,AAAO,YAA4B,YAAwB;EAAxB;CAAyB;;;;;;;;;CAU5D,AAAO,GAAG,WAAmB;AAC3B,SAAO;GACL,IAAI,KAAK,GAAG,KAAK,MAAM,UAAU;GACjC,KAAK,KAAK,IAAI,KAAK,MAAM,UAAU;GACnC,MAAM,KAAK,KAAK,KAAK,MAAM,UAAU;GACrC,MAAM,KAAK,KAAK,KAAK,MAAM,UAAU;GACrC,oBAAoB,KAAK,mBAAmB,KAAK,MAAM,UAAU;EAClE;CACH;;;;;;;CAQA,AAAO,GAAG,WAAmB,OAAe,UAA4B;EACtE,KAAK,QAAQ,GAAG,GAAG,UAAU,CAAC,EAAE,OAAO,EAAE,SAAS;CACpD;;;;;;;CAQA,AAAO,IAAI,WAAmB,OAAe,UAA4B;EACvE,KAAK,QAAQ,IAAI,GAAG,UAAU,CAAC,EAAE,OAAO,EAAE,SAAS;CACrD;;;;;;;;CASA,AAAO,KAAK,WAAmB,OAAe,UAA4B;EACxE,KAAK,QAAQ,KAAK,GAAG,UAAU,CAAC,EAAE,OAAO,EAAE,SAAS;CACtD;;;;;;;;CASA,AAAO,KAAK,WAAmB,OAAe,GAAG,MAAa;AAC5D,SAAO,KAAK,QAAQ,KAAK,GAAG,UAAU,CAAC,EAAE,OAAO,EAAE,GAAG,KAAK;CAC5D;CASA,AAAO,mBAAmB,WAAmB,OAAsB;AACjE,MAAI,OACF,KAAK,QAAQ,mBAAmB,GAAG,UAAU,CAAC,EAAE,OAAO,CAAC;OAExD,KAAK,QAAQ,mBAAmB,UAAU;CAE9C;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandsRouter-Bs9UuowL.js","names":[],"sources":["../src/app/router/CommandsRouter.ts"],"sourcesContent":["import { Collection } from 'discord.js';\nimport { Dirent, existsSync } from 'node:fs';\nimport { readdir } from 'node:fs/promises';\nimport { basename, extname, join, normalize } from 'node:path';\n\n/**\n * Represents a command with its metadata and middleware associations.\n */\nexport interface Command {\n id: string;\n name: string;\n path: string;\n relativePath: string;\n parentPath: string;\n middlewares: Array<string>;\n category: string | null;\n}\n\n/**\n * Represents a middleware with its metadata and scope.\n */\nexport interface Middleware {\n id: string;\n name: string;\n path: string;\n relativePath: string;\n parentPath: string;\n global: boolean;\n command: string | null;\n}\n\n/**\n * Data structure containing parsed commands and middleware.\n */\nexport interface ParsedCommandData {\n commands: Record<string, Command>;\n middlewares: Record<string, Middleware>;\n}\n\n/**\n * Configuration options for the commands router.\n */\nexport interface CommandsRouterOptions {\n entrypoint: string;\n}\n\n/**\n * @private\n * @internal\n */\nconst MIDDLEWARE_PATTERN = /^\\+middleware\\.(m|c)?(j|t)sx?$/;\n\n/**\n * @private\n * @internal\n */\nconst COMMAND_MIDDLEWARE_PATTERN =\n /^\\+([^+().][^().]*)\\.middleware\\.(m|c)?(j|t)sx?$/;\n\n/**\n * @private\n * @internal\n */\nconst GLOBAL_MIDDLEWARE_PATTERN = /^\\+global-middleware\\.(m|c)?(j|t)sx?$/;\n\n/**\n * @private\n * @internal\n */\nconst COMMAND_PATTERN = /^([^+().][^().]*)\\.(m|c)?(j|t)sx?$/;\n\n/**\n * @private\n * @internal\n */\nconst CATEGORY_PATTERN = /^\\(.+\\)$/;\n\n/**\n * Handles discovery and parsing of command and middleware files in the filesystem.\n */\nexport class CommandsRouter {\n /**\n * @private\n * @internal\n */\n private commands = new Collection<string, Command>();\n\n /**\n * @private\n * @internal\n */\n private middlewares = new Collection<string, Middleware>();\n\n /**\n * Creates a new CommandsRouter instance.\n * @param options - Configuration options for the router\n */\n public constructor(private readonly options: CommandsRouterOptions) {}\n\n /**\n * Populates the router with existing command and middleware data.\n * @param data - Parsed command data to populate with\n */\n public populate(data: ParsedCommandData) {\n for (const [id, command] of Object.entries(data.commands)) {\n this.commands.set(id, command);\n }\n\n for (const [id, middleware] of Object.entries(data.middlewares)) {\n this.middlewares.set(id, middleware);\n }\n }\n\n /**\n * Checks if the configured entrypoint path exists.\n * @returns True if the path exists\n */\n public isValidPath(): boolean {\n return existsSync(this.options.entrypoint);\n }\n\n /**\n * @private\n * @internal\n */\n private isCommand(name: string): boolean {\n return COMMAND_PATTERN.test(name);\n }\n\n /**\n * @private\n * @internal\n */\n private isMiddleware(name: string): boolean {\n return (\n MIDDLEWARE_PATTERN.test(name) ||\n GLOBAL_MIDDLEWARE_PATTERN.test(name) ||\n COMMAND_MIDDLEWARE_PATTERN.test(name)\n );\n }\n\n /**\n * @private\n * @internal\n */\n private isCategory(name: string): boolean {\n return CATEGORY_PATTERN.test(name);\n }\n\n /**\n * Clears all loaded commands and middleware.\n */\n public clear() {\n this.commands.clear();\n this.middlewares.clear();\n }\n\n /**\n * Scans the filesystem for commands and middleware files.\n * @returns Parsed command data\n */\n public async scan() {\n const entries = await readdir(this.options.entrypoint, {\n withFileTypes: true,\n });\n\n for (const entry of entries) {\n // ignore _ prefixed files\n if (entry.name.startsWith('_')) continue;\n\n const fullPath = join(this.options.entrypoint, entry.name);\n\n if (entry.isDirectory()) {\n const category = this.isCategory(entry.name)\n ? entry.name.slice(1, -1)\n : null;\n\n await this.traverse(fullPath, category);\n } else {\n await this.handle(entry);\n }\n }\n\n await this.applyMiddlewares();\n\n return this.toJSON();\n }\n\n /**\n * Gets the raw command and middleware collections.\n * @returns Object containing commands and middlewares collections\n */\n public getData() {\n return {\n commands: this.commands,\n middlewares: this.middlewares,\n };\n }\n\n /**\n * Converts the loaded data to a JSON-serializable format.\n * @returns Plain object with commands and middlewares\n */\n public toJSON() {\n return {\n commands: Object.fromEntries(this.commands.entries()),\n middlewares: Object.fromEntries(this.middlewares.entries()),\n };\n }\n\n /**\n * @private\n * @internal\n */\n private async traverse(path: string, category: string | null) {\n const entries = await readdir(path, {\n withFileTypes: true,\n });\n\n for (const entry of entries) {\n // ignore _ prefixed files\n if (entry.name.startsWith('_')) continue;\n\n if (entry.isFile()) {\n if (this.isCommand(entry.name) || this.isMiddleware(entry.name)) {\n await this.handle(entry, category);\n }\n } else if (\n entry.isDirectory() &&\n this.isCategory(entry.name) &&\n category\n ) {\n // nested category\n const nestedCategory = this.isCategory(entry.name)\n ? `${category}:${entry.name.slice(1, -1)}`\n : null;\n await this.traverse(join(path, entry.name), nestedCategory);\n }\n\n // TODO: handle subcommands\n }\n }\n\n /**\n * @private\n * @internal\n */\n private async handle(entry: Dirent, category: string | null = null) {\n const name = entry.name;\n const path = join(entry.parentPath, entry.name);\n\n if (this.isCommand(name)) {\n const command: Command = {\n id: crypto.randomUUID(),\n name: basename(path, extname(path)),\n path,\n category,\n parentPath: entry.parentPath,\n relativePath: this.replaceEntrypoint(path),\n middlewares: [],\n };\n\n this.commands.set(command.id, command);\n } else if (this.isMiddleware(name)) {\n const middleware: Middleware = {\n id: crypto.randomUUID(),\n name: basename(path, extname(path)),\n path,\n relativePath: this.replaceEntrypoint(path),\n parentPath: entry.parentPath,\n global: GLOBAL_MIDDLEWARE_PATTERN.test(name),\n command: COMMAND_MIDDLEWARE_PATTERN.test(name)\n ? name.split('.')[0] || null\n : null,\n };\n\n this.middlewares.set(middleware.id, middleware);\n }\n }\n\n /**\n * @private\n * @internal\n */\n private applyMiddlewares() {\n this.commands.forEach((command) => {\n const commandPath = command.parentPath;\n const samePathMiddlewares = Array.from(this.middlewares.values())\n .filter((middleware) => {\n if (middleware.global) return true;\n if (middleware.command) return middleware.command === command.name;\n return middleware.parentPath === commandPath;\n })\n .map((middleware) => middleware.id);\n\n command.middlewares = Array.from(\n new Set([...command.middlewares, ...samePathMiddlewares]),\n );\n });\n }\n\n /**\n * @private\n * @internal\n */\n private replaceEntrypoint(path: string) {\n const normalized = normalize(path);\n return normalized.replace(this.options.entrypoint, '');\n }\n}\n"],"mappings":";;;;;;;;;;;AAkDA,MAAM,qBAAqB;;;;;AAM3B,MAAM,6BACN;;;;;AAMA,MAAM,4BAA4B;;;;;AAMlC,MAAM,kBAAkB;;;;;AAMxB,MAAM,mBAAmB;;;;AAKzB,IAAa,iBAAb,MAA4B;;;;;CAK1B,AAAQ,WAAW,IAAI;;;;;CAMvB,AAAQ,cAAc,IAAI;;;;;CAM1B,AAAO,YAA6B,SAAgC;EAAhC;CAAiC;;;;;CAMrE,AAAO,SAAS,MAAyB;AACvC,OAAK,MAAM,CAAC,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,SAAS,CACvD,MAAK,SAAS,IAAI,IAAI,QAAQ;AAGhC,OAAK,MAAM,CAAC,IAAI,WAAW,IAAI,OAAO,QAAQ,KAAK,YAAY,CAC7D,MAAK,YAAY,IAAI,IAAI,WAAW;CAExC;;;;;CAMA,AAAO,cAAuB;AAC5B,SAAO,wBAAW,KAAK,QAAQ,WAAW;CAC5C;;;;;CAMA,AAAQ,UAAU,MAAuB;AACvC,SAAO,gBAAgB,KAAK,KAAK;CACnC;;;;;CAMA,AAAQ,aAAa,MAAuB;AAC1C,SACE,mBAAmB,KAAK,KAAK,IAC7B,0BAA0B,KAAK,KAAK,IACpC,2BAA2B,KAAK,KAAI;CAExC;;;;;CAMA,AAAQ,WAAW,MAAuB;AACxC,SAAO,iBAAiB,KAAK,KAAK;CACpC;;;;CAKA,AAAO,QAAQ;AACb,OAAK,SAAS,OAAO;AACrB,OAAK,YAAY,OAAO;CAC1B;;;;;CAMA,MAAa,OAAO;EAClB,MAAM,UAAU,MAAM,8BAAQ,KAAK,QAAQ,YAAY,EACrD,eAAe,KAChB,EAAC;AAEF,OAAK,MAAM,SAAS,SAAS;AAE3B,OAAI,MAAM,KAAK,WAAW,IAAI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} from 'discord.js';\nimport { Dirent, existsSync } from 'node:fs';\nimport { readdir } from 'node:fs/promises';\nimport { basename, extname, join, normalize } from 'node:path';\n\n/**\n * Represents a command with its metadata and middleware associations.\n */\nexport interface Command {\n id: string;\n name: string;\n path: string;\n relativePath: string;\n parentPath: string;\n middlewares: Array<string>;\n category: string | null;\n}\n\n/**\n * Represents a middleware with its metadata and scope.\n */\nexport interface Middleware {\n id: string;\n name: string;\n path: string;\n relativePath: string;\n parentPath: string;\n global: boolean;\n command: string | null;\n}\n\n/**\n * Data structure containing parsed commands and middleware.\n */\nexport interface ParsedCommandData {\n commands: Record<string, Command>;\n middlewares: Record<string, Middleware>;\n}\n\n/**\n * Configuration options for the commands router.\n */\nexport interface CommandsRouterOptions {\n entrypoint: string;\n}\n\n/**\n * @private\n * @internal\n */\nconst MIDDLEWARE_PATTERN = /^\\+middleware\\.(m|c)?(j|t)sx?$/;\n\n/**\n * @private\n * @internal\n */\nconst COMMAND_MIDDLEWARE_PATTERN =\n /^\\+([^+().][^().]*)\\.middleware\\.(m|c)?(j|t)sx?$/;\n\n/**\n * @private\n * @internal\n */\nconst GLOBAL_MIDDLEWARE_PATTERN = /^\\+global-middleware\\.(m|c)?(j|t)sx?$/;\n\n/**\n * @private\n * @internal\n */\nconst COMMAND_PATTERN = /^([^+().][^().]*)\\.(m|c)?(j|t)sx?$/;\n\n/**\n * @private\n * @internal\n */\nconst CATEGORY_PATTERN = /^\\(.+\\)$/;\n\n/**\n * Handles discovery and parsing of command and middleware files in the filesystem.\n */\nexport class CommandsRouter {\n /**\n * @private\n * @internal\n */\n private commands = new Collection<string, Command>();\n\n /**\n * @private\n * @internal\n */\n private middlewares = new Collection<string, Middleware>();\n\n /**\n * Creates a new CommandsRouter instance.\n * @param options - Configuration options for the router\n */\n public constructor(private readonly options: CommandsRouterOptions) {}\n\n /**\n * Populates the router with existing command and middleware data.\n * @param data - Parsed command data to populate with\n */\n public populate(data: ParsedCommandData) {\n for (const [id, command] of Object.entries(data.commands)) {\n this.commands.set(id, command);\n }\n\n for (const [id, middleware] of Object.entries(data.middlewares)) {\n this.middlewares.set(id, middleware);\n }\n }\n\n /**\n * Checks if the configured entrypoint path exists.\n * @returns True if the path exists\n */\n public isValidPath(): boolean {\n return existsSync(this.options.entrypoint);\n }\n\n /**\n * @private\n * @internal\n */\n private isCommand(name: string): boolean {\n return COMMAND_PATTERN.test(name);\n }\n\n /**\n * @private\n * @internal\n */\n private isMiddleware(name: string): boolean {\n return (\n MIDDLEWARE_PATTERN.test(name) ||\n GLOBAL_MIDDLEWARE_PATTERN.test(name) ||\n COMMAND_MIDDLEWARE_PATTERN.test(name)\n );\n }\n\n /**\n * @private\n * @internal\n */\n private isCategory(name: string): boolean {\n return CATEGORY_PATTERN.test(name);\n }\n\n /**\n * Clears all loaded commands and middleware.\n */\n public clear() {\n this.commands.clear();\n this.middlewares.clear();\n }\n\n /**\n * Scans the filesystem for commands and middleware files.\n * @returns Parsed command data\n */\n public async scan() {\n const entries = await readdir(this.options.entrypoint, {\n withFileTypes: true,\n });\n\n for (const entry of entries) {\n // ignore _ prefixed files\n if (entry.name.startsWith('_')) continue;\n\n const fullPath = join(this.options.entrypoint, entry.name);\n\n if (entry.isDirectory()) {\n const category = this.isCategory(entry.name)\n ? entry.name.slice(1, -1)\n : null;\n\n await this.traverse(fullPath, category);\n } else {\n await this.handle(entry);\n }\n }\n\n await this.applyMiddlewares();\n\n return this.toJSON();\n }\n\n /**\n * Gets the raw command and middleware collections.\n * @returns Object containing commands and middlewares collections\n */\n public getData() {\n return {\n commands: this.commands,\n middlewares: this.middlewares,\n };\n }\n\n /**\n * Converts the loaded data to a JSON-serializable format.\n * @returns Plain object with commands and middlewares\n */\n public toJSON() {\n return {\n commands: Object.fromEntries(this.commands.entries()),\n middlewares: Object.fromEntries(this.middlewares.entries()),\n };\n }\n\n /**\n * @private\n * @internal\n */\n private async traverse(path: string, category: string | null) {\n const entries = await readdir(path, {\n withFileTypes: true,\n });\n\n for (const entry of entries) {\n // ignore _ prefixed files\n if (entry.name.startsWith('_')) continue;\n\n if (entry.isFile()) {\n if (this.isCommand(entry.name) || this.isMiddleware(entry.name)) {\n await this.handle(entry, category);\n }\n } else if (\n entry.isDirectory() &&\n this.isCategory(entry.name) &&\n category\n ) {\n // nested category\n const nestedCategory = this.isCategory(entry.name)\n ? `${category}:${entry.name.slice(1, -1)}`\n : null;\n await this.traverse(join(path, entry.name), nestedCategory);\n }\n\n // TODO: handle subcommands\n }\n }\n\n /**\n * @private\n * @internal\n */\n private async handle(entry: Dirent, category: string | null = null) {\n const name = entry.name;\n const path = join(entry.parentPath, entry.name);\n\n if (this.isCommand(name)) {\n const command: Command = {\n id: crypto.randomUUID(),\n name: basename(path, extname(path)),\n path,\n category,\n parentPath: entry.parentPath,\n relativePath: this.replaceEntrypoint(path),\n middlewares: [],\n };\n\n this.commands.set(command.id, command);\n } else if (this.isMiddleware(name)) {\n const middleware: Middleware = {\n id: crypto.randomUUID(),\n name: basename(path, extname(path)),\n path,\n relativePath: this.replaceEntrypoint(path),\n parentPath: entry.parentPath,\n global: GLOBAL_MIDDLEWARE_PATTERN.test(name),\n command: COMMAND_MIDDLEWARE_PATTERN.test(name)\n ? name.split('.')[0] || null\n : null,\n };\n\n this.middlewares.set(middleware.id, middleware);\n }\n }\n\n /**\n * @private\n * @internal\n */\n private applyMiddlewares() {\n this.commands.forEach((command) => {\n const commandPath = command.parentPath;\n const samePathMiddlewares = Array.from(this.middlewares.values())\n .filter((middleware) => {\n if (middleware.global) return true;\n if (middleware.command) return middleware.command === command.name;\n return middleware.parentPath === commandPath;\n })\n .map((middleware) => middleware.id);\n\n command.middlewares = Array.from(\n new Set([...command.middlewares, ...samePathMiddlewares]),\n );\n });\n }\n\n /**\n * @private\n * @internal\n */\n private replaceEntrypoint(path: string) {\n const normalized = normalize(path);\n return normalized.replace(this.options.entrypoint, '');\n }\n}\n"],"mappings":";;;;;;;;;;;AAkDA,MAAM,qBAAqB;;;;;AAM3B,MAAM,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I,QAAQ;EACvC,WAAU,KAAK,aAAa,KAAK,EAAE;GAClC,MAAM,aAAyB;IAC7B,IAAI,OAAO,YAAY;IACvB,8BAAe,6BAAc,KAAK,CAAC;IACnC;IACA,cAAc,KAAK,kBAAkB,KAAK;IAC1C,YAAY,MAAM;IAClB,QAAQ,0BAA0B,KAAK,KAAK;IAC5C,SAAS,2BAA2B,KAAK,KAAI,GAC7C,KAAK,MAAM,IAAI,CAAC,MAAM,OACtB;GACD;GAED,KAAK,YAAY,IAAI,WAAW,IAAI,WAAW;EACjD;CACF;;;;;CAMA,AAAQ,mBAAmB;EACzB,KAAK,SAAS,QAAQ,CAAC,YAAY;GACjC,MAAM,cAAc,QAAQ;GAC5B,MAAM,sBAAsB,MAAM,KAAK,KAAK,YAAY,QAAQ,CAAA,CAChE,OAAO,CAAC,eAAe;AACrB,QAAI,WAAW,OAAQ,QAAO;AAC9B,QAAI,WAAW,QAAS,QAAO,WAAW,YAAY,QAAQ;AAC9D,WAAO,WAAW,eAAe;GAClC,EAAC,CACF,IAAI,CAAC,eAAe,WAAW,GAAG;GAElC,QAAQ,cAAc,MAAM,KAC1B,IAAI,IAAI,CAAC,GAAG,QAAQ,aAAa,GAAG,mBAAoB,GACzD;EACF,EAAC;CACJ;;;;;CAMA,AAAQ,kBAAkB,MAAc;EACtC,MAAM,sCAAuB,KAAK;AAClC,SAAO,WAAW,QAAQ,KAAK,QAAQ,YAAY,GAAG;CACxD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventInterceptor-CQ4PBpBJ.js","names":[],"sources":["../src/components/common/EventInterceptor.ts"],"sourcesContent":["import { Awaitable, Client, ClientEvents, Events } from 'discord.js';\n\nexport interface EventInterceptorContextData<E extends keyof ClientEvents> {\n /**\n * The filter to use for the collector.\n */\n filter?: (...args: ClientEvents[E]) => Awaitable<boolean>;\n /**\n * The duration (in ms) that the collector should run for.\n */\n time?: number;\n /**\n * If the collector should automatically reset the timer when a button is clicked.\n */\n autoReset?: boolean;\n /**\n * Whether the collector should run only once.\n */\n once?: boolean;\n /**\n * The handler to run when the collector ends.\n */\n onEnd?: (reason: string) => Awaitable<void>;\n /**\n * The handler to run upon an error.\n */\n onError?: EventInterceptorErrorHandler;\n}\n\n/**\n * The error handler for the event interceptor.\n */\nexport type EventInterceptorErrorHandler = (error: Error) => Awaitable<void>;\n\n/**\n * The event interceptor class that allows subscribing to events and handling them with custom logic.\n * It also supports automatic cleanup of expired subscriptions.\n */\nexport class EventInterceptor {\n private subscribers = new Map<\n keyof ClientEvents,\n Set<(...args: any[]) => void>\n >();\n private globalHandlers = new Map<\n keyof ClientEvents,\n (...args: any[]) => void\n >();\n private cleanupTimer: NodeJS.Timeout | null = null;\n\n /**\n * Creates the event interceptor.\n */\n public constructor(public readonly client: Client) {\n this.#cleanupLoop();\n }\n\n #cleanupLoop() {\n if (this.cleanupTimer) clearInterval(this.cleanupTimer);\n\n this.cleanupTimer = setInterval(() => {\n for (const [event, handlers] of this.subscribers) {\n for (const handler of handlers) {\n const options = Reflect.get(\n handler,\n 'options',\n ) as EventInterceptorContextData<keyof ClientEvents> & {\n registeredAt: number;\n };\n\n const isExpired =\n options.time && Date.now() - options.registeredAt > options.time;\n\n if (isExpired) {\n this.unsubscribe(event, handler, 'time');\n }\n }\n }\n }, 60_000).unref();\n }\n\n /**\n * Destroys the event interceptor.\n */\n public destroy(): void {\n if (this.cleanupTimer) {\n clearInterval(this.cleanupTimer);\n this.cleanupTimer = null;\n }\n\n for (const [event, handlers] of this.subscribers) {\n for (const handler of handlers) {\n this.unsubscribe(event, handler, 'destroy');\n }\n }\n\n this.subscribers.clear();\n this.globalHandlers.clear();\n }\n\n /**\n * Whether the event has subscribers.\n * @param event The event to check.\n */\n public hasSubscribers(event: keyof ClientEvents): boolean {\n return this.subscribers.has(event);\n }\n\n /**\n * Returns the number of subscribers for the event.\n * @param event The event to check.\n */\n public getSubscriberCount(event: keyof ClientEvents): number {\n const handlers = this.subscribers.get(event);\n return handlers?.size ?? 0;\n }\n\n /**\n * Whether the event has global handlers.\n */\n public hasGlobalHandlers(): boolean {\n return this.globalHandlers.size > 0;\n }\n\n /**\n * Returns the number of global handlers.\n */\n public getGlobalHandlersCount(): number {\n return this.subscribers.size;\n }\n\n /**\n * Subscribes to an event.\n * @param event The event to subscribe to.\n * @param listener The listener to call when the event is emitted.\n * @returns A function to unsubscribe from the event.\n */\n public subscribe<Event extends keyof ClientEvents>(\n event: Event,\n listener: (...args: ClientEvents[Event]) => void,\n options?: EventInterceptorContextData<Event>,\n ): () => void {\n if (!this.subscribers.has(event)) {\n this.subscribers.set(event, new Set());\n this.client.on(event, this.createGlobalHandler(event));\n this.client.setMaxListeners(this.client.getMaxListeners() + 1);\n }\n\n options ??= {};\n\n // @ts-ignore\n options.registeredAt = Date.now();\n\n Reflect.set(listener, 'options', options);\n\n this.subscribers.get(event)!.add(listener);\n\n return () => {\n this.unsubscribe(event, listener);\n };\n }\n\n /**\n * Unsubscribes from an event.\n * @param event The event to unsubscribe from.\n */\n public unsubscribe<Event extends keyof ClientEvents>(\n event: Event,\n listener: (...args: ClientEvents[Event]) => void,\n reason?: string,\n ): void {\n const handlers = this.subscribers.get(event);\n if (!handlers) return;\n\n handlers.delete(listener);\n\n if (handlers.size < 1) {\n this.subscribers.delete(event);\n this.client.removeListener(event, this.globalHandlers.get(event)!);\n this.globalHandlers.delete(event);\n this.client.setMaxListeners(\n Math.max(this.client.getMaxListeners() - 1, 0),\n );\n }\n\n Reflect.get(listener, 'options').onEnd?.(reason ?? 'unsubscribe');\n }\n\n /**\n * Creates a global handler for the event.\n * @param event The event to create a global handler for.\n * @returns The global handler.\n */\n private createGlobalHandler<Event extends keyof ClientEvents>(\n event: Event,\n ): (...args: ClientEvents[Event]) => void {\n if (this.globalHandlers.has(event)) {\n return this.globalHandlers.get(event)!;\n }\n\n const handler = async (...args: ClientEvents[Event]) => {\n const subscribers = this.subscribers.get(event);\n if (subscribers && subscribers.size > 0) {\n for (const subscriber of subscribers) {\n const options = Reflect.get(\n subscriber,\n 'options',\n ) as EventInterceptorContextData<Event> & { registeredAt: number };\n\n const isExpired =\n options.time && Date.now() - options.registeredAt > options.time;\n\n if (isExpired) {\n this.unsubscribe(event, subscriber, 'time');\n continue;\n }\n\n if (options.autoReset) {\n options.registeredAt = Date.now();\n }\n\n if (options.filter && !(await options.filter(...args))) {\n continue;\n }\n\n try {\n await subscriber(...args);\n } catch (e) {\n if (options.onError) {\n await options.onError(<Error>e);\n } else {\n throw e;\n }\n } finally {\n if (options.once) {\n this.unsubscribe(event, subscriber, 'once');\n }\n }\n }\n }\n };\n\n this.globalHandlers.set(event, handler);\n\n return handler;\n }\n}\n"],"mappings":";;;;;;AAsCA,IAAa,mBAAb,MAA8B;CAC5B,AAAQ,8BAAc,IAAI;CAI1B,AAAQ,iCAAiB,IAAI;CAI7B,AAAQ,eAAsC;;;;CAK9C,AAAO,YAA4B,QAAgB;EAAhB;
|
|
1
|
+
{"version":3,"file":"EventInterceptor-CQ4PBpBJ.js","names":[],"sources":["../src/components/common/EventInterceptor.ts"],"sourcesContent":["import { Awaitable, Client, ClientEvents, Events } from 'discord.js';\n\nexport interface EventInterceptorContextData<E extends keyof ClientEvents> {\n /**\n * The filter to use for the collector.\n */\n filter?: (...args: ClientEvents[E]) => Awaitable<boolean>;\n /**\n * The duration (in ms) that the collector should run for.\n */\n time?: number;\n /**\n * If the collector should automatically reset the timer when a button is clicked.\n */\n autoReset?: boolean;\n /**\n * Whether the collector should run only once.\n */\n once?: boolean;\n /**\n * The handler to run when the collector ends.\n */\n onEnd?: (reason: string) => Awaitable<void>;\n /**\n * The handler to run upon an error.\n */\n onError?: EventInterceptorErrorHandler;\n}\n\n/**\n * The error handler for the event interceptor.\n */\nexport type EventInterceptorErrorHandler = (error: Error) => Awaitable<void>;\n\n/**\n * The event interceptor class that allows subscribing to events and handling them with custom logic.\n * It also supports automatic cleanup of expired subscriptions.\n */\nexport class EventInterceptor {\n private subscribers = new Map<\n keyof ClientEvents,\n Set<(...args: any[]) => void>\n >();\n private globalHandlers = new Map<\n keyof ClientEvents,\n (...args: any[]) => void\n >();\n private cleanupTimer: NodeJS.Timeout | null = null;\n\n /**\n * Creates the event interceptor.\n */\n public constructor(public readonly client: Client) {\n this.#cleanupLoop();\n }\n\n #cleanupLoop() {\n if (this.cleanupTimer) clearInterval(this.cleanupTimer);\n\n this.cleanupTimer = setInterval(() => {\n for (const [event, handlers] of this.subscribers) {\n for (const handler of handlers) {\n const options = Reflect.get(\n handler,\n 'options',\n ) as EventInterceptorContextData<keyof ClientEvents> & {\n registeredAt: number;\n };\n\n const isExpired =\n options.time && Date.now() - options.registeredAt > options.time;\n\n if (isExpired) {\n this.unsubscribe(event, handler, 'time');\n }\n }\n }\n }, 60_000).unref();\n }\n\n /**\n * Destroys the event interceptor.\n */\n public destroy(): void {\n if (this.cleanupTimer) {\n clearInterval(this.cleanupTimer);\n this.cleanupTimer = null;\n }\n\n for (const [event, handlers] of this.subscribers) {\n for (const handler of handlers) {\n this.unsubscribe(event, handler, 'destroy');\n }\n }\n\n this.subscribers.clear();\n this.globalHandlers.clear();\n }\n\n /**\n * Whether the event has subscribers.\n * @param event The event to check.\n */\n public hasSubscribers(event: keyof ClientEvents): boolean {\n return this.subscribers.has(event);\n }\n\n /**\n * Returns the number of subscribers for the event.\n * @param event The event to check.\n */\n public getSubscriberCount(event: keyof ClientEvents): number {\n const handlers = this.subscribers.get(event);\n return handlers?.size ?? 0;\n }\n\n /**\n * Whether the event has global handlers.\n */\n public hasGlobalHandlers(): boolean {\n return this.globalHandlers.size > 0;\n }\n\n /**\n * Returns the number of global handlers.\n */\n public getGlobalHandlersCount(): number {\n return this.subscribers.size;\n }\n\n /**\n * Subscribes to an event.\n * @param event The event to subscribe to.\n * @param listener The listener to call when the event is emitted.\n * @returns A function to unsubscribe from the event.\n */\n public subscribe<Event extends keyof ClientEvents>(\n event: Event,\n listener: (...args: ClientEvents[Event]) => void,\n options?: EventInterceptorContextData<Event>,\n ): () => void {\n if (!this.subscribers.has(event)) {\n this.subscribers.set(event, new Set());\n this.client.on(event, this.createGlobalHandler(event));\n this.client.setMaxListeners(this.client.getMaxListeners() + 1);\n }\n\n options ??= {};\n\n // @ts-ignore\n options.registeredAt = Date.now();\n\n Reflect.set(listener, 'options', options);\n\n this.subscribers.get(event)!.add(listener);\n\n return () => {\n this.unsubscribe(event, listener);\n };\n }\n\n /**\n * Unsubscribes from an event.\n * @param event The event to unsubscribe from.\n */\n public unsubscribe<Event extends keyof ClientEvents>(\n event: Event,\n listener: (...args: ClientEvents[Event]) => void,\n reason?: string,\n ): void {\n const handlers = this.subscribers.get(event);\n if (!handlers) return;\n\n handlers.delete(listener);\n\n if (handlers.size < 1) {\n this.subscribers.delete(event);\n this.client.removeListener(event, this.globalHandlers.get(event)!);\n this.globalHandlers.delete(event);\n this.client.setMaxListeners(\n Math.max(this.client.getMaxListeners() - 1, 0),\n );\n }\n\n Reflect.get(listener, 'options').onEnd?.(reason ?? 'unsubscribe');\n }\n\n /**\n * Creates a global handler for the event.\n * @param event The event to create a global handler for.\n * @returns The global handler.\n */\n private createGlobalHandler<Event extends keyof ClientEvents>(\n event: Event,\n ): (...args: ClientEvents[Event]) => void {\n if (this.globalHandlers.has(event)) {\n return this.globalHandlers.get(event)!;\n }\n\n const handler = async (...args: ClientEvents[Event]) => {\n const subscribers = this.subscribers.get(event);\n if (subscribers && subscribers.size > 0) {\n for (const subscriber of subscribers) {\n const options = Reflect.get(\n subscriber,\n 'options',\n ) as EventInterceptorContextData<Event> & { registeredAt: number };\n\n const isExpired =\n options.time && Date.now() - options.registeredAt > options.time;\n\n if (isExpired) {\n this.unsubscribe(event, subscriber, 'time');\n continue;\n }\n\n if (options.autoReset) {\n options.registeredAt = Date.now();\n }\n\n if (options.filter && !(await options.filter(...args))) {\n continue;\n }\n\n try {\n await subscriber(...args);\n } catch (e) {\n if (options.onError) {\n await options.onError(<Error>e);\n } else {\n throw e;\n }\n } finally {\n if (options.once) {\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OAAO,YAAY,OAAO;AAC3C;IACF;AAEA,QAAI,QAAQ,WACV,QAAQ,eAAe,KAAK,KAAK;AAGnC,QAAI,QAAQ,UAAU,CAAE,MAAM,QAAQ,OAAO,GAAG,KAAK,CACnD;AAGF,QAAI;KACF,MAAM,WAAW,GAAG,KAAK;IAC1B,SAAQ,GAAG;AACV,SAAI,QAAQ,SACV,MAAM,QAAQ,QAAgB,EAAC;SAE/B,OAAM;IAET,UAAS;AACR,SAAI,QAAQ,MACV,KAAK,YAAY,OAAO,YAAY,OAAO;IAE/C;GACF;EAEH;EAED,KAAK,eAAe,IAAI,OAAO,QAAQ;AAEvC,SAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventWorkerContext-DxfS_0fJ.js","names":[],"sources":["../src/app/events/EventWorkerContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport { ParsedEvent } from '../router';\nimport { CommandKit } from '../../commandkit';\n\n/**\n * Context object containing information about the currently executing event.\n */\nexport interface EventWorkerContext {\n event: string;\n namespace: string | null;\n data: ParsedEvent;\n commandkit: CommandKit;\n arguments: any[];\n variables: Map<string, any>;\n}\n\n/**\n * @private\n * @internal\n */\nconst kEventWorker = Symbol('commandkitEventWorker');\n\n/**\n * Async local storage for event worker context.\n */\nexport const eventWorkerContext = new AsyncLocalStorage<EventWorkerContext>();\n\n/**\n * Runs a callback within an event worker context.\n * @param context - The event worker context\n * @param callback - The callback to execute\n * @returns The result of the callback\n */\nexport function runInEventWorkerContext<T>(\n context: EventWorkerContext,\n callback: () => T,\n): T {\n Reflect.set(context, kEventWorker, true);\n\n return eventWorkerContext.run(context, callback);\n}\n\n/**\n * Gets the current event worker context.\n * @returns The current event worker context\n * @throws Error if no context is found\n */\nexport function getEventWorkerContext(): EventWorkerContext {\n const context = eventWorkerContext.getStore();\n\n if (!context) {\n throw new Error('Event worker context not found');\n }\n\n return context;\n}\n\n/**\n * Type guard to check if an object is an event worker context.\n * @param worker - The object to check\n * @returns True if the object is an event worker context\n */\nexport function isEventWorkerContext(\n worker: any,\n): worker is EventWorkerContext {\n return worker && Reflect.get(worker, kEventWorker) === true;\n}\n"],"mappings":";;;;;;;;AAoBA,MAAM,eAAe,OAAO,wBAAwB;;;;AAKpD,MAAa,qBAAqB,IAAI;;;;;;;AAQtC,SAAgB,wBAChB,SACA,UACI;
|
|
1
|
+
{"version":3,"file":"EventWorkerContext-DxfS_0fJ.js","names":[],"sources":["../src/app/events/EventWorkerContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport { ParsedEvent } from '../router';\nimport { CommandKit } from '../../commandkit';\n\n/**\n * Context object containing information about the currently executing event.\n */\nexport interface EventWorkerContext {\n event: string;\n namespace: string | null;\n data: ParsedEvent;\n commandkit: CommandKit;\n arguments: any[];\n variables: Map<string, any>;\n}\n\n/**\n * @private\n * @internal\n */\nconst kEventWorker = Symbol('commandkitEventWorker');\n\n/**\n * Async local storage for event worker context.\n */\nexport const eventWorkerContext = new AsyncLocalStorage<EventWorkerContext>();\n\n/**\n * Runs a callback within an event worker context.\n * @param context - The event worker context\n * @param callback - The callback to execute\n * @returns The result of the callback\n */\nexport function runInEventWorkerContext<T>(\n context: EventWorkerContext,\n callback: () => T,\n): T {\n Reflect.set(context, kEventWorker, true);\n\n return eventWorkerContext.run(context, callback);\n}\n\n/**\n * Gets the current event worker context.\n * @returns The current event worker context\n * @throws Error if no context is found\n */\nexport function getEventWorkerContext(): EventWorkerContext {\n const context = eventWorkerContext.getStore();\n\n if (!context) {\n throw new Error('Event worker context not found');\n }\n\n return context;\n}\n\n/**\n * Type guard to check if an object is an event worker context.\n * @param worker - The object to check\n * @returns True if the object is an event worker context\n */\nexport function isEventWorkerContext(\n worker: any,\n): worker is EventWorkerContext {\n return worker && Reflect.get(worker, kEventWorker) === true;\n}\n"],"mappings":";;;;;;;;AAoBA,MAAM,eAAe,OAAO,wBAAwB;;;;AAKpD,MAAa,qBAAqB,IAAI;;;;;;;AAQtC,SAAgB,wBAChB,SACA,UACI;CACF,QAAQ,IAAI,SAAS,cAAc,KAAK;AAExC,QAAO,mBAAmB,IAAI,SAAS,SAAS;AAClD;;;;;;AAOA,SAAgB,wBAA4C;CAC1D,MAAM,UAAU,mBAAmB,UAAU;AAE7C,KAAI,CAAC,QACH,OAAM,IAAI,MAAM;AAGlB,QAAO;AACT;;;;;;AAOA,SAAgB,qBAChB,QAC+B;AAC7B,QAAO,UAAU,QAAQ,IAAI,QAAQ,aAAa,KAAK;AACzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventsRouter-B7oifgM6.js","names":[],"sources":["../src/app/router/EventsRouter.ts"],"sourcesContent":["import { Collection } from 'discord.js';\nimport { existsSync } from 'node:fs';\nimport { readdir } from 'node:fs/promises';\nimport { join } from 'node:path';\n\n/**\n * Configuration options for the EventsRouter\n * @interface EventsRouterOptions\n */\nexport interface EventsRouterOptions {\n /** Root directory path where event handlers are located */\n entrypoints: string[];\n}\n\n/**\n * Represents a parsed event with its handlers\n * @interface ParsedEvent\n */\nexport interface ParsedEvent {\n /** Name of the event derived from directory name */\n event: string;\n /** Absolute path to the event directory */\n path: string;\n /** Array of file paths to event listener handlers */\n listeners: string[];\n /** Namespace of the event */\n namespace: string | null;\n}\n\n/** Collection of event names to their parsed metadata */\nexport type EventsTree = Record<string, ParsedEvent>;\n\n/**\n * Router for discovering and managing event handler files in a directory structure.\n * Events are represented by directories, and handlers are files within those directories.\n */\nexport class EventsRouter {\n /** Internal storage of parsed events */\n private events = new Collection<string, ParsedEvent>();\n\n /**\n * Creates a new EventsRouter instance\n * @param options - Configuration options for the router\n * @throws Error if entrypoint is not provided\n */\n public constructor(private options: EventsRouterOptions) {\n if (options.entrypoints) {\n options.entrypoints = Array.from(new Set(options.entrypoints));\n }\n\n if (!options.entrypoints?.length) {\n throw new Error('Entrypoint directory must be provided');\n }\n }\n\n /**\n * Adds new entrypoints to the router\n * @param entrypoints - Array of new entrypoint paths\n */\n public addEntrypoints(entrypoints: string[]) {\n this.options.entrypoints = Array.from(\n new Set([...this.options.entrypoints, ...entrypoints]),\n );\n }\n\n /**\n * Find a parsed event by its name\n * @param event - Name of the event to find\n * @returns Parsed event metadata or null if not found\n */\n public match(event: string): ParsedEvent | null {\n return this.events.get(event) ?? null;\n }\n\n /**\n * Get the entrypoint directory path\n * @returns Entrypoint directory path\n */\n public get entrypoints(): string[] {\n return this.options.entrypoints;\n }\n\n /**\n * Checks if the entrypoint path is valid\n */\n public isValidPath() {\n return this.entrypoints.every((entrypoint) => existsSync(entrypoint));\n }\n\n /**\n * Clear all parsed events\n */\n public clear() {\n this.events.clear();\n }\n\n /**\n * Reload and re-scan the entrypoint directory for events\n * @returns Promise resolving to the updated events tree\n */\n public async reload() {\n this.clear();\n return this.scan();\n }\n\n /**\n * Scan the entrypoint directory for events and their handlers\n * @returns Promise resolving to the events tree\n */\n public async scan(): Promise<EventsTree> {\n for (const entrypoint of this.entrypoints) {\n const dirs = await readdir(entrypoint, { withFileTypes: true });\n\n for (const dir of dirs) {\n if (dir.isDirectory()) {\n const path = join(entrypoint, dir.name);\n await this.scanEvent(dir.name, path, null, [], true);\n }\n }\n }\n\n return Object.fromEntries(this.events);\n }\n\n /**\n * Convert the internal events Collection to a plain object\n * @returns Events tree as a plain object\n */\n public toJSON(): EventsTree {\n return Object.fromEntries(this.events);\n }\n\n /**\n * Recursively scan a directory for event handlers\n * @param event - Name of the event\n * @param path - Path to the event directory\n * @param listeners - Array to collect listener file paths\n * @returns Promise resolving to the parsed event metadata\n */\n private async scanEvent(\n event: string,\n path: string,\n _namespace: string | null = null,\n listeners: string[] = [],\n isRoot = false,\n ): Promise<void> {\n const files = await readdir(path, { withFileTypes: true });\n const isNamespace = isRoot && /^\\(.+\\)$/.test(event);\n\n // if event = (something) pattern then namespace is something\n const namespace = isNamespace ? event.slice(1, -1) : (_namespace ?? null);\n\n files.sort((a, b) => a.name.localeCompare(b.name));\n\n for (const file of files) {\n if (file.name.startsWith('_')) continue;\n\n if (file.isDirectory()) {\n const nextPath = join(path, file.name);\n await this.scanEvent(file.name, nextPath, namespace, listeners);\n continue;\n }\n\n if (file.isFile() && /\\.(m|c)?(j|t)sx?$/.test(file.name)) {\n listeners.push(join(file.parentPath, file.name));\n }\n }\n\n if (!isNamespace) {\n const existing = this.events.get(event);\n\n if (existing) {\n existing.listeners = Array.from(\n new Set([...existing.listeners, ...listeners]),\n );\n\n return;\n }\n\n this.events.set(event, { event, path, listeners, namespace });\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAoCA,IAAa,eAAb,MAA0B;;CAExB,AAAQ,SAAS,IAAI;;;;;;CAOrB,AAAO,YAAoB,SAA8B;;EAA9B;AACzB,MAAI,QAAQ,
|
|
1
|
+
{"version":3,"file":"EventsRouter-B7oifgM6.js","names":[],"sources":["../src/app/router/EventsRouter.ts"],"sourcesContent":["import { Collection } from 'discord.js';\nimport { existsSync } from 'node:fs';\nimport { readdir } from 'node:fs/promises';\nimport { join } from 'node:path';\n\n/**\n * Configuration options for the EventsRouter\n * @interface EventsRouterOptions\n */\nexport interface EventsRouterOptions {\n /** Root directory path where event handlers are located */\n entrypoints: string[];\n}\n\n/**\n * Represents a parsed event with its handlers\n * @interface ParsedEvent\n */\nexport interface ParsedEvent {\n /** Name of the event derived from directory name */\n event: string;\n /** Absolute path to the event directory */\n path: string;\n /** Array of file paths to event listener handlers */\n listeners: string[];\n /** Namespace of the event */\n namespace: string | null;\n}\n\n/** Collection of event names to their parsed metadata */\nexport type EventsTree = Record<string, ParsedEvent>;\n\n/**\n * Router for discovering and managing event handler files in a directory structure.\n * Events are represented by directories, and handlers are files within those directories.\n */\nexport class EventsRouter {\n /** Internal storage of parsed events */\n private events = new Collection<string, ParsedEvent>();\n\n /**\n * Creates a new EventsRouter instance\n * @param options - Configuration options for the router\n * @throws Error if entrypoint is not provided\n */\n public constructor(private options: EventsRouterOptions) {\n if (options.entrypoints) {\n options.entrypoints = Array.from(new Set(options.entrypoints));\n }\n\n if (!options.entrypoints?.length) {\n throw new Error('Entrypoint directory must be provided');\n }\n }\n\n /**\n * Adds new entrypoints to the router\n * @param entrypoints - Array of new entrypoint paths\n */\n public addEntrypoints(entrypoints: string[]) {\n this.options.entrypoints = Array.from(\n new Set([...this.options.entrypoints, ...entrypoints]),\n );\n }\n\n /**\n * Find a parsed event by its name\n * @param event - Name of the event to find\n * @returns Parsed event metadata or null if not found\n */\n public match(event: string): ParsedEvent | null {\n return this.events.get(event) ?? null;\n }\n\n /**\n * Get the entrypoint directory path\n * @returns Entrypoint directory path\n */\n public get entrypoints(): string[] {\n return this.options.entrypoints;\n }\n\n /**\n * Checks if the entrypoint path is valid\n */\n public isValidPath() {\n return this.entrypoints.every((entrypoint) => existsSync(entrypoint));\n }\n\n /**\n * Clear all parsed events\n */\n public clear() {\n this.events.clear();\n }\n\n /**\n * Reload and re-scan the entrypoint directory for events\n * @returns Promise resolving to the updated events tree\n */\n public async reload() {\n this.clear();\n return this.scan();\n }\n\n /**\n * Scan the entrypoint directory for events and their handlers\n * @returns Promise resolving to the events tree\n */\n public async scan(): Promise<EventsTree> {\n for (const entrypoint of this.entrypoints) {\n const dirs = await readdir(entrypoint, { withFileTypes: true });\n\n for (const dir of dirs) {\n if (dir.isDirectory()) {\n const path = join(entrypoint, dir.name);\n await this.scanEvent(dir.name, path, null, [], true);\n }\n }\n }\n\n return Object.fromEntries(this.events);\n }\n\n /**\n * Convert the internal events Collection to a plain object\n * @returns Events tree as a plain object\n */\n public toJSON(): EventsTree {\n return Object.fromEntries(this.events);\n }\n\n /**\n * Recursively scan a directory for event handlers\n * @param event - Name of the event\n * @param path - Path to the event directory\n * @param listeners - Array to collect listener file paths\n * @returns Promise resolving to the parsed event metadata\n */\n private async scanEvent(\n event: string,\n path: string,\n _namespace: string | null = null,\n listeners: string[] = [],\n isRoot = false,\n ): Promise<void> {\n const files = await readdir(path, { withFileTypes: true });\n const isNamespace = isRoot && /^\\(.+\\)$/.test(event);\n\n // if event = (something) pattern then namespace is something\n const namespace = isNamespace ? event.slice(1, -1) : (_namespace ?? null);\n\n files.sort((a, b) => a.name.localeCompare(b.name));\n\n for (const file of files) {\n if (file.name.startsWith('_')) continue;\n\n if (file.isDirectory()) {\n const nextPath = join(path, file.name);\n await this.scanEvent(file.name, nextPath, namespace, listeners);\n continue;\n }\n\n if (file.isFile() && /\\.(m|c)?(j|t)sx?$/.test(file.name)) {\n listeners.push(join(file.parentPath, file.name));\n }\n }\n\n if (!isNamespace) {\n const existing = this.events.get(event);\n\n if (existing) {\n existing.listeners = Array.from(\n new Set([...existing.listeners, ...listeners]),\n );\n\n return;\n }\n\n this.events.set(event, { event, path, listeners, namespace });\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAoCA,IAAa,eAAb,MAA0B;;CAExB,AAAQ,SAAS,IAAI;;;;;;CAOrB,AAAO,YAAoB,SAA8B;;EAA9B;AACzB,MAAI,QAAQ,aACV,QAAQ,cAAc,MAAM,KAAK,IAAI,IAAI,QAAQ,aAAa;AAGhE,MAAI,0BAAC,QAAQ,yFAAa,QACxB,OAAM,IAAI,MAAM;CAEpB;;;;;CAMA,AAAO,eAAe,aAAuB;EAC3C,KAAK,QAAQ,cAAc,MAAM,KAC/B,IAAI,IAAI,CAAC,GAAG,KAAK,QAAQ,aAAa,GAAG,WAAY,GACtD;CACH;;;;;;CAOA,AAAO,MAAM,OAAmC;AAC9C,SAAO,KAAK,OAAO,IAAI,MAAM,IAAI;CACnC;;;;;CAMA,IAAW,cAAwB;AACjC,SAAO,KAAK,QAAQ;CACtB;;;;CAKA,AAAO,cAAc;AACnB,SAAO,KAAK,YAAY,MAAM,CAAC,uCAA0B,WAAW,CAAC;CACvE;;;;CAKA,AAAO,QAAQ;EACb,KAAK,OAAO,OAAO;CACrB;;;;;CAMA,MAAa,SAAS;EACpB,KAAK,OAAO;AACZ,SAAO,KAAK,MAAM;CACpB;;;;;CAMA,MAAa,OAA4B;AACvC,OAAK,MAAM,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AAC;EAC/D;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageCommandParser-CGhN3xNN.js","names":[],"sources":["../src/app/commands/MessageCommandParser.ts"],"sourcesContent":["import { Channel } from 'diagnostics_channel';\nimport {\n Message,\n ApplicationCommandOptionType,\n GuildMember,\n Attachment,\n User,\n Role,\n CommandInteractionOption,\n} from 'discord.js';\nimport {\n CommandKitErrorCodes,\n createCommandKitError,\n} from '../../utils/error-codes';\n\n/**\n * Represents a parsed message command with its components.\n */\nexport interface ParsedMessageCommand {\n command: string;\n options: { name: string; value: unknown }[];\n subcommand?: string;\n subcommandGroup?: string;\n}\n\n/**\n * Schema defining the types of options for a message command.\n */\nexport type MessageCommandOptionsSchema = Record<\n string,\n ApplicationCommandOptionType\n>;\n\n/**\n * Parses message content into structured command data with options and subcommands.\n */\nexport class MessageCommandParser {\n /**\n * @private\n * @internal\n */\n #parsed: ParsedMessageCommand | null = null;\n\n /**\n * @private\n * @internal\n */\n #options: MessageCommandOptions | null = null;\n\n /**\n * @private\n * @internal\n */\n #args: string[] = [];\n\n /**\n * Creates a new message command parser.\n * @param message - The Discord message to parse\n * @param prefix - Array of valid command prefixes\n * @param schema - Function that returns the options schema for a command\n */\n public constructor(\n public message: Message,\n private prefix: string[],\n private schema: (command: string) => MessageCommandOptionsSchema,\n ) {}\n\n /**\n * Gets the parsed command arguments.\n * @returns Array of command arguments\n */\n public getArgs() {\n void this.parse();\n return this.#args;\n }\n\n /**\n * Gets the message command options object for easy access to typed option values.\n */\n public get options() {\n if (!this.#options) {\n this.#options = new MessageCommandOptions(this);\n }\n\n return this.#options;\n }\n\n /**\n * Gets a specific option value by name.\n * @param name - The option name\n * @returns The option value or undefined if not found\n */\n public getOption<T>(name: string): T | undefined {\n return this.parse().options.find((o) => o.name === name)?.value as T;\n }\n\n /**\n * Gets the main command name.\n * @returns The command name\n */\n public getCommand(): string {\n return this.parse().command;\n }\n\n /**\n * Gets the subcommand name if present.\n * @returns The subcommand name or undefined\n */\n public getSubcommand(): string | undefined {\n return this.parse().subcommand;\n }\n\n /**\n * Gets the subcommand group name if present.\n * @returns The subcommand group name or undefined\n */\n public getSubcommandGroup(): string | undefined {\n return this.parse().subcommandGroup;\n }\n\n /**\n * Gets the prefix used in the message.\n * @returns The matched prefix or undefined\n */\n public getPrefix() {\n for (const p of this.prefix) {\n if (this.message.content.startsWith(p)) {\n return p;\n }\n }\n }\n\n /**\n * Gets the full command including subcommand group and subcommand.\n * @returns The complete command string\n */\n public getFullCommand() {\n return [this.getCommand(), this.getSubcommandGroup(), this.getSubcommand()]\n .filter((v) => v)\n .join(' ');\n }\n\n /**\n * Parses the message content into structured command data.\n * @returns The parsed command data\n */\n public parse(): ParsedMessageCommand {\n if (this.#parsed) {\n return this.#parsed;\n }\n\n const content = this.message.content;\n\n const prefix = this.getPrefix();\n\n if (!prefix) {\n throw createCommandKitError(CommandKitErrorCodes.InvalidCommandPrefix);\n }\n\n const parts = content.slice(prefix.length).trim().split(' ');\n const command = parts.shift();\n\n this.#args = parts;\n\n let subcommandGroup: string | undefined;\n let subcommand: string | undefined;\n\n if (command?.includes(':')) {\n const [, group, cmd] = command.split(':');\n\n if (!cmd && group) {\n subcommand = group;\n } else if (cmd && group) {\n subcommandGroup = group;\n subcommand = cmd;\n }\n }\n\n const schema = this.schema(\n [command, subcommandGroup, subcommand].filter(Boolean).join(' ').trim(),\n );\n\n const options = parts\n .map((part) => {\n try {\n const [name, value] = part.split(':');\n\n if (!(name in schema)) return null;\n\n switch (schema[name]) {\n case ApplicationCommandOptionType.Boolean:\n return { name, value: value === 'true' };\n case ApplicationCommandOptionType.Integer:\n return { name, value: parseInt(value, 10) };\n case ApplicationCommandOptionType.Number:\n return { name, value: parseFloat(value) };\n case ApplicationCommandOptionType.String:\n return { name, value };\n case ApplicationCommandOptionType.User:\n return {\n name,\n value: this.message.mentions.users.find((u) => {\n return u.id === value.replace(/[<@!>]/g, '');\n }),\n };\n case ApplicationCommandOptionType.Channel:\n return {\n name,\n value: this.message.mentions.channels.find((c) => {\n return c.id === value.replace(/[<#>]/g, '');\n }),\n };\n case ApplicationCommandOptionType.Role:\n return {\n name,\n value: this.message.mentions.roles.find((r) => {\n return r.id === value.replace(/[<@&>]/g, '');\n }),\n };\n case ApplicationCommandOptionType.Attachment:\n return {\n name,\n value: this.message.attachments.find((a) => {\n return a.name === value;\n }),\n };\n default:\n return null;\n }\n } catch {\n // Invalid option\n return null;\n }\n })\n .filter((v) => v !== null);\n\n this.#parsed = {\n command: command!,\n options,\n subcommand,\n subcommandGroup,\n };\n\n return this.#parsed;\n }\n}\n\n/**\n * Provides typed access to message command options with methods similar to Discord.js interaction options.\n */\nexport class MessageCommandOptions {\n /**\n * Creates a new message command options instance.\n * @param parser - The message command parser instance\n */\n public constructor(private parser: MessageCommandParser) {}\n\n /**\n * @private\n * @internal\n */\n private assertOption<T>(name: string, required = false) {\n const option = this.parser.getOption<T>(name);\n\n if (required && option === undefined) {\n throw new Error(`Option \"${name}\" is required.`);\n }\n\n return option ?? null;\n }\n\n /**\n * Gets a guild member from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The guild member or null if not found\n */\n getMember(name: string): GuildMember | null;\n getMember(name: string, required: true): GuildMember;\n getMember(name: string, required = false) {\n const user = this.assertOption<User>(name, required);\n const member = this.parser.message.guild?.members.cache.get(user?.id!);\n\n if (required && !member) {\n throw new Error(`Member \"${name}\" is required.`);\n }\n\n return member ?? null;\n }\n\n /**\n * Gets an attachment from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The attachment or null if not found\n */\n getAttachment(name: string): Attachment | null;\n getAttachment(name: string, required: true): Attachment;\n getAttachment(name: string, required = false) {\n return this.assertOption<Attachment>(name, required);\n }\n\n /**\n * Gets a boolean value from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The boolean value or null if not found\n */\n getBoolean(name: string): boolean | null;\n getBoolean(name: string, required: true): boolean;\n getBoolean(name: string, required = false) {\n return this.assertOption<boolean>(name, required);\n }\n\n /**\n * Gets a number value from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The number value or null if not found\n */\n getNumber(name: string): number | null;\n getNumber(name: string, required: true): number;\n getNumber(name: string, required = false) {\n return this.assertOption<number>(name, required);\n }\n\n /**\n * Gets a string value from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The string value or null if not found\n */\n getString(name: string): string | null;\n getString(name: string, required: true): string;\n getString(name: string, required = false) {\n return this.assertOption<string>(name, required);\n }\n\n /**\n * Gets an integer value from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The integer value or null if not found\n */\n getInteger(name: string): number | null;\n getInteger(name: string, required: true): number;\n getInteger(name: string, required = false) {\n return this.assertOption<number>(name, required);\n }\n\n /**\n * Gets a user from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The user or null if not found\n */\n getUser(name: string): User | null;\n getUser(name: string, required: true): User;\n getUser(name: string, required = false) {\n return this.assertOption<User>(name, required);\n }\n\n /**\n * Gets a channel from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The channel or null if not found\n */\n getChannel(name: string): Channel | null;\n getChannel(name: string, required: true): Channel;\n getChannel(name: string, required = false) {\n return this.assertOption<Channel>(name, required);\n }\n\n /**\n * Gets a role from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The role or null if not found\n */\n getRole(name: string): Role | null;\n getRole(name: string, required: true): Role;\n getRole(name: string, required = false) {\n return this.assertOption<Role>(name, required);\n }\n\n /**\n * Gets a mentionable (user, member, or role) from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The mentionable or null if not found\n */\n getMentionable(\n name: string,\n ): NonNullable<CommandInteractionOption['member' | 'role' | 'user']> | null;\n getMentionable(\n name: string,\n required: true,\n ): NonNullable<CommandInteractionOption['member' | 'role' | 'user']>;\n getMentionable(\n name: string,\n required = false,\n ): NonNullable<CommandInteractionOption['member' | 'role' | 'user']> | null {\n const target = this.assertOption(name, required);\n\n if (\n target instanceof GuildMember ||\n target instanceof User ||\n target instanceof Role\n ) {\n return target;\n }\n\n if (required) {\n throw new Error(`Mentionable \"${name}\" is required.`);\n }\n\n return null;\n }\n\n /**\n * Gets the subcommand name from the command.\n * @param required - Whether the subcommand is required\n * @returns The subcommand name or null if not found\n */\n getSubcommand(): string | null;\n getSubcommand(required: true): string;\n getSubcommand(required = false) {\n const sub = this.parser.getSubcommand();\n\n if (required && sub === undefined) {\n throw new Error('Subcommand is required.');\n }\n\n return sub ?? null;\n }\n\n /**\n * Gets the subcommand group name from the command.\n * @param required - Whether the subcommand group is required\n * @returns The subcommand group name or null if not found\n */\n getSubcommandGroup(): string | null;\n getSubcommandGroup(required: true): string;\n getSubcommandGroup(required = false) {\n const sub = this.parser.getSubcommandGroup();\n\n if (required && sub === undefined) {\n throw new Error('Subcommand group is required.');\n }\n\n return sub ?? null;\n }\n}\n"],"mappings":";;;;;;;;AAoCA,IAAa,uBAAb,MAAkC;;;;;CAKhC,UAAuC;;;;;CAMvC,WAAyC;;;;;CAMzC,QAAkB,CAAE;;;;;;;CAQpB,AAAO,YACA,SACC,QACA,QACR;EAHO;EACC;EACA;CACN;;;;;CAMF,AAAO,UAAU;AACf,EAAK,KAAK,OAAO;AACjB,SAAO,KAAK;CACd;;;;CAKA,IAAW,UAAU;AACnB,OAAK,KAAK,SACR,MAAK,WAAW,IAAI,sBAAsB;AAG5C,SAAO,KAAK;CACd;;;;;;CAOA,AAAO,UAAa,MAA6B;;AAC/C,kCAAO,KAAK,OAAO,CAAC,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,KAAK,gFAAE;CAC5D;;;;;CAMA,AAAO,aAAqB;AAC1B,SAAO,KAAK,OAAO,CAAC;CACtB;;;;;CAMA,AAAO,gBAAoC;AACzC,SAAO,KAAK,OAAO,CAAC;CACtB;;;;;CAMA,AAAO,qBAAyC;AAC9C,SAAO,KAAK,OAAO,CAAC;CACtB;;;;;CAMA,AAA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;AAEtE,MAAI,aAAa,OACf,OAAM,IAAI,OAAO,UAAU,KAAK;AAGlC,SAAO,UAAU;CACnB;CAUA,cAAc,MAAc,WAAW,OAAO;AAC5C,SAAO,KAAK,aAAyB,MAAM,SAAS;CACtD;CAUA,WAAW,MAAc,WAAW,OAAO;AACzC,SAAO,KAAK,aAAsB,MAAM,SAAS;CACnD;CAUA,UAAU,MAAc,WAAW,OAAO;AACxC,SAAO,KAAK,aAAqB,MAAM,SAAS;CAClD;CAUA,UAAU,MAAc,WAAW,OAAO;AACxC,SAAO,KAAK,aAAqB,MAAM,SAAS;CAClD;CAUA,WAAW,MAAc,WAAW,OAAO;AACzC,SAAO,KAAK,aAAqB,MAAM,SAAS;CAClD;CAUA,QAAQ,MAAc,WAAW,OAAO;AACtC,SAAO,KAAK,aAAmB,MAAM,SAAS;CAChD;CAUA,WAAW,MAAc,WAAW,OAAO;AACzC,SAAO,KAAK,aAAsB,MAAM,SAAS;CACnD;CAUA,QAAQ,MAAc,WAAW,OAAO;AACtC,SAAO,KAAK,aAAmB,MAAM,SAAS;CAChD;CAeA,eACA,MACA,WAAW,OACgE;EACzE,MAAM,SAAS,KAAK,aAAa,MAAM,SAAS;AAEhD,MACA,kBAAkB,0BAClB,kBAAkB,mBAClB,kBAAkB,gBAEhB,QAAO;AAGT,MAAI,SACF,OAAM,IAAI,OAAO,eAAe,KAAK;AAGvC,SAAO;CACT;CASA,cAAc,WAAW,OAAO;EAC9B,MAAM,MAAM,KAAK,OAAO,eAAe;AAEvC,MAAI,YAAY,eACd,OAAM,IAAI,MAAM;AAGlB,SAAO,OAAO;CAChB;CASA,mBAAmB,WAAW,OAAO;EACnC,MAAM,MAAM,KAAK,OAAO,oBAAoB;AAE5C,MAAI,YAAY,eACd,OAAM,IAAI,MAAM;AAGlB,SAAO,OAAO;CAChB;AACF"}
|
|
1
|
+
{"version":3,"file":"MessageCommandParser-CGhN3xNN.js","names":[],"sources":["../src/app/commands/MessageCommandParser.ts"],"sourcesContent":["import { Channel } from 'diagnostics_channel';\nimport {\n Message,\n ApplicationCommandOptionType,\n GuildMember,\n Attachment,\n User,\n Role,\n CommandInteractionOption,\n} from 'discord.js';\nimport {\n CommandKitErrorCodes,\n createCommandKitError,\n} from '../../utils/error-codes';\n\n/**\n * Represents a parsed message command with its components.\n */\nexport interface ParsedMessageCommand {\n command: string;\n options: { name: string; value: unknown }[];\n subcommand?: string;\n subcommandGroup?: string;\n}\n\n/**\n * Schema defining the types of options for a message command.\n */\nexport type MessageCommandOptionsSchema = Record<\n string,\n ApplicationCommandOptionType\n>;\n\n/**\n * Parses message content into structured command data with options and subcommands.\n */\nexport class MessageCommandParser {\n /**\n * @private\n * @internal\n */\n #parsed: ParsedMessageCommand | null = null;\n\n /**\n * @private\n * @internal\n */\n #options: MessageCommandOptions | null = null;\n\n /**\n * @private\n * @internal\n */\n #args: string[] = [];\n\n /**\n * Creates a new message command parser.\n * @param message - The Discord message to parse\n * @param prefix - Array of valid command prefixes\n * @param schema - Function that returns the options schema for a command\n */\n public constructor(\n public message: Message,\n private prefix: string[],\n private schema: (command: string) => MessageCommandOptionsSchema,\n ) {}\n\n /**\n * Gets the parsed command arguments.\n * @returns Array of command arguments\n */\n public getArgs() {\n void this.parse();\n return this.#args;\n }\n\n /**\n * Gets the message command options object for easy access to typed option values.\n */\n public get options() {\n if (!this.#options) {\n this.#options = new MessageCommandOptions(this);\n }\n\n return this.#options;\n }\n\n /**\n * Gets a specific option value by name.\n * @param name - The option name\n * @returns The option value or undefined if not found\n */\n public getOption<T>(name: string): T | undefined {\n return this.parse().options.find((o) => o.name === name)?.value as T;\n }\n\n /**\n * Gets the main command name.\n * @returns The command name\n */\n public getCommand(): string {\n return this.parse().command;\n }\n\n /**\n * Gets the subcommand name if present.\n * @returns The subcommand name or undefined\n */\n public getSubcommand(): string | undefined {\n return this.parse().subcommand;\n }\n\n /**\n * Gets the subcommand group name if present.\n * @returns The subcommand group name or undefined\n */\n public getSubcommandGroup(): string | undefined {\n return this.parse().subcommandGroup;\n }\n\n /**\n * Gets the prefix used in the message.\n * @returns The matched prefix or undefined\n */\n public getPrefix() {\n for (const p of this.prefix) {\n if (this.message.content.startsWith(p)) {\n return p;\n }\n }\n }\n\n /**\n * Gets the full command including subcommand group and subcommand.\n * @returns The complete command string\n */\n public getFullCommand() {\n return [this.getCommand(), this.getSubcommandGroup(), this.getSubcommand()]\n .filter((v) => v)\n .join(' ');\n }\n\n /**\n * Parses the message content into structured command data.\n * @returns The parsed command data\n */\n public parse(): ParsedMessageCommand {\n if (this.#parsed) {\n return this.#parsed;\n }\n\n const content = this.message.content;\n\n const prefix = this.getPrefix();\n\n if (!prefix) {\n throw createCommandKitError(CommandKitErrorCodes.InvalidCommandPrefix);\n }\n\n const parts = content.slice(prefix.length).trim().split(' ');\n const command = parts.shift();\n\n this.#args = parts;\n\n let subcommandGroup: string | undefined;\n let subcommand: string | undefined;\n\n if (command?.includes(':')) {\n const [, group, cmd] = command.split(':');\n\n if (!cmd && group) {\n subcommand = group;\n } else if (cmd && group) {\n subcommandGroup = group;\n subcommand = cmd;\n }\n }\n\n const schema = this.schema(\n [command, subcommandGroup, subcommand].filter(Boolean).join(' ').trim(),\n );\n\n const options = parts\n .map((part) => {\n try {\n const [name, value] = part.split(':');\n\n if (!(name in schema)) return null;\n\n switch (schema[name]) {\n case ApplicationCommandOptionType.Boolean:\n return { name, value: value === 'true' };\n case ApplicationCommandOptionType.Integer:\n return { name, value: parseInt(value, 10) };\n case ApplicationCommandOptionType.Number:\n return { name, value: parseFloat(value) };\n case ApplicationCommandOptionType.String:\n return { name, value };\n case ApplicationCommandOptionType.User:\n return {\n name,\n value: this.message.mentions.users.find((u) => {\n return u.id === value.replace(/[<@!>]/g, '');\n }),\n };\n case ApplicationCommandOptionType.Channel:\n return {\n name,\n value: this.message.mentions.channels.find((c) => {\n return c.id === value.replace(/[<#>]/g, '');\n }),\n };\n case ApplicationCommandOptionType.Role:\n return {\n name,\n value: this.message.mentions.roles.find((r) => {\n return r.id === value.replace(/[<@&>]/g, '');\n }),\n };\n case ApplicationCommandOptionType.Attachment:\n return {\n name,\n value: this.message.attachments.find((a) => {\n return a.name === value;\n }),\n };\n default:\n return null;\n }\n } catch {\n // Invalid option\n return null;\n }\n })\n .filter((v) => v !== null);\n\n this.#parsed = {\n command: command!,\n options,\n subcommand,\n subcommandGroup,\n };\n\n return this.#parsed;\n }\n}\n\n/**\n * Provides typed access to message command options with methods similar to Discord.js interaction options.\n */\nexport class MessageCommandOptions {\n /**\n * Creates a new message command options instance.\n * @param parser - The message command parser instance\n */\n public constructor(private parser: MessageCommandParser) {}\n\n /**\n * @private\n * @internal\n */\n private assertOption<T>(name: string, required = false) {\n const option = this.parser.getOption<T>(name);\n\n if (required && option === undefined) {\n throw new Error(`Option \"${name}\" is required.`);\n }\n\n return option ?? null;\n }\n\n /**\n * Gets a guild member from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The guild member or null if not found\n */\n getMember(name: string): GuildMember | null;\n getMember(name: string, required: true): GuildMember;\n getMember(name: string, required = false) {\n const user = this.assertOption<User>(name, required);\n const member = this.parser.message.guild?.members.cache.get(user?.id!);\n\n if (required && !member) {\n throw new Error(`Member \"${name}\" is required.`);\n }\n\n return member ?? null;\n }\n\n /**\n * Gets an attachment from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The attachment or null if not found\n */\n getAttachment(name: string): Attachment | null;\n getAttachment(name: string, required: true): Attachment;\n getAttachment(name: string, required = false) {\n return this.assertOption<Attachment>(name, required);\n }\n\n /**\n * Gets a boolean value from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The boolean value or null if not found\n */\n getBoolean(name: string): boolean | null;\n getBoolean(name: string, required: true): boolean;\n getBoolean(name: string, required = false) {\n return this.assertOption<boolean>(name, required);\n }\n\n /**\n * Gets a number value from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The number value or null if not found\n */\n getNumber(name: string): number | null;\n getNumber(name: string, required: true): number;\n getNumber(name: string, required = false) {\n return this.assertOption<number>(name, required);\n }\n\n /**\n * Gets a string value from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The string value or null if not found\n */\n getString(name: string): string | null;\n getString(name: string, required: true): string;\n getString(name: string, required = false) {\n return this.assertOption<string>(name, required);\n }\n\n /**\n * Gets an integer value from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The integer value or null if not found\n */\n getInteger(name: string): number | null;\n getInteger(name: string, required: true): number;\n getInteger(name: string, required = false) {\n return this.assertOption<number>(name, required);\n }\n\n /**\n * Gets a user from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The user or null if not found\n */\n getUser(name: string): User | null;\n getUser(name: string, required: true): User;\n getUser(name: string, required = false) {\n return this.assertOption<User>(name, required);\n }\n\n /**\n * Gets a channel from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The channel or null if not found\n */\n getChannel(name: string): Channel | null;\n getChannel(name: string, required: true): Channel;\n getChannel(name: string, required = false) {\n return this.assertOption<Channel>(name, required);\n }\n\n /**\n * Gets a role from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The role or null if not found\n */\n getRole(name: string): Role | null;\n getRole(name: string, required: true): Role;\n getRole(name: string, required = false) {\n return this.assertOption<Role>(name, required);\n }\n\n /**\n * Gets a mentionable (user, member, or role) from the command options.\n * @param name - The option name\n * @param required - Whether the option is required\n * @returns The mentionable or null if not found\n */\n getMentionable(\n name: string,\n ): NonNullable<CommandInteractionOption['member' | 'role' | 'user']> | null;\n getMentionable(\n name: string,\n required: true,\n ): NonNullable<CommandInteractionOption['member' | 'role' | 'user']>;\n getMentionable(\n name: string,\n required = false,\n ): NonNullable<CommandInteractionOption['member' | 'role' | 'user']> | null {\n const target = this.assertOption(name, required);\n\n if (\n target instanceof GuildMember ||\n target instanceof User ||\n target instanceof Role\n ) {\n return target;\n }\n\n if (required) {\n throw new Error(`Mentionable \"${name}\" is required.`);\n }\n\n return null;\n }\n\n /**\n * Gets the subcommand name from the command.\n * @param required - Whether the subcommand is required\n * @returns The subcommand name or null if not found\n */\n getSubcommand(): string | null;\n getSubcommand(required: true): string;\n getSubcommand(required = false) {\n const sub = this.parser.getSubcommand();\n\n if (required && sub === undefined) {\n throw new Error('Subcommand is required.');\n }\n\n return sub ?? null;\n }\n\n /**\n * Gets the subcommand group name from the command.\n * @param required - Whether the subcommand group is required\n * @returns The subcommand group name or null if not found\n */\n getSubcommandGroup(): string | null;\n getSubcommandGroup(required: true): string;\n getSubcommandGroup(required = false) {\n const sub = this.parser.getSubcommandGroup();\n\n if (required && sub === undefined) {\n throw new Error('Subcommand group is required.');\n }\n\n return sub ?? null;\n }\n}\n"],"mappings":";;;;;;;;AAoCA,IAAa,uBAAb,MAAkC;;;;;CAKhC,UAAuC;;;;;CAMvC,WAAyC;;;;;CAMzC,QAAkB,CAAE;;;;;;;CAQpB,AAAO,YACA,SACC,QACA,QACR;EAHO;EACC;EACA;CACN;;;;;CAMF,AAAO,UAAU;EACV,KAAK,OAAO;AACjB,SAAO,KAAK;CACd;;;;CAKA,IAAW,UAAU;AACnB,MAAI,CAAC,KAAK,UACR,KAAK,WAAW,IAAI,sBAAsB;AAG5C,SAAO,KAAK;CACd;;;;;;CAOA,AAAO,UAAa,MAA6B;;AAC/C,kCAAO,KAAK,OAAO,CAAC,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,KAAK,gFAAE;CAC5D;;;;;CAMA,AAAO,aAAqB;AAC1B,SAAO,KAAK,OAAO,CAAC;CACtB;;;;;CAMA,AAAO,gBAAoC;AACzC,SAAO,KAAK,OAAO,CAAC;CACtB;;;;;CAMA,AAAO,qBAAyC;AAC9C,SAAO,KAAK,OAAO,CAAC;CACtB;;;;;CAMA,AAAO,YAAY;AACjB,OAAK,MAAM,KAAK,KAAK,OACnB,KAAI,KAAK,QAAQ,QAAQ,WAAW,EAAE,CACpC,QAAO;CAGb;;;;;CAMA,AAAO,iBAAiB;AACtB,SAAO;G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UAAU;CACnB;CAUA,cAAc,MAAc,WAAW,OAAO;AAC5C,SAAO,KAAK,aAAyB,MAAM,SAAS;CACtD;CAUA,WAAW,MAAc,WAAW,OAAO;AACzC,SAAO,KAAK,aAAsB,MAAM,SAAS;CACnD;CAUA,UAAU,MAAc,WAAW,OAAO;AACxC,SAAO,KAAK,aAAqB,MAAM,SAAS;CAClD;CAUA,UAAU,MAAc,WAAW,OAAO;AACxC,SAAO,KAAK,aAAqB,MAAM,SAAS;CAClD;CAUA,WAAW,MAAc,WAAW,OAAO;AACzC,SAAO,KAAK,aAAqB,MAAM,SAAS;CAClD;CAUA,QAAQ,MAAc,WAAW,OAAO;AACtC,SAAO,KAAK,aAAmB,MAAM,SAAS;CAChD;CAUA,WAAW,MAAc,WAAW,OAAO;AACzC,SAAO,KAAK,aAAsB,MAAM,SAAS;CACnD;CAUA,QAAQ,MAAc,WAAW,OAAO;AACtC,SAAO,KAAK,aAAmB,MAAM,SAAS;CAChD;CAeA,eACA,MACA,WAAW,OACgE;EACzE,MAAM,SAAS,KAAK,aAAa,MAAM,SAAS;AAEhD,MACA,kBAAkB,0BAClB,kBAAkB,mBAClB,kBAAkB,gBAEhB,QAAO;AAGT,MAAI,SACF,OAAM,IAAI,MAAM,CAAC,aAAa,EAAE,KAAK,cAAc,CAAC;AAGtD,SAAO;CACT;CASA,cAAc,WAAW,OAAO;EAC9B,MAAM,MAAM,KAAK,OAAO,eAAe;AAEvC,MAAI,YAAY,QAAQ,OACtB,OAAM,IAAI,MAAM;AAGlB,SAAO,OAAO;CAChB;CASA,mBAAmB,WAAW,OAAO;EACnC,MAAM,MAAM,KAAK,OAAO,oBAAoB;AAE5C,MAAI,YAAY,QAAQ,OACtB,OAAM,IAAI,MAAM;AAGlB,SAAO,OAAO;CAChB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginCommon-Di1xIa8d.js","names":[],"sources":["../src/plugins/PluginCommon.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { CommonPluginRuntime } from './plugin-runtime/runtime';\n\n/**\n * The options for a CommandKit plugin.\n */\nexport type PluginOptions = Record<string, any>;\n\n/**\n * Enum representing the type of plugin.\n * - Compiler: A plugin that runs at compile time.\n * - Runtime: A plugin that runs at runtime.\n */\nexport enum PluginType {\n Compiler = 'compiler',\n Runtime = 'runtime',\n}\n\n/**\n * Base class for CommandKit plugins.\n */\nexport abstract class PluginCommon<\n T extends PluginOptions = PluginOptions,\n C extends CommonPluginRuntime = CommonPluginRuntime,\n> {\n /**\n * The type of the plugin, either Compiler or Runtime.\n */\n public abstract readonly type: PluginType;\n /**\n * Unique identifier for the plugin instance.\n */\n public readonly id = randomUUID();\n /**\n * The time when the plugin was loaded, in milliseconds since the Unix epoch.\n */\n public readonly loadedAt = Date.now();\n /**\n * The name of the plugin.\n */\n public abstract readonly name: string;\n\n /**\n * Creates a new instance of the plugin.\n */\n public constructor(protected readonly options: T) {}\n\n /**\n * Called when this plugin is activated\n */\n public async activate(ctx: C): Promise<void> {}\n\n /**\n * Called when this plugin is deactivated\n */\n public async deactivate(ctx: C): Promise<void> {}\n}\n\n/**\n * Whether the given object is a CommandKit plugin.\n * @param plugin The object to check.\n * @returns Boolean indicating whether the object is a plugin.\n */\nexport function isPlugin(\n plugin: unknown,\n): plugin is PluginCommon<PluginOptions> {\n return plugin instanceof PluginCommon;\n}\n"],"mappings":";;;;;;;;;AAaA,IAAY,oDAAL
|
|
1
|
+
{"version":3,"file":"PluginCommon-Di1xIa8d.js","names":[],"sources":["../src/plugins/PluginCommon.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { CommonPluginRuntime } from './plugin-runtime/runtime';\n\n/**\n * The options for a CommandKit plugin.\n */\nexport type PluginOptions = Record<string, any>;\n\n/**\n * Enum representing the type of plugin.\n * - Compiler: A plugin that runs at compile time.\n * - Runtime: A plugin that runs at runtime.\n */\nexport enum PluginType {\n Compiler = 'compiler',\n Runtime = 'runtime',\n}\n\n/**\n * Base class for CommandKit plugins.\n */\nexport abstract class PluginCommon<\n T extends PluginOptions = PluginOptions,\n C extends CommonPluginRuntime = CommonPluginRuntime,\n> {\n /**\n * The type of the plugin, either Compiler or Runtime.\n */\n public abstract readonly type: PluginType;\n /**\n * Unique identifier for the plugin instance.\n */\n public readonly id = randomUUID();\n /**\n * The time when the plugin was loaded, in milliseconds since the Unix epoch.\n */\n public readonly loadedAt = Date.now();\n /**\n * The name of the plugin.\n */\n public abstract readonly name: string;\n\n /**\n * Creates a new instance of the plugin.\n */\n public constructor(protected readonly options: T) {}\n\n /**\n * Called when this plugin is activated\n */\n public async activate(ctx: C): Promise<void> {}\n\n /**\n * Called when this plugin is deactivated\n */\n public async deactivate(ctx: C): Promise<void> {}\n}\n\n/**\n * Whether the given object is a CommandKit plugin.\n * @param plugin The object to check.\n * @returns Boolean indicating whether the object is a plugin.\n */\nexport function isPlugin(\n plugin: unknown,\n): plugin is PluginCommon<PluginOptions> {\n return plugin instanceof PluginCommon;\n}\n"],"mappings":";;;;;;;;;AAaA,IAAY,oDAAL;;;;AAGP;;;;AAKA,IAAsB,eAAtB,MAGA;;;;CAQE,AAAgB,kCAAiB;;;;CAIjC,AAAgB,WAAW,KAAK,KAAK;;;;CASrC,AAAO,YAA+B,SAAY;EAAZ;CAAa;;;;CAKnD,MAAa,SAAS,KAAuB,CAAC;;;;CAK9C,MAAa,WAAW,KAAuB,CAAC;AAClD;;;;;;AAOA,SAAgB,SAChB,QACwC;AACtC,QAAO,kBAAkB;AAC3B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../colors-Cd4Oz-r-.js');
|
|
2
2
|
require('../ActionRow-CmTHbo2t.js');
|
|
3
3
|
require('../error-codes-C-ViHyu-.js');
|
|
4
|
-
const require_commandkit = require('../commandkit-
|
|
4
|
+
const require_commandkit = require('../commandkit-CUFTPuzm.js');
|
|
5
5
|
require('../common-CcfjYnPG.js');
|
|
6
6
|
require('../common-vnMIelAE.js');
|
|
7
7
|
require('../container-DCjIgp-B.js');
|
package/dist/analytics/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../colors-Cd4Oz-r-.js');
|
|
2
2
|
require('../ActionRow-CmTHbo2t.js');
|
|
3
3
|
require('../error-codes-C-ViHyu-.js');
|
|
4
|
-
const require_commandkit = require('../commandkit-
|
|
4
|
+
const require_commandkit = require('../commandkit-CUFTPuzm.js');
|
|
5
5
|
require('../common-CcfjYnPG.js');
|
|
6
6
|
require('../common-vnMIelAE.js');
|
|
7
7
|
require('../container-DCjIgp-B.js');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../../colors-Cd4Oz-r-.js');
|
|
2
2
|
require('../../ActionRow-CmTHbo2t.js');
|
|
3
3
|
require('../../error-codes-C-ViHyu-.js');
|
|
4
|
-
const require_commandkit = require('../../commandkit-
|
|
4
|
+
const require_commandkit = require('../../commandkit-CUFTPuzm.js');
|
|
5
5
|
require('../../common-CcfjYnPG.js');
|
|
6
6
|
require('../../common-vnMIelAE.js');
|
|
7
7
|
require('../../container-DCjIgp-B.js');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../../colors-Cd4Oz-r-.js');
|
|
2
2
|
require('../../ActionRow-CmTHbo2t.js');
|
|
3
3
|
require('../../error-codes-C-ViHyu-.js');
|
|
4
|
-
const require_commandkit = require('../../commandkit-
|
|
4
|
+
const require_commandkit = require('../../commandkit-CUFTPuzm.js');
|
|
5
5
|
require('../../common-CcfjYnPG.js');
|
|
6
6
|
require('../../common-vnMIelAE.js');
|
|
7
7
|
require('../../container-DCjIgp-B.js');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../../colors-Cd4Oz-r-.js');
|
|
2
2
|
require('../../ActionRow-CmTHbo2t.js');
|
|
3
3
|
require('../../error-codes-C-ViHyu-.js');
|
|
4
|
-
const require_commandkit = require('../../commandkit-
|
|
4
|
+
const require_commandkit = require('../../commandkit-CUFTPuzm.js');
|
|
5
5
|
require('../../common-CcfjYnPG.js');
|
|
6
6
|
require('../../common-vnMIelAE.js');
|
|
7
7
|
require('../../container-DCjIgp-B.js');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../../colors-Cd4Oz-r-.js');
|
|
2
2
|
require('../../ActionRow-CmTHbo2t.js');
|
|
3
3
|
require('../../error-codes-C-ViHyu-.js');
|
|
4
|
-
const require_commandkit = require('../../commandkit-
|
|
4
|
+
const require_commandkit = require('../../commandkit-CUFTPuzm.js');
|
|
5
5
|
require('../../common-CcfjYnPG.js');
|
|
6
6
|
require('../../common-vnMIelAE.js');
|
|
7
7
|
require('../../container-DCjIgp-B.js');
|
package/dist/app/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../colors-Cd4Oz-r-.js');
|
|
2
2
|
require('../ActionRow-CmTHbo2t.js');
|
|
3
3
|
require('../error-codes-C-ViHyu-.js');
|
|
4
|
-
const require_commandkit = require('../commandkit-
|
|
4
|
+
const require_commandkit = require('../commandkit-CUFTPuzm.js');
|
|
5
5
|
require('../common-CcfjYnPG.js');
|
|
6
6
|
require('../common-vnMIelAE.js');
|
|
7
7
|
require('../container-DCjIgp-B.js');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../../colors-Cd4Oz-r-.js');
|
|
2
2
|
require('../../ActionRow-CmTHbo2t.js');
|
|
3
3
|
require('../../error-codes-C-ViHyu-.js');
|
|
4
|
-
const require_commandkit = require('../../commandkit-
|
|
4
|
+
const require_commandkit = require('../../commandkit-CUFTPuzm.js');
|
|
5
5
|
require('../../common-CcfjYnPG.js');
|
|
6
6
|
require('../../common-vnMIelAE.js');
|
|
7
7
|
require('../../container-DCjIgp-B.js');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-process-CKLJAmil.js","names":[],"sources":["../src/cli/app-process.ts"],"sourcesContent":["import { IOType, spawn } from 'node:child_process';\nimport { DevEnv, ProdEnv } from './env';\nimport { join } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport { panic } from './common';\n\n/**\n * @private\n * @internal\n */\nfunction getStdio(supportsCommands: boolean) {\n if (supportsCommands) {\n return ['pipe', 'pipe', 'pipe', 'ipc'];\n }\n\n return ['pipe', 'pipe', 'pipe'];\n}\n\n/**\n * @private\n * @internal\n */\nexport function createAppProcess(\n fileName: string,\n cwd: string,\n isDev: boolean,\n) {\n if (!existsSync(join(cwd, fileName))) {\n panic(`Could not locate the entrypoint file: ${fileName}`);\n }\n\n const stdio = getStdio(isDev) as IOType[];\n\n const ps = spawn(\n 'node',\n [\n `--title=\"CommandKit ${isDev ? 'Development' : 'Production'}\"`,\n '--enable-source-maps',\n fileName,\n ],\n {\n cwd,\n windowsHide: true,\n env: isDev ? DevEnv() : ProdEnv(),\n stdio,\n },\n );\n\n ps.stdout?.pipe(process.stdout);\n ps.stderr?.pipe(process.stderr);\n\n return ps;\n}\n"],"mappings":";;;;;;;;;;;;AAUA,SAAS,SAAS,kBAA2B;AAC3C,KAAI,iBACF,QAAO;EAAC;EAAQ;EAAQ;EAAQ;CAAM;AAGxC,QAAO;EAAC;EAAQ;EAAQ;CAAO;AACjC;;;;;AAMA,SAAgB,iBAChB,UACA,KACA,OACA;;AACE,
|
|
1
|
+
{"version":3,"file":"app-process-CKLJAmil.js","names":[],"sources":["../src/cli/app-process.ts"],"sourcesContent":["import { IOType, spawn } from 'node:child_process';\nimport { DevEnv, ProdEnv } from './env';\nimport { join } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport { panic } from './common';\n\n/**\n * @private\n * @internal\n */\nfunction getStdio(supportsCommands: boolean) {\n if (supportsCommands) {\n return ['pipe', 'pipe', 'pipe', 'ipc'];\n }\n\n return ['pipe', 'pipe', 'pipe'];\n}\n\n/**\n * @private\n * @internal\n */\nexport function createAppProcess(\n fileName: string,\n cwd: string,\n isDev: boolean,\n) {\n if (!existsSync(join(cwd, fileName))) {\n panic(`Could not locate the entrypoint file: ${fileName}`);\n }\n\n const stdio = getStdio(isDev) as IOType[];\n\n const ps = spawn(\n 'node',\n [\n `--title=\"CommandKit ${isDev ? 'Development' : 'Production'}\"`,\n '--enable-source-maps',\n fileName,\n ],\n {\n cwd,\n windowsHide: true,\n env: isDev ? DevEnv() : ProdEnv(),\n stdio,\n },\n );\n\n ps.stdout?.pipe(process.stdout);\n ps.stderr?.pipe(process.stderr);\n\n return ps;\n}\n"],"mappings":";;;;;;;;;;;;AAUA,SAAS,SAAS,kBAA2B;AAC3C,KAAI,iBACF,QAAO;EAAC;EAAQ;EAAQ;EAAQ;CAAM;AAGxC,QAAO;EAAC;EAAQ;EAAQ;CAAO;AACjC;;;;;AAMA,SAAgB,iBAChB,UACA,KACA,OACA;;AACE,KAAI,6CAAiB,KAAK,SAAS,CAAC,EAClC,qBAAM,CAAC,sCAAsC,EAAE,UAAU,CAAC;CAG5D,MAAM,QAAQ,SAAS,MAAM;CAE7B,MAAM,mCACJ,QACA;EACA,CAAC,oBAAoB,EAAE,QAAQ,gBAAgB,aAAa,CAAC,CAAC;EAC9D;EACA;CAAS,GAET;EACE;EACA,aAAa;EACb,KAAK,QAAQ,oBAAQ,GAAG,qBAAS;EACjC;CACD,EACF;eAED,GAAG,wDAAQ,KAAK,QAAQ,OAAO;eAC/B,GAAG,wDAAQ,KAAK,QAAQ,OAAO;AAE/B,QAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-nOFOJqeH.js');
|
|
2
|
-
const require_commandkit = require('./commandkit-
|
|
2
|
+
const require_commandkit = require('./commandkit-CUFTPuzm.js');
|
|
3
3
|
const require_constants = require('./constants-B5_Ta7PR.js');
|
|
4
4
|
const require_common = require('./common-DoZjgUs0.js');
|
|
5
5
|
const require_env = require('./env-DakvrBzy.js');
|
|
@@ -161,4 +161,4 @@ Object.defineProperty(exports, 'buildApplication', {
|
|
|
161
161
|
return buildApplication;
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
|
-
//# sourceMappingURL=build-
|
|
164
|
+
//# sourceMappingURL=build-D8P0ENm6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-
|
|
1
|
+
{"version":3,"file":"build-D8P0ENm6.js","names":[],"sources":["../src/cli/build.ts"],"sourcesContent":["import { build } from 'tsdown';\nimport { CompilerPlugin, CompilerPluginRuntime } from '../plugins';\nimport { loadConfigFile } from '../config/loader';\nimport { writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { DevEnv, devEnvFileArgs, ProdEnv, prodEnvFileArgs } from './env';\nimport { rimraf } from 'rimraf';\nimport { performTypeCheck } from './type-checker';\nimport { copyLocaleFiles } from './common';\nimport { MaybeArray } from '../components';\nimport { COMMANDKIT_CWD } from '../utils/constants';\n\n/**\n * @private\n * @internal\n */\nexport interface ApplicationBuildOptions {\n plugins?: MaybeArray<CompilerPlugin>[] | Array<CompilerPlugin>;\n rolldownPlugins?: any[];\n isDev?: boolean;\n configPath?: string;\n}\n\n// emit public env variables and given env variables\n/**\n * @private\n * @internal\n */\nfunction mergeDefinitionsIfNeeded(env: Record<string, string>, isDev: boolean) {\n const values = Object.fromEntries(\n Object.entries(process.env).filter(\n ([k]) => !(k in env) && k.startsWith('COMMANDKIT_PUBLIC_'),\n ),\n );\n\n return {\n ...env,\n ...values,\n ...(isDev\n ? {\n NODE_ENV: 'development',\n COMMANDKIT_BOOTSTRAP_MODE: 'development',\n COMMANDKIT_IS_DEV: 'true',\n COMMANDKIT_IS_TEST: 'false',\n }\n : {\n NODE_ENV: 'production',\n COMMANDKIT_BOOTSTRAP_MODE: 'production',\n COMMANDKIT_IS_DEV: 'false',\n COMMANDKIT_IS_TEST: 'false',\n }),\n };\n}\n\n/**\n * @private\n * @internal\n */\nexport async function buildApplication({\n plugins,\n rolldownPlugins,\n isDev,\n configPath,\n}: ApplicationBuildOptions) {\n const config = await loadConfigFile(configPath);\n\n if (!isDev && !config?.typescript?.ignoreBuildErrors) {\n await performTypeCheck(configPath || COMMANDKIT_CWD);\n }\n\n const pluginRuntime = new CompilerPluginRuntime(\n (plugins || []) as CompilerPlugin[],\n );\n\n rolldownPlugins ??= [];\n\n rolldownPlugins.push(pluginRuntime.toJSON());\n\n try {\n const dest = isDev ? '.commandkit' : config.distDir;\n\n // Clean the destination directory\n await rimraf(dest);\n\n await pluginRuntime.init();\n\n await build({\n watch: false,\n dts: false,\n clean: true,\n format: ['esm'],\n shims: true,\n minify: false,\n silent: !!isDev,\n inputOptions: {\n transform: {\n jsx: {\n runtime: 'automatic',\n importSource: 'commandkit',\n },\n },\n checks: {\n circularDependency: true,\n },\n onwarn: (warning, defaultWarn) => {\n if (warning?.message?.includes('compilerOptions.jsx')) return;\n\n return defaultWarn(warning);\n },\n onLog: (level, log, defaultLog) => {\n if (isDev) return;\n\n return defaultLog(level, log);\n },\n moduleTypes: {\n '.json': 'js',\n '.node': 'binary',\n },\n },\n plugins: rolldownPlugins,\n platform: 'node',\n skipNodeModulesBundle: true,\n sourcemap: true,\n target: 'node16',\n outDir: dest,\n env: mergeDefinitionsIfNeeded(config.env || {}, !!isDev),\n entry: [\n 'src',\n `!${config.distDir}`,\n '!.commandkit',\n '!**/*.test.*',\n '!**/*.spec.*',\n ],\n unbundle: !!isDev,\n });\n\n await copyLocaleFiles('src', dest);\n await injectEntryFile(\n configPath || COMMANDKIT_CWD,\n !!isDev,\n config.distDir,\n );\n } catch (error) {\n console.error('Build failed:', error);\n if (error instanceof Error) {\n console.error('Error details:', error.stack);\n }\n process.exit(1); // Force exit on error\n } finally {\n // Ensure plugins are cleaned up\n await pluginRuntime.destroy();\n }\n}\n\nconst envScript = (dev: boolean) => `// --- Environment Variables Loader ---\nconst $env = [${(dev ? devEnvFileArgs : prodEnvFileArgs).map((p) => `\"${p}\"`).join(', ')}];\nfor (const file of $env) {\n try {\n process.loadEnvFile(file);\n console.log('\\\\x1b[36m✔ Loaded \\\\x1b[0m\\\\x1b[33m%s\\\\x1b[0m', file);\n } catch {}\n}\n`;\n\nconst antiCrashScript = [\n '// --- CommandKit Anti-Crash Monitor ---',\n \" // 'uncaughtException' event is supposed to be used to perform synchronous cleanup before shutting down the process\",\n ' // instead of using it as a means to resume operation.',\n ' // But it exists here due to compatibility reasons with discord bot ecosystem.',\n \" const p = (t) => `\\\\x1b[31m${t}\\\\x1b[0m`, b = '[CommandKit Anti-Crash Monitor]', l = console.log, e1 = 'uncaughtException', e2 = 'unhandledRejection';\",\n ' if (!process.eventNames().includes(e1)) // skip if it is already handled',\n ' process.on(e1, (e) => {',\n ' l(p(`${b} Uncaught Exception`)); l(p(b), p(e.stack || e));',\n ' })',\n ' if (!process.eventNames().includes(e2)) // skip if it is already handled',\n ' process.on(e2, (r) => {',\n ' l(p(`${b} Unhandled promise rejection`)); l(p(`${b} ${r.stack || r}`));',\n ' });',\n '// --- CommandKit Anti-Crash Monitor ---',\n].join('\\n');\n\nconst wrapInAsyncIIFE = (code: string[]) =>\n `;await (async () => {\\n${code.join('\\n\\n')}\\n})();`;\n\nasync function injectEntryFile(\n configPath: string,\n isDev: boolean,\n distDir?: string,\n) {\n const code = `/* Entrypoint File Generated By CommandKit */\n${isDev ? `\\n\\n// Injected for development\\n${wrapInAsyncIIFE([envScript(isDev), antiCrashScript])}\\n\\n` : wrapInAsyncIIFE([envScript(isDev)])}\n\nimport { commandkit } from 'commandkit';\nimport { Client } from 'discord.js';\n\nasync function bootstrap() {\n const app = await import('./app.js').then((m) => m.default ?? m);\n\n if (!app || !(app instanceof Client)) {\n throw new Error('The app file must default export the discord.js client instance');\n }\n\n commandkit.setClient(app);\n\n await commandkit.start();\n}\n\nawait bootstrap().catch((e) => {\n console.error('Failed to bootstrap CommandKit application:\\\\n', e.stack);\n})\n`;\n\n const dist = isDev ? '.commandkit' : distDir || 'dist';\n\n await writeFile(join(configPath, dist, 'index.js'), code);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,SAAS,yBAAyB,KAA6B,OAAgB;CAC7E,MAAM,SAAS,OAAO,YACpB,OAAO,QAAQ,QAAQ,IAA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ActionRow-CmTHbo2t.js');
|
|
3
3
|
require('../error-codes-C-ViHyu-.js');
|
|
4
|
-
require('../commandkit-
|
|
4
|
+
require('../commandkit-CUFTPuzm.js');
|
|
5
5
|
require('../common-CcfjYnPG.js');
|
|
6
6
|
require('../common-vnMIelAE.js');
|
|
7
7
|
require('../container-DCjIgp-B.js');
|
|
@@ -34,6 +34,6 @@ require('../CommandKitEventsChannel-BSdcgY3Q.js');
|
|
|
34
34
|
require('../store-CyzliDXj.js');
|
|
35
35
|
require('../env-DakvrBzy.js');
|
|
36
36
|
require('../type-checker-DDHZIEBi.js');
|
|
37
|
-
const require_build = require('../build-
|
|
37
|
+
const require_build = require('../build-D8P0ENm6.js');
|
|
38
38
|
|
|
39
39
|
exports.buildApplication = require_build.buildApplication;
|
package/dist/cli/common.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ import "../CommandsRouter-CoOA7hkf.js";
|
|
|
29
29
|
import "../EventsRouter-BacqK6z3.js";
|
|
30
30
|
import "../index-CUPkUUOR.js";
|
|
31
31
|
import "../constants-MKu-Q1jh.js";
|
|
32
|
-
import * as
|
|
32
|
+
import * as typescript0 from "typescript";
|
|
33
33
|
|
|
34
34
|
//#region src/cli/common.d.ts
|
|
35
35
|
/**
|
|
@@ -52,7 +52,7 @@ declare function panic(message: any): never;
|
|
|
52
52
|
* @private
|
|
53
53
|
* @internal
|
|
54
54
|
*/
|
|
55
|
-
declare function loadTypeScript(e?: string): Promise<typeof
|
|
55
|
+
declare function loadTypeScript(e?: string): Promise<typeof typescript0>;
|
|
56
56
|
/**
|
|
57
57
|
* @private
|
|
58
58
|
* @internal
|
package/dist/cli/development.js
CHANGED
|
@@ -2,7 +2,7 @@ const require_chunk = require('../chunk-nOFOJqeH.js');
|
|
|
2
2
|
const require_colors = require('../colors-Cd4Oz-r-.js');
|
|
3
3
|
require('../ActionRow-CmTHbo2t.js');
|
|
4
4
|
require('../error-codes-C-ViHyu-.js');
|
|
5
|
-
const require_commandkit = require('../commandkit-
|
|
5
|
+
const require_commandkit = require('../commandkit-CUFTPuzm.js');
|
|
6
6
|
require('../common-CcfjYnPG.js');
|
|
7
7
|
require('../common-vnMIelAE.js');
|
|
8
8
|
require('../container-DCjIgp-B.js');
|
|
@@ -36,7 +36,7 @@ require('../store-CyzliDXj.js');
|
|
|
36
36
|
require('../env-DakvrBzy.js');
|
|
37
37
|
const require_app_process = require('../app-process-CKLJAmil.js');
|
|
38
38
|
require('../type-checker-DDHZIEBi.js');
|
|
39
|
-
const require_build = require('../build-
|
|
39
|
+
const require_build = require('../build-D8P0ENm6.js');
|
|
40
40
|
const node_crypto = require_chunk.__toESM(require("node:crypto"));
|
|
41
41
|
const path = require_chunk.__toESM(require("path"));
|
|
42
42
|
const chokidar = require_chunk.__toESM(require("chokidar"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"development.js","names":[],"sources":["../../src/cli/development.ts"],"sourcesContent":["import { join } from 'path';\nimport { getPossibleConfigPaths, loadConfigFile } from '../config/loader';\nimport { isCompilerPlugin } from '../plugins';\nimport { createAppProcess } from './app-process';\nimport { buildApplication } from './build';\nimport { watch } from 'chokidar';\nimport { debounce } from '../utils/utilities';\nimport colors from '../utils/colors';\nimport { ChildProcess } from 'node:child_process';\nimport { setTimeout as sleep } from 'node:timers/promises';\nimport { randomUUID } from 'node:crypto';\nimport { COMMANDKIT_CWD, HMREventType } from '../utils/constants';\nimport { findEntrypoint } from './common';\n\n/**\n * @private\n * @internal\n */\nasync function buildAndStart(configPath: string, skipStart = false) {\n const config = await loadConfigFile(configPath);\n const mainFile = findEntrypoint('.commandkit');\n\n await buildApplication({\n configPath,\n isDev: true,\n plugins: config.plugins.flat(2).filter((p) => isCompilerPlugin(p)),\n rolldownPlugins: config.rolldownPlugins,\n });\n\n if (skipStart) return null as never;\n\n const ps = createAppProcess(mainFile, configPath, true);\n\n return ps;\n}\n\n/**\n * @private\n * @internal\n */\nconst isCommandSource = (p: string) =>\n p.replaceAll('\\\\', '/').includes('src/app/commands');\n\n/**\n * @private\n * @internal\n */\nconst isEventSource = (p: string) =>\n p.replaceAll('\\\\', '/').includes('src/app/events');\n\n/**\n * @private\n * @internal\n */\nexport async function bootstrapDevelopmentServer(configPath?: string) {\n process.env.COMMANDKIT_BOOTSTRAP_MODE = 'development';\n const start = performance.now();\n const cwd = configPath || COMMANDKIT_CWD;\n const configPaths = getPossibleConfigPaths(cwd);\n\n const watcher = watch([join(cwd, 'src'), ...configPaths], {\n ignoreInitial: true,\n });\n\n let ps: ChildProcess | null = null;\n\n const waitForAcknowledgment = (messageId: string): Promise<boolean> => {\n return new Promise((resolve) => {\n if (!ps) return resolve(false);\n\n let _handled = false;\n const onMessage = (message: any) => {\n _handled = true;\n if (typeof message !== 'object' || message === null) return;\n\n const { type, id, handled } = message;\n if (type === 'commandkit-hmr-ack' && id === messageId) {\n ps?.off('message', onMessage);\n resolve(!!handled);\n }\n };\n\n ps.once('message', onMessage);\n\n if (!_handled) {\n sleep(3000).then(() => {\n ps?.off('message', onMessage);\n resolve(false);\n });\n }\n });\n };\n\n const sendHmrEvent = async (\n event: HMREventType,\n path?: string,\n ): Promise<boolean> => {\n if (!ps || !ps.send) return false;\n\n const messageId = randomUUID();\n const messagePromise = waitForAcknowledgment(messageId);\n\n ps.send({ event, path, id: messageId });\n\n // Wait for acknowledgment or timeout after 3 seconds\n try {\n let triggered = false;\n const res = !!(await Promise.race([\n messagePromise,\n sleep(3000).then(() => {\n if (!triggered) {\n console.warn(\n colors.yellow(\n `HMR acknowledgment timed out for event ${event} on path ${path}`,\n ),\n );\n }\n return false;\n }),\n ]));\n\n triggered = true;\n\n return res;\n } catch (error) {\n console.error(\n colors.red(`Error waiting for HMR acknowledgment: ${error}`),\n );\n return false;\n }\n };\n\n const performHMR = debounce(async (path?: string): Promise<boolean> => {\n if (!path || !ps) return false;\n\n let eventType: HMREventType | null = null;\n let eventDescription = '';\n\n if (isCommandSource(path)) {\n eventType = HMREventType.ReloadCommands;\n eventDescription = 'command(s)';\n } else if (isEventSource(path)) {\n eventType = HMREventType.ReloadEvents;\n eventDescription = 'event(s)';\n } else {\n eventType = HMREventType.Unknown;\n eventDescription = 'unknown source';\n }\n\n if (eventType) {\n console.log(\n `${colors.cyanBright(`Attempting to reload ${eventDescription} at`)} ${colors.yellowBright(path)}`,\n );\n\n await buildAndStart(cwd, true);\n const hmrHandled = await sendHmrEvent(eventType, path);\n\n if (hmrHandled) {\n console.log(\n `${colors.greenBright(`Successfully hot reloaded ${eventDescription} at`)} ${colors.yellowBright(path)}`,\n );\n return true;\n }\n }\n\n return false;\n }, 300);\n\n const isConfigUpdate = (path: string) => {\n const isConfig = configPaths.some((configPath) => path === configPath);\n\n if (!isConfig) return false;\n\n console.log(\n colors.yellowBright(\n 'It seems like commandkit config file was updated, please restart the server manually to apply changes.',\n ),\n );\n\n return isConfig;\n };\n\n const hmrHandler = async (path: string) => {\n if (isConfigUpdate(path)) return;\n const hmr = await performHMR(path);\n if (hmr) return;\n\n console.log(\n `${colors.yellowBright('⚡️ Performing full restart due to the changes in')} ${colors.cyanBright(path)}`,\n );\n\n ps?.kill();\n ps = await buildAndStart(cwd);\n };\n\n process.stdin.on('data', async (d) => {\n const command = d.toString().trim();\n\n switch (command) {\n case 'r':\n console.log(`Received restart command, restarting...`);\n ps?.kill();\n ps = null;\n ps = await buildAndStart(cwd);\n break;\n case 'rc':\n console.log(`Received reload commands command, reloading...`);\n await sendHmrEvent(HMREventType.ReloadCommands);\n break;\n case 're':\n console.log(`Received reload events command, reloading...`);\n await sendHmrEvent(HMREventType.ReloadEvents);\n break;\n break;\n }\n });\n\n watcher.on('change', hmrHandler);\n watcher.on('add', hmrHandler);\n watcher.on('unlink', hmrHandler);\n watcher.on('unlinkDir', hmrHandler);\n watcher.on('error', (e) => {\n console.error(e);\n });\n\n console.log(`${colors.greenBright('Bootstrapped CommandKit Development Environment in')} ${colors.yellowBright(`${(performance.now() - start).toFixed(2)}ms`)}\n${colors.greenBright('Watching for changes in')} ${colors.yellowBright('src')} ${colors.greenBright('directory')}\n\n${colors.greenBright('Commands:')}\n${colors.yellowBright('r')} - Restart the server\n${colors.yellowBright('rc')} - Reload all commands\n${colors.yellowBright('re')} - Reload all events`);\n\n const buildStart = performance.now();\n\n ps = await buildAndStart(cwd);\n\n const buildEnd = performance.now();\n\n console.log(\n `\\n${colors.greenBright('Development mode compilation took')} ${colors.yellowBright(`${(buildEnd - buildStart).toFixed(2)}ms`)}\\n`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,eAAe,cAAc,YAAoB,YAAY,OAAO;CAClE,MAAM,SAAS,MAAM,kCAAe,WAAW;CAC/C,MAAM,WAAW,gCAAe,cAAc;AAE9C,OAAM,+BAAiB;EACrB;EACA,OAAO;EACP,SAAS,OAAO,QAAQ,KAAK,EAAE,CAAC,OAAO,CAAC,MAAM,wCAAiB,EAAE,CAAC;EAClE,iBAAiB,OAAO;CACzB,EAAC;AAEF,KAAI,UAAW,QAAO;CAEtB,MAAM,KAAK,qCAAiB,UAAU,YAAY,KAAK;AAEvD,QAAO;AACT;;;;;AAMA,MAAM,kBAAkB,CAAC,MACzB,EAAE,WAAW,MAAM,IAAI,CAAC,SAAS,mBAAmB;;;;;AAMpD,MAAM,gBAAgB,CAAC,MACvB,EAAE,WAAW,MAAM,IAAI,CAAC,SAAS,iBAAiB;;;;;AAMlD,eAAsB,2BAA2B,YAAqB;AACpE,SAAQ,IAAI,4BAA4B;CACxC,MAAM,QAAQ,YAAY,KAAK;CAC/B,MAAM,MAAM,cAAc;CAC1B,MAAM,cAAc,0CAAuB,IAAI;CAE/C,MAAM,UAAU,oBAAM,CAAC,eAAK,KAAK,MAAM,EAAE,GAAG,WAAY,GAAE,EACxD,eAAe,KAChB,EAAC;CAEF,IAAI,KAA0B;CAE9B,MAAM,wBAAwB,CAAC,cAAwC;AACrE,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,QAAK,GAA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C,SAAQ,GAAG,aAAa,WAAW;AACnC,SAAQ,GAAG,SAAS,CAAC,MAAM;AACzB,UAAQ,MAAM,EAAE;CACjB,EAAC;AAEF,SAAQ,OAAO,8BAAO,YAAY,qDAAqD,CAAC,GAAG,8BAAO,gBAAgB,CAAC,YAAY,KAAK,GAAG,OAAO,QAAQ,EAAE,CAAC,IAAI,CAAA;EAC7J,8BAAO,YAAY,0BAA0B,CAAC,GAAG,8BAAO,aAAa,MAAM,CAAC,GAAG,8BAAO,YAAY,YAAY,CAAA;;EAE9G,8BAAO,YAAY,YAAY,CAAA;EAC/B,8BAAO,aAAa,IAAI,CAAC;EACzB,8BAAO,aAAa,KAAK,CAAC;EAC1B,8BAAO,aAAa,KAAK,CAAC,sBAAsB;CAEhD,MAAM,aAAa,YAAY,KAAK;AAEpC,MAAK,MAAM,cAAc,IAAI;CAE7B,MAAM,WAAW,YAAY,KAAK;AAElC,SAAQ,KACL,IAAI,8BAAO,YAAY,oCAAoC,CAAC,GAAG,8BAAO,gBAAgB,CAAC,WAAW,YAAY,QAAQ,EAAE,CAAC,IAAI,CAAC,IAChI;AACH"}
|
|
1
|
+
{"version":3,"file":"development.js","names":[],"sources":["../../src/cli/development.ts"],"sourcesContent":["import { join } from 'path';\nimport { getPossibleConfigPaths, loadConfigFile } from '../config/loader';\nimport { isCompilerPlugin } from '../plugins';\nimport { createAppProcess } from './app-process';\nimport { buildApplication } from './build';\nimport { watch } from 'chokidar';\nimport { debounce } from '../utils/utilities';\nimport colors from '../utils/colors';\nimport { ChildProcess } from 'node:child_process';\nimport { setTimeout as sleep } from 'node:timers/promises';\nimport { randomUUID } from 'node:crypto';\nimport { COMMANDKIT_CWD, HMREventType } from '../utils/constants';\nimport { findEntrypoint } from './common';\n\n/**\n * @private\n * @internal\n */\nasync function buildAndStart(configPath: string, skipStart = false) {\n const config = await loadConfigFile(configPath);\n const mainFile = findEntrypoint('.commandkit');\n\n await buildApplication({\n configPath,\n isDev: true,\n plugins: config.plugins.flat(2).filter((p) => isCompilerPlugin(p)),\n rolldownPlugins: config.rolldownPlugins,\n });\n\n if (skipStart) return null as never;\n\n const ps = createAppProcess(mainFile, configPath, true);\n\n return ps;\n}\n\n/**\n * @private\n * @internal\n */\nconst isCommandSource = (p: string) =>\n p.replaceAll('\\\\', '/').includes('src/app/commands');\n\n/**\n * @private\n * @internal\n */\nconst isEventSource = (p: string) =>\n p.replaceAll('\\\\', '/').includes('src/app/events');\n\n/**\n * @private\n * @internal\n */\nexport async function bootstrapDevelopmentServer(configPath?: string) {\n process.env.COMMANDKIT_BOOTSTRAP_MODE = 'development';\n const start = performance.now();\n const cwd = configPath || COMMANDKIT_CWD;\n const configPaths = getPossibleConfigPaths(cwd);\n\n const watcher = watch([join(cwd, 'src'), ...configPaths], {\n ignoreInitial: true,\n });\n\n let ps: ChildProcess | null = null;\n\n const waitForAcknowledgment = (messageId: string): Promise<boolean> => {\n return new Promise((resolve) => {\n if (!ps) return resolve(false);\n\n let _handled = false;\n const onMessage = (message: any) => {\n _handled = true;\n if (typeof message !== 'object' || message === null) return;\n\n const { type, id, handled } = message;\n if (type === 'commandkit-hmr-ack' && id === messageId) {\n ps?.off('message', onMessage);\n resolve(!!handled);\n }\n };\n\n ps.once('message', onMessage);\n\n if (!_handled) {\n sleep(3000).then(() => {\n ps?.off('message', onMessage);\n resolve(false);\n });\n }\n });\n };\n\n const sendHmrEvent = async (\n event: HMREventType,\n path?: string,\n ): Promise<boolean> => {\n if (!ps || !ps.send) return false;\n\n const messageId = randomUUID();\n const messagePromise = waitForAcknowledgment(messageId);\n\n ps.send({ event, path, id: messageId });\n\n // Wait for acknowledgment or timeout after 3 seconds\n try {\n let triggered = false;\n const res = !!(await Promise.race([\n messagePromise,\n sleep(3000).then(() => {\n if (!triggered) {\n console.warn(\n colors.yellow(\n `HMR acknowledgment timed out for event ${event} on path ${path}`,\n ),\n );\n }\n return false;\n }),\n ]));\n\n triggered = true;\n\n return res;\n } catch (error) {\n console.error(\n colors.red(`Error waiting for HMR acknowledgment: ${error}`),\n );\n return false;\n }\n };\n\n const performHMR = debounce(async (path?: string): Promise<boolean> => {\n if (!path || !ps) return false;\n\n let eventType: HMREventType | null = null;\n let eventDescription = '';\n\n if (isCommandSource(path)) {\n eventType = HMREventType.ReloadCommands;\n eventDescription = 'command(s)';\n } else if (isEventSource(path)) {\n eventType = HMREventType.ReloadEvents;\n eventDescription = 'event(s)';\n } else {\n eventType = HMREventType.Unknown;\n eventDescription = 'unknown source';\n }\n\n if (eventType) {\n console.log(\n `${colors.cyanBright(`Attempting to reload ${eventDescription} at`)} ${colors.yellowBright(path)}`,\n );\n\n await buildAndStart(cwd, true);\n const hmrHandled = await sendHmrEvent(eventType, path);\n\n if (hmrHandled) {\n console.log(\n `${colors.greenBright(`Successfully hot reloaded ${eventDescription} at`)} ${colors.yellowBright(path)}`,\n );\n return true;\n }\n }\n\n return false;\n }, 300);\n\n const isConfigUpdate = (path: string) => {\n const isConfig = configPaths.some((configPath) => path === configPath);\n\n if (!isConfig) return false;\n\n console.log(\n colors.yellowBright(\n 'It seems like commandkit config file was updated, please restart the server manually to apply changes.',\n ),\n );\n\n return isConfig;\n };\n\n const hmrHandler = async (path: string) => {\n if (isConfigUpdate(path)) return;\n const hmr = await performHMR(path);\n if (hmr) return;\n\n console.log(\n `${colors.yellowBright('⚡️ Performing full restart due to the changes in')} ${colors.cyanBright(path)}`,\n );\n\n ps?.kill();\n ps = await buildAndStart(cwd);\n };\n\n process.stdin.on('data', async (d) => {\n const command = d.toString().trim();\n\n switch (command) {\n case 'r':\n console.log(`Received restart command, restarting...`);\n ps?.kill();\n ps = null;\n ps = await buildAndStart(cwd);\n break;\n case 'rc':\n console.log(`Received reload commands command, reloading...`);\n await sendHmrEvent(HMREventType.ReloadCommands);\n break;\n case 're':\n console.log(`Received reload events command, reloading...`);\n await sendHmrEvent(HMREventType.ReloadEvents);\n break;\n break;\n }\n });\n\n watcher.on('change', hmrHandler);\n watcher.on('add', hmrHandler);\n watcher.on('unlink', hmrHandler);\n watcher.on('unlinkDir', hmrHandler);\n watcher.on('error', (e) => {\n console.error(e);\n });\n\n console.log(`${colors.greenBright('Bootstrapped CommandKit Development Environment in')} ${colors.yellowBright(`${(performance.now() - start).toFixed(2)}ms`)}\n${colors.greenBright('Watching for changes in')} ${colors.yellowBright('src')} ${colors.greenBright('directory')}\n\n${colors.greenBright('Commands:')}\n${colors.yellowBright('r')} - Restart the server\n${colors.yellowBright('rc')} - Reload all commands\n${colors.yellowBright('re')} - Reload all events`);\n\n const buildStart = performance.now();\n\n ps = await buildAndStart(cwd);\n\n const buildEnd = performance.now();\n\n console.log(\n `\\n${colors.greenBright('Development mode compilation took')} ${colors.yellowBright(`${(buildEnd - buildStart).toFixed(2)}ms`)}\\n`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,eAAe,cAAc,YAAoB,YAAY,OAAO;CAClE,MAAM,SAAS,MAAM,kCAAe,WAAW;CAC/C,MAAM,WAAW,gCAAe,cAAc;CAE9C,MAAM,+BAAiB;EACrB;EACA,OAAO;EACP,SAAS,OAAO,QAAQ,KAAK,EAAE,CAAC,OAAO,CAAC,MAAM,wCAAiB,EAAE,CAAC;EAClE,iBAAiB,OAAO;CACzB,EAAC;AAEF,KAAI,UAAW,QAAO;CAEtB,MAAM,KAAK,qCAAiB,UAAU,YAAY,KAAK;AAEvD,QAAO;AACT;;;;;AAMA,MAAM,kBAAkB,CAAC,MACzB,EAAE,WAAW,MAAM,IAAI,CAAC,SAAS,mBAAmB;;;;;AAMpD,MAAM,gBAAgB,CAAC,MACvB,EAAE,WAAW,MAAM,IAAI,CAAC,SAAS,iBAAiB;;;;;AAMlD,eAAsB,2BAA2B,YAAqB;CACpE,QAAQ,IAAI,4BAA4B;CACxC,MAAM,QAAQ,YAAY,KAAK;CAC/B,MAAM,MAAM,cAAc;CAC1B,MAAM,cAAc,0CAAuB,IAAI;CAE/C,MAAM,8BA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