commandkit 1.2.0-rc.13 → 1.2.0-rc.15
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/README.md +42 -23
- package/dist/{ActionRow-B-CGmjDp.d.ts → ActionRow-Bt9qi0Mb.d.ts} +2 -2
- package/dist/{Button-C-GPeFA3.d.ts → Button-DxJLcZIU.d.ts} +5 -5
- package/dist/{ButtonKit-DKu0VAe4.d.ts → ButtonKit-BfcyvWfj.d.ts} +35 -35
- package/dist/{ChannelSelectMenuKit-HQZ4hH5s.d.ts → ChannelSelectMenuKit-DYkudikb.d.ts} +33 -33
- package/dist/{CommandsRouter-C7dZEepB.d.ts → CommandsRouter-DiNoF0dq.d.ts} +48 -48
- package/dist/{EventInterceptor-CZmWpS08.d.ts → EventInterceptor-D9JKMcfi.d.ts} +39 -39
- package/dist/{EventsRouter-DZ37r54v.d.ts → EventsRouter-EuuSu6NH.d.ts} +34 -34
- package/dist/{MentionableSelectMenuKit-7URDUM3-.d.ts → MentionableSelectMenuKit-Mu4xqP6B.d.ts} +33 -33
- package/dist/MessageCommandParser-DPCbHXCS.d.ts +194 -0
- package/dist/{Modal-CZT9MZsy.d.ts → Modal-v9rrcMl-.d.ts} +7 -7
- package/dist/{ModalKit-BWXI3Z26.d.ts → ModalKit-XJSM65SV.d.ts} +32 -32
- package/dist/{RoleSelectMenuKit-BY-JJ18w.d.ts → RoleSelectMenuKit-CCjcp3HY.d.ts} +33 -33
- package/dist/{SelectMenu-q_b3Mjv9.d.ts → SelectMenu-CY0vvoSu.d.ts} +15 -11
- package/dist/{StringSelectMenuKit-lVhUMc3g.d.ts → StringSelectMenuKit-G5nBTicX.d.ts} +33 -33
- package/dist/{UserSelectMenuKit-CCj4Fpkr.d.ts → UserSelectMenuKit-D3SO_fXA.d.ts} +33 -33
- package/dist/analytics/analytics-engine.d.ts +1 -1
- package/dist/analytics/analytics-engine.js +2 -24
- package/dist/analytics/analytics-provider.d.ts +1 -1
- package/dist/analytics/analytics-provider.js +1 -0
- package/dist/analytics/constants.js +26 -3
- package/dist/analytics/constants.js.map +1 -0
- package/dist/analytics/utils.js +2 -24
- package/dist/{analytics-engine-WQhXmx3H.d.ts → analytics-engine-DnRsHBId.d.ts} +846 -841
- package/dist/app/commands/AppCommandRunner.d.ts +1 -1
- package/dist/app/commands/AppCommandRunner.js +2 -24
- package/dist/app/commands/Context.d.ts +1 -1
- package/dist/app/commands/Context.js +2 -24
- package/dist/app/commands/MessageCommandParser.d.ts +1 -1
- package/dist/app/commands/MessageCommandParser.js +261 -3
- package/dist/app/commands/MessageCommandParser.js.map +1 -0
- package/dist/app/commands/helpers.d.ts +1 -1
- package/dist/app/commands/helpers.js +25 -3
- package/dist/app/commands/helpers.js.map +1 -0
- package/dist/app/events/EventWorkerContext.d.ts +2 -2
- package/dist/app/events/EventWorkerContext.js +48 -5
- package/dist/app/events/EventWorkerContext.js.map +1 -0
- package/dist/app/handlers/AppCommandHandler.d.ts +1 -1
- package/dist/app/handlers/AppCommandHandler.js +2 -24
- package/dist/app/handlers/AppEventsHandler.d.ts +1 -1
- package/dist/app/handlers/AppEventsHandler.js +2 -24
- package/dist/app/index.d.ts +4 -4
- package/dist/app/index.js +13 -32
- package/dist/app/interrupt/signals.d.ts +1 -1
- package/dist/app/interrupt/signals.js +54 -6
- package/dist/app/interrupt/signals.js.map +1 -0
- package/dist/app/middlewares/permissions.d.ts +1 -1
- package/dist/app/middlewares/permissions.js +2 -24
- package/dist/app/register/CommandRegistrar.d.ts +1 -1
- package/dist/app/register/CommandRegistrar.js +2 -24
- package/dist/app/router/CommandsRouter.d.ts +1 -1
- package/dist/app/router/CommandsRouter.js +210 -2
- package/dist/app/router/CommandsRouter.js.map +1 -0
- package/dist/app/router/EventsRouter.d.ts +1 -1
- package/dist/app/router/EventsRouter.js +128 -2
- package/dist/app/router/EventsRouter.js.map +1 -0
- package/dist/app/router/index.d.ts +2 -2
- package/dist/app/router/index.js +5 -5
- package/dist/{chunk-kSYXY2_d.js → chunk-BE-pF4vm.js} +1 -1
- package/dist/cli/app-process.d.ts +2 -2
- package/dist/cli/app-process.js +6 -8
- package/dist/cli/app-process.js.map +1 -1
- package/dist/cli/build.d.ts +2 -2
- package/dist/cli/build.js +15 -35
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/common.d.ts +5 -5
- package/dist/cli/common.js +182 -12
- package/dist/cli/common.js.map +1 -0
- package/dist/cli/development.d.ts +3 -3
- package/dist/cli/development.js +38 -59
- package/dist/cli/development.js.map +1 -1
- package/dist/cli/env.js +73 -9
- package/dist/cli/env.js.map +1 -0
- package/dist/cli/generators.js +10 -10
- package/dist/cli/generators.js.map +1 -1
- package/dist/cli/information.js +8 -7
- package/dist/cli/information.js.map +1 -1
- package/dist/cli/init.d.ts +2 -2
- package/dist/cli/init.js +14 -33
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/production.d.ts +2 -2
- package/dist/cli/production.js +11 -33
- package/dist/cli/production.js.map +1 -1
- package/dist/cli/type-checker.js +83 -6
- package/dist/cli/type-checker.js.map +1 -0
- package/dist/cli/utils.js +1 -0
- package/dist/cli/utils.js.map +1 -1
- package/dist/{commandkit-SIjTLD2R.js → commandkit--k6yDJEr.js} +3157 -2699
- package/dist/commandkit--k6yDJEr.js.map +1 -0
- package/dist/commandkit.d.ts +1 -1
- package/dist/commandkit.js +2 -24
- package/dist/{common-DnwCYit8.d.ts → common-CCvvgnxi.d.ts} +2 -2
- package/dist/components/common/EventInterceptor.d.ts +1 -1
- package/dist/components/common/EventInterceptor.js +137 -2
- package/dist/components/common/EventInterceptor.js.map +1 -0
- package/dist/components/common/element.d.ts +2 -2
- package/dist/components/common/element.js +10 -8
- package/dist/components/common/types.d.ts +1 -1
- package/dist/components/common/types.js +1 -0
- package/dist/components/display/common.js +3 -2
- package/dist/components/display/container.d.ts +1 -1
- package/dist/components/display/container.js +3 -2
- package/dist/components/display/file.d.ts +1 -1
- package/dist/components/display/file.js +23 -2
- package/dist/components/display/file.js.map +1 -0
- package/dist/components/display/index.d.ts +8 -8
- package/dist/components/display/index.js +18 -21
- package/dist/components/display/label.d.ts +1 -1
- package/dist/components/display/label.js +3 -2
- package/dist/components/display/media-gallery.d.ts +1 -1
- package/dist/components/display/media-gallery.js +4 -3
- package/dist/components/display/poll.d.ts +1 -1
- package/dist/components/display/poll.js +85 -4
- package/dist/{poll-CFe8yvoJ.js.map → components/display/poll.js.map} +1 -1
- package/dist/components/display/section.d.ts +1 -1
- package/dist/components/display/section.js +4 -3
- package/dist/components/display/separator.d.ts +1 -1
- package/dist/components/display/separator.js +21 -2
- package/dist/components/display/separator.js.map +1 -0
- package/dist/components/display/text-display.d.ts +1 -1
- package/dist/components/display/text-display.js +26 -2
- package/dist/components/display/text-display.js.map +1 -0
- package/dist/components/index.d.ts +23 -23
- package/dist/components/index.js +28 -45
- package/dist/components/interactive/action-row/ActionRow.d.ts +1 -1
- package/dist/components/interactive/action-row/ActionRow.js +20 -2
- package/dist/{ActionRow-CSN_UKmM.js.map → components/interactive/action-row/ActionRow.js.map} +1 -1
- package/dist/components/interactive/button/Button.d.ts +1 -1
- package/dist/components/interactive/button/Button.js +2 -24
- package/dist/components/interactive/button/ButtonKit.d.ts +1 -1
- package/dist/components/interactive/button/ButtonKit.js +2 -24
- package/dist/components/interactive/modal/Modal.d.ts +1 -1
- package/dist/components/interactive/modal/Modal.js +2 -24
- package/dist/components/interactive/modal/ModalKit.d.ts +1 -1
- package/dist/components/interactive/modal/ModalKit.js +2 -24
- package/dist/components/interactive/select-menu/ChannelSelectMenuKit.d.ts +1 -1
- package/dist/components/interactive/select-menu/ChannelSelectMenuKit.js +2 -24
- package/dist/components/interactive/select-menu/MentionableSelectMenuKit.d.ts +1 -1
- package/dist/components/interactive/select-menu/MentionableSelectMenuKit.js +2 -24
- package/dist/components/interactive/select-menu/RoleSelectMenuKit.d.ts +1 -1
- package/dist/components/interactive/select-menu/RoleSelectMenuKit.js +2 -24
- package/dist/components/interactive/select-menu/SelectMenu.d.ts +1 -1
- package/dist/components/interactive/select-menu/SelectMenu.js +2 -24
- package/dist/components/interactive/select-menu/StringSelectMenuKit.d.ts +1 -1
- package/dist/components/interactive/select-menu/StringSelectMenuKit.js +2 -24
- package/dist/components/interactive/select-menu/UserSelectMenuKit.d.ts +1 -1
- package/dist/components/interactive/select-menu/UserSelectMenuKit.js +2 -24
- package/dist/components/interactive/select-menu/common.d.ts +1 -1
- package/dist/components/interactive/select-menu/common.js +1 -0
- package/dist/config/config.d.ts +1 -1
- package/dist/config/config.js +2 -24
- package/dist/config/default.d.ts +1 -1
- package/dist/config/default.js +2 -24
- package/dist/config/loader.d.ts +1 -1
- package/dist/config/loader.js +2 -24
- package/dist/config/types.d.ts +1 -1
- package/dist/config/types.js +1 -0
- package/dist/config/utils.d.ts +1 -1
- package/dist/config/utils.js +29 -2
- package/dist/config/utils.js.map +1 -0
- package/dist/{constants-EpKcj0dH.d.ts → constants-DqtJY0t-.d.ts} +2 -2
- package/dist/{constants-CuYW0K10.d.ts → constants-DwxpkIeH.d.ts} +7 -7
- package/dist/{container-DYcb7zGw.d.ts → container-CYojOA9d.d.ts} +1 -1
- package/dist/context/async-context.d.ts +1 -1
- package/dist/context/async-context.js +2 -24
- package/dist/context/environment.d.ts +1 -1
- package/dist/context/environment.js +2 -24
- package/dist/{element-wQo0heGj.d.ts → element-DeLvTMfZ.d.ts} +5 -4
- package/dist/events/CommandKitEventsChannel.d.ts +1 -1
- package/dist/events/CommandKitEventsChannel.js +83 -2
- package/dist/events/CommandKitEventsChannel.js.map +1 -0
- package/dist/{file-CrV4lSnl.d.ts → file-DLO1zEcH.d.ts} +1 -1
- package/dist/flags/FlagProvider.d.ts +1 -1
- package/dist/flags/FlagProvider.js +1 -0
- package/dist/flags/FlagProvider.js.map +1 -1
- package/dist/flags/feature-flags.d.ts +1 -1
- package/dist/flags/feature-flags.js +5 -165
- package/dist/flags/store.d.ts +1 -1
- package/dist/flags/store.js +13 -2
- package/dist/flags/store.js.map +1 -0
- package/dist/{helpers-AQPLVY35.d.ts → helpers-zmC44Mcu.d.ts} +1 -1
- package/dist/index.d.ts +31 -31
- package/dist/index.js +78 -97
- package/dist/kv/constants.d.ts +1 -1
- package/dist/kv/constants.js +22 -2
- package/dist/kv/constants.js.map +1 -0
- package/dist/kv/dotprops.js +1 -0
- package/dist/kv/dotprops.js.map +1 -1
- package/dist/kv/kv.d.ts +288 -288
- package/dist/kv/kv.js +2 -1
- package/dist/kv/kv.js.map +1 -1
- package/dist/kv/serde.d.ts +1 -1
- package/dist/kv/serde.js +29 -28
- package/dist/kv/serde.js.map +1 -1
- package/dist/{label-37kaNWMH.d.ts → label-DqGRqodo.d.ts} +3 -3
- package/dist/logger/DefaultLogger.d.ts +19 -19
- package/dist/logger/DefaultLogger.js +2 -24
- package/dist/logger/ILogger.d.ts +35 -35
- package/dist/logger/ILogger.js +1 -0
- package/dist/logger/Logger.d.ts +5 -5
- package/dist/logger/Logger.js +2 -24
- package/dist/logger/NoopLogger.d.ts +35 -35
- package/dist/logger/NoopLogger.js +1 -0
- package/dist/logger/NoopLogger.js.map +1 -1
- package/dist/{media-gallery-Ci3I4ElH.d.ts → media-gallery-Ca8es-eB.d.ts} +1 -1
- package/dist/plugins/CompilerPlugin.d.ts +1 -1
- package/dist/plugins/CompilerPlugin.js +33 -3
- package/dist/plugins/CompilerPlugin.js.map +1 -0
- package/dist/plugins/PluginCommon.d.ts +1 -1
- package/dist/plugins/PluginCommon.js +55 -4
- package/dist/plugins/PluginCommon.js.map +1 -0
- package/dist/plugins/RuntimePlugin.d.ts +1 -1
- package/dist/plugins/RuntimePlugin.js +124 -3
- package/dist/plugins/RuntimePlugin.js.map +1 -0
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +8 -30
- package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.d.ts +1 -1
- package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.js +2 -24
- package/dist/plugins/plugin-runtime/CompilerPluginRuntime.d.ts +1 -1
- package/dist/plugins/plugin-runtime/CompilerPluginRuntime.js +2 -24
- package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.d.ts +1 -1
- package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.js +2 -24
- package/dist/plugins/plugin-runtime/builtin/MacroPlugin.d.ts +1 -1
- package/dist/plugins/plugin-runtime/builtin/MacroPlugin.js +2 -24
- package/dist/plugins/plugin-runtime/runtime.d.ts +1 -1
- package/dist/plugins/plugin-runtime/runtime.js +1 -0
- package/dist/plugins/types.d.ts +1 -1
- package/dist/plugins/types.js +1 -0
- package/dist/{poll-Ddtapd6n.d.ts → poll-DQ6DX_Tt.d.ts} +8 -8
- package/dist/{section-DkUKULnB.d.ts → section-Q8nwx_-q.d.ts} +1 -1
- package/dist/{separator-CbXsIFCa.d.ts → separator-B8P-kdIK.d.ts} +1 -1
- package/dist/{signals-BbTgTc0i.d.ts → signals-CBXwugBW.d.ts} +1 -1
- package/dist/{text-display-D7j39VC-.d.ts → text-display-CL9C2yMc.d.ts} +1 -1
- package/dist/{types-BywA9d2Z.d.ts → types-DZy7U-Ld.d.ts} +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -0
- package/dist/utils/colors.js +9 -3
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/constants.js +50 -8
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/dev-hooks.d.ts +1 -1
- package/dist/utils/dev-hooks.js +2 -24
- package/dist/utils/error-codes.d.ts +10 -10
- package/dist/utils/error-codes.js +53 -5
- package/dist/utils/error-codes.js.map +1 -0
- package/dist/utils/resolve-file-url.js +18 -2
- package/dist/utils/resolve-file-url.js.map +1 -0
- package/dist/utils/types-package.js +61 -4
- package/dist/utils/types-package.js.map +1 -0
- package/dist/utils/useful-stuff/async-queue.d.ts +21 -21
- package/dist/utils/useful-stuff/async-queue.js +1 -0
- package/dist/utils/useful-stuff/async-queue.js.map +1 -1
- package/dist/utils/useful-stuff/mutex.d.ts +62 -62
- package/dist/utils/useful-stuff/mutex.js +1 -0
- package/dist/utils/useful-stuff/mutex.js.map +1 -1
- package/dist/utils/useful-stuff/ratelimiter.d.ts +56 -56
- package/dist/utils/useful-stuff/ratelimiter.js +1 -0
- package/dist/utils/useful-stuff/ratelimiter.js.map +1 -1
- package/dist/utils/useful-stuff/semaphore.d.ts +82 -82
- package/dist/utils/useful-stuff/semaphore.js +1 -0
- package/dist/utils/useful-stuff/semaphore.js.map +1 -1
- package/dist/utils/utilities.d.ts +5 -5
- package/dist/utils/utilities.js +2 -24
- package/dist/utils/warning.js +38 -4
- package/dist/utils/warning.js.map +1 -0
- package/dist/version.js +2 -1
- package/dist/version.js.map +1 -1
- package/package.json +12 -15
- package/dist/ActionRow-CSN_UKmM.js +0 -25
- package/dist/CommandKitEventsChannel-CnT5ymYe.js +0 -88
- package/dist/CommandKitEventsChannel-CnT5ymYe.js.map +0 -1
- package/dist/CommandsRouter-C_HLsrGX.js +0 -215
- package/dist/CommandsRouter-C_HLsrGX.js.map +0 -1
- package/dist/CompilerPlugin-CUsGAfgl.js +0 -43
- package/dist/CompilerPlugin-CUsGAfgl.js.map +0 -1
- package/dist/EventInterceptor-BWoEJMHZ.js +0 -142
- package/dist/EventInterceptor-BWoEJMHZ.js.map +0 -1
- package/dist/EventWorkerContext-Dfhgv329.js +0 -68
- package/dist/EventWorkerContext-Dfhgv329.js.map +0 -1
- package/dist/EventsRouter-DZYIha6m.js +0 -133
- package/dist/EventsRouter-DZYIha6m.js.map +0 -1
- package/dist/MessageCommandParser-Bs9fimmd.js +0 -271
- package/dist/MessageCommandParser-Bs9fimmd.js.map +0 -1
- package/dist/MessageCommandParser-q3dQcE5N.d.ts +0 -194
- package/dist/PluginCommon-BLxWww5u.js +0 -70
- package/dist/PluginCommon-BLxWww5u.js.map +0 -1
- package/dist/RuntimePlugin-CtobluSU.js +0 -134
- package/dist/RuntimePlugin-CtobluSU.js.map +0 -1
- package/dist/colors-Csc0X4QJ.js +0 -14
- package/dist/colors-Csc0X4QJ.js.map +0 -1
- package/dist/commandkit-SIjTLD2R.js.map +0 -1
- package/dist/common-C2jAjX4U.js +0 -0
- package/dist/common-CEordwf3.js +0 -17
- package/dist/common-CEordwf3.js.map +0 -1
- package/dist/common-DSRs_mfw.js +0 -222
- package/dist/common-DSRs_mfw.js.map +0 -1
- package/dist/constants-BFFK-hfP.js +0 -27
- package/dist/constants-BFFK-hfP.js.map +0 -1
- package/dist/constants-Cw8VjCVz.js +0 -36
- package/dist/constants-Cw8VjCVz.js.map +0 -1
- package/dist/constants-CxkFFZ7p.js +0 -85
- package/dist/constants-CxkFFZ7p.js.map +0 -1
- package/dist/container-DCPljKVH.js +0 -43
- package/dist/container-DCPljKVH.js.map +0 -1
- package/dist/display-WDb9wMCv.js +0 -0
- package/dist/element-DibzzA5L.js +0 -84
- package/dist/element-DibzzA5L.js.map +0 -1
- package/dist/env-CmspDhHy.js +0 -113
- package/dist/env-CmspDhHy.js.map +0 -1
- package/dist/error-codes-Ds0bnPvT.js +0 -73
- package/dist/error-codes-Ds0bnPvT.js.map +0 -1
- package/dist/file-Ca1kpEtE.js +0 -28
- package/dist/file-Ca1kpEtE.js.map +0 -1
- package/dist/flags/feature-flags.js.map +0 -1
- package/dist/helpers-Btx1FSZx.js +0 -35
- package/dist/helpers-Btx1FSZx.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/label-B6vXvwLM.js +0 -35
- package/dist/label-B6vXvwLM.js.map +0 -1
- package/dist/media-gallery-u3gjX7yD.js +0 -61
- package/dist/media-gallery-u3gjX7yD.js.map +0 -1
- package/dist/poll-CFe8yvoJ.js +0 -100
- package/dist/resolve-file-url-CdHqwWs3.js +0 -23
- package/dist/resolve-file-url-CdHqwWs3.js.map +0 -1
- package/dist/router-BvamdzoF.js +0 -0
- package/dist/runtime-Skt5NiOc.js +0 -0
- package/dist/section-BC8LF-B2.js +0 -59
- package/dist/section-BC8LF-B2.js.map +0 -1
- package/dist/separator-BUTiW7uz.js +0 -26
- package/dist/separator-BUTiW7uz.js.map +0 -1
- package/dist/signals-B8z1wJ6W.js +0 -74
- package/dist/signals-B8z1wJ6W.js.map +0 -1
- package/dist/store-D8r_hryO.js +0 -18
- package/dist/store-D8r_hryO.js.map +0 -1
- package/dist/text-display-DANahMN3.js +0 -31
- package/dist/text-display-DANahMN3.js.map +0 -1
- package/dist/type-checker-cVd3Hpnh.js +0 -88
- package/dist/type-checker-cVd3Hpnh.js.map +0 -1
- package/dist/types-Cdh4uaFR.js +0 -0
- package/dist/types-TC4g3w91.js +0 -0
- package/dist/types-package-CsTNfvv2.js +0 -71
- package/dist/types-package-CsTNfvv2.js.map +0 -1
- package/dist/utils-Br3eenD1.js +0 -34
- package/dist/utils-Br3eenD1.js.map +0 -1
- package/dist/warning-CszH8HeS.js +0 -53
- package/dist/warning-CszH8HeS.js.map +0 -1
- /package/dist/{index-BJfko-dP.d.ts → index-BIsCUWAs.d.ts} +0 -0
- /package/dist/{index-CCggO_hw.d.ts → index-CwHYpK-f.d.ts} +0 -0
- /package/dist/{index-CLjpoGi1.d.ts → index-DHrsNvX1.d.ts} +0 -0
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-kSYXY2_d.js');
|
|
2
|
-
let discord_js = require("discord.js");
|
|
3
|
-
let node_fs = require("node:fs");
|
|
4
|
-
let node_path = require("node:path");
|
|
5
|
-
let node_fs_promises = require("node:fs/promises");
|
|
6
|
-
|
|
7
|
-
//#region src/app/router/CommandsRouter.ts
|
|
8
|
-
/**
|
|
9
|
-
* @private
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
const MIDDLEWARE_PATTERN = /^\+middleware\.(m|c)?(j|t)sx?$/;
|
|
13
|
-
/**
|
|
14
|
-
* @private
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
const COMMAND_MIDDLEWARE_PATTERN = /^\+([^+().][^().]*)\.middleware\.(m|c)?(j|t)sx?$/;
|
|
18
|
-
/**
|
|
19
|
-
* @private
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
const GLOBAL_MIDDLEWARE_PATTERN = /^\+global-middleware\.(m|c)?(j|t)sx?$/;
|
|
23
|
-
/**
|
|
24
|
-
* @private
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
const COMMAND_PATTERN = /^([^+().][^().]*)\.(m|c)?(j|t)sx?$/;
|
|
28
|
-
/**
|
|
29
|
-
* @private
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
const CATEGORY_PATTERN = /^\(.+\)$/;
|
|
33
|
-
/**
|
|
34
|
-
* Handles discovery and parsing of command and middleware files in the filesystem.
|
|
35
|
-
*/
|
|
36
|
-
var CommandsRouter = class {
|
|
37
|
-
/**
|
|
38
|
-
* @private
|
|
39
|
-
* @internal
|
|
40
|
-
*/
|
|
41
|
-
commands = new discord_js.Collection();
|
|
42
|
-
/**
|
|
43
|
-
* @private
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
middlewares = new discord_js.Collection();
|
|
47
|
-
/**
|
|
48
|
-
* Creates a new CommandsRouter instance.
|
|
49
|
-
* @param options - Configuration options for the router
|
|
50
|
-
*/
|
|
51
|
-
constructor(options) {
|
|
52
|
-
this.options = options;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Populates the router with existing command and middleware data.
|
|
56
|
-
* @param data - Parsed command data to populate with
|
|
57
|
-
*/
|
|
58
|
-
populate(data) {
|
|
59
|
-
for (const [id, command] of Object.entries(data.commands)) this.commands.set(id, command);
|
|
60
|
-
for (const [id, middleware] of Object.entries(data.middlewares)) this.middlewares.set(id, middleware);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Checks if the configured entrypoint path exists.
|
|
64
|
-
* @returns True if the path exists
|
|
65
|
-
*/
|
|
66
|
-
isValidPath() {
|
|
67
|
-
return (0, node_fs.existsSync)(this.options.entrypoint);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* @private
|
|
71
|
-
* @internal
|
|
72
|
-
*/
|
|
73
|
-
isCommand(name) {
|
|
74
|
-
return COMMAND_PATTERN.test(name);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* @private
|
|
78
|
-
* @internal
|
|
79
|
-
*/
|
|
80
|
-
isMiddleware(name) {
|
|
81
|
-
return MIDDLEWARE_PATTERN.test(name) || GLOBAL_MIDDLEWARE_PATTERN.test(name) || COMMAND_MIDDLEWARE_PATTERN.test(name);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* @private
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
|
-
isCategory(name) {
|
|
88
|
-
return CATEGORY_PATTERN.test(name);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Clears all loaded commands and middleware.
|
|
92
|
-
*/
|
|
93
|
-
clear() {
|
|
94
|
-
this.commands.clear();
|
|
95
|
-
this.middlewares.clear();
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Scans the filesystem for commands and middleware files.
|
|
99
|
-
* @returns Parsed command data
|
|
100
|
-
*/
|
|
101
|
-
async scan() {
|
|
102
|
-
const entries = await (0, node_fs_promises.readdir)(this.options.entrypoint, { withFileTypes: true });
|
|
103
|
-
for (const entry of entries) {
|
|
104
|
-
if (entry.name.startsWith("_")) continue;
|
|
105
|
-
const fullPath = (0, node_path.join)(this.options.entrypoint, entry.name);
|
|
106
|
-
if (entry.isDirectory()) {
|
|
107
|
-
const category = this.isCategory(entry.name) ? entry.name.slice(1, -1) : null;
|
|
108
|
-
await this.traverse(fullPath, category);
|
|
109
|
-
} else await this.handle(entry);
|
|
110
|
-
}
|
|
111
|
-
await this.applyMiddlewares();
|
|
112
|
-
return this.toJSON();
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Gets the raw command and middleware collections.
|
|
116
|
-
* @returns Object containing commands and middlewares collections
|
|
117
|
-
*/
|
|
118
|
-
getData() {
|
|
119
|
-
return {
|
|
120
|
-
commands: this.commands,
|
|
121
|
-
middlewares: this.middlewares
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Converts the loaded data to a JSON-serializable format.
|
|
126
|
-
* @returns Plain object with commands and middlewares
|
|
127
|
-
*/
|
|
128
|
-
toJSON() {
|
|
129
|
-
return {
|
|
130
|
-
commands: Object.fromEntries(this.commands.entries()),
|
|
131
|
-
middlewares: Object.fromEntries(this.middlewares.entries())
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* @private
|
|
136
|
-
* @internal
|
|
137
|
-
*/
|
|
138
|
-
async traverse(path, category) {
|
|
139
|
-
const entries = await (0, node_fs_promises.readdir)(path, { withFileTypes: true });
|
|
140
|
-
for (const entry of entries) {
|
|
141
|
-
if (entry.name.startsWith("_")) continue;
|
|
142
|
-
if (entry.isFile()) {
|
|
143
|
-
if (this.isCommand(entry.name) || this.isMiddleware(entry.name)) await this.handle(entry, category);
|
|
144
|
-
} else if (entry.isDirectory() && this.isCategory(entry.name) && category) {
|
|
145
|
-
const nestedCategory = this.isCategory(entry.name) ? `${category}:${entry.name.slice(1, -1)}` : null;
|
|
146
|
-
await this.traverse((0, node_path.join)(path, entry.name), nestedCategory);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* @private
|
|
152
|
-
* @internal
|
|
153
|
-
*/
|
|
154
|
-
async handle(entry, category = null) {
|
|
155
|
-
const name = entry.name;
|
|
156
|
-
const path = (0, node_path.join)(entry.parentPath, entry.name);
|
|
157
|
-
if (this.isCommand(name)) {
|
|
158
|
-
const command = {
|
|
159
|
-
id: crypto.randomUUID(),
|
|
160
|
-
name: (0, node_path.basename)(path, (0, node_path.extname)(path)),
|
|
161
|
-
path,
|
|
162
|
-
category,
|
|
163
|
-
parentPath: entry.parentPath,
|
|
164
|
-
relativePath: this.replaceEntrypoint(path),
|
|
165
|
-
middlewares: []
|
|
166
|
-
};
|
|
167
|
-
this.commands.set(command.id, command);
|
|
168
|
-
} else if (this.isMiddleware(name)) {
|
|
169
|
-
var _name$match;
|
|
170
|
-
const middleware = {
|
|
171
|
-
id: crypto.randomUUID(),
|
|
172
|
-
name: (0, node_path.basename)(path, (0, node_path.extname)(path)),
|
|
173
|
-
path,
|
|
174
|
-
relativePath: this.replaceEntrypoint(path),
|
|
175
|
-
parentPath: entry.parentPath,
|
|
176
|
-
global: GLOBAL_MIDDLEWARE_PATTERN.test(name),
|
|
177
|
-
command: COMMAND_MIDDLEWARE_PATTERN.test(name) ? ((_name$match = name.match(COMMAND_MIDDLEWARE_PATTERN)) === null || _name$match === void 0 ? void 0 : _name$match[1]) || null : null
|
|
178
|
-
};
|
|
179
|
-
this.middlewares.set(middleware.id, middleware);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* @private
|
|
184
|
-
* @internal
|
|
185
|
-
*/
|
|
186
|
-
applyMiddlewares() {
|
|
187
|
-
this.commands.forEach((command) => {
|
|
188
|
-
const commandPath = command.parentPath;
|
|
189
|
-
const allMiddlewares = Array.from(this.middlewares.values());
|
|
190
|
-
const commandSpecificMiddlewares = allMiddlewares.filter((middleware) => middleware.command === command.name).map((middleware) => middleware.id);
|
|
191
|
-
const directorySpecificMiddlewares = allMiddlewares.filter((middleware) => !middleware.global && !middleware.command && middleware.parentPath === commandPath).map((middleware) => middleware.id);
|
|
192
|
-
command.middlewares = [
|
|
193
|
-
...allMiddlewares.filter((middleware) => middleware.global).map((middleware) => middleware.id),
|
|
194
|
-
...directorySpecificMiddlewares,
|
|
195
|
-
...commandSpecificMiddlewares
|
|
196
|
-
];
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* @private
|
|
201
|
-
* @internal
|
|
202
|
-
*/
|
|
203
|
-
replaceEntrypoint(path) {
|
|
204
|
-
return (0, node_path.normalize)(path).replace(this.options.entrypoint, "");
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
//#endregion
|
|
209
|
-
Object.defineProperty(exports, 'CommandsRouter', {
|
|
210
|
-
enumerable: true,
|
|
211
|
-
get: function () {
|
|
212
|
-
return CommandsRouter;
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
//# sourceMappingURL=CommandsRouter-C_HLsrGX.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CommandsRouter-C_HLsrGX.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.match(COMMAND_MIDDLEWARE_PATTERN)?.[1] || 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 allMiddlewares = Array.from(this.middlewares.values());\n\n const commandSpecificMiddlewares = allMiddlewares\n .filter((middleware) => middleware.command === command.name)\n .map((middleware) => middleware.id);\n\n const directorySpecificMiddlewares = allMiddlewares\n .filter(\n (middleware) =>\n !middleware.global &&\n !middleware.command &&\n middleware.parentPath === commandPath,\n )\n .map((middleware) => middleware.id);\n\n const globalMiddlewares = allMiddlewares\n .filter((middleware) => middleware.global)\n .map((middleware) => middleware.id);\n\n command.middlewares = [\n ...globalMiddlewares,\n ...directorySpecificMiddlewares,\n ...commandSpecificMiddlewares,\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,uBAA6B;;;;;CAMpD,AAAQ,cAAc,IAAI,uBAAgC;;;;;CAM1D,AAAO,YAAY,AAAiB,SAAgC;EAAhC;;;;;;CAMpC,AAAO,SAAS,MAAyB;AACvC,OAAK,MAAM,CAAC,IAAI,YAAY,OAAO,QAAQ,KAAK,SAAS,CACvD,MAAK,SAAS,IAAI,IAAI,QAAQ;AAGhC,OAAK,MAAM,CAAC,IAAI,eAAe,OAAO,QAAQ,KAAK,YAAY,CAC7D,MAAK,YAAY,IAAI,IAAI,WAAW;;;;;;CAQxC,AAAO,cAAuB;AAC5B,iCAAkB,KAAK,QAAQ,WAAW;;;;;;CAO5C,AAAQ,UAAU,MAAuB;AACvC,SAAO,gBAAgB,KAAK,KAAK;;;;;;CAOnC,AAAQ,aAAa,MA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AAW;AAMlC,WAAQ,cAAc;IACtB,GAL0B,eAC1B,QAAG,eAAoB,WAAG,OAAW,CACrC,KAAG,eAAiB,WAAG,GAAW;IAIlC,GAAG;IACH,GAAG;IAAE;IAEL;;;;;;CAOJ,AAAQ,kBAAkB,MAAc;AAEtC,kCAD6B,KAAK,CAChB,QAAQ,KAAK,QAAQ,YAAY,GAAG"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const require_PluginCommon = require('./PluginCommon-BLxWww5u.js');
|
|
2
|
-
|
|
3
|
-
//#region src/plugins/CompilerPlugin.ts
|
|
4
|
-
/**
|
|
5
|
-
* CommandKit plugin that runs at compile time.
|
|
6
|
-
*/
|
|
7
|
-
var CompilerPlugin = class extends require_PluginCommon.PluginCommon {
|
|
8
|
-
/**
|
|
9
|
-
* The type of the plugin, which is Compiler.
|
|
10
|
-
*/
|
|
11
|
-
type = require_PluginCommon.PluginType.Compiler;
|
|
12
|
-
/**
|
|
13
|
-
* Called when transformation is requested to this plugin
|
|
14
|
-
* @param params The parameters for the transformation
|
|
15
|
-
* @returns The transformed result
|
|
16
|
-
*/
|
|
17
|
-
async transform(params) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Type guard to check if the given object is a CompilerPlugin.
|
|
23
|
-
* @param plugin The object to check.
|
|
24
|
-
* @returns Boolean indicating whether the object is a CompilerPlugin.
|
|
25
|
-
*/
|
|
26
|
-
function isCompilerPlugin(plugin) {
|
|
27
|
-
return plugin instanceof CompilerPlugin || require_PluginCommon.isPlugin(plugin) && plugin.type === require_PluginCommon.PluginType.Compiler;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
//#endregion
|
|
31
|
-
Object.defineProperty(exports, 'CompilerPlugin', {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function () {
|
|
34
|
-
return CompilerPlugin;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(exports, 'isCompilerPlugin', {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function () {
|
|
40
|
-
return isCompilerPlugin;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
//# sourceMappingURL=CompilerPlugin-CUsGAfgl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CompilerPlugin-CUsGAfgl.js","names":[],"sources":["../src/plugins/CompilerPlugin.ts"],"sourcesContent":["import {\n isPlugin,\n PluginCommon,\n PluginOptions,\n PluginType,\n} from './PluginCommon';\nimport { MaybeFalsey } from './types';\nimport { CompilerPluginRuntime } from './plugin-runtime/CompilerPluginRuntime';\n\n/**\n * The parameters for the transformation function of a compiler plugin.\n */\nexport interface PluginTransformParameters {\n /**\n * The code to be transformed.\n */\n code: string;\n /**\n * The filename of the code being transformed.\n */\n id: string;\n}\n\nexport interface TransformedResult {\n /**\n * The transformed code.\n */\n code?: string;\n /**\n * The source map for the transformed code, if applicable.\n */\n map?: string | null;\n}\n\n/**\n * CommandKit plugin that runs at compile time.\n */\nexport abstract class CompilerPlugin<\n T extends PluginOptions = PluginOptions,\n> extends PluginCommon<T, CompilerPluginRuntime> {\n /**\n * The type of the plugin, which is Compiler.\n */\n public readonly type = PluginType.Compiler;\n\n /**\n * Called when transformation is requested to this plugin\n * @param params The parameters for the transformation\n * @returns The transformed result\n */\n public async transform(\n params: PluginTransformParameters,\n ): Promise<MaybeFalsey<TransformedResult>> {\n return null;\n }\n}\n\n/**\n * Type guard to check if the given object is a CompilerPlugin.\n * @param plugin The object to check.\n * @returns Boolean indicating whether the object is a CompilerPlugin.\n */\nexport function isCompilerPlugin(plugin: unknown): plugin is CompilerPlugin {\n return (\n plugin instanceof CompilerPlugin ||\n (isPlugin(plugin) && plugin.type === PluginType.Compiler)\n );\n}\n"],"mappings":";;;;;;AAqCA,IAAsB,iBAAtB,cAEA,kCAA0B;;;;CAIxB,AAAgB,OAAO,gCAAW;;;;;;CAOlC,MAAa,UACb,QAC0C;AACxC,SAAO;;;;;;;;AASX,SAAgB,iBAAiB,QAA2C;AAC1E,QACE,kBAAkB,kBAClB,8BAAS,OAAO,IAAI,OAAO,SAAS,gCAAW"}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/components/common/EventInterceptor.ts
|
|
3
|
-
/**
|
|
4
|
-
* The event interceptor class that allows subscribing to events and handling them with custom logic.
|
|
5
|
-
* It also supports automatic cleanup of expired subscriptions.
|
|
6
|
-
*/
|
|
7
|
-
var EventInterceptor = class {
|
|
8
|
-
subscribers = /* @__PURE__ */ new Map();
|
|
9
|
-
globalHandlers = /* @__PURE__ */ new Map();
|
|
10
|
-
cleanupTimer = null;
|
|
11
|
-
/**
|
|
12
|
-
* Creates the event interceptor.
|
|
13
|
-
*/
|
|
14
|
-
constructor(client) {
|
|
15
|
-
this.client = client;
|
|
16
|
-
this.#cleanupLoop();
|
|
17
|
-
}
|
|
18
|
-
#cleanupLoop() {
|
|
19
|
-
if (this.cleanupTimer) clearInterval(this.cleanupTimer);
|
|
20
|
-
this.cleanupTimer = setInterval(() => {
|
|
21
|
-
for (const [event, handlers] of this.subscribers) for (const handler of handlers) {
|
|
22
|
-
const options = Reflect.get(handler, "options");
|
|
23
|
-
if (options.time && Date.now() - options.registeredAt > options.time) this.unsubscribe(event, handler, "time");
|
|
24
|
-
}
|
|
25
|
-
}, 6e4).unref();
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Destroys the event interceptor.
|
|
29
|
-
*/
|
|
30
|
-
destroy() {
|
|
31
|
-
if (this.cleanupTimer) {
|
|
32
|
-
clearInterval(this.cleanupTimer);
|
|
33
|
-
this.cleanupTimer = null;
|
|
34
|
-
}
|
|
35
|
-
for (const [event, handlers] of this.subscribers) for (const handler of handlers) this.unsubscribe(event, handler, "destroy");
|
|
36
|
-
this.subscribers.clear();
|
|
37
|
-
this.globalHandlers.clear();
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Whether the event has subscribers.
|
|
41
|
-
* @param event The event to check.
|
|
42
|
-
*/
|
|
43
|
-
hasSubscribers(event) {
|
|
44
|
-
return this.subscribers.has(event);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Returns the number of subscribers for the event.
|
|
48
|
-
* @param event The event to check.
|
|
49
|
-
*/
|
|
50
|
-
getSubscriberCount(event) {
|
|
51
|
-
const handlers = this.subscribers.get(event);
|
|
52
|
-
return (handlers === null || handlers === void 0 ? void 0 : handlers.size) ?? 0;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Whether the event has global handlers.
|
|
56
|
-
*/
|
|
57
|
-
hasGlobalHandlers() {
|
|
58
|
-
return this.globalHandlers.size > 0;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Returns the number of global handlers.
|
|
62
|
-
*/
|
|
63
|
-
getGlobalHandlersCount() {
|
|
64
|
-
return this.subscribers.size;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Subscribes to an event.
|
|
68
|
-
* @param event The event to subscribe to.
|
|
69
|
-
* @param listener The listener to call when the event is emitted.
|
|
70
|
-
* @returns A function to unsubscribe from the event.
|
|
71
|
-
*/
|
|
72
|
-
subscribe(event, listener, options) {
|
|
73
|
-
if (!this.subscribers.has(event)) {
|
|
74
|
-
this.subscribers.set(event, /* @__PURE__ */ new Set());
|
|
75
|
-
this.client.on(event, this.createGlobalHandler(event));
|
|
76
|
-
this.client.setMaxListeners(this.client.getMaxListeners() + 1);
|
|
77
|
-
}
|
|
78
|
-
options ??= {};
|
|
79
|
-
options.registeredAt = Date.now();
|
|
80
|
-
Reflect.set(listener, "options", options);
|
|
81
|
-
this.subscribers.get(event).add(listener);
|
|
82
|
-
return () => {
|
|
83
|
-
this.unsubscribe(event, listener);
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Unsubscribes from an event.
|
|
88
|
-
* @param event The event to unsubscribe from.
|
|
89
|
-
*/
|
|
90
|
-
unsubscribe(event, listener, reason) {
|
|
91
|
-
var _Reflect$get$onEnd, _Reflect$get;
|
|
92
|
-
const handlers = this.subscribers.get(event);
|
|
93
|
-
if (!handlers) return;
|
|
94
|
-
handlers.delete(listener);
|
|
95
|
-
if (handlers.size < 1) {
|
|
96
|
-
this.subscribers.delete(event);
|
|
97
|
-
this.client.removeListener(event, this.globalHandlers.get(event));
|
|
98
|
-
this.globalHandlers.delete(event);
|
|
99
|
-
this.client.setMaxListeners(Math.max(this.client.getMaxListeners() - 1, 0));
|
|
100
|
-
}
|
|
101
|
-
(_Reflect$get$onEnd = (_Reflect$get = Reflect.get(listener, "options")).onEnd) === null || _Reflect$get$onEnd === void 0 || _Reflect$get$onEnd.call(_Reflect$get, reason ?? "unsubscribe");
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Creates a global handler for the event.
|
|
105
|
-
* @param event The event to create a global handler for.
|
|
106
|
-
* @returns The global handler.
|
|
107
|
-
*/
|
|
108
|
-
createGlobalHandler(event) {
|
|
109
|
-
if (this.globalHandlers.has(event)) return this.globalHandlers.get(event);
|
|
110
|
-
const handler = async (...args) => {
|
|
111
|
-
const subscribers = this.subscribers.get(event);
|
|
112
|
-
if (subscribers && subscribers.size > 0) for (const subscriber of subscribers) {
|
|
113
|
-
const options = Reflect.get(subscriber, "options");
|
|
114
|
-
if (options.time && Date.now() - options.registeredAt > options.time) {
|
|
115
|
-
this.unsubscribe(event, subscriber, "time");
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (options.autoReset) options.registeredAt = Date.now();
|
|
119
|
-
if (options.filter && !await options.filter(...args)) continue;
|
|
120
|
-
try {
|
|
121
|
-
await subscriber(...args);
|
|
122
|
-
} catch (e) {
|
|
123
|
-
if (options.onError) await options.onError(e);
|
|
124
|
-
else throw e;
|
|
125
|
-
} finally {
|
|
126
|
-
if (options.once) this.unsubscribe(event, subscriber, "once");
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
this.globalHandlers.set(event, handler);
|
|
131
|
-
return handler;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
//#endregion
|
|
136
|
-
Object.defineProperty(exports, 'EventInterceptor', {
|
|
137
|
-
enumerable: true,
|
|
138
|
-
get: function () {
|
|
139
|
-
return EventInterceptor;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
//# sourceMappingURL=EventInterceptor-BWoEJMHZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventInterceptor-BWoEJMHZ.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,KAGzB;CACD,AAAQ,iCAAiB,IAAI,KAG5B;CACD,AAAQ,eAAsC;;;;CAK9C,AAAO,YAAY,AAAgB,QAAg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,OAAO,QAAQ;AAEvC,SAAO"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-kSYXY2_d.js');
|
|
2
|
-
let node_async_hooks = require("node:async_hooks");
|
|
3
|
-
|
|
4
|
-
//#region src/app/events/EventWorkerContext.ts
|
|
5
|
-
/**
|
|
6
|
-
* @private
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
const kEventWorker = Symbol("commandkitEventWorker");
|
|
10
|
-
/**
|
|
11
|
-
* Async local storage for event worker context.
|
|
12
|
-
*/
|
|
13
|
-
const eventWorkerContext = new node_async_hooks.AsyncLocalStorage();
|
|
14
|
-
/**
|
|
15
|
-
* Runs a callback within an event worker context.
|
|
16
|
-
* @param context - The event worker context
|
|
17
|
-
* @param callback - The callback to execute
|
|
18
|
-
* @returns The result of the callback
|
|
19
|
-
*/
|
|
20
|
-
function runInEventWorkerContext(context, callback) {
|
|
21
|
-
Reflect.set(context, kEventWorker, true);
|
|
22
|
-
return eventWorkerContext.run(context, callback);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Gets the current event worker context.
|
|
26
|
-
* @returns The current event worker context
|
|
27
|
-
* @throws Error if no context is found
|
|
28
|
-
*/
|
|
29
|
-
function getEventWorkerContext() {
|
|
30
|
-
const context = eventWorkerContext.getStore();
|
|
31
|
-
if (!context) throw new Error("Event worker context not found");
|
|
32
|
-
return context;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Type guard to check if an object is an event worker context.
|
|
36
|
-
* @param worker - The object to check
|
|
37
|
-
* @returns True if the object is an event worker context
|
|
38
|
-
*/
|
|
39
|
-
function isEventWorkerContext(worker) {
|
|
40
|
-
return worker && Reflect.get(worker, kEventWorker) === true;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
|
-
Object.defineProperty(exports, 'eventWorkerContext', {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
get: function () {
|
|
47
|
-
return eventWorkerContext;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(exports, 'getEventWorkerContext', {
|
|
51
|
-
enumerable: true,
|
|
52
|
-
get: function () {
|
|
53
|
-
return getEventWorkerContext;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(exports, 'isEventWorkerContext', {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
get: function () {
|
|
59
|
-
return isEventWorkerContext;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
Object.defineProperty(exports, 'runInEventWorkerContext', {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
get: function () {
|
|
65
|
-
return runInEventWorkerContext;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
//# sourceMappingURL=EventWorkerContext-Dfhgv329.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventWorkerContext-Dfhgv329.js","names":[],"sources":["../src/app/events/EventWorkerContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport { ParsedEvent } from '../router';\nimport type { 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,oCAAuC;;;;;;;AAQ7E,SAAgB,wBAChB,SACA,UACI;AACF,SAAQ,IAAI,SAAS,cAAc,KAAK;AAExC,QAAO,mBAAmB,IAAI,SAAS,SAAS;;;;;;;AAQlD,SAAgB,wBAA4C;CAC1D,MAAM,UAAU,mBAAmB,UAAU;AAE7C,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,iCAAiC;AAGnD,QAAO;;;;;;;AAQT,SAAgB,qBAChB,QAC+B;AAC7B,QAAO,UAAU,QAAQ,IAAI,QAAQ,aAAa,KAAK"}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-kSYXY2_d.js');
|
|
2
|
-
let discord_js = require("discord.js");
|
|
3
|
-
let node_fs = require("node:fs");
|
|
4
|
-
let node_path = require("node:path");
|
|
5
|
-
let node_fs_promises = require("node:fs/promises");
|
|
6
|
-
|
|
7
|
-
//#region src/app/router/EventsRouter.ts
|
|
8
|
-
/**
|
|
9
|
-
* Router for discovering and managing event handler files in a directory structure.
|
|
10
|
-
* Events are represented by directories, and handlers are files within those directories.
|
|
11
|
-
*/
|
|
12
|
-
var EventsRouter = class {
|
|
13
|
-
/** Internal storage of parsed events */
|
|
14
|
-
events = new discord_js.Collection();
|
|
15
|
-
/**
|
|
16
|
-
* Creates a new EventsRouter instance
|
|
17
|
-
* @param options - Configuration options for the router
|
|
18
|
-
* @throws Error if entrypoint is not provided
|
|
19
|
-
*/
|
|
20
|
-
constructor(options) {
|
|
21
|
-
var _options$entrypoints;
|
|
22
|
-
this.options = options;
|
|
23
|
-
if (options.entrypoints) options.entrypoints = Array.from(new Set(options.entrypoints));
|
|
24
|
-
if (!((_options$entrypoints = options.entrypoints) === null || _options$entrypoints === void 0 ? void 0 : _options$entrypoints.length)) throw new Error("Entrypoint directory must be provided");
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Adds new entrypoints to the router
|
|
28
|
-
* @param entrypoints - Array of new entrypoint paths
|
|
29
|
-
*/
|
|
30
|
-
addEntrypoints(entrypoints) {
|
|
31
|
-
this.options.entrypoints = Array.from(new Set([...this.options.entrypoints, ...entrypoints]));
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Find a parsed event by its name
|
|
35
|
-
* @param event - Name of the event to find
|
|
36
|
-
* @returns Parsed event metadata or null if not found
|
|
37
|
-
*/
|
|
38
|
-
match(event) {
|
|
39
|
-
return this.events.get(event) ?? null;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Get the entrypoint directory path
|
|
43
|
-
* @returns Entrypoint directory path
|
|
44
|
-
*/
|
|
45
|
-
get entrypoints() {
|
|
46
|
-
return this.options.entrypoints;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Checks if the entrypoint path is valid
|
|
50
|
-
*/
|
|
51
|
-
isValidPath() {
|
|
52
|
-
return this.entrypoints.every((entrypoint) => (0, node_fs.existsSync)(entrypoint));
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Clear all parsed events
|
|
56
|
-
*/
|
|
57
|
-
clear() {
|
|
58
|
-
this.events.clear();
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Reload and re-scan the entrypoint directory for events
|
|
62
|
-
* @returns Promise resolving to the updated events tree
|
|
63
|
-
*/
|
|
64
|
-
async reload() {
|
|
65
|
-
this.clear();
|
|
66
|
-
return this.scan();
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Scan the entrypoint directory for events and their handlers
|
|
70
|
-
* @returns Promise resolving to the events tree
|
|
71
|
-
*/
|
|
72
|
-
async scan() {
|
|
73
|
-
for (const entrypoint of this.entrypoints) {
|
|
74
|
-
const dirs = await (0, node_fs_promises.readdir)(entrypoint, { withFileTypes: true });
|
|
75
|
-
for (const dir of dirs) if (dir.isDirectory()) {
|
|
76
|
-
const path = (0, node_path.join)(entrypoint, dir.name);
|
|
77
|
-
await this.scanEvent(dir.name, path, null, [], true);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return Object.fromEntries(this.events);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Convert the internal events Collection to a plain object
|
|
84
|
-
* @returns Events tree as a plain object
|
|
85
|
-
*/
|
|
86
|
-
toJSON() {
|
|
87
|
-
return Object.fromEntries(this.events);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Recursively scan a directory for event handlers
|
|
91
|
-
* @param event - Name of the event
|
|
92
|
-
* @param path - Path to the event directory
|
|
93
|
-
* @param listeners - Array to collect listener file paths
|
|
94
|
-
* @returns Promise resolving to the parsed event metadata
|
|
95
|
-
*/
|
|
96
|
-
async scanEvent(event, path, _namespace = null, listeners = [], isRoot = false) {
|
|
97
|
-
const files = await (0, node_fs_promises.readdir)(path, { withFileTypes: true });
|
|
98
|
-
const isNamespace = isRoot && /^\(.+\)$/.test(event);
|
|
99
|
-
const namespace = isNamespace ? event.slice(1, -1) : _namespace ?? null;
|
|
100
|
-
files.sort((a, b) => a.name.localeCompare(b.name));
|
|
101
|
-
for (const file of files) {
|
|
102
|
-
if (file.name.startsWith("_")) continue;
|
|
103
|
-
if (file.isDirectory()) {
|
|
104
|
-
const nextPath = (0, node_path.join)(path, file.name);
|
|
105
|
-
await this.scanEvent(file.name, nextPath, namespace, listeners);
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
if (file.isFile() && /\.(m|c)?(j|t)sx?$/.test(file.name)) listeners.push((0, node_path.join)(file.parentPath, file.name));
|
|
109
|
-
}
|
|
110
|
-
if (!isNamespace) {
|
|
111
|
-
const existing = this.events.get(event);
|
|
112
|
-
if (existing) {
|
|
113
|
-
existing.listeners = Array.from(new Set([...existing.listeners, ...listeners]));
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
this.events.set(event, {
|
|
117
|
-
event,
|
|
118
|
-
path,
|
|
119
|
-
listeners,
|
|
120
|
-
namespace
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
//#endregion
|
|
127
|
-
Object.defineProperty(exports, 'EventsRouter', {
|
|
128
|
-
enumerable: true,
|
|
129
|
-
get: function () {
|
|
130
|
-
return EventsRouter;
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
//# sourceMappingURL=EventsRouter-DZYIha6m.js.map
|